29 #define _RTL871X_MLME_C_
63 set_scanned_network_val(pmlmepriv, 0);
71 _init_listhead(&(pnetwork->
list));
72 list_insert_tail(&(pnetwork->
list),
91 if (_queue_empty(free_queue) ==
true)
96 list_delete(&pnetwork->
list);
99 spin_unlock_irqrestore(&free_queue->
lock, irqL);
103 static void _free_network(
struct mlme_priv *pmlmepriv,
106 u32 curr_time, delta_time;
110 if (pnetwork ==
NULL)
112 if (pnetwork->
fixed ==
true)
119 list_delete(&pnetwork->
list);
120 list_insert_tail(&pnetwork->
list, &free_queue->
queue);
122 spin_unlock_irqrestore(&free_queue->
lock, irqL);
125 static void _free_network_nolock(
struct mlme_priv *pmlmepriv,
130 if (pnetwork ==
NULL)
132 if (pnetwork->
fixed ==
true)
134 list_delete(&pnetwork->
list);
135 list_insert_tail(&pnetwork->
list, get_list_head(free_queue));
152 if (is_zero_ether_addr(addr))
155 phead = get_list_head(scanned_queue);
157 while (plist != phead) {
163 spin_unlock_irqrestore(&scanned_queue->
lock, irqL);
167 static void _free_network_queue(
struct _adapter *padapter)
176 phead = get_list_head(scanned_queue);
178 while (end_of_queue_search(phead, plist) ==
false) {
181 _free_network(pmlmepriv, pnetwork);
183 spin_unlock_irqrestore(&scanned_queue->
lock, irqL);
205 pibss[3] = (
u8)(curtime & 0xff);
206 pibss[4] = (
u8)((curtime>>8) & 0xff);
207 pibss[5] = (
u8)((curtime>>16) & 0xff);
214 t_len =
sizeof(
u32) + 6 *
sizeof(
unsigned long) + 2 +
217 sizeof(enum NDIS_802_11_NETWORK_TYPE) +
218 sizeof(struct NDIS_802_11_CONFIGURATION) +
219 sizeof(enum NDIS_802_11_NETWORK_INFRASTRUCTURE) +
220 sizeof(NDIS_802_11_RATES_EX) +
221 sizeof(u32) + bss->IELength;
232 return _init_mlme_priv(padapter);
245 static void free_network_nolock(
struct mlme_priv *pmlmepriv,
248 _free_network_nolock(pmlmepriv, pnetwork);
253 _free_network_queue(dev);
265 struct wlan_network *pnetwork = _r8712_find_network(scanned_queue,
277 (pnetwork->
network.Privacy == 0))
280 (pnetwork->
network.Privacy == 1))
295 return (src->
Ssid.SsidLength == dst->
Ssid.SsidLength) &&
302 src->
Ssid.SsidLength))) &&
317 phead = get_list_head(scanned_queue);
320 if (end_of_queue_search(phead, plist) ==
true)
323 if (pwlan->
fixed !=
true) {
324 if (oldest ==
NULL ||
338 u32 last_evm = 0, tmpVal;
341 is_same_network(&(padapter->
mlmepriv.cur_network.network), src)) {
342 if (padapter->
recvpriv.signal_qual_data.total_num++ >=
344 padapter->
recvpriv.signal_qual_data.total_num =
346 last_evm = padapter->
recvpriv.signal_qual_data.
348 signal_qual_data.index];
349 padapter->
recvpriv.signal_qual_data.total_val -=
352 padapter->
recvpriv.signal_qual_data.total_val += src->
Rssi;
354 padapter->
recvpriv.signal_qual_data.
357 if (padapter->
recvpriv.signal_qual_data.index >=
359 padapter->
recvpriv.signal_qual_data.index = 0;
361 tmpVal = padapter->
recvpriv.signal_qual_data.total_val /
362 padapter->
recvpriv.signal_qual_data.total_num;
376 if (is_same_network(&(pmlmepriv->
cur_network.network), pnetwork)) {
389 static void update_scanned_network(
struct _adapter *adapter,
400 phead = get_list_head(queue);
404 if (end_of_queue_search(phead, plist) ==
true)
408 if (is_same_network(&pnetwork->
network, target))
421 if (end_of_queue_search(phead, plist) ==
true) {
433 pnetwork = alloc_network(pmlmepriv);
434 if (pnetwork ==
NULL)
437 target->
Length = bssid_ex_sz;
439 list_insert_tail(&pnetwork->
list, &queue->
queue);
452 static void rtl8711_add_network(
struct _adapter *adapter,
460 update_current_network(adapter, pnetwork);
461 update_scanned_network(adapter, pnetwork);
462 spin_unlock_irqrestore(&queue->
lock, irqL);
472 static int is_desired_network(
struct _adapter *adapter,
477 int bselected =
true;
482 pnetwork->
network.IELength, wps_ie,
489 (pnetwork->
network.Privacy == 0))
492 if (pnetwork->
network.InfrastructureMode !=
493 adapter->
mlmepriv.cur_network.network.
552 ibss_wlan = r8712_find_network(
564 if (pnetwork->
Ssid.Ssid[0] != 0)
565 rtl8711_add_network(adapter, pnetwork);
567 pnetwork->
Ssid.SsidLength = 8;
569 rtl8711_add_network(adapter, pnetwork);
573 spin_unlock_irqrestore(&pmlmepriv->
lock2, flags);
591 if (pmlmepriv->
to_join ==
true) {
593 if (check_fwstate(pmlmepriv,
_FW_LINKED) ==
false) {
605 dev_network.MacAddress;
633 spin_unlock_irqrestore(&pmlmepriv->
lock, irqL);
648 tgt_network->
network.MacAddress);
654 tgt_network->
network.MacAddress);
661 if (check_fwstate(pmlmepriv,
665 pwlan->
fixed =
false;
668 (adapter->
stapriv.asoc_sta_count == 1)))
669 free_network_nolock(pmlmepriv, pwlan);
695 if (check_fwstate(pmlmepriv,
_FW_LINKED) ==
true) {
720 unsigned long irqL = 0, irqL2;
727 unsigned int the_same_macaddr =
false;
743 pnetwork->
network.Ssid.SsidLength =
747 pnetwork->
network.NetworkTypeInUse =
749 pnetwork->
network.Configuration.ATIMWindow =
751 pnetwork->
network.Configuration.BeaconPeriod =
753 pnetwork->
network.Configuration.DSConfig =
755 pnetwork->
network.Configuration.FHConfig.DwellTime =
758 pnetwork->
network.Configuration.FHConfig.HopPattern =
760 FHConfig.HopPattern);
761 pnetwork->
network.Configuration.FHConfig.HopSet =
763 pnetwork->
network.Configuration.FHConfig.Length =
765 pnetwork->
network.Configuration.Length =
767 pnetwork->
network.InfrastructureMode =
778 goto ignore_joinbss_callback;
782 if (check_fwstate(pmlmepriv,
_FW_LINKED) ==
true) {
783 if (the_same_macaddr ==
true)
785 r8712_find_network(&pmlmepriv->
787 cur_network->
network.MacAddress);
790 r8712_find_network(&pmlmepriv->
792 cur_network->
network.MacAddress);
793 pcur_wlan->
fixed =
false;
796 cur_network->
network.MacAddress);
798 sta_hash_lock, irqL2);
800 spin_unlock_irqrestore(&(pstapriv->
801 sta_hash_lock), irqL2);
804 r8712_find_network(&pmlmepriv->
809 ptarget_wlan->fixed =
true;
812 ptarget_wlan = r8712_find_network(&pmlmepriv->
816 ptarget_wlan->fixed =
true;
819 if (ptarget_wlan ==
NULL) {
820 if (check_fwstate(pmlmepriv,
824 goto ignore_joinbss_callback;
829 if (the_same_macaddr ==
true) {
833 if (ptarget_sta ==
NULL)
881 if (check_fwstate(pmlmepriv,
885 goto ignore_joinbss_callback;
894 switch (pnetwork->
network.InfrastructureMode) {
908 (cur_network->
network.IELength));
910 update_ht_cap(adapter, cur_network->
network.IEs,
911 cur_network->
network.IELength);
919 goto ignore_joinbss_callback;
926 ignore_joinbss_callback:
927 spin_unlock_irqrestore(&pmlmepriv->
lock, irqL);
964 if (adapter->
stapriv.asoc_sta_count == 2) {
969 spin_unlock_irqrestore(&pmlmepriv->
lock, irqL);
974 unsigned long irqL, irqL2;
995 if (adapter->
stapriv.asoc_sta_count == 1) {
998 tgt_network->
network.MacAddress);
1000 pwlan->
fixed =
false;
1001 free_network_nolock(pmlmepriv, pwlan);
1022 spin_unlock_irqrestore(&pmlmepriv->
lock, irqL2);
1076 u64 current_tx_pkts;
1077 uint current_rx_pkts;
1079 current_tx_pkts = (adapter->
xmitpriv.tx_pkts) -
1081 current_rx_pkts = (adapter->
recvpriv.rx_pkts) -
1085 if ((current_tx_pkts > pregistrypriv->
busy_thresh) ||
1102 if (check_fwstate(pmlmepriv,
_FW_LINKED) ==
true) {
1110 spin_unlock_irqrestore(&pmlmepriv->
lock, irqL);
1121 spin_unlock_irqrestore(&pmlmepriv->
lock, irqL);
1141 unsigned char *dst_ssid, *src_ssid;
1149 phead = get_list_head(queue);
1152 if (end_of_queue_search(phead, pmlmepriv->
pscanned) ==
true) {
1154 (pnetwork_max_rssi !=
NULL)) {
1155 pnetwork = pnetwork_max_rssi;
1156 goto ask_for_joinbss;
1162 if (pnetwork ==
NULL)
1166 dst_ssid = pnetwork->
network.MacAddress;
1170 if (is_same_network(&pmlmepriv->
1171 cur_network.network,
1173 _clr_fwstate_(pmlmepriv,
1183 goto ask_for_joinbss;
1185 }
else if (pmlmepriv->
assoc_ssid.SsidLength == 0)
1186 goto ask_for_joinbss;
1187 dst_ssid = pnetwork->
network.Ssid.Ssid;
1189 if ((pnetwork->
network.Ssid.SsidLength ==
1191 (!
memcmp(dst_ssid, src_ssid,
1196 if (pnetwork_max_rssi) {
1198 pnetwork_max_rssi->
network.Rssi)
1199 pnetwork_max_rssi = pnetwork;
1201 pnetwork_max_rssi = pnetwork;
1202 }
else if (is_desired_network(adapter, pnetwork)) {
1207 goto ask_for_joinbss;
1230 if (psetauthparm ==
NULL) {
1231 kfree((
unsigned char *)pcmd);
1236 pcmd->
cmdcode = _SetAuth_CMD_;
1237 pcmd->
parmbuf = (
unsigned char *)psetauthparm;
1241 _init_listhead(&pcmd->
list);
1259 if (psetkeyparm ==
NULL) {
1260 kfree((
unsigned char *)pcmd);
1271 psetkeyparm->
keyid = (
u8)keyid;
1285 if (keyid < 1 || keyid > 2)
1289 &psecuritypriv->
XGrpKey[keyid - 1], keylen);
1293 if (keyid < 1 || keyid > 2)
1297 &psecuritypriv->
XGrpKey[keyid - 1], keylen);
1308 _init_listhead(&pcmd->
list);
1317 unsigned int ielength = 0;
1321 while (i < in_len) {
1322 ielength = initial_out_len;
1323 if (in_ie[i] == 0xDD && in_ie[i + 2] == 0x00 &&
1324 in_ie[i + 3] == 0x50 && in_ie[i + 4] == 0xF2 &&
1325 in_ie[i + 5] == 0x02 && i + 5 < in_len) {
1327 for (j = i; j < i + 9; j++) {
1328 out_ie[ielength] = in_ie[
j];
1331 out_ie[initial_out_len + 1] = 0x07;
1332 out_ie[initial_out_len + 6] = 0x00;
1333 out_ie[initial_out_len + 8] = 0x00;
1336 i += (in_ie[i + 1] + 2);
1355 if (psecuritypriv->
PMKIDList[i].bUsed &&
1375 u8 authmode = 0, securitytype,
match;
1376 u8 sec_ie[255], uncst_oui[4], bkup_ie[255];
1377 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
1378 uint ielength,
cnt, remove_cnt;
1389 uncst_oui[1] = 0x50;
1390 uncst_oui[2] = 0xf2;
1392 if ((ndisauthmode == Ndis802_11AuthModeWPA2) ||
1393 (ndisauthmode == Ndis802_11AuthModeWPA2PSK)) {
1396 uncst_oui[1] = 0x0f;
1397 uncst_oui[2] = 0xac;
1399 switch (ndissecuritytype) {
1412 securitytype =
_AES_;
1422 while (cnt < in_len) {
1423 if (in_ie[cnt] == authmode) {
1425 (!
memcmp(&in_ie[cnt+2], &wpa_oui[0], 4))) {
1426 memcpy(&sec_ie[0], &in_ie[cnt],
1427 in_ie[cnt + 1] + 2);
1432 memcpy(&sec_ie[0], &in_ie[cnt],
1433 in_ie[cnt + 1] + 2);
1438 (!
memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) ||
1440 memcpy(&bkup_ie[0], &in_ie[cnt],
1441 in_ie[cnt + 1] + 2);
1443 cnt += in_ie[cnt+1] + 2;
1446 if (match ==
true) {
1452 if (
memcmp(&sec_ie[2], &wpa_oui[0], 4)) {
1456 if ((sec_ie[6] != 0x01) || (sec_ie[7] != 0x0)) {
1461 if (!
memcmp(&sec_ie[8], &wpa_oui[0], 3)) {
1464 switch (sec_ie[11]) {
1491 if (sec_ie[12] == 0x01) {
1494 &uncst_oui[0], 4)) {
1503 remove_cnt = (cnt-1) * 4;
1505 memcpy(&sec_ie[14], &uncst_oui[0], 4);
1508 &sec_ie[18 + remove_cnt],
1509 sec_ie[1] - 18 + 2 -
1511 sec_ie[1] = sec_ie[1] - remove_cnt;
1520 if ((sec_ie[2] != 0x01) || (sec_ie[3] != 0x0)) {
1525 if (!
memcmp(&sec_ie[4], &uncst_oui[0], 3)) {
1527 switch (sec_ie[7]) {
1553 if (sec_ie[8] == 0x01) {
1556 &uncst_oui[0], 4)) {
1564 remove_cnt = (cnt-1)*4;
1566 memcpy(&sec_ie[10], &uncst_oui[0], 4);
1569 &sec_ie[14 + remove_cnt],
1570 (sec_ie[1] - 14 + 2 -
1572 sec_ie[1] = sec_ie[1]-remove_cnt;
1580 memcpy(out_ie, in_ie, 12);
1583 if (match ==
true) {
1584 memcpy(&out_ie[ielength], &sec_ie[0], sec_ie[1]+2);
1585 ielength += sec_ie[1] + 2;
1588 out_ie[ielength - 1] = 0;
1589 out_ie[ielength - 2] = 0;
1595 memcpy(out_ie, in_ie, 12);
1608 out_ie[ielength] = 1;
1610 out_ie[ielength] = 0;
1612 memcpy(&out_ie[ielength],
1613 &psecuritypriv->
PMKIDList[iEntry].PMKID, 16);
1626 u8 *myhwaddr = myid(peepriv);
1650 pdev_network->
Rssi = 0;
1671 cur_network->
network.InfrastructureMode);
1691 for (i = 0; i < 16; i++)
1708 unsigned char *
p, *pframe;
1710 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
1717 if (p && (ielen > 0)) {
1719 out_len = *pout_len;
1726 out_len = *pout_len;
1738 (
unsigned char *)&ht_capie, pout_len);
1747 u8 *
p, max_ampdu_sz;
1775 max_ampdu_sz = 1 << (max_ampdu_sz+3);
1785 for (i = 0; i < 16; i++) {
1788 preorder_ctrl->
wend_b = 0xffff;
1792 pcur_network->
network.MacAddress);
1794 for (i = 0; i < 16 ; i++) {
1797 preorder_ctrl->
wend_b = 0xffff;