wmi.c 97 KB

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