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