core.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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_deley) {
  296. rtlpriv->mac80211.offchan_deley = 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 == true)
  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 == true)
  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 "MAC_FMT"\n", MAC_ARG(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 "MAC_FMT"\n", MAC_ARG(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, u16 queue,
  449. const struct ieee80211_tx_queue_params *param)
  450. {
  451. struct rtl_priv *rtlpriv = rtl_priv(hw);
  452. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  453. int aci;
  454. if (queue >= AC_MAX) {
  455. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  456. ("queue number %d is incorrect!\n", queue));
  457. return -EINVAL;
  458. }
  459. aci = _rtl_get_hal_qnum(queue);
  460. mac->ac[aci].aifs = param->aifs;
  461. mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
  462. mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
  463. mac->ac[aci].tx_op = cpu_to_le16(param->txop);
  464. memcpy(&mac->edca_param[aci], param, sizeof(*param));
  465. rtlpriv->cfg->ops->set_qos(hw, aci);
  466. return 0;
  467. }
  468. static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
  469. struct ieee80211_vif *vif,
  470. struct ieee80211_bss_conf *bss_conf, u32 changed)
  471. {
  472. struct rtl_priv *rtlpriv = rtl_priv(hw);
  473. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  474. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  475. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  476. struct ieee80211_sta *sta = NULL;
  477. mutex_lock(&rtlpriv->locks.conf_mutex);
  478. if ((vif->type == NL80211_IFTYPE_ADHOC) ||
  479. (vif->type == NL80211_IFTYPE_AP) ||
  480. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  481. if ((changed & BSS_CHANGED_BEACON) ||
  482. (changed & BSS_CHANGED_BEACON_ENABLED &&
  483. bss_conf->enable_beacon)) {
  484. if (mac->beacon_enabled == 0) {
  485. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  486. ("BSS_CHANGED_BEACON_ENABLED\n"));
  487. /*start hw beacon interrupt. */
  488. /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
  489. mac->beacon_enabled = 1;
  490. rtlpriv->cfg->ops->update_interrupt_mask(hw,
  491. rtlpriv->cfg->maps
  492. [RTL_IBSS_INT_MASKS],
  493. 0);
  494. if (rtlpriv->cfg->ops->linked_set_reg)
  495. rtlpriv->cfg->ops->linked_set_reg(hw);
  496. }
  497. }
  498. if ((changed & BSS_CHANGED_BEACON_ENABLED &&
  499. !bss_conf->enable_beacon)) {
  500. if (mac->beacon_enabled == 1) {
  501. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  502. ("ADHOC DISABLE BEACON\n"));
  503. mac->beacon_enabled = 0;
  504. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  505. rtlpriv->cfg->maps
  506. [RTL_IBSS_INT_MASKS]);
  507. }
  508. }
  509. if (changed & BSS_CHANGED_BEACON_INT) {
  510. RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
  511. ("BSS_CHANGED_BEACON_INT\n"));
  512. mac->beacon_interval = bss_conf->beacon_int;
  513. rtlpriv->cfg->ops->set_bcn_intv(hw);
  514. }
  515. }
  516. /*TODO: reference to enum ieee80211_bss_change */
  517. if (changed & BSS_CHANGED_ASSOC) {
  518. if (bss_conf->assoc) {
  519. /* we should reset all sec info & cam
  520. * before set cam after linked, we should not
  521. * reset in disassoc, that will cause tkip->wep
  522. * fail because some flag will be wrong */
  523. /* reset sec info */
  524. rtl_cam_reset_sec_info(hw);
  525. /* reset cam to fix wep fail issue
  526. * when change from wpa to wep */
  527. rtl_cam_reset_all_entry(hw);
  528. mac->link_state = MAC80211_LINKED;
  529. mac->cnt_after_linked = 0;
  530. mac->assoc_id = bss_conf->aid;
  531. memcpy(mac->bssid, bss_conf->bssid, 6);
  532. if (rtlpriv->cfg->ops->linked_set_reg)
  533. rtlpriv->cfg->ops->linked_set_reg(hw);
  534. if (mac->opmode == NL80211_IFTYPE_STATION && sta)
  535. rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
  536. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  537. ("BSS_CHANGED_ASSOC\n"));
  538. } else {
  539. if (mac->link_state == MAC80211_LINKED)
  540. rtl_lps_leave(hw);
  541. mac->link_state = MAC80211_NOLINK;
  542. memset(mac->bssid, 0, 6);
  543. /* reset sec info */
  544. rtl_cam_reset_sec_info(hw);
  545. rtl_cam_reset_all_entry(hw);
  546. mac->vendor = PEER_UNKNOWN;
  547. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  548. ("BSS_CHANGED_UN_ASSOC\n"));
  549. }
  550. }
  551. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  552. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  553. ("BSS_CHANGED_ERP_CTS_PROT\n"));
  554. mac->use_cts_protect = bss_conf->use_cts_prot;
  555. }
  556. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  557. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  558. ("BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
  559. bss_conf->use_short_preamble));
  560. mac->short_preamble = bss_conf->use_short_preamble;
  561. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
  562. (u8 *) (&mac->short_preamble));
  563. }
  564. if (changed & BSS_CHANGED_ERP_SLOT) {
  565. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  566. ("BSS_CHANGED_ERP_SLOT\n"));
  567. if (bss_conf->use_short_slot)
  568. mac->slot_time = RTL_SLOT_TIME_9;
  569. else
  570. mac->slot_time = RTL_SLOT_TIME_20;
  571. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  572. (u8 *) (&mac->slot_time));
  573. }
  574. if (changed & BSS_CHANGED_HT) {
  575. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  576. ("BSS_CHANGED_HT\n"));
  577. rcu_read_lock();
  578. sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
  579. if (sta) {
  580. if (sta->ht_cap.ampdu_density >
  581. mac->current_ampdu_density)
  582. mac->current_ampdu_density =
  583. sta->ht_cap.ampdu_density;
  584. if (sta->ht_cap.ampdu_factor <
  585. mac->current_ampdu_factor)
  586. mac->current_ampdu_factor =
  587. sta->ht_cap.ampdu_factor;
  588. }
  589. rcu_read_unlock();
  590. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
  591. (u8 *) (&mac->max_mss_density));
  592. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
  593. &mac->current_ampdu_factor);
  594. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
  595. &mac->current_ampdu_density);
  596. }
  597. if (changed & BSS_CHANGED_BSSID) {
  598. u32 basic_rates;
  599. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
  600. (u8 *) bss_conf->bssid);
  601. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  602. (MAC_FMT "\n", MAC_ARG(bss_conf->bssid)));
  603. mac->vendor = PEER_UNKNOWN;
  604. memcpy(mac->bssid, bss_conf->bssid, 6);
  605. rtlpriv->cfg->ops->set_network_type(hw, vif->type);
  606. rcu_read_lock();
  607. sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
  608. if (!sta) {
  609. rcu_read_unlock();
  610. goto out;
  611. }
  612. if (rtlhal->current_bandtype == BAND_ON_5G) {
  613. mac->mode = WIRELESS_MODE_A;
  614. } else {
  615. if (sta->supp_rates[0] <= 0xf)
  616. mac->mode = WIRELESS_MODE_B;
  617. else
  618. mac->mode = WIRELESS_MODE_G;
  619. }
  620. if (sta->ht_cap.ht_supported) {
  621. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  622. mac->mode = WIRELESS_MODE_N_24G;
  623. else
  624. mac->mode = WIRELESS_MODE_N_5G;
  625. }
  626. /* just station need it, because ibss & ap mode will
  627. * set in sta_add, and will be NULL here */
  628. if (mac->opmode == NL80211_IFTYPE_STATION) {
  629. struct rtl_sta_info *sta_entry;
  630. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  631. sta_entry->wireless_mode = mac->mode;
  632. }
  633. if (sta->ht_cap.ht_supported) {
  634. mac->ht_enable = true;
  635. /*
  636. * for cisco 1252 bw20 it's wrong
  637. * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  638. * mac->bw_40 = true;
  639. * }
  640. * */
  641. }
  642. if (changed & BSS_CHANGED_BASIC_RATES) {
  643. /* for 5G must << RATE_6M_INDEX=4,
  644. * because 5G have no cck rate*/
  645. if (rtlhal->current_bandtype == BAND_ON_5G)
  646. basic_rates = sta->supp_rates[1] << 4;
  647. else
  648. basic_rates = sta->supp_rates[0];
  649. mac->basic_rates = basic_rates;
  650. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  651. (u8 *) (&basic_rates));
  652. }
  653. rcu_read_unlock();
  654. }
  655. /*
  656. * For FW LPS:
  657. * To tell firmware we have connected
  658. * to an AP. For 92SE/CE power save v2.
  659. */
  660. if (changed & BSS_CHANGED_ASSOC) {
  661. if (bss_conf->assoc) {
  662. if (ppsc->fwctrl_lps) {
  663. u8 mstatus = RT_MEDIA_CONNECT;
  664. rtlpriv->cfg->ops->set_hw_reg(hw,
  665. HW_VAR_H2C_FW_JOINBSSRPT,
  666. (u8 *) (&mstatus));
  667. ppsc->report_linked = true;
  668. }
  669. } else {
  670. if (ppsc->fwctrl_lps) {
  671. u8 mstatus = RT_MEDIA_DISCONNECT;
  672. rtlpriv->cfg->ops->set_hw_reg(hw,
  673. HW_VAR_H2C_FW_JOINBSSRPT,
  674. (u8 *)(&mstatus));
  675. ppsc->report_linked = false;
  676. }
  677. }
  678. }
  679. out:
  680. mutex_unlock(&rtlpriv->locks.conf_mutex);
  681. }
  682. static u64 rtl_op_get_tsf(struct ieee80211_hw *hw)
  683. {
  684. struct rtl_priv *rtlpriv = rtl_priv(hw);
  685. u64 tsf;
  686. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
  687. return tsf;
  688. }
  689. static void rtl_op_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  690. {
  691. struct rtl_priv *rtlpriv = rtl_priv(hw);
  692. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  693. u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
  694. mac->tsf = tsf;
  695. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss));
  696. }
  697. static void rtl_op_reset_tsf(struct ieee80211_hw *hw)
  698. {
  699. struct rtl_priv *rtlpriv = rtl_priv(hw);
  700. u8 tmp = 0;
  701. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *) (&tmp));
  702. }
  703. static void rtl_op_sta_notify(struct ieee80211_hw *hw,
  704. struct ieee80211_vif *vif,
  705. enum sta_notify_cmd cmd,
  706. struct ieee80211_sta *sta)
  707. {
  708. switch (cmd) {
  709. case STA_NOTIFY_SLEEP:
  710. break;
  711. case STA_NOTIFY_AWAKE:
  712. break;
  713. default:
  714. break;
  715. }
  716. }
  717. static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
  718. struct ieee80211_vif *vif,
  719. enum ieee80211_ampdu_mlme_action action,
  720. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  721. u8 buf_size)
  722. {
  723. struct rtl_priv *rtlpriv = rtl_priv(hw);
  724. switch (action) {
  725. case IEEE80211_AMPDU_TX_START:
  726. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  727. ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid));
  728. return rtl_tx_agg_start(hw, sta, tid, ssn);
  729. break;
  730. case IEEE80211_AMPDU_TX_STOP:
  731. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  732. ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid));
  733. return rtl_tx_agg_stop(hw, sta, tid);
  734. break;
  735. case IEEE80211_AMPDU_TX_OPERATIONAL:
  736. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  737. ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid));
  738. rtl_tx_agg_oper(hw, sta, tid);
  739. break;
  740. case IEEE80211_AMPDU_RX_START:
  741. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  742. ("IEEE80211_AMPDU_RX_START:TID:%d\n", tid));
  743. break;
  744. case IEEE80211_AMPDU_RX_STOP:
  745. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  746. ("IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid));
  747. break;
  748. default:
  749. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  750. ("IEEE80211_AMPDU_ERR!!!!:\n"));
  751. return -EOPNOTSUPP;
  752. }
  753. return 0;
  754. }
  755. static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
  756. {
  757. struct rtl_priv *rtlpriv = rtl_priv(hw);
  758. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  759. mac->act_scanning = true;
  760. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
  761. if (mac->link_state == MAC80211_LINKED) {
  762. rtl_lps_leave(hw);
  763. mac->link_state = MAC80211_LINKED_SCANNING;
  764. } else {
  765. rtl_ips_nic_on(hw);
  766. }
  767. /* Dual mac */
  768. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  769. rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
  770. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
  771. }
  772. static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
  773. {
  774. struct rtl_priv *rtlpriv = rtl_priv(hw);
  775. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  776. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
  777. mac->act_scanning = false;
  778. /* Dual mac */
  779. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  780. if (mac->link_state == MAC80211_LINKED_SCANNING) {
  781. mac->link_state = MAC80211_LINKED;
  782. if (mac->opmode == NL80211_IFTYPE_STATION) {
  783. /* fix fwlps issue */
  784. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  785. }
  786. }
  787. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
  788. }
  789. static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  790. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  791. struct ieee80211_key_conf *key)
  792. {
  793. struct rtl_priv *rtlpriv = rtl_priv(hw);
  794. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  795. u8 key_type = NO_ENCRYPTION;
  796. u8 key_idx;
  797. bool group_key = false;
  798. bool wep_only = false;
  799. int err = 0;
  800. u8 mac_addr[ETH_ALEN];
  801. u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  802. u8 zero_addr[ETH_ALEN] = { 0 };
  803. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  804. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  805. ("not open hw encryption\n"));
  806. return -ENOSPC; /*User disabled HW-crypto */
  807. }
  808. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  809. ("%s hardware based encryption for keyidx: %d, mac: %pM\n",
  810. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  811. sta ? sta->addr : bcast_addr));
  812. rtlpriv->sec.being_setkey = true;
  813. rtl_ips_nic_on(hw);
  814. mutex_lock(&rtlpriv->locks.conf_mutex);
  815. /* <1> get encryption alg */
  816. switch (key->cipher) {
  817. case WLAN_CIPHER_SUITE_WEP40:
  818. key_type = WEP40_ENCRYPTION;
  819. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n"));
  820. break;
  821. case WLAN_CIPHER_SUITE_WEP104:
  822. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  823. ("alg:WEP104\n"));
  824. key_type = WEP104_ENCRYPTION;
  825. break;
  826. case WLAN_CIPHER_SUITE_TKIP:
  827. key_type = TKIP_ENCRYPTION;
  828. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n"));
  829. break;
  830. case WLAN_CIPHER_SUITE_CCMP:
  831. key_type = AESCCMP_ENCRYPTION;
  832. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n"));
  833. break;
  834. default:
  835. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  836. ("alg_err:%x!!!!:\n", key->cipher));
  837. goto out_unlock;
  838. }
  839. if (key_type == WEP40_ENCRYPTION ||
  840. key_type == WEP104_ENCRYPTION ||
  841. mac->opmode == NL80211_IFTYPE_ADHOC)
  842. rtlpriv->sec.use_defaultkey = true;
  843. /* <2> get key_idx */
  844. key_idx = (u8) (key->keyidx);
  845. if (key_idx > 3)
  846. goto out_unlock;
  847. /* <3> if pairwise key enable_hw_sec */
  848. group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  849. /* wep always be group key, but there are two conditions:
  850. * 1) wep only: is just for wep enc, in this condition
  851. * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
  852. * will be true & enable_hw_sec will be set when wep
  853. * ke setting.
  854. * 2) wep(group) + AES(pairwise): some AP like cisco
  855. * may use it, in this condition enable_hw_sec will not
  856. * be set when wep key setting */
  857. /* we must reset sec_info after lingked before set key,
  858. * or some flag will be wrong*/
  859. if (mac->opmode == NL80211_IFTYPE_AP) {
  860. if (!group_key || key_type == WEP40_ENCRYPTION ||
  861. key_type == WEP104_ENCRYPTION) {
  862. if (group_key)
  863. wep_only = true;
  864. rtlpriv->cfg->ops->enable_hw_sec(hw);
  865. }
  866. } else {
  867. if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
  868. rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
  869. if (rtlpriv->sec.pairwise_enc_algorithm ==
  870. NO_ENCRYPTION &&
  871. (key_type == WEP40_ENCRYPTION ||
  872. key_type == WEP104_ENCRYPTION))
  873. wep_only = true;
  874. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  875. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  876. ("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1"
  877. " TKIP:2 AES:4 WEP104:5)\n", key_type));
  878. rtlpriv->cfg->ops->enable_hw_sec(hw);
  879. }
  880. }
  881. /* <4> set key based on cmd */
  882. switch (cmd) {
  883. case SET_KEY:
  884. if (wep_only) {
  885. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  886. ("set WEP(group/pairwise) key\n"));
  887. /* Pairwise key with an assigned MAC address. */
  888. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  889. rtlpriv->sec.group_enc_algorithm = key_type;
  890. /*set local buf about wep key. */
  891. memcpy(rtlpriv->sec.key_buf[key_idx],
  892. key->key, key->keylen);
  893. rtlpriv->sec.key_len[key_idx] = key->keylen;
  894. memcpy(mac_addr, zero_addr, ETH_ALEN);
  895. } else if (group_key) { /* group key */
  896. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  897. ("set group key\n"));
  898. /* group key */
  899. rtlpriv->sec.group_enc_algorithm = key_type;
  900. /*set local buf about group key. */
  901. memcpy(rtlpriv->sec.key_buf[key_idx],
  902. key->key, key->keylen);
  903. rtlpriv->sec.key_len[key_idx] = key->keylen;
  904. memcpy(mac_addr, bcast_addr, ETH_ALEN);
  905. } else { /* pairwise key */
  906. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  907. ("set pairwise key\n"));
  908. if (!sta) {
  909. RT_ASSERT(false, ("pairwise key withnot"
  910. "mac_addr\n"));
  911. err = -EOPNOTSUPP;
  912. goto out_unlock;
  913. }
  914. /* Pairwise key with an assigned MAC address. */
  915. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  916. /*set local buf about pairwise key. */
  917. memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
  918. key->key, key->keylen);
  919. rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
  920. rtlpriv->sec.pairwise_key =
  921. rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
  922. memcpy(mac_addr, sta->addr, ETH_ALEN);
  923. }
  924. rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
  925. group_key, key_type, wep_only,
  926. false);
  927. /* <5> tell mac80211 do something: */
  928. /*must use sw generate IV, or can not work !!!!. */
  929. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  930. key->hw_key_idx = key_idx;
  931. if (key_type == TKIP_ENCRYPTION)
  932. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  933. break;
  934. case DISABLE_KEY:
  935. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  936. ("disable key delete one entry\n"));
  937. /*set local buf about wep key. */
  938. if (mac->opmode == NL80211_IFTYPE_AP) {
  939. if (sta)
  940. rtl_cam_del_entry(hw, sta->addr);
  941. }
  942. memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
  943. rtlpriv->sec.key_len[key_idx] = 0;
  944. memcpy(mac_addr, zero_addr, ETH_ALEN);
  945. /*
  946. *mac80211 will delete entrys one by one,
  947. *so don't use rtl_cam_reset_all_entry
  948. *or clear all entry here.
  949. */
  950. rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
  951. rtl_cam_reset_sec_info(hw);
  952. break;
  953. default:
  954. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  955. ("cmd_err:%x!!!!:\n", cmd));
  956. }
  957. out_unlock:
  958. mutex_unlock(&rtlpriv->locks.conf_mutex);
  959. rtlpriv->sec.being_setkey = false;
  960. return err;
  961. }
  962. static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
  963. {
  964. struct rtl_priv *rtlpriv = rtl_priv(hw);
  965. bool radio_state;
  966. bool blocked;
  967. u8 valid = 0;
  968. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  969. return;
  970. mutex_lock(&rtlpriv->locks.conf_mutex);
  971. /*if Radio On return true here */
  972. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  973. if (valid) {
  974. if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
  975. rtlpriv->rfkill.rfkill_state = radio_state;
  976. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  977. (KERN_INFO "wireless radio switch turned %s\n",
  978. radio_state ? "on" : "off"));
  979. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  980. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  981. }
  982. }
  983. mutex_unlock(&rtlpriv->locks.conf_mutex);
  984. }
  985. /* this function is called by mac80211 to flush tx buffer
  986. * before switch channle or power save, or tx buffer packet
  987. * maybe send after offchannel or rf sleep, this may cause
  988. * dis-association by AP */
  989. static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
  990. {
  991. struct rtl_priv *rtlpriv = rtl_priv(hw);
  992. if (rtlpriv->intf_ops->flush)
  993. rtlpriv->intf_ops->flush(hw, drop);
  994. }
  995. const struct ieee80211_ops rtl_ops = {
  996. .start = rtl_op_start,
  997. .stop = rtl_op_stop,
  998. .tx = rtl_op_tx,
  999. .add_interface = rtl_op_add_interface,
  1000. .remove_interface = rtl_op_remove_interface,
  1001. .config = rtl_op_config,
  1002. .configure_filter = rtl_op_configure_filter,
  1003. .sta_add = rtl_op_sta_add,
  1004. .sta_remove = rtl_op_sta_remove,
  1005. .set_key = rtl_op_set_key,
  1006. .conf_tx = rtl_op_conf_tx,
  1007. .bss_info_changed = rtl_op_bss_info_changed,
  1008. .get_tsf = rtl_op_get_tsf,
  1009. .set_tsf = rtl_op_set_tsf,
  1010. .reset_tsf = rtl_op_reset_tsf,
  1011. .sta_notify = rtl_op_sta_notify,
  1012. .ampdu_action = rtl_op_ampdu_action,
  1013. .sw_scan_start = rtl_op_sw_scan_start,
  1014. .sw_scan_complete = rtl_op_sw_scan_complete,
  1015. .rfkill_poll = rtl_op_rfkill_poll,
  1016. .flush = rtl_op_flush,
  1017. };