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 short rtllib_is_54g(struct rtllib_network *net)
28 return (net->rates_ex_len > 0) || (net->rates_len > 4);
31 short rtllib_is_shortslot(const struct rtllib_network *net)
33 return net->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME;
36 /* returns the total length needed for placing the RATE MFIE
37 * tag and the EXTENDED RATE MFIE tag if needed.
38 * It encludes two bytes per tag for the tag itself and its len
40 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
42 unsigned int rate_len = 0;
44 if (ieee->modulation & RTLLIB_CCK_MODULATION)
45 rate_len = RTLLIB_CCK_RATE_LEN + 2;
47 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
49 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
54 /* place the MFIE rate, tag to the memory (double) pointed.
55 * Then it updates the pointer so that
56 * it points after the new MFIE tag added.
58 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
62 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
63 *tag++ = MFIE_TYPE_RATES;
65 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
66 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
67 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
68 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
71 /* We may add an option for custom rates that specific HW
77 static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p)
81 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
82 *tag++ = MFIE_TYPE_RATES_EX;
84 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
85 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
86 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
87 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
88 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
89 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
90 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
91 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;
93 /* We may add an option for custom rates that specific HW might
99 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
103 *tag++ = MFIE_TYPE_GENERIC;
115 void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
119 *tag++ = MFIE_TYPE_GENERIC;
130 netdev_alert(ieee->dev, "This is enable turbo mode IE process\n");
133 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
137 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
139 /* if the queue is full but we have newer frames then
140 * just overwrites the oldest.
142 * if (nh == ieee->mgmt_queue_tail)
145 ieee->mgmt_queue_head = nh;
146 ieee->mgmt_queue_ring[nh] = skb;
150 static struct sk_buff *dequeue_mgmt(struct rtllib_device *ieee)
154 if (ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
157 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
159 ieee->mgmt_queue_tail =
160 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
165 static void init_mgmt_queue(struct rtllib_device *ieee)
167 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
172 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
179 for (i = 0; i < ieee->current_network.rates_len; i++) {
180 BasicRate = ieee->current_network.rates[i]&0x7F;
181 if (!rtllib_is_cck_rate(BasicRate)) {
182 if (QueryRate == 0) {
183 QueryRate = BasicRate;
185 if (BasicRate < QueryRate)
186 QueryRate = BasicRate;
191 if (QueryRate == 0) {
193 netdev_info(ieee->dev, "No BasicRate found!!\n");
198 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
200 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
203 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
206 rate = ieee->basic_rate & 0x7f;
209 if (ieee->mode == IEEE_A ||
210 ieee->mode == IEEE_N_5G ||
211 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
220 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
223 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
224 struct rtllib_hdr_3addr *header =
225 (struct rtllib_hdr_3addr *) skb->data;
227 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
229 spin_lock_irqsave(&ieee->lock, flags);
231 /* called with 2nd param 0, no mgmt lock required */
232 rtllib_sta_wakeup(ieee, 0);
234 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
235 tcb_desc->queue_index = BEACON_QUEUE;
237 tcb_desc->queue_index = MGNT_QUEUE;
239 if (ieee->disable_mgnt_queue)
240 tcb_desc->queue_index = HIGH_QUEUE;
242 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
243 tcb_desc->RATRIndex = 7;
244 tcb_desc->bTxDisableRateFallBack = 1;
245 tcb_desc->bTxUseDriverAssingedRate = 1;
247 if (ieee->queue_stop) {
248 enqueue_mgmt(ieee, skb);
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 /* avoid watchdog triggers */
258 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
262 spin_unlock_irqrestore(&ieee->lock, flags);
264 spin_unlock_irqrestore(&ieee->lock, flags);
265 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
267 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
269 if (ieee->seq_ctrl[0] == 0xFFF)
270 ieee->seq_ctrl[0] = 0;
274 /* check whether the managed packet queued greater than 5 */
275 if (!ieee->check_nic_enough_desc(ieee->dev,
276 tcb_desc->queue_index) ||
277 skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) ||
279 /* insert the skb packet to the management queue
281 * as for the completion function, it does not need
282 * to check it any more.
284 netdev_info(ieee->dev,
285 "%s():insert to waitqueue, queue_index:%d!\n",
286 __func__, tcb_desc->queue_index);
287 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
290 ieee->softmac_hard_start_xmit(skb, ieee->dev);
292 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
296 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb,
297 struct rtllib_device *ieee)
299 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
300 struct rtllib_hdr_3addr *header =
301 (struct rtllib_hdr_3addr *) skb->data;
303 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
305 fc = le16_to_cpu(header->frame_ctl);
306 type = WLAN_FC_GET_TYPE(fc);
307 stype = WLAN_FC_GET_STYPE(fc);
310 if (stype != RTLLIB_STYPE_PSPOLL)
311 tcb_desc->queue_index = MGNT_QUEUE;
313 tcb_desc->queue_index = HIGH_QUEUE;
315 if (ieee->disable_mgnt_queue)
316 tcb_desc->queue_index = HIGH_QUEUE;
319 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
320 tcb_desc->RATRIndex = 7;
321 tcb_desc->bTxDisableRateFallBack = 1;
322 tcb_desc->bTxUseDriverAssingedRate = 1;
324 if (type != RTLLIB_FTYPE_CTL) {
325 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
327 if (ieee->seq_ctrl[0] == 0xFFF)
328 ieee->seq_ctrl[0] = 0;
333 /* avoid watchdog triggers */
334 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
338 if (type != RTLLIB_FTYPE_CTL) {
339 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
341 if (ieee->seq_ctrl[0] == 0xFFF)
342 ieee->seq_ctrl[0] = 0;
346 ieee->softmac_hard_start_xmit(skb, ieee->dev);
351 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
353 unsigned int len, rate_len;
356 struct rtllib_probe_request *req;
358 len = ieee->current_network.ssid_len;
360 rate_len = rtllib_MFIE_rate_len(ieee);
362 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
363 2 + len + rate_len + ieee->tx_headroom);
368 skb_reserve(skb, ieee->tx_headroom);
370 req = (struct rtllib_probe_request *) skb_put(skb,
371 sizeof(struct rtllib_probe_request));
372 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
373 req->header.duration_id = 0;
375 memset(req->header.addr1, 0xff, ETH_ALEN);
376 ether_addr_copy(req->header.addr2, ieee->dev->dev_addr);
377 memset(req->header.addr3, 0xff, ETH_ALEN);
379 tag = (u8 *) skb_put(skb, len + 2 + rate_len);
381 *tag++ = MFIE_TYPE_SSID;
383 memcpy(tag, ieee->current_network.ssid, len);
386 rtllib_MFIE_Brate(ieee, &tag);
387 rtllib_MFIE_Grate(ieee, &tag);
392 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
394 static void rtllib_send_beacon(struct rtllib_device *ieee)
400 skb = rtllib_get_beacon_(ieee);
403 softmac_mgmt_xmit(skb, ieee);
404 ieee->softmac_stats.tx_beacons++;
407 if (ieee->beacon_txing && ieee->ieee_up)
408 mod_timer(&ieee->beacon_timer, jiffies +
409 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
413 static void rtllib_send_beacon_cb(unsigned long _ieee)
415 struct rtllib_device *ieee =
416 (struct rtllib_device *) _ieee;
419 spin_lock_irqsave(&ieee->beacon_lock, flags);
420 rtllib_send_beacon(ieee);
421 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
424 /* Enables network monitor mode, all rx packets will be received. */
425 void rtllib_EnableNetMonitorMode(struct net_device *dev,
428 struct rtllib_device *ieee = netdev_priv_rsl(dev);
430 netdev_info(dev, "========>Enter Monitor Mode\n");
432 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
436 /* Disables network monitor mode. Only packets destinated to
437 * us will be received.
439 void rtllib_DisableNetMonitorMode(struct net_device *dev,
442 struct rtllib_device *ieee = netdev_priv_rsl(dev);
444 netdev_info(dev, "========>Exit Monitor Mode\n");
446 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
450 /* Enables the specialized promiscuous mode required by Intel.
451 * In this mode, Intel intends to hear traffics from/to other STAs in the
452 * same BSS. Therefore we don't have to disable checking BSSID and we only need
453 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
454 * packets from other STA.
456 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
459 bool bFilterOutNonAssociatedBSSID = false;
461 struct rtllib_device *ieee = netdev_priv_rsl(dev);
463 netdev_info(dev, "========>Enter Intel Promiscuous Mode\n");
465 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
466 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
467 (u8 *)&bFilterOutNonAssociatedBSSID);
469 ieee->bNetPromiscuousMode = true;
471 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
474 /* Disables the specialized promiscuous mode required by Intel.
475 * See MgntEnableIntelPromiscuousMode for detail.
477 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
480 bool bFilterOutNonAssociatedBSSID = true;
482 struct rtllib_device *ieee = netdev_priv_rsl(dev);
484 netdev_info(dev, "========>Exit Intel Promiscuous Mode\n");
486 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
487 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
488 (u8 *)&bFilterOutNonAssociatedBSSID);
490 ieee->bNetPromiscuousMode = false;
492 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
494 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
498 skb = rtllib_probe_req(ieee);
500 softmac_mgmt_xmit(skb, ieee);
501 ieee->softmac_stats.tx_probe_rq++;
506 void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
508 if (ieee->active_scan && (ieee->softmac_features &
509 IEEE_SOFTMAC_PROBERQ)) {
510 rtllib_send_probe(ieee, 0);
511 rtllib_send_probe(ieee, 0);
515 static void rtllib_softmac_hint11d_wq(void *data)
519 void rtllib_update_active_chan_map(struct rtllib_device *ieee)
521 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
522 MAX_CHANNEL_NUMBER+1);
525 /* this performs syncro scan blocking the caller until all channels
526 * in the allowed channel map has been checked.
528 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
530 union iwreq_data wrqu;
533 rtllib_update_active_chan_map(ieee);
535 ieee->be_scan_inprogress = true;
537 down(&ieee->scan_sem);
542 if (ch > MAX_CHANNEL_NUMBER)
543 goto out; /* scan completed */
544 } while (!ieee->active_channel_map[ch]);
546 /* this function can be called in two situations
547 * 1- We have switched to ad-hoc mode and we are
548 * performing a complete syncro scan before conclude
549 * there are no interesting cell and to create a
550 * new one. In this case the link state is
551 * RTLLIB_NOLINK until we found an interesting cell.
552 * If so the ieee8021_new_net, called by the RX path
553 * will set the state to RTLLIB_LINKED, so we stop
555 * 2- We are linked and the root uses run iwlist scan.
556 * So we switch to RTLLIB_LINKED_SCANNING to remember
557 * that we are still logically linked (not interested in
558 * new network events, despite for updating the net list,
559 * but we are temporarly 'unlinked' as the driver shall
560 * not filter RX frames and the channel is changing.
561 * So the only situation in which are interested is to check
562 * if the state become LINKED because of the #1 situation
565 if (ieee->state == RTLLIB_LINKED)
567 if (ieee->sync_scan_hurryup) {
568 netdev_info(ieee->dev,
569 "============>sync_scan_hurryup out\n");
573 ieee->set_chan(ieee->dev, ch);
574 if (ieee->active_channel_map[ch] == 1)
575 rtllib_send_probe_requests(ieee, 0);
577 /* this prevent excessive time wait when we
578 * need to wait for a syncro scan to end..
580 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
583 ieee->actscanning = false;
584 ieee->sync_scan_hurryup = 0;
586 if (ieee->state >= RTLLIB_LINKED) {
587 if (IS_DOT11D_ENABLE(ieee))
588 DOT11D_ScanComplete(ieee);
592 ieee->be_scan_inprogress = false;
594 memset(&wrqu, 0, sizeof(wrqu));
595 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
598 static void rtllib_softmac_scan_wq(void *data)
600 struct rtllib_device *ieee = container_of_dwork_rsl(data,
601 struct rtllib_device, softmac_scan_wq);
602 u8 last_channel = ieee->current_network.channel;
604 rtllib_update_active_chan_map(ieee);
608 if (rtllib_act_scanning(ieee, true))
611 down(&ieee->scan_sem);
613 if (ieee->eRFPowerState == eRfOff) {
614 netdev_info(ieee->dev,
615 "======>%s():rf state is eRfOff, return\n",
621 ieee->current_network.channel =
622 (ieee->current_network.channel + 1) %
624 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
625 if (!ieee->active_channel_map[ieee->current_network.channel])
626 ieee->current_network.channel = 6;
627 goto out; /* no good chans */
629 } while (!ieee->active_channel_map[ieee->current_network.channel]);
631 if (ieee->scanning_continue == 0)
634 ieee->set_chan(ieee->dev, ieee->current_network.channel);
636 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
637 rtllib_send_probe_requests(ieee, 0);
639 queue_delayed_work_rsl(ieee->wq, &ieee->softmac_scan_wq,
640 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
646 if (IS_DOT11D_ENABLE(ieee))
647 DOT11D_ScanComplete(ieee);
648 ieee->current_network.channel = last_channel;
651 ieee->actscanning = false;
652 ieee->scan_watch_dog = 0;
653 ieee->scanning_continue = 0;
659 static void rtllib_beacons_start(struct rtllib_device *ieee)
663 spin_lock_irqsave(&ieee->beacon_lock, flags);
665 ieee->beacon_txing = 1;
666 rtllib_send_beacon(ieee);
668 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
671 static void rtllib_beacons_stop(struct rtllib_device *ieee)
675 spin_lock_irqsave(&ieee->beacon_lock, flags);
677 ieee->beacon_txing = 0;
678 del_timer_sync(&ieee->beacon_timer);
680 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
685 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
687 if (ieee->stop_send_beacons)
688 ieee->stop_send_beacons(ieee->dev);
689 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
690 rtllib_beacons_stop(ieee);
692 EXPORT_SYMBOL(rtllib_stop_send_beacons);
695 void rtllib_start_send_beacons(struct rtllib_device *ieee)
697 if (ieee->start_send_beacons)
698 ieee->start_send_beacons(ieee->dev);
699 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
700 rtllib_beacons_start(ieee);
702 EXPORT_SYMBOL(rtllib_start_send_beacons);
705 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
707 down(&ieee->scan_sem);
708 ieee->scan_watch_dog = 0;
709 if (ieee->scanning_continue == 1) {
710 ieee->scanning_continue = 0;
711 ieee->actscanning = false;
713 cancel_delayed_work(&ieee->softmac_scan_wq);
719 void rtllib_stop_scan(struct rtllib_device *ieee)
721 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
722 rtllib_softmac_stop_scan(ieee);
724 if (ieee->rtllib_stop_hw_scan)
725 ieee->rtllib_stop_hw_scan(ieee->dev);
728 EXPORT_SYMBOL(rtllib_stop_scan);
730 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
732 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
733 ieee->sync_scan_hurryup = 1;
735 if (ieee->rtllib_stop_hw_scan)
736 ieee->rtllib_stop_hw_scan(ieee->dev);
739 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
741 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
743 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
745 return ieee->be_scan_inprogress;
747 return ieee->actscanning || ieee->be_scan_inprogress;
749 return test_bit(STATUS_SCANNING, &ieee->status);
752 EXPORT_SYMBOL(rtllib_act_scanning);
754 /* called with ieee->lock held */
755 static void rtllib_start_scan(struct rtllib_device *ieee)
757 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
758 if (ieee->rtllib_ips_leave_wq != NULL)
759 ieee->rtllib_ips_leave_wq(ieee->dev);
761 if (IS_DOT11D_ENABLE(ieee)) {
762 if (IS_COUNTRY_IE_VALID(ieee))
763 RESET_CIE_WATCHDOG(ieee);
765 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
766 if (ieee->scanning_continue == 0) {
767 ieee->actscanning = true;
768 ieee->scanning_continue = 1;
769 queue_delayed_work_rsl(ieee->wq,
770 &ieee->softmac_scan_wq, 0);
773 if (ieee->rtllib_start_hw_scan)
774 ieee->rtllib_start_hw_scan(ieee->dev);
778 /* called with wx_sem held */
779 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
781 if (IS_DOT11D_ENABLE(ieee)) {
782 if (IS_COUNTRY_IE_VALID(ieee))
783 RESET_CIE_WATCHDOG(ieee);
785 ieee->sync_scan_hurryup = 0;
786 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
787 rtllib_softmac_scan_syncro(ieee, is_mesh);
789 if (ieee->rtllib_start_hw_scan)
790 ieee->rtllib_start_hw_scan(ieee->dev);
793 EXPORT_SYMBOL(rtllib_start_scan_syncro);
795 inline struct sk_buff *rtllib_authentication_req(struct rtllib_network *beacon,
796 struct rtllib_device *ieee, int challengelen, u8 *daddr)
799 struct rtllib_authentication *auth;
802 len = sizeof(struct rtllib_authentication) + challengelen +
803 ieee->tx_headroom + 4;
804 skb = dev_alloc_skb(len);
809 skb_reserve(skb, ieee->tx_headroom);
811 auth = (struct rtllib_authentication *)
812 skb_put(skb, sizeof(struct rtllib_authentication));
814 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
816 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
818 auth->header.duration_id = cpu_to_le16(0x013a);
819 ether_addr_copy(auth->header.addr1, beacon->bssid);
820 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
821 ether_addr_copy(auth->header.addr3, beacon->bssid);
822 if (ieee->auth_mode == 0)
823 auth->algorithm = WLAN_AUTH_OPEN;
824 else if (ieee->auth_mode == 1)
825 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
826 else if (ieee->auth_mode == 2)
827 auth->algorithm = WLAN_AUTH_OPEN;
828 auth->transaction = cpu_to_le16(ieee->associate_seq);
829 ieee->associate_seq++;
831 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
836 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee,
841 struct rtllib_probe_response *beacon_buf;
842 struct sk_buff *skb = NULL;
844 int atim_len, erp_len;
845 struct lib80211_crypt_data *crypt;
847 char *ssid = ieee->current_network.ssid;
848 int ssid_len = ieee->current_network.ssid_len;
849 int rate_len = ieee->current_network.rates_len+2;
850 int rate_ex_len = ieee->current_network.rates_ex_len;
851 int wpa_ie_len = ieee->wpa_ie_len;
852 u8 erpinfo_content = 0;
854 u8 *tmp_ht_cap_buf = NULL;
855 u8 tmp_ht_cap_len = 0;
856 u8 *tmp_ht_info_buf = NULL;
857 u8 tmp_ht_info_len = 0;
858 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
859 u8 *tmp_generic_ie_buf = NULL;
860 u8 tmp_generic_ie_len = 0;
865 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
870 if ((ieee->current_network.mode == IEEE_G) ||
871 (ieee->current_network.mode == IEEE_N_24G &&
872 ieee->pHTInfo->bCurSuppCCK)) {
875 if (ieee->current_network.buseprotection)
876 erpinfo_content |= ERP_UseProtection;
880 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
881 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
882 ((0 == strcmp(crypt->ops->name, "R-WEP") || wpa_ie_len));
883 if (ieee->pHTInfo->bCurrentHTSupport) {
884 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
885 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
886 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
887 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
888 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
889 &tmp_ht_cap_len, encrypt, false);
890 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
893 if (pHTInfo->bRegRT2RTAggregation) {
894 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
896 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
897 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
898 &tmp_generic_ie_len);
902 beacon_size = sizeof(struct rtllib_probe_response)+2+
903 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
904 + wpa_ie_len + ieee->tx_headroom;
905 skb = dev_alloc_skb(beacon_size);
909 skb_reserve(skb, ieee->tx_headroom);
911 beacon_buf = (struct rtllib_probe_response *) skb_put(skb,
912 (beacon_size - ieee->tx_headroom));
913 ether_addr_copy(beacon_buf->header.addr1, dest);
914 ether_addr_copy(beacon_buf->header.addr2, ieee->dev->dev_addr);
915 ether_addr_copy(beacon_buf->header.addr3, ieee->current_network.bssid);
917 beacon_buf->header.duration_id = 0;
918 beacon_buf->beacon_interval =
919 cpu_to_le16(ieee->current_network.beacon_interval);
920 beacon_buf->capability =
921 cpu_to_le16(ieee->current_network.capability &
922 WLAN_CAPABILITY_IBSS);
923 beacon_buf->capability |=
924 cpu_to_le16(ieee->current_network.capability &
925 WLAN_CAPABILITY_SHORT_PREAMBLE);
927 if (ieee->short_slot && (ieee->current_network.capability &
928 WLAN_CAPABILITY_SHORT_SLOT_TIME))
929 beacon_buf->capability |=
930 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
932 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
934 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
937 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
938 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
939 beacon_buf->info_element[0].len = ssid_len;
941 tag = (u8 *) beacon_buf->info_element[0].data;
943 memcpy(tag, ssid, ssid_len);
947 *(tag++) = MFIE_TYPE_RATES;
948 *(tag++) = rate_len-2;
949 memcpy(tag, ieee->current_network.rates, rate_len-2);
952 *(tag++) = MFIE_TYPE_DS_SET;
954 *(tag++) = ieee->current_network.channel;
958 *(tag++) = MFIE_TYPE_IBSS_SET;
960 val16 = ieee->current_network.atim_window;
961 memcpy((u8 *)tag, (u8 *)&val16, 2);
966 *(tag++) = MFIE_TYPE_ERP;
968 *(tag++) = erpinfo_content;
971 *(tag++) = MFIE_TYPE_RATES_EX;
972 *(tag++) = rate_ex_len-2;
973 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
974 tag += rate_ex_len-2;
978 if (ieee->iw_mode == IW_MODE_ADHOC)
979 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
980 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
981 tag += ieee->wpa_ie_len;
986 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
991 struct lib80211_crypt_data *crypt;
992 struct rtllib_assoc_response_frame *assoc;
995 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
996 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
999 skb = dev_alloc_skb(len);
1004 skb_reserve(skb, ieee->tx_headroom);
1006 assoc = (struct rtllib_assoc_response_frame *)
1007 skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
1009 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
1010 ether_addr_copy(assoc->header.addr1, dest);
1011 ether_addr_copy(assoc->header.addr3, ieee->dev->dev_addr);
1012 ether_addr_copy(assoc->header.addr2, ieee->dev->dev_addr);
1013 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1014 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
1017 if (ieee->short_slot)
1018 assoc->capability |=
1019 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1021 if (ieee->host_encrypt)
1022 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1026 encrypt = (crypt && crypt->ops);
1029 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1032 assoc->aid = cpu_to_le16(ieee->assoc_id);
1033 if (ieee->assoc_id == 0x2007)
1038 tag = (u8 *) skb_put(skb, rate_len);
1039 rtllib_MFIE_Brate(ieee, &tag);
1040 rtllib_MFIE_Grate(ieee, &tag);
1045 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1048 struct sk_buff *skb = NULL;
1049 struct rtllib_authentication *auth;
1050 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1052 skb = dev_alloc_skb(len);
1056 skb->len = sizeof(struct rtllib_authentication);
1058 skb_reserve(skb, ieee->tx_headroom);
1060 auth = (struct rtllib_authentication *)
1061 skb_put(skb, sizeof(struct rtllib_authentication));
1063 auth->status = cpu_to_le16(status);
1064 auth->transaction = cpu_to_le16(2);
1065 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1067 ether_addr_copy(auth->header.addr3, ieee->dev->dev_addr);
1068 ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr);
1069 ether_addr_copy(auth->header.addr1, dest);
1070 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1076 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1078 struct sk_buff *skb;
1079 struct rtllib_hdr_3addr *hdr;
1081 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1085 skb_reserve(skb, ieee->tx_headroom);
1087 hdr = (struct rtllib_hdr_3addr *)skb_put(skb,
1088 sizeof(struct rtllib_hdr_3addr));
1090 ether_addr_copy(hdr->addr1, ieee->current_network.bssid);
1091 ether_addr_copy(hdr->addr2, ieee->dev->dev_addr);
1092 ether_addr_copy(hdr->addr3, ieee->current_network.bssid);
1094 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1095 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1096 (pwr ? RTLLIB_FCTL_PM : 0));
1103 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1105 struct sk_buff *skb;
1106 struct rtllib_pspoll_hdr *hdr;
1108 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1112 skb_reserve(skb, ieee->tx_headroom);
1114 hdr = (struct rtllib_pspoll_hdr *)skb_put(skb,
1115 sizeof(struct rtllib_pspoll_hdr));
1117 ether_addr_copy(hdr->bssid, ieee->current_network.bssid);
1118 ether_addr_copy(hdr->ta, ieee->dev->dev_addr);
1120 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1121 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1128 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1130 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1133 softmac_mgmt_xmit(buf, ieee);
1137 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1139 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1142 softmac_mgmt_xmit(buf, ieee);
1146 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1148 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1151 softmac_mgmt_xmit(buf, ieee);
1155 inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1160 if ((ieee->PMKIDList[i].bUsed) &&
1161 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1164 } while (i < NUM_PMKID_CACHE);
1166 if (i == NUM_PMKID_CACHE)
1171 inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1172 struct rtllib_device *ieee)
1174 struct sk_buff *skb;
1175 struct rtllib_assoc_request_frame *hdr;
1178 u8 *ht_cap_buf = NULL;
1180 u8 *realtek_ie_buf = NULL;
1181 u8 realtek_ie_len = 0;
1182 int wpa_ie_len = ieee->wpa_ie_len;
1183 int wps_ie_len = ieee->wps_ie_len;
1184 unsigned int ckip_ie_len = 0;
1185 unsigned int ccxrm_ie_len = 0;
1186 unsigned int cxvernum_ie_len = 0;
1187 struct lib80211_crypt_data *crypt;
1191 unsigned int rate_len = (beacon->rates_len ?
1192 (beacon->rates_len + 2) : 0) +
1193 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1196 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1197 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1201 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1203 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1204 ((0 == strcmp(crypt->ops->name, "R-WEP") ||
1209 if ((ieee->rtllib_ap_sec_type &&
1210 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1211 ieee->bForcedBgMode) {
1212 ieee->pHTInfo->bEnableHT = 0;
1213 ieee->mode = WIRELESS_MODE_G;
1216 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1217 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1218 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1219 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1221 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1222 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1224 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1225 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1230 if (beacon->bCkipSupported)
1232 if (beacon->bCcxRmEnable)
1234 if (beacon->BssCcxVerNumber >= 2)
1235 cxvernum_ie_len = 5+2;
1237 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1238 if (PMKCacheIdx >= 0) {
1240 netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n",
1243 len = sizeof(struct rtllib_assoc_request_frame) + 2
1255 + ieee->tx_headroom;
1257 skb = dev_alloc_skb(len);
1262 skb_reserve(skb, ieee->tx_headroom);
1264 hdr = (struct rtllib_assoc_request_frame *)
1265 skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1268 hdr->header.frame_ctl = RTLLIB_STYPE_ASSOC_REQ;
1269 hdr->header.duration_id = cpu_to_le16(37);
1270 ether_addr_copy(hdr->header.addr1, beacon->bssid);
1271 ether_addr_copy(hdr->header.addr2, ieee->dev->dev_addr);
1272 ether_addr_copy(hdr->header.addr3, beacon->bssid);
1274 ether_addr_copy(ieee->ap_mac_addr, beacon->bssid);
1276 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1277 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1278 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1280 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1281 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1283 if (ieee->short_slot &&
1284 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1285 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1288 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1290 hdr->info_element[0].id = MFIE_TYPE_SSID;
1292 hdr->info_element[0].len = beacon->ssid_len;
1293 tag = skb_put(skb, beacon->ssid_len);
1294 memcpy(tag, beacon->ssid, beacon->ssid_len);
1296 tag = skb_put(skb, rate_len);
1298 if (beacon->rates_len) {
1299 *tag++ = MFIE_TYPE_RATES;
1300 *tag++ = beacon->rates_len;
1301 for (i = 0; i < beacon->rates_len; i++)
1302 *tag++ = beacon->rates[i];
1305 if (beacon->rates_ex_len) {
1306 *tag++ = MFIE_TYPE_RATES_EX;
1307 *tag++ = beacon->rates_ex_len;
1308 for (i = 0; i < beacon->rates_ex_len; i++)
1309 *tag++ = beacon->rates_ex[i];
1312 if (beacon->bCkipSupported) {
1313 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1314 u8 CcxAironetBuf[30];
1315 struct octet_string osCcxAironetIE;
1317 memset(CcxAironetBuf, 0, 30);
1318 osCcxAironetIE.Octet = CcxAironetBuf;
1319 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1320 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1321 sizeof(AironetIeOui));
1323 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1324 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1325 tag = skb_put(skb, ckip_ie_len);
1326 *tag++ = MFIE_TYPE_AIRONET;
1327 *tag++ = osCcxAironetIE.Length;
1328 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1329 tag += osCcxAironetIE.Length;
1332 if (beacon->bCcxRmEnable) {
1333 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1335 struct octet_string osCcxRmCap;
1337 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1338 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1339 tag = skb_put(skb, ccxrm_ie_len);
1340 *tag++ = MFIE_TYPE_GENERIC;
1341 *tag++ = osCcxRmCap.Length;
1342 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1343 tag += osCcxRmCap.Length;
1346 if (beacon->BssCcxVerNumber >= 2) {
1347 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1348 struct octet_string osCcxVerNum;
1350 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1351 osCcxVerNum.Octet = CcxVerNumBuf;
1352 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1353 tag = skb_put(skb, cxvernum_ie_len);
1354 *tag++ = MFIE_TYPE_GENERIC;
1355 *tag++ = osCcxVerNum.Length;
1356 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1357 tag += osCcxVerNum.Length;
1359 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1360 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1361 tag = skb_put(skb, ht_cap_len);
1362 *tag++ = MFIE_TYPE_HT_CAP;
1363 *tag++ = ht_cap_len - 2;
1364 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1365 tag += ht_cap_len - 2;
1370 tag = skb_put(skb, ieee->wpa_ie_len);
1371 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1373 if (PMKCacheIdx >= 0) {
1374 tag = skb_put(skb, 18);
1377 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1382 tag = skb_put(skb, wmm_info_len);
1383 rtllib_WMM_Info(ieee, &tag);
1386 if (wps_ie_len && ieee->wps_ie) {
1387 tag = skb_put(skb, wps_ie_len);
1388 memcpy(tag, ieee->wps_ie, wps_ie_len);
1391 tag = skb_put(skb, turbo_info_len);
1393 rtllib_TURBO_Info(ieee, &tag);
1395 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1396 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1397 tag = skb_put(skb, ht_cap_len);
1398 *tag++ = MFIE_TYPE_GENERIC;
1399 *tag++ = ht_cap_len - 2;
1400 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1401 tag += ht_cap_len - 2;
1404 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1405 tag = skb_put(skb, realtek_ie_len);
1406 *tag++ = MFIE_TYPE_GENERIC;
1407 *tag++ = realtek_ie_len - 2;
1408 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1412 kfree(ieee->assocreq_ies);
1413 ieee->assocreq_ies = NULL;
1414 ies = &(hdr->info_element[0].id);
1415 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1416 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1417 if (ieee->assocreq_ies)
1418 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1420 netdev_info(ieee->dev,
1421 "%s()Warning: can't alloc memory for assocreq_ies\n",
1423 ieee->assocreq_ies_len = 0;
1428 void rtllib_associate_abort(struct rtllib_device *ieee)
1430 unsigned long flags;
1432 spin_lock_irqsave(&ieee->lock, flags);
1434 ieee->associate_seq++;
1436 /* don't scan, and avoid to have the RX path possibily
1437 * try again to associate. Even do not react to AUTH or
1438 * ASSOC response. Just wait for the retry wq to be scheduled.
1439 * Here we will check if there are good nets to associate
1440 * with, so we retry or just get back to NO_LINK and scanning
1442 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1443 netdev_dbg(ieee->dev, "Authentication failed\n");
1444 ieee->softmac_stats.no_auth_rs++;
1446 netdev_dbg(ieee->dev, "Association failed\n");
1447 ieee->softmac_stats.no_ass_rs++;
1450 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1452 queue_delayed_work_rsl(ieee->wq, &ieee->associate_retry_wq,
1453 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1455 spin_unlock_irqrestore(&ieee->lock, flags);
1458 static void rtllib_associate_abort_cb(unsigned long dev)
1460 rtllib_associate_abort((struct rtllib_device *) dev);
1463 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr)
1465 struct rtllib_network *beacon = &ieee->current_network;
1466 struct sk_buff *skb;
1468 netdev_dbg(ieee->dev, "Stopping scan\n");
1470 ieee->softmac_stats.tx_auth_rq++;
1472 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1475 rtllib_associate_abort(ieee);
1477 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING;
1478 netdev_dbg(ieee->dev, "Sending authentication request\n");
1479 softmac_mgmt_xmit(skb, ieee);
1480 if (!timer_pending(&ieee->associate_timer)) {
1481 ieee->associate_timer.expires = jiffies + (HZ / 2);
1482 add_timer(&ieee->associate_timer);
1487 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge,
1491 struct sk_buff *skb;
1492 struct rtllib_network *beacon = &ieee->current_network;
1494 ieee->associate_seq++;
1495 ieee->softmac_stats.tx_auth_rq++;
1497 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1500 rtllib_associate_abort(ieee);
1502 c = skb_put(skb, chlen+2);
1503 *(c++) = MFIE_TYPE_CHALLENGE;
1505 memcpy(c, challenge, chlen);
1507 netdev_dbg(ieee->dev,
1508 "Sending authentication challenge response\n");
1510 rtllib_encrypt_fragment(ieee, skb,
1511 sizeof(struct rtllib_hdr_3addr));
1513 softmac_mgmt_xmit(skb, ieee);
1514 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1519 static void rtllib_associate_step2(struct rtllib_device *ieee)
1521 struct sk_buff *skb;
1522 struct rtllib_network *beacon = &ieee->current_network;
1524 del_timer_sync(&ieee->associate_timer);
1526 netdev_dbg(ieee->dev, "Sending association request\n");
1528 ieee->softmac_stats.tx_ass_rq++;
1529 skb = rtllib_association_req(beacon, ieee);
1531 rtllib_associate_abort(ieee);
1533 softmac_mgmt_xmit(skb, ieee);
1534 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1539 static void rtllib_associate_complete_wq(void *data)
1541 struct rtllib_device *ieee = (struct rtllib_device *)
1542 container_of_work_rsl(data,
1543 struct rtllib_device,
1544 associate_complete_wq);
1545 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1546 (&(ieee->PowerSaveControl));
1547 netdev_info(ieee->dev, "Associated successfully\n");
1548 if (!ieee->is_silent_reset) {
1549 netdev_info(ieee->dev, "normal associate\n");
1550 notify_wx_assoc_event(ieee);
1553 netif_carrier_on(ieee->dev);
1554 ieee->is_roaming = false;
1555 if (rtllib_is_54g(&ieee->current_network) &&
1556 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1558 netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate);
1561 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1562 netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate);
1564 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1565 netdev_info(ieee->dev, "Successfully associated, ht enabled\n");
1568 netdev_info(ieee->dev,
1569 "Successfully associated, ht not enabled(%d, %d)\n",
1570 ieee->pHTInfo->bCurrentHTSupport,
1571 ieee->pHTInfo->bEnableHT);
1572 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1574 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1575 ieee->current_network.beacon_interval /
1577 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1578 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1579 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1580 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1582 pPSC->LpsIdleCount = 0;
1583 ieee->link_change(ieee->dev);
1585 if (ieee->is_silent_reset) {
1586 netdev_info(ieee->dev, "silent reset associate\n");
1587 ieee->is_silent_reset = false;
1590 if (ieee->data_hard_resume)
1591 ieee->data_hard_resume(ieee->dev);
1595 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1599 static void rtllib_associate_complete(struct rtllib_device *ieee)
1601 del_timer_sync(&ieee->associate_timer);
1603 ieee->state = RTLLIB_LINKED;
1604 rtllib_sta_send_associnfo(ieee);
1606 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1609 static void rtllib_associate_procedure_wq(void *data)
1611 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1612 struct rtllib_device,
1613 associate_procedure_wq);
1614 rtllib_stop_scan_syncro(ieee);
1615 if (ieee->rtllib_ips_leave != NULL)
1616 ieee->rtllib_ips_leave(ieee->dev);
1617 down(&ieee->wx_sem);
1619 if (ieee->data_hard_stop)
1620 ieee->data_hard_stop(ieee->dev);
1622 rtllib_stop_scan(ieee);
1623 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1624 ieee->current_network.channel);
1625 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1626 if (ieee->eRFPowerState == eRfOff) {
1628 "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n",
1630 if (ieee->rtllib_ips_leave_wq != NULL)
1631 ieee->rtllib_ips_leave_wq(ieee->dev);
1635 ieee->associate_seq = 1;
1637 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1642 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1643 struct rtllib_network *net)
1645 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1646 int tmp_ssid_len = 0;
1648 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1650 /* we are interested in new new only if we are not associated
1651 * and we are not associating / authenticating
1653 if (ieee->state != RTLLIB_NOLINK)
1656 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1657 WLAN_CAPABILITY_ESS))
1660 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1661 WLAN_CAPABILITY_IBSS))
1664 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1665 (net->channel > ieee->ibss_maxjoin_chal))
1667 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1668 /* if the user specified the AP MAC, we need also the essid
1669 * This could be obtained by beacons or, if the network does not
1670 * broadcast it, it can be put manually.
1672 apset = ieee->wap_set;
1673 ssidset = ieee->ssid_set;
1674 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1675 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1678 ssidmatch = (ieee->current_network.ssid_len ==
1679 net->hidden_ssid_len) &&
1680 (!strncmp(ieee->current_network.ssid,
1681 net->hidden_ssid, net->hidden_ssid_len));
1682 if (net->hidden_ssid_len > 0) {
1683 strncpy(net->ssid, net->hidden_ssid,
1684 net->hidden_ssid_len);
1685 net->ssid_len = net->hidden_ssid_len;
1690 (ieee->current_network.ssid_len == net->ssid_len) &&
1691 (!strncmp(ieee->current_network.ssid, net->ssid,
1694 /* if the user set the AP check if match.
1695 * if the network does not broadcast essid we check the
1696 * user supplied ANY essid
1697 * if the network does broadcast and the user does not set
1699 * if the network does broadcast and the user did set essid
1700 * check if essid match
1701 * if the ap is not set, check that the user set the bssid
1702 * and the network does broadcast and that those two bssid match
1704 if ((apset && apmatch &&
1705 ((ssidset && ssidbroad && ssidmatch) ||
1706 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1707 (!apset && ssidset && ssidbroad && ssidmatch) ||
1708 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1709 /* if the essid is hidden replace it with the
1710 * essid provided by the user.
1713 strncpy(tmp_ssid, ieee->current_network.ssid,
1715 tmp_ssid_len = ieee->current_network.ssid_len;
1717 memcpy(&ieee->current_network, net,
1718 sizeof(struct rtllib_network));
1720 strncpy(ieee->current_network.ssid, tmp_ssid,
1722 ieee->current_network.ssid_len = tmp_ssid_len;
1724 netdev_info(ieee->dev,
1725 "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",
1726 ieee->current_network.ssid,
1727 ieee->current_network.channel,
1728 ieee->current_network.qos_data.supported,
1729 ieee->pHTInfo->bEnableHT,
1730 ieee->current_network.bssht.bdSupportHT,
1731 ieee->current_network.mode,
1732 ieee->current_network.flags);
1734 if ((rtllib_act_scanning(ieee, false)) &&
1735 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1736 rtllib_stop_scan_syncro(ieee);
1738 ieee->hwscan_ch_bk = ieee->current_network.channel;
1739 HTResetIOTSetting(ieee->pHTInfo);
1741 if (ieee->iw_mode == IW_MODE_INFRA) {
1742 /* Join the network for the first time */
1743 ieee->AsocRetryCount = 0;
1744 if ((ieee->current_network.qos_data.supported == 1) &&
1745 ieee->current_network.bssht.bdSupportHT)
1746 HTResetSelfAndSavePeerSetting(ieee,
1747 &(ieee->current_network));
1749 ieee->pHTInfo->bCurrentHTSupport =
1752 ieee->state = RTLLIB_ASSOCIATING;
1753 if (ieee->LedControlHandler != NULL)
1754 ieee->LedControlHandler(ieee->dev,
1755 LED_CTL_START_TO_LINK);
1756 queue_delayed_work_rsl(ieee->wq,
1757 &ieee->associate_procedure_wq, 0);
1759 if (rtllib_is_54g(&ieee->current_network) &&
1761 RTLLIB_OFDM_MODULATION)) {
1763 ieee->SetWirelessMode(ieee->dev,
1765 netdev_info(ieee->dev,
1769 ieee->SetWirelessMode(ieee->dev,
1771 netdev_info(ieee->dev,
1774 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1775 ieee->state = RTLLIB_LINKED;
1781 void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1783 unsigned long flags;
1784 struct rtllib_network *target;
1786 spin_lock_irqsave(&ieee->lock, flags);
1788 list_for_each_entry(target, &ieee->network_list, list) {
1790 /* if the state become different that NOLINK means
1791 * we had found what we are searching for
1794 if (ieee->state != RTLLIB_NOLINK)
1797 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1798 ieee->scan_age, jiffies))
1799 rtllib_softmac_new_net(ieee, target);
1801 spin_unlock_irqrestore(&ieee->lock, flags);
1804 static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
1805 u8 **challenge, int *chlen)
1807 struct rtllib_authentication *a;
1810 if (skb->len < (sizeof(struct rtllib_authentication) -
1811 sizeof(struct rtllib_info_element))) {
1812 netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
1816 a = (struct rtllib_authentication *) skb->data;
1817 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1818 t = skb->data + sizeof(struct rtllib_authentication);
1820 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1822 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1827 return le16_to_cpu(a->status);
1830 static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1832 struct rtllib_authentication *a;
1834 if (skb->len < (sizeof(struct rtllib_authentication) -
1835 sizeof(struct rtllib_info_element))) {
1836 netdev_dbg(dev, "invalid len in auth request: %d\n", skb->len);
1839 a = (struct rtllib_authentication *) skb->data;
1841 ether_addr_copy(dest, a->header.addr2);
1843 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1844 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1846 return WLAN_STATUS_SUCCESS;
1849 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1856 struct rtllib_hdr_3addr *header =
1857 (struct rtllib_hdr_3addr *) skb->data;
1860 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1861 return -1; /* corrupted */
1864 (!ether_addr_equal(header->addr3, ieee->current_network.bssid)) &&
1865 (!is_broadcast_ether_addr(header->addr3));
1869 ether_addr_copy(src, header->addr2);
1871 skbend = (u8 *)skb->data + skb->len;
1873 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1875 while (tag + 1 < skbend) {
1878 ssidlen = *(tag + 1);
1881 tag++; /* point to the len field */
1882 tag = tag + *(tag); /* point to the last data byte of the tag */
1883 tag++; /* point to the next tag */
1890 return 1; /* ssid not found in tagged param */
1892 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1895 static int assoc_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
1897 struct rtllib_assoc_request_frame *a;
1899 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1900 sizeof(struct rtllib_info_element))) {
1901 netdev_dbg(dev, "invalid len in auth request:%d\n", skb->len);
1905 a = (struct rtllib_assoc_request_frame *) skb->data;
1907 ether_addr_copy(dest, a->header.addr2);
1912 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1915 struct rtllib_assoc_response_frame *response_head;
1918 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1919 netdev_dbg(ieee->dev, "Invalid len in auth resp: %d\n",
1924 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1925 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1927 status_code = le16_to_cpu(response_head->status);
1928 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1929 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1930 ((ieee->mode == IEEE_G) &&
1931 (ieee->current_network.mode == IEEE_N_24G) &&
1932 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1933 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1935 ieee->AsocRetryCount = 0;
1938 return le16_to_cpu(response_head->status);
1941 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1945 ieee->softmac_stats.rx_probe_rq++;
1946 if (probe_rq_parse(ieee, skb, dest) > 0) {
1947 ieee->softmac_stats.tx_probe_rs++;
1948 rtllib_resp_to_probe(ieee, dest);
1952 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1953 struct sk_buff *skb)
1958 ieee->softmac_stats.rx_auth_rq++;
1960 status = auth_rq_parse(ieee->dev, skb, dest);
1962 rtllib_resp_to_auth(ieee, status, dest);
1965 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1966 struct sk_buff *skb)
1971 ieee->softmac_stats.rx_ass_rq++;
1972 if (assoc_rq_parse(ieee->dev, skb, dest) != -1)
1973 rtllib_resp_to_assoc_rq(ieee, dest);
1975 netdev_info(ieee->dev, "New client associated: %pM\n", dest);
1978 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1981 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1984 softmac_ps_mgmt_xmit(buf, ieee);
1986 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1988 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1990 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1993 softmac_ps_mgmt_xmit(buf, ieee);
1996 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1998 int timeout = ieee->ps_timeout;
2000 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
2001 (&(ieee->PowerSaveControl));
2003 if (ieee->LPSDelayCnt) {
2004 ieee->LPSDelayCnt--;
2008 dtim = ieee->current_network.dtim_data;
2009 if (!(dtim & RTLLIB_DTIM_VALID))
2011 timeout = ieee->current_network.beacon_interval;
2012 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
2013 /* there's no need to nofity AP that I find you buffered
2014 * with broadcast packet
2016 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
2019 if (!time_after(jiffies,
2020 ieee->dev->trans_start + msecs_to_jiffies(timeout)))
2022 if (!time_after(jiffies,
2023 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
2025 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
2026 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
2030 if (ieee->bAwakePktSent) {
2031 pPSC->LPSAwakeIntvl = 1;
2035 if (pPSC->LPSAwakeIntvl == 0)
2036 pPSC->LPSAwakeIntvl = 1;
2037 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2039 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2040 MaxPeriod = ieee->current_network.dtim_period;
2042 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2043 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2044 MaxPeriod) ? MaxPeriod :
2045 (pPSC->LPSAwakeIntvl + 1);
2048 u8 LPSAwakeIntvl_tmp = 0;
2049 u8 period = ieee->current_network.dtim_period;
2050 u8 count = ieee->current_network.tim.tim_count;
2053 if (pPSC->LPSAwakeIntvl > period)
2054 LPSAwakeIntvl_tmp = period +
2055 (pPSC->LPSAwakeIntvl -
2057 ((pPSC->LPSAwakeIntvl-period) %
2060 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2063 if (pPSC->LPSAwakeIntvl >
2064 ieee->current_network.tim.tim_count)
2065 LPSAwakeIntvl_tmp = count +
2066 (pPSC->LPSAwakeIntvl - count) -
2067 ((pPSC->LPSAwakeIntvl-count)%period);
2069 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2072 *time = ieee->current_network.last_dtim_sta_time
2073 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2083 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2087 unsigned long flags, flags2;
2089 spin_lock_irqsave(&ieee->lock, flags);
2091 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2092 ieee->iw_mode != IW_MODE_INFRA ||
2093 ieee->state != RTLLIB_LINKED)) {
2095 "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n",
2096 __func__, ieee->ps, ieee->iw_mode, ieee->state);
2097 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2098 rtllib_sta_wakeup(ieee, 1);
2100 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2102 sleep = rtllib_sta_ps_sleep(ieee, &time);
2103 /* 2 wake, 1 sleep, 0 do nothing */
2107 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2108 ieee->enter_sleep_state(ieee->dev, time);
2109 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2110 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2112 if (ieee->ps_is_queue_empty(ieee->dev)) {
2113 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2114 ieee->ack_tx_to_ieee = 1;
2115 rtllib_sta_ps_send_null_frame(ieee, 1);
2116 ieee->ps_time = time;
2118 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2122 ieee->bAwakePktSent = false;
2124 } else if (sleep == 2) {
2125 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2127 rtllib_sta_wakeup(ieee, 1);
2129 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2133 spin_unlock_irqrestore(&ieee->lock, flags);
2137 void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2139 if (ieee->sta_sleep == LPS_IS_WAKE) {
2141 if (ieee->pHTInfo->IOTAction &
2142 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2143 ieee->ack_tx_to_ieee = 1;
2144 rtllib_sta_ps_send_null_frame(ieee, 0);
2146 ieee->ack_tx_to_ieee = 1;
2147 rtllib_sta_ps_send_pspoll_frame(ieee);
2154 if (ieee->sta_sleep == LPS_IS_SLEEP)
2155 ieee->sta_wake_up(ieee->dev);
2157 if (ieee->pHTInfo->IOTAction &
2158 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2159 ieee->ack_tx_to_ieee = 1;
2160 rtllib_sta_ps_send_null_frame(ieee, 0);
2162 ieee->ack_tx_to_ieee = 1;
2163 ieee->polling = true;
2164 rtllib_sta_ps_send_pspoll_frame(ieee);
2168 ieee->sta_sleep = LPS_IS_WAKE;
2169 ieee->polling = false;
2173 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2175 unsigned long flags, flags2;
2177 spin_lock_irqsave(&ieee->lock, flags);
2179 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2180 /* Null frame with PS bit set */
2182 ieee->sta_sleep = LPS_IS_SLEEP;
2183 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2185 /* if the card report not success we can't be sure the AP
2186 * has not RXed so we can't assume the AP believe us awake
2188 } else {/* 21112005 - tx again null without PS bit if lost */
2190 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2191 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2192 if (ieee->pHTInfo->IOTAction &
2193 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2194 rtllib_sta_ps_send_null_frame(ieee, 0);
2196 rtllib_sta_ps_send_pspoll_frame(ieee);
2197 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2200 spin_unlock_irqrestore(&ieee->lock, flags);
2202 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2204 static void rtllib_process_action(struct rtllib_device *ieee,
2205 struct sk_buff *skb)
2207 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2208 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2212 netdev_warn(ieee->dev,
2213 "Error getting payload of action frame\n");
2223 rtllib_rx_ADDBAReq(ieee, skb);
2226 rtllib_rx_ADDBARsp(ieee, skb);
2229 rtllib_rx_DELBA(ieee, skb);
2238 inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2239 struct rtllib_rx_stats *rx_stats)
2244 struct rtllib_assoc_response_frame *assoc_resp;
2245 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2247 netdev_dbg(ieee->dev, "received [RE]ASSOCIATION RESPONSE (%d)\n",
2248 WLAN_FC_GET_STYPE(header->frame_ctl));
2250 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2251 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2252 (ieee->iw_mode == IW_MODE_INFRA)) {
2253 errcode = assoc_parse(ieee, skb, &aid);
2255 struct rtllib_network *network =
2256 kzalloc(sizeof(struct rtllib_network),
2261 ieee->state = RTLLIB_LINKED;
2262 ieee->assoc_id = aid;
2263 ieee->softmac_stats.rx_ass_ok++;
2264 /* station support qos */
2265 /* Let the register setting default with Legacy station */
2266 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2267 if (ieee->current_network.qos_data.supported == 1) {
2268 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2269 rx_stats->len - sizeof(*assoc_resp),
2270 network, rx_stats)) {
2274 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2275 network->bssht.bdHTCapBuf,
2276 network->bssht.bdHTCapLen);
2277 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2278 network->bssht.bdHTInfoBuf,
2279 network->bssht.bdHTInfoLen);
2280 if (ieee->handle_assoc_response != NULL)
2281 ieee->handle_assoc_response(ieee->dev,
2282 (struct rtllib_assoc_response_frame *)header,
2287 kfree(ieee->assocresp_ies);
2288 ieee->assocresp_ies = NULL;
2289 ies = &(assoc_resp->info_element[0].id);
2290 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2291 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2293 if (ieee->assocresp_ies)
2294 memcpy(ieee->assocresp_ies, ies,
2295 ieee->assocresp_ies_len);
2297 netdev_info(ieee->dev,
2298 "%s()Warning: can't alloc memory for assocresp_ies\n",
2300 ieee->assocresp_ies_len = 0;
2302 rtllib_associate_complete(ieee);
2304 /* aid could not been allocated */
2305 ieee->softmac_stats.rx_ass_err++;
2306 netdev_info(ieee->dev,
2307 "Association response status code 0x%x\n",
2309 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2310 queue_delayed_work_rsl(ieee->wq,
2311 &ieee->associate_procedure_wq, 0);
2313 rtllib_associate_abort(ieee);
2319 static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
2324 bool bSupportNmode = true, bHalfSupportNmode = false;
2326 errcode = auth_parse(ieee->dev, skb, &challenge, &chlen);
2329 ieee->softmac_stats.rx_auth_rs_err++;
2330 netdev_info(ieee->dev,
2331 "Authentication respose status code 0x%x", errcode);
2332 rtllib_associate_abort(ieee);
2336 if (ieee->open_wep || !challenge) {
2337 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2338 ieee->softmac_stats.rx_auth_rs_ok++;
2339 if (!(ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE)) {
2340 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2341 if (IsHTHalfNmodeAPs(ieee)) {
2342 bSupportNmode = true;
2343 bHalfSupportNmode = true;
2345 bSupportNmode = false;
2346 bHalfSupportNmode = false;
2350 /* Dummy wirless mode setting to avoid encryption issue */
2351 if (bSupportNmode) {
2352 ieee->SetWirelessMode(ieee->dev,
2353 ieee->current_network.mode);
2356 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2359 if ((ieee->current_network.mode == IEEE_N_24G) &&
2360 bHalfSupportNmode) {
2361 netdev_info(ieee->dev, "======>enter half N mode\n");
2362 ieee->bHalfWirelessN24GMode = true;
2364 ieee->bHalfWirelessN24GMode = false;
2366 rtllib_associate_step2(ieee);
2368 rtllib_auth_challenge(ieee, challenge, chlen);
2372 inline int rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2373 struct rtllib_rx_stats *rx_stats)
2376 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2377 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2378 (ieee->iw_mode == IW_MODE_INFRA)) {
2379 netdev_dbg(ieee->dev,
2380 "Received authentication response");
2381 rtllib_rx_auth_resp(ieee, skb);
2382 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2383 rtllib_rx_auth_rq(ieee, skb);
2389 inline int rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2391 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2393 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2396 /* FIXME for now repeat all the association procedure
2397 * both for disassociation and deauthentication
2399 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2400 ieee->state == RTLLIB_LINKED &&
2401 (ieee->iw_mode == IW_MODE_INFRA)) {
2402 netdev_info(ieee->dev,
2403 "==========>received disassoc/deauth(%x) frame, reason code:%x\n",
2404 WLAN_FC_GET_STYPE(header->frame_ctl),
2405 ((struct rtllib_disassoc *)skb->data)->reason);
2406 ieee->state = RTLLIB_ASSOCIATING;
2407 ieee->softmac_stats.reassoc++;
2408 ieee->is_roaming = true;
2409 ieee->LinkDetectInfo.bBusyTraffic = false;
2410 rtllib_disassociate(ieee);
2411 RemovePeerTS(ieee, header->addr2);
2412 if (ieee->LedControlHandler != NULL)
2413 ieee->LedControlHandler(ieee->dev,
2414 LED_CTL_START_TO_LINK);
2416 if (!(ieee->rtllib_ap_sec_type(ieee) &
2417 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2418 queue_delayed_work_rsl(ieee->wq,
2419 &ieee->associate_procedure_wq, 5);
2424 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2425 struct sk_buff *skb,
2426 struct rtllib_rx_stats *rx_stats, u16 type,
2429 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2431 if (!ieee->proto_started)
2434 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2435 case RTLLIB_STYPE_ASSOC_RESP:
2436 case RTLLIB_STYPE_REASSOC_RESP:
2437 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2440 case RTLLIB_STYPE_ASSOC_REQ:
2441 case RTLLIB_STYPE_REASSOC_REQ:
2442 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2443 ieee->iw_mode == IW_MODE_MASTER)
2444 rtllib_rx_assoc_rq(ieee, skb);
2446 case RTLLIB_STYPE_AUTH:
2447 rtllib_rx_auth(ieee, skb, rx_stats);
2449 case RTLLIB_STYPE_DISASSOC:
2450 case RTLLIB_STYPE_DEAUTH:
2451 rtllib_rx_deauth(ieee, skb);
2453 case RTLLIB_STYPE_MANAGE_ACT:
2454 rtllib_process_action(ieee, skb);
2462 /* following are for a simpler TX queue management.
2463 * Instead of using netif_[stop/wake]_queue the driver
2464 * will use these two functions (plus a reset one), that
2465 * will internally use the kernel netif_* and takes
2466 * care of the ieee802.11 fragmentation.
2467 * So the driver receives a fragment per time and might
2468 * call the stop function when it wants to not
2469 * have enough room to TX an entire packet.
2470 * This might be useful if each fragment needs it's own
2471 * descriptor, thus just keep a total free memory > than
2472 * the max fragmentation threshold is not enough.. If the
2473 * ieee802.11 stack passed a TXB struct then you need
2474 * to keep N free descriptors where
2475 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2476 * In this way you need just one and the 802.11 stack
2477 * will take care of buffering fragments and pass them to
2478 * to the driver later, when it wakes the queue.
2480 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2483 unsigned int queue_index = txb->queue_index;
2484 unsigned long flags;
2486 struct cb_desc *tcb_desc = NULL;
2487 unsigned long queue_len = 0;
2489 spin_lock_irqsave(&ieee->lock, flags);
2491 /* called with 2nd parm 0, no tx mgmt lock required */
2492 rtllib_sta_wakeup(ieee, 0);
2494 /* update the tx status */
2495 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2497 if (tcb_desc->bMulticast)
2498 ieee->stats.multicast++;
2500 /* if xmit available, just xmit it immediately, else just insert it to
2503 for (i = 0; i < txb->nr_frags; i++) {
2504 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2505 if ((queue_len != 0) ||
2506 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2507 (ieee->queue_stop)) {
2508 /* insert the skb packet to the wait queue
2509 * as for the completion function, it does not need
2510 * to check it any more.
2512 if (queue_len < 200)
2513 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2516 kfree_skb(txb->fragments[i]);
2518 ieee->softmac_data_hard_start_xmit(
2520 ieee->dev, ieee->rate);
2524 rtllib_txb_free(txb);
2526 spin_unlock_irqrestore(&ieee->lock, flags);
2530 /* called with ieee->lock acquired */
2531 static void rtllib_resume_tx(struct rtllib_device *ieee)
2535 for (i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags;
2538 if (ieee->queue_stop) {
2539 ieee->tx_pending.frag = i;
2543 ieee->softmac_data_hard_start_xmit(
2544 ieee->tx_pending.txb->fragments[i],
2545 ieee->dev, ieee->rate);
2546 ieee->stats.tx_packets++;
2549 rtllib_txb_free(ieee->tx_pending.txb);
2550 ieee->tx_pending.txb = NULL;
2554 void rtllib_reset_queue(struct rtllib_device *ieee)
2556 unsigned long flags;
2558 spin_lock_irqsave(&ieee->lock, flags);
2559 init_mgmt_queue(ieee);
2560 if (ieee->tx_pending.txb) {
2561 rtllib_txb_free(ieee->tx_pending.txb);
2562 ieee->tx_pending.txb = NULL;
2564 ieee->queue_stop = 0;
2565 spin_unlock_irqrestore(&ieee->lock, flags);
2568 EXPORT_SYMBOL(rtllib_reset_queue);
2570 void rtllib_wake_queue(struct rtllib_device *ieee)
2573 unsigned long flags;
2574 struct sk_buff *skb;
2575 struct rtllib_hdr_3addr *header;
2577 spin_lock_irqsave(&ieee->lock, flags);
2578 if (!ieee->queue_stop)
2581 ieee->queue_stop = 0;
2583 if (ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) {
2584 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))) {
2586 header = (struct rtllib_hdr_3addr *) skb->data;
2588 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2590 if (ieee->seq_ctrl[0] == 0xFFF)
2591 ieee->seq_ctrl[0] = 0;
2593 ieee->seq_ctrl[0]++;
2595 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
2599 if (!ieee->queue_stop && ieee->tx_pending.txb)
2600 rtllib_resume_tx(ieee);
2602 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)) {
2603 ieee->softmac_stats.swtxawake++;
2604 netif_wake_queue(ieee->dev);
2608 spin_unlock_irqrestore(&ieee->lock, flags);
2612 void rtllib_stop_queue(struct rtllib_device *ieee)
2615 if (!netif_queue_stopped(ieee->dev)) {
2616 netif_stop_queue(ieee->dev);
2617 ieee->softmac_stats.swtxstop++;
2619 ieee->queue_stop = 1;
2623 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2627 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2628 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2630 netif_tx_stop_all_queues(ieee->dev);
2633 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2635 netif_tx_wake_all_queues(ieee->dev);
2638 inline void rtllib_randomize_cell(struct rtllib_device *ieee)
2641 random_ether_addr(ieee->current_network.bssid);
2644 /* called in user context only */
2645 void rtllib_start_master_bss(struct rtllib_device *ieee)
2649 if (ieee->current_network.ssid_len == 0) {
2650 strncpy(ieee->current_network.ssid,
2651 RTLLIB_DEFAULT_TX_ESSID,
2654 ieee->current_network.ssid_len =
2655 strlen(RTLLIB_DEFAULT_TX_ESSID);
2659 ether_addr_copy(ieee->current_network.bssid, ieee->dev->dev_addr);
2661 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2662 ieee->state = RTLLIB_LINKED;
2663 ieee->link_change(ieee->dev);
2664 notify_wx_assoc_event(ieee);
2666 if (ieee->data_hard_resume)
2667 ieee->data_hard_resume(ieee->dev);
2669 netif_carrier_on(ieee->dev);
2672 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2674 /* reset hardware status */
2676 if (ieee->data_hard_resume)
2677 ieee->data_hard_resume(ieee->dev);
2679 netif_carrier_on(ieee->dev);
2683 static void rtllib_start_ibss_wq(void *data)
2685 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2686 struct rtllib_device, start_ibss_wq);
2687 /* iwconfig mode ad-hoc will schedule this and return
2688 * on the other hand this will block further iwconfig SET
2689 * operations because of the wx_sem hold.
2690 * Anyway some most set operations set a flag to speed-up
2691 * (abort) this wq (when syncro scanning) before sleeping
2694 if (!ieee->proto_started) {
2695 netdev_info(ieee->dev, "==========oh driver down return\n");
2698 down(&ieee->wx_sem);
2700 if (ieee->current_network.ssid_len == 0) {
2701 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2702 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2706 ieee->state = RTLLIB_NOLINK;
2707 ieee->mode = IEEE_G;
2708 /* check if we have this cell in our network list */
2709 rtllib_softmac_check_all_nets(ieee);
2712 /* if not then the state is not linked. Maybe the user switched to
2713 * ad-hoc mode just after being in monitor mode, or just after
2714 * being very few time in managed mode (so the card have had no
2715 * time to scan all the chans..) or we have just run up the iface
2716 * after setting ad-hoc mode. So we have to give another try..
2717 * Here, in ibss mode, should be safe to do this without extra care
2718 * (in bss mode we had to make sure no-one tried to associate when
2719 * we had just checked the ieee->state and we was going to start the
2720 * scan) because in ibss mode the rtllib_new_net function, when
2721 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2722 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2723 * scan, that will stop at the first round because it sees the state
2726 if (ieee->state == RTLLIB_NOLINK)
2727 rtllib_start_scan_syncro(ieee, 0);
2729 /* the network definitively is not here.. create a new cell */
2730 if (ieee->state == RTLLIB_NOLINK) {
2731 netdev_info(ieee->dev, "creating new IBSS cell\n");
2732 ieee->current_network.channel = ieee->IbssStartChnl;
2734 rtllib_randomize_cell(ieee);
2736 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2738 ieee->current_network.rates_len = 4;
2740 ieee->current_network.rates[0] =
2741 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2742 ieee->current_network.rates[1] =
2743 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2744 ieee->current_network.rates[2] =
2745 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2746 ieee->current_network.rates[3] =
2747 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2750 ieee->current_network.rates_len = 0;
2752 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2753 ieee->current_network.rates_ex_len = 8;
2755 ieee->current_network.rates_ex[0] =
2756 RTLLIB_OFDM_RATE_6MB;
2757 ieee->current_network.rates_ex[1] =
2758 RTLLIB_OFDM_RATE_9MB;
2759 ieee->current_network.rates_ex[2] =
2760 RTLLIB_OFDM_RATE_12MB;
2761 ieee->current_network.rates_ex[3] =
2762 RTLLIB_OFDM_RATE_18MB;
2763 ieee->current_network.rates_ex[4] =
2764 RTLLIB_OFDM_RATE_24MB;
2765 ieee->current_network.rates_ex[5] =
2766 RTLLIB_OFDM_RATE_36MB;
2767 ieee->current_network.rates_ex[6] =
2768 RTLLIB_OFDM_RATE_48MB;
2769 ieee->current_network.rates_ex[7] =
2770 RTLLIB_OFDM_RATE_54MB;
2774 ieee->current_network.rates_ex_len = 0;
2778 ieee->current_network.qos_data.supported = 0;
2779 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2780 ieee->current_network.mode = ieee->mode;
2781 ieee->current_network.atim_window = 0;
2782 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2785 netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2786 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2787 HTUseDefaultSetting(ieee);
2789 ieee->pHTInfo->bCurrentHTSupport = false;
2791 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2792 (u8 *)(&ieee->state));
2794 ieee->state = RTLLIB_LINKED;
2795 ieee->link_change(ieee->dev);
2797 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2798 if (ieee->LedControlHandler != NULL)
2799 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2801 rtllib_start_send_beacons(ieee);
2803 notify_wx_assoc_event(ieee);
2805 if (ieee->data_hard_resume)
2806 ieee->data_hard_resume(ieee->dev);
2808 netif_carrier_on(ieee->dev);
2813 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2815 queue_delayed_work_rsl(ieee->wq, &ieee->start_ibss_wq,
2816 msecs_to_jiffies(150));
2819 /* this is called only in user context, with wx_sem held */
2820 void rtllib_start_bss(struct rtllib_device *ieee)
2822 unsigned long flags;
2824 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2825 if (!ieee->bGlobalDomain)
2828 /* check if we have already found the net we
2829 * are interested in (if any).
2830 * if not (we are disassociated and we are not
2831 * in associating / authenticating phase) start the background scanning.
2833 rtllib_softmac_check_all_nets(ieee);
2835 /* ensure no-one start an associating process (thus setting
2836 * the ieee->state to rtllib_ASSOCIATING) while we
2837 * have just checked it and we are going to enable scan.
2838 * The rtllib_new_net function is always called with
2839 * lock held (from both rtllib_softmac_check_all_nets and
2840 * the rx path), so we cannot be in the middle of such function
2842 spin_lock_irqsave(&ieee->lock, flags);
2844 if (ieee->state == RTLLIB_NOLINK)
2845 rtllib_start_scan(ieee);
2846 spin_unlock_irqrestore(&ieee->lock, flags);
2849 static void rtllib_link_change_wq(void *data)
2851 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2852 struct rtllib_device, link_change_wq);
2853 ieee->link_change(ieee->dev);
2855 /* called only in userspace context */
2856 void rtllib_disassociate(struct rtllib_device *ieee)
2858 netif_carrier_off(ieee->dev);
2859 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2860 rtllib_reset_queue(ieee);
2862 if (ieee->data_hard_stop)
2863 ieee->data_hard_stop(ieee->dev);
2864 if (IS_DOT11D_ENABLE(ieee))
2866 ieee->state = RTLLIB_NOLINK;
2867 ieee->is_set_key = false;
2870 queue_delayed_work_rsl(ieee->wq, &ieee->link_change_wq, 0);
2872 notify_wx_assoc_event(ieee);
2875 static void rtllib_associate_retry_wq(void *data)
2877 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2878 struct rtllib_device, associate_retry_wq);
2879 unsigned long flags;
2881 down(&ieee->wx_sem);
2882 if (!ieee->proto_started)
2885 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2888 /* until we do not set the state to RTLLIB_NOLINK
2889 * there are no possibility to have someone else trying
2890 * to start an association procedure (we get here with
2891 * ieee->state = RTLLIB_ASSOCIATING).
2892 * When we set the state to RTLLIB_NOLINK it is possible
2893 * that the RX path run an attempt to associate, but
2894 * both rtllib_softmac_check_all_nets and the
2895 * RX path works with ieee->lock held so there are no
2896 * problems. If we are still disassociated then start a scan.
2897 * the lock here is necessary to ensure no one try to start
2898 * an association procedure when we have just checked the
2899 * state and we are going to start the scan.
2901 ieee->beinretry = true;
2902 ieee->state = RTLLIB_NOLINK;
2904 rtllib_softmac_check_all_nets(ieee);
2906 spin_lock_irqsave(&ieee->lock, flags);
2908 if (ieee->state == RTLLIB_NOLINK)
2909 rtllib_start_scan(ieee);
2910 spin_unlock_irqrestore(&ieee->lock, flags);
2912 ieee->beinretry = false;
2917 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2919 const u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2921 struct sk_buff *skb;
2922 struct rtllib_probe_response *b;
2924 skb = rtllib_probe_resp(ieee, broadcast_addr);
2929 b = (struct rtllib_probe_response *) skb->data;
2930 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2936 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2938 struct sk_buff *skb;
2939 struct rtllib_probe_response *b;
2941 skb = rtllib_get_beacon_(ieee);
2945 b = (struct rtllib_probe_response *) skb->data;
2946 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2948 if (ieee->seq_ctrl[0] == 0xFFF)
2949 ieee->seq_ctrl[0] = 0;
2951 ieee->seq_ctrl[0]++;
2955 EXPORT_SYMBOL(rtllib_get_beacon);
2957 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2960 rtllib_stop_scan_syncro(ieee);
2961 down(&ieee->wx_sem);
2962 rtllib_stop_protocol(ieee, shutdown);
2965 EXPORT_SYMBOL(rtllib_softmac_stop_protocol);
2968 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2970 if (!ieee->proto_started)
2974 ieee->proto_started = 0;
2975 ieee->proto_stoppping = 1;
2976 if (ieee->rtllib_ips_leave != NULL)
2977 ieee->rtllib_ips_leave(ieee->dev);
2980 rtllib_stop_send_beacons(ieee);
2981 del_timer_sync(&ieee->associate_timer);
2982 cancel_delayed_work(&ieee->associate_retry_wq);
2983 cancel_delayed_work(&ieee->start_ibss_wq);
2984 cancel_delayed_work(&ieee->link_change_wq);
2985 rtllib_stop_scan(ieee);
2987 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2988 ieee->state = RTLLIB_NOLINK;
2990 if (ieee->state == RTLLIB_LINKED) {
2991 if (ieee->iw_mode == IW_MODE_INFRA)
2992 SendDisassociation(ieee, 1, WLAN_REASON_DEAUTH_LEAVING);
2993 rtllib_disassociate(ieee);
2998 ieee->proto_stoppping = 0;
3000 kfree(ieee->assocreq_ies);
3001 ieee->assocreq_ies = NULL;
3002 ieee->assocreq_ies_len = 0;
3003 kfree(ieee->assocresp_ies);
3004 ieee->assocresp_ies = NULL;
3005 ieee->assocresp_ies_len = 0;
3008 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
3010 down(&ieee->wx_sem);
3011 rtllib_start_protocol(ieee);
3014 EXPORT_SYMBOL(rtllib_softmac_start_protocol);
3016 void rtllib_start_protocol(struct rtllib_device *ieee)
3021 rtllib_update_active_chan_map(ieee);
3023 if (ieee->proto_started)
3026 ieee->proto_started = 1;
3028 if (ieee->current_network.channel == 0) {
3031 if (ch > MAX_CHANNEL_NUMBER)
3032 return; /* no channel found */
3033 } while (!ieee->active_channel_map[ch]);
3034 ieee->current_network.channel = ch;
3037 if (ieee->current_network.beacon_interval == 0)
3038 ieee->current_network.beacon_interval = 100;
3040 for (i = 0; i < 17; i++) {
3041 ieee->last_rxseq_num[i] = -1;
3042 ieee->last_rxfrag_num[i] = -1;
3043 ieee->last_packet_time[i] = 0;
3046 if (ieee->UpdateBeaconInterruptHandler)
3047 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
3050 /* if the user set the MAC of the ad-hoc cell and then
3051 * switch to managed mode, shall we make sure that association
3052 * attempts does not fail just because the user provide the essid
3053 * and the nic is still checking for the AP MAC ??
3055 if (ieee->iw_mode == IW_MODE_INFRA) {
3056 rtllib_start_bss(ieee);
3057 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
3058 if (ieee->UpdateBeaconInterruptHandler)
3059 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
3061 rtllib_start_ibss(ieee);
3063 } else if (ieee->iw_mode == IW_MODE_MASTER) {
3064 rtllib_start_master_bss(ieee);
3065 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
3066 rtllib_start_monitor_mode(ieee);
3070 void rtllib_softmac_init(struct rtllib_device *ieee)
3074 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
3076 ieee->state = RTLLIB_NOLINK;
3077 for (i = 0; i < 5; i++)
3078 ieee->seq_ctrl[i] = 0;
3079 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
3080 if (!ieee->pDot11dInfo)
3081 netdev_err(ieee->dev, "Can't alloc memory for DOT11D\n");
3082 ieee->LinkDetectInfo.SlotIndex = 0;
3083 ieee->LinkDetectInfo.SlotNum = 2;
3084 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3085 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
3086 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3087 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3088 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
3089 ieee->bIsAggregateFrame = false;
3091 ieee->queue_stop = 0;
3092 ieee->scanning_continue = 0;
3093 ieee->softmac_features = 0;
3096 ieee->proto_started = 0;
3097 ieee->proto_stoppping = 0;
3098 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
3100 ieee->ps = RTLLIB_PS_DISABLED;
3101 ieee->sta_sleep = LPS_IS_WAKE;
3103 ieee->Regdot11HTOperationalRateSet[0] = 0xff;
3104 ieee->Regdot11HTOperationalRateSet[1] = 0xff;
3105 ieee->Regdot11HTOperationalRateSet[4] = 0x01;
3107 ieee->Regdot11TxHTOperationalRateSet[0] = 0xff;
3108 ieee->Regdot11TxHTOperationalRateSet[1] = 0xff;
3109 ieee->Regdot11TxHTOperationalRateSet[4] = 0x01;
3111 ieee->FirstIe_InScan = false;
3112 ieee->actscanning = false;
3113 ieee->beinretry = false;
3114 ieee->is_set_key = false;
3115 init_mgmt_queue(ieee);
3117 ieee->sta_edca_param[0] = 0x0000A403;
3118 ieee->sta_edca_param[1] = 0x0000A427;
3119 ieee->sta_edca_param[2] = 0x005E4342;
3120 ieee->sta_edca_param[3] = 0x002F3262;
3121 ieee->aggregation = true;
3122 ieee->enable_rx_imm_BA = true;
3123 ieee->tx_pending.txb = NULL;
3125 _setup_timer(&ieee->associate_timer,
3126 rtllib_associate_abort_cb,
3127 (unsigned long) ieee);
3129 _setup_timer(&ieee->beacon_timer,
3130 rtllib_send_beacon_cb,
3131 (unsigned long) ieee);
3134 ieee->wq = create_workqueue(DRV_NAME);
3136 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3137 (void *)rtllib_link_change_wq, ieee);
3138 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3139 (void *)rtllib_start_ibss_wq, ieee);
3140 INIT_WORK_RSL(&ieee->associate_complete_wq,
3141 (void *)rtllib_associate_complete_wq, ieee);
3142 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3143 (void *)rtllib_associate_procedure_wq, ieee);
3144 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3145 (void *)rtllib_softmac_scan_wq, ieee);
3146 INIT_DELAYED_WORK_RSL(&ieee->softmac_hint11d_wq,
3147 (void *)rtllib_softmac_hint11d_wq, ieee);
3148 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3149 (void *)rtllib_associate_retry_wq, ieee);
3150 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3153 sema_init(&ieee->wx_sem, 1);
3154 sema_init(&ieee->scan_sem, 1);
3155 sema_init(&ieee->ips_sem, 1);
3157 spin_lock_init(&ieee->mgmt_tx_lock);
3158 spin_lock_init(&ieee->beacon_lock);
3160 tasklet_init(&ieee->ps_task,
3161 (void(*)(unsigned long)) rtllib_sta_ps,
3162 (unsigned long)ieee);
3166 void rtllib_softmac_free(struct rtllib_device *ieee)
3168 down(&ieee->wx_sem);
3169 kfree(ieee->pDot11dInfo);
3170 ieee->pDot11dInfo = NULL;
3171 del_timer_sync(&ieee->associate_timer);
3173 cancel_delayed_work(&ieee->associate_retry_wq);
3174 destroy_workqueue(ieee->wq);
3176 tasklet_kill(&ieee->ps_task);
3179 /********************************************************
3180 * Start of WPA code. *
3181 * this is stolen from the ipw2200 driver *
3182 ********************************************************/
3185 static int rtllib_wpa_enable(struct rtllib_device *ieee, int value)
3187 /* This is called when wpa_supplicant loads and closes the driver
3190 netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling");
3191 ieee->wpa_enabled = value;
3192 memset(ieee->ap_mac_addr, 0, 6);
3197 static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie,
3200 /* make sure WPA is enabled */
3201 rtllib_wpa_enable(ieee, 1);
3203 rtllib_disassociate(ieee);
3207 static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason)
3213 case IEEE_MLME_STA_DEAUTH:
3216 case IEEE_MLME_STA_DISASSOC:
3217 rtllib_disassociate(ieee);
3221 netdev_info(ieee->dev, "Unknown MLME request: %d\n", command);
3229 static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee,
3230 struct ieee_param *param, int plen)
3234 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3235 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3238 if (param->u.wpa_ie.len) {
3239 buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
3244 kfree(ieee->wpa_ie);
3246 ieee->wpa_ie_len = param->u.wpa_ie.len;
3248 kfree(ieee->wpa_ie);
3249 ieee->wpa_ie = NULL;
3250 ieee->wpa_ie_len = 0;
3253 rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3257 #define AUTH_ALG_OPEN_SYSTEM 0x1
3258 #define AUTH_ALG_SHARED_KEY 0x2
3259 #define AUTH_ALG_LEAP 0x4
3260 static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value)
3263 struct rtllib_security sec = {
3264 .flags = SEC_AUTH_MODE,
3267 if (value & AUTH_ALG_SHARED_KEY) {
3268 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3270 ieee->auth_mode = 1;
3271 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
3272 sec.auth_mode = WLAN_AUTH_OPEN;
3274 ieee->auth_mode = 0;
3275 } else if (value & AUTH_ALG_LEAP) {
3276 sec.auth_mode = WLAN_AUTH_LEAP >> 6;
3278 ieee->auth_mode = 2;
3282 if (ieee->set_security)
3283 ieee->set_security(ieee->dev, &sec);
3288 static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value)
3291 unsigned long flags;
3294 case IEEE_PARAM_WPA_ENABLED:
3295 ret = rtllib_wpa_enable(ieee, value);
3298 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3299 ieee->tkip_countermeasures = value;
3302 case IEEE_PARAM_DROP_UNENCRYPTED:
3306 * wpa_supplicant calls set_wpa_enabled when the driver
3307 * is loaded and unloaded, regardless of if WPA is being
3308 * used. No other calls are made which can be used to
3309 * determine if encryption will be used or not prior to
3310 * association being expected. If encryption is not being
3311 * used, drop_unencrypted is set to false, else true -- we
3312 * can use this to determine if the CAP_PRIVACY_ON bit should
3315 struct rtllib_security sec = {
3316 .flags = SEC_ENABLED,
3319 ieee->drop_unencrypted = value;
3320 /* We only change SEC_LEVEL for open mode. Others
3321 * are set by ipw_wpa_set_encryption.
3324 sec.flags |= SEC_LEVEL;
3325 sec.level = SEC_LEVEL_0;
3327 sec.flags |= SEC_LEVEL;
3328 sec.level = SEC_LEVEL_1;
3330 if (ieee->set_security)
3331 ieee->set_security(ieee->dev, &sec);
3335 case IEEE_PARAM_PRIVACY_INVOKED:
3336 ieee->privacy_invoked = value;
3339 case IEEE_PARAM_AUTH_ALGS:
3340 ret = rtllib_wpa_set_auth_algs(ieee, value);
3343 case IEEE_PARAM_IEEE_802_1X:
3344 ieee->ieee802_1x = value;
3346 case IEEE_PARAM_WPAX_SELECT:
3347 spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags);
3348 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags);
3352 netdev_info(ieee->dev, "Unknown WPA param: %d\n", name);
3359 /* implementation borrowed from hostap driver */
3360 static int rtllib_wpa_set_encryption(struct rtllib_device *ieee,
3361 struct ieee_param *param, int param_len,
3365 struct lib80211_crypto_ops *ops;
3366 struct lib80211_crypt_data **crypt;
3368 struct rtllib_security sec = {
3372 param->u.crypt.err = 0;
3373 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3376 (int) ((char *) param->u.crypt.key - (char *) param) +
3377 param->u.crypt.key_len) {
3378 netdev_info(ieee->dev, "Len mismatch %d, %d\n", param_len,
3379 param->u.crypt.key_len);
3382 if (is_broadcast_ether_addr(param->sta_addr)) {
3383 if (param->u.crypt.idx >= NUM_WEP_KEYS)
3385 crypt = &ieee->crypt_info.crypt[param->u.crypt.idx];
3390 if (strcmp(param->u.crypt.alg, "none") == 0) {
3393 sec.level = SEC_LEVEL_0;
3394 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3395 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3400 sec.flags |= SEC_ENABLED;
3402 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3403 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3404 strcmp(param->u.crypt.alg, "R-TKIP"))
3405 goto skip_host_crypt;
3407 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3408 if (ops == NULL && strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3409 request_module("rtllib_crypt_wep");
3410 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3411 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3412 request_module("rtllib_crypt_tkip");
3413 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3414 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3415 request_module("rtllib_crypt_ccmp");
3416 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3419 netdev_info(ieee->dev, "unknown crypto alg '%s'\n",
3420 param->u.crypt.alg);
3421 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3425 if (*crypt == NULL || (*crypt)->ops != ops) {
3426 struct lib80211_crypt_data *new_crypt;
3428 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3430 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
3431 if (new_crypt == NULL) {
3435 new_crypt->ops = ops;
3438 new_crypt->ops->init(param->u.crypt.idx);
3440 if (new_crypt->priv == NULL) {
3442 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3450 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3451 (*crypt)->ops->set_key(param->u.crypt.key,
3452 param->u.crypt.key_len, param->u.crypt.seq,
3453 (*crypt)->priv) < 0) {
3454 netdev_info(ieee->dev, "key setting failed\n");
3455 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3461 if (param->u.crypt.set_tx) {
3462 ieee->crypt_info.tx_keyidx = param->u.crypt.idx;
3463 sec.active_key = param->u.crypt.idx;
3464 sec.flags |= SEC_ACTIVE_KEY;
3466 sec.flags &= ~SEC_ACTIVE_KEY;
3468 if (param->u.crypt.alg != NULL) {
3469 memcpy(sec.keys[param->u.crypt.idx],
3471 param->u.crypt.key_len);
3472 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3473 sec.flags |= (1 << param->u.crypt.idx);
3475 if (strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3476 sec.flags |= SEC_LEVEL;
3477 sec.level = SEC_LEVEL_1;
3478 } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3479 sec.flags |= SEC_LEVEL;
3480 sec.level = SEC_LEVEL_2;
3481 } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3482 sec.flags |= SEC_LEVEL;
3483 sec.level = SEC_LEVEL_3;
3487 if (ieee->set_security)
3488 ieee->set_security(ieee->dev, &sec);
3490 /* Do not reset port if card is in Managed mode since resetting will
3491 * generate new IEEE 802.11 authentication which may end up in looping
3492 * with IEEE 802.1X. If your hardware requires a reset after WEP
3493 * configuration (for example... Prism2), implement the reset_port in
3494 * the callbacks structures used to initialize the 802.11 stack.
3496 if (ieee->reset_on_keychange &&
3497 ieee->iw_mode != IW_MODE_INFRA &&
3499 ieee->reset_port(ieee->dev)) {
3500 netdev_info(ieee->dev, "reset_port failed\n");
3501 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3508 inline struct sk_buff *rtllib_disauth_skb(struct rtllib_network *beacon,
3509 struct rtllib_device *ieee, u16 asRsn)
3511 struct sk_buff *skb;
3512 struct rtllib_disauth *disauth;
3513 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3515 skb = dev_alloc_skb(len);
3519 skb_reserve(skb, ieee->tx_headroom);
3521 disauth = (struct rtllib_disauth *) skb_put(skb,
3522 sizeof(struct rtllib_disauth));
3523 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3524 disauth->header.duration_id = 0;
3526 ether_addr_copy(disauth->header.addr1, beacon->bssid);
3527 ether_addr_copy(disauth->header.addr2, ieee->dev->dev_addr);
3528 ether_addr_copy(disauth->header.addr3, beacon->bssid);
3530 disauth->reason = cpu_to_le16(asRsn);
3534 inline struct sk_buff *rtllib_disassociate_skb(struct rtllib_network *beacon,
3535 struct rtllib_device *ieee, u16 asRsn)
3537 struct sk_buff *skb;
3538 struct rtllib_disassoc *disass;
3539 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3541 skb = dev_alloc_skb(len);
3546 skb_reserve(skb, ieee->tx_headroom);
3548 disass = (struct rtllib_disassoc *) skb_put(skb,
3549 sizeof(struct rtllib_disassoc));
3550 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3551 disass->header.duration_id = 0;
3553 ether_addr_copy(disass->header.addr1, beacon->bssid);
3554 ether_addr_copy(disass->header.addr2, ieee->dev->dev_addr);
3555 ether_addr_copy(disass->header.addr3, beacon->bssid);
3557 disass->reason = cpu_to_le16(asRsn);
3561 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3563 struct rtllib_network *beacon = &ieee->current_network;
3564 struct sk_buff *skb;
3567 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3569 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3572 softmac_mgmt_xmit(skb, ieee);
3575 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3577 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3578 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3579 int wpa_ie_len = ieee->wpa_ie_len;
3580 struct lib80211_crypt_data *crypt;
3583 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3584 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3585 || (ieee->host_encrypt && crypt && crypt->ops &&
3586 (0 == strcmp(crypt->ops->name, "R-WEP")));
3589 if (encrypt && (wpa_ie_len == 0)) {
3591 } else if ((wpa_ie_len != 0)) {
3592 if (((ieee->wpa_ie[0] == 0xdd) &&
3593 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3594 ((ieee->wpa_ie[0] == 0x30) &&
3595 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3596 return SEC_ALG_CCMP;
3598 return SEC_ALG_TKIP;
3600 return SEC_ALG_NONE;
3604 int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p,
3607 struct ieee_param *param;
3610 down(&ieee->wx_sem);
3612 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3617 param = memdup_user(p->pointer, p->length);
3618 if (IS_ERR(param)) {
3619 ret = PTR_ERR(param);
3623 switch (param->cmd) {
3624 case IEEE_CMD_SET_WPA_PARAM:
3625 ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name,
3626 param->u.wpa_param.value);
3629 case IEEE_CMD_SET_WPA_IE:
3630 ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length);
3633 case IEEE_CMD_SET_ENCRYPTION:
3634 ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0);
3638 ret = rtllib_wpa_mlme(ieee, param->u.mlme.command,
3639 param->u.mlme.reason_code);
3643 netdev_info(ieee->dev, "Unknown WPA supplicant request: %d\n",
3649 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3658 EXPORT_SYMBOL(rtllib_wpa_supplicant_ioctl);
3660 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3664 bool bFilterOutNonAssociatedBSSID = false;
3666 rtllib->state = RTLLIB_NOLINK;
3668 for (i = 0; i < 6; i++)
3669 rtllib->current_network.bssid[i] = 0x55;
3671 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3672 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3673 rtllib->current_network.bssid);
3674 OpMode = RT_OP_MODE_NO_LINK;
3675 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3676 rtllib_stop_send_beacons(rtllib);
3678 bFilterOutNonAssociatedBSSID = false;
3679 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3680 (u8 *)(&bFilterOutNonAssociatedBSSID));
3681 notify_wx_assoc_event(rtllib);
3685 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib,
3686 u8 *asSta, u8 asRsn)
3691 RemovePeerTS(rtllib, asSta);
3693 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3694 rtllib->state = RTLLIB_NOLINK;
3696 for (i = 0; i < 6; i++)
3697 rtllib->current_network.bssid[i] = 0x22;
3698 OpMode = RT_OP_MODE_NO_LINK;
3699 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3700 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3702 rtllib_disassociate(rtllib);
3704 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3705 rtllib->current_network.bssid);
3712 rtllib_MgntDisconnectAP(
3713 struct rtllib_device *rtllib,
3717 bool bFilterOutNonAssociatedBSSID = false;
3719 bFilterOutNonAssociatedBSSID = false;
3720 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3721 (u8 *)(&bFilterOutNonAssociatedBSSID));
3722 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3725 rtllib->state = RTLLIB_NOLINK;
3728 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3730 if (rtllib->ps != RTLLIB_PS_DISABLED)
3731 rtllib->sta_wake_up(rtllib->dev);
3733 if (rtllib->state == RTLLIB_LINKED) {
3734 if (rtllib->iw_mode == IW_MODE_ADHOC)
3735 rtllib_MgntDisconnectIBSS(rtllib);
3736 if (rtllib->iw_mode == IW_MODE_INFRA)
3737 rtllib_MgntDisconnectAP(rtllib, asRsn);
3743 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3745 void notify_wx_assoc_event(struct rtllib_device *ieee)
3747 union iwreq_data wrqu;
3749 if (ieee->cannot_notify)
3752 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3753 if (ieee->state == RTLLIB_LINKED)
3754 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3758 netdev_info(ieee->dev, "%s(): Tell user space disconnected\n",
3760 eth_zero_addr(wrqu.ap_addr.sa_data);
3762 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3764 EXPORT_SYMBOL(notify_wx_assoc_event);