/************************************************************ Start the sending of a packet ************************************************************/ DWORD PacketWrite(POPEN_INSTANCE Open, DWORD dwDDB, DWORD hDevice, PDIOCPARAMETERS pDiocParms ) { PNDIS_PACKET pPacket; PNDIS_BUFFER pNdisBuffer; NDIS_STATUS Status; TRACE_ENTER( "SendPacket" ); PacketAllocatePacketBuffer( &Status, Open, &pPacket, pDiocParms, IOCTL_PROTOCOL_WRITE ); if ( Status != NDIS_STATUS_SUCCESS ) { return 0; } NdisSend( &Status, Open->AdapterHandle, pPacket ); if ( Status != NDIS_STATUS_PENDING ) { PacketSendComplete( Open, pPacket, Status ); } TRACE_LEAVE( "SendPacket" ); return(-1); }
DWORD PacketRead(POPEN_INSTANCE Open, DWORD dwDDB, DWORD hDevice, PDIOCPARAMETERS pDiocParms) { // read a packet NDIS_STATUS Status; PNDIS_PACKET pPacket; // Check that the buffer can hold a max length Ethernet packet if (pDiocParms->cbOutBuffer < ETHERNET_PACKET_LENGTH) { *(DWORD *)(pDiocParms->lpcbBytesReturned) = 0; // Need bigger buffer return NDIS_STATUS_SUCCESS; } PacketAllocatePacketBuffer(&Status, Open, &pPacket, pDiocParms, IOCTL_EPACKET_READ); if (Status == NDIS_STATUS_SUCCESS) { // Put this packet in a list of pending reads. // The receive indication handler will attempt to remove packets // from this list for use in transfer data calls NdisAcquireSpinLock(&Open->RcvQSpinLock); // fixed 6.11.97 InsertTailList(&Open->RcvList, &RESERVED(pPacket)->ListElement); NdisReleaseSpinLock(&Open->RcvQSpinLock); } return -1; // This will make DeviceIOControl return ERROR_IO_PENDING }
DWORD PacketWrite(POPEN_INSTANCE Open, DWORD dwDDB, DWORD hDevice, PDIOCPARAMETERS pDiocParms) { // write a packet PNDIS_PACKET pPacket; NDIS_STATUS Status; PacketAllocatePacketBuffer(&Status, Open, &pPacket, pDiocParms, IOCTL_EPACKET_WRITE); if (Status != NDIS_STATUS_SUCCESS) return 0; // This will return immediately with no data written // Call the MAC NdisSend(&Status, Open->AdapterHandle, pPacket); if (Status != NDIS_STATUS_PENDING) { // The send didn't pend so call the completion handler now PacketSendComplete(Open, pPacket, Status); } return(-1); // This will make DeviceIOControl return ERROR_IO_PENDING }