base.c 59 KB

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