📄 wlan_cmd.c
字号:
WLAN_802_11_SSID *ssid;
#endif
u16 TmpCap;
ENTER();
if (!Adapter)
return -ENODEV;
cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
cmd->Size = sizeof(HostCmd_DS_802_11_ASSOCIATE) + S_DS_GEN - sizeof(pAsso->RsnIE);
if (Adapter->RequestViaBSSID)
pReqBSSID = Adapter->RequestedBSSID;
/*
* find out the BSSID that matches
* the SSID given in InformationBuffer
*/
PRINTK1("NumOfBSSIDs = %u\n", Adapter->ulNumOfBSSIDs);
PRINTK1("Wanted SSID = %s\n", ((WLAN_802_11_SSID *)InfoBuf)->Ssid);
#ifdef DEBUG
for (i = 0; i < Adapter->ulNumOfBSSIDs; i++) {
ssid = &Adapter->BSSIDList[i].Ssid;
PRINTK1("Listed SSID = %s\n", ssid->Ssid);
}
#endif
i = FindSSIDInList(Adapter, InfoBuf, pReqBSSID,
Wlan802_11Infrastructure);
if (i >= 0) {
memmove(pAsso->PeerStaAddr, &(Adapter->BSSIDList[i].MacAddress),
ETH_ALEN);
} else {
PRINTK1("HWAC - SSID is not in the list\n");
return -1;
}
/* check if the requested SSID is already associated */
if ((Adapter->CurBssParams.ssid.SsidLength != 0) &&
!SSIDcmp(InfoBuf, &Adapter->CurBssParams.ssid) &&
!memcmp(Adapter->CurrentBSSID,
Adapter->BSSIDList[i].MacAddress, ETH_ALEN)) {
if ((&(Adapter->CurrentBSSIDDescriptor) != NULL)) {
if (Adapter->CurrentBSSIDDescriptor.
InfrastructureMode
== Wlan802_11Infrastructure) {
/*
* current associated SSID is same
* as the new one
*/
PRINTK1("*** new SSID is the"
"same as current, not"
"attempting to re-associate\n");
return -1;
}
}
}
/* Set the temporary BSSID Index */
Adapter->ulAttemptedBSSIDIndex = i;
/* set failure-time-out */
pAsso->FailTimeOut = wlan_cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
// set preamble to firmware
if (Adapter->capInfo.ShortPreamble
&& Adapter->BSSIDList[i].Cap.ShortPreamble) {
Adapter->Preamble = HostCmd_TYPE_SHORT_PREAMBLE;
} else {
Adapter->Preamble = HostCmd_TYPE_LONG_PREAMBLE;
}
SetRadioControl(priv);
/* set the Capability info */
memcpy(&pAsso->CapInfo, &Adapter->BSSIDList[i].Cap,
sizeof(pAsso->CapInfo));
memcpy(&TmpCap, &pAsso->CapInfo, sizeof(pAsso->CapInfo));
TmpCap &= CAPINFO_MASK;
PRINTK("TmpCap=%4X CAPINFO_MASK=%4X\n", TmpCap, CAPINFO_MASK);
TmpCap = wlan_cpu_to_le16(TmpCap);
memcpy(&pAsso->CapInfo, &TmpCap, sizeof(pAsso->CapInfo));
memcpy(pAsso->SsId,
Adapter->BSSIDList
[Adapter->ulAttemptedBSSIDIndex].Ssid.Ssid,
Adapter->BSSIDList
[Adapter->ulAttemptedBSSIDIndex].Ssid.SsidLength);
memcpy(&pAsso->PhyParamSet.DsParamSet, &(Adapter->BSSIDList[Adapter->
ulAttemptedBSSIDIndex].PhyParamSet.DsParamSet),
sizeof(pAsso->PhyParamSet.DsParamSet));
memcpy(&pAsso->DataRates,&(Adapter->BSSIDList[Adapter->
ulAttemptedBSSIDIndex]. SupportedRates),
sizeof(pAsso->DataRates));
#ifdef WPA
if (Adapter->SecInfo.WPAEnabled
#ifdef WPA2
|| Adapter->SecInfo.WPA2Enabled
#endif //WPA2
) {
memcpy(pAsso->RsnIE, Adapter->Wpa_ie, sizeof(pAsso->RsnIE));
cmd->Size += Adapter->Wpa_ie[1] + 2; // ID and length field!
#ifdef DEBUG
HEXDUMP("RSN IE : ", (u8*)pAsso->RsnIE, sizeof(pAsso->RsnIE));
#endif
}
#endif //WPA
cmd->Size = wlan_cpu_to_le16(cmd->Size);
#ifdef MULTI_BANDS
if (Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band ==
BAND_A) {
card_rates = SupportedRates_A;
card_rates_size = sizeof(SupportedRates_A);
}
else if (Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band ==
BAND_B) {
card_rates = SupportedRates_B;
card_rates_size = sizeof(SupportedRates_B);
}
else if (Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band ==
BAND_G) {
card_rates = SupportedRates_G;
card_rates_size = sizeof(SupportedRates_G);
}
else {
return -EINVAL;
}
#else
card_rates = SupportedRates;
card_rates_size = sizeof(SupportedRates);
#endif /* MULTI_BANDS*/
Adapter->CurBssParams.channel =
Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].
PhyParamSet.DsParamSet.CurrentChan;
#ifdef MULTI_BANDS
Adapter->CurBssParams.band =
Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band;
#endif /* MULTI_BANDS*/
if (get_common_rates(Adapter, pAsso->DataRates,
sizeof(pAsso->DataRates),
card_rates, card_rates_size)) {
return -EINVAL;
}
for (i=0; i < MIN(sizeof(pAsso->DataRates),IW_MAX_BITRATES)
&& pAsso->DataRates[i]; i++) {
}
Adapter->CurBssParams.NumOfRates = i;
/* Copy the infra. association rates into Current BSS state structure */
memcpy(&Adapter->CurBssParams.DataRates, &pAsso->DataRates,
Adapter->CurBssParams.NumOfRates);
/* set IBSS field */
if ((Adapter->BSSIDList[i].InfrastructureMode) ==
Wlan802_11Infrastructure) {
pAsso->CapInfo.Ess = 1; /* HostCmd_CAPINFO_ESS */
#ifdef ENABLE_802_11D
ret = wlan_parse_dnld_countryinfo_11d( priv );
if ( ret ) {
LEAVE();
return ret;
}
#endif
#ifdef ENABLE_802_11H_TPC
/*infra, before Assoc, send power constraint to FW first. */
{
PWLAN_802_11_BSSID bssid =
&(Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex]);
if (Adapter->State11HTPC.Enable11HTPC==TRUE &&
bssid->Sensed11H )
pAsso->CapInfo.SpectrumMgmt = 1;
PRINTK2( "11HTPC: Cap = 0x%x\n", *(unsigned int *)&(pAsso->CapInfo));
PRINTK2("11HTPC:Enable11H=%s Sensed11H=%s\n",
(Adapter->State11HTPC.Enable11HTPC == TRUE)?"TRUE":"FALSE",
(bssid->Sensed11H)?"TRUE":"FALSE"
);
if (Adapter->State11HTPC.Enable11HTPC==TRUE &&
bssid->Sensed11H ) {
Adapter->State11HTPC.InfoTpc.Chan =
Adapter->CurBssParams.channel;
Adapter->State11HTPC.InfoTpc.PowerConstraint =
bssid->PowerConstraint.LocalPowerConstraint;
/*Enabel 11H and Dnld TPC Info to FW*/
wlan_802_11h_tpc_enable( priv, TRUE );
ret = PrepareAndSendCommand(priv,
HostCmd_CMD_802_11H_TPC_INFO,
HostCmd_ACT_SET, HostCmd_OPTION_USE_INT,
0, HostCmd_PENDING_ON_NONE, NULL);
if (ret) {
PRINTK2("11HTPC:Err: Send TPC_INFO CMD: %d\n", ret);
LEAVE();
return ret;
}
}
else {
wlan_802_11h_tpc_enable( priv, FALSE ); /* Disable 11H*/
}
}
#endif
}
/* set the listen interval */
pAsso->ListenInterval = Adapter->ListenInterval;
Adapter->bIsAssociationInProgress = TRUE;
/* need to report disconnect event if currently associated */
if (Adapter->CurBssParams.ssid.SsidLength != 0) {
MacEventDisconnected(priv);
}
#ifdef MULTI_BANDS
if (Adapter->is_multiband) {
bc.BandSelection = Adapter->CurBssParams.band;
bc.Channel = Adapter->CurBssParams.channel;
ret = PrepareAndSendCommand(priv,
HostCmd_CMD_802_11_BAND_CONFIG,
HostCmd_ACT_SET, HostCmd_OPTION_USE_INT,
0, HostCmd_PENDING_ON_NONE, &bc);
if (ret) {
LEAVE();
return ret;
}
}
#endif /* MULTI_BANDS */
LEAVE();
return ret;
}
#endif /* TLV_ASSOCIATION */
/*
* New commands - for ioctl's
*/
static inline int wlan_cmd_802_11_deauthenticate(wlan_private * priv,
HostCmd_DS_COMMAND * cmd)
{
wlan_adapter *Adapter = priv->adapter;
ENTER();
if (cmd->Command == HostCmd_CMD_802_11_DEAUTHENTICATE) {
HostCmd_DS_802_11_DEAUTHENTICATE *dauth = &cmd->params.deauth;
cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
cmd->Size =
wlan_cpu_to_le16(sizeof(HostCmd_DS_802_11_DEAUTHENTICATE) + S_DS_GEN);
/* set AP MAC address */
memmove(dauth->MacAddr, Adapter->CurrentBSSID,
MRVDRV_ETH_ADDR_LEN);
/* Reason code 3 = Station is leaving */
dauth->ReasonCode = wlan_cpu_to_le16(3);
}
else if (cmd->Command == HostCmd_CMD_802_11_DISASSOCIATE) {
HostCmd_DS_802_11_DISASSOCIATE *dassociate =
&cmd->params.dassociate;
cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_DISASSOCIATE);
cmd->Size = wlan_cpu_to_le16(sizeof(HostCmd_DS_802_11_DISASSOCIATE) + S_DS_GEN);
/* set AP MAC address */
memmove(dassociate->DestMacAddr, Adapter->CurrentBSSID,
MRVDRV_ETH_ADDR_LEN);
/* Reason code 0 = Station is leaving */
dassociate->ReasonCode = wlan_cpu_to_le16(0);
}
LEAVE();
return 0;
}
/* Needs OID,Info buffer and action to be paased */
#define WEP_40_BIT_LEN 5
#define WEP_104_BIT_LEN 13
static inline int wlan_cmd_802_11_set_wep(wlan_private * priv,
HostCmd_DS_COMMAND * cmd, u32 PendingOID,
void *InformationBuffer, u16 CmdOption)
{
HostCmd_DS_802_11_SET_WEP *wep = &cmd->params.wep;
wlan_adapter *Adapter = priv->adapter;
ENTER();
if (PendingOID == OID_802_11_ADD_WEP) {
cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_SET_WEP);
cmd->Size = wlan_cpu_to_le16((sizeof(HostCmd_DS_802_11_SET_WEP)) + S_DS_GEN);
wep->Action = wlan_cpu_to_le16(HostCmd_ACT_ADD);
//default tx key index
wep->KeyIndex = wlan_cpu_to_le16(Adapter->CurrentWepKeyIndex &
HostCmd_WEP_KEY_INDEX_MASK);
PRINTK1("Tx Key Index: %u\n", wep->KeyIndex);
switch (Adapter->WepKey[0].KeyLength) {
case WEP_40_BIT_LEN:
wep->WEPTypeForKey1 = HostCmd_TYPE_WEP_40_BIT;
memmove(wep->WEP1, Adapter->WepKey[0].KeyMaterial, Adapter->WepKey[0].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey1 = HostCmd_TYPE_WEP_104_BIT;
memmove(wep->WEP1, Adapter->WepKey[0].KeyMaterial, Adapter->WepKey[0].KeyLength);
break;
case 0:
break;
default:
PRINTK("Key1 Length = %d is incorrect\n", Adapter->WepKey[0].KeyLength);
LEAVE();
return -1;
}
switch (Adapter->WepKey[1].KeyLength) {
case WEP_40_BIT_LEN:
wep->WEPTypeForKey2 = HostCmd_TYPE_WEP_40_BIT;
memmove(wep->WEP2, Adapter->WepKey[1].KeyMaterial, Adapter->WepKey[1].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey2 = HostCmd_TYPE_WEP_104_BIT;
memmove(wep->WEP2, Adapter->WepKey[1].KeyMaterial, Adapter->WepKey[1].KeyLength);
break;
case 0:
break;
default:
PRINTK("Key2 Length = %d is incorrect\n", Adapter->WepKey[1].KeyLength);
LEAVE();
return -1;
}
switch (Adapter->WepKey[2].KeyLength) {
case WEP_40_BIT_LEN:
wep->WEPTypeForKey3 = HostCmd_TYPE_WEP_40_BIT;
memmove(wep->WEP3, Adapter->WepKey[2].KeyMaterial, Adapter->WepKey[2].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey3 = HostCmd_TYPE_WEP_104_BIT;
memmove(wep->WEP3, Adapter->WepKey[2].KeyMaterial, Adapter->WepKey[2].KeyLength);
break;
case 0:
break;
default:
PRINTK("Key3 Length = %d is incorrect\n", Adapter->WepKey[2].KeyLength);
LEAVE();
return -1;
}
switch (Adapter->WepKey[3].KeyLength) {
case WEP_40_BIT_LEN:
wep->WEPTypeForKey4 = HostCmd_TYPE_WEP_40_BIT;
memmove(wep->WEP4, Adapter->WepKey[3].KeyMaterial, Adapter->WepKey[3].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey4 = HostCmd_TYPE_WEP_104_BIT;
memmove(wep->WEP4, Adapter->WepKey[3].KeyMaterial, Adapter->WepKey[3].KeyLength);
break;
case 0:
break;
default:
PRINTK("Key4 Length = %d is incorrect\n", Adapter->WepKey[3].KeyLength);
LEAVE();
return -1;
}
}
else if (PendingOID == OID_802_11_REMOVE_WEP) {
cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_SET_WEP);
cmd->Size = wlan_cpu_to_le16((sizeof(HostCmd_DS_802_11_SET_WEP)) + S_DS_GEN);
wep->Action = wlan_cpu_to_le16(HostCmd_ACT_REMOVE);
//default tx key index
wep->KeyIndex = wlan_cpu_to_le16((u16) (Adapter->CurrentWepKeyIndex &
(u32) HostCmd_WEP_KEY_INDEX_MASK));
}
LEAVE();
return 0;
}
/*
* Needs a infoBuf to be transferred
*/
static inline int wlan_cmd_802_11_ad_hoc_start(wlan_private * priv,
CmdCtrlNode * cmdnode,
void *InformationBuffer)
{
int ret = 0;
wlan_adapter *Adapter = priv->adapter;
HostCmd_DS_COMMAND *cmd =
(HostCmd_DS_COMMAND *) cmdnode->BufVirtualAddr;
HostCmd_DS_802_11_AD_HOC_START *adhs = &cmd->params.ads;
int i, j;
#ifdef MULTI_BANDS
HostCmd_DS_802_11_BAND_CONFIG bc;
#endif /* MULTI BANDS */
u16 TmpCap;
ENTER();
cmd->Size = wlan_cpu_to_le16(sizeof(HostCmd_DS_802_11_AD_HOC_START) + S_DS_GEN);
cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
if (Adapter->AdHocCreated && Adapter->ulNumOfBSSIDs)
Adapter->ulNumOfBSSIDs--;
i = Adapter->ulNumOfBSSIDs;
/* add a new entry in the BSSID list */
if (Adapter->ulNumOfBSSIDs < MRVDRV_MAX_BSSID_LIST) {
Adapter->ulAttemptedBSSIDIndex = i;
Adapter->ulNumOfBSSIDs++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -