2 * Copyright (c) 2011-2014 Espressif System.
4 * MAC80211 support module
7 #include <linux/etherdevice.h>
8 #include <linux/workqueue.h>
9 #include <linux/nl80211.h>
10 #include <linux/ieee80211.h>
11 #include <linux/slab.h>
12 #include <net/cfg80211.h>
13 #include <net/mac80211.h>
14 #include <linux/version.h>
15 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
16 #include <net/regulatory.h>
18 /* for support scan in p2p concurrent */
19 #include <../net/mac80211/ieee80211_i.h>
24 #include "esp_debug.h"
26 #include "esp_utils.h"
28 #define ESP_IEEE80211_DBG esp_dbg
30 #define GET_NEXT_SEQ(seq) (((seq) +1) & 0x0fff)
33 static u8 esp_mac_addr[ETH_ALEN * 2];
35 static u8 getaddr_index(u8 * addr, struct esp_pub *epub);
38 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
40 esp_op_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb)
41 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
43 esp_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
46 esp_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
47 #endif /* NEW_KERNEL */
49 struct esp_pub *epub = (struct esp_pub *)hw->priv;
51 ESP_IEEE80211_DBG(ESP_DBG_LOG, "%s enter\n", __func__);
52 if (!mod_support_no_txampdu() &&
53 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
54 cfg80211_get_chandef_type(&epub->hw->conf.chandef) != NL80211_CHAN_NO_HT
55 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
56 hw->conf.channel_type != NL80211_CHAN_NO_HT
58 !(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
61 struct ieee80211_tx_info * tx_info = IEEE80211_SKB_CB(skb);
62 struct ieee80211_hdr * wh = (struct ieee80211_hdr *)skb->data;
63 if(ieee80211_is_data_qos(wh->frame_control)) {
64 if(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
65 u8 tidno = ieee80211_get_qos_ctl(wh)[0] & IEEE80211_QOS_CTL_TID_MASK;
66 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
67 struct esp_node * node = esp_get_node_by_addr(epub, wh->addr1);
68 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
69 struct ieee80211_sta *sta = tx_info->control.sta;
70 struct esp_node * node = (struct esp_node *)sta->drv_priv;
71 if(sta->ht_cap.ht_supported)
73 struct esp_node * node = esp_get_node_by_addr(epub, wh->addr1);
74 if(node->ht_info.ht_supported)
77 struct esp_tx_tid *tid = &node->tid[tidno];
79 spin_lock_bh(&epub->tx_ampdu_lock);
80 tid->ssn = GET_NEXT_SEQ(le16_to_cpu(wh->seq_ctrl)>>4);
81 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "tidno:%u,ssn:%u\n", tidno, tid->ssn);
82 spin_unlock_bh(&epub->tx_ampdu_lock);
85 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "tx ampdu pkt, sn:%u, %u\n", le16_to_cpu(wh->seq_ctrl)>>4, skb->len);
90 #ifdef GEN_ERR_CHECKSUM
91 esp_gen_err_checksum(skb);
94 sip_tx_data_pkt_enqueue(epub, skb);
96 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
97 ieee80211_queue_work(hw, &epub->tx_work);
99 queue_work(hw->workqueue,&epub->tx_work);
101 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
106 static int esp_op_start(struct ieee80211_hw *hw)
108 struct esp_pub *epub;
110 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
113 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no hw!\n", __func__);
117 epub = (struct esp_pub *)hw->priv;
120 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no epub!\n", __func__);
123 /*add rfkill poll function*/
125 atomic_set(&epub->wl.off, 0);
126 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
127 wiphy_rfkill_start_polling(hw->wiphy);
132 static void esp_op_stop(struct ieee80211_hw *hw)
134 struct esp_pub *epub;
136 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
139 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no hw!\n", __func__);
143 epub = (struct esp_pub *)hw->priv;
146 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no epub!\n", __func__);
150 atomic_set(&epub->wl.off, 1);
152 #ifdef HOST_RESET_BUG
156 if (epub->wl.scan_req) {
157 hw_scan_done(epub, true);
158 epub->wl.scan_req=NULL;
163 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
165 static int esp_op_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
167 esp_dbg(ESP_DBG_OP, "%s\n", __func__);
172 static int esp_op_resume(struct ieee80211_hw *hw)
174 esp_dbg(ESP_DBG_OP, "%s\n", __func__);
181 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
182 static int esp_op_add_interface(struct ieee80211_hw *hw,
183 struct ieee80211_if_init_conf *conf)
185 static int esp_op_add_interface(struct ieee80211_hw *hw,
186 struct ieee80211_vif *vif)
189 struct esp_pub *epub = (struct esp_pub *)hw->priv;
190 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
191 struct ieee80211_vif *vif = conf->vif;
193 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
194 struct sip_cmd_setvif svif;
196 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
197 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter: type %d, addr %pM\n", __func__, vif->type, conf->mac_addr);
199 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter: type %d, addr %pM\n", __func__, vif->type, vif->addr);
202 memset(&svif, 0, sizeof(struct sip_cmd_setvif));
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
204 memcpy(svif.mac, conf->mac_addr, ETH_ALEN);
205 evif->index = svif.index = getaddr_index(conf->mac_addr, epub);
207 memcpy(svif.mac, vif->addr, ETH_ALEN);
208 evif->index = svif.index = getaddr_index(vif->addr, epub);
213 if((1 << svif.index) & epub->vif_slot){
214 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s interface %d already used\n", __func__, svif.index);
217 epub->vif_slot |= 1 << svif.index;
219 if (svif.index == ESP_PUB_MAX_VIF) {
220 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s only support MAX %d interface\n", __func__, ESP_PUB_MAX_VIF);
225 case NL80211_IFTYPE_STATION:
226 //if (svif.index == 1)
227 // vif->type = NL80211_IFTYPE_UNSPECIFIED;
228 ESP_IEEE80211_DBG(ESP_SHOW, "%s STA \n", __func__);
232 case NL80211_IFTYPE_AP:
233 ESP_IEEE80211_DBG(ESP_SHOW, "%s AP \n", __func__);
237 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
238 case NL80211_IFTYPE_P2P_CLIENT:
239 ESP_IEEE80211_DBG(ESP_SHOW, "%s P2P_CLIENT \n", __func__);
243 case NL80211_IFTYPE_P2P_GO:
244 ESP_IEEE80211_DBG(ESP_SHOW, "%s P2P_GO \n", __func__);
249 case NL80211_IFTYPE_UNSPECIFIED:
250 case NL80211_IFTYPE_ADHOC:
251 case NL80211_IFTYPE_AP_VLAN:
252 case NL80211_IFTYPE_WDS:
253 case NL80211_IFTYPE_MONITOR:
255 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s does NOT support type %d\n", __func__, vif->type);
259 sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
263 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
264 static int esp_op_change_interface(struct ieee80211_hw *hw,
265 struct ieee80211_vif *vif,
266 enum nl80211_iftype new_type, bool p2p)
268 struct esp_pub *epub = (struct esp_pub *)hw->priv;
269 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
270 struct sip_cmd_setvif svif;
271 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter,change to if:%d \n", __func__, new_type);
273 if (new_type == NL80211_IFTYPE_AP) {
274 ESP_IEEE80211_DBG(ESP_SHOW, "%s enter,change to AP \n", __func__);
277 if (vif->type != new_type) {
278 ESP_IEEE80211_DBG(ESP_SHOW, "%s type from %d to %d\n", __func__, vif->type, new_type);
281 memset(&svif, 0, sizeof(struct sip_cmd_setvif));
282 memcpy(svif.mac, vif->addr, ETH_ALEN);
283 svif.index = evif->index;
287 case NL80211_IFTYPE_STATION:
291 case NL80211_IFTYPE_AP:
295 case NL80211_IFTYPE_P2P_CLIENT:
299 case NL80211_IFTYPE_P2P_GO:
303 case NL80211_IFTYPE_UNSPECIFIED:
304 case NL80211_IFTYPE_ADHOC:
305 case NL80211_IFTYPE_AP_VLAN:
306 case NL80211_IFTYPE_WDS:
307 case NL80211_IFTYPE_MONITOR:
309 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s does NOT support type %d\n", __func__, vif->type);
312 sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
317 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
318 static void esp_op_remove_interface(struct ieee80211_hw *hw,
319 struct ieee80211_if_init_conf *conf)
321 static void esp_op_remove_interface(struct ieee80211_hw *hw,
322 struct ieee80211_vif *vif)
325 struct esp_pub *epub = (struct esp_pub *)hw->priv;
326 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
327 struct ieee80211_vif *vif = conf->vif;
329 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
330 struct sip_cmd_setvif svif;
332 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 30))
333 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM\n", __func__, conf->mac_addr);
334 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
335 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, beacon enable %x\n", __func__, conf->mac_addr, vif->bss_conf.enable_beacon);
337 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, beacon enable %x\n", __func__, vif->addr, vif->bss_conf.enable_beacon);
340 memset(&svif, 0, sizeof(struct sip_cmd_setvif));
341 svif.index = evif->index;
342 epub->vif_slot &= ~(1 << svif.index);
345 evif->beacon_interval = 0;
346 del_timer_sync(&evif->beacon_timer);
352 sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
354 /* clean up tx/rx queue */
358 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
359 #define BEACON_TIM_SAVE_MAX 20
360 u8 beacon_tim_saved[BEACON_TIM_SAVE_MAX];
361 int beacon_tim_count;
362 static void beacon_tim_init(void)
364 memset(beacon_tim_saved, BEACON_TIM_SAVE_MAX, 0);
365 beacon_tim_count = 0;
368 static u8 beacon_tim_save(u8 this_tim)
372 beacon_tim_saved[beacon_tim_count] = this_tim;
373 if(++beacon_tim_count >= BEACON_TIM_SAVE_MAX)
374 beacon_tim_count = 0;
375 for(i = 0; i < BEACON_TIM_SAVE_MAX; i++)
376 all_tim |= beacon_tim_saved[i];
380 static bool beacon_tim_alter(struct sk_buff *beacon)
386 struct ieee80211_mgmt * mgmt;
391 mgmt = (struct ieee80211_mgmt *)((u8 *)beacon->data);
393 remain_len = beacon->len - ((u8 *)mgmt->u.beacon.variable - (u8 *)mgmt + 12);
394 p = mgmt->u.beacon.variable;
396 while (remain_len > 0) {
398 if (*p == WLAN_EID_TIM) { // tim field
405 if((*p & 0xfe) == 0 && tim_end >= p+1){// we only support 8 sta in this case
407 *p = beacon_tim_save(*p);
409 return tim_count == 0;
412 remain_len -= (2 + len);
418 unsigned long init_jiffies;
419 unsigned long cycle_beacon_count;
420 static void drv_handle_beacon(unsigned long data)
422 struct ieee80211_vif *vif = (struct ieee80211_vif *) data;
423 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
424 struct sk_buff *beacon;
426 static int dbgcnt = 0;
427 bool tim_reach = false;
429 if(evif->epub == NULL)
432 mdelay(2400 * (cycle_beacon_count % 25) % 10000 /1000);
434 beacon = ieee80211_beacon_get(evif->epub->hw, vif);
436 tim_reach = beacon_tim_alter(beacon);
438 if (beacon && !(dbgcnt++ % 600)) {
439 ESP_IEEE80211_DBG(ESP_SHOW, " beacon length:%d,fc:0x%x\n", beacon->len,
440 ((struct ieee80211_mgmt *)(beacon->data))->frame_control);
445 sip_tx_data_pkt_enqueue(evif->epub, beacon);
447 if(cycle_beacon_count++ == 100){
448 init_jiffies = jiffies;
449 cycle_beacon_count -= 100;
451 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
452 mod_timer(&evif->beacon_timer, init_jiffies + msecs_to_jiffies(cycle_beacon_count * vif->bss_conf.beacon_int*1024/1000));
454 mod_timer(&evif->beacon_timer, init_jiffies +msecs_to_jiffies(cycle_beacon_count * evif->beacon_interval*1024/1000));
456 //FIXME:the packets must be sent at home channel
457 //send buffer mcast frames
459 skb = ieee80211_get_buffered_bc(evif->epub->hw, vif);
461 sip_tx_data_pkt_enqueue(evif->epub, skb);
462 skb = ieee80211_get_buffered_bc(evif->epub->hw, vif);
467 static void init_beacon_timer(struct ieee80211_vif *vif)
469 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
471 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, evif->beacon_interval);
474 init_timer(&evif->beacon_timer); //TBD, not init here...
475 cycle_beacon_count = 1;
476 init_jiffies = jiffies;
477 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
478 evif->beacon_timer.expires = init_jiffies + msecs_to_jiffies(cycle_beacon_count * vif->bss_conf.beacon_int*1024/1000);
480 evif->beacon_timer.expires = init_jiffies + msecs_to_jiffies(cycle_beacon_count * evif->beacon_interval*1024/1000);
482 evif->beacon_timer.data = (unsigned long) vif;
483 evif->beacon_timer.function = drv_handle_beacon;
484 add_timer(&evif->beacon_timer);
489 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
490 static void init_beacon_timer(struct ieee80211_vif *vif)
492 static void init_beacon_timer(struct ieee80211_conf *conf)
495 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
496 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
497 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, vif->bss_conf.beacon_int);
499 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, conf->beacon_int);
501 init_timer(&evif->beacon_timer); //TBD, not init here...
502 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
503 evif->beacon_timer.expires=jiffies+msecs_to_jiffies(vif->bss_conf.beacon_int*102/100);
504 evif->beacon_timer.data = (unsigned long) vif;
506 evif->beacon_timer.expires=jiffies+msecs_to_jiffies(conf->beacon_int*102/100);
507 evif->beacon_timer.data = (unsigned long) conf;
509 //evif->beacon_timer.data = (unsigned long) vif;
510 evif->beacon_timer.function = drv_handle_beacon;
511 add_timer(&evif->beacon_timer);
515 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
516 static int esp_op_config(struct ieee80211_hw *hw, u32 changed)
518 static int esp_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
521 //struct ieee80211_conf *conf = &hw->conf;
523 struct esp_pub *epub = (struct esp_pub *)hw->priv;
524 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29))
525 //struct esp_vif *evif = (struct esp_vif *)epub->vif->drv_priv;
528 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
529 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter 0x%08x\n", __func__, changed);
531 if (changed & (IEEE80211_CONF_CHANGE_CHANNEL | IEEE80211_CONF_CHANGE_IDLE)) {
532 sip_send_config(epub, &hw->conf);
535 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter 0x%08x\n", __func__, conf->flags);
536 sip_send_config(epub, &hw->conf);
539 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29))
540 //evif->beacon_interval = conf->beacon_int;
541 //init_beacon_timer(epub->vif);
546 if (changed & IEEE80211_CONF_CHANGE_PS) {
547 struct esp_ps *ps = &epub->ps;
549 ps->dtim_period = conf->ps_dtim_period;
550 ps->max_sleep_period = conf->max_sleep_period;
551 esp_ps_config(epub, ps, (conf->flags & IEEE80211_CONF_PS));
557 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
558 static int esp_op_config_interface (struct ieee80211_hw *hw,
559 struct ieee80211_vif *vif,
560 struct ieee80211_if_conf *conf)
562 // assoc = 2 means AP
563 struct esp_pub *epub = (struct esp_pub *)hw->priv;
564 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
565 //struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
566 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: changed %x, bssid %pM,vif->type = %d\n", __func__, conf->changed, conf->bssid,vif->type);
569 memcpy(epub->wl.bssid, conf->bssid, ETH_ALEN);
571 memset(epub->wl.bssid, 0, ETH_ALEN);
573 if(vif->type == NL80211_IFTYPE_AP){
574 if((conf->changed & IEEE80211_IFCC_BEACON)){
575 sip_send_bss_info_update(epub, evif, (u8*)conf->bssid, 2);
576 //evif->beacon_interval = conf->beacon_int;
579 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op----1-- mode unspecified\n", __func__);
583 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op----2-- mode unspecified\n", __func__);
589 static void esp_op_bss_info_changed(struct ieee80211_hw *hw,
590 struct ieee80211_vif *vif,
591 struct ieee80211_bss_conf *info,
594 struct esp_pub *epub = (struct esp_pub *)hw->priv;
595 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
596 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
598 struct sta_info *sta;
599 struct esp_node *node;
600 struct ieee80211_ht_info *ht_info;
603 memset(addr_0,0,ETH_ALEN);
605 ESP_IEEE80211_DBG(ESP_DBG_OP,"%s enter, changed %x\n",__func__,changed);
607 if((changed & BSS_CHANGED_ASSOC) && (memcmp(epub->wl.bssid,addr_0, ETH_ALEN)))
611 node = esp_get_node_by_addr(epub, epub->wl.bssid );
612 sta = sta_info_get(container_of(hw,struct ieee80211_local,hw), epub->wl.bssid);
614 ht_info = &sta->ht_info;
615 memcpy(node->supp_rates, sta->supp_rates, sizeof(node->supp_rates));
616 memcpy(&node->ht_info.cap, &ht_info->cap, sizeof(node->ht_info.cap));
617 memcpy(&node->ht_info.ht_supported, &ht_info->ht_supported, sizeof(node->ht_info.ht_supported));
618 memcpy(&node->ht_info.ampdu_density, &ht_info->ampdu_density, sizeof(node->ht_info.ampdu_density));
619 memcpy(&node->ht_info.ampdu_factor, &ht_info->ampdu_factor, sizeof(node->ht_info.ampdu_factor));
621 memcpy(&node->aid, &info->aid, sizeof(node->aid));
623 memcpy(&node->aid, &sta->aid, sizeof(node->aid));
626 sip_send_set_sta(epub, evif->index, 1, node, vif, (u8)node->index);
629 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
630 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
633 // ieee80211_bss_conf(include/net/mac80211.h) is included in ieee80211_sub_if_data(net/mac80211/ieee80211_i.h) , does bssid=ieee80211_if_ap's ssid ?
634 // in 2.6.27, ieee80211_sub_if_data has ieee80211_bss_conf while in 2.6.32 ieee80211_sub_if_data don't have ieee80211_bss_conf
635 // in 2.6.27, ieee80211_bss_conf->enable_beacon don't exist, does it mean it support beacon always?
636 // ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: vif addr %pM, changed %x, assoc %x, bssid %pM\n", __func__, vif->addr, changed, info->assoc, info->bssid);
637 // sdata->u.sta.bssid
639 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: changed %x, assoc %x, bssid %pM\n", __func__, changed, info->assoc, info->bssid);
641 if (vif->type == NL80211_IFTYPE_STATION) {
642 if ((changed & BSS_CHANGED_BSSID) ||
643 ((changed & BSS_CHANGED_ASSOC) && (info->assoc)))
645 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s STA change bssid or assoc\n", __func__);
646 evif->beacon_interval = info->aid;
647 memcpy(epub->wl.bssid, (u8*)info->bssid, ETH_ALEN);
648 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, info->assoc);
649 } else if ((changed & BSS_CHANGED_ASSOC) && (!info->assoc)) {
650 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s STA change disassoc\n", __func__);
651 evif->beacon_interval = 0;
652 memset(epub->wl.bssid, 0, ETH_ALEN);
653 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, info->assoc);
655 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s wrong mode of STA mode\n", __func__);
657 } else if (vif->type == NL80211_IFTYPE_AP) {
658 if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
659 (changed & BSS_CHANGED_BEACON_INT)) {
660 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s AP change enable %d, interval is %d, bssid %pM\n", __func__, info->enable_beacon, info->beacon_int, info->bssid);
661 if (info->enable_beacon && evif->ap_up != true) {
662 evif->beacon_interval = info->beacon_int;
663 init_beacon_timer(vif);
664 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, 2);
666 } else if (!info->enable_beacon && evif->ap_up &&
667 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
668 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)
673 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s AP disable beacon, interval is %d\n", __func__, info->beacon_int);
674 evif->beacon_interval = 0;
675 del_timer_sync(&evif->beacon_timer);
676 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, 2);
681 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op mode unspecified\n", __func__);
687 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
688 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
689 static u64 esp_op_prepare_multicast(struct ieee80211_hw *hw,
690 int mc_count, struct dev_addr_list *mc_list)
692 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
697 static u64 esp_op_prepare_multicast(struct ieee80211_hw *hw,
698 struct netdev_hw_addr_list *mc_list)
700 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
705 #endif /* NEW_KERNEL && KERNEL_35 */
708 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
709 static void esp_op_configure_filter(struct ieee80211_hw *hw,
710 unsigned int changed_flags,
711 unsigned int *total_flags,
714 static void esp_op_configure_filter(struct ieee80211_hw *hw,
715 unsigned int changed_flags,
716 unsigned int *total_flags,
718 struct dev_addr_list *mc_list)
721 struct esp_pub *epub = (struct esp_pub *)hw->priv;
723 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
727 if (*total_flags & FIF_PROMISC_IN_BSS)
728 epub->rx_filter |= FIF_PROMISC_IN_BSS;
730 if (*total_flags & FIF_ALLMULTI)
731 epub->rx_filter |= FIF_ALLMULTI;
733 *total_flags = epub->rx_filter;
737 static int esp_op_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
740 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
746 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
747 static int esp_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
748 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
749 struct ieee80211_key_conf *key)
751 static int esp_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
752 const u8 *local_address,const u8 *address,
753 struct ieee80211_key_conf *key)
758 struct esp_pub *epub = (struct esp_pub *)hw->priv;
759 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
760 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
761 u8 ifidx = evif->index;
763 u8 ifidx = getaddr_index((u8 *)(local_address), epub);
765 u8 *peer_addr,isvalid;
767 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
768 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, flags = %x keyindx = %x cmd = %x mac = %pM cipher = %x\n", __func__, key->flags, key->keyidx, cmd, vif->addr, key->cipher);
770 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, flags = %x keyindx = %x cmd = %x cipher = %x\n", __func__, key->flags, key->keyidx, cmd, key->alg);
773 key->flags= key->flags|IEEE80211_KEY_FLAG_GENERATE_IV;
775 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
777 if (memcmp(sta->addr, epub->wl.bssid, ETH_ALEN))
778 peer_addr = sta->addr;
780 peer_addr = epub->wl.bssid;
782 peer_addr=epub->wl.bssid;
785 peer_addr = (u8 *)address;
787 isvalid = (cmd==SET_KEY) ? 1 : 0;
789 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
790 if ((key->flags&IEEE80211_KEY_FLAG_PAIRWISE) || (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104))
792 if ((key->flags&IEEE80211_KEY_FLAG_PAIRWISE) || (key->alg == ALG_WEP))
796 for (i = 0; i < 19; i++) {
797 if (epub->hi_map[i].flag == 0) {
798 epub->hi_map[i].flag = 1;
799 key->hw_key_idx = i + 6;
800 memcpy(epub->hi_map[i].mac, peer_addr, ETH_ALEN);
805 u8 index = key->hw_key_idx - 6;
806 epub->hi_map[index].flag = 0;
807 memset(epub->hi_map[index].mac, 0, ETH_ALEN);
811 for(i = 0; i < 2; i++)
812 if (epub->low_map[ifidx][i].flag == 0) {
813 epub->low_map[ifidx][i].flag = 1;
814 key->hw_key_idx = i + ifidx * 2 + 2;
815 memcpy(epub->low_map[ifidx][i].mac, peer_addr, ETH_ALEN);
819 u8 index = key->hw_key_idx - 2 - ifidx * 2;
820 epub->low_map[ifidx][index].flag = 0;
821 memset(epub->low_map[ifidx][index].mac, 0, ETH_ALEN);
823 //key->hw_key_idx = key->keyidx + ifidx * 2 + 1;
826 if (key->hw_key_idx >= 6) {
827 /*send sub_scan task to target*/
828 //epub->wl.ptk = (cmd==SET_KEY) ? key : NULL;
830 atomic_inc(&epub->wl.ptk_cnt);
832 atomic_dec(&epub->wl.ptk_cnt);
833 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
834 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104)
836 if (key->alg == ALG_WEP)
840 atomic_inc(&epub->wl.gtk_cnt);
842 atomic_dec(&epub->wl.gtk_cnt);
845 /*send sub_scan task to target*/
847 atomic_inc(&epub->wl.gtk_cnt);
849 atomic_dec(&epub->wl.gtk_cnt);
851 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
852 if((key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104))
854 if((key->alg == ALG_WEP))
858 atomic_inc(&epub->wl.ptk_cnt);
860 atomic_dec(&epub->wl.ptk_cnt);
861 //epub->wl.ptk = (cmd==SET_KEY) ? key : NULL;
865 ret = sip_send_setkey(epub, ifidx, peer_addr, key, isvalid);
867 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
868 if((key->cipher == WLAN_CIPHER_SUITE_TKIP || key->cipher == WLAN_CIPHER_SUITE_TKIP))
870 if((key->alg == ALG_TKIP))
874 atomic_set(&epub->wl.tkip_key_set, 1);
877 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s exit\n", __func__);
881 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
882 static void esp_op_update_tkip_key(struct ieee80211_hw *hw,
883 struct ieee80211_key_conf *conf, const u8 *address,
884 u32 iv32, u16 *phase1key)
886 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
890 static void esp_op_update_tkip_key(struct ieee80211_hw *hw,
891 struct ieee80211_vif *vif,
892 struct ieee80211_key_conf *conf,
893 struct ieee80211_sta *sta,
894 u32 iv32, u16 *phase1key)
896 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
899 #endif /* KERNEL_35 NEW_KERNEL*/
902 void hw_scan_done(struct esp_pub *epub, bool aborted)
904 cancel_delayed_work_sync(&epub->scan_timeout_work);
906 ESSERT(epub->wl.scan_req != NULL);
908 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
909 ieee80211_scan_completed(epub->hw, aborted);
911 ieee80211_scan_completed(epub->hw);
913 if (test_and_clear_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags)) {
914 sip_trigger_txq_process(epub->sip);
918 static void hw_scan_timeout_report(struct work_struct *work)
920 struct esp_pub *epub =
921 container_of(work, struct esp_pub, scan_timeout_work.work);
924 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "eagle hw scan done\n");
926 if (test_and_clear_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags)) {
927 sip_trigger_txq_process(epub->sip);
929 /*check if normally complete or aborted like timeout/hw error */
930 aborted = (epub->wl.scan_req) ? true : false;
933 epub->wl.scan_req = NULL;
936 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
937 ieee80211_scan_completed(epub->hw, aborted);
939 ieee80211_scan_completed(epub->hw);
944 static void esp_op_sw_scan_start(struct ieee80211_hw *hw)
947 static void esp_op_sw_scan_complete(struct ieee80211_hw *hw)
949 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
954 static int esp_op_get_stats(struct ieee80211_hw *hw,
955 struct ieee80211_low_level_stats *stats)
957 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
962 static void esp_op_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
963 u32 *iv32, u16 *iv16)
965 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
969 static int esp_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
971 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
976 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
977 static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx, struct ieee80211_sta *sta)
979 static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx, const u8 *addr)
982 struct esp_pub *epub = (struct esp_pub *)hw->priv;
983 struct esp_node *node;
985 struct esp_tx_tid *tid;
987 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
988 struct sta_info *info = sta_info_get(container_of(hw,struct ieee80211_local,hw),(u8 *)addr);
989 struct ieee80211_ht_info *ht_info = &info->ht_info;
992 spin_lock_bh(&epub->tx_ampdu_lock);
994 if(hweight32(epub->enodes_maps[ifidx]) < ESP_PUB_MAX_STA && (i = ffz(epub->enodes_map)) < ESP_PUB_MAX_STA + 1){
995 epub->enodes_map |= (1 << i);
996 epub->enodes_maps[ifidx] |= (1 << i);
997 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
998 node = (struct esp_node *)sta->drv_priv;
999 epub->enodes[i] = node;
1002 node = &epub->nodes[i];
1003 epub->enodes[i] = node;
1004 memcpy(node->addr, addr, ETH_ALEN);
1005 memcpy(&node->aid, &info->aid, sizeof(node->aid));
1006 memcpy(node->supp_rates, info->supp_rates, sizeof(node->supp_rates));
1007 memcpy(&node->ht_info.cap, &ht_info->cap, sizeof(node->ht_info.cap));
1008 memcpy(&node->ht_info.ht_supported, &ht_info->ht_supported, sizeof(node->ht_info.ht_supported));
1009 memcpy(&node->ht_info.ampdu_factor, &ht_info->ampdu_factor, sizeof(node->ht_info.ampdu_factor));
1010 memcpy(&node->ht_info.ampdu_density, &ht_info->ampdu_density, sizeof(node->ht_info.ampdu_density));
1012 node->ifidx = ifidx;
1015 for(tidno = 0, tid = &node->tid[tidno]; tidno < WME_NUM_TID; tidno++) {
1018 tid->state = ESP_TID_STATE_INIT;
1026 spin_unlock_bh(&epub->tx_ampdu_lock);
1030 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1031 static int esp_node_detach(struct ieee80211_hw *hw, u8 ifidx, struct ieee80211_sta *sta)
1033 static int esp_node_detach(struct ieee80211_hw *hw, u8 ifidx, const u8 *addr)
1036 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1039 struct esp_node *node = NULL;
1041 spin_lock_bh(&epub->tx_ampdu_lock);
1042 map = epub->enodes_maps[ifidx];
1045 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1046 if(epub->enodes[i]->sta == sta){
1047 epub->enodes[i]->sta = NULL;
1049 if(memcmp(epub->enodes[i]->addr, addr, ETH_ALEN) == 0){
1051 node = epub->enodes[i];
1052 epub->enodes[i] = NULL;
1053 epub->enodes_map &= ~(1 << i);
1054 epub->enodes_maps[ifidx] &= ~(1 << i);
1056 spin_unlock_bh(&epub->tx_ampdu_lock);
1062 spin_unlock_bh(&epub->tx_ampdu_lock);
1066 struct esp_node * esp_get_node_by_addr(struct esp_pub * epub, const u8 *addr)
1070 struct esp_node *node = NULL;
1073 spin_lock_bh(&epub->tx_ampdu_lock);
1074 map = epub->enodes_map;
1078 spin_unlock_bh(&epub->tx_ampdu_lock);
1082 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1083 if(memcmp(epub->enodes[i]->sta->addr, addr, ETH_ALEN) == 0)
1085 if(memcmp(epub->enodes[i]->addr, addr, ETH_ALEN) == 0)
1088 node = epub->enodes[i];
1093 spin_unlock_bh(&epub->tx_ampdu_lock);
1097 struct esp_node * esp_get_node_by_index(struct esp_pub * epub, u8 index)
1100 struct esp_node *node = NULL;
1105 spin_lock_bh(&epub->tx_ampdu_lock);
1106 map = epub->enodes_map;
1107 if (map & BIT(index)) {
1108 node = epub->enodes[index];
1110 spin_unlock_bh(&epub->tx_ampdu_lock);
1114 spin_unlock_bh(&epub->tx_ampdu_lock);
1118 int esp_get_empty_rxampdu(struct esp_pub * epub, const u8 *addr, u8 tid)
1123 spin_lock_bh(&epub->rx_ampdu_lock);
1124 if((index = ffz(epub->rxampdu_map)) < ESP_PUB_MAX_RXAMPDU){
1125 epub->rxampdu_map |= BIT(index);
1126 epub->rxampdu_node[index] = esp_get_node_by_addr(epub, addr);
1127 epub->rxampdu_tid[index] = tid;
1131 spin_unlock_bh(&epub->rx_ampdu_lock);
1135 int esp_get_exist_rxampdu(struct esp_pub * epub, const u8 *addr, u8 tid)
1142 spin_lock_bh(&epub->rx_ampdu_lock);
1143 map = epub->rxampdu_map;
1147 spin_unlock_bh(&epub->rx_ampdu_lock);
1151 if(epub->rxampdu_tid[i] == tid &&
1152 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1153 memcmp(epub->rxampdu_node[i]->sta->addr, addr, ETH_ALEN) == 0
1155 memcmp(epub->rxampdu_node[i]->addr, addr, ETH_ALEN) == 0
1163 epub->rxampdu_map &= ~ BIT(index);
1164 spin_unlock_bh(&epub->rx_ampdu_lock);
1169 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1170 static int esp_op_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
1172 static int esp_op_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, const u8 *addr)
1175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1176 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1178 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
1180 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1181 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, addr %pM\n", __func__, addr);
1182 index = esp_node_attach(hw, evif->index, addr);
1185 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
1186 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, sta addr %pM\n", __func__, sta->addr);
1188 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, sta addr %pM\n", __func__, vif->addr, sta->addr);
1190 index = esp_node_attach(hw, evif->index, sta);
1195 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1196 sip_send_set_sta(epub, evif->index, 1, sta, vif, (u8)index);
1198 //node = esp_get_node_by_addr(epub, addr);
1199 //sip_send_set_sta(epub, evif->index, 1, node, vif, (u8)index);
1204 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1205 static int esp_op_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
1207 static int esp_op_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, const u8 *addr)
1210 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1211 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
1214 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1215 struct esp_node *node;
1216 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, addr %pM\n", __func__, addr);
1217 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
1218 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, sta addr %pM\n", __func__, sta->addr);
1220 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, sta addr %pM\n", __func__, vif->addr, sta->addr);
1223 //remove a connect in target
1224 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1225 index = esp_node_detach(hw, evif->index, sta);
1226 sip_send_set_sta(epub, evif->index, 0, sta, vif, (u8)index);
1228 node = esp_get_node_by_addr(epub, addr);
1229 index = esp_node_detach(hw, evif->index, addr);
1230 sip_send_set_sta(epub, evif->index, 0, node, vif, node->index);
1237 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1238 static void esp_op_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
1240 static void esp_op_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, enum sta_notify_cmd cmd, const u8 *addr)
1243 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1244 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1247 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1250 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1251 case STA_NOTIFY_ADD:
1252 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s cmd add\n", __func__);
1253 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1254 esp_op_sta_add(hw, vif, sta);
1256 memcpy(epub->wl.bssid, addr, ETH_ALEN);
1257 esp_op_sta_add(hw, vif, addr);
1261 case STA_NOTIFY_REMOVE:
1262 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1263 esp_op_sta_remove(hw, vif, sta);
1265 esp_op_sta_remove(hw, vif, addr);
1266 memset(epub->wl.bssid, 0, ETH_ALEN);
1269 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1270 case STA_NOTIFY_SLEEP:
1273 case STA_NOTIFY_AWAKE:
1275 #endif /* NEW_KERNEL */
1283 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1284 static int esp_op_conf_tx(struct ieee80211_hw *hw,
1285 struct ieee80211_vif *vif,
1287 const struct ieee80211_tx_queue_params *params)
1290 static int esp_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1291 const struct ieee80211_tx_queue_params *params)
1294 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1295 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1296 return sip_send_wmm_params(epub, queue, params);
1299 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
1300 static int esp_op_get_tx_stats(struct ieee80211_hw *hw,
1301 struct ieee80211_tx_queue_stats *stats)
1303 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1307 #endif /* !NEW_KERNEL && !KERNEL_35*/
1309 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1310 static u64 esp_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1312 static u64 esp_op_get_tsf(struct ieee80211_hw *hw)
1315 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1320 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1321 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1322 static void esp_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf)
1324 static void esp_op_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1327 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1331 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1332 static void esp_op_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1334 static void esp_op_reset_tsf(struct ieee80211_hw *hw)
1337 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1341 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
1342 static void esp_op_rfkill_poll(struct ieee80211_hw *hw)
1344 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1346 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1348 wiphy_rfkill_set_hw_state(hw->wiphy,
1349 test_bit(ESP_WL_FLAG_RFKILL, &epub->wl.flags) ? true : false);
1354 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
1355 static int esp_op_hw_scan(struct ieee80211_hw *hw,
1356 struct cfg80211_scan_request *req)
1358 static int esp_op_hw_scan(struct ieee80211_hw *hw,
1359 struct ieee80211_vif *vif,
1360 struct cfg80211_scan_request *req)
1361 #endif /* NEW_KERNEL && KERNEL_35 */
1363 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1365 bool scan_often = true;
1367 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
1369 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "scan, %d\n", req->n_ssids);
1370 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "scan, len 1:%d,ssid 1:%s\n", req->ssids->ssid_len, req->ssids->ssid_len == 0? "":(char *)req->ssids->ssid);
1371 if(req->n_ssids > 1)
1372 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "scan, len 2:%d,ssid 2:%s\n", (req->ssids+1)->ssid_len, (req->ssids+1)->ssid_len == 0? "":(char *)(req->ssids + 1)->ssid);
1374 /*scan_request is keep allocate untill scan_done,record it
1375 to split request into multi sdio_cmd*/
1376 if (atomic_read(&epub->wl.off)) {
1377 esp_dbg(ESP_DBG_ERROR, "%s scan but wl off \n", __func__);
1381 if(req->n_ssids > 1){
1382 struct cfg80211_ssid *ssid2 = req->ssids + 1;
1383 if((req->ssids->ssid_len > 0 && ssid2->ssid_len > 0) || req->n_ssids > 2){
1384 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "scan ssid num: %d, ssid1:%s, ssid2:%s,not support\n", req->n_ssids,
1385 req->ssids->ssid_len == 0 ? "":(char *)req->ssids->ssid, ssid2->ssid_len == 0? "":(char *)ssid2->ssid);
1390 epub->wl.scan_req = req;
1392 for (i = 0; i < req->n_channels; i++)
1393 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "eagle hw_scan freq %d\n",
1394 req->channels[i]->center_freq);
1396 for (i = 0; i < req->n_ssids; i++) {
1397 if (req->ssids->ssid_len> 0) {
1398 req->ssids->ssid[req->ssids->ssid_len]='\0';
1399 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "scan_ssid %d:%s\n",
1400 i, req->ssids->ssid);
1405 /*in connect state, suspend tx data*/
1406 if(epub->sip->support_bgscan &&
1407 test_bit(ESP_WL_FLAG_CONNECT, &epub->wl.flags) &&
1408 req->n_channels > 0)
1411 scan_often = epub->scan_permit_valid && time_before(jiffies, epub->scan_permit);
1412 epub->scan_permit_valid = true;
1415 /* epub->scan_permit = jiffies + msecs_to_jiffies(900);
1416 set_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags);
1417 if (atomic_read(&epub->txq_stopped) == false) {
1418 atomic_set(&epub->txq_stopped, true);
1419 ieee80211_stop_queues(hw);
1423 ESP_IEEE80211_DBG(ESP_DBG_LOG, "scan too often\n");
1430 /*send sub_scan task to target*/
1431 ret = sip_send_scan(epub);
1434 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "fail to send scan_cmd\n");
1438 epub->scan_permit = jiffies + msecs_to_jiffies(900);
1439 set_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags);
1440 if (atomic_read(&epub->txq_stopped) == false) {
1441 atomic_set(&epub->txq_stopped, true);
1442 ieee80211_stop_queues(hw);
1444 /*force scan complete in case target fail to report in time*/
1445 ieee80211_queue_delayed_work(hw, &epub->scan_timeout_work, req->n_channels * HZ / 4);
1452 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1453 static int esp_op_remain_on_channel(struct ieee80211_hw *hw,
1454 struct ieee80211_channel *chan,
1455 enum nl80211_channel_type channel_type,
1458 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1460 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, center_freq = %d duration = %d\n", __func__, chan->center_freq, duration);
1461 sip_send_roc(epub, chan->center_freq, duration);
1465 static int esp_op_cancel_remain_on_channel(struct ieee80211_hw *hw)
1467 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1469 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1470 epub->roc_flags= 0; // to disable roc state
1471 sip_send_roc(epub, 0, 0);
1474 #endif /* > 2.6.38 */
1477 void esp_rocdone_process(struct ieee80211_hw *hw, struct sip_evt_roc *report)
1479 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1481 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, state = %d is_ok = %d\n", __func__, report->state, report->is_ok);
1484 if((report->state==1)&&(report->is_ok==1))
1486 epub->roc_flags=1; //flags in roc state, to fix channel, not change
1487 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1488 ieee80211_ready_on_channel(hw);
1491 else if ((report->state==0)&&(report->is_ok==1)) //roc process timeout
1493 epub->roc_flags= 0; // to disable roc state
1494 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1495 ieee80211_remain_on_channel_expired(hw);
1500 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
1501 static int esp_op_set_bitrate_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1502 const struct cfg80211_bitrate_mask *mask)
1504 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1505 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s vif->macaddr[%pM], mask[%d]\n", __func__, vif->addr, mask->control[0].legacy);
1511 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1512 void esp_op_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1514 void esp_op_flush(struct ieee80211_hw *hw, bool drop)
1518 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1521 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1522 unsigned long time = jiffies + msecs_to_jiffies(15);
1523 while(atomic_read(&epub->sip->tx_data_pkt_queued)){
1524 if(!time_before(jiffies, time)){
1527 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
1528 if(sif_get_ate_config() == 0){
1529 ieee80211_queue_work(epub->hw, &epub->tx_work);
1531 queue_work(epub->esp_wkq, &epub->tx_work);
1534 queue_work(epub->esp_wkq, &epub->tx_work);
1536 //sip_txq_process(epub);
1543 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1544 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1545 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1546 enum ieee80211_ampdu_mlme_action action,
1547 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1549 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1550 enum ieee80211_ampdu_mlme_action action,
1551 const u8 *addr, u16 tid, u16 *ssn)
1554 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1555 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1556 struct ieee80211_vif *vif,
1557 enum ieee80211_ampdu_mlme_action action,
1558 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1560 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1561 struct ieee80211_vif *vif,
1562 enum ieee80211_ampdu_mlme_action action,
1563 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
1566 #endif /* NEW_KERNEL && KERNEL_35 */
1568 int ret = -EOPNOTSUPP;
1569 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1570 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1571 struct esp_node * node = (struct esp_node *)sta->drv_priv;
1573 struct esp_node * node = esp_get_node_by_addr(epub, addr);
1575 struct esp_tx_tid * tid_info = &node->tid[tid];
1576 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1580 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1582 case IEEE80211_AMPDU_TX_START:
1583 if (mod_support_no_txampdu() ||
1584 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1585 cfg80211_get_chandef_type(&epub->hw->conf.chandef) == NL80211_CHAN_NO_HT
1586 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1587 hw->conf.channel_type == NL80211_CHAN_NO_HT
1589 !(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
1592 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1593 !sta->ht_cap.ht_supported
1595 !node->ht_info.ht_supported
1600 //if (vif->p2p || vif->type != NL80211_IFTYPE_STATION)
1603 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1604 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX START, addr:%pM,tid:%u\n", __func__, addr, tid);
1606 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX START, addr:%pM,tid:%u,state:%d\n", __func__, sta->addr, tid, tid_info->state);
1608 spin_lock_bh(&epub->tx_ampdu_lock);
1609 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1610 ESSERT(tid_info->state == ESP_TID_STATE_TRIGGER);
1611 *ssn = tid_info->ssn;
1612 tid_info->state = ESP_TID_STATE_PROGRESS;
1615 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1616 ieee80211_start_tx_ba_cb_irqsafe(hw, addr, tid);
1617 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1618 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1620 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1622 spin_unlock_bh(&epub->tx_ampdu_lock);
1623 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1626 spin_lock_bh(&epub->tx_ampdu_lock);
1628 if (tid_info->state != ESP_TID_STATE_PROGRESS) {
1629 if (tid_info->state == ESP_TID_STATE_INIT) {
1630 printk(KERN_ERR "%s WIFI RESET, IGNORE\n", __func__);
1631 spin_unlock_bh(&epub->tx_ampdu_lock);
1638 tid_info->state = ESP_TID_STATE_OPERATIONAL;
1639 spin_unlock_bh(&epub->tx_ampdu_lock);
1640 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1641 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_OPERATIONAL, sta->addr, tid, node->ifidx, buf_size);
1643 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_OPERATIONAL, addr, tid, node->ifidx, buf_size);
1647 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1648 case IEEE80211_AMPDU_TX_STOP_CONT:
1650 case IEEE80211_AMPDU_TX_STOP:
1652 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1653 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX STOP, addr:%pM,tid:%u\n", __func__, addr, tid);
1655 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX STOP, addr:%pM,tid:%u,state:%d\n", __func__, sta->addr, tid, tid_info->state);
1657 spin_lock_bh(&epub->tx_ampdu_lock);
1658 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1659 if(tid_info->state == ESP_TID_STATE_WAIT_STOP)
1660 tid_info->state = ESP_TID_STATE_STOP;
1662 tid_info->state = ESP_TID_STATE_INIT;
1664 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1665 ieee80211_stop_tx_ba_cb_irqsafe(hw, addr, tid);
1666 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1667 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1669 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1671 spin_unlock_bh(&epub->tx_ampdu_lock);
1672 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1673 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_STOP, addr, tid, node->ifidx, 0);
1675 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_STOP, sta->addr, tid, node->ifidx, 0);
1678 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1679 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1680 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1681 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1682 if(tid_info->state == ESP_TID_STATE_WAIT_STOP)
1683 tid_info->state = ESP_TID_STATE_STOP;
1685 tid_info->state = ESP_TID_STATE_INIT;
1687 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_STOP, sta->addr, tid, node->ifidx, 0);
1690 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1691 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1692 case IEEE80211_AMPDU_TX_OPERATIONAL:
1694 case IEEE80211_AMPDU_TX_RESUME:
1696 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX OPERATION, addr:%pM,tid:%u,state:%d\n", __func__, sta->addr, tid, tid_info->state);
1697 spin_lock_bh(&epub->tx_ampdu_lock);
1699 if (tid_info->state != ESP_TID_STATE_PROGRESS) {
1700 if (tid_info->state == ESP_TID_STATE_INIT) {
1701 printk(KERN_ERR "%s WIFI RESET, IGNORE\n", __func__);
1702 spin_unlock_bh(&epub->tx_ampdu_lock);
1709 tid_info->state = ESP_TID_STATE_OPERATIONAL;
1710 spin_unlock_bh(&epub->tx_ampdu_lock);
1711 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_OPERATIONAL, sta->addr, tid, node->ifidx, buf_size);
1714 case IEEE80211_AMPDU_RX_START:
1715 if(mod_support_no_rxampdu() ||
1716 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1717 cfg80211_get_chandef_type(&epub->hw->conf.chandef) == NL80211_CHAN_NO_HT
1718 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1719 hw->conf.channel_type == NL80211_CHAN_NO_HT
1721 !(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
1724 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1725 !sta->ht_cap.ht_supported
1727 !node->ht_info.ht_supported
1733 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
1738 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1741 || (vif->type != NL80211_IFTYPE_STATION && false)
1745 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1746 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX START %pM tid %u %u\n", __func__, addr, tid, *ssn);
1747 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_START, addr, tid, *ssn, 64);
1749 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX START %pM tid %u %u\n", __func__, sta->addr, tid, *ssn);
1750 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_START, sta->addr, tid, *ssn, 64);
1753 case IEEE80211_AMPDU_RX_STOP:
1754 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1755 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX STOP %pM tid %u\n", __func__, addr, tid);
1756 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_STOP, addr, tid, 0, 0);
1758 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX STOP %pM tid %u\n", __func__, sta->addr, tid);
1759 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_STOP, sta->addr, tid, 0, 0);
1769 static int esp_op_tx_last_beacon(struct ieee80211_hw *hw)
1772 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1777 #ifdef CONFIG_NL80211_TESTMODE
1778 static int esp_op_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
1780 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1784 #endif /* CONFIG_NL80211_TESTMODE */
1788 esp_tx_work(struct work_struct *work)
1790 struct esp_pub *epub = container_of(work, struct esp_pub, tx_work);
1792 mutex_lock(&epub->tx_mtx);
1793 sip_txq_process(epub);
1794 mutex_unlock(&epub->tx_mtx);
1797 #ifndef RX_SENDUP_SYNC
1799 static int data_pkt_dequeue_cnt = 0;
1800 static void _esp_flush_rxq(struct esp_pub *epub)
1802 struct sk_buff *skb = NULL;
1804 while ((skb = skb_dequeue(&epub->rxq))) {
1805 //do not log when in spin_lock
1806 //esp_dbg(ESP_DBG_TRACE, "%s call ieee80211_rx \n", __func__);
1807 ieee80211_rx(epub->hw, skb);
1812 esp_sendup_work(struct work_struct *work)
1814 struct esp_pub *epub = container_of(work, struct esp_pub, sendup_work);
1815 spin_lock_bh(&epub->rx_lock);
1816 _esp_flush_rxq(epub);
1817 spin_unlock_bh(&epub->rx_lock);
1819 #endif /* !RX_SENDUP_SYNC */
1821 static const struct ieee80211_ops esp_mac80211_ops = {
1823 .start = esp_op_start,
1824 .stop = esp_op_stop,
1825 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
1827 .suspend = esp_op_suspend,
1828 .resume = esp_op_resume,
1831 .add_interface = esp_op_add_interface,
1832 .remove_interface = esp_op_remove_interface,
1833 .config = esp_op_config,
1835 .bss_info_changed = esp_op_bss_info_changed,
1836 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1837 .config_interface = esp_op_config_interface,
1839 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1840 .prepare_multicast = esp_op_prepare_multicast,
1842 .configure_filter = esp_op_configure_filter,
1843 .set_key = esp_op_set_key,
1844 .update_tkip_key = esp_op_update_tkip_key,
1845 //.sched_scan_start = esp_op_sched_scan_start,
1846 //.sched_scan_stop = esp_op_sched_scan_stop,
1847 .set_rts_threshold = esp_op_set_rts_threshold,
1848 .sta_notify = esp_op_sta_notify,
1849 .conf_tx = esp_op_conf_tx,
1850 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
1851 .get_tx_stats = esp_op_get_tx_stats,
1852 #endif /* KERNEL_VERSION < 2.6.35*/
1853 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
1854 .change_interface = esp_op_change_interface,
1856 .get_tsf = esp_op_get_tsf,
1857 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1858 .set_tsf = esp_op_set_tsf,
1860 .reset_tsf = esp_op_reset_tsf,
1861 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
1862 .rfkill_poll= esp_op_rfkill_poll,
1865 .hw_scan = esp_op_hw_scan,
1866 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1867 .remain_on_channel= esp_op_remain_on_channel,
1868 .cancel_remain_on_channel=esp_op_cancel_remain_on_channel,
1869 #endif /* >=2.6.38 */
1871 .ampdu_action = esp_op_ampdu_action,
1872 //.get_survey = esp_op_get_survey,
1873 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34))
1874 .sta_add = esp_op_sta_add,
1875 .sta_remove = esp_op_sta_remove,
1876 #endif /* >= 2.6.34 */
1877 #ifdef CONFIG_NL80211_TESTMODE
1878 //CFG80211_TESTMODE_CMD(esp_op_tm_cmd)
1880 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
1881 .set_bitrate_mask = esp_op_set_bitrate_mask,
1883 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34))
1884 .flush = esp_op_flush,
1888 struct esp_pub * esp_pub_alloc_mac80211(struct device *dev)
1890 struct ieee80211_hw *hw;
1891 struct esp_pub *epub;
1894 hw = ieee80211_alloc_hw(sizeof(struct esp_pub), &esp_mac80211_ops);
1897 esp_dbg(ESP_DBG_ERROR, "ieee80211 can't alloc hw!\n");
1899 return ERR_PTR(ret);
1901 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1902 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
1906 memset(epub, 0, sizeof(*epub));
1908 SET_IEEE80211_DEV(hw, dev);
1911 skb_queue_head_init(&epub->txq);
1912 skb_queue_head_init(&epub->txdoneq);
1913 skb_queue_head_init(&epub->rxq);
1915 spin_lock_init(&epub->tx_ampdu_lock);
1916 spin_lock_init(&epub->rx_ampdu_lock);
1917 spin_lock_init(&epub->tx_lock);
1918 mutex_init(&epub->tx_mtx);
1919 spin_lock_init(&epub->rx_lock);
1921 INIT_WORK(&epub->tx_work, esp_tx_work);
1922 #ifndef RX_SENDUP_SYNC
1923 INIT_WORK(&epub->sendup_work, esp_sendup_work);
1924 #endif //!RX_SENDUP_SYNC
1926 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1927 //epub->esp_wkq = create_freezeable_workqueue("esp_wkq");
1928 epub->esp_wkq = create_singlethread_workqueue("esp_wkq");
1930 //epub->esp_wkq = create_freezable_workqueue("esp_wkq");
1931 epub->esp_wkq = create_singlethread_workqueue("esp_wkq");
1932 #endif /* NEW_KERNEL */
1934 if (epub->esp_wkq == NULL) {
1936 return ERR_PTR(ret);
1938 epub->scan_permit_valid = false;
1939 INIT_DELAYED_WORK(&epub->scan_timeout_work, hw_scan_timeout_report);
1945 int esp_pub_dealloc_mac80211(struct esp_pub *epub)
1947 set_bit(ESP_WL_FLAG_RFKILL, &epub->wl.flags);
1949 destroy_workqueue(epub->esp_wkq);
1950 mutex_destroy(&epub->tx_mtx);
1952 #ifdef ESP_NO_MAC80211
1953 free_netdev(epub->net_dev);
1954 wiphy_free(epub->wdev->wiphy);
1958 ieee80211_free_hw(epub->hw);
1966 static int esp_reg_notifier(struct wiphy *wiphy,
1967 struct regulatory_request *request)
1969 struct ieee80211_supported_band *sband;
1970 struct ieee80211_channel *ch;
1973 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter %d\n", __func__, request->initiator
1980 /* 2G band channels */
1981 static struct ieee80211_channel esp_channels_2ghz[] = {
1982 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
1983 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
1984 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
1985 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
1986 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
1987 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
1988 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
1989 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
1990 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
1991 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
1992 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
1993 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
1994 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
1995 //{ .hw_value = 14, .center_freq = 2484, .max_power = 25 },
1999 static struct ieee80211_rate esp_rates_2ghz[] = {
2002 .hw_value = CONF_HW_BIT_RATE_1MBPS,
2003 .hw_value_short = CONF_HW_BIT_RATE_1MBPS,
2007 .hw_value = CONF_HW_BIT_RATE_2MBPS,
2008 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
2009 .flags = IEEE80211_RATE_SHORT_PREAMBLE
2013 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
2014 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
2015 .flags = IEEE80211_RATE_SHORT_PREAMBLE
2019 .hw_value = CONF_HW_BIT_RATE_11MBPS,
2020 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
2021 .flags = IEEE80211_RATE_SHORT_PREAMBLE
2025 .hw_value = CONF_HW_BIT_RATE_6MBPS,
2026 .hw_value_short = CONF_HW_BIT_RATE_6MBPS,
2030 .hw_value = CONF_HW_BIT_RATE_9MBPS,
2031 .hw_value_short = CONF_HW_BIT_RATE_9MBPS,
2035 .hw_value = CONF_HW_BIT_RATE_12MBPS,
2036 .hw_value_short = CONF_HW_BIT_RATE_12MBPS,
2040 .hw_value = CONF_HW_BIT_RATE_18MBPS,
2041 .hw_value_short = CONF_HW_BIT_RATE_18MBPS,
2045 .hw_value = CONF_HW_BIT_RATE_24MBPS,
2046 .hw_value_short = CONF_HW_BIT_RATE_24MBPS,
2050 .hw_value = CONF_HW_BIT_RATE_36MBPS,
2051 .hw_value_short = CONF_HW_BIT_RATE_36MBPS,
2055 .hw_value = CONF_HW_BIT_RATE_48MBPS,
2056 .hw_value_short = CONF_HW_BIT_RATE_48MBPS,
2060 .hw_value = CONF_HW_BIT_RATE_54MBPS,
2061 .hw_value_short = CONF_HW_BIT_RATE_54MBPS,
2066 esp_pub_init_mac80211(struct esp_pub *epub)
2068 struct ieee80211_hw *hw = epub->hw;
2070 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
2071 static const u32 cipher_suites[] = {
2072 WLAN_CIPHER_SUITE_WEP40,
2073 WLAN_CIPHER_SUITE_WEP104,
2074 WLAN_CIPHER_SUITE_TKIP,
2075 WLAN_CIPHER_SUITE_CCMP,
2079 hw->channel_change_time = 420000; /* in us */
2080 hw->max_listen_interval = 10;
2082 hw->flags = IEEE80211_HW_SIGNAL_DBM |
2083 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
2084 IEEE80211_HW_HAS_RATE_CONTROL |
2085 #endif /* >= 2.6.33 */
2086 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
2087 IEEE80211_HW_SUPPORTS_PS |
2089 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
2090 IEEE80211_HW_AMPDU_AGGREGATION |
2092 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
2093 //IEEE80211_HW_PS_NULLFUNC_STACK |
2094 //IEEE80211_HW_CONNECTION_MONITOR |
2095 //IEEE80211_HW_BEACON_FILTER |
2096 //IEEE80211_HW_AMPDU_AGGREGATION |
2097 //IEEE80211_HW_REPORTS_TX_ACK_STATUS;
2098 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
2099 hw->max_rx_aggregation_subframes = 0x40;
2100 hw->max_tx_aggregation_subframes = 0x40;
2101 #endif /* >= 2.6.39 */
2103 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
2104 hw->wiphy->cipher_suites = cipher_suites;
2105 hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2106 hw->wiphy->max_scan_ie_len = epub->sip->tx_blksz - sizeof(struct sip_hdr) - sizeof(struct sip_cmd_scan);
2109 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
2110 /* ONLY station for now, support P2P soon... */
2111 hw->wiphy->interface_modes =
2112 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
2113 BIT(NL80211_IFTYPE_P2P_GO) |
2114 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2116 BIT(NL80211_IFTYPE_STATION) |
2117 BIT(NL80211_IFTYPE_AP);
2120 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
2121 hw->wiphy->max_scan_ssids = 2;
2122 //hw->wiphy->max_sched_scan_ssids = 16;
2123 //hw->wiphy->max_match_sets = 16;
2126 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
2127 hw->wiphy->max_remain_on_channel_duration = 5000;
2130 atomic_set(&epub->wl.off, 1);
2132 epub->wl.sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
2133 epub->wl.sbands[IEEE80211_BAND_2GHZ].channels = esp_channels_2ghz;
2134 epub->wl.sbands[IEEE80211_BAND_2GHZ].bitrates = esp_rates_2ghz;
2135 epub->wl.sbands[IEEE80211_BAND_2GHZ].n_channels = ARRAY_SIZE(esp_channels_2ghz);
2136 epub->wl.sbands[IEEE80211_BAND_2GHZ].n_bitrates = ARRAY_SIZE(esp_rates_2ghz);
2137 /*add to support 11n*/
2138 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
2139 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ht_supported = true;
2140 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.cap = 0x116C;//IEEE80211_HT_CAP_RX_STBC; //IEEE80211_HT_CAP_SGI_20;
2141 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
2142 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
2143 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2145 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_factor = 1;//IEEE80211_HT_MAX_AMPDU_16K;
2146 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_density = 0;//IEEE80211_HT_MPDU_DENSITY_NONE;
2148 memset(&epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs, 0,
2149 sizeof(epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs));
2150 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs.rx_mask[0] = 0xff;
2151 //epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs.rx_highest = 7;
2152 //epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2154 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.ht_supported = true;
2155 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.cap = 0x116C;//IEEE80211_HT_CAP_RX_STBC; //IEEE80211_HT_CAP_SGI_20;
2156 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.ampdu_factor = 1;//IEEE80211_HT_MAX_AMPDU_16K;
2157 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.ampdu_density = 0;//IEEE80211_HT_MPDU_DENSITY_NONE;
2158 memset(&epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.supp_mcs_set, 0,
2159 sizeof(epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.supp_mcs_set));
2160 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.supp_mcs_set[0] = 0xff;
2166 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2167 &epub->wl.sbands[IEEE80211_BAND_2GHZ];
2170 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
2172 hw->wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
2175 /* handle AC queue in f/w */
2177 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
2178 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
2181 hw->max_altrates = 4;
2184 //hw->wiphy->reg_notifier = esp_reg_notify;
2186 hw->vif_data_size = sizeof(struct esp_vif);
2187 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
2188 hw->sta_data_size = sizeof(struct esp_node);
2191 //hw->max_rx_aggregation_subframes = 8;
2195 esp_register_mac80211(struct esp_pub *epub)
2198 #ifdef P2P_CONCURRENT
2204 esp_pub_init_mac80211(epub);
2206 #ifdef P2P_CONCURRENT
2207 epub->hw->wiphy->addresses = (struct mac_address *)esp_mac_addr;
2208 memcpy(&epub->hw->wiphy->addresses[0], epub->mac_addr, ETH_ALEN);
2209 memcpy(&epub->hw->wiphy->addresses[1], epub->mac_addr, ETH_ALEN);
2210 wlan_addr = (u8 *)&epub->hw->wiphy->addresses[0];
2211 p2p_addr = (u8 *)&epub->hw->wiphy->addresses[1];
2213 for (idx = 0; idx < 64; idx++) {
2214 p2p_addr[0] = wlan_addr[0] | 0x02;
2215 p2p_addr[0] ^= idx << 2;
2216 if (strncmp(p2p_addr, wlan_addr, 6) != 0)
2220 epub->hw->wiphy->n_addresses = 2;
2223 SET_IEEE80211_PERM_ADDR(epub->hw, epub->mac_addr);
2226 ret = ieee80211_register_hw(epub->hw);
2229 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "unable to register mac80211 hw: %d\n", ret);
2232 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
2233 #ifdef MAC80211_NO_CHANGE
2235 if (epub->hw->wiphy->interface_modes &
2236 (BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT))) {
2237 ret = ieee80211_if_add(hw_to_local(epub->hw), "p2p%d", NULL,
2238 NL80211_IFTYPE_STATION, NULL);
2240 wiphy_warn(epub->hw->wiphy,
2241 "Failed to add default virtual iface\n");
2249 set_bit(ESP_WL_FLAG_HW_REGISTERED, &epub->wl.flags);
2254 static u8 getaddr_index(u8 * addr, struct esp_pub *epub)
2256 #ifdef P2P_CONCURRENT
2258 for(i = 0; i < ESP_PUB_MAX_VIF; i++)
2259 if(memcmp(addr, (u8 *)&epub->hw->wiphy->addresses[i], ETH_ALEN) == 0)
2261 return ESP_PUB_MAX_VIF;