wmi.c 103 KB

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