cfg80211.c 72 KB

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