wmi.c 78 KB

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