2 * Copyright (c) 2011 Espressif System.
4 * MAC80211 support module
6 #include <linux/etherdevice.h>
7 #include <linux/workqueue.h>
8 #include <linux/nl80211.h>
9 #include <linux/ieee80211.h>
10 #include <linux/slab.h>
11 #include <net/cfg80211.h>
12 #include <net/mac80211.h>
13 #include <linux/version.h>
14 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
15 #include <net/regulatory.h>
17 /* for support scan in p2p concurrent */
18 #include <../net/mac80211/ieee80211_i.h>
23 #include "esp_debug.h"
25 #include "esp_utils.h"
27 #define ESP_IEEE80211_DBG esp_dbg
29 #define GET_NEXT_SEQ(seq) (((seq) +1) & 0x0fff)
32 static u8 esp_mac_addr[ETH_ALEN * 2];
34 static u8 getaddr_index(u8 * addr, struct esp_pub *epub);
37 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
39 esp_op_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb)
40 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
42 esp_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
45 esp_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
46 #endif /* NEW_KERNEL */
48 struct esp_pub *epub = (struct esp_pub *)hw->priv;
50 ESP_IEEE80211_DBG(ESP_DBG_LOG, "%s enter\n", __func__);
51 if (!mod_support_no_txampdu() &&
52 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
53 cfg80211_get_chandef_type(&epub->hw->conf.chandef) != NL80211_CHAN_NO_HT
54 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
55 hw->conf.channel_type != NL80211_CHAN_NO_HT
57 !(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
60 struct ieee80211_tx_info * tx_info = IEEE80211_SKB_CB(skb);
61 struct ieee80211_hdr * wh = (struct ieee80211_hdr *)skb->data;
62 if(ieee80211_is_data_qos(wh->frame_control)) {
63 if(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
64 u8 tidno = ieee80211_get_qos_ctl(wh)[0] & IEEE80211_QOS_CTL_TID_MASK;
65 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
66 struct esp_node * node = esp_get_node_by_addr(epub, wh->addr1);
67 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
68 struct ieee80211_sta *sta = tx_info->control.sta;
69 struct esp_node * node = (struct esp_node *)sta->drv_priv;
71 struct esp_node * node = esp_get_node_by_addr(epub, wh->addr1);
73 struct esp_tx_tid *tid = &node->tid[tidno];
75 spin_lock_bh(&epub->tx_ampdu_lock);
76 tid->ssn = GET_NEXT_SEQ(le16_to_cpu(wh->seq_ctrl)>>4);
77 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "tidno:%u,ssn:%u\n", tidno, tid->ssn);
78 spin_unlock_bh(&epub->tx_ampdu_lock);
80 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "tx ampdu pkt, sn:%u, %u\n", le16_to_cpu(wh->seq_ctrl)>>4, skb->len);
85 #ifdef GEN_ERR_CHECKSUM
86 esp_gen_err_checksum(skb);
89 sip_tx_data_pkt_enqueue(epub, skb);
91 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
92 ieee80211_queue_work(hw, &epub->tx_work);
94 queue_work(hw->workqueue,&epub->tx_work);
96 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
101 static int esp_op_start(struct ieee80211_hw *hw)
103 struct esp_pub *epub;
105 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
108 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no hw!\n", __func__);
112 epub = (struct esp_pub *)hw->priv;
115 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no epub!\n", __func__);
118 /*add rfkill poll function*/
120 atomic_set(&epub->wl.off, 0);
121 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
122 wiphy_rfkill_start_polling(hw->wiphy);
127 static void esp_op_stop(struct ieee80211_hw *hw)
129 struct esp_pub *epub;
131 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
134 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no hw!\n", __func__);
138 epub = (struct esp_pub *)hw->priv;
141 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no epub!\n", __func__);
145 atomic_set(&epub->wl.off, 1);
147 #ifdef HOST_RESET_BUG
151 if (epub->wl.scan_req) {
152 hw_scan_done(epub, true);
153 epub->wl.scan_req=NULL;
158 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
160 static int esp_op_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
162 esp_dbg(ESP_DBG_OP, "%s\n", __func__);
167 static int esp_op_resume(struct ieee80211_hw *hw)
169 esp_dbg(ESP_DBG_OP, "%s\n", __func__);
176 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
177 static int esp_op_add_interface(struct ieee80211_hw *hw,
178 struct ieee80211_if_init_conf *conf)
180 static int esp_op_add_interface(struct ieee80211_hw *hw,
181 struct ieee80211_vif *vif)
184 struct esp_pub *epub = (struct esp_pub *)hw->priv;
185 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
186 struct ieee80211_vif *vif = conf->vif;
188 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
189 struct sip_cmd_setvif svif;
191 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
192 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter: type %d, addr %pM\n", __func__, vif->type, conf->mac_addr);
194 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter: type %d, addr %pM\n", __func__, vif->type, vif->addr);
197 memset(&svif, 0, sizeof(struct sip_cmd_setvif));
198 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
199 memcpy(svif.mac, conf->mac_addr, ETH_ALEN);
200 evif->index = svif.index = getaddr_index(conf->mac_addr, epub);
202 memcpy(svif.mac, vif->addr, ETH_ALEN);
203 evif->index = svif.index = getaddr_index(vif->addr, epub);
208 if((1 << svif.index) & epub->vif_slot){
209 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s interface %d already used\n", __func__, svif.index);
212 epub->vif_slot |= 1 << svif.index;
214 if (svif.index == ESP_PUB_MAX_VIF) {
215 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s only support MAX %d interface\n", __func__, ESP_PUB_MAX_VIF);
220 case NL80211_IFTYPE_STATION:
221 //if (svif.index == 1)
222 // vif->type = NL80211_IFTYPE_UNSPECIFIED;
223 ESP_IEEE80211_DBG(ESP_SHOW, "%s STA \n", __func__);
227 case NL80211_IFTYPE_AP:
228 ESP_IEEE80211_DBG(ESP_SHOW, "%s AP \n", __func__);
232 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
233 case NL80211_IFTYPE_P2P_CLIENT:
234 ESP_IEEE80211_DBG(ESP_SHOW, "%s P2P_CLIENT \n", __func__);
238 case NL80211_IFTYPE_P2P_GO:
239 ESP_IEEE80211_DBG(ESP_SHOW, "%s P2P_GO \n", __func__);
244 case NL80211_IFTYPE_UNSPECIFIED:
245 case NL80211_IFTYPE_ADHOC:
246 case NL80211_IFTYPE_AP_VLAN:
247 case NL80211_IFTYPE_WDS:
248 case NL80211_IFTYPE_MONITOR:
250 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s does NOT support type %d\n", __func__, vif->type);
254 sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
258 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
259 static int esp_op_change_interface(struct ieee80211_hw *hw,
260 struct ieee80211_vif *vif,
261 enum nl80211_iftype new_type, bool p2p)
263 struct esp_pub *epub = (struct esp_pub *)hw->priv;
264 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
265 struct sip_cmd_setvif svif;
266 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter,change to if:%d \n", __func__, new_type);
268 if (new_type == NL80211_IFTYPE_AP) {
269 ESP_IEEE80211_DBG(ESP_SHOW, "%s enter,change to AP \n", __func__);
272 if (vif->type != new_type) {
273 ESP_IEEE80211_DBG(ESP_SHOW, "%s type from %d to %d\n", __func__, vif->type, new_type);
276 memset(&svif, 0, sizeof(struct sip_cmd_setvif));
277 memcpy(svif.mac, vif->addr, ETH_ALEN);
278 svif.index = evif->index;
282 case NL80211_IFTYPE_STATION:
286 case NL80211_IFTYPE_AP:
290 case NL80211_IFTYPE_P2P_CLIENT:
294 case NL80211_IFTYPE_P2P_GO:
298 case NL80211_IFTYPE_UNSPECIFIED:
299 case NL80211_IFTYPE_ADHOC:
300 case NL80211_IFTYPE_AP_VLAN:
301 case NL80211_IFTYPE_WDS:
302 case NL80211_IFTYPE_MONITOR:
304 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s does NOT support type %d\n", __func__, vif->type);
307 sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
312 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
313 static void esp_op_remove_interface(struct ieee80211_hw *hw,
314 struct ieee80211_if_init_conf *conf)
316 static void esp_op_remove_interface(struct ieee80211_hw *hw,
317 struct ieee80211_vif *vif)
320 struct esp_pub *epub = (struct esp_pub *)hw->priv;
321 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
322 struct ieee80211_vif *vif = conf->vif;
324 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
325 struct sip_cmd_setvif svif;
327 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 30))
328 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM\n", __func__, conf->mac_addr);
329 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
330 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, beacon enable %x\n", __func__, conf->mac_addr, vif->bss_conf.enable_beacon);
332 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, beacon enable %x\n", __func__, vif->addr, vif->bss_conf.enable_beacon);
335 memset(&svif, 0, sizeof(struct sip_cmd_setvif));
336 svif.index = evif->index;
337 epub->vif_slot &= ~(1 << svif.index);
340 evif->beacon_interval = 0;
341 del_timer_sync(&evif->beacon_timer);
347 sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
349 /* clean up tx/rx queue */
353 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
354 static void drv_handle_beacon(unsigned long data)
356 struct ieee80211_vif *vif = (struct ieee80211_vif *) data;
357 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
358 struct sk_buff *beacon;
360 static int dbgcnt = 0;
362 if(evif->epub == NULL)
364 beacon = ieee80211_beacon_get(evif->epub->hw, vif);
366 if (beacon && !(dbgcnt++ % 600)) {
367 ESP_IEEE80211_DBG(ESP_SHOW, " beacon length:%d,fc:0x%x\n", beacon->len,
368 ((struct ieee80211_mgmt *)(beacon->data))->frame_control);
372 sip_tx_data_pkt_enqueue(evif->epub, beacon);
374 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
375 mod_timer(&evif->beacon_timer, jiffies+msecs_to_jiffies(vif->bss_conf.beacon_int));
377 mod_timer(&evif->beacon_timer, jiffies+msecs_to_jiffies(evif->beacon_interval));
379 //FIXME:the packets must be sent at home channel
380 //send buffer mcast frames
381 skb = ieee80211_get_buffered_bc(evif->epub->hw, vif);
383 sip_tx_data_pkt_enqueue(evif->epub, skb);
384 skb = ieee80211_get_buffered_bc(evif->epub->hw, vif);
388 static void init_beacon_timer(struct ieee80211_vif *vif)
390 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
392 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, evif->beacon_interval);
394 init_timer(&evif->beacon_timer); //TBD, not init here...
395 evif->beacon_timer.expires=jiffies+msecs_to_jiffies(evif->beacon_interval*1024/1000);
396 evif->beacon_timer.data = (unsigned long) vif;
397 evif->beacon_timer.function = drv_handle_beacon;
398 add_timer(&evif->beacon_timer);
403 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
404 static void init_beacon_timer(struct ieee80211_vif *vif)
406 static void init_beacon_timer(struct ieee80211_conf *conf)
409 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
410 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
411 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, vif->bss_conf.beacon_int);
413 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, conf->beacon_int);
415 init_timer(&evif->beacon_timer); //TBD, not init here...
416 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
417 evif->beacon_timer.expires=jiffies+msecs_to_jiffies(vif->bss_conf.beacon_int*102/100);
418 evif->beacon_timer.data = (unsigned long) vif;
420 evif->beacon_timer.expires=jiffies+msecs_to_jiffies(conf->beacon_int*102/100);
421 evif->beacon_timer.data = (unsigned long) conf;
423 //evif->beacon_timer.data = (unsigned long) vif;
424 evif->beacon_timer.function = drv_handle_beacon;
425 add_timer(&evif->beacon_timer);
429 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
430 static int esp_op_config(struct ieee80211_hw *hw, u32 changed)
432 static int esp_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
435 //struct ieee80211_conf *conf = &hw->conf;
437 struct esp_pub *epub = (struct esp_pub *)hw->priv;
438 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29))
439 //struct esp_vif *evif = (struct esp_vif *)epub->vif->drv_priv;
442 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
443 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter 0x%08x\n", __func__, changed);
445 if (changed&IEEE80211_CONF_CHANGE_CHANNEL) {
446 sip_send_config(epub, &hw->conf);
449 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter 0x%08x\n", __func__, conf->flags);
450 sip_send_config(epub, &hw->conf);
453 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29))
454 //evif->beacon_interval = conf->beacon_int;
455 //init_beacon_timer(epub->vif);
460 if (changed & IEEE80211_CONF_CHANGE_PS) {
461 struct esp_ps *ps = &epub->ps;
463 ps->dtim_period = conf->ps_dtim_period;
464 ps->max_sleep_period = conf->max_sleep_period;
465 esp_ps_config(epub, ps, (conf->flags & IEEE80211_CONF_PS));
471 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
472 static int esp_op_config_interface (struct ieee80211_hw *hw,
473 struct ieee80211_vif *vif,
474 struct ieee80211_if_conf *conf)
476 // assoc = 2 means AP
477 struct esp_pub *epub = (struct esp_pub *)hw->priv;
478 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
479 //struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
480 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: changed %x, bssid %pM,vif->type = %d\n", __func__, conf->changed, conf->bssid,vif->type);
483 memcpy(epub->wl.bssid, conf->bssid, ETH_ALEN);
485 memset(epub->wl.bssid, 0, ETH_ALEN);
487 if(vif->type == NL80211_IFTYPE_AP){
488 if((conf->changed & IEEE80211_IFCC_BEACON)){
489 sip_send_bss_info_update(epub, evif, (u8*)conf->bssid, 2);
490 //evif->beacon_interval = conf->beacon_int;
493 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op----1-- mode unspecified\n", __func__);
497 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op----2-- mode unspecified\n", __func__);
503 static void esp_op_bss_info_changed(struct ieee80211_hw *hw,
504 struct ieee80211_vif *vif,
505 struct ieee80211_bss_conf *info,
508 struct esp_pub *epub = (struct esp_pub *)hw->priv;
509 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
510 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
512 struct sta_info *sta;
513 struct esp_node *node;
514 struct ieee80211_ht_info *ht_info;
517 memset(addr_0,0,ETH_ALEN);
519 ESP_IEEE80211_DBG(ESP_DBG_OP,"%s enter, changed %x\n",__func__,changed);
521 if((changed & BSS_CHANGED_ASSOC) && (memcmp(epub->wl.bssid,addr_0, ETH_ALEN)))
525 node = esp_get_node_by_addr(epub, epub->wl.bssid );
526 sta = sta_info_get(container_of(hw,struct ieee80211_local,hw), epub->wl.bssid);
528 ht_info = &sta->ht_info;
529 memcpy(node->supp_rates, sta->supp_rates, sizeof(node->supp_rates));
530 memcpy(&node->ht_info.cap, &ht_info->cap, sizeof(node->ht_info.cap));
531 memcpy(&node->ht_info.ht_supported, &ht_info->ht_supported, sizeof(node->ht_info.ht_supported));
532 memcpy(&node->ht_info.ampdu_density, &ht_info->ampdu_density, sizeof(node->ht_info.ampdu_density));
533 memcpy(&node->ht_info.ampdu_factor, &ht_info->ampdu_factor, sizeof(node->ht_info.ampdu_factor));
535 memcpy(&node->aid, &info->aid, sizeof(node->aid));
537 memcpy(&node->aid, &sta->aid, sizeof(node->aid));
540 sip_send_set_sta(epub, evif->index, 1, node, vif, (u8)node->index);
543 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
544 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
547 // 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 ?
548 // 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
549 // in 2.6.27, ieee80211_bss_conf->enable_beacon don't exist, does it mean it support beacon always?
550 // 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);
551 // sdata->u.sta.bssid
553 ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: changed %x, assoc %x, bssid %pM\n", __func__, changed, info->assoc, info->bssid);
555 if (vif->type == NL80211_IFTYPE_STATION) {
556 if ((changed & BSS_CHANGED_BSSID) ||
557 ((changed & BSS_CHANGED_ASSOC) && (info->assoc)))
559 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s STA change bssid or assoc\n", __func__);
560 memcpy(epub->wl.bssid, (u8*)info->bssid, ETH_ALEN);
561 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, info->assoc);
562 } else if ((changed & BSS_CHANGED_ASSOC) && (!info->assoc)) {
563 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s STA change disassoc\n", __func__);
564 memset(epub->wl.bssid, 0, ETH_ALEN);
565 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, info->assoc);
567 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s wrong mode of STA mode\n", __func__);
569 } else if (vif->type == NL80211_IFTYPE_AP) {
570 if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
571 (changed & BSS_CHANGED_BEACON_INT)) {
572 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);
573 if (info->enable_beacon && evif->ap_up != true) {
574 evif->beacon_interval = info->beacon_int;
575 init_beacon_timer(vif);
576 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, 2);
578 } else if (!info->enable_beacon && evif->ap_up &&
579 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
580 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)
585 ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s AP disable beacon, interval is %d\n", __func__, info->beacon_int);
586 evif->beacon_interval = 0;
587 del_timer_sync(&evif->beacon_timer);
588 sip_send_bss_info_update(epub, evif, (u8*)info->bssid, 2);
593 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op mode unspecified\n", __func__);
599 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
600 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
601 static u64 esp_op_prepare_multicast(struct ieee80211_hw *hw,
602 int mc_count, struct dev_addr_list *mc_list)
604 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
609 static u64 esp_op_prepare_multicast(struct ieee80211_hw *hw,
610 struct netdev_hw_addr_list *mc_list)
612 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
617 #endif /* NEW_KERNEL && KERNEL_35 */
620 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
621 static void esp_op_configure_filter(struct ieee80211_hw *hw,
622 unsigned int changed_flags,
623 unsigned int *total_flags,
626 static void esp_op_configure_filter(struct ieee80211_hw *hw,
627 unsigned int changed_flags,
628 unsigned int *total_flags,
630 struct dev_addr_list *mc_list)
633 struct esp_pub *epub = (struct esp_pub *)hw->priv;
635 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
639 if (*total_flags & FIF_PROMISC_IN_BSS)
640 epub->rx_filter |= FIF_PROMISC_IN_BSS;
642 if (*total_flags & FIF_ALLMULTI)
643 epub->rx_filter |= FIF_ALLMULTI;
645 *total_flags = epub->rx_filter;
649 static int esp_op_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
652 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
658 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
659 static int esp_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
660 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
661 struct ieee80211_key_conf *key)
663 static int esp_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
664 const u8 *local_address,const u8 *address,
665 struct ieee80211_key_conf *key)
670 struct esp_pub *epub = (struct esp_pub *)hw->priv;
671 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
672 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
673 u8 ifidx = evif->index;
675 u8 ifidx = getaddr_index((u8 *)(local_address), epub);
677 u8 *peer_addr,isvalid;
679 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
680 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);
682 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);
685 key->flags= key->flags|IEEE80211_KEY_FLAG_GENERATE_IV;
687 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
689 if (memcmp(sta->addr, epub->wl.bssid, ETH_ALEN))
690 peer_addr = sta->addr;
692 peer_addr = epub->wl.bssid;
694 peer_addr=epub->wl.bssid;
697 peer_addr = (u8 *)address;
699 isvalid = (cmd==SET_KEY) ? 1 : 0;
701 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
702 if ((key->flags&IEEE80211_KEY_FLAG_PAIRWISE) || (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104))
704 if ((key->flags&IEEE80211_KEY_FLAG_PAIRWISE) || (key->alg == ALG_WEP))
708 for (i = 0; i < 19; i++) {
709 if (epub->hi_map[i].flag == 0) {
710 epub->hi_map[i].flag = 1;
711 key->hw_key_idx = i + 6;
712 memcpy(epub->hi_map[i].mac, peer_addr, ETH_ALEN);
717 u8 index = key->hw_key_idx - 6;
718 epub->hi_map[index].flag = 0;
719 memset(epub->hi_map[index].mac, 0, ETH_ALEN);
723 for(i = 0; i < 2; i++)
724 if (epub->low_map[ifidx][i].flag == 0) {
725 epub->low_map[ifidx][i].flag = 1;
726 key->hw_key_idx = i + ifidx * 2 + 2;
727 memcpy(epub->low_map[ifidx][i].mac, peer_addr, ETH_ALEN);
731 u8 index = key->hw_key_idx - 2 - ifidx * 2;
732 epub->low_map[ifidx][index].flag = 0;
733 memset(epub->low_map[ifidx][index].mac, 0, ETH_ALEN);
735 //key->hw_key_idx = key->keyidx + ifidx * 2 + 1;
738 if (key->hw_key_idx >= 6) {
739 /*send sub_scan task to target*/
740 //epub->wl.ptk = (cmd==SET_KEY) ? key : NULL;
742 atomic_inc(&epub->wl.ptk_cnt);
744 atomic_dec(&epub->wl.ptk_cnt);
745 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
746 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104)
748 if (key->alg == ALG_WEP)
752 atomic_inc(&epub->wl.gtk_cnt);
754 atomic_dec(&epub->wl.gtk_cnt);
757 /*send sub_scan task to target*/
759 atomic_inc(&epub->wl.gtk_cnt);
761 atomic_dec(&epub->wl.gtk_cnt);
763 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
764 if((key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104))
766 if((key->alg == ALG_WEP))
770 atomic_inc(&epub->wl.ptk_cnt);
772 atomic_dec(&epub->wl.ptk_cnt);
773 //epub->wl.ptk = (cmd==SET_KEY) ? key : NULL;
777 ret = sip_send_setkey(epub, ifidx, peer_addr, key, isvalid);
779 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
780 if((key->cipher == WLAN_CIPHER_SUITE_TKIP || key->cipher == WLAN_CIPHER_SUITE_TKIP))
782 if((key->alg == ALG_TKIP))
786 atomic_set(&epub->wl.tkip_key_set, 1);
789 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s exit\n", __func__);
793 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
794 static void esp_op_update_tkip_key(struct ieee80211_hw *hw,
795 struct ieee80211_key_conf *conf, const u8 *address,
796 u32 iv32, u16 *phase1key)
798 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
802 static void esp_op_update_tkip_key(struct ieee80211_hw *hw,
803 struct ieee80211_vif *vif,
804 struct ieee80211_key_conf *conf,
805 struct ieee80211_sta *sta,
806 u32 iv32, u16 *phase1key)
808 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
811 #endif /* KERNEL_35 NEW_KERNEL*/
814 void hw_scan_done(struct esp_pub *epub, bool aborted)
816 cancel_delayed_work_sync(&epub->scan_timeout_work);
818 ASSERT(epub->wl.scan_req != NULL);
820 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
821 ieee80211_scan_completed(epub->hw, aborted);
823 ieee80211_scan_completed(epub->hw);
825 if (test_and_clear_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags)) {
826 sip_trigger_txq_process(epub->sip);
830 static void hw_scan_timeout_report(struct work_struct *work)
832 struct esp_pub *epub =
833 container_of(work, struct esp_pub, scan_timeout_work.work);
836 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "eagle hw scan done\n");
838 if (test_and_clear_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags)) {
839 sip_trigger_txq_process(epub->sip);
841 /*check if normally complete or aborted like timeout/hw error */
842 aborted = (epub->wl.scan_req) ? true : false;
845 epub->wl.scan_req = NULL;
848 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
849 ieee80211_scan_completed(epub->hw, aborted);
851 ieee80211_scan_completed(epub->hw);
856 static void esp_op_sw_scan_start(struct ieee80211_hw *hw)
859 static void esp_op_sw_scan_complete(struct ieee80211_hw *hw)
861 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
866 static int esp_op_get_stats(struct ieee80211_hw *hw,
867 struct ieee80211_low_level_stats *stats)
869 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
874 static void esp_op_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
875 u32 *iv32, u16 *iv16)
877 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
881 static int esp_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
883 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
888 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
889 static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx, struct ieee80211_sta *sta)
891 static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx, const u8 *addr)
894 struct esp_pub *epub = (struct esp_pub *)hw->priv;
895 struct esp_node *node;
897 struct esp_tx_tid *tid;
899 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
900 struct sta_info *info = sta_info_get(container_of(hw,struct ieee80211_local,hw),(u8 *)addr);
901 struct ieee80211_ht_info *ht_info = &info->ht_info;
904 spin_lock_bh(&epub->tx_ampdu_lock);
906 if(hweight32(epub->enodes_maps[ifidx]) < ESP_PUB_MAX_STA && (i = ffz(epub->enodes_map)) < ESP_PUB_MAX_STA + 1){
907 epub->enodes_map |= (1 << i);
908 epub->enodes_maps[ifidx] |= (1 << i);
909 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
910 node = (struct esp_node *)sta->drv_priv;
911 epub->enodes[i] = node;
914 node = &epub->nodes[i];
915 epub->enodes[i] = node;
916 memcpy(node->addr, addr, ETH_ALEN);
917 memcpy(&node->aid, &info->aid, sizeof(node->aid));
918 memcpy(node->supp_rates, info->supp_rates, sizeof(node->supp_rates));
919 memcpy(&node->ht_info.cap, &ht_info->cap, sizeof(node->ht_info.cap));
920 memcpy(&node->ht_info.ht_supported, &ht_info->ht_supported, sizeof(node->ht_info.ht_supported));
921 memcpy(&node->ht_info.ampdu_factor, &ht_info->ampdu_factor, sizeof(node->ht_info.ampdu_factor));
922 memcpy(&node->ht_info.ampdu_density, &ht_info->ampdu_density, sizeof(node->ht_info.ampdu_density));
927 for(tidno = 0, tid = &node->tid[tidno]; tidno < WME_NUM_TID; tidno++) {
930 tid->state = ESP_TID_STATE_INIT;
938 spin_unlock_bh(&epub->tx_ampdu_lock);
942 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
943 static int esp_node_detach(struct ieee80211_hw *hw, u8 ifidx, struct ieee80211_sta *sta)
945 static int esp_node_detach(struct ieee80211_hw *hw, u8 ifidx, const u8 *addr)
948 struct esp_pub *epub = (struct esp_pub *)hw->priv;
951 struct esp_node *node = NULL;
953 spin_lock_bh(&epub->tx_ampdu_lock);
954 map = epub->enodes_maps[ifidx];
957 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
958 if(epub->enodes[i]->sta == sta){
959 epub->enodes[i]->sta = NULL;
961 if(memcmp(epub->enodes[i]->addr, addr, ETH_ALEN) == 0){
963 node = epub->enodes[i];
964 epub->enodes[i] = NULL;
965 epub->enodes_map &= ~(1 << i);
966 epub->enodes_maps[ifidx] &= ~(1 << i);
968 spin_unlock_bh(&epub->tx_ampdu_lock);
974 spin_unlock_bh(&epub->tx_ampdu_lock);
978 struct esp_node * esp_get_node_by_addr(struct esp_pub * epub, const u8 *addr)
982 struct esp_node *node = NULL;
985 spin_lock_bh(&epub->tx_ampdu_lock);
986 map = epub->enodes_map;
990 spin_unlock_bh(&epub->tx_ampdu_lock);
994 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
995 if(memcmp(epub->enodes[i]->sta->addr, addr, ETH_ALEN) == 0)
997 if(memcmp(epub->enodes[i]->addr, addr, ETH_ALEN) == 0)
1000 node = epub->enodes[i];
1005 spin_unlock_bh(&epub->tx_ampdu_lock);
1009 int esp_get_empty_rxampdu(struct esp_pub * epub, const u8 *addr, u8 tid)
1014 spin_lock_bh(&epub->rx_ampdu_lock);
1015 if((index = ffz(epub->rxampdu_map)) < ESP_PUB_MAX_RXAMPDU){
1016 epub->rxampdu_map |= BIT(index);
1017 epub->rxampdu_node[index] = esp_get_node_by_addr(epub, addr);
1018 epub->rxampdu_tid[index] = tid;
1022 spin_unlock_bh(&epub->rx_ampdu_lock);
1026 int esp_get_exist_rxampdu(struct esp_pub * epub, const u8 *addr, u8 tid)
1033 spin_lock_bh(&epub->rx_ampdu_lock);
1034 map = epub->rxampdu_map;
1038 spin_unlock_bh(&epub->rx_ampdu_lock);
1042 if(epub->rxampdu_tid[i] == tid &&
1043 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1044 memcmp(epub->rxampdu_node[i]->sta->addr, addr, ETH_ALEN) == 0
1046 memcmp(epub->rxampdu_node[i]->addr, addr, ETH_ALEN) == 0
1054 epub->rxampdu_map &= ~ BIT(index);
1055 spin_unlock_bh(&epub->rx_ampdu_lock);
1060 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1061 static int esp_op_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
1063 static int esp_op_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, const u8 *addr)
1066 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1067 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1069 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
1071 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1072 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, addr %pM\n", __func__, addr);
1073 index = esp_node_attach(hw, evif->index, addr);
1076 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
1077 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, sta addr %pM\n", __func__, sta->addr);
1079 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, sta addr %pM\n", __func__, vif->addr, sta->addr);
1081 index = esp_node_attach(hw, evif->index, sta);
1086 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1087 sip_send_set_sta(epub, evif->index, 1, sta, vif, (u8)index);
1089 //node = esp_get_node_by_addr(epub, addr);
1090 //sip_send_set_sta(epub, evif->index, 1, node, vif, (u8)index);
1095 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1096 static int esp_op_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
1098 static int esp_op_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, const u8 *addr)
1101 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1102 struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
1105 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1106 struct esp_node *node;
1107 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, addr %pM\n", __func__, addr);
1108 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
1109 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, sta addr %pM\n", __func__, sta->addr);
1111 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, sta addr %pM\n", __func__, vif->addr, sta->addr);
1114 //remove a connect in target
1115 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1116 index = esp_node_detach(hw, evif->index, sta);
1117 sip_send_set_sta(epub, evif->index, 0, sta, vif, (u8)index);
1119 node = esp_get_node_by_addr(epub, addr);
1120 index = esp_node_detach(hw, evif->index, addr);
1121 sip_send_set_sta(epub, evif->index, 0, node, vif, node->index);
1128 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1129 static void esp_op_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
1131 static void esp_op_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, enum sta_notify_cmd cmd, const u8 *addr)
1134 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1135 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1138 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1141 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1142 case STA_NOTIFY_ADD:
1143 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s cmd add\n", __func__);
1144 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1145 esp_op_sta_add(hw, vif, sta);
1147 memcpy(epub->wl.bssid, addr, ETH_ALEN);
1148 esp_op_sta_add(hw, vif, addr);
1152 case STA_NOTIFY_REMOVE:
1153 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1154 esp_op_sta_remove(hw, vif, sta);
1156 esp_op_sta_remove(hw, vif, addr);
1157 memset(epub->wl.bssid, 0, ETH_ALEN);
1160 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1161 case STA_NOTIFY_SLEEP:
1164 case STA_NOTIFY_AWAKE:
1166 #endif /* NEW_KERNEL */
1174 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1175 static int esp_op_conf_tx(struct ieee80211_hw *hw,
1176 struct ieee80211_vif *vif,
1178 const struct ieee80211_tx_queue_params *params)
1181 static int esp_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1182 const struct ieee80211_tx_queue_params *params)
1185 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1186 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1187 return sip_send_wmm_params(epub, queue, params);
1190 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
1191 static int esp_op_get_tx_stats(struct ieee80211_hw *hw,
1192 struct ieee80211_tx_queue_stats *stats)
1194 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1198 #endif /* !NEW_KERNEL && !KERNEL_35*/
1200 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1201 static u64 esp_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1203 static u64 esp_op_get_tsf(struct ieee80211_hw *hw)
1206 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1211 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1212 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1213 static void esp_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf)
1215 static void esp_op_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1218 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1222 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1223 static void esp_op_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1225 static void esp_op_reset_tsf(struct ieee80211_hw *hw)
1228 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1232 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
1233 static void esp_op_rfkill_poll(struct ieee80211_hw *hw)
1235 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1237 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1239 wiphy_rfkill_set_hw_state(hw->wiphy,
1240 test_bit(ESP_WL_FLAG_RFKILL, &epub->wl.flags) ? true : false);
1245 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
1246 static int esp_op_hw_scan(struct ieee80211_hw *hw,
1247 struct cfg80211_scan_request *req)
1249 static int esp_op_hw_scan(struct ieee80211_hw *hw,
1250 struct ieee80211_vif *vif,
1251 struct cfg80211_scan_request *req)
1252 #endif /* NEW_KERNEL && KERNEL_35 */
1254 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1256 bool scan_often = true;
1258 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
1260 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "scan, %d\n", req->n_ssids);
1261 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);
1262 if(req->n_ssids > 1)
1263 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);
1265 /*scan_request is keep allocate untill scan_done,record it
1266 to split request into multi sdio_cmd*/
1267 if (atomic_read(&epub->wl.off)) {
1268 esp_dbg(ESP_DBG_ERROR, "%s scan but wl off \n", __func__);
1272 if(req->n_ssids > 1){
1273 struct cfg80211_ssid *ssid2 = req->ssids + 1;
1274 if((req->ssids->ssid_len > 0 && ssid2->ssid_len > 0) || req->n_ssids > 2){
1275 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "scan ssid num: %d, ssid1:%s, ssid2:%s,not support\n", req->n_ssids,
1276 req->ssids->ssid_len == 0 ? "":(char *)req->ssids->ssid, ssid2->ssid_len == 0? "":(char *)ssid2->ssid);
1281 epub->wl.scan_req = req;
1283 for (i = 0; i < req->n_channels; i++)
1284 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "eagle hw_scan freq %d\n",
1285 req->channels[i]->center_freq);
1287 for (i = 0; i < req->n_ssids; i++) {
1288 if (req->ssids->ssid_len> 0) {
1289 req->ssids->ssid[req->ssids->ssid_len]='\0';
1290 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "scan_ssid %d:%s\n",
1291 i, req->ssids->ssid);
1296 /*in connect state, suspend tx data*/
1297 if(epub->sip->support_bgscan &&
1298 test_bit(ESP_WL_FLAG_CONNECT, &epub->wl.flags) &&
1299 req->n_channels > 0)
1302 scan_often = epub->scan_permit_valid && time_before(jiffies, epub->scan_permit);
1303 epub->scan_permit_valid = true;
1306 /* epub->scan_permit = jiffies + msecs_to_jiffies(900);
1307 set_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags);
1308 if (atomic_read(&epub->txq_stopped) == false) {
1309 atomic_set(&epub->txq_stopped, true);
1310 ieee80211_stop_queues(hw);
1314 ESP_IEEE80211_DBG(ESP_DBG_LOG, "scan too often\n");
1321 /*send sub_scan task to target*/
1322 ret = sip_send_scan(epub);
1325 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "fail to send scan_cmd\n");
1329 epub->scan_permit = jiffies + msecs_to_jiffies(900);
1330 set_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags);
1331 if (atomic_read(&epub->txq_stopped) == false) {
1332 atomic_set(&epub->txq_stopped, true);
1333 ieee80211_stop_queues(hw);
1335 /*force scan complete in case target fail to report in time*/
1336 ieee80211_queue_delayed_work(hw, &epub->scan_timeout_work, req->n_channels * HZ / 4);
1343 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1344 static int esp_op_remain_on_channel(struct ieee80211_hw *hw,
1345 struct ieee80211_channel *chan,
1346 enum nl80211_channel_type channel_type,
1349 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1351 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, center_freq = %d duration = %d\n", __func__, chan->center_freq, duration);
1352 sip_send_roc(epub, chan->center_freq, duration);
1356 static int esp_op_cancel_remain_on_channel(struct ieee80211_hw *hw)
1358 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1360 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1361 epub->roc_flags= 0; // to disable roc state
1362 sip_send_roc(epub, 0, 0);
1365 #endif /* > 2.6.38 */
1368 void esp_rocdone_process(struct ieee80211_hw *hw, struct sip_evt_roc *report)
1370 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1372 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, state = %d is_ok = %d\n", __func__, report->state, report->is_ok);
1375 if((report->state==1)&&(report->is_ok==1))
1377 epub->roc_flags=1; //flags in roc state, to fix channel, not change
1378 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1379 ieee80211_ready_on_channel(hw);
1382 else if ((report->state==0)&&(report->is_ok==1)) //roc process timeout
1384 epub->roc_flags= 0; // to disable roc state
1385 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1386 ieee80211_remain_on_channel_expired(hw);
1391 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
1392 static int esp_op_set_bitrate_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1393 const struct cfg80211_bitrate_mask *mask)
1395 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1396 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s vif->macaddr[%pM], mask[%d]\n", __func__, vif->addr, mask->control[0].legacy);
1402 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1403 void esp_op_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1405 void esp_op_flush(struct ieee80211_hw *hw, bool drop)
1409 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1412 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1413 unsigned long time = jiffies + msecs_to_jiffies(15);
1414 while(atomic_read(&epub->sip->tx_data_pkt_queued)){
1415 if(!time_before(jiffies, time)){
1418 #if !defined(FPGA_LOOPBACK) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1419 ieee80211_queue_work(epub->hw, &epub->tx_work);
1421 queue_work(epub->esp_wkq, &epub->tx_work);
1423 //sip_txq_process(epub);
1430 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1431 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1432 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1433 enum ieee80211_ampdu_mlme_action action,
1434 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1436 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1437 enum ieee80211_ampdu_mlme_action action,
1438 const u8 *addr, u16 tid, u16 *ssn)
1441 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1442 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1443 struct ieee80211_vif *vif,
1444 enum ieee80211_ampdu_mlme_action action,
1445 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1447 static int esp_op_ampdu_action(struct ieee80211_hw *hw,
1448 struct ieee80211_vif *vif,
1449 enum ieee80211_ampdu_mlme_action action,
1450 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
1453 #endif /* NEW_KERNEL && KERNEL_35 */
1455 int ret = -EOPNOTSUPP;
1456 struct esp_pub *epub = (struct esp_pub *)hw->priv;
1457 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1458 struct esp_node * node = (struct esp_node *)sta->drv_priv;
1460 struct esp_node * node = esp_get_node_by_addr(epub, addr);
1462 struct esp_tx_tid * tid_info = &node->tid[tid];
1463 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1467 ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter \n", __func__);
1469 case IEEE80211_AMPDU_TX_START:
1470 if (mod_support_no_txampdu() ||
1471 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1472 cfg80211_get_chandef_type(&epub->hw->conf.chandef) != NL80211_CHAN_NO_HT
1473 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1474 hw->conf.channel_type == NL80211_CHAN_NO_HT
1476 !(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
1481 //if (vif->p2p || vif->type != NL80211_IFTYPE_STATION)
1484 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1485 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX START, addr:%pM,tid:%u\n", __func__, addr, tid);
1487 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX START, addr:%pM,tid:%u,state:%d\n", __func__, sta->addr, tid, tid_info->state);
1489 spin_lock_bh(&epub->tx_ampdu_lock);
1490 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1491 ASSERT(tid_info->state == ESP_TID_STATE_TRIGGER);
1492 *ssn = tid_info->ssn;
1493 tid_info->state = ESP_TID_STATE_PROGRESS;
1496 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1497 ieee80211_start_tx_ba_cb_irqsafe(hw, addr, tid);
1498 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1499 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1501 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1503 spin_unlock_bh(&epub->tx_ampdu_lock);
1504 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1507 spin_lock_bh(&epub->tx_ampdu_lock);
1509 if (tid_info->state != ESP_TID_STATE_PROGRESS) {
1510 if (tid_info->state == ESP_TID_STATE_INIT) {
1511 printk(KERN_ERR "%s WIFI RESET, IGNORE\n", __func__);
1512 spin_unlock_bh(&epub->tx_ampdu_lock);
1519 tid_info->state = ESP_TID_STATE_OPERATIONAL;
1520 spin_unlock_bh(&epub->tx_ampdu_lock);
1521 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1522 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_OPERATIONAL, sta->addr, tid, node->ifidx, buf_size);
1524 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_OPERATIONAL, addr, tid, node->ifidx, buf_size);
1528 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1529 case IEEE80211_AMPDU_TX_STOP_CONT:
1531 case IEEE80211_AMPDU_TX_STOP:
1533 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1534 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX STOP, addr:%pM,tid:%u\n", __func__, addr, tid);
1536 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX STOP, addr:%pM,tid:%u,state:%d\n", __func__, sta->addr, tid, tid_info->state);
1538 spin_lock_bh(&epub->tx_ampdu_lock);
1539 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1540 if(tid_info->state == ESP_TID_STATE_WAIT_STOP)
1541 tid_info->state = ESP_TID_STATE_STOP;
1543 tid_info->state = ESP_TID_STATE_INIT;
1545 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1546 ieee80211_stop_tx_ba_cb_irqsafe(hw, addr, tid);
1547 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1548 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1550 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1552 spin_unlock_bh(&epub->tx_ampdu_lock);
1553 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1554 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_STOP, addr, tid, node->ifidx, 0);
1556 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_STOP, sta->addr, tid, node->ifidx, 0);
1559 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1560 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1561 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1562 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_STOP, sta->addr, tid, node->ifidx, 0);
1565 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1566 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1567 case IEEE80211_AMPDU_TX_OPERATIONAL:
1569 case IEEE80211_AMPDU_TX_RESUME:
1571 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s TX OPERATION, addr:%pM,tid:%u,state:%d\n", __func__, sta->addr, tid, tid_info->state);
1572 spin_lock_bh(&epub->tx_ampdu_lock);
1574 if (tid_info->state != ESP_TID_STATE_PROGRESS) {
1575 if (tid_info->state == ESP_TID_STATE_INIT) {
1576 printk(KERN_ERR "%s WIFI RESET, IGNORE\n", __func__);
1577 spin_unlock_bh(&epub->tx_ampdu_lock);
1584 tid_info->state = ESP_TID_STATE_OPERATIONAL;
1585 spin_unlock_bh(&epub->tx_ampdu_lock);
1586 ret = sip_send_ampdu_action(epub, SIP_AMPDU_TX_OPERATIONAL, sta->addr, tid, node->ifidx, buf_size);
1589 case IEEE80211_AMPDU_RX_START:
1590 if(mod_support_no_rxampdu() ||
1591 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1592 cfg80211_get_chandef_type(&epub->hw->conf.chandef) != NL80211_CHAN_NO_HT
1593 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1594 hw->conf.channel_type == NL80211_CHAN_NO_HT
1596 !(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
1602 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
1607 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
1610 || (vif->type != NL80211_IFTYPE_STATION && false)
1614 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1615 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX START %pM tid %u %u\n", __func__, addr, tid, *ssn);
1616 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_START, addr, tid, *ssn, 64);
1618 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX START %pM tid %u %u\n", __func__, sta->addr, tid, *ssn);
1619 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_START, sta->addr, tid, *ssn, 64);
1622 case IEEE80211_AMPDU_RX_STOP:
1623 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1624 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX STOP %pM tid %u\n", __func__, addr, tid);
1625 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_STOP, addr, tid, 0, 0);
1627 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s RX STOP %pM tid %u\n", __func__, sta->addr, tid);
1628 ret = sip_send_ampdu_action(epub, SIP_AMPDU_RX_STOP, sta->addr, tid, 0, 0);
1638 static int esp_op_tx_last_beacon(struct ieee80211_hw *hw)
1641 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1646 #ifdef CONFIG_NL80211_TESTMODE
1647 static int esp_op_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
1649 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
1653 #endif /* CONFIG_NL80211_TESTMODE */
1657 esp_tx_work(struct work_struct *work)
1659 struct esp_pub *epub = container_of(work, struct esp_pub, tx_work);
1661 mutex_lock(&epub->tx_mtx);
1662 sip_txq_process(epub);
1663 mutex_unlock(&epub->tx_mtx);
1666 #ifndef RX_SENDUP_SYNC
1668 static int data_pkt_dequeue_cnt = 0;
1669 static void _esp_flush_rxq(struct esp_pub *epub)
1671 struct sk_buff *skb = NULL;
1673 while ((skb = skb_dequeue(&epub->rxq))) {
1674 esp_dbg(ESP_DBG_TRACE, "%s call ieee80211_rx \n", __func__);
1675 //local_bh_disable();
1676 ieee80211_rx(epub->hw, skb);
1677 //local_bh_enable();
1682 esp_sendup_work(struct work_struct *work)
1684 struct esp_pub *epub = container_of(work, struct esp_pub, sendup_work);
1685 spin_lock_bh(&epub->rx_lock);
1686 _esp_flush_rxq(epub);
1687 spin_unlock_bh(&epub->rx_lock);
1689 #endif /* !RX_SENDUP_SYNC */
1691 static const struct ieee80211_ops esp_mac80211_ops = {
1693 .start = esp_op_start,
1694 .stop = esp_op_stop,
1695 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
1697 .suspend = esp_op_suspend,
1698 .resume = esp_op_resume,
1701 .add_interface = esp_op_add_interface,
1702 .remove_interface = esp_op_remove_interface,
1703 .config = esp_op_config,
1705 .bss_info_changed = esp_op_bss_info_changed,
1706 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
1707 .config_interface = esp_op_config_interface,
1709 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1710 .prepare_multicast = esp_op_prepare_multicast,
1712 .configure_filter = esp_op_configure_filter,
1713 .set_key = esp_op_set_key,
1714 .update_tkip_key = esp_op_update_tkip_key,
1715 //.sched_scan_start = esp_op_sched_scan_start,
1716 //.sched_scan_stop = esp_op_sched_scan_stop,
1717 .set_rts_threshold = esp_op_set_rts_threshold,
1718 .sta_notify = esp_op_sta_notify,
1719 .conf_tx = esp_op_conf_tx,
1720 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
1721 .get_tx_stats = esp_op_get_tx_stats,
1722 #endif /* KERNEL_VERSION < 2.6.35*/
1723 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
1724 .change_interface = esp_op_change_interface,
1726 .get_tsf = esp_op_get_tsf,
1727 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1728 .set_tsf = esp_op_set_tsf,
1730 .reset_tsf = esp_op_reset_tsf,
1731 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
1732 .rfkill_poll= esp_op_rfkill_poll,
1735 .hw_scan = esp_op_hw_scan,
1736 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1737 .remain_on_channel= esp_op_remain_on_channel,
1738 .cancel_remain_on_channel=esp_op_cancel_remain_on_channel,
1739 #endif /* >=2.6.38 */
1741 .ampdu_action = esp_op_ampdu_action,
1742 //.get_survey = esp_op_get_survey,
1743 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34))
1744 .sta_add = esp_op_sta_add,
1745 .sta_remove = esp_op_sta_remove,
1746 #endif /* >= 2.6.34 */
1747 #ifdef CONFIG_NL80211_TESTMODE
1748 //CFG80211_TESTMODE_CMD(esp_op_tm_cmd)
1750 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
1751 .set_bitrate_mask = esp_op_set_bitrate_mask,
1753 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34))
1754 .flush = esp_op_flush,
1758 struct esp_pub * esp_pub_alloc_mac80211(struct device *dev)
1760 struct ieee80211_hw *hw;
1761 struct esp_pub *epub;
1764 hw = ieee80211_alloc_hw(sizeof(struct esp_pub), &esp_mac80211_ops);
1767 esp_dbg(ESP_DBG_ERROR, "ieee80211 can't alloc hw!\n");
1769 return ERR_PTR(ret);
1771 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1772 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
1775 memset(epub, 0, sizeof(*epub));
1777 SET_IEEE80211_DEV(hw, dev);
1780 skb_queue_head_init(&epub->txq);
1781 skb_queue_head_init(&epub->txdoneq);
1782 skb_queue_head_init(&epub->rxq);
1784 spin_lock_init(&epub->tx_ampdu_lock);
1785 spin_lock_init(&epub->rx_ampdu_lock);
1786 spin_lock_init(&epub->tx_lock);
1787 mutex_init(&epub->tx_mtx);
1788 spin_lock_init(&epub->rx_lock);
1790 INIT_WORK(&epub->tx_work, esp_tx_work);
1791 #ifndef RX_SENDUP_SYNC
1792 INIT_WORK(&epub->sendup_work, esp_sendup_work);
1793 #endif //!RX_SENDUP_SYNC
1795 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
1796 //epub->esp_wkq = create_freezeable_workqueue("esp_wkq");
1797 epub->esp_wkq = create_singlethread_workqueue("esp_wkq");
1799 //epub->esp_wkq = create_freezable_workqueue("esp_wkq");
1800 epub->esp_wkq = create_singlethread_workqueue("esp_wkq");
1801 #endif /* NEW_KERNEL */
1803 if (epub->esp_wkq == NULL) {
1805 return ERR_PTR(ret);
1807 epub->scan_permit_valid = false;
1808 INIT_DELAYED_WORK(&epub->scan_timeout_work, hw_scan_timeout_report);
1814 int esp_pub_dealloc_mac80211(struct esp_pub *epub)
1816 set_bit(ESP_WL_FLAG_RFKILL, &epub->wl.flags);
1818 destroy_workqueue(epub->esp_wkq);
1819 mutex_destroy(&epub->tx_mtx);
1821 #ifdef ESP_NO_MAC80211
1822 free_netdev(epub->net_dev);
1823 wiphy_free(epub->wdev->wiphy);
1827 ieee80211_free_hw(epub->hw);
1835 static int esp_reg_notifier(struct wiphy *wiphy,
1836 struct regulatory_request *request)
1838 struct ieee80211_supported_band *sband;
1839 struct ieee80211_channel *ch;
1842 ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter %d\n", __func__, request->initiator
1849 /* 2G band channels */
1850 static struct ieee80211_channel esp_channels_2ghz[] = {
1851 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
1852 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
1853 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
1854 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
1855 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
1856 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
1857 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
1858 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
1859 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
1860 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
1861 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
1862 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
1863 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
1864 //{ .hw_value = 14, .center_freq = 2484, .max_power = 25 },
1868 static struct ieee80211_rate esp_rates_2ghz[] = {
1871 .hw_value = CONF_HW_BIT_RATE_1MBPS,
1872 .hw_value_short = CONF_HW_BIT_RATE_1MBPS,
1876 .hw_value = CONF_HW_BIT_RATE_2MBPS,
1877 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
1878 .flags = IEEE80211_RATE_SHORT_PREAMBLE
1882 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
1883 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
1884 .flags = IEEE80211_RATE_SHORT_PREAMBLE
1888 .hw_value = CONF_HW_BIT_RATE_11MBPS,
1889 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
1890 .flags = IEEE80211_RATE_SHORT_PREAMBLE
1894 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1895 .hw_value_short = CONF_HW_BIT_RATE_6MBPS,
1899 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1900 .hw_value_short = CONF_HW_BIT_RATE_9MBPS,
1904 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1905 .hw_value_short = CONF_HW_BIT_RATE_12MBPS,
1909 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1910 .hw_value_short = CONF_HW_BIT_RATE_18MBPS,
1914 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1915 .hw_value_short = CONF_HW_BIT_RATE_24MBPS,
1919 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1920 .hw_value_short = CONF_HW_BIT_RATE_36MBPS,
1924 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1925 .hw_value_short = CONF_HW_BIT_RATE_48MBPS,
1929 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1930 .hw_value_short = CONF_HW_BIT_RATE_54MBPS,
1935 esp_pub_init_mac80211(struct esp_pub *epub)
1937 struct ieee80211_hw *hw = epub->hw;
1939 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
1940 static const u32 cipher_suites[] = {
1941 WLAN_CIPHER_SUITE_WEP40,
1942 WLAN_CIPHER_SUITE_WEP104,
1943 WLAN_CIPHER_SUITE_TKIP,
1944 WLAN_CIPHER_SUITE_CCMP,
1948 hw->channel_change_time = 420000; /* in us */
1949 hw->max_listen_interval = 10;
1951 hw->flags = IEEE80211_HW_SIGNAL_DBM |
1952 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1953 IEEE80211_HW_HAS_RATE_CONTROL |
1954 #endif /* >= 2.6.33 */
1955 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1956 IEEE80211_HW_SUPPORTS_PS |
1958 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
1959 IEEE80211_HW_AMPDU_AGGREGATION |
1961 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
1962 //IEEE80211_HW_PS_NULLFUNC_STACK |
1963 //IEEE80211_HW_CONNECTION_MONITOR |
1964 //IEEE80211_HW_BEACON_FILTER |
1965 //IEEE80211_HW_AMPDU_AGGREGATION |
1966 //IEEE80211_HW_REPORTS_TX_ACK_STATUS;
1967 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
1968 hw->max_rx_aggregation_subframes = 0x40;
1969 hw->max_tx_aggregation_subframes = 0x40;
1970 #endif /* >= 2.6.39 */
1972 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
1973 hw->wiphy->cipher_suites = cipher_suites;
1974 hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1975 hw->wiphy->max_scan_ie_len = epub->sip->tx_blksz - sizeof(struct sip_hdr) - sizeof(struct sip_cmd_scan);
1978 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
1979 /* ONLY station for now, support P2P soon... */
1980 hw->wiphy->interface_modes =
1981 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
1982 BIT(NL80211_IFTYPE_P2P_GO) |
1983 BIT(NL80211_IFTYPE_P2P_CLIENT) |
1985 BIT(NL80211_IFTYPE_STATION) |
1986 BIT(NL80211_IFTYPE_AP);
1989 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
1990 hw->wiphy->max_scan_ssids = 2;
1991 //hw->wiphy->max_sched_scan_ssids = 16;
1992 //hw->wiphy->max_match_sets = 16;
1995 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1996 hw->wiphy->max_remain_on_channel_duration = 5000;
1999 atomic_set(&epub->wl.off, 1);
2001 epub->wl.sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
2002 epub->wl.sbands[IEEE80211_BAND_2GHZ].channels = esp_channels_2ghz;
2003 epub->wl.sbands[IEEE80211_BAND_2GHZ].bitrates = esp_rates_2ghz;
2004 epub->wl.sbands[IEEE80211_BAND_2GHZ].n_channels = ARRAY_SIZE(esp_channels_2ghz);
2005 epub->wl.sbands[IEEE80211_BAND_2GHZ].n_bitrates = ARRAY_SIZE(esp_rates_2ghz);
2006 /*add to support 11n*/
2007 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
2008 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ht_supported = true;
2009 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.cap = 0x116C;//IEEE80211_HT_CAP_RX_STBC; //IEEE80211_HT_CAP_SGI_20;
2010 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
2011 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
2012 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2014 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_factor = 1;//IEEE80211_HT_MAX_AMPDU_16K;
2015 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.ampdu_density = 0;//IEEE80211_HT_MPDU_DENSITY_NONE;
2017 memset(&epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs, 0,
2018 sizeof(epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs));
2019 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs.rx_mask[0] = 0xff;
2020 //epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs.rx_highest = 7;
2021 //epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2023 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.ht_supported = true;
2024 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.cap = 0x116C;//IEEE80211_HT_CAP_RX_STBC; //IEEE80211_HT_CAP_SGI_20;
2025 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.ampdu_factor = 1;//IEEE80211_HT_MAX_AMPDU_16K;
2026 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.ampdu_density = 0;//IEEE80211_HT_MPDU_DENSITY_NONE;
2027 memset(&epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.supp_mcs_set, 0,
2028 sizeof(epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.supp_mcs_set));
2029 epub->wl.sbands[IEEE80211_BAND_2GHZ].ht_info.supp_mcs_set[0] = 0xff;
2035 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2036 &epub->wl.sbands[IEEE80211_BAND_2GHZ];
2039 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
2041 hw->wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
2044 /* handle AC queue in f/w */
2046 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
2047 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
2050 hw->max_altrates = 4;
2053 //hw->wiphy->reg_notifier = esp_reg_notify;
2055 hw->vif_data_size = sizeof(struct esp_vif);
2056 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
2057 hw->sta_data_size = sizeof(struct esp_node);
2060 //hw->max_rx_aggregation_subframes = 8;
2064 esp_register_mac80211(struct esp_pub *epub)
2067 #ifdef P2P_CONCURRENT
2073 esp_pub_init_mac80211(epub);
2075 #ifdef P2P_CONCURRENT
2076 epub->hw->wiphy->addresses = (struct mac_address *)esp_mac_addr;
2077 memcpy(&epub->hw->wiphy->addresses[0], epub->mac_addr, ETH_ALEN);
2078 memcpy(&epub->hw->wiphy->addresses[1], epub->mac_addr, ETH_ALEN);
2079 wlan_addr = (u8 *)&epub->hw->wiphy->addresses[0];
2080 p2p_addr = (u8 *)&epub->hw->wiphy->addresses[1];
2082 for (idx = 0; idx < 64; idx++) {
2083 p2p_addr[0] = wlan_addr[0] | 0x02;
2084 p2p_addr[0] ^= idx << 2;
2085 if (strncmp(p2p_addr, wlan_addr, 6) != 0)
2089 epub->hw->wiphy->n_addresses = 2;
2092 SET_IEEE80211_PERM_ADDR(epub->hw, epub->mac_addr);
2095 ret = ieee80211_register_hw(epub->hw);
2098 ESP_IEEE80211_DBG(ESP_DBG_ERROR, "unable to register mac80211 hw: %d\n", ret);
2101 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
2102 #ifdef MAC80211_NO_CHANGE
2104 if (epub->hw->wiphy->interface_modes &
2105 (BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT))) {
2106 ret = ieee80211_if_add(hw_to_local(epub->hw), "p2p%d", NULL,
2107 NL80211_IFTYPE_STATION, NULL);
2109 wiphy_warn(epub->hw->wiphy,
2110 "Failed to add default virtual iface\n");
2118 set_bit(ESP_WL_FLAG_HW_REGISTERED, &epub->wl.flags);
2123 static u8 getaddr_index(u8 * addr, struct esp_pub *epub)
2125 #ifdef P2P_CONCURRENT
2127 for(i = 0; i < ESP_PUB_MAX_VIF; i++)
2128 if(memcmp(addr, (u8 *)&epub->hw->wiphy->addresses[i], ETH_ALEN) == 0)
2130 return ESP_PUB_MAX_VIF;