wmi.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101
  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. if (bih->frame_type == BEACON_FTYPE &&
  743. test_bit(CLEAR_BSSFILTER_ON_BEACON, &ar->flag)) {
  744. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &ar->flag);
  745. ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
  746. }
  747. channel = ieee80211_get_channel(ar->wdev->wiphy, le16_to_cpu(bih->ch));
  748. if (channel == NULL)
  749. return -EINVAL;
  750. if (len < 8 + 2 + 2)
  751. return -EINVAL;
  752. if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &ar->flag) &&
  753. memcmp(bih->bssid, ar->bssid, ETH_ALEN) == 0) {
  754. const u8 *tim;
  755. tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
  756. len - 8 - 2 - 2);
  757. if (tim && tim[1] >= 2) {
  758. ar->assoc_bss_dtim_period = tim[3];
  759. set_bit(DTIM_PERIOD_AVAIL, &ar->flag);
  760. }
  761. }
  762. /*
  763. * In theory, use of cfg80211_inform_bss() would be more natural here
  764. * since we do not have the full frame. However, at least for now,
  765. * cfg80211 can only distinguish Beacon and Probe Response frames from
  766. * each other when using cfg80211_inform_bss_frame(), so let's build a
  767. * fake IEEE 802.11 header to be able to take benefit of this.
  768. */
  769. mgmt = kmalloc(24 + len, GFP_ATOMIC);
  770. if (mgmt == NULL)
  771. return -EINVAL;
  772. if (bih->frame_type == BEACON_FTYPE) {
  773. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  774. IEEE80211_STYPE_BEACON);
  775. memset(mgmt->da, 0xff, ETH_ALEN);
  776. } else {
  777. struct net_device *dev = ar->net_dev;
  778. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  779. IEEE80211_STYPE_PROBE_RESP);
  780. memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
  781. }
  782. mgmt->duration = cpu_to_le16(0);
  783. memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
  784. memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
  785. mgmt->seq_ctrl = cpu_to_le16(0);
  786. memcpy(&mgmt->u.beacon, buf, len);
  787. bss = cfg80211_inform_bss_frame(ar->wdev->wiphy, channel, mgmt,
  788. 24 + len, (bih->snr - 95) * 100,
  789. GFP_ATOMIC);
  790. kfree(mgmt);
  791. if (bss == NULL)
  792. return -ENOMEM;
  793. cfg80211_put_bss(bss);
  794. return 0;
  795. }
  796. /* Inactivity timeout of a fatpipe(pstream) at the target */
  797. static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
  798. int len)
  799. {
  800. struct wmi_pstream_timeout_event *ev;
  801. if (len < sizeof(struct wmi_pstream_timeout_event))
  802. return -EINVAL;
  803. ev = (struct wmi_pstream_timeout_event *) datap;
  804. /*
  805. * When the pstream (fat pipe == AC) timesout, it means there were
  806. * no thinStreams within this pstream & it got implicitly created
  807. * due to data flow on this AC. We start the inactivity timer only
  808. * for implicitly created pstream. Just reset the host state.
  809. */
  810. spin_lock_bh(&wmi->lock);
  811. wmi->stream_exist_for_ac[ev->traffic_class] = 0;
  812. wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
  813. spin_unlock_bh(&wmi->lock);
  814. /* Indicate inactivity to driver layer for this fatpipe (pstream) */
  815. ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
  816. return 0;
  817. }
  818. static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
  819. {
  820. struct wmi_bit_rate_reply *reply;
  821. s32 rate;
  822. u32 sgi, index;
  823. if (len < sizeof(struct wmi_bit_rate_reply))
  824. return -EINVAL;
  825. reply = (struct wmi_bit_rate_reply *) datap;
  826. ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
  827. if (reply->rate_index == (s8) RATE_AUTO) {
  828. rate = RATE_AUTO;
  829. } else {
  830. index = reply->rate_index & 0x7f;
  831. sgi = (reply->rate_index & 0x80) ? 1 : 0;
  832. rate = wmi_rate_tbl[index][sgi];
  833. }
  834. ath6kl_wakeup_event(wmi->parent_dev);
  835. return 0;
  836. }
  837. static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
  838. {
  839. ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
  840. return 0;
  841. }
  842. static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
  843. {
  844. if (len < sizeof(struct wmi_fix_rates_reply))
  845. return -EINVAL;
  846. ath6kl_wakeup_event(wmi->parent_dev);
  847. return 0;
  848. }
  849. static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
  850. {
  851. if (len < sizeof(struct wmi_channel_list_reply))
  852. return -EINVAL;
  853. ath6kl_wakeup_event(wmi->parent_dev);
  854. return 0;
  855. }
  856. static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
  857. {
  858. struct wmi_tx_pwr_reply *reply;
  859. if (len < sizeof(struct wmi_tx_pwr_reply))
  860. return -EINVAL;
  861. reply = (struct wmi_tx_pwr_reply *) datap;
  862. ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
  863. return 0;
  864. }
  865. static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
  866. {
  867. if (len < sizeof(struct wmi_get_keepalive_cmd))
  868. return -EINVAL;
  869. ath6kl_wakeup_event(wmi->parent_dev);
  870. return 0;
  871. }
  872. static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
  873. {
  874. struct wmi_scan_complete_event *ev;
  875. ev = (struct wmi_scan_complete_event *) datap;
  876. ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
  877. wmi->is_probe_ssid = false;
  878. return 0;
  879. }
  880. static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
  881. int len)
  882. {
  883. struct wmi_neighbor_report_event *ev;
  884. u8 i;
  885. if (len < sizeof(*ev))
  886. return -EINVAL;
  887. ev = (struct wmi_neighbor_report_event *) datap;
  888. if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
  889. > len) {
  890. ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
  891. "(num=%d len=%d)\n", ev->num_neighbors, len);
  892. return -EINVAL;
  893. }
  894. for (i = 0; i < ev->num_neighbors; i++) {
  895. ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
  896. i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
  897. ev->neighbor[i].bss_flags);
  898. cfg80211_pmksa_candidate_notify(wmi->parent_dev->net_dev, i,
  899. ev->neighbor[i].bssid,
  900. !!(ev->neighbor[i].bss_flags &
  901. WMI_PREAUTH_CAPABLE_BSS),
  902. GFP_ATOMIC);
  903. }
  904. return 0;
  905. }
  906. /*
  907. * Target is reporting a programming error. This is for
  908. * developer aid only. Target only checks a few common violations
  909. * and it is responsibility of host to do all error checking.
  910. * Behavior of target after wmi error event is undefined.
  911. * A reset is recommended.
  912. */
  913. static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
  914. {
  915. const char *type = "unknown error";
  916. struct wmi_cmd_error_event *ev;
  917. ev = (struct wmi_cmd_error_event *) datap;
  918. switch (ev->err_code) {
  919. case INVALID_PARAM:
  920. type = "invalid parameter";
  921. break;
  922. case ILLEGAL_STATE:
  923. type = "invalid state";
  924. break;
  925. case INTERNAL_ERROR:
  926. type = "internal error";
  927. break;
  928. }
  929. ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
  930. ev->cmd_id, type);
  931. return 0;
  932. }
  933. static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
  934. {
  935. ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
  936. return 0;
  937. }
  938. static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
  939. struct sq_threshold_params *sq_thresh,
  940. u32 size)
  941. {
  942. u32 index;
  943. u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
  944. /* The list is already in sorted order. Get the next lower value */
  945. for (index = 0; index < size; index++) {
  946. if (rssi < sq_thresh->upper_threshold[index]) {
  947. threshold = (u8) sq_thresh->upper_threshold[index];
  948. break;
  949. }
  950. }
  951. return threshold;
  952. }
  953. static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
  954. struct sq_threshold_params *sq_thresh,
  955. u32 size)
  956. {
  957. u32 index;
  958. u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
  959. /* The list is already in sorted order. Get the next lower value */
  960. for (index = 0; index < size; index++) {
  961. if (rssi > sq_thresh->lower_threshold[index]) {
  962. threshold = (u8) sq_thresh->lower_threshold[index];
  963. break;
  964. }
  965. }
  966. return threshold;
  967. }
  968. static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
  969. struct wmi_rssi_threshold_params_cmd *rssi_cmd)
  970. {
  971. struct sk_buff *skb;
  972. struct wmi_rssi_threshold_params_cmd *cmd;
  973. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  974. if (!skb)
  975. return -ENOMEM;
  976. cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
  977. memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
  978. return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
  979. NO_SYNC_WMIFLAG);
  980. }
  981. static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
  982. int len)
  983. {
  984. struct wmi_rssi_threshold_event *reply;
  985. struct wmi_rssi_threshold_params_cmd cmd;
  986. struct sq_threshold_params *sq_thresh;
  987. enum wmi_rssi_threshold_val new_threshold;
  988. u8 upper_rssi_threshold, lower_rssi_threshold;
  989. s16 rssi;
  990. int ret;
  991. if (len < sizeof(struct wmi_rssi_threshold_event))
  992. return -EINVAL;
  993. reply = (struct wmi_rssi_threshold_event *) datap;
  994. new_threshold = (enum wmi_rssi_threshold_val) reply->range;
  995. rssi = a_sle16_to_cpu(reply->rssi);
  996. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
  997. /*
  998. * Identify the threshold breached and communicate that to the app.
  999. * After that install a new set of thresholds based on the signal
  1000. * quality reported by the target
  1001. */
  1002. if (new_threshold) {
  1003. /* Upper threshold breached */
  1004. if (rssi < sq_thresh->upper_threshold[0]) {
  1005. ath6kl_dbg(ATH6KL_DBG_WMI,
  1006. "spurious upper rssi threshold event: %d\n",
  1007. rssi);
  1008. } else if ((rssi < sq_thresh->upper_threshold[1]) &&
  1009. (rssi >= sq_thresh->upper_threshold[0])) {
  1010. new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
  1011. } else if ((rssi < sq_thresh->upper_threshold[2]) &&
  1012. (rssi >= sq_thresh->upper_threshold[1])) {
  1013. new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
  1014. } else if ((rssi < sq_thresh->upper_threshold[3]) &&
  1015. (rssi >= sq_thresh->upper_threshold[2])) {
  1016. new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
  1017. } else if ((rssi < sq_thresh->upper_threshold[4]) &&
  1018. (rssi >= sq_thresh->upper_threshold[3])) {
  1019. new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
  1020. } else if ((rssi < sq_thresh->upper_threshold[5]) &&
  1021. (rssi >= sq_thresh->upper_threshold[4])) {
  1022. new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
  1023. } else if (rssi >= sq_thresh->upper_threshold[5]) {
  1024. new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
  1025. }
  1026. } else {
  1027. /* Lower threshold breached */
  1028. if (rssi > sq_thresh->lower_threshold[0]) {
  1029. ath6kl_dbg(ATH6KL_DBG_WMI,
  1030. "spurious lower rssi threshold event: %d %d\n",
  1031. rssi, sq_thresh->lower_threshold[0]);
  1032. } else if ((rssi > sq_thresh->lower_threshold[1]) &&
  1033. (rssi <= sq_thresh->lower_threshold[0])) {
  1034. new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
  1035. } else if ((rssi > sq_thresh->lower_threshold[2]) &&
  1036. (rssi <= sq_thresh->lower_threshold[1])) {
  1037. new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
  1038. } else if ((rssi > sq_thresh->lower_threshold[3]) &&
  1039. (rssi <= sq_thresh->lower_threshold[2])) {
  1040. new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
  1041. } else if ((rssi > sq_thresh->lower_threshold[4]) &&
  1042. (rssi <= sq_thresh->lower_threshold[3])) {
  1043. new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
  1044. } else if ((rssi > sq_thresh->lower_threshold[5]) &&
  1045. (rssi <= sq_thresh->lower_threshold[4])) {
  1046. new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
  1047. } else if (rssi <= sq_thresh->lower_threshold[5]) {
  1048. new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
  1049. }
  1050. }
  1051. /* Calculate and install the next set of thresholds */
  1052. lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
  1053. sq_thresh->lower_threshold_valid_count);
  1054. upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
  1055. sq_thresh->upper_threshold_valid_count);
  1056. /* Issue a wmi command to install the thresholds */
  1057. cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
  1058. cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
  1059. cmd.weight = sq_thresh->weight;
  1060. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1061. ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
  1062. if (ret) {
  1063. ath6kl_err("unable to configure rssi thresholds\n");
  1064. return -EIO;
  1065. }
  1066. return 0;
  1067. }
  1068. static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
  1069. {
  1070. struct wmi_cac_event *reply;
  1071. struct ieee80211_tspec_ie *ts;
  1072. u16 active_tsids, tsinfo;
  1073. u8 tsid, index;
  1074. u8 ts_id;
  1075. if (len < sizeof(struct wmi_cac_event))
  1076. return -EINVAL;
  1077. reply = (struct wmi_cac_event *) datap;
  1078. if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
  1079. (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
  1080. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1081. tsinfo = le16_to_cpu(ts->tsinfo);
  1082. tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1083. IEEE80211_WMM_IE_TSPEC_TID_MASK;
  1084. ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
  1085. } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
  1086. /*
  1087. * Following assumes that there is only one outstanding
  1088. * ADDTS request when this event is received
  1089. */
  1090. spin_lock_bh(&wmi->lock);
  1091. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1092. spin_unlock_bh(&wmi->lock);
  1093. for (index = 0; index < sizeof(active_tsids) * 8; index++) {
  1094. if ((active_tsids >> index) & 1)
  1095. break;
  1096. }
  1097. if (index < (sizeof(active_tsids) * 8))
  1098. ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
  1099. }
  1100. /*
  1101. * Clear active tsids and Add missing handling
  1102. * for delete qos stream from AP
  1103. */
  1104. else if (reply->cac_indication == CAC_INDICATION_DELETE) {
  1105. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1106. tsinfo = le16_to_cpu(ts->tsinfo);
  1107. ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1108. IEEE80211_WMM_IE_TSPEC_TID_MASK);
  1109. spin_lock_bh(&wmi->lock);
  1110. wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
  1111. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1112. spin_unlock_bh(&wmi->lock);
  1113. /* Indicate stream inactivity to driver layer only if all tsids
  1114. * within this AC are deleted.
  1115. */
  1116. if (!active_tsids) {
  1117. ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
  1118. false);
  1119. wmi->fat_pipe_exist &= ~(1 << reply->ac);
  1120. }
  1121. }
  1122. return 0;
  1123. }
  1124. static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
  1125. struct wmi_snr_threshold_params_cmd *snr_cmd)
  1126. {
  1127. struct sk_buff *skb;
  1128. struct wmi_snr_threshold_params_cmd *cmd;
  1129. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1130. if (!skb)
  1131. return -ENOMEM;
  1132. cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
  1133. memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
  1134. return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
  1135. NO_SYNC_WMIFLAG);
  1136. }
  1137. static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1138. int len)
  1139. {
  1140. struct wmi_snr_threshold_event *reply;
  1141. struct sq_threshold_params *sq_thresh;
  1142. struct wmi_snr_threshold_params_cmd cmd;
  1143. enum wmi_snr_threshold_val new_threshold;
  1144. u8 upper_snr_threshold, lower_snr_threshold;
  1145. s16 snr;
  1146. int ret;
  1147. if (len < sizeof(struct wmi_snr_threshold_event))
  1148. return -EINVAL;
  1149. reply = (struct wmi_snr_threshold_event *) datap;
  1150. new_threshold = (enum wmi_snr_threshold_val) reply->range;
  1151. snr = reply->snr;
  1152. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
  1153. /*
  1154. * Identify the threshold breached and communicate that to the app.
  1155. * After that install a new set of thresholds based on the signal
  1156. * quality reported by the target.
  1157. */
  1158. if (new_threshold) {
  1159. /* Upper threshold breached */
  1160. if (snr < sq_thresh->upper_threshold[0]) {
  1161. ath6kl_dbg(ATH6KL_DBG_WMI,
  1162. "spurious upper snr threshold event: %d\n",
  1163. snr);
  1164. } else if ((snr < sq_thresh->upper_threshold[1]) &&
  1165. (snr >= sq_thresh->upper_threshold[0])) {
  1166. new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
  1167. } else if ((snr < sq_thresh->upper_threshold[2]) &&
  1168. (snr >= sq_thresh->upper_threshold[1])) {
  1169. new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
  1170. } else if ((snr < sq_thresh->upper_threshold[3]) &&
  1171. (snr >= sq_thresh->upper_threshold[2])) {
  1172. new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
  1173. } else if (snr >= sq_thresh->upper_threshold[3]) {
  1174. new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
  1175. }
  1176. } else {
  1177. /* Lower threshold breached */
  1178. if (snr > sq_thresh->lower_threshold[0]) {
  1179. ath6kl_dbg(ATH6KL_DBG_WMI,
  1180. "spurious lower snr threshold event: %d\n",
  1181. sq_thresh->lower_threshold[0]);
  1182. } else if ((snr > sq_thresh->lower_threshold[1]) &&
  1183. (snr <= sq_thresh->lower_threshold[0])) {
  1184. new_threshold = WMI_SNR_THRESHOLD4_BELOW;
  1185. } else if ((snr > sq_thresh->lower_threshold[2]) &&
  1186. (snr <= sq_thresh->lower_threshold[1])) {
  1187. new_threshold = WMI_SNR_THRESHOLD3_BELOW;
  1188. } else if ((snr > sq_thresh->lower_threshold[3]) &&
  1189. (snr <= sq_thresh->lower_threshold[2])) {
  1190. new_threshold = WMI_SNR_THRESHOLD2_BELOW;
  1191. } else if (snr <= sq_thresh->lower_threshold[3]) {
  1192. new_threshold = WMI_SNR_THRESHOLD1_BELOW;
  1193. }
  1194. }
  1195. /* Calculate and install the next set of thresholds */
  1196. lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
  1197. sq_thresh->lower_threshold_valid_count);
  1198. upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
  1199. sq_thresh->upper_threshold_valid_count);
  1200. /* Issue a wmi command to install the thresholds */
  1201. cmd.thresh_above1_val = upper_snr_threshold;
  1202. cmd.thresh_below1_val = lower_snr_threshold;
  1203. cmd.weight = sq_thresh->weight;
  1204. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1205. ath6kl_dbg(ATH6KL_DBG_WMI,
  1206. "snr: %d, threshold: %d, lower: %d, upper: %d\n",
  1207. snr, new_threshold,
  1208. lower_snr_threshold, upper_snr_threshold);
  1209. ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
  1210. if (ret) {
  1211. ath6kl_err("unable to configure snr threshold\n");
  1212. return -EIO;
  1213. }
  1214. return 0;
  1215. }
  1216. static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
  1217. {
  1218. u16 ap_info_entry_size;
  1219. struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
  1220. struct wmi_ap_info_v1 *ap_info_v1;
  1221. u8 index;
  1222. if (len < sizeof(struct wmi_aplist_event) ||
  1223. ev->ap_list_ver != APLIST_VER1)
  1224. return -EINVAL;
  1225. ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
  1226. ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
  1227. ath6kl_dbg(ATH6KL_DBG_WMI,
  1228. "number of APs in aplist event: %d\n", ev->num_ap);
  1229. if (len < (int) (sizeof(struct wmi_aplist_event) +
  1230. (ev->num_ap - 1) * ap_info_entry_size))
  1231. return -EINVAL;
  1232. /* AP list version 1 contents */
  1233. for (index = 0; index < ev->num_ap; index++) {
  1234. ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
  1235. index, ap_info_v1->bssid, ap_info_v1->channel);
  1236. ap_info_v1++;
  1237. }
  1238. return 0;
  1239. }
  1240. int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
  1241. enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
  1242. {
  1243. struct wmi_cmd_hdr *cmd_hdr;
  1244. enum htc_endpoint_id ep_id = wmi->ep_id;
  1245. int ret;
  1246. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: cmd_id=%d\n", __func__, cmd_id);
  1247. if (WARN_ON(skb == NULL))
  1248. return -EINVAL;
  1249. if (sync_flag >= END_WMIFLAG) {
  1250. dev_kfree_skb(skb);
  1251. return -EINVAL;
  1252. }
  1253. if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
  1254. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1255. /*
  1256. * Make sure all data currently queued is transmitted before
  1257. * the cmd execution. Establish a new sync point.
  1258. */
  1259. ath6kl_wmi_sync_point(wmi);
  1260. }
  1261. skb_push(skb, sizeof(struct wmi_cmd_hdr));
  1262. cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
  1263. cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
  1264. cmd_hdr->info1 = 0; /* added for virtual interface */
  1265. /* Only for OPT_TX_CMD, use BE endpoint. */
  1266. if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
  1267. ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
  1268. false, false, 0, NULL);
  1269. if (ret) {
  1270. dev_kfree_skb(skb);
  1271. return ret;
  1272. }
  1273. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
  1274. }
  1275. ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1276. if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
  1277. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1278. /*
  1279. * Make sure all new data queued waits for the command to
  1280. * execute. Establish a new sync point.
  1281. */
  1282. ath6kl_wmi_sync_point(wmi);
  1283. }
  1284. return 0;
  1285. }
  1286. int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
  1287. enum dot11_auth_mode dot11_auth_mode,
  1288. enum auth_mode auth_mode,
  1289. enum crypto_type pairwise_crypto,
  1290. u8 pairwise_crypto_len,
  1291. enum crypto_type group_crypto,
  1292. u8 group_crypto_len, int ssid_len, u8 *ssid,
  1293. u8 *bssid, u16 channel, u32 ctrl_flags)
  1294. {
  1295. struct sk_buff *skb;
  1296. struct wmi_connect_cmd *cc;
  1297. int ret;
  1298. wmi->traffic_class = 100;
  1299. if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
  1300. return -EINVAL;
  1301. if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
  1302. return -EINVAL;
  1303. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
  1304. if (!skb)
  1305. return -ENOMEM;
  1306. cc = (struct wmi_connect_cmd *) skb->data;
  1307. if (ssid_len)
  1308. memcpy(cc->ssid, ssid, ssid_len);
  1309. cc->ssid_len = ssid_len;
  1310. cc->nw_type = nw_type;
  1311. cc->dot11_auth_mode = dot11_auth_mode;
  1312. cc->auth_mode = auth_mode;
  1313. cc->prwise_crypto_type = pairwise_crypto;
  1314. cc->prwise_crypto_len = pairwise_crypto_len;
  1315. cc->grp_crypto_type = group_crypto;
  1316. cc->grp_crypto_len = group_crypto_len;
  1317. cc->ch = cpu_to_le16(channel);
  1318. cc->ctrl_flags = cpu_to_le32(ctrl_flags);
  1319. if (bssid != NULL)
  1320. memcpy(cc->bssid, bssid, ETH_ALEN);
  1321. wmi->pair_crypto_type = pairwise_crypto;
  1322. wmi->grp_crypto_type = group_crypto;
  1323. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
  1324. return ret;
  1325. }
  1326. int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
  1327. {
  1328. struct sk_buff *skb;
  1329. struct wmi_reconnect_cmd *cc;
  1330. int ret;
  1331. wmi->traffic_class = 100;
  1332. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
  1333. if (!skb)
  1334. return -ENOMEM;
  1335. cc = (struct wmi_reconnect_cmd *) skb->data;
  1336. cc->channel = cpu_to_le16(channel);
  1337. if (bssid != NULL)
  1338. memcpy(cc->bssid, bssid, ETH_ALEN);
  1339. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
  1340. NO_SYNC_WMIFLAG);
  1341. return ret;
  1342. }
  1343. int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
  1344. {
  1345. int ret;
  1346. wmi->traffic_class = 100;
  1347. /* Disconnect command does not need to do a SYNC before. */
  1348. ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
  1349. return ret;
  1350. }
  1351. int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
  1352. u32 force_fgscan, u32 is_legacy,
  1353. u32 home_dwell_time, u32 force_scan_interval,
  1354. s8 num_chan, u16 *ch_list)
  1355. {
  1356. struct sk_buff *skb;
  1357. struct wmi_start_scan_cmd *sc;
  1358. s8 size;
  1359. int i, ret;
  1360. size = sizeof(struct wmi_start_scan_cmd);
  1361. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1362. return -EINVAL;
  1363. if (num_chan > WMI_MAX_CHANNELS)
  1364. return -EINVAL;
  1365. if (num_chan)
  1366. size += sizeof(u16) * (num_chan - 1);
  1367. skb = ath6kl_wmi_get_new_buf(size);
  1368. if (!skb)
  1369. return -ENOMEM;
  1370. sc = (struct wmi_start_scan_cmd *) skb->data;
  1371. sc->scan_type = scan_type;
  1372. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1373. sc->is_legacy = cpu_to_le32(is_legacy);
  1374. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1375. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1376. sc->num_ch = num_chan;
  1377. for (i = 0; i < num_chan; i++)
  1378. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1379. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
  1380. NO_SYNC_WMIFLAG);
  1381. return ret;
  1382. }
  1383. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
  1384. u16 fg_end_sec, u16 bg_sec,
  1385. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1386. u16 pas_chdw_msec, u8 short_scan_ratio,
  1387. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1388. u16 maxact_scan_per_ssid)
  1389. {
  1390. struct sk_buff *skb;
  1391. struct wmi_scan_params_cmd *sc;
  1392. int ret;
  1393. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1394. if (!skb)
  1395. return -ENOMEM;
  1396. sc = (struct wmi_scan_params_cmd *) skb->data;
  1397. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1398. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1399. sc->bg_period = cpu_to_le16(bg_sec);
  1400. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1401. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1402. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1403. sc->short_scan_ratio = short_scan_ratio;
  1404. sc->scan_ctrl_flags = scan_ctrl_flag;
  1405. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1406. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1407. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1408. NO_SYNC_WMIFLAG);
  1409. return ret;
  1410. }
  1411. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
  1412. {
  1413. struct sk_buff *skb;
  1414. struct wmi_bss_filter_cmd *cmd;
  1415. int ret;
  1416. if (filter >= LAST_BSS_FILTER)
  1417. return -EINVAL;
  1418. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1419. if (!skb)
  1420. return -ENOMEM;
  1421. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1422. cmd->bss_filter = filter;
  1423. cmd->ie_mask = cpu_to_le32(ie_mask);
  1424. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
  1425. NO_SYNC_WMIFLAG);
  1426. return ret;
  1427. }
  1428. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
  1429. u8 ssid_len, u8 *ssid)
  1430. {
  1431. struct sk_buff *skb;
  1432. struct wmi_probed_ssid_cmd *cmd;
  1433. int ret;
  1434. if (index > MAX_PROBED_SSID_INDEX)
  1435. return -EINVAL;
  1436. if (ssid_len > sizeof(cmd->ssid))
  1437. return -EINVAL;
  1438. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1439. return -EINVAL;
  1440. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1441. return -EINVAL;
  1442. if (flag & SPECIFIC_SSID_FLAG)
  1443. wmi->is_probe_ssid = true;
  1444. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1445. if (!skb)
  1446. return -ENOMEM;
  1447. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1448. cmd->entry_index = index;
  1449. cmd->flag = flag;
  1450. cmd->ssid_len = ssid_len;
  1451. memcpy(cmd->ssid, ssid, ssid_len);
  1452. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
  1453. NO_SYNC_WMIFLAG);
  1454. return ret;
  1455. }
  1456. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
  1457. u16 listen_beacons)
  1458. {
  1459. struct sk_buff *skb;
  1460. struct wmi_listen_int_cmd *cmd;
  1461. int ret;
  1462. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1463. if (!skb)
  1464. return -ENOMEM;
  1465. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1466. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1467. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1468. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
  1469. NO_SYNC_WMIFLAG);
  1470. return ret;
  1471. }
  1472. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
  1473. {
  1474. struct sk_buff *skb;
  1475. struct wmi_power_mode_cmd *cmd;
  1476. int ret;
  1477. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1478. if (!skb)
  1479. return -ENOMEM;
  1480. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1481. cmd->pwr_mode = pwr_mode;
  1482. wmi->pwr_mode = pwr_mode;
  1483. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
  1484. NO_SYNC_WMIFLAG);
  1485. return ret;
  1486. }
  1487. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
  1488. u16 ps_poll_num, u16 dtim_policy,
  1489. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1490. u16 ps_fail_event_policy)
  1491. {
  1492. struct sk_buff *skb;
  1493. struct wmi_power_params_cmd *pm;
  1494. int ret;
  1495. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1496. if (!skb)
  1497. return -ENOMEM;
  1498. pm = (struct wmi_power_params_cmd *)skb->data;
  1499. pm->idle_period = cpu_to_le16(idle_period);
  1500. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1501. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1502. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1503. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1504. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1505. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
  1506. NO_SYNC_WMIFLAG);
  1507. return ret;
  1508. }
  1509. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
  1510. {
  1511. struct sk_buff *skb;
  1512. struct wmi_disc_timeout_cmd *cmd;
  1513. int ret;
  1514. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1515. if (!skb)
  1516. return -ENOMEM;
  1517. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1518. cmd->discon_timeout = timeout;
  1519. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1520. NO_SYNC_WMIFLAG);
  1521. return ret;
  1522. }
  1523. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
  1524. enum crypto_type key_type,
  1525. u8 key_usage, u8 key_len,
  1526. u8 *key_rsc, u8 *key_material,
  1527. u8 key_op_ctrl, u8 *mac_addr,
  1528. enum wmi_sync_flag sync_flag)
  1529. {
  1530. struct sk_buff *skb;
  1531. struct wmi_add_cipher_key_cmd *cmd;
  1532. int ret;
  1533. ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
  1534. "key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1535. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1536. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1537. (key_material == NULL))
  1538. return -EINVAL;
  1539. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1540. return -EINVAL;
  1541. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1542. if (!skb)
  1543. return -ENOMEM;
  1544. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1545. cmd->key_index = key_index;
  1546. cmd->key_type = key_type;
  1547. cmd->key_usage = key_usage;
  1548. cmd->key_len = key_len;
  1549. memcpy(cmd->key, key_material, key_len);
  1550. if (key_rsc != NULL)
  1551. memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
  1552. cmd->key_op_ctrl = key_op_ctrl;
  1553. if (mac_addr)
  1554. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1555. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1556. sync_flag);
  1557. return ret;
  1558. }
  1559. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
  1560. {
  1561. struct sk_buff *skb;
  1562. struct wmi_add_krk_cmd *cmd;
  1563. int ret;
  1564. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1565. if (!skb)
  1566. return -ENOMEM;
  1567. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1568. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1569. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
  1570. return ret;
  1571. }
  1572. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
  1573. {
  1574. struct sk_buff *skb;
  1575. struct wmi_delete_cipher_key_cmd *cmd;
  1576. int ret;
  1577. if (key_index > WMI_MAX_KEY_INDEX)
  1578. return -EINVAL;
  1579. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1580. if (!skb)
  1581. return -ENOMEM;
  1582. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1583. cmd->key_index = key_index;
  1584. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1585. NO_SYNC_WMIFLAG);
  1586. return ret;
  1587. }
  1588. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
  1589. const u8 *pmkid, bool set)
  1590. {
  1591. struct sk_buff *skb;
  1592. struct wmi_setpmkid_cmd *cmd;
  1593. int ret;
  1594. if (bssid == NULL)
  1595. return -EINVAL;
  1596. if (set && pmkid == NULL)
  1597. return -EINVAL;
  1598. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1599. if (!skb)
  1600. return -ENOMEM;
  1601. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1602. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1603. if (set) {
  1604. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1605. cmd->enable = PMKID_ENABLE;
  1606. } else {
  1607. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1608. cmd->enable = PMKID_DISABLE;
  1609. }
  1610. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
  1611. NO_SYNC_WMIFLAG);
  1612. return ret;
  1613. }
  1614. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1615. enum htc_endpoint_id ep_id)
  1616. {
  1617. struct wmi_data_hdr *data_hdr;
  1618. int ret;
  1619. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
  1620. return -EINVAL;
  1621. skb_push(skb, sizeof(struct wmi_data_hdr));
  1622. data_hdr = (struct wmi_data_hdr *) skb->data;
  1623. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1624. data_hdr->info3 = 0;
  1625. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1626. return ret;
  1627. }
  1628. static int ath6kl_wmi_sync_point(struct wmi *wmi)
  1629. {
  1630. struct sk_buff *skb;
  1631. struct wmi_sync_cmd *cmd;
  1632. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1633. enum htc_endpoint_id ep_id;
  1634. u8 index, num_pri_streams = 0;
  1635. int ret = 0;
  1636. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  1637. spin_lock_bh(&wmi->lock);
  1638. for (index = 0; index < WMM_NUM_AC; index++) {
  1639. if (wmi->fat_pipe_exist & (1 << index)) {
  1640. num_pri_streams++;
  1641. data_sync_bufs[num_pri_streams - 1].traffic_class =
  1642. index;
  1643. }
  1644. }
  1645. spin_unlock_bh(&wmi->lock);
  1646. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1647. if (!skb) {
  1648. ret = -ENOMEM;
  1649. goto free_skb;
  1650. }
  1651. cmd = (struct wmi_sync_cmd *) skb->data;
  1652. /*
  1653. * In the SYNC cmd sent on the control Ep, send a bitmap
  1654. * of the data eps on which the Data Sync will be sent
  1655. */
  1656. cmd->data_sync_map = wmi->fat_pipe_exist;
  1657. for (index = 0; index < num_pri_streams; index++) {
  1658. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  1659. if (data_sync_bufs[index].skb == NULL) {
  1660. ret = -ENOMEM;
  1661. break;
  1662. }
  1663. }
  1664. /*
  1665. * If buffer allocation for any of the dataSync fails,
  1666. * then do not send the Synchronize cmd on the control ep
  1667. */
  1668. if (ret)
  1669. goto free_skb;
  1670. /*
  1671. * Send sync cmd followed by sync data messages on all
  1672. * endpoints being used
  1673. */
  1674. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
  1675. NO_SYNC_WMIFLAG);
  1676. if (ret)
  1677. goto free_skb;
  1678. /* cmd buffer sent, we no longer own it */
  1679. skb = NULL;
  1680. for (index = 0; index < num_pri_streams; index++) {
  1681. if (WARN_ON(!data_sync_bufs[index].skb))
  1682. break;
  1683. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  1684. data_sync_bufs[index].
  1685. traffic_class);
  1686. ret =
  1687. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  1688. ep_id);
  1689. if (ret)
  1690. break;
  1691. data_sync_bufs[index].skb = NULL;
  1692. }
  1693. free_skb:
  1694. /* free up any resources left over (possibly due to an error) */
  1695. if (skb)
  1696. dev_kfree_skb(skb);
  1697. for (index = 0; index < num_pri_streams; index++) {
  1698. if (data_sync_bufs[index].skb != NULL) {
  1699. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
  1700. skb);
  1701. }
  1702. }
  1703. return ret;
  1704. }
  1705. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
  1706. struct wmi_create_pstream_cmd *params)
  1707. {
  1708. struct sk_buff *skb;
  1709. struct wmi_create_pstream_cmd *cmd;
  1710. u8 fatpipe_exist_for_ac = 0;
  1711. s32 min_phy = 0;
  1712. s32 nominal_phy = 0;
  1713. int ret;
  1714. if (!((params->user_pri < 8) &&
  1715. (params->user_pri <= 0x7) &&
  1716. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  1717. (params->traffic_direc == UPLINK_TRAFFIC ||
  1718. params->traffic_direc == DNLINK_TRAFFIC ||
  1719. params->traffic_direc == BIDIR_TRAFFIC) &&
  1720. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  1721. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  1722. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  1723. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  1724. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  1725. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  1726. params->tsid <= WMI_MAX_THINSTREAM))) {
  1727. return -EINVAL;
  1728. }
  1729. /*
  1730. * Check nominal PHY rate is >= minimalPHY,
  1731. * so that DUT can allow TSRS IE
  1732. */
  1733. /* Get the physical rate (units of bps) */
  1734. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  1735. /* Check minimal phy < nominal phy rate */
  1736. if (params->nominal_phy >= min_phy) {
  1737. /* unit of 500 kbps */
  1738. nominal_phy = (params->nominal_phy * 1000) / 500;
  1739. ath6kl_dbg(ATH6KL_DBG_WMI,
  1740. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  1741. min_phy, nominal_phy);
  1742. params->nominal_phy = nominal_phy;
  1743. } else {
  1744. params->nominal_phy = 0;
  1745. }
  1746. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1747. if (!skb)
  1748. return -ENOMEM;
  1749. ath6kl_dbg(ATH6KL_DBG_WMI,
  1750. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  1751. params->traffic_class, params->tsid);
  1752. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  1753. memcpy(cmd, params, sizeof(*cmd));
  1754. /* This is an implicitly created Fat pipe */
  1755. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  1756. spin_lock_bh(&wmi->lock);
  1757. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  1758. (1 << params->traffic_class));
  1759. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  1760. spin_unlock_bh(&wmi->lock);
  1761. } else {
  1762. /* explicitly created thin stream within a fat pipe */
  1763. spin_lock_bh(&wmi->lock);
  1764. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  1765. (1 << params->traffic_class));
  1766. wmi->stream_exist_for_ac[params->traffic_class] |=
  1767. (1 << params->tsid);
  1768. /*
  1769. * If a thinstream becomes active, the fat pipe automatically
  1770. * becomes active
  1771. */
  1772. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  1773. spin_unlock_bh(&wmi->lock);
  1774. }
  1775. /*
  1776. * Indicate activty change to driver layer only if this is the
  1777. * first TSID to get created in this AC explicitly or an implicit
  1778. * fat pipe is getting created.
  1779. */
  1780. if (!fatpipe_exist_for_ac)
  1781. ath6kl_indicate_tx_activity(wmi->parent_dev,
  1782. params->traffic_class, true);
  1783. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
  1784. NO_SYNC_WMIFLAG);
  1785. return ret;
  1786. }
  1787. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
  1788. {
  1789. struct sk_buff *skb;
  1790. struct wmi_delete_pstream_cmd *cmd;
  1791. u16 active_tsids = 0;
  1792. int ret;
  1793. if (traffic_class > 3) {
  1794. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  1795. return -EINVAL;
  1796. }
  1797. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1798. if (!skb)
  1799. return -ENOMEM;
  1800. cmd = (struct wmi_delete_pstream_cmd *) skb->data;
  1801. cmd->traffic_class = traffic_class;
  1802. cmd->tsid = tsid;
  1803. spin_lock_bh(&wmi->lock);
  1804. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  1805. spin_unlock_bh(&wmi->lock);
  1806. if (!(active_tsids & (1 << tsid))) {
  1807. dev_kfree_skb(skb);
  1808. ath6kl_dbg(ATH6KL_DBG_WMI,
  1809. "TSID %d doesn't exist for traffic class: %d\n",
  1810. tsid, traffic_class);
  1811. return -ENODATA;
  1812. }
  1813. ath6kl_dbg(ATH6KL_DBG_WMI,
  1814. "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
  1815. traffic_class, tsid);
  1816. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
  1817. SYNC_BEFORE_WMIFLAG);
  1818. spin_lock_bh(&wmi->lock);
  1819. wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
  1820. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  1821. spin_unlock_bh(&wmi->lock);
  1822. /*
  1823. * Indicate stream inactivity to driver layer only if all tsids
  1824. * within this AC are deleted.
  1825. */
  1826. if (!active_tsids) {
  1827. ath6kl_indicate_tx_activity(wmi->parent_dev,
  1828. traffic_class, false);
  1829. wmi->fat_pipe_exist &= ~(1 << traffic_class);
  1830. }
  1831. return ret;
  1832. }
  1833. int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
  1834. {
  1835. struct sk_buff *skb;
  1836. struct wmi_set_ip_cmd *cmd;
  1837. int ret;
  1838. /* Multicast address are not valid */
  1839. if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
  1840. (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
  1841. return -EINVAL;
  1842. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
  1843. if (!skb)
  1844. return -ENOMEM;
  1845. cmd = (struct wmi_set_ip_cmd *) skb->data;
  1846. memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
  1847. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
  1848. return ret;
  1849. }
  1850. static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
  1851. int len)
  1852. {
  1853. if (len < sizeof(struct wmi_get_wow_list_reply))
  1854. return -EINVAL;
  1855. return 0;
  1856. }
  1857. static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
  1858. enum wmix_command_id cmd_id,
  1859. enum wmi_sync_flag sync_flag)
  1860. {
  1861. struct wmix_cmd_hdr *cmd_hdr;
  1862. int ret;
  1863. skb_push(skb, sizeof(struct wmix_cmd_hdr));
  1864. cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
  1865. cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
  1866. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
  1867. return ret;
  1868. }
  1869. int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
  1870. {
  1871. struct sk_buff *skb;
  1872. struct wmix_hb_challenge_resp_cmd *cmd;
  1873. int ret;
  1874. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1875. if (!skb)
  1876. return -ENOMEM;
  1877. cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
  1878. cmd->cookie = cpu_to_le32(cookie);
  1879. cmd->source = cpu_to_le32(source);
  1880. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
  1881. NO_SYNC_WMIFLAG);
  1882. return ret;
  1883. }
  1884. int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
  1885. {
  1886. struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
  1887. struct sk_buff *skb;
  1888. int ret;
  1889. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1890. if (!skb)
  1891. return -ENOMEM;
  1892. cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
  1893. cmd->valid = cpu_to_le32(valid);
  1894. cmd->config = cpu_to_le32(config);
  1895. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
  1896. NO_SYNC_WMIFLAG);
  1897. return ret;
  1898. }
  1899. int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
  1900. {
  1901. return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
  1902. }
  1903. int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
  1904. {
  1905. struct sk_buff *skb;
  1906. struct wmi_set_tx_pwr_cmd *cmd;
  1907. int ret;
  1908. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
  1909. if (!skb)
  1910. return -ENOMEM;
  1911. cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
  1912. cmd->dbM = dbM;
  1913. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
  1914. NO_SYNC_WMIFLAG);
  1915. return ret;
  1916. }
  1917. int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
  1918. {
  1919. return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
  1920. }
  1921. int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
  1922. {
  1923. struct sk_buff *skb;
  1924. struct wmi_set_lpreamble_cmd *cmd;
  1925. int ret;
  1926. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
  1927. if (!skb)
  1928. return -ENOMEM;
  1929. cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
  1930. cmd->status = status;
  1931. cmd->preamble_policy = preamble_policy;
  1932. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
  1933. NO_SYNC_WMIFLAG);
  1934. return ret;
  1935. }
  1936. int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
  1937. {
  1938. struct sk_buff *skb;
  1939. struct wmi_set_rts_cmd *cmd;
  1940. int ret;
  1941. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
  1942. if (!skb)
  1943. return -ENOMEM;
  1944. cmd = (struct wmi_set_rts_cmd *) skb->data;
  1945. cmd->threshold = cpu_to_le16(threshold);
  1946. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
  1947. return ret;
  1948. }
  1949. int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
  1950. {
  1951. struct sk_buff *skb;
  1952. struct wmi_set_wmm_txop_cmd *cmd;
  1953. int ret;
  1954. if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
  1955. return -EINVAL;
  1956. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
  1957. if (!skb)
  1958. return -ENOMEM;
  1959. cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
  1960. cmd->txop_enable = cfg;
  1961. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
  1962. NO_SYNC_WMIFLAG);
  1963. return ret;
  1964. }
  1965. int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
  1966. {
  1967. struct sk_buff *skb;
  1968. struct wmi_set_keepalive_cmd *cmd;
  1969. int ret;
  1970. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1971. if (!skb)
  1972. return -ENOMEM;
  1973. cmd = (struct wmi_set_keepalive_cmd *) skb->data;
  1974. cmd->keep_alive_intvl = keep_alive_intvl;
  1975. wmi->keep_alive_intvl = keep_alive_intvl;
  1976. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
  1977. NO_SYNC_WMIFLAG);
  1978. return ret;
  1979. }
  1980. int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
  1981. {
  1982. struct sk_buff *skb;
  1983. int ret;
  1984. skb = ath6kl_wmi_get_new_buf(len);
  1985. if (!skb)
  1986. return -ENOMEM;
  1987. memcpy(skb->data, buf, len);
  1988. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
  1989. return ret;
  1990. }
  1991. s32 ath6kl_wmi_get_rate(s8 rate_index)
  1992. {
  1993. if (rate_index == RATE_AUTO)
  1994. return 0;
  1995. return wmi_rate_tbl[(u32) rate_index][0];
  1996. }
  1997. static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
  1998. u32 len)
  1999. {
  2000. struct wmi_pmkid_list_reply *reply;
  2001. u32 expected_len;
  2002. if (len < sizeof(struct wmi_pmkid_list_reply))
  2003. return -EINVAL;
  2004. reply = (struct wmi_pmkid_list_reply *)datap;
  2005. expected_len = sizeof(reply->num_pmkid) +
  2006. le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
  2007. if (len < expected_len)
  2008. return -EINVAL;
  2009. return 0;
  2010. }
  2011. static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
  2012. {
  2013. struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
  2014. aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
  2015. le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
  2016. return 0;
  2017. }
  2018. static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
  2019. {
  2020. struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
  2021. aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
  2022. return 0;
  2023. }
  2024. /* AP mode functions */
  2025. int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
  2026. {
  2027. struct sk_buff *skb;
  2028. struct wmi_connect_cmd *cm;
  2029. int res;
  2030. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2031. if (!skb)
  2032. return -ENOMEM;
  2033. cm = (struct wmi_connect_cmd *) skb->data;
  2034. memcpy(cm, p, sizeof(*cm));
  2035. res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
  2036. NO_SYNC_WMIFLAG);
  2037. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
  2038. "ctrl_flags=0x%x-> res=%d\n",
  2039. __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
  2040. le32_to_cpu(p->ctrl_flags), res);
  2041. return res;
  2042. }
  2043. int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
  2044. {
  2045. struct sk_buff *skb;
  2046. struct wmi_ap_set_mlme_cmd *cm;
  2047. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2048. if (!skb)
  2049. return -ENOMEM;
  2050. cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
  2051. memcpy(cm->mac, mac, ETH_ALEN);
  2052. cm->reason = cpu_to_le16(reason);
  2053. cm->cmd = cmd;
  2054. return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
  2055. NO_SYNC_WMIFLAG);
  2056. }
  2057. static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
  2058. {
  2059. struct wmi_pspoll_event *ev;
  2060. if (len < sizeof(struct wmi_pspoll_event))
  2061. return -EINVAL;
  2062. ev = (struct wmi_pspoll_event *) datap;
  2063. ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
  2064. return 0;
  2065. }
  2066. static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
  2067. {
  2068. ath6kl_dtimexpiry_event(wmi->parent_dev);
  2069. return 0;
  2070. }
  2071. int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
  2072. {
  2073. struct sk_buff *skb;
  2074. struct wmi_ap_set_pvb_cmd *cmd;
  2075. int ret;
  2076. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
  2077. if (!skb)
  2078. return -ENOMEM;
  2079. cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
  2080. cmd->aid = cpu_to_le16(aid);
  2081. cmd->rsvd = cpu_to_le16(0);
  2082. cmd->flag = cpu_to_le32(flag);
  2083. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
  2084. NO_SYNC_WMIFLAG);
  2085. return 0;
  2086. }
  2087. int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
  2088. bool rx_dot11_hdr, bool defrag_on_host)
  2089. {
  2090. struct sk_buff *skb;
  2091. struct wmi_rx_frame_format_cmd *cmd;
  2092. int ret;
  2093. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2094. if (!skb)
  2095. return -ENOMEM;
  2096. cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
  2097. cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
  2098. cmd->defrag_on_host = defrag_on_host ? 1 : 0;
  2099. cmd->meta_ver = rx_meta_ver;
  2100. /* Delete the local aggr state, on host */
  2101. ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
  2102. NO_SYNC_WMIFLAG);
  2103. return ret;
  2104. }
  2105. int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
  2106. u8 ie_len)
  2107. {
  2108. struct sk_buff *skb;
  2109. struct wmi_set_appie_cmd *p;
  2110. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2111. if (!skb)
  2112. return -ENOMEM;
  2113. ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
  2114. "ie_len=%u\n", mgmt_frm_type, ie_len);
  2115. p = (struct wmi_set_appie_cmd *) skb->data;
  2116. p->mgmt_frm_type = mgmt_frm_type;
  2117. p->ie_len = ie_len;
  2118. memcpy(p->ie_info, ie, ie_len);
  2119. return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
  2120. NO_SYNC_WMIFLAG);
  2121. }
  2122. int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
  2123. {
  2124. struct sk_buff *skb;
  2125. struct wmi_disable_11b_rates_cmd *cmd;
  2126. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2127. if (!skb)
  2128. return -ENOMEM;
  2129. ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
  2130. disable);
  2131. cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
  2132. cmd->disable = disable ? 1 : 0;
  2133. return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
  2134. NO_SYNC_WMIFLAG);
  2135. }
  2136. int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
  2137. {
  2138. struct sk_buff *skb;
  2139. struct wmi_remain_on_chnl_cmd *p;
  2140. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2141. if (!skb)
  2142. return -ENOMEM;
  2143. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
  2144. freq, dur);
  2145. p = (struct wmi_remain_on_chnl_cmd *) skb->data;
  2146. p->freq = cpu_to_le32(freq);
  2147. p->duration = cpu_to_le32(dur);
  2148. return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
  2149. NO_SYNC_WMIFLAG);
  2150. }
  2151. int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
  2152. const u8 *data, u16 data_len)
  2153. {
  2154. struct sk_buff *skb;
  2155. struct wmi_send_action_cmd *p;
  2156. u8 *buf;
  2157. if (wait)
  2158. return -EINVAL; /* Offload for wait not supported */
  2159. buf = kmalloc(data_len, GFP_KERNEL);
  2160. if (!buf)
  2161. return -ENOMEM;
  2162. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2163. if (!skb) {
  2164. kfree(buf);
  2165. return -ENOMEM;
  2166. }
  2167. kfree(wmi->last_mgmt_tx_frame);
  2168. wmi->last_mgmt_tx_frame = buf;
  2169. wmi->last_mgmt_tx_frame_len = data_len;
  2170. ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
  2171. "len=%u\n", id, freq, wait, data_len);
  2172. p = (struct wmi_send_action_cmd *) skb->data;
  2173. p->id = cpu_to_le32(id);
  2174. p->freq = cpu_to_le32(freq);
  2175. p->wait = cpu_to_le32(wait);
  2176. p->len = cpu_to_le16(data_len);
  2177. memcpy(p->data, data, data_len);
  2178. return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
  2179. NO_SYNC_WMIFLAG);
  2180. }
  2181. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
  2182. const u8 *dst,
  2183. const u8 *data, u16 data_len)
  2184. {
  2185. struct sk_buff *skb;
  2186. struct wmi_p2p_probe_response_cmd *p;
  2187. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2188. if (!skb)
  2189. return -ENOMEM;
  2190. ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
  2191. "len=%u\n", freq, dst, data_len);
  2192. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  2193. p->freq = cpu_to_le32(freq);
  2194. memcpy(p->destination_addr, dst, ETH_ALEN);
  2195. p->len = cpu_to_le16(data_len);
  2196. memcpy(p->data, data, data_len);
  2197. return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
  2198. NO_SYNC_WMIFLAG);
  2199. }
  2200. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
  2201. {
  2202. struct sk_buff *skb;
  2203. struct wmi_probe_req_report_cmd *p;
  2204. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2205. if (!skb)
  2206. return -ENOMEM;
  2207. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  2208. enable);
  2209. p = (struct wmi_probe_req_report_cmd *) skb->data;
  2210. p->enable = enable ? 1 : 0;
  2211. return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
  2212. NO_SYNC_WMIFLAG);
  2213. }
  2214. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
  2215. {
  2216. struct sk_buff *skb;
  2217. struct wmi_get_p2p_info *p;
  2218. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2219. if (!skb)
  2220. return -ENOMEM;
  2221. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  2222. info_req_flags);
  2223. p = (struct wmi_get_p2p_info *) skb->data;
  2224. p->info_req_flags = cpu_to_le32(info_req_flags);
  2225. return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
  2226. NO_SYNC_WMIFLAG);
  2227. }
  2228. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
  2229. {
  2230. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  2231. return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  2232. }
  2233. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  2234. {
  2235. struct wmix_cmd_hdr *cmd;
  2236. u32 len;
  2237. u16 id;
  2238. u8 *datap;
  2239. int ret = 0;
  2240. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  2241. ath6kl_err("bad packet 1\n");
  2242. wmi->stat.cmd_len_err++;
  2243. return -EINVAL;
  2244. }
  2245. cmd = (struct wmix_cmd_hdr *) skb->data;
  2246. id = le32_to_cpu(cmd->cmd_id);
  2247. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  2248. datap = skb->data;
  2249. len = skb->len;
  2250. switch (id) {
  2251. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  2252. break;
  2253. case WMIX_DBGLOG_EVENTID:
  2254. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  2255. break;
  2256. default:
  2257. ath6kl_err("unknown cmd id 0x%x\n", id);
  2258. wmi->stat.cmd_id_err++;
  2259. ret = -EINVAL;
  2260. break;
  2261. }
  2262. return ret;
  2263. }
  2264. /* Control Path */
  2265. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  2266. {
  2267. struct wmi_cmd_hdr *cmd;
  2268. u32 len;
  2269. u16 id;
  2270. u8 *datap;
  2271. int ret = 0;
  2272. if (WARN_ON(skb == NULL))
  2273. return -EINVAL;
  2274. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  2275. ath6kl_err("bad packet 1\n");
  2276. dev_kfree_skb(skb);
  2277. wmi->stat.cmd_len_err++;
  2278. return -EINVAL;
  2279. }
  2280. cmd = (struct wmi_cmd_hdr *) skb->data;
  2281. id = le16_to_cpu(cmd->cmd_id);
  2282. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  2283. datap = skb->data;
  2284. len = skb->len;
  2285. ath6kl_dbg(ATH6KL_DBG_WMI, "%s: wmi id: %d\n", __func__, id);
  2286. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "msg payload ", "wmi rx ",
  2287. datap, len);
  2288. switch (id) {
  2289. case WMI_GET_BITRATE_CMDID:
  2290. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  2291. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  2292. break;
  2293. case WMI_GET_CHANNEL_LIST_CMDID:
  2294. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  2295. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  2296. break;
  2297. case WMI_GET_TX_PWR_CMDID:
  2298. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  2299. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  2300. break;
  2301. case WMI_READY_EVENTID:
  2302. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  2303. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  2304. break;
  2305. case WMI_CONNECT_EVENTID:
  2306. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  2307. ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
  2308. break;
  2309. case WMI_DISCONNECT_EVENTID:
  2310. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  2311. ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
  2312. break;
  2313. case WMI_PEER_NODE_EVENTID:
  2314. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  2315. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  2316. break;
  2317. case WMI_TKIP_MICERR_EVENTID:
  2318. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  2319. ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
  2320. break;
  2321. case WMI_BSSINFO_EVENTID:
  2322. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  2323. ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len);
  2324. break;
  2325. case WMI_REGDOMAIN_EVENTID:
  2326. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  2327. ath6kl_wmi_regdomain_event(wmi, datap, len);
  2328. break;
  2329. case WMI_PSTREAM_TIMEOUT_EVENTID:
  2330. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  2331. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  2332. break;
  2333. case WMI_NEIGHBOR_REPORT_EVENTID:
  2334. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  2335. ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len);
  2336. break;
  2337. case WMI_SCAN_COMPLETE_EVENTID:
  2338. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  2339. ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
  2340. break;
  2341. case WMI_CMDERROR_EVENTID:
  2342. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  2343. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  2344. break;
  2345. case WMI_REPORT_STATISTICS_EVENTID:
  2346. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  2347. ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
  2348. break;
  2349. case WMI_RSSI_THRESHOLD_EVENTID:
  2350. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  2351. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  2352. break;
  2353. case WMI_ERROR_REPORT_EVENTID:
  2354. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  2355. break;
  2356. case WMI_OPT_RX_FRAME_EVENTID:
  2357. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  2358. /* this event has been deprecated */
  2359. break;
  2360. case WMI_REPORT_ROAM_TBL_EVENTID:
  2361. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  2362. break;
  2363. case WMI_EXTENSION_EVENTID:
  2364. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  2365. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  2366. break;
  2367. case WMI_CAC_EVENTID:
  2368. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  2369. ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
  2370. break;
  2371. case WMI_CHANNEL_CHANGE_EVENTID:
  2372. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  2373. break;
  2374. case WMI_REPORT_ROAM_DATA_EVENTID:
  2375. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  2376. break;
  2377. case WMI_TEST_EVENTID:
  2378. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  2379. ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
  2380. break;
  2381. case WMI_GET_FIXRATES_CMDID:
  2382. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  2383. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  2384. break;
  2385. case WMI_TX_RETRY_ERR_EVENTID:
  2386. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  2387. break;
  2388. case WMI_SNR_THRESHOLD_EVENTID:
  2389. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  2390. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  2391. break;
  2392. case WMI_LQ_THRESHOLD_EVENTID:
  2393. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  2394. break;
  2395. case WMI_APLIST_EVENTID:
  2396. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  2397. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  2398. break;
  2399. case WMI_GET_KEEPALIVE_CMDID:
  2400. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  2401. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  2402. break;
  2403. case WMI_GET_WOW_LIST_EVENTID:
  2404. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  2405. ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
  2406. break;
  2407. case WMI_GET_PMKID_LIST_EVENTID:
  2408. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  2409. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  2410. break;
  2411. case WMI_PSPOLL_EVENTID:
  2412. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  2413. ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
  2414. break;
  2415. case WMI_DTIMEXPIRY_EVENTID:
  2416. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  2417. ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
  2418. break;
  2419. case WMI_SET_PARAMS_REPLY_EVENTID:
  2420. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  2421. break;
  2422. case WMI_ADDBA_REQ_EVENTID:
  2423. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  2424. ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
  2425. break;
  2426. case WMI_ADDBA_RESP_EVENTID:
  2427. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  2428. break;
  2429. case WMI_DELBA_REQ_EVENTID:
  2430. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  2431. ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
  2432. break;
  2433. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  2434. ath6kl_dbg(ATH6KL_DBG_WMI,
  2435. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  2436. break;
  2437. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  2438. ath6kl_dbg(ATH6KL_DBG_WMI,
  2439. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  2440. break;
  2441. case WMI_TX_COMPLETE_EVENTID:
  2442. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  2443. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  2444. break;
  2445. case WMI_REMAIN_ON_CHNL_EVENTID:
  2446. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  2447. ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
  2448. break;
  2449. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  2450. ath6kl_dbg(ATH6KL_DBG_WMI,
  2451. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  2452. ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  2453. len);
  2454. break;
  2455. case WMI_TX_STATUS_EVENTID:
  2456. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  2457. ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len);
  2458. break;
  2459. case WMI_RX_PROBE_REQ_EVENTID:
  2460. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  2461. ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
  2462. break;
  2463. case WMI_P2P_CAPABILITIES_EVENTID:
  2464. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  2465. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  2466. break;
  2467. case WMI_RX_ACTION_EVENTID:
  2468. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  2469. ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len);
  2470. break;
  2471. case WMI_P2P_INFO_EVENTID:
  2472. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  2473. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  2474. break;
  2475. default:
  2476. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
  2477. wmi->stat.cmd_id_err++;
  2478. ret = -EINVAL;
  2479. break;
  2480. }
  2481. dev_kfree_skb(skb);
  2482. return ret;
  2483. }
  2484. static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
  2485. {
  2486. if (!wmi)
  2487. return;
  2488. spin_lock_bh(&wmi->lock);
  2489. wmi->fat_pipe_exist = 0;
  2490. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  2491. spin_unlock_bh(&wmi->lock);
  2492. }
  2493. void *ath6kl_wmi_init(struct ath6kl *dev)
  2494. {
  2495. struct wmi *wmi;
  2496. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  2497. if (!wmi)
  2498. return NULL;
  2499. spin_lock_init(&wmi->lock);
  2500. wmi->parent_dev = dev;
  2501. ath6kl_wmi_qos_state_init(wmi);
  2502. wmi->pwr_mode = REC_POWER;
  2503. wmi->phy_mode = WMI_11G_MODE;
  2504. wmi->pair_crypto_type = NONE_CRYPT;
  2505. wmi->grp_crypto_type = NONE_CRYPT;
  2506. wmi->ht_allowed[A_BAND_24GHZ] = 1;
  2507. wmi->ht_allowed[A_BAND_5GHZ] = 1;
  2508. return wmi;
  2509. }
  2510. void ath6kl_wmi_shutdown(struct wmi *wmi)
  2511. {
  2512. if (!wmi)
  2513. return;
  2514. kfree(wmi->last_mgmt_tx_frame);
  2515. kfree(wmi);
  2516. }