cfg80211.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419
  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. static void
  719. mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
  720. struct rate_info *rate)
  721. {
  722. struct mwifiex_adapter *adapter = priv->adapter;
  723. if (adapter->is_hw_11ac_capable) {
  724. /* bit[1-0]: 00=LG 01=HT 10=VHT */
  725. if (tx_htinfo & BIT(0)) {
  726. /* HT */
  727. rate->mcs = priv->tx_rate;
  728. rate->flags |= RATE_INFO_FLAGS_MCS;
  729. }
  730. if (tx_htinfo & BIT(1)) {
  731. /* VHT */
  732. rate->mcs = priv->tx_rate & 0x0F;
  733. rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
  734. }
  735. if (tx_htinfo & (BIT(1) | BIT(0))) {
  736. /* HT or VHT */
  737. switch (tx_htinfo & (BIT(3) | BIT(2))) {
  738. case 0:
  739. /* This will be 20MHz */
  740. break;
  741. case (BIT(2)):
  742. rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  743. break;
  744. case (BIT(3)):
  745. rate->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
  746. break;
  747. case (BIT(3) | BIT(2)):
  748. rate->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
  749. break;
  750. }
  751. if (tx_htinfo & BIT(4))
  752. rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
  753. if ((priv->tx_rate >> 4) == 1)
  754. rate->nss = 2;
  755. else
  756. rate->nss = 1;
  757. }
  758. } else {
  759. /*
  760. * Bit 0 in tx_htinfo indicates that current Tx rate
  761. * is 11n rate. Valid MCS index values for us are 0 to 15.
  762. */
  763. if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
  764. rate->mcs = priv->tx_rate;
  765. rate->flags |= RATE_INFO_FLAGS_MCS;
  766. if (tx_htinfo & BIT(1))
  767. rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  768. if (tx_htinfo & BIT(2))
  769. rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
  770. }
  771. }
  772. }
  773. /*
  774. * This function dumps the station information on a buffer.
  775. *
  776. * The following information are shown -
  777. * - Total bytes transmitted
  778. * - Total bytes received
  779. * - Total packets transmitted
  780. * - Total packets received
  781. * - Signal quality level
  782. * - Transmission rate
  783. */
  784. static int
  785. mwifiex_dump_station_info(struct mwifiex_private *priv,
  786. struct station_info *sinfo)
  787. {
  788. u32 rate;
  789. sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
  790. STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
  791. STATION_INFO_TX_BITRATE |
  792. STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  793. /* Get signal information from the firmware */
  794. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
  795. HostCmd_ACT_GEN_GET, 0, NULL)) {
  796. dev_err(priv->adapter->dev, "failed to get signal information\n");
  797. return -EFAULT;
  798. }
  799. if (mwifiex_drv_get_data_rate(priv, &rate)) {
  800. dev_err(priv->adapter->dev, "getting data rate\n");
  801. return -EFAULT;
  802. }
  803. /* Get DTIM period information from firmware */
  804. mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
  805. HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
  806. &priv->dtim_period);
  807. mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
  808. sinfo->signal_avg = priv->bcn_rssi_avg;
  809. sinfo->rx_bytes = priv->stats.rx_bytes;
  810. sinfo->tx_bytes = priv->stats.tx_bytes;
  811. sinfo->rx_packets = priv->stats.rx_packets;
  812. sinfo->tx_packets = priv->stats.tx_packets;
  813. sinfo->signal = priv->bcn_rssi_avg;
  814. /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
  815. sinfo->txrate.legacy = rate * 5;
  816. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  817. sinfo->filled |= STATION_INFO_BSS_PARAM;
  818. sinfo->bss_param.flags = 0;
  819. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  820. WLAN_CAPABILITY_SHORT_PREAMBLE)
  821. sinfo->bss_param.flags |=
  822. BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  823. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  824. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  825. sinfo->bss_param.flags |=
  826. BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  827. sinfo->bss_param.dtim_period = priv->dtim_period;
  828. sinfo->bss_param.beacon_interval =
  829. priv->curr_bss_params.bss_descriptor.beacon_period;
  830. }
  831. return 0;
  832. }
  833. /*
  834. * CFG802.11 operation handler to get station information.
  835. *
  836. * This function only works in connected mode, and dumps the
  837. * requested station information, if available.
  838. */
  839. static int
  840. mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  841. u8 *mac, struct station_info *sinfo)
  842. {
  843. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  844. if (!priv->media_connected)
  845. return -ENOENT;
  846. if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
  847. return -ENOENT;
  848. return mwifiex_dump_station_info(priv, sinfo);
  849. }
  850. /*
  851. * CFG802.11 operation handler to dump station information.
  852. */
  853. static int
  854. mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  855. int idx, u8 *mac, struct station_info *sinfo)
  856. {
  857. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  858. if (!priv->media_connected || idx)
  859. return -ENOENT;
  860. memcpy(mac, priv->cfg_bssid, ETH_ALEN);
  861. return mwifiex_dump_station_info(priv, sinfo);
  862. }
  863. /* Supported rates to be advertised to the cfg80211 */
  864. static struct ieee80211_rate mwifiex_rates[] = {
  865. {.bitrate = 10, .hw_value = 2, },
  866. {.bitrate = 20, .hw_value = 4, },
  867. {.bitrate = 55, .hw_value = 11, },
  868. {.bitrate = 110, .hw_value = 22, },
  869. {.bitrate = 60, .hw_value = 12, },
  870. {.bitrate = 90, .hw_value = 18, },
  871. {.bitrate = 120, .hw_value = 24, },
  872. {.bitrate = 180, .hw_value = 36, },
  873. {.bitrate = 240, .hw_value = 48, },
  874. {.bitrate = 360, .hw_value = 72, },
  875. {.bitrate = 480, .hw_value = 96, },
  876. {.bitrate = 540, .hw_value = 108, },
  877. };
  878. /* Channel definitions to be advertised to cfg80211 */
  879. static struct ieee80211_channel mwifiex_channels_2ghz[] = {
  880. {.center_freq = 2412, .hw_value = 1, },
  881. {.center_freq = 2417, .hw_value = 2, },
  882. {.center_freq = 2422, .hw_value = 3, },
  883. {.center_freq = 2427, .hw_value = 4, },
  884. {.center_freq = 2432, .hw_value = 5, },
  885. {.center_freq = 2437, .hw_value = 6, },
  886. {.center_freq = 2442, .hw_value = 7, },
  887. {.center_freq = 2447, .hw_value = 8, },
  888. {.center_freq = 2452, .hw_value = 9, },
  889. {.center_freq = 2457, .hw_value = 10, },
  890. {.center_freq = 2462, .hw_value = 11, },
  891. {.center_freq = 2467, .hw_value = 12, },
  892. {.center_freq = 2472, .hw_value = 13, },
  893. {.center_freq = 2484, .hw_value = 14, },
  894. };
  895. static struct ieee80211_supported_band mwifiex_band_2ghz = {
  896. .channels = mwifiex_channels_2ghz,
  897. .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
  898. .bitrates = mwifiex_rates,
  899. .n_bitrates = ARRAY_SIZE(mwifiex_rates),
  900. };
  901. static struct ieee80211_channel mwifiex_channels_5ghz[] = {
  902. {.center_freq = 5040, .hw_value = 8, },
  903. {.center_freq = 5060, .hw_value = 12, },
  904. {.center_freq = 5080, .hw_value = 16, },
  905. {.center_freq = 5170, .hw_value = 34, },
  906. {.center_freq = 5190, .hw_value = 38, },
  907. {.center_freq = 5210, .hw_value = 42, },
  908. {.center_freq = 5230, .hw_value = 46, },
  909. {.center_freq = 5180, .hw_value = 36, },
  910. {.center_freq = 5200, .hw_value = 40, },
  911. {.center_freq = 5220, .hw_value = 44, },
  912. {.center_freq = 5240, .hw_value = 48, },
  913. {.center_freq = 5260, .hw_value = 52, },
  914. {.center_freq = 5280, .hw_value = 56, },
  915. {.center_freq = 5300, .hw_value = 60, },
  916. {.center_freq = 5320, .hw_value = 64, },
  917. {.center_freq = 5500, .hw_value = 100, },
  918. {.center_freq = 5520, .hw_value = 104, },
  919. {.center_freq = 5540, .hw_value = 108, },
  920. {.center_freq = 5560, .hw_value = 112, },
  921. {.center_freq = 5580, .hw_value = 116, },
  922. {.center_freq = 5600, .hw_value = 120, },
  923. {.center_freq = 5620, .hw_value = 124, },
  924. {.center_freq = 5640, .hw_value = 128, },
  925. {.center_freq = 5660, .hw_value = 132, },
  926. {.center_freq = 5680, .hw_value = 136, },
  927. {.center_freq = 5700, .hw_value = 140, },
  928. {.center_freq = 5745, .hw_value = 149, },
  929. {.center_freq = 5765, .hw_value = 153, },
  930. {.center_freq = 5785, .hw_value = 157, },
  931. {.center_freq = 5805, .hw_value = 161, },
  932. {.center_freq = 5825, .hw_value = 165, },
  933. };
  934. static struct ieee80211_supported_band mwifiex_band_5ghz = {
  935. .channels = mwifiex_channels_5ghz,
  936. .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
  937. .bitrates = mwifiex_rates + 4,
  938. .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
  939. };
  940. /* Supported crypto cipher suits to be advertised to cfg80211 */
  941. static const u32 mwifiex_cipher_suites[] = {
  942. WLAN_CIPHER_SUITE_WEP40,
  943. WLAN_CIPHER_SUITE_WEP104,
  944. WLAN_CIPHER_SUITE_TKIP,
  945. WLAN_CIPHER_SUITE_CCMP,
  946. WLAN_CIPHER_SUITE_AES_CMAC,
  947. };
  948. /* Supported mgmt frame types to be advertised to cfg80211 */
  949. static const struct ieee80211_txrx_stypes
  950. mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  951. [NL80211_IFTYPE_STATION] = {
  952. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  953. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  954. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  955. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  956. },
  957. [NL80211_IFTYPE_AP] = {
  958. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  959. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  960. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  961. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  962. },
  963. [NL80211_IFTYPE_P2P_CLIENT] = {
  964. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  965. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  966. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  967. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  968. },
  969. [NL80211_IFTYPE_P2P_GO] = {
  970. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  971. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  972. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  973. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  974. },
  975. };
  976. /*
  977. * CFG802.11 operation handler for setting bit rates.
  978. *
  979. * Function configures data rates to firmware using bitrate mask
  980. * provided by cfg80211.
  981. */
  982. static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
  983. struct net_device *dev,
  984. const u8 *peer,
  985. const struct cfg80211_bitrate_mask *mask)
  986. {
  987. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  988. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  989. enum ieee80211_band band;
  990. if (!priv->media_connected) {
  991. dev_err(priv->adapter->dev,
  992. "Can not set Tx data rate in disconnected state\n");
  993. return -EINVAL;
  994. }
  995. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  996. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  997. /* Fill HR/DSSS rates. */
  998. if (band == IEEE80211_BAND_2GHZ)
  999. bitmap_rates[0] = mask->control[band].legacy & 0x000f;
  1000. /* Fill OFDM rates */
  1001. if (band == IEEE80211_BAND_2GHZ)
  1002. bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
  1003. else
  1004. bitmap_rates[1] = mask->control[band].legacy;
  1005. /* Fill MCS rates */
  1006. bitmap_rates[2] = mask->control[band].mcs[0];
  1007. if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  1008. bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
  1009. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
  1010. HostCmd_ACT_GEN_SET, 0, bitmap_rates);
  1011. }
  1012. /*
  1013. * CFG802.11 operation handler for connection quality monitoring.
  1014. *
  1015. * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
  1016. * events to FW.
  1017. */
  1018. static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1019. struct net_device *dev,
  1020. s32 rssi_thold, u32 rssi_hyst)
  1021. {
  1022. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1023. struct mwifiex_ds_misc_subsc_evt subsc_evt;
  1024. priv->cqm_rssi_thold = rssi_thold;
  1025. priv->cqm_rssi_hyst = rssi_hyst;
  1026. memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  1027. subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  1028. /* Subscribe/unsubscribe low and high rssi events */
  1029. if (rssi_thold && rssi_hyst) {
  1030. subsc_evt.action = HostCmd_ACT_BITWISE_SET;
  1031. subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
  1032. subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
  1033. subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
  1034. subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
  1035. return mwifiex_send_cmd_sync(priv,
  1036. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  1037. 0, 0, &subsc_evt);
  1038. } else {
  1039. subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
  1040. return mwifiex_send_cmd_sync(priv,
  1041. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  1042. 0, 0, &subsc_evt);
  1043. }
  1044. return 0;
  1045. }
  1046. /* cfg80211 operation handler for change_beacon.
  1047. * Function retrieves and sets modified management IEs to FW.
  1048. */
  1049. static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
  1050. struct net_device *dev,
  1051. struct cfg80211_beacon_data *data)
  1052. {
  1053. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1054. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
  1055. wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
  1056. return -EINVAL;
  1057. }
  1058. if (!priv->bss_started) {
  1059. wiphy_err(wiphy, "%s: bss not started\n", __func__);
  1060. return -EINVAL;
  1061. }
  1062. if (mwifiex_set_mgmt_ies(priv, data)) {
  1063. wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
  1064. return -EFAULT;
  1065. }
  1066. return 0;
  1067. }
  1068. static int
  1069. mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1070. {
  1071. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1072. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  1073. MWIFIEX_BSS_ROLE_ANY);
  1074. struct mwifiex_ds_ant_cfg ant_cfg;
  1075. if (!tx_ant || !rx_ant)
  1076. return -EOPNOTSUPP;
  1077. if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
  1078. /* Not a MIMO chip. User should provide specific antenna number
  1079. * for Tx/Rx path or enable all antennas for diversity
  1080. */
  1081. if (tx_ant != rx_ant)
  1082. return -EOPNOTSUPP;
  1083. if ((tx_ant & (tx_ant - 1)) &&
  1084. (tx_ant != BIT(adapter->number_of_antenna) - 1))
  1085. return -EOPNOTSUPP;
  1086. if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
  1087. (priv->adapter->number_of_antenna > 1)) {
  1088. tx_ant = RF_ANTENNA_AUTO;
  1089. rx_ant = RF_ANTENNA_AUTO;
  1090. }
  1091. }
  1092. ant_cfg.tx_ant = tx_ant;
  1093. ant_cfg.rx_ant = rx_ant;
  1094. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
  1095. HostCmd_ACT_GEN_SET, 0, &ant_cfg);
  1096. }
  1097. /* cfg80211 operation handler for stop ap.
  1098. * Function stops BSS running at uAP interface.
  1099. */
  1100. static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  1101. {
  1102. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1103. if (mwifiex_del_mgmt_ies(priv))
  1104. wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
  1105. priv->ap_11n_enabled = 0;
  1106. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
  1107. HostCmd_ACT_GEN_SET, 0, NULL)) {
  1108. wiphy_err(wiphy, "Failed to stop the BSS\n");
  1109. return -1;
  1110. }
  1111. return 0;
  1112. }
  1113. /* cfg80211 operation handler for start_ap.
  1114. * Function sets beacon period, DTIM period, SSID and security into
  1115. * AP config structure.
  1116. * AP is configured with these settings and BSS is started.
  1117. */
  1118. static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
  1119. struct net_device *dev,
  1120. struct cfg80211_ap_settings *params)
  1121. {
  1122. struct mwifiex_uap_bss_param *bss_cfg;
  1123. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1124. u8 config_bands = 0;
  1125. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
  1126. return -1;
  1127. if (mwifiex_set_mgmt_ies(priv, &params->beacon))
  1128. return -1;
  1129. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  1130. if (!bss_cfg)
  1131. return -ENOMEM;
  1132. mwifiex_set_sys_config_invalid_data(bss_cfg);
  1133. if (params->beacon_interval)
  1134. bss_cfg->beacon_period = params->beacon_interval;
  1135. if (params->dtim_period)
  1136. bss_cfg->dtim_period = params->dtim_period;
  1137. if (params->ssid && params->ssid_len) {
  1138. memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
  1139. bss_cfg->ssid.ssid_len = params->ssid_len;
  1140. }
  1141. switch (params->hidden_ssid) {
  1142. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  1143. bss_cfg->bcast_ssid_ctl = 1;
  1144. break;
  1145. case NL80211_HIDDEN_SSID_ZERO_LEN:
  1146. bss_cfg->bcast_ssid_ctl = 0;
  1147. break;
  1148. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  1149. /* firmware doesn't support this type of hidden SSID */
  1150. default:
  1151. kfree(bss_cfg);
  1152. return -EINVAL;
  1153. }
  1154. bss_cfg->channel = ieee80211_frequency_to_channel(
  1155. params->chandef.chan->center_freq);
  1156. /* Set appropriate bands */
  1157. if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
  1158. bss_cfg->band_cfg = BAND_CONFIG_BG;
  1159. config_bands = BAND_B | BAND_G;
  1160. if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
  1161. config_bands |= BAND_GN;
  1162. if (params->chandef.width > NL80211_CHAN_WIDTH_40)
  1163. config_bands |= BAND_GAC;
  1164. } else {
  1165. bss_cfg->band_cfg = BAND_CONFIG_A;
  1166. config_bands = BAND_A;
  1167. if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
  1168. config_bands |= BAND_AN;
  1169. if (params->chandef.width > NL80211_CHAN_WIDTH_40)
  1170. config_bands |= BAND_AAC;
  1171. }
  1172. if (!((config_bands | priv->adapter->fw_bands) &
  1173. ~priv->adapter->fw_bands))
  1174. priv->adapter->config_bands = config_bands;
  1175. mwifiex_set_uap_rates(bss_cfg, params);
  1176. mwifiex_send_domain_info_cmd_fw(wiphy);
  1177. if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
  1178. kfree(bss_cfg);
  1179. wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
  1180. return -1;
  1181. }
  1182. mwifiex_set_ht_params(priv, bss_cfg, params);
  1183. mwifiex_set_wmm_params(priv, bss_cfg, params);
  1184. if (params->inactivity_timeout > 0) {
  1185. /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
  1186. bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
  1187. bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
  1188. }
  1189. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
  1190. HostCmd_ACT_GEN_SET, 0, NULL)) {
  1191. wiphy_err(wiphy, "Failed to stop the BSS\n");
  1192. kfree(bss_cfg);
  1193. return -1;
  1194. }
  1195. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  1196. HostCmd_ACT_GEN_SET,
  1197. UAP_BSS_PARAMS_I, bss_cfg)) {
  1198. wiphy_err(wiphy, "Failed to set the SSID\n");
  1199. kfree(bss_cfg);
  1200. return -1;
  1201. }
  1202. kfree(bss_cfg);
  1203. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
  1204. HostCmd_ACT_GEN_SET, 0, NULL)) {
  1205. wiphy_err(wiphy, "Failed to start the BSS\n");
  1206. return -1;
  1207. }
  1208. if (priv->sec_info.wep_enabled)
  1209. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  1210. else
  1211. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  1212. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  1213. HostCmd_ACT_GEN_SET, 0,
  1214. &priv->curr_pkt_filter))
  1215. return -1;
  1216. return 0;
  1217. }
  1218. /*
  1219. * CFG802.11 operation handler for disconnection request.
  1220. *
  1221. * This function does not work when there is already a disconnection
  1222. * procedure going on.
  1223. */
  1224. static int
  1225. mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1226. u16 reason_code)
  1227. {
  1228. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1229. if (mwifiex_deauthenticate(priv, NULL))
  1230. return -EFAULT;
  1231. wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
  1232. " reason code %d\n", priv->cfg_bssid, reason_code);
  1233. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1234. return 0;
  1235. }
  1236. /*
  1237. * This function informs the CFG802.11 subsystem of a new IBSS.
  1238. *
  1239. * The following information are sent to the CFG802.11 subsystem
  1240. * to register the new IBSS. If we do not register the new IBSS,
  1241. * a kernel panic will result.
  1242. * - SSID
  1243. * - SSID length
  1244. * - BSSID
  1245. * - Channel
  1246. */
  1247. static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
  1248. {
  1249. struct ieee80211_channel *chan;
  1250. struct mwifiex_bss_info bss_info;
  1251. struct cfg80211_bss *bss;
  1252. int ie_len;
  1253. u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
  1254. enum ieee80211_band band;
  1255. if (mwifiex_get_bss_info(priv, &bss_info))
  1256. return -1;
  1257. ie_buf[0] = WLAN_EID_SSID;
  1258. ie_buf[1] = bss_info.ssid.ssid_len;
  1259. memcpy(&ie_buf[sizeof(struct ieee_types_header)],
  1260. &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
  1261. ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
  1262. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  1263. chan = __ieee80211_get_channel(priv->wdev->wiphy,
  1264. ieee80211_channel_to_frequency(bss_info.bss_chan,
  1265. band));
  1266. bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
  1267. bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
  1268. 0, ie_buf, ie_len, 0, GFP_KERNEL);
  1269. cfg80211_put_bss(priv->wdev->wiphy, bss);
  1270. memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
  1271. return 0;
  1272. }
  1273. /*
  1274. * This function connects with a BSS.
  1275. *
  1276. * This function handles both Infra and Ad-Hoc modes. It also performs
  1277. * validity checking on the provided parameters, disconnects from the
  1278. * current BSS (if any), sets up the association/scan parameters,
  1279. * including security settings, and performs specific SSID scan before
  1280. * trying to connect.
  1281. *
  1282. * For Infra mode, the function returns failure if the specified SSID
  1283. * is not found in scan table. However, for Ad-Hoc mode, it can create
  1284. * the IBSS if it does not exist. On successful completion in either case,
  1285. * the function notifies the CFG802.11 subsystem of the new BSS connection.
  1286. */
  1287. static int
  1288. mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
  1289. u8 *bssid, int mode, struct ieee80211_channel *channel,
  1290. struct cfg80211_connect_params *sme, bool privacy)
  1291. {
  1292. struct cfg80211_ssid req_ssid;
  1293. int ret, auth_type = 0;
  1294. struct cfg80211_bss *bss = NULL;
  1295. u8 is_scanning_required = 0;
  1296. memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
  1297. req_ssid.ssid_len = ssid_len;
  1298. if (ssid_len > IEEE80211_MAX_SSID_LEN) {
  1299. dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
  1300. return -EINVAL;
  1301. }
  1302. memcpy(req_ssid.ssid, ssid, ssid_len);
  1303. if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
  1304. dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
  1305. return -EINVAL;
  1306. }
  1307. /* disconnect before try to associate */
  1308. mwifiex_deauthenticate(priv, NULL);
  1309. /* As this is new association, clear locally stored
  1310. * keys and security related flags */
  1311. priv->sec_info.wpa_enabled = false;
  1312. priv->sec_info.wpa2_enabled = false;
  1313. priv->wep_key_curr_index = 0;
  1314. priv->sec_info.encryption_mode = 0;
  1315. priv->sec_info.is_authtype_auto = 0;
  1316. ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
  1317. if (mode == NL80211_IFTYPE_ADHOC) {
  1318. /* "privacy" is set only for ad-hoc mode */
  1319. if (privacy) {
  1320. /*
  1321. * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
  1322. * the firmware can find a matching network from the
  1323. * scan. The cfg80211 does not give us the encryption
  1324. * mode at this stage so just setting it to WEP here.
  1325. */
  1326. priv->sec_info.encryption_mode =
  1327. WLAN_CIPHER_SUITE_WEP104;
  1328. priv->sec_info.authentication_mode =
  1329. NL80211_AUTHTYPE_OPEN_SYSTEM;
  1330. }
  1331. goto done;
  1332. }
  1333. /* Now handle infra mode. "sme" is valid for infra mode only */
  1334. if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
  1335. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1336. priv->sec_info.is_authtype_auto = 1;
  1337. } else {
  1338. auth_type = sme->auth_type;
  1339. }
  1340. if (sme->crypto.n_ciphers_pairwise) {
  1341. priv->sec_info.encryption_mode =
  1342. sme->crypto.ciphers_pairwise[0];
  1343. priv->sec_info.authentication_mode = auth_type;
  1344. }
  1345. if (sme->crypto.cipher_group) {
  1346. priv->sec_info.encryption_mode = sme->crypto.cipher_group;
  1347. priv->sec_info.authentication_mode = auth_type;
  1348. }
  1349. if (sme->ie)
  1350. ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
  1351. if (sme->key) {
  1352. if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
  1353. dev_dbg(priv->adapter->dev,
  1354. "info: setting wep encryption"
  1355. " with key len %d\n", sme->key_len);
  1356. priv->wep_key_curr_index = sme->key_idx;
  1357. ret = mwifiex_set_encode(priv, NULL, sme->key,
  1358. sme->key_len, sme->key_idx,
  1359. NULL, 0);
  1360. }
  1361. }
  1362. done:
  1363. /*
  1364. * Scan entries are valid for some time (15 sec). So we can save one
  1365. * active scan time if we just try cfg80211_get_bss first. If it fails
  1366. * then request scan and cfg80211_get_bss() again for final output.
  1367. */
  1368. while (1) {
  1369. if (is_scanning_required) {
  1370. /* Do specific SSID scanning */
  1371. if (mwifiex_request_scan(priv, &req_ssid)) {
  1372. dev_err(priv->adapter->dev, "scan error\n");
  1373. return -EFAULT;
  1374. }
  1375. }
  1376. /* Find the BSS we want using available scan results */
  1377. if (mode == NL80211_IFTYPE_ADHOC)
  1378. bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
  1379. bssid, ssid, ssid_len,
  1380. WLAN_CAPABILITY_IBSS,
  1381. WLAN_CAPABILITY_IBSS);
  1382. else
  1383. bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
  1384. bssid, ssid, ssid_len,
  1385. WLAN_CAPABILITY_ESS,
  1386. WLAN_CAPABILITY_ESS);
  1387. if (!bss) {
  1388. if (is_scanning_required) {
  1389. dev_warn(priv->adapter->dev,
  1390. "assoc: requested bss not found in scan results\n");
  1391. break;
  1392. }
  1393. is_scanning_required = 1;
  1394. } else {
  1395. dev_dbg(priv->adapter->dev,
  1396. "info: trying to associate to '%s' bssid %pM\n",
  1397. (char *) req_ssid.ssid, bss->bssid);
  1398. memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
  1399. break;
  1400. }
  1401. }
  1402. ret = mwifiex_bss_start(priv, bss, &req_ssid);
  1403. if (ret)
  1404. return ret;
  1405. if (mode == NL80211_IFTYPE_ADHOC) {
  1406. /* Inform the BSS information to kernel, otherwise
  1407. * kernel will give a panic after successful assoc */
  1408. if (mwifiex_cfg80211_inform_ibss_bss(priv))
  1409. return -EFAULT;
  1410. }
  1411. return ret;
  1412. }
  1413. /*
  1414. * CFG802.11 operation handler for association request.
  1415. *
  1416. * This function does not work when the current mode is set to Ad-Hoc, or
  1417. * when there is already an association procedure going on. The given BSS
  1418. * information is used to associate.
  1419. */
  1420. static int
  1421. mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  1422. struct cfg80211_connect_params *sme)
  1423. {
  1424. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1425. int ret = 0;
  1426. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  1427. wiphy_err(wiphy, "received infra assoc request "
  1428. "when station is in ibss mode\n");
  1429. goto done;
  1430. }
  1431. if (priv->bss_mode == NL80211_IFTYPE_AP) {
  1432. wiphy_err(wiphy, "skip association request for AP interface\n");
  1433. goto done;
  1434. }
  1435. wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
  1436. (char *) sme->ssid, sme->bssid);
  1437. ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
  1438. priv->bss_mode, sme->channel, sme, 0);
  1439. done:
  1440. if (!ret) {
  1441. cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
  1442. NULL, 0, WLAN_STATUS_SUCCESS,
  1443. GFP_KERNEL);
  1444. dev_dbg(priv->adapter->dev,
  1445. "info: associated to bssid %pM successfully\n",
  1446. priv->cfg_bssid);
  1447. } else {
  1448. dev_dbg(priv->adapter->dev,
  1449. "info: association to bssid %pM failed\n",
  1450. priv->cfg_bssid);
  1451. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1452. if (ret > 0)
  1453. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  1454. NULL, 0, NULL, 0, ret,
  1455. GFP_KERNEL);
  1456. else
  1457. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  1458. NULL, 0, NULL, 0,
  1459. WLAN_STATUS_UNSPECIFIED_FAILURE,
  1460. GFP_KERNEL);
  1461. }
  1462. return 0;
  1463. }
  1464. /*
  1465. * This function sets following parameters for ibss network.
  1466. * - channel
  1467. * - start band
  1468. * - 11n flag
  1469. * - secondary channel offset
  1470. */
  1471. static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
  1472. struct cfg80211_ibss_params *params)
  1473. {
  1474. struct wiphy *wiphy = priv->wdev->wiphy;
  1475. struct mwifiex_adapter *adapter = priv->adapter;
  1476. int index = 0, i;
  1477. u8 config_bands = 0;
  1478. if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
  1479. if (!params->basic_rates) {
  1480. config_bands = BAND_B | BAND_G;
  1481. } else {
  1482. for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
  1483. /*
  1484. * Rates below 6 Mbps in the table are CCK
  1485. * rates; 802.11b and from 6 they are OFDM;
  1486. * 802.11G
  1487. */
  1488. if (mwifiex_rates[i].bitrate == 60) {
  1489. index = 1 << i;
  1490. break;
  1491. }
  1492. }
  1493. if (params->basic_rates < index) {
  1494. config_bands = BAND_B;
  1495. } else {
  1496. config_bands = BAND_G;
  1497. if (params->basic_rates % index)
  1498. config_bands |= BAND_B;
  1499. }
  1500. }
  1501. if (cfg80211_get_chandef_type(&params->chandef) !=
  1502. NL80211_CHAN_NO_HT)
  1503. config_bands |= BAND_G | BAND_GN;
  1504. } else {
  1505. if (cfg80211_get_chandef_type(&params->chandef) ==
  1506. NL80211_CHAN_NO_HT)
  1507. config_bands = BAND_A;
  1508. else
  1509. config_bands = BAND_AN | BAND_A;
  1510. }
  1511. if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
  1512. adapter->config_bands = config_bands;
  1513. adapter->adhoc_start_band = config_bands;
  1514. if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
  1515. adapter->adhoc_11n_enabled = true;
  1516. else
  1517. adapter->adhoc_11n_enabled = false;
  1518. }
  1519. adapter->sec_chan_offset =
  1520. mwifiex_chan_type_to_sec_chan_offset(
  1521. cfg80211_get_chandef_type(&params->chandef));
  1522. priv->adhoc_channel = ieee80211_frequency_to_channel(
  1523. params->chandef.chan->center_freq);
  1524. wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
  1525. config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
  1526. return 0;
  1527. }
  1528. /*
  1529. * CFG802.11 operation handler to join an IBSS.
  1530. *
  1531. * This function does not work in any mode other than Ad-Hoc, or if
  1532. * a join operation is already in progress.
  1533. */
  1534. static int
  1535. mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1536. struct cfg80211_ibss_params *params)
  1537. {
  1538. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1539. int ret = 0;
  1540. if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
  1541. wiphy_err(wiphy, "request to join ibss received "
  1542. "when station is not in ibss mode\n");
  1543. goto done;
  1544. }
  1545. wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
  1546. (char *) params->ssid, params->bssid);
  1547. mwifiex_set_ibss_params(priv, params);
  1548. ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
  1549. params->bssid, priv->bss_mode,
  1550. params->chandef.chan, NULL,
  1551. params->privacy);
  1552. done:
  1553. if (!ret) {
  1554. cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
  1555. dev_dbg(priv->adapter->dev,
  1556. "info: joined/created adhoc network with bssid"
  1557. " %pM successfully\n", priv->cfg_bssid);
  1558. } else {
  1559. dev_dbg(priv->adapter->dev,
  1560. "info: failed creating/joining adhoc network\n");
  1561. }
  1562. return ret;
  1563. }
  1564. /*
  1565. * CFG802.11 operation handler to leave an IBSS.
  1566. *
  1567. * This function does not work if a leave operation is
  1568. * already in progress.
  1569. */
  1570. static int
  1571. mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1572. {
  1573. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1574. wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
  1575. priv->cfg_bssid);
  1576. if (mwifiex_deauthenticate(priv, NULL))
  1577. return -EFAULT;
  1578. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1579. return 0;
  1580. }
  1581. /*
  1582. * CFG802.11 operation handler for scan request.
  1583. *
  1584. * This function issues a scan request to the firmware based upon
  1585. * the user specified scan configuration. On successfull completion,
  1586. * it also informs the results.
  1587. */
  1588. static int
  1589. mwifiex_cfg80211_scan(struct wiphy *wiphy,
  1590. struct cfg80211_scan_request *request)
  1591. {
  1592. struct net_device *dev = request->wdev->netdev;
  1593. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1594. int i, offset, ret;
  1595. struct ieee80211_channel *chan;
  1596. struct ieee_types_header *ie;
  1597. wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
  1598. if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  1599. atomic_read(&priv->wmm.tx_pkts_queued) >=
  1600. MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
  1601. dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
  1602. return -EBUSY;
  1603. }
  1604. if (priv->user_scan_cfg) {
  1605. dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
  1606. return -EBUSY;
  1607. }
  1608. priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
  1609. GFP_KERNEL);
  1610. if (!priv->user_scan_cfg)
  1611. return -ENOMEM;
  1612. priv->scan_request = request;
  1613. priv->user_scan_cfg->num_ssids = request->n_ssids;
  1614. priv->user_scan_cfg->ssid_list = request->ssids;
  1615. if (request->ie && request->ie_len) {
  1616. offset = 0;
  1617. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  1618. if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
  1619. continue;
  1620. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
  1621. ie = (struct ieee_types_header *)(request->ie + offset);
  1622. memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
  1623. offset += sizeof(*ie) + ie->len;
  1624. if (offset >= request->ie_len)
  1625. break;
  1626. }
  1627. }
  1628. for (i = 0; i < min_t(u32, request->n_channels,
  1629. MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
  1630. chan = request->channels[i];
  1631. priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
  1632. priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
  1633. if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  1634. priv->user_scan_cfg->chan_list[i].scan_type =
  1635. MWIFIEX_SCAN_TYPE_PASSIVE;
  1636. else
  1637. priv->user_scan_cfg->chan_list[i].scan_type =
  1638. MWIFIEX_SCAN_TYPE_ACTIVE;
  1639. priv->user_scan_cfg->chan_list[i].scan_time = 0;
  1640. }
  1641. ret = mwifiex_scan_networks(priv, priv->user_scan_cfg);
  1642. if (ret) {
  1643. dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
  1644. priv->scan_request = NULL;
  1645. kfree(priv->user_scan_cfg);
  1646. priv->user_scan_cfg = NULL;
  1647. return ret;
  1648. }
  1649. if (request->ie && request->ie_len) {
  1650. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  1651. if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
  1652. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
  1653. memset(&priv->vs_ie[i].ie, 0,
  1654. MWIFIEX_MAX_VSIE_LEN);
  1655. }
  1656. }
  1657. }
  1658. return 0;
  1659. }
  1660. static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
  1661. struct mwifiex_private *priv)
  1662. {
  1663. struct mwifiex_adapter *adapter = priv->adapter;
  1664. u32 vht_cap = 0, cap = adapter->hw_dot_11ac_dev_cap;
  1665. vht_info->vht_supported = true;
  1666. switch (GET_VHTCAP_MAXMPDULEN(cap)) {
  1667. case 0x00:
  1668. vht_cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  1669. break;
  1670. case 0x01:
  1671. vht_cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  1672. break;
  1673. case 0x10:
  1674. vht_cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  1675. break;
  1676. default:
  1677. dev_err(adapter->dev, "unsupported MAX MPDU len\n");
  1678. break;
  1679. }
  1680. if (ISSUPP_11ACVHTHTCVHT(cap))
  1681. vht_cap |= IEEE80211_VHT_CAP_HTC_VHT;
  1682. if (ISSUPP_11ACVHTTXOPPS(cap))
  1683. vht_cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
  1684. if (ISSUPP_11ACMURXBEAMFORMEE(cap))
  1685. vht_cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
  1686. if (ISSUPP_11ACMUTXBEAMFORMEE(cap))
  1687. vht_cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  1688. if (ISSUPP_11ACSUBEAMFORMER(cap))
  1689. vht_cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
  1690. if (ISSUPP_11ACSUBEAMFORMEE(cap))
  1691. vht_cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
  1692. if (ISSUPP_11ACRXSTBC(cap))
  1693. vht_cap |= IEEE80211_VHT_CAP_RXSTBC_1;
  1694. if (ISSUPP_11ACTXSTBC(cap))
  1695. vht_cap |= IEEE80211_VHT_CAP_TXSTBC;
  1696. if (ISSUPP_11ACSGI160(cap))
  1697. vht_cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
  1698. if (ISSUPP_11ACSGI80(cap))
  1699. vht_cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
  1700. if (ISSUPP_11ACLDPC(cap))
  1701. vht_cap |= IEEE80211_VHT_CAP_RXLDPC;
  1702. if (ISSUPP_11ACBW8080(cap))
  1703. vht_cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  1704. if (ISSUPP_11ACBW160(cap))
  1705. vht_cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  1706. vht_info->cap = vht_cap;
  1707. /* Update MCS support for VHT */
  1708. vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
  1709. adapter->hw_dot_11ac_mcs_support & 0xFFFF);
  1710. vht_info->vht_mcs.rx_highest = 0;
  1711. vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
  1712. adapter->hw_dot_11ac_mcs_support >> 16);
  1713. vht_info->vht_mcs.tx_highest = 0;
  1714. }
  1715. /*
  1716. * This function sets up the CFG802.11 specific HT capability fields
  1717. * with default values.
  1718. *
  1719. * The following default values are set -
  1720. * - HT Supported = True
  1721. * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
  1722. * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
  1723. * - HT Capabilities supported by firmware
  1724. * - MCS information, Rx mask = 0xff
  1725. * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
  1726. */
  1727. static void
  1728. mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
  1729. struct mwifiex_private *priv)
  1730. {
  1731. int rx_mcs_supp;
  1732. struct ieee80211_mcs_info mcs_set;
  1733. u8 *mcs = (u8 *)&mcs_set;
  1734. struct mwifiex_adapter *adapter = priv->adapter;
  1735. ht_info->ht_supported = true;
  1736. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  1737. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1738. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  1739. /* Fill HT capability information */
  1740. if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  1741. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1742. else
  1743. ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1744. if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
  1745. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  1746. else
  1747. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
  1748. if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
  1749. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  1750. else
  1751. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
  1752. if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
  1753. ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
  1754. else
  1755. ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  1756. if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
  1757. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  1758. else
  1759. ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
  1760. if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
  1761. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  1762. else
  1763. ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
  1764. if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
  1765. ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
  1766. else
  1767. ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
  1768. if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
  1769. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  1770. else
  1771. ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
  1772. ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  1773. ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
  1774. rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
  1775. /* Set MCS for 1x1 */
  1776. memset(mcs, 0xff, rx_mcs_supp);
  1777. /* Clear all the other values */
  1778. memset(&mcs[rx_mcs_supp], 0,
  1779. sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
  1780. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  1781. ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  1782. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  1783. SETHT_MCS32(mcs_set.rx_mask);
  1784. memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
  1785. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  1786. }
  1787. /*
  1788. * create a new virtual interface with the given name
  1789. */
  1790. struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
  1791. const char *name,
  1792. enum nl80211_iftype type,
  1793. u32 *flags,
  1794. struct vif_params *params)
  1795. {
  1796. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1797. struct mwifiex_private *priv;
  1798. struct net_device *dev;
  1799. void *mdev_priv;
  1800. struct wireless_dev *wdev;
  1801. if (!adapter)
  1802. return ERR_PTR(-EFAULT);
  1803. switch (type) {
  1804. case NL80211_IFTYPE_UNSPECIFIED:
  1805. case NL80211_IFTYPE_STATION:
  1806. case NL80211_IFTYPE_ADHOC:
  1807. priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
  1808. if (priv->bss_mode) {
  1809. wiphy_err(wiphy,
  1810. "cannot create multiple sta/adhoc ifaces\n");
  1811. return ERR_PTR(-EINVAL);
  1812. }
  1813. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1814. if (!wdev)
  1815. return ERR_PTR(-ENOMEM);
  1816. wdev->wiphy = wiphy;
  1817. priv->wdev = wdev;
  1818. wdev->iftype = NL80211_IFTYPE_STATION;
  1819. if (type == NL80211_IFTYPE_UNSPECIFIED)
  1820. priv->bss_mode = NL80211_IFTYPE_STATION;
  1821. else
  1822. priv->bss_mode = type;
  1823. priv->bss_type = MWIFIEX_BSS_TYPE_STA;
  1824. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  1825. priv->bss_priority = 0;
  1826. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  1827. priv->bss_num = 0;
  1828. break;
  1829. case NL80211_IFTYPE_AP:
  1830. priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
  1831. if (priv->bss_mode) {
  1832. wiphy_err(wiphy, "Can't create multiple AP interfaces");
  1833. return ERR_PTR(-EINVAL);
  1834. }
  1835. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1836. if (!wdev)
  1837. return ERR_PTR(-ENOMEM);
  1838. priv->wdev = wdev;
  1839. wdev->wiphy = wiphy;
  1840. wdev->iftype = NL80211_IFTYPE_AP;
  1841. priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
  1842. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  1843. priv->bss_priority = 0;
  1844. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  1845. priv->bss_started = 0;
  1846. priv->bss_num = 0;
  1847. priv->bss_mode = type;
  1848. break;
  1849. case NL80211_IFTYPE_P2P_CLIENT:
  1850. priv = adapter->priv[MWIFIEX_BSS_TYPE_P2P];
  1851. if (priv->bss_mode) {
  1852. wiphy_err(wiphy, "Can't create multiple P2P ifaces");
  1853. return ERR_PTR(-EINVAL);
  1854. }
  1855. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1856. if (!wdev)
  1857. return ERR_PTR(-ENOMEM);
  1858. priv->wdev = wdev;
  1859. wdev->wiphy = wiphy;
  1860. /* At start-up, wpa_supplicant tries to change the interface
  1861. * to NL80211_IFTYPE_STATION if it is not managed mode.
  1862. * So, we initialize it to STA mode.
  1863. */
  1864. wdev->iftype = NL80211_IFTYPE_STATION;
  1865. priv->bss_mode = NL80211_IFTYPE_STATION;
  1866. /* Setting bss_type to P2P tells firmware that this interface
  1867. * is receiving P2P peers found during find phase and doing
  1868. * action frame handshake.
  1869. */
  1870. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  1871. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  1872. priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
  1873. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  1874. priv->bss_started = 0;
  1875. priv->bss_num = 0;
  1876. break;
  1877. default:
  1878. wiphy_err(wiphy, "type not supported\n");
  1879. return ERR_PTR(-EINVAL);
  1880. }
  1881. dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
  1882. ether_setup, IEEE80211_NUM_ACS, 1);
  1883. if (!dev) {
  1884. wiphy_err(wiphy, "no memory available for netdevice\n");
  1885. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  1886. return ERR_PTR(-ENOMEM);
  1887. }
  1888. mwifiex_init_priv_params(priv, dev);
  1889. priv->netdev = dev;
  1890. mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
  1891. if (adapter->is_hw_11ac_capable)
  1892. mwifiex_setup_vht_caps(
  1893. &wiphy->bands[IEEE80211_BAND_2GHZ]->vht_cap, priv);
  1894. if (adapter->config_bands & BAND_A)
  1895. mwifiex_setup_ht_caps(
  1896. &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
  1897. if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
  1898. mwifiex_setup_vht_caps(
  1899. &wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap, priv);
  1900. dev_net_set(dev, wiphy_net(wiphy));
  1901. dev->ieee80211_ptr = priv->wdev;
  1902. dev->ieee80211_ptr->iftype = priv->bss_mode;
  1903. memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
  1904. SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
  1905. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  1906. dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
  1907. dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
  1908. mdev_priv = netdev_priv(dev);
  1909. *((unsigned long *) mdev_priv) = (unsigned long) priv;
  1910. SET_NETDEV_DEV(dev, adapter->dev);
  1911. /* Register network device */
  1912. if (register_netdevice(dev)) {
  1913. wiphy_err(wiphy, "cannot register virtual network device\n");
  1914. free_netdev(dev);
  1915. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  1916. return ERR_PTR(-EFAULT);
  1917. }
  1918. sema_init(&priv->async_sem, 1);
  1919. dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
  1920. #ifdef CONFIG_DEBUG_FS
  1921. mwifiex_dev_debugfs_init(priv);
  1922. #endif
  1923. return wdev;
  1924. }
  1925. EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
  1926. /*
  1927. * del_virtual_intf: remove the virtual interface determined by dev
  1928. */
  1929. int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
  1930. {
  1931. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  1932. #ifdef CONFIG_DEBUG_FS
  1933. mwifiex_dev_debugfs_remove(priv);
  1934. #endif
  1935. mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
  1936. if (netif_carrier_ok(priv->netdev))
  1937. netif_carrier_off(priv->netdev);
  1938. if (wdev->netdev->reg_state == NETREG_REGISTERED)
  1939. unregister_netdevice(wdev->netdev);
  1940. if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
  1941. free_netdev(wdev->netdev);
  1942. /* Clear the priv in adapter */
  1943. priv->netdev = NULL;
  1944. priv->media_connected = false;
  1945. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  1946. return 0;
  1947. }
  1948. EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
  1949. /* station cfg80211 operations */
  1950. static struct cfg80211_ops mwifiex_cfg80211_ops = {
  1951. .add_virtual_intf = mwifiex_add_virtual_intf,
  1952. .del_virtual_intf = mwifiex_del_virtual_intf,
  1953. .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
  1954. .scan = mwifiex_cfg80211_scan,
  1955. .connect = mwifiex_cfg80211_connect,
  1956. .disconnect = mwifiex_cfg80211_disconnect,
  1957. .get_station = mwifiex_cfg80211_get_station,
  1958. .dump_station = mwifiex_cfg80211_dump_station,
  1959. .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
  1960. .join_ibss = mwifiex_cfg80211_join_ibss,
  1961. .leave_ibss = mwifiex_cfg80211_leave_ibss,
  1962. .add_key = mwifiex_cfg80211_add_key,
  1963. .del_key = mwifiex_cfg80211_del_key,
  1964. .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
  1965. .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
  1966. .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
  1967. .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
  1968. .set_default_key = mwifiex_cfg80211_set_default_key,
  1969. .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
  1970. .set_tx_power = mwifiex_cfg80211_set_tx_power,
  1971. .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
  1972. .start_ap = mwifiex_cfg80211_start_ap,
  1973. .stop_ap = mwifiex_cfg80211_stop_ap,
  1974. .change_beacon = mwifiex_cfg80211_change_beacon,
  1975. .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
  1976. .set_antenna = mwifiex_cfg80211_set_antenna,
  1977. };
  1978. /*
  1979. * This function registers the device with CFG802.11 subsystem.
  1980. *
  1981. * The function creates the wireless device/wiphy, populates it with
  1982. * default parameters and handler function pointers, and finally
  1983. * registers the device.
  1984. */
  1985. int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
  1986. {
  1987. int ret;
  1988. void *wdev_priv;
  1989. struct wiphy *wiphy;
  1990. struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
  1991. u8 *country_code;
  1992. /* create a new wiphy for use with cfg80211 */
  1993. wiphy = wiphy_new(&mwifiex_cfg80211_ops,
  1994. sizeof(struct mwifiex_adapter *));
  1995. if (!wiphy) {
  1996. dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
  1997. return -ENOMEM;
  1998. }
  1999. wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
  2000. wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
  2001. wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
  2002. wiphy->max_remain_on_channel_duration = 5000;
  2003. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  2004. BIT(NL80211_IFTYPE_ADHOC) |
  2005. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  2006. BIT(NL80211_IFTYPE_P2P_GO) |
  2007. BIT(NL80211_IFTYPE_AP);
  2008. wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
  2009. if (adapter->config_bands & BAND_A)
  2010. wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
  2011. else
  2012. wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  2013. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
  2014. wiphy->n_iface_combinations = 1;
  2015. /* Initialize cipher suits */
  2016. wiphy->cipher_suites = mwifiex_cipher_suites;
  2017. wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
  2018. memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
  2019. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  2020. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  2021. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  2022. WIPHY_FLAG_AP_UAPSD |
  2023. WIPHY_FLAG_CUSTOM_REGULATORY |
  2024. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  2025. wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
  2026. wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  2027. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  2028. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  2029. wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
  2030. wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
  2031. wiphy->features |= NL80211_FEATURE_HT_IBSS |
  2032. NL80211_FEATURE_INACTIVITY_TIMER |
  2033. NL80211_FEATURE_LOW_PRIORITY_SCAN;
  2034. /* Reserve space for mwifiex specific private data for BSS */
  2035. wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
  2036. wiphy->reg_notifier = mwifiex_reg_notifier;
  2037. /* Set struct mwifiex_adapter pointer in wiphy_priv */
  2038. wdev_priv = wiphy_priv(wiphy);
  2039. *(unsigned long *)wdev_priv = (unsigned long)adapter;
  2040. set_wiphy_dev(wiphy, priv->adapter->dev);
  2041. ret = wiphy_register(wiphy);
  2042. if (ret < 0) {
  2043. dev_err(adapter->dev,
  2044. "%s: wiphy_register failed: %d\n", __func__, ret);
  2045. wiphy_free(wiphy);
  2046. return ret;
  2047. }
  2048. country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
  2049. if (country_code)
  2050. dev_info(adapter->dev,
  2051. "ignoring F/W country code %2.2s\n", country_code);
  2052. adapter->wiphy = wiphy;
  2053. return ret;
  2054. }