wmi.c 107 KB

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