core.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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.chandef.chan;
  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 (cfg80211_get_chandef_type(&hw->conf.chandef)) {
  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. cfg80211_get_chandef_type(&hw->conf.chandef));
  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. rtlpriv->enter_ps = false;
  659. schedule_work(&rtlpriv->works.lps_change_work);
  660. }
  661. if (ppsc->p2p_ps_info.p2p_ps_mode > P2P_PS_NONE)
  662. rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE);
  663. mac->link_state = MAC80211_NOLINK;
  664. memset(mac->bssid, 0, 6);
  665. mac->vendor = PEER_UNKNOWN;
  666. if (rtlpriv->dm.supp_phymode_switch) {
  667. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  668. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  669. }
  670. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  671. "BSS_CHANGED_UN_ASSOC\n");
  672. }
  673. }
  674. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  675. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  676. "BSS_CHANGED_ERP_CTS_PROT\n");
  677. mac->use_cts_protect = bss_conf->use_cts_prot;
  678. }
  679. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  680. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  681. "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
  682. bss_conf->use_short_preamble);
  683. mac->short_preamble = bss_conf->use_short_preamble;
  684. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
  685. &mac->short_preamble);
  686. }
  687. if (changed & BSS_CHANGED_ERP_SLOT) {
  688. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  689. "BSS_CHANGED_ERP_SLOT\n");
  690. if (bss_conf->use_short_slot)
  691. mac->slot_time = RTL_SLOT_TIME_9;
  692. else
  693. mac->slot_time = RTL_SLOT_TIME_20;
  694. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  695. &mac->slot_time);
  696. }
  697. if (changed & BSS_CHANGED_HT) {
  698. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, "BSS_CHANGED_HT\n");
  699. rcu_read_lock();
  700. sta = get_sta(hw, vif, bss_conf->bssid);
  701. if (sta) {
  702. if (sta->ht_cap.ampdu_density >
  703. mac->current_ampdu_density)
  704. mac->current_ampdu_density =
  705. sta->ht_cap.ampdu_density;
  706. if (sta->ht_cap.ampdu_factor <
  707. mac->current_ampdu_factor)
  708. mac->current_ampdu_factor =
  709. sta->ht_cap.ampdu_factor;
  710. }
  711. rcu_read_unlock();
  712. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
  713. &mac->max_mss_density);
  714. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
  715. &mac->current_ampdu_factor);
  716. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
  717. &mac->current_ampdu_density);
  718. }
  719. if (changed & BSS_CHANGED_BSSID) {
  720. u32 basic_rates;
  721. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
  722. (u8 *) bss_conf->bssid);
  723. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, "%pM\n",
  724. bss_conf->bssid);
  725. mac->vendor = PEER_UNKNOWN;
  726. memcpy(mac->bssid, bss_conf->bssid, 6);
  727. rtlpriv->cfg->ops->set_network_type(hw, vif->type);
  728. rcu_read_lock();
  729. sta = get_sta(hw, vif, bss_conf->bssid);
  730. if (!sta) {
  731. rcu_read_unlock();
  732. goto out;
  733. }
  734. if (rtlhal->current_bandtype == BAND_ON_5G) {
  735. mac->mode = WIRELESS_MODE_A;
  736. } else {
  737. if (sta->supp_rates[0] <= 0xf)
  738. mac->mode = WIRELESS_MODE_B;
  739. else
  740. mac->mode = WIRELESS_MODE_G;
  741. }
  742. if (sta->ht_cap.ht_supported) {
  743. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  744. mac->mode = WIRELESS_MODE_N_24G;
  745. else
  746. mac->mode = WIRELESS_MODE_N_5G;
  747. }
  748. /* just station need it, because ibss & ap mode will
  749. * set in sta_add, and will be NULL here */
  750. if (mac->opmode == NL80211_IFTYPE_STATION) {
  751. struct rtl_sta_info *sta_entry;
  752. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  753. sta_entry->wireless_mode = mac->mode;
  754. }
  755. if (sta->ht_cap.ht_supported) {
  756. mac->ht_enable = true;
  757. /*
  758. * for cisco 1252 bw20 it's wrong
  759. * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  760. * mac->bw_40 = true;
  761. * }
  762. * */
  763. }
  764. if (changed & BSS_CHANGED_BASIC_RATES) {
  765. /* for 5G must << RATE_6M_INDEX = 4,
  766. * because 5G have no cck rate*/
  767. if (rtlhal->current_bandtype == BAND_ON_5G)
  768. basic_rates = sta->supp_rates[1] << 4;
  769. else
  770. basic_rates = sta->supp_rates[0];
  771. mac->basic_rates = basic_rates;
  772. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  773. (u8 *) (&basic_rates));
  774. }
  775. rcu_read_unlock();
  776. }
  777. /*
  778. * For FW LPS:
  779. * To tell firmware we have connected
  780. * to an AP. For 92SE/CE power save v2.
  781. */
  782. if (changed & BSS_CHANGED_ASSOC) {
  783. if (bss_conf->assoc) {
  784. if (ppsc->fwctrl_lps) {
  785. u8 mstatus = RT_MEDIA_CONNECT;
  786. rtlpriv->cfg->ops->set_hw_reg(hw,
  787. HW_VAR_H2C_FW_JOINBSSRPT,
  788. &mstatus);
  789. ppsc->report_linked = true;
  790. }
  791. } else {
  792. if (ppsc->fwctrl_lps) {
  793. u8 mstatus = RT_MEDIA_DISCONNECT;
  794. rtlpriv->cfg->ops->set_hw_reg(hw,
  795. HW_VAR_H2C_FW_JOINBSSRPT,
  796. &mstatus);
  797. ppsc->report_linked = false;
  798. }
  799. }
  800. if (rtlpriv->cfg->ops->bt_wifi_media_status_notify)
  801. rtlpriv->cfg->ops->bt_wifi_media_status_notify(hw,
  802. ppsc->report_linked);
  803. }
  804. out:
  805. mutex_unlock(&rtlpriv->locks.conf_mutex);
  806. }
  807. static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  808. {
  809. struct rtl_priv *rtlpriv = rtl_priv(hw);
  810. u64 tsf;
  811. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
  812. return tsf;
  813. }
  814. static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  815. u64 tsf)
  816. {
  817. struct rtl_priv *rtlpriv = rtl_priv(hw);
  818. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  819. u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
  820. mac->tsf = tsf;
  821. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, &bibss);
  822. }
  823. static void rtl_op_reset_tsf(struct ieee80211_hw *hw,
  824. struct ieee80211_vif *vif)
  825. {
  826. struct rtl_priv *rtlpriv = rtl_priv(hw);
  827. u8 tmp = 0;
  828. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, &tmp);
  829. }
  830. static void rtl_op_sta_notify(struct ieee80211_hw *hw,
  831. struct ieee80211_vif *vif,
  832. enum sta_notify_cmd cmd,
  833. struct ieee80211_sta *sta)
  834. {
  835. switch (cmd) {
  836. case STA_NOTIFY_SLEEP:
  837. break;
  838. case STA_NOTIFY_AWAKE:
  839. break;
  840. default:
  841. break;
  842. }
  843. }
  844. static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
  845. struct ieee80211_vif *vif,
  846. enum ieee80211_ampdu_mlme_action action,
  847. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  848. u8 buf_size)
  849. {
  850. struct rtl_priv *rtlpriv = rtl_priv(hw);
  851. switch (action) {
  852. case IEEE80211_AMPDU_TX_START:
  853. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  854. "IEEE80211_AMPDU_TX_START: TID:%d\n", tid);
  855. return rtl_tx_agg_start(hw, sta, tid, ssn);
  856. break;
  857. case IEEE80211_AMPDU_TX_STOP_CONT:
  858. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  859. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  860. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  861. "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
  862. return rtl_tx_agg_stop(hw, sta, tid);
  863. case IEEE80211_AMPDU_TX_OPERATIONAL:
  864. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  865. "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
  866. rtl_tx_agg_oper(hw, sta, tid);
  867. break;
  868. case IEEE80211_AMPDU_RX_START:
  869. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  870. "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
  871. return rtl_rx_agg_start(hw, sta, tid);
  872. case IEEE80211_AMPDU_RX_STOP:
  873. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  874. "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
  875. return rtl_rx_agg_stop(hw, sta, tid);
  876. default:
  877. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  878. "IEEE80211_AMPDU_ERR!!!!:\n");
  879. return -EOPNOTSUPP;
  880. }
  881. return 0;
  882. }
  883. static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
  884. {
  885. struct rtl_priv *rtlpriv = rtl_priv(hw);
  886. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  887. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  888. mac->act_scanning = true;
  889. if (rtlpriv->link_info.higher_busytraffic) {
  890. mac->skip_scan = true;
  891. return;
  892. }
  893. if (rtlpriv->dm.supp_phymode_switch) {
  894. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  895. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  896. }
  897. if (mac->link_state == MAC80211_LINKED) {
  898. rtlpriv->enter_ps = false;
  899. schedule_work(&rtlpriv->works.lps_change_work);
  900. mac->link_state = MAC80211_LINKED_SCANNING;
  901. } else {
  902. rtl_ips_nic_on(hw);
  903. }
  904. /* Dual mac */
  905. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  906. rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
  907. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
  908. }
  909. static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
  910. {
  911. struct rtl_priv *rtlpriv = rtl_priv(hw);
  912. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  913. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  914. mac->act_scanning = false;
  915. mac->skip_scan = false;
  916. if (rtlpriv->link_info.higher_busytraffic)
  917. return;
  918. /*p2p will use 1/6/11 to scan */
  919. if (mac->n_channels == 3)
  920. mac->p2p_in_use = true;
  921. else
  922. mac->p2p_in_use = false;
  923. mac->n_channels = 0;
  924. /* Dual mac */
  925. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  926. if (mac->link_state == MAC80211_LINKED_SCANNING) {
  927. mac->link_state = MAC80211_LINKED;
  928. if (mac->opmode == NL80211_IFTYPE_STATION) {
  929. /* fix fwlps issue */
  930. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  931. }
  932. }
  933. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
  934. }
  935. static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  936. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  937. struct ieee80211_key_conf *key)
  938. {
  939. struct rtl_priv *rtlpriv = rtl_priv(hw);
  940. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  941. u8 key_type = NO_ENCRYPTION;
  942. u8 key_idx;
  943. bool group_key = false;
  944. bool wep_only = false;
  945. int err = 0;
  946. u8 mac_addr[ETH_ALEN];
  947. u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  948. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  949. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  950. "not open hw encryption\n");
  951. return -ENOSPC; /*User disabled HW-crypto */
  952. }
  953. /* To support IBSS, use sw-crypto for GTK */
  954. if (((vif->type == NL80211_IFTYPE_ADHOC) ||
  955. (vif->type == NL80211_IFTYPE_MESH_POINT)) &&
  956. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  957. return -ENOSPC;
  958. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  959. "%s hardware based encryption for keyidx: %d, mac: %pM\n",
  960. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  961. sta ? sta->addr : bcast_addr);
  962. rtlpriv->sec.being_setkey = true;
  963. rtl_ips_nic_on(hw);
  964. mutex_lock(&rtlpriv->locks.conf_mutex);
  965. /* <1> get encryption alg */
  966. switch (key->cipher) {
  967. case WLAN_CIPHER_SUITE_WEP40:
  968. key_type = WEP40_ENCRYPTION;
  969. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
  970. break;
  971. case WLAN_CIPHER_SUITE_WEP104:
  972. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
  973. key_type = WEP104_ENCRYPTION;
  974. break;
  975. case WLAN_CIPHER_SUITE_TKIP:
  976. key_type = TKIP_ENCRYPTION;
  977. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
  978. break;
  979. case WLAN_CIPHER_SUITE_CCMP:
  980. key_type = AESCCMP_ENCRYPTION;
  981. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
  982. break;
  983. case WLAN_CIPHER_SUITE_AES_CMAC:
  984. /*HW doesn't support CMAC encryption, use software CMAC */
  985. key_type = AESCMAC_ENCRYPTION;
  986. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n");
  987. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  988. "HW don't support CMAC encryption, use software CMAC\n");
  989. err = -EOPNOTSUPP;
  990. goto out_unlock;
  991. default:
  992. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n",
  993. key->cipher);
  994. goto out_unlock;
  995. }
  996. if (key_type == WEP40_ENCRYPTION ||
  997. key_type == WEP104_ENCRYPTION ||
  998. mac->opmode == NL80211_IFTYPE_ADHOC)
  999. rtlpriv->sec.use_defaultkey = true;
  1000. /* <2> get key_idx */
  1001. key_idx = (u8) (key->keyidx);
  1002. if (key_idx > 3)
  1003. goto out_unlock;
  1004. /* <3> if pairwise key enable_hw_sec */
  1005. group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  1006. /* wep always be group key, but there are two conditions:
  1007. * 1) wep only: is just for wep enc, in this condition
  1008. * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
  1009. * will be true & enable_hw_sec will be set when wep
  1010. * key setting.
  1011. * 2) wep(group) + AES(pairwise): some AP like cisco
  1012. * may use it, in this condition enable_hw_sec will not
  1013. * be set when wep key setting */
  1014. /* we must reset sec_info after lingked before set key,
  1015. * or some flag will be wrong*/
  1016. if (vif->type == NL80211_IFTYPE_AP ||
  1017. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1018. if (!group_key || key_type == WEP40_ENCRYPTION ||
  1019. key_type == WEP104_ENCRYPTION) {
  1020. if (group_key)
  1021. wep_only = true;
  1022. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1023. }
  1024. } else {
  1025. if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
  1026. rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
  1027. if (rtlpriv->sec.pairwise_enc_algorithm ==
  1028. NO_ENCRYPTION &&
  1029. (key_type == WEP40_ENCRYPTION ||
  1030. key_type == WEP104_ENCRYPTION))
  1031. wep_only = true;
  1032. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1033. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1034. "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
  1035. key_type);
  1036. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1037. }
  1038. }
  1039. /* <4> set key based on cmd */
  1040. switch (cmd) {
  1041. case SET_KEY:
  1042. if (wep_only) {
  1043. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1044. "set WEP(group/pairwise) key\n");
  1045. /* Pairwise key with an assigned MAC address. */
  1046. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1047. rtlpriv->sec.group_enc_algorithm = key_type;
  1048. /*set local buf about wep key. */
  1049. memcpy(rtlpriv->sec.key_buf[key_idx],
  1050. key->key, key->keylen);
  1051. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1052. eth_zero_addr(mac_addr);
  1053. } else if (group_key) { /* group key */
  1054. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1055. "set group key\n");
  1056. /* group key */
  1057. rtlpriv->sec.group_enc_algorithm = key_type;
  1058. /*set local buf about group key. */
  1059. memcpy(rtlpriv->sec.key_buf[key_idx],
  1060. key->key, key->keylen);
  1061. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1062. memcpy(mac_addr, bcast_addr, ETH_ALEN);
  1063. } else { /* pairwise key */
  1064. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1065. "set pairwise key\n");
  1066. if (!sta) {
  1067. RT_ASSERT(false,
  1068. "pairwise key without mac_addr\n");
  1069. err = -EOPNOTSUPP;
  1070. goto out_unlock;
  1071. }
  1072. /* Pairwise key with an assigned MAC address. */
  1073. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1074. /*set local buf about pairwise key. */
  1075. memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
  1076. key->key, key->keylen);
  1077. rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
  1078. rtlpriv->sec.pairwise_key =
  1079. rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
  1080. memcpy(mac_addr, sta->addr, ETH_ALEN);
  1081. }
  1082. rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
  1083. group_key, key_type, wep_only,
  1084. false);
  1085. /* <5> tell mac80211 do something: */
  1086. /*must use sw generate IV, or can not work !!!!. */
  1087. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1088. key->hw_key_idx = key_idx;
  1089. if (key_type == TKIP_ENCRYPTION)
  1090. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1091. /*use software CCMP encryption for management frames (MFP) */
  1092. if (key_type == AESCCMP_ENCRYPTION)
  1093. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1094. break;
  1095. case DISABLE_KEY:
  1096. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1097. "disable key delete one entry\n");
  1098. /*set local buf about wep key. */
  1099. if (vif->type == NL80211_IFTYPE_AP ||
  1100. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1101. if (sta)
  1102. rtl_cam_del_entry(hw, sta->addr);
  1103. }
  1104. memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
  1105. rtlpriv->sec.key_len[key_idx] = 0;
  1106. eth_zero_addr(mac_addr);
  1107. /*
  1108. *mac80211 will delete entrys one by one,
  1109. *so don't use rtl_cam_reset_all_entry
  1110. *or clear all entry here.
  1111. */
  1112. rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
  1113. rtl_cam_reset_sec_info(hw);
  1114. break;
  1115. default:
  1116. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1117. "cmd_err:%x!!!!\n", cmd);
  1118. }
  1119. out_unlock:
  1120. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1121. rtlpriv->sec.being_setkey = false;
  1122. return err;
  1123. }
  1124. static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
  1125. {
  1126. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1127. bool radio_state;
  1128. bool blocked;
  1129. u8 valid = 0;
  1130. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1131. return;
  1132. mutex_lock(&rtlpriv->locks.conf_mutex);
  1133. /*if Radio On return true here */
  1134. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  1135. if (valid) {
  1136. if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
  1137. rtlpriv->rfkill.rfkill_state = radio_state;
  1138. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1139. "wireless radio switch turned %s\n",
  1140. radio_state ? "on" : "off");
  1141. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  1142. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  1143. }
  1144. }
  1145. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1146. }
  1147. /* this function is called by mac80211 to flush tx buffer
  1148. * before switch channel or power save, or tx buffer packet
  1149. * maybe send after offchannel or rf sleep, this may cause
  1150. * dis-association by AP */
  1151. static void rtl_op_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  1152. {
  1153. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1154. if (rtlpriv->intf_ops->flush)
  1155. rtlpriv->intf_ops->flush(hw, drop);
  1156. }
  1157. const struct ieee80211_ops rtl_ops = {
  1158. .start = rtl_op_start,
  1159. .stop = rtl_op_stop,
  1160. .tx = rtl_op_tx,
  1161. .add_interface = rtl_op_add_interface,
  1162. .remove_interface = rtl_op_remove_interface,
  1163. .change_interface = rtl_op_change_interface,
  1164. .config = rtl_op_config,
  1165. .configure_filter = rtl_op_configure_filter,
  1166. .sta_add = rtl_op_sta_add,
  1167. .sta_remove = rtl_op_sta_remove,
  1168. .set_key = rtl_op_set_key,
  1169. .conf_tx = rtl_op_conf_tx,
  1170. .bss_info_changed = rtl_op_bss_info_changed,
  1171. .get_tsf = rtl_op_get_tsf,
  1172. .set_tsf = rtl_op_set_tsf,
  1173. .reset_tsf = rtl_op_reset_tsf,
  1174. .sta_notify = rtl_op_sta_notify,
  1175. .ampdu_action = rtl_op_ampdu_action,
  1176. .sw_scan_start = rtl_op_sw_scan_start,
  1177. .sw_scan_complete = rtl_op_sw_scan_complete,
  1178. .rfkill_poll = rtl_op_rfkill_poll,
  1179. .flush = rtl_op_flush,
  1180. };
  1181. EXPORT_SYMBOL_GPL(rtl_ops);