wmi.c 105 KB

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