cfg80211.c 105 KB

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