rtw_ieee80211.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _IEEE80211_C
  21. #ifdef CONFIG_PLATFORM_INTEL_BYT
  22. #include <linux/fs.h>
  23. #endif
  24. #include <drv_types.h>
  25. u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
  26. u16 RTW_WPA_VERSION = 1;
  27. u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };
  28. u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };
  29. u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };
  30. u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };
  31. u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };
  32. u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };
  33. u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };
  34. u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };
  35. u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };
  36. u16 RSN_VERSION_BSD = 1;
  37. u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 };
  38. u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 };
  39. u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };
  40. u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };
  41. u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };
  42. u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };
  43. u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };
  44. u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };
  45. /* -----------------------------------------------------------
  46. * for adhoc-master to generate ie and provide supported-rate to fw
  47. * ----------------------------------------------------------- */
  48. static u8 WIFI_CCKRATES[] = {
  49. (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
  50. (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
  51. (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
  52. (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)
  53. };
  54. static u8 WIFI_OFDMRATES[] = {
  55. (IEEE80211_OFDM_RATE_6MB),
  56. (IEEE80211_OFDM_RATE_9MB),
  57. (IEEE80211_OFDM_RATE_12MB),
  58. (IEEE80211_OFDM_RATE_18MB),
  59. (IEEE80211_OFDM_RATE_24MB),
  60. IEEE80211_OFDM_RATE_36MB,
  61. IEEE80211_OFDM_RATE_48MB,
  62. IEEE80211_OFDM_RATE_54MB
  63. };
  64. u8 mgn_rates_cck[4] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M};
  65. u8 mgn_rates_ofdm[8] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
  66. u8 mgn_rates_mcs0_7[8] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7};
  67. u8 mgn_rates_mcs8_15[8] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15};
  68. u8 mgn_rates_mcs16_23[8] = {MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23};
  69. u8 mgn_rates_mcs24_31[8] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31};
  70. u8 mgn_rates_vht1ss[10] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4
  71. , MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9
  72. };
  73. u8 mgn_rates_vht2ss[10] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4
  74. , MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9
  75. };
  76. u8 mgn_rates_vht3ss[10] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4
  77. , MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9
  78. };
  79. u8 mgn_rates_vht4ss[10] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS4
  80. , MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS9
  81. };
  82. static const char *const _rate_section_str[] = {
  83. "CCK",
  84. "OFDM",
  85. "HT_1SS",
  86. "HT_2SS",
  87. "HT_3SS",
  88. "HT_4SS",
  89. "VHT_1SS",
  90. "VHT_2SS",
  91. "VHT_3SS",
  92. "VHT_4SS",
  93. "RATE_SECTION_UNKNOWN",
  94. };
  95. const char *rate_section_str(u8 section)
  96. {
  97. section = (section >= RATE_SECTION_NUM) ? RATE_SECTION_NUM : section;
  98. return _rate_section_str[section];
  99. }
  100. struct rate_section_ent rates_by_sections[RATE_SECTION_NUM] = {
  101. {RF_1TX, 4, mgn_rates_cck},
  102. {RF_1TX, 8, mgn_rates_ofdm},
  103. {RF_1TX, 8, mgn_rates_mcs0_7},
  104. {RF_2TX, 8, mgn_rates_mcs8_15},
  105. {RF_3TX, 8, mgn_rates_mcs16_23},
  106. {RF_4TX, 8, mgn_rates_mcs24_31},
  107. {RF_1TX, 10, mgn_rates_vht1ss},
  108. {RF_2TX, 10, mgn_rates_vht2ss},
  109. {RF_3TX, 10, mgn_rates_vht3ss},
  110. {RF_4TX, 10, mgn_rates_vht4ss},
  111. };
  112. int rtw_get_bit_value_from_ieee_value(u8 val)
  113. {
  114. unsigned char dot11_rate_table[] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0}; /* last element must be zero!! */
  115. int i = 0;
  116. while (dot11_rate_table[i] != 0) {
  117. if (dot11_rate_table[i] == val)
  118. return BIT(i);
  119. i++;
  120. }
  121. return 0;
  122. }
  123. uint rtw_is_cckrates_included(u8 *rate)
  124. {
  125. u32 i = 0;
  126. while (rate[i] != 0) {
  127. if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
  128. (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
  129. return _TRUE;
  130. i++;
  131. }
  132. return _FALSE;
  133. }
  134. uint rtw_is_cckratesonly_included(u8 *rate)
  135. {
  136. u32 i = 0;
  137. while (rate[i] != 0) {
  138. if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
  139. (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
  140. return _FALSE;
  141. i++;
  142. }
  143. return _TRUE;
  144. }
  145. int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
  146. {
  147. if (channel > 14) {
  148. if ((rtw_is_cckrates_included(rate)) == _TRUE)
  149. return WIRELESS_INVALID;
  150. else
  151. return WIRELESS_11A;
  152. } else { /* could be pure B, pure G, or B/G */
  153. if ((rtw_is_cckratesonly_included(rate)) == _TRUE)
  154. return WIRELESS_11B;
  155. else if ((rtw_is_cckrates_included(rate)) == _TRUE)
  156. return WIRELESS_11BG;
  157. else
  158. return WIRELESS_11G;
  159. }
  160. }
  161. u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
  162. unsigned int *frlen)
  163. {
  164. _rtw_memcpy((void *)pbuf, (void *)source, len);
  165. *frlen = *frlen + len;
  166. return pbuf + len;
  167. }
  168. /* rtw_set_ie will update frame length */
  169. u8 *rtw_set_ie
  170. (
  171. u8 *pbuf,
  172. sint index,
  173. uint len,
  174. u8 *source,
  175. uint *frlen /* frame length */
  176. )
  177. {
  178. *pbuf = (u8)index;
  179. *(pbuf + 1) = (u8)len;
  180. if (len > 0)
  181. _rtw_memcpy((void *)(pbuf + 2), (void *)source, len);
  182. *frlen = *frlen + (len + 2);
  183. return pbuf + len + 2;
  184. }
  185. inline u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode,
  186. u8 new_ch, u8 ch_switch_cnt)
  187. {
  188. u8 ie_data[3];
  189. ie_data[0] = ch_switch_mode;
  190. ie_data[1] = new_ch;
  191. ie_data[2] = ch_switch_cnt;
  192. return rtw_set_ie(buf, WLAN_EID_CHANNEL_SWITCH, 3, ie_data, buf_len);
  193. }
  194. inline u8 secondary_ch_offset_to_hal_ch_offset(u8 ch_offset)
  195. {
  196. if (ch_offset == SCN)
  197. return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  198. else if (ch_offset == SCA)
  199. return HAL_PRIME_CHNL_OFFSET_UPPER;
  200. else if (ch_offset == SCB)
  201. return HAL_PRIME_CHNL_OFFSET_LOWER;
  202. return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  203. }
  204. inline u8 hal_ch_offset_to_secondary_ch_offset(u8 ch_offset)
  205. {
  206. if (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
  207. return SCN;
  208. else if (ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
  209. return SCB;
  210. else if (ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
  211. return SCA;
  212. return SCN;
  213. }
  214. inline u8 *rtw_set_ie_secondary_ch_offset(u8 *buf, u32 *buf_len, u8 secondary_ch_offset)
  215. {
  216. return rtw_set_ie(buf, WLAN_EID_SECONDARY_CHANNEL_OFFSET, 1, &secondary_ch_offset, buf_len);
  217. }
  218. inline u8 *rtw_set_ie_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl,
  219. u8 flags, u16 reason, u16 precedence)
  220. {
  221. u8 ie_data[6];
  222. ie_data[0] = ttl;
  223. ie_data[1] = flags;
  224. RTW_PUT_LE16((u8 *)&ie_data[2], reason);
  225. RTW_PUT_LE16((u8 *)&ie_data[4], precedence);
  226. return rtw_set_ie(buf, 0x118, 6, ie_data, buf_len);
  227. }
  228. /*----------------------------------------------------------------------------
  229. index: the information element id index, limit is the limit for search
  230. -----------------------------------------------------------------------------*/
  231. u8 *rtw_get_ie(u8 *pbuf, sint index, sint *len, sint limit)
  232. {
  233. sint tmp, i;
  234. u8 *p;
  235. if (limit < 1) {
  236. return NULL;
  237. }
  238. p = pbuf;
  239. i = 0;
  240. *len = 0;
  241. while (1) {
  242. if (*p == index) {
  243. *len = *(p + 1);
  244. return p;
  245. } else {
  246. tmp = *(p + 1);
  247. p += (tmp + 2);
  248. i += (tmp + 2);
  249. }
  250. if (i >= limit)
  251. break;
  252. }
  253. return NULL;
  254. }
  255. /**
  256. * rtw_get_ie_ex - Search specific IE from a series of IEs
  257. * @in_ie: Address of IEs to search
  258. * @in_len: Length limit from in_ie
  259. * @eid: Element ID to match
  260. * @oui: OUI to match
  261. * @oui_len: OUI length
  262. * @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE
  263. * @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE
  264. *
  265. * Returns: The address of the specific IE found, or NULL
  266. */
  267. u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen)
  268. {
  269. uint cnt;
  270. u8 *target_ie = NULL;
  271. if (ielen)
  272. *ielen = 0;
  273. if (!in_ie || in_len <= 0)
  274. return target_ie;
  275. cnt = 0;
  276. while (cnt < in_len) {
  277. if (eid == in_ie[cnt]
  278. && (!oui || _rtw_memcmp(&in_ie[cnt + 2], oui, oui_len) == _TRUE)) {
  279. target_ie = &in_ie[cnt];
  280. if (ie)
  281. _rtw_memcpy(ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  282. if (ielen)
  283. *ielen = in_ie[cnt + 1] + 2;
  284. break;
  285. } else {
  286. cnt += in_ie[cnt + 1] + 2; /* goto next */
  287. }
  288. }
  289. return target_ie;
  290. }
  291. /**
  292. * rtw_ies_remove_ie - Find matching IEs and remove
  293. * @ies: Address of IEs to search
  294. * @ies_len: Pointer of length of ies, will update to new length
  295. * @offset: The offset to start scarch
  296. * @eid: Element ID to match
  297. * @oui: OUI to match
  298. * @oui_len: OUI length
  299. *
  300. * Returns: _SUCCESS: ies is updated, _FAIL: not updated
  301. */
  302. int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len)
  303. {
  304. int ret = _FAIL;
  305. u8 *target_ie;
  306. u32 target_ielen;
  307. u8 *start;
  308. uint search_len;
  309. if (!ies || !ies_len || *ies_len <= offset)
  310. goto exit;
  311. start = ies + offset;
  312. search_len = *ies_len - offset;
  313. while (1) {
  314. target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen);
  315. if (target_ie && target_ielen) {
  316. u8 *remain_ies = target_ie + target_ielen;
  317. uint remain_len = search_len - (remain_ies - start);
  318. _rtw_memmove(target_ie, remain_ies, remain_len);
  319. *ies_len = *ies_len - target_ielen;
  320. ret = _SUCCESS;
  321. start = target_ie;
  322. search_len = remain_len;
  323. } else
  324. break;
  325. }
  326. exit:
  327. return ret;
  328. }
  329. void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
  330. {
  331. _rtw_memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
  332. switch (mode) {
  333. case WIRELESS_11B:
  334. _rtw_memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
  335. break;
  336. case WIRELESS_11G:
  337. case WIRELESS_11A:
  338. case WIRELESS_11_5N:
  339. case WIRELESS_11A_5N: /* Todo: no basic rate for ofdm ? */
  340. case WIRELESS_11_5AC:
  341. _rtw_memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
  342. break;
  343. case WIRELESS_11BG:
  344. case WIRELESS_11G_24N:
  345. case WIRELESS_11_24N:
  346. case WIRELESS_11BG_24N:
  347. _rtw_memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
  348. _rtw_memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
  349. break;
  350. }
  351. }
  352. uint rtw_get_rateset_len(u8 *rateset)
  353. {
  354. uint i = 0;
  355. while (1) {
  356. if ((rateset[i]) == 0)
  357. break;
  358. if (i > 12)
  359. break;
  360. i++;
  361. }
  362. return i;
  363. }
  364. int rtw_generate_ie(struct registry_priv *pregistrypriv)
  365. {
  366. u8 wireless_mode;
  367. int sz = 0, rateLen;
  368. WLAN_BSSID_EX *pdev_network = &pregistrypriv->dev_network;
  369. u8 *ie = pdev_network->IEs;
  370. /* timestamp will be inserted by hardware */
  371. sz += 8;
  372. ie += sz;
  373. /* beacon interval : 2bytes */
  374. *(u16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod); /* BCN_INTERVAL; */
  375. sz += 2;
  376. ie += 2;
  377. /* capability info */
  378. *(u16 *)ie = 0;
  379. *(u16 *)ie |= cpu_to_le16(cap_IBSS);
  380. if (pregistrypriv->preamble == PREAMBLE_SHORT)
  381. *(u16 *)ie |= cpu_to_le16(cap_ShortPremble);
  382. if (pdev_network->Privacy)
  383. *(u16 *)ie |= cpu_to_le16(cap_Privacy);
  384. sz += 2;
  385. ie += 2;
  386. /* SSID */
  387. ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);
  388. /* supported rates */
  389. if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) {
  390. if (pdev_network->Configuration.DSConfig > 14)
  391. wireless_mode = WIRELESS_11A_5N;
  392. else
  393. wireless_mode = WIRELESS_11BG_24N;
  394. } else if (pregistrypriv->wireless_mode == WIRELESS_MODE_MAX) { /* WIRELESS_11ABGN | WIRELESS_11AC */
  395. if (pdev_network->Configuration.DSConfig > 14)
  396. wireless_mode = WIRELESS_11_5AC;
  397. else
  398. wireless_mode = WIRELESS_11BG_24N;
  399. } else
  400. wireless_mode = pregistrypriv->wireless_mode;
  401. rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode) ;
  402. rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
  403. if (rateLen > 8) {
  404. ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
  405. /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
  406. } else
  407. ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
  408. /* DS parameter set */
  409. ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&(pdev_network->Configuration.DSConfig), &sz);
  410. /* IBSS Parameter Set */
  411. ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz);
  412. if (rateLen > 8)
  413. ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
  414. #ifdef CONFIG_80211N_HT
  415. /* HT Cap. */
  416. if (((pregistrypriv->wireless_mode & WIRELESS_11_5N) || (pregistrypriv->wireless_mode & WIRELESS_11_24N))
  417. && (pregistrypriv->ht_enable == _TRUE)) {
  418. /* todo: */
  419. }
  420. #endif /* CONFIG_80211N_HT */
  421. /* pdev_network->IELength = sz; */ /* update IELength */
  422. /* return _SUCCESS; */
  423. return sz;
  424. }
  425. unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
  426. {
  427. int len;
  428. u16 val16;
  429. unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
  430. u8 *pbuf = pie;
  431. int limit_new = limit;
  432. while (1) {
  433. pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
  434. if (pbuf) {
  435. /* check if oui matches... */
  436. if (_rtw_memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)) == _FALSE)
  437. goto check_next_ie;
  438. /* check version... */
  439. _rtw_memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16));
  440. val16 = le16_to_cpu(val16);
  441. if (val16 != 0x0001)
  442. goto check_next_ie;
  443. *wpa_ie_len = *(pbuf + 1);
  444. return pbuf;
  445. } else {
  446. *wpa_ie_len = 0;
  447. return NULL;
  448. }
  449. check_next_ie:
  450. limit_new = limit - (pbuf - pie) - 2 - len;
  451. if (limit_new <= 0)
  452. break;
  453. pbuf += (2 + len);
  454. }
  455. *wpa_ie_len = 0;
  456. return NULL;
  457. }
  458. unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
  459. {
  460. return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
  461. }
  462. int rtw_get_wpa_cipher_suite(u8 *s)
  463. {
  464. if (_rtw_memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN) == _TRUE)
  465. return WPA_CIPHER_NONE;
  466. if (_rtw_memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN) == _TRUE)
  467. return WPA_CIPHER_WEP40;
  468. if (_rtw_memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN) == _TRUE)
  469. return WPA_CIPHER_TKIP;
  470. if (_rtw_memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN) == _TRUE)
  471. return WPA_CIPHER_CCMP;
  472. if (_rtw_memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN) == _TRUE)
  473. return WPA_CIPHER_WEP104;
  474. return 0;
  475. }
  476. int rtw_get_wpa2_cipher_suite(u8 *s)
  477. {
  478. if (_rtw_memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN) == _TRUE)
  479. return WPA_CIPHER_NONE;
  480. if (_rtw_memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN) == _TRUE)
  481. return WPA_CIPHER_WEP40;
  482. if (_rtw_memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN) == _TRUE)
  483. return WPA_CIPHER_TKIP;
  484. if (_rtw_memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN) == _TRUE)
  485. return WPA_CIPHER_CCMP;
  486. if (_rtw_memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN) == _TRUE)
  487. return WPA_CIPHER_WEP104;
  488. return 0;
  489. }
  490. int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
  491. {
  492. int i, ret = _SUCCESS;
  493. int left, count;
  494. u8 *pos;
  495. u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
  496. if (wpa_ie_len <= 0) {
  497. /* No WPA IE - fail silently */
  498. return _FAIL;
  499. }
  500. if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
  501. (_rtw_memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN) != _TRUE))
  502. return _FAIL;
  503. pos = wpa_ie;
  504. pos += 8;
  505. left = wpa_ie_len - 8;
  506. /* group_cipher */
  507. if (left >= WPA_SELECTOR_LEN) {
  508. *group_cipher = rtw_get_wpa_cipher_suite(pos);
  509. pos += WPA_SELECTOR_LEN;
  510. left -= WPA_SELECTOR_LEN;
  511. } else if (left > 0) {
  512. return _FAIL;
  513. }
  514. /* pairwise_cipher */
  515. if (left >= 2) {
  516. /* count = le16_to_cpu(*(u16*)pos); */
  517. count = RTW_GET_LE16(pos);
  518. pos += 2;
  519. left -= 2;
  520. if (count == 0 || left < count * WPA_SELECTOR_LEN) {
  521. return _FAIL;
  522. }
  523. for (i = 0; i < count; i++) {
  524. *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
  525. pos += WPA_SELECTOR_LEN;
  526. left -= WPA_SELECTOR_LEN;
  527. }
  528. } else if (left == 1) {
  529. return _FAIL;
  530. }
  531. if (is_8021x) {
  532. if (left >= 6) {
  533. pos += 2;
  534. if (_rtw_memcmp(pos, SUITE_1X, 4) == 1) {
  535. *is_8021x = 1;
  536. }
  537. }
  538. }
  539. return ret;
  540. }
  541. int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
  542. {
  543. int i, ret = _SUCCESS;
  544. int left, count;
  545. u8 *pos;
  546. u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
  547. if (rsn_ie_len <= 0) {
  548. /* No RSN IE - fail silently */
  549. return _FAIL;
  550. }
  551. if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
  552. return _FAIL;
  553. pos = rsn_ie;
  554. pos += 4;
  555. left = rsn_ie_len - 4;
  556. /* group_cipher */
  557. if (left >= RSN_SELECTOR_LEN) {
  558. *group_cipher = rtw_get_wpa2_cipher_suite(pos);
  559. pos += RSN_SELECTOR_LEN;
  560. left -= RSN_SELECTOR_LEN;
  561. } else if (left > 0) {
  562. return _FAIL;
  563. }
  564. /* pairwise_cipher */
  565. if (left >= 2) {
  566. /* count = le16_to_cpu(*(u16*)pos); */
  567. count = RTW_GET_LE16(pos);
  568. pos += 2;
  569. left -= 2;
  570. if (count == 0 || left < count * RSN_SELECTOR_LEN) {
  571. return _FAIL;
  572. }
  573. for (i = 0; i < count; i++) {
  574. *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
  575. pos += RSN_SELECTOR_LEN;
  576. left -= RSN_SELECTOR_LEN;
  577. }
  578. } else if (left == 1) {
  579. return _FAIL;
  580. }
  581. if (is_8021x) {
  582. if (left >= 6) {
  583. pos += 2;
  584. if (_rtw_memcmp(pos, SUITE_1X, 4) == 1) {
  585. *is_8021x = 1;
  586. }
  587. }
  588. }
  589. return ret;
  590. }
  591. /* #ifdef CONFIG_WAPI_SUPPORT */
  592. int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)
  593. {
  594. int len = 0;
  595. u8 authmode, i;
  596. uint cnt;
  597. u8 wapi_oui1[4] = {0x0, 0x14, 0x72, 0x01};
  598. u8 wapi_oui2[4] = {0x0, 0x14, 0x72, 0x02};
  599. if (wapi_len)
  600. *wapi_len = 0;
  601. if (!in_ie || in_len <= 0)
  602. return len;
  603. cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
  604. while (cnt < in_len) {
  605. authmode = in_ie[cnt];
  606. /* if(authmode==_WAPI_IE_) */
  607. if (authmode == _WAPI_IE_ && (_rtw_memcmp(&in_ie[cnt + 6], wapi_oui1, 4) == _TRUE ||
  608. _rtw_memcmp(&in_ie[cnt + 6], wapi_oui2, 4) == _TRUE)) {
  609. if (wapi_ie)
  610. _rtw_memcpy(wapi_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  611. if (wapi_len)
  612. *wapi_len = in_ie[cnt + 1] + 2;
  613. cnt += in_ie[cnt + 1] + 2; /* get next */
  614. } else {
  615. cnt += in_ie[cnt + 1] + 2; /* get next */
  616. }
  617. }
  618. if (wapi_len)
  619. len = *wapi_len;
  620. return len;
  621. }
  622. /* #endif */
  623. int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
  624. {
  625. u8 authmode, sec_idx, i;
  626. u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
  627. uint cnt;
  628. /* Search required WPA or WPA2 IE and copy to sec_ie[ ] */
  629. cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
  630. sec_idx = 0;
  631. while (cnt < in_len) {
  632. authmode = in_ie[cnt];
  633. if ((authmode == _WPA_IE_ID_) && (_rtw_memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4) == _TRUE)) {
  634. if (wpa_ie)
  635. _rtw_memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  636. *wpa_len = in_ie[cnt + 1] + 2;
  637. cnt += in_ie[cnt + 1] + 2; /* get next */
  638. } else {
  639. if (authmode == _WPA2_IE_ID_) {
  640. if (rsn_ie)
  641. _rtw_memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  642. *rsn_len = in_ie[cnt + 1] + 2;
  643. cnt += in_ie[cnt + 1] + 2; /* get next */
  644. } else {
  645. cnt += in_ie[cnt + 1] + 2; /* get next */
  646. }
  647. }
  648. }
  649. return *rsn_len + *wpa_len;
  650. }
  651. u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
  652. {
  653. u8 match = _FALSE;
  654. u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
  655. if (ie_ptr == NULL)
  656. return match;
  657. eid = ie_ptr[0];
  658. if ((eid == _WPA_IE_ID_) && (_rtw_memcmp(&ie_ptr[2], wps_oui, 4) == _TRUE)) {
  659. /* RTW_INFO("==> found WPS_IE.....\n"); */
  660. *wps_ielen = ie_ptr[1] + 2;
  661. match = _TRUE;
  662. }
  663. return match;
  664. }
  665. u8 *rtw_get_wps_ie_from_scan_queue(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen, u8 frame_type)
  666. {
  667. u8 *wps = NULL;
  668. RTW_INFO("[%s] frame_type = %d\n", __FUNCTION__, frame_type);
  669. switch (frame_type) {
  670. case 1:
  671. case 3: {
  672. /* Beacon or Probe Response */
  673. wps = rtw_get_wps_ie(in_ie + _PROBERSP_IE_OFFSET_, in_len - _PROBERSP_IE_OFFSET_, wps_ie, wps_ielen);
  674. break;
  675. }
  676. case 2: {
  677. /* Probe Request */
  678. wps = rtw_get_wps_ie(in_ie + _PROBEREQ_IE_OFFSET_ , in_len - _PROBEREQ_IE_OFFSET_ , wps_ie, wps_ielen);
  679. break;
  680. }
  681. }
  682. return wps;
  683. }
  684. /**
  685. * rtw_get_wps_ie - Search WPS IE from a series of IEs
  686. * @in_ie: Address of IEs to search
  687. * @in_len: Length limit from in_ie
  688. * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
  689. * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
  690. *
  691. * Returns: The address of the WPS IE found, or NULL
  692. */
  693. u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
  694. {
  695. uint cnt;
  696. u8 *wpsie_ptr = NULL;
  697. u8 eid, wps_oui[4] = {0x00, 0x50, 0xf2, 0x04};
  698. if (wps_ielen)
  699. *wps_ielen = 0;
  700. if (!in_ie) {
  701. rtw_warn_on(1);
  702. return wpsie_ptr;
  703. }
  704. if (in_len <= 0)
  705. return wpsie_ptr;
  706. cnt = 0;
  707. while (cnt + 1 + 4 < in_len) {
  708. eid = in_ie[cnt];
  709. if (cnt + 1 + 4 >= MAX_IE_SZ) {
  710. rtw_warn_on(1);
  711. return NULL;
  712. }
  713. if (eid == WLAN_EID_VENDOR_SPECIFIC && _rtw_memcmp(&in_ie[cnt + 2], wps_oui, 4) == _TRUE) {
  714. wpsie_ptr = in_ie + cnt;
  715. if (wps_ie)
  716. _rtw_memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  717. if (wps_ielen)
  718. *wps_ielen = in_ie[cnt + 1] + 2;
  719. break;
  720. } else
  721. cnt += in_ie[cnt + 1] + 2;
  722. }
  723. return wpsie_ptr;
  724. }
  725. /**
  726. * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
  727. * @wps_ie: Address of WPS IE to search
  728. * @wps_ielen: Length limit from wps_ie
  729. * @target_attr_id: The attribute ID of WPS attribute to search
  730. * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
  731. * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
  732. *
  733. * Returns: the address of the specific WPS attribute found, or NULL
  734. */
  735. u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_attr, u32 *len_attr)
  736. {
  737. u8 *attr_ptr = NULL;
  738. u8 *target_attr_ptr = NULL;
  739. u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
  740. if (len_attr)
  741. *len_attr = 0;
  742. if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
  743. (_rtw_memcmp(wps_ie + 2, wps_oui , 4) != _TRUE))
  744. return attr_ptr;
  745. /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
  746. attr_ptr = wps_ie + 6; /* goto first attr */
  747. while (attr_ptr - wps_ie < wps_ielen) {
  748. /* 4 = 2(Attribute ID) + 2(Length) */
  749. u16 attr_id = RTW_GET_BE16(attr_ptr);
  750. u16 attr_data_len = RTW_GET_BE16(attr_ptr + 2);
  751. u16 attr_len = attr_data_len + 4;
  752. /* RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __FUNCTION__, attr_ptr, attr_id, attr_data_len); */
  753. if (attr_id == target_attr_id) {
  754. target_attr_ptr = attr_ptr;
  755. if (buf_attr)
  756. _rtw_memcpy(buf_attr, attr_ptr, attr_len);
  757. if (len_attr)
  758. *len_attr = attr_len;
  759. break;
  760. } else {
  761. attr_ptr += attr_len; /* goto next */
  762. }
  763. }
  764. return target_attr_ptr;
  765. }
  766. /**
  767. * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
  768. * @wps_ie: Address of WPS IE to search
  769. * @wps_ielen: Length limit from wps_ie
  770. * @target_attr_id: The attribute ID of WPS attribute to search
  771. * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
  772. * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
  773. *
  774. * Returns: the address of the specific WPS attribute content found, or NULL
  775. */
  776. u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_content, uint *len_content)
  777. {
  778. u8 *attr_ptr;
  779. u32 attr_len;
  780. if (len_content)
  781. *len_content = 0;
  782. attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
  783. if (attr_ptr && attr_len) {
  784. if (buf_content)
  785. _rtw_memcpy(buf_content, attr_ptr + 4, attr_len - 4);
  786. if (len_content)
  787. *len_content = attr_len - 4;
  788. return attr_ptr + 4;
  789. }
  790. return NULL;
  791. }
  792. static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
  793. struct rtw_ieee802_11_elems *elems,
  794. int show_errors)
  795. {
  796. unsigned int oui;
  797. /* first 3 bytes in vendor specific information element are the IEEE
  798. * OUI of the vendor. The following byte is used a vendor specific
  799. * sub-type. */
  800. if (elen < 4) {
  801. if (show_errors) {
  802. RTW_INFO("short vendor specific "
  803. "information element ignored (len=%lu)\n",
  804. (unsigned long) elen);
  805. }
  806. return -1;
  807. }
  808. oui = RTW_GET_BE24(pos);
  809. switch (oui) {
  810. case OUI_MICROSOFT:
  811. /* Microsoft/Wi-Fi information elements are further typed and
  812. * subtyped */
  813. switch (pos[3]) {
  814. case 1:
  815. /* Microsoft OUI (00:50:F2) with OUI Type 1:
  816. * real WPA information element */
  817. elems->wpa_ie = pos;
  818. elems->wpa_ie_len = elen;
  819. break;
  820. case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
  821. if (elen < 5) {
  822. RTW_DBG("short WME "
  823. "information element ignored "
  824. "(len=%lu)\n",
  825. (unsigned long) elen);
  826. return -1;
  827. }
  828. switch (pos[4]) {
  829. case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
  830. case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
  831. elems->wme = pos;
  832. elems->wme_len = elen;
  833. break;
  834. case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
  835. elems->wme_tspec = pos;
  836. elems->wme_tspec_len = elen;
  837. break;
  838. default:
  839. RTW_DBG("unknown WME "
  840. "information element ignored "
  841. "(subtype=%d len=%lu)\n",
  842. pos[4], (unsigned long) elen);
  843. return -1;
  844. }
  845. break;
  846. case 4:
  847. /* Wi-Fi Protected Setup (WPS) IE */
  848. elems->wps_ie = pos;
  849. elems->wps_ie_len = elen;
  850. break;
  851. default:
  852. RTW_DBG("Unknown Microsoft "
  853. "information element ignored "
  854. "(type=%d len=%lu)\n",
  855. pos[3], (unsigned long) elen);
  856. return -1;
  857. }
  858. break;
  859. case OUI_BROADCOM:
  860. switch (pos[3]) {
  861. case VENDOR_HT_CAPAB_OUI_TYPE:
  862. elems->vendor_ht_cap = pos;
  863. elems->vendor_ht_cap_len = elen;
  864. break;
  865. default:
  866. RTW_DBG("Unknown Broadcom "
  867. "information element ignored "
  868. "(type=%d len=%lu)\n",
  869. pos[3], (unsigned long) elen);
  870. return -1;
  871. }
  872. break;
  873. default:
  874. RTW_DBG("unknown vendor specific information "
  875. "element ignored (vendor OUI %02x:%02x:%02x "
  876. "len=%lu)\n",
  877. pos[0], pos[1], pos[2], (unsigned long) elen);
  878. return -1;
  879. }
  880. return 0;
  881. }
  882. /**
  883. * ieee802_11_parse_elems - Parse information elements in management frames
  884. * @start: Pointer to the start of IEs
  885. * @len: Length of IE buffer in octets
  886. * @elems: Data structure for parsed elements
  887. * @show_errors: Whether to show parsing errors in debug log
  888. * Returns: Parsing result
  889. */
  890. ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,
  891. struct rtw_ieee802_11_elems *elems,
  892. int show_errors)
  893. {
  894. uint left = len;
  895. u8 *pos = start;
  896. int unknown = 0;
  897. _rtw_memset(elems, 0, sizeof(*elems));
  898. while (left >= 2) {
  899. u8 id, elen;
  900. id = *pos++;
  901. elen = *pos++;
  902. left -= 2;
  903. if (elen > left) {
  904. if (show_errors) {
  905. RTW_INFO("IEEE 802.11 element "
  906. "parse failed (id=%d elen=%d "
  907. "left=%lu)\n",
  908. id, elen, (unsigned long) left);
  909. }
  910. return ParseFailed;
  911. }
  912. switch (id) {
  913. case WLAN_EID_SSID:
  914. elems->ssid = pos;
  915. elems->ssid_len = elen;
  916. break;
  917. case WLAN_EID_SUPP_RATES:
  918. elems->supp_rates = pos;
  919. elems->supp_rates_len = elen;
  920. break;
  921. case WLAN_EID_FH_PARAMS:
  922. elems->fh_params = pos;
  923. elems->fh_params_len = elen;
  924. break;
  925. case WLAN_EID_DS_PARAMS:
  926. elems->ds_params = pos;
  927. elems->ds_params_len = elen;
  928. break;
  929. case WLAN_EID_CF_PARAMS:
  930. elems->cf_params = pos;
  931. elems->cf_params_len = elen;
  932. break;
  933. case WLAN_EID_TIM:
  934. elems->tim = pos;
  935. elems->tim_len = elen;
  936. break;
  937. case WLAN_EID_IBSS_PARAMS:
  938. elems->ibss_params = pos;
  939. elems->ibss_params_len = elen;
  940. break;
  941. case WLAN_EID_CHALLENGE:
  942. elems->challenge = pos;
  943. elems->challenge_len = elen;
  944. break;
  945. case WLAN_EID_ERP_INFO:
  946. elems->erp_info = pos;
  947. elems->erp_info_len = elen;
  948. break;
  949. case WLAN_EID_EXT_SUPP_RATES:
  950. elems->ext_supp_rates = pos;
  951. elems->ext_supp_rates_len = elen;
  952. break;
  953. case WLAN_EID_VENDOR_SPECIFIC:
  954. if (rtw_ieee802_11_parse_vendor_specific(pos, elen,
  955. elems,
  956. show_errors))
  957. unknown++;
  958. break;
  959. case WLAN_EID_RSN:
  960. elems->rsn_ie = pos;
  961. elems->rsn_ie_len = elen;
  962. break;
  963. case WLAN_EID_PWR_CAPABILITY:
  964. elems->power_cap = pos;
  965. elems->power_cap_len = elen;
  966. break;
  967. case WLAN_EID_SUPPORTED_CHANNELS:
  968. elems->supp_channels = pos;
  969. elems->supp_channels_len = elen;
  970. break;
  971. case WLAN_EID_MOBILITY_DOMAIN:
  972. elems->mdie = pos;
  973. elems->mdie_len = elen;
  974. break;
  975. case WLAN_EID_FAST_BSS_TRANSITION:
  976. elems->ftie = pos;
  977. elems->ftie_len = elen;
  978. break;
  979. case WLAN_EID_TIMEOUT_INTERVAL:
  980. elems->timeout_int = pos;
  981. elems->timeout_int_len = elen;
  982. break;
  983. case WLAN_EID_HT_CAP:
  984. elems->ht_capabilities = pos;
  985. elems->ht_capabilities_len = elen;
  986. break;
  987. case WLAN_EID_HT_OPERATION:
  988. elems->ht_operation = pos;
  989. elems->ht_operation_len = elen;
  990. break;
  991. case WLAN_EID_VHT_CAPABILITY:
  992. elems->vht_capabilities = pos;
  993. elems->vht_capabilities_len = elen;
  994. break;
  995. case WLAN_EID_VHT_OPERATION:
  996. elems->vht_operation = pos;
  997. elems->vht_operation_len = elen;
  998. break;
  999. case WLAN_EID_VHT_OP_MODE_NOTIFY:
  1000. elems->vht_op_mode_notify = pos;
  1001. elems->vht_op_mode_notify_len = elen;
  1002. break;
  1003. default:
  1004. unknown++;
  1005. if (!show_errors)
  1006. break;
  1007. RTW_DBG("IEEE 802.11 element parse "
  1008. "ignored unknown element (id=%d elen=%d)\n",
  1009. id, elen);
  1010. break;
  1011. }
  1012. left -= elen;
  1013. pos += elen;
  1014. }
  1015. if (left)
  1016. return ParseFailed;
  1017. return unknown ? ParseUnknown : ParseOK;
  1018. }
  1019. static u8 key_char2num(u8 ch);
  1020. static u8 key_char2num(u8 ch)
  1021. {
  1022. if ((ch >= '0') && (ch <= '9'))
  1023. return ch - '0';
  1024. else if ((ch >= 'a') && (ch <= 'f'))
  1025. return ch - 'a' + 10;
  1026. else if ((ch >= 'A') && (ch <= 'F'))
  1027. return ch - 'A' + 10;
  1028. else
  1029. return 0xff;
  1030. }
  1031. u8 str_2char2num(u8 hch, u8 lch);
  1032. u8 str_2char2num(u8 hch, u8 lch)
  1033. {
  1034. return (key_char2num(hch) * 10) + key_char2num(lch);
  1035. }
  1036. u8 key_2char2num(u8 hch, u8 lch);
  1037. u8 key_2char2num(u8 hch, u8 lch)
  1038. {
  1039. return (key_char2num(hch) << 4) | key_char2num(lch);
  1040. }
  1041. void macstr2num(u8 *dst, u8 *src);
  1042. void macstr2num(u8 *dst, u8 *src)
  1043. {
  1044. int jj, kk;
  1045. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  1046. dst[jj] = key_2char2num(src[kk], src[kk + 1]);
  1047. }
  1048. u8 convert_ip_addr(u8 hch, u8 mch, u8 lch)
  1049. {
  1050. return (key_char2num(hch) * 100) + (key_char2num(mch) * 10) + key_char2num(lch);
  1051. }
  1052. #ifdef CONFIG_PLATFORM_INTEL_BYT
  1053. #define MAC_ADDRESS_LEN 12
  1054. int rtw_get_mac_addr_intel(unsigned char *buf)
  1055. {
  1056. int ret = 0;
  1057. int i;
  1058. struct file *fp = NULL;
  1059. mm_segment_t oldfs;
  1060. unsigned char c_mac[MAC_ADDRESS_LEN];
  1061. char fname[] = "/config/wifi/mac.txt";
  1062. int jj, kk;
  1063. RTW_INFO("%s Enter\n", __FUNCTION__);
  1064. ret = rtw_retrieve_from_file(fname, c_mac, MAC_ADDRESS_LEN);
  1065. if (ret < MAC_ADDRESS_LEN)
  1066. return -1;
  1067. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 2)
  1068. buf[jj] = key_2char2num(c_mac[kk], c_mac[kk + 1]);
  1069. RTW_INFO("%s: read from file mac address: "MAC_FMT"\n",
  1070. __FUNCTION__, MAC_ARG(buf));
  1071. return 0;
  1072. }
  1073. #endif /* CONFIG_PLATFORM_INTEL_BYT */
  1074. /*
  1075. * Description:
  1076. * rtw_check_invalid_mac_address:
  1077. * This is only used for checking mac address valid or not.
  1078. *
  1079. * Input:
  1080. * adapter: mac_address pointer.
  1081. * check_local_bit: check locally bit or not.
  1082. *
  1083. * Output:
  1084. * _TRUE: The mac address is invalid.
  1085. * _FALSE: The mac address is valid.
  1086. *
  1087. * Auther: Isaac.Li
  1088. */
  1089. u8 rtw_check_invalid_mac_address(u8 *mac_addr, u8 check_local_bit)
  1090. {
  1091. u8 null_mac_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
  1092. u8 multi_mac_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  1093. u8 res = _FALSE;
  1094. if (_rtw_memcmp(mac_addr, null_mac_addr, ETH_ALEN)) {
  1095. res = _TRUE;
  1096. goto func_exit;
  1097. }
  1098. if (_rtw_memcmp(mac_addr, multi_mac_addr, ETH_ALEN)) {
  1099. res = _TRUE;
  1100. goto func_exit;
  1101. }
  1102. if (mac_addr[0] & BIT0) {
  1103. res = _TRUE;
  1104. goto func_exit;
  1105. }
  1106. if (check_local_bit == _TRUE) {
  1107. if (mac_addr[0] & BIT1) {
  1108. res = _TRUE;
  1109. goto func_exit;
  1110. }
  1111. }
  1112. func_exit:
  1113. return res;
  1114. }
  1115. extern char *rtw_initmac;
  1116. /**
  1117. * rtw_macaddr_cfg - Decide the mac address used
  1118. * @out: buf to store mac address decided
  1119. * @hw_mac_addr: mac address from efuse/epprom
  1120. */
  1121. void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr)
  1122. {
  1123. #define DEFAULT_RANDOM_MACADDR 1
  1124. u8 mac[ETH_ALEN];
  1125. if (out == NULL) {
  1126. rtw_warn_on(1);
  1127. return;
  1128. }
  1129. /* Users specify the mac address */
  1130. if (rtw_initmac) {
  1131. int jj, kk;
  1132. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  1133. mac[jj] = key_2char2num(rtw_initmac[kk], rtw_initmac[kk + 1]);
  1134. goto err_chk;
  1135. }
  1136. /* platform specified */
  1137. #ifdef CONFIG_PLATFORM_INTEL_BYT
  1138. if (rtw_get_mac_addr_intel(mac) == 0)
  1139. goto err_chk;
  1140. #endif
  1141. /* Use the mac address stored in the Efuse */
  1142. if (hw_mac_addr) {
  1143. _rtw_memcpy(mac, hw_mac_addr, ETH_ALEN);
  1144. goto err_chk;
  1145. }
  1146. err_chk:
  1147. if (rtw_check_invalid_mac_address(mac, _TRUE) == _TRUE) {
  1148. #if DEFAULT_RANDOM_MACADDR
  1149. RTW_ERR("invalid mac addr:"MAC_FMT", assign random MAC\n", MAC_ARG(mac));
  1150. *((u32 *)(&mac[2])) = rtw_random32();
  1151. mac[0] = 0x00;
  1152. mac[1] = 0xe0;
  1153. mac[2] = 0x4c;
  1154. #else
  1155. RTW_ERR("invalid mac addr:"MAC_FMT", assign default one\n", MAC_ARG(mac));
  1156. mac[0] = 0x00;
  1157. mac[1] = 0xe0;
  1158. mac[2] = 0x4c;
  1159. mac[3] = 0x87;
  1160. mac[4] = 0x00;
  1161. mac[5] = 0x00;
  1162. #endif
  1163. }
  1164. _rtw_memcpy(out, mac, ETH_ALEN);
  1165. RTW_INFO("%s mac addr:"MAC_FMT"\n", __func__, MAC_ARG(out));
  1166. }
  1167. #ifdef CONFIG_80211N_HT
  1168. void dump_ht_cap_ie_content(void *sel, u8 *buf, u32 buf_len)
  1169. {
  1170. if (buf_len != 26) {
  1171. RTW_PRINT_SEL(sel, "Invalid HT capability IE len:%d != %d\n", buf_len, 26);
  1172. return;
  1173. }
  1174. RTW_PRINT_SEL(sel, "HT Capabilities Info:%02x%02x\n", *(buf), *(buf + 1));
  1175. RTW_PRINT_SEL(sel, "A-MPDU Parameters:"HT_AMPDU_PARA_FMT"\n"
  1176. , HT_AMPDU_PARA_ARG(HT_CAP_ELE_AMPDU_PARA(buf)));
  1177. RTW_PRINT_SEL(sel, "Supported MCS Set:"HT_SUP_MCS_SET_FMT"\n"
  1178. , HT_SUP_MCS_SET_ARG(HT_CAP_ELE_SUP_MCS_SET(buf)));
  1179. }
  1180. void dump_ht_cap_ie(void *sel, u8 *ie, u32 ie_len)
  1181. {
  1182. u8 *pos = (u8 *)ie;
  1183. u16 id;
  1184. u16 len;
  1185. u8 *ht_cap_ie;
  1186. sint ht_cap_ielen;
  1187. ht_cap_ie = rtw_get_ie(ie, _HT_CAPABILITY_IE_, &ht_cap_ielen, ie_len);
  1188. if (!ie || ht_cap_ie != ie)
  1189. return;
  1190. dump_ht_cap_ie_content(sel, ht_cap_ie + 2, ht_cap_ielen);
  1191. }
  1192. #endif /* CONFIG_80211N_HT */
  1193. void dump_ies(void *sel, u8 *buf, u32 buf_len)
  1194. {
  1195. u8 *pos = (u8 *)buf;
  1196. u8 id, len;
  1197. while (pos - buf + 1 < buf_len) {
  1198. id = *pos;
  1199. len = *(pos + 1);
  1200. RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u\n", __FUNCTION__, id, len);
  1201. #ifdef CONFIG_80211N_HT
  1202. dump_ht_cap_ie(sel, pos, len + 2);
  1203. #endif
  1204. dump_wps_ie(sel, pos, len + 2);
  1205. #ifdef CONFIG_P2P
  1206. dump_p2p_ie(sel, pos, len + 2);
  1207. #ifdef CONFIG_WFD
  1208. dump_wfd_ie(sel, pos, len + 2);
  1209. #endif
  1210. #endif
  1211. pos += (2 + len);
  1212. }
  1213. }
  1214. void dump_wps_ie(void *sel, u8 *ie, u32 ie_len)
  1215. {
  1216. u8 *pos = (u8 *)ie;
  1217. u16 id;
  1218. u16 len;
  1219. u8 *wps_ie;
  1220. uint wps_ielen;
  1221. wps_ie = rtw_get_wps_ie(ie, ie_len, NULL, &wps_ielen);
  1222. if (wps_ie != ie || wps_ielen == 0)
  1223. return;
  1224. pos += 6;
  1225. while (pos - ie + 4 <= ie_len) {
  1226. id = RTW_GET_BE16(pos);
  1227. len = RTW_GET_BE16(pos + 2);
  1228. RTW_PRINT_SEL(sel, "%s ID:0x%04x, LEN:%u%s\n", __func__, id, len
  1229. , ((pos - ie + 4 + len) <= ie_len) ? "" : "(exceed ie_len)");
  1230. pos += (4 + len);
  1231. }
  1232. }
  1233. /**
  1234. * rtw_ies_get_chbw - get operation ch, bw, offset from IEs of BSS.
  1235. * @ies: pointer of the first tlv IE
  1236. * @ies_len: length of @ies
  1237. * @ch: pointer of ch, used as output
  1238. * @bw: pointer of bw, used as output
  1239. * @offset: pointer of offset, used as output
  1240. */
  1241. void rtw_ies_get_chbw(u8 *ies, int ies_len, u8 *ch, u8 *bw, u8 *offset)
  1242. {
  1243. u8 *p;
  1244. int ie_len;
  1245. *ch = 0;
  1246. *bw = CHANNEL_WIDTH_20;
  1247. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1248. p = rtw_get_ie(ies, _DSSET_IE_, &ie_len, ies_len);
  1249. if (p && ie_len > 0)
  1250. *ch = *(p + 2);
  1251. #ifdef CONFIG_80211N_HT
  1252. {
  1253. u8 *ht_cap_ie, *ht_op_ie;
  1254. int ht_cap_ielen, ht_op_ielen;
  1255. ht_cap_ie = rtw_get_ie(ies, EID_HTCapability, &ht_cap_ielen, ies_len);
  1256. if (ht_cap_ie && ht_cap_ielen) {
  1257. if (GET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2))
  1258. *bw = CHANNEL_WIDTH_40;
  1259. }
  1260. ht_op_ie = rtw_get_ie(ies, EID_HTInfo, &ht_op_ielen, ies_len);
  1261. if (ht_op_ie && ht_op_ielen) {
  1262. if (*ch == 0)
  1263. *ch = GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2);
  1264. else if (*ch != 0 && *ch != GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2)) {
  1265. RTW_INFO("%s ch inconsistent, DSSS:%u, HT primary:%u\n"
  1266. , __func__, *ch, GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2));
  1267. }
  1268. if (!GET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2))
  1269. *bw = CHANNEL_WIDTH_20;
  1270. if (*bw == CHANNEL_WIDTH_40) {
  1271. switch (GET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2)) {
  1272. case SCA:
  1273. *offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1274. break;
  1275. case SCB:
  1276. *offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. }
  1282. #endif /* CONFIG_80211N_HT */
  1283. #ifdef CONFIG_80211AC_VHT
  1284. {
  1285. u8 *vht_op_ie;
  1286. int vht_op_ielen;
  1287. vht_op_ie = rtw_get_ie(ies, EID_VHTOperation, &vht_op_ielen, ies_len);
  1288. if (vht_op_ie && vht_op_ielen) {
  1289. /* enable VHT 80 before check enable HT40 or not */
  1290. if (GET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2) >= 1) {
  1291. /* for HT40, enable VHT80 */
  1292. if (*bw == CHANNEL_WIDTH_40)
  1293. *bw = CHANNEL_WIDTH_80;
  1294. /* for HT20, enable VHT20 */
  1295. else if (*bw == CHANNEL_WIDTH_20) {
  1296. /* modify VHT OP IE */
  1297. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 0);
  1298. /* reset to 0 for VHT20 */
  1299. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, 0);
  1300. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
  1301. }
  1302. } else {
  1303. /*
  1304. VHT OP WIDTH = 0 under HT20/HT40
  1305. if REGSTY_BW_5G(pregistrypriv) < CHANNEL_WIDTH_80 in rtw_build_vht_operation_ie
  1306. */
  1307. }
  1308. }
  1309. }
  1310. #endif
  1311. }
  1312. void rtw_bss_get_chbw(WLAN_BSSID_EX *bss, u8 *ch, u8 *bw, u8 *offset)
  1313. {
  1314. rtw_ies_get_chbw(bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)
  1315. , bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)
  1316. , ch, bw, offset);
  1317. if (*ch == 0)
  1318. *ch = bss->Configuration.DSConfig;
  1319. else if (*ch != bss->Configuration.DSConfig) {
  1320. RTW_INFO("inconsistent ch - ies:%u bss->Configuration.DSConfig:%u\n"
  1321. , *ch, bss->Configuration.DSConfig);
  1322. *ch = bss->Configuration.DSConfig;
  1323. rtw_warn_on(1);
  1324. }
  1325. }
  1326. /**
  1327. * rtw_is_chbw_grouped - test if the two ch settings can be grouped together
  1328. * @ch_a: ch of set a
  1329. * @bw_a: bw of set a
  1330. * @offset_a: offset of set a
  1331. * @ch_b: ch of set b
  1332. * @bw_b: bw of set b
  1333. * @offset_b: offset of set b
  1334. */
  1335. bool rtw_is_chbw_grouped(u8 ch_a, u8 bw_a, u8 offset_a
  1336. , u8 ch_b, u8 bw_b, u8 offset_b)
  1337. {
  1338. bool is_grouped = _FALSE;
  1339. if (ch_a != ch_b) {
  1340. /* ch is different */
  1341. goto exit;
  1342. } else if ((bw_a == CHANNEL_WIDTH_40 || bw_a == CHANNEL_WIDTH_80)
  1343. && (bw_b == CHANNEL_WIDTH_40 || bw_b == CHANNEL_WIDTH_80)
  1344. ) {
  1345. if (offset_a != offset_b)
  1346. goto exit;
  1347. }
  1348. is_grouped = _TRUE;
  1349. exit:
  1350. return is_grouped;
  1351. }
  1352. /**
  1353. * rtw_sync_chbw - obey g_ch, adjust g_bw, g_offset, bw, offset
  1354. * @req_ch: pointer of the request ch, may be modified further
  1355. * @req_bw: pointer of the request bw, may be modified further
  1356. * @req_offset: pointer of the request offset, may be modified further
  1357. * @g_ch: pointer of the ongoing group ch
  1358. * @g_bw: pointer of the ongoing group bw, may be modified further
  1359. * @g_offset: pointer of the ongoing group offset, may be modified further
  1360. */
  1361. void rtw_sync_chbw(u8 *req_ch, u8 *req_bw, u8 *req_offset
  1362. , u8 *g_ch, u8 *g_bw, u8 *g_offset)
  1363. {
  1364. *req_ch = *g_ch;
  1365. if (*req_bw == CHANNEL_WIDTH_80 && *g_ch <= 14) {
  1366. /*2.4G ch, downgrade to 40Mhz */
  1367. *req_bw = CHANNEL_WIDTH_40;
  1368. }
  1369. switch (*req_bw) {
  1370. case CHANNEL_WIDTH_80:
  1371. if (*g_bw == CHANNEL_WIDTH_40 || *g_bw == CHANNEL_WIDTH_80)
  1372. *req_offset = *g_offset;
  1373. else if (*g_bw == CHANNEL_WIDTH_20)
  1374. *req_offset = rtw_get_offset_by_ch(*req_ch);
  1375. if (*req_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
  1376. RTW_ERR("%s req 80MHz BW without offset, down to 20MHz\n", __func__);
  1377. rtw_warn_on(1);
  1378. *req_bw = CHANNEL_WIDTH_20;
  1379. }
  1380. break;
  1381. case CHANNEL_WIDTH_40:
  1382. if (*g_bw == CHANNEL_WIDTH_40 || *g_bw == CHANNEL_WIDTH_80)
  1383. *req_offset = *g_offset;
  1384. else if (*g_bw == CHANNEL_WIDTH_20)
  1385. *req_offset = rtw_get_offset_by_ch(*req_ch);
  1386. if (*req_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
  1387. RTW_ERR("%s req 40MHz BW without offset, down to 20MHz\n", __func__);
  1388. rtw_warn_on(1);
  1389. *req_bw = CHANNEL_WIDTH_20;
  1390. }
  1391. break;
  1392. case CHANNEL_WIDTH_20:
  1393. *req_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1394. break;
  1395. default:
  1396. RTW_ERR("%s req unsupported BW:%u\n", __func__, *req_bw);
  1397. rtw_warn_on(1);
  1398. }
  1399. if (*req_bw > *g_bw) {
  1400. *g_bw = *req_bw;
  1401. *g_offset = *req_offset;
  1402. }
  1403. }
  1404. /**
  1405. * rtw_get_p2p_merged_len - Get merged ie length from muitiple p2p ies.
  1406. * @in_ie: Pointer of the first p2p ie
  1407. * @in_len: Total len of muiltiple p2p ies
  1408. * Returns: Length of merged p2p ie length
  1409. */
  1410. u32 rtw_get_p2p_merged_ies_len(u8 *in_ie, u32 in_len)
  1411. {
  1412. PNDIS_802_11_VARIABLE_IEs pIE;
  1413. u8 OUI[4] = { 0x50, 0x6f, 0x9a, 0x09 };
  1414. int i = 0;
  1415. int j = 0, len = 0;
  1416. while (i < in_len) {
  1417. pIE = (PNDIS_802_11_VARIABLE_IEs)(in_ie + i);
  1418. if (pIE->ElementID == _VENDOR_SPECIFIC_IE_ && _rtw_memcmp(pIE->data, OUI, 4)) {
  1419. len += pIE->Length - 4; /* 4 is P2P OUI length, don't count it in this loop */
  1420. }
  1421. i += (pIE->Length + 2);
  1422. }
  1423. return len + 4; /* Append P2P OUI length at last. */
  1424. }
  1425. /**
  1426. * rtw_p2p_merge_ies - Merge muitiple p2p ies into one
  1427. * @in_ie: Pointer of the first p2p ie
  1428. * @in_len: Total len of muiltiple p2p ies
  1429. * @merge_ie: Pointer of merged ie
  1430. * Returns: Length of merged p2p ie
  1431. */
  1432. int rtw_p2p_merge_ies(u8 *in_ie, u32 in_len, u8 *merge_ie)
  1433. {
  1434. PNDIS_802_11_VARIABLE_IEs pIE;
  1435. u8 len = 0;
  1436. u8 OUI[4] = { 0x50, 0x6f, 0x9a, 0x09 };
  1437. u8 ELOUI[6] = { 0xDD, 0x00, 0x50, 0x6f, 0x9a, 0x09 }; /* EID;Len;OUI, Len would copy at the end of function */
  1438. int i = 0;
  1439. if (merge_ie != NULL) {
  1440. /* Set first P2P OUI */
  1441. _rtw_memcpy(merge_ie, ELOUI, 6);
  1442. merge_ie += 6;
  1443. while (i < in_len) {
  1444. pIE = (PNDIS_802_11_VARIABLE_IEs)(in_ie + i);
  1445. /* Take out the rest of P2P OUIs */
  1446. if (pIE->ElementID == _VENDOR_SPECIFIC_IE_ && _rtw_memcmp(pIE->data, OUI, 4)) {
  1447. _rtw_memcpy(merge_ie, pIE->data + 4, pIE->Length - 4);
  1448. len += pIE->Length - 4;
  1449. merge_ie += pIE->Length - 4;
  1450. }
  1451. i += (pIE->Length + 2);
  1452. }
  1453. return len + 4; /* 4 is for P2P OUI */
  1454. }
  1455. return 0;
  1456. }
  1457. void dump_p2p_ie(void *sel, u8 *ie, u32 ie_len)
  1458. {
  1459. u8 *pos = (u8 *)ie;
  1460. u8 id;
  1461. u16 len;
  1462. u8 *p2p_ie;
  1463. uint p2p_ielen;
  1464. p2p_ie = rtw_get_p2p_ie(ie, ie_len, NULL, &p2p_ielen);
  1465. if (p2p_ie != ie || p2p_ielen == 0)
  1466. return;
  1467. pos += 6;
  1468. while (pos - ie + 3 <= ie_len) {
  1469. id = *pos;
  1470. len = RTW_GET_LE16(pos + 1);
  1471. RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u%s\n", __func__, id, len
  1472. , ((pos - ie + 3 + len) <= ie_len) ? "" : "(exceed ie_len)");
  1473. pos += (3 + len);
  1474. }
  1475. }
  1476. /**
  1477. * rtw_get_p2p_ie - Search P2P IE from a series of IEs
  1478. * @in_ie: Address of IEs to search
  1479. * @in_len: Length limit from in_ie
  1480. * @p2p_ie: If not NULL and P2P IE is found, P2P IE will be copied to the buf starting from p2p_ie
  1481. * @p2p_ielen: If not NULL and P2P IE is found, will set to the length of the entire P2P IE
  1482. *
  1483. * Returns: The address of the P2P IE found, or NULL
  1484. */
  1485. u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)
  1486. {
  1487. uint cnt;
  1488. u8 *p2p_ie_ptr = NULL;
  1489. u8 eid, p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
  1490. if (p2p_ielen)
  1491. *p2p_ielen = 0;
  1492. if (!in_ie || in_len < 0) {
  1493. rtw_warn_on(1);
  1494. return p2p_ie_ptr;
  1495. }
  1496. if (in_len <= 0)
  1497. return p2p_ie_ptr;
  1498. cnt = 0;
  1499. while (cnt + 1 + 4 < in_len) {
  1500. eid = in_ie[cnt];
  1501. if (cnt + 1 + 4 >= MAX_IE_SZ) {
  1502. rtw_warn_on(1);
  1503. return NULL;
  1504. }
  1505. if (eid == WLAN_EID_VENDOR_SPECIFIC && _rtw_memcmp(&in_ie[cnt + 2], p2p_oui, 4) == _TRUE) {
  1506. p2p_ie_ptr = in_ie + cnt;
  1507. if (p2p_ie)
  1508. _rtw_memcpy(p2p_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  1509. if (p2p_ielen)
  1510. *p2p_ielen = in_ie[cnt + 1] + 2;
  1511. break;
  1512. } else
  1513. cnt += in_ie[cnt + 1] + 2;
  1514. }
  1515. return p2p_ie_ptr;
  1516. }
  1517. /**
  1518. * rtw_get_p2p_attr - Search a specific P2P attribute from a given P2P IE
  1519. * @p2p_ie: Address of P2P IE to search
  1520. * @p2p_ielen: Length limit from p2p_ie
  1521. * @target_attr_id: The attribute ID of P2P attribute to search
  1522. * @buf_attr: If not NULL and the P2P attribute is found, P2P attribute will be copied to the buf starting from buf_attr
  1523. * @len_attr: If not NULL and the P2P attribute is found, will set to the length of the entire P2P attribute
  1524. *
  1525. * Returns: the address of the specific WPS attribute found, or NULL
  1526. */
  1527. u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_attr, u32 *len_attr)
  1528. {
  1529. u8 *attr_ptr = NULL;
  1530. u8 *target_attr_ptr = NULL;
  1531. u8 p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
  1532. if (len_attr)
  1533. *len_attr = 0;
  1534. if (!p2p_ie
  1535. || p2p_ielen <= 6
  1536. || (p2p_ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  1537. || (_rtw_memcmp(p2p_ie + 2, p2p_oui, 4) != _TRUE))
  1538. return attr_ptr;
  1539. /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
  1540. attr_ptr = p2p_ie + 6; /* goto first attr */
  1541. while ((attr_ptr - p2p_ie + 3) <= p2p_ielen) {
  1542. /* 3 = 1(Attribute ID) + 2(Length) */
  1543. u8 attr_id = *attr_ptr;
  1544. u16 attr_data_len = RTW_GET_LE16(attr_ptr + 1);
  1545. u16 attr_len = attr_data_len + 3;
  1546. if (0)
  1547. RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len);
  1548. if ((attr_ptr - p2p_ie + attr_len) > p2p_ielen)
  1549. break;
  1550. if (attr_id == target_attr_id) {
  1551. target_attr_ptr = attr_ptr;
  1552. if (buf_attr)
  1553. _rtw_memcpy(buf_attr, attr_ptr, attr_len);
  1554. if (len_attr)
  1555. *len_attr = attr_len;
  1556. break;
  1557. } else
  1558. attr_ptr += attr_len;
  1559. }
  1560. return target_attr_ptr;
  1561. }
  1562. /**
  1563. * rtw_get_p2p_attr_content - Search a specific P2P attribute content from a given P2P IE
  1564. * @p2p_ie: Address of P2P IE to search
  1565. * @p2p_ielen: Length limit from p2p_ie
  1566. * @target_attr_id: The attribute ID of P2P attribute to search
  1567. * @buf_content: If not NULL and the P2P attribute is found, P2P attribute content will be copied to the buf starting from buf_content
  1568. * @len_content: If not NULL and the P2P attribute is found, will set to the length of the P2P attribute content
  1569. *
  1570. * Returns: the address of the specific P2P attribute content found, or NULL
  1571. */
  1572. u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_content, uint *len_content)
  1573. {
  1574. u8 *attr_ptr;
  1575. u32 attr_len;
  1576. if (len_content)
  1577. *len_content = 0;
  1578. attr_ptr = rtw_get_p2p_attr(p2p_ie, p2p_ielen, target_attr_id, NULL, &attr_len);
  1579. if (attr_ptr && attr_len) {
  1580. if (buf_content)
  1581. _rtw_memcpy(buf_content, attr_ptr + 3, attr_len - 3);
  1582. if (len_content)
  1583. *len_content = attr_len - 3;
  1584. return attr_ptr + 3;
  1585. }
  1586. return NULL;
  1587. }
  1588. u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr)
  1589. {
  1590. u32 a_len;
  1591. *pbuf = attr_id;
  1592. /* *(u16*)(pbuf + 1) = cpu_to_le16(attr_len); */
  1593. RTW_PUT_LE16(pbuf + 1, attr_len);
  1594. if (pdata_attr)
  1595. _rtw_memcpy(pbuf + 3, pdata_attr, attr_len);
  1596. a_len = attr_len + 3;
  1597. return a_len;
  1598. }
  1599. uint rtw_del_p2p_ie(u8 *ies, uint ies_len_ori, const char *msg)
  1600. {
  1601. #define DBG_DEL_P2P_IE 0
  1602. u8 *target_ie;
  1603. u32 target_ie_len;
  1604. uint ies_len = ies_len_ori;
  1605. int index = 0;
  1606. while (1) {
  1607. target_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &target_ie_len);
  1608. if (target_ie && target_ie_len) {
  1609. u8 *next_ie = target_ie + target_ie_len;
  1610. uint remain_len = ies_len - (next_ie - ies);
  1611. if (DBG_DEL_P2P_IE && msg) {
  1612. RTW_INFO("%s %d before\n", __func__, index);
  1613. dump_ies(RTW_DBGDUMP, ies, ies_len);
  1614. RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
  1615. RTW_INFO("target_ie:%p, target_ie_len:%u\n", target_ie, target_ie_len);
  1616. RTW_INFO("next_ie:%p, remain_len:%u\n", next_ie, remain_len);
  1617. }
  1618. _rtw_memmove(target_ie, next_ie, remain_len);
  1619. _rtw_memset(target_ie + remain_len, 0, target_ie_len);
  1620. ies_len -= target_ie_len;
  1621. if (DBG_DEL_P2P_IE && msg) {
  1622. RTW_INFO("%s %d after\n", __func__, index);
  1623. dump_ies(RTW_DBGDUMP, ies, ies_len);
  1624. }
  1625. index++;
  1626. } else
  1627. break;
  1628. }
  1629. return ies_len;
  1630. }
  1631. uint rtw_del_p2p_attr(u8 *ie, uint ielen_ori, u8 attr_id)
  1632. {
  1633. #define DBG_DEL_P2P_ATTR 0
  1634. u8 *target_attr;
  1635. u32 target_attr_len;
  1636. uint ielen = ielen_ori;
  1637. int index = 0;
  1638. while (1) {
  1639. target_attr = rtw_get_p2p_attr(ie, ielen, attr_id, NULL, &target_attr_len);
  1640. if (target_attr && target_attr_len) {
  1641. u8 *next_attr = target_attr + target_attr_len;
  1642. uint remain_len = ielen - (next_attr - ie);
  1643. if (DBG_DEL_P2P_ATTR) {
  1644. RTW_INFO("%s %d before\n", __func__, index);
  1645. dump_ies(RTW_DBGDUMP, ie, ielen);
  1646. RTW_INFO("ie:%p, ielen:%u\n", ie, ielen);
  1647. RTW_INFO("target_attr:%p, target_attr_len:%u\n", target_attr, target_attr_len);
  1648. RTW_INFO("next_attr:%p, remain_len:%u\n", next_attr, remain_len);
  1649. }
  1650. _rtw_memmove(target_attr, next_attr, remain_len);
  1651. _rtw_memset(target_attr + remain_len, 0, target_attr_len);
  1652. *(ie + 1) -= target_attr_len;
  1653. ielen -= target_attr_len;
  1654. if (DBG_DEL_P2P_ATTR) {
  1655. RTW_INFO("%s %d after\n", __func__, index);
  1656. dump_ies(RTW_DBGDUMP, ie, ielen);
  1657. }
  1658. index++;
  1659. } else
  1660. break;
  1661. }
  1662. return ielen;
  1663. }
  1664. inline u8 *rtw_bss_ex_get_p2p_ie(WLAN_BSSID_EX *bss_ex, u8 *p2p_ie, uint *p2p_ielen)
  1665. {
  1666. return rtw_get_p2p_ie(BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex), p2p_ie, p2p_ielen);
  1667. }
  1668. void rtw_bss_ex_del_p2p_ie(WLAN_BSSID_EX *bss_ex)
  1669. {
  1670. #define DBG_BSS_EX_DEL_P2P_IE 0
  1671. u8 *ies = BSS_EX_TLV_IES(bss_ex);
  1672. uint ies_len_ori = BSS_EX_TLV_IES_LEN(bss_ex);
  1673. uint ies_len;
  1674. ies_len = rtw_del_p2p_ie(ies, ies_len_ori, DBG_BSS_EX_DEL_P2P_IE ? __func__ : NULL);
  1675. bss_ex->IELength -= ies_len_ori - ies_len;
  1676. }
  1677. void rtw_bss_ex_del_p2p_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id)
  1678. {
  1679. #define DBG_BSS_EX_DEL_P2P_ATTR 0
  1680. u8 *ies = BSS_EX_TLV_IES(bss_ex);
  1681. uint ies_len = BSS_EX_TLV_IES_LEN(bss_ex);
  1682. u8 *ie;
  1683. uint ie_len, ie_len_ori;
  1684. int index = 0;
  1685. while (1) {
  1686. ie = rtw_get_p2p_ie(ies, ies_len, NULL, &ie_len_ori);
  1687. if (ie) {
  1688. u8 *next_ie_ori = ie + ie_len_ori;
  1689. uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);
  1690. u8 has_target_attr = 0;
  1691. if (DBG_BSS_EX_DEL_P2P_ATTR) {
  1692. if (rtw_get_p2p_attr(ie, ie_len_ori, attr_id, NULL, NULL)) {
  1693. RTW_INFO("%s %d before\n", __func__, index);
  1694. dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
  1695. RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
  1696. RTW_INFO("ie:%p, ie_len_ori:%u\n", ie, ie_len_ori);
  1697. RTW_INFO("next_ie_ori:%p, remain_len:%u\n", next_ie_ori, remain_len);
  1698. has_target_attr = 1;
  1699. }
  1700. }
  1701. ie_len = rtw_del_p2p_attr(ie, ie_len_ori, attr_id);
  1702. if (ie_len != ie_len_ori) {
  1703. u8 *next_ie = ie + ie_len;
  1704. _rtw_memmove(next_ie, next_ie_ori, remain_len);
  1705. _rtw_memset(next_ie + remain_len, 0, ie_len_ori - ie_len);
  1706. bss_ex->IELength -= ie_len_ori - ie_len;
  1707. ies = next_ie;
  1708. } else
  1709. ies = next_ie_ori;
  1710. if (DBG_BSS_EX_DEL_P2P_ATTR) {
  1711. if (has_target_attr) {
  1712. RTW_INFO("%s %d after\n", __func__, index);
  1713. dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
  1714. }
  1715. }
  1716. ies_len = remain_len;
  1717. index++;
  1718. } else
  1719. break;
  1720. }
  1721. }
  1722. void dump_wfd_ie(void *sel, u8 *ie, u32 ie_len)
  1723. {
  1724. u8 *pos = (u8 *)ie;
  1725. u8 id;
  1726. u16 len;
  1727. u8 *wfd_ie;
  1728. uint wfd_ielen;
  1729. wfd_ie = rtw_get_wfd_ie(ie, ie_len, NULL, &wfd_ielen);
  1730. if (wfd_ie != ie || wfd_ielen == 0)
  1731. return;
  1732. pos += 6;
  1733. while (pos - ie + 3 <= ie_len) {
  1734. id = *pos;
  1735. len = RTW_GET_BE16(pos + 1);
  1736. RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u%s\n", __func__, id, len
  1737. , ((pos - ie + 3 + len) <= ie_len) ? "" : "(exceed ie_len)");
  1738. pos += (3 + len);
  1739. }
  1740. }
  1741. /**
  1742. * rtw_get_wfd_ie - Search WFD IE from a series of IEs
  1743. * @in_ie: Address of IEs to search
  1744. * @in_len: Length limit from in_ie
  1745. * @wfd_ie: If not NULL and WFD IE is found, WFD IE will be copied to the buf starting from wfd_ie
  1746. * @wfd_ielen: If not NULL and WFD IE is found, will set to the length of the entire WFD IE
  1747. *
  1748. * Returns: The address of the P2P IE found, or NULL
  1749. */
  1750. u8 *rtw_get_wfd_ie(u8 *in_ie, int in_len, u8 *wfd_ie, uint *wfd_ielen)
  1751. {
  1752. uint cnt;
  1753. u8 *wfd_ie_ptr = NULL;
  1754. u8 eid, wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};
  1755. if (wfd_ielen)
  1756. *wfd_ielen = 0;
  1757. if (!in_ie || in_len < 0) {
  1758. rtw_warn_on(1);
  1759. return wfd_ie_ptr;
  1760. }
  1761. if (in_len <= 0)
  1762. return wfd_ie_ptr;
  1763. cnt = 0;
  1764. while (cnt + 1 + 4 < in_len) {
  1765. eid = in_ie[cnt];
  1766. if (cnt + 1 + 4 >= MAX_IE_SZ) {
  1767. rtw_warn_on(1);
  1768. return NULL;
  1769. }
  1770. if (eid == WLAN_EID_VENDOR_SPECIFIC && _rtw_memcmp(&in_ie[cnt + 2], wfd_oui, 4) == _TRUE) {
  1771. wfd_ie_ptr = in_ie + cnt;
  1772. if (wfd_ie)
  1773. _rtw_memcpy(wfd_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
  1774. if (wfd_ielen)
  1775. *wfd_ielen = in_ie[cnt + 1] + 2;
  1776. break;
  1777. } else
  1778. cnt += in_ie[cnt + 1] + 2;
  1779. }
  1780. return wfd_ie_ptr;
  1781. }
  1782. /**
  1783. * rtw_get_wfd_attr - Search a specific WFD attribute from a given WFD IE
  1784. * @wfd_ie: Address of WFD IE to search
  1785. * @wfd_ielen: Length limit from wfd_ie
  1786. * @target_attr_id: The attribute ID of WFD attribute to search
  1787. * @buf_attr: If not NULL and the WFD attribute is found, WFD attribute will be copied to the buf starting from buf_attr
  1788. * @len_attr: If not NULL and the WFD attribute is found, will set to the length of the entire WFD attribute
  1789. *
  1790. * Returns: the address of the specific WPS attribute found, or NULL
  1791. */
  1792. u8 *rtw_get_wfd_attr(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_attr, u32 *len_attr)
  1793. {
  1794. u8 *attr_ptr = NULL;
  1795. u8 *target_attr_ptr = NULL;
  1796. u8 wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};
  1797. if (len_attr)
  1798. *len_attr = 0;
  1799. if (!wfd_ie
  1800. || wfd_ielen <= 6
  1801. || (wfd_ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  1802. || (_rtw_memcmp(wfd_ie + 2, wfd_oui, 4) != _TRUE))
  1803. return attr_ptr;
  1804. /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
  1805. attr_ptr = wfd_ie + 6; /* goto first attr */
  1806. while ((attr_ptr - wfd_ie + 3) <= wfd_ielen) {
  1807. /* 3 = 1(Attribute ID) + 2(Length) */
  1808. u8 attr_id = *attr_ptr;
  1809. u16 attr_data_len = RTW_GET_BE16(attr_ptr + 1);
  1810. u16 attr_len = attr_data_len + 3;
  1811. if (0)
  1812. RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len);
  1813. if ((attr_ptr - wfd_ie + attr_len) > wfd_ielen)
  1814. break;
  1815. if (attr_id == target_attr_id) {
  1816. target_attr_ptr = attr_ptr;
  1817. if (buf_attr)
  1818. _rtw_memcpy(buf_attr, attr_ptr, attr_len);
  1819. if (len_attr)
  1820. *len_attr = attr_len;
  1821. break;
  1822. } else
  1823. attr_ptr += attr_len;
  1824. }
  1825. return target_attr_ptr;
  1826. }
  1827. /**
  1828. * rtw_get_wfd_attr_content - Search a specific WFD attribute content from a given WFD IE
  1829. * @wfd_ie: Address of WFD IE to search
  1830. * @wfd_ielen: Length limit from wfd_ie
  1831. * @target_attr_id: The attribute ID of WFD attribute to search
  1832. * @buf_content: If not NULL and the WFD attribute is found, WFD attribute content will be copied to the buf starting from buf_content
  1833. * @len_content: If not NULL and the WFD attribute is found, will set to the length of the WFD attribute content
  1834. *
  1835. * Returns: the address of the specific WFD attribute content found, or NULL
  1836. */
  1837. u8 *rtw_get_wfd_attr_content(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_content, uint *len_content)
  1838. {
  1839. u8 *attr_ptr;
  1840. u32 attr_len;
  1841. if (len_content)
  1842. *len_content = 0;
  1843. attr_ptr = rtw_get_wfd_attr(wfd_ie, wfd_ielen, target_attr_id, NULL, &attr_len);
  1844. if (attr_ptr && attr_len) {
  1845. if (buf_content)
  1846. _rtw_memcpy(buf_content, attr_ptr + 3, attr_len - 3);
  1847. if (len_content)
  1848. *len_content = attr_len - 3;
  1849. return attr_ptr + 3;
  1850. }
  1851. return NULL;
  1852. }
  1853. uint rtw_del_wfd_ie(u8 *ies, uint ies_len_ori, const char *msg)
  1854. {
  1855. #define DBG_DEL_WFD_IE 0
  1856. u8 *target_ie;
  1857. u32 target_ie_len;
  1858. uint ies_len = ies_len_ori;
  1859. int index = 0;
  1860. while (1) {
  1861. target_ie = rtw_get_wfd_ie(ies, ies_len, NULL, &target_ie_len);
  1862. if (target_ie && target_ie_len) {
  1863. u8 *next_ie = target_ie + target_ie_len;
  1864. uint remain_len = ies_len - (next_ie - ies);
  1865. if (DBG_DEL_WFD_IE && msg) {
  1866. RTW_INFO("%s %d before\n", __func__, index);
  1867. dump_ies(RTW_DBGDUMP, ies, ies_len);
  1868. RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
  1869. RTW_INFO("target_ie:%p, target_ie_len:%u\n", target_ie, target_ie_len);
  1870. RTW_INFO("next_ie:%p, remain_len:%u\n", next_ie, remain_len);
  1871. }
  1872. _rtw_memmove(target_ie, next_ie, remain_len);
  1873. _rtw_memset(target_ie + remain_len, 0, target_ie_len);
  1874. ies_len -= target_ie_len;
  1875. if (DBG_DEL_WFD_IE && msg) {
  1876. RTW_INFO("%s %d after\n", __func__, index);
  1877. dump_ies(RTW_DBGDUMP, ies, ies_len);
  1878. }
  1879. index++;
  1880. } else
  1881. break;
  1882. }
  1883. return ies_len;
  1884. }
  1885. uint rtw_del_wfd_attr(u8 *ie, uint ielen_ori, u8 attr_id)
  1886. {
  1887. #define DBG_DEL_WFD_ATTR 0
  1888. u8 *target_attr;
  1889. u32 target_attr_len;
  1890. uint ielen = ielen_ori;
  1891. int index = 0;
  1892. while (1) {
  1893. target_attr = rtw_get_wfd_attr(ie, ielen, attr_id, NULL, &target_attr_len);
  1894. if (target_attr && target_attr_len) {
  1895. u8 *next_attr = target_attr + target_attr_len;
  1896. uint remain_len = ielen - (next_attr - ie);
  1897. if (DBG_DEL_WFD_ATTR) {
  1898. RTW_INFO("%s %d before\n", __func__, index);
  1899. dump_ies(RTW_DBGDUMP, ie, ielen);
  1900. RTW_INFO("ie:%p, ielen:%u\n", ie, ielen);
  1901. RTW_INFO("target_attr:%p, target_attr_len:%u\n", target_attr, target_attr_len);
  1902. RTW_INFO("next_attr:%p, remain_len:%u\n", next_attr, remain_len);
  1903. }
  1904. _rtw_memmove(target_attr, next_attr, remain_len);
  1905. _rtw_memset(target_attr + remain_len, 0, target_attr_len);
  1906. *(ie + 1) -= target_attr_len;
  1907. ielen -= target_attr_len;
  1908. if (DBG_DEL_WFD_ATTR) {
  1909. RTW_INFO("%s %d after\n", __func__, index);
  1910. dump_ies(RTW_DBGDUMP, ie, ielen);
  1911. }
  1912. index++;
  1913. } else
  1914. break;
  1915. }
  1916. return ielen;
  1917. }
  1918. inline u8 *rtw_bss_ex_get_wfd_ie(WLAN_BSSID_EX *bss_ex, u8 *wfd_ie, uint *wfd_ielen)
  1919. {
  1920. return rtw_get_wfd_ie(BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex), wfd_ie, wfd_ielen);
  1921. }
  1922. void rtw_bss_ex_del_wfd_ie(WLAN_BSSID_EX *bss_ex)
  1923. {
  1924. #define DBG_BSS_EX_DEL_WFD_IE 0
  1925. u8 *ies = BSS_EX_TLV_IES(bss_ex);
  1926. uint ies_len_ori = BSS_EX_TLV_IES_LEN(bss_ex);
  1927. uint ies_len;
  1928. ies_len = rtw_del_wfd_ie(ies, ies_len_ori, DBG_BSS_EX_DEL_WFD_IE ? __func__ : NULL);
  1929. bss_ex->IELength -= ies_len_ori - ies_len;
  1930. }
  1931. void rtw_bss_ex_del_wfd_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id)
  1932. {
  1933. #define DBG_BSS_EX_DEL_WFD_ATTR 0
  1934. u8 *ies = BSS_EX_TLV_IES(bss_ex);
  1935. uint ies_len = BSS_EX_TLV_IES_LEN(bss_ex);
  1936. u8 *ie;
  1937. uint ie_len, ie_len_ori;
  1938. int index = 0;
  1939. while (1) {
  1940. ie = rtw_get_wfd_ie(ies, ies_len, NULL, &ie_len_ori);
  1941. if (ie) {
  1942. u8 *next_ie_ori = ie + ie_len_ori;
  1943. uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);
  1944. u8 has_target_attr = 0;
  1945. if (DBG_BSS_EX_DEL_WFD_ATTR) {
  1946. if (rtw_get_wfd_attr(ie, ie_len_ori, attr_id, NULL, NULL)) {
  1947. RTW_INFO("%s %d before\n", __func__, index);
  1948. dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
  1949. RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
  1950. RTW_INFO("ie:%p, ie_len_ori:%u\n", ie, ie_len_ori);
  1951. RTW_INFO("next_ie_ori:%p, remain_len:%u\n", next_ie_ori, remain_len);
  1952. has_target_attr = 1;
  1953. }
  1954. }
  1955. ie_len = rtw_del_wfd_attr(ie, ie_len_ori, attr_id);
  1956. if (ie_len != ie_len_ori) {
  1957. u8 *next_ie = ie + ie_len;
  1958. _rtw_memmove(next_ie, next_ie_ori, remain_len);
  1959. _rtw_memset(next_ie + remain_len, 0, ie_len_ori - ie_len);
  1960. bss_ex->IELength -= ie_len_ori - ie_len;
  1961. ies = next_ie;
  1962. } else
  1963. ies = next_ie_ori;
  1964. if (DBG_BSS_EX_DEL_WFD_ATTR) {
  1965. if (has_target_attr) {
  1966. RTW_INFO("%s %d after\n", __func__, index);
  1967. dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
  1968. }
  1969. }
  1970. ies_len = remain_len;
  1971. index++;
  1972. } else
  1973. break;
  1974. }
  1975. }
  1976. /* Baron adds to avoid FreeBSD warning */
  1977. int ieee80211_is_empty_essid(const char *essid, int essid_len)
  1978. {
  1979. /* Single white space is for Linksys APs */
  1980. if (essid_len == 1 && essid[0] == ' ')
  1981. return 1;
  1982. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  1983. while (essid_len) {
  1984. essid_len--;
  1985. if (essid[essid_len] != '\0')
  1986. return 0;
  1987. }
  1988. return 1;
  1989. }
  1990. int ieee80211_get_hdrlen(u16 fc)
  1991. {
  1992. int hdrlen = 24;
  1993. switch (WLAN_FC_GET_TYPE(fc)) {
  1994. case RTW_IEEE80211_FTYPE_DATA:
  1995. if (fc & RTW_IEEE80211_STYPE_QOS_DATA)
  1996. hdrlen += 2;
  1997. if ((fc & RTW_IEEE80211_FCTL_FROMDS) && (fc & RTW_IEEE80211_FCTL_TODS))
  1998. hdrlen += 6; /* Addr4 */
  1999. break;
  2000. case RTW_IEEE80211_FTYPE_CTL:
  2001. switch (WLAN_FC_GET_STYPE(fc)) {
  2002. case RTW_IEEE80211_STYPE_CTS:
  2003. case RTW_IEEE80211_STYPE_ACK:
  2004. hdrlen = 10;
  2005. break;
  2006. default:
  2007. hdrlen = 16;
  2008. break;
  2009. }
  2010. break;
  2011. }
  2012. return hdrlen;
  2013. }
  2014. int rtw_get_cipher_info(struct wlan_network *pnetwork)
  2015. {
  2016. u32 wpa_ielen;
  2017. unsigned char *pbuf;
  2018. int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
  2019. int ret = _FAIL;
  2020. pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
  2021. if (pbuf && (wpa_ielen > 0)) {
  2022. if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
  2023. pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
  2024. pnetwork->BcnInfo.group_cipher = group_cipher;
  2025. pnetwork->BcnInfo.is_8021x = is8021x;
  2026. ret = _SUCCESS;
  2027. }
  2028. } else {
  2029. pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
  2030. if (pbuf && (wpa_ielen > 0)) {
  2031. if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
  2032. pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
  2033. pnetwork->BcnInfo.group_cipher = group_cipher;
  2034. pnetwork->BcnInfo.is_8021x = is8021x;
  2035. ret = _SUCCESS;
  2036. }
  2037. }
  2038. }
  2039. return ret;
  2040. }
  2041. void rtw_get_bcn_info(struct wlan_network *pnetwork)
  2042. {
  2043. unsigned short cap = 0;
  2044. u8 bencrypt = 0;
  2045. /* u8 wpa_ie[255],rsn_ie[255]; */
  2046. u16 wpa_len = 0, rsn_len = 0;
  2047. struct HT_info_element *pht_info = NULL;
  2048. struct rtw_ieee80211_ht_cap *pht_cap = NULL;
  2049. unsigned int len;
  2050. unsigned char *p;
  2051. _rtw_memcpy((u8 *)&cap, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
  2052. cap = le16_to_cpu(cap);
  2053. if (cap & WLAN_CAPABILITY_PRIVACY) {
  2054. bencrypt = 1;
  2055. pnetwork->network.Privacy = 1;
  2056. } else
  2057. pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
  2058. rtw_get_sec_ie(pnetwork->network.IEs , pnetwork->network.IELength, NULL, &rsn_len, NULL, &wpa_len);
  2059. if (rsn_len > 0)
  2060. pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
  2061. else if (wpa_len > 0)
  2062. pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
  2063. else {
  2064. if (bencrypt)
  2065. pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
  2066. }
  2067. rtw_get_cipher_info(pnetwork);
  2068. /* get bwmode and ch_offset */
  2069. /* parsing HT_CAP_IE */
  2070. p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
  2071. if (p && len > 0) {
  2072. pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
  2073. pnetwork->BcnInfo.ht_cap_info = pht_cap->cap_info;
  2074. } else
  2075. pnetwork->BcnInfo.ht_cap_info = 0;
  2076. /* parsing HT_INFO_IE */
  2077. p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
  2078. if (p && len > 0) {
  2079. pht_info = (struct HT_info_element *)(p + 2);
  2080. pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
  2081. } else
  2082. pnetwork->BcnInfo.ht_info_infos_0 = 0;
  2083. }
  2084. u8 rtw_ht_mcsset_to_nss(u8 *supp_mcs_set)
  2085. {
  2086. u8 nss = 1;
  2087. if (supp_mcs_set[3])
  2088. nss = 4;
  2089. else if (supp_mcs_set[2])
  2090. nss = 3;
  2091. else if (supp_mcs_set[1])
  2092. nss = 2;
  2093. else if (supp_mcs_set[0])
  2094. nss = 1;
  2095. else
  2096. RTW_INFO("%s,%d, warning! supp_mcs_set is zero\n", __func__, __LINE__);
  2097. /* RTW_INFO("%s HT: %dSS\n", __FUNCTION__, nss); */
  2098. return nss;
  2099. }
  2100. u32 rtw_ht_mcs_set_to_bitmap(u8 *mcs_set, u8 nss)
  2101. {
  2102. u8 i;
  2103. u32 bitmap = 0;
  2104. for (i = 0; i < nss; i++)
  2105. bitmap |= mcs_set[i] << (i * 8);
  2106. RTW_INFO("ht_mcs_set=%02x %02x %02x %02x, nss=%u, bitmap=%08x\n"
  2107. , mcs_set[0], mcs_set[1], mcs_set[2], mcs_set[3], nss, bitmap);
  2108. return bitmap;
  2109. }
  2110. /* show MCS rate, unit: 100Kbps */
  2111. u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate)
  2112. {
  2113. u16 max_rate = 0;
  2114. if (MCS_rate[3]) {
  2115. if (MCS_rate[3] & BIT(7))
  2116. max_rate = (bw_40MHz) ? ((short_GI) ? 6000 : 5400) : ((short_GI) ? 2889 : 2600);
  2117. else if (MCS_rate[3] & BIT(6))
  2118. max_rate = (bw_40MHz) ? ((short_GI) ? 5400 : 4860) : ((short_GI) ? 2600 : 2340);
  2119. else if (MCS_rate[3] & BIT(5))
  2120. max_rate = (bw_40MHz) ? ((short_GI) ? 4800 : 4320) : ((short_GI) ? 2311 : 2080);
  2121. else if (MCS_rate[3] & BIT(4))
  2122. max_rate = (bw_40MHz) ? ((short_GI) ? 3600 : 3240) : ((short_GI) ? 1733 : 1560);
  2123. else if (MCS_rate[3] & BIT(3))
  2124. max_rate = (bw_40MHz) ? ((short_GI) ? 2400 : 2160) : ((short_GI) ? 1156 : 1040);
  2125. else if (MCS_rate[3] & BIT(2))
  2126. max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);
  2127. else if (MCS_rate[3] & BIT(1))
  2128. max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);
  2129. else if (MCS_rate[3] & BIT(0))
  2130. max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);
  2131. } else if (MCS_rate[2]) {
  2132. if (MCS_rate[2] & BIT(7))
  2133. max_rate = (bw_40MHz) ? ((short_GI) ? 4500 : 4050) : ((short_GI) ? 2167 : 1950);
  2134. else if (MCS_rate[2] & BIT(6))
  2135. max_rate = (bw_40MHz) ? ((short_GI) ? 4050 : 3645) : ((short_GI) ? 1950 : 1750);
  2136. else if (MCS_rate[2] & BIT(5))
  2137. max_rate = (bw_40MHz) ? ((short_GI) ? 3600 : 3240) : ((short_GI) ? 1733 : 1560);
  2138. else if (MCS_rate[2] & BIT(4))
  2139. max_rate = (bw_40MHz) ? ((short_GI) ? 2700 : 2430) : ((short_GI) ? 1300 : 1170);
  2140. else if (MCS_rate[2] & BIT(3))
  2141. max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);
  2142. else if (MCS_rate[2] & BIT(2))
  2143. max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585);
  2144. else if (MCS_rate[2] & BIT(1))
  2145. max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);
  2146. else if (MCS_rate[2] & BIT(0))
  2147. max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195);
  2148. } else if (MCS_rate[1]) {
  2149. if (MCS_rate[1] & BIT(7))
  2150. max_rate = (bw_40MHz) ? ((short_GI) ? 3000 : 2700) : ((short_GI) ? 1444 : 1300);
  2151. else if (MCS_rate[1] & BIT(6))
  2152. max_rate = (bw_40MHz) ? ((short_GI) ? 2700 : 2430) : ((short_GI) ? 1300 : 1170);
  2153. else if (MCS_rate[1] & BIT(5))
  2154. max_rate = (bw_40MHz) ? ((short_GI) ? 2400 : 2160) : ((short_GI) ? 1156 : 1040);
  2155. else if (MCS_rate[1] & BIT(4))
  2156. max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);
  2157. else if (MCS_rate[1] & BIT(3))
  2158. max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);
  2159. else if (MCS_rate[1] & BIT(2))
  2160. max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);
  2161. else if (MCS_rate[1] & BIT(1))
  2162. max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);
  2163. else if (MCS_rate[1] & BIT(0))
  2164. max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
  2165. } else {
  2166. if (MCS_rate[0] & BIT(7))
  2167. max_rate = (bw_40MHz) ? ((short_GI) ? 1500 : 1350) : ((short_GI) ? 722 : 650);
  2168. else if (MCS_rate[0] & BIT(6))
  2169. max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585);
  2170. else if (MCS_rate[0] & BIT(5))
  2171. max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);
  2172. else if (MCS_rate[0] & BIT(4))
  2173. max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);
  2174. else if (MCS_rate[0] & BIT(3))
  2175. max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);
  2176. else if (MCS_rate[0] & BIT(2))
  2177. max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195);
  2178. else if (MCS_rate[0] & BIT(1))
  2179. max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
  2180. else if (MCS_rate[0] & BIT(0))
  2181. max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
  2182. }
  2183. return max_rate;
  2184. }
  2185. int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action)
  2186. {
  2187. const u8 *frame_body = frame + sizeof(struct rtw_ieee80211_hdr_3addr);
  2188. u16 fc;
  2189. u8 c;
  2190. u8 a = ACT_PUBLIC_MAX;
  2191. fc = le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)frame)->frame_ctl);
  2192. if ((fc & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE))
  2193. != (RTW_IEEE80211_FTYPE_MGMT | RTW_IEEE80211_STYPE_ACTION)
  2194. )
  2195. return _FALSE;
  2196. c = frame_body[0];
  2197. switch (c) {
  2198. case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */
  2199. break;
  2200. default:
  2201. a = frame_body[1];
  2202. }
  2203. if (category)
  2204. *category = c;
  2205. if (action)
  2206. *action = a;
  2207. return _TRUE;
  2208. }
  2209. static const char *_action_public_str[] = {
  2210. "ACT_PUB_BSSCOEXIST",
  2211. "ACT_PUB_DSE_ENABLE",
  2212. "ACT_PUB_DSE_DEENABLE",
  2213. "ACT_PUB_DSE_REG_LOCATION",
  2214. "ACT_PUB_EXT_CHL_SWITCH",
  2215. "ACT_PUB_DSE_MSR_REQ",
  2216. "ACT_PUB_DSE_MSR_RPRT",
  2217. "ACT_PUB_MP",
  2218. "ACT_PUB_DSE_PWR_CONSTRAINT",
  2219. "ACT_PUB_VENDOR",
  2220. "ACT_PUB_GAS_INITIAL_REQ",
  2221. "ACT_PUB_GAS_INITIAL_RSP",
  2222. "ACT_PUB_GAS_COMEBACK_REQ",
  2223. "ACT_PUB_GAS_COMEBACK_RSP",
  2224. "ACT_PUB_TDLS_DISCOVERY_RSP",
  2225. "ACT_PUB_LOCATION_TRACK",
  2226. "ACT_PUB_RSVD",
  2227. };
  2228. const char *action_public_str(u8 action)
  2229. {
  2230. action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
  2231. return _action_public_str[action];
  2232. }