cfg80211.c 122 KB

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