1 // SPDX-License-Identifier: GPL-2.0
2 /* IEEE 802.11 SoftMAC layer
5 * Mostly extracted from the rtl8180-sa2400 driver for the
6 * in-kernel generic ieee802.11 stack.
8 * Few lines might be stolen from other part of the rtllib
9 * stack. Copyright who own it's copyright
11 * WPA code stolen from the ipw2200 driver.
12 * Copyright who own it's copyright.
16 #include <linux/random.h>
17 #include <linux/delay.h>
18 #include <linux/uaccess.h>
19 #include <linux/etherdevice.h>
20 #include <linux/ieee80211.h>
23 static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
26 static short rtllib_is_54g(struct rtllib_network *net)
28 return (net->rates_ex_len > 0) || (net->rates_len > 4);
31 /* returns the total length needed for placing the RATE MFIE
32 * tag and the EXTENDED RATE MFIE tag if needed.
33 * It encludes two bytes per tag for the tag itself and its len
35 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
37 unsigned int rate_len = 0;
39 if (ieee->modulation & RTLLIB_CCK_MODULATION)
40 rate_len = RTLLIB_CCK_RATE_LEN + 2;
42 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
44 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
49 /* place the MFIE rate, tag to the memory (double) pointed.
50 * Then it updates the pointer so that
51 * it points after the new MFIE tag added.
53 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
57 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
58 *tag++ = MFIE_TYPE_RATES;
60 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
61 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
62 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
63 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
66 /* We may add an option for custom rates that specific HW
72 static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p)
76 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
77 *tag++ = MFIE_TYPE_RATES_EX;
79 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
80 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
81 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
82 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
83 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
84 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
85 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
86 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;
88 /* We may add an option for custom rates that specific HW might
94 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
98 *tag++ = MFIE_TYPE_GENERIC;
110 static void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
114 *tag++ = MFIE_TYPE_GENERIC;
125 netdev_alert(ieee->dev, "This is enable turbo mode IE process\n");
128 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
132 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
134 /* if the queue is full but we have newer frames then
135 * just overwrites the oldest.
137 * if (nh == ieee->mgmt_queue_tail)
140 ieee->mgmt_queue_head = nh;
141 ieee->mgmt_queue_ring[nh] = skb;
145 static void init_mgmt_queue(struct rtllib_device *ieee)
147 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
151 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
158 for (i = 0; i < ieee->current_network.rates_len; i++) {
159 BasicRate = ieee->current_network.rates[i]&0x7F;
160 if (!rtllib_is_cck_rate(BasicRate)) {
161 if (QueryRate == 0) {
162 QueryRate = BasicRate;
164 if (BasicRate < QueryRate)
165 QueryRate = BasicRate;
170 if (QueryRate == 0) {
172 netdev_info(ieee->dev, "No BasicRate found!!\n");
177 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
179 struct rt_hi_throughput *ht_info = ieee->ht_info;
182 if (ht_info->iot_action & HT_IOT_ACT_MGNT_USE_CCK_6M)
185 rate = ieee->basic_rate & 0x7f;
188 if (ieee->mode == IEEE_A ||
189 ieee->mode == IEEE_N_5G ||
190 (ieee->mode == IEEE_N_24G && !ht_info->bCurSuppCCK))
199 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
202 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
203 struct rtllib_hdr_3addr *header =
204 (struct rtllib_hdr_3addr *)skb->data;
206 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
208 spin_lock_irqsave(&ieee->lock, flags);
210 /* called with 2nd param 0, no mgmt lock required */
211 rtllib_sta_wakeup(ieee, 0);
213 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
214 tcb_desc->queue_index = BEACON_QUEUE;
216 tcb_desc->queue_index = MGNT_QUEUE;
218 if (ieee->disable_mgnt_queue)
219 tcb_desc->queue_index = HIGH_QUEUE;
221 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
222 tcb_desc->RATRIndex = 7;
223 tcb_desc->tx_dis_rate_fallback = 1;
224 tcb_desc->tx_use_drv_assinged_rate = 1;
226 if (ieee->queue_stop) {
227 enqueue_mgmt(ieee, skb);
229 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
231 if (ieee->seq_ctrl[0] == 0xFFF)
232 ieee->seq_ctrl[0] = 0;
236 /* avoid watchdog triggers */
237 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
241 spin_unlock_irqrestore(&ieee->lock, flags);
243 spin_unlock_irqrestore(&ieee->lock, flags);
244 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
246 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
248 if (ieee->seq_ctrl[0] == 0xFFF)
249 ieee->seq_ctrl[0] = 0;
253 /* check whether the managed packet queued greater than 5 */
254 if (!ieee->check_nic_enough_desc(ieee->dev,
255 tcb_desc->queue_index) ||
256 skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) ||
258 /* insert the skb packet to the management queue
260 * as for the completion function, it does not need
261 * to check it any more.
263 netdev_info(ieee->dev,
264 "%s():insert to waitqueue, queue_index:%d!\n",
265 __func__, tcb_desc->queue_index);
266 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
269 ieee->softmac_hard_start_xmit(skb, ieee->dev);
271 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
276 softmac_ps_mgmt_xmit(struct sk_buff *skb,
277 struct rtllib_device *ieee)
279 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
280 struct rtllib_hdr_3addr *header =
281 (struct rtllib_hdr_3addr *)skb->data;
283 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
285 fc = le16_to_cpu(header->frame_ctl);
286 type = WLAN_FC_GET_TYPE(fc);
287 stype = WLAN_FC_GET_STYPE(fc);
290 if (stype != RTLLIB_STYPE_PSPOLL)
291 tcb_desc->queue_index = MGNT_QUEUE;
293 tcb_desc->queue_index = HIGH_QUEUE;
295 if (ieee->disable_mgnt_queue)
296 tcb_desc->queue_index = HIGH_QUEUE;
299 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
300 tcb_desc->RATRIndex = 7;
301 tcb_desc->tx_dis_rate_fallback = 1;
302 tcb_desc->tx_use_drv_assinged_rate = 1;
304 if (type != RTLLIB_FTYPE_CTL) {
305 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
307 if (ieee->seq_ctrl[0] == 0xFFF)
308 ieee->seq_ctrl[0] = 0;
313 /* avoid watchdog triggers */
314 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
318 if (type != RTLLIB_FTYPE_CTL) {
319 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
321 if (ieee->seq_ctrl[0] == 0xFFF)
322 ieee->seq_ctrl[0] = 0;
326 ieee->softmac_hard_start_xmit(skb, ieee->dev);
331 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
333 unsigned int len, rate_len;
336 struct rtllib_probe_request *req;
338 len = ieee->current_network.ssid_len;
340 rate_len = rtllib_MFIE_rate_len(ieee);
342 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
343 2 + len + rate_len + ieee->tx_headroom);
348 skb_reserve(skb, ieee->tx_headroom);
350 req = skb_put(skb, sizeof(struct rtllib_probe_request));
351 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
352 req->header.duration_id = 0;
354 eth_broadcast_addr(req->header.addr1);
355 ether_addr_copy(req->header.addr2, ieee->dev->dev_addr);
356 eth_broadcast_addr(req->header.addr3);
358 tag = skb_put(skb, len + 2 + rate_len);
360 *tag++ = MFIE_TYPE_SSID;
362 memcpy(tag, ieee->current_network.ssid, len);
365 rtllib_MFIE_Brate(ieee, &tag);
366 rtllib_MFIE_Grate(ieee, &tag);
371 static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
373 static void rtllib_send_beacon(struct rtllib_device *ieee)
379 skb = rtllib_get_beacon_(ieee);
382 softmac_mgmt_xmit(skb, ieee);
383 ieee->softmac_stats.tx_beacons++;
386 if (ieee->beacon_txing && ieee->ieee_up)
387 mod_timer(&ieee->beacon_timer, jiffies +
388 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
392 static void rtllib_send_beacon_cb(struct timer_list *t)
394 struct rtllib_device *ieee =
395 from_timer(ieee, t, beacon_timer);
398 spin_lock_irqsave(&ieee->beacon_lock, flags);
399 rtllib_send_beacon(ieee);
400 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
403 /* Enables network monitor mode, all rx packets will be received. */
404 void rtllib_EnableNetMonitorMode(struct net_device *dev,
407 struct rtllib_device *ieee = netdev_priv_rsl(dev);
409 netdev_info(dev, "========>Enter Monitor Mode\n");
411 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
415 /* Disables network monitor mode. Only packets destinated to
416 * us will be received.
418 void rtllib_DisableNetMonitorMode(struct net_device *dev,
421 struct rtllib_device *ieee = netdev_priv_rsl(dev);
423 netdev_info(dev, "========>Exit Monitor Mode\n");
425 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
429 /* Enables the specialized promiscuous mode required by Intel.
430 * In this mode, Intel intends to hear traffics from/to other STAs in the
431 * same BSS. Therefore we don't have to disable checking BSSID and we only need
432 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
433 * packets from other STA.
435 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
438 bool bFilterOutNonAssociatedBSSID = false;
440 struct rtllib_device *ieee = netdev_priv_rsl(dev);
442 netdev_info(dev, "========>Enter Intel Promiscuous Mode\n");
444 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
445 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
446 (u8 *)&bFilterOutNonAssociatedBSSID);
448 ieee->net_promiscuous_md = true;
450 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
453 /* Disables the specialized promiscuous mode required by Intel.
454 * See MgntEnableIntelPromiscuousMode for detail.
456 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
459 bool bFilterOutNonAssociatedBSSID = true;
461 struct rtllib_device *ieee = netdev_priv_rsl(dev);
463 netdev_info(dev, "========>Exit Intel Promiscuous Mode\n");
465 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
466 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
467 (u8 *)&bFilterOutNonAssociatedBSSID);
469 ieee->net_promiscuous_md = false;
471 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
473 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
477 skb = rtllib_probe_req(ieee);
479 softmac_mgmt_xmit(skb, ieee);
480 ieee->softmac_stats.tx_probe_rq++;
485 static void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
487 if (ieee->active_scan && (ieee->softmac_features &
488 IEEE_SOFTMAC_PROBERQ)) {
489 rtllib_send_probe(ieee, 0);
490 rtllib_send_probe(ieee, 0);
494 static void rtllib_update_active_chan_map(struct rtllib_device *ieee)
496 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
497 MAX_CHANNEL_NUMBER+1);
500 /* this performs syncro scan blocking the caller until all channels
501 * in the allowed channel map has been checked.
503 static void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
505 union iwreq_data wrqu;
508 rtllib_update_active_chan_map(ieee);
510 ieee->be_scan_inprogress = true;
512 mutex_lock(&ieee->scan_mutex);
517 if (ch > MAX_CHANNEL_NUMBER)
518 goto out; /* scan completed */
519 } while (!ieee->active_channel_map[ch]);
521 /* this function can be called in two situations
522 * 1- We have switched to ad-hoc mode and we are
523 * performing a complete syncro scan before conclude
524 * there are no interesting cell and to create a
525 * new one. In this case the link state is
526 * RTLLIB_NOLINK until we found an interesting cell.
527 * If so the ieee8021_new_net, called by the RX path
528 * will set the state to RTLLIB_LINKED, so we stop
530 * 2- We are linked and the root uses run iwlist scan.
531 * So we switch to RTLLIB_LINKED_SCANNING to remember
532 * that we are still logically linked (not interested in
533 * new network events, despite for updating the net list,
534 * but we are temporarly 'unlinked' as the driver shall
535 * not filter RX frames and the channel is changing.
536 * So the only situation in which are interested is to check
537 * if the state become LINKED because of the #1 situation
540 if (ieee->state == RTLLIB_LINKED)
542 if (ieee->sync_scan_hurryup) {
543 netdev_info(ieee->dev,
544 "============>sync_scan_hurryup out\n");
548 ieee->set_chan(ieee->dev, ch);
549 if (ieee->active_channel_map[ch] == 1)
550 rtllib_send_probe_requests(ieee, 0);
552 /* this prevent excessive time wait when we
553 * need to wait for a syncro scan to end..
555 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
558 ieee->actscanning = false;
559 ieee->sync_scan_hurryup = 0;
561 if (ieee->state >= RTLLIB_LINKED) {
562 if (IS_DOT11D_ENABLE(ieee))
563 dot11d_scan_complete(ieee);
565 mutex_unlock(&ieee->scan_mutex);
567 ieee->be_scan_inprogress = false;
569 memset(&wrqu, 0, sizeof(wrqu));
570 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
573 static void rtllib_softmac_scan_wq(void *data)
575 struct rtllib_device *ieee = container_of_dwork_rsl(data,
576 struct rtllib_device, softmac_scan_wq);
577 u8 last_channel = ieee->current_network.channel;
579 rtllib_update_active_chan_map(ieee);
583 if (rtllib_act_scanning(ieee, true))
586 mutex_lock(&ieee->scan_mutex);
588 if (ieee->rf_power_state == rf_off) {
589 netdev_info(ieee->dev,
590 "======>%s():rf state is rf_off, return\n",
596 ieee->current_network.channel =
597 (ieee->current_network.channel + 1) %
599 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
600 if (!ieee->active_channel_map[ieee->current_network.channel])
601 ieee->current_network.channel = 6;
602 goto out; /* no good chans */
604 } while (!ieee->active_channel_map[ieee->current_network.channel]);
606 if (ieee->scanning_continue == 0)
609 ieee->set_chan(ieee->dev, ieee->current_network.channel);
611 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
612 rtllib_send_probe_requests(ieee, 0);
614 schedule_delayed_work(&ieee->softmac_scan_wq,
615 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
617 mutex_unlock(&ieee->scan_mutex);
621 if (IS_DOT11D_ENABLE(ieee))
622 dot11d_scan_complete(ieee);
623 ieee->current_network.channel = last_channel;
626 ieee->actscanning = false;
627 ieee->scan_watch_dog = 0;
628 ieee->scanning_continue = 0;
629 mutex_unlock(&ieee->scan_mutex);
634 static void rtllib_beacons_start(struct rtllib_device *ieee)
638 spin_lock_irqsave(&ieee->beacon_lock, flags);
640 ieee->beacon_txing = 1;
641 rtllib_send_beacon(ieee);
643 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
646 static void rtllib_beacons_stop(struct rtllib_device *ieee)
650 spin_lock_irqsave(&ieee->beacon_lock, flags);
652 ieee->beacon_txing = 0;
654 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
655 del_timer_sync(&ieee->beacon_timer);
660 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
662 ieee->stop_send_beacons(ieee->dev);
663 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
664 rtllib_beacons_stop(ieee);
666 EXPORT_SYMBOL(rtllib_stop_send_beacons);
669 void rtllib_start_send_beacons(struct rtllib_device *ieee)
671 ieee->start_send_beacons(ieee->dev);
672 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
673 rtllib_beacons_start(ieee);
675 EXPORT_SYMBOL(rtllib_start_send_beacons);
678 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
680 mutex_lock(&ieee->scan_mutex);
681 ieee->scan_watch_dog = 0;
682 if (ieee->scanning_continue == 1) {
683 ieee->scanning_continue = 0;
684 ieee->actscanning = false;
686 cancel_delayed_work_sync(&ieee->softmac_scan_wq);
689 mutex_unlock(&ieee->scan_mutex);
692 void rtllib_stop_scan(struct rtllib_device *ieee)
694 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
695 rtllib_softmac_stop_scan(ieee);
697 if (ieee->rtllib_stop_hw_scan)
698 ieee->rtllib_stop_hw_scan(ieee->dev);
701 EXPORT_SYMBOL(rtllib_stop_scan);
703 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
705 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
706 ieee->sync_scan_hurryup = 1;
708 if (ieee->rtllib_stop_hw_scan)
709 ieee->rtllib_stop_hw_scan(ieee->dev);
712 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
714 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
716 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
718 return ieee->be_scan_inprogress;
720 return ieee->actscanning || ieee->be_scan_inprogress;
722 return test_bit(STATUS_SCANNING, &ieee->status);
725 EXPORT_SYMBOL(rtllib_act_scanning);
727 /* called with ieee->lock held */
728 static void rtllib_start_scan(struct rtllib_device *ieee)
730 ieee->rtllib_ips_leave_wq(ieee->dev);
732 if (IS_DOT11D_ENABLE(ieee)) {
733 if (IS_COUNTRY_IE_VALID(ieee))
734 RESET_CIE_WATCHDOG(ieee);
736 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
737 if (ieee->scanning_continue == 0) {
738 ieee->actscanning = true;
739 ieee->scanning_continue = 1;
740 schedule_delayed_work(&ieee->softmac_scan_wq, 0);
743 if (ieee->rtllib_start_hw_scan)
744 ieee->rtllib_start_hw_scan(ieee->dev);
748 /* called with wx_mutex held */
749 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
751 if (IS_DOT11D_ENABLE(ieee)) {
752 if (IS_COUNTRY_IE_VALID(ieee))
753 RESET_CIE_WATCHDOG(ieee);
755 ieee->sync_scan_hurryup = 0;
756 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
757 rtllib_softmac_scan_syncro(ieee, is_mesh);
759 if (ieee->rtllib_start_hw_scan)
760 ieee->rtllib_start_hw_scan(ieee->dev);
763 EXPORT_SYMBOL(rtllib_start_scan_syncro);
765 static inline struct sk_buff *
766 rtllib_authentication_req(struct rtllib_network *beacon,
767 struct rtllib_device *ieee,
768 int challengelen, u8 *daddr)
771 struct rtllib_authentication *auth;
774 len = sizeof(struct rtllib_authentication) + challengelen +
775 ieee->tx_headroom + 4;
776 skb = dev_alloc_skb(len);
781 skb_reserve(skb, ieee->tx_headroom);
783 auth = skb_put(skb, sizeof(struct rtllib_authentication));
785 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
787 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
789 auth->header.duration_id = cpu_to_le16(0x013a);
790 ether_addr_copy(auth->header.addr1, beacon->bssid);
791 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
792 ether_addr_copy(auth->header.addr3, beacon->bssid);
793 if (ieee->auth_mode == 0)
794 auth->algorithm = WLAN_AUTH_OPEN;
795 else if (ieee->auth_mode == 1)
796 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
797 else if (ieee->auth_mode == 2)
798 auth->algorithm = WLAN_AUTH_OPEN;
799 auth->transaction = cpu_to_le16(ieee->associate_seq);
800 ieee->associate_seq++;
802 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
807 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee,
812 struct rtllib_probe_response *beacon_buf;
813 struct sk_buff *skb = NULL;
815 int atim_len, erp_len;
816 struct lib80211_crypt_data *crypt;
818 char *ssid = ieee->current_network.ssid;
819 int ssid_len = ieee->current_network.ssid_len;
820 int rate_len = ieee->current_network.rates_len+2;
821 int rate_ex_len = ieee->current_network.rates_ex_len;
822 int wpa_ie_len = ieee->wpa_ie_len;
823 u8 erpinfo_content = 0;
825 u8 *tmp_ht_cap_buf = NULL;
826 u8 tmp_ht_cap_len = 0;
827 u8 *tmp_ht_info_buf = NULL;
828 u8 tmp_ht_info_len = 0;
829 struct rt_hi_throughput *ht_info = ieee->ht_info;
830 u8 *tmp_generic_ie_buf = NULL;
831 u8 tmp_generic_ie_len = 0;
836 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
841 if ((ieee->current_network.mode == IEEE_G) ||
842 (ieee->current_network.mode == IEEE_N_24G &&
843 ieee->ht_info->bCurSuppCCK)) {
846 if (ieee->current_network.buseprotection)
847 erpinfo_content |= ERP_UseProtection;
851 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
852 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
853 ((strcmp(crypt->ops->name, "R-WEP") == 0 || wpa_ie_len));
854 if (ieee->ht_info->bCurrentHTSupport) {
855 tmp_ht_cap_buf = (u8 *)&(ieee->ht_info->SelfHTCap);
856 tmp_ht_cap_len = sizeof(ieee->ht_info->SelfHTCap);
857 tmp_ht_info_buf = (u8 *)&(ieee->ht_info->SelfHTInfo);
858 tmp_ht_info_len = sizeof(ieee->ht_info->SelfHTInfo);
859 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
860 &tmp_ht_cap_len, encrypt, false);
861 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
864 if (ht_info->reg_rt2rt_aggregation) {
865 tmp_generic_ie_buf = ieee->ht_info->sz_rt2rt_agg_buf;
867 sizeof(ieee->ht_info->sz_rt2rt_agg_buf);
868 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
869 &tmp_generic_ie_len);
873 beacon_size = sizeof(struct rtllib_probe_response)+2+
874 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
875 + wpa_ie_len + ieee->tx_headroom;
876 skb = dev_alloc_skb(beacon_size);
880 skb_reserve(skb, ieee->tx_headroom);
882 beacon_buf = skb_put(skb, (beacon_size - ieee->tx_headroom));
883 ether_addr_copy(beacon_buf->header.addr1, dest);
884 ether_addr_copy(beacon_buf->header.addr2, ieee->dev->dev_addr);
885 ether_addr_copy(beacon_buf->header.addr3, ieee->current_network.bssid);
887 beacon_buf->header.duration_id = 0;
888 beacon_buf->beacon_interval =
889 cpu_to_le16(ieee->current_network.beacon_interval);
890 beacon_buf->capability =
891 cpu_to_le16(ieee->current_network.capability &
892 WLAN_CAPABILITY_IBSS);
893 beacon_buf->capability |=
894 cpu_to_le16(ieee->current_network.capability &
895 WLAN_CAPABILITY_SHORT_PREAMBLE);
897 if (ieee->short_slot && (ieee->current_network.capability &
898 WLAN_CAPABILITY_SHORT_SLOT_TIME))
899 beacon_buf->capability |=
900 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
902 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
904 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
907 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
908 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
909 beacon_buf->info_element[0].len = ssid_len;
911 tag = (u8 *)beacon_buf->info_element[0].data;
913 memcpy(tag, ssid, ssid_len);
917 *(tag++) = MFIE_TYPE_RATES;
918 *(tag++) = rate_len-2;
919 memcpy(tag, ieee->current_network.rates, rate_len-2);
922 *(tag++) = MFIE_TYPE_DS_SET;
924 *(tag++) = ieee->current_network.channel;
928 *(tag++) = MFIE_TYPE_IBSS_SET;
930 val16 = ieee->current_network.atim_window;
931 memcpy((u8 *)tag, (u8 *)&val16, 2);
936 *(tag++) = MFIE_TYPE_ERP;
938 *(tag++) = erpinfo_content;
941 *(tag++) = MFIE_TYPE_RATES_EX;
942 *(tag++) = rate_ex_len-2;
943 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
944 tag += rate_ex_len-2;
948 if (ieee->iw_mode == IW_MODE_ADHOC)
949 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
950 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
951 tag += ieee->wpa_ie_len;
956 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
961 struct lib80211_crypt_data *crypt;
962 struct rtllib_assoc_response_frame *assoc;
965 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
966 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
969 skb = dev_alloc_skb(len);
974 skb_reserve(skb, ieee->tx_headroom);
976 assoc = skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
978 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
979 ether_addr_copy(assoc->header.addr1, dest);
980 ether_addr_copy(assoc->header.addr3, ieee->dev->dev_addr);
981 ether_addr_copy(assoc->header.addr2, ieee->dev->dev_addr);
982 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
983 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
986 if (ieee->short_slot)
988 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
990 if (ieee->host_encrypt)
991 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
995 encrypt = (crypt && crypt->ops);
998 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1001 assoc->aid = cpu_to_le16(ieee->assoc_id);
1002 if (ieee->assoc_id == 0x2007)
1007 tag = skb_put(skb, rate_len);
1008 rtllib_MFIE_Brate(ieee, &tag);
1009 rtllib_MFIE_Grate(ieee, &tag);
1014 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1017 struct sk_buff *skb = NULL;
1018 struct rtllib_authentication *auth;
1019 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1021 skb = dev_alloc_skb(len);
1025 skb->len = sizeof(struct rtllib_authentication);
1027 skb_reserve(skb, ieee->tx_headroom);
1029 auth = skb_put(skb, sizeof(struct rtllib_authentication));
1031 auth->status = cpu_to_le16(status);
1032 auth->transaction = cpu_to_le16(2);
1033 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1035 ether_addr_copy(auth->header.addr3, ieee->dev->dev_addr);
1036 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
1037 ether_addr_copy(auth->header.addr1, dest);
1038 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1044 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1046 struct sk_buff *skb;
1047 struct rtllib_hdr_3addr *hdr;
1049 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1053 skb_reserve(skb, ieee->tx_headroom);
1055 hdr = skb_put(skb, sizeof(struct rtllib_hdr_3addr));
1057 ether_addr_copy(hdr->addr1, ieee->current_network.bssid);
1058 ether_addr_copy(hdr->addr2, ieee->dev->dev_addr);
1059 ether_addr_copy(hdr->addr3, ieee->current_network.bssid);
1061 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1062 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1063 (pwr ? RTLLIB_FCTL_PM : 0));
1070 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1072 struct sk_buff *skb;
1073 struct rtllib_pspoll_hdr *hdr;
1075 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1079 skb_reserve(skb, ieee->tx_headroom);
1081 hdr = skb_put(skb, sizeof(struct rtllib_pspoll_hdr));
1083 ether_addr_copy(hdr->bssid, ieee->current_network.bssid);
1084 ether_addr_copy(hdr->ta, ieee->dev->dev_addr);
1086 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1087 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1094 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1096 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1099 softmac_mgmt_xmit(buf, ieee);
1103 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1105 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1108 softmac_mgmt_xmit(buf, ieee);
1112 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1114 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1117 softmac_mgmt_xmit(buf, ieee);
1121 static inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1126 if ((ieee->PMKIDList[i].bUsed) &&
1127 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1130 } while (i < NUM_PMKID_CACHE);
1132 if (i == NUM_PMKID_CACHE)
1137 static inline struct sk_buff *
1138 rtllib_association_req(struct rtllib_network *beacon,
1139 struct rtllib_device *ieee)
1141 struct sk_buff *skb;
1142 struct rtllib_assoc_request_frame *hdr;
1145 u8 *ht_cap_buf = NULL;
1147 u8 *realtek_ie_buf = NULL;
1148 u8 realtek_ie_len = 0;
1149 int wpa_ie_len = ieee->wpa_ie_len;
1150 int wps_ie_len = ieee->wps_ie_len;
1151 unsigned int ckip_ie_len = 0;
1152 unsigned int ccxrm_ie_len = 0;
1153 unsigned int cxvernum_ie_len = 0;
1154 struct lib80211_crypt_data *crypt;
1158 unsigned int rate_len = (beacon->rates_len ?
1159 (beacon->rates_len + 2) : 0) +
1160 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1163 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1164 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1168 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1170 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1171 ((strcmp(crypt->ops->name, "R-WEP") == 0 ||
1176 if ((ieee->rtllib_ap_sec_type &&
1177 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1178 ieee->bForcedBgMode) {
1179 ieee->ht_info->enable_ht = 0;
1180 ieee->mode = WIRELESS_MODE_G;
1183 if (ieee->ht_info->bCurrentHTSupport && ieee->ht_info->enable_ht) {
1184 ht_cap_buf = (u8 *)&(ieee->ht_info->SelfHTCap);
1185 ht_cap_len = sizeof(ieee->ht_info->SelfHTCap);
1186 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1188 if (ieee->ht_info->current_rt2rt_aggregation) {
1189 realtek_ie_buf = ieee->ht_info->sz_rt2rt_agg_buf;
1191 sizeof(ieee->ht_info->sz_rt2rt_agg_buf);
1192 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1197 if (beacon->bCkipSupported)
1199 if (beacon->bCcxRmEnable)
1201 if (beacon->BssCcxVerNumber >= 2)
1202 cxvernum_ie_len = 5+2;
1204 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1205 if (PMKCacheIdx >= 0) {
1207 netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n",
1210 len = sizeof(struct rtllib_assoc_request_frame) + 2
1222 + ieee->tx_headroom;
1224 skb = dev_alloc_skb(len);
1229 skb_reserve(skb, ieee->tx_headroom);
1231 hdr = skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1234 hdr->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_REQ);
1235 hdr->header.duration_id = cpu_to_le16(37);
1236 ether_addr_copy(hdr->header.addr1, beacon->bssid);
1237 ether_addr_copy(hdr->header.addr2, ieee->dev->dev_addr);
1238 ether_addr_copy(hdr->header.addr3, beacon->bssid);
1240 ether_addr_copy(ieee->ap_mac_addr, beacon->bssid);
1242 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1243 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1244 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1246 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1247 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1249 if (ieee->short_slot &&
1250 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1251 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1254 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1256 hdr->info_element[0].id = MFIE_TYPE_SSID;
1258 hdr->info_element[0].len = beacon->ssid_len;
1259 skb_put_data(skb, beacon->ssid, beacon->ssid_len);
1261 tag = skb_put(skb, rate_len);
1263 if (beacon->rates_len) {
1264 *tag++ = MFIE_TYPE_RATES;
1265 *tag++ = beacon->rates_len;
1266 for (i = 0; i < beacon->rates_len; i++)
1267 *tag++ = beacon->rates[i];
1270 if (beacon->rates_ex_len) {
1271 *tag++ = MFIE_TYPE_RATES_EX;
1272 *tag++ = beacon->rates_ex_len;
1273 for (i = 0; i < beacon->rates_ex_len; i++)
1274 *tag++ = beacon->rates_ex[i];
1277 if (beacon->bCkipSupported) {
1278 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1279 u8 CcxAironetBuf[30];
1280 struct octet_string osCcxAironetIE;
1282 memset(CcxAironetBuf, 0, 30);
1283 osCcxAironetIE.Octet = CcxAironetBuf;
1284 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1285 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1286 sizeof(AironetIeOui));
1288 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1289 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1290 tag = skb_put(skb, ckip_ie_len);
1291 *tag++ = MFIE_TYPE_AIRONET;
1292 *tag++ = osCcxAironetIE.Length;
1293 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1294 tag += osCcxAironetIE.Length;
1297 if (beacon->bCcxRmEnable) {
1298 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1300 struct octet_string osCcxRmCap;
1302 osCcxRmCap.Octet = (u8 *)CcxRmCapBuf;
1303 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1304 tag = skb_put(skb, ccxrm_ie_len);
1305 *tag++ = MFIE_TYPE_GENERIC;
1306 *tag++ = osCcxRmCap.Length;
1307 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1308 tag += osCcxRmCap.Length;
1311 if (beacon->BssCcxVerNumber >= 2) {
1312 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1313 struct octet_string osCcxVerNum;
1315 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1316 osCcxVerNum.Octet = CcxVerNumBuf;
1317 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1318 tag = skb_put(skb, cxvernum_ie_len);
1319 *tag++ = MFIE_TYPE_GENERIC;
1320 *tag++ = osCcxVerNum.Length;
1321 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1322 tag += osCcxVerNum.Length;
1324 if (ieee->ht_info->bCurrentHTSupport && ieee->ht_info->enable_ht) {
1325 if (ieee->ht_info->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1326 tag = skb_put(skb, ht_cap_len);
1327 *tag++ = MFIE_TYPE_HT_CAP;
1328 *tag++ = ht_cap_len - 2;
1329 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1330 tag += ht_cap_len - 2;
1335 skb_put_data(skb, ieee->wpa_ie, ieee->wpa_ie_len);
1337 if (PMKCacheIdx >= 0) {
1338 tag = skb_put(skb, 18);
1341 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1346 tag = skb_put(skb, wmm_info_len);
1347 rtllib_WMM_Info(ieee, &tag);
1350 if (wps_ie_len && ieee->wps_ie)
1351 skb_put_data(skb, ieee->wps_ie, wps_ie_len);
1353 if (turbo_info_len) {
1354 tag = skb_put(skb, turbo_info_len);
1355 rtllib_TURBO_Info(ieee, &tag);
1358 if (ieee->ht_info->bCurrentHTSupport && ieee->ht_info->enable_ht) {
1359 if (ieee->ht_info->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1360 tag = skb_put(skb, ht_cap_len);
1361 *tag++ = MFIE_TYPE_GENERIC;
1362 *tag++ = ht_cap_len - 2;
1363 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1364 tag += ht_cap_len - 2;
1367 if (ieee->ht_info->current_rt2rt_aggregation) {
1368 tag = skb_put(skb, realtek_ie_len);
1369 *tag++ = MFIE_TYPE_GENERIC;
1370 *tag++ = realtek_ie_len - 2;
1371 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1375 kfree(ieee->assocreq_ies);
1376 ieee->assocreq_ies = NULL;
1377 ies = &(hdr->info_element[0].id);
1378 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1379 ieee->assocreq_ies = kmemdup(ies, ieee->assocreq_ies_len, GFP_ATOMIC);
1380 if (!ieee->assocreq_ies)
1381 ieee->assocreq_ies_len = 0;
1386 static void rtllib_associate_abort(struct rtllib_device *ieee)
1388 unsigned long flags;
1390 spin_lock_irqsave(&ieee->lock, flags);
1392 ieee->associate_seq++;
1394 /* don't scan, and avoid to have the RX path possibily
1395 * try again to associate. Even do not react to AUTH or
1396 * ASSOC response. Just wait for the retry wq to be scheduled.
1397 * Here we will check if there are good nets to associate
1398 * with, so we retry or just get back to NO_LINK and scanning
1400 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1401 netdev_dbg(ieee->dev, "Authentication failed\n");
1402 ieee->softmac_stats.no_auth_rs++;
1404 netdev_dbg(ieee->dev, "Association failed\n");
1405 ieee->softmac_stats.no_ass_rs++;
1408 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1410 schedule_delayed_work(&ieee->associate_retry_wq,
1411 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1413 spin_unlock_irqrestore(&ieee->lock, flags);
1416 static void rtllib_associate_abort_cb(struct timer_list *t)
1418 struct rtllib_device *dev = from_timer(dev, t, associate_timer);
1420 rtllib_associate_abort(dev);
1423 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr)
1425 struct rtllib_network *beacon = &ieee->current_network;
1426 struct sk_buff *skb;
1428 netdev_dbg(ieee->dev, "Stopping scan\n");
1430 ieee->softmac_stats.tx_auth_rq++;
1432 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1435 rtllib_associate_abort(ieee);
1437 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING;
1438 netdev_dbg(ieee->dev, "Sending authentication request\n");
1439 softmac_mgmt_xmit(skb, ieee);
1440 if (!timer_pending(&ieee->associate_timer)) {
1441 ieee->associate_timer.expires = jiffies + (HZ / 2);
1442 add_timer(&ieee->associate_timer);
1447 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge,
1451 struct sk_buff *skb;
1452 struct rtllib_network *beacon = &ieee->current_network;
1454 ieee->associate_seq++;
1455 ieee->softmac_stats.tx_auth_rq++;
1457 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1460 rtllib_associate_abort(ieee);
1462 c = skb_put(skb, chlen+2);
1463 *(c++) = MFIE_TYPE_CHALLENGE;
1465 memcpy(c, challenge, chlen);
1467 netdev_dbg(ieee->dev,
1468 "Sending authentication challenge response\n");
1470 rtllib_encrypt_fragment(ieee, skb,
1471 sizeof(struct rtllib_hdr_3addr));
1473 softmac_mgmt_xmit(skb, ieee);
1474 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1479 static void rtllib_associate_step2(struct rtllib_device *ieee)
1481 struct sk_buff *skb;
1482 struct rtllib_network *beacon = &ieee->current_network;
1484 del_timer_sync(&ieee->associate_timer);
1486 netdev_dbg(ieee->dev, "Sending association request\n");
1488 ieee->softmac_stats.tx_ass_rq++;
1489 skb = rtllib_association_req(beacon, ieee);
1491 rtllib_associate_abort(ieee);
1493 softmac_mgmt_xmit(skb, ieee);
1494 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1498 static void rtllib_associate_complete_wq(void *data)
1500 struct rtllib_device *ieee = (struct rtllib_device *)
1502 struct rtllib_device,
1503 associate_complete_wq);
1504 struct rt_pwr_save_ctrl *psc = &ieee->pwr_save_ctrl;
1506 netdev_info(ieee->dev, "Associated successfully with %pM\n",
1507 ieee->current_network.bssid);
1508 if (!ieee->is_silent_reset) {
1509 netdev_info(ieee->dev, "normal associate\n");
1510 notify_wx_assoc_event(ieee);
1513 netif_carrier_on(ieee->dev);
1514 ieee->is_roaming = false;
1515 if (rtllib_is_54g(&ieee->current_network) &&
1516 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1518 netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate);
1521 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1522 netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate);
1524 if (ieee->ht_info->bCurrentHTSupport && ieee->ht_info->enable_ht) {
1525 netdev_info(ieee->dev, "Successfully associated, ht enabled\n");
1528 netdev_info(ieee->dev,
1529 "Successfully associated, ht not enabled(%d, %d)\n",
1530 ieee->ht_info->bCurrentHTSupport,
1531 ieee->ht_info->enable_ht);
1532 memset(ieee->dot11ht_oper_rate_set, 0, 16);
1534 ieee->link_detect_info.SlotNum = 2 * (1 +
1535 ieee->current_network.beacon_interval /
1537 if (ieee->link_detect_info.NumRecvBcnInPeriod == 0 ||
1538 ieee->link_detect_info.NumRecvDataInPeriod == 0) {
1539 ieee->link_detect_info.NumRecvBcnInPeriod = 1;
1540 ieee->link_detect_info.NumRecvDataInPeriod = 1;
1542 psc->LpsIdleCount = 0;
1543 ieee->link_change(ieee->dev);
1545 if (ieee->is_silent_reset) {
1546 netdev_info(ieee->dev, "silent reset associate\n");
1547 ieee->is_silent_reset = false;
1550 if (ieee->data_hard_resume)
1551 ieee->data_hard_resume(ieee->dev);
1555 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1559 static void rtllib_associate_complete(struct rtllib_device *ieee)
1561 del_timer_sync(&ieee->associate_timer);
1563 ieee->state = RTLLIB_LINKED;
1564 rtllib_sta_send_associnfo(ieee);
1566 schedule_work(&ieee->associate_complete_wq);
1569 static void rtllib_associate_procedure_wq(void *data)
1571 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1572 struct rtllib_device,
1573 associate_procedure_wq);
1574 rtllib_stop_scan_syncro(ieee);
1575 ieee->rtllib_ips_leave(ieee->dev);
1576 mutex_lock(&ieee->wx_mutex);
1578 if (ieee->data_hard_stop)
1579 ieee->data_hard_stop(ieee->dev);
1581 rtllib_stop_scan(ieee);
1582 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1583 if (ieee->rf_power_state == rf_off) {
1584 ieee->rtllib_ips_leave_wq(ieee->dev);
1585 mutex_unlock(&ieee->wx_mutex);
1588 ieee->associate_seq = 1;
1590 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1592 mutex_unlock(&ieee->wx_mutex);
1595 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1596 struct rtllib_network *net)
1598 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1599 int tmp_ssid_len = 0;
1601 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1603 /* we are interested in new only if we are not associated
1604 * and we are not associating / authenticating
1606 if (ieee->state != RTLLIB_NOLINK)
1609 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1610 WLAN_CAPABILITY_ESS))
1613 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1614 WLAN_CAPABILITY_IBSS))
1617 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1618 (net->channel > ieee->ibss_maxjoin_chal))
1620 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1621 /* if the user specified the AP MAC, we need also the essid
1622 * This could be obtained by beacons or, if the network does not
1623 * broadcast it, it can be put manually.
1625 apset = ieee->wap_set;
1626 ssidset = ieee->ssid_set;
1627 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1628 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1631 ssidmatch = (ieee->current_network.ssid_len ==
1632 net->hidden_ssid_len) &&
1633 (!strncmp(ieee->current_network.ssid,
1634 net->hidden_ssid, net->hidden_ssid_len));
1635 if (net->hidden_ssid_len > 0) {
1636 strncpy(net->ssid, net->hidden_ssid,
1637 net->hidden_ssid_len);
1638 net->ssid_len = net->hidden_ssid_len;
1643 (ieee->current_network.ssid_len == net->ssid_len) &&
1644 (!strncmp(ieee->current_network.ssid, net->ssid,
1647 /* if the user set the AP check if match.
1648 * if the network does not broadcast essid we check the
1649 * user supplied ANY essid
1650 * if the network does broadcast and the user does not set
1652 * if the network does broadcast and the user did set essid
1653 * check if essid match
1654 * if the ap is not set, check that the user set the bssid
1655 * and the network does broadcast and that those two bssid match
1657 if ((apset && apmatch &&
1658 ((ssidset && ssidbroad && ssidmatch) ||
1659 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1660 (!apset && ssidset && ssidbroad && ssidmatch) ||
1661 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1662 /* Save the essid so that if it is hidden, it is
1663 * replaced with the essid provided by the user.
1666 memcpy(tmp_ssid, ieee->current_network.ssid,
1667 ieee->current_network.ssid_len);
1668 tmp_ssid_len = ieee->current_network.ssid_len;
1670 memcpy(&ieee->current_network, net,
1671 sizeof(ieee->current_network));
1673 memcpy(ieee->current_network.ssid, tmp_ssid,
1675 ieee->current_network.ssid_len = tmp_ssid_len;
1677 netdev_info(ieee->dev,
1678 "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",
1679 ieee->current_network.ssid,
1680 ieee->current_network.channel,
1681 ieee->current_network.qos_data.supported,
1682 ieee->ht_info->enable_ht,
1683 ieee->current_network.bssht.bd_support_ht,
1684 ieee->current_network.mode,
1685 ieee->current_network.flags);
1687 if ((rtllib_act_scanning(ieee, false)) &&
1688 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1689 rtllib_stop_scan_syncro(ieee);
1691 HTResetIOTSetting(ieee->ht_info);
1693 if (ieee->iw_mode == IW_MODE_INFRA) {
1694 /* Join the network for the first time */
1695 ieee->AsocRetryCount = 0;
1696 if ((ieee->current_network.qos_data.supported == 1) &&
1697 ieee->current_network.bssht.bd_support_ht)
1698 HTResetSelfAndSavePeerSetting(ieee,
1699 &(ieee->current_network));
1701 ieee->ht_info->bCurrentHTSupport =
1704 ieee->state = RTLLIB_ASSOCIATING;
1705 if (ieee->LedControlHandler != NULL)
1706 ieee->LedControlHandler(ieee->dev,
1707 LED_CTL_START_TO_LINK);
1708 schedule_delayed_work(
1709 &ieee->associate_procedure_wq, 0);
1711 if (rtllib_is_54g(&ieee->current_network) &&
1713 RTLLIB_OFDM_MODULATION)) {
1715 ieee->SetWirelessMode(ieee->dev,
1717 netdev_info(ieee->dev,
1721 ieee->SetWirelessMode(ieee->dev,
1723 netdev_info(ieee->dev,
1726 memset(ieee->dot11ht_oper_rate_set, 0, 16);
1727 ieee->state = RTLLIB_LINKED;
1733 static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1735 unsigned long flags;
1736 struct rtllib_network *target;
1738 spin_lock_irqsave(&ieee->lock, flags);
1740 list_for_each_entry(target, &ieee->network_list, list) {
1742 /* if the state become different that NOLINK means
1743 * we had found what we are searching for
1746 if (ieee->state != RTLLIB_NOLINK)
1749 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1750 ieee->scan_age, jiffies))
1751 rtllib_softmac_new_net(ieee, target);
1753 spin_unlock_irqrestore(&ieee->lock, flags);
1756 static inline int auth_parse(struct net_device *dev, struct sk_buff *skb,
1757 u8 **challenge, int *chlen)
1759 struct rtllib_authentication *a;
1762 if (skb->len < (sizeof(struct rtllib_authentication) -
1763 sizeof(struct rtllib_info_element))) {
1764 netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
1768 a = (struct rtllib_authentication *)skb->data;
1769 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1770 t = skb->data + sizeof(struct rtllib_authentication);
1772 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1774 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1781 netdev_dbg(dev, "auth_parse() failed\n");
1788 static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1790 struct rtllib_authentication *a;
1792 if (skb->len < (sizeof(struct rtllib_authentication) -
1793 sizeof(struct rtllib_info_element))) {
1794 netdev_dbg(dev, "invalid len in auth request: %d\n", skb->len);
1797 a = (struct rtllib_authentication *)skb->data;
1799 ether_addr_copy(dest, a->header.addr2);
1801 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1802 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1804 return WLAN_STATUS_SUCCESS;
1807 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1814 struct rtllib_hdr_3addr *header =
1815 (struct rtllib_hdr_3addr *)skb->data;
1818 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1819 return -1; /* corrupted */
1822 (!ether_addr_equal(header->addr3, ieee->current_network.bssid)) &&
1823 (!is_broadcast_ether_addr(header->addr3));
1827 ether_addr_copy(src, header->addr2);
1829 skbend = (u8 *)skb->data + skb->len;
1831 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1833 while (tag + 1 < skbend) {
1836 ssidlen = *(tag + 1);
1839 tag++; /* point to the len field */
1840 tag = tag + *(tag); /* point to the last data byte of the tag */
1841 tag++; /* point to the next tag */
1848 return 1; /* ssid not found in tagged param */
1850 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1853 static int assoc_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1855 struct rtllib_assoc_request_frame *a;
1857 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1858 sizeof(struct rtllib_info_element))) {
1859 netdev_dbg(dev, "invalid len in auth request:%d\n", skb->len);
1863 a = (struct rtllib_assoc_request_frame *)skb->data;
1865 ether_addr_copy(dest, a->header.addr2);
1870 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1873 struct rtllib_assoc_response_frame *response_head;
1876 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1877 netdev_dbg(ieee->dev, "Invalid len in auth resp: %d\n",
1882 response_head = (struct rtllib_assoc_response_frame *)skb->data;
1883 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1885 status_code = le16_to_cpu(response_head->status);
1886 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1887 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1888 ((ieee->mode == IEEE_G) &&
1889 (ieee->current_network.mode == IEEE_N_24G) &&
1890 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1891 ieee->ht_info->iot_action |= HT_IOT_ACT_PURE_N_MODE;
1893 ieee->AsocRetryCount = 0;
1896 return le16_to_cpu(response_head->status);
1899 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1903 ieee->softmac_stats.rx_probe_rq++;
1904 if (probe_rq_parse(ieee, skb, dest) > 0) {
1905 ieee->softmac_stats.tx_probe_rs++;
1906 rtllib_resp_to_probe(ieee, dest);
1910 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1911 struct sk_buff *skb)
1916 ieee->softmac_stats.rx_auth_rq++;
1918 status = auth_rq_parse(ieee->dev, skb, dest);
1920 rtllib_resp_to_auth(ieee, status, dest);
1923 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1924 struct sk_buff *skb)
1929 ieee->softmac_stats.rx_ass_rq++;
1930 if (assoc_rq_parse(ieee->dev, skb, dest) != -1)
1931 rtllib_resp_to_assoc_rq(ieee, dest);
1933 netdev_info(ieee->dev, "New client associated: %pM\n", dest);
1936 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1939 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1942 softmac_ps_mgmt_xmit(buf, ieee);
1944 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1946 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1948 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1951 softmac_ps_mgmt_xmit(buf, ieee);
1954 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1958 struct rt_pwr_save_ctrl *psc = &ieee->pwr_save_ctrl;
1960 if (ieee->LPSDelayCnt) {
1961 ieee->LPSDelayCnt--;
1965 dtim = ieee->current_network.dtim_data;
1966 if (!(dtim & RTLLIB_DTIM_VALID))
1968 timeout = ieee->current_network.beacon_interval;
1969 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
1970 /* there's no need to nofity AP that I find you buffered
1971 * with broadcast packet
1973 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
1976 if (!time_after(jiffies,
1977 dev_trans_start(ieee->dev) + msecs_to_jiffies(timeout)))
1979 if (!time_after(jiffies,
1980 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
1982 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
1983 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1987 if (ieee->bAwakePktSent) {
1988 psc->LPSAwakeIntvl = 1;
1992 if (psc->LPSAwakeIntvl == 0)
1993 psc->LPSAwakeIntvl = 1;
1994 if (psc->reg_max_lps_awake_intvl == 0)
1996 else if (psc->reg_max_lps_awake_intvl == 0xFF)
1997 MaxPeriod = ieee->current_network.dtim_period;
1999 MaxPeriod = psc->reg_max_lps_awake_intvl;
2000 psc->LPSAwakeIntvl = (psc->LPSAwakeIntvl >=
2001 MaxPeriod) ? MaxPeriod :
2002 (psc->LPSAwakeIntvl + 1);
2005 u8 LPSAwakeIntvl_tmp = 0;
2006 u8 period = ieee->current_network.dtim_period;
2007 u8 count = ieee->current_network.tim.tim_count;
2010 if (psc->LPSAwakeIntvl > period)
2011 LPSAwakeIntvl_tmp = period +
2012 (psc->LPSAwakeIntvl -
2014 ((psc->LPSAwakeIntvl-period) %
2017 LPSAwakeIntvl_tmp = psc->LPSAwakeIntvl;
2020 if (psc->LPSAwakeIntvl >
2021 ieee->current_network.tim.tim_count)
2022 LPSAwakeIntvl_tmp = count +
2023 (psc->LPSAwakeIntvl - count) -
2024 ((psc->LPSAwakeIntvl-count)%period);
2026 LPSAwakeIntvl_tmp = psc->LPSAwakeIntvl;
2029 *time = ieee->current_network.last_dtim_sta_time
2030 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2040 static inline void rtllib_sta_ps(struct work_struct *work)
2042 struct rtllib_device *ieee;
2045 unsigned long flags, flags2;
2047 ieee = container_of(work, struct rtllib_device, ps_task);
2049 spin_lock_irqsave(&ieee->lock, flags);
2051 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2052 ieee->iw_mode != IW_MODE_INFRA ||
2053 ieee->state != RTLLIB_LINKED)) {
2054 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2055 rtllib_sta_wakeup(ieee, 1);
2057 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2059 sleep = rtllib_sta_ps_sleep(ieee, &time);
2060 /* 2 wake, 1 sleep, 0 do nothing */
2064 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2065 ieee->enter_sleep_state(ieee->dev, time);
2066 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2067 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2069 if (ieee->ps_is_queue_empty(ieee->dev)) {
2070 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2071 ieee->ack_tx_to_ieee = 1;
2072 rtllib_sta_ps_send_null_frame(ieee, 1);
2073 ieee->ps_time = time;
2075 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2079 ieee->bAwakePktSent = false;
2081 } else if (sleep == 2) {
2082 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2084 rtllib_sta_wakeup(ieee, 1);
2086 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2090 spin_unlock_irqrestore(&ieee->lock, flags);
2094 static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2096 if (ieee->sta_sleep == LPS_IS_WAKE) {
2098 if (ieee->ht_info->iot_action &
2099 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2100 ieee->ack_tx_to_ieee = 1;
2101 rtllib_sta_ps_send_null_frame(ieee, 0);
2103 ieee->ack_tx_to_ieee = 1;
2104 rtllib_sta_ps_send_pspoll_frame(ieee);
2111 if (ieee->sta_sleep == LPS_IS_SLEEP)
2112 ieee->sta_wake_up(ieee->dev);
2114 if (ieee->ht_info->iot_action &
2115 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2116 ieee->ack_tx_to_ieee = 1;
2117 rtllib_sta_ps_send_null_frame(ieee, 0);
2119 ieee->ack_tx_to_ieee = 1;
2120 ieee->polling = true;
2121 rtllib_sta_ps_send_pspoll_frame(ieee);
2125 ieee->sta_sleep = LPS_IS_WAKE;
2126 ieee->polling = false;
2130 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2132 unsigned long flags, flags2;
2134 spin_lock_irqsave(&ieee->lock, flags);
2136 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2137 /* Null frame with PS bit set */
2139 ieee->sta_sleep = LPS_IS_SLEEP;
2140 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2142 /* if the card report not success we can't be sure the AP
2143 * has not RXed so we can't assume the AP believe us awake
2145 } else {/* 21112005 - tx again null without PS bit if lost */
2147 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2148 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2149 if (ieee->ht_info->iot_action &
2150 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2151 rtllib_sta_ps_send_null_frame(ieee, 0);
2153 rtllib_sta_ps_send_pspoll_frame(ieee);
2154 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2157 spin_unlock_irqrestore(&ieee->lock, flags);
2159 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2161 static void rtllib_process_action(struct rtllib_device *ieee,
2162 struct sk_buff *skb)
2164 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *)skb->data;
2165 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2169 netdev_warn(ieee->dev,
2170 "Error getting payload of action frame\n");
2180 rtllib_rx_ADDBAReq(ieee, skb);
2183 rtllib_rx_ADDBARsp(ieee, skb);
2186 rtllib_rx_DELBA(ieee, skb);
2196 rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2197 struct rtllib_rx_stats *rx_stats)
2202 struct rtllib_assoc_response_frame *assoc_resp;
2203 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *)skb->data;
2204 u16 frame_ctl = le16_to_cpu(header->frame_ctl);
2206 netdev_dbg(ieee->dev, "received [RE]ASSOCIATION RESPONSE (%d)\n",
2207 WLAN_FC_GET_STYPE(frame_ctl));
2209 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2210 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2211 (ieee->iw_mode == IW_MODE_INFRA)) {
2212 errcode = assoc_parse(ieee, skb, &aid);
2214 struct rtllib_network *network =
2215 kzalloc(sizeof(struct rtllib_network),
2220 ieee->state = RTLLIB_LINKED;
2221 ieee->assoc_id = aid;
2222 ieee->softmac_stats.rx_ass_ok++;
2223 /* station support qos */
2224 /* Let the register setting default with Legacy station */
2225 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2226 if (ieee->current_network.qos_data.supported == 1) {
2227 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2228 rx_stats->len - sizeof(*assoc_resp),
2229 network, rx_stats)) {
2233 memcpy(ieee->ht_info->PeerHTCapBuf,
2234 network->bssht.bd_ht_cap_buf,
2235 network->bssht.bd_ht_cap_len);
2236 memcpy(ieee->ht_info->PeerHTInfoBuf,
2237 network->bssht.bd_ht_info_buf,
2238 network->bssht.bd_ht_info_len);
2239 ieee->handle_assoc_response(ieee->dev,
2240 (struct rtllib_assoc_response_frame *)header, network);
2244 kfree(ieee->assocresp_ies);
2245 ieee->assocresp_ies = NULL;
2246 ies = &(assoc_resp->info_element[0].id);
2247 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2248 ieee->assocresp_ies = kmemdup(ies,
2249 ieee->assocresp_ies_len,
2251 if (!ieee->assocresp_ies)
2252 ieee->assocresp_ies_len = 0;
2254 rtllib_associate_complete(ieee);
2256 /* aid could not been allocated */
2257 ieee->softmac_stats.rx_ass_err++;
2258 netdev_info(ieee->dev,
2259 "Association response status code 0x%x\n",
2261 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2262 schedule_delayed_work(
2263 &ieee->associate_procedure_wq, 0);
2265 rtllib_associate_abort(ieee);
2271 static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
2276 bool bSupportNmode = true, bHalfSupportNmode = false;
2278 errcode = auth_parse(ieee->dev, skb, &challenge, &chlen);
2281 ieee->softmac_stats.rx_auth_rs_err++;
2282 netdev_info(ieee->dev,
2283 "Authentication response status code %d", errcode);
2284 rtllib_associate_abort(ieee);
2288 if (ieee->open_wep || !challenge) {
2289 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2290 ieee->softmac_stats.rx_auth_rs_ok++;
2291 if (!(ieee->ht_info->iot_action & HT_IOT_ACT_PURE_N_MODE)) {
2292 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2293 if (IsHTHalfNmodeAPs(ieee)) {
2294 bSupportNmode = true;
2295 bHalfSupportNmode = true;
2297 bSupportNmode = false;
2298 bHalfSupportNmode = false;
2302 /* Dummy wirless mode setting to avoid encryption issue */
2303 if (bSupportNmode) {
2304 ieee->SetWirelessMode(ieee->dev,
2305 ieee->current_network.mode);
2308 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2311 if ((ieee->current_network.mode == IEEE_N_24G) &&
2312 bHalfSupportNmode) {
2313 netdev_info(ieee->dev, "======>enter half N mode\n");
2314 ieee->bHalfWirelessN24GMode = true;
2316 ieee->bHalfWirelessN24GMode = false;
2318 rtllib_associate_step2(ieee);
2320 rtllib_auth_challenge(ieee, challenge, chlen);
2325 rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2326 struct rtllib_rx_stats *rx_stats)
2329 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2330 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2331 (ieee->iw_mode == IW_MODE_INFRA)) {
2332 netdev_dbg(ieee->dev,
2333 "Received authentication response");
2334 rtllib_rx_auth_resp(ieee, skb);
2335 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2336 rtllib_rx_auth_rq(ieee, skb);
2343 rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2345 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *)skb->data;
2348 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2351 /* FIXME for now repeat all the association procedure
2352 * both for disassociation and deauthentication
2354 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2355 ieee->state == RTLLIB_LINKED &&
2356 (ieee->iw_mode == IW_MODE_INFRA)) {
2357 frame_ctl = le16_to_cpu(header->frame_ctl);
2358 netdev_info(ieee->dev,
2359 "==========>received disassoc/deauth(%x) frame, reason code:%x\n",
2360 WLAN_FC_GET_STYPE(frame_ctl),
2361 ((struct rtllib_disassoc *)skb->data)->reason);
2362 ieee->state = RTLLIB_ASSOCIATING;
2363 ieee->softmac_stats.reassoc++;
2364 ieee->is_roaming = true;
2365 ieee->link_detect_info.bBusyTraffic = false;
2366 rtllib_disassociate(ieee);
2367 RemovePeerTS(ieee, header->addr2);
2368 if (ieee->LedControlHandler != NULL)
2369 ieee->LedControlHandler(ieee->dev,
2370 LED_CTL_START_TO_LINK);
2372 if (!(ieee->rtllib_ap_sec_type(ieee) &
2373 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2374 schedule_delayed_work(
2375 &ieee->associate_procedure_wq, 5);
2380 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2381 struct sk_buff *skb,
2382 struct rtllib_rx_stats *rx_stats, u16 type,
2385 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *)skb->data;
2388 if (!ieee->proto_started)
2391 frame_ctl = le16_to_cpu(header->frame_ctl);
2392 switch (WLAN_FC_GET_STYPE(frame_ctl)) {
2393 case RTLLIB_STYPE_ASSOC_RESP:
2394 case RTLLIB_STYPE_REASSOC_RESP:
2395 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2398 case RTLLIB_STYPE_ASSOC_REQ:
2399 case RTLLIB_STYPE_REASSOC_REQ:
2400 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2401 ieee->iw_mode == IW_MODE_MASTER)
2402 rtllib_rx_assoc_rq(ieee, skb);
2404 case RTLLIB_STYPE_AUTH:
2405 rtllib_rx_auth(ieee, skb, rx_stats);
2407 case RTLLIB_STYPE_DISASSOC:
2408 case RTLLIB_STYPE_DEAUTH:
2409 rtllib_rx_deauth(ieee, skb);
2411 case RTLLIB_STYPE_MANAGE_ACT:
2412 rtllib_process_action(ieee, skb);
2420 /* following are for a simpler TX queue management.
2421 * Instead of using netif_[stop/wake]_queue the driver
2422 * will use these two functions (plus a reset one), that
2423 * will internally use the kernel netif_* and takes
2424 * care of the ieee802.11 fragmentation.
2425 * So the driver receives a fragment per time and might
2426 * call the stop function when it wants to not
2427 * have enough room to TX an entire packet.
2428 * This might be useful if each fragment needs it's own
2429 * descriptor, thus just keep a total free memory > than
2430 * the max fragmentation threshold is not enough.. If the
2431 * ieee802.11 stack passed a TXB struct then you need
2432 * to keep N free descriptors where
2433 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2434 * In this way you need just one and the 802.11 stack
2435 * will take care of buffering fragments and pass them to
2436 * the driver later, when it wakes the queue.
2438 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2441 unsigned int queue_index = txb->queue_index;
2442 unsigned long flags;
2444 struct cb_desc *tcb_desc = NULL;
2445 unsigned long queue_len = 0;
2447 spin_lock_irqsave(&ieee->lock, flags);
2449 /* called with 2nd parm 0, no tx mgmt lock required */
2450 rtllib_sta_wakeup(ieee, 0);
2452 /* update the tx status */
2453 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2455 if (tcb_desc->bMulticast)
2456 ieee->stats.multicast++;
2458 /* if xmit available, just xmit it immediately, else just insert it to
2461 for (i = 0; i < txb->nr_frags; i++) {
2462 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2463 if ((queue_len != 0) ||
2464 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2465 (ieee->queue_stop)) {
2466 /* insert the skb packet to the wait queue
2467 * as for the completion function, it does not need
2468 * to check it any more.
2470 if (queue_len < 200)
2471 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2474 kfree_skb(txb->fragments[i]);
2476 ieee->softmac_data_hard_start_xmit(
2478 ieee->dev, ieee->rate);
2482 rtllib_txb_free(txb);
2484 spin_unlock_irqrestore(&ieee->lock, flags);
2488 void rtllib_reset_queue(struct rtllib_device *ieee)
2490 unsigned long flags;
2492 spin_lock_irqsave(&ieee->lock, flags);
2493 init_mgmt_queue(ieee);
2494 if (ieee->tx_pending.txb) {
2495 rtllib_txb_free(ieee->tx_pending.txb);
2496 ieee->tx_pending.txb = NULL;
2498 ieee->queue_stop = 0;
2499 spin_unlock_irqrestore(&ieee->lock, flags);
2502 EXPORT_SYMBOL(rtllib_reset_queue);
2504 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2508 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2509 txq_trans_cond_update(netdev_get_tx_queue(ieee->dev, i));
2511 netif_tx_stop_all_queues(ieee->dev);
2514 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2516 netif_tx_wake_all_queues(ieee->dev);
2519 /* called in user context only */
2520 static void rtllib_start_master_bss(struct rtllib_device *ieee)
2524 if (ieee->current_network.ssid_len == 0) {
2525 strncpy(ieee->current_network.ssid,
2526 RTLLIB_DEFAULT_TX_ESSID,
2529 ieee->current_network.ssid_len =
2530 strlen(RTLLIB_DEFAULT_TX_ESSID);
2534 ether_addr_copy(ieee->current_network.bssid, ieee->dev->dev_addr);
2536 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2537 ieee->state = RTLLIB_LINKED;
2538 ieee->link_change(ieee->dev);
2539 notify_wx_assoc_event(ieee);
2541 if (ieee->data_hard_resume)
2542 ieee->data_hard_resume(ieee->dev);
2544 netif_carrier_on(ieee->dev);
2547 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2549 /* reset hardware status */
2551 if (ieee->data_hard_resume)
2552 ieee->data_hard_resume(ieee->dev);
2554 netif_carrier_on(ieee->dev);
2558 static void rtllib_start_ibss_wq(void *data)
2560 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2561 struct rtllib_device, start_ibss_wq);
2562 /* iwconfig mode ad-hoc will schedule this and return
2563 * on the other hand this will block further iwconfig SET
2564 * operations because of the wx_mutex hold.
2565 * Anyway some most set operations set a flag to speed-up
2566 * (abort) this wq (when syncro scanning) before sleeping
2569 if (!ieee->proto_started) {
2570 netdev_info(ieee->dev, "==========oh driver down return\n");
2573 mutex_lock(&ieee->wx_mutex);
2575 if (ieee->current_network.ssid_len == 0) {
2576 strscpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID,
2577 sizeof(ieee->current_network.ssid));
2578 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2582 ieee->state = RTLLIB_NOLINK;
2583 ieee->mode = IEEE_G;
2584 /* check if we have this cell in our network list */
2585 rtllib_softmac_check_all_nets(ieee);
2588 /* if not then the state is not linked. Maybe the user switched to
2589 * ad-hoc mode just after being in monitor mode, or just after
2590 * being very few time in managed mode (so the card have had no
2591 * time to scan all the chans..) or we have just run up the iface
2592 * after setting ad-hoc mode. So we have to give another try..
2593 * Here, in ibss mode, should be safe to do this without extra care
2594 * (in bss mode we had to make sure no-one tried to associate when
2595 * we had just checked the ieee->state and we was going to start the
2596 * scan) because in ibss mode the rtllib_new_net function, when
2597 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2598 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2599 * scan, that will stop at the first round because it sees the state
2602 if (ieee->state == RTLLIB_NOLINK)
2603 rtllib_start_scan_syncro(ieee, 0);
2605 /* the network definitively is not here.. create a new cell */
2606 if (ieee->state == RTLLIB_NOLINK) {
2607 netdev_info(ieee->dev, "creating new IBSS cell\n");
2608 ieee->current_network.channel = ieee->bss_start_channel;
2610 eth_random_addr(ieee->current_network.bssid);
2612 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2614 ieee->current_network.rates_len = 4;
2616 ieee->current_network.rates[0] =
2617 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2618 ieee->current_network.rates[1] =
2619 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2620 ieee->current_network.rates[2] =
2621 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2622 ieee->current_network.rates[3] =
2623 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2626 ieee->current_network.rates_len = 0;
2628 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2629 ieee->current_network.rates_ex_len = 8;
2631 ieee->current_network.rates_ex[0] =
2632 RTLLIB_OFDM_RATE_6MB;
2633 ieee->current_network.rates_ex[1] =
2634 RTLLIB_OFDM_RATE_9MB;
2635 ieee->current_network.rates_ex[2] =
2636 RTLLIB_OFDM_RATE_12MB;
2637 ieee->current_network.rates_ex[3] =
2638 RTLLIB_OFDM_RATE_18MB;
2639 ieee->current_network.rates_ex[4] =
2640 RTLLIB_OFDM_RATE_24MB;
2641 ieee->current_network.rates_ex[5] =
2642 RTLLIB_OFDM_RATE_36MB;
2643 ieee->current_network.rates_ex[6] =
2644 RTLLIB_OFDM_RATE_48MB;
2645 ieee->current_network.rates_ex[7] =
2646 RTLLIB_OFDM_RATE_54MB;
2650 ieee->current_network.rates_ex_len = 0;
2654 ieee->current_network.qos_data.supported = 0;
2655 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2656 ieee->current_network.mode = ieee->mode;
2657 ieee->current_network.atim_window = 0;
2658 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2661 netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2662 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2663 HTUseDefaultSetting(ieee);
2665 ieee->ht_info->bCurrentHTSupport = false;
2667 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2668 (u8 *)(&ieee->state));
2670 ieee->state = RTLLIB_LINKED;
2671 ieee->link_change(ieee->dev);
2673 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2674 if (ieee->LedControlHandler != NULL)
2675 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2677 rtllib_start_send_beacons(ieee);
2679 notify_wx_assoc_event(ieee);
2681 if (ieee->data_hard_resume)
2682 ieee->data_hard_resume(ieee->dev);
2684 netif_carrier_on(ieee->dev);
2686 mutex_unlock(&ieee->wx_mutex);
2689 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2691 schedule_delayed_work(&ieee->start_ibss_wq, msecs_to_jiffies(150));
2694 /* this is called only in user context, with wx_mutex held */
2695 static void rtllib_start_bss(struct rtllib_device *ieee)
2697 unsigned long flags;
2699 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2700 if (!ieee->global_domain)
2703 /* check if we have already found the net we
2704 * are interested in (if any).
2705 * if not (we are disassociated and we are not
2706 * in associating / authenticating phase) start the background scanning.
2708 rtllib_softmac_check_all_nets(ieee);
2710 /* ensure no-one start an associating process (thus setting
2711 * the ieee->state to rtllib_ASSOCIATING) while we
2712 * have just checked it and we are going to enable scan.
2713 * The rtllib_new_net function is always called with
2714 * lock held (from both rtllib_softmac_check_all_nets and
2715 * the rx path), so we cannot be in the middle of such function
2717 spin_lock_irqsave(&ieee->lock, flags);
2719 if (ieee->state == RTLLIB_NOLINK)
2720 rtllib_start_scan(ieee);
2721 spin_unlock_irqrestore(&ieee->lock, flags);
2724 static void rtllib_link_change_wq(void *data)
2726 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2727 struct rtllib_device, link_change_wq);
2728 ieee->link_change(ieee->dev);
2730 /* called only in userspace context */
2731 void rtllib_disassociate(struct rtllib_device *ieee)
2733 netif_carrier_off(ieee->dev);
2734 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2735 rtllib_reset_queue(ieee);
2737 if (ieee->data_hard_stop)
2738 ieee->data_hard_stop(ieee->dev);
2739 if (IS_DOT11D_ENABLE(ieee))
2741 ieee->state = RTLLIB_NOLINK;
2742 ieee->is_set_key = false;
2745 schedule_delayed_work(&ieee->link_change_wq, 0);
2747 notify_wx_assoc_event(ieee);
2750 static void rtllib_associate_retry_wq(void *data)
2752 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2753 struct rtllib_device, associate_retry_wq);
2754 unsigned long flags;
2756 mutex_lock(&ieee->wx_mutex);
2757 if (!ieee->proto_started)
2760 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2763 /* until we do not set the state to RTLLIB_NOLINK
2764 * there are no possibility to have someone else trying
2765 * to start an association procedure (we get here with
2766 * ieee->state = RTLLIB_ASSOCIATING).
2767 * When we set the state to RTLLIB_NOLINK it is possible
2768 * that the RX path run an attempt to associate, but
2769 * both rtllib_softmac_check_all_nets and the
2770 * RX path works with ieee->lock held so there are no
2771 * problems. If we are still disassociated then start a scan.
2772 * the lock here is necessary to ensure no one try to start
2773 * an association procedure when we have just checked the
2774 * state and we are going to start the scan.
2776 ieee->beinretry = true;
2777 ieee->state = RTLLIB_NOLINK;
2779 rtllib_softmac_check_all_nets(ieee);
2781 spin_lock_irqsave(&ieee->lock, flags);
2783 if (ieee->state == RTLLIB_NOLINK)
2784 rtllib_start_scan(ieee);
2785 spin_unlock_irqrestore(&ieee->lock, flags);
2787 ieee->beinretry = false;
2789 mutex_unlock(&ieee->wx_mutex);
2792 static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2794 static const u8 broadcast_addr[] = {
2795 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2797 struct sk_buff *skb;
2798 struct rtllib_probe_response *b;
2800 skb = rtllib_probe_resp(ieee, broadcast_addr);
2805 b = (struct rtllib_probe_response *)skb->data;
2806 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2812 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2814 struct sk_buff *skb;
2815 struct rtllib_probe_response *b;
2817 skb = rtllib_get_beacon_(ieee);
2821 b = (struct rtllib_probe_response *)skb->data;
2822 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2824 if (ieee->seq_ctrl[0] == 0xFFF)
2825 ieee->seq_ctrl[0] = 0;
2827 ieee->seq_ctrl[0]++;
2831 EXPORT_SYMBOL(rtllib_get_beacon);
2833 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2836 rtllib_stop_scan_syncro(ieee);
2837 mutex_lock(&ieee->wx_mutex);
2838 rtllib_stop_protocol(ieee, shutdown);
2839 mutex_unlock(&ieee->wx_mutex);
2841 EXPORT_SYMBOL(rtllib_softmac_stop_protocol);
2844 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2846 if (!ieee->proto_started)
2850 ieee->proto_started = 0;
2851 ieee->proto_stoppping = 1;
2852 ieee->rtllib_ips_leave(ieee->dev);
2855 rtllib_stop_send_beacons(ieee);
2856 del_timer_sync(&ieee->associate_timer);
2857 cancel_delayed_work_sync(&ieee->associate_retry_wq);
2858 cancel_delayed_work_sync(&ieee->start_ibss_wq);
2859 cancel_delayed_work_sync(&ieee->link_change_wq);
2860 rtllib_stop_scan(ieee);
2862 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2863 ieee->state = RTLLIB_NOLINK;
2865 if (ieee->state == RTLLIB_LINKED) {
2866 if (ieee->iw_mode == IW_MODE_INFRA)
2867 SendDisassociation(ieee, 1, WLAN_REASON_DEAUTH_LEAVING);
2868 rtllib_disassociate(ieee);
2873 ieee->proto_stoppping = 0;
2875 kfree(ieee->assocreq_ies);
2876 ieee->assocreq_ies = NULL;
2877 ieee->assocreq_ies_len = 0;
2878 kfree(ieee->assocresp_ies);
2879 ieee->assocresp_ies = NULL;
2880 ieee->assocresp_ies_len = 0;
2883 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
2885 mutex_lock(&ieee->wx_mutex);
2886 rtllib_start_protocol(ieee);
2887 mutex_unlock(&ieee->wx_mutex);
2889 EXPORT_SYMBOL(rtllib_softmac_start_protocol);
2891 void rtllib_start_protocol(struct rtllib_device *ieee)
2896 rtllib_update_active_chan_map(ieee);
2898 if (ieee->proto_started)
2901 ieee->proto_started = 1;
2903 if (ieee->current_network.channel == 0) {
2906 if (ch > MAX_CHANNEL_NUMBER)
2907 return; /* no channel found */
2908 } while (!ieee->active_channel_map[ch]);
2909 ieee->current_network.channel = ch;
2912 if (ieee->current_network.beacon_interval == 0)
2913 ieee->current_network.beacon_interval = 100;
2915 for (i = 0; i < 17; i++) {
2916 ieee->last_rxseq_num[i] = -1;
2917 ieee->last_rxfrag_num[i] = -1;
2918 ieee->last_packet_time[i] = 0;
2921 if (ieee->UpdateBeaconInterruptHandler)
2922 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
2925 /* if the user set the MAC of the ad-hoc cell and then
2926 * switch to managed mode, shall we make sure that association
2927 * attempts does not fail just because the user provide the essid
2928 * and the nic is still checking for the AP MAC ??
2930 if (ieee->iw_mode == IW_MODE_INFRA) {
2931 rtllib_start_bss(ieee);
2932 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
2933 if (ieee->UpdateBeaconInterruptHandler)
2934 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
2936 rtllib_start_ibss(ieee);
2938 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2939 rtllib_start_master_bss(ieee);
2940 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
2941 rtllib_start_monitor_mode(ieee);
2945 int rtllib_softmac_init(struct rtllib_device *ieee)
2949 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
2951 ieee->state = RTLLIB_NOLINK;
2952 for (i = 0; i < 5; i++)
2953 ieee->seq_ctrl[i] = 0;
2954 ieee->dot11d_info = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
2955 if (!ieee->dot11d_info)
2958 ieee->link_detect_info.SlotIndex = 0;
2959 ieee->link_detect_info.SlotNum = 2;
2960 ieee->link_detect_info.NumRecvBcnInPeriod = 0;
2961 ieee->link_detect_info.NumRecvDataInPeriod = 0;
2962 ieee->link_detect_info.NumTxOkInPeriod = 0;
2963 ieee->link_detect_info.NumRxOkInPeriod = 0;
2964 ieee->link_detect_info.NumRxUnicastOkInPeriod = 0;
2965 ieee->bIsAggregateFrame = false;
2967 ieee->queue_stop = 0;
2968 ieee->scanning_continue = 0;
2969 ieee->softmac_features = 0;
2972 ieee->proto_started = 0;
2973 ieee->proto_stoppping = 0;
2974 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
2976 ieee->ps = RTLLIB_PS_DISABLED;
2977 ieee->sta_sleep = LPS_IS_WAKE;
2979 ieee->reg_dot11ht_oper_rate_set[0] = 0xff;
2980 ieee->reg_dot11ht_oper_rate_set[1] = 0xff;
2981 ieee->reg_dot11ht_oper_rate_set[4] = 0x01;
2983 ieee->reg_dot11tx_ht_oper_rate_set[0] = 0xff;
2984 ieee->reg_dot11tx_ht_oper_rate_set[1] = 0xff;
2985 ieee->reg_dot11tx_ht_oper_rate_set[4] = 0x01;
2987 ieee->FirstIe_InScan = false;
2988 ieee->actscanning = false;
2989 ieee->beinretry = false;
2990 ieee->is_set_key = false;
2991 init_mgmt_queue(ieee);
2993 ieee->tx_pending.txb = NULL;
2995 timer_setup(&ieee->associate_timer, rtllib_associate_abort_cb, 0);
2997 timer_setup(&ieee->beacon_timer, rtllib_send_beacon_cb, 0);
2999 INIT_DELAYED_WORK(&ieee->link_change_wq, (void *)rtllib_link_change_wq);
3000 INIT_DELAYED_WORK(&ieee->start_ibss_wq, (void *)rtllib_start_ibss_wq);
3001 INIT_WORK(&ieee->associate_complete_wq, (void *)rtllib_associate_complete_wq);
3002 INIT_DELAYED_WORK(&ieee->associate_procedure_wq, (void *)rtllib_associate_procedure_wq);
3003 INIT_DELAYED_WORK(&ieee->softmac_scan_wq, (void *)rtllib_softmac_scan_wq);
3004 INIT_DELAYED_WORK(&ieee->associate_retry_wq, (void *)rtllib_associate_retry_wq);
3005 INIT_WORK(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq);
3007 mutex_init(&ieee->wx_mutex);
3008 mutex_init(&ieee->scan_mutex);
3009 mutex_init(&ieee->ips_mutex);
3011 spin_lock_init(&ieee->mgmt_tx_lock);
3012 spin_lock_init(&ieee->beacon_lock);
3014 INIT_WORK(&ieee->ps_task, rtllib_sta_ps);
3019 void rtllib_softmac_free(struct rtllib_device *ieee)
3021 mutex_lock(&ieee->wx_mutex);
3022 kfree(ieee->dot11d_info);
3023 ieee->dot11d_info = NULL;
3024 del_timer_sync(&ieee->associate_timer);
3026 cancel_delayed_work_sync(&ieee->associate_retry_wq);
3027 cancel_delayed_work_sync(&ieee->associate_procedure_wq);
3028 cancel_delayed_work_sync(&ieee->softmac_scan_wq);
3029 cancel_delayed_work_sync(&ieee->start_ibss_wq);
3030 cancel_delayed_work_sync(&ieee->hw_wakeup_wq);
3031 cancel_delayed_work_sync(&ieee->hw_sleep_wq);
3032 cancel_delayed_work_sync(&ieee->link_change_wq);
3033 cancel_work_sync(&ieee->associate_complete_wq);
3034 cancel_work_sync(&ieee->ips_leave_wq);
3035 cancel_work_sync(&ieee->wx_sync_scan_wq);
3036 cancel_work_sync(&ieee->ps_task);
3037 mutex_unlock(&ieee->wx_mutex);
3040 static inline struct sk_buff *
3041 rtllib_disauth_skb(struct rtllib_network *beacon,
3042 struct rtllib_device *ieee, u16 asRsn)
3044 struct sk_buff *skb;
3045 struct rtllib_disauth *disauth;
3046 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3048 skb = dev_alloc_skb(len);
3052 skb_reserve(skb, ieee->tx_headroom);
3054 disauth = skb_put(skb, sizeof(struct rtllib_disauth));
3055 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3056 disauth->header.duration_id = 0;
3058 ether_addr_copy(disauth->header.addr1, beacon->bssid);
3059 ether_addr_copy(disauth->header.addr2, ieee->dev->dev_addr);
3060 ether_addr_copy(disauth->header.addr3, beacon->bssid);
3062 disauth->reason = cpu_to_le16(asRsn);
3066 static inline struct sk_buff *
3067 rtllib_disassociate_skb(struct rtllib_network *beacon,
3068 struct rtllib_device *ieee, u16 asRsn)
3070 struct sk_buff *skb;
3071 struct rtllib_disassoc *disass;
3072 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3074 skb = dev_alloc_skb(len);
3079 skb_reserve(skb, ieee->tx_headroom);
3081 disass = skb_put(skb, sizeof(struct rtllib_disassoc));
3082 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3083 disass->header.duration_id = 0;
3085 ether_addr_copy(disass->header.addr1, beacon->bssid);
3086 ether_addr_copy(disass->header.addr2, ieee->dev->dev_addr);
3087 ether_addr_copy(disass->header.addr3, beacon->bssid);
3089 disass->reason = cpu_to_le16(asRsn);
3093 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3095 struct rtllib_network *beacon = &ieee->current_network;
3096 struct sk_buff *skb;
3099 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3101 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3104 softmac_mgmt_xmit(skb, ieee);
3107 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3109 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3110 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3111 int wpa_ie_len = ieee->wpa_ie_len;
3112 struct lib80211_crypt_data *crypt;
3115 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3116 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3117 || (ieee->host_encrypt && crypt && crypt->ops &&
3118 (strcmp(crypt->ops->name, "R-WEP") == 0));
3121 if (encrypt && (wpa_ie_len == 0)) {
3123 } else if ((wpa_ie_len != 0)) {
3124 if (((ieee->wpa_ie[0] == 0xdd) &&
3125 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3126 ((ieee->wpa_ie[0] == 0x30) &&
3127 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3128 return SEC_ALG_CCMP;
3130 return SEC_ALG_TKIP;
3132 return SEC_ALG_NONE;
3136 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3140 bool bFilterOutNonAssociatedBSSID = false;
3142 rtllib->state = RTLLIB_NOLINK;
3144 for (i = 0; i < 6; i++)
3145 rtllib->current_network.bssid[i] = 0x55;
3147 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3148 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3149 rtllib->current_network.bssid);
3150 OpMode = RT_OP_MODE_NO_LINK;
3151 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3152 rtllib_stop_send_beacons(rtllib);
3154 bFilterOutNonAssociatedBSSID = false;
3155 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3156 (u8 *)(&bFilterOutNonAssociatedBSSID));
3157 notify_wx_assoc_event(rtllib);
3161 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib,
3162 u8 *asSta, u8 asRsn)
3167 RemovePeerTS(rtllib, asSta);
3169 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3170 rtllib->state = RTLLIB_NOLINK;
3172 for (i = 0; i < 6; i++)
3173 rtllib->current_network.bssid[i] = 0x22;
3174 OpMode = RT_OP_MODE_NO_LINK;
3175 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3176 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3178 rtllib_disassociate(rtllib);
3180 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3181 rtllib->current_network.bssid);
3188 rtllib_MgntDisconnectAP(
3189 struct rtllib_device *rtllib,
3193 bool bFilterOutNonAssociatedBSSID = false;
3195 bFilterOutNonAssociatedBSSID = false;
3196 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3197 (u8 *)(&bFilterOutNonAssociatedBSSID));
3198 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3201 rtllib->state = RTLLIB_NOLINK;
3204 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3206 if (rtllib->ps != RTLLIB_PS_DISABLED)
3207 rtllib->sta_wake_up(rtllib->dev);
3209 if (rtllib->state == RTLLIB_LINKED) {
3210 if (rtllib->iw_mode == IW_MODE_ADHOC)
3211 rtllib_MgntDisconnectIBSS(rtllib);
3212 if (rtllib->iw_mode == IW_MODE_INFRA)
3213 rtllib_MgntDisconnectAP(rtllib, asRsn);
3219 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3221 void notify_wx_assoc_event(struct rtllib_device *ieee)
3223 union iwreq_data wrqu;
3225 if (ieee->cannot_notify)
3228 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3229 if (ieee->state == RTLLIB_LINKED)
3230 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3234 netdev_info(ieee->dev, "%s(): Tell user space disconnected\n",
3236 eth_zero_addr(wrqu.ap_addr.sa_data);
3238 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3240 EXPORT_SYMBOL(notify_wx_assoc_event);