how to add WEP?

E

Eric Yun

hi everyone,

I am working on a project. One part of this project is force the wireless
network adapter to connect to an access point. I am doing the following way:

1. Set Authentication Mode (0 for Open)
2. Set Infrastructure Mode (1 for Infrastructure)
3. Set SSID
4. Set WEP Key
5. Enable WEP

I found when I remove WEP from my AP, and comment out step 4 & 5, my PC
(actually Pocket PC)will connect to the AP. When I add WEP to AP, and run
steps 1 to 5, my PPC only have IP address like 169.254.xx.xx. The following
is how I add WEP and enable WEP:


/*Add WEP*/
NDIS_802_11_WEP WepKey;

UCHAR KeyMaterial[13];

/*The WEP key is ACDB95776DD114409AB54323C6.
The following steps will convert 26 Digit
Hex key to a 13 bit string*/
KeyMaterial[0] = 0xAC;
KeyMaterial[1] = 0xDB;
KeyMaterial[2] = 0x95;
KeyMaterial[3] = 0x77;
KeyMaterial[4] = 0x6D;
KeyMaterial[5] = 0xD1;
KeyMaterial[6] = 0x14;
KeyMaterial[7] = 0x40;
KeyMaterial[8] = 0x9A;
KeyMaterial[9] = 0xB5;
KeyMaterial[10] = 0x43;
KeyMaterial[11] = 0x23;
KeyMaterial[12] = 0xC6;



WepKey.KeyLength = sizeof(KeyMaterial);
WepKey.KeyIndex = 0;

memset(WepKey.KeyMaterial,0,sizeof(WepKey.KeyMaterial));
memcpy(WepKey.KeyMaterial, KeyMaterial, WepKey.KeyLength);
WepKey.Length = sizeof(WepKey);

if(!AddWEP(&WepKey)) return FALSE;

/* Set WEP status, Mode means enable or disable WEP*/
if(!SetWEPStatus(mode)) return FALSE;







The following is function AddWEP:

BOOL AddWEP(PNDIS_802_11_WEP pWEP)
{
UCHAR SetBuffer[sizeof(NDIS_OID) +
sizeof(PTCHAR)+sizeof(NDIS_802_11_WEP)];
PNDISUIO_SET_OID pSetOid;
DWORD dwBytesReturned=0;

pSetOid = (PNDISUIO_SET_OID) &SetBuffer[0];
pSetOid->Oid = OID_802_11_ADD_WEP;
pSetOid->ptcDeviceName = ptcDeviceName; /*this is because the application
runs on PPC*/

memcpy(&pSetOid->Data[0], (LPVOID)pWEP, sizeof(NDIS_802_11_WEP));

if (!DeviceIoControl(g_hNdisUio,
IOCTL_NDISUIO_SET_OID_VALUE,
(LPVOID)&SetBuffer[0],
sizeof(SetBuffer),
(LPVOID) &SetBuffer[0],
0,
&dwBytesReturned,
NULL))
{

long m_dwError = GetLastError();

TCHAR szOut[64];
wsprintf(szOut, TEXT("Can Not add WEP: %d"),m_dwError );
MessageBox(0,szOut,TEXT("ERROR"),MB_OK);
return FALSE;
}



return TRUE;
}


Does anyone know what is wrong with my code? I haven't been stuck here for a
couple of days...

Thanks,

Eric
 
N

Niklas

Shouldn't KeyIndex be 0x80000000 (if the first key is used to transmit,
0x80000001 for second...)?
If think it matters in which order you set the oids and I would set the
AuthenticationMode after you have set the wepkey, but maybe it's just me who
think it matters.

you should get the checkbuild of wzcsvc and log what windows does.

/Niklas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top