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>
23 #include <linux/ieee80211.h>
26 static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
29 static short rtllib_is_54g(struct rtllib_network *net)
31 return (net->rates_ex_len > 0) || (net->rates_len > 4);
34 /* returns the total length needed for placing the RATE MFIE
35 * tag and the EXTENDED RATE MFIE tag if needed.
36 * It encludes two bytes per tag for the tag itself and its len
38 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
40 unsigned int rate_len = 0;
42 if (ieee->modulation & RTLLIB_CCK_MODULATION)
43 rate_len = RTLLIB_CCK_RATE_LEN + 2;
45 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
47 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
52 /* place the MFIE rate, tag to the memory (double) pointed.
53 * Then it updates the pointer so that
54 * it points after the new MFIE tag added.
56 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
60 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
61 *tag++ = MFIE_TYPE_RATES;
63 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
64 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
65 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
66 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
69 /* 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
97 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
101 *tag++ = MFIE_TYPE_GENERIC;
113 static void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
117 *tag++ = MFIE_TYPE_GENERIC;
128 netdev_alert(ieee->dev, "This is enable turbo mode IE process\n");
131 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
135 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 void init_mgmt_queue(struct rtllib_device *ieee)
150 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
155 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
162 for (i = 0; i < ieee->current_network.rates_len; i++) {
163 BasicRate = ieee->current_network.rates[i]&0x7F;
164 if (!rtllib_is_cck_rate(BasicRate)) {
165 if (QueryRate == 0) {
166 QueryRate = BasicRate;
168 if (BasicRate < QueryRate)
169 QueryRate = BasicRate;
174 if (QueryRate == 0) {
176 netdev_info(ieee->dev, "No BasicRate found!!\n");
181 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
183 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
186 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
189 rate = ieee->basic_rate & 0x7f;
192 if (ieee->mode == IEEE_A ||
193 ieee->mode == IEEE_N_5G ||
194 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
203 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
206 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
207 struct rtllib_hdr_3addr *header =
208 (struct rtllib_hdr_3addr *) skb->data;
210 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
212 spin_lock_irqsave(&ieee->lock, flags);
214 /* called with 2nd param 0, no mgmt lock required */
215 rtllib_sta_wakeup(ieee, 0);
217 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
218 tcb_desc->queue_index = BEACON_QUEUE;
220 tcb_desc->queue_index = MGNT_QUEUE;
222 if (ieee->disable_mgnt_queue)
223 tcb_desc->queue_index = HIGH_QUEUE;
225 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
226 tcb_desc->RATRIndex = 7;
227 tcb_desc->bTxDisableRateFallBack = 1;
228 tcb_desc->bTxUseDriverAssingedRate = 1;
230 if (ieee->queue_stop) {
231 enqueue_mgmt(ieee, skb);
233 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
235 if (ieee->seq_ctrl[0] == 0xFFF)
236 ieee->seq_ctrl[0] = 0;
240 /* avoid watchdog triggers */
241 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
245 spin_unlock_irqrestore(&ieee->lock, flags);
247 spin_unlock_irqrestore(&ieee->lock, flags);
248 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
250 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
252 if (ieee->seq_ctrl[0] == 0xFFF)
253 ieee->seq_ctrl[0] = 0;
257 /* check whether the managed packet queued greater than 5 */
258 if (!ieee->check_nic_enough_desc(ieee->dev,
259 tcb_desc->queue_index) ||
260 skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) ||
262 /* insert the skb packet to the management queue
264 * as for the completion function, it does not need
265 * to check it any more.
267 netdev_info(ieee->dev,
268 "%s():insert to waitqueue, queue_index:%d!\n",
269 __func__, tcb_desc->queue_index);
270 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
273 ieee->softmac_hard_start_xmit(skb, ieee->dev);
275 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
280 softmac_ps_mgmt_xmit(struct sk_buff *skb,
281 struct rtllib_device *ieee)
283 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
284 struct rtllib_hdr_3addr *header =
285 (struct rtllib_hdr_3addr *) skb->data;
287 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
289 fc = le16_to_cpu(header->frame_ctl);
290 type = WLAN_FC_GET_TYPE(fc);
291 stype = WLAN_FC_GET_STYPE(fc);
294 if (stype != RTLLIB_STYPE_PSPOLL)
295 tcb_desc->queue_index = MGNT_QUEUE;
297 tcb_desc->queue_index = HIGH_QUEUE;
299 if (ieee->disable_mgnt_queue)
300 tcb_desc->queue_index = HIGH_QUEUE;
303 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
304 tcb_desc->RATRIndex = 7;
305 tcb_desc->bTxDisableRateFallBack = 1;
306 tcb_desc->bTxUseDriverAssingedRate = 1;
308 if (type != RTLLIB_FTYPE_CTL) {
309 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
311 if (ieee->seq_ctrl[0] == 0xFFF)
312 ieee->seq_ctrl[0] = 0;
317 /* avoid watchdog triggers */
318 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
322 if (type != RTLLIB_FTYPE_CTL) {
323 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
325 if (ieee->seq_ctrl[0] == 0xFFF)
326 ieee->seq_ctrl[0] = 0;
330 ieee->softmac_hard_start_xmit(skb, ieee->dev);
335 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
337 unsigned int len, rate_len;
340 struct rtllib_probe_request *req;
342 len = ieee->current_network.ssid_len;
344 rate_len = rtllib_MFIE_rate_len(ieee);
346 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
347 2 + len + rate_len + ieee->tx_headroom);
352 skb_reserve(skb, ieee->tx_headroom);
354 req = skb_put(skb, sizeof(struct rtllib_probe_request));
355 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
356 req->header.duration_id = 0;
358 eth_broadcast_addr(req->header.addr1);
359 ether_addr_copy(req->header.addr2, ieee->dev->dev_addr);
360 eth_broadcast_addr(req->header.addr3);
362 tag = skb_put(skb, len + 2 + rate_len);
364 *tag++ = MFIE_TYPE_SSID;
366 memcpy(tag, ieee->current_network.ssid, len);
369 rtllib_MFIE_Brate(ieee, &tag);
370 rtllib_MFIE_Grate(ieee, &tag);
375 static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
377 static void rtllib_send_beacon(struct rtllib_device *ieee)
383 skb = rtllib_get_beacon_(ieee);
386 softmac_mgmt_xmit(skb, ieee);
387 ieee->softmac_stats.tx_beacons++;
390 if (ieee->beacon_txing && ieee->ieee_up)
391 mod_timer(&ieee->beacon_timer, jiffies +
392 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
396 static void rtllib_send_beacon_cb(unsigned long _ieee)
398 struct rtllib_device *ieee =
399 (struct rtllib_device *) _ieee;
402 spin_lock_irqsave(&ieee->beacon_lock, flags);
403 rtllib_send_beacon(ieee);
404 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
407 /* Enables network monitor mode, all rx packets will be received. */
408 void rtllib_EnableNetMonitorMode(struct net_device *dev,
411 struct rtllib_device *ieee = netdev_priv_rsl(dev);
413 netdev_info(dev, "========>Enter Monitor Mode\n");
415 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
419 /* Disables network monitor mode. Only packets destinated to
420 * us will be received.
422 void rtllib_DisableNetMonitorMode(struct net_device *dev,
425 struct rtllib_device *ieee = netdev_priv_rsl(dev);
427 netdev_info(dev, "========>Exit Monitor Mode\n");
429 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
433 /* Enables the specialized promiscuous mode required by Intel.
434 * In this mode, Intel intends to hear traffics from/to other STAs in the
435 * same BSS. Therefore we don't have to disable checking BSSID and we only need
436 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
437 * packets from other STA.
439 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
442 bool bFilterOutNonAssociatedBSSID = false;
444 struct rtllib_device *ieee = netdev_priv_rsl(dev);
446 netdev_info(dev, "========>Enter Intel Promiscuous Mode\n");
448 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
449 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
450 (u8 *)&bFilterOutNonAssociatedBSSID);
452 ieee->bNetPromiscuousMode = true;
454 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
457 /* Disables the specialized promiscuous mode required by Intel.
458 * See MgntEnableIntelPromiscuousMode for detail.
460 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
463 bool bFilterOutNonAssociatedBSSID = true;
465 struct rtllib_device *ieee = netdev_priv_rsl(dev);
467 netdev_info(dev, "========>Exit Intel Promiscuous Mode\n");
469 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
470 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
471 (u8 *)&bFilterOutNonAssociatedBSSID);
473 ieee->bNetPromiscuousMode = false;
475 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
477 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
481 skb = rtllib_probe_req(ieee);
483 softmac_mgmt_xmit(skb, ieee);
484 ieee->softmac_stats.tx_probe_rq++;
489 static void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
491 if (ieee->active_scan && (ieee->softmac_features &
492 IEEE_SOFTMAC_PROBERQ)) {
493 rtllib_send_probe(ieee, 0);
494 rtllib_send_probe(ieee, 0);
498 static void rtllib_update_active_chan_map(struct rtllib_device *ieee)
500 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
501 MAX_CHANNEL_NUMBER+1);
504 /* this performs syncro scan blocking the caller until all channels
505 * in the allowed channel map has been checked.
507 static void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
509 union iwreq_data wrqu;
512 rtllib_update_active_chan_map(ieee);
514 ieee->be_scan_inprogress = true;
516 mutex_lock(&ieee->scan_mutex);
521 if (ch > MAX_CHANNEL_NUMBER)
522 goto out; /* scan completed */
523 } while (!ieee->active_channel_map[ch]);
525 /* this function can be called in two situations
526 * 1- We have switched to ad-hoc mode and we are
527 * performing a complete syncro scan before conclude
528 * there are no interesting cell and to create a
529 * new one. In this case the link state is
530 * RTLLIB_NOLINK until we found an interesting cell.
531 * If so the ieee8021_new_net, called by the RX path
532 * will set the state to RTLLIB_LINKED, so we stop
534 * 2- We are linked and the root uses run iwlist scan.
535 * So we switch to RTLLIB_LINKED_SCANNING to remember
536 * that we are still logically linked (not interested in
537 * new network events, despite for updating the net list,
538 * but we are temporarly 'unlinked' as the driver shall
539 * not filter RX frames and the channel is changing.
540 * So the only situation in which are interested is to check
541 * if the state become LINKED because of the #1 situation
544 if (ieee->state == RTLLIB_LINKED)
546 if (ieee->sync_scan_hurryup) {
547 netdev_info(ieee->dev,
548 "============>sync_scan_hurryup out\n");
552 ieee->set_chan(ieee->dev, ch);
553 if (ieee->active_channel_map[ch] == 1)
554 rtllib_send_probe_requests(ieee, 0);
556 /* this prevent excessive time wait when we
557 * need to wait for a syncro scan to end..
559 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
562 ieee->actscanning = false;
563 ieee->sync_scan_hurryup = 0;
565 if (ieee->state >= RTLLIB_LINKED) {
566 if (IS_DOT11D_ENABLE(ieee))
567 DOT11D_ScanComplete(ieee);
569 mutex_unlock(&ieee->scan_mutex);
571 ieee->be_scan_inprogress = false;
573 memset(&wrqu, 0, sizeof(wrqu));
574 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
577 static void rtllib_softmac_scan_wq(void *data)
579 struct rtllib_device *ieee = container_of_dwork_rsl(data,
580 struct rtllib_device, softmac_scan_wq);
581 u8 last_channel = ieee->current_network.channel;
583 rtllib_update_active_chan_map(ieee);
587 if (rtllib_act_scanning(ieee, true))
590 mutex_lock(&ieee->scan_mutex);
592 if (ieee->eRFPowerState == eRfOff) {
593 netdev_info(ieee->dev,
594 "======>%s():rf state is eRfOff, return\n",
600 ieee->current_network.channel =
601 (ieee->current_network.channel + 1) %
603 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
604 if (!ieee->active_channel_map[ieee->current_network.channel])
605 ieee->current_network.channel = 6;
606 goto out; /* no good chans */
608 } while (!ieee->active_channel_map[ieee->current_network.channel]);
610 if (ieee->scanning_continue == 0)
613 ieee->set_chan(ieee->dev, ieee->current_network.channel);
615 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
616 rtllib_send_probe_requests(ieee, 0);
618 schedule_delayed_work(&ieee->softmac_scan_wq,
619 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
621 mutex_unlock(&ieee->scan_mutex);
625 if (IS_DOT11D_ENABLE(ieee))
626 DOT11D_ScanComplete(ieee);
627 ieee->current_network.channel = last_channel;
630 ieee->actscanning = false;
631 ieee->scan_watch_dog = 0;
632 ieee->scanning_continue = 0;
633 mutex_unlock(&ieee->scan_mutex);
638 static void rtllib_beacons_start(struct rtllib_device *ieee)
642 spin_lock_irqsave(&ieee->beacon_lock, flags);
644 ieee->beacon_txing = 1;
645 rtllib_send_beacon(ieee);
647 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
650 static void rtllib_beacons_stop(struct rtllib_device *ieee)
654 spin_lock_irqsave(&ieee->beacon_lock, flags);
656 ieee->beacon_txing = 0;
657 del_timer_sync(&ieee->beacon_timer);
659 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
664 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
666 if (ieee->stop_send_beacons)
667 ieee->stop_send_beacons(ieee->dev);
668 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
669 rtllib_beacons_stop(ieee);
671 EXPORT_SYMBOL(rtllib_stop_send_beacons);
674 void rtllib_start_send_beacons(struct rtllib_device *ieee)
676 if (ieee->start_send_beacons)
677 ieee->start_send_beacons(ieee->dev);
678 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
679 rtllib_beacons_start(ieee);
681 EXPORT_SYMBOL(rtllib_start_send_beacons);
684 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
686 mutex_lock(&ieee->scan_mutex);
687 ieee->scan_watch_dog = 0;
688 if (ieee->scanning_continue == 1) {
689 ieee->scanning_continue = 0;
690 ieee->actscanning = false;
692 cancel_delayed_work_sync(&ieee->softmac_scan_wq);
695 mutex_unlock(&ieee->scan_mutex);
698 void rtllib_stop_scan(struct rtllib_device *ieee)
700 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
701 rtllib_softmac_stop_scan(ieee);
703 if (ieee->rtllib_stop_hw_scan)
704 ieee->rtllib_stop_hw_scan(ieee->dev);
707 EXPORT_SYMBOL(rtllib_stop_scan);
709 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
711 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
712 ieee->sync_scan_hurryup = 1;
714 if (ieee->rtllib_stop_hw_scan)
715 ieee->rtllib_stop_hw_scan(ieee->dev);
718 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
720 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
722 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
724 return ieee->be_scan_inprogress;
726 return ieee->actscanning || ieee->be_scan_inprogress;
728 return test_bit(STATUS_SCANNING, &ieee->status);
731 EXPORT_SYMBOL(rtllib_act_scanning);
733 /* called with ieee->lock held */
734 static void rtllib_start_scan(struct rtllib_device *ieee)
736 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
737 if (ieee->rtllib_ips_leave_wq != NULL)
738 ieee->rtllib_ips_leave_wq(ieee->dev);
740 if (IS_DOT11D_ENABLE(ieee)) {
741 if (IS_COUNTRY_IE_VALID(ieee))
742 RESET_CIE_WATCHDOG(ieee);
744 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
745 if (ieee->scanning_continue == 0) {
746 ieee->actscanning = true;
747 ieee->scanning_continue = 1;
748 schedule_delayed_work(&ieee->softmac_scan_wq, 0);
751 if (ieee->rtllib_start_hw_scan)
752 ieee->rtllib_start_hw_scan(ieee->dev);
756 /* called with wx_mutex held */
757 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
759 if (IS_DOT11D_ENABLE(ieee)) {
760 if (IS_COUNTRY_IE_VALID(ieee))
761 RESET_CIE_WATCHDOG(ieee);
763 ieee->sync_scan_hurryup = 0;
764 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
765 rtllib_softmac_scan_syncro(ieee, is_mesh);
767 if (ieee->rtllib_start_hw_scan)
768 ieee->rtllib_start_hw_scan(ieee->dev);
771 EXPORT_SYMBOL(rtllib_start_scan_syncro);
773 static inline struct sk_buff *
774 rtllib_authentication_req(struct rtllib_network *beacon,
775 struct rtllib_device *ieee,
776 int challengelen, u8 *daddr)
779 struct rtllib_authentication *auth;
782 len = sizeof(struct rtllib_authentication) + challengelen +
783 ieee->tx_headroom + 4;
784 skb = dev_alloc_skb(len);
789 skb_reserve(skb, ieee->tx_headroom);
791 auth = skb_put(skb, sizeof(struct rtllib_authentication));
793 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
795 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
797 auth->header.duration_id = cpu_to_le16(0x013a);
798 ether_addr_copy(auth->header.addr1, beacon->bssid);
799 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
800 ether_addr_copy(auth->header.addr3, beacon->bssid);
801 if (ieee->auth_mode == 0)
802 auth->algorithm = WLAN_AUTH_OPEN;
803 else if (ieee->auth_mode == 1)
804 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
805 else if (ieee->auth_mode == 2)
806 auth->algorithm = WLAN_AUTH_OPEN;
807 auth->transaction = cpu_to_le16(ieee->associate_seq);
808 ieee->associate_seq++;
810 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
815 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee,
820 struct rtllib_probe_response *beacon_buf;
821 struct sk_buff *skb = NULL;
823 int atim_len, erp_len;
824 struct lib80211_crypt_data *crypt;
826 char *ssid = ieee->current_network.ssid;
827 int ssid_len = ieee->current_network.ssid_len;
828 int rate_len = ieee->current_network.rates_len+2;
829 int rate_ex_len = ieee->current_network.rates_ex_len;
830 int wpa_ie_len = ieee->wpa_ie_len;
831 u8 erpinfo_content = 0;
833 u8 *tmp_ht_cap_buf = NULL;
834 u8 tmp_ht_cap_len = 0;
835 u8 *tmp_ht_info_buf = NULL;
836 u8 tmp_ht_info_len = 0;
837 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
838 u8 *tmp_generic_ie_buf = NULL;
839 u8 tmp_generic_ie_len = 0;
844 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
849 if ((ieee->current_network.mode == IEEE_G) ||
850 (ieee->current_network.mode == IEEE_N_24G &&
851 ieee->pHTInfo->bCurSuppCCK)) {
854 if (ieee->current_network.buseprotection)
855 erpinfo_content |= ERP_UseProtection;
859 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
860 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
861 ((strcmp(crypt->ops->name, "R-WEP") == 0 || wpa_ie_len));
862 if (ieee->pHTInfo->bCurrentHTSupport) {
863 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
864 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
865 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
866 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
867 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
868 &tmp_ht_cap_len, encrypt, false);
869 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
872 if (pHTInfo->bRegRT2RTAggregation) {
873 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
875 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
876 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
877 &tmp_generic_ie_len);
881 beacon_size = sizeof(struct rtllib_probe_response)+2+
882 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
883 + wpa_ie_len + ieee->tx_headroom;
884 skb = dev_alloc_skb(beacon_size);
888 skb_reserve(skb, ieee->tx_headroom);
890 beacon_buf = skb_put(skb, (beacon_size - ieee->tx_headroom));
891 ether_addr_copy(beacon_buf->header.addr1, dest);
892 ether_addr_copy(beacon_buf->header.addr2, ieee->dev->dev_addr);
893 ether_addr_copy(beacon_buf->header.addr3, ieee->current_network.bssid);
895 beacon_buf->header.duration_id = 0;
896 beacon_buf->beacon_interval =
897 cpu_to_le16(ieee->current_network.beacon_interval);
898 beacon_buf->capability =
899 cpu_to_le16(ieee->current_network.capability &
900 WLAN_CAPABILITY_IBSS);
901 beacon_buf->capability |=
902 cpu_to_le16(ieee->current_network.capability &
903 WLAN_CAPABILITY_SHORT_PREAMBLE);
905 if (ieee->short_slot && (ieee->current_network.capability &
906 WLAN_CAPABILITY_SHORT_SLOT_TIME))
907 beacon_buf->capability |=
908 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
910 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
912 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
915 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
916 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
917 beacon_buf->info_element[0].len = ssid_len;
919 tag = (u8 *) beacon_buf->info_element[0].data;
921 memcpy(tag, ssid, ssid_len);
925 *(tag++) = MFIE_TYPE_RATES;
926 *(tag++) = rate_len-2;
927 memcpy(tag, ieee->current_network.rates, rate_len-2);
930 *(tag++) = MFIE_TYPE_DS_SET;
932 *(tag++) = ieee->current_network.channel;
936 *(tag++) = MFIE_TYPE_IBSS_SET;
938 val16 = ieee->current_network.atim_window;
939 memcpy((u8 *)tag, (u8 *)&val16, 2);
944 *(tag++) = MFIE_TYPE_ERP;
946 *(tag++) = erpinfo_content;
949 *(tag++) = MFIE_TYPE_RATES_EX;
950 *(tag++) = rate_ex_len-2;
951 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
952 tag += rate_ex_len-2;
956 if (ieee->iw_mode == IW_MODE_ADHOC)
957 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
958 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
959 tag += ieee->wpa_ie_len;
964 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
969 struct lib80211_crypt_data *crypt;
970 struct rtllib_assoc_response_frame *assoc;
973 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
974 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
977 skb = dev_alloc_skb(len);
982 skb_reserve(skb, ieee->tx_headroom);
984 assoc = skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
986 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
987 ether_addr_copy(assoc->header.addr1, dest);
988 ether_addr_copy(assoc->header.addr3, ieee->dev->dev_addr);
989 ether_addr_copy(assoc->header.addr2, ieee->dev->dev_addr);
990 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
991 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
994 if (ieee->short_slot)
996 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
998 if (ieee->host_encrypt)
999 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1003 encrypt = (crypt && crypt->ops);
1006 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1009 assoc->aid = cpu_to_le16(ieee->assoc_id);
1010 if (ieee->assoc_id == 0x2007)
1015 tag = skb_put(skb, rate_len);
1016 rtllib_MFIE_Brate(ieee, &tag);
1017 rtllib_MFIE_Grate(ieee, &tag);
1022 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1025 struct sk_buff *skb = NULL;
1026 struct rtllib_authentication *auth;
1027 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1029 skb = dev_alloc_skb(len);
1033 skb->len = sizeof(struct rtllib_authentication);
1035 skb_reserve(skb, ieee->tx_headroom);
1037 auth = skb_put(skb, sizeof(struct rtllib_authentication));
1039 auth->status = cpu_to_le16(status);
1040 auth->transaction = cpu_to_le16(2);
1041 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1043 ether_addr_copy(auth->header.addr3, ieee->dev->dev_addr);
1044 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
1045 ether_addr_copy(auth->header.addr1, dest);
1046 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1052 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1054 struct sk_buff *skb;
1055 struct rtllib_hdr_3addr *hdr;
1057 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1061 skb_reserve(skb, ieee->tx_headroom);
1063 hdr = skb_put(skb, sizeof(struct rtllib_hdr_3addr));
1065 ether_addr_copy(hdr->addr1, ieee->current_network.bssid);
1066 ether_addr_copy(hdr->addr2, ieee->dev->dev_addr);
1067 ether_addr_copy(hdr->addr3, ieee->current_network.bssid);
1069 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1070 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1071 (pwr ? RTLLIB_FCTL_PM : 0));
1078 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1080 struct sk_buff *skb;
1081 struct rtllib_pspoll_hdr *hdr;
1083 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1087 skb_reserve(skb, ieee->tx_headroom);
1089 hdr = skb_put(skb, sizeof(struct rtllib_pspoll_hdr));
1091 ether_addr_copy(hdr->bssid, ieee->current_network.bssid);
1092 ether_addr_copy(hdr->ta, ieee->dev->dev_addr);
1094 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1095 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1102 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1104 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1107 softmac_mgmt_xmit(buf, ieee);
1111 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1113 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1116 softmac_mgmt_xmit(buf, ieee);
1120 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1122 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1125 softmac_mgmt_xmit(buf, ieee);
1129 static inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1134 if ((ieee->PMKIDList[i].bUsed) &&
1135 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1138 } while (i < NUM_PMKID_CACHE);
1140 if (i == NUM_PMKID_CACHE)
1145 static inline struct sk_buff *
1146 rtllib_association_req(struct rtllib_network *beacon,
1147 struct rtllib_device *ieee)
1149 struct sk_buff *skb;
1150 struct rtllib_assoc_request_frame *hdr;
1153 u8 *ht_cap_buf = NULL;
1155 u8 *realtek_ie_buf = NULL;
1156 u8 realtek_ie_len = 0;
1157 int wpa_ie_len = ieee->wpa_ie_len;
1158 int wps_ie_len = ieee->wps_ie_len;
1159 unsigned int ckip_ie_len = 0;
1160 unsigned int ccxrm_ie_len = 0;
1161 unsigned int cxvernum_ie_len = 0;
1162 struct lib80211_crypt_data *crypt;
1166 unsigned int rate_len = (beacon->rates_len ?
1167 (beacon->rates_len + 2) : 0) +
1168 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1171 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1172 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1176 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1178 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1179 ((strcmp(crypt->ops->name, "R-WEP") == 0 ||
1184 if ((ieee->rtllib_ap_sec_type &&
1185 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1186 ieee->bForcedBgMode) {
1187 ieee->pHTInfo->bEnableHT = 0;
1188 ieee->mode = WIRELESS_MODE_G;
1191 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1192 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1193 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1194 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1196 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1197 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1199 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1200 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1205 if (beacon->bCkipSupported)
1207 if (beacon->bCcxRmEnable)
1209 if (beacon->BssCcxVerNumber >= 2)
1210 cxvernum_ie_len = 5+2;
1212 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1213 if (PMKCacheIdx >= 0) {
1215 netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n",
1218 len = sizeof(struct rtllib_assoc_request_frame) + 2
1230 + ieee->tx_headroom;
1232 skb = dev_alloc_skb(len);
1237 skb_reserve(skb, ieee->tx_headroom);
1239 hdr = skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1242 hdr->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_REQ);
1243 hdr->header.duration_id = cpu_to_le16(37);
1244 ether_addr_copy(hdr->header.addr1, beacon->bssid);
1245 ether_addr_copy(hdr->header.addr2, ieee->dev->dev_addr);
1246 ether_addr_copy(hdr->header.addr3, beacon->bssid);
1248 ether_addr_copy(ieee->ap_mac_addr, beacon->bssid);
1250 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1251 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1252 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1254 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1255 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1257 if (ieee->short_slot &&
1258 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1259 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1262 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1264 hdr->info_element[0].id = MFIE_TYPE_SSID;
1266 hdr->info_element[0].len = beacon->ssid_len;
1267 skb_put_data(skb, beacon->ssid, beacon->ssid_len);
1269 tag = skb_put(skb, rate_len);
1271 if (beacon->rates_len) {
1272 *tag++ = MFIE_TYPE_RATES;
1273 *tag++ = beacon->rates_len;
1274 for (i = 0; i < beacon->rates_len; i++)
1275 *tag++ = beacon->rates[i];
1278 if (beacon->rates_ex_len) {
1279 *tag++ = MFIE_TYPE_RATES_EX;
1280 *tag++ = beacon->rates_ex_len;
1281 for (i = 0; i < beacon->rates_ex_len; i++)
1282 *tag++ = beacon->rates_ex[i];
1285 if (beacon->bCkipSupported) {
1286 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1287 u8 CcxAironetBuf[30];
1288 struct octet_string osCcxAironetIE;
1290 memset(CcxAironetBuf, 0, 30);
1291 osCcxAironetIE.Octet = CcxAironetBuf;
1292 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1293 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1294 sizeof(AironetIeOui));
1296 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1297 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1298 tag = skb_put(skb, ckip_ie_len);
1299 *tag++ = MFIE_TYPE_AIRONET;
1300 *tag++ = osCcxAironetIE.Length;
1301 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1302 tag += osCcxAironetIE.Length;
1305 if (beacon->bCcxRmEnable) {
1306 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1308 struct octet_string osCcxRmCap;
1310 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1311 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1312 tag = skb_put(skb, ccxrm_ie_len);
1313 *tag++ = MFIE_TYPE_GENERIC;
1314 *tag++ = osCcxRmCap.Length;
1315 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1316 tag += osCcxRmCap.Length;
1319 if (beacon->BssCcxVerNumber >= 2) {
1320 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1321 struct octet_string osCcxVerNum;
1323 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1324 osCcxVerNum.Octet = CcxVerNumBuf;
1325 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1326 tag = skb_put(skb, cxvernum_ie_len);
1327 *tag++ = MFIE_TYPE_GENERIC;
1328 *tag++ = osCcxVerNum.Length;
1329 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1330 tag += osCcxVerNum.Length;
1332 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1333 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1334 tag = skb_put(skb, ht_cap_len);
1335 *tag++ = MFIE_TYPE_HT_CAP;
1336 *tag++ = ht_cap_len - 2;
1337 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1338 tag += ht_cap_len - 2;
1343 skb_put_data(skb, ieee->wpa_ie, ieee->wpa_ie_len);
1345 if (PMKCacheIdx >= 0) {
1346 tag = skb_put(skb, 18);
1349 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1354 tag = skb_put(skb, wmm_info_len);
1355 rtllib_WMM_Info(ieee, &tag);
1358 if (wps_ie_len && ieee->wps_ie) {
1359 skb_put_data(skb, ieee->wps_ie, wps_ie_len);
1362 if (turbo_info_len) {
1363 tag = skb_put(skb, turbo_info_len);
1364 rtllib_TURBO_Info(ieee, &tag);
1367 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1368 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1369 tag = skb_put(skb, ht_cap_len);
1370 *tag++ = MFIE_TYPE_GENERIC;
1371 *tag++ = ht_cap_len - 2;
1372 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1373 tag += ht_cap_len - 2;
1376 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1377 tag = skb_put(skb, realtek_ie_len);
1378 *tag++ = MFIE_TYPE_GENERIC;
1379 *tag++ = realtek_ie_len - 2;
1380 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1384 kfree(ieee->assocreq_ies);
1385 ieee->assocreq_ies = NULL;
1386 ies = &(hdr->info_element[0].id);
1387 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1388 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1389 if (ieee->assocreq_ies)
1390 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1392 netdev_info(ieee->dev,
1393 "%s()Warning: can't alloc memory for assocreq_ies\n",
1395 ieee->assocreq_ies_len = 0;
1400 static void rtllib_associate_abort(struct rtllib_device *ieee)
1402 unsigned long flags;
1404 spin_lock_irqsave(&ieee->lock, flags);
1406 ieee->associate_seq++;
1408 /* don't scan, and avoid to have the RX path possibily
1409 * try again to associate. Even do not react to AUTH or
1410 * ASSOC response. Just wait for the retry wq to be scheduled.
1411 * Here we will check if there are good nets to associate
1412 * with, so we retry or just get back to NO_LINK and scanning
1414 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1415 netdev_dbg(ieee->dev, "Authentication failed\n");
1416 ieee->softmac_stats.no_auth_rs++;
1418 netdev_dbg(ieee->dev, "Association failed\n");
1419 ieee->softmac_stats.no_ass_rs++;
1422 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1424 schedule_delayed_work(&ieee->associate_retry_wq,
1425 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1427 spin_unlock_irqrestore(&ieee->lock, flags);
1430 static void rtllib_associate_abort_cb(unsigned long dev)
1432 rtllib_associate_abort((struct rtllib_device *) dev);
1435 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr)
1437 struct rtllib_network *beacon = &ieee->current_network;
1438 struct sk_buff *skb;
1440 netdev_dbg(ieee->dev, "Stopping scan\n");
1442 ieee->softmac_stats.tx_auth_rq++;
1444 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1447 rtllib_associate_abort(ieee);
1449 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING;
1450 netdev_dbg(ieee->dev, "Sending authentication request\n");
1451 softmac_mgmt_xmit(skb, ieee);
1452 if (!timer_pending(&ieee->associate_timer)) {
1453 ieee->associate_timer.expires = jiffies + (HZ / 2);
1454 add_timer(&ieee->associate_timer);
1459 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge,
1463 struct sk_buff *skb;
1464 struct rtllib_network *beacon = &ieee->current_network;
1466 ieee->associate_seq++;
1467 ieee->softmac_stats.tx_auth_rq++;
1469 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1472 rtllib_associate_abort(ieee);
1474 c = skb_put(skb, chlen+2);
1475 *(c++) = MFIE_TYPE_CHALLENGE;
1477 memcpy(c, challenge, chlen);
1479 netdev_dbg(ieee->dev,
1480 "Sending authentication challenge response\n");
1482 rtllib_encrypt_fragment(ieee, skb,
1483 sizeof(struct rtllib_hdr_3addr));
1485 softmac_mgmt_xmit(skb, ieee);
1486 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1491 static void rtllib_associate_step2(struct rtllib_device *ieee)
1493 struct sk_buff *skb;
1494 struct rtllib_network *beacon = &ieee->current_network;
1496 del_timer_sync(&ieee->associate_timer);
1498 netdev_dbg(ieee->dev, "Sending association request\n");
1500 ieee->softmac_stats.tx_ass_rq++;
1501 skb = rtllib_association_req(beacon, ieee);
1503 rtllib_associate_abort(ieee);
1505 softmac_mgmt_xmit(skb, ieee);
1506 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1510 static void rtllib_associate_complete_wq(void *data)
1512 struct rtllib_device *ieee = (struct rtllib_device *)
1513 container_of_work_rsl(data,
1514 struct rtllib_device,
1515 associate_complete_wq);
1516 struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
1518 netdev_info(ieee->dev, "Associated successfully with %pM\n",
1519 ieee->current_network.bssid);
1520 if (!ieee->is_silent_reset) {
1521 netdev_info(ieee->dev, "normal associate\n");
1522 notify_wx_assoc_event(ieee);
1525 netif_carrier_on(ieee->dev);
1526 ieee->is_roaming = false;
1527 if (rtllib_is_54g(&ieee->current_network) &&
1528 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1530 netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate);
1533 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1534 netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate);
1536 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1537 netdev_info(ieee->dev, "Successfully associated, ht enabled\n");
1540 netdev_info(ieee->dev,
1541 "Successfully associated, ht not enabled(%d, %d)\n",
1542 ieee->pHTInfo->bCurrentHTSupport,
1543 ieee->pHTInfo->bEnableHT);
1544 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1546 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1547 ieee->current_network.beacon_interval /
1549 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1550 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1551 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1552 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1554 pPSC->LpsIdleCount = 0;
1555 ieee->link_change(ieee->dev);
1557 if (ieee->is_silent_reset) {
1558 netdev_info(ieee->dev, "silent reset associate\n");
1559 ieee->is_silent_reset = false;
1562 if (ieee->data_hard_resume)
1563 ieee->data_hard_resume(ieee->dev);
1567 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1571 static void rtllib_associate_complete(struct rtllib_device *ieee)
1573 del_timer_sync(&ieee->associate_timer);
1575 ieee->state = RTLLIB_LINKED;
1576 rtllib_sta_send_associnfo(ieee);
1578 schedule_work(&ieee->associate_complete_wq);
1581 static void rtllib_associate_procedure_wq(void *data)
1583 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1584 struct rtllib_device,
1585 associate_procedure_wq);
1586 rtllib_stop_scan_syncro(ieee);
1587 if (ieee->rtllib_ips_leave != NULL)
1588 ieee->rtllib_ips_leave(ieee->dev);
1589 mutex_lock(&ieee->wx_mutex);
1591 if (ieee->data_hard_stop)
1592 ieee->data_hard_stop(ieee->dev);
1594 rtllib_stop_scan(ieee);
1595 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1596 ieee->current_network.channel);
1597 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1598 if (ieee->eRFPowerState == eRfOff) {
1600 "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n",
1602 if (ieee->rtllib_ips_leave_wq != NULL)
1603 ieee->rtllib_ips_leave_wq(ieee->dev);
1604 mutex_unlock(&ieee->wx_mutex);
1607 ieee->associate_seq = 1;
1609 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1611 mutex_unlock(&ieee->wx_mutex);
1614 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1615 struct rtllib_network *net)
1617 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1618 int tmp_ssid_len = 0;
1620 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1622 /* we are interested in new new only if we are not associated
1623 * and we are not associating / authenticating
1625 if (ieee->state != RTLLIB_NOLINK)
1628 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1629 WLAN_CAPABILITY_ESS))
1632 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1633 WLAN_CAPABILITY_IBSS))
1636 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1637 (net->channel > ieee->ibss_maxjoin_chal))
1639 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1640 /* if the user specified the AP MAC, we need also the essid
1641 * This could be obtained by beacons or, if the network does not
1642 * broadcast it, it can be put manually.
1644 apset = ieee->wap_set;
1645 ssidset = ieee->ssid_set;
1646 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1647 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1650 ssidmatch = (ieee->current_network.ssid_len ==
1651 net->hidden_ssid_len) &&
1652 (!strncmp(ieee->current_network.ssid,
1653 net->hidden_ssid, net->hidden_ssid_len));
1654 if (net->hidden_ssid_len > 0) {
1655 strncpy(net->ssid, net->hidden_ssid,
1656 net->hidden_ssid_len);
1657 net->ssid_len = net->hidden_ssid_len;
1662 (ieee->current_network.ssid_len == net->ssid_len) &&
1663 (!strncmp(ieee->current_network.ssid, net->ssid,
1666 /* if the user set the AP check if match.
1667 * if the network does not broadcast essid we check the
1668 * user supplied ANY essid
1669 * if the network does broadcast and the user does not set
1671 * if the network does broadcast and the user did set essid
1672 * check if essid match
1673 * if the ap is not set, check that the user set the bssid
1674 * and the network does broadcast and that those two bssid match
1676 if ((apset && apmatch &&
1677 ((ssidset && ssidbroad && ssidmatch) ||
1678 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1679 (!apset && ssidset && ssidbroad && ssidmatch) ||
1680 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1681 /* if the essid is hidden replace it with the
1682 * essid provided by the user.
1685 strncpy(tmp_ssid, ieee->current_network.ssid,
1687 tmp_ssid_len = ieee->current_network.ssid_len;
1689 memcpy(&ieee->current_network, net,
1690 sizeof(struct rtllib_network));
1692 strncpy(ieee->current_network.ssid, tmp_ssid,
1694 ieee->current_network.ssid_len = tmp_ssid_len;
1696 netdev_info(ieee->dev,
1697 "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",
1698 ieee->current_network.ssid,
1699 ieee->current_network.channel,
1700 ieee->current_network.qos_data.supported,
1701 ieee->pHTInfo->bEnableHT,
1702 ieee->current_network.bssht.bdSupportHT,
1703 ieee->current_network.mode,
1704 ieee->current_network.flags);
1706 if ((rtllib_act_scanning(ieee, false)) &&
1707 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1708 rtllib_stop_scan_syncro(ieee);
1710 HTResetIOTSetting(ieee->pHTInfo);
1712 if (ieee->iw_mode == IW_MODE_INFRA) {
1713 /* Join the network for the first time */
1714 ieee->AsocRetryCount = 0;
1715 if ((ieee->current_network.qos_data.supported == 1) &&
1716 ieee->current_network.bssht.bdSupportHT)
1717 HTResetSelfAndSavePeerSetting(ieee,
1718 &(ieee->current_network));
1720 ieee->pHTInfo->bCurrentHTSupport =
1723 ieee->state = RTLLIB_ASSOCIATING;
1724 if (ieee->LedControlHandler != NULL)
1725 ieee->LedControlHandler(ieee->dev,
1726 LED_CTL_START_TO_LINK);
1727 schedule_delayed_work(
1728 &ieee->associate_procedure_wq, 0);
1730 if (rtllib_is_54g(&ieee->current_network) &&
1732 RTLLIB_OFDM_MODULATION)) {
1734 ieee->SetWirelessMode(ieee->dev,
1736 netdev_info(ieee->dev,
1740 ieee->SetWirelessMode(ieee->dev,
1742 netdev_info(ieee->dev,
1745 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1746 ieee->state = RTLLIB_LINKED;
1752 static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1754 unsigned long flags;
1755 struct rtllib_network *target;
1757 spin_lock_irqsave(&ieee->lock, flags);
1759 list_for_each_entry(target, &ieee->network_list, list) {
1761 /* if the state become different that NOLINK means
1762 * we had found what we are searching for
1765 if (ieee->state != RTLLIB_NOLINK)
1768 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1769 ieee->scan_age, jiffies))
1770 rtllib_softmac_new_net(ieee, target);
1772 spin_unlock_irqrestore(&ieee->lock, flags);
1775 static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
1776 u8 **challenge, int *chlen)
1778 struct rtllib_authentication *a;
1781 if (skb->len < (sizeof(struct rtllib_authentication) -
1782 sizeof(struct rtllib_info_element))) {
1783 netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
1787 a = (struct rtllib_authentication *) skb->data;
1788 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1789 t = skb->data + sizeof(struct rtllib_authentication);
1791 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1793 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1798 return le16_to_cpu(a->status);
1801 static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1803 struct rtllib_authentication *a;
1805 if (skb->len < (sizeof(struct rtllib_authentication) -
1806 sizeof(struct rtllib_info_element))) {
1807 netdev_dbg(dev, "invalid len in auth request: %d\n", skb->len);
1810 a = (struct rtllib_authentication *) skb->data;
1812 ether_addr_copy(dest, a->header.addr2);
1814 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1815 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1817 return WLAN_STATUS_SUCCESS;
1820 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1827 struct rtllib_hdr_3addr *header =
1828 (struct rtllib_hdr_3addr *) skb->data;
1831 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1832 return -1; /* corrupted */
1835 (!ether_addr_equal(header->addr3, ieee->current_network.bssid)) &&
1836 (!is_broadcast_ether_addr(header->addr3));
1840 ether_addr_copy(src, header->addr2);
1842 skbend = (u8 *)skb->data + skb->len;
1844 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1846 while (tag + 1 < skbend) {
1849 ssidlen = *(tag + 1);
1852 tag++; /* point to the len field */
1853 tag = tag + *(tag); /* point to the last data byte of the tag */
1854 tag++; /* point to the next tag */
1861 return 1; /* ssid not found in tagged param */
1863 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1866 static int assoc_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1868 struct rtllib_assoc_request_frame *a;
1870 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1871 sizeof(struct rtllib_info_element))) {
1872 netdev_dbg(dev, "invalid len in auth request:%d\n", skb->len);
1876 a = (struct rtllib_assoc_request_frame *) skb->data;
1878 ether_addr_copy(dest, a->header.addr2);
1883 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1886 struct rtllib_assoc_response_frame *response_head;
1889 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1890 netdev_dbg(ieee->dev, "Invalid len in auth resp: %d\n",
1895 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1896 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1898 status_code = le16_to_cpu(response_head->status);
1899 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1900 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1901 ((ieee->mode == IEEE_G) &&
1902 (ieee->current_network.mode == IEEE_N_24G) &&
1903 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1904 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1906 ieee->AsocRetryCount = 0;
1909 return le16_to_cpu(response_head->status);
1912 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1916 ieee->softmac_stats.rx_probe_rq++;
1917 if (probe_rq_parse(ieee, skb, dest) > 0) {
1918 ieee->softmac_stats.tx_probe_rs++;
1919 rtllib_resp_to_probe(ieee, dest);
1923 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1924 struct sk_buff *skb)
1929 ieee->softmac_stats.rx_auth_rq++;
1931 status = auth_rq_parse(ieee->dev, skb, dest);
1933 rtllib_resp_to_auth(ieee, status, dest);
1936 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1937 struct sk_buff *skb)
1942 ieee->softmac_stats.rx_ass_rq++;
1943 if (assoc_rq_parse(ieee->dev, skb, dest) != -1)
1944 rtllib_resp_to_assoc_rq(ieee, dest);
1946 netdev_info(ieee->dev, "New client associated: %pM\n", dest);
1949 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1952 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1955 softmac_ps_mgmt_xmit(buf, ieee);
1957 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1959 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1961 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1964 softmac_ps_mgmt_xmit(buf, ieee);
1967 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1969 int timeout = ieee->ps_timeout;
1971 struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
1973 if (ieee->LPSDelayCnt) {
1974 ieee->LPSDelayCnt--;
1978 dtim = ieee->current_network.dtim_data;
1979 if (!(dtim & RTLLIB_DTIM_VALID))
1981 timeout = ieee->current_network.beacon_interval;
1982 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
1983 /* there's no need to nofity AP that I find you buffered
1984 * with broadcast packet
1986 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
1989 if (!time_after(jiffies,
1990 dev_trans_start(ieee->dev) + msecs_to_jiffies(timeout)))
1992 if (!time_after(jiffies,
1993 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
1995 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
1996 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
2000 if (ieee->bAwakePktSent) {
2001 pPSC->LPSAwakeIntvl = 1;
2005 if (pPSC->LPSAwakeIntvl == 0)
2006 pPSC->LPSAwakeIntvl = 1;
2007 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2009 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2010 MaxPeriod = ieee->current_network.dtim_period;
2012 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2013 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2014 MaxPeriod) ? MaxPeriod :
2015 (pPSC->LPSAwakeIntvl + 1);
2018 u8 LPSAwakeIntvl_tmp = 0;
2019 u8 period = ieee->current_network.dtim_period;
2020 u8 count = ieee->current_network.tim.tim_count;
2023 if (pPSC->LPSAwakeIntvl > period)
2024 LPSAwakeIntvl_tmp = period +
2025 (pPSC->LPSAwakeIntvl -
2027 ((pPSC->LPSAwakeIntvl-period) %
2030 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2033 if (pPSC->LPSAwakeIntvl >
2034 ieee->current_network.tim.tim_count)
2035 LPSAwakeIntvl_tmp = count +
2036 (pPSC->LPSAwakeIntvl - count) -
2037 ((pPSC->LPSAwakeIntvl-count)%period);
2039 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2042 *time = ieee->current_network.last_dtim_sta_time
2043 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2053 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2057 unsigned long flags, flags2;
2059 spin_lock_irqsave(&ieee->lock, flags);
2061 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2062 ieee->iw_mode != IW_MODE_INFRA ||
2063 ieee->state != RTLLIB_LINKED)) {
2065 "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n",
2066 __func__, ieee->ps, ieee->iw_mode, ieee->state);
2067 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2068 rtllib_sta_wakeup(ieee, 1);
2070 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2072 sleep = rtllib_sta_ps_sleep(ieee, &time);
2073 /* 2 wake, 1 sleep, 0 do nothing */
2077 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2078 ieee->enter_sleep_state(ieee->dev, time);
2079 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2080 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2082 if (ieee->ps_is_queue_empty(ieee->dev)) {
2083 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2084 ieee->ack_tx_to_ieee = 1;
2085 rtllib_sta_ps_send_null_frame(ieee, 1);
2086 ieee->ps_time = time;
2088 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2092 ieee->bAwakePktSent = false;
2094 } else if (sleep == 2) {
2095 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2097 rtllib_sta_wakeup(ieee, 1);
2099 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2103 spin_unlock_irqrestore(&ieee->lock, flags);
2107 static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2109 if (ieee->sta_sleep == LPS_IS_WAKE) {
2111 if (ieee->pHTInfo->IOTAction &
2112 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2113 ieee->ack_tx_to_ieee = 1;
2114 rtllib_sta_ps_send_null_frame(ieee, 0);
2116 ieee->ack_tx_to_ieee = 1;
2117 rtllib_sta_ps_send_pspoll_frame(ieee);
2124 if (ieee->sta_sleep == LPS_IS_SLEEP)
2125 ieee->sta_wake_up(ieee->dev);
2127 if (ieee->pHTInfo->IOTAction &
2128 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2129 ieee->ack_tx_to_ieee = 1;
2130 rtllib_sta_ps_send_null_frame(ieee, 0);
2132 ieee->ack_tx_to_ieee = 1;
2133 ieee->polling = true;
2134 rtllib_sta_ps_send_pspoll_frame(ieee);
2138 ieee->sta_sleep = LPS_IS_WAKE;
2139 ieee->polling = false;
2143 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2145 unsigned long flags, flags2;
2147 spin_lock_irqsave(&ieee->lock, flags);
2149 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2150 /* Null frame with PS bit set */
2152 ieee->sta_sleep = LPS_IS_SLEEP;
2153 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2155 /* if the card report not success we can't be sure the AP
2156 * has not RXed so we can't assume the AP believe us awake
2158 } else {/* 21112005 - tx again null without PS bit if lost */
2160 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2161 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2162 if (ieee->pHTInfo->IOTAction &
2163 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2164 rtllib_sta_ps_send_null_frame(ieee, 0);
2166 rtllib_sta_ps_send_pspoll_frame(ieee);
2167 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2170 spin_unlock_irqrestore(&ieee->lock, flags);
2172 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2174 static void rtllib_process_action(struct rtllib_device *ieee,
2175 struct sk_buff *skb)
2177 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2178 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2182 netdev_warn(ieee->dev,
2183 "Error getting payload of action frame\n");
2193 rtllib_rx_ADDBAReq(ieee, skb);
2196 rtllib_rx_ADDBARsp(ieee, skb);
2199 rtllib_rx_DELBA(ieee, skb);
2209 rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2210 struct rtllib_rx_stats *rx_stats)
2215 struct rtllib_assoc_response_frame *assoc_resp;
2216 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2217 u16 frame_ctl = le16_to_cpu(header->frame_ctl);
2219 netdev_dbg(ieee->dev, "received [RE]ASSOCIATION RESPONSE (%d)\n",
2220 WLAN_FC_GET_STYPE(frame_ctl));
2222 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2223 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2224 (ieee->iw_mode == IW_MODE_INFRA)) {
2225 errcode = assoc_parse(ieee, skb, &aid);
2227 struct rtllib_network *network =
2228 kzalloc(sizeof(struct rtllib_network),
2233 ieee->state = RTLLIB_LINKED;
2234 ieee->assoc_id = aid;
2235 ieee->softmac_stats.rx_ass_ok++;
2236 /* station support qos */
2237 /* Let the register setting default with Legacy station */
2238 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2239 if (ieee->current_network.qos_data.supported == 1) {
2240 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2241 rx_stats->len - sizeof(*assoc_resp),
2242 network, rx_stats)) {
2246 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2247 network->bssht.bdHTCapBuf,
2248 network->bssht.bdHTCapLen);
2249 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2250 network->bssht.bdHTInfoBuf,
2251 network->bssht.bdHTInfoLen);
2252 if (ieee->handle_assoc_response != NULL)
2253 ieee->handle_assoc_response(ieee->dev,
2254 (struct rtllib_assoc_response_frame *)header,
2259 kfree(ieee->assocresp_ies);
2260 ieee->assocresp_ies = NULL;
2261 ies = &(assoc_resp->info_element[0].id);
2262 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2263 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2265 if (ieee->assocresp_ies)
2266 memcpy(ieee->assocresp_ies, ies,
2267 ieee->assocresp_ies_len);
2269 netdev_info(ieee->dev,
2270 "%s()Warning: can't alloc memory for assocresp_ies\n",
2272 ieee->assocresp_ies_len = 0;
2274 rtllib_associate_complete(ieee);
2276 /* aid could not been allocated */
2277 ieee->softmac_stats.rx_ass_err++;
2278 netdev_info(ieee->dev,
2279 "Association response status code 0x%x\n",
2281 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2282 schedule_delayed_work(
2283 &ieee->associate_procedure_wq, 0);
2285 rtllib_associate_abort(ieee);
2291 static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
2296 bool bSupportNmode = true, bHalfSupportNmode = false;
2298 errcode = auth_parse(ieee->dev, skb, &challenge, &chlen);
2301 ieee->softmac_stats.rx_auth_rs_err++;
2302 netdev_info(ieee->dev,
2303 "Authentication response status code 0x%x",
2305 rtllib_associate_abort(ieee);
2309 if (ieee->open_wep || !challenge) {
2310 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2311 ieee->softmac_stats.rx_auth_rs_ok++;
2312 if (!(ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE)) {
2313 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2314 if (IsHTHalfNmodeAPs(ieee)) {
2315 bSupportNmode = true;
2316 bHalfSupportNmode = true;
2318 bSupportNmode = false;
2319 bHalfSupportNmode = false;
2323 /* Dummy wirless mode setting to avoid encryption issue */
2324 if (bSupportNmode) {
2325 ieee->SetWirelessMode(ieee->dev,
2326 ieee->current_network.mode);
2329 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2332 if ((ieee->current_network.mode == IEEE_N_24G) &&
2333 bHalfSupportNmode) {
2334 netdev_info(ieee->dev, "======>enter half N mode\n");
2335 ieee->bHalfWirelessN24GMode = true;
2337 ieee->bHalfWirelessN24GMode = false;
2339 rtllib_associate_step2(ieee);
2341 rtllib_auth_challenge(ieee, challenge, chlen);
2346 rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2347 struct rtllib_rx_stats *rx_stats)
2350 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2351 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2352 (ieee->iw_mode == IW_MODE_INFRA)) {
2353 netdev_dbg(ieee->dev,
2354 "Received authentication response");
2355 rtllib_rx_auth_resp(ieee, skb);
2356 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2357 rtllib_rx_auth_rq(ieee, skb);
2364 rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2366 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2369 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2372 /* FIXME for now repeat all the association procedure
2373 * both for disassociation and deauthentication
2375 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2376 ieee->state == RTLLIB_LINKED &&
2377 (ieee->iw_mode == IW_MODE_INFRA)) {
2378 frame_ctl = le16_to_cpu(header->frame_ctl);
2379 netdev_info(ieee->dev,
2380 "==========>received disassoc/deauth(%x) frame, reason code:%x\n",
2381 WLAN_FC_GET_STYPE(frame_ctl),
2382 ((struct rtllib_disassoc *)skb->data)->reason);
2383 ieee->state = RTLLIB_ASSOCIATING;
2384 ieee->softmac_stats.reassoc++;
2385 ieee->is_roaming = true;
2386 ieee->LinkDetectInfo.bBusyTraffic = false;
2387 rtllib_disassociate(ieee);
2388 RemovePeerTS(ieee, header->addr2);
2389 if (ieee->LedControlHandler != NULL)
2390 ieee->LedControlHandler(ieee->dev,
2391 LED_CTL_START_TO_LINK);
2393 if (!(ieee->rtllib_ap_sec_type(ieee) &
2394 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2395 schedule_delayed_work(
2396 &ieee->associate_procedure_wq, 5);
2401 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2402 struct sk_buff *skb,
2403 struct rtllib_rx_stats *rx_stats, u16 type,
2406 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2409 if (!ieee->proto_started)
2412 frame_ctl = le16_to_cpu(header->frame_ctl);
2413 switch (WLAN_FC_GET_STYPE(frame_ctl)) {
2414 case RTLLIB_STYPE_ASSOC_RESP:
2415 case RTLLIB_STYPE_REASSOC_RESP:
2416 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2419 case RTLLIB_STYPE_ASSOC_REQ:
2420 case RTLLIB_STYPE_REASSOC_REQ:
2421 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2422 ieee->iw_mode == IW_MODE_MASTER)
2423 rtllib_rx_assoc_rq(ieee, skb);
2425 case RTLLIB_STYPE_AUTH:
2426 rtllib_rx_auth(ieee, skb, rx_stats);
2428 case RTLLIB_STYPE_DISASSOC:
2429 case RTLLIB_STYPE_DEAUTH:
2430 rtllib_rx_deauth(ieee, skb);
2432 case RTLLIB_STYPE_MANAGE_ACT:
2433 rtllib_process_action(ieee, skb);
2441 /* following are for a simpler TX queue management.
2442 * Instead of using netif_[stop/wake]_queue the driver
2443 * will use these two functions (plus a reset one), that
2444 * will internally use the kernel netif_* and takes
2445 * care of the ieee802.11 fragmentation.
2446 * So the driver receives a fragment per time and might
2447 * call the stop function when it wants to not
2448 * have enough room to TX an entire packet.
2449 * This might be useful if each fragment needs it's own
2450 * descriptor, thus just keep a total free memory > than
2451 * the max fragmentation threshold is not enough.. If the
2452 * ieee802.11 stack passed a TXB struct then you need
2453 * to keep N free descriptors where
2454 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2455 * In this way you need just one and the 802.11 stack
2456 * will take care of buffering fragments and pass them to
2457 * to the driver later, when it wakes the queue.
2459 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2462 unsigned int queue_index = txb->queue_index;
2463 unsigned long flags;
2465 struct cb_desc *tcb_desc = NULL;
2466 unsigned long queue_len = 0;
2468 spin_lock_irqsave(&ieee->lock, flags);
2470 /* called with 2nd parm 0, no tx mgmt lock required */
2471 rtllib_sta_wakeup(ieee, 0);
2473 /* update the tx status */
2474 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2476 if (tcb_desc->bMulticast)
2477 ieee->stats.multicast++;
2479 /* if xmit available, just xmit it immediately, else just insert it to
2482 for (i = 0; i < txb->nr_frags; i++) {
2483 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2484 if ((queue_len != 0) ||
2485 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2486 (ieee->queue_stop)) {
2487 /* insert the skb packet to the wait queue
2488 * as for the completion function, it does not need
2489 * to check it any more.
2491 if (queue_len < 200)
2492 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2495 kfree_skb(txb->fragments[i]);
2497 ieee->softmac_data_hard_start_xmit(
2499 ieee->dev, ieee->rate);
2503 rtllib_txb_free(txb);
2505 spin_unlock_irqrestore(&ieee->lock, flags);
2509 void rtllib_reset_queue(struct rtllib_device *ieee)
2511 unsigned long flags;
2513 spin_lock_irqsave(&ieee->lock, flags);
2514 init_mgmt_queue(ieee);
2515 if (ieee->tx_pending.txb) {
2516 rtllib_txb_free(ieee->tx_pending.txb);
2517 ieee->tx_pending.txb = NULL;
2519 ieee->queue_stop = 0;
2520 spin_unlock_irqrestore(&ieee->lock, flags);
2523 EXPORT_SYMBOL(rtllib_reset_queue);
2525 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2529 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2530 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2532 netif_tx_stop_all_queues(ieee->dev);
2535 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2537 netif_tx_wake_all_queues(ieee->dev);
2540 /* called in user context only */
2541 static void rtllib_start_master_bss(struct rtllib_device *ieee)
2545 if (ieee->current_network.ssid_len == 0) {
2546 strncpy(ieee->current_network.ssid,
2547 RTLLIB_DEFAULT_TX_ESSID,
2550 ieee->current_network.ssid_len =
2551 strlen(RTLLIB_DEFAULT_TX_ESSID);
2555 ether_addr_copy(ieee->current_network.bssid, ieee->dev->dev_addr);
2557 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2558 ieee->state = RTLLIB_LINKED;
2559 ieee->link_change(ieee->dev);
2560 notify_wx_assoc_event(ieee);
2562 if (ieee->data_hard_resume)
2563 ieee->data_hard_resume(ieee->dev);
2565 netif_carrier_on(ieee->dev);
2568 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2570 /* reset hardware status */
2572 if (ieee->data_hard_resume)
2573 ieee->data_hard_resume(ieee->dev);
2575 netif_carrier_on(ieee->dev);
2579 static void rtllib_start_ibss_wq(void *data)
2581 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2582 struct rtllib_device, start_ibss_wq);
2583 /* iwconfig mode ad-hoc will schedule this and return
2584 * on the other hand this will block further iwconfig SET
2585 * operations because of the wx_mutex hold.
2586 * Anyway some most set operations set a flag to speed-up
2587 * (abort) this wq (when syncro scanning) before sleeping
2590 if (!ieee->proto_started) {
2591 netdev_info(ieee->dev, "==========oh driver down return\n");
2594 mutex_lock(&ieee->wx_mutex);
2596 if (ieee->current_network.ssid_len == 0) {
2597 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2598 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2602 ieee->state = RTLLIB_NOLINK;
2603 ieee->mode = IEEE_G;
2604 /* check if we have this cell in our network list */
2605 rtllib_softmac_check_all_nets(ieee);
2608 /* if not then the state is not linked. Maybe the user switched to
2609 * ad-hoc mode just after being in monitor mode, or just after
2610 * being very few time in managed mode (so the card have had no
2611 * time to scan all the chans..) or we have just run up the iface
2612 * after setting ad-hoc mode. So we have to give another try..
2613 * Here, in ibss mode, should be safe to do this without extra care
2614 * (in bss mode we had to make sure no-one tried to associate when
2615 * we had just checked the ieee->state and we was going to start the
2616 * scan) because in ibss mode the rtllib_new_net function, when
2617 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2618 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2619 * scan, that will stop at the first round because it sees the state
2622 if (ieee->state == RTLLIB_NOLINK)
2623 rtllib_start_scan_syncro(ieee, 0);
2625 /* the network definitively is not here.. create a new cell */
2626 if (ieee->state == RTLLIB_NOLINK) {
2627 netdev_info(ieee->dev, "creating new IBSS cell\n");
2628 ieee->current_network.channel = ieee->IbssStartChnl;
2630 eth_random_addr(ieee->current_network.bssid);
2632 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2634 ieee->current_network.rates_len = 4;
2636 ieee->current_network.rates[0] =
2637 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2638 ieee->current_network.rates[1] =
2639 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2640 ieee->current_network.rates[2] =
2641 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2642 ieee->current_network.rates[3] =
2643 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2646 ieee->current_network.rates_len = 0;
2648 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2649 ieee->current_network.rates_ex_len = 8;
2651 ieee->current_network.rates_ex[0] =
2652 RTLLIB_OFDM_RATE_6MB;
2653 ieee->current_network.rates_ex[1] =
2654 RTLLIB_OFDM_RATE_9MB;
2655 ieee->current_network.rates_ex[2] =
2656 RTLLIB_OFDM_RATE_12MB;
2657 ieee->current_network.rates_ex[3] =
2658 RTLLIB_OFDM_RATE_18MB;
2659 ieee->current_network.rates_ex[4] =
2660 RTLLIB_OFDM_RATE_24MB;
2661 ieee->current_network.rates_ex[5] =
2662 RTLLIB_OFDM_RATE_36MB;
2663 ieee->current_network.rates_ex[6] =
2664 RTLLIB_OFDM_RATE_48MB;
2665 ieee->current_network.rates_ex[7] =
2666 RTLLIB_OFDM_RATE_54MB;
2670 ieee->current_network.rates_ex_len = 0;
2674 ieee->current_network.qos_data.supported = 0;
2675 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2676 ieee->current_network.mode = ieee->mode;
2677 ieee->current_network.atim_window = 0;
2678 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2681 netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2682 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2683 HTUseDefaultSetting(ieee);
2685 ieee->pHTInfo->bCurrentHTSupport = false;
2687 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2688 (u8 *)(&ieee->state));
2690 ieee->state = RTLLIB_LINKED;
2691 ieee->link_change(ieee->dev);
2693 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2694 if (ieee->LedControlHandler != NULL)
2695 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2697 rtllib_start_send_beacons(ieee);
2699 notify_wx_assoc_event(ieee);
2701 if (ieee->data_hard_resume)
2702 ieee->data_hard_resume(ieee->dev);
2704 netif_carrier_on(ieee->dev);
2706 mutex_unlock(&ieee->wx_mutex);
2709 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2711 schedule_delayed_work(&ieee->start_ibss_wq, msecs_to_jiffies(150));
2714 /* this is called only in user context, with wx_mutex held */
2715 static void rtllib_start_bss(struct rtllib_device *ieee)
2717 unsigned long flags;
2719 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2720 if (!ieee->bGlobalDomain)
2723 /* check if we have already found the net we
2724 * are interested in (if any).
2725 * if not (we are disassociated and we are not
2726 * in associating / authenticating phase) start the background scanning.
2728 rtllib_softmac_check_all_nets(ieee);
2730 /* ensure no-one start an associating process (thus setting
2731 * the ieee->state to rtllib_ASSOCIATING) while we
2732 * have just checked it and we are going to enable scan.
2733 * The rtllib_new_net function is always called with
2734 * lock held (from both rtllib_softmac_check_all_nets and
2735 * the rx path), so we cannot be in the middle of such function
2737 spin_lock_irqsave(&ieee->lock, flags);
2739 if (ieee->state == RTLLIB_NOLINK)
2740 rtllib_start_scan(ieee);
2741 spin_unlock_irqrestore(&ieee->lock, flags);
2744 static void rtllib_link_change_wq(void *data)
2746 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2747 struct rtllib_device, link_change_wq);
2748 ieee->link_change(ieee->dev);
2750 /* called only in userspace context */
2751 void rtllib_disassociate(struct rtllib_device *ieee)
2753 netif_carrier_off(ieee->dev);
2754 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2755 rtllib_reset_queue(ieee);
2757 if (ieee->data_hard_stop)
2758 ieee->data_hard_stop(ieee->dev);
2759 if (IS_DOT11D_ENABLE(ieee))
2761 ieee->state = RTLLIB_NOLINK;
2762 ieee->is_set_key = false;
2765 schedule_delayed_work(&ieee->link_change_wq, 0);
2767 notify_wx_assoc_event(ieee);
2770 static void rtllib_associate_retry_wq(void *data)
2772 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2773 struct rtllib_device, associate_retry_wq);
2774 unsigned long flags;
2776 mutex_lock(&ieee->wx_mutex);
2777 if (!ieee->proto_started)
2780 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2783 /* until we do not set the state to RTLLIB_NOLINK
2784 * there are no possibility to have someone else trying
2785 * to start an association procedure (we get here with
2786 * ieee->state = RTLLIB_ASSOCIATING).
2787 * When we set the state to RTLLIB_NOLINK it is possible
2788 * that the RX path run an attempt to associate, but
2789 * both rtllib_softmac_check_all_nets and the
2790 * RX path works with ieee->lock held so there are no
2791 * problems. If we are still disassociated then start a scan.
2792 * the lock here is necessary to ensure no one try to start
2793 * an association procedure when we have just checked the
2794 * state and we are going to start the scan.
2796 ieee->beinretry = true;
2797 ieee->state = RTLLIB_NOLINK;
2799 rtllib_softmac_check_all_nets(ieee);
2801 spin_lock_irqsave(&ieee->lock, flags);
2803 if (ieee->state == RTLLIB_NOLINK)
2804 rtllib_start_scan(ieee);
2805 spin_unlock_irqrestore(&ieee->lock, flags);
2807 ieee->beinretry = false;
2809 mutex_unlock(&ieee->wx_mutex);
2812 static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2814 const u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2816 struct sk_buff *skb;
2817 struct rtllib_probe_response *b;
2819 skb = rtllib_probe_resp(ieee, broadcast_addr);
2824 b = (struct rtllib_probe_response *) skb->data;
2825 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2831 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2833 struct sk_buff *skb;
2834 struct rtllib_probe_response *b;
2836 skb = rtllib_get_beacon_(ieee);
2840 b = (struct rtllib_probe_response *) skb->data;
2841 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2843 if (ieee->seq_ctrl[0] == 0xFFF)
2844 ieee->seq_ctrl[0] = 0;
2846 ieee->seq_ctrl[0]++;
2850 EXPORT_SYMBOL(rtllib_get_beacon);
2852 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2855 rtllib_stop_scan_syncro(ieee);
2856 mutex_lock(&ieee->wx_mutex);
2857 rtllib_stop_protocol(ieee, shutdown);
2858 mutex_unlock(&ieee->wx_mutex);
2860 EXPORT_SYMBOL(rtllib_softmac_stop_protocol);
2863 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2865 if (!ieee->proto_started)
2869 ieee->proto_started = 0;
2870 ieee->proto_stoppping = 1;
2871 if (ieee->rtllib_ips_leave != NULL)
2872 ieee->rtllib_ips_leave(ieee->dev);
2875 rtllib_stop_send_beacons(ieee);
2876 del_timer_sync(&ieee->associate_timer);
2877 cancel_delayed_work_sync(&ieee->associate_retry_wq);
2878 cancel_delayed_work_sync(&ieee->start_ibss_wq);
2879 cancel_delayed_work_sync(&ieee->link_change_wq);
2880 rtllib_stop_scan(ieee);
2882 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2883 ieee->state = RTLLIB_NOLINK;
2885 if (ieee->state == RTLLIB_LINKED) {
2886 if (ieee->iw_mode == IW_MODE_INFRA)
2887 SendDisassociation(ieee, 1, WLAN_REASON_DEAUTH_LEAVING);
2888 rtllib_disassociate(ieee);
2893 ieee->proto_stoppping = 0;
2895 kfree(ieee->assocreq_ies);
2896 ieee->assocreq_ies = NULL;
2897 ieee->assocreq_ies_len = 0;
2898 kfree(ieee->assocresp_ies);
2899 ieee->assocresp_ies = NULL;
2900 ieee->assocresp_ies_len = 0;
2903 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
2905 mutex_lock(&ieee->wx_mutex);
2906 rtllib_start_protocol(ieee);
2907 mutex_unlock(&ieee->wx_mutex);
2909 EXPORT_SYMBOL(rtllib_softmac_start_protocol);
2911 void rtllib_start_protocol(struct rtllib_device *ieee)
2916 rtllib_update_active_chan_map(ieee);
2918 if (ieee->proto_started)
2921 ieee->proto_started = 1;
2923 if (ieee->current_network.channel == 0) {
2926 if (ch > MAX_CHANNEL_NUMBER)
2927 return; /* no channel found */
2928 } while (!ieee->active_channel_map[ch]);
2929 ieee->current_network.channel = ch;
2932 if (ieee->current_network.beacon_interval == 0)
2933 ieee->current_network.beacon_interval = 100;
2935 for (i = 0; i < 17; i++) {
2936 ieee->last_rxseq_num[i] = -1;
2937 ieee->last_rxfrag_num[i] = -1;
2938 ieee->last_packet_time[i] = 0;
2941 if (ieee->UpdateBeaconInterruptHandler)
2942 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
2945 /* if the user set the MAC of the ad-hoc cell and then
2946 * switch to managed mode, shall we make sure that association
2947 * attempts does not fail just because the user provide the essid
2948 * and the nic is still checking for the AP MAC ??
2950 if (ieee->iw_mode == IW_MODE_INFRA) {
2951 rtllib_start_bss(ieee);
2952 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
2953 if (ieee->UpdateBeaconInterruptHandler)
2954 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
2956 rtllib_start_ibss(ieee);
2958 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2959 rtllib_start_master_bss(ieee);
2960 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
2961 rtllib_start_monitor_mode(ieee);
2965 void rtllib_softmac_init(struct rtllib_device *ieee)
2969 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
2971 ieee->state = RTLLIB_NOLINK;
2972 for (i = 0; i < 5; i++)
2973 ieee->seq_ctrl[i] = 0;
2974 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
2975 if (!ieee->pDot11dInfo)
2976 netdev_err(ieee->dev, "Can't alloc memory for DOT11D\n");
2977 ieee->LinkDetectInfo.SlotIndex = 0;
2978 ieee->LinkDetectInfo.SlotNum = 2;
2979 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
2980 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
2981 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
2982 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
2983 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
2984 ieee->bIsAggregateFrame = false;
2986 ieee->queue_stop = 0;
2987 ieee->scanning_continue = 0;
2988 ieee->softmac_features = 0;
2991 ieee->proto_started = 0;
2992 ieee->proto_stoppping = 0;
2993 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
2995 ieee->ps = RTLLIB_PS_DISABLED;
2996 ieee->sta_sleep = LPS_IS_WAKE;
2998 ieee->Regdot11HTOperationalRateSet[0] = 0xff;
2999 ieee->Regdot11HTOperationalRateSet[1] = 0xff;
3000 ieee->Regdot11HTOperationalRateSet[4] = 0x01;
3002 ieee->Regdot11TxHTOperationalRateSet[0] = 0xff;
3003 ieee->Regdot11TxHTOperationalRateSet[1] = 0xff;
3004 ieee->Regdot11TxHTOperationalRateSet[4] = 0x01;
3006 ieee->FirstIe_InScan = false;
3007 ieee->actscanning = false;
3008 ieee->beinretry = false;
3009 ieee->is_set_key = false;
3010 init_mgmt_queue(ieee);
3012 ieee->tx_pending.txb = NULL;
3014 setup_timer(&ieee->associate_timer,
3015 rtllib_associate_abort_cb,
3016 (unsigned long) ieee);
3018 setup_timer(&ieee->beacon_timer,
3019 rtllib_send_beacon_cb,
3020 (unsigned long) ieee);
3022 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3023 (void *)rtllib_link_change_wq, ieee);
3024 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3025 (void *)rtllib_start_ibss_wq, ieee);
3026 INIT_WORK_RSL(&ieee->associate_complete_wq,
3027 (void *)rtllib_associate_complete_wq, ieee);
3028 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3029 (void *)rtllib_associate_procedure_wq, ieee);
3030 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3031 (void *)rtllib_softmac_scan_wq, ieee);
3032 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3033 (void *)rtllib_associate_retry_wq, ieee);
3034 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3037 mutex_init(&ieee->wx_mutex);
3038 mutex_init(&ieee->scan_mutex);
3039 mutex_init(&ieee->ips_mutex);
3041 spin_lock_init(&ieee->mgmt_tx_lock);
3042 spin_lock_init(&ieee->beacon_lock);
3044 tasklet_init(&ieee->ps_task,
3045 (void(*)(unsigned long)) rtllib_sta_ps,
3046 (unsigned long)ieee);
3050 void rtllib_softmac_free(struct rtllib_device *ieee)
3052 mutex_lock(&ieee->wx_mutex);
3053 kfree(ieee->pDot11dInfo);
3054 ieee->pDot11dInfo = NULL;
3055 del_timer_sync(&ieee->associate_timer);
3057 cancel_delayed_work_sync(&ieee->associate_retry_wq);
3058 cancel_delayed_work_sync(&ieee->associate_procedure_wq);
3059 cancel_delayed_work_sync(&ieee->softmac_scan_wq);
3060 cancel_delayed_work_sync(&ieee->start_ibss_wq);
3061 cancel_delayed_work_sync(&ieee->hw_wakeup_wq);
3062 cancel_delayed_work_sync(&ieee->hw_sleep_wq);
3063 cancel_delayed_work_sync(&ieee->link_change_wq);
3064 cancel_work_sync(&ieee->associate_complete_wq);
3065 cancel_work_sync(&ieee->ips_leave_wq);
3066 cancel_work_sync(&ieee->wx_sync_scan_wq);
3067 mutex_unlock(&ieee->wx_mutex);
3068 tasklet_kill(&ieee->ps_task);
3071 static inline struct sk_buff *
3072 rtllib_disauth_skb(struct rtllib_network *beacon,
3073 struct rtllib_device *ieee, u16 asRsn)
3075 struct sk_buff *skb;
3076 struct rtllib_disauth *disauth;
3077 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3079 skb = dev_alloc_skb(len);
3083 skb_reserve(skb, ieee->tx_headroom);
3085 disauth = skb_put(skb, sizeof(struct rtllib_disauth));
3086 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3087 disauth->header.duration_id = 0;
3089 ether_addr_copy(disauth->header.addr1, beacon->bssid);
3090 ether_addr_copy(disauth->header.addr2, ieee->dev->dev_addr);
3091 ether_addr_copy(disauth->header.addr3, beacon->bssid);
3093 disauth->reason = cpu_to_le16(asRsn);
3097 static inline struct sk_buff *
3098 rtllib_disassociate_skb(struct rtllib_network *beacon,
3099 struct rtllib_device *ieee, u16 asRsn)
3101 struct sk_buff *skb;
3102 struct rtllib_disassoc *disass;
3103 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3105 skb = dev_alloc_skb(len);
3110 skb_reserve(skb, ieee->tx_headroom);
3112 disass = skb_put(skb, sizeof(struct rtllib_disassoc));
3113 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3114 disass->header.duration_id = 0;
3116 ether_addr_copy(disass->header.addr1, beacon->bssid);
3117 ether_addr_copy(disass->header.addr2, ieee->dev->dev_addr);
3118 ether_addr_copy(disass->header.addr3, beacon->bssid);
3120 disass->reason = cpu_to_le16(asRsn);
3124 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3126 struct rtllib_network *beacon = &ieee->current_network;
3127 struct sk_buff *skb;
3130 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3132 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3135 softmac_mgmt_xmit(skb, ieee);
3138 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3140 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3141 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3142 int wpa_ie_len = ieee->wpa_ie_len;
3143 struct lib80211_crypt_data *crypt;
3146 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3147 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3148 || (ieee->host_encrypt && crypt && crypt->ops &&
3149 (strcmp(crypt->ops->name, "R-WEP") == 0));
3152 if (encrypt && (wpa_ie_len == 0)) {
3154 } else if ((wpa_ie_len != 0)) {
3155 if (((ieee->wpa_ie[0] == 0xdd) &&
3156 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3157 ((ieee->wpa_ie[0] == 0x30) &&
3158 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3159 return SEC_ALG_CCMP;
3161 return SEC_ALG_TKIP;
3163 return SEC_ALG_NONE;
3167 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3171 bool bFilterOutNonAssociatedBSSID = false;
3173 rtllib->state = RTLLIB_NOLINK;
3175 for (i = 0; i < 6; i++)
3176 rtllib->current_network.bssid[i] = 0x55;
3178 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3179 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3180 rtllib->current_network.bssid);
3181 OpMode = RT_OP_MODE_NO_LINK;
3182 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3183 rtllib_stop_send_beacons(rtllib);
3185 bFilterOutNonAssociatedBSSID = false;
3186 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3187 (u8 *)(&bFilterOutNonAssociatedBSSID));
3188 notify_wx_assoc_event(rtllib);
3192 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib,
3193 u8 *asSta, u8 asRsn)
3198 RemovePeerTS(rtllib, asSta);
3200 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3201 rtllib->state = RTLLIB_NOLINK;
3203 for (i = 0; i < 6; i++)
3204 rtllib->current_network.bssid[i] = 0x22;
3205 OpMode = RT_OP_MODE_NO_LINK;
3206 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3207 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3209 rtllib_disassociate(rtllib);
3211 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3212 rtllib->current_network.bssid);
3219 rtllib_MgntDisconnectAP(
3220 struct rtllib_device *rtllib,
3224 bool bFilterOutNonAssociatedBSSID = false;
3226 bFilterOutNonAssociatedBSSID = false;
3227 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3228 (u8 *)(&bFilterOutNonAssociatedBSSID));
3229 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3232 rtllib->state = RTLLIB_NOLINK;
3235 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3237 if (rtllib->ps != RTLLIB_PS_DISABLED)
3238 rtllib->sta_wake_up(rtllib->dev);
3240 if (rtllib->state == RTLLIB_LINKED) {
3241 if (rtllib->iw_mode == IW_MODE_ADHOC)
3242 rtllib_MgntDisconnectIBSS(rtllib);
3243 if (rtllib->iw_mode == IW_MODE_INFRA)
3244 rtllib_MgntDisconnectAP(rtllib, asRsn);
3250 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3252 void notify_wx_assoc_event(struct rtllib_device *ieee)
3254 union iwreq_data wrqu;
3256 if (ieee->cannot_notify)
3259 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3260 if (ieee->state == RTLLIB_LINKED)
3261 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3265 netdev_info(ieee->dev, "%s(): Tell user space disconnected\n",
3267 eth_zero_addr(wrqu.ap_addr.sa_data);
3269 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3271 EXPORT_SYMBOL(notify_wx_assoc_event);