1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
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/version.h>
22 #include <linux/uaccess.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 pleacing 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 /* pleace the MFIE rate, tag to the memory (double) poined.
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)
133 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
136 * if the queue is full but we have newer frames then
137 * just overwrites the oldest.
139 * if (nh == ieee->mgmt_queue_tail)
142 ieee->mgmt_queue_head = nh;
143 ieee->mgmt_queue_ring[nh] = skb;
147 static struct sk_buff *dequeue_mgmt(struct rtllib_device *ieee)
151 if (ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
154 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
156 ieee->mgmt_queue_tail =
157 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
162 static void init_mgmt_queue(struct rtllib_device *ieee)
164 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
169 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
176 for (i = 0; i < ieee->current_network.rates_len; i++) {
177 BasicRate = ieee->current_network.rates[i]&0x7F;
178 if (!rtllib_is_cck_rate(BasicRate)) {
179 if (QueryRate == 0) {
180 QueryRate = BasicRate;
182 if (BasicRate < QueryRate)
183 QueryRate = BasicRate;
188 if (QueryRate == 0) {
190 printk(KERN_INFO "No BasicRate found!!\n");
195 u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
197 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
200 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
203 rate = ieee->basic_rate & 0x7f;
206 if (ieee->mode == IEEE_A ||
207 ieee->mode == IEEE_N_5G ||
208 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
217 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
220 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
221 struct rtllib_hdr_3addr *header =
222 (struct rtllib_hdr_3addr *) skb->data;
224 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
225 spin_lock_irqsave(&ieee->lock, flags);
227 /* called with 2nd param 0, no mgmt lock required */
228 rtllib_sta_wakeup(ieee, 0);
230 if (header->frame_ctl == RTLLIB_STYPE_BEACON)
231 tcb_desc->queue_index = BEACON_QUEUE;
233 tcb_desc->queue_index = MGNT_QUEUE;
235 if (ieee->disable_mgnt_queue)
236 tcb_desc->queue_index = HIGH_QUEUE;
238 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
239 tcb_desc->RATRIndex = 7;
240 tcb_desc->bTxDisableRateFallBack = 1;
241 tcb_desc->bTxUseDriverAssingedRate = 1;
243 if (ieee->queue_stop) {
244 enqueue_mgmt(ieee, skb);
246 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
248 if (ieee->seq_ctrl[0] == 0xFFF)
249 ieee->seq_ctrl[0] = 0;
253 /* avoid watchdog triggers */
254 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
258 spin_unlock_irqrestore(&ieee->lock, flags);
260 spin_unlock_irqrestore(&ieee->lock, flags);
261 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
263 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
265 if (ieee->seq_ctrl[0] == 0xFFF)
266 ieee->seq_ctrl[0] = 0;
270 /* check wether the managed packet queued greater than 5 */
271 if (!ieee->check_nic_enough_desc(ieee->dev, tcb_desc->queue_index) ||
272 (skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) != 0) ||
273 (ieee->queue_stop)) {
274 /* insert the skb packet to the management queue */
275 /* as for the completion function, it does not need
276 * to check it any more.
278 printk(KERN_INFO "%s():insert to waitqueue, queue_index"
279 ":%d!\n", __func__, tcb_desc->queue_index);
280 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
283 ieee->softmac_hard_start_xmit(skb, ieee->dev);
285 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
289 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb,
290 struct rtllib_device *ieee)
292 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
293 struct rtllib_hdr_3addr *header =
294 (struct rtllib_hdr_3addr *) skb->data;
296 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
298 fc = header->frame_ctl;
299 type = WLAN_FC_GET_TYPE(fc);
300 stype = WLAN_FC_GET_STYPE(fc);
303 if (stype != RTLLIB_STYPE_PSPOLL)
304 tcb_desc->queue_index = MGNT_QUEUE;
306 tcb_desc->queue_index = HIGH_QUEUE;
308 if (ieee->disable_mgnt_queue)
309 tcb_desc->queue_index = HIGH_QUEUE;
312 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
313 tcb_desc->RATRIndex = 7;
314 tcb_desc->bTxDisableRateFallBack = 1;
315 tcb_desc->bTxUseDriverAssingedRate = 1;
317 if (type != RTLLIB_FTYPE_CTL) {
318 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
320 if (ieee->seq_ctrl[0] == 0xFFF)
321 ieee->seq_ctrl[0] = 0;
326 /* avoid watchdog triggers */
327 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
331 if (type != RTLLIB_FTYPE_CTL) {
332 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
334 if (ieee->seq_ctrl[0] == 0xFFF)
335 ieee->seq_ctrl[0] = 0;
339 ieee->softmac_hard_start_xmit(skb, ieee->dev);
344 inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
346 unsigned int len, rate_len;
349 struct rtllib_probe_request *req;
351 len = ieee->current_network.ssid_len;
353 rate_len = rtllib_MFIE_rate_len(ieee);
355 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
356 2 + len + rate_len + ieee->tx_headroom);
361 skb_reserve(skb, ieee->tx_headroom);
363 req = (struct rtllib_probe_request *) skb_put(skb,
364 sizeof(struct rtllib_probe_request));
365 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
366 req->header.duration_id = 0;
368 memset(req->header.addr1, 0xff, ETH_ALEN);
369 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
370 memset(req->header.addr3, 0xff, ETH_ALEN);
372 tag = (u8 *) skb_put(skb, len + 2 + rate_len);
374 *tag++ = MFIE_TYPE_SSID;
376 memcpy(tag, ieee->current_network.ssid, len);
379 rtllib_MFIE_Brate(ieee, &tag);
380 rtllib_MFIE_Grate(ieee, &tag);
385 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
387 static void rtllib_send_beacon(struct rtllib_device *ieee)
392 skb = rtllib_get_beacon_(ieee);
395 softmac_mgmt_xmit(skb, ieee);
396 ieee->softmac_stats.tx_beacons++;
399 if (ieee->beacon_txing && ieee->ieee_up)
400 mod_timer(&ieee->beacon_timer, jiffies +
401 (MSECS(ieee->current_network.beacon_interval - 5)));
405 static void rtllib_send_beacon_cb(unsigned long _ieee)
407 struct rtllib_device *ieee =
408 (struct rtllib_device *) _ieee;
411 spin_lock_irqsave(&ieee->beacon_lock, flags);
412 rtllib_send_beacon(ieee);
413 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
418 * Enable network monitor mode, all rx packets will be received.
420 void rtllib_EnableNetMonitorMode(struct net_device *dev,
423 struct rtllib_device *ieee = netdev_priv_rsl(dev);
425 printk(KERN_INFO "========>Enter Monitor Mode\n");
427 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
433 * Disable network network monitor mode, only packets destinated to
434 * us will be received.
436 void rtllib_DisableNetMonitorMode(struct net_device *dev,
439 struct rtllib_device *ieee = netdev_priv_rsl(dev);
441 printk(KERN_INFO "========>Exit Monitor Mode\n");
443 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
449 * This enables the specialized promiscuous mode required by Intel.
450 * In this mode, Intel intends to hear traffics from/to other STAs in the
451 * same BSS. Therefore we don't have to disable checking BSSID and we only need
452 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
453 * packets from other STA.
455 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
458 bool bFilterOutNonAssociatedBSSID = false;
460 struct rtllib_device *ieee = netdev_priv_rsl(dev);
462 printk(KERN_INFO "========>Enter Intel Promiscuous Mode\n");
464 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
465 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
466 (u8 *)&bFilterOutNonAssociatedBSSID);
468 ieee->bNetPromiscuousMode = true;
474 * This disables the specialized promiscuous mode required by Intel.
475 * See MgntEnableIntelPromiscuousMode for detail.
477 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
480 bool bFilterOutNonAssociatedBSSID = true;
482 struct rtllib_device *ieee = netdev_priv_rsl(dev);
484 printk(KERN_INFO "========>Exit Intel Promiscuous Mode\n");
486 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
487 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
488 (u8 *)&bFilterOutNonAssociatedBSSID);
490 ieee->bNetPromiscuousMode = false;
493 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
496 skb = rtllib_probe_req(ieee);
498 softmac_mgmt_xmit(skb, ieee);
499 ieee->softmac_stats.tx_probe_rq++;
504 void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
506 if (ieee->active_scan && (ieee->softmac_features &
507 IEEE_SOFTMAC_PROBERQ)) {
508 rtllib_send_probe(ieee, 0);
509 rtllib_send_probe(ieee, 0);
513 static void rtllib_softmac_hint11d_wq(void *data)
517 void rtllib_update_active_chan_map(struct rtllib_device *ieee)
519 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
520 MAX_CHANNEL_NUMBER+1);
523 /* this performs syncro scan blocking the caller until all channels
524 * in the allowed channel map has been checked.
526 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
528 union iwreq_data wrqu;
531 rtllib_update_active_chan_map(ieee);
533 ieee->be_scan_inprogress = true;
535 down(&ieee->scan_sem);
540 if (ch > MAX_CHANNEL_NUMBER)
541 goto out; /* scan completed */
542 } while (!ieee->active_channel_map[ch]);
544 /* this fuction can be called in two situations
545 * 1- We have switched to ad-hoc mode and we are
546 * performing a complete syncro scan before conclude
547 * there are no interesting cell and to create a
548 * new one. In this case the link state is
549 * RTLLIB_NOLINK until we found an interesting cell.
550 * If so the ieee8021_new_net, called by the RX path
551 * will set the state to RTLLIB_LINKED, so we stop
553 * 2- We are linked and the root uses run iwlist scan.
554 * So we switch to RTLLIB_LINKED_SCANNING to remember
555 * that we are still logically linked (not interested in
556 * new network events, despite for updating the net list,
557 * but we are temporarly 'unlinked' as the driver shall
558 * not filter RX frames and the channel is changing.
559 * So the only situation in witch are interested is to check
560 * if the state become LINKED because of the #1 situation
563 if (ieee->state == RTLLIB_LINKED)
565 if (ieee->sync_scan_hurryup) {
566 printk(KERN_INFO "============>sync_scan_hurryup out\n");
570 ieee->set_chan(ieee->dev, ch);
571 if (ieee->active_channel_map[ch] == 1)
572 rtllib_send_probe_requests(ieee, 0);
574 /* this prevent excessive time wait when we
575 * need to wait for a syncro scan to end..
577 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
580 ieee->actscanning = false;
581 ieee->sync_scan_hurryup = 0;
583 if (ieee->state >= RTLLIB_LINKED) {
584 if (IS_DOT11D_ENABLE(ieee))
585 DOT11D_ScanComplete(ieee);
589 ieee->be_scan_inprogress = false;
591 memset(&wrqu, 0, sizeof(wrqu));
592 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
595 static void rtllib_softmac_scan_wq(void *data)
597 struct rtllib_device *ieee = container_of_dwork_rsl(data,
598 struct rtllib_device, softmac_scan_wq);
599 u8 last_channel = ieee->current_network.channel;
601 rtllib_update_active_chan_map(ieee);
605 if (rtllib_act_scanning(ieee, true) == true)
608 down(&ieee->scan_sem);
610 if (ieee->eRFPowerState == eRfOff) {
611 printk(KERN_INFO "======>%s():rf state is eRfOff, return\n",
617 ieee->current_network.channel =
618 (ieee->current_network.channel + 1) %
620 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
621 if (!ieee->active_channel_map[ieee->current_network.channel])
622 ieee->current_network.channel = 6;
623 goto out; /* no good chans */
625 } while (!ieee->active_channel_map[ieee->current_network.channel]);
627 if (ieee->scanning_continue == 0)
630 ieee->set_chan(ieee->dev, ieee->current_network.channel);
632 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
633 rtllib_send_probe_requests(ieee, 0);
635 queue_delayed_work_rsl(ieee->wq, &ieee->softmac_scan_wq,
636 MSECS(RTLLIB_SOFTMAC_SCAN_TIME));
642 if (IS_DOT11D_ENABLE(ieee))
643 DOT11D_ScanComplete(ieee);
644 ieee->current_network.channel = last_channel;
647 ieee->actscanning = false;
648 ieee->scan_watch_dog = 0;
649 ieee->scanning_continue = 0;
655 static void rtllib_beacons_start(struct rtllib_device *ieee)
658 spin_lock_irqsave(&ieee->beacon_lock, flags);
660 ieee->beacon_txing = 1;
661 rtllib_send_beacon(ieee);
663 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
666 static void rtllib_beacons_stop(struct rtllib_device *ieee)
670 spin_lock_irqsave(&ieee->beacon_lock, flags);
672 ieee->beacon_txing = 0;
673 del_timer_sync(&ieee->beacon_timer);
675 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
680 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
682 if (ieee->stop_send_beacons)
683 ieee->stop_send_beacons(ieee->dev);
684 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
685 rtllib_beacons_stop(ieee);
689 void rtllib_start_send_beacons(struct rtllib_device *ieee)
691 if (ieee->start_send_beacons)
692 ieee->start_send_beacons(ieee->dev);
693 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
694 rtllib_beacons_start(ieee);
698 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
700 down(&ieee->scan_sem);
701 ieee->scan_watch_dog = 0;
702 if (ieee->scanning_continue == 1) {
703 ieee->scanning_continue = 0;
704 ieee->actscanning = 0;
706 cancel_delayed_work(&ieee->softmac_scan_wq);
712 void rtllib_stop_scan(struct rtllib_device *ieee)
714 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
715 rtllib_softmac_stop_scan(ieee);
717 if (ieee->rtllib_stop_hw_scan)
718 ieee->rtllib_stop_hw_scan(ieee->dev);
722 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
724 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
725 ieee->sync_scan_hurryup = 1;
727 if (ieee->rtllib_stop_hw_scan)
728 ieee->rtllib_stop_hw_scan(ieee->dev);
732 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
734 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
736 return ieee->be_scan_inprogress;
738 return ieee->actscanning || ieee->be_scan_inprogress;
740 return test_bit(STATUS_SCANNING, &ieee->status);
744 /* called with ieee->lock held */
745 static void rtllib_start_scan(struct rtllib_device *ieee)
747 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
748 if (ieee->rtllib_ips_leave_wq != NULL)
749 ieee->rtllib_ips_leave_wq(ieee->dev);
751 if (IS_DOT11D_ENABLE(ieee)) {
752 if (IS_COUNTRY_IE_VALID(ieee))
753 RESET_CIE_WATCHDOG(ieee);
755 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
756 if (ieee->scanning_continue == 0) {
757 ieee->actscanning = true;
758 ieee->scanning_continue = 1;
759 queue_delayed_work_rsl(ieee->wq,
760 &ieee->softmac_scan_wq, 0);
763 if (ieee->rtllib_start_hw_scan)
764 ieee->rtllib_start_hw_scan(ieee->dev);
768 /* called with wx_sem held */
769 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
771 if (IS_DOT11D_ENABLE(ieee)) {
772 if (IS_COUNTRY_IE_VALID(ieee))
773 RESET_CIE_WATCHDOG(ieee);
775 ieee->sync_scan_hurryup = 0;
776 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
777 rtllib_softmac_scan_syncro(ieee, is_mesh);
779 if (ieee->rtllib_start_hw_scan)
780 ieee->rtllib_start_hw_scan(ieee->dev);
784 inline struct sk_buff *rtllib_authentication_req(struct rtllib_network *beacon,
785 struct rtllib_device *ieee, int challengelen, u8 *daddr)
788 struct rtllib_authentication *auth;
790 len = sizeof(struct rtllib_authentication) + challengelen +
791 ieee->tx_headroom + 4;
792 skb = dev_alloc_skb(len);
797 skb_reserve(skb, ieee->tx_headroom);
799 auth = (struct rtllib_authentication *)
800 skb_put(skb, sizeof(struct rtllib_authentication));
802 auth->header.frame_ctl = RTLLIB_STYPE_AUTH;
804 auth->header.frame_ctl |= RTLLIB_FCTL_WEP;
806 auth->header.duration_id = 0x013a;
807 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
808 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
809 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
810 if (ieee->auth_mode == 0)
811 auth->algorithm = WLAN_AUTH_OPEN;
812 else if (ieee->auth_mode == 1)
813 auth->algorithm = WLAN_AUTH_SHARED_KEY;
814 else if (ieee->auth_mode == 2)
815 auth->algorithm = WLAN_AUTH_OPEN;
816 auth->transaction = cpu_to_le16(ieee->associate_seq);
817 ieee->associate_seq++;
819 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
824 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, u8 *dest)
828 struct rtllib_probe_response *beacon_buf;
829 struct sk_buff *skb = NULL;
831 int atim_len, erp_len;
832 struct rtllib_crypt_data *crypt;
834 char *ssid = ieee->current_network.ssid;
835 int ssid_len = ieee->current_network.ssid_len;
836 int rate_len = ieee->current_network.rates_len+2;
837 int rate_ex_len = ieee->current_network.rates_ex_len;
838 int wpa_ie_len = ieee->wpa_ie_len;
839 u8 erpinfo_content = 0;
841 u8 *tmp_ht_cap_buf = NULL;
842 u8 tmp_ht_cap_len = 0;
843 u8 *tmp_ht_info_buf = NULL;
844 u8 tmp_ht_info_len = 0;
845 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
846 u8 *tmp_generic_ie_buf = NULL;
847 u8 tmp_generic_ie_len = 0;
852 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
857 if ((ieee->current_network.mode == IEEE_G) ||
858 (ieee->current_network.mode == IEEE_N_24G &&
859 ieee->pHTInfo->bCurSuppCCK)) {
862 if (ieee->current_network.buseprotection)
863 erpinfo_content |= ERP_UseProtection;
867 crypt = ieee->crypt[ieee->tx_keyidx];
868 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
869 ((0 == strcmp(crypt->ops->name, "WEP") || wpa_ie_len));
870 if (ieee->pHTInfo->bCurrentHTSupport) {
871 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
872 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
873 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
874 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
875 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
876 &tmp_ht_cap_len, encrypt, false);
877 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
880 if (pHTInfo->bRegRT2RTAggregation) {
881 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
883 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
884 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
885 &tmp_generic_ie_len);
889 beacon_size = sizeof(struct rtllib_probe_response)+2+
890 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
891 + wpa_ie_len + ieee->tx_headroom;
892 skb = dev_alloc_skb(beacon_size);
896 skb_reserve(skb, ieee->tx_headroom);
898 beacon_buf = (struct rtllib_probe_response *) skb_put(skb,
899 (beacon_size - ieee->tx_headroom));
900 memcpy(beacon_buf->header.addr1, dest, ETH_ALEN);
901 memcpy(beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
902 memcpy(beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
904 beacon_buf->header.duration_id = 0;
905 beacon_buf->beacon_interval =
906 cpu_to_le16(ieee->current_network.beacon_interval);
907 beacon_buf->capability =
908 cpu_to_le16(ieee->current_network.capability &
909 WLAN_CAPABILITY_IBSS);
910 beacon_buf->capability |=
911 cpu_to_le16(ieee->current_network.capability &
912 WLAN_CAPABILITY_SHORT_PREAMBLE);
914 if (ieee->short_slot && (ieee->current_network.capability &
915 WLAN_CAPABILITY_SHORT_SLOT_TIME))
916 cpu_to_le16((beacon_buf->capability |=
917 WLAN_CAPABILITY_SHORT_SLOT_TIME));
919 crypt = ieee->crypt[ieee->tx_keyidx];
921 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
924 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
925 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
926 beacon_buf->info_element[0].len = ssid_len;
928 tag = (u8 *) beacon_buf->info_element[0].data;
930 memcpy(tag, ssid, ssid_len);
934 *(tag++) = MFIE_TYPE_RATES;
935 *(tag++) = rate_len-2;
936 memcpy(tag, ieee->current_network.rates, rate_len-2);
939 *(tag++) = MFIE_TYPE_DS_SET;
941 *(tag++) = ieee->current_network.channel;
945 *(tag++) = MFIE_TYPE_IBSS_SET;
947 val16 = cpu_to_le16(ieee->current_network.atim_window);
948 memcpy((u8 *)tag, (u8 *)&val16, 2);
953 *(tag++) = MFIE_TYPE_ERP;
955 *(tag++) = erpinfo_content;
958 *(tag++) = MFIE_TYPE_RATES_EX;
959 *(tag++) = rate_ex_len-2;
960 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
961 tag += rate_ex_len-2;
965 if (ieee->iw_mode == IW_MODE_ADHOC)
966 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
967 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
968 tag += ieee->wpa_ie_len;
973 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
978 struct rtllib_crypt_data *crypt;
979 struct rtllib_assoc_response_frame *assoc;
982 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
983 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
986 skb = dev_alloc_skb(len);
991 skb_reserve(skb, ieee->tx_headroom);
993 assoc = (struct rtllib_assoc_response_frame *)
994 skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
996 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
997 memcpy(assoc->header.addr1, dest, ETH_ALEN);
998 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
999 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1000 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1001 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
1004 if (ieee->short_slot)
1005 assoc->capability |=
1006 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1008 if (ieee->host_encrypt)
1009 crypt = ieee->crypt[ieee->tx_keyidx];
1013 encrypt = (crypt && crypt->ops);
1016 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1019 assoc->aid = cpu_to_le16(ieee->assoc_id);
1020 if (ieee->assoc_id == 0x2007)
1025 tag = (u8 *) skb_put(skb, rate_len);
1026 rtllib_MFIE_Brate(ieee, &tag);
1027 rtllib_MFIE_Grate(ieee, &tag);
1032 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1035 struct sk_buff *skb = NULL;
1036 struct rtllib_authentication *auth;
1037 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1038 skb = dev_alloc_skb(len);
1042 skb->len = sizeof(struct rtllib_authentication);
1044 skb_reserve(skb, ieee->tx_headroom);
1046 auth = (struct rtllib_authentication *)
1047 skb_put(skb, sizeof(struct rtllib_authentication));
1049 auth->status = cpu_to_le16(status);
1050 auth->transaction = cpu_to_le16(2);
1051 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1053 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1054 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1055 memcpy(auth->header.addr1, dest, ETH_ALEN);
1056 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1062 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1064 struct sk_buff *skb;
1065 struct rtllib_hdr_3addr *hdr;
1067 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1071 skb_reserve(skb, ieee->tx_headroom);
1073 hdr = (struct rtllib_hdr_3addr *)skb_put(skb,
1074 sizeof(struct rtllib_hdr_3addr));
1076 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1077 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1078 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1080 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1081 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1082 (pwr ? RTLLIB_FCTL_PM : 0));
1089 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1091 struct sk_buff *skb;
1092 struct rtllib_pspoll_hdr *hdr;
1094 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1098 skb_reserve(skb, ieee->tx_headroom);
1100 hdr = (struct rtllib_pspoll_hdr *)skb_put(skb,
1101 sizeof(struct rtllib_pspoll_hdr));
1103 memcpy(hdr->bssid, ieee->current_network.bssid, ETH_ALEN);
1104 memcpy(hdr->ta, ieee->dev->dev_addr, ETH_ALEN);
1106 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1107 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1114 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1116 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1119 softmac_mgmt_xmit(buf, ieee);
1123 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1125 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1128 softmac_mgmt_xmit(buf, ieee);
1132 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1135 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1137 softmac_mgmt_xmit(buf, ieee);
1141 inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1146 if ((ieee->PMKIDList[i].bUsed) &&
1147 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1151 } while (i < NUM_PMKID_CACHE);
1153 if (i == NUM_PMKID_CACHE)
1158 inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1159 struct rtllib_device *ieee)
1161 struct sk_buff *skb;
1162 struct rtllib_assoc_request_frame *hdr;
1165 u8 *ht_cap_buf = NULL;
1167 u8 *realtek_ie_buf = NULL;
1168 u8 realtek_ie_len = 0;
1169 int wpa_ie_len = ieee->wpa_ie_len;
1170 int wps_ie_len = ieee->wps_ie_len;
1171 unsigned int ckip_ie_len = 0;
1172 unsigned int ccxrm_ie_len = 0;
1173 unsigned int cxvernum_ie_len = 0;
1174 struct rtllib_crypt_data *crypt;
1178 unsigned int rate_len = (beacon->rates_len ?
1179 (beacon->rates_len + 2) : 0) +
1180 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1183 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1184 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1187 crypt = ieee->crypt[ieee->tx_keyidx];
1189 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1190 ((0 == strcmp(crypt->ops->name, "WEP") ||
1195 if ((ieee->rtllib_ap_sec_type &&
1196 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1197 (ieee->bForcedBgMode == true)) {
1198 ieee->pHTInfo->bEnableHT = 0;
1199 ieee->mode = WIRELESS_MODE_G;
1202 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1203 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1204 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1205 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1207 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1208 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1210 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1211 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1216 if (beacon->bCkipSupported)
1218 if (beacon->bCcxRmEnable)
1220 if (beacon->BssCcxVerNumber >= 2)
1221 cxvernum_ie_len = 5+2;
1223 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1224 if (PMKCacheIdx >= 0) {
1226 printk(KERN_INFO "[PMK cache]: WPA2 IE length: %x\n",
1229 len = sizeof(struct rtllib_assoc_request_frame) + 2
1241 + ieee->tx_headroom;
1243 skb = dev_alloc_skb(len);
1248 skb_reserve(skb, ieee->tx_headroom);
1250 hdr = (struct rtllib_assoc_request_frame *)
1251 skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1254 hdr->header.frame_ctl = RTLLIB_STYPE_ASSOC_REQ;
1255 hdr->header.duration_id = 37;
1256 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1257 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1258 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1260 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);
1262 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1263 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1264 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1266 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1267 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1269 if (ieee->short_slot &&
1270 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1271 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1274 hdr->listen_interval = beacon->listen_interval;
1276 hdr->info_element[0].id = MFIE_TYPE_SSID;
1278 hdr->info_element[0].len = beacon->ssid_len;
1279 tag = skb_put(skb, beacon->ssid_len);
1280 memcpy(tag, beacon->ssid, beacon->ssid_len);
1282 tag = skb_put(skb, rate_len);
1284 if (beacon->rates_len) {
1285 *tag++ = MFIE_TYPE_RATES;
1286 *tag++ = beacon->rates_len;
1287 for (i = 0; i < beacon->rates_len; i++)
1288 *tag++ = beacon->rates[i];
1291 if (beacon->rates_ex_len) {
1292 *tag++ = MFIE_TYPE_RATES_EX;
1293 *tag++ = beacon->rates_ex_len;
1294 for (i = 0; i < beacon->rates_ex_len; i++)
1295 *tag++ = beacon->rates_ex[i];
1298 if (beacon->bCkipSupported) {
1299 static u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1300 u8 CcxAironetBuf[30];
1301 struct octet_string osCcxAironetIE;
1303 memset(CcxAironetBuf, 0, 30);
1304 osCcxAironetIE.Octet = CcxAironetBuf;
1305 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1306 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1307 sizeof(AironetIeOui));
1309 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1310 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1311 tag = skb_put(skb, ckip_ie_len);
1312 *tag++ = MFIE_TYPE_AIRONET;
1313 *tag++ = osCcxAironetIE.Length;
1314 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1315 tag += osCcxAironetIE.Length;
1318 if (beacon->bCcxRmEnable) {
1319 static u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01, 0x00};
1320 struct octet_string osCcxRmCap;
1322 osCcxRmCap.Octet = CcxRmCapBuf;
1323 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1324 tag = skb_put(skb, ccxrm_ie_len);
1325 *tag++ = MFIE_TYPE_GENERIC;
1326 *tag++ = osCcxRmCap.Length;
1327 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1328 tag += osCcxRmCap.Length;
1331 if (beacon->BssCcxVerNumber >= 2) {
1332 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1333 struct octet_string osCcxVerNum;
1334 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1335 osCcxVerNum.Octet = CcxVerNumBuf;
1336 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1337 tag = skb_put(skb, cxvernum_ie_len);
1338 *tag++ = MFIE_TYPE_GENERIC;
1339 *tag++ = osCcxVerNum.Length;
1340 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1341 tag += osCcxVerNum.Length;
1343 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1344 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1345 tag = skb_put(skb, ht_cap_len);
1346 *tag++ = MFIE_TYPE_HT_CAP;
1347 *tag++ = ht_cap_len - 2;
1348 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1349 tag += ht_cap_len - 2;
1354 tag = skb_put(skb, ieee->wpa_ie_len);
1355 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1357 if (PMKCacheIdx >= 0) {
1358 tag = skb_put(skb, 18);
1361 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1366 tag = skb_put(skb, wmm_info_len);
1367 rtllib_WMM_Info(ieee, &tag);
1370 if (wps_ie_len && ieee->wps_ie) {
1371 tag = skb_put(skb, wps_ie_len);
1372 memcpy(tag, ieee->wps_ie, wps_ie_len);
1375 tag = skb_put(skb, turbo_info_len);
1377 rtllib_TURBO_Info(ieee, &tag);
1379 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1380 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1381 tag = skb_put(skb, ht_cap_len);
1382 *tag++ = MFIE_TYPE_GENERIC;
1383 *tag++ = ht_cap_len - 2;
1384 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1385 tag += ht_cap_len - 2;
1388 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1389 tag = skb_put(skb, realtek_ie_len);
1390 *tag++ = MFIE_TYPE_GENERIC;
1391 *tag++ = realtek_ie_len - 2;
1392 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1396 kfree(ieee->assocreq_ies);
1397 ieee->assocreq_ies = NULL;
1398 ies = &(hdr->info_element[0].id);
1399 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1400 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1401 if (ieee->assocreq_ies)
1402 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1404 printk(KERN_INFO "%s()Warning: can't alloc memory for assocreq"
1405 "_ies\n", __func__);
1406 ieee->assocreq_ies_len = 0;
1411 void rtllib_associate_abort(struct rtllib_device *ieee)
1414 unsigned long flags;
1415 spin_lock_irqsave(&ieee->lock, flags);
1417 ieee->associate_seq++;
1419 /* don't scan, and avoid to have the RX path possibily
1420 * try again to associate. Even do not react to AUTH or
1421 * ASSOC response. Just wait for the retry wq to be scheduled.
1422 * Here we will check if there are good nets to associate
1423 * with, so we retry or just get back to NO_LINK and scanning
1425 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1426 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1427 ieee->softmac_stats.no_auth_rs++;
1429 RTLLIB_DEBUG_MGMT("Association failed\n");
1430 ieee->softmac_stats.no_ass_rs++;
1433 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1435 queue_delayed_work_rsl(ieee->wq, &ieee->associate_retry_wq,
1436 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1438 spin_unlock_irqrestore(&ieee->lock, flags);
1441 static void rtllib_associate_abort_cb(unsigned long dev)
1443 rtllib_associate_abort((struct rtllib_device *) dev);
1446 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 * daddr)
1448 struct rtllib_network *beacon = &ieee->current_network;
1449 struct sk_buff *skb;
1451 RTLLIB_DEBUG_MGMT("Stopping scan\n");
1453 ieee->softmac_stats.tx_auth_rq++;
1455 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1458 rtllib_associate_abort(ieee);
1460 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING ;
1461 RTLLIB_DEBUG_MGMT("Sending authentication request\n");
1462 softmac_mgmt_xmit(skb, ieee);
1463 if (!timer_pending(&ieee->associate_timer)) {
1464 ieee->associate_timer.expires = jiffies + (HZ / 2);
1465 add_timer(&ieee->associate_timer);
1470 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge, int chlen)
1473 struct sk_buff *skb;
1474 struct rtllib_network *beacon = &ieee->current_network;
1476 ieee->associate_seq++;
1477 ieee->softmac_stats.tx_auth_rq++;
1479 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1482 rtllib_associate_abort(ieee);
1484 c = skb_put(skb, chlen+2);
1485 *(c++) = MFIE_TYPE_CHALLENGE;
1487 memcpy(c, challenge, chlen);
1489 RTLLIB_DEBUG_MGMT("Sending authentication challenge "
1492 rtllib_encrypt_fragment(ieee, skb,
1493 sizeof(struct rtllib_hdr_3addr));
1495 softmac_mgmt_xmit(skb, ieee);
1496 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1501 static void rtllib_associate_step2(struct rtllib_device *ieee)
1503 struct sk_buff *skb;
1504 struct rtllib_network *beacon = &ieee->current_network;
1506 del_timer_sync(&ieee->associate_timer);
1508 RTLLIB_DEBUG_MGMT("Sending association request\n");
1510 ieee->softmac_stats.tx_ass_rq++;
1511 skb = rtllib_association_req(beacon, ieee);
1513 rtllib_associate_abort(ieee);
1515 softmac_mgmt_xmit(skb, ieee);
1516 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1521 static void rtllib_associate_complete_wq(void *data)
1523 struct rtllib_device *ieee = (struct rtllib_device *)
1524 container_of_work_rsl(data,
1525 struct rtllib_device,
1526 associate_complete_wq);
1527 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1528 (&(ieee->PowerSaveControl));
1529 printk(KERN_INFO "Associated successfully\n");
1530 if (ieee->is_silent_reset == 0) {
1531 printk(KERN_INFO "normal associate\n");
1532 notify_wx_assoc_event(ieee);
1535 netif_carrier_on(ieee->dev);
1536 ieee->is_roaming = false;
1537 if (rtllib_is_54g(&ieee->current_network) &&
1538 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1540 printk(KERN_INFO"Using G rates:%d\n", ieee->rate);
1543 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1544 printk(KERN_INFO"Using B rates:%d\n", ieee->rate);
1546 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1547 printk(KERN_INFO "Successfully associated, ht enabled\n");
1550 printk(KERN_INFO "Successfully associated, ht not "
1551 "enabled(%d, %d)\n",
1552 ieee->pHTInfo->bCurrentHTSupport,
1553 ieee->pHTInfo->bEnableHT);
1554 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1556 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1557 ieee->current_network.beacon_interval /
1559 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1560 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1561 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1562 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1564 pPSC->LpsIdleCount = 0;
1565 ieee->link_change(ieee->dev);
1567 if (ieee->is_silent_reset == 1) {
1568 printk(KERN_INFO "silent reset associate\n");
1569 ieee->is_silent_reset = 0;
1572 if (ieee->data_hard_resume)
1573 ieee->data_hard_resume(ieee->dev);
1577 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1581 static void rtllib_associate_complete(struct rtllib_device *ieee)
1583 del_timer_sync(&ieee->associate_timer);
1585 ieee->state = RTLLIB_LINKED;
1586 rtllib_sta_send_associnfo(ieee);
1588 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1591 static void rtllib_associate_procedure_wq(void *data)
1593 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1594 struct rtllib_device,
1595 associate_procedure_wq);
1596 rtllib_stop_scan_syncro(ieee);
1597 if (ieee->rtllib_ips_leave != NULL)
1598 ieee->rtllib_ips_leave(ieee->dev);
1599 down(&ieee->wx_sem);
1601 if (ieee->data_hard_stop)
1602 ieee->data_hard_stop(ieee->dev);
1604 rtllib_stop_scan(ieee);
1605 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1606 ieee->current_network.channel);
1607 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1608 if (ieee->eRFPowerState == eRfOff) {
1609 RT_TRACE(COMP_DBG, "=============>%s():Rf state is eRfOff,"
1610 " schedule ipsleave wq again,return\n", __func__);
1611 if (ieee->rtllib_ips_leave_wq != NULL)
1612 ieee->rtllib_ips_leave_wq(ieee->dev);
1616 ieee->associate_seq = 1;
1618 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1623 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1624 struct rtllib_network *net)
1626 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1627 int tmp_ssid_len = 0;
1629 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1631 /* we are interested in new new only if we are not associated
1632 * and we are not associating / authenticating
1634 if (ieee->state != RTLLIB_NOLINK)
1637 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1638 WLAN_CAPABILITY_ESS))
1641 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1642 WLAN_CAPABILITY_IBSS))
1645 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1646 (net->channel > ieee->ibss_maxjoin_chal))
1648 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1649 /* if the user specified the AP MAC, we need also the essid
1650 * This could be obtained by beacons or, if the network does not
1651 * broadcast it, it can be put manually.
1653 apset = ieee->wap_set;
1654 ssidset = ieee->ssid_set;
1655 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1656 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1659 ssidmatch = (ieee->current_network.ssid_len ==
1660 net->hidden_ssid_len) &&
1661 (!strncmp(ieee->current_network.ssid,
1662 net->hidden_ssid, net->hidden_ssid_len));
1663 if (net->hidden_ssid_len > 0) {
1664 strncpy(net->ssid, net->hidden_ssid,
1665 net->hidden_ssid_len);
1666 net->ssid_len = net->hidden_ssid_len;
1671 (ieee->current_network.ssid_len == net->ssid_len) &&
1672 (!strncmp(ieee->current_network.ssid, net->ssid,
1675 /* if the user set the AP check if match.
1676 * if the network does not broadcast essid we check the
1677 * user supplyed ANY essid
1678 * if the network does broadcast and the user does not set
1680 * if the network does broadcast and the user did set essid
1681 * check if essid match
1682 * if the ap is not set, check that the user set the bssid
1683 * and the network does bradcast and that those two bssid match
1685 if ((apset && apmatch &&
1686 ((ssidset && ssidbroad && ssidmatch) ||
1687 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1688 (!apset && ssidset && ssidbroad && ssidmatch) ||
1689 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1690 /* if the essid is hidden replace it with the
1691 * essid provided by the user.
1694 strncpy(tmp_ssid, ieee->current_network.ssid,
1696 tmp_ssid_len = ieee->current_network.ssid_len;
1698 memcpy(&ieee->current_network, net,
1699 sizeof(struct rtllib_network));
1701 strncpy(ieee->current_network.ssid, tmp_ssid,
1703 ieee->current_network.ssid_len = tmp_ssid_len;
1705 printk(KERN_INFO"Linking with %s,channel:%d, qos:%d, "
1706 "myHT:%d, networkHT:%d, mode:%x cur_net.flags"
1707 ":0x%x\n", ieee->current_network.ssid,
1708 ieee->current_network.channel,
1709 ieee->current_network.qos_data.supported,
1710 ieee->pHTInfo->bEnableHT,
1711 ieee->current_network.bssht.bdSupportHT,
1712 ieee->current_network.mode,
1713 ieee->current_network.flags);
1715 if ((rtllib_act_scanning(ieee, false)) &&
1716 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1717 rtllib_stop_scan_syncro(ieee);
1719 ieee->hwscan_ch_bk = ieee->current_network.channel;
1720 HTResetIOTSetting(ieee->pHTInfo);
1722 if (ieee->iw_mode == IW_MODE_INFRA) {
1723 /* Join the network for the first time */
1724 ieee->AsocRetryCount = 0;
1725 if ((ieee->current_network.qos_data.supported == 1) &&
1726 ieee->current_network.bssht.bdSupportHT)
1727 HTResetSelfAndSavePeerSetting(ieee,
1728 &(ieee->current_network));
1730 ieee->pHTInfo->bCurrentHTSupport =
1733 ieee->state = RTLLIB_ASSOCIATING;
1734 if (ieee->LedControlHandler != NULL)
1735 ieee->LedControlHandler(ieee->dev,
1736 LED_CTL_START_TO_LINK);
1737 queue_delayed_work_rsl(ieee->wq,
1738 &ieee->associate_procedure_wq, 0);
1740 if (rtllib_is_54g(&ieee->current_network) &&
1741 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1743 ieee->SetWirelessMode(ieee->dev, IEEE_G);
1744 printk(KERN_INFO"Using G rates\n");
1747 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1748 printk(KERN_INFO"Using B rates\n");
1750 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1751 ieee->state = RTLLIB_LINKED;
1757 void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1759 unsigned long flags;
1760 struct rtllib_network *target;
1762 spin_lock_irqsave(&ieee->lock, flags);
1764 list_for_each_entry(target, &ieee->network_list, list) {
1766 /* if the state become different that NOLINK means
1767 * we had found what we are searching for
1770 if (ieee->state != RTLLIB_NOLINK)
1773 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1774 ieee->scan_age, jiffies))
1775 rtllib_softmac_new_net(ieee, target);
1777 spin_unlock_irqrestore(&ieee->lock, flags);
1780 static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
1782 struct rtllib_authentication *a;
1784 if (skb->len < (sizeof(struct rtllib_authentication) -
1785 sizeof(struct rtllib_info_element))) {
1786 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1790 a = (struct rtllib_authentication *) skb->data;
1791 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1792 t = skb->data + sizeof(struct rtllib_authentication);
1794 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1796 *challenge = kmalloc(*chlen, GFP_ATOMIC);
1797 memcpy(*challenge, t, *chlen); /*TODO - check here*/
1800 return cpu_to_le16(a->status);
1803 static int auth_rq_parse(struct sk_buff *skb, u8 *dest)
1805 struct rtllib_authentication *a;
1807 if (skb->len < (sizeof(struct rtllib_authentication) -
1808 sizeof(struct rtllib_info_element))) {
1809 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",
1813 a = (struct rtllib_authentication *) skb->data;
1815 memcpy(dest, a->header.addr2, ETH_ALEN);
1817 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1818 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1820 return WLAN_STATUS_SUCCESS;
1823 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1830 struct rtllib_hdr_3addr *header =
1831 (struct rtllib_hdr_3addr *) skb->data;
1834 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1835 return -1; /* corrupted */
1838 (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0) &&
1839 (memcmp(header->addr3, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0);
1843 memcpy(src, header->addr2, ETH_ALEN);
1845 skbend = (u8 *)skb->data + skb->len;
1847 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1849 while (tag + 1 < skbend) {
1852 ssidlen = *(tag + 1);
1855 tag++; /* point to the len field */
1856 tag = tag + *(tag); /* point to the last data byte of the tag */
1857 tag++; /* point to the next tag */
1864 return 1; /* ssid not found in tagged param */
1866 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1869 static int assoc_rq_parse(struct sk_buff *skb, u8 *dest)
1871 struct rtllib_assoc_request_frame *a;
1873 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1874 sizeof(struct rtllib_info_element))) {
1876 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d\n", skb->len);
1880 a = (struct rtllib_assoc_request_frame *) skb->data;
1882 memcpy(dest, a->header.addr2, ETH_ALEN);
1887 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1890 struct rtllib_assoc_response_frame *response_head;
1893 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1894 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1898 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1899 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1901 status_code = le16_to_cpu(response_head->status);
1902 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1903 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1904 ((ieee->mode == IEEE_G) &&
1905 (ieee->current_network.mode == IEEE_N_24G) &&
1906 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1907 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1909 ieee->AsocRetryCount = 0;
1912 return le16_to_cpu(response_head->status);
1915 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1918 ieee->softmac_stats.rx_probe_rq++;
1919 if (probe_rq_parse(ieee, skb, dest) > 0) {
1920 ieee->softmac_stats.tx_probe_rs++;
1921 rtllib_resp_to_probe(ieee, dest);
1925 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1926 struct sk_buff *skb)
1930 ieee->softmac_stats.rx_auth_rq++;
1932 status = auth_rq_parse(skb, dest);
1934 rtllib_resp_to_auth(ieee, status, dest);
1937 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1938 struct sk_buff *skb)
1943 ieee->softmac_stats.rx_ass_rq++;
1944 if (assoc_rq_parse(skb, dest) != -1)
1945 rtllib_resp_to_assoc_rq(ieee, dest);
1947 printk(KERN_INFO"New client associated: %pM\n", dest);
1950 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1953 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1956 softmac_ps_mgmt_xmit(buf, ieee);
1959 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1961 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1964 softmac_ps_mgmt_xmit(buf, ieee);
1967 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1969 int timeout = ieee->ps_timeout;
1971 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1972 (&(ieee->PowerSaveControl));
1974 if (ieee->LPSDelayCnt) {
1975 ieee->LPSDelayCnt--;
1979 dtim = ieee->current_network.dtim_data;
1980 if (!(dtim & RTLLIB_DTIM_VALID))
1982 timeout = ieee->current_network.beacon_interval;
1983 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
1984 /* there's no need to nofity AP that I find you buffered
1985 * with broadcast packet */
1986 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
1989 if (!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout)))
1991 if (!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout)))
1993 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
1994 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1998 if (ieee->bAwakePktSent == true) {
1999 pPSC->LPSAwakeIntvl = 1;
2003 if (pPSC->LPSAwakeIntvl == 0)
2004 pPSC->LPSAwakeIntvl = 1;
2005 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2007 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2008 MaxPeriod = ieee->current_network.dtim_period;
2010 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2011 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2012 MaxPeriod) ? MaxPeriod :
2013 (pPSC->LPSAwakeIntvl + 1);
2016 u8 LPSAwakeIntvl_tmp = 0;
2017 u8 period = ieee->current_network.dtim_period;
2018 u8 count = ieee->current_network.tim.tim_count;
2020 if (pPSC->LPSAwakeIntvl > period)
2021 LPSAwakeIntvl_tmp = period +
2022 (pPSC->LPSAwakeIntvl -
2024 ((pPSC->LPSAwakeIntvl-period) %
2027 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2030 if (pPSC->LPSAwakeIntvl >
2031 ieee->current_network.tim.tim_count)
2032 LPSAwakeIntvl_tmp = count +
2033 (pPSC->LPSAwakeIntvl - count) -
2034 ((pPSC->LPSAwakeIntvl-count)%period);
2036 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2039 *time = ieee->current_network.last_dtim_sta_time
2040 + MSECS(ieee->current_network.beacon_interval *
2050 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2054 unsigned long flags, flags2;
2056 spin_lock_irqsave(&ieee->lock, flags);
2058 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2059 ieee->iw_mode != IW_MODE_INFRA ||
2060 ieee->state != RTLLIB_LINKED)) {
2061 RT_TRACE(COMP_DBG, "=====>%s(): no need to ps,wake up!! "
2062 "ieee->ps is %d, ieee->iw_mode is %d, ieee->state"
2063 " is %d\n", __func__, ieee->ps, ieee->iw_mode,
2065 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2066 rtllib_sta_wakeup(ieee, 1);
2068 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2070 sleep = rtllib_sta_ps_sleep(ieee, &time);
2071 /* 2 wake, 1 sleep, 0 do nothing */
2075 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2076 ieee->enter_sleep_state(ieee->dev, time);
2077 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2078 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2080 if (ieee->ps_is_queue_empty(ieee->dev)) {
2081 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2082 ieee->ack_tx_to_ieee = 1;
2083 rtllib_sta_ps_send_null_frame(ieee, 1);
2084 ieee->ps_time = time;
2086 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2090 ieee->bAwakePktSent = false;
2092 } else if (sleep == 2) {
2093 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2095 rtllib_sta_wakeup(ieee, 1);
2097 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2101 spin_unlock_irqrestore(&ieee->lock, flags);
2105 void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2107 if (ieee->sta_sleep == LPS_IS_WAKE) {
2109 if (ieee->pHTInfo->IOTAction &
2110 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2111 ieee->ack_tx_to_ieee = 1;
2112 rtllib_sta_ps_send_null_frame(ieee, 0);
2114 ieee->ack_tx_to_ieee = 1;
2115 rtllib_sta_ps_send_pspoll_frame(ieee);
2122 if (ieee->sta_sleep == LPS_IS_SLEEP)
2123 ieee->sta_wake_up(ieee->dev);
2125 if (ieee->pHTInfo->IOTAction &
2126 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2127 ieee->ack_tx_to_ieee = 1;
2128 rtllib_sta_ps_send_null_frame(ieee, 0);
2130 ieee->ack_tx_to_ieee = 1;
2131 ieee->polling = true;
2132 rtllib_sta_ps_send_pspoll_frame(ieee);
2136 ieee->sta_sleep = LPS_IS_WAKE;
2137 ieee->polling = false;
2141 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2143 unsigned long flags, flags2;
2145 spin_lock_irqsave(&ieee->lock, flags);
2147 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2148 /* Null frame with PS bit set */
2150 ieee->sta_sleep = LPS_IS_SLEEP;
2151 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2153 /* if the card report not success we can't be sure the AP
2154 * has not RXed so we can't assume the AP believe us awake
2156 } else {/* 21112005 - tx again null without PS bit if lost */
2158 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2159 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2160 if (ieee->pHTInfo->IOTAction &
2161 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2162 rtllib_sta_ps_send_null_frame(ieee, 0);
2164 rtllib_sta_ps_send_pspoll_frame(ieee);
2165 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2168 spin_unlock_irqrestore(&ieee->lock, flags);
2171 static void rtllib_process_action(struct rtllib_device *ieee, struct sk_buff *skb)
2173 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2174 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2178 RTLLIB_DEBUG(RTLLIB_DL_ERR, "error to get payload of "
2189 rtllib_rx_ADDBAReq(ieee, skb);
2192 rtllib_rx_ADDBARsp(ieee, skb);
2195 rtllib_rx_DELBA(ieee, skb);
2205 inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2206 struct rtllib_rx_stats *rx_stats)
2211 struct rtllib_assoc_response_frame *assoc_resp;
2212 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2214 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2215 WLAN_FC_GET_STYPE(header->frame_ctl));
2217 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2218 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2219 (ieee->iw_mode == IW_MODE_INFRA)) {
2220 errcode = assoc_parse(ieee, skb, &aid);
2222 struct rtllib_network *network =
2223 kzalloc(sizeof(struct rtllib_network),
2228 memset(network, 0, sizeof(*network));
2229 ieee->state = RTLLIB_LINKED;
2230 ieee->assoc_id = aid;
2231 ieee->softmac_stats.rx_ass_ok++;
2232 /* station support qos */
2233 /* Let the register setting default with Legacy station */
2234 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2235 if (ieee->current_network.qos_data.supported == 1) {
2236 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2237 rx_stats->len - sizeof(*assoc_resp),
2238 network, rx_stats)) {
2242 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2243 network->bssht.bdHTCapBuf,
2244 network->bssht.bdHTCapLen);
2245 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2246 network->bssht.bdHTInfoBuf,
2247 network->bssht.bdHTInfoLen);
2249 if (ieee->handle_assoc_response != NULL)
2250 ieee->handle_assoc_response(ieee->dev,
2251 (struct rtllib_assoc_response_frame *)header,
2256 kfree(ieee->assocresp_ies);
2257 ieee->assocresp_ies = NULL;
2258 ies = &(assoc_resp->info_element[0].id);
2259 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2260 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2262 if (ieee->assocresp_ies)
2263 memcpy(ieee->assocresp_ies, ies,
2264 ieee->assocresp_ies_len);
2266 printk(KERN_INFO "%s()Warning: can't alloc "
2267 "memory for assocresp_ies\n", __func__);
2268 ieee->assocresp_ies_len = 0;
2270 rtllib_associate_complete(ieee);
2272 /* aid could not been allocated */
2273 ieee->softmac_stats.rx_ass_err++;
2274 printk(KERN_INFO "Association response status code 0x%x\n",
2277 "Association response status code 0x%x\n",
2279 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2280 queue_delayed_work_rsl(ieee->wq,
2281 &ieee->associate_procedure_wq, 0);
2283 rtllib_associate_abort(ieee);
2289 inline int rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2290 struct rtllib_rx_stats *rx_stats)
2295 bool bSupportNmode = true, bHalfSupportNmode = false;
2297 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2298 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2299 (ieee->iw_mode == IW_MODE_INFRA)) {
2300 RTLLIB_DEBUG_MGMT("Received authentication response");
2302 errcode = auth_parse(skb, &challenge, &chlen);
2304 if (ieee->open_wep || !challenge) {
2305 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2306 ieee->softmac_stats.rx_auth_rs_ok++;
2307 if (!(ieee->pHTInfo->IOTAction &
2308 HT_IOT_ACT_PURE_N_MODE)) {
2309 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2310 if (IsHTHalfNmodeAPs(ieee)) {
2311 bSupportNmode = true;
2312 bHalfSupportNmode = true;
2314 bSupportNmode = false;
2315 bHalfSupportNmode = false;
2319 /* Dummy wirless mode setting to avoid
2320 * encryption issue */
2321 if (bSupportNmode) {
2322 ieee->SetWirelessMode(ieee->dev,
2323 ieee->current_network.mode);
2326 ieee->SetWirelessMode(ieee->dev,
2330 if (ieee->current_network.mode ==
2332 bHalfSupportNmode == true) {
2333 printk(KERN_INFO "======>enter "
2335 ieee->bHalfWirelessN24GMode =
2338 ieee->bHalfWirelessN24GMode =
2341 rtllib_associate_step2(ieee);
2343 rtllib_auth_challenge(ieee, challenge,
2347 ieee->softmac_stats.rx_auth_rs_err++;
2348 RTLLIB_DEBUG_MGMT("Authentication respose"
2349 " status code 0x%x", errcode);
2351 printk(KERN_INFO "Authentication respose "
2352 "status code 0x%x", errcode);
2353 rtllib_associate_abort(ieee);
2356 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2357 rtllib_rx_auth_rq(ieee, skb);
2363 inline int rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2365 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2367 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2370 /* FIXME for now repeat all the association procedure
2371 * both for disassociation and deauthentication
2373 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2374 ieee->state == RTLLIB_LINKED &&
2375 (ieee->iw_mode == IW_MODE_INFRA)) {
2376 printk(KERN_INFO "==========>received disassoc/deauth(%x) "
2377 "frame, reason code:%x\n",
2378 WLAN_FC_GET_STYPE(header->frame_ctl),
2379 ((struct rtllib_disassoc *)skb->data)->reason);
2380 ieee->state = RTLLIB_ASSOCIATING;
2381 ieee->softmac_stats.reassoc++;
2382 ieee->is_roaming = true;
2383 ieee->LinkDetectInfo.bBusyTraffic = false;
2384 rtllib_disassociate(ieee);
2385 RemovePeerTS(ieee, header->addr2);
2386 if (ieee->LedControlHandler != NULL)
2387 ieee->LedControlHandler(ieee->dev,
2388 LED_CTL_START_TO_LINK);
2390 if (!(ieee->rtllib_ap_sec_type(ieee) &
2391 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2392 queue_delayed_work_rsl(ieee->wq,
2393 &ieee->associate_procedure_wq, 5);
2398 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2399 struct sk_buff *skb,
2400 struct rtllib_rx_stats *rx_stats, u16 type,
2403 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2405 if (!ieee->proto_started)
2408 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2409 case RTLLIB_STYPE_ASSOC_RESP:
2410 case RTLLIB_STYPE_REASSOC_RESP:
2411 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2414 case RTLLIB_STYPE_ASSOC_REQ:
2415 case RTLLIB_STYPE_REASSOC_REQ:
2416 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2417 ieee->iw_mode == IW_MODE_MASTER)
2418 rtllib_rx_assoc_rq(ieee, skb);
2420 case RTLLIB_STYPE_AUTH:
2421 rtllib_rx_auth(ieee, skb, rx_stats);
2423 case RTLLIB_STYPE_DISASSOC:
2424 case RTLLIB_STYPE_DEAUTH:
2425 rtllib_rx_deauth(ieee, skb);
2427 case RTLLIB_STYPE_MANAGE_ACT:
2428 rtllib_process_action(ieee, skb);
2437 /* following are for a simplier TX queue management.
2438 * Instead of using netif_[stop/wake]_queue the driver
2439 * will uses these two function (plus a reset one), that
2440 * will internally uses the kernel netif_* and takes
2441 * care of the ieee802.11 fragmentation.
2442 * So the driver receives a fragment per time and might
2443 * call the stop function when it want without take care
2444 * to have enought room to TX an entire packet.
2445 * This might be useful if each fragment need it's own
2446 * descriptor, thus just keep a total free memory > than
2447 * the max fragmentation treshold is not enought.. If the
2448 * ieee802.11 stack passed a TXB struct then you needed
2449 * to keep N free descriptors where
2450 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2451 * In this way you need just one and the 802.11 stack
2452 * will take care of buffering fragments and pass them to
2453 * to the driver later, when it wakes the queue.
2455 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2458 unsigned int queue_index = txb->queue_index;
2459 unsigned long flags;
2461 struct cb_desc *tcb_desc = NULL;
2462 unsigned long queue_len = 0;
2464 spin_lock_irqsave(&ieee->lock, flags);
2466 /* called with 2nd parm 0, no tx mgmt lock required */
2467 rtllib_sta_wakeup(ieee, 0);
2469 /* update the tx status */
2470 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2472 if (tcb_desc->bMulticast)
2473 ieee->stats.multicast++;
2475 /* if xmit available, just xmit it immediately, else just insert it to
2477 for (i = 0; i < txb->nr_frags; i++) {
2478 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2479 if ((queue_len != 0) ||\
2480 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2481 (ieee->queue_stop)) {
2482 /* insert the skb packet to the wait queue */
2483 /* as for the completion function, it does not need
2484 * to check it any more.
2486 if (queue_len < 200)
2487 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2490 kfree_skb(txb->fragments[i]);
2492 ieee->softmac_data_hard_start_xmit(
2494 ieee->dev, ieee->rate);
2498 rtllib_txb_free(txb);
2500 spin_unlock_irqrestore(&ieee->lock, flags);
2504 /* called with ieee->lock acquired */
2505 static void rtllib_resume_tx(struct rtllib_device *ieee)
2508 for (i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags;
2511 if (ieee->queue_stop) {
2512 ieee->tx_pending.frag = i;
2516 ieee->softmac_data_hard_start_xmit(
2517 ieee->tx_pending.txb->fragments[i],
2518 ieee->dev, ieee->rate);
2519 ieee->stats.tx_packets++;
2523 rtllib_txb_free(ieee->tx_pending.txb);
2524 ieee->tx_pending.txb = NULL;
2528 void rtllib_reset_queue(struct rtllib_device *ieee)
2530 unsigned long flags;
2532 spin_lock_irqsave(&ieee->lock, flags);
2533 init_mgmt_queue(ieee);
2534 if (ieee->tx_pending.txb) {
2535 rtllib_txb_free(ieee->tx_pending.txb);
2536 ieee->tx_pending.txb = NULL;
2538 ieee->queue_stop = 0;
2539 spin_unlock_irqrestore(&ieee->lock, flags);
2543 void rtllib_wake_queue(struct rtllib_device *ieee)
2546 unsigned long flags;
2547 struct sk_buff *skb;
2548 struct rtllib_hdr_3addr *header;
2550 spin_lock_irqsave(&ieee->lock, flags);
2551 if (!ieee->queue_stop)
2554 ieee->queue_stop = 0;
2556 if (ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) {
2557 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))) {
2559 header = (struct rtllib_hdr_3addr *) skb->data;
2561 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2563 if (ieee->seq_ctrl[0] == 0xFFF)
2564 ieee->seq_ctrl[0] = 0;
2566 ieee->seq_ctrl[0]++;
2568 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
2572 if (!ieee->queue_stop && ieee->tx_pending.txb)
2573 rtllib_resume_tx(ieee);
2575 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)) {
2576 ieee->softmac_stats.swtxawake++;
2577 netif_wake_queue(ieee->dev);
2581 spin_unlock_irqrestore(&ieee->lock, flags);
2585 void rtllib_stop_queue(struct rtllib_device *ieee)
2588 if (!netif_queue_stopped(ieee->dev)) {
2589 netif_stop_queue(ieee->dev);
2590 ieee->softmac_stats.swtxstop++;
2592 ieee->queue_stop = 1;
2596 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2599 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2600 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2602 netif_tx_stop_all_queues(ieee->dev);
2605 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2607 netif_tx_wake_all_queues(ieee->dev);
2610 inline void rtllib_randomize_cell(struct rtllib_device *ieee)
2613 get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2615 /* an IBSS cell address must have the two less significant
2616 * bits of the first byte = 2
2618 ieee->current_network.bssid[0] &= ~0x01;
2619 ieee->current_network.bssid[0] |= 0x02;
2622 /* called in user context only */
2623 void rtllib_start_master_bss(struct rtllib_device *ieee)
2627 if (ieee->current_network.ssid_len == 0) {
2628 strncpy(ieee->current_network.ssid,
2629 RTLLIB_DEFAULT_TX_ESSID,
2632 ieee->current_network.ssid_len =
2633 strlen(RTLLIB_DEFAULT_TX_ESSID);
2637 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2639 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2640 ieee->state = RTLLIB_LINKED;
2641 ieee->link_change(ieee->dev);
2642 notify_wx_assoc_event(ieee);
2644 if (ieee->data_hard_resume)
2645 ieee->data_hard_resume(ieee->dev);
2647 netif_carrier_on(ieee->dev);
2650 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2652 /* reset hardware status */
2654 if (ieee->data_hard_resume)
2655 ieee->data_hard_resume(ieee->dev);
2657 netif_carrier_on(ieee->dev);
2661 static void rtllib_start_ibss_wq(void *data)
2663 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2664 struct rtllib_device, start_ibss_wq);
2665 /* iwconfig mode ad-hoc will schedule this and return
2666 * on the other hand this will block further iwconfig SET
2667 * operations because of the wx_sem hold.
2668 * Anyway some most set operations set a flag to speed-up
2669 * (abort) this wq (when syncro scanning) before sleeping
2672 if (!ieee->proto_started) {
2673 printk(KERN_INFO "==========oh driver down return\n");
2676 down(&ieee->wx_sem);
2678 if (ieee->current_network.ssid_len == 0) {
2679 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2680 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2684 ieee->state = RTLLIB_NOLINK;
2685 ieee->mode = IEEE_G;
2686 /* check if we have this cell in our network list */
2687 rtllib_softmac_check_all_nets(ieee);
2690 /* if not then the state is not linked. Maybe the user swithced to
2691 * ad-hoc mode just after being in monitor mode, or just after
2692 * being very few time in managed mode (so the card have had no
2693 * time to scan all the chans..) or we have just run up the iface
2694 * after setting ad-hoc mode. So we have to give another try..
2695 * Here, in ibss mode, should be safe to do this without extra care
2696 * (in bss mode we had to make sure no-one tryed to associate when
2697 * we had just checked the ieee->state and we was going to start the
2698 * scan) beacause in ibss mode the rtllib_new_net function, when
2699 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2700 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2701 * scan, that will stop at the first round because it sees the state
2704 if (ieee->state == RTLLIB_NOLINK)
2705 rtllib_start_scan_syncro(ieee, 0);
2707 /* the network definitively is not here.. create a new cell */
2708 if (ieee->state == RTLLIB_NOLINK) {
2709 printk(KERN_INFO "creating new IBSS cell\n");
2710 ieee->current_network.channel = ieee->IbssStartChnl;
2712 rtllib_randomize_cell(ieee);
2714 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2716 ieee->current_network.rates_len = 4;
2718 ieee->current_network.rates[0] =
2719 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2720 ieee->current_network.rates[1] =
2721 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2722 ieee->current_network.rates[2] =
2723 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2724 ieee->current_network.rates[3] =
2725 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2728 ieee->current_network.rates_len = 0;
2730 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2731 ieee->current_network.rates_ex_len = 8;
2733 ieee->current_network.rates_ex[0] =
2734 RTLLIB_OFDM_RATE_6MB;
2735 ieee->current_network.rates_ex[1] =
2736 RTLLIB_OFDM_RATE_9MB;
2737 ieee->current_network.rates_ex[2] =
2738 RTLLIB_OFDM_RATE_12MB;
2739 ieee->current_network.rates_ex[3] =
2740 RTLLIB_OFDM_RATE_18MB;
2741 ieee->current_network.rates_ex[4] =
2742 RTLLIB_OFDM_RATE_24MB;
2743 ieee->current_network.rates_ex[5] =
2744 RTLLIB_OFDM_RATE_36MB;
2745 ieee->current_network.rates_ex[6] =
2746 RTLLIB_OFDM_RATE_48MB;
2747 ieee->current_network.rates_ex[7] =
2748 RTLLIB_OFDM_RATE_54MB;
2752 ieee->current_network.rates_ex_len = 0;
2756 ieee->current_network.qos_data.supported = 0;
2757 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2758 ieee->current_network.mode = ieee->mode;
2759 ieee->current_network.atim_window = 0;
2760 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2763 printk(KERN_INFO "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2764 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2765 HTUseDefaultSetting(ieee);
2767 ieee->pHTInfo->bCurrentHTSupport = false;
2769 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2770 (u8 *)(&ieee->state));
2772 ieee->state = RTLLIB_LINKED;
2773 ieee->link_change(ieee->dev);
2775 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2776 if (ieee->LedControlHandler != NULL)
2777 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2779 rtllib_start_send_beacons(ieee);
2781 notify_wx_assoc_event(ieee);
2783 if (ieee->data_hard_resume)
2784 ieee->data_hard_resume(ieee->dev);
2786 netif_carrier_on(ieee->dev);
2791 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2793 queue_delayed_work_rsl(ieee->wq, &ieee->start_ibss_wq, MSECS(150));
2796 /* this is called only in user context, with wx_sem held */
2797 void rtllib_start_bss(struct rtllib_device *ieee)
2799 unsigned long flags;
2800 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2801 if (!ieee->bGlobalDomain)
2804 /* check if we have already found the net we
2805 * are interested in (if any).
2806 * if not (we are disassociated and we are not
2807 * in associating / authenticating phase) start the background scanning.
2809 rtllib_softmac_check_all_nets(ieee);
2811 /* ensure no-one start an associating process (thus setting
2812 * the ieee->state to rtllib_ASSOCIATING) while we
2813 * have just cheked it and we are going to enable scan.
2814 * The rtllib_new_net function is always called with
2815 * lock held (from both rtllib_softmac_check_all_nets and
2816 * the rx path), so we cannot be in the middle of such function
2818 spin_lock_irqsave(&ieee->lock, flags);
2820 if (ieee->state == RTLLIB_NOLINK)
2821 rtllib_start_scan(ieee);
2822 spin_unlock_irqrestore(&ieee->lock, flags);
2825 static void rtllib_link_change_wq(void *data)
2827 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2828 struct rtllib_device, link_change_wq);
2829 ieee->link_change(ieee->dev);
2831 /* called only in userspace context */
2832 void rtllib_disassociate(struct rtllib_device *ieee)
2834 netif_carrier_off(ieee->dev);
2835 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2836 rtllib_reset_queue(ieee);
2838 if (ieee->data_hard_stop)
2839 ieee->data_hard_stop(ieee->dev);
2840 if (IS_DOT11D_ENABLE(ieee))
2842 ieee->state = RTLLIB_NOLINK;
2843 ieee->is_set_key = false;
2846 queue_delayed_work_rsl(ieee->wq, &ieee->link_change_wq, 0);
2848 notify_wx_assoc_event(ieee);
2851 static void rtllib_associate_retry_wq(void *data)
2853 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2854 struct rtllib_device, associate_retry_wq);
2855 unsigned long flags;
2857 down(&ieee->wx_sem);
2858 if (!ieee->proto_started)
2861 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2864 /* until we do not set the state to RTLLIB_NOLINK
2865 * there are no possibility to have someone else trying
2866 * to start an association procdure (we get here with
2867 * ieee->state = RTLLIB_ASSOCIATING).
2868 * When we set the state to RTLLIB_NOLINK it is possible
2869 * that the RX path run an attempt to associate, but
2870 * both rtllib_softmac_check_all_nets and the
2871 * RX path works with ieee->lock held so there are no
2872 * problems. If we are still disassociated then start a scan.
2873 * the lock here is necessary to ensure no one try to start
2874 * an association procedure when we have just checked the
2875 * state and we are going to start the scan.
2877 ieee->beinretry = true;
2878 ieee->state = RTLLIB_NOLINK;
2880 rtllib_softmac_check_all_nets(ieee);
2882 spin_lock_irqsave(&ieee->lock, flags);
2884 if (ieee->state == RTLLIB_NOLINK)
2885 rtllib_start_scan(ieee);
2886 spin_unlock_irqrestore(&ieee->lock, flags);
2888 ieee->beinretry = false;
2893 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2895 u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2897 struct sk_buff *skb;
2898 struct rtllib_probe_response *b;
2899 skb = rtllib_probe_resp(ieee, broadcast_addr);
2904 b = (struct rtllib_probe_response *) skb->data;
2905 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2911 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2913 struct sk_buff *skb;
2914 struct rtllib_probe_response *b;
2916 skb = rtllib_get_beacon_(ieee);
2920 b = (struct rtllib_probe_response *) skb->data;
2921 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2923 if (ieee->seq_ctrl[0] == 0xFFF)
2924 ieee->seq_ctrl[0] = 0;
2926 ieee->seq_ctrl[0]++;
2931 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2934 rtllib_stop_scan_syncro(ieee);
2935 down(&ieee->wx_sem);
2936 rtllib_stop_protocol(ieee, shutdown);
2941 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2943 if (!ieee->proto_started)
2947 ieee->proto_started = 0;
2948 ieee->proto_stoppping = 1;
2949 if (ieee->rtllib_ips_leave != NULL)
2950 ieee->rtllib_ips_leave(ieee->dev);
2953 rtllib_stop_send_beacons(ieee);
2954 del_timer_sync(&ieee->associate_timer);
2955 cancel_delayed_work(&ieee->associate_retry_wq);
2956 cancel_delayed_work(&ieee->start_ibss_wq);
2957 cancel_delayed_work(&ieee->link_change_wq);
2958 rtllib_stop_scan(ieee);
2960 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2961 ieee->state = RTLLIB_NOLINK;
2963 if (ieee->state == RTLLIB_LINKED) {
2964 if (ieee->iw_mode == IW_MODE_INFRA)
2965 SendDisassociation(ieee, 1, deauth_lv_ss);
2966 rtllib_disassociate(ieee);
2971 ieee->proto_stoppping = 0;
2973 kfree(ieee->assocreq_ies);
2974 ieee->assocreq_ies = NULL;
2975 ieee->assocreq_ies_len = 0;
2976 kfree(ieee->assocresp_ies);
2977 ieee->assocresp_ies = NULL;
2978 ieee->assocresp_ies_len = 0;
2981 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
2983 down(&ieee->wx_sem);
2984 rtllib_start_protocol(ieee);
2988 void rtllib_start_protocol(struct rtllib_device *ieee)
2993 rtllib_update_active_chan_map(ieee);
2995 if (ieee->proto_started)
2998 ieee->proto_started = 1;
3000 if (ieee->current_network.channel == 0) {
3003 if (ch > MAX_CHANNEL_NUMBER)
3004 return; /* no channel found */
3005 } while (!ieee->active_channel_map[ch]);
3006 ieee->current_network.channel = ch;
3009 if (ieee->current_network.beacon_interval == 0)
3010 ieee->current_network.beacon_interval = 100;
3012 for (i = 0; i < 17; i++) {
3013 ieee->last_rxseq_num[i] = -1;
3014 ieee->last_rxfrag_num[i] = -1;
3015 ieee->last_packet_time[i] = 0;
3018 if (ieee->UpdateBeaconInterruptHandler)
3019 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
3022 /* if the user set the MAC of the ad-hoc cell and then
3023 * switch to managed mode, shall we make sure that association
3024 * attempts does not fail just because the user provide the essid
3025 * and the nic is still checking for the AP MAC ??
3027 if (ieee->iw_mode == IW_MODE_INFRA) {
3028 rtllib_start_bss(ieee);
3029 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
3030 if (ieee->UpdateBeaconInterruptHandler)
3031 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
3033 rtllib_start_ibss(ieee);
3035 } else if (ieee->iw_mode == IW_MODE_MASTER) {
3036 rtllib_start_master_bss(ieee);
3037 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
3038 rtllib_start_monitor_mode(ieee);
3042 void rtllib_softmac_init(struct rtllib_device *ieee)
3045 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
3047 ieee->state = RTLLIB_NOLINK;
3048 for (i = 0; i < 5; i++)
3049 ieee->seq_ctrl[i] = 0;
3050 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
3051 if (!ieee->pDot11dInfo)
3052 RTLLIB_DEBUG(RTLLIB_DL_ERR, "can't alloc memory for DOT11D\n");
3053 ieee->LinkDetectInfo.SlotIndex = 0;
3054 ieee->LinkDetectInfo.SlotNum = 2;
3055 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3056 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
3057 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3058 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3059 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
3060 ieee->bIsAggregateFrame = false;
3062 ieee->queue_stop = 0;
3063 ieee->scanning_continue = 0;
3064 ieee->softmac_features = 0;
3067 ieee->proto_started = 0;
3068 ieee->proto_stoppping = 0;
3069 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
3071 ieee->ps = RTLLIB_PS_DISABLED;
3072 ieee->sta_sleep = LPS_IS_WAKE;
3074 ieee->Regdot11HTOperationalRateSet[0] = 0xff;
3075 ieee->Regdot11HTOperationalRateSet[1] = 0xff;
3076 ieee->Regdot11HTOperationalRateSet[4] = 0x01;
3078 ieee->Regdot11TxHTOperationalRateSet[0] = 0xff;
3079 ieee->Regdot11TxHTOperationalRateSet[1] = 0xff;
3080 ieee->Regdot11TxHTOperationalRateSet[4] = 0x01;
3082 ieee->FirstIe_InScan = false;
3083 ieee->actscanning = false;
3084 ieee->beinretry = false;
3085 ieee->is_set_key = false;
3086 init_mgmt_queue(ieee);
3088 ieee->sta_edca_param[0] = 0x0000A403;
3089 ieee->sta_edca_param[1] = 0x0000A427;
3090 ieee->sta_edca_param[2] = 0x005E4342;
3091 ieee->sta_edca_param[3] = 0x002F3262;
3092 ieee->aggregation = true;
3093 ieee->enable_rx_imm_BA = 1;
3094 ieee->tx_pending.txb = NULL;
3096 _setup_timer(&ieee->associate_timer,
3097 rtllib_associate_abort_cb,
3098 (unsigned long) ieee);
3100 _setup_timer(&ieee->beacon_timer,
3101 rtllib_send_beacon_cb,
3102 (unsigned long) ieee);
3105 ieee->wq = create_workqueue(DRV_NAME);
3107 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3108 (void *)rtllib_link_change_wq, ieee);
3109 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3110 (void *)rtllib_start_ibss_wq, ieee);
3111 INIT_WORK_RSL(&ieee->associate_complete_wq,
3112 (void *)rtllib_associate_complete_wq, ieee);
3113 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3114 (void *)rtllib_associate_procedure_wq, ieee);
3115 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3116 (void *)rtllib_softmac_scan_wq, ieee);
3117 INIT_DELAYED_WORK_RSL(&ieee->softmac_hint11d_wq,
3118 (void *)rtllib_softmac_hint11d_wq, ieee);
3119 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3120 (void *)rtllib_associate_retry_wq, ieee);
3121 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3124 sema_init(&ieee->wx_sem, 1);
3125 sema_init(&ieee->scan_sem, 1);
3126 sema_init(&ieee->ips_sem, 1);
3128 spin_lock_init(&ieee->mgmt_tx_lock);
3129 spin_lock_init(&ieee->beacon_lock);
3131 tasklet_init(&ieee->ps_task,
3132 (void(*)(unsigned long)) rtllib_sta_ps,
3133 (unsigned long)ieee);
3137 void rtllib_softmac_free(struct rtllib_device *ieee)
3139 down(&ieee->wx_sem);
3140 kfree(ieee->pDot11dInfo);
3141 ieee->pDot11dInfo = NULL;
3142 del_timer_sync(&ieee->associate_timer);
3144 cancel_delayed_work(&ieee->associate_retry_wq);
3145 destroy_workqueue(ieee->wq);
3149 /********************************************************
3150 * Start of WPA code. *
3151 * this is stolen from the ipw2200 driver *
3152 ********************************************************/
3155 static int rtllib_wpa_enable(struct rtllib_device *ieee, int value)
3157 /* This is called when wpa_supplicant loads and closes the driver
3159 printk(KERN_INFO "%s WPA\n", value ? "enabling" : "disabling");
3160 ieee->wpa_enabled = value;
3161 memset(ieee->ap_mac_addr, 0, 6);
3166 static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie,
3169 /* make sure WPA is enabled */
3170 rtllib_wpa_enable(ieee, 1);
3172 rtllib_disassociate(ieee);
3176 static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason)
3182 case IEEE_MLME_STA_DEAUTH:
3185 case IEEE_MLME_STA_DISASSOC:
3186 rtllib_disassociate(ieee);
3190 printk(KERN_INFO "Unknown MLME request: %d\n", command);
3198 static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee,
3199 struct ieee_param *param, int plen)
3203 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3204 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3207 if (param->u.wpa_ie.len) {
3208 buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
3213 kfree(ieee->wpa_ie);
3215 ieee->wpa_ie_len = param->u.wpa_ie.len;
3217 kfree(ieee->wpa_ie);
3218 ieee->wpa_ie = NULL;
3219 ieee->wpa_ie_len = 0;
3222 rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3226 #define AUTH_ALG_OPEN_SYSTEM 0x1
3227 #define AUTH_ALG_SHARED_KEY 0x2
3228 #define AUTH_ALG_LEAP 0x4
3229 static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value)
3232 struct rtllib_security sec = {
3233 .flags = SEC_AUTH_MODE,
3237 if (value & AUTH_ALG_SHARED_KEY) {
3238 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3240 ieee->auth_mode = 1;
3241 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
3242 sec.auth_mode = WLAN_AUTH_OPEN;
3244 ieee->auth_mode = 0;
3245 } else if (value & AUTH_ALG_LEAP) {
3246 sec.auth_mode = WLAN_AUTH_LEAP >> 6;
3248 ieee->auth_mode = 2;
3252 if (ieee->set_security)
3253 ieee->set_security(ieee->dev, &sec);
3258 static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value)
3261 unsigned long flags;
3264 case IEEE_PARAM_WPA_ENABLED:
3265 ret = rtllib_wpa_enable(ieee, value);
3268 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3269 ieee->tkip_countermeasures = value;
3272 case IEEE_PARAM_DROP_UNENCRYPTED:
3276 * wpa_supplicant calls set_wpa_enabled when the driver
3277 * is loaded and unloaded, regardless of if WPA is being
3278 * used. No other calls are made which can be used to
3279 * determine if encryption will be used or not prior to
3280 * association being expected. If encryption is not being
3281 * used, drop_unencrypted is set to false, else true -- we
3282 * can use this to determine if the CAP_PRIVACY_ON bit should
3285 struct rtllib_security sec = {
3286 .flags = SEC_ENABLED,
3289 ieee->drop_unencrypted = value;
3290 /* We only change SEC_LEVEL for open mode. Others
3291 * are set by ipw_wpa_set_encryption.
3294 sec.flags |= SEC_LEVEL;
3295 sec.level = SEC_LEVEL_0;
3297 sec.flags |= SEC_LEVEL;
3298 sec.level = SEC_LEVEL_1;
3300 if (ieee->set_security)
3301 ieee->set_security(ieee->dev, &sec);
3305 case IEEE_PARAM_PRIVACY_INVOKED:
3306 ieee->privacy_invoked = value;
3309 case IEEE_PARAM_AUTH_ALGS:
3310 ret = rtllib_wpa_set_auth_algs(ieee, value);
3313 case IEEE_PARAM_IEEE_802_1X:
3314 ieee->ieee802_1x = value;
3316 case IEEE_PARAM_WPAX_SELECT:
3317 spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags);
3318 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags);
3322 printk(KERN_INFO "Unknown WPA param: %d\n", name);
3329 /* implementation borrowed from hostap driver */
3330 static int rtllib_wpa_set_encryption(struct rtllib_device *ieee,
3331 struct ieee_param *param, int param_len,
3335 struct rtllib_crypto_ops *ops;
3336 struct rtllib_crypt_data **crypt;
3338 struct rtllib_security sec = {
3342 param->u.crypt.err = 0;
3343 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3346 (int) ((char *) param->u.crypt.key - (char *) param) +
3347 param->u.crypt.key_len) {
3348 printk(KERN_INFO "Len mismatch %d, %d\n", param_len,
3349 param->u.crypt.key_len);
3352 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3353 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3354 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3355 if (param->u.crypt.idx >= WEP_KEYS)
3357 crypt = &ieee->crypt[param->u.crypt.idx];
3362 if (strcmp(param->u.crypt.alg, "none") == 0) {
3365 sec.level = SEC_LEVEL_0;
3366 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3367 rtllib_crypt_delayed_deinit(ieee, crypt);
3372 sec.flags |= SEC_ENABLED;
3374 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3375 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3376 strcmp(param->u.crypt.alg, "TKIP"))
3377 goto skip_host_crypt;
3379 ops = rtllib_get_crypto_ops(param->u.crypt.alg);
3380 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3381 request_module("rtllib_crypt_wep");
3382 ops = rtllib_get_crypto_ops(param->u.crypt.alg);
3383 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3384 request_module("rtllib_crypt_tkip");
3385 ops = rtllib_get_crypto_ops(param->u.crypt.alg);
3386 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3387 request_module("rtllib_crypt_ccmp");
3388 ops = rtllib_get_crypto_ops(param->u.crypt.alg);
3391 printk(KERN_INFO "unknown crypto alg '%s'\n",
3392 param->u.crypt.alg);
3393 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3397 if (*crypt == NULL || (*crypt)->ops != ops) {
3398 struct rtllib_crypt_data *new_crypt;
3400 rtllib_crypt_delayed_deinit(ieee, crypt);
3402 new_crypt = (struct rtllib_crypt_data *)
3403 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
3404 if (new_crypt == NULL) {
3408 memset(new_crypt, 0, sizeof(struct rtllib_crypt_data));
3409 new_crypt->ops = ops;
3412 new_crypt->ops->init(param->u.crypt.idx);
3414 if (new_crypt->priv == NULL) {
3416 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3424 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3425 (*crypt)->ops->set_key(param->u.crypt.key,
3426 param->u.crypt.key_len, param->u.crypt.seq,
3427 (*crypt)->priv) < 0) {
3428 printk(KERN_INFO "key setting failed\n");
3429 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3435 if (param->u.crypt.set_tx) {
3436 ieee->tx_keyidx = param->u.crypt.idx;
3437 sec.active_key = param->u.crypt.idx;
3438 sec.flags |= SEC_ACTIVE_KEY;
3440 sec.flags &= ~SEC_ACTIVE_KEY;
3442 if (param->u.crypt.alg != NULL) {
3443 memcpy(sec.keys[param->u.crypt.idx],
3445 param->u.crypt.key_len);
3446 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3447 sec.flags |= (1 << param->u.crypt.idx);
3449 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
3450 sec.flags |= SEC_LEVEL;
3451 sec.level = SEC_LEVEL_1;
3452 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
3453 sec.flags |= SEC_LEVEL;
3454 sec.level = SEC_LEVEL_2;
3455 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
3456 sec.flags |= SEC_LEVEL;
3457 sec.level = SEC_LEVEL_3;
3461 if (ieee->set_security)
3462 ieee->set_security(ieee->dev, &sec);
3464 /* Do not reset port if card is in Managed mode since resetting will
3465 * generate new IEEE 802.11 authentication which may end up in looping
3466 * with IEEE 802.1X. If your hardware requires a reset after WEP
3467 * configuration (for example... Prism2), implement the reset_port in
3468 * the callbacks structures used to initialize the 802.11 stack. */
3469 if (ieee->reset_on_keychange &&
3470 ieee->iw_mode != IW_MODE_INFRA &&
3472 ieee->reset_port(ieee->dev)) {
3473 printk(KERN_INFO "reset_port failed\n");
3474 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3481 inline struct sk_buff *rtllib_disauth_skb(struct rtllib_network *beacon,
3482 struct rtllib_device *ieee, u16 asRsn)
3484 struct sk_buff *skb;
3485 struct rtllib_disauth *disauth;
3486 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3488 skb = dev_alloc_skb(len);
3492 skb_reserve(skb, ieee->tx_headroom);
3494 disauth = (struct rtllib_disauth *) skb_put(skb,
3495 sizeof(struct rtllib_disauth));
3496 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3497 disauth->header.duration_id = 0;
3499 memcpy(disauth->header.addr1, beacon->bssid, ETH_ALEN);
3500 memcpy(disauth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3501 memcpy(disauth->header.addr3, beacon->bssid, ETH_ALEN);
3503 disauth->reason = cpu_to_le16(asRsn);
3507 inline struct sk_buff *rtllib_disassociate_skb(struct rtllib_network *beacon,
3508 struct rtllib_device *ieee, u16 asRsn)
3510 struct sk_buff *skb;
3511 struct rtllib_disassoc *disass;
3512 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3513 skb = dev_alloc_skb(len);
3518 skb_reserve(skb, ieee->tx_headroom);
3520 disass = (struct rtllib_disassoc *) skb_put(skb,
3521 sizeof(struct rtllib_disassoc));
3522 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3523 disass->header.duration_id = 0;
3525 memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
3526 memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3527 memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
3529 disass->reason = cpu_to_le16(asRsn);
3533 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3535 struct rtllib_network *beacon = &ieee->current_network;
3536 struct sk_buff *skb;
3539 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3541 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3544 softmac_mgmt_xmit(skb, ieee);
3547 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3549 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3550 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3551 int wpa_ie_len = ieee->wpa_ie_len;
3552 struct rtllib_crypt_data *crypt;
3555 crypt = ieee->crypt[ieee->tx_keyidx];
3556 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3557 || (ieee->host_encrypt && crypt && crypt->ops &&
3558 (0 == strcmp(crypt->ops->name, "WEP")));
3561 if (encrypt && (wpa_ie_len == 0)) {
3563 } else if ((wpa_ie_len != 0)) {
3564 if (((ieee->wpa_ie[0] == 0xdd) &&
3565 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3566 ((ieee->wpa_ie[0] == 0x30) &&
3567 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3568 return SEC_ALG_CCMP;
3570 return SEC_ALG_TKIP;
3572 return SEC_ALG_NONE;
3576 int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p,
3579 struct ieee_param *param;
3582 down(&ieee->wx_sem);
3584 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3589 param = kmalloc(p->length, GFP_KERNEL);
3590 if (param == NULL) {
3594 if (copy_from_user(param, p->pointer, p->length)) {
3600 switch (param->cmd) {
3601 case IEEE_CMD_SET_WPA_PARAM:
3602 ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name,
3603 param->u.wpa_param.value);
3606 case IEEE_CMD_SET_WPA_IE:
3607 ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length);
3610 case IEEE_CMD_SET_ENCRYPTION:
3611 ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0);
3615 ret = rtllib_wpa_mlme(ieee, param->u.mlme.command,
3616 param->u.mlme.reason_code);
3620 printk(KERN_INFO "Unknown WPA supplicant request: %d\n",
3626 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3636 void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3640 bool bFilterOutNonAssociatedBSSID = false;
3642 rtllib->state = RTLLIB_NOLINK;
3644 for (i = 0; i < 6; i++)
3645 rtllib->current_network.bssid[i] = 0x55;
3647 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3648 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3649 rtllib->current_network.bssid);
3650 OpMode = RT_OP_MODE_NO_LINK;
3651 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3652 rtllib_stop_send_beacons(rtllib);
3654 bFilterOutNonAssociatedBSSID = false;
3655 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3656 (u8 *)(&bFilterOutNonAssociatedBSSID));
3657 notify_wx_assoc_event(rtllib);
3661 void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, u8 *asSta,
3667 RemovePeerTS(rtllib, asSta);
3670 if (memcpy(rtllib->current_network.bssid, asSta, 6) == NULL) {
3671 rtllib->state = RTLLIB_NOLINK;
3673 for (i = 0; i < 6; i++)
3674 rtllib->current_network.bssid[i] = 0x22;
3675 OpMode = RT_OP_MODE_NO_LINK;
3676 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3677 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3679 rtllib_disassociate(rtllib);
3681 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3682 rtllib->current_network.bssid);
3689 rtllib_MgntDisconnectAP(
3690 struct rtllib_device *rtllib,
3694 bool bFilterOutNonAssociatedBSSID = false;
3696 bFilterOutNonAssociatedBSSID = false;
3697 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3698 (u8 *)(&bFilterOutNonAssociatedBSSID));
3699 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3702 rtllib->state = RTLLIB_NOLINK;
3705 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3707 if (rtllib->ps != RTLLIB_PS_DISABLED)
3708 rtllib->sta_wake_up(rtllib->dev);
3710 if (rtllib->state == RTLLIB_LINKED) {
3711 if (rtllib->iw_mode == IW_MODE_ADHOC)
3712 rtllib_MgntDisconnectIBSS(rtllib);
3713 if (rtllib->iw_mode == IW_MODE_INFRA)
3714 rtllib_MgntDisconnectAP(rtllib, asRsn);
3721 void notify_wx_assoc_event(struct rtllib_device *ieee)
3723 union iwreq_data wrqu;
3725 if (ieee->cannot_notify)
3728 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3729 if (ieee->state == RTLLIB_LINKED)
3730 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3734 printk(KERN_INFO "%s(): Tell user space disconnected\n",
3736 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
3738 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);