wmi.c 99 KB

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