cfg80211.c 108 KB

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