wmi.c 97 KB

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