base.c 60 KB

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