cfg80211.c 72 KB

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