wmi.c 80 KB

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