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

Re: Setting OID_802_11_BSSID through DeviceIOControl() by Maxim

Maxim
Wed Aug 29 05:29:36 CDT 2007

I think that this is not doable, since WZC will override your config and
enforce its own.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com

"Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message
news:B367B505-6051-4C8D-B17B-6403E8445566@microsoft.com...
> 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


Re: Setting OID_802_11_BSSID through DeviceIOControl() by BruceTovac

BruceTovac
Wed Aug 29 21:00:02 CDT 2007

I tried running the same code with WZC disabled and it still not works. If
anyone can help me get the code running without WZC that'll be very helpful.

Thanks

Bruce

"Maxim S. Shatskih" wrote:

> I think that this is not doable, since WZC will override your config and
> enforce its own.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
> "Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message
> news:B367B505-6051-4C8D-B17B-6403E8445566@microsoft.com...
> > 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
>
>

Re: Setting OID_802_11_BSSID through DeviceIOControl() by Pavel

Pavel
Sat Sep 01 15:56:31 PDT 2007

Please give Wlan API a try ( in MSDN: look under "Native wi-fi" ).
NDISUIO is the wrong way.

--PA

"Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message news:3A0A5060-569A-4369-B47B-350BE027F738@microsoft.com...
>I tried running the same code with WZC disabled and it still not works. If
> anyone can help me get the code running without WZC that'll be very helpful.
>
> Thanks
>
> Bruce
>
> "Maxim S. Shatskih" wrote:
>
>> I think that this is not doable, since WZC will override your config and
>> enforce its own.
>>
>> --
>> Maxim Shatskih, Windows DDK MVP
>> StorageCraft Corporation
>> maxim@storagecraft.com
>> http://www.storagecraft.com
>>
>> "Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message
>> news:B367B505-6051-4C8D-B17B-6403E8445566@microsoft.com...
>> > 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
>>
>>



Re: Setting OID_802_11_BSSID through DeviceIOControl() by BruceTovac

BruceTovac
Mon Sep 03 08:02:28 PDT 2007

Thanks Pavel for your pointer. I looked in MSDN and it seems that the WLAN
API is listed only under Windows CE. I am running Windows XP with a
micration path to Vista next year, and my understanding is that WLAN API is
not supported under any of these platforms. Am I mistaken?

My preference would really to get it to work with NDISUIO.

Bruce

"Pavel A." wrote:

> Please give Wlan API a try ( in MSDN: look under "Native wi-fi" ).
> NDISUIO is the wrong way.
>
> --PA
>
> "Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message news:3A0A5060-569A-4369-B47B-350BE027F738@microsoft.com...
> >I tried running the same code with WZC disabled and it still not works. If
> > anyone can help me get the code running without WZC that'll be very helpful.
> >
> > Thanks
> >
> > Bruce
> >
> > "Maxim S. Shatskih" wrote:
> >
> >> I think that this is not doable, since WZC will override your config and
> >> enforce its own.
> >>
> >> --
> >> Maxim Shatskih, Windows DDK MVP
> >> StorageCraft Corporation
> >> maxim@storagecraft.com
> >> http://www.storagecraft.com
> >>
> >> "Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message
> >> news:B367B505-6051-4C8D-B17B-6403E8445566@microsoft.com...
> >> > 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
> >>
> >>
>
>
>

Re: Setting OID_802_11_BSSID through DeviceIOControl() by Stephan

Stephan
Wed Sep 05 05:15:21 PDT 2007

First, you should not try to communicate with the NDISUIO driver that
comes with Windows because IIRC it is slightly different in all
Windows variants and you never know exactly which NDISUIO version you
are currently talking to. This is why the NDISUIO driver sample in the
DDK/WDK has been renamed to NDISPROT some time ago. You could modify
and use your own NDISPROT driver to set OIDs.

The NDIS Wrapper itself also provides an I/O control interface, which
allows you to (unfortunately only) read OIDs via
IOCTL_NDIS_QUERY_GLOBAL_STATS, see

"How can I access my NDIS miniport driver from a user-mode
application?"
http://www.ndis.com/faq/QA10290101.htm

Sample source code is here:

http://www.pcausa.com/Utilities/macaddr2.htm

IIRC, there is another way to set OIDs wihtout using NDISUIO or some
self-made driver. I'll have to check my archives...

Stephan


Re: Setting OID_802_11_BSSID through DeviceIOControl() by Maxim

Maxim
Wed Sep 05 08:22:13 PDT 2007

Correct, on Windows NT, NDISUIO is not a part of the official platform and
should be considered to be as "auxiliary shim for WZC service".

The sources (maybe 99% matching the real binary and 100% working) are
distributed under the name of NDISPROT in the DDK/WDK.

On Windows CE, on the other side, NDISUIO is the documented part of the
platform. A very convinient thing to control your NDIS IMs.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com

"Stephan Wolf [MVP]" <stewo68@hotmail.com> wrote in message
news:1188994521.190427.193160@50g2000hsm.googlegroups.com...
> First, you should not try to communicate with the NDISUIO driver that
> comes with Windows because IIRC it is slightly different in all
> Windows variants and you never know exactly which NDISUIO version you
> are currently talking to. This is why the NDISUIO driver sample in the
> DDK/WDK has been renamed to NDISPROT some time ago. You could modify
> and use your own NDISPROT driver to set OIDs.
>
> The NDIS Wrapper itself also provides an I/O control interface, which
> allows you to (unfortunately only) read OIDs via
> IOCTL_NDIS_QUERY_GLOBAL_STATS, see
>
> "How can I access my NDIS miniport driver from a user-mode
> application?"
> http://www.ndis.com/faq/QA10290101.htm
>
> Sample source code is here:
>
> http://www.pcausa.com/Utilities/macaddr2.htm
>
> IIRC, there is another way to set OIDs wihtout using NDISUIO or some
> self-made driver. I'll have to check my archives...
>
> Stephan
>


Re: Setting OID_802_11_BSSID through DeviceIOControl() by Stephan

Stephan
Fri Sep 14 00:55:04 PDT 2007

On Sep 5, 2:15 pm, "Stephan Wolf [MVP]" <stew...@hotmail.com> wrote:
> IIRC, there is another way to set OIDs wihtout using NDISUIO or some
> self-made driver. I'll have to check my archives...

You can use Native Wifi API functions to initiate certain actions like
e.g. a WLAN scan via WZCRefreshInterface(). See

http://msdn2.microsoft.com/library/
> Win32 and COM Development
> Networking
> Network Management
> Native Wifi
> Wireless Zero Configuration Reference
> Wireless Zero Configuration Functions

Stephan


Re: Setting OID_802_11_BSSID through DeviceIOControl() by Pavel

Pavel
Thu Sep 27 17:40:37 PDT 2007

Apologies for late reply. Yes, WLAN (aka "Native wi-fi") API exists on Vista,
and a subset of it exists for XP SP2.
Hope the OP already found the docum in MSDN.

Regards,
--PA

"Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message news:778FC85D-1CC5-4EAE-B32E-6E30E751CFF6@microsoft.com...
> Thanks Pavel for your pointer. I looked in MSDN and it seems that the WLAN
> API is listed only under Windows CE. I am running Windows XP with a
> micration path to Vista next year, and my understanding is that WLAN API is
> not supported under any of these platforms. Am I mistaken?
>
> My preference would really to get it to work with NDISUIO.
>
> Bruce
>
> "Pavel A." wrote:
>
>> Please give Wlan API a try ( in MSDN: look under "Native wi-fi" ).
>> NDISUIO is the wrong way.
>>
>> --PA
>>
>> "Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message
>> news:3A0A5060-569A-4369-B47B-350BE027F738@microsoft.com...
>> >I tried running the same code with WZC disabled and it still not works. If
>> > anyone can help me get the code running without WZC that'll be very helpful.
>> >
>> > Thanks
>> >
>> > Bruce
>> >
>> > "Maxim S. Shatskih" wrote:
>> >
>> >> I think that this is not doable, since WZC will override your config and
>> >> enforce its own.
>> >>
>> >> --
>> >> Maxim Shatskih, Windows DDK MVP
>> >> StorageCraft Corporation
>> >> maxim@storagecraft.com
>> >> http://www.storagecraft.com
>> >>
>> >> "Bruce Tovac" <BruceTovac@discussions.microsoft.com> wrote in message
>> >> news:B367B505-6051-4C8D-B17B-6403E8445566@microsoft.com...
>> >> > 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
>> >>
>> >>
>>
>>
>>