base.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  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 "rc.h"
  27. #include "base.h"
  28. #include "efuse.h"
  29. #include "cam.h"
  30. #include "ps.h"
  31. #include "regd.h"
  32. #include "pci.h"
  33. #include <linux/ip.h>
  34. #include <linux/module.h>
  35. #include <linux/udp.h>
  36. /*
  37. *NOTICE!!!: This file will be very big, we should
  38. *keep it clear under following roles:
  39. *
  40. *This file include following parts, so, if you add new
  41. *functions into this file, please check which part it
  42. *should includes. or check if you should add new part
  43. *for this file:
  44. *
  45. *1) mac80211 init functions
  46. *2) tx information functions
  47. *3) functions called by core.c
  48. *4) wq & timer callback functions
  49. *5) frame process functions
  50. *6) IOT functions
  51. *7) sysfs functions
  52. *8) vif functions
  53. *9) ...
  54. */
  55. /*********************************************************
  56. *
  57. * mac80211 init functions
  58. *
  59. *********************************************************/
  60. static struct ieee80211_channel rtl_channeltable_2g[] = {
  61. {.center_freq = 2412, .hw_value = 1,},
  62. {.center_freq = 2417, .hw_value = 2,},
  63. {.center_freq = 2422, .hw_value = 3,},
  64. {.center_freq = 2427, .hw_value = 4,},
  65. {.center_freq = 2432, .hw_value = 5,},
  66. {.center_freq = 2437, .hw_value = 6,},
  67. {.center_freq = 2442, .hw_value = 7,},
  68. {.center_freq = 2447, .hw_value = 8,},
  69. {.center_freq = 2452, .hw_value = 9,},
  70. {.center_freq = 2457, .hw_value = 10,},
  71. {.center_freq = 2462, .hw_value = 11,},
  72. {.center_freq = 2467, .hw_value = 12,},
  73. {.center_freq = 2472, .hw_value = 13,},
  74. {.center_freq = 2484, .hw_value = 14,},
  75. };
  76. static struct ieee80211_channel rtl_channeltable_5g[] = {
  77. {.center_freq = 5180, .hw_value = 36,},
  78. {.center_freq = 5200, .hw_value = 40,},
  79. {.center_freq = 5220, .hw_value = 44,},
  80. {.center_freq = 5240, .hw_value = 48,},
  81. {.center_freq = 5260, .hw_value = 52,},
  82. {.center_freq = 5280, .hw_value = 56,},
  83. {.center_freq = 5300, .hw_value = 60,},
  84. {.center_freq = 5320, .hw_value = 64,},
  85. {.center_freq = 5500, .hw_value = 100,},
  86. {.center_freq = 5520, .hw_value = 104,},
  87. {.center_freq = 5540, .hw_value = 108,},
  88. {.center_freq = 5560, .hw_value = 112,},
  89. {.center_freq = 5580, .hw_value = 116,},
  90. {.center_freq = 5600, .hw_value = 120,},
  91. {.center_freq = 5620, .hw_value = 124,},
  92. {.center_freq = 5640, .hw_value = 128,},
  93. {.center_freq = 5660, .hw_value = 132,},
  94. {.center_freq = 5680, .hw_value = 136,},
  95. {.center_freq = 5700, .hw_value = 140,},
  96. {.center_freq = 5745, .hw_value = 149,},
  97. {.center_freq = 5765, .hw_value = 153,},
  98. {.center_freq = 5785, .hw_value = 157,},
  99. {.center_freq = 5805, .hw_value = 161,},
  100. {.center_freq = 5825, .hw_value = 165,},
  101. };
  102. static struct ieee80211_rate rtl_ratetable_2g[] = {
  103. {.bitrate = 10, .hw_value = 0x00,},
  104. {.bitrate = 20, .hw_value = 0x01,},
  105. {.bitrate = 55, .hw_value = 0x02,},
  106. {.bitrate = 110, .hw_value = 0x03,},
  107. {.bitrate = 60, .hw_value = 0x04,},
  108. {.bitrate = 90, .hw_value = 0x05,},
  109. {.bitrate = 120, .hw_value = 0x06,},
  110. {.bitrate = 180, .hw_value = 0x07,},
  111. {.bitrate = 240, .hw_value = 0x08,},
  112. {.bitrate = 360, .hw_value = 0x09,},
  113. {.bitrate = 480, .hw_value = 0x0a,},
  114. {.bitrate = 540, .hw_value = 0x0b,},
  115. };
  116. static struct ieee80211_rate rtl_ratetable_5g[] = {
  117. {.bitrate = 60, .hw_value = 0x04,},
  118. {.bitrate = 90, .hw_value = 0x05,},
  119. {.bitrate = 120, .hw_value = 0x06,},
  120. {.bitrate = 180, .hw_value = 0x07,},
  121. {.bitrate = 240, .hw_value = 0x08,},
  122. {.bitrate = 360, .hw_value = 0x09,},
  123. {.bitrate = 480, .hw_value = 0x0a,},
  124. {.bitrate = 540, .hw_value = 0x0b,},
  125. };
  126. static const struct ieee80211_supported_band rtl_band_2ghz = {
  127. .band = IEEE80211_BAND_2GHZ,
  128. .channels = rtl_channeltable_2g,
  129. .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
  130. .bitrates = rtl_ratetable_2g,
  131. .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
  132. .ht_cap = {0},
  133. };
  134. static struct ieee80211_supported_band rtl_band_5ghz = {
  135. .band = IEEE80211_BAND_5GHZ,
  136. .channels = rtl_channeltable_5g,
  137. .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
  138. .bitrates = rtl_ratetable_5g,
  139. .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
  140. .ht_cap = {0},
  141. };
  142. static const u8 tid_to_ac[] = {
  143. 2, /* IEEE80211_AC_BE */
  144. 3, /* IEEE80211_AC_BK */
  145. 3, /* IEEE80211_AC_BK */
  146. 2, /* IEEE80211_AC_BE */
  147. 1, /* IEEE80211_AC_VI */
  148. 1, /* IEEE80211_AC_VI */
  149. 0, /* IEEE80211_AC_VO */
  150. 0, /* IEEE80211_AC_VO */
  151. };
  152. u8 rtl_tid_to_ac(u8 tid)
  153. {
  154. return tid_to_ac[tid];
  155. }
  156. EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
  157. static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
  158. struct ieee80211_sta_ht_cap *ht_cap)
  159. {
  160. struct rtl_priv *rtlpriv = rtl_priv(hw);
  161. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  162. ht_cap->ht_supported = true;
  163. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  164. IEEE80211_HT_CAP_SGI_40 |
  165. IEEE80211_HT_CAP_SGI_20 |
  166. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  167. if (rtlpriv->rtlhal.disable_amsdu_8k)
  168. ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  169. /*
  170. *Maximum length of AMPDU that the STA can receive.
  171. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  172. */
  173. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  174. /*Minimum MPDU start spacing , */
  175. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  176. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  177. /*hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  178. *base on ant_num
  179. *rx_mask: RX mask
  180. *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
  181. *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
  182. *if rx_ant >= 3 rx_mask[2]= 0xff;
  183. *if BW_40 rx_mask[4]= 0x01;
  184. *highest supported RX rate
  185. */
  186. if (rtlpriv->dm.supp_phymode_switch) {
  187. RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
  188. "Support phy mode switch\n");
  189. ht_cap->mcs.rx_mask[0] = 0xFF;
  190. ht_cap->mcs.rx_mask[1] = 0xFF;
  191. ht_cap->mcs.rx_mask[4] = 0x01;
  192. ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  193. } else {
  194. if (get_rf_type(rtlphy) == RF_1T2R ||
  195. get_rf_type(rtlphy) == RF_2T2R) {
  196. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  197. "1T2R or 2T2R\n");
  198. ht_cap->mcs.rx_mask[0] = 0xFF;
  199. ht_cap->mcs.rx_mask[1] = 0xFF;
  200. ht_cap->mcs.rx_mask[4] = 0x01;
  201. ht_cap->mcs.rx_highest =
  202. cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  203. } else if (get_rf_type(rtlphy) == RF_1T1R) {
  204. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
  205. ht_cap->mcs.rx_mask[0] = 0xFF;
  206. ht_cap->mcs.rx_mask[1] = 0x00;
  207. ht_cap->mcs.rx_mask[4] = 0x01;
  208. ht_cap->mcs.rx_highest =
  209. cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
  210. }
  211. }
  212. }
  213. static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
  214. struct ieee80211_sta_vht_cap *vht_cap)
  215. {
  216. struct rtl_priv *rtlpriv = rtl_priv(hw);
  217. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  218. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
  219. u16 mcs_map;
  220. vht_cap->vht_supported = true;
  221. vht_cap->cap =
  222. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
  223. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
  224. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  225. IEEE80211_VHT_CAP_SHORT_GI_80 |
  226. IEEE80211_VHT_CAP_TXSTBC |
  227. IEEE80211_VHT_CAP_RXSTBC_1 |
  228. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  229. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  230. IEEE80211_VHT_CAP_HTC_VHT |
  231. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  232. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  233. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  234. 0;
  235. mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  236. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  237. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  238. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  239. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  240. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  241. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  242. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
  243. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  244. vht_cap->vht_mcs.rx_highest =
  245. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
  246. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  247. vht_cap->vht_mcs.tx_highest =
  248. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
  249. } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
  250. u16 mcs_map;
  251. vht_cap->vht_supported = true;
  252. vht_cap->cap =
  253. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
  254. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
  255. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  256. IEEE80211_VHT_CAP_SHORT_GI_80 |
  257. IEEE80211_VHT_CAP_TXSTBC |
  258. IEEE80211_VHT_CAP_RXSTBC_1 |
  259. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  260. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  261. IEEE80211_VHT_CAP_HTC_VHT |
  262. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  263. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  264. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  265. 0;
  266. mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  267. IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
  268. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  269. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  270. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  271. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  272. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  273. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
  274. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  275. vht_cap->vht_mcs.rx_highest =
  276. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
  277. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  278. vht_cap->vht_mcs.tx_highest =
  279. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
  280. }
  281. }
  282. static void _rtl_init_mac80211(struct ieee80211_hw *hw)
  283. {
  284. struct rtl_priv *rtlpriv = rtl_priv(hw);
  285. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  286. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  287. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  288. struct ieee80211_supported_band *sband;
  289. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
  290. rtlhal->bandset == BAND_ON_BOTH) {
  291. /* 1: 2.4 G bands */
  292. /* <1> use mac->bands as mem for hw->wiphy->bands */
  293. sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
  294. /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  295. * to default value(1T1R) */
  296. memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
  297. sizeof(struct ieee80211_supported_band));
  298. /* <3> init ht cap base on ant_num */
  299. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  300. /* <4> set mac->sband to wiphy->sband */
  301. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
  302. /* 2: 5 G bands */
  303. /* <1> use mac->bands as mem for hw->wiphy->bands */
  304. sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
  305. /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
  306. * to default value(1T1R) */
  307. memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
  308. sizeof(struct ieee80211_supported_band));
  309. /* <3> init ht cap base on ant_num */
  310. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  311. _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
  312. /* <4> set mac->sband to wiphy->sband */
  313. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
  314. } else {
  315. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  316. /* <1> use mac->bands as mem for hw->wiphy->bands */
  317. sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
  318. /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  319. * to default value(1T1R) */
  320. memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
  321. &rtl_band_2ghz,
  322. sizeof(struct ieee80211_supported_band));
  323. /* <3> init ht cap base on ant_num */
  324. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  325. /* <4> set mac->sband to wiphy->sband */
  326. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
  327. } else if (rtlhal->current_bandtype == BAND_ON_5G) {
  328. /* <1> use mac->bands as mem for hw->wiphy->bands */
  329. sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
  330. /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
  331. * to default value(1T1R) */
  332. memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
  333. &rtl_band_5ghz,
  334. sizeof(struct ieee80211_supported_band));
  335. /* <3> init ht cap base on ant_num */
  336. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  337. _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
  338. /* <4> set mac->sband to wiphy->sband */
  339. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
  340. } else {
  341. RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
  342. rtlhal->current_bandtype);
  343. }
  344. }
  345. /* <5> set hw caps */
  346. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  347. IEEE80211_HW_RX_INCLUDES_FCS |
  348. IEEE80211_HW_AMPDU_AGGREGATION |
  349. IEEE80211_HW_CONNECTION_MONITOR |
  350. /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
  351. IEEE80211_HW_MFP_CAPABLE |
  352. IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
  353. /* swlps or hwlps has been set in diff chip in init_sw_vars */
  354. if (rtlpriv->psc.swctrl_lps)
  355. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  356. IEEE80211_HW_PS_NULLFUNC_STACK |
  357. /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
  358. 0;
  359. hw->wiphy->interface_modes =
  360. BIT(NL80211_IFTYPE_AP) |
  361. BIT(NL80211_IFTYPE_STATION) |
  362. BIT(NL80211_IFTYPE_ADHOC) |
  363. BIT(NL80211_IFTYPE_MESH_POINT) |
  364. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  365. BIT(NL80211_IFTYPE_P2P_GO);
  366. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  367. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  368. hw->wiphy->rts_threshold = 2347;
  369. hw->queues = AC_MAX;
  370. hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
  371. /* TODO: Correct this value for our hw */
  372. /* TODO: define these hard code value */
  373. hw->max_listen_interval = 10;
  374. hw->max_rate_tries = 4;
  375. /* hw->max_rates = 1; */
  376. hw->sta_data_size = sizeof(struct rtl_sta_info);
  377. /* wowlan is not supported by kernel if CONFIG_PM is not defined */
  378. #ifdef CONFIG_PM
  379. if (rtlpriv->psc.wo_wlan_mode) {
  380. if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
  381. rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
  382. if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
  383. rtlpriv->wowlan.n_patterns =
  384. MAX_SUPPORT_WOL_PATTERN_NUM;
  385. rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
  386. rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
  387. }
  388. hw->wiphy->wowlan = &rtlpriv->wowlan;
  389. }
  390. #endif
  391. /* <6> mac address */
  392. if (is_valid_ether_addr(rtlefuse->dev_addr)) {
  393. SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
  394. } else {
  395. u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
  396. get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
  397. SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
  398. }
  399. }
  400. static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
  401. {
  402. struct rtl_priv *rtlpriv = rtl_priv(hw);
  403. /* <1> timer */
  404. setup_timer(&rtlpriv->works.watchdog_timer,
  405. rtl_watch_dog_timer_callback, (unsigned long)hw);
  406. setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
  407. rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
  408. /* <2> work queue */
  409. rtlpriv->works.hw = hw;
  410. rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
  411. INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
  412. (void *)rtl_watchdog_wq_callback);
  413. INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
  414. (void *)rtl_ips_nic_off_wq_callback);
  415. INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
  416. (void *)rtl_swlps_wq_callback);
  417. INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
  418. (void *)rtl_swlps_rfon_wq_callback);
  419. INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
  420. (void *)rtl_fwevt_wq_callback);
  421. }
  422. void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
  423. {
  424. struct rtl_priv *rtlpriv = rtl_priv(hw);
  425. del_timer_sync(&rtlpriv->works.watchdog_timer);
  426. cancel_delayed_work(&rtlpriv->works.watchdog_wq);
  427. cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
  428. cancel_delayed_work(&rtlpriv->works.ps_work);
  429. cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
  430. cancel_delayed_work(&rtlpriv->works.fwevt_wq);
  431. }
  432. EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
  433. void rtl_init_rfkill(struct ieee80211_hw *hw)
  434. {
  435. struct rtl_priv *rtlpriv = rtl_priv(hw);
  436. bool radio_state;
  437. bool blocked;
  438. u8 valid = 0;
  439. /*set init state to on */
  440. rtlpriv->rfkill.rfkill_state = true;
  441. wiphy_rfkill_set_hw_state(hw->wiphy, 0);
  442. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  443. if (valid) {
  444. pr_info("rtlwifi: wireless switch is %s\n",
  445. rtlpriv->rfkill.rfkill_state ? "on" : "off");
  446. rtlpriv->rfkill.rfkill_state = radio_state;
  447. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  448. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  449. }
  450. wiphy_rfkill_start_polling(hw->wiphy);
  451. }
  452. EXPORT_SYMBOL(rtl_init_rfkill);
  453. void rtl_deinit_rfkill(struct ieee80211_hw *hw)
  454. {
  455. wiphy_rfkill_stop_polling(hw->wiphy);
  456. }
  457. EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
  458. int rtl_init_core(struct ieee80211_hw *hw)
  459. {
  460. struct rtl_priv *rtlpriv = rtl_priv(hw);
  461. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  462. /* <1> init mac80211 */
  463. _rtl_init_mac80211(hw);
  464. rtlmac->hw = hw;
  465. /* <2> rate control register */
  466. hw->rate_control_algorithm = "rtl_rc";
  467. /*
  468. * <3> init CRDA must come after init
  469. * mac80211 hw in _rtl_init_mac80211.
  470. */
  471. if (rtl_regd_init(hw, rtl_reg_notifier)) {
  472. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
  473. return 1;
  474. }
  475. /* <4> locks */
  476. mutex_init(&rtlpriv->locks.conf_mutex);
  477. spin_lock_init(&rtlpriv->locks.ips_lock);
  478. spin_lock_init(&rtlpriv->locks.irq_th_lock);
  479. spin_lock_init(&rtlpriv->locks.h2c_lock);
  480. spin_lock_init(&rtlpriv->locks.rf_ps_lock);
  481. spin_lock_init(&rtlpriv->locks.rf_lock);
  482. spin_lock_init(&rtlpriv->locks.waitq_lock);
  483. spin_lock_init(&rtlpriv->locks.entry_list_lock);
  484. spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
  485. spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
  486. spin_lock_init(&rtlpriv->locks.fw_ps_lock);
  487. spin_lock_init(&rtlpriv->locks.lps_lock);
  488. spin_lock_init(&rtlpriv->locks.iqk_lock);
  489. /* <5> init list */
  490. INIT_LIST_HEAD(&rtlpriv->entry_list);
  491. rtlmac->link_state = MAC80211_NOLINK;
  492. /* <6> init deferred work */
  493. _rtl_init_deferred_work(hw);
  494. return 0;
  495. }
  496. EXPORT_SYMBOL_GPL(rtl_init_core);
  497. void rtl_deinit_core(struct ieee80211_hw *hw)
  498. {
  499. }
  500. EXPORT_SYMBOL_GPL(rtl_deinit_core);
  501. void rtl_init_rx_config(struct ieee80211_hw *hw)
  502. {
  503. struct rtl_priv *rtlpriv = rtl_priv(hw);
  504. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  505. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
  506. }
  507. EXPORT_SYMBOL_GPL(rtl_init_rx_config);
  508. /*********************************************************
  509. *
  510. * tx information functions
  511. *
  512. *********************************************************/
  513. static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
  514. struct rtl_tcb_desc *tcb_desc,
  515. struct ieee80211_tx_info *info)
  516. {
  517. struct rtl_priv *rtlpriv = rtl_priv(hw);
  518. u8 rate_flag = info->control.rates[0].flags;
  519. tcb_desc->use_shortpreamble = false;
  520. /* 1M can only use Long Preamble. 11B spec */
  521. if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
  522. return;
  523. else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  524. tcb_desc->use_shortpreamble = true;
  525. return;
  526. }
  527. static void _rtl_query_shortgi(struct ieee80211_hw *hw,
  528. struct ieee80211_sta *sta,
  529. struct rtl_tcb_desc *tcb_desc,
  530. struct ieee80211_tx_info *info)
  531. {
  532. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  533. u8 rate_flag = info->control.rates[0].flags;
  534. u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
  535. u8 sgi_80 = 0, bw_80 = 0;
  536. tcb_desc->use_shortgi = false;
  537. if (sta == NULL)
  538. return;
  539. sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  540. sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
  541. sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
  542. if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
  543. return;
  544. if (!sgi_40 && !sgi_20)
  545. return;
  546. if (mac->opmode == NL80211_IFTYPE_STATION) {
  547. bw_40 = mac->bw_40;
  548. bw_80 = mac->bw_80;
  549. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  550. mac->opmode == NL80211_IFTYPE_ADHOC ||
  551. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  552. bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  553. bw_80 = sta->vht_cap.vht_supported;
  554. }
  555. if (bw_80) {
  556. if (sgi_80)
  557. tcb_desc->use_shortgi = true;
  558. else
  559. tcb_desc->use_shortgi = false;
  560. } else {
  561. if (bw_40 && sgi_40)
  562. tcb_desc->use_shortgi = true;
  563. else if (!bw_40 && sgi_20)
  564. tcb_desc->use_shortgi = true;
  565. }
  566. if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
  567. tcb_desc->use_shortgi = false;
  568. }
  569. static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
  570. struct rtl_tcb_desc *tcb_desc,
  571. struct ieee80211_tx_info *info)
  572. {
  573. struct rtl_priv *rtlpriv = rtl_priv(hw);
  574. u8 rate_flag = info->control.rates[0].flags;
  575. /* Common Settings */
  576. tcb_desc->rts_stbc = false;
  577. tcb_desc->cts_enable = false;
  578. tcb_desc->rts_sc = 0;
  579. tcb_desc->rts_bw = false;
  580. tcb_desc->rts_use_shortpreamble = false;
  581. tcb_desc->rts_use_shortgi = false;
  582. if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  583. /* Use CTS-to-SELF in protection mode. */
  584. tcb_desc->rts_enable = true;
  585. tcb_desc->cts_enable = true;
  586. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  587. } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
  588. /* Use RTS-CTS in protection mode. */
  589. tcb_desc->rts_enable = true;
  590. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  591. }
  592. }
  593. static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
  594. struct ieee80211_sta *sta,
  595. struct rtl_tcb_desc *tcb_desc)
  596. {
  597. struct rtl_priv *rtlpriv = rtl_priv(hw);
  598. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  599. struct rtl_sta_info *sta_entry = NULL;
  600. u8 ratr_index = 7;
  601. if (sta) {
  602. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  603. ratr_index = sta_entry->ratr_index;
  604. }
  605. if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
  606. if (mac->opmode == NL80211_IFTYPE_STATION) {
  607. tcb_desc->ratr_index = 0;
  608. } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
  609. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  610. if (tcb_desc->multicast || tcb_desc->broadcast) {
  611. tcb_desc->hw_rate =
  612. rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
  613. tcb_desc->use_driver_rate = 1;
  614. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  615. } else {
  616. tcb_desc->ratr_index = ratr_index;
  617. }
  618. } else if (mac->opmode == NL80211_IFTYPE_AP) {
  619. tcb_desc->ratr_index = ratr_index;
  620. }
  621. }
  622. if (rtlpriv->dm.useramask) {
  623. tcb_desc->ratr_index = ratr_index;
  624. /* TODO we will differentiate adhoc and station future */
  625. if (mac->opmode == NL80211_IFTYPE_STATION ||
  626. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  627. tcb_desc->mac_id = 0;
  628. if (mac->mode == WIRELESS_MODE_AC_5G)
  629. tcb_desc->ratr_index =
  630. RATR_INX_WIRELESS_AC_5N;
  631. else if (mac->mode == WIRELESS_MODE_AC_24G)
  632. tcb_desc->ratr_index =
  633. RATR_INX_WIRELESS_AC_24N;
  634. else if (mac->mode == WIRELESS_MODE_N_24G)
  635. tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
  636. else if (mac->mode == WIRELESS_MODE_N_5G)
  637. tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
  638. else if (mac->mode & WIRELESS_MODE_G)
  639. tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
  640. else if (mac->mode & WIRELESS_MODE_B)
  641. tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
  642. else if (mac->mode & WIRELESS_MODE_A)
  643. tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
  644. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  645. mac->opmode == NL80211_IFTYPE_ADHOC) {
  646. if (NULL != sta) {
  647. if (sta->aid > 0)
  648. tcb_desc->mac_id = sta->aid + 1;
  649. else
  650. tcb_desc->mac_id = 1;
  651. } else {
  652. tcb_desc->mac_id = 0;
  653. }
  654. }
  655. }
  656. }
  657. static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
  658. struct ieee80211_sta *sta,
  659. struct rtl_tcb_desc *tcb_desc)
  660. {
  661. struct rtl_priv *rtlpriv = rtl_priv(hw);
  662. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  663. tcb_desc->packet_bw = false;
  664. if (!sta)
  665. return;
  666. if (mac->opmode == NL80211_IFTYPE_AP ||
  667. mac->opmode == NL80211_IFTYPE_ADHOC ||
  668. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  669. if (!(sta->ht_cap.ht_supported) ||
  670. !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  671. return;
  672. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  673. if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
  674. return;
  675. }
  676. if (tcb_desc->multicast || tcb_desc->broadcast)
  677. return;
  678. /*use legency rate, shall use 20MHz */
  679. if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
  680. return;
  681. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
  682. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
  683. rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
  684. if (mac->opmode == NL80211_IFTYPE_AP ||
  685. mac->opmode == NL80211_IFTYPE_ADHOC ||
  686. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  687. if (!(sta->vht_cap.vht_supported))
  688. return;
  689. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  690. if (!mac->bw_80 ||
  691. !(sta->vht_cap.vht_supported))
  692. return;
  693. }
  694. if (tcb_desc->hw_rate <=
  695. rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
  696. return;
  697. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
  698. }
  699. }
  700. static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
  701. struct ieee80211_sta *sta)
  702. {
  703. struct rtl_priv *rtlpriv = rtl_priv(hw);
  704. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  705. u8 hw_rate;
  706. u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
  707. if ((get_rf_type(rtlphy) == RF_2T2R) &&
  708. (tx_mcs_map & 0x000c) != 0x000c) {
  709. if ((tx_mcs_map & 0x000c) >> 2 ==
  710. IEEE80211_VHT_MCS_SUPPORT_0_7)
  711. hw_rate =
  712. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
  713. else if ((tx_mcs_map & 0x000c) >> 2 ==
  714. IEEE80211_VHT_MCS_SUPPORT_0_8)
  715. hw_rate =
  716. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  717. else
  718. hw_rate =
  719. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  720. } else {
  721. if ((tx_mcs_map & 0x0003) ==
  722. IEEE80211_VHT_MCS_SUPPORT_0_7)
  723. hw_rate =
  724. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
  725. else if ((tx_mcs_map & 0x0003) ==
  726. IEEE80211_VHT_MCS_SUPPORT_0_8)
  727. hw_rate =
  728. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  729. else
  730. hw_rate =
  731. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  732. }
  733. return hw_rate;
  734. }
  735. static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
  736. struct ieee80211_sta *sta)
  737. {
  738. struct rtl_priv *rtlpriv = rtl_priv(hw);
  739. struct rtl_phy *rtlphy = &rtlpriv->phy;
  740. u8 hw_rate;
  741. if ((get_rf_type(rtlphy) == RF_2T2R) &&
  742. (sta->ht_cap.mcs.rx_mask[1] != 0))
  743. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
  744. else
  745. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
  746. return hw_rate;
  747. }
  748. /* mac80211's rate_idx is like this:
  749. *
  750. * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
  751. *
  752. * B/G rate:
  753. * (rx_status->flag & RX_FLAG_HT) = 0,
  754. * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
  755. *
  756. * N rate:
  757. * (rx_status->flag & RX_FLAG_HT) = 1,
  758. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  759. *
  760. * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
  761. * A rate:
  762. * (rx_status->flag & RX_FLAG_HT) = 0,
  763. * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
  764. *
  765. * N rate:
  766. * (rx_status->flag & RX_FLAG_HT) = 1,
  767. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  768. *
  769. * VHT rates:
  770. * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
  771. * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
  772. */
  773. int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
  774. u8 desc_rate)
  775. {
  776. int rate_idx;
  777. if (isvht) {
  778. switch (desc_rate) {
  779. case DESC_RATEVHT1SS_MCS0:
  780. rate_idx = 0;
  781. break;
  782. case DESC_RATEVHT1SS_MCS1:
  783. rate_idx = 1;
  784. break;
  785. case DESC_RATEVHT1SS_MCS2:
  786. rate_idx = 2;
  787. break;
  788. case DESC_RATEVHT1SS_MCS3:
  789. rate_idx = 3;
  790. break;
  791. case DESC_RATEVHT1SS_MCS4:
  792. rate_idx = 4;
  793. break;
  794. case DESC_RATEVHT1SS_MCS5:
  795. rate_idx = 5;
  796. break;
  797. case DESC_RATEVHT1SS_MCS6:
  798. rate_idx = 6;
  799. break;
  800. case DESC_RATEVHT1SS_MCS7:
  801. rate_idx = 7;
  802. break;
  803. case DESC_RATEVHT1SS_MCS8:
  804. rate_idx = 8;
  805. break;
  806. case DESC_RATEVHT1SS_MCS9:
  807. rate_idx = 9;
  808. break;
  809. case DESC_RATEVHT2SS_MCS0:
  810. rate_idx = 0;
  811. break;
  812. case DESC_RATEVHT2SS_MCS1:
  813. rate_idx = 1;
  814. break;
  815. case DESC_RATEVHT2SS_MCS2:
  816. rate_idx = 2;
  817. break;
  818. case DESC_RATEVHT2SS_MCS3:
  819. rate_idx = 3;
  820. break;
  821. case DESC_RATEVHT2SS_MCS4:
  822. rate_idx = 4;
  823. break;
  824. case DESC_RATEVHT2SS_MCS5:
  825. rate_idx = 5;
  826. break;
  827. case DESC_RATEVHT2SS_MCS6:
  828. rate_idx = 6;
  829. break;
  830. case DESC_RATEVHT2SS_MCS7:
  831. rate_idx = 7;
  832. break;
  833. case DESC_RATEVHT2SS_MCS8:
  834. rate_idx = 8;
  835. break;
  836. case DESC_RATEVHT2SS_MCS9:
  837. rate_idx = 9;
  838. break;
  839. default:
  840. rate_idx = 0;
  841. break;
  842. }
  843. return rate_idx;
  844. }
  845. if (false == isht) {
  846. if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
  847. switch (desc_rate) {
  848. case DESC_RATE1M:
  849. rate_idx = 0;
  850. break;
  851. case DESC_RATE2M:
  852. rate_idx = 1;
  853. break;
  854. case DESC_RATE5_5M:
  855. rate_idx = 2;
  856. break;
  857. case DESC_RATE11M:
  858. rate_idx = 3;
  859. break;
  860. case DESC_RATE6M:
  861. rate_idx = 4;
  862. break;
  863. case DESC_RATE9M:
  864. rate_idx = 5;
  865. break;
  866. case DESC_RATE12M:
  867. rate_idx = 6;
  868. break;
  869. case DESC_RATE18M:
  870. rate_idx = 7;
  871. break;
  872. case DESC_RATE24M:
  873. rate_idx = 8;
  874. break;
  875. case DESC_RATE36M:
  876. rate_idx = 9;
  877. break;
  878. case DESC_RATE48M:
  879. rate_idx = 10;
  880. break;
  881. case DESC_RATE54M:
  882. rate_idx = 11;
  883. break;
  884. default:
  885. rate_idx = 0;
  886. break;
  887. }
  888. } else {
  889. switch (desc_rate) {
  890. case DESC_RATE6M:
  891. rate_idx = 0;
  892. break;
  893. case DESC_RATE9M:
  894. rate_idx = 1;
  895. break;
  896. case DESC_RATE12M:
  897. rate_idx = 2;
  898. break;
  899. case DESC_RATE18M:
  900. rate_idx = 3;
  901. break;
  902. case DESC_RATE24M:
  903. rate_idx = 4;
  904. break;
  905. case DESC_RATE36M:
  906. rate_idx = 5;
  907. break;
  908. case DESC_RATE48M:
  909. rate_idx = 6;
  910. break;
  911. case DESC_RATE54M:
  912. rate_idx = 7;
  913. break;
  914. default:
  915. rate_idx = 0;
  916. break;
  917. }
  918. }
  919. } else {
  920. switch (desc_rate) {
  921. case DESC_RATEMCS0:
  922. rate_idx = 0;
  923. break;
  924. case DESC_RATEMCS1:
  925. rate_idx = 1;
  926. break;
  927. case DESC_RATEMCS2:
  928. rate_idx = 2;
  929. break;
  930. case DESC_RATEMCS3:
  931. rate_idx = 3;
  932. break;
  933. case DESC_RATEMCS4:
  934. rate_idx = 4;
  935. break;
  936. case DESC_RATEMCS5:
  937. rate_idx = 5;
  938. break;
  939. case DESC_RATEMCS6:
  940. rate_idx = 6;
  941. break;
  942. case DESC_RATEMCS7:
  943. rate_idx = 7;
  944. break;
  945. case DESC_RATEMCS8:
  946. rate_idx = 8;
  947. break;
  948. case DESC_RATEMCS9:
  949. rate_idx = 9;
  950. break;
  951. case DESC_RATEMCS10:
  952. rate_idx = 10;
  953. break;
  954. case DESC_RATEMCS11:
  955. rate_idx = 11;
  956. break;
  957. case DESC_RATEMCS12:
  958. rate_idx = 12;
  959. break;
  960. case DESC_RATEMCS13:
  961. rate_idx = 13;
  962. break;
  963. case DESC_RATEMCS14:
  964. rate_idx = 14;
  965. break;
  966. case DESC_RATEMCS15:
  967. rate_idx = 15;
  968. break;
  969. default:
  970. rate_idx = 0;
  971. break;
  972. }
  973. }
  974. return rate_idx;
  975. }
  976. EXPORT_SYMBOL(rtlwifi_rate_mapping);
  977. void rtl_get_tcb_desc(struct ieee80211_hw *hw,
  978. struct ieee80211_tx_info *info,
  979. struct ieee80211_sta *sta,
  980. struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
  981. {
  982. struct rtl_priv *rtlpriv = rtl_priv(hw);
  983. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  984. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  985. struct ieee80211_rate *txrate;
  986. __le16 fc = rtl_get_fc(skb);
  987. txrate = ieee80211_get_tx_rate(hw, info);
  988. if (txrate)
  989. tcb_desc->hw_rate = txrate->hw_value;
  990. if (ieee80211_is_data(fc)) {
  991. /*
  992. *we set data rate INX 0
  993. *in rtl_rc.c if skb is special data or
  994. *mgt which need low data rate.
  995. */
  996. /*
  997. *So tcb_desc->hw_rate is just used for
  998. *special data and mgt frames
  999. */
  1000. if (info->control.rates[0].idx == 0 ||
  1001. ieee80211_is_nullfunc(fc)) {
  1002. tcb_desc->use_driver_rate = true;
  1003. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  1004. tcb_desc->disable_ratefallback = 1;
  1005. } else {
  1006. /*
  1007. *because hw will nerver use hw_rate
  1008. *when tcb_desc->use_driver_rate = false
  1009. *so we never set highest N rate here,
  1010. *and N rate will all be controlled by FW
  1011. *when tcb_desc->use_driver_rate = false
  1012. */
  1013. if (sta && sta->vht_cap.vht_supported) {
  1014. tcb_desc->hw_rate =
  1015. _rtl_get_vht_highest_n_rate(hw, sta);
  1016. } else {
  1017. if (sta && (sta->ht_cap.ht_supported)) {
  1018. tcb_desc->hw_rate =
  1019. _rtl_get_highest_n_rate(hw, sta);
  1020. } else {
  1021. if (rtlmac->mode == WIRELESS_MODE_B) {
  1022. tcb_desc->hw_rate =
  1023. rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
  1024. } else {
  1025. tcb_desc->hw_rate =
  1026. rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
  1027. }
  1028. }
  1029. }
  1030. }
  1031. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  1032. tcb_desc->multicast = 1;
  1033. else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
  1034. tcb_desc->broadcast = 1;
  1035. _rtl_txrate_selectmode(hw, sta, tcb_desc);
  1036. _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
  1037. _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
  1038. _rtl_query_shortgi(hw, sta, tcb_desc, info);
  1039. _rtl_query_protection_mode(hw, tcb_desc, info);
  1040. } else {
  1041. tcb_desc->use_driver_rate = true;
  1042. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  1043. tcb_desc->disable_ratefallback = 1;
  1044. tcb_desc->mac_id = 0;
  1045. tcb_desc->packet_bw = false;
  1046. }
  1047. }
  1048. EXPORT_SYMBOL(rtl_get_tcb_desc);
  1049. bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
  1050. {
  1051. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1052. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1053. __le16 fc = rtl_get_fc(skb);
  1054. if (rtlpriv->dm.supp_phymode_switch &&
  1055. mac->link_state < MAC80211_LINKED &&
  1056. (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
  1057. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  1058. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  1059. }
  1060. if (ieee80211_is_auth(fc)) {
  1061. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  1062. rtl_ips_nic_on(hw);
  1063. mac->link_state = MAC80211_LINKING;
  1064. /* Dul mac */
  1065. rtlpriv->phy.need_iqk = true;
  1066. }
  1067. return true;
  1068. }
  1069. EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
  1070. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
  1071. u8 *bssid, u16 tid);
  1072. static void process_agg_start(struct ieee80211_hw *hw,
  1073. struct ieee80211_hdr *hdr, u16 tid)
  1074. {
  1075. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1076. struct ieee80211_rx_status rx_status = { 0 };
  1077. struct sk_buff *skb_delba = NULL;
  1078. skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
  1079. if (skb_delba) {
  1080. rx_status.freq = hw->conf.chandef.chan->center_freq;
  1081. rx_status.band = hw->conf.chandef.chan->band;
  1082. rx_status.flag |= RX_FLAG_DECRYPTED;
  1083. rx_status.flag |= RX_FLAG_MACTIME_START;
  1084. rx_status.rate_idx = 0;
  1085. rx_status.signal = 50 + 10;
  1086. memcpy(IEEE80211_SKB_RXCB(skb_delba),
  1087. &rx_status, sizeof(rx_status));
  1088. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
  1089. "fake del\n",
  1090. skb_delba->data,
  1091. skb_delba->len);
  1092. ieee80211_rx_irqsafe(hw, skb_delba);
  1093. }
  1094. }
  1095. bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
  1096. {
  1097. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1098. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1099. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1100. __le16 fc = rtl_get_fc(skb);
  1101. u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
  1102. u8 category;
  1103. if (!ieee80211_is_action(fc))
  1104. return true;
  1105. category = *act;
  1106. act++;
  1107. switch (category) {
  1108. case ACT_CAT_BA:
  1109. switch (*act) {
  1110. case ACT_ADDBAREQ:
  1111. if (mac->act_scanning)
  1112. return false;
  1113. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1114. "%s ACT_ADDBAREQ From :%pM\n",
  1115. is_tx ? "Tx" : "Rx", hdr->addr2);
  1116. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
  1117. skb->data, skb->len);
  1118. if (!is_tx) {
  1119. struct ieee80211_sta *sta = NULL;
  1120. struct rtl_sta_info *sta_entry = NULL;
  1121. struct rtl_tid_data *tid_data;
  1122. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1123. u16 capab = 0, tid = 0;
  1124. rcu_read_lock();
  1125. sta = rtl_find_sta(hw, hdr->addr3);
  1126. if (sta == NULL) {
  1127. RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
  1128. DBG_DMESG, "sta is NULL\n");
  1129. rcu_read_unlock();
  1130. return true;
  1131. }
  1132. sta_entry =
  1133. (struct rtl_sta_info *)sta->drv_priv;
  1134. if (!sta_entry) {
  1135. rcu_read_unlock();
  1136. return true;
  1137. }
  1138. capab =
  1139. le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1140. tid = (capab &
  1141. IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1142. tid_data = &sta_entry->tids[tid];
  1143. if (tid_data->agg.rx_agg_state ==
  1144. RTL_RX_AGG_START)
  1145. process_agg_start(hw, hdr, tid);
  1146. rcu_read_unlock();
  1147. }
  1148. break;
  1149. case ACT_ADDBARSP:
  1150. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1151. "%s ACT_ADDBARSP From :%pM\n",
  1152. is_tx ? "Tx" : "Rx", hdr->addr2);
  1153. break;
  1154. case ACT_DELBA:
  1155. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1156. "ACT_ADDBADEL From :%pM\n", hdr->addr2);
  1157. break;
  1158. }
  1159. break;
  1160. default:
  1161. break;
  1162. }
  1163. return true;
  1164. }
  1165. EXPORT_SYMBOL_GPL(rtl_action_proc);
  1166. static void setup_arp_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc)
  1167. {
  1168. rtlpriv->ra.is_special_data = true;
  1169. if (rtlpriv->cfg->ops->get_btc_status())
  1170. rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
  1171. rtlpriv, 1);
  1172. rtlpriv->enter_ps = false;
  1173. schedule_work(&rtlpriv->works.lps_change_work);
  1174. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1175. }
  1176. /*should call before software enc*/
  1177. u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
  1178. bool is_enc)
  1179. {
  1180. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1181. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1182. __le16 fc = rtl_get_fc(skb);
  1183. u16 ether_type;
  1184. u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
  1185. u8 encrypt_header_len = 0;
  1186. u8 offset;
  1187. const struct iphdr *ip;
  1188. if (!ieee80211_is_data(fc))
  1189. goto end;
  1190. switch (rtlpriv->sec.pairwise_enc_algorithm) {
  1191. case WEP40_ENCRYPTION:
  1192. case WEP104_ENCRYPTION:
  1193. encrypt_header_len = 4;/*WEP_IV_LEN*/
  1194. break;
  1195. case TKIP_ENCRYPTION:
  1196. encrypt_header_len = 8;/*TKIP_IV_LEN*/
  1197. break;
  1198. case AESCCMP_ENCRYPTION:
  1199. encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
  1200. break;
  1201. default:
  1202. break;
  1203. }
  1204. offset = mac_hdr_len + SNAP_SIZE;
  1205. if (is_enc)
  1206. offset += encrypt_header_len;
  1207. ether_type = be16_to_cpup((__be16 *)(skb->data + offset));
  1208. if (ETH_P_IP == ether_type) {
  1209. ip = (struct iphdr *)((u8 *)skb->data + offset +
  1210. PROTOC_TYPE_SIZE);
  1211. if (IPPROTO_UDP == ip->protocol) {
  1212. struct udphdr *udp = (struct udphdr *)((u8 *)ip +
  1213. (ip->ihl << 2));
  1214. if (((((u8 *)udp)[1] == 68) &&
  1215. (((u8 *)udp)[3] == 67)) ||
  1216. ((((u8 *)udp)[1] == 67) &&
  1217. (((u8 *)udp)[3] == 68))) {
  1218. /* 68 : UDP BOOTP client
  1219. * 67 : UDP BOOTP server
  1220. */
  1221. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
  1222. DBG_DMESG, "dhcp %s !!\n",
  1223. (is_tx) ? "Tx" : "Rx");
  1224. if (is_tx)
  1225. setup_arp_tx(rtlpriv, ppsc);
  1226. return true;
  1227. }
  1228. }
  1229. } else if (ETH_P_ARP == ether_type) {
  1230. if (is_tx)
  1231. setup_arp_tx(rtlpriv, ppsc);
  1232. return true;
  1233. } else if (ETH_P_PAE == ether_type) {
  1234. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1235. "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
  1236. if (is_tx) {
  1237. rtlpriv->ra.is_special_data = true;
  1238. rtlpriv->enter_ps = false;
  1239. schedule_work(&rtlpriv->works.lps_change_work);
  1240. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1241. }
  1242. return true;
  1243. } else if (ETH_P_IPV6 == ether_type) {
  1244. /* TODO: Handle any IPv6 cases that need special handling.
  1245. * For now, always return false
  1246. */
  1247. goto end;
  1248. }
  1249. end:
  1250. rtlpriv->ra.is_special_data = false;
  1251. return false;
  1252. }
  1253. EXPORT_SYMBOL_GPL(rtl_is_special_data);
  1254. /*********************************************************
  1255. *
  1256. * functions called by core.c
  1257. *
  1258. *********************************************************/
  1259. int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1260. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  1261. {
  1262. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1263. struct rtl_tid_data *tid_data;
  1264. struct rtl_sta_info *sta_entry = NULL;
  1265. if (sta == NULL)
  1266. return -EINVAL;
  1267. if (unlikely(tid >= MAX_TID_COUNT))
  1268. return -EINVAL;
  1269. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1270. if (!sta_entry)
  1271. return -ENXIO;
  1272. tid_data = &sta_entry->tids[tid];
  1273. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1274. "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
  1275. tid_data->seq_number);
  1276. *ssn = tid_data->seq_number;
  1277. tid_data->agg.agg_state = RTL_AGG_START;
  1278. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1279. return 0;
  1280. }
  1281. int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1282. struct ieee80211_sta *sta, u16 tid)
  1283. {
  1284. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1285. struct rtl_tid_data *tid_data;
  1286. struct rtl_sta_info *sta_entry = NULL;
  1287. if (sta == NULL)
  1288. return -EINVAL;
  1289. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1290. "on ra = %pM tid = %d\n", sta->addr, tid);
  1291. if (unlikely(tid >= MAX_TID_COUNT))
  1292. return -EINVAL;
  1293. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1294. tid_data = &sta_entry->tids[tid];
  1295. sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
  1296. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1297. return 0;
  1298. }
  1299. int rtl_rx_agg_start(struct ieee80211_hw *hw,
  1300. struct ieee80211_sta *sta, u16 tid)
  1301. {
  1302. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1303. struct rtl_tid_data *tid_data;
  1304. struct rtl_sta_info *sta_entry = NULL;
  1305. if (sta == NULL)
  1306. return -EINVAL;
  1307. if (unlikely(tid >= MAX_TID_COUNT))
  1308. return -EINVAL;
  1309. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1310. if (!sta_entry)
  1311. return -ENXIO;
  1312. tid_data = &sta_entry->tids[tid];
  1313. RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
  1314. "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
  1315. tid_data->seq_number);
  1316. tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
  1317. return 0;
  1318. }
  1319. int rtl_rx_agg_stop(struct ieee80211_hw *hw,
  1320. struct ieee80211_sta *sta, u16 tid)
  1321. {
  1322. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1323. struct rtl_sta_info *sta_entry = NULL;
  1324. if (sta == NULL)
  1325. return -EINVAL;
  1326. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1327. "on ra = %pM tid = %d\n", sta->addr, tid);
  1328. if (unlikely(tid >= MAX_TID_COUNT))
  1329. return -EINVAL;
  1330. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1331. sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
  1332. return 0;
  1333. }
  1334. int rtl_tx_agg_oper(struct ieee80211_hw *hw,
  1335. struct ieee80211_sta *sta, u16 tid)
  1336. {
  1337. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1338. struct rtl_sta_info *sta_entry = NULL;
  1339. if (sta == NULL)
  1340. return -EINVAL;
  1341. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1342. "on ra = %pM tid = %d\n", sta->addr, tid);
  1343. if (unlikely(tid >= MAX_TID_COUNT))
  1344. return -EINVAL;
  1345. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1346. sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
  1347. return 0;
  1348. }
  1349. /*********************************************************
  1350. *
  1351. * wq & timer callback functions
  1352. *
  1353. *********************************************************/
  1354. /* this function is used for roaming */
  1355. void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
  1356. {
  1357. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1358. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1359. if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
  1360. return;
  1361. if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
  1362. return;
  1363. /* check if this really is a beacon */
  1364. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1365. !ieee80211_is_probe_resp(hdr->frame_control))
  1366. return;
  1367. /* min. beacon length + FCS_LEN */
  1368. if (skb->len <= 40 + FCS_LEN)
  1369. return;
  1370. /* and only beacons from the associated BSSID, please */
  1371. if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
  1372. return;
  1373. rtlpriv->link_info.bcn_rx_inperiod++;
  1374. }
  1375. EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
  1376. void rtl_watchdog_wq_callback(void *data)
  1377. {
  1378. struct rtl_works *rtlworks = container_of_dwork_rtl(data,
  1379. struct rtl_works,
  1380. watchdog_wq);
  1381. struct ieee80211_hw *hw = rtlworks->hw;
  1382. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1383. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1384. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1385. bool busytraffic = false;
  1386. bool tx_busy_traffic = false;
  1387. bool rx_busy_traffic = false;
  1388. bool higher_busytraffic = false;
  1389. bool higher_busyrxtraffic = false;
  1390. u8 idx, tid;
  1391. u32 rx_cnt_inp4eriod = 0;
  1392. u32 tx_cnt_inp4eriod = 0;
  1393. u32 aver_rx_cnt_inperiod = 0;
  1394. u32 aver_tx_cnt_inperiod = 0;
  1395. u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
  1396. u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
  1397. if (is_hal_stop(rtlhal))
  1398. return;
  1399. /* <1> Determine if action frame is allowed */
  1400. if (mac->link_state > MAC80211_NOLINK) {
  1401. if (mac->cnt_after_linked < 20)
  1402. mac->cnt_after_linked++;
  1403. } else {
  1404. mac->cnt_after_linked = 0;
  1405. }
  1406. /* <2> to check if traffic busy, if
  1407. * busytraffic we don't change channel
  1408. */
  1409. if (mac->link_state >= MAC80211_LINKED) {
  1410. /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
  1411. for (idx = 0; idx <= 2; idx++) {
  1412. rtlpriv->link_info.num_rx_in4period[idx] =
  1413. rtlpriv->link_info.num_rx_in4period[idx + 1];
  1414. rtlpriv->link_info.num_tx_in4period[idx] =
  1415. rtlpriv->link_info.num_tx_in4period[idx + 1];
  1416. }
  1417. rtlpriv->link_info.num_rx_in4period[3] =
  1418. rtlpriv->link_info.num_rx_inperiod;
  1419. rtlpriv->link_info.num_tx_in4period[3] =
  1420. rtlpriv->link_info.num_tx_inperiod;
  1421. for (idx = 0; idx <= 3; idx++) {
  1422. rx_cnt_inp4eriod +=
  1423. rtlpriv->link_info.num_rx_in4period[idx];
  1424. tx_cnt_inp4eriod +=
  1425. rtlpriv->link_info.num_tx_in4period[idx];
  1426. }
  1427. aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
  1428. aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
  1429. /* (2) check traffic busy */
  1430. if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
  1431. busytraffic = true;
  1432. if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
  1433. rx_busy_traffic = true;
  1434. else
  1435. tx_busy_traffic = false;
  1436. }
  1437. /* Higher Tx/Rx data. */
  1438. if (aver_rx_cnt_inperiod > 4000 ||
  1439. aver_tx_cnt_inperiod > 4000) {
  1440. higher_busytraffic = true;
  1441. /* Extremely high Rx data. */
  1442. if (aver_rx_cnt_inperiod > 5000)
  1443. higher_busyrxtraffic = true;
  1444. }
  1445. /* check every tid's tx traffic */
  1446. for (tid = 0; tid <= 7; tid++) {
  1447. for (idx = 0; idx <= 2; idx++)
  1448. rtlpriv->link_info.tidtx_in4period[tid][idx] =
  1449. rtlpriv->link_info.tidtx_in4period[tid]
  1450. [idx + 1];
  1451. rtlpriv->link_info.tidtx_in4period[tid][3] =
  1452. rtlpriv->link_info.tidtx_inperiod[tid];
  1453. for (idx = 0; idx <= 3; idx++)
  1454. tidtx_inp4eriod[tid] +=
  1455. rtlpriv->link_info.tidtx_in4period[tid][idx];
  1456. aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
  1457. if (aver_tidtx_inperiod[tid] > 5000)
  1458. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1459. true;
  1460. else
  1461. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1462. false;
  1463. }
  1464. if (((rtlpriv->link_info.num_rx_inperiod +
  1465. rtlpriv->link_info.num_tx_inperiod) > 8) ||
  1466. (rtlpriv->link_info.num_rx_inperiod > 2))
  1467. rtl_lps_enter(hw);
  1468. else
  1469. rtl_lps_leave(hw);
  1470. }
  1471. rtlpriv->link_info.num_rx_inperiod = 0;
  1472. rtlpriv->link_info.num_tx_inperiod = 0;
  1473. for (tid = 0; tid <= 7; tid++)
  1474. rtlpriv->link_info.tidtx_inperiod[tid] = 0;
  1475. rtlpriv->link_info.busytraffic = busytraffic;
  1476. rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
  1477. rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
  1478. rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
  1479. rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
  1480. /* <3> DM */
  1481. if (!rtlpriv->cfg->mod_params->disable_watchdog)
  1482. rtlpriv->cfg->ops->dm_watchdog(hw);
  1483. /* <4> roaming */
  1484. if (mac->link_state == MAC80211_LINKED &&
  1485. mac->opmode == NL80211_IFTYPE_STATION) {
  1486. if ((rtlpriv->link_info.bcn_rx_inperiod +
  1487. rtlpriv->link_info.num_rx_inperiod) == 0) {
  1488. rtlpriv->link_info.roam_times++;
  1489. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  1490. "AP off for %d s\n",
  1491. (rtlpriv->link_info.roam_times * 2));
  1492. /* if we can't recv beacon for 10s,
  1493. * we should reconnect this AP
  1494. */
  1495. if (rtlpriv->link_info.roam_times >= 5) {
  1496. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1497. "AP off, try to reconnect now\n");
  1498. rtlpriv->link_info.roam_times = 0;
  1499. ieee80211_connection_loss(
  1500. rtlpriv->mac80211.vif);
  1501. }
  1502. } else {
  1503. rtlpriv->link_info.roam_times = 0;
  1504. }
  1505. }
  1506. if (rtlpriv->cfg->ops->get_btc_status())
  1507. rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
  1508. rtlpriv->link_info.bcn_rx_inperiod = 0;
  1509. }
  1510. void rtl_watch_dog_timer_callback(unsigned long data)
  1511. {
  1512. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  1513. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1514. queue_delayed_work(rtlpriv->works.rtl_wq,
  1515. &rtlpriv->works.watchdog_wq, 0);
  1516. mod_timer(&rtlpriv->works.watchdog_timer,
  1517. jiffies + MSECS(RTL_WATCH_DOG_TIME));
  1518. }
  1519. void rtl_fwevt_wq_callback(void *data)
  1520. {
  1521. struct rtl_works *rtlworks =
  1522. container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
  1523. struct ieee80211_hw *hw = rtlworks->hw;
  1524. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1525. rtlpriv->cfg->ops->c2h_command_handle(hw);
  1526. }
  1527. void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
  1528. {
  1529. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  1530. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1531. struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
  1532. if (buddy_priv == NULL)
  1533. return;
  1534. rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
  1535. }
  1536. /*********************************************************
  1537. *
  1538. * frame process functions
  1539. *
  1540. *********************************************************/
  1541. u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
  1542. {
  1543. struct ieee80211_mgmt *mgmt = (void *)data;
  1544. u8 *pos, *end;
  1545. pos = (u8 *)mgmt->u.beacon.variable;
  1546. end = data + len;
  1547. while (pos < end) {
  1548. if (pos + 2 + pos[1] > end)
  1549. return NULL;
  1550. if (pos[0] == ie)
  1551. return pos;
  1552. pos += 2 + pos[1];
  1553. }
  1554. return NULL;
  1555. }
  1556. /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
  1557. /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
  1558. static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
  1559. enum ieee80211_smps_mode smps,
  1560. u8 *da, u8 *bssid)
  1561. {
  1562. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1563. struct sk_buff *skb;
  1564. struct ieee80211_mgmt *action_frame;
  1565. /* 27 = header + category + action + smps mode */
  1566. skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
  1567. if (!skb)
  1568. return NULL;
  1569. skb_reserve(skb, hw->extra_tx_headroom);
  1570. action_frame = (void *)skb_put(skb, 27);
  1571. memset(action_frame, 0, 27);
  1572. memcpy(action_frame->da, da, ETH_ALEN);
  1573. memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
  1574. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  1575. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1576. IEEE80211_STYPE_ACTION);
  1577. action_frame->u.action.category = WLAN_CATEGORY_HT;
  1578. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  1579. switch (smps) {
  1580. case IEEE80211_SMPS_AUTOMATIC:/* 0 */
  1581. case IEEE80211_SMPS_NUM_MODES:/* 4 */
  1582. WARN_ON(1);
  1583. /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
  1584. * According to Kernel Code, here is right.
  1585. */
  1586. case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
  1587. action_frame->u.action.u.ht_smps.smps_control =
  1588. WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
  1589. break;
  1590. case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
  1591. action_frame->u.action.u.ht_smps.smps_control =
  1592. WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
  1593. break;
  1594. case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
  1595. action_frame->u.action.u.ht_smps.smps_control =
  1596. WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
  1597. break;
  1598. }
  1599. return skb;
  1600. }
  1601. int rtl_send_smps_action(struct ieee80211_hw *hw,
  1602. struct ieee80211_sta *sta,
  1603. enum ieee80211_smps_mode smps)
  1604. {
  1605. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1606. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1607. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1608. struct sk_buff *skb = NULL;
  1609. struct rtl_tcb_desc tcb_desc;
  1610. u8 bssid[ETH_ALEN] = {0};
  1611. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  1612. if (rtlpriv->mac80211.act_scanning)
  1613. goto err_free;
  1614. if (!sta)
  1615. goto err_free;
  1616. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  1617. goto err_free;
  1618. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1619. goto err_free;
  1620. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
  1621. memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
  1622. else
  1623. memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
  1624. skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
  1625. /* this is a type = mgmt * stype = action frame */
  1626. if (skb) {
  1627. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1628. struct rtl_sta_info *sta_entry =
  1629. (struct rtl_sta_info *) sta->drv_priv;
  1630. sta_entry->mimo_ps = smps;
  1631. /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
  1632. info->control.rates[0].idx = 0;
  1633. info->band = hw->conf.chandef.chan->band;
  1634. rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
  1635. }
  1636. return 1;
  1637. err_free:
  1638. return 0;
  1639. }
  1640. EXPORT_SYMBOL(rtl_send_smps_action);
  1641. void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
  1642. {
  1643. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1644. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1645. enum io_type iotype;
  1646. if (!is_hal_stop(rtlhal)) {
  1647. switch (operation) {
  1648. case SCAN_OPT_BACKUP:
  1649. iotype = IO_CMD_PAUSE_DM_BY_SCAN;
  1650. rtlpriv->cfg->ops->set_hw_reg(hw,
  1651. HW_VAR_IO_CMD,
  1652. (u8 *)&iotype);
  1653. break;
  1654. case SCAN_OPT_RESTORE:
  1655. iotype = IO_CMD_RESUME_DM_BY_SCAN;
  1656. rtlpriv->cfg->ops->set_hw_reg(hw,
  1657. HW_VAR_IO_CMD,
  1658. (u8 *)&iotype);
  1659. break;
  1660. default:
  1661. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1662. "Unknown Scan Backup operation.\n");
  1663. break;
  1664. }
  1665. }
  1666. }
  1667. EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
  1668. /* because mac80211 have issues when can receive del ba
  1669. * so here we just make a fake del_ba if we receive a ba_req
  1670. * but rx_agg was opened to let mac80211 release some ba
  1671. * related resources, so please this del_ba for tx
  1672. */
  1673. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
  1674. u8 *sa, u8 *bssid, u16 tid)
  1675. {
  1676. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1677. struct sk_buff *skb;
  1678. struct ieee80211_mgmt *action_frame;
  1679. u16 params;
  1680. /* 27 = header + category + action + smps mode */
  1681. skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
  1682. if (!skb)
  1683. return NULL;
  1684. skb_reserve(skb, hw->extra_tx_headroom);
  1685. action_frame = (void *)skb_put(skb, 34);
  1686. memset(action_frame, 0, 34);
  1687. memcpy(action_frame->sa, sa, ETH_ALEN);
  1688. memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
  1689. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  1690. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1691. IEEE80211_STYPE_ACTION);
  1692. action_frame->u.action.category = WLAN_CATEGORY_BACK;
  1693. action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  1694. params = (u16)(1 << 11); /* bit 11 initiator */
  1695. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  1696. action_frame->u.action.u.delba.params = cpu_to_le16(params);
  1697. action_frame->u.action.u.delba.reason_code =
  1698. cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  1699. return skb;
  1700. }
  1701. /*********************************************************
  1702. *
  1703. * IOT functions
  1704. *
  1705. *********************************************************/
  1706. static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
  1707. struct octet_string vendor_ie)
  1708. {
  1709. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1710. bool matched = false;
  1711. static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
  1712. static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
  1713. static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
  1714. static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
  1715. static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
  1716. static u8 racap[] = { 0x00, 0x0c, 0x43 };
  1717. static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
  1718. static u8 marvcap[] = { 0x00, 0x50, 0x43 };
  1719. if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
  1720. memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
  1721. rtlpriv->mac80211.vendor = PEER_ATH;
  1722. matched = true;
  1723. } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
  1724. memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
  1725. memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
  1726. rtlpriv->mac80211.vendor = PEER_BROAD;
  1727. matched = true;
  1728. } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
  1729. rtlpriv->mac80211.vendor = PEER_RAL;
  1730. matched = true;
  1731. } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
  1732. rtlpriv->mac80211.vendor = PEER_CISCO;
  1733. matched = true;
  1734. } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
  1735. rtlpriv->mac80211.vendor = PEER_MARV;
  1736. matched = true;
  1737. }
  1738. return matched;
  1739. }
  1740. static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
  1741. unsigned int len)
  1742. {
  1743. struct ieee80211_mgmt *mgmt = (void *)data;
  1744. struct octet_string vendor_ie;
  1745. u8 *pos, *end;
  1746. pos = (u8 *)mgmt->u.beacon.variable;
  1747. end = data + len;
  1748. while (pos < end) {
  1749. if (pos[0] == 221) {
  1750. vendor_ie.length = pos[1];
  1751. vendor_ie.octet = &pos[2];
  1752. if (rtl_chk_vendor_ouisub(hw, vendor_ie))
  1753. return true;
  1754. }
  1755. if (pos + 2 + pos[1] > end)
  1756. return false;
  1757. pos += 2 + pos[1];
  1758. }
  1759. return false;
  1760. }
  1761. void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
  1762. {
  1763. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1764. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1765. struct ieee80211_hdr *hdr = (void *)data;
  1766. u32 vendor = PEER_UNKNOWN;
  1767. static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
  1768. static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
  1769. static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
  1770. static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
  1771. static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
  1772. static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
  1773. static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
  1774. static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
  1775. static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
  1776. static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
  1777. static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
  1778. static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
  1779. static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
  1780. static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
  1781. static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
  1782. static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
  1783. if (mac->opmode != NL80211_IFTYPE_STATION)
  1784. return;
  1785. if (mac->link_state == MAC80211_NOLINK) {
  1786. mac->vendor = PEER_UNKNOWN;
  1787. return;
  1788. }
  1789. if (mac->cnt_after_linked > 2)
  1790. return;
  1791. /* check if this really is a beacon */
  1792. if (!ieee80211_is_beacon(hdr->frame_control))
  1793. return;
  1794. /* min. beacon length + FCS_LEN */
  1795. if (len <= 40 + FCS_LEN)
  1796. return;
  1797. /* and only beacons from the associated BSSID, please */
  1798. if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
  1799. return;
  1800. if (rtl_find_221_ie(hw, data, len))
  1801. vendor = mac->vendor;
  1802. if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
  1803. (memcmp(mac->bssid, ap5_2, 3) == 0) ||
  1804. (memcmp(mac->bssid, ap5_3, 3) == 0) ||
  1805. (memcmp(mac->bssid, ap5_4, 3) == 0) ||
  1806. (memcmp(mac->bssid, ap5_5, 3) == 0) ||
  1807. (memcmp(mac->bssid, ap5_6, 3) == 0) ||
  1808. vendor == PEER_ATH) {
  1809. vendor = PEER_ATH;
  1810. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
  1811. } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
  1812. (memcmp(mac->bssid, ap4_5, 3) == 0) ||
  1813. (memcmp(mac->bssid, ap4_1, 3) == 0) ||
  1814. (memcmp(mac->bssid, ap4_2, 3) == 0) ||
  1815. (memcmp(mac->bssid, ap4_3, 3) == 0) ||
  1816. vendor == PEER_RAL) {
  1817. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
  1818. vendor = PEER_RAL;
  1819. } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
  1820. vendor == PEER_CISCO) {
  1821. vendor = PEER_CISCO;
  1822. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
  1823. } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
  1824. (memcmp(mac->bssid, ap3_2, 3) == 0) ||
  1825. (memcmp(mac->bssid, ap3_3, 3) == 0) ||
  1826. vendor == PEER_BROAD) {
  1827. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
  1828. vendor = PEER_BROAD;
  1829. } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
  1830. vendor == PEER_MARV) {
  1831. vendor = PEER_MARV;
  1832. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
  1833. }
  1834. mac->vendor = vendor;
  1835. }
  1836. EXPORT_SYMBOL_GPL(rtl_recognize_peer);
  1837. /*********************************************************
  1838. *
  1839. * sysfs functions
  1840. *
  1841. *********************************************************/
  1842. static ssize_t rtl_show_debug_level(struct device *d,
  1843. struct device_attribute *attr, char *buf)
  1844. {
  1845. struct ieee80211_hw *hw = dev_get_drvdata(d);
  1846. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1847. return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
  1848. }
  1849. static ssize_t rtl_store_debug_level(struct device *d,
  1850. struct device_attribute *attr,
  1851. const char *buf, size_t count)
  1852. {
  1853. struct ieee80211_hw *hw = dev_get_drvdata(d);
  1854. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1855. unsigned long val;
  1856. int ret;
  1857. ret = kstrtoul(buf, 0, &val);
  1858. if (ret) {
  1859. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  1860. "%s is not in hex or decimal form.\n", buf);
  1861. } else {
  1862. rtlpriv->dbg.global_debuglevel = val;
  1863. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  1864. "debuglevel:%x\n",
  1865. rtlpriv->dbg.global_debuglevel);
  1866. }
  1867. return strnlen(buf, count);
  1868. }
  1869. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  1870. rtl_show_debug_level, rtl_store_debug_level);
  1871. static struct attribute *rtl_sysfs_entries[] = {
  1872. &dev_attr_debug_level.attr,
  1873. NULL
  1874. };
  1875. /*
  1876. * "name" is folder name witch will be
  1877. * put in device directory like :
  1878. * sys/devices/pci0000:00/0000:00:1c.4/
  1879. * 0000:06:00.0/rtl_sysfs
  1880. */
  1881. struct attribute_group rtl_attribute_group = {
  1882. .name = "rtlsysfs",
  1883. .attrs = rtl_sysfs_entries,
  1884. };
  1885. EXPORT_SYMBOL_GPL(rtl_attribute_group);
  1886. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  1887. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  1888. MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
  1889. MODULE_LICENSE("GPL");
  1890. MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
  1891. struct rtl_global_var rtl_global_var = {};
  1892. EXPORT_SYMBOL_GPL(rtl_global_var);
  1893. static int __init rtl_core_module_init(void)
  1894. {
  1895. if (rtl_rate_control_register())
  1896. pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
  1897. /* init some global vars */
  1898. INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
  1899. spin_lock_init(&rtl_global_var.glb_list_lock);
  1900. return 0;
  1901. }
  1902. static void __exit rtl_core_module_exit(void)
  1903. {
  1904. /*RC*/
  1905. rtl_rate_control_unregister();
  1906. }
  1907. module_init(rtl_core_module_init);
  1908. module_exit(rtl_core_module_exit);