1 // SPDX-License-Identifier: GPL-2.0
2 /* IEEE 802.11 SoftMAC layer
3 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
5 * Mostly extracted from the rtl8180-sa2400 driver for the
6 * in-kernel generic ieee802.11 stack.
8 * Few lines might be stolen from other part of the rtllib
9 * stack. Copyright who own it's copyright
11 * WPA code stolen from the ipw2200 driver.
12 * Copyright who own it's copyright.
16 #include <linux/random.h>
17 #include <linux/delay.h>
18 #include <linux/uaccess.h>
19 #include <linux/etherdevice.h>
20 #include <linux/ieee80211.h>
23 static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
26 static short rtllib_is_54g(struct rtllib_network *net)
28 return (net->rates_ex_len > 0) || (net->rates_len > 4);
31 /* returns the total length needed for placing the RATE MFIE
32 * tag and the EXTENDED RATE MFIE tag if needed.
33 * It encludes two bytes per tag for the tag itself and its len
35 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
37 unsigned int rate_len = 0;
39 if (ieee->modulation & RTLLIB_CCK_MODULATION)
40 rate_len = RTLLIB_CCK_RATE_LEN + 2;
42 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
44 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
49 /* place the MFIE rate, tag to the memory (double) pointed.
50 * Then it updates the pointer so that
51 * it points after the new MFIE tag added.
53 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
57 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
58 *tag++ = MFIE_TYPE_RATES;
60 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
61 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
62 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
63 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
66 /* We may add an option for custom rates that specific HW
72 static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p)
76 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
77 *tag++ = MFIE_TYPE_RATES_EX;
79 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
80 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
81 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
82 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
83 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
84 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
85 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
86 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;
88 /* We may add an option for custom rates that specific HW might
94 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
98 *tag++ = MFIE_TYPE_GENERIC;
110 static void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
114 *tag++ = MFIE_TYPE_GENERIC;
125 netdev_alert(ieee->dev, "This is enable turbo mode IE process\n");
128 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
132 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
134 /* if the queue is full but we have newer frames then
135 * just overwrites the oldest.
137 * if (nh == ieee->mgmt_queue_tail)
140 ieee->mgmt_queue_head = nh;
141 ieee->mgmt_queue_ring[nh] = skb;
145 static void init_mgmt_queue(struct rtllib_device *ieee)
147 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
152 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
159 for (i = 0; i < ieee->current_network.rates_len; i++) {
160 BasicRate = ieee->current_network.rates[i]&0x7F;
161 if (!rtllib_is_cck_rate(BasicRate)) {
162 if (QueryRate == 0) {
163 QueryRate = BasicRate;
165 if (BasicRate < QueryRate)
166 QueryRate = BasicRate;
171 if (QueryRate == 0) {
173 netdev_info(ieee->dev, "No BasicRate found!!\n");
178 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
180 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
183 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
186 rate = ieee->basic_rate & 0x7f;
189 if (ieee->mode == IEEE_A ||
190 ieee->mode == IEEE_N_5G ||
191 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
200 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
203 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
204 struct rtllib_hdr_3addr *header =
205 (struct rtllib_hdr_3addr *) skb->data;
207 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
209 spin_lock_irqsave(&ieee->lock, flags);
211 /* called with 2nd param 0, no mgmt lock required */
212 rtllib_sta_wakeup(ieee, 0);
214 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
215 tcb_desc->queue_index = BEACON_QUEUE;
217 tcb_desc->queue_index = MGNT_QUEUE;
219 if (ieee->disable_mgnt_queue)
220 tcb_desc->queue_index = HIGH_QUEUE;
222 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
223 tcb_desc->RATRIndex = 7;
224 tcb_desc->bTxDisableRateFallBack = 1;
225 tcb_desc->bTxUseDriverAssingedRate = 1;
227 if (ieee->queue_stop) {
228 enqueue_mgmt(ieee, skb);
230 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
232 if (ieee->seq_ctrl[0] == 0xFFF)
233 ieee->seq_ctrl[0] = 0;
237 /* avoid watchdog triggers */
238 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
242 spin_unlock_irqrestore(&ieee->lock, flags);
244 spin_unlock_irqrestore(&ieee->lock, flags);
245 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
247 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
249 if (ieee->seq_ctrl[0] == 0xFFF)
250 ieee->seq_ctrl[0] = 0;
254 /* check whether the managed packet queued greater than 5 */
255 if (!ieee->check_nic_enough_desc(ieee->dev,
256 tcb_desc->queue_index) ||
257 skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) ||
259 /* insert the skb packet to the management queue
261 * as for the completion function, it does not need
262 * to check it any more.
264 netdev_info(ieee->dev,
265 "%s():insert to waitqueue, queue_index:%d!\n",
266 __func__, tcb_desc->queue_index);
267 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
270 ieee->softmac_hard_start_xmit(skb, ieee->dev);
272 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
277 softmac_ps_mgmt_xmit(struct sk_buff *skb,
278 struct rtllib_device *ieee)
280 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
281 struct rtllib_hdr_3addr *header =
282 (struct rtllib_hdr_3addr *) skb->data;
284 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
286 fc = le16_to_cpu(header->frame_ctl);
287 type = WLAN_FC_GET_TYPE(fc);
288 stype = WLAN_FC_GET_STYPE(fc);
291 if (stype != RTLLIB_STYPE_PSPOLL)
292 tcb_desc->queue_index = MGNT_QUEUE;
294 tcb_desc->queue_index = HIGH_QUEUE;
296 if (ieee->disable_mgnt_queue)
297 tcb_desc->queue_index = HIGH_QUEUE;
300 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
301 tcb_desc->RATRIndex = 7;
302 tcb_desc->bTxDisableRateFallBack = 1;
303 tcb_desc->bTxUseDriverAssingedRate = 1;
305 if (type != RTLLIB_FTYPE_CTL) {
306 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
308 if (ieee->seq_ctrl[0] == 0xFFF)
309 ieee->seq_ctrl[0] = 0;
314 /* avoid watchdog triggers */
315 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
319 if (type != RTLLIB_FTYPE_CTL) {
320 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
322 if (ieee->seq_ctrl[0] == 0xFFF)
323 ieee->seq_ctrl[0] = 0;
327 ieee->softmac_hard_start_xmit(skb, ieee->dev);
332 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
334 unsigned int len, rate_len;
337 struct rtllib_probe_request *req;
339 len = ieee->current_network.ssid_len;
341 rate_len = rtllib_MFIE_rate_len(ieee);
343 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
344 2 + len + rate_len + ieee->tx_headroom);
349 skb_reserve(skb, ieee->tx_headroom);
351 req = skb_put(skb, sizeof(struct rtllib_probe_request));
352 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
353 req->header.duration_id = 0;
355 eth_broadcast_addr(req->header.addr1);
356 ether_addr_copy(req->header.addr2, ieee->dev->dev_addr);
357 eth_broadcast_addr(req->header.addr3);
359 tag = skb_put(skb, len + 2 + rate_len);
361 *tag++ = MFIE_TYPE_SSID;
363 memcpy(tag, ieee->current_network.ssid, len);
366 rtllib_MFIE_Brate(ieee, &tag);
367 rtllib_MFIE_Grate(ieee, &tag);
372 static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
374 static void rtllib_send_beacon(struct rtllib_device *ieee)
380 skb = rtllib_get_beacon_(ieee);
383 softmac_mgmt_xmit(skb, ieee);
384 ieee->softmac_stats.tx_beacons++;
387 if (ieee->beacon_txing && ieee->ieee_up)
388 mod_timer(&ieee->beacon_timer, jiffies +
389 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
393 static void rtllib_send_beacon_cb(struct timer_list *t)
395 struct rtllib_device *ieee =
396 from_timer(ieee, t, beacon_timer);
399 spin_lock_irqsave(&ieee->beacon_lock, flags);
400 rtllib_send_beacon(ieee);
401 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
404 /* Enables network monitor mode, all rx packets will be received. */
405 void rtllib_EnableNetMonitorMode(struct net_device *dev,
408 struct rtllib_device *ieee = netdev_priv_rsl(dev);
410 netdev_info(dev, "========>Enter Monitor Mode\n");
412 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
416 /* Disables network monitor mode. Only packets destinated to
417 * us will be received.
419 void rtllib_DisableNetMonitorMode(struct net_device *dev,
422 struct rtllib_device *ieee = netdev_priv_rsl(dev);
424 netdev_info(dev, "========>Exit Monitor Mode\n");
426 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
430 /* Enables the specialized promiscuous mode required by Intel.
431 * In this mode, Intel intends to hear traffics from/to other STAs in the
432 * same BSS. Therefore we don't have to disable checking BSSID and we only need
433 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
434 * packets from other STA.
436 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
439 bool bFilterOutNonAssociatedBSSID = false;
441 struct rtllib_device *ieee = netdev_priv_rsl(dev);
443 netdev_info(dev, "========>Enter Intel Promiscuous Mode\n");
445 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
446 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
447 (u8 *)&bFilterOutNonAssociatedBSSID);
449 ieee->bNetPromiscuousMode = true;
451 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
454 /* Disables the specialized promiscuous mode required by Intel.
455 * See MgntEnableIntelPromiscuousMode for detail.
457 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
460 bool bFilterOutNonAssociatedBSSID = true;
462 struct rtllib_device *ieee = netdev_priv_rsl(dev);
464 netdev_info(dev, "========>Exit Intel Promiscuous Mode\n");
466 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
467 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
468 (u8 *)&bFilterOutNonAssociatedBSSID);
470 ieee->bNetPromiscuousMode = false;
472 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
474 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
478 skb = rtllib_probe_req(ieee);
480 softmac_mgmt_xmit(skb, ieee);
481 ieee->softmac_stats.tx_probe_rq++;
486 static void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
488 if (ieee->active_scan && (ieee->softmac_features &
489 IEEE_SOFTMAC_PROBERQ)) {
490 rtllib_send_probe(ieee, 0);
491 rtllib_send_probe(ieee, 0);
495 static void rtllib_update_active_chan_map(struct rtllib_device *ieee)
497 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
498 MAX_CHANNEL_NUMBER+1);
501 /* this performs syncro scan blocking the caller until all channels
502 * in the allowed channel map has been checked.
504 static void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
506 union iwreq_data wrqu;
509 rtllib_update_active_chan_map(ieee);
511 ieee->be_scan_inprogress = true;
513 mutex_lock(&ieee->scan_mutex);
518 if (ch > MAX_CHANNEL_NUMBER)
519 goto out; /* scan completed */
520 } while (!ieee->active_channel_map[ch]);
522 /* this function can be called in two situations
523 * 1- We have switched to ad-hoc mode and we are
524 * performing a complete syncro scan before conclude
525 * there are no interesting cell and to create a
526 * new one. In this case the link state is
527 * RTLLIB_NOLINK until we found an interesting cell.
528 * If so the ieee8021_new_net, called by the RX path
529 * will set the state to RTLLIB_LINKED, so we stop
531 * 2- We are linked and the root uses run iwlist scan.
532 * So we switch to RTLLIB_LINKED_SCANNING to remember
533 * that we are still logically linked (not interested in
534 * new network events, despite for updating the net list,
535 * but we are temporarly 'unlinked' as the driver shall
536 * not filter RX frames and the channel is changing.
537 * So the only situation in which are interested is to check
538 * if the state become LINKED because of the #1 situation
541 if (ieee->state == RTLLIB_LINKED)
543 if (ieee->sync_scan_hurryup) {
544 netdev_info(ieee->dev,
545 "============>sync_scan_hurryup out\n");
549 ieee->set_chan(ieee->dev, ch);
550 if (ieee->active_channel_map[ch] == 1)
551 rtllib_send_probe_requests(ieee, 0);
553 /* this prevent excessive time wait when we
554 * need to wait for a syncro scan to end..
556 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
559 ieee->actscanning = false;
560 ieee->sync_scan_hurryup = 0;
562 if (ieee->state >= RTLLIB_LINKED) {
563 if (IS_DOT11D_ENABLE(ieee))
564 dot11d_scan_complete(ieee);
566 mutex_unlock(&ieee->scan_mutex);
568 ieee->be_scan_inprogress = false;
570 memset(&wrqu, 0, sizeof(wrqu));
571 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
574 static void rtllib_softmac_scan_wq(void *data)
576 struct rtllib_device *ieee = container_of_dwork_rsl(data,
577 struct rtllib_device, softmac_scan_wq);
578 u8 last_channel = ieee->current_network.channel;
580 rtllib_update_active_chan_map(ieee);
584 if (rtllib_act_scanning(ieee, true))
587 mutex_lock(&ieee->scan_mutex);
589 if (ieee->eRFPowerState == eRfOff) {
590 netdev_info(ieee->dev,
591 "======>%s():rf state is eRfOff, return\n",
597 ieee->current_network.channel =
598 (ieee->current_network.channel + 1) %
600 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
601 if (!ieee->active_channel_map[ieee->current_network.channel])
602 ieee->current_network.channel = 6;
603 goto out; /* no good chans */
605 } while (!ieee->active_channel_map[ieee->current_network.channel]);
607 if (ieee->scanning_continue == 0)
610 ieee->set_chan(ieee->dev, ieee->current_network.channel);
612 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
613 rtllib_send_probe_requests(ieee, 0);
615 schedule_delayed_work(&ieee->softmac_scan_wq,
616 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
618 mutex_unlock(&ieee->scan_mutex);
622 if (IS_DOT11D_ENABLE(ieee))
623 dot11d_scan_complete(ieee);
624 ieee->current_network.channel = last_channel;
627 ieee->actscanning = false;
628 ieee->scan_watch_dog = 0;
629 ieee->scanning_continue = 0;
630 mutex_unlock(&ieee->scan_mutex);
635 static void rtllib_beacons_start(struct rtllib_device *ieee)
639 spin_lock_irqsave(&ieee->beacon_lock, flags);
641 ieee->beacon_txing = 1;
642 rtllib_send_beacon(ieee);
644 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
647 static void rtllib_beacons_stop(struct rtllib_device *ieee)
651 spin_lock_irqsave(&ieee->beacon_lock, flags);
653 ieee->beacon_txing = 0;
654 del_timer_sync(&ieee->beacon_timer);
656 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
661 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
663 if (ieee->stop_send_beacons)
664 ieee->stop_send_beacons(ieee->dev);
665 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
666 rtllib_beacons_stop(ieee);
668 EXPORT_SYMBOL(rtllib_stop_send_beacons);
671 void rtllib_start_send_beacons(struct rtllib_device *ieee)
673 if (ieee->start_send_beacons)
674 ieee->start_send_beacons(ieee->dev);
675 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
676 rtllib_beacons_start(ieee);
678 EXPORT_SYMBOL(rtllib_start_send_beacons);
681 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
683 mutex_lock(&ieee->scan_mutex);
684 ieee->scan_watch_dog = 0;
685 if (ieee->scanning_continue == 1) {
686 ieee->scanning_continue = 0;
687 ieee->actscanning = false;
689 cancel_delayed_work_sync(&ieee->softmac_scan_wq);
692 mutex_unlock(&ieee->scan_mutex);
695 void rtllib_stop_scan(struct rtllib_device *ieee)
697 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
698 rtllib_softmac_stop_scan(ieee);
700 if (ieee->rtllib_stop_hw_scan)
701 ieee->rtllib_stop_hw_scan(ieee->dev);
704 EXPORT_SYMBOL(rtllib_stop_scan);
706 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
708 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
709 ieee->sync_scan_hurryup = 1;
711 if (ieee->rtllib_stop_hw_scan)
712 ieee->rtllib_stop_hw_scan(ieee->dev);
715 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
717 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
719 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
721 return ieee->be_scan_inprogress;
723 return ieee->actscanning || ieee->be_scan_inprogress;
725 return test_bit(STATUS_SCANNING, &ieee->status);
728 EXPORT_SYMBOL(rtllib_act_scanning);
730 /* called with ieee->lock held */
731 static void rtllib_start_scan(struct rtllib_device *ieee)
733 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
734 if (ieee->rtllib_ips_leave_wq != NULL)
735 ieee->rtllib_ips_leave_wq(ieee->dev);
737 if (IS_DOT11D_ENABLE(ieee)) {
738 if (IS_COUNTRY_IE_VALID(ieee))
739 RESET_CIE_WATCHDOG(ieee);
741 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
742 if (ieee->scanning_continue == 0) {
743 ieee->actscanning = true;
744 ieee->scanning_continue = 1;
745 schedule_delayed_work(&ieee->softmac_scan_wq, 0);
748 if (ieee->rtllib_start_hw_scan)
749 ieee->rtllib_start_hw_scan(ieee->dev);
753 /* called with wx_mutex held */
754 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
756 if (IS_DOT11D_ENABLE(ieee)) {
757 if (IS_COUNTRY_IE_VALID(ieee))
758 RESET_CIE_WATCHDOG(ieee);
760 ieee->sync_scan_hurryup = 0;
761 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
762 rtllib_softmac_scan_syncro(ieee, is_mesh);
764 if (ieee->rtllib_start_hw_scan)
765 ieee->rtllib_start_hw_scan(ieee->dev);
768 EXPORT_SYMBOL(rtllib_start_scan_syncro);
770 static inline struct sk_buff *
771 rtllib_authentication_req(struct rtllib_network *beacon,
772 struct rtllib_device *ieee,
773 int challengelen, u8 *daddr)
776 struct rtllib_authentication *auth;
779 len = sizeof(struct rtllib_authentication) + challengelen +
780 ieee->tx_headroom + 4;
781 skb = dev_alloc_skb(len);
786 skb_reserve(skb, ieee->tx_headroom);
788 auth = skb_put(skb, sizeof(struct rtllib_authentication));
790 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
792 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
794 auth->header.duration_id = cpu_to_le16(0x013a);
795 ether_addr_copy(auth->header.addr1, beacon->bssid);
796 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
797 ether_addr_copy(auth->header.addr3, beacon->bssid);
798 if (ieee->auth_mode == 0)
799 auth->algorithm = WLAN_AUTH_OPEN;
800 else if (ieee->auth_mode == 1)
801 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
802 else if (ieee->auth_mode == 2)
803 auth->algorithm = WLAN_AUTH_OPEN;
804 auth->transaction = cpu_to_le16(ieee->associate_seq);
805 ieee->associate_seq++;
807 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
812 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee,
817 struct rtllib_probe_response *beacon_buf;
818 struct sk_buff *skb = NULL;
820 int atim_len, erp_len;
821 struct lib80211_crypt_data *crypt;
823 char *ssid = ieee->current_network.ssid;
824 int ssid_len = ieee->current_network.ssid_len;
825 int rate_len = ieee->current_network.rates_len+2;
826 int rate_ex_len = ieee->current_network.rates_ex_len;
827 int wpa_ie_len = ieee->wpa_ie_len;
828 u8 erpinfo_content = 0;
830 u8 *tmp_ht_cap_buf = NULL;
831 u8 tmp_ht_cap_len = 0;
832 u8 *tmp_ht_info_buf = NULL;
833 u8 tmp_ht_info_len = 0;
834 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
835 u8 *tmp_generic_ie_buf = NULL;
836 u8 tmp_generic_ie_len = 0;
841 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
846 if ((ieee->current_network.mode == IEEE_G) ||
847 (ieee->current_network.mode == IEEE_N_24G &&
848 ieee->pHTInfo->bCurSuppCCK)) {
851 if (ieee->current_network.buseprotection)
852 erpinfo_content |= ERP_UseProtection;
856 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
857 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
858 ((strcmp(crypt->ops->name, "R-WEP") == 0 || wpa_ie_len));
859 if (ieee->pHTInfo->bCurrentHTSupport) {
860 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
861 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
862 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
863 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
864 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
865 &tmp_ht_cap_len, encrypt, false);
866 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
869 if (pHTInfo->bRegRT2RTAggregation) {
870 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
872 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
873 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
874 &tmp_generic_ie_len);
878 beacon_size = sizeof(struct rtllib_probe_response)+2+
879 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
880 + wpa_ie_len + ieee->tx_headroom;
881 skb = dev_alloc_skb(beacon_size);
885 skb_reserve(skb, ieee->tx_headroom);
887 beacon_buf = skb_put(skb, (beacon_size - ieee->tx_headroom));
888 ether_addr_copy(beacon_buf->header.addr1, dest);
889 ether_addr_copy(beacon_buf->header.addr2, ieee->dev->dev_addr);
890 ether_addr_copy(beacon_buf->header.addr3, ieee->current_network.bssid);
892 beacon_buf->header.duration_id = 0;
893 beacon_buf->beacon_interval =
894 cpu_to_le16(ieee->current_network.beacon_interval);
895 beacon_buf->capability =
896 cpu_to_le16(ieee->current_network.capability &
897 WLAN_CAPABILITY_IBSS);
898 beacon_buf->capability |=
899 cpu_to_le16(ieee->current_network.capability &
900 WLAN_CAPABILITY_SHORT_PREAMBLE);
902 if (ieee->short_slot && (ieee->current_network.capability &
903 WLAN_CAPABILITY_SHORT_SLOT_TIME))
904 beacon_buf->capability |=
905 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
907 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
909 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
912 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
913 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
914 beacon_buf->info_element[0].len = ssid_len;
916 tag = (u8 *) beacon_buf->info_element[0].data;
918 memcpy(tag, ssid, ssid_len);
922 *(tag++) = MFIE_TYPE_RATES;
923 *(tag++) = rate_len-2;
924 memcpy(tag, ieee->current_network.rates, rate_len-2);
927 *(tag++) = MFIE_TYPE_DS_SET;
929 *(tag++) = ieee->current_network.channel;
933 *(tag++) = MFIE_TYPE_IBSS_SET;
935 val16 = ieee->current_network.atim_window;
936 memcpy((u8 *)tag, (u8 *)&val16, 2);
941 *(tag++) = MFIE_TYPE_ERP;
943 *(tag++) = erpinfo_content;
946 *(tag++) = MFIE_TYPE_RATES_EX;
947 *(tag++) = rate_ex_len-2;
948 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
949 tag += rate_ex_len-2;
953 if (ieee->iw_mode == IW_MODE_ADHOC)
954 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
955 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
956 tag += ieee->wpa_ie_len;
961 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
966 struct lib80211_crypt_data *crypt;
967 struct rtllib_assoc_response_frame *assoc;
970 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
971 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
974 skb = dev_alloc_skb(len);
979 skb_reserve(skb, ieee->tx_headroom);
981 assoc = skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
983 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
984 ether_addr_copy(assoc->header.addr1, dest);
985 ether_addr_copy(assoc->header.addr3, ieee->dev->dev_addr);
986 ether_addr_copy(assoc->header.addr2, ieee->dev->dev_addr);
987 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
988 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
991 if (ieee->short_slot)
993 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
995 if (ieee->host_encrypt)
996 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1000 encrypt = (crypt && crypt->ops);
1003 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1006 assoc->aid = cpu_to_le16(ieee->assoc_id);
1007 if (ieee->assoc_id == 0x2007)
1012 tag = skb_put(skb, rate_len);
1013 rtllib_MFIE_Brate(ieee, &tag);
1014 rtllib_MFIE_Grate(ieee, &tag);
1019 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1022 struct sk_buff *skb = NULL;
1023 struct rtllib_authentication *auth;
1024 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1026 skb = dev_alloc_skb(len);
1030 skb->len = sizeof(struct rtllib_authentication);
1032 skb_reserve(skb, ieee->tx_headroom);
1034 auth = skb_put(skb, sizeof(struct rtllib_authentication));
1036 auth->status = cpu_to_le16(status);
1037 auth->transaction = cpu_to_le16(2);
1038 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1040 ether_addr_copy(auth->header.addr3, ieee->dev->dev_addr);
1041 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
1042 ether_addr_copy(auth->header.addr1, dest);
1043 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1049 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1051 struct sk_buff *skb;
1052 struct rtllib_hdr_3addr *hdr;
1054 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1058 skb_reserve(skb, ieee->tx_headroom);
1060 hdr = skb_put(skb, sizeof(struct rtllib_hdr_3addr));
1062 ether_addr_copy(hdr->addr1, ieee->current_network.bssid);
1063 ether_addr_copy(hdr->addr2, ieee->dev->dev_addr);
1064 ether_addr_copy(hdr->addr3, ieee->current_network.bssid);
1066 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1067 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1068 (pwr ? RTLLIB_FCTL_PM : 0));
1075 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1077 struct sk_buff *skb;
1078 struct rtllib_pspoll_hdr *hdr;
1080 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1084 skb_reserve(skb, ieee->tx_headroom);
1086 hdr = skb_put(skb, sizeof(struct rtllib_pspoll_hdr));
1088 ether_addr_copy(hdr->bssid, ieee->current_network.bssid);
1089 ether_addr_copy(hdr->ta, ieee->dev->dev_addr);
1091 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1092 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1099 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1101 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1104 softmac_mgmt_xmit(buf, ieee);
1108 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1110 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1113 softmac_mgmt_xmit(buf, ieee);
1117 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1119 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1122 softmac_mgmt_xmit(buf, ieee);
1126 static inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1131 if ((ieee->PMKIDList[i].bUsed) &&
1132 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1135 } while (i < NUM_PMKID_CACHE);
1137 if (i == NUM_PMKID_CACHE)
1142 static inline struct sk_buff *
1143 rtllib_association_req(struct rtllib_network *beacon,
1144 struct rtllib_device *ieee)
1146 struct sk_buff *skb;
1147 struct rtllib_assoc_request_frame *hdr;
1150 u8 *ht_cap_buf = NULL;
1152 u8 *realtek_ie_buf = NULL;
1153 u8 realtek_ie_len = 0;
1154 int wpa_ie_len = ieee->wpa_ie_len;
1155 int wps_ie_len = ieee->wps_ie_len;
1156 unsigned int ckip_ie_len = 0;
1157 unsigned int ccxrm_ie_len = 0;
1158 unsigned int cxvernum_ie_len = 0;
1159 struct lib80211_crypt_data *crypt;
1163 unsigned int rate_len = (beacon->rates_len ?
1164 (beacon->rates_len + 2) : 0) +
1165 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1168 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1169 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1173 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1175 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1176 ((strcmp(crypt->ops->name, "R-WEP") == 0 ||
1181 if ((ieee->rtllib_ap_sec_type &&
1182 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1183 ieee->bForcedBgMode) {
1184 ieee->pHTInfo->bEnableHT = 0;
1185 ieee->mode = WIRELESS_MODE_G;
1188 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1189 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1190 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1191 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1193 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1194 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1196 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1197 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1202 if (beacon->bCkipSupported)
1204 if (beacon->bCcxRmEnable)
1206 if (beacon->BssCcxVerNumber >= 2)
1207 cxvernum_ie_len = 5+2;
1209 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1210 if (PMKCacheIdx >= 0) {
1212 netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n",
1215 len = sizeof(struct rtllib_assoc_request_frame) + 2
1227 + ieee->tx_headroom;
1229 skb = dev_alloc_skb(len);
1234 skb_reserve(skb, ieee->tx_headroom);
1236 hdr = skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1239 hdr->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_REQ);
1240 hdr->header.duration_id = cpu_to_le16(37);
1241 ether_addr_copy(hdr->header.addr1, beacon->bssid);
1242 ether_addr_copy(hdr->header.addr2, ieee->dev->dev_addr);
1243 ether_addr_copy(hdr->header.addr3, beacon->bssid);
1245 ether_addr_copy(ieee->ap_mac_addr, beacon->bssid);
1247 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1248 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1249 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1251 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1252 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1254 if (ieee->short_slot &&
1255 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1256 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1259 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1261 hdr->info_element[0].id = MFIE_TYPE_SSID;
1263 hdr->info_element[0].len = beacon->ssid_len;
1264 skb_put_data(skb, beacon->ssid, beacon->ssid_len);
1266 tag = skb_put(skb, rate_len);
1268 if (beacon->rates_len) {
1269 *tag++ = MFIE_TYPE_RATES;
1270 *tag++ = beacon->rates_len;
1271 for (i = 0; i < beacon->rates_len; i++)
1272 *tag++ = beacon->rates[i];
1275 if (beacon->rates_ex_len) {
1276 *tag++ = MFIE_TYPE_RATES_EX;
1277 *tag++ = beacon->rates_ex_len;
1278 for (i = 0; i < beacon->rates_ex_len; i++)
1279 *tag++ = beacon->rates_ex[i];
1282 if (beacon->bCkipSupported) {
1283 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1284 u8 CcxAironetBuf[30];
1285 struct octet_string osCcxAironetIE;
1287 memset(CcxAironetBuf, 0, 30);
1288 osCcxAironetIE.Octet = CcxAironetBuf;
1289 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1290 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1291 sizeof(AironetIeOui));
1293 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1294 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1295 tag = skb_put(skb, ckip_ie_len);
1296 *tag++ = MFIE_TYPE_AIRONET;
1297 *tag++ = osCcxAironetIE.Length;
1298 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1299 tag += osCcxAironetIE.Length;
1302 if (beacon->bCcxRmEnable) {
1303 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1305 struct octet_string osCcxRmCap;
1307 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1308 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1309 tag = skb_put(skb, ccxrm_ie_len);
1310 *tag++ = MFIE_TYPE_GENERIC;
1311 *tag++ = osCcxRmCap.Length;
1312 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1313 tag += osCcxRmCap.Length;
1316 if (beacon->BssCcxVerNumber >= 2) {
1317 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1318 struct octet_string osCcxVerNum;
1320 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1321 osCcxVerNum.Octet = CcxVerNumBuf;
1322 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1323 tag = skb_put(skb, cxvernum_ie_len);
1324 *tag++ = MFIE_TYPE_GENERIC;
1325 *tag++ = osCcxVerNum.Length;
1326 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1327 tag += osCcxVerNum.Length;
1329 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1330 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1331 tag = skb_put(skb, ht_cap_len);
1332 *tag++ = MFIE_TYPE_HT_CAP;
1333 *tag++ = ht_cap_len - 2;
1334 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1335 tag += ht_cap_len - 2;
1340 skb_put_data(skb, ieee->wpa_ie, ieee->wpa_ie_len);
1342 if (PMKCacheIdx >= 0) {
1343 tag = skb_put(skb, 18);
1346 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1351 tag = skb_put(skb, wmm_info_len);
1352 rtllib_WMM_Info(ieee, &tag);
1355 if (wps_ie_len && ieee->wps_ie) {
1356 skb_put_data(skb, ieee->wps_ie, wps_ie_len);
1359 if (turbo_info_len) {
1360 tag = skb_put(skb, turbo_info_len);
1361 rtllib_TURBO_Info(ieee, &tag);
1364 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1365 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1366 tag = skb_put(skb, ht_cap_len);
1367 *tag++ = MFIE_TYPE_GENERIC;
1368 *tag++ = ht_cap_len - 2;
1369 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1370 tag += ht_cap_len - 2;
1373 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1374 tag = skb_put(skb, realtek_ie_len);
1375 *tag++ = MFIE_TYPE_GENERIC;
1376 *tag++ = realtek_ie_len - 2;
1377 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1381 kfree(ieee->assocreq_ies);
1382 ieee->assocreq_ies = NULL;
1383 ies = &(hdr->info_element[0].id);
1384 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1385 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1386 if (ieee->assocreq_ies)
1387 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1389 netdev_info(ieee->dev,
1390 "%s()Warning: can't alloc memory for assocreq_ies\n",
1392 ieee->assocreq_ies_len = 0;
1397 static void rtllib_associate_abort(struct rtllib_device *ieee)
1399 unsigned long flags;
1401 spin_lock_irqsave(&ieee->lock, flags);
1403 ieee->associate_seq++;
1405 /* don't scan, and avoid to have the RX path possibily
1406 * try again to associate. Even do not react to AUTH or
1407 * ASSOC response. Just wait for the retry wq to be scheduled.
1408 * Here we will check if there are good nets to associate
1409 * with, so we retry or just get back to NO_LINK and scanning
1411 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1412 netdev_dbg(ieee->dev, "Authentication failed\n");
1413 ieee->softmac_stats.no_auth_rs++;
1415 netdev_dbg(ieee->dev, "Association failed\n");
1416 ieee->softmac_stats.no_ass_rs++;
1419 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1421 schedule_delayed_work(&ieee->associate_retry_wq,
1422 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1424 spin_unlock_irqrestore(&ieee->lock, flags);
1427 static void rtllib_associate_abort_cb(struct timer_list *t)
1429 struct rtllib_device *dev = from_timer(dev, t, associate_timer);
1431 rtllib_associate_abort(dev);
1434 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr)
1436 struct rtllib_network *beacon = &ieee->current_network;
1437 struct sk_buff *skb;
1439 netdev_dbg(ieee->dev, "Stopping scan\n");
1441 ieee->softmac_stats.tx_auth_rq++;
1443 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1446 rtllib_associate_abort(ieee);
1448 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING;
1449 netdev_dbg(ieee->dev, "Sending authentication request\n");
1450 softmac_mgmt_xmit(skb, ieee);
1451 if (!timer_pending(&ieee->associate_timer)) {
1452 ieee->associate_timer.expires = jiffies + (HZ / 2);
1453 add_timer(&ieee->associate_timer);
1458 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge,
1462 struct sk_buff *skb;
1463 struct rtllib_network *beacon = &ieee->current_network;
1465 ieee->associate_seq++;
1466 ieee->softmac_stats.tx_auth_rq++;
1468 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1471 rtllib_associate_abort(ieee);
1473 c = skb_put(skb, chlen+2);
1474 *(c++) = MFIE_TYPE_CHALLENGE;
1476 memcpy(c, challenge, chlen);
1478 netdev_dbg(ieee->dev,
1479 "Sending authentication challenge response\n");
1481 rtllib_encrypt_fragment(ieee, skb,
1482 sizeof(struct rtllib_hdr_3addr));
1484 softmac_mgmt_xmit(skb, ieee);
1485 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1490 static void rtllib_associate_step2(struct rtllib_device *ieee)
1492 struct sk_buff *skb;
1493 struct rtllib_network *beacon = &ieee->current_network;
1495 del_timer_sync(&ieee->associate_timer);
1497 netdev_dbg(ieee->dev, "Sending association request\n");
1499 ieee->softmac_stats.tx_ass_rq++;
1500 skb = rtllib_association_req(beacon, ieee);
1502 rtllib_associate_abort(ieee);
1504 softmac_mgmt_xmit(skb, ieee);
1505 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1509 static void rtllib_associate_complete_wq(void *data)
1511 struct rtllib_device *ieee = (struct rtllib_device *)
1512 container_of_work_rsl(data,
1513 struct rtllib_device,
1514 associate_complete_wq);
1515 struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
1517 netdev_info(ieee->dev, "Associated successfully with %pM\n",
1518 ieee->current_network.bssid);
1519 if (!ieee->is_silent_reset) {
1520 netdev_info(ieee->dev, "normal associate\n");
1521 notify_wx_assoc_event(ieee);
1524 netif_carrier_on(ieee->dev);
1525 ieee->is_roaming = false;
1526 if (rtllib_is_54g(&ieee->current_network) &&
1527 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1529 netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate);
1532 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1533 netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate);
1535 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1536 netdev_info(ieee->dev, "Successfully associated, ht enabled\n");
1539 netdev_info(ieee->dev,
1540 "Successfully associated, ht not enabled(%d, %d)\n",
1541 ieee->pHTInfo->bCurrentHTSupport,
1542 ieee->pHTInfo->bEnableHT);
1543 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1545 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1546 ieee->current_network.beacon_interval /
1548 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1549 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1550 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1551 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1553 pPSC->LpsIdleCount = 0;
1554 ieee->link_change(ieee->dev);
1556 if (ieee->is_silent_reset) {
1557 netdev_info(ieee->dev, "silent reset associate\n");
1558 ieee->is_silent_reset = false;
1561 if (ieee->data_hard_resume)
1562 ieee->data_hard_resume(ieee->dev);
1566 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1570 static void rtllib_associate_complete(struct rtllib_device *ieee)
1572 del_timer_sync(&ieee->associate_timer);
1574 ieee->state = RTLLIB_LINKED;
1575 rtllib_sta_send_associnfo(ieee);
1577 schedule_work(&ieee->associate_complete_wq);
1580 static void rtllib_associate_procedure_wq(void *data)
1582 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1583 struct rtllib_device,
1584 associate_procedure_wq);
1585 rtllib_stop_scan_syncro(ieee);
1586 if (ieee->rtllib_ips_leave != NULL)
1587 ieee->rtllib_ips_leave(ieee->dev);
1588 mutex_lock(&ieee->wx_mutex);
1590 if (ieee->data_hard_stop)
1591 ieee->data_hard_stop(ieee->dev);
1593 rtllib_stop_scan(ieee);
1594 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1595 ieee->current_network.channel);
1596 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1597 if (ieee->eRFPowerState == eRfOff) {
1599 "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n",
1601 if (ieee->rtllib_ips_leave_wq != NULL)
1602 ieee->rtllib_ips_leave_wq(ieee->dev);
1603 mutex_unlock(&ieee->wx_mutex);
1606 ieee->associate_seq = 1;
1608 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1610 mutex_unlock(&ieee->wx_mutex);
1613 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1614 struct rtllib_network *net)
1616 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1617 int tmp_ssid_len = 0;
1619 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1621 /* we are interested in new new only if we are not associated
1622 * and we are not associating / authenticating
1624 if (ieee->state != RTLLIB_NOLINK)
1627 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1628 WLAN_CAPABILITY_ESS))
1631 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1632 WLAN_CAPABILITY_IBSS))
1635 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1636 (net->channel > ieee->ibss_maxjoin_chal))
1638 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1639 /* if the user specified the AP MAC, we need also the essid
1640 * This could be obtained by beacons or, if the network does not
1641 * broadcast it, it can be put manually.
1643 apset = ieee->wap_set;
1644 ssidset = ieee->ssid_set;
1645 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1646 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1649 ssidmatch = (ieee->current_network.ssid_len ==
1650 net->hidden_ssid_len) &&
1651 (!strncmp(ieee->current_network.ssid,
1652 net->hidden_ssid, net->hidden_ssid_len));
1653 if (net->hidden_ssid_len > 0) {
1654 strncpy(net->ssid, net->hidden_ssid,
1655 net->hidden_ssid_len);
1656 net->ssid_len = net->hidden_ssid_len;
1661 (ieee->current_network.ssid_len == net->ssid_len) &&
1662 (!strncmp(ieee->current_network.ssid, net->ssid,
1665 /* if the user set the AP check if match.
1666 * if the network does not broadcast essid we check the
1667 * user supplied ANY essid
1668 * if the network does broadcast and the user does not set
1670 * if the network does broadcast and the user did set essid
1671 * check if essid match
1672 * if the ap is not set, check that the user set the bssid
1673 * and the network does broadcast and that those two bssid match
1675 if ((apset && apmatch &&
1676 ((ssidset && ssidbroad && ssidmatch) ||
1677 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1678 (!apset && ssidset && ssidbroad && ssidmatch) ||
1679 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1680 /* Save the essid so that if it is hidden, it is
1681 * replaced with the essid provided by the user.
1684 memcpy(tmp_ssid, ieee->current_network.ssid,
1685 ieee->current_network.ssid_len);
1686 tmp_ssid_len = ieee->current_network.ssid_len;
1688 memcpy(&ieee->current_network, net,
1689 sizeof(ieee->current_network));
1691 memcpy(ieee->current_network.ssid, tmp_ssid,
1693 ieee->current_network.ssid_len = tmp_ssid_len;
1695 netdev_info(ieee->dev,
1696 "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",
1697 ieee->current_network.ssid,
1698 ieee->current_network.channel,
1699 ieee->current_network.qos_data.supported,
1700 ieee->pHTInfo->bEnableHT,
1701 ieee->current_network.bssht.bdSupportHT,
1702 ieee->current_network.mode,
1703 ieee->current_network.flags);
1705 if ((rtllib_act_scanning(ieee, false)) &&
1706 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1707 rtllib_stop_scan_syncro(ieee);
1709 HTResetIOTSetting(ieee->pHTInfo);
1711 if (ieee->iw_mode == IW_MODE_INFRA) {
1712 /* Join the network for the first time */
1713 ieee->AsocRetryCount = 0;
1714 if ((ieee->current_network.qos_data.supported == 1) &&
1715 ieee->current_network.bssht.bdSupportHT)
1716 HTResetSelfAndSavePeerSetting(ieee,
1717 &(ieee->current_network));
1719 ieee->pHTInfo->bCurrentHTSupport =
1722 ieee->state = RTLLIB_ASSOCIATING;
1723 if (ieee->LedControlHandler != NULL)
1724 ieee->LedControlHandler(ieee->dev,
1725 LED_CTL_START_TO_LINK);
1726 schedule_delayed_work(
1727 &ieee->associate_procedure_wq, 0);
1729 if (rtllib_is_54g(&ieee->current_network) &&
1731 RTLLIB_OFDM_MODULATION)) {
1733 ieee->SetWirelessMode(ieee->dev,
1735 netdev_info(ieee->dev,
1739 ieee->SetWirelessMode(ieee->dev,
1741 netdev_info(ieee->dev,
1744 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1745 ieee->state = RTLLIB_LINKED;
1751 static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1753 unsigned long flags;
1754 struct rtllib_network *target;
1756 spin_lock_irqsave(&ieee->lock, flags);
1758 list_for_each_entry(target, &ieee->network_list, list) {
1760 /* if the state become different that NOLINK means
1761 * we had found what we are searching for
1764 if (ieee->state != RTLLIB_NOLINK)
1767 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1768 ieee->scan_age, jiffies))
1769 rtllib_softmac_new_net(ieee, target);
1771 spin_unlock_irqrestore(&ieee->lock, flags);
1774 static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
1775 u8 **challenge, int *chlen)
1777 struct rtllib_authentication *a;
1780 if (skb->len < (sizeof(struct rtllib_authentication) -
1781 sizeof(struct rtllib_info_element))) {
1782 netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
1786 a = (struct rtllib_authentication *) skb->data;
1787 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1788 t = skb->data + sizeof(struct rtllib_authentication);
1790 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1792 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1797 return le16_to_cpu(a->status);
1800 static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1802 struct rtllib_authentication *a;
1804 if (skb->len < (sizeof(struct rtllib_authentication) -
1805 sizeof(struct rtllib_info_element))) {
1806 netdev_dbg(dev, "invalid len in auth request: %d\n", skb->len);
1809 a = (struct rtllib_authentication *) skb->data;
1811 ether_addr_copy(dest, a->header.addr2);
1813 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1814 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1816 return WLAN_STATUS_SUCCESS;
1819 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1826 struct rtllib_hdr_3addr *header =
1827 (struct rtllib_hdr_3addr *) skb->data;
1830 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1831 return -1; /* corrupted */
1834 (!ether_addr_equal(header->addr3, ieee->current_network.bssid)) &&
1835 (!is_broadcast_ether_addr(header->addr3));
1839 ether_addr_copy(src, header->addr2);
1841 skbend = (u8 *)skb->data + skb->len;
1843 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1845 while (tag + 1 < skbend) {
1848 ssidlen = *(tag + 1);
1851 tag++; /* point to the len field */
1852 tag = tag + *(tag); /* point to the last data byte of the tag */
1853 tag++; /* point to the next tag */
1860 return 1; /* ssid not found in tagged param */
1862 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1865 static int assoc_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1867 struct rtllib_assoc_request_frame *a;
1869 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1870 sizeof(struct rtllib_info_element))) {
1871 netdev_dbg(dev, "invalid len in auth request:%d\n", skb->len);
1875 a = (struct rtllib_assoc_request_frame *) skb->data;
1877 ether_addr_copy(dest, a->header.addr2);
1882 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1885 struct rtllib_assoc_response_frame *response_head;
1888 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1889 netdev_dbg(ieee->dev, "Invalid len in auth resp: %d\n",
1894 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1895 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1897 status_code = le16_to_cpu(response_head->status);
1898 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1899 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1900 ((ieee->mode == IEEE_G) &&
1901 (ieee->current_network.mode == IEEE_N_24G) &&
1902 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1903 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1905 ieee->AsocRetryCount = 0;
1908 return le16_to_cpu(response_head->status);
1911 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1915 ieee->softmac_stats.rx_probe_rq++;
1916 if (probe_rq_parse(ieee, skb, dest) > 0) {
1917 ieee->softmac_stats.tx_probe_rs++;
1918 rtllib_resp_to_probe(ieee, dest);
1922 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1923 struct sk_buff *skb)
1928 ieee->softmac_stats.rx_auth_rq++;
1930 status = auth_rq_parse(ieee->dev, skb, dest);
1932 rtllib_resp_to_auth(ieee, status, dest);
1935 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1936 struct sk_buff *skb)
1941 ieee->softmac_stats.rx_ass_rq++;
1942 if (assoc_rq_parse(ieee->dev, skb, dest) != -1)
1943 rtllib_resp_to_assoc_rq(ieee, dest);
1945 netdev_info(ieee->dev, "New client associated: %pM\n", dest);
1948 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1951 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1954 softmac_ps_mgmt_xmit(buf, ieee);
1956 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1958 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1960 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1963 softmac_ps_mgmt_xmit(buf, ieee);
1966 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1970 struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
1972 if (ieee->LPSDelayCnt) {
1973 ieee->LPSDelayCnt--;
1977 dtim = ieee->current_network.dtim_data;
1978 if (!(dtim & RTLLIB_DTIM_VALID))
1980 timeout = ieee->current_network.beacon_interval;
1981 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
1982 /* there's no need to nofity AP that I find you buffered
1983 * with broadcast packet
1985 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
1988 if (!time_after(jiffies,
1989 dev_trans_start(ieee->dev) + msecs_to_jiffies(timeout)))
1991 if (!time_after(jiffies,
1992 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
1994 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
1995 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1999 if (ieee->bAwakePktSent) {
2000 pPSC->LPSAwakeIntvl = 1;
2004 if (pPSC->LPSAwakeIntvl == 0)
2005 pPSC->LPSAwakeIntvl = 1;
2006 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2008 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2009 MaxPeriod = ieee->current_network.dtim_period;
2011 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2012 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2013 MaxPeriod) ? MaxPeriod :
2014 (pPSC->LPSAwakeIntvl + 1);
2017 u8 LPSAwakeIntvl_tmp = 0;
2018 u8 period = ieee->current_network.dtim_period;
2019 u8 count = ieee->current_network.tim.tim_count;
2022 if (pPSC->LPSAwakeIntvl > period)
2023 LPSAwakeIntvl_tmp = period +
2024 (pPSC->LPSAwakeIntvl -
2026 ((pPSC->LPSAwakeIntvl-period) %
2029 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2032 if (pPSC->LPSAwakeIntvl >
2033 ieee->current_network.tim.tim_count)
2034 LPSAwakeIntvl_tmp = count +
2035 (pPSC->LPSAwakeIntvl - count) -
2036 ((pPSC->LPSAwakeIntvl-count)%period);
2038 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2041 *time = ieee->current_network.last_dtim_sta_time
2042 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2052 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2056 unsigned long flags, flags2;
2058 spin_lock_irqsave(&ieee->lock, flags);
2060 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2061 ieee->iw_mode != IW_MODE_INFRA ||
2062 ieee->state != RTLLIB_LINKED)) {
2064 "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n",
2065 __func__, ieee->ps, ieee->iw_mode, ieee->state);
2066 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2067 rtllib_sta_wakeup(ieee, 1);
2069 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2071 sleep = rtllib_sta_ps_sleep(ieee, &time);
2072 /* 2 wake, 1 sleep, 0 do nothing */
2076 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2077 ieee->enter_sleep_state(ieee->dev, time);
2078 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2079 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2081 if (ieee->ps_is_queue_empty(ieee->dev)) {
2082 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2083 ieee->ack_tx_to_ieee = 1;
2084 rtllib_sta_ps_send_null_frame(ieee, 1);
2085 ieee->ps_time = time;
2087 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2091 ieee->bAwakePktSent = false;
2093 } else if (sleep == 2) {
2094 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2096 rtllib_sta_wakeup(ieee, 1);
2098 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2102 spin_unlock_irqrestore(&ieee->lock, flags);
2106 static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2108 if (ieee->sta_sleep == LPS_IS_WAKE) {
2110 if (ieee->pHTInfo->IOTAction &
2111 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2112 ieee->ack_tx_to_ieee = 1;
2113 rtllib_sta_ps_send_null_frame(ieee, 0);
2115 ieee->ack_tx_to_ieee = 1;
2116 rtllib_sta_ps_send_pspoll_frame(ieee);
2123 if (ieee->sta_sleep == LPS_IS_SLEEP)
2124 ieee->sta_wake_up(ieee->dev);
2126 if (ieee->pHTInfo->IOTAction &
2127 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2128 ieee->ack_tx_to_ieee = 1;
2129 rtllib_sta_ps_send_null_frame(ieee, 0);
2131 ieee->ack_tx_to_ieee = 1;
2132 ieee->polling = true;
2133 rtllib_sta_ps_send_pspoll_frame(ieee);
2137 ieee->sta_sleep = LPS_IS_WAKE;
2138 ieee->polling = false;
2142 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2144 unsigned long flags, flags2;
2146 spin_lock_irqsave(&ieee->lock, flags);
2148 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2149 /* Null frame with PS bit set */
2151 ieee->sta_sleep = LPS_IS_SLEEP;
2152 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2154 /* if the card report not success we can't be sure the AP
2155 * has not RXed so we can't assume the AP believe us awake
2157 } else {/* 21112005 - tx again null without PS bit if lost */
2159 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2160 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2161 if (ieee->pHTInfo->IOTAction &
2162 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2163 rtllib_sta_ps_send_null_frame(ieee, 0);
2165 rtllib_sta_ps_send_pspoll_frame(ieee);
2166 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2169 spin_unlock_irqrestore(&ieee->lock, flags);
2171 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2173 static void rtllib_process_action(struct rtllib_device *ieee,
2174 struct sk_buff *skb)
2176 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2177 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2181 netdev_warn(ieee->dev,
2182 "Error getting payload of action frame\n");
2192 rtllib_rx_ADDBAReq(ieee, skb);
2195 rtllib_rx_ADDBARsp(ieee, skb);
2198 rtllib_rx_DELBA(ieee, skb);
2208 rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2209 struct rtllib_rx_stats *rx_stats)
2214 struct rtllib_assoc_response_frame *assoc_resp;
2215 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2216 u16 frame_ctl = le16_to_cpu(header->frame_ctl);
2218 netdev_dbg(ieee->dev, "received [RE]ASSOCIATION RESPONSE (%d)\n",
2219 WLAN_FC_GET_STYPE(frame_ctl));
2221 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2222 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2223 (ieee->iw_mode == IW_MODE_INFRA)) {
2224 errcode = assoc_parse(ieee, skb, &aid);
2226 struct rtllib_network *network =
2227 kzalloc(sizeof(struct rtllib_network),
2232 ieee->state = RTLLIB_LINKED;
2233 ieee->assoc_id = aid;
2234 ieee->softmac_stats.rx_ass_ok++;
2235 /* station support qos */
2236 /* Let the register setting default with Legacy station */
2237 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2238 if (ieee->current_network.qos_data.supported == 1) {
2239 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2240 rx_stats->len - sizeof(*assoc_resp),
2241 network, rx_stats)) {
2245 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2246 network->bssht.bdHTCapBuf,
2247 network->bssht.bdHTCapLen);
2248 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2249 network->bssht.bdHTInfoBuf,
2250 network->bssht.bdHTInfoLen);
2251 if (ieee->handle_assoc_response != NULL)
2252 ieee->handle_assoc_response(ieee->dev,
2253 (struct rtllib_assoc_response_frame *)header,
2258 kfree(ieee->assocresp_ies);
2259 ieee->assocresp_ies = NULL;
2260 ies = &(assoc_resp->info_element[0].id);
2261 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2262 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2264 if (ieee->assocresp_ies)
2265 memcpy(ieee->assocresp_ies, ies,
2266 ieee->assocresp_ies_len);
2268 netdev_info(ieee->dev,
2269 "%s()Warning: can't alloc memory for assocresp_ies\n",
2271 ieee->assocresp_ies_len = 0;
2273 rtllib_associate_complete(ieee);
2275 /* aid could not been allocated */
2276 ieee->softmac_stats.rx_ass_err++;
2277 netdev_info(ieee->dev,
2278 "Association response status code 0x%x\n",
2280 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2281 schedule_delayed_work(
2282 &ieee->associate_procedure_wq, 0);
2284 rtllib_associate_abort(ieee);
2290 static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
2295 bool bSupportNmode = true, bHalfSupportNmode = false;
2297 errcode = auth_parse(ieee->dev, skb, &challenge, &chlen);
2300 ieee->softmac_stats.rx_auth_rs_err++;
2301 netdev_info(ieee->dev,
2302 "Authentication response status code 0x%x",
2304 rtllib_associate_abort(ieee);
2308 if (ieee->open_wep || !challenge) {
2309 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2310 ieee->softmac_stats.rx_auth_rs_ok++;
2311 if (!(ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE)) {
2312 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2313 if (IsHTHalfNmodeAPs(ieee)) {
2314 bSupportNmode = true;
2315 bHalfSupportNmode = true;
2317 bSupportNmode = false;
2318 bHalfSupportNmode = false;
2322 /* Dummy wirless mode setting to avoid encryption issue */
2323 if (bSupportNmode) {
2324 ieee->SetWirelessMode(ieee->dev,
2325 ieee->current_network.mode);
2328 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2331 if ((ieee->current_network.mode == IEEE_N_24G) &&
2332 bHalfSupportNmode) {
2333 netdev_info(ieee->dev, "======>enter half N mode\n");
2334 ieee->bHalfWirelessN24GMode = true;
2336 ieee->bHalfWirelessN24GMode = false;
2338 rtllib_associate_step2(ieee);
2340 rtllib_auth_challenge(ieee, challenge, chlen);
2345 rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2346 struct rtllib_rx_stats *rx_stats)
2349 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2350 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2351 (ieee->iw_mode == IW_MODE_INFRA)) {
2352 netdev_dbg(ieee->dev,
2353 "Received authentication response");
2354 rtllib_rx_auth_resp(ieee, skb);
2355 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2356 rtllib_rx_auth_rq(ieee, skb);
2363 rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2365 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2368 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2371 /* FIXME for now repeat all the association procedure
2372 * both for disassociation and deauthentication
2374 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2375 ieee->state == RTLLIB_LINKED &&
2376 (ieee->iw_mode == IW_MODE_INFRA)) {
2377 frame_ctl = le16_to_cpu(header->frame_ctl);
2378 netdev_info(ieee->dev,
2379 "==========>received disassoc/deauth(%x) frame, reason code:%x\n",
2380 WLAN_FC_GET_STYPE(frame_ctl),
2381 ((struct rtllib_disassoc *)skb->data)->reason);
2382 ieee->state = RTLLIB_ASSOCIATING;
2383 ieee->softmac_stats.reassoc++;
2384 ieee->is_roaming = true;
2385 ieee->LinkDetectInfo.bBusyTraffic = false;
2386 rtllib_disassociate(ieee);
2387 RemovePeerTS(ieee, header->addr2);
2388 if (ieee->LedControlHandler != NULL)
2389 ieee->LedControlHandler(ieee->dev,
2390 LED_CTL_START_TO_LINK);
2392 if (!(ieee->rtllib_ap_sec_type(ieee) &
2393 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2394 schedule_delayed_work(
2395 &ieee->associate_procedure_wq, 5);
2400 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2401 struct sk_buff *skb,
2402 struct rtllib_rx_stats *rx_stats, u16 type,
2405 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2408 if (!ieee->proto_started)
2411 frame_ctl = le16_to_cpu(header->frame_ctl);
2412 switch (WLAN_FC_GET_STYPE(frame_ctl)) {
2413 case RTLLIB_STYPE_ASSOC_RESP:
2414 case RTLLIB_STYPE_REASSOC_RESP:
2415 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2418 case RTLLIB_STYPE_ASSOC_REQ:
2419 case RTLLIB_STYPE_REASSOC_REQ:
2420 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2421 ieee->iw_mode == IW_MODE_MASTER)
2422 rtllib_rx_assoc_rq(ieee, skb);
2424 case RTLLIB_STYPE_AUTH:
2425 rtllib_rx_auth(ieee, skb, rx_stats);
2427 case RTLLIB_STYPE_DISASSOC:
2428 case RTLLIB_STYPE_DEAUTH:
2429 rtllib_rx_deauth(ieee, skb);
2431 case RTLLIB_STYPE_MANAGE_ACT:
2432 rtllib_process_action(ieee, skb);
2440 /* following are for a simpler TX queue management.
2441 * Instead of using netif_[stop/wake]_queue the driver
2442 * will use these two functions (plus a reset one), that
2443 * will internally use the kernel netif_* and takes
2444 * care of the ieee802.11 fragmentation.
2445 * So the driver receives a fragment per time and might
2446 * call the stop function when it wants to not
2447 * have enough room to TX an entire packet.
2448 * This might be useful if each fragment needs it's own
2449 * descriptor, thus just keep a total free memory > than
2450 * the max fragmentation threshold is not enough.. If the
2451 * ieee802.11 stack passed a TXB struct then you need
2452 * to keep N free descriptors where
2453 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2454 * In this way you need just one and the 802.11 stack
2455 * will take care of buffering fragments and pass them to
2456 * to the driver later, when it wakes the queue.
2458 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2461 unsigned int queue_index = txb->queue_index;
2462 unsigned long flags;
2464 struct cb_desc *tcb_desc = NULL;
2465 unsigned long queue_len = 0;
2467 spin_lock_irqsave(&ieee->lock, flags);
2469 /* called with 2nd parm 0, no tx mgmt lock required */
2470 rtllib_sta_wakeup(ieee, 0);
2472 /* update the tx status */
2473 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2475 if (tcb_desc->bMulticast)
2476 ieee->stats.multicast++;
2478 /* if xmit available, just xmit it immediately, else just insert it to
2481 for (i = 0; i < txb->nr_frags; i++) {
2482 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2483 if ((queue_len != 0) ||
2484 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2485 (ieee->queue_stop)) {
2486 /* insert the skb packet to the wait queue
2487 * as for the completion function, it does not need
2488 * to check it any more.
2490 if (queue_len < 200)
2491 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2494 kfree_skb(txb->fragments[i]);
2496 ieee->softmac_data_hard_start_xmit(
2498 ieee->dev, ieee->rate);
2502 rtllib_txb_free(txb);
2504 spin_unlock_irqrestore(&ieee->lock, flags);
2508 void rtllib_reset_queue(struct rtllib_device *ieee)
2510 unsigned long flags;
2512 spin_lock_irqsave(&ieee->lock, flags);
2513 init_mgmt_queue(ieee);
2514 if (ieee->tx_pending.txb) {
2515 rtllib_txb_free(ieee->tx_pending.txb);
2516 ieee->tx_pending.txb = NULL;
2518 ieee->queue_stop = 0;
2519 spin_unlock_irqrestore(&ieee->lock, flags);
2522 EXPORT_SYMBOL(rtllib_reset_queue);
2524 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2528 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2529 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2531 netif_tx_stop_all_queues(ieee->dev);
2534 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2536 netif_tx_wake_all_queues(ieee->dev);
2539 /* called in user context only */
2540 static void rtllib_start_master_bss(struct rtllib_device *ieee)
2544 if (ieee->current_network.ssid_len == 0) {
2545 strncpy(ieee->current_network.ssid,
2546 RTLLIB_DEFAULT_TX_ESSID,
2549 ieee->current_network.ssid_len =
2550 strlen(RTLLIB_DEFAULT_TX_ESSID);
2554 ether_addr_copy(ieee->current_network.bssid, ieee->dev->dev_addr);
2556 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2557 ieee->state = RTLLIB_LINKED;
2558 ieee->link_change(ieee->dev);
2559 notify_wx_assoc_event(ieee);
2561 if (ieee->data_hard_resume)
2562 ieee->data_hard_resume(ieee->dev);
2564 netif_carrier_on(ieee->dev);
2567 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2569 /* reset hardware status */
2571 if (ieee->data_hard_resume)
2572 ieee->data_hard_resume(ieee->dev);
2574 netif_carrier_on(ieee->dev);
2578 static void rtllib_start_ibss_wq(void *data)
2580 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2581 struct rtllib_device, start_ibss_wq);
2582 /* iwconfig mode ad-hoc will schedule this and return
2583 * on the other hand this will block further iwconfig SET
2584 * operations because of the wx_mutex hold.
2585 * Anyway some most set operations set a flag to speed-up
2586 * (abort) this wq (when syncro scanning) before sleeping
2589 if (!ieee->proto_started) {
2590 netdev_info(ieee->dev, "==========oh driver down return\n");
2593 mutex_lock(&ieee->wx_mutex);
2595 if (ieee->current_network.ssid_len == 0) {
2596 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2597 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2601 ieee->state = RTLLIB_NOLINK;
2602 ieee->mode = IEEE_G;
2603 /* check if we have this cell in our network list */
2604 rtllib_softmac_check_all_nets(ieee);
2607 /* if not then the state is not linked. Maybe the user switched to
2608 * ad-hoc mode just after being in monitor mode, or just after
2609 * being very few time in managed mode (so the card have had no
2610 * time to scan all the chans..) or we have just run up the iface
2611 * after setting ad-hoc mode. So we have to give another try..
2612 * Here, in ibss mode, should be safe to do this without extra care
2613 * (in bss mode we had to make sure no-one tried to associate when
2614 * we had just checked the ieee->state and we was going to start the
2615 * scan) because in ibss mode the rtllib_new_net function, when
2616 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2617 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2618 * scan, that will stop at the first round because it sees the state
2621 if (ieee->state == RTLLIB_NOLINK)
2622 rtllib_start_scan_syncro(ieee, 0);
2624 /* the network definitively is not here.. create a new cell */
2625 if (ieee->state == RTLLIB_NOLINK) {
2626 netdev_info(ieee->dev, "creating new IBSS cell\n");
2627 ieee->current_network.channel = ieee->bss_start_channel;
2629 eth_random_addr(ieee->current_network.bssid);
2631 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2633 ieee->current_network.rates_len = 4;
2635 ieee->current_network.rates[0] =
2636 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2637 ieee->current_network.rates[1] =
2638 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2639 ieee->current_network.rates[2] =
2640 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2641 ieee->current_network.rates[3] =
2642 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2645 ieee->current_network.rates_len = 0;
2647 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2648 ieee->current_network.rates_ex_len = 8;
2650 ieee->current_network.rates_ex[0] =
2651 RTLLIB_OFDM_RATE_6MB;
2652 ieee->current_network.rates_ex[1] =
2653 RTLLIB_OFDM_RATE_9MB;
2654 ieee->current_network.rates_ex[2] =
2655 RTLLIB_OFDM_RATE_12MB;
2656 ieee->current_network.rates_ex[3] =
2657 RTLLIB_OFDM_RATE_18MB;
2658 ieee->current_network.rates_ex[4] =
2659 RTLLIB_OFDM_RATE_24MB;
2660 ieee->current_network.rates_ex[5] =
2661 RTLLIB_OFDM_RATE_36MB;
2662 ieee->current_network.rates_ex[6] =
2663 RTLLIB_OFDM_RATE_48MB;
2664 ieee->current_network.rates_ex[7] =
2665 RTLLIB_OFDM_RATE_54MB;
2669 ieee->current_network.rates_ex_len = 0;
2673 ieee->current_network.qos_data.supported = 0;
2674 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2675 ieee->current_network.mode = ieee->mode;
2676 ieee->current_network.atim_window = 0;
2677 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2680 netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2681 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2682 HTUseDefaultSetting(ieee);
2684 ieee->pHTInfo->bCurrentHTSupport = false;
2686 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2687 (u8 *)(&ieee->state));
2689 ieee->state = RTLLIB_LINKED;
2690 ieee->link_change(ieee->dev);
2692 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2693 if (ieee->LedControlHandler != NULL)
2694 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2696 rtllib_start_send_beacons(ieee);
2698 notify_wx_assoc_event(ieee);
2700 if (ieee->data_hard_resume)
2701 ieee->data_hard_resume(ieee->dev);
2703 netif_carrier_on(ieee->dev);
2705 mutex_unlock(&ieee->wx_mutex);
2708 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2710 schedule_delayed_work(&ieee->start_ibss_wq, msecs_to_jiffies(150));
2713 /* this is called only in user context, with wx_mutex held */
2714 static void rtllib_start_bss(struct rtllib_device *ieee)
2716 unsigned long flags;
2718 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2719 if (!ieee->global_domain)
2722 /* check if we have already found the net we
2723 * are interested in (if any).
2724 * if not (we are disassociated and we are not
2725 * in associating / authenticating phase) start the background scanning.
2727 rtllib_softmac_check_all_nets(ieee);
2729 /* ensure no-one start an associating process (thus setting
2730 * the ieee->state to rtllib_ASSOCIATING) while we
2731 * have just checked it and we are going to enable scan.
2732 * The rtllib_new_net function is always called with
2733 * lock held (from both rtllib_softmac_check_all_nets and
2734 * the rx path), so we cannot be in the middle of such function
2736 spin_lock_irqsave(&ieee->lock, flags);
2738 if (ieee->state == RTLLIB_NOLINK)
2739 rtllib_start_scan(ieee);
2740 spin_unlock_irqrestore(&ieee->lock, flags);
2743 static void rtllib_link_change_wq(void *data)
2745 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2746 struct rtllib_device, link_change_wq);
2747 ieee->link_change(ieee->dev);
2749 /* called only in userspace context */
2750 void rtllib_disassociate(struct rtllib_device *ieee)
2752 netif_carrier_off(ieee->dev);
2753 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2754 rtllib_reset_queue(ieee);
2756 if (ieee->data_hard_stop)
2757 ieee->data_hard_stop(ieee->dev);
2758 if (IS_DOT11D_ENABLE(ieee))
2760 ieee->state = RTLLIB_NOLINK;
2761 ieee->is_set_key = false;
2764 schedule_delayed_work(&ieee->link_change_wq, 0);
2766 notify_wx_assoc_event(ieee);
2769 static void rtllib_associate_retry_wq(void *data)
2771 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2772 struct rtllib_device, associate_retry_wq);
2773 unsigned long flags;
2775 mutex_lock(&ieee->wx_mutex);
2776 if (!ieee->proto_started)
2779 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2782 /* until we do not set the state to RTLLIB_NOLINK
2783 * there are no possibility to have someone else trying
2784 * to start an association procedure (we get here with
2785 * ieee->state = RTLLIB_ASSOCIATING).
2786 * When we set the state to RTLLIB_NOLINK it is possible
2787 * that the RX path run an attempt to associate, but
2788 * both rtllib_softmac_check_all_nets and the
2789 * RX path works with ieee->lock held so there are no
2790 * problems. If we are still disassociated then start a scan.
2791 * the lock here is necessary to ensure no one try to start
2792 * an association procedure when we have just checked the
2793 * state and we are going to start the scan.
2795 ieee->beinretry = true;
2796 ieee->state = RTLLIB_NOLINK;
2798 rtllib_softmac_check_all_nets(ieee);
2800 spin_lock_irqsave(&ieee->lock, flags);
2802 if (ieee->state == RTLLIB_NOLINK)
2803 rtllib_start_scan(ieee);
2804 spin_unlock_irqrestore(&ieee->lock, flags);
2806 ieee->beinretry = false;
2808 mutex_unlock(&ieee->wx_mutex);
2811 static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2813 static const u8 broadcast_addr[] = {
2814 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->dot11d_info = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
2975 if (!ieee->dot11d_info)
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 timer_setup(&ieee->associate_timer, rtllib_associate_abort_cb, 0);
3016 timer_setup(&ieee->beacon_timer, rtllib_send_beacon_cb, 0);
3018 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3019 (void *)rtllib_link_change_wq, ieee);
3020 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3021 (void *)rtllib_start_ibss_wq, ieee);
3022 INIT_WORK_RSL(&ieee->associate_complete_wq,
3023 (void *)rtllib_associate_complete_wq, ieee);
3024 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3025 (void *)rtllib_associate_procedure_wq, ieee);
3026 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3027 (void *)rtllib_softmac_scan_wq, ieee);
3028 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3029 (void *)rtllib_associate_retry_wq, ieee);
3030 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3033 mutex_init(&ieee->wx_mutex);
3034 mutex_init(&ieee->scan_mutex);
3035 mutex_init(&ieee->ips_mutex);
3037 spin_lock_init(&ieee->mgmt_tx_lock);
3038 spin_lock_init(&ieee->beacon_lock);
3040 tasklet_init(&ieee->ps_task,
3041 (void(*)(unsigned long)) rtllib_sta_ps,
3042 (unsigned long)ieee);
3046 void rtllib_softmac_free(struct rtllib_device *ieee)
3048 mutex_lock(&ieee->wx_mutex);
3049 kfree(ieee->dot11d_info);
3050 ieee->dot11d_info = NULL;
3051 del_timer_sync(&ieee->associate_timer);
3053 cancel_delayed_work_sync(&ieee->associate_retry_wq);
3054 cancel_delayed_work_sync(&ieee->associate_procedure_wq);
3055 cancel_delayed_work_sync(&ieee->softmac_scan_wq);
3056 cancel_delayed_work_sync(&ieee->start_ibss_wq);
3057 cancel_delayed_work_sync(&ieee->hw_wakeup_wq);
3058 cancel_delayed_work_sync(&ieee->hw_sleep_wq);
3059 cancel_delayed_work_sync(&ieee->link_change_wq);
3060 cancel_work_sync(&ieee->associate_complete_wq);
3061 cancel_work_sync(&ieee->ips_leave_wq);
3062 cancel_work_sync(&ieee->wx_sync_scan_wq);
3063 mutex_unlock(&ieee->wx_mutex);
3064 tasklet_kill(&ieee->ps_task);
3067 static inline struct sk_buff *
3068 rtllib_disauth_skb(struct rtllib_network *beacon,
3069 struct rtllib_device *ieee, u16 asRsn)
3071 struct sk_buff *skb;
3072 struct rtllib_disauth *disauth;
3073 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3075 skb = dev_alloc_skb(len);
3079 skb_reserve(skb, ieee->tx_headroom);
3081 disauth = skb_put(skb, sizeof(struct rtllib_disauth));
3082 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3083 disauth->header.duration_id = 0;
3085 ether_addr_copy(disauth->header.addr1, beacon->bssid);
3086 ether_addr_copy(disauth->header.addr2, ieee->dev->dev_addr);
3087 ether_addr_copy(disauth->header.addr3, beacon->bssid);
3089 disauth->reason = cpu_to_le16(asRsn);
3093 static inline struct sk_buff *
3094 rtllib_disassociate_skb(struct rtllib_network *beacon,
3095 struct rtllib_device *ieee, u16 asRsn)
3097 struct sk_buff *skb;
3098 struct rtllib_disassoc *disass;
3099 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3101 skb = dev_alloc_skb(len);
3106 skb_reserve(skb, ieee->tx_headroom);
3108 disass = skb_put(skb, sizeof(struct rtllib_disassoc));
3109 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3110 disass->header.duration_id = 0;
3112 ether_addr_copy(disass->header.addr1, beacon->bssid);
3113 ether_addr_copy(disass->header.addr2, ieee->dev->dev_addr);
3114 ether_addr_copy(disass->header.addr3, beacon->bssid);
3116 disass->reason = cpu_to_le16(asRsn);
3120 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3122 struct rtllib_network *beacon = &ieee->current_network;
3123 struct sk_buff *skb;
3126 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3128 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3131 softmac_mgmt_xmit(skb, ieee);
3134 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3136 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3137 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3138 int wpa_ie_len = ieee->wpa_ie_len;
3139 struct lib80211_crypt_data *crypt;
3142 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3143 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3144 || (ieee->host_encrypt && crypt && crypt->ops &&
3145 (strcmp(crypt->ops->name, "R-WEP") == 0));
3148 if (encrypt && (wpa_ie_len == 0)) {
3150 } else if ((wpa_ie_len != 0)) {
3151 if (((ieee->wpa_ie[0] == 0xdd) &&
3152 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3153 ((ieee->wpa_ie[0] == 0x30) &&
3154 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3155 return SEC_ALG_CCMP;
3157 return SEC_ALG_TKIP;
3159 return SEC_ALG_NONE;
3163 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3167 bool bFilterOutNonAssociatedBSSID = false;
3169 rtllib->state = RTLLIB_NOLINK;
3171 for (i = 0; i < 6; i++)
3172 rtllib->current_network.bssid[i] = 0x55;
3174 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3175 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3176 rtllib->current_network.bssid);
3177 OpMode = RT_OP_MODE_NO_LINK;
3178 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3179 rtllib_stop_send_beacons(rtllib);
3181 bFilterOutNonAssociatedBSSID = false;
3182 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3183 (u8 *)(&bFilterOutNonAssociatedBSSID));
3184 notify_wx_assoc_event(rtllib);
3188 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib,
3189 u8 *asSta, u8 asRsn)
3194 RemovePeerTS(rtllib, asSta);
3196 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3197 rtllib->state = RTLLIB_NOLINK;
3199 for (i = 0; i < 6; i++)
3200 rtllib->current_network.bssid[i] = 0x22;
3201 OpMode = RT_OP_MODE_NO_LINK;
3202 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3203 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3205 rtllib_disassociate(rtllib);
3207 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3208 rtllib->current_network.bssid);
3215 rtllib_MgntDisconnectAP(
3216 struct rtllib_device *rtllib,
3220 bool bFilterOutNonAssociatedBSSID = false;
3222 bFilterOutNonAssociatedBSSID = false;
3223 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3224 (u8 *)(&bFilterOutNonAssociatedBSSID));
3225 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3228 rtllib->state = RTLLIB_NOLINK;
3231 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3233 if (rtllib->ps != RTLLIB_PS_DISABLED)
3234 rtllib->sta_wake_up(rtllib->dev);
3236 if (rtllib->state == RTLLIB_LINKED) {
3237 if (rtllib->iw_mode == IW_MODE_ADHOC)
3238 rtllib_MgntDisconnectIBSS(rtllib);
3239 if (rtllib->iw_mode == IW_MODE_INFRA)
3240 rtllib_MgntDisconnectAP(rtllib, asRsn);
3246 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3248 void notify_wx_assoc_event(struct rtllib_device *ieee)
3250 union iwreq_data wrqu;
3252 if (ieee->cannot_notify)
3255 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3256 if (ieee->state == RTLLIB_LINKED)
3257 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3261 netdev_info(ieee->dev, "%s(): Tell user space disconnected\n",
3263 eth_zero_addr(wrqu.ap_addr.sa_data);
3265 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3267 EXPORT_SYMBOL(notify_wx_assoc_event);