1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *****************************************************************************/
35 /*mutex for start & stop is must here. */
36 static int rtl_op_start(struct ieee80211_hw
*hw
)
39 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
40 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
42 if (!is_hal_stop(rtlhal
))
44 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
46 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
47 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
50 rtl_watch_dog_timer_callback((unsigned long)hw
);
52 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
56 static void rtl_op_stop(struct ieee80211_hw
*hw
)
58 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
59 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
60 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
61 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
63 if (is_hal_stop(rtlhal
))
66 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
)) {
71 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
73 mac
->link_state
= MAC80211_NOLINK
;
74 memset(mac
->bssid
, 0, 6);
77 rtl_cam_reset_sec_info(hw
);
79 rtl_deinit_deferred_work(hw
);
80 rtlpriv
->intf_ops
->adapter_stop(hw
);
82 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
85 static int rtl_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
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
));
91 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
94 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
98 rtlpriv
->intf_ops
->adapter_tx(hw
, skb
);
103 dev_kfree_skb_any(skb
);
107 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
108 struct ieee80211_vif
*vif
)
110 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
111 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
115 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
116 ("vif has been set!! mac->vif = 0x%p\n", mac
->vif
));
122 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
124 case NL80211_IFTYPE_STATION
:
125 if (mac
->beacon_enabled
== 1) {
126 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
127 ("NL80211_IFTYPE_STATION\n"));
128 mac
->beacon_enabled
= 0;
129 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
131 [RTL_IBSS_INT_MASKS
]);
134 case NL80211_IFTYPE_ADHOC
:
135 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
136 ("NL80211_IFTYPE_ADHOC\n"));
138 mac
->link_state
= MAC80211_LINKED
;
139 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
141 case NL80211_IFTYPE_AP
:
142 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
143 ("NL80211_IFTYPE_AP\n"));
146 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
147 ("operation mode %d is not support!\n", vif
->type
));
153 mac
->opmode
= vif
->type
;
154 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
155 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
156 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
159 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
163 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
164 struct ieee80211_vif
*vif
)
166 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
167 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
169 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
171 /* Free beacon resources */
172 if ((mac
->opmode
== NL80211_IFTYPE_AP
) ||
173 (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
174 (mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)) {
175 if (mac
->beacon_enabled
== 1) {
176 mac
->beacon_enabled
= 0;
177 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
179 [RTL_IBSS_INT_MASKS
]);
184 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
185 *NO LINK for our hardware.
188 mac
->link_state
= MAC80211_NOLINK
;
189 memset(mac
->bssid
, 0, 6);
190 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
191 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
193 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
197 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
199 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
200 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
201 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
202 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
203 struct ieee80211_conf
*conf
= &hw
->conf
;
205 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
206 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /*BIT(2)*/
207 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
208 ("IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"));
212 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
213 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
219 *although rfoff may not cause by ips, but we will
220 *check the reason in set_rf_power_state function
222 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
227 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
228 if (conf
->flags
& IEEE80211_CONF_PS
)
234 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
235 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
236 ("IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
237 hw
->conf
.long_frame_max_tx_count
));
238 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
239 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
240 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
242 long_frame_max_tx_count
));
245 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
246 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
247 u8 wide_chan
= (u8
) channel
->hw_value
;
250 *because we should back channel to
251 *current_network.chan in in scanning,
252 *So if set_chan == current_network.chan
254 *because mac80211 tell us wrong bw40
255 *info for cisco1253 bw20, so we modify
256 *it here based on UPPER & LOWER
258 switch (hw
->conf
.channel_type
) {
259 case NL80211_CHAN_HT20
:
260 case NL80211_CHAN_NO_HT
:
262 mac
->cur_40_prime_sc
=
263 PRIME_CHNL_OFFSET_DONT_CARE
;
264 rtlphy
->current_chan_bw
= HT_CHANNEL_WIDTH_20
;
267 case NL80211_CHAN_HT40MINUS
:
269 mac
->cur_40_prime_sc
= PRIME_CHNL_OFFSET_UPPER
;
270 rtlphy
->current_chan_bw
=
271 HT_CHANNEL_WIDTH_20_40
;
278 case NL80211_CHAN_HT40PLUS
:
280 mac
->cur_40_prime_sc
= PRIME_CHNL_OFFSET_LOWER
;
281 rtlphy
->current_chan_bw
=
282 HT_CHANNEL_WIDTH_20_40
;
291 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
292 ("switch case not processed\n"));
298 rtlphy
->current_channel
= wide_chan
;
300 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
301 rtlpriv
->cfg
->ops
->switch_channel(hw
);
302 rtlpriv
->cfg
->ops
->set_bw_mode(hw
,
303 hw
->conf
.channel_type
);
306 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
311 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
312 unsigned int changed_flags
,
313 unsigned int *new_flags
, u64 multicast
)
315 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
316 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
318 *new_flags
&= RTL_SUPPORTED_FILTERS
;
322 /*TODO: we disable broadcase now, so enable here */
323 if (changed_flags
& FIF_ALLMULTI
) {
324 if (*new_flags
& FIF_ALLMULTI
) {
325 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
326 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
327 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
328 ("Enable receive multicast frame.\n"));
330 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
331 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
332 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
333 ("Disable receive multicast frame.\n"));
337 if (changed_flags
& FIF_FCSFAIL
) {
338 if (*new_flags
& FIF_FCSFAIL
) {
339 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
340 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
341 ("Enable receive FCS error frame.\n"));
343 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
344 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
345 ("Disable receive FCS error frame.\n"));
349 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
351 *TODO: BIT(5) is probe response BIT(8) is beacon
352 *TODO: Use define for BIT(5) and BIT(8)
354 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
)
355 mac
->rx_mgt_filter
|= (BIT(5) | BIT(8));
357 mac
->rx_mgt_filter
&= ~(BIT(5) | BIT(8));
360 if (changed_flags
& FIF_CONTROL
) {
361 if (*new_flags
& FIF_CONTROL
) {
362 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
363 mac
->rx_ctrl_filter
|= RTL_SUPPORTED_CTRL_FILTER
;
365 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
366 ("Enable receive control frame.\n"));
368 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
369 mac
->rx_ctrl_filter
&= ~RTL_SUPPORTED_CTRL_FILTER
;
370 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
371 ("Disable receive control frame.\n"));
375 if (changed_flags
& FIF_OTHER_BSS
) {
376 if (*new_flags
& FIF_OTHER_BSS
) {
377 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
378 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
379 ("Enable receive other BSS's frame.\n"));
381 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
382 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
383 ("Disable receive other BSS's frame.\n"));
387 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*) (&mac
->rx_conf
));
388 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_MGT_FILTER
,
389 (u8
*) (&mac
->rx_mgt_filter
));
390 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CTRL_FILTER
,
391 (u8
*) (&mac
->rx_ctrl_filter
));
394 static int _rtl_get_hal_qnum(u16 queue
)
419 *for mac80211 VO=0, VI=1, BE=2, BK=3
420 *for rtl819x BE=0, BK=1, VI=2, VO=3
422 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
423 const struct ieee80211_tx_queue_params
*param
)
425 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
426 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
429 if (queue
>= AC_MAX
) {
430 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
431 ("queue number %d is incorrect!\n", queue
));
435 aci
= _rtl_get_hal_qnum(queue
);
436 mac
->ac
[aci
].aifs
= param
->aifs
;
437 mac
->ac
[aci
].cw_min
= param
->cw_min
;
438 mac
->ac
[aci
].cw_max
= param
->cw_max
;
439 mac
->ac
[aci
].tx_op
= param
->txop
;
440 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
441 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
445 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
446 struct ieee80211_vif
*vif
,
447 struct ieee80211_bss_conf
*bss_conf
, u32 changed
)
449 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
450 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
451 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
453 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
455 if ((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
456 (vif
->type
== NL80211_IFTYPE_AP
) ||
457 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
459 if ((changed
& BSS_CHANGED_BEACON
) ||
460 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
461 bss_conf
->enable_beacon
)) {
463 if (mac
->beacon_enabled
== 0) {
464 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
465 ("BSS_CHANGED_BEACON_ENABLED\n"));
467 /*start hw beacon interrupt. */
468 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
469 mac
->beacon_enabled
= 1;
470 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
472 [RTL_IBSS_INT_MASKS
],
476 if (mac
->beacon_enabled
== 1) {
477 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
478 ("ADHOC DISABLE BEACON\n"));
480 mac
->beacon_enabled
= 0;
481 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
483 [RTL_IBSS_INT_MASKS
]);
487 if (changed
& BSS_CHANGED_BEACON_INT
) {
488 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
489 ("BSS_CHANGED_BEACON_INT\n"));
490 mac
->beacon_interval
= bss_conf
->beacon_int
;
491 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
495 /*TODO: reference to enum ieee80211_bss_change */
496 if (changed
& BSS_CHANGED_ASSOC
) {
497 if (bss_conf
->assoc
) {
498 mac
->link_state
= MAC80211_LINKED
;
499 mac
->cnt_after_linked
= 0;
500 mac
->assoc_id
= bss_conf
->aid
;
501 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
503 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
504 ("BSS_CHANGED_ASSOC\n"));
506 if (mac
->link_state
== MAC80211_LINKED
)
509 mac
->link_state
= MAC80211_NOLINK
;
510 memset(mac
->bssid
, 0, 6);
513 rtl_cam_reset_sec_info(hw
);
515 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
516 ("BSS_CHANGED_UN_ASSOC\n"));
520 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
521 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
522 ("BSS_CHANGED_ERP_CTS_PROT\n"));
523 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
526 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
527 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
528 ("BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
529 bss_conf
->use_short_preamble
));
531 mac
->short_preamble
= bss_conf
->use_short_preamble
;
532 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
533 (u8
*) (&mac
->short_preamble
));
536 if (changed
& BSS_CHANGED_ERP_SLOT
) {
537 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
538 ("BSS_CHANGED_ERP_SLOT\n"));
540 if (bss_conf
->use_short_slot
)
541 mac
->slot_time
= RTL_SLOT_TIME_9
;
543 mac
->slot_time
= RTL_SLOT_TIME_20
;
545 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
546 (u8
*) (&mac
->slot_time
));
549 if (changed
& BSS_CHANGED_HT
) {
550 struct ieee80211_sta
*sta
= NULL
;
552 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
553 ("BSS_CHANGED_HT\n"));
555 sta
= ieee80211_find_sta(mac
->vif
, mac
->bssid
);
558 if (sta
->ht_cap
.ampdu_density
>
559 mac
->current_ampdu_density
)
560 mac
->current_ampdu_density
=
561 sta
->ht_cap
.ampdu_density
;
562 if (sta
->ht_cap
.ampdu_factor
<
563 mac
->current_ampdu_factor
)
564 mac
->current_ampdu_factor
=
565 sta
->ht_cap
.ampdu_factor
;
568 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
569 (u8
*) (&mac
->max_mss_density
));
570 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
571 &mac
->current_ampdu_factor
);
572 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
573 &mac
->current_ampdu_density
);
576 if (changed
& BSS_CHANGED_BSSID
) {
577 struct ieee80211_sta
*sta
= NULL
;
581 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
582 (u8
*) bss_conf
->bssid
);
584 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
585 (MAC_FMT
"\n", MAC_ARG(bss_conf
->bssid
)));
587 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
588 if (is_valid_ether_addr(bss_conf
->bssid
)) {
590 case NL80211_IFTYPE_UNSPECIFIED
:
592 case NL80211_IFTYPE_ADHOC
:
594 case NL80211_IFTYPE_STATION
:
596 case NL80211_IFTYPE_AP
:
599 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
600 ("switch case not process\n"));
603 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
605 rtlpriv
->cfg
->ops
->set_network_type(hw
,
606 NL80211_IFTYPE_UNSPECIFIED
);
608 memset(mac
->mcs
, 0, 16);
609 mac
->ht_enable
= false;
613 if (!bss_conf
->use_short_slot
)
614 mac
->mode
= WIRELESS_MODE_B
;
616 mac
->mode
= WIRELESS_MODE_G
;
618 sta
= ieee80211_find_sta(mac
->vif
, mac
->bssid
);
621 if (sta
->ht_cap
.ht_supported
) {
622 mac
->mode
= WIRELESS_MODE_N_24G
;
623 mac
->ht_enable
= true;
626 if (mac
->ht_enable
) {
627 u16 ht_cap
= sta
->ht_cap
.cap
;
628 memcpy(mac
->mcs
, (u8
*) (&sta
->ht_cap
.mcs
), 16);
630 for (i
= 0; i
< 16; i
++)
631 RT_TRACE(rtlpriv
, COMP_MAC80211
,
634 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
637 if (ht_cap
& IEEE80211_HT_CAP_SGI_40
)
640 if (ht_cap
& IEEE80211_HT_CAP_SGI_20
)
644 * for cisco 1252 bw20 it's wrong
646 * IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
653 /*mac80211 just give us CCK rates any time
654 *So we add G rate in basic rates when
656 if (changed
& BSS_CHANGED_BASIC_RATES
) {
657 if (mac
->mode
== WIRELESS_MODE_B
)
658 basic_rates
= bss_conf
->basic_rates
| 0x00f;
660 basic_rates
= bss_conf
->basic_rates
| 0xff0;
665 mac
->basic_rates
= basic_rates
;
666 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
667 (u8
*) (&basic_rates
));
669 if (rtlpriv
->dm
.b_useramask
)
670 rtlpriv
->cfg
->ops
->update_rate_mask(hw
, 0);
672 rtlpriv
->cfg
->ops
->update_rate_table(hw
);
679 * To tell firmware we have connected
680 * to an AP. For 92SE/CE power save v2.
682 if (changed
& BSS_CHANGED_ASSOC
) {
683 if (bss_conf
->assoc
) {
684 if (ppsc
->b_fwctrl_lps
) {
685 u8 mstatus
= RT_MEDIA_CONNECT
;
686 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
687 HW_VAR_H2C_FW_JOINBSSRPT
,
689 ppsc
->report_linked
= true;
692 if (ppsc
->b_fwctrl_lps
) {
693 u8 mstatus
= RT_MEDIA_DISCONNECT
;
694 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
695 HW_VAR_H2C_FW_JOINBSSRPT
,
697 ppsc
->report_linked
= false;
703 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
706 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
)
708 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
711 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*) (&tsf
));
715 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
717 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
718 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
719 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;;
722 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*) (&bibss
));
725 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
)
727 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
730 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*) (&tmp
));
733 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
734 struct ieee80211_vif
*vif
,
735 enum sta_notify_cmd cmd
,
736 struct ieee80211_sta
*sta
)
739 case STA_NOTIFY_SLEEP
:
741 case STA_NOTIFY_AWAKE
:
748 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
749 struct ieee80211_vif
*vif
,
750 enum ieee80211_ampdu_mlme_action action
,
751 struct ieee80211_sta
*sta
, u16 tid
, u16
* ssn
)
753 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
756 case IEEE80211_AMPDU_TX_START
:
757 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
758 ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid
));
759 return rtl_tx_agg_start(hw
, sta
->addr
, tid
, ssn
);
761 case IEEE80211_AMPDU_TX_STOP
:
762 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
763 ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
));
764 return rtl_tx_agg_stop(hw
, sta
->addr
, tid
);
766 case IEEE80211_AMPDU_TX_OPERATIONAL
:
767 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
768 ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
));
770 case IEEE80211_AMPDU_RX_START
:
771 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
772 ("IEEE80211_AMPDU_RX_START:TID:%d\n", tid
));
774 case IEEE80211_AMPDU_RX_STOP
:
775 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
776 ("IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
));
779 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
780 ("IEEE80211_AMPDU_ERR!!!!:\n"));
786 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
)
788 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
789 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
791 mac
->act_scanning
= true;
793 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("\n"));
795 if (mac
->link_state
== MAC80211_LINKED
) {
797 mac
->link_state
= MAC80211_LINKED_SCANNING
;
801 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
802 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP
);
805 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
)
807 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
808 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
810 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("\n"));
812 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
813 mac
->act_scanning
= false;
814 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
815 mac
->link_state
= MAC80211_LINKED
;
817 /* fix fwlps issue */
818 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
820 if (rtlpriv
->dm
.b_useramask
)
821 rtlpriv
->cfg
->ops
->update_rate_mask(hw
, 0);
823 rtlpriv
->cfg
->ops
->update_rate_table(hw
);
829 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
830 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
831 struct ieee80211_key_conf
*key
)
833 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
834 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
835 u8 key_type
= NO_ENCRYPTION
;
837 bool group_key
= false;
838 bool wep_only
= false;
840 u8 mac_addr
[ETH_ALEN
];
841 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
842 u8 zero_addr
[ETH_ALEN
] = { 0 };
844 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
845 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
846 ("not open hw encryption\n"));
847 return -ENOSPC
; /*User disabled HW-crypto */
849 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
850 ("%s hardware based encryption for keyidx: %d, mac: %pM\n",
851 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
852 sta
? sta
->addr
: bcast_addr
));
853 rtlpriv
->sec
.being_setkey
= true;
855 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
856 /* <1> get encryption alg */
857 switch (key
->cipher
) {
858 case WLAN_CIPHER_SUITE_WEP40
:
859 key_type
= WEP40_ENCRYPTION
;
860 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, ("alg:WEP40\n"));
861 rtlpriv
->sec
.use_defaultkey
= true;
863 case WLAN_CIPHER_SUITE_WEP104
:
864 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
866 key_type
= WEP104_ENCRYPTION
;
867 rtlpriv
->sec
.use_defaultkey
= true;
869 case WLAN_CIPHER_SUITE_TKIP
:
870 key_type
= TKIP_ENCRYPTION
;
871 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, ("alg:TKIP\n"));
872 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
873 rtlpriv
->sec
.use_defaultkey
= true;
875 case WLAN_CIPHER_SUITE_CCMP
:
876 key_type
= AESCCMP_ENCRYPTION
;
877 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, ("alg:CCMP\n"));
878 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
879 rtlpriv
->sec
.use_defaultkey
= true;
882 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
883 ("alg_err:%x!!!!:\n", key
->cipher
));
886 /* <2> get key_idx */
887 key_idx
= (u8
) (key
->keyidx
);
890 /* <3> if pairwise key enable_hw_sec */
891 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
892 if ((!group_key
) || (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
893 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
894 if (rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
&&
895 (key_type
== WEP40_ENCRYPTION
||
896 key_type
== WEP104_ENCRYPTION
))
898 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
899 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
901 /* <4> set key based on cmd */
905 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
906 ("set WEP(group/pairwise) key\n"));
907 /* Pairwise key with an assigned MAC address. */
908 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
909 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
910 /*set local buf about wep key. */
911 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
912 key
->key
, key
->keylen
);
913 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
914 memcpy(mac_addr
, zero_addr
, ETH_ALEN
);
915 } else if (group_key
) { /* group key */
916 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
917 ("set group key\n"));
919 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
920 /*set local buf about group key. */
921 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
922 key
->key
, key
->keylen
);
923 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
924 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
925 } else { /* pairwise key */
926 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
927 ("set pairwise key\n"));
929 RT_ASSERT(false, ("pairwise key withnot"
934 /* Pairwise key with an assigned MAC address. */
935 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
936 /*set local buf about pairwise key. */
937 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
938 key
->key
, key
->keylen
);
939 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
940 rtlpriv
->sec
.pairwise_key
=
941 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
942 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
944 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
945 group_key
, key_type
, wep_only
,
947 /* <5> tell mac80211 do something: */
948 /*must use sw generate IV, or can not work !!!!. */
949 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
950 key
->hw_key_idx
= key_idx
;
951 if (key_type
== TKIP_ENCRYPTION
)
952 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
955 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
956 ("disable key delete one entry\n"));
957 /*set local buf about wep key. */
958 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
959 rtlpriv
->sec
.key_len
[key_idx
] = 0;
960 memcpy(mac_addr
, zero_addr
, ETH_ALEN
);
962 *mac80211 will delete entrys one by one,
963 *so don't use rtl_cam_reset_all_entry
964 *or clear all entry here.
966 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
969 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
970 ("cmd_err:%x!!!!:\n", cmd
));
973 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
974 rtlpriv
->sec
.being_setkey
= false;
978 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
980 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
986 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
989 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
991 /*if Radio On return true here */
992 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
995 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
996 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
998 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
999 (KERN_INFO
"wireless radio switch turned %s\n",
1000 radio_state
? "on" : "off"));
1002 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1003 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1007 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1010 const struct ieee80211_ops rtl_ops
= {
1011 .start
= rtl_op_start
,
1012 .stop
= rtl_op_stop
,
1014 .add_interface
= rtl_op_add_interface
,
1015 .remove_interface
= rtl_op_remove_interface
,
1016 .config
= rtl_op_config
,
1017 .configure_filter
= rtl_op_configure_filter
,
1018 .set_key
= rtl_op_set_key
,
1019 .conf_tx
= rtl_op_conf_tx
,
1020 .bss_info_changed
= rtl_op_bss_info_changed
,
1021 .get_tsf
= rtl_op_get_tsf
,
1022 .set_tsf
= rtl_op_set_tsf
,
1023 .reset_tsf
= rtl_op_reset_tsf
,
1024 .sta_notify
= rtl_op_sta_notify
,
1025 .ampdu_action
= rtl_op_ampdu_action
,
1026 .sw_scan_start
= rtl_op_sw_scan_start
,
1027 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1028 .rfkill_poll
= rtl_op_rfkill_poll
,