📄 cardif_windows_dot11.c
字号:
char *key, int keylen)
{
char seq[6] = {0x00,0x00,0x00,0x00,0x00,0x00};
return cardif_windows_dot11_set_key_ext(ctx, ALG_CCMP, addr, keyidx, settx,
seq, 6, key, keylen);
}
/**
* Set the WPA IE that is in use for this interface.
* On Windows, we don't have the ability to send in an IE, so this function
* does nothing.
**/
int cardif_windows_dot11_set_wpa_ie(context *ctx,
unsigned char *wpaie, unsigned int wpalen)
{
return XENONE;
}
/**
* Convert our cipher designator to something that will be understood by
* Windows.
*/
DWORD cardif_windows_dot11_cipher(int cipher)
{
switch (cipher)
{
case CIPHER_NONE:
return 0xffffffff;
break;
case CIPHER_WEP40:
return Ndis802_11Encryption1Enabled;
break;
case CIPHER_TKIP:
return Ndis802_11Encryption2Enabled;
break;
case CIPHER_WRAP:
debug_printf(DEBUG_NORMAL, "WRAP is not supported!\n");
return 0xffffffff;
break;
case CIPHER_CCMP:
return Ndis802_11Encryption3Enabled;
break;
case CIPHER_WEP104:
return Ndis802_11Encryption1Enabled;
break;
default:
debug_printf(DEBUG_NORMAL, "Unknown cipher value of %d!\n", cipher);
return 0xff;
break;
}
}
/**
* Set all of the card settings that are needed in order to complete an
* association, so that we can begin the authentication.
**/
void cardif_windows_dot11_associate(context *ctx)
{
struct config_globals *globals;
wireless_ctx *wctx;
DWORD enc_mode;
if (!xsup_assert((ctx != NULL), "ctx != NULL", FALSE))
return;
wctx = (wireless_ctx *)ctx->intTypeData;
if (!xsup_assert((wctx != NULL), "wctx != NULL", FALSE)) return;
debug_printf(DEBUG_INT, "(Associate) Set infra mode.\n");
if (cardif_windows_dot11_set_infra_mode(ctx) != 0)
{
debug_printf(DEBUG_NORMAL, "Request to set infrastructure mode failed.\n");
return;
}
if (config_ssid_get_ssid_abilities(ctx->intTypeData) & RSN_IE)
{
wctx->assoc_type = ASSOC_TYPE_WPA2;
// We are doing WPA2.
if (ctx->conn->association.auth_type != AUTH_PSK)
{
debug_printf(DEBUG_INT, "(Associate) Set auth mode. (WPA2-802.1X)\n");
if (cardif_windows_dot11_set_auth_mode(ctx, Ndis802_11AuthModeWPA2) != 0)
{
debug_printf(DEBUG_NORMAL, "Couldn't set the authentication mode to WPA2-Enterprise.\n");
return;
}
}
else
{
debug_printf(DEBUG_INT, "(Associate) Set auth mode. (WPA2-PSK)\n");
if (cardif_windows_dot11_set_auth_mode(ctx, Ndis802_11AuthModeWPA2PSK) != 0)
{
debug_printf(DEBUG_NORMAL, "Request to set the authentication mode to WPA2-PSK failed.\n");
return;
}
}
wctx->groupKeyType = wpa2_get_group_crypt(ctx);
wctx->pairwiseKeyType = wpa2_get_pairwise_crypt(ctx);
} else if (config_ssid_get_ssid_abilities(ctx->intTypeData) & WPA_IE)
{
wctx->assoc_type = ASSOC_TYPE_WPA1;
// We are doing WPA1.
if (ctx->conn->association.auth_type != AUTH_PSK)
{
debug_printf(DEBUG_INT, "(Associate) Set auth mode. (WPA-802.1X)\n");
if (cardif_windows_dot11_set_auth_mode(ctx, Ndis802_11AuthModeWPA) != 0)
{
debug_printf(DEBUG_NORMAL, "Couldn't set the authentication mode to WPA-Enterprise.\n");
return;
}
}
else
{
debug_printf(DEBUG_INT, "(Associate) Set auth mode. (WPA-PSK)\n");
if (cardif_windows_dot11_set_auth_mode(ctx, Ndis802_11AuthModeWPAPSK) != 0)
{
debug_printf(DEBUG_NORMAL, "Couldn't set the authentication mode to WPA-PSK.\n");
return;
}
}
wctx->groupKeyType = wpa_get_group_crypt(ctx);
wctx->pairwiseKeyType = wpa_get_pairwise_crypt(ctx);
}
enc_mode = cardif_windows_dot11_cipher(wctx->pairwiseKeyType);
debug_printf(DEBUG_INT, "(Associate) Set encryption mode.\n");
if (cardif_windows_dot11_set_enc_mode(ctx, enc_mode) != 0)
{
debug_printf(DEBUG_NORMAL, "Request to set encryption mode failed.\n");
return;
}
wctx = (wireless_ctx *)ctx->intTypeData;
if (!xsup_assert((wctx != NULL), "wctx != NULL", FALSE)) return;
debug_printf(DEBUG_INT, "(Associate) Set SSID.\n");
if (cardif_windows_dot11_set_ssid(ctx, wctx->cur_essid) != 0)
{
debug_printf(DEBUG_NORMAL, "Request to set the SSID failed.\n");
return;
}
return;
}
// Windows doesn't seem to distinguish between WEP40 and WEP104. So, "DOES_WEP" defines both.
#define DOES_WEP (DOES_WEP40 | DOES_WEP104)
/**
* Determine the types of encryption supported.
**/
void cardif_windows_dot11_enc_mode_supported(NDIS_802_11_ENCRYPTION_STATUS es, uint32_t *enc)
{
switch (es)
{
// The values below should never come up in the results.
case Ndis802_11EncryptionNotSupported:
case Ndis802_11EncryptionDisabled:
case Ndis802_11Encryption1KeyAbsent:
case Ndis802_11Encryption2KeyAbsent:
case Ndis802_11Encryption3KeyAbsent:
break;
default:
debug_printf(DEBUG_NORMAL, "Unknown/Invalid encryption method. (%d)\n", es);
break;
case Ndis802_11Encryption1Enabled:
(*enc) |= (DOES_WEP);
break;
case Ndis802_11Encryption2Enabled:
(*enc) |= (DOES_WEP | DOES_TKIP);
break;
case Ndis802_11Encryption3Enabled:
(*enc) |= (DOES_WEP | DOES_TKIP | DOES_CCMP);
break;
}
}
/**
* Determine the authentication modes supported.
**/
void cardif_windows_dot11_auth_mode_supported(NDIS_802_11_AUTHENTICATION_MODE am, uint32_t *capa)
{
switch (am)
{
// Don't currently care about these.
case Ndis802_11AuthModeOpen:
case Ndis802_11AuthModeShared:
case Ndis802_11AuthModeAutoSwitch:
break;
case Ndis802_11AuthModeWPA:
case Ndis802_11AuthModeWPAPSK:
case Ndis802_11AuthModeWPANone:
(*capa) |= DOES_WPA;
break;
case Ndis802_11AuthModeWPA2:
case Ndis802_11AuthModeWPA2PSK:
(*capa) |= DOES_WPA2;
break;
default:
printf("Unknown authentication mode %d!\n", am);
break;
}
}
/**
* Determine the encryption capabilities for this driver/interface.
**/
void cardif_windows_dot11_enc_capabilities(context *ctx)
{
struct win_sock_data *sockData;
DWORD BytesReturned;
UCHAR QueryBuffer[1024];
PNDISPROT_QUERY_OID pQueryOid;
PNDIS_802_11_CAPABILITY pCapa;
int i;
wireless_ctx *wctx;
if (!xsup_assert((ctx != NULL), "ctx != NULL", FALSE)) return;
wctx = (wireless_ctx *)ctx->intTypeData;
if (!xsup_assert((wctx != NULL), "wctx != NULL", FALSE)) return;
sockData = ctx->sockData;
if (!xsup_assert((sockData != NULL), "sockData != NULL", FALSE)) return;
pQueryOid = (PNDISPROT_QUERY_OID)&QueryBuffer[0];
pQueryOid->Oid = OID_802_11_CAPABILITY;
if (devioctl_blk(sockData->devHandle, IOCTL_NDISPROT_QUERY_OID_VALUE, &QueryBuffer[0],
sizeof(QueryBuffer), &QueryBuffer[0], sizeof(QueryBuffer), &BytesReturned) == FALSE)
{
debug_printf(DEBUG_NORMAL, "Unable to determine the capabilities of this interface.\n");
wctx->enc_capa = 0;
return;
}
pCapa = (PNDIS_802_11_CAPABILITY)&pQueryOid->Data[0];
for (i=0; i < (int)pCapa->NoOfAuthEncryptPairsSupported; i++)
{
cardif_windows_dot11_auth_mode_supported(pCapa->AuthenticationEncryptionSupported[i].AuthModeSupported, &wctx->enc_capa);
cardif_windows_dot11_enc_mode_supported(pCapa->AuthenticationEncryptionSupported[i].EncryptStatusSupported, &wctx->enc_capa);
}
}
/**
* Delete any keys that are currently installed in the driver/interface.
**/
int cardif_windows_dot11_delete_key(context *ctx, int key_idx, int set_tx)
{
struct win_sock_data *sockData;
DWORD BytesReturned;
UCHAR Buffer[sizeof(NDIS_OID)+sizeof(NDIS_802_11_REMOVE_KEY)];
PNDISPROT_SET_OID pSetOid;
PNDIS_802_11_REMOVE_KEY pRkey;
LPVOID lpMsgBuf;
if (!xsup_assert((ctx != NULL), "ctx != NULL", FALSE)) return -1;
sockData = ctx->sockData;
if (!xsup_assert((sockData != NULL), "sockData != NULL", FALSE)) return -1;
pSetOid = (PNDISPROT_SET_OID)&Buffer[0];
pSetOid->Oid = OID_802_11_REMOVE_KEY;
pRkey = (PNDIS_802_11_REMOVE_KEY)&pSetOid->Data[0];
pRkey->Length = sizeof(NDIS_802_11_REMOVE_KEY);
pRkey->KeyIndex = 0;
pRkey->KeyIndex = key_idx;
if (set_tx == TRUE)
{
memcpy(pRkey->BSSID, &ctx->dest_mac[0], 6);
pRkey->KeyIndex |= (1 << 30);
}
else
{
memset(pRkey->BSSID, 0xff, 6);
}
if (devioctl_blk(sockData->devHandle, IOCTL_NDISPROT_SET_OID_VALUE,
(LPVOID)&Buffer[0], sizeof(Buffer), NULL, 0, &BytesReturned) == FALSE)
{
debug_printf(DEBUG_NORMAL, "Remove Key IOCTL failed.\n");
lpMsgBuf = GetLastErrorStr(GetLastError());
debug_printf(DEBUG_NORMAL, "Reason was : %s\n", lpMsgBuf);
LocalFree(lpMsgBuf);
return -1;
}
return XENONE;
}
/**
* Enable the filter that only allows for EAPoL frames to get through.
**/
int cardif_windows_dot11_drop_unencrypted(context *ctx, char endis)
{
struct win_sock_data *sockData;
DWORD BytesReturned;
UCHAR Buffer[sizeof(NDIS_OID)+sizeof(NDIS_802_11_PRIVACY_FILTER)];
PNDISPROT_SET_OID pSetOid;
DWORD *filter;
if (!xsup_assert((ctx != NULL), "ctx != NULL", FALSE)) return -1;
sockData = ctx->sockData;
if (!xsup_assert((sockData != NULL), "sockData != NULL", FALSE)) return -1;
pSetOid = (PNDISPROT_SET_OID)&Buffer[0];
pSetOid->Oid = OID_802_11_PRIVACY_FILTER;
filter = (DWORD *)&pSetOid->Data[0];
if (endis == TRUE)
{
(*filter) = Ndis802_11PrivFilter8021xWEP;
}
else
{
(*filter) = Ndis802_11PrivFilterAcceptAll;
}
if (devioctl_blk(sockData->devHandle, IOCTL_NDISPROT_SET_OID_VALUE, &Buffer[0],
sizeof(Buffer), NULL, 0, &BytesReturned) == FALSE)
{
debug_printf(DEBUG_NORMAL, "Couldn't set privacy filter status.\n");
return -1;
}
return XENONE;
}
/**
* Take the RSSI value that Windows returns, and convert it to a percentage. This
* call will only return something valid if the interface is associated. If the
* interface isn't associated, then this function will return -1.
**/
int cardif_windows_dot11_get_percent(context *ctx)
{
struct win_sock_data *sockData;
DWORD BytesReturned;
UCHAR QueryBuffer[1024];
PNDISPROT_QUERY_OID pQueryOid;
NDIS_802_11_RSSI *pRssi;
int i;
int percentage = -1;
wireless_ctx *wctx;
if (!xsup_assert((ctx != NULL), "ctx != NULL", FALSE)) return -1;
wctx = (wireless_ctx *)ctx->intTypeData;
if (!xsup_assert((wctx != NULL), "wctx != NULL", FALSE)) return -1;
sockData = ctx->sockData;
if (!xsup_assert((sockData != NULL), "sockData != NULL", FALSE)) return -1;
pQueryOid = (PNDISPROT_QUERY_OID)&QueryBuffer[0];
pQueryOid->Oid = OID_802_11_RSSI;
if (devioctl_blk(sockData->devHandle, IOCTL_NDISPROT_QUERY_OID_VALUE, &QueryBuffer[0],
sizeof(QueryBuffer), &QueryBuffer[0], sizeof(QueryBuffer), &BytesReturned) == FALSE)
{
debug_printf(DEBUG_NORMAL, "Couldn't determine the RSSI value for interface %s.\n",
ctx->desc);
return -1;
}
pRssi = (NDIS_802_11_RSSI *)&pQueryOid->Data[0];
// According to the windows documentation, the RSSI should vary between
// -10 and -200 dBm. So, we need to figure out a percentage based on that.
// However, many examples on the net show that valid ranges will run from -50 to -100.
percentage = (((*pRssi) + 100)*2); // Make the dBm a positive number, and the lowest value
// equal to 0. (So, the range will now be 0 - 190.)
// percentage = (int)(((float)percentage/(float)190) * 100); // And make it a percentage.
return percentage;
}
struct cardif_funcs cardif_windows_dot11_driver = {
cardif_windows_dot11_scan, // .scan
cardif_windows_dot11_disassociate, // .disassociate
cardif_windows_dot11_set_WEP_key, // .set_wep_key
cardif_windows_dot11_set_tkip_key, // .set_tkip_key
cardif_windows_dot11_set_ccmp_key, // .set_ccmp_key
cardif_windows_dot11_delete_key, // .delete_key
cardif_windows_dot11_associate, // .associate
cardif_windows_dot11_get_ssid, // .get_ssid
cardif_windows_dot11_get_bssid, // .get_bssid
NULL, // .wpa_state
NULL, // .wpa
cardif_windows_dot11_wep_associate, // .wep_associate
NULL, // .countermeasures
cardif_windows_dot11_drop_unencrypted, // .drop_unencrypted
cardif_windows_dot11_get_wpa_ie, // .get_wpa_ie
cardif_windows_dot11_get_wpa2_ie, // .get_wpa2_ie
cardif_windows_dot11_enc_disable, // .enc_disable
cardif_windows_dot11_enc_capabilities, // .enc_capabilities
cardif_windows_dot11_set_bssid, // .set_bssid
NULL, // .set_operstate
NULL, // .set_linkmode
cardif_windows_dot11_get_percent, // .get_signal_percent
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -