wmi.c 107 KB

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