wmi.c 107 KB

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