Link to home
Start Free TrialLog in
Avatar of crayola3
crayola3

asked on

Programmatically switching the WEP key

I need to change the WEP key on my wireless connection to Win XP/CE on demand through a C++ program.  I looked for an ntddndis.h file - is it available somewhere on my windows system folder?  I can't find it.   I looked around here and MSDN - do you need to use the OID_802_11_ADD_WEP function?  Is it built in somewhere in a library?
ASKER CERTIFIED SOLUTION
Avatar of opanza
opanza

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of crayola3
crayola3

ASKER

Getting many compile errors on your code - I'm likely not including something correctly -- either a missing .h or some variables I need are not defined.

What are m_pwDeviceName, m_hFileHandle and GetLastError() ?  Are they included somewhere or do I need to define them?

I have your code in my gw.cpp source file:

#include "stdafx.h"
#include "ntddndis.h"

HRESULT SetWEPKey(PNDIS_802_11_WEP pWepKey) <-- I get a compile syntax error -- HRESULT not defined ?
{
UCHAR               SetBuffer[ 1024 ] = { 0 };
PNDISUIO_SET_OID    pSetOid;     <--- I get compile syntax errors here -- PNDISUIO_SET_OID not defined ?
HRESULT                  hRes = S_OK;
DWORD                    dwBytesReturned = 0;

     pSetOid = (PNDISUIO_SET_OID)SetBuffer;
     pSetOid->Oid = OID_802_11_ADD_WEP;
     pSetOid->ptcDeviceName = m_pwDeviceName;

     memcpy( pSetOid->Data, (LPVOID)pWepKey, pWepKey->Length );

     if( DeviceIoControl( m_hFileHandle,
                          IOCTL_NDISUIO_SET_OID_VALUE,
                          (LPVOID)SetBuffer,
                          sizeof( SetBuffer ),
                          (LPVOID)SetBuffer,
                          0,
                          &dwBytesReturned,
                          NULL ) )
     {
          hRes = S_OK;
     }
     else
     {
          hRes = GetLastError();
     }

     return hRes;
}
int main(int argc, char* argv[])
{
NDIS_802_11_WEP WepKey;
UCHAR KeyMaterial[13];
HRESULT hr;

// Key 1 (WEP key you want to set)
// 0123456789ABCDEF0123456789
KeyMaterial[0] = 0x01;
KeyMaterial[1] = 0x23;
KeyMaterial[2] = 0x45;
KeyMaterial[3] = 0x67;
KeyMaterial[4] = 0x89;
KeyMaterial[5] = 0xAB;
KeyMaterial[6] = 0xCD;
KeyMaterial[7] = 0xEF;
KeyMaterial[8] = 0x01;
KeyMaterial[9] = 0x23;
KeyMaterial[10] = 0x45;
KeyMaterial[11] = 0x67;
KeyMaterial[12] = 0x89;

// Fill in WEP Key structure

// key index - 0
WepKey.KeyIndex = 0x80000000;
WepKey.KeyLength = sizeof( KeyMaterial );

// Copy WEP Key
memset(WepKey.KeyMaterial,0,sizeof(WepKey.KeyMaterial));
memcpy(WepKey.KeyMaterial, KeyMaterial, WepKey.KeyLength);
WepKey.Length = sizeof(NDIS_802_11_WEP) + WepKey.KeyLength;

// Set the key
if( ( hr = SetWEPKey(&WepKey) ) == S_OK )
{
     //WEP Key 1 set
}
else
{
     // Error setting key
}
      printf("Hello World!\n");
      return 0;
}
I solved this problem by installing the Platform SDK.
This post talks about it as well:

https://www.experts-exchange.com/questions/21250950/Compiling-WRAPI-dlls-and-WrapiTest-cpp.html