cfg80211.c 85 KB

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