cfg80211.c 83 KB

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