core.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "wifi.h"
  26. #include "core.h"
  27. #include "cam.h"
  28. #include "base.h"
  29. #include "ps.h"
  30. #include "pwrseqcmd.h"
  31. #include "btcoexist/rtl_btc.h"
  32. #include <linux/firmware.h>
  33. #include <linux/export.h>
  34. #include <net/cfg80211.h>
  35. void rtl_addr_delay(u32 addr)
  36. {
  37. if (addr == 0xfe)
  38. mdelay(50);
  39. else if (addr == 0xfd)
  40. mdelay(5);
  41. else if (addr == 0xfc)
  42. mdelay(1);
  43. else if (addr == 0xfb)
  44. udelay(50);
  45. else if (addr == 0xfa)
  46. udelay(5);
  47. else if (addr == 0xf9)
  48. udelay(1);
  49. }
  50. EXPORT_SYMBOL(rtl_addr_delay);
  51. void rtl_rfreg_delay(struct ieee80211_hw *hw, enum radio_path rfpath, u32 addr,
  52. u32 mask, u32 data)
  53. {
  54. if (addr == 0xfe) {
  55. mdelay(50);
  56. } else if (addr == 0xfd) {
  57. mdelay(5);
  58. } else if (addr == 0xfc) {
  59. mdelay(1);
  60. } else if (addr == 0xfb) {
  61. udelay(50);
  62. } else if (addr == 0xfa) {
  63. udelay(5);
  64. } else if (addr == 0xf9) {
  65. udelay(1);
  66. } else {
  67. rtl_set_rfreg(hw, rfpath, addr, mask, data);
  68. udelay(1);
  69. }
  70. }
  71. EXPORT_SYMBOL(rtl_rfreg_delay);
  72. void rtl_bb_delay(struct ieee80211_hw *hw, u32 addr, u32 data)
  73. {
  74. if (addr == 0xfe) {
  75. mdelay(50);
  76. } else if (addr == 0xfd) {
  77. mdelay(5);
  78. } else if (addr == 0xfc) {
  79. mdelay(1);
  80. } else if (addr == 0xfb) {
  81. udelay(50);
  82. } else if (addr == 0xfa) {
  83. udelay(5);
  84. } else if (addr == 0xf9) {
  85. udelay(1);
  86. } else {
  87. rtl_set_bbreg(hw, addr, MASKDWORD, data);
  88. udelay(1);
  89. }
  90. }
  91. EXPORT_SYMBOL(rtl_bb_delay);
  92. void rtl_fw_cb(const struct firmware *firmware, void *context)
  93. {
  94. struct ieee80211_hw *hw = context;
  95. struct rtl_priv *rtlpriv = rtl_priv(hw);
  96. int err;
  97. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  98. "Firmware callback routine entered!\n");
  99. complete(&rtlpriv->firmware_loading_complete);
  100. if (!firmware) {
  101. if (rtlpriv->cfg->alt_fw_name) {
  102. err = request_firmware(&firmware,
  103. rtlpriv->cfg->alt_fw_name,
  104. rtlpriv->io.dev);
  105. pr_info("Loading alternative firmware %s\n",
  106. rtlpriv->cfg->alt_fw_name);
  107. if (!err)
  108. goto found_alt;
  109. }
  110. pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name);
  111. rtlpriv->max_fw_size = 0;
  112. return;
  113. }
  114. found_alt:
  115. if (firmware->size > rtlpriv->max_fw_size) {
  116. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  117. "Firmware is too big!\n");
  118. release_firmware(firmware);
  119. return;
  120. }
  121. memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, firmware->size);
  122. rtlpriv->rtlhal.fwsize = firmware->size;
  123. release_firmware(firmware);
  124. }
  125. EXPORT_SYMBOL(rtl_fw_cb);
  126. /*mutex for start & stop is must here. */
  127. static int rtl_op_start(struct ieee80211_hw *hw)
  128. {
  129. int err = 0;
  130. struct rtl_priv *rtlpriv = rtl_priv(hw);
  131. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  132. if (!is_hal_stop(rtlhal))
  133. return 0;
  134. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  135. return 0;
  136. mutex_lock(&rtlpriv->locks.conf_mutex);
  137. err = rtlpriv->intf_ops->adapter_start(hw);
  138. if (!err)
  139. rtl_watch_dog_timer_callback((unsigned long)hw);
  140. mutex_unlock(&rtlpriv->locks.conf_mutex);
  141. return err;
  142. }
  143. static void rtl_op_stop(struct ieee80211_hw *hw)
  144. {
  145. struct rtl_priv *rtlpriv = rtl_priv(hw);
  146. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  147. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  148. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  149. bool support_remote_wakeup = false;
  150. if (is_hal_stop(rtlhal))
  151. return;
  152. rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
  153. (u8 *)(&support_remote_wakeup));
  154. /* here is must, because adhoc do stop and start,
  155. * but stop with RFOFF may cause something wrong,
  156. * like adhoc TP
  157. */
  158. if (unlikely(ppsc->rfpwr_state == ERFOFF))
  159. rtl_ips_nic_on(hw);
  160. mutex_lock(&rtlpriv->locks.conf_mutex);
  161. /* if wowlan supported, DON'T clear connected info */
  162. if (!(support_remote_wakeup &&
  163. rtlhal->enter_pnp_sleep)) {
  164. mac->link_state = MAC80211_NOLINK;
  165. memset(mac->bssid, 0, 6);
  166. mac->vendor = PEER_UNKNOWN;
  167. /* reset sec info */
  168. rtl_cam_reset_sec_info(hw);
  169. rtl_deinit_deferred_work(hw);
  170. }
  171. rtlpriv->intf_ops->adapter_stop(hw);
  172. mutex_unlock(&rtlpriv->locks.conf_mutex);
  173. }
  174. static void rtl_op_tx(struct ieee80211_hw *hw,
  175. struct ieee80211_tx_control *control,
  176. struct sk_buff *skb)
  177. {
  178. struct rtl_priv *rtlpriv = rtl_priv(hw);
  179. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  180. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  181. struct rtl_tcb_desc tcb_desc;
  182. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  183. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  184. goto err_free;
  185. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  186. goto err_free;
  187. if (!rtlpriv->intf_ops->waitq_insert(hw, control->sta, skb))
  188. rtlpriv->intf_ops->adapter_tx(hw, control->sta, skb, &tcb_desc);
  189. return;
  190. err_free:
  191. dev_kfree_skb_any(skb);
  192. }
  193. static int rtl_op_add_interface(struct ieee80211_hw *hw,
  194. struct ieee80211_vif *vif)
  195. {
  196. struct rtl_priv *rtlpriv = rtl_priv(hw);
  197. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  198. int err = 0;
  199. if (mac->vif) {
  200. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  201. "vif has been set!! mac->vif = 0x%p\n", mac->vif);
  202. return -EOPNOTSUPP;
  203. }
  204. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
  205. rtl_ips_nic_on(hw);
  206. mutex_lock(&rtlpriv->locks.conf_mutex);
  207. switch (ieee80211_vif_type_p2p(vif)) {
  208. case NL80211_IFTYPE_P2P_CLIENT:
  209. mac->p2p = P2P_ROLE_CLIENT;
  210. /*fall through*/
  211. case NL80211_IFTYPE_STATION:
  212. if (mac->beacon_enabled == 1) {
  213. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  214. "NL80211_IFTYPE_STATION\n");
  215. mac->beacon_enabled = 0;
  216. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  217. rtlpriv->cfg->maps[RTL_IBSS_INT_MASKS]);
  218. }
  219. break;
  220. case NL80211_IFTYPE_ADHOC:
  221. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  222. "NL80211_IFTYPE_ADHOC\n");
  223. mac->link_state = MAC80211_LINKED;
  224. rtlpriv->cfg->ops->set_bcn_reg(hw);
  225. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  226. mac->basic_rates = 0xfff;
  227. else
  228. mac->basic_rates = 0xff0;
  229. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  230. (u8 *)(&mac->basic_rates));
  231. break;
  232. case NL80211_IFTYPE_P2P_GO:
  233. mac->p2p = P2P_ROLE_GO;
  234. /*fall through*/
  235. case NL80211_IFTYPE_AP:
  236. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  237. "NL80211_IFTYPE_AP\n");
  238. mac->link_state = MAC80211_LINKED;
  239. rtlpriv->cfg->ops->set_bcn_reg(hw);
  240. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  241. mac->basic_rates = 0xfff;
  242. else
  243. mac->basic_rates = 0xff0;
  244. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  245. (u8 *)(&mac->basic_rates));
  246. break;
  247. case NL80211_IFTYPE_MESH_POINT:
  248. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  249. "NL80211_IFTYPE_MESH_POINT\n");
  250. mac->link_state = MAC80211_LINKED;
  251. rtlpriv->cfg->ops->set_bcn_reg(hw);
  252. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  253. mac->basic_rates = 0xfff;
  254. else
  255. mac->basic_rates = 0xff0;
  256. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  257. (u8 *)(&mac->basic_rates));
  258. break;
  259. default:
  260. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  261. "operation mode %d is not support!\n", vif->type);
  262. err = -EOPNOTSUPP;
  263. goto out;
  264. }
  265. if (mac->p2p) {
  266. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  267. "p2p role %x\n", vif->type);
  268. mac->basic_rates = 0xff0;/*disable cck rate for p2p*/
  269. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  270. (u8 *)(&mac->basic_rates));
  271. }
  272. mac->vif = vif;
  273. mac->opmode = vif->type;
  274. rtlpriv->cfg->ops->set_network_type(hw, vif->type);
  275. memcpy(mac->mac_addr, vif->addr, ETH_ALEN);
  276. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  277. out:
  278. mutex_unlock(&rtlpriv->locks.conf_mutex);
  279. return err;
  280. }
  281. static void rtl_op_remove_interface(struct ieee80211_hw *hw,
  282. struct ieee80211_vif *vif)
  283. {
  284. struct rtl_priv *rtlpriv = rtl_priv(hw);
  285. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  286. mutex_lock(&rtlpriv->locks.conf_mutex);
  287. /* Free beacon resources */
  288. if ((vif->type == NL80211_IFTYPE_AP) ||
  289. (vif->type == NL80211_IFTYPE_ADHOC) ||
  290. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  291. if (mac->beacon_enabled == 1) {
  292. mac->beacon_enabled = 0;
  293. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  294. rtlpriv->cfg->maps[RTL_IBSS_INT_MASKS]);
  295. }
  296. }
  297. /*
  298. *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
  299. *NO LINK for our hardware.
  300. */
  301. mac->p2p = 0;
  302. mac->vif = NULL;
  303. mac->link_state = MAC80211_NOLINK;
  304. memset(mac->bssid, 0, ETH_ALEN);
  305. mac->vendor = PEER_UNKNOWN;
  306. mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
  307. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  308. mutex_unlock(&rtlpriv->locks.conf_mutex);
  309. }
  310. static int rtl_op_change_interface(struct ieee80211_hw *hw,
  311. struct ieee80211_vif *vif,
  312. enum nl80211_iftype new_type, bool p2p)
  313. {
  314. struct rtl_priv *rtlpriv = rtl_priv(hw);
  315. int ret;
  316. rtl_op_remove_interface(hw, vif);
  317. vif->type = new_type;
  318. vif->p2p = p2p;
  319. ret = rtl_op_add_interface(hw, vif);
  320. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  321. "p2p %x\n", p2p);
  322. return ret;
  323. }
  324. #ifdef CONFIG_PM
  325. static u16 crc16_ccitt(u8 data, u16 crc)
  326. {
  327. u8 shift_in, data_bit, crc_bit11, crc_bit4, crc_bit15;
  328. u8 i;
  329. u16 result;
  330. for (i = 0; i < 8; i++) {
  331. crc_bit15 = ((crc & BIT(15)) ? 1 : 0);
  332. data_bit = (data & (BIT(0) << i) ? 1 : 0);
  333. shift_in = crc_bit15 ^ data_bit;
  334. result = crc << 1;
  335. if (shift_in == 0)
  336. result &= (~BIT(0));
  337. else
  338. result |= BIT(0);
  339. crc_bit11 = ((crc & BIT(11)) ? 1 : 0) ^ shift_in;
  340. if (crc_bit11 == 0)
  341. result &= (~BIT(12));
  342. else
  343. result |= BIT(12);
  344. crc_bit4 = ((crc & BIT(4)) ? 1 : 0) ^ shift_in;
  345. if (crc_bit4 == 0)
  346. result &= (~BIT(5));
  347. else
  348. result |= BIT(5);
  349. crc = result;
  350. }
  351. return crc;
  352. }
  353. static u16 _calculate_wol_pattern_crc(u8 *pattern, u16 len)
  354. {
  355. u16 crc = 0xffff;
  356. u32 i;
  357. for (i = 0; i < len; i++)
  358. crc = crc16_ccitt(pattern[i], crc);
  359. crc = ~crc;
  360. return crc;
  361. }
  362. static void _rtl_add_wowlan_patterns(struct ieee80211_hw *hw,
  363. struct cfg80211_wowlan *wow)
  364. {
  365. struct rtl_priv *rtlpriv = rtl_priv(hw);
  366. struct rtl_mac *mac = &rtlpriv->mac80211;
  367. struct cfg80211_pkt_pattern *patterns = wow->patterns;
  368. struct rtl_wow_pattern rtl_pattern;
  369. const u8 *pattern_os, *mask_os;
  370. u8 mask[MAX_WOL_BIT_MASK_SIZE] = {0};
  371. u8 content[MAX_WOL_PATTERN_SIZE] = {0};
  372. u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  373. u8 multicast_addr1[2] = {0x33, 0x33};
  374. u8 multicast_addr2[3] = {0x01, 0x00, 0x5e};
  375. u8 i, mask_len;
  376. u16 j, len;
  377. for (i = 0; i < wow->n_patterns; i++) {
  378. memset(&rtl_pattern, 0, sizeof(struct rtl_wow_pattern));
  379. memset(mask, 0, MAX_WOL_BIT_MASK_SIZE);
  380. if (patterns[i].pattern_len > MAX_WOL_PATTERN_SIZE) {
  381. RT_TRACE(rtlpriv, COMP_POWER, DBG_WARNING,
  382. "Pattern[%d] is too long\n", i);
  383. continue;
  384. }
  385. pattern_os = patterns[i].pattern;
  386. mask_len = DIV_ROUND_UP(patterns[i].pattern_len, 8);
  387. mask_os = patterns[i].mask;
  388. RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE,
  389. "pattern content\n", pattern_os,
  390. patterns[i].pattern_len);
  391. RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE,
  392. "mask content\n", mask_os, mask_len);
  393. /* 1. unicast? multicast? or broadcast? */
  394. if (memcmp(pattern_os, broadcast_addr, 6) == 0)
  395. rtl_pattern.type = BROADCAST_PATTERN;
  396. else if (memcmp(pattern_os, multicast_addr1, 2) == 0 ||
  397. memcmp(pattern_os, multicast_addr2, 3) == 0)
  398. rtl_pattern.type = MULTICAST_PATTERN;
  399. else if (memcmp(pattern_os, mac->mac_addr, 6) == 0)
  400. rtl_pattern.type = UNICAST_PATTERN;
  401. else
  402. rtl_pattern.type = UNKNOWN_TYPE;
  403. /* 2. translate mask_from_os to mask_for_hw */
  404. /******************************************************************************
  405. * pattern from OS uses 'ethenet frame', like this:
  406. | 6 | 6 | 2 | 20 | Variable | 4 |
  407. |--------+--------+------+-----------+------------+-----|
  408. | 802.3 Mac Header | IP Header | TCP Packet | FCS |
  409. | DA | SA | Type |
  410. * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
  411. | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
  412. |-------------------+--------+------+-----------+------------+-----|
  413. | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
  414. | Others | Tpye |
  415. * Therefore, we need translate mask_from_OS to mask_to_hw.
  416. * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0,
  417. * because new mask[0~5] means 'SA', but our HW packet begins from LLC,
  418. * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match.
  419. ******************************************************************************/
  420. /* Shift 6 bits */
  421. for (j = 0; j < mask_len - 1; j++) {
  422. mask[j] = mask_os[j] >> 6;
  423. mask[j] |= (mask_os[j + 1] & 0x3F) << 2;
  424. }
  425. mask[j] = (mask_os[j] >> 6) & 0x3F;
  426. /* Set bit 0-5 to zero */
  427. mask[0] &= 0xC0;
  428. RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE,
  429. "mask to hw\n", mask, mask_len);
  430. for (j = 0; j < (MAX_WOL_BIT_MASK_SIZE + 1) / 4; j++) {
  431. rtl_pattern.mask[j] = mask[j * 4];
  432. rtl_pattern.mask[j] |= (mask[j * 4 + 1] << 8);
  433. rtl_pattern.mask[j] |= (mask[j * 4 + 2] << 16);
  434. rtl_pattern.mask[j] |= (mask[j * 4 + 3] << 24);
  435. }
  436. /* To get the wake up pattern from the mask.
  437. * We do not count first 12 bits which means
  438. * DA[6] and SA[6] in the pattern to match HW design.
  439. */
  440. len = 0;
  441. for (j = 12; j < patterns[i].pattern_len; j++) {
  442. if ((mask_os[j / 8] >> (j % 8)) & 0x01) {
  443. content[len] = pattern_os[j];
  444. len++;
  445. }
  446. }
  447. RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE,
  448. "pattern to hw\n", content, len);
  449. /* 3. calculate crc */
  450. rtl_pattern.crc = _calculate_wol_pattern_crc(content, len);
  451. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  452. "CRC_Remainder = 0x%x", rtl_pattern.crc);
  453. /* 4. write crc & mask_for_hw to hw */
  454. rtlpriv->cfg->ops->add_wowlan_pattern(hw, &rtl_pattern, i);
  455. }
  456. rtl_write_byte(rtlpriv, 0x698, wow->n_patterns);
  457. }
  458. static int rtl_op_suspend(struct ieee80211_hw *hw,
  459. struct cfg80211_wowlan *wow)
  460. {
  461. struct rtl_priv *rtlpriv = rtl_priv(hw);
  462. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  463. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  464. struct timeval ts;
  465. RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n");
  466. if (WARN_ON(!wow))
  467. return -EINVAL;
  468. /* to resolve s4 can not wake up*/
  469. do_gettimeofday(&ts);
  470. rtlhal->last_suspend_sec = ts.tv_sec;
  471. if ((ppsc->wo_wlan_mode & WAKE_ON_PATTERN_MATCH) && wow->n_patterns)
  472. _rtl_add_wowlan_patterns(hw, wow);
  473. rtlhal->driver_is_goingto_unload = true;
  474. rtlhal->enter_pnp_sleep = true;
  475. rtl_lps_leave(hw);
  476. rtl_op_stop(hw);
  477. device_set_wakeup_enable(wiphy_dev(hw->wiphy), true);
  478. return 0;
  479. }
  480. static int rtl_op_resume(struct ieee80211_hw *hw)
  481. {
  482. struct rtl_priv *rtlpriv = rtl_priv(hw);
  483. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  484. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  485. struct timeval ts;
  486. RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n");
  487. rtlhal->driver_is_goingto_unload = false;
  488. rtlhal->enter_pnp_sleep = false;
  489. rtlhal->wake_from_pnp_sleep = true;
  490. /* to resovle s4 can not wake up*/
  491. do_gettimeofday(&ts);
  492. if (ts.tv_sec - rtlhal->last_suspend_sec < 5)
  493. return -1;
  494. rtl_op_start(hw);
  495. device_set_wakeup_enable(wiphy_dev(hw->wiphy), false);
  496. ieee80211_resume_disconnect(mac->vif);
  497. rtlhal->wake_from_pnp_sleep = false;
  498. return 0;
  499. }
  500. #endif
  501. static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
  502. {
  503. struct rtl_priv *rtlpriv = rtl_priv(hw);
  504. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  505. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  506. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  507. struct ieee80211_conf *conf = &hw->conf;
  508. if (mac->skip_scan)
  509. return 1;
  510. mutex_lock(&rtlpriv->locks.conf_mutex);
  511. if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /* BIT(2)*/
  512. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  513. "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
  514. }
  515. /*For IPS */
  516. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  517. if (hw->conf.flags & IEEE80211_CONF_IDLE)
  518. rtl_ips_nic_off(hw);
  519. else
  520. rtl_ips_nic_on(hw);
  521. } else {
  522. /*
  523. *although rfoff may not cause by ips, but we will
  524. *check the reason in set_rf_power_state function
  525. */
  526. if (unlikely(ppsc->rfpwr_state == ERFOFF))
  527. rtl_ips_nic_on(hw);
  528. }
  529. /*For LPS */
  530. if (changed & IEEE80211_CONF_CHANGE_PS) {
  531. cancel_delayed_work(&rtlpriv->works.ps_work);
  532. cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
  533. if (conf->flags & IEEE80211_CONF_PS) {
  534. rtlpriv->psc.sw_ps_enabled = true;
  535. /* sleep here is must, or we may recv the beacon and
  536. * cause mac80211 into wrong ps state, this will cause
  537. * power save nullfunc send fail, and further cause
  538. * pkt loss, So sleep must quickly but not immediatly
  539. * because that will cause nullfunc send by mac80211
  540. * fail, and cause pkt loss, we have tested that 5mA
  541. * is worked very well */
  542. if (!rtlpriv->psc.multi_buffered)
  543. queue_delayed_work(rtlpriv->works.rtl_wq,
  544. &rtlpriv->works.ps_work,
  545. MSECS(5));
  546. } else {
  547. rtl_swlps_rf_awake(hw);
  548. rtlpriv->psc.sw_ps_enabled = false;
  549. }
  550. }
  551. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
  552. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  553. "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
  554. hw->conf.long_frame_max_tx_count);
  555. mac->retry_long = hw->conf.long_frame_max_tx_count;
  556. mac->retry_short = hw->conf.long_frame_max_tx_count;
  557. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
  558. (u8 *)(&hw->conf.long_frame_max_tx_count));
  559. }
  560. if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
  561. !rtlpriv->proximity.proxim_on) {
  562. struct ieee80211_channel *channel = hw->conf.chandef.chan;
  563. enum nl80211_chan_width width = hw->conf.chandef.width;
  564. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  565. u8 wide_chan = (u8) channel->hw_value;
  566. /* channel_type is for 20&40M */
  567. if (width < NL80211_CHAN_WIDTH_80)
  568. channel_type =
  569. cfg80211_get_chandef_type(&hw->conf.chandef);
  570. if (mac->act_scanning)
  571. mac->n_channels++;
  572. if (rtlpriv->dm.supp_phymode_switch &&
  573. mac->link_state < MAC80211_LINKED &&
  574. !mac->act_scanning) {
  575. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  576. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  577. }
  578. /*
  579. *because we should back channel to
  580. *current_network.chan in in scanning,
  581. *So if set_chan == current_network.chan
  582. *we should set it.
  583. *because mac80211 tell us wrong bw40
  584. *info for cisco1253 bw20, so we modify
  585. *it here based on UPPER & LOWER
  586. */
  587. if (width >= NL80211_CHAN_WIDTH_80) {
  588. if (width == NL80211_CHAN_WIDTH_80) {
  589. u32 center = hw->conf.chandef.center_freq1;
  590. u32 primary =
  591. (u32)hw->conf.chandef.chan->center_freq;
  592. rtlphy->current_chan_bw =
  593. HT_CHANNEL_WIDTH_80;
  594. mac->bw_80 = true;
  595. mac->bw_40 = true;
  596. if (center > primary) {
  597. mac->cur_80_prime_sc =
  598. PRIME_CHNL_OFFSET_LOWER;
  599. if (center - primary == 10) {
  600. mac->cur_40_prime_sc =
  601. PRIME_CHNL_OFFSET_UPPER;
  602. wide_chan += 2;
  603. } else if (center - primary == 30) {
  604. mac->cur_40_prime_sc =
  605. PRIME_CHNL_OFFSET_LOWER;
  606. wide_chan += 6;
  607. }
  608. } else {
  609. mac->cur_80_prime_sc =
  610. PRIME_CHNL_OFFSET_UPPER;
  611. if (primary - center == 10) {
  612. mac->cur_40_prime_sc =
  613. PRIME_CHNL_OFFSET_LOWER;
  614. wide_chan -= 2;
  615. } else if (primary - center == 30) {
  616. mac->cur_40_prime_sc =
  617. PRIME_CHNL_OFFSET_UPPER;
  618. wide_chan -= 6;
  619. }
  620. }
  621. }
  622. } else {
  623. switch (channel_type) {
  624. case NL80211_CHAN_HT20:
  625. case NL80211_CHAN_NO_HT:
  626. /* SC */
  627. mac->cur_40_prime_sc =
  628. PRIME_CHNL_OFFSET_DONT_CARE;
  629. rtlphy->current_chan_bw =
  630. HT_CHANNEL_WIDTH_20;
  631. mac->bw_40 = false;
  632. mac->bw_80 = false;
  633. break;
  634. case NL80211_CHAN_HT40MINUS:
  635. /* SC */
  636. mac->cur_40_prime_sc =
  637. PRIME_CHNL_OFFSET_UPPER;
  638. rtlphy->current_chan_bw =
  639. HT_CHANNEL_WIDTH_20_40;
  640. mac->bw_40 = true;
  641. mac->bw_80 = false;
  642. /*wide channel */
  643. wide_chan -= 2;
  644. break;
  645. case NL80211_CHAN_HT40PLUS:
  646. /* SC */
  647. mac->cur_40_prime_sc =
  648. PRIME_CHNL_OFFSET_LOWER;
  649. rtlphy->current_chan_bw =
  650. HT_CHANNEL_WIDTH_20_40;
  651. mac->bw_40 = true;
  652. mac->bw_80 = false;
  653. /*wide channel */
  654. wide_chan += 2;
  655. break;
  656. default:
  657. mac->bw_40 = false;
  658. mac->bw_80 = false;
  659. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  660. "switch case not processed\n");
  661. break;
  662. }
  663. }
  664. if (wide_chan <= 0)
  665. wide_chan = 1;
  666. /* In scanning, when before we offchannel we may send a ps=1
  667. * null to AP, and then we may send a ps = 0 null to AP quickly,
  668. * but first null may have caused AP to put lots of packet to
  669. * hw tx buffer. These packets must be tx'd before we go off
  670. * channel so we must delay more time to let AP flush these
  671. * packets before going offchannel, or dis-association or
  672. * delete BA will be caused by AP
  673. */
  674. if (rtlpriv->mac80211.offchan_delay) {
  675. rtlpriv->mac80211.offchan_delay = false;
  676. mdelay(50);
  677. }
  678. rtlphy->current_channel = wide_chan;
  679. rtlpriv->cfg->ops->switch_channel(hw);
  680. rtlpriv->cfg->ops->set_channel_access(hw);
  681. rtlpriv->cfg->ops->set_bw_mode(hw, channel_type);
  682. }
  683. mutex_unlock(&rtlpriv->locks.conf_mutex);
  684. return 0;
  685. }
  686. static void rtl_op_configure_filter(struct ieee80211_hw *hw,
  687. unsigned int changed_flags,
  688. unsigned int *new_flags, u64 multicast)
  689. {
  690. struct rtl_priv *rtlpriv = rtl_priv(hw);
  691. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  692. *new_flags &= RTL_SUPPORTED_FILTERS;
  693. if (0 == changed_flags)
  694. return;
  695. /*TODO: we disable broadcase now, so enable here */
  696. if (changed_flags & FIF_ALLMULTI) {
  697. if (*new_flags & FIF_ALLMULTI) {
  698. mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] |
  699. rtlpriv->cfg->maps[MAC_RCR_AB];
  700. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  701. "Enable receive multicast frame\n");
  702. } else {
  703. mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] |
  704. rtlpriv->cfg->maps[MAC_RCR_AB]);
  705. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  706. "Disable receive multicast frame\n");
  707. }
  708. }
  709. if (changed_flags & FIF_FCSFAIL) {
  710. if (*new_flags & FIF_FCSFAIL) {
  711. mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32];
  712. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  713. "Enable receive FCS error frame\n");
  714. } else {
  715. mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32];
  716. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  717. "Disable receive FCS error frame\n");
  718. }
  719. }
  720. /* if ssid not set to hw don't check bssid
  721. * here just used for linked scanning, & linked
  722. * and nolink check bssid is set in set network_type
  723. */
  724. if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
  725. (mac->link_state >= MAC80211_LINKED)) {
  726. if (mac->opmode != NL80211_IFTYPE_AP &&
  727. mac->opmode != NL80211_IFTYPE_MESH_POINT) {
  728. if (*new_flags & FIF_BCN_PRBRESP_PROMISC)
  729. rtlpriv->cfg->ops->set_chk_bssid(hw, false);
  730. else
  731. rtlpriv->cfg->ops->set_chk_bssid(hw, true);
  732. }
  733. }
  734. if (changed_flags & FIF_CONTROL) {
  735. if (*new_flags & FIF_CONTROL) {
  736. mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
  737. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  738. "Enable receive control frame.\n");
  739. } else {
  740. mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
  741. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  742. "Disable receive control frame.\n");
  743. }
  744. }
  745. if (changed_flags & FIF_OTHER_BSS) {
  746. if (*new_flags & FIF_OTHER_BSS) {
  747. mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP];
  748. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  749. "Enable receive other BSS's frame.\n");
  750. } else {
  751. mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP];
  752. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  753. "Disable receive other BSS's frame.\n");
  754. }
  755. }
  756. }
  757. static int rtl_op_sta_add(struct ieee80211_hw *hw,
  758. struct ieee80211_vif *vif,
  759. struct ieee80211_sta *sta)
  760. {
  761. struct rtl_priv *rtlpriv = rtl_priv(hw);
  762. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  763. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  764. struct rtl_sta_info *sta_entry;
  765. if (sta) {
  766. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  767. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  768. list_add_tail(&sta_entry->list, &rtlpriv->entry_list);
  769. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  770. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  771. sta_entry->wireless_mode = WIRELESS_MODE_G;
  772. if (sta->supp_rates[0] <= 0xf)
  773. sta_entry->wireless_mode = WIRELESS_MODE_B;
  774. if (sta->ht_cap.ht_supported)
  775. sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
  776. if (vif->type == NL80211_IFTYPE_ADHOC)
  777. sta_entry->wireless_mode = WIRELESS_MODE_G;
  778. } else if (rtlhal->current_bandtype == BAND_ON_5G) {
  779. sta_entry->wireless_mode = WIRELESS_MODE_A;
  780. if (sta->ht_cap.ht_supported)
  781. sta_entry->wireless_mode = WIRELESS_MODE_N_5G;
  782. if (sta->vht_cap.vht_supported)
  783. sta_entry->wireless_mode = WIRELESS_MODE_AC_5G;
  784. if (vif->type == NL80211_IFTYPE_ADHOC)
  785. sta_entry->wireless_mode = WIRELESS_MODE_A;
  786. }
  787. /*disable cck rate for p2p*/
  788. if (mac->p2p)
  789. sta->supp_rates[0] &= 0xfffffff0;
  790. memcpy(sta_entry->mac_addr, sta->addr, ETH_ALEN);
  791. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  792. "Add sta addr is %pM\n", sta->addr);
  793. rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
  794. }
  795. return 0;
  796. }
  797. static int rtl_op_sta_remove(struct ieee80211_hw *hw,
  798. struct ieee80211_vif *vif,
  799. struct ieee80211_sta *sta)
  800. {
  801. struct rtl_priv *rtlpriv = rtl_priv(hw);
  802. struct rtl_sta_info *sta_entry;
  803. if (sta) {
  804. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  805. "Remove sta addr is %pM\n", sta->addr);
  806. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  807. sta_entry->wireless_mode = 0;
  808. sta_entry->ratr_index = 0;
  809. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  810. list_del(&sta_entry->list);
  811. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  812. }
  813. return 0;
  814. }
  815. static int _rtl_get_hal_qnum(u16 queue)
  816. {
  817. int qnum;
  818. switch (queue) {
  819. case 0:
  820. qnum = AC3_VO;
  821. break;
  822. case 1:
  823. qnum = AC2_VI;
  824. break;
  825. case 2:
  826. qnum = AC0_BE;
  827. break;
  828. case 3:
  829. qnum = AC1_BK;
  830. break;
  831. default:
  832. qnum = AC0_BE;
  833. break;
  834. }
  835. return qnum;
  836. }
  837. /*
  838. *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
  839. *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
  840. */
  841. static int rtl_op_conf_tx(struct ieee80211_hw *hw,
  842. struct ieee80211_vif *vif, u16 queue,
  843. const struct ieee80211_tx_queue_params *param)
  844. {
  845. struct rtl_priv *rtlpriv = rtl_priv(hw);
  846. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  847. int aci;
  848. if (queue >= AC_MAX) {
  849. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  850. "queue number %d is incorrect!\n", queue);
  851. return -EINVAL;
  852. }
  853. aci = _rtl_get_hal_qnum(queue);
  854. mac->ac[aci].aifs = param->aifs;
  855. mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
  856. mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
  857. mac->ac[aci].tx_op = cpu_to_le16(param->txop);
  858. memcpy(&mac->edca_param[aci], param, sizeof(*param));
  859. rtlpriv->cfg->ops->set_qos(hw, aci);
  860. return 0;
  861. }
  862. static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
  863. struct ieee80211_vif *vif,
  864. struct ieee80211_bss_conf *bss_conf,
  865. u32 changed)
  866. {
  867. struct rtl_priv *rtlpriv = rtl_priv(hw);
  868. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  869. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  870. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  871. mutex_lock(&rtlpriv->locks.conf_mutex);
  872. if ((vif->type == NL80211_IFTYPE_ADHOC) ||
  873. (vif->type == NL80211_IFTYPE_AP) ||
  874. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  875. if ((changed & BSS_CHANGED_BEACON) ||
  876. (changed & BSS_CHANGED_BEACON_ENABLED &&
  877. bss_conf->enable_beacon)) {
  878. if (mac->beacon_enabled == 0) {
  879. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  880. "BSS_CHANGED_BEACON_ENABLED\n");
  881. /*start hw beacon interrupt. */
  882. /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
  883. mac->beacon_enabled = 1;
  884. rtlpriv->cfg->ops->update_interrupt_mask(hw,
  885. rtlpriv->cfg->maps
  886. [RTL_IBSS_INT_MASKS], 0);
  887. if (rtlpriv->cfg->ops->linked_set_reg)
  888. rtlpriv->cfg->ops->linked_set_reg(hw);
  889. }
  890. }
  891. if ((changed & BSS_CHANGED_BEACON_ENABLED &&
  892. !bss_conf->enable_beacon)) {
  893. if (mac->beacon_enabled == 1) {
  894. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  895. "ADHOC DISABLE BEACON\n");
  896. mac->beacon_enabled = 0;
  897. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  898. rtlpriv->cfg->maps
  899. [RTL_IBSS_INT_MASKS]);
  900. }
  901. }
  902. if (changed & BSS_CHANGED_BEACON_INT) {
  903. RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
  904. "BSS_CHANGED_BEACON_INT\n");
  905. mac->beacon_interval = bss_conf->beacon_int;
  906. rtlpriv->cfg->ops->set_bcn_intv(hw);
  907. }
  908. }
  909. /*TODO: reference to enum ieee80211_bss_change */
  910. if (changed & BSS_CHANGED_ASSOC) {
  911. u8 mstatus;
  912. if (bss_conf->assoc) {
  913. struct ieee80211_sta *sta = NULL;
  914. u8 keep_alive = 10;
  915. mstatus = RT_MEDIA_CONNECT;
  916. /* we should reset all sec info & cam
  917. * before set cam after linked, we should not
  918. * reset in disassoc, that will cause tkip->wep
  919. * fail because some flag will be wrong */
  920. /* reset sec info */
  921. rtl_cam_reset_sec_info(hw);
  922. /* reset cam to fix wep fail issue
  923. * when change from wpa to wep */
  924. rtl_cam_reset_all_entry(hw);
  925. mac->link_state = MAC80211_LINKED;
  926. mac->cnt_after_linked = 0;
  927. mac->assoc_id = bss_conf->aid;
  928. memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
  929. if (rtlpriv->cfg->ops->linked_set_reg)
  930. rtlpriv->cfg->ops->linked_set_reg(hw);
  931. rcu_read_lock();
  932. sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
  933. if (!sta) {
  934. rcu_read_unlock();
  935. goto out;
  936. }
  937. RT_TRACE(rtlpriv, COMP_EASY_CONCURRENT, DBG_LOUD,
  938. "send PS STATIC frame\n");
  939. if (rtlpriv->dm.supp_phymode_switch) {
  940. if (sta->ht_cap.ht_supported)
  941. rtl_send_smps_action(hw, sta,
  942. IEEE80211_SMPS_STATIC);
  943. }
  944. if (rtlhal->current_bandtype == BAND_ON_5G) {
  945. mac->mode = WIRELESS_MODE_A;
  946. } else {
  947. if (sta->supp_rates[0] <= 0xf)
  948. mac->mode = WIRELESS_MODE_B;
  949. else
  950. mac->mode = WIRELESS_MODE_G;
  951. }
  952. if (sta->ht_cap.ht_supported) {
  953. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  954. mac->mode = WIRELESS_MODE_N_24G;
  955. else
  956. mac->mode = WIRELESS_MODE_N_5G;
  957. }
  958. if (sta->vht_cap.vht_supported) {
  959. if (rtlhal->current_bandtype == BAND_ON_5G)
  960. mac->mode = WIRELESS_MODE_AC_5G;
  961. else
  962. mac->mode = WIRELESS_MODE_AC_24G;
  963. }
  964. if (vif->type == NL80211_IFTYPE_STATION && sta)
  965. rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
  966. rcu_read_unlock();
  967. /* to avoid AP Disassociation caused by inactivity */
  968. rtlpriv->cfg->ops->set_hw_reg(hw,
  969. HW_VAR_KEEP_ALIVE,
  970. (u8 *)(&keep_alive));
  971. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  972. "BSS_CHANGED_ASSOC\n");
  973. } else {
  974. mstatus = RT_MEDIA_DISCONNECT;
  975. if (mac->link_state == MAC80211_LINKED) {
  976. rtlpriv->enter_ps = false;
  977. schedule_work(&rtlpriv->works.lps_change_work);
  978. }
  979. if (ppsc->p2p_ps_info.p2p_ps_mode > P2P_PS_NONE)
  980. rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE);
  981. mac->link_state = MAC80211_NOLINK;
  982. memset(mac->bssid, 0, ETH_ALEN);
  983. mac->vendor = PEER_UNKNOWN;
  984. mac->mode = 0;
  985. if (rtlpriv->dm.supp_phymode_switch) {
  986. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  987. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  988. }
  989. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  990. "BSS_CHANGED_UN_ASSOC\n");
  991. }
  992. rtlpriv->cfg->ops->set_network_type(hw, vif->type);
  993. /* For FW LPS:
  994. * To tell firmware we have connected or disconnected
  995. */
  996. rtlpriv->cfg->ops->set_hw_reg(hw,
  997. HW_VAR_H2C_FW_JOINBSSRPT,
  998. (u8 *)(&mstatus));
  999. ppsc->report_linked = (mstatus == RT_MEDIA_CONNECT) ?
  1000. true : false;
  1001. if (rtlpriv->cfg->ops->get_btc_status())
  1002. rtlpriv->btcoexist.btc_ops->btc_mediastatus_notify(
  1003. rtlpriv, mstatus);
  1004. }
  1005. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  1006. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1007. "BSS_CHANGED_ERP_CTS_PROT\n");
  1008. mac->use_cts_protect = bss_conf->use_cts_prot;
  1009. }
  1010. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  1011. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  1012. "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
  1013. bss_conf->use_short_preamble);
  1014. mac->short_preamble = bss_conf->use_short_preamble;
  1015. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
  1016. (u8 *)(&mac->short_preamble));
  1017. }
  1018. if (changed & BSS_CHANGED_ERP_SLOT) {
  1019. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1020. "BSS_CHANGED_ERP_SLOT\n");
  1021. if (bss_conf->use_short_slot)
  1022. mac->slot_time = RTL_SLOT_TIME_9;
  1023. else
  1024. mac->slot_time = RTL_SLOT_TIME_20;
  1025. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  1026. (u8 *)(&mac->slot_time));
  1027. }
  1028. if (changed & BSS_CHANGED_HT) {
  1029. struct ieee80211_sta *sta = NULL;
  1030. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1031. "BSS_CHANGED_HT\n");
  1032. rcu_read_lock();
  1033. sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
  1034. if (sta) {
  1035. if (sta->ht_cap.ampdu_density >
  1036. mac->current_ampdu_density)
  1037. mac->current_ampdu_density =
  1038. sta->ht_cap.ampdu_density;
  1039. if (sta->ht_cap.ampdu_factor <
  1040. mac->current_ampdu_factor)
  1041. mac->current_ampdu_factor =
  1042. sta->ht_cap.ampdu_factor;
  1043. }
  1044. rcu_read_unlock();
  1045. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
  1046. (u8 *)(&mac->max_mss_density));
  1047. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
  1048. &mac->current_ampdu_factor);
  1049. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
  1050. &mac->current_ampdu_density);
  1051. }
  1052. if (changed & BSS_CHANGED_BSSID) {
  1053. u32 basic_rates;
  1054. struct ieee80211_sta *sta = NULL;
  1055. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
  1056. (u8 *)bss_conf->bssid);
  1057. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  1058. "bssid: %pM\n", bss_conf->bssid);
  1059. mac->vendor = PEER_UNKNOWN;
  1060. memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
  1061. rcu_read_lock();
  1062. sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
  1063. if (!sta) {
  1064. rcu_read_unlock();
  1065. goto out;
  1066. }
  1067. if (rtlhal->current_bandtype == BAND_ON_5G) {
  1068. mac->mode = WIRELESS_MODE_A;
  1069. } else {
  1070. if (sta->supp_rates[0] <= 0xf)
  1071. mac->mode = WIRELESS_MODE_B;
  1072. else
  1073. mac->mode = WIRELESS_MODE_G;
  1074. }
  1075. if (sta->ht_cap.ht_supported) {
  1076. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  1077. mac->mode = WIRELESS_MODE_N_24G;
  1078. else
  1079. mac->mode = WIRELESS_MODE_N_5G;
  1080. }
  1081. if (sta->vht_cap.vht_supported) {
  1082. if (rtlhal->current_bandtype == BAND_ON_5G)
  1083. mac->mode = WIRELESS_MODE_AC_5G;
  1084. else
  1085. mac->mode = WIRELESS_MODE_AC_24G;
  1086. }
  1087. /* just station need it, because ibss & ap mode will
  1088. * set in sta_add, and will be NULL here */
  1089. if (vif->type == NL80211_IFTYPE_STATION) {
  1090. struct rtl_sta_info *sta_entry;
  1091. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1092. sta_entry->wireless_mode = mac->mode;
  1093. }
  1094. if (sta->ht_cap.ht_supported) {
  1095. mac->ht_enable = true;
  1096. /*
  1097. * for cisco 1252 bw20 it's wrong
  1098. * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  1099. * mac->bw_40 = true;
  1100. * }
  1101. * */
  1102. }
  1103. if (sta->vht_cap.vht_supported)
  1104. mac->vht_enable = true;
  1105. if (changed & BSS_CHANGED_BASIC_RATES) {
  1106. /* for 5G must << RATE_6M_INDEX = 4,
  1107. * because 5G have no cck rate*/
  1108. if (rtlhal->current_bandtype == BAND_ON_5G)
  1109. basic_rates = sta->supp_rates[1] << 4;
  1110. else
  1111. basic_rates = sta->supp_rates[0];
  1112. mac->basic_rates = basic_rates;
  1113. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  1114. (u8 *)(&basic_rates));
  1115. }
  1116. rcu_read_unlock();
  1117. }
  1118. out:
  1119. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1120. }
  1121. static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1122. {
  1123. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1124. u64 tsf;
  1125. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&tsf));
  1126. return tsf;
  1127. }
  1128. static void rtl_op_set_tsf(struct ieee80211_hw *hw,
  1129. struct ieee80211_vif *vif, u64 tsf)
  1130. {
  1131. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1132. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1133. u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
  1134. mac->tsf = tsf;
  1135. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&bibss));
  1136. }
  1137. static void rtl_op_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1138. {
  1139. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1140. u8 tmp = 0;
  1141. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *)(&tmp));
  1142. }
  1143. static void rtl_op_sta_notify(struct ieee80211_hw *hw,
  1144. struct ieee80211_vif *vif,
  1145. enum sta_notify_cmd cmd,
  1146. struct ieee80211_sta *sta)
  1147. {
  1148. switch (cmd) {
  1149. case STA_NOTIFY_SLEEP:
  1150. break;
  1151. case STA_NOTIFY_AWAKE:
  1152. break;
  1153. default:
  1154. break;
  1155. }
  1156. }
  1157. static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
  1158. struct ieee80211_vif *vif,
  1159. enum ieee80211_ampdu_mlme_action action,
  1160. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  1161. u8 buf_size)
  1162. {
  1163. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1164. switch (action) {
  1165. case IEEE80211_AMPDU_TX_START:
  1166. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1167. "IEEE80211_AMPDU_TX_START: TID:%d\n", tid);
  1168. return rtl_tx_agg_start(hw, vif, sta, tid, ssn);
  1169. case IEEE80211_AMPDU_TX_STOP_CONT:
  1170. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  1171. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  1172. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1173. "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
  1174. return rtl_tx_agg_stop(hw, vif, sta, tid);
  1175. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1176. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1177. "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
  1178. rtl_tx_agg_oper(hw, sta, tid);
  1179. break;
  1180. case IEEE80211_AMPDU_RX_START:
  1181. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1182. "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
  1183. return rtl_rx_agg_start(hw, sta, tid);
  1184. case IEEE80211_AMPDU_RX_STOP:
  1185. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  1186. "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
  1187. return rtl_rx_agg_stop(hw, sta, tid);
  1188. default:
  1189. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1190. "IEEE80211_AMPDU_ERR!!!!:\n");
  1191. return -EOPNOTSUPP;
  1192. }
  1193. return 0;
  1194. }
  1195. static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
  1196. {
  1197. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1198. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1199. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  1200. mac->act_scanning = true;
  1201. if (rtlpriv->link_info.higher_busytraffic) {
  1202. mac->skip_scan = true;
  1203. return;
  1204. }
  1205. if (rtlpriv->cfg->ops->get_btc_status())
  1206. rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 1);
  1207. if (rtlpriv->dm.supp_phymode_switch) {
  1208. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  1209. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  1210. }
  1211. if (mac->link_state == MAC80211_LINKED) {
  1212. rtlpriv->enter_ps = false;
  1213. schedule_work(&rtlpriv->works.lps_change_work);
  1214. mac->link_state = MAC80211_LINKED_SCANNING;
  1215. } else {
  1216. rtl_ips_nic_on(hw);
  1217. }
  1218. /* Dul mac */
  1219. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  1220. rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
  1221. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP_BAND0);
  1222. }
  1223. static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
  1224. {
  1225. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1226. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1227. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  1228. mac->act_scanning = false;
  1229. mac->skip_scan = false;
  1230. if (rtlpriv->link_info.higher_busytraffic)
  1231. return;
  1232. /* p2p will use 1/6/11 to scan */
  1233. if (mac->n_channels == 3)
  1234. mac->p2p_in_use = true;
  1235. else
  1236. mac->p2p_in_use = false;
  1237. mac->n_channels = 0;
  1238. /* Dul mac */
  1239. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  1240. if (mac->link_state == MAC80211_LINKED_SCANNING) {
  1241. mac->link_state = MAC80211_LINKED;
  1242. if (mac->opmode == NL80211_IFTYPE_STATION) {
  1243. /* fix fwlps issue */
  1244. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  1245. }
  1246. }
  1247. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
  1248. if (rtlpriv->cfg->ops->get_btc_status())
  1249. rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 0);
  1250. }
  1251. static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1252. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1253. struct ieee80211_key_conf *key)
  1254. {
  1255. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1256. u8 key_type = NO_ENCRYPTION;
  1257. u8 key_idx;
  1258. bool group_key = false;
  1259. bool wep_only = false;
  1260. int err = 0;
  1261. u8 mac_addr[ETH_ALEN];
  1262. u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1263. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  1264. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1265. "not open hw encryption\n");
  1266. return -ENOSPC; /*User disabled HW-crypto */
  1267. }
  1268. /* To support IBSS, use sw-crypto for GTK */
  1269. if (((vif->type == NL80211_IFTYPE_ADHOC) ||
  1270. (vif->type == NL80211_IFTYPE_MESH_POINT)) &&
  1271. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  1272. return -ENOSPC;
  1273. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1274. "%s hardware based encryption for keyidx: %d, mac: %pM\n",
  1275. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  1276. sta ? sta->addr : bcast_addr);
  1277. rtlpriv->sec.being_setkey = true;
  1278. rtl_ips_nic_on(hw);
  1279. mutex_lock(&rtlpriv->locks.conf_mutex);
  1280. /* <1> get encryption alg */
  1281. switch (key->cipher) {
  1282. case WLAN_CIPHER_SUITE_WEP40:
  1283. key_type = WEP40_ENCRYPTION;
  1284. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
  1285. break;
  1286. case WLAN_CIPHER_SUITE_WEP104:
  1287. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
  1288. key_type = WEP104_ENCRYPTION;
  1289. break;
  1290. case WLAN_CIPHER_SUITE_TKIP:
  1291. key_type = TKIP_ENCRYPTION;
  1292. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
  1293. break;
  1294. case WLAN_CIPHER_SUITE_CCMP:
  1295. key_type = AESCCMP_ENCRYPTION;
  1296. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
  1297. break;
  1298. case WLAN_CIPHER_SUITE_AES_CMAC:
  1299. /* HW don't support CMAC encryption,
  1300. * use software CMAC encryption
  1301. */
  1302. key_type = AESCMAC_ENCRYPTION;
  1303. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n");
  1304. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1305. "HW don't support CMAC encrypiton, use software CMAC encrypiton\n");
  1306. err = -EOPNOTSUPP;
  1307. goto out_unlock;
  1308. default:
  1309. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1310. "alg_err:%x!!!!:\n", key->cipher);
  1311. goto out_unlock;
  1312. }
  1313. if (key_type == WEP40_ENCRYPTION ||
  1314. key_type == WEP104_ENCRYPTION ||
  1315. vif->type == NL80211_IFTYPE_ADHOC)
  1316. rtlpriv->sec.use_defaultkey = true;
  1317. /* <2> get key_idx */
  1318. key_idx = (u8) (key->keyidx);
  1319. if (key_idx > 3)
  1320. goto out_unlock;
  1321. /* <3> if pairwise key enable_hw_sec */
  1322. group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  1323. /* wep always be group key, but there are two conditions:
  1324. * 1) wep only: is just for wep enc, in this condition
  1325. * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
  1326. * will be true & enable_hw_sec will be set when wep
  1327. * ke setting.
  1328. * 2) wep(group) + AES(pairwise): some AP like cisco
  1329. * may use it, in this condition enable_hw_sec will not
  1330. * be set when wep key setting */
  1331. /* we must reset sec_info after lingked before set key,
  1332. * or some flag will be wrong*/
  1333. if (vif->type == NL80211_IFTYPE_AP ||
  1334. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1335. if (!group_key || key_type == WEP40_ENCRYPTION ||
  1336. key_type == WEP104_ENCRYPTION) {
  1337. if (group_key)
  1338. wep_only = true;
  1339. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1340. }
  1341. } else {
  1342. if ((!group_key) || (vif->type == NL80211_IFTYPE_ADHOC) ||
  1343. rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
  1344. if (rtlpriv->sec.pairwise_enc_algorithm ==
  1345. NO_ENCRYPTION &&
  1346. (key_type == WEP40_ENCRYPTION ||
  1347. key_type == WEP104_ENCRYPTION))
  1348. wep_only = true;
  1349. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1350. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1351. "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
  1352. key_type);
  1353. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1354. }
  1355. }
  1356. /* <4> set key based on cmd */
  1357. switch (cmd) {
  1358. case SET_KEY:
  1359. if (wep_only) {
  1360. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1361. "set WEP(group/pairwise) key\n");
  1362. /* Pairwise key with an assigned MAC address. */
  1363. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1364. rtlpriv->sec.group_enc_algorithm = key_type;
  1365. /*set local buf about wep key. */
  1366. memcpy(rtlpriv->sec.key_buf[key_idx],
  1367. key->key, key->keylen);
  1368. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1369. eth_zero_addr(mac_addr);
  1370. } else if (group_key) { /* group key */
  1371. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1372. "set group key\n");
  1373. /* group key */
  1374. rtlpriv->sec.group_enc_algorithm = key_type;
  1375. /*set local buf about group key. */
  1376. memcpy(rtlpriv->sec.key_buf[key_idx],
  1377. key->key, key->keylen);
  1378. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1379. memcpy(mac_addr, bcast_addr, ETH_ALEN);
  1380. } else { /* pairwise key */
  1381. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1382. "set pairwise key\n");
  1383. if (!sta) {
  1384. RT_ASSERT(false,
  1385. "pairwise key without mac_addr\n");
  1386. err = -EOPNOTSUPP;
  1387. goto out_unlock;
  1388. }
  1389. /* Pairwise key with an assigned MAC address. */
  1390. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1391. /*set local buf about pairwise key. */
  1392. memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
  1393. key->key, key->keylen);
  1394. rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
  1395. rtlpriv->sec.pairwise_key =
  1396. rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
  1397. memcpy(mac_addr, sta->addr, ETH_ALEN);
  1398. }
  1399. rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
  1400. group_key, key_type, wep_only,
  1401. false);
  1402. /* <5> tell mac80211 do something: */
  1403. /*must use sw generate IV, or can not work !!!!. */
  1404. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1405. key->hw_key_idx = key_idx;
  1406. if (key_type == TKIP_ENCRYPTION)
  1407. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1408. /*use software CCMP encryption for management frames (MFP) */
  1409. if (key_type == AESCCMP_ENCRYPTION)
  1410. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1411. break;
  1412. case DISABLE_KEY:
  1413. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1414. "disable key delete one entry\n");
  1415. /*set local buf about wep key. */
  1416. if (vif->type == NL80211_IFTYPE_AP ||
  1417. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1418. if (sta)
  1419. rtl_cam_del_entry(hw, sta->addr);
  1420. }
  1421. memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
  1422. rtlpriv->sec.key_len[key_idx] = 0;
  1423. eth_zero_addr(mac_addr);
  1424. /*
  1425. *mac80211 will delete entrys one by one,
  1426. *so don't use rtl_cam_reset_all_entry
  1427. *or clear all entry here.
  1428. */
  1429. rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
  1430. break;
  1431. default:
  1432. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1433. "cmd_err:%x!!!!:\n", cmd);
  1434. }
  1435. out_unlock:
  1436. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1437. rtlpriv->sec.being_setkey = false;
  1438. return err;
  1439. }
  1440. static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
  1441. {
  1442. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1443. bool radio_state;
  1444. bool blocked;
  1445. u8 valid = 0;
  1446. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1447. return;
  1448. mutex_lock(&rtlpriv->locks.conf_mutex);
  1449. /*if Radio On return true here */
  1450. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  1451. if (valid) {
  1452. if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
  1453. rtlpriv->rfkill.rfkill_state = radio_state;
  1454. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1455. "wireless radio switch turned %s\n",
  1456. radio_state ? "on" : "off");
  1457. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  1458. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  1459. }
  1460. }
  1461. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1462. }
  1463. /* this function is called by mac80211 to flush tx buffer
  1464. * before switch channle or power save, or tx buffer packet
  1465. * maybe send after offchannel or rf sleep, this may cause
  1466. * dis-association by AP */
  1467. static void rtl_op_flush(struct ieee80211_hw *hw,
  1468. struct ieee80211_vif *vif,
  1469. u32 queues,
  1470. bool drop)
  1471. {
  1472. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1473. if (rtlpriv->intf_ops->flush)
  1474. rtlpriv->intf_ops->flush(hw, queues, drop);
  1475. }
  1476. /* Description:
  1477. * This routine deals with the Power Configuration CMD
  1478. * parsing for RTL8723/RTL8188E Series IC.
  1479. * Assumption:
  1480. * We should follow specific format that was released from HW SD.
  1481. */
  1482. bool rtl_hal_pwrseqcmdparsing(struct rtl_priv *rtlpriv, u8 cut_version,
  1483. u8 faversion, u8 interface_type,
  1484. struct wlan_pwr_cfg pwrcfgcmd[])
  1485. {
  1486. struct wlan_pwr_cfg cfg_cmd = {0};
  1487. bool polling_bit = false;
  1488. u32 ary_idx = 0;
  1489. u8 value = 0;
  1490. u32 offset = 0;
  1491. u32 polling_count = 0;
  1492. u32 max_polling_cnt = 5000;
  1493. do {
  1494. cfg_cmd = pwrcfgcmd[ary_idx];
  1495. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1496. "rtl_hal_pwrseqcmdparsing(): offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n",
  1497. GET_PWR_CFG_OFFSET(cfg_cmd),
  1498. GET_PWR_CFG_CUT_MASK(cfg_cmd),
  1499. GET_PWR_CFG_FAB_MASK(cfg_cmd),
  1500. GET_PWR_CFG_INTF_MASK(cfg_cmd),
  1501. GET_PWR_CFG_BASE(cfg_cmd), GET_PWR_CFG_CMD(cfg_cmd),
  1502. GET_PWR_CFG_MASK(cfg_cmd), GET_PWR_CFG_VALUE(cfg_cmd));
  1503. if ((GET_PWR_CFG_FAB_MASK(cfg_cmd)&faversion) &&
  1504. (GET_PWR_CFG_CUT_MASK(cfg_cmd)&cut_version) &&
  1505. (GET_PWR_CFG_INTF_MASK(cfg_cmd)&interface_type)) {
  1506. switch (GET_PWR_CFG_CMD(cfg_cmd)) {
  1507. case PWR_CMD_READ:
  1508. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1509. "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n");
  1510. break;
  1511. case PWR_CMD_WRITE:
  1512. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1513. "rtl_hal_pwrseqcmdparsing(): PWR_CMD_WRITE\n");
  1514. offset = GET_PWR_CFG_OFFSET(cfg_cmd);
  1515. /*Read the value from system register*/
  1516. value = rtl_read_byte(rtlpriv, offset);
  1517. value &= (~(GET_PWR_CFG_MASK(cfg_cmd)));
  1518. value |= (GET_PWR_CFG_VALUE(cfg_cmd) &
  1519. GET_PWR_CFG_MASK(cfg_cmd));
  1520. /*Write the value back to sytem register*/
  1521. rtl_write_byte(rtlpriv, offset, value);
  1522. break;
  1523. case PWR_CMD_POLLING:
  1524. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1525. "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n");
  1526. polling_bit = false;
  1527. offset = GET_PWR_CFG_OFFSET(cfg_cmd);
  1528. do {
  1529. value = rtl_read_byte(rtlpriv, offset);
  1530. value &= GET_PWR_CFG_MASK(cfg_cmd);
  1531. if (value ==
  1532. (GET_PWR_CFG_VALUE(cfg_cmd) &
  1533. GET_PWR_CFG_MASK(cfg_cmd)))
  1534. polling_bit = true;
  1535. else
  1536. udelay(10);
  1537. if (polling_count++ > max_polling_cnt)
  1538. return false;
  1539. } while (!polling_bit);
  1540. break;
  1541. case PWR_CMD_DELAY:
  1542. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1543. "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n");
  1544. if (GET_PWR_CFG_VALUE(cfg_cmd) ==
  1545. PWRSEQ_DELAY_US)
  1546. udelay(GET_PWR_CFG_OFFSET(cfg_cmd));
  1547. else
  1548. mdelay(GET_PWR_CFG_OFFSET(cfg_cmd));
  1549. break;
  1550. case PWR_CMD_END:
  1551. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1552. "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n");
  1553. return true;
  1554. default:
  1555. RT_ASSERT(false,
  1556. "rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n");
  1557. break;
  1558. }
  1559. }
  1560. ary_idx++;
  1561. } while (1);
  1562. return true;
  1563. }
  1564. EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing);
  1565. bool rtl_cmd_send_packet(struct ieee80211_hw *hw, struct sk_buff *skb)
  1566. {
  1567. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1568. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1569. struct rtl8192_tx_ring *ring;
  1570. struct rtl_tx_desc *pdesc;
  1571. unsigned long flags;
  1572. struct sk_buff *pskb = NULL;
  1573. ring = &rtlpci->tx_ring[BEACON_QUEUE];
  1574. spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
  1575. pskb = __skb_dequeue(&ring->queue);
  1576. if (pskb)
  1577. kfree_skb(pskb);
  1578. /*this is wrong, fill_tx_cmddesc needs update*/
  1579. pdesc = &ring->desc[0];
  1580. rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *)pdesc, 1, 1, skb);
  1581. __skb_queue_tail(&ring->queue, skb);
  1582. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  1583. rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE);
  1584. return true;
  1585. }
  1586. EXPORT_SYMBOL(rtl_cmd_send_packet);
  1587. const struct ieee80211_ops rtl_ops = {
  1588. .start = rtl_op_start,
  1589. .stop = rtl_op_stop,
  1590. .tx = rtl_op_tx,
  1591. .add_interface = rtl_op_add_interface,
  1592. .remove_interface = rtl_op_remove_interface,
  1593. .change_interface = rtl_op_change_interface,
  1594. #ifdef CONFIG_PM
  1595. .suspend = rtl_op_suspend,
  1596. .resume = rtl_op_resume,
  1597. #endif
  1598. .config = rtl_op_config,
  1599. .configure_filter = rtl_op_configure_filter,
  1600. .set_key = rtl_op_set_key,
  1601. .conf_tx = rtl_op_conf_tx,
  1602. .bss_info_changed = rtl_op_bss_info_changed,
  1603. .get_tsf = rtl_op_get_tsf,
  1604. .set_tsf = rtl_op_set_tsf,
  1605. .reset_tsf = rtl_op_reset_tsf,
  1606. .sta_notify = rtl_op_sta_notify,
  1607. .ampdu_action = rtl_op_ampdu_action,
  1608. .sw_scan_start = rtl_op_sw_scan_start,
  1609. .sw_scan_complete = rtl_op_sw_scan_complete,
  1610. .rfkill_poll = rtl_op_rfkill_poll,
  1611. .sta_add = rtl_op_sta_add,
  1612. .sta_remove = rtl_op_sta_remove,
  1613. .flush = rtl_op_flush,
  1614. };
  1615. EXPORT_SYMBOL_GPL(rtl_ops);
  1616. bool rtl_btc_status_false(void)
  1617. {
  1618. return false;
  1619. }
  1620. EXPORT_SYMBOL_GPL(rtl_btc_status_false);