Connect parameters are being passed to the kernel code. (Rev 71)
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 12:02:13 +0000 (12:02 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 12:02:13 +0000 (12:02 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@160 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/sdp/include/SdpShared.h
ulp/sdp/kernel/SdpDriver.cpp
ulp/sdp/kernel/SdpGenUtils.cpp
ulp/sdp/kernel/SdpGenUtils.h
ulp/sdp/kernel/SdpSocket.cpp
ulp/sdp/kernel/SdpSocket.h
ulp/sdp/kernel/SdpUserFile.cpp
ulp/sdp/kernel/SdpUserFile.h

index f470f36..577c4f2 100644 (file)
@@ -12,6 +12,7 @@
 // Define the IOCTL codes that will be used for sending the requests down\r
 \r
 #define IOCTL_WSP_SOCKET       CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED ,FILE_ANY_ACCESS)\r
+#define IOCTL_WSP_CONNECT      CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED ,FILE_ANY_ACCESS)\r
 \r
 // Data structures that are used for connect\r
 struct WspSocketIn {\r
@@ -24,13 +25,13 @@ struct WspSocketOut {
 };\r
 \r
 struct WspConnectIn {\r
+    VOID *pSocket;\r
        ULONG IP;\r
        USHORT Port;\r
-       int namelen;\r
 };\r
 \r
 struct WspConnectOut {\r
        int Errno;\r
 };\r
 \r
-#endif //_SDP_SHARED_H
\ No newline at end of file
+#endif //_SDP_SHARED_H\r
index a7d1d0f..3af15f2 100644 (file)
@@ -302,6 +302,9 @@ NTSTATUS SdpDriver::DispatchDeviceIoControl(
     NTSTATUS rc = STATUS_SUCCESS;\r
     SdpUserFile *pSdpUserFile = NULL;\r
     SdpSocket *pSdpSocket = NULL;\r
+\r
+    WspConnectIn *pWspConnectIn = NULL;\r
+    WspConnectOut *pWspConnectOut = NULL;\r
     \r
     switch (IoControlCode) {\r
         case IOCTL_WSP_SOCKET :\r
@@ -324,8 +327,35 @@ NTSTATUS SdpDriver::DispatchDeviceIoControl(
                 SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpUserFile->AddSocket failed rc = 0x%x\n", rc ));        \r
                 goto Cleanup;\r
             }\r
+            OutputDataSize = sizeof (WspSocketOut);\r
 \r
         break;\r
+\r
+        case IOCTL_WSP_CONNECT :\r
+            SDP_PRINT(SDP_DEBUG, SDP_DRIVER, ("DispatchDeviceIoControl IOCTL_WSP_CONNECT recieved\n" ));   \r
+            VERIFY_BUFFERS(InputBufferLength, OutputBufferLength, WspConnectIn, WspConnectOut);\r
+            OutputDataSize = sizeof (WspConnectOut);\r
+\r
+            // get the socket based on the users pointer\r
+            pWspConnectIn = (WspConnectIn *) pInputBuffer;\r
+            pWspConnectOut = (WspConnectOut *) pOutputBuffer;\r
+            pSdpUserFile = (SdpUserFile *)pIrpSp->FileObject->FsContext;\r
+            pSdpSocket = pSdpUserFile->SocketByPointer(pWspConnectIn->pSocket);\r
+            if (pSdpSocket == NULL) {\r
+               SDP_PRINT(SDP_DEBUG, SDP_DRIVER, ("DispatchDeviceIoControl IOCTL_WSP_CONNECT socket %x not found\n",pWspConnectIn->pSocket));   \r
+               // This is a well defined winsock error\r
+               pWspConnectOut->Errno = WSAENOTSOCK;\r
+               goto Cleanup;\r
+            }\r
+            rc = pSdpSocket->WSPConnect(pWspConnectIn, pWspConnectOut);\r
+            if (!NT_SUCCESS(rc)) {\r
+                SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpSocket->WSPConnect failed rc = 0x%x\n", rc ));        \r
+                goto Cleanup;\r
+            }\r
+            \r
+\r
+\r
+            break;\r
         \r
     default:\r
         // This is an unrecgnized IOCTL\r
index 1c7e08e..67cc886 100644 (file)
@@ -3,6 +3,12 @@
 #include "Precompile.h"\r
 \r
 \r
+USHORT nthos(USHORT in)\r
+{\r
+    return ((in & 0xff) << 8) | ((in & 0xff00) >> 8);\r
+}\r
+\r
+\r
 \r
 void* __cdecl operator new(size_t n ) throw() {\r
     return ExAllocatePoolWithTag(NonPagedPool , n, GLOBAL_ALLOCATION_TAG);\r
index 6ca2012..8e9bd9e 100644 (file)
@@ -39,4 +39,72 @@ public:
 \r
 };\r
 \r
+\r
+USHORT nthos(USHORT in);\r
+\r
+\r
+// This error codes are taken from winsock2.h (the file can not)\r
+// be included from user mode\r
+\r
+/*\r
+ * All Windows Sockets error constants are biased by WSABASEERR from\r
+ * the "normal"\r
+ */\r
+#define WSABASEERR              10000\r
+\r
+/*\r
+ * Windows Sockets definitions of regular Microsoft C error constants\r
+ */\r
+#define WSAEINTR                (WSABASEERR+4)\r
+#define WSAEBADF                (WSABASEERR+9)\r
+#define WSAEACCES               (WSABASEERR+13)\r
+#define WSAEFAULT               (WSABASEERR+14)\r
+#define WSAEINVAL               (WSABASEERR+22)\r
+#define WSAEMFILE               (WSABASEERR+24)\r
+\r
+/*\r
+ * Windows Sockets definitions of regular Berkeley error constants\r
+ */\r
+#define WSAEWOULDBLOCK          (WSABASEERR+35)\r
+#define WSAEINPROGRESS          (WSABASEERR+36)\r
+#define WSAEALREADY             (WSABASEERR+37)\r
+#define WSAENOTSOCK             (WSABASEERR+38)\r
+#define WSAEDESTADDRREQ         (WSABASEERR+39)\r
+#define WSAEMSGSIZE             (WSABASEERR+40)\r
+#define WSAEPROTOTYPE           (WSABASEERR+41)\r
+#define WSAENOPROTOOPT          (WSABASEERR+42)\r
+#define WSAEPROTONOSUPPORT      (WSABASEERR+43)\r
+#define WSAESOCKTNOSUPPORT      (WSABASEERR+44)\r
+#define WSAEOPNOTSUPP           (WSABASEERR+45)\r
+#define WSAEPFNOSUPPORT         (WSABASEERR+46)\r
+#define WSAEAFNOSUPPORT         (WSABASEERR+47)\r
+#define WSAEADDRINUSE           (WSABASEERR+48)\r
+#define WSAEADDRNOTAVAIL        (WSABASEERR+49)\r
+#define WSAENETDOWN             (WSABASEERR+50)\r
+#define WSAENETUNREACH          (WSABASEERR+51)\r
+#define WSAENETRESET            (WSABASEERR+52)\r
+#define WSAECONNABORTED         (WSABASEERR+53)\r
+#define WSAECONNRESET           (WSABASEERR+54)\r
+#define WSAENOBUFS              (WSABASEERR+55)\r
+#define WSAEISCONN              (WSABASEERR+56)\r
+#define WSAENOTCONN             (WSABASEERR+57)\r
+#define WSAESHUTDOWN            (WSABASEERR+58)\r
+#define WSAETOOMANYREFS         (WSABASEERR+59)\r
+#define WSAETIMEDOUT            (WSABASEERR+60)\r
+#define WSAECONNREFUSED         (WSABASEERR+61)\r
+#define WSAELOOP                (WSABASEERR+62)\r
+#define WSAENAMETOOLONG         (WSABASEERR+63)\r
+#define WSAEHOSTDOWN            (WSABASEERR+64)\r
+#define WSAEHOSTUNREACH         (WSABASEERR+65)\r
+#define WSAENOTEMPTY            (WSABASEERR+66)\r
+#define WSAEPROCLIM             (WSABASEERR+67)\r
+#define WSAEUSERS               (WSABASEERR+68)\r
+#define WSAEDQUOT               (WSABASEERR+69)\r
+#define WSAESTALE               (WSABASEERR+70)\r
+#define WSAEREMOTE              (WSABASEERR+71)\r
+\r
+\r
+\r
+\r
+\r
 #endif // _SDP_GEN_UTILS_H\r
index 3b9aeb7..ca54437 100644 (file)
@@ -16,6 +16,34 @@ NTSTATUS SdpSocket::Init(
     return STATUS_SUCCESS;\r
 }\r
 \r
+NTSTATUS SdpSocket::WSPConnect(\r
+    WspConnectIn    *pWspConnectIn,\r
+    WspConnectOut   *pWspConnectOut\r
+    )\r
+{\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("SdpSocket::WSPConnect this = 0x%x remote addresses ip=%d.%d.%d.%d:%d",\r
+        this,\r
+        (pWspConnectIn->IP & 0XFF),\r
+        (pWspConnectIn->IP & 0XFF00) >> 8,\r
+        (pWspConnectIn->IP & 0XFF0000) >> 16,\r
+        (pWspConnectIn->IP & 0XFF000000) >> 24,\r
+        nthos(pWspConnectIn->Port)\r
+        ));\r
+\r
+    if((pWspConnectIn->IP == 0) || (pWspConnectIn->Port == 0)) {\r
+        SDP_PRINT(SDP_ERR, SDP_SOCKET, ("Invalid Addresses"));\r
+        pWspConnectOut->Errno = WSAEADDRNOTAVAIL;\r
+        goto Cleanup;\r
+    }\r
+\r
+Cleanup:    \r
+    return rc;\r
+\r
+}\r
+\r
+\r
+\r
 VOID SdpSocket::Shutdown()\r
 {\r
     SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("SdpSocket::Shutdown called this = 0x%x\n", this));\r
index 876b107..9dc1479 100644 (file)
@@ -21,8 +21,14 @@ private:
     \r
 public:\r
     NTSTATUS Init(\r
-        WspSocketIn *pSocketInParam, \r
-        WspSocketOut *pSocketOutParam);\r
+        WspSocketIn     *pSocketInParam, \r
+        WspSocketOut    *pSocketOutParam\r
+        );\r
+\r
+    NTSTATUS WSPConnect(\r
+        WspConnectIn    *pWspConnectIn,\r
+        WspConnectOut   *pWspConnectOut\r
+        );\r
 \r
     VOID Shutdown();\r
 \r
index ebe0b71..3442dd4 100644 (file)
@@ -53,4 +53,32 @@ NTSTATUS SdpUserFile::AddSocket(SdpSocket *pSdpSocket)
 \r
 }\r
 \r
+SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket)\r
+{\r
+    SdpSocket *pSdpSocket = NULL;\r
+    PLIST_ENTRY pNext;\r
+    CSpinLockWrapper Lock(m_Lock);\r
+    Lock.Lock();\r
+    if (m_shutdown) {\r
+        Lock.Unlock();\r
+        return NULL;\r
+    }\r
+\r
+    pNext = m_SocketsList.Flink;\r
+    while (pNext != &m_SocketsList) {\r
+        pSdpSocket = CONTAINING_RECORD(pNext, SdpSocket, m_UserFileList );\r
+        if (pSdpSocket == Socket) {\r
+            // We have found the socket that we are looking for\r
+            break;\r
+        }\r
+        pNext = pNext->Flink;\r
+    }\r
+    if (pSdpSocket) {   \r
+        pSdpSocket->AddRef();\r
+    }\r
+    \r
+    Lock.Unlock();\r
+    return pSdpSocket;\r
+}\r
+\r
 \r
index 92ded63..67ab18b 100644 (file)
@@ -25,6 +25,9 @@ public:
 \r
     NTSTATUS Init();\r
     VOID Shutdown();\r
+\r
+    SdpSocket *SocketByPointer(VOID *Socket);\r
+    \r
     \r
     NTSTATUS AddSocket(SdpSocket *pSdpSocket);\r
 \r