// windows #include #include // standard #include #include // other #include "device.h" //------------------------------------------------------------------------------ void DeviceReadPacketCallback( PDEVICE_INFO lpDeviceInfo, PUCHAR lpBufferData, ULONG dwBufferSize) { PUCHAR lpFrameData; ULONG dwFrameSize; BOOL bOK; // visual indicator that we received something printf( "."); // skip avs wlan header if (*(ULONG*)(lpBufferData + 0) == _byteswap_ulong( 0x80211001)) { lpFrameData = lpBufferData + _byteswap_ulong( *(ULONG*)(lpBufferData + 4)); dwFrameSize = dwBufferSize - _byteswap_ulong( *(ULONG*)(lpBufferData + 4)); } else { lpFrameData = lpBufferData + 0; dwFrameSize = dwBufferSize - 0; } // write packet bOK = DeviceWritePacket( lpDeviceInfo, lpFrameData, dwFrameSize); if (!bOK) printf( "DeviceWritePacket() failed\n"); } //------------------------------------------------------------------------------ int main( int argc, char *argv[]) { BOOL bOK; DEVICE_INFO DeviceInfo; UCHAR mac[6]; int key; USHORT ver[4]; // application title printf( "\n"); printf( "RT2560 Driver - Test Application \"Echo\" - Version 1.1\n"); printf( "\n"); printf( "(c) 2005 Tim Schuerewegen\n"); printf( "\n"); // ZeroMemory( &DeviceInfo, sizeof( DeviceInfo)); // find device bOK = DeviceFind( &DeviceInfo, 0); if (!bOK) { printf( "DeviceFind() failed\n"); return 0; } // get driver version memset( ver, 0, sizeof( ver)); bOK = DeviceGetDriverVersion( &DeviceInfo, ver); if (!bOK) printf( "DeviceGetDriverVersion() failed\n"); // device info printf( "Device Description = %s\n", DeviceInfo.Description); printf( "Device Hardware ID = %s\n", DeviceInfo.HardwareID); printf( "Device Location = %s\n", DeviceInfo.Location); printf( "Driver Version = %d.%d.%d.%d\n", ver[0], ver[1], ver[2], ver[3]); printf( "\n"); // open device bOK = DeviceOpen( &DeviceInfo); if (!bOK) { printf( "DeviceOpen() failed\n"); return 0; } // set packet filter bOK = DeviceSetPacketFilter( &DeviceInfo, NDIS_PACKET_TYPE_PROMISCUOUS); if (!bOK) printf( "DeviceSetPacketFilter() failed\n"); // get mac address memset( &mac[0], 0, sizeof( mac)); bOK = DeviceGetMacAddress( &DeviceInfo, mac); if (!bOK) printf( "DeviceGetMacAddress() failed\n"); // set channel bOK = DeviceSetChannel( &DeviceInfo, 11); if (!bOK) printf( "DeviceSetChannel() failed\n"); // install ReadPacket callback function bOK = DeviceSetReadPacketCallback( &DeviceInfo, DeviceReadPacketCallback); if (!bOK) printf( "DeviceSetReadPacketCallback() failed\n"); // start receive thread bOK = DeviceThreadReceiveStart( &DeviceInfo); if (!bOK) printf( "DeviceThreadReceiveStart() failed\n"); // wait for key printf( "Press [x] to abort\n"); key = 0; while (key != 'x') { Sleep( 10); if (kbhit()) key = getch(); } // stop receive thread bOK = DeviceThreadReceiveStop( &DeviceInfo); if (!bOK) printf( "DeviceThreadReceiveStop() failed\n"); // remove packet filter bOK = DeviceSetPacketFilter( &DeviceInfo, 0); if (!bOK) printf( "DeviceSetPacketFilter() failed\n"); // close device bOK = DeviceClose( &DeviceInfo); if (!bOK) printf( "DeviceClose() failed\n"); // exit return 0; }