+ /* Set the network mode */
+ SetOid->Oid = OID_802_11_INFRASTRUCTURE_MODE;
+ *(PULONG)SetOid->Data = bAdhoc ? Ndis802_11IBSS : Ndis802_11Infrastructure;
+
+ bSuccess = DeviceIoControl(hAdapter,
+ IOCTL_NDISUIO_SET_OID_VALUE,
+ SetOid,
+ SetOidSize,
+ NULL,
+ 0,
+ &dwBytesReturned,
+ NULL);
+ if (!bSuccess)
+ {
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ return FALSE;
+ }
+
+ /* Set the authentication mode */
+ SetOid->Oid = OID_802_11_AUTHENTICATION_MODE;
+ *(PULONG)SetOid->Data = sWepKey ? Ndis802_11AuthModeShared : Ndis802_11AuthModeOpen;
+
+ bSuccess = DeviceIoControl(hAdapter,
+ IOCTL_NDISUIO_SET_OID_VALUE,
+ SetOid,
+ SetOidSize,
+ NULL,
+ 0,
+ &dwBytesReturned,
+ NULL);
+ if (!bSuccess)
+ {
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ return FALSE;
+ }
+
+ if (sWepKey)
+ {
+ PNDIS_802_11_WEP WepData;
+
+ HeapFree(GetProcessHeap(), 0, SetOid);
+
+ SetOidSize = sizeof(NDISUIO_SET_OID) + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial) +
+ (strlen(sWepKey) >> 1);
+ SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
+ if (!SetOid)
+ return FALSE;
+
+ /* Add the WEP key */
+ SetOid->Oid = OID_802_11_ADD_WEP;
+ WepData = (PNDIS_802_11_WEP)SetOid->Data;
+
+ WepData->KeyIndex = 0x80000000;
+ WepData->KeyLength = strlen(sWepKey) >> 1;
+ WepData->Length = FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial) + WepData->KeyLength;
+
+ /* Assemble the hex key */
+ i = 0;
+ while (sWepKey[i << 1] != '\0')
+ {
+ WepData->KeyMaterial[i] = CharToHex(sWepKey[i << 1]) << 4;
+ WepData->KeyMaterial[i] |= CharToHex(sWepKey[(i << 1) + 1]);
+ i++;
+ }
+
+ bSuccess = DeviceIoControl(hAdapter,
+ IOCTL_NDISUIO_SET_OID_VALUE,
+ SetOid,
+ SetOidSize,
+ NULL,
+ 0,
+ &dwBytesReturned,
+ NULL);
+ if (!bSuccess)
+ {
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ return FALSE;
+ }
+ }
+
+ /* Set the encryption status */
+ SetOid->Oid = OID_802_11_WEP_STATUS;
+ *(PULONG)SetOid->Data = sWepKey ? Ndis802_11WEPEnabled : Ndis802_11WEPDisabled;
+
+ bSuccess = DeviceIoControl(hAdapter,
+ IOCTL_NDISUIO_SET_OID_VALUE,
+ SetOid,
+ SetOidSize,
+ NULL,
+ 0,
+ &dwBytesReturned,
+ NULL);
+ if (!bSuccess)
+ {
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ return FALSE;
+ }
+
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ SetOidSize = sizeof(NDISUIO_SET_OID) + sizeof(NDIS_802_11_MAC_ADDRESS);
+ SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
+ if (!SetOid)
+ return FALSE;
+
+ /* Set the BSSID */
+ SetOid->Oid = OID_802_11_BSSID;
+ RtlFillMemory(SetOid->Data, sizeof(NDIS_802_11_MAC_ADDRESS), 0xFF);
+
+ bSuccess = DeviceIoControl(hAdapter,
+ IOCTL_NDISUIO_SET_OID_VALUE,
+ SetOid,
+ SetOidSize,
+ NULL,
+ 0,
+ &dwBytesReturned,
+ NULL);
+ if (!bSuccess)
+ {
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ return FALSE;
+ }
+
+ HeapFree(GetProcessHeap(), 0, SetOid);
+ SetOidSize = sizeof(NDISUIO_SET_OID) + sizeof(NDIS_802_11_SSID);
+ SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
+ if (!SetOid)
+ return FALSE;
+
+ /* Finally, set the SSID */