cfg80211.c 77 KB

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