wmi.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/ip.h>
  17. #include "core.h"
  18. #include "debug.h"
  19. #include "testmode.h"
  20. #include "../regd.h"
  21. #include "../regd_common.h"
  22. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
  23. static const s32 wmi_rate_tbl[][2] = {
  24. /* {W/O SGI, with SGI} */
  25. {1000, 1000},
  26. {2000, 2000},
  27. {5500, 5500},
  28. {11000, 11000},
  29. {6000, 6000},
  30. {9000, 9000},
  31. {12000, 12000},
  32. {18000, 18000},
  33. {24000, 24000},
  34. {36000, 36000},
  35. {48000, 48000},
  36. {54000, 54000},
  37. {6500, 7200},
  38. {13000, 14400},
  39. {19500, 21700},
  40. {26000, 28900},
  41. {39000, 43300},
  42. {52000, 57800},
  43. {58500, 65000},
  44. {65000, 72200},
  45. {13500, 15000},
  46. {27000, 30000},
  47. {40500, 45000},
  48. {54000, 60000},
  49. {81000, 90000},
  50. {108000, 120000},
  51. {121500, 135000},
  52. {135000, 150000},
  53. {0, 0}
  54. };
  55. /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
  56. static const u8 up_to_ac[] = {
  57. WMM_AC_BE,
  58. WMM_AC_BK,
  59. WMM_AC_BK,
  60. WMM_AC_BE,
  61. WMM_AC_VI,
  62. WMM_AC_VI,
  63. WMM_AC_VO,
  64. WMM_AC_VO,
  65. };
  66. void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
  67. {
  68. if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
  69. return;
  70. wmi->ep_id = ep_id;
  71. }
  72. enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
  73. {
  74. return wmi->ep_id;
  75. }
  76. struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
  77. {
  78. struct ath6kl_vif *vif, *found = NULL;
  79. if (WARN_ON(if_idx > (ar->vif_max - 1)))
  80. return NULL;
  81. /* FIXME: Locking */
  82. spin_lock_bh(&ar->list_lock);
  83. list_for_each_entry(vif, &ar->vif_list, list) {
  84. if (vif->fw_vif_idx == if_idx) {
  85. found = vif;
  86. break;
  87. }
  88. }
  89. spin_unlock_bh(&ar->list_lock);
  90. return found;
  91. }
  92. /* Performs DIX to 802.3 encapsulation for transmit packets.
  93. * Assumes the entire DIX header is contigous and that there is
  94. * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
  95. */
  96. int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
  97. {
  98. struct ath6kl_llc_snap_hdr *llc_hdr;
  99. struct ethhdr *eth_hdr;
  100. size_t new_len;
  101. __be16 type;
  102. u8 *datap;
  103. u16 size;
  104. if (WARN_ON(skb == NULL))
  105. return -EINVAL;
  106. size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
  107. if (skb_headroom(skb) < size)
  108. return -ENOMEM;
  109. eth_hdr = (struct ethhdr *) skb->data;
  110. type = eth_hdr->h_proto;
  111. if (!is_ethertype(be16_to_cpu(type))) {
  112. ath6kl_dbg(ATH6KL_DBG_WMI,
  113. "%s: pkt is already in 802.3 format\n", __func__);
  114. return 0;
  115. }
  116. new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
  117. skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
  118. datap = skb->data;
  119. eth_hdr->h_proto = cpu_to_be16(new_len);
  120. memcpy(datap, eth_hdr, sizeof(*eth_hdr));
  121. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
  122. llc_hdr->dsap = 0xAA;
  123. llc_hdr->ssap = 0xAA;
  124. llc_hdr->cntl = 0x03;
  125. llc_hdr->org_code[0] = 0x0;
  126. llc_hdr->org_code[1] = 0x0;
  127. llc_hdr->org_code[2] = 0x0;
  128. llc_hdr->eth_type = type;
  129. return 0;
  130. }
  131. static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
  132. u8 *version, void *tx_meta_info)
  133. {
  134. struct wmi_tx_meta_v1 *v1;
  135. struct wmi_tx_meta_v2 *v2;
  136. if (WARN_ON(skb == NULL || version == NULL))
  137. return -EINVAL;
  138. switch (*version) {
  139. case WMI_META_VERSION_1:
  140. skb_push(skb, WMI_MAX_TX_META_SZ);
  141. v1 = (struct wmi_tx_meta_v1 *) skb->data;
  142. v1->pkt_id = 0;
  143. v1->rate_plcy_id = 0;
  144. *version = WMI_META_VERSION_1;
  145. break;
  146. case WMI_META_VERSION_2:
  147. skb_push(skb, WMI_MAX_TX_META_SZ);
  148. v2 = (struct wmi_tx_meta_v2 *) skb->data;
  149. memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
  150. sizeof(struct wmi_tx_meta_v2));
  151. break;
  152. }
  153. return 0;
  154. }
  155. int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
  156. u8 msg_type, u32 flags,
  157. enum wmi_data_hdr_data_type data_type,
  158. u8 meta_ver, void *tx_meta_info, u8 if_idx)
  159. {
  160. struct wmi_data_hdr *data_hdr;
  161. int ret;
  162. if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
  163. return -EINVAL;
  164. if (tx_meta_info) {
  165. ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
  166. if (ret)
  167. return ret;
  168. }
  169. skb_push(skb, sizeof(struct wmi_data_hdr));
  170. data_hdr = (struct wmi_data_hdr *)skb->data;
  171. memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
  172. data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  173. data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
  174. if (flags & WMI_DATA_HDR_FLAGS_MORE)
  175. data_hdr->info |= WMI_DATA_HDR_MORE;
  176. if (flags & WMI_DATA_HDR_FLAGS_EOSP)
  177. data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
  178. data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
  179. data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  180. return 0;
  181. }
  182. u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
  183. {
  184. struct iphdr *ip_hdr = (struct iphdr *) pkt;
  185. u8 ip_pri;
  186. /*
  187. * Determine IPTOS priority
  188. *
  189. * IP-TOS - 8bits
  190. * : DSCP(6-bits) ECN(2-bits)
  191. * : DSCP - P2 P1 P0 X X X
  192. * where (P2 P1 P0) form 802.1D
  193. */
  194. ip_pri = ip_hdr->tos >> 5;
  195. ip_pri &= 0x7;
  196. if ((layer2_pri & 0x7) > ip_pri)
  197. return (u8) layer2_pri & 0x7;
  198. else
  199. return ip_pri;
  200. }
  201. u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
  202. {
  203. return up_to_ac[user_priority & 0x7];
  204. }
  205. int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
  206. struct sk_buff *skb,
  207. u32 layer2_priority, bool wmm_enabled,
  208. u8 *ac)
  209. {
  210. struct wmi_data_hdr *data_hdr;
  211. struct ath6kl_llc_snap_hdr *llc_hdr;
  212. struct wmi_create_pstream_cmd cmd;
  213. u32 meta_size, hdr_size;
  214. u16 ip_type = IP_ETHERTYPE;
  215. u8 stream_exist, usr_pri;
  216. u8 traffic_class = WMM_AC_BE;
  217. u8 *datap;
  218. if (WARN_ON(skb == NULL))
  219. return -EINVAL;
  220. datap = skb->data;
  221. data_hdr = (struct wmi_data_hdr *) datap;
  222. meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
  223. WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
  224. if (!wmm_enabled) {
  225. /* If WMM is disabled all traffic goes as BE traffic */
  226. usr_pri = 0;
  227. } else {
  228. hdr_size = sizeof(struct ethhdr);
  229. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
  230. sizeof(struct
  231. wmi_data_hdr) +
  232. meta_size + hdr_size);
  233. if (llc_hdr->eth_type == htons(ip_type)) {
  234. /*
  235. * Extract the endpoint info from the TOS field
  236. * in the IP header.
  237. */
  238. usr_pri =
  239. ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
  240. sizeof(struct ath6kl_llc_snap_hdr),
  241. layer2_priority);
  242. } else
  243. usr_pri = layer2_priority & 0x7;
  244. }
  245. /*
  246. * workaround for WMM S5
  247. *
  248. * FIXME: wmi->traffic_class is always 100 so this test doesn't
  249. * make sense
  250. */
  251. if ((wmi->traffic_class == WMM_AC_VI) &&
  252. ((usr_pri == 5) || (usr_pri == 4)))
  253. usr_pri = 1;
  254. /* Convert user priority to traffic class */
  255. traffic_class = up_to_ac[usr_pri & 0x7];
  256. wmi_data_hdr_set_up(data_hdr, usr_pri);
  257. spin_lock_bh(&wmi->lock);
  258. stream_exist = wmi->fat_pipe_exist;
  259. spin_unlock_bh(&wmi->lock);
  260. if (!(stream_exist & (1 << traffic_class))) {
  261. memset(&cmd, 0, sizeof(cmd));
  262. cmd.traffic_class = traffic_class;
  263. cmd.user_pri = usr_pri;
  264. cmd.inactivity_int =
  265. cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
  266. /* Implicit streams are created with TSID 0xFF */
  267. cmd.tsid = WMI_IMPLICIT_PSTREAM;
  268. ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
  269. }
  270. *ac = traffic_class;
  271. return 0;
  272. }
  273. int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
  274. {
  275. struct ieee80211_hdr_3addr *pwh, wh;
  276. struct ath6kl_llc_snap_hdr *llc_hdr;
  277. struct ethhdr eth_hdr;
  278. u32 hdr_size;
  279. u8 *datap;
  280. __le16 sub_type;
  281. if (WARN_ON(skb == NULL))
  282. return -EINVAL;
  283. datap = skb->data;
  284. pwh = (struct ieee80211_hdr_3addr *) datap;
  285. sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  286. memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
  287. /* Strip off the 802.11 header */
  288. if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  289. hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
  290. sizeof(u32));
  291. skb_pull(skb, hdr_size);
  292. } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
  293. skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
  294. datap = skb->data;
  295. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
  296. memset(&eth_hdr, 0, sizeof(eth_hdr));
  297. eth_hdr.h_proto = llc_hdr->eth_type;
  298. switch ((le16_to_cpu(wh.frame_control)) &
  299. (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  300. case 0:
  301. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  302. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  303. break;
  304. case IEEE80211_FCTL_TODS:
  305. memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
  306. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  307. break;
  308. case IEEE80211_FCTL_FROMDS:
  309. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  310. memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
  311. break;
  312. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  313. break;
  314. }
  315. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  316. skb_push(skb, sizeof(eth_hdr));
  317. datap = skb->data;
  318. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  319. return 0;
  320. }
  321. /*
  322. * Performs 802.3 to DIX encapsulation for received packets.
  323. * Assumes the entire 802.3 header is contigous.
  324. */
  325. int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
  326. {
  327. struct ath6kl_llc_snap_hdr *llc_hdr;
  328. struct ethhdr eth_hdr;
  329. u8 *datap;
  330. if (WARN_ON(skb == NULL))
  331. return -EINVAL;
  332. datap = skb->data;
  333. memcpy(&eth_hdr, datap, sizeof(eth_hdr));
  334. llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
  335. eth_hdr.h_proto = llc_hdr->eth_type;
  336. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  337. datap = skb->data;
  338. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  339. return 0;
  340. }
  341. static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
  342. {
  343. struct tx_complete_msg_v1 *msg_v1;
  344. struct wmi_tx_complete_event *evt;
  345. int index;
  346. u16 size;
  347. evt = (struct wmi_tx_complete_event *) datap;
  348. ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
  349. evt->num_msg, evt->msg_len, evt->msg_type);
  350. for (index = 0; index < evt->num_msg; index++) {
  351. size = sizeof(struct wmi_tx_complete_event) +
  352. (index * sizeof(struct tx_complete_msg_v1));
  353. msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
  354. ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
  355. msg_v1->status, msg_v1->pkt_id,
  356. msg_v1->rate_idx, msg_v1->ack_failures);
  357. }
  358. return 0;
  359. }
  360. static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
  361. int len, struct ath6kl_vif *vif)
  362. {
  363. struct wmi_remain_on_chnl_event *ev;
  364. u32 freq;
  365. u32 dur;
  366. struct ieee80211_channel *chan;
  367. struct ath6kl *ar = wmi->parent_dev;
  368. u32 id;
  369. if (len < sizeof(*ev))
  370. return -EINVAL;
  371. ev = (struct wmi_remain_on_chnl_event *) datap;
  372. freq = le32_to_cpu(ev->freq);
  373. dur = le32_to_cpu(ev->duration);
  374. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
  375. freq, dur);
  376. chan = ieee80211_get_channel(ar->wiphy, freq);
  377. if (!chan) {
  378. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
  379. "(freq=%u)\n", freq);
  380. return -EINVAL;
  381. }
  382. id = vif->last_roc_id;
  383. cfg80211_ready_on_channel(vif->ndev, id, chan, NL80211_CHAN_NO_HT,
  384. dur, GFP_ATOMIC);
  385. return 0;
  386. }
  387. static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
  388. u8 *datap, int len,
  389. struct ath6kl_vif *vif)
  390. {
  391. struct wmi_cancel_remain_on_chnl_event *ev;
  392. u32 freq;
  393. u32 dur;
  394. struct ieee80211_channel *chan;
  395. struct ath6kl *ar = wmi->parent_dev;
  396. u32 id;
  397. if (len < sizeof(*ev))
  398. return -EINVAL;
  399. ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
  400. freq = le32_to_cpu(ev->freq);
  401. dur = le32_to_cpu(ev->duration);
  402. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
  403. "status=%u\n", freq, dur, ev->status);
  404. chan = ieee80211_get_channel(ar->wiphy, freq);
  405. if (!chan) {
  406. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
  407. "channel (freq=%u)\n", freq);
  408. return -EINVAL;
  409. }
  410. if (vif->last_cancel_roc_id &&
  411. vif->last_cancel_roc_id + 1 == vif->last_roc_id)
  412. id = vif->last_cancel_roc_id; /* event for cancel command */
  413. else
  414. id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
  415. vif->last_cancel_roc_id = 0;
  416. cfg80211_remain_on_channel_expired(vif->ndev, id, chan,
  417. NL80211_CHAN_NO_HT, GFP_ATOMIC);
  418. return 0;
  419. }
  420. static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
  421. struct ath6kl_vif *vif)
  422. {
  423. struct wmi_tx_status_event *ev;
  424. u32 id;
  425. if (len < sizeof(*ev))
  426. return -EINVAL;
  427. ev = (struct wmi_tx_status_event *) datap;
  428. id = le32_to_cpu(ev->id);
  429. ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
  430. id, ev->ack_status);
  431. if (wmi->last_mgmt_tx_frame) {
  432. cfg80211_mgmt_tx_status(vif->ndev, id,
  433. wmi->last_mgmt_tx_frame,
  434. wmi->last_mgmt_tx_frame_len,
  435. !!ev->ack_status, GFP_ATOMIC);
  436. kfree(wmi->last_mgmt_tx_frame);
  437. wmi->last_mgmt_tx_frame = NULL;
  438. wmi->last_mgmt_tx_frame_len = 0;
  439. }
  440. return 0;
  441. }
  442. static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  443. struct ath6kl_vif *vif)
  444. {
  445. struct wmi_p2p_rx_probe_req_event *ev;
  446. u32 freq;
  447. u16 dlen;
  448. if (len < sizeof(*ev))
  449. return -EINVAL;
  450. ev = (struct wmi_p2p_rx_probe_req_event *) datap;
  451. freq = le32_to_cpu(ev->freq);
  452. dlen = le16_to_cpu(ev->len);
  453. if (datap + len < ev->data + dlen) {
  454. ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
  455. "len=%d dlen=%u\n", len, dlen);
  456. return -EINVAL;
  457. }
  458. ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
  459. "probe_req_report=%d\n",
  460. dlen, freq, vif->probe_req_report);
  461. if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
  462. cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
  463. return 0;
  464. }
  465. static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
  466. {
  467. struct wmi_p2p_capabilities_event *ev;
  468. u16 dlen;
  469. if (len < sizeof(*ev))
  470. return -EINVAL;
  471. ev = (struct wmi_p2p_capabilities_event *) datap;
  472. dlen = le16_to_cpu(ev->len);
  473. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
  474. return 0;
  475. }
  476. static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
  477. struct ath6kl_vif *vif)
  478. {
  479. struct wmi_rx_action_event *ev;
  480. u32 freq;
  481. u16 dlen;
  482. if (len < sizeof(*ev))
  483. return -EINVAL;
  484. ev = (struct wmi_rx_action_event *) datap;
  485. freq = le32_to_cpu(ev->freq);
  486. dlen = le16_to_cpu(ev->len);
  487. if (datap + len < ev->data + dlen) {
  488. ath6kl_err("invalid wmi_rx_action_event: "
  489. "len=%d dlen=%u\n", len, dlen);
  490. return -EINVAL;
  491. }
  492. ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
  493. cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
  494. return 0;
  495. }
  496. static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
  497. {
  498. struct wmi_p2p_info_event *ev;
  499. u32 flags;
  500. u16 dlen;
  501. if (len < sizeof(*ev))
  502. return -EINVAL;
  503. ev = (struct wmi_p2p_info_event *) datap;
  504. flags = le32_to_cpu(ev->info_req_flags);
  505. dlen = le16_to_cpu(ev->len);
  506. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
  507. if (flags & P2P_FLAG_CAPABILITIES_REQ) {
  508. struct wmi_p2p_capabilities *cap;
  509. if (dlen < sizeof(*cap))
  510. return -EINVAL;
  511. cap = (struct wmi_p2p_capabilities *) ev->data;
  512. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
  513. cap->go_power_save);
  514. }
  515. if (flags & P2P_FLAG_MACADDR_REQ) {
  516. struct wmi_p2p_macaddr *mac;
  517. if (dlen < sizeof(*mac))
  518. return -EINVAL;
  519. mac = (struct wmi_p2p_macaddr *) ev->data;
  520. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
  521. mac->mac_addr);
  522. }
  523. if (flags & P2P_FLAG_HMODEL_REQ) {
  524. struct wmi_p2p_hmodel *mod;
  525. if (dlen < sizeof(*mod))
  526. return -EINVAL;
  527. mod = (struct wmi_p2p_hmodel *) ev->data;
  528. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
  529. mod->p2p_model,
  530. mod->p2p_model ? "host" : "firmware");
  531. }
  532. return 0;
  533. }
  534. static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
  535. {
  536. struct sk_buff *skb;
  537. skb = ath6kl_buf_alloc(size);
  538. if (!skb)
  539. return NULL;
  540. skb_put(skb, size);
  541. if (size)
  542. memset(skb->data, 0, size);
  543. return skb;
  544. }
  545. /* Send a "simple" wmi command -- one with no arguments */
  546. static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
  547. enum wmi_cmd_id cmd_id)
  548. {
  549. struct sk_buff *skb;
  550. int ret;
  551. skb = ath6kl_wmi_get_new_buf(0);
  552. if (!skb)
  553. return -ENOMEM;
  554. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
  555. return ret;
  556. }
  557. static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
  558. {
  559. struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
  560. if (len < sizeof(struct wmi_ready_event_2))
  561. return -EINVAL;
  562. ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
  563. le32_to_cpu(ev->sw_version),
  564. le32_to_cpu(ev->abi_version));
  565. return 0;
  566. }
  567. /*
  568. * Mechanism to modify the roaming behavior in the firmware. The lower rssi
  569. * at which the station has to roam can be passed with
  570. * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
  571. * in dBm.
  572. */
  573. int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
  574. {
  575. struct sk_buff *skb;
  576. struct roam_ctrl_cmd *cmd;
  577. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  578. if (!skb)
  579. return -ENOMEM;
  580. cmd = (struct roam_ctrl_cmd *) skb->data;
  581. cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
  582. cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
  583. DEF_SCAN_FOR_ROAM_INTVL);
  584. cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
  585. cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
  586. cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
  587. ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  588. NO_SYNC_WMIFLAG);
  589. return 0;
  590. }
  591. int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
  592. {
  593. struct sk_buff *skb;
  594. struct roam_ctrl_cmd *cmd;
  595. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  596. if (!skb)
  597. return -ENOMEM;
  598. cmd = (struct roam_ctrl_cmd *) skb->data;
  599. memset(cmd, 0, sizeof(*cmd));
  600. memcpy(cmd->info.bssid, bssid, ETH_ALEN);
  601. cmd->roam_ctrl = WMI_FORCE_ROAM;
  602. ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
  603. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  604. NO_SYNC_WMIFLAG);
  605. }
  606. int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
  607. {
  608. struct sk_buff *skb;
  609. struct roam_ctrl_cmd *cmd;
  610. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  611. if (!skb)
  612. return -ENOMEM;
  613. cmd = (struct roam_ctrl_cmd *) skb->data;
  614. memset(cmd, 0, sizeof(*cmd));
  615. cmd->info.roam_mode = mode;
  616. cmd->roam_ctrl = WMI_SET_ROAM_MODE;
  617. ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
  618. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  619. NO_SYNC_WMIFLAG);
  620. }
  621. static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
  622. struct ath6kl_vif *vif)
  623. {
  624. struct wmi_connect_event *ev;
  625. u8 *pie, *peie;
  626. if (len < sizeof(struct wmi_connect_event))
  627. return -EINVAL;
  628. ev = (struct wmi_connect_event *) datap;
  629. if (vif->nw_type == AP_NETWORK) {
  630. /* AP mode start/STA connected event */
  631. struct net_device *dev = vif->ndev;
  632. if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
  633. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
  634. "(AP started)\n",
  635. __func__, le16_to_cpu(ev->u.ap_bss.ch),
  636. ev->u.ap_bss.bssid);
  637. ath6kl_connect_ap_mode_bss(
  638. vif, le16_to_cpu(ev->u.ap_bss.ch));
  639. } else {
  640. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
  641. "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
  642. "(STA connected)\n",
  643. __func__, ev->u.ap_sta.aid,
  644. ev->u.ap_sta.mac_addr,
  645. ev->u.ap_sta.auth,
  646. ev->u.ap_sta.keymgmt,
  647. le16_to_cpu(ev->u.ap_sta.cipher),
  648. ev->u.ap_sta.apsd_info);
  649. ath6kl_connect_ap_mode_sta(
  650. vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
  651. ev->u.ap_sta.keymgmt,
  652. le16_to_cpu(ev->u.ap_sta.cipher),
  653. ev->u.ap_sta.auth, ev->assoc_req_len,
  654. ev->assoc_info + ev->beacon_ie_len,
  655. ev->u.ap_sta.apsd_info);
  656. }
  657. return 0;
  658. }
  659. /* STA/IBSS mode connection event */
  660. ath6kl_dbg(ATH6KL_DBG_WMI,
  661. "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
  662. le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
  663. le16_to_cpu(ev->u.sta.listen_intvl),
  664. le16_to_cpu(ev->u.sta.beacon_intvl),
  665. le32_to_cpu(ev->u.sta.nw_type));
  666. /* Start of assoc rsp IEs */
  667. pie = ev->assoc_info + ev->beacon_ie_len +
  668. ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
  669. /* End of assoc rsp IEs */
  670. peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
  671. ev->assoc_resp_len;
  672. while (pie < peie) {
  673. switch (*pie) {
  674. case WLAN_EID_VENDOR_SPECIFIC:
  675. if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
  676. pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
  677. /* WMM OUT (00:50:F2) */
  678. if (pie[1] > 5
  679. && pie[6] == WMM_PARAM_OUI_SUBTYPE)
  680. wmi->is_wmm_enabled = true;
  681. }
  682. break;
  683. }
  684. if (wmi->is_wmm_enabled)
  685. break;
  686. pie += pie[1] + 2;
  687. }
  688. ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
  689. ev->u.sta.bssid,
  690. le16_to_cpu(ev->u.sta.listen_intvl),
  691. le16_to_cpu(ev->u.sta.beacon_intvl),
  692. le32_to_cpu(ev->u.sta.nw_type),
  693. ev->beacon_ie_len, ev->assoc_req_len,
  694. ev->assoc_resp_len, ev->assoc_info);
  695. return 0;
  696. }
  697. static struct country_code_to_enum_rd *
  698. ath6kl_regd_find_country(u16 countryCode)
  699. {
  700. int i;
  701. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  702. if (allCountries[i].countryCode == countryCode)
  703. return &allCountries[i];
  704. }
  705. return NULL;
  706. }
  707. static struct reg_dmn_pair_mapping *
  708. ath6kl_get_regpair(u16 regdmn)
  709. {
  710. int i;
  711. if (regdmn == NO_ENUMRD)
  712. return NULL;
  713. for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
  714. if (regDomainPairs[i].regDmnEnum == regdmn)
  715. return &regDomainPairs[i];
  716. }
  717. return NULL;
  718. }
  719. static struct country_code_to_enum_rd *
  720. ath6kl_regd_find_country_by_rd(u16 regdmn)
  721. {
  722. int i;
  723. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  724. if (allCountries[i].regDmnEnum == regdmn)
  725. return &allCountries[i];
  726. }
  727. return NULL;
  728. }
  729. static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
  730. {
  731. struct ath6kl_wmi_regdomain *ev;
  732. struct country_code_to_enum_rd *country = NULL;
  733. struct reg_dmn_pair_mapping *regpair = NULL;
  734. char alpha2[2];
  735. u32 reg_code;
  736. ev = (struct ath6kl_wmi_regdomain *) datap;
  737. reg_code = le32_to_cpu(ev->reg_code);
  738. if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
  739. country = ath6kl_regd_find_country((u16) reg_code);
  740. else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
  741. regpair = ath6kl_get_regpair((u16) reg_code);
  742. country = ath6kl_regd_find_country_by_rd((u16) reg_code);
  743. ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
  744. regpair->regDmnEnum);
  745. }
  746. if (country) {
  747. alpha2[0] = country->isoName[0];
  748. alpha2[1] = country->isoName[1];
  749. regulatory_hint(wmi->parent_dev->wiphy, alpha2);
  750. ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
  751. alpha2[0], alpha2[1]);
  752. }
  753. }
  754. static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
  755. struct ath6kl_vif *vif)
  756. {
  757. struct wmi_disconnect_event *ev;
  758. wmi->traffic_class = 100;
  759. if (len < sizeof(struct wmi_disconnect_event))
  760. return -EINVAL;
  761. ev = (struct wmi_disconnect_event *) datap;
  762. ath6kl_dbg(ATH6KL_DBG_WMI,
  763. "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
  764. le16_to_cpu(ev->proto_reason_status), ev->bssid,
  765. ev->disconn_reason, ev->assoc_resp_len);
  766. wmi->is_wmm_enabled = false;
  767. ath6kl_disconnect_event(vif, ev->disconn_reason,
  768. ev->bssid, ev->assoc_resp_len, ev->assoc_info,
  769. le16_to_cpu(ev->proto_reason_status));
  770. return 0;
  771. }
  772. static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
  773. {
  774. struct wmi_peer_node_event *ev;
  775. if (len < sizeof(struct wmi_peer_node_event))
  776. return -EINVAL;
  777. ev = (struct wmi_peer_node_event *) datap;
  778. if (ev->event_code == PEER_NODE_JOIN_EVENT)
  779. ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
  780. ev->peer_mac_addr);
  781. else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
  782. ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
  783. ev->peer_mac_addr);
  784. return 0;
  785. }
  786. static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
  787. struct ath6kl_vif *vif)
  788. {
  789. struct wmi_tkip_micerr_event *ev;
  790. if (len < sizeof(struct wmi_tkip_micerr_event))
  791. return -EINVAL;
  792. ev = (struct wmi_tkip_micerr_event *) datap;
  793. ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
  794. return 0;
  795. }
  796. void ath6kl_wmi_sscan_timer(unsigned long ptr)
  797. {
  798. struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
  799. cfg80211_sched_scan_results(vif->ar->wiphy);
  800. }
  801. static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
  802. struct ath6kl_vif *vif)
  803. {
  804. struct wmi_bss_info_hdr2 *bih;
  805. u8 *buf;
  806. struct ieee80211_channel *channel;
  807. struct ath6kl *ar = wmi->parent_dev;
  808. struct ieee80211_mgmt *mgmt;
  809. struct cfg80211_bss *bss;
  810. if (len <= sizeof(struct wmi_bss_info_hdr2))
  811. return -EINVAL;
  812. bih = (struct wmi_bss_info_hdr2 *) datap;
  813. buf = datap + sizeof(struct wmi_bss_info_hdr2);
  814. len -= sizeof(struct wmi_bss_info_hdr2);
  815. ath6kl_dbg(ATH6KL_DBG_WMI,
  816. "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
  817. "frame_type=%d\n",
  818. bih->ch, bih->snr, bih->snr - 95, bih->bssid,
  819. bih->frame_type);
  820. if (bih->frame_type != BEACON_FTYPE &&
  821. bih->frame_type != PROBERESP_FTYPE)
  822. return 0; /* Only update BSS table for now */
  823. if (bih->frame_type == BEACON_FTYPE &&
  824. test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
  825. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  826. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  827. NONE_BSS_FILTER, 0);
  828. }
  829. channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
  830. if (channel == NULL)
  831. return -EINVAL;
  832. if (len < 8 + 2 + 2)
  833. return -EINVAL;
  834. if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &vif->flags)
  835. && memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
  836. const u8 *tim;
  837. tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
  838. len - 8 - 2 - 2);
  839. if (tim && tim[1] >= 2) {
  840. vif->assoc_bss_dtim_period = tim[3];
  841. set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
  842. }
  843. }
  844. /*
  845. * In theory, use of cfg80211_inform_bss() would be more natural here
  846. * since we do not have the full frame. However, at least for now,
  847. * cfg80211 can only distinguish Beacon and Probe Response frames from
  848. * each other when using cfg80211_inform_bss_frame(), so let's build a
  849. * fake IEEE 802.11 header to be able to take benefit of this.
  850. */
  851. mgmt = kmalloc(24 + len, GFP_ATOMIC);
  852. if (mgmt == NULL)
  853. return -EINVAL;
  854. if (bih->frame_type == BEACON_FTYPE) {
  855. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  856. IEEE80211_STYPE_BEACON);
  857. memset(mgmt->da, 0xff, ETH_ALEN);
  858. } else {
  859. struct net_device *dev = vif->ndev;
  860. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  861. IEEE80211_STYPE_PROBE_RESP);
  862. memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
  863. }
  864. mgmt->duration = cpu_to_le16(0);
  865. memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
  866. memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
  867. mgmt->seq_ctrl = cpu_to_le16(0);
  868. memcpy(&mgmt->u.beacon, buf, len);
  869. bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
  870. 24 + len, (bih->snr - 95) * 100,
  871. GFP_ATOMIC);
  872. kfree(mgmt);
  873. if (bss == NULL)
  874. return -ENOMEM;
  875. cfg80211_put_bss(bss);
  876. /*
  877. * Firmware doesn't return any event when scheduled scan has
  878. * finished, so we need to use a timer to find out when there are
  879. * no more results.
  880. *
  881. * The timer is started from the first bss info received, otherwise
  882. * the timer would not ever fire if the scan interval is short
  883. * enough.
  884. */
  885. if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
  886. !timer_pending(&vif->sched_scan_timer)) {
  887. mod_timer(&vif->sched_scan_timer, jiffies +
  888. msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
  889. }
  890. return 0;
  891. }
  892. /* Inactivity timeout of a fatpipe(pstream) at the target */
  893. static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
  894. int len)
  895. {
  896. struct wmi_pstream_timeout_event *ev;
  897. if (len < sizeof(struct wmi_pstream_timeout_event))
  898. return -EINVAL;
  899. ev = (struct wmi_pstream_timeout_event *) datap;
  900. /*
  901. * When the pstream (fat pipe == AC) timesout, it means there were
  902. * no thinStreams within this pstream & it got implicitly created
  903. * due to data flow on this AC. We start the inactivity timer only
  904. * for implicitly created pstream. Just reset the host state.
  905. */
  906. spin_lock_bh(&wmi->lock);
  907. wmi->stream_exist_for_ac[ev->traffic_class] = 0;
  908. wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
  909. spin_unlock_bh(&wmi->lock);
  910. /* Indicate inactivity to driver layer for this fatpipe (pstream) */
  911. ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
  912. return 0;
  913. }
  914. static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
  915. {
  916. struct wmi_bit_rate_reply *reply;
  917. s32 rate;
  918. u32 sgi, index;
  919. if (len < sizeof(struct wmi_bit_rate_reply))
  920. return -EINVAL;
  921. reply = (struct wmi_bit_rate_reply *) datap;
  922. ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
  923. if (reply->rate_index == (s8) RATE_AUTO) {
  924. rate = RATE_AUTO;
  925. } else {
  926. index = reply->rate_index & 0x7f;
  927. sgi = (reply->rate_index & 0x80) ? 1 : 0;
  928. rate = wmi_rate_tbl[index][sgi];
  929. }
  930. ath6kl_wakeup_event(wmi->parent_dev);
  931. return 0;
  932. }
  933. static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
  934. {
  935. ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
  936. return 0;
  937. }
  938. static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
  939. {
  940. if (len < sizeof(struct wmi_fix_rates_reply))
  941. return -EINVAL;
  942. ath6kl_wakeup_event(wmi->parent_dev);
  943. return 0;
  944. }
  945. static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
  946. {
  947. if (len < sizeof(struct wmi_channel_list_reply))
  948. return -EINVAL;
  949. ath6kl_wakeup_event(wmi->parent_dev);
  950. return 0;
  951. }
  952. static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
  953. {
  954. struct wmi_tx_pwr_reply *reply;
  955. if (len < sizeof(struct wmi_tx_pwr_reply))
  956. return -EINVAL;
  957. reply = (struct wmi_tx_pwr_reply *) datap;
  958. ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
  959. return 0;
  960. }
  961. static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
  962. {
  963. if (len < sizeof(struct wmi_get_keepalive_cmd))
  964. return -EINVAL;
  965. ath6kl_wakeup_event(wmi->parent_dev);
  966. return 0;
  967. }
  968. static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
  969. struct ath6kl_vif *vif)
  970. {
  971. struct wmi_scan_complete_event *ev;
  972. ev = (struct wmi_scan_complete_event *) datap;
  973. ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
  974. wmi->is_probe_ssid = false;
  975. return 0;
  976. }
  977. static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
  978. int len, struct ath6kl_vif *vif)
  979. {
  980. struct wmi_neighbor_report_event *ev;
  981. u8 i;
  982. if (len < sizeof(*ev))
  983. return -EINVAL;
  984. ev = (struct wmi_neighbor_report_event *) datap;
  985. if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
  986. > len) {
  987. ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
  988. "(num=%d len=%d)\n", ev->num_neighbors, len);
  989. return -EINVAL;
  990. }
  991. for (i = 0; i < ev->num_neighbors; i++) {
  992. ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
  993. i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
  994. ev->neighbor[i].bss_flags);
  995. cfg80211_pmksa_candidate_notify(vif->ndev, i,
  996. ev->neighbor[i].bssid,
  997. !!(ev->neighbor[i].bss_flags &
  998. WMI_PREAUTH_CAPABLE_BSS),
  999. GFP_ATOMIC);
  1000. }
  1001. return 0;
  1002. }
  1003. /*
  1004. * Target is reporting a programming error. This is for
  1005. * developer aid only. Target only checks a few common violations
  1006. * and it is responsibility of host to do all error checking.
  1007. * Behavior of target after wmi error event is undefined.
  1008. * A reset is recommended.
  1009. */
  1010. static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
  1011. {
  1012. const char *type = "unknown error";
  1013. struct wmi_cmd_error_event *ev;
  1014. ev = (struct wmi_cmd_error_event *) datap;
  1015. switch (ev->err_code) {
  1016. case INVALID_PARAM:
  1017. type = "invalid parameter";
  1018. break;
  1019. case ILLEGAL_STATE:
  1020. type = "invalid state";
  1021. break;
  1022. case INTERNAL_ERROR:
  1023. type = "internal error";
  1024. break;
  1025. }
  1026. ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
  1027. ev->cmd_id, type);
  1028. return 0;
  1029. }
  1030. static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
  1031. struct ath6kl_vif *vif)
  1032. {
  1033. ath6kl_tgt_stats_event(vif, datap, len);
  1034. return 0;
  1035. }
  1036. static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
  1037. struct sq_threshold_params *sq_thresh,
  1038. u32 size)
  1039. {
  1040. u32 index;
  1041. u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
  1042. /* The list is already in sorted order. Get the next lower value */
  1043. for (index = 0; index < size; index++) {
  1044. if (rssi < sq_thresh->upper_threshold[index]) {
  1045. threshold = (u8) sq_thresh->upper_threshold[index];
  1046. break;
  1047. }
  1048. }
  1049. return threshold;
  1050. }
  1051. static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
  1052. struct sq_threshold_params *sq_thresh,
  1053. u32 size)
  1054. {
  1055. u32 index;
  1056. u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
  1057. /* The list is already in sorted order. Get the next lower value */
  1058. for (index = 0; index < size; index++) {
  1059. if (rssi > sq_thresh->lower_threshold[index]) {
  1060. threshold = (u8) sq_thresh->lower_threshold[index];
  1061. break;
  1062. }
  1063. }
  1064. return threshold;
  1065. }
  1066. static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
  1067. struct wmi_rssi_threshold_params_cmd *rssi_cmd)
  1068. {
  1069. struct sk_buff *skb;
  1070. struct wmi_rssi_threshold_params_cmd *cmd;
  1071. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1072. if (!skb)
  1073. return -ENOMEM;
  1074. cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
  1075. memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
  1076. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
  1077. NO_SYNC_WMIFLAG);
  1078. }
  1079. static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1080. int len)
  1081. {
  1082. struct wmi_rssi_threshold_event *reply;
  1083. struct wmi_rssi_threshold_params_cmd cmd;
  1084. struct sq_threshold_params *sq_thresh;
  1085. enum wmi_rssi_threshold_val new_threshold;
  1086. u8 upper_rssi_threshold, lower_rssi_threshold;
  1087. s16 rssi;
  1088. int ret;
  1089. if (len < sizeof(struct wmi_rssi_threshold_event))
  1090. return -EINVAL;
  1091. reply = (struct wmi_rssi_threshold_event *) datap;
  1092. new_threshold = (enum wmi_rssi_threshold_val) reply->range;
  1093. rssi = a_sle16_to_cpu(reply->rssi);
  1094. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
  1095. /*
  1096. * Identify the threshold breached and communicate that to the app.
  1097. * After that install a new set of thresholds based on the signal
  1098. * quality reported by the target
  1099. */
  1100. if (new_threshold) {
  1101. /* Upper threshold breached */
  1102. if (rssi < sq_thresh->upper_threshold[0]) {
  1103. ath6kl_dbg(ATH6KL_DBG_WMI,
  1104. "spurious upper rssi threshold event: %d\n",
  1105. rssi);
  1106. } else if ((rssi < sq_thresh->upper_threshold[1]) &&
  1107. (rssi >= sq_thresh->upper_threshold[0])) {
  1108. new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
  1109. } else if ((rssi < sq_thresh->upper_threshold[2]) &&
  1110. (rssi >= sq_thresh->upper_threshold[1])) {
  1111. new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
  1112. } else if ((rssi < sq_thresh->upper_threshold[3]) &&
  1113. (rssi >= sq_thresh->upper_threshold[2])) {
  1114. new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
  1115. } else if ((rssi < sq_thresh->upper_threshold[4]) &&
  1116. (rssi >= sq_thresh->upper_threshold[3])) {
  1117. new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
  1118. } else if ((rssi < sq_thresh->upper_threshold[5]) &&
  1119. (rssi >= sq_thresh->upper_threshold[4])) {
  1120. new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
  1121. } else if (rssi >= sq_thresh->upper_threshold[5]) {
  1122. new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
  1123. }
  1124. } else {
  1125. /* Lower threshold breached */
  1126. if (rssi > sq_thresh->lower_threshold[0]) {
  1127. ath6kl_dbg(ATH6KL_DBG_WMI,
  1128. "spurious lower rssi threshold event: %d %d\n",
  1129. rssi, sq_thresh->lower_threshold[0]);
  1130. } else if ((rssi > sq_thresh->lower_threshold[1]) &&
  1131. (rssi <= sq_thresh->lower_threshold[0])) {
  1132. new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
  1133. } else if ((rssi > sq_thresh->lower_threshold[2]) &&
  1134. (rssi <= sq_thresh->lower_threshold[1])) {
  1135. new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
  1136. } else if ((rssi > sq_thresh->lower_threshold[3]) &&
  1137. (rssi <= sq_thresh->lower_threshold[2])) {
  1138. new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
  1139. } else if ((rssi > sq_thresh->lower_threshold[4]) &&
  1140. (rssi <= sq_thresh->lower_threshold[3])) {
  1141. new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
  1142. } else if ((rssi > sq_thresh->lower_threshold[5]) &&
  1143. (rssi <= sq_thresh->lower_threshold[4])) {
  1144. new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
  1145. } else if (rssi <= sq_thresh->lower_threshold[5]) {
  1146. new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
  1147. }
  1148. }
  1149. /* Calculate and install the next set of thresholds */
  1150. lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
  1151. sq_thresh->lower_threshold_valid_count);
  1152. upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
  1153. sq_thresh->upper_threshold_valid_count);
  1154. /* Issue a wmi command to install the thresholds */
  1155. cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
  1156. cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
  1157. cmd.weight = sq_thresh->weight;
  1158. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1159. ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
  1160. if (ret) {
  1161. ath6kl_err("unable to configure rssi thresholds\n");
  1162. return -EIO;
  1163. }
  1164. return 0;
  1165. }
  1166. static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
  1167. struct ath6kl_vif *vif)
  1168. {
  1169. struct wmi_cac_event *reply;
  1170. struct ieee80211_tspec_ie *ts;
  1171. u16 active_tsids, tsinfo;
  1172. u8 tsid, index;
  1173. u8 ts_id;
  1174. if (len < sizeof(struct wmi_cac_event))
  1175. return -EINVAL;
  1176. reply = (struct wmi_cac_event *) datap;
  1177. if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
  1178. (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
  1179. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1180. tsinfo = le16_to_cpu(ts->tsinfo);
  1181. tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1182. IEEE80211_WMM_IE_TSPEC_TID_MASK;
  1183. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1184. reply->ac, tsid);
  1185. } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
  1186. /*
  1187. * Following assumes that there is only one outstanding
  1188. * ADDTS request when this event is received
  1189. */
  1190. spin_lock_bh(&wmi->lock);
  1191. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1192. spin_unlock_bh(&wmi->lock);
  1193. for (index = 0; index < sizeof(active_tsids) * 8; index++) {
  1194. if ((active_tsids >> index) & 1)
  1195. break;
  1196. }
  1197. if (index < (sizeof(active_tsids) * 8))
  1198. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1199. reply->ac, index);
  1200. }
  1201. /*
  1202. * Clear active tsids and Add missing handling
  1203. * for delete qos stream from AP
  1204. */
  1205. else if (reply->cac_indication == CAC_INDICATION_DELETE) {
  1206. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1207. tsinfo = le16_to_cpu(ts->tsinfo);
  1208. ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1209. IEEE80211_WMM_IE_TSPEC_TID_MASK);
  1210. spin_lock_bh(&wmi->lock);
  1211. wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
  1212. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1213. spin_unlock_bh(&wmi->lock);
  1214. /* Indicate stream inactivity to driver layer only if all tsids
  1215. * within this AC are deleted.
  1216. */
  1217. if (!active_tsids) {
  1218. ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
  1219. false);
  1220. wmi->fat_pipe_exist &= ~(1 << reply->ac);
  1221. }
  1222. }
  1223. return 0;
  1224. }
  1225. static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
  1226. struct wmi_snr_threshold_params_cmd *snr_cmd)
  1227. {
  1228. struct sk_buff *skb;
  1229. struct wmi_snr_threshold_params_cmd *cmd;
  1230. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1231. if (!skb)
  1232. return -ENOMEM;
  1233. cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
  1234. memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
  1235. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
  1236. NO_SYNC_WMIFLAG);
  1237. }
  1238. static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1239. int len)
  1240. {
  1241. struct wmi_snr_threshold_event *reply;
  1242. struct sq_threshold_params *sq_thresh;
  1243. struct wmi_snr_threshold_params_cmd cmd;
  1244. enum wmi_snr_threshold_val new_threshold;
  1245. u8 upper_snr_threshold, lower_snr_threshold;
  1246. s16 snr;
  1247. int ret;
  1248. if (len < sizeof(struct wmi_snr_threshold_event))
  1249. return -EINVAL;
  1250. reply = (struct wmi_snr_threshold_event *) datap;
  1251. new_threshold = (enum wmi_snr_threshold_val) reply->range;
  1252. snr = reply->snr;
  1253. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
  1254. /*
  1255. * Identify the threshold breached and communicate that to the app.
  1256. * After that install a new set of thresholds based on the signal
  1257. * quality reported by the target.
  1258. */
  1259. if (new_threshold) {
  1260. /* Upper threshold breached */
  1261. if (snr < sq_thresh->upper_threshold[0]) {
  1262. ath6kl_dbg(ATH6KL_DBG_WMI,
  1263. "spurious upper snr threshold event: %d\n",
  1264. snr);
  1265. } else if ((snr < sq_thresh->upper_threshold[1]) &&
  1266. (snr >= sq_thresh->upper_threshold[0])) {
  1267. new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
  1268. } else if ((snr < sq_thresh->upper_threshold[2]) &&
  1269. (snr >= sq_thresh->upper_threshold[1])) {
  1270. new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
  1271. } else if ((snr < sq_thresh->upper_threshold[3]) &&
  1272. (snr >= sq_thresh->upper_threshold[2])) {
  1273. new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
  1274. } else if (snr >= sq_thresh->upper_threshold[3]) {
  1275. new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
  1276. }
  1277. } else {
  1278. /* Lower threshold breached */
  1279. if (snr > sq_thresh->lower_threshold[0]) {
  1280. ath6kl_dbg(ATH6KL_DBG_WMI,
  1281. "spurious lower snr threshold event: %d\n",
  1282. sq_thresh->lower_threshold[0]);
  1283. } else if ((snr > sq_thresh->lower_threshold[1]) &&
  1284. (snr <= sq_thresh->lower_threshold[0])) {
  1285. new_threshold = WMI_SNR_THRESHOLD4_BELOW;
  1286. } else if ((snr > sq_thresh->lower_threshold[2]) &&
  1287. (snr <= sq_thresh->lower_threshold[1])) {
  1288. new_threshold = WMI_SNR_THRESHOLD3_BELOW;
  1289. } else if ((snr > sq_thresh->lower_threshold[3]) &&
  1290. (snr <= sq_thresh->lower_threshold[2])) {
  1291. new_threshold = WMI_SNR_THRESHOLD2_BELOW;
  1292. } else if (snr <= sq_thresh->lower_threshold[3]) {
  1293. new_threshold = WMI_SNR_THRESHOLD1_BELOW;
  1294. }
  1295. }
  1296. /* Calculate and install the next set of thresholds */
  1297. lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
  1298. sq_thresh->lower_threshold_valid_count);
  1299. upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
  1300. sq_thresh->upper_threshold_valid_count);
  1301. /* Issue a wmi command to install the thresholds */
  1302. cmd.thresh_above1_val = upper_snr_threshold;
  1303. cmd.thresh_below1_val = lower_snr_threshold;
  1304. cmd.weight = sq_thresh->weight;
  1305. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1306. ath6kl_dbg(ATH6KL_DBG_WMI,
  1307. "snr: %d, threshold: %d, lower: %d, upper: %d\n",
  1308. snr, new_threshold,
  1309. lower_snr_threshold, upper_snr_threshold);
  1310. ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
  1311. if (ret) {
  1312. ath6kl_err("unable to configure snr threshold\n");
  1313. return -EIO;
  1314. }
  1315. return 0;
  1316. }
  1317. static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
  1318. {
  1319. u16 ap_info_entry_size;
  1320. struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
  1321. struct wmi_ap_info_v1 *ap_info_v1;
  1322. u8 index;
  1323. if (len < sizeof(struct wmi_aplist_event) ||
  1324. ev->ap_list_ver != APLIST_VER1)
  1325. return -EINVAL;
  1326. ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
  1327. ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
  1328. ath6kl_dbg(ATH6KL_DBG_WMI,
  1329. "number of APs in aplist event: %d\n", ev->num_ap);
  1330. if (len < (int) (sizeof(struct wmi_aplist_event) +
  1331. (ev->num_ap - 1) * ap_info_entry_size))
  1332. return -EINVAL;
  1333. /* AP list version 1 contents */
  1334. for (index = 0; index < ev->num_ap; index++) {
  1335. ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
  1336. index, ap_info_v1->bssid, ap_info_v1->channel);
  1337. ap_info_v1++;
  1338. }
  1339. return 0;
  1340. }
  1341. int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
  1342. enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
  1343. {
  1344. struct wmi_cmd_hdr *cmd_hdr;
  1345. enum htc_endpoint_id ep_id = wmi->ep_id;
  1346. int ret;
  1347. u16 info1;
  1348. if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
  1349. return -EINVAL;
  1350. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
  1351. cmd_id, skb->len, sync_flag);
  1352. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
  1353. skb->data, skb->len);
  1354. if (sync_flag >= END_WMIFLAG) {
  1355. dev_kfree_skb(skb);
  1356. return -EINVAL;
  1357. }
  1358. if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
  1359. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1360. /*
  1361. * Make sure all data currently queued is transmitted before
  1362. * the cmd execution. Establish a new sync point.
  1363. */
  1364. ath6kl_wmi_sync_point(wmi, if_idx);
  1365. }
  1366. skb_push(skb, sizeof(struct wmi_cmd_hdr));
  1367. cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
  1368. cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
  1369. info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
  1370. cmd_hdr->info1 = cpu_to_le16(info1);
  1371. /* Only for OPT_TX_CMD, use BE endpoint. */
  1372. if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
  1373. ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
  1374. false, false, 0, NULL, if_idx);
  1375. if (ret) {
  1376. dev_kfree_skb(skb);
  1377. return ret;
  1378. }
  1379. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
  1380. }
  1381. ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1382. if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
  1383. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1384. /*
  1385. * Make sure all new data queued waits for the command to
  1386. * execute. Establish a new sync point.
  1387. */
  1388. ath6kl_wmi_sync_point(wmi, if_idx);
  1389. }
  1390. return 0;
  1391. }
  1392. int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
  1393. enum network_type nw_type,
  1394. enum dot11_auth_mode dot11_auth_mode,
  1395. enum auth_mode auth_mode,
  1396. enum crypto_type pairwise_crypto,
  1397. u8 pairwise_crypto_len,
  1398. enum crypto_type group_crypto,
  1399. u8 group_crypto_len, int ssid_len, u8 *ssid,
  1400. u8 *bssid, u16 channel, u32 ctrl_flags,
  1401. u8 nw_subtype)
  1402. {
  1403. struct sk_buff *skb;
  1404. struct wmi_connect_cmd *cc;
  1405. int ret;
  1406. ath6kl_dbg(ATH6KL_DBG_WMI,
  1407. "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
  1408. "type %d dot11_auth %d auth %d pairwise %d group %d\n",
  1409. bssid, channel, ctrl_flags, ssid_len, nw_type,
  1410. dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
  1411. ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
  1412. wmi->traffic_class = 100;
  1413. if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
  1414. return -EINVAL;
  1415. if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
  1416. return -EINVAL;
  1417. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
  1418. if (!skb)
  1419. return -ENOMEM;
  1420. cc = (struct wmi_connect_cmd *) skb->data;
  1421. if (ssid_len)
  1422. memcpy(cc->ssid, ssid, ssid_len);
  1423. cc->ssid_len = ssid_len;
  1424. cc->nw_type = nw_type;
  1425. cc->dot11_auth_mode = dot11_auth_mode;
  1426. cc->auth_mode = auth_mode;
  1427. cc->prwise_crypto_type = pairwise_crypto;
  1428. cc->prwise_crypto_len = pairwise_crypto_len;
  1429. cc->grp_crypto_type = group_crypto;
  1430. cc->grp_crypto_len = group_crypto_len;
  1431. cc->ch = cpu_to_le16(channel);
  1432. cc->ctrl_flags = cpu_to_le32(ctrl_flags);
  1433. cc->nw_subtype = nw_subtype;
  1434. if (bssid != NULL)
  1435. memcpy(cc->bssid, bssid, ETH_ALEN);
  1436. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
  1437. NO_SYNC_WMIFLAG);
  1438. return ret;
  1439. }
  1440. int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
  1441. u16 channel)
  1442. {
  1443. struct sk_buff *skb;
  1444. struct wmi_reconnect_cmd *cc;
  1445. int ret;
  1446. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
  1447. bssid, channel);
  1448. wmi->traffic_class = 100;
  1449. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
  1450. if (!skb)
  1451. return -ENOMEM;
  1452. cc = (struct wmi_reconnect_cmd *) skb->data;
  1453. cc->channel = cpu_to_le16(channel);
  1454. if (bssid != NULL)
  1455. memcpy(cc->bssid, bssid, ETH_ALEN);
  1456. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
  1457. NO_SYNC_WMIFLAG);
  1458. return ret;
  1459. }
  1460. int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
  1461. {
  1462. int ret;
  1463. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
  1464. wmi->traffic_class = 100;
  1465. /* Disconnect command does not need to do a SYNC before. */
  1466. ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
  1467. return ret;
  1468. }
  1469. int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
  1470. enum wmi_scan_type scan_type,
  1471. u32 force_fgscan, u32 is_legacy,
  1472. u32 home_dwell_time, u32 force_scan_interval,
  1473. s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
  1474. {
  1475. struct sk_buff *skb;
  1476. struct wmi_begin_scan_cmd *sc;
  1477. s8 size;
  1478. int i, band, ret;
  1479. struct ath6kl *ar = wmi->parent_dev;
  1480. int num_rates;
  1481. size = sizeof(struct wmi_begin_scan_cmd);
  1482. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1483. return -EINVAL;
  1484. if (num_chan > WMI_MAX_CHANNELS)
  1485. return -EINVAL;
  1486. if (num_chan)
  1487. size += sizeof(u16) * (num_chan - 1);
  1488. skb = ath6kl_wmi_get_new_buf(size);
  1489. if (!skb)
  1490. return -ENOMEM;
  1491. sc = (struct wmi_begin_scan_cmd *) skb->data;
  1492. sc->scan_type = scan_type;
  1493. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1494. sc->is_legacy = cpu_to_le32(is_legacy);
  1495. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1496. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1497. sc->no_cck = cpu_to_le32(no_cck);
  1498. sc->num_ch = num_chan;
  1499. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1500. struct ieee80211_supported_band *sband =
  1501. ar->wiphy->bands[band];
  1502. u32 ratemask = rates[band];
  1503. u8 *supp_rates = sc->supp_rates[band].rates;
  1504. num_rates = 0;
  1505. for (i = 0; i < sband->n_bitrates; i++) {
  1506. if ((BIT(i) & ratemask) == 0)
  1507. continue; /* skip rate */
  1508. supp_rates[num_rates++] =
  1509. (u8) (sband->bitrates[i].bitrate / 5);
  1510. }
  1511. sc->supp_rates[band].nrates = num_rates;
  1512. }
  1513. for (i = 0; i < num_chan; i++)
  1514. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1515. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
  1516. NO_SYNC_WMIFLAG);
  1517. return ret;
  1518. }
  1519. /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
  1520. * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
  1521. * mgmt operations using station interface.
  1522. */
  1523. int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
  1524. enum wmi_scan_type scan_type,
  1525. u32 force_fgscan, u32 is_legacy,
  1526. u32 home_dwell_time, u32 force_scan_interval,
  1527. s8 num_chan, u16 *ch_list)
  1528. {
  1529. struct sk_buff *skb;
  1530. struct wmi_start_scan_cmd *sc;
  1531. s8 size;
  1532. int i, ret;
  1533. size = sizeof(struct wmi_start_scan_cmd);
  1534. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1535. return -EINVAL;
  1536. if (num_chan > WMI_MAX_CHANNELS)
  1537. return -EINVAL;
  1538. if (num_chan)
  1539. size += sizeof(u16) * (num_chan - 1);
  1540. skb = ath6kl_wmi_get_new_buf(size);
  1541. if (!skb)
  1542. return -ENOMEM;
  1543. sc = (struct wmi_start_scan_cmd *) skb->data;
  1544. sc->scan_type = scan_type;
  1545. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1546. sc->is_legacy = cpu_to_le32(is_legacy);
  1547. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1548. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1549. sc->num_ch = num_chan;
  1550. for (i = 0; i < num_chan; i++)
  1551. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1552. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
  1553. NO_SYNC_WMIFLAG);
  1554. return ret;
  1555. }
  1556. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
  1557. u16 fg_start_sec,
  1558. u16 fg_end_sec, u16 bg_sec,
  1559. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1560. u16 pas_chdw_msec, u8 short_scan_ratio,
  1561. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1562. u16 maxact_scan_per_ssid)
  1563. {
  1564. struct sk_buff *skb;
  1565. struct wmi_scan_params_cmd *sc;
  1566. int ret;
  1567. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1568. if (!skb)
  1569. return -ENOMEM;
  1570. sc = (struct wmi_scan_params_cmd *) skb->data;
  1571. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1572. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1573. sc->bg_period = cpu_to_le16(bg_sec);
  1574. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1575. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1576. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1577. sc->short_scan_ratio = short_scan_ratio;
  1578. sc->scan_ctrl_flags = scan_ctrl_flag;
  1579. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1580. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1581. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1582. NO_SYNC_WMIFLAG);
  1583. return ret;
  1584. }
  1585. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
  1586. {
  1587. struct sk_buff *skb;
  1588. struct wmi_bss_filter_cmd *cmd;
  1589. int ret;
  1590. if (filter >= LAST_BSS_FILTER)
  1591. return -EINVAL;
  1592. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1593. if (!skb)
  1594. return -ENOMEM;
  1595. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1596. cmd->bss_filter = filter;
  1597. cmd->ie_mask = cpu_to_le32(ie_mask);
  1598. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
  1599. NO_SYNC_WMIFLAG);
  1600. return ret;
  1601. }
  1602. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
  1603. u8 ssid_len, u8 *ssid)
  1604. {
  1605. struct sk_buff *skb;
  1606. struct wmi_probed_ssid_cmd *cmd;
  1607. int ret;
  1608. if (index > MAX_PROBED_SSID_INDEX)
  1609. return -EINVAL;
  1610. if (ssid_len > sizeof(cmd->ssid))
  1611. return -EINVAL;
  1612. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1613. return -EINVAL;
  1614. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1615. return -EINVAL;
  1616. if (flag & SPECIFIC_SSID_FLAG)
  1617. wmi->is_probe_ssid = true;
  1618. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1619. if (!skb)
  1620. return -ENOMEM;
  1621. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1622. cmd->entry_index = index;
  1623. cmd->flag = flag;
  1624. cmd->ssid_len = ssid_len;
  1625. memcpy(cmd->ssid, ssid, ssid_len);
  1626. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
  1627. NO_SYNC_WMIFLAG);
  1628. return ret;
  1629. }
  1630. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
  1631. u16 listen_interval,
  1632. u16 listen_beacons)
  1633. {
  1634. struct sk_buff *skb;
  1635. struct wmi_listen_int_cmd *cmd;
  1636. int ret;
  1637. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1638. if (!skb)
  1639. return -ENOMEM;
  1640. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1641. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1642. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1643. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
  1644. NO_SYNC_WMIFLAG);
  1645. return ret;
  1646. }
  1647. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
  1648. {
  1649. struct sk_buff *skb;
  1650. struct wmi_power_mode_cmd *cmd;
  1651. int ret;
  1652. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1653. if (!skb)
  1654. return -ENOMEM;
  1655. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1656. cmd->pwr_mode = pwr_mode;
  1657. wmi->pwr_mode = pwr_mode;
  1658. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
  1659. NO_SYNC_WMIFLAG);
  1660. return ret;
  1661. }
  1662. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
  1663. u16 ps_poll_num, u16 dtim_policy,
  1664. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1665. u16 ps_fail_event_policy)
  1666. {
  1667. struct sk_buff *skb;
  1668. struct wmi_power_params_cmd *pm;
  1669. int ret;
  1670. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1671. if (!skb)
  1672. return -ENOMEM;
  1673. pm = (struct wmi_power_params_cmd *)skb->data;
  1674. pm->idle_period = cpu_to_le16(idle_period);
  1675. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1676. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1677. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1678. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1679. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1680. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
  1681. NO_SYNC_WMIFLAG);
  1682. return ret;
  1683. }
  1684. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
  1685. {
  1686. struct sk_buff *skb;
  1687. struct wmi_disc_timeout_cmd *cmd;
  1688. int ret;
  1689. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1690. if (!skb)
  1691. return -ENOMEM;
  1692. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1693. cmd->discon_timeout = timeout;
  1694. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1695. NO_SYNC_WMIFLAG);
  1696. if (ret == 0)
  1697. ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
  1698. return ret;
  1699. }
  1700. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
  1701. enum crypto_type key_type,
  1702. u8 key_usage, u8 key_len,
  1703. u8 *key_rsc, unsigned int key_rsc_len,
  1704. u8 *key_material,
  1705. u8 key_op_ctrl, u8 *mac_addr,
  1706. enum wmi_sync_flag sync_flag)
  1707. {
  1708. struct sk_buff *skb;
  1709. struct wmi_add_cipher_key_cmd *cmd;
  1710. int ret;
  1711. ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
  1712. "key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1713. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1714. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1715. (key_material == NULL) || key_rsc_len > 8)
  1716. return -EINVAL;
  1717. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1718. return -EINVAL;
  1719. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1720. if (!skb)
  1721. return -ENOMEM;
  1722. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1723. cmd->key_index = key_index;
  1724. cmd->key_type = key_type;
  1725. cmd->key_usage = key_usage;
  1726. cmd->key_len = key_len;
  1727. memcpy(cmd->key, key_material, key_len);
  1728. if (key_rsc != NULL)
  1729. memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
  1730. cmd->key_op_ctrl = key_op_ctrl;
  1731. if (mac_addr)
  1732. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1733. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1734. sync_flag);
  1735. return ret;
  1736. }
  1737. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
  1738. {
  1739. struct sk_buff *skb;
  1740. struct wmi_add_krk_cmd *cmd;
  1741. int ret;
  1742. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1743. if (!skb)
  1744. return -ENOMEM;
  1745. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1746. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1747. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
  1748. NO_SYNC_WMIFLAG);
  1749. return ret;
  1750. }
  1751. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
  1752. {
  1753. struct sk_buff *skb;
  1754. struct wmi_delete_cipher_key_cmd *cmd;
  1755. int ret;
  1756. if (key_index > WMI_MAX_KEY_INDEX)
  1757. return -EINVAL;
  1758. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1759. if (!skb)
  1760. return -ENOMEM;
  1761. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1762. cmd->key_index = key_index;
  1763. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1764. NO_SYNC_WMIFLAG);
  1765. return ret;
  1766. }
  1767. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
  1768. const u8 *pmkid, bool set)
  1769. {
  1770. struct sk_buff *skb;
  1771. struct wmi_setpmkid_cmd *cmd;
  1772. int ret;
  1773. if (bssid == NULL)
  1774. return -EINVAL;
  1775. if (set && pmkid == NULL)
  1776. return -EINVAL;
  1777. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1778. if (!skb)
  1779. return -ENOMEM;
  1780. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1781. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1782. if (set) {
  1783. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1784. cmd->enable = PMKID_ENABLE;
  1785. } else {
  1786. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1787. cmd->enable = PMKID_DISABLE;
  1788. }
  1789. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
  1790. NO_SYNC_WMIFLAG);
  1791. return ret;
  1792. }
  1793. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1794. enum htc_endpoint_id ep_id, u8 if_idx)
  1795. {
  1796. struct wmi_data_hdr *data_hdr;
  1797. int ret;
  1798. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
  1799. return -EINVAL;
  1800. skb_push(skb, sizeof(struct wmi_data_hdr));
  1801. data_hdr = (struct wmi_data_hdr *) skb->data;
  1802. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1803. data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  1804. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1805. return ret;
  1806. }
  1807. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
  1808. {
  1809. struct sk_buff *skb;
  1810. struct wmi_sync_cmd *cmd;
  1811. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1812. enum htc_endpoint_id ep_id;
  1813. u8 index, num_pri_streams = 0;
  1814. int ret = 0;
  1815. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  1816. spin_lock_bh(&wmi->lock);
  1817. for (index = 0; index < WMM_NUM_AC; index++) {
  1818. if (wmi->fat_pipe_exist & (1 << index)) {
  1819. num_pri_streams++;
  1820. data_sync_bufs[num_pri_streams - 1].traffic_class =
  1821. index;
  1822. }
  1823. }
  1824. spin_unlock_bh(&wmi->lock);
  1825. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1826. if (!skb) {
  1827. ret = -ENOMEM;
  1828. goto free_skb;
  1829. }
  1830. cmd = (struct wmi_sync_cmd *) skb->data;
  1831. /*
  1832. * In the SYNC cmd sent on the control Ep, send a bitmap
  1833. * of the data eps on which the Data Sync will be sent
  1834. */
  1835. cmd->data_sync_map = wmi->fat_pipe_exist;
  1836. for (index = 0; index < num_pri_streams; index++) {
  1837. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  1838. if (data_sync_bufs[index].skb == NULL) {
  1839. ret = -ENOMEM;
  1840. break;
  1841. }
  1842. }
  1843. /*
  1844. * If buffer allocation for any of the dataSync fails,
  1845. * then do not send the Synchronize cmd on the control ep
  1846. */
  1847. if (ret)
  1848. goto free_skb;
  1849. /*
  1850. * Send sync cmd followed by sync data messages on all
  1851. * endpoints being used
  1852. */
  1853. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
  1854. NO_SYNC_WMIFLAG);
  1855. if (ret)
  1856. goto free_skb;
  1857. /* cmd buffer sent, we no longer own it */
  1858. skb = NULL;
  1859. for (index = 0; index < num_pri_streams; index++) {
  1860. if (WARN_ON(!data_sync_bufs[index].skb))
  1861. break;
  1862. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  1863. data_sync_bufs[index].
  1864. traffic_class);
  1865. ret =
  1866. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  1867. ep_id, if_idx);
  1868. if (ret)
  1869. break;
  1870. data_sync_bufs[index].skb = NULL;
  1871. }
  1872. free_skb:
  1873. /* free up any resources left over (possibly due to an error) */
  1874. if (skb)
  1875. dev_kfree_skb(skb);
  1876. for (index = 0; index < num_pri_streams; index++) {
  1877. if (data_sync_bufs[index].skb != NULL) {
  1878. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
  1879. skb);
  1880. }
  1881. }
  1882. return ret;
  1883. }
  1884. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
  1885. struct wmi_create_pstream_cmd *params)
  1886. {
  1887. struct sk_buff *skb;
  1888. struct wmi_create_pstream_cmd *cmd;
  1889. u8 fatpipe_exist_for_ac = 0;
  1890. s32 min_phy = 0;
  1891. s32 nominal_phy = 0;
  1892. int ret;
  1893. if (!((params->user_pri < 8) &&
  1894. (params->user_pri <= 0x7) &&
  1895. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  1896. (params->traffic_direc == UPLINK_TRAFFIC ||
  1897. params->traffic_direc == DNLINK_TRAFFIC ||
  1898. params->traffic_direc == BIDIR_TRAFFIC) &&
  1899. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  1900. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  1901. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  1902. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  1903. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  1904. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  1905. params->tsid <= WMI_MAX_THINSTREAM))) {
  1906. return -EINVAL;
  1907. }
  1908. /*
  1909. * Check nominal PHY rate is >= minimalPHY,
  1910. * so that DUT can allow TSRS IE
  1911. */
  1912. /* Get the physical rate (units of bps) */
  1913. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  1914. /* Check minimal phy < nominal phy rate */
  1915. if (params->nominal_phy >= min_phy) {
  1916. /* unit of 500 kbps */
  1917. nominal_phy = (params->nominal_phy * 1000) / 500;
  1918. ath6kl_dbg(ATH6KL_DBG_WMI,
  1919. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  1920. min_phy, nominal_phy);
  1921. params->nominal_phy = nominal_phy;
  1922. } else {
  1923. params->nominal_phy = 0;
  1924. }
  1925. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1926. if (!skb)
  1927. return -ENOMEM;
  1928. ath6kl_dbg(ATH6KL_DBG_WMI,
  1929. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  1930. params->traffic_class, params->tsid);
  1931. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  1932. memcpy(cmd, params, sizeof(*cmd));
  1933. /* This is an implicitly created Fat pipe */
  1934. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  1935. spin_lock_bh(&wmi->lock);
  1936. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  1937. (1 << params->traffic_class));
  1938. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  1939. spin_unlock_bh(&wmi->lock);
  1940. } else {
  1941. /* explicitly created thin stream within a fat pipe */
  1942. spin_lock_bh(&wmi->lock);
  1943. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  1944. (1 << params->traffic_class));
  1945. wmi->stream_exist_for_ac[params->traffic_class] |=
  1946. (1 << params->tsid);
  1947. /*
  1948. * If a thinstream becomes active, the fat pipe automatically
  1949. * becomes active
  1950. */
  1951. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  1952. spin_unlock_bh(&wmi->lock);
  1953. }
  1954. /*
  1955. * Indicate activty change to driver layer only if this is the
  1956. * first TSID to get created in this AC explicitly or an implicit
  1957. * fat pipe is getting created.
  1958. */
  1959. if (!fatpipe_exist_for_ac)
  1960. ath6kl_indicate_tx_activity(wmi->parent_dev,
  1961. params->traffic_class, true);
  1962. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
  1963. NO_SYNC_WMIFLAG);
  1964. return ret;
  1965. }
  1966. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
  1967. u8 tsid)
  1968. {
  1969. struct sk_buff *skb;
  1970. struct wmi_delete_pstream_cmd *cmd;
  1971. u16 active_tsids = 0;
  1972. int ret;
  1973. if (traffic_class > 3) {
  1974. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  1975. return -EINVAL;
  1976. }
  1977. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1978. if (!skb)
  1979. return -ENOMEM;
  1980. cmd = (struct wmi_delete_pstream_cmd *) skb->data;
  1981. cmd->traffic_class = traffic_class;
  1982. cmd->tsid = tsid;
  1983. spin_lock_bh(&wmi->lock);
  1984. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  1985. spin_unlock_bh(&wmi->lock);
  1986. if (!(active_tsids & (1 << tsid))) {
  1987. dev_kfree_skb(skb);
  1988. ath6kl_dbg(ATH6KL_DBG_WMI,
  1989. "TSID %d doesn't exist for traffic class: %d\n",
  1990. tsid, traffic_class);
  1991. return -ENODATA;
  1992. }
  1993. ath6kl_dbg(ATH6KL_DBG_WMI,
  1994. "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
  1995. traffic_class, tsid);
  1996. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
  1997. SYNC_BEFORE_WMIFLAG);
  1998. spin_lock_bh(&wmi->lock);
  1999. wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
  2000. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2001. spin_unlock_bh(&wmi->lock);
  2002. /*
  2003. * Indicate stream inactivity to driver layer only if all tsids
  2004. * within this AC are deleted.
  2005. */
  2006. if (!active_tsids) {
  2007. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2008. traffic_class, false);
  2009. wmi->fat_pipe_exist &= ~(1 << traffic_class);
  2010. }
  2011. return ret;
  2012. }
  2013. int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
  2014. __be32 ips0, __be32 ips1)
  2015. {
  2016. struct sk_buff *skb;
  2017. struct wmi_set_ip_cmd *cmd;
  2018. int ret;
  2019. /* Multicast address are not valid */
  2020. if (ipv4_is_multicast(ips0) ||
  2021. ipv4_is_multicast(ips1))
  2022. return -EINVAL;
  2023. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
  2024. if (!skb)
  2025. return -ENOMEM;
  2026. cmd = (struct wmi_set_ip_cmd *) skb->data;
  2027. cmd->ips[0] = ips0;
  2028. cmd->ips[1] = ips1;
  2029. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
  2030. NO_SYNC_WMIFLAG);
  2031. return ret;
  2032. }
  2033. static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
  2034. {
  2035. u16 active_tsids;
  2036. u8 stream_exist;
  2037. int i;
  2038. /*
  2039. * Relinquish credits from all implicitly created pstreams
  2040. * since when we go to sleep. If user created explicit
  2041. * thinstreams exists with in a fatpipe leave them intact
  2042. * for the user to delete.
  2043. */
  2044. spin_lock_bh(&wmi->lock);
  2045. stream_exist = wmi->fat_pipe_exist;
  2046. spin_unlock_bh(&wmi->lock);
  2047. for (i = 0; i < WMM_NUM_AC; i++) {
  2048. if (stream_exist & (1 << i)) {
  2049. /*
  2050. * FIXME: Is this lock & unlock inside
  2051. * for loop correct? may need rework.
  2052. */
  2053. spin_lock_bh(&wmi->lock);
  2054. active_tsids = wmi->stream_exist_for_ac[i];
  2055. spin_unlock_bh(&wmi->lock);
  2056. /*
  2057. * If there are no user created thin streams
  2058. * delete the fatpipe
  2059. */
  2060. if (!active_tsids) {
  2061. stream_exist &= ~(1 << i);
  2062. /*
  2063. * Indicate inactivity to driver layer for
  2064. * this fatpipe (pstream)
  2065. */
  2066. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2067. i, false);
  2068. }
  2069. }
  2070. }
  2071. /* FIXME: Can we do this assignment without locking ? */
  2072. spin_lock_bh(&wmi->lock);
  2073. wmi->fat_pipe_exist = stream_exist;
  2074. spin_unlock_bh(&wmi->lock);
  2075. }
  2076. int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
  2077. enum ath6kl_host_mode host_mode)
  2078. {
  2079. struct sk_buff *skb;
  2080. struct wmi_set_host_sleep_mode_cmd *cmd;
  2081. int ret;
  2082. if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
  2083. (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
  2084. ath6kl_err("invalid host sleep mode: %d\n", host_mode);
  2085. return -EINVAL;
  2086. }
  2087. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2088. if (!skb)
  2089. return -ENOMEM;
  2090. cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
  2091. if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
  2092. ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
  2093. cmd->asleep = cpu_to_le32(1);
  2094. } else
  2095. cmd->awake = cpu_to_le32(1);
  2096. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2097. WMI_SET_HOST_SLEEP_MODE_CMDID,
  2098. NO_SYNC_WMIFLAG);
  2099. return ret;
  2100. }
  2101. int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
  2102. enum ath6kl_wow_mode wow_mode,
  2103. u32 filter, u16 host_req_delay)
  2104. {
  2105. struct sk_buff *skb;
  2106. struct wmi_set_wow_mode_cmd *cmd;
  2107. int ret;
  2108. if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
  2109. wow_mode != ATH6KL_WOW_MODE_DISABLE) {
  2110. ath6kl_err("invalid wow mode: %d\n", wow_mode);
  2111. return -EINVAL;
  2112. }
  2113. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2114. if (!skb)
  2115. return -ENOMEM;
  2116. cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
  2117. cmd->enable_wow = cpu_to_le32(wow_mode);
  2118. cmd->filter = cpu_to_le32(filter);
  2119. cmd->host_req_delay = cpu_to_le16(host_req_delay);
  2120. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
  2121. NO_SYNC_WMIFLAG);
  2122. return ret;
  2123. }
  2124. int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2125. u8 list_id, u8 filter_size,
  2126. u8 filter_offset, const u8 *filter,
  2127. const u8 *mask)
  2128. {
  2129. struct sk_buff *skb;
  2130. struct wmi_add_wow_pattern_cmd *cmd;
  2131. u16 size;
  2132. u8 *filter_mask;
  2133. int ret;
  2134. /*
  2135. * Allocate additional memory in the buffer to hold
  2136. * filter and mask value, which is twice of filter_size.
  2137. */
  2138. size = sizeof(*cmd) + (2 * filter_size);
  2139. skb = ath6kl_wmi_get_new_buf(size);
  2140. if (!skb)
  2141. return -ENOMEM;
  2142. cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
  2143. cmd->filter_list_id = list_id;
  2144. cmd->filter_size = filter_size;
  2145. cmd->filter_offset = filter_offset;
  2146. memcpy(cmd->filter, filter, filter_size);
  2147. filter_mask = (u8 *) (cmd->filter + filter_size);
  2148. memcpy(filter_mask, mask, filter_size);
  2149. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
  2150. NO_SYNC_WMIFLAG);
  2151. return ret;
  2152. }
  2153. int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2154. u16 list_id, u16 filter_id)
  2155. {
  2156. struct sk_buff *skb;
  2157. struct wmi_del_wow_pattern_cmd *cmd;
  2158. int ret;
  2159. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2160. if (!skb)
  2161. return -ENOMEM;
  2162. cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
  2163. cmd->filter_list_id = cpu_to_le16(list_id);
  2164. cmd->filter_id = cpu_to_le16(filter_id);
  2165. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
  2166. NO_SYNC_WMIFLAG);
  2167. return ret;
  2168. }
  2169. static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
  2170. enum wmix_command_id cmd_id,
  2171. enum wmi_sync_flag sync_flag)
  2172. {
  2173. struct wmix_cmd_hdr *cmd_hdr;
  2174. int ret;
  2175. skb_push(skb, sizeof(struct wmix_cmd_hdr));
  2176. cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
  2177. cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
  2178. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
  2179. return ret;
  2180. }
  2181. int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
  2182. {
  2183. struct sk_buff *skb;
  2184. struct wmix_hb_challenge_resp_cmd *cmd;
  2185. int ret;
  2186. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2187. if (!skb)
  2188. return -ENOMEM;
  2189. cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
  2190. cmd->cookie = cpu_to_le32(cookie);
  2191. cmd->source = cpu_to_le32(source);
  2192. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
  2193. NO_SYNC_WMIFLAG);
  2194. return ret;
  2195. }
  2196. int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
  2197. {
  2198. struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
  2199. struct sk_buff *skb;
  2200. int ret;
  2201. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2202. if (!skb)
  2203. return -ENOMEM;
  2204. cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
  2205. cmd->valid = cpu_to_le32(valid);
  2206. cmd->config = cpu_to_le32(config);
  2207. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
  2208. NO_SYNC_WMIFLAG);
  2209. return ret;
  2210. }
  2211. int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
  2212. {
  2213. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
  2214. }
  2215. int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
  2216. {
  2217. struct sk_buff *skb;
  2218. struct wmi_set_tx_pwr_cmd *cmd;
  2219. int ret;
  2220. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
  2221. if (!skb)
  2222. return -ENOMEM;
  2223. cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
  2224. cmd->dbM = dbM;
  2225. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
  2226. NO_SYNC_WMIFLAG);
  2227. return ret;
  2228. }
  2229. int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
  2230. {
  2231. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
  2232. }
  2233. int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
  2234. {
  2235. return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
  2236. }
  2237. int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
  2238. u8 preamble_policy)
  2239. {
  2240. struct sk_buff *skb;
  2241. struct wmi_set_lpreamble_cmd *cmd;
  2242. int ret;
  2243. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
  2244. if (!skb)
  2245. return -ENOMEM;
  2246. cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
  2247. cmd->status = status;
  2248. cmd->preamble_policy = preamble_policy;
  2249. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
  2250. NO_SYNC_WMIFLAG);
  2251. return ret;
  2252. }
  2253. int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
  2254. {
  2255. struct sk_buff *skb;
  2256. struct wmi_set_rts_cmd *cmd;
  2257. int ret;
  2258. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
  2259. if (!skb)
  2260. return -ENOMEM;
  2261. cmd = (struct wmi_set_rts_cmd *) skb->data;
  2262. cmd->threshold = cpu_to_le16(threshold);
  2263. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
  2264. NO_SYNC_WMIFLAG);
  2265. return ret;
  2266. }
  2267. int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
  2268. {
  2269. struct sk_buff *skb;
  2270. struct wmi_set_wmm_txop_cmd *cmd;
  2271. int ret;
  2272. if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
  2273. return -EINVAL;
  2274. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
  2275. if (!skb)
  2276. return -ENOMEM;
  2277. cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
  2278. cmd->txop_enable = cfg;
  2279. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
  2280. NO_SYNC_WMIFLAG);
  2281. return ret;
  2282. }
  2283. int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
  2284. u8 keep_alive_intvl)
  2285. {
  2286. struct sk_buff *skb;
  2287. struct wmi_set_keepalive_cmd *cmd;
  2288. int ret;
  2289. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2290. if (!skb)
  2291. return -ENOMEM;
  2292. cmd = (struct wmi_set_keepalive_cmd *) skb->data;
  2293. cmd->keep_alive_intvl = keep_alive_intvl;
  2294. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
  2295. NO_SYNC_WMIFLAG);
  2296. if (ret == 0)
  2297. ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
  2298. return ret;
  2299. }
  2300. int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
  2301. {
  2302. struct sk_buff *skb;
  2303. int ret;
  2304. skb = ath6kl_wmi_get_new_buf(len);
  2305. if (!skb)
  2306. return -ENOMEM;
  2307. memcpy(skb->data, buf, len);
  2308. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
  2309. return ret;
  2310. }
  2311. int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
  2312. {
  2313. struct sk_buff *skb;
  2314. struct wmi_mcast_filter_cmd *cmd;
  2315. int ret;
  2316. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2317. if (!skb)
  2318. return -ENOMEM;
  2319. cmd = (struct wmi_mcast_filter_cmd *) skb->data;
  2320. cmd->mcast_all_enable = mc_all_on;
  2321. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
  2322. NO_SYNC_WMIFLAG);
  2323. return ret;
  2324. }
  2325. int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
  2326. u8 *filter, bool add_filter)
  2327. {
  2328. struct sk_buff *skb;
  2329. struct wmi_mcast_filter_add_del_cmd *cmd;
  2330. int ret;
  2331. if ((filter[0] != 0x33 || filter[1] != 0x33) &&
  2332. (filter[0] != 0x01 || filter[1] != 0x00 ||
  2333. filter[2] != 0x5e || filter[3] > 0x7f)) {
  2334. ath6kl_warn("invalid multicast filter address\n");
  2335. return -EINVAL;
  2336. }
  2337. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2338. if (!skb)
  2339. return -ENOMEM;
  2340. cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
  2341. memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
  2342. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2343. add_filter ? WMI_SET_MCAST_FILTER_CMDID :
  2344. WMI_DEL_MCAST_FILTER_CMDID,
  2345. NO_SYNC_WMIFLAG);
  2346. return ret;
  2347. }
  2348. s32 ath6kl_wmi_get_rate(s8 rate_index)
  2349. {
  2350. if (rate_index == RATE_AUTO)
  2351. return 0;
  2352. return wmi_rate_tbl[(u32) rate_index][0];
  2353. }
  2354. static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
  2355. u32 len)
  2356. {
  2357. struct wmi_pmkid_list_reply *reply;
  2358. u32 expected_len;
  2359. if (len < sizeof(struct wmi_pmkid_list_reply))
  2360. return -EINVAL;
  2361. reply = (struct wmi_pmkid_list_reply *)datap;
  2362. expected_len = sizeof(reply->num_pmkid) +
  2363. le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
  2364. if (len < expected_len)
  2365. return -EINVAL;
  2366. return 0;
  2367. }
  2368. static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2369. struct ath6kl_vif *vif)
  2370. {
  2371. struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
  2372. aggr_recv_addba_req_evt(vif, cmd->tid,
  2373. le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
  2374. return 0;
  2375. }
  2376. static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2377. struct ath6kl_vif *vif)
  2378. {
  2379. struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
  2380. aggr_recv_delba_req_evt(vif, cmd->tid);
  2381. return 0;
  2382. }
  2383. /* AP mode functions */
  2384. int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
  2385. struct wmi_connect_cmd *p)
  2386. {
  2387. struct sk_buff *skb;
  2388. struct wmi_connect_cmd *cm;
  2389. int res;
  2390. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2391. if (!skb)
  2392. return -ENOMEM;
  2393. cm = (struct wmi_connect_cmd *) skb->data;
  2394. memcpy(cm, p, sizeof(*cm));
  2395. res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
  2396. NO_SYNC_WMIFLAG);
  2397. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
  2398. "ctrl_flags=0x%x-> res=%d\n",
  2399. __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
  2400. le32_to_cpu(p->ctrl_flags), res);
  2401. return res;
  2402. }
  2403. int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
  2404. u16 reason)
  2405. {
  2406. struct sk_buff *skb;
  2407. struct wmi_ap_set_mlme_cmd *cm;
  2408. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2409. if (!skb)
  2410. return -ENOMEM;
  2411. cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
  2412. memcpy(cm->mac, mac, ETH_ALEN);
  2413. cm->reason = cpu_to_le16(reason);
  2414. cm->cmd = cmd;
  2415. return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
  2416. NO_SYNC_WMIFLAG);
  2417. }
  2418. /* This command will be used to enable/disable AP uAPSD feature */
  2419. int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
  2420. {
  2421. struct wmi_ap_set_apsd_cmd *cmd;
  2422. struct sk_buff *skb;
  2423. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2424. if (!skb)
  2425. return -ENOMEM;
  2426. cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
  2427. cmd->enable = enable;
  2428. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
  2429. NO_SYNC_WMIFLAG);
  2430. }
  2431. int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
  2432. u16 aid, u16 bitmap, u32 flags)
  2433. {
  2434. struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
  2435. struct sk_buff *skb;
  2436. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2437. if (!skb)
  2438. return -ENOMEM;
  2439. cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
  2440. cmd->aid = cpu_to_le16(aid);
  2441. cmd->bitmap = cpu_to_le16(bitmap);
  2442. cmd->flags = cpu_to_le32(flags);
  2443. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2444. WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
  2445. NO_SYNC_WMIFLAG);
  2446. }
  2447. static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
  2448. struct ath6kl_vif *vif)
  2449. {
  2450. struct wmi_pspoll_event *ev;
  2451. if (len < sizeof(struct wmi_pspoll_event))
  2452. return -EINVAL;
  2453. ev = (struct wmi_pspoll_event *) datap;
  2454. ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
  2455. return 0;
  2456. }
  2457. static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
  2458. struct ath6kl_vif *vif)
  2459. {
  2460. ath6kl_dtimexpiry_event(vif);
  2461. return 0;
  2462. }
  2463. int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
  2464. bool flag)
  2465. {
  2466. struct sk_buff *skb;
  2467. struct wmi_ap_set_pvb_cmd *cmd;
  2468. int ret;
  2469. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
  2470. if (!skb)
  2471. return -ENOMEM;
  2472. cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
  2473. cmd->aid = cpu_to_le16(aid);
  2474. cmd->rsvd = cpu_to_le16(0);
  2475. cmd->flag = cpu_to_le32(flag);
  2476. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
  2477. NO_SYNC_WMIFLAG);
  2478. return 0;
  2479. }
  2480. int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
  2481. u8 rx_meta_ver,
  2482. bool rx_dot11_hdr, bool defrag_on_host)
  2483. {
  2484. struct sk_buff *skb;
  2485. struct wmi_rx_frame_format_cmd *cmd;
  2486. int ret;
  2487. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2488. if (!skb)
  2489. return -ENOMEM;
  2490. cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
  2491. cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
  2492. cmd->defrag_on_host = defrag_on_host ? 1 : 0;
  2493. cmd->meta_ver = rx_meta_ver;
  2494. /* Delete the local aggr state, on host */
  2495. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
  2496. NO_SYNC_WMIFLAG);
  2497. return ret;
  2498. }
  2499. int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
  2500. const u8 *ie, u8 ie_len)
  2501. {
  2502. struct sk_buff *skb;
  2503. struct wmi_set_appie_cmd *p;
  2504. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2505. if (!skb)
  2506. return -ENOMEM;
  2507. ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
  2508. "ie_len=%u\n", mgmt_frm_type, ie_len);
  2509. p = (struct wmi_set_appie_cmd *) skb->data;
  2510. p->mgmt_frm_type = mgmt_frm_type;
  2511. p->ie_len = ie_len;
  2512. if (ie != NULL && ie_len > 0)
  2513. memcpy(p->ie_info, ie, ie_len);
  2514. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
  2515. NO_SYNC_WMIFLAG);
  2516. }
  2517. int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
  2518. {
  2519. struct sk_buff *skb;
  2520. struct wmi_disable_11b_rates_cmd *cmd;
  2521. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2522. if (!skb)
  2523. return -ENOMEM;
  2524. ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
  2525. disable);
  2526. cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
  2527. cmd->disable = disable ? 1 : 0;
  2528. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
  2529. NO_SYNC_WMIFLAG);
  2530. }
  2531. int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
  2532. {
  2533. struct sk_buff *skb;
  2534. struct wmi_remain_on_chnl_cmd *p;
  2535. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2536. if (!skb)
  2537. return -ENOMEM;
  2538. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
  2539. freq, dur);
  2540. p = (struct wmi_remain_on_chnl_cmd *) skb->data;
  2541. p->freq = cpu_to_le32(freq);
  2542. p->duration = cpu_to_le32(dur);
  2543. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
  2544. NO_SYNC_WMIFLAG);
  2545. }
  2546. /* ath6kl_wmi_send_action_cmd is to be deprecated. Use
  2547. * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
  2548. * mgmt operations using station interface.
  2549. */
  2550. int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  2551. u32 wait, const u8 *data, u16 data_len)
  2552. {
  2553. struct sk_buff *skb;
  2554. struct wmi_send_action_cmd *p;
  2555. u8 *buf;
  2556. if (wait)
  2557. return -EINVAL; /* Offload for wait not supported */
  2558. buf = kmalloc(data_len, GFP_KERNEL);
  2559. if (!buf)
  2560. return -ENOMEM;
  2561. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2562. if (!skb) {
  2563. kfree(buf);
  2564. return -ENOMEM;
  2565. }
  2566. kfree(wmi->last_mgmt_tx_frame);
  2567. memcpy(buf, data, data_len);
  2568. wmi->last_mgmt_tx_frame = buf;
  2569. wmi->last_mgmt_tx_frame_len = data_len;
  2570. ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
  2571. "len=%u\n", id, freq, wait, data_len);
  2572. p = (struct wmi_send_action_cmd *) skb->data;
  2573. p->id = cpu_to_le32(id);
  2574. p->freq = cpu_to_le32(freq);
  2575. p->wait = cpu_to_le32(wait);
  2576. p->len = cpu_to_le16(data_len);
  2577. memcpy(p->data, data, data_len);
  2578. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
  2579. NO_SYNC_WMIFLAG);
  2580. }
  2581. int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  2582. u32 wait, const u8 *data, u16 data_len,
  2583. u32 no_cck)
  2584. {
  2585. struct sk_buff *skb;
  2586. struct wmi_send_mgmt_cmd *p;
  2587. u8 *buf;
  2588. if (wait)
  2589. return -EINVAL; /* Offload for wait not supported */
  2590. buf = kmalloc(data_len, GFP_KERNEL);
  2591. if (!buf)
  2592. return -ENOMEM;
  2593. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2594. if (!skb) {
  2595. kfree(buf);
  2596. return -ENOMEM;
  2597. }
  2598. kfree(wmi->last_mgmt_tx_frame);
  2599. memcpy(buf, data, data_len);
  2600. wmi->last_mgmt_tx_frame = buf;
  2601. wmi->last_mgmt_tx_frame_len = data_len;
  2602. ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
  2603. "len=%u\n", id, freq, wait, data_len);
  2604. p = (struct wmi_send_mgmt_cmd *) skb->data;
  2605. p->id = cpu_to_le32(id);
  2606. p->freq = cpu_to_le32(freq);
  2607. p->wait = cpu_to_le32(wait);
  2608. p->no_cck = cpu_to_le32(no_cck);
  2609. p->len = cpu_to_le16(data_len);
  2610. memcpy(p->data, data, data_len);
  2611. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
  2612. NO_SYNC_WMIFLAG);
  2613. }
  2614. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
  2615. const u8 *dst, const u8 *data,
  2616. u16 data_len)
  2617. {
  2618. struct sk_buff *skb;
  2619. struct wmi_p2p_probe_response_cmd *p;
  2620. size_t cmd_len = sizeof(*p) + data_len;
  2621. if (data_len == 0)
  2622. cmd_len++; /* work around target minimum length requirement */
  2623. skb = ath6kl_wmi_get_new_buf(cmd_len);
  2624. if (!skb)
  2625. return -ENOMEM;
  2626. ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
  2627. "len=%u\n", freq, dst, data_len);
  2628. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  2629. p->freq = cpu_to_le32(freq);
  2630. memcpy(p->destination_addr, dst, ETH_ALEN);
  2631. p->len = cpu_to_le16(data_len);
  2632. memcpy(p->data, data, data_len);
  2633. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2634. WMI_SEND_PROBE_RESPONSE_CMDID,
  2635. NO_SYNC_WMIFLAG);
  2636. }
  2637. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  2638. {
  2639. struct sk_buff *skb;
  2640. struct wmi_probe_req_report_cmd *p;
  2641. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2642. if (!skb)
  2643. return -ENOMEM;
  2644. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  2645. enable);
  2646. p = (struct wmi_probe_req_report_cmd *) skb->data;
  2647. p->enable = enable ? 1 : 0;
  2648. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
  2649. NO_SYNC_WMIFLAG);
  2650. }
  2651. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
  2652. {
  2653. struct sk_buff *skb;
  2654. struct wmi_get_p2p_info *p;
  2655. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2656. if (!skb)
  2657. return -ENOMEM;
  2658. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  2659. info_req_flags);
  2660. p = (struct wmi_get_p2p_info *) skb->data;
  2661. p->info_req_flags = cpu_to_le32(info_req_flags);
  2662. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
  2663. NO_SYNC_WMIFLAG);
  2664. }
  2665. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
  2666. {
  2667. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  2668. return ath6kl_wmi_simple_cmd(wmi, if_idx,
  2669. WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  2670. }
  2671. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  2672. {
  2673. struct wmix_cmd_hdr *cmd;
  2674. u32 len;
  2675. u16 id;
  2676. u8 *datap;
  2677. int ret = 0;
  2678. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  2679. ath6kl_err("bad packet 1\n");
  2680. return -EINVAL;
  2681. }
  2682. cmd = (struct wmix_cmd_hdr *) skb->data;
  2683. id = le32_to_cpu(cmd->cmd_id);
  2684. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  2685. datap = skb->data;
  2686. len = skb->len;
  2687. switch (id) {
  2688. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  2689. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
  2690. break;
  2691. case WMIX_DBGLOG_EVENTID:
  2692. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
  2693. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  2694. break;
  2695. default:
  2696. ath6kl_warn("unknown cmd id 0x%x\n", id);
  2697. ret = -EINVAL;
  2698. break;
  2699. }
  2700. return ret;
  2701. }
  2702. static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
  2703. {
  2704. return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
  2705. }
  2706. /* Control Path */
  2707. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  2708. {
  2709. struct wmi_cmd_hdr *cmd;
  2710. struct ath6kl_vif *vif;
  2711. u32 len;
  2712. u16 id;
  2713. u8 if_idx;
  2714. u8 *datap;
  2715. int ret = 0;
  2716. if (WARN_ON(skb == NULL))
  2717. return -EINVAL;
  2718. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  2719. ath6kl_err("bad packet 1\n");
  2720. dev_kfree_skb(skb);
  2721. return -EINVAL;
  2722. }
  2723. cmd = (struct wmi_cmd_hdr *) skb->data;
  2724. id = le16_to_cpu(cmd->cmd_id);
  2725. if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
  2726. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  2727. datap = skb->data;
  2728. len = skb->len;
  2729. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
  2730. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
  2731. datap, len);
  2732. vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
  2733. if (!vif) {
  2734. ath6kl_dbg(ATH6KL_DBG_WMI,
  2735. "Wmi event for unavailable vif, vif_index:%d\n",
  2736. if_idx);
  2737. dev_kfree_skb(skb);
  2738. return -EINVAL;
  2739. }
  2740. switch (id) {
  2741. case WMI_GET_BITRATE_CMDID:
  2742. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  2743. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  2744. break;
  2745. case WMI_GET_CHANNEL_LIST_CMDID:
  2746. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  2747. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  2748. break;
  2749. case WMI_GET_TX_PWR_CMDID:
  2750. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  2751. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  2752. break;
  2753. case WMI_READY_EVENTID:
  2754. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  2755. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  2756. break;
  2757. case WMI_CONNECT_EVENTID:
  2758. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  2759. ret = ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
  2760. break;
  2761. case WMI_DISCONNECT_EVENTID:
  2762. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  2763. ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
  2764. break;
  2765. case WMI_PEER_NODE_EVENTID:
  2766. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  2767. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  2768. break;
  2769. case WMI_TKIP_MICERR_EVENTID:
  2770. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  2771. ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
  2772. break;
  2773. case WMI_BSSINFO_EVENTID:
  2774. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  2775. ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
  2776. break;
  2777. case WMI_REGDOMAIN_EVENTID:
  2778. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  2779. ath6kl_wmi_regdomain_event(wmi, datap, len);
  2780. break;
  2781. case WMI_PSTREAM_TIMEOUT_EVENTID:
  2782. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  2783. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  2784. break;
  2785. case WMI_NEIGHBOR_REPORT_EVENTID:
  2786. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  2787. ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
  2788. vif);
  2789. break;
  2790. case WMI_SCAN_COMPLETE_EVENTID:
  2791. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  2792. ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
  2793. break;
  2794. case WMI_CMDERROR_EVENTID:
  2795. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  2796. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  2797. break;
  2798. case WMI_REPORT_STATISTICS_EVENTID:
  2799. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  2800. ret = ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
  2801. break;
  2802. case WMI_RSSI_THRESHOLD_EVENTID:
  2803. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  2804. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  2805. break;
  2806. case WMI_ERROR_REPORT_EVENTID:
  2807. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  2808. break;
  2809. case WMI_OPT_RX_FRAME_EVENTID:
  2810. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  2811. /* this event has been deprecated */
  2812. break;
  2813. case WMI_REPORT_ROAM_TBL_EVENTID:
  2814. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  2815. ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
  2816. break;
  2817. case WMI_EXTENSION_EVENTID:
  2818. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  2819. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  2820. break;
  2821. case WMI_CAC_EVENTID:
  2822. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  2823. ret = ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
  2824. break;
  2825. case WMI_CHANNEL_CHANGE_EVENTID:
  2826. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  2827. break;
  2828. case WMI_REPORT_ROAM_DATA_EVENTID:
  2829. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  2830. break;
  2831. case WMI_TEST_EVENTID:
  2832. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  2833. ret = ath6kl_wmi_test_rx(wmi, datap, len);
  2834. break;
  2835. case WMI_GET_FIXRATES_CMDID:
  2836. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  2837. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  2838. break;
  2839. case WMI_TX_RETRY_ERR_EVENTID:
  2840. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  2841. break;
  2842. case WMI_SNR_THRESHOLD_EVENTID:
  2843. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  2844. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  2845. break;
  2846. case WMI_LQ_THRESHOLD_EVENTID:
  2847. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  2848. break;
  2849. case WMI_APLIST_EVENTID:
  2850. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  2851. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  2852. break;
  2853. case WMI_GET_KEEPALIVE_CMDID:
  2854. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  2855. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  2856. break;
  2857. case WMI_GET_WOW_LIST_EVENTID:
  2858. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  2859. break;
  2860. case WMI_GET_PMKID_LIST_EVENTID:
  2861. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  2862. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  2863. break;
  2864. case WMI_PSPOLL_EVENTID:
  2865. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  2866. ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
  2867. break;
  2868. case WMI_DTIMEXPIRY_EVENTID:
  2869. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  2870. ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
  2871. break;
  2872. case WMI_SET_PARAMS_REPLY_EVENTID:
  2873. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  2874. break;
  2875. case WMI_ADDBA_REQ_EVENTID:
  2876. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  2877. ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
  2878. break;
  2879. case WMI_ADDBA_RESP_EVENTID:
  2880. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  2881. break;
  2882. case WMI_DELBA_REQ_EVENTID:
  2883. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  2884. ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
  2885. break;
  2886. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  2887. ath6kl_dbg(ATH6KL_DBG_WMI,
  2888. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  2889. break;
  2890. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  2891. ath6kl_dbg(ATH6KL_DBG_WMI,
  2892. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  2893. break;
  2894. case WMI_TX_COMPLETE_EVENTID:
  2895. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  2896. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  2897. break;
  2898. case WMI_REMAIN_ON_CHNL_EVENTID:
  2899. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  2900. ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
  2901. break;
  2902. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  2903. ath6kl_dbg(ATH6KL_DBG_WMI,
  2904. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  2905. ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  2906. len, vif);
  2907. break;
  2908. case WMI_TX_STATUS_EVENTID:
  2909. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  2910. ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
  2911. break;
  2912. case WMI_RX_PROBE_REQ_EVENTID:
  2913. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  2914. ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
  2915. break;
  2916. case WMI_P2P_CAPABILITIES_EVENTID:
  2917. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  2918. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  2919. break;
  2920. case WMI_RX_ACTION_EVENTID:
  2921. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  2922. ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
  2923. break;
  2924. case WMI_P2P_INFO_EVENTID:
  2925. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  2926. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  2927. break;
  2928. default:
  2929. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
  2930. ret = -EINVAL;
  2931. break;
  2932. }
  2933. dev_kfree_skb(skb);
  2934. return ret;
  2935. }
  2936. void ath6kl_wmi_reset(struct wmi *wmi)
  2937. {
  2938. spin_lock_bh(&wmi->lock);
  2939. wmi->fat_pipe_exist = 0;
  2940. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  2941. spin_unlock_bh(&wmi->lock);
  2942. }
  2943. void *ath6kl_wmi_init(struct ath6kl *dev)
  2944. {
  2945. struct wmi *wmi;
  2946. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  2947. if (!wmi)
  2948. return NULL;
  2949. spin_lock_init(&wmi->lock);
  2950. wmi->parent_dev = dev;
  2951. wmi->pwr_mode = REC_POWER;
  2952. ath6kl_wmi_reset(wmi);
  2953. return wmi;
  2954. }
  2955. void ath6kl_wmi_shutdown(struct wmi *wmi)
  2956. {
  2957. if (!wmi)
  2958. return;
  2959. kfree(wmi->last_mgmt_tx_frame);
  2960. kfree(wmi);
  2961. }