wmi.c 92 KB

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