core.c 38 KB

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