wmi.c 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040
  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. /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
  1541. * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
  1542. * mgmt operations using station interface.
  1543. */
  1544. static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
  1545. enum wmi_scan_type scan_type,
  1546. u32 force_fgscan, u32 is_legacy,
  1547. u32 home_dwell_time,
  1548. u32 force_scan_interval,
  1549. s8 num_chan, u16 *ch_list)
  1550. {
  1551. struct sk_buff *skb;
  1552. struct wmi_start_scan_cmd *sc;
  1553. s8 size;
  1554. int i, ret;
  1555. size = sizeof(struct wmi_start_scan_cmd);
  1556. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1557. return -EINVAL;
  1558. if (num_chan > WMI_MAX_CHANNELS)
  1559. return -EINVAL;
  1560. if (num_chan)
  1561. size += sizeof(u16) * (num_chan - 1);
  1562. skb = ath6kl_wmi_get_new_buf(size);
  1563. if (!skb)
  1564. return -ENOMEM;
  1565. sc = (struct wmi_start_scan_cmd *) skb->data;
  1566. sc->scan_type = scan_type;
  1567. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1568. sc->is_legacy = cpu_to_le32(is_legacy);
  1569. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1570. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1571. sc->num_ch = num_chan;
  1572. for (i = 0; i < num_chan; i++)
  1573. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1574. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
  1575. NO_SYNC_WMIFLAG);
  1576. return ret;
  1577. }
  1578. /*
  1579. * beginscan supports (compared to old startscan) P2P mgmt operations using
  1580. * station interface, send additional information like supported rates to
  1581. * advertise and xmit rates for probe requests
  1582. */
  1583. int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
  1584. enum wmi_scan_type scan_type,
  1585. u32 force_fgscan, u32 is_legacy,
  1586. u32 home_dwell_time, u32 force_scan_interval,
  1587. s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
  1588. {
  1589. struct ieee80211_supported_band *sband;
  1590. struct sk_buff *skb;
  1591. struct wmi_begin_scan_cmd *sc;
  1592. s8 size, *supp_rates;
  1593. int i, band, ret;
  1594. struct ath6kl *ar = wmi->parent_dev;
  1595. int num_rates;
  1596. u32 ratemask;
  1597. if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  1598. ar->fw_capabilities)) {
  1599. return ath6kl_wmi_startscan_cmd(wmi, if_idx,
  1600. scan_type, force_fgscan,
  1601. is_legacy, home_dwell_time,
  1602. force_scan_interval,
  1603. num_chan, ch_list);
  1604. }
  1605. size = sizeof(struct wmi_begin_scan_cmd);
  1606. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1607. return -EINVAL;
  1608. if (num_chan > WMI_MAX_CHANNELS)
  1609. return -EINVAL;
  1610. if (num_chan)
  1611. size += sizeof(u16) * (num_chan - 1);
  1612. skb = ath6kl_wmi_get_new_buf(size);
  1613. if (!skb)
  1614. return -ENOMEM;
  1615. sc = (struct wmi_begin_scan_cmd *) skb->data;
  1616. sc->scan_type = scan_type;
  1617. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1618. sc->is_legacy = cpu_to_le32(is_legacy);
  1619. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1620. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1621. sc->no_cck = cpu_to_le32(no_cck);
  1622. sc->num_ch = num_chan;
  1623. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1624. sband = ar->wiphy->bands[band];
  1625. if (!sband)
  1626. continue;
  1627. ratemask = rates[band];
  1628. supp_rates = sc->supp_rates[band].rates;
  1629. num_rates = 0;
  1630. for (i = 0; i < sband->n_bitrates; i++) {
  1631. if ((BIT(i) & ratemask) == 0)
  1632. continue; /* skip rate */
  1633. supp_rates[num_rates++] =
  1634. (u8) (sband->bitrates[i].bitrate / 5);
  1635. }
  1636. sc->supp_rates[band].nrates = num_rates;
  1637. }
  1638. for (i = 0; i < num_chan; i++)
  1639. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1640. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
  1641. NO_SYNC_WMIFLAG);
  1642. return ret;
  1643. }
  1644. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
  1645. u16 fg_start_sec,
  1646. u16 fg_end_sec, u16 bg_sec,
  1647. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1648. u16 pas_chdw_msec, u8 short_scan_ratio,
  1649. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1650. u16 maxact_scan_per_ssid)
  1651. {
  1652. struct sk_buff *skb;
  1653. struct wmi_scan_params_cmd *sc;
  1654. int ret;
  1655. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1656. if (!skb)
  1657. return -ENOMEM;
  1658. sc = (struct wmi_scan_params_cmd *) skb->data;
  1659. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1660. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1661. sc->bg_period = cpu_to_le16(bg_sec);
  1662. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1663. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1664. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1665. sc->short_scan_ratio = short_scan_ratio;
  1666. sc->scan_ctrl_flags = scan_ctrl_flag;
  1667. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1668. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1669. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1670. NO_SYNC_WMIFLAG);
  1671. return ret;
  1672. }
  1673. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
  1674. {
  1675. struct sk_buff *skb;
  1676. struct wmi_bss_filter_cmd *cmd;
  1677. int ret;
  1678. if (filter >= LAST_BSS_FILTER)
  1679. return -EINVAL;
  1680. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1681. if (!skb)
  1682. return -ENOMEM;
  1683. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1684. cmd->bss_filter = filter;
  1685. cmd->ie_mask = cpu_to_le32(ie_mask);
  1686. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
  1687. NO_SYNC_WMIFLAG);
  1688. return ret;
  1689. }
  1690. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
  1691. u8 ssid_len, u8 *ssid)
  1692. {
  1693. struct sk_buff *skb;
  1694. struct wmi_probed_ssid_cmd *cmd;
  1695. int ret;
  1696. if (index >= MAX_PROBED_SSIDS)
  1697. return -EINVAL;
  1698. if (ssid_len > sizeof(cmd->ssid))
  1699. return -EINVAL;
  1700. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1701. return -EINVAL;
  1702. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1703. return -EINVAL;
  1704. if (flag & SPECIFIC_SSID_FLAG)
  1705. wmi->is_probe_ssid = true;
  1706. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1707. if (!skb)
  1708. return -ENOMEM;
  1709. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1710. cmd->entry_index = index;
  1711. cmd->flag = flag;
  1712. cmd->ssid_len = ssid_len;
  1713. memcpy(cmd->ssid, ssid, ssid_len);
  1714. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
  1715. NO_SYNC_WMIFLAG);
  1716. return ret;
  1717. }
  1718. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
  1719. u16 listen_interval,
  1720. u16 listen_beacons)
  1721. {
  1722. struct sk_buff *skb;
  1723. struct wmi_listen_int_cmd *cmd;
  1724. int ret;
  1725. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1726. if (!skb)
  1727. return -ENOMEM;
  1728. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1729. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1730. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1731. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
  1732. NO_SYNC_WMIFLAG);
  1733. return ret;
  1734. }
  1735. int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
  1736. u16 bmiss_time, u16 num_beacons)
  1737. {
  1738. struct sk_buff *skb;
  1739. struct wmi_bmiss_time_cmd *cmd;
  1740. int ret;
  1741. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1742. if (!skb)
  1743. return -ENOMEM;
  1744. cmd = (struct wmi_bmiss_time_cmd *) skb->data;
  1745. cmd->bmiss_time = cpu_to_le16(bmiss_time);
  1746. cmd->num_beacons = cpu_to_le16(num_beacons);
  1747. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
  1748. NO_SYNC_WMIFLAG);
  1749. return ret;
  1750. }
  1751. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
  1752. {
  1753. struct sk_buff *skb;
  1754. struct wmi_power_mode_cmd *cmd;
  1755. int ret;
  1756. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1757. if (!skb)
  1758. return -ENOMEM;
  1759. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1760. cmd->pwr_mode = pwr_mode;
  1761. wmi->pwr_mode = pwr_mode;
  1762. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
  1763. NO_SYNC_WMIFLAG);
  1764. return ret;
  1765. }
  1766. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
  1767. u16 ps_poll_num, u16 dtim_policy,
  1768. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1769. u16 ps_fail_event_policy)
  1770. {
  1771. struct sk_buff *skb;
  1772. struct wmi_power_params_cmd *pm;
  1773. int ret;
  1774. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1775. if (!skb)
  1776. return -ENOMEM;
  1777. pm = (struct wmi_power_params_cmd *)skb->data;
  1778. pm->idle_period = cpu_to_le16(idle_period);
  1779. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1780. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1781. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1782. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1783. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1784. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
  1785. NO_SYNC_WMIFLAG);
  1786. return ret;
  1787. }
  1788. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
  1789. {
  1790. struct sk_buff *skb;
  1791. struct wmi_disc_timeout_cmd *cmd;
  1792. int ret;
  1793. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1794. if (!skb)
  1795. return -ENOMEM;
  1796. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1797. cmd->discon_timeout = timeout;
  1798. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1799. NO_SYNC_WMIFLAG);
  1800. if (ret == 0)
  1801. ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
  1802. return ret;
  1803. }
  1804. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
  1805. enum crypto_type key_type,
  1806. u8 key_usage, u8 key_len,
  1807. u8 *key_rsc, unsigned int key_rsc_len,
  1808. u8 *key_material,
  1809. u8 key_op_ctrl, u8 *mac_addr,
  1810. enum wmi_sync_flag sync_flag)
  1811. {
  1812. struct sk_buff *skb;
  1813. struct wmi_add_cipher_key_cmd *cmd;
  1814. int ret;
  1815. ath6kl_dbg(ATH6KL_DBG_WMI,
  1816. "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1817. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1818. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1819. (key_material == NULL) || key_rsc_len > 8)
  1820. return -EINVAL;
  1821. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1822. return -EINVAL;
  1823. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1824. if (!skb)
  1825. return -ENOMEM;
  1826. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1827. cmd->key_index = key_index;
  1828. cmd->key_type = key_type;
  1829. cmd->key_usage = key_usage;
  1830. cmd->key_len = key_len;
  1831. memcpy(cmd->key, key_material, key_len);
  1832. if (key_rsc != NULL)
  1833. memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
  1834. cmd->key_op_ctrl = key_op_ctrl;
  1835. if (mac_addr)
  1836. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1837. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1838. sync_flag);
  1839. return ret;
  1840. }
  1841. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
  1842. {
  1843. struct sk_buff *skb;
  1844. struct wmi_add_krk_cmd *cmd;
  1845. int ret;
  1846. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1847. if (!skb)
  1848. return -ENOMEM;
  1849. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1850. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1851. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
  1852. NO_SYNC_WMIFLAG);
  1853. return ret;
  1854. }
  1855. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
  1856. {
  1857. struct sk_buff *skb;
  1858. struct wmi_delete_cipher_key_cmd *cmd;
  1859. int ret;
  1860. if (key_index > WMI_MAX_KEY_INDEX)
  1861. return -EINVAL;
  1862. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1863. if (!skb)
  1864. return -ENOMEM;
  1865. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1866. cmd->key_index = key_index;
  1867. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1868. NO_SYNC_WMIFLAG);
  1869. return ret;
  1870. }
  1871. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
  1872. const u8 *pmkid, bool set)
  1873. {
  1874. struct sk_buff *skb;
  1875. struct wmi_setpmkid_cmd *cmd;
  1876. int ret;
  1877. if (bssid == NULL)
  1878. return -EINVAL;
  1879. if (set && pmkid == NULL)
  1880. return -EINVAL;
  1881. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1882. if (!skb)
  1883. return -ENOMEM;
  1884. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1885. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1886. if (set) {
  1887. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1888. cmd->enable = PMKID_ENABLE;
  1889. } else {
  1890. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1891. cmd->enable = PMKID_DISABLE;
  1892. }
  1893. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
  1894. NO_SYNC_WMIFLAG);
  1895. return ret;
  1896. }
  1897. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1898. enum htc_endpoint_id ep_id, u8 if_idx)
  1899. {
  1900. struct wmi_data_hdr *data_hdr;
  1901. int ret;
  1902. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
  1903. return -EINVAL;
  1904. skb_push(skb, sizeof(struct wmi_data_hdr));
  1905. data_hdr = (struct wmi_data_hdr *) skb->data;
  1906. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1907. data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  1908. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1909. return ret;
  1910. }
  1911. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
  1912. {
  1913. struct sk_buff *skb;
  1914. struct wmi_sync_cmd *cmd;
  1915. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1916. enum htc_endpoint_id ep_id;
  1917. u8 index, num_pri_streams = 0;
  1918. int ret = 0;
  1919. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  1920. spin_lock_bh(&wmi->lock);
  1921. for (index = 0; index < WMM_NUM_AC; index++) {
  1922. if (wmi->fat_pipe_exist & (1 << index)) {
  1923. num_pri_streams++;
  1924. data_sync_bufs[num_pri_streams - 1].traffic_class =
  1925. index;
  1926. }
  1927. }
  1928. spin_unlock_bh(&wmi->lock);
  1929. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1930. if (!skb) {
  1931. ret = -ENOMEM;
  1932. goto free_skb;
  1933. }
  1934. cmd = (struct wmi_sync_cmd *) skb->data;
  1935. /*
  1936. * In the SYNC cmd sent on the control Ep, send a bitmap
  1937. * of the data eps on which the Data Sync will be sent
  1938. */
  1939. cmd->data_sync_map = wmi->fat_pipe_exist;
  1940. for (index = 0; index < num_pri_streams; index++) {
  1941. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  1942. if (data_sync_bufs[index].skb == NULL) {
  1943. ret = -ENOMEM;
  1944. break;
  1945. }
  1946. }
  1947. /*
  1948. * If buffer allocation for any of the dataSync fails,
  1949. * then do not send the Synchronize cmd on the control ep
  1950. */
  1951. if (ret)
  1952. goto free_skb;
  1953. /*
  1954. * Send sync cmd followed by sync data messages on all
  1955. * endpoints being used
  1956. */
  1957. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
  1958. NO_SYNC_WMIFLAG);
  1959. if (ret)
  1960. goto free_skb;
  1961. /* cmd buffer sent, we no longer own it */
  1962. skb = NULL;
  1963. for (index = 0; index < num_pri_streams; index++) {
  1964. if (WARN_ON(!data_sync_bufs[index].skb))
  1965. break;
  1966. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  1967. data_sync_bufs[index].
  1968. traffic_class);
  1969. ret =
  1970. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  1971. ep_id, if_idx);
  1972. if (ret)
  1973. break;
  1974. data_sync_bufs[index].skb = NULL;
  1975. }
  1976. free_skb:
  1977. /* free up any resources left over (possibly due to an error) */
  1978. if (skb)
  1979. dev_kfree_skb(skb);
  1980. for (index = 0; index < num_pri_streams; index++) {
  1981. if (data_sync_bufs[index].skb != NULL) {
  1982. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
  1983. skb);
  1984. }
  1985. }
  1986. return ret;
  1987. }
  1988. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
  1989. struct wmi_create_pstream_cmd *params)
  1990. {
  1991. struct sk_buff *skb;
  1992. struct wmi_create_pstream_cmd *cmd;
  1993. u8 fatpipe_exist_for_ac = 0;
  1994. s32 min_phy = 0;
  1995. s32 nominal_phy = 0;
  1996. int ret;
  1997. if (!((params->user_pri < 8) &&
  1998. (params->user_pri <= 0x7) &&
  1999. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  2000. (params->traffic_direc == UPLINK_TRAFFIC ||
  2001. params->traffic_direc == DNLINK_TRAFFIC ||
  2002. params->traffic_direc == BIDIR_TRAFFIC) &&
  2003. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  2004. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  2005. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  2006. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  2007. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  2008. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  2009. params->tsid <= WMI_MAX_THINSTREAM))) {
  2010. return -EINVAL;
  2011. }
  2012. /*
  2013. * Check nominal PHY rate is >= minimalPHY,
  2014. * so that DUT can allow TSRS IE
  2015. */
  2016. /* Get the physical rate (units of bps) */
  2017. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  2018. /* Check minimal phy < nominal phy rate */
  2019. if (params->nominal_phy >= min_phy) {
  2020. /* unit of 500 kbps */
  2021. nominal_phy = (params->nominal_phy * 1000) / 500;
  2022. ath6kl_dbg(ATH6KL_DBG_WMI,
  2023. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  2024. min_phy, nominal_phy);
  2025. params->nominal_phy = nominal_phy;
  2026. } else {
  2027. params->nominal_phy = 0;
  2028. }
  2029. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2030. if (!skb)
  2031. return -ENOMEM;
  2032. ath6kl_dbg(ATH6KL_DBG_WMI,
  2033. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  2034. params->traffic_class, params->tsid);
  2035. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  2036. memcpy(cmd, params, sizeof(*cmd));
  2037. /* This is an implicitly created Fat pipe */
  2038. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  2039. spin_lock_bh(&wmi->lock);
  2040. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2041. (1 << params->traffic_class));
  2042. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2043. spin_unlock_bh(&wmi->lock);
  2044. } else {
  2045. /* explicitly created thin stream within a fat pipe */
  2046. spin_lock_bh(&wmi->lock);
  2047. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2048. (1 << params->traffic_class));
  2049. wmi->stream_exist_for_ac[params->traffic_class] |=
  2050. (1 << params->tsid);
  2051. /*
  2052. * If a thinstream becomes active, the fat pipe automatically
  2053. * becomes active
  2054. */
  2055. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2056. spin_unlock_bh(&wmi->lock);
  2057. }
  2058. /*
  2059. * Indicate activty change to driver layer only if this is the
  2060. * first TSID to get created in this AC explicitly or an implicit
  2061. * fat pipe is getting created.
  2062. */
  2063. if (!fatpipe_exist_for_ac)
  2064. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2065. params->traffic_class, true);
  2066. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
  2067. NO_SYNC_WMIFLAG);
  2068. return ret;
  2069. }
  2070. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
  2071. u8 tsid)
  2072. {
  2073. struct sk_buff *skb;
  2074. struct wmi_delete_pstream_cmd *cmd;
  2075. u16 active_tsids = 0;
  2076. int ret;
  2077. if (traffic_class > 3) {
  2078. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  2079. return -EINVAL;
  2080. }
  2081. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2082. if (!skb)
  2083. return -ENOMEM;
  2084. cmd = (struct wmi_delete_pstream_cmd *) skb->data;
  2085. cmd->traffic_class = traffic_class;
  2086. cmd->tsid = tsid;
  2087. spin_lock_bh(&wmi->lock);
  2088. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2089. spin_unlock_bh(&wmi->lock);
  2090. if (!(active_tsids & (1 << tsid))) {
  2091. dev_kfree_skb(skb);
  2092. ath6kl_dbg(ATH6KL_DBG_WMI,
  2093. "TSID %d doesn't exist for traffic class: %d\n",
  2094. tsid, traffic_class);
  2095. return -ENODATA;
  2096. }
  2097. ath6kl_dbg(ATH6KL_DBG_WMI,
  2098. "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
  2099. traffic_class, tsid);
  2100. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
  2101. SYNC_BEFORE_WMIFLAG);
  2102. spin_lock_bh(&wmi->lock);
  2103. wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
  2104. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2105. spin_unlock_bh(&wmi->lock);
  2106. /*
  2107. * Indicate stream inactivity to driver layer only if all tsids
  2108. * within this AC are deleted.
  2109. */
  2110. if (!active_tsids) {
  2111. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2112. traffic_class, false);
  2113. wmi->fat_pipe_exist &= ~(1 << traffic_class);
  2114. }
  2115. return ret;
  2116. }
  2117. int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
  2118. __be32 ips0, __be32 ips1)
  2119. {
  2120. struct sk_buff *skb;
  2121. struct wmi_set_ip_cmd *cmd;
  2122. int ret;
  2123. /* Multicast address are not valid */
  2124. if (ipv4_is_multicast(ips0) ||
  2125. ipv4_is_multicast(ips1))
  2126. return -EINVAL;
  2127. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
  2128. if (!skb)
  2129. return -ENOMEM;
  2130. cmd = (struct wmi_set_ip_cmd *) skb->data;
  2131. cmd->ips[0] = ips0;
  2132. cmd->ips[1] = ips1;
  2133. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
  2134. NO_SYNC_WMIFLAG);
  2135. return ret;
  2136. }
  2137. static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
  2138. {
  2139. u16 active_tsids;
  2140. u8 stream_exist;
  2141. int i;
  2142. /*
  2143. * Relinquish credits from all implicitly created pstreams
  2144. * since when we go to sleep. If user created explicit
  2145. * thinstreams exists with in a fatpipe leave them intact
  2146. * for the user to delete.
  2147. */
  2148. spin_lock_bh(&wmi->lock);
  2149. stream_exist = wmi->fat_pipe_exist;
  2150. spin_unlock_bh(&wmi->lock);
  2151. for (i = 0; i < WMM_NUM_AC; i++) {
  2152. if (stream_exist & (1 << i)) {
  2153. /*
  2154. * FIXME: Is this lock & unlock inside
  2155. * for loop correct? may need rework.
  2156. */
  2157. spin_lock_bh(&wmi->lock);
  2158. active_tsids = wmi->stream_exist_for_ac[i];
  2159. spin_unlock_bh(&wmi->lock);
  2160. /*
  2161. * If there are no user created thin streams
  2162. * delete the fatpipe
  2163. */
  2164. if (!active_tsids) {
  2165. stream_exist &= ~(1 << i);
  2166. /*
  2167. * Indicate inactivity to driver layer for
  2168. * this fatpipe (pstream)
  2169. */
  2170. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2171. i, false);
  2172. }
  2173. }
  2174. }
  2175. /* FIXME: Can we do this assignment without locking ? */
  2176. spin_lock_bh(&wmi->lock);
  2177. wmi->fat_pipe_exist = stream_exist;
  2178. spin_unlock_bh(&wmi->lock);
  2179. }
  2180. static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
  2181. const struct cfg80211_bitrate_mask *mask)
  2182. {
  2183. struct sk_buff *skb;
  2184. int ret, mode, band;
  2185. u64 mcsrate, ratemask[IEEE80211_NUM_BANDS];
  2186. struct wmi_set_tx_select_rates64_cmd *cmd;
  2187. memset(&ratemask, 0, sizeof(ratemask));
  2188. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  2189. /* copy legacy rate mask */
  2190. ratemask[band] = mask->control[band].legacy;
  2191. if (band == IEEE80211_BAND_5GHZ)
  2192. ratemask[band] =
  2193. mask->control[band].legacy << 4;
  2194. /* copy mcs rate mask */
  2195. mcsrate = mask->control[band].mcs[1];
  2196. mcsrate <<= 8;
  2197. mcsrate |= mask->control[band].mcs[0];
  2198. ratemask[band] |= mcsrate << 12;
  2199. ratemask[band] |= mcsrate << 28;
  2200. }
  2201. ath6kl_dbg(ATH6KL_DBG_WMI,
  2202. "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
  2203. ratemask[0], ratemask[1]);
  2204. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
  2205. if (!skb)
  2206. return -ENOMEM;
  2207. cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
  2208. for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
  2209. /* A mode operate in 5GHZ band */
  2210. if (mode == WMI_RATES_MODE_11A ||
  2211. mode == WMI_RATES_MODE_11A_HT20 ||
  2212. mode == WMI_RATES_MODE_11A_HT40)
  2213. band = IEEE80211_BAND_5GHZ;
  2214. else
  2215. band = IEEE80211_BAND_2GHZ;
  2216. cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
  2217. }
  2218. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2219. WMI_SET_TX_SELECT_RATES_CMDID,
  2220. NO_SYNC_WMIFLAG);
  2221. return ret;
  2222. }
  2223. static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
  2224. const struct cfg80211_bitrate_mask *mask)
  2225. {
  2226. struct sk_buff *skb;
  2227. int ret, mode, band;
  2228. u32 mcsrate, ratemask[IEEE80211_NUM_BANDS];
  2229. struct wmi_set_tx_select_rates32_cmd *cmd;
  2230. memset(&ratemask, 0, sizeof(ratemask));
  2231. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  2232. /* copy legacy rate mask */
  2233. ratemask[band] = mask->control[band].legacy;
  2234. if (band == IEEE80211_BAND_5GHZ)
  2235. ratemask[band] =
  2236. mask->control[band].legacy << 4;
  2237. /* copy mcs rate mask */
  2238. mcsrate = mask->control[band].mcs[0];
  2239. ratemask[band] |= mcsrate << 12;
  2240. ratemask[band] |= mcsrate << 20;
  2241. }
  2242. ath6kl_dbg(ATH6KL_DBG_WMI,
  2243. "Ratemask 32 bit: 2.4:%x 5:%x\n",
  2244. ratemask[0], ratemask[1]);
  2245. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
  2246. if (!skb)
  2247. return -ENOMEM;
  2248. cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
  2249. for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
  2250. /* A mode operate in 5GHZ band */
  2251. if (mode == WMI_RATES_MODE_11A ||
  2252. mode == WMI_RATES_MODE_11A_HT20 ||
  2253. mode == WMI_RATES_MODE_11A_HT40)
  2254. band = IEEE80211_BAND_5GHZ;
  2255. else
  2256. band = IEEE80211_BAND_2GHZ;
  2257. cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
  2258. }
  2259. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2260. WMI_SET_TX_SELECT_RATES_CMDID,
  2261. NO_SYNC_WMIFLAG);
  2262. return ret;
  2263. }
  2264. int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
  2265. const struct cfg80211_bitrate_mask *mask)
  2266. {
  2267. struct ath6kl *ar = wmi->parent_dev;
  2268. if (ar->hw.flags & ATH6KL_HW_FLAG_64BIT_RATES)
  2269. return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
  2270. else
  2271. return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
  2272. }
  2273. int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
  2274. enum ath6kl_host_mode host_mode)
  2275. {
  2276. struct sk_buff *skb;
  2277. struct wmi_set_host_sleep_mode_cmd *cmd;
  2278. int ret;
  2279. if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
  2280. (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
  2281. ath6kl_err("invalid host sleep mode: %d\n", host_mode);
  2282. return -EINVAL;
  2283. }
  2284. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2285. if (!skb)
  2286. return -ENOMEM;
  2287. cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
  2288. if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
  2289. ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
  2290. cmd->asleep = cpu_to_le32(1);
  2291. } else
  2292. cmd->awake = cpu_to_le32(1);
  2293. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2294. WMI_SET_HOST_SLEEP_MODE_CMDID,
  2295. NO_SYNC_WMIFLAG);
  2296. return ret;
  2297. }
  2298. /* This command has zero length payload */
  2299. static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
  2300. struct ath6kl_vif *vif)
  2301. {
  2302. struct ath6kl *ar = wmi->parent_dev;
  2303. set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  2304. wake_up(&ar->event_wq);
  2305. return 0;
  2306. }
  2307. int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
  2308. enum ath6kl_wow_mode wow_mode,
  2309. u32 filter, u16 host_req_delay)
  2310. {
  2311. struct sk_buff *skb;
  2312. struct wmi_set_wow_mode_cmd *cmd;
  2313. int ret;
  2314. if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
  2315. wow_mode != ATH6KL_WOW_MODE_DISABLE) {
  2316. ath6kl_err("invalid wow mode: %d\n", wow_mode);
  2317. return -EINVAL;
  2318. }
  2319. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2320. if (!skb)
  2321. return -ENOMEM;
  2322. cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
  2323. cmd->enable_wow = cpu_to_le32(wow_mode);
  2324. cmd->filter = cpu_to_le32(filter);
  2325. cmd->host_req_delay = cpu_to_le16(host_req_delay);
  2326. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
  2327. NO_SYNC_WMIFLAG);
  2328. return ret;
  2329. }
  2330. int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2331. u8 list_id, u8 filter_size,
  2332. u8 filter_offset, const u8 *filter,
  2333. const u8 *mask)
  2334. {
  2335. struct sk_buff *skb;
  2336. struct wmi_add_wow_pattern_cmd *cmd;
  2337. u16 size;
  2338. u8 *filter_mask;
  2339. int ret;
  2340. /*
  2341. * Allocate additional memory in the buffer to hold
  2342. * filter and mask value, which is twice of filter_size.
  2343. */
  2344. size = sizeof(*cmd) + (2 * filter_size);
  2345. skb = ath6kl_wmi_get_new_buf(size);
  2346. if (!skb)
  2347. return -ENOMEM;
  2348. cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
  2349. cmd->filter_list_id = list_id;
  2350. cmd->filter_size = filter_size;
  2351. cmd->filter_offset = filter_offset;
  2352. memcpy(cmd->filter, filter, filter_size);
  2353. filter_mask = (u8 *) (cmd->filter + filter_size);
  2354. memcpy(filter_mask, mask, filter_size);
  2355. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
  2356. NO_SYNC_WMIFLAG);
  2357. return ret;
  2358. }
  2359. int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2360. u16 list_id, u16 filter_id)
  2361. {
  2362. struct sk_buff *skb;
  2363. struct wmi_del_wow_pattern_cmd *cmd;
  2364. int ret;
  2365. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2366. if (!skb)
  2367. return -ENOMEM;
  2368. cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
  2369. cmd->filter_list_id = cpu_to_le16(list_id);
  2370. cmd->filter_id = cpu_to_le16(filter_id);
  2371. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
  2372. NO_SYNC_WMIFLAG);
  2373. return ret;
  2374. }
  2375. static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
  2376. enum wmix_command_id cmd_id,
  2377. enum wmi_sync_flag sync_flag)
  2378. {
  2379. struct wmix_cmd_hdr *cmd_hdr;
  2380. int ret;
  2381. skb_push(skb, sizeof(struct wmix_cmd_hdr));
  2382. cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
  2383. cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
  2384. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
  2385. return ret;
  2386. }
  2387. int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
  2388. {
  2389. struct sk_buff *skb;
  2390. struct wmix_hb_challenge_resp_cmd *cmd;
  2391. int ret;
  2392. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2393. if (!skb)
  2394. return -ENOMEM;
  2395. cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
  2396. cmd->cookie = cpu_to_le32(cookie);
  2397. cmd->source = cpu_to_le32(source);
  2398. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
  2399. NO_SYNC_WMIFLAG);
  2400. return ret;
  2401. }
  2402. int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
  2403. {
  2404. struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
  2405. struct sk_buff *skb;
  2406. int ret;
  2407. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2408. if (!skb)
  2409. return -ENOMEM;
  2410. cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
  2411. cmd->valid = cpu_to_le32(valid);
  2412. cmd->config = cpu_to_le32(config);
  2413. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
  2414. NO_SYNC_WMIFLAG);
  2415. return ret;
  2416. }
  2417. int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
  2418. {
  2419. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
  2420. }
  2421. int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
  2422. {
  2423. struct sk_buff *skb;
  2424. struct wmi_set_tx_pwr_cmd *cmd;
  2425. int ret;
  2426. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
  2427. if (!skb)
  2428. return -ENOMEM;
  2429. cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
  2430. cmd->dbM = dbM;
  2431. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
  2432. NO_SYNC_WMIFLAG);
  2433. return ret;
  2434. }
  2435. int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
  2436. {
  2437. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
  2438. }
  2439. int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
  2440. {
  2441. return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
  2442. }
  2443. int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
  2444. u8 preamble_policy)
  2445. {
  2446. struct sk_buff *skb;
  2447. struct wmi_set_lpreamble_cmd *cmd;
  2448. int ret;
  2449. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
  2450. if (!skb)
  2451. return -ENOMEM;
  2452. cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
  2453. cmd->status = status;
  2454. cmd->preamble_policy = preamble_policy;
  2455. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
  2456. NO_SYNC_WMIFLAG);
  2457. return ret;
  2458. }
  2459. int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
  2460. {
  2461. struct sk_buff *skb;
  2462. struct wmi_set_rts_cmd *cmd;
  2463. int ret;
  2464. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
  2465. if (!skb)
  2466. return -ENOMEM;
  2467. cmd = (struct wmi_set_rts_cmd *) skb->data;
  2468. cmd->threshold = cpu_to_le16(threshold);
  2469. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
  2470. NO_SYNC_WMIFLAG);
  2471. return ret;
  2472. }
  2473. int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
  2474. {
  2475. struct sk_buff *skb;
  2476. struct wmi_set_wmm_txop_cmd *cmd;
  2477. int ret;
  2478. if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
  2479. return -EINVAL;
  2480. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
  2481. if (!skb)
  2482. return -ENOMEM;
  2483. cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
  2484. cmd->txop_enable = cfg;
  2485. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
  2486. NO_SYNC_WMIFLAG);
  2487. return ret;
  2488. }
  2489. int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
  2490. u8 keep_alive_intvl)
  2491. {
  2492. struct sk_buff *skb;
  2493. struct wmi_set_keepalive_cmd *cmd;
  2494. int ret;
  2495. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2496. if (!skb)
  2497. return -ENOMEM;
  2498. cmd = (struct wmi_set_keepalive_cmd *) skb->data;
  2499. cmd->keep_alive_intvl = keep_alive_intvl;
  2500. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
  2501. NO_SYNC_WMIFLAG);
  2502. if (ret == 0)
  2503. ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
  2504. return ret;
  2505. }
  2506. int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
  2507. enum ieee80211_band band,
  2508. struct ath6kl_htcap *htcap)
  2509. {
  2510. struct sk_buff *skb;
  2511. struct wmi_set_htcap_cmd *cmd;
  2512. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2513. if (!skb)
  2514. return -ENOMEM;
  2515. cmd = (struct wmi_set_htcap_cmd *) skb->data;
  2516. /*
  2517. * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
  2518. * this will be changed in firmware. If at all there is any change in
  2519. * band value, the host needs to be fixed.
  2520. */
  2521. cmd->band = band;
  2522. cmd->ht_enable = !!htcap->ht_enable;
  2523. cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
  2524. cmd->ht40_supported =
  2525. !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  2526. cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
  2527. cmd->intolerant_40mhz =
  2528. !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
  2529. cmd->max_ampdu_len_exp = htcap->ampdu_factor;
  2530. ath6kl_dbg(ATH6KL_DBG_WMI,
  2531. "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
  2532. cmd->band, cmd->ht_enable, cmd->ht40_supported,
  2533. cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
  2534. cmd->max_ampdu_len_exp);
  2535. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
  2536. NO_SYNC_WMIFLAG);
  2537. }
  2538. int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
  2539. {
  2540. struct sk_buff *skb;
  2541. int ret;
  2542. skb = ath6kl_wmi_get_new_buf(len);
  2543. if (!skb)
  2544. return -ENOMEM;
  2545. memcpy(skb->data, buf, len);
  2546. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
  2547. return ret;
  2548. }
  2549. int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
  2550. {
  2551. struct sk_buff *skb;
  2552. struct wmi_mcast_filter_cmd *cmd;
  2553. int ret;
  2554. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2555. if (!skb)
  2556. return -ENOMEM;
  2557. cmd = (struct wmi_mcast_filter_cmd *) skb->data;
  2558. cmd->mcast_all_enable = mc_all_on;
  2559. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
  2560. NO_SYNC_WMIFLAG);
  2561. return ret;
  2562. }
  2563. int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
  2564. u8 *filter, bool add_filter)
  2565. {
  2566. struct sk_buff *skb;
  2567. struct wmi_mcast_filter_add_del_cmd *cmd;
  2568. int ret;
  2569. if ((filter[0] != 0x33 || filter[1] != 0x33) &&
  2570. (filter[0] != 0x01 || filter[1] != 0x00 ||
  2571. filter[2] != 0x5e || filter[3] > 0x7f)) {
  2572. ath6kl_warn("invalid multicast filter address\n");
  2573. return -EINVAL;
  2574. }
  2575. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2576. if (!skb)
  2577. return -ENOMEM;
  2578. cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
  2579. memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
  2580. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2581. add_filter ? WMI_SET_MCAST_FILTER_CMDID :
  2582. WMI_DEL_MCAST_FILTER_CMDID,
  2583. NO_SYNC_WMIFLAG);
  2584. return ret;
  2585. }
  2586. int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
  2587. {
  2588. struct sk_buff *skb;
  2589. struct wmi_sta_bmiss_enhance_cmd *cmd;
  2590. int ret;
  2591. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2592. if (!skb)
  2593. return -ENOMEM;
  2594. cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
  2595. cmd->enable = enhance ? 1 : 0;
  2596. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2597. WMI_STA_BMISS_ENHANCE_CMDID,
  2598. NO_SYNC_WMIFLAG);
  2599. return ret;
  2600. }
  2601. s32 ath6kl_wmi_get_rate(s8 rate_index)
  2602. {
  2603. if (rate_index == RATE_AUTO)
  2604. return 0;
  2605. return wmi_rate_tbl[(u32) rate_index][0];
  2606. }
  2607. static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
  2608. u32 len)
  2609. {
  2610. struct wmi_pmkid_list_reply *reply;
  2611. u32 expected_len;
  2612. if (len < sizeof(struct wmi_pmkid_list_reply))
  2613. return -EINVAL;
  2614. reply = (struct wmi_pmkid_list_reply *)datap;
  2615. expected_len = sizeof(reply->num_pmkid) +
  2616. le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
  2617. if (len < expected_len)
  2618. return -EINVAL;
  2619. return 0;
  2620. }
  2621. static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2622. struct ath6kl_vif *vif)
  2623. {
  2624. struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
  2625. aggr_recv_addba_req_evt(vif, cmd->tid,
  2626. le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
  2627. return 0;
  2628. }
  2629. static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2630. struct ath6kl_vif *vif)
  2631. {
  2632. struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
  2633. aggr_recv_delba_req_evt(vif, cmd->tid);
  2634. return 0;
  2635. }
  2636. /* AP mode functions */
  2637. int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
  2638. struct wmi_connect_cmd *p)
  2639. {
  2640. struct sk_buff *skb;
  2641. struct wmi_connect_cmd *cm;
  2642. int res;
  2643. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2644. if (!skb)
  2645. return -ENOMEM;
  2646. cm = (struct wmi_connect_cmd *) skb->data;
  2647. memcpy(cm, p, sizeof(*cm));
  2648. res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
  2649. NO_SYNC_WMIFLAG);
  2650. ath6kl_dbg(ATH6KL_DBG_WMI,
  2651. "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
  2652. __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
  2653. le32_to_cpu(p->ctrl_flags), res);
  2654. return res;
  2655. }
  2656. int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
  2657. u16 reason)
  2658. {
  2659. struct sk_buff *skb;
  2660. struct wmi_ap_set_mlme_cmd *cm;
  2661. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2662. if (!skb)
  2663. return -ENOMEM;
  2664. cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
  2665. memcpy(cm->mac, mac, ETH_ALEN);
  2666. cm->reason = cpu_to_le16(reason);
  2667. cm->cmd = cmd;
  2668. ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
  2669. cm->reason);
  2670. return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
  2671. NO_SYNC_WMIFLAG);
  2672. }
  2673. int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
  2674. {
  2675. struct sk_buff *skb;
  2676. struct wmi_ap_hidden_ssid_cmd *cmd;
  2677. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2678. if (!skb)
  2679. return -ENOMEM;
  2680. cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
  2681. cmd->hidden_ssid = enable ? 1 : 0;
  2682. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
  2683. NO_SYNC_WMIFLAG);
  2684. }
  2685. /* This command will be used to enable/disable AP uAPSD feature */
  2686. int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
  2687. {
  2688. struct wmi_ap_set_apsd_cmd *cmd;
  2689. struct sk_buff *skb;
  2690. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2691. if (!skb)
  2692. return -ENOMEM;
  2693. cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
  2694. cmd->enable = enable;
  2695. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
  2696. NO_SYNC_WMIFLAG);
  2697. }
  2698. int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
  2699. u16 aid, u16 bitmap, u32 flags)
  2700. {
  2701. struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
  2702. struct sk_buff *skb;
  2703. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2704. if (!skb)
  2705. return -ENOMEM;
  2706. cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
  2707. cmd->aid = cpu_to_le16(aid);
  2708. cmd->bitmap = cpu_to_le16(bitmap);
  2709. cmd->flags = cpu_to_le32(flags);
  2710. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2711. WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
  2712. NO_SYNC_WMIFLAG);
  2713. }
  2714. static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
  2715. struct ath6kl_vif *vif)
  2716. {
  2717. struct wmi_pspoll_event *ev;
  2718. if (len < sizeof(struct wmi_pspoll_event))
  2719. return -EINVAL;
  2720. ev = (struct wmi_pspoll_event *) datap;
  2721. ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
  2722. return 0;
  2723. }
  2724. static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
  2725. struct ath6kl_vif *vif)
  2726. {
  2727. ath6kl_dtimexpiry_event(vif);
  2728. return 0;
  2729. }
  2730. int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
  2731. bool flag)
  2732. {
  2733. struct sk_buff *skb;
  2734. struct wmi_ap_set_pvb_cmd *cmd;
  2735. int ret;
  2736. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
  2737. if (!skb)
  2738. return -ENOMEM;
  2739. cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
  2740. cmd->aid = cpu_to_le16(aid);
  2741. cmd->rsvd = cpu_to_le16(0);
  2742. cmd->flag = cpu_to_le32(flag);
  2743. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
  2744. NO_SYNC_WMIFLAG);
  2745. return 0;
  2746. }
  2747. int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
  2748. u8 rx_meta_ver,
  2749. bool rx_dot11_hdr, bool defrag_on_host)
  2750. {
  2751. struct sk_buff *skb;
  2752. struct wmi_rx_frame_format_cmd *cmd;
  2753. int ret;
  2754. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2755. if (!skb)
  2756. return -ENOMEM;
  2757. cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
  2758. cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
  2759. cmd->defrag_on_host = defrag_on_host ? 1 : 0;
  2760. cmd->meta_ver = rx_meta_ver;
  2761. /* Delete the local aggr state, on host */
  2762. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
  2763. NO_SYNC_WMIFLAG);
  2764. return ret;
  2765. }
  2766. int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
  2767. const u8 *ie, u8 ie_len)
  2768. {
  2769. struct sk_buff *skb;
  2770. struct wmi_set_appie_cmd *p;
  2771. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2772. if (!skb)
  2773. return -ENOMEM;
  2774. ath6kl_dbg(ATH6KL_DBG_WMI,
  2775. "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
  2776. mgmt_frm_type, ie_len);
  2777. p = (struct wmi_set_appie_cmd *) skb->data;
  2778. p->mgmt_frm_type = mgmt_frm_type;
  2779. p->ie_len = ie_len;
  2780. if (ie != NULL && ie_len > 0)
  2781. memcpy(p->ie_info, ie, ie_len);
  2782. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
  2783. NO_SYNC_WMIFLAG);
  2784. }
  2785. int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
  2786. const u8 *ie_info, u8 ie_len)
  2787. {
  2788. struct sk_buff *skb;
  2789. struct wmi_set_ie_cmd *p;
  2790. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2791. if (!skb)
  2792. return -ENOMEM;
  2793. ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
  2794. ie_id, ie_field, ie_len);
  2795. p = (struct wmi_set_ie_cmd *) skb->data;
  2796. p->ie_id = ie_id;
  2797. p->ie_field = ie_field;
  2798. p->ie_len = ie_len;
  2799. if (ie_info && ie_len > 0)
  2800. memcpy(p->ie_info, ie_info, ie_len);
  2801. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
  2802. NO_SYNC_WMIFLAG);
  2803. }
  2804. int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
  2805. {
  2806. struct sk_buff *skb;
  2807. struct wmi_disable_11b_rates_cmd *cmd;
  2808. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2809. if (!skb)
  2810. return -ENOMEM;
  2811. ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
  2812. disable);
  2813. cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
  2814. cmd->disable = disable ? 1 : 0;
  2815. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
  2816. NO_SYNC_WMIFLAG);
  2817. }
  2818. int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
  2819. {
  2820. struct sk_buff *skb;
  2821. struct wmi_remain_on_chnl_cmd *p;
  2822. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2823. if (!skb)
  2824. return -ENOMEM;
  2825. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
  2826. freq, dur);
  2827. p = (struct wmi_remain_on_chnl_cmd *) skb->data;
  2828. p->freq = cpu_to_le32(freq);
  2829. p->duration = cpu_to_le32(dur);
  2830. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
  2831. NO_SYNC_WMIFLAG);
  2832. }
  2833. /* ath6kl_wmi_send_action_cmd is to be deprecated. Use
  2834. * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
  2835. * mgmt operations using station interface.
  2836. */
  2837. static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2838. u32 freq, u32 wait, const u8 *data,
  2839. u16 data_len)
  2840. {
  2841. struct sk_buff *skb;
  2842. struct wmi_send_action_cmd *p;
  2843. u8 *buf;
  2844. if (wait)
  2845. return -EINVAL; /* Offload for wait not supported */
  2846. buf = kmalloc(data_len, GFP_KERNEL);
  2847. if (!buf)
  2848. return -ENOMEM;
  2849. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2850. if (!skb) {
  2851. kfree(buf);
  2852. return -ENOMEM;
  2853. }
  2854. kfree(wmi->last_mgmt_tx_frame);
  2855. memcpy(buf, data, data_len);
  2856. wmi->last_mgmt_tx_frame = buf;
  2857. wmi->last_mgmt_tx_frame_len = data_len;
  2858. ath6kl_dbg(ATH6KL_DBG_WMI,
  2859. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2860. id, freq, wait, data_len);
  2861. p = (struct wmi_send_action_cmd *) skb->data;
  2862. p->id = cpu_to_le32(id);
  2863. p->freq = cpu_to_le32(freq);
  2864. p->wait = cpu_to_le32(wait);
  2865. p->len = cpu_to_le16(data_len);
  2866. memcpy(p->data, data, data_len);
  2867. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
  2868. NO_SYNC_WMIFLAG);
  2869. }
  2870. static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2871. u32 freq, u32 wait, const u8 *data,
  2872. u16 data_len, u32 no_cck)
  2873. {
  2874. struct sk_buff *skb;
  2875. struct wmi_send_mgmt_cmd *p;
  2876. u8 *buf;
  2877. if (wait)
  2878. return -EINVAL; /* Offload for wait not supported */
  2879. buf = kmalloc(data_len, GFP_KERNEL);
  2880. if (!buf)
  2881. return -ENOMEM;
  2882. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2883. if (!skb) {
  2884. kfree(buf);
  2885. return -ENOMEM;
  2886. }
  2887. kfree(wmi->last_mgmt_tx_frame);
  2888. memcpy(buf, data, data_len);
  2889. wmi->last_mgmt_tx_frame = buf;
  2890. wmi->last_mgmt_tx_frame_len = data_len;
  2891. ath6kl_dbg(ATH6KL_DBG_WMI,
  2892. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2893. id, freq, wait, data_len);
  2894. p = (struct wmi_send_mgmt_cmd *) skb->data;
  2895. p->id = cpu_to_le32(id);
  2896. p->freq = cpu_to_le32(freq);
  2897. p->wait = cpu_to_le32(wait);
  2898. p->no_cck = cpu_to_le32(no_cck);
  2899. p->len = cpu_to_le16(data_len);
  2900. memcpy(p->data, data, data_len);
  2901. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
  2902. NO_SYNC_WMIFLAG);
  2903. }
  2904. int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  2905. u32 wait, const u8 *data, u16 data_len,
  2906. u32 no_cck)
  2907. {
  2908. int status;
  2909. struct ath6kl *ar = wmi->parent_dev;
  2910. if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  2911. ar->fw_capabilities)) {
  2912. /*
  2913. * If capable of doing P2P mgmt operations using
  2914. * station interface, send additional information like
  2915. * supported rates to advertise and xmit rates for
  2916. * probe requests
  2917. */
  2918. status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
  2919. wait, data, data_len,
  2920. no_cck);
  2921. } else {
  2922. status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
  2923. wait, data, data_len);
  2924. }
  2925. return status;
  2926. }
  2927. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
  2928. const u8 *dst, const u8 *data,
  2929. u16 data_len)
  2930. {
  2931. struct sk_buff *skb;
  2932. struct wmi_p2p_probe_response_cmd *p;
  2933. size_t cmd_len = sizeof(*p) + data_len;
  2934. if (data_len == 0)
  2935. cmd_len++; /* work around target minimum length requirement */
  2936. skb = ath6kl_wmi_get_new_buf(cmd_len);
  2937. if (!skb)
  2938. return -ENOMEM;
  2939. ath6kl_dbg(ATH6KL_DBG_WMI,
  2940. "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
  2941. freq, dst, data_len);
  2942. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  2943. p->freq = cpu_to_le32(freq);
  2944. memcpy(p->destination_addr, dst, ETH_ALEN);
  2945. p->len = cpu_to_le16(data_len);
  2946. memcpy(p->data, data, data_len);
  2947. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2948. WMI_SEND_PROBE_RESPONSE_CMDID,
  2949. NO_SYNC_WMIFLAG);
  2950. }
  2951. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  2952. {
  2953. struct sk_buff *skb;
  2954. struct wmi_probe_req_report_cmd *p;
  2955. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2956. if (!skb)
  2957. return -ENOMEM;
  2958. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  2959. enable);
  2960. p = (struct wmi_probe_req_report_cmd *) skb->data;
  2961. p->enable = enable ? 1 : 0;
  2962. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
  2963. NO_SYNC_WMIFLAG);
  2964. }
  2965. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
  2966. {
  2967. struct sk_buff *skb;
  2968. struct wmi_get_p2p_info *p;
  2969. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2970. if (!skb)
  2971. return -ENOMEM;
  2972. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  2973. info_req_flags);
  2974. p = (struct wmi_get_p2p_info *) skb->data;
  2975. p->info_req_flags = cpu_to_le32(info_req_flags);
  2976. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
  2977. NO_SYNC_WMIFLAG);
  2978. }
  2979. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
  2980. {
  2981. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  2982. return ath6kl_wmi_simple_cmd(wmi, if_idx,
  2983. WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  2984. }
  2985. int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
  2986. {
  2987. struct sk_buff *skb;
  2988. struct wmi_set_inact_period_cmd *cmd;
  2989. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2990. if (!skb)
  2991. return -ENOMEM;
  2992. cmd = (struct wmi_set_inact_period_cmd *) skb->data;
  2993. cmd->inact_period = cpu_to_le32(inact_timeout);
  2994. cmd->num_null_func = 0;
  2995. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
  2996. NO_SYNC_WMIFLAG);
  2997. }
  2998. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  2999. {
  3000. struct wmix_cmd_hdr *cmd;
  3001. u32 len;
  3002. u16 id;
  3003. u8 *datap;
  3004. int ret = 0;
  3005. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  3006. ath6kl_err("bad packet 1\n");
  3007. return -EINVAL;
  3008. }
  3009. cmd = (struct wmix_cmd_hdr *) skb->data;
  3010. id = le32_to_cpu(cmd->cmd_id);
  3011. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  3012. datap = skb->data;
  3013. len = skb->len;
  3014. switch (id) {
  3015. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  3016. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
  3017. break;
  3018. case WMIX_DBGLOG_EVENTID:
  3019. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
  3020. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  3021. break;
  3022. default:
  3023. ath6kl_warn("unknown cmd id 0x%x\n", id);
  3024. ret = -EINVAL;
  3025. break;
  3026. }
  3027. return ret;
  3028. }
  3029. static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
  3030. {
  3031. return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
  3032. }
  3033. /* Process interface specific wmi events, caller would free the datap */
  3034. static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
  3035. u8 *datap, u32 len)
  3036. {
  3037. struct ath6kl_vif *vif;
  3038. vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
  3039. if (!vif) {
  3040. ath6kl_dbg(ATH6KL_DBG_WMI,
  3041. "Wmi event for unavailable vif, vif_index:%d\n",
  3042. if_idx);
  3043. return -EINVAL;
  3044. }
  3045. switch (cmd_id) {
  3046. case WMI_CONNECT_EVENTID:
  3047. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  3048. return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
  3049. case WMI_DISCONNECT_EVENTID:
  3050. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  3051. return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
  3052. case WMI_TKIP_MICERR_EVENTID:
  3053. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  3054. return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
  3055. case WMI_BSSINFO_EVENTID:
  3056. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  3057. return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
  3058. case WMI_NEIGHBOR_REPORT_EVENTID:
  3059. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  3060. return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
  3061. vif);
  3062. case WMI_SCAN_COMPLETE_EVENTID:
  3063. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  3064. return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
  3065. case WMI_REPORT_STATISTICS_EVENTID:
  3066. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  3067. return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
  3068. case WMI_CAC_EVENTID:
  3069. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  3070. return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
  3071. case WMI_PSPOLL_EVENTID:
  3072. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  3073. return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
  3074. case WMI_DTIMEXPIRY_EVENTID:
  3075. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  3076. return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
  3077. case WMI_ADDBA_REQ_EVENTID:
  3078. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  3079. return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
  3080. case WMI_DELBA_REQ_EVENTID:
  3081. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  3082. return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
  3083. case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
  3084. ath6kl_dbg(ATH6KL_DBG_WMI,
  3085. "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
  3086. return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
  3087. case WMI_REMAIN_ON_CHNL_EVENTID:
  3088. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  3089. return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
  3090. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  3091. ath6kl_dbg(ATH6KL_DBG_WMI,
  3092. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  3093. return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  3094. len, vif);
  3095. case WMI_TX_STATUS_EVENTID:
  3096. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  3097. return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
  3098. case WMI_RX_PROBE_REQ_EVENTID:
  3099. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  3100. return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
  3101. case WMI_RX_ACTION_EVENTID:
  3102. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  3103. return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
  3104. case WMI_TXE_NOTIFY_EVENTID:
  3105. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
  3106. return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
  3107. default:
  3108. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
  3109. return -EINVAL;
  3110. }
  3111. return 0;
  3112. }
  3113. static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
  3114. {
  3115. struct wmi_cmd_hdr *cmd;
  3116. int ret = 0;
  3117. u32 len;
  3118. u16 id;
  3119. u8 if_idx;
  3120. u8 *datap;
  3121. cmd = (struct wmi_cmd_hdr *) skb->data;
  3122. id = le16_to_cpu(cmd->cmd_id);
  3123. if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
  3124. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  3125. datap = skb->data;
  3126. len = skb->len;
  3127. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
  3128. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
  3129. datap, len);
  3130. switch (id) {
  3131. case WMI_GET_BITRATE_CMDID:
  3132. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  3133. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  3134. break;
  3135. case WMI_GET_CHANNEL_LIST_CMDID:
  3136. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  3137. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  3138. break;
  3139. case WMI_GET_TX_PWR_CMDID:
  3140. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  3141. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  3142. break;
  3143. case WMI_READY_EVENTID:
  3144. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  3145. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  3146. break;
  3147. case WMI_PEER_NODE_EVENTID:
  3148. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  3149. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  3150. break;
  3151. case WMI_REGDOMAIN_EVENTID:
  3152. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  3153. ath6kl_wmi_regdomain_event(wmi, datap, len);
  3154. break;
  3155. case WMI_PSTREAM_TIMEOUT_EVENTID:
  3156. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  3157. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  3158. break;
  3159. case WMI_CMDERROR_EVENTID:
  3160. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  3161. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  3162. break;
  3163. case WMI_RSSI_THRESHOLD_EVENTID:
  3164. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  3165. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  3166. break;
  3167. case WMI_ERROR_REPORT_EVENTID:
  3168. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  3169. break;
  3170. case WMI_OPT_RX_FRAME_EVENTID:
  3171. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  3172. /* this event has been deprecated */
  3173. break;
  3174. case WMI_REPORT_ROAM_TBL_EVENTID:
  3175. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  3176. ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
  3177. break;
  3178. case WMI_EXTENSION_EVENTID:
  3179. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  3180. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  3181. break;
  3182. case WMI_CHANNEL_CHANGE_EVENTID:
  3183. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  3184. break;
  3185. case WMI_REPORT_ROAM_DATA_EVENTID:
  3186. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  3187. break;
  3188. case WMI_TEST_EVENTID:
  3189. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  3190. ret = ath6kl_wmi_test_rx(wmi, datap, len);
  3191. break;
  3192. case WMI_GET_FIXRATES_CMDID:
  3193. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  3194. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  3195. break;
  3196. case WMI_TX_RETRY_ERR_EVENTID:
  3197. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  3198. break;
  3199. case WMI_SNR_THRESHOLD_EVENTID:
  3200. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  3201. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  3202. break;
  3203. case WMI_LQ_THRESHOLD_EVENTID:
  3204. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  3205. break;
  3206. case WMI_APLIST_EVENTID:
  3207. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  3208. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  3209. break;
  3210. case WMI_GET_KEEPALIVE_CMDID:
  3211. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  3212. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  3213. break;
  3214. case WMI_GET_WOW_LIST_EVENTID:
  3215. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  3216. break;
  3217. case WMI_GET_PMKID_LIST_EVENTID:
  3218. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  3219. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  3220. break;
  3221. case WMI_SET_PARAMS_REPLY_EVENTID:
  3222. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  3223. break;
  3224. case WMI_ADDBA_RESP_EVENTID:
  3225. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  3226. break;
  3227. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  3228. ath6kl_dbg(ATH6KL_DBG_WMI,
  3229. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  3230. break;
  3231. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  3232. ath6kl_dbg(ATH6KL_DBG_WMI,
  3233. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  3234. break;
  3235. case WMI_TX_COMPLETE_EVENTID:
  3236. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  3237. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  3238. break;
  3239. case WMI_P2P_CAPABILITIES_EVENTID:
  3240. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  3241. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  3242. break;
  3243. case WMI_P2P_INFO_EVENTID:
  3244. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  3245. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  3246. break;
  3247. default:
  3248. /* may be the event is interface specific */
  3249. ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
  3250. break;
  3251. }
  3252. dev_kfree_skb(skb);
  3253. return ret;
  3254. }
  3255. /* Control Path */
  3256. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  3257. {
  3258. if (WARN_ON(skb == NULL))
  3259. return -EINVAL;
  3260. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  3261. ath6kl_err("bad packet 1\n");
  3262. dev_kfree_skb(skb);
  3263. return -EINVAL;
  3264. }
  3265. return ath6kl_wmi_proc_events(wmi, skb);
  3266. }
  3267. void ath6kl_wmi_reset(struct wmi *wmi)
  3268. {
  3269. spin_lock_bh(&wmi->lock);
  3270. wmi->fat_pipe_exist = 0;
  3271. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  3272. spin_unlock_bh(&wmi->lock);
  3273. }
  3274. void *ath6kl_wmi_init(struct ath6kl *dev)
  3275. {
  3276. struct wmi *wmi;
  3277. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  3278. if (!wmi)
  3279. return NULL;
  3280. spin_lock_init(&wmi->lock);
  3281. wmi->parent_dev = dev;
  3282. wmi->pwr_mode = REC_POWER;
  3283. ath6kl_wmi_reset(wmi);
  3284. return wmi;
  3285. }
  3286. void ath6kl_wmi_shutdown(struct wmi *wmi)
  3287. {
  3288. if (!wmi)
  3289. return;
  3290. kfree(wmi->last_mgmt_tx_frame);
  3291. kfree(wmi);
  3292. }