cfg80211.c 85 KB

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