wmi.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434
  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. {
  1398. struct sk_buff *skb;
  1399. struct wmi_connect_cmd *cc;
  1400. int ret;
  1401. ath6kl_dbg(ATH6KL_DBG_WMI,
  1402. "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
  1403. "type %d dot11_auth %d auth %d pairwise %d group %d\n",
  1404. bssid, channel, ctrl_flags, ssid_len, nw_type,
  1405. dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
  1406. ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
  1407. wmi->traffic_class = 100;
  1408. if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
  1409. return -EINVAL;
  1410. if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
  1411. return -EINVAL;
  1412. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
  1413. if (!skb)
  1414. return -ENOMEM;
  1415. cc = (struct wmi_connect_cmd *) skb->data;
  1416. if (ssid_len)
  1417. memcpy(cc->ssid, ssid, ssid_len);
  1418. cc->ssid_len = ssid_len;
  1419. cc->nw_type = nw_type;
  1420. cc->dot11_auth_mode = dot11_auth_mode;
  1421. cc->auth_mode = auth_mode;
  1422. cc->prwise_crypto_type = pairwise_crypto;
  1423. cc->prwise_crypto_len = pairwise_crypto_len;
  1424. cc->grp_crypto_type = group_crypto;
  1425. cc->grp_crypto_len = group_crypto_len;
  1426. cc->ch = cpu_to_le16(channel);
  1427. cc->ctrl_flags = cpu_to_le32(ctrl_flags);
  1428. if (bssid != NULL)
  1429. memcpy(cc->bssid, bssid, ETH_ALEN);
  1430. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
  1431. NO_SYNC_WMIFLAG);
  1432. return ret;
  1433. }
  1434. int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
  1435. u16 channel)
  1436. {
  1437. struct sk_buff *skb;
  1438. struct wmi_reconnect_cmd *cc;
  1439. int ret;
  1440. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
  1441. bssid, channel);
  1442. wmi->traffic_class = 100;
  1443. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
  1444. if (!skb)
  1445. return -ENOMEM;
  1446. cc = (struct wmi_reconnect_cmd *) skb->data;
  1447. cc->channel = cpu_to_le16(channel);
  1448. if (bssid != NULL)
  1449. memcpy(cc->bssid, bssid, ETH_ALEN);
  1450. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
  1451. NO_SYNC_WMIFLAG);
  1452. return ret;
  1453. }
  1454. int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
  1455. {
  1456. int ret;
  1457. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
  1458. wmi->traffic_class = 100;
  1459. /* Disconnect command does not need to do a SYNC before. */
  1460. ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
  1461. return ret;
  1462. }
  1463. int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
  1464. enum wmi_scan_type scan_type,
  1465. u32 force_fgscan, u32 is_legacy,
  1466. u32 home_dwell_time, u32 force_scan_interval,
  1467. s8 num_chan, u16 *ch_list)
  1468. {
  1469. struct sk_buff *skb;
  1470. struct wmi_start_scan_cmd *sc;
  1471. s8 size;
  1472. int i, ret;
  1473. size = sizeof(struct wmi_start_scan_cmd);
  1474. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1475. return -EINVAL;
  1476. if (num_chan > WMI_MAX_CHANNELS)
  1477. return -EINVAL;
  1478. if (num_chan)
  1479. size += sizeof(u16) * (num_chan - 1);
  1480. skb = ath6kl_wmi_get_new_buf(size);
  1481. if (!skb)
  1482. return -ENOMEM;
  1483. sc = (struct wmi_start_scan_cmd *) skb->data;
  1484. sc->scan_type = scan_type;
  1485. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1486. sc->is_legacy = cpu_to_le32(is_legacy);
  1487. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1488. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1489. sc->num_ch = num_chan;
  1490. for (i = 0; i < num_chan; i++)
  1491. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1492. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
  1493. NO_SYNC_WMIFLAG);
  1494. return ret;
  1495. }
  1496. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
  1497. u16 fg_start_sec,
  1498. u16 fg_end_sec, u16 bg_sec,
  1499. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1500. u16 pas_chdw_msec, u8 short_scan_ratio,
  1501. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1502. u16 maxact_scan_per_ssid)
  1503. {
  1504. struct sk_buff *skb;
  1505. struct wmi_scan_params_cmd *sc;
  1506. int ret;
  1507. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1508. if (!skb)
  1509. return -ENOMEM;
  1510. sc = (struct wmi_scan_params_cmd *) skb->data;
  1511. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1512. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1513. sc->bg_period = cpu_to_le16(bg_sec);
  1514. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1515. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1516. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1517. sc->short_scan_ratio = short_scan_ratio;
  1518. sc->scan_ctrl_flags = scan_ctrl_flag;
  1519. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1520. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1521. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1522. NO_SYNC_WMIFLAG);
  1523. return ret;
  1524. }
  1525. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
  1526. {
  1527. struct sk_buff *skb;
  1528. struct wmi_bss_filter_cmd *cmd;
  1529. int ret;
  1530. if (filter >= LAST_BSS_FILTER)
  1531. return -EINVAL;
  1532. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1533. if (!skb)
  1534. return -ENOMEM;
  1535. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1536. cmd->bss_filter = filter;
  1537. cmd->ie_mask = cpu_to_le32(ie_mask);
  1538. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
  1539. NO_SYNC_WMIFLAG);
  1540. return ret;
  1541. }
  1542. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
  1543. u8 ssid_len, u8 *ssid)
  1544. {
  1545. struct sk_buff *skb;
  1546. struct wmi_probed_ssid_cmd *cmd;
  1547. int ret;
  1548. if (index > MAX_PROBED_SSID_INDEX)
  1549. return -EINVAL;
  1550. if (ssid_len > sizeof(cmd->ssid))
  1551. return -EINVAL;
  1552. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1553. return -EINVAL;
  1554. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1555. return -EINVAL;
  1556. if (flag & SPECIFIC_SSID_FLAG)
  1557. wmi->is_probe_ssid = true;
  1558. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1559. if (!skb)
  1560. return -ENOMEM;
  1561. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1562. cmd->entry_index = index;
  1563. cmd->flag = flag;
  1564. cmd->ssid_len = ssid_len;
  1565. memcpy(cmd->ssid, ssid, ssid_len);
  1566. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
  1567. NO_SYNC_WMIFLAG);
  1568. return ret;
  1569. }
  1570. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
  1571. u16 listen_interval,
  1572. u16 listen_beacons)
  1573. {
  1574. struct sk_buff *skb;
  1575. struct wmi_listen_int_cmd *cmd;
  1576. int ret;
  1577. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1578. if (!skb)
  1579. return -ENOMEM;
  1580. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1581. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1582. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1583. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
  1584. NO_SYNC_WMIFLAG);
  1585. return ret;
  1586. }
  1587. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
  1588. {
  1589. struct sk_buff *skb;
  1590. struct wmi_power_mode_cmd *cmd;
  1591. int ret;
  1592. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1593. if (!skb)
  1594. return -ENOMEM;
  1595. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1596. cmd->pwr_mode = pwr_mode;
  1597. wmi->pwr_mode = pwr_mode;
  1598. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
  1599. NO_SYNC_WMIFLAG);
  1600. return ret;
  1601. }
  1602. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
  1603. u16 ps_poll_num, u16 dtim_policy,
  1604. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1605. u16 ps_fail_event_policy)
  1606. {
  1607. struct sk_buff *skb;
  1608. struct wmi_power_params_cmd *pm;
  1609. int ret;
  1610. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1611. if (!skb)
  1612. return -ENOMEM;
  1613. pm = (struct wmi_power_params_cmd *)skb->data;
  1614. pm->idle_period = cpu_to_le16(idle_period);
  1615. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1616. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1617. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1618. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1619. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1620. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
  1621. NO_SYNC_WMIFLAG);
  1622. return ret;
  1623. }
  1624. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
  1625. {
  1626. struct sk_buff *skb;
  1627. struct wmi_disc_timeout_cmd *cmd;
  1628. int ret;
  1629. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1630. if (!skb)
  1631. return -ENOMEM;
  1632. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1633. cmd->discon_timeout = timeout;
  1634. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1635. NO_SYNC_WMIFLAG);
  1636. if (ret == 0)
  1637. ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
  1638. return ret;
  1639. }
  1640. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
  1641. enum crypto_type key_type,
  1642. u8 key_usage, u8 key_len,
  1643. u8 *key_rsc, unsigned int key_rsc_len,
  1644. u8 *key_material,
  1645. u8 key_op_ctrl, u8 *mac_addr,
  1646. enum wmi_sync_flag sync_flag)
  1647. {
  1648. struct sk_buff *skb;
  1649. struct wmi_add_cipher_key_cmd *cmd;
  1650. int ret;
  1651. ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
  1652. "key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1653. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1654. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1655. (key_material == NULL) || key_rsc_len > 8)
  1656. return -EINVAL;
  1657. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1658. return -EINVAL;
  1659. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1660. if (!skb)
  1661. return -ENOMEM;
  1662. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1663. cmd->key_index = key_index;
  1664. cmd->key_type = key_type;
  1665. cmd->key_usage = key_usage;
  1666. cmd->key_len = key_len;
  1667. memcpy(cmd->key, key_material, key_len);
  1668. if (key_rsc != NULL)
  1669. memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
  1670. cmd->key_op_ctrl = key_op_ctrl;
  1671. if (mac_addr)
  1672. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1673. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1674. sync_flag);
  1675. return ret;
  1676. }
  1677. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
  1678. {
  1679. struct sk_buff *skb;
  1680. struct wmi_add_krk_cmd *cmd;
  1681. int ret;
  1682. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1683. if (!skb)
  1684. return -ENOMEM;
  1685. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1686. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1687. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
  1688. NO_SYNC_WMIFLAG);
  1689. return ret;
  1690. }
  1691. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
  1692. {
  1693. struct sk_buff *skb;
  1694. struct wmi_delete_cipher_key_cmd *cmd;
  1695. int ret;
  1696. if (key_index > WMI_MAX_KEY_INDEX)
  1697. return -EINVAL;
  1698. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1699. if (!skb)
  1700. return -ENOMEM;
  1701. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1702. cmd->key_index = key_index;
  1703. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1704. NO_SYNC_WMIFLAG);
  1705. return ret;
  1706. }
  1707. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
  1708. const u8 *pmkid, bool set)
  1709. {
  1710. struct sk_buff *skb;
  1711. struct wmi_setpmkid_cmd *cmd;
  1712. int ret;
  1713. if (bssid == NULL)
  1714. return -EINVAL;
  1715. if (set && pmkid == NULL)
  1716. return -EINVAL;
  1717. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1718. if (!skb)
  1719. return -ENOMEM;
  1720. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1721. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1722. if (set) {
  1723. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1724. cmd->enable = PMKID_ENABLE;
  1725. } else {
  1726. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1727. cmd->enable = PMKID_DISABLE;
  1728. }
  1729. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
  1730. NO_SYNC_WMIFLAG);
  1731. return ret;
  1732. }
  1733. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1734. enum htc_endpoint_id ep_id, u8 if_idx)
  1735. {
  1736. struct wmi_data_hdr *data_hdr;
  1737. int ret;
  1738. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
  1739. return -EINVAL;
  1740. skb_push(skb, sizeof(struct wmi_data_hdr));
  1741. data_hdr = (struct wmi_data_hdr *) skb->data;
  1742. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1743. data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  1744. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1745. return ret;
  1746. }
  1747. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
  1748. {
  1749. struct sk_buff *skb;
  1750. struct wmi_sync_cmd *cmd;
  1751. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1752. enum htc_endpoint_id ep_id;
  1753. u8 index, num_pri_streams = 0;
  1754. int ret = 0;
  1755. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  1756. spin_lock_bh(&wmi->lock);
  1757. for (index = 0; index < WMM_NUM_AC; index++) {
  1758. if (wmi->fat_pipe_exist & (1 << index)) {
  1759. num_pri_streams++;
  1760. data_sync_bufs[num_pri_streams - 1].traffic_class =
  1761. index;
  1762. }
  1763. }
  1764. spin_unlock_bh(&wmi->lock);
  1765. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1766. if (!skb) {
  1767. ret = -ENOMEM;
  1768. goto free_skb;
  1769. }
  1770. cmd = (struct wmi_sync_cmd *) skb->data;
  1771. /*
  1772. * In the SYNC cmd sent on the control Ep, send a bitmap
  1773. * of the data eps on which the Data Sync will be sent
  1774. */
  1775. cmd->data_sync_map = wmi->fat_pipe_exist;
  1776. for (index = 0; index < num_pri_streams; index++) {
  1777. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  1778. if (data_sync_bufs[index].skb == NULL) {
  1779. ret = -ENOMEM;
  1780. break;
  1781. }
  1782. }
  1783. /*
  1784. * If buffer allocation for any of the dataSync fails,
  1785. * then do not send the Synchronize cmd on the control ep
  1786. */
  1787. if (ret)
  1788. goto free_skb;
  1789. /*
  1790. * Send sync cmd followed by sync data messages on all
  1791. * endpoints being used
  1792. */
  1793. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
  1794. NO_SYNC_WMIFLAG);
  1795. if (ret)
  1796. goto free_skb;
  1797. /* cmd buffer sent, we no longer own it */
  1798. skb = NULL;
  1799. for (index = 0; index < num_pri_streams; index++) {
  1800. if (WARN_ON(!data_sync_bufs[index].skb))
  1801. break;
  1802. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  1803. data_sync_bufs[index].
  1804. traffic_class);
  1805. ret =
  1806. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  1807. ep_id, if_idx);
  1808. if (ret)
  1809. break;
  1810. data_sync_bufs[index].skb = NULL;
  1811. }
  1812. free_skb:
  1813. /* free up any resources left over (possibly due to an error) */
  1814. if (skb)
  1815. dev_kfree_skb(skb);
  1816. for (index = 0; index < num_pri_streams; index++) {
  1817. if (data_sync_bufs[index].skb != NULL) {
  1818. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
  1819. skb);
  1820. }
  1821. }
  1822. return ret;
  1823. }
  1824. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
  1825. struct wmi_create_pstream_cmd *params)
  1826. {
  1827. struct sk_buff *skb;
  1828. struct wmi_create_pstream_cmd *cmd;
  1829. u8 fatpipe_exist_for_ac = 0;
  1830. s32 min_phy = 0;
  1831. s32 nominal_phy = 0;
  1832. int ret;
  1833. if (!((params->user_pri < 8) &&
  1834. (params->user_pri <= 0x7) &&
  1835. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  1836. (params->traffic_direc == UPLINK_TRAFFIC ||
  1837. params->traffic_direc == DNLINK_TRAFFIC ||
  1838. params->traffic_direc == BIDIR_TRAFFIC) &&
  1839. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  1840. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  1841. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  1842. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  1843. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  1844. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  1845. params->tsid <= WMI_MAX_THINSTREAM))) {
  1846. return -EINVAL;
  1847. }
  1848. /*
  1849. * Check nominal PHY rate is >= minimalPHY,
  1850. * so that DUT can allow TSRS IE
  1851. */
  1852. /* Get the physical rate (units of bps) */
  1853. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  1854. /* Check minimal phy < nominal phy rate */
  1855. if (params->nominal_phy >= min_phy) {
  1856. /* unit of 500 kbps */
  1857. nominal_phy = (params->nominal_phy * 1000) / 500;
  1858. ath6kl_dbg(ATH6KL_DBG_WMI,
  1859. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  1860. min_phy, nominal_phy);
  1861. params->nominal_phy = nominal_phy;
  1862. } else {
  1863. params->nominal_phy = 0;
  1864. }
  1865. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1866. if (!skb)
  1867. return -ENOMEM;
  1868. ath6kl_dbg(ATH6KL_DBG_WMI,
  1869. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  1870. params->traffic_class, params->tsid);
  1871. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  1872. memcpy(cmd, params, sizeof(*cmd));
  1873. /* This is an implicitly created Fat pipe */
  1874. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  1875. spin_lock_bh(&wmi->lock);
  1876. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  1877. (1 << params->traffic_class));
  1878. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  1879. spin_unlock_bh(&wmi->lock);
  1880. } else {
  1881. /* explicitly created thin stream within a fat pipe */
  1882. spin_lock_bh(&wmi->lock);
  1883. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  1884. (1 << params->traffic_class));
  1885. wmi->stream_exist_for_ac[params->traffic_class] |=
  1886. (1 << params->tsid);
  1887. /*
  1888. * If a thinstream becomes active, the fat pipe automatically
  1889. * becomes active
  1890. */
  1891. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  1892. spin_unlock_bh(&wmi->lock);
  1893. }
  1894. /*
  1895. * Indicate activty change to driver layer only if this is the
  1896. * first TSID to get created in this AC explicitly or an implicit
  1897. * fat pipe is getting created.
  1898. */
  1899. if (!fatpipe_exist_for_ac)
  1900. ath6kl_indicate_tx_activity(wmi->parent_dev,
  1901. params->traffic_class, true);
  1902. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
  1903. NO_SYNC_WMIFLAG);
  1904. return ret;
  1905. }
  1906. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
  1907. u8 tsid)
  1908. {
  1909. struct sk_buff *skb;
  1910. struct wmi_delete_pstream_cmd *cmd;
  1911. u16 active_tsids = 0;
  1912. int ret;
  1913. if (traffic_class > 3) {
  1914. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  1915. return -EINVAL;
  1916. }
  1917. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1918. if (!skb)
  1919. return -ENOMEM;
  1920. cmd = (struct wmi_delete_pstream_cmd *) skb->data;
  1921. cmd->traffic_class = traffic_class;
  1922. cmd->tsid = tsid;
  1923. spin_lock_bh(&wmi->lock);
  1924. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  1925. spin_unlock_bh(&wmi->lock);
  1926. if (!(active_tsids & (1 << tsid))) {
  1927. dev_kfree_skb(skb);
  1928. ath6kl_dbg(ATH6KL_DBG_WMI,
  1929. "TSID %d doesn't exist for traffic class: %d\n",
  1930. tsid, traffic_class);
  1931. return -ENODATA;
  1932. }
  1933. ath6kl_dbg(ATH6KL_DBG_WMI,
  1934. "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
  1935. traffic_class, tsid);
  1936. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
  1937. SYNC_BEFORE_WMIFLAG);
  1938. spin_lock_bh(&wmi->lock);
  1939. wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
  1940. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  1941. spin_unlock_bh(&wmi->lock);
  1942. /*
  1943. * Indicate stream inactivity to driver layer only if all tsids
  1944. * within this AC are deleted.
  1945. */
  1946. if (!active_tsids) {
  1947. ath6kl_indicate_tx_activity(wmi->parent_dev,
  1948. traffic_class, false);
  1949. wmi->fat_pipe_exist &= ~(1 << traffic_class);
  1950. }
  1951. return ret;
  1952. }
  1953. int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
  1954. {
  1955. struct sk_buff *skb;
  1956. struct wmi_set_ip_cmd *cmd;
  1957. int ret;
  1958. /* Multicast address are not valid */
  1959. if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
  1960. (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
  1961. return -EINVAL;
  1962. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
  1963. if (!skb)
  1964. return -ENOMEM;
  1965. cmd = (struct wmi_set_ip_cmd *) skb->data;
  1966. memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
  1967. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_IP_CMDID,
  1968. NO_SYNC_WMIFLAG);
  1969. return ret;
  1970. }
  1971. static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
  1972. {
  1973. u16 active_tsids;
  1974. u8 stream_exist;
  1975. int i;
  1976. /*
  1977. * Relinquish credits from all implicitly created pstreams
  1978. * since when we go to sleep. If user created explicit
  1979. * thinstreams exists with in a fatpipe leave them intact
  1980. * for the user to delete.
  1981. */
  1982. spin_lock_bh(&wmi->lock);
  1983. stream_exist = wmi->fat_pipe_exist;
  1984. spin_unlock_bh(&wmi->lock);
  1985. for (i = 0; i < WMM_NUM_AC; i++) {
  1986. if (stream_exist & (1 << i)) {
  1987. /*
  1988. * FIXME: Is this lock & unlock inside
  1989. * for loop correct? may need rework.
  1990. */
  1991. spin_lock_bh(&wmi->lock);
  1992. active_tsids = wmi->stream_exist_for_ac[i];
  1993. spin_unlock_bh(&wmi->lock);
  1994. /*
  1995. * If there are no user created thin streams
  1996. * delete the fatpipe
  1997. */
  1998. if (!active_tsids) {
  1999. stream_exist &= ~(1 << i);
  2000. /*
  2001. * Indicate inactivity to driver layer for
  2002. * this fatpipe (pstream)
  2003. */
  2004. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2005. i, false);
  2006. }
  2007. }
  2008. }
  2009. /* FIXME: Can we do this assignment without locking ? */
  2010. spin_lock_bh(&wmi->lock);
  2011. wmi->fat_pipe_exist = stream_exist;
  2012. spin_unlock_bh(&wmi->lock);
  2013. }
  2014. int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
  2015. enum ath6kl_host_mode host_mode)
  2016. {
  2017. struct sk_buff *skb;
  2018. struct wmi_set_host_sleep_mode_cmd *cmd;
  2019. int ret;
  2020. if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
  2021. (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
  2022. ath6kl_err("invalid host sleep mode: %d\n", host_mode);
  2023. return -EINVAL;
  2024. }
  2025. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2026. if (!skb)
  2027. return -ENOMEM;
  2028. cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
  2029. if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
  2030. ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
  2031. cmd->asleep = cpu_to_le32(1);
  2032. } else
  2033. cmd->awake = cpu_to_le32(1);
  2034. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2035. WMI_SET_HOST_SLEEP_MODE_CMDID,
  2036. NO_SYNC_WMIFLAG);
  2037. return ret;
  2038. }
  2039. int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
  2040. enum ath6kl_wow_mode wow_mode,
  2041. u32 filter, u16 host_req_delay)
  2042. {
  2043. struct sk_buff *skb;
  2044. struct wmi_set_wow_mode_cmd *cmd;
  2045. int ret;
  2046. if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
  2047. wow_mode != ATH6KL_WOW_MODE_DISABLE) {
  2048. ath6kl_err("invalid wow mode: %d\n", wow_mode);
  2049. return -EINVAL;
  2050. }
  2051. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2052. if (!skb)
  2053. return -ENOMEM;
  2054. cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
  2055. cmd->enable_wow = cpu_to_le32(wow_mode);
  2056. cmd->filter = cpu_to_le32(filter);
  2057. cmd->host_req_delay = cpu_to_le16(host_req_delay);
  2058. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
  2059. NO_SYNC_WMIFLAG);
  2060. return ret;
  2061. }
  2062. int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2063. u8 list_id, u8 filter_size,
  2064. u8 filter_offset, u8 *filter, u8 *mask)
  2065. {
  2066. struct sk_buff *skb;
  2067. struct wmi_add_wow_pattern_cmd *cmd;
  2068. u16 size;
  2069. u8 *filter_mask;
  2070. int ret;
  2071. /*
  2072. * Allocate additional memory in the buffer to hold
  2073. * filter and mask value, which is twice of filter_size.
  2074. */
  2075. size = sizeof(*cmd) + (2 * filter_size);
  2076. skb = ath6kl_wmi_get_new_buf(size);
  2077. if (!skb)
  2078. return -ENOMEM;
  2079. cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
  2080. cmd->filter_list_id = list_id;
  2081. cmd->filter_size = filter_size;
  2082. cmd->filter_offset = filter_offset;
  2083. memcpy(cmd->filter, filter, filter_size);
  2084. filter_mask = (u8 *) (cmd->filter + filter_size);
  2085. memcpy(filter_mask, mask, filter_size);
  2086. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
  2087. NO_SYNC_WMIFLAG);
  2088. return ret;
  2089. }
  2090. int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2091. u16 list_id, u16 filter_id)
  2092. {
  2093. struct sk_buff *skb;
  2094. struct wmi_del_wow_pattern_cmd *cmd;
  2095. int ret;
  2096. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2097. if (!skb)
  2098. return -ENOMEM;
  2099. cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
  2100. cmd->filter_list_id = cpu_to_le16(list_id);
  2101. cmd->filter_id = cpu_to_le16(filter_id);
  2102. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
  2103. NO_SYNC_WMIFLAG);
  2104. return ret;
  2105. }
  2106. static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
  2107. enum wmix_command_id cmd_id,
  2108. enum wmi_sync_flag sync_flag)
  2109. {
  2110. struct wmix_cmd_hdr *cmd_hdr;
  2111. int ret;
  2112. skb_push(skb, sizeof(struct wmix_cmd_hdr));
  2113. cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
  2114. cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
  2115. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
  2116. return ret;
  2117. }
  2118. int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
  2119. {
  2120. struct sk_buff *skb;
  2121. struct wmix_hb_challenge_resp_cmd *cmd;
  2122. int ret;
  2123. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2124. if (!skb)
  2125. return -ENOMEM;
  2126. cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
  2127. cmd->cookie = cpu_to_le32(cookie);
  2128. cmd->source = cpu_to_le32(source);
  2129. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
  2130. NO_SYNC_WMIFLAG);
  2131. return ret;
  2132. }
  2133. int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
  2134. {
  2135. struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
  2136. struct sk_buff *skb;
  2137. int ret;
  2138. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2139. if (!skb)
  2140. return -ENOMEM;
  2141. cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
  2142. cmd->valid = cpu_to_le32(valid);
  2143. cmd->config = cpu_to_le32(config);
  2144. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
  2145. NO_SYNC_WMIFLAG);
  2146. return ret;
  2147. }
  2148. int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
  2149. {
  2150. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
  2151. }
  2152. int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
  2153. {
  2154. struct sk_buff *skb;
  2155. struct wmi_set_tx_pwr_cmd *cmd;
  2156. int ret;
  2157. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
  2158. if (!skb)
  2159. return -ENOMEM;
  2160. cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
  2161. cmd->dbM = dbM;
  2162. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
  2163. NO_SYNC_WMIFLAG);
  2164. return ret;
  2165. }
  2166. int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
  2167. {
  2168. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
  2169. }
  2170. int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
  2171. {
  2172. return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
  2173. }
  2174. int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
  2175. u8 preamble_policy)
  2176. {
  2177. struct sk_buff *skb;
  2178. struct wmi_set_lpreamble_cmd *cmd;
  2179. int ret;
  2180. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
  2181. if (!skb)
  2182. return -ENOMEM;
  2183. cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
  2184. cmd->status = status;
  2185. cmd->preamble_policy = preamble_policy;
  2186. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
  2187. NO_SYNC_WMIFLAG);
  2188. return ret;
  2189. }
  2190. int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
  2191. {
  2192. struct sk_buff *skb;
  2193. struct wmi_set_rts_cmd *cmd;
  2194. int ret;
  2195. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
  2196. if (!skb)
  2197. return -ENOMEM;
  2198. cmd = (struct wmi_set_rts_cmd *) skb->data;
  2199. cmd->threshold = cpu_to_le16(threshold);
  2200. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
  2201. NO_SYNC_WMIFLAG);
  2202. return ret;
  2203. }
  2204. int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
  2205. {
  2206. struct sk_buff *skb;
  2207. struct wmi_set_wmm_txop_cmd *cmd;
  2208. int ret;
  2209. if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
  2210. return -EINVAL;
  2211. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
  2212. if (!skb)
  2213. return -ENOMEM;
  2214. cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
  2215. cmd->txop_enable = cfg;
  2216. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
  2217. NO_SYNC_WMIFLAG);
  2218. return ret;
  2219. }
  2220. int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
  2221. u8 keep_alive_intvl)
  2222. {
  2223. struct sk_buff *skb;
  2224. struct wmi_set_keepalive_cmd *cmd;
  2225. int ret;
  2226. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2227. if (!skb)
  2228. return -ENOMEM;
  2229. cmd = (struct wmi_set_keepalive_cmd *) skb->data;
  2230. cmd->keep_alive_intvl = keep_alive_intvl;
  2231. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
  2232. NO_SYNC_WMIFLAG);
  2233. if (ret == 0)
  2234. ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
  2235. return ret;
  2236. }
  2237. int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
  2238. {
  2239. struct sk_buff *skb;
  2240. int ret;
  2241. skb = ath6kl_wmi_get_new_buf(len);
  2242. if (!skb)
  2243. return -ENOMEM;
  2244. memcpy(skb->data, buf, len);
  2245. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
  2246. return ret;
  2247. }
  2248. s32 ath6kl_wmi_get_rate(s8 rate_index)
  2249. {
  2250. if (rate_index == RATE_AUTO)
  2251. return 0;
  2252. return wmi_rate_tbl[(u32) rate_index][0];
  2253. }
  2254. static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
  2255. u32 len)
  2256. {
  2257. struct wmi_pmkid_list_reply *reply;
  2258. u32 expected_len;
  2259. if (len < sizeof(struct wmi_pmkid_list_reply))
  2260. return -EINVAL;
  2261. reply = (struct wmi_pmkid_list_reply *)datap;
  2262. expected_len = sizeof(reply->num_pmkid) +
  2263. le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
  2264. if (len < expected_len)
  2265. return -EINVAL;
  2266. return 0;
  2267. }
  2268. static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2269. struct ath6kl_vif *vif)
  2270. {
  2271. struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
  2272. aggr_recv_addba_req_evt(vif, cmd->tid,
  2273. le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
  2274. return 0;
  2275. }
  2276. static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2277. struct ath6kl_vif *vif)
  2278. {
  2279. struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
  2280. aggr_recv_delba_req_evt(vif, cmd->tid);
  2281. return 0;
  2282. }
  2283. /* AP mode functions */
  2284. int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
  2285. struct wmi_connect_cmd *p)
  2286. {
  2287. struct sk_buff *skb;
  2288. struct wmi_connect_cmd *cm;
  2289. int res;
  2290. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2291. if (!skb)
  2292. return -ENOMEM;
  2293. cm = (struct wmi_connect_cmd *) skb->data;
  2294. memcpy(cm, p, sizeof(*cm));
  2295. res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
  2296. NO_SYNC_WMIFLAG);
  2297. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
  2298. "ctrl_flags=0x%x-> res=%d\n",
  2299. __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
  2300. le32_to_cpu(p->ctrl_flags), res);
  2301. return res;
  2302. }
  2303. int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
  2304. u16 reason)
  2305. {
  2306. struct sk_buff *skb;
  2307. struct wmi_ap_set_mlme_cmd *cm;
  2308. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2309. if (!skb)
  2310. return -ENOMEM;
  2311. cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
  2312. memcpy(cm->mac, mac, ETH_ALEN);
  2313. cm->reason = cpu_to_le16(reason);
  2314. cm->cmd = cmd;
  2315. return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
  2316. NO_SYNC_WMIFLAG);
  2317. }
  2318. static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
  2319. struct ath6kl_vif *vif)
  2320. {
  2321. struct wmi_pspoll_event *ev;
  2322. if (len < sizeof(struct wmi_pspoll_event))
  2323. return -EINVAL;
  2324. ev = (struct wmi_pspoll_event *) datap;
  2325. ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
  2326. return 0;
  2327. }
  2328. static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
  2329. struct ath6kl_vif *vif)
  2330. {
  2331. ath6kl_dtimexpiry_event(vif);
  2332. return 0;
  2333. }
  2334. int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
  2335. bool flag)
  2336. {
  2337. struct sk_buff *skb;
  2338. struct wmi_ap_set_pvb_cmd *cmd;
  2339. int ret;
  2340. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
  2341. if (!skb)
  2342. return -ENOMEM;
  2343. cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
  2344. cmd->aid = cpu_to_le16(aid);
  2345. cmd->rsvd = cpu_to_le16(0);
  2346. cmd->flag = cpu_to_le32(flag);
  2347. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
  2348. NO_SYNC_WMIFLAG);
  2349. return 0;
  2350. }
  2351. int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
  2352. u8 rx_meta_ver,
  2353. bool rx_dot11_hdr, bool defrag_on_host)
  2354. {
  2355. struct sk_buff *skb;
  2356. struct wmi_rx_frame_format_cmd *cmd;
  2357. int ret;
  2358. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2359. if (!skb)
  2360. return -ENOMEM;
  2361. cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
  2362. cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
  2363. cmd->defrag_on_host = defrag_on_host ? 1 : 0;
  2364. cmd->meta_ver = rx_meta_ver;
  2365. /* Delete the local aggr state, on host */
  2366. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
  2367. NO_SYNC_WMIFLAG);
  2368. return ret;
  2369. }
  2370. int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
  2371. const u8 *ie, u8 ie_len)
  2372. {
  2373. struct sk_buff *skb;
  2374. struct wmi_set_appie_cmd *p;
  2375. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2376. if (!skb)
  2377. return -ENOMEM;
  2378. ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
  2379. "ie_len=%u\n", mgmt_frm_type, ie_len);
  2380. p = (struct wmi_set_appie_cmd *) skb->data;
  2381. p->mgmt_frm_type = mgmt_frm_type;
  2382. p->ie_len = ie_len;
  2383. if (ie != NULL && ie_len > 0)
  2384. memcpy(p->ie_info, ie, ie_len);
  2385. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
  2386. NO_SYNC_WMIFLAG);
  2387. }
  2388. int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
  2389. {
  2390. struct sk_buff *skb;
  2391. struct wmi_disable_11b_rates_cmd *cmd;
  2392. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2393. if (!skb)
  2394. return -ENOMEM;
  2395. ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
  2396. disable);
  2397. cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
  2398. cmd->disable = disable ? 1 : 0;
  2399. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
  2400. NO_SYNC_WMIFLAG);
  2401. }
  2402. int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
  2403. {
  2404. struct sk_buff *skb;
  2405. struct wmi_remain_on_chnl_cmd *p;
  2406. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2407. if (!skb)
  2408. return -ENOMEM;
  2409. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
  2410. freq, dur);
  2411. p = (struct wmi_remain_on_chnl_cmd *) skb->data;
  2412. p->freq = cpu_to_le32(freq);
  2413. p->duration = cpu_to_le32(dur);
  2414. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
  2415. NO_SYNC_WMIFLAG);
  2416. }
  2417. int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  2418. u32 wait, const u8 *data, u16 data_len)
  2419. {
  2420. struct sk_buff *skb;
  2421. struct wmi_send_action_cmd *p;
  2422. u8 *buf;
  2423. if (wait)
  2424. return -EINVAL; /* Offload for wait not supported */
  2425. buf = kmalloc(data_len, GFP_KERNEL);
  2426. if (!buf)
  2427. return -ENOMEM;
  2428. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2429. if (!skb) {
  2430. kfree(buf);
  2431. return -ENOMEM;
  2432. }
  2433. kfree(wmi->last_mgmt_tx_frame);
  2434. memcpy(buf, data, data_len);
  2435. wmi->last_mgmt_tx_frame = buf;
  2436. wmi->last_mgmt_tx_frame_len = data_len;
  2437. ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
  2438. "len=%u\n", id, freq, wait, data_len);
  2439. p = (struct wmi_send_action_cmd *) skb->data;
  2440. p->id = cpu_to_le32(id);
  2441. p->freq = cpu_to_le32(freq);
  2442. p->wait = cpu_to_le32(wait);
  2443. p->len = cpu_to_le16(data_len);
  2444. memcpy(p->data, data, data_len);
  2445. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
  2446. NO_SYNC_WMIFLAG);
  2447. }
  2448. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
  2449. const u8 *dst, const u8 *data,
  2450. u16 data_len)
  2451. {
  2452. struct sk_buff *skb;
  2453. struct wmi_p2p_probe_response_cmd *p;
  2454. size_t cmd_len = sizeof(*p) + data_len;
  2455. if (data_len == 0)
  2456. cmd_len++; /* work around target minimum length requirement */
  2457. skb = ath6kl_wmi_get_new_buf(cmd_len);
  2458. if (!skb)
  2459. return -ENOMEM;
  2460. ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
  2461. "len=%u\n", freq, dst, data_len);
  2462. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  2463. p->freq = cpu_to_le32(freq);
  2464. memcpy(p->destination_addr, dst, ETH_ALEN);
  2465. p->len = cpu_to_le16(data_len);
  2466. memcpy(p->data, data, data_len);
  2467. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2468. WMI_SEND_PROBE_RESPONSE_CMDID,
  2469. NO_SYNC_WMIFLAG);
  2470. }
  2471. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  2472. {
  2473. struct sk_buff *skb;
  2474. struct wmi_probe_req_report_cmd *p;
  2475. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2476. if (!skb)
  2477. return -ENOMEM;
  2478. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  2479. enable);
  2480. p = (struct wmi_probe_req_report_cmd *) skb->data;
  2481. p->enable = enable ? 1 : 0;
  2482. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
  2483. NO_SYNC_WMIFLAG);
  2484. }
  2485. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
  2486. {
  2487. struct sk_buff *skb;
  2488. struct wmi_get_p2p_info *p;
  2489. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2490. if (!skb)
  2491. return -ENOMEM;
  2492. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  2493. info_req_flags);
  2494. p = (struct wmi_get_p2p_info *) skb->data;
  2495. p->info_req_flags = cpu_to_le32(info_req_flags);
  2496. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
  2497. NO_SYNC_WMIFLAG);
  2498. }
  2499. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
  2500. {
  2501. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  2502. return ath6kl_wmi_simple_cmd(wmi, if_idx,
  2503. WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  2504. }
  2505. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  2506. {
  2507. struct wmix_cmd_hdr *cmd;
  2508. u32 len;
  2509. u16 id;
  2510. u8 *datap;
  2511. int ret = 0;
  2512. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  2513. ath6kl_err("bad packet 1\n");
  2514. return -EINVAL;
  2515. }
  2516. cmd = (struct wmix_cmd_hdr *) skb->data;
  2517. id = le32_to_cpu(cmd->cmd_id);
  2518. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  2519. datap = skb->data;
  2520. len = skb->len;
  2521. switch (id) {
  2522. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  2523. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
  2524. break;
  2525. case WMIX_DBGLOG_EVENTID:
  2526. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
  2527. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  2528. break;
  2529. default:
  2530. ath6kl_warn("unknown cmd id 0x%x\n", id);
  2531. ret = -EINVAL;
  2532. break;
  2533. }
  2534. return ret;
  2535. }
  2536. static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
  2537. {
  2538. return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
  2539. }
  2540. /* Control Path */
  2541. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  2542. {
  2543. struct wmi_cmd_hdr *cmd;
  2544. struct ath6kl_vif *vif;
  2545. u32 len;
  2546. u16 id;
  2547. u8 if_idx;
  2548. u8 *datap;
  2549. int ret = 0;
  2550. if (WARN_ON(skb == NULL))
  2551. return -EINVAL;
  2552. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  2553. ath6kl_err("bad packet 1\n");
  2554. dev_kfree_skb(skb);
  2555. return -EINVAL;
  2556. }
  2557. cmd = (struct wmi_cmd_hdr *) skb->data;
  2558. id = le16_to_cpu(cmd->cmd_id);
  2559. if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
  2560. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  2561. datap = skb->data;
  2562. len = skb->len;
  2563. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
  2564. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
  2565. datap, len);
  2566. vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
  2567. if (!vif) {
  2568. ath6kl_dbg(ATH6KL_DBG_WMI,
  2569. "Wmi event for unavailable vif, vif_index:%d\n",
  2570. if_idx);
  2571. dev_kfree_skb(skb);
  2572. return -EINVAL;
  2573. }
  2574. switch (id) {
  2575. case WMI_GET_BITRATE_CMDID:
  2576. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  2577. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  2578. break;
  2579. case WMI_GET_CHANNEL_LIST_CMDID:
  2580. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  2581. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  2582. break;
  2583. case WMI_GET_TX_PWR_CMDID:
  2584. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  2585. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  2586. break;
  2587. case WMI_READY_EVENTID:
  2588. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  2589. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  2590. break;
  2591. case WMI_CONNECT_EVENTID:
  2592. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  2593. ret = ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
  2594. break;
  2595. case WMI_DISCONNECT_EVENTID:
  2596. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  2597. ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
  2598. break;
  2599. case WMI_PEER_NODE_EVENTID:
  2600. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  2601. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  2602. break;
  2603. case WMI_TKIP_MICERR_EVENTID:
  2604. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  2605. ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
  2606. break;
  2607. case WMI_BSSINFO_EVENTID:
  2608. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  2609. ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
  2610. break;
  2611. case WMI_REGDOMAIN_EVENTID:
  2612. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  2613. ath6kl_wmi_regdomain_event(wmi, datap, len);
  2614. break;
  2615. case WMI_PSTREAM_TIMEOUT_EVENTID:
  2616. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  2617. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  2618. break;
  2619. case WMI_NEIGHBOR_REPORT_EVENTID:
  2620. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  2621. ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
  2622. vif);
  2623. break;
  2624. case WMI_SCAN_COMPLETE_EVENTID:
  2625. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  2626. ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
  2627. break;
  2628. case WMI_CMDERROR_EVENTID:
  2629. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  2630. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  2631. break;
  2632. case WMI_REPORT_STATISTICS_EVENTID:
  2633. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  2634. ret = ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
  2635. break;
  2636. case WMI_RSSI_THRESHOLD_EVENTID:
  2637. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  2638. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  2639. break;
  2640. case WMI_ERROR_REPORT_EVENTID:
  2641. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  2642. break;
  2643. case WMI_OPT_RX_FRAME_EVENTID:
  2644. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  2645. /* this event has been deprecated */
  2646. break;
  2647. case WMI_REPORT_ROAM_TBL_EVENTID:
  2648. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  2649. ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
  2650. break;
  2651. case WMI_EXTENSION_EVENTID:
  2652. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  2653. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  2654. break;
  2655. case WMI_CAC_EVENTID:
  2656. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  2657. ret = ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
  2658. break;
  2659. case WMI_CHANNEL_CHANGE_EVENTID:
  2660. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  2661. break;
  2662. case WMI_REPORT_ROAM_DATA_EVENTID:
  2663. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  2664. break;
  2665. case WMI_TEST_EVENTID:
  2666. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  2667. ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
  2668. break;
  2669. case WMI_GET_FIXRATES_CMDID:
  2670. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  2671. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  2672. break;
  2673. case WMI_TX_RETRY_ERR_EVENTID:
  2674. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  2675. break;
  2676. case WMI_SNR_THRESHOLD_EVENTID:
  2677. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  2678. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  2679. break;
  2680. case WMI_LQ_THRESHOLD_EVENTID:
  2681. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  2682. break;
  2683. case WMI_APLIST_EVENTID:
  2684. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  2685. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  2686. break;
  2687. case WMI_GET_KEEPALIVE_CMDID:
  2688. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  2689. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  2690. break;
  2691. case WMI_GET_WOW_LIST_EVENTID:
  2692. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  2693. break;
  2694. case WMI_GET_PMKID_LIST_EVENTID:
  2695. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  2696. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  2697. break;
  2698. case WMI_PSPOLL_EVENTID:
  2699. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  2700. ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
  2701. break;
  2702. case WMI_DTIMEXPIRY_EVENTID:
  2703. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  2704. ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
  2705. break;
  2706. case WMI_SET_PARAMS_REPLY_EVENTID:
  2707. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  2708. break;
  2709. case WMI_ADDBA_REQ_EVENTID:
  2710. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  2711. ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
  2712. break;
  2713. case WMI_ADDBA_RESP_EVENTID:
  2714. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  2715. break;
  2716. case WMI_DELBA_REQ_EVENTID:
  2717. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  2718. ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
  2719. break;
  2720. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  2721. ath6kl_dbg(ATH6KL_DBG_WMI,
  2722. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  2723. break;
  2724. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  2725. ath6kl_dbg(ATH6KL_DBG_WMI,
  2726. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  2727. break;
  2728. case WMI_TX_COMPLETE_EVENTID:
  2729. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  2730. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  2731. break;
  2732. case WMI_REMAIN_ON_CHNL_EVENTID:
  2733. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  2734. ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
  2735. break;
  2736. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  2737. ath6kl_dbg(ATH6KL_DBG_WMI,
  2738. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  2739. ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  2740. len, vif);
  2741. break;
  2742. case WMI_TX_STATUS_EVENTID:
  2743. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  2744. ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
  2745. break;
  2746. case WMI_RX_PROBE_REQ_EVENTID:
  2747. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  2748. ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
  2749. break;
  2750. case WMI_P2P_CAPABILITIES_EVENTID:
  2751. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  2752. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  2753. break;
  2754. case WMI_RX_ACTION_EVENTID:
  2755. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  2756. ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
  2757. break;
  2758. case WMI_P2P_INFO_EVENTID:
  2759. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  2760. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  2761. break;
  2762. default:
  2763. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
  2764. ret = -EINVAL;
  2765. break;
  2766. }
  2767. dev_kfree_skb(skb);
  2768. return ret;
  2769. }
  2770. void ath6kl_wmi_reset(struct wmi *wmi)
  2771. {
  2772. spin_lock_bh(&wmi->lock);
  2773. wmi->fat_pipe_exist = 0;
  2774. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  2775. spin_unlock_bh(&wmi->lock);
  2776. }
  2777. void *ath6kl_wmi_init(struct ath6kl *dev)
  2778. {
  2779. struct wmi *wmi;
  2780. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  2781. if (!wmi)
  2782. return NULL;
  2783. spin_lock_init(&wmi->lock);
  2784. wmi->parent_dev = dev;
  2785. wmi->pwr_mode = REC_POWER;
  2786. ath6kl_wmi_reset(wmi);
  2787. return wmi;
  2788. }
  2789. void ath6kl_wmi_shutdown(struct wmi *wmi)
  2790. {
  2791. if (!wmi)
  2792. return;
  2793. kfree(wmi->last_mgmt_tx_frame);
  2794. kfree(wmi);
  2795. }