cfg80211.c 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * NXP Wireless LAN device driver: CFG80211
  4. *
  5. * Copyright 2011-2020 NXP
  6. */
  7. #include "cfg80211.h"
  8. #include "main.h"
  9. #include "11n.h"
  10. #include "wmm.h"
  11. static char *reg_alpha2;
  12. module_param(reg_alpha2, charp, 0);
  13. static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
  14. {
  15. .max = MWIFIEX_MAX_BSS_NUM,
  16. .types = BIT(NL80211_IFTYPE_STATION) |
  17. BIT(NL80211_IFTYPE_P2P_GO) |
  18. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  19. BIT(NL80211_IFTYPE_AP),
  20. },
  21. };
  22. static const struct ieee80211_iface_combination
  23. mwifiex_iface_comb_ap_sta = {
  24. .limits = mwifiex_ap_sta_limits,
  25. .num_different_channels = 1,
  26. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  27. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  28. .beacon_int_infra_match = true,
  29. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  30. BIT(NL80211_CHAN_WIDTH_20) |
  31. BIT(NL80211_CHAN_WIDTH_40),
  32. };
  33. static const struct ieee80211_iface_combination
  34. mwifiex_iface_comb_ap_sta_vht = {
  35. .limits = mwifiex_ap_sta_limits,
  36. .num_different_channels = 1,
  37. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  38. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  39. .beacon_int_infra_match = true,
  40. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  41. BIT(NL80211_CHAN_WIDTH_20) |
  42. BIT(NL80211_CHAN_WIDTH_40) |
  43. BIT(NL80211_CHAN_WIDTH_80),
  44. };
  45. static const struct
  46. ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
  47. .limits = mwifiex_ap_sta_limits,
  48. .num_different_channels = 2,
  49. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  50. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  51. .beacon_int_infra_match = true,
  52. };
  53. /*
  54. * This function maps the nl802.11 channel type into driver channel type.
  55. *
  56. * The mapping is as follows -
  57. * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  58. * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  59. * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
  60. * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
  61. * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  62. */
  63. u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
  64. {
  65. switch (chan_type) {
  66. case NL80211_CHAN_NO_HT:
  67. case NL80211_CHAN_HT20:
  68. return IEEE80211_HT_PARAM_CHA_SEC_NONE;
  69. case NL80211_CHAN_HT40PLUS:
  70. return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  71. case NL80211_CHAN_HT40MINUS:
  72. return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  73. default:
  74. return IEEE80211_HT_PARAM_CHA_SEC_NONE;
  75. }
  76. }
  77. /* This function maps IEEE HT secondary channel type to NL80211 channel type
  78. */
  79. u8 mwifiex_get_chan_type(struct mwifiex_private *priv)
  80. {
  81. struct mwifiex_channel_band channel_band;
  82. int ret;
  83. ret = mwifiex_get_chan_info(priv, &channel_band);
  84. if (!ret) {
  85. switch (channel_band.band_config.chan_width) {
  86. case CHAN_BW_20MHZ:
  87. if (IS_11N_ENABLED(priv))
  88. return NL80211_CHAN_HT20;
  89. else
  90. return NL80211_CHAN_NO_HT;
  91. case CHAN_BW_40MHZ:
  92. if (channel_band.band_config.chan2_offset ==
  93. SEC_CHAN_ABOVE)
  94. return NL80211_CHAN_HT40PLUS;
  95. else
  96. return NL80211_CHAN_HT40MINUS;
  97. default:
  98. return NL80211_CHAN_HT20;
  99. }
  100. }
  101. return NL80211_CHAN_HT20;
  102. }
  103. /*
  104. * This function checks whether WEP is set.
  105. */
  106. static int
  107. mwifiex_is_alg_wep(u32 cipher)
  108. {
  109. switch (cipher) {
  110. case WLAN_CIPHER_SUITE_WEP40:
  111. case WLAN_CIPHER_SUITE_WEP104:
  112. return 1;
  113. default:
  114. break;
  115. }
  116. return 0;
  117. }
  118. /*
  119. * This function retrieves the private structure from kernel wiphy structure.
  120. */
  121. static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
  122. {
  123. return (void *) (*(unsigned long *) wiphy_priv(wiphy));
  124. }
  125. /*
  126. * CFG802.11 operation handler to delete a network key.
  127. */
  128. static int
  129. mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
  130. int link_id, u8 key_index, bool pairwise,
  131. const u8 *mac_addr)
  132. {
  133. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  134. static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  135. const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
  136. if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
  137. mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
  138. return -EFAULT;
  139. }
  140. mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
  141. return 0;
  142. }
  143. /*
  144. * This function forms an skb for management frame.
  145. */
  146. static int
  147. mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
  148. {
  149. u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  150. u16 pkt_len;
  151. u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
  152. pkt_len = len + ETH_ALEN;
  153. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
  154. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  155. memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
  156. memcpy(skb_push(skb, sizeof(tx_control)),
  157. &tx_control, sizeof(tx_control));
  158. memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
  159. /* Add packet data and address4 */
  160. skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
  161. skb_put_data(skb, addr, ETH_ALEN);
  162. skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
  163. len - sizeof(struct ieee80211_hdr_3addr));
  164. skb->priority = LOW_PRIO_TID;
  165. __net_timestamp(skb);
  166. return 0;
  167. }
  168. /*
  169. * CFG802.11 operation handler to transmit a management frame.
  170. */
  171. static int
  172. mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  173. struct cfg80211_mgmt_tx_params *params, u64 *cookie)
  174. {
  175. const u8 *buf = params->buf;
  176. size_t len = params->len;
  177. struct sk_buff *skb;
  178. u16 pkt_len;
  179. const struct ieee80211_mgmt *mgmt;
  180. struct mwifiex_txinfo *tx_info;
  181. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  182. if (!buf || !len) {
  183. mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
  184. return -EFAULT;
  185. }
  186. mgmt = (const struct ieee80211_mgmt *)buf;
  187. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
  188. ieee80211_is_probe_resp(mgmt->frame_control)) {
  189. /* Since we support offload probe resp, we need to skip probe
  190. * resp in AP or GO mode */
  191. mwifiex_dbg(priv->adapter, INFO,
  192. "info: skip to send probe resp in AP or GO mode\n");
  193. return 0;
  194. }
  195. pkt_len = len + ETH_ALEN;
  196. skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
  197. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  198. pkt_len + sizeof(pkt_len));
  199. if (!skb) {
  200. mwifiex_dbg(priv->adapter, ERROR,
  201. "allocate skb failed for management frame\n");
  202. return -ENOMEM;
  203. }
  204. tx_info = MWIFIEX_SKB_TXCB(skb);
  205. memset(tx_info, 0, sizeof(*tx_info));
  206. tx_info->bss_num = priv->bss_num;
  207. tx_info->bss_type = priv->bss_type;
  208. tx_info->pkt_len = pkt_len;
  209. mwifiex_form_mgmt_frame(skb, buf, len);
  210. *cookie = get_random_u32() | 1;
  211. if (ieee80211_is_action(mgmt->frame_control))
  212. skb = mwifiex_clone_skb_for_tx_status(priv,
  213. skb,
  214. MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
  215. else
  216. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
  217. GFP_ATOMIC);
  218. mwifiex_queue_tx_pkt(priv, skb);
  219. mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
  220. return 0;
  221. }
  222. /*
  223. * CFG802.11 operation handler to register a mgmt frame.
  224. */
  225. static void
  226. mwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
  227. struct wireless_dev *wdev,
  228. struct mgmt_frame_regs *upd)
  229. {
  230. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  231. u32 mask = upd->interface_stypes;
  232. if (mask != priv->mgmt_frame_mask) {
  233. priv->mgmt_frame_mask = mask;
  234. mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
  235. HostCmd_ACT_GEN_SET, 0,
  236. &priv->mgmt_frame_mask, false);
  237. mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
  238. }
  239. }
  240. /*
  241. * CFG802.11 operation handler to remain on channel.
  242. */
  243. static int
  244. mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
  245. struct wireless_dev *wdev,
  246. struct ieee80211_channel *chan,
  247. unsigned int duration, u64 *cookie)
  248. {
  249. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  250. int ret;
  251. if (!chan || !cookie) {
  252. mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
  253. return -EINVAL;
  254. }
  255. if (priv->roc_cfg.cookie) {
  256. mwifiex_dbg(priv->adapter, INFO,
  257. "info: ongoing ROC, cookie = 0x%llx\n",
  258. priv->roc_cfg.cookie);
  259. return -EBUSY;
  260. }
  261. ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
  262. duration);
  263. if (!ret) {
  264. *cookie = get_random_u32() | 1;
  265. priv->roc_cfg.cookie = *cookie;
  266. priv->roc_cfg.chan = *chan;
  267. cfg80211_ready_on_channel(wdev, *cookie, chan,
  268. duration, GFP_ATOMIC);
  269. mwifiex_dbg(priv->adapter, INFO,
  270. "info: ROC, cookie = 0x%llx\n", *cookie);
  271. }
  272. return ret;
  273. }
  274. /*
  275. * CFG802.11 operation handler to cancel remain on channel.
  276. */
  277. static int
  278. mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
  279. struct wireless_dev *wdev, u64 cookie)
  280. {
  281. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  282. int ret;
  283. if (cookie != priv->roc_cfg.cookie)
  284. return -ENOENT;
  285. ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
  286. &priv->roc_cfg.chan, 0);
  287. if (!ret) {
  288. cfg80211_remain_on_channel_expired(wdev, cookie,
  289. &priv->roc_cfg.chan,
  290. GFP_ATOMIC);
  291. memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
  292. mwifiex_dbg(priv->adapter, INFO,
  293. "info: cancel ROC, cookie = 0x%llx\n", cookie);
  294. }
  295. return ret;
  296. }
  297. /*
  298. * CFG802.11 operation handler to set Tx power.
  299. */
  300. static int
  301. mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
  302. struct wireless_dev *wdev,
  303. enum nl80211_tx_power_setting type,
  304. int mbm)
  305. {
  306. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  307. struct mwifiex_private *priv;
  308. struct mwifiex_power_cfg power_cfg;
  309. int dbm = MBM_TO_DBM(mbm);
  310. switch (type) {
  311. case NL80211_TX_POWER_FIXED:
  312. power_cfg.is_power_auto = 0;
  313. power_cfg.is_power_fixed = 1;
  314. power_cfg.power_level = dbm;
  315. break;
  316. case NL80211_TX_POWER_LIMITED:
  317. power_cfg.is_power_auto = 0;
  318. power_cfg.is_power_fixed = 0;
  319. power_cfg.power_level = dbm;
  320. break;
  321. case NL80211_TX_POWER_AUTOMATIC:
  322. power_cfg.is_power_auto = 1;
  323. break;
  324. }
  325. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  326. return mwifiex_set_tx_power(priv, &power_cfg);
  327. }
  328. /*
  329. * CFG802.11 operation handler to get Tx power.
  330. */
  331. static int
  332. mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
  333. struct wireless_dev *wdev,
  334. int *dbm)
  335. {
  336. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  337. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  338. MWIFIEX_BSS_ROLE_ANY);
  339. int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
  340. HostCmd_ACT_GEN_GET, 0, NULL, true);
  341. if (ret < 0)
  342. return ret;
  343. /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
  344. *dbm = priv->tx_power_level;
  345. return 0;
  346. }
  347. /*
  348. * CFG802.11 operation handler to set Power Save option.
  349. *
  350. * The timeout value, if provided, is currently ignored.
  351. */
  352. static int
  353. mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  354. struct net_device *dev,
  355. bool enabled, int timeout)
  356. {
  357. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  358. u32 ps_mode;
  359. if (timeout)
  360. mwifiex_dbg(priv->adapter, INFO,
  361. "info: ignore timeout value for IEEE Power Save\n");
  362. ps_mode = enabled;
  363. return mwifiex_drv_set_power(priv, &ps_mode);
  364. }
  365. /*
  366. * CFG802.11 operation handler to set the default network key.
  367. */
  368. static int
  369. mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  370. int link_id, u8 key_index, bool unicast,
  371. bool multicast)
  372. {
  373. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  374. /* Return if WEP key not configured */
  375. if (!priv->sec_info.wep_enabled)
  376. return 0;
  377. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
  378. priv->wep_key_curr_index = key_index;
  379. } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
  380. NULL, 0)) {
  381. mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
  382. return -EFAULT;
  383. }
  384. return 0;
  385. }
  386. /*
  387. * CFG802.11 operation handler to add a network key.
  388. */
  389. static int
  390. mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
  391. int link_id, u8 key_index, bool pairwise,
  392. const u8 *mac_addr, struct key_params *params)
  393. {
  394. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  395. struct mwifiex_wep_key *wep_key;
  396. static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  397. const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
  398. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
  399. (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  400. params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
  401. if (params->key && params->key_len) {
  402. wep_key = &priv->wep_key[key_index];
  403. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  404. memcpy(wep_key->key_material, params->key,
  405. params->key_len);
  406. wep_key->key_index = key_index;
  407. wep_key->key_length = params->key_len;
  408. priv->sec_info.wep_enabled = 1;
  409. }
  410. return 0;
  411. }
  412. if (mwifiex_set_encode(priv, params, params->key, params->key_len,
  413. key_index, peer_mac, 0)) {
  414. mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
  415. return -EFAULT;
  416. }
  417. return 0;
  418. }
  419. /*
  420. * CFG802.11 operation handler to set default mgmt key.
  421. */
  422. static int
  423. mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
  424. struct net_device *netdev,
  425. int link_id,
  426. u8 key_index)
  427. {
  428. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  429. struct mwifiex_ds_encrypt_key encrypt_key;
  430. wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
  431. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  432. encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
  433. encrypt_key.key_index = key_index;
  434. encrypt_key.is_igtk_def_key = true;
  435. eth_broadcast_addr(encrypt_key.mac_addr);
  436. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  437. HostCmd_ACT_GEN_SET, true, &encrypt_key, true)) {
  438. mwifiex_dbg(priv->adapter, ERROR,
  439. "Sending KEY_MATERIAL command failed\n");
  440. return -1;
  441. }
  442. return 0;
  443. }
  444. /*
  445. * This function sends domain information to the firmware.
  446. *
  447. * The following information are passed to the firmware -
  448. * - Country codes
  449. * - Sub bands (first channel, number of channels, maximum Tx power)
  450. */
  451. int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
  452. {
  453. u8 no_of_triplet = 0;
  454. struct ieee80211_country_ie_triplet *t;
  455. u8 no_of_parsed_chan = 0;
  456. u8 first_chan = 0, next_chan = 0, max_pwr = 0;
  457. u8 i, flag = 0;
  458. enum nl80211_band band;
  459. struct ieee80211_supported_band *sband;
  460. struct ieee80211_channel *ch;
  461. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  462. struct mwifiex_private *priv;
  463. struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
  464. /* Set country code */
  465. domain_info->country_code[0] = adapter->country_code[0];
  466. domain_info->country_code[1] = adapter->country_code[1];
  467. domain_info->country_code[2] = ' ';
  468. band = mwifiex_band_to_radio_type(adapter->config_bands);
  469. if (!wiphy->bands[band]) {
  470. mwifiex_dbg(adapter, ERROR,
  471. "11D: setting domain info in FW\n");
  472. return -1;
  473. }
  474. sband = wiphy->bands[band];
  475. for (i = 0; i < sband->n_channels ; i++) {
  476. ch = &sband->channels[i];
  477. if (ch->flags & IEEE80211_CHAN_DISABLED)
  478. continue;
  479. if (!flag) {
  480. flag = 1;
  481. first_chan = (u32) ch->hw_value;
  482. next_chan = first_chan;
  483. max_pwr = ch->max_power;
  484. no_of_parsed_chan = 1;
  485. continue;
  486. }
  487. if (ch->hw_value == next_chan + 1 &&
  488. ch->max_power == max_pwr) {
  489. next_chan++;
  490. no_of_parsed_chan++;
  491. } else {
  492. t = &domain_info->triplet[no_of_triplet];
  493. t->chans.first_channel = first_chan;
  494. t->chans.num_channels = no_of_parsed_chan;
  495. t->chans.max_power = max_pwr;
  496. no_of_triplet++;
  497. first_chan = (u32) ch->hw_value;
  498. next_chan = first_chan;
  499. max_pwr = ch->max_power;
  500. no_of_parsed_chan = 1;
  501. }
  502. }
  503. if (flag) {
  504. t = &domain_info->triplet[no_of_triplet];
  505. t->chans.first_channel = first_chan;
  506. t->chans.num_channels = no_of_parsed_chan;
  507. t->chans.max_power = max_pwr;
  508. no_of_triplet++;
  509. }
  510. domain_info->no_of_triplet = no_of_triplet;
  511. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  512. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  513. HostCmd_ACT_GEN_SET, 0, NULL, false)) {
  514. mwifiex_dbg(adapter, INFO,
  515. "11D: setting domain info in FW\n");
  516. return -1;
  517. }
  518. return 0;
  519. }
  520. static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
  521. {
  522. struct ieee80211_supported_band *sband;
  523. struct ieee80211_channel *chan;
  524. unsigned int i;
  525. if (!wiphy->bands[NL80211_BAND_5GHZ])
  526. return;
  527. sband = wiphy->bands[NL80211_BAND_5GHZ];
  528. for (i = 0; i < sband->n_channels; i++) {
  529. chan = &sband->channels[i];
  530. if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
  531. (chan->flags & IEEE80211_CHAN_RADAR))
  532. chan->flags |= IEEE80211_CHAN_NO_IR;
  533. }
  534. }
  535. /*
  536. * CFG802.11 regulatory domain callback function.
  537. *
  538. * This function is called when the regulatory domain is changed due to the
  539. * following reasons -
  540. * - Set by driver
  541. * - Set by system core
  542. * - Set by user
  543. * - Set bt Country IE
  544. */
  545. static void mwifiex_reg_notifier(struct wiphy *wiphy,
  546. struct regulatory_request *request)
  547. {
  548. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  549. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  550. MWIFIEX_BSS_ROLE_ANY);
  551. mwifiex_dbg(adapter, INFO,
  552. "info: cfg80211 regulatory domain callback for %c%c\n",
  553. request->alpha2[0], request->alpha2[1]);
  554. mwifiex_reg_apply_radar_flags(wiphy);
  555. switch (request->initiator) {
  556. case NL80211_REGDOM_SET_BY_DRIVER:
  557. case NL80211_REGDOM_SET_BY_CORE:
  558. case NL80211_REGDOM_SET_BY_USER:
  559. case NL80211_REGDOM_SET_BY_COUNTRY_IE:
  560. break;
  561. default:
  562. mwifiex_dbg(adapter, ERROR,
  563. "unknown regdom initiator: %d\n",
  564. request->initiator);
  565. return;
  566. }
  567. /* Don't send world or same regdom info to firmware */
  568. if (strncmp(request->alpha2, "00", 2) &&
  569. strncmp(request->alpha2, adapter->country_code,
  570. sizeof(request->alpha2))) {
  571. memcpy(adapter->country_code, request->alpha2,
  572. sizeof(request->alpha2));
  573. mwifiex_send_domain_info_cmd_fw(wiphy);
  574. mwifiex_dnld_txpwr_table(priv);
  575. }
  576. }
  577. /*
  578. * This function sets the fragmentation threshold.
  579. *
  580. * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
  581. * and MWIFIEX_FRAG_MAX_VALUE.
  582. */
  583. static int
  584. mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
  585. {
  586. if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
  587. frag_thr > MWIFIEX_FRAG_MAX_VALUE)
  588. frag_thr = MWIFIEX_FRAG_MAX_VALUE;
  589. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  590. HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
  591. &frag_thr, true);
  592. }
  593. /*
  594. * This function sets the RTS threshold.
  595. * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
  596. * and MWIFIEX_RTS_MAX_VALUE.
  597. */
  598. static int
  599. mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
  600. {
  601. if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
  602. rts_thr = MWIFIEX_RTS_MAX_VALUE;
  603. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  604. HostCmd_ACT_GEN_SET, RTS_THRESH_I,
  605. &rts_thr, true);
  606. }
  607. /*
  608. * CFG802.11 operation handler to set wiphy parameters.
  609. *
  610. * This function can be used to set the RTS threshold and the
  611. * Fragmentation threshold of the driver.
  612. */
  613. static int
  614. mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  615. {
  616. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  617. struct mwifiex_private *priv;
  618. struct mwifiex_uap_bss_param *bss_cfg;
  619. int ret;
  620. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  621. switch (priv->bss_role) {
  622. case MWIFIEX_BSS_ROLE_UAP:
  623. if (priv->bss_started) {
  624. mwifiex_dbg(adapter, ERROR,
  625. "cannot change wiphy params when bss started");
  626. return -EINVAL;
  627. }
  628. bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
  629. if (!bss_cfg)
  630. return -ENOMEM;
  631. mwifiex_set_sys_config_invalid_data(bss_cfg);
  632. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  633. bss_cfg->rts_threshold = wiphy->rts_threshold;
  634. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  635. bss_cfg->frag_threshold = wiphy->frag_threshold;
  636. if (changed & WIPHY_PARAM_RETRY_LONG)
  637. bss_cfg->retry_limit = wiphy->retry_long;
  638. ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  639. HostCmd_ACT_GEN_SET,
  640. UAP_BSS_PARAMS_I, bss_cfg,
  641. false);
  642. kfree(bss_cfg);
  643. if (ret) {
  644. mwifiex_dbg(adapter, ERROR,
  645. "Failed to set wiphy phy params\n");
  646. return ret;
  647. }
  648. break;
  649. case MWIFIEX_BSS_ROLE_STA:
  650. if (priv->media_connected) {
  651. mwifiex_dbg(adapter, ERROR,
  652. "cannot change wiphy params when connected");
  653. return -EINVAL;
  654. }
  655. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  656. ret = mwifiex_set_rts(priv,
  657. wiphy->rts_threshold);
  658. if (ret)
  659. return ret;
  660. }
  661. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  662. ret = mwifiex_set_frag(priv,
  663. wiphy->frag_threshold);
  664. if (ret)
  665. return ret;
  666. }
  667. break;
  668. }
  669. return 0;
  670. }
  671. static int
  672. mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
  673. {
  674. u16 mode = P2P_MODE_DISABLE;
  675. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  676. HostCmd_ACT_GEN_SET, 0, &mode, true))
  677. return -1;
  678. return 0;
  679. }
  680. /*
  681. * This function initializes the functionalities for P2P client.
  682. * The P2P client initialization sequence is:
  683. * disable -> device -> client
  684. */
  685. static int
  686. mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
  687. {
  688. u16 mode;
  689. if (mwifiex_cfg80211_deinit_p2p(priv))
  690. return -1;
  691. mode = P2P_MODE_DEVICE;
  692. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  693. HostCmd_ACT_GEN_SET, 0, &mode, true))
  694. return -1;
  695. mode = P2P_MODE_CLIENT;
  696. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  697. HostCmd_ACT_GEN_SET, 0, &mode, true))
  698. return -1;
  699. return 0;
  700. }
  701. /*
  702. * This function initializes the functionalities for P2P GO.
  703. * The P2P GO initialization sequence is:
  704. * disable -> device -> GO
  705. */
  706. static int
  707. mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
  708. {
  709. u16 mode;
  710. if (mwifiex_cfg80211_deinit_p2p(priv))
  711. return -1;
  712. mode = P2P_MODE_DEVICE;
  713. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  714. HostCmd_ACT_GEN_SET, 0, &mode, true))
  715. return -1;
  716. mode = P2P_MODE_GO;
  717. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  718. HostCmd_ACT_GEN_SET, 0, &mode, true))
  719. return -1;
  720. return 0;
  721. }
  722. static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
  723. {
  724. struct mwifiex_adapter *adapter = priv->adapter;
  725. unsigned long flags;
  726. priv->mgmt_frame_mask = 0;
  727. if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
  728. HostCmd_ACT_GEN_SET, 0,
  729. &priv->mgmt_frame_mask, false)) {
  730. mwifiex_dbg(adapter, ERROR,
  731. "could not unregister mgmt frame rx\n");
  732. return -1;
  733. }
  734. mwifiex_deauthenticate(priv, NULL);
  735. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  736. adapter->main_locked = true;
  737. if (adapter->mwifiex_processing) {
  738. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  739. flush_workqueue(adapter->workqueue);
  740. } else {
  741. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  742. }
  743. spin_lock_bh(&adapter->rx_proc_lock);
  744. adapter->rx_locked = true;
  745. if (adapter->rx_processing) {
  746. spin_unlock_bh(&adapter->rx_proc_lock);
  747. flush_workqueue(adapter->rx_workqueue);
  748. } else {
  749. spin_unlock_bh(&adapter->rx_proc_lock);
  750. }
  751. mwifiex_free_priv(priv);
  752. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  753. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  754. priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
  755. return 0;
  756. }
  757. static int
  758. mwifiex_init_new_priv_params(struct mwifiex_private *priv,
  759. struct net_device *dev,
  760. enum nl80211_iftype type)
  761. {
  762. struct mwifiex_adapter *adapter = priv->adapter;
  763. unsigned long flags;
  764. mwifiex_init_priv(priv);
  765. priv->bss_mode = type;
  766. priv->wdev.iftype = type;
  767. mwifiex_init_priv_params(priv, priv->netdev);
  768. priv->bss_started = 0;
  769. switch (type) {
  770. case NL80211_IFTYPE_STATION:
  771. case NL80211_IFTYPE_ADHOC:
  772. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  773. priv->bss_type = MWIFIEX_BSS_TYPE_STA;
  774. break;
  775. case NL80211_IFTYPE_P2P_CLIENT:
  776. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  777. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  778. break;
  779. case NL80211_IFTYPE_P2P_GO:
  780. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  781. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  782. break;
  783. case NL80211_IFTYPE_AP:
  784. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  785. priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
  786. break;
  787. default:
  788. mwifiex_dbg(adapter, ERROR,
  789. "%s: changing to %d not supported\n",
  790. dev->name, type);
  791. return -EOPNOTSUPP;
  792. }
  793. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  794. adapter->main_locked = false;
  795. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  796. spin_lock_bh(&adapter->rx_proc_lock);
  797. adapter->rx_locked = false;
  798. spin_unlock_bh(&adapter->rx_proc_lock);
  799. mwifiex_set_mac_address(priv, dev, false, NULL);
  800. return 0;
  801. }
  802. static bool
  803. is_vif_type_change_allowed(struct mwifiex_adapter *adapter,
  804. enum nl80211_iftype old_iftype,
  805. enum nl80211_iftype new_iftype)
  806. {
  807. switch (old_iftype) {
  808. case NL80211_IFTYPE_ADHOC:
  809. switch (new_iftype) {
  810. case NL80211_IFTYPE_STATION:
  811. return true;
  812. case NL80211_IFTYPE_P2P_CLIENT:
  813. case NL80211_IFTYPE_P2P_GO:
  814. return adapter->curr_iface_comb.p2p_intf !=
  815. adapter->iface_limit.p2p_intf;
  816. case NL80211_IFTYPE_AP:
  817. return adapter->curr_iface_comb.uap_intf !=
  818. adapter->iface_limit.uap_intf;
  819. default:
  820. return false;
  821. }
  822. case NL80211_IFTYPE_STATION:
  823. switch (new_iftype) {
  824. case NL80211_IFTYPE_ADHOC:
  825. return true;
  826. case NL80211_IFTYPE_P2P_CLIENT:
  827. case NL80211_IFTYPE_P2P_GO:
  828. return adapter->curr_iface_comb.p2p_intf !=
  829. adapter->iface_limit.p2p_intf;
  830. case NL80211_IFTYPE_AP:
  831. return adapter->curr_iface_comb.uap_intf !=
  832. adapter->iface_limit.uap_intf;
  833. default:
  834. return false;
  835. }
  836. case NL80211_IFTYPE_AP:
  837. switch (new_iftype) {
  838. case NL80211_IFTYPE_ADHOC:
  839. case NL80211_IFTYPE_STATION:
  840. return adapter->curr_iface_comb.sta_intf !=
  841. adapter->iface_limit.sta_intf;
  842. case NL80211_IFTYPE_P2P_CLIENT:
  843. case NL80211_IFTYPE_P2P_GO:
  844. return adapter->curr_iface_comb.p2p_intf !=
  845. adapter->iface_limit.p2p_intf;
  846. default:
  847. return false;
  848. }
  849. case NL80211_IFTYPE_P2P_CLIENT:
  850. switch (new_iftype) {
  851. case NL80211_IFTYPE_ADHOC:
  852. case NL80211_IFTYPE_STATION:
  853. return true;
  854. case NL80211_IFTYPE_P2P_GO:
  855. return true;
  856. case NL80211_IFTYPE_AP:
  857. return adapter->curr_iface_comb.uap_intf !=
  858. adapter->iface_limit.uap_intf;
  859. default:
  860. return false;
  861. }
  862. case NL80211_IFTYPE_P2P_GO:
  863. switch (new_iftype) {
  864. case NL80211_IFTYPE_ADHOC:
  865. case NL80211_IFTYPE_STATION:
  866. return true;
  867. case NL80211_IFTYPE_P2P_CLIENT:
  868. return true;
  869. case NL80211_IFTYPE_AP:
  870. return adapter->curr_iface_comb.uap_intf !=
  871. adapter->iface_limit.uap_intf;
  872. default:
  873. return false;
  874. }
  875. default:
  876. break;
  877. }
  878. return false;
  879. }
  880. static void
  881. update_vif_type_counter(struct mwifiex_adapter *adapter,
  882. enum nl80211_iftype iftype,
  883. int change)
  884. {
  885. switch (iftype) {
  886. case NL80211_IFTYPE_UNSPECIFIED:
  887. case NL80211_IFTYPE_ADHOC:
  888. case NL80211_IFTYPE_STATION:
  889. adapter->curr_iface_comb.sta_intf += change;
  890. break;
  891. case NL80211_IFTYPE_AP:
  892. adapter->curr_iface_comb.uap_intf += change;
  893. break;
  894. case NL80211_IFTYPE_P2P_CLIENT:
  895. case NL80211_IFTYPE_P2P_GO:
  896. adapter->curr_iface_comb.p2p_intf += change;
  897. break;
  898. default:
  899. mwifiex_dbg(adapter, ERROR,
  900. "%s: Unsupported iftype passed: %d\n",
  901. __func__, iftype);
  902. break;
  903. }
  904. }
  905. static int
  906. mwifiex_change_vif_to_p2p(struct net_device *dev,
  907. enum nl80211_iftype curr_iftype,
  908. enum nl80211_iftype type,
  909. struct vif_params *params)
  910. {
  911. struct mwifiex_private *priv;
  912. struct mwifiex_adapter *adapter;
  913. priv = mwifiex_netdev_get_priv(dev);
  914. if (!priv)
  915. return -1;
  916. adapter = priv->adapter;
  917. mwifiex_dbg(adapter, INFO,
  918. "%s: changing role to p2p\n", dev->name);
  919. if (mwifiex_deinit_priv_params(priv))
  920. return -1;
  921. if (mwifiex_init_new_priv_params(priv, dev, type))
  922. return -1;
  923. update_vif_type_counter(adapter, curr_iftype, -1);
  924. update_vif_type_counter(adapter, type, +1);
  925. dev->ieee80211_ptr->iftype = type;
  926. switch (type) {
  927. case NL80211_IFTYPE_P2P_CLIENT:
  928. if (mwifiex_cfg80211_init_p2p_client(priv))
  929. return -EFAULT;
  930. break;
  931. case NL80211_IFTYPE_P2P_GO:
  932. if (mwifiex_cfg80211_init_p2p_go(priv))
  933. return -EFAULT;
  934. break;
  935. default:
  936. mwifiex_dbg(adapter, ERROR,
  937. "%s: changing to %d not supported\n",
  938. dev->name, type);
  939. return -EOPNOTSUPP;
  940. }
  941. if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  942. HostCmd_ACT_GEN_SET, 0, NULL, true))
  943. return -1;
  944. if (mwifiex_sta_init_cmd(priv, false, false))
  945. return -1;
  946. return 0;
  947. }
  948. static int
  949. mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
  950. enum nl80211_iftype curr_iftype,
  951. enum nl80211_iftype type,
  952. struct vif_params *params)
  953. {
  954. struct mwifiex_private *priv;
  955. struct mwifiex_adapter *adapter;
  956. priv = mwifiex_netdev_get_priv(dev);
  957. if (!priv)
  958. return -1;
  959. adapter = priv->adapter;
  960. if (type == NL80211_IFTYPE_STATION)
  961. mwifiex_dbg(adapter, INFO,
  962. "%s: changing role to station\n", dev->name);
  963. else
  964. mwifiex_dbg(adapter, INFO,
  965. "%s: changing role to adhoc\n", dev->name);
  966. if (mwifiex_deinit_priv_params(priv))
  967. return -1;
  968. if (mwifiex_init_new_priv_params(priv, dev, type))
  969. return -1;
  970. update_vif_type_counter(adapter, curr_iftype, -1);
  971. update_vif_type_counter(adapter, type, +1);
  972. dev->ieee80211_ptr->iftype = type;
  973. if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  974. HostCmd_ACT_GEN_SET, 0, NULL, true))
  975. return -1;
  976. if (mwifiex_sta_init_cmd(priv, false, false))
  977. return -1;
  978. return 0;
  979. }
  980. static int
  981. mwifiex_change_vif_to_ap(struct net_device *dev,
  982. enum nl80211_iftype curr_iftype,
  983. enum nl80211_iftype type,
  984. struct vif_params *params)
  985. {
  986. struct mwifiex_private *priv;
  987. struct mwifiex_adapter *adapter;
  988. priv = mwifiex_netdev_get_priv(dev);
  989. if (!priv)
  990. return -1;
  991. adapter = priv->adapter;
  992. mwifiex_dbg(adapter, INFO,
  993. "%s: changing role to AP\n", dev->name);
  994. if (mwifiex_deinit_priv_params(priv))
  995. return -1;
  996. if (mwifiex_init_new_priv_params(priv, dev, type))
  997. return -1;
  998. update_vif_type_counter(adapter, curr_iftype, -1);
  999. update_vif_type_counter(adapter, type, +1);
  1000. dev->ieee80211_ptr->iftype = type;
  1001. if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  1002. HostCmd_ACT_GEN_SET, 0, NULL, true))
  1003. return -1;
  1004. if (mwifiex_sta_init_cmd(priv, false, false))
  1005. return -1;
  1006. return 0;
  1007. }
  1008. /*
  1009. * CFG802.11 operation handler to change interface type.
  1010. */
  1011. static int
  1012. mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
  1013. struct net_device *dev,
  1014. enum nl80211_iftype type,
  1015. struct vif_params *params)
  1016. {
  1017. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1018. enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
  1019. if (priv->scan_request) {
  1020. mwifiex_dbg(priv->adapter, ERROR,
  1021. "change virtual interface: scan in process\n");
  1022. return -EBUSY;
  1023. }
  1024. if (type == NL80211_IFTYPE_UNSPECIFIED) {
  1025. mwifiex_dbg(priv->adapter, INFO,
  1026. "%s: no new type specified, keeping old type %d\n",
  1027. dev->name, curr_iftype);
  1028. return 0;
  1029. }
  1030. if (curr_iftype == type) {
  1031. mwifiex_dbg(priv->adapter, INFO,
  1032. "%s: interface already is of type %d\n",
  1033. dev->name, curr_iftype);
  1034. return 0;
  1035. }
  1036. if (!is_vif_type_change_allowed(priv->adapter, curr_iftype, type)) {
  1037. mwifiex_dbg(priv->adapter, ERROR,
  1038. "%s: change from type %d to %d is not allowed\n",
  1039. dev->name, curr_iftype, type);
  1040. return -EOPNOTSUPP;
  1041. }
  1042. switch (curr_iftype) {
  1043. case NL80211_IFTYPE_ADHOC:
  1044. switch (type) {
  1045. case NL80211_IFTYPE_STATION:
  1046. priv->bss_mode = type;
  1047. priv->sec_info.authentication_mode =
  1048. NL80211_AUTHTYPE_OPEN_SYSTEM;
  1049. dev->ieee80211_ptr->iftype = type;
  1050. mwifiex_deauthenticate(priv, NULL);
  1051. return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  1052. HostCmd_ACT_GEN_SET, 0, NULL,
  1053. true);
  1054. case NL80211_IFTYPE_P2P_CLIENT:
  1055. case NL80211_IFTYPE_P2P_GO:
  1056. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  1057. type, params);
  1058. case NL80211_IFTYPE_AP:
  1059. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  1060. params);
  1061. default:
  1062. goto errnotsupp;
  1063. }
  1064. case NL80211_IFTYPE_STATION:
  1065. switch (type) {
  1066. case NL80211_IFTYPE_ADHOC:
  1067. priv->bss_mode = type;
  1068. priv->sec_info.authentication_mode =
  1069. NL80211_AUTHTYPE_OPEN_SYSTEM;
  1070. dev->ieee80211_ptr->iftype = type;
  1071. mwifiex_deauthenticate(priv, NULL);
  1072. return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  1073. HostCmd_ACT_GEN_SET, 0, NULL,
  1074. true);
  1075. case NL80211_IFTYPE_P2P_CLIENT:
  1076. case NL80211_IFTYPE_P2P_GO:
  1077. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  1078. type, params);
  1079. case NL80211_IFTYPE_AP:
  1080. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  1081. params);
  1082. default:
  1083. goto errnotsupp;
  1084. }
  1085. case NL80211_IFTYPE_AP:
  1086. switch (type) {
  1087. case NL80211_IFTYPE_ADHOC:
  1088. case NL80211_IFTYPE_STATION:
  1089. return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
  1090. type, params);
  1091. break;
  1092. case NL80211_IFTYPE_P2P_CLIENT:
  1093. case NL80211_IFTYPE_P2P_GO:
  1094. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  1095. type, params);
  1096. default:
  1097. goto errnotsupp;
  1098. }
  1099. case NL80211_IFTYPE_P2P_CLIENT:
  1100. if (mwifiex_cfg80211_deinit_p2p(priv))
  1101. return -EFAULT;
  1102. switch (type) {
  1103. case NL80211_IFTYPE_ADHOC:
  1104. case NL80211_IFTYPE_STATION:
  1105. return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
  1106. type, params);
  1107. case NL80211_IFTYPE_P2P_GO:
  1108. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  1109. type, params);
  1110. case NL80211_IFTYPE_AP:
  1111. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  1112. params);
  1113. default:
  1114. goto errnotsupp;
  1115. }
  1116. case NL80211_IFTYPE_P2P_GO:
  1117. if (mwifiex_cfg80211_deinit_p2p(priv))
  1118. return -EFAULT;
  1119. switch (type) {
  1120. case NL80211_IFTYPE_ADHOC:
  1121. case NL80211_IFTYPE_STATION:
  1122. return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
  1123. type, params);
  1124. case NL80211_IFTYPE_P2P_CLIENT:
  1125. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  1126. type, params);
  1127. case NL80211_IFTYPE_AP:
  1128. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  1129. params);
  1130. default:
  1131. goto errnotsupp;
  1132. }
  1133. default:
  1134. goto errnotsupp;
  1135. }
  1136. return 0;
  1137. errnotsupp:
  1138. mwifiex_dbg(priv->adapter, ERROR,
  1139. "unsupported interface type transition: %d to %d\n",
  1140. curr_iftype, type);
  1141. return -EOPNOTSUPP;
  1142. }
  1143. static void
  1144. mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 rateinfo, u8 htinfo,
  1145. struct rate_info *rate)
  1146. {
  1147. struct mwifiex_adapter *adapter = priv->adapter;
  1148. if (adapter->is_hw_11ac_capable) {
  1149. /* bit[1-0]: 00=LG 01=HT 10=VHT */
  1150. if (htinfo & BIT(0)) {
  1151. /* HT */
  1152. rate->mcs = rateinfo;
  1153. rate->flags |= RATE_INFO_FLAGS_MCS;
  1154. }
  1155. if (htinfo & BIT(1)) {
  1156. /* VHT */
  1157. rate->mcs = rateinfo & 0x0F;
  1158. rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
  1159. }
  1160. if (htinfo & (BIT(1) | BIT(0))) {
  1161. /* HT or VHT */
  1162. switch (htinfo & (BIT(3) | BIT(2))) {
  1163. case 0:
  1164. rate->bw = RATE_INFO_BW_20;
  1165. break;
  1166. case (BIT(2)):
  1167. rate->bw = RATE_INFO_BW_40;
  1168. break;
  1169. case (BIT(3)):
  1170. rate->bw = RATE_INFO_BW_80;
  1171. break;
  1172. case (BIT(3) | BIT(2)):
  1173. rate->bw = RATE_INFO_BW_160;
  1174. break;
  1175. }
  1176. if (htinfo & BIT(4))
  1177. rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
  1178. if ((rateinfo >> 4) == 1)
  1179. rate->nss = 2;
  1180. else
  1181. rate->nss = 1;
  1182. }
  1183. } else {
  1184. /*
  1185. * Bit 0 in htinfo indicates that current rate is 11n. Valid
  1186. * MCS index values for us are 0 to 15.
  1187. */
  1188. if ((htinfo & BIT(0)) && (rateinfo < 16)) {
  1189. rate->mcs = rateinfo;
  1190. rate->flags |= RATE_INFO_FLAGS_MCS;
  1191. rate->bw = RATE_INFO_BW_20;
  1192. if (htinfo & BIT(1))
  1193. rate->bw = RATE_INFO_BW_40;
  1194. if (htinfo & BIT(2))
  1195. rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
  1196. }
  1197. }
  1198. /* Decode legacy rates for non-HT. */
  1199. if (!(htinfo & (BIT(0) | BIT(1)))) {
  1200. /* Bitrates in multiples of 100kb/s. */
  1201. static const int legacy_rates[] = {
  1202. [0] = 10,
  1203. [1] = 20,
  1204. [2] = 55,
  1205. [3] = 110,
  1206. [4] = 60, /* MWIFIEX_RATE_INDEX_OFDM0 */
  1207. [5] = 60,
  1208. [6] = 90,
  1209. [7] = 120,
  1210. [8] = 180,
  1211. [9] = 240,
  1212. [10] = 360,
  1213. [11] = 480,
  1214. [12] = 540,
  1215. };
  1216. if (rateinfo < ARRAY_SIZE(legacy_rates))
  1217. rate->legacy = legacy_rates[rateinfo];
  1218. }
  1219. }
  1220. /*
  1221. * This function dumps the station information on a buffer.
  1222. *
  1223. * The following information are shown -
  1224. * - Total bytes transmitted
  1225. * - Total bytes received
  1226. * - Total packets transmitted
  1227. * - Total packets received
  1228. * - Signal quality level
  1229. * - Transmission rate
  1230. */
  1231. static int
  1232. mwifiex_dump_station_info(struct mwifiex_private *priv,
  1233. struct mwifiex_sta_node *node,
  1234. struct station_info *sinfo)
  1235. {
  1236. u32 rate;
  1237. sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
  1238. BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
  1239. BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
  1240. BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
  1241. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  1242. if (!node)
  1243. return -ENOENT;
  1244. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
  1245. BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  1246. sinfo->inactive_time =
  1247. jiffies_to_msecs(jiffies - node->stats.last_rx);
  1248. sinfo->signal = node->stats.rssi;
  1249. sinfo->signal_avg = node->stats.rssi;
  1250. sinfo->rx_bytes = node->stats.rx_bytes;
  1251. sinfo->tx_bytes = node->stats.tx_bytes;
  1252. sinfo->rx_packets = node->stats.rx_packets;
  1253. sinfo->tx_packets = node->stats.tx_packets;
  1254. sinfo->tx_failed = node->stats.tx_failed;
  1255. mwifiex_parse_htinfo(priv, priv->tx_rate,
  1256. node->stats.last_tx_htinfo,
  1257. &sinfo->txrate);
  1258. sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
  1259. return 0;
  1260. }
  1261. /* Get signal information from the firmware */
  1262. if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
  1263. HostCmd_ACT_GEN_GET, 0, NULL, true)) {
  1264. mwifiex_dbg(priv->adapter, ERROR,
  1265. "failed to get signal information\n");
  1266. return -EFAULT;
  1267. }
  1268. if (mwifiex_drv_get_data_rate(priv, &rate)) {
  1269. mwifiex_dbg(priv->adapter, ERROR,
  1270. "getting data rate error\n");
  1271. return -EFAULT;
  1272. }
  1273. /* Get DTIM period information from firmware */
  1274. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1275. HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
  1276. &priv->dtim_period, true);
  1277. mwifiex_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo,
  1278. &sinfo->txrate);
  1279. sinfo->signal_avg = priv->bcn_rssi_avg;
  1280. sinfo->rx_bytes = priv->stats.rx_bytes;
  1281. sinfo->tx_bytes = priv->stats.tx_bytes;
  1282. sinfo->rx_packets = priv->stats.rx_packets;
  1283. sinfo->tx_packets = priv->stats.tx_packets;
  1284. sinfo->signal = priv->bcn_rssi_avg;
  1285. /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
  1286. sinfo->txrate.legacy = rate * 5;
  1287. sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
  1288. mwifiex_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo,
  1289. &sinfo->rxrate);
  1290. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  1291. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
  1292. sinfo->bss_param.flags = 0;
  1293. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  1294. WLAN_CAPABILITY_SHORT_PREAMBLE)
  1295. sinfo->bss_param.flags |=
  1296. BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  1297. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  1298. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  1299. sinfo->bss_param.flags |=
  1300. BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  1301. sinfo->bss_param.dtim_period = priv->dtim_period;
  1302. sinfo->bss_param.beacon_interval =
  1303. priv->curr_bss_params.bss_descriptor.beacon_period;
  1304. }
  1305. return 0;
  1306. }
  1307. /*
  1308. * CFG802.11 operation handler to get station information.
  1309. *
  1310. * This function only works in connected mode, and dumps the
  1311. * requested station information, if available.
  1312. */
  1313. static int
  1314. mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  1315. const u8 *mac, struct station_info *sinfo)
  1316. {
  1317. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1318. if (!priv->media_connected)
  1319. return -ENOENT;
  1320. if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
  1321. return -ENOENT;
  1322. return mwifiex_dump_station_info(priv, NULL, sinfo);
  1323. }
  1324. /*
  1325. * CFG802.11 operation handler to dump station information.
  1326. */
  1327. static int
  1328. mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  1329. int idx, u8 *mac, struct station_info *sinfo)
  1330. {
  1331. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1332. struct mwifiex_sta_node *node;
  1333. int i;
  1334. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  1335. priv->media_connected && idx == 0) {
  1336. ether_addr_copy(mac, priv->cfg_bssid);
  1337. return mwifiex_dump_station_info(priv, NULL, sinfo);
  1338. } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  1339. mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
  1340. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1341. i = 0;
  1342. list_for_each_entry(node, &priv->sta_list, list) {
  1343. if (i++ != idx)
  1344. continue;
  1345. ether_addr_copy(mac, node->mac_addr);
  1346. return mwifiex_dump_station_info(priv, node, sinfo);
  1347. }
  1348. }
  1349. return -ENOENT;
  1350. }
  1351. static int
  1352. mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  1353. int idx, struct survey_info *survey)
  1354. {
  1355. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1356. struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
  1357. enum nl80211_band band;
  1358. mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
  1359. memset(survey, 0, sizeof(struct survey_info));
  1360. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  1361. priv->media_connected && idx == 0) {
  1362. u8 curr_bss_band = priv->curr_bss_params.band;
  1363. u32 chan = priv->curr_bss_params.bss_descriptor.channel;
  1364. band = mwifiex_band_to_radio_type(curr_bss_band);
  1365. survey->channel = ieee80211_get_channel(wiphy,
  1366. ieee80211_channel_to_frequency(chan, band));
  1367. if (priv->bcn_nf_last) {
  1368. survey->filled = SURVEY_INFO_NOISE_DBM;
  1369. survey->noise = priv->bcn_nf_last;
  1370. }
  1371. return 0;
  1372. }
  1373. if (idx >= priv->adapter->num_in_chan_stats)
  1374. return -ENOENT;
  1375. if (!pchan_stats[idx].cca_scan_dur)
  1376. return 0;
  1377. band = pchan_stats[idx].bandcfg;
  1378. survey->channel = ieee80211_get_channel(wiphy,
  1379. ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
  1380. survey->filled = SURVEY_INFO_NOISE_DBM |
  1381. SURVEY_INFO_TIME |
  1382. SURVEY_INFO_TIME_BUSY;
  1383. survey->noise = pchan_stats[idx].noise;
  1384. survey->time = pchan_stats[idx].cca_scan_dur;
  1385. survey->time_busy = pchan_stats[idx].cca_busy_dur;
  1386. return 0;
  1387. }
  1388. /* Supported rates to be advertised to the cfg80211 */
  1389. static struct ieee80211_rate mwifiex_rates[] = {
  1390. {.bitrate = 10, .hw_value = 2, },
  1391. {.bitrate = 20, .hw_value = 4, },
  1392. {.bitrate = 55, .hw_value = 11, },
  1393. {.bitrate = 110, .hw_value = 22, },
  1394. {.bitrate = 60, .hw_value = 12, },
  1395. {.bitrate = 90, .hw_value = 18, },
  1396. {.bitrate = 120, .hw_value = 24, },
  1397. {.bitrate = 180, .hw_value = 36, },
  1398. {.bitrate = 240, .hw_value = 48, },
  1399. {.bitrate = 360, .hw_value = 72, },
  1400. {.bitrate = 480, .hw_value = 96, },
  1401. {.bitrate = 540, .hw_value = 108, },
  1402. };
  1403. /* Channel definitions to be advertised to cfg80211 */
  1404. static struct ieee80211_channel mwifiex_channels_2ghz[] = {
  1405. {.center_freq = 2412, .hw_value = 1, },
  1406. {.center_freq = 2417, .hw_value = 2, },
  1407. {.center_freq = 2422, .hw_value = 3, },
  1408. {.center_freq = 2427, .hw_value = 4, },
  1409. {.center_freq = 2432, .hw_value = 5, },
  1410. {.center_freq = 2437, .hw_value = 6, },
  1411. {.center_freq = 2442, .hw_value = 7, },
  1412. {.center_freq = 2447, .hw_value = 8, },
  1413. {.center_freq = 2452, .hw_value = 9, },
  1414. {.center_freq = 2457, .hw_value = 10, },
  1415. {.center_freq = 2462, .hw_value = 11, },
  1416. {.center_freq = 2467, .hw_value = 12, },
  1417. {.center_freq = 2472, .hw_value = 13, },
  1418. {.center_freq = 2484, .hw_value = 14, },
  1419. };
  1420. static struct ieee80211_supported_band mwifiex_band_2ghz = {
  1421. .channels = mwifiex_channels_2ghz,
  1422. .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
  1423. .bitrates = mwifiex_rates,
  1424. .n_bitrates = ARRAY_SIZE(mwifiex_rates),
  1425. };
  1426. static struct ieee80211_channel mwifiex_channels_5ghz[] = {
  1427. {.center_freq = 5040, .hw_value = 8, },
  1428. {.center_freq = 5060, .hw_value = 12, },
  1429. {.center_freq = 5080, .hw_value = 16, },
  1430. {.center_freq = 5170, .hw_value = 34, },
  1431. {.center_freq = 5190, .hw_value = 38, },
  1432. {.center_freq = 5210, .hw_value = 42, },
  1433. {.center_freq = 5230, .hw_value = 46, },
  1434. {.center_freq = 5180, .hw_value = 36, },
  1435. {.center_freq = 5200, .hw_value = 40, },
  1436. {.center_freq = 5220, .hw_value = 44, },
  1437. {.center_freq = 5240, .hw_value = 48, },
  1438. {.center_freq = 5260, .hw_value = 52, },
  1439. {.center_freq = 5280, .hw_value = 56, },
  1440. {.center_freq = 5300, .hw_value = 60, },
  1441. {.center_freq = 5320, .hw_value = 64, },
  1442. {.center_freq = 5500, .hw_value = 100, },
  1443. {.center_freq = 5520, .hw_value = 104, },
  1444. {.center_freq = 5540, .hw_value = 108, },
  1445. {.center_freq = 5560, .hw_value = 112, },
  1446. {.center_freq = 5580, .hw_value = 116, },
  1447. {.center_freq = 5600, .hw_value = 120, },
  1448. {.center_freq = 5620, .hw_value = 124, },
  1449. {.center_freq = 5640, .hw_value = 128, },
  1450. {.center_freq = 5660, .hw_value = 132, },
  1451. {.center_freq = 5680, .hw_value = 136, },
  1452. {.center_freq = 5700, .hw_value = 140, },
  1453. {.center_freq = 5745, .hw_value = 149, },
  1454. {.center_freq = 5765, .hw_value = 153, },
  1455. {.center_freq = 5785, .hw_value = 157, },
  1456. {.center_freq = 5805, .hw_value = 161, },
  1457. {.center_freq = 5825, .hw_value = 165, },
  1458. };
  1459. static struct ieee80211_supported_band mwifiex_band_5ghz = {
  1460. .channels = mwifiex_channels_5ghz,
  1461. .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
  1462. .bitrates = mwifiex_rates + 4,
  1463. .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
  1464. };
  1465. /* Supported crypto cipher suits to be advertised to cfg80211 */
  1466. static const u32 mwifiex_cipher_suites[] = {
  1467. WLAN_CIPHER_SUITE_WEP40,
  1468. WLAN_CIPHER_SUITE_WEP104,
  1469. WLAN_CIPHER_SUITE_TKIP,
  1470. WLAN_CIPHER_SUITE_CCMP,
  1471. WLAN_CIPHER_SUITE_SMS4,
  1472. WLAN_CIPHER_SUITE_AES_CMAC,
  1473. };
  1474. /* Supported mgmt frame types to be advertised to cfg80211 */
  1475. static const struct ieee80211_txrx_stypes
  1476. mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  1477. [NL80211_IFTYPE_STATION] = {
  1478. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1479. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1480. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1481. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1482. },
  1483. [NL80211_IFTYPE_AP] = {
  1484. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1485. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1486. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1487. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1488. },
  1489. [NL80211_IFTYPE_P2P_CLIENT] = {
  1490. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1491. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1492. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1493. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1494. },
  1495. [NL80211_IFTYPE_P2P_GO] = {
  1496. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1497. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1498. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1499. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1500. },
  1501. };
  1502. /*
  1503. * CFG802.11 operation handler for setting bit rates.
  1504. *
  1505. * Function configures data rates to firmware using bitrate mask
  1506. * provided by cfg80211.
  1507. */
  1508. static int
  1509. mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
  1510. struct net_device *dev,
  1511. unsigned int link_id,
  1512. const u8 *peer,
  1513. const struct cfg80211_bitrate_mask *mask)
  1514. {
  1515. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1516. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  1517. enum nl80211_band band;
  1518. struct mwifiex_adapter *adapter = priv->adapter;
  1519. if (!priv->media_connected) {
  1520. mwifiex_dbg(adapter, ERROR,
  1521. "Can not set Tx data rate in disconnected state\n");
  1522. return -EINVAL;
  1523. }
  1524. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  1525. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1526. /* Fill HR/DSSS rates. */
  1527. if (band == NL80211_BAND_2GHZ)
  1528. bitmap_rates[0] = mask->control[band].legacy & 0x000f;
  1529. /* Fill OFDM rates */
  1530. if (band == NL80211_BAND_2GHZ)
  1531. bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
  1532. else
  1533. bitmap_rates[1] = mask->control[band].legacy;
  1534. /* Fill HT MCS rates */
  1535. bitmap_rates[2] = mask->control[band].ht_mcs[0];
  1536. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  1537. bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
  1538. /* Fill VHT MCS rates */
  1539. if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
  1540. bitmap_rates[10] = mask->control[band].vht_mcs[0];
  1541. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  1542. bitmap_rates[11] = mask->control[band].vht_mcs[1];
  1543. }
  1544. return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
  1545. HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
  1546. }
  1547. /*
  1548. * CFG802.11 operation handler for connection quality monitoring.
  1549. *
  1550. * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
  1551. * events to FW.
  1552. */
  1553. static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1554. struct net_device *dev,
  1555. s32 rssi_thold, u32 rssi_hyst)
  1556. {
  1557. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1558. struct mwifiex_ds_misc_subsc_evt subsc_evt;
  1559. priv->cqm_rssi_thold = rssi_thold;
  1560. priv->cqm_rssi_hyst = rssi_hyst;
  1561. memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  1562. subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  1563. /* Subscribe/unsubscribe low and high rssi events */
  1564. if (rssi_thold && rssi_hyst) {
  1565. subsc_evt.action = HostCmd_ACT_BITWISE_SET;
  1566. subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
  1567. subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
  1568. subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
  1569. subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
  1570. return mwifiex_send_cmd(priv,
  1571. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  1572. 0, 0, &subsc_evt, true);
  1573. } else {
  1574. subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
  1575. return mwifiex_send_cmd(priv,
  1576. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  1577. 0, 0, &subsc_evt, true);
  1578. }
  1579. return 0;
  1580. }
  1581. /* cfg80211 operation handler for change_beacon.
  1582. * Function retrieves and sets modified management IEs to FW.
  1583. */
  1584. static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
  1585. struct net_device *dev,
  1586. struct cfg80211_beacon_data *data)
  1587. {
  1588. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1589. struct mwifiex_adapter *adapter = priv->adapter;
  1590. mwifiex_cancel_scan(adapter);
  1591. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
  1592. mwifiex_dbg(priv->adapter, ERROR,
  1593. "%s: bss_type mismatched\n", __func__);
  1594. return -EINVAL;
  1595. }
  1596. if (!priv->bss_started) {
  1597. mwifiex_dbg(priv->adapter, ERROR,
  1598. "%s: bss not started\n", __func__);
  1599. return -EINVAL;
  1600. }
  1601. if (mwifiex_set_mgmt_ies(priv, data)) {
  1602. mwifiex_dbg(priv->adapter, ERROR,
  1603. "%s: setting mgmt ies failed\n", __func__);
  1604. return -EFAULT;
  1605. }
  1606. return 0;
  1607. }
  1608. /* cfg80211 operation handler for del_station.
  1609. * Function deauthenticates station which value is provided in mac parameter.
  1610. * If mac is NULL/broadcast, all stations in associated station list are
  1611. * deauthenticated. If bss is not started or there are no stations in
  1612. * associated stations list, no action is taken.
  1613. */
  1614. static int
  1615. mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1616. struct station_del_parameters *params)
  1617. {
  1618. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1619. struct mwifiex_sta_node *sta_node;
  1620. u8 deauth_mac[ETH_ALEN];
  1621. if (!priv->bss_started && priv->wdev.cac_started) {
  1622. mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
  1623. mwifiex_abort_cac(priv);
  1624. }
  1625. if (list_empty(&priv->sta_list) || !priv->bss_started)
  1626. return 0;
  1627. if (!params->mac || is_broadcast_ether_addr(params->mac))
  1628. return 0;
  1629. mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
  1630. __func__, params->mac);
  1631. eth_zero_addr(deauth_mac);
  1632. spin_lock_bh(&priv->sta_list_spinlock);
  1633. sta_node = mwifiex_get_sta_entry(priv, params->mac);
  1634. if (sta_node)
  1635. ether_addr_copy(deauth_mac, params->mac);
  1636. spin_unlock_bh(&priv->sta_list_spinlock);
  1637. if (is_valid_ether_addr(deauth_mac)) {
  1638. if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
  1639. HostCmd_ACT_GEN_SET, 0,
  1640. deauth_mac, true))
  1641. return -1;
  1642. }
  1643. return 0;
  1644. }
  1645. static int
  1646. mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1647. {
  1648. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1649. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  1650. MWIFIEX_BSS_ROLE_ANY);
  1651. struct mwifiex_ds_ant_cfg ant_cfg;
  1652. if (!tx_ant || !rx_ant)
  1653. return -EOPNOTSUPP;
  1654. if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
  1655. /* Not a MIMO chip. User should provide specific antenna number
  1656. * for Tx/Rx path or enable all antennas for diversity
  1657. */
  1658. if (tx_ant != rx_ant)
  1659. return -EOPNOTSUPP;
  1660. if ((tx_ant & (tx_ant - 1)) &&
  1661. (tx_ant != BIT(adapter->number_of_antenna) - 1))
  1662. return -EOPNOTSUPP;
  1663. if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
  1664. (priv->adapter->number_of_antenna > 1)) {
  1665. tx_ant = RF_ANTENNA_AUTO;
  1666. rx_ant = RF_ANTENNA_AUTO;
  1667. }
  1668. } else {
  1669. struct ieee80211_sta_ht_cap *ht_info;
  1670. int rx_mcs_supp;
  1671. enum nl80211_band band;
  1672. if ((tx_ant == 0x1 && rx_ant == 0x1)) {
  1673. adapter->user_dev_mcs_support = HT_STREAM_1X1;
  1674. if (adapter->is_hw_11ac_capable)
  1675. adapter->usr_dot_11ac_mcs_support =
  1676. MWIFIEX_11AC_MCS_MAP_1X1;
  1677. } else {
  1678. adapter->user_dev_mcs_support = HT_STREAM_2X2;
  1679. if (adapter->is_hw_11ac_capable)
  1680. adapter->usr_dot_11ac_mcs_support =
  1681. MWIFIEX_11AC_MCS_MAP_2X2;
  1682. }
  1683. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1684. if (!adapter->wiphy->bands[band])
  1685. continue;
  1686. ht_info = &adapter->wiphy->bands[band]->ht_cap;
  1687. rx_mcs_supp =
  1688. GET_RXMCSSUPP(adapter->user_dev_mcs_support);
  1689. memset(&ht_info->mcs, 0, adapter->number_of_antenna);
  1690. memset(&ht_info->mcs, 0xff, rx_mcs_supp);
  1691. }
  1692. }
  1693. ant_cfg.tx_ant = tx_ant;
  1694. ant_cfg.rx_ant = rx_ant;
  1695. return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
  1696. HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
  1697. }
  1698. static int
  1699. mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1700. {
  1701. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1702. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  1703. MWIFIEX_BSS_ROLE_ANY);
  1704. mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
  1705. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1706. *tx_ant = priv->tx_ant;
  1707. *rx_ant = priv->rx_ant;
  1708. return 0;
  1709. }
  1710. /* cfg80211 operation handler for stop ap.
  1711. * Function stops BSS running at uAP interface.
  1712. */
  1713. static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
  1714. unsigned int link_id)
  1715. {
  1716. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1717. mwifiex_abort_cac(priv);
  1718. if (mwifiex_del_mgmt_ies(priv))
  1719. mwifiex_dbg(priv->adapter, ERROR,
  1720. "Failed to delete mgmt IEs!\n");
  1721. priv->ap_11n_enabled = 0;
  1722. memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
  1723. if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
  1724. HostCmd_ACT_GEN_SET, 0, NULL, true)) {
  1725. mwifiex_dbg(priv->adapter, ERROR,
  1726. "Failed to stop the BSS\n");
  1727. return -1;
  1728. }
  1729. if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
  1730. HostCmd_ACT_GEN_SET, 0, NULL, true)) {
  1731. mwifiex_dbg(priv->adapter, ERROR,
  1732. "Failed to reset BSS\n");
  1733. return -1;
  1734. }
  1735. if (netif_carrier_ok(priv->netdev))
  1736. netif_carrier_off(priv->netdev);
  1737. mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
  1738. return 0;
  1739. }
  1740. /* cfg80211 operation handler for start_ap.
  1741. * Function sets beacon period, DTIM period, SSID and security into
  1742. * AP config structure.
  1743. * AP is configured with these settings and BSS is started.
  1744. */
  1745. static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
  1746. struct net_device *dev,
  1747. struct cfg80211_ap_settings *params)
  1748. {
  1749. struct mwifiex_uap_bss_param *bss_cfg;
  1750. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1751. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
  1752. return -1;
  1753. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  1754. if (!bss_cfg)
  1755. return -ENOMEM;
  1756. mwifiex_set_sys_config_invalid_data(bss_cfg);
  1757. if (params->beacon_interval)
  1758. bss_cfg->beacon_period = params->beacon_interval;
  1759. if (params->dtim_period)
  1760. bss_cfg->dtim_period = params->dtim_period;
  1761. if (params->ssid && params->ssid_len) {
  1762. memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
  1763. bss_cfg->ssid.ssid_len = params->ssid_len;
  1764. }
  1765. if (params->inactivity_timeout > 0) {
  1766. /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
  1767. bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
  1768. bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
  1769. }
  1770. switch (params->hidden_ssid) {
  1771. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  1772. bss_cfg->bcast_ssid_ctl = 1;
  1773. break;
  1774. case NL80211_HIDDEN_SSID_ZERO_LEN:
  1775. bss_cfg->bcast_ssid_ctl = 0;
  1776. break;
  1777. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  1778. bss_cfg->bcast_ssid_ctl = 2;
  1779. break;
  1780. default:
  1781. kfree(bss_cfg);
  1782. return -EINVAL;
  1783. }
  1784. mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
  1785. mwifiex_set_uap_rates(bss_cfg, params);
  1786. if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
  1787. mwifiex_dbg(priv->adapter, ERROR,
  1788. "Failed to parse security parameters!\n");
  1789. goto out;
  1790. }
  1791. mwifiex_set_ht_params(priv, bss_cfg, params);
  1792. if (priv->adapter->is_hw_11ac_capable) {
  1793. mwifiex_set_vht_params(priv, bss_cfg, params);
  1794. mwifiex_set_vht_width(priv, params->chandef.width,
  1795. priv->ap_11ac_enabled);
  1796. }
  1797. if (priv->ap_11ac_enabled)
  1798. mwifiex_set_11ac_ba_params(priv);
  1799. else
  1800. mwifiex_set_ba_params(priv);
  1801. mwifiex_set_wmm_params(priv, bss_cfg, params);
  1802. if (mwifiex_is_11h_active(priv))
  1803. mwifiex_set_tpc_params(priv, bss_cfg, params);
  1804. if (mwifiex_is_11h_active(priv) &&
  1805. !cfg80211_chandef_dfs_required(wiphy, &params->chandef,
  1806. priv->bss_mode)) {
  1807. mwifiex_dbg(priv->adapter, INFO,
  1808. "Disable 11h extensions in FW\n");
  1809. if (mwifiex_11h_activate(priv, false)) {
  1810. mwifiex_dbg(priv->adapter, ERROR,
  1811. "Failed to disable 11h extensions!!");
  1812. goto out;
  1813. }
  1814. priv->state_11h.is_11h_active = false;
  1815. }
  1816. mwifiex_config_uap_11d(priv, &params->beacon);
  1817. if (mwifiex_config_start_uap(priv, bss_cfg)) {
  1818. mwifiex_dbg(priv->adapter, ERROR,
  1819. "Failed to start AP\n");
  1820. goto out;
  1821. }
  1822. if (mwifiex_set_mgmt_ies(priv, &params->beacon))
  1823. goto out;
  1824. if (!netif_carrier_ok(priv->netdev))
  1825. netif_carrier_on(priv->netdev);
  1826. mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
  1827. memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
  1828. kfree(bss_cfg);
  1829. return 0;
  1830. out:
  1831. kfree(bss_cfg);
  1832. return -1;
  1833. }
  1834. /*
  1835. * CFG802.11 operation handler for disconnection request.
  1836. *
  1837. * This function does not work when there is already a disconnection
  1838. * procedure going on.
  1839. */
  1840. static int
  1841. mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1842. u16 reason_code)
  1843. {
  1844. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1845. if (!mwifiex_stop_bg_scan(priv))
  1846. cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
  1847. if (mwifiex_deauthenticate(priv, NULL))
  1848. return -EFAULT;
  1849. eth_zero_addr(priv->cfg_bssid);
  1850. priv->hs2_enabled = false;
  1851. return 0;
  1852. }
  1853. /*
  1854. * This function informs the CFG802.11 subsystem of a new IBSS.
  1855. *
  1856. * The following information are sent to the CFG802.11 subsystem
  1857. * to register the new IBSS. If we do not register the new IBSS,
  1858. * a kernel panic will result.
  1859. * - SSID
  1860. * - SSID length
  1861. * - BSSID
  1862. * - Channel
  1863. */
  1864. static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
  1865. {
  1866. struct ieee80211_channel *chan;
  1867. struct mwifiex_bss_info bss_info;
  1868. struct cfg80211_bss *bss;
  1869. int ie_len;
  1870. u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
  1871. enum nl80211_band band;
  1872. if (mwifiex_get_bss_info(priv, &bss_info))
  1873. return -1;
  1874. ie_buf[0] = WLAN_EID_SSID;
  1875. ie_buf[1] = bss_info.ssid.ssid_len;
  1876. memcpy(&ie_buf[sizeof(struct ieee_types_header)],
  1877. &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
  1878. ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
  1879. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  1880. chan = ieee80211_get_channel(priv->wdev.wiphy,
  1881. ieee80211_channel_to_frequency(bss_info.bss_chan,
  1882. band));
  1883. bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
  1884. CFG80211_BSS_FTYPE_UNKNOWN,
  1885. bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
  1886. 0, ie_buf, ie_len, 0, GFP_KERNEL);
  1887. if (bss) {
  1888. cfg80211_put_bss(priv->wdev.wiphy, bss);
  1889. ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
  1890. }
  1891. return 0;
  1892. }
  1893. /*
  1894. * This function connects with a BSS.
  1895. *
  1896. * This function handles both Infra and Ad-Hoc modes. It also performs
  1897. * validity checking on the provided parameters, disconnects from the
  1898. * current BSS (if any), sets up the association/scan parameters,
  1899. * including security settings, and performs specific SSID scan before
  1900. * trying to connect.
  1901. *
  1902. * For Infra mode, the function returns failure if the specified SSID
  1903. * is not found in scan table. However, for Ad-Hoc mode, it can create
  1904. * the IBSS if it does not exist. On successful completion in either case,
  1905. * the function notifies the CFG802.11 subsystem of the new BSS connection.
  1906. */
  1907. static int
  1908. mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
  1909. const u8 *ssid, const u8 *bssid, int mode,
  1910. struct ieee80211_channel *channel,
  1911. struct cfg80211_connect_params *sme, bool privacy,
  1912. struct cfg80211_bss **sel_bss)
  1913. {
  1914. struct cfg80211_ssid req_ssid;
  1915. int ret, auth_type = 0;
  1916. struct cfg80211_bss *bss = NULL;
  1917. u8 is_scanning_required = 0;
  1918. memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
  1919. req_ssid.ssid_len = ssid_len;
  1920. if (ssid_len > IEEE80211_MAX_SSID_LEN) {
  1921. mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
  1922. return -EINVAL;
  1923. }
  1924. memcpy(req_ssid.ssid, ssid, ssid_len);
  1925. if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
  1926. mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
  1927. return -EINVAL;
  1928. }
  1929. /* As this is new association, clear locally stored
  1930. * keys and security related flags */
  1931. priv->sec_info.wpa_enabled = false;
  1932. priv->sec_info.wpa2_enabled = false;
  1933. priv->wep_key_curr_index = 0;
  1934. priv->sec_info.encryption_mode = 0;
  1935. priv->sec_info.is_authtype_auto = 0;
  1936. ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
  1937. if (mode == NL80211_IFTYPE_ADHOC) {
  1938. u16 enable = true;
  1939. /* set ibss coalescing_status */
  1940. ret = mwifiex_send_cmd(
  1941. priv,
  1942. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1943. HostCmd_ACT_GEN_SET, 0, &enable, true);
  1944. if (ret)
  1945. return ret;
  1946. /* "privacy" is set only for ad-hoc mode */
  1947. if (privacy) {
  1948. /*
  1949. * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
  1950. * the firmware can find a matching network from the
  1951. * scan. The cfg80211 does not give us the encryption
  1952. * mode at this stage so just setting it to WEP here.
  1953. */
  1954. priv->sec_info.encryption_mode =
  1955. WLAN_CIPHER_SUITE_WEP104;
  1956. priv->sec_info.authentication_mode =
  1957. NL80211_AUTHTYPE_OPEN_SYSTEM;
  1958. }
  1959. goto done;
  1960. }
  1961. /* Now handle infra mode. "sme" is valid for infra mode only */
  1962. if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
  1963. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1964. priv->sec_info.is_authtype_auto = 1;
  1965. } else {
  1966. auth_type = sme->auth_type;
  1967. }
  1968. if (sme->crypto.n_ciphers_pairwise) {
  1969. priv->sec_info.encryption_mode =
  1970. sme->crypto.ciphers_pairwise[0];
  1971. priv->sec_info.authentication_mode = auth_type;
  1972. }
  1973. if (sme->crypto.cipher_group) {
  1974. priv->sec_info.encryption_mode = sme->crypto.cipher_group;
  1975. priv->sec_info.authentication_mode = auth_type;
  1976. }
  1977. if (sme->ie)
  1978. ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
  1979. if (sme->key) {
  1980. if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
  1981. mwifiex_dbg(priv->adapter, INFO,
  1982. "info: setting wep encryption\t"
  1983. "with key len %d\n", sme->key_len);
  1984. priv->wep_key_curr_index = sme->key_idx;
  1985. ret = mwifiex_set_encode(priv, NULL, sme->key,
  1986. sme->key_len, sme->key_idx,
  1987. NULL, 0);
  1988. }
  1989. }
  1990. done:
  1991. /*
  1992. * Scan entries are valid for some time (15 sec). So we can save one
  1993. * active scan time if we just try cfg80211_get_bss first. If it fails
  1994. * then request scan and cfg80211_get_bss() again for final output.
  1995. */
  1996. while (1) {
  1997. if (is_scanning_required) {
  1998. /* Do specific SSID scanning */
  1999. if (mwifiex_request_scan(priv, &req_ssid)) {
  2000. mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
  2001. return -EFAULT;
  2002. }
  2003. }
  2004. /* Find the BSS we want using available scan results */
  2005. if (mode == NL80211_IFTYPE_ADHOC)
  2006. bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
  2007. bssid, ssid, ssid_len,
  2008. IEEE80211_BSS_TYPE_IBSS,
  2009. IEEE80211_PRIVACY_ANY);
  2010. else
  2011. bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
  2012. bssid, ssid, ssid_len,
  2013. IEEE80211_BSS_TYPE_ESS,
  2014. IEEE80211_PRIVACY_ANY);
  2015. if (!bss) {
  2016. if (is_scanning_required) {
  2017. mwifiex_dbg(priv->adapter, MSG,
  2018. "assoc: requested bss not found in scan results\n");
  2019. break;
  2020. }
  2021. is_scanning_required = 1;
  2022. } else {
  2023. mwifiex_dbg(priv->adapter, MSG,
  2024. "info: trying to associate to bssid %pM\n",
  2025. bss->bssid);
  2026. memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
  2027. break;
  2028. }
  2029. }
  2030. if (bss)
  2031. cfg80211_ref_bss(priv->adapter->wiphy, bss);
  2032. ret = mwifiex_bss_start(priv, bss, &req_ssid);
  2033. if (ret)
  2034. goto cleanup;
  2035. if (mode == NL80211_IFTYPE_ADHOC) {
  2036. /* Inform the BSS information to kernel, otherwise
  2037. * kernel will give a panic after successful assoc */
  2038. if (mwifiex_cfg80211_inform_ibss_bss(priv)) {
  2039. ret = -EFAULT;
  2040. goto cleanup;
  2041. }
  2042. }
  2043. /* Pass the selected BSS entry to caller. */
  2044. if (sel_bss) {
  2045. *sel_bss = bss;
  2046. bss = NULL;
  2047. }
  2048. cleanup:
  2049. if (bss)
  2050. cfg80211_put_bss(priv->adapter->wiphy, bss);
  2051. return ret;
  2052. }
  2053. /*
  2054. * CFG802.11 operation handler for association request.
  2055. *
  2056. * This function does not work when the current mode is set to Ad-Hoc, or
  2057. * when there is already an association procedure going on. The given BSS
  2058. * information is used to associate.
  2059. */
  2060. static int
  2061. mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  2062. struct cfg80211_connect_params *sme)
  2063. {
  2064. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2065. struct mwifiex_adapter *adapter = priv->adapter;
  2066. struct cfg80211_bss *bss = NULL;
  2067. int ret;
  2068. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
  2069. mwifiex_dbg(adapter, ERROR,
  2070. "%s: reject infra assoc request in non-STA role\n",
  2071. dev->name);
  2072. return -EINVAL;
  2073. }
  2074. if (priv->wdev.connected) {
  2075. mwifiex_dbg(adapter, ERROR,
  2076. "%s: already connected\n", dev->name);
  2077. return -EALREADY;
  2078. }
  2079. if (priv->scan_block)
  2080. priv->scan_block = false;
  2081. if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
  2082. test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
  2083. mwifiex_dbg(adapter, ERROR,
  2084. "%s: Ignore connection.\t"
  2085. "Card removed or FW in bad state\n",
  2086. dev->name);
  2087. return -EFAULT;
  2088. }
  2089. mwifiex_dbg(adapter, INFO,
  2090. "info: Trying to associate to bssid %pM\n", sme->bssid);
  2091. if (!mwifiex_stop_bg_scan(priv))
  2092. cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
  2093. ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
  2094. priv->bss_mode, sme->channel, sme, 0,
  2095. &bss);
  2096. if (!ret) {
  2097. cfg80211_connect_bss(priv->netdev, priv->cfg_bssid, bss, NULL,
  2098. 0, NULL, 0, WLAN_STATUS_SUCCESS,
  2099. GFP_KERNEL, NL80211_TIMEOUT_UNSPECIFIED);
  2100. mwifiex_dbg(priv->adapter, MSG,
  2101. "info: associated to bssid %pM successfully\n",
  2102. priv->cfg_bssid);
  2103. if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  2104. priv->adapter->auto_tdls &&
  2105. priv->bss_type == MWIFIEX_BSS_TYPE_STA)
  2106. mwifiex_setup_auto_tdls_timer(priv);
  2107. } else {
  2108. mwifiex_dbg(priv->adapter, ERROR,
  2109. "info: association to bssid %pM failed\n",
  2110. priv->cfg_bssid);
  2111. eth_zero_addr(priv->cfg_bssid);
  2112. if (ret > 0)
  2113. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  2114. NULL, 0, NULL, 0, ret,
  2115. GFP_KERNEL);
  2116. else
  2117. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  2118. NULL, 0, NULL, 0,
  2119. WLAN_STATUS_UNSPECIFIED_FAILURE,
  2120. GFP_KERNEL);
  2121. }
  2122. return 0;
  2123. }
  2124. /*
  2125. * This function sets following parameters for ibss network.
  2126. * - channel
  2127. * - start band
  2128. * - 11n flag
  2129. * - secondary channel offset
  2130. */
  2131. static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
  2132. struct cfg80211_ibss_params *params)
  2133. {
  2134. struct mwifiex_adapter *adapter = priv->adapter;
  2135. int index = 0, i;
  2136. u8 config_bands = 0;
  2137. if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
  2138. if (!params->basic_rates) {
  2139. config_bands = BAND_B | BAND_G;
  2140. } else {
  2141. for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
  2142. /*
  2143. * Rates below 6 Mbps in the table are CCK
  2144. * rates; 802.11b and from 6 they are OFDM;
  2145. * 802.11G
  2146. */
  2147. if (mwifiex_rates[i].bitrate == 60) {
  2148. index = 1 << i;
  2149. break;
  2150. }
  2151. }
  2152. if (params->basic_rates < index) {
  2153. config_bands = BAND_B;
  2154. } else {
  2155. config_bands = BAND_G;
  2156. if (params->basic_rates % index)
  2157. config_bands |= BAND_B;
  2158. }
  2159. }
  2160. if (cfg80211_get_chandef_type(&params->chandef) !=
  2161. NL80211_CHAN_NO_HT)
  2162. config_bands |= BAND_G | BAND_GN;
  2163. } else {
  2164. if (cfg80211_get_chandef_type(&params->chandef) ==
  2165. NL80211_CHAN_NO_HT)
  2166. config_bands = BAND_A;
  2167. else
  2168. config_bands = BAND_AN | BAND_A;
  2169. }
  2170. if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
  2171. adapter->config_bands = config_bands;
  2172. adapter->adhoc_start_band = config_bands;
  2173. if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
  2174. adapter->adhoc_11n_enabled = true;
  2175. else
  2176. adapter->adhoc_11n_enabled = false;
  2177. }
  2178. adapter->sec_chan_offset =
  2179. mwifiex_chan_type_to_sec_chan_offset(
  2180. cfg80211_get_chandef_type(&params->chandef));
  2181. priv->adhoc_channel = ieee80211_frequency_to_channel(
  2182. params->chandef.chan->center_freq);
  2183. mwifiex_dbg(adapter, INFO,
  2184. "info: set ibss band %d, chan %d, chan offset %d\n",
  2185. config_bands, priv->adhoc_channel,
  2186. adapter->sec_chan_offset);
  2187. return 0;
  2188. }
  2189. /*
  2190. * CFG802.11 operation handler to join an IBSS.
  2191. *
  2192. * This function does not work in any mode other than Ad-Hoc, or if
  2193. * a join operation is already in progress.
  2194. */
  2195. static int
  2196. mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  2197. struct cfg80211_ibss_params *params)
  2198. {
  2199. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2200. int ret = 0;
  2201. if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
  2202. mwifiex_dbg(priv->adapter, ERROR,
  2203. "request to join ibss received\t"
  2204. "when station is not in ibss mode\n");
  2205. goto done;
  2206. }
  2207. mwifiex_dbg(priv->adapter, MSG, "info: trying to join to bssid %pM\n",
  2208. params->bssid);
  2209. mwifiex_set_ibss_params(priv, params);
  2210. ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
  2211. params->bssid, priv->bss_mode,
  2212. params->chandef.chan, NULL,
  2213. params->privacy, NULL);
  2214. done:
  2215. if (!ret) {
  2216. cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
  2217. params->chandef.chan, GFP_KERNEL);
  2218. mwifiex_dbg(priv->adapter, MSG,
  2219. "info: joined/created adhoc network with bssid\t"
  2220. "%pM successfully\n", priv->cfg_bssid);
  2221. } else {
  2222. mwifiex_dbg(priv->adapter, ERROR,
  2223. "info: failed creating/joining adhoc network\n");
  2224. }
  2225. return ret;
  2226. }
  2227. /*
  2228. * CFG802.11 operation handler to leave an IBSS.
  2229. *
  2230. * This function does not work if a leave operation is
  2231. * already in progress.
  2232. */
  2233. static int
  2234. mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  2235. {
  2236. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2237. mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
  2238. priv->cfg_bssid);
  2239. if (mwifiex_deauthenticate(priv, NULL))
  2240. return -EFAULT;
  2241. eth_zero_addr(priv->cfg_bssid);
  2242. return 0;
  2243. }
  2244. /*
  2245. * CFG802.11 operation handler for scan request.
  2246. *
  2247. * This function issues a scan request to the firmware based upon
  2248. * the user specified scan configuration. On successful completion,
  2249. * it also informs the results.
  2250. */
  2251. static int
  2252. mwifiex_cfg80211_scan(struct wiphy *wiphy,
  2253. struct cfg80211_scan_request *request)
  2254. {
  2255. struct net_device *dev = request->wdev->netdev;
  2256. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2257. int i, offset, ret;
  2258. struct ieee80211_channel *chan;
  2259. struct ieee_types_header *ie;
  2260. struct mwifiex_user_scan_cfg *user_scan_cfg;
  2261. u8 mac_addr[ETH_ALEN];
  2262. mwifiex_dbg(priv->adapter, CMD,
  2263. "info: received scan request on %s\n", dev->name);
  2264. /* Block scan request if scan operation or scan cleanup when interface
  2265. * is disabled is in process
  2266. */
  2267. if (priv->scan_request || priv->scan_aborting) {
  2268. mwifiex_dbg(priv->adapter, WARN,
  2269. "cmd: Scan already in process..\n");
  2270. return -EBUSY;
  2271. }
  2272. if (!priv->wdev.connected && priv->scan_block)
  2273. priv->scan_block = false;
  2274. if (!mwifiex_stop_bg_scan(priv))
  2275. cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
  2276. user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
  2277. if (!user_scan_cfg)
  2278. return -ENOMEM;
  2279. priv->scan_request = request;
  2280. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  2281. get_random_mask_addr(mac_addr, request->mac_addr,
  2282. request->mac_addr_mask);
  2283. ether_addr_copy(request->mac_addr, mac_addr);
  2284. ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
  2285. }
  2286. user_scan_cfg->num_ssids = request->n_ssids;
  2287. user_scan_cfg->ssid_list = request->ssids;
  2288. if (request->ie && request->ie_len) {
  2289. offset = 0;
  2290. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  2291. if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
  2292. continue;
  2293. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
  2294. ie = (struct ieee_types_header *)(request->ie + offset);
  2295. memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
  2296. offset += sizeof(*ie) + ie->len;
  2297. if (offset >= request->ie_len)
  2298. break;
  2299. }
  2300. }
  2301. for (i = 0; i < min_t(u32, request->n_channels,
  2302. MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
  2303. chan = request->channels[i];
  2304. user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
  2305. user_scan_cfg->chan_list[i].radio_type = chan->band;
  2306. if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
  2307. user_scan_cfg->chan_list[i].scan_type =
  2308. MWIFIEX_SCAN_TYPE_PASSIVE;
  2309. else
  2310. user_scan_cfg->chan_list[i].scan_type =
  2311. MWIFIEX_SCAN_TYPE_ACTIVE;
  2312. user_scan_cfg->chan_list[i].scan_time = 0;
  2313. }
  2314. if (priv->adapter->scan_chan_gap_enabled &&
  2315. mwifiex_is_any_intf_active(priv))
  2316. user_scan_cfg->scan_chan_gap =
  2317. priv->adapter->scan_chan_gap_time;
  2318. ret = mwifiex_scan_networks(priv, user_scan_cfg);
  2319. kfree(user_scan_cfg);
  2320. if (ret) {
  2321. mwifiex_dbg(priv->adapter, ERROR,
  2322. "scan failed: %d\n", ret);
  2323. priv->scan_aborting = false;
  2324. priv->scan_request = NULL;
  2325. return ret;
  2326. }
  2327. if (request->ie && request->ie_len) {
  2328. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  2329. if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
  2330. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
  2331. memset(&priv->vs_ie[i].ie, 0,
  2332. MWIFIEX_MAX_VSIE_LEN);
  2333. }
  2334. }
  2335. }
  2336. return 0;
  2337. }
  2338. /* CFG802.11 operation handler for sched_scan_start.
  2339. *
  2340. * This function issues a bgscan config request to the firmware based upon
  2341. * the user specified sched_scan configuration. On successful completion,
  2342. * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
  2343. * query command to get sched_scan results from firmware.
  2344. */
  2345. static int
  2346. mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
  2347. struct net_device *dev,
  2348. struct cfg80211_sched_scan_request *request)
  2349. {
  2350. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2351. int i, offset;
  2352. struct ieee80211_channel *chan;
  2353. struct mwifiex_bg_scan_cfg *bgscan_cfg;
  2354. struct ieee_types_header *ie;
  2355. if (!request || (!request->n_ssids && !request->n_match_sets)) {
  2356. wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
  2357. __func__);
  2358. return -EINVAL;
  2359. }
  2360. wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
  2361. request->n_ssids, request->n_match_sets);
  2362. wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
  2363. request->n_channels, request->scan_plans->interval,
  2364. (int)request->ie_len);
  2365. bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
  2366. if (!bgscan_cfg)
  2367. return -ENOMEM;
  2368. if (priv->scan_request || priv->scan_aborting)
  2369. bgscan_cfg->start_later = true;
  2370. bgscan_cfg->num_ssids = request->n_match_sets;
  2371. bgscan_cfg->ssid_list = request->match_sets;
  2372. if (request->ie && request->ie_len) {
  2373. offset = 0;
  2374. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  2375. if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
  2376. continue;
  2377. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
  2378. ie = (struct ieee_types_header *)(request->ie + offset);
  2379. memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
  2380. offset += sizeof(*ie) + ie->len;
  2381. if (offset >= request->ie_len)
  2382. break;
  2383. }
  2384. }
  2385. for (i = 0; i < min_t(u32, request->n_channels,
  2386. MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
  2387. chan = request->channels[i];
  2388. bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
  2389. bgscan_cfg->chan_list[i].radio_type = chan->band;
  2390. if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
  2391. bgscan_cfg->chan_list[i].scan_type =
  2392. MWIFIEX_SCAN_TYPE_PASSIVE;
  2393. else
  2394. bgscan_cfg->chan_list[i].scan_type =
  2395. MWIFIEX_SCAN_TYPE_ACTIVE;
  2396. bgscan_cfg->chan_list[i].scan_time = 0;
  2397. }
  2398. bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
  2399. MWIFIEX_BG_SCAN_CHAN_MAX);
  2400. /* Use at least 15 second for per scan cycle */
  2401. bgscan_cfg->scan_interval = (request->scan_plans->interval >
  2402. MWIFIEX_BGSCAN_INTERVAL) ?
  2403. request->scan_plans->interval :
  2404. MWIFIEX_BGSCAN_INTERVAL;
  2405. bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
  2406. bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
  2407. MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
  2408. bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
  2409. bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
  2410. bgscan_cfg->enable = true;
  2411. if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
  2412. bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
  2413. bgscan_cfg->rssi_threshold = request->min_rssi_thold;
  2414. }
  2415. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
  2416. HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
  2417. kfree(bgscan_cfg);
  2418. return -EFAULT;
  2419. }
  2420. priv->sched_scanning = true;
  2421. kfree(bgscan_cfg);
  2422. return 0;
  2423. }
  2424. /* CFG802.11 operation handler for sched_scan_stop.
  2425. *
  2426. * This function issues a bgscan config command to disable
  2427. * previous bgscan configuration in the firmware
  2428. */
  2429. static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
  2430. struct net_device *dev, u64 reqid)
  2431. {
  2432. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2433. wiphy_info(wiphy, "sched scan stop!");
  2434. mwifiex_stop_bg_scan(priv);
  2435. return 0;
  2436. }
  2437. static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
  2438. struct mwifiex_private *priv)
  2439. {
  2440. struct mwifiex_adapter *adapter = priv->adapter;
  2441. vht_info->vht_supported = true;
  2442. vht_info->cap = adapter->hw_dot_11ac_dev_cap;
  2443. /* Update MCS support for VHT */
  2444. vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
  2445. adapter->hw_dot_11ac_mcs_support & 0xFFFF);
  2446. vht_info->vht_mcs.rx_highest = 0;
  2447. vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
  2448. adapter->hw_dot_11ac_mcs_support >> 16);
  2449. vht_info->vht_mcs.tx_highest = 0;
  2450. }
  2451. /*
  2452. * This function sets up the CFG802.11 specific HT capability fields
  2453. * with default values.
  2454. *
  2455. * The following default values are set -
  2456. * - HT Supported = True
  2457. * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
  2458. * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
  2459. * - HT Capabilities supported by firmware
  2460. * - MCS information, Rx mask = 0xff
  2461. * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
  2462. */
  2463. static void
  2464. mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
  2465. struct mwifiex_private *priv)
  2466. {
  2467. int rx_mcs_supp;
  2468. struct ieee80211_mcs_info mcs_set;
  2469. u8 *mcs = (u8 *)&mcs_set;
  2470. struct mwifiex_adapter *adapter = priv->adapter;
  2471. ht_info->ht_supported = true;
  2472. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  2473. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  2474. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  2475. /* Fill HT capability information */
  2476. if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  2477. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2478. else
  2479. ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2480. if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
  2481. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  2482. else
  2483. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
  2484. if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
  2485. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  2486. else
  2487. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
  2488. if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
  2489. ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
  2490. else
  2491. ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
  2492. if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
  2493. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  2494. else
  2495. ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
  2496. if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
  2497. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  2498. else
  2499. ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
  2500. if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
  2501. ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
  2502. else
  2503. ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
  2504. if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
  2505. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  2506. else
  2507. ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
  2508. ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  2509. ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
  2510. rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
  2511. /* Set MCS for 1x1/2x2 */
  2512. memset(mcs, 0xff, rx_mcs_supp);
  2513. /* Clear all the other values */
  2514. memset(&mcs[rx_mcs_supp], 0,
  2515. sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
  2516. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  2517. ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  2518. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  2519. SETHT_MCS32(mcs_set.rx_mask);
  2520. memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
  2521. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  2522. }
  2523. /*
  2524. * create a new virtual interface with the given name and name assign type
  2525. */
  2526. struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
  2527. const char *name,
  2528. unsigned char name_assign_type,
  2529. enum nl80211_iftype type,
  2530. struct vif_params *params)
  2531. {
  2532. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  2533. struct mwifiex_private *priv;
  2534. struct net_device *dev;
  2535. void *mdev_priv;
  2536. int ret;
  2537. if (!adapter)
  2538. return ERR_PTR(-EFAULT);
  2539. switch (type) {
  2540. case NL80211_IFTYPE_UNSPECIFIED:
  2541. case NL80211_IFTYPE_STATION:
  2542. case NL80211_IFTYPE_ADHOC:
  2543. if (adapter->curr_iface_comb.sta_intf ==
  2544. adapter->iface_limit.sta_intf) {
  2545. mwifiex_dbg(adapter, ERROR,
  2546. "cannot create multiple sta/adhoc ifaces\n");
  2547. return ERR_PTR(-EINVAL);
  2548. }
  2549. priv = mwifiex_get_unused_priv_by_bss_type(
  2550. adapter, MWIFIEX_BSS_TYPE_STA);
  2551. if (!priv) {
  2552. mwifiex_dbg(adapter, ERROR,
  2553. "could not get free private struct\n");
  2554. return ERR_PTR(-EFAULT);
  2555. }
  2556. priv->wdev.wiphy = wiphy;
  2557. priv->wdev.iftype = NL80211_IFTYPE_STATION;
  2558. if (type == NL80211_IFTYPE_UNSPECIFIED)
  2559. priv->bss_mode = NL80211_IFTYPE_STATION;
  2560. else
  2561. priv->bss_mode = type;
  2562. priv->bss_type = MWIFIEX_BSS_TYPE_STA;
  2563. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  2564. priv->bss_priority = 0;
  2565. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  2566. break;
  2567. case NL80211_IFTYPE_AP:
  2568. if (adapter->curr_iface_comb.uap_intf ==
  2569. adapter->iface_limit.uap_intf) {
  2570. mwifiex_dbg(adapter, ERROR,
  2571. "cannot create multiple AP ifaces\n");
  2572. return ERR_PTR(-EINVAL);
  2573. }
  2574. priv = mwifiex_get_unused_priv_by_bss_type(
  2575. adapter, MWIFIEX_BSS_TYPE_UAP);
  2576. if (!priv) {
  2577. mwifiex_dbg(adapter, ERROR,
  2578. "could not get free private struct\n");
  2579. return ERR_PTR(-EFAULT);
  2580. }
  2581. priv->wdev.wiphy = wiphy;
  2582. priv->wdev.iftype = NL80211_IFTYPE_AP;
  2583. priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
  2584. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  2585. priv->bss_priority = 0;
  2586. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  2587. priv->bss_started = 0;
  2588. priv->bss_mode = type;
  2589. break;
  2590. case NL80211_IFTYPE_P2P_CLIENT:
  2591. if (adapter->curr_iface_comb.p2p_intf ==
  2592. adapter->iface_limit.p2p_intf) {
  2593. mwifiex_dbg(adapter, ERROR,
  2594. "cannot create multiple P2P ifaces\n");
  2595. return ERR_PTR(-EINVAL);
  2596. }
  2597. priv = mwifiex_get_unused_priv_by_bss_type(
  2598. adapter, MWIFIEX_BSS_TYPE_P2P);
  2599. if (!priv) {
  2600. mwifiex_dbg(adapter, ERROR,
  2601. "could not get free private struct\n");
  2602. return ERR_PTR(-EFAULT);
  2603. }
  2604. priv->wdev.wiphy = wiphy;
  2605. /* At start-up, wpa_supplicant tries to change the interface
  2606. * to NL80211_IFTYPE_STATION if it is not managed mode.
  2607. */
  2608. priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
  2609. priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
  2610. /* Setting bss_type to P2P tells firmware that this interface
  2611. * is receiving P2P peers found during find phase and doing
  2612. * action frame handshake.
  2613. */
  2614. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  2615. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  2616. priv->bss_priority = 0;
  2617. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  2618. priv->bss_started = 0;
  2619. if (mwifiex_cfg80211_init_p2p_client(priv)) {
  2620. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2621. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2622. return ERR_PTR(-EFAULT);
  2623. }
  2624. break;
  2625. default:
  2626. mwifiex_dbg(adapter, ERROR, "type not supported\n");
  2627. return ERR_PTR(-EINVAL);
  2628. }
  2629. dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
  2630. name_assign_type, ether_setup,
  2631. IEEE80211_NUM_ACS, 1);
  2632. if (!dev) {
  2633. mwifiex_dbg(adapter, ERROR,
  2634. "no memory available for netdevice\n");
  2635. ret = -ENOMEM;
  2636. goto err_alloc_netdev;
  2637. }
  2638. mwifiex_init_priv_params(priv, dev);
  2639. priv->netdev = dev;
  2640. if (!adapter->mfg_mode) {
  2641. mwifiex_set_mac_address(priv, dev, false, NULL);
  2642. ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  2643. HostCmd_ACT_GEN_SET, 0, NULL, true);
  2644. if (ret)
  2645. goto err_set_bss_mode;
  2646. ret = mwifiex_sta_init_cmd(priv, false, false);
  2647. if (ret)
  2648. goto err_sta_init;
  2649. }
  2650. mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
  2651. if (adapter->is_hw_11ac_capable)
  2652. mwifiex_setup_vht_caps(
  2653. &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
  2654. if (adapter->config_bands & BAND_A)
  2655. mwifiex_setup_ht_caps(
  2656. &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
  2657. if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
  2658. mwifiex_setup_vht_caps(
  2659. &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
  2660. dev_net_set(dev, wiphy_net(wiphy));
  2661. dev->ieee80211_ptr = &priv->wdev;
  2662. dev->ieee80211_ptr->iftype = priv->bss_mode;
  2663. SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
  2664. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  2665. dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
  2666. dev->needed_headroom = MWIFIEX_MIN_DATA_HEADER_LEN;
  2667. dev->ethtool_ops = &mwifiex_ethtool_ops;
  2668. mdev_priv = netdev_priv(dev);
  2669. *((unsigned long *) mdev_priv) = (unsigned long) priv;
  2670. SET_NETDEV_DEV(dev, adapter->dev);
  2671. priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
  2672. WQ_HIGHPRI |
  2673. WQ_MEM_RECLAIM |
  2674. WQ_UNBOUND, 1, name);
  2675. if (!priv->dfs_cac_workqueue) {
  2676. mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n");
  2677. ret = -ENOMEM;
  2678. goto err_alloc_cac;
  2679. }
  2680. INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
  2681. priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
  2682. WQ_HIGHPRI | WQ_UNBOUND |
  2683. WQ_MEM_RECLAIM, 1, name);
  2684. if (!priv->dfs_chan_sw_workqueue) {
  2685. mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n");
  2686. ret = -ENOMEM;
  2687. goto err_alloc_chsw;
  2688. }
  2689. INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
  2690. mwifiex_dfs_chan_sw_work_queue);
  2691. mutex_init(&priv->async_mutex);
  2692. /* Register network device */
  2693. if (cfg80211_register_netdevice(dev)) {
  2694. mwifiex_dbg(adapter, ERROR, "cannot register network device\n");
  2695. ret = -EFAULT;
  2696. goto err_reg_netdev;
  2697. }
  2698. mwifiex_dbg(adapter, INFO,
  2699. "info: %s: Marvell 802.11 Adapter\n", dev->name);
  2700. #ifdef CONFIG_DEBUG_FS
  2701. mwifiex_dev_debugfs_init(priv);
  2702. #endif
  2703. update_vif_type_counter(adapter, type, +1);
  2704. return &priv->wdev;
  2705. err_reg_netdev:
  2706. destroy_workqueue(priv->dfs_chan_sw_workqueue);
  2707. priv->dfs_chan_sw_workqueue = NULL;
  2708. err_alloc_chsw:
  2709. destroy_workqueue(priv->dfs_cac_workqueue);
  2710. priv->dfs_cac_workqueue = NULL;
  2711. err_alloc_cac:
  2712. free_netdev(dev);
  2713. priv->netdev = NULL;
  2714. err_sta_init:
  2715. err_set_bss_mode:
  2716. err_alloc_netdev:
  2717. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2718. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2719. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2720. return ERR_PTR(ret);
  2721. }
  2722. EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
  2723. /*
  2724. * del_virtual_intf: remove the virtual interface determined by dev
  2725. */
  2726. int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
  2727. {
  2728. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  2729. struct mwifiex_adapter *adapter = priv->adapter;
  2730. struct sk_buff *skb, *tmp;
  2731. #ifdef CONFIG_DEBUG_FS
  2732. mwifiex_dev_debugfs_remove(priv);
  2733. #endif
  2734. if (priv->sched_scanning)
  2735. priv->sched_scanning = false;
  2736. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  2737. skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
  2738. skb_unlink(skb, &priv->bypass_txq);
  2739. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  2740. }
  2741. if (netif_carrier_ok(priv->netdev))
  2742. netif_carrier_off(priv->netdev);
  2743. if (wdev->netdev->reg_state == NETREG_REGISTERED)
  2744. cfg80211_unregister_netdevice(wdev->netdev);
  2745. if (priv->dfs_cac_workqueue) {
  2746. destroy_workqueue(priv->dfs_cac_workqueue);
  2747. priv->dfs_cac_workqueue = NULL;
  2748. }
  2749. if (priv->dfs_chan_sw_workqueue) {
  2750. destroy_workqueue(priv->dfs_chan_sw_workqueue);
  2751. priv->dfs_chan_sw_workqueue = NULL;
  2752. }
  2753. /* Clear the priv in adapter */
  2754. priv->netdev = NULL;
  2755. update_vif_type_counter(adapter, priv->bss_mode, -1);
  2756. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2757. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
  2758. GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  2759. kfree(priv->hist_data);
  2760. return 0;
  2761. }
  2762. EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
  2763. static bool
  2764. mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
  2765. u8 max_byte_seq)
  2766. {
  2767. int j, k, valid_byte_cnt = 0;
  2768. bool dont_care_byte = false;
  2769. for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
  2770. for (k = 0; k < 8; k++) {
  2771. if (pat->mask[j] & 1 << k) {
  2772. memcpy(byte_seq + valid_byte_cnt,
  2773. &pat->pattern[j * 8 + k], 1);
  2774. valid_byte_cnt++;
  2775. if (dont_care_byte)
  2776. return false;
  2777. } else {
  2778. if (valid_byte_cnt)
  2779. dont_care_byte = true;
  2780. }
  2781. /* wildcard bytes record as the offset
  2782. * before the valid byte
  2783. */
  2784. if (!valid_byte_cnt && !dont_care_byte)
  2785. pat->pkt_offset++;
  2786. if (valid_byte_cnt > max_byte_seq)
  2787. return false;
  2788. }
  2789. }
  2790. byte_seq[max_byte_seq] = valid_byte_cnt;
  2791. return true;
  2792. }
  2793. #ifdef CONFIG_PM
  2794. static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
  2795. struct mwifiex_mef_entry *mef_entry)
  2796. {
  2797. int i, filt_num = 0, num_ipv4 = 0;
  2798. struct in_device *in_dev;
  2799. struct in_ifaddr *ifa;
  2800. __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
  2801. struct mwifiex_adapter *adapter = priv->adapter;
  2802. mef_entry->mode = MEF_MODE_HOST_SLEEP;
  2803. mef_entry->action = MEF_ACTION_AUTO_ARP;
  2804. /* Enable ARP offload feature */
  2805. memset(ips, 0, sizeof(ips));
  2806. for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
  2807. if (adapter->priv[i]->netdev) {
  2808. in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
  2809. if (!in_dev)
  2810. continue;
  2811. ifa = rtnl_dereference(in_dev->ifa_list);
  2812. if (!ifa || !ifa->ifa_local)
  2813. continue;
  2814. ips[i] = ifa->ifa_local;
  2815. num_ipv4++;
  2816. }
  2817. }
  2818. for (i = 0; i < num_ipv4; i++) {
  2819. if (!ips[i])
  2820. continue;
  2821. mef_entry->filter[filt_num].repeat = 1;
  2822. memcpy(mef_entry->filter[filt_num].byte_seq,
  2823. (u8 *)&ips[i], sizeof(ips[i]));
  2824. mef_entry->filter[filt_num].
  2825. byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
  2826. sizeof(ips[i]);
  2827. mef_entry->filter[filt_num].offset = 46;
  2828. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2829. if (filt_num) {
  2830. mef_entry->filter[filt_num].filt_action =
  2831. TYPE_OR;
  2832. }
  2833. filt_num++;
  2834. }
  2835. mef_entry->filter[filt_num].repeat = 1;
  2836. mef_entry->filter[filt_num].byte_seq[0] = 0x08;
  2837. mef_entry->filter[filt_num].byte_seq[1] = 0x06;
  2838. mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
  2839. mef_entry->filter[filt_num].offset = 20;
  2840. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2841. mef_entry->filter[filt_num].filt_action = TYPE_AND;
  2842. }
  2843. static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
  2844. struct mwifiex_ds_mef_cfg *mef_cfg,
  2845. struct mwifiex_mef_entry *mef_entry,
  2846. struct cfg80211_wowlan *wowlan)
  2847. {
  2848. int i, filt_num = 0, ret = 0;
  2849. bool first_pat = true;
  2850. u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
  2851. static const u8 ipv4_mc_mac[] = {0x33, 0x33};
  2852. static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
  2853. mef_entry->mode = MEF_MODE_HOST_SLEEP;
  2854. mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
  2855. for (i = 0; i < wowlan->n_patterns; i++) {
  2856. memset(byte_seq, 0, sizeof(byte_seq));
  2857. if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
  2858. byte_seq,
  2859. MWIFIEX_MEF_MAX_BYTESEQ)) {
  2860. mwifiex_dbg(priv->adapter, ERROR,
  2861. "Pattern not supported\n");
  2862. return -EOPNOTSUPP;
  2863. }
  2864. if (!wowlan->patterns[i].pkt_offset) {
  2865. if (!(byte_seq[0] & 0x01) &&
  2866. (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
  2867. mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
  2868. continue;
  2869. } else if (is_broadcast_ether_addr(byte_seq)) {
  2870. mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
  2871. continue;
  2872. } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
  2873. (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
  2874. (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
  2875. (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
  2876. mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
  2877. continue;
  2878. }
  2879. }
  2880. mef_entry->filter[filt_num].repeat = 1;
  2881. mef_entry->filter[filt_num].offset =
  2882. wowlan->patterns[i].pkt_offset;
  2883. memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
  2884. sizeof(byte_seq));
  2885. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2886. if (first_pat) {
  2887. first_pat = false;
  2888. mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
  2889. } else {
  2890. mef_entry->filter[filt_num].filt_action = TYPE_AND;
  2891. }
  2892. filt_num++;
  2893. }
  2894. if (wowlan->magic_pkt) {
  2895. mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
  2896. mef_entry->filter[filt_num].repeat = 16;
  2897. memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
  2898. ETH_ALEN);
  2899. mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
  2900. ETH_ALEN;
  2901. mef_entry->filter[filt_num].offset = 28;
  2902. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2903. if (filt_num)
  2904. mef_entry->filter[filt_num].filt_action = TYPE_OR;
  2905. filt_num++;
  2906. mef_entry->filter[filt_num].repeat = 16;
  2907. memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
  2908. ETH_ALEN);
  2909. mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
  2910. ETH_ALEN;
  2911. mef_entry->filter[filt_num].offset = 56;
  2912. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2913. mef_entry->filter[filt_num].filt_action = TYPE_OR;
  2914. mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
  2915. }
  2916. return ret;
  2917. }
  2918. static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
  2919. struct cfg80211_wowlan *wowlan)
  2920. {
  2921. int ret = 0, num_entries = 1;
  2922. struct mwifiex_ds_mef_cfg mef_cfg;
  2923. struct mwifiex_mef_entry *mef_entry;
  2924. if (wowlan->n_patterns || wowlan->magic_pkt)
  2925. num_entries++;
  2926. mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
  2927. if (!mef_entry)
  2928. return -ENOMEM;
  2929. memset(&mef_cfg, 0, sizeof(mef_cfg));
  2930. mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
  2931. MWIFIEX_CRITERIA_UNICAST;
  2932. mef_cfg.num_entries = num_entries;
  2933. mef_cfg.mef_entry = mef_entry;
  2934. mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
  2935. if (wowlan->n_patterns || wowlan->magic_pkt) {
  2936. ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
  2937. &mef_entry[1], wowlan);
  2938. if (ret)
  2939. goto err;
  2940. }
  2941. if (!mef_cfg.criteria)
  2942. mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
  2943. MWIFIEX_CRITERIA_UNICAST |
  2944. MWIFIEX_CRITERIA_MULTICAST;
  2945. ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
  2946. HostCmd_ACT_GEN_SET, 0,
  2947. &mef_cfg, true);
  2948. err:
  2949. kfree(mef_entry);
  2950. return ret;
  2951. }
  2952. static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
  2953. struct cfg80211_wowlan *wowlan)
  2954. {
  2955. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  2956. struct mwifiex_ds_hs_cfg hs_cfg;
  2957. int i, ret = 0, retry_num = 10;
  2958. struct mwifiex_private *priv;
  2959. struct mwifiex_private *sta_priv =
  2960. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
  2961. sta_priv->scan_aborting = true;
  2962. for (i = 0; i < adapter->priv_num; i++) {
  2963. priv = adapter->priv[i];
  2964. mwifiex_abort_cac(priv);
  2965. }
  2966. mwifiex_cancel_all_pending_cmd(adapter);
  2967. for (i = 0; i < adapter->priv_num; i++) {
  2968. priv = adapter->priv[i];
  2969. if (priv && priv->netdev)
  2970. netif_device_detach(priv->netdev);
  2971. }
  2972. for (i = 0; i < retry_num; i++) {
  2973. if (!mwifiex_wmm_lists_empty(adapter) ||
  2974. !mwifiex_bypass_txlist_empty(adapter) ||
  2975. !skb_queue_empty(&adapter->tx_data_q))
  2976. usleep_range(10000, 15000);
  2977. else
  2978. break;
  2979. }
  2980. if (!wowlan) {
  2981. mwifiex_dbg(adapter, INFO,
  2982. "None of the WOWLAN triggers enabled\n");
  2983. ret = 0;
  2984. goto done;
  2985. }
  2986. if (!sta_priv->media_connected && !wowlan->nd_config) {
  2987. mwifiex_dbg(adapter, ERROR,
  2988. "Can not configure WOWLAN in disconnected state\n");
  2989. ret = 0;
  2990. goto done;
  2991. }
  2992. ret = mwifiex_set_mef_filter(sta_priv, wowlan);
  2993. if (ret) {
  2994. mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
  2995. goto done;
  2996. }
  2997. memset(&hs_cfg, 0, sizeof(hs_cfg));
  2998. hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  2999. if (wowlan->nd_config) {
  3000. mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
  3001. hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
  3002. mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
  3003. wowlan->nd_config);
  3004. }
  3005. if (wowlan->disconnect) {
  3006. hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
  3007. mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
  3008. }
  3009. hs_cfg.is_invoke_hostcmd = false;
  3010. hs_cfg.gpio = adapter->hs_cfg.gpio;
  3011. hs_cfg.gap = adapter->hs_cfg.gap;
  3012. ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
  3013. MWIFIEX_SYNC_CMD, &hs_cfg);
  3014. if (ret)
  3015. mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
  3016. done:
  3017. sta_priv->scan_aborting = false;
  3018. return ret;
  3019. }
  3020. static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
  3021. {
  3022. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  3023. struct mwifiex_private *priv;
  3024. struct mwifiex_ds_wakeup_reason wakeup_reason;
  3025. struct cfg80211_wowlan_wakeup wakeup_report;
  3026. int i;
  3027. bool report_wakeup_reason = true;
  3028. for (i = 0; i < adapter->priv_num; i++) {
  3029. priv = adapter->priv[i];
  3030. if (priv && priv->netdev)
  3031. netif_device_attach(priv->netdev);
  3032. }
  3033. if (!wiphy->wowlan_config)
  3034. goto done;
  3035. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
  3036. mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
  3037. &wakeup_reason);
  3038. memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
  3039. wakeup_report.pattern_idx = -1;
  3040. switch (wakeup_reason.hs_wakeup_reason) {
  3041. case NO_HSWAKEUP_REASON:
  3042. break;
  3043. case BCAST_DATA_MATCHED:
  3044. break;
  3045. case MCAST_DATA_MATCHED:
  3046. break;
  3047. case UCAST_DATA_MATCHED:
  3048. break;
  3049. case MASKTABLE_EVENT_MATCHED:
  3050. break;
  3051. case NON_MASKABLE_EVENT_MATCHED:
  3052. if (wiphy->wowlan_config->disconnect)
  3053. wakeup_report.disconnect = true;
  3054. if (wiphy->wowlan_config->nd_config)
  3055. wakeup_report.net_detect = adapter->nd_info;
  3056. break;
  3057. case NON_MASKABLE_CONDITION_MATCHED:
  3058. break;
  3059. case MAGIC_PATTERN_MATCHED:
  3060. if (wiphy->wowlan_config->magic_pkt)
  3061. wakeup_report.magic_pkt = true;
  3062. if (wiphy->wowlan_config->n_patterns)
  3063. wakeup_report.pattern_idx = 1;
  3064. break;
  3065. case GTK_REKEY_FAILURE:
  3066. if (wiphy->wowlan_config->gtk_rekey_failure)
  3067. wakeup_report.gtk_rekey_failure = true;
  3068. break;
  3069. default:
  3070. report_wakeup_reason = false;
  3071. break;
  3072. }
  3073. if (report_wakeup_reason)
  3074. cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
  3075. GFP_KERNEL);
  3076. done:
  3077. if (adapter->nd_info) {
  3078. for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
  3079. kfree(adapter->nd_info->matches[i]);
  3080. kfree(adapter->nd_info);
  3081. adapter->nd_info = NULL;
  3082. }
  3083. return 0;
  3084. }
  3085. static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
  3086. bool enabled)
  3087. {
  3088. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  3089. device_set_wakeup_enable(adapter->dev, enabled);
  3090. }
  3091. static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
  3092. struct cfg80211_gtk_rekey_data *data)
  3093. {
  3094. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3095. if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
  3096. return -EOPNOTSUPP;
  3097. return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
  3098. HostCmd_ACT_GEN_SET, 0, data, true);
  3099. }
  3100. #endif
  3101. static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
  3102. {
  3103. static const u8 ipv4_mc_mac[] = {0x33, 0x33};
  3104. static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
  3105. static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
  3106. if ((byte_seq[0] & 0x01) &&
  3107. (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
  3108. return PACKET_TYPE_UNICAST;
  3109. else if (!memcmp(byte_seq, bc_mac, 4))
  3110. return PACKET_TYPE_BROADCAST;
  3111. else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
  3112. byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
  3113. (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
  3114. byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
  3115. return PACKET_TYPE_MULTICAST;
  3116. return 0;
  3117. }
  3118. static int
  3119. mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
  3120. struct cfg80211_coalesce_rules *crule,
  3121. struct mwifiex_coalesce_rule *mrule)
  3122. {
  3123. u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
  3124. struct filt_field_param *param;
  3125. int i;
  3126. mrule->max_coalescing_delay = crule->delay;
  3127. param = mrule->params;
  3128. for (i = 0; i < crule->n_patterns; i++) {
  3129. memset(byte_seq, 0, sizeof(byte_seq));
  3130. if (!mwifiex_is_pattern_supported(&crule->patterns[i],
  3131. byte_seq,
  3132. MWIFIEX_COALESCE_MAX_BYTESEQ)) {
  3133. mwifiex_dbg(priv->adapter, ERROR,
  3134. "Pattern not supported\n");
  3135. return -EOPNOTSUPP;
  3136. }
  3137. if (!crule->patterns[i].pkt_offset) {
  3138. u8 pkt_type;
  3139. pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
  3140. if (pkt_type && mrule->pkt_type) {
  3141. mwifiex_dbg(priv->adapter, ERROR,
  3142. "Multiple packet types not allowed\n");
  3143. return -EOPNOTSUPP;
  3144. } else if (pkt_type) {
  3145. mrule->pkt_type = pkt_type;
  3146. continue;
  3147. }
  3148. }
  3149. if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
  3150. param->operation = RECV_FILTER_MATCH_TYPE_EQ;
  3151. else
  3152. param->operation = RECV_FILTER_MATCH_TYPE_NE;
  3153. param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
  3154. memcpy(param->operand_byte_stream, byte_seq,
  3155. param->operand_len);
  3156. param->offset = crule->patterns[i].pkt_offset;
  3157. param++;
  3158. mrule->num_of_fields++;
  3159. }
  3160. if (!mrule->pkt_type) {
  3161. mwifiex_dbg(priv->adapter, ERROR,
  3162. "Packet type can not be determined\n");
  3163. return -EOPNOTSUPP;
  3164. }
  3165. return 0;
  3166. }
  3167. static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
  3168. struct cfg80211_coalesce *coalesce)
  3169. {
  3170. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  3171. int i, ret;
  3172. struct mwifiex_ds_coalesce_cfg coalesce_cfg;
  3173. struct mwifiex_private *priv =
  3174. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
  3175. memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
  3176. if (!coalesce) {
  3177. mwifiex_dbg(adapter, WARN,
  3178. "Disable coalesce and reset all previous rules\n");
  3179. return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
  3180. HostCmd_ACT_GEN_SET, 0,
  3181. &coalesce_cfg, true);
  3182. }
  3183. coalesce_cfg.num_of_rules = coalesce->n_rules;
  3184. for (i = 0; i < coalesce->n_rules; i++) {
  3185. ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
  3186. &coalesce_cfg.rule[i]);
  3187. if (ret) {
  3188. mwifiex_dbg(adapter, ERROR,
  3189. "Recheck the patterns provided for rule %d\n",
  3190. i + 1);
  3191. return ret;
  3192. }
  3193. }
  3194. return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
  3195. HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
  3196. }
  3197. /* cfg80211 ops handler for tdls_mgmt.
  3198. * Function prepares TDLS action frame packets and forwards them to FW
  3199. */
  3200. static int
  3201. mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  3202. const u8 *peer, u8 action_code, u8 dialog_token,
  3203. u16 status_code, u32 peer_capability,
  3204. bool initiator, const u8 *extra_ies,
  3205. size_t extra_ies_len)
  3206. {
  3207. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3208. int ret;
  3209. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  3210. return -EOPNOTSUPP;
  3211. /* make sure we are in station mode and connected */
  3212. if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
  3213. return -EOPNOTSUPP;
  3214. switch (action_code) {
  3215. case WLAN_TDLS_SETUP_REQUEST:
  3216. mwifiex_dbg(priv->adapter, MSG,
  3217. "Send TDLS Setup Request to %pM status_code=%d\n",
  3218. peer, status_code);
  3219. mwifiex_add_auto_tdls_peer(priv, peer);
  3220. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3221. dialog_token, status_code,
  3222. extra_ies, extra_ies_len);
  3223. break;
  3224. case WLAN_TDLS_SETUP_RESPONSE:
  3225. mwifiex_add_auto_tdls_peer(priv, peer);
  3226. mwifiex_dbg(priv->adapter, MSG,
  3227. "Send TDLS Setup Response to %pM status_code=%d\n",
  3228. peer, status_code);
  3229. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3230. dialog_token, status_code,
  3231. extra_ies, extra_ies_len);
  3232. break;
  3233. case WLAN_TDLS_SETUP_CONFIRM:
  3234. mwifiex_dbg(priv->adapter, MSG,
  3235. "Send TDLS Confirm to %pM status_code=%d\n", peer,
  3236. status_code);
  3237. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3238. dialog_token, status_code,
  3239. extra_ies, extra_ies_len);
  3240. break;
  3241. case WLAN_TDLS_TEARDOWN:
  3242. mwifiex_dbg(priv->adapter, MSG,
  3243. "Send TDLS Tear down to %pM\n", peer);
  3244. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3245. dialog_token, status_code,
  3246. extra_ies, extra_ies_len);
  3247. break;
  3248. case WLAN_TDLS_DISCOVERY_REQUEST:
  3249. mwifiex_dbg(priv->adapter, MSG,
  3250. "Send TDLS Discovery Request to %pM\n", peer);
  3251. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3252. dialog_token, status_code,
  3253. extra_ies, extra_ies_len);
  3254. break;
  3255. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  3256. mwifiex_dbg(priv->adapter, MSG,
  3257. "Send TDLS Discovery Response to %pM\n", peer);
  3258. ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
  3259. dialog_token, status_code,
  3260. extra_ies, extra_ies_len);
  3261. break;
  3262. default:
  3263. mwifiex_dbg(priv->adapter, ERROR,
  3264. "Unknown TDLS mgmt/action frame %pM\n", peer);
  3265. ret = -EINVAL;
  3266. break;
  3267. }
  3268. return ret;
  3269. }
  3270. static int
  3271. mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  3272. const u8 *peer, enum nl80211_tdls_operation action)
  3273. {
  3274. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3275. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  3276. !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
  3277. return -EOPNOTSUPP;
  3278. /* make sure we are in station mode and connected */
  3279. if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
  3280. return -EOPNOTSUPP;
  3281. mwifiex_dbg(priv->adapter, MSG,
  3282. "TDLS peer=%pM, oper=%d\n", peer, action);
  3283. switch (action) {
  3284. case NL80211_TDLS_ENABLE_LINK:
  3285. action = MWIFIEX_TDLS_ENABLE_LINK;
  3286. break;
  3287. case NL80211_TDLS_DISABLE_LINK:
  3288. action = MWIFIEX_TDLS_DISABLE_LINK;
  3289. break;
  3290. case NL80211_TDLS_TEARDOWN:
  3291. /* shouldn't happen!*/
  3292. mwifiex_dbg(priv->adapter, ERROR,
  3293. "tdls_oper: teardown from driver not supported\n");
  3294. return -EINVAL;
  3295. case NL80211_TDLS_SETUP:
  3296. /* shouldn't happen!*/
  3297. mwifiex_dbg(priv->adapter, ERROR,
  3298. "tdls_oper: setup from driver not supported\n");
  3299. return -EINVAL;
  3300. case NL80211_TDLS_DISCOVERY_REQ:
  3301. /* shouldn't happen!*/
  3302. mwifiex_dbg(priv->adapter, ERROR,
  3303. "tdls_oper: discovery from driver not supported\n");
  3304. return -EINVAL;
  3305. default:
  3306. mwifiex_dbg(priv->adapter, ERROR,
  3307. "tdls_oper: operation not supported\n");
  3308. return -EOPNOTSUPP;
  3309. }
  3310. return mwifiex_tdls_oper(priv, peer, action);
  3311. }
  3312. static int
  3313. mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
  3314. const u8 *addr, u8 oper_class,
  3315. struct cfg80211_chan_def *chandef)
  3316. {
  3317. struct mwifiex_sta_node *sta_ptr;
  3318. u16 chan;
  3319. u8 second_chan_offset, band;
  3320. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3321. spin_lock_bh(&priv->sta_list_spinlock);
  3322. sta_ptr = mwifiex_get_sta_entry(priv, addr);
  3323. if (!sta_ptr) {
  3324. spin_unlock_bh(&priv->sta_list_spinlock);
  3325. wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
  3326. __func__, addr);
  3327. return -ENOENT;
  3328. }
  3329. if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
  3330. WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
  3331. spin_unlock_bh(&priv->sta_list_spinlock);
  3332. wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
  3333. return -ENOENT;
  3334. }
  3335. if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
  3336. sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
  3337. spin_unlock_bh(&priv->sta_list_spinlock);
  3338. wiphy_err(wiphy, "channel switch is running, abort request\n");
  3339. return -EALREADY;
  3340. }
  3341. spin_unlock_bh(&priv->sta_list_spinlock);
  3342. chan = chandef->chan->hw_value;
  3343. second_chan_offset = mwifiex_get_sec_chan_offset(chan);
  3344. band = chandef->chan->band;
  3345. mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
  3346. return 0;
  3347. }
  3348. static void
  3349. mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
  3350. struct net_device *dev,
  3351. const u8 *addr)
  3352. {
  3353. struct mwifiex_sta_node *sta_ptr;
  3354. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3355. spin_lock_bh(&priv->sta_list_spinlock);
  3356. sta_ptr = mwifiex_get_sta_entry(priv, addr);
  3357. if (!sta_ptr) {
  3358. spin_unlock_bh(&priv->sta_list_spinlock);
  3359. wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
  3360. __func__, addr);
  3361. } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
  3362. sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
  3363. sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
  3364. spin_unlock_bh(&priv->sta_list_spinlock);
  3365. wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
  3366. addr);
  3367. } else {
  3368. spin_unlock_bh(&priv->sta_list_spinlock);
  3369. mwifiex_stop_tdls_cs(priv, addr);
  3370. }
  3371. }
  3372. static int
  3373. mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  3374. const u8 *mac, struct station_parameters *params)
  3375. {
  3376. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3377. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3378. return -EOPNOTSUPP;
  3379. /* make sure we are in station mode and connected */
  3380. if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
  3381. return -EOPNOTSUPP;
  3382. return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
  3383. }
  3384. static int
  3385. mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  3386. struct cfg80211_csa_settings *params)
  3387. {
  3388. struct ieee_types_header *chsw_ie;
  3389. struct ieee80211_channel_sw_ie *channel_sw;
  3390. int chsw_msec;
  3391. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3392. if (priv->adapter->scan_processing) {
  3393. mwifiex_dbg(priv->adapter, ERROR,
  3394. "radar detection: scan in process...\n");
  3395. return -EBUSY;
  3396. }
  3397. if (priv->wdev.cac_started)
  3398. return -EBUSY;
  3399. if (cfg80211_chandef_identical(&params->chandef,
  3400. &priv->dfs_chandef))
  3401. return -EINVAL;
  3402. chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
  3403. params->beacon_csa.tail,
  3404. params->beacon_csa.tail_len);
  3405. if (!chsw_ie) {
  3406. mwifiex_dbg(priv->adapter, ERROR,
  3407. "Could not parse channel switch announcement IE\n");
  3408. return -EINVAL;
  3409. }
  3410. channel_sw = (void *)(chsw_ie + 1);
  3411. if (channel_sw->mode) {
  3412. if (netif_carrier_ok(priv->netdev))
  3413. netif_carrier_off(priv->netdev);
  3414. mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
  3415. }
  3416. if (mwifiex_del_mgmt_ies(priv))
  3417. mwifiex_dbg(priv->adapter, ERROR,
  3418. "Failed to delete mgmt IEs!\n");
  3419. if (mwifiex_set_mgmt_ies(priv, &params->beacon_csa)) {
  3420. mwifiex_dbg(priv->adapter, ERROR,
  3421. "%s: setting mgmt ies failed\n", __func__);
  3422. return -EFAULT;
  3423. }
  3424. memcpy(&priv->dfs_chandef, &params->chandef, sizeof(priv->dfs_chandef));
  3425. memcpy(&priv->beacon_after, &params->beacon_after,
  3426. sizeof(priv->beacon_after));
  3427. chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
  3428. queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
  3429. msecs_to_jiffies(chsw_msec));
  3430. return 0;
  3431. }
  3432. static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
  3433. struct wireless_dev *wdev,
  3434. unsigned int link_id,
  3435. struct cfg80211_chan_def *chandef)
  3436. {
  3437. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  3438. struct mwifiex_bssdescriptor *curr_bss;
  3439. struct ieee80211_channel *chan;
  3440. enum nl80211_channel_type chan_type;
  3441. enum nl80211_band band;
  3442. int freq;
  3443. int ret = -ENODATA;
  3444. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
  3445. cfg80211_chandef_valid(&priv->bss_chandef)) {
  3446. *chandef = priv->bss_chandef;
  3447. ret = 0;
  3448. } else if (priv->media_connected) {
  3449. curr_bss = &priv->curr_bss_params.bss_descriptor;
  3450. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  3451. freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
  3452. chan = ieee80211_get_channel(wiphy, freq);
  3453. if (priv->ht_param_present) {
  3454. chan_type = mwifiex_get_chan_type(priv);
  3455. cfg80211_chandef_create(chandef, chan, chan_type);
  3456. } else {
  3457. cfg80211_chandef_create(chandef, chan,
  3458. NL80211_CHAN_NO_HT);
  3459. }
  3460. ret = 0;
  3461. }
  3462. return ret;
  3463. }
  3464. #ifdef CONFIG_NL80211_TESTMODE
  3465. enum mwifiex_tm_attr {
  3466. __MWIFIEX_TM_ATTR_INVALID = 0,
  3467. MWIFIEX_TM_ATTR_CMD = 1,
  3468. MWIFIEX_TM_ATTR_DATA = 2,
  3469. /* keep last */
  3470. __MWIFIEX_TM_ATTR_AFTER_LAST,
  3471. MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
  3472. };
  3473. static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
  3474. [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
  3475. [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
  3476. .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
  3477. };
  3478. enum mwifiex_tm_command {
  3479. MWIFIEX_TM_CMD_HOSTCMD = 0,
  3480. };
  3481. static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
  3482. void *data, int len)
  3483. {
  3484. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  3485. struct mwifiex_ds_misc_cmd *hostcmd;
  3486. struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
  3487. struct sk_buff *skb;
  3488. int err;
  3489. if (!priv)
  3490. return -EINVAL;
  3491. err = nla_parse_deprecated(tb, MWIFIEX_TM_ATTR_MAX, data, len,
  3492. mwifiex_tm_policy, NULL);
  3493. if (err)
  3494. return err;
  3495. if (!tb[MWIFIEX_TM_ATTR_CMD])
  3496. return -EINVAL;
  3497. switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
  3498. case MWIFIEX_TM_CMD_HOSTCMD:
  3499. if (!tb[MWIFIEX_TM_ATTR_DATA])
  3500. return -EINVAL;
  3501. hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
  3502. if (!hostcmd)
  3503. return -ENOMEM;
  3504. hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
  3505. memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
  3506. hostcmd->len);
  3507. if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
  3508. dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
  3509. kfree(hostcmd);
  3510. return -EFAULT;
  3511. }
  3512. /* process hostcmd response*/
  3513. skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
  3514. if (!skb) {
  3515. kfree(hostcmd);
  3516. return -ENOMEM;
  3517. }
  3518. err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
  3519. hostcmd->len, hostcmd->cmd);
  3520. if (err) {
  3521. kfree(hostcmd);
  3522. kfree_skb(skb);
  3523. return -EMSGSIZE;
  3524. }
  3525. err = cfg80211_testmode_reply(skb);
  3526. kfree(hostcmd);
  3527. return err;
  3528. default:
  3529. return -EOPNOTSUPP;
  3530. }
  3531. }
  3532. #endif
  3533. static int
  3534. mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
  3535. struct net_device *dev,
  3536. struct cfg80211_chan_def *chandef,
  3537. u32 cac_time_ms)
  3538. {
  3539. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3540. struct mwifiex_radar_params radar_params;
  3541. if (priv->adapter->scan_processing) {
  3542. mwifiex_dbg(priv->adapter, ERROR,
  3543. "radar detection: scan already in process...\n");
  3544. return -EBUSY;
  3545. }
  3546. if (!mwifiex_is_11h_active(priv)) {
  3547. mwifiex_dbg(priv->adapter, INFO,
  3548. "Enable 11h extensions in FW\n");
  3549. if (mwifiex_11h_activate(priv, true)) {
  3550. mwifiex_dbg(priv->adapter, ERROR,
  3551. "Failed to activate 11h extensions!!");
  3552. return -1;
  3553. }
  3554. priv->state_11h.is_11h_active = true;
  3555. }
  3556. memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
  3557. radar_params.chandef = chandef;
  3558. radar_params.cac_time_ms = cac_time_ms;
  3559. memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
  3560. if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
  3561. HostCmd_ACT_GEN_SET, 0, &radar_params, true))
  3562. return -1;
  3563. queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
  3564. msecs_to_jiffies(cac_time_ms));
  3565. return 0;
  3566. }
  3567. static int
  3568. mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
  3569. const u8 *mac,
  3570. struct station_parameters *params)
  3571. {
  3572. int ret;
  3573. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3574. /* we support change_station handler only for TDLS peers*/
  3575. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3576. return -EOPNOTSUPP;
  3577. /* make sure we are in station mode and connected */
  3578. if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
  3579. return -EOPNOTSUPP;
  3580. priv->sta_params = params;
  3581. ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
  3582. priv->sta_params = NULL;
  3583. return ret;
  3584. }
  3585. /* station cfg80211 operations */
  3586. static struct cfg80211_ops mwifiex_cfg80211_ops = {
  3587. .add_virtual_intf = mwifiex_add_virtual_intf,
  3588. .del_virtual_intf = mwifiex_del_virtual_intf,
  3589. .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
  3590. .scan = mwifiex_cfg80211_scan,
  3591. .connect = mwifiex_cfg80211_connect,
  3592. .disconnect = mwifiex_cfg80211_disconnect,
  3593. .get_station = mwifiex_cfg80211_get_station,
  3594. .dump_station = mwifiex_cfg80211_dump_station,
  3595. .dump_survey = mwifiex_cfg80211_dump_survey,
  3596. .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
  3597. .join_ibss = mwifiex_cfg80211_join_ibss,
  3598. .leave_ibss = mwifiex_cfg80211_leave_ibss,
  3599. .add_key = mwifiex_cfg80211_add_key,
  3600. .del_key = mwifiex_cfg80211_del_key,
  3601. .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
  3602. .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
  3603. .update_mgmt_frame_registrations =
  3604. mwifiex_cfg80211_update_mgmt_frame_registrations,
  3605. .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
  3606. .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
  3607. .set_default_key = mwifiex_cfg80211_set_default_key,
  3608. .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
  3609. .set_tx_power = mwifiex_cfg80211_set_tx_power,
  3610. .get_tx_power = mwifiex_cfg80211_get_tx_power,
  3611. .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
  3612. .start_ap = mwifiex_cfg80211_start_ap,
  3613. .stop_ap = mwifiex_cfg80211_stop_ap,
  3614. .change_beacon = mwifiex_cfg80211_change_beacon,
  3615. .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
  3616. .set_antenna = mwifiex_cfg80211_set_antenna,
  3617. .get_antenna = mwifiex_cfg80211_get_antenna,
  3618. .del_station = mwifiex_cfg80211_del_station,
  3619. .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
  3620. .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
  3621. #ifdef CONFIG_PM
  3622. .suspend = mwifiex_cfg80211_suspend,
  3623. .resume = mwifiex_cfg80211_resume,
  3624. .set_wakeup = mwifiex_cfg80211_set_wakeup,
  3625. .set_rekey_data = mwifiex_set_rekey_data,
  3626. #endif
  3627. .set_coalesce = mwifiex_cfg80211_set_coalesce,
  3628. .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
  3629. .tdls_oper = mwifiex_cfg80211_tdls_oper,
  3630. .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
  3631. .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
  3632. .add_station = mwifiex_cfg80211_add_station,
  3633. .change_station = mwifiex_cfg80211_change_station,
  3634. CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
  3635. .get_channel = mwifiex_cfg80211_get_channel,
  3636. .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
  3637. .channel_switch = mwifiex_cfg80211_channel_switch,
  3638. };
  3639. #ifdef CONFIG_PM
  3640. static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
  3641. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
  3642. WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  3643. WIPHY_WOWLAN_GTK_REKEY_FAILURE,
  3644. .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
  3645. .pattern_min_len = 1,
  3646. .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
  3647. .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
  3648. .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
  3649. };
  3650. static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = {
  3651. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
  3652. WIPHY_WOWLAN_NET_DETECT,
  3653. .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
  3654. .pattern_min_len = 1,
  3655. .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
  3656. .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
  3657. .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
  3658. };
  3659. #endif
  3660. static bool mwifiex_is_valid_alpha2(const char *alpha2)
  3661. {
  3662. if (!alpha2 || strlen(alpha2) != 2)
  3663. return false;
  3664. if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
  3665. return true;
  3666. return false;
  3667. }
  3668. static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
  3669. .n_rules = MWIFIEX_COALESCE_MAX_RULES,
  3670. .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
  3671. .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
  3672. .pattern_min_len = 1,
  3673. .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
  3674. .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
  3675. };
  3676. int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
  3677. {
  3678. u32 n_channels_bg, n_channels_a = 0;
  3679. n_channels_bg = mwifiex_band_2ghz.n_channels;
  3680. if (adapter->config_bands & BAND_A)
  3681. n_channels_a = mwifiex_band_5ghz.n_channels;
  3682. /* allocate twice the number total channels, since the driver issues an
  3683. * additional active scan request for hidden SSIDs on passive channels.
  3684. */
  3685. adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
  3686. adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
  3687. adapter->num_in_chan_stats));
  3688. if (!adapter->chan_stats)
  3689. return -ENOMEM;
  3690. return 0;
  3691. }
  3692. /*
  3693. * This function registers the device with CFG802.11 subsystem.
  3694. *
  3695. * The function creates the wireless device/wiphy, populates it with
  3696. * default parameters and handler function pointers, and finally
  3697. * registers the device.
  3698. */
  3699. int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
  3700. {
  3701. int ret;
  3702. void *wdev_priv;
  3703. struct wiphy *wiphy;
  3704. struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
  3705. u8 *country_code;
  3706. u32 thr, retry;
  3707. /* create a new wiphy for use with cfg80211 */
  3708. wiphy = wiphy_new(&mwifiex_cfg80211_ops,
  3709. sizeof(struct mwifiex_adapter *));
  3710. if (!wiphy) {
  3711. mwifiex_dbg(adapter, ERROR,
  3712. "%s: creating new wiphy\n", __func__);
  3713. return -ENOMEM;
  3714. }
  3715. wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
  3716. wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
  3717. wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
  3718. wiphy->max_remain_on_channel_duration = 5000;
  3719. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  3720. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  3721. BIT(NL80211_IFTYPE_P2P_GO) |
  3722. BIT(NL80211_IFTYPE_AP);
  3723. if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
  3724. wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  3725. wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
  3726. if (adapter->config_bands & BAND_A)
  3727. wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
  3728. else
  3729. wiphy->bands[NL80211_BAND_5GHZ] = NULL;
  3730. if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
  3731. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
  3732. else if (adapter->is_hw_11ac_capable)
  3733. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
  3734. else
  3735. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
  3736. wiphy->n_iface_combinations = 1;
  3737. if (adapter->max_sta_conn > adapter->max_p2p_conn)
  3738. wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
  3739. else
  3740. wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
  3741. /* Initialize cipher suits */
  3742. wiphy->cipher_suites = mwifiex_cipher_suites;
  3743. wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
  3744. if (adapter->regd) {
  3745. wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
  3746. REGULATORY_DISABLE_BEACON_HINTS |
  3747. REGULATORY_COUNTRY_IE_IGNORE;
  3748. wiphy_apply_custom_regulatory(wiphy, adapter->regd);
  3749. }
  3750. ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
  3751. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  3752. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  3753. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  3754. WIPHY_FLAG_AP_UAPSD |
  3755. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  3756. WIPHY_FLAG_HAS_CHANNEL_SWITCH |
  3757. WIPHY_FLAG_PS_ON_BY_DEFAULT;
  3758. if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
  3759. wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
  3760. WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  3761. #ifdef CONFIG_PM
  3762. if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
  3763. wiphy->wowlan = &mwifiex_wowlan_support;
  3764. else
  3765. wiphy->wowlan = &mwifiex_wowlan_support_no_gtk;
  3766. #endif
  3767. wiphy->coalesce = &mwifiex_coalesce_support;
  3768. wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  3769. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  3770. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  3771. wiphy->max_sched_scan_reqs = 1;
  3772. wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
  3773. wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
  3774. wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
  3775. wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
  3776. wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
  3777. wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER |
  3778. NL80211_FEATURE_LOW_PRIORITY_SCAN |
  3779. NL80211_FEATURE_NEED_OBSS_SCAN;
  3780. if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
  3781. wiphy->features |= NL80211_FEATURE_HT_IBSS;
  3782. if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
  3783. wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
  3784. NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
  3785. NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  3786. if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
  3787. wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
  3788. if (adapter->fw_api_ver == MWIFIEX_FW_V15)
  3789. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  3790. /* Reserve space for mwifiex specific private data for BSS */
  3791. wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
  3792. wiphy->reg_notifier = mwifiex_reg_notifier;
  3793. /* Set struct mwifiex_adapter pointer in wiphy_priv */
  3794. wdev_priv = wiphy_priv(wiphy);
  3795. *(unsigned long *)wdev_priv = (unsigned long)adapter;
  3796. set_wiphy_dev(wiphy, priv->adapter->dev);
  3797. ret = wiphy_register(wiphy);
  3798. if (ret < 0) {
  3799. mwifiex_dbg(adapter, ERROR,
  3800. "%s: wiphy_register failed: %d\n", __func__, ret);
  3801. wiphy_free(wiphy);
  3802. return ret;
  3803. }
  3804. if (!adapter->regd) {
  3805. if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
  3806. mwifiex_dbg(adapter, INFO,
  3807. "driver hint alpha2: %2.2s\n", reg_alpha2);
  3808. regulatory_hint(wiphy, reg_alpha2);
  3809. } else {
  3810. if (adapter->region_code == 0x00) {
  3811. mwifiex_dbg(adapter, WARN,
  3812. "Ignore world regulatory domain\n");
  3813. } else {
  3814. wiphy->regulatory_flags |=
  3815. REGULATORY_DISABLE_BEACON_HINTS |
  3816. REGULATORY_COUNTRY_IE_IGNORE;
  3817. country_code =
  3818. mwifiex_11d_code_2_region(
  3819. adapter->region_code);
  3820. if (country_code &&
  3821. regulatory_hint(wiphy, country_code))
  3822. mwifiex_dbg(priv->adapter, ERROR,
  3823. "regulatory_hint() failed\n");
  3824. }
  3825. }
  3826. }
  3827. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3828. HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
  3829. wiphy->frag_threshold = thr;
  3830. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3831. HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
  3832. wiphy->rts_threshold = thr;
  3833. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3834. HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
  3835. wiphy->retry_short = (u8) retry;
  3836. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3837. HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
  3838. wiphy->retry_long = (u8) retry;
  3839. adapter->wiphy = wiphy;
  3840. return ret;
  3841. }