1 /** @file rtos_wpa_supp_if.c
2  *
3  *  @brief  This file provides RTOS WPA Supplicant interface wifi APIs
4  *
5  *
6  *  Copyright 2008-2024 NXP
7  *
8  *  SPDX-License-Identifier: BSD-3-Clause
9  *
10  */
11 
12 #include <stdlib.h>
13 #include "fsl_os_abstraction.h"
14 #include "wifi.h"
15 #include <wm_net.h>
16 
17 #if CONFIG_WPA_SUPP
18 
19 #include "rtos_wpa_supp_if.h"
20 #include "wifi-internal.h"
21 #include "supp_main.h"
22 
23 #define MAX_MGMT_TX_FRAME_SIZE 1500
24 
25 static const chan_to_freq_t chan_to_freq[] = {
26     {2412, 1, 0},   {2417, 2, 0},   {2422, 3, 0},   {2427, 4, 0},   {2432, 5, 0},   {2437, 6, 0},   {2442, 7, 0},
27     {2447, 8, 0},   {2452, 9, 0},   {2457, 10, 0},  {2462, 11, 0},  {2467, 12, 0},  {2472, 13, 0},  {2484, 14, 0},
28     {4915, 183, 1}, {4920, 184, 1}, {4925, 185, 1}, {4935, 187, 1}, {4940, 188, 1}, {4945, 189, 1}, {4960, 192, 1},
29     {4980, 196, 1}, {5035, 7, 1},   {5040, 8, 1},   {5045, 9, 1},   {5055, 11, 1},  {5060, 12, 1},  {5080, 16, 1},
30     {5170, 34, 1},  {5180, 36, 1},  {5190, 38, 1},  {5200, 40, 1},  {5210, 42, 1},  {5220, 44, 1},  {5230, 46, 1},
31     {5240, 48, 1},  {5260, 52, 1},  {5280, 56, 1},  {5300, 60, 1},  {5320, 64, 1},  {5500, 100, 1}, {5520, 104, 1},
32     {5540, 108, 1}, {5560, 112, 1}, {5580, 116, 1}, {5600, 120, 1}, {5620, 124, 1}, {5640, 128, 1}, {5660, 132, 1},
33     {5680, 136, 1}, {5700, 140, 1}, {5720, 144, 1}, {5745, 149, 1}, {5765, 153, 1}, {5785, 157, 1}, {5805, 161, 1},
34 #if CONFIG_UNII4_BAND_SUPPORT
35     {5825, 165, 1}, {5845, 169, 1}, {5865, 173, 1}, {5885, 177, 1},
36 #else
37     {5825, 165, 1},
38 #endif
39 };
40 
41 static uint8_t *g_extended_capa = NULL;
42 static uint8_t *g_extended_capa_mask = NULL;
43 
get_algo_from_auth_type(int wpa_auth_alg)44 static unsigned char get_algo_from_auth_type(int wpa_auth_alg)
45 {
46     if (wpa_auth_alg & WPA_AUTH_ALG_OPEN)
47     {
48         return MLAN_AUTH_MODE_OPEN;
49     }
50     if (wpa_auth_alg & WPA_AUTH_ALG_SHARED)
51     {
52         return MLAN_AUTH_MODE_SHARED;
53     }
54     if (wpa_auth_alg & WPA_AUTH_ALG_LEAP)
55     {
56         return MLAN_AUTH_MODE_NETWORKEAP;
57     }
58     if (wpa_auth_alg & WPA_AUTH_ALG_FT)
59     {
60         return MLAN_AUTH_MODE_FT;
61     }
62     if (wpa_auth_alg & WPA_AUTH_ALG_SAE)
63     {
64         return MLAN_AUTH_MODE_SAE;
65     }
66 
67     return MLAN_AUTH_MODE_AUTO;
68 }
69 
wpa_alg_to_cipher_suite(enum wpa_alg alg,size_t key_len)70 static unsigned int wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
71 {
72     unsigned flags = 0;
73 
74     if (alg == WPA_ALG_GCMP)
75     {
76         flags |= KEY_FLAG_GCMP;
77     }
78     else if (alg == WPA_ALG_GCMP_256)
79     {
80         flags |= KEY_FLAG_GCMP_256;
81     }
82 
83     if (alg == WPA_ALG_CCMP_256)
84     {
85         flags |= KEY_FLAG_CCMP_256;
86     }
87 
88     if ((alg == WPA_ALG_BIP_CMAC_128) || (alg == WPA_ALG_BIP_CMAC_256) || (alg == WPA_ALG_BIP_GMAC_128) ||
89         (alg == WPA_ALG_BIP_GMAC_256))
90     {
91         flags |= KEY_FLAG_AES_MCAST_IGTK;
92 
93         if (alg == WPA_ALG_BIP_GMAC_128)
94         {
95             flags |= KEY_FLAG_GMAC_128;
96         }
97         else if (alg == WPA_ALG_BIP_GMAC_256)
98         {
99             flags |= KEY_FLAG_GMAC_256;
100         }
101     }
102 
103     return flags;
104 }
105 
wifi_nxp_wpa_supp_event_proc_mac_changed(void * if_priv)106 void wifi_nxp_wpa_supp_event_proc_mac_changed(void *if_priv)
107 {
108     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
109 
110     if (!if_priv)
111     {
112         supp_e("%s: Missing interface context", __func__);
113         return;
114     }
115 
116     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
117 
118 #ifdef CONFIG_WPA_SUPP_AP
119     if (wifi_if_ctx_rtos->hostapd)
120     {
121         wifi_if_ctx_rtos->hostapd_callbk_fns.mac_changed(wifi_if_ctx_rtos->hapd_drv_if_ctx);
122     }
123     else
124 #endif
125     {
126         wifi_if_ctx_rtos->supp_callbk_fns.mac_changed(wifi_if_ctx_rtos->supp_drv_if_ctx);
127     }
128 }
129 
130 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
drv2supp_chan_width(int width)131 static enum chan_width drv2supp_chan_width(int width)
132 {
133 	switch (width) {
134 	case NXP_WIFI_CHAN_WIDTH_20_NOHT:
135 		return CHAN_WIDTH_20_NOHT;
136 	case NXP_WIFI_CHAN_WIDTH_20:
137 		return CHAN_WIDTH_20;
138 	case NXP_WIFI_CHAN_WIDTH_40:
139 		return CHAN_WIDTH_40;
140 	case NXP_WIFI_CHAN_WIDTH_80:
141 		return CHAN_WIDTH_80;
142 	case NXP_WIFI_CHAN_WIDTH_80P80:
143 		return CHAN_WIDTH_80P80;
144 	case NXP_WIFI_CHAN_WIDTH_160:
145 		return CHAN_WIDTH_160;
146 	default:
147 		break;
148 	}
149 	return CHAN_WIDTH_UNKNOWN;
150 }
151 #endif
152 
153 /** Convertion from/to frequency/channel */
154 /**
155  *  @brief Get frequency for channel in given band
156  *
157  *  @param channel      channel
158  *  @param band         band
159  *
160  *  @return             freq
161  */
channel_to_frequency(t_u16 channel,t_u8 band)162 int channel_to_frequency(t_u16 channel, t_u8 band)
163 {
164     int i = 0;
165     for (i = 0; i < (int)ARRAY_SIZE(chan_to_freq); i++)
166     {
167         if (channel == chan_to_freq[i].channel && band == chan_to_freq[i].band)
168         {
169             return chan_to_freq[i].freq;
170         }
171     }
172     return 0;
173 }
174 
freq_to_chan(unsigned int freq)175 t_u16 freq_to_chan(unsigned int freq)
176 {
177     int i = 0;
178     for (i = 0; i < (int)ARRAY_SIZE(chan_to_freq); i++)
179     {
180         if (freq == chan_to_freq[i].freq)
181         {
182             return chan_to_freq[i].channel;
183         }
184     }
185     return 0;
186 }
187 
wifi_nxp_wpa_supp_event_proc_chan_list_changed(void * if_priv,const char * alpha2)188 void wifi_nxp_wpa_supp_event_proc_chan_list_changed(void *if_priv, const char *alpha2)
189 {
190     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
191     union wpa_event_data event;
192 
193     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
194 
195     if (!if_priv)
196     {
197         supp_e("%s: Missing interface context", __func__);
198         return;
199     }
200 
201     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
202 
203     memset(&event, 0, sizeof(event));
204 
205     if (!alpha2)
206     {
207         supp_e("%s: Missing alpha2 data", __func__);
208         return;
209     }
210 
211     event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
212     event.channel_list_changed.type      = REGDOM_TYPE_COUNTRY;
213     event.channel_list_changed.alpha2[0] = alpha2[0];
214     event.channel_list_changed.alpha2[1] = alpha2[1];
215     event.channel_list_changed.alpha2[2] = alpha2[2];
216 
217 #if CONFIG_WPA_SUPP_AP
218     if (wifi_if_ctx_rtos->hostapd)
219     {
220         wifi_if_ctx_rtos->hostapd_callbk_fns.chan_list_changed(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
221     }
222     else
223 #endif
224     {
225         wifi_if_ctx_rtos->supp_callbk_fns.chan_list_changed(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
226     }
227 }
228 
wifi_nxp_wpa_supp_event_proc_scan_start(void * if_priv)229 void wifi_nxp_wpa_supp_event_proc_scan_start(void *if_priv)
230 {
231     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
232     struct os_time t;
233 
234     if (!if_priv)
235     {
236         supp_e("%s: Missing interface context", __func__);
237         return;
238     }
239 
240     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
241 
242     os_get_time(&t);
243 
244     memcpy(&wifi_if_ctx_rtos->scan_start_tsf_bssid, &wifi_if_ctx_rtos->assoc_bssid, ETH_ALEN);
245 
246     wifi_if_ctx_rtos->scan_start_tsf = t.sec * 1000;
247 
248     if (wifi_if_ctx_rtos->supp_callbk_fns.scan_start)
249     {
250         wifi_if_ctx_rtos->supp_callbk_fns.scan_start(wifi_if_ctx_rtos->supp_drv_if_ctx);
251     }
252 }
253 
wifi_nxp_wpa_supp_event_proc_scan_done(void * if_priv,int aborted,int external_scan)254 void wifi_nxp_wpa_supp_event_proc_scan_done(void *if_priv, int aborted, int external_scan)
255 {
256     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
257     union wpa_event_data event;
258     struct scan_info *info = NULL;
259 
260     if (!if_priv)
261     {
262         supp_e("%s: Missing interface context", __func__);
263         return;
264     }
265 
266     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
267 
268     memset(&event, 0, sizeof(event));
269 
270     info                = &event.scan_info;
271     info->aborted       = aborted;
272     info->external_scan = external_scan;
273     info->nl_scan_event = 1;
274 
275     memcpy(&info->scan_start_tsf, &wifi_if_ctx_rtos->scan_start_tsf, sizeof(info->scan_start_tsf));
276 
277     memcpy(&info->scan_start_tsf_bssid, &wifi_if_ctx_rtos->scan_start_tsf_bssid, ETH_ALEN);
278 
279     wifi_if_ctx_rtos->scan_in_progress = false;
280 
281     wifi_nxp_reset_scan_flag();
282 
283 #if CONFIG_WPA_SUPP_AP
284     if (wifi_if_ctx_rtos->hostapd)
285     {
286         wifi_if_ctx_rtos->hostapd_callbk_fns.scan_done(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
287     }
288     else
289 #endif
290     {
291         wifi_if_ctx_rtos->supp_callbk_fns.scan_done(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
292     }
293 }
294 
295 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wifi_nxp_wpa_supp_event_proc_survey_res(void * if_priv,nxp_wifi_event_new_survey_result_t * survey_res,unsigned int event_len,bool more_res)296 void wifi_nxp_wpa_supp_event_proc_survey_res(void *if_priv,
297                                              nxp_wifi_event_new_survey_result_t *survey_res,
298                                              unsigned int event_len,
299                                              bool more_res)
300 {
301     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
302     struct freq_survey *survey                 = NULL;
303 
304     if (!if_priv)
305     {
306         supp_e("%s: Missing interface context", __func__);
307         return;
308     }
309 
310     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
311 
312     if (survey_res == NULL)
313     {
314 #if CONFIG_WPA_SUPP_AP
315         if (wifi_if_ctx_rtos->hostapd)
316         {
317             wifi_if_ctx_rtos->hostapd_callbk_fns.survey_res(wifi_if_ctx_rtos->hapd_drv_if_ctx, survey, more_res);
318         }
319         else
320 #endif
321         {
322             wifi_if_ctx_rtos->supp_callbk_fns.survey_res(wifi_if_ctx_rtos->supp_drv_if_ctx, survey, more_res);
323         }
324         return;
325     }
326 
327     survey = (struct freq_survey *)OSA_MemoryAllocate(sizeof(*survey));
328 
329     if (!survey)
330     {
331         supp_e("%s: Unable to calloc memory for survey result\n", __func__);
332         return;
333     }
334 
335     survey->freq = survey_res->freq;
336 
337     if (survey_res->nf)
338     {
339         survey->nf = survey_res->nf;
340         survey->filled |= SURVEY_HAS_NF;
341     }
342 
343     if (survey_res->channel_time)
344     {
345         (void)memcpy((void *)&survey->channel_time, (const void *)&survey_res->channel_time,
346                      sizeof(survey->channel_time));
347         survey->filled |= SURVEY_HAS_CHAN_TIME;
348     }
349 
350     if (survey_res->channel_time_busy)
351     {
352         (void)memcpy((void *)&survey->channel_time_busy, (const void *)&survey_res->channel_time_busy,
353                      sizeof(survey->channel_time_busy));
354         survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
355     }
356 
357     if (survey_res->channel_time_rx)
358     {
359         (void)memcpy((void *)&survey->channel_time_rx, (const void *)&survey_res->channel_time_rx,
360                      sizeof(survey->channel_time_rx));
361         survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
362     }
363 
364     if (survey_res->channel_time_tx)
365     {
366         (void)memcpy((void *)&survey->channel_time_tx, (const void *)&survey_res->channel_time_tx,
367                      sizeof(survey->channel_time_tx));
368         survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
369     }
370 
371 #if CONFIG_WPA_SUPP_AP
372     if (wifi_if_ctx_rtos->hostapd)
373     {
374         wifi_if_ctx_rtos->hostapd_callbk_fns.survey_res(wifi_if_ctx_rtos->hapd_drv_if_ctx, survey, more_res);
375     }
376     else
377 #endif
378     {
379         wifi_if_ctx_rtos->supp_callbk_fns.survey_res(wifi_if_ctx_rtos->supp_drv_if_ctx, survey, more_res);
380     }
381 }
382 #endif
383 
wifi_nxp_wpa_supp_free_pairwise_key_params(struct wpa_driver_set_key_params * params)384 static void wifi_nxp_wpa_supp_free_pairwise_key_params(struct wpa_driver_set_key_params *params)
385 {
386     if (params->ifname)
387     {
388         os_free((void *)params->ifname);
389     }
390 
391     if (params->addr)
392     {
393         os_free((void *)params->addr);
394     }
395 
396     if (params->seq)
397     {
398         os_free((void *)params->seq);
399     }
400 
401     if (params->key)
402     {
403         os_free((void *)params->key);
404     }
405 
406     os_free(params);
407 }
408 
wifi_nxp_wpa_supp_event_proc_auth_resp(void * if_priv,nxp_wifi_event_mlme_t * auth_resp,unsigned int event_len)409 void wifi_nxp_wpa_supp_event_proc_auth_resp(void *if_priv, nxp_wifi_event_mlme_t *auth_resp, unsigned int event_len)
410 {
411     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
412     union wpa_event_data event;
413     const struct ieee80211_mgmt *mgmt = NULL;
414     const unsigned char *frame        = NULL;
415     unsigned int frame_len            = 0;
416 
417     if (!if_priv)
418     {
419         supp_e("%s: Missing interface context", __func__);
420         return;
421     }
422 
423     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
424 
425     frame     = (const unsigned char *)auth_resp->frame.frame;
426     frame_len = auth_resp->frame.frame_len;
427     mgmt      = (const struct ieee80211_mgmt *)frame;
428 
429     if (frame_len < 4 + (2 * WIFI_ETH_ADDR_LEN))
430     {
431         supp_e("%s: MLME event too short", __func__);
432         return;
433     }
434 
435     if (frame_len < 24 + sizeof(mgmt->u.auth))
436     {
437         supp_e("%s: Authentication response frame too short", __func__);
438         return;
439     }
440 
441     memset(&event, 0, sizeof(event));
442 
443     memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
444 
445     event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
446 
447     event.auth.auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
448 
449     event.auth.status_code = le_to_host16(mgmt->u.auth.status_code);
450 
451     if (frame_len > 24 + sizeof(mgmt->u.auth))
452     {
453         event.auth.ies     = mgmt->u.auth.variable;
454         event.auth.ies_len = (frame_len - 24 - sizeof(mgmt->u.auth));
455     }
456 
457     wifi_if_ctx_rtos->supp_callbk_fns.auth_resp(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
458 }
459 
wifi_nxp_wpa_supp_event_proc_assoc_resp(void * if_priv,nxp_wifi_assoc_event_mlme_t * assoc_resp,unsigned int event_len)460 void wifi_nxp_wpa_supp_event_proc_assoc_resp(void *if_priv,
461                                              nxp_wifi_assoc_event_mlme_t *assoc_resp,
462                                              unsigned int event_len)
463 {
464     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
465     union wpa_event_data event;
466     const struct ieee80211_mgmt *mgmt              = NULL;
467     const unsigned char *frame                     = NULL;
468     const unsigned char *req_frame                 = NULL;
469     const unsigned char *bssid                     = NULL;
470     unsigned int frame_len                         = 0;
471     unsigned short status                          = WLAN_STATUS_UNSPECIFIED_FAILURE;
472     enum sta_connect_fail_reason_codes reason_code = STA_CONNECT_FAIL_REASON_UNSPECIFIED;
473 
474     if (!if_priv)
475     {
476         supp_e("%s: Missing interface context", __func__);
477         return;
478     }
479 
480     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
481 
482     frame     = (const unsigned char *)assoc_resp->frame.frame;
483     frame_len = assoc_resp->frame.frame_len;
484     req_frame = (const unsigned char *)assoc_resp->req_ie;
485 
486     mgmt = (const struct ieee80211_mgmt *)frame;
487 
488     memset(&event, 0, sizeof(event));
489     memset(&wifi_if_ctx_rtos->assoc_bssid, 0, ETH_ALEN);
490 
491     if (frame_len < 24 + sizeof(mgmt->u.assoc_resp))
492     {
493         supp_d("%s: Association response frame too short", __func__);
494         bssid       = (unsigned char *)&wifi_if_ctx_rtos->attempt_bssid;
495         reason_code = STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED;
496         goto fail;
497     }
498 
499     status = le_to_host16(mgmt->u.assoc_resp.status_code);
500 
501     bssid = mgmt->bssid;
502 
503     if (status != WLAN_STATUS_SUCCESS)
504     {
505     fail:
506         wifi_if_ctx_rtos->associated = false;
507         event.assoc_reject.bssid     = bssid;
508 
509         if (frame_len > 24 + sizeof(mgmt->u.assoc_resp))
510         {
511             event.assoc_reject.resp_ies     = (unsigned char *)mgmt->u.assoc_resp.variable;
512             event.assoc_reject.resp_ies_len = (frame_len - 24 - sizeof(mgmt->u.assoc_resp));
513         }
514 
515         event.assoc_reject.status_code    = status;
516         event.assoc_reject.reason_code    = reason_code;
517         event.assoc_reject.timeout_reason = NULL;
518         if (wifi_if_ctx_rtos->ft_roaming)
519         {
520             wifi_if_ctx_rtos->ft_roaming = false;
521             wifi_nxp_wpa_supp_free_pairwise_key_params(wifi_if_ctx_rtos->key_params);
522             wifi_if_ctx_rtos->key_params = NULL;
523         }
524     }
525     else
526     {
527         wifi_if_ctx_rtos->associated = true;
528         memcpy(&wifi_if_ctx_rtos->assoc_bssid, mgmt->bssid, ETH_ALEN);
529 
530         event.assoc_info.addr           = mgmt->bssid;
531         event.assoc_info.resp_frame     = frame;
532         event.assoc_info.resp_frame_len = frame_len;
533         event.assoc_info.freq           = wifi_if_ctx_rtos->assoc_freq;
534 
535         if (frame_len > 24 + sizeof(mgmt->u.assoc_resp))
536         {
537             event.assoc_info.resp_ies     = (unsigned char *)mgmt->u.assoc_resp.variable;
538             event.assoc_info.resp_ies_len = (frame_len - 24 - sizeof(mgmt->u.assoc_resp));
539         }
540         if (assoc_resp->req_ie_len)
541         {
542             event.assoc_info.req_ies     = (unsigned char *)req_frame;
543             event.assoc_info.req_ies_len = assoc_resp->req_ie_len;
544         }
545     }
546 
547     wifi_if_ctx_rtos->supp_callbk_fns.assoc_resp(wifi_if_ctx_rtos->supp_drv_if_ctx, &event, status);
548 }
549 
wifi_nxp_wpa_supp_event_proc_deauth(void * if_priv,nxp_wifi_event_mlme_t * deauth,unsigned int event_len)550 void wifi_nxp_wpa_supp_event_proc_deauth(void *if_priv, nxp_wifi_event_mlme_t *deauth, unsigned int event_len)
551 {
552     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
553     union wpa_event_data event;
554     const struct ieee80211_mgmt *mgmt = NULL;
555     const unsigned char *frame        = NULL;
556     unsigned int frame_len            = 0;
557 
558     if (!if_priv)
559     {
560         supp_e("%s: Missing interface context", __func__);
561         return;
562     }
563 
564     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
565 
566     frame     = (const unsigned char *)deauth->frame.frame;
567     frame_len = deauth->frame.frame_len;
568     mgmt      = (const struct ieee80211_mgmt *)frame;
569 
570     if (frame_len < 24 + sizeof(mgmt->u.deauth))
571     {
572         supp_e("%s: Deauthentication response frame too short", __func__);
573         return;
574     }
575 
576     memset(&event, 0, sizeof(event));
577 
578     event.deauth_info.addr        = &mgmt->sa[0];
579     event.deauth_info.reason_code = le_to_host16(WLAN_REASON_DEAUTH_LEAVING);
580     if (frame + frame_len > mgmt->u.deauth.variable)
581     {
582         event.deauth_info.ie     = mgmt->u.deauth.variable;
583         event.deauth_info.ie_len = (frame + frame_len - mgmt->u.deauth.variable);
584     }
585 
586     (void)wifi_event_completion(WIFI_EVENT_DEAUTHENTICATION, le_to_host16(mgmt->u.deauth.reason_code), NULL);
587 
588     wifi_if_ctx_rtos->supp_callbk_fns.deauth(wifi_if_ctx_rtos->supp_drv_if_ctx, &event, mgmt);
589 }
590 
wifi_nxp_wpa_supp_event_proc_disassoc(void * if_priv,nxp_wifi_event_mlme_t * disassoc,unsigned int event_len)591 void wifi_nxp_wpa_supp_event_proc_disassoc(void *if_priv, nxp_wifi_event_mlme_t *disassoc, unsigned int event_len)
592 {
593     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
594     union wpa_event_data event;
595     const struct ieee80211_mgmt *mgmt = NULL;
596     const unsigned char *frame        = NULL;
597     unsigned int frame_len            = 0;
598 
599     if (!if_priv)
600     {
601         supp_e("%s: Missing interface context", __func__);
602         return;
603     }
604 
605     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
606 
607     frame     = (const unsigned char *)disassoc->frame.frame;
608     frame_len = disassoc->frame.frame_len;
609     mgmt      = (const struct ieee80211_mgmt *)frame;
610 
611     if (frame_len < 24 + sizeof(mgmt->u.disassoc))
612     {
613         supp_e("%s: Dis-association response frame too short", __func__);
614         return;
615     }
616 
617     memset(&event, 0, sizeof(event));
618 
619     event.disassoc_info.addr        = &mgmt->sa[0];
620     event.disassoc_info.reason_code = le_to_host16(mgmt->u.disassoc.reason_code);
621     if (frame + frame_len > mgmt->u.disassoc.variable)
622     {
623         event.disassoc_info.ie     = mgmt->u.disassoc.variable;
624         event.disassoc_info.ie_len = (frame + frame_len - mgmt->u.disassoc.variable);
625     }
626 
627     wifi_if_ctx_rtos->supp_callbk_fns.disassoc(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
628 }
629 
630 #if 0
631 void wifi_nxp_wpa_supp_event_proc_remain_on_channel(void *if_priv, int cancel_channel)
632 {
633     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
634     wifi_if_ctx_rtos                           = (struct wifi_nxp_ctx_rtos *)if_priv;
635     union wpa_event_data event;
636     os_memset(&event, 0, sizeof(event));
637     event.remain_on_channel.freq     = wifi_if_ctx_rtos->remain_on_channel_freq;
638     event.remain_on_channel.duration = wifi_if_ctx_rtos->remain_on_channel_duration;
639     wifi_if_ctx_rtos->supp_callbk_fns.remain_on_channel(wifi_if_ctx_rtos->supp_drv_if_ctx, cancel_channel, &event);
640 }
641 #endif
642 
wifi_nxp_supp_state(void)643 int wifi_nxp_supp_state(void)
644 {
645     struct net_if *iface = (struct net_if *)(void *)net_get_sta_interface();
646     struct wpa_supplicant *wpa_s;
647     char if_name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
648     int ret;
649 
650     if (!get_supp_ready_state())
651     {
652         return 0;
653     }
654 
655     ret = net_if_get_name(iface, if_name, sizeof(if_name));
656     if (!ret) {
657         supp_e("Cannot get interface name (%d)", ret);
658         return 0;
659     }
660 
661     wpa_s = zephyr_get_handle_by_ifname(if_name);
662     if (!wpa_s) {
663         supp_e("Interface %s not found", if_name);
664         return 0;
665     }
666 
667     return wpa_s->wpa_state;
668 }
669 
wifi_nxp_hapd_state(void)670 int wifi_nxp_hapd_state(void)
671 {
672 #if CONFIG_WIFI_NM_HOSTAPD_AP
673     struct net_if *iface = (struct net_if *)(void *)net_get_uap_interface();
674     struct hostapd_iface *hapd_if;
675     char if_name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
676     int ret;
677 
678     if (!get_supp_ready_state())
679     {
680         return 0;
681     }
682 
683     ret = net_if_get_name(iface, if_name, sizeof(if_name));
684     if (!ret) {
685         supp_e("Cannot get interface name (%d)", ret);
686         return 0;
687     }
688 
689     hapd_if = zephyr_get_hapd_handle_by_ifname(if_name);
690     if (!hapd_if) {
691         supp_e("Interface %s not found", if_name);
692         return 0;
693     }
694 
695     return hapd_if->state;
696 #else
697     return 0;
698 #endif
699 }
700 
wifi_nxp_wpa_supp_dev_init(void * supp_drv_if_ctx,const char * iface_name,rtos_wpa_supp_dev_callbk_fns * supp_callbk_fns)701 void *wifi_nxp_wpa_supp_dev_init(void *supp_drv_if_ctx,
702                                  const char *iface_name,
703                                  rtos_wpa_supp_dev_callbk_fns *supp_callbk_fns)
704 {
705     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
706     const struct netif *iface = NULL;
707     u8 extended_capa[10]           = {0x00, 0x00, 0x8A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
708     u8 extended_capa_mask[10]      = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
709 
710     iface = net_if_get_binding(iface_name);
711 
712     if (!iface)
713     {
714         supp_e("%s: Interface %s not found", __func__, iface_name);
715         return NULL;
716     }
717 
718     if (strstr(iface_name, "ml"))
719         wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)wm_wifi.if_priv;
720     else
721         wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)wm_wifi.hapd_if_priv;
722 
723     if (!wifi_if_ctx_rtos)
724     {
725         supp_e("%s: Interface %s not properly initialized", __func__, iface_name);
726         return NULL;
727     }
728 
729     memset(wifi_if_ctx_rtos, 0x00, sizeof(struct wifi_nxp_ctx_rtos));
730 
731     wifi_if_ctx_rtos->iface_ctx       = iface;
732     wifi_if_ctx_rtos->supp_drv_if_ctx = supp_drv_if_ctx;
733 
734     if (strstr(iface_name, "ml"))
735     {
736         wifi_if_ctx_rtos->bss_type = BSS_TYPE_STA;
737     }
738     else
739     {
740         wifi_if_ctx_rtos->bss_type = BSS_TYPE_UAP;
741     }
742     wifi_if_ctx_rtos->last_mgmt_tx_data = (uint8_t *)OSA_MemoryAllocate(MAX_MGMT_TX_FRAME_SIZE);
743 
744     if (!wifi_if_ctx_rtos->last_mgmt_tx_data)
745     {
746         supp_e("%s: Buffer to store mgmt tx failed", __func__);
747         return NULL;
748     }
749 
750     g_extended_capa = (uint8_t *)OSA_MemoryAllocate(sizeof(extended_capa));
751     if (g_extended_capa)
752     {
753         os_memcpy(g_extended_capa, extended_capa, sizeof(extended_capa));
754     }
755 
756     g_extended_capa_mask = (uint8_t *)OSA_MemoryAllocate(sizeof(extended_capa_mask));
757     if (g_extended_capa_mask)
758     {
759         os_memcpy(g_extended_capa_mask, extended_capa_mask, sizeof(extended_capa_mask));
760     }
761 
762     memcpy(&wifi_if_ctx_rtos->supp_callbk_fns, supp_callbk_fns, sizeof(wifi_if_ctx_rtos->supp_callbk_fns));
763     return wifi_if_ctx_rtos;
764 }
765 
wifi_nxp_wpa_supp_dev_deinit(void * if_priv)766 void wifi_nxp_wpa_supp_dev_deinit(void *if_priv)
767 {
768     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
769 
770     if (wifi_if_ctx_rtos != NULL)
771     {
772         if (wifi_if_ctx_rtos->last_mgmt_tx_data != NULL)
773         {
774             OSA_MemoryFree(wifi_if_ctx_rtos->last_mgmt_tx_data);
775         }
776         memset(wifi_if_ctx_rtos, 0x00, sizeof(struct wifi_nxp_ctx_rtos));
777     }
778 
779     if (g_extended_capa != NULL)
780     {
781         OSA_MemoryFree(g_extended_capa);
782         g_extended_capa = NULL;
783     }
784 
785     if (g_extended_capa_mask != NULL)
786     {
787         OSA_MemoryFree(g_extended_capa_mask);
788         g_extended_capa_mask = NULL;
789     }
790 }
791 
wifi_nxp_sort_channels(t_u8 channels[],unsigned char num_chans)792 static void wifi_nxp_sort_channels(t_u8 channels[], unsigned char num_chans)
793 {
794     t_u8 i, j;
795 
796     /* Bubble sort */
797     for (i = 0; i < num_chans; i++)
798     {
799         for (j = 1; j < num_chans - i; j++)
800         {
801             if ((t_u8)channels[j - 1] > (t_u8)channels[j])
802             {
803                 SWAP_U8(channels[j - 1], channels[j]);
804             }
805         }
806     }
807 }
808 
wifi_nxp_wpa_supp_scan2(void * if_priv,struct wpa_driver_scan_params * params)809 int wifi_nxp_wpa_supp_scan2(void *if_priv, struct wpa_driver_scan_params *params)
810 {
811     int status                                 = -WM_FAIL;
812     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
813     int ret                                    = -1;
814     int i                                      = 0;
815     unsigned char num_chans                    = 0;
816     t_u8 bss_mode                              = BSS_INFRASTRUCTURE;
817     const char *ssid = NULL;
818     char ssid_v[(MLAN_MAX_SSID_LENGTH + 1) * MRVDRV_MAX_SSID_LIST_LENGTH]  = {0};
819     const t_u8 *bssid                      = NULL;
820     wifi_scan_channel_list_t *chan_list    = NULL;
821     t_u8 channels[WIFI_SCAN_MAX_NUM_CHAN]  = {0};
822     mlan_scan_type scan_type               = MLAN_SCAN_TYPE_ACTIVE;
823 
824     if (!if_priv || !params)
825     {
826         supp_e("%s: Invalid params", __func__);
827         goto out;
828     }
829 
830     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
831 
832     if (wifi_if_ctx_rtos->scan_in_progress)
833     {
834         supp_d("%s: Scan already in progress", __func__);
835         ret = -EBUSY;
836         goto out;
837     }
838 
839     if (wifi_is_remain_on_channel())
840     {
841         supp_e("%s: Block scan while remaining on channel", __func__);
842         ret = -EBUSY;
843         goto out;
844     }
845 
846     wifi_d("initiating wifi-scan");
847 
848     if (params->freqs)
849     {
850         for (i = 0; params->freqs[i] && i < WIFI_SCAN_MAX_NUM_CHAN; i++)
851         {
852             channels[i] = freq_to_chan(params->freqs[i]);
853         }
854 
855         num_chans = i;
856     }
857     else
858     {
859         num_chans = 0;
860     }
861     uint8_t ssid_off = 0;
862     for (i = 0;  i < params->num_ssids; i++)
863     {
864         memcpy(ssid_v+ssid_off, (const char *)params->ssids[i].ssid, params->ssids[i].ssid_len);
865         ssid_off += params->ssids[i].ssid_len;
866         ssid_v[ssid_off] = '\0';
867         ssid_off++;
868     }
869 #if CONFIG_ROAMING
870     if (wlan_get_roaming_status() && mlan_adap->priv[0]->media_connected)
871     {
872         if (params->num_ssids == 1 && params->ssids[0].ssid_len == 0)
873         {
874              ssid_off = 0;
875              memcpy(ssid_v+ssid_off,
876                     mlan_adap->priv[0]->curr_bss_params.bss_descriptor.ssid.ssid,
877                     mlan_adap->priv[0]->curr_bss_params.bss_descriptor.ssid.ssid_len);
878              ssid_off += mlan_adap->priv[0]->curr_bss_params.bss_descriptor.ssid.ssid_len;
879              ssid_v[ssid_off] = '\0';
880              ssid_off++;
881         }
882     }
883 #endif
884     ssid = (const char *)&ssid_v;
885 #if 0
886 #if CONFIG_COMBO_SCAN
887     if (params->num_filter_ssids > 1)
888     {
889         if (params->filter_ssids[1].ssid_len)
890         {
891             memcpy(ssid_v2, (const char *)params->filter_ssids[1].ssid, params->filter_ssids[1].ssid_len);
892             ssid2 = (const char *)&ssid_v2;
893         }
894     }
895 #endif
896 #endif
897     /*
898      * no ssids means passive scan
899      * refer to woal_cfg80211_scan
900      */
901     if (!params->num_ssids)
902     {
903         scan_type = MLAN_SCAN_TYPE_PASSIVE;
904     }
905 
906     bssid = params->bssid;
907 
908     if (num_chans != 0)
909     {
910         chan_list = OSA_MemoryAllocate(sizeof(wifi_scan_channel_list_t) * num_chans);
911 
912         if (chan_list != NULL)
913         {
914             wifi_nxp_sort_channels(channels, num_chans);
915             for (i = 0; i < num_chans; i++)
916             {
917                 chan_list[i].chan_number = channels[i];
918                 chan_list[i].scan_type   = scan_type;
919                 chan_list[i].scan_time   = 100;
920             }
921         }
922     }
923 
924     if (params->extra_ies_len)
925     {
926         status = wifi_set_scan_ies((void *)params->extra_ies, params->extra_ies_len);
927 
928         if (status != WM_SUCCESS)
929         {
930             wifi_d("wifi set scan IEs failed");
931             goto out;
932         }
933     }
934 
935     wm_wifi.external_scan = false;
936     wm_wifi.wpa_supp_scan = true;
937 
938 #if CONFIG_WPA_SUPP_AP
939     wm_wifi.hostapd_op = false;
940 
941     if (wifi_if_ctx_rtos->hostapd)
942     {
943         wm_wifi.hostapd_op = true;
944     }
945 #endif
946 
947     status = wifi_send_scan_cmd(bss_mode, bssid, ssid, params->num_ssids, num_chans, chan_list, 0,
948 #if CONFIG_SCAN_WITH_RSSIFILTER
949                                 params->filter_rssi,
950 #endif
951 #if CONFIG_SCAN_CHANNEL_GAP
952                                 50U,
953 #endif
954                                 false, false);
955     if (status != WM_SUCCESS)
956     {
957         wifi_d("wifi send scan cmd failed");
958         goto out;
959     }
960 
961     wifi_if_ctx_rtos->scan_in_progress = true;
962     ret                                = 0;
963 out:
964     if (chan_list != NULL)
965     {
966         OSA_MemoryFree((void *)chan_list);
967     }
968 
969     return ret;
970 }
971 
wifi_nxp_wpa_supp_set_default_scan_ies(void * priv,const u8 * ies,size_t ies_len)972 int wifi_nxp_wpa_supp_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len)
973 {
974     int ret = -1;
975 
976     if ((!priv) || (!ies))
977     {
978         supp_e("%s: Invalid params", __func__);
979         goto out;
980     }
981 
982     ret = wifi_nxp_set_default_scan_ies(ies, ies_len);
983 
984     if (ret != WM_SUCCESS)
985     {
986         supp_e("%s: Default scan ies set failed", __func__);
987     }
988     else
989     {
990         supp_d("%s: Default scan ies set successfully", __func__);
991     }
992 out:
993     return ret;
994 }
995 
wifi_nxp_wpa_supp_sched_scan(void * if_priv,struct wpa_driver_scan_params * params)996 int wifi_nxp_wpa_supp_sched_scan(void *if_priv, struct wpa_driver_scan_params *params)
997 {
998     int status = -WM_FAIL;
999     // struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1000     int ret = -1;
1001     int i   = 0;
1002     nxp_wifi_trigger_sched_scan_t *wifi_sched_scan_params;
1003 
1004     if (!if_priv || !params)
1005     {
1006         supp_e("%s: Invalid params", __func__);
1007         goto out;
1008     }
1009 
1010     // wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1011 
1012     wifi_sched_scan_params = (nxp_wifi_trigger_sched_scan_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_trigger_sched_scan_t));
1013 
1014     if (!wifi_sched_scan_params)
1015     {
1016         supp_e("%s:  wifi sched scan params calloc failed", __func__);
1017         goto out;
1018     }
1019 
1020     if (params->num_ssids != 0U)
1021     {
1022         wifi_sched_scan_params->num_ssids = MIN(WIFI_SCAN_MAX_NUM_SSIDS, params->num_ssids);
1023 
1024         for (i = 0; i < wifi_sched_scan_params->num_ssids; i++)
1025         {
1026             memcpy(wifi_sched_scan_params->scan_ssids[i].ssid, (const unsigned char *)params->ssids[i].ssid,
1027                    params->ssids[i].ssid_len);
1028 
1029             wifi_sched_scan_params->scan_ssids[i].ssid_len = params->ssids[i].ssid_len;
1030         }
1031     }
1032 
1033     for (i = 0; params->freqs[i] && i < WIFI_SCAN_MAX_NUM_CHAN; i++)
1034     {
1035         wifi_sched_scan_params->chan_list[i] = freq_to_chan(params->freqs[i]);
1036     }
1037 
1038     wifi_sched_scan_params->num_chans = i;
1039 
1040     if ((params->extra_ies) && (params->extra_ies_len))
1041     {
1042         memcpy(wifi_sched_scan_params->extra_ies.ie, params->extra_ies, params->extra_ies_len);
1043         wifi_sched_scan_params->extra_ies.ie_len = params->extra_ies_len;
1044     }
1045 
1046     wifi_sched_scan_params->chan_per_scan = MIN(WLAN_BG_SCAN_CHAN_MAX, wifi_sched_scan_params->num_chans);
1047 
1048     wifi_sched_scan_params->scan_interval = MIN_BGSCAN_INTERVAL;
1049     wifi_sched_scan_params->repeat_count  = 2;
1050 
1051     wifi_sched_scan_params->report_condition = BG_SCAN_SSID_MATCH | BG_SCAN_WAIT_ALL_CHAN_DONE;
1052 
1053     wifi_sched_scan_params->filter_rssi = params->filter_rssi;
1054 
1055     status = wifi_send_sched_scan_cmd(wifi_sched_scan_params);
1056     if (status != WM_SUCCESS)
1057     {
1058         supp_e("%s: Sched Scan trigger failed", __func__);
1059         goto out;
1060     }
1061     ret = 0;
1062 out:
1063     return ret;
1064 }
1065 
wifi_nxp_wpa_supp_stop_sched_scan(void * if_priv)1066 int wifi_nxp_wpa_supp_stop_sched_scan(void *if_priv)
1067 {
1068     int status = WM_SUCCESS;
1069     int ret    = -1;
1070 
1071     if (!if_priv)
1072     {
1073         supp_e("%s: Invalid params", __func__);
1074         goto out;
1075     }
1076 
1077     status = wifi_send_stop_sched_scan_cmd();
1078     if (status != WM_SUCCESS)
1079     {
1080         supp_e("%s: wifi_supp_stop_sched_scan failed", __func__);
1081         goto out;
1082     }
1083     ret = 0;
1084 out:
1085     return ret;
1086 }
1087 
wifi_nxp_wpa_supp_scan_abort(void * if_priv)1088 int wifi_nxp_wpa_supp_scan_abort(void *if_priv)
1089 {
1090     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1091     int status                                 = -WM_FAIL;
1092 
1093     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1094 
1095     if (!wifi_if_ctx_rtos || (!wifi_if_ctx_rtos->scan_in_progress))
1096     {
1097         supp_e("%s:Ignore scan abort, no scan in progress", __func__);
1098         goto out;
1099     }
1100 
1101     wlan_abort_split_scan();
1102     wifi_user_scan_config_cleanup();
1103 
1104     status = WM_SUCCESS;
1105 
1106 out:
1107     return status;
1108 }
1109 
wifi_nxp_wpa_supp_proc_scan_res(nxp_wifi_event_new_scan_result_t * scan_res,struct wifi_nxp_ctx_rtos * wifi_if_ctx_rtos)1110 struct wpa_scan_res *wifi_nxp_wpa_supp_proc_scan_res(nxp_wifi_event_new_scan_result_t *scan_res,
1111                    struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos)
1112 {
1113     struct wpa_scan_res *r  = NULL;
1114     const unsigned char *ie = NULL;
1115     unsigned int ie_len     = 0;
1116     unsigned char *pos      = NULL;
1117 
1118     if (scan_res->ies.ie_len != 0U)
1119     {
1120         ie     = (const unsigned char *)scan_res->ies.ie;
1121         ie_len = scan_res->ies.ie_len;
1122     }
1123 
1124     r = (struct wpa_scan_res *)OSA_MemoryAllocate(sizeof(*r) + ie_len);
1125 
1126     if (!r)
1127     {
1128         supp_e("%s: Unable to calloc  memory for scan result\n", __func__);
1129         if (ie)
1130         {
1131             OSA_MemoryFree((void *)ie);
1132         }
1133         return NULL;
1134     }
1135 
1136     memcpy(r->bssid, scan_res->mac_addr, ETH_ALEN);
1137 
1138     r->freq = scan_res->frequency;
1139 
1140     r->beacon_int = scan_res->beacon_interval;
1141 
1142     r->caps = scan_res->capability;
1143 
1144     if (scan_res->noise == 0)
1145     {
1146         r->flags |= WPA_SCAN_NOISE_INVALID;
1147     }
1148     else
1149     {
1150         r->noise = scan_res->noise;
1151     }
1152 
1153     r->level = scan_res->rssi;
1154 
1155     r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID;
1156 
1157     (void)memcpy((void *)&r->tsf, (const void *)&scan_res->ies_tsf, sizeof(r->tsf));
1158 
1159     if (scan_res->beacon_ies_tsf > r->tsf)
1160     {
1161         (void)memcpy((void *)&r->tsf, (const void *)&scan_res->beacon_ies_tsf, sizeof(r->tsf));
1162     }
1163 
1164     if (scan_res->seen_ms_ago)
1165     {
1166         r->age = scan_res->seen_ms_ago;
1167     }
1168 
1169     (void)memcpy((void *)&r->parent_tsf, (const void *)&scan_res->ies_tsf, sizeof(r->parent_tsf));
1170 
1171     memcpy(r->tsf_bssid, wifi_if_ctx_rtos->scan_start_tsf_bssid, ETH_ALEN);
1172 
1173     r->ie_len = ie_len;
1174 
1175     pos = (unsigned char *)(r + 1);
1176 
1177     if (ie_len)
1178     {
1179         memcpy(pos, ie, ie_len);
1180 
1181         pos += ie_len;
1182 
1183         OSA_MemoryFree((void *)ie);
1184     }
1185 
1186     if (scan_res->status)
1187     {
1188         r->flags |= WPA_SCAN_ASSOCIATED;
1189     }
1190 
1191     return r;
1192 }
1193 
wifi_nxp_wpa_supp_scan_results_get(void * if_priv)1194 int wifi_nxp_wpa_supp_scan_results_get(void *if_priv)
1195 {
1196     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1197     int ret = -1;
1198     unsigned int i, num;
1199     nxp_wifi_event_new_scan_result_t scan_res;
1200     struct wpa_scan_res *sr = NULL;
1201 
1202     if (!if_priv)
1203     {
1204         supp_e("%s: Invalid params", __func__);
1205         goto out;
1206     }
1207 
1208     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1209 
1210     num = wifi_nxp_scan_res_num();
1211 
1212     if (num == 0)
1213     {
1214         supp_d("%s: No networks found", __func__);
1215         goto out;
1216     }
1217 
1218     for (i = 0; i < num; i++)
1219     {
1220         memset(&scan_res, 0, sizeof(nxp_wifi_event_new_scan_result_t));
1221         (void)wifi_nxp_scan_res_get2(i, &scan_res);
1222 
1223         sr = wifi_nxp_wpa_supp_proc_scan_res(&scan_res, wifi_if_ctx_rtos);
1224 
1225         if (sr)
1226         {
1227             wifi_if_ctx_rtos->supp_callbk_fns.scan_res(wifi_if_ctx_rtos->supp_drv_if_ctx, sr, i == num -1 ? false : true);
1228             OSA_MemoryFree((void *)sr);
1229             sr = NULL;
1230         }
1231     }
1232 
1233     ret = 0;
1234 out:
1235     return ret;
1236 }
1237 
wifi_nxp_wpa_supp_survey_results_get(void * if_priv)1238 int wifi_nxp_wpa_supp_survey_results_get(void *if_priv)
1239 {
1240     int status                                 = WM_SUCCESS;
1241     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1242     int ret                                    = -1;
1243     nxp_wifi_trigger_op_t *wifi_survey_params;
1244 
1245     if (!if_priv)
1246     {
1247         supp_e("%s: Invalid params", __func__);
1248         goto out;
1249     }
1250 
1251     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1252 
1253     wifi_survey_params = (nxp_wifi_trigger_op_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_trigger_op_t));
1254 
1255     if (!wifi_survey_params)
1256     {
1257         supp_e("%s:  wifi survey params calloc failed", __func__);
1258         goto out;
1259     }
1260 
1261     wifi_survey_params->hostapd = wifi_if_ctx_rtos->hostapd;
1262 
1263     status = wifi_event_completion(WIFI_EVENT_SURVEY_RESULT_GET, WIFI_EVENT_REASON_SUCCESS, wifi_survey_params);
1264     if (status != WM_SUCCESS)
1265     {
1266         supp_e("%s: wifi_supp_survey_res_get failed", __func__);
1267         OSA_MemoryFree(wifi_survey_params);
1268         goto out;
1269     }
1270     ret = 0;
1271 out:
1272     return ret;
1273 }
1274 
wifi_nxp_wpa_supp_deauthenticate(void * if_priv,const char * addr,unsigned short reason_code)1275 int wifi_nxp_wpa_supp_deauthenticate(void *if_priv, const char *addr, unsigned short reason_code)
1276 {
1277     int status = -WM_FAIL;
1278     int ret    = -1;
1279     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1280 
1281     if ((!if_priv) || (!addr))
1282     {
1283         supp_e("%s: Invalid params", __func__);
1284         goto out;
1285     }
1286 
1287     wifi_d("initiating wifi-deauth");
1288 
1289     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1290     if (wifi_if_ctx_rtos->ft_roaming)
1291     {
1292         wifi_if_ctx_rtos->ft_roaming = false;
1293     }
1294 
1295     status = wifi_nxp_deauthenticate(MLAN_BSS_TYPE_STA, (const unsigned char *)addr, reason_code);
1296 
1297     if (status != WM_SUCCESS)
1298     {
1299         supp_e("%s: wifi_nxp_wpa_supp_deauthenticate failed", __func__);
1300         goto out;
1301     }
1302     ret = 0;
1303 out:
1304     return ret;
1305 }
1306 
1307 #if 0
1308 int wifi_nxp_wpa_supp_add_key(struct nxp_wifi_umac_key_info *key_info, enum wpa_alg alg,
1309 			      int key_idx,
1310 			      int defkey, const unsigned char *seq, size_t seq_len,
1311 			      const unsigned char *key, size_t key_len)
1312 {
1313 	unsigned int suite = 0;
1314 
1315 	suite = wpa_alg_to_cipher_suite(alg, key_len);
1316 
1317 	if (!suite) {
1318 		return -1;
1319 	}
1320 
1321 	if (defkey && alg == WPA_ALG_BIP_CMAC_128) {
1322 		key_info->nxp_wifi_flags = NXP_WIFI_KEY_DEFAULT_MGMT;
1323 	} else if (defkey) {
1324 		key_info->nxp_wifi_flags = NXP_WIFI_KEY_DEFAULT;
1325 	}
1326 
1327 	key_info->key_idx = key_idx;
1328 	key_info->cipher_suite = suite;
1329 
1330 	if (key && key_len) {
1331 		memcpy(key_info->key.nxp_wifi_key, key, key_len);
1332 		key_info->key.nxp_wifi_key_len = key_len;
1333 	}
1334 	if (seq && seq_len) {
1335 		memcpy(key_info->seq.nxp_wifi_seq, seq, seq_len);
1336 		key_info->seq.nxp_wifi_seq_len = seq_len;
1337 	}
1338 
1339 	return 0;
1340 }
1341 #endif
1342 
wifi_nxp_wpa_supp_save_pairwise_key_params(struct wifi_nxp_ctx_rtos * if_ctx,const unsigned char * ifname,enum wpa_alg alg,const unsigned char * addr,int key_idx,int set_tx,const unsigned char * seq,size_t seq_len,const unsigned char * key,size_t key_len,enum key_flag key_flag)1343 static int wifi_nxp_wpa_supp_save_pairwise_key_params(struct wifi_nxp_ctx_rtos *if_ctx,
1344                                                       const unsigned char *ifname,
1345                                                       enum wpa_alg alg,
1346                                                       const unsigned char *addr,
1347                                                       int key_idx,
1348                                                       int set_tx,
1349                                                       const unsigned char *seq,
1350                                                       size_t seq_len,
1351                                                       const unsigned char *key,
1352                                                       size_t key_len,
1353                                                       enum key_flag key_flag)
1354 {
1355     int ret = -1;
1356 
1357     if (if_ctx->key_params)
1358     {
1359         wifi_nxp_wpa_supp_free_pairwise_key_params(if_ctx->key_params);
1360         if_ctx->key_params = NULL;
1361     }
1362 
1363     if_ctx->key_params = (struct wpa_driver_set_key_params *)os_zalloc(sizeof(struct wpa_driver_set_key_params));
1364 
1365     if (!if_ctx->key_params)
1366     {
1367         wpa_printf(MSG_DEBUG, "%s: failed to alloc", __func__);
1368         return -1;
1369     }
1370 
1371     if (ifname)
1372     {
1373         if_ctx->key_params->ifname = os_strdup(ifname);
1374         if (!if_ctx->key_params->ifname)
1375         {
1376             wpa_printf(MSG_DEBUG, "%s: failed to alloc ifname", __func__);
1377             goto out;
1378         }
1379     }
1380 
1381     if (addr)
1382     {
1383         if_ctx->key_params->addr = os_memdup(addr, ETH_ALEN);
1384         if (!if_ctx->key_params->addr)
1385         {
1386             wpa_printf(MSG_DEBUG, "%s: failed to alloc addr", __func__);
1387             goto out;
1388         }
1389     }
1390 
1391     if (seq)
1392     {
1393         if_ctx->key_params->seq = os_memdup(seq, seq_len);
1394         if (!if_ctx->key_params->seq)
1395         {
1396             wpa_printf(MSG_DEBUG, "%s: failed to alloc seq", __func__);
1397             goto out;
1398         }
1399         if_ctx->key_params->seq_len = seq_len;
1400     }
1401 
1402     if (key)
1403     {
1404         if_ctx->key_params->key = os_memdup(key, key_len);
1405         if (!if_ctx->key_params->key)
1406         {
1407             wpa_printf(MSG_DEBUG, "%s: failed to alloc key", __func__);
1408             goto out;
1409         }
1410         if_ctx->key_params->key_len = key_len;
1411     }
1412 
1413     if_ctx->key_params->alg      = alg;
1414     if_ctx->key_params->key_idx  = key_idx;
1415     if_ctx->key_params->set_tx   = set_tx;
1416     if_ctx->key_params->key_flag = key_flag;
1417 
1418     ret = 0;
1419 out:
1420     if (ret)
1421     {
1422         wifi_nxp_wpa_supp_free_pairwise_key_params(if_ctx->key_params);
1423         if_ctx->key_params = NULL;
1424     }
1425     return ret;
1426 }
1427 
wifi_nxp_wpa_supp_authenticate(void * if_priv,struct wpa_driver_auth_params * params,struct wpa_bss * curr_bss)1428 int wifi_nxp_wpa_supp_authenticate(void *if_priv, struct wpa_driver_auth_params *params, struct wpa_bss *curr_bss)
1429 {
1430     int status         = -WM_FAIL;
1431     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1432     unsigned char *pos = NULL;
1433     unsigned char auth_alg;
1434     unsigned char auth_trans_num[2] = {1, 0};
1435     unsigned char status_code[2]    = {0, 0};
1436     int ret                         = -1;
1437     unsigned short len              = 0;
1438     int channel;
1439 
1440     if ((!if_priv) || (!params))
1441     {
1442         supp_e("%s: Invalid params", __func__);
1443         goto out;
1444     }
1445 
1446     if (params->local_state_change)
1447     {
1448         /* This is just a notify info */
1449         ret = 0;
1450         goto out;
1451     }
1452 
1453     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1454     auth_alg = get_algo_from_auth_type(params->auth_alg);
1455 
1456     wifi_if_ctx_rtos->ft_roaming = false;
1457     if (params->auth_alg == WPA_AUTH_ALG_FT)
1458     {
1459         pos = (unsigned char *)params->ie;
1460         len = params->ie_len;
1461         wifi_if_ctx_rtos->ft_roaming = true;
1462     }
1463     else if ((params->auth_data != NULL) && (params->auth_data_len >= 4))
1464     {
1465         pos = (unsigned char *)params->auth_data;
1466 
1467         auth_trans_num[0] = pos[0];
1468         auth_trans_num[1] = pos[1];
1469         status_code[0]    = pos[2];
1470         status_code[1]    = pos[3];
1471         pos += 4;
1472         len = params->auth_data_len - 4;
1473     }
1474 
1475     channel = freq_to_chan(params->freq);
1476 
1477     wifi_d("initiating wifi-auth");
1478 
1479     status = wifi_send_mgmt_auth_request(channel, auth_alg, auth_trans_num, status_code, params->bssid,
1480                                          (const unsigned char *)pos, len);
1481 
1482     if (status != WM_SUCCESS)
1483     {
1484         supp_e("%s: MLME command failed (auth): ret=%d", __func__, ret);
1485         ret = -1;
1486     }
1487     else
1488     {
1489         supp_d("%s:Authentication request sent successfully", __func__);
1490         ret = 0;
1491     }
1492 out:
1493     return ret;
1494 }
1495 
wifi_nxp_wpa_supp_associate(void * if_priv,struct wpa_driver_associate_params * params)1496 int wifi_nxp_wpa_supp_associate(void *if_priv, struct wpa_driver_associate_params *params)
1497 {
1498     int status                                 = -WM_FAIL;
1499     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1500     nxp_wifi_assoc_info_t *assoc_params;
1501     int ret = -1;
1502 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
1503     t_u8 mfpc, mfpr;
1504 #endif
1505     if ((!if_priv) || (!params))
1506     {
1507         supp_e("%s: Invalid params", __func__);
1508         goto out;
1509     }
1510 
1511     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1512 
1513     assoc_params = (nxp_wifi_assoc_info_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_assoc_info_t));
1514 
1515     if (!assoc_params)
1516     {
1517         supp_e("%s: assoc params calloc failed", __func__);
1518         goto out;
1519     }
1520 
1521     wifi_if_ctx_rtos->associated = false;
1522 
1523     if (params->auth_alg & WPA_AUTH_ALG_FT)
1524     {
1525         assoc_params->is_ft = true;
1526     }
1527 
1528 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
1529     if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED)
1530     {
1531         mfpc = 1;
1532         mfpr = 1;
1533     }
1534     else if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL)
1535     {
1536         mfpc = 1;
1537         mfpr = 0;
1538     }
1539     else
1540     {
1541         mfpc = 0;
1542         mfpr = 0;
1543     }
1544     wifi_set_pmfcfg(mfpc, mfpr);
1545 #endif
1546 
1547     if (params->bssid)
1548     {
1549         memcpy(&wifi_if_ctx_rtos->attempt_bssid, params->bssid, ETH_ALEN);
1550 
1551         memcpy(assoc_params->bssid, params->bssid, WIFI_ETH_ADDR_LEN);
1552     }
1553 
1554     if (params->prev_bssid)
1555     {
1556         memcpy(assoc_params->prev_bssid, params->prev_bssid, sizeof(assoc_params->prev_bssid));
1557     }
1558 
1559     if (params->freq.freq)
1560     {
1561         int channel           = freq_to_chan(params->freq.freq);
1562         assoc_params->channel = channel;
1563 
1564         wifi_if_ctx_rtos->assoc_freq = params->freq.freq;
1565     }
1566     else
1567     {
1568         wifi_if_ctx_rtos->assoc_freq = 0;
1569     }
1570 
1571     if (params->ssid)
1572     {
1573         assoc_params->ssid.ssid_len = params->ssid_len;
1574 
1575         memcpy(assoc_params->ssid.ssid, params->ssid, params->ssid_len);
1576     }
1577 
1578     if (params->wpa_ie)
1579     {
1580         assoc_params->wpa_ie.ie_len = params->wpa_ie_len;
1581         memcpy(assoc_params->wpa_ie.ie, params->wpa_ie, params->wpa_ie_len);
1582     }
1583 
1584     assoc_params->control_port = 1;
1585 
1586     wifi_d("initiating wifi-assoc");
1587 
1588     status = wifi_nxp_send_assoc(assoc_params);
1589 
1590     if (status != WM_SUCCESS)
1591     {
1592         supp_e("%s: MLME command failed (assoc)", __func__);
1593     }
1594     else
1595     {
1596         supp_d("%s: Association request sent successfully", __func__);
1597         ret = 0;
1598     }
1599     OSA_MemoryFree((void *)assoc_params);
1600 
1601 out:
1602     return ret;
1603 }
1604 
_wifi_nxp_wpa_supp_set_key(void * if_priv,const unsigned char * ifname,enum wpa_alg alg,const unsigned char * addr,int key_idx,int set_tx,const unsigned char * seq,size_t seq_len,const unsigned char * key,size_t key_len,enum key_flag key_flag)1605 static int _wifi_nxp_wpa_supp_set_key(void *if_priv,
1606                                       const unsigned char *ifname,
1607                                       enum wpa_alg alg,
1608                                       const unsigned char *addr,
1609                                       int key_idx,
1610                                       int set_tx,
1611                                       const unsigned char *seq,
1612                                       size_t seq_len,
1613                                       const unsigned char *key,
1614                                       size_t key_len,
1615                                       enum key_flag key_flag)
1616 
1617 {
1618     int status                                 = -WM_FAIL;
1619     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1620     unsigned int flags                         = 0;
1621     int ret                                    = -1;
1622     bool is_pairwise                           = false;
1623     int skip_set_key                           = 1;
1624 
1625     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1626     if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == KEY_FLAG_PAIRWISE_RX_TX_MODIFY)
1627     {
1628         supp_d("SET_KEY (pairwise RX/TX modify)");
1629     }
1630     else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX))
1631     {
1632         supp_d("%s: invalid key_flag to delete key", __func__);
1633         ret = -1;
1634         goto out;
1635     }
1636     else if (alg == WPA_ALG_NONE)
1637     {
1638         supp_d("DEL_KEY");
1639 
1640         status = wifi_remove_key(wifi_if_ctx_rtos->bss_type, is_pairwise, key_idx, addr);
1641 
1642         if (status != WM_SUCCESS)
1643         {
1644             supp_e("%s: wifi_nxp_del_key failed", __func__);
1645         }
1646         else
1647         {
1648             ret = 0;
1649         }
1650     }
1651     else
1652     {
1653         flags = wpa_alg_to_cipher_suite(alg, key_len);
1654 
1655         /* TODO: Implement/check set_tx */
1656         if (addr && !is_broadcast_ether_addr(addr))
1657         {
1658             is_pairwise = true;
1659             if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == KEY_FLAG_PAIRWISE_RX ||
1660                 (key_flag & KEY_FLAG_PAIRWISE_MASK) == KEY_FLAG_PAIRWISE_RX_TX_MODIFY)
1661             {
1662             }
1663             else if ((key_flag & KEY_FLAG_GROUP_MASK) == KEY_FLAG_GROUP_RX)
1664             {
1665             }
1666             else if (!(key_flag & KEY_FLAG_PAIRWISE))
1667             {
1668                 supp_d("   key_flag missing PAIRWISE when setting a pairwise key");
1669                 ret = -1;
1670                 goto out;
1671             }
1672             else if (alg == WPA_ALG_WEP && (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX)
1673             {
1674                 supp_d("   unicast WEP key");
1675                 skip_set_key = 0;
1676             }
1677             else
1678             {
1679                 supp_d("   pairwise key");
1680             }
1681         }
1682         else if ((key_flag & KEY_FLAG_PAIRWISE) || !(key_flag & KEY_FLAG_GROUP))
1683         {
1684             supp_d("   invalid key_flag for a broadcast key");
1685             ret = -1;
1686             goto out;
1687         }
1688         else
1689         {
1690             supp_d("   broadcast key");
1691             is_pairwise = false;
1692             if (key_flag & KEY_FLAG_DEFAULT)
1693                 skip_set_key = 0;
1694         }
1695 
1696         status =
1697             wifi_set_key(wifi_if_ctx_rtos->bss_type, is_pairwise, key_idx, key, key_len, seq, seq_len, addr, flags);
1698 
1699         if (status != WM_SUCCESS)
1700         {
1701             supp_e("%s: wifi_set_key failed", __func__);
1702         }
1703         else
1704         {
1705             ret = 0;
1706         }
1707 
1708         if (ret || skip_set_key)
1709             return ret;
1710     }
1711 out:
1712     return ret;
1713 }
1714 
wifi_nxp_wpa_supp_set_key(void * if_priv,const unsigned char * ifname,enum wpa_alg alg,const unsigned char * addr,int key_idx,int set_tx,const unsigned char * seq,size_t seq_len,const unsigned char * key,size_t key_len,enum key_flag key_flag)1715 int wifi_nxp_wpa_supp_set_key(void *if_priv,
1716                               const unsigned char *ifname,
1717                               enum wpa_alg alg,
1718                               const unsigned char *addr,
1719                               int key_idx,
1720                               int set_tx,
1721                               const unsigned char *seq,
1722                               size_t seq_len,
1723                               const unsigned char *key,
1724                               size_t key_len,
1725                               enum key_flag key_flag)
1726 
1727 {
1728     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1729 
1730     if ((!if_priv) || (!ifname))
1731     {
1732         supp_e("%s: Invalid params", __func__);
1733         return -1;
1734     }
1735 
1736     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1737 
1738     if (wifi_if_ctx_rtos->ft_roaming && (key_flag & KEY_FLAG_PAIRWISE)) {
1739         return wifi_nxp_wpa_supp_save_pairwise_key_params(wifi_if_ctx_rtos, ifname, alg,
1740                                                           addr, key_idx, set_tx, seq, seq_len,
1741                                                           key, key_len, key_flag);
1742     }
1743 
1744     if (wifi_if_ctx_rtos->ft_roaming && (key_flag & KEY_FLAG_GROUP)) {
1745         if (wifi_if_ctx_rtos->key_params &&
1746             (wifi_if_ctx_rtos->key_params->key_flag & KEY_FLAG_PAIRWISE)) {
1747             _wifi_nxp_wpa_supp_set_key(if_priv, (const unsigned char *)wifi_if_ctx_rtos->key_params->ifname,
1748                                        wifi_if_ctx_rtos->key_params->alg, wifi_if_ctx_rtos->key_params->addr,
1749                                        wifi_if_ctx_rtos->key_params->key_idx, wifi_if_ctx_rtos->key_params->set_tx,
1750                                        wifi_if_ctx_rtos->key_params->seq, wifi_if_ctx_rtos->key_params->seq_len,
1751                                        wifi_if_ctx_rtos->key_params->key, wifi_if_ctx_rtos->key_params->key_len,
1752                                        wifi_if_ctx_rtos->key_params->key_flag);
1753             wifi_nxp_wpa_supp_free_pairwise_key_params(wifi_if_ctx_rtos->key_params);
1754             wifi_if_ctx_rtos->key_params = NULL;
1755         }
1756     }
1757     return _wifi_nxp_wpa_supp_set_key(if_priv, ifname, alg, addr, key_idx, set_tx, seq, seq_len, key, key_len, key_flag);
1758 }
1759 
wifi_nxp_wpa_supp_del_key(void * if_priv,const unsigned char * addr,int key_idx)1760 int wifi_nxp_wpa_supp_del_key(void *if_priv, const unsigned char *addr, int key_idx)
1761 
1762 {
1763     int status                                 = -WM_FAIL;
1764     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1765     int ret                                    = -1;
1766 
1767     if (!if_priv)
1768     {
1769         supp_e("%s: Invalid params", __func__);
1770         goto out;
1771     }
1772 
1773     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1774 
1775     status = wifi_remove_key(wifi_if_ctx_rtos->bss_type, 0, key_idx, addr);
1776 
1777     if (status != WM_SUCCESS)
1778     {
1779         supp_e("%s: wifi_nxp_del_key failed", __func__);
1780     }
1781     else
1782     {
1783         ret = 0;
1784     }
1785 
1786 out:
1787     return ret;
1788 }
1789 
wifi_nxp_wpa_supp_set_rekey_info(void * if_priv,const u8 * kek,size_t kek_len,const u8 * kck,size_t kck_len,const u8 * replay_ctr)1790 int wifi_nxp_wpa_supp_set_rekey_info(
1791     void *if_priv, const u8 *kek, size_t kek_len, const u8 *kck, size_t kck_len, const u8 *replay_ctr)
1792 {
1793     int status                                 = -WM_FAIL;
1794     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1795     int ret                                    = -1;
1796 
1797     if ((!if_priv) || (!kek) || (!kck) || (!replay_ctr))
1798     {
1799         supp_e("%s: Invalid params", __func__);
1800         goto out;
1801     }
1802 
1803     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1804 
1805     status = wifi_set_rekey_info(wifi_if_ctx_rtos->bss_type, kek, kek_len, kck, kck_len, replay_ctr);
1806 
1807     if (status != WM_SUCCESS)
1808     {
1809         supp_e("%s: wifi_set_rekey_info failed", __func__);
1810         goto out;
1811     }
1812     else
1813     {
1814         ret = 0;
1815     }
1816 
1817 out:
1818     return ret;
1819 }
1820 
wifi_nxp_wpa_supp_set_supp_port(void * if_priv,int authorized,char * bssid)1821 int wifi_nxp_wpa_supp_set_supp_port(void *if_priv, int authorized, char *bssid)
1822 {
1823     int ret                                    = -1;
1824     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1825 
1826     if ((!if_priv) || (!bssid))
1827     {
1828         supp_e("%s: Invalid params", __func__);
1829         goto out;
1830     }
1831 
1832     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1833 
1834     wifi_d("initiating wifi-set-port authorized: %d", authorized);
1835 
1836     if (wifi_if_ctx_rtos->associated)
1837     {
1838 #if CONFIG_WPA_SUPP_WPS
1839         if (!wifi_nxp_wps_session_enable())
1840         {
1841 #endif
1842             if (authorized)
1843             {
1844 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
1845                 (void)wifi_event_completion(WIFI_EVENT_AUTHENTICATION, WIFI_EVENT_REASON_SUCCESS, NULL);
1846 #endif
1847             }
1848 #if CONFIG_WPA_SUPP_WPS
1849         }
1850 #endif
1851     }
1852     if (authorized == 0U)
1853     {
1854         wlan_abort_split_scan();
1855         wifi_user_scan_config_cleanup();
1856     }
1857 
1858 #if CONFIG_ROAMING
1859     wlan_subscribe_rssi_low_event();
1860 #endif
1861     ret = 0;
1862 out:
1863     return ret;
1864 }
1865 
wifi_nxp_wpa_supp_set_country(void * if_priv,const char * alpha2)1866 int wifi_nxp_wpa_supp_set_country(void *if_priv, const char *alpha2)
1867 {
1868     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1869     int ret                                    = -WM_FAIL;
1870     char country[COUNTRY_CODE_LEN]             = {0};
1871     t_u8 region_code                           = 0;
1872     unsigned char country3                     = 0x20;
1873 
1874     if ((!if_priv) || (!alpha2))
1875     {
1876         supp_e("%s: Invalid params", __func__);
1877         goto out;
1878     }
1879 
1880     if ((alpha2[2] == 0x4f) || (alpha2[2] == 0x49) || (alpha2[2] == 0x58) || (alpha2[2] == 0x04))
1881     {
1882         country3 = alpha2[2];
1883     }
1884 
1885     country[0] = alpha2[0];
1886     country[1] = alpha2[1];
1887     country[2] = country3;
1888 
1889     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1890 
1891 #if CONFIG_WPA_SUPP_AP
1892     wm_wifi.hostapd_op = false;
1893 
1894     if (wifi_if_ctx_rtos->hostapd)
1895     {
1896         wm_wifi.hostapd_op = true;
1897     }
1898 #endif
1899     ret = wlan_11d_region_2_code(mlan_adap, (t_u8 *)country, &region_code);
1900     if(ret != WM_SUCCESS)
1901     {
1902         wlcm_e("%s: Invalid country code.", country);
1903         goto out;
1904     }
1905 
1906     ret              = wifi_nxp_set_country(wifi_if_ctx_rtos->bss_type, alpha2);
1907     if (ret != WM_SUCCESS)
1908     {
1909         goto out;
1910     }
1911 
1912 #if CONFIG_COMPRESS_TX_PWTBL
1913     ret = wlan_set_rg_power_cfg(region_code);
1914     if (ret != WM_SUCCESS)
1915     {
1916         goto out;
1917     }
1918 #endif
1919 
1920 #if defined(RW610) && ((CONFIG_COMPRESS_RU_TX_PWTBL) && (CONFIG_11AX))
1921     ret = wlan_set_ru_power_cfg(region_code);
1922     if (ret != WM_SUCCESS)
1923     {
1924         return -WM_FAIL;
1925     }
1926 #endif
1927 
1928     return ret;
1929 
1930 out:
1931     return -1;
1932 }
1933 
wifi_nxp_wpa_supp_get_country(void * if_priv,char * alpha2)1934 int wifi_nxp_wpa_supp_get_country(void *if_priv, char *alpha2)
1935 {
1936     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1937 
1938     if ((!if_priv) || (!alpha2))
1939     {
1940         supp_e("%s: Invalid params", __func__);
1941         goto out;
1942     }
1943 
1944     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1945 
1946     return wifi_nxp_get_country(wifi_if_ctx_rtos->bss_type, alpha2);
1947 
1948 out:
1949     return -1;
1950 }
1951 
wifi_rate_to_signal_info(wlan_ds_rate * ds_rate,struct wpa_signal_info * si)1952 static int wifi_rate_to_signal_info(wlan_ds_rate *ds_rate, struct wpa_signal_info *si)
1953 {
1954     wifi_data_rate_t *datarate = (wifi_data_rate_t *)&ds_rate->param.data_rate;
1955     /* refer to legacy rates */
1956     int lg_rate[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54};
1957 
1958     if (datarate->tx_rate_format == MLAN_RATE_FORMAT_LG && datarate->tx_data_rate < 12)
1959     {
1960         /* Legacy rates (in Kbps) */
1961         si->data.current_tx_rate = lg_rate[datarate->tx_data_rate]*1000;
1962     }
1963     else if (datarate->tx_rate_format <= 3)
1964     {
1965         /* HT, VHT, HE rates (in Kbps) */
1966         si->data.current_tx_rate = (datarate->tx_data_rate >> 1)*1000;
1967     }
1968 
1969     return WM_SUCCESS;
1970 }
1971 
wifi_nxp_wpa_supp_signal_poll(void * if_priv,struct wpa_signal_info * si,unsigned char * bssid)1972 int wifi_nxp_wpa_supp_signal_poll(void *if_priv, struct wpa_signal_info *si, unsigned char *bssid)
1973 {
1974     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
1975     int ret                                    = -WM_FAIL;
1976     nxp_wifi_signal_info_t signal_params;
1977     wlan_ds_rate ds_rate = {0};
1978 
1979     if (!if_priv || !si || !bssid)
1980     {
1981         supp_e("%s: Invalid params\r\n", __func__);
1982         goto out;
1983     }
1984 
1985     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
1986 
1987     ret = wifi_nxp_get_signal(wifi_if_ctx_rtos->bss_type, &signal_params);
1988     if (ret != WM_SUCCESS)
1989     {
1990         supp_e("%s: wifi_nxp_get_signal failed", __func__);
1991         goto out;
1992     }
1993 
1994     memset(si, 0x00, sizeof(struct wpa_signal_info));
1995 
1996     si->frequency         = wifi_if_ctx_rtos->assoc_freq;
1997     si->data.signal    = signal_params.current_signal;
1998     si->data.avg_signal        = signal_params.avg_signal;
1999     si->data.avg_beacon_signal = signal_params.avg_beacon_signal;
2000     si->current_noise     = signal_params.current_noise;
2001 
2002     ds_rate.sub_command = WIFI_DS_GET_DATA_RATE;
2003     ret = wlan_get_data_rate(&ds_rate, WLAN_BSS_TYPE_STA);
2004     if (ret != WM_SUCCESS)
2005     {
2006         supp_e("%s: wifi_nxp_get_signal rate failed", __func__);
2007         goto out;
2008     }
2009 
2010     ret = wifi_rate_to_signal_info(&ds_rate, si);
2011     if (ret != WM_SUCCESS)
2012     {
2013         supp_e("%s: wifi_nxp_get_signal rate convert failed", __func__);
2014         goto out;
2015     }
2016 
2017 out:
2018     return ret;
2019 }
2020 
wifi_nxp_wpa_supp_event_acs_channel_selected(void * if_priv,nxp_wifi_acs_params * acs_params)2021 void wifi_nxp_wpa_supp_event_acs_channel_selected(void *if_priv, nxp_wifi_acs_params *acs_params)
2022 {
2023     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2024     union wpa_event_data event;
2025 
2026     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2027 
2028     if (!if_priv)
2029     {
2030         supp_e("%s: Missing interface context", __func__);
2031         return;
2032     }
2033 
2034     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2035 
2036     memset(&event, 0, sizeof(event));
2037 
2038     if (!acs_params)
2039     {
2040         supp_e("%s: Missing acs params data", __func__);
2041         return;
2042     }
2043 
2044     event.acs_selected_channels.pri_freq = acs_params->pri_freq;
2045     event.acs_selected_channels.sec_freq = acs_params->sec_freq;
2046     event.acs_selected_channels.ch_width = acs_params->ch_width;
2047     event.acs_selected_channels.hw_mode  = (enum hostapd_hw_mode)acs_params->hw_mode;
2048 
2049 #if CONFIG_WPA_SUPP_AP
2050     if (wifi_if_ctx_rtos->hostapd)
2051     {
2052         wifi_if_ctx_rtos->hostapd_callbk_fns.acs_channel_sel(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
2053     }
2054     else
2055 #endif
2056     {
2057 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
2058         wifi_if_ctx_rtos->supp_callbk_fns.acs_channel_sel(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2059 #endif
2060     }
2061 }
2062 
wifi_nxp_wpa_supp_event_mgmt_tx_status(void * if_priv,nxp_wifi_event_mlme_t * mlme_event,unsigned int event_len)2063 void wifi_nxp_wpa_supp_event_mgmt_tx_status(void *if_priv, nxp_wifi_event_mlme_t *mlme_event, unsigned int event_len)
2064 {
2065     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2066 
2067     if (!if_priv)
2068     {
2069         supp_e("%s: Missing interface context", __func__);
2070         return;
2071     }
2072 
2073     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2074 
2075     if (!mlme_event)
2076     {
2077         supp_e("%s: Missing MLME event data", __func__);
2078         return;
2079     }
2080 
2081     if (wifi_if_ctx_rtos->mgmt_tx_status == 0U)
2082     {
2083         supp_d("%s: Only send mgmt tx status", __func__);
2084         return;
2085     }
2086 
2087     if (wifi_if_ctx_rtos->last_mgmt_tx_data_len && wifi_if_ctx_rtos->mgmt_tx_status)
2088     {
2089         memcpy((void *)mlme_event->frame.frame, (const void *)wifi_if_ctx_rtos->last_mgmt_tx_data,
2090                (size_t)wifi_if_ctx_rtos->last_mgmt_tx_data_len);
2091         mlme_event->frame.frame_len             = wifi_if_ctx_rtos->last_mgmt_tx_data_len;
2092         wifi_if_ctx_rtos->last_mgmt_tx_data_len = 0;
2093         wifi_if_ctx_rtos->mgmt_tx_status        = 0;
2094     }
2095 
2096     wifi_if_ctx_rtos->mgmt_tx_status = 0;
2097 
2098     if (mlme_event->frame.frame_len == 0)
2099     {
2100         supp_d("%s: mgmt tx status frame invalid", __func__);
2101         return;
2102     }
2103 
2104 #if CONFIG_WPA_SUPP_AP
2105     if (wifi_if_ctx_rtos->hostapd)
2106     {
2107         wifi_if_ctx_rtos->hostapd_callbk_fns.mgmt_tx_status(wifi_if_ctx_rtos->hapd_drv_if_ctx,
2108                                                             (const unsigned char *)mlme_event->frame.frame,
2109                                                             mlme_event->frame.frame_len, true);
2110     }
2111     else
2112 #endif
2113     {
2114         wifi_if_ctx_rtos->supp_callbk_fns.mgmt_tx_status(wifi_if_ctx_rtos->supp_drv_if_ctx,
2115                                                          (const unsigned char *)mlme_event->frame.frame,
2116                                                          mlme_event->frame.frame_len, true);
2117     }
2118 }
2119 
wifi_nxp_wpa_supp_event_proc_unprot_mgmt(void * if_priv,nxp_wifi_event_mlme_t * unprot_mgmt,unsigned int event_len)2120 void wifi_nxp_wpa_supp_event_proc_unprot_mgmt(void *if_priv, nxp_wifi_event_mlme_t *unprot_mgmt, unsigned int event_len)
2121 {
2122     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2123     union wpa_event_data event;
2124     const struct ieee80211_mgmt *mgmt = NULL;
2125     const unsigned char *frame        = NULL;
2126     unsigned int frame_len            = 0;
2127 
2128     if (!if_priv)
2129     {
2130         supp_e("%s: Missing interface context", __func__);
2131         return;
2132     }
2133 
2134     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2135 
2136     frame     = (const unsigned char *)unprot_mgmt->frame.frame;
2137     frame_len = unprot_mgmt->frame.frame_len;
2138 
2139     mgmt = (const struct ieee80211_mgmt *)frame;
2140 
2141     if (frame_len < 24 + sizeof(mgmt->u.deauth))
2142     {
2143         supp_e("%s: Unprotected mgmt frame too short", __func__);
2144         return;
2145     }
2146 
2147     memset(&event, 0, sizeof(event));
2148 
2149     event.unprot_deauth.sa = &mgmt->sa[0];
2150     event.unprot_deauth.da = &mgmt->da[0];
2151 
2152     //	if (cmd_evnt == NXP_WIFI_EVENT_UNPROT_DEAUTHENTICATE) {
2153     event.unprot_deauth.reason_code = le_to_host16(mgmt->u.deauth.reason_code);
2154     wifi_if_ctx_rtos->supp_callbk_fns.unprot_deauth(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2155     //	} else if (cmd_evnt == NXP_WIFI_EVENT_UNPROT_DISASSOCIATE) {
2156     event.unprot_disassoc.reason_code = le_to_host16(mgmt->u.deauth.reason_code);
2157     wifi_if_ctx_rtos->supp_callbk_fns.unprot_disassoc(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2158     //	}
2159 }
2160 
wifi_nxp_wpa_supp_send_mlme(void * if_priv,const u8 * data,size_t data_len,int noack,unsigned int freq,int no_cck,int offchanok,unsigned int wait_time,int cookie)2161 int wifi_nxp_wpa_supp_send_mlme(void *if_priv,
2162                            const u8 *data,
2163                            size_t data_len,
2164                            int noack,
2165                            unsigned int freq,
2166                            int no_cck,
2167                            int offchanok,
2168                            unsigned int wait_time,
2169                            int cookie)
2170 {
2171     int status                                 = -WM_FAIL;
2172     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2173     const struct ieee80211_hdr *hdr;
2174     u16 fc, stype;
2175 
2176     hdr   = (const struct ieee80211_hdr *)data;
2177     fc    = le_to_host16(hdr->frame_control);
2178     stype = WLAN_FC_GET_STYPE(fc);
2179 
2180     if (!if_priv)
2181     {
2182         supp_e("%s: Missing interface context", __func__);
2183         goto out;
2184     }
2185 
2186     if (data_len > 1500)
2187     {
2188         supp_d("%s: Invalid data length", __func__);
2189         goto out;
2190     }
2191 
2192     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2193 
2194     wifi_if_ctx_rtos->mgmt_tx_status = 0;
2195 
2196     status = wifi_nxp_send_mlme(wifi_if_ctx_rtos->bss_type, freq_to_chan(freq), wait_time, data, data_len);
2197 
2198     if (status == -WM_FAIL)
2199     {
2200         wifi_if_ctx_rtos->last_mgmt_tx_data_len = 0;
2201         wifi_if_ctx_rtos->mgmt_tx_status        = 0;
2202         supp_e("%s: wifi_inject_frame failed", __func__);
2203         goto out;
2204     }
2205 
2206     if (((wifi_if_ctx_rtos->bss_type == BSS_TYPE_UAP) &&
2207          ((stype == WLAN_FC_STYPE_ASSOC_RESP) || (stype == WLAN_FC_STYPE_REASSOC_RESP))) ||
2208         (stype == WLAN_FC_STYPE_ACTION))
2209     {
2210         memcpy((void *)wifi_if_ctx_rtos->last_mgmt_tx_data, (const void *)data, (size_t)data_len);
2211         wifi_if_ctx_rtos->last_mgmt_tx_data_len = data_len;
2212         wifi_if_ctx_rtos->mgmt_tx_status        = 1;
2213     }
2214     else
2215     {
2216         wifi_if_ctx_rtos->last_mgmt_tx_data_len = 0;
2217     }
2218 
2219 out:
2220     return status;
2221 }
2222 
wifi_nxp_parse_sband(struct wifi_nxp_event_supported_band * event,struct wpa_supp_event_supported_band * band)2223 int wifi_nxp_parse_sband( struct wifi_nxp_event_supported_band *event,
2224             struct wpa_supp_event_supported_band *band)
2225 {
2226     int count;
2227 
2228     if (event && (event->wifi_nxp_n_bitrates == 0 || event->wifi_nxp_n_channels == 0))
2229     {
2230         return -WM_FAIL;
2231     }
2232 
2233     memset(band, 0, sizeof(*band));
2234 
2235     band->wpa_supp_n_channels = event->wifi_nxp_n_channels;
2236     band->wpa_supp_n_bitrates = event->wifi_nxp_n_bitrates;
2237 
2238     for (count = 0; count < band->wpa_supp_n_channels; count++) {
2239         struct wpa_supp_event_channel *chan = &band->channels[count];
2240 
2241         if (count >= WPA_SUPP_SBAND_MAX_CHANNELS)
2242         {
2243             supp_e("%s: Failed to add channel", __func__);
2244             break;
2245         }
2246 
2247         chan->wpa_supp_flags = event->channels[count].wifi_nxp_flags;
2248         chan->wpa_supp_max_power = event->channels[count].wifi_nxp_max_power;
2249         chan->wpa_supp_time = event->channels[count].wifi_nxp_time;
2250         chan->dfs_cac_msec = event->channels[count].dfs_cac_msec;
2251         chan->ch_valid = event->channels[count].ch_valid;
2252         chan->center_frequency = event->channels[count].center_frequency;
2253         chan->dfs_state = event->channels[count].dfs_state;
2254     }
2255 
2256     for (count = 0; count < band->wpa_supp_n_bitrates; count++) {
2257         struct wpa_supp_event_rate *rate = &band->bitrates[count];
2258 
2259         if (count >= WPA_SUPP_SBAND_MAX_RATES) {
2260             supp_e("%s: Failed to add bitrate", __func__);
2261             break;
2262         }
2263 
2264         rate->wpa_supp_flags = event->bitrates[count].wifi_nxp_flags;
2265         rate->wpa_supp_bitrate = event->bitrates[count].wifi_nxp_bitrate;
2266     }
2267 
2268     band->ht_cap.wpa_supp_ht_supported = event->ht_cap.wifi_nxp_ht_supported;
2269     band->ht_cap.wpa_supp_cap = event->ht_cap.wifi_nxp_cap;
2270     band->ht_cap.mcs.wpa_supp_rx_highest = event->ht_cap.mcs.wifi_nxp_rx_highest;
2271 
2272     for (count = 0; count < WPA_SUPP_HT_MCS_MASK_LEN; count++) {
2273         band->ht_cap.mcs.wpa_supp_rx_mask[count] =
2274         event->ht_cap.mcs.wifi_nxp_rx_mask[count];
2275     }
2276 
2277     band->ht_cap.mcs.wpa_supp_tx_params = event->ht_cap.mcs.wifi_nxp_tx_params;
2278 
2279     for (count = 0; count < WIFI_NXP_HT_MCS_RES_LEN; count++) {
2280 
2281         if (count >= WPA_SUPP_HT_MCS_RES_LEN) {
2282             supp_e("%s: Failed to add reserved bytes", __func__);
2283             break;
2284         }
2285 
2286         band->ht_cap.mcs.wpa_supp_reserved[count] =
2287             event->ht_cap.mcs.wifi_nxp_reserved[count];
2288     }
2289 
2290     band->ht_cap.wpa_supp_ampdu_factor = event->ht_cap.wifi_nxp_ampdu_factor;
2291     band->ht_cap.wpa_supp_ampdu_density = event->ht_cap.wifi_nxp_ampdu_density;
2292 
2293     band->vht_cap.wpa_supp_vht_supported = event->vht_cap.wifi_nxp_vht_supported;
2294     band->vht_cap.wpa_supp_cap = event->vht_cap.wifi_nxp_cap;
2295 
2296     band->vht_cap.vht_mcs.rx_mcs_map = event->vht_cap.vht_mcs.rx_mcs_map;
2297     band->vht_cap.vht_mcs.rx_highest = event->vht_cap.vht_mcs.rx_highest;
2298     band->vht_cap.vht_mcs.tx_mcs_map = event->vht_cap.vht_mcs.tx_mcs_map;
2299     band->vht_cap.vht_mcs.tx_highest = event->vht_cap.vht_mcs.tx_highest;
2300 
2301     band->he_cap.wpa_supp_he_supported = event->he_cap.wifi_nxp_he_supported;
2302     band->he_cap.he_6ghz_capa = event->he_cap.he_6ghz_capa;
2303     memcpy(band->he_cap.mac_cap, event->he_cap.mac_cap, WIFI_NXP_HE_MAX_MAC_CAPAB_SIZE);
2304     memcpy(band->he_cap.phy_cap, event->he_cap.phy_cap, WIFI_NXP_HE_MAX_PHY_CAPAB_SIZE);
2305     memcpy(band->he_cap.mcs, event->he_cap.mcs, WIFI_NXP_HE_MAX_MCS_CAPAB_SIZE);
2306     memcpy(band->he_cap.ppet, event->he_cap.ppet, WIFI_NXP_HE_MAX_PPET_CAPAB_SIZE);
2307 
2308     band->band = event->band;
2309 
2310     return WM_SUCCESS;
2311 }
2312 
wifi_nxp_wpa_supp_event_get_wiphy(void * if_priv,struct wifi_nxp_event_get_wiphy * wiphy_info,unsigned int event_len)2313 void wifi_nxp_wpa_supp_event_get_wiphy(void *if_priv,
2314         struct wifi_nxp_event_get_wiphy *wiphy_info,
2315         unsigned int event_len)
2316 {
2317     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2318     struct wpa_supp_event_supported_band band;
2319 
2320     if (!if_priv || !wiphy_info || !event_len) {
2321         supp_e("%s: Invalid parameters", __func__);
2322         return;
2323     }
2324 
2325     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2326 
2327     memset(&band, 0, sizeof(band));
2328 
2329     for (int i = 0; i < WIFI_NXP_EVENT_GET_WIPHY_NUM_BANDS; i++) {
2330         if (wifi_nxp_parse_sband(&wiphy_info->sband[i], &band) != WM_SUCCESS) {
2331             continue;
2332         }
2333         if (wifi_if_ctx_rtos->bss_type == BSS_TYPE_STA)
2334         {
2335             if (wifi_if_ctx_rtos->supp_drv_if_ctx && wifi_if_ctx_rtos->supp_callbk_fns.get_wiphy_res) {
2336                 wifi_if_ctx_rtos->supp_callbk_fns.get_wiphy_res(wifi_if_ctx_rtos->supp_drv_if_ctx, &band);
2337             }
2338         }
2339 #if CONFIG_WPA_SUPP_AP
2340         else
2341         {
2342            if (wifi_if_ctx_rtos->hapd_drv_if_ctx && wifi_if_ctx_rtos->hostapd_callbk_fns.get_wiphy_res) {
2343                 wifi_if_ctx_rtos->hostapd_callbk_fns.get_wiphy_res(wifi_if_ctx_rtos->hapd_drv_if_ctx, &band);
2344            }
2345         }
2346 #endif
2347     }
2348 
2349     if (wifi_if_ctx_rtos->bss_type == BSS_TYPE_STA)
2350     {
2351         if (wifi_if_ctx_rtos->supp_drv_if_ctx && wifi_if_ctx_rtos->supp_callbk_fns.get_wiphy_res) {
2352              wifi_if_ctx_rtos->supp_callbk_fns.get_wiphy_res(wifi_if_ctx_rtos->supp_drv_if_ctx, NULL);
2353         }
2354     }
2355 #if CONFIG_WPA_SUPP_AP
2356     else
2357     {
2358         if (wifi_if_ctx_rtos->hapd_drv_if_ctx && wifi_if_ctx_rtos->hostapd_callbk_fns.get_wiphy_res) {
2359              wifi_if_ctx_rtos->hostapd_callbk_fns.get_wiphy_res(wifi_if_ctx_rtos->hapd_drv_if_ctx, NULL);
2360         }
2361     }
2362 #endif
2363 }
2364 
wifi_nxp_wpa_supp_get_wiphy(void * if_priv)2365 int wifi_nxp_wpa_supp_get_wiphy(void *if_priv)
2366 {
2367     int status                                 = -WM_FAIL;
2368     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2369 
2370     if (!if_priv) {
2371         supp_e("%s: Missing interface context", __func__);
2372         goto out;
2373     }
2374 
2375     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2376 
2377     status = wifi_nxp_get_wiphy(wifi_if_ctx_rtos->bss_type);
2378 
2379     if (status != WM_SUCCESS) {
2380         supp_e("%s: wifi nxp get_wiphy failed", __func__);
2381         goto out;
2382     }
2383 out:
2384     return status;
2385 }
2386 
2387 #if 0
2388 int wifi_nxp_wpa_supp_register_frame(void *if_priv,
2389         u16 type, const u8 *match, size_t match_len,
2390         bool multicast)
2391 {
2392     enum wifi_nxp_status status = wifi_nxp_STATUS_FAIL;
2393     struct wifi_nxp_wifi_if_ctx_rtos *wifi_if_ctx_rtos = NULL;
2394     struct wifi_nxp_ctx_zep *rpu_ctx_zep = NULL;
2395     struct wifi_nxp_umac_mgmt_frame_info frame_info;
2396 
2397     if (!if_priv || !match || !match_len) {
2398         LOG_ERR("%s: Invalid parameters", __func__);
2399         goto out;
2400     }
2401 
2402     wifi_if_ctx_rtos = if_priv;
2403     rpu_ctx_zep = wifi_if_ctx_rtos->rpu_ctx_zep;
2404 
2405     memset(&frame_info, 0, sizeof(frame_info));
2406 
2407     frame_info.frame_type = type;
2408     frame_info.frame_match.frame_match_len = match_len;
2409     memcpy(frame_info.frame_match.frame_match, match, match_len);
2410 
2411     status = wifi_nxp_fmac_register_frame(rpu_ctx_zep->rpu_ctx, wifi_if_ctx_rtos->vif_idx,
2412         &frame_info);
2413 
2414     if (status != wifi_nxp_STATUS_SUCCESS) {
2415         LOG_ERR("%s: wifi_nxp_fmac_register_frame failed", __func__);
2416         goto out;
2417     }
2418 out:
2419     return status;
2420 }
2421 
2422 void wifi_nxp_wpa_supp_event_mgmt_rx_callbk_fn(void *if_priv,
2423                     struct wifi_nxp_umac_event_mlme *mlme_event,
2424                     unsigned int event_len)
2425 {
2426     struct wifi_nxp_wifi_if_ctx_rtos *wifi_if_ctx_rtos = NULL;
2427 
2428     if (!if_priv) {
2429         LOG_ERR("%s: Missing interface context", __func__);
2430         return;
2431     }
2432 
2433     wifi_if_ctx_rtos = if_priv;
2434 
2435     if (!mlme_event || !event_len) {
2436         LOG_ERR("%s: Missing MLME event data", __func__);
2437         return;
2438     }
2439 
2440     if (wifi_if_ctx_rtos->supp_drv_if_ctx && wifi_if_ctx_rtos->supp_callbk_fns.mgmt_rx) {
2441         wifi_if_ctx_rtos->supp_callbk_fns.mgmt_rx(wifi_if_ctx_rtos->supp_drv_if_ctx,
2442                 mlme_event->frame.frame,
2443                 mlme_event->frame.frame_len,
2444                 mlme_event->frequency,
2445                 mlme_event->rx_signal_dbm);
2446     }
2447 }
2448 #endif
2449 
wifi_nxp_wpa_supp_get_capa(void * if_priv,struct wpa_driver_capa * capa)2450 int wifi_nxp_wpa_supp_get_capa(void *if_priv, struct wpa_driver_capa *capa)
2451 {
2452     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2453 
2454     if (!if_priv || !capa) {
2455         supp_e("%s: Invalid parameters", __func__);
2456         goto out;
2457     }
2458 
2459     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2460 
2461     os_memset(capa, 0, sizeof(*capa));
2462 
2463     capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
2464     capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
2465     capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
2466     capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
2467     capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
2468     capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
2469     capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
2470     capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
2471     capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
2472 
2473     /* Use SME */
2474     capa->flags = 0;
2475     capa->flags |= WPA_DRIVER_FLAGS_SME;
2476     capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
2477     capa->flags |= WPA_DRIVER_FLAGS_SAE;
2478     capa->flags |= WPA_DRIVER_FLAGS_ACS_OFFLOAD;
2479     capa->flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
2480     //capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
2481     capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
2482     if (IS_ENABLED(CONFIG_NXP_WIFI_SOFTAP_SUPPORT))
2483     {
2484         capa->flags |= WPA_DRIVER_FLAGS_AP;
2485         capa->flags |= WPA_DRIVER_FLAGS_AP_MLME;
2486         capa->flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
2487         capa->flags |= WPA_DRIVER_FLAGS_AP_CSA;
2488         capa->flags2 |= WPA_DRIVER_FLAGS2_AP_SME;
2489     }
2490 #if !defined(RW610) && !defined(SD8801)
2491     capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
2492 #endif
2493     capa->flags |= WPA_DRIVER_FLAGS_HE_CAPABILITIES;
2494     capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
2495 
2496     capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
2497     capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT;
2498     capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
2499 
2500     capa->max_scan_ssids       = 1;
2501     capa->max_sched_scan_ssids = 1;
2502     capa->sched_scan_supported = 0;
2503     capa->max_remain_on_chan   = 5000;
2504     capa->max_stations         = 32;
2505     capa->max_acl_mac_addrs    = 32;
2506 
2507     capa->extended_capa = g_extended_capa;
2508     capa->extended_capa_mask = g_extended_capa_mask;
2509     capa->extended_capa_len = 10;
2510 
2511 out:
2512     return 0;
2513 }
2514 
wifi_nxp_wpa_supp_get_conn_info(void * if_priv,struct wpa_conn_info * info)2515 int wifi_nxp_wpa_supp_get_conn_info(void *if_priv, struct wpa_conn_info *info)
2516 {
2517     int ret = -WM_FAIL;
2518 
2519     if (!if_priv || !info) {
2520         supp_e("%s: Invalid params", __func__);
2521         goto out;
2522     }
2523 
2524     ret = wifi_nxp_get_conn_info(&info->beacon_interval, &info->dtim_period, &info->twt_capable);
2525     if (ret != WM_SUCCESS) {
2526         supp_e("%s: Failed to get beacon info", __func__);
2527         goto out;
2528     }
2529 
2530     ret = WM_SUCCESS;
2531 
2532 out:
2533     return ret;
2534 }
2535 
wifi_nxp_wpa_supp_remain_on_channel(void * if_priv,unsigned int freq,unsigned int duration)2536 int wifi_nxp_wpa_supp_remain_on_channel(void *if_priv, unsigned int freq, unsigned int duration)
2537 {
2538     int status                                 = -WM_FAIL;
2539     int ret                                    = -1;
2540     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2541     int channel;
2542 
2543     if (!if_priv)
2544     {
2545         supp_e("%s: Invalid params", __func__);
2546         goto out;
2547     }
2548     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2549     if (freq)
2550     {
2551         wifi_if_ctx_rtos->remain_on_channel_freq = freq;
2552     }
2553     wifi_if_ctx_rtos->remain_on_channel_duration = duration;
2554 
2555     channel = freq_to_chan(wifi_if_ctx_rtos->remain_on_channel_freq);
2556 
2557     wifi_if_ctx_rtos->supp_called_remain_on_chan = true;
2558     wifi_if_ctx_rtos->remain_on_chan_is_canceled = false;
2559     status                                       = wifi_remain_on_channel(true, channel, duration);
2560 
2561     if (status != WM_SUCCESS)
2562     {
2563         supp_e("%s: Remain on channel cmd failed", __func__);
2564         ret = -1;
2565     }
2566     else
2567     {
2568         supp_d("%s:Remain on channel sent successfully", __func__);
2569         ret = 0;
2570     }
2571 out:
2572     return ret;
2573 }
2574 
wifi_nxp_wpa_supp_cancel_remain_on_channel(void * if_priv)2575 int wifi_nxp_wpa_supp_cancel_remain_on_channel(void *if_priv)
2576 {
2577     int status                                 = -WM_FAIL;
2578     int ret                                    = -1;
2579     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2580 
2581     if (!if_priv)
2582     {
2583         supp_e("%s: Invalid params", __func__);
2584         goto out;
2585     }
2586     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2587     if (wifi_if_ctx_rtos->remain_on_chan_is_canceled)
2588     {
2589         supp_d("%s:Already canceled, ignore it", __func__);
2590         ret = 0;
2591         goto out;
2592     }
2593 
2594     wifi_if_ctx_rtos->supp_called_remain_on_chan = true;
2595     wifi_if_ctx_rtos->remain_on_chan_is_canceled = true;
2596     status                                       = wifi_remain_on_channel(false, 0, 0);
2597 
2598     if (status != WM_SUCCESS)
2599     {
2600         supp_e("%s: Cancel on channel cmd failed", __func__);
2601         ret = -1;
2602     }
2603     else
2604     {
2605         supp_d("%s:Cancel on channel sent successfully", __func__);
2606         ret = 0;
2607     }
2608 out:
2609     return ret;
2610 }
2611 
wifi_nxp_wpa_supp_event_proc_mgmt_rx(void * if_priv,nxp_wifi_event_mlme_t * mgmt_rx,unsigned int event_len,int rssi)2612 void wifi_nxp_wpa_supp_event_proc_mgmt_rx(void *if_priv, nxp_wifi_event_mlme_t *mgmt_rx,
2613     unsigned int event_len, int rssi)
2614 {
2615     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2616     struct ieee80211_mgmt *mgmt                = NULL;
2617     unsigned char *frame                       = NULL;
2618     unsigned int frame_len                     = 0;
2619 
2620     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2621 
2622     frame     = (unsigned char *)mgmt_rx->frame.frame;
2623     frame_len = mgmt_rx->frame.frame_len;
2624     mgmt      = (struct ieee80211_mgmt *)frame;
2625 
2626     if (frame_len < 4 + (2 * WIFI_ETH_ADDR_LEN))
2627     {
2628         supp_e("%s: MLME event too short", __func__);
2629         return;
2630     }
2631 
2632     if (frame_len < 24 + sizeof(mgmt->u.deauth))
2633     {
2634         supp_e("%s: MGMT RX frame too short", __func__);
2635         return;
2636     }
2637 
2638 #if CONFIG_WPA_SUPP_AP
2639     if (wifi_if_ctx_rtos->hostapd)
2640     {
2641         wifi_if_ctx_rtos->hostapd_callbk_fns.mgmt_rx(wifi_if_ctx_rtos->hapd_drv_if_ctx,
2642             frame, frame_len, mgmt_rx->frame.freq, rssi);
2643     }
2644     else
2645 #endif
2646     {
2647         wifi_if_ctx_rtos->supp_callbk_fns.mgmt_rx(wifi_if_ctx_rtos->supp_drv_if_ctx,
2648             frame, frame_len, mgmt_rx->frame.freq, rssi);
2649     }
2650 }
2651 
wifi_nxp_wpa_supp_event_proc_ecsa_complete(void * if_priv,nxp_wifi_ch_switch_info * ch_switch_info)2652 void wifi_nxp_wpa_supp_event_proc_ecsa_complete(void *if_priv, nxp_wifi_ch_switch_info *ch_switch_info)
2653 {
2654     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2655     union wpa_event_data event;
2656 
2657     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2658 
2659     memset(&event, 0, sizeof(event));
2660 
2661     event.ch_switch.freq       = ch_switch_info->center_freq;
2662     event.ch_switch.ht_enabled = ch_switch_info->ht_enabled;
2663     event.ch_switch.ch_offset  = ch_switch_info->ch_offset;
2664     event.ch_switch.ch_width   = (enum chan_width)ch_switch_info->ch_width;
2665     event.ch_switch.cf1        = ch_switch_info->center_freq1;
2666     event.ch_switch.cf2        = ch_switch_info->center_freq2;
2667 
2668 #if CONFIG_WPA_SUPP_AP
2669     if (wifi_if_ctx_rtos->hostapd)
2670     {
2671         wifi_if_ctx_rtos->hostapd_callbk_fns.ecsa_complete(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
2672     }
2673     else
2674 #endif
2675     {
2676         wifi_if_ctx_rtos->supp_callbk_fns.ecsa_complete(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2677     }
2678 }
2679 
2680 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wifi_nxp_wpa_supp_event_proc_eapol_rx(void * if_priv,nxp_wifi_event_eapol_mlme_t * eapol_rx,unsigned int event_len)2681 void wifi_nxp_wpa_supp_event_proc_eapol_rx(void *if_priv, nxp_wifi_event_eapol_mlme_t *eapol_rx, unsigned int event_len)
2682 {
2683     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2684     union wpa_event_data event;
2685 
2686     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2687 
2688     memset(&event, 0, sizeof(event));
2689 
2690     event.eapol_rx.src      = (const unsigned char *)eapol_rx->mac_addr;
2691     event.eapol_rx.data     = (const unsigned char *)eapol_rx->frame.frame;
2692     event.eapol_rx.data_len = eapol_rx->frame.frame_len;
2693 
2694 #if CONFIG_WPA_SUPP_AP
2695     if (wifi_if_ctx_rtos->hostapd)
2696     {
2697         wifi_if_ctx_rtos->hostapd_callbk_fns.eapol_rx(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
2698     }
2699     else
2700 #endif
2701     {
2702         wifi_if_ctx_rtos->supp_callbk_fns.eapol_rx(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2703     }
2704 }
2705 #endif
2706 
wifi_nxp_wpa_supp_event_proc_dfs_cac_started(void * if_priv,nxp_wifi_dfs_cac_info * dfs_cac_info)2707 void wifi_nxp_wpa_supp_event_proc_dfs_cac_started(void *if_priv, nxp_wifi_dfs_cac_info *dfs_cac_info)
2708 {
2709     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2710     union wpa_event_data event;
2711 
2712     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2713 
2714     memset(&event, 0, sizeof(event));
2715 
2716     event.dfs_event.freq        = dfs_cac_info->center_freq;
2717     event.dfs_event.ht_enabled  = dfs_cac_info->ht_enabled;
2718     event.dfs_event.chan_offset = dfs_cac_info->ch_offset;
2719     event.dfs_event.chan_width  = (enum chan_width)dfs_cac_info->ch_width;
2720     event.dfs_event.cf1         = dfs_cac_info->center_freq1;
2721     event.dfs_event.cf2         = dfs_cac_info->center_freq2;
2722 
2723 #if CONFIG_WPA_SUPP_AP
2724     if (wifi_if_ctx_rtos->hostapd)
2725     {
2726         wifi_if_ctx_rtos->hostapd_callbk_fns.dfs_cac_started(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
2727     }
2728     else
2729 #endif
2730     {
2731         wifi_if_ctx_rtos->supp_callbk_fns.dfs_cac_started(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2732     }
2733 }
2734 
wifi_nxp_wpa_supp_event_proc_dfs_cac_finished(void * if_priv,nxp_wifi_dfs_cac_info * dfs_cac_info)2735 void wifi_nxp_wpa_supp_event_proc_dfs_cac_finished(void *if_priv, nxp_wifi_dfs_cac_info *dfs_cac_info)
2736 {
2737     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2738     union wpa_event_data event;
2739 
2740     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2741 
2742     memset(&event, 0, sizeof(event));
2743 
2744     event.dfs_event.freq        = dfs_cac_info->center_freq;
2745     event.dfs_event.ht_enabled  = dfs_cac_info->ht_enabled;
2746     event.dfs_event.chan_offset = dfs_cac_info->ch_offset;
2747     event.dfs_event.chan_width  = (enum chan_width)dfs_cac_info->ch_width;
2748     event.dfs_event.cf1         = dfs_cac_info->center_freq1;
2749     event.dfs_event.cf2         = dfs_cac_info->center_freq2;
2750 
2751 #if CONFIG_WPA_SUPP_AP
2752     if (wifi_if_ctx_rtos->hostapd)
2753     {
2754         wifi_if_ctx_rtos->hostapd_callbk_fns.dfs_cac_finished(wifi_if_ctx_rtos->hapd_drv_if_ctx, &event);
2755     }
2756     else
2757 #endif
2758     {
2759         wifi_if_ctx_rtos->supp_callbk_fns.dfs_cac_finished(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2760     }
2761 }
2762 
wifi_nxp_wpa_supp_event_signal_change(void * if_priv,t_s16 * curr_rssi)2763 void wifi_nxp_wpa_supp_event_signal_change(void *if_priv, t_s16 *curr_rssi)
2764 {
2765     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2766     union wpa_event_data event;
2767 
2768     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2769 
2770     if (wifi_if_ctx_rtos == NULL)
2771     {
2772         wifi_e("%s: wifi_if_ctx_rtos is NULL", __func__);
2773         return;
2774     }
2775     memset(&event, 0, sizeof(event));
2776     event.signal_change.above_threshold = 0;
2777     event.signal_change.data.signal = abs(*curr_rssi);
2778 
2779     wifi_if_ctx_rtos->supp_callbk_fns.signal_change(wifi_if_ctx_rtos->supp_drv_if_ctx, &event);
2780 }
2781 
2782 #if CONFIG_WIFI_SOFTAP_SUPPORT
wifi_nxp_wpa_supp_init_ap(void * if_priv,struct wpa_driver_associate_params * params)2783 int wifi_nxp_wpa_supp_init_ap(void *if_priv, struct wpa_driver_associate_params *params)
2784 {
2785     int status                                 = -WM_FAIL;
2786     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2787     nxp_wifi_ap_info_t *ap_params = NULL;
2788 
2789     dump_hex(params, sizeof(struct wpa_driver_associate_params));
2790 
2791     int ret = -1;
2792 
2793     if ((!if_priv) || (!params))
2794     {
2795         supp_e("%s: Invalid params", __func__);
2796         goto out;
2797     }
2798 
2799     if (params->mode != IEEE80211_MODE_AP) {
2800         supp_e("%s: Invalid mode", __func__);
2801         goto out;
2802     }
2803 
2804     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2805 
2806     ap_params = (nxp_wifi_ap_info_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_ap_info_t));
2807 
2808     if (!ap_params)
2809     {
2810         supp_e("%s: ap params calloc failed", __func__);
2811         goto out;
2812     }
2813 
2814     if (params->auth_alg & WPA_AUTH_ALG_FT)
2815     {
2816 //       assoc_params->is_ft = true;
2817     }
2818 
2819     if (params->bssid)
2820     {
2821         memcpy(ap_params->bssid, params->bssid, WIFI_ETH_ADDR_LEN);
2822     }
2823 
2824     if (params->freq.freq)
2825     {
2826         int channel           = freq_to_chan(params->freq.freq);
2827         ap_params->chan.channel = channel;
2828     }
2829 
2830     if (params->ssid)
2831     {
2832         ap_params->ssid.ssid_len = params->ssid_len;
2833 
2834         memcpy(ap_params->ssid.ssid, params->ssid, params->ssid_len);
2835     }
2836 
2837     if (params->wpa_ie)
2838     {
2839 //       ap_params->wpa_ie.ie_len = params->wpa_ie_len;
2840 //       memcpy(ap_params->wpa_ie.ie, params->wpa_ie, params->wpa_ie_len);
2841     }
2842 
2843     wifi_d("initiating init ap");
2844 
2845     status = wifi_nxp_init_ap(ap_params);
2846 
2847     if (status != WM_SUCCESS)
2848     {
2849         supp_e("%s: MLME command failed (init ap)", __func__);
2850     }
2851     else
2852     {
2853         supp_d("%s: Init AP is done successfully", __func__);
2854         ret = 0;
2855     }
2856     OSA_MemoryFree((void *)ap_params);
2857 
2858 out:
2859     return ret;
2860 }
2861 #endif
2862 
2863 #if CONFIG_WPA_SUPP_AP
wifi_nxp_hostapd_dev_init(void * hapd_drv_if_ctx,const char * iface_name,rtos_hostapd_dev_callbk_fns * hostapd_callbk_fns)2864 void *wifi_nxp_hostapd_dev_init(void *hapd_drv_if_ctx,
2865                                 const char *iface_name,
2866                                 rtos_hostapd_dev_callbk_fns *hostapd_callbk_fns)
2867 {
2868     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
2869 
2870     const struct netif *iface = NULL;
2871 
2872     iface = net_if_get_binding(iface_name);
2873 
2874     if (!iface)
2875     {
2876         supp_e("%s: Interface %s not found", __func__, iface_name);
2877         return NULL;
2878     }
2879 
2880     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)wm_wifi.hapd_if_priv;
2881 
2882     if (!wifi_if_ctx_rtos)
2883     {
2884         supp_e("%s: Interface %s not properly initialized", __func__, iface_name);
2885         return NULL;
2886     }
2887 
2888     memset(wifi_if_ctx_rtos, 0x00, sizeof(struct wifi_nxp_ctx_rtos));
2889 
2890     wifi_if_ctx_rtos->iface_ctx = iface;
2891 
2892     wifi_if_ctx_rtos->hostapd = true;
2893 
2894     wifi_if_ctx_rtos->bss_type = BSS_TYPE_UAP;
2895 
2896     wifi_if_ctx_rtos->hapd_drv_if_ctx = hapd_drv_if_ctx;
2897 
2898     wifi_if_ctx_rtos->last_mgmt_tx_data = (uint8_t *)OSA_MemoryAllocate(MAX_MGMT_TX_FRAME_SIZE);
2899 
2900     if (!wifi_if_ctx_rtos->last_mgmt_tx_data)
2901     {
2902         supp_e("%s: Buffer to store mgmt tx failed", __func__);
2903         return NULL;
2904     }
2905 
2906     memcpy(&wifi_if_ctx_rtos->hostapd_callbk_fns, hostapd_callbk_fns, sizeof(wifi_if_ctx_rtos->hostapd_callbk_fns));
2907 
2908     return wifi_if_ctx_rtos;
2909 }
2910 
wifi_nxp_hostapd_dev_deinit(void * if_priv)2911 void wifi_nxp_hostapd_dev_deinit(void *if_priv)
2912 {
2913     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
2914 
2915     if (wifi_if_ctx_rtos != NULL)
2916     {
2917         OSA_MemoryFree((void *)wifi_if_ctx_rtos->last_mgmt_tx_data);
2918         memset(wifi_if_ctx_rtos, 0x00, sizeof(struct wifi_nxp_ctx_rtos));
2919     }
2920 }
2921 
wifi_nxp_hostapd_set_modes(void * if_priv,struct hostapd_hw_modes * modes)2922 int wifi_nxp_hostapd_set_modes(void *if_priv, struct hostapd_hw_modes *modes)
2923 {
2924     int status     = -WM_FAIL;
2925 #if CONFIG_11AX
2926     t_u8 bandwidth = wifi_uap_get_bandwidth();
2927 #endif
2928 
2929     if ((!if_priv) || (!modes))
2930     {
2931         supp_e("%s: Invalid params", __func__);
2932         goto out;
2933     }
2934 
2935     status = wifi_setup_ht_cap(&modes[HOSTAPD_MODE_IEEE80211G].ht_capab, &modes[HOSTAPD_MODE_IEEE80211G].mcs_set[0],
2936                                &modes[HOSTAPD_MODE_IEEE80211G].a_mpdu_params, 0);
2937     if (status != WM_SUCCESS)
2938     {
2939         supp_e("%s: wifi nxp set 2G infra ht cap failed", __func__);
2940         goto out;
2941     }
2942 
2943 #if CONFIG_5GHz_SUPPORT
2944     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
2945     {
2946         status = wifi_setup_ht_cap(&modes[HOSTAPD_MODE_IEEE80211A].ht_capab, &modes[HOSTAPD_MODE_IEEE80211A].mcs_set[0],
2947                                    &modes[HOSTAPD_MODE_IEEE80211A].a_mpdu_params, 1);
2948         if (status != WM_SUCCESS)
2949         {
2950             supp_e("%s: wifi nxp set 5G infra ht cap failed", __func__);
2951             goto out;
2952         }
2953     }
2954 #endif
2955 
2956     modes[HOSTAPD_MODE_IEEE80211G].flags |= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN;
2957 #if CONFIG_5GHz_SUPPORT
2958     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
2959     {
2960         modes[HOSTAPD_MODE_IEEE80211A].flags |= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN;
2961     }
2962 #endif
2963 
2964 #if CONFIG_11AC
2965     status = wifi_setup_vht_cap((t_u32 *)&modes[HOSTAPD_MODE_IEEE80211G].vht_capab,
2966                                 modes[HOSTAPD_MODE_IEEE80211G].vht_mcs_set, 0);
2967     if (status != WM_SUCCESS)
2968     {
2969         supp_e("%s: wifi nxp set 2G infra vht cap failed", __func__);
2970         goto out;
2971     }
2972 
2973 #if CONFIG_5GHz_SUPPORT
2974     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
2975     {
2976         status = wifi_setup_vht_cap((t_u32 *)&modes[HOSTAPD_MODE_IEEE80211A].vht_capab,
2977                                     modes[HOSTAPD_MODE_IEEE80211A].vht_mcs_set, 1);
2978         if (status != WM_SUCCESS)
2979         {
2980             supp_e("%s: wifi nxp set 5G infra vht cap failed", __func__);
2981             goto out;
2982         }
2983     }
2984 #endif
2985 
2986     modes[HOSTAPD_MODE_IEEE80211G].flags |= HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
2987 #if CONFIG_5GHz_SUPPORT
2988     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
2989     {
2990         modes[HOSTAPD_MODE_IEEE80211A].flags |= HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
2991     }
2992 #endif
2993 #endif
2994 
2995 #if CONFIG_11AX
2996     status = wifi_setup_he_cap(
2997         (nxp_wifi_he_capabilities *)&modes[HOSTAPD_MODE_IEEE80211G].he_capab[IEEE80211_MODE_INFRA], 0);
2998     if (status != WM_SUCCESS)
2999     {
3000         supp_e("%s: wifi nxp set 2G infra he cap failed", __func__);
3001         goto out;
3002     }
3003 
3004     status =
3005         wifi_setup_he_cap((nxp_wifi_he_capabilities *)&modes[HOSTAPD_MODE_IEEE80211G].he_capab[IEEE80211_MODE_AP], 0);
3006     if (status != WM_SUCCESS)
3007     {
3008         supp_e("%s: wifi nxp set 2G ap he cap failed", __func__);
3009         goto out;
3010     }
3011     if (bandwidth == BANDWIDTH_20MHZ)
3012     {
3013         modes[HOSTAPD_MODE_IEEE80211G].he_capab[IEEE80211_MODE_AP].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] = 0;
3014     }
3015 #if CONFIG_5GHz_SUPPORT
3016     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
3017     {
3018         status = wifi_setup_he_cap(
3019             (nxp_wifi_he_capabilities *)&modes[HOSTAPD_MODE_IEEE80211A].he_capab[IEEE80211_MODE_INFRA], 1);
3020         if (status != WM_SUCCESS)
3021         {
3022             supp_e("%s: wifi nxp set 5G infra he cap failed", __func__);
3023             goto out;
3024         }
3025 
3026         status = wifi_setup_he_cap(
3027             (nxp_wifi_he_capabilities *)&modes[HOSTAPD_MODE_IEEE80211A].he_capab[IEEE80211_MODE_AP], 1);
3028         if (status != WM_SUCCESS)
3029         {
3030             supp_e("%s: wifi nxp set 5G ap he cap failed", __func__);
3031             goto out;
3032         }
3033     }
3034     if (bandwidth == BANDWIDTH_20MHZ)
3035     {
3036         modes[HOSTAPD_MODE_IEEE80211A].he_capab[IEEE80211_MODE_AP].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] = 0;
3037     }
3038 #endif
3039 #endif
3040 
3041     wifi_setup_channel_info(modes[HOSTAPD_MODE_IEEE80211B].channels, modes[HOSTAPD_MODE_IEEE80211B].num_channels,
3042                             BAND_2GHZ);
3043     wifi_setup_channel_info(modes[HOSTAPD_MODE_IEEE80211G].channels, modes[HOSTAPD_MODE_IEEE80211G].num_channels,
3044                             BAND_2GHZ);
3045 #if CONFIG_5GHz_SUPPORT
3046     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
3047     {
3048         wifi_setup_channel_info(modes[HOSTAPD_MODE_IEEE80211A].channels, modes[HOSTAPD_MODE_IEEE80211A].num_channels,
3049                                 BAND_5GHZ);
3050     }
3051 #endif
3052 
3053     status = WM_SUCCESS;
3054 
3055 out:
3056     return status;
3057 }
3058 
wifi_nxp_set_acs_params(nxp_wifi_acs_params * acs_params)3059 static void wifi_nxp_set_acs_params(nxp_wifi_acs_params *acs_params)
3060 {
3061     mlan_private *pmpriv = mlan_adap->priv[0];
3062     unsigned int channel = pmpriv->curr_bss_params.bss_descriptor.channel;
3063 
3064     memset(acs_params, 0, sizeof(nxp_wifi_acs_params));
3065     acs_params->pri_freq = pmpriv->curr_bss_params.bss_descriptor.freq;
3066     acs_params->hw_mode  = channel <= MAX_CHANNELS_BG ? 1 : 2;
3067 #if defined(RW610)
3068     acs_params->ch_width = 20;
3069 #else
3070     t_u8 chan_offset;
3071 
3072     chan_offset = wifi_get_sec_channel_offset(channel);
3073     if (chan_offset == SEC_CHAN_ABOVE)
3074     {
3075         acs_params->sec_freq = acs_params->pri_freq + 20;
3076     }
3077     else if (chan_offset == SEC_CHAN_BELOW)
3078     {
3079         acs_params->sec_freq = acs_params->pri_freq - 20;
3080     }
3081     else
3082     {
3083         acs_params->sec_freq = acs_params->pri_freq;
3084     }
3085 #if CONFIG_5GHz_SUPPORT
3086     if (channel > MAX_CHANNELS_BG)
3087     {
3088 #if CONFIG_11AC
3089         if (wm_wifi.bandwidth == BANDWIDTH_80MHZ)
3090         {
3091             acs_params->ch_width = 80;
3092         }
3093 #endif
3094     }
3095 #endif
3096     if (wm_wifi.bandwidth == BANDWIDTH_40MHZ)
3097     {
3098         acs_params->ch_width = 40;
3099     }
3100     else
3101     {
3102         acs_params->sec_freq = 0;
3103         acs_params->ch_width = 20;
3104     }
3105 #endif
3106 }
3107 
wifi_nxp_hostapd_do_acs(void * if_priv,struct drv_acs_params * params)3108 int wifi_nxp_hostapd_do_acs(void *if_priv, struct drv_acs_params *params)
3109 {
3110     int status = -WM_FAIL;
3111 
3112     if ((!if_priv) || (!params))
3113     {
3114         supp_e("%s: Invalid params", __func__);
3115         goto out;
3116     }
3117 
3118 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
3119     if(mlan_adap->priv[0]->media_connected)
3120     {
3121         nxp_wifi_acs_params acs_params;
3122 
3123         wifi_nxp_set_acs_params(&acs_params);
3124         if (wm_wifi.supp_if_callbk_fns->acs_channel_sel_callbk_fn)
3125         {
3126             wm_wifi.supp_if_callbk_fns->acs_channel_sel_callbk_fn(wm_wifi.hapd_if_priv, &acs_params);
3127         }
3128        status = WM_SUCCESS;
3129        goto out;
3130     }
3131 #endif
3132 
3133     status = wifi_uap_do_acs(params->freq_list);
3134     if (status != WM_SUCCESS)
3135     {
3136         supp_e("%s: wifi uap do acs failed", __func__);
3137         goto out;
3138     }
3139 
3140     status = WM_SUCCESS;
3141 
3142 out:
3143     return status;
3144 }
3145 
3146 #define BSSID_OFFSET 16
3147 
wifi_nxp_hostapd_set_ap(void * if_priv,int beacon_set,struct wpa_driver_ap_params * params)3148 int wifi_nxp_hostapd_set_ap(void *if_priv, int beacon_set, struct wpa_driver_ap_params *params)
3149 {
3150     int status                                 = -WM_FAIL;
3151     int ret                                    = -1;
3152     nxp_wifi_ap_info_t *ap_params              = NULL;
3153     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
3154 
3155     if ((!if_priv) || (!params))
3156     {
3157         supp_e("%s: Invalid params", __func__);
3158         goto out;
3159     }
3160 
3161     ap_params = (nxp_wifi_ap_info_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_ap_info_t));
3162 
3163     if (!ap_params)
3164     {
3165         supp_e("%s: ap params calloc failed", __func__);
3166         goto out;
3167     }
3168 
3169     ap_params->beacon_set = beacon_set;
3170 
3171     memcpy(ap_params->bssid, params->head + BSSID_OFFSET, WIFI_ETH_ADDR_LEN);
3172 
3173     memcpy(ap_params->head_ie.ie, params->head, params->head_len);
3174 
3175     ap_params->head_ie.ie_len = params->head_len;
3176 
3177     memcpy(ap_params->tail_ie.ie, params->tail, params->tail_len);
3178 
3179     ap_params->tail_ie.ie_len = params->tail_len;
3180 
3181     ap_params->dtim_period = params->dtim_period;
3182 
3183     ap_params->beacon_int = params->beacon_int;
3184 
3185     if (params->proberesp && params->proberesp_len)
3186     {
3187         memcpy(ap_params->proberesp.ie, params->proberesp, params->proberesp_len);
3188 
3189         ap_params->proberesp_ies.ie_len = params->proberesp_len;
3190     }
3191 
3192     if (params->ssid && params->ssid_len)
3193     {
3194         memcpy((void *)ap_params->ssid.ssid, (const void *)params->ssid, (size_t)params->ssid_len);
3195 
3196         ap_params->ssid.ssid_len = params->ssid_len;
3197     }
3198 
3199     ap_params->hide_ssid = params->hide_ssid;
3200 
3201     ap_params->pairwise_ciphers = params->pairwise_ciphers;
3202     ap_params->group_cipher     = params->group_cipher;
3203     ap_params->key_mgmt_suites  = params->key_mgmt_suites;
3204     ap_params->auth_algs        = params->auth_algs;
3205     ap_params->wpa_version      = params->wpa_version;
3206     ap_params->privacy          = params->privacy;
3207 
3208     if (params->beacon_ies)
3209     {
3210         memcpy(ap_params->beacon_ies.ie, params->beacon_ies->buf, params->beacon_ies->used);
3211 
3212         ap_params->beacon_ies.ie_len = params->beacon_ies->used;
3213     }
3214 
3215     if (params->proberesp_ies)
3216     {
3217         memcpy(ap_params->proberesp_ies.ie, params->proberesp_ies->buf, params->proberesp_ies->used);
3218 
3219         ap_params->proberesp_ies.ie_len = params->proberesp_ies->used;
3220     }
3221 
3222     if (params->assocresp_ies)
3223     {
3224         memcpy(ap_params->assocresp_ies.ie, params->assocresp_ies->buf, params->assocresp_ies->used);
3225 
3226         ap_params->assocresp_ies.ie_len = params->assocresp_ies->used;
3227     }
3228 
3229     ap_params->ht_opmode         = params->ht_opmode;
3230     ap_params->ap_max_inactivity = params->ap_max_inactivity;
3231     ap_params->reenable          = params->reenable;
3232     ap_params->twt_responder     = params->twt_responder;
3233     ap_params->sae_pwe           = params->sae_pwe;
3234 
3235     if (params->freq)
3236     {
3237         ap_params->chan.mode               = (enum wifi_mode)params->freq->mode;
3238         ap_params->chan.freq               = params->freq->freq;
3239         ap_params->chan.channel            = params->freq->channel;
3240         ap_params->chan.sec_channel_offset = params->freq->sec_channel_offset;
3241         ap_params->chan.bandwidth          = params->freq->bandwidth;
3242         ap_params->chan.ht_enabled         = params->freq->ht_enabled;
3243         ap_params->chan.vht_enabled        = params->freq->vht_enabled;
3244         ap_params->chan.he_enabled         = params->freq->he_enabled;
3245         ap_params->chan.center_freq1       = params->freq->center_freq1;
3246         ap_params->chan.center_freq2       = params->freq->center_freq2;
3247     }
3248 
3249     status = wifi_nxp_beacon_config(ap_params);
3250     if (status != WM_SUCCESS)
3251     {
3252         supp_e("%s: wifi nxp beacon config failed", __func__);
3253         goto out;
3254     }
3255 
3256     if (!beacon_set)
3257     {
3258         wifi_if_ctx_rtos->uap_started = true;
3259     }
3260 
3261     ret = 0;
3262 out:
3263     if (ap_params != NULL)
3264     {
3265         OSA_MemoryFree((void *)ap_params);
3266     }
3267     return ret;
3268 }
3269 
wifi_nxp_hostapd_sta_add(void * if_priv,struct hostapd_sta_add_params * params)3270 int wifi_nxp_hostapd_sta_add(void *if_priv, struct hostapd_sta_add_params *params)
3271 {
3272     int status                      = -WM_FAIL;
3273     nxp_wifi_sta_info_t *sta_params = NULL;
3274 
3275     if ((!if_priv) || (!params))
3276     {
3277         supp_e("%s: Invalid params", __func__);
3278         goto out;
3279     }
3280 
3281     sta_params = (nxp_wifi_sta_info_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_sta_info_t));
3282 
3283     if (!sta_params)
3284     {
3285         supp_e("%s: sta params calloc failed", __func__);
3286         goto out;
3287     }
3288 
3289     sta_params->set = params->set;
3290 
3291     memcpy(sta_params->addr, params->addr, WIFI_ETH_ADDR_LEN);
3292 
3293     sta_params->aid = params->aid;
3294 
3295     sta_params->capability = params->capability;
3296 
3297     if (params->supp_rates_len)
3298     {
3299         sta_params->supp_rates_len = params->supp_rates_len;
3300         memcpy((void *)sta_params->supp_rates, (const void *)params->supp_rates, (size_t)sta_params->supp_rates_len);
3301     }
3302 
3303     sta_params->listen_interval = params->listen_interval;
3304 
3305     if (params->ext_capab)
3306     {
3307         memcpy(sta_params->ext_capab, params->ext_capab, params->ext_capab_len);
3308         sta_params->ext_capab_len = params->ext_capab_len;
3309     }
3310 
3311     sta_params->qosinfo = params->qosinfo;
3312 
3313     if (params->flags & WPA_STA_AUTHORIZED)
3314         sta_params->flags |= STA_FLAG_AUTHORIZED;
3315 
3316     if (params->flags & WPA_STA_WMM)
3317         sta_params->flags |= STA_FLAG_WME;
3318 
3319     if (params->flags & WPA_STA_SHORT_PREAMBLE)
3320         sta_params->flags |= STA_FLAG_SHORT_PREAMBLE;
3321 
3322     if (params->flags & WPA_STA_MFP)
3323         sta_params->flags |= STA_FLAG_MFP;
3324 
3325     if (params->flags & WPA_STA_AUTHENTICATED)
3326         sta_params->flags |= STA_FLAG_AUTHENTICATED;
3327 
3328     if (params->flags & WPA_STA_ASSOCIATED)
3329         sta_params->flags |= STA_FLAG_ASSOCIATED;
3330 
3331     if (params->ht_capabilities)
3332     {
3333         memcpy(&sta_params->ht_capab, params->ht_capabilities, sizeof(struct ieee80211_ht_capabilities));
3334         sta_params->ht_capab_len = sizeof(struct ieee80211_ht_capabilities);
3335     }
3336 
3337     if (params->vht_capabilities)
3338     {
3339         memcpy(&sta_params->vht_capab, params->vht_capabilities, sizeof(struct ieee80211_vht_capabilities));
3340         sta_params->vht_capab_len = sizeof(struct ieee80211_vht_capabilities);
3341     }
3342 
3343     if (params->he_capab)
3344     {
3345         memcpy(&sta_params->he_capab, params->he_capab, sizeof(struct ieee80211_he_capabilities));
3346         sta_params->he_capab_len = params->he_capab_len;
3347     }
3348 
3349     status = wifi_nxp_sta_add(sta_params);
3350     if (status != WM_SUCCESS)
3351     {
3352         supp_e("%s: wifi nxp sta add failed", __func__);
3353     }
3354 
3355     wifi_uap_client_assoc(sta_params->addr, params->ht_capabilities ? 1 : 0);
3356 out:
3357     if (sta_params != NULL)
3358     {
3359         OSA_MemoryFree((void *)sta_params);
3360     }
3361     return status;
3362 }
3363 
wifi_nxp_hostapd_sta_remove(void * if_priv,const u8 * addr)3364 int wifi_nxp_hostapd_sta_remove(void *if_priv, const u8 *addr)
3365 {
3366     int status = -WM_FAIL;
3367 
3368     if ((!if_priv) || (!addr))
3369     {
3370         supp_e("%s: Invalid params", __func__);
3371         goto out;
3372     }
3373 
3374     status = wifi_nxp_sta_remove(addr);
3375     if (status != WM_SUCCESS)
3376     {
3377         supp_e("%s: wifi nxp sta remove failed", __func__);
3378     }
3379 
3380     wifi_uap_client_deauth((t_u8 *)addr);
3381 out:
3382     return status;
3383 }
3384 
wifi_nxp_hostapd_send_eapol(void * if_priv,const u8 * data,size_t data_len)3385 int wifi_nxp_hostapd_send_eapol(void *if_priv, const u8 *data, size_t data_len)
3386 {
3387     int ret = -1;
3388     if ((!if_priv) || (!data))
3389     {
3390         supp_e("%s: Invalid params\n", __func__);
3391         goto out;
3392     }
3393 
3394     ret = wifi_supp_inject_frame(WLAN_BSS_TYPE_UAP, data, data_len);
3395 
3396 out:
3397     return ret;
3398 }
3399 
wifi_nxp_hostapd_set_freq(void * if_priv,struct hostapd_freq_params * freq)3400 int wifi_nxp_hostapd_set_freq(void *if_priv, struct hostapd_freq_params *freq)
3401 {
3402     int ret = -1;
3403     nxp_wifi_chan_info_t chan;
3404 
3405     if ((!if_priv) || (!freq))
3406     {
3407         supp_e("%s: Invalid params\n", __func__);
3408         goto out;
3409     }
3410 
3411     memset(&chan, 0x00, sizeof(nxp_wifi_chan_info_t));
3412 
3413 #if 0
3414     PRINTF("freq->freq: %d\r\n", freq->freq);
3415     PRINTF("freq->channel: %d\r\n", freq->channel);
3416     PRINTF("freq->ht_enabled: %d\r\n", freq->ht_enabled);
3417     PRINTF("freq->sec_channel_offset: %d\r\n", freq->sec_channel_offset);
3418     PRINTF("freq->vht_enabled: %d\r\n", freq->vht_enabled);
3419     PRINTF("freq->he_enabled: %d\r\n", freq->he_enabled);
3420     PRINTF("freq->bandwidth: %d\r\n", freq->bandwidth);
3421 #endif
3422     ret = 0;
3423 
3424     chan.mode               = (enum wifi_mode)freq->mode;
3425     chan.freq               = freq->freq;
3426     chan.channel            = freq->channel;
3427     chan.sec_channel_offset = freq->sec_channel_offset;
3428     chan.bandwidth          = freq->bandwidth;
3429     chan.ht_enabled         = freq->ht_enabled;
3430     chan.vht_enabled        = freq->vht_enabled;
3431     chan.he_enabled         = freq->he_enabled;
3432     chan.center_freq1       = freq->center_freq1;
3433     chan.center_freq2       = freq->center_freq2;
3434 
3435     ret = 0; // wifi_nxp_set_chan(chan);
3436 
3437 out:
3438     return ret;
3439 }
3440 
wifi_nxp_hostapd_set_rts(void * if_priv,int rts_threshold)3441 int wifi_nxp_hostapd_set_rts(void *if_priv, int rts_threshold)
3442 {
3443     int ret = -1;
3444     if (!if_priv)
3445     {
3446         supp_e("%s: Invalid params\n", __func__);
3447         goto out;
3448     }
3449 
3450     // ret = wifi_nxp_set_rts(rts_threshold);
3451     ret = wifi_set_uap_rts(rts_threshold);
3452 
3453 out:
3454     return ret;
3455 }
3456 
wifi_nxp_hostapd_set_frag(void * if_priv,int frag_threshold)3457 int wifi_nxp_hostapd_set_frag(void *if_priv, int frag_threshold)
3458 {
3459     int ret = -1;
3460     if (!if_priv)
3461     {
3462         supp_e("%s: Invalid params\n", __func__);
3463         goto out;
3464     }
3465 
3466     ret = wifi_set_uap_frag(frag_threshold);
3467 
3468 out:
3469     return ret;
3470 }
3471 
wifi_nxp_hostapd_stop_ap(void * if_priv)3472 int wifi_nxp_hostapd_stop_ap(void *if_priv)
3473 {
3474     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
3475     int ret                                    = -1;
3476     if (!if_priv)
3477     {
3478         supp_e("%s: Invalid params", __func__);
3479         goto out;
3480     }
3481 
3482     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
3483 
3484     ret = wifi_nxp_stop_ap();
3485     if (ret != 0)
3486     {
3487         supp_e("%s: Stop AP failed", __func__);
3488         goto out;
3489     }
3490     wifi_if_ctx_rtos->uap_started = false;
3491 out:
3492     return ret;
3493 }
3494 
wifi_nxp_hostapd_set_acl(void * if_priv,struct hostapd_acl_params * params)3495 int wifi_nxp_hostapd_set_acl(void *if_priv, struct hostapd_acl_params *params)
3496 {
3497     // struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
3498     int ret                         = -1;
3499     nxp_wifi_acl_info_t *acl_params = NULL;
3500     size_t acl_sz                   = 0;
3501     unsigned int i;
3502 
3503     if ((!if_priv) || (!params))
3504     {
3505         supp_e("%s: Invalid params", __func__);
3506         goto out;
3507     }
3508 
3509     // wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
3510 
3511     acl_sz = WIFI_ETH_ADDR_LEN * params->num_mac_acl;
3512 
3513     acl_params = (nxp_wifi_acl_info_t *)OSA_MemoryAllocate(sizeof(nxp_wifi_acl_info_t) + acl_sz);
3514     if (!acl_params)
3515     {
3516         supp_e("%s: acl params calloc failed", __func__);
3517         goto out;
3518     }
3519 
3520     acl_params->acl_policy  = params->acl_policy;
3521     acl_params->num_mac_acl = params->num_mac_acl;
3522 
3523     for (i = 0; i < params->num_mac_acl; i++)
3524     {
3525         memcpy(acl_params->mac_acl[i].addr, params->mac_acl[i].addr, WIFI_ETH_ADDR_LEN);
3526     }
3527 
3528     ret = wifi_nxp_set_acl(acl_params);
3529     if (ret != 0)
3530     {
3531         supp_e("%s: Set ACL failed", __func__);
3532     }
3533 
3534 out:
3535     if (acl_params)
3536         OSA_MemoryFree((void *)acl_params);
3537     return ret;
3538 }
3539 #endif
3540 
wifi_nxp_wpa_dpp_listen(void * if_priv,bool enable)3541 int wifi_nxp_wpa_dpp_listen(void *if_priv, bool enable)
3542 {
3543     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
3544 
3545     if (!if_priv)
3546     {
3547         supp_e("%s: Invalid params", __func__);
3548         goto out;
3549     }
3550 
3551     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
3552 
3553     return wlan_supp_dpp_listen(wifi_if_ctx_rtos->bss_type, enable);
3554 out:
3555     return -1;
3556 }
3557 
wifi_nxp_wpa_get_modes(void * if_priv)3558 bool wifi_nxp_wpa_get_modes(void *if_priv)
3559 {
3560     return (!ISSUPP_NO5G(mlan_adap->fw_cap_ext));
3561 }
3562 
wifi_nxp_wpa_supp_cancel_action_wait(void * if_priv)3563 void wifi_nxp_wpa_supp_cancel_action_wait(void *if_priv)
3564 {
3565     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = NULL;
3566 
3567     if (!if_priv)
3568     {
3569         supp_e("%s: Invalid params", __func__);
3570         goto out;
3571     }
3572 
3573     wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)if_priv;
3574     if (wifi_if_ctx_rtos->bss_type == BSS_TYPE_STA)
3575     {
3576         (void)wifi_remain_on_channel(false, 0, 0);
3577     }
3578 
3579 out:
3580     return;
3581 }
3582 #endif
3583