wmi.c 81 KB

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