core.c 38 KB

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