Hi
I am trying to control the association of a wireless adapter through NDIS
miniport driver. I did not write a specific driver myself. Using
DeviceIOControl() function, I can query all the OIDs of interest without any
difficulty, that is fine. My problem is that I need to set OID_802_11_BSSID
to a specific value to control where I want my wireless adapter to connect.
Here is the code snippet that I am trying to get to work:
BOOL SetAssociated( LPCTSTR lpAdapterName,
NDIS_802_11_MAC_ADDRESS DestinationMacAddress)
{
UCHAR SetBuffer[sizeof(NDISUIO_SET_OID) +
sizeof(NDIS_802_11_MAC_ADDRESS)];
PNDISUIO_SET_OID pSetOid;
DWORD dwBytesReturned=0;
int i = 0, nResult;
TCHAR szOut[64];
long e;
HANDLE hNIC;
UCHAR szMACFileName[512];
pSetOid = (PNDISUIO_SET_OID) &SetBuffer[0];
pSetOid->Oid = OID_802_11_BSSID;
for ( i = 0; i < 6; i++ )
{
pSetOid->Data[i] = DestinationMacAddress[i];
}
//
// Construct a device name to pass to CreateFile
//
strcpy(szMACFileName, DEVICE_PREFIX);
strcat(szMACFileName, lpAdapterName);
hNIC = CreateFile(
szMACFileName,
GENERIC_READ|GENERIC_WRITE, // Device Query Access
FILE_SHARE_READ | FILE_SHARE_WRITE, //FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, //0,
NULL //INVALID_HANDLE_VALUE
);
nResult = GetLastError();
if (hNIC != INVALID_HANDLE_VALUE)
{
//
// We successfully opened the driver, format the IOCTL to pass the
// driver.
//
nResult = DeviceIoControl(
hNIC,
IOCTL_NDISUIO_SET_OID_VALUE,
(LPVOID) &SetBuffer[0],
sizeof(SetBuffer),
(LPVOID) &SetBuffer[0],
0,
&dwBytesReturned,
NULL
);
if( nResult == 0) /// there was an error, print it out.
{
e = GetLastError();
wsprintf(szOut, TEXT("Set Associated AP/PC ERROR\nError Code:
%d"),e );
MessageBox(0,szOut,TEXT("Error"),MB_OK);
return FALSE;
}
}
return TRUE;
}
I have tried many variations of the above but could not get anything to work
yet. I tried both with WZC running or stopped, same results. The
CreateFile() function returns no error, but DeviceIOControl() returns with
error code 1 (ERROR_INVALID_FUNCTION)
Thanks in advance.
Bruce