wmi.c 79 KB

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