wmi.c 79 KB

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