dhd_bandsteer.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Band Steering logic
  3. *
  4. * Feature by which dualband capable PEERs will be
  5. * forced move on 5GHz interface
  6. *
  7. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  8. *
  9. * Copyright (C) 1999-2020, Broadcom Corporation
  10. *
  11. * Unless you and Broadcom execute a separate written software license
  12. * agreement governing use of this software, this software is licensed to you
  13. * under the terms of the GNU General Public License version 2 (the "GPL"),
  14. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  15. * following added to such license:
  16. *
  17. * As a special exception, the copyright holders of this software give you
  18. * permission to link this software with independent modules, and to copy and
  19. * distribute the resulting executable under terms of your choice, provided that
  20. * you also meet, for each linked independent module, the terms and conditions of
  21. * the license of that module. An independent module is a module which is not
  22. * derived from this software. The special exception does not apply to any
  23. * modifications of the software.
  24. *
  25. * Notwithstanding the above, under no circumstances may you combine this
  26. * software in any way with any other Broadcom software provided under a license
  27. * other than the GPL, without Broadcom's express prior written consent.
  28. *
  29. * <<Broadcom-WL-IPTag/Open:>>
  30. *
  31. * $ Copyright Cypress Semiconductor $
  32. *
  33. * $Id: dhd_bandsteer.c 724689 2020-03-04 10:04:03Z $
  34. */
  35. #include <typedefs.h>
  36. #include <linuxver.h>
  37. #include <osl.h>
  38. #include <linux/kernel.h>
  39. #include <linux/time.h>
  40. #include <bcmutils.h>
  41. #include <net/cfg80211.h>
  42. #include <net/rtnetlink.h>
  43. #include <wl_cfg80211.h>
  44. #include <wl_android.h>
  45. #include <wldev_common.h>
  46. #include <dhd_linux_wq.h>
  47. #include <dhd_cfg80211.h>
  48. #include <dhd_bandsteer.h>
  49. #include <dhd_dbg.h>
  50. /* defines */
  51. /* BANDSTEER STATE MACHINE STATES */
  52. #define DHD_BANDSTEER_START 0x0001
  53. #define DHD_BANDSTEER_WNM_FRAME_SEND 0x0002
  54. #define DHD_BANDSTEER_WNM_FRAME_RETRY 0x0004
  55. #define DHD_BANDSTEER_WNM_FRAME_SENT 0x0008
  56. #define DHD_BANDSTEER_TRIAL_DONE 0x0080
  57. #define DHD_BANDSTEER_ON_PROCESS_MASK (DHD_BANDSTEER_START | DHD_BANDSTEER_WNM_FRAME_SEND \
  58. | DHD_BANDSTEER_WNM_FRAME_RETRY | DHD_BANDSTEER_TRIAL_DONE)
  59. #define DHD_BANDSTEER_WNM_FRAME_MAXRETRY 3
  60. #define DHD_BANDSTEER_WNM_FRAME_DELAY 1000
  61. #define DHD_BANDSTEER_WNM_FRAME_START_DELAY 10
  62. #define DHD_BANDSTEER_WNM_FRAME_RESPONSE_DWELL 40
  63. #define MAX_NUM_OF_ASSOCLIST 64
  64. #define DHD_BANDSTEER_MAXIFACES 2
  65. #define CHANNEL_IS_5G(channel) (((channel >= 36) && (channel <= 165)) ? \
  66. true : false)
  67. /* ********************** Function declaration *********************** */
  68. static s32
  69. dhd_bandsteer_addmac_to_monitorlist(dhd_bandsteer_context_t *dhd_bandsteer_cntx, uint8 *mac_addr);
  70. static s32
  71. dhd_bandsteer_remove_mac_from_list(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac, int all);
  72. static dhd_bandsteer_mac_entry_t*
  73. dhd_bandsteer_look_for_match(dhd_bandsteer_context_t *dhd_bandsteer_cntx, uint8 *mac_addr);
  74. static s32
  75. dhd_bandsteer_tx_wnm_actframe(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac);
  76. static void
  77. dhd_bandsteer_add_to_black_list(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac);
  78. extern int
  79. wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist);
  80. /* ********************** Function declartion ends ****************** */
  81. static void
  82. dhd_bandsteer_add_timer(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac, unsigned long msec)
  83. {
  84. timer_expires(&dhd_bandsteer_mac->dhd_bandsteer_timer) =
  85. jiffies + msecs_to_jiffies(msec);
  86. add_timer(&dhd_bandsteer_mac->dhd_bandsteer_timer);
  87. }
  88. static void
  89. dhd_bandsteer_delete_timer(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac)
  90. {
  91. del_timer(&dhd_bandsteer_mac->dhd_bandsteer_timer);
  92. }
  93. /*
  94. * Idea used to call same callback everytime you conifigure timer
  95. * based on the status of the mac entry next step will be taken
  96. */
  97. static void
  98. dhd_bandsteer_state_machine(ulong arg)
  99. {
  100. dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac = (dhd_bandsteer_mac_entry_t *)arg;
  101. if (dhd_bandsteer_mac == NULL) {
  102. DHD_ERROR(("%s: dhd_bandsteer_mac is null\n", __FUNCTION__));
  103. return;
  104. }
  105. DHD_TRACE(("%s: Peer STA BandSteer status 0x%x", __FUNCTION__,
  106. dhd_bandsteer_mac->dhd_bandsteer_status));
  107. switch (dhd_bandsteer_mac->dhd_bandsteer_status) {
  108. case DHD_BANDSTEER_START:
  109. case DHD_BANDSTEER_WNM_FRAME_RETRY:
  110. dhd_bandsteer_mac->dhd_bandsteer_status = DHD_BANDSTEER_WNM_FRAME_SEND;
  111. dhd_bandsteer_schedule_work_on_timeout(dhd_bandsteer_mac);
  112. break;
  113. case DHD_BANDSTEER_WNM_FRAME_SEND:
  114. dhd_bandsteer_tx_wnm_actframe(dhd_bandsteer_mac);
  115. if (dhd_bandsteer_mac->wnm_frame_counter < DHD_BANDSTEER_WNM_FRAME_MAXRETRY) {
  116. /* Sending out WNM action frame as soon as assoc indication recieved */
  117. dhd_bandsteer_mac->dhd_bandsteer_status = DHD_BANDSTEER_WNM_FRAME_RETRY;
  118. }
  119. else {
  120. dhd_bandsteer_mac->dhd_bandsteer_status = DHD_BANDSTEER_TRIAL_DONE;
  121. }
  122. break;
  123. case DHD_BANDSTEER_TRIAL_DONE:
  124. dhd_bandsteer_remove_mac_from_list(dhd_bandsteer_mac, 0);
  125. break;
  126. }
  127. return;
  128. }
  129. void
  130. dhd_bandsteer_workqueue_wrapper(void *handle, void *event_info, u8 event)
  131. {
  132. dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac = (dhd_bandsteer_mac_entry_t *)event_info;
  133. if (event != DHD_WQ_WORK_BANDSTEER_STEP_MOVE) {
  134. DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
  135. return;
  136. }
  137. dhd_bandsteer_state_machine((ulong)dhd_bandsteer_mac);
  138. }
  139. /*
  140. * This API create and initilize an entry into list which need to be processed later
  141. */
  142. static s32
  143. dhd_bandsteer_addmac_to_monitorlist(dhd_bandsteer_context_t *dhd_bandsteer_cntx, uint8 *mac_addr)
  144. {
  145. dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac;
  146. dhd_bandsteer_mac = kzalloc(sizeof(dhd_bandsteer_mac_entry_t), GFP_KERNEL);
  147. if (unlikely(!dhd_bandsteer_mac)) {
  148. DHD_ERROR(("%s: alloc failed\n", __FUNCTION__));
  149. return BCME_NOMEM;
  150. }
  151. INIT_LIST_HEAD(&dhd_bandsteer_mac->list);
  152. /* pointer dhd_bandsteer_cntx for future use */
  153. dhd_bandsteer_mac->dhd_bandsteer_cntx = dhd_bandsteer_cntx;
  154. dhd_bandsteer_mac->dhd_bandsteer_status = DHD_BANDSTEER_START;
  155. memcpy(&dhd_bandsteer_mac->mac_addr.octet, mac_addr, ETHER_ADDR_LEN);
  156. /* Configure timer for 20 Sec */
  157. init_timer_compat(&dhd_bandsteer_mac->dhd_bandsteer_timer, dhd_bandsteer_state_machine,
  158. dhd_bandsteer_mac);
  159. dhd_bandsteer_mac->wnm_frame_counter = 0;
  160. /* Add new entry into the list */
  161. list_add_tail(&dhd_bandsteer_mac->list,
  162. &dhd_bandsteer_cntx->dhd_bandsteer_monitor_list);
  163. DHD_TRACE(("%s: " MACDBG " added into list \n", __FUNCTION__,
  164. MAC2STRDBG(dhd_bandsteer_mac->mac_addr.octet)));
  165. /* This can be tweaked more */
  166. dhd_bandsteer_add_timer(dhd_bandsteer_mac, DHD_BANDSTEER_WNM_FRAME_START_DELAY);
  167. return BCME_OK;
  168. }
  169. /*
  170. * This function removes one or all mac entry from the list
  171. */
  172. static s32
  173. dhd_bandsteer_remove_mac_from_list(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac, int all)
  174. {
  175. dhd_bandsteer_context_t *dhd_bandsteer_cntx;
  176. dhd_bandsteer_mac_entry_t *curr, *next;
  177. DHD_INFO(("%s: entered \n", __FUNCTION__));
  178. /* TODO:probably these sanity lines can be removed */
  179. if (dhd_bandsteer_mac == NULL) {
  180. DHD_ERROR(("%s: dhd_bandsteer_mac is NULL\n", __FUNCTION__));
  181. return BCME_ERROR;
  182. }
  183. dhd_bandsteer_cntx = dhd_bandsteer_mac->dhd_bandsteer_cntx;
  184. list_for_each_entry_safe(curr, next,
  185. &dhd_bandsteer_cntx->dhd_bandsteer_monitor_list, list) {
  186. if (curr == NULL) {
  187. DHD_ERROR(("%s: Invalid MAC\n", __FUNCTION__));
  188. break;
  189. }
  190. if ((curr == dhd_bandsteer_mac) || all) {
  191. DHD_ERROR(("%s: " MACDBG " deleted from list \n", __FUNCTION__,
  192. MAC2STRDBG(dhd_bandsteer_mac->mac_addr.octet)));
  193. list_del(&curr->list);
  194. dhd_bandsteer_delete_timer(curr);
  195. kfree(curr);
  196. if (!all)
  197. break;
  198. }
  199. }
  200. return BCME_OK;
  201. }
  202. /*
  203. * Logic to find corresponding node in list based given mac address
  204. * Returns null if entry not seen
  205. */
  206. static dhd_bandsteer_mac_entry_t*
  207. dhd_bandsteer_look_for_match(dhd_bandsteer_context_t *dhd_bandsteer_cntx, uint8 *mac_addr)
  208. {
  209. dhd_bandsteer_mac_entry_t *curr = NULL, *next = NULL;
  210. list_for_each_entry_safe(curr, next,
  211. &dhd_bandsteer_cntx->dhd_bandsteer_monitor_list, list) {
  212. if (memcmp(&curr->mac_addr.octet, mac_addr, ETHER_ADDR_LEN) == 0) {
  213. return curr;
  214. }
  215. }
  216. return NULL;
  217. }
  218. /*
  219. * This API will send wnm action frame also configure timeout timer
  220. */
  221. static s32
  222. dhd_bandsteer_tx_wnm_actframe(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac)
  223. {
  224. dhd_bandsteer_context_t *dhd_bandsteer_cntx = dhd_bandsteer_mac->dhd_bandsteer_cntx;
  225. wl_action_frame_t *action_frame = NULL;
  226. wl_af_params_t *af_params = NULL;
  227. char *smbuf = NULL;
  228. int error = BCME_ERROR;
  229. uint8 *bp;
  230. dhd_bandsteer_iface_info_t *if_info_5g, *if_info_2g;
  231. if_info_5g = &dhd_bandsteer_cntx->bsd_ifaces[dhd_bandsteer_cntx->ifidx_5g];
  232. if_info_2g = &dhd_bandsteer_cntx->bsd_ifaces[!dhd_bandsteer_cntx->ifidx_5g];
  233. smbuf = kzalloc(WLC_IOCTL_MAXLEN, GFP_KERNEL);
  234. if (smbuf == NULL) {
  235. DHD_ERROR(("%s: failed to allocated memory %d bytes\n", __FUNCTION__,
  236. WLC_IOCTL_MAXLEN));
  237. goto send_action_frame_out;
  238. }
  239. af_params = (wl_af_params_t *) kzalloc(WL_WIFI_AF_PARAMS_SIZE, GFP_KERNEL);
  240. if (af_params == NULL) {
  241. DHD_ERROR(("%s: unable to allocate frame\n", __FUNCTION__));
  242. goto send_action_frame_out;
  243. }
  244. af_params->channel = if_info_2g->channel;
  245. af_params->dwell_time = DHD_BANDSTEER_WNM_FRAME_RESPONSE_DWELL;
  246. memcpy(&af_params->BSSID, &dhd_bandsteer_mac->mac_addr.octet, ETHER_ADDR_LEN);
  247. action_frame = &af_params->action_frame;
  248. action_frame->packetId = 0;
  249. memcpy(&action_frame->da, &dhd_bandsteer_mac->mac_addr.octet, ETHER_ADDR_LEN);
  250. dhd_bandsteer_mac->wnm_frame_counter++;
  251. bp = (uint8 *)action_frame->data;
  252. *bp++ = 0xa; /* Category */
  253. *bp++ = 0x7; /* Action ID */
  254. *bp++ = dhd_bandsteer_mac->wnm_frame_counter; /* Dialog Token */
  255. *bp++ = 0x1; /* Request mode */
  256. *bp++ = 0x0; /* disassociation timer has two bytes */
  257. *bp++ = 0x0;
  258. *bp++ = 0x0; /* Validity interval */
  259. *bp++ = 0x34; /* Element ID */
  260. *bp++ = 0xd; /* Len */
  261. memcpy(bp, if_info_5g->macaddr.octet, ETHER_ADDR_LEN);
  262. bp += ETHER_ADDR_LEN;
  263. bp +=4; /* Skip BSSID info 4 bytes in size */
  264. *bp++ = 0x7d; /* Operating class */
  265. *bp++ = if_info_5g->channel; /* Channel number */
  266. *bp = 0x0; /* Phy Type */
  267. action_frame->len = (bp - (uint8 *)&action_frame->data) + 1;
  268. error = wldev_iovar_setbuf(if_info_2g->ndev, "actframe", af_params,
  269. sizeof(wl_af_params_t), smbuf, WLC_IOCTL_MAXLEN, NULL);
  270. if (error) {
  271. DHD_ERROR(("Failed to set action frame, error=%d\n", error));
  272. goto send_action_frame_out;
  273. }
  274. DHD_TRACE(("%s: BSS Trans Req frame sent to " MACDBG " try %d\n", __FUNCTION__,
  275. MAC2STRDBG(dhd_bandsteer_mac->mac_addr.octet),
  276. dhd_bandsteer_mac->wnm_frame_counter));
  277. send_action_frame_out:
  278. /* Re-schedule the timer */
  279. dhd_bandsteer_add_timer(dhd_bandsteer_mac, DHD_BANDSTEER_WNM_FRAME_DELAY);
  280. if (af_params)
  281. kfree(af_params);
  282. if (smbuf)
  283. kfree(smbuf);
  284. if (error)
  285. return BCME_ERROR;
  286. return BCME_OK;
  287. }
  288. /*
  289. * Call dhd_bandsteer_remove_mac_from_list()
  290. * Add into black list of corresponding interace at present 2.4
  291. * Uses existing IOVAR calls
  292. */
  293. static void
  294. dhd_bandsteer_add_to_black_list(dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac)
  295. {
  296. dhd_bandsteer_context_t *dhd_bandsteer_cntx = dhd_bandsteer_mac->dhd_bandsteer_cntx;
  297. dhd_bandsteer_iface_info_t *if_info_2g;
  298. int err;
  299. int macmode = MACLIST_MODE_DENY;
  300. struct maclist *maclist;
  301. uint8 *pmaclist_ea;
  302. uint8 mac_buf[MAX_NUM_OF_ASSOCLIST *
  303. sizeof(struct ether_addr) + sizeof(uint)] = {0};
  304. if_info_2g = &dhd_bandsteer_cntx->bsd_ifaces[!dhd_bandsteer_cntx->ifidx_5g];
  305. /* Black listing */
  306. DHD_INFO(("%s: Black listing " MACDBG " on 2GHz IF\n", __FUNCTION__,
  307. MAC2STRDBG(dhd_bandsteer_mac->mac_addr.octet)));
  308. /* Get current black list */
  309. if ((err = wldev_ioctl_get(if_info_2g->ndev, WLC_GET_MACLIST, mac_buf,
  310. sizeof(mac_buf))) != 0) {
  311. DHD_ERROR(("%s: WLC_GET_MACLIST error=%d\n", __FUNCTION__, err));
  312. }
  313. maclist = (struct maclist *)mac_buf;
  314. pmaclist_ea = (uint8*) mac_buf +
  315. (sizeof(struct ether_addr) * maclist->count) + sizeof(uint);
  316. maclist->count++;
  317. memcpy(pmaclist_ea, &dhd_bandsteer_mac->mac_addr.octet, ETHER_ADDR_LEN);
  318. if ((err = wldev_ioctl_set(if_info_2g->ndev, WLC_SET_MACMODE, &macmode,
  319. sizeof(macmode))) != 0) {
  320. DHD_ERROR(("%s: WLC_SET_MACMODE error=%d\n", __FUNCTION__, err));
  321. }
  322. /* set the MAC filter list */
  323. if ((err = wldev_ioctl_set(if_info_2g->ndev, WLC_SET_MACLIST, maclist,
  324. sizeof(int) + sizeof(struct ether_addr) * maclist->count)) != 0) {
  325. DHD_ERROR(("%s: WLC_SET_MACLIST error=%d\n", __FUNCTION__, err));
  326. }
  327. }
  328. /*
  329. * Check if mac association on 2.4 G
  330. * If on 2.4
  331. * * Ignore if we have already run Bandsteer cycle for this
  332. * * Add PEER STA mac monitor_list
  333. * * Send BSS transition request frame
  334. * Else
  335. * * We recieved assoc on 5g from Mac we forced to move onto 5G
  336. */
  337. s32
  338. dhd_bandsteer_trigger_bandsteer(struct net_device *ndev, uint8 *mac_addr)
  339. {
  340. struct wireless_dev *__wdev = (struct wireless_dev *)(ndev)->ieee80211_ptr;
  341. struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)wiphy_priv(__wdev->wiphy);
  342. struct net_device *netdev_5g = NULL;
  343. dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac = NULL;
  344. dhd_bandsteer_context_t *dhd_bandsteer_cntx = NULL;
  345. DHD_ERROR(("%s: Start band-steer procedure for " MACDBG "\n", __FUNCTION__,
  346. MAC2STRDBG(mac_addr)));
  347. if (cfg == NULL) {
  348. DHD_ERROR(("%s: bcmcfg is null\n", __FUNCTION__));
  349. return BCME_ERROR;
  350. }
  351. if (cfg->dhd_bandsteer_cntx == NULL) {
  352. DHD_ERROR(("%s: Band Steering not enabled\n", __FUNCTION__));
  353. return BCME_ERROR;
  354. }
  355. dhd_bandsteer_cntx = cfg->dhd_bandsteer_cntx;
  356. netdev_5g = dhd_bandsteer_cntx->bsd_ifaces[dhd_bandsteer_cntx->ifidx_5g].ndev;
  357. dhd_bandsteer_mac = dhd_bandsteer_look_for_match(dhd_bandsteer_cntx, mac_addr);
  358. if (dhd_bandsteer_mac == NULL) {
  359. /*
  360. * This STA entry not found in list check if bandsteer is already done for this
  361. * Check if this on 2.4/5Ghz
  362. */
  363. if (ndev == netdev_5g) {
  364. /* Ignore as device aleady connectd to 5G */
  365. DHD_ERROR(("%s: " MACDBG " is on 5GHz interface\n", __FUNCTION__,
  366. MAC2STRDBG(mac_addr)));
  367. dhd_bandsteer_mac = kzalloc(sizeof(dhd_bandsteer_mac_entry_t), GFP_KERNEL);
  368. if (unlikely(!dhd_bandsteer_mac)) {
  369. DHD_ERROR(("%s: alloc failed\n", __FUNCTION__));
  370. return BCME_NOMEM;
  371. }
  372. dhd_bandsteer_mac->dhd_bandsteer_cntx = dhd_bandsteer_cntx;
  373. memcpy(&dhd_bandsteer_mac->mac_addr.octet, mac_addr, ETHER_ADDR_LEN);
  374. dhd_bandsteer_add_to_black_list(dhd_bandsteer_mac);
  375. kfree(dhd_bandsteer_mac);
  376. dhd_bandsteer_mac = NULL;
  377. return BCME_OK;
  378. } else {
  379. DHD_INFO(("%s: dhd_bandsteer_addmac_to_monitorlist\n", __FUNCTION__));
  380. dhd_bandsteer_addmac_to_monitorlist(dhd_bandsteer_cntx, mac_addr);
  381. /*
  382. * TODO: Time for us to enable PROB_REQ MSG
  383. */
  384. }
  385. } else {
  386. /*
  387. * Start post connect process as bandsteer is successful for this entry
  388. */
  389. if (ndev == netdev_5g) {
  390. DHD_ERROR(("%s: Band Steer for " MACDBG " successful\n", __FUNCTION__,
  391. MAC2STRDBG(mac_addr)));
  392. dhd_bandsteer_add_to_black_list(dhd_bandsteer_mac);
  393. dhd_bandsteer_remove_mac_from_list(dhd_bandsteer_mac, 0);
  394. /* Probabaly add this mac into black list */
  395. }
  396. }
  397. return BCME_OK;
  398. }
  399. s32
  400. dhd_bandsteer_module_init(struct net_device *ndev, bool ap, bool p2p)
  401. {
  402. /* Initialize */
  403. dhd_bandsteer_context_t *dhd_bandsteer_cntx = NULL;
  404. struct channel_info ci;
  405. uint8 ifidx;
  406. struct wireless_dev *__wdev = (struct wireless_dev *)(ndev)->ieee80211_ptr;
  407. struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)wiphy_priv(__wdev->wiphy);
  408. int err;
  409. DHD_INFO(("%s: entered\n", __FUNCTION__));
  410. if (cfg == NULL) {
  411. DHD_ERROR(("%s: bcmcfg is null\n", __FUNCTION__));
  412. return BCME_ERROR;
  413. }
  414. if (cfg->dhd_bandsteer_cntx != NULL) {
  415. DHD_ERROR(("%s: Band Steering already enabled\n", __FUNCTION__));
  416. goto init_done;
  417. }
  418. dhd_bandsteer_cntx = (dhd_bandsteer_context_t *)kzalloc(sizeof(dhd_bandsteer_context_t),
  419. GFP_KERNEL);
  420. if (unlikely(!dhd_bandsteer_cntx)) {
  421. DHD_ERROR(("%s: dhd_bandsteer_cntx alloc failed\n", __FUNCTION__));
  422. return BCME_NOMEM;
  423. }
  424. if (dhd_bandsteer_get_ifaces(cfg->pub, &dhd_bandsteer_cntx->bsd_ifaces)) {
  425. DHD_ERROR(("%s: AP interfaces count != 2", __FUNCTION__));
  426. err = BCME_ERROR;
  427. goto failed;
  428. }
  429. for (ifidx = 0; ifidx < DHD_BANDSTEER_MAXIFACES; ifidx++) {
  430. err = wldev_iovar_getbuf_bsscfg(dhd_bandsteer_cntx->bsd_ifaces[ifidx].ndev,
  431. "cur_etheraddr", NULL, 0, cfg->ioctl_buf,
  432. WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  433. if (err) {
  434. DHD_ERROR(("%s: Failed to get mac address\n", __FUNCTION__));
  435. goto failed;
  436. }
  437. memcpy(dhd_bandsteer_cntx->bsd_ifaces[ifidx].macaddr.octet,
  438. cfg->ioctl_buf, ETHER_ADDR_LEN);
  439. memset(&ci, 0, sizeof(struct channel_info));
  440. err = wldev_ioctl_get(dhd_bandsteer_cntx->bsd_ifaces[ifidx].ndev, WLC_GET_CHANNEL,
  441. &ci, sizeof(ci));
  442. if (err) {
  443. DHD_ERROR(("%s: Failed to get channel\n", __FUNCTION__));
  444. goto failed;
  445. }
  446. if (CHANNEL_IS_5G(ci.hw_channel))
  447. dhd_bandsteer_cntx->ifidx_5g = ifidx;
  448. dhd_bandsteer_cntx->bsd_ifaces[ifidx].channel = ci.hw_channel;
  449. }
  450. if (ap) {
  451. INIT_LIST_HEAD(&dhd_bandsteer_cntx->dhd_bandsteer_monitor_list);
  452. dhd_bandsteer_cntx->dhd_pub = cfg->pub;
  453. cfg->dhd_bandsteer_cntx = (void *) dhd_bandsteer_cntx;
  454. }
  455. /*
  456. * Enabling iovar "probresp_sw" suppresses probe request as a result of
  457. * which p2p discovery for only 2G capable STA fails. Hence commenting for now.
  458. *
  459. */
  460. init_done:
  461. /* Enable p2p bandsteer on 2GHz interface */
  462. if (p2p) {
  463. if (dhd_bandsteer_cntx == NULL)
  464. dhd_bandsteer_cntx = cfg->dhd_bandsteer_cntx;
  465. if ((err = wldev_iovar_setint(
  466. dhd_bandsteer_cntx->bsd_ifaces[!dhd_bandsteer_cntx->ifidx_5g].ndev,
  467. "bandsteer", 1)) != BCME_OK) {
  468. DHD_ERROR(("%s: Failed to enable bandsteer in FW err = %d\n",
  469. __FUNCTION__, err));
  470. }
  471. }
  472. DHD_INFO(("%s: exited\n", __FUNCTION__));
  473. return BCME_OK;
  474. failed:
  475. kfree(dhd_bandsteer_cntx);
  476. return err;
  477. }
  478. s32
  479. dhd_bandsteer_module_deinit(struct net_device *ndev, bool ap, bool p2p)
  480. {
  481. dhd_bandsteer_mac_entry_t *dhd_bandsteer_mac = NULL;
  482. dhd_bandsteer_context_t *dhd_bandsteer_cntx = NULL;
  483. struct wireless_dev *__wdev = (struct wireless_dev *)(ndev)->ieee80211_ptr;
  484. struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)wiphy_priv(__wdev->wiphy);
  485. int macmode = MACLIST_MODE_DISABLED;
  486. int err;
  487. struct maclist maclist;
  488. DHD_INFO(("%s: entered\n", __FUNCTION__));
  489. if (cfg == NULL) {
  490. DHD_ERROR(("%s: bcmcfg is null\n", __FUNCTION__));
  491. return BCME_ERROR;
  492. }
  493. if (cfg->dhd_bandsteer_cntx == NULL) {
  494. DHD_ERROR(("%s: Band Steering not enabled\n", __FUNCTION__));
  495. return BCME_ERROR;
  496. }
  497. dhd_bandsteer_cntx = cfg->dhd_bandsteer_cntx;
  498. if (ap) {
  499. /* Disable mac filter */
  500. if ((err = wldev_ioctl_set(
  501. dhd_bandsteer_cntx->bsd_ifaces[!dhd_bandsteer_cntx->ifidx_5g].ndev,
  502. WLC_SET_MACMODE, &macmode, sizeof(macmode))) != 0) {
  503. DHD_ERROR(("%s: WLC_SET_MACMODE error=%d\n", __FUNCTION__, err));
  504. }
  505. /* Set the MAC filter list */
  506. memset(&maclist, 0, sizeof(struct maclist));
  507. if ((err = wldev_ioctl_set(
  508. dhd_bandsteer_cntx->bsd_ifaces[!dhd_bandsteer_cntx->ifidx_5g].ndev,
  509. WLC_SET_MACLIST, &maclist, sizeof(struct maclist))) != 0) {
  510. DHD_ERROR(("%s: WLC_SET_MACLIST error=%d\n", __FUNCTION__, err));
  511. }
  512. }
  513. /* Disable p2p bandsteer on 2GHz interface */
  514. if (p2p) {
  515. if ((err = wldev_iovar_setint(
  516. dhd_bandsteer_cntx->bsd_ifaces[!dhd_bandsteer_cntx->ifidx_5g].ndev,
  517. "bandsteer", 0)) != BCME_OK) {
  518. DHD_ERROR(("%s: Failed to enable bandsteer in FW err = %d\n",
  519. __FUNCTION__, err));
  520. }
  521. }
  522. if (ap) {
  523. /* Get the first element of the list & pass it to remove */
  524. if (dhd_bandsteer_cntx->dhd_bandsteer_monitor_list.next !=
  525. &dhd_bandsteer_cntx->dhd_bandsteer_monitor_list) {
  526. dhd_bandsteer_mac = (dhd_bandsteer_mac_entry_t *)list_entry(
  527. dhd_bandsteer_cntx->dhd_bandsteer_monitor_list.next,
  528. dhd_bandsteer_mac_entry_t, list);
  529. }
  530. if (dhd_bandsteer_mac) {
  531. dhd_bandsteer_remove_mac_from_list(dhd_bandsteer_mac, 1);
  532. }
  533. kfree(dhd_bandsteer_cntx);
  534. cfg->dhd_bandsteer_cntx = NULL;
  535. }
  536. DHD_INFO(("%s: exited\n", __FUNCTION__));
  537. return BCME_OK;
  538. }