cfg80211.c 76 KB

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