1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
4 * Mostly extracted from the rtl8180-sa2400 driver for the
5 * in-kernel generic ieee802.11 stack.
7 * Few lines might be stolen from other part of the rtllib
8 * stack. Copyright who own it's copyright
10 * WPA code stolen from the ipw2200 driver.
11 * Copyright who own it's copyright.
13 * released under the GPL
19 #include <linux/random.h>
20 #include <linux/delay.h>
21 #include <linux/uaccess.h>
22 #include <linux/etherdevice.h>
23 #include <linux/ieee80211.h>
26 short rtllib_is_54g(struct rtllib_network *net)
28 return (net->rates_ex_len > 0) || (net->rates_len > 4);
31 short rtllib_is_shortslot(const struct rtllib_network *net)
33 return net->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME;
36 /* returns the total length needed for placing the RATE MFIE
37 * tag and the EXTENDED RATE MFIE tag if needed.
38 * It encludes two bytes per tag for the tag itself and its len
40 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
42 unsigned int rate_len = 0;
44 if (ieee->modulation & RTLLIB_CCK_MODULATION)
45 rate_len = RTLLIB_CCK_RATE_LEN + 2;
47 if (ieee->modulation & RTLLIB_OFDM_MODULATION)
49 rate_len += RTLLIB_OFDM_RATE_LEN + 2;
54 /* place the MFIE rate, tag to the memory (double) pointed.
55 * Then it updates the pointer so that
56 * it points after the new MFIE tag added.
58 static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p)
62 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
63 *tag++ = MFIE_TYPE_RATES;
65 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
66 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
67 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
68 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
71 /* We may add an option for custom rates that specific HW
77 static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p)
81 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
82 *tag++ = MFIE_TYPE_RATES_EX;
84 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
85 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
86 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
87 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
88 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
89 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
90 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
91 *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;
93 /* We may add an option for custom rates that specific HW might
99 static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
103 *tag++ = MFIE_TYPE_GENERIC;
115 void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
119 *tag++ = MFIE_TYPE_GENERIC;
130 netdev_alert(ieee->dev, "This is enable turbo mode IE process\n");
133 static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb)
137 nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM;
139 /* if the queue is full but we have newer frames then
140 * just overwrites the oldest.
142 * if (nh == ieee->mgmt_queue_tail)
145 ieee->mgmt_queue_head = nh;
146 ieee->mgmt_queue_ring[nh] = skb;
150 static struct sk_buff *dequeue_mgmt(struct rtllib_device *ieee)
154 if (ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
157 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
159 ieee->mgmt_queue_tail =
160 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
165 static void init_mgmt_queue(struct rtllib_device *ieee)
167 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
172 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
179 for (i = 0; i < ieee->current_network.rates_len; i++) {
180 BasicRate = ieee->current_network.rates[i]&0x7F;
181 if (!rtllib_is_cck_rate(BasicRate)) {
182 if (QueryRate == 0) {
183 QueryRate = BasicRate;
185 if (BasicRate < QueryRate)
186 QueryRate = BasicRate;
191 if (QueryRate == 0) {
193 netdev_info(ieee->dev, "No BasicRate found!!\n");
198 static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
200 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
203 if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M)
206 rate = ieee->basic_rate & 0x7f;
209 if (ieee->mode == IEEE_A ||
210 ieee->mode == IEEE_N_5G ||
211 (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK))
220 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee)
223 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
224 struct rtllib_hdr_3addr *header =
225 (struct rtllib_hdr_3addr *) skb->data;
227 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
229 spin_lock_irqsave(&ieee->lock, flags);
231 /* called with 2nd param 0, no mgmt lock required */
232 rtllib_sta_wakeup(ieee, 0);
234 if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON)
235 tcb_desc->queue_index = BEACON_QUEUE;
237 tcb_desc->queue_index = MGNT_QUEUE;
239 if (ieee->disable_mgnt_queue)
240 tcb_desc->queue_index = HIGH_QUEUE;
242 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
243 tcb_desc->RATRIndex = 7;
244 tcb_desc->bTxDisableRateFallBack = 1;
245 tcb_desc->bTxUseDriverAssingedRate = 1;
247 if (ieee->queue_stop) {
248 enqueue_mgmt(ieee, skb);
250 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
252 if (ieee->seq_ctrl[0] == 0xFFF)
253 ieee->seq_ctrl[0] = 0;
257 /* avoid watchdog triggers */
258 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
262 spin_unlock_irqrestore(&ieee->lock, flags);
264 spin_unlock_irqrestore(&ieee->lock, flags);
265 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
267 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
269 if (ieee->seq_ctrl[0] == 0xFFF)
270 ieee->seq_ctrl[0] = 0;
274 /* check whether the managed packet queued greater than 5 */
275 if (!ieee->check_nic_enough_desc(ieee->dev, tcb_desc->queue_index) ||
276 (skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) != 0) ||
277 (ieee->queue_stop)) {
278 /* insert the skb packet to the management queue
280 * as for the completion function, it does not need
281 * to check it any more.
283 netdev_info(ieee->dev,
284 "%s():insert to waitqueue, queue_index:%d!\n",
285 __func__, tcb_desc->queue_index);
286 skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index],
289 ieee->softmac_hard_start_xmit(skb, ieee->dev);
291 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
295 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb,
296 struct rtllib_device *ieee)
298 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
299 struct rtllib_hdr_3addr *header =
300 (struct rtllib_hdr_3addr *) skb->data;
302 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
304 fc = le16_to_cpu(header->frame_ctl);
305 type = WLAN_FC_GET_TYPE(fc);
306 stype = WLAN_FC_GET_STYPE(fc);
309 if (stype != RTLLIB_STYPE_PSPOLL)
310 tcb_desc->queue_index = MGNT_QUEUE;
312 tcb_desc->queue_index = HIGH_QUEUE;
314 if (ieee->disable_mgnt_queue)
315 tcb_desc->queue_index = HIGH_QUEUE;
318 tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee);
319 tcb_desc->RATRIndex = 7;
320 tcb_desc->bTxDisableRateFallBack = 1;
321 tcb_desc->bTxUseDriverAssingedRate = 1;
323 if (type != RTLLIB_FTYPE_CTL) {
324 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
326 if (ieee->seq_ctrl[0] == 0xFFF)
327 ieee->seq_ctrl[0] = 0;
332 /* avoid watchdog triggers */
333 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
337 if (type != RTLLIB_FTYPE_CTL) {
338 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
340 if (ieee->seq_ctrl[0] == 0xFFF)
341 ieee->seq_ctrl[0] = 0;
345 ieee->softmac_hard_start_xmit(skb, ieee->dev);
350 static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
352 unsigned int len, rate_len;
355 struct rtllib_probe_request *req;
357 len = ieee->current_network.ssid_len;
359 rate_len = rtllib_MFIE_rate_len(ieee);
361 skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) +
362 2 + len + rate_len + ieee->tx_headroom);
367 skb_reserve(skb, ieee->tx_headroom);
369 req = (struct rtllib_probe_request *) skb_put(skb,
370 sizeof(struct rtllib_probe_request));
371 req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ);
372 req->header.duration_id = 0;
374 memset(req->header.addr1, 0xff, ETH_ALEN);
375 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
376 memset(req->header.addr3, 0xff, ETH_ALEN);
378 tag = (u8 *) skb_put(skb, len + 2 + rate_len);
380 *tag++ = MFIE_TYPE_SSID;
382 memcpy(tag, ieee->current_network.ssid, len);
385 rtllib_MFIE_Brate(ieee, &tag);
386 rtllib_MFIE_Grate(ieee, &tag);
391 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
393 static void rtllib_send_beacon(struct rtllib_device *ieee)
399 skb = rtllib_get_beacon_(ieee);
402 softmac_mgmt_xmit(skb, ieee);
403 ieee->softmac_stats.tx_beacons++;
406 if (ieee->beacon_txing && ieee->ieee_up)
407 mod_timer(&ieee->beacon_timer, jiffies +
408 (msecs_to_jiffies(ieee->current_network.beacon_interval - 5)));
412 static void rtllib_send_beacon_cb(unsigned long _ieee)
414 struct rtllib_device *ieee =
415 (struct rtllib_device *) _ieee;
418 spin_lock_irqsave(&ieee->beacon_lock, flags);
419 rtllib_send_beacon(ieee);
420 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
423 /* Enables network monitor mode, all rx packets will be received. */
424 void rtllib_EnableNetMonitorMode(struct net_device *dev,
427 struct rtllib_device *ieee = netdev_priv_rsl(dev);
429 netdev_info(dev, "========>Enter Monitor Mode\n");
431 ieee->AllowAllDestAddrHandler(dev, true, !bInitState);
435 /* Disables network monitor mode. Only packets destinated to
436 * us will be received.
438 void rtllib_DisableNetMonitorMode(struct net_device *dev,
441 struct rtllib_device *ieee = netdev_priv_rsl(dev);
443 netdev_info(dev, "========>Exit Monitor Mode\n");
445 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
449 /* 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 netdev_info(dev, "========>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;
470 EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode);
473 /* Disables the specialized promiscuous mode required by Intel.
474 * See MgntEnableIntelPromiscuousMode for detail.
476 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
479 bool bFilterOutNonAssociatedBSSID = true;
481 struct rtllib_device *ieee = netdev_priv_rsl(dev);
483 netdev_info(dev, "========>Exit Intel Promiscuous Mode\n");
485 ieee->AllowAllDestAddrHandler(dev, false, !bInitState);
486 ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID,
487 (u8 *)&bFilterOutNonAssociatedBSSID);
489 ieee->bNetPromiscuousMode = false;
491 EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode);
493 static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
497 skb = rtllib_probe_req(ieee);
499 softmac_mgmt_xmit(skb, ieee);
500 ieee->softmac_stats.tx_probe_rq++;
505 void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
507 if (ieee->active_scan && (ieee->softmac_features &
508 IEEE_SOFTMAC_PROBERQ)) {
509 rtllib_send_probe(ieee, 0);
510 rtllib_send_probe(ieee, 0);
514 static void rtllib_softmac_hint11d_wq(void *data)
518 void rtllib_update_active_chan_map(struct rtllib_device *ieee)
520 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
521 MAX_CHANNEL_NUMBER+1);
524 /* this performs syncro scan blocking the caller until all channels
525 * in the allowed channel map has been checked.
527 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
529 union iwreq_data wrqu;
532 rtllib_update_active_chan_map(ieee);
534 ieee->be_scan_inprogress = true;
536 down(&ieee->scan_sem);
541 if (ch > MAX_CHANNEL_NUMBER)
542 goto out; /* scan completed */
543 } while (!ieee->active_channel_map[ch]);
545 /* this function can be called in two situations
546 * 1- We have switched to ad-hoc mode and we are
547 * performing a complete syncro scan before conclude
548 * there are no interesting cell and to create a
549 * new one. In this case the link state is
550 * RTLLIB_NOLINK until we found an interesting cell.
551 * If so the ieee8021_new_net, called by the RX path
552 * will set the state to RTLLIB_LINKED, so we stop
554 * 2- We are linked and the root uses run iwlist scan.
555 * So we switch to RTLLIB_LINKED_SCANNING to remember
556 * that we are still logically linked (not interested in
557 * new network events, despite for updating the net list,
558 * but we are temporarly 'unlinked' as the driver shall
559 * not filter RX frames and the channel is changing.
560 * So the only situation in which are interested is to check
561 * if the state become LINKED because of the #1 situation
564 if (ieee->state == RTLLIB_LINKED)
566 if (ieee->sync_scan_hurryup) {
567 netdev_info(ieee->dev,
568 "============>sync_scan_hurryup out\n");
572 ieee->set_chan(ieee->dev, ch);
573 if (ieee->active_channel_map[ch] == 1)
574 rtllib_send_probe_requests(ieee, 0);
576 /* this prevent excessive time wait when we
577 * need to wait for a syncro scan to end..
579 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME);
582 ieee->actscanning = false;
583 ieee->sync_scan_hurryup = 0;
585 if (ieee->state >= RTLLIB_LINKED) {
586 if (IS_DOT11D_ENABLE(ieee))
587 DOT11D_ScanComplete(ieee);
591 ieee->be_scan_inprogress = false;
593 memset(&wrqu, 0, sizeof(wrqu));
594 wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL);
597 static void rtllib_softmac_scan_wq(void *data)
599 struct rtllib_device *ieee = container_of_dwork_rsl(data,
600 struct rtllib_device, softmac_scan_wq);
601 u8 last_channel = ieee->current_network.channel;
603 rtllib_update_active_chan_map(ieee);
607 if (rtllib_act_scanning(ieee, true))
610 down(&ieee->scan_sem);
612 if (ieee->eRFPowerState == eRfOff) {
613 netdev_info(ieee->dev,
614 "======>%s():rf state is eRfOff, return\n",
620 ieee->current_network.channel =
621 (ieee->current_network.channel + 1) %
623 if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) {
624 if (!ieee->active_channel_map[ieee->current_network.channel])
625 ieee->current_network.channel = 6;
626 goto out; /* no good chans */
628 } while (!ieee->active_channel_map[ieee->current_network.channel]);
630 if (ieee->scanning_continue == 0)
633 ieee->set_chan(ieee->dev, ieee->current_network.channel);
635 if (ieee->active_channel_map[ieee->current_network.channel] == 1)
636 rtllib_send_probe_requests(ieee, 0);
638 queue_delayed_work_rsl(ieee->wq, &ieee->softmac_scan_wq,
639 msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
645 if (IS_DOT11D_ENABLE(ieee))
646 DOT11D_ScanComplete(ieee);
647 ieee->current_network.channel = last_channel;
650 ieee->actscanning = false;
651 ieee->scan_watch_dog = 0;
652 ieee->scanning_continue = 0;
658 static void rtllib_beacons_start(struct rtllib_device *ieee)
662 spin_lock_irqsave(&ieee->beacon_lock, flags);
664 ieee->beacon_txing = 1;
665 rtllib_send_beacon(ieee);
667 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
670 static void rtllib_beacons_stop(struct rtllib_device *ieee)
674 spin_lock_irqsave(&ieee->beacon_lock, flags);
676 ieee->beacon_txing = 0;
677 del_timer_sync(&ieee->beacon_timer);
679 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
684 void rtllib_stop_send_beacons(struct rtllib_device *ieee)
686 if (ieee->stop_send_beacons)
687 ieee->stop_send_beacons(ieee->dev);
688 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
689 rtllib_beacons_stop(ieee);
691 EXPORT_SYMBOL(rtllib_stop_send_beacons);
694 void rtllib_start_send_beacons(struct rtllib_device *ieee)
696 if (ieee->start_send_beacons)
697 ieee->start_send_beacons(ieee->dev);
698 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
699 rtllib_beacons_start(ieee);
701 EXPORT_SYMBOL(rtllib_start_send_beacons);
704 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
706 down(&ieee->scan_sem);
707 ieee->scan_watch_dog = 0;
708 if (ieee->scanning_continue == 1) {
709 ieee->scanning_continue = 0;
710 ieee->actscanning = false;
712 cancel_delayed_work(&ieee->softmac_scan_wq);
718 void rtllib_stop_scan(struct rtllib_device *ieee)
720 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
721 rtllib_softmac_stop_scan(ieee);
723 if (ieee->rtllib_stop_hw_scan)
724 ieee->rtllib_stop_hw_scan(ieee->dev);
727 EXPORT_SYMBOL(rtllib_stop_scan);
729 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
731 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
732 ieee->sync_scan_hurryup = 1;
734 if (ieee->rtllib_stop_hw_scan)
735 ieee->rtllib_stop_hw_scan(ieee->dev);
738 EXPORT_SYMBOL(rtllib_stop_scan_syncro);
740 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan)
742 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
744 return ieee->be_scan_inprogress;
746 return ieee->actscanning || ieee->be_scan_inprogress;
748 return test_bit(STATUS_SCANNING, &ieee->status);
751 EXPORT_SYMBOL(rtllib_act_scanning);
753 /* called with ieee->lock held */
754 static void rtllib_start_scan(struct rtllib_device *ieee)
756 RT_TRACE(COMP_DBG, "===>%s()\n", __func__);
757 if (ieee->rtllib_ips_leave_wq != NULL)
758 ieee->rtllib_ips_leave_wq(ieee->dev);
760 if (IS_DOT11D_ENABLE(ieee)) {
761 if (IS_COUNTRY_IE_VALID(ieee))
762 RESET_CIE_WATCHDOG(ieee);
764 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
765 if (ieee->scanning_continue == 0) {
766 ieee->actscanning = true;
767 ieee->scanning_continue = 1;
768 queue_delayed_work_rsl(ieee->wq,
769 &ieee->softmac_scan_wq, 0);
772 if (ieee->rtllib_start_hw_scan)
773 ieee->rtllib_start_hw_scan(ieee->dev);
777 /* called with wx_sem held */
778 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
780 if (IS_DOT11D_ENABLE(ieee)) {
781 if (IS_COUNTRY_IE_VALID(ieee))
782 RESET_CIE_WATCHDOG(ieee);
784 ieee->sync_scan_hurryup = 0;
785 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
786 rtllib_softmac_scan_syncro(ieee, is_mesh);
788 if (ieee->rtllib_start_hw_scan)
789 ieee->rtllib_start_hw_scan(ieee->dev);
792 EXPORT_SYMBOL(rtllib_start_scan_syncro);
794 inline struct sk_buff *rtllib_authentication_req(struct rtllib_network *beacon,
795 struct rtllib_device *ieee, int challengelen, u8 *daddr)
798 struct rtllib_authentication *auth;
801 len = sizeof(struct rtllib_authentication) + challengelen +
802 ieee->tx_headroom + 4;
803 skb = dev_alloc_skb(len);
808 skb_reserve(skb, ieee->tx_headroom);
810 auth = (struct rtllib_authentication *)
811 skb_put(skb, sizeof(struct rtllib_authentication));
813 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
815 auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP);
817 auth->header.duration_id = cpu_to_le16(0x013a);
818 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
819 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
820 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
821 if (ieee->auth_mode == 0)
822 auth->algorithm = WLAN_AUTH_OPEN;
823 else if (ieee->auth_mode == 1)
824 auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY);
825 else if (ieee->auth_mode == 2)
826 auth->algorithm = WLAN_AUTH_OPEN;
827 auth->transaction = cpu_to_le16(ieee->associate_seq);
828 ieee->associate_seq++;
830 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
835 static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, u8 *dest)
839 struct rtllib_probe_response *beacon_buf;
840 struct sk_buff *skb = NULL;
842 int atim_len, erp_len;
843 struct lib80211_crypt_data *crypt;
845 char *ssid = ieee->current_network.ssid;
846 int ssid_len = ieee->current_network.ssid_len;
847 int rate_len = ieee->current_network.rates_len+2;
848 int rate_ex_len = ieee->current_network.rates_ex_len;
849 int wpa_ie_len = ieee->wpa_ie_len;
850 u8 erpinfo_content = 0;
852 u8 *tmp_ht_cap_buf = NULL;
853 u8 tmp_ht_cap_len = 0;
854 u8 *tmp_ht_info_buf = NULL;
855 u8 tmp_ht_info_len = 0;
856 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
857 u8 *tmp_generic_ie_buf = NULL;
858 u8 tmp_generic_ie_len = 0;
863 if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
868 if ((ieee->current_network.mode == IEEE_G) ||
869 (ieee->current_network.mode == IEEE_N_24G &&
870 ieee->pHTInfo->bCurSuppCCK)) {
873 if (ieee->current_network.buseprotection)
874 erpinfo_content |= ERP_UseProtection;
878 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
879 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
880 ((0 == strcmp(crypt->ops->name, "R-WEP") || wpa_ie_len));
881 if (ieee->pHTInfo->bCurrentHTSupport) {
882 tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
883 tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
884 tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo);
885 tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo);
886 HTConstructCapabilityElement(ieee, tmp_ht_cap_buf,
887 &tmp_ht_cap_len, encrypt, false);
888 HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len,
891 if (pHTInfo->bRegRT2RTAggregation) {
892 tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
894 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
895 HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf,
896 &tmp_generic_ie_len);
900 beacon_size = sizeof(struct rtllib_probe_response)+2+
901 ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len
902 + wpa_ie_len + ieee->tx_headroom;
903 skb = dev_alloc_skb(beacon_size);
907 skb_reserve(skb, ieee->tx_headroom);
909 beacon_buf = (struct rtllib_probe_response *) skb_put(skb,
910 (beacon_size - ieee->tx_headroom));
911 memcpy(beacon_buf->header.addr1, dest, ETH_ALEN);
912 memcpy(beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
913 memcpy(beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
915 beacon_buf->header.duration_id = 0;
916 beacon_buf->beacon_interval =
917 cpu_to_le16(ieee->current_network.beacon_interval);
918 beacon_buf->capability =
919 cpu_to_le16(ieee->current_network.capability &
920 WLAN_CAPABILITY_IBSS);
921 beacon_buf->capability |=
922 cpu_to_le16(ieee->current_network.capability &
923 WLAN_CAPABILITY_SHORT_PREAMBLE);
925 if (ieee->short_slot && (ieee->current_network.capability &
926 WLAN_CAPABILITY_SHORT_SLOT_TIME))
927 beacon_buf->capability |=
928 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
930 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
932 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
935 beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP);
936 beacon_buf->info_element[0].id = MFIE_TYPE_SSID;
937 beacon_buf->info_element[0].len = ssid_len;
939 tag = (u8 *) beacon_buf->info_element[0].data;
941 memcpy(tag, ssid, ssid_len);
945 *(tag++) = MFIE_TYPE_RATES;
946 *(tag++) = rate_len-2;
947 memcpy(tag, ieee->current_network.rates, rate_len-2);
950 *(tag++) = MFIE_TYPE_DS_SET;
952 *(tag++) = ieee->current_network.channel;
956 *(tag++) = MFIE_TYPE_IBSS_SET;
958 val16 = ieee->current_network.atim_window;
959 memcpy((u8 *)tag, (u8 *)&val16, 2);
964 *(tag++) = MFIE_TYPE_ERP;
966 *(tag++) = erpinfo_content;
969 *(tag++) = MFIE_TYPE_RATES_EX;
970 *(tag++) = rate_ex_len-2;
971 memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2);
972 tag += rate_ex_len-2;
976 if (ieee->iw_mode == IW_MODE_ADHOC)
977 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
978 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
979 tag += ieee->wpa_ie_len;
984 static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
989 struct lib80211_crypt_data *crypt;
990 struct rtllib_assoc_response_frame *assoc;
993 unsigned int rate_len = rtllib_MFIE_rate_len(ieee);
994 int len = sizeof(struct rtllib_assoc_response_frame) + rate_len +
997 skb = dev_alloc_skb(len);
1002 skb_reserve(skb, ieee->tx_headroom);
1004 assoc = (struct rtllib_assoc_response_frame *)
1005 skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
1007 assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
1008 memcpy(assoc->header.addr1, dest, ETH_ALEN);
1009 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1010 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1011 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1012 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS);
1015 if (ieee->short_slot)
1016 assoc->capability |=
1017 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1019 if (ieee->host_encrypt)
1020 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1024 encrypt = (crypt && crypt->ops);
1027 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1030 assoc->aid = cpu_to_le16(ieee->assoc_id);
1031 if (ieee->assoc_id == 0x2007)
1036 tag = (u8 *) skb_put(skb, rate_len);
1037 rtllib_MFIE_Brate(ieee, &tag);
1038 rtllib_MFIE_Grate(ieee, &tag);
1043 static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
1046 struct sk_buff *skb = NULL;
1047 struct rtllib_authentication *auth;
1048 int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1;
1050 skb = dev_alloc_skb(len);
1054 skb->len = sizeof(struct rtllib_authentication);
1056 skb_reserve(skb, ieee->tx_headroom);
1058 auth = (struct rtllib_authentication *)
1059 skb_put(skb, sizeof(struct rtllib_authentication));
1061 auth->status = cpu_to_le16(status);
1062 auth->transaction = cpu_to_le16(2);
1063 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1065 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1066 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1067 memcpy(auth->header.addr1, dest, ETH_ALEN);
1068 auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
1074 static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr)
1076 struct sk_buff *skb;
1077 struct rtllib_hdr_3addr *hdr;
1079 skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom);
1083 skb_reserve(skb, ieee->tx_headroom);
1085 hdr = (struct rtllib_hdr_3addr *)skb_put(skb,
1086 sizeof(struct rtllib_hdr_3addr));
1088 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1089 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1090 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1092 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA |
1093 RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS |
1094 (pwr ? RTLLIB_FCTL_PM : 0));
1101 static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee)
1103 struct sk_buff *skb;
1104 struct rtllib_pspoll_hdr *hdr;
1106 skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom);
1110 skb_reserve(skb, ieee->tx_headroom);
1112 hdr = (struct rtllib_pspoll_hdr *)skb_put(skb,
1113 sizeof(struct rtllib_pspoll_hdr));
1115 memcpy(hdr->bssid, ieee->current_network.bssid, ETH_ALEN);
1116 memcpy(hdr->ta, ieee->dev->dev_addr, ETH_ALEN);
1118 hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000);
1119 hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL |
1126 static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest)
1128 struct sk_buff *buf = rtllib_assoc_resp(ieee, dest);
1131 softmac_mgmt_xmit(buf, ieee);
1135 static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest)
1137 struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest);
1140 softmac_mgmt_xmit(buf, ieee);
1144 static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest)
1146 struct sk_buff *buf = rtllib_probe_resp(ieee, dest);
1149 softmac_mgmt_xmit(buf, ieee);
1153 inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid)
1158 if ((ieee->PMKIDList[i].bUsed) &&
1159 (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0))
1162 } while (i < NUM_PMKID_CACHE);
1164 if (i == NUM_PMKID_CACHE)
1169 inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1170 struct rtllib_device *ieee)
1172 struct sk_buff *skb;
1173 struct rtllib_assoc_request_frame *hdr;
1176 u8 *ht_cap_buf = NULL;
1178 u8 *realtek_ie_buf = NULL;
1179 u8 realtek_ie_len = 0;
1180 int wpa_ie_len = ieee->wpa_ie_len;
1181 int wps_ie_len = ieee->wps_ie_len;
1182 unsigned int ckip_ie_len = 0;
1183 unsigned int ccxrm_ie_len = 0;
1184 unsigned int cxvernum_ie_len = 0;
1185 struct lib80211_crypt_data *crypt;
1189 unsigned int rate_len = (beacon->rates_len ?
1190 (beacon->rates_len + 2) : 0) +
1191 (beacon->rates_ex_len ? (beacon->rates_ex_len) +
1194 unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0;
1195 unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0;
1199 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
1201 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1202 ((0 == strcmp(crypt->ops->name, "R-WEP") ||
1207 if ((ieee->rtllib_ap_sec_type &&
1208 (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) ||
1209 ieee->bForcedBgMode) {
1210 ieee->pHTInfo->bEnableHT = 0;
1211 ieee->mode = WIRELESS_MODE_G;
1214 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1215 ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap);
1216 ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
1217 HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len,
1219 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1220 realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer;
1222 sizeof(ieee->pHTInfo->szRT2RTAggBuffer);
1223 HTConstructRT2RTAggElement(ieee, realtek_ie_buf,
1228 if (beacon->bCkipSupported)
1230 if (beacon->bCcxRmEnable)
1232 if (beacon->BssCcxVerNumber >= 2)
1233 cxvernum_ie_len = 5+2;
1235 PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid);
1236 if (PMKCacheIdx >= 0) {
1238 netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n",
1241 len = sizeof(struct rtllib_assoc_request_frame) + 2
1253 + ieee->tx_headroom;
1255 skb = dev_alloc_skb(len);
1260 skb_reserve(skb, ieee->tx_headroom);
1262 hdr = (struct rtllib_assoc_request_frame *)
1263 skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2);
1266 hdr->header.frame_ctl = RTLLIB_STYPE_ASSOC_REQ;
1267 hdr->header.duration_id = cpu_to_le16(37);
1268 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1269 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1270 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1272 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);
1274 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
1275 if (beacon->capability & WLAN_CAPABILITY_PRIVACY)
1276 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1278 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1279 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1281 if (ieee->short_slot &&
1282 (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME))
1283 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
1286 hdr->listen_interval = cpu_to_le16(beacon->listen_interval);
1288 hdr->info_element[0].id = MFIE_TYPE_SSID;
1290 hdr->info_element[0].len = beacon->ssid_len;
1291 tag = skb_put(skb, beacon->ssid_len);
1292 memcpy(tag, beacon->ssid, beacon->ssid_len);
1294 tag = skb_put(skb, rate_len);
1296 if (beacon->rates_len) {
1297 *tag++ = MFIE_TYPE_RATES;
1298 *tag++ = beacon->rates_len;
1299 for (i = 0; i < beacon->rates_len; i++)
1300 *tag++ = beacon->rates[i];
1303 if (beacon->rates_ex_len) {
1304 *tag++ = MFIE_TYPE_RATES_EX;
1305 *tag++ = beacon->rates_ex_len;
1306 for (i = 0; i < beacon->rates_ex_len; i++)
1307 *tag++ = beacon->rates_ex[i];
1310 if (beacon->bCkipSupported) {
1311 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1312 u8 CcxAironetBuf[30];
1313 struct octet_string osCcxAironetIE;
1315 memset(CcxAironetBuf, 0, 30);
1316 osCcxAironetIE.Octet = CcxAironetBuf;
1317 osCcxAironetIE.Length = sizeof(CcxAironetBuf);
1318 memcpy(osCcxAironetIE.Octet, AironetIeOui,
1319 sizeof(AironetIeOui));
1321 osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |=
1322 (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC);
1323 tag = skb_put(skb, ckip_ie_len);
1324 *tag++ = MFIE_TYPE_AIRONET;
1325 *tag++ = osCcxAironetIE.Length;
1326 memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length);
1327 tag += osCcxAironetIE.Length;
1330 if (beacon->bCcxRmEnable) {
1331 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1333 struct octet_string osCcxRmCap;
1335 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1336 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1337 tag = skb_put(skb, ccxrm_ie_len);
1338 *tag++ = MFIE_TYPE_GENERIC;
1339 *tag++ = osCcxRmCap.Length;
1340 memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length);
1341 tag += osCcxRmCap.Length;
1344 if (beacon->BssCcxVerNumber >= 2) {
1345 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1346 struct octet_string osCcxVerNum;
1348 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
1349 osCcxVerNum.Octet = CcxVerNumBuf;
1350 osCcxVerNum.Length = sizeof(CcxVerNumBuf);
1351 tag = skb_put(skb, cxvernum_ie_len);
1352 *tag++ = MFIE_TYPE_GENERIC;
1353 *tag++ = osCcxVerNum.Length;
1354 memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length);
1355 tag += osCcxVerNum.Length;
1357 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1358 if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) {
1359 tag = skb_put(skb, ht_cap_len);
1360 *tag++ = MFIE_TYPE_HT_CAP;
1361 *tag++ = ht_cap_len - 2;
1362 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1363 tag += ht_cap_len - 2;
1368 tag = skb_put(skb, ieee->wpa_ie_len);
1369 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1371 if (PMKCacheIdx >= 0) {
1372 tag = skb_put(skb, 18);
1375 memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID,
1380 tag = skb_put(skb, wmm_info_len);
1381 rtllib_WMM_Info(ieee, &tag);
1384 if (wps_ie_len && ieee->wps_ie) {
1385 tag = skb_put(skb, wps_ie_len);
1386 memcpy(tag, ieee->wps_ie, wps_ie_len);
1389 tag = skb_put(skb, turbo_info_len);
1391 rtllib_TURBO_Info(ieee, &tag);
1393 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1394 if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) {
1395 tag = skb_put(skb, ht_cap_len);
1396 *tag++ = MFIE_TYPE_GENERIC;
1397 *tag++ = ht_cap_len - 2;
1398 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1399 tag += ht_cap_len - 2;
1402 if (ieee->pHTInfo->bCurrentRT2RTAggregation) {
1403 tag = skb_put(skb, realtek_ie_len);
1404 *tag++ = MFIE_TYPE_GENERIC;
1405 *tag++ = realtek_ie_len - 2;
1406 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1410 kfree(ieee->assocreq_ies);
1411 ieee->assocreq_ies = NULL;
1412 ies = &(hdr->info_element[0].id);
1413 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1414 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC);
1415 if (ieee->assocreq_ies)
1416 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1418 netdev_info(ieee->dev,
1419 "%s()Warning: can't alloc memory for assocreq_ies\n",
1421 ieee->assocreq_ies_len = 0;
1426 void rtllib_associate_abort(struct rtllib_device *ieee)
1428 unsigned long flags;
1430 spin_lock_irqsave(&ieee->lock, flags);
1432 ieee->associate_seq++;
1434 /* don't scan, and avoid to have the RX path possibily
1435 * try again to associate. Even do not react to AUTH or
1436 * ASSOC response. Just wait for the retry wq to be scheduled.
1437 * Here we will check if there are good nets to associate
1438 * with, so we retry or just get back to NO_LINK and scanning
1440 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) {
1441 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1442 ieee->softmac_stats.no_auth_rs++;
1444 RTLLIB_DEBUG_MGMT("Association failed\n");
1445 ieee->softmac_stats.no_ass_rs++;
1448 ieee->state = RTLLIB_ASSOCIATING_RETRY;
1450 queue_delayed_work_rsl(ieee->wq, &ieee->associate_retry_wq,
1451 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME);
1453 spin_unlock_irqrestore(&ieee->lock, flags);
1456 static void rtllib_associate_abort_cb(unsigned long dev)
1458 rtllib_associate_abort((struct rtllib_device *) dev);
1461 static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr)
1463 struct rtllib_network *beacon = &ieee->current_network;
1464 struct sk_buff *skb;
1466 RTLLIB_DEBUG_MGMT("Stopping scan\n");
1468 ieee->softmac_stats.tx_auth_rq++;
1470 skb = rtllib_authentication_req(beacon, ieee, 0, daddr);
1473 rtllib_associate_abort(ieee);
1475 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING;
1476 RTLLIB_DEBUG_MGMT("Sending authentication request\n");
1477 softmac_mgmt_xmit(skb, ieee);
1478 if (!timer_pending(&ieee->associate_timer)) {
1479 ieee->associate_timer.expires = jiffies + (HZ / 2);
1480 add_timer(&ieee->associate_timer);
1485 static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge, int chlen)
1488 struct sk_buff *skb;
1489 struct rtllib_network *beacon = &ieee->current_network;
1491 ieee->associate_seq++;
1492 ieee->softmac_stats.tx_auth_rq++;
1494 skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid);
1497 rtllib_associate_abort(ieee);
1499 c = skb_put(skb, chlen+2);
1500 *(c++) = MFIE_TYPE_CHALLENGE;
1502 memcpy(c, challenge, chlen);
1504 RTLLIB_DEBUG_MGMT("Sending authentication challenge response\n");
1506 rtllib_encrypt_fragment(ieee, skb,
1507 sizeof(struct rtllib_hdr_3addr));
1509 softmac_mgmt_xmit(skb, ieee);
1510 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1515 static void rtllib_associate_step2(struct rtllib_device *ieee)
1517 struct sk_buff *skb;
1518 struct rtllib_network *beacon = &ieee->current_network;
1520 del_timer_sync(&ieee->associate_timer);
1522 RTLLIB_DEBUG_MGMT("Sending association request\n");
1524 ieee->softmac_stats.tx_ass_rq++;
1525 skb = rtllib_association_req(beacon, ieee);
1527 rtllib_associate_abort(ieee);
1529 softmac_mgmt_xmit(skb, ieee);
1530 mod_timer(&ieee->associate_timer, jiffies + (HZ/2));
1535 static void rtllib_associate_complete_wq(void *data)
1537 struct rtllib_device *ieee = (struct rtllib_device *)
1538 container_of_work_rsl(data,
1539 struct rtllib_device,
1540 associate_complete_wq);
1541 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1542 (&(ieee->PowerSaveControl));
1543 netdev_info(ieee->dev, "Associated successfully\n");
1544 if (!ieee->is_silent_reset) {
1545 netdev_info(ieee->dev, "normal associate\n");
1546 notify_wx_assoc_event(ieee);
1549 netif_carrier_on(ieee->dev);
1550 ieee->is_roaming = false;
1551 if (rtllib_is_54g(&ieee->current_network) &&
1552 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1554 netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate);
1557 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1558 netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate);
1560 if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) {
1561 netdev_info(ieee->dev, "Successfully associated, ht enabled\n");
1564 netdev_info(ieee->dev,
1565 "Successfully associated, ht not enabled(%d, %d)\n",
1566 ieee->pHTInfo->bCurrentHTSupport,
1567 ieee->pHTInfo->bEnableHT);
1568 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1570 ieee->LinkDetectInfo.SlotNum = 2 * (1 +
1571 ieee->current_network.beacon_interval /
1573 if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 ||
1574 ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
1575 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
1576 ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
1578 pPSC->LpsIdleCount = 0;
1579 ieee->link_change(ieee->dev);
1581 if (ieee->is_silent_reset) {
1582 netdev_info(ieee->dev, "silent reset associate\n");
1583 ieee->is_silent_reset = false;
1586 if (ieee->data_hard_resume)
1587 ieee->data_hard_resume(ieee->dev);
1591 static void rtllib_sta_send_associnfo(struct rtllib_device *ieee)
1595 static void rtllib_associate_complete(struct rtllib_device *ieee)
1597 del_timer_sync(&ieee->associate_timer);
1599 ieee->state = RTLLIB_LINKED;
1600 rtllib_sta_send_associnfo(ieee);
1602 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1605 static void rtllib_associate_procedure_wq(void *data)
1607 struct rtllib_device *ieee = container_of_dwork_rsl(data,
1608 struct rtllib_device,
1609 associate_procedure_wq);
1610 rtllib_stop_scan_syncro(ieee);
1611 if (ieee->rtllib_ips_leave != NULL)
1612 ieee->rtllib_ips_leave(ieee->dev);
1613 down(&ieee->wx_sem);
1615 if (ieee->data_hard_stop)
1616 ieee->data_hard_stop(ieee->dev);
1618 rtllib_stop_scan(ieee);
1619 RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__,
1620 ieee->current_network.channel);
1621 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1622 if (ieee->eRFPowerState == eRfOff) {
1624 "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n",
1626 if (ieee->rtllib_ips_leave_wq != NULL)
1627 ieee->rtllib_ips_leave_wq(ieee->dev);
1631 ieee->associate_seq = 1;
1633 rtllib_associate_step1(ieee, ieee->current_network.bssid);
1638 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1639 struct rtllib_network *net)
1641 u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1];
1642 int tmp_ssid_len = 0;
1644 short apset, ssidset, ssidbroad, apmatch, ssidmatch;
1646 /* we are interested in new new only if we are not associated
1647 * and we are not associating / authenticating
1649 if (ieee->state != RTLLIB_NOLINK)
1652 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability &
1653 WLAN_CAPABILITY_ESS))
1656 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability &
1657 WLAN_CAPABILITY_IBSS))
1660 if ((ieee->iw_mode == IW_MODE_ADHOC) &&
1661 (net->channel > ieee->ibss_maxjoin_chal))
1663 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1664 /* if the user specified the AP MAC, we need also the essid
1665 * This could be obtained by beacons or, if the network does not
1666 * broadcast it, it can be put manually.
1668 apset = ieee->wap_set;
1669 ssidset = ieee->ssid_set;
1670 ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0');
1671 apmatch = (memcmp(ieee->current_network.bssid, net->bssid,
1674 ssidmatch = (ieee->current_network.ssid_len ==
1675 net->hidden_ssid_len) &&
1676 (!strncmp(ieee->current_network.ssid,
1677 net->hidden_ssid, net->hidden_ssid_len));
1678 if (net->hidden_ssid_len > 0) {
1679 strncpy(net->ssid, net->hidden_ssid,
1680 net->hidden_ssid_len);
1681 net->ssid_len = net->hidden_ssid_len;
1686 (ieee->current_network.ssid_len == net->ssid_len) &&
1687 (!strncmp(ieee->current_network.ssid, net->ssid,
1690 /* if the user set the AP check if match.
1691 * if the network does not broadcast essid we check the
1692 * user supplied ANY essid
1693 * if the network does broadcast and the user does not set
1695 * if the network does broadcast and the user did set essid
1696 * check if essid match
1697 * if the ap is not set, check that the user set the bssid
1698 * and the network does broadcast and that those two bssid match
1700 if ((apset && apmatch &&
1701 ((ssidset && ssidbroad && ssidmatch) ||
1702 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1703 (!apset && ssidset && ssidbroad && ssidmatch) ||
1704 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1705 /* if the essid is hidden replace it with the
1706 * essid provided by the user.
1709 strncpy(tmp_ssid, ieee->current_network.ssid,
1711 tmp_ssid_len = ieee->current_network.ssid_len;
1713 memcpy(&ieee->current_network, net,
1714 sizeof(struct rtllib_network));
1716 strncpy(ieee->current_network.ssid, tmp_ssid,
1718 ieee->current_network.ssid_len = tmp_ssid_len;
1720 netdev_info(ieee->dev,
1721 "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",
1722 ieee->current_network.ssid,
1723 ieee->current_network.channel,
1724 ieee->current_network.qos_data.supported,
1725 ieee->pHTInfo->bEnableHT,
1726 ieee->current_network.bssht.bdSupportHT,
1727 ieee->current_network.mode,
1728 ieee->current_network.flags);
1730 if ((rtllib_act_scanning(ieee, false)) &&
1731 !(ieee->softmac_features & IEEE_SOFTMAC_SCAN))
1732 rtllib_stop_scan_syncro(ieee);
1734 ieee->hwscan_ch_bk = ieee->current_network.channel;
1735 HTResetIOTSetting(ieee->pHTInfo);
1737 if (ieee->iw_mode == IW_MODE_INFRA) {
1738 /* Join the network for the first time */
1739 ieee->AsocRetryCount = 0;
1740 if ((ieee->current_network.qos_data.supported == 1) &&
1741 ieee->current_network.bssht.bdSupportHT)
1742 HTResetSelfAndSavePeerSetting(ieee,
1743 &(ieee->current_network));
1745 ieee->pHTInfo->bCurrentHTSupport =
1748 ieee->state = RTLLIB_ASSOCIATING;
1749 if (ieee->LedControlHandler != NULL)
1750 ieee->LedControlHandler(ieee->dev,
1751 LED_CTL_START_TO_LINK);
1752 queue_delayed_work_rsl(ieee->wq,
1753 &ieee->associate_procedure_wq, 0);
1755 if (rtllib_is_54g(&ieee->current_network) &&
1756 (ieee->modulation & RTLLIB_OFDM_MODULATION)) {
1758 ieee->SetWirelessMode(ieee->dev, IEEE_G);
1759 netdev_info(ieee->dev, "Using G rates\n");
1762 ieee->SetWirelessMode(ieee->dev, IEEE_B);
1763 netdev_info(ieee->dev, "Using B rates\n");
1765 memset(ieee->dot11HTOperationalRateSet, 0, 16);
1766 ieee->state = RTLLIB_LINKED;
1772 void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1774 unsigned long flags;
1775 struct rtllib_network *target;
1777 spin_lock_irqsave(&ieee->lock, flags);
1779 list_for_each_entry(target, &ieee->network_list, list) {
1781 /* if the state become different that NOLINK means
1782 * we had found what we are searching for
1785 if (ieee->state != RTLLIB_NOLINK)
1788 if (ieee->scan_age == 0 || time_after(target->last_scanned +
1789 ieee->scan_age, jiffies))
1790 rtllib_softmac_new_net(ieee, target);
1792 spin_unlock_irqrestore(&ieee->lock, flags);
1795 static inline u16 auth_parse(struct sk_buff *skb, u8 **challenge, int *chlen)
1797 struct rtllib_authentication *a;
1800 if (skb->len < (sizeof(struct rtllib_authentication) -
1801 sizeof(struct rtllib_info_element))) {
1802 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1806 a = (struct rtllib_authentication *) skb->data;
1807 if (skb->len > (sizeof(struct rtllib_authentication) + 3)) {
1808 t = skb->data + sizeof(struct rtllib_authentication);
1810 if (*(t++) == MFIE_TYPE_CHALLENGE) {
1812 *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
1817 return cpu_to_le16(a->status);
1820 static int auth_rq_parse(struct sk_buff *skb, u8 *dest)
1822 struct rtllib_authentication *a;
1824 if (skb->len < (sizeof(struct rtllib_authentication) -
1825 sizeof(struct rtllib_info_element))) {
1826 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",
1830 a = (struct rtllib_authentication *) skb->data;
1832 memcpy(dest, a->header.addr2, ETH_ALEN);
1834 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1835 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1837 return WLAN_STATUS_SUCCESS;
1840 static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1847 struct rtllib_hdr_3addr *header =
1848 (struct rtllib_hdr_3addr *) skb->data;
1851 if (skb->len < sizeof(struct rtllib_hdr_3addr))
1852 return -1; /* corrupted */
1855 (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0) &&
1856 (!is_broadcast_ether_addr(header->addr3));
1860 memcpy(src, header->addr2, ETH_ALEN);
1862 skbend = (u8 *)skb->data + skb->len;
1864 tag = skb->data + sizeof(struct rtllib_hdr_3addr);
1866 while (tag + 1 < skbend) {
1869 ssidlen = *(tag + 1);
1872 tag++; /* point to the len field */
1873 tag = tag + *(tag); /* point to the last data byte of the tag */
1874 tag++; /* point to the next tag */
1881 return 1; /* ssid not found in tagged param */
1883 return !strncmp(ssid, ieee->current_network.ssid, ssidlen);
1886 static int assoc_rq_parse(struct sk_buff *skb, u8 *dest)
1888 struct rtllib_assoc_request_frame *a;
1890 if (skb->len < (sizeof(struct rtllib_assoc_request_frame) -
1891 sizeof(struct rtllib_info_element))) {
1893 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d\n", skb->len);
1897 a = (struct rtllib_assoc_request_frame *) skb->data;
1899 memcpy(dest, a->header.addr2, ETH_ALEN);
1904 static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb,
1907 struct rtllib_assoc_response_frame *response_head;
1910 if (skb->len < sizeof(struct rtllib_assoc_response_frame)) {
1911 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1915 response_head = (struct rtllib_assoc_response_frame *) skb->data;
1916 *aid = le16_to_cpu(response_head->aid) & 0x3fff;
1918 status_code = le16_to_cpu(response_head->status);
1919 if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES ||
1920 status_code == WLAN_STATUS_CAPS_UNSUPPORTED) &&
1921 ((ieee->mode == IEEE_G) &&
1922 (ieee->current_network.mode == IEEE_N_24G) &&
1923 (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) {
1924 ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE;
1926 ieee->AsocRetryCount = 0;
1929 return le16_to_cpu(response_head->status);
1932 void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb)
1936 ieee->softmac_stats.rx_probe_rq++;
1937 if (probe_rq_parse(ieee, skb, dest) > 0) {
1938 ieee->softmac_stats.tx_probe_rs++;
1939 rtllib_resp_to_probe(ieee, dest);
1943 static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee,
1944 struct sk_buff *skb)
1949 ieee->softmac_stats.rx_auth_rq++;
1951 status = auth_rq_parse(skb, dest);
1953 rtllib_resp_to_auth(ieee, status, dest);
1956 static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee,
1957 struct sk_buff *skb)
1962 ieee->softmac_stats.rx_ass_rq++;
1963 if (assoc_rq_parse(skb, dest) != -1)
1964 rtllib_resp_to_assoc_rq(ieee, dest);
1966 netdev_info(ieee->dev, "New client associated: %pM\n", dest);
1969 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr)
1972 struct sk_buff *buf = rtllib_null_func(ieee, pwr);
1975 softmac_ps_mgmt_xmit(buf, ieee);
1977 EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame);
1979 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1981 struct sk_buff *buf = rtllib_pspoll_func(ieee);
1984 softmac_ps_mgmt_xmit(buf, ieee);
1987 static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1989 int timeout = ieee->ps_timeout;
1991 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1992 (&(ieee->PowerSaveControl));
1994 if (ieee->LPSDelayCnt) {
1995 ieee->LPSDelayCnt--;
1999 dtim = ieee->current_network.dtim_data;
2000 if (!(dtim & RTLLIB_DTIM_VALID))
2002 timeout = ieee->current_network.beacon_interval;
2003 ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID;
2004 /* there's no need to nofity AP that I find you buffered
2005 * with broadcast packet
2007 if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps))
2010 if (!time_after(jiffies,
2011 ieee->dev->trans_start + msecs_to_jiffies(timeout)))
2013 if (!time_after(jiffies,
2014 ieee->last_rx_ps_time + msecs_to_jiffies(timeout)))
2016 if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) &&
2017 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
2021 if (ieee->bAwakePktSent) {
2022 pPSC->LPSAwakeIntvl = 1;
2026 if (pPSC->LPSAwakeIntvl == 0)
2027 pPSC->LPSAwakeIntvl = 1;
2028 if (pPSC->RegMaxLPSAwakeIntvl == 0)
2030 else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF)
2031 MaxPeriod = ieee->current_network.dtim_period;
2033 MaxPeriod = pPSC->RegMaxLPSAwakeIntvl;
2034 pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >=
2035 MaxPeriod) ? MaxPeriod :
2036 (pPSC->LPSAwakeIntvl + 1);
2039 u8 LPSAwakeIntvl_tmp = 0;
2040 u8 period = ieee->current_network.dtim_period;
2041 u8 count = ieee->current_network.tim.tim_count;
2044 if (pPSC->LPSAwakeIntvl > period)
2045 LPSAwakeIntvl_tmp = period +
2046 (pPSC->LPSAwakeIntvl -
2048 ((pPSC->LPSAwakeIntvl-period) %
2051 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2054 if (pPSC->LPSAwakeIntvl >
2055 ieee->current_network.tim.tim_count)
2056 LPSAwakeIntvl_tmp = count +
2057 (pPSC->LPSAwakeIntvl - count) -
2058 ((pPSC->LPSAwakeIntvl-count)%period);
2060 LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
2063 *time = ieee->current_network.last_dtim_sta_time
2064 + msecs_to_jiffies(ieee->current_network.beacon_interval *
2074 static inline void rtllib_sta_ps(struct rtllib_device *ieee)
2078 unsigned long flags, flags2;
2080 spin_lock_irqsave(&ieee->lock, flags);
2082 if ((ieee->ps == RTLLIB_PS_DISABLED ||
2083 ieee->iw_mode != IW_MODE_INFRA ||
2084 ieee->state != RTLLIB_LINKED)) {
2086 "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n",
2087 __func__, ieee->ps, ieee->iw_mode, ieee->state);
2088 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2089 rtllib_sta_wakeup(ieee, 1);
2091 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2093 sleep = rtllib_sta_ps_sleep(ieee, &time);
2094 /* 2 wake, 1 sleep, 0 do nothing */
2098 if (ieee->sta_sleep == LPS_IS_SLEEP) {
2099 ieee->enter_sleep_state(ieee->dev, time);
2100 } else if (ieee->sta_sleep == LPS_IS_WAKE) {
2101 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2103 if (ieee->ps_is_queue_empty(ieee->dev)) {
2104 ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
2105 ieee->ack_tx_to_ieee = 1;
2106 rtllib_sta_ps_send_null_frame(ieee, 1);
2107 ieee->ps_time = time;
2109 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2113 ieee->bAwakePktSent = false;
2115 } else if (sleep == 2) {
2116 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2118 rtllib_sta_wakeup(ieee, 1);
2120 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2124 spin_unlock_irqrestore(&ieee->lock, flags);
2128 void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2130 if (ieee->sta_sleep == LPS_IS_WAKE) {
2132 if (ieee->pHTInfo->IOTAction &
2133 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2134 ieee->ack_tx_to_ieee = 1;
2135 rtllib_sta_ps_send_null_frame(ieee, 0);
2137 ieee->ack_tx_to_ieee = 1;
2138 rtllib_sta_ps_send_pspoll_frame(ieee);
2145 if (ieee->sta_sleep == LPS_IS_SLEEP)
2146 ieee->sta_wake_up(ieee->dev);
2148 if (ieee->pHTInfo->IOTAction &
2149 HT_IOT_ACT_NULL_DATA_POWER_SAVING) {
2150 ieee->ack_tx_to_ieee = 1;
2151 rtllib_sta_ps_send_null_frame(ieee, 0);
2153 ieee->ack_tx_to_ieee = 1;
2154 ieee->polling = true;
2155 rtllib_sta_ps_send_pspoll_frame(ieee);
2159 ieee->sta_sleep = LPS_IS_WAKE;
2160 ieee->polling = false;
2164 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success)
2166 unsigned long flags, flags2;
2168 spin_lock_irqsave(&ieee->lock, flags);
2170 if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) {
2171 /* Null frame with PS bit set */
2173 ieee->sta_sleep = LPS_IS_SLEEP;
2174 ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
2176 /* if the card report not success we can't be sure the AP
2177 * has not RXed so we can't assume the AP believe us awake
2179 } else {/* 21112005 - tx again null without PS bit if lost */
2181 if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) {
2182 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2183 if (ieee->pHTInfo->IOTAction &
2184 HT_IOT_ACT_NULL_DATA_POWER_SAVING)
2185 rtllib_sta_ps_send_null_frame(ieee, 0);
2187 rtllib_sta_ps_send_pspoll_frame(ieee);
2188 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2191 spin_unlock_irqrestore(&ieee->lock, flags);
2193 EXPORT_SYMBOL(rtllib_ps_tx_ack);
2195 static void rtllib_process_action(struct rtllib_device *ieee, struct sk_buff *skb)
2197 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2198 u8 *act = rtllib_get_payload((struct rtllib_hdr *)header);
2202 RTLLIB_DEBUG(RTLLIB_DL_ERR,
2203 "error to get payload of action frame\n");
2213 rtllib_rx_ADDBAReq(ieee, skb);
2216 rtllib_rx_ADDBARsp(ieee, skb);
2219 rtllib_rx_DELBA(ieee, skb);
2228 inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2229 struct rtllib_rx_stats *rx_stats)
2234 struct rtllib_assoc_response_frame *assoc_resp;
2235 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2237 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2238 WLAN_FC_GET_STYPE(header->frame_ctl));
2240 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2241 ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
2242 (ieee->iw_mode == IW_MODE_INFRA)) {
2243 errcode = assoc_parse(ieee, skb, &aid);
2245 struct rtllib_network *network =
2246 kzalloc(sizeof(struct rtllib_network),
2251 ieee->state = RTLLIB_LINKED;
2252 ieee->assoc_id = aid;
2253 ieee->softmac_stats.rx_ass_ok++;
2254 /* station support qos */
2255 /* Let the register setting default with Legacy station */
2256 assoc_resp = (struct rtllib_assoc_response_frame *)skb->data;
2257 if (ieee->current_network.qos_data.supported == 1) {
2258 if (rtllib_parse_info_param(ieee, assoc_resp->info_element,
2259 rx_stats->len - sizeof(*assoc_resp),
2260 network, rx_stats)) {
2264 memcpy(ieee->pHTInfo->PeerHTCapBuf,
2265 network->bssht.bdHTCapBuf,
2266 network->bssht.bdHTCapLen);
2267 memcpy(ieee->pHTInfo->PeerHTInfoBuf,
2268 network->bssht.bdHTInfoBuf,
2269 network->bssht.bdHTInfoLen);
2270 if (ieee->handle_assoc_response != NULL)
2271 ieee->handle_assoc_response(ieee->dev,
2272 (struct rtllib_assoc_response_frame *)header,
2277 kfree(ieee->assocresp_ies);
2278 ieee->assocresp_ies = NULL;
2279 ies = &(assoc_resp->info_element[0].id);
2280 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2281 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len,
2283 if (ieee->assocresp_ies)
2284 memcpy(ieee->assocresp_ies, ies,
2285 ieee->assocresp_ies_len);
2287 netdev_info(ieee->dev,
2288 "%s()Warning: can't alloc memory for assocresp_ies\n",
2290 ieee->assocresp_ies_len = 0;
2292 rtllib_associate_complete(ieee);
2294 /* aid could not been allocated */
2295 ieee->softmac_stats.rx_ass_err++;
2296 netdev_info(ieee->dev,
2297 "Association response status code 0x%x\n",
2300 "Association response status code 0x%x\n",
2302 if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT)
2303 queue_delayed_work_rsl(ieee->wq,
2304 &ieee->associate_procedure_wq, 0);
2306 rtllib_associate_abort(ieee);
2312 static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
2317 bool bSupportNmode = true, bHalfSupportNmode = false;
2319 errcode = auth_parse(skb, &challenge, &chlen);
2322 ieee->softmac_stats.rx_auth_rs_err++;
2323 RTLLIB_DEBUG_MGMT("Authentication respose status code 0x%x",
2326 netdev_info(ieee->dev,
2327 "Authentication respose status code 0x%x", errcode);
2328 rtllib_associate_abort(ieee);
2332 if (ieee->open_wep || !challenge) {
2333 ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED;
2334 ieee->softmac_stats.rx_auth_rs_ok++;
2335 if (!(ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE)) {
2336 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
2337 if (IsHTHalfNmodeAPs(ieee)) {
2338 bSupportNmode = true;
2339 bHalfSupportNmode = true;
2341 bSupportNmode = false;
2342 bHalfSupportNmode = false;
2346 /* Dummy wirless mode setting to avoid encryption issue */
2347 if (bSupportNmode) {
2348 ieee->SetWirelessMode(ieee->dev,
2349 ieee->current_network.mode);
2352 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2355 if ((ieee->current_network.mode == IEEE_N_24G) &&
2356 bHalfSupportNmode) {
2357 netdev_info(ieee->dev, "======>enter half N mode\n");
2358 ieee->bHalfWirelessN24GMode = true;
2360 ieee->bHalfWirelessN24GMode = false;
2362 rtllib_associate_step2(ieee);
2364 rtllib_auth_challenge(ieee, challenge, chlen);
2368 inline int rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb,
2369 struct rtllib_rx_stats *rx_stats)
2372 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) {
2373 if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING &&
2374 (ieee->iw_mode == IW_MODE_INFRA)) {
2375 RTLLIB_DEBUG_MGMT("Received authentication response");
2376 rtllib_rx_auth_resp(ieee, skb);
2377 } else if (ieee->iw_mode == IW_MODE_MASTER) {
2378 rtllib_rx_auth_rq(ieee, skb);
2384 inline int rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb)
2386 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2388 if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0)
2391 /* FIXME for now repeat all the association procedure
2392 * both for disassociation and deauthentication
2394 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2395 ieee->state == RTLLIB_LINKED &&
2396 (ieee->iw_mode == IW_MODE_INFRA)) {
2397 netdev_info(ieee->dev,
2398 "==========>received disassoc/deauth(%x) frame, reason code:%x\n",
2399 WLAN_FC_GET_STYPE(header->frame_ctl),
2400 ((struct rtllib_disassoc *)skb->data)->reason);
2401 ieee->state = RTLLIB_ASSOCIATING;
2402 ieee->softmac_stats.reassoc++;
2403 ieee->is_roaming = true;
2404 ieee->LinkDetectInfo.bBusyTraffic = false;
2405 rtllib_disassociate(ieee);
2406 RemovePeerTS(ieee, header->addr2);
2407 if (ieee->LedControlHandler != NULL)
2408 ieee->LedControlHandler(ieee->dev,
2409 LED_CTL_START_TO_LINK);
2411 if (!(ieee->rtllib_ap_sec_type(ieee) &
2412 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
2413 queue_delayed_work_rsl(ieee->wq,
2414 &ieee->associate_procedure_wq, 5);
2419 inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2420 struct sk_buff *skb,
2421 struct rtllib_rx_stats *rx_stats, u16 type,
2424 struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data;
2426 if (!ieee->proto_started)
2429 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2430 case RTLLIB_STYPE_ASSOC_RESP:
2431 case RTLLIB_STYPE_REASSOC_RESP:
2432 if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1)
2435 case RTLLIB_STYPE_ASSOC_REQ:
2436 case RTLLIB_STYPE_REASSOC_REQ:
2437 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2438 ieee->iw_mode == IW_MODE_MASTER)
2439 rtllib_rx_assoc_rq(ieee, skb);
2441 case RTLLIB_STYPE_AUTH:
2442 rtllib_rx_auth(ieee, skb, rx_stats);
2444 case RTLLIB_STYPE_DISASSOC:
2445 case RTLLIB_STYPE_DEAUTH:
2446 rtllib_rx_deauth(ieee, skb);
2448 case RTLLIB_STYPE_MANAGE_ACT:
2449 rtllib_process_action(ieee, skb);
2457 /* following are for a simpler TX queue management.
2458 * Instead of using netif_[stop/wake]_queue the driver
2459 * will use these two functions (plus a reset one), that
2460 * will internally use the kernel netif_* and takes
2461 * care of the ieee802.11 fragmentation.
2462 * So the driver receives a fragment per time and might
2463 * call the stop function when it wants to not
2464 * have enough room to TX an entire packet.
2465 * This might be useful if each fragment needs it's own
2466 * descriptor, thus just keep a total free memory > than
2467 * the max fragmentation threshold is not enough.. If the
2468 * ieee802.11 stack passed a TXB struct then you need
2469 * to keep N free descriptors where
2470 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2471 * In this way you need just one and the 802.11 stack
2472 * will take care of buffering fragments and pass them to
2473 * to the driver later, when it wakes the queue.
2475 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee)
2478 unsigned int queue_index = txb->queue_index;
2479 unsigned long flags;
2481 struct cb_desc *tcb_desc = NULL;
2482 unsigned long queue_len = 0;
2484 spin_lock_irqsave(&ieee->lock, flags);
2486 /* called with 2nd parm 0, no tx mgmt lock required */
2487 rtllib_sta_wakeup(ieee, 0);
2489 /* update the tx status */
2490 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb +
2492 if (tcb_desc->bMulticast)
2493 ieee->stats.multicast++;
2495 /* if xmit available, just xmit it immediately, else just insert it to
2498 for (i = 0; i < txb->nr_frags; i++) {
2499 queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]);
2500 if ((queue_len != 0) ||
2501 (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) ||
2502 (ieee->queue_stop)) {
2503 /* insert the skb packet to the wait queue
2504 * as for the completion function, it does not need
2505 * to check it any more.
2507 if (queue_len < 200)
2508 skb_queue_tail(&ieee->skb_waitQ[queue_index],
2511 kfree_skb(txb->fragments[i]);
2513 ieee->softmac_data_hard_start_xmit(
2515 ieee->dev, ieee->rate);
2519 rtllib_txb_free(txb);
2521 spin_unlock_irqrestore(&ieee->lock, flags);
2525 /* called with ieee->lock acquired */
2526 static void rtllib_resume_tx(struct rtllib_device *ieee)
2530 for (i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags;
2533 if (ieee->queue_stop) {
2534 ieee->tx_pending.frag = i;
2538 ieee->softmac_data_hard_start_xmit(
2539 ieee->tx_pending.txb->fragments[i],
2540 ieee->dev, ieee->rate);
2541 ieee->stats.tx_packets++;
2544 rtllib_txb_free(ieee->tx_pending.txb);
2545 ieee->tx_pending.txb = NULL;
2549 void rtllib_reset_queue(struct rtllib_device *ieee)
2551 unsigned long flags;
2553 spin_lock_irqsave(&ieee->lock, flags);
2554 init_mgmt_queue(ieee);
2555 if (ieee->tx_pending.txb) {
2556 rtllib_txb_free(ieee->tx_pending.txb);
2557 ieee->tx_pending.txb = NULL;
2559 ieee->queue_stop = 0;
2560 spin_unlock_irqrestore(&ieee->lock, flags);
2563 EXPORT_SYMBOL(rtllib_reset_queue);
2565 void rtllib_wake_queue(struct rtllib_device *ieee)
2568 unsigned long flags;
2569 struct sk_buff *skb;
2570 struct rtllib_hdr_3addr *header;
2572 spin_lock_irqsave(&ieee->lock, flags);
2573 if (!ieee->queue_stop)
2576 ieee->queue_stop = 0;
2578 if (ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) {
2579 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))) {
2581 header = (struct rtllib_hdr_3addr *) skb->data;
2583 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2585 if (ieee->seq_ctrl[0] == 0xFFF)
2586 ieee->seq_ctrl[0] = 0;
2588 ieee->seq_ctrl[0]++;
2590 ieee->softmac_data_hard_start_xmit(skb, ieee->dev,
2594 if (!ieee->queue_stop && ieee->tx_pending.txb)
2595 rtllib_resume_tx(ieee);
2597 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)) {
2598 ieee->softmac_stats.swtxawake++;
2599 netif_wake_queue(ieee->dev);
2603 spin_unlock_irqrestore(&ieee->lock, flags);
2607 void rtllib_stop_queue(struct rtllib_device *ieee)
2610 if (!netif_queue_stopped(ieee->dev)) {
2611 netif_stop_queue(ieee->dev);
2612 ieee->softmac_stats.swtxstop++;
2614 ieee->queue_stop = 1;
2618 void rtllib_stop_all_queues(struct rtllib_device *ieee)
2622 for (i = 0; i < ieee->dev->num_tx_queues; i++)
2623 netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies;
2625 netif_tx_stop_all_queues(ieee->dev);
2628 void rtllib_wake_all_queues(struct rtllib_device *ieee)
2630 netif_tx_wake_all_queues(ieee->dev);
2633 inline void rtllib_randomize_cell(struct rtllib_device *ieee)
2636 random_ether_addr(ieee->current_network.bssid);
2639 /* called in user context only */
2640 void rtllib_start_master_bss(struct rtllib_device *ieee)
2644 if (ieee->current_network.ssid_len == 0) {
2645 strncpy(ieee->current_network.ssid,
2646 RTLLIB_DEFAULT_TX_ESSID,
2649 ieee->current_network.ssid_len =
2650 strlen(RTLLIB_DEFAULT_TX_ESSID);
2654 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2656 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2657 ieee->state = RTLLIB_LINKED;
2658 ieee->link_change(ieee->dev);
2659 notify_wx_assoc_event(ieee);
2661 if (ieee->data_hard_resume)
2662 ieee->data_hard_resume(ieee->dev);
2664 netif_carrier_on(ieee->dev);
2667 static void rtllib_start_monitor_mode(struct rtllib_device *ieee)
2669 /* reset hardware status */
2671 if (ieee->data_hard_resume)
2672 ieee->data_hard_resume(ieee->dev);
2674 netif_carrier_on(ieee->dev);
2678 static void rtllib_start_ibss_wq(void *data)
2680 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2681 struct rtllib_device, start_ibss_wq);
2682 /* iwconfig mode ad-hoc will schedule this and return
2683 * on the other hand this will block further iwconfig SET
2684 * operations because of the wx_sem hold.
2685 * Anyway some most set operations set a flag to speed-up
2686 * (abort) this wq (when syncro scanning) before sleeping
2689 if (!ieee->proto_started) {
2690 netdev_info(ieee->dev, "==========oh driver down return\n");
2693 down(&ieee->wx_sem);
2695 if (ieee->current_network.ssid_len == 0) {
2696 strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
2697 ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
2701 ieee->state = RTLLIB_NOLINK;
2702 ieee->mode = IEEE_G;
2703 /* check if we have this cell in our network list */
2704 rtllib_softmac_check_all_nets(ieee);
2707 /* if not then the state is not linked. Maybe the user switched to
2708 * ad-hoc mode just after being in monitor mode, or just after
2709 * being very few time in managed mode (so the card have had no
2710 * time to scan all the chans..) or we have just run up the iface
2711 * after setting ad-hoc mode. So we have to give another try..
2712 * Here, in ibss mode, should be safe to do this without extra care
2713 * (in bss mode we had to make sure no-one tried to associate when
2714 * we had just checked the ieee->state and we was going to start the
2715 * scan) because in ibss mode the rtllib_new_net function, when
2716 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2717 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2718 * scan, that will stop at the first round because it sees the state
2721 if (ieee->state == RTLLIB_NOLINK)
2722 rtllib_start_scan_syncro(ieee, 0);
2724 /* the network definitively is not here.. create a new cell */
2725 if (ieee->state == RTLLIB_NOLINK) {
2726 netdev_info(ieee->dev, "creating new IBSS cell\n");
2727 ieee->current_network.channel = ieee->IbssStartChnl;
2729 rtllib_randomize_cell(ieee);
2731 if (ieee->modulation & RTLLIB_CCK_MODULATION) {
2733 ieee->current_network.rates_len = 4;
2735 ieee->current_network.rates[0] =
2736 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB;
2737 ieee->current_network.rates[1] =
2738 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB;
2739 ieee->current_network.rates[2] =
2740 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB;
2741 ieee->current_network.rates[3] =
2742 RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB;
2745 ieee->current_network.rates_len = 0;
2747 if (ieee->modulation & RTLLIB_OFDM_MODULATION) {
2748 ieee->current_network.rates_ex_len = 8;
2750 ieee->current_network.rates_ex[0] =
2751 RTLLIB_OFDM_RATE_6MB;
2752 ieee->current_network.rates_ex[1] =
2753 RTLLIB_OFDM_RATE_9MB;
2754 ieee->current_network.rates_ex[2] =
2755 RTLLIB_OFDM_RATE_12MB;
2756 ieee->current_network.rates_ex[3] =
2757 RTLLIB_OFDM_RATE_18MB;
2758 ieee->current_network.rates_ex[4] =
2759 RTLLIB_OFDM_RATE_24MB;
2760 ieee->current_network.rates_ex[5] =
2761 RTLLIB_OFDM_RATE_36MB;
2762 ieee->current_network.rates_ex[6] =
2763 RTLLIB_OFDM_RATE_48MB;
2764 ieee->current_network.rates_ex[7] =
2765 RTLLIB_OFDM_RATE_54MB;
2769 ieee->current_network.rates_ex_len = 0;
2773 ieee->current_network.qos_data.supported = 0;
2774 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2775 ieee->current_network.mode = ieee->mode;
2776 ieee->current_network.atim_window = 0;
2777 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2780 netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode);
2781 if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G))
2782 HTUseDefaultSetting(ieee);
2784 ieee->pHTInfo->bCurrentHTSupport = false;
2786 ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS,
2787 (u8 *)(&ieee->state));
2789 ieee->state = RTLLIB_LINKED;
2790 ieee->link_change(ieee->dev);
2792 HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2793 if (ieee->LedControlHandler != NULL)
2794 ieee->LedControlHandler(ieee->dev, LED_CTL_LINK);
2796 rtllib_start_send_beacons(ieee);
2798 notify_wx_assoc_event(ieee);
2800 if (ieee->data_hard_resume)
2801 ieee->data_hard_resume(ieee->dev);
2803 netif_carrier_on(ieee->dev);
2808 inline void rtllib_start_ibss(struct rtllib_device *ieee)
2810 queue_delayed_work_rsl(ieee->wq, &ieee->start_ibss_wq,
2811 msecs_to_jiffies(150));
2814 /* this is called only in user context, with wx_sem held */
2815 void rtllib_start_bss(struct rtllib_device *ieee)
2817 unsigned long flags;
2819 if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) {
2820 if (!ieee->bGlobalDomain)
2823 /* check if we have already found the net we
2824 * are interested in (if any).
2825 * if not (we are disassociated and we are not
2826 * in associating / authenticating phase) start the background scanning.
2828 rtllib_softmac_check_all_nets(ieee);
2830 /* ensure no-one start an associating process (thus setting
2831 * the ieee->state to rtllib_ASSOCIATING) while we
2832 * have just checked it and we are going to enable scan.
2833 * The rtllib_new_net function is always called with
2834 * lock held (from both rtllib_softmac_check_all_nets and
2835 * the rx path), so we cannot be in the middle of such function
2837 spin_lock_irqsave(&ieee->lock, flags);
2839 if (ieee->state == RTLLIB_NOLINK)
2840 rtllib_start_scan(ieee);
2841 spin_unlock_irqrestore(&ieee->lock, flags);
2844 static void rtllib_link_change_wq(void *data)
2846 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2847 struct rtllib_device, link_change_wq);
2848 ieee->link_change(ieee->dev);
2850 /* called only in userspace context */
2851 void rtllib_disassociate(struct rtllib_device *ieee)
2853 netif_carrier_off(ieee->dev);
2854 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2855 rtllib_reset_queue(ieee);
2857 if (ieee->data_hard_stop)
2858 ieee->data_hard_stop(ieee->dev);
2859 if (IS_DOT11D_ENABLE(ieee))
2861 ieee->state = RTLLIB_NOLINK;
2862 ieee->is_set_key = false;
2865 queue_delayed_work_rsl(ieee->wq, &ieee->link_change_wq, 0);
2867 notify_wx_assoc_event(ieee);
2870 static void rtllib_associate_retry_wq(void *data)
2872 struct rtllib_device *ieee = container_of_dwork_rsl(data,
2873 struct rtllib_device, associate_retry_wq);
2874 unsigned long flags;
2876 down(&ieee->wx_sem);
2877 if (!ieee->proto_started)
2880 if (ieee->state != RTLLIB_ASSOCIATING_RETRY)
2883 /* until we do not set the state to RTLLIB_NOLINK
2884 * there are no possibility to have someone else trying
2885 * to start an association procedure (we get here with
2886 * ieee->state = RTLLIB_ASSOCIATING).
2887 * When we set the state to RTLLIB_NOLINK it is possible
2888 * that the RX path run an attempt to associate, but
2889 * both rtllib_softmac_check_all_nets and the
2890 * RX path works with ieee->lock held so there are no
2891 * problems. If we are still disassociated then start a scan.
2892 * the lock here is necessary to ensure no one try to start
2893 * an association procedure when we have just checked the
2894 * state and we are going to start the scan.
2896 ieee->beinretry = true;
2897 ieee->state = RTLLIB_NOLINK;
2899 rtllib_softmac_check_all_nets(ieee);
2901 spin_lock_irqsave(&ieee->lock, flags);
2903 if (ieee->state == RTLLIB_NOLINK)
2904 rtllib_start_scan(ieee);
2905 spin_unlock_irqrestore(&ieee->lock, flags);
2907 ieee->beinretry = false;
2912 struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2914 u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2916 struct sk_buff *skb;
2917 struct rtllib_probe_response *b;
2919 skb = rtllib_probe_resp(ieee, broadcast_addr);
2924 b = (struct rtllib_probe_response *) skb->data;
2925 b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON);
2931 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee)
2933 struct sk_buff *skb;
2934 struct rtllib_probe_response *b;
2936 skb = rtllib_get_beacon_(ieee);
2940 b = (struct rtllib_probe_response *) skb->data;
2941 b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2943 if (ieee->seq_ctrl[0] == 0xFFF)
2944 ieee->seq_ctrl[0] = 0;
2946 ieee->seq_ctrl[0]++;
2950 EXPORT_SYMBOL(rtllib_get_beacon);
2952 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag,
2955 rtllib_stop_scan_syncro(ieee);
2956 down(&ieee->wx_sem);
2957 rtllib_stop_protocol(ieee, shutdown);
2960 EXPORT_SYMBOL(rtllib_softmac_stop_protocol);
2963 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown)
2965 if (!ieee->proto_started)
2969 ieee->proto_started = 0;
2970 ieee->proto_stoppping = 1;
2971 if (ieee->rtllib_ips_leave != NULL)
2972 ieee->rtllib_ips_leave(ieee->dev);
2975 rtllib_stop_send_beacons(ieee);
2976 del_timer_sync(&ieee->associate_timer);
2977 cancel_delayed_work(&ieee->associate_retry_wq);
2978 cancel_delayed_work(&ieee->start_ibss_wq);
2979 cancel_delayed_work(&ieee->link_change_wq);
2980 rtllib_stop_scan(ieee);
2982 if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED)
2983 ieee->state = RTLLIB_NOLINK;
2985 if (ieee->state == RTLLIB_LINKED) {
2986 if (ieee->iw_mode == IW_MODE_INFRA)
2987 SendDisassociation(ieee, 1, WLAN_REASON_DEAUTH_LEAVING);
2988 rtllib_disassociate(ieee);
2993 ieee->proto_stoppping = 0;
2995 kfree(ieee->assocreq_ies);
2996 ieee->assocreq_ies = NULL;
2997 ieee->assocreq_ies_len = 0;
2998 kfree(ieee->assocresp_ies);
2999 ieee->assocresp_ies = NULL;
3000 ieee->assocresp_ies_len = 0;
3003 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag)
3005 down(&ieee->wx_sem);
3006 rtllib_start_protocol(ieee);
3009 EXPORT_SYMBOL(rtllib_softmac_start_protocol);
3011 void rtllib_start_protocol(struct rtllib_device *ieee)
3016 rtllib_update_active_chan_map(ieee);
3018 if (ieee->proto_started)
3021 ieee->proto_started = 1;
3023 if (ieee->current_network.channel == 0) {
3026 if (ch > MAX_CHANNEL_NUMBER)
3027 return; /* no channel found */
3028 } while (!ieee->active_channel_map[ch]);
3029 ieee->current_network.channel = ch;
3032 if (ieee->current_network.beacon_interval == 0)
3033 ieee->current_network.beacon_interval = 100;
3035 for (i = 0; i < 17; i++) {
3036 ieee->last_rxseq_num[i] = -1;
3037 ieee->last_rxfrag_num[i] = -1;
3038 ieee->last_packet_time[i] = 0;
3041 if (ieee->UpdateBeaconInterruptHandler)
3042 ieee->UpdateBeaconInterruptHandler(ieee->dev, false);
3045 /* if the user set the MAC of the ad-hoc cell and then
3046 * switch to managed mode, shall we make sure that association
3047 * attempts does not fail just because the user provide the essid
3048 * and the nic is still checking for the AP MAC ??
3050 if (ieee->iw_mode == IW_MODE_INFRA) {
3051 rtllib_start_bss(ieee);
3052 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
3053 if (ieee->UpdateBeaconInterruptHandler)
3054 ieee->UpdateBeaconInterruptHandler(ieee->dev, true);
3056 rtllib_start_ibss(ieee);
3058 } else if (ieee->iw_mode == IW_MODE_MASTER) {
3059 rtllib_start_master_bss(ieee);
3060 } else if (ieee->iw_mode == IW_MODE_MONITOR) {
3061 rtllib_start_monitor_mode(ieee);
3065 void rtllib_softmac_init(struct rtllib_device *ieee)
3069 memset(&ieee->current_network, 0, sizeof(struct rtllib_network));
3071 ieee->state = RTLLIB_NOLINK;
3072 for (i = 0; i < 5; i++)
3073 ieee->seq_ctrl[i] = 0;
3074 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
3075 if (!ieee->pDot11dInfo)
3076 RTLLIB_DEBUG(RTLLIB_DL_ERR, "can't alloc memory for DOT11D\n");
3077 ieee->LinkDetectInfo.SlotIndex = 0;
3078 ieee->LinkDetectInfo.SlotNum = 2;
3079 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3080 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
3081 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3082 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3083 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
3084 ieee->bIsAggregateFrame = false;
3086 ieee->queue_stop = 0;
3087 ieee->scanning_continue = 0;
3088 ieee->softmac_features = 0;
3091 ieee->proto_started = 0;
3092 ieee->proto_stoppping = 0;
3093 ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE;
3095 ieee->ps = RTLLIB_PS_DISABLED;
3096 ieee->sta_sleep = LPS_IS_WAKE;
3098 ieee->Regdot11HTOperationalRateSet[0] = 0xff;
3099 ieee->Regdot11HTOperationalRateSet[1] = 0xff;
3100 ieee->Regdot11HTOperationalRateSet[4] = 0x01;
3102 ieee->Regdot11TxHTOperationalRateSet[0] = 0xff;
3103 ieee->Regdot11TxHTOperationalRateSet[1] = 0xff;
3104 ieee->Regdot11TxHTOperationalRateSet[4] = 0x01;
3106 ieee->FirstIe_InScan = false;
3107 ieee->actscanning = false;
3108 ieee->beinretry = false;
3109 ieee->is_set_key = false;
3110 init_mgmt_queue(ieee);
3112 ieee->sta_edca_param[0] = 0x0000A403;
3113 ieee->sta_edca_param[1] = 0x0000A427;
3114 ieee->sta_edca_param[2] = 0x005E4342;
3115 ieee->sta_edca_param[3] = 0x002F3262;
3116 ieee->aggregation = true;
3117 ieee->enable_rx_imm_BA = true;
3118 ieee->tx_pending.txb = NULL;
3120 _setup_timer(&ieee->associate_timer,
3121 rtllib_associate_abort_cb,
3122 (unsigned long) ieee);
3124 _setup_timer(&ieee->beacon_timer,
3125 rtllib_send_beacon_cb,
3126 (unsigned long) ieee);
3129 ieee->wq = create_workqueue(DRV_NAME);
3131 INIT_DELAYED_WORK_RSL(&ieee->link_change_wq,
3132 (void *)rtllib_link_change_wq, ieee);
3133 INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq,
3134 (void *)rtllib_start_ibss_wq, ieee);
3135 INIT_WORK_RSL(&ieee->associate_complete_wq,
3136 (void *)rtllib_associate_complete_wq, ieee);
3137 INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq,
3138 (void *)rtllib_associate_procedure_wq, ieee);
3139 INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq,
3140 (void *)rtllib_softmac_scan_wq, ieee);
3141 INIT_DELAYED_WORK_RSL(&ieee->softmac_hint11d_wq,
3142 (void *)rtllib_softmac_hint11d_wq, ieee);
3143 INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq,
3144 (void *)rtllib_associate_retry_wq, ieee);
3145 INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq,
3148 sema_init(&ieee->wx_sem, 1);
3149 sema_init(&ieee->scan_sem, 1);
3150 sema_init(&ieee->ips_sem, 1);
3152 spin_lock_init(&ieee->mgmt_tx_lock);
3153 spin_lock_init(&ieee->beacon_lock);
3155 tasklet_init(&ieee->ps_task,
3156 (void(*)(unsigned long)) rtllib_sta_ps,
3157 (unsigned long)ieee);
3161 void rtllib_softmac_free(struct rtllib_device *ieee)
3163 down(&ieee->wx_sem);
3164 kfree(ieee->pDot11dInfo);
3165 ieee->pDot11dInfo = NULL;
3166 del_timer_sync(&ieee->associate_timer);
3168 cancel_delayed_work(&ieee->associate_retry_wq);
3169 destroy_workqueue(ieee->wq);
3171 tasklet_kill(&ieee->ps_task);
3174 /********************************************************
3175 * Start of WPA code. *
3176 * this is stolen from the ipw2200 driver *
3177 ********************************************************/
3180 static int rtllib_wpa_enable(struct rtllib_device *ieee, int value)
3182 /* This is called when wpa_supplicant loads and closes the driver
3185 netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling");
3186 ieee->wpa_enabled = value;
3187 memset(ieee->ap_mac_addr, 0, 6);
3192 static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie,
3195 /* make sure WPA is enabled */
3196 rtllib_wpa_enable(ieee, 1);
3198 rtllib_disassociate(ieee);
3202 static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason)
3208 case IEEE_MLME_STA_DEAUTH:
3211 case IEEE_MLME_STA_DISASSOC:
3212 rtllib_disassociate(ieee);
3216 netdev_info(ieee->dev, "Unknown MLME request: %d\n", command);
3224 static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee,
3225 struct ieee_param *param, int plen)
3229 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3230 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3233 if (param->u.wpa_ie.len) {
3234 buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
3239 kfree(ieee->wpa_ie);
3241 ieee->wpa_ie_len = param->u.wpa_ie.len;
3243 kfree(ieee->wpa_ie);
3244 ieee->wpa_ie = NULL;
3245 ieee->wpa_ie_len = 0;
3248 rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3252 #define AUTH_ALG_OPEN_SYSTEM 0x1
3253 #define AUTH_ALG_SHARED_KEY 0x2
3254 #define AUTH_ALG_LEAP 0x4
3255 static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value)
3258 struct rtllib_security sec = {
3259 .flags = SEC_AUTH_MODE,
3262 if (value & AUTH_ALG_SHARED_KEY) {
3263 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3265 ieee->auth_mode = 1;
3266 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
3267 sec.auth_mode = WLAN_AUTH_OPEN;
3269 ieee->auth_mode = 0;
3270 } else if (value & AUTH_ALG_LEAP) {
3271 sec.auth_mode = WLAN_AUTH_LEAP >> 6;
3273 ieee->auth_mode = 2;
3277 if (ieee->set_security)
3278 ieee->set_security(ieee->dev, &sec);
3283 static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value)
3286 unsigned long flags;
3289 case IEEE_PARAM_WPA_ENABLED:
3290 ret = rtllib_wpa_enable(ieee, value);
3293 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3294 ieee->tkip_countermeasures = value;
3297 case IEEE_PARAM_DROP_UNENCRYPTED:
3301 * wpa_supplicant calls set_wpa_enabled when the driver
3302 * is loaded and unloaded, regardless of if WPA is being
3303 * used. No other calls are made which can be used to
3304 * determine if encryption will be used or not prior to
3305 * association being expected. If encryption is not being
3306 * used, drop_unencrypted is set to false, else true -- we
3307 * can use this to determine if the CAP_PRIVACY_ON bit should
3310 struct rtllib_security sec = {
3311 .flags = SEC_ENABLED,
3314 ieee->drop_unencrypted = value;
3315 /* We only change SEC_LEVEL for open mode. Others
3316 * are set by ipw_wpa_set_encryption.
3319 sec.flags |= SEC_LEVEL;
3320 sec.level = SEC_LEVEL_0;
3322 sec.flags |= SEC_LEVEL;
3323 sec.level = SEC_LEVEL_1;
3325 if (ieee->set_security)
3326 ieee->set_security(ieee->dev, &sec);
3330 case IEEE_PARAM_PRIVACY_INVOKED:
3331 ieee->privacy_invoked = value;
3334 case IEEE_PARAM_AUTH_ALGS:
3335 ret = rtllib_wpa_set_auth_algs(ieee, value);
3338 case IEEE_PARAM_IEEE_802_1X:
3339 ieee->ieee802_1x = value;
3341 case IEEE_PARAM_WPAX_SELECT:
3342 spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags);
3343 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags);
3347 netdev_info(ieee->dev, "Unknown WPA param: %d\n", name);
3354 /* implementation borrowed from hostap driver */
3355 static int rtllib_wpa_set_encryption(struct rtllib_device *ieee,
3356 struct ieee_param *param, int param_len,
3360 struct lib80211_crypto_ops *ops;
3361 struct lib80211_crypt_data **crypt;
3363 struct rtllib_security sec = {
3367 param->u.crypt.err = 0;
3368 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3371 (int) ((char *) param->u.crypt.key - (char *) param) +
3372 param->u.crypt.key_len) {
3373 netdev_info(ieee->dev, "Len mismatch %d, %d\n", param_len,
3374 param->u.crypt.key_len);
3377 if (is_broadcast_ether_addr(param->sta_addr)) {
3378 if (param->u.crypt.idx >= NUM_WEP_KEYS)
3380 crypt = &ieee->crypt_info.crypt[param->u.crypt.idx];
3385 if (strcmp(param->u.crypt.alg, "none") == 0) {
3388 sec.level = SEC_LEVEL_0;
3389 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3390 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3395 sec.flags |= SEC_ENABLED;
3397 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3398 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3399 strcmp(param->u.crypt.alg, "R-TKIP"))
3400 goto skip_host_crypt;
3402 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3403 if (ops == NULL && strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3404 request_module("rtllib_crypt_wep");
3405 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3406 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3407 request_module("rtllib_crypt_tkip");
3408 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3409 } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3410 request_module("rtllib_crypt_ccmp");
3411 ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3414 netdev_info(ieee->dev, "unknown crypto alg '%s'\n",
3415 param->u.crypt.alg);
3416 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3420 if (*crypt == NULL || (*crypt)->ops != ops) {
3421 struct lib80211_crypt_data *new_crypt;
3423 lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
3425 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
3426 if (new_crypt == NULL) {
3430 new_crypt->ops = ops;
3433 new_crypt->ops->init(param->u.crypt.idx);
3435 if (new_crypt->priv == NULL) {
3437 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3445 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3446 (*crypt)->ops->set_key(param->u.crypt.key,
3447 param->u.crypt.key_len, param->u.crypt.seq,
3448 (*crypt)->priv) < 0) {
3449 netdev_info(ieee->dev, "key setting failed\n");
3450 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3456 if (param->u.crypt.set_tx) {
3457 ieee->crypt_info.tx_keyidx = param->u.crypt.idx;
3458 sec.active_key = param->u.crypt.idx;
3459 sec.flags |= SEC_ACTIVE_KEY;
3461 sec.flags &= ~SEC_ACTIVE_KEY;
3463 if (param->u.crypt.alg != NULL) {
3464 memcpy(sec.keys[param->u.crypt.idx],
3466 param->u.crypt.key_len);
3467 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3468 sec.flags |= (1 << param->u.crypt.idx);
3470 if (strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3471 sec.flags |= SEC_LEVEL;
3472 sec.level = SEC_LEVEL_1;
3473 } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3474 sec.flags |= SEC_LEVEL;
3475 sec.level = SEC_LEVEL_2;
3476 } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3477 sec.flags |= SEC_LEVEL;
3478 sec.level = SEC_LEVEL_3;
3482 if (ieee->set_security)
3483 ieee->set_security(ieee->dev, &sec);
3485 /* Do not reset port if card is in Managed mode since resetting will
3486 * generate new IEEE 802.11 authentication which may end up in looping
3487 * with IEEE 802.1X. If your hardware requires a reset after WEP
3488 * configuration (for example... Prism2), implement the reset_port in
3489 * the callbacks structures used to initialize the 802.11 stack.
3491 if (ieee->reset_on_keychange &&
3492 ieee->iw_mode != IW_MODE_INFRA &&
3494 ieee->reset_port(ieee->dev)) {
3495 netdev_info(ieee->dev, "reset_port failed\n");
3496 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3503 inline struct sk_buff *rtllib_disauth_skb(struct rtllib_network *beacon,
3504 struct rtllib_device *ieee, u16 asRsn)
3506 struct sk_buff *skb;
3507 struct rtllib_disauth *disauth;
3508 int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom;
3510 skb = dev_alloc_skb(len);
3514 skb_reserve(skb, ieee->tx_headroom);
3516 disauth = (struct rtllib_disauth *) skb_put(skb,
3517 sizeof(struct rtllib_disauth));
3518 disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH);
3519 disauth->header.duration_id = 0;
3521 memcpy(disauth->header.addr1, beacon->bssid, ETH_ALEN);
3522 memcpy(disauth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3523 memcpy(disauth->header.addr3, beacon->bssid, ETH_ALEN);
3525 disauth->reason = cpu_to_le16(asRsn);
3529 inline struct sk_buff *rtllib_disassociate_skb(struct rtllib_network *beacon,
3530 struct rtllib_device *ieee, u16 asRsn)
3532 struct sk_buff *skb;
3533 struct rtllib_disassoc *disass;
3534 int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom;
3536 skb = dev_alloc_skb(len);
3541 skb_reserve(skb, ieee->tx_headroom);
3543 disass = (struct rtllib_disassoc *) skb_put(skb,
3544 sizeof(struct rtllib_disassoc));
3545 disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC);
3546 disass->header.duration_id = 0;
3548 memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
3549 memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
3550 memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
3552 disass->reason = cpu_to_le16(asRsn);
3556 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn)
3558 struct rtllib_network *beacon = &ieee->current_network;
3559 struct sk_buff *skb;
3562 skb = rtllib_disauth_skb(beacon, ieee, asRsn);
3564 skb = rtllib_disassociate_skb(beacon, ieee, asRsn);
3567 softmac_mgmt_xmit(skb, ieee);
3570 u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
3572 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
3573 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3574 int wpa_ie_len = ieee->wpa_ie_len;
3575 struct lib80211_crypt_data *crypt;
3578 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
3579 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
3580 || (ieee->host_encrypt && crypt && crypt->ops &&
3581 (0 == strcmp(crypt->ops->name, "R-WEP")));
3584 if (encrypt && (wpa_ie_len == 0)) {
3586 } else if ((wpa_ie_len != 0)) {
3587 if (((ieee->wpa_ie[0] == 0xdd) &&
3588 (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) ||
3589 ((ieee->wpa_ie[0] == 0x30) &&
3590 (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
3591 return SEC_ALG_CCMP;
3593 return SEC_ALG_TKIP;
3595 return SEC_ALG_NONE;
3599 int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p,
3602 struct ieee_param *param;
3605 down(&ieee->wx_sem);
3607 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3612 param = memdup_user(p->pointer, p->length);
3613 if (IS_ERR(param)) {
3614 ret = PTR_ERR(param);
3618 switch (param->cmd) {
3619 case IEEE_CMD_SET_WPA_PARAM:
3620 ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name,
3621 param->u.wpa_param.value);
3624 case IEEE_CMD_SET_WPA_IE:
3625 ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length);
3628 case IEEE_CMD_SET_ENCRYPTION:
3629 ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0);
3633 ret = rtllib_wpa_mlme(ieee, param->u.mlme.command,
3634 param->u.mlme.reason_code);
3638 netdev_info(ieee->dev, "Unknown WPA supplicant request: %d\n",
3644 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3653 EXPORT_SYMBOL(rtllib_wpa_supplicant_ioctl);
3655 static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib)
3659 bool bFilterOutNonAssociatedBSSID = false;
3661 rtllib->state = RTLLIB_NOLINK;
3663 for (i = 0; i < 6; i++)
3664 rtllib->current_network.bssid[i] = 0x55;
3666 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3667 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3668 rtllib->current_network.bssid);
3669 OpMode = RT_OP_MODE_NO_LINK;
3670 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode);
3671 rtllib_stop_send_beacons(rtllib);
3673 bFilterOutNonAssociatedBSSID = false;
3674 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3675 (u8 *)(&bFilterOutNonAssociatedBSSID));
3676 notify_wx_assoc_event(rtllib);
3680 static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, u8 *asSta,
3686 RemovePeerTS(rtllib, asSta);
3688 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3689 rtllib->state = RTLLIB_NOLINK;
3691 for (i = 0; i < 6; i++)
3692 rtllib->current_network.bssid[i] = 0x22;
3693 OpMode = RT_OP_MODE_NO_LINK;
3694 rtllib->OpMode = RT_OP_MODE_NO_LINK;
3695 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS,
3697 rtllib_disassociate(rtllib);
3699 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID,
3700 rtllib->current_network.bssid);
3707 rtllib_MgntDisconnectAP(
3708 struct rtllib_device *rtllib,
3712 bool bFilterOutNonAssociatedBSSID = false;
3714 bFilterOutNonAssociatedBSSID = false;
3715 rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID,
3716 (u8 *)(&bFilterOutNonAssociatedBSSID));
3717 rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid,
3720 rtllib->state = RTLLIB_NOLINK;
3723 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn)
3725 if (rtllib->ps != RTLLIB_PS_DISABLED)
3726 rtllib->sta_wake_up(rtllib->dev);
3728 if (rtllib->state == RTLLIB_LINKED) {
3729 if (rtllib->iw_mode == IW_MODE_ADHOC)
3730 rtllib_MgntDisconnectIBSS(rtllib);
3731 if (rtllib->iw_mode == IW_MODE_INFRA)
3732 rtllib_MgntDisconnectAP(rtllib, asRsn);
3738 EXPORT_SYMBOL(rtllib_MgntDisconnect);
3740 void notify_wx_assoc_event(struct rtllib_device *ieee)
3742 union iwreq_data wrqu;
3744 if (ieee->cannot_notify)
3747 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3748 if (ieee->state == RTLLIB_LINKED)
3749 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid,
3753 netdev_info(ieee->dev, "%s(): Tell user space disconnected\n",
3755 eth_zero_addr(wrqu.ap_addr.sa_data);
3757 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3759 EXPORT_SYMBOL(notify_wx_assoc_event);