📄 card.cpp
字号:
//
// Data type: NDIS_802_11_AUTHENTICATION_MODE.
// Query: Current mode.
// Set: Set to open or shared or auto-switch.
// Indication: Not supported.
//-----------------------------------------------------------------------
case OID_802_11_AUTHENTICATION_MODE: {
USHORT mode = card->m_activeProfile->zFlags.cfg.AuthenType;
if (mode & AUTH_TYPE_OPEN) {
ndis_authmode = Ndis802_11AuthModeOpen;
}
else if (mode & AUTH_TYPE_SHARED_KEY) {
ndis_authmode = Ndis802_11AuthModeShared;
}
else {
StatusToReturn = NDIS_STATUS_INVALID_DATA;
}
MoveSource = &ndis_authmode;
MoveBytes = sizeof(NDIS_802_11_AUTHENTICATION_MODE);
break;
}
//-----------------------------------------------------------------------
// This object is the MAC address of the associated Access point. Setting
// is useful when doing a site survey.
//
// Data type: NDIS_802_11_MAC_ADDRESS.
// Query: Returns the current AP MAC address.
// Set: Sets the MAC address of the desired AP.
// Indication: Not supported.
//-----------------------------------------------------------------------
case OID_802_11_BSSID: {
if (NDIS_STATUS_MEDIA_DISCONNECT == card->m_MSenceStatus) {
StatusToReturn = NDIS_STATUS_ADAPTER_NOT_READY;
}
else {
MoveSource = &ndis_bssid;
MoveBytes = sizeof(NDIS_802_11_MAC_ADDRESS);
NdisMoveMemory(&ndis_bssid, card->m_BSSID, MoveBytes);
}
break;
}
//-----------------------------------------------------------------------
// Data type: NDIS_802_11_NETWORK_TYPE.
// Query: Returns the current NDIS_802_11_NETWORK_TYPE used by the device.
// Set: Will set the network type that should be used for the driver.
// Indication: Not supported.
//-----------------------------------------------------------------------
case OID_802_11_NETWORK_TYPE_IN_USE: {
if (card->m_activeProfile->zFlags.cfg.RadioType == 1) {
ndis_nettype = Ndis802_11FH;
}
else {
ndis_nettype = Ndis802_11DS;
}
MoveSource = &ndis_nettype;
MoveBytes = sizeof(NDIS_802_11_NETWORK_TYPE);
break;
}
//-----------------------------------------------------------------------
// A set of supported data rates in the operational rate set that the radio
// is capable of running at. Data rates are encoded as 8 octets where each
// octet describes a single supported rate in units of 0.5 Mbps. Supported
// rates belonging to the BSSBasicRateSet are used for frames such as control
// and broadcast frames. Each supported rate belonging to the BSSBasicRateSet
// is encoded as an octet with the msb (bit 7) set to 1 (e.g., a 1 Mbps rate
// belonging to the BSSBasicRateSet is encoded as 0x82). Rates not belonging
// to the BSSBasicRateSet are encoded with the msb set to 0 (e.g., a 2 Mbps
// rate not belonging to the BSSBasicRateSet is encoded as 0x04).
//
// Data type: NDIS_802_11_RATES.
// Query: Returns the set of supported data rates the radio is capable
// of running.
// Set: Not supported.
// Indication: Not supported.
//-----------------------------------------------------------------------
case OID_802_11_RATES_SUPPORTED: {
STCAPS caps;
if (cmdCapsGet(card, &caps)) {
NdisMoveMemory(&ndis_rates, &caps.au8SupportedRates, sizeof(NDIS_802_11_RATES));
MoveSource = &ndis_rates;
MoveBytes = sizeof(NDIS_802_11_RATES);
}
else {
StatusToReturn = NDIS_STATUS_INVALID_DATA;
}
break;
}
//-----------------------------------------------------------------------
// Configures the radio parameters.
//
// Data type: NDIS_802_11_CONFIGURATION.
// Query: Returns the current radio configuration.
// Set: Sets the radio configuration.
// Indication: Not supported.
//-----------------------------------------------------------------------
case OID_802_11_CONFIGURATION: {
STSTATUS status;
if (cmdStatusGet(card, &status)) {
ndis_config.Length = sizeof(NDIS_802_11_CONFIGURATION);
ndis_config.BeaconPeriod = status.u16BeaconPeriod;
ndis_config.ATIMWindow = status.u16AtimDuration;
ndis_config.DSConfig = (BASE_FREQUENCY_MHZ + ((status.u16DsChannel - 1) * 5)) * 1000;
ndis_config.FHConfig.Length = sizeof(NDIS_802_11_CONFIGURATION_FH);
ndis_config.FHConfig.HopPattern = status.u16HopPattern;
//
// NOTE: u16DsChannel and u16HopSet are unioned in the STSTATUS structure.
// Since we don't support frequency hopping, we'll just set hopset to 0.
//
ndis_config.FHConfig.HopSet = 0;
ndis_config.FHConfig.DwellTime = status.u16HopPeriod;
MoveSource = &ndis_config;
MoveBytes = sizeof(NDIS_802_11_CONFIGURATION);
}
else {
StatusToReturn = NDIS_STATUS_INVALID_DATA;
}
break;
}
//-----------------------------------------------------------------------
// Returns the list of all BSSIDs detected including their attributes
// specified in the data structure. The list of BSSIDs returned is the cached
// list stored in the IEEE 802.11 NIC's database. The list of BSSIDs in the
// IEEE 802.11 NIC's database is the set of BSSs detected by the IEEE 802.11 NIC
// during the last survey of potential BSSs. A call to this OID should result in
// an immediate return of the list of BSSIDs in the IEEE 802.11 NIC's database.
// Note that if this OID is called without a preceding OID_802_11_BSSID_LIST_SCAN,
// and the IEEE 802.11 NIC is active, it may return a list of BSSIDs limited to
// those BSSIDs that the IEEE 802.11 NIC considers valid to join based on its
// current configuration. However, if this OID is immediately preceded by
// OID_802_11_BSSID_LIST_SCAN, then the list of BSSIDs should contain all the
// BSSIDs found during the OID_802_11_BSSID_LIST_SCAN.
//
// Data type: NDIS_802_11_BSSID_LIST.
// Query: Array of NDIS_802_11_BSSID_LIST structures.
// Set: Not supported.
// Indication: Not supported.
//-----------------------------------------------------------------------
case OID_802_11_BSSID_LIST: {
#ifdef DEBUG_BSSID_LIST
DbgPrint("OID_802_11_BSSID_LIST: enter\n");
#endif
RID_BSS ridBss;
BOOLEAN emptyList = FALSE;
BOOLEAN endOfList = FALSE;
StatusToReturn = NDIS_STATUS_SUCCESS;
//
// Rebuild the list if we don't have a cached copy.
//
if (card->bssid_list == NULL) {
#ifdef DEBUG_BSSID_LIST
DbgPrint("Rebuilding BSSID list\n");
#endif
NDIS_802_11_BSSID_LIST *ndis_bssid_list = NULL;
//
// Get the first bss rid.
//
if (cmdGetFirstBSS(card, &ridBss, &emptyList)) {
NDIS_802_11_BSSID_LIST *savebssid_list = NULL;
//
// Size of fixed portion of NDIS_802_11_BSSID_LIST.
//
UINT fixedSize = sizeof(NDIS_802_11_BSSID_LIST) - sizeof(NDIS_WLAN_BSSID);
#ifdef DEBUG_BSSID_LIST
DbgPrint("sizeof(NDIS_802_11_BSSID_LIST) = %d\n", sizeof(NDIS_802_11_BSSID_LIST));
DbgPrint("sizeof(NDIS_WLAN_BSSID) = %d\n", sizeof(NDIS_WLAN_BSSID));
DbgPrint("fixedSize = %d\n", fixedSize);
DbgPrint("\n");
int loopCount = 0;
#endif
UINT curSize = fixedSize;
UINT count = 0;
//
// Loop through the rest of the list.
//
do {
#ifdef DEBUG_BSSID_LIST
loopCount++;
char ssid[33];
NdisZeroMemory(ssid, 33);
NdisMoveMemory(ssid, (const char *)ridBss.ssid, MIN(ridBss.ssidLen),32);
DbgPrint("%d) BSSID = %0d:%0d:%0d:%0d:%0d:%0d, SSID = %s\n",
loopCount,
(int)ridBss.bssid[0],
(int)ridBss.bssid[1],
(int)ridBss.bssid[2],
(int)ridBss.bssid[3],
(int)ridBss.bssid[4],
(int)ridBss.bssid[5],
ssid);
// dumpMem(&ridBss, sizeof(RID_BSS), 1);
#endif
//
// Make sure the radio supports 802.11
//
if (ridBss.radioType != RADIO_TYPE_TMA_DS) {
count++;
#ifdef DEBUG_BSSID_LIST
DbgPrint(" count = %d\n", count);
#endif
//
// Hang on to previous list.
//
savebssid_list = ndis_bssid_list;
//
// Allocate new list with one additional element.
//
curSize += sizeof(NDIS_WLAN_BSSID);
ndis_bssid_list = (NDIS_802_11_BSSID_LIST*)(new char[curSize]);
if (ndis_bssid_list != NULL) {
NdisZeroMemory(ndis_bssid_list, curSize);
//
// If there was a previous list, copy it into the new one.
//
if (savebssid_list != NULL) {
NdisMoveMemory(ndis_bssid_list,
savebssid_list,
(curSize - sizeof(NDIS_WLAN_BSSID)));
delete savebssid_list;
savebssid_list = NULL;
}
//
// Check for empty list
//
if (emptyList) {
ndis_bssid_list->NumberOfItems = 0;
}
else {
ndis_bssid_list->NumberOfItems = count;
//
// Just for convenience...
//
NDIS_WLAN_BSSID *bss = &ndis_bssid_list->Bssid[count - 1];
//
// Fill in new list element.
//
NdisMoveMemory(bss->MacAddress, ridBss.bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
NdisZeroMemory(&bss->Reserved, 2);
bss->Ssid.SsidLength = MIN((ULONG)ridBss.ssidLen,(ULONG)32);
NdisMoveMemory(bss->Ssid.Ssid, ridBss.ssid, bss->Ssid.SsidLength);
NdisMoveMemory(&bss->SupportedRates, &ridBss.rates, sizeof(NDIS_802_11_RATES));
bss->Length = sizeof(NDIS_WLAN_BSSID);
bss->Privacy = (ridBss.capability & CAP_PRIVACY) != 0;
bss->Rssi = ridBss.rssi;
bss->NetworkTypeInUse = (ridBss.radioType == RADIO_TYPE_FH) ?
Ndis802_11FH :
Ndis802_11DS;
bss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
bss->Configuration.BeaconPeriod = ridBss.beaconInterval;
bss->Configuration.ATIMWindow = ridBss.atimWindow;
bss->Configuration.DSConfig = (BASE_FREQUENCY_MHZ + ((ridBss.dsChannel - 1) * 5)) * 1000;
bss->Configuration.FHConfig.Length = sizeof(NDIS_802_11_CONFIGURATION_FH);
bss->Configuration.FHConfig.HopPattern = ridBss.fhInfo.hopPattern;
bss->Configuration.FHConfig.HopSet = ridBss.fhInfo.hopSet;
bss->Configuration.FHConfig.DwellTime = ridBss.fhInfo.dwellTime;
bss->InfrastructureMode = (ridBss.capability & CAP_ESS) ?
Ndis802_11Infrastructure :
Ndis802_11IBSS;
}
}
else {
//
// Memory allocation error.
//
StatusToReturn = NDIS_STATUS_RESOURCES;
if (savebssid_list != NULL) {
delete savebssid_list;
}
}
}
else {
//
// not 802.11 so return "not supported".
//
#ifdef DEBUG_BSSID_LIST
DbgPrint(" skipped: does not support 802.11\n");
#endif
// StatusToReturn = NDIS_STATUS_NOT_SUPPORTED;
}
} while ((StatusToReturn == NDIS_STATUS_SUCCESS) && cmdGetNextBSS(card, &ridBss, &endOfList) && !endOfList);
if (StatusToReturn == NDIS_STATUS_SUCCESS) {
card->bssid_list = ndis_bssid_list;
card->bssid_list_count = count;
card->bssid_list_size = curSize;
}
else {
delete [] ndis_bssid_list;
}
}
else {
StatusToReturn = NDIS_STATUS_NOT_SUPPORTED;
}
}
#ifdef DEBUG_BSSID_LIST
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -