cfg80211.c 64 KB

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