1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
4 * Mostly extracted from the rtl8180-sa2400 driver for the
5 * in-kernel generic ieee802.11 stack.
7 * Few lines might be stolen from other part of the rtllib
8 * stack. Copyright who own it's copyright
10 * WPA code stolen from the ipw2200 driver.
11 * Copyright who own it's copyright.
13 * released under the GPL
19 #include <linux/random.h>
20 #include <linux/delay.h>
21 #include <linux/uaccess.h>
22 #include <linux/etherdevice.h>
25 short rtllib_is_54g(struct rtllib_network *net)
27 return (net->rates_ex_len > 0) || (net->rates_len > 4);
30 short rtllib_is_shortslot(const struct rtllib_network *net)
32 return net->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME;
35 /* returns the total length needed for placing the RATE MFIE
36 * tag and the EXTENDED RATE MFIE tag if needed.
37 * It encludes two bytes per tag for the tag itself and its len
39 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
41 unsigned int rate_len = 0;
43 if (ieee->modulation & RTLLIB_CCK_MODULATION)
44 rate_len = RTLLIB_CCK_RATE_LEN + 2;
46 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
48 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
53 /* place the MFIE rate, tag to the memory (double) pointed.
54 * Then it updates the pointer so that
55 * it points after the new MFIE tag added.
57 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
61 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
62 *tag++ = MFIE_TYPE_RATES;
64 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
65 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
66 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
67 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
70 /* We may add an option for custom rates that specific HW
75 static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p)
79 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
80 *tag++ = MFIE_TYPE_RATES_EX;
82 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
83 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
84 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
85 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
86 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
87 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
88 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
89 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;
91 /* We may add an option for custom rates that specific HW might
96 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
100 *tag++ = MFIE_TYPE_GENERIC;
112 void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
116 *tag++ = MFIE_TYPE_GENERIC;
127 netdev_alert(ieee->dev, "This is enable turbo mode IE process\n");
130 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
134 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
137 * if the queue is full but we have newer frames then
138 * just overwrites the oldest.
140 * if (nh == ieee->mgmt_queue_tail)
143 ieee->mgmt_queue_head = nh;
144 ieee->mgmt_queue_ring[nh] = skb;
148 static struct sk_buff *dequeue_mgmt(struct rtllib_device *ieee)
152 if (ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
155 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
157 ieee->mgmt_queue_tail =
158 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
163 static void init_mgmt_queue(struct rtllib_device *ieee)
165 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
170 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
177 for (i = 0; i < ieee->current_network.rates_len; i++) {
178 BasicRate = ieee->current_network.rates[i]&0x7F;
179 if (!rtllib_is_cck_rate(BasicRate)) {
180 if (QueryRate == 0) {
181 QueryRate = BasicRate;
183 if (BasicRate < QueryRate)
184 QueryRate = BasicRate;
189 if (QueryRate == 0) {
191 netdev_info(ieee->dev, "No BasicRate found!!\n");
196 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
198 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
201 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
204 rate = ieee->basic_rate & 0x7f;
207 if (ieee->mode == IEEE_A ||
208 ieee->mode == IEEE_N_5G ||
209 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
218 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
221 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
222 struct rtllib_hdr_3addr *header =
223 (struct rtllib_hdr_3addr *) skb->data;
225 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
227 spin_lock_irqsave(&ieee->lock, flags);
229 /* called with 2nd param 0, no mgmt lock required */
230 rtllib_sta_wakeup(ieee, 0);
232 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
233 tcb_desc->queue_index = BEACON_QUEUE;
235 tcb_desc->queue_index = MGNT_QUEUE;
237 if (ieee->disable_mgnt_queue)
238 tcb_desc->queue_index = HIGH_QUEUE;
240 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
241 tcb_desc->RATRIndex = 7;
242 tcb_desc->bTxDisableRateFallBack = 1;
243 tcb_desc->bTxUseDriverAssingedRate = 1;
245 if (ieee->queue_stop) {
246 enqueue_mgmt(ieee, skb);
248 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
250 if (ieee->seq_ctrl[0] == 0xFFF)
251 ieee->seq_ctrl[0] = 0;
255 /* avoid watchdog triggers */
256 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
260 spin_unlock_irqrestore(&ieee->lock, flags);
262 spin_unlock_irqrestore(&ieee->lock, flags);
263 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
265 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
267 if (ieee->seq_ctrl[0] == 0xFFF)
268 ieee->seq_ctrl[0] = 0;
272 /* check whether the managed packet queued greater than 5 */
273 if (!ieee->check_nic_enough_desc(ieee->dev, tcb_desc->queue_index) ||
274 (skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) != 0) ||
275 (ieee->queue_stop)) {
276 /* insert the skb packet to the management queue */
277 /* as for the completion function, it does not need
278 * to check it any more.
280 netdev_info(ieee->dev,
281 "%s():insert to waitqueue, queue_index:%d!\n",
282 __func__, tcb_desc->queue_index);
283 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
286 ieee->softmac_hard_start_xmit(skb, ieee->dev);
288 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
292 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb,
293 struct rtllib_device *ieee)
295 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
296 struct rtllib_hdr_3addr *header =
297 (struct rtllib_hdr_3addr *) skb->data;
299 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
301 fc = le16_to_cpu(header->frame_ctl);
302 type = WLAN_FC_GET_TYPE(fc);
303 stype = WLAN_FC_GET_STYPE(fc);
306 if (stype != RTLLIB_STYPE_PSPOLL)
307 tcb_desc->queue_index = MGNT_QUEUE;
309 tcb_desc->queue_index = HIGH_QUEUE;
311 if (ieee->disable_mgnt_queue)
312 tcb_desc->queue_index = HIGH_QUEUE;
315 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
316 tcb_desc->RATRIndex = 7;
317 tcb_desc->bTxDisableRateFallBack = 1;
318 tcb_desc->bTxUseDriverAssingedRate = 1;
320 if (type != RTLLIB_FTYPE_CTL) {
321 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
323 if (ieee->seq_ctrl[0] == 0xFFF)
324 ieee->seq_ctrl[0] = 0;
329 /* avoid watchdog triggers */
330 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
334 if (type != RTLLIB_FTYPE_CTL) {
335 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
337 if (ieee->seq_ctrl[0] == 0xFFF)
338 ieee->seq_ctrl[0] = 0;
342 ieee->softmac_hard_start_xmit(skb, ieee->dev);
347 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
349 unsigned int len, rate_len;
352 struct rtllib_probe_request *req;
354 len = ieee->current_network.ssid_len;
356 rate_len = rtllib_MFIE_rate_len(ieee);
358 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
359 2 + len + rate_len + ieee->tx_headroom);
364 skb_reserve(skb, ieee->tx_headroom);
366 req = (struct rtllib_probe_request *) skb_put(skb,
367 sizeof(struct rtllib_probe_request));
368 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
369 req->header.duration_id = 0;
371 memset(req->header.addr1, 0xff, ETH_ALEN);
372 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
373 memset(req->header.addr3, 0xff, ETH_ALEN);
375 tag = (u8 *) skb_put(skb, len + 2 + rate_len);
377 *tag++ = MFIE_TYPE_SSID;
379 memcpy(tag, ieee->current_network.ssid, len);
382 rtllib_MFIE_Brate(ieee, &tag);
383 rtllib_MFIE_Grate(ieee, &tag);
388 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
390 static void rtllib_send_beacon(struct rtllib_device *ieee)
396 skb = rtllib_get_beacon_(ieee);
399 softmac_mgmt_xmit(skb, ieee);
400 ieee->softmac_stats.tx_beacons++;
403 if (ieee->beacon_txing && ieee->ieee_up)
404 mod_timer(&ieee->beacon_timer, jiffies +
405 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
409 static void rtllib_send_beacon_cb(unsigned long _ieee)
411 struct rtllib_device *ieee =
412 (struct rtllib_device *) _ieee;
415 spin_lock_irqsave(&ieee->beacon_lock, flags);
416 rtllib_send_beacon(ieee);
417 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
422 * Enable network monitor mode, all rx packets will be received.
424 void rtllib_EnableNetMonitorMode(struct net_device *dev,
427 struct rtllib_device *ieee = netdev_priv_rsl(dev);
429 netdev_info(dev, "========>Enter Monitor Mode\n");
431 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
437 * Disable network network monitor mode, only packets destinated to
438 * us will be received.
440 void rtllib_DisableNetMonitorMode(struct net_device *dev,
443 struct rtllib_device *ieee = netdev_priv_rsl(dev);
445 netdev_info(dev, "========>Exit Monitor Mode\n");
447 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
453 * This enables the specialized promiscuous mode required by Intel.
454 * In this mode, Intel intends to hear traffics from/to other STAs in the
455 * same BSS. Therefore we don't have to disable checking BSSID and we only need
456 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
457 * packets from other STA.
459 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
462 bool bFilterOutNonAssociatedBSSID = false;
464 struct rtllib_device *ieee = netdev_priv_rsl(dev);
466 netdev_info(dev, "========>Enter Intel Promiscuous Mode\n");
468 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
469 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
470 (u8 *)&bFilterOutNonAssociatedBSSID);
472 ieee->bNetPromiscuousMode = true;
474 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
479 * This disables the specialized promiscuous mode required by Intel.
480 * See MgntEnableIntelPromiscuousMode for detail.
482 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
485 bool bFilterOutNonAssociatedBSSID = true;
487 struct rtllib_device *ieee = netdev_priv_rsl(dev);
489 netdev_info(dev, "========>Exit Intel Promiscuous Mode\n");
491 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
492 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
493 (u8 *)&bFilterOutNonAssociatedBSSID);
495 ieee->bNetPromiscuousMode = false;
497 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
499 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
503 skb = rtllib_probe_req(ieee);
505 softmac_mgmt_xmit(skb, ieee);
506 ieee->softmac_stats.tx_probe_rq++;
511 void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
513 if (ieee->active_scan && (ieee->softmac_features &
514 IEEE_SOFTMAC_PROBERQ)) {
515 rtllib_send_probe(ieee, 0);
516 rtllib_send_probe(ieee, 0);
520 static void rtllib_softmac_hint11d_wq(void *data)
524 void rtllib_update_active_chan_map(struct rtllib_device *ieee)
526 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
527 MAX_CHANNEL_NUMBER+1);
530 /* this performs syncro scan blocking the caller until all channels
531 * in the allowed channel map has been checked.
533 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
535 union iwreq_data wrqu;
538 rtllib_update_active_chan_map(ieee);
540 ieee->be_scan_inprogress = true;
542 down(&ieee->scan_sem);
547 if (ch > MAX_CHANNEL_NUMBER)
548 goto out; /* scan completed */
549 } while (!ieee->active_channel_map[ch]);
551 /* this function can be called in two situations
552 * 1- We have switched to ad-hoc mode and we are
553 * performing a complete syncro scan before conclude
554 * there are no interesting cell and to create a
555 * new one. In this case the link state is
556 * RTLLIB_NOLINK until we found an interesting cell.
557 * If so the ieee8021_new_net, called by the RX path
558 * will set the state to RTLLIB_LINKED, so we stop
560 * 2- We are linked and the root uses run iwlist scan.
561 * So we switch to RTLLIB_LINKED_SCANNING to remember
562 * that we are still logically linked (not interested in
563 * new network events, despite for updating the net list,
564 * but we are temporarly 'unlinked' as the driver shall
565 * not filter RX frames and the channel is changing.
566 * So the only situation in which are interested is to check
567 * if the state become LINKED because of the #1 situation
570 if (ieee->state == RTLLIB_LINKED)
572 if (ieee->sync_scan_hurryup) {
573 netdev_info(ieee->dev,
574 "============>sync_scan_hurryup out\n");
578 ieee->set_chan(ieee->dev, ch);
579 if (ieee->active_channel_map[ch] == 1)
580 rtllib_send_probe_requests(ieee, 0);
582 /* this prevent excessive time wait when we
583 * need to wait for a syncro scan to end..
585 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
588 ieee->actscanning = false;
589 ieee->sync_scan_hurryup = 0;
591 if (ieee->state >= RTLLIB_LINKED) {
592 if (IS_DOT11D_ENABLE(ieee))
593 DOT11D_ScanComplete(ieee);
597 ieee->be_scan_inprogress = false;
599 memset(&wrqu, 0, sizeof(wrqu));
600 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
603 static void rtllib_softmac_scan_wq(void *data)
605 struct rtllib_device *ieee = container_of_dwork_rsl(data,
606 struct rtllib_device, softmac_scan_wq);
607 u8 last_channel = ieee->current_network.channel;
609 rtllib_update_active_chan_map(ieee);
613 if (rtllib_act_scanning(ieee, true))
616 down(&ieee->scan_sem);
618 if (ieee->eRFPowerState == eRfOff) {
619 netdev_info(ieee->dev,
620 "======>%s():rf state is eRfOff, return\n",
626 ieee->current_network.channel =
627 (ieee->current_network.channel + 1) %
629 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
630 if (!ieee->active_channel_map[ieee->current_network.channel])
631 ieee->current_network.channel = 6;
632 goto out; /* no good chans */
634 } while (!ieee->active_channel_map[ieee->current_network.channel]);
636 if (ieee->scanning_continue == 0)
639 ieee->set_chan(ieee->dev, ieee->current_network.channel);
641 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
642 rtllib_send_probe_requests(ieee, 0);
644 queue_delayed_work_rsl(ieee->wq, &ieee->softmac_scan_wq,
645 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
651 if (IS_DOT11D_ENABLE(ieee))
652 DOT11D_ScanComplete(ieee);
653 ieee->current_network.channel = last_channel;
656 ieee->actscanning = false;
657 ieee->scan_watch_dog = 0;
658 ieee->scanning_continue = 0;
664 static void rtllib_beacons_start(struct rtllib_device *ieee)
668 spin_lock_irqsave(&ieee->beacon_lock, flags);
670 ieee->beacon_txing = 1;
671 rtllib_send_beacon(ieee);
673 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
676 static void rtllib_beacons_stop(struct rtllib_device *ieee)
680 spin_lock_irqsave(&ieee->beacon_lock, flags);
682 ieee->beacon_txing = 0;
683 del_timer_sync(&ieee->beacon_timer);
685 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
690 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
692 if (ieee->stop_send_beacons)
693 ieee->stop_send_beacons(ieee->dev);
694 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
695 rtllib_beacons_stop(ieee);
697 EXPORT_SYMBOL(rtllib_stop_send_beacons);
700 void rtllib_start_send_beacons(struct rtllib_device *ieee)
702 if (ieee->start_send_beacons)
703 ieee->start_send_beacons(ieee->dev);
704 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
705 rtllib_beacons_start(ieee);
707 EXPORT_SYMBOL(rtllib_start_send_beacons);
710 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
712 down(&ieee->scan_sem);
713 ieee->scan_watch_dog = 0;
714 if (ieee->scanning_continue == 1) {
715 ieee->scanning_continue = 0;
716 ieee->actscanning = false;
718 cancel_delayed_work(&ieee->softmac_scan_wq);
724 void rtllib_stop_scan(struct rtllib_device *ieee)
726 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
727 rtllib_softmac_stop_scan(ieee);
729 if (ieee->rtllib_stop_hw_scan)
730 ieee->rtllib_stop_hw_scan(ieee->dev);
733 EXPORT_SYMBOL(rtllib_stop_scan);
735 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
737 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
738 ieee->sync_scan_hurryup = 1;
740 if (ieee->rtllib_stop_hw_scan)
741 ieee->rtllib_stop_hw_scan(ieee->dev);
744 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
746 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
748 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
750 return ieee->be_scan_inprogress;
752 return ieee->actscanning || ieee->be_scan_inprogress;
754 return test_bit(STATUS_SCANNING, &ieee->status);
757 EXPORT_SYMBOL(rtllib_act_scanning);
759 /* called with ieee->lock held */
760 static void rtllib_start_scan(struct rtllib_device *ieee)
762 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
763 if (ieee->rtllib_ips_leave_wq != NULL)
764 ieee->rtllib_ips_leave_wq(ieee->dev);
766 if (IS_DOT11D_ENABLE(ieee)) {
767 if (IS_COUNTRY_IE_VALID(ieee))
768 RESET_CIE_WATCHDOG(ieee);
770 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
771 if (ieee->scanning_continue == 0) {
772 ieee->actscanning = true;
773 ieee->scanning_continue = 1;
774 queue_delayed_work_rsl(ieee->wq,
775 &ieee->softmac_scan_wq, 0);
778 if (ieee->rtllib_start_hw_scan)
779 ieee->rtllib_start_hw_scan(ieee->dev);
783 /* called with wx_sem held */
784 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
786 if (IS_DOT11D_ENABLE(ieee)) {
787 if (IS_COUNTRY_IE_VALID(ieee))
788 RESET_CIE_WATCHDOG(ieee);
790 ieee->sync_scan_hurryup = 0;
791 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
792 rtllib_softmac_scan_syncro(ieee, is_mesh);
794 if (ieee->rtllib_start_hw_scan)
795 ieee->rtllib_start_hw_scan(ieee->dev);
798 EXPORT_SYMBOL(rtllib_start_scan_syncro);
800 inline struct sk_buff *rtllib_authentication_req(struct rtllib_network *beacon,
801 struct rtllib_device *ieee, int challengelen, u8 *daddr)
804 struct rtllib_authentication *auth;
807 len = sizeof(struct rtllib_authentication) + challengelen +
808 ieee->tx_headroom + 4;
809 skb = dev_alloc_skb(len);
814 skb_reserve(skb, ieee->tx_headroom);
816 auth = (struct rtllib_authentication *)
817 skb_put(skb, sizeof(struct rtllib_authentication));
819 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
821 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
823 auth->header.duration_id = cpu_to_le16(0x013a);
824 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
825 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
826 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
827 if (ieee->auth_mode == 0)
828 auth->algorithm = WLAN_AUTH_OPEN;
829 else if (ieee->auth_mode == 1)
830 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
831 else if (ieee->auth_mode == 2)
832 auth->algorithm = WLAN_AUTH_OPEN;
833 auth->transaction = cpu_to_le16(ieee->associate_seq);
834 ieee->associate_seq++;
836 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
841 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, u8 *dest)
845 struct rtllib_probe_response *beacon_buf;
846 struct sk_buff *skb = NULL;
848 int atim_len, erp_len;
849 struct lib80211_crypt_data *crypt;
851 char *ssid = ieee->current_network.ssid;
852 int ssid_len = ieee->current_network.ssid_len;
853 int rate_len = ieee->current_network.rates_len+2;
854 int rate_ex_len = ieee->current_network.rates_ex_len;
855 int wpa_ie_len = ieee->wpa_ie_len;
856 u8 erpinfo_content = 0;
858 u8 *tmp_ht_cap_buf = NULL;
859 u8 tmp_ht_cap_len = 0;
860 u8 *tmp_ht_info_buf = NULL;
861 u8 tmp_ht_info_len = 0;
862 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
863 u8 *tmp_generic_ie_buf = NULL;
864 u8 tmp_generic_ie_len = 0;
869 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
874 if ((ieee->current_network.mode == IEEE_G) ||
875 (ieee->current_network.mode == IEEE_N_24G &&
876 ieee->pHTInfo->bCurSuppCCK)) {
879 if (ieee->current_network.buseprotection)
880 erpinfo_content |= ERP_UseProtection;
884 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
885 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
886 ((0 == strcmp(crypt->ops->name, "R-WEP") || wpa_ie_len));
887 if (ieee->pHTInfo->bCurrentHTSupport) {
888 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
889 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
890 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
891 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
892 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
893 &tmp_ht_cap_len, encrypt, false);
894 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
897 if (pHTInfo->bRegRT2RTAggregation) {
898 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
900 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
901 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
902 &tmp_generic_ie_len);
906 beacon_size = sizeof(struct rtllib_probe_response)+2+
907 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
908 + wpa_ie_len + ieee->tx_headroom;
909 skb = dev_alloc_skb(beacon_size);
913 skb_reserve(skb, ieee->tx_headroom);
915 beacon_buf = (struct rtllib_probe_response *) skb_put(skb,
916 (beacon_size - ieee->tx_headroom));
917 memcpy(beacon_buf->header.addr1, dest, ETH_ALEN);
918 memcpy(beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
919 memcpy(beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
921 beacon_buf->header.duration_id = 0;
922 beacon_buf->beacon_interval =
923 cpu_to_le16(ieee->current_network.beacon_interval);
924 beacon_buf->capability =
925 cpu_to_le16(ieee->current_network.capability &
926 WLAN_CAPABILITY_IBSS);
927 beacon_buf->capability |=
928 cpu_to_le16(ieee->current_network.capability &
929 WLAN_CAPABILITY_SHORT_PREAMBLE);
931 if (ieee->short_slot && (ieee->current_network.capability &
932 WLAN_CAPABILITY_SHORT_SLOT_TIME))
933 beacon_buf->capability |=
934 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
936 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
938 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
941 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
942 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
943 beacon_buf->info_element[0].len = ssid_len;
945 tag = (u8 *) beacon_buf->info_element[0].data;
947 memcpy(tag, ssid, ssid_len);
951 *(tag++) = MFIE_TYPE_RATES;
952 *(tag++) = rate_len-2;
953 memcpy(tag, ieee->current_network.rates, rate_len-2);
956 *(tag++) = MFIE_TYPE_DS_SET;
958 *(tag++) = ieee->current_network.channel;
962 *(tag++) = MFIE_TYPE_IBSS_SET;
964 val16 = ieee->current_network.atim_window;
965 memcpy((u8 *)tag, (u8 *)&val16, 2);
970 *(tag++) = MFIE_TYPE_ERP;
972 *(tag++) = erpinfo_content;
975 *(tag++) = MFIE_TYPE_RATES_EX;
976 *(tag++) = rate_ex_len-2;
977 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
978 tag += rate_ex_len-2;
982 if (ieee->iw_mode == IW_MODE_ADHOC)
983 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
984 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
985 tag += ieee->wpa_ie_len;
990 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
995 struct lib80211_crypt_data *crypt;
996 struct rtllib_assoc_response_frame *assoc;
999 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
1000 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
1003 skb = dev_alloc_skb(len);
1008 skb_reserve(skb, ieee->tx_headroom);
1010 assoc = (struct rtllib_assoc_response_frame *)
1011 skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
1013 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
1014 memcpy(assoc->header.addr1, dest, ETH_ALEN);
1015 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1016 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1017 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1018 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
1021 if (ieee->short_slot)
1022 assoc->capability |=
1023 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1025 if (ieee->host_encrypt)
1026 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1030 encrypt = (crypt && crypt->ops);
1033 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1036 assoc->aid = cpu_to_le16(ieee->assoc_id);
1037 if (ieee->assoc_id == 0x2007)
1042 tag = (u8 *) skb_put(skb, rate_len);
1043 rtllib_MFIE_Brate(ieee, &tag);
1044 rtllib_MFIE_Grate(ieee, &tag);
1049 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1052 struct sk_buff *skb = NULL;
1053 struct rtllib_authentication *auth;
1054 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1056 skb = dev_alloc_skb(len);
1060 skb->len = sizeof(struct rtllib_authentication);
1062 skb_reserve(skb, ieee->tx_headroom);
1064 auth = (struct rtllib_authentication *)
1065 skb_put(skb, sizeof(struct rtllib_authentication));
1067 auth->status = cpu_to_le16(status);
1068 auth->transaction = cpu_to_le16(2);
1069 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1071 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1072 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1073 memcpy(auth->header.addr1, dest, ETH_ALEN);
1074 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1080 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1082 struct sk_buff *skb;
1083 struct rtllib_hdr_3addr *hdr;
1085 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1089 skb_reserve(skb, ieee->tx_headroom);
1091 hdr = (struct rtllib_hdr_3addr *)skb_put(skb,
1092 sizeof(struct rtllib_hdr_3addr));
1094 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1095 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1096 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1098 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1099 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1100 (pwr ? RTLLIB_FCTL_PM : 0));
1107 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1109 struct sk_buff *skb;
1110 struct rtllib_pspoll_hdr *hdr;
1112 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1116 skb_reserve(skb, ieee->tx_headroom);
1118 hdr = (struct rtllib_pspoll_hdr *)skb_put(skb,
1119 sizeof(struct rtllib_pspoll_hdr));
1121 memcpy(hdr->bssid, ieee->current_network.bssid, ETH_ALEN);
1122 memcpy(hdr->ta, ieee->dev->dev_addr, ETH_ALEN);
1124 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1125 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1132 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1134 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1137 softmac_mgmt_xmit(buf, ieee);
1141 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1143 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1146 softmac_mgmt_xmit(buf, ieee);
1150 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1152 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1155 softmac_mgmt_xmit(buf, ieee);
1159 inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1164 if ((ieee->PMKIDList[i].bUsed) &&
1165 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1168 } while (i < NUM_PMKID_CACHE);
1170 if (i == NUM_PMKID_CACHE)
1175 inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1176 struct rtllib_device *ieee)
1178 struct sk_buff *skb;
1179 struct rtllib_assoc_request_frame *hdr;
1182 u8 *ht_cap_buf = NULL;
1184 u8 *realtek_ie_buf = NULL;
1185 u8 realtek_ie_len = 0;
1186 int wpa_ie_len = ieee->wpa_ie_len;
1187 int wps_ie_len = ieee->wps_ie_len;
1188 unsigned int ckip_ie_len = 0;
1189 unsigned int ccxrm_ie_len = 0;
1190 unsigned int cxvernum_ie_len = 0;
1191 struct lib80211_crypt_data *crypt;
1195 unsigned int rate_len = (beacon->rates_len ?
1196 (beacon->rates_len + 2) : 0) +
1197 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1200 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1201 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1205 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1207 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1208 ((0 == strcmp(crypt->ops->name, "R-WEP") ||
1213 if ((ieee->rtllib_ap_sec_type &&
1214 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1215 ieee->bForcedBgMode) {
1216 ieee->pHTInfo->bEnableHT = 0;
1217 ieee->mode = WIRELESS_MODE_G;
1220 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1221 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1222 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1223 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1225 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1226 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1228 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1229 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1234 if (beacon->bCkipSupported)
1236 if (beacon->bCcxRmEnable)
1238 if (beacon->BssCcxVerNumber >= 2)
1239 cxvernum_ie_len = 5+2;
1241 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1242 if (PMKCacheIdx >= 0) {
1244 netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n",
1247 len = sizeof(struct rtllib_assoc_request_frame) + 2
1259 + ieee->tx_headroom;
1261 skb = dev_alloc_skb(len);
1266 skb_reserve(skb, ieee->tx_headroom);
1268 hdr = (struct rtllib_assoc_request_frame *)
1269 skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1272 hdr->header.frame_ctl = RTLLIB_STYPE_ASSOC_REQ;
1273 hdr->header.duration_id = cpu_to_le16(37);
1274 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1275 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1276 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1278 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);
1280 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1281 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1282 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1284 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1285 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1287 if (ieee->short_slot &&
1288 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1289 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1292 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1294 hdr->info_element[0].id = MFIE_TYPE_SSID;
1296 hdr->info_element[0].len = beacon->ssid_len;
1297 tag = skb_put(skb, beacon->ssid_len);
1298 memcpy(tag, beacon->ssid, beacon->ssid_len);
1300 tag = skb_put(skb, rate_len);
1302 if (beacon->rates_len) {
1303 *tag++ = MFIE_TYPE_RATES;
1304 *tag++ = beacon->rates_len;
1305 for (i = 0; i < beacon->rates_len; i++)
1306 *tag++ = beacon->rates[i];
1309 if (beacon->rates_ex_len) {
1310 *tag++ = MFIE_TYPE_RATES_EX;
1311 *tag++ = beacon->rates_ex_len;
1312 for (i = 0; i < beacon->rates_ex_len; i++)
1313 *tag++ = beacon->rates_ex[i];
1316 if (beacon->bCkipSupported) {
1317 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1318 u8 CcxAironetBuf[30];
1319 struct octet_string osCcxAironetIE;
1321 memset(CcxAironetBuf, 0, 30);
1322 osCcxAironetIE.Octet = CcxAironetBuf;
1323 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1324 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1325 sizeof(AironetIeOui));
1327 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1328 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1329 tag = skb_put(skb, ckip_ie_len);
1330 *tag++ = MFIE_TYPE_AIRONET;
1331 *tag++ = osCcxAironetIE.Length;
1332 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1333 tag += osCcxAironetIE.Length;
1336 if (beacon->bCcxRmEnable) {
1337 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1339 struct octet_string osCcxRmCap;
1341 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1342 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1343 tag = skb_put(skb, ccxrm_ie_len);
1344 *tag++ = MFIE_TYPE_GENERIC;
1345 *tag++ = osCcxRmCap.Length;
1346 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1347 tag += osCcxRmCap.Length;
1350 if (beacon->BssCcxVerNumber >= 2) {
1351 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1352 struct octet_string osCcxVerNum;
1354 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1355 osCcxVerNum.Octet = CcxVerNumBuf;
1356 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1357 tag = skb_put(skb, cxvernum_ie_len);
1358 *tag++ = MFIE_TYPE_GENERIC;
1359 *tag++ = osCcxVerNum.Length;
1360 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1361 tag += osCcxVerNum.Length;
1363 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1364 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1365 tag = skb_put(skb, ht_cap_len);
1366 *tag++ = MFIE_TYPE_HT_CAP;
1367 *tag++ = ht_cap_len - 2;
1368 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1369 tag += ht_cap_len - 2;
1374 tag = skb_put(skb, ieee->wpa_ie_len);
1375 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1377 if (PMKCacheIdx >= 0) {
1378 tag = skb_put(skb, 18);
1381 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1386 tag = skb_put(skb, wmm_info_len);
1387 rtllib_WMM_Info(ieee, &tag);
1390 if (wps_ie_len && ieee->wps_ie) {
1391 tag = skb_put(skb, wps_ie_len);
1392 memcpy(tag, ieee->wps_ie, wps_ie_len);
1395 tag = skb_put(skb, turbo_info_len);
1397 rtllib_TURBO_Info(ieee, &tag);
1399 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1400 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1401 tag = skb_put(skb, ht_cap_len);
1402 *tag++ = MFIE_TYPE_GENERIC;
1403 *tag++ = ht_cap_len - 2;
1404 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1405 tag += ht_cap_len - 2;
1408 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1409 tag = skb_put(skb, realtek_ie_len);
1410 *tag++ = MFIE_TYPE_GENERIC;
1411 *tag++ = realtek_ie_len - 2;
1412 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1416 kfree(ieee->assocreq_ies);
1417 ieee->assocreq_ies = NULL;
1418 ies = &(hdr->info_element[0].id);
1419 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1420 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1421 if (ieee->assocreq_ies)
1422 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1424 netdev_info(ieee->dev,
1425 "%s()Warning: can't alloc memory for assocreq_ies\n",
1427 ieee->assocreq_ies_len = 0;
1432 void rtllib_associate_abort(struct rtllib_device *ieee)
1434 unsigned long flags;
1436 spin_lock_irqsave(&ieee->lock, flags);
1438 ieee->associate_seq++;
1440 /* don't scan, and avoid to have the RX path possibily
1441 * try again to associate. Even do not react to AUTH or
1442 * ASSOC response. Just wait for the retry wq to be scheduled.
1443 * Here we will check if there are good nets to associate
1444 * with, so we retry or just get back to NO_LINK and scanning
1446 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1447 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1448 ieee->softmac_stats.no_auth_rs++;
1450 RTLLIB_DEBUG_MGMT("Association failed\n");
1451 ieee->softmac_stats.no_ass_rs++;
1454 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1456 queue_delayed_work_rsl(ieee->wq, &ieee->associate_retry_wq,
1457 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1459 spin_unlock_irqrestore(&ieee->lock, flags);
1462 static void rtllib_associate_abort_cb(unsigned long dev)
1464 rtllib_associate_abort((struct rtllib_device *) dev);
1467 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr)
1469 struct rtllib_network *beacon = &ieee->current_network;
1470 struct sk_buff *skb;
1472 RTLLIB_DEBUG_MGMT("Stopping scan\n");
1474 ieee->softmac_stats.tx_auth_rq++;
1476 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1479 rtllib_associate_abort(ieee);
1481 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING;
1482 RTLLIB_DEBUG_MGMT("Sending authentication request\n");
1483 softmac_mgmt_xmit(skb, ieee);
1484 if (!timer_pending(&ieee->associate_timer)) {
1485 ieee->associate_timer.expires = jiffies + (HZ / 2);
1486 add_timer(&ieee->associate_timer);
1491 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge, int chlen)
1494 struct sk_buff *skb;
1495 struct rtllib_network *beacon = &ieee->current_network;
1497 ieee->associate_seq++;
1498 ieee->softmac_stats.tx_auth_rq++;
1500 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1503 rtllib_associate_abort(ieee);
1505 c = skb_put(skb, chlen+2);
1506 *(c++) = MFIE_TYPE_CHALLENGE;
1508 memcpy(c, challenge, chlen);
1510 RTLLIB_DEBUG_MGMT("Sending authentication challenge response\n");
1512 rtllib_encrypt_fragment(ieee, skb,
1513 sizeof(struct rtllib_hdr_3addr));
1515 softmac_mgmt_xmit(skb, ieee);
1516 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1521 static void rtllib_associate_step2(struct rtllib_device *ieee)
1523 struct sk_buff *skb;
1524 struct rtllib_network *beacon = &ieee->current_network;
1526 del_timer_sync(&ieee->associate_timer);
1528 RTLLIB_DEBUG_MGMT("Sending association request\n");
1530 ieee->softmac_stats.tx_ass_rq++;
1531 skb = rtllib_association_req(beacon, ieee);
1533 rtllib_associate_abort(ieee);
1535 softmac_mgmt_xmit(skb, ieee);
1536 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1541 static void rtllib_associate_complete_wq(void *data)
1543 struct rtllib_device *ieee = (struct rtllib_device *)
1544 container_of_work_rsl(data,
1545 struct rtllib_device,
1546 associate_complete_wq);
1547 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1548 (&(ieee->PowerSaveControl));
1549 netdev_info(ieee->dev, "Associated successfully\n");
1550 if (!ieee->is_silent_reset) {
1551 netdev_info(ieee->dev, "normal associate\n");
1552 notify_wx_assoc_event(ieee);
1555 netif_carrier_on(ieee->dev);
1556 ieee->is_roaming = false;
1557 if (rtllib_is_54g(&ieee->current_network) &&
1558 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1560 netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate);
1563 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1564 netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate);
1566 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1567 netdev_info(ieee->dev, "Successfully associated, ht enabled\n");
1570 netdev_info(ieee->dev,
1571 "Successfully associated, ht not enabled(%d, %d)\n",
1572 ieee->pHTInfo->bCurrentHTSupport,
1573 ieee->pHTInfo->bEnableHT);
1574 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1576 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1577 ieee->current_network.beacon_interval /
1579 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1580 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1581 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1582 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1584 pPSC->LpsIdleCount = 0;
1585 ieee->link_change(ieee->dev);
1587 if (ieee->is_silent_reset) {
1588 netdev_info(ieee->dev, "silent reset associate\n");
1589 ieee->is_silent_reset = false;
1592 if (ieee->data_hard_resume)
1593 ieee->data_hard_resume(ieee->dev);
1597 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1601 static void rtllib_associate_complete(struct rtllib_device *ieee)
1603 del_timer_sync(&ieee->associate_timer);
1605 ieee->state = RTLLIB_LINKED;
1606 rtllib_sta_send_associnfo(ieee);
1608 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1611 static void rtllib_associate_procedure_wq(void *data)
1613 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1614 struct rtllib_device,
1615 associate_procedure_wq);
1616 rtllib_stop_scan_syncro(ieee);
1617 if (ieee->rtllib_ips_leave != NULL)
1618 ieee->rtllib_ips_leave(ieee->dev);
1619 down(&ieee->wx_sem);
1621 if (ieee->data_hard_stop)
1622 ieee->data_hard_stop(ieee->dev);
1624 rtllib_stop_scan(ieee);
1625 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1626 ieee->current_network.channel);
1627 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1628 if (ieee->eRFPowerState == eRfOff) {
1630 "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n",
1632 if (ieee->rtllib_ips_leave_wq != NULL)
1633 ieee->rtllib_ips_leave_wq(ieee->dev);
1637 ieee->associate_seq = 1;
1639 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1644 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1645 struct rtllib_network *net)
1647 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1648 int tmp_ssid_len = 0;
1650 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1652 /* we are interested in new new only if we are not associated
1653 * and we are not associating / authenticating
1655 if (ieee->state != RTLLIB_NOLINK)
1658 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1659 WLAN_CAPABILITY_ESS))
1662 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1663 WLAN_CAPABILITY_IBSS))
1666 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1667 (net->channel > ieee->ibss_maxjoin_chal))
1669 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1670 /* if the user specified the AP MAC, we need also the essid
1671 * This could be obtained by beacons or, if the network does not
1672 * broadcast it, it can be put manually.
1674 apset = ieee->wap_set;
1675 ssidset = ieee->ssid_set;
1676 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1677 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1680 ssidmatch = (ieee->current_network.ssid_len ==
1681 net->hidden_ssid_len) &&
1682 (!strncmp(ieee->current_network.ssid,
1683 net->hidden_ssid, net->hidden_ssid_len));
1684 if (net->hidden_ssid_len > 0) {
1685 strncpy(net->ssid, net->hidden_ssid,
1686 net->hidden_ssid_len);
1687 net->ssid_len = net->hidden_ssid_len;
1692 (ieee->current_network.ssid_len == net->ssid_len) &&
1693 (!strncmp(ieee->current_network.ssid, net->ssid,
1696 /* if the user set the AP check if match.
1697 * if the network does not broadcast essid we check the
1698 * user supplied ANY essid
1699 * if the network does broadcast and the user does not set
1701 * if the network does broadcast and the user did set essid
1702 * check if essid match
1703 * if the ap is not set, check that the user set the bssid
1704 * and the network does broadcast and that those two bssid match
1706 if ((apset && apmatch &&
1707 ((ssidset && ssidbroad && ssidmatch) ||
1708 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1709 (!apset && ssidset && ssidbroad && ssidmatch) ||
1710 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1711 /* if the essid is hidden replace it with the
1712 * essid provided by the user.
1715 strncpy(tmp_ssid, ieee->current_network.ssid,
1717 tmp_ssid_len = ieee->current_network.ssid_len;
1719 memcpy(&ieee->current_network, net,
1720 sizeof(struct rtllib_network));
1722 strncpy(ieee->current_network.ssid, tmp_ssid,
1724 ieee->current_network.ssid_len = tmp_ssid_len;
1726 netdev_info(ieee->dev,
1727 "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",
1728 ieee->current_network.ssid,
1729 ieee->current_network.channel,
1730 ieee->current_network.qos_data.supported,
1731 ieee->pHTInfo->bEnableHT,
1732 ieee->current_network.bssht.bdSupportHT,
1733 ieee->current_network.mode,
1734 ieee->current_network.flags);
1736 if ((rtllib_act_scanning(ieee, false)) &&
1737 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1738 rtllib_stop_scan_syncro(ieee);
1740 ieee->hwscan_ch_bk = ieee->current_network.channel;
1741 HTResetIOTSetting(ieee->pHTInfo);
1743 if (ieee->iw_mode == IW_MODE_INFRA) {
1744 /* Join the network for the first time */
1745 ieee->AsocRetryCount = 0;
1746 if ((ieee->current_network.qos_data.supported == 1) &&
1747 ieee->current_network.bssht.bdSupportHT)
1748 HTResetSelfAndSavePeerSetting(ieee,
1749 &(ieee->current_network));
1751 ieee->pHTInfo->bCurrentHTSupport =
1754 ieee->state = RTLLIB_ASSOCIATING;
1755 if (ieee->LedControlHandler != NULL)
1756 ieee->LedControlHandler(ieee->dev,
1757 LED_CTL_START_TO_LINK);
1758 queue_delayed_work_rsl(ieee->wq,
1759 &ieee->associate_procedure_wq, 0);
1761 if (rtllib_is_54g(&ieee->current_network) &&
1762 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1764 ieee->SetWirelessMode(ieee->dev, IEEE_G);
1765 netdev_info(ieee->dev, "Using G rates\n");
1768 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1769 netdev_info(ieee->dev, "Using B rates\n");
1771 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1772 ieee->state = RTLLIB_LINKED;
1778 void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1780 unsigned long flags;
1781 struct rtllib_network *target;
1783 spin_lock_irqsave(&ieee->lock, flags);
1785 list_for_each_entry(target, &ieee->network_list, list) {
1787 /* if the state become different that NOLINK means
1788 * we had found what we are searching for
1791 if (ieee->state != RTLLIB_NOLINK)
1794 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1795 ieee->scan_age, jiffies))
1796 rtllib_softmac_new_net(ieee, target);
1798 spin_unlock_irqrestore(&ieee->lock, flags);
1801 static inline u16 auth_parse(struct sk_buff *skb, u8 **challenge, int *chlen)
1803 struct rtllib_authentication *a;
1806 if (skb->len < (sizeof(struct rtllib_authentication) -
1807 sizeof(struct rtllib_info_element))) {
1808 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1812 a = (struct rtllib_authentication *) skb->data;
1813 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1814 t = skb->data + sizeof(struct rtllib_authentication);
1816 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1818 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1823 return cpu_to_le16(a->status);
1826 static int auth_rq_parse(struct sk_buff *skb, u8 *dest)
1828 struct rtllib_authentication *a;
1830 if (skb->len < (sizeof(struct rtllib_authentication) -
1831 sizeof(struct rtllib_info_element))) {
1832 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",
1836 a = (struct rtllib_authentication *) skb->data;
1838 memcpy(dest, a->header.addr2, ETH_ALEN);
1840 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1841 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1843 return WLAN_STATUS_SUCCESS;
1846 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1853 struct rtllib_hdr_3addr *header =
1854 (struct rtllib_hdr_3addr *) skb->data;
1857 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1858 return -1; /* corrupted */
1861 (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0) &&
1862 (!is_broadcast_ether_addr(header->addr3));
1866 memcpy(src, header->addr2, ETH_ALEN);
1868 skbend = (u8 *)skb->data + skb->len;
1870 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1872 while (tag + 1 < skbend) {
1875 ssidlen = *(tag + 1);
1878 tag++; /* point to the len field */
1879 tag = tag + *(tag); /* point to the last data byte of the tag */
1880 tag++; /* point to the next tag */
1887 return 1; /* ssid not found in tagged param */
1889 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1892 static int assoc_rq_parse(struct sk_buff *skb, u8 *dest)
1894 struct rtllib_assoc_request_frame *a;
1896 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1897 sizeof(struct rtllib_info_element))) {
1899 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d\n", skb->len);
1903 a = (struct rtllib_assoc_request_frame *) skb->data;
1905 memcpy(dest, a->header.addr2, ETH_ALEN);
1910 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1913 struct rtllib_assoc_response_frame *response_head;
1916 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1917 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1921 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1922 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1924 status_code = le16_to_cpu(response_head->status);
1925 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1926 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1927 ((ieee->mode == IEEE_G) &&
1928 (ieee->current_network.mode == IEEE_N_24G) &&
1929 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1930 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1932 ieee->AsocRetryCount = 0;
1935 return le16_to_cpu(response_head->status);
1938 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1942 ieee->softmac_stats.rx_probe_rq++;
1943 if (probe_rq_parse(ieee, skb, dest) > 0) {
1944 ieee->softmac_stats.tx_probe_rs++;
1945 rtllib_resp_to_probe(ieee, dest);
1949 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1950 struct sk_buff *skb)
1955 ieee->softmac_stats.rx_auth_rq++;
1957 status = auth_rq_parse(skb, dest);
1959 rtllib_resp_to_auth(ieee, status, dest);
1962 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1963 struct sk_buff *skb)
1968 ieee->softmac_stats.rx_ass_rq++;
1969 if (assoc_rq_parse(skb, dest) != -1)
1970 rtllib_resp_to_assoc_rq(ieee, dest);
1972 netdev_info(ieee->dev, "New client associated: %pM\n", dest);
1975 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1978 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1981 softmac_ps_mgmt_xmit(buf, ieee);
1983 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1985 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1987 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1990 softmac_ps_mgmt_xmit(buf, ieee);
1993 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1995 int timeout = ieee->ps_timeout;
1997 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1998 (&(ieee->PowerSaveControl));
2000 if (ieee->LPSDelayCnt) {
2001 ieee->LPSDelayCnt--;
2005 dtim = ieee->current_network.dtim_data;
2006 if (!(dtim & RTLLIB_DTIM_VALID))
2008 timeout = ieee->current_network.beacon_interval;
2009 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
2010 /* there's no need to nofity AP that I find you buffered
2011 * with broadcast packet */
2012 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
2015 if (!time_after(jiffies,
2016 ieee->dev->trans_start + msecs_to_jiffies(timeout)))
2018 if (!time_after(jiffies,
2019 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
2021 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
2022 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
2026 if (ieee->bAwakePktSent) {
2027 pPSC->LPSAwakeIntvl = 1;
2031 if (pPSC->LPSAwakeIntvl == 0)
2032 pPSC->LPSAwakeIntvl = 1;
2033 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2035 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2036 MaxPeriod = ieee->current_network.dtim_period;
2038 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2039 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2040 MaxPeriod) ? MaxPeriod :
2041 (pPSC->LPSAwakeIntvl + 1);
2044 u8 LPSAwakeIntvl_tmp = 0;
2045 u8 period = ieee->current_network.dtim_period;
2046 u8 count = ieee->current_network.tim.tim_count;
2049 if (pPSC->LPSAwakeIntvl > period)
2050 LPSAwakeIntvl_tmp = period +
2051 (pPSC->LPSAwakeIntvl -
2053 ((pPSC->LPSAwakeIntvl-period) %
2056 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2059 if (pPSC->LPSAwakeIntvl >
2060 ieee->current_network.tim.tim_count)
2061 LPSAwakeIntvl_tmp = count +
2062 (pPSC->LPSAwakeIntvl - count) -
2063 ((pPSC->LPSAwakeIntvl-count)%period);
2065 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2068 *time = ieee->current_network.last_dtim_sta_time
2069 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2079 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2083 unsigned long flags, flags2;
2085 spin_lock_irqsave(&ieee->lock, flags);
2087 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2088 ieee->iw_mode != IW_MODE_INFRA ||
2089 ieee->state != RTLLIB_LINKED)) {
2091 "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n",
2092 __func__, ieee->ps, ieee->iw_mode, ieee->state);
2093 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2094 rtllib_sta_wakeup(ieee, 1);
2096 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2098 sleep = rtllib_sta_ps_sleep(ieee, &time);
2099 /* 2 wake, 1 sleep, 0 do nothing */
2103 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2104 ieee->enter_sleep_state(ieee->dev, time);
2105 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2106 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2108 if (ieee->ps_is_queue_empty(ieee->dev)) {
2109 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2110 ieee->ack_tx_to_ieee = 1;
2111 rtllib_sta_ps_send_null_frame(ieee, 1);
2112 ieee->ps_time = time;
2114 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2118 ieee->bAwakePktSent = false;
2120 } else if (sleep == 2) {
2121 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2123 rtllib_sta_wakeup(ieee, 1);
2125 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2129 spin_unlock_irqrestore(&ieee->lock, flags);
2133 void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2135 if (ieee->sta_sleep == LPS_IS_WAKE) {
2137 if (ieee->pHTInfo->IOTAction &
2138 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2139 ieee->ack_tx_to_ieee = 1;
2140 rtllib_sta_ps_send_null_frame(ieee, 0);
2142 ieee->ack_tx_to_ieee = 1;
2143 rtllib_sta_ps_send_pspoll_frame(ieee);
2150 if (ieee->sta_sleep == LPS_IS_SLEEP)
2151 ieee->sta_wake_up(ieee->dev);
2153 if (ieee->pHTInfo->IOTAction &
2154 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2155 ieee->ack_tx_to_ieee = 1;
2156 rtllib_sta_ps_send_null_frame(ieee, 0);
2158 ieee->ack_tx_to_ieee = 1;
2159 ieee->polling = true;
2160 rtllib_sta_ps_send_pspoll_frame(ieee);
2164 ieee->sta_sleep = LPS_IS_WAKE;
2165 ieee->polling = false;
2169 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2171 unsigned long flags, flags2;
2173 spin_lock_irqsave(&ieee->lock, flags);
2175 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2176 /* Null frame with PS bit set */
2178 ieee->sta_sleep = LPS_IS_SLEEP;
2179 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2181 /* if the card report not success we can't be sure the AP
2182 * has not RXed so we can't assume the AP believe us awake
2184 } else {/* 21112005 - tx again null without PS bit if lost */
2186 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2187 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2188 if (ieee->pHTInfo->IOTAction &
2189 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2190 rtllib_sta_ps_send_null_frame(ieee, 0);
2192 rtllib_sta_ps_send_pspoll_frame(ieee);
2193 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2196 spin_unlock_irqrestore(&ieee->lock, flags);
2198 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2200 static void rtllib_process_action(struct rtllib_device *ieee, struct sk_buff *skb)
2202 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2203 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2207 RTLLIB_DEBUG(RTLLIB_DL_ERR,
2208 "error to get payload of action frame\n");
2218 rtllib_rx_ADDBAReq(ieee, skb);
2221 rtllib_rx_ADDBARsp(ieee, skb);
2224 rtllib_rx_DELBA(ieee, skb);
2234 inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2235 struct rtllib_rx_stats *rx_stats)
2240 struct rtllib_assoc_response_frame *assoc_resp;
2241 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2243 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2244 WLAN_FC_GET_STYPE(header->frame_ctl));
2246 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2247 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2248 (ieee->iw_mode == IW_MODE_INFRA)) {
2249 errcode = assoc_parse(ieee, skb, &aid);
2251 struct rtllib_network *network =
2252 kzalloc(sizeof(struct rtllib_network),
2257 ieee->state = RTLLIB_LINKED;
2258 ieee->assoc_id = aid;
2259 ieee->softmac_stats.rx_ass_ok++;
2260 /* station support qos */
2261 /* Let the register setting default with Legacy station */
2262 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2263 if (ieee->current_network.qos_data.supported == 1) {
2264 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2265 rx_stats->len - sizeof(*assoc_resp),
2266 network, rx_stats)) {
2270 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2271 network->bssht.bdHTCapBuf,
2272 network->bssht.bdHTCapLen);
2273 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2274 network->bssht.bdHTInfoBuf,
2275 network->bssht.bdHTInfoLen);
2276 if (ieee->handle_assoc_response != NULL)
2277 ieee->handle_assoc_response(ieee->dev,
2278 (struct rtllib_assoc_response_frame *)header,
2283 kfree(ieee->assocresp_ies);
2284 ieee->assocresp_ies = NULL;
2285 ies = &(assoc_resp->info_element[0].id);
2286 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2287 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2289 if (ieee->assocresp_ies)
2290 memcpy(ieee->assocresp_ies, ies,
2291 ieee->assocresp_ies_len);
2293 netdev_info(ieee->dev,
2294 "%s()Warning: can't alloc memory for assocresp_ies\n",
2296 ieee->assocresp_ies_len = 0;
2298 rtllib_associate_complete(ieee);
2300 /* aid could not been allocated */
2301 ieee->softmac_stats.rx_ass_err++;
2302 netdev_info(ieee->dev,
2303 "Association response status code 0x%x\n",
2306 "Association response status code 0x%x\n",
2308 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2309 queue_delayed_work_rsl(ieee->wq,
2310 &ieee->associate_procedure_wq, 0);
2312 rtllib_associate_abort(ieee);
2318 inline int rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2319 struct rtllib_rx_stats *rx_stats)
2324 bool bSupportNmode = true, bHalfSupportNmode = false;
2326 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2327 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2328 (ieee->iw_mode == IW_MODE_INFRA)) {
2329 RTLLIB_DEBUG_MGMT("Received authentication response");
2331 errcode = auth_parse(skb, &challenge, &chlen);
2333 if (ieee->open_wep || !challenge) {
2334 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2335 ieee->softmac_stats.rx_auth_rs_ok++;
2336 if (!(ieee->pHTInfo->IOTAction &
2337 HT_IOT_ACT_PURE_N_MODE)) {
2338 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2339 if (IsHTHalfNmodeAPs(ieee)) {
2340 bSupportNmode = true;
2341 bHalfSupportNmode = true;
2343 bSupportNmode = false;
2344 bHalfSupportNmode = false;
2348 /* Dummy wirless mode setting to avoid
2349 * encryption issue */
2350 if (bSupportNmode) {
2351 ieee->SetWirelessMode(ieee->dev,
2352 ieee->current_network.mode);
2355 ieee->SetWirelessMode(ieee->dev,
2359 if (ieee->current_network.mode ==
2360 IEEE_N_24G && bHalfSupportNmode) {
2361 netdev_info(ieee->dev,
2362 "======>enter half N mode\n");
2363 ieee->bHalfWirelessN24GMode =
2366 ieee->bHalfWirelessN24GMode =
2369 rtllib_associate_step2(ieee);
2371 rtllib_auth_challenge(ieee, challenge,
2375 ieee->softmac_stats.rx_auth_rs_err++;
2376 RTLLIB_DEBUG_MGMT("Authentication respose status code 0x%x",
2379 netdev_info(ieee->dev,
2380 "Authentication respose status code 0x%x",
2382 rtllib_associate_abort(ieee);
2385 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2386 rtllib_rx_auth_rq(ieee, skb);
2392 inline int rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2394 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2396 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2399 /* FIXME for now repeat all the association procedure
2400 * both for disassociation and deauthentication
2402 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2403 ieee->state == RTLLIB_LINKED &&
2404 (ieee->iw_mode == IW_MODE_INFRA)) {
2405 netdev_info(ieee->dev,
2406 "==========>received disassoc/deauth(%x) frame, reason code:%x\n",
2407 WLAN_FC_GET_STYPE(header->frame_ctl),
2408 ((struct rtllib_disassoc *)skb->data)->reason);
2409 ieee->state = RTLLIB_ASSOCIATING;
2410 ieee->softmac_stats.reassoc++;
2411 ieee->is_roaming = true;
2412 ieee->LinkDetectInfo.bBusyTraffic = false;
2413 rtllib_disassociate(ieee);
2414 RemovePeerTS(ieee, header->addr2);
2415 if (ieee->LedControlHandler != NULL)
2416 ieee->LedControlHandler(ieee->dev,
2417 LED_CTL_START_TO_LINK);
2419 if (!(ieee->rtllib_ap_sec_type(ieee) &
2420 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2421 queue_delayed_work_rsl(ieee->wq,
2422 &ieee->associate_procedure_wq, 5);
2427 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2428 struct sk_buff *skb,
2429 struct rtllib_rx_stats *rx_stats, u16 type,
2432 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2434 if (!ieee->proto_started)
2437 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2438 case RTLLIB_STYPE_ASSOC_RESP:
2439 case RTLLIB_STYPE_REASSOC_RESP:
2440 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2443 case RTLLIB_STYPE_ASSOC_REQ:
2444 case RTLLIB_STYPE_REASSOC_REQ:
2445 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2446 ieee->iw_mode == IW_MODE_MASTER)
2447 rtllib_rx_assoc_rq(ieee, skb);
2449 case RTLLIB_STYPE_AUTH:
2450 rtllib_rx_auth(ieee, skb, rx_stats);
2452 case RTLLIB_STYPE_DISASSOC:
2453 case RTLLIB_STYPE_DEAUTH:
2454 rtllib_rx_deauth(ieee, skb);
2456 case RTLLIB_STYPE_MANAGE_ACT:
2457 rtllib_process_action(ieee, skb);
2465 /* following are for a simpler TX queue management.
2466 * Instead of using netif_[stop/wake]_queue the driver
2467 * will use these two functions (plus a reset one), that
2468 * will internally use the kernel netif_* and takes
2469 * care of the ieee802.11 fragmentation.
2470 * So the driver receives a fragment per time and might
2471 * call the stop function when it wants to not
2472 * have enough room to TX an entire packet.
2473 * This might be useful if each fragment needs it's own
2474 * descriptor, thus just keep a total free memory > than
2475 * the max fragmentation threshold is not enough.. If the
2476 * ieee802.11 stack passed a TXB struct then you need
2477 * to keep N free descriptors where
2478 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2479 * In this way you need just one and the 802.11 stack
2480 * will take care of buffering fragments and pass them to
2481 * to the driver later, when it wakes the queue.
2483 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2486 unsigned int queue_index = txb->queue_index;
2487 unsigned long flags;
2489 struct cb_desc *tcb_desc = NULL;
2490 unsigned long queue_len = 0;
2492 spin_lock_irqsave(&ieee->lock, flags);
2494 /* called with 2nd parm 0, no tx mgmt lock required */
2495 rtllib_sta_wakeup(ieee, 0);
2497 /* update the tx status */
2498 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2500 if (tcb_desc->bMulticast)
2501 ieee->stats.multicast++;
2503 /* if xmit available, just xmit it immediately, else just insert it to
2505 for (i = 0; i < txb->nr_frags; i++) {
2506 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2507 if ((queue_len != 0) ||\
2508 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2509 (ieee->queue_stop)) {
2510 /* insert the skb packet to the wait queue */
2511 /* as for the completion function, it does not need
2512 * to check it any more.
2514 if (queue_len < 200)
2515 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2518 kfree_skb(txb->fragments[i]);
2520 ieee->softmac_data_hard_start_xmit(
2522 ieee->dev, ieee->rate);
2526 rtllib_txb_free(txb);
2528 spin_unlock_irqrestore(&ieee->lock, flags);
2532 /* called with ieee->lock acquired */
2533 static void rtllib_resume_tx(struct rtllib_device *ieee)
2537 for (i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags;
2540 if (ieee->queue_stop) {
2541 ieee->tx_pending.frag = i;
2545 ieee->softmac_data_hard_start_xmit(
2546 ieee->tx_pending.txb->fragments[i],
2547 ieee->dev, ieee->rate);
2548 ieee->stats.tx_packets++;
2552 rtllib_txb_free(ieee->tx_pending.txb);
2553 ieee->tx_pending.txb = NULL;
2557 void rtllib_reset_queue(struct rtllib_device *ieee)
2559 unsigned long flags;
2561 spin_lock_irqsave(&ieee->lock, flags);
2562 init_mgmt_queue(ieee);
2563 if (ieee->tx_pending.txb) {
2564 rtllib_txb_free(ieee->tx_pending.txb);
2565 ieee->tx_pending.txb = NULL;
2567 ieee->queue_stop = 0;
2568 spin_unlock_irqrestore(&ieee->lock, flags);
2571 EXPORT_SYMBOL(rtllib_reset_queue);
2573 void rtllib_wake_queue(struct rtllib_device *ieee)
2576 unsigned long flags;
2577 struct sk_buff *skb;
2578 struct rtllib_hdr_3addr *header;
2580 spin_lock_irqsave(&ieee->lock, flags);
2581 if (!ieee->queue_stop)
2584 ieee->queue_stop = 0;
2586 if (ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) {
2587 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))) {
2589 header = (struct rtllib_hdr_3addr *) skb->data;
2591 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2593 if (ieee->seq_ctrl[0] == 0xFFF)
2594 ieee->seq_ctrl[0] = 0;
2596 ieee->seq_ctrl[0]++;
2598 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
2602 if (!ieee->queue_stop && ieee->tx_pending.txb)
2603 rtllib_resume_tx(ieee);
2605 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)) {
2606 ieee->softmac_stats.swtxawake++;
2607 netif_wake_queue(ieee->dev);
2611 spin_unlock_irqrestore(&ieee->lock, flags);
2615 void rtllib_stop_queue(struct rtllib_device *ieee)
2618 if (!netif_queue_stopped(ieee->dev)) {
2619 netif_stop_queue(ieee->dev);
2620 ieee->softmac_stats.swtxstop++;
2622 ieee->queue_stop = 1;
2626 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2630 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2631 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2633 netif_tx_stop_all_queues(ieee->dev);
2636 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2638 netif_tx_wake_all_queues(ieee->dev);
2641 inline void rtllib_randomize_cell(struct rtllib_device *ieee)
2644 random_ether_addr(ieee->current_network.bssid);
2647 /* called in user context only */
2648 void rtllib_start_master_bss(struct rtllib_device *ieee)
2652 if (ieee->current_network.ssid_len == 0) {
2653 strncpy(ieee->current_network.ssid,
2654 RTLLIB_DEFAULT_TX_ESSID,
2657 ieee->current_network.ssid_len =
2658 strlen(RTLLIB_DEFAULT_TX_ESSID);
2662 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2664 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2665 ieee->state = RTLLIB_LINKED;
2666 ieee->link_change(ieee->dev);
2667 notify_wx_assoc_event(ieee);
2669 if (ieee->data_hard_resume)
2670 ieee->data_hard_resume(ieee->dev);
2672 netif_carrier_on(ieee->dev);
2675 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2677 /* reset hardware status */
2679 if (ieee->data_hard_resume)
2680 ieee->data_hard_resume(ieee->dev);
2682 netif_carrier_on(ieee->dev);
2686 static void rtllib_start_ibss_wq(void *data)
2688 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2689 struct rtllib_device, start_ibss_wq);
2690 /* iwconfig mode ad-hoc will schedule this and return
2691 * on the other hand this will block further iwconfig SET
2692 * operations because of the wx_sem hold.
2693 * Anyway some most set operations set a flag to speed-up
2694 * (abort) this wq (when syncro scanning) before sleeping
2697 if (!ieee->proto_started) {
2698 netdev_info(ieee->dev, "==========oh driver down return\n");
2701 down(&ieee->wx_sem);
2703 if (ieee->current_network.ssid_len == 0) {
2704 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2705 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2709 ieee->state = RTLLIB_NOLINK;
2710 ieee->mode = IEEE_G;
2711 /* check if we have this cell in our network list */
2712 rtllib_softmac_check_all_nets(ieee);
2715 /* if not then the state is not linked. Maybe the user switched to
2716 * ad-hoc mode just after being in monitor mode, or just after
2717 * being very few time in managed mode (so the card have had no
2718 * time to scan all the chans..) or we have just run up the iface
2719 * after setting ad-hoc mode. So we have to give another try..
2720 * Here, in ibss mode, should be safe to do this without extra care
2721 * (in bss mode we had to make sure no-one tried to associate when
2722 * we had just checked the ieee->state and we was going to start the
2723 * scan) because in ibss mode the rtllib_new_net function, when
2724 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2725 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2726 * scan, that will stop at the first round because it sees the state
2729 if (ieee->state == RTLLIB_NOLINK)
2730 rtllib_start_scan_syncro(ieee, 0);
2732 /* the network definitively is not here.. create a new cell */
2733 if (ieee->state == RTLLIB_NOLINK) {
2734 netdev_info(ieee->dev, "creating new IBSS cell\n");
2735 ieee->current_network.channel = ieee->IbssStartChnl;
2737 rtllib_randomize_cell(ieee);
2739 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2741 ieee->current_network.rates_len = 4;
2743 ieee->current_network.rates[0] =
2744 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2745 ieee->current_network.rates[1] =
2746 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2747 ieee->current_network.rates[2] =
2748 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2749 ieee->current_network.rates[3] =
2750 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2753 ieee->current_network.rates_len = 0;
2755 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2756 ieee->current_network.rates_ex_len = 8;
2758 ieee->current_network.rates_ex[0] =
2759 RTLLIB_OFDM_RATE_6MB;
2760 ieee->current_network.rates_ex[1] =
2761 RTLLIB_OFDM_RATE_9MB;
2762 ieee->current_network.rates_ex[2] =
2763 RTLLIB_OFDM_RATE_12MB;
2764 ieee->current_network.rates_ex[3] =
2765 RTLLIB_OFDM_RATE_18MB;
2766 ieee->current_network.rates_ex[4] =
2767 RTLLIB_OFDM_RATE_24MB;
2768 ieee->current_network.rates_ex[5] =
2769 RTLLIB_OFDM_RATE_36MB;
2770 ieee->current_network.rates_ex[6] =
2771 RTLLIB_OFDM_RATE_48MB;
2772 ieee->current_network.rates_ex[7] =
2773 RTLLIB_OFDM_RATE_54MB;
2777 ieee->current_network.rates_ex_len = 0;
2781 ieee->current_network.qos_data.supported = 0;
2782 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2783 ieee->current_network.mode = ieee->mode;
2784 ieee->current_network.atim_window = 0;
2785 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2788 netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2789 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2790 HTUseDefaultSetting(ieee);
2792 ieee->pHTInfo->bCurrentHTSupport = false;
2794 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2795 (u8 *)(&ieee->state));
2797 ieee->state = RTLLIB_LINKED;
2798 ieee->link_change(ieee->dev);
2800 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2801 if (ieee->LedControlHandler != NULL)
2802 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2804 rtllib_start_send_beacons(ieee);
2806 notify_wx_assoc_event(ieee);
2808 if (ieee->data_hard_resume)
2809 ieee->data_hard_resume(ieee->dev);
2811 netif_carrier_on(ieee->dev);
2816 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2818 queue_delayed_work_rsl(ieee->wq, &ieee->start_ibss_wq,
2819 msecs_to_jiffies(150));
2822 /* this is called only in user context, with wx_sem held */
2823 void rtllib_start_bss(struct rtllib_device *ieee)
2825 unsigned long flags;
2827 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2828 if (!ieee->bGlobalDomain)
2831 /* check if we have already found the net we
2832 * are interested in (if any).
2833 * if not (we are disassociated and we are not
2834 * in associating / authenticating phase) start the background scanning.
2836 rtllib_softmac_check_all_nets(ieee);
2838 /* ensure no-one start an associating process (thus setting
2839 * the ieee->state to rtllib_ASSOCIATING) while we
2840 * have just checked it and we are going to enable scan.
2841 * The rtllib_new_net function is always called with
2842 * lock held (from both rtllib_softmac_check_all_nets and
2843 * the rx path), so we cannot be in the middle of such function
2845 spin_lock_irqsave(&ieee->lock, flags);
2847 if (ieee->state == RTLLIB_NOLINK)
2848 rtllib_start_scan(ieee);
2849 spin_unlock_irqrestore(&ieee->lock, flags);
2852 static void rtllib_link_change_wq(void *data)
2854 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2855 struct rtllib_device, link_change_wq);
2856 ieee->link_change(ieee->dev);
2858 /* called only in userspace context */
2859 void rtllib_disassociate(struct rtllib_device *ieee)
2861 netif_carrier_off(ieee->dev);
2862 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2863 rtllib_reset_queue(ieee);
2865 if (ieee->data_hard_stop)
2866 ieee->data_hard_stop(ieee->dev);
2867 if (IS_DOT11D_ENABLE(ieee))
2869 ieee->state = RTLLIB_NOLINK;
2870 ieee->is_set_key = false;
2873 queue_delayed_work_rsl(ieee->wq, &ieee->link_change_wq, 0);
2875 notify_wx_assoc_event(ieee);
2878 static void rtllib_associate_retry_wq(void *data)
2880 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2881 struct rtllib_device, associate_retry_wq);
2882 unsigned long flags;
2884 down(&ieee->wx_sem);
2885 if (!ieee->proto_started)
2888 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2891 /* until we do not set the state to RTLLIB_NOLINK
2892 * there are no possibility to have someone else trying
2893 * to start an association procedure (we get here with
2894 * ieee->state = RTLLIB_ASSOCIATING).
2895 * When we set the state to RTLLIB_NOLINK it is possible
2896 * that the RX path run an attempt to associate, but
2897 * both rtllib_softmac_check_all_nets and the
2898 * RX path works with ieee->lock held so there are no
2899 * problems. If we are still disassociated then start a scan.
2900 * the lock here is necessary to ensure no one try to start
2901 * an association procedure when we have just checked the
2902 * state and we are going to start the scan.
2904 ieee->beinretry = true;
2905 ieee->state = RTLLIB_NOLINK;
2907 rtllib_softmac_check_all_nets(ieee);
2909 spin_lock_irqsave(&ieee->lock, flags);
2911 if (ieee->state == RTLLIB_NOLINK)
2912 rtllib_start_scan(ieee);
2913 spin_unlock_irqrestore(&ieee->lock, flags);
2915 ieee->beinretry = false;
2920 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2922 u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2924 struct sk_buff *skb;
2925 struct rtllib_probe_response *b;
2927 skb = rtllib_probe_resp(ieee, broadcast_addr);
2932 b = (struct rtllib_probe_response *) skb->data;
2933 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2939 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2941 struct sk_buff *skb;
2942 struct rtllib_probe_response *b;
2944 skb = rtllib_get_beacon_(ieee);
2948 b = (struct rtllib_probe_response *) skb->data;
2949 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2951 if (ieee->seq_ctrl[0] == 0xFFF)
2952 ieee->seq_ctrl[0] = 0;
2954 ieee->seq_ctrl[0]++;
2958 EXPORT_SYMBOL(rtllib_get_beacon);
2960 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2963 rtllib_stop_scan_syncro(ieee);
2964 down(&ieee->wx_sem);
2965 rtllib_stop_protocol(ieee, shutdown);
2968 EXPORT_SYMBOL(rtllib_softmac_stop_protocol);
2971 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2973 if (!ieee->proto_started)
2977 ieee->proto_started = 0;
2978 ieee->proto_stoppping = 1;
2979 if (ieee->rtllib_ips_leave != NULL)
2980 ieee->rtllib_ips_leave(ieee->dev);
2983 rtllib_stop_send_beacons(ieee);
2984 del_timer_sync(&ieee->associate_timer);
2985 cancel_delayed_work(&ieee->associate_retry_wq);
2986 cancel_delayed_work(&ieee->start_ibss_wq);
2987 cancel_delayed_work(&ieee->link_change_wq);
2988 rtllib_stop_scan(ieee);
2990 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2991 ieee->state = RTLLIB_NOLINK;
2993 if (ieee->state == RTLLIB_LINKED) {
2994 if (ieee->iw_mode == IW_MODE_INFRA)
2995 SendDisassociation(ieee, 1, deauth_lv_ss);
2996 rtllib_disassociate(ieee);
3001 ieee->proto_stoppping = 0;
3003 kfree(ieee->assocreq_ies);
3004 ieee->assocreq_ies = NULL;
3005 ieee->assocreq_ies_len = 0;
3006 kfree(ieee->assocresp_ies);
3007 ieee->assocresp_ies = NULL;
3008 ieee->assocresp_ies_len = 0;
3011 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
3013 down(&ieee->wx_sem);
3014 rtllib_start_protocol(ieee);
3017 EXPORT_SYMBOL(rtllib_softmac_start_protocol);
3019 void rtllib_start_protocol(struct rtllib_device *ieee)
3024 rtllib_update_active_chan_map(ieee);
3026 if (ieee->proto_started)
3029 ieee->proto_started = 1;
3031 if (ieee->current_network.channel == 0) {
3034 if (ch > MAX_CHANNEL_NUMBER)
3035 return; /* no channel found */
3036 } while (!ieee->active_channel_map[ch]);
3037 ieee->current_network.channel = ch;
3040 if (ieee->current_network.beacon_interval == 0)
3041 ieee->current_network.beacon_interval = 100;
3043 for (i = 0; i < 17; i++) {
3044 ieee->last_rxseq_num[i] = -1;
3045 ieee->last_rxfrag_num[i] = -1;
3046 ieee->last_packet_time[i] = 0;
3049 if (ieee->UpdateBeaconInterruptHandler)
3050 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
3053 /* if the user set the MAC of the ad-hoc cell and then
3054 * switch to managed mode, shall we make sure that association
3055 * attempts does not fail just because the user provide the essid
3056 * and the nic is still checking for the AP MAC ??
3058 if (ieee->iw_mode == IW_MODE_INFRA) {
3059 rtllib_start_bss(ieee);
3060 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
3061 if (ieee->UpdateBeaconInterruptHandler)
3062 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
3064 rtllib_start_ibss(ieee);
3066 } else if (ieee->iw_mode == IW_MODE_MASTER) {
3067 rtllib_start_master_bss(ieee);
3068 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
3069 rtllib_start_monitor_mode(ieee);
3073 void rtllib_softmac_init(struct rtllib_device *ieee)
3077 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
3079 ieee->state = RTLLIB_NOLINK;
3080 for (i = 0; i < 5; i++)
3081 ieee->seq_ctrl[i] = 0;
3082 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
3083 if (!ieee->pDot11dInfo)
3084 RTLLIB_DEBUG(RTLLIB_DL_ERR, "can't alloc memory for DOT11D\n");
3085 ieee->LinkDetectInfo.SlotIndex = 0;
3086 ieee->LinkDetectInfo.SlotNum = 2;
3087 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3088 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
3089 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3090 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3091 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
3092 ieee->bIsAggregateFrame = false;
3094 ieee->queue_stop = 0;
3095 ieee->scanning_continue = 0;
3096 ieee->softmac_features = 0;
3099 ieee->proto_started = 0;
3100 ieee->proto_stoppping = 0;
3101 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
3103 ieee->ps = RTLLIB_PS_DISABLED;
3104 ieee->sta_sleep = LPS_IS_WAKE;
3106 ieee->Regdot11HTOperationalRateSet[0] = 0xff;
3107 ieee->Regdot11HTOperationalRateSet[1] = 0xff;
3108 ieee->Regdot11HTOperationalRateSet[4] = 0x01;
3110 ieee->Regdot11TxHTOperationalRateSet[0] = 0xff;
3111 ieee->Regdot11TxHTOperationalRateSet[1] = 0xff;
3112 ieee->Regdot11TxHTOperationalRateSet[4] = 0x01;
3114 ieee->FirstIe_InScan = false;
3115 ieee->actscanning = false;
3116 ieee->beinretry = false;
3117 ieee->is_set_key = false;
3118 init_mgmt_queue(ieee);
3120 ieee->sta_edca_param[0] = 0x0000A403;
3121 ieee->sta_edca_param[1] = 0x0000A427;
3122 ieee->sta_edca_param[2] = 0x005E4342;
3123 ieee->sta_edca_param[3] = 0x002F3262;
3124 ieee->aggregation = true;
3125 ieee->enable_rx_imm_BA = true;
3126 ieee->tx_pending.txb = NULL;
3128 _setup_timer(&ieee->associate_timer,
3129 rtllib_associate_abort_cb,
3130 (unsigned long) ieee);
3132 _setup_timer(&ieee->beacon_timer,
3133 rtllib_send_beacon_cb,
3134 (unsigned long) ieee);
3137 ieee->wq = create_workqueue(DRV_NAME);
3139 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3140 (void *)rtllib_link_change_wq, ieee);
3141 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3142 (void *)rtllib_start_ibss_wq, ieee);
3143 INIT_WORK_RSL(&ieee->associate_complete_wq,
3144 (void *)rtllib_associate_complete_wq, ieee);
3145 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3146 (void *)rtllib_associate_procedure_wq, ieee);
3147 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3148 (void *)rtllib_softmac_scan_wq, ieee);
3149 INIT_DELAYED_WORK_RSL(&ieee->softmac_hint11d_wq,
3150 (void *)rtllib_softmac_hint11d_wq, ieee);
3151 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3152 (void *)rtllib_associate_retry_wq, ieee);
3153 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3156 sema_init(&ieee->wx_sem, 1);
3157 sema_init(&ieee->scan_sem, 1);
3158 sema_init(&ieee->ips_sem, 1);
3160 spin_lock_init(&ieee->mgmt_tx_lock);
3161 spin_lock_init(&ieee->beacon_lock);
3163 tasklet_init(&ieee->ps_task,
3164 (void(*)(unsigned long)) rtllib_sta_ps,
3165 (unsigned long)ieee);
3169 void rtllib_softmac_free(struct rtllib_device *ieee)
3171 down(&ieee->wx_sem);
3172 kfree(ieee->pDot11dInfo);
3173 ieee->pDot11dInfo = NULL;
3174 del_timer_sync(&ieee->associate_timer);
3176 cancel_delayed_work(&ieee->associate_retry_wq);
3177 destroy_workqueue(ieee->wq);
3179 tasklet_kill(&ieee->ps_task);
3182 /********************************************************
3183 * Start of WPA code. *
3184 * this is stolen from the ipw2200 driver *
3185 ********************************************************/
3188 static int rtllib_wpa_enable(struct rtllib_device *ieee, int value)
3190 /* This is called when wpa_supplicant loads and closes the driver
3192 netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling");
3193 ieee->wpa_enabled = value;
3194 memset(ieee->ap_mac_addr, 0, 6);
3199 static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie,
3202 /* make sure WPA is enabled */
3203 rtllib_wpa_enable(ieee, 1);
3205 rtllib_disassociate(ieee);
3209 static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason)
3215 case IEEE_MLME_STA_DEAUTH:
3218 case IEEE_MLME_STA_DISASSOC:
3219 rtllib_disassociate(ieee);
3223 netdev_info(ieee->dev, "Unknown MLME request: %d\n", command);
3231 static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee,
3232 struct ieee_param *param, int plen)
3236 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3237 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3240 if (param->u.wpa_ie.len) {
3241 buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
3246 kfree(ieee->wpa_ie);
3248 ieee->wpa_ie_len = param->u.wpa_ie.len;
3250 kfree(ieee->wpa_ie);
3251 ieee->wpa_ie = NULL;
3252 ieee->wpa_ie_len = 0;
3255 rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3259 #define AUTH_ALG_OPEN_SYSTEM 0x1
3260 #define AUTH_ALG_SHARED_KEY 0x2
3261 #define AUTH_ALG_LEAP 0x4
3262 static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value)
3265 struct rtllib_security sec = {
3266 .flags = SEC_AUTH_MODE,
3269 if (value & AUTH_ALG_SHARED_KEY) {
3270 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3272 ieee->auth_mode = 1;
3273 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
3274 sec.auth_mode = WLAN_AUTH_OPEN;
3276 ieee->auth_mode = 0;
3277 } else if (value & AUTH_ALG_LEAP) {
3278 sec.auth_mode = WLAN_AUTH_LEAP >> 6;
3280 ieee->auth_mode = 2;
3284 if (ieee->set_security)
3285 ieee->set_security(ieee->dev, &sec);
3290 static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value)
3293 unsigned long flags;
3296 case IEEE_PARAM_WPA_ENABLED:
3297 ret = rtllib_wpa_enable(ieee, value);
3300 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3301 ieee->tkip_countermeasures = value;
3304 case IEEE_PARAM_DROP_UNENCRYPTED:
3308 * wpa_supplicant calls set_wpa_enabled when the driver
3309 * is loaded and unloaded, regardless of if WPA is being
3310 * used. No other calls are made which can be used to
3311 * determine if encryption will be used or not prior to
3312 * association being expected. If encryption is not being
3313 * used, drop_unencrypted is set to false, else true -- we
3314 * can use this to determine if the CAP_PRIVACY_ON bit should
3317 struct rtllib_security sec = {
3318 .flags = SEC_ENABLED,
3321 ieee->drop_unencrypted = value;
3322 /* We only change SEC_LEVEL for open mode. Others
3323 * are set by ipw_wpa_set_encryption.
3326 sec.flags |= SEC_LEVEL;
3327 sec.level = SEC_LEVEL_0;
3329 sec.flags |= SEC_LEVEL;
3330 sec.level = SEC_LEVEL_1;
3332 if (ieee->set_security)
3333 ieee->set_security(ieee->dev, &sec);
3337 case IEEE_PARAM_PRIVACY_INVOKED:
3338 ieee->privacy_invoked = value;
3341 case IEEE_PARAM_AUTH_ALGS:
3342 ret = rtllib_wpa_set_auth_algs(ieee, value);
3345 case IEEE_PARAM_IEEE_802_1X:
3346 ieee->ieee802_1x = value;
3348 case IEEE_PARAM_WPAX_SELECT:
3349 spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags);
3350 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags);
3354 netdev_info(ieee->dev, "Unknown WPA param: %d\n", name);
3361 /* implementation borrowed from hostap driver */
3362 static int rtllib_wpa_set_encryption(struct rtllib_device *ieee,
3363 struct ieee_param *param, int param_len,
3367 struct lib80211_crypto_ops *ops;
3368 struct lib80211_crypt_data **crypt;
3370 struct rtllib_security sec = {
3374 param->u.crypt.err = 0;
3375 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3378 (int) ((char *) param->u.crypt.key - (char *) param) +
3379 param->u.crypt.key_len) {
3380 netdev_info(ieee->dev, "Len mismatch %d, %d\n", param_len,
3381 param->u.crypt.key_len);
3384 if (is_broadcast_ether_addr(param->sta_addr)) {
3385 if (param->u.crypt.idx >= NUM_WEP_KEYS)
3387 crypt = &ieee->crypt_info.crypt[param->u.crypt.idx];
3392 if (strcmp(param->u.crypt.alg, "none") == 0) {
3395 sec.level = SEC_LEVEL_0;
3396 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3397 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3402 sec.flags |= SEC_ENABLED;
3404 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3405 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3406 strcmp(param->u.crypt.alg, "R-TKIP"))
3407 goto skip_host_crypt;
3409 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3410 if (ops == NULL && strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3411 request_module("rtllib_crypt_wep");
3412 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3413 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3414 request_module("rtllib_crypt_tkip");
3415 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3416 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3417 request_module("rtllib_crypt_ccmp");
3418 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3421 netdev_info(ieee->dev, "unknown crypto alg '%s'\n",
3422 param->u.crypt.alg);
3423 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3427 if (*crypt == NULL || (*crypt)->ops != ops) {
3428 struct lib80211_crypt_data *new_crypt;
3430 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3432 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
3433 if (new_crypt == NULL) {
3437 new_crypt->ops = ops;
3440 new_crypt->ops->init(param->u.crypt.idx);
3442 if (new_crypt->priv == NULL) {
3444 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3452 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3453 (*crypt)->ops->set_key(param->u.crypt.key,
3454 param->u.crypt.key_len, param->u.crypt.seq,
3455 (*crypt)->priv) < 0) {
3456 netdev_info(ieee->dev, "key setting failed\n");
3457 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3463 if (param->u.crypt.set_tx) {
3464 ieee->crypt_info.tx_keyidx = param->u.crypt.idx;
3465 sec.active_key = param->u.crypt.idx;
3466 sec.flags |= SEC_ACTIVE_KEY;
3468 sec.flags &= ~SEC_ACTIVE_KEY;
3470 if (param->u.crypt.alg != NULL) {
3471 memcpy(sec.keys[param->u.crypt.idx],
3473 param->u.crypt.key_len);
3474 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3475 sec.flags |= (1 << param->u.crypt.idx);
3477 if (strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3478 sec.flags |= SEC_LEVEL;
3479 sec.level = SEC_LEVEL_1;
3480 } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3481 sec.flags |= SEC_LEVEL;
3482 sec.level = SEC_LEVEL_2;
3483 } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3484 sec.flags |= SEC_LEVEL;
3485 sec.level = SEC_LEVEL_3;
3489 if (ieee->set_security)
3490 ieee->set_security(ieee->dev, &sec);
3492 /* Do not reset port if card is in Managed mode since resetting will
3493 * generate new IEEE 802.11 authentication which may end up in looping
3494 * with IEEE 802.1X. If your hardware requires a reset after WEP
3495 * configuration (for example... Prism2), implement the reset_port in
3496 * the callbacks structures used to initialize the 802.11 stack. */
3497 if (ieee->reset_on_keychange &&
3498 ieee->iw_mode != IW_MODE_INFRA &&
3500 ieee->reset_port(ieee->dev)) {
3501 netdev_info(ieee->dev, "reset_port failed\n");
3502 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3509 inline struct sk_buff *rtllib_disauth_skb(struct rtllib_network *beacon,
3510 struct rtllib_device *ieee, u16 asRsn)
3512 struct sk_buff *skb;
3513 struct rtllib_disauth *disauth;
3514 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3516 skb = dev_alloc_skb(len);
3520 skb_reserve(skb, ieee->tx_headroom);
3522 disauth = (struct rtllib_disauth *) skb_put(skb,
3523 sizeof(struct rtllib_disauth));
3524 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3525 disauth->header.duration_id = 0;
3527 memcpy(disauth->header.addr1, beacon->bssid, ETH_ALEN);
3528 memcpy(disauth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3529 memcpy(disauth->header.addr3, beacon->bssid, ETH_ALEN);
3531 disauth->reason = cpu_to_le16(asRsn);
3535 inline struct sk_buff *rtllib_disassociate_skb(struct rtllib_network *beacon,
3536 struct rtllib_device *ieee, u16 asRsn)
3538 struct sk_buff *skb;
3539 struct rtllib_disassoc *disass;
3540 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3542 skb = dev_alloc_skb(len);
3547 skb_reserve(skb, ieee->tx_headroom);
3549 disass = (struct rtllib_disassoc *) skb_put(skb,
3550 sizeof(struct rtllib_disassoc));
3551 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3552 disass->header.duration_id = 0;
3554 memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
3555 memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3556 memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
3558 disass->reason = cpu_to_le16(asRsn);
3562 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3564 struct rtllib_network *beacon = &ieee->current_network;
3565 struct sk_buff *skb;
3568 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3570 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3573 softmac_mgmt_xmit(skb, ieee);
3576 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3578 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3579 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3580 int wpa_ie_len = ieee->wpa_ie_len;
3581 struct lib80211_crypt_data *crypt;
3584 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3585 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3586 || (ieee->host_encrypt && crypt && crypt->ops &&
3587 (0 == strcmp(crypt->ops->name, "R-WEP")));
3590 if (encrypt && (wpa_ie_len == 0)) {
3592 } else if ((wpa_ie_len != 0)) {
3593 if (((ieee->wpa_ie[0] == 0xdd) &&
3594 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3595 ((ieee->wpa_ie[0] == 0x30) &&
3596 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3597 return SEC_ALG_CCMP;
3599 return SEC_ALG_TKIP;
3601 return SEC_ALG_NONE;
3605 int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p,
3608 struct ieee_param *param;
3611 down(&ieee->wx_sem);
3613 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3618 param = memdup_user(p->pointer, p->length);
3619 if (IS_ERR(param)) {
3620 ret = PTR_ERR(param);
3624 switch (param->cmd) {
3625 case IEEE_CMD_SET_WPA_PARAM:
3626 ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name,
3627 param->u.wpa_param.value);
3630 case IEEE_CMD_SET_WPA_IE:
3631 ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length);
3634 case IEEE_CMD_SET_ENCRYPTION:
3635 ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0);
3639 ret = rtllib_wpa_mlme(ieee, param->u.mlme.command,
3640 param->u.mlme.reason_code);
3644 netdev_info(ieee->dev, "Unknown WPA supplicant request: %d\n",
3650 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3659 EXPORT_SYMBOL(rtllib_wpa_supplicant_ioctl);
3661 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3665 bool bFilterOutNonAssociatedBSSID = false;
3667 rtllib->state = RTLLIB_NOLINK;
3669 for (i = 0; i < 6; i++)
3670 rtllib->current_network.bssid[i] = 0x55;
3672 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3673 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3674 rtllib->current_network.bssid);
3675 OpMode = RT_OP_MODE_NO_LINK;
3676 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3677 rtllib_stop_send_beacons(rtllib);
3679 bFilterOutNonAssociatedBSSID = false;
3680 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3681 (u8 *)(&bFilterOutNonAssociatedBSSID));
3682 notify_wx_assoc_event(rtllib);
3686 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, u8 *asSta,
3692 RemovePeerTS(rtllib, asSta);
3694 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3695 rtllib->state = RTLLIB_NOLINK;
3697 for (i = 0; i < 6; i++)
3698 rtllib->current_network.bssid[i] = 0x22;
3699 OpMode = RT_OP_MODE_NO_LINK;
3700 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3701 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3703 rtllib_disassociate(rtllib);
3705 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3706 rtllib->current_network.bssid);
3713 rtllib_MgntDisconnectAP(
3714 struct rtllib_device *rtllib,
3718 bool bFilterOutNonAssociatedBSSID = false;
3720 bFilterOutNonAssociatedBSSID = false;
3721 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3722 (u8 *)(&bFilterOutNonAssociatedBSSID));
3723 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3726 rtllib->state = RTLLIB_NOLINK;
3729 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3731 if (rtllib->ps != RTLLIB_PS_DISABLED)
3732 rtllib->sta_wake_up(rtllib->dev);
3734 if (rtllib->state == RTLLIB_LINKED) {
3735 if (rtllib->iw_mode == IW_MODE_ADHOC)
3736 rtllib_MgntDisconnectIBSS(rtllib);
3737 if (rtllib->iw_mode == IW_MODE_INFRA)
3738 rtllib_MgntDisconnectAP(rtllib, asRsn);
3744 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3746 void notify_wx_assoc_event(struct rtllib_device *ieee)
3748 union iwreq_data wrqu;
3750 if (ieee->cannot_notify)
3753 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3754 if (ieee->state == RTLLIB_LINKED)
3755 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3759 netdev_info(ieee->dev, "%s(): Tell user space disconnected\n",
3761 eth_zero_addr(wrqu.ap_addr.sa_data);
3763 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3765 EXPORT_SYMBOL(notify_wx_assoc_event);