cfg80211.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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 const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
  22. {
  23. .max = 1, .types = BIT(NL80211_IFTYPE_STATION),
  24. },
  25. {
  26. .max = 1, .types = BIT(NL80211_IFTYPE_AP),
  27. },
  28. };
  29. static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
  30. .limits = mwifiex_ap_sta_limits,
  31. .num_different_channels = 1,
  32. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  33. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  34. .beacon_int_infra_match = true,
  35. };
  36. static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
  37. .n_reg_rules = 7,
  38. .alpha2 = "99",
  39. .reg_rules = {
  40. /* Channel 1 - 11 */
  41. REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
  42. /* Channel 12 - 13 */
  43. REG_RULE(2467-10, 2472+10, 20, 3, 20,
  44. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
  45. /* Channel 14 */
  46. REG_RULE(2484-10, 2484+10, 20, 3, 20,
  47. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
  48. NL80211_RRF_NO_OFDM),
  49. /* Channel 36 - 48 */
  50. REG_RULE(5180-10, 5240+10, 40, 3, 20,
  51. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
  52. /* Channel 149 - 165 */
  53. REG_RULE(5745-10, 5825+10, 40, 3, 20,
  54. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
  55. /* Channel 52 - 64 */
  56. REG_RULE(5260-10, 5320+10, 40, 3, 30,
  57. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
  58. NL80211_RRF_DFS),
  59. /* Channel 100 - 140 */
  60. REG_RULE(5500-10, 5700+10, 40, 3, 30,
  61. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
  62. NL80211_RRF_DFS),
  63. }
  64. };
  65. /*
  66. * This function maps the nl802.11 channel type into driver channel type.
  67. *
  68. * The mapping is as follows -
  69. * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  70. * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  71. * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
  72. * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
  73. * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  74. */
  75. static u8
  76. mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
  77. {
  78. switch (chan_type) {
  79. case NL80211_CHAN_NO_HT:
  80. case NL80211_CHAN_HT20:
  81. return IEEE80211_HT_PARAM_CHA_SEC_NONE;
  82. case NL80211_CHAN_HT40PLUS:
  83. return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  84. case NL80211_CHAN_HT40MINUS:
  85. return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  86. default:
  87. return IEEE80211_HT_PARAM_CHA_SEC_NONE;
  88. }
  89. }
  90. /*
  91. * This function checks whether WEP is set.
  92. */
  93. static int
  94. mwifiex_is_alg_wep(u32 cipher)
  95. {
  96. switch (cipher) {
  97. case WLAN_CIPHER_SUITE_WEP40:
  98. case WLAN_CIPHER_SUITE_WEP104:
  99. return 1;
  100. default:
  101. break;
  102. }
  103. return 0;
  104. }
  105. /*
  106. * This function retrieves the private structure from kernel wiphy structure.
  107. */
  108. static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
  109. {
  110. return (void *) (*(unsigned long *) wiphy_priv(wiphy));
  111. }
  112. /*
  113. * CFG802.11 operation handler to delete a network key.
  114. */
  115. static int
  116. mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
  117. u8 key_index, bool pairwise, const u8 *mac_addr)
  118. {
  119. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  120. const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  121. const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
  122. if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
  123. wiphy_err(wiphy, "deleting the crypto keys\n");
  124. return -EFAULT;
  125. }
  126. wiphy_dbg(wiphy, "info: crypto keys deleted\n");
  127. return 0;
  128. }
  129. /*
  130. * This function forms an skb for management frame.
  131. */
  132. static int
  133. mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
  134. {
  135. u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  136. u16 pkt_len;
  137. u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
  138. struct timeval tv;
  139. pkt_len = len + ETH_ALEN;
  140. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
  141. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  142. memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
  143. memcpy(skb_push(skb, sizeof(tx_control)),
  144. &tx_control, sizeof(tx_control));
  145. memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
  146. /* Add packet data and address4 */
  147. memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
  148. sizeof(struct ieee80211_hdr_3addr));
  149. memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
  150. memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
  151. buf + sizeof(struct ieee80211_hdr_3addr),
  152. len - sizeof(struct ieee80211_hdr_3addr));
  153. skb->priority = LOW_PRIO_TID;
  154. do_gettimeofday(&tv);
  155. skb->tstamp = timeval_to_ktime(tv);
  156. return 0;
  157. }
  158. /*
  159. * CFG802.11 operation handler to transmit a management frame.
  160. */
  161. static int
  162. mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  163. struct ieee80211_channel *chan, bool offchan,
  164. enum nl80211_channel_type channel_type,
  165. bool channel_type_valid, unsigned int wait,
  166. const u8 *buf, size_t len, bool no_cck,
  167. bool dont_wait_for_ack, u64 *cookie)
  168. {
  169. struct sk_buff *skb;
  170. u16 pkt_len;
  171. const struct ieee80211_mgmt *mgmt;
  172. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  173. if (!buf || !len) {
  174. wiphy_err(wiphy, "invalid buffer and length\n");
  175. return -EFAULT;
  176. }
  177. mgmt = (const struct ieee80211_mgmt *)buf;
  178. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
  179. ieee80211_is_probe_resp(mgmt->frame_control)) {
  180. /* Since we support offload probe resp, we need to skip probe
  181. * resp in AP or GO mode */
  182. wiphy_dbg(wiphy,
  183. "info: skip to send probe resp in AP or GO mode\n");
  184. return 0;
  185. }
  186. pkt_len = len + ETH_ALEN;
  187. skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
  188. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  189. pkt_len + sizeof(pkt_len));
  190. if (!skb) {
  191. wiphy_err(wiphy, "allocate skb failed for management frame\n");
  192. return -ENOMEM;
  193. }
  194. mwifiex_form_mgmt_frame(skb, buf, len);
  195. mwifiex_queue_tx_pkt(priv, skb);
  196. *cookie = random32() | 1;
  197. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, GFP_ATOMIC);
  198. wiphy_dbg(wiphy, "info: management frame transmitted\n");
  199. return 0;
  200. }
  201. /*
  202. * CFG802.11 operation handler to register a mgmt frame.
  203. */
  204. static void
  205. mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
  206. struct wireless_dev *wdev,
  207. u16 frame_type, bool reg)
  208. {
  209. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  210. if (reg)
  211. priv->mgmt_frame_mask |= BIT(frame_type >> 4);
  212. else
  213. priv->mgmt_frame_mask &= ~BIT(frame_type >> 4);
  214. mwifiex_send_cmd_async(priv, HostCmd_CMD_MGMT_FRAME_REG,
  215. HostCmd_ACT_GEN_SET, 0, &priv->mgmt_frame_mask);
  216. wiphy_dbg(wiphy, "info: mgmt frame registered\n");
  217. }
  218. /*
  219. * CFG802.11 operation handler to set Tx power.
  220. */
  221. static int
  222. mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
  223. enum nl80211_tx_power_setting type,
  224. int mbm)
  225. {
  226. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  227. struct mwifiex_private *priv;
  228. struct mwifiex_power_cfg power_cfg;
  229. int dbm = MBM_TO_DBM(mbm);
  230. if (type == NL80211_TX_POWER_FIXED) {
  231. power_cfg.is_power_auto = 0;
  232. power_cfg.power_level = dbm;
  233. } else {
  234. power_cfg.is_power_auto = 1;
  235. }
  236. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  237. return mwifiex_set_tx_power(priv, &power_cfg);
  238. }
  239. /*
  240. * CFG802.11 operation handler to set Power Save option.
  241. *
  242. * The timeout value, if provided, is currently ignored.
  243. */
  244. static int
  245. mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  246. struct net_device *dev,
  247. bool enabled, int timeout)
  248. {
  249. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  250. u32 ps_mode;
  251. if (timeout)
  252. wiphy_dbg(wiphy,
  253. "info: ignore timeout value for IEEE Power Save\n");
  254. ps_mode = enabled;
  255. return mwifiex_drv_set_power(priv, &ps_mode);
  256. }
  257. /*
  258. * CFG802.11 operation handler to set the default network key.
  259. */
  260. static int
  261. mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  262. u8 key_index, bool unicast,
  263. bool multicast)
  264. {
  265. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  266. /* Return if WEP key not configured */
  267. if (!priv->sec_info.wep_enabled)
  268. return 0;
  269. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
  270. priv->wep_key_curr_index = key_index;
  271. } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
  272. NULL, 0)) {
  273. wiphy_err(wiphy, "set default Tx key index\n");
  274. return -EFAULT;
  275. }
  276. return 0;
  277. }
  278. /*
  279. * CFG802.11 operation handler to add a network key.
  280. */
  281. static int
  282. mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
  283. u8 key_index, bool pairwise, const u8 *mac_addr,
  284. struct key_params *params)
  285. {
  286. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  287. struct mwifiex_wep_key *wep_key;
  288. const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  289. const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
  290. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
  291. (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  292. params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
  293. if (params->key && params->key_len) {
  294. wep_key = &priv->wep_key[key_index];
  295. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  296. memcpy(wep_key->key_material, params->key,
  297. params->key_len);
  298. wep_key->key_index = key_index;
  299. wep_key->key_length = params->key_len;
  300. priv->sec_info.wep_enabled = 1;
  301. }
  302. return 0;
  303. }
  304. if (mwifiex_set_encode(priv, params, params->key, params->key_len,
  305. key_index, peer_mac, 0)) {
  306. wiphy_err(wiphy, "crypto keys added\n");
  307. return -EFAULT;
  308. }
  309. return 0;
  310. }
  311. /*
  312. * This function sends domain information to the firmware.
  313. *
  314. * The following information are passed to the firmware -
  315. * - Country codes
  316. * - Sub bands (first channel, number of channels, maximum Tx power)
  317. */
  318. static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
  319. {
  320. u8 no_of_triplet = 0;
  321. struct ieee80211_country_ie_triplet *t;
  322. u8 no_of_parsed_chan = 0;
  323. u8 first_chan = 0, next_chan = 0, max_pwr = 0;
  324. u8 i, flag = 0;
  325. enum ieee80211_band band;
  326. struct ieee80211_supported_band *sband;
  327. struct ieee80211_channel *ch;
  328. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  329. struct mwifiex_private *priv;
  330. struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
  331. /* Set country code */
  332. domain_info->country_code[0] = adapter->country_code[0];
  333. domain_info->country_code[1] = adapter->country_code[1];
  334. domain_info->country_code[2] = ' ';
  335. band = mwifiex_band_to_radio_type(adapter->config_bands);
  336. if (!wiphy->bands[band]) {
  337. wiphy_err(wiphy, "11D: setting domain info in FW\n");
  338. return -1;
  339. }
  340. sband = wiphy->bands[band];
  341. for (i = 0; i < sband->n_channels ; i++) {
  342. ch = &sband->channels[i];
  343. if (ch->flags & IEEE80211_CHAN_DISABLED)
  344. continue;
  345. if (!flag) {
  346. flag = 1;
  347. first_chan = (u32) ch->hw_value;
  348. next_chan = first_chan;
  349. max_pwr = ch->max_reg_power;
  350. no_of_parsed_chan = 1;
  351. continue;
  352. }
  353. if (ch->hw_value == next_chan + 1 &&
  354. ch->max_reg_power == max_pwr) {
  355. next_chan++;
  356. no_of_parsed_chan++;
  357. } else {
  358. t = &domain_info->triplet[no_of_triplet];
  359. t->chans.first_channel = first_chan;
  360. t->chans.num_channels = no_of_parsed_chan;
  361. t->chans.max_power = max_pwr;
  362. no_of_triplet++;
  363. first_chan = (u32) ch->hw_value;
  364. next_chan = first_chan;
  365. max_pwr = ch->max_reg_power;
  366. no_of_parsed_chan = 1;
  367. }
  368. }
  369. if (flag) {
  370. t = &domain_info->triplet[no_of_triplet];
  371. t->chans.first_channel = first_chan;
  372. t->chans.num_channels = no_of_parsed_chan;
  373. t->chans.max_power = max_pwr;
  374. no_of_triplet++;
  375. }
  376. domain_info->no_of_triplet = no_of_triplet;
  377. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  378. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  379. HostCmd_ACT_GEN_SET, 0, NULL)) {
  380. wiphy_err(wiphy, "11D: setting domain info in FW\n");
  381. return -1;
  382. }
  383. return 0;
  384. }
  385. /*
  386. * CFG802.11 regulatory domain callback function.
  387. *
  388. * This function is called when the regulatory domain is changed due to the
  389. * following reasons -
  390. * - Set by driver
  391. * - Set by system core
  392. * - Set by user
  393. * - Set bt Country IE
  394. */
  395. static int mwifiex_reg_notifier(struct wiphy *wiphy,
  396. struct regulatory_request *request)
  397. {
  398. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  399. wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
  400. request->alpha2[0], request->alpha2[1]);
  401. memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
  402. switch (request->initiator) {
  403. case NL80211_REGDOM_SET_BY_DRIVER:
  404. case NL80211_REGDOM_SET_BY_CORE:
  405. case NL80211_REGDOM_SET_BY_USER:
  406. break;
  407. /* Todo: apply driver specific changes in channel flags based
  408. on the request initiator if necessary. */
  409. case NL80211_REGDOM_SET_BY_COUNTRY_IE:
  410. break;
  411. }
  412. mwifiex_send_domain_info_cmd_fw(wiphy);
  413. return 0;
  414. }
  415. /*
  416. * This function sets the fragmentation threshold.
  417. *
  418. * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
  419. * and MWIFIEX_FRAG_MAX_VALUE.
  420. */
  421. static int
  422. mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
  423. {
  424. if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
  425. frag_thr > MWIFIEX_FRAG_MAX_VALUE)
  426. frag_thr = MWIFIEX_FRAG_MAX_VALUE;
  427. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
  428. HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
  429. &frag_thr);
  430. }
  431. /*
  432. * This function sets the RTS threshold.
  433. * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
  434. * and MWIFIEX_RTS_MAX_VALUE.
  435. */
  436. static int
  437. mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
  438. {
  439. if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
  440. rts_thr = MWIFIEX_RTS_MAX_VALUE;
  441. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
  442. HostCmd_ACT_GEN_SET, RTS_THRESH_I,
  443. &rts_thr);
  444. }
  445. /*
  446. * CFG802.11 operation handler to set wiphy parameters.
  447. *
  448. * This function can be used to set the RTS threshold and the
  449. * Fragmentation threshold of the driver.
  450. */
  451. static int
  452. mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  453. {
  454. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  455. struct mwifiex_private *priv;
  456. struct mwifiex_uap_bss_param *bss_cfg;
  457. int ret, bss_started, i;
  458. for (i = 0; i < adapter->priv_num; i++) {
  459. priv = adapter->priv[i];
  460. switch (priv->bss_role) {
  461. case MWIFIEX_BSS_ROLE_UAP:
  462. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
  463. GFP_KERNEL);
  464. if (!bss_cfg)
  465. return -ENOMEM;
  466. mwifiex_set_sys_config_invalid_data(bss_cfg);
  467. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  468. bss_cfg->rts_threshold = wiphy->rts_threshold;
  469. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  470. bss_cfg->frag_threshold = wiphy->frag_threshold;
  471. if (changed & WIPHY_PARAM_RETRY_LONG)
  472. bss_cfg->retry_limit = wiphy->retry_long;
  473. bss_started = priv->bss_started;
  474. ret = mwifiex_send_cmd_sync(priv,
  475. HostCmd_CMD_UAP_BSS_STOP,
  476. HostCmd_ACT_GEN_SET, 0,
  477. NULL);
  478. if (ret) {
  479. wiphy_err(wiphy, "Failed to stop the BSS\n");
  480. kfree(bss_cfg);
  481. return ret;
  482. }
  483. ret = mwifiex_send_cmd_async(priv,
  484. HostCmd_CMD_UAP_SYS_CONFIG,
  485. HostCmd_ACT_GEN_SET,
  486. UAP_BSS_PARAMS_I, bss_cfg);
  487. kfree(bss_cfg);
  488. if (ret) {
  489. wiphy_err(wiphy, "Failed to set bss config\n");
  490. return ret;
  491. }
  492. if (!bss_started)
  493. break;
  494. ret = mwifiex_send_cmd_async(priv,
  495. HostCmd_CMD_UAP_BSS_START,
  496. HostCmd_ACT_GEN_SET, 0,
  497. NULL);
  498. if (ret) {
  499. wiphy_err(wiphy, "Failed to start BSS\n");
  500. return ret;
  501. }
  502. break;
  503. case MWIFIEX_BSS_ROLE_STA:
  504. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  505. ret = mwifiex_set_rts(priv,
  506. wiphy->rts_threshold);
  507. if (ret)
  508. return ret;
  509. }
  510. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  511. ret = mwifiex_set_frag(priv,
  512. wiphy->frag_threshold);
  513. if (ret)
  514. return ret;
  515. }
  516. break;
  517. }
  518. }
  519. return 0;
  520. }
  521. /*
  522. * CFG802.11 operation handler to change interface type.
  523. */
  524. static int
  525. mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
  526. struct net_device *dev,
  527. enum nl80211_iftype type, u32 *flags,
  528. struct vif_params *params)
  529. {
  530. int ret;
  531. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  532. switch (dev->ieee80211_ptr->iftype) {
  533. case NL80211_IFTYPE_ADHOC:
  534. switch (type) {
  535. case NL80211_IFTYPE_STATION:
  536. break;
  537. case NL80211_IFTYPE_UNSPECIFIED:
  538. wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
  539. case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
  540. return 0;
  541. case NL80211_IFTYPE_AP:
  542. default:
  543. wiphy_err(wiphy, "%s: changing to %d not supported\n",
  544. dev->name, type);
  545. return -EOPNOTSUPP;
  546. }
  547. break;
  548. case NL80211_IFTYPE_STATION:
  549. switch (type) {
  550. case NL80211_IFTYPE_ADHOC:
  551. break;
  552. case NL80211_IFTYPE_UNSPECIFIED:
  553. wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
  554. case NL80211_IFTYPE_STATION: /* This shouldn't happen */
  555. return 0;
  556. case NL80211_IFTYPE_AP:
  557. default:
  558. wiphy_err(wiphy, "%s: changing to %d not supported\n",
  559. dev->name, type);
  560. return -EOPNOTSUPP;
  561. }
  562. break;
  563. case NL80211_IFTYPE_AP:
  564. switch (type) {
  565. case NL80211_IFTYPE_UNSPECIFIED:
  566. wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
  567. case NL80211_IFTYPE_AP: /* This shouldn't happen */
  568. return 0;
  569. case NL80211_IFTYPE_ADHOC:
  570. case NL80211_IFTYPE_STATION:
  571. default:
  572. wiphy_err(wiphy, "%s: changing to %d not supported\n",
  573. dev->name, type);
  574. return -EOPNOTSUPP;
  575. }
  576. break;
  577. default:
  578. wiphy_err(wiphy, "%s: unknown iftype: %d\n",
  579. dev->name, dev->ieee80211_ptr->iftype);
  580. return -EOPNOTSUPP;
  581. }
  582. dev->ieee80211_ptr->iftype = type;
  583. priv->bss_mode = type;
  584. mwifiex_deauthenticate(priv, NULL);
  585. priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
  586. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
  587. HostCmd_ACT_GEN_SET, 0, NULL);
  588. return ret;
  589. }
  590. /*
  591. * This function dumps the station information on a buffer.
  592. *
  593. * The following information are shown -
  594. * - Total bytes transmitted
  595. * - Total bytes received
  596. * - Total packets transmitted
  597. * - Total packets received
  598. * - Signal quality level
  599. * - Transmission rate
  600. */
  601. static int
  602. mwifiex_dump_station_info(struct mwifiex_private *priv,
  603. struct station_info *sinfo)
  604. {
  605. u32 rate;
  606. sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
  607. STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
  608. STATION_INFO_TX_BITRATE |
  609. STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  610. /* Get signal information from the firmware */
  611. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
  612. HostCmd_ACT_GEN_GET, 0, NULL)) {
  613. dev_err(priv->adapter->dev, "failed to get signal information\n");
  614. return -EFAULT;
  615. }
  616. if (mwifiex_drv_get_data_rate(priv, &rate)) {
  617. dev_err(priv->adapter->dev, "getting data rate\n");
  618. return -EFAULT;
  619. }
  620. /* Get DTIM period information from firmware */
  621. mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
  622. HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
  623. &priv->dtim_period);
  624. /*
  625. * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
  626. * MCS index values for us are 0 to 15.
  627. */
  628. if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
  629. sinfo->txrate.mcs = priv->tx_rate;
  630. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  631. /* 40MHz rate */
  632. if (priv->tx_htinfo & BIT(1))
  633. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  634. /* SGI enabled */
  635. if (priv->tx_htinfo & BIT(2))
  636. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  637. }
  638. sinfo->signal_avg = priv->bcn_rssi_avg;
  639. sinfo->rx_bytes = priv->stats.rx_bytes;
  640. sinfo->tx_bytes = priv->stats.tx_bytes;
  641. sinfo->rx_packets = priv->stats.rx_packets;
  642. sinfo->tx_packets = priv->stats.tx_packets;
  643. sinfo->signal = priv->bcn_rssi_avg;
  644. /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
  645. sinfo->txrate.legacy = rate * 5;
  646. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  647. sinfo->filled |= STATION_INFO_BSS_PARAM;
  648. sinfo->bss_param.flags = 0;
  649. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  650. WLAN_CAPABILITY_SHORT_PREAMBLE)
  651. sinfo->bss_param.flags |=
  652. BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  653. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  654. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  655. sinfo->bss_param.flags |=
  656. BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  657. sinfo->bss_param.dtim_period = priv->dtim_period;
  658. sinfo->bss_param.beacon_interval =
  659. priv->curr_bss_params.bss_descriptor.beacon_period;
  660. }
  661. return 0;
  662. }
  663. /*
  664. * CFG802.11 operation handler to get station information.
  665. *
  666. * This function only works in connected mode, and dumps the
  667. * requested station information, if available.
  668. */
  669. static int
  670. mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  671. u8 *mac, struct station_info *sinfo)
  672. {
  673. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  674. if (!priv->media_connected)
  675. return -ENOENT;
  676. if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
  677. return -ENOENT;
  678. return mwifiex_dump_station_info(priv, sinfo);
  679. }
  680. /*
  681. * CFG802.11 operation handler to dump station information.
  682. */
  683. static int
  684. mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  685. int idx, u8 *mac, struct station_info *sinfo)
  686. {
  687. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  688. if (!priv->media_connected || idx)
  689. return -ENOENT;
  690. memcpy(mac, priv->cfg_bssid, ETH_ALEN);
  691. return mwifiex_dump_station_info(priv, sinfo);
  692. }
  693. /* Supported rates to be advertised to the cfg80211 */
  694. static struct ieee80211_rate mwifiex_rates[] = {
  695. {.bitrate = 10, .hw_value = 2, },
  696. {.bitrate = 20, .hw_value = 4, },
  697. {.bitrate = 55, .hw_value = 11, },
  698. {.bitrate = 110, .hw_value = 22, },
  699. {.bitrate = 60, .hw_value = 12, },
  700. {.bitrate = 90, .hw_value = 18, },
  701. {.bitrate = 120, .hw_value = 24, },
  702. {.bitrate = 180, .hw_value = 36, },
  703. {.bitrate = 240, .hw_value = 48, },
  704. {.bitrate = 360, .hw_value = 72, },
  705. {.bitrate = 480, .hw_value = 96, },
  706. {.bitrate = 540, .hw_value = 108, },
  707. };
  708. /* Channel definitions to be advertised to cfg80211 */
  709. static struct ieee80211_channel mwifiex_channels_2ghz[] = {
  710. {.center_freq = 2412, .hw_value = 1, },
  711. {.center_freq = 2417, .hw_value = 2, },
  712. {.center_freq = 2422, .hw_value = 3, },
  713. {.center_freq = 2427, .hw_value = 4, },
  714. {.center_freq = 2432, .hw_value = 5, },
  715. {.center_freq = 2437, .hw_value = 6, },
  716. {.center_freq = 2442, .hw_value = 7, },
  717. {.center_freq = 2447, .hw_value = 8, },
  718. {.center_freq = 2452, .hw_value = 9, },
  719. {.center_freq = 2457, .hw_value = 10, },
  720. {.center_freq = 2462, .hw_value = 11, },
  721. {.center_freq = 2467, .hw_value = 12, },
  722. {.center_freq = 2472, .hw_value = 13, },
  723. {.center_freq = 2484, .hw_value = 14, },
  724. };
  725. static struct ieee80211_supported_band mwifiex_band_2ghz = {
  726. .channels = mwifiex_channels_2ghz,
  727. .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
  728. .bitrates = mwifiex_rates,
  729. .n_bitrates = ARRAY_SIZE(mwifiex_rates),
  730. };
  731. static struct ieee80211_channel mwifiex_channels_5ghz[] = {
  732. {.center_freq = 5040, .hw_value = 8, },
  733. {.center_freq = 5060, .hw_value = 12, },
  734. {.center_freq = 5080, .hw_value = 16, },
  735. {.center_freq = 5170, .hw_value = 34, },
  736. {.center_freq = 5190, .hw_value = 38, },
  737. {.center_freq = 5210, .hw_value = 42, },
  738. {.center_freq = 5230, .hw_value = 46, },
  739. {.center_freq = 5180, .hw_value = 36, },
  740. {.center_freq = 5200, .hw_value = 40, },
  741. {.center_freq = 5220, .hw_value = 44, },
  742. {.center_freq = 5240, .hw_value = 48, },
  743. {.center_freq = 5260, .hw_value = 52, },
  744. {.center_freq = 5280, .hw_value = 56, },
  745. {.center_freq = 5300, .hw_value = 60, },
  746. {.center_freq = 5320, .hw_value = 64, },
  747. {.center_freq = 5500, .hw_value = 100, },
  748. {.center_freq = 5520, .hw_value = 104, },
  749. {.center_freq = 5540, .hw_value = 108, },
  750. {.center_freq = 5560, .hw_value = 112, },
  751. {.center_freq = 5580, .hw_value = 116, },
  752. {.center_freq = 5600, .hw_value = 120, },
  753. {.center_freq = 5620, .hw_value = 124, },
  754. {.center_freq = 5640, .hw_value = 128, },
  755. {.center_freq = 5660, .hw_value = 132, },
  756. {.center_freq = 5680, .hw_value = 136, },
  757. {.center_freq = 5700, .hw_value = 140, },
  758. {.center_freq = 5745, .hw_value = 149, },
  759. {.center_freq = 5765, .hw_value = 153, },
  760. {.center_freq = 5785, .hw_value = 157, },
  761. {.center_freq = 5805, .hw_value = 161, },
  762. {.center_freq = 5825, .hw_value = 165, },
  763. };
  764. static struct ieee80211_supported_band mwifiex_band_5ghz = {
  765. .channels = mwifiex_channels_5ghz,
  766. .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
  767. .bitrates = mwifiex_rates + 4,
  768. .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
  769. };
  770. /* Supported crypto cipher suits to be advertised to cfg80211 */
  771. static const u32 mwifiex_cipher_suites[] = {
  772. WLAN_CIPHER_SUITE_WEP40,
  773. WLAN_CIPHER_SUITE_WEP104,
  774. WLAN_CIPHER_SUITE_TKIP,
  775. WLAN_CIPHER_SUITE_CCMP,
  776. WLAN_CIPHER_SUITE_AES_CMAC,
  777. };
  778. /* Supported mgmt frame types to be advertised to cfg80211 */
  779. static const struct ieee80211_txrx_stypes
  780. mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  781. [NL80211_IFTYPE_STATION] = {
  782. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  783. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  784. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  785. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  786. },
  787. [NL80211_IFTYPE_AP] = {
  788. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  789. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  790. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  791. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  792. },
  793. [NL80211_IFTYPE_P2P_CLIENT] = {
  794. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  795. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  796. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  797. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  798. },
  799. [NL80211_IFTYPE_P2P_GO] = {
  800. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  801. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  802. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  803. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  804. },
  805. };
  806. /*
  807. * CFG802.11 operation handler for setting bit rates.
  808. *
  809. * Function configures data rates to firmware using bitrate mask
  810. * provided by cfg80211.
  811. */
  812. static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
  813. struct net_device *dev,
  814. const u8 *peer,
  815. const struct cfg80211_bitrate_mask *mask)
  816. {
  817. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  818. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  819. enum ieee80211_band band;
  820. if (!priv->media_connected) {
  821. dev_err(priv->adapter->dev,
  822. "Can not set Tx data rate in disconnected state\n");
  823. return -EINVAL;
  824. }
  825. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  826. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  827. /* Fill HR/DSSS rates. */
  828. if (band == IEEE80211_BAND_2GHZ)
  829. bitmap_rates[0] = mask->control[band].legacy & 0x000f;
  830. /* Fill OFDM rates */
  831. if (band == IEEE80211_BAND_2GHZ)
  832. bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
  833. else
  834. bitmap_rates[1] = mask->control[band].legacy;
  835. /* Fill MCS rates */
  836. bitmap_rates[2] = mask->control[band].mcs[0];
  837. if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  838. bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
  839. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
  840. HostCmd_ACT_GEN_SET, 0, bitmap_rates);
  841. }
  842. /*
  843. * CFG802.11 operation handler for connection quality monitoring.
  844. *
  845. * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
  846. * events to FW.
  847. */
  848. static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
  849. struct net_device *dev,
  850. s32 rssi_thold, u32 rssi_hyst)
  851. {
  852. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  853. struct mwifiex_ds_misc_subsc_evt subsc_evt;
  854. priv->cqm_rssi_thold = rssi_thold;
  855. priv->cqm_rssi_hyst = rssi_hyst;
  856. memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  857. subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  858. /* Subscribe/unsubscribe low and high rssi events */
  859. if (rssi_thold && rssi_hyst) {
  860. subsc_evt.action = HostCmd_ACT_BITWISE_SET;
  861. subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
  862. subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
  863. subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
  864. subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
  865. return mwifiex_send_cmd_sync(priv,
  866. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  867. 0, 0, &subsc_evt);
  868. } else {
  869. subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
  870. return mwifiex_send_cmd_sync(priv,
  871. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  872. 0, 0, &subsc_evt);
  873. }
  874. return 0;
  875. }
  876. /* cfg80211 operation handler for change_beacon.
  877. * Function retrieves and sets modified management IEs to FW.
  878. */
  879. static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
  880. struct net_device *dev,
  881. struct cfg80211_beacon_data *data)
  882. {
  883. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  884. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  885. wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
  886. return -EINVAL;
  887. }
  888. if (!priv->bss_started) {
  889. wiphy_err(wiphy, "%s: bss not started\n", __func__);
  890. return -EINVAL;
  891. }
  892. if (mwifiex_set_mgmt_ies(priv, data)) {
  893. wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
  894. return -EFAULT;
  895. }
  896. return 0;
  897. }
  898. static int
  899. mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  900. {
  901. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  902. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  903. MWIFIEX_BSS_ROLE_ANY);
  904. struct mwifiex_ds_ant_cfg ant_cfg;
  905. if (!tx_ant || !rx_ant)
  906. return -EOPNOTSUPP;
  907. if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
  908. /* Not a MIMO chip. User should provide specific antenna number
  909. * for Tx/Rx path or enable all antennas for diversity
  910. */
  911. if (tx_ant != rx_ant)
  912. return -EOPNOTSUPP;
  913. if ((tx_ant & (tx_ant - 1)) &&
  914. (tx_ant != BIT(adapter->number_of_antenna) - 1))
  915. return -EOPNOTSUPP;
  916. if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
  917. (priv->adapter->number_of_antenna > 1)) {
  918. tx_ant = RF_ANTENNA_AUTO;
  919. rx_ant = RF_ANTENNA_AUTO;
  920. }
  921. }
  922. ant_cfg.tx_ant = tx_ant;
  923. ant_cfg.rx_ant = rx_ant;
  924. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
  925. HostCmd_ACT_GEN_SET, 0, &ant_cfg);
  926. }
  927. /* cfg80211 operation handler for stop ap.
  928. * Function stops BSS running at uAP interface.
  929. */
  930. static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  931. {
  932. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  933. if (mwifiex_del_mgmt_ies(priv))
  934. wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
  935. priv->ap_11n_enabled = 0;
  936. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
  937. HostCmd_ACT_GEN_SET, 0, NULL)) {
  938. wiphy_err(wiphy, "Failed to stop the BSS\n");
  939. return -1;
  940. }
  941. return 0;
  942. }
  943. /* cfg80211 operation handler for start_ap.
  944. * Function sets beacon period, DTIM period, SSID and security into
  945. * AP config structure.
  946. * AP is configured with these settings and BSS is started.
  947. */
  948. static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
  949. struct net_device *dev,
  950. struct cfg80211_ap_settings *params)
  951. {
  952. struct mwifiex_uap_bss_param *bss_cfg;
  953. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  954. u8 config_bands = 0;
  955. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP)
  956. return -1;
  957. if (mwifiex_set_mgmt_ies(priv, &params->beacon))
  958. return -1;
  959. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  960. if (!bss_cfg)
  961. return -ENOMEM;
  962. mwifiex_set_sys_config_invalid_data(bss_cfg);
  963. if (params->beacon_interval)
  964. bss_cfg->beacon_period = params->beacon_interval;
  965. if (params->dtim_period)
  966. bss_cfg->dtim_period = params->dtim_period;
  967. if (params->ssid && params->ssid_len) {
  968. memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
  969. bss_cfg->ssid.ssid_len = params->ssid_len;
  970. }
  971. switch (params->hidden_ssid) {
  972. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  973. bss_cfg->bcast_ssid_ctl = 1;
  974. break;
  975. case NL80211_HIDDEN_SSID_ZERO_LEN:
  976. bss_cfg->bcast_ssid_ctl = 0;
  977. break;
  978. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  979. /* firmware doesn't support this type of hidden SSID */
  980. default:
  981. kfree(bss_cfg);
  982. return -EINVAL;
  983. }
  984. bss_cfg->channel =
  985. (u8)ieee80211_frequency_to_channel(params->channel->center_freq);
  986. /* Set appropriate bands */
  987. if (params->channel->band == IEEE80211_BAND_2GHZ) {
  988. bss_cfg->band_cfg = BAND_CONFIG_BG;
  989. if (params->channel_type == NL80211_CHAN_NO_HT)
  990. config_bands = BAND_B | BAND_G;
  991. else
  992. config_bands = BAND_B | BAND_G | BAND_GN;
  993. } else {
  994. bss_cfg->band_cfg = BAND_CONFIG_A;
  995. if (params->channel_type == NL80211_CHAN_NO_HT)
  996. config_bands = BAND_A;
  997. else
  998. config_bands = BAND_AN | BAND_A;
  999. }
  1000. if (!((config_bands | priv->adapter->fw_bands) &
  1001. ~priv->adapter->fw_bands))
  1002. priv->adapter->config_bands = config_bands;
  1003. mwifiex_set_uap_rates(bss_cfg, params);
  1004. mwifiex_send_domain_info_cmd_fw(wiphy);
  1005. if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
  1006. kfree(bss_cfg);
  1007. wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
  1008. return -1;
  1009. }
  1010. mwifiex_set_ht_params(priv, bss_cfg, params);
  1011. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
  1012. HostCmd_ACT_GEN_SET, 0, NULL)) {
  1013. wiphy_err(wiphy, "Failed to stop the BSS\n");
  1014. kfree(bss_cfg);
  1015. return -1;
  1016. }
  1017. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  1018. HostCmd_ACT_GEN_SET,
  1019. UAP_BSS_PARAMS_I, bss_cfg)) {
  1020. wiphy_err(wiphy, "Failed to set the SSID\n");
  1021. kfree(bss_cfg);
  1022. return -1;
  1023. }
  1024. kfree(bss_cfg);
  1025. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
  1026. HostCmd_ACT_GEN_SET, 0, NULL)) {
  1027. wiphy_err(wiphy, "Failed to start the BSS\n");
  1028. return -1;
  1029. }
  1030. if (priv->sec_info.wep_enabled)
  1031. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  1032. else
  1033. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  1034. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  1035. HostCmd_ACT_GEN_SET, 0,
  1036. &priv->curr_pkt_filter))
  1037. return -1;
  1038. return 0;
  1039. }
  1040. /*
  1041. * CFG802.11 operation handler for disconnection request.
  1042. *
  1043. * This function does not work when there is already a disconnection
  1044. * procedure going on.
  1045. */
  1046. static int
  1047. mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1048. u16 reason_code)
  1049. {
  1050. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1051. if (mwifiex_deauthenticate(priv, NULL))
  1052. return -EFAULT;
  1053. wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
  1054. " reason code %d\n", priv->cfg_bssid, reason_code);
  1055. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1056. return 0;
  1057. }
  1058. /*
  1059. * This function informs the CFG802.11 subsystem of a new IBSS.
  1060. *
  1061. * The following information are sent to the CFG802.11 subsystem
  1062. * to register the new IBSS. If we do not register the new IBSS,
  1063. * a kernel panic will result.
  1064. * - SSID
  1065. * - SSID length
  1066. * - BSSID
  1067. * - Channel
  1068. */
  1069. static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
  1070. {
  1071. struct ieee80211_channel *chan;
  1072. struct mwifiex_bss_info bss_info;
  1073. struct cfg80211_bss *bss;
  1074. int ie_len;
  1075. u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
  1076. enum ieee80211_band band;
  1077. if (mwifiex_get_bss_info(priv, &bss_info))
  1078. return -1;
  1079. ie_buf[0] = WLAN_EID_SSID;
  1080. ie_buf[1] = bss_info.ssid.ssid_len;
  1081. memcpy(&ie_buf[sizeof(struct ieee_types_header)],
  1082. &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
  1083. ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
  1084. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  1085. chan = __ieee80211_get_channel(priv->wdev->wiphy,
  1086. ieee80211_channel_to_frequency(bss_info.bss_chan,
  1087. band));
  1088. bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
  1089. bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
  1090. 0, ie_buf, ie_len, 0, GFP_KERNEL);
  1091. cfg80211_put_bss(bss);
  1092. memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
  1093. return 0;
  1094. }
  1095. /*
  1096. * This function connects with a BSS.
  1097. *
  1098. * This function handles both Infra and Ad-Hoc modes. It also performs
  1099. * validity checking on the provided parameters, disconnects from the
  1100. * current BSS (if any), sets up the association/scan parameters,
  1101. * including security settings, and performs specific SSID scan before
  1102. * trying to connect.
  1103. *
  1104. * For Infra mode, the function returns failure if the specified SSID
  1105. * is not found in scan table. However, for Ad-Hoc mode, it can create
  1106. * the IBSS if it does not exist. On successful completion in either case,
  1107. * the function notifies the CFG802.11 subsystem of the new BSS connection.
  1108. */
  1109. static int
  1110. mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
  1111. u8 *bssid, int mode, struct ieee80211_channel *channel,
  1112. struct cfg80211_connect_params *sme, bool privacy)
  1113. {
  1114. struct cfg80211_ssid req_ssid;
  1115. int ret, auth_type = 0;
  1116. struct cfg80211_bss *bss = NULL;
  1117. u8 is_scanning_required = 0, config_bands = 0;
  1118. memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
  1119. req_ssid.ssid_len = ssid_len;
  1120. if (ssid_len > IEEE80211_MAX_SSID_LEN) {
  1121. dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
  1122. return -EINVAL;
  1123. }
  1124. memcpy(req_ssid.ssid, ssid, ssid_len);
  1125. if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
  1126. dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
  1127. return -EINVAL;
  1128. }
  1129. /* disconnect before try to associate */
  1130. mwifiex_deauthenticate(priv, NULL);
  1131. if (channel) {
  1132. if (mode == NL80211_IFTYPE_STATION) {
  1133. if (channel->band == IEEE80211_BAND_2GHZ)
  1134. config_bands = BAND_B | BAND_G | BAND_GN;
  1135. else
  1136. config_bands = BAND_A | BAND_AN;
  1137. if (!((config_bands | priv->adapter->fw_bands) &
  1138. ~priv->adapter->fw_bands))
  1139. priv->adapter->config_bands = config_bands;
  1140. }
  1141. }
  1142. /* As this is new association, clear locally stored
  1143. * keys and security related flags */
  1144. priv->sec_info.wpa_enabled = false;
  1145. priv->sec_info.wpa2_enabled = false;
  1146. priv->wep_key_curr_index = 0;
  1147. priv->sec_info.encryption_mode = 0;
  1148. priv->sec_info.is_authtype_auto = 0;
  1149. ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
  1150. if (mode == NL80211_IFTYPE_ADHOC) {
  1151. /* "privacy" is set only for ad-hoc mode */
  1152. if (privacy) {
  1153. /*
  1154. * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
  1155. * the firmware can find a matching network from the
  1156. * scan. The cfg80211 does not give us the encryption
  1157. * mode at this stage so just setting it to WEP here.
  1158. */
  1159. priv->sec_info.encryption_mode =
  1160. WLAN_CIPHER_SUITE_WEP104;
  1161. priv->sec_info.authentication_mode =
  1162. NL80211_AUTHTYPE_OPEN_SYSTEM;
  1163. }
  1164. goto done;
  1165. }
  1166. /* Now handle infra mode. "sme" is valid for infra mode only */
  1167. if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
  1168. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1169. priv->sec_info.is_authtype_auto = 1;
  1170. } else {
  1171. auth_type = sme->auth_type;
  1172. }
  1173. if (sme->crypto.n_ciphers_pairwise) {
  1174. priv->sec_info.encryption_mode =
  1175. sme->crypto.ciphers_pairwise[0];
  1176. priv->sec_info.authentication_mode = auth_type;
  1177. }
  1178. if (sme->crypto.cipher_group) {
  1179. priv->sec_info.encryption_mode = sme->crypto.cipher_group;
  1180. priv->sec_info.authentication_mode = auth_type;
  1181. }
  1182. if (sme->ie)
  1183. ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
  1184. if (sme->key) {
  1185. if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
  1186. dev_dbg(priv->adapter->dev,
  1187. "info: setting wep encryption"
  1188. " with key len %d\n", sme->key_len);
  1189. priv->wep_key_curr_index = sme->key_idx;
  1190. ret = mwifiex_set_encode(priv, NULL, sme->key,
  1191. sme->key_len, sme->key_idx,
  1192. NULL, 0);
  1193. }
  1194. }
  1195. done:
  1196. /*
  1197. * Scan entries are valid for some time (15 sec). So we can save one
  1198. * active scan time if we just try cfg80211_get_bss first. If it fails
  1199. * then request scan and cfg80211_get_bss() again for final output.
  1200. */
  1201. while (1) {
  1202. if (is_scanning_required) {
  1203. /* Do specific SSID scanning */
  1204. if (mwifiex_request_scan(priv, &req_ssid)) {
  1205. dev_err(priv->adapter->dev, "scan error\n");
  1206. return -EFAULT;
  1207. }
  1208. }
  1209. /* Find the BSS we want using available scan results */
  1210. if (mode == NL80211_IFTYPE_ADHOC)
  1211. bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
  1212. bssid, ssid, ssid_len,
  1213. WLAN_CAPABILITY_IBSS,
  1214. WLAN_CAPABILITY_IBSS);
  1215. else
  1216. bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
  1217. bssid, ssid, ssid_len,
  1218. WLAN_CAPABILITY_ESS,
  1219. WLAN_CAPABILITY_ESS);
  1220. if (!bss) {
  1221. if (is_scanning_required) {
  1222. dev_warn(priv->adapter->dev,
  1223. "assoc: requested bss not found in scan results\n");
  1224. break;
  1225. }
  1226. is_scanning_required = 1;
  1227. } else {
  1228. dev_dbg(priv->adapter->dev,
  1229. "info: trying to associate to '%s' bssid %pM\n",
  1230. (char *) req_ssid.ssid, bss->bssid);
  1231. memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
  1232. break;
  1233. }
  1234. }
  1235. if (mwifiex_bss_start(priv, bss, &req_ssid))
  1236. return -EFAULT;
  1237. if (mode == NL80211_IFTYPE_ADHOC) {
  1238. /* Inform the BSS information to kernel, otherwise
  1239. * kernel will give a panic after successful assoc */
  1240. if (mwifiex_cfg80211_inform_ibss_bss(priv))
  1241. return -EFAULT;
  1242. }
  1243. return ret;
  1244. }
  1245. /*
  1246. * CFG802.11 operation handler for association request.
  1247. *
  1248. * This function does not work when the current mode is set to Ad-Hoc, or
  1249. * when there is already an association procedure going on. The given BSS
  1250. * information is used to associate.
  1251. */
  1252. static int
  1253. mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  1254. struct cfg80211_connect_params *sme)
  1255. {
  1256. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1257. int ret = 0;
  1258. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  1259. wiphy_err(wiphy, "received infra assoc request "
  1260. "when station is in ibss mode\n");
  1261. goto done;
  1262. }
  1263. if (priv->bss_mode == NL80211_IFTYPE_AP) {
  1264. wiphy_err(wiphy, "skip association request for AP interface\n");
  1265. goto done;
  1266. }
  1267. wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
  1268. (char *) sme->ssid, sme->bssid);
  1269. ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
  1270. priv->bss_mode, sme->channel, sme, 0);
  1271. done:
  1272. if (!ret) {
  1273. cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
  1274. NULL, 0, WLAN_STATUS_SUCCESS,
  1275. GFP_KERNEL);
  1276. dev_dbg(priv->adapter->dev,
  1277. "info: associated to bssid %pM successfully\n",
  1278. priv->cfg_bssid);
  1279. } else {
  1280. dev_dbg(priv->adapter->dev,
  1281. "info: association to bssid %pM failed\n",
  1282. priv->cfg_bssid);
  1283. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1284. }
  1285. return ret;
  1286. }
  1287. /*
  1288. * This function sets following parameters for ibss network.
  1289. * - channel
  1290. * - start band
  1291. * - 11n flag
  1292. * - secondary channel offset
  1293. */
  1294. static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
  1295. struct cfg80211_ibss_params *params)
  1296. {
  1297. struct wiphy *wiphy = priv->wdev->wiphy;
  1298. struct mwifiex_adapter *adapter = priv->adapter;
  1299. int index = 0, i;
  1300. u8 config_bands = 0;
  1301. if (params->channel->band == IEEE80211_BAND_2GHZ) {
  1302. if (!params->basic_rates) {
  1303. config_bands = BAND_B | BAND_G;
  1304. } else {
  1305. for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
  1306. /*
  1307. * Rates below 6 Mbps in the table are CCK
  1308. * rates; 802.11b and from 6 they are OFDM;
  1309. * 802.11G
  1310. */
  1311. if (mwifiex_rates[i].bitrate == 60) {
  1312. index = 1 << i;
  1313. break;
  1314. }
  1315. }
  1316. if (params->basic_rates < index) {
  1317. config_bands = BAND_B;
  1318. } else {
  1319. config_bands = BAND_G;
  1320. if (params->basic_rates % index)
  1321. config_bands |= BAND_B;
  1322. }
  1323. }
  1324. if (params->channel_type != NL80211_CHAN_NO_HT)
  1325. config_bands |= BAND_GN;
  1326. } else {
  1327. if (params->channel_type == NL80211_CHAN_NO_HT)
  1328. config_bands = BAND_A;
  1329. else
  1330. config_bands = BAND_AN | BAND_A;
  1331. }
  1332. if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
  1333. adapter->config_bands = config_bands;
  1334. adapter->adhoc_start_band = config_bands;
  1335. if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
  1336. adapter->adhoc_11n_enabled = true;
  1337. else
  1338. adapter->adhoc_11n_enabled = false;
  1339. }
  1340. adapter->sec_chan_offset =
  1341. mwifiex_chan_type_to_sec_chan_offset(params->channel_type);
  1342. priv->adhoc_channel =
  1343. ieee80211_frequency_to_channel(params->channel->center_freq);
  1344. wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
  1345. config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
  1346. return 0;
  1347. }
  1348. /*
  1349. * CFG802.11 operation handler to join an IBSS.
  1350. *
  1351. * This function does not work in any mode other than Ad-Hoc, or if
  1352. * a join operation is already in progress.
  1353. */
  1354. static int
  1355. mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1356. struct cfg80211_ibss_params *params)
  1357. {
  1358. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1359. int ret = 0;
  1360. if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
  1361. wiphy_err(wiphy, "request to join ibss received "
  1362. "when station is not in ibss mode\n");
  1363. goto done;
  1364. }
  1365. wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
  1366. (char *) params->ssid, params->bssid);
  1367. mwifiex_set_ibss_params(priv, params);
  1368. ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
  1369. params->bssid, priv->bss_mode,
  1370. params->channel, NULL, params->privacy);
  1371. done:
  1372. if (!ret) {
  1373. cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
  1374. dev_dbg(priv->adapter->dev,
  1375. "info: joined/created adhoc network with bssid"
  1376. " %pM successfully\n", priv->cfg_bssid);
  1377. } else {
  1378. dev_dbg(priv->adapter->dev,
  1379. "info: failed creating/joining adhoc network\n");
  1380. }
  1381. return ret;
  1382. }
  1383. /*
  1384. * CFG802.11 operation handler to leave an IBSS.
  1385. *
  1386. * This function does not work if a leave operation is
  1387. * already in progress.
  1388. */
  1389. static int
  1390. mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1391. {
  1392. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1393. wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
  1394. priv->cfg_bssid);
  1395. if (mwifiex_deauthenticate(priv, NULL))
  1396. return -EFAULT;
  1397. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1398. return 0;
  1399. }
  1400. /*
  1401. * CFG802.11 operation handler for scan request.
  1402. *
  1403. * This function issues a scan request to the firmware based upon
  1404. * the user specified scan configuration. On successfull completion,
  1405. * it also informs the results.
  1406. */
  1407. static int
  1408. mwifiex_cfg80211_scan(struct wiphy *wiphy,
  1409. struct cfg80211_scan_request *request)
  1410. {
  1411. struct net_device *dev = request->wdev->netdev;
  1412. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1413. int i;
  1414. struct ieee80211_channel *chan;
  1415. wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
  1416. if (atomic_read(&priv->wmm.tx_pkts_queued) >=
  1417. MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
  1418. dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
  1419. return -EBUSY;
  1420. }
  1421. priv->scan_request = request;
  1422. priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
  1423. GFP_KERNEL);
  1424. if (!priv->user_scan_cfg) {
  1425. dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
  1426. return -ENOMEM;
  1427. }
  1428. priv->user_scan_cfg->num_ssids = request->n_ssids;
  1429. priv->user_scan_cfg->ssid_list = request->ssids;
  1430. if (request->ie && request->ie_len) {
  1431. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  1432. if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
  1433. continue;
  1434. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
  1435. memcpy(&priv->vs_ie[i].ie, request->ie,
  1436. request->ie_len);
  1437. break;
  1438. }
  1439. }
  1440. for (i = 0; i < request->n_channels; i++) {
  1441. chan = request->channels[i];
  1442. priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
  1443. priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
  1444. if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  1445. priv->user_scan_cfg->chan_list[i].scan_type =
  1446. MWIFIEX_SCAN_TYPE_PASSIVE;
  1447. else
  1448. priv->user_scan_cfg->chan_list[i].scan_type =
  1449. MWIFIEX_SCAN_TYPE_ACTIVE;
  1450. priv->user_scan_cfg->chan_list[i].scan_time = 0;
  1451. }
  1452. if (mwifiex_scan_networks(priv, priv->user_scan_cfg))
  1453. return -EFAULT;
  1454. if (request->ie && request->ie_len) {
  1455. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  1456. if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
  1457. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
  1458. memset(&priv->vs_ie[i].ie, 0,
  1459. MWIFIEX_MAX_VSIE_LEN);
  1460. }
  1461. }
  1462. }
  1463. return 0;
  1464. }
  1465. /*
  1466. * This function sets up the CFG802.11 specific HT capability fields
  1467. * with default values.
  1468. *
  1469. * The following default values are set -
  1470. * - HT Supported = True
  1471. * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
  1472. * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
  1473. * - HT Capabilities supported by firmware
  1474. * - MCS information, Rx mask = 0xff
  1475. * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
  1476. */
  1477. static void
  1478. mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
  1479. struct mwifiex_private *priv)
  1480. {
  1481. int rx_mcs_supp;
  1482. struct ieee80211_mcs_info mcs_set;
  1483. u8 *mcs = (u8 *)&mcs_set;
  1484. struct mwifiex_adapter *adapter = priv->adapter;
  1485. ht_info->ht_supported = true;
  1486. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  1487. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1488. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  1489. /* Fill HT capability information */
  1490. if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  1491. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1492. else
  1493. ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1494. if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
  1495. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  1496. else
  1497. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
  1498. if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
  1499. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  1500. else
  1501. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
  1502. if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
  1503. ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
  1504. else
  1505. ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  1506. if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
  1507. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  1508. else
  1509. ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
  1510. ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  1511. ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
  1512. rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
  1513. /* Set MCS for 1x1 */
  1514. memset(mcs, 0xff, rx_mcs_supp);
  1515. /* Clear all the other values */
  1516. memset(&mcs[rx_mcs_supp], 0,
  1517. sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
  1518. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  1519. ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  1520. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  1521. SETHT_MCS32(mcs_set.rx_mask);
  1522. memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
  1523. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  1524. }
  1525. /*
  1526. * create a new virtual interface with the given name
  1527. */
  1528. struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
  1529. const char *name,
  1530. enum nl80211_iftype type,
  1531. u32 *flags,
  1532. struct vif_params *params)
  1533. {
  1534. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1535. struct mwifiex_private *priv;
  1536. struct net_device *dev;
  1537. void *mdev_priv;
  1538. struct wireless_dev *wdev;
  1539. if (!adapter)
  1540. return ERR_PTR(-EFAULT);
  1541. switch (type) {
  1542. case NL80211_IFTYPE_UNSPECIFIED:
  1543. case NL80211_IFTYPE_STATION:
  1544. case NL80211_IFTYPE_ADHOC:
  1545. priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
  1546. if (priv->bss_mode) {
  1547. wiphy_err(wiphy,
  1548. "cannot create multiple sta/adhoc ifaces\n");
  1549. return ERR_PTR(-EINVAL);
  1550. }
  1551. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1552. if (!wdev)
  1553. return ERR_PTR(-ENOMEM);
  1554. wdev->wiphy = wiphy;
  1555. priv->wdev = wdev;
  1556. wdev->iftype = NL80211_IFTYPE_STATION;
  1557. if (type == NL80211_IFTYPE_UNSPECIFIED)
  1558. priv->bss_mode = NL80211_IFTYPE_STATION;
  1559. else
  1560. priv->bss_mode = type;
  1561. priv->bss_type = MWIFIEX_BSS_TYPE_STA;
  1562. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  1563. priv->bss_priority = 0;
  1564. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  1565. priv->bss_num = 0;
  1566. break;
  1567. case NL80211_IFTYPE_AP:
  1568. priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
  1569. if (priv->bss_mode) {
  1570. wiphy_err(wiphy, "Can't create multiple AP interfaces");
  1571. return ERR_PTR(-EINVAL);
  1572. }
  1573. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1574. if (!wdev)
  1575. return ERR_PTR(-ENOMEM);
  1576. priv->wdev = wdev;
  1577. wdev->wiphy = wiphy;
  1578. wdev->iftype = NL80211_IFTYPE_AP;
  1579. priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
  1580. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  1581. priv->bss_priority = 0;
  1582. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  1583. priv->bss_started = 0;
  1584. priv->bss_num = 0;
  1585. priv->bss_mode = type;
  1586. break;
  1587. default:
  1588. wiphy_err(wiphy, "type not supported\n");
  1589. return ERR_PTR(-EINVAL);
  1590. }
  1591. dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
  1592. ether_setup, 1);
  1593. if (!dev) {
  1594. wiphy_err(wiphy, "no memory available for netdevice\n");
  1595. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  1596. return ERR_PTR(-ENOMEM);
  1597. }
  1598. mwifiex_init_priv_params(priv, dev);
  1599. priv->netdev = dev;
  1600. mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
  1601. if (adapter->config_bands & BAND_A)
  1602. mwifiex_setup_ht_caps(
  1603. &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
  1604. dev_net_set(dev, wiphy_net(wiphy));
  1605. dev->ieee80211_ptr = priv->wdev;
  1606. dev->ieee80211_ptr->iftype = priv->bss_mode;
  1607. memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
  1608. memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
  1609. SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
  1610. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  1611. dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
  1612. dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
  1613. mdev_priv = netdev_priv(dev);
  1614. *((unsigned long *) mdev_priv) = (unsigned long) priv;
  1615. SET_NETDEV_DEV(dev, adapter->dev);
  1616. /* Register network device */
  1617. if (register_netdevice(dev)) {
  1618. wiphy_err(wiphy, "cannot register virtual network device\n");
  1619. free_netdev(dev);
  1620. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  1621. return ERR_PTR(-EFAULT);
  1622. }
  1623. sema_init(&priv->async_sem, 1);
  1624. priv->scan_pending_on_block = false;
  1625. dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
  1626. #ifdef CONFIG_DEBUG_FS
  1627. mwifiex_dev_debugfs_init(priv);
  1628. #endif
  1629. return wdev;
  1630. }
  1631. EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
  1632. /*
  1633. * del_virtual_intf: remove the virtual interface determined by dev
  1634. */
  1635. int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
  1636. {
  1637. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  1638. #ifdef CONFIG_DEBUG_FS
  1639. mwifiex_dev_debugfs_remove(priv);
  1640. #endif
  1641. if (!netif_queue_stopped(priv->netdev))
  1642. netif_stop_queue(priv->netdev);
  1643. if (netif_carrier_ok(priv->netdev))
  1644. netif_carrier_off(priv->netdev);
  1645. if (wdev->netdev->reg_state == NETREG_REGISTERED)
  1646. unregister_netdevice(wdev->netdev);
  1647. if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
  1648. free_netdev(wdev->netdev);
  1649. /* Clear the priv in adapter */
  1650. priv->netdev = NULL;
  1651. priv->media_connected = false;
  1652. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  1653. return 0;
  1654. }
  1655. EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
  1656. /* station cfg80211 operations */
  1657. static struct cfg80211_ops mwifiex_cfg80211_ops = {
  1658. .add_virtual_intf = mwifiex_add_virtual_intf,
  1659. .del_virtual_intf = mwifiex_del_virtual_intf,
  1660. .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
  1661. .scan = mwifiex_cfg80211_scan,
  1662. .connect = mwifiex_cfg80211_connect,
  1663. .disconnect = mwifiex_cfg80211_disconnect,
  1664. .get_station = mwifiex_cfg80211_get_station,
  1665. .dump_station = mwifiex_cfg80211_dump_station,
  1666. .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
  1667. .join_ibss = mwifiex_cfg80211_join_ibss,
  1668. .leave_ibss = mwifiex_cfg80211_leave_ibss,
  1669. .add_key = mwifiex_cfg80211_add_key,
  1670. .del_key = mwifiex_cfg80211_del_key,
  1671. .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
  1672. .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
  1673. .set_default_key = mwifiex_cfg80211_set_default_key,
  1674. .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
  1675. .set_tx_power = mwifiex_cfg80211_set_tx_power,
  1676. .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
  1677. .start_ap = mwifiex_cfg80211_start_ap,
  1678. .stop_ap = mwifiex_cfg80211_stop_ap,
  1679. .change_beacon = mwifiex_cfg80211_change_beacon,
  1680. .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
  1681. .set_antenna = mwifiex_cfg80211_set_antenna,
  1682. };
  1683. /*
  1684. * This function registers the device with CFG802.11 subsystem.
  1685. *
  1686. * The function creates the wireless device/wiphy, populates it with
  1687. * default parameters and handler function pointers, and finally
  1688. * registers the device.
  1689. */
  1690. int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
  1691. {
  1692. int ret;
  1693. void *wdev_priv;
  1694. struct wiphy *wiphy;
  1695. struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
  1696. u8 *country_code;
  1697. /* create a new wiphy for use with cfg80211 */
  1698. wiphy = wiphy_new(&mwifiex_cfg80211_ops,
  1699. sizeof(struct mwifiex_adapter *));
  1700. if (!wiphy) {
  1701. dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
  1702. return -ENOMEM;
  1703. }
  1704. wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
  1705. wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
  1706. wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
  1707. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1708. BIT(NL80211_IFTYPE_ADHOC) |
  1709. BIT(NL80211_IFTYPE_AP);
  1710. wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
  1711. if (adapter->config_bands & BAND_A)
  1712. wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
  1713. else
  1714. wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  1715. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
  1716. wiphy->n_iface_combinations = 1;
  1717. /* Initialize cipher suits */
  1718. wiphy->cipher_suites = mwifiex_cipher_suites;
  1719. wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
  1720. memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
  1721. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1722. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  1723. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  1724. WIPHY_FLAG_CUSTOM_REGULATORY;
  1725. wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
  1726. wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  1727. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  1728. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  1729. wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
  1730. wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
  1731. wiphy->features = NL80211_FEATURE_HT_IBSS;
  1732. /* Reserve space for mwifiex specific private data for BSS */
  1733. wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
  1734. wiphy->reg_notifier = mwifiex_reg_notifier;
  1735. /* Set struct mwifiex_adapter pointer in wiphy_priv */
  1736. wdev_priv = wiphy_priv(wiphy);
  1737. *(unsigned long *)wdev_priv = (unsigned long)adapter;
  1738. set_wiphy_dev(wiphy, priv->adapter->dev);
  1739. ret = wiphy_register(wiphy);
  1740. if (ret < 0) {
  1741. dev_err(adapter->dev,
  1742. "%s: wiphy_register failed: %d\n", __func__, ret);
  1743. wiphy_free(wiphy);
  1744. return ret;
  1745. }
  1746. country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
  1747. if (country_code)
  1748. dev_info(adapter->dev,
  1749. "ignoring F/W country code %2.2s\n", country_code);
  1750. adapter->wiphy = wiphy;
  1751. return ret;
  1752. }