wmi.c 84 KB

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