⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpclient.c

📁 网络驱动开发
💻 C
📖 第 1 页 / 共 3 页
字号:
      {
         pSession->m_TestParams.m_nNoDelay = TRUE;

         Status = KS_TCPSetInformation(
                     pSession->m_KS_Endpoint.m_pFileObject,// Connection Endpoint File Object
                     CO_TL_ENTITY,              // Entity
                     INFO_CLASS_PROTOCOL,       // Class
                     INFO_TYPE_CONNECTION,      // Type
                     TCP_SOCKET_NODELAY,        // Id
                     &pSession->m_TestParams.m_nNoDelay,          // Value
                     sizeof( pSession->m_TestParams.m_nNoDelay )  // ValueLength
                     );

         KdPrint(( "NoDelay Status: 0x%8.8x\n", Status ));
      }

      //
      // Make TDI_ADDRESS_INFO Query Test
      //
      DoQueryAddressInfoTest( pSession );

      //
      // Make TDI_CONNECTION_INFO Query Test
      //
      DoQueryConnectionInfoTest( pSession );

      //
      // Set TDI Connection Info
      // ===================
      // Is apparently not implemented in TCP/IP driver. Returns error
      // 0xC0000002 -> STATUS_NOT_IMPLEMENTED.
      //

      switch( pSession->m_TestParams.m_SendMode )
      {
         case TTCP_SEND_NEXT_FROM_COMPLETION:
            KdPrint(( "  Send Mode: Send Next From Completion.\n"));

            //
            // Initialize The Final Send Event
            //
            KeInitializeEvent(
               &pSession->m_FinalSendEvent,
               NotificationEvent,
               FALSE
               );

            //
            // Start The First Send On The Connection
            //
            (pSession->m_pPatternMdl)->Next = NULL;   // IMPORTANT!!!

            Status = KS_SendOnEndpoint(
                           &pSession->m_KS_Endpoint,
                           NULL,       // User Completion Event
                           TCPC_SendCompletion,// User Completion Routine
                           pSession,   // User Completion Context
                           &pSession->m_PatternIoStatus,
                           pSession->m_pPatternMdl,
                           0           // Send Flags
                           );

            if( NT_SUCCESS(Status) )
            {
               //
               // Wait For Final Send To Complete
               // -------------------------------
               // The TCPC_SendCompletion callback will set the event
               // when the final buffer has been send and acknowledged.
               //
               Status = KeWaitForSingleObject(
                              &pSession->m_FinalSendEvent,  // Object to wait on.
                              Executive,  // Reason for waiting
                              KernelMode, // Processor mode
                              FALSE,      // Alertable
                              NULL        // Timeout
                              );
            }
            else
            {
               KdPrint(( "TCPC_SendBuffer: Status 0x%8.8X\n", Status ));
            }
            break;

         case TTCP_SEND_SYNCHRONOUS:
         default:
            KdPrint(( "  Send Mode: Synchronous Send.\n"));

            while( pSession->m_nNumBuffersToSend-- )
            {
               //
               // Synchronous Send On The Connection
               //
               (pSession->m_pPatternMdl)->Next = NULL;   // IMPORTANT!!!

               Status = KS_SendOnEndpoint(
                              &pSession->m_KS_Endpoint,
                              NULL,       // User Completion Event
                              NULL,       // User Completion Routine
                              NULL,       // User Completion Context
                              &pSession->m_PatternIoStatus,
                              pSession->m_pPatternMdl,
                              0           // Send Flags
                              );

               if( NT_SUCCESS(Status) )
               {
//                  KdPrint(( "TCPC_SendBuffer: Sent %d Bytes\n", pSession->m_PatternIoStatus.Information ));
               }
               else
               {
                  KdPrint(( "TCPC_SendBuffer: Status 0x%8.8X\n", Status ));
                  break;
               }
            }
            break;
      }
   }

   //
   // Perfrom Synchronous Disconnect
   //
   Status = KS_Disconnect(
               &pSession->m_KS_Endpoint,
               NULL,    // UserCompletionEvent
               NULL,    // UserCompletionRoutine
               NULL,    // UserCompletionContext
               NULL,    // pIoStatusBlock
               0        // Disconnect Flags
               );

   KdPrint(( "Disconnect Status: 0x%8.8x\n", Status ));

   KdPrint(( "Waiting After Disconnect...\n" ));

   DelayTime.QuadPart = 10*1000*1000*5;   // 5 Seconds

   KeDelayExecutionThread( KernelMode, FALSE, &DelayTime );


   //
   // Close The Connection Endpoint
   // -----------------------------
   // This will close the connection file object and the address file
   // object.
   //
   KS_CloseConnectionEndpoint( &pSession->m_KS_Endpoint );
   KS_CloseTransportAddress( &pSession->m_KS_Address );

   //
   // Exit The Thread
   //
ExitTheThread:

   KdPrint(("TCPC_TestThread: Exiting...\n") );

   if( pSession )
   {
      if( pSession->m_pPatternMdl )
      {
         KS_UnlockAndFreeMdl( pSession->m_pPatternMdl );
      }

      pSession->m_pPatternMdl = NULL;


      if( pSession->m_pPatternBuffer )
      {
         NdisFreeMemory(
            pSession->m_pPatternBuffer,
            pSession->m_PatternBufferSize,
            0
            );
      }

      pSession->m_pPatternBuffer = NULL;

      NdisFreeMemory( pSession, sizeof( TCPC_SESSION ), 0 );
   }

   pSession = NULL;

   (void)PsTerminateSystemThread( STATUS_SUCCESS );
}

/////////////////////////////////////////////////////////////////////////////
//// TCPC_StartTest
//
// Purpose
// Start A TTCP TCP Client Test
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pIrp - Pointer to the request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

NTSTATUS
TCPC_StartTest(
   IN PDEVICE_OBJECT pDeviceObject,
   IN PIRP pIrp
   )
{
   HANDLE               hTestThread;
   NDIS_STATUS          nNdisStatus;
   PTTCP_TEST_START_CMD pStartCmd = NULL;
   PTCPC_SESSION        pSession = NULL;

   //
   // Initialize Default Settings
   //
   pIrp->IoStatus.Information = sizeof( ULONG );  // For m_Status

   //
   // Locate Test Start Command Buffer
   //
   pStartCmd = (PTTCP_TEST_START_CMD )pIrp->AssociatedIrp.SystemBuffer;

   pStartCmd->m_Status = STATUS_UNSUCCESSFUL;

   TDITTCP_DumpTestParams( &pStartCmd->m_TestParams );

   //
   // Allocate Memory For The Test Session
   //
   nNdisStatus = NdisAllocateMemory(
                  &pSession,
                  sizeof( TCPC_SESSION ),
                  0,       // Allocate non-paged system-space memory
                  HighestAcceptableMax
                  );

   if( !NT_SUCCESS( nNdisStatus ) )
   {
      return( nNdisStatus );
   }

   NdisZeroMemory( pSession, sizeof( TCPC_SESSION ) );

   NdisMoveMemory(
      &pSession->m_TestParams,
      &pStartCmd->m_TestParams,
      sizeof( TDITTCP_TEST_PARAMS )
      );

   //
   // Start The Thread That Will Execute The Test
   //
   PsCreateSystemThread(
      &hTestThread,     // thread handle
      0L,               // desired access
      NULL,             // object attributes
      NULL,             // process handle
      NULL,             // client id
      TCPC_TestThread,  // start routine
      (PVOID )pSession  // start context
      );

   return( STATUS_SUCCESS );
}

/////////////////////////////////////////////////////////////////////////////
//// TCPC_DeviceIoControl (IRP_MJ_DEVICE_CONTROL Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDI TTCP TCP Client device IOCTL requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pIrp - Pointer to the request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

NTSTATUS
TCPC_DeviceIoControl(
    IN PDEVICE_OBJECT pDeviceObject,
    IN PIRP pIrp
    )
{
   PDEVICE_EXTENSION    pDeviceExtension;
   NTSTATUS             Status;
   PIO_STACK_LOCATION   pIrpSp;
   ULONG                nFunctionCode;

   KdPrint(("TCPC_DeviceIoControl: Entry...\n") );

   pDeviceExtension = pDeviceObject->DeviceExtension;

   pIrp->IoStatus.Information = 0;      // Nothing Returned Yet

   pIrpSp = IoGetCurrentIrpStackLocation(pIrp);

   nFunctionCode=pIrpSp->Parameters.DeviceIoControl.IoControlCode;

   switch( nFunctionCode )
   {
      case IOCTL_TCP_CLIENT_START_TEST:
         Status = TCPC_StartTest( pDeviceObject, pIrp );
         break;

      default:
         KdPrint((  "FunctionCode: 0x%8.8X\n", nFunctionCode ));
         Status = STATUS_UNSUCCESSFUL;
         break;
   }

   TdiCompleteRequest( pIrp, Status );

   return( Status );
}


/////////////////////////////////////////////////////////////////////////////
//// TCPC_DeviceCleanup (IRP_MJ_CLEANUP Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDI TTCP TCP Client device cleanup
// requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pFlushIrp - Pointer to the flush request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

NTSTATUS
TCPC_DeviceCleanup(
    IN PDEVICE_OBJECT pDeviceObject,
    IN PIRP pIrp
    )
{
   PDEVICE_EXTENSION    pDeviceExtension;

   KdPrint(("TCPC_DeviceCleanup: Entry...\n"));

   pDeviceExtension = pDeviceObject->DeviceExtension;

   pIrp->IoStatus.Status = STATUS_SUCCESS;
   pIrp->IoStatus.Information = 0;

   return( STATUS_SUCCESS );
}


/////////////////////////////////////////////////////////////////////////////
//// TCPC_DeviceUnload
//
// Purpose
//
// Parameters
//   pDeviceObject - Pointer to device object created by system.
//
// Return Value
//
// Remarks
//

VOID
TCPC_DeviceUnload(
   IN PDEVICE_OBJECT pDeviceObject
   )
{
   PDEVICE_EXTENSION  pDeviceExtension;

   KdPrint(("TCPC_DeviceUnload: Entry...\n") );

   pDeviceExtension = pDeviceObject->DeviceExtension;

   //
   // Destroy The Symbolic Link
   //
   if( g_bSymbolicLinkCreated )
   {
      UNICODE_STRING UnicodeDeviceName;

      NdisInitUnicodeString(
         &UnicodeDeviceName,
         TDI_TCP_CLIENT_DEVICE_NAME_W
         );

      KS_CreateSymbolicLink(
         &UnicodeDeviceName,
         FALSE
         );
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -