1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
4 * Mostly extracted from the rtl8180-sa2400 driver for the
5 * in-kernel generic ieee802.11 stack.
7 * Few lines might be stolen from other part of the rtllib
8 * stack. Copyright who own it's copyright
10 * WPA code stolen from the ipw2200 driver.
11 * Copyright who own it's copyright.
13 * released under the GPL
19 #include <linux/random.h>
20 #include <linux/delay.h>
21 #include <linux/uaccess.h>
22 #include <linux/etherdevice.h>
25 short rtllib_is_54g(struct rtllib_network *net)
27 return (net->rates_ex_len > 0) || (net->rates_len > 4);
30 short rtllib_is_shortslot(const struct rtllib_network *net)
32 return net->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME;
35 /* returns the total length needed for placing the RATE MFIE
36 * tag and the EXTENDED RATE MFIE tag if needed.
37 * It encludes two bytes per tag for the tag itself and its len
39 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
41 unsigned int rate_len = 0;
43 if (ieee->modulation & RTLLIB_CCK_MODULATION)
44 rate_len = RTLLIB_CCK_RATE_LEN + 2;
46 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
48 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
53 /* place the MFIE rate, tag to the memory (double) pointed.
54 * Then it updates the pointer so that
55 * it points after the new MFIE tag added.
57 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
61 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
62 *tag++ = MFIE_TYPE_RATES;
64 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
65 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
66 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
67 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
70 /* We may add an option for custom rates that specific HW
75 static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p)
79 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
80 *tag++ = MFIE_TYPE_RATES_EX;
82 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
83 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
84 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
85 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
86 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
87 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
88 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
89 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;
91 /* We may add an option for custom rates that specific HW might
96 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
100 *tag++ = MFIE_TYPE_GENERIC;
112 void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
116 *tag++ = MFIE_TYPE_GENERIC;
127 printk(KERN_ALERT "This is enable turbo mode IE process\n");
130 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
134 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
137 * if the queue is full but we have newer frames then
138 * just overwrites the oldest.
140 * if (nh == ieee->mgmt_queue_tail)
143 ieee->mgmt_queue_head = nh;
144 ieee->mgmt_queue_ring[nh] = skb;
148 static struct sk_buff *dequeue_mgmt(struct rtllib_device *ieee)
152 if (ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
155 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
157 ieee->mgmt_queue_tail =
158 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
163 static void init_mgmt_queue(struct rtllib_device *ieee)
165 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
170 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
177 for (i = 0; i < ieee->current_network.rates_len; i++) {
178 BasicRate = ieee->current_network.rates[i]&0x7F;
179 if (!rtllib_is_cck_rate(BasicRate)) {
180 if (QueryRate == 0) {
181 QueryRate = BasicRate;
183 if (BasicRate < QueryRate)
184 QueryRate = BasicRate;
189 if (QueryRate == 0) {
191 printk(KERN_INFO "No BasicRate found!!\n");
196 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
198 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
201 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
204 rate = ieee->basic_rate & 0x7f;
207 if (ieee->mode == IEEE_A ||
208 ieee->mode == IEEE_N_5G ||
209 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
218 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
221 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
222 struct rtllib_hdr_3addr *header =
223 (struct rtllib_hdr_3addr *) skb->data;
225 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
227 spin_lock_irqsave(&ieee->lock, flags);
229 /* called with 2nd param 0, no mgmt lock required */
230 rtllib_sta_wakeup(ieee, 0);
232 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
233 tcb_desc->queue_index = BEACON_QUEUE;
235 tcb_desc->queue_index = MGNT_QUEUE;
237 if (ieee->disable_mgnt_queue)
238 tcb_desc->queue_index = HIGH_QUEUE;
240 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
241 tcb_desc->RATRIndex = 7;
242 tcb_desc->bTxDisableRateFallBack = 1;
243 tcb_desc->bTxUseDriverAssingedRate = 1;
245 if (ieee->queue_stop) {
246 enqueue_mgmt(ieee, skb);
248 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
250 if (ieee->seq_ctrl[0] == 0xFFF)
251 ieee->seq_ctrl[0] = 0;
255 /* avoid watchdog triggers */
256 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
260 spin_unlock_irqrestore(&ieee->lock, flags);
262 spin_unlock_irqrestore(&ieee->lock, flags);
263 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
265 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
267 if (ieee->seq_ctrl[0] == 0xFFF)
268 ieee->seq_ctrl[0] = 0;
272 /* check whether the managed packet queued greater than 5 */
273 if (!ieee->check_nic_enough_desc(ieee->dev, tcb_desc->queue_index) ||
274 (skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) != 0) ||
275 (ieee->queue_stop)) {
276 /* insert the skb packet to the management queue */
277 /* as for the completion function, it does not need
278 * to check it any more.
280 printk(KERN_INFO "%s():insert to waitqueue, queue_index"
281 ":%d!\n", __func__, tcb_desc->queue_index);
282 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
285 ieee->softmac_hard_start_xmit(skb, ieee->dev);
287 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
291 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb,
292 struct rtllib_device *ieee)
294 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
295 struct rtllib_hdr_3addr *header =
296 (struct rtllib_hdr_3addr *) skb->data;
298 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
300 fc = le16_to_cpu(header->frame_ctl);
301 type = WLAN_FC_GET_TYPE(fc);
302 stype = WLAN_FC_GET_STYPE(fc);
305 if (stype != RTLLIB_STYPE_PSPOLL)
306 tcb_desc->queue_index = MGNT_QUEUE;
308 tcb_desc->queue_index = HIGH_QUEUE;
310 if (ieee->disable_mgnt_queue)
311 tcb_desc->queue_index = HIGH_QUEUE;
314 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
315 tcb_desc->RATRIndex = 7;
316 tcb_desc->bTxDisableRateFallBack = 1;
317 tcb_desc->bTxUseDriverAssingedRate = 1;
319 if (type != RTLLIB_FTYPE_CTL) {
320 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
322 if (ieee->seq_ctrl[0] == 0xFFF)
323 ieee->seq_ctrl[0] = 0;
328 /* avoid watchdog triggers */
329 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
333 if (type != RTLLIB_FTYPE_CTL) {
334 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
336 if (ieee->seq_ctrl[0] == 0xFFF)
337 ieee->seq_ctrl[0] = 0;
341 ieee->softmac_hard_start_xmit(skb, ieee->dev);
346 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
348 unsigned int len, rate_len;
351 struct rtllib_probe_request *req;
353 len = ieee->current_network.ssid_len;
355 rate_len = rtllib_MFIE_rate_len(ieee);
357 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
358 2 + len + rate_len + ieee->tx_headroom);
363 skb_reserve(skb, ieee->tx_headroom);
365 req = (struct rtllib_probe_request *) skb_put(skb,
366 sizeof(struct rtllib_probe_request));
367 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
368 req->header.duration_id = 0;
370 memset(req->header.addr1, 0xff, ETH_ALEN);
371 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
372 memset(req->header.addr3, 0xff, ETH_ALEN);
374 tag = (u8 *) skb_put(skb, len + 2 + rate_len);
376 *tag++ = MFIE_TYPE_SSID;
378 memcpy(tag, ieee->current_network.ssid, len);
381 rtllib_MFIE_Brate(ieee, &tag);
382 rtllib_MFIE_Grate(ieee, &tag);
387 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
389 static void rtllib_send_beacon(struct rtllib_device *ieee)
395 skb = rtllib_get_beacon_(ieee);
398 softmac_mgmt_xmit(skb, ieee);
399 ieee->softmac_stats.tx_beacons++;
402 if (ieee->beacon_txing && ieee->ieee_up)
403 mod_timer(&ieee->beacon_timer, jiffies +
404 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
408 static void rtllib_send_beacon_cb(unsigned long _ieee)
410 struct rtllib_device *ieee =
411 (struct rtllib_device *) _ieee;
414 spin_lock_irqsave(&ieee->beacon_lock, flags);
415 rtllib_send_beacon(ieee);
416 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
421 * Enable network monitor mode, all rx packets will be received.
423 void rtllib_EnableNetMonitorMode(struct net_device *dev,
426 struct rtllib_device *ieee = netdev_priv_rsl(dev);
428 printk(KERN_INFO "========>Enter Monitor Mode\n");
430 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
436 * Disable network 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 printk(KERN_INFO "========>Exit Monitor Mode\n");
446 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
452 * This enables the specialized promiscuous mode required by Intel.
453 * In this mode, Intel intends to hear traffics from/to other STAs in the
454 * same BSS. Therefore we don't have to disable checking BSSID and we only need
455 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
456 * packets from other STA.
458 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
461 bool bFilterOutNonAssociatedBSSID = false;
463 struct rtllib_device *ieee = netdev_priv_rsl(dev);
465 printk(KERN_INFO "========>Enter Intel Promiscuous Mode\n");
467 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
468 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
469 (u8 *)&bFilterOutNonAssociatedBSSID);
471 ieee->bNetPromiscuousMode = true;
473 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
478 * This disables the specialized promiscuous mode required by Intel.
479 * See MgntEnableIntelPromiscuousMode for detail.
481 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
484 bool bFilterOutNonAssociatedBSSID = true;
486 struct rtllib_device *ieee = netdev_priv_rsl(dev);
488 printk(KERN_INFO "========>Exit Intel Promiscuous Mode\n");
490 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
491 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
492 (u8 *)&bFilterOutNonAssociatedBSSID);
494 ieee->bNetPromiscuousMode = false;
496 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
498 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
502 skb = rtllib_probe_req(ieee);
504 softmac_mgmt_xmit(skb, ieee);
505 ieee->softmac_stats.tx_probe_rq++;
510 void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
512 if (ieee->active_scan && (ieee->softmac_features &
513 IEEE_SOFTMAC_PROBERQ)) {
514 rtllib_send_probe(ieee, 0);
515 rtllib_send_probe(ieee, 0);
519 static void rtllib_softmac_hint11d_wq(void *data)
523 void rtllib_update_active_chan_map(struct rtllib_device *ieee)
525 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
526 MAX_CHANNEL_NUMBER+1);
529 /* this performs syncro scan blocking the caller until all channels
530 * in the allowed channel map has been checked.
532 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
534 union iwreq_data wrqu;
537 rtllib_update_active_chan_map(ieee);
539 ieee->be_scan_inprogress = true;
541 down(&ieee->scan_sem);
546 if (ch > MAX_CHANNEL_NUMBER)
547 goto out; /* scan completed */
548 } while (!ieee->active_channel_map[ch]);
550 /* this function can be called in two situations
551 * 1- We have switched to ad-hoc mode and we are
552 * performing a complete syncro scan before conclude
553 * there are no interesting cell and to create a
554 * new one. In this case the link state is
555 * RTLLIB_NOLINK until we found an interesting cell.
556 * If so the ieee8021_new_net, called by the RX path
557 * will set the state to RTLLIB_LINKED, so we stop
559 * 2- We are linked and the root uses run iwlist scan.
560 * So we switch to RTLLIB_LINKED_SCANNING to remember
561 * that we are still logically linked (not interested in
562 * new network events, despite for updating the net list,
563 * but we are temporarly 'unlinked' as the driver shall
564 * not filter RX frames and the channel is changing.
565 * So the only situation in which are interested is to check
566 * if the state become LINKED because of the #1 situation
569 if (ieee->state == RTLLIB_LINKED)
571 if (ieee->sync_scan_hurryup) {
572 printk(KERN_INFO "============>sync_scan_hurryup out\n");
576 ieee->set_chan(ieee->dev, ch);
577 if (ieee->active_channel_map[ch] == 1)
578 rtllib_send_probe_requests(ieee, 0);
580 /* this prevent excessive time wait when we
581 * need to wait for a syncro scan to end..
583 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
586 ieee->actscanning = false;
587 ieee->sync_scan_hurryup = 0;
589 if (ieee->state >= RTLLIB_LINKED) {
590 if (IS_DOT11D_ENABLE(ieee))
591 DOT11D_ScanComplete(ieee);
595 ieee->be_scan_inprogress = false;
597 memset(&wrqu, 0, sizeof(wrqu));
598 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
601 static void rtllib_softmac_scan_wq(void *data)
603 struct rtllib_device *ieee = container_of_dwork_rsl(data,
604 struct rtllib_device, softmac_scan_wq);
605 u8 last_channel = ieee->current_network.channel;
607 rtllib_update_active_chan_map(ieee);
611 if (rtllib_act_scanning(ieee, true))
614 down(&ieee->scan_sem);
616 if (ieee->eRFPowerState == eRfOff) {
617 printk(KERN_INFO "======>%s():rf state is eRfOff, return\n",
623 ieee->current_network.channel =
624 (ieee->current_network.channel + 1) %
626 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
627 if (!ieee->active_channel_map[ieee->current_network.channel])
628 ieee->current_network.channel = 6;
629 goto out; /* no good chans */
631 } while (!ieee->active_channel_map[ieee->current_network.channel]);
633 if (ieee->scanning_continue == 0)
636 ieee->set_chan(ieee->dev, ieee->current_network.channel);
638 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
639 rtllib_send_probe_requests(ieee, 0);
641 queue_delayed_work_rsl(ieee->wq, &ieee->softmac_scan_wq,
642 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
648 if (IS_DOT11D_ENABLE(ieee))
649 DOT11D_ScanComplete(ieee);
650 ieee->current_network.channel = last_channel;
653 ieee->actscanning = false;
654 ieee->scan_watch_dog = 0;
655 ieee->scanning_continue = 0;
661 static void rtllib_beacons_start(struct rtllib_device *ieee)
665 spin_lock_irqsave(&ieee->beacon_lock, flags);
667 ieee->beacon_txing = 1;
668 rtllib_send_beacon(ieee);
670 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
673 static void rtllib_beacons_stop(struct rtllib_device *ieee)
677 spin_lock_irqsave(&ieee->beacon_lock, flags);
679 ieee->beacon_txing = 0;
680 del_timer_sync(&ieee->beacon_timer);
682 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
687 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
689 if (ieee->stop_send_beacons)
690 ieee->stop_send_beacons(ieee->dev);
691 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
692 rtllib_beacons_stop(ieee);
694 EXPORT_SYMBOL(rtllib_stop_send_beacons);
697 void rtllib_start_send_beacons(struct rtllib_device *ieee)
699 if (ieee->start_send_beacons)
700 ieee->start_send_beacons(ieee->dev);
701 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
702 rtllib_beacons_start(ieee);
704 EXPORT_SYMBOL(rtllib_start_send_beacons);
707 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
709 down(&ieee->scan_sem);
710 ieee->scan_watch_dog = 0;
711 if (ieee->scanning_continue == 1) {
712 ieee->scanning_continue = 0;
713 ieee->actscanning = false;
715 cancel_delayed_work(&ieee->softmac_scan_wq);
721 void rtllib_stop_scan(struct rtllib_device *ieee)
723 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
724 rtllib_softmac_stop_scan(ieee);
726 if (ieee->rtllib_stop_hw_scan)
727 ieee->rtllib_stop_hw_scan(ieee->dev);
730 EXPORT_SYMBOL(rtllib_stop_scan);
732 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
734 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
735 ieee->sync_scan_hurryup = 1;
737 if (ieee->rtllib_stop_hw_scan)
738 ieee->rtllib_stop_hw_scan(ieee->dev);
741 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
743 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
745 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
747 return ieee->be_scan_inprogress;
749 return ieee->actscanning || ieee->be_scan_inprogress;
751 return test_bit(STATUS_SCANNING, &ieee->status);
754 EXPORT_SYMBOL(rtllib_act_scanning);
756 /* called with ieee->lock held */
757 static void rtllib_start_scan(struct rtllib_device *ieee)
759 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
760 if (ieee->rtllib_ips_leave_wq != NULL)
761 ieee->rtllib_ips_leave_wq(ieee->dev);
763 if (IS_DOT11D_ENABLE(ieee)) {
764 if (IS_COUNTRY_IE_VALID(ieee))
765 RESET_CIE_WATCHDOG(ieee);
767 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
768 if (ieee->scanning_continue == 0) {
769 ieee->actscanning = true;
770 ieee->scanning_continue = 1;
771 queue_delayed_work_rsl(ieee->wq,
772 &ieee->softmac_scan_wq, 0);
775 if (ieee->rtllib_start_hw_scan)
776 ieee->rtllib_start_hw_scan(ieee->dev);
780 /* called with wx_sem held */
781 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
783 if (IS_DOT11D_ENABLE(ieee)) {
784 if (IS_COUNTRY_IE_VALID(ieee))
785 RESET_CIE_WATCHDOG(ieee);
787 ieee->sync_scan_hurryup = 0;
788 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
789 rtllib_softmac_scan_syncro(ieee, is_mesh);
791 if (ieee->rtllib_start_hw_scan)
792 ieee->rtllib_start_hw_scan(ieee->dev);
795 EXPORT_SYMBOL(rtllib_start_scan_syncro);
797 inline struct sk_buff *rtllib_authentication_req(struct rtllib_network *beacon,
798 struct rtllib_device *ieee, int challengelen, u8 *daddr)
801 struct rtllib_authentication *auth;
804 len = sizeof(struct rtllib_authentication) + challengelen +
805 ieee->tx_headroom + 4;
806 skb = dev_alloc_skb(len);
811 skb_reserve(skb, ieee->tx_headroom);
813 auth = (struct rtllib_authentication *)
814 skb_put(skb, sizeof(struct rtllib_authentication));
816 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
818 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
820 auth->header.duration_id = cpu_to_le16(0x013a);
821 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
822 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
823 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
824 if (ieee->auth_mode == 0)
825 auth->algorithm = WLAN_AUTH_OPEN;
826 else if (ieee->auth_mode == 1)
827 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
828 else if (ieee->auth_mode == 2)
829 auth->algorithm = WLAN_AUTH_OPEN;
830 auth->transaction = cpu_to_le16(ieee->associate_seq);
831 ieee->associate_seq++;
833 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
838 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, u8 *dest)
842 struct rtllib_probe_response *beacon_buf;
843 struct sk_buff *skb = NULL;
845 int atim_len, erp_len;
846 struct lib80211_crypt_data *crypt;
848 char *ssid = ieee->current_network.ssid;
849 int ssid_len = ieee->current_network.ssid_len;
850 int rate_len = ieee->current_network.rates_len+2;
851 int rate_ex_len = ieee->current_network.rates_ex_len;
852 int wpa_ie_len = ieee->wpa_ie_len;
853 u8 erpinfo_content = 0;
855 u8 *tmp_ht_cap_buf = NULL;
856 u8 tmp_ht_cap_len = 0;
857 u8 *tmp_ht_info_buf = NULL;
858 u8 tmp_ht_info_len = 0;
859 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
860 u8 *tmp_generic_ie_buf = NULL;
861 u8 tmp_generic_ie_len = 0;
866 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
871 if ((ieee->current_network.mode == IEEE_G) ||
872 (ieee->current_network.mode == IEEE_N_24G &&
873 ieee->pHTInfo->bCurSuppCCK)) {
876 if (ieee->current_network.buseprotection)
877 erpinfo_content |= ERP_UseProtection;
881 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
882 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
883 ((0 == strcmp(crypt->ops->name, "R-WEP") || wpa_ie_len));
884 if (ieee->pHTInfo->bCurrentHTSupport) {
885 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
886 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
887 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
888 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
889 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
890 &tmp_ht_cap_len, encrypt, false);
891 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
894 if (pHTInfo->bRegRT2RTAggregation) {
895 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
897 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
898 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
899 &tmp_generic_ie_len);
903 beacon_size = sizeof(struct rtllib_probe_response)+2+
904 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
905 + wpa_ie_len + ieee->tx_headroom;
906 skb = dev_alloc_skb(beacon_size);
910 skb_reserve(skb, ieee->tx_headroom);
912 beacon_buf = (struct rtllib_probe_response *) skb_put(skb,
913 (beacon_size - ieee->tx_headroom));
914 memcpy(beacon_buf->header.addr1, dest, ETH_ALEN);
915 memcpy(beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
916 memcpy(beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
918 beacon_buf->header.duration_id = 0;
919 beacon_buf->beacon_interval =
920 cpu_to_le16(ieee->current_network.beacon_interval);
921 beacon_buf->capability =
922 cpu_to_le16(ieee->current_network.capability &
923 WLAN_CAPABILITY_IBSS);
924 beacon_buf->capability |=
925 cpu_to_le16(ieee->current_network.capability &
926 WLAN_CAPABILITY_SHORT_PREAMBLE);
928 if (ieee->short_slot && (ieee->current_network.capability &
929 WLAN_CAPABILITY_SHORT_SLOT_TIME))
930 beacon_buf->capability |=
931 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
933 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
935 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
938 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
939 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
940 beacon_buf->info_element[0].len = ssid_len;
942 tag = (u8 *) beacon_buf->info_element[0].data;
944 memcpy(tag, ssid, ssid_len);
948 *(tag++) = MFIE_TYPE_RATES;
949 *(tag++) = rate_len-2;
950 memcpy(tag, ieee->current_network.rates, rate_len-2);
953 *(tag++) = MFIE_TYPE_DS_SET;
955 *(tag++) = ieee->current_network.channel;
959 *(tag++) = MFIE_TYPE_IBSS_SET;
961 val16 = ieee->current_network.atim_window;
962 memcpy((u8 *)tag, (u8 *)&val16, 2);
967 *(tag++) = MFIE_TYPE_ERP;
969 *(tag++) = erpinfo_content;
972 *(tag++) = MFIE_TYPE_RATES_EX;
973 *(tag++) = rate_ex_len-2;
974 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
975 tag += rate_ex_len-2;
979 if (ieee->iw_mode == IW_MODE_ADHOC)
980 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
981 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
982 tag += ieee->wpa_ie_len;
987 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
992 struct lib80211_crypt_data *crypt;
993 struct rtllib_assoc_response_frame *assoc;
996 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
997 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
1000 skb = dev_alloc_skb(len);
1005 skb_reserve(skb, ieee->tx_headroom);
1007 assoc = (struct rtllib_assoc_response_frame *)
1008 skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
1010 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
1011 memcpy(assoc->header.addr1, dest, ETH_ALEN);
1012 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1013 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1014 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1015 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
1018 if (ieee->short_slot)
1019 assoc->capability |=
1020 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1022 if (ieee->host_encrypt)
1023 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1027 encrypt = (crypt && crypt->ops);
1030 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1033 assoc->aid = cpu_to_le16(ieee->assoc_id);
1034 if (ieee->assoc_id == 0x2007)
1039 tag = (u8 *) skb_put(skb, rate_len);
1040 rtllib_MFIE_Brate(ieee, &tag);
1041 rtllib_MFIE_Grate(ieee, &tag);
1046 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1049 struct sk_buff *skb = NULL;
1050 struct rtllib_authentication *auth;
1051 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1053 skb = dev_alloc_skb(len);
1057 skb->len = sizeof(struct rtllib_authentication);
1059 skb_reserve(skb, ieee->tx_headroom);
1061 auth = (struct rtllib_authentication *)
1062 skb_put(skb, sizeof(struct rtllib_authentication));
1064 auth->status = cpu_to_le16(status);
1065 auth->transaction = cpu_to_le16(2);
1066 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1068 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1069 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1070 memcpy(auth->header.addr1, dest, ETH_ALEN);
1071 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1077 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1079 struct sk_buff *skb;
1080 struct rtllib_hdr_3addr *hdr;
1082 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1086 skb_reserve(skb, ieee->tx_headroom);
1088 hdr = (struct rtllib_hdr_3addr *)skb_put(skb,
1089 sizeof(struct rtllib_hdr_3addr));
1091 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1092 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1093 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1095 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1096 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1097 (pwr ? RTLLIB_FCTL_PM : 0));
1104 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1106 struct sk_buff *skb;
1107 struct rtllib_pspoll_hdr *hdr;
1109 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1113 skb_reserve(skb, ieee->tx_headroom);
1115 hdr = (struct rtllib_pspoll_hdr *)skb_put(skb,
1116 sizeof(struct rtllib_pspoll_hdr));
1118 memcpy(hdr->bssid, ieee->current_network.bssid, ETH_ALEN);
1119 memcpy(hdr->ta, ieee->dev->dev_addr, ETH_ALEN);
1121 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1122 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1129 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1131 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1134 softmac_mgmt_xmit(buf, ieee);
1138 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1140 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1143 softmac_mgmt_xmit(buf, ieee);
1147 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1149 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1152 softmac_mgmt_xmit(buf, ieee);
1156 inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1161 if ((ieee->PMKIDList[i].bUsed) &&
1162 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1165 } while (i < NUM_PMKID_CACHE);
1167 if (i == NUM_PMKID_CACHE)
1172 inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1173 struct rtllib_device *ieee)
1175 struct sk_buff *skb;
1176 struct rtllib_assoc_request_frame *hdr;
1179 u8 *ht_cap_buf = NULL;
1181 u8 *realtek_ie_buf = NULL;
1182 u8 realtek_ie_len = 0;
1183 int wpa_ie_len = ieee->wpa_ie_len;
1184 int wps_ie_len = ieee->wps_ie_len;
1185 unsigned int ckip_ie_len = 0;
1186 unsigned int ccxrm_ie_len = 0;
1187 unsigned int cxvernum_ie_len = 0;
1188 struct lib80211_crypt_data *crypt;
1192 unsigned int rate_len = (beacon->rates_len ?
1193 (beacon->rates_len + 2) : 0) +
1194 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1197 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1198 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1202 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1204 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1205 ((0 == strcmp(crypt->ops->name, "R-WEP") ||
1210 if ((ieee->rtllib_ap_sec_type &&
1211 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1212 ieee->bForcedBgMode) {
1213 ieee->pHTInfo->bEnableHT = 0;
1214 ieee->mode = WIRELESS_MODE_G;
1217 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1218 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1219 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1220 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1222 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1223 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1225 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1226 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1231 if (beacon->bCkipSupported)
1233 if (beacon->bCcxRmEnable)
1235 if (beacon->BssCcxVerNumber >= 2)
1236 cxvernum_ie_len = 5+2;
1238 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1239 if (PMKCacheIdx >= 0) {
1241 printk(KERN_INFO "[PMK cache]: WPA2 IE length: %x\n",
1244 len = sizeof(struct rtllib_assoc_request_frame) + 2
1256 + ieee->tx_headroom;
1258 skb = dev_alloc_skb(len);
1263 skb_reserve(skb, ieee->tx_headroom);
1265 hdr = (struct rtllib_assoc_request_frame *)
1266 skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1269 hdr->header.frame_ctl = RTLLIB_STYPE_ASSOC_REQ;
1270 hdr->header.duration_id = cpu_to_le16(37);
1271 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1272 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1273 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1275 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);
1277 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1278 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1279 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1281 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1282 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1284 if (ieee->short_slot &&
1285 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1286 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1289 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1291 hdr->info_element[0].id = MFIE_TYPE_SSID;
1293 hdr->info_element[0].len = beacon->ssid_len;
1294 tag = skb_put(skb, beacon->ssid_len);
1295 memcpy(tag, beacon->ssid, beacon->ssid_len);
1297 tag = skb_put(skb, rate_len);
1299 if (beacon->rates_len) {
1300 *tag++ = MFIE_TYPE_RATES;
1301 *tag++ = beacon->rates_len;
1302 for (i = 0; i < beacon->rates_len; i++)
1303 *tag++ = beacon->rates[i];
1306 if (beacon->rates_ex_len) {
1307 *tag++ = MFIE_TYPE_RATES_EX;
1308 *tag++ = beacon->rates_ex_len;
1309 for (i = 0; i < beacon->rates_ex_len; i++)
1310 *tag++ = beacon->rates_ex[i];
1313 if (beacon->bCkipSupported) {
1314 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1315 u8 CcxAironetBuf[30];
1316 struct octet_string osCcxAironetIE;
1318 memset(CcxAironetBuf, 0, 30);
1319 osCcxAironetIE.Octet = CcxAironetBuf;
1320 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1321 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1322 sizeof(AironetIeOui));
1324 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1325 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1326 tag = skb_put(skb, ckip_ie_len);
1327 *tag++ = MFIE_TYPE_AIRONET;
1328 *tag++ = osCcxAironetIE.Length;
1329 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1330 tag += osCcxAironetIE.Length;
1333 if (beacon->bCcxRmEnable) {
1334 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1336 struct octet_string osCcxRmCap;
1338 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1339 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1340 tag = skb_put(skb, ccxrm_ie_len);
1341 *tag++ = MFIE_TYPE_GENERIC;
1342 *tag++ = osCcxRmCap.Length;
1343 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1344 tag += osCcxRmCap.Length;
1347 if (beacon->BssCcxVerNumber >= 2) {
1348 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1349 struct octet_string osCcxVerNum;
1351 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1352 osCcxVerNum.Octet = CcxVerNumBuf;
1353 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1354 tag = skb_put(skb, cxvernum_ie_len);
1355 *tag++ = MFIE_TYPE_GENERIC;
1356 *tag++ = osCcxVerNum.Length;
1357 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1358 tag += osCcxVerNum.Length;
1360 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1361 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1362 tag = skb_put(skb, ht_cap_len);
1363 *tag++ = MFIE_TYPE_HT_CAP;
1364 *tag++ = ht_cap_len - 2;
1365 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1366 tag += ht_cap_len - 2;
1371 tag = skb_put(skb, ieee->wpa_ie_len);
1372 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1374 if (PMKCacheIdx >= 0) {
1375 tag = skb_put(skb, 18);
1378 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1383 tag = skb_put(skb, wmm_info_len);
1384 rtllib_WMM_Info(ieee, &tag);
1387 if (wps_ie_len && ieee->wps_ie) {
1388 tag = skb_put(skb, wps_ie_len);
1389 memcpy(tag, ieee->wps_ie, wps_ie_len);
1392 tag = skb_put(skb, turbo_info_len);
1394 rtllib_TURBO_Info(ieee, &tag);
1396 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1397 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1398 tag = skb_put(skb, ht_cap_len);
1399 *tag++ = MFIE_TYPE_GENERIC;
1400 *tag++ = ht_cap_len - 2;
1401 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1402 tag += ht_cap_len - 2;
1405 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1406 tag = skb_put(skb, realtek_ie_len);
1407 *tag++ = MFIE_TYPE_GENERIC;
1408 *tag++ = realtek_ie_len - 2;
1409 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1413 kfree(ieee->assocreq_ies);
1414 ieee->assocreq_ies = NULL;
1415 ies = &(hdr->info_element[0].id);
1416 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1417 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1418 if (ieee->assocreq_ies)
1419 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1421 printk(KERN_INFO "%s()Warning: can't alloc memory for assocreq"
1422 "_ies\n", __func__);
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 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1444 ieee->softmac_stats.no_auth_rs++;
1446 RTLLIB_DEBUG_MGMT("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 RTLLIB_DEBUG_MGMT("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 RTLLIB_DEBUG_MGMT("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, int chlen)
1490 struct sk_buff *skb;
1491 struct rtllib_network *beacon = &ieee->current_network;
1493 ieee->associate_seq++;
1494 ieee->softmac_stats.tx_auth_rq++;
1496 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1499 rtllib_associate_abort(ieee);
1501 c = skb_put(skb, chlen+2);
1502 *(c++) = MFIE_TYPE_CHALLENGE;
1504 memcpy(c, challenge, chlen);
1506 RTLLIB_DEBUG_MGMT("Sending authentication challenge "
1509 rtllib_encrypt_fragment(ieee, skb,
1510 sizeof(struct rtllib_hdr_3addr));
1512 softmac_mgmt_xmit(skb, ieee);
1513 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1518 static void rtllib_associate_step2(struct rtllib_device *ieee)
1520 struct sk_buff *skb;
1521 struct rtllib_network *beacon = &ieee->current_network;
1523 del_timer_sync(&ieee->associate_timer);
1525 RTLLIB_DEBUG_MGMT("Sending association request\n");
1527 ieee->softmac_stats.tx_ass_rq++;
1528 skb = rtllib_association_req(beacon, ieee);
1530 rtllib_associate_abort(ieee);
1532 softmac_mgmt_xmit(skb, ieee);
1533 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1538 static void rtllib_associate_complete_wq(void *data)
1540 struct rtllib_device *ieee = (struct rtllib_device *)
1541 container_of_work_rsl(data,
1542 struct rtllib_device,
1543 associate_complete_wq);
1544 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1545 (&(ieee->PowerSaveControl));
1546 printk(KERN_INFO "Associated successfully\n");
1547 if (!ieee->is_silent_reset) {
1548 printk(KERN_INFO "normal associate\n");
1549 notify_wx_assoc_event(ieee);
1552 netif_carrier_on(ieee->dev);
1553 ieee->is_roaming = false;
1554 if (rtllib_is_54g(&ieee->current_network) &&
1555 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1557 printk(KERN_INFO"Using G rates:%d\n", ieee->rate);
1560 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1561 printk(KERN_INFO"Using B rates:%d\n", ieee->rate);
1563 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1564 printk(KERN_INFO "Successfully associated, ht enabled\n");
1567 printk(KERN_INFO "Successfully associated, ht not "
1568 "enabled(%d, %d)\n",
1569 ieee->pHTInfo->bCurrentHTSupport,
1570 ieee->pHTInfo->bEnableHT);
1571 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1573 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1574 ieee->current_network.beacon_interval /
1576 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1577 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1578 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1579 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1581 pPSC->LpsIdleCount = 0;
1582 ieee->link_change(ieee->dev);
1584 if (ieee->is_silent_reset) {
1585 printk(KERN_INFO "silent reset associate\n");
1586 ieee->is_silent_reset = false;
1589 if (ieee->data_hard_resume)
1590 ieee->data_hard_resume(ieee->dev);
1594 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1598 static void rtllib_associate_complete(struct rtllib_device *ieee)
1600 del_timer_sync(&ieee->associate_timer);
1602 ieee->state = RTLLIB_LINKED;
1603 rtllib_sta_send_associnfo(ieee);
1605 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1608 static void rtllib_associate_procedure_wq(void *data)
1610 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1611 struct rtllib_device,
1612 associate_procedure_wq);
1613 rtllib_stop_scan_syncro(ieee);
1614 if (ieee->rtllib_ips_leave != NULL)
1615 ieee->rtllib_ips_leave(ieee->dev);
1616 down(&ieee->wx_sem);
1618 if (ieee->data_hard_stop)
1619 ieee->data_hard_stop(ieee->dev);
1621 rtllib_stop_scan(ieee);
1622 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1623 ieee->current_network.channel);
1624 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1625 if (ieee->eRFPowerState == eRfOff) {
1626 RT_TRACE(COMP_DBG, "=============>%s():Rf state is eRfOff,"
1627 " schedule ipsleave wq again,return\n", __func__);
1628 if (ieee->rtllib_ips_leave_wq != NULL)
1629 ieee->rtllib_ips_leave_wq(ieee->dev);
1633 ieee->associate_seq = 1;
1635 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1640 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1641 struct rtllib_network *net)
1643 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1644 int tmp_ssid_len = 0;
1646 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1648 /* we are interested in new new only if we are not associated
1649 * and we are not associating / authenticating
1651 if (ieee->state != RTLLIB_NOLINK)
1654 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1655 WLAN_CAPABILITY_ESS))
1658 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1659 WLAN_CAPABILITY_IBSS))
1662 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1663 (net->channel > ieee->ibss_maxjoin_chal))
1665 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1666 /* if the user specified the AP MAC, we need also the essid
1667 * This could be obtained by beacons or, if the network does not
1668 * broadcast it, it can be put manually.
1670 apset = ieee->wap_set;
1671 ssidset = ieee->ssid_set;
1672 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1673 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1676 ssidmatch = (ieee->current_network.ssid_len ==
1677 net->hidden_ssid_len) &&
1678 (!strncmp(ieee->current_network.ssid,
1679 net->hidden_ssid, net->hidden_ssid_len));
1680 if (net->hidden_ssid_len > 0) {
1681 strncpy(net->ssid, net->hidden_ssid,
1682 net->hidden_ssid_len);
1683 net->ssid_len = net->hidden_ssid_len;
1688 (ieee->current_network.ssid_len == net->ssid_len) &&
1689 (!strncmp(ieee->current_network.ssid, net->ssid,
1692 /* if the user set the AP check if match.
1693 * if the network does not broadcast essid we check the
1694 * user supplied ANY essid
1695 * if the network does broadcast and the user does not set
1697 * if the network does broadcast and the user did set essid
1698 * check if essid match
1699 * if the ap is not set, check that the user set the bssid
1700 * and the network does broadcast and that those two bssid match
1702 if ((apset && apmatch &&
1703 ((ssidset && ssidbroad && ssidmatch) ||
1704 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1705 (!apset && ssidset && ssidbroad && ssidmatch) ||
1706 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1707 /* if the essid is hidden replace it with the
1708 * essid provided by the user.
1711 strncpy(tmp_ssid, ieee->current_network.ssid,
1713 tmp_ssid_len = ieee->current_network.ssid_len;
1715 memcpy(&ieee->current_network, net,
1716 sizeof(struct rtllib_network));
1718 strncpy(ieee->current_network.ssid, tmp_ssid,
1720 ieee->current_network.ssid_len = tmp_ssid_len;
1722 printk(KERN_INFO"Linking with %s,channel:%d, qos:%d, "
1723 "myHT:%d, networkHT:%d, mode:%x cur_net.flags"
1724 ":0x%x\n", ieee->current_network.ssid,
1725 ieee->current_network.channel,
1726 ieee->current_network.qos_data.supported,
1727 ieee->pHTInfo->bEnableHT,
1728 ieee->current_network.bssht.bdSupportHT,
1729 ieee->current_network.mode,
1730 ieee->current_network.flags);
1732 if ((rtllib_act_scanning(ieee, false)) &&
1733 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1734 rtllib_stop_scan_syncro(ieee);
1736 ieee->hwscan_ch_bk = ieee->current_network.channel;
1737 HTResetIOTSetting(ieee->pHTInfo);
1739 if (ieee->iw_mode == IW_MODE_INFRA) {
1740 /* Join the network for the first time */
1741 ieee->AsocRetryCount = 0;
1742 if ((ieee->current_network.qos_data.supported == 1) &&
1743 ieee->current_network.bssht.bdSupportHT)
1744 HTResetSelfAndSavePeerSetting(ieee,
1745 &(ieee->current_network));
1747 ieee->pHTInfo->bCurrentHTSupport =
1750 ieee->state = RTLLIB_ASSOCIATING;
1751 if (ieee->LedControlHandler != NULL)
1752 ieee->LedControlHandler(ieee->dev,
1753 LED_CTL_START_TO_LINK);
1754 queue_delayed_work_rsl(ieee->wq,
1755 &ieee->associate_procedure_wq, 0);
1757 if (rtllib_is_54g(&ieee->current_network) &&
1758 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1760 ieee->SetWirelessMode(ieee->dev, IEEE_G);
1761 printk(KERN_INFO"Using G rates\n");
1764 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1765 printk(KERN_INFO"Using B rates\n");
1767 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1768 ieee->state = RTLLIB_LINKED;
1774 void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1776 unsigned long flags;
1777 struct rtllib_network *target;
1779 spin_lock_irqsave(&ieee->lock, flags);
1781 list_for_each_entry(target, &ieee->network_list, list) {
1783 /* if the state become different that NOLINK means
1784 * we had found what we are searching for
1787 if (ieee->state != RTLLIB_NOLINK)
1790 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1791 ieee->scan_age, jiffies))
1792 rtllib_softmac_new_net(ieee, target);
1794 spin_unlock_irqrestore(&ieee->lock, flags);
1797 static inline u16 auth_parse(struct sk_buff *skb, u8 **challenge, int *chlen)
1799 struct rtllib_authentication *a;
1802 if (skb->len < (sizeof(struct rtllib_authentication) -
1803 sizeof(struct rtllib_info_element))) {
1804 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1808 a = (struct rtllib_authentication *) skb->data;
1809 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1810 t = skb->data + sizeof(struct rtllib_authentication);
1812 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1814 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1819 return cpu_to_le16(a->status);
1822 static int auth_rq_parse(struct sk_buff *skb, u8 *dest)
1824 struct rtllib_authentication *a;
1826 if (skb->len < (sizeof(struct rtllib_authentication) -
1827 sizeof(struct rtllib_info_element))) {
1828 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",
1832 a = (struct rtllib_authentication *) skb->data;
1834 memcpy(dest, a->header.addr2, ETH_ALEN);
1836 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1837 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1839 return WLAN_STATUS_SUCCESS;
1842 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1849 struct rtllib_hdr_3addr *header =
1850 (struct rtllib_hdr_3addr *) skb->data;
1853 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1854 return -1; /* corrupted */
1857 (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0) &&
1858 (!is_broadcast_ether_addr(header->addr3));
1862 memcpy(src, header->addr2, ETH_ALEN);
1864 skbend = (u8 *)skb->data + skb->len;
1866 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1868 while (tag + 1 < skbend) {
1871 ssidlen = *(tag + 1);
1874 tag++; /* point to the len field */
1875 tag = tag + *(tag); /* point to the last data byte of the tag */
1876 tag++; /* point to the next tag */
1883 return 1; /* ssid not found in tagged param */
1885 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1888 static int assoc_rq_parse(struct sk_buff *skb, u8 *dest)
1890 struct rtllib_assoc_request_frame *a;
1892 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1893 sizeof(struct rtllib_info_element))) {
1895 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d\n", skb->len);
1899 a = (struct rtllib_assoc_request_frame *) skb->data;
1901 memcpy(dest, a->header.addr2, ETH_ALEN);
1906 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1909 struct rtllib_assoc_response_frame *response_head;
1912 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1913 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1917 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1918 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1920 status_code = le16_to_cpu(response_head->status);
1921 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1922 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1923 ((ieee->mode == IEEE_G) &&
1924 (ieee->current_network.mode == IEEE_N_24G) &&
1925 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1926 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1928 ieee->AsocRetryCount = 0;
1931 return le16_to_cpu(response_head->status);
1934 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1938 ieee->softmac_stats.rx_probe_rq++;
1939 if (probe_rq_parse(ieee, skb, dest) > 0) {
1940 ieee->softmac_stats.tx_probe_rs++;
1941 rtllib_resp_to_probe(ieee, dest);
1945 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1946 struct sk_buff *skb)
1951 ieee->softmac_stats.rx_auth_rq++;
1953 status = auth_rq_parse(skb, dest);
1955 rtllib_resp_to_auth(ieee, status, dest);
1958 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1959 struct sk_buff *skb)
1964 ieee->softmac_stats.rx_ass_rq++;
1965 if (assoc_rq_parse(skb, dest) != -1)
1966 rtllib_resp_to_assoc_rq(ieee, dest);
1968 printk(KERN_INFO"New client associated: %pM\n", dest);
1971 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1974 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1977 softmac_ps_mgmt_xmit(buf, ieee);
1979 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1981 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1983 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1986 softmac_ps_mgmt_xmit(buf, ieee);
1989 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1991 int timeout = ieee->ps_timeout;
1993 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1994 (&(ieee->PowerSaveControl));
1996 if (ieee->LPSDelayCnt) {
1997 ieee->LPSDelayCnt--;
2001 dtim = ieee->current_network.dtim_data;
2002 if (!(dtim & RTLLIB_DTIM_VALID))
2004 timeout = ieee->current_network.beacon_interval;
2005 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
2006 /* there's no need to nofity AP that I find you buffered
2007 * with broadcast packet */
2008 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
2011 if (!time_after(jiffies,
2012 ieee->dev->trans_start + msecs_to_jiffies(timeout)))
2014 if (!time_after(jiffies,
2015 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
2017 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
2018 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
2022 if (ieee->bAwakePktSent) {
2023 pPSC->LPSAwakeIntvl = 1;
2027 if (pPSC->LPSAwakeIntvl == 0)
2028 pPSC->LPSAwakeIntvl = 1;
2029 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2031 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2032 MaxPeriod = ieee->current_network.dtim_period;
2034 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2035 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2036 MaxPeriod) ? MaxPeriod :
2037 (pPSC->LPSAwakeIntvl + 1);
2040 u8 LPSAwakeIntvl_tmp = 0;
2041 u8 period = ieee->current_network.dtim_period;
2042 u8 count = ieee->current_network.tim.tim_count;
2045 if (pPSC->LPSAwakeIntvl > period)
2046 LPSAwakeIntvl_tmp = period +
2047 (pPSC->LPSAwakeIntvl -
2049 ((pPSC->LPSAwakeIntvl-period) %
2052 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2055 if (pPSC->LPSAwakeIntvl >
2056 ieee->current_network.tim.tim_count)
2057 LPSAwakeIntvl_tmp = count +
2058 (pPSC->LPSAwakeIntvl - count) -
2059 ((pPSC->LPSAwakeIntvl-count)%period);
2061 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2064 *time = ieee->current_network.last_dtim_sta_time
2065 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2075 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2079 unsigned long flags, flags2;
2081 spin_lock_irqsave(&ieee->lock, flags);
2083 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2084 ieee->iw_mode != IW_MODE_INFRA ||
2085 ieee->state != RTLLIB_LINKED)) {
2086 RT_TRACE(COMP_DBG, "=====>%s(): no need to ps,wake up!! "
2087 "ieee->ps is %d, ieee->iw_mode is %d, ieee->state"
2088 " is %d\n", __func__, ieee->ps, ieee->iw_mode,
2090 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2091 rtllib_sta_wakeup(ieee, 1);
2093 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2095 sleep = rtllib_sta_ps_sleep(ieee, &time);
2096 /* 2 wake, 1 sleep, 0 do nothing */
2100 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2101 ieee->enter_sleep_state(ieee->dev, time);
2102 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2103 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2105 if (ieee->ps_is_queue_empty(ieee->dev)) {
2106 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2107 ieee->ack_tx_to_ieee = 1;
2108 rtllib_sta_ps_send_null_frame(ieee, 1);
2109 ieee->ps_time = time;
2111 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2115 ieee->bAwakePktSent = false;
2117 } else if (sleep == 2) {
2118 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2120 rtllib_sta_wakeup(ieee, 1);
2122 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2126 spin_unlock_irqrestore(&ieee->lock, flags);
2130 void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2132 if (ieee->sta_sleep == LPS_IS_WAKE) {
2134 if (ieee->pHTInfo->IOTAction &
2135 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2136 ieee->ack_tx_to_ieee = 1;
2137 rtllib_sta_ps_send_null_frame(ieee, 0);
2139 ieee->ack_tx_to_ieee = 1;
2140 rtllib_sta_ps_send_pspoll_frame(ieee);
2147 if (ieee->sta_sleep == LPS_IS_SLEEP)
2148 ieee->sta_wake_up(ieee->dev);
2150 if (ieee->pHTInfo->IOTAction &
2151 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2152 ieee->ack_tx_to_ieee = 1;
2153 rtllib_sta_ps_send_null_frame(ieee, 0);
2155 ieee->ack_tx_to_ieee = 1;
2156 ieee->polling = true;
2157 rtllib_sta_ps_send_pspoll_frame(ieee);
2161 ieee->sta_sleep = LPS_IS_WAKE;
2162 ieee->polling = false;
2166 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2168 unsigned long flags, flags2;
2170 spin_lock_irqsave(&ieee->lock, flags);
2172 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2173 /* Null frame with PS bit set */
2175 ieee->sta_sleep = LPS_IS_SLEEP;
2176 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2178 /* if the card report not success we can't be sure the AP
2179 * has not RXed so we can't assume the AP believe us awake
2181 } else {/* 21112005 - tx again null without PS bit if lost */
2183 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2184 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2185 if (ieee->pHTInfo->IOTAction &
2186 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2187 rtllib_sta_ps_send_null_frame(ieee, 0);
2189 rtllib_sta_ps_send_pspoll_frame(ieee);
2190 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2193 spin_unlock_irqrestore(&ieee->lock, flags);
2195 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2197 static void rtllib_process_action(struct rtllib_device *ieee, struct sk_buff *skb)
2199 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2200 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2204 RTLLIB_DEBUG(RTLLIB_DL_ERR, "error to get payload of "
2215 rtllib_rx_ADDBAReq(ieee, skb);
2218 rtllib_rx_ADDBARsp(ieee, skb);
2221 rtllib_rx_DELBA(ieee, skb);
2231 inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2232 struct rtllib_rx_stats *rx_stats)
2237 struct rtllib_assoc_response_frame *assoc_resp;
2238 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2240 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2241 WLAN_FC_GET_STYPE(header->frame_ctl));
2243 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2244 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2245 (ieee->iw_mode == IW_MODE_INFRA)) {
2246 errcode = assoc_parse(ieee, skb, &aid);
2248 struct rtllib_network *network =
2249 kzalloc(sizeof(struct rtllib_network),
2254 ieee->state = RTLLIB_LINKED;
2255 ieee->assoc_id = aid;
2256 ieee->softmac_stats.rx_ass_ok++;
2257 /* station support qos */
2258 /* Let the register setting default with Legacy station */
2259 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2260 if (ieee->current_network.qos_data.supported == 1) {
2261 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2262 rx_stats->len - sizeof(*assoc_resp),
2263 network, rx_stats)) {
2267 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2268 network->bssht.bdHTCapBuf,
2269 network->bssht.bdHTCapLen);
2270 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2271 network->bssht.bdHTInfoBuf,
2272 network->bssht.bdHTInfoLen);
2273 if (ieee->handle_assoc_response != NULL)
2274 ieee->handle_assoc_response(ieee->dev,
2275 (struct rtllib_assoc_response_frame *)header,
2280 kfree(ieee->assocresp_ies);
2281 ieee->assocresp_ies = NULL;
2282 ies = &(assoc_resp->info_element[0].id);
2283 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2284 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2286 if (ieee->assocresp_ies)
2287 memcpy(ieee->assocresp_ies, ies,
2288 ieee->assocresp_ies_len);
2290 printk(KERN_INFO "%s()Warning: can't alloc "
2291 "memory for assocresp_ies\n", __func__);
2292 ieee->assocresp_ies_len = 0;
2294 rtllib_associate_complete(ieee);
2296 /* aid could not been allocated */
2297 ieee->softmac_stats.rx_ass_err++;
2298 printk(KERN_INFO "Association response status code 0x%x\n",
2301 "Association response status code 0x%x\n",
2303 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2304 queue_delayed_work_rsl(ieee->wq,
2305 &ieee->associate_procedure_wq, 0);
2307 rtllib_associate_abort(ieee);
2313 inline int rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2314 struct rtllib_rx_stats *rx_stats)
2319 bool bSupportNmode = true, bHalfSupportNmode = false;
2321 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2322 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2323 (ieee->iw_mode == IW_MODE_INFRA)) {
2324 RTLLIB_DEBUG_MGMT("Received authentication response");
2326 errcode = auth_parse(skb, &challenge, &chlen);
2328 if (ieee->open_wep || !challenge) {
2329 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2330 ieee->softmac_stats.rx_auth_rs_ok++;
2331 if (!(ieee->pHTInfo->IOTAction &
2332 HT_IOT_ACT_PURE_N_MODE)) {
2333 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2334 if (IsHTHalfNmodeAPs(ieee)) {
2335 bSupportNmode = true;
2336 bHalfSupportNmode = true;
2338 bSupportNmode = false;
2339 bHalfSupportNmode = false;
2343 /* Dummy wirless mode setting to avoid
2344 * encryption issue */
2345 if (bSupportNmode) {
2346 ieee->SetWirelessMode(ieee->dev,
2347 ieee->current_network.mode);
2350 ieee->SetWirelessMode(ieee->dev,
2354 if (ieee->current_network.mode ==
2355 IEEE_N_24G && bHalfSupportNmode) {
2356 printk(KERN_INFO "======>enter "
2358 ieee->bHalfWirelessN24GMode =
2361 ieee->bHalfWirelessN24GMode =
2364 rtllib_associate_step2(ieee);
2366 rtllib_auth_challenge(ieee, challenge,
2370 ieee->softmac_stats.rx_auth_rs_err++;
2371 RTLLIB_DEBUG_MGMT("Authentication respose"
2372 " status code 0x%x", errcode);
2374 printk(KERN_INFO "Authentication respose "
2375 "status code 0x%x", errcode);
2376 rtllib_associate_abort(ieee);
2379 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2380 rtllib_rx_auth_rq(ieee, skb);
2386 inline int rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2388 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2390 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2393 /* FIXME for now repeat all the association procedure
2394 * both for disassociation and deauthentication
2396 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2397 ieee->state == RTLLIB_LINKED &&
2398 (ieee->iw_mode == IW_MODE_INFRA)) {
2399 printk(KERN_INFO "==========>received disassoc/deauth(%x) "
2400 "frame, reason code:%x\n",
2401 WLAN_FC_GET_STYPE(header->frame_ctl),
2402 ((struct rtllib_disassoc *)skb->data)->reason);
2403 ieee->state = RTLLIB_ASSOCIATING;
2404 ieee->softmac_stats.reassoc++;
2405 ieee->is_roaming = true;
2406 ieee->LinkDetectInfo.bBusyTraffic = false;
2407 rtllib_disassociate(ieee);
2408 RemovePeerTS(ieee, header->addr2);
2409 if (ieee->LedControlHandler != NULL)
2410 ieee->LedControlHandler(ieee->dev,
2411 LED_CTL_START_TO_LINK);
2413 if (!(ieee->rtllib_ap_sec_type(ieee) &
2414 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2415 queue_delayed_work_rsl(ieee->wq,
2416 &ieee->associate_procedure_wq, 5);
2421 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2422 struct sk_buff *skb,
2423 struct rtllib_rx_stats *rx_stats, u16 type,
2426 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2428 if (!ieee->proto_started)
2431 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2432 case RTLLIB_STYPE_ASSOC_RESP:
2433 case RTLLIB_STYPE_REASSOC_RESP:
2434 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2437 case RTLLIB_STYPE_ASSOC_REQ:
2438 case RTLLIB_STYPE_REASSOC_REQ:
2439 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2440 ieee->iw_mode == IW_MODE_MASTER)
2441 rtllib_rx_assoc_rq(ieee, skb);
2443 case RTLLIB_STYPE_AUTH:
2444 rtllib_rx_auth(ieee, skb, rx_stats);
2446 case RTLLIB_STYPE_DISASSOC:
2447 case RTLLIB_STYPE_DEAUTH:
2448 rtllib_rx_deauth(ieee, skb);
2450 case RTLLIB_STYPE_MANAGE_ACT:
2451 rtllib_process_action(ieee, skb);
2460 /* following are for a simpler TX queue management.
2461 * Instead of using netif_[stop/wake]_queue the driver
2462 * will use these two functions (plus a reset one), that
2463 * will internally use the kernel netif_* and takes
2464 * care of the ieee802.11 fragmentation.
2465 * So the driver receives a fragment per time and might
2466 * call the stop function when it wants to not
2467 * have enough room to TX an entire packet.
2468 * This might be useful if each fragment needs it's own
2469 * descriptor, thus just keep a total free memory > than
2470 * the max fragmentation threshold is not enough.. If the
2471 * ieee802.11 stack passed a TXB struct then you need
2472 * to keep N free descriptors where
2473 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2474 * In this way you need just one and the 802.11 stack
2475 * will take care of buffering fragments and pass them to
2476 * to the driver later, when it wakes the queue.
2478 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2481 unsigned int queue_index = txb->queue_index;
2482 unsigned long flags;
2484 struct cb_desc *tcb_desc = NULL;
2485 unsigned long queue_len = 0;
2487 spin_lock_irqsave(&ieee->lock, flags);
2489 /* called with 2nd parm 0, no tx mgmt lock required */
2490 rtllib_sta_wakeup(ieee, 0);
2492 /* update the tx status */
2493 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2495 if (tcb_desc->bMulticast)
2496 ieee->stats.multicast++;
2498 /* if xmit available, just xmit it immediately, else just insert it to
2500 for (i = 0; i < txb->nr_frags; i++) {
2501 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2502 if ((queue_len != 0) ||\
2503 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2504 (ieee->queue_stop)) {
2505 /* insert the skb packet to the wait queue */
2506 /* as for the completion function, it does not need
2507 * to check it any more.
2509 if (queue_len < 200)
2510 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2513 kfree_skb(txb->fragments[i]);
2515 ieee->softmac_data_hard_start_xmit(
2517 ieee->dev, ieee->rate);
2521 rtllib_txb_free(txb);
2523 spin_unlock_irqrestore(&ieee->lock, flags);
2527 /* called with ieee->lock acquired */
2528 static void rtllib_resume_tx(struct rtllib_device *ieee)
2532 for (i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags;
2535 if (ieee->queue_stop) {
2536 ieee->tx_pending.frag = i;
2540 ieee->softmac_data_hard_start_xmit(
2541 ieee->tx_pending.txb->fragments[i],
2542 ieee->dev, ieee->rate);
2543 ieee->stats.tx_packets++;
2547 rtllib_txb_free(ieee->tx_pending.txb);
2548 ieee->tx_pending.txb = NULL;
2552 void rtllib_reset_queue(struct rtllib_device *ieee)
2554 unsigned long flags;
2556 spin_lock_irqsave(&ieee->lock, flags);
2557 init_mgmt_queue(ieee);
2558 if (ieee->tx_pending.txb) {
2559 rtllib_txb_free(ieee->tx_pending.txb);
2560 ieee->tx_pending.txb = NULL;
2562 ieee->queue_stop = 0;
2563 spin_unlock_irqrestore(&ieee->lock, flags);
2566 EXPORT_SYMBOL(rtllib_reset_queue);
2568 void rtllib_wake_queue(struct rtllib_device *ieee)
2571 unsigned long flags;
2572 struct sk_buff *skb;
2573 struct rtllib_hdr_3addr *header;
2575 spin_lock_irqsave(&ieee->lock, flags);
2576 if (!ieee->queue_stop)
2579 ieee->queue_stop = 0;
2581 if (ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) {
2582 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))) {
2584 header = (struct rtllib_hdr_3addr *) skb->data;
2586 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2588 if (ieee->seq_ctrl[0] == 0xFFF)
2589 ieee->seq_ctrl[0] = 0;
2591 ieee->seq_ctrl[0]++;
2593 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
2597 if (!ieee->queue_stop && ieee->tx_pending.txb)
2598 rtllib_resume_tx(ieee);
2600 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)) {
2601 ieee->softmac_stats.swtxawake++;
2602 netif_wake_queue(ieee->dev);
2606 spin_unlock_irqrestore(&ieee->lock, flags);
2610 void rtllib_stop_queue(struct rtllib_device *ieee)
2613 if (!netif_queue_stopped(ieee->dev)) {
2614 netif_stop_queue(ieee->dev);
2615 ieee->softmac_stats.swtxstop++;
2617 ieee->queue_stop = 1;
2621 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2625 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2626 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2628 netif_tx_stop_all_queues(ieee->dev);
2631 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2633 netif_tx_wake_all_queues(ieee->dev);
2636 inline void rtllib_randomize_cell(struct rtllib_device *ieee)
2639 random_ether_addr(ieee->current_network.bssid);
2642 /* called in user context only */
2643 void rtllib_start_master_bss(struct rtllib_device *ieee)
2647 if (ieee->current_network.ssid_len == 0) {
2648 strncpy(ieee->current_network.ssid,
2649 RTLLIB_DEFAULT_TX_ESSID,
2652 ieee->current_network.ssid_len =
2653 strlen(RTLLIB_DEFAULT_TX_ESSID);
2657 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2659 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2660 ieee->state = RTLLIB_LINKED;
2661 ieee->link_change(ieee->dev);
2662 notify_wx_assoc_event(ieee);
2664 if (ieee->data_hard_resume)
2665 ieee->data_hard_resume(ieee->dev);
2667 netif_carrier_on(ieee->dev);
2670 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2672 /* reset hardware status */
2674 if (ieee->data_hard_resume)
2675 ieee->data_hard_resume(ieee->dev);
2677 netif_carrier_on(ieee->dev);
2681 static void rtllib_start_ibss_wq(void *data)
2683 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2684 struct rtllib_device, start_ibss_wq);
2685 /* iwconfig mode ad-hoc will schedule this and return
2686 * on the other hand this will block further iwconfig SET
2687 * operations because of the wx_sem hold.
2688 * Anyway some most set operations set a flag to speed-up
2689 * (abort) this wq (when syncro scanning) before sleeping
2692 if (!ieee->proto_started) {
2693 printk(KERN_INFO "==========oh driver down return\n");
2696 down(&ieee->wx_sem);
2698 if (ieee->current_network.ssid_len == 0) {
2699 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2700 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2704 ieee->state = RTLLIB_NOLINK;
2705 ieee->mode = IEEE_G;
2706 /* check if we have this cell in our network list */
2707 rtllib_softmac_check_all_nets(ieee);
2710 /* if not then the state is not linked. Maybe the user switched to
2711 * ad-hoc mode just after being in monitor mode, or just after
2712 * being very few time in managed mode (so the card have had no
2713 * time to scan all the chans..) or we have just run up the iface
2714 * after setting ad-hoc mode. So we have to give another try..
2715 * Here, in ibss mode, should be safe to do this without extra care
2716 * (in bss mode we had to make sure no-one tried to associate when
2717 * we had just checked the ieee->state and we was going to start the
2718 * scan) because in ibss mode the rtllib_new_net function, when
2719 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2720 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2721 * scan, that will stop at the first round because it sees the state
2724 if (ieee->state == RTLLIB_NOLINK)
2725 rtllib_start_scan_syncro(ieee, 0);
2727 /* the network definitively is not here.. create a new cell */
2728 if (ieee->state == RTLLIB_NOLINK) {
2729 printk(KERN_INFO "creating new IBSS cell\n");
2730 ieee->current_network.channel = ieee->IbssStartChnl;
2732 rtllib_randomize_cell(ieee);
2734 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2736 ieee->current_network.rates_len = 4;
2738 ieee->current_network.rates[0] =
2739 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2740 ieee->current_network.rates[1] =
2741 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2742 ieee->current_network.rates[2] =
2743 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2744 ieee->current_network.rates[3] =
2745 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2748 ieee->current_network.rates_len = 0;
2750 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2751 ieee->current_network.rates_ex_len = 8;
2753 ieee->current_network.rates_ex[0] =
2754 RTLLIB_OFDM_RATE_6MB;
2755 ieee->current_network.rates_ex[1] =
2756 RTLLIB_OFDM_RATE_9MB;
2757 ieee->current_network.rates_ex[2] =
2758 RTLLIB_OFDM_RATE_12MB;
2759 ieee->current_network.rates_ex[3] =
2760 RTLLIB_OFDM_RATE_18MB;
2761 ieee->current_network.rates_ex[4] =
2762 RTLLIB_OFDM_RATE_24MB;
2763 ieee->current_network.rates_ex[5] =
2764 RTLLIB_OFDM_RATE_36MB;
2765 ieee->current_network.rates_ex[6] =
2766 RTLLIB_OFDM_RATE_48MB;
2767 ieee->current_network.rates_ex[7] =
2768 RTLLIB_OFDM_RATE_54MB;
2772 ieee->current_network.rates_ex_len = 0;
2776 ieee->current_network.qos_data.supported = 0;
2777 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2778 ieee->current_network.mode = ieee->mode;
2779 ieee->current_network.atim_window = 0;
2780 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2783 printk(KERN_INFO "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2784 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2785 HTUseDefaultSetting(ieee);
2787 ieee->pHTInfo->bCurrentHTSupport = false;
2789 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2790 (u8 *)(&ieee->state));
2792 ieee->state = RTLLIB_LINKED;
2793 ieee->link_change(ieee->dev);
2795 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2796 if (ieee->LedControlHandler != NULL)
2797 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2799 rtllib_start_send_beacons(ieee);
2801 notify_wx_assoc_event(ieee);
2803 if (ieee->data_hard_resume)
2804 ieee->data_hard_resume(ieee->dev);
2806 netif_carrier_on(ieee->dev);
2811 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2813 queue_delayed_work_rsl(ieee->wq, &ieee->start_ibss_wq,
2814 msecs_to_jiffies(150));
2817 /* this is called only in user context, with wx_sem held */
2818 void rtllib_start_bss(struct rtllib_device *ieee)
2820 unsigned long flags;
2822 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2823 if (!ieee->bGlobalDomain)
2826 /* check if we have already found the net we
2827 * are interested in (if any).
2828 * if not (we are disassociated and we are not
2829 * in associating / authenticating phase) start the background scanning.
2831 rtllib_softmac_check_all_nets(ieee);
2833 /* ensure no-one start an associating process (thus setting
2834 * the ieee->state to rtllib_ASSOCIATING) while we
2835 * have just checked it and we are going to enable scan.
2836 * The rtllib_new_net function is always called with
2837 * lock held (from both rtllib_softmac_check_all_nets and
2838 * the rx path), so we cannot be in the middle of such function
2840 spin_lock_irqsave(&ieee->lock, flags);
2842 if (ieee->state == RTLLIB_NOLINK)
2843 rtllib_start_scan(ieee);
2844 spin_unlock_irqrestore(&ieee->lock, flags);
2847 static void rtllib_link_change_wq(void *data)
2849 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2850 struct rtllib_device, link_change_wq);
2851 ieee->link_change(ieee->dev);
2853 /* called only in userspace context */
2854 void rtllib_disassociate(struct rtllib_device *ieee)
2856 netif_carrier_off(ieee->dev);
2857 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2858 rtllib_reset_queue(ieee);
2860 if (ieee->data_hard_stop)
2861 ieee->data_hard_stop(ieee->dev);
2862 if (IS_DOT11D_ENABLE(ieee))
2864 ieee->state = RTLLIB_NOLINK;
2865 ieee->is_set_key = false;
2868 queue_delayed_work_rsl(ieee->wq, &ieee->link_change_wq, 0);
2870 notify_wx_assoc_event(ieee);
2873 static void rtllib_associate_retry_wq(void *data)
2875 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2876 struct rtllib_device, associate_retry_wq);
2877 unsigned long flags;
2879 down(&ieee->wx_sem);
2880 if (!ieee->proto_started)
2883 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2886 /* until we do not set the state to RTLLIB_NOLINK
2887 * there are no possibility to have someone else trying
2888 * to start an association procedure (we get here with
2889 * ieee->state = RTLLIB_ASSOCIATING).
2890 * When we set the state to RTLLIB_NOLINK it is possible
2891 * that the RX path run an attempt to associate, but
2892 * both rtllib_softmac_check_all_nets and the
2893 * RX path works with ieee->lock held so there are no
2894 * problems. If we are still disassociated then start a scan.
2895 * the lock here is necessary to ensure no one try to start
2896 * an association procedure when we have just checked the
2897 * state and we are going to start the scan.
2899 ieee->beinretry = true;
2900 ieee->state = RTLLIB_NOLINK;
2902 rtllib_softmac_check_all_nets(ieee);
2904 spin_lock_irqsave(&ieee->lock, flags);
2906 if (ieee->state == RTLLIB_NOLINK)
2907 rtllib_start_scan(ieee);
2908 spin_unlock_irqrestore(&ieee->lock, flags);
2910 ieee->beinretry = false;
2915 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2917 u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2919 struct sk_buff *skb;
2920 struct rtllib_probe_response *b;
2922 skb = rtllib_probe_resp(ieee, broadcast_addr);
2927 b = (struct rtllib_probe_response *) skb->data;
2928 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2934 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2936 struct sk_buff *skb;
2937 struct rtllib_probe_response *b;
2939 skb = rtllib_get_beacon_(ieee);
2943 b = (struct rtllib_probe_response *) skb->data;
2944 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2946 if (ieee->seq_ctrl[0] == 0xFFF)
2947 ieee->seq_ctrl[0] = 0;
2949 ieee->seq_ctrl[0]++;
2953 EXPORT_SYMBOL(rtllib_get_beacon);
2955 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2958 rtllib_stop_scan_syncro(ieee);
2959 down(&ieee->wx_sem);
2960 rtllib_stop_protocol(ieee, shutdown);
2963 EXPORT_SYMBOL(rtllib_softmac_stop_protocol);
2966 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2968 if (!ieee->proto_started)
2972 ieee->proto_started = 0;
2973 ieee->proto_stoppping = 1;
2974 if (ieee->rtllib_ips_leave != NULL)
2975 ieee->rtllib_ips_leave(ieee->dev);
2978 rtllib_stop_send_beacons(ieee);
2979 del_timer_sync(&ieee->associate_timer);
2980 cancel_delayed_work(&ieee->associate_retry_wq);
2981 cancel_delayed_work(&ieee->start_ibss_wq);
2982 cancel_delayed_work(&ieee->link_change_wq);
2983 rtllib_stop_scan(ieee);
2985 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2986 ieee->state = RTLLIB_NOLINK;
2988 if (ieee->state == RTLLIB_LINKED) {
2989 if (ieee->iw_mode == IW_MODE_INFRA)
2990 SendDisassociation(ieee, 1, deauth_lv_ss);
2991 rtllib_disassociate(ieee);
2996 ieee->proto_stoppping = 0;
2998 kfree(ieee->assocreq_ies);
2999 ieee->assocreq_ies = NULL;
3000 ieee->assocreq_ies_len = 0;
3001 kfree(ieee->assocresp_ies);
3002 ieee->assocresp_ies = NULL;
3003 ieee->assocresp_ies_len = 0;
3006 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
3008 down(&ieee->wx_sem);
3009 rtllib_start_protocol(ieee);
3012 EXPORT_SYMBOL(rtllib_softmac_start_protocol);
3014 void rtllib_start_protocol(struct rtllib_device *ieee)
3019 rtllib_update_active_chan_map(ieee);
3021 if (ieee->proto_started)
3024 ieee->proto_started = 1;
3026 if (ieee->current_network.channel == 0) {
3029 if (ch > MAX_CHANNEL_NUMBER)
3030 return; /* no channel found */
3031 } while (!ieee->active_channel_map[ch]);
3032 ieee->current_network.channel = ch;
3035 if (ieee->current_network.beacon_interval == 0)
3036 ieee->current_network.beacon_interval = 100;
3038 for (i = 0; i < 17; i++) {
3039 ieee->last_rxseq_num[i] = -1;
3040 ieee->last_rxfrag_num[i] = -1;
3041 ieee->last_packet_time[i] = 0;
3044 if (ieee->UpdateBeaconInterruptHandler)
3045 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
3048 /* if the user set the MAC of the ad-hoc cell and then
3049 * switch to managed mode, shall we make sure that association
3050 * attempts does not fail just because the user provide the essid
3051 * and the nic is still checking for the AP MAC ??
3053 if (ieee->iw_mode == IW_MODE_INFRA) {
3054 rtllib_start_bss(ieee);
3055 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
3056 if (ieee->UpdateBeaconInterruptHandler)
3057 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
3059 rtllib_start_ibss(ieee);
3061 } else if (ieee->iw_mode == IW_MODE_MASTER) {
3062 rtllib_start_master_bss(ieee);
3063 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
3064 rtllib_start_monitor_mode(ieee);
3068 void rtllib_softmac_init(struct rtllib_device *ieee)
3072 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
3074 ieee->state = RTLLIB_NOLINK;
3075 for (i = 0; i < 5; i++)
3076 ieee->seq_ctrl[i] = 0;
3077 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
3078 if (!ieee->pDot11dInfo)
3079 RTLLIB_DEBUG(RTLLIB_DL_ERR, "can't alloc memory for DOT11D\n");
3080 ieee->LinkDetectInfo.SlotIndex = 0;
3081 ieee->LinkDetectInfo.SlotNum = 2;
3082 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3083 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
3084 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3085 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3086 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
3087 ieee->bIsAggregateFrame = false;
3089 ieee->queue_stop = 0;
3090 ieee->scanning_continue = 0;
3091 ieee->softmac_features = 0;
3094 ieee->proto_started = 0;
3095 ieee->proto_stoppping = 0;
3096 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
3098 ieee->ps = RTLLIB_PS_DISABLED;
3099 ieee->sta_sleep = LPS_IS_WAKE;
3101 ieee->Regdot11HTOperationalRateSet[0] = 0xff;
3102 ieee->Regdot11HTOperationalRateSet[1] = 0xff;
3103 ieee->Regdot11HTOperationalRateSet[4] = 0x01;
3105 ieee->Regdot11TxHTOperationalRateSet[0] = 0xff;
3106 ieee->Regdot11TxHTOperationalRateSet[1] = 0xff;
3107 ieee->Regdot11TxHTOperationalRateSet[4] = 0x01;
3109 ieee->FirstIe_InScan = false;
3110 ieee->actscanning = false;
3111 ieee->beinretry = false;
3112 ieee->is_set_key = false;
3113 init_mgmt_queue(ieee);
3115 ieee->sta_edca_param[0] = 0x0000A403;
3116 ieee->sta_edca_param[1] = 0x0000A427;
3117 ieee->sta_edca_param[2] = 0x005E4342;
3118 ieee->sta_edca_param[3] = 0x002F3262;
3119 ieee->aggregation = true;
3120 ieee->enable_rx_imm_BA = true;
3121 ieee->tx_pending.txb = NULL;
3123 _setup_timer(&ieee->associate_timer,
3124 rtllib_associate_abort_cb,
3125 (unsigned long) ieee);
3127 _setup_timer(&ieee->beacon_timer,
3128 rtllib_send_beacon_cb,
3129 (unsigned long) ieee);
3132 ieee->wq = create_workqueue(DRV_NAME);
3134 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3135 (void *)rtllib_link_change_wq, ieee);
3136 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3137 (void *)rtllib_start_ibss_wq, ieee);
3138 INIT_WORK_RSL(&ieee->associate_complete_wq,
3139 (void *)rtllib_associate_complete_wq, ieee);
3140 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3141 (void *)rtllib_associate_procedure_wq, ieee);
3142 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3143 (void *)rtllib_softmac_scan_wq, ieee);
3144 INIT_DELAYED_WORK_RSL(&ieee->softmac_hint11d_wq,
3145 (void *)rtllib_softmac_hint11d_wq, ieee);
3146 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3147 (void *)rtllib_associate_retry_wq, ieee);
3148 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3151 sema_init(&ieee->wx_sem, 1);
3152 sema_init(&ieee->scan_sem, 1);
3153 sema_init(&ieee->ips_sem, 1);
3155 spin_lock_init(&ieee->mgmt_tx_lock);
3156 spin_lock_init(&ieee->beacon_lock);
3158 tasklet_init(&ieee->ps_task,
3159 (void(*)(unsigned long)) rtllib_sta_ps,
3160 (unsigned long)ieee);
3164 void rtllib_softmac_free(struct rtllib_device *ieee)
3166 down(&ieee->wx_sem);
3167 kfree(ieee->pDot11dInfo);
3168 ieee->pDot11dInfo = NULL;
3169 del_timer_sync(&ieee->associate_timer);
3171 cancel_delayed_work(&ieee->associate_retry_wq);
3172 destroy_workqueue(ieee->wq);
3174 tasklet_kill(&ieee->ps_task);
3177 /********************************************************
3178 * Start of WPA code. *
3179 * this is stolen from the ipw2200 driver *
3180 ********************************************************/
3183 static int rtllib_wpa_enable(struct rtllib_device *ieee, int value)
3185 /* This is called when wpa_supplicant loads and closes the driver
3187 printk(KERN_INFO "%s WPA\n", value ? "enabling" : "disabling");
3188 ieee->wpa_enabled = value;
3189 memset(ieee->ap_mac_addr, 0, 6);
3194 static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie,
3197 /* make sure WPA is enabled */
3198 rtllib_wpa_enable(ieee, 1);
3200 rtllib_disassociate(ieee);
3204 static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason)
3210 case IEEE_MLME_STA_DEAUTH:
3213 case IEEE_MLME_STA_DISASSOC:
3214 rtllib_disassociate(ieee);
3218 printk(KERN_INFO "Unknown MLME request: %d\n", command);
3226 static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee,
3227 struct ieee_param *param, int plen)
3231 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3232 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3235 if (param->u.wpa_ie.len) {
3236 buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
3241 kfree(ieee->wpa_ie);
3243 ieee->wpa_ie_len = param->u.wpa_ie.len;
3245 kfree(ieee->wpa_ie);
3246 ieee->wpa_ie = NULL;
3247 ieee->wpa_ie_len = 0;
3250 rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3254 #define AUTH_ALG_OPEN_SYSTEM 0x1
3255 #define AUTH_ALG_SHARED_KEY 0x2
3256 #define AUTH_ALG_LEAP 0x4
3257 static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value)
3260 struct rtllib_security sec = {
3261 .flags = SEC_AUTH_MODE,
3264 if (value & AUTH_ALG_SHARED_KEY) {
3265 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3267 ieee->auth_mode = 1;
3268 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
3269 sec.auth_mode = WLAN_AUTH_OPEN;
3271 ieee->auth_mode = 0;
3272 } else if (value & AUTH_ALG_LEAP) {
3273 sec.auth_mode = WLAN_AUTH_LEAP >> 6;
3275 ieee->auth_mode = 2;
3279 if (ieee->set_security)
3280 ieee->set_security(ieee->dev, &sec);
3285 static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value)
3288 unsigned long flags;
3291 case IEEE_PARAM_WPA_ENABLED:
3292 ret = rtllib_wpa_enable(ieee, value);
3295 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3296 ieee->tkip_countermeasures = value;
3299 case IEEE_PARAM_DROP_UNENCRYPTED:
3303 * wpa_supplicant calls set_wpa_enabled when the driver
3304 * is loaded and unloaded, regardless of if WPA is being
3305 * used. No other calls are made which can be used to
3306 * determine if encryption will be used or not prior to
3307 * association being expected. If encryption is not being
3308 * used, drop_unencrypted is set to false, else true -- we
3309 * can use this to determine if the CAP_PRIVACY_ON bit should
3312 struct rtllib_security sec = {
3313 .flags = SEC_ENABLED,
3316 ieee->drop_unencrypted = value;
3317 /* We only change SEC_LEVEL for open mode. Others
3318 * are set by ipw_wpa_set_encryption.
3321 sec.flags |= SEC_LEVEL;
3322 sec.level = SEC_LEVEL_0;
3324 sec.flags |= SEC_LEVEL;
3325 sec.level = SEC_LEVEL_1;
3327 if (ieee->set_security)
3328 ieee->set_security(ieee->dev, &sec);
3332 case IEEE_PARAM_PRIVACY_INVOKED:
3333 ieee->privacy_invoked = value;
3336 case IEEE_PARAM_AUTH_ALGS:
3337 ret = rtllib_wpa_set_auth_algs(ieee, value);
3340 case IEEE_PARAM_IEEE_802_1X:
3341 ieee->ieee802_1x = value;
3343 case IEEE_PARAM_WPAX_SELECT:
3344 spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags);
3345 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags);
3349 printk(KERN_INFO "Unknown WPA param: %d\n", name);
3356 /* implementation borrowed from hostap driver */
3357 static int rtllib_wpa_set_encryption(struct rtllib_device *ieee,
3358 struct ieee_param *param, int param_len,
3362 struct lib80211_crypto_ops *ops;
3363 struct lib80211_crypt_data **crypt;
3365 struct rtllib_security sec = {
3369 param->u.crypt.err = 0;
3370 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3373 (int) ((char *) param->u.crypt.key - (char *) param) +
3374 param->u.crypt.key_len) {
3375 printk(KERN_INFO "Len mismatch %d, %d\n", param_len,
3376 param->u.crypt.key_len);
3379 if (is_broadcast_ether_addr(param->sta_addr)) {
3380 if (param->u.crypt.idx >= NUM_WEP_KEYS)
3382 crypt = &ieee->crypt_info.crypt[param->u.crypt.idx];
3387 if (strcmp(param->u.crypt.alg, "none") == 0) {
3390 sec.level = SEC_LEVEL_0;
3391 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3392 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3397 sec.flags |= SEC_ENABLED;
3399 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3400 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3401 strcmp(param->u.crypt.alg, "R-TKIP"))
3402 goto skip_host_crypt;
3404 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3405 if (ops == NULL && strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3406 request_module("rtllib_crypt_wep");
3407 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3408 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3409 request_module("rtllib_crypt_tkip");
3410 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3411 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3412 request_module("rtllib_crypt_ccmp");
3413 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3416 printk(KERN_INFO "unknown crypto alg '%s'\n",
3417 param->u.crypt.alg);
3418 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3422 if (*crypt == NULL || (*crypt)->ops != ops) {
3423 struct lib80211_crypt_data *new_crypt;
3425 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3427 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
3428 if (new_crypt == NULL) {
3432 new_crypt->ops = ops;
3435 new_crypt->ops->init(param->u.crypt.idx);
3437 if (new_crypt->priv == NULL) {
3439 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3447 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3448 (*crypt)->ops->set_key(param->u.crypt.key,
3449 param->u.crypt.key_len, param->u.crypt.seq,
3450 (*crypt)->priv) < 0) {
3451 printk(KERN_INFO "key setting failed\n");
3452 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3458 if (param->u.crypt.set_tx) {
3459 ieee->crypt_info.tx_keyidx = param->u.crypt.idx;
3460 sec.active_key = param->u.crypt.idx;
3461 sec.flags |= SEC_ACTIVE_KEY;
3463 sec.flags &= ~SEC_ACTIVE_KEY;
3465 if (param->u.crypt.alg != NULL) {
3466 memcpy(sec.keys[param->u.crypt.idx],
3468 param->u.crypt.key_len);
3469 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3470 sec.flags |= (1 << param->u.crypt.idx);
3472 if (strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3473 sec.flags |= SEC_LEVEL;
3474 sec.level = SEC_LEVEL_1;
3475 } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3476 sec.flags |= SEC_LEVEL;
3477 sec.level = SEC_LEVEL_2;
3478 } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3479 sec.flags |= SEC_LEVEL;
3480 sec.level = SEC_LEVEL_3;
3484 if (ieee->set_security)
3485 ieee->set_security(ieee->dev, &sec);
3487 /* Do not reset port if card is in Managed mode since resetting will
3488 * generate new IEEE 802.11 authentication which may end up in looping
3489 * with IEEE 802.1X. If your hardware requires a reset after WEP
3490 * configuration (for example... Prism2), implement the reset_port in
3491 * the callbacks structures used to initialize the 802.11 stack. */
3492 if (ieee->reset_on_keychange &&
3493 ieee->iw_mode != IW_MODE_INFRA &&
3495 ieee->reset_port(ieee->dev)) {
3496 printk(KERN_INFO "reset_port failed\n");
3497 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3504 inline struct sk_buff *rtllib_disauth_skb(struct rtllib_network *beacon,
3505 struct rtllib_device *ieee, u16 asRsn)
3507 struct sk_buff *skb;
3508 struct rtllib_disauth *disauth;
3509 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3511 skb = dev_alloc_skb(len);
3515 skb_reserve(skb, ieee->tx_headroom);
3517 disauth = (struct rtllib_disauth *) skb_put(skb,
3518 sizeof(struct rtllib_disauth));
3519 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3520 disauth->header.duration_id = 0;
3522 memcpy(disauth->header.addr1, beacon->bssid, ETH_ALEN);
3523 memcpy(disauth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3524 memcpy(disauth->header.addr3, beacon->bssid, ETH_ALEN);
3526 disauth->reason = cpu_to_le16(asRsn);
3530 inline struct sk_buff *rtllib_disassociate_skb(struct rtllib_network *beacon,
3531 struct rtllib_device *ieee, u16 asRsn)
3533 struct sk_buff *skb;
3534 struct rtllib_disassoc *disass;
3535 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3537 skb = dev_alloc_skb(len);
3542 skb_reserve(skb, ieee->tx_headroom);
3544 disass = (struct rtllib_disassoc *) skb_put(skb,
3545 sizeof(struct rtllib_disassoc));
3546 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3547 disass->header.duration_id = 0;
3549 memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
3550 memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3551 memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
3553 disass->reason = cpu_to_le16(asRsn);
3557 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3559 struct rtllib_network *beacon = &ieee->current_network;
3560 struct sk_buff *skb;
3563 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3565 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3568 softmac_mgmt_xmit(skb, ieee);
3571 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3573 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3574 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3575 int wpa_ie_len = ieee->wpa_ie_len;
3576 struct lib80211_crypt_data *crypt;
3579 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3580 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3581 || (ieee->host_encrypt && crypt && crypt->ops &&
3582 (0 == strcmp(crypt->ops->name, "R-WEP")));
3585 if (encrypt && (wpa_ie_len == 0)) {
3587 } else if ((wpa_ie_len != 0)) {
3588 if (((ieee->wpa_ie[0] == 0xdd) &&
3589 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3590 ((ieee->wpa_ie[0] == 0x30) &&
3591 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3592 return SEC_ALG_CCMP;
3594 return SEC_ALG_TKIP;
3596 return SEC_ALG_NONE;
3600 int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p,
3603 struct ieee_param *param;
3606 down(&ieee->wx_sem);
3608 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3613 param = memdup_user(p->pointer, p->length);
3614 if (IS_ERR(param)) {
3615 ret = PTR_ERR(param);
3619 switch (param->cmd) {
3620 case IEEE_CMD_SET_WPA_PARAM:
3621 ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name,
3622 param->u.wpa_param.value);
3625 case IEEE_CMD_SET_WPA_IE:
3626 ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length);
3629 case IEEE_CMD_SET_ENCRYPTION:
3630 ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0);
3634 ret = rtllib_wpa_mlme(ieee, param->u.mlme.command,
3635 param->u.mlme.reason_code);
3639 printk(KERN_INFO "Unknown WPA supplicant request: %d\n",
3645 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3654 EXPORT_SYMBOL(rtllib_wpa_supplicant_ioctl);
3656 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3660 bool bFilterOutNonAssociatedBSSID = false;
3662 rtllib->state = RTLLIB_NOLINK;
3664 for (i = 0; i < 6; i++)
3665 rtllib->current_network.bssid[i] = 0x55;
3667 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3668 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3669 rtllib->current_network.bssid);
3670 OpMode = RT_OP_MODE_NO_LINK;
3671 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3672 rtllib_stop_send_beacons(rtllib);
3674 bFilterOutNonAssociatedBSSID = false;
3675 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3676 (u8 *)(&bFilterOutNonAssociatedBSSID));
3677 notify_wx_assoc_event(rtllib);
3681 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, u8 *asSta,
3687 RemovePeerTS(rtllib, asSta);
3689 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3690 rtllib->state = RTLLIB_NOLINK;
3692 for (i = 0; i < 6; i++)
3693 rtllib->current_network.bssid[i] = 0x22;
3694 OpMode = RT_OP_MODE_NO_LINK;
3695 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3696 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3698 rtllib_disassociate(rtllib);
3700 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3701 rtllib->current_network.bssid);
3708 rtllib_MgntDisconnectAP(
3709 struct rtllib_device *rtllib,
3713 bool bFilterOutNonAssociatedBSSID = false;
3715 bFilterOutNonAssociatedBSSID = false;
3716 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3717 (u8 *)(&bFilterOutNonAssociatedBSSID));
3718 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3721 rtllib->state = RTLLIB_NOLINK;
3724 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3726 if (rtllib->ps != RTLLIB_PS_DISABLED)
3727 rtllib->sta_wake_up(rtllib->dev);
3729 if (rtllib->state == RTLLIB_LINKED) {
3730 if (rtllib->iw_mode == IW_MODE_ADHOC)
3731 rtllib_MgntDisconnectIBSS(rtllib);
3732 if (rtllib->iw_mode == IW_MODE_INFRA)
3733 rtllib_MgntDisconnectAP(rtllib, asRsn);
3739 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3741 void notify_wx_assoc_event(struct rtllib_device *ieee)
3743 union iwreq_data wrqu;
3745 if (ieee->cannot_notify)
3748 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3749 if (ieee->state == RTLLIB_LINKED)
3750 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3754 printk(KERN_INFO "%s(): Tell user space disconnected\n",
3756 eth_zero_addr(wrqu.ap_addr.sa_data);
3758 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3760 EXPORT_SYMBOL(notify_wx_assoc_event);