core.c 32 KB

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