19 #include <linux/random.h>
39 static unsigned int rtllib_MFIE_rate_len(
struct rtllib_device *ieee)
41 unsigned int rate_len = 0;
178 if (!rtllib_is_cck_rate(BasicRate)) {
179 if (QueryRate == 0) {
180 QueryRate = BasicRate;
182 if (BasicRate < QueryRate)
183 QueryRate = BasicRate;
188 if (QueryRate == 0) {
239 tcb_desc->RATRIndex = 7;
240 tcb_desc->bTxDisableRateFallBack = 1;
241 tcb_desc->bTxUseDriverAssingedRate = 1;
258 spin_unlock_irqrestore(&ieee->
lock, flags);
260 spin_unlock_irqrestore(&ieee->
lock, flags);
272 (skb_queue_len(&ieee->
skb_waitQ[tcb_desc->queue_index]) != 0) ||
279 ":%d!\n", __func__, tcb_desc->queue_index);
313 tcb_desc->RATRIndex = 7;
314 tcb_desc->bTxDisableRateFallBack = 1;
315 tcb_desc->bTxUseDriverAssingedRate = 1;
346 unsigned int len, rate_len;
353 rate_len = rtllib_MFIE_rate_len(ieee);
366 req->
header.duration_id = 0;
372 tag = (
u8 *)
skb_put(skb, len + 2 + rate_len);
379 rtllib_MFIE_Brate(ieee, &tag);
380 rtllib_MFIE_Grate(ieee, &tag);
405 static void rtllib_send_beacon_cb(
unsigned long _ieee)
412 rtllib_send_beacon(ieee);
458 bool bFilterOutNonAssociatedBSSID =
false;
466 (
u8 *)&bFilterOutNonAssociatedBSSID);
481 bool bFilterOutNonAssociatedBSSID =
true;
489 (
u8 *)&bFilterOutNonAssociatedBSSID);
510 rtllib_send_probe(ieee, 0);
511 rtllib_send_probe(ieee, 0);
515 static void rtllib_softmac_hint11d_wq(
void *
data)
593 memset(&wrqu, 0,
sizeof(wrqu));
597 static void rtllib_softmac_scan_wq(
void *
data)
663 rtllib_send_beacon(ieee);
687 rtllib_beacons_stop(ieee);
697 rtllib_beacons_start(ieee);
702 static void rtllib_softmac_stop_scan(
struct rtllib_device *ieee)
719 rtllib_softmac_stop_scan(ieee);
799 ieee->tx_headroom + 4;
800 skb = dev_alloc_skb(len);
805 skb_reserve(skb, ieee->tx_headroom);
814 auth->
header.duration_id = 0x013a;
818 if (ieee->auth_mode == 0)
820 else if (ieee->auth_mode == 1)
822 else if (ieee->auth_mode == 2)
825 ieee->associate_seq++;
839 int atim_len, erp_len;
847 u8 erpinfo_content = 0;
849 u8 *tmp_ht_cap_buf =
NULL;
850 u8 tmp_ht_cap_len = 0;
851 u8 *tmp_ht_info_buf =
NULL;
852 u8 tmp_ht_info_len = 0;
854 u8 *tmp_generic_ie_buf =
NULL;
855 u8 tmp_generic_ie_len = 0;
877 ((0 ==
strcmp(crypt->
ops->name,
"R-WEP") || wpa_ie_len));
878 if (ieee->
pHTInfo->bCurrentHTSupport) {
879 tmp_ht_cap_buf = (
u8 *) &(ieee->
pHTInfo->SelfHTCap);
880 tmp_ht_cap_len =
sizeof(ieee->
pHTInfo->SelfHTCap);
881 tmp_ht_info_buf = (
u8 *) &(ieee->
pHTInfo->SelfHTInfo);
882 tmp_ht_info_len =
sizeof(ieee->
pHTInfo->SelfHTInfo);
884 &tmp_ht_cap_len, encrypt,
false);
889 tmp_generic_ie_buf = ieee->
pHTInfo->szRT2RTAggBuffer;
891 sizeof(ieee->
pHTInfo->szRT2RTAggBuffer);
893 &tmp_generic_ie_len);
898 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
899 + wpa_ie_len + ieee->tx_headroom;
900 skb = dev_alloc_skb(beacon_size);
912 beacon_buf->
header.duration_id = 0;
938 memcpy(tag, ssid, ssid_len);
943 *(tag++) = rate_len-2;
963 *(tag++) = erpinfo_content;
967 *(tag++) = rate_ex_len-2;
969 tag += rate_ex_len-2;
990 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
994 skb = dev_alloc_skb(len);
1021 encrypt = (crypt && crypt->
ops);
1034 rtllib_MFIE_Brate(ieee, &tag);
1035 rtllib_MFIE_Grate(ieee, &tag);
1046 skb = dev_alloc_skb(len);
1122 static void rtllib_resp_to_assoc_rq(
struct rtllib_device *ieee,
u8 *dest)
1124 struct sk_buff *
buf = rtllib_assoc_resp(ieee, dest);
1131 static void rtllib_resp_to_auth(
struct rtllib_device *ieee,
int s,
u8 *dest)
1133 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1140 static void rtllib_resp_to_probe(
struct rtllib_device *ieee,
u8 *dest)
1143 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1175 u8 *realtek_ie_buf =
NULL;
1176 u8 realtek_ie_len = 0;
1179 unsigned int ckip_ie_len = 0;
1180 unsigned int ccxrm_ie_len = 0;
1181 unsigned int cxvernum_ie_len = 0;
1186 unsigned int rate_len = (beacon->
rates_len ?
1191 unsigned int wmm_info_len = beacon->
qos_data.supported ? 9 : 0;
1192 unsigned int turbo_info_len = beacon->
Turbo_Enable ? 9 : 0;
1198 ((0 ==
strcmp(crypt->
ops->name,
"R-WEP") ||
1210 if (ieee->
pHTInfo->bCurrentHTSupport && ieee->
pHTInfo->bEnableHT) {
1211 ht_cap_buf = (
u8 *)&(ieee->
pHTInfo->SelfHTCap);
1212 ht_cap_len =
sizeof(ieee->
pHTInfo->SelfHTCap);
1215 if (ieee->
pHTInfo->bCurrentRT2RTAggregation) {
1216 realtek_ie_buf = ieee->
pHTInfo->szRT2RTAggBuffer;
1218 sizeof(ieee->
pHTInfo->szRT2RTAggBuffer);
1229 cxvernum_ie_len = 5+2;
1232 if (PMKCacheIdx >= 0) {
1249 + ieee->tx_headroom;
1251 skb = dev_alloc_skb(len);
1256 skb_reserve(skb, ieee->tx_headroom);
1263 hdr->
header.duration_id = 37;
1277 if (ieee->short_slot &&
1287 tag =
skb_put(skb, beacon->ssid_len);
1288 memcpy(tag, beacon->ssid, beacon->ssid_len);
1292 if (beacon->rates_len) {
1294 *tag++ = beacon->rates_len;
1295 for (i = 0; i < beacon->rates_len; i++)
1296 *tag++ = beacon->rates[i];
1299 if (beacon->rates_ex_len) {
1301 *tag++ = beacon->rates_ex_len;
1302 for (i = 0; i < beacon->rates_ex_len; i++)
1303 *tag++ = beacon->rates_ex[i];
1306 if (beacon->bCkipSupported) {
1307 static u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1308 u8 CcxAironetBuf[30];
1311 memset(CcxAironetBuf, 0, 30);
1312 osCcxAironetIE.
Octet = CcxAironetBuf;
1313 osCcxAironetIE.
Length =
sizeof(CcxAironetBuf);
1315 sizeof(AironetIeOui));
1319 tag =
skb_put(skb, ckip_ie_len);
1321 *tag++ = osCcxAironetIE.
Length;
1323 tag += osCcxAironetIE.
Length;
1326 if (beacon->bCcxRmEnable) {
1327 static u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01, 0x00};
1330 osCcxRmCap.
Octet = CcxRmCapBuf;
1331 osCcxRmCap.
Length =
sizeof(CcxRmCapBuf);
1332 tag =
skb_put(skb, ccxrm_ie_len);
1334 *tag++ = osCcxRmCap.
Length;
1336 tag += osCcxRmCap.
Length;
1339 if (beacon->BssCcxVerNumber >= 2) {
1340 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1342 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1343 osCcxVerNum.
Octet = CcxVerNumBuf;
1344 osCcxVerNum.
Length =
sizeof(CcxVerNumBuf);
1345 tag =
skb_put(skb, cxvernum_ie_len);
1347 *tag++ = osCcxVerNum.
Length;
1349 tag += osCcxVerNum.
Length;
1351 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1353 tag =
skb_put(skb, ht_cap_len);
1355 *tag++ = ht_cap_len - 2;
1356 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1357 tag += ht_cap_len - 2;
1362 tag =
skb_put(skb, ieee->wpa_ie_len);
1363 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1365 if (PMKCacheIdx >= 0) {
1369 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1374 tag =
skb_put(skb, wmm_info_len);
1375 rtllib_WMM_Info(ieee, &tag);
1378 if (wps_ie_len && ieee->wps_ie) {
1379 tag =
skb_put(skb, wps_ie_len);
1380 memcpy(tag, ieee->wps_ie, wps_ie_len);
1383 tag =
skb_put(skb, turbo_info_len);
1387 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1389 tag =
skb_put(skb, ht_cap_len);
1391 *tag++ = ht_cap_len - 2;
1392 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1393 tag += ht_cap_len - 2;
1396 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1397 tag =
skb_put(skb, realtek_ie_len);
1399 *tag++ = realtek_ie_len - 2;
1400 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1404 kfree(ieee->assocreq_ies);
1405 ieee->assocreq_ies =
NULL;
1407 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1409 if (ieee->assocreq_ies)
1410 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1413 "_ies\n", __func__);
1414 ieee->assocreq_ies_len = 0;
1422 unsigned long flags;
1446 spin_unlock_irqrestore(&ieee->
lock, flags);
1449 static void rtllib_associate_abort_cb(
unsigned long dev)
1478 static void rtllib_auth_challenge(
struct rtllib_device *ieee,
u8 *challenge,
int chlen)
1495 memcpy(c, challenge, chlen);
1509 static void rtllib_associate_step2(
struct rtllib_device *ieee)
1529 static void rtllib_associate_complete_wq(
void *data)
1554 if (ieee->
pHTInfo->bCurrentHTSupport && ieee->
pHTInfo->bEnableHT) {
1559 "enabled(%d, %d)\n",
1560 ieee->
pHTInfo->bCurrentHTSupport,
1585 static void rtllib_sta_send_associnfo(
struct rtllib_device *ieee)
1589 static void rtllib_associate_complete(
struct rtllib_device *ieee)
1594 rtllib_sta_send_associnfo(ieee);
1599 static void rtllib_associate_procedure_wq(
void *data)
1618 " schedule ipsleave wq again,return\n", __func__);
1635 int tmp_ssid_len = 0;
1637 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1663 ssidbroad = !(net->
ssid_len == 0 || net->
ssid[0] ==
'\0');
1693 if ((apset && apmatch &&
1694 ((ssidset && ssidbroad && ssidmatch) ||
1695 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1696 (!apset && ssidset && ssidbroad && ssidmatch) ||
1697 (ieee->
is_roaming && ssidset && ssidbroad && ssidmatch)) {
1714 "myHT:%d, networkHT:%d, mode:%x cur_net.flags"
1738 ieee->
pHTInfo->bCurrentHTSupport =
1767 unsigned long flags;
1785 spin_unlock_irqrestore(&ieee->
lock, flags);
1788 static inline u16 auth_parse(
struct sk_buff *skb,
u8** challenge,
int *chlen)
1805 memcpy(*challenge, t, *chlen);
1847 (!is_broadcast_ether_addr(header->
addr3));
1857 while (tag + 1 < skbend) {
1860 ssidlen = *(tag + 1);
1927 if (probe_rq_parse(ieee, skb, dest) > 0) {
1929 rtllib_resp_to_probe(ieee, dest);
1933 static inline void rtllib_rx_auth_rq(
struct rtllib_device *ieee,
1942 rtllib_resp_to_auth(ieee, status, dest);
1945 static inline void rtllib_rx_assoc_rq(
struct rtllib_device *ieee,
1953 rtllib_resp_to_assoc_rq(ieee, dest);
1961 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1970 struct sk_buff *buf = rtllib_pspoll_func(ieee);
2021 MaxPeriod) ? MaxPeriod :
2025 u8 LPSAwakeIntvl_tmp = 0;
2030 LPSAwakeIntvl_tmp = period +
2041 LPSAwakeIntvl_tmp = count +
2059 static inline void rtllib_sta_ps(
struct rtllib_device *ieee)
2071 "ieee->ps is %d, ieee->iw_mode is %d, ieee->state"
2072 " is %d\n", __func__, ieee->
ps, ieee->
iw_mode,
2079 sleep = rtllib_sta_ps_sleep(ieee, &time);
2101 }
else if (sleep == 2) {
2110 spin_unlock_irqrestore(&ieee->
lock, flags);
2118 if (ieee->
pHTInfo->IOTAction &
2134 if (ieee->
pHTInfo->IOTAction &
2169 if (ieee->
pHTInfo->IOTAction &
2177 spin_unlock_irqrestore(&ieee->
lock, flags);
2184 u8 *act = rtllib_get_payload((
struct rtllib_hdr *)header);
2230 errcode = assoc_parse(ieee, skb, &aid);
2246 rx_stats->
len -
sizeof(*assoc_resp),
2247 network, rx_stats)) {
2252 network->
bssht.bdHTCapBuf,
2253 network->
bssht.bdHTCapLen);
2255 network->
bssht.bdHTInfoBuf,
2256 network->
bssht.bdHTInfoLen);
2276 "memory for assocresp_ies\n", __func__);
2279 rtllib_associate_complete(ieee);
2286 "Association response status code 0x%x\n",
2304 bool bSupportNmode =
true, bHalfSupportNmode =
false;
2311 errcode = auth_parse(skb, &challenge, &chlen);
2313 if (ieee->
open_wep || !challenge) {
2316 if (!(ieee->
pHTInfo->IOTAction &
2320 bSupportNmode =
true;
2321 bHalfSupportNmode =
true;
2323 bSupportNmode =
false;
2324 bHalfSupportNmode =
false;
2330 if (bSupportNmode) {
2341 bHalfSupportNmode ==
true) {
2350 rtllib_associate_step2(ieee);
2352 rtllib_auth_challenge(ieee, challenge,
2358 " status code 0x%x", errcode);
2361 "status code 0x%x", errcode);
2366 rtllib_rx_auth_rq(ieee, skb);
2386 "frame, reason code:%x\n",
2427 rtllib_rx_assoc_rq(ieee, skb);
2437 rtllib_process_action(ieee, skb);
2468 unsigned long flags;
2471 unsigned long queue_len = 0;
2482 ieee->
stats.multicast++;
2486 for (i = 0; i < txb->
nr_frags; i++) {
2487 queue_len = skb_queue_len(&ieee->
skb_waitQ[queue_index]);
2488 if ((queue_len != 0) ||\
2495 if (queue_len < 200)
2509 spin_unlock_irqrestore(&ieee->
lock, flags);
2528 ieee->
stats.tx_packets++;
2539 unsigned long flags;
2548 spin_unlock_irqrestore(&ieee->
lock, flags);
2556 unsigned long flags;
2583 rtllib_resume_tx(ieee);
2587 netif_wake_queue(ieee->
dev);
2591 spin_unlock_irqrestore(&ieee->
lock, flags);
2598 if (!netif_queue_stopped(ieee->
dev)) {
2599 netif_stop_queue(ieee->
dev);
2609 for (i = 0; i < ieee->
dev->num_tx_queues; i++)
2610 netdev_get_tx_queue(ieee->
dev, i)->trans_start =
jiffies;
2612 netif_tx_stop_all_queues(ieee->
dev);
2617 netif_tx_wake_all_queues(ieee->
dev);
2654 static void rtllib_start_monitor_mode(
struct rtllib_device *ieee)
2665 static void rtllib_start_ibss_wq(
void *data)
2771 ieee->
pHTInfo->bCurrentHTSupport =
false;
2803 unsigned long flags;
2825 rtllib_start_scan(ieee);
2826 spin_unlock_irqrestore(&ieee->
lock, flags);
2829 static void rtllib_link_change_wq(
void *data)
2855 static void rtllib_associate_retry_wq(
void *data)
2859 unsigned long flags;
2889 rtllib_start_scan(ieee);
2890 spin_unlock_irqrestore(&ieee->
lock, flags);
2899 u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2903 skb = rtllib_probe_resp(ieee, broadcast_addr);
3019 for (i = 0; i < 17; i++) {
3045 rtllib_start_monitor_mode(ieee);
3055 for (i = 0; i < 5; i++)
3104 rtllib_associate_abort_cb,
3105 (
unsigned long) ieee);
3108 rtllib_send_beacon_cb,
3109 (
unsigned long) ieee);
3115 (
void *)rtllib_link_change_wq, ieee);
3117 (
void *)rtllib_start_ibss_wq, ieee);
3119 (
void *)rtllib_associate_complete_wq, ieee);
3121 (
void *)rtllib_associate_procedure_wq, ieee);
3123 (
void *)rtllib_softmac_scan_wq, ieee);
3125 (
void *)rtllib_softmac_hint11d_wq, ieee);
3127 (
void *)rtllib_associate_retry_wq, ieee);
3131 sema_init(&ieee->wx_sem, 1);
3132 sema_init(&ieee->scan_sem, 1);
3133 sema_init(&ieee->ips_sem, 1);
3139 (
void(*)(
unsigned long)) rtllib_sta_ps,
3140 (
unsigned long)ieee);
3173 static void rtllib_wpa_assoc_frame(
struct rtllib_device *ieee,
char *wpa_ie,
3177 rtllib_wpa_enable(ieee, 1);
3205 static int rtllib_wpa_set_wpa_ie(
struct rtllib_device *ieee,
3233 #define AUTH_ALG_OPEN_SYSTEM 0x1
3234 #define AUTH_ALG_SHARED_KEY 0x2
3235 #define AUTH_ALG_LEAP 0x4
3268 unsigned long flags;
3272 ret = rtllib_wpa_enable(ieee, value);
3317 ret = rtllib_wpa_set_auth_algs(ieee, value);
3337 static int rtllib_wpa_set_encryption(
struct rtllib_device *ieee,
3353 (
int) ((
char *) param->
u.
crypt.key - (
char *) param) +
3354 param->
u.
crypt.key_len) {
3359 if (is_broadcast_ether_addr(param->
sta_addr)) {
3382 goto skip_host_crypt;
3386 request_module(
"rtllib_crypt_wep");
3389 request_module(
"rtllib_crypt_tkip");
3392 request_module(
"rtllib_crypt_ccmp");
3402 if (*crypt ==
NULL || (*crypt)->ops != ops) {
3408 if (new_crypt ==
NULL) {
3416 new_crypt->
ops->init(param->
u.
crypt.idx);
3428 if (param->
u.
crypt.key_len > 0 && (*crypt)->ops->set_key &&
3429 (*crypt)->ops->set_key(param->
u.
crypt.key,
3431 (*crypt)->priv) < 0) {
3439 if (param->
u.
crypt.set_tx) {
3456 }
else if (
strcmp(param->
u.
crypt.alg,
"R-TKIP") == 0) {
3459 }
else if (
strcmp(param->
u.
crypt.alg,
"R-CCMP") == 0) {
3492 skb = dev_alloc_skb(len);
3496 skb_reserve(skb, ieee->tx_headroom);
3501 disauth->
header.duration_id = 0;
3517 skb = dev_alloc_skb(len);
3522 skb_reserve(skb, ieee->tx_headroom);
3527 disass->
header.duration_id = 0;
3553 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3554 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3562 (0 ==
strcmp(crypt->
ops->name,
"R-WEP")));
3565 if (encrypt && (wpa_ie_len == 0)) {
3567 }
else if ((wpa_ie_len != 0)) {
3568 if (((ieee->
wpa_ie[0] == 0xdd) &&
3570 ((ieee->
wpa_ie[0] == 0x30) &&
3594 if (param ==
NULL) {
3604 switch (param->
cmd) {
3606 ret = rtllib_wpa_set_param(ieee, param->
u.
wpa_param.name,
3611 ret = rtllib_wpa_set_wpa_ie(ieee, param, p->
length);
3615 ret = rtllib_wpa_set_encryption(ieee, param, p->
length, 0);
3619 ret = rtllib_wpa_mlme(ieee, param->
u.
mlme.command,
3620 param->
u.
mlme.reason_code);
3645 bool bFilterOutNonAssociatedBSSID =
false;
3649 for (i = 0; i < 6; i++)
3659 bFilterOutNonAssociatedBSSID =
false;
3661 (
u8 *)(&bFilterOutNonAssociatedBSSID));
3677 for (i = 0; i < 6; i++)
3698 bool bFilterOutNonAssociatedBSSID =
false;
3700 bFilterOutNonAssociatedBSSID =
false;
3702 (
u8 *)(&bFilterOutNonAssociatedBSSID));