]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/rtlwifi/core.c
d6e37e6a1d53f2ee6e2f6223d36aafe3f34f195f
[karo-tx-linux.git] / drivers / net / wireless / rtlwifi / core.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012  Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <wlanfae@realtek.com>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <Larry.Finger@lwfinger.net>
27  *
28  *****************************************************************************/
29
30 #include "wifi.h"
31 #include "core.h"
32 #include "cam.h"
33 #include "base.h"
34 #include "ps.h"
35
36 /*mutex for start & stop is must here. */
37 static int rtl_op_start(struct ieee80211_hw *hw)
38 {
39         int err;
40         struct rtl_priv *rtlpriv = rtl_priv(hw);
41         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
42
43         if (!is_hal_stop(rtlhal))
44                 return 0;
45         if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
46                 return 0;
47         mutex_lock(&rtlpriv->locks.conf_mutex);
48         err = rtlpriv->intf_ops->adapter_start(hw);
49         if (!err)
50                 rtl_watch_dog_timer_callback((unsigned long)hw);
51         mutex_unlock(&rtlpriv->locks.conf_mutex);
52         return err;
53 }
54
55 static void rtl_op_stop(struct ieee80211_hw *hw)
56 {
57         struct rtl_priv *rtlpriv = rtl_priv(hw);
58         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
59         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
60         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
61
62         if (is_hal_stop(rtlhal))
63                 return;
64
65         if (unlikely(ppsc->rfpwr_state == ERFOFF)) {
66                 rtl_ips_nic_on(hw);
67                 mdelay(1);
68         }
69
70         mutex_lock(&rtlpriv->locks.conf_mutex);
71
72         mac->link_state = MAC80211_NOLINK;
73         memset(mac->bssid, 0, 6);
74         mac->vendor = PEER_UNKNOWN;
75
76         /*reset sec info */
77         rtl_cam_reset_sec_info(hw);
78
79         rtl_deinit_deferred_work(hw);
80         rtlpriv->intf_ops->adapter_stop(hw);
81
82         mutex_unlock(&rtlpriv->locks.conf_mutex);
83 }
84
85 static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
86 {
87         struct rtl_priv *rtlpriv = rtl_priv(hw);
88         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
89         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
90         struct rtl_tcb_desc tcb_desc;
91         memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
92
93         if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
94                 goto err_free;
95
96         if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
97                 goto err_free;
98
99         if (!rtlpriv->intf_ops->waitq_insert(hw, skb))
100                 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
101
102         return;
103
104 err_free:
105         dev_kfree_skb_any(skb);
106 }
107
108 static int rtl_op_add_interface(struct ieee80211_hw *hw,
109                 struct ieee80211_vif *vif)
110 {
111         struct rtl_priv *rtlpriv = rtl_priv(hw);
112         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
113         int err = 0;
114
115         if (mac->vif) {
116                 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
117                          "vif has been set!! mac->vif = 0x%p\n", mac->vif);
118                 return -EOPNOTSUPP;
119         }
120
121         rtl_ips_nic_on(hw);
122
123         mutex_lock(&rtlpriv->locks.conf_mutex);
124         switch (vif->type) {
125         case NL80211_IFTYPE_STATION:
126                 if (mac->beacon_enabled == 1) {
127                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
128                                  "NL80211_IFTYPE_STATION\n");
129                         mac->beacon_enabled = 0;
130                         rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
131                                         rtlpriv->cfg->maps
132                                         [RTL_IBSS_INT_MASKS]);
133                 }
134                 break;
135         case NL80211_IFTYPE_ADHOC:
136                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
137                          "NL80211_IFTYPE_ADHOC\n");
138
139                 mac->link_state = MAC80211_LINKED;
140                 rtlpriv->cfg->ops->set_bcn_reg(hw);
141                 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
142                         mac->basic_rates = 0xfff;
143                 else
144                         mac->basic_rates = 0xff0;
145                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
146                                 (u8 *) (&mac->basic_rates));
147
148                 break;
149         case NL80211_IFTYPE_AP:
150                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
151                          "NL80211_IFTYPE_AP\n");
152
153                 mac->link_state = MAC80211_LINKED;
154                 rtlpriv->cfg->ops->set_bcn_reg(hw);
155                 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
156                         mac->basic_rates = 0xfff;
157                 else
158                         mac->basic_rates = 0xff0;
159                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
160                                 (u8 *) (&mac->basic_rates));
161                 break;
162         default:
163                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
164                          "operation mode %d is not supported!\n", vif->type);
165                 err = -EOPNOTSUPP;
166                 goto out;
167         }
168
169         mac->vif = vif;
170         mac->opmode = vif->type;
171         rtlpriv->cfg->ops->set_network_type(hw, vif->type);
172         memcpy(mac->mac_addr, vif->addr, ETH_ALEN);
173         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
174
175 out:
176         mutex_unlock(&rtlpriv->locks.conf_mutex);
177         return err;
178 }
179
180 static void rtl_op_remove_interface(struct ieee80211_hw *hw,
181                 struct ieee80211_vif *vif)
182 {
183         struct rtl_priv *rtlpriv = rtl_priv(hw);
184         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
185
186         mutex_lock(&rtlpriv->locks.conf_mutex);
187
188         /* Free beacon resources */
189         if ((mac->opmode == NL80211_IFTYPE_AP) ||
190             (mac->opmode == NL80211_IFTYPE_ADHOC) ||
191             (mac->opmode == NL80211_IFTYPE_MESH_POINT)) {
192                 if (mac->beacon_enabled == 1) {
193                         mac->beacon_enabled = 0;
194                         rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
195                                         rtlpriv->cfg->maps
196                                         [RTL_IBSS_INT_MASKS]);
197                 }
198         }
199
200         /*
201          *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
202          *NO LINK for our hardware.
203          */
204         mac->vif = NULL;
205         mac->link_state = MAC80211_NOLINK;
206         memset(mac->bssid, 0, 6);
207         mac->vendor = PEER_UNKNOWN;
208         mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
209         rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
210         mutex_unlock(&rtlpriv->locks.conf_mutex);
211 }
212
213 static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
214 {
215         struct rtl_priv *rtlpriv = rtl_priv(hw);
216         struct rtl_phy *rtlphy = &(rtlpriv->phy);
217         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
218         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
219         struct ieee80211_conf *conf = &hw->conf;
220
221         mutex_lock(&rtlpriv->locks.conf_mutex);
222         if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {  /*BIT(2)*/
223                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
224                          "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
225         }
226
227         /*For IPS */
228         if (changed & IEEE80211_CONF_CHANGE_IDLE) {
229                 if (hw->conf.flags & IEEE80211_CONF_IDLE)
230                         rtl_ips_nic_off(hw);
231                 else
232                         rtl_ips_nic_on(hw);
233         } else {
234                 /*
235                  *although rfoff may not cause by ips, but we will
236                  *check the reason in set_rf_power_state function
237                  */
238                 if (unlikely(ppsc->rfpwr_state == ERFOFF))
239                         rtl_ips_nic_on(hw);
240         }
241
242         /*For LPS */
243         if (changed & IEEE80211_CONF_CHANGE_PS) {
244                 cancel_delayed_work(&rtlpriv->works.ps_work);
245                 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
246                 if (conf->flags & IEEE80211_CONF_PS) {
247                         rtlpriv->psc.sw_ps_enabled = true;
248                         /* sleep here is must, or we may recv the beacon and
249                          * cause mac80211 into wrong ps state, this will cause
250                          * power save nullfunc send fail, and further cause
251                          * pkt loss, So sleep must quickly but not immediatly
252                          * because that will cause nullfunc send by mac80211
253                          * fail, and cause pkt loss, we have tested that 5mA
254                          * is worked very well */
255                         if (!rtlpriv->psc.multi_buffered)
256                                 queue_delayed_work(rtlpriv->works.rtl_wq,
257                                                 &rtlpriv->works.ps_work,
258                                                 MSECS(5));
259                 } else {
260                         rtl_swlps_rf_awake(hw);
261                         rtlpriv->psc.sw_ps_enabled = false;
262                 }
263         }
264
265         if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
266                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
267                          "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
268                          hw->conf.long_frame_max_tx_count);
269                 mac->retry_long = hw->conf.long_frame_max_tx_count;
270                 mac->retry_short = hw->conf.long_frame_max_tx_count;
271                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
272                                               (u8 *) (&hw->conf.
273                                                       long_frame_max_tx_count));
274         }
275
276         if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
277                 struct ieee80211_channel *channel = hw->conf.channel;
278                 u8 wide_chan = (u8) channel->hw_value;
279
280                 /*
281                  *because we should back channel to
282                  *current_network.chan in in scanning,
283                  *So if set_chan == current_network.chan
284                  *we should set it.
285                  *because mac80211 tell us wrong bw40
286                  *info for cisco1253 bw20, so we modify
287                  *it here based on UPPER & LOWER
288                  */
289                 switch (hw->conf.channel_type) {
290                 case NL80211_CHAN_HT20:
291                 case NL80211_CHAN_NO_HT:
292                         /* SC */
293                         mac->cur_40_prime_sc =
294                                 PRIME_CHNL_OFFSET_DONT_CARE;
295                         rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
296                         mac->bw_40 = false;
297                         break;
298                 case NL80211_CHAN_HT40MINUS:
299                         /* SC */
300                         mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
301                         rtlphy->current_chan_bw =
302                                 HT_CHANNEL_WIDTH_20_40;
303                         mac->bw_40 = true;
304
305                         /*wide channel */
306                         wide_chan -= 2;
307
308                         break;
309                 case NL80211_CHAN_HT40PLUS:
310                         /* SC */
311                         mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
312                         rtlphy->current_chan_bw =
313                                 HT_CHANNEL_WIDTH_20_40;
314                         mac->bw_40 = true;
315
316                         /*wide channel */
317                         wide_chan += 2;
318
319                         break;
320                 default:
321                         mac->bw_40 = false;
322                         RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
323                                  "switch case not processed\n");
324                         break;
325                 }
326
327                 if (wide_chan <= 0)
328                         wide_chan = 1;
329
330                 /* In scanning, before we go offchannel we may send a ps=1 null
331                  * to AP, and then we may send a ps = 0 null to AP quickly, but
332                  * first null may have caused AP to put lots of packet to hw tx
333                  * buffer. These packets must be tx'd before we go off channel
334                  * so we must delay more time to let AP flush these packets
335                  * before going offchannel, or dis-association or delete BA will
336                  * happen by AP
337                  */
338                 if (rtlpriv->mac80211.offchan_delay) {
339                         rtlpriv->mac80211.offchan_delay = false;
340                         mdelay(50);
341                 }
342                 rtlphy->current_channel = wide_chan;
343
344                 rtlpriv->cfg->ops->switch_channel(hw);
345                 rtlpriv->cfg->ops->set_channel_access(hw);
346                 rtlpriv->cfg->ops->set_bw_mode(hw,
347                                                hw->conf.channel_type);
348         }
349
350         mutex_unlock(&rtlpriv->locks.conf_mutex);
351
352         return 0;
353 }
354
355 static void rtl_op_configure_filter(struct ieee80211_hw *hw,
356                              unsigned int changed_flags,
357                              unsigned int *new_flags, u64 multicast)
358 {
359         struct rtl_priv *rtlpriv = rtl_priv(hw);
360         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
361
362         *new_flags &= RTL_SUPPORTED_FILTERS;
363         if (!changed_flags)
364                 return;
365
366         /*TODO: we disable broadcase now, so enable here */
367         if (changed_flags & FIF_ALLMULTI) {
368                 if (*new_flags & FIF_ALLMULTI) {
369                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] |
370                             rtlpriv->cfg->maps[MAC_RCR_AB];
371                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
372                                  "Enable receive multicast frame\n");
373                 } else {
374                         mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] |
375                                           rtlpriv->cfg->maps[MAC_RCR_AB]);
376                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
377                                  "Disable receive multicast frame\n");
378                 }
379         }
380
381         if (changed_flags & FIF_FCSFAIL) {
382                 if (*new_flags & FIF_FCSFAIL) {
383                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32];
384                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
385                                  "Enable receive FCS error frame\n");
386                 } else {
387                         mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32];
388                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
389                                  "Disable receive FCS error frame\n");
390                 }
391         }
392
393         /* if ssid not set to hw don't check bssid
394          * here just used for linked scanning, & linked
395          * and nolink check bssid is set in set network_type */
396         if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
397                 (mac->link_state >= MAC80211_LINKED)) {
398                 if (mac->opmode != NL80211_IFTYPE_AP) {
399                         if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
400                                 rtlpriv->cfg->ops->set_chk_bssid(hw, false);
401                         } else {
402                                 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
403                         }
404                 }
405         }
406
407         if (changed_flags & FIF_CONTROL) {
408                 if (*new_flags & FIF_CONTROL) {
409                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
410
411                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
412                                  "Enable receive control frame\n");
413                 } else {
414                         mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
415                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
416                                  "Disable receive control frame\n");
417                 }
418         }
419
420         if (changed_flags & FIF_OTHER_BSS) {
421                 if (*new_flags & FIF_OTHER_BSS) {
422                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP];
423                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
424                                  "Enable receive other BSS's frame\n");
425                 } else {
426                         mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP];
427                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
428                                  "Disable receive other BSS's frame\n");
429                 }
430         }
431 }
432 static int rtl_op_sta_add(struct ieee80211_hw *hw,
433                          struct ieee80211_vif *vif,
434                          struct ieee80211_sta *sta)
435 {
436         struct rtl_priv *rtlpriv = rtl_priv(hw);
437         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
438         struct rtl_sta_info *sta_entry;
439
440         if (sta) {
441                 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
442                 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
443                         sta_entry->wireless_mode = WIRELESS_MODE_G;
444                         if (sta->supp_rates[0] <= 0xf)
445                                 sta_entry->wireless_mode = WIRELESS_MODE_B;
446                         if (sta->ht_cap.ht_supported)
447                                 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
448                 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
449                         sta_entry->wireless_mode = WIRELESS_MODE_A;
450                         if (sta->ht_cap.ht_supported)
451                                 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
452                 }
453
454                 /* I found some times mac80211 give wrong supp_rates for adhoc*/
455                 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC)
456                         sta_entry->wireless_mode = WIRELESS_MODE_G;
457
458                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
459                          "Add sta addr is %pM\n", sta->addr);
460                 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
461         }
462         return 0;
463 }
464 static int rtl_op_sta_remove(struct ieee80211_hw *hw,
465                                 struct ieee80211_vif *vif,
466                                 struct ieee80211_sta *sta)
467 {
468         struct rtl_priv *rtlpriv = rtl_priv(hw);
469         struct rtl_sta_info *sta_entry;
470         if (sta) {
471                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
472                          "Remove sta addr is %pM\n", sta->addr);
473                 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
474                 sta_entry->wireless_mode = 0;
475                 sta_entry->ratr_index = 0;
476         }
477         return 0;
478 }
479 static int _rtl_get_hal_qnum(u16 queue)
480 {
481         int qnum;
482
483         switch (queue) {
484         case 0:
485                 qnum = AC3_VO;
486                 break;
487         case 1:
488                 qnum = AC2_VI;
489                 break;
490         case 2:
491                 qnum = AC0_BE;
492                 break;
493         case 3:
494                 qnum = AC1_BK;
495                 break;
496         default:
497                 qnum = AC0_BE;
498                 break;
499         }
500         return qnum;
501 }
502
503 /*
504  *for mac80211 VO=0, VI=1, BE=2, BK=3
505  *for rtl819x  BE=0, BK=1, VI=2, VO=3
506  */
507 static int rtl_op_conf_tx(struct ieee80211_hw *hw,
508                    struct ieee80211_vif *vif, u16 queue,
509                    const struct ieee80211_tx_queue_params *param)
510 {
511         struct rtl_priv *rtlpriv = rtl_priv(hw);
512         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
513         int aci;
514
515         if (queue >= AC_MAX) {
516                 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
517                          "queue number %d is incorrect!\n", queue);
518                 return -EINVAL;
519         }
520
521         aci = _rtl_get_hal_qnum(queue);
522         mac->ac[aci].aifs = param->aifs;
523         mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
524         mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
525         mac->ac[aci].tx_op = cpu_to_le16(param->txop);
526         memcpy(&mac->edca_param[aci], param, sizeof(*param));
527         rtlpriv->cfg->ops->set_qos(hw, aci);
528         return 0;
529 }
530
531 static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
532                              struct ieee80211_vif *vif,
533                              struct ieee80211_bss_conf *bss_conf, u32 changed)
534 {
535         struct rtl_priv *rtlpriv = rtl_priv(hw);
536         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
537         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
538         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
539         struct ieee80211_sta *sta = NULL;
540
541         mutex_lock(&rtlpriv->locks.conf_mutex);
542         if ((vif->type == NL80211_IFTYPE_ADHOC) ||
543             (vif->type == NL80211_IFTYPE_AP) ||
544             (vif->type == NL80211_IFTYPE_MESH_POINT)) {
545                 if ((changed & BSS_CHANGED_BEACON) ||
546                     (changed & BSS_CHANGED_BEACON_ENABLED &&
547                      bss_conf->enable_beacon)) {
548                         if (mac->beacon_enabled == 0) {
549                                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
550                                          "BSS_CHANGED_BEACON_ENABLED\n");
551
552                                 /*start hw beacon interrupt. */
553                                 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
554                                 mac->beacon_enabled = 1;
555                                 rtlpriv->cfg->ops->update_interrupt_mask(hw,
556                                                 rtlpriv->cfg->maps
557                                                 [RTL_IBSS_INT_MASKS],
558                                                 0);
559
560                                 if (rtlpriv->cfg->ops->linked_set_reg)
561                                         rtlpriv->cfg->ops->linked_set_reg(hw);
562                         }
563                 }
564                 if ((changed & BSS_CHANGED_BEACON_ENABLED &&
565                         !bss_conf->enable_beacon)) {
566                         if (mac->beacon_enabled == 1) {
567                                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
568                                          "ADHOC DISABLE BEACON\n");
569
570                                 mac->beacon_enabled = 0;
571                                 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
572                                                 rtlpriv->cfg->maps
573                                                 [RTL_IBSS_INT_MASKS]);
574                         }
575                 }
576                 if (changed & BSS_CHANGED_BEACON_INT) {
577                         RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
578                                  "BSS_CHANGED_BEACON_INT\n");
579                         mac->beacon_interval = bss_conf->beacon_int;
580                         rtlpriv->cfg->ops->set_bcn_intv(hw);
581                 }
582         }
583
584         /*TODO: reference to enum ieee80211_bss_change */
585         if (changed & BSS_CHANGED_ASSOC) {
586                 if (bss_conf->assoc) {
587                         /* we should reset all sec info & cam
588                          * before set cam after linked, we should not
589                          * reset in disassoc, that will cause tkip->wep
590                          * fail because some flag will be wrong */
591                         /* reset sec info */
592                         rtl_cam_reset_sec_info(hw);
593                         /* reset cam to fix wep fail issue
594                          * when change from wpa to wep */
595                         rtl_cam_reset_all_entry(hw);
596
597                         mac->link_state = MAC80211_LINKED;
598                         mac->cnt_after_linked = 0;
599                         mac->assoc_id = bss_conf->aid;
600                         memcpy(mac->bssid, bss_conf->bssid, 6);
601
602                         if (rtlpriv->cfg->ops->linked_set_reg)
603                                 rtlpriv->cfg->ops->linked_set_reg(hw);
604                         if (mac->opmode == NL80211_IFTYPE_STATION && sta)
605                                 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
606                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
607                                  "BSS_CHANGED_ASSOC\n");
608                 } else {
609                         if (mac->link_state == MAC80211_LINKED)
610                                 rtl_lps_leave(hw);
611
612                         mac->link_state = MAC80211_NOLINK;
613                         memset(mac->bssid, 0, 6);
614
615                         /* reset sec info */
616                         rtl_cam_reset_sec_info(hw);
617
618                         rtl_cam_reset_all_entry(hw);
619                         mac->vendor = PEER_UNKNOWN;
620
621                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
622                                  "BSS_CHANGED_UN_ASSOC\n");
623                 }
624         }
625
626         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
627                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
628                          "BSS_CHANGED_ERP_CTS_PROT\n");
629                 mac->use_cts_protect = bss_conf->use_cts_prot;
630         }
631
632         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
633                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
634                          "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
635                          bss_conf->use_short_preamble);
636
637                 mac->short_preamble = bss_conf->use_short_preamble;
638                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
639                                               (u8 *) (&mac->short_preamble));
640         }
641
642         if (changed & BSS_CHANGED_ERP_SLOT) {
643                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
644                          "BSS_CHANGED_ERP_SLOT\n");
645
646                 if (bss_conf->use_short_slot)
647                         mac->slot_time = RTL_SLOT_TIME_9;
648                 else
649                         mac->slot_time = RTL_SLOT_TIME_20;
650
651                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
652                                               (u8 *) (&mac->slot_time));
653         }
654
655         if (changed & BSS_CHANGED_HT) {
656                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, "BSS_CHANGED_HT\n");
657                 rcu_read_lock();
658                 sta = get_sta(hw, vif, bss_conf->bssid);
659                 if (sta) {
660                         if (sta->ht_cap.ampdu_density >
661                             mac->current_ampdu_density)
662                                 mac->current_ampdu_density =
663                                     sta->ht_cap.ampdu_density;
664                         if (sta->ht_cap.ampdu_factor <
665                             mac->current_ampdu_factor)
666                                 mac->current_ampdu_factor =
667                                     sta->ht_cap.ampdu_factor;
668                 }
669                 rcu_read_unlock();
670
671                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
672                                               (u8 *) (&mac->max_mss_density));
673                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
674                                               &mac->current_ampdu_factor);
675                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
676                                               &mac->current_ampdu_density);
677         }
678
679         if (changed & BSS_CHANGED_BSSID) {
680                 u32 basic_rates;
681
682                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
683                                               (u8 *) bss_conf->bssid);
684
685                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, "%pM\n",
686                          bss_conf->bssid);
687
688                 mac->vendor = PEER_UNKNOWN;
689                 memcpy(mac->bssid, bss_conf->bssid, 6);
690                 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
691
692                 rcu_read_lock();
693                 sta = get_sta(hw, vif, bss_conf->bssid);
694                 if (!sta) {
695                         rcu_read_unlock();
696                         goto out;
697                 }
698
699                 if (rtlhal->current_bandtype == BAND_ON_5G) {
700                         mac->mode = WIRELESS_MODE_A;
701                 } else {
702                         if (sta->supp_rates[0] <= 0xf)
703                                 mac->mode = WIRELESS_MODE_B;
704                         else
705                                 mac->mode = WIRELESS_MODE_G;
706                 }
707
708                 if (sta->ht_cap.ht_supported) {
709                         if (rtlhal->current_bandtype == BAND_ON_2_4G)
710                                 mac->mode = WIRELESS_MODE_N_24G;
711                         else
712                                 mac->mode = WIRELESS_MODE_N_5G;
713                 }
714
715                 /* just station need it, because ibss & ap mode will
716                  * set in sta_add, and will be NULL here */
717                 if (mac->opmode == NL80211_IFTYPE_STATION) {
718                         struct rtl_sta_info *sta_entry;
719                         sta_entry = (struct rtl_sta_info *) sta->drv_priv;
720                         sta_entry->wireless_mode = mac->mode;
721                 }
722
723                 if (sta->ht_cap.ht_supported) {
724                         mac->ht_enable = true;
725
726                         /*
727                          * for cisco 1252 bw20 it's wrong
728                          * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
729                          *      mac->bw_40 = true;
730                          * }
731                          * */
732                 }
733
734                 if (changed & BSS_CHANGED_BASIC_RATES) {
735                         /* for 5G must << RATE_6M_INDEX=4,
736                          * because 5G have no cck rate*/
737                         if (rtlhal->current_bandtype == BAND_ON_5G)
738                                 basic_rates = sta->supp_rates[1] << 4;
739                         else
740                                 basic_rates = sta->supp_rates[0];
741
742                         mac->basic_rates = basic_rates;
743                         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
744                                         (u8 *) (&basic_rates));
745                 }
746                 rcu_read_unlock();
747         }
748
749         /*
750          * For FW LPS:
751          * To tell firmware we have connected
752          * to an AP. For 92SE/CE power save v2.
753          */
754         if (changed & BSS_CHANGED_ASSOC) {
755                 if (bss_conf->assoc) {
756                         if (ppsc->fwctrl_lps) {
757                                 u8 mstatus = RT_MEDIA_CONNECT;
758                                 rtlpriv->cfg->ops->set_hw_reg(hw,
759                                                       HW_VAR_H2C_FW_JOINBSSRPT,
760                                                       (u8 *) (&mstatus));
761                                 ppsc->report_linked = true;
762                         }
763                 } else {
764                         if (ppsc->fwctrl_lps) {
765                                 u8 mstatus = RT_MEDIA_DISCONNECT;
766                                 rtlpriv->cfg->ops->set_hw_reg(hw,
767                                                       HW_VAR_H2C_FW_JOINBSSRPT,
768                                                       (u8 *)(&mstatus));
769                                 ppsc->report_linked = false;
770                         }
771                 }
772         }
773
774 out:
775         mutex_unlock(&rtlpriv->locks.conf_mutex);
776 }
777
778 static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
779 {
780         struct rtl_priv *rtlpriv = rtl_priv(hw);
781         u64 tsf;
782
783         rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
784         return tsf;
785 }
786
787 static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
788                            u64 tsf)
789 {
790         struct rtl_priv *rtlpriv = rtl_priv(hw);
791         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
792         u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
793
794         mac->tsf = tsf;
795         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss));
796 }
797
798 static void rtl_op_reset_tsf(struct ieee80211_hw *hw,
799                              struct ieee80211_vif *vif)
800 {
801         struct rtl_priv *rtlpriv = rtl_priv(hw);
802         u8 tmp = 0;
803
804         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *) (&tmp));
805 }
806
807 static void rtl_op_sta_notify(struct ieee80211_hw *hw,
808                               struct ieee80211_vif *vif,
809                               enum sta_notify_cmd cmd,
810                               struct ieee80211_sta *sta)
811 {
812         switch (cmd) {
813         case STA_NOTIFY_SLEEP:
814                 break;
815         case STA_NOTIFY_AWAKE:
816                 break;
817         default:
818                 break;
819         }
820 }
821
822 static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
823                                struct ieee80211_vif *vif,
824                                enum ieee80211_ampdu_mlme_action action,
825                                struct ieee80211_sta *sta, u16 tid, u16 *ssn,
826                                u8 buf_size)
827 {
828         struct rtl_priv *rtlpriv = rtl_priv(hw);
829
830         switch (action) {
831         case IEEE80211_AMPDU_TX_START:
832                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
833                          "IEEE80211_AMPDU_TX_START: TID:%d\n", tid);
834                 return rtl_tx_agg_start(hw, sta, tid, ssn);
835                 break;
836         case IEEE80211_AMPDU_TX_STOP:
837                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
838                          "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
839                 return rtl_tx_agg_stop(hw, sta, tid);
840                 break;
841         case IEEE80211_AMPDU_TX_OPERATIONAL:
842                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
843                          "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
844                 rtl_tx_agg_oper(hw, sta, tid);
845                 break;
846         case IEEE80211_AMPDU_RX_START:
847                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
848                          "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
849                 break;
850         case IEEE80211_AMPDU_RX_STOP:
851                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
852                          "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
853                 break;
854         default:
855                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
856                          "IEEE80211_AMPDU_ERR!!!!:\n");
857                 return -EOPNOTSUPP;
858         }
859         return 0;
860 }
861
862 static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
863 {
864         struct rtl_priv *rtlpriv = rtl_priv(hw);
865         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
866
867         mac->act_scanning = true;
868
869         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
870
871         if (mac->link_state == MAC80211_LINKED) {
872                 rtl_lps_leave(hw);
873                 mac->link_state = MAC80211_LINKED_SCANNING;
874         } else {
875                 rtl_ips_nic_on(hw);
876         }
877
878         /* Dual mac */
879         rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
880
881         rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
882         rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
883 }
884
885 static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
886 {
887         struct rtl_priv *rtlpriv = rtl_priv(hw);
888         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
889
890         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
891         mac->act_scanning = false;
892         /* Dual mac */
893         rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
894
895         if (mac->link_state == MAC80211_LINKED_SCANNING) {
896                 mac->link_state = MAC80211_LINKED;
897                 if (mac->opmode == NL80211_IFTYPE_STATION) {
898                         /* fix fwlps issue */
899                         rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
900                 }
901         }
902
903         rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
904 }
905
906 static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
907                           struct ieee80211_vif *vif, struct ieee80211_sta *sta,
908                           struct ieee80211_key_conf *key)
909 {
910         struct rtl_priv *rtlpriv = rtl_priv(hw);
911         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
912         u8 key_type = NO_ENCRYPTION;
913         u8 key_idx;
914         bool group_key = false;
915         bool wep_only = false;
916         int err = 0;
917         u8 mac_addr[ETH_ALEN];
918         u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
919         u8 zero_addr[ETH_ALEN] = { 0 };
920
921         if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
922                 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
923                          "not open hw encryption\n");
924                 return -ENOSPC; /*User disabled HW-crypto */
925         }
926         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
927                  "%s hardware based encryption for keyidx: %d, mac: %pM\n",
928                  cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
929                  sta ? sta->addr : bcast_addr);
930         rtlpriv->sec.being_setkey = true;
931         rtl_ips_nic_on(hw);
932         mutex_lock(&rtlpriv->locks.conf_mutex);
933         /* <1> get encryption alg */
934
935         switch (key->cipher) {
936         case WLAN_CIPHER_SUITE_WEP40:
937                 key_type = WEP40_ENCRYPTION;
938                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
939                 break;
940         case WLAN_CIPHER_SUITE_WEP104:
941                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
942                 key_type = WEP104_ENCRYPTION;
943                 break;
944         case WLAN_CIPHER_SUITE_TKIP:
945                 key_type = TKIP_ENCRYPTION;
946                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
947                 break;
948         case WLAN_CIPHER_SUITE_CCMP:
949                 key_type = AESCCMP_ENCRYPTION;
950                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
951                 break;
952         default:
953                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n",
954                          key->cipher);
955                 goto out_unlock;
956         }
957         if (key_type == WEP40_ENCRYPTION ||
958                         key_type == WEP104_ENCRYPTION ||
959                         mac->opmode == NL80211_IFTYPE_ADHOC)
960                 rtlpriv->sec.use_defaultkey = true;
961
962         /* <2> get key_idx */
963         key_idx = (u8) (key->keyidx);
964         if (key_idx > 3)
965                 goto out_unlock;
966         /* <3> if pairwise key enable_hw_sec */
967         group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
968
969         /* wep always be group key, but there are two conditions:
970          * 1) wep only: is just for wep enc, in this condition
971          * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
972          * will be true & enable_hw_sec will be set when wep
973          * ke setting.
974          * 2) wep(group) + AES(pairwise): some AP like cisco
975          * may use it, in this condition enable_hw_sec will not
976          * be set when wep key setting */
977         /* we must reset sec_info after lingked before set key,
978          * or some flag will be wrong*/
979         if (mac->opmode == NL80211_IFTYPE_AP) {
980                 if (!group_key || key_type == WEP40_ENCRYPTION ||
981                         key_type == WEP104_ENCRYPTION) {
982                         if (group_key)
983                                 wep_only = true;
984                         rtlpriv->cfg->ops->enable_hw_sec(hw);
985                 }
986         } else {
987                 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
988                      rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
989                         if (rtlpriv->sec.pairwise_enc_algorithm ==
990                             NO_ENCRYPTION &&
991                             (key_type == WEP40_ENCRYPTION ||
992                             key_type == WEP104_ENCRYPTION))
993                                 wep_only = true;
994                         rtlpriv->sec.pairwise_enc_algorithm = key_type;
995                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
996                                  "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
997                                  key_type);
998                         rtlpriv->cfg->ops->enable_hw_sec(hw);
999                 }
1000         }
1001         /* <4> set key based on cmd */
1002         switch (cmd) {
1003         case SET_KEY:
1004                 if (wep_only) {
1005                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1006                                  "set WEP(group/pairwise) key\n");
1007                         /* Pairwise key with an assigned MAC address. */
1008                         rtlpriv->sec.pairwise_enc_algorithm = key_type;
1009                         rtlpriv->sec.group_enc_algorithm = key_type;
1010                         /*set local buf about wep key. */
1011                         memcpy(rtlpriv->sec.key_buf[key_idx],
1012                                key->key, key->keylen);
1013                         rtlpriv->sec.key_len[key_idx] = key->keylen;
1014                         memcpy(mac_addr, zero_addr, ETH_ALEN);
1015                 } else if (group_key) { /* group key */
1016                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1017                                  "set group key\n");
1018                         /* group key */
1019                         rtlpriv->sec.group_enc_algorithm = key_type;
1020                         /*set local buf about group key. */
1021                         memcpy(rtlpriv->sec.key_buf[key_idx],
1022                                key->key, key->keylen);
1023                         rtlpriv->sec.key_len[key_idx] = key->keylen;
1024                         memcpy(mac_addr, bcast_addr, ETH_ALEN);
1025                 } else {        /* pairwise key */
1026                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1027                                  "set pairwise key\n");
1028                         if (!sta) {
1029                                 RT_ASSERT(false,
1030                                           "pairwise key without mac_addr\n");
1031
1032                                 err = -EOPNOTSUPP;
1033                                 goto out_unlock;
1034                         }
1035                         /* Pairwise key with an assigned MAC address. */
1036                         rtlpriv->sec.pairwise_enc_algorithm = key_type;
1037                         /*set local buf about pairwise key. */
1038                         memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
1039                                key->key, key->keylen);
1040                         rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
1041                         rtlpriv->sec.pairwise_key =
1042                             rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
1043                         memcpy(mac_addr, sta->addr, ETH_ALEN);
1044                 }
1045                 rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
1046                                            group_key, key_type, wep_only,
1047                                            false);
1048                 /* <5> tell mac80211 do something: */
1049                 /*must use sw generate IV, or can not work !!!!. */
1050                 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1051                 key->hw_key_idx = key_idx;
1052                 if (key_type == TKIP_ENCRYPTION)
1053                         key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1054                 break;
1055         case DISABLE_KEY:
1056                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1057                          "disable key delete one entry\n");
1058                 /*set local buf about wep key. */
1059                 if (mac->opmode == NL80211_IFTYPE_AP) {
1060                         if (sta)
1061                                 rtl_cam_del_entry(hw, sta->addr);
1062                 }
1063                 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
1064                 rtlpriv->sec.key_len[key_idx] = 0;
1065                 memcpy(mac_addr, zero_addr, ETH_ALEN);
1066                 /*
1067                  *mac80211 will delete entrys one by one,
1068                  *so don't use rtl_cam_reset_all_entry
1069                  *or clear all entry here.
1070                  */
1071                 rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
1072
1073                 rtl_cam_reset_sec_info(hw);
1074
1075                 break;
1076         default:
1077                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1078                          "cmd_err:%x!!!!\n", cmd);
1079         }
1080 out_unlock:
1081         mutex_unlock(&rtlpriv->locks.conf_mutex);
1082         rtlpriv->sec.being_setkey = false;
1083         return err;
1084 }
1085
1086 static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1087 {
1088         struct rtl_priv *rtlpriv = rtl_priv(hw);
1089
1090         bool radio_state;
1091         bool blocked;
1092         u8 valid = 0;
1093
1094         if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1095                 return;
1096
1097         mutex_lock(&rtlpriv->locks.conf_mutex);
1098
1099         /*if Radio On return true here */
1100         radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
1101
1102         if (valid) {
1103                 if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
1104                         rtlpriv->rfkill.rfkill_state = radio_state;
1105
1106                         RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1107                                  "wireless radio switch turned %s\n",
1108                                  radio_state ? "on" : "off");
1109
1110                         blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
1111                         wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1112                 }
1113         }
1114
1115         mutex_unlock(&rtlpriv->locks.conf_mutex);
1116 }
1117
1118 /* this function is called by mac80211 to flush tx buffer
1119  * before switch channle or power save, or tx buffer packet
1120  * maybe send after offchannel or rf sleep, this may cause
1121  * dis-association by AP */
1122 static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
1123 {
1124         struct rtl_priv *rtlpriv = rtl_priv(hw);
1125
1126         if (rtlpriv->intf_ops->flush)
1127                 rtlpriv->intf_ops->flush(hw, drop);
1128 }
1129
1130 const struct ieee80211_ops rtl_ops = {
1131         .start = rtl_op_start,
1132         .stop = rtl_op_stop,
1133         .tx = rtl_op_tx,
1134         .add_interface = rtl_op_add_interface,
1135         .remove_interface = rtl_op_remove_interface,
1136         .config = rtl_op_config,
1137         .configure_filter = rtl_op_configure_filter,
1138         .sta_add = rtl_op_sta_add,
1139         .sta_remove = rtl_op_sta_remove,
1140         .set_key = rtl_op_set_key,
1141         .conf_tx = rtl_op_conf_tx,
1142         .bss_info_changed = rtl_op_bss_info_changed,
1143         .get_tsf = rtl_op_get_tsf,
1144         .set_tsf = rtl_op_set_tsf,
1145         .reset_tsf = rtl_op_reset_tsf,
1146         .sta_notify = rtl_op_sta_notify,
1147         .ampdu_action = rtl_op_ampdu_action,
1148         .sw_scan_start = rtl_op_sw_scan_start,
1149         .sw_scan_complete = rtl_op_sw_scan_complete,
1150         .rfkill_poll = rtl_op_rfkill_poll,
1151         .flush = rtl_op_flush,
1152 };