wmi.c 82 KB

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