wmi.c 92 KB

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