blob: 2eeaf8c0ecf523604cff9897c680ce6fc2070977 [file] [log] [blame]
developer72fb0bb2023-01-11 09:46:29 +08001/*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2019 RDK Management
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18*/
19
20/*
21* Material from the TR181 data model is Copyright (c) 2010-2017, Broadband Forum
22* Licensed under the BSD-3 license
23*/
24
25/*
26* This file includes material that is Copyright (c) 2020, Plume Design Inc.
27* Licensed under the BSD-3 license
28*/
29
30/* Code in rxStatsInfo_callback and other callbacks is credited as follows:
developera3511852023-06-14 14:12:59 +080031Copyright (c) 2007, 2008 Johannes Berg
32Copyright (c) 2007 Andy Lutomirski
33Copyright (c) 2007 Mike Kershaw
34Copyright (c) 2008-2009 Luis R. Rodriguez
developer72fb0bb2023-01-11 09:46:29 +080035Licensed under the ISC license
36*/
37#define MTK_IMPL
38#define HAL_NETLINK_IMPL
39#define _GNU_SOURCE /* needed for strcasestr */
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <string.h>
45#include <fcntl.h>
46#include <stdbool.h>
47#include "wifi_hal.h"
48
49#ifdef HAL_NETLINK_IMPL
50#include <errno.h>
51#include <netlink/attr.h>
52#include <netlink/netlink.h>
53#include <netlink/genl/genl.h>
54#include <netlink/genl/family.h>
55#include <netlink/genl/ctrl.h>
56#include <linux/nl80211.h>
developer8dd72532023-05-17 19:58:35 +080057#include <net/if.h>
58#include <unl.h>
59#include "mtk_vendor_nl80211.h"
developer72fb0bb2023-01-11 09:46:29 +080060#endif
61
62#include <ev.h>
63#include <wpa_ctrl.h>
64#include <errno.h>
65#include <time.h>
developercc5cbfb2023-06-13 18:29:52 +080066
67#include <sys/socket.h>
68#include <sys/ioctl.h>
69#include <arpa/inet.h>
70#include <linux/if.h>
71#include <linux/if_bridge.h>
72#include <linux/sockios.h>
developer86035662023-06-28 19:21:12 +080073#include <errno.h>
74#include <limits.h>
developer33f13ba2023-07-12 16:19:06 +080075#include "secure_wrapper.h"
developercc5cbfb2023-06-13 18:29:52 +080076
developer72fb0bb2023-01-11 09:46:29 +080077#define MAC_ALEN 6
78
79#define MAX_BUF_SIZE 256
80#define MAX_CMD_SIZE 256
developerb149d9d2023-06-06 16:14:22 +080081#define MAX_SUB_CMD_SIZE 200
82
developer72fb0bb2023-01-11 09:46:29 +080083#define IF_NAME_SIZE 16
84#define CONFIG_PREFIX "/nvram/hostapd"
85#define ACL_PREFIX "/nvram/hostapd-acl"
86#define DENY_PREFIX "/nvram/hostapd-deny"
87//#define ACL_PREFIX "/tmp/wifi_acl_list" //RDKB convention
88#define SOCK_PREFIX "/var/run/hostapd/wifi"
89#define VAP_STATUS_FILE "/nvram/vap-status"
90#define ESSID_FILE "/tmp/essid"
91#define GUARD_INTERVAL_FILE "/nvram/guard-interval"
92#define CHANNEL_STATS_FILE "/tmp/channel_stats"
93#define DFS_ENABLE_FILE "/nvram/dfs_enable.txt"
94#define VLAN_FILE "/nvram/hostapd.vlan"
95#define PSK_FILE "/nvram/hostapd"
96#define MCS_FILE "/tmp/MCS"
developera1255e42023-05-13 17:45:02 +080097#define POWER_PERCENTAGE "/tmp/POWER"
98#define MGMT_POWER_CTRL "/tmp/mgmt_power_ctrl"
99/*LOGAN_DAT_FILE: may be different on customer's platform.*/
developerc7adba42023-07-14 10:58:45 +0800100#ifdef WIFI_7992
101#define LOGAN_DAT_FILE "/etc/wireless/mediatek/mt7992.b"
102#define ROM_LOGAN_DAT_FILE "/rom/etc/wireless/mediatek/mt7992.b"
103#else
developera1255e42023-05-13 17:45:02 +0800104#define LOGAN_DAT_FILE "/etc/wireless/mediatek/mt7990.b"
developerb2977562023-05-24 17:54:12 +0800105#define ROM_LOGAN_DAT_FILE "/rom/etc/wireless/mediatek/mt7990.b"
developerc7adba42023-07-14 10:58:45 +0800106#endif
developera1255e42023-05-13 17:45:02 +0800107
developer72fb0bb2023-01-11 09:46:29 +0800108#define NOACK_MAP_FILE "/tmp/NoAckMap"
developerfead3972023-05-25 20:15:02 +0800109#define RADIO_RESET_FILE "/nvram/radio_reset"
developerf6a87542023-05-16 15:47:28 +0800110
developer72fb0bb2023-01-11 09:46:29 +0800111#define BRIDGE_NAME "brlan0"
developerd1824452023-05-18 12:30:04 +0800112#define BASE_PHY_INDEX 1
113#define BASE_RADIO_INDEX 0
developer72fb0bb2023-01-11 09:46:29 +0800114
115/*
116 MAX_APS - Number of all AP available in system
117 2x Home AP
118 2x Backhaul AP
119 2x Guest AP
120 2x Secure Onboard AP
121 2x Service AP
122
123*/
124
developerbb9b20f2023-10-17 18:46:37 +0800125#define LOGAN_MAX_NUM_VAP_PER_RADIO (MAX_NUM_VAP_PER_RADIO > 16 ? 16 : MAX_NUM_VAP_PER_RADIO)
126#define MAX_APS MAX_NUM_RADIOS * LOGAN_MAX_NUM_VAP_PER_RADIO
developer7e4a2a62023-04-06 19:56:03 +0800127
128#define PREFIX_WIFI2G "ra"
129#define PREFIX_WIFI5G "rai"
130#define PREFIX_WIFI6G "rax"
developer72fb0bb2023-01-11 09:46:29 +0800131
developer47cc27a2023-05-17 23:09:58 +0800132#define PREFIX_SSID_2G "RDKB_2G"
133#define PREFIX_SSID_5G "RDKB_5G"
134#define PREFIX_SSID_6G "RDKB_6G"
135
developer72fb0bb2023-01-11 09:46:29 +0800136#ifndef RADIO_PREFIX
137#define RADIO_PREFIX "wlan"
138#endif
139
140#define MAX_ASSOCIATED_STA_NUM 2007
141
142//Uncomment to enable debug logs
143//#define WIFI_DEBUG
developer49b17232023-05-19 16:35:19 +0800144enum {
145 DEBUG_OFF = 0,
146 DEBUG_ERROR = 1,
147 DEBUG_WARN = 2,
148 DEBUG_NOTICE = 3,
149 DEBUG_INFO = 4
150};
151int wifi_debug_level = DEBUG_NOTICE;
152#define wifi_debug(level, fmt, args...) \
153{ \
154 if (level <= wifi_debug_level) \
155 { \
developer2edaf012023-05-24 14:24:53 +0800156 printf("[%s][%d]"fmt"", __func__, __LINE__, ##args); \
developer49b17232023-05-19 16:35:19 +0800157 } \
158}
developer72fb0bb2023-01-11 09:46:29 +0800159
160#ifdef WIFI_DEBUG
161#define wifi_dbg_printf printf
162#define WIFI_ENTRY_EXIT_DEBUG printf
163#else
developer2f79c922023-06-02 17:33:42 +0800164#define wifi_dbg_printf(format, args...)
165#define WIFI_ENTRY_EXIT_DEBUG(format, args...)
developer72fb0bb2023-01-11 09:46:29 +0800166#endif
167
168#define HOSTAPD_CONF_0 "/nvram/hostapd0.conf" //private-wifi-2g
169#define HOSTAPD_CONF_1 "/nvram/hostapd1.conf" //private-wifi-5g
170#define HOSTAPD_CONF_4 "/nvram/hostapd4.conf" //public-wifi-2g
171#define HOSTAPD_CONF_5 "/nvram/hostapd5.conf" //public-wifi-5g
172#define DEF_HOSTAPD_CONF_0 "/usr/ccsp/wifi/hostapd0.conf"
173#define DEF_HOSTAPD_CONF_1 "/usr/ccsp/wifi/hostapd1.conf"
174#define DEF_HOSTAPD_CONF_4 "/usr/ccsp/wifi/hostapd4.conf"
175#define DEF_HOSTAPD_CONF_5 "/usr/ccsp/wifi/hostapd5.conf"
176#define DEF_RADIO_PARAM_CONF "/usr/ccsp/wifi/radio_param_def.cfg"
177#define LM_DHCP_CLIENT_FORMAT "%63d %17s %63s %63s"
178
179#define HOSTAPD_HT_CAPAB "[LDPC][SHORT-GI-20][SHORT-GI-40][MAX-AMSDU-7935]"
180
181#define BW_FNAME "/nvram/bw_file.txt"
182
183#define PS_MAX_TID 16
184
developer96b38512023-02-22 11:17:45 +0800185#define MAX_CARD_INDEX 3
186
developer72fb0bb2023-01-11 09:46:29 +0800187static wifi_radioQueueType_t _tid_ac_index_get[PS_MAX_TID] = {
developera3511852023-06-14 14:12:59 +0800188 WIFI_RADIO_QUEUE_TYPE_BE, /* 0 */
189 WIFI_RADIO_QUEUE_TYPE_BK, /* 1 */
190 WIFI_RADIO_QUEUE_TYPE_BK, /* 2 */
191 WIFI_RADIO_QUEUE_TYPE_BE, /* 3 */
192 WIFI_RADIO_QUEUE_TYPE_VI, /* 4 */
193 WIFI_RADIO_QUEUE_TYPE_VI, /* 5 */
194 WIFI_RADIO_QUEUE_TYPE_VO, /* 6 */
195 WIFI_RADIO_QUEUE_TYPE_VO, /* 7 */
196 WIFI_RADIO_QUEUE_TYPE_BE, /* 8 */
197 WIFI_RADIO_QUEUE_TYPE_BK, /* 9 */
198 WIFI_RADIO_QUEUE_TYPE_BK, /* 10 */
199 WIFI_RADIO_QUEUE_TYPE_BE, /* 11 */
200 WIFI_RADIO_QUEUE_TYPE_VI, /* 12 */
201 WIFI_RADIO_QUEUE_TYPE_VI, /* 13 */
202 WIFI_RADIO_QUEUE_TYPE_VO, /* 14 */
203 WIFI_RADIO_QUEUE_TYPE_VO, /* 15 */
developer72fb0bb2023-01-11 09:46:29 +0800204};
205
206typedef unsigned long long u64;
207
208/* Enum to define WiFi Bands */
209typedef enum
210{
developera3511852023-06-14 14:12:59 +0800211 band_invalid = -1,
212 band_2_4 = 0,
213 band_5 = 1,
214 band_6 = 2,
developer72fb0bb2023-01-11 09:46:29 +0800215} wifi_band;
216
developer17038e62023-03-02 14:43:43 +0800217char* wifi_band_str[] = {
developera3511852023-06-14 14:12:59 +0800218 "2G",
219 "5G",
220 "6G",
developer17038e62023-03-02 14:43:43 +0800221};
222
developer72fb0bb2023-01-11 09:46:29 +0800223typedef enum {
developera3511852023-06-14 14:12:59 +0800224 WIFI_MODE_A = 0x01,
225 WIFI_MODE_B = 0x02,
226 WIFI_MODE_G = 0x04,
227 WIFI_MODE_N = 0x08,
228 WIFI_MODE_AC = 0x10,
229 WIFI_MODE_AX = 0x20,
230 WIFI_MODE_BE = 0x40,
developer72fb0bb2023-01-11 09:46:29 +0800231} wifi_ieee80211_Mode;
232
developer2f79c922023-06-02 17:33:42 +0800233typedef enum {
developera3511852023-06-14 14:12:59 +0800234 HT_BW_20,
235 HT_BW_40,
developer2f79c922023-06-02 17:33:42 +0800236} ht_config_bw;
developerd1824452023-05-18 12:30:04 +0800237
developer2f79c922023-06-02 17:33:42 +0800238typedef enum {
developera3511852023-06-14 14:12:59 +0800239 VHT_BW_2040,
240 VHT_BW_80,
241 VHT_BW_160,
242 VHT_BW_8080,
developer2f79c922023-06-02 17:33:42 +0800243} vht_config_bw;
developerd1824452023-05-18 12:30:04 +0800244
developer2f79c922023-06-02 17:33:42 +0800245typedef enum {
developera3511852023-06-14 14:12:59 +0800246 EHT_BW_20,
247 EHT_BW_40,
248 EHT_BW_80,
249 EHT_BW_160,
250 EHT_BW_320,
developer2f79c922023-06-02 17:33:42 +0800251} eht_config_bw;
developerd1824452023-05-18 12:30:04 +0800252
developer72fb0bb2023-01-11 09:46:29 +0800253#ifdef WIFI_HAL_VERSION_3
254
255// Return number of elements in array
256#ifndef ARRAY_SIZE
developera3511852023-06-14 14:12:59 +0800257#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
developer72fb0bb2023-01-11 09:46:29 +0800258#endif /* ARRAY_SIZE */
259
260#ifndef ARRAY_AND_SIZE
developera3511852023-06-14 14:12:59 +0800261#define ARRAY_AND_SIZE(x) (x),ARRAY_SIZE(x)
developer72fb0bb2023-01-11 09:46:29 +0800262#endif /* ARRAY_AND_SIZE */
263
developera3511852023-06-14 14:12:59 +0800264#define WIFI_ITEM_STR(key, str) {0, sizeof(str)-1, (int)key, (intptr_t)str}
developer72fb0bb2023-01-11 09:46:29 +0800265
266typedef struct {
developera3511852023-06-14 14:12:59 +0800267 int32_t value;
268 int32_t param;
269 intptr_t key;
270 intptr_t data;
developer72fb0bb2023-01-11 09:46:29 +0800271} wifi_secur_list;
272
developer0155a502023-06-19 20:33:57 +0800273typedef struct GNU_PACKED _wdev_extended_ap_metrics {
274 unsigned int uc_tx;
275 unsigned int uc_rx;
276 unsigned int mc_tx;
277 unsigned int mc_rx;
278 unsigned int bc_tx;
279 unsigned int bc_rx;
280} wdev_extended_ap_metric;
281
282typedef struct GNU_PACKED _wdev_ap_metric {
283 unsigned char bssid[6];
284 unsigned char cu;
285 unsigned char ESPI_AC[4][3];
286 wdev_extended_ap_metric ext_ap_metric;
287} wdev_ap_metric;
288
developer6c6ef372023-11-08 10:59:14 +0800289enum mld_type {
290 AP_MLD_SINGLE_LINK,
291 AP_MLD_MULTI_LINK,
292};
293
294struct multi_link_device {
295 unsigned char mld_mac[6];
296 unsigned char mld_index;
297// enum mld_type type;
298 unsigned char affiliated_ap_bitmap[6];
299};
300
301struct mld_configuration {
302 unsigned char valid_mld_bitmap[9];
303 struct multi_link_device mld[66]; /*0,65 - invalid, 1~16 multi-link mld, 17-64 single link mld*/
304};
305struct mld_configuration mld_config;
developer0155a502023-06-19 20:33:57 +0800306
developer72fb0bb2023-01-11 09:46:29 +0800307static int util_unii_5g_centerfreq(const char *ht_mode, int channel);
308static int util_unii_6g_centerfreq(const char *ht_mode, int channel);
developera3511852023-06-14 14:12:59 +0800309wifi_secur_list * wifi_get_item_by_key(wifi_secur_list *list, int list_sz, int key);
310wifi_secur_list * wifi_get_item_by_str(wifi_secur_list *list, int list_sz, const char *str);
311char * wifi_get_str_by_key(wifi_secur_list *list, int list_sz, int key);
developer72fb0bb2023-01-11 09:46:29 +0800312static int ieee80211_channel_to_frequency(int channel, int *freqMHz);
developerd14dff12023-06-28 22:47:44 +0800313static void wifi_PrepareDefaultHostapdConfigs(bool reset);
developer47cc27a2023-05-17 23:09:58 +0800314static void wifi_psk_file_reset();
developerb2977562023-05-24 17:54:12 +0800315static void wifi_dat_file_reset_by_radio(char radio_idx);
developer262f4cb2023-05-24 12:22:04 +0800316static int util_get_sec_chan_offset(int channel, const char* ht_mode);
developer2f79c922023-06-02 17:33:42 +0800317int hostapd_raw_add_bss(int apIndex);
318int hostapd_raw_remove_bss(int apIndex);
developerd14dff12023-06-28 22:47:44 +0800319INT wifi_getApDevicesAssociated(INT apIndex, CHAR *macArray, UINT buf_size);
320
developer86035662023-06-28 19:21:12 +0800321static inline int hal_strtol(char *src, int base, long int *out)
322{
323 long int res = 0;
324 char *end_ptr = NULL;
325
326 errno = 0;
327 res = strtol(src, &end_ptr, base);
328
329 if ((errno == ERANGE && (res == LONG_MIN || res == LONG_MAX))
developer5fbf2ff2023-06-30 10:51:56 +0800330 || (errno != 0 && res == 0) || /*ignore end_ptr!=0 error*/ /**end_ptr != '\0' ||*/src == end_ptr ) {
331 *out = res;
developer86035662023-06-28 19:21:12 +0800332 return -1;
developer5fbf2ff2023-06-30 10:51:56 +0800333 } else
developer86035662023-06-28 19:21:12 +0800334 *out = res;
335
336 return 0;
337}
338
339static inline int hal_strtoul(char *src, int base, unsigned long *out)
340{
341 unsigned long res = 0;
342 char *end_ptr = NULL;
343
344 errno = 0;
345 res = strtoul(src, &end_ptr, base);
346
347 if ((errno == ERANGE && res == ULONG_MAX)
developer5fbf2ff2023-06-30 10:51:56 +0800348 || (errno != 0 && res == 0) || /*ignore end_ptr!=0 error*/ /**end_ptr != '\0' ||*/src == end_ptr ) {
349 *out = res;
developer86035662023-06-28 19:21:12 +0800350 return -1;
developer5fbf2ff2023-06-30 10:51:56 +0800351 } else
developer86035662023-06-28 19:21:12 +0800352 *out = res;
353
354 return 0;
355}
developer47cc27a2023-05-17 23:09:58 +0800356
developercc5cbfb2023-06-13 18:29:52 +0800357static inline int os_snprintf_error(size_t size, int res)
358{
359 return res < 0 || (unsigned int) res >= size;
360}
361
developer49b17232023-05-19 16:35:19 +0800362/*type define the nl80211 call back func*/
363typedef int (*mtk_nl80211_cb) (struct nl_msg *, void *);
364
365/**
366*struct mtk_nl80211_param
367* init mtk nl80211 using parameters
368* @sub_cmd: the cmd define in the mtk_vendor_nl80211.h.
369* @if_type: now only support the NL80211_ATTR_IFINDEX/NL80211_ATTR_WIPHY.
370* @if_idx: the index should match the interface or wiphy.
371* Note: NA
372**/
373struct mtk_nl80211_param {
374 unsigned int sub_cmd;
375 int if_type;
376 int if_idx;
377};
378
379/**
developer121a8e72023-05-22 09:19:39 +0800380*struct mtk_nl80211_cb_data
381* init mtk nl80211 call back parameters
382* @out_buf: store the mtk vendor output msg for wifi hal buffer.
383* @out_len: the output buffer length.
384* Note: NA
385**/
386struct mtk_nl80211_cb_data {
387 char * out_buf;
388 unsigned int out_len;
389};
390
391/**
developer49b17232023-05-19 16:35:19 +0800392*mtk_nl80211_init
393* init mtk nl80211 netlink and init the vendor msg common part.
394* @nl: netlink, just init it.
395* @msg: netlink message will alloc it.
396* the msg send success/fails is not free by app
397* only the nla_put etc api fails should use nlmsg_free.
398* @msg_data: vendor data msg attr pointer.
399* @param: init using interface and sub_cmd parameter.
400*
401*init the netlink context and mtk netlink vendor msg.
402*
403*return:
404* 0: success
405* other: fail
406**/
407
408int mtk_nl80211_init(struct unl *nl, struct nl_msg **msg,
409 struct nlattr **msg_data, struct mtk_nl80211_param *param) {
410 /*sanity check here*/
411 if (!nl || !param) {
412 (void)fprintf(stderr,
developerdaf24792023-06-06 11:40:04 +0800413 "[%s][%d]:nl(%p) or param(%p) is null, error!\n",
developer49b17232023-05-19 16:35:19 +0800414 __func__, __LINE__, nl, param);
415 return -1;
416 }
417 /*if_type check*/
418 if ( param->if_type != NL80211_ATTR_IFINDEX && param->if_type != NL80211_ATTR_WIPHY) {
419 (void)fprintf(stderr,
420 "[%s][%d]:if_type(0x%x) is not supported, only 0x%x and 0x%x supported.\n",
421 __func__, __LINE__, param->if_type, NL80211_ATTR_IFINDEX, NL80211_ATTR_WIPHY);
422 return -1;
423 }
424 /*init the nl*/
425 if (unl_genl_init(nl, "nl80211") < 0) {
426 (void)fprintf(stderr, "[%s][%d]::Failed to connect to nl80211\n",
427 __func__, __LINE__);
428 return -1;
429 }
430 /*init the msg*/
431 *msg = unl_genl_msg(nl, NL80211_CMD_VENDOR, false);
432
433 if (nla_put_u32(*msg, param->if_type, param->if_idx) ||
developera3511852023-06-14 14:12:59 +0800434 nla_put_u32(*msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
435 nla_put_u32(*msg, NL80211_ATTR_VENDOR_SUBCMD, param->sub_cmd)) {
developer49b17232023-05-19 16:35:19 +0800436 (void)fprintf(stderr,
437 "[%s][%d]:Nla put error: if_type: 0x%x, if_idx: 0x%x, sub_cmd: 0x%x\n",
438 __func__, __LINE__, param->if_type, param->if_idx, param->sub_cmd);
439 goto err;
440 }
441
442 *msg_data = nla_nest_start(*msg, NL80211_ATTR_VENDOR_DATA);
443 if (!*msg_data) {
444 (void)fprintf(stderr, "[%s][%d]:Nla put NL80211_ATTR_VENDOR_DATA start error\n",
445 __func__, __LINE__);
446 goto err;
447 }
448
449 return 0;
450err:
developer49b17232023-05-19 16:35:19 +0800451 nlmsg_free(*msg);
452 unl_free(nl);
453 return -1;
454}
455
456/**
457*mtk_nl80211_send
458* set the vendor cmd call back and sent the vendor msg.
459* @nl: netlink.
460* @msg: netlink message.
461* @msg_data: vendor data msg attr pointer.
462* @handler: if the msg have call back shoud add the call back func
463* the event msg will handle by the call back func(exp:get cmd)
464* other set it as NULL(exp:set cmd).
465* @arg:call back func arg parameter.
466*add end of the netlink msg, set the call back and send msg
467*
468*return:
469* 0: success
470* other: fail
471**/
472int mtk_nl80211_send(struct unl *nl, struct nl_msg *msg,
473 struct nlattr *msg_data, mtk_nl80211_cb handler, void *arg) {
474 int ret = 0;
475 /*sanity check*/
476 if (!nl || !msg || !msg_data) {
477 (void)fprintf(stderr,
developerdaf24792023-06-06 11:40:04 +0800478 "[%s][%d]:nl(%p),msg(%p) or msg_data(%p) is null, error!\n",
developer49b17232023-05-19 16:35:19 +0800479 __func__, __LINE__, nl, msg, msg_data);
480 return -1;
481 }
482 /*end the msg attr of vendor data*/
483 nla_nest_end(msg, msg_data);
484 /*send the msg and set call back */
485 ret = unl_genl_request(nl, msg, handler, arg);
486 if (ret)
487 (void)fprintf(stderr, "send nl80211 cmd fails\n");
488 return ret;
489}
490
491/**
492*mtk_nl80211_deint
developer2edaf012023-05-24 14:24:53 +0800493* deinit the netlink.
developer49b17232023-05-19 16:35:19 +0800494* @nl: netlink.
495*
developer2edaf012023-05-24 14:24:53 +0800496*free deinit the netlink.
developer49b17232023-05-19 16:35:19 +0800497*
498*return:
499* 0: success
500**/
501
502int mtk_nl80211_deint(struct unl *nl) {
503 unl_free(nl);
504 return 0;
505}
506
developer72fb0bb2023-01-11 09:46:29 +0800507wifi_secur_list * wifi_get_item_by_key(wifi_secur_list *list, int list_sz, int key)
508{
developera3511852023-06-14 14:12:59 +0800509 wifi_secur_list *item;
510 int i;
developer72fb0bb2023-01-11 09:46:29 +0800511
developera3511852023-06-14 14:12:59 +0800512 for (item = list,i = 0;i < list_sz; item++, i++) {
513 if ((int)(item->key) == key) {
514 return item;
515 }
516 }
developer72fb0bb2023-01-11 09:46:29 +0800517
developera3511852023-06-14 14:12:59 +0800518 return NULL;
developer72fb0bb2023-01-11 09:46:29 +0800519}
520
521char * wifi_get_str_by_key(wifi_secur_list *list, int list_sz, int key)
522{
developera3511852023-06-14 14:12:59 +0800523 wifi_secur_list *item = wifi_get_item_by_key(list, list_sz, key);
developer72fb0bb2023-01-11 09:46:29 +0800524
developera3511852023-06-14 14:12:59 +0800525 if (!item) {
526 return "";
527 }
developer72fb0bb2023-01-11 09:46:29 +0800528
developera3511852023-06-14 14:12:59 +0800529 return (char *)(item->data);
developer72fb0bb2023-01-11 09:46:29 +0800530}
531
532wifi_secur_list * wifi_get_item_by_str(wifi_secur_list *list, int list_sz, const char *str)
533{
developera3511852023-06-14 14:12:59 +0800534 wifi_secur_list *item;
535 int i;
developer72fb0bb2023-01-11 09:46:29 +0800536
developera3511852023-06-14 14:12:59 +0800537 for (item = list,i = 0;i < list_sz; item++, i++) {
538 if (strcmp((char *)(item->data), str) == 0) {
539 return item;
540 }
541 }
developer72fb0bb2023-01-11 09:46:29 +0800542
developera3511852023-06-14 14:12:59 +0800543 return NULL;
developer72fb0bb2023-01-11 09:46:29 +0800544}
545#endif /* WIFI_HAL_VERSION_3 */
546
developer6c6ef372023-11-08 10:59:14 +0800547#define _syscmd_secure(retBuf, retBufSize, fmt, args...) \
548 ({ \
549 FILE *f; \
550 char *ptr = retBuf; \
551 int bufSize = retBufSize, bufbytes = 0, readbytes = 0, cmd_ret = -1; \
552 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__); \
553 f = v_secure_popen("r", fmt, ##args); \
554 if(f) { \
555 while(!feof(f)) \
556 { \
557 *ptr = 0; \
558 if(bufSize>=128) { \
559 bufbytes=128; \
560 } else { \
561 bufbytes=bufSize-1; \
562 } \
563 if (fgets(ptr,bufbytes,f) == NULL) \
564 break; \
565 readbytes=strlen(ptr); \
566 if(!readbytes) \
567 break; \
568 bufSize-=readbytes; \
569 ptr += readbytes; \
570 } \
571 cmd_ret = v_secure_pclose(f); \
572 retBuf[retBufSize-1]=0; \
573 } \
574 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__); \
575 cmd_ret; \
576 })
577
developer96b38512023-02-22 11:17:45 +0800578
579static char l1profile[32] = "/etc/wireless/l1profile.dat";
developer17038e62023-03-02 14:43:43 +0800580char main_prefix[MAX_NUM_RADIOS][IFNAMSIZ];
581char ext_prefix[MAX_NUM_RADIOS][IFNAMSIZ];
582#define MAX_SSID_LEN 64
583char default_ssid[MAX_NUM_RADIOS][MAX_SSID_LEN];;
developer745f0bd2023-03-06 14:32:53 +0800584int radio_band[MAX_NUM_RADIOS];
developer17038e62023-03-02 14:43:43 +0800585
586static int array_index_to_vap_index(UINT radioIndex, int arrayIndex);
587static int vap_index_to_array_index(int vapIndex, int *radioIndex, int *arrayIndex);
developer6c6ef372023-11-08 10:59:14 +0800588static int wifi_datfileRead(char *conf_file, char *param, char *output, int output_size);
589int hwaddr_aton2(const char *txt, unsigned char *addr);
590static int wifi_GetInterfaceName(int apIndex, char *interface_name);
591INT wifi_getMaxRadioNumber(INT *max_radio_num);
592static int wifi_BandProfileRead(int card_idx,
593 int radio_idx,
594 char *param,
595 char *output,
596 int output_size,
597 char *default_value);
598static int array_index_to_vap_index(UINT radioIndex, int arrayIndex);
599struct params
600{
601 char * name;
602 char * value;
603};
604static int wifi_datfileWrite(char *conf_file, struct params *list, int item_count);
605
606#ifdef WIFI_HAL_VERSION_3
607#define MAX_ML_MLD_CNT 16 /*Max multi-link MLD*/
608//#define MAX_SL_MLD_CNT 48 /*MAX single-link MLD*/
609
610static void mld_set(unsigned char mld_index, unsigned char set)
611{
612 mld_config.valid_mld_bitmap[mld_index / 8] |= set ? (1 << (mld_index % 8)) : ~(1 << (mld_index % 8));
613}
614
615static unsigned char mld_test(unsigned char mld_index)
616{
617 return mld_config.valid_mld_bitmap[mld_index / 8] & (1 << (mld_index % 8));
618}
619
620static void mld_ap_set(struct multi_link_device *mld, unsigned char ap_index, unsigned char set)
621{
622 mld->affiliated_ap_bitmap[ap_index / 8] |= set ? (1 << (ap_index % 8)) : ~(1 << (ap_index % 8));
623}
624
625static unsigned char mld_ap_test(struct multi_link_device *mld, unsigned char ap_index)
626{
627 return mld->affiliated_ap_bitmap[ap_index / 8] & (1 << (ap_index % 8));
628}
629
630static int eht_mld_config_init(void)
631{
632 char config_file[128] = {0}, str_mldgroup[256], *buf, mac_str[32] = {0};
633 int res, band, bss_idx;
634 char *token;
635 long mld_index;
636 unsigned char ap_index;
637 struct multi_link_device *mld;
638 char *mld_start, *mldaddr_start, *mldaddr_end;
639
640 buf = (char*)malloc(4096);
641 if (!buf) {
642 wifi_debug(DEBUG_ERROR, "fail to allocate memory\n");
643 return RETURN_ERR;
644 }
645 wifi_debug(DEBUG_ERROR, "==========>\n");
646
647 memset(&mld_config, 0, sizeof(mld_config));
648 for (band = 0; band < MAX_NUM_RADIOS; band++) {
649 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
650 if (os_snprintf_error(sizeof(config_file), res)) {
651 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
652 free(buf);
653 return RETURN_ERR;
654 }
655
656 wifi_datfileRead(config_file, "MldGroup", str_mldgroup, sizeof(str_mldgroup));
657 token = strtok(str_mldgroup, ";");
658 bss_idx = 0;
659 while(token != NULL && bss_idx < 16) {
660 if (hal_strtol(token, 10, &mld_index) < 0) {
661 wifi_debug(DEBUG_ERROR, "strtol fail\n");
662 break;
663 }
664
665 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
666 wifi_debug(DEBUG_ERROR, "invalid mld_index %ld, skip it.\n", mld_index);
667 bss_idx++;
668 token = strtok(NULL, ";");
669 continue;
670 }
671
672 mld_set(mld_index, 1);
673 ap_index = array_index_to_vap_index(band, bss_idx);
674
675 mld = &(mld_config.mld[mld_index]);
676 mld->mld_index = mld_index;
677 /* need to fulfill mld mac later.
678 memcpy(mld->mld_mac, mac, sizeof(mld->mld_mac));
679 */
680// mld->type = mld_index <= MAX_ML_MLD_CNT ? AP_MLD_MULTI_LINK : AP_MLD_SINGLE_LINK;
681 mld_ap_set(mld, ap_index, 1);
682 bss_idx++;
683 token = strtok(NULL, ";");
684 wifi_debug(DEBUG_ERROR, "mld[%ld] affiliated ap[%d].\n", mld_index, ap_index);
685 }
686 }
687
688 res = _syscmd_secure(buf, 4096,
689 "mwctl ra0 show bssmngr;dmesg | tail -500 | grep -e \"MLD\" -e \"bss_mngr_con_info_show\"");
690 if (res) {
691 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
692 free(buf);
693 return RETURN_ERR;
694 }
695
696 /*fulfill mld mac address from bssmngr information*/
697 mld_start = strstr(buf, "bss_mngr_con_info_show");
698 if (!mld_start) {
699 wifi_debug(DEBUG_ERROR, "fail to find string \"bss_mngr_con_info_show\"\n");
700 printf("*************************\n");
701 printf("buf:%s\n", buf);
702 printf("*************************\n");
703 free(buf);
704 return RETURN_ERR;
705 }
706 mld_start = strstr(mld_start, "MLD[");
707 if (!mld_start) {
708 printf("*************************\n");
709 printf("mld_start:%s\n", buf);
710 printf("*************************\n");
711 }
712 while (mld_start) {
713 if (hal_strtol(mld_start + 4, 10, &mld_index) < 0) {
714 wifi_debug(DEBUG_ERROR, "strtol fail\n");
715 free(buf);
716 return RETURN_ERR;
717 }
718
719 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
720 wifi_debug(DEBUG_ERROR, "invalid mld_index %ld\n", mld_index);
721 mld_start = strstr(mld_start + 4, "MLD[");
722 continue;
723 }
724
725 if (!mld_test(mld_index)) {
726 wifi_debug(DEBUG_ERROR, "mld(%ld) is not obvoiusly config in dat file, stll maintain it!",
727 mld_index);
728 mld_set(mld_index, 1);
729 }
730
731 mld = &(mld_config.mld[mld_index]);
732 mldaddr_start = strstr(mld_start, "MLD Addr:");
733 if (!mldaddr_start) {
734 wifi_debug(DEBUG_ERROR, "invalid mld address from bssmngr, mld_index=%ld\n", mld_index);
735 free(buf);
736 return RETURN_ERR;
737 }
738 mldaddr_end = strstr(mldaddr_start, ")");
739 if (!mldaddr_end) {
740 wifi_debug(DEBUG_ERROR, "invalid mld address from bssmngr, mld_index=%ld\n", mld_index);
741 free(buf);
742 return RETURN_ERR;
743 }
744
745 memset(mac_str, 0, sizeof(mac_str));
746 if ((mldaddr_end - mldaddr_start - 10) >= sizeof(mac_str)) {
747 wifi_debug(DEBUG_ERROR, "invalid mld address string from bssmngr, mld_index=%ld\n",
748 mld_index);
749 free(buf);
750 return RETURN_ERR;
751 }
752 strncpy(mac_str, mldaddr_start + 10, mldaddr_end - mldaddr_start - 10);
753 if (!hwaddr_aton2(mac_str, mld->mld_mac)) {
754 wifi_debug(DEBUG_ERROR, "invalid mld address from bssmngr, mld_index=%ld\n", mld_index);
755 free(buf);
756 return RETURN_ERR;
757 }
758
759 mld_start = strstr(mldaddr_end, "MLD[");
760 }
761 wifi_debug(DEBUG_ERROR, "<==========\n");
762
763 free(buf);
764 return RETURN_OK;
765}
766
767static unsigned char mld_ap_test_all_mlds(unsigned char ap_index)
768{
769 unsigned char mld_index;
770 struct multi_link_device *mld;
771
772 for (mld_index = 1; mld_index <= MAX_ML_MLD_CNT; mld_index++) {
773
774 if (!mld_test(mld_index))
775 continue;
776
777 mld = &(mld_config.mld[mld_index]);
778
779 if (mld_ap_test(mld, ap_index))
780 return mld_index;
781 }
782
783 return 0;
784}
785
786static void mld_info_display(void)
787{
788 unsigned char mld_index, ap_index;
789 struct multi_link_device *mld;
790 char interface_name[IF_NAME_SIZE] = {0};
791
792 wifi_debug(DEBUG_ERROR, "==========>\n");
793 for (mld_index = 1; mld_index <= MAX_ML_MLD_CNT; mld_index++) {
794 if (!mld_test(mld_index))
795 continue;
796
797 mld = &(mld_config.mld[mld_index]);
798
799 printf("MLD[%02d]: %02x:%02x:%02x:%02x:%02x:%02x\n\tAffiliated AP:\n", (int)(mld->mld_index),
800 mld->mld_mac[0], mld->mld_mac[1], mld->mld_mac[2],
801 mld->mld_mac[3], mld->mld_mac[4], mld->mld_mac[5]);
802
803 for (ap_index = 0; ap_index <= MAX_APS; ap_index++) {
804 if (!mld_ap_test(mld, ap_index))
805 continue;
806 if (wifi_GetInterfaceName(ap_index, interface_name) != RETURN_OK) {
807 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
808 continue;
809 }
810 printf("\tap[%d] %s\n", (int)ap_index, interface_name);
811 }
812 }
813 wifi_debug(DEBUG_ERROR, "<==========\n");
814}
815
816INT wifi_eht_create_ap_mld(unsigned char mld_index, unsigned char *mac)
817{
818 int res;
819// enum mld_type type;
820 struct multi_link_device *mld;
821
822// if (mld_index == 0 || mld_index > (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT)) {
823 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
824 wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", mld_index);
825 return RETURN_ERR;
826 }
827
828 if (mld_test(mld_index)) {
829 wifi_debug(DEBUG_ERROR, "mld already exist with mld_index %d\n", mld_index);
830 return RETURN_ERR;
831 }
832
833// type = mld_index <= MAX_ML_MLD_CNT ? AP_MLD_MULTI_LINK : AP_MLD_SINGLE_LINK;
834
835 res = v_secure_system("mwctl ra0 set apmld=create:group=%u,addr=%02x:%02x:%02x:%02x:%02x:%02x",
836 mld_index, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
837
838 if (res) {
839 wifi_debug(DEBUG_ERROR, "fail to create mld with mld_index %d\n", mld_index);
840 return RETURN_ERR;
841 }
842
843 mld_set(mld_index, 1);
844
845 mld = &(mld_config.mld[mld_index]);
846 mld->mld_index = mld_index;
847 memcpy(mld->mld_mac, mac, sizeof(mld->mld_mac));
848// mld->type = type;
849 memset(mld->affiliated_ap_bitmap, 0, sizeof(mld->affiliated_ap_bitmap));
850
851 return RETURN_OK;
852
853}
854
855INT wifi_eht_destroy_ap_mld(unsigned char mld_index)
856{
857 int res;
858 struct multi_link_device *mld;
859
860// if (mld_index == 0 || mld_index > (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT)) {
861 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
862 wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", mld_index);
863 return RETURN_ERR;
864 }
865
866 if (!mld_test(mld_index)) {
867 wifi_debug(DEBUG_ERROR, "mld does not exist with mld_index %d\n", mld_index);
868 return RETURN_ERR;
869 }
870
871 res = v_secure_system("mwctl ra0 set apmld=destroy:group=%u", mld_index);
872
873 if (res) {
874 wifi_debug(DEBUG_ERROR, "fail to destroy mld with mld_index %d\n", mld_index);
875 return RETURN_ERR;
876 }
877
878 mld_set(mld_index, 0);
879 mld = &(mld_config.mld[mld_index]);
880 memset(mld, 0, sizeof(*mld));
881
882 return RETURN_OK;
883}
884
885INT wifi_eht_list_ap_mld(unsigned char mld_index[], unsigned char *mld_num)
886{
887 unsigned char i, j = 0;
888
889// for (i = 1; i <= (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT); i++) {
890 for (i = 1; i <= MAX_ML_MLD_CNT; i++) {
891 if (mld_test(i))
892 mld_index[j++] = i;
893 }
894
895 *mld_num = j;
896
897 return RETURN_OK;
898}
899
900INT wifi_eht_add_to_ap_mld(unsigned char mld_index, INT ap_index)
901{
902 int res;
903// enum mld_type type;
904 struct multi_link_device *mld;
905 char interface_name[IF_NAME_SIZE] = {0};
906 unsigned char i;
907 int max_radio_num;
908
909 if (ap_index < 0 || ap_index >= MAX_APS) {
910 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
911 return RETURN_ERR;
912 }
913
914 if (wifi_GetInterfaceName(ap_index, interface_name) != RETURN_OK) {
915 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
916 return RETURN_ERR;
917 }
918
919// if (mld_index == 0 || mld_index > (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT)) {
920 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
921 wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", mld_index);
922 return RETURN_ERR;
923 }
924
925 if (!mld_test(mld_index)) {
926 wifi_debug(DEBUG_ERROR, "mld does not exist with mld_index %d\n", mld_index);
927 return RETURN_ERR;
928 }
929
930 mld = &(mld_config.mld[mld_index]);
931#if 0
932 if (mld->type == AP_MLD_SINGLE_LINK) {
933 /*check single link mld is not occupied by other ap*/
934 for (i = 0; i < MAX_APS; i++) {
935 if(mld_ap_test(mld, i))
936 break;
937 }
938
939 if (i < MAX_APS) {
940 if (i == ap_index) {
941 wifi_debug(DEBUG_ERROR, "current ap(%d) has already joined single link mld(%d)\n", i, mld_index);
942 return RETURN_OK;
943 }
944 wifi_debug(DEBUG_ERROR,
945 "single link mld(%d) already has an affiliated AP(ap_index %d)\n", mld_index, i);
946 return RETURN_ERR;
947 }
948 } else if (mld->type == AP_MLD_MULTI_LINK) {
949#endif
950 /*check if a same band ap already has been joined before*/
951 wifi_getMaxRadioNumber(&max_radio_num);
952 if(max_radio_num == 0){
953 return RETURN_ERR;
954 }
955 for (i = 0; i < MAX_APS; i++) {
956 if(mld_ap_test(mld, i)) {
957 if (i == ap_index) {
958 wifi_debug(DEBUG_ERROR, "current ap(index=%d) has already joined current mld\n", i);
959 return RETURN_OK;
960 }
961 if ((i % max_radio_num) == (ap_index % max_radio_num)) {
962 wifi_debug(DEBUG_ERROR, "same band ap(index=%d) has already joined current mld\n", i);
963 return RETURN_ERR;
964 }
965 }
966 }
967
968 res = v_secure_system("mwctl %s set apmld=addlink:group=%u", interface_name, mld_index);
969
970 if (res) {
971 wifi_debug(DEBUG_ERROR, "fail to add ap to ap mld with mld_index %d\n", mld_index);
972 return RETURN_ERR;
973 }
974
975 mld_ap_set(mld, ap_index, 1);
developer17038e62023-03-02 14:43:43 +0800976
developer6c6ef372023-11-08 10:59:14 +0800977 return RETURN_OK;
978}
979
980INT wifi_eht_remove_from_ap_mld(unsigned char mld_index, INT ap_index)
981{
982 int res;
983// enum mld_type type;
984 struct multi_link_device *mld;
985 char interface_name[IF_NAME_SIZE] = {0};
986
987 if (ap_index < 0 || ap_index >= MAX_APS) {
988 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
989 return RETURN_ERR;
990 }
991
992 if (wifi_GetInterfaceName(ap_index, interface_name) != RETURN_OK) {
993 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
994 return RETURN_ERR;
995 }
996
997// if (mld_index == 0 || mld_index > (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT)) {
998 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
999 wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", mld_index);
1000 return RETURN_ERR;
1001 }
1002
1003 if (!mld_test(mld_index)) {
1004 wifi_debug(DEBUG_ERROR, "mld does not exist with mld_index %d\n", mld_index);
1005 return RETURN_ERR;
1006 }
1007
1008 mld = &(mld_config.mld[mld_index]);
1009
1010 res = v_secure_system("mwctl %s apmld=dellink", interface_name);
1011
1012 if (res) {
1013 wifi_debug(DEBUG_ERROR, "fail to del ap from ap mld with mld_index %d\n", mld_index);
1014 return RETURN_ERR;
1015 }
1016
1017 mld_ap_set(mld, ap_index, 0);
1018
1019 return RETURN_OK;
1020}
1021
1022INT wifi_eht_get_ap_from_mld(unsigned char mld_index, unsigned char ap_index[], unsigned char *ap_num)
1023{
1024 unsigned char i, j = 0;
1025 struct multi_link_device *mld;
1026
1027// if (mld_index == 0 || mld_index > (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT)) {
1028 if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
1029 wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", mld_index);
1030 return RETURN_ERR;
1031 }
1032
1033 if (!mld_test(mld_index)) {
1034 wifi_debug(DEBUG_ERROR, "mld does not exist with mld_index %d\n", mld_index);
1035 return RETURN_ERR;
1036 }
1037
1038 mld = &(mld_config.mld[mld_index]);
1039
1040 for (i = 0; i < MAX_APS; i++) {
1041 if (mld_ap_test(mld, i))
1042 ap_index[j++] = i;
1043 }
1044
1045 *ap_num = j;
1046
1047 return RETURN_OK;
1048}
1049
1050INT wifi_eht_mld_ap_transfer(unsigned char old_mld_index,
1051 unsigned char new_mld_index, INT ap_index)
1052{
1053 int res;
1054// enum mld_type type;
1055 struct multi_link_device *mld, *old_mld;
1056 char interface_name[IF_NAME_SIZE] = {0};
1057 unsigned char i;
1058 int max_radio_num;
1059
1060 if (old_mld_index == new_mld_index) {
1061 wifi_debug(DEBUG_ERROR, "same mld index %d\n", new_mld_index);
1062 return RETURN_OK;
1063 }
1064
1065 if (ap_index < 0 || ap_index >= MAX_APS) {
1066 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
1067 return RETURN_ERR;
1068 }
1069
1070 if (wifi_GetInterfaceName(ap_index, interface_name) != RETURN_OK) {
1071 wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
1072 return RETURN_ERR;
1073 }
1074
1075 if (old_mld_index == 0 || old_mld_index > MAX_ML_MLD_CNT) {
1076 wifi_debug(DEBUG_ERROR, "invalid old_mld_index %d\n", old_mld_index);
1077 return RETURN_ERR;
1078 }
1079 old_mld = mld = &(mld_config.mld[new_mld_index]);
1080
1081 if (!mld_test(old_mld_index)) {
1082 wifi_debug(DEBUG_ERROR, "mld does not exist with old_mld_index %d\n", old_mld_index);
1083 return RETURN_ERR;
1084 }
1085
1086
1087// if (mld_index == 0 || mld_index > (MAX_ML_MLD_CNT + MAX_SL_MLD_CNT)) {
1088 if (new_mld_index == 0 || new_mld_index > MAX_ML_MLD_CNT) {
1089 wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", new_mld_index);
1090 return RETURN_ERR;
1091 }
1092
1093 if (!mld_test(new_mld_index)) {
1094 wifi_debug(DEBUG_ERROR, "mld does not exist with mld_index %d\n", new_mld_index);
1095 return RETURN_ERR;
1096 }
1097
1098 mld = &(mld_config.mld[new_mld_index]);
1099
1100 wifi_getMaxRadioNumber(&max_radio_num);
1101 if(max_radio_num == 0){
1102 return RETURN_ERR;
1103 }
1104 for (i = 0; i < MAX_APS; i++) {
1105 if(mld_ap_test(mld, i)) {
1106 if (i == ap_index) {
1107 wifi_debug(DEBUG_ERROR, "current ap has already joined current mld\n");
1108 return RETURN_OK;
1109 }
1110 if ((i % max_radio_num) == (ap_index % max_radio_num)) {
1111 wifi_debug(DEBUG_ERROR, "same band ap(index=%d) has already joined current mld\n", i);
1112 return RETURN_ERR;
1113 }
1114 }
1115 }
1116
1117 res = v_secure_system("mwctl %s set apmld=tsfrlink:group=%u", interface_name, new_mld_index);
1118
1119 if (res) {
1120 wifi_debug(DEBUG_ERROR, "fail to transfer ap to ap mld with mld_index %d\n", new_mld_index);
1121 return RETURN_ERR;
1122 }
1123
1124 mld_ap_set(old_mld, ap_index, 0);
1125 mld_ap_set(mld, ap_index, 1);
1126
1127 return RETURN_OK;
1128}
1129
1130INT wifi_eht_config_sync2_dat_by_radio(unsigned char band)
1131{
1132 unsigned char bss_idx, mld_index;
1133 char config_file_dat[128] = {0}, MldGroup_V_Str[128] = {0}, buf[64] = {0};
1134 int res, vap_index, len = 0, bssidnum;
1135 struct params MldGroup;
1136
1137 if (band >= MAX_NUM_RADIOS) {
1138 wifi_debug(DEBUG_ERROR, "invalid band %u\n", band);
1139 return RETURN_ERR;
1140 }
1141
1142 res = wifi_BandProfileRead(0, band, "BssidNum", buf, sizeof(buf), "0");
1143 if (res != 0) {
1144 wifi_debug(DEBUG_ERROR, "wifi_BandProfileRead BssidNum failed\n");
1145 return RETURN_ERR;
1146 }
1147
1148 bssidnum = atoi(buf);
1149 if (bssidnum <= 0) {
1150 wifi_debug(DEBUG_ERROR, "invalid BssidNum %s\n", buf);
1151 return RETURN_ERR;
1152 }
1153 if (bssidnum > LOGAN_MAX_NUM_VAP_PER_RADIO) {
1154 wifi_debug(DEBUG_ERROR, "bss_num is larger than %d\n", LOGAN_MAX_NUM_VAP_PER_RADIO);
1155 return RETURN_ERR;
1156 }
1157
1158 res = snprintf(config_file_dat, sizeof(config_file_dat), "%s%d.dat", LOGAN_DAT_FILE, band);
1159 if (os_snprintf_error(sizeof(config_file_dat), res)) {
1160 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1161 return RETURN_ERR;
1162 }
1163
1164 for (bss_idx = 0; bss_idx < bssidnum; bss_idx++) {
1165 vap_index = array_index_to_vap_index(band, bss_idx);
1166 if (vap_index == RETURN_ERR) {
1167 wifi_debug(DEBUG_ERROR, "invalide vap index, band=%d, bss_idx=%d\n", (int)band, (int)bss_idx);
1168 break;
1169 }
1170 mld_index = mld_ap_test_all_mlds(vap_index);
1171 res = snprintf(&(MldGroup_V_Str[len]), sizeof(MldGroup_V_Str) - len, "%u;", mld_index);
1172 if (os_snprintf_error(sizeof(MldGroup_V_Str) - len, res)) {
1173 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1174 break;
1175 }
1176 len += res;
1177 }
1178
1179 MldGroup.name = "MldGroup";
1180 MldGroup.value = MldGroup_V_Str;
1181 wifi_datfileWrite(config_file_dat, &MldGroup, 1);
1182 wifi_debug(DEBUG_ERROR, "band[%u] MldGroup=%s\n", band, MldGroup_V_Str);
1183
1184 return RETURN_OK;
1185}
1186
1187void wifi_eht_config_sync2_dat(void)
1188{
1189 unsigned char band;
1190
1191 for (band = 0; band < MAX_NUM_RADIOS; band++) {
1192 wifi_eht_config_sync2_dat_by_radio(band);
1193 }
1194}
1195
1196#endif
developer96b38512023-02-22 11:17:45 +08001197
1198static int
1199get_value(const char *conf_file, const char *param, char *value, int len)
1200{
developera3511852023-06-14 14:12:59 +08001201 FILE *fp;
1202 int ret = -1;
1203 int param_len = strlen(param);
1204 int buf_len;
developer86035662023-06-28 19:21:12 +08001205 char buf[256] = {0};
developer96b38512023-02-22 11:17:45 +08001206
developera3511852023-06-14 14:12:59 +08001207 fp = fopen(conf_file, "r");
1208 if (!fp) {
1209 return -1;
1210 }
developer96b38512023-02-22 11:17:45 +08001211
developera3511852023-06-14 14:12:59 +08001212 while (fgets(buf, sizeof(buf), fp)) {
1213 buf_len = strlen(buf);
developer86035662023-06-28 19:21:12 +08001214 if (buf_len == 0) {
1215 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developerc14d83a2023-06-29 20:09:42 +08001216 if (fclose(fp) != 0) {
1217 wifi_debug(DEBUG_ERROR, "fclose fail\n");
1218 }
developer86035662023-06-28 19:21:12 +08001219 return RETURN_ERR;
1220 }
developera3511852023-06-14 14:12:59 +08001221 if (buf[buf_len - 1] == '\n') {
1222 buf_len--;
1223 buf[buf_len] = '\0';
1224 }
1225 if ((buf_len > param_len) &&
1226 (strncmp(buf, param, param_len) == 0) &&
1227 (buf[param_len] == '=')) {
developer96b38512023-02-22 11:17:45 +08001228
developera3511852023-06-14 14:12:59 +08001229 if (buf_len == (param_len + 1)) {
1230 value[0] = '\0';
1231 ret = 0;
1232 } else {
1233 ret = snprintf(value, len, "%s", buf + (param_len + 1));
developer75bd10c2023-06-27 11:34:08 +08001234 if (os_snprintf_error(len, ret)) {
1235 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1236 }
developera3511852023-06-14 14:12:59 +08001237 }
developerd14dff12023-06-28 22:47:44 +08001238 if (fclose(fp) != 0) {
1239 ret = -1;
1240 wifi_debug(DEBUG_ERROR, "fclose fail\n");
1241 }
developera3511852023-06-14 14:12:59 +08001242 return ret;
1243 }
1244 }
developer37646972023-06-29 10:58:43 +08001245 if (fclose(fp) == EOF){
1246 wifi_debug(DEBUG_ERROR, "fclose fail\n");
1247 return RETURN_ERR;
1248 }
developera3511852023-06-14 14:12:59 +08001249 return -1;
developer96b38512023-02-22 11:17:45 +08001250}
1251
1252static int
1253get_value_by_idx(const char *conf_file, const char *param, int idx, char *value, int len)
1254{
developera3511852023-06-14 14:12:59 +08001255 char buf[256];
1256 int ret;
1257 char *save_ptr = NULL;
1258 char *tok = NULL;
developer96b38512023-02-22 11:17:45 +08001259
developera3511852023-06-14 14:12:59 +08001260 ret = get_value(conf_file, param, buf, sizeof(buf));
1261 if (ret < 0)
1262 return ret;
developer96b38512023-02-22 11:17:45 +08001263
developera3511852023-06-14 14:12:59 +08001264 tok = strtok_r(buf, ";", &save_ptr);
1265 do {
1266 if (idx == 0 || tok == NULL)
1267 break;
1268 else
1269 idx--;
developer96b38512023-02-22 11:17:45 +08001270
developera3511852023-06-14 14:12:59 +08001271 tok = strtok_r(NULL, ";", &save_ptr);
1272 } while (tok != NULL);
developer96b38512023-02-22 11:17:45 +08001273
developera3511852023-06-14 14:12:59 +08001274 if (tok) {
1275 ret = snprintf(value, len, "%s", tok);
developer75bd10c2023-06-27 11:34:08 +08001276 if (os_snprintf_error(len, ret)) {
1277 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1278 return -1;
1279 }
developera3511852023-06-14 14:12:59 +08001280 } else {
1281 ret = 0;
1282 value[0] = '\0';
1283 }
developer96b38512023-02-22 11:17:45 +08001284
developera3511852023-06-14 14:12:59 +08001285 return ret;
developer96b38512023-02-22 11:17:45 +08001286}
1287
1288
developer72fb0bb2023-01-11 09:46:29 +08001289#ifdef HAL_NETLINK_IMPL
1290typedef struct {
developera3511852023-06-14 14:12:59 +08001291 int id;
1292 struct nl_sock* socket;
1293 struct nl_cb* cb;
developer72fb0bb2023-01-11 09:46:29 +08001294} Netlink;
1295
1296static int mac_addr_aton(unsigned char *mac_addr, char *arg)
1297{
developera3511852023-06-14 14:12:59 +08001298 unsigned char mac_addr_int[6]={};
developer75bd10c2023-06-27 11:34:08 +08001299 unsigned int recv;
1300
1301 recv = sscanf(arg, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", mac_addr_int+0, mac_addr_int+1, mac_addr_int+2, mac_addr_int+3, mac_addr_int+4, mac_addr_int+5);
1302
1303 if (recv != 6) {
1304 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
1305 return -1;
1306 }
developera3511852023-06-14 14:12:59 +08001307 mac_addr[0] = mac_addr_int[0];
1308 mac_addr[1] = mac_addr_int[1];
1309 mac_addr[2] = mac_addr_int[2];
1310 mac_addr[3] = mac_addr_int[3];
1311 mac_addr[4] = mac_addr_int[4];
1312 mac_addr[5] = mac_addr_int[5];
1313 return 0;
developer72fb0bb2023-01-11 09:46:29 +08001314}
1315
1316static void mac_addr_ntoa(char *mac_addr, unsigned char *arg)
1317{
developera3511852023-06-14 14:12:59 +08001318 unsigned int mac_addr_int[6]={};
developere40952c2023-06-15 18:46:43 +08001319 int res;
1320
developera3511852023-06-14 14:12:59 +08001321 mac_addr_int[0] = arg[0];
1322 mac_addr_int[1] = arg[1];
1323 mac_addr_int[2] = arg[2];
1324 mac_addr_int[3] = arg[3];
1325 mac_addr_int[4] = arg[4];
1326 mac_addr_int[5] = arg[5];
developere40952c2023-06-15 18:46:43 +08001327 res = snprintf(mac_addr, 20, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", mac_addr_int[0], mac_addr_int[1],mac_addr_int[2],mac_addr_int[3],mac_addr_int[4],mac_addr_int[5]);
1328 if (os_snprintf_error(20, res)) {
1329 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1330 }
developera3511852023-06-14 14:12:59 +08001331 return;
developer72fb0bb2023-01-11 09:46:29 +08001332}
1333
1334static int ieee80211_frequency_to_channel(int freq)
1335{
developera3511852023-06-14 14:12:59 +08001336 /* see 802.11-2007 17.3.8.3.2 and Annex J */
1337 if (freq == 2484)
1338 return 14;
1339 /* see 802.11ax D6.1 27.3.23.2 and Annex E */
1340 else if (freq == 5935)
1341 return 2;
1342 else if (freq < 2484)
1343 return (freq - 2407) / 5;
1344 else if (freq >= 4910 && freq <= 4980)
1345 return (freq - 4000) / 5;
1346 else if (freq < 5950)
1347 return (freq - 5000) / 5;
1348 else if (freq <= 45000) /* DMG band lower limit */
1349 /* see 802.11ax D6.1 27.3.23.2 */
1350 return (freq - 5950) / 5;
1351 else if (freq >= 58320 && freq <= 70200)
1352 return (freq - 56160) / 2160;
1353 else
1354 return 0;
developer72fb0bb2023-01-11 09:46:29 +08001355}
1356
1357static int initSock80211(Netlink* nl) {
developera3511852023-06-14 14:12:59 +08001358 nl->socket = nl_socket_alloc();
1359 if (!nl->socket) {
developer75bd10c2023-06-27 11:34:08 +08001360 wifi_debug(DEBUG_ERROR, "Failing to allocate the sock\n");
developera3511852023-06-14 14:12:59 +08001361 return -ENOMEM;
1362 }
developer72fb0bb2023-01-11 09:46:29 +08001363
developera3511852023-06-14 14:12:59 +08001364 nl_socket_set_buffer_size(nl->socket, 8192, 8192);
developer72fb0bb2023-01-11 09:46:29 +08001365
developera3511852023-06-14 14:12:59 +08001366 if (genl_connect(nl->socket)) {
developer75bd10c2023-06-27 11:34:08 +08001367 wifi_debug(DEBUG_ERROR, "Failed to connect\n");
developera3511852023-06-14 14:12:59 +08001368 nl_close(nl->socket);
1369 nl_socket_free(nl->socket);
1370 return -ENOLINK;
1371 }
developer72fb0bb2023-01-11 09:46:29 +08001372
developera3511852023-06-14 14:12:59 +08001373 nl->id = genl_ctrl_resolve(nl->socket, "nl80211");
1374 if (nl->id< 0) {
developer75bd10c2023-06-27 11:34:08 +08001375 wifi_debug(DEBUG_ERROR, "interface not found.\n");
developera3511852023-06-14 14:12:59 +08001376 nl_close(nl->socket);
1377 nl_socket_free(nl->socket);
1378 return -ENOENT;
1379 }
developer72fb0bb2023-01-11 09:46:29 +08001380
developera3511852023-06-14 14:12:59 +08001381 nl->cb = nl_cb_alloc(NL_CB_DEFAULT);
1382 if ((!nl->cb)) {
developer75bd10c2023-06-27 11:34:08 +08001383 wifi_debug(DEBUG_ERROR, "Failed to allocate netlink callback.\n");
developera3511852023-06-14 14:12:59 +08001384 nl_close(nl->socket);
1385 nl_socket_free(nl->socket);
1386 return ENOMEM;
1387 }
developer72fb0bb2023-01-11 09:46:29 +08001388
developera3511852023-06-14 14:12:59 +08001389 return nl->id;
developer72fb0bb2023-01-11 09:46:29 +08001390}
1391
1392static int nlfree(Netlink *nl)
1393{
developera3511852023-06-14 14:12:59 +08001394 nl_cb_put(nl->cb);
1395 nl_close(nl->socket);
1396 nl_socket_free(nl->socket);
1397 return 0;
developer72fb0bb2023-01-11 09:46:29 +08001398}
1399
1400static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
developera3511852023-06-14 14:12:59 +08001401 [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED },
1402 [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED },
1403 [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }
developer72fb0bb2023-01-11 09:46:29 +08001404};
1405
1406static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1407};
1408
1409static struct nla_policy tid_policy[NL80211_TID_STATS_MAX + 1] = {
1410};
1411
1412typedef struct _wifi_channelStats_loc {
developera3511852023-06-14 14:12:59 +08001413 INT array_size;
1414 INT ch_number;
1415 BOOL ch_in_pool;
1416 INT ch_noise;
1417 BOOL ch_radar_noise;
1418 INT ch_max_80211_rssi;
1419 INT ch_non_80211_noise;
1420 INT ch_utilization;
1421 ULLONG ch_utilization_total;
1422 ULLONG ch_utilization_busy;
1423 ULLONG ch_utilization_busy_tx;
1424 ULLONG ch_utilization_busy_rx;
1425 ULLONG ch_utilization_busy_self;
1426 ULLONG ch_utilization_busy_ext;
developer72fb0bb2023-01-11 09:46:29 +08001427} wifi_channelStats_t_loc;
1428
1429typedef struct wifi_device_info {
developera3511852023-06-14 14:12:59 +08001430 INT wifi_devIndex;
1431 UCHAR wifi_devMacAddress[6];
1432 CHAR wifi_devIPAddress[64];
1433 BOOL wifi_devAssociatedDeviceAuthentiationState;
1434 INT wifi_devSignalStrength;
1435 INT wifi_devTxRate;
1436 INT wifi_devRxRate;
developer72fb0bb2023-01-11 09:46:29 +08001437} wifi_device_info_t;
1438
1439#endif
1440
1441//For 5g Alias Interfaces
developer72fb0bb2023-01-11 09:46:29 +08001442static BOOL Radio_flag = TRUE;
1443//wifi_setApBeaconRate(1, beaconRate);
1444
1445BOOL multiple_set = FALSE;
1446
developer8078acf2023-08-04 18:52:48 +08001447/*static int _syscmd(char *cmd, char *retBuf, int retBufSize)
developer72fb0bb2023-01-11 09:46:29 +08001448{
developera3511852023-06-14 14:12:59 +08001449 FILE *f;
1450 char *ptr = retBuf;
1451 int bufSize=retBufSize, bufbytes=0, readbytes=0, cmd_ret=0;
developer72fb0bb2023-01-11 09:46:29 +08001452
developera3511852023-06-14 14:12:59 +08001453 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1454 if((f = popen(cmd, "r")) == NULL) {
developer75bd10c2023-06-27 11:34:08 +08001455 wifi_debug(DEBUG_ERROR, "\npopen %s error\n", cmd);
developera3511852023-06-14 14:12:59 +08001456 return RETURN_ERR;
1457 }
developer72fb0bb2023-01-11 09:46:29 +08001458
developera3511852023-06-14 14:12:59 +08001459 while(!feof(f))
1460 {
1461 *ptr = 0;
1462 if(bufSize>=128) {
1463 bufbytes=128;
1464 } else {
1465 bufbytes=bufSize-1;
1466 }
developer72fb0bb2023-01-11 09:46:29 +08001467
developerd14dff12023-06-28 22:47:44 +08001468 if (fgets(ptr,bufbytes,f) == NULL)
1469 break;
developera3511852023-06-14 14:12:59 +08001470 readbytes=strlen(ptr);
developer72fb0bb2023-01-11 09:46:29 +08001471
developera3511852023-06-14 14:12:59 +08001472 if(!readbytes)
1473 break;
developer72fb0bb2023-01-11 09:46:29 +08001474
developera3511852023-06-14 14:12:59 +08001475 bufSize-=readbytes;
1476 ptr += readbytes;
1477 }
1478 cmd_ret = pclose(f);
1479 retBuf[retBufSize-1]=0;
1480 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001481
developera3511852023-06-14 14:12:59 +08001482 return cmd_ret >> 8;
developer72fb0bb2023-01-11 09:46:29 +08001483}
developer8078acf2023-08-04 18:52:48 +08001484*/
developer72fb0bb2023-01-11 09:46:29 +08001485
1486INT radio_index_to_phy(int radioIndex)
1487{
developera3511852023-06-14 14:12:59 +08001488 /* TODO */
1489 return radioIndex;
developer72fb0bb2023-01-11 09:46:29 +08001490}
1491
1492INT wifi_getMaxRadioNumber(INT *max_radio_num)
1493{
developera3511852023-06-14 14:12:59 +08001494 char buf[4] = {0};
developere40952c2023-06-15 18:46:43 +08001495 int res;
developerc14d83a2023-06-29 20:09:42 +08001496 unsigned long tmp;
developera3511852023-06-14 14:12:59 +08001497 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001498
developer33f13ba2023-07-12 16:19:06 +08001499 res = _syscmd_secure(buf, sizeof(buf), "iw list | grep Wiphy | wc -l | tr -d '\\n'");
1500 if (res) {
1501 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08001502 }
developerc14d83a2023-06-29 20:09:42 +08001503 if (hal_strtoul(buf, 10, &tmp) < 0) {
1504 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08001505 }
developerc14d83a2023-06-29 20:09:42 +08001506 res = tmp;
developerd14dff12023-06-28 22:47:44 +08001507
1508 *max_radio_num = res > MAX_NUM_RADIOS ? MAX_NUM_RADIOS:res;
developer72fb0bb2023-01-11 09:46:29 +08001509
developera3511852023-06-14 14:12:59 +08001510 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001511
developera3511852023-06-14 14:12:59 +08001512 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08001513}
1514
developer17038e62023-03-02 14:43:43 +08001515wifi_band radio_index_to_band(int radioIndex)
1516{
developera3511852023-06-14 14:12:59 +08001517 return radio_band[radioIndex];
developer17038e62023-03-02 14:43:43 +08001518}
1519
developer72fb0bb2023-01-11 09:46:29 +08001520wifi_band wifi_index_to_band(int apIndex)
1521{
developera3511852023-06-14 14:12:59 +08001522 char buf[64] = {0};
developerc14d83a2023-06-29 20:09:42 +08001523 long int nl80211_band = 0;
developera3511852023-06-14 14:12:59 +08001524 int i = 0;
1525 int phyIndex = 0;
1526 int radioIndex = 0;
1527 int max_radio_num = 0;
1528 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08001529 int res;
developera3511852023-06-14 14:12:59 +08001530 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001531
developera3511852023-06-14 14:12:59 +08001532 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +08001533 if(max_radio_num == 0){
1534 return RETURN_ERR;
1535 }
developera3511852023-06-14 14:12:59 +08001536 radioIndex = apIndex % max_radio_num;
1537 phyIndex = radio_index_to_phy(radioIndex);
developer33f13ba2023-07-12 16:19:06 +08001538 while (i < 10) {
1539 res = _syscmd_secure(buf, sizeof(buf),
1540 "iw phy%d info | grep 'Band .:' | tail -n 1 | tr -d ':\\n' | awk '{print $2}'", phyIndex);
1541
1542 if (res) {
1543 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08001544 }
developer33f13ba2023-07-12 16:19:06 +08001545
developerc14d83a2023-06-29 20:09:42 +08001546 if (hal_strtol(buf, 16, &nl80211_band) < 0) {
1547 wifi_debug(DEBUG_ERROR, "strtol fail\n");
1548 }
developera3511852023-06-14 14:12:59 +08001549 if (nl80211_band == 1)
1550 band = band_2_4;
1551 else if (nl80211_band == 2)
1552 band = band_5;
1553 else if (nl80211_band == 4) // band == 3 is 60GHz
1554 band = band_6;
developer72fb0bb2023-01-11 09:46:29 +08001555
developera3511852023-06-14 14:12:59 +08001556 if(band != band_invalid)
1557 break;
developer69b61b02023-03-07 17:17:44 +08001558
developera3511852023-06-14 14:12:59 +08001559 i++;
1560 sleep(1);
1561 }
developer72fb0bb2023-01-11 09:46:29 +08001562
developera3511852023-06-14 14:12:59 +08001563 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
1564 return band;
developer72fb0bb2023-01-11 09:46:29 +08001565}
1566
1567static int wifi_hostapdRead(char *conf_file, char *param, char *output, int output_size)
1568{
developer8078acf2023-08-04 18:52:48 +08001569
developer7e4a2a62023-04-06 19:56:03 +08001570 char buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08001571 int res = 0;
developer72fb0bb2023-01-11 09:46:29 +08001572
developer72fb0bb2023-01-11 09:46:29 +08001573
developer8078acf2023-08-04 18:52:48 +08001574 res = _syscmd_secure(buf, sizeof(buf), "cat %s 2> /dev/null | grep \"^%s=\" | cut -d \"=\" -f 2 | head -n1 | tr -d \"\\n\"",conf_file, param);
1575 if (res) {
1576 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer7e4a2a62023-04-06 19:56:03 +08001577 }
developerb758dfd2023-06-21 17:32:07 +08001578
developer7e4a2a62023-04-06 19:56:03 +08001579
developere40952c2023-06-15 18:46:43 +08001580 res = snprintf(output, output_size, "%s", buf);
1581 if (os_snprintf_error(output_size, res)) {
1582 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1583 return RETURN_ERR;
1584 }
developer7e4a2a62023-04-06 19:56:03 +08001585
1586 return 0;
developer72fb0bb2023-01-11 09:46:29 +08001587}
1588
1589static int wifi_hostapdWrite(char *conf_file, struct params *list, int item_count)
1590{
developer8078acf2023-08-04 18:52:48 +08001591
developera3511852023-06-14 14:12:59 +08001592 char buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08001593 int res;
developer72fb0bb2023-01-11 09:46:29 +08001594
developera3511852023-06-14 14:12:59 +08001595 for (int i = 0; i < item_count; i++) {
1596 wifi_hostapdRead(conf_file, list[i].name, buf, sizeof(buf));
1597 if (strlen(buf) == 0) /*no such item, insert it*/
developer8078acf2023-08-04 18:52:48 +08001598 res = _syscmd_secure(buf, sizeof(buf), "sed -i -e '$a %s=%s' %s", list[i].name, list[i].value, conf_file);
developera3511852023-06-14 14:12:59 +08001599 else /*find the item, update it*/
developer8078acf2023-08-04 18:52:48 +08001600 res = _syscmd_secure(buf, sizeof(buf), "sed -i \"s/^%s=.*/%s=%s/\" %s", list[i].name, list[i].name, list[i].value, conf_file);
developera1255e42023-05-13 17:45:02 +08001601
developer8078acf2023-08-04 18:52:48 +08001602 if(res) {
1603 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08001604 }
developera3511852023-06-14 14:12:59 +08001605 }
developer72fb0bb2023-01-11 09:46:29 +08001606
developera3511852023-06-14 14:12:59 +08001607 return 0;
developera1255e42023-05-13 17:45:02 +08001608}
developerfde01262023-05-22 15:15:24 +08001609
developera1255e42023-05-13 17:45:02 +08001610static int wifi_datfileRead(char *conf_file, char *param, char *output, int output_size)
1611{
developere40952c2023-06-15 18:46:43 +08001612 int res = 0;
developera3511852023-06-14 14:12:59 +08001613 int len;
developerfde01262023-05-22 15:15:24 +08001614
developer8078acf2023-08-04 18:52:48 +08001615 res = _syscmd_secure(output, output_size, "datconf -f %s get %s", conf_file, param);
developere40952c2023-06-15 18:46:43 +08001616
developer8078acf2023-08-04 18:52:48 +08001617 if (res) {
1618 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developera3511852023-06-14 14:12:59 +08001619 }
developera1255e42023-05-13 17:45:02 +08001620
developer8078acf2023-08-04 18:52:48 +08001621
developera3511852023-06-14 14:12:59 +08001622 len = strlen(output);
1623 if ((len > 0) && (output[len - 1] == '\n')) {
1624 output[len - 1] = '\0';
1625 }
developerfde01262023-05-22 15:15:24 +08001626
developera3511852023-06-14 14:12:59 +08001627 return 0;
developerfde01262023-05-22 15:15:24 +08001628}
developera1255e42023-05-13 17:45:02 +08001629
developera1255e42023-05-13 17:45:02 +08001630static int wifi_datfileWrite(char *conf_file, struct params *list, int item_count)
1631{
developere40952c2023-06-15 18:46:43 +08001632 int res;
developera3511852023-06-14 14:12:59 +08001633 char buf[MAX_BUF_SIZE] = {0};
developera1255e42023-05-13 17:45:02 +08001634
developera3511852023-06-14 14:12:59 +08001635 for (int i = 0; i < item_count; i++) {
developer8078acf2023-08-04 18:52:48 +08001636 res = _syscmd_secure(buf, sizeof(buf), "datconf -f %s set %s \"%s\"", conf_file, list[i].name, list[i].value);
developera1255e42023-05-13 17:45:02 +08001637
developer8078acf2023-08-04 18:52:48 +08001638 if (res) {
1639 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
1640 }
developera3511852023-06-14 14:12:59 +08001641 }
developera1255e42023-05-13 17:45:02 +08001642
developera3511852023-06-14 14:12:59 +08001643 return 0;
developera1255e42023-05-13 17:45:02 +08001644}
1645
developerfde01262023-05-22 15:15:24 +08001646static int wifi_l1ProfileRead(char *param, char *output, int output_size)
1647{
developera3511852023-06-14 14:12:59 +08001648 int ret;
developerfde01262023-05-22 15:15:24 +08001649
developera3511852023-06-14 14:12:59 +08001650 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1651 if (!param || !output || (output_size <= 0)) {
developer75bd10c2023-06-27 11:34:08 +08001652 wifi_debug(DEBUG_ERROR, "invalid parameters");
developera3511852023-06-14 14:12:59 +08001653 return RETURN_ERR;
1654 }
developerfde01262023-05-22 15:15:24 +08001655
developera3511852023-06-14 14:12:59 +08001656 ret = wifi_datfileRead(l1profile, param, output, output_size);
1657 if (ret != 0) {
developer75bd10c2023-06-27 11:34:08 +08001658 wifi_debug(DEBUG_ERROR, "wifi_datfileRead %s from %s failed, ret:%d", param, l1profile, ret);
developera3511852023-06-14 14:12:59 +08001659 return RETURN_ERR;
1660 }
developerfde01262023-05-22 15:15:24 +08001661
developera3511852023-06-14 14:12:59 +08001662 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
1663 return RETURN_OK;
developerfde01262023-05-22 15:15:24 +08001664}
1665
1666static int wifi_CardProfileRead(int card_idx, char *param, char *output, int output_size)
1667{
developera3511852023-06-14 14:12:59 +08001668 char option[64];
1669 char card_profile_path[64];
developere40952c2023-06-15 18:46:43 +08001670 int res;
developerfde01262023-05-22 15:15:24 +08001671
developera3511852023-06-14 14:12:59 +08001672 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developerfde01262023-05-22 15:15:24 +08001673
developera3511852023-06-14 14:12:59 +08001674 if (!param || !output || (output_size <= 0)) {
developer75bd10c2023-06-27 11:34:08 +08001675 wifi_debug(DEBUG_ERROR, "invalid parameters");
developera3511852023-06-14 14:12:59 +08001676 return RETURN_ERR;
1677 }
developerfde01262023-05-22 15:15:24 +08001678
developere40952c2023-06-15 18:46:43 +08001679 res = snprintf(option, sizeof(option), "INDEX%d_profile_path", card_idx);
1680 if (os_snprintf_error(sizeof(option), res)) {
1681 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developera3511852023-06-14 14:12:59 +08001682 return RETURN_ERR;
1683 }
developere40952c2023-06-15 18:46:43 +08001684 res = wifi_l1ProfileRead(option, card_profile_path, sizeof(card_profile_path));
1685 if (res != 0) {
developer75bd10c2023-06-27 11:34:08 +08001686 wifi_debug(DEBUG_ERROR, "wifi_l1ProfileRead %s failed, ret:%d", option, res);
developere40952c2023-06-15 18:46:43 +08001687 return RETURN_ERR;
1688 }
developerfde01262023-05-22 15:15:24 +08001689
developere40952c2023-06-15 18:46:43 +08001690 res = wifi_datfileRead(card_profile_path, param, output, output_size);
1691 if (res != 0) {
developer75bd10c2023-06-27 11:34:08 +08001692 wifi_debug(DEBUG_ERROR, "wifi_datfileRead %s from %s failed, ret:%d", param, card_profile_path, res);
developera3511852023-06-14 14:12:59 +08001693 return RETURN_ERR;
1694 }
developerfde01262023-05-22 15:15:24 +08001695
developera3511852023-06-14 14:12:59 +08001696 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
1697 return RETURN_OK;
developerfde01262023-05-22 15:15:24 +08001698}
1699
1700static int wifi_BandProfileRead(int card_idx,
developera3511852023-06-14 14:12:59 +08001701 int radio_idx,
1702 char *param,
1703 char *output,
1704 int output_size,
1705 char *default_value)
developerfde01262023-05-22 15:15:24 +08001706{
developera3511852023-06-14 14:12:59 +08001707 char option[64];
1708 char band_profile_path[64];
developere40952c2023-06-15 18:46:43 +08001709 int ret, res;
developerfde01262023-05-22 15:15:24 +08001710
developera3511852023-06-14 14:12:59 +08001711 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1712 if (!param || !output || (output_size <= 0)) {
developer75bd10c2023-06-27 11:34:08 +08001713 wifi_debug(DEBUG_ERROR, "invalid parameters");
developera3511852023-06-14 14:12:59 +08001714 return RETURN_ERR;
1715 }
developerfde01262023-05-22 15:15:24 +08001716
developere40952c2023-06-15 18:46:43 +08001717 res = snprintf(option, sizeof(option), "BN%d_profile_path", radio_idx);
1718 if (os_snprintf_error(sizeof(option), res)) {
1719 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1720 return RETURN_ERR;
1721 }
developera3511852023-06-14 14:12:59 +08001722 ret = wifi_CardProfileRead(card_idx, option, band_profile_path, sizeof(band_profile_path));
1723 if (ret != 0) {
developer75bd10c2023-06-27 11:34:08 +08001724 wifi_debug(DEBUG_ERROR, "wifi_CardProfileRead %s failed, ret:%d", option, ret);
developera3511852023-06-14 14:12:59 +08001725 return RETURN_ERR;
1726 }
developerfde01262023-05-22 15:15:24 +08001727
developera3511852023-06-14 14:12:59 +08001728 ret = wifi_datfileRead(band_profile_path, param, output, output_size);
1729 if (ret != 0) {
1730 if (default_value) {
developere40952c2023-06-15 18:46:43 +08001731 res = snprintf(output, output_size, "%s", default_value);
1732 if (os_snprintf_error(output_size, res)) {
1733 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1734 return RETURN_ERR;
1735 }
developera3511852023-06-14 14:12:59 +08001736 } else {
1737 output[0] = '\0';
1738 }
1739 }
developerfde01262023-05-22 15:15:24 +08001740
developera3511852023-06-14 14:12:59 +08001741 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
1742 return RETURN_OK;
developerfde01262023-05-22 15:15:24 +08001743}
1744
developer72fb0bb2023-01-11 09:46:29 +08001745//For Getting Current Interface Name from corresponding hostapd configuration
1746static int wifi_GetInterfaceName(int apIndex, char *interface_name)
1747{
developera3511852023-06-14 14:12:59 +08001748 char config_file[128] = {0};
developere40952c2023-06-15 18:46:43 +08001749 int res;
developer72fb0bb2023-01-11 09:46:29 +08001750
developera3511852023-06-14 14:12:59 +08001751 if (interface_name == NULL)
1752 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08001753
developera3511852023-06-14 14:12:59 +08001754 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001755
developere40952c2023-06-15 18:46:43 +08001756 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
1757 if (os_snprintf_error(sizeof(config_file), res)) {
1758 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1759 return RETURN_ERR;
1760 }
developera3511852023-06-14 14:12:59 +08001761 wifi_hostapdRead(config_file, "interface", interface_name, 16);
1762 if (strlen(interface_name) == 0)
1763 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08001764
developera3511852023-06-14 14:12:59 +08001765 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
1766 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08001767}
1768
developera1255e42023-05-13 17:45:02 +08001769static UCHAR get_bssnum_byindex(INT radio_index, UCHAR *bss_cnt)
1770{
developera3511852023-06-14 14:12:59 +08001771 char interface_name[IF_NAME_SIZE] = {0};
developera3511852023-06-14 14:12:59 +08001772 char buf[MAX_CMD_SIZE]={'\0'};
1773 UCHAR channel = 0;
developere40952c2023-06-15 18:46:43 +08001774 int res;
developera1255e42023-05-13 17:45:02 +08001775
developera3511852023-06-14 14:12:59 +08001776 if (wifi_GetInterfaceName(radio_index, interface_name) != RETURN_OK)
1777 return RETURN_ERR;
1778 /*interface name to channel number*/
developer8078acf2023-08-04 18:52:48 +08001779 res = _syscmd_secure(buf, sizeof(buf), "iw dev %s info | grep -i 'channel' | cut -d ' ' -f2", interface_name);
1780
1781 if (res) {
1782 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08001783 }
1784
developera3511852023-06-14 14:12:59 +08001785 channel = atoi(buf);
1786 WIFI_ENTRY_EXIT_DEBUG("%s:channel=%d\n", __func__, channel);
developera1255e42023-05-13 17:45:02 +08001787 /*count dev number with the same channel*/
developer8078acf2023-08-04 18:52:48 +08001788 res = _syscmd_secure(buf, sizeof(buf), "iw dev | grep -i 'channel %d' | wc -l", channel);
1789
1790 if (res) {
1791 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08001792 }
1793
developera3511852023-06-14 14:12:59 +08001794 *bss_cnt = atoi(buf) - 1;/*1 for apcli interface*/
1795 WIFI_ENTRY_EXIT_DEBUG("%s:bss_cnt=%d\n", __func__, *bss_cnt);
1796 return RETURN_OK;
developera1255e42023-05-13 17:45:02 +08001797}
developer72fb0bb2023-01-11 09:46:29 +08001798
1799static int wifi_hostapdProcessUpdate(int apIndex, struct params *list, int item_count)
1800{
developera3511852023-06-14 14:12:59 +08001801 char interface_name[16] = {0};
1802 if (multiple_set == TRUE)
1803 return RETURN_OK;
developer8078acf2023-08-04 18:52:48 +08001804 char output[32]="";
developera3511852023-06-14 14:12:59 +08001805 FILE *fp;
developer8078acf2023-08-04 18:52:48 +08001806 int i;
developera3511852023-06-14 14:12:59 +08001807 //NOTE RELOAD should be done in ApplySSIDSettings
1808 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
1809 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08001810
1811 for (i=0; i<item_count; i++, list++) {
developer8078acf2023-08-04 18:52:48 +08001812 fp = v_secure_popen("r", "hostapd_cli -i%s SET %s %s", interface_name, list->name, list->value);
1813
developer8078acf2023-08-04 18:52:48 +08001814 if (fp == NULL) {
1815 perror("v_secure_popen failed");
developera3511852023-06-14 14:12:59 +08001816 return -1;
1817 }
developere40952c2023-06-15 18:46:43 +08001818 if (!fgets(output, sizeof(output), fp) || strncmp(output, "OK", 2)) {
developer8078acf2023-08-04 18:52:48 +08001819 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +08001820 perror("fgets failed");
1821 return -1;
1822 }
developer8078acf2023-08-04 18:52:48 +08001823 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +08001824 }
1825 return 0;
developer72fb0bb2023-01-11 09:46:29 +08001826}
1827
developer7e4a2a62023-04-06 19:56:03 +08001828static int wifi_quick_reload_ap(int apIndex)
1829{
1830 char interface_name[IF_NAME_SIZE] = {0};
developer7e4a2a62023-04-06 19:56:03 +08001831 char buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08001832 int res;
developer7e4a2a62023-04-06 19:56:03 +08001833
1834 if (multiple_set == TRUE)
1835 return RETURN_OK;
1836
developer9f2358c2023-09-22 18:42:12 +08001837
developer7e4a2a62023-04-06 19:56:03 +08001838 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
1839 return RETURN_ERR;
1840
developer8078acf2023-08-04 18:52:48 +08001841 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s reload", interface_name);
developer9f2358c2023-09-22 18:42:12 +08001842 if (res) {
developer8078acf2023-08-04 18:52:48 +08001843 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer7e4a2a62023-04-06 19:56:03 +08001844 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +08001845 }
developer7e4a2a62023-04-06 19:56:03 +08001846
1847 return RETURN_OK;
1848}
1849
developer72fb0bb2023-01-11 09:46:29 +08001850static int wifi_reloadAp(int apIndex)
1851{
developera3511852023-06-14 14:12:59 +08001852 char interface_name[16] = {0};
developer22e0c672023-06-07 15:25:37 +08001853 int res;
1854
developera3511852023-06-14 14:12:59 +08001855 if (multiple_set == TRUE)
1856 return RETURN_OK;
developera3511852023-06-14 14:12:59 +08001857 char buf[MAX_BUF_SIZE]="";
developer72fb0bb2023-01-11 09:46:29 +08001858
developera3511852023-06-14 14:12:59 +08001859 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
1860 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08001861
developer8078acf2023-08-04 18:52:48 +08001862 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s reload", interface_name);
1863 if (res) {
1864 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer22e0c672023-06-07 15:25:37 +08001865 return RETURN_ERR;
1866 }
developer72fb0bb2023-01-11 09:46:29 +08001867
developer8078acf2023-08-04 18:52:48 +08001868
1869 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s disable", interface_name);
1870 if (res) {
1871 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer22e0c672023-06-07 15:25:37 +08001872 return RETURN_ERR;
1873 }
developer72fb0bb2023-01-11 09:46:29 +08001874
developer8078acf2023-08-04 18:52:48 +08001875 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s enable", interface_name);
1876 if (res) {
1877 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developera3511852023-06-14 14:12:59 +08001878 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +08001879 }
developer72fb0bb2023-01-11 09:46:29 +08001880
developera3511852023-06-14 14:12:59 +08001881 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08001882}
1883
1884void wifi_RestartHostapd_2G()
1885{
developera3511852023-06-14 14:12:59 +08001886 int Public2GApIndex = 4;
developer72fb0bb2023-01-11 09:46:29 +08001887
developera3511852023-06-14 14:12:59 +08001888 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1889 wifi_setApEnable(Public2GApIndex, FALSE);
1890 wifi_setApEnable(Public2GApIndex, TRUE);
1891 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001892}
1893
1894void wifi_RestartHostapd_5G()
1895{
developerbb9b20f2023-10-17 18:46:37 +08001896 int Public5GApIndex = 1;
developer72fb0bb2023-01-11 09:46:29 +08001897
developera3511852023-06-14 14:12:59 +08001898 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1899 wifi_setApEnable(Public5GApIndex, FALSE);
1900 wifi_setApEnable(Public5GApIndex, TRUE);
1901 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001902}
1903
1904void wifi_RestartPrivateWifi_2G()
1905{
developera3511852023-06-14 14:12:59 +08001906 int PrivateApIndex = 0;
developer72fb0bb2023-01-11 09:46:29 +08001907
developera3511852023-06-14 14:12:59 +08001908 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1909 wifi_setApEnable(PrivateApIndex, FALSE);
1910 wifi_setApEnable(PrivateApIndex, TRUE);
1911 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001912}
1913
1914void wifi_RestartPrivateWifi_5G()
1915{
developera3511852023-06-14 14:12:59 +08001916 int Private5GApIndex = 1;
developer72fb0bb2023-01-11 09:46:29 +08001917
developera3511852023-06-14 14:12:59 +08001918 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1919 wifi_setApEnable(Private5GApIndex, FALSE);
1920 wifi_setApEnable(Private5GApIndex, TRUE);
1921 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001922}
1923
1924static int writeBandWidth(int radioIndex,char *bw_value)
1925{
developera3511852023-06-14 14:12:59 +08001926 char buf[MAX_BUF_SIZE];
developere40952c2023-06-15 18:46:43 +08001927 int res;
developer72fb0bb2023-01-11 09:46:29 +08001928
developere40952c2023-06-15 18:46:43 +08001929
developer8078acf2023-08-04 18:52:48 +08001930 if (_syscmd_secure(buf, sizeof(buf), "grep SET_BW%d %s", radioIndex, BW_FNAME)) {
developer82160f02023-08-19 15:30:44 +08001931 res = _syscmd_secure(buf, sizeof(buf), "echo SET_BW%d=%s >> /nvram/bw_file.txt", radioIndex, bw_value);
developer8078acf2023-08-04 18:52:48 +08001932 if (res) {
1933 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08001934 }
developera3511852023-06-14 14:12:59 +08001935 return RETURN_OK;
1936 }
developer72fb0bb2023-01-11 09:46:29 +08001937
developer8078acf2023-08-04 18:52:48 +08001938
1939 res = _syscmd_secure(buf, sizeof(buf), "sed -i 's/^SET_BW%d=.*$/SET_BW%d=%s/' %s",radioIndex,radioIndex,bw_value,BW_FNAME);
1940 if (res) {
1941 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +08001942 }
developera3511852023-06-14 14:12:59 +08001943 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08001944}
1945
1946// Input could be "1Mbps"; "5.5Mbps"; "6Mbps"; "2Mbps"; "11Mbps"; "12Mbps"; "24Mbps"
1947INT wifi_setApBeaconRate(INT radioIndex,CHAR *beaconRate)
1948{
developera3511852023-06-14 14:12:59 +08001949 struct params params={'\0'};
1950 char config_file[MAX_BUF_SIZE] = {0};
1951 char buf[MAX_BUF_SIZE] = {'\0'};
developere40952c2023-06-15 18:46:43 +08001952 int res;
developer72fb0bb2023-01-11 09:46:29 +08001953
developera3511852023-06-14 14:12:59 +08001954 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
1955 // Copy the numeric value
1956 if (strlen (beaconRate) >= 5) {
1957 strncpy(buf, beaconRate, strlen(beaconRate) - 4);
1958 buf[strlen(beaconRate) - 4] = '\0';
developer9ce44382023-06-28 11:09:37 +08001959 } else if (strlen(beaconRate) > 0){
1960 strncpy(buf, beaconRate,sizeof(buf) - 1);
1961 buf[sizeof(buf) - 1] = '\0';
1962 } else
developera3511852023-06-14 14:12:59 +08001963 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08001964
developera3511852023-06-14 14:12:59 +08001965 params.name = "beacon_rate";
1966 // hostapd config unit is 100 kbps. To convert Mbps to 100kbps, the value need to multiply 10.
1967 if (strncmp(buf, "5.5", 3) == 0) {
developere40952c2023-06-15 18:46:43 +08001968 res = snprintf(buf, sizeof(buf), "55");
1969 if (os_snprintf_error(sizeof(buf), res)) {
1970 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1971 return RETURN_ERR;
1972 }
developera3511852023-06-14 14:12:59 +08001973 params.value = buf;
1974 } else {
developer32f2a182023-06-27 19:50:41 +08001975 if (strlen(buf) >= (MAX_BUF_SIZE - 1)) {
1976 wifi_debug(DEBUG_ERROR, "not enough room in buf\n");
1977 return RETURN_ERR;
1978 }
1979 strncat(buf, "0", sizeof(buf) - strlen(buf) - 1);
developera3511852023-06-14 14:12:59 +08001980 params.value = buf;
1981 }
developer72fb0bb2023-01-11 09:46:29 +08001982
developer32f2a182023-06-27 19:50:41 +08001983 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
1984 if (os_snprintf_error(sizeof(config_file), res)) {
1985 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
1986 return RETURN_ERR;
1987 }
1988
developera3511852023-06-14 14:12:59 +08001989 wifi_hostapdWrite(config_file, &params, 1);
1990 wifi_hostapdProcessUpdate(radioIndex, &params, 1);
1991 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08001992
developera3511852023-06-14 14:12:59 +08001993 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08001994}
1995
1996INT wifi_getApBeaconRate(INT radioIndex, CHAR *beaconRate)
1997{
developera3511852023-06-14 14:12:59 +08001998 char config_file[128] = {'\0'};
1999 char temp_output[MAX_BUF_SIZE] = {'\0'};
2000 char buf[128] = {'\0'};
developer8078acf2023-08-04 18:52:48 +08002001
developerc14d83a2023-06-29 20:09:42 +08002002 long int rate = 0;
developere40952c2023-06-15 18:46:43 +08002003 int phyId = 0, res;
developer72fb0bb2023-01-11 09:46:29 +08002004
developera3511852023-06-14 14:12:59 +08002005 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
2006 if (NULL == beaconRate)
2007 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08002008
developer75bd10c2023-06-27 11:34:08 +08002009 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
2010 if (os_snprintf_error(sizeof(config_file), res)) {
2011 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2012 return RETURN_ERR;
2013 }
developera3511852023-06-14 14:12:59 +08002014 wifi_hostapdRead(config_file, "beacon_rate", buf, sizeof(buf));
2015 phyId = radio_index_to_phy(radioIndex);
2016 // Hostapd unit is 100kbps. To convert to 100kbps to Mbps, the value need to divide 10.
2017 if(strlen(buf) > 0) {
2018 if (strncmp(buf, "55", 2) == 0)
developere40952c2023-06-15 18:46:43 +08002019 res = snprintf(temp_output, sizeof(temp_output), "5.5Mbps");
developera3511852023-06-14 14:12:59 +08002020 else {
developerc14d83a2023-06-29 20:09:42 +08002021 if (hal_strtol(buf, 10, &rate) < 0) {
2022 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2023 }
developerb14b3462023-07-01 18:02:42 +08002024 res = snprintf(temp_output, sizeof(temp_output), "%ldMbps", rate/10);
developera3511852023-06-14 14:12:59 +08002025 }
developer75bd10c2023-06-27 11:34:08 +08002026 if (os_snprintf_error(sizeof(temp_output), res)) {
2027 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2028 return RETURN_ERR;
2029 }
developera3511852023-06-14 14:12:59 +08002030 } else {
2031 // config not set, so we would use lowest rate as default
developer8078acf2023-08-04 18:52:48 +08002032 res = _syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep Bitrates -A1 | tail -n 1 | awk '{print $2}' | tr -d '.0\\n'", phyId);
2033 if (res) {
2034 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +08002035 }
developer8078acf2023-08-04 18:52:48 +08002036
developere40952c2023-06-15 18:46:43 +08002037 res = snprintf(temp_output, sizeof(temp_output), "%sMbps", buf);
developer75bd10c2023-06-27 11:34:08 +08002038 if (os_snprintf_error(sizeof(temp_output), res)) {
2039 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2040 return RETURN_ERR;
2041 }
developera3511852023-06-14 14:12:59 +08002042 }
developer75bd10c2023-06-27 11:34:08 +08002043
developera3511852023-06-14 14:12:59 +08002044 strncpy(beaconRate, temp_output, strlen(temp_output));
2045 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08002046
developera3511852023-06-14 14:12:59 +08002047 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002048}
2049
2050INT wifi_setLED(INT radioIndex, BOOL enable)
2051{
2052 return 0;
2053}
2054INT wifi_setRadioAutoChannelRefreshPeriod(INT radioIndex, ULONG seconds)
2055{
2056 return RETURN_OK;
2057}
2058/**********************************************************************************
2059 *
developer69b61b02023-03-07 17:17:44 +08002060 * Wifi Subsystem level function prototypes
developer72fb0bb2023-01-11 09:46:29 +08002061 *
2062**********************************************************************************/
2063//---------------------------------------------------------------------------------------------------
2064//Wifi system api
2065//Get the wifi hal version in string, eg "2.0.0". WIFI_HAL_MAJOR_VERSION.WIFI_HAL_MINOR_VERSION.WIFI_HAL_MAINTENANCE_VERSION
developer69b61b02023-03-07 17:17:44 +08002066INT wifi_getHalVersion(CHAR *output_string) //RDKB
developer72fb0bb2023-01-11 09:46:29 +08002067{
developere40952c2023-06-15 18:46:43 +08002068 int res;
2069
developera3511852023-06-14 14:12:59 +08002070 if(!output_string)
2071 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08002072 res = snprintf(output_string, 64, "%d.%d.%d", WIFI_HAL_MAJOR_VERSION, WIFI_HAL_MINOR_VERSION, WIFI_HAL_MAINTENANCE_VERSION);
2073 if (os_snprintf_error(64, res)) {
2074 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2075 return RETURN_ERR;
2076 }
developer72fb0bb2023-01-11 09:46:29 +08002077
developera3511852023-06-14 14:12:59 +08002078 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002079}
2080
2081
2082/* wifi_factoryReset() function */
2083/**
developer69b61b02023-03-07 17:17:44 +08002084* @description Clears internal variables to implement a factory reset of the Wi-Fi
developer72fb0bb2023-01-11 09:46:29 +08002085* subsystem. Resets Implementation specifics may dictate some functionality since different hardware implementations may have different requirements.
2086*
2087* @param None
2088*
2089* @return The status of the operation.
2090* @retval RETURN_OK if successful.
2091* @retval RETURN_ERR if any error is detected
2092*
2093* @execution Synchronous
2094* @sideeffect None
2095*
2096* @note This function must not suspend and must not invoke any blocking system
2097* calls. It should probably just send a message to a driver event handler task.
2098*
2099*/
2100INT wifi_factoryReset()
2101{
developer47cc27a2023-05-17 23:09:58 +08002102 char buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08002103 int res;
developer72fb0bb2023-01-11 09:46:29 +08002104
developer47cc27a2023-05-17 23:09:58 +08002105 /*delete running hostapd conf files*/
2106 wifi_dbg_printf("\n[%s]: deleting hostapd conf file.", __func__);
developere40952c2023-06-15 18:46:43 +08002107
developer8078acf2023-08-04 18:52:48 +08002108 res = _syscmd_secure(buf, sizeof(buf), "rm -rf /nvram/*.conf");
2109 if (res) {
2110 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
2111 }
developer72fb0bb2023-01-11 09:46:29 +08002112
developerd14dff12023-06-28 22:47:44 +08002113 wifi_PrepareDefaultHostapdConfigs(TRUE);
developer47cc27a2023-05-17 23:09:58 +08002114 wifi_psk_file_reset();
2115
developer8078acf2023-08-04 18:52:48 +08002116
developer47cc27a2023-05-17 23:09:58 +08002117 memset(buf, 0, MAX_BUF_SIZE);
2118
developer8078acf2023-08-04 18:52:48 +08002119 res = _syscmd_secure(buf, sizeof(buf), "systemctl restart hostapd.service");
2120 if (res) {
2121 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002122 }
2123
developer47cc27a2023-05-17 23:09:58 +08002124 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002125}
2126
2127/* wifi_factoryResetRadios() function */
2128/**
2129* @description Restore all radio parameters without touching access point parameters. Resets Implementation specifics may dictate some functionality since different hardware implementations may have different requirements.
2130*
2131* @param None
2132* @return The status of the operation
2133* @retval RETURN_OK if successful
2134* @retval RETURN_ERR if any error is detected
2135*
2136* @execution Synchronous
2137*
2138* @sideeffect None
2139*
2140* @note This function must not suspend and must not invoke any blocking system
2141* calls. It should probably just send a message to a driver event handler task.
2142*
2143*/
2144INT wifi_factoryResetRadios()
2145{
developera3511852023-06-14 14:12:59 +08002146 if((RETURN_OK == wifi_factoryResetRadio(0)) && (RETURN_OK == wifi_factoryResetRadio(1)))
2147 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002148
developera3511852023-06-14 14:12:59 +08002149 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08002150}
2151
developerfead3972023-05-25 20:15:02 +08002152ULONG get_radio_reset_cnt(int radioIndex)
2153{
developerfead3972023-05-25 20:15:02 +08002154 char buf[MAX_BUF_SIZE] = {0};
2155 ULONG reset_count = 0;
developere40952c2023-06-15 18:46:43 +08002156 int res;
developerfead3972023-05-25 20:15:02 +08002157
developer8078acf2023-08-04 18:52:48 +08002158 res = _syscmd_secure(buf, sizeof(buf), "cat %s 2> /dev/null | grep \"^reset%d=\" | cut -d \"=\" -f 2 | head -n1 | tr -d \"\\n\"",
developerfead3972023-05-25 20:15:02 +08002159 RADIO_RESET_FILE, radioIndex);
developer8078acf2023-08-04 18:52:48 +08002160 if (res) {
2161 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002162 }
2163
developerfead3972023-05-25 20:15:02 +08002164 if (strlen(buf) == 0)
2165 return 0;
2166 else {
2167 reset_count = atol(buf);
2168 return reset_count;
2169 }
2170}
developerd08b7d52023-08-22 15:41:36 +08002171
2172void reset_guard_interval(int radioIndex)
2173{
2174 char buf[MAX_BUF_SIZE] = {0};
2175 int res;
2176 FILE *f = NULL;
2177
2178 res = snprintf(buf, sizeof(buf), "%s%d.txt", GUARD_INTERVAL_FILE, radioIndex);
2179 if (os_snprintf_error(sizeof(buf), res)) {
2180 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2181 return;
2182 }
2183 f = fopen(buf, "w");
2184 if (f == NULL)
2185 return;
2186 fprintf(f, "%s", "auto");
2187 if (fclose(f) == EOF)
2188 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
2189}
2190
developerfead3972023-05-25 20:15:02 +08002191void update_radio_reset_cnt(int radioIndex)
2192{
developerfead3972023-05-25 20:15:02 +08002193 char buf[MAX_BUF_SIZE] = {0};
2194 ULONG reset_count = 0;
developere40952c2023-06-15 18:46:43 +08002195 int res;
developerfead3972023-05-25 20:15:02 +08002196
developer8078acf2023-08-04 18:52:48 +08002197 res = _syscmd_secure(buf, sizeof(buf), "cat %s 2> /dev/null | grep \"^reset%d=\" | cut -d \"=\" -f 2 | head -n1 | tr -d \"\\n\"",
2198 RADIO_RESET_FILE, radioIndex );
2199 if (res) {
2200 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002201 }
2202
developerfead3972023-05-25 20:15:02 +08002203 if (strlen(buf) == 0)
developer8078acf2023-08-04 18:52:48 +08002204 res =_syscmd_secure(buf, sizeof(buf), "sed -i -e '$a reset%d=1' %s", radioIndex, RADIO_RESET_FILE);
developerfead3972023-05-25 20:15:02 +08002205 else {
2206 reset_count = atol(buf);
2207 reset_count++;
developer8078acf2023-08-04 18:52:48 +08002208 res = _syscmd_secure(buf,sizeof(buf), "sed -i \"s/^reset%d=.*/reset%d=%lu/\" %s", radioIndex, radioIndex, reset_count, RADIO_RESET_FILE);
developere40952c2023-06-15 18:46:43 +08002209 }
developer8078acf2023-08-04 18:52:48 +08002210
2211 if (res) {
2212 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developerfead3972023-05-25 20:15:02 +08002213 }
developerfead3972023-05-25 20:15:02 +08002214}
developer72fb0bb2023-01-11 09:46:29 +08002215
2216/* wifi_factoryResetRadio() function */
2217/**
2218* @description Restore selected radio parameters without touching access point parameters
2219*
2220* @param radioIndex - Index of Wi-Fi Radio channel
2221*
2222* @return The status of the operation.
2223* @retval RETURN_OK if successful.
2224* @retval RETURN_ERR if any error is detected
2225*
2226* @execution Synchronous.
2227* @sideeffect None.
2228*
2229* @note This function must not suspend and must not invoke any blocking system
2230* calls. It should probably just send a message to a driver event handler task.
2231*
2232*/
2233INT wifi_factoryResetRadio(int radioIndex) //RDKB
2234{
developer47cc27a2023-05-17 23:09:58 +08002235 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08002236
developerb2977562023-05-24 17:54:12 +08002237 wifi_dat_file_reset_by_radio(radioIndex);
developer47cc27a2023-05-17 23:09:58 +08002238
developerb2977562023-05-24 17:54:12 +08002239 /*reset gi setting*/
developerd08b7d52023-08-22 15:41:36 +08002240 reset_guard_interval(radioIndex);
2241
developerb2977562023-05-24 17:54:12 +08002242 /*TBD: check mbss issue*/
2243 wifi_factoryResetAP(radioIndex);
developerfead3972023-05-25 20:15:02 +08002244 update_radio_reset_cnt(radioIndex);
developerb2977562023-05-24 17:54:12 +08002245
developer47cc27a2023-05-17 23:09:58 +08002246 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
2247 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002248}
2249
2250/* wifi_initRadio() function */
2251/**
2252* Description: This function call initializes the specified radio.
developer69b61b02023-03-07 17:17:44 +08002253* Implementation specifics may dictate the functionality since
developer72fb0bb2023-01-11 09:46:29 +08002254* different hardware implementations may have different initilization requirements.
2255* Parameters : radioIndex - The index of the radio. First radio is index 0. 2nd radio is index 1 - type INT
2256*
2257* @return The status of the operation.
2258* @retval RETURN_OK if successful.
2259* @retval RETURN_ERR if any error is detected
2260*
2261* @execution Synchronous.
2262* @sideeffect None.
2263*
2264* @note This function must not suspend and must not invoke any blocking system
2265* calls. It should probably just send a message to a driver event handler task.
2266*
2267*/
2268INT wifi_initRadio(INT radioIndex)
2269{
developera3511852023-06-14 14:12:59 +08002270 //TODO: Initializes the wifi subsystem (for specified radio)
2271 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002272}
2273
developer17038e62023-03-02 14:43:43 +08002274static void
2275wifi_ParseProfile(void)
2276{
developere40952c2023-06-15 18:46:43 +08002277 int i, res;
developera3511852023-06-14 14:12:59 +08002278 int max_radio_num = 0;
2279 int card_idx;
2280 int band_idx;
2281 int phy_idx = 0;
2282 int wireless_mode = 0;
2283 char buf[MAX_BUF_SIZE] = {0};
2284 char chip_name[12];
2285 char card_profile[MAX_BUF_SIZE] = {0};
2286 char band_profile[MAX_BUF_SIZE] = {0};
developer17038e62023-03-02 14:43:43 +08002287
developera3511852023-06-14 14:12:59 +08002288 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer17038e62023-03-02 14:43:43 +08002289
developera3511852023-06-14 14:12:59 +08002290 memset(main_prefix, 0, sizeof(main_prefix));
2291 memset(ext_prefix, 0, sizeof(ext_prefix));
2292 memset(default_ssid, 0, sizeof(default_ssid));
2293 for (i = 0; i < MAX_NUM_RADIOS; i++)
2294 radio_band[i] = band_invalid;
developer17038e62023-03-02 14:43:43 +08002295
developera3511852023-06-14 14:12:59 +08002296 if (wifi_getMaxRadioNumber(&max_radio_num) != RETURN_OK) {
2297 /* LOG */
developer17038e62023-03-02 14:43:43 +08002298 return;
developera3511852023-06-14 14:12:59 +08002299 }
developer17038e62023-03-02 14:43:43 +08002300
developera3511852023-06-14 14:12:59 +08002301 for (card_idx = 0; card_idx < 3; card_idx++) {
developere40952c2023-06-15 18:46:43 +08002302 res = snprintf(buf, sizeof(buf), "INDEX%d", card_idx);
2303 if (os_snprintf_error(sizeof(buf), res)) {
2304 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2305 return;
2306 }
developera3511852023-06-14 14:12:59 +08002307 if (get_value(l1profile, buf, chip_name, sizeof(chip_name)) < 0) {
2308 break;
2309 }
developere40952c2023-06-15 18:46:43 +08002310 res = snprintf(buf, sizeof(buf), "INDEX%d_profile_path", card_idx);
2311 if (os_snprintf_error(sizeof(buf), res)) {
2312 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2313 return;
2314 }
developera3511852023-06-14 14:12:59 +08002315 if (get_value(l1profile, buf, card_profile, sizeof(card_profile)) < 0) {
2316 break;
2317 }
2318 for (band_idx = 0; band_idx < 3; band_idx++) {
developere40952c2023-06-15 18:46:43 +08002319 res = snprintf(buf, sizeof(buf), "BN%d_profile_path", band_idx);
2320 if (os_snprintf_error(sizeof(buf), res)) {
2321 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2322 return;
2323 }
developera3511852023-06-14 14:12:59 +08002324 if (get_value(card_profile, buf, band_profile, sizeof(band_profile)) < 0) {
2325 /* LOG */
2326 break;
2327 }
developer17038e62023-03-02 14:43:43 +08002328
developere40952c2023-06-15 18:46:43 +08002329 res = snprintf(buf, sizeof(buf), "INDEX%d_main_ifname", card_idx);
2330 if (os_snprintf_error(sizeof(buf), res)) {
2331 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2332 return;
2333 }
developera3511852023-06-14 14:12:59 +08002334 if (get_value_by_idx(l1profile, buf, band_idx, main_prefix[phy_idx], IFNAMSIZ) < 0) {
2335 /* LOG */
2336 }
developer17038e62023-03-02 14:43:43 +08002337
developere40952c2023-06-15 18:46:43 +08002338 res = snprintf(buf, sizeof(buf), "INDEX%d_ext_ifname", card_idx);
2339 if (os_snprintf_error(sizeof(buf), res)) {
2340 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2341 return;
2342 }
developera3511852023-06-14 14:12:59 +08002343 if (get_value_by_idx(l1profile, buf, band_idx, ext_prefix[phy_idx], IFNAMSIZ) < 0) {
2344 /* LOG */
2345 }
developer17038e62023-03-02 14:43:43 +08002346
developera3511852023-06-14 14:12:59 +08002347 if (get_value(band_profile, "SSID1", default_ssid[phy_idx], sizeof(default_ssid[phy_idx])) < 0) {
2348 /* LOG */
2349 }
2350 if (get_value(band_profile, "WirelessMode", buf, sizeof(buf)) < 0) {
2351 /* LOG */
2352 }
developer745f0bd2023-03-06 14:32:53 +08002353
developera3511852023-06-14 14:12:59 +08002354 wireless_mode = atoi(buf);
2355 switch (wireless_mode) {
2356 case 22:
2357 case 16:
2358 case 6:
2359 case 4:
2360 case 1:
2361 radio_band[phy_idx] = band_2_4;
2362 break;
2363 case 23:
2364 case 17:
2365 case 14:
2366 case 11:
2367 case 2:
2368 radio_band[phy_idx] = band_5;
2369 break;
2370 case 24:
2371 case 18:
2372 radio_band[phy_idx] = band_6;
2373 break;
2374 }
2375 phy_idx++;
2376 }
2377 }
developer17038e62023-03-02 14:43:43 +08002378
developera3511852023-06-14 14:12:59 +08002379 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer17038e62023-03-02 14:43:43 +08002380}
2381
2382static void
developerd14dff12023-06-28 22:47:44 +08002383wifi_PrepareDefaultHostapdConfigs(bool reset)
developer17038e62023-03-02 14:43:43 +08002384{
developere40952c2023-06-15 18:46:43 +08002385 int radio_idx, res;
developer0132ed92023-03-21 13:48:53 +08002386 int bss_idx;
2387 int ap_idx;
developer8078acf2023-08-04 18:52:48 +08002388
developerb149d9d2023-06-06 16:14:22 +08002389 char config_file[MAX_SUB_CMD_SIZE] = {0};
developer0132ed92023-03-21 13:48:53 +08002390 char ssid[MAX_BUF_SIZE] = {0};
2391 char interface[32] = {0};
2392 char ret_buf[MAX_BUF_SIZE] = {0};
2393 char psk_file[64] = {0};
2394 struct params params[3];
developer17038e62023-03-02 14:43:43 +08002395
developer0132ed92023-03-21 13:48:53 +08002396 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
2397 for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++) {
developer47cc27a2023-05-17 23:09:58 +08002398
developerbb9b20f2023-10-17 18:46:37 +08002399 for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++) {
developer47cc27a2023-05-17 23:09:58 +08002400 ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
developer0132ed92023-03-21 13:48:53 +08002401
developere40952c2023-06-15 18:46:43 +08002402 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_idx);
2403 if (os_snprintf_error(sizeof(config_file), res)) {
2404 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2405 return;
2406 }
developerd14dff12023-06-28 22:47:44 +08002407 if (access(config_file, F_OK) == 0 && reset == FALSE)
2408 continue;
developer8078acf2023-08-04 18:52:48 +08002409 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "cp /etc/hostapd-%s.conf %s", wifi_band_str[radio_idx], config_file);
2410 if (res) {
2411 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002412 }
developer8078acf2023-08-04 18:52:48 +08002413
2414
2415
2416
developer17038e62023-03-02 14:43:43 +08002417
developer47cc27a2023-05-17 23:09:58 +08002418 if (radio_idx == band_2_4) {
developere40952c2023-06-15 18:46:43 +08002419 res = snprintf(ssid, sizeof(ssid), "%s_%d", PREFIX_SSID_2G, bss_idx);
2420 if (os_snprintf_error(sizeof(ssid), res)) {
2421 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2422 return;
2423 }
2424 res = snprintf(interface, sizeof(interface), "%s%d", PREFIX_WIFI2G, bss_idx);
2425 if (os_snprintf_error(sizeof(interface), res)) {
2426 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2427 return;
2428 }
developer47cc27a2023-05-17 23:09:58 +08002429 } else if (radio_idx == band_5) {
developere40952c2023-06-15 18:46:43 +08002430 res = snprintf(ssid, sizeof(ssid), "%s_%d", PREFIX_SSID_5G, bss_idx);
2431 if (os_snprintf_error(sizeof(ssid), res)) {
2432 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2433 return;
2434 }
2435 res = snprintf(interface, sizeof(interface), "%s%d", PREFIX_WIFI5G, bss_idx);
2436 if (os_snprintf_error(sizeof(interface), res)) {
2437 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2438 return;
2439 }
developer47cc27a2023-05-17 23:09:58 +08002440 } else if (radio_idx == band_6) {
developere40952c2023-06-15 18:46:43 +08002441 res = snprintf(ssid, sizeof(ssid), "%s_%d", PREFIX_SSID_6G, bss_idx);
2442 if (os_snprintf_error(sizeof(ssid), res)) {
2443 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2444 return;
2445 }
2446 res = snprintf(interface, sizeof(interface), "%s%d", PREFIX_WIFI6G, bss_idx);
2447 if (os_snprintf_error(sizeof(interface), res)) {
2448 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2449 return;
2450 }
developer47cc27a2023-05-17 23:09:58 +08002451 }
developer17038e62023-03-02 14:43:43 +08002452
developer47cc27a2023-05-17 23:09:58 +08002453 /* fix wpa_psk_file path */
developere40952c2023-06-15 18:46:43 +08002454 res = snprintf(psk_file, sizeof(psk_file), "\\/nvram\\/hostapd%d.psk", ap_idx);
2455 if (os_snprintf_error(sizeof(psk_file), res)) {
2456 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2457 return;
2458 }
developer17038e62023-03-02 14:43:43 +08002459
developer47cc27a2023-05-17 23:09:58 +08002460 params[0].name = "ssid";
2461 params[0].value = ssid;
2462 params[1].name = "interface";
2463 params[1].value = interface;
2464 params[2].name = "wpa_psk_file";
2465 params[2].value = psk_file;
developer17038e62023-03-02 14:43:43 +08002466
developer47cc27a2023-05-17 23:09:58 +08002467 wifi_hostapdWrite(config_file, params, 3);
developer0132ed92023-03-21 13:48:53 +08002468 }
2469 }
2470 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer17038e62023-03-02 14:43:43 +08002471}
2472
2473static void
developer4fe22c62023-08-03 13:23:58 +08002474wifiBringUpInterfacesForRadio(int radio_idx)
2475{
2476 int bss_idx;
2477 int ap_idx;
2478 char cmd[MAX_CMD_SIZE] = {0};
2479 char config_file[MAX_SUB_CMD_SIZE] = {0};
2480 char ret_buf[MAX_BUF_SIZE] = {0};
2481 char inf_name[IF_NAME_SIZE] = {0};
developer82160f02023-08-19 15:30:44 +08002482 int res, ret, bss_num;
developer4fe22c62023-08-03 13:23:58 +08002483
2484 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
2485
2486 bss_idx = 0;
developer82160f02023-08-19 15:30:44 +08002487
2488 ret = wifi_BandProfileRead(0, radio_idx, "BssidNum", ret_buf, sizeof(ret_buf), "1");
2489 if (ret != 0) {
2490 wifi_debug(DEBUG_ERROR, "wifi_BandProfileRead BssidNum failed\n");
2491 return;
2492 }
2493
2494 bss_num = atoi(ret_buf);
2495 if (bss_num <= 0) {
2496 wifi_debug(DEBUG_ERROR, "invalid BssidNum %s\n", ret_buf);
2497 return ;
2498 }
developerbb9b20f2023-10-17 18:46:37 +08002499
2500 if (bss_num > LOGAN_MAX_NUM_VAP_PER_RADIO) {
2501 wifi_debug(DEBUG_ERROR, "bss_num is larger than %d, use %d\n", LOGAN_MAX_NUM_VAP_PER_RADIO, LOGAN_MAX_NUM_VAP_PER_RADIO);
2502 bss_num = LOGAN_MAX_NUM_VAP_PER_RADIO;
2503 }
2504
developer82160f02023-08-19 15:30:44 +08002505 wifi_debug(DEBUG_ERROR, "band %d BssidNum %d\n", radio_idx, bss_num);
developer4fe22c62023-08-03 13:23:58 +08002506 /*TBD: we need refine setup flow and mbss flow*/
developer82160f02023-08-19 15:30:44 +08002507 for (bss_idx = 0; bss_idx < bss_num; bss_idx++) {
developer4fe22c62023-08-03 13:23:58 +08002508 ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
2509
developere7e0ae42023-08-17 09:29:49 +08002510 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "touch %s%d.psk", PSK_FILE, ap_idx);
2511 if (res) {
2512 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer4fe22c62023-08-03 13:23:58 +08002513 }
developer4fe22c62023-08-03 13:23:58 +08002514
2515 memset(cmd, 0, MAX_CMD_SIZE);
2516 memset(ret_buf, 0, MAX_BUF_SIZE);
2517
2518 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_idx);
2519 if (os_snprintf_error(sizeof(cmd), res)) {
2520 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2521 return;
2522 }
developer82160f02023-08-19 15:30:44 +08002523
developere7e0ae42023-08-17 09:29:49 +08002524 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "hostapd_cli -i global raw ADD bss_config=phy%d:%s", radio_idx, config_file);
2525 if (res) {
2526 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer4fe22c62023-08-03 13:23:58 +08002527 }
developer4fe22c62023-08-03 13:23:58 +08002528
2529 wifi_GetInterfaceName(ap_idx, inf_name);
developer82160f02023-08-19 15:30:44 +08002530 wifi_debug(DEBUG_ERROR, "bring up %s\n", inf_name);
developer4fe22c62023-08-03 13:23:58 +08002531
2532 memset(cmd, 0, MAX_CMD_SIZE);
2533 memset(ret_buf, 0, MAX_BUF_SIZE);
2534
2535 /* fix vap-status file */
developere7e0ae42023-08-17 09:29:49 +08002536 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "sed -i \"s/^%s=.*/%s=1/\" %s", inf_name, inf_name, VAP_STATUS_FILE);
2537 if (res) {
2538 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer4fe22c62023-08-03 13:23:58 +08002539 }
developere7e0ae42023-08-17 09:29:49 +08002540
developer82160f02023-08-19 15:30:44 +08002541 }
developer4fe22c62023-08-03 13:23:58 +08002542
2543 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
2544}
2545
2546
2547static void
2548wifi_BringUpInterfaces(void)
2549{
2550 int radio_idx;
2551 int band_idx;
2552
2553 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
2554 for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++) {
2555 band_idx = radio_index_to_band(radio_idx);
2556 if (band_idx < 0) {
2557 break;
2558 }
2559 wifiBringUpInterfacesForRadio(radio_idx);
2560 }
2561 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
2562}
2563
2564static void
developer17038e62023-03-02 14:43:43 +08002565wifi_BringDownInterfacesForRadio(int radio_idx)
2566{
developer8078acf2023-08-04 18:52:48 +08002567
developera3511852023-06-14 14:12:59 +08002568 char ret_buf[MAX_BUF_SIZE]={'\0'};
developere40952c2023-06-15 18:46:43 +08002569 int res;
developerb758dfd2023-06-21 17:32:07 +08002570
developera3511852023-06-14 14:12:59 +08002571 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer17038e62023-03-02 14:43:43 +08002572
developer8078acf2023-08-04 18:52:48 +08002573 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "hostapd_cli -i global raw REMOVE %s", main_prefix[radio_idx]);
2574 if (res) {
2575 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002576 }
developer8a3bbbf2023-03-15 17:47:23 +08002577
developera3511852023-06-14 14:12:59 +08002578 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer17038e62023-03-02 14:43:43 +08002579}
2580
2581
2582static void
2583wifi_BringDownInterfaces(void)
2584{
developera3511852023-06-14 14:12:59 +08002585 int radio_idx;
2586 int band_idx;
developer17038e62023-03-02 14:43:43 +08002587
developera3511852023-06-14 14:12:59 +08002588 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
2589 for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++) {
2590 band_idx = radio_index_to_band(radio_idx);
2591 if (band_idx < 0) {
2592 break;
2593 }
2594 wifi_BringDownInterfacesForRadio(radio_idx);
2595 }
2596 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer17038e62023-03-02 14:43:43 +08002597}
2598
developerb2977562023-05-24 17:54:12 +08002599static void wifi_dat_file_reset_by_radio(char radio_idx)
2600{
developer8078acf2023-08-04 18:52:48 +08002601
developerb2977562023-05-24 17:54:12 +08002602 char ret_buf[MAX_BUF_SIZE] = {0};
developerb149d9d2023-06-06 16:14:22 +08002603 char rom_dat_file[MAX_SUB_CMD_SIZE]= {0};
2604 char dat_file[MAX_SUB_CMD_SIZE]= {0};
developere40952c2023-06-15 18:46:43 +08002605 int res;
developerb2977562023-05-24 17:54:12 +08002606
developere40952c2023-06-15 18:46:43 +08002607 res = snprintf(rom_dat_file, sizeof(rom_dat_file), "%s%d.dat", ROM_LOGAN_DAT_FILE, radio_idx);
2608 if (os_snprintf_error(sizeof(rom_dat_file), res)) {
2609 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2610 return;
2611 }
2612 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, radio_idx);
2613 if (os_snprintf_error(sizeof(dat_file), res)) {
2614 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2615 return;
2616 }
developerb2977562023-05-24 17:54:12 +08002617
developer8078acf2023-08-04 18:52:48 +08002618 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "cp -rf %s %s", rom_dat_file, dat_file);
2619 if (res) {
2620 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
2621 }
developerb2977562023-05-24 17:54:12 +08002622}
2623
developer47cc27a2023-05-17 23:09:58 +08002624static void wifi_psk_file_reset()
2625{
developer47cc27a2023-05-17 23:09:58 +08002626 char ret_buf[MAX_BUF_SIZE] = {0};
developerb149d9d2023-06-06 16:14:22 +08002627 char psk_file[MAX_SUB_CMD_SIZE]= {0};
developer47cc27a2023-05-17 23:09:58 +08002628 char vap_idx = 0;
developere40952c2023-06-15 18:46:43 +08002629 int res;
developer47cc27a2023-05-17 23:09:58 +08002630
2631 for (vap_idx = 0; vap_idx < MAX_APS; vap_idx++) {
developere40952c2023-06-15 18:46:43 +08002632 res = snprintf(psk_file, sizeof(psk_file), "%s%d.psk", PSK_FILE, vap_idx);
2633 if (os_snprintf_error(sizeof(psk_file), res)) {
2634 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2635 return;
2636 }
developer47cc27a2023-05-17 23:09:58 +08002637
2638 if (access(psk_file, F_OK) != 0) {
developer8078acf2023-08-04 18:52:48 +08002639 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "touch %s", psk_file);
2640 if (res) {
2641 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002642 }
developer47cc27a2023-05-17 23:09:58 +08002643 } else {
developere40952c2023-06-15 18:46:43 +08002644
developer8078acf2023-08-04 18:52:48 +08002645 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "echo '' > %s", psk_file);
2646 if (res) {
2647 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
2648 }
developer47cc27a2023-05-17 23:09:58 +08002649 }
2650 }
developerb2977562023-05-24 17:54:12 +08002651}
2652
developer8a3bbbf2023-03-15 17:47:23 +08002653static void wifi_vap_status_reset()
2654{
developera3511852023-06-14 14:12:59 +08002655 char ret_buf[MAX_BUF_SIZE] = {0};
developer863a4a62023-06-06 16:55:59 +08002656 int radio_idx = 0;
developer8a3bbbf2023-03-15 17:47:23 +08002657 char bss_idx = 0;
developere40952c2023-06-15 18:46:43 +08002658 int res;
developer8666b312023-03-24 14:05:31 +08002659
developer8a3bbbf2023-03-15 17:47:23 +08002660 if (access(VAP_STATUS_FILE, F_OK) != 0) {
developer8078acf2023-08-04 18:52:48 +08002661 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "touch %s", VAP_STATUS_FILE);
2662 if (res) {
2663 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002664 }
developer8a3bbbf2023-03-15 17:47:23 +08002665 } else {
developer8078acf2023-08-04 18:52:48 +08002666 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "echo '' > %s", VAP_STATUS_FILE);
2667 if (res) {
2668 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002669 }
developer8a3bbbf2023-03-15 17:47:23 +08002670 }
2671
developer8a3bbbf2023-03-15 17:47:23 +08002672 memset(ret_buf, 0, MAX_BUF_SIZE);
2673
2674 for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++)
developerbb9b20f2023-10-17 18:46:37 +08002675 for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++) {
developer82160f02023-08-19 15:30:44 +08002676 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "echo %s%d=0 >> /nvram/vap-status", ext_prefix[radio_idx], bss_idx);
developer8078acf2023-08-04 18:52:48 +08002677 if (res) {
2678 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002679 }
developer8a3bbbf2023-03-15 17:47:23 +08002680 }
2681
developerfead3972023-05-25 20:15:02 +08002682}
2683
2684static void wifi_radio_reset_count_reset()
2685{
developer8078acf2023-08-04 18:52:48 +08002686
developera3511852023-06-14 14:12:59 +08002687 char ret_buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08002688 int res;
developerfead3972023-05-25 20:15:02 +08002689
2690 if (access(VAP_STATUS_FILE, F_OK) != 0) {
developer8078acf2023-08-04 18:52:48 +08002691 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "touch %s", RADIO_RESET_FILE);
2692 if (res) {
2693 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002694 }
developerfead3972023-05-25 20:15:02 +08002695 } else {
developer82160f02023-08-19 15:30:44 +08002696 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "echo '' > /nvram/radio_reset");
developer8078acf2023-08-04 18:52:48 +08002697 if (res) {
2698 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002699 }
developerfead3972023-05-25 20:15:02 +08002700 }
developer8a3bbbf2023-03-15 17:47:23 +08002701}
developer17038e62023-03-02 14:43:43 +08002702
developer72fb0bb2023-01-11 09:46:29 +08002703// Initializes the wifi subsystem (all radios)
developera3511852023-06-14 14:12:59 +08002704INT wifi_init() //RDKB
developer72fb0bb2023-01-11 09:46:29 +08002705{
developera3511852023-06-14 14:12:59 +08002706 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developercc9a4f32023-05-30 17:40:02 +08002707 static int CallOnce = 1;
developera3511852023-06-14 14:12:59 +08002708 //Not intitializing macfilter for Turris-Omnia Platform for now
2709 //macfilter_init();
2710 if (CallOnce) {
developercc9a4f32023-05-30 17:40:02 +08002711 wifi_ParseProfile();
developerd14dff12023-06-28 22:47:44 +08002712 wifi_PrepareDefaultHostapdConfigs(FALSE);
developercc9a4f32023-05-30 17:40:02 +08002713 wifi_psk_file_reset();
developer33f13ba2023-07-12 16:19:06 +08002714 //v_secure_system("/usr/sbin/iw reg set US");
2715 v_secure_system("systemctl start hostapd.service");
developercc9a4f32023-05-30 17:40:02 +08002716 sleep(2);
developerc338aba2023-08-09 13:56:42 +08002717 setbuf(stdout, NULL);
developercc9a4f32023-05-30 17:40:02 +08002718 wifi_vap_status_reset();
2719 wifi_radio_reset_count_reset();
developer4fe22c62023-08-03 13:23:58 +08002720 wifi_BringUpInterfaces();
developer6c6ef372023-11-08 10:59:14 +08002721 eht_mld_config_init();
developercc9a4f32023-05-30 17:40:02 +08002722 CallOnce = 0;
developer6c6ef372023-11-08 10:59:14 +08002723 mld_info_display();
developera3511852023-06-14 14:12:59 +08002724 }
developer96b38512023-02-22 11:17:45 +08002725
developera3511852023-06-14 14:12:59 +08002726 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08002727
developera3511852023-06-14 14:12:59 +08002728 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002729}
2730
2731/* wifi_reset() function */
2732/**
2733* Description: Resets the Wifi subsystem. This includes reset of all AP varibles.
developer69b61b02023-03-07 17:17:44 +08002734* Implementation specifics may dictate what is actualy reset since
developer72fb0bb2023-01-11 09:46:29 +08002735* different hardware implementations may have different requirements.
2736* Parameters : None
2737*
2738* @return The status of the operation.
2739* @retval RETURN_OK if successful.
2740* @retval RETURN_ERR if any error is detected
2741*
2742* @execution Synchronous.
2743* @sideeffect None.
2744*
2745* @note This function must not suspend and must not invoke any blocking system
2746* calls. It should probably just send a message to a driver event handler task.
2747*
2748*/
2749INT wifi_reset()
2750{
developer17038e62023-03-02 14:43:43 +08002751
developera3511852023-06-14 14:12:59 +08002752 wifi_BringDownInterfaces();
2753 sleep(2);
developer17038e62023-03-02 14:43:43 +08002754
developera3511852023-06-14 14:12:59 +08002755 //TODO: resets the wifi subsystem, deletes all APs
developer33f13ba2023-07-12 16:19:06 +08002756 v_secure_system("systemctl stop hostapd.service");
developera3511852023-06-14 14:12:59 +08002757 sleep(2);
developer17038e62023-03-02 14:43:43 +08002758
developer33f13ba2023-07-12 16:19:06 +08002759 v_secure_system("systemctl start hostapd.service");
developera3511852023-06-14 14:12:59 +08002760 sleep(5);
developer17038e62023-03-02 14:43:43 +08002761
developerd14dff12023-06-28 22:47:44 +08002762 wifi_PrepareDefaultHostapdConfigs(TRUE);
developer47cc27a2023-05-17 23:09:58 +08002763 wifi_psk_file_reset();
developer4fe22c62023-08-03 13:23:58 +08002764 wifi_BringUpInterfaces();
developera3511852023-06-14 14:12:59 +08002765 sleep(2);
developer8a3bbbf2023-03-15 17:47:23 +08002766
2767 wifi_vap_status_reset();
2768
developera3511852023-06-14 14:12:59 +08002769 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002770}
2771
2772/* wifi_down() function */
2773/**
2774* @description Turns off transmit power for the entire Wifi subsystem, for all radios.
developer69b61b02023-03-07 17:17:44 +08002775* Implementation specifics may dictate some functionality since
developer72fb0bb2023-01-11 09:46:29 +08002776* different hardware implementations may have different requirements.
2777*
2778* @param None
2779*
2780* @return The status of the operation
2781* @retval RETURN_OK if successful
2782* @retval RETURN_ERR if any error is detected
2783*
2784* @execution Synchronous
2785* @sideeffect None
2786*
2787* @note This function must not suspend and must not invoke any blocking system
2788* calls. It should probably just send a message to a driver event handler task.
2789*
2790*/
2791INT wifi_down()
2792{
developera3511852023-06-14 14:12:59 +08002793 //TODO: turns off transmit power for the entire Wifi subsystem, for all radios
2794 int max_num_radios = 0;
developerb2977562023-05-24 17:54:12 +08002795 wifi_getMaxRadioNumber(&max_num_radios);
developer17038e62023-03-02 14:43:43 +08002796
developerb2977562023-05-24 17:54:12 +08002797 for (int radioIndex = 0; radioIndex < max_num_radios; radioIndex++)
2798 wifi_setRadioEnable(radioIndex, FALSE);
2799
developera3511852023-06-14 14:12:59 +08002800 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002801}
2802
2803
2804/* wifi_createInitialConfigFiles() function */
2805/**
2806* @description This function creates wifi configuration files. The format
developer69b61b02023-03-07 17:17:44 +08002807* and content of these files are implementation dependent. This function call is
2808* used to trigger this task if necessary. Some implementations may not need this
2809* function. If an implementation does not need to create config files the function call can
developer72fb0bb2023-01-11 09:46:29 +08002810* do nothing and return RETURN_OK.
2811*
2812* @param None
2813*
2814* @return The status of the operation
2815* @retval RETURN_OK if successful
2816* @retval RETURN_ERR if any error is detected
2817*
2818* @execution Synchronous
2819* @sideeffect None
2820*
2821* @note This function must not suspend and must not invoke any blocking system
2822* calls. It should probably just send a message to a driver event handler task.
2823*
2824*/
2825INT wifi_createInitialConfigFiles()
2826{
developera3511852023-06-14 14:12:59 +08002827 //TODO: creates initial implementation dependent configuration files that are later used for variable storage. Not all implementations may need this function. If not needed for a particular implementation simply return no-error (0)
2828 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002829}
2830
developer7e4a2a62023-04-06 19:56:03 +08002831/* outputs the country code to a max 64 character string */
developer72fb0bb2023-01-11 09:46:29 +08002832INT wifi_getRadioCountryCode(INT radioIndex, CHAR *output_string)
2833{
developera3511852023-06-14 14:12:59 +08002834 int ret;
developer72fb0bb2023-01-11 09:46:29 +08002835
developera3511852023-06-14 14:12:59 +08002836 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer7e4a2a62023-04-06 19:56:03 +08002837
developera3511852023-06-14 14:12:59 +08002838 ret = wifi_BandProfileRead(0, radioIndex, "CountryCode", output_string, 64, NULL);
2839 if (ret != 0) {
developer75bd10c2023-06-27 11:34:08 +08002840 wifi_debug(DEBUG_ERROR, "wifi_BandProfileRead CountryCode failed\n");
developera3511852023-06-14 14:12:59 +08002841 return RETURN_ERR;
2842 }
developer7e4a2a62023-04-06 19:56:03 +08002843
developera3511852023-06-14 14:12:59 +08002844 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
developer7e4a2a62023-04-06 19:56:03 +08002845
developera3511852023-06-14 14:12:59 +08002846 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002847}
2848
2849INT wifi_setRadioCountryCode(INT radioIndex, CHAR *CountryCode)
2850{
developer7e4a2a62023-04-06 19:56:03 +08002851 /*Set wifi config. Wait for wifi reset to apply*/
developer7e4a2a62023-04-06 19:56:03 +08002852 struct params params;
2853 char config_file[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08002854 int ret = 0, res;
developer72fb0bb2023-01-11 09:46:29 +08002855
developer7e4a2a62023-04-06 19:56:03 +08002856 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08002857
developer7e4a2a62023-04-06 19:56:03 +08002858 if(NULL == CountryCode || strlen(CountryCode) >= 32 ) {
2859 printf("%s: input para error!!!\n", __func__);
2860 return RETURN_ERR;
2861 }
developer72fb0bb2023-01-11 09:46:29 +08002862
developerc79e9172023-06-06 19:48:03 +08002863 if (!strlen(CountryCode)) {
2864 memcpy(CountryCode, "US", strlen("US")); /*default set the code to US*/
2865 CountryCode[2] = '\0';
2866 }
developer72fb0bb2023-01-11 09:46:29 +08002867
developer7e4a2a62023-04-06 19:56:03 +08002868 params.name = "country_code";
2869 params.value = CountryCode;
developer72fb0bb2023-01-11 09:46:29 +08002870
developere40952c2023-06-15 18:46:43 +08002871 res = snprintf(config_file, MAX_BUF_SIZE, "%s%d.conf", CONFIG_PREFIX, radioIndex);
2872 if (os_snprintf_error(MAX_BUF_SIZE, res)) {
2873 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2874 return RETURN_ERR;
2875 }
developer7e4a2a62023-04-06 19:56:03 +08002876 ret = wifi_hostapdWrite(config_file, &params, 1);
2877
2878 if (ret) {
2879 WIFI_ENTRY_EXIT_DEBUG("Inside %s: wifi_hostapdWrite() return %d\n",
2880 __func__, ret);
2881 }
2882
2883 ret = wifi_hostapdProcessUpdate(radioIndex, &params, 1);
2884
2885 if (ret) {
2886 WIFI_ENTRY_EXIT_DEBUG("Inside %s: wifi_hostapdProcessUpdate() return %d\n",
2887 __func__, ret);
2888 }
2889
2890 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
2891
2892 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08002893}
2894
2895INT wifi_getRadioChannelStats2(INT radioIndex, wifi_channelStats2_t *outputChannelStats2)
2896{
developera3511852023-06-14 14:12:59 +08002897 char interface_name[16] = {0};
2898 char channel_util_file[64] = {0};
2899 char cmd[128] = {0};
2900 char buf[128] = {0};
2901 char *line = NULL;
2902 char *param = NULL, *value = NULL;
developere40952c2023-06-15 18:46:43 +08002903 int read = 0, res;
developera3511852023-06-14 14:12:59 +08002904 unsigned int ActiveTime = 0, BusyTime = 0, TransmitTime = 0;
developer86035662023-06-28 19:21:12 +08002905 unsigned long preActiveTime = 0, preBusyTime = 0, preTransmitTime = 0;
developerc14d83a2023-06-29 20:09:42 +08002906 long int rssi;
2907 long int tmp_l;
2908 unsigned long tmp_ul;
developera3511852023-06-14 14:12:59 +08002909 size_t len = 0;
2910 FILE *f = NULL;
developer72fb0bb2023-01-11 09:46:29 +08002911
developera3511852023-06-14 14:12:59 +08002912 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08002913
developera3511852023-06-14 14:12:59 +08002914 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
2915 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +08002916
2917 res = _syscmd_secure(buf, sizeof(buf), "iw %s scan | grep signal | awk '{print $2}' | sort -n | tail -n1", interface_name);
2918 if (res) {
2919 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08002920 }
2921
developerc14d83a2023-06-29 20:09:42 +08002922 if (hal_strtol(buf, 10, &rssi) < 0) {
2923 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2924 }
2925 outputChannelStats2->ch_Max80211Rssi = rssi;
developer72fb0bb2023-01-11 09:46:29 +08002926
developera3511852023-06-14 14:12:59 +08002927 memset(cmd, 0, sizeof(cmd));
2928 memset(buf, 0, sizeof(buf));
developere40952c2023-06-15 18:46:43 +08002929 res = snprintf(cmd, sizeof(cmd), "iw %s survey dump | grep 'in use' -A6", interface_name);
2930 if (os_snprintf_error(sizeof(cmd), res)) {
2931 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2932 return RETURN_ERR;
2933 }
developer8078acf2023-08-04 18:52:48 +08002934 f = v_secure_popen("r","iw %s survey dump | grep 'in use' -A6", interface_name);
2935 if (f == NULL) {
2936 wifi_dbg_printf("%s: v_secure_popen %s error\n", __func__, cmd);
developera3511852023-06-14 14:12:59 +08002937 return RETURN_ERR;
2938 }
developer72fb0bb2023-01-11 09:46:29 +08002939
developera3511852023-06-14 14:12:59 +08002940 read = getline(&line, &len, f);
2941 while (read != -1) {
2942 param = strtok(line, ":\t");
developerc14d83a2023-06-29 20:09:42 +08002943 if (!param) {
2944 read = getline(&line, &len, f);
2945 continue;
2946 }
developera3511852023-06-14 14:12:59 +08002947 value = strtok(NULL, " ");
developerc14d83a2023-06-29 20:09:42 +08002948 if (!value) {
developer37646972023-06-29 10:58:43 +08002949 read = getline(&line, &len, f);
2950 continue;
2951 }
developera3511852023-06-14 14:12:59 +08002952 if(strstr(param, "frequency") != NULL) {
developerc14d83a2023-06-29 20:09:42 +08002953 if (hal_strtoul(value, 10, &tmp_ul) < 0) {
2954 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2955 }
2956 outputChannelStats2->ch_Frequency = tmp_ul;
developera3511852023-06-14 14:12:59 +08002957 }
2958 if(strstr(param, "noise") != NULL) {
developerc14d83a2023-06-29 20:09:42 +08002959 if (hal_strtol(value, 10, &tmp_l) < 0) {
2960 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2961 }
2962 outputChannelStats2->ch_NoiseFloor = tmp_l;
developer37646972023-06-29 10:58:43 +08002963
developerc14d83a2023-06-29 20:09:42 +08002964 if (hal_strtol(value, 10, &tmp_l) < 0) {
2965 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2966 }
2967 outputChannelStats2->ch_Non80211Noise = tmp_l;
developera3511852023-06-14 14:12:59 +08002968 }
2969 if(strstr(param, "channel active time") != NULL) {
developerc14d83a2023-06-29 20:09:42 +08002970 if (hal_strtoul(value, 10, &tmp_ul) < 0) {
2971 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2972 }
2973 ActiveTime = tmp_ul;
developera3511852023-06-14 14:12:59 +08002974 }
developer5b23cd02023-07-19 20:26:03 +08002975 if(strstr(param, "channel busy time") != NULL) {
developerc14d83a2023-06-29 20:09:42 +08002976 if (hal_strtoul(value, 10, &tmp_ul) < 0) {
2977 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2978 }
2979 BusyTime = tmp_ul;
developera3511852023-06-14 14:12:59 +08002980 }
2981 if(strstr(param, "channel transmit time") != NULL) {
developerc14d83a2023-06-29 20:09:42 +08002982 if (hal_strtoul(value, 10, &tmp_ul) < 0) {
2983 wifi_debug(DEBUG_ERROR, "strtol fail\n");
2984 }
2985 TransmitTime = tmp_ul;
developera3511852023-06-14 14:12:59 +08002986 }
2987 read = getline(&line, &len, f);
2988 }
developer8078acf2023-08-04 18:52:48 +08002989 v_secure_pclose(f);
developer72fb0bb2023-01-11 09:46:29 +08002990
developera3511852023-06-14 14:12:59 +08002991 // The file should store the last active, busy and transmit time
developere40952c2023-06-15 18:46:43 +08002992 res = snprintf(channel_util_file, sizeof(channel_util_file), "%s%d.txt", CHANNEL_STATS_FILE, radioIndex);
2993 if (os_snprintf_error(sizeof(channel_util_file), res)) {
2994 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
2995 return RETURN_ERR;
2996 }
2997
developera3511852023-06-14 14:12:59 +08002998 f = fopen(channel_util_file, "r");
2999 if (f != NULL) {
3000 read = getline(&line, &len, f);
developer86035662023-06-28 19:21:12 +08003001 if (hal_strtoul(line, 10, &preActiveTime) < 0) {
3002 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +08003003 }
developera3511852023-06-14 14:12:59 +08003004 read = getline(&line, &len, f);
developer86035662023-06-28 19:21:12 +08003005 if (hal_strtoul(line, 10, &preBusyTime) < 0) {
3006 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerb6f05602023-06-30 11:32:41 +08003007
developer86035662023-06-28 19:21:12 +08003008 }
developera3511852023-06-14 14:12:59 +08003009 read = getline(&line, &len, f);
developer86035662023-06-28 19:21:12 +08003010 if (hal_strtoul(line, 10, &preTransmitTime) < 0) {
3011 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +08003012 }
developer5b23cd02023-07-19 20:26:03 +08003013
developerc14d83a2023-06-29 20:09:42 +08003014 if (fclose(f) == EOF)
3015 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
developer5b23cd02023-07-19 20:26:03 +08003016
developerc14d83a2023-06-29 20:09:42 +08003017 }
3018
developerb14b3462023-07-01 18:02:42 +08003019 /*if (ActiveTime == preActiveTime) {
developer5b23cd02023-07-19 20:26:03 +08003020 wifi_debug(DEBUG_ERROR, "error:ActiveTime[%d] == preActiveTime[%ld]\n",
developerb14b3462023-07-01 18:02:42 +08003021 ActiveTime, preActiveTime);
developerc14d83a2023-06-29 20:09:42 +08003022 return RETURN_ERR;
developerb14b3462023-07-01 18:02:42 +08003023 }*/
developer72fb0bb2023-01-11 09:46:29 +08003024
developera3511852023-06-14 14:12:59 +08003025 outputChannelStats2->ch_ObssUtil = (BusyTime - preBusyTime)*100/(ActiveTime - preActiveTime);
3026 outputChannelStats2->ch_SelfBssUtil = (TransmitTime - preTransmitTime)*100/(ActiveTime - preActiveTime);
developer72fb0bb2023-01-11 09:46:29 +08003027
developera3511852023-06-14 14:12:59 +08003028 f = fopen(channel_util_file, "w");
3029 if (f != NULL) {
developer86035662023-06-28 19:21:12 +08003030 if (fprintf(f, "%u\n%u\n%u\n", ActiveTime, BusyTime, TransmitTime) < 0) {
3031 wifi_debug(DEBUG_ERROR, "fprintf fail\n");
3032 }
3033 if (fclose(f) != 0) {
3034 wifi_debug(DEBUG_ERROR, "fclose fail\n");
3035 }
developera3511852023-06-14 14:12:59 +08003036 }
3037 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
3038 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003039}
3040
3041/**********************************************************************************
3042 *
3043 * Wifi radio level function prototypes
3044 *
3045**********************************************************************************/
3046
3047//Get the total number of radios in this wifi subsystem
3048INT wifi_getRadioNumberOfEntries(ULONG *output) //Tr181
3049{
developera3511852023-06-14 14:12:59 +08003050 if (NULL == output)
3051 return RETURN_ERR;
3052 *output = MAX_NUM_RADIOS;
developer72fb0bb2023-01-11 09:46:29 +08003053
developera3511852023-06-14 14:12:59 +08003054 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003055}
3056
developer69b61b02023-03-07 17:17:44 +08003057//Get the total number of SSID entries in this wifi subsystem
developer72fb0bb2023-01-11 09:46:29 +08003058INT wifi_getSSIDNumberOfEntries(ULONG *output) //Tr181
3059{
developera3511852023-06-14 14:12:59 +08003060 if (NULL == output)
3061 return RETURN_ERR;
3062 *output = MAX_APS;
developer72fb0bb2023-01-11 09:46:29 +08003063
developera3511852023-06-14 14:12:59 +08003064 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003065}
3066
3067//Get the Radio enable config parameter
developera3511852023-06-14 14:12:59 +08003068INT wifi_getRadioEnable(INT radioIndex, BOOL *output_bool) //RDKB
developer72fb0bb2023-01-11 09:46:29 +08003069{
developer56fbedb2023-05-30 16:47:05 +08003070 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +08003071 char buf[128] = {0};
developer56fbedb2023-05-30 16:47:05 +08003072 int apIndex;
3073 int max_radio_num = 0;
developer3a85ab82023-05-25 11:59:38 +08003074
developer56fbedb2023-05-30 16:47:05 +08003075 if (NULL == output_bool)
3076 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003077
developer56fbedb2023-05-30 16:47:05 +08003078 *output_bool = FALSE;
developer72fb0bb2023-01-11 09:46:29 +08003079
developer56fbedb2023-05-30 16:47:05 +08003080 wifi_getMaxRadioNumber(&max_radio_num);
developer72fb0bb2023-01-11 09:46:29 +08003081
developer56fbedb2023-05-30 16:47:05 +08003082 if (radioIndex >= max_radio_num)
3083 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003084
developer56fbedb2023-05-30 16:47:05 +08003085 /* loop all interface in radio, if any is enable, reture true, else return false */
3086 for(apIndex = radioIndex; apIndex < MAX_APS; apIndex += max_radio_num)
3087 {
3088 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
3089 continue;
developer8078acf2023-08-04 18:52:48 +08003090
developer8078acf2023-08-04 18:52:48 +08003091 *output_bool = _syscmd_secure(buf, sizeof(buf), "ifconfig %s 2> /dev/null | grep UP", interface_name) ? FALSE : TRUE;
developer56fbedb2023-05-30 16:47:05 +08003092 if (*output_bool == TRUE)
3093 break;
developer8078acf2023-08-04 18:52:48 +08003094
developer56fbedb2023-05-30 16:47:05 +08003095 }
3096
3097 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003098}
3099
developere82c0ca2023-05-10 16:25:35 +08003100typedef long time_t;
3101static time_t radio_up_time[MAX_NUM_RADIOS];
3102
developereef7d562023-10-21 16:04:21 +08003103enum mwctl_chan_width {
3104 MWCTL_CHAN_WIDTH_20,
3105 MWCTL_CHAN_WIDTH_40,
3106 MWCTL_CHAN_WIDTH_80,
3107 MWCTL_CHAN_WIDTH_160,
3108 MWCTL_CHAN_WIDTH_320,
3109};
3110
3111struct bw_option {
3112 unsigned int bandwith;
3113 enum mwctl_chan_width mode;
3114};
3115
3116struct bw_option bw_opt[] = {
3117 {20, MWCTL_CHAN_WIDTH_20},
3118 {40, MWCTL_CHAN_WIDTH_40},
3119 {80, MWCTL_CHAN_WIDTH_80},
3120 {160, MWCTL_CHAN_WIDTH_160},
3121 {320, MWCTL_CHAN_WIDTH_320},
3122};
3123
3124INT wifi_setChannel_netlink(INT radioIndex, ULONG* channel, UINT *bandwidth, UCHAR *ext_ch, UCHAR *ht_coex)
3125{
3126 int ret;
3127 int i;
3128 struct unl unl_ins;
3129 struct nl_msg *msg = NULL;
3130 struct nlattr * msg_data = NULL;
3131 struct mtk_nl80211_param param;
3132 bool b_match = FALSE;
3133
3134 /*init mtk nl80211 vendor cmd*/
3135 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_CHANNEL;
3136 param.if_type = NL80211_ATTR_WIPHY;
3137 param.if_idx = radio_index_to_phy(radioIndex);
3138
3139 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
3140 if (ret) {
3141 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
3142 return RETURN_ERR;
3143 }
3144
3145 /*add mtk vendor cmd data*/
3146 if (channel != NULL)
3147 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_CHAN_SET_NUM, *channel)) {
3148 wifi_debug(DEBUG_ERROR, "Nla put CHAN_SET_NUM attribute error\n");
3149 nlmsg_free(msg);
3150 goto err;
3151 }
3152
3153 if (bandwidth != NULL) {
3154 for (i = 0; i < (sizeof(bw_opt)/sizeof(bw_opt[0])); i++) {
3155 if (bw_opt[i].bandwith == *bandwidth) {
3156 b_match = true;
3157 if (nla_put_u32(msg, MTK_NL80211_VENDOR_ATTR_CHAN_SET_BW, bw_opt[i].mode)) {
3158 wifi_debug(DEBUG_ERROR, "Nla put CHAN_SET_BW attribute error\n");
3159 nlmsg_free(msg);
3160 goto err;
3161 }
3162 break;
3163 }
3164 }
3165
3166 if (!b_match) {
3167 wifi_debug(DEBUG_ERROR, "Cannot find bandwith error\n");
3168 nlmsg_free(msg);
3169 goto err;
3170 }
3171 }
3172
3173 if (ext_ch != NULL)
3174 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_CHAN_SET_HT_EXTCHAN, *ext_ch)) {
3175 wifi_debug(DEBUG_ERROR, "Nla put CHAN_SET_HT_EXTCHAN attribute error\n");
3176 nlmsg_free(msg);
3177 goto err;
3178 }
3179
3180 if (ht_coex != NULL)
3181 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_CHAN_SET_HT_COEX, *ht_coex)) {
3182 wifi_debug(DEBUG_ERROR, "Nla put CHAN_SET_HT_COEX attribute error\n");
3183 nlmsg_free(msg);
3184 goto err;
3185 }
3186
3187 /*send mtk nl80211 vendor msg*/
3188 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
3189 if (ret) {
3190 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
3191 goto err;
3192 }
3193 /*deinit mtk nl80211 vendor msg*/
3194 mtk_nl80211_deint(&unl_ins);
3195 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
3196 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
3197
3198 return RETURN_OK;
3199err:
3200 mtk_nl80211_deint(&unl_ins);
3201 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
3202 return RETURN_ERR;
3203}
3204
3205INT wifi_set80211h_netlink(INT radioIndex, unsigned char enable)
3206{
3207 int ret;
3208 struct unl unl_ins;
3209 struct nl_msg *msg = NULL;
3210 struct nlattr * msg_data = NULL;
3211 struct mtk_nl80211_param param;
3212
3213 /*init mtk nl80211 vendor cmd*/
3214 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_RADIO;
3215 param.if_type = NL80211_ATTR_WIPHY;
3216 param.if_idx = radio_index_to_phy(radioIndex);
3217
3218 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
3219 if (ret) {
3220 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
3221 return RETURN_ERR;
3222 }
3223
3224 /*add mtk vendor cmd data*/
3225 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_IEEE80211H_INFO, enable)) {
3226 wifi_debug(DEBUG_ERROR, "Nla put IEEE80211H_INFO attribute error\n");
3227 nlmsg_free(msg);
3228 goto err;
3229 }
3230
3231 /*send mtk nl80211 vendor msg*/
3232 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
3233 if (ret) {
3234 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
3235 goto err;
3236 }
3237 /*deinit mtk nl80211 vendor msg*/
3238 mtk_nl80211_deint(&unl_ins);
3239 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
3240 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
3241
3242 return RETURN_OK;
3243err:
3244 mtk_nl80211_deint(&unl_ins);
3245 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
3246 return RETURN_ERR;
3247}
3248
developer72fb0bb2023-01-11 09:46:29 +08003249INT wifi_setRadioEnable(INT radioIndex, BOOL enable)
3250{
developera3511852023-06-14 14:12:59 +08003251 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +08003252 char buf[MAX_BUF_SIZE] = {0};
3253 int apIndex;
3254 int max_radio_num = 0;
developere40952c2023-06-15 18:46:43 +08003255 int phyId = 0, res;
developer72fb0bb2023-01-11 09:46:29 +08003256
developera3511852023-06-14 14:12:59 +08003257 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08003258
developera3511852023-06-14 14:12:59 +08003259 phyId = radio_index_to_phy(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +08003260
developera3511852023-06-14 14:12:59 +08003261 wifi_getMaxRadioNumber(&max_radio_num);
developer72fb0bb2023-01-11 09:46:29 +08003262
developera3511852023-06-14 14:12:59 +08003263 if(enable == FALSE) {
developer47cc27a2023-05-17 23:09:58 +08003264
3265 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
3266 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08003267
developer8078acf2023-08-04 18:52:48 +08003268
3269 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw REMOVE %s", interface_name);
3270 if (res) {
3271 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003272 }
developer8078acf2023-08-04 18:52:48 +08003273 memset(buf, 0, MAX_BUF_SIZE);
developer47cc27a2023-05-17 23:09:58 +08003274
developer8078acf2023-08-04 18:52:48 +08003275 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
3276 if (res) {
3277 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003278 }
developer8078acf2023-08-04 18:52:48 +08003279
developere82c0ca2023-05-10 16:25:35 +08003280 if(strncmp(buf, "OK", 2))
developer75bd10c2023-06-27 11:34:08 +08003281 wifi_debug(DEBUG_ERROR, "Could not detach %s from hostapd daemon", interface_name);
developer8a3bbbf2023-03-15 17:47:23 +08003282 } else {
developere82c0ca2023-05-10 16:25:35 +08003283 for (apIndex = radioIndex; apIndex < MAX_APS; apIndex += max_radio_num) {
developera3511852023-06-14 14:12:59 +08003284 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
3285 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003286
developer8a3bbbf2023-03-15 17:47:23 +08003287 memset(buf, 0, MAX_BUF_SIZE);
3288
developer8078acf2023-08-04 18:52:48 +08003289
3290 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep %s | cut -d'=' -f2", VAP_STATUS_FILE, interface_name);
3291 if (res) {
3292 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003293 }
developer8a3bbbf2023-03-15 17:47:23 +08003294
developera3511852023-06-14 14:12:59 +08003295 if(*buf == '1') {
developer8078acf2023-08-04 18:52:48 +08003296 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up", interface_name);
3297 if (res) {
3298 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003299 }
developer8a3bbbf2023-03-15 17:47:23 +08003300
developer8a3bbbf2023-03-15 17:47:23 +08003301 memset(buf, 0, MAX_BUF_SIZE);
3302
developer8078acf2023-08-04 18:52:48 +08003303 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw ADD bss_config=phy%d:/nvram/hostapd%d.conf",phyId,apIndex);
3304 if (res) {
3305 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003306 }
developera3511852023-06-14 14:12:59 +08003307 }
3308 }
developere75ba632023-06-29 16:03:33 +08003309 if (time(&radio_up_time[radioIndex]) < 0) {
3310 wifi_debug(DEBUG_ERROR, "GET time fail\n");
3311 return RETURN_ERR;
3312 }
developera3511852023-06-14 14:12:59 +08003313 }
developer72fb0bb2023-01-11 09:46:29 +08003314
developera3511852023-06-14 14:12:59 +08003315 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
3316 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003317}
3318
3319//Get the Radio enable status
3320INT wifi_getRadioStatus(INT radioIndex, BOOL *output_bool) //RDKB
3321{
developera3511852023-06-14 14:12:59 +08003322 if (NULL == output_bool)
3323 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003324
developera3511852023-06-14 14:12:59 +08003325 return wifi_getRadioEnable(radioIndex, output_bool);
developer72fb0bb2023-01-11 09:46:29 +08003326}
3327
3328//Get the Radio Interface name from platform, eg "wlan0"
3329INT wifi_getRadioIfName(INT radioIndex, CHAR *output_string) //Tr181
3330{
developera3511852023-06-14 14:12:59 +08003331 if (NULL == output_string || radioIndex>=MAX_NUM_RADIOS || radioIndex<0)
3332 return RETURN_ERR;
3333 return wifi_GetInterfaceName(radioIndex, output_string);
developer72fb0bb2023-01-11 09:46:29 +08003334}
3335
developer6e578302023-06-21 10:11:16 +08003336int mtk_get_vow_info_callback(struct nl_msg *msg, void *data)
3337{
3338 struct nlattr *tb[NL80211_ATTR_MAX + 1];
3339 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_AP_VOW_ATTR_MAX + 1];
3340 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
3341 int err = 0;
3342 struct vow_info *vow_info = NULL;
3343 struct mtk_nl80211_cb_data *cb_data = data;
3344
3345 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
3346 genlmsg_attrlen(gnlh, 0), NULL);
3347 if (err < 0) {
3348 wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
3349 return err;
3350 }
3351
3352 if (tb[NL80211_ATTR_VENDOR_DATA]) {
3353 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_AP_VOW_ATTR_MAX,
3354 tb[NL80211_ATTR_VENDOR_DATA], NULL);
3355 if (err < 0){
3356 wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_AP_VOW_ATTR_MAX fails\n");
3357 return err;
3358 }
3359
3360 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO]) {
3361 vow_info = (struct vow_info *)nla_data(vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO]);
3362 memmove(cb_data->out_buf, vow_info, sizeof(struct vow_info));
3363 }
3364 }
3365
3366 return 0;
3367}
3368
3369INT mtk_wifi_set_air_time_management(
3370 INT apIndex, INT vendor_data_attr, mtk_nl80211_cb call_back,
3371 char* data, INT len, void *output)
3372{
3373 char inf_name[IF_NAME_SIZE] = {0};
3374 unsigned int if_idx = 0;
3375 int ret = -1;
3376 struct unl unl_ins;
3377 struct nl_msg *msg = NULL;
3378 struct nlattr * msg_data = NULL;
3379 struct mtk_nl80211_param param;
3380
3381 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
3382 return RETURN_ERR;
3383 if_idx = if_nametoindex(inf_name);
3384 if (!if_idx) {
3385 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
3386 return RETURN_ERR;
3387 }
3388 /*init mtk nl80211 vendor cmd*/
3389 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_VOW;
3390 param.if_type = NL80211_ATTR_IFINDEX;
3391 param.if_idx = if_idx;
3392
3393 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
3394 if (ret) {
3395 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
3396 return RETURN_ERR;
3397 }
3398 /*add mtk vendor cmd data*/
3399 if (nla_put(msg, vendor_data_attr, len, data)) {
3400 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", vendor_data_attr);
3401 nlmsg_free(msg);
3402 goto err;
3403 }
3404
3405 /*send mtk nl80211 vendor msg*/
3406 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, call_back, output);
3407 if (ret) {
3408 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
3409 goto err;
3410 }
3411 /*deinit mtk nl80211 vendor msg*/
3412 mtk_nl80211_deint(&unl_ins);
3413 wifi_debug(DEBUG_INFO, "send cmd success.\n");
3414
3415 return RETURN_OK;
3416err:
3417 mtk_nl80211_deint(&unl_ins);
3418 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
3419 return RETURN_ERR;
3420}
3421
3422//Get the ATM(Air Time Management) Capable.
3423INT wifi_getATMCapable(BOOL *output_bool)
3424{
3425 if (NULL == output_bool)
3426 return RETURN_ERR;
3427 *output_bool = TRUE;
3428
3429 return RETURN_OK;
3430}
3431
3432INT wifi_setATMEnable(BOOL enable)
3433{
3434 int max_radio_num = 0;
3435 int radio_idx = 0;
3436 char dat_file[MAX_BUF_SIZE] = {0};
3437 int res;
3438 struct params params[2];
3439
3440 wifi_getMaxRadioNumber(&max_radio_num);
3441 for (radio_idx = 0; radio_idx < max_radio_num; radio_idx++) {
3442 if (mtk_wifi_set_air_time_management
3443 (radio_idx, MTK_NL80211_VENDOR_ATTR_AP_VOW_ATF_EN_INFO,
3444 NULL, (char *)&enable, 1, NULL)!= RETURN_OK) {
3445 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_ATF_EN_INFO cmd fails\n");
3446 return RETURN_ERR;
3447 }
3448
3449 if (mtk_wifi_set_air_time_management
3450 (radio_idx, MTK_NL80211_VENDOR_ATTR_AP_VOW_BW_EN_INFO,
3451 NULL, (char *)&enable, 1, NULL)!= RETURN_OK) {
3452 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_ATF_EN_INFO cmd fails\n");
3453 return RETURN_ERR;
3454 }
3455
3456 params[0].name = "VOW_Airtime_Fairness_En";
3457 params[0].value = enable ? "1" : "0";
3458 params[1].name = "VOW_BW_Ctrl";
3459 params[1].value = enable ? "1" : "0";
3460
3461 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, radio_idx);
3462 if (os_snprintf_error(sizeof(dat_file), res)) {
3463 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3464 return RETURN_ERR;
3465 }
3466 wifi_datfileWrite(dat_file, params, 2);
3467 }
3468
3469 return RETURN_OK;
3470}
3471
3472INT wifi_getATMEnable(BOOL *output_enable)
3473{
3474 int max_radio_num = 0;
3475 int radio_idx = 0;
3476 struct vow_info vow_info;
3477 struct vow_info get_vow_info;
3478 struct mtk_nl80211_cb_data cb_data;
3479
3480 if (output_enable == NULL)
3481 return RETURN_ERR;
3482
3483 wifi_getMaxRadioNumber(&max_radio_num);
3484
3485 *output_enable = FALSE;
3486
3487 memset(&vow_info, 0, sizeof(struct vow_info));
3488
3489 cb_data.out_buf = (char *)&vow_info;
3490 cb_data.out_len = sizeof(struct vow_info);
3491
3492 for (radio_idx = 0; radio_idx < max_radio_num; radio_idx++) {
3493 if (mtk_wifi_set_air_time_management
3494 (radio_idx, MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO,
3495 mtk_get_vow_info_callback, (char *)&get_vow_info, sizeof(struct vow_info), &cb_data)!= RETURN_OK) {
3496 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO cmd fails\n");
3497 return RETURN_ERR;
3498 }
3499
3500 if (vow_info.atf_en == TRUE || vow_info.bw_en == TRUE) {
3501 *output_enable = TRUE;
3502 break;
3503 }
3504 }
3505
3506 return RETURN_OK;
3507}
3508
3509UINT apidx_to_group(INT apIndex)
3510{
3511 int max_radio_num = 0;
3512 unsigned int group = 0;
3513
3514 wifi_getMaxRadioNumber(&max_radio_num);
developerc14d83a2023-06-29 20:09:42 +08003515 if (max_radio_num == 0) {
3516 wifi_debug(DEBUG_ERROR, "invalid max radio num\n");
3517 return 0;
3518 }
developer6e578302023-06-21 10:11:16 +08003519 group = apIndex / max_radio_num + 5 * (apIndex % max_radio_num);
3520
3521 return group;
3522}
3523
3524INT wifi_setApATMAirTimePercent(INT apIndex, UINT ap_AirTimePercent)
3525{
3526 struct vow_group_en_param atc_en_param;
3527 struct vow_ratio_param radio_param;
3528 unsigned int group = 0;
3529 //BOOL ATM_enable = FALSE;
3530
3531 if (ap_AirTimePercent < 5 || ap_AirTimePercent > 100) {
3532 wifi_debug(DEBUG_ERROR, "invalid ait time percent!\n");
3533 return RETURN_ERR;
3534 }
3535
3536 /* mt7990 support 15 group now*/
3537 group = apidx_to_group(apIndex);
3538
3539 if (group > 15) {
3540 wifi_debug(DEBUG_ERROR, "invalid group!\n");
3541 return RETURN_ERR;
3542 }
3543
3544 atc_en_param.group = group;
3545 atc_en_param.en = 1;
3546 if (mtk_wifi_set_air_time_management
3547 (apIndex, MTK_NL80211_VENDOR_ATTR_AP_VOW_ATC_EN_INFO,
3548 NULL, (char *)&atc_en_param, sizeof(struct vow_group_en_param), NULL)!= RETURN_OK) {
3549 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_ATC_EN_INFO cmd fails\n");
3550 return RETURN_ERR;
3551 }
3552
3553 radio_param.group = group;
3554 radio_param.ratio = ap_AirTimePercent;
3555 if (mtk_wifi_set_air_time_management
3556 (apIndex, MTK_NL80211_VENDOR_ATTR_AP_VOW_MIN_RATIO_INFO,
3557 NULL, (char *)&radio_param, sizeof(struct vow_ratio_param), NULL)!= RETURN_OK) {
3558 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_MIN_RATIO_INFO cmd fails\n");
3559 return RETURN_ERR;
3560 }
3561
3562 if (mtk_wifi_set_air_time_management
3563 (apIndex, MTK_NL80211_VENDOR_ATTR_AP_VOW_MAX_RATIO_INFO,
3564 NULL, (char *)&radio_param, sizeof(struct vow_ratio_param), NULL)!= RETURN_OK) {
3565 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_MAX_RATIO_INFO cmd fails\n");
3566 return RETURN_ERR;
3567 }
3568
3569 return RETURN_OK;
3570}
3571
3572INT wifi_getApATMAirTimePercent(INT apIndex, UINT *output_ap_AirTimePercent)
3573{
3574 unsigned int group = 0;
3575 struct vow_info get_vow_info, vow_info;
3576 struct mtk_nl80211_cb_data cb_data;
3577
3578 if (output_ap_AirTimePercent == NULL)
3579 return RETURN_ERR;
3580
3581 group = apidx_to_group(apIndex);
3582 if (group > 15) {
3583 wifi_debug(DEBUG_ERROR, "invalid group!\n");
3584 return RETURN_ERR;
3585 }
3586
3587 memset(&vow_info, 0, sizeof(struct vow_info));
3588 memset(&get_vow_info, 0, sizeof(struct vow_info));
3589
3590 cb_data.out_buf = (char *)&vow_info;
3591 cb_data.out_len = sizeof(struct vow_info);
3592
3593 get_vow_info.group = group;
3594
3595 if (mtk_wifi_set_air_time_management
3596 (apIndex, MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO,
3597 mtk_get_vow_info_callback, (char *)&get_vow_info, sizeof(struct vow_info), &cb_data)!= RETURN_OK) {
3598 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO cmd fails\n");
3599 return RETURN_ERR;
3600 }
3601
3602 *output_ap_AirTimePercent = vow_info.ratio;
3603
3604 return RETURN_ERR;
3605}
3606
developerd14dff12023-06-28 22:47:44 +08003607INT wifi_getApATMSta(INT apIndex, UCHAR *output_sta_MAC_ATM_array, UINT buf_size)
3608{
3609 ULONG dev_num = 0;
3610 struct vow_info vow_info;
3611 struct vow_info get_vow_info;
3612 struct mtk_nl80211_cb_data cb_data;
3613 unsigned int percent;
3614 char assocArray[MAX_BUF_SIZE] = {0};
3615 char *mac = NULL;
3616 unsigned char output_len = 0;
3617 int res;
3618 char buf[MAX_BUF_SIZE] = {0};
3619
3620 memset(&vow_info, 0, sizeof(struct vow_info));
3621 memset(&get_vow_info, 0, sizeof(struct vow_info));
3622
3623 cb_data.out_buf = (char *)&vow_info;
3624 cb_data.out_len = sizeof(struct vow_info);
3625
3626 if (mtk_wifi_set_air_time_management
3627 (apIndex, MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO,
3628 mtk_get_vow_info_callback, (char *)&get_vow_info, sizeof(struct vow_info), &cb_data)!= RETURN_OK) {
3629 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO cmd fails\n");
3630 return RETURN_ERR;
3631 }
3632
3633 if (vow_info.atf_en == FALSE) {
3634 wifi_debug(DEBUG_ERROR, "ATF disable!\n");
3635 return RETURN_ERR;
3636 }
3637
3638 if (wifi_getApNumDevicesAssociated(apIndex, &dev_num) != RETURN_OK) {
3639 wifi_debug(DEBUG_ERROR, "get sta num fail!\n");
3640 return RETURN_ERR;;
3641 }
3642
3643 percent = 100 / dev_num;
3644
3645 if (wifi_getApDevicesAssociated(apIndex, assocArray, sizeof(assocArray)) != RETURN_OK){
3646 wifi_debug(DEBUG_ERROR, "get sta mac fail!\n");
3647 return RETURN_ERR;;
3648 }
3649
3650 memset(output_sta_MAC_ATM_array, 0, MAX_BUF_SIZE);
3651
3652 mac = strtok(assocArray, "\n");
3653 while (mac != NULL) {
3654 if (strlen(mac) >= 17) {
3655 res = snprintf(buf, sizeof(buf), "%s %d|", mac, percent);
3656
3657 if (os_snprintf_error(sizeof(buf), res)) {
3658 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3659 return RETURN_ERR;
3660 }
3661
3662 if (output_len + strlen(buf) > buf_size)
3663 break;
3664
3665 strncat((char *)output_sta_MAC_ATM_array, buf, strlen(buf));
3666
3667 output_len += strlen(buf);
3668 }
3669
3670 mac = strtok(NULL, "\n");
3671 }
3672
3673 /* Remove the last | */
3674 if (strlen((char *)output_sta_MAC_ATM_array) != 0)
3675 output_sta_MAC_ATM_array[strlen((char *)output_sta_MAC_ATM_array)-1] = '\0';
3676
3677 return RETURN_OK;
3678}
3679
3680INT wifi_setApATMSta(INT apIndex, UCHAR *sta_MAC_ATM_array, UINT ap_AirTimePercent)
3681{
3682 return RETURN_ERR;
3683}
developer9ce44382023-06-28 11:09:37 +08003684
developer72fb0bb2023-01-11 09:46:29 +08003685//Get the maximum PHY bit rate supported by this interface. eg: "216.7 Mb/s", "1.3 Gb/s"
3686//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
3687INT wifi_getRadioMaxBitRate(INT radioIndex, CHAR *output_string) //RDKB
3688{
developera3511852023-06-14 14:12:59 +08003689 // The formula to coculate bit rate is "Subcarriers * Modulation * Coding rate * Spatial stream / (Data interval + Guard interval)"
3690 // For max bit rate, we should always choose the best MCS
3691 char mode[64] = {0};
3692 char channel_bandwidth_str[64] = {0};
3693 UINT mode_map = 0;
3694 UINT num_subcarrier = 0;
3695 UINT code_bits = 0;
3696 float code_rate = 0; // use max code rate
3697 int NSS = 0;
3698 UINT Symbol_duration = 0;
3699 UINT GI_duration = 0;
3700 wifi_guard_interval_t gi = wifi_guard_interval_auto;
3701 BOOL enable = FALSE;
3702 float bit_rate = 0;
developere40952c2023-06-15 18:46:43 +08003703 int ant_bitmap = 0, res;
developer72fb0bb2023-01-11 09:46:29 +08003704
developera3511852023-06-14 14:12:59 +08003705 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
3706 if (NULL == output_string)
3707 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003708
developera3511852023-06-14 14:12:59 +08003709 wifi_getRadioEnable(radioIndex, &enable);
3710 if (enable == FALSE) {
developere40952c2023-06-15 18:46:43 +08003711 res = snprintf(output_string, 64, "0 Mb/s");
3712 if (os_snprintf_error(64, res)) {
3713 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3714 return RETURN_ERR;
3715 }
developera3511852023-06-14 14:12:59 +08003716 return RETURN_OK;
3717 }
developer72fb0bb2023-01-11 09:46:29 +08003718
developera3511852023-06-14 14:12:59 +08003719 if (wifi_getRadioMode(radioIndex, mode, &mode_map) == RETURN_ERR) {
developer75bd10c2023-06-27 11:34:08 +08003720 wifi_debug(DEBUG_ERROR, "wifi_getRadioMode return error.\n");
developera3511852023-06-14 14:12:59 +08003721 return RETURN_ERR;
3722 }
developer72fb0bb2023-01-11 09:46:29 +08003723
developera3511852023-06-14 14:12:59 +08003724 if (wifi_getGuardInterval(radioIndex, &gi) == RETURN_ERR) {
developer75bd10c2023-06-27 11:34:08 +08003725 wifi_debug(DEBUG_ERROR, "wifi_getGuardInterval return error.\n");
developera3511852023-06-14 14:12:59 +08003726 return RETURN_ERR;
3727 }
developer72fb0bb2023-01-11 09:46:29 +08003728
developera3511852023-06-14 14:12:59 +08003729 if (gi == wifi_guard_interval_3200)
3730 GI_duration = 32;
3731 else if (gi == wifi_guard_interval_1600)
3732 GI_duration = 16;
3733 else if (gi == wifi_guard_interval_800)
3734 GI_duration = 8;
3735 else // auto, 400
3736 GI_duration = 4;
developer72fb0bb2023-01-11 09:46:29 +08003737
developera3511852023-06-14 14:12:59 +08003738 if (wifi_getRadioOperatingChannelBandwidth(radioIndex, channel_bandwidth_str) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +08003739 wifi_debug(DEBUG_ERROR, "wifi_getRadioOperatingChannelBandwidth return error\n");
developera3511852023-06-14 14:12:59 +08003740 return RETURN_ERR;
3741 }
developer72fb0bb2023-01-11 09:46:29 +08003742
developera3511852023-06-14 14:12:59 +08003743 if (strstr(channel_bandwidth_str, "80+80") != NULL)
developer32f2a182023-06-27 19:50:41 +08003744 memcpy(channel_bandwidth_str, "160", strlen("160"));
developer72fb0bb2023-01-11 09:46:29 +08003745
developera3511852023-06-14 14:12:59 +08003746 if (mode_map & WIFI_MODE_AX) {
3747 if (strstr(channel_bandwidth_str, "160") != NULL)
3748 num_subcarrier = 1960;
3749 else if (strstr(channel_bandwidth_str, "80") != NULL)
3750 num_subcarrier = 980;
3751 else if (strstr(channel_bandwidth_str, "40") != NULL)
3752 num_subcarrier = 468;
3753 else if (strstr(channel_bandwidth_str, "20") != NULL)
3754 num_subcarrier = 234;
3755 code_bits = 10;
3756 code_rate = (float)5/6;
3757 Symbol_duration = 128;
3758 GI_duration = 8;/*HE no GI 400ns*/
3759 } else if (mode_map & WIFI_MODE_AC) {
3760 if (strstr(channel_bandwidth_str, "160") != NULL)
3761 num_subcarrier = 468;
3762 else if (strstr(channel_bandwidth_str, "80") != NULL)
3763 num_subcarrier = 234;
3764 else if (strstr(channel_bandwidth_str, "40") != NULL)
3765 num_subcarrier = 108;
3766 else if (strstr(channel_bandwidth_str, "20") != NULL)
3767 num_subcarrier = 52;
3768 code_bits = 8;
3769 code_rate = (float)5/6;
3770 Symbol_duration = 32;
3771 } else if (mode_map & WIFI_MODE_N) {
3772 if (strstr(channel_bandwidth_str, "160") != NULL)
3773 num_subcarrier = 468;
3774 else if (strstr(channel_bandwidth_str, "80") != NULL)
3775 num_subcarrier = 234;
3776 else if (strstr(channel_bandwidth_str, "40") != NULL)
3777 num_subcarrier = 108;
3778 else if (strstr(channel_bandwidth_str, "20") != NULL)
3779 num_subcarrier = 52;
3780 code_bits = 6;
3781 code_rate = (float)3/4;
3782 Symbol_duration = 32;
3783 } else if ((mode_map & WIFI_MODE_G || mode_map & WIFI_MODE_B) || mode_map & WIFI_MODE_A) {
3784 // mode b must run with mode g, so we output mode g bitrate in 2.4 G.
developere40952c2023-06-15 18:46:43 +08003785 res = snprintf(output_string, 64, "65 Mb/s");
3786 if (os_snprintf_error(64, res)) {
3787 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3788 return RETURN_ERR;
3789 }
developera3511852023-06-14 14:12:59 +08003790 return RETURN_OK;
3791 } else {
developere40952c2023-06-15 18:46:43 +08003792 res = snprintf(output_string, 64, "0 Mb/s");
3793 if (os_snprintf_error(64, res)) {
3794 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3795 return RETURN_ERR;
3796 }
developera3511852023-06-14 14:12:59 +08003797 return RETURN_OK;
3798 }
developer72fb0bb2023-01-11 09:46:29 +08003799
developera3511852023-06-14 14:12:59 +08003800 // Spatial streams
3801 if (wifi_getRadioTxChainMask(radioIndex, &ant_bitmap) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +08003802 wifi_debug(DEBUG_ERROR, "wifi_getRadioTxChainMask return error\n");
developera3511852023-06-14 14:12:59 +08003803 return RETURN_ERR;
3804 }
3805 for (; ant_bitmap > 0; ant_bitmap >>= 1)
3806 NSS += ant_bitmap & 1;
developer72fb0bb2023-01-11 09:46:29 +08003807
developera3511852023-06-14 14:12:59 +08003808 // multiple 10 is to align duration unit (0.1 us)
3809 bit_rate = (num_subcarrier * code_bits * code_rate * NSS) / (Symbol_duration + GI_duration) * 10;
developere40952c2023-06-15 18:46:43 +08003810 res = snprintf(output_string, 64, "%.1f Mb/s", bit_rate);
3811 if (os_snprintf_error(64, res)) {
3812 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3813 return RETURN_ERR;
3814 }
developera3511852023-06-14 14:12:59 +08003815 WIFI_ENTRY_EXIT_DEBUG("%s:num_subcarrier=%d, code_bits=%d, code_rate=%.3f, nss=%d, symbol time=%u, %.1f Mb/s\n",
3816 __func__, num_subcarrier, code_bits, code_rate, NSS, Symbol_duration + GI_duration, bit_rate);
3817 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08003818
developera3511852023-06-14 14:12:59 +08003819 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003820}
developer72fb0bb2023-01-11 09:46:29 +08003821
3822//Get Supported frequency bands at which the radio can operate. eg: "2.4GHz,5GHz"
3823//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
3824INT wifi_getRadioSupportedFrequencyBands(INT radioIndex, CHAR *output_string) //RDKB
3825{
developera3511852023-06-14 14:12:59 +08003826 wifi_band band = band_invalid;
developer72fb0bb2023-01-11 09:46:29 +08003827
developera3511852023-06-14 14:12:59 +08003828 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
3829 if (NULL == output_string)
3830 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003831
developera3511852023-06-14 14:12:59 +08003832 band = wifi_index_to_band(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +08003833
developera3511852023-06-14 14:12:59 +08003834 memset(output_string, 0, 10);
3835 if (band == band_2_4)
developer32f2a182023-06-27 19:50:41 +08003836 memcpy(output_string, "2.4GHz", strlen("2.4GHz"));
developera3511852023-06-14 14:12:59 +08003837 else if (band == band_5)
developer32f2a182023-06-27 19:50:41 +08003838 memcpy(output_string, "5GHz", strlen("5GHz"));
developera3511852023-06-14 14:12:59 +08003839 else if (band == band_6)
developer32f2a182023-06-27 19:50:41 +08003840 memcpy(output_string, "6GHz", strlen("6GHz"));
developera3511852023-06-14 14:12:59 +08003841 else
3842 return RETURN_ERR;
3843 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08003844
developera3511852023-06-14 14:12:59 +08003845 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003846}
3847
3848//Get the frequency band at which the radio is operating, eg: "2.4GHz"
3849//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
3850INT wifi_getRadioOperatingFrequencyBand(INT radioIndex, CHAR *output_string) //Tr181
3851{
developera3511852023-06-14 14:12:59 +08003852 wifi_band band = band_invalid;
developer9ce44382023-06-28 11:09:37 +08003853 int res = -1;
developere40952c2023-06-15 18:46:43 +08003854
developera3511852023-06-14 14:12:59 +08003855 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
3856 if (NULL == output_string)
3857 return RETURN_ERR;
3858 band = wifi_index_to_band(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +08003859
developera3511852023-06-14 14:12:59 +08003860 if (band == band_2_4)
developere40952c2023-06-15 18:46:43 +08003861 res = snprintf(output_string, 64, "2.4GHz");
developera3511852023-06-14 14:12:59 +08003862 else if (band == band_5)
developere40952c2023-06-15 18:46:43 +08003863 res = snprintf(output_string, 64, "5GHz");
developera3511852023-06-14 14:12:59 +08003864 else if (band == band_6)
developere40952c2023-06-15 18:46:43 +08003865 res = snprintf(output_string, 64, "6GHz");
developer72fb0bb2023-01-11 09:46:29 +08003866
developere40952c2023-06-15 18:46:43 +08003867 if (os_snprintf_error(64, res)) {
3868 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3869 return RETURN_ERR;
3870 }
developera3511852023-06-14 14:12:59 +08003871 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08003872
developera3511852023-06-14 14:12:59 +08003873 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003874}
3875
3876//Get the Supported Radio Mode. eg: "b,g,n"; "n,ac"
3877//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
3878INT wifi_getRadioSupportedStandards(INT radioIndex, CHAR *output_string) //Tr181
3879{
developera3511852023-06-14 14:12:59 +08003880 char buf[128]={0};
3881 char temp_output[128] = {0};
3882 wifi_band band;
developere40952c2023-06-15 18:46:43 +08003883 int phyId = 0, res;
developer72fb0bb2023-01-11 09:46:29 +08003884
developera3511852023-06-14 14:12:59 +08003885 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
3886 if (NULL == output_string)
3887 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003888
developera3511852023-06-14 14:12:59 +08003889 band = wifi_index_to_band(radioIndex);
3890 if (band == band_2_4) {
developer32f2a182023-06-27 19:50:41 +08003891 strncat(temp_output, "b,g,", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08003892 } else if (band == band_5) {
developer32f2a182023-06-27 19:50:41 +08003893 strncat(temp_output, "a,", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08003894 }
3895 phyId = radio_index_to_phy(radioIndex);
3896 // ht capabilities
developer8078acf2023-08-04 18:52:48 +08003897
3898 res = _syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep '[^PHY|MAC|VHT].Capabilities' | head -n 1 | cut -d ':' -f2 | sed 's/^.//' | tr -d '\\n'", phyId);
3899 if (res) {
3900 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003901 }
developer8078acf2023-08-04 18:52:48 +08003902
developera3511852023-06-14 14:12:59 +08003903 if (strlen(buf) >= 4 && strncmp(buf, "0x00", 4) != 0) {
developer32f2a182023-06-27 19:50:41 +08003904 if (strlen(temp_output) >= sizeof(temp_output) - 2)
3905 return RETURN_ERR;
3906 strncat(temp_output, "n,", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08003907 }
developer72fb0bb2023-01-11 09:46:29 +08003908
developera3511852023-06-14 14:12:59 +08003909 // vht capabilities
3910 if (band == band_5) {
developer8078acf2023-08-04 18:52:48 +08003911 res = _syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep 'VHT Capabilities' | cut -d '(' -f2 | cut -c1-10 | tr -d '\\n'", phyId);
3912 if (res) {
3913 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003914 }
developere40952c2023-06-15 18:46:43 +08003915 if (strlen(buf) >= 10 && strncmp(buf, "0x00000000", 10) != 0) {
developer32f2a182023-06-27 19:50:41 +08003916 if (strlen(temp_output) >= sizeof(temp_output) - 3)
3917 return RETURN_ERR;
developerc14d83a2023-06-29 20:09:42 +08003918 strncat(temp_output, "ac,", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08003919 }
3920 }
developer72fb0bb2023-01-11 09:46:29 +08003921
developera3511852023-06-14 14:12:59 +08003922 // he capabilities
developer8078acf2023-08-04 18:52:48 +08003923 res = _syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep 'HE MAC Capabilities' | head -n 2 | tail -n 1 | cut -d '(' -f2 | cut -c1-6 | tr -d '\\n'", phyId);
3924 if (res) {
3925 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003926 }
developer8078acf2023-08-04 18:52:48 +08003927
developera3511852023-06-14 14:12:59 +08003928 if (strlen(buf) >= 6 && strncmp (buf, "0x0000", 6) != 0) {
developer32f2a182023-06-27 19:50:41 +08003929 if (strlen(temp_output) >= sizeof(temp_output) - 3)
3930 return RETURN_ERR;
3931 strncat(temp_output, "ax,", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08003932 }
developer72fb0bb2023-01-11 09:46:29 +08003933
developere82c0ca2023-05-10 16:25:35 +08003934 // eht capabilities
developer8078acf2023-08-04 18:52:48 +08003935 res = _syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep 'EHT MAC Capabilities' | head -n 2 | tail -n 1 | cut -d '(' -f2 | cut -c1-6 | tr -d '\\n'", phyId);
3936 if (res) {
3937 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08003938 }
developer8078acf2023-08-04 18:52:48 +08003939
developera3511852023-06-14 14:12:59 +08003940 if (strlen(buf) >= 6 && strncmp (buf, "0x0000", 6) != 0) {
developer32f2a182023-06-27 19:50:41 +08003941 if (strlen(temp_output) >= sizeof(temp_output) - 3)
3942 return RETURN_ERR;
3943 strncat(temp_output, "be,", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08003944 }
developere82c0ca2023-05-10 16:25:35 +08003945
developera3511852023-06-14 14:12:59 +08003946 // Remove the last comma
3947 if (strlen(temp_output) != 0)
3948 temp_output[strlen(temp_output)-1] = '\0';
3949 strncpy(output_string, temp_output, strlen(temp_output));
3950 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
3951 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003952}
3953
3954//Get the radio operating mode, and pure mode flag. eg: "ac"
3955//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
3956INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL *nOnly, BOOL *acOnly) //RDKB
3957{
developere40952c2023-06-15 18:46:43 +08003958 int res;
3959
developera3511852023-06-14 14:12:59 +08003960 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
3961 if (NULL == output_string)
3962 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08003963
developera3511852023-06-14 14:12:59 +08003964 if (radioIndex == 0) {
developere40952c2023-06-15 18:46:43 +08003965 res = snprintf(output_string, 64, "n"); //"ht" needs to be translated to "n" or others
3966 if (os_snprintf_error(64, res)) {
3967 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3968 return RETURN_ERR;
3969 }
developera3511852023-06-14 14:12:59 +08003970 *gOnly = FALSE;
3971 *nOnly = TRUE;
3972 *acOnly = FALSE;
3973 } else {
developere40952c2023-06-15 18:46:43 +08003974 res = snprintf(output_string, 64, "ac"); //"vht" needs to be translated to "ac"
3975 if (os_snprintf_error(64, res)) {
3976 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
3977 return RETURN_ERR;
3978 }
developera3511852023-06-14 14:12:59 +08003979 *gOnly = FALSE;
3980 *nOnly = FALSE;
3981 *acOnly = FALSE;
3982 }
3983 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08003984
developera3511852023-06-14 14:12:59 +08003985 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08003986}
3987
developer0f10c772023-05-16 21:43:39 +08003988enum WIFI_MODE {
3989 WMODE_INVALID = 0,
3990 WMODE_A = 1 << 0,
3991 WMODE_B = 1 << 1,
3992 WMODE_G = 1 << 2,
3993 WMODE_GN = 1 << 3,
3994 WMODE_AN = 1 << 4,
3995 WMODE_AC = 1 << 5,
3996 WMODE_AX_24G = 1 << 6,
3997 WMODE_AX_5G = 1 << 7,
3998 WMODE_AX_6G = 1 << 8,
3999 WMODE_BE_24G = 1 << 9,
4000 WMODE_BE_5G = 1 << 10,
4001 WMODE_BE_6G = 1 << 11,
4002 /*
4003 * total types of supported wireless mode,
4004 * add this value once yow add new type
4005 */
4006 WMODE_COMP = 12,
4007};
4008
4009#define RADIO_MODE_LEN 32
developerfead3972023-05-25 20:15:02 +08004010
4011int get_radio_mode_handler(struct nl_msg *msg, void *cb)
developer72fb0bb2023-01-11 09:46:29 +08004012{
developerfead3972023-05-25 20:15:02 +08004013 struct nlattr *tb[NL80211_ATTR_MAX + 1];
4014 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_MAX + 1];
developerc14d83a2023-06-29 20:09:42 +08004015 struct genlmsghdr *gnlh;
developerfead3972023-05-25 20:15:02 +08004016 unsigned int *phymode;
4017 int err = 0;
4018 struct mtk_nl80211_cb_data *cb_data = cb;
developer72fb0bb2023-01-11 09:46:29 +08004019
developerfead3972023-05-25 20:15:02 +08004020 if (!msg || !cb_data) {
developerdaf24792023-06-06 11:40:04 +08004021 wifi_debug(DEBUG_ERROR, "msg(%p) or cb_data(%p) is null,error.\n", msg, cb_data);
developerfead3972023-05-25 20:15:02 +08004022 return NL_SKIP;
4023 }
developerc14d83a2023-06-29 20:09:42 +08004024 gnlh = nlmsg_data(nlmsg_hdr(msg));
developer72fb0bb2023-01-11 09:46:29 +08004025
developerfead3972023-05-25 20:15:02 +08004026 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
4027 genlmsg_attrlen(gnlh, 0), NULL);
4028 if (err < 0) {
4029 wifi_debug(DEBUG_ERROR, "nla_parse radio nl80211 msg fails,error.\n");
4030 return NL_SKIP;
4031 }
developer0f10c772023-05-16 21:43:39 +08004032
developerfead3972023-05-25 20:15:02 +08004033 if (tb[NL80211_ATTR_VENDOR_DATA]) {
4034 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_MAX,
4035 tb[NL80211_ATTR_VENDOR_DATA], NULL);
4036 if (err < 0)
4037 return NL_SKIP;
developer72fb0bb2023-01-11 09:46:29 +08004038
developerfead3972023-05-25 20:15:02 +08004039 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_WMODE]) {
4040 phymode = (unsigned int *)nla_data(vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_WMODE]);
4041
4042 memset(cb_data->out_buf, 0, cb_data->out_len);
4043 memmove(cb_data->out_buf, phymode, sizeof(unsigned int));
4044 }
4045 } else
4046 wifi_debug(DEBUG_ERROR, "No Stats from driver.\n");
4047
4048 return NL_OK;
4049}
developer0f10c772023-05-16 21:43:39 +08004050
developerfead3972023-05-25 20:15:02 +08004051void phymode_to_puremode(INT radioIndex, CHAR *output_string, UINT *pureMode, UINT phymode)
4052{
4053 wifi_band band;
4054 unsigned char radio_mode_tem_len;
developere40952c2023-06-15 18:46:43 +08004055 int res;
developerfead3972023-05-25 20:15:02 +08004056
4057 band = wifi_index_to_band(radioIndex);
developer0f10c772023-05-16 21:43:39 +08004058 // puremode is a bit map
developera3511852023-06-14 14:12:59 +08004059 *pureMode = 0;
developer0f10c772023-05-16 21:43:39 +08004060 memset(output_string, 0, RADIO_MODE_LEN);
4061
4062 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4063
4064 switch (band) {
4065 case band_2_4:
4066 if (phymode & WMODE_B) {
developere40952c2023-06-15 18:46:43 +08004067 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "b,");
4068 if (os_snprintf_error(radio_mode_tem_len, res)) {
4069 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4070 return;
4071 }
developer0f10c772023-05-16 21:43:39 +08004072 *pureMode |= WIFI_MODE_B;
4073 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4074 }
4075 if (phymode & WMODE_G) {
developere40952c2023-06-15 18:46:43 +08004076 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "g,");
4077 if (os_snprintf_error(radio_mode_tem_len, res)) {
4078 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4079 return;
4080 }
developer0f10c772023-05-16 21:43:39 +08004081 *pureMode |= WIFI_MODE_G;
4082 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4083 }
4084 if (phymode & WMODE_GN) {
developere40952c2023-06-15 18:46:43 +08004085 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "n,");
4086 if (os_snprintf_error(radio_mode_tem_len, res)) {
4087 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4088 return;
4089 }
developer0f10c772023-05-16 21:43:39 +08004090 *pureMode |= WIFI_MODE_N;
4091 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4092 }
4093 if (phymode & WMODE_AX_24G) {
developere40952c2023-06-15 18:46:43 +08004094 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "ax,");
4095 if (os_snprintf_error(radio_mode_tem_len, res)) {
4096 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4097 return;
4098 }
developer0f10c772023-05-16 21:43:39 +08004099 *pureMode |= WIFI_MODE_AX;
4100 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4101 }
4102 if (phymode & WMODE_BE_24G) {
developere40952c2023-06-15 18:46:43 +08004103 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "be,");
4104 if (os_snprintf_error(radio_mode_tem_len, res)) {
4105 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4106 return;
4107 }
developer0f10c772023-05-16 21:43:39 +08004108 *pureMode |= WIFI_MODE_BE;
4109 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4110 }
4111 break;
4112 case band_5:
4113 if (phymode & WMODE_A) {
developere40952c2023-06-15 18:46:43 +08004114 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "a,");
4115 if (os_snprintf_error(radio_mode_tem_len, res)) {
4116 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4117 return;
4118 }
developer0f10c772023-05-16 21:43:39 +08004119 *pureMode |= WIFI_MODE_A;
4120 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4121 }
4122 if (phymode & WMODE_AN) {
developere40952c2023-06-15 18:46:43 +08004123 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "n,");
4124 if (os_snprintf_error(radio_mode_tem_len, res)) {
4125 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4126 return;
4127 }
developer0f10c772023-05-16 21:43:39 +08004128 *pureMode |= WIFI_MODE_N;
4129 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4130 }
4131 if (phymode & WMODE_AC) {
developere40952c2023-06-15 18:46:43 +08004132 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "ac,");
4133 if (os_snprintf_error(radio_mode_tem_len, res)) {
4134 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4135 return;
4136 }
developer0f10c772023-05-16 21:43:39 +08004137 *pureMode |= WIFI_MODE_AC;
4138 }
4139 if (phymode & WMODE_AX_5G) {
developere40952c2023-06-15 18:46:43 +08004140 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "ax,");
4141 if (os_snprintf_error(radio_mode_tem_len, res)) {
4142 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4143 return;
4144 }
developer0f10c772023-05-16 21:43:39 +08004145 *pureMode |= WIFI_MODE_AX;
4146 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4147 }
4148 if (phymode & WMODE_BE_5G) {
developere40952c2023-06-15 18:46:43 +08004149 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "be,");
4150 if (os_snprintf_error(radio_mode_tem_len, res)) {
4151 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4152 return;
4153 }
developer0f10c772023-05-16 21:43:39 +08004154 *pureMode |= WIFI_MODE_BE;
4155 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4156 }
4157 break;
4158 case band_6:
4159 if (phymode & WMODE_AX_6G) {
developere40952c2023-06-15 18:46:43 +08004160 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "ax,");
4161 if (os_snprintf_error(radio_mode_tem_len, res)) {
4162 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4163 return;
4164 }
developer0f10c772023-05-16 21:43:39 +08004165 *pureMode |= WIFI_MODE_AX;
4166 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4167 }
4168 if (phymode & WMODE_BE_6G) {
developere40952c2023-06-15 18:46:43 +08004169 res = snprintf(output_string + strlen(output_string), radio_mode_tem_len, "%s", "be,");
4170 if (os_snprintf_error(radio_mode_tem_len, res)) {
4171 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4172 return;
4173 }
developer0f10c772023-05-16 21:43:39 +08004174 *pureMode |= WIFI_MODE_BE;
4175 radio_mode_tem_len = RADIO_MODE_LEN - strlen(output_string);
4176 }
4177 break;
4178 default:
developer86035662023-06-28 19:21:12 +08004179 wifi_debug(DEBUG_ERROR, "%s band_idx invalid\n", __func__);
developer0f10c772023-05-16 21:43:39 +08004180 break;
4181 }
4182
4183 /* Remove the last comma */
4184 if (strlen(output_string) != 0)
developera3511852023-06-14 14:12:59 +08004185 output_string[strlen(output_string)-1] = '\0';
developer72fb0bb2023-01-11 09:46:29 +08004186
developerfead3972023-05-25 20:15:02 +08004187}
4188
4189INT wifi_getRadioMode(INT radioIndex, CHAR *output_string, UINT *pureMode)
4190{
4191 unsigned int phymode;
4192 char interface_name[IF_NAME_SIZE] = {0};
developerfead3972023-05-25 20:15:02 +08004193 int ret = -1;
4194 unsigned int if_idx = 0;
4195 struct unl unl_ins;
4196 struct nl_msg *msg = NULL;
4197 struct nlattr * msg_data = NULL;
4198 struct mtk_nl80211_param param;
4199 struct mtk_nl80211_cb_data cb_data;
4200
developera3511852023-06-14 14:12:59 +08004201 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
4202 if (NULL == output_string || NULL == pureMode)
developerdaf24792023-06-06 11:40:04 +08004203 return RETURN_ERR;
developerfead3972023-05-25 20:15:02 +08004204
4205 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
4206 return RETURN_ERR;
4207
4208 if_idx = if_nametoindex(interface_name);
4209 if (!if_idx) {
4210 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", interface_name);
4211 return RETURN_ERR;
4212 }
4213 /*init mtk nl80211 vendor cmd*/
4214 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_GET_RUNTIME_INFO;
4215 param.if_type = NL80211_ATTR_IFINDEX;
4216 param.if_idx = if_idx;
4217
4218 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
4219 if (ret) {
4220 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
4221 return RETURN_ERR;
4222 }
4223
4224 /*add mtk vendor cmd data*/
4225 if (nla_put_u16(msg, MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_WMODE, 0)) {
4226 wifi_debug(DEBUG_ERROR, "Nla put GET_RUNTIME_INFO_GET_WMODE attribute error\n");
4227 nlmsg_free(msg);
4228 goto err;
4229 }
4230
4231 /*send mtk nl80211 vendor msg*/
4232 cb_data.out_buf = (char *)&phymode;
4233 cb_data.out_len = sizeof(unsigned int);
4234
4235 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, get_radio_mode_handler, &cb_data);
4236
4237 if (ret) {
4238 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
4239 goto err;
4240 }
4241 /*deinit mtk nl80211 vendor msg*/
4242 mtk_nl80211_deint(&unl_ins);
4243
4244 phymode_to_puremode(radioIndex, output_string, pureMode, phymode);
developer6e578302023-06-21 10:11:16 +08004245 wifi_debug(DEBUG_INFO,"send cmd success\n");
developerfead3972023-05-25 20:15:02 +08004246
developera3511852023-06-14 14:12:59 +08004247 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
4248 return RETURN_OK;
developerfead3972023-05-25 20:15:02 +08004249err:
4250 mtk_nl80211_deint(&unl_ins);
4251 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
4252 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08004253}
4254
4255// Set the radio operating mode, and pure mode flag.
4256INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, BOOL nOnlyFlag, BOOL acOnlyFlag) //RDKB
4257{
developera3511852023-06-14 14:12:59 +08004258 WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__);
4259 if (strcmp (channelMode,"11A") == 0)
4260 {
4261 writeBandWidth(radioIndex,"20MHz");
4262 wifi_setRadioOperatingChannelBandwidth(radioIndex,"20MHz");
4263 printf("\nChannel Mode is 802.11a (5GHz)\n");
4264 }
4265 else if (strcmp (channelMode,"11NAHT20") == 0)
4266 {
4267 writeBandWidth(radioIndex,"20MHz");
4268 wifi_setRadioOperatingChannelBandwidth(radioIndex,"20MHz");
4269 printf("\nChannel Mode is 802.11n-20MHz(5GHz)\n");
4270 }
4271 else if (strcmp (channelMode,"11NAHT40PLUS") == 0)
4272 {
4273 writeBandWidth(radioIndex,"40MHz");
4274 wifi_setRadioOperatingChannelBandwidth(radioIndex,"40MHz");
4275 printf("\nChannel Mode is 802.11n-40MHz(5GHz)\n");
4276 }
4277 else if (strcmp (channelMode,"11NAHT40MINUS") == 0)
4278 {
4279 writeBandWidth(radioIndex,"40MHz");
4280 wifi_setRadioOperatingChannelBandwidth(radioIndex,"40MHz");
4281 printf("\nChannel Mode is 802.11n-40MHz(5GHz)\n");
4282 }
4283 else if (strcmp (channelMode,"11ACVHT20") == 0)
4284 {
4285 writeBandWidth(radioIndex,"20MHz");
4286 wifi_setRadioOperatingChannelBandwidth(radioIndex,"20MHz");
4287 printf("\nChannel Mode is 802.11ac-20MHz(5GHz)\n");
4288 }
4289 else if (strcmp (channelMode,"11ACVHT40PLUS") == 0)
4290 {
4291 writeBandWidth(radioIndex,"40MHz");
4292 wifi_setRadioOperatingChannelBandwidth(radioIndex,"40MHz");
4293 printf("\nChannel Mode is 802.11ac-40MHz(5GHz)\n");
4294 }
4295 else if (strcmp (channelMode,"11ACVHT40MINUS") == 0)
4296 {
4297 writeBandWidth(radioIndex,"40MHz");
4298 wifi_setRadioOperatingChannelBandwidth(radioIndex,"40MHz");
4299 printf("\nChannel Mode is 802.11ac-40MHz(5GHz)\n");
4300 }
4301 else if (strcmp (channelMode,"11ACVHT80") == 0)
4302 {
4303 wifi_setRadioOperatingChannelBandwidth(radioIndex,"80MHz");
4304 printf("\nChannel Mode is 802.11ac-80MHz(5GHz)\n");
4305 }
4306 else if (strcmp (channelMode,"11ACVHT160") == 0)
4307 {
4308 wifi_setRadioOperatingChannelBandwidth(radioIndex,"160MHz");
4309 printf("\nChannel Mode is 802.11ac-160MHz(5GHz)\n");
4310 }
4311 else if (strcmp (channelMode,"11B") == 0)
4312 {
4313 writeBandWidth(radioIndex,"20MHz");
4314 wifi_setRadioOperatingChannelBandwidth(radioIndex,"20MHz");
4315 printf("\nChannel Mode is 802.11b(2.4GHz)\n");
4316 }
4317 else if (strcmp (channelMode,"11G") == 0)
4318 {
4319 writeBandWidth(radioIndex,"20MHz");
4320 wifi_setRadioOperatingChannelBandwidth(radioIndex,"20MHz");
4321 printf("\nChannel Mode is 802.11g(2.4GHz)\n");
4322 }
4323 else if (strcmp (channelMode,"11NGHT20") == 0)
4324 {
4325 writeBandWidth(radioIndex,"20MHz");
4326 wifi_setRadioOperatingChannelBandwidth(radioIndex,"20MHz");
4327 printf("\nChannel Mode is 802.11n-20MHz(2.4GHz)\n");
4328 }
4329 else if (strcmp (channelMode,"11NGHT40PLUS") == 0)
4330 {
4331 writeBandWidth(radioIndex,"40MHz");
4332 wifi_setRadioOperatingChannelBandwidth(radioIndex,"40MHz");
4333 printf("\nChannel Mode is 802.11n-40MHz(2.4GHz)\n");
4334 }
4335 else if (strcmp (channelMode,"11NGHT40MINUS") == 0)
4336 {
4337 writeBandWidth(radioIndex,"40MHz");
4338 wifi_setRadioOperatingChannelBandwidth(radioIndex,"40MHz");
4339 printf("\nChannel Mode is 802.11n-40MHz(2.4GHz)\n");
4340 }
4341 else
4342 {
4343 return RETURN_ERR;
4344 }
4345 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004346
developera3511852023-06-14 14:12:59 +08004347 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004348}
4349
developer0f10c772023-05-16 21:43:39 +08004350typedef enum _RT_802_11_PHY_MODE {
4351 PHY_11BG_MIXED = 0,
4352 PHY_11B = 1,
4353 PHY_11A = 2,
4354 PHY_11ABG_MIXED = 3,
4355 PHY_11G = 4,
4356 PHY_11ABGN_MIXED = 5, /* both band 5 */
developera3511852023-06-14 14:12:59 +08004357 PHY_11N_2_4G = 6, /* 11n-only with 2.4G band 6 */
4358 PHY_11GN_MIXED = 7, /* 2.4G band 7 */
4359 PHY_11AN_MIXED = 8, /* 5G band 8 */
4360 PHY_11BGN_MIXED = 9, /* if check 802.11b. 9 */
4361 PHY_11AGN_MIXED = 10, /* if check 802.11b. 10 */
4362 PHY_11N_5G = 11, /* 11n-only with 5G band 11 */
developer0f10c772023-05-16 21:43:39 +08004363 PHY_11VHT_N_ABG_MIXED = 12, /* 12 -> AC/A/AN/B/G/GN mixed */
4364 PHY_11VHT_N_AG_MIXED = 13, /* 13 -> AC/A/AN/G/GN mixed */
4365 PHY_11VHT_N_A_MIXED = 14, /* 14 -> AC/AN/A mixed in 5G band */
4366 PHY_11VHT_N_MIXED = 15, /* 15 -> AC/AN mixed in 5G band */
4367 PHY_11AX_24G = 16,
4368 PHY_11AX_5G = 17,
4369 PHY_11AX_6G = 18,
4370 PHY_11AX_24G_6G = 19,
4371 PHY_11AX_5G_6G = 20,
4372 PHY_11AX_24G_5G_6G = 21,
4373 PHY_11BE_24G = 22,
4374 PHY_11BE_5G = 23,
4375 PHY_11BE_6G = 24,
4376 PHY_11BE_24G_6G = 25,
4377 PHY_11BE_5G_6G = 26,
4378 PHY_11BE_24G_5G_6G = 27,
4379 PHY_MODE_MAX,
4380} RT_802_11_PHY_MODE;
4381
4382unsigned int puremode_to_wireless_mode(INT radioIndex, UINT pureMode)
4383{
developerfead3972023-05-25 20:15:02 +08004384 unsigned char wireless_mode = PHY_MODE_MAX;
developer0f10c772023-05-16 21:43:39 +08004385
developer408cde72023-10-19 13:44:02 +08004386 switch (radioIndex) {
developer0f10c772023-05-16 21:43:39 +08004387 case band_2_4:
4388 if (pureMode == (WIFI_MODE_G | WIFI_MODE_N))
4389 wireless_mode = PHY_11GN_MIXED;
4390 if (pureMode == (WIFI_MODE_B | WIFI_MODE_G | WIFI_MODE_N))
4391 wireless_mode = PHY_11BGN_MIXED;
4392 if (pureMode & WIFI_MODE_AX)
4393 wireless_mode = PHY_11AX_24G;
4394 if (pureMode & WIFI_MODE_BE)
4395 wireless_mode = PHY_11BE_24G;
4396 break;
4397 case band_5:
4398 if (pureMode == WIFI_MODE_N)
4399 wireless_mode = PHY_11N_5G;
4400 if ((pureMode == WIFI_MODE_AC) || (pureMode == (WIFI_MODE_N | WIFI_MODE_AC)))
4401 wireless_mode = PHY_11VHT_N_MIXED;
4402 if (pureMode == (WIFI_MODE_A | WIFI_MODE_N | WIFI_MODE_AC))
4403 wireless_mode = PHY_11VHT_N_A_MIXED;
4404 if (pureMode & WIFI_MODE_AX)
4405 wireless_mode = PHY_11AX_5G;
4406 if (pureMode & WIFI_MODE_BE)
4407 wireless_mode = PHY_11BE_5G;
4408 break;
4409 case band_6:
4410 if (pureMode & WIFI_MODE_AX)
4411 wireless_mode = PHY_11AX_6G;
4412 if (pureMode & WIFI_MODE_BE)
4413 wireless_mode = PHY_11BE_6G;
4414 break;
4415 default:
developer37646972023-06-29 10:58:43 +08004416 if (fprintf(stderr, "%s band_idx invalid\n", __func__) < 0)
4417 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
developer0f10c772023-05-16 21:43:39 +08004418 break;
4419 }
4420
4421 return wireless_mode;
4422}
4423
developer72fb0bb2023-01-11 09:46:29 +08004424// Set the radio operating mode, and pure mode flag.
4425INT wifi_setRadioMode(INT radioIndex, CHAR *channelMode, UINT pureMode)
4426{
developerfead3972023-05-25 20:15:02 +08004427 unsigned char wireless_mode = PHY_MODE_MAX;
developer69b61b02023-03-07 17:17:44 +08004428
developer0f10c772023-05-16 21:43:39 +08004429 char interface_name[IF_NAME_SIZE] = {0};
developerfead3972023-05-25 20:15:02 +08004430 int ret = -1;
4431 unsigned int if_idx = 0;
4432 struct unl unl_ins;
4433 struct nl_msg *msg = NULL;
4434 struct nlattr * msg_data = NULL;
4435 struct mtk_nl80211_param param;
developer72fb0bb2023-01-11 09:46:29 +08004436
developer9f2358c2023-09-22 18:42:12 +08004437 WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s:%d_%d\n", __func__, channelMode, pureMode, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004438
developer0f10c772023-05-16 21:43:39 +08004439 wireless_mode = puremode_to_wireless_mode(radioIndex, pureMode);
developer72fb0bb2023-01-11 09:46:29 +08004440
developera3511852023-06-14 14:12:59 +08004441 if (wireless_mode == PHY_MODE_MAX) {
developer75bd10c2023-06-27 11:34:08 +08004442 wifi_debug(DEBUG_ERROR, "invalid pureMode = %x\n", pureMode);
developer0f10c772023-05-16 21:43:39 +08004443 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +08004444 }
developer72fb0bb2023-01-11 09:46:29 +08004445
developer0f10c772023-05-16 21:43:39 +08004446 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
developera3511852023-06-14 14:12:59 +08004447 return RETURN_ERR;
developerfead3972023-05-25 20:15:02 +08004448
4449 if_idx = if_nametoindex(interface_name);
4450 if (!if_idx) {
4451 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", interface_name);
4452 return RETURN_ERR;
4453 }
4454 /*init mtk nl80211 vendor cmd*/
4455 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_BSS;
4456 param.if_type = NL80211_ATTR_IFINDEX;
4457 param.if_idx = if_idx;
4458
4459 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
4460 if (ret) {
4461 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
4462 return RETURN_ERR;
4463 }
4464
4465 /*add mtk vendor cmd data*/
4466 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_WIRELESS_MODE, wireless_mode)) {
4467 wifi_debug(DEBUG_ERROR, "Nla put AP_WIRELESS_MODE attribute error\n");
4468 nlmsg_free(msg);
4469 goto err;
4470 }
4471 /*send mtk nl80211 vendor msg*/
4472 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
4473 if (ret) {
4474 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
4475 goto err;
4476 }
4477 /*deinit mtk nl80211 vendor msg*/
4478 mtk_nl80211_deint(&unl_ins);
4479 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
developer72fb0bb2023-01-11 09:46:29 +08004480
developera3511852023-06-14 14:12:59 +08004481 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer0f10c772023-05-16 21:43:39 +08004482
developera3511852023-06-14 14:12:59 +08004483 return RETURN_OK;
developerfead3972023-05-25 20:15:02 +08004484err:
4485 mtk_nl80211_deint(&unl_ins);
4486 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
4487 return RETURN_ERR;
developer0f10c772023-05-16 21:43:39 +08004488}
4489
4490INT wifi_setRadioMode_by_dat(INT radioIndex, UINT pureMode)
4491{
developerfead3972023-05-25 20:15:02 +08004492 unsigned char wireless_mode = PHY_MODE_MAX;
developera3511852023-06-14 14:12:59 +08004493 char buf[MAX_BUF_SIZE] = {0};
developer0f10c772023-05-16 21:43:39 +08004494 char dat_file[MAX_BUF_SIZE] = {0};
4495 struct params params={0};
developere40952c2023-06-15 18:46:43 +08004496 int res;
developer0f10c772023-05-16 21:43:39 +08004497
4498 WIFI_ENTRY_EXIT_DEBUG("Inside %s_%d:%d\n", __func__, pureMode, __LINE__);
4499
4500 wireless_mode = puremode_to_wireless_mode(radioIndex, pureMode);
4501
developera3511852023-06-14 14:12:59 +08004502 if (wireless_mode == PHY_MODE_MAX) {
developer75bd10c2023-06-27 11:34:08 +08004503 wifi_debug(DEBUG_ERROR, "invalid pureMode = %x\n", pureMode);
developer0f10c772023-05-16 21:43:39 +08004504 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +08004505 }
developer0f10c772023-05-16 21:43:39 +08004506
4507 params.name = "WirelessMode";
developere40952c2023-06-15 18:46:43 +08004508 res = snprintf(buf, sizeof(buf), "%d", wireless_mode);
4509 if (os_snprintf_error(sizeof(buf), res)) {
4510 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4511 return RETURN_ERR;
4512 }
4513
developera3511852023-06-14 14:12:59 +08004514 params.value = buf;
developer0f10c772023-05-16 21:43:39 +08004515
developere40952c2023-06-15 18:46:43 +08004516 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, radioIndex);
4517 if (os_snprintf_error(sizeof(dat_file), res)) {
4518 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4519 return RETURN_ERR;
4520 }
developera3511852023-06-14 14:12:59 +08004521 wifi_datfileWrite(dat_file, &params, 1);
developer0f10c772023-05-16 21:43:39 +08004522
developera3511852023-06-14 14:12:59 +08004523 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004524
developera3511852023-06-14 14:12:59 +08004525 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004526}
4527
4528INT wifi_setRadioHwMode(INT radioIndex, CHAR *hw_mode) {
4529
developera3511852023-06-14 14:12:59 +08004530 char config_file[64] = {0};
4531 char buf[64] = {0};
4532 struct params params = {0};
4533 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08004534 int res;
developer72fb0bb2023-01-11 09:46:29 +08004535
developera3511852023-06-14 14:12:59 +08004536 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004537
developera3511852023-06-14 14:12:59 +08004538 band = wifi_index_to_band(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +08004539
developera3511852023-06-14 14:12:59 +08004540 if (strncmp(hw_mode, "a", 1) == 0 && (band != band_5 && band != band_6))
4541 return RETURN_ERR;
4542 else if ((strncmp(hw_mode, "b", 1) == 0 || strncmp(hw_mode, "g", 1) == 0) && band != band_2_4)
4543 return RETURN_ERR;
4544 else if ((strncmp(hw_mode, "a", 1) && strncmp(hw_mode, "b", 1) && strncmp(hw_mode, "g", 1)) || band == band_invalid)
4545 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08004546
developer75bd10c2023-06-27 11:34:08 +08004547 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
4548 if (os_snprintf_error(sizeof(config_file), res)) {
4549 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4550 return RETURN_ERR;
4551 }
developera3511852023-06-14 14:12:59 +08004552 params.name = "hw_mode";
4553 params.value = hw_mode;
4554 wifi_hostapdWrite(config_file, &params, 1);
4555 wifi_hostapdProcessUpdate(radioIndex, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +08004556
developera3511852023-06-14 14:12:59 +08004557 if (band == band_2_4) {
4558 if (strncmp(hw_mode, "b", 1) == 0) {
4559 wifi_setRadioMode(radioIndex, "20MHz", WIFI_MODE_B);
developere40952c2023-06-15 18:46:43 +08004560 res = snprintf(buf, sizeof(buf), "%s", "1,2,5.5,11");
4561 if (os_snprintf_error(sizeof(buf), res)) {
4562 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4563 return RETURN_ERR;
4564 }
developera3511852023-06-14 14:12:59 +08004565 wifi_setRadioOperationalDataTransmitRates(radioIndex, buf);
developere40952c2023-06-15 18:46:43 +08004566 res = snprintf(buf, sizeof(buf), "%s", "1,2");
4567 if (os_snprintf_error(sizeof(buf), res)) {
4568 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4569 return RETURN_ERR;
4570 }
developera3511852023-06-14 14:12:59 +08004571 wifi_setRadioBasicDataTransmitRates(radioIndex, buf);
4572 } else {
4573 // We don't set mode here, because we don't know whitch mode should be set (g, n or ax?).
developer72fb0bb2023-01-11 09:46:29 +08004574
developere40952c2023-06-15 18:46:43 +08004575 res = snprintf(buf, sizeof(buf), "%s", "6,9,12,18,24,36,48,54");
4576 if (os_snprintf_error(sizeof(buf), res)) {
4577 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4578 return RETURN_ERR;
4579 }
developera3511852023-06-14 14:12:59 +08004580 wifi_setRadioOperationalDataTransmitRates(radioIndex, buf);
developere40952c2023-06-15 18:46:43 +08004581 res = snprintf(buf, sizeof(buf), "%s", "6,12,24");
4582 if (os_snprintf_error(sizeof(buf), res)) {
4583 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4584 return RETURN_ERR;
4585 }
developera3511852023-06-14 14:12:59 +08004586 wifi_setRadioBasicDataTransmitRates(radioIndex, buf);
4587 }
4588 }
developer72fb0bb2023-01-11 09:46:29 +08004589
developera3511852023-06-14 14:12:59 +08004590 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
4591 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004592}
4593
4594INT wifi_setNoscan(INT radioIndex, CHAR *noscan)
4595{
developera3511852023-06-14 14:12:59 +08004596 char config_file[64] = {0};
4597 struct params params = {0};
4598 wifi_band band = band_invalid;
developer75bd10c2023-06-27 11:34:08 +08004599 int res;
developer72fb0bb2023-01-11 09:46:29 +08004600
developera3511852023-06-14 14:12:59 +08004601 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004602
developera3511852023-06-14 14:12:59 +08004603 band = wifi_index_to_band(radioIndex);
4604 if (band != band_2_4)
4605 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004606
developer75bd10c2023-06-27 11:34:08 +08004607 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
4608 if (os_snprintf_error(sizeof(config_file), res)) {
4609 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4610 return RETURN_ERR;
4611 }
developera3511852023-06-14 14:12:59 +08004612 params.name = "noscan";
4613 params.value = noscan;
4614 wifi_hostapdWrite(config_file, &params, 1);
4615 wifi_hostapdProcessUpdate(radioIndex, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +08004616
developera3511852023-06-14 14:12:59 +08004617 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
4618 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004619}
4620
4621//Get the list of supported channel. eg: "1-11"
4622//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
4623INT wifi_getRadioPossibleChannels(INT radioIndex, CHAR *output_string) //RDKB
4624{
developera3511852023-06-14 14:12:59 +08004625 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
4626 if (NULL == output_string)
4627 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +08004628
developera3511852023-06-14 14:12:59 +08004629 char buf[128] = {0};
4630 BOOL dfs_enable = false;
developere40952c2023-06-15 18:46:43 +08004631 int phyId = 0, res;
developer72fb0bb2023-01-11 09:46:29 +08004632
developera3511852023-06-14 14:12:59 +08004633 // Parse possible channel number and separate them with commas.
4634 wifi_getRadioDfsEnable(radioIndex, &dfs_enable);
4635 phyId = radio_index_to_phy(radioIndex);
4636 // Channel 68 and 96 only allow bandwidth 20MHz, so we remove them with their frequency.
4637 if (dfs_enable)
developer8078acf2023-08-04 18:52:48 +08004638 res = _syscmd_secure(buf, sizeof(buf), "iw phy phy%d info | grep -e '\\*.*MHz .*dBm' | grep -v 'no IR\\|5340\\|5480' | cut -d '[' -f2 | cut -d ']' -f1 | tr '\\n' ',' | sed 's/.$//'", phyId);
developera3511852023-06-14 14:12:59 +08004639 else
developer8078acf2023-08-04 18:52:48 +08004640 res = _syscmd_secure(buf, sizeof(buf), "iw phy phy%d info | grep -e '\\*.*MHz .*dBm' | grep -v 'radar\\|no IR\\|5340\\|5480' | cut -d '[' -f2 | cut -d ']' -f1 | tr '\\n' ',' | sed 's/.$//'", phyId);
developer72fb0bb2023-01-11 09:46:29 +08004641
developer8078acf2023-08-04 18:52:48 +08004642 if (res) {
4643 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08004644 }
developera3511852023-06-14 14:12:59 +08004645 strncpy(output_string, buf, strlen(buf) < sizeof(buf) ? strlen(buf) : sizeof(buf));
developer72fb0bb2023-01-11 09:46:29 +08004646
developera3511852023-06-14 14:12:59 +08004647 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
4648 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004649}
developerd1824452023-05-18 12:30:04 +08004650//Getting current radio extension channel
4651INT wifi_halgetRadioExtChannel(CHAR *file,CHAR *Value)
4652{
developera3511852023-06-14 14:12:59 +08004653 CHAR buf[150] = {0};
developer32f2a182023-06-27 19:50:41 +08004654 int len;
developerd1824452023-05-18 12:30:04 +08004655
developera3511852023-06-14 14:12:59 +08004656 wifi_datfileRead(file, "HT_EXTCHA", buf, sizeof(buf));
developerb14b3462023-07-01 18:02:42 +08004657
4658 if (strncmp(buf, "0", 1) == 0) {
developer32f2a182023-06-27 19:50:41 +08004659 len = strlen("BelowControlChannel");
4660 memcpy(Value, "BelowControlChannel", len);
developerc14d83a2023-06-29 20:09:42 +08004661 Value[len] = '\0';
developer32f2a182023-06-27 19:50:41 +08004662 }
developerb14b3462023-07-01 18:02:42 +08004663 else if(strncmp(buf, "1", 1) == 0) {
developer32f2a182023-06-27 19:50:41 +08004664 len = strlen("AboveControlChannel");
4665 memcpy(Value, "AboveControlChannel", len);
developerc14d83a2023-06-29 20:09:42 +08004666 Value[len] = '\0';
developer32f2a182023-06-27 19:50:41 +08004667 }
developer5b23cd02023-07-19 20:26:03 +08004668
developera3511852023-06-14 14:12:59 +08004669 return RETURN_OK;
developerd1824452023-05-18 12:30:04 +08004670}
developerf6a87542023-05-16 15:47:28 +08004671
developer72fb0bb2023-01-11 09:46:29 +08004672//Get the list for used channel. eg: "1,6,9,11"
4673//The output_string is a max length 256 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
4674INT wifi_getRadioChannelsInUse(INT radioIndex, CHAR *output_string) //RDKB
4675{
developera3511852023-06-14 14:12:59 +08004676 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +08004677
developera3511852023-06-14 14:12:59 +08004678 char buf[128] = {0};
4679 char config_file[64] = {0};
4680 int channel = 0;
4681 int freq = 0;
4682 int bandwidth = 0;
4683 int center_freq = 0;
4684 int center_channel = 0;
4685 int channel_delta = 0;
4686 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08004687 int res;
developer72fb0bb2023-01-11 09:46:29 +08004688
developera3511852023-06-14 14:12:59 +08004689 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004690
developera3511852023-06-14 14:12:59 +08004691 if (NULL == output_string)
4692 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08004693
developera3511852023-06-14 14:12:59 +08004694 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
4695 return RETURN_ERR;
developer75bd10c2023-06-27 11:34:08 +08004696
developer8078acf2023-08-04 18:52:48 +08004697 res = _syscmd_secure(buf, sizeof(buf), "iw %s info | grep channel | sed -e 's/[^0-9 ]//g'", interface_name);
4698 if (res) {
4699 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +08004700 }
developera3511852023-06-14 14:12:59 +08004701 if (strlen(buf) == 0) {
developer75bd10c2023-06-27 11:34:08 +08004702 wifi_debug(DEBUG_ERROR, "failed to get channel information from iw.\n");
developera3511852023-06-14 14:12:59 +08004703 return RETURN_ERR;
4704 }
developerd14dff12023-06-28 22:47:44 +08004705 if (sscanf(buf, "%d %d %d %*d %d", &channel, &freq, &bandwidth, &center_freq) != 4) {
4706 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
4707 return RETURN_ERR;
4708 }
developer72fb0bb2023-01-11 09:46:29 +08004709
developera3511852023-06-14 14:12:59 +08004710 if (bandwidth == 20) {
developere40952c2023-06-15 18:46:43 +08004711 res = snprintf(output_string, 256, "%d", channel);
4712 if (os_snprintf_error(256, res)) {
4713 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4714 return RETURN_ERR;
4715 }
developera3511852023-06-14 14:12:59 +08004716 return RETURN_OK;
4717 }
developer72fb0bb2023-01-11 09:46:29 +08004718
developera3511852023-06-14 14:12:59 +08004719 center_channel = ieee80211_frequency_to_channel(center_freq);
developer72fb0bb2023-01-11 09:46:29 +08004720
developera3511852023-06-14 14:12:59 +08004721 band = wifi_index_to_band(radioIndex);
4722 if (band == band_2_4 && bandwidth == 40) {
developer32f2a182023-06-27 19:50:41 +08004723 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
4724 if (os_snprintf_error(sizeof(config_file), res)) {
4725 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4726 return RETURN_ERR;
4727 }
developera3511852023-06-14 14:12:59 +08004728 memset(buf, 0, sizeof(buf));
4729 wifi_halgetRadioExtChannel(config_file, buf); // read ht_capab for HT40+ or -
developer72fb0bb2023-01-11 09:46:29 +08004730
developera3511852023-06-14 14:12:59 +08004731 if (strncmp(buf, "AboveControlChannel", strlen("AboveControlChannel")) == 0 && channel < 10) {
developere40952c2023-06-15 18:46:43 +08004732 res = snprintf(output_string, 256, "%d,%d", channel, channel+4);
developera3511852023-06-14 14:12:59 +08004733 } else if (strncmp(buf, "BelowControlChannel", strlen("BelowControlChannel")) == 0 && channel > 4) {
developere40952c2023-06-15 18:46:43 +08004734 res = snprintf(output_string, 256, "%d,%d", channel-4, channel);
developera3511852023-06-14 14:12:59 +08004735 } else {
developer37646972023-06-29 10:58:43 +08004736 if (fprintf(stderr, "%s: invalid channel %d set with %s\n.", __func__, channel, buf) < 0)
4737 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
developera3511852023-06-14 14:12:59 +08004738 return RETURN_ERR;
4739 }
developerb758dfd2023-06-21 17:32:07 +08004740
developere40952c2023-06-15 18:46:43 +08004741 if (os_snprintf_error(256, res)) {
4742 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4743 return RETURN_ERR;
4744 }
developera3511852023-06-14 14:12:59 +08004745 } else if (band == band_5 || band == band_6){
4746 // to minus 20 is an offset, because frequence of a channel have a range. We need to use offset to calculate correct channel.
4747 // example: bandwidth 80: center is 42 (5210), channels are "36,40,44,48" (5170-5250). The delta should be 6.
4748 channel_delta = (bandwidth-20)/10;
4749 memset(output_string, 0, 256);
4750 for (int i = center_channel-channel_delta; i <= center_channel+channel_delta; i+=4) {
4751 // If i is not the last channel, we add a comma.
developere40952c2023-06-15 18:46:43 +08004752 res = snprintf(buf, sizeof(buf), "%d%s", i, i==center_channel+channel_delta?"":",");
developer5b23cd02023-07-19 20:26:03 +08004753
developere40952c2023-06-15 18:46:43 +08004754 if (os_snprintf_error(sizeof(buf), res)) {
4755 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4756 return RETURN_ERR;
4757 }
developer32f2a182023-06-27 19:50:41 +08004758 strncat(output_string, buf, sizeof(output_string) - strlen(output_string) - 1);
developera3511852023-06-14 14:12:59 +08004759 }
4760 } else
4761 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08004762
developera3511852023-06-14 14:12:59 +08004763 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
4764 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004765}
4766
developer408cde72023-10-19 13:44:02 +08004767int get_channel_handler(struct nl_msg *msg, void *data)
4768{
4769 struct nlattr *tb[NL80211_ATTR_MAX + 1];
4770 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_MAX + 1];
4771 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
4772 unsigned char *channel = (unsigned char *)data;
4773 int err = 0;
4774
4775 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
4776 genlmsg_attrlen(gnlh, 0), NULL);
4777 if (err < 0)
4778 return err;
4779
4780 if (tb[NL80211_ATTR_VENDOR_DATA]) {
4781 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_MAX,
4782 tb[NL80211_ATTR_VENDOR_DATA], NULL);
4783 if (err < 0)
4784 return err;
4785
4786 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_CHANNEL]) {
4787 *channel = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_CHANNEL]);
4788 }
4789 }
4790
4791 return 0;
4792}
4793
4794INT mtk_wifi_get_radio_info(
4795 INT radioIndex, INT vendor_data_attr, mtk_nl80211_cb call_back, void *output)
4796{
4797 int ret = -1;
4798 struct unl unl_ins;
4799 struct nl_msg *msg = NULL;
4800 struct nlattr * msg_data = NULL;
4801 struct mtk_nl80211_param param;
4802
4803 /*init mtk nl80211 vendor cmd*/
4804 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_GET_BAND_INFO;
4805 param.if_type = NL80211_ATTR_WIPHY;
4806 param.if_idx = radio_index_to_phy(radioIndex);
4807
4808 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
4809 if (ret) {
4810 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
4811 return RETURN_ERR;
4812 }
4813 /*add mtk vendor cmd data*/
4814 if (nla_put_u8(msg, vendor_data_attr, 1)) {
4815 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", vendor_data_attr);
4816 nlmsg_free(msg);
4817 goto err;
4818 }
4819
4820 /*send mtk nl80211 vendor msg*/
4821 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, call_back, output);
4822 if (ret) {
4823 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
4824 goto err;
4825 }
4826 /*deinit mtk nl80211 vendor msg*/
4827 mtk_nl80211_deint(&unl_ins);
4828 wifi_debug(DEBUG_INFO, "send cmd success.\n");
4829
4830 return RETURN_OK;
4831err:
4832 mtk_nl80211_deint(&unl_ins);
4833 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
4834 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08004835}
4836
developer69b61b02023-03-07 17:17:44 +08004837//Get the running channel number
developerd1824452023-05-18 12:30:04 +08004838INT wifi_getRadioChannel(INT radioIndex, ULONG *output_ulong) //RDKB
developer72fb0bb2023-01-11 09:46:29 +08004839{
developera3511852023-06-14 14:12:59 +08004840 char channel_str[16] = {0};
4841 char config_file[128] = {0};
developera3511852023-06-14 14:12:59 +08004842 wifi_band band = band_invalid;
developer408cde72023-10-19 13:44:02 +08004843 unsigned char channel;
developere40952c2023-06-15 18:46:43 +08004844 int res;
developer47a56bf2023-05-30 13:38:57 +08004845
developera3511852023-06-14 14:12:59 +08004846 if (output_ulong == NULL)
4847 return RETURN_ERR;
4848 band = wifi_index_to_band(radioIndex);
developerb758dfd2023-06-21 17:32:07 +08004849 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
developere40952c2023-06-15 18:46:43 +08004850 if (os_snprintf_error(sizeof(config_file), res)) {
4851 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4852 return RETURN_ERR;
4853 }
4854
developera3511852023-06-14 14:12:59 +08004855 wifi_datfileRead(config_file, "Channel", channel_str, sizeof(channel_str));
developerb14b3462023-07-01 18:02:42 +08004856 if (hal_strtoul(channel_str, 10, output_ulong) < 0) {
developerc14d83a2023-06-29 20:09:42 +08004857 wifi_debug(DEBUG_ERROR, "strtol fail\n");
4858 }
developera3511852023-06-14 14:12:59 +08004859 if (*output_ulong == 0) {
developer408cde72023-10-19 13:44:02 +08004860 if (mtk_wifi_get_radio_info(radioIndex, MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_CHANNEL,
4861 get_channel_handler, &channel)!= RETURN_OK) {
4862 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_CHANNEL cmd fails\n");
developerd14dff12023-06-28 22:47:44 +08004863 return RETURN_ERR;
4864 }
developer408cde72023-10-19 13:44:02 +08004865 *output_ulong = channel;
developera3511852023-06-14 14:12:59 +08004866 }
developer72fb0bb2023-01-11 09:46:29 +08004867
developera3511852023-06-14 14:12:59 +08004868 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004869}
4870
developer72fb0bb2023-01-11 09:46:29 +08004871INT wifi_getApChannel(INT apIndex,ULONG *output_ulong) //RDKB
4872{
developer8078acf2023-08-04 18:52:48 +08004873 char buf[5] = {0};
developera3511852023-06-14 14:12:59 +08004874 char interface_name[16] = {0};
developere40952c2023-06-15 18:46:43 +08004875 int res;
developer72fb0bb2023-01-11 09:46:29 +08004876
developera3511852023-06-14 14:12:59 +08004877 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
4878 if (NULL == output_ulong)
4879 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08004880
developera3511852023-06-14 14:12:59 +08004881 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
4882 return RETURN_ERR;
developer47a56bf2023-05-30 13:38:57 +08004883
developer8078acf2023-08-04 18:52:48 +08004884
4885 res = _syscmd_secure(buf, sizeof(buf), "iw dev %s info |grep channel | cut -d ' ' -f2", interface_name);
4886 if (res) {
4887 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
4888 }
developera3511852023-06-14 14:12:59 +08004889 *output_ulong = (strlen(buf) >= 1)? atol(buf): 0;
4890 if (*output_ulong == 0) {
4891 return RETURN_ERR;
4892 }
developer72fb0bb2023-01-11 09:46:29 +08004893
developera3511852023-06-14 14:12:59 +08004894 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
4895 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004896}
developer72fb0bb2023-01-11 09:46:29 +08004897//Storing the previous channel value
4898INT wifi_storeprevchanval(INT radioIndex)
4899{
developera3511852023-06-14 14:12:59 +08004900 char output[4]={'\0'};
4901 char config_file[MAX_BUF_SIZE] = {0};
4902 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08004903 int res;
developerd1824452023-05-18 12:30:04 +08004904
developera3511852023-06-14 14:12:59 +08004905 band = wifi_index_to_band(radioIndex);
4906 if (band == band_invalid) {
4907 return RETURN_ERR;
4908 wifi_dbg_printf("[%s]: Invalid radio index", __func__);
4909 }
developere40952c2023-06-15 18:46:43 +08004910 res = snprintf(config_file, sizeof(config_file), "%s%d.dat",LOGAN_DAT_FILE, band);
4911 if (os_snprintf_error(sizeof(config_file), res)) {
4912 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4913 return RETURN_ERR;
4914 }
4915
developera3511852023-06-14 14:12:59 +08004916 wifi_datfileRead(config_file, "Channel", output, sizeof(output));
developerd1824452023-05-18 12:30:04 +08004917
developera3511852023-06-14 14:12:59 +08004918 if(band == band_2_4)
developer33f13ba2023-07-12 16:19:06 +08004919 res = v_secure_system("echo %s > /var/prevchanval2G_AutoChannelEnable", output);
developera3511852023-06-14 14:12:59 +08004920 else if(band == band_5)
developer33f13ba2023-07-12 16:19:06 +08004921 res = v_secure_system("echo %s > /var/prevchanval5G_AutoChannelEnable", output);
developera3511852023-06-14 14:12:59 +08004922 else
developer33f13ba2023-07-12 16:19:06 +08004923 res = v_secure_system("echo %s > /var/prevchanval6G_AutoChannelEnable", output);
developer75bd10c2023-06-27 11:34:08 +08004924
developer33f13ba2023-07-12 16:19:06 +08004925 if (res) {
4926 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developer75bd10c2023-06-27 11:34:08 +08004927 }
developera3511852023-06-14 14:12:59 +08004928 Radio_flag = FALSE;
4929 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08004930}
4931
4932//Set the running channel number
4933INT wifi_setRadioChannel(INT radioIndex, ULONG channel) //RDKB //AP only
4934{
developera3511852023-06-14 14:12:59 +08004935 // We only write hostapd config here
4936 char str_channel[8]={0};
4937 char *list_channel;
4938 char possible_channels[256] = {0};
4939 char config_file_dat[128] = {0};
4940 struct params dat = {0};
4941 struct params acs = {0};
4942 wifi_band band = band_invalid;
4943 bool acs_channel = false;
developere40952c2023-06-15 18:46:43 +08004944 int res;
developereef7d562023-10-21 16:04:21 +08004945 int ret = 0;
developer72fb0bb2023-01-11 09:46:29 +08004946
developera3511852023-06-14 14:12:59 +08004947 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08004948
developera3511852023-06-14 14:12:59 +08004949 if (channel == 0)
4950 acs_channel = true;
4951 // Check valid
developer75bd10c2023-06-27 11:34:08 +08004952 res = snprintf(str_channel, sizeof(str_channel), "%lu", channel);
4953 if (os_snprintf_error(sizeof(str_channel), res)) {
4954 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4955 return RETURN_ERR;
4956 }
developer47a56bf2023-05-30 13:38:57 +08004957
developera3511852023-06-14 14:12:59 +08004958 wifi_getRadioPossibleChannels(radioIndex, possible_channels);
4959 list_channel = strtok(possible_channels, ",");
4960 while(true)
4961 {
4962 if(list_channel == NULL) { // input not in the list
developer75bd10c2023-06-27 11:34:08 +08004963 wifi_debug(DEBUG_ERROR, "Channel %s is not in possible list\n", str_channel);
developera3511852023-06-14 14:12:59 +08004964 return RETURN_ERR;
4965 }
4966 if (strncmp(str_channel, list_channel, strlen(list_channel)) == 0 || strncmp(str_channel, "0", 1) == 0)
4967 break;
4968 list_channel = strtok(NULL, ",");
4969 }
4970 /*
4971 list.name = "channel";
4972 list.value = str_channel;
4973 wifi_getMaxRadioNumber(&max_radio_num);
4974 for(int i=0; i<=MAX_APS/max_radio_num;i++)
4975 {
4976 sprintf(config_file, "%s%d.conf", CONFIG_PREFIX, radioIndex+(max_radio_num*i));
4977 wifi_hostapdWrite(config_file, &list, 1);
4978 }
4979 */
4980 dat.name = "Channel";
4981 dat.value = str_channel;
4982 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +08004983 res = snprintf(config_file_dat, sizeof(config_file_dat), "%s%d.dat", LOGAN_DAT_FILE, band);
4984 if (os_snprintf_error(sizeof(config_file_dat), res)) {
4985 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
4986 return RETURN_ERR;
4987 }
developera3511852023-06-14 14:12:59 +08004988 wifi_datfileWrite(config_file_dat, &dat, 1);
developereef7d562023-10-21 16:04:21 +08004989
developera3511852023-06-14 14:12:59 +08004990 if (acs_channel == true) {
4991 acs.name = "AutoChannelSelect";
4992 acs.value = "3";
4993 } else {
4994 acs.name = "AutoChannelSelect";
4995 acs.value = "0";
4996 }
4997 wifi_datfileWrite(config_file_dat, &acs, 1);
developereef7d562023-10-21 16:04:21 +08004998
4999 /*do channel quick setting*/
5000 if (channel != 0) {
5001 ret = wifi_setChannel_netlink(radioIndex, &channel, NULL, NULL, NULL);
5002 if (ret != RETURN_OK)
5003 wifi_debug(DEBUG_ERROR, "channel quick setting fail\n");
developer5b23cd02023-07-19 20:26:03 +08005004 }
5005
developera3511852023-06-14 14:12:59 +08005006 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
5007 return RETURN_OK;
5008}
5009
5010INT wifi_setRadioCenterChannel(INT radioIndex, ULONG channel)
5011{
5012 struct params list[2];
5013 char str_idx[16];
5014 char config_file[64];
developere40952c2023-06-15 18:46:43 +08005015 int max_num_radios = 0, res;
developera3511852023-06-14 14:12:59 +08005016 wifi_band band = band_invalid;
5017
5018 band = wifi_index_to_band(radioIndex);
5019 if (band == band_2_4)
5020 return RETURN_OK;
5021
developere40952c2023-06-15 18:46:43 +08005022 res = snprintf(str_idx, sizeof(str_idx), "%lu", channel);
5023 if (os_snprintf_error(sizeof(str_idx), res)) {
5024 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5025 return RETURN_ERR;
5026 }
5027
developera3511852023-06-14 14:12:59 +08005028 list[0].name = "vht_oper_centr_freq_seg0_idx";
5029 list[0].value = str_idx;
5030 list[1].name = "he_oper_centr_freq_seg0_idx";
5031 list[1].value = str_idx;
5032
5033 wifi_getMaxRadioNumber(&max_num_radios);
developer9ce44382023-06-28 11:09:37 +08005034 if(max_num_radios== 0){
5035 return RETURN_ERR;
5036 }
developera3511852023-06-14 14:12:59 +08005037 for(int i=0; i<=MAX_APS/max_num_radios; i++)
5038 {
developere40952c2023-06-15 18:46:43 +08005039 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex+(max_num_radios*i));
5040 if (os_snprintf_error(sizeof(config_file), res)) {
5041 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5042 return RETURN_ERR;
5043 }
developera3511852023-06-14 14:12:59 +08005044 if (band == band_6)
5045 wifi_hostapdWrite(config_file, &list[1], 1);
5046 else
5047 wifi_hostapdWrite(config_file, list, 2);
5048 }
5049
5050 return RETURN_OK;
5051}
5052
5053//Enables or disables a driver level variable to indicate if auto channel selection is enabled on this radio
5054//This "auto channel" means the auto channel selection when radio is up. (which is different from the dynamic channel/frequency selection (DFC/DCS))
5055INT wifi_setRadioAutoChannelEnable(INT radioIndex, BOOL enable) //RDKB
5056{
5057 //Set to wifi config only. Wait for wifi reset to apply.
5058 ULONG Value = 0;
5059 char config_file_dat[128] = {0};
5060 struct params acs = {0};
5061 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08005062 int res;
developera3511852023-06-14 14:12:59 +08005063
5064 if(enable == TRUE) {
5065 wifi_setRadioChannel(radioIndex,Value);
5066 } else {
5067 acs.name = "AutoChannelSelect";
5068 acs.value = "0";
5069 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +08005070 res = snprintf(config_file_dat, sizeof(config_file_dat), "%s%d.dat", LOGAN_DAT_FILE, band);
5071 if (os_snprintf_error(sizeof(config_file_dat), res)) {
5072 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5073 return RETURN_ERR;
5074 }
developera3511852023-06-14 14:12:59 +08005075 wifi_datfileWrite(config_file_dat, &acs, 1);
5076 }
5077 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005078}
5079
5080INT wifi_getRadioAutoChannelSupported(INT radioIndex, BOOL *output_bool)
5081{
developera3511852023-06-14 14:12:59 +08005082 if (output_bool == NULL)
5083 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08005084
developera3511852023-06-14 14:12:59 +08005085 *output_bool = TRUE;
developer72fb0bb2023-01-11 09:46:29 +08005086
developera3511852023-06-14 14:12:59 +08005087 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005088}
5089
5090INT wifi_getRadioDCSSupported(INT radioIndex, BOOL *output_bool) //RDKB
5091{
developera3511852023-06-14 14:12:59 +08005092 if (NULL == output_bool)
5093 return RETURN_ERR;
developer326d4232023-06-15 16:45:30 +08005094 *output_bool=TRUE;
developera3511852023-06-14 14:12:59 +08005095 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005096}
5097
5098INT wifi_getRadioDCSEnable(INT radioIndex, BOOL *output_bool) //RDKB
5099{
developer326d4232023-06-15 16:45:30 +08005100 unsigned long period = 0;
5101
developera3511852023-06-14 14:12:59 +08005102 if (NULL == output_bool)
5103 return RETURN_ERR;
developer326d4232023-06-15 16:45:30 +08005104
5105 if (wifi_getRadioAutoChannelRefreshPeriod(radioIndex, &period) != RETURN_OK)
developerb758dfd2023-06-21 17:32:07 +08005106 return RETURN_OK;
developer326d4232023-06-15 16:45:30 +08005107
5108 *output_bool = (period > 0) ? TRUE : FALSE;
5109
developera3511852023-06-14 14:12:59 +08005110 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005111}
5112
developer326d4232023-06-15 16:45:30 +08005113INT wifi_setRadioDCSEnable(INT radioIndex, BOOL enable) //RDKB
developer72fb0bb2023-01-11 09:46:29 +08005114{
developer326d4232023-06-15 16:45:30 +08005115 ULONG period = 1800;
5116
5117 if (enable == TRUE) {
5118 if (wifi_setRadioAutoChannelRefreshPeriod(radioIndex, period) != RETURN_OK)
5119 return RETURN_ERR;
5120 }
5121 else {
5122 if (wifi_setRadioAutoChannelRefreshPeriod(radioIndex, 0) != RETURN_OK)
5123 return RETURN_ERR;
5124 }
developera3511852023-06-14 14:12:59 +08005125 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005126}
5127
5128INT wifi_setApEnableOnLine(ULONG wlanIndex,BOOL enable)
5129{
developera3511852023-06-14 14:12:59 +08005130 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005131}
5132
5133INT wifi_factoryResetAP(int apIndex)
5134{
developerb149d9d2023-06-06 16:14:22 +08005135 char ap_config_file[MAX_SUB_CMD_SIZE] = {0};
developer8078acf2023-08-04 18:52:48 +08005136
developer47cc27a2023-05-17 23:09:58 +08005137 char ret_buf[MAX_BUF_SIZE] = {0};
5138 int radio_idx = 0;
5139 int bss_idx = 0;
5140 char ssid[32] = {0};
5141 char interface[IF_NAME_SIZE] = {0};
developerb149d9d2023-06-06 16:14:22 +08005142 char psk_file[MAX_SUB_CMD_SIZE] = {0};
developera3511852023-06-14 14:12:59 +08005143 struct params params[3] = {0};
developere40952c2023-06-15 18:46:43 +08005144 int res;
developer72fb0bb2023-01-11 09:46:29 +08005145
developera3511852023-06-14 14:12:59 +08005146 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08005147
developer47cc27a2023-05-17 23:09:58 +08005148 /*del old config file*/
developer9ce44382023-06-28 11:09:37 +08005149 res = snprintf(ap_config_file, sizeof(ap_config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
developerd14dff12023-06-28 22:47:44 +08005150 if (os_snprintf_error(sizeof(ap_config_file), res)) {
developere40952c2023-06-15 18:46:43 +08005151 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5152 return RETURN_ERR;
5153 }
5154
developer8078acf2023-08-04 18:52:48 +08005155 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "rm %s", ap_config_file);
5156 if (res) {
5157 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08005158 }
5159
developer72fb0bb2023-01-11 09:46:29 +08005160
developer47cc27a2023-05-17 23:09:58 +08005161 memset(ret_buf, 0, sizeof(ret_buf));
developer72fb0bb2023-01-11 09:46:29 +08005162
developer47cc27a2023-05-17 23:09:58 +08005163 vap_index_to_array_index(apIndex, &radio_idx, &bss_idx);
5164
5165 /*prepare new config file*/
developer8078acf2023-08-04 18:52:48 +08005166
5167 res = _syscmd_secure(ret_buf, sizeof(ret_buf), "cp /etc/hostapd-%s.conf %s", wifi_band_str[radio_idx], ap_config_file);
5168 if (res) {
5169 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08005170 }
5171
developer47cc27a2023-05-17 23:09:58 +08005172
5173 if (radio_idx == band_2_4) {
developere40952c2023-06-15 18:46:43 +08005174 res = snprintf(ssid, sizeof(ssid), "%s_%d", PREFIX_SSID_2G, bss_idx);
5175 if (os_snprintf_error(sizeof(ssid), res)) {
5176 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5177 return RETURN_ERR;
5178 }
5179
5180 res = snprintf(interface, sizeof(interface), "%s%d", PREFIX_WIFI2G, bss_idx);
5181 if (os_snprintf_error(sizeof(interface), res)) {
5182 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5183 return RETURN_ERR;
5184 }
developer47cc27a2023-05-17 23:09:58 +08005185 } else if (radio_idx == band_5) {
developere40952c2023-06-15 18:46:43 +08005186 res = snprintf(ssid, sizeof(ssid), "%s_%d", PREFIX_SSID_5G, bss_idx);
5187 if (os_snprintf_error(sizeof(ssid), res)) {
5188 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5189 return RETURN_ERR;
5190 }
5191
5192 res = snprintf(interface, sizeof(interface), "%s%d", PREFIX_WIFI5G, bss_idx);
5193 if (os_snprintf_error(sizeof(interface), res)) {
5194 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5195 return RETURN_ERR;
5196 }
developer47cc27a2023-05-17 23:09:58 +08005197 } else if (radio_idx == band_6) {
developere40952c2023-06-15 18:46:43 +08005198 res = snprintf(ssid, sizeof(ssid), "%s_%d", PREFIX_SSID_6G, bss_idx);
5199 if (os_snprintf_error(sizeof(ssid), res)) {
5200 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5201 return RETURN_ERR;
5202 }
5203
5204 res = snprintf(interface, sizeof(interface), "%s%d", PREFIX_WIFI6G, bss_idx);
5205 if (os_snprintf_error(sizeof(interface), res)) {
5206 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5207 return RETURN_ERR;
5208 }
developer47cc27a2023-05-17 23:09:58 +08005209 }
5210
5211 /* fix wpa_psk_file path */
developere40952c2023-06-15 18:46:43 +08005212 res = snprintf(psk_file, sizeof(psk_file), "\\/nvram\\/hostapd%d.psk", apIndex);
5213 if (os_snprintf_error(sizeof(psk_file), res)) {
5214 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5215 return RETURN_ERR;
5216 }
developer47cc27a2023-05-17 23:09:58 +08005217
5218 params[0].name = "ssid";
5219 params[0].value = ssid;
5220 params[1].name = "interface";
5221 params[1].value = interface;
5222 params[2].name = "wpa_psk_file";
5223 params[2].value = psk_file;
5224
5225 wifi_hostapdWrite(ap_config_file, params, 3);
5226
5227 /*clear psk file*/
developer8078acf2023-08-04 18:52:48 +08005228
developer47cc27a2023-05-17 23:09:58 +08005229 memset(ret_buf, 0, sizeof(ret_buf));
5230
developere40952c2023-06-15 18:46:43 +08005231 res = snprintf(psk_file, sizeof(psk_file), "%s%d.psk", PSK_FILE, apIndex);
5232 if (os_snprintf_error(sizeof(psk_file), res)) {
5233 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5234 return RETURN_ERR;
5235 }
developer47cc27a2023-05-17 23:09:58 +08005236
5237 if (access(psk_file, F_OK) != 0) {
developer8078acf2023-08-04 18:52:48 +08005238 res = _syscmd_secure(ret_buf,sizeof(ret_buf), "touch %s", psk_file);
5239 if (res) {
5240 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08005241 }
5242
developer47cc27a2023-05-17 23:09:58 +08005243 } else {
developer8078acf2023-08-04 18:52:48 +08005244
5245 res = _syscmd_secure(ret_buf,sizeof(ret_buf), "echo '' > %s", psk_file);
5246 if (res) {
5247 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08005248 }
5249
developer47cc27a2023-05-17 23:09:58 +08005250 }
5251
developer429ba832023-05-31 11:03:35 +08005252 wifi_setApEnable(apIndex, FALSE);
5253 wifi_setApEnable(apIndex, TRUE);
developer47cc27a2023-05-17 23:09:58 +08005254 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5255
5256 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005257}
5258
developer72fb0bb2023-01-11 09:46:29 +08005259INT wifi_setBandSteeringApGroup(char *ApGroup)
5260{
developera3511852023-06-14 14:12:59 +08005261 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005262}
5263
5264INT wifi_getApDTIMInterval(INT apIndex, INT *dtimInterval)
5265{
developera3511852023-06-14 14:12:59 +08005266 char config_file[128] = {'\0'};
5267 char buf[128] = {'\0'};
developere40952c2023-06-15 18:46:43 +08005268 int res;
developerc14d83a2023-06-29 20:09:42 +08005269 long int tmp;
developer5b23cd02023-07-19 20:26:03 +08005270
developera3511852023-06-14 14:12:59 +08005271 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
5272 if (dtimInterval == NULL)
5273 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08005274
5275 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
5276 if (os_snprintf_error(sizeof(config_file), res)) {
5277 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5278 return RETURN_ERR;
5279 }
developer72fb0bb2023-01-11 09:46:29 +08005280
developera3511852023-06-14 14:12:59 +08005281 wifi_hostapdRead(config_file, "dtim_period", buf, sizeof(buf));
developer72fb0bb2023-01-11 09:46:29 +08005282
developera3511852023-06-14 14:12:59 +08005283 if (strlen(buf) == 0) {
5284 *dtimInterval = 2;
5285 } else {
developerc14d83a2023-06-29 20:09:42 +08005286 if (hal_strtol(buf, 10, &tmp) < 0) {
5287 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08005288 }
developerc14d83a2023-06-29 20:09:42 +08005289 *dtimInterval = tmp;
developera3511852023-06-14 14:12:59 +08005290 }
developer72fb0bb2023-01-11 09:46:29 +08005291
developera3511852023-06-14 14:12:59 +08005292 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5293 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005294}
5295
5296INT wifi_setApDTIMInterval(INT apIndex, INT dtimInterval)
5297{
developera3511852023-06-14 14:12:59 +08005298 struct params params={0};
5299 char config_file[MAX_BUF_SIZE] = {'\0'};
5300 char buf[MAX_BUF_SIZE] = {'\0'};
developere40952c2023-06-15 18:46:43 +08005301 int res;
developer72fb0bb2023-01-11 09:46:29 +08005302
developera3511852023-06-14 14:12:59 +08005303 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
5304 if (dtimInterval < 1 || dtimInterval > 255) {
5305 WIFI_ENTRY_EXIT_DEBUG("Invalid dtimInterval: %d\n", dtimInterval);
5306 return RETURN_ERR;
5307 }
developer69b61b02023-03-07 17:17:44 +08005308
developera3511852023-06-14 14:12:59 +08005309 params.name = "dtim_period";
developere40952c2023-06-15 18:46:43 +08005310 res = snprintf(buf, sizeof(buf), "%d", dtimInterval);
5311 if (os_snprintf_error(sizeof(buf), res)) {
5312 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5313 return RETURN_ERR;
5314 }
developera3511852023-06-14 14:12:59 +08005315 params.value = buf;
developer72fb0bb2023-01-11 09:46:29 +08005316
developer75bd10c2023-06-27 11:34:08 +08005317 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
5318 if (os_snprintf_error(sizeof(config_file), res)) {
5319 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5320 return RETURN_ERR;
5321 }
developera3511852023-06-14 14:12:59 +08005322 wifi_hostapdWrite(config_file, &params, 1);
5323 wifi_hostapdProcessUpdate(apIndex, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +08005324
developera3511852023-06-14 14:12:59 +08005325 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5326 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005327}
5328
5329//Check if the driver support the Dfs
5330INT wifi_getRadioDfsSupport(INT radioIndex, BOOL *output_bool) //Tr181
5331{
developera3511852023-06-14 14:12:59 +08005332 wifi_band band = band_invalid;
5333 if (NULL == output_bool)
5334 return RETURN_ERR;
5335 *output_bool=FALSE;
developer72fb0bb2023-01-11 09:46:29 +08005336
developera3511852023-06-14 14:12:59 +08005337 band = wifi_index_to_band(radioIndex);
5338 if (band == band_5)
5339 *output_bool = TRUE;
5340 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005341}
5342
5343//The output_string is a max length 256 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
5344//The value of this parameter is a comma seperated list of channel number
5345INT wifi_getRadioDCSChannelPool(INT radioIndex, CHAR *output_pool) //RDKB
5346{
developer326d4232023-06-15 16:45:30 +08005347
5348 #define CHANNEL_AVAILABLE 0
5349 #define CHANNEL_INVALID 1
5350 #define CHANNEL_LIST_MAX_LENGTH 256
5351 #define MAX_CHANNEL_NUMBER 255
5352
5353 char config_file[MAX_BUF_SIZE] = {0};
5354 char possible_channels[CHANNEL_LIST_MAX_LENGTH] = {0};
5355 char skip_list[CHANNEL_LIST_MAX_LENGTH] = {0};
5356 int skip_table[MAX_CHANNEL_NUMBER +1] = {0};
5357 wifi_band band = band_invalid;
5358 char *token_channel = NULL, *token_skip = NULL;
developer75bd10c2023-06-27 11:34:08 +08005359 int res;
developere40952c2023-06-15 18:46:43 +08005360
developera3511852023-06-14 14:12:59 +08005361 if (NULL == output_pool)
5362 return RETURN_ERR;
developer326d4232023-06-15 16:45:30 +08005363 // get skiplist, possible_channels list
5364 wifi_getRadioPossibleChannels(radioIndex, possible_channels);
5365 band = wifi_index_to_band(radioIndex);
developer75bd10c2023-06-27 11:34:08 +08005366 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
5367 if (os_snprintf_error(sizeof(config_file), res)) {
5368 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5369 return RETURN_ERR;
5370 }
developer326d4232023-06-15 16:45:30 +08005371 wifi_datfileRead(config_file, "AutoChannelSkipList", skip_list, sizeof(skip_list));
5372
5373 if (skip_list[0] != '\0') {
5374 int len = strlen(skip_list);
5375 for (int i = 0; i < len; i++) {
5376 if (skip_list[i] == ';') {
5377 skip_list[i] = ',';
5378 }
5379 }
5380 // skip list
5381 token_skip = strtok(skip_list, ",");
5382 while (token_skip != NULL) {
5383 int channel = atoi(token_skip);
5384 if (channel <= MAX_CHANNEL_NUMBER && strstr(possible_channels, token_skip) != NULL)
5385 skip_table[atoi(token_skip)] = CHANNEL_INVALID;
5386 token_skip = strtok(NULL, ",");
5387 }
developere40952c2023-06-15 18:46:43 +08005388 }
developer72fb0bb2023-01-11 09:46:29 +08005389
developer326d4232023-06-15 16:45:30 +08005390 int count = 0;
5391 token_channel = strtok(possible_channels, ",");
5392 while (token_channel != NULL) {
5393 int channel = atoi(token_channel);
5394 if (channel <= MAX_CHANNEL_NUMBER && skip_table[channel] == CHANNEL_AVAILABLE) {
5395 count += snprintf(&output_pool[count], CHANNEL_LIST_MAX_LENGTH-count, "%d,", channel);
5396 if (count >= CHANNEL_LIST_MAX_LENGTH-1)
5397 break;
5398 }
5399 token_channel = strtok(NULL, ",");
5400 }
5401 //delete the last one ','
5402 if (count >0 && output_pool[count-1] == ',')
5403 output_pool[count-1] = '\0';
developera3511852023-06-14 14:12:59 +08005404 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005405}
5406
5407INT wifi_setRadioDCSChannelPool(INT radioIndex, CHAR *pool) //RDKB
5408{
developer326d4232023-06-15 16:45:30 +08005409 char config_file_dat[128] = {0};
5410 struct params dat = {0};
5411 wifi_band band = band_invalid;
5412 char new_pool[128] = {0};
developer75bd10c2023-06-27 11:34:08 +08005413 int res;
developer326d4232023-06-15 16:45:30 +08005414
5415 if (NULL == pool)
5416 return RETURN_ERR;
5417
developer9ce44382023-06-28 11:09:37 +08005418 strncpy(new_pool, pool, sizeof(new_pool) - 1);
5419 new_pool[sizeof(new_pool) - 1] = '\0';
developer326d4232023-06-15 16:45:30 +08005420 for (int i = 0; new_pool[i] != '\0'; i++) {
5421 if (new_pool[i] == ',')
5422 new_pool[i] = ';';
5423 }
5424
5425 dat.name = "AutoChannelSkipList";
5426 dat.value = new_pool;
5427 band = wifi_index_to_band(radioIndex);
developer75bd10c2023-06-27 11:34:08 +08005428 res = snprintf(config_file_dat, sizeof(config_file_dat), "%s%d.dat", LOGAN_DAT_FILE, band);
5429 if (os_snprintf_error(sizeof(config_file_dat), res)) {
5430 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5431 return RETURN_ERR;
5432 }
developer326d4232023-06-15 16:45:30 +08005433 if (wifi_datfileWrite(config_file_dat, &dat, 1) != 0)
5434 return RETURN_ERR;
5435 wifi_reloadAp(radioIndex);
5436
developera3511852023-06-14 14:12:59 +08005437 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005438}
5439
5440INT wifi_getRadioDCSScanTime(INT radioIndex, INT *output_interval_seconds, INT *output_dwell_milliseconds)
5441{
developera3511852023-06-14 14:12:59 +08005442 if (NULL == output_interval_seconds || NULL == output_dwell_milliseconds)
5443 return RETURN_ERR;
developer326d4232023-06-15 16:45:30 +08005444 //Should refresh period time be filled in here? output_interval_seconds is INT type
5445 //wifi_getRadioAutoChannelRefreshPeriod is Ulong type
5446 *output_interval_seconds = 1800;
5447 *output_dwell_milliseconds = 200;
developer72fb0bb2023-01-11 09:46:29 +08005448
developera3511852023-06-14 14:12:59 +08005449 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005450}
5451
5452INT wifi_setRadioDCSScanTime(INT radioIndex, INT interval_seconds, INT dwell_milliseconds)
5453{
developera3511852023-06-14 14:12:59 +08005454 //Set to wifi config. And apply instantly.
5455 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005456}
5457
5458INT wifi_getRadioDfsAtBootUpEnable(INT radioIndex, BOOL *output_bool) //Tr181
5459{
developera3511852023-06-14 14:12:59 +08005460 if (output_bool == NULL)
5461 return RETURN_ERR;
5462 *output_bool = true;
5463 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005464}
5465
5466INT wifi_setRadioDfsAtBootUpEnable(INT radioIndex, BOOL enable) //Tr181
5467{
developera3511852023-06-14 14:12:59 +08005468 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005469}
5470
5471//Get the Dfs enable status
5472INT wifi_getRadioDfsEnable(INT radioIndex, BOOL *output_bool) //Tr181
5473{
developera3511852023-06-14 14:12:59 +08005474 char buf[16] = {0};
5475 char config_file_dat[128] = {0};
5476 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08005477 int res;
developer72fb0bb2023-01-11 09:46:29 +08005478
developera3511852023-06-14 14:12:59 +08005479 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08005480
developera3511852023-06-14 14:12:59 +08005481 if (output_bool == NULL)
5482 return RETURN_ERR;
5483 *output_bool = TRUE; // default
5484 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +08005485 res = snprintf(config_file_dat, sizeof(config_file_dat), "%s%d.dat", LOGAN_DAT_FILE, band);
5486 if (os_snprintf_error(sizeof(config_file_dat), res)) {
5487 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5488 return RETURN_ERR;
5489 }
developerd1824452023-05-18 12:30:04 +08005490
developera3511852023-06-14 14:12:59 +08005491 wifi_datfileRead(config_file_dat, "DfsEnable", buf, sizeof(buf));
developerd1824452023-05-18 12:30:04 +08005492
developera3511852023-06-14 14:12:59 +08005493 if (strncmp(buf, "0", 1) == 0)
5494 *output_bool = FALSE;
5495 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5496 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005497}
5498
5499//Set the Dfs enable status
5500INT wifi_setRadioDfsEnable(INT radioIndex, BOOL enable) //Tr181
5501{
developera3511852023-06-14 14:12:59 +08005502 char config_dat_file[128] = {0};
5503 FILE *f = NULL;
5504 struct params dat = {0};
5505 wifi_band band = band_invalid;
developer75bd10c2023-06-27 11:34:08 +08005506 int res, ret;
developer72fb0bb2023-01-11 09:46:29 +08005507
developera3511852023-06-14 14:12:59 +08005508 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08005509
developera3511852023-06-14 14:12:59 +08005510 f = fopen(DFS_ENABLE_FILE, "w");
5511 if (f == NULL)
5512 return RETURN_ERR;
developer75bd10c2023-06-27 11:34:08 +08005513 ret = fprintf(f, "%d", enable);
5514 if (ret < 0)
5515 wifi_debug(DEBUG_ERROR, "fprintf fail\n");
developerd14dff12023-06-28 22:47:44 +08005516 if (fclose(f) != 0) {
5517 wifi_debug(DEBUG_ERROR, "fclose fail\n");
5518 return RETURN_ERR;
5519 }
developer72fb0bb2023-01-11 09:46:29 +08005520
developera3511852023-06-14 14:12:59 +08005521 wifi_setRadioIEEE80211hEnabled(radioIndex, enable);
developer72fb0bb2023-01-11 09:46:29 +08005522
developera3511852023-06-14 14:12:59 +08005523 dat.name = "DfsEnable";
5524 dat.value = enable?"1":"0";
5525 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +08005526 res = snprintf(config_dat_file, sizeof(config_dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
5527 if (os_snprintf_error(sizeof(config_dat_file), res)) {
5528 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5529 return RETURN_ERR;
5530 }
5531
developera3511852023-06-14 14:12:59 +08005532 wifi_datfileWrite(config_dat_file, &dat, 1);
5533 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5534 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005535}
5536
5537//Check if the driver support the AutoChannelRefreshPeriod
5538INT wifi_getRadioAutoChannelRefreshPeriodSupported(INT radioIndex, BOOL *output_bool) //Tr181
5539{
developera3511852023-06-14 14:12:59 +08005540 if (NULL == output_bool)
5541 return RETURN_ERR;
developer326d4232023-06-15 16:45:30 +08005542 *output_bool = TRUE;
developer72fb0bb2023-01-11 09:46:29 +08005543
developera3511852023-06-14 14:12:59 +08005544 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005545}
5546
developer326d4232023-06-15 16:45:30 +08005547
5548int get_ACS_RefreshPeriod_callback(struct nl_msg *msg, void *arg)
5549{
5550 ULONG *data = (ULONG *)arg;
5551 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5552 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_MAX + 1];
5553 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5554 int err = 0;
5555
5556 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5557 genlmsg_attrlen(gnlh, 0), NULL);
5558 if (err < 0)
5559 return NL_SKIP;
5560
5561 if (tb[NL80211_ATTR_VENDOR_DATA]) {
5562 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_MAX,
5563 tb[NL80211_ATTR_VENDOR_DATA], NULL);
5564 if (err < 0)
5565 return NL_SKIP;
5566
5567 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_ACS_REFRESH_PERIOD]) {
5568 *data = nla_get_u32(vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_ACS_REFRESH_PERIOD]);
5569 }
5570 }
5571
5572 return NL_OK;
5573}
5574
developer72fb0bb2023-01-11 09:46:29 +08005575//Get the ACS refresh period in seconds
5576INT wifi_getRadioAutoChannelRefreshPeriod(INT radioIndex, ULONG *output_ulong) //Tr181
5577{
developer326d4232023-06-15 16:45:30 +08005578 char interface_name[IF_NAME_SIZE] = {0};
5579 int ret = -1;
5580 unsigned int if_idx = 0;
5581 struct unl unl_ins;
5582 struct nl_msg *msg = NULL;
5583 struct nlattr * msg_data = NULL;
5584 struct mtk_nl80211_param param;
5585 unsigned long checktime = 0;
5586
5587 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developera3511852023-06-14 14:12:59 +08005588 if (NULL == output_ulong)
5589 return RETURN_ERR;
developer326d4232023-06-15 16:45:30 +08005590
5591 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
5592 return RETURN_ERR;
5593
5594 if_idx = if_nametoindex(interface_name);
5595 if (!if_idx) {
5596 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", interface_name);
5597 return RETURN_ERR;
5598 }
5599 /*init mtk nl80211 vendor cmd*/
5600 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_GET_RUNTIME_INFO;
5601 param.if_type = NL80211_ATTR_IFINDEX;
5602 param.if_idx = if_idx;
developer72fb0bb2023-01-11 09:46:29 +08005603
developer326d4232023-06-15 16:45:30 +08005604 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
5605 if (ret) {
5606 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
5607 return RETURN_ERR;
5608 }
5609
5610 /*add mtk vendor cmd data*/
5611 if (nla_put_u32(msg, MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_ACS_REFRESH_PERIOD, 0)) {
5612 wifi_debug(DEBUG_ERROR, "Nla put GET_RUNTIME_INFO_GET_ACS_REFRESH_PERIOD attribute error\n");
5613 nlmsg_free(msg);
5614 goto err;
5615 }
5616
5617 /*send mtk nl80211 vendor msg*/
5618 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, get_ACS_RefreshPeriod_callback, &checktime);
5619
5620 if (ret) {
5621 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
5622 goto err;
5623 }
5624 /*deinit mtk nl80211 vendor msg*/
5625 mtk_nl80211_deint(&unl_ins);
5626 *output_ulong = checktime;
5627 wifi_debug(DEBUG_NOTICE,"send cmd success\n");
5628
5629 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developera3511852023-06-14 14:12:59 +08005630 return RETURN_OK;
developer326d4232023-06-15 16:45:30 +08005631err:
5632 mtk_nl80211_deint(&unl_ins);
5633 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
5634 return RETURN_ERR;
5635
developer72fb0bb2023-01-11 09:46:29 +08005636}
5637
5638//Set the ACS refresh period in seconds
5639INT wifi_setRadioDfsRefreshPeriod(INT radioIndex, ULONG seconds) //Tr181
5640{
developer326d4232023-06-15 16:45:30 +08005641 char interface_name[IF_NAME_SIZE] = {0};
5642 int ret = -1;
5643 unsigned int if_idx = 0;
5644 struct unl unl_ins;
5645 struct nl_msg *msg = NULL;
5646 struct nlattr * msg_data = NULL;
5647 struct mtk_nl80211_param param;
5648
5649 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
5650
5651 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
5652 return RETURN_ERR;
5653
5654 if_idx = if_nametoindex(interface_name);
5655 if (!if_idx) {
5656 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", interface_name);
5657 return RETURN_ERR;
5658 }
5659 /*init mtk nl80211 vendor cmd*/
5660 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AUTO_CH_SEL;
5661 param.if_type = NL80211_ATTR_IFINDEX;
5662 param.if_idx = if_idx;
5663
5664 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
5665 if (ret) {
5666 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
5667 return RETURN_ERR;
5668 }
5669
5670 /*add mtk vendor cmd data*/
5671 if (nla_put_u32(msg, MTK_NL80211_VENDOR_ATTR_AUTO_CH_CHECK_TIME, seconds)) {
5672 wifi_debug(DEBUG_ERROR, "Nla put MTK_NL80211_VENDOR_ATTR_AUTO_CH_CHECK_TIME attribute error\n");
5673 nlmsg_free(msg);
5674 goto err;
5675 }
5676
5677 /*send mtk nl80211 vendor msg*/
5678 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
5679
5680 if (ret) {
5681 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
5682 goto err;
5683 }
5684 /*deinit mtk nl80211 vendor msg*/
5685 mtk_nl80211_deint(&unl_ins);
5686 wifi_debug(DEBUG_NOTICE,"send cmd success\n");
5687
5688 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5689 return RETURN_OK;
5690err:
5691 mtk_nl80211_deint(&unl_ins);
5692 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
developera3511852023-06-14 14:12:59 +08005693 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08005694}
5695
developer408cde72023-10-19 13:44:02 +08005696int get_bandwidth_handler(struct nl_msg *msg, void *data)
5697{
5698 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5699 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_MAX + 1];
5700 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5701 unsigned char *bw = (unsigned char *)data;
5702 int err = 0;
5703
5704 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5705 genlmsg_attrlen(gnlh, 0), NULL);
5706 if (err < 0)
5707 return err;
5708
5709 if (tb[NL80211_ATTR_VENDOR_DATA]) {
5710 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_MAX,
5711 tb[NL80211_ATTR_VENDOR_DATA], NULL);
5712 if (err < 0)
5713 return err;
5714
5715 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH]) {
5716 *bw = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH]);
5717 }
5718 }
5719
5720 return 0;
5721}
5722
5723enum bw_idx {
5724 BAND_WIDTH_20,
5725 BAND_WIDTH_40,
5726 BAND_WIDTH_80,
5727 BAND_WIDTH_160,
5728 BAND_WIDTH_8080 = 6,
5729 BAND_WIDTH_320
5730};
5731
5732int bwidx_to_string(unsigned char bw, char *buf)
5733{
5734 int res;
5735 switch (bw) {
5736 case BAND_WIDTH_20:
5737 res = snprintf(buf, 32, "%s", "20");
5738 if (os_snprintf_error(64, res)) {
5739 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5740 return -1;
5741 }
5742 break;
5743 case BAND_WIDTH_40:
5744 res = snprintf(buf, 32, "%s", "40");
5745 if (os_snprintf_error(64, res)) {
5746 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5747 return -1;
5748 }
5749 break;
5750 case BAND_WIDTH_80:
5751 res = snprintf(buf, 32, "%s", "80");
5752 if (os_snprintf_error(64, res)) {
5753 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5754 return -1;
5755 }
5756 break;
5757 case BAND_WIDTH_160:
5758 res = snprintf(buf, 32, "%s", "160");
5759 if (os_snprintf_error(64, res)) {
5760 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5761 return -1;
5762 }
5763 break;
5764 case BAND_WIDTH_8080:
5765 res = snprintf(buf, 32, "%s", "80+80");
5766 if (os_snprintf_error(64, res)) {
5767 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5768 return -1;
5769 }
5770 break;
5771 case BAND_WIDTH_320:
5772 res = snprintf(buf, 32, "%s", "320");
5773 if (os_snprintf_error(64, res)) {
5774 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5775 return -1;
5776 }
5777 break;
5778 default:
5779 wifi_debug(DEBUG_ERROR, "unkown bw[%d]\n", bw);
5780 return -1;
5781 }
5782
5783 return 0;
5784}
5785
developer72fb0bb2023-01-11 09:46:29 +08005786//Get the Operating Channel Bandwidth. eg "20MHz", "40MHz", "80MHz", "80+80", "160"
5787//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
5788INT wifi_getRadioOperatingChannelBandwidth(INT radioIndex, CHAR *output_string) //Tr181
5789{
developer408cde72023-10-19 13:44:02 +08005790 char buf[32] = {0};
developera3511852023-06-14 14:12:59 +08005791 char extchannel[128] = {0};
developer408cde72023-10-19 13:44:02 +08005792 int ret = 0, res;
developera3511852023-06-14 14:12:59 +08005793 BOOL radio_enable = FALSE;
5794 wifi_band band;
developer408cde72023-10-19 13:44:02 +08005795 unsigned char bw;
developer72fb0bb2023-01-11 09:46:29 +08005796
developera3511852023-06-14 14:12:59 +08005797 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08005798
developera3511852023-06-14 14:12:59 +08005799 if (NULL == output_string) {
5800 WIFI_ENTRY_EXIT_DEBUG("output_string is nuill %s: %d \n", __func__, __LINE__);
5801 return RETURN_ERR;
5802 }
5803 if (wifi_getRadioEnable(radioIndex, &radio_enable) == RETURN_ERR) {
5804 WIFI_ENTRY_EXIT_DEBUG("wifi_getRadioEnable failed %s: %d \n", __func__, __LINE__);
5805 return RETURN_ERR;
5806 }
5807 if (radio_enable != TRUE) {
5808 WIFI_ENTRY_EXIT_DEBUG("Radio %d is not enable failed %s: %d \n", radioIndex, __func__, __LINE__);
5809 return RETURN_OK;
5810 }
developer408cde72023-10-19 13:44:02 +08005811 if (mtk_wifi_get_radio_info(radioIndex, MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH,
5812 get_bandwidth_handler, &bw)!= RETURN_OK) {
5813 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH cmd fails\n");
developere40952c2023-06-15 18:46:43 +08005814 return RETURN_ERR;
5815 }
developer8078acf2023-08-04 18:52:48 +08005816
developer408cde72023-10-19 13:44:02 +08005817 ret = bwidx_to_string(bw, buf);
5818 if (ret) {
5819 wifi_debug(DEBUG_ERROR, "bwidx_to_string fails\n");
developera3511852023-06-14 14:12:59 +08005820 return RETURN_ERR;
5821 }
developer8666b312023-03-24 14:05:31 +08005822
developera3511852023-06-14 14:12:59 +08005823 band = wifi_index_to_band(radioIndex);
5824 if (band == band_2_4 && strncmp(buf, "20", 2) == 0) {
5825 wifi_getRadioExtChannel(radioIndex, extchannel);
developere40952c2023-06-15 18:46:43 +08005826 if (strncmp(extchannel, "Auto", 4) != 0) {
5827 res = snprintf(buf, sizeof(buf), "40");
5828 if (os_snprintf_error(sizeof(buf), res)) {
5829 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5830 return RETURN_ERR;
5831 }
5832 }
5833 }
5834 res = snprintf(output_string, 64, "%sMHz", buf);
5835 if (os_snprintf_error(64, res)) {
5836 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5837 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +08005838 }
developera3511852023-06-14 14:12:59 +08005839 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08005840
developera3511852023-06-14 14:12:59 +08005841 return RETURN_OK;
developerfead3972023-05-25 20:15:02 +08005842}
5843
developer72fb0bb2023-01-11 09:46:29 +08005844//Set the Operating Channel Bandwidth.
5845INT wifi_setRadioOperatingChannelBandwidth(INT radioIndex, CHAR *bandwidth) //Tr181 //AP only
5846{
developera3511852023-06-14 14:12:59 +08005847 char config_file[128];
5848 char ht_value[16];
5849 char vht_value[16];
5850 char eht_value[16];
5851 struct params dat[3];
5852 wifi_band band = band_invalid;
5853 unsigned int bw = 20;
developere40952c2023-06-15 18:46:43 +08005854 int ret = 0, res1, res2, res3;
developer72fb0bb2023-01-11 09:46:29 +08005855
developera3511852023-06-14 14:12:59 +08005856 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08005857
developera3511852023-06-14 14:12:59 +08005858 if(NULL == bandwidth)
5859 return RETURN_ERR;
5860 band = wifi_index_to_band(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +08005861
developera3511852023-06-14 14:12:59 +08005862 if(strstr(bandwidth,"320") != NULL) {
developere40952c2023-06-15 18:46:43 +08005863 res1 = snprintf(ht_value, sizeof(ht_value), "%d", HT_BW_40);
5864 res2 = snprintf(vht_value, sizeof(vht_value), "%d", VHT_BW_160);
5865 res3 = snprintf(eht_value, sizeof(eht_value), "%d", EHT_BW_320);
developera3511852023-06-14 14:12:59 +08005866 bw = 320;
5867 } else if(strstr(bandwidth,"160") != NULL) {
developere40952c2023-06-15 18:46:43 +08005868 res1 = snprintf(ht_value, sizeof(ht_value), "%d", HT_BW_40);
5869 res2 = snprintf(vht_value, sizeof(vht_value), "%d", VHT_BW_160);
5870 res3 = snprintf(eht_value, sizeof(eht_value), "%d", EHT_BW_160);
developera3511852023-06-14 14:12:59 +08005871 bw = 160;
5872 } else if(strstr(bandwidth,"80") != NULL) {
developere40952c2023-06-15 18:46:43 +08005873 res1 = snprintf(ht_value, sizeof(ht_value), "%d", HT_BW_40);
5874 res2 = snprintf(vht_value, sizeof(vht_value), "%d", VHT_BW_80);
5875 res3 = snprintf(eht_value, sizeof(eht_value), "%d", EHT_BW_80);
developera3511852023-06-14 14:12:59 +08005876 bw = 80;
5877 } else if(strstr(bandwidth,"40") != NULL) {
developere40952c2023-06-15 18:46:43 +08005878 res1 = snprintf(ht_value, sizeof(ht_value), "%d", HT_BW_40);
5879 res2 = snprintf(vht_value, sizeof(vht_value), "%d", VHT_BW_2040);
5880 res3 = snprintf(eht_value, sizeof(eht_value), "%d", EHT_BW_40);
developera3511852023-06-14 14:12:59 +08005881 bw = 40;
5882 } else if(strstr(bandwidth,"20") != NULL) {
developere40952c2023-06-15 18:46:43 +08005883 res1 = snprintf(ht_value, sizeof(ht_value), "%d", HT_BW_20);
5884 res2 = snprintf(vht_value, sizeof(vht_value), "%d", VHT_BW_2040);
5885 res3 = snprintf(eht_value, sizeof(eht_value), "%d", EHT_BW_20);
developera3511852023-06-14 14:12:59 +08005886 bw = 20;
5887 } else {
developer37646972023-06-29 10:58:43 +08005888 if (fprintf(stderr, "%s: Invalid Bandwidth %s\n", __func__, bandwidth) < 0)
5889 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
developera3511852023-06-14 14:12:59 +08005890 return RETURN_ERR;
5891 }
developer72fb0bb2023-01-11 09:46:29 +08005892
developer37646972023-06-29 10:58:43 +08005893 if (os_snprintf_error(sizeof(ht_value), res1) ||
5894 os_snprintf_error(sizeof(vht_value), res2) ||
5895 os_snprintf_error(sizeof(eht_value), res3)) {
developere40952c2023-06-15 18:46:43 +08005896 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5897 return RETURN_ERR;
5898 }
5899
5900 res1 = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
5901 if (os_snprintf_error(sizeof(config_file), res1)) {
5902 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5903 return RETURN_ERR;
5904 }
developera3511852023-06-14 14:12:59 +08005905 dat[0].name = "HT_BW";
5906 dat[0].value = ht_value;
5907 dat[1].name = "VHT_BW";
5908 dat[1].value = vht_value;
5909 dat[2].name = "EHT_ApBw";
5910 dat[2].value = eht_value;
5911 wifi_datfileWrite(config_file, dat, 3);
developereef7d562023-10-21 16:04:21 +08005912
5913 /*do bw quick setting*/
5914 ret = wifi_setChannel_netlink(radioIndex, NULL, &bw, NULL, NULL);
developerfead3972023-05-25 20:15:02 +08005915 if (ret != RETURN_OK) {
developereef7d562023-10-21 16:04:21 +08005916 wifi_debug(DEBUG_ERROR, "bw quick setting fail\n");
developer37646972023-06-29 10:58:43 +08005917 if (fprintf(stderr, "%s: wifi_setChannel return error.\n", __func__) < 0)
5918 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
developera3511852023-06-14 14:12:59 +08005919 }
developer72fb0bb2023-01-11 09:46:29 +08005920
developera3511852023-06-14 14:12:59 +08005921 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
5922 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08005923}
5924
developer72fb0bb2023-01-11 09:46:29 +08005925//Get the secondary extension channel position, "AboveControlChannel" or "BelowControlChannel". (this is for 40MHz and 80MHz bandwith only)
5926//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
5927INT wifi_getRadioExtChannel(INT radioIndex, CHAR *output_string) //Tr181
5928{
developera3511852023-06-14 14:12:59 +08005929 char config_file[64] = {0};
5930 char config_dat_file[64] = {0};
5931 char mode_str[16] = {0};
5932 char buf[64] = {0};
5933 char cmd[MAX_CMD_SIZE] = {0};
5934 char interface_name[64] = {0};
5935 int ret = 0, len=0;
5936 wifi_band band;
5937 ULONG channel = 0;
5938 int centr_channel = 0;
5939 UINT mode_map = 0;
developere40952c2023-06-15 18:46:43 +08005940 int freq=0, res;
developer72fb0bb2023-01-11 09:46:29 +08005941
developera3511852023-06-14 14:12:59 +08005942 if (output_string == NULL)
5943 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08005944
developer86035662023-06-28 19:21:12 +08005945 if (wifi_getRadioMode(radioIndex, mode_str, &mode_map) != RETURN_OK) {
5946 wifi_debug(DEBUG_ERROR, "wifi_getRadioMode fail\n");
5947 }
developer72fb0bb2023-01-11 09:46:29 +08005948
developera3511852023-06-14 14:12:59 +08005949 band = wifi_index_to_band(radioIndex);
5950 if (band == band_invalid)
5951 return RETURN_ERR;
5952 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
5953 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08005954
developere40952c2023-06-15 18:46:43 +08005955 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
5956 if (os_snprintf_error(sizeof(config_file), res)) {
5957 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5958 return RETURN_ERR;
5959 }
5960
5961 res = snprintf(output_string, 64, "Auto");
5962 if (os_snprintf_error(64, res)) {
5963 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5964 return RETURN_ERR;
5965 }
developer72fb0bb2023-01-11 09:46:29 +08005966
developera3511852023-06-14 14:12:59 +08005967 if (band == band_2_4 || (!(mode_map&WIFI_MODE_AC) && !(mode_map&WIFI_MODE_AX))) {
5968 // 2G band or ac and ax mode is disable, we will check HT_EXTCHA
developere40952c2023-06-15 18:46:43 +08005969 res = snprintf(config_dat_file, sizeof(config_dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
5970 if (os_snprintf_error(sizeof(config_dat_file), res)) {
5971 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5972 return RETURN_ERR;
5973 }
developerb758dfd2023-06-21 17:32:07 +08005974
developera3511852023-06-14 14:12:59 +08005975 wifi_halgetRadioExtChannel(config_dat_file, output_string);
developer37646972023-06-29 10:58:43 +08005976 if (!(mode_map&WIFI_MODE_N)) {
developere40952c2023-06-15 18:46:43 +08005977 res = snprintf(output_string, 64, "Auto");
developer37646972023-06-29 10:58:43 +08005978 if (os_snprintf_error(64, res)) {
5979 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5980 return RETURN_ERR;
5981 }
5982 }
developera3511852023-06-14 14:12:59 +08005983 } else {
5984 // 5G and 6G band with ac or ax mode.
5985 wifi_getRadioChannel(radioIndex, &channel);
developere40952c2023-06-15 18:46:43 +08005986 res = snprintf(cmd, sizeof(cmd),"iw dev %s info | grep 'center1' | cut -d ' ' -f9 | tr -d '\\n'", interface_name);
5987 if (os_snprintf_error(sizeof(cmd), res)) {
5988 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
5989 return RETURN_ERR;
5990 }
developerd1824452023-05-18 12:30:04 +08005991
developer8078acf2023-08-04 18:52:48 +08005992 ret = _syscmd_secure(buf, sizeof(buf), "iw dev %s info | grep 'center1' | cut -d ' ' -f9 | tr -d '\\n'", interface_name);
5993 if(ret) {
5994 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
5995 }
5996
developera3511852023-06-14 14:12:59 +08005997 len = strlen(buf);
5998 if((ret != 0) || (len == 0))
5999 {
6000 WIFI_ENTRY_EXIT_DEBUG("failed with Command %s %s:%d\n",cmd,__func__, __LINE__);
6001 return RETURN_ERR;
6002 }
6003 sscanf(buf, "%d", &freq);
6004 centr_channel = ieee80211_frequency_to_channel(freq);
6005 if (centr_channel > (int)channel)
developere40952c2023-06-15 18:46:43 +08006006 res = snprintf(output_string, 64, "AboveControlChannel");
developera3511852023-06-14 14:12:59 +08006007 else
developere40952c2023-06-15 18:46:43 +08006008 res = snprintf(output_string, 64, "BelowControlChannel");
6009
6010 if (os_snprintf_error(64, res)) {
6011 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6012 return RETURN_ERR;
6013 }
developera3511852023-06-14 14:12:59 +08006014 }
developer72fb0bb2023-01-11 09:46:29 +08006015
developera3511852023-06-14 14:12:59 +08006016 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006017}
6018
6019//Set the extension channel.
6020INT wifi_setRadioExtChannel(INT radioIndex, CHAR *string) //Tr181 //AP only
developer69b61b02023-03-07 17:17:44 +08006021{
developera3511852023-06-14 14:12:59 +08006022 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6023 struct params params={0};
6024 char config_file[64] = {0};
6025 char config_dat_file[64] = {0};
6026 char ext_channel[64] = {0};
developereef7d562023-10-21 16:04:21 +08006027 unsigned char ext_ch;
developera3511852023-06-14 14:12:59 +08006028 char buf[128] = {0};
developerc14d83a2023-06-29 20:09:42 +08006029 int max_radio_num =0, ret = 0;
6030 long int bandwidth = 0;
developera3511852023-06-14 14:12:59 +08006031 unsigned long channel = 0;
6032 bool stbcEnable = FALSE;
6033 params.name = "ht_capab";
6034 wifi_band band;
developere40952c2023-06-15 18:46:43 +08006035 int res;
developer72fb0bb2023-01-11 09:46:29 +08006036
developer75bd10c2023-06-27 11:34:08 +08006037 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
6038 if (os_snprintf_error(sizeof(config_file), res)) {
6039 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6040 return RETURN_ERR;
6041 }
6042
developer8078acf2023-08-04 18:52:48 +08006043 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep STBC", config_file);
6044 if(res) {
6045 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08006046 }
developer8078acf2023-08-04 18:52:48 +08006047
developera3511852023-06-14 14:12:59 +08006048 if (strlen(buf) != 0)
6049 stbcEnable = TRUE;
6050 if (wifi_getRadioOperatingChannelBandwidth(radioIndex, buf) != RETURN_OK)
6051 return RETURN_ERR;
developerc14d83a2023-06-29 20:09:42 +08006052 if (hal_strtol(buf, 10, &bandwidth) < 0) {
6053 wifi_debug(DEBUG_ERROR, "strtol fail\n");
6054 }
developera3511852023-06-14 14:12:59 +08006055 // TDK expected to get error with 20MHz
6056 // we handle 20MHz in function wifi_RemoveRadioExtChannel().
6057 if (bandwidth == 20 || strstr(buf, "80+80") != NULL)
6058 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006059
developera3511852023-06-14 14:12:59 +08006060 band = wifi_index_to_band(radioIndex);
6061 if (band == band_invalid)
6062 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006063
developera3511852023-06-14 14:12:59 +08006064 if (wifi_getRadioChannel(radioIndex, &channel) != RETURN_OK)
6065 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006066
developerc14d83a2023-06-29 20:09:42 +08006067 res = snprintf(buf, sizeof(buf), "HT%ld", bandwidth);
developere40952c2023-06-15 18:46:43 +08006068 if (os_snprintf_error(sizeof(buf), res)) {
6069 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6070 return RETURN_ERR;
6071 }
developera3511852023-06-14 14:12:59 +08006072 ret = util_get_sec_chan_offset(channel, buf);
6073 if (ret == -EINVAL)
6074 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006075
developera3511852023-06-14 14:12:59 +08006076 if(NULL!= strstr(string,"Above")) {
6077 if ((band == band_2_4 && channel > 9) || (band == band_5 && ret == -1))
6078 return RETURN_OK;
developerb14b3462023-07-01 18:02:42 +08006079 memcpy(ext_channel, "1", strlen("1"));
developereef7d562023-10-21 16:04:21 +08006080 ext_ch = 1;
developera3511852023-06-14 14:12:59 +08006081 } else if(NULL!= strstr(string,"Below")) {
6082 if ((band == band_2_4 && channel < 5) || (band == band_5 && ret == -1))
6083 return RETURN_OK;
developerb14b3462023-07-01 18:02:42 +08006084 memcpy(ext_channel, "0", strlen("0"));
developereef7d562023-10-21 16:04:21 +08006085 ext_ch = 0;
developera3511852023-06-14 14:12:59 +08006086 } else {
6087 printf("%s: invalid EXT_CHA:%s\n", __func__, string);
developereef7d562023-10-21 16:04:21 +08006088 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +08006089 }
6090 params.name = "HT_EXTCHA";
6091 params.value = ext_channel;
developer72fb0bb2023-01-11 09:46:29 +08006092
developere75ba632023-06-29 16:03:33 +08006093 res = snprintf (config_dat_file, sizeof(config_dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
developere40952c2023-06-15 18:46:43 +08006094 if (os_snprintf_error(sizeof(config_dat_file), res)) {
6095 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6096 return RETURN_ERR;
6097 }
developera3511852023-06-14 14:12:59 +08006098 wifi_datfileWrite(config_dat_file, &params, 1);
developerd1824452023-05-18 12:30:04 +08006099
developera3511852023-06-14 14:12:59 +08006100 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +08006101 if(max_radio_num== 0){
6102 return RETURN_ERR;
6103 }
developera3511852023-06-14 14:12:59 +08006104 for(int i=0; i<=MAX_APS/max_radio_num; i++)
6105 {
developer32f2a182023-06-27 19:50:41 +08006106 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,radioIndex+(max_radio_num*i));
6107 if (os_snprintf_error(sizeof(config_file), res)) {
6108 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6109 return RETURN_ERR;
6110 }
developera3511852023-06-14 14:12:59 +08006111 wifi_setRadioSTBCEnable(radioIndex+(max_radio_num*i), stbcEnable);
6112 }
developer72fb0bb2023-01-11 09:46:29 +08006113
developereef7d562023-10-21 16:04:21 +08006114 /*do ext_ch quicking setting*/
6115 if (ext_ch != -1) {
6116 ret = wifi_setChannel_netlink(radioIndex, NULL, NULL, &ext_ch, NULL);
6117 if (ret != RETURN_OK)
6118 wifi_debug(DEBUG_ERROR, "ext_ch quicking setting fail\n");
6119 }
6120
developera3511852023-06-14 14:12:59 +08006121 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6122 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006123}
6124
6125//Get the guard interval value. eg "400nsec" or "800nsec"
6126//The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
6127INT wifi_getRadioGuardInterval(INT radioIndex, CHAR *output_string) //Tr181
6128{
developera3511852023-06-14 14:12:59 +08006129 wifi_guard_interval_t GI;
developer32f2a182023-06-27 19:50:41 +08006130 unsigned long len;
developer72fb0bb2023-01-11 09:46:29 +08006131
developera3511852023-06-14 14:12:59 +08006132 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08006133
developera3511852023-06-14 14:12:59 +08006134 if (output_string == NULL || wifi_getGuardInterval(radioIndex, &GI) == RETURN_ERR)
6135 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006136
developer32f2a182023-06-27 19:50:41 +08006137 if (GI == wifi_guard_interval_400) {
6138 len = strlen("400nsec");
6139 memcpy(output_string, "400nsec", len);
developer5b23cd02023-07-19 20:26:03 +08006140 } else if (GI == wifi_guard_interval_800) {
developer32f2a182023-06-27 19:50:41 +08006141 len = strlen("800nsec");
6142 memcpy(output_string, "800nsec", strlen("800nsec"));
6143 } else if (GI == wifi_guard_interval_1600) {
6144 len = strlen("1600nsec");
6145 memcpy(output_string, "1600nsec", strlen("1600nsec"));
6146 } else if (GI == wifi_guard_interval_3200) {
6147 len = strlen("3200nsec");
6148 memcpy(output_string, "3200nsec", strlen("3200nsec"));
6149 } else {
6150 len = strlen("Auto");
6151 memcpy(output_string, "Auto", strlen("Auto"));
6152 }
6153 output_string[len] = '\0';
developera3511852023-06-14 14:12:59 +08006154 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6155 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006156}
6157
6158//Set the guard interval value.
6159INT wifi_setRadioGuardInterval(INT radioIndex, CHAR *string) //Tr181
6160{
developera3511852023-06-14 14:12:59 +08006161 wifi_guard_interval_t GI;
6162 int ret = 0;
developer72fb0bb2023-01-11 09:46:29 +08006163
developera3511852023-06-14 14:12:59 +08006164 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08006165
developera3511852023-06-14 14:12:59 +08006166 if (strcmp(string, "400nsec") == 0)
6167 GI = wifi_guard_interval_400;
6168 else if (strcmp(string , "800nsec") == 0)
6169 GI = wifi_guard_interval_800;
6170 else if (strcmp(string , "1600nsec") == 0)
6171 GI = wifi_guard_interval_1600;
6172 else if (strcmp(string , "3200nsec") == 0)
6173 GI = wifi_guard_interval_3200;
6174 else
6175 GI = wifi_guard_interval_auto;
developer72fb0bb2023-01-11 09:46:29 +08006176
developera3511852023-06-14 14:12:59 +08006177 ret = wifi_setGuardInterval(radioIndex, GI);
developer72fb0bb2023-01-11 09:46:29 +08006178
developera3511852023-06-14 14:12:59 +08006179 if (ret == RETURN_ERR) {
6180 wifi_dbg_printf("%s: wifi_setGuardInterval return error\n", __func__);
6181 return RETURN_ERR;
6182 }
developer72fb0bb2023-01-11 09:46:29 +08006183
developera3511852023-06-14 14:12:59 +08006184 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6185 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006186}
6187
6188//Get the Modulation Coding Scheme index, eg: "-1", "1", "15"
6189INT wifi_getRadioMCS(INT radioIndex, INT *output_int) //Tr181
6190{
developera3511852023-06-14 14:12:59 +08006191 char buf[32]={0};
6192 char mcs_file[64] = {0};
developer8078acf2023-08-04 18:52:48 +08006193
developera3511852023-06-14 14:12:59 +08006194 UINT mode_bitmap = 0;
developere40952c2023-06-15 18:46:43 +08006195 int res;
developerc14d83a2023-06-29 20:09:42 +08006196 long int tmp;
developer72fb0bb2023-01-11 09:46:29 +08006197
developera3511852023-06-14 14:12:59 +08006198 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6199 if(output_int == NULL)
6200 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08006201 res = snprintf(mcs_file, sizeof(mcs_file), "%s%d.txt", MCS_FILE, radioIndex);
6202 if (os_snprintf_error(sizeof(mcs_file), res)) {
6203 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6204 return RETURN_ERR;
6205 }
6206
developer8078acf2023-08-04 18:52:48 +08006207 res = _syscmd_secure(buf, sizeof(buf), "cat %s 2> /dev/null", mcs_file);
6208 if (res) {
6209 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08006210 }
developer72fb0bb2023-01-11 09:46:29 +08006211
developerd14dff12023-06-28 22:47:44 +08006212 if (strlen(buf) > 0) {
developerc14d83a2023-06-29 20:09:42 +08006213 if (hal_strtol(buf, 10, &tmp) < 0) {
6214 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08006215 }
developerc14d83a2023-06-29 20:09:42 +08006216 *output_int = tmp;
developerd14dff12023-06-28 22:47:44 +08006217 } else {
developera3511852023-06-14 14:12:59 +08006218 // output the max MCS for the current radio mode
6219 if (wifi_getRadioMode(radioIndex, buf, &mode_bitmap) == RETURN_ERR) {
6220 wifi_dbg_printf("%s: wifi_getradiomode return error.\n", __func__);
6221 return RETURN_ERR;
6222 }
6223 if (mode_bitmap & WIFI_MODE_AX) {
6224 *output_int = 11;
6225 } else if (mode_bitmap & WIFI_MODE_AC) {
6226 *output_int = 9;
6227 } else if (mode_bitmap & WIFI_MODE_N) {
6228 *output_int = 7;
6229 }
6230 }
6231 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08006232
developera3511852023-06-14 14:12:59 +08006233 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006234}
6235
6236//Set the Modulation Coding Scheme index
6237INT wifi_setRadioMCS(INT radioIndex, INT MCS) //Tr181
6238{
developera3511852023-06-14 14:12:59 +08006239 /*Only HE mode can specify MCS capability. We don't support MCS in HT mode,
6240 because that would be ambiguous (MCS code 8~11 refer to 2 NSS in HT but 1 NSS in HE adn VHT).*/
6241 char config_file[64] = {0};
6242 char set_value[16] = {0};
6243 char mcs_file[32] = {0};
6244 struct params set_config = {0};
6245 FILE *f = NULL;
6246 INT nss = 0;
6247 int ant_bitmap = 0;
6248 unsigned short cal_value = 0;
6249 UCHAR tval = 0, i = 0;
developere40952c2023-06-15 18:46:43 +08006250 int res;
developer72fb0bb2023-01-11 09:46:29 +08006251
developera3511852023-06-14 14:12:59 +08006252 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08006253
developere40952c2023-06-15 18:46:43 +08006254 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
6255 if (os_snprintf_error(sizeof(config_file), res)) {
6256 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6257 return RETURN_ERR;
6258 }
developer72fb0bb2023-01-11 09:46:29 +08006259
developera3511852023-06-14 14:12:59 +08006260 // -1 means auto
6261 if (MCS > 15 || MCS < -1) {
developer75bd10c2023-06-27 11:34:08 +08006262 wifi_debug(DEBUG_ERROR, "invalid MCS %d\n", MCS);
developera3511852023-06-14 14:12:59 +08006263 return RETURN_ERR;
6264 }
6265 wifi_getRadioTxChainMask(radioIndex, &ant_bitmap);/*nss is a bit map value,1111*/
6266 for(; ant_bitmap > 0; ant_bitmap >>= 1)
6267 nss += 1;
6268 //printf("%s:nss = %d\n", __func__, nss);
6269 /*16-bit combination of 2-bit values of Max HE-MCS For 1..8 SS;each 2-bit value have following meaning:
6270 0 = HE-MCS 0-7, 1 = HE-MCS 0-9, 2 = HE-MCS 0-11, 3 = not supported*/
6271 if (MCS > 9 || MCS == -1)
6272 tval = 2;/*one stream value*/
6273 else if (MCS > 7)
6274 tval = 1;
6275 else
6276 tval = 0;
6277 for (i = 0; i < nss; i++)
6278 cal_value |= (tval << (2*i));
developere40952c2023-06-15 18:46:43 +08006279 res = snprintf(set_value, sizeof(set_value), "%x", cal_value);
6280 if (os_snprintf_error(sizeof(set_value), res)) {
6281 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6282 return RETURN_ERR;
6283 }
6284
developera3511852023-06-14 14:12:59 +08006285 WIFI_ENTRY_EXIT_DEBUG("%s:set=%s, cal=%x\n", __func__, set_value, cal_value);
6286 set_config.name = "he_basic_mcs_nss_set";/*He capability in beacon or response*/
6287 set_config.value = set_value;
developer72fb0bb2023-01-11 09:46:29 +08006288
developera3511852023-06-14 14:12:59 +08006289 wifi_hostapdWrite(config_file, &set_config, 1);
6290 wifi_hostapdProcessUpdate(radioIndex, &set_config, 1);
developer72fb0bb2023-01-11 09:46:29 +08006291
developera3511852023-06-14 14:12:59 +08006292 // For pass tdk test, we need to record last MCS setting. No matter whether it is effective or not.
developere40952c2023-06-15 18:46:43 +08006293 res = snprintf(mcs_file, sizeof(mcs_file), "%s%d.txt", MCS_FILE, radioIndex);
6294 if (os_snprintf_error(sizeof(mcs_file), res)) {
6295 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6296 return RETURN_ERR;
6297 }
6298
developera3511852023-06-14 14:12:59 +08006299 f = fopen(mcs_file, "w");
6300 if (f == NULL) {
developere75ba632023-06-29 16:03:33 +08006301 if (fprintf(stderr, "%s: fopen failed\n", __func__) < 0)
6302 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
developera3511852023-06-14 14:12:59 +08006303 return RETURN_ERR;
6304 }
developere75ba632023-06-29 16:03:33 +08006305 if (fprintf(f, "%d", MCS) < 0)
6306 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
6307 if (fclose(f) == EOF) {
6308 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
6309 return RETURN_ERR;
6310 }
developer72fb0bb2023-01-11 09:46:29 +08006311
developera3511852023-06-14 14:12:59 +08006312 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6313 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006314}
6315
6316//Get supported Transmit Power list, eg : "0,25,50,75,100"
6317//The output_list is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this.
6318INT wifi_getRadioTransmitPowerSupported(INT radioIndex, CHAR *output_list) //Tr181
6319{
developere40952c2023-06-15 18:46:43 +08006320 int res;
6321 if (NULL == output_list)
6322 return RETURN_ERR;
6323 res = snprintf(output_list, 64,"0,25,50,75,100");
6324 if (os_snprintf_error(64, res)) {
6325 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6326 return RETURN_ERR;
6327 }
6328
6329 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006330}
6331
6332//Get current Transmit Power in dBm units.
6333//The transmite power level is in units of full power for this radio.
6334INT wifi_getRadioTransmitPower(INT radioIndex, ULONG *output_ulong) //RDKB
6335{
developera3511852023-06-14 14:12:59 +08006336 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +08006337
developera3511852023-06-14 14:12:59 +08006338 char buf[16]={0};
developera1255e42023-05-13 17:45:02 +08006339 char pwr_file[128]={0};
developere40952c2023-06-15 18:46:43 +08006340 int res;
developera1255e42023-05-13 17:45:02 +08006341
developera3511852023-06-14 14:12:59 +08006342 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08006343
developera3511852023-06-14 14:12:59 +08006344 if(output_ulong == NULL)
6345 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006346
developera3511852023-06-14 14:12:59 +08006347 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
6348 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08006349 res = snprintf(pwr_file, sizeof(pwr_file), "%s%d.txt", POWER_PERCENTAGE, radioIndex);
6350 if (os_snprintf_error(sizeof(pwr_file), res)) {
6351 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6352 return RETURN_ERR;
6353 }
6354
developer8078acf2023-08-04 18:52:48 +08006355 res = _syscmd_secure(buf, sizeof(buf),"cat %s 2> /dev/null", pwr_file);
6356 if(res) {
6357 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08006358 }
6359
developer5b23cd02023-07-19 20:26:03 +08006360 if (strlen(buf) > 0) {
developerc14d83a2023-06-29 20:09:42 +08006361 if (hal_strtoul(buf, 10, output_ulong) < 0) {
6362 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08006363 }
6364 } else
developera1255e42023-05-13 17:45:02 +08006365 *output_ulong = 100;
developera3511852023-06-14 14:12:59 +08006366 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6367 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006368}
6369
6370//Set Transmit Power
6371//The transmite power level is in units of full power for this radio.
6372INT wifi_setRadioTransmitPower(INT radioIndex, ULONG TransmitPower) //RDKB
6373{
developera3511852023-06-14 14:12:59 +08006374 char interface_name[16] = {0};
6375 char *support;
6376 char buf[128]={0};
6377 char txpower_str[64] = {0};
developera1255e42023-05-13 17:45:02 +08006378 char pwr_file[128]={0};
developera3511852023-06-14 14:12:59 +08006379 FILE *f = NULL;
developerfead3972023-05-25 20:15:02 +08006380 int if_idx, ret = 0;
6381 struct nl_msg *msg = NULL;
6382 struct nlattr * msg_data = NULL;
6383 struct mtk_nl80211_param param;
6384 struct unl unl_ins;
developere40952c2023-06-15 18:46:43 +08006385 int res;
developer72fb0bb2023-01-11 09:46:29 +08006386
developera3511852023-06-14 14:12:59 +08006387 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08006388
developera3511852023-06-14 14:12:59 +08006389 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
6390 return RETURN_ERR;
6391 // Get the Tx power supported list and check that is the input in the list
developere40952c2023-06-15 18:46:43 +08006392 res = snprintf(txpower_str, sizeof(txpower_str), "%lu", TransmitPower);
6393 if (os_snprintf_error(sizeof(txpower_str), res)) {
6394 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6395 return RETURN_ERR;
6396 }
developera3511852023-06-14 14:12:59 +08006397 wifi_getRadioTransmitPowerSupported(radioIndex, buf);
6398 support = strtok(buf, ",");
6399 while(true)
6400 {
6401 if(support == NULL) { // input not in the list
6402 wifi_dbg_printf("Input value is invalid.\n");
6403 return RETURN_ERR;
6404 }
6405 if (strncmp(txpower_str, support, strlen(support)) == 0) {
6406 break;
6407 }
6408 support = strtok(NULL, ",");
6409 }
developerfead3972023-05-25 20:15:02 +08006410
6411 if_idx = if_nametoindex(interface_name);
6412 /*init mtk nl80211 vendor cmd*/
6413 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_TXPOWER;
6414 param.if_type = NL80211_ATTR_IFINDEX;
6415 param.if_idx = if_idx;
6416 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
6417 if (ret) {
6418 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
6419 return RETURN_ERR;
6420 }
6421 /*add mtk vendor cmd data*/
6422 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_TXPWR_PERCENTAGE_EN, 1)) {
6423 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
6424 nlmsg_free(msg);
6425 goto err;
6426 }
6427
6428 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_TXPWR_DROP_CTRL, TransmitPower)) {
6429 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
6430 nlmsg_free(msg);
6431 goto err;
6432 }
6433
6434 /*send mtk nl80211 vendor msg*/
6435 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
6436 if (ret) {
6437 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
6438 goto err;
6439 }
6440 /*deinit mtk nl80211 vendor msg*/
6441 mtk_nl80211_deint(&unl_ins);
6442 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
6443
developere40952c2023-06-15 18:46:43 +08006444 res = snprintf(pwr_file, sizeof(pwr_file), "%s%d.txt", POWER_PERCENTAGE, radioIndex);
6445 if (os_snprintf_error(sizeof(pwr_file), res)) {
6446 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6447 return RETURN_ERR;
6448 }
6449
developera3511852023-06-14 14:12:59 +08006450 f = fopen(pwr_file, "w");
6451 if (f == NULL) {
developerc14d83a2023-06-29 20:09:42 +08006452 wifi_debug(DEBUG_ERROR, "%s: fopen failed\n", __func__);
developera3511852023-06-14 14:12:59 +08006453 return RETURN_ERR;
6454 }
6455 fprintf(f, "%lu", TransmitPower);
developerc14d83a2023-06-29 20:09:42 +08006456 if (fclose(f) == EOF)
6457 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
developera1255e42023-05-13 17:45:02 +08006458 return RETURN_OK;
developerfead3972023-05-25 20:15:02 +08006459err:
6460 mtk_nl80211_deint(&unl_ins);
6461 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
6462 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006463}
6464
6465//get 80211h Supported. 80211h solves interference with satellites and radar using the same 5 GHz frequency band
6466INT wifi_getRadioIEEE80211hSupported(INT radioIndex, BOOL *Supported) //Tr181
6467{
developera3511852023-06-14 14:12:59 +08006468 if (NULL == Supported)
6469 return RETURN_ERR;
6470 *Supported = TRUE;
developer72fb0bb2023-01-11 09:46:29 +08006471
developera3511852023-06-14 14:12:59 +08006472 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006473}
6474
6475//Get 80211h feature enable
6476INT wifi_getRadioIEEE80211hEnabled(INT radioIndex, BOOL *enable) //Tr181
6477{
developera3511852023-06-14 14:12:59 +08006478 char buf[64]={'\0'};
6479 char config_file[64] = {'\0'};
developer75bd10c2023-06-27 11:34:08 +08006480 int res;
developer72fb0bb2023-01-11 09:46:29 +08006481
developera3511852023-06-14 14:12:59 +08006482 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6483 if(enable == NULL)
6484 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006485
developer75bd10c2023-06-27 11:34:08 +08006486 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
6487 if (os_snprintf_error(sizeof(config_file), res)) {
6488 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6489 return RETURN_ERR;
6490 }
developera3511852023-06-14 14:12:59 +08006491 /* wifi_hostapdRead(config_file, "ieee80211h", buf, sizeof(buf)); */
6492 wifi_datfileRead(config_file, "IEEE80211H", buf, sizeof(buf));
developer72fb0bb2023-01-11 09:46:29 +08006493
developera3511852023-06-14 14:12:59 +08006494 if (strncmp(buf, "1", 1) == 0)
6495 *enable = TRUE;
6496 else
6497 *enable = FALSE;
developer72fb0bb2023-01-11 09:46:29 +08006498
developera3511852023-06-14 14:12:59 +08006499 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6500 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006501}
6502
6503//Set 80211h feature enable
6504INT wifi_setRadioIEEE80211hEnabled(INT radioIndex, BOOL enable) //Tr181
6505{
developera3511852023-06-14 14:12:59 +08006506 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6507 struct params params={'\0'};
6508 struct params dat={0};
6509 char config_file[MAX_BUF_SIZE] = {0};
6510 char config_dat_file[MAX_BUF_SIZE] = {0};
6511 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08006512 int res;
developereef7d562023-10-21 16:04:21 +08006513 int ret = -1;
6514 unsigned char en_80211h;
developer72fb0bb2023-01-11 09:46:29 +08006515
developera3511852023-06-14 14:12:59 +08006516 params.name = "ieee80211h";
developer72fb0bb2023-01-11 09:46:29 +08006517
developera3511852023-06-14 14:12:59 +08006518 if (enable) {
6519 params.value = "1";
developereef7d562023-10-21 16:04:21 +08006520 en_80211h = 1;
developera3511852023-06-14 14:12:59 +08006521 } else {
6522 params.value = "0";
developereef7d562023-10-21 16:04:21 +08006523 en_80211h = 0;
developera3511852023-06-14 14:12:59 +08006524 }
developer72fb0bb2023-01-11 09:46:29 +08006525
developera3511852023-06-14 14:12:59 +08006526 dat.name = "IEEE80211H";
6527 dat.value = params.value;
developerd1824452023-05-18 12:30:04 +08006528
developera3511852023-06-14 14:12:59 +08006529 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +08006530 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
6531 if (os_snprintf_error(sizeof(config_file), res)) {
6532 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6533 return RETURN_ERR;
6534 }
6535
6536 res = snprintf(config_dat_file, sizeof(config_dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
6537 if (os_snprintf_error(sizeof(config_dat_file), res)) {
6538 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6539 return RETURN_ERR;
6540 }
developer69b61b02023-03-07 17:17:44 +08006541
developera3511852023-06-14 14:12:59 +08006542 wifi_hostapdWrite(config_file, &params, 1);
6543 wifi_datfileWrite(config_dat_file, &dat, 1);
6544 wifi_hostapdProcessUpdate(radioIndex, &params, 1);
developereef7d562023-10-21 16:04:21 +08006545
6546 /*do IEEE80211h quick setting*/
6547 ret = wifi_set80211h_netlink(radioIndex, en_80211h);
6548 if (ret != RETURN_OK)
6549 wifi_debug(DEBUG_ERROR, "IEEE80211h quick setting fail\n");
6550
developera3511852023-06-14 14:12:59 +08006551 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6552 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006553}
6554
6555//Indicates the Carrier Sense ranges supported by the radio. It is measured in dBm. Refer section A.2.3.2 of CableLabs Wi-Fi MGMT Specification.
6556INT wifi_getRadioCarrierSenseThresholdRange(INT radioIndex, INT *output) //P3
6557{
developera3511852023-06-14 14:12:59 +08006558 if (NULL == output)
6559 return RETURN_ERR;
6560 *output=100;
developer72fb0bb2023-01-11 09:46:29 +08006561
developera3511852023-06-14 14:12:59 +08006562 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006563}
6564
6565//The RSSI signal level at which CS/CCA detects a busy condition. This attribute enables APs to increase minimum sensitivity to avoid detecting busy condition from multiple/weak Wi-Fi sources in dense Wi-Fi environments. It is measured in dBm. Refer section A.2.3.2 of CableLabs Wi-Fi MGMT Specification.
6566INT wifi_getRadioCarrierSenseThresholdInUse(INT radioIndex, INT *output) //P3
6567{
developera3511852023-06-14 14:12:59 +08006568 if (NULL == output)
6569 return RETURN_ERR;
6570 *output = -99;
developer72fb0bb2023-01-11 09:46:29 +08006571
developera3511852023-06-14 14:12:59 +08006572 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006573}
6574
6575INT wifi_setRadioCarrierSenseThresholdInUse(INT radioIndex, INT threshold) //P3
6576{
developera3511852023-06-14 14:12:59 +08006577 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006578}
6579
6580
6581//Time interval between transmitting beacons (expressed in milliseconds). This parameter is based ondot11BeaconPeriod from [802.11-2012].
6582INT wifi_getRadioBeaconPeriod(INT radioIndex, UINT *output)
6583{
developera3511852023-06-14 14:12:59 +08006584 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +08006585
developera3511852023-06-14 14:12:59 +08006586 char buf[MAX_CMD_SIZE]={'\0'};
developere40952c2023-06-15 18:46:43 +08006587 int res;
developer72fb0bb2023-01-11 09:46:29 +08006588
developera3511852023-06-14 14:12:59 +08006589 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6590 if(output == NULL)
6591 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006592
developera3511852023-06-14 14:12:59 +08006593 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
6594 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +08006595
6596 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s status | grep beacon_int | cut -d '=' -f2 | tr -d '\n'", interface_name);
6597 if(res) {
6598 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08006599 }
6600
developera3511852023-06-14 14:12:59 +08006601 *output = atoi(buf);
developer72fb0bb2023-01-11 09:46:29 +08006602
developera3511852023-06-14 14:12:59 +08006603 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6604 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006605}
developer69b61b02023-03-07 17:17:44 +08006606
developer72fb0bb2023-01-11 09:46:29 +08006607INT wifi_setRadioBeaconPeriod(INT radioIndex, UINT BeaconPeriod)
6608{
developera3511852023-06-14 14:12:59 +08006609 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6610 struct params params={'\0'};
6611 char buf[MAX_BUF_SIZE] = {'\0'};
6612 char config_file[MAX_BUF_SIZE] = {'\0'};
developere40952c2023-06-15 18:46:43 +08006613 int res;
developer72fb0bb2023-01-11 09:46:29 +08006614
developera3511852023-06-14 14:12:59 +08006615 if (BeaconPeriod < 15 || BeaconPeriod > 65535)
6616 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006617
developera3511852023-06-14 14:12:59 +08006618 params.name = "beacon_int";
developere40952c2023-06-15 18:46:43 +08006619 res = snprintf(buf, sizeof(buf), "%u", BeaconPeriod);
6620 if (os_snprintf_error(sizeof(buf), res)) {
6621 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6622 return RETURN_ERR;
6623 }
6624
developera3511852023-06-14 14:12:59 +08006625 params.value = buf;
developer72fb0bb2023-01-11 09:46:29 +08006626
developer75bd10c2023-06-27 11:34:08 +08006627 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
6628 if (os_snprintf_error(sizeof(config_file), res)) {
6629 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6630 return RETURN_ERR;
6631 }
developera3511852023-06-14 14:12:59 +08006632 wifi_hostapdWrite(config_file, &params, 1);
developer69b61b02023-03-07 17:17:44 +08006633
developera3511852023-06-14 14:12:59 +08006634 wifi_hostapdProcessUpdate(radioIndex, &params, 1);
6635 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6636 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006637}
6638
6639//Comma-separated list of strings. The set of data rates, in Mbps, that have to be supported by all stations that desire to join this BSS. The stations have to be able to receive and transmit at each of the data rates listed inBasicDataTransmitRates. For example, a value of "1,2", indicates that stations support 1 Mbps and 2 Mbps. Most control packets use a data rate in BasicDataTransmitRates.
6640INT wifi_getRadioBasicDataTransmitRates(INT radioIndex, CHAR *output)
6641{
developera3511852023-06-14 14:12:59 +08006642 //TODO: need to revisit below implementation
6643 char *temp;
6644 char temp_output[128] = {0};
6645 char temp_TransmitRates[64] = {0};
6646 char config_file[64] = {0};
developer75bd10c2023-06-27 11:34:08 +08006647 int res;
developer72fb0bb2023-01-11 09:46:29 +08006648
developera3511852023-06-14 14:12:59 +08006649 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
6650 if (NULL == output)
6651 return RETURN_ERR;
developer75bd10c2023-06-27 11:34:08 +08006652
6653 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
6654 if (os_snprintf_error(sizeof(config_file), res)) {
6655 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6656 return RETURN_ERR;
6657 }
developera3511852023-06-14 14:12:59 +08006658 wifi_hostapdRead(config_file,"basic_rates",temp_TransmitRates,64);
developer69b61b02023-03-07 17:17:44 +08006659
developera3511852023-06-14 14:12:59 +08006660 if (strlen(temp_TransmitRates) == 0) { // config not set, use supported rate
6661 wifi_getRadioSupportedDataTransmitRates(radioIndex, output);
6662 } else {
6663 temp = strtok(temp_TransmitRates," ");
6664 while(temp!=NULL)
6665 {
6666 // Convert 100 kbps to Mbps
6667 temp[strlen(temp)-1]=0;
6668 if((temp[0]=='5') && (temp[1]=='\0'))
6669 {
6670 temp="5.5";
6671 }
developer32f2a182023-06-27 19:50:41 +08006672 if (strlen(temp) >= sizeof(temp_output))
6673 return RETURN_ERR;
6674 strncat(temp_output, temp, sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08006675 temp = strtok(NULL," ");
6676 if(temp!=NULL)
6677 {
developer32f2a182023-06-27 19:50:41 +08006678 if (strlen(temp_output) >= (sizeof(temp_output) - 1))
6679 strncat(temp_output, ",", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08006680 }
6681 }
developer32f2a182023-06-27 19:50:41 +08006682 memcpy(output, temp_output, strlen(temp_output));
6683 output[strlen(temp_output)] = '\0';
developera3511852023-06-14 14:12:59 +08006684 }
6685 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6686 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006687}
6688
6689INT wifi_setRadioBasicDataTransmitRates(INT radioIndex, CHAR *TransmitRates)
6690{
developera3511852023-06-14 14:12:59 +08006691 char *temp;
developer32f2a182023-06-27 19:50:41 +08006692 char temp1[128] = {0};
6693 char temp_output[128] = {0};
6694 char temp_TransmitRates[128] = {0};
6695 char set[128] = {0};
6696 char sub_set[128] = {0};
developera3511852023-06-14 14:12:59 +08006697 int set_count=0,subset_count=0;
6698 int set_index=0,subset_index=0;
6699 char *token;
6700 int flag=0, i=0;
6701 struct params params={'\0'};
6702 char config_file[MAX_BUF_SIZE] = {0};
6703 wifi_band band = wifi_index_to_band(radioIndex);
developer32f2a182023-06-27 19:50:41 +08006704 int res;
developer9f2358c2023-09-22 18:42:12 +08006705 bool temp_multiple_set = multiple_set;
developer72fb0bb2023-01-11 09:46:29 +08006706
developera3511852023-06-14 14:12:59 +08006707 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer9f2358c2023-09-22 18:42:12 +08006708
developera3511852023-06-14 14:12:59 +08006709 if(NULL == TransmitRates)
6710 return RETURN_ERR;
developer32f2a182023-06-27 19:50:41 +08006711 if (strlen(TransmitRates) >= sizeof(sub_set))
6712 return RETURN_ERR;
6713
6714 memcpy(sub_set, TransmitRates, strlen(TransmitRates));
developer72fb0bb2023-01-11 09:46:29 +08006715
developera3511852023-06-14 14:12:59 +08006716 //Allow only supported Data transmit rate to be set
6717 wifi_getRadioSupportedDataTransmitRates(radioIndex,set);
6718 token = strtok(sub_set,",");
6719 while( token != NULL ) /* split the basic rate to be set, by comma */
6720 {
6721 sub_set[subset_count]=atoi(token);
6722 subset_count++;
6723 token=strtok(NULL,",");
6724 }
6725 token=strtok(set,",");
6726 while(token!=NULL) /* split the supported rate by comma */
6727 {
6728 set[set_count]=atoi(token);
6729 set_count++;
6730 token=strtok(NULL,",");
6731 }
6732 for(subset_index=0;subset_index < subset_count;subset_index++) /* Compare each element of subset and set */
6733 {
6734 for(set_index=0;set_index < set_count;set_index++)
6735 {
6736 flag=0;
6737 if(sub_set[subset_index]==set[set_index])
6738 break;
6739 else
6740 flag=1; /* No match found */
6741 }
6742 if(flag==1)
6743 return RETURN_ERR; //If value not found return Error
6744 }
developer5b23cd02023-07-19 20:26:03 +08006745
developer32f2a182023-06-27 19:50:41 +08006746 if (strlen(TransmitRates) >= sizeof(temp_TransmitRates))
6747 return RETURN_ERR;
6748
6749 memcpy(temp_TransmitRates, TransmitRates, strlen(TransmitRates));
developer72fb0bb2023-01-11 09:46:29 +08006750
developera3511852023-06-14 14:12:59 +08006751 for(i=0;i<strlen(temp_TransmitRates);i++)
6752 {
6753 //if (((temp_TransmitRates[i]>=48) && (temp_TransmitRates[i]<=57)) | (temp_TransmitRates[i]==32))
6754 if (((temp_TransmitRates[i]>='0') && (temp_TransmitRates[i]<='9')) || (temp_TransmitRates[i]==' ') || (temp_TransmitRates[i]=='.') || (temp_TransmitRates[i]==','))
6755 {
6756 continue;
6757 }
6758 else
6759 {
6760 return RETURN_ERR;
6761 }
6762 }
developera3511852023-06-14 14:12:59 +08006763 temp = strtok(temp_TransmitRates,",");
6764 while(temp!=NULL)
6765 {
developer32f2a182023-06-27 19:50:41 +08006766 if (strlen(temp) >= sizeof(temp1))
6767 return RETURN_ERR;
6768 strncpy(temp1, temp, strlen(temp));
developera3511852023-06-14 14:12:59 +08006769 if(band == band_5)
6770 {
6771 if((strcmp(temp,"1")==0) || (strcmp(temp,"2")==0) || (strcmp(temp,"5.5")==0))
6772 {
6773 return RETURN_ERR;
6774 }
6775 }
developer72fb0bb2023-01-11 09:46:29 +08006776
developera3511852023-06-14 14:12:59 +08006777 if(strcmp(temp,"5.5")==0)
6778 {
developer32f2a182023-06-27 19:50:41 +08006779 memcpy(temp1, "55", 2);
developera3511852023-06-14 14:12:59 +08006780 }
6781 else
6782 {
developer32f2a182023-06-27 19:50:41 +08006783 if (strlen(temp1) >= (sizeof(temp1) - 1))
6784 return RETURN_ERR;
6785 strncat(temp1, "0", sizeof(temp1) - strlen(temp1) - 1);
developera3511852023-06-14 14:12:59 +08006786 }
developer32f2a182023-06-27 19:50:41 +08006787 if (strlen(temp1) >= (sizeof(temp_output) - strlen(temp_output)))
6788 return RETURN_ERR;
6789 strncat(temp_output, temp1, sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08006790 temp = strtok(NULL,",");
6791 if(temp!=NULL)
6792 {
developer32f2a182023-06-27 19:50:41 +08006793 if (strlen(temp_output) >= (sizeof(temp_output) - 1))
6794 return RETURN_ERR;
6795 strncat(temp_output," ", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +08006796 }
6797 }
developer32f2a182023-06-27 19:50:41 +08006798 memcpy(TransmitRates, temp_output, strlen(temp_output));
6799 TransmitRates[strlen(temp_output)] = '\0';
developer5b23cd02023-07-19 20:26:03 +08006800
developera3511852023-06-14 14:12:59 +08006801 params.name= "basic_rates";
6802 params.value =TransmitRates;
developer72fb0bb2023-01-11 09:46:29 +08006803
developera3511852023-06-14 14:12:59 +08006804 wifi_dbg_printf("\n%s:",__func__);
6805 wifi_dbg_printf("\nparams.value=%s\n",params.value);
6806 wifi_dbg_printf("\n******************Transmit rates=%s\n",TransmitRates);
developer32f2a182023-06-27 19:50:41 +08006807 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,radioIndex);
6808 if (os_snprintf_error(sizeof(config_file), res)) {
6809 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
6810 return RETURN_ERR;
6811 }
developer5b23cd02023-07-19 20:26:03 +08006812
developera3511852023-06-14 14:12:59 +08006813 wifi_hostapdWrite(config_file,&params,1);
developer9f2358c2023-09-22 18:42:12 +08006814 multiple_set = false;
6815 wifi_hostapdProcessUpdate(radioIndex, &params, 1);
6816 wifi_quick_reload_ap(radioIndex);
6817 multiple_set = temp_multiple_set;
6818
developera3511852023-06-14 14:12:59 +08006819 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
6820 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006821}
6822
developer72fb0bb2023-01-11 09:46:29 +08006823INT wifi_halGetIfStatsNull(wifi_radioTrafficStats2_t *output_struct)
6824{
developera3511852023-06-14 14:12:59 +08006825 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
6826 output_struct->radio_BytesSent = 0;
6827 output_struct->radio_BytesReceived = 0;
6828 output_struct->radio_PacketsSent = 0;
6829 output_struct->radio_PacketsReceived = 0;
6830 output_struct->radio_ErrorsSent = 0;
6831 output_struct->radio_ErrorsReceived = 0;
6832 output_struct->radio_DiscardPacketsSent = 0;
6833 output_struct->radio_DiscardPacketsReceived = 0;
6834 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
6835 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006836}
6837
6838
6839INT wifi_halGetIfStats(char *ifname, wifi_radioTrafficStats2_t *pStats)
6840{
developera3511852023-06-14 14:12:59 +08006841 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer8078acf2023-08-04 18:52:48 +08006842
developera3511852023-06-14 14:12:59 +08006843 CHAR Value[MAX_BUF_SIZE] = {0};
6844 FILE *fp = NULL;
developere40952c2023-06-15 18:46:43 +08006845 int res;
developer37646972023-06-29 10:58:43 +08006846 unsigned long ret;
developer72fb0bb2023-01-11 09:46:29 +08006847
developera3511852023-06-14 14:12:59 +08006848 if (ifname == NULL || strlen(ifname) <= 1)
6849 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006850
developer33f13ba2023-07-12 16:19:06 +08006851 res = v_secure_system("ifconfig -a %s > /tmp/Radio_Stats.txt", ifname);
6852 if (res) {
6853 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developere40952c2023-06-15 18:46:43 +08006854 return RETURN_ERR;
6855 }
6856
developera3511852023-06-14 14:12:59 +08006857 fp = fopen("/tmp/Radio_Stats.txt", "r");
6858 if(fp == NULL)
6859 {
6860 printf("/tmp/Radio_Stats.txt not exists \n");
6861 return RETURN_ERR;
6862 }
developerd14dff12023-06-28 22:47:44 +08006863 if (fclose(fp) != 0) {
6864 wifi_debug(DEBUG_ERROR, "fclose fail\n");
6865 return RETURN_ERR;
6866 }
developer72fb0bb2023-01-11 09:46:29 +08006867
developer8078acf2023-08-04 18:52:48 +08006868 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'RX packets' | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f1");
6869 if(res) {
6870 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +08006871 }
developer5b23cd02023-07-19 20:26:03 +08006872
developerc14d83a2023-06-29 20:09:42 +08006873 if (hal_strtoul(Value, 10, &ret) < 0) {
developer37646972023-06-29 10:58:43 +08006874 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developer37646972023-06-29 10:58:43 +08006875 }
developerc14d83a2023-06-29 20:09:42 +08006876
developer37646972023-06-29 10:58:43 +08006877 pStats->radio_PacketsReceived = ret;
developer72fb0bb2023-01-11 09:46:29 +08006878
developer8078acf2023-08-04 18:52:48 +08006879 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'TX packets' | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f1");
6880 if(res) {
6881 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006882 }
developer5b23cd02023-07-19 20:26:03 +08006883
developerc14d83a2023-06-29 20:09:42 +08006884 if (hal_strtoul(Value, 10, &ret) < 0) {
6885 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006886 }
developer5b23cd02023-07-19 20:26:03 +08006887
developer37646972023-06-29 10:58:43 +08006888 pStats->radio_PacketsSent = ret;
developer72fb0bb2023-01-11 09:46:29 +08006889
developer8078acf2023-08-04 18:52:48 +08006890 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'RX bytes' | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f1");
6891 if(res) {
6892 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006893 }
developer8078acf2023-08-04 18:52:48 +08006894
developerc14d83a2023-06-29 20:09:42 +08006895 if (hal_strtoul(Value, 10, &ret) < 0) {
6896 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006897 }
6898 pStats->radio_BytesReceived = ret;
developer72fb0bb2023-01-11 09:46:29 +08006899
developer8078acf2023-08-04 18:52:48 +08006900 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'TX bytes' | tr -s ' ' | cut -d ':' -f3 | cut -d ' ' -f1");
6901 if(res) {
6902 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006903 }
developer8078acf2023-08-04 18:52:48 +08006904
developerc14d83a2023-06-29 20:09:42 +08006905 if (hal_strtoul(Value, 10, &ret) < 0) {
6906 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006907 }
6908 pStats->radio_BytesSent = ret;
developer72fb0bb2023-01-11 09:46:29 +08006909
developer8078acf2023-08-04 18:52:48 +08006910 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'RX packets' | tr -s ' ' | cut -d ':' -f3 | cut -d ' ' -f1");
6911 if(res) {
6912 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006913 }
developer8078acf2023-08-04 18:52:48 +08006914
developerc14d83a2023-06-29 20:09:42 +08006915 if (hal_strtoul(Value, 10, &ret) < 0) {
6916 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006917 }
6918 pStats->radio_ErrorsReceived = ret;
developer72fb0bb2023-01-11 09:46:29 +08006919
developer8078acf2023-08-04 18:52:48 +08006920 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'TX packets' | tr -s ' ' | cut -d ':' -f3 | cut -d ' ' -f1");
6921 if(res) {
6922 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006923 }
developer8078acf2023-08-04 18:52:48 +08006924
developerc14d83a2023-06-29 20:09:42 +08006925 if (hal_strtoul(Value, 10, &ret) < 0) {
6926 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006927 }
6928 pStats->radio_ErrorsSent = ret;
developer72fb0bb2023-01-11 09:46:29 +08006929
developer8078acf2023-08-04 18:52:48 +08006930 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'RX packets' | tr -s ' ' | cut -d ':' -f4 | cut -d ' ' -f1");
6931 if(res) {
6932 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006933 }
developer8078acf2023-08-04 18:52:48 +08006934
developerc14d83a2023-06-29 20:09:42 +08006935 if (hal_strtoul(Value, 10, &ret) < 0) {
6936 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006937 }
6938 pStats->radio_DiscardPacketsReceived = ret;
developer72fb0bb2023-01-11 09:46:29 +08006939
developer8078acf2023-08-04 18:52:48 +08006940 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/Radio_Stats.txt | grep 'TX packets' | tr -s ' ' | cut -d ':' -f4 | cut -d ' ' -f1");
6941 if(res) {
6942 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer86035662023-06-28 19:21:12 +08006943 }
developer8078acf2023-08-04 18:52:48 +08006944
developerc14d83a2023-06-29 20:09:42 +08006945 if (hal_strtoul(Value, 10, &ret) < 0) {
6946 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08006947 }
6948 pStats->radio_DiscardPacketsSent = ret;
developer72fb0bb2023-01-11 09:46:29 +08006949
developera3511852023-06-14 14:12:59 +08006950 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
6951 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006952}
6953
6954INT GetIfacestatus(CHAR *interface_name, CHAR *status)
6955{
developer75bd10c2023-06-27 11:34:08 +08006956 int res;
developer72fb0bb2023-01-11 09:46:29 +08006957
developer7e4a2a62023-04-06 19:56:03 +08006958 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
6959
6960 if (interface_name != NULL && (strlen(interface_name) > 1) && status != NULL) {
developer8078acf2023-08-04 18:52:48 +08006961
developerd08b7d52023-08-22 15:41:36 +08006962 res = _syscmd_secure(status, sizeof(status), "ifconfig -a %s | grep %s | wc -l",
6963 interface_name, interface_name);
6964 if(res) {
6965 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
6966 }
developer75bd10c2023-06-27 11:34:08 +08006967
developer7e4a2a62023-04-06 19:56:03 +08006968 }
6969
6970 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
6971 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08006972}
6973
6974//Get detail radio traffic static info
6975INT wifi_getRadioTrafficStats2(INT radioIndex, wifi_radioTrafficStats2_t *output_struct) //Tr181
6976{
developera3511852023-06-14 14:12:59 +08006977 CHAR interface_name[64] = {0};
6978 BOOL iface_status = FALSE;
6979 wifi_radioTrafficStats2_t radioTrafficStats = {0};
developer72fb0bb2023-01-11 09:46:29 +08006980
developera3511852023-06-14 14:12:59 +08006981 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
6982 if (NULL == output_struct)
6983 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006984
developera3511852023-06-14 14:12:59 +08006985 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
6986 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08006987
developera3511852023-06-14 14:12:59 +08006988 wifi_getApEnable(radioIndex, &iface_status);
developer72fb0bb2023-01-11 09:46:29 +08006989
developera3511852023-06-14 14:12:59 +08006990 if (iface_status == TRUE)
6991 wifi_halGetIfStats(interface_name, &radioTrafficStats);
6992 else
6993 wifi_halGetIfStatsNull(&radioTrafficStats); // just set some transmission statistic value to 0
developer72fb0bb2023-01-11 09:46:29 +08006994
developera3511852023-06-14 14:12:59 +08006995 output_struct->radio_BytesSent = radioTrafficStats.radio_BytesSent;
6996 output_struct->radio_BytesReceived = radioTrafficStats.radio_BytesReceived;
6997 output_struct->radio_PacketsSent = radioTrafficStats.radio_PacketsSent;
6998 output_struct->radio_PacketsReceived = radioTrafficStats.radio_PacketsReceived;
6999 output_struct->radio_ErrorsSent = radioTrafficStats.radio_ErrorsSent;
7000 output_struct->radio_ErrorsReceived = radioTrafficStats.radio_ErrorsReceived;
7001 output_struct->radio_DiscardPacketsSent = radioTrafficStats.radio_DiscardPacketsSent;
7002 output_struct->radio_DiscardPacketsReceived = radioTrafficStats.radio_DiscardPacketsReceived;
developer72fb0bb2023-01-11 09:46:29 +08007003
developera3511852023-06-14 14:12:59 +08007004 output_struct->radio_PLCPErrorCount = 0; //The number of packets that were received with a detected Physical Layer Convergence Protocol (PLCP) header error.
7005 output_struct->radio_FCSErrorCount = 0; //The number of packets that were received with a detected FCS error. This parameter is based on dot11FCSErrorCount from [Annex C/802.11-2012].
7006 output_struct->radio_InvalidMACCount = 0; //The number of packets that were received with a detected invalid MAC header error.
7007 output_struct->radio_PacketsOtherReceived = 0; //The number of packets that were received, but which were destined for a MAC address that is not associated with this interface.
7008 output_struct->radio_NoiseFloor = -99; //The noise floor for this radio channel where a recoverable signal can be obtained. Expressed as a signed integer in the range (-110:0). Measurement should capture all energy (in dBm) from sources other than Wi-Fi devices as well as interference from Wi-Fi devices too weak to be decoded. Measured in dBm
7009 output_struct->radio_ChannelUtilization = 35; //Percentage of time the channel was occupied by the radio\92s own activity (Activity Factor) or the activity of other radios. Channel utilization MUST cover all user traffic, management traffic, and time the radio was unavailable for CSMA activities, including DIFS intervals, etc. The metric is calculated and updated in this parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected from the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in Percentage
7010 output_struct->radio_ActivityFactor = 2; //Percentage of time that the radio was transmitting or receiving Wi-Fi packets to/from associated clients. Activity factor MUST include all traffic that deals with communication between the radio and clients associated to the radio as well as management overhead for the radio, including NAV timers, beacons, probe responses,time for receiving devices to send an ACK, SIFC intervals, etc. The metric is calculated and updated in this parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected from the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in Percentage
7011 output_struct->radio_CarrierSenseThreshold_Exceeded = 20; //Percentage of time that the radio was unable to transmit or receive Wi-Fi packets to/from associated clients due to energy detection (ED) on the channel or clear channel assessment (CCA). The metric is calculated and updated in this Parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected from the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in Percentage
7012 output_struct->radio_RetransmissionMetirc = 0; //Percentage of packets that had to be re-transmitted. Multiple re-transmissions of the same packet count as one. The metric is calculated and updated in this parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected from the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in percentage
developer72fb0bb2023-01-11 09:46:29 +08007013
developera3511852023-06-14 14:12:59 +08007014 output_struct->radio_MaximumNoiseFloorOnChannel = -1; //Maximum Noise on the channel during the measuring interval. The metric is updated in this parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected in the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in dBm
7015 output_struct->radio_MinimumNoiseFloorOnChannel = -1; //Minimum Noise on the channel. The metric is updated in this Parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected in the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in dBm
7016 output_struct->radio_MedianNoiseFloorOnChannel = -1; //Median Noise on the channel during the measuring interval. The metric is updated in this parameter at the end of the interval defined by "Radio Statistics Measuring Interval". The calculation of this metric MUST only use the data collected in the just completed interval. If this metric is queried before it has been updated with an initial calculation, it MUST return -1. Units in dBm
7017 output_struct->radio_StatisticsStartTime = 0; //The date and time at which the collection of the current set of statistics started. This time must be updated whenever the radio statistics are reset.
developer72fb0bb2023-01-11 09:46:29 +08007018
developera3511852023-06-14 14:12:59 +08007019 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08007020
developera3511852023-06-14 14:12:59 +08007021 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007022}
7023
7024//Set radio traffic static Measureing rules
7025INT wifi_setRadioTrafficStatsMeasure(INT radioIndex, wifi_radioTrafficStatsMeasure_t *input_struct) //Tr181
7026{
developera39cfb22023-06-20 16:28:17 +08007027 char inf_name[IF_NAME_SIZE] = {0};
7028 unsigned int if_idx = 0;
7029 int ret = -1;
7030 struct unl unl_ins;
7031 struct nl_msg *msg = NULL;
7032 struct nlattr * msg_data = NULL;
7033 struct mtk_nl80211_param param;
7034
7035 if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
7036 return RETURN_ERR;
7037 if_idx = if_nametoindex(inf_name);
7038 if (!if_idx) {
7039 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
7040 return RETURN_ERR;
7041 }
7042 /*init mtk nl80211 vendor cmd*/
7043 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_RADIO_STATS;
7044 param.if_type = NL80211_ATTR_IFINDEX;
7045 param.if_idx = if_idx;
7046
7047 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
7048 if (ret) {
7049 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
7050 return RETURN_ERR;
7051 }
7052 /*add mtk vendor cmd data*/
7053 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_RADIO_SET_STATS_MEASURING_METHOD,
7054 sizeof(wifi_radioTrafficStatsMeasure_t), input_struct)) {
7055 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n",
7056 MTK_NL80211_VENDOR_ATTR_RADIO_SET_STATS_MEASURING_METHOD);
7057 nlmsg_free(msg);
7058 goto err;
7059 }
7060
7061 /*send mtk nl80211 vendor msg*/
7062 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
7063 if (ret) {
7064 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
7065 goto err;
7066 }
7067 /*deinit mtk nl80211 vendor msg*/
7068 mtk_nl80211_deint(&unl_ins);
developera3511852023-06-14 14:12:59 +08007069 return RETURN_OK;
developera39cfb22023-06-20 16:28:17 +08007070err:
7071 mtk_nl80211_deint(&unl_ins);
7072 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
7073 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007074}
7075
7076//To start or stop RadioTrafficStats
7077INT wifi_setRadioTrafficStatsRadioStatisticsEnable(INT radioIndex, BOOL enable)
7078{
developera39cfb22023-06-20 16:28:17 +08007079 char inf_name[IF_NAME_SIZE] = {0};
7080 unsigned int if_idx = 0;
7081 int ret = -1;
7082 struct unl unl_ins;
7083 struct nl_msg *msg = NULL;
7084 struct nlattr * msg_data = NULL;
7085 struct mtk_nl80211_param param;
7086
7087 if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
7088 return RETURN_ERR;
7089 if_idx = if_nametoindex(inf_name);
7090 if (!if_idx) {
7091 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
7092 return RETURN_ERR;
7093 }
7094 /*init mtk nl80211 vendor cmd*/
7095 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_RADIO_STATS;
7096 param.if_type = NL80211_ATTR_IFINDEX;
7097 param.if_idx = if_idx;
7098
7099 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
7100 if (ret) {
7101 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
7102 return RETURN_ERR;
7103 }
7104 /*add mtk vendor cmd data*/
7105 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_RADIO_SET_MEASURE_ENABEL, enable)) {
7106 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n",
7107 MTK_NL80211_VENDOR_ATTR_RADIO_SET_MEASURE_ENABEL);
7108 nlmsg_free(msg);
7109 goto err;
7110 }
7111
7112 /*send mtk nl80211 vendor msg*/
7113 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
7114 if (ret) {
7115 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
7116 goto err;
7117 }
7118 /*deinit mtk nl80211 vendor msg*/
7119 mtk_nl80211_deint(&unl_ins);
developera3511852023-06-14 14:12:59 +08007120 return RETURN_OK;
developera39cfb22023-06-20 16:28:17 +08007121err:
7122 mtk_nl80211_deint(&unl_ins);
7123 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
7124 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007125}
7126
7127//Clients associated with the AP over a specific interval. The histogram MUST have a range from -110to 0 dBm and MUST be divided in bins of 3 dBM, with bins aligning on the -110 dBm end of the range. Received signal levels equal to or greater than the smaller boundary of a bin and less than the larger boundary are included in the respective bin. The bin associated with the client?s current received signal level MUST be incremented when a client associates with the AP. Additionally, the respective bins associated with each connected client?s current received signal level MUST be incremented at the interval defined by "Radio Statistics Measuring Rate". The histogram?s bins MUST NOT be incremented at any other time. The histogram data collected during the interval MUST be published to the parameter only at the end of the interval defined by "Radio Statistics Measuring Interval". The underlying histogram data MUST be cleared at the start of each interval defined by "Radio Statistics Measuring Interval?. If any of the parameter's representing this histogram is queried before the histogram has been updated with an initial set of data, it MUST return -1. Units dBm
7128INT wifi_getRadioStatsReceivedSignalLevel(INT radioIndex, INT signalIndex, INT *SignalLevel) //Tr181
7129{
developera3511852023-06-14 14:12:59 +08007130 if (NULL == SignalLevel)
7131 return RETURN_ERR;
developer47cc27a2023-05-17 23:09:58 +08007132
developer9ce44382023-06-28 11:09:37 +08007133 *SignalLevel = -19;
developer72fb0bb2023-01-11 09:46:29 +08007134
developera3511852023-06-14 14:12:59 +08007135 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007136}
7137
7138//Not all implementations may need this function. If not needed for a particular implementation simply return no-error (0)
7139INT wifi_applyRadioSettings(INT radioIndex)
7140{
developera3511852023-06-14 14:12:59 +08007141 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007142}
7143
7144//Get the radio index assocated with this SSID entry
7145INT wifi_getSSIDRadioIndex(INT ssidIndex, INT *radioIndex)
7146{
developera3511852023-06-14 14:12:59 +08007147 if(NULL == radioIndex)
7148 return RETURN_ERR;
7149 int max_radio_num = 0;
7150 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +08007151 if(max_radio_num == 0){
7152 return RETURN_ERR;
7153 }
developera3511852023-06-14 14:12:59 +08007154 *radioIndex = ssidIndex%max_radio_num;
7155 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007156}
7157
7158//Device.WiFi.SSID.{i}.Enable
7159//Get SSID enable configuration parameters (not the SSID enable status)
7160INT wifi_getSSIDEnable(INT ssidIndex, BOOL *output_bool) //Tr181
7161{
developera3511852023-06-14 14:12:59 +08007162 if (NULL == output_bool)
7163 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007164
developera3511852023-06-14 14:12:59 +08007165 return wifi_getApEnable(ssidIndex, output_bool);
developer72fb0bb2023-01-11 09:46:29 +08007166}
7167
7168//Device.WiFi.SSID.{i}.Enable
7169//Set SSID enable configuration parameters
7170INT wifi_setSSIDEnable(INT ssidIndex, BOOL enable) //Tr181
7171{
developera3511852023-06-14 14:12:59 +08007172 return wifi_setApEnable(ssidIndex, enable);
developer72fb0bb2023-01-11 09:46:29 +08007173}
7174
7175//Device.WiFi.SSID.{i}.Status
7176//Get the SSID enable status
7177INT wifi_getSSIDStatus(INT ssidIndex, CHAR *output_string) //Tr181
7178{
developer9ce44382023-06-28 11:09:37 +08007179 BOOL output_bool = 0;
developere40952c2023-06-15 18:46:43 +08007180 int res;
developer72fb0bb2023-01-11 09:46:29 +08007181
developera3511852023-06-14 14:12:59 +08007182 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7183 if (NULL == output_string)
7184 return RETURN_ERR;
developer69b61b02023-03-07 17:17:44 +08007185
developera3511852023-06-14 14:12:59 +08007186 wifi_getApEnable(ssidIndex,&output_bool);
developere40952c2023-06-15 18:46:43 +08007187 res = snprintf(output_string, 32, output_bool==1?"Enabled":"Disabled");
7188 if (os_snprintf_error(32, res)) {
7189 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
7190 return RETURN_ERR;
7191 }
developer72fb0bb2023-01-11 09:46:29 +08007192
developera3511852023-06-14 14:12:59 +08007193 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
7194 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007195}
7196
7197// Outputs a 32 byte or less string indicating the SSID name. Sring buffer must be preallocated by the caller.
7198INT wifi_getSSIDName(INT apIndex, CHAR *output)
7199{
developera3511852023-06-14 14:12:59 +08007200 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +08007201 int res;
developer72fb0bb2023-01-11 09:46:29 +08007202
developera3511852023-06-14 14:12:59 +08007203 if (NULL == output)
7204 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007205
developer75bd10c2023-06-27 11:34:08 +08007206 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
7207 if (os_snprintf_error(sizeof(config_file), res)) {
7208 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
7209 return RETURN_ERR;
7210 }
developera3511852023-06-14 14:12:59 +08007211 wifi_hostapdRead(config_file,"ssid",output,32);
developer72fb0bb2023-01-11 09:46:29 +08007212
developera3511852023-06-14 14:12:59 +08007213 wifi_dbg_printf("\n[%s]: SSID Name is : %s",__func__,output);
7214 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007215}
7216
developer69b61b02023-03-07 17:17:44 +08007217// Set a max 32 byte string and sets an internal variable to the SSID name
developer72fb0bb2023-01-11 09:46:29 +08007218INT wifi_setSSIDName(INT apIndex, CHAR *ssid_string)
7219{
developera3511852023-06-14 14:12:59 +08007220 struct params params;
7221 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +08007222 int res;
developer72fb0bb2023-01-11 09:46:29 +08007223
developera3511852023-06-14 14:12:59 +08007224 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7225 if(NULL == ssid_string || strlen(ssid_string) >= 32 || strlen(ssid_string) == 0 )
7226 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007227
developera3511852023-06-14 14:12:59 +08007228 params.name = "ssid";
7229 params.value = ssid_string;
developer75bd10c2023-06-27 11:34:08 +08007230
7231 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
7232 if (os_snprintf_error(sizeof(config_file), res)) {
7233 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
7234 return RETURN_ERR;
7235 }
7236
developera3511852023-06-14 14:12:59 +08007237 wifi_hostapdWrite(config_file, &params, 1);
7238 wifi_hostapdProcessUpdate(apIndex, &params, 1);
7239 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08007240
developera3511852023-06-14 14:12:59 +08007241 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007242}
7243
7244//Get the BSSID
7245INT wifi_getBaseBSSID(INT ssidIndex, CHAR *output_string) //RDKB
7246{
developer7e4a2a62023-04-06 19:56:03 +08007247 char inf_name[IF_NAME_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08007248 int res;
developer72fb0bb2023-01-11 09:46:29 +08007249
developera3511852023-06-14 14:12:59 +08007250 if (!output_string)
developerdaf24792023-06-06 11:40:04 +08007251 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007252
developer47cc27a2023-05-17 23:09:58 +08007253 if (wifi_GetInterfaceName(ssidIndex, inf_name) != RETURN_OK)
7254 return RETURN_ERR;
developer7e4a2a62023-04-06 19:56:03 +08007255
developer5b2f10c2023-05-25 17:02:21 +08007256 if (ssidIndex < 0 || ssidIndex > MAX_APS) {
7257 wifi_debug(DEBUG_ERROR, "innvalide ssidIdex(%d)\n", ssidIndex);
7258 strncpy(output_string, "\0", 1);
7259 return RETURN_ERR;
7260 }
developere40952c2023-06-15 18:46:43 +08007261
developer8078acf2023-08-04 18:52:48 +08007262 res = _syscmd_secure(output_string,64,"hostapd_cli -i %s get_config | grep bssid | cut -d '=' -f2 | tr -d '\\n'", inf_name);
7263 if(res) {
7264 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
7265 }
developer7e4a2a62023-04-06 19:56:03 +08007266
developer5b2f10c2023-05-25 17:02:21 +08007267 /* if hostapd does not control interface even if this interface has been brought up,
7268 * try to get its mac address by iw command.
7269 */
7270 if(strlen(output_string) == 0) {
developer8078acf2023-08-04 18:52:48 +08007271 res = _syscmd_secure(output_string, 64, "iw dev %s info | grep \"addr\" | awk \'{print $2}\'", inf_name);
7272 if(res) {
7273 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08007274 }
developer5b2f10c2023-05-25 17:02:21 +08007275 }
developer72fb0bb2023-01-11 09:46:29 +08007276
developer5b2f10c2023-05-25 17:02:21 +08007277 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007278}
7279
7280//Get the MAC address associated with this Wifi SSID
7281INT wifi_getSSIDMACAddress(INT ssidIndex, CHAR *output_string) //Tr181
7282{
developera3511852023-06-14 14:12:59 +08007283 wifi_getBaseBSSID(ssidIndex,output_string);
7284 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007285}
7286
7287//Get the basic SSID traffic static info
7288//Apply SSID and AP (in the case of Acess Point devices) to the hardware
7289//Not all implementations may need this function. If not needed for a particular implementation simply return no-error (0)
7290INT wifi_applySSIDSettings(INT ssidIndex)
7291{
developera3511852023-06-14 14:12:59 +08007292 char interface_name[16] = {0};
7293 BOOL status = false;
developera3511852023-06-14 14:12:59 +08007294 char buf[MAX_CMD_SIZE] = {0};
7295 int apIndex, ret;
7296 int max_radio_num = 0;
7297 int radioIndex = 0;
developere40952c2023-06-15 18:46:43 +08007298 int res;
developer72fb0bb2023-01-11 09:46:29 +08007299
developera3511852023-06-14 14:12:59 +08007300 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +08007301 if(max_radio_num == 0){
7302 return RETURN_ERR;
7303 }
developera3511852023-06-14 14:12:59 +08007304 radioIndex = ssidIndex % max_radio_num;
developer72fb0bb2023-01-11 09:46:29 +08007305
developera3511852023-06-14 14:12:59 +08007306 wifi_getApEnable(ssidIndex,&status);
7307 // Do not apply when ssid index is disabled
7308 if (status == false)
7309 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007310
developera3511852023-06-14 14:12:59 +08007311 /* Doing full remove and add for ssid Index
7312 * Not all hostapd options are supported with reload
7313 * for example macaddr_acl
7314 */
7315 if(wifi_setApEnable(ssidIndex,false) != RETURN_OK)
7316 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007317
developera3511852023-06-14 14:12:59 +08007318 ret = wifi_setApEnable(ssidIndex,true);
developer72fb0bb2023-01-11 09:46:29 +08007319
developera3511852023-06-14 14:12:59 +08007320 /* Workaround for hostapd issue with multiple bss definitions
7321 * when first created interface will be removed
7322 * then all vaps other vaps on same phy are removed
7323 * after calling setApEnable to false readd all enabled vaps */
7324 for(int i=0; i < MAX_APS/max_radio_num; i++) {
7325 apIndex = max_radio_num*i+radioIndex;
7326 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
7327 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08007328
developer8078acf2023-08-04 18:52:48 +08007329 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep %s | cut -d'=' -f2", VAP_STATUS_FILE, interface_name);
7330 if(res) {
7331 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
7332 }
developera3511852023-06-14 14:12:59 +08007333 if(*buf == '1')
7334 wifi_setApEnable(apIndex, true);
7335 }
developer72fb0bb2023-01-11 09:46:29 +08007336
developera3511852023-06-14 14:12:59 +08007337 return ret;
developer72fb0bb2023-01-11 09:46:29 +08007338}
7339
7340struct channels_noise {
developera3511852023-06-14 14:12:59 +08007341 int channel;
7342 int noise;
developer72fb0bb2023-01-11 09:46:29 +08007343};
7344
7345// Return noise array for each channel
7346int get_noise(int radioIndex, struct channels_noise *channels_noise_arr, int channels_num)
7347{
developera3511852023-06-14 14:12:59 +08007348 char interface_name[16] = {0};
7349 FILE *f = NULL;
7350 char cmd[128] = {0};
7351 char line[256] = {0};
developer75bd10c2023-06-27 11:34:08 +08007352 int tmp = 0, arr_index = -1, res;
developer72fb0bb2023-01-11 09:46:29 +08007353
developera3511852023-06-14 14:12:59 +08007354 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
7355 return RETURN_ERR;
developer75bd10c2023-06-27 11:34:08 +08007356
7357 res = snprintf(cmd, sizeof(cmd), "iw dev %s survey dump | grep 'frequency\\|noise' | awk '{print $2}'", interface_name);
7358 if (os_snprintf_error(sizeof(cmd), res)) {
7359 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
7360 return RETURN_ERR;
7361 }
developer8078acf2023-08-04 18:52:48 +08007362 f = v_secure_popen("r", "iw dev %s survey dump | grep 'frequency\\|noise' | awk '{print $2}'", interface_name);
7363 if (f == NULL) {
7364 wifi_dbg_printf("%s: v_secure_popen %s error\n", __func__, cmd);
developera3511852023-06-14 14:12:59 +08007365 return RETURN_ERR;
7366 }
developer69b61b02023-03-07 17:17:44 +08007367
developera3511852023-06-14 14:12:59 +08007368 while(fgets(line, sizeof(line), f) != NULL) {
7369 if(arr_index < channels_num){
developer37646972023-06-29 10:58:43 +08007370 if (sscanf(line, "%d", &tmp) == EOF)
7371 continue;
developera3511852023-06-14 14:12:59 +08007372 if (tmp > 0) { // channel frequency, the first line must be frequency
7373 arr_index++;
7374 channels_noise_arr[arr_index].channel = ieee80211_frequency_to_channel(tmp);
7375 } else { // noise
7376 channels_noise_arr[arr_index].noise = tmp;
7377 }
7378 }else{
7379 break;
7380 }
7381 }
developer8078acf2023-08-04 18:52:48 +08007382 v_secure_pclose(f);
developera3511852023-06-14 14:12:59 +08007383 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007384}
7385
7386//Start the wifi scan and get the result into output buffer for RDKB to parser. The result will be used to manage endpoint list
7387//HAL funciton should allocate an data structure array, and return to caller with "neighbor_ap_array"
developer69b61b02023-03-07 17:17:44 +08007388INT wifi_getNeighboringWiFiDiagnosticResult2(INT radioIndex, wifi_neighbor_ap2_t **neighbor_ap_array, UINT *output_array_size) //Tr181
developer72fb0bb2023-01-11 09:46:29 +08007389{
developera3511852023-06-14 14:12:59 +08007390 int index = -1;
7391 wifi_neighbor_ap2_t *scan_array = NULL;
7392 char cmd[256]={0};
7393 char buf[128]={0};
7394 char file_name[32] = {0};
7395 char filter_SSID[32] = {0};
7396 char line[256] = {0};
7397 char interface_name[16] = {0};
7398 char *ret = NULL;
7399 int freq=0;
7400 FILE *f = NULL;
developerc14d83a2023-06-29 20:09:42 +08007401 unsigned long channels_num = 0;
developera3511852023-06-14 14:12:59 +08007402 int vht_channel_width = 0;
7403 int get_noise_ret = RETURN_ERR;
7404 bool filter_enable = false;
7405 bool filter_BSS = false; // The flag determine whether the BSS information need to be filterd.
developere40952c2023-06-15 18:46:43 +08007406 int phyId = 0, res;
developerc14d83a2023-06-29 20:09:42 +08007407 unsigned long len, tmp;
developer72fb0bb2023-01-11 09:46:29 +08007408
developera3511852023-06-14 14:12:59 +08007409 WIFI_ENTRY_EXIT_DEBUG("Inside %s: %d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08007410
developera3511852023-06-14 14:12:59 +08007411 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
7412 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08007413
7414 res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, radioIndex);
7415 if (os_snprintf_error(sizeof(file_name), res)) {
7416 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
7417 return RETURN_ERR;
7418 }
developer72fb0bb2023-01-11 09:46:29 +08007419
developera3511852023-06-14 14:12:59 +08007420 f = fopen(file_name, "r");
7421 if (f != NULL) {
developerd14dff12023-06-28 22:47:44 +08007422 if (fgets(buf, sizeof(file_name), f) == NULL)
7423 wifi_debug(DEBUG_ERROR, "fgets failed\n");
developera3511852023-06-14 14:12:59 +08007424 if ((strncmp(buf, "0", 1)) != 0) {
developerd14dff12023-06-28 22:47:44 +08007425 if (fgets(filter_SSID, sizeof(file_name), f) == NULL)
7426 wifi_debug(DEBUG_ERROR, "fgets failed\n");
developera3511852023-06-14 14:12:59 +08007427 if (strlen(filter_SSID) != 0)
7428 filter_enable = true;
7429 }
developerd14dff12023-06-28 22:47:44 +08007430 if (fclose(f) != 0) {
7431 wifi_debug(DEBUG_ERROR, "fclose fail\n");
7432 return RETURN_ERR;
7433 }
developera3511852023-06-14 14:12:59 +08007434 }
developer72fb0bb2023-01-11 09:46:29 +08007435
developera3511852023-06-14 14:12:59 +08007436 phyId = radio_index_to_phy(radioIndex);
developer8078acf2023-08-04 18:52:48 +08007437
7438 res = _syscmd_secure(buf, sizeof(buf), "iw phy phy%d channels | grep * | grep -v disable | wc -l", phyId);
7439 if (res) {
7440 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08007441 }
7442
developerc14d83a2023-06-29 20:09:42 +08007443 if (hal_strtoul(buf, 10, &tmp) < 0) {
7444 wifi_debug(DEBUG_ERROR, "strtol fail\n");
7445 }
developer72fb0bb2023-01-11 09:46:29 +08007446
developerc14d83a2023-06-29 20:09:42 +08007447 channels_num = tmp;
developer32f2a182023-06-27 19:50:41 +08007448 res = snprintf(cmd, sizeof(cmd), "iw dev %s scan | grep '%s\\|SSID\\|freq\\|beacon interval\\|capabilities\\|signal\\|Supported rates\\|DTIM\\| \
developera3511852023-06-14 14:12:59 +08007449 // WPA\\|RSN\\|Group cipher\\|HT operation\\|secondary channel offset\\|channel width\\|HE.*GHz' | grep -v -e '*.*BSS'", interface_name, interface_name);
developer32f2a182023-06-27 19:50:41 +08007450 if (os_snprintf_error(sizeof(cmd), res)) {
7451 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
7452 return RETURN_ERR;
7453 }
developer86035662023-06-28 19:21:12 +08007454 wifi_debug(DEBUG_ERROR, "cmd: %s\n", cmd);
developer8078acf2023-08-04 18:52:48 +08007455
7456 f = v_secure_popen("r", "iw dev %s scan | grep '%s\\|SSID\\|freq\\|beacon interval\\|capabilities\\|signal\\|Supported rates\\|DTIM\\| \
7457 // WPA\\|RSN\\|Group cipher\\|HT operation\\|secondary channel offset\\|channel width\\|HE.*GHz' | grep -v -e '*.*BSS'", interface_name, interface_name);
7458
7459 if (f == NULL) {
7460 wifi_debug(DEBUG_ERROR, "v_secure_popen error\n");
developera3511852023-06-14 14:12:59 +08007461 return RETURN_ERR;
7462 }
developer9ce44382023-06-28 11:09:37 +08007463 struct channels_noise *channels_noise_arr = NULL;
7464 if(channels_num > 0 && channels_num <= 243){
7465 channels_noise_arr = calloc(channels_num, sizeof(struct channels_noise));
7466 } else{
developerb14b3462023-07-01 18:02:42 +08007467 wifi_debug(DEBUG_ERROR, "channel num = %ld!!\n", channels_num);
developer9ce44382023-06-28 11:09:37 +08007468 }
developer5b23cd02023-07-19 20:26:03 +08007469
developer9ce44382023-06-28 11:09:37 +08007470 if(channels_noise_arr != NULL){
7471 get_noise_ret = get_noise(radioIndex, channels_noise_arr, channels_num);
7472 } else{
developerb14b3462023-07-01 18:02:42 +08007473 wifi_debug(DEBUG_ERROR, "channels_noise_arr is NULL!!\n");
developer9ce44382023-06-28 11:09:37 +08007474 }
developer5b23cd02023-07-19 20:26:03 +08007475
developer69b61b02023-03-07 17:17:44 +08007476
developera3511852023-06-14 14:12:59 +08007477 ret = fgets(line, sizeof(line), f);
7478 while (ret != NULL) {
7479 if(strstr(line, "BSS") != NULL) { // new neighbor info
7480 // The SSID field is not in the first field. So, we should store whole BSS informations and the filter flag.
7481 // And we will determine whether we need the previous BSS infomation when parsing the next BSS field or end of while loop.
7482 // If we don't want the BSS info, we don't realloc more space, and just clean the previous BSS.
developer72fb0bb2023-01-11 09:46:29 +08007483
developera3511852023-06-14 14:12:59 +08007484 if (!filter_BSS) {
7485 index++;
7486 wifi_neighbor_ap2_t *tmp;
7487 tmp = realloc(scan_array, sizeof(wifi_neighbor_ap2_t)*(index+1));
7488 if (tmp == NULL) { // no more memory to use
7489 index--;
7490 wifi_dbg_printf("%s: realloc failed\n", __func__);
7491 break;
7492 }
7493 scan_array = tmp;
7494 }
7495 memset(&(scan_array[index]), 0, sizeof(wifi_neighbor_ap2_t));
developer72fb0bb2023-01-11 09:46:29 +08007496
developera3511852023-06-14 14:12:59 +08007497 filter_BSS = false;
developer86035662023-06-28 19:21:12 +08007498 if (sscanf(line, "BSS %17s", scan_array[index].ap_BSSID) != 1) {
7499 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
7500 goto err;
7501 }
developerc79e9172023-06-06 19:48:03 +08007502 memset(scan_array[index].ap_Mode, 0, sizeof(scan_array[index].ap_Mode));
developera3511852023-06-14 14:12:59 +08007503 memcpy(scan_array[index].ap_Mode, "Infrastructure", strlen("Infrastructure"));
developerc79e9172023-06-06 19:48:03 +08007504 memset(scan_array[index].ap_SecurityModeEnabled, 0, sizeof(scan_array[index].ap_SecurityModeEnabled));
developera3511852023-06-14 14:12:59 +08007505 memcpy(scan_array[index].ap_SecurityModeEnabled, "None", strlen("None"));
developerc79e9172023-06-06 19:48:03 +08007506 memset(scan_array[index].ap_EncryptionMode, 0, sizeof(scan_array[index].ap_EncryptionMode));
developera3511852023-06-14 14:12:59 +08007507 memcpy(scan_array[index].ap_EncryptionMode, "None", strlen("None"));
7508 } else if (strstr(line, "freq") != NULL) {
developer86035662023-06-28 19:21:12 +08007509 if (sscanf(line," freq: %d", &freq) != 1) {
7510 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
developer86035662023-06-28 19:21:12 +08007511 }
developera3511852023-06-14 14:12:59 +08007512 scan_array[index].ap_Channel = ieee80211_frequency_to_channel(freq);
developer72fb0bb2023-01-11 09:46:29 +08007513
developera3511852023-06-14 14:12:59 +08007514 if (freq >= 2412 && freq <= 2484) {
developerc79e9172023-06-06 19:48:03 +08007515 memset(scan_array[index].ap_OperatingFrequencyBand, 0, sizeof(scan_array[index].ap_OperatingFrequencyBand));
developera3511852023-06-14 14:12:59 +08007516 memcpy(scan_array[index].ap_OperatingFrequencyBand, "2.4GHz", strlen("2.4GHz"));
developerc79e9172023-06-06 19:48:03 +08007517 memset(scan_array[index].ap_SupportedStandards, 0, sizeof(scan_array[index].ap_SupportedStandards));
developera3511852023-06-14 14:12:59 +08007518 memcpy(scan_array[index].ap_SupportedStandards, "b,g", strlen("b,g"));
developerc79e9172023-06-06 19:48:03 +08007519 memset(scan_array[index].ap_OperatingStandards, 0, sizeof(scan_array[index].ap_OperatingStandards));
developera3511852023-06-14 14:12:59 +08007520 memcpy(scan_array[index].ap_OperatingStandards, "g", strlen("g"));
7521 }
7522 else if (freq >= 5160 && freq <= 5805) {
developerc79e9172023-06-06 19:48:03 +08007523 memset(scan_array[index].ap_OperatingFrequencyBand, 0, sizeof(scan_array[index].ap_OperatingFrequencyBand));
developera3511852023-06-14 14:12:59 +08007524 memcpy(scan_array[index].ap_OperatingFrequencyBand, "5GHz", strlen("5GHz"));
developerc79e9172023-06-06 19:48:03 +08007525 memset(scan_array[index].ap_SupportedStandards, 0, sizeof(scan_array[index].ap_SupportedStandards));
developera3511852023-06-14 14:12:59 +08007526 memcpy(scan_array[index].ap_SupportedStandards, "a", strlen("a"));
developerc79e9172023-06-06 19:48:03 +08007527 memset(scan_array[index].ap_OperatingStandards, 0, sizeof(scan_array[index].ap_OperatingStandards));
developera3511852023-06-14 14:12:59 +08007528 memcpy(scan_array[index].ap_OperatingStandards, "a", strlen("a"));
7529 }
developer72fb0bb2023-01-11 09:46:29 +08007530
developera3511852023-06-14 14:12:59 +08007531 scan_array[index].ap_Noise = 0;
7532 if (get_noise_ret == RETURN_OK) {
7533 for (int i = 0; i < channels_num; i++) {
7534 if (scan_array[index].ap_Channel == channels_noise_arr[i].channel) {
7535 scan_array[index].ap_Noise = channels_noise_arr[i].noise;
7536 break;
7537 }
7538 }
7539 }
7540 } else if (strstr(line, "beacon interval") != NULL) {
developer86035662023-06-28 19:21:12 +08007541 if (sscanf(line," beacon interval: %d TUs", &(scan_array[index].ap_BeaconPeriod)) != 1) {
7542 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
7543 goto err;
7544 }
developera3511852023-06-14 14:12:59 +08007545 } else if (strstr(line, "signal") != NULL) {
developer86035662023-06-28 19:21:12 +08007546 if (sscanf(line," signal: %d", &(scan_array[index].ap_SignalStrength)) != 1) {
7547 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
7548 goto err;
7549 }
developera3511852023-06-14 14:12:59 +08007550 } else if (strstr(line,"SSID") != NULL) {
developer86035662023-06-28 19:21:12 +08007551 if (sscanf(line," SSID: %32s", scan_array[index].ap_SSID) != 1) {
7552 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
developerb14b3462023-07-01 18:02:42 +08007553 //goto err;
developer86035662023-06-28 19:21:12 +08007554 }
developera3511852023-06-14 14:12:59 +08007555 if (filter_enable && strcmp(scan_array[index].ap_SSID, filter_SSID) != 0) {
7556 filter_BSS = true;
7557 }
7558 } else if (strstr(line, "Supported rates") != NULL) {
7559 char SRate[80] = {0}, *tmp = NULL;
7560 memset(buf, 0, sizeof(buf));
developer32f2a182023-06-27 19:50:41 +08007561 if (strlen(line) >= sizeof(SRate))
developer86035662023-06-28 19:21:12 +08007562 goto err;
developer32f2a182023-06-27 19:50:41 +08007563 strncpy(SRate, line, strlen(line));
developera3511852023-06-14 14:12:59 +08007564 tmp = strtok(SRate, ":");
developer86035662023-06-28 19:21:12 +08007565 if (tmp == NULL)
7566 goto err;
developera3511852023-06-14 14:12:59 +08007567 tmp = strtok(NULL, ":");
developer86035662023-06-28 19:21:12 +08007568 if (tmp == NULL)
7569 goto err;
developer32f2a182023-06-27 19:50:41 +08007570 if (strlen(tmp) >= sizeof(buf))
developer86035662023-06-28 19:21:12 +08007571 goto err;
developer32f2a182023-06-27 19:50:41 +08007572 strncpy(buf, tmp, strlen(tmp));
developera3511852023-06-14 14:12:59 +08007573 memset(SRate, 0, sizeof(SRate));
developer72fb0bb2023-01-11 09:46:29 +08007574
developera3511852023-06-14 14:12:59 +08007575 tmp = strtok(buf, " \n");
7576 while (tmp != NULL) {
developer32f2a182023-06-27 19:50:41 +08007577 if (strlen(tmp) >= (sizeof(SRate) - strlen(SRate)))
developer86035662023-06-28 19:21:12 +08007578 goto err;
developer32f2a182023-06-27 19:50:41 +08007579 strncat(SRate, tmp, sizeof(SRate) - strlen(SRate) - 1);
developera3511852023-06-14 14:12:59 +08007580 if (SRate[strlen(SRate) - 1] == '*') {
7581 SRate[strlen(SRate) - 1] = '\0';
7582 }
developer32f2a182023-06-27 19:50:41 +08007583 if (strlen(SRate) >= (sizeof(SRate) - 1))
developer86035662023-06-28 19:21:12 +08007584 goto err;
developer32f2a182023-06-27 19:50:41 +08007585 strncat(SRate, ",", sizeof(SRate) - strlen(SRate) - 1);
developer72fb0bb2023-01-11 09:46:29 +08007586
developera3511852023-06-14 14:12:59 +08007587 tmp = strtok(NULL, " \n");
7588 }
7589 SRate[strlen(SRate) - 1] = '\0';
developer32f2a182023-06-27 19:50:41 +08007590 if (sizeof(scan_array[index].ap_SupportedDataTransferRates) <= strlen(SRate))
developer86035662023-06-28 19:21:12 +08007591 goto err;
developer32f2a182023-06-27 19:50:41 +08007592 strncpy(scan_array[index].ap_SupportedDataTransferRates, SRate, strlen(SRate));
developera3511852023-06-14 14:12:59 +08007593 } else if (strstr(line, "DTIM") != NULL) {
developer86035662023-06-28 19:21:12 +08007594 if (sscanf(line,"DTIM Period %u", &(scan_array[index].ap_DTIMPeriod)) != 1) {
7595 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
developer86035662023-06-28 19:21:12 +08007596 }
developera3511852023-06-14 14:12:59 +08007597 } else if (strstr(line, "VHT capabilities") != NULL) {
developer32f2a182023-06-27 19:50:41 +08007598 if (sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) <= 4)
developer86035662023-06-28 19:21:12 +08007599 goto err;
developer32f2a182023-06-27 19:50:41 +08007600 strncat(scan_array[index].ap_SupportedStandards, ",ac",
7601 sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) - 1);
7602 memcpy(scan_array[index].ap_OperatingStandards, "ac", 2);
7603 scan_array[index].ap_OperatingStandards[2] = '\0';
developera3511852023-06-14 14:12:59 +08007604 } else if (strstr(line, "HT capabilities") != NULL) {
developer32f2a182023-06-27 19:50:41 +08007605 strncat(scan_array[index].ap_SupportedStandards, ",n", sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) - 1);
7606 memcpy(scan_array[index].ap_OperatingStandards, "n", 1);
7607 scan_array[index].ap_OperatingStandards[1] = '\0';
developera3511852023-06-14 14:12:59 +08007608 } else if (strstr(line, "VHT operation") != NULL) {
developer86035662023-06-28 19:21:12 +08007609 if (fgets(line, sizeof(line), f) == NULL) {
7610 wifi_debug(DEBUG_ERROR, "fgets fail\n");
7611 goto err;
7612 }
7613 if (sscanf(line," * channel width: %d", &vht_channel_width) != 1) {
7614 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
7615 goto err;
7616 }
developera3511852023-06-14 14:12:59 +08007617 if(vht_channel_width == 1) {
developere40952c2023-06-15 18:46:43 +08007618 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11AC_VHT80");
developera3511852023-06-14 14:12:59 +08007619 } else {
developere40952c2023-06-15 18:46:43 +08007620 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11AC_VHT40");
developera3511852023-06-14 14:12:59 +08007621 }
developere40952c2023-06-15 18:46:43 +08007622 if (os_snprintf_error(sizeof(scan_array[index].ap_OperatingChannelBandwidth), res)) {
7623 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developerc14d83a2023-06-29 20:09:42 +08007624 goto err;
developere40952c2023-06-15 18:46:43 +08007625 }
7626
developera3511852023-06-14 14:12:59 +08007627 if (strstr(line, "BSS") != NULL) // prevent to get the next neighbor information
7628 continue;
7629 } else if (strstr(line, "HT operation") != NULL) {
developer86035662023-06-28 19:21:12 +08007630 if (fgets(line, sizeof(line), f) == NULL) {
7631 wifi_debug(DEBUG_ERROR, "fgets fail\n");
7632 goto err;
7633 }
developerc14d83a2023-06-29 20:09:42 +08007634 if (sscanf(line," * secondary channel offset: %127s", buf) != 1) {
developer86035662023-06-28 19:21:12 +08007635 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
7636 goto err;
7637 }
developera3511852023-06-14 14:12:59 +08007638 if (!strcmp(buf, "above")) {
7639 //40Mhz +
developere40952c2023-06-15 18:46:43 +08007640 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11N%s_HT40PLUS", radioIndex%1 ? "A": "G");
developera3511852023-06-14 14:12:59 +08007641 }
7642 else if (!strcmp(buf, "below")) {
7643 //40Mhz -
developere40952c2023-06-15 18:46:43 +08007644 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11N%s_HT40MINUS", radioIndex%1 ? "A": "G");
developera3511852023-06-14 14:12:59 +08007645 } else {
7646 //20Mhz
developere40952c2023-06-15 18:46:43 +08007647 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11N%s_HT20", radioIndex%1 ? "A": "G");
7648 }
7649 if (os_snprintf_error(sizeof(scan_array[index].ap_OperatingChannelBandwidth), res)) {
7650 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developer86035662023-06-28 19:21:12 +08007651 goto err;
developera3511852023-06-14 14:12:59 +08007652 }
developere40952c2023-06-15 18:46:43 +08007653
developera3511852023-06-14 14:12:59 +08007654 if (strstr(line, "BSS") != NULL) // prevent to get the next neighbor information
7655 continue;
7656 } else if (strstr(line, "HE capabilities") != NULL) {
developer32f2a182023-06-27 19:50:41 +08007657 strncat(scan_array[index].ap_SupportedStandards, ",ax",
7658 sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) - 1);
7659 memcpy(scan_array[index].ap_OperatingStandards, "ax", 2);
7660 scan_array[index].ap_OperatingStandards[2] = '\0';
developer86035662023-06-28 19:21:12 +08007661 if (fgets(line, sizeof(line), f) == NULL) {
7662 wifi_debug(DEBUG_ERROR, "fgets fail\n");
7663 goto err;
7664 }
developera3511852023-06-14 14:12:59 +08007665 if (strncmp(scan_array[index].ap_OperatingFrequencyBand, "2.4GHz", strlen("2.4GHz")) == 0) {
developer32f2a182023-06-27 19:50:41 +08007666 if (strstr(line, "HE40/2.4GHz") != NULL) {
7667 len = strlen("11AXHE40PLUS");
7668 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE40PLUS", len);
7669 } else {
7670 len = strlen("11AXHE20");
7671 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE20", len);
7672 }
7673 scan_array[index].ap_OperatingChannelBandwidth[len] = '\0';
developera3511852023-06-14 14:12:59 +08007674 } else if (strncmp(scan_array[index].ap_OperatingFrequencyBand, "5GHz", strlen("5GHz")) == 0) {
7675 if (strstr(line, "HE80/5GHz") != NULL) {
developer32f2a182023-06-27 19:50:41 +08007676 len = strlen("11AXHE80");
7677 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE80", len);
7678 scan_array[index].ap_OperatingChannelBandwidth[len] = '\0';
developer86035662023-06-28 19:21:12 +08007679 if (fgets(line, sizeof(line), f) == NULL) {
7680 wifi_debug(DEBUG_ERROR, "fgets fail\n");
7681 goto err;
7682 }
developera3511852023-06-14 14:12:59 +08007683 } else
7684 continue;
developer32f2a182023-06-27 19:50:41 +08007685 if (strstr(line, "HE160/5GHz") != NULL) {
7686 len = strlen("11AXHE160");
7687 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE160", len);
7688 scan_array[index].ap_OperatingChannelBandwidth[len] = '\0';
7689 }
developera3511852023-06-14 14:12:59 +08007690 }
7691 continue;
7692 } else if (strstr(line, "WPA") != NULL) {
developer32f2a182023-06-27 19:50:41 +08007693 memcpy(scan_array[index].ap_SecurityModeEnabled, "WPA", 3);
7694 scan_array[index].ap_SecurityModeEnabled[3] = '\0';
developera3511852023-06-14 14:12:59 +08007695 } else if (strstr(line, "RSN") != NULL) {
developer32f2a182023-06-27 19:50:41 +08007696 memcpy(scan_array[index].ap_SecurityModeEnabled, "RSN", 3);
7697 scan_array[index].ap_SecurityModeEnabled[3] = '\0';
developera3511852023-06-14 14:12:59 +08007698 } else if (strstr(line, "Group cipher") != NULL) {
developer86035662023-06-28 19:21:12 +08007699 if (sscanf(line, " * Group cipher: %64s", scan_array[index].ap_EncryptionMode) != 1) {
7700 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
7701 goto err;
7702 }
developera3511852023-06-14 14:12:59 +08007703 if (strncmp(scan_array[index].ap_EncryptionMode, "CCMP", strlen("CCMP")) == 0) {
developer32f2a182023-06-27 19:50:41 +08007704 memcpy(scan_array[index].ap_EncryptionMode, "AES", 3);
7705 scan_array[index].ap_EncryptionMode[3] = '\0';
developera3511852023-06-14 14:12:59 +08007706 }
7707 }
developerb14b3462023-07-01 18:02:42 +08007708 ret = fgets(line, sizeof(line), f);
developera3511852023-06-14 14:12:59 +08007709 }
developer72fb0bb2023-01-11 09:46:29 +08007710
developera3511852023-06-14 14:12:59 +08007711 if (!filter_BSS) {
7712 *output_array_size = index + 1;
7713 } else {
7714 memset(&(scan_array[index]), 0, sizeof(wifi_neighbor_ap2_t));
7715 *output_array_size = index;
7716 }
7717 *neighbor_ap_array = scan_array;
developer8078acf2023-08-04 18:52:48 +08007718 v_secure_pclose(f);
developera3511852023-06-14 14:12:59 +08007719 free(channels_noise_arr);
7720 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
7721 return RETURN_OK;
developer86035662023-06-28 19:21:12 +08007722err:
developer8078acf2023-08-04 18:52:48 +08007723 v_secure_pclose(f);
developer86035662023-06-28 19:21:12 +08007724 free(channels_noise_arr);
developerc14d83a2023-06-29 20:09:42 +08007725 if (scan_array)
7726 free(scan_array);
developer86035662023-06-28 19:21:12 +08007727 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
7728 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007729}
7730
7731//>> Deprecated: used for old RDKB code.
7732INT wifi_getRadioWifiTrafficStats(INT radioIndex, wifi_radioTrafficStats_t *output_struct)
7733{
developera3511852023-06-14 14:12:59 +08007734 INT status = RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007735
developera3511852023-06-14 14:12:59 +08007736 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7737 output_struct->wifi_PLCPErrorCount = 0;
7738 output_struct->wifi_FCSErrorCount = 0;
7739 output_struct->wifi_InvalidMACCount = 0;
7740 output_struct->wifi_PacketsOtherReceived = 0;
7741 output_struct->wifi_Noise = 0;
7742 status = RETURN_OK;
7743 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
7744 return status;
developer72fb0bb2023-01-11 09:46:29 +08007745}
7746
7747INT wifi_getBasicTrafficStats(INT apIndex, wifi_basicTrafficStats_t *output_struct)
7748{
developera3511852023-06-14 14:12:59 +08007749 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +08007750
developera3511852023-06-14 14:12:59 +08007751 char buf[1280] = {0};
7752 char *pos = NULL;
developere40952c2023-06-15 18:46:43 +08007753 int res;
developer72fb0bb2023-01-11 09:46:29 +08007754
developera3511852023-06-14 14:12:59 +08007755 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7756 if (NULL == output_struct)
7757 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007758
developera3511852023-06-14 14:12:59 +08007759 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
7760 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007761
developera3511852023-06-14 14:12:59 +08007762 memset(output_struct, 0, sizeof(wifi_basicTrafficStats_t));
developer72fb0bb2023-01-11 09:46:29 +08007763
developer8078acf2023-08-04 18:52:48 +08007764 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s", interface_name);
7765 if (res) {
7766 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08007767 }
7768
developera3511852023-06-14 14:12:59 +08007769 pos = buf;
7770 if ((pos = strstr(pos, "RX packets:")) == NULL)
7771 return RETURN_ERR;
7772 output_struct->wifi_PacketsReceived = atoi(pos+strlen("RX packets:"));
developer72fb0bb2023-01-11 09:46:29 +08007773
developera3511852023-06-14 14:12:59 +08007774 if ((pos = strstr(pos, "TX packets:")) == NULL)
7775 return RETURN_ERR;
7776 output_struct->wifi_PacketsSent = atoi(pos+strlen("TX packets:"));
developer72fb0bb2023-01-11 09:46:29 +08007777
developera3511852023-06-14 14:12:59 +08007778 if ((pos = strstr(pos, "RX bytes:")) == NULL)
7779 return RETURN_ERR;
7780 output_struct->wifi_BytesReceived = atoi(pos+strlen("RX bytes:"));
developer72fb0bb2023-01-11 09:46:29 +08007781
developera3511852023-06-14 14:12:59 +08007782 if ((pos = strstr(pos, "TX bytes:")) == NULL)
7783 return RETURN_ERR;
7784 output_struct->wifi_BytesSent = atoi(pos+strlen("TX bytes:"));
developer72fb0bb2023-01-11 09:46:29 +08007785
developer8078acf2023-08-04 18:52:48 +08007786 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s list_sta | wc -l | tr -d '\n'", interface_name);
7787 if (res) {
7788 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer37646972023-06-29 10:58:43 +08007789 }
developer8078acf2023-08-04 18:52:48 +08007790
developer37646972023-06-29 10:58:43 +08007791 if (sscanf(buf, "%lu", &output_struct->wifi_Associations) == EOF)
7792 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
developer72fb0bb2023-01-11 09:46:29 +08007793
developera3511852023-06-14 14:12:59 +08007794 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
7795 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007796}
7797
7798INT wifi_getWifiTrafficStats(INT apIndex, wifi_trafficStats_t *output_struct)
7799{
developera3511852023-06-14 14:12:59 +08007800 char interface_name[IF_NAME_SIZE] = {0};
7801 char interface_status[MAX_BUF_SIZE] = {0};
7802 char Value[MAX_BUF_SIZE] = {0};
developera3511852023-06-14 14:12:59 +08007803 FILE *fp = NULL;
developere40952c2023-06-15 18:46:43 +08007804 int res;
developerc14d83a2023-06-29 20:09:42 +08007805 unsigned long tmp;
developer72fb0bb2023-01-11 09:46:29 +08007806
developera3511852023-06-14 14:12:59 +08007807 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7808 if (NULL == output_struct)
7809 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007810
developera3511852023-06-14 14:12:59 +08007811 memset(output_struct, 0, sizeof(wifi_trafficStats_t));
developer72fb0bb2023-01-11 09:46:29 +08007812
developera3511852023-06-14 14:12:59 +08007813 if (wifi_GetInterfaceName(apIndex,interface_name) != RETURN_OK)
7814 return RETURN_ERR;
7815 GetIfacestatus(interface_name, interface_status);
developer72fb0bb2023-01-11 09:46:29 +08007816
developerd08b7d52023-08-22 15:41:36 +08007817 if(0 != strncmp(interface_status, "1", 1))
developera3511852023-06-14 14:12:59 +08007818 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08007819
developer33f13ba2023-07-12 16:19:06 +08007820 res = v_secure_system("ifconfig %s > /tmp/SSID_Stats.txt", interface_name);
7821 if (res) {
7822 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developere40952c2023-06-15 18:46:43 +08007823 return RETURN_ERR;
7824 }
developer72fb0bb2023-01-11 09:46:29 +08007825
developera3511852023-06-14 14:12:59 +08007826 fp = fopen("/tmp/SSID_Stats.txt", "r");
7827 if(fp == NULL)
7828 {
7829 printf("/tmp/SSID_Stats.txt not exists \n");
7830 return RETURN_ERR;
7831 }
developer37646972023-06-29 10:58:43 +08007832 if (fclose(fp) == EOF) {
7833 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
7834 return RETURN_ERR;
7835 }
developer72fb0bb2023-01-11 09:46:29 +08007836
developer8078acf2023-08-04 18:52:48 +08007837 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/SSID_Stats.txt | grep 'RX packets' | tr -s ' ' | cut -d ':' -f3 | cut -d ' ' -f1");
7838 if(res) {
7839 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer37646972023-06-29 10:58:43 +08007840 }
developer5b23cd02023-07-19 20:26:03 +08007841
developerc14d83a2023-06-29 20:09:42 +08007842 if (hal_strtoul(Value, 10, &tmp) < 0) {
7843 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08007844 }
developerc14d83a2023-06-29 20:09:42 +08007845 output_struct->wifi_ErrorsReceived = tmp;
developer72fb0bb2023-01-11 09:46:29 +08007846
developer8078acf2023-08-04 18:52:48 +08007847 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/SSID_Stats.txt | grep 'TX packets' | tr -s ' ' | cut -d ':' -f3 | cut -d ' ' -f1");
7848 if(res) {
7849 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer37646972023-06-29 10:58:43 +08007850 }
developerc14d83a2023-06-29 20:09:42 +08007851
7852 if (hal_strtoul(Value, 10, &tmp) < 0) {
7853 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08007854 }
developerc14d83a2023-06-29 20:09:42 +08007855 output_struct->wifi_ErrorsSent = tmp;
developer72fb0bb2023-01-11 09:46:29 +08007856
developer8078acf2023-08-04 18:52:48 +08007857 res = _syscmd_secure(Value, sizeof(Value), "cat /tmp/SSID_Stats.txt | grep 'RX packets' | tr -s ' ' | cut -d ':' -f4 | cut -d ' ' -f1");
7858 if(res) {
7859 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer37646972023-06-29 10:58:43 +08007860 }
developerc14d83a2023-06-29 20:09:42 +08007861
7862 if (hal_strtoul(Value, 10, &tmp) < 0) {
7863 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08007864 }
developerc14d83a2023-06-29 20:09:42 +08007865 output_struct->wifi_DiscardedPacketsReceived = tmp;
developer72fb0bb2023-01-11 09:46:29 +08007866
developer8078acf2023-08-04 18:52:48 +08007867 res = _syscmd_secure(Value, sizeof(Value),"cat /tmp/SSID_Stats.txt | grep 'TX packets' | tr -s ' ' | cut -d ':' -f4 | cut -d ' ' -f1");
7868 if(res) {
7869 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer37646972023-06-29 10:58:43 +08007870 }
developerc14d83a2023-06-29 20:09:42 +08007871
7872 if (hal_strtoul(Value, 10, &tmp) < 0) {
7873 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +08007874 }
developerc14d83a2023-06-29 20:09:42 +08007875 output_struct->wifi_DiscardedPacketsSent = tmp;
developer72fb0bb2023-01-11 09:46:29 +08007876
developera3511852023-06-14 14:12:59 +08007877 output_struct->wifi_UnicastPacketsSent = 0;
7878 output_struct->wifi_UnicastPacketsReceived = 0;
7879 output_struct->wifi_MulticastPacketsSent = 0;
7880 output_struct->wifi_MulticastPacketsReceived = 0;
7881 output_struct->wifi_BroadcastPacketsSent = 0;
7882 output_struct->wifi_BroadcastPacketsRecevied = 0;
7883 output_struct->wifi_UnknownPacketsReceived = 0;
developer72fb0bb2023-01-11 09:46:29 +08007884
developera3511852023-06-14 14:12:59 +08007885 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
7886 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007887}
7888
7889INT wifi_getSSIDTrafficStats(INT apIndex, wifi_ssidTrafficStats_t *output_struct)
7890{
developera3511852023-06-14 14:12:59 +08007891 INT status = RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08007892
developera3511852023-06-14 14:12:59 +08007893 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7894 //Below values should get updated from hal
7895 output_struct->wifi_RetransCount=0;
7896 output_struct->wifi_FailedRetransCount=0;
7897 output_struct->wifi_RetryCount=0;
7898 output_struct->wifi_MultipleRetryCount=0;
7899 output_struct->wifi_ACKFailureCount=0;
7900 output_struct->wifi_AggregatedPacketCount=0;
developer72fb0bb2023-01-11 09:46:29 +08007901
developera3511852023-06-14 14:12:59 +08007902 status = RETURN_OK;
7903 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08007904
developera3511852023-06-14 14:12:59 +08007905 return status;
developer72fb0bb2023-01-11 09:46:29 +08007906}
7907
7908INT wifi_getNeighboringWiFiDiagnosticResult(wifi_neighbor_ap_t **neighbor_ap_array, UINT *output_array_size)
7909{
developera3511852023-06-14 14:12:59 +08007910 INT status = RETURN_ERR;
7911 UINT index;
7912 wifi_neighbor_ap_t *pt=NULL;
developer72fb0bb2023-01-11 09:46:29 +08007913
developera3511852023-06-14 14:12:59 +08007914 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
7915 *output_array_size=2;
7916 //zqiu: HAL alloc the array and return to caller. Caller response to free it.
7917 *neighbor_ap_array=(wifi_neighbor_ap_t *)calloc(sizeof(wifi_neighbor_ap_t), *output_array_size);
developer86035662023-06-28 19:21:12 +08007918 if (*neighbor_ap_array == NULL) {
7919 wifi_debug(DEBUG_ERROR, "calloc fail!\n");
7920 return RETURN_ERR;
7921 }
developera3511852023-06-14 14:12:59 +08007922 for (index = 0, pt=*neighbor_ap_array; index < *output_array_size; index++, pt++) {
developer32f2a182023-06-27 19:50:41 +08007923 pt->ap_Radio[0] = '\0';
7924 pt->ap_SSID[0] = '\0';
7925 pt->ap_BSSID[0] = '\0';
7926 pt->ap_Mode[0] = '\0';
developera3511852023-06-14 14:12:59 +08007927 pt->ap_Channel=1;
7928 pt->ap_SignalStrength=0;
developer32f2a182023-06-27 19:50:41 +08007929 pt->ap_SecurityModeEnabled[0] = '\0';
7930 pt->ap_EncryptionMode[0] = '\0';
7931 pt->ap_OperatingFrequencyBand[0] = '\0';
7932 pt->ap_SupportedStandards[0] = '\0';
7933 pt->ap_OperatingStandards[0] = '\0';
7934 pt->ap_OperatingChannelBandwidth[0] = '\0';
7935 pt->ap_BasicDataTransferRates[0] = '\0';
7936 pt->ap_SupportedDataTransferRates[0] = '\0';
developera3511852023-06-14 14:12:59 +08007937 pt->ap_BeaconPeriod=1;
7938 pt->ap_Noise=0;
developera3511852023-06-14 14:12:59 +08007939 pt->ap_DTIMPeriod=1;
7940 pt->ap_ChannelUtilization = 1;
7941 }
developer72fb0bb2023-01-11 09:46:29 +08007942
developera3511852023-06-14 14:12:59 +08007943 status = RETURN_OK;
7944 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08007945
developera3511852023-06-14 14:12:59 +08007946 return status;
developer72fb0bb2023-01-11 09:46:29 +08007947}
7948
7949//----------------- AP HAL -------------------------------
7950
7951//>> Deprecated: used for old RDKB code.
7952INT wifi_getAllAssociatedDeviceDetail(INT apIndex, ULONG *output_ulong, wifi_device_t **output_struct)
7953{
developera3511852023-06-14 14:12:59 +08007954 if (NULL == output_ulong || NULL == output_struct)
7955 return RETURN_ERR;
7956 *output_ulong = 0;
7957 *output_struct = NULL;
7958 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08007959}
7960
7961#ifdef HAL_NETLINK_IMPL
7962static int AssoDevInfo_callback(struct nl_msg *msg, void *arg) {
developera3511852023-06-14 14:12:59 +08007963 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7964 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
developerc14d83a2023-06-29 20:09:42 +08007965 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1] = {NULL};
7966 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1] = {NULL};
developera3511852023-06-14 14:12:59 +08007967 char mac_addr[20];
7968 static int count=0;
7969 int rate=0;
developer72fb0bb2023-01-11 09:46:29 +08007970
developera3511852023-06-14 14:12:59 +08007971 wifi_device_info_t *out = (wifi_device_info_t*)arg;
developer72fb0bb2023-01-11 09:46:29 +08007972
developera3511852023-06-14 14:12:59 +08007973 nla_parse(tb,
7974 NL80211_ATTR_MAX,
7975 genlmsg_attrdata(gnlh, 0),
7976 genlmsg_attrlen(gnlh, 0),
7977 NULL);
developer72fb0bb2023-01-11 09:46:29 +08007978
developera3511852023-06-14 14:12:59 +08007979 if(!tb[NL80211_ATTR_STA_INFO]) {
developer75bd10c2023-06-27 11:34:08 +08007980 wifi_debug(DEBUG_ERROR, "sta stats missing!\n");
developera3511852023-06-14 14:12:59 +08007981 return NL_SKIP;
7982 }
developer72fb0bb2023-01-11 09:46:29 +08007983
7984
developera3511852023-06-14 14:12:59 +08007985 if(nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,tb[NL80211_ATTR_STA_INFO], stats_policy)) {
developer75bd10c2023-06-27 11:34:08 +08007986 wifi_debug(DEBUG_ERROR, "failed to parse nested attributes!\n");
developera3511852023-06-14 14:12:59 +08007987 return NL_SKIP;
7988 }
developer72fb0bb2023-01-11 09:46:29 +08007989
developera3511852023-06-14 14:12:59 +08007990 //devIndex starts from 1
7991 if( ++count == out->wifi_devIndex )
7992 {
7993 mac_addr_ntoa(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
7994 //Getting the mac addrress
7995 mac_addr_aton(out->wifi_devMacAddress,mac_addr);
developer12fb9f62023-06-30 15:26:27 +08007996 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
7997 if(nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, sinfo[NL80211_STA_INFO_TX_BITRATE], rate_policy)) {
7998 wifi_debug(DEBUG_ERROR, "failed to parse nested rate attributes!");
7999 return NL_SKIP;
8000 }
developera3511852023-06-14 14:12:59 +08008001 }
developer72fb0bb2023-01-11 09:46:29 +08008002
developera3511852023-06-14 14:12:59 +08008003 if(sinfo[NL80211_STA_INFO_TX_BITRATE]) {
8004 if(rinfo[NL80211_RATE_INFO_BITRATE]) {
8005 rate=nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
8006 out->wifi_devTxRate = rate/10;
8007 }
8008 }
developer72fb0bb2023-01-11 09:46:29 +08008009
developer12fb9f62023-06-30 15:26:27 +08008010 if (sinfo[NL80211_STA_INFO_RX_BITRATE]) {
8011 if(nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, sinfo[NL80211_STA_INFO_RX_BITRATE], rate_policy)) {
8012 wifi_debug(DEBUG_ERROR, "failed to parse nested rate attributes!");
8013 return NL_SKIP;
8014 }
developera3511852023-06-14 14:12:59 +08008015 }
developera3511852023-06-14 14:12:59 +08008016 if(sinfo[NL80211_STA_INFO_RX_BITRATE]) {
8017 if(rinfo[NL80211_RATE_INFO_BITRATE]) {
8018 rate=nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
8019 out->wifi_devRxRate = rate/10;
8020 }
8021 }
8022 if(sinfo[NL80211_STA_INFO_SIGNAL_AVG])
8023 out->wifi_devSignalStrength = (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
developer72fb0bb2023-01-11 09:46:29 +08008024
developera3511852023-06-14 14:12:59 +08008025 out->wifi_devAssociatedDeviceAuthentiationState = 1;
8026 count = 0; //starts the count for next cycle
8027 return NL_STOP;
8028 }
developer72fb0bb2023-01-11 09:46:29 +08008029
developera3511852023-06-14 14:12:59 +08008030 return NL_SKIP;
developer72fb0bb2023-01-11 09:46:29 +08008031
8032}
8033#endif
8034
8035INT wifi_getAssociatedDeviceDetail(INT apIndex, INT devIndex, wifi_device_t *output_struct)
8036{
developera3511852023-06-14 14:12:59 +08008037 Netlink nl = {0};
8038 char if_name[IF_NAME_SIZE] = {0};
8039 char interface_name[16] = {0};
developere40952c2023-06-15 18:46:43 +08008040 int res;
developer72fb0bb2023-01-11 09:46:29 +08008041
developera3511852023-06-14 14:12:59 +08008042 wifi_device_info_t info = {0};
8043 info.wifi_devIndex = devIndex;
developer72fb0bb2023-01-11 09:46:29 +08008044
developera3511852023-06-14 14:12:59 +08008045 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
8046 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008047
developere40952c2023-06-15 18:46:43 +08008048 res = snprintf(if_name,sizeof(if_name),"%s", interface_name);
8049 if (os_snprintf_error(sizeof(if_name), res)) {
8050 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8051 return RETURN_ERR;
8052 }
developer72fb0bb2023-01-11 09:46:29 +08008053
developera3511852023-06-14 14:12:59 +08008054 nl.id = initSock80211(&nl);
developer72fb0bb2023-01-11 09:46:29 +08008055
developera3511852023-06-14 14:12:59 +08008056 if (nl.id < 0) {
developer75bd10c2023-06-27 11:34:08 +08008057 wifi_debug(DEBUG_ERROR, "Error initializing netlink \n");
developera3511852023-06-14 14:12:59 +08008058 return -1;
8059 }
developer72fb0bb2023-01-11 09:46:29 +08008060
developera3511852023-06-14 14:12:59 +08008061 struct nl_msg* msg = nlmsg_alloc();
developer72fb0bb2023-01-11 09:46:29 +08008062
developera3511852023-06-14 14:12:59 +08008063 if (!msg) {
developer75bd10c2023-06-27 11:34:08 +08008064 wifi_debug(DEBUG_ERROR, "Failed to allocate netlink message.\n");
developera3511852023-06-14 14:12:59 +08008065 nlfree(&nl);
8066 return -2;
8067 }
developer72fb0bb2023-01-11 09:46:29 +08008068
developera3511852023-06-14 14:12:59 +08008069 genlmsg_put(msg,
8070 NL_AUTO_PID,
8071 NL_AUTO_SEQ,
8072 nl.id,
8073 0,
8074 NLM_F_DUMP,
8075 NL80211_CMD_GET_STATION,
8076 0);
developer72fb0bb2023-01-11 09:46:29 +08008077
developera3511852023-06-14 14:12:59 +08008078 nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(if_name));
8079 nl_send_auto_complete(nl.socket, msg);
8080 nl_cb_set(nl.cb,NL_CB_VALID,NL_CB_CUSTOM,AssoDevInfo_callback,&info);
8081 nl_recvmsgs(nl.socket, nl.cb);
8082 nlmsg_free(msg);
8083 nlfree(&nl);
developer72fb0bb2023-01-11 09:46:29 +08008084
developera3511852023-06-14 14:12:59 +08008085 output_struct->wifi_devAssociatedDeviceAuthentiationState = info.wifi_devAssociatedDeviceAuthentiationState;
8086 output_struct->wifi_devRxRate = info.wifi_devRxRate;
8087 output_struct->wifi_devTxRate = info.wifi_devTxRate;
8088 output_struct->wifi_devSignalStrength = info.wifi_devSignalStrength;
8089 memcpy(&output_struct->wifi_devMacAddress, &info.wifi_devMacAddress, sizeof(info.wifi_devMacAddress));
8090 return RETURN_OK;
8091}
developer72fb0bb2023-01-11 09:46:29 +08008092
developera3511852023-06-14 14:12:59 +08008093INT wifi_kickAssociatedDevice(INT apIndex, wifi_device_t *device)
8094{
8095 if (NULL == device)
8096 return RETURN_ERR;
8097 return RETURN_OK;
8098}
8099//<<
developer72fb0bb2023-01-11 09:46:29 +08008100
developer72fb0bb2023-01-11 09:46:29 +08008101
8102//--------------wifi_ap_hal-----------------------------
8103//enables CTS protection for the radio used by this AP
8104INT wifi_setRadioCtsProtectionEnable(INT apIndex, BOOL enable)
8105{
developera3511852023-06-14 14:12:59 +08008106 //save config and Apply instantly
8107 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008108}
8109
8110// enables OBSS Coexistence - fall back to 20MHz if necessary for the radio used by this ap
8111INT wifi_setRadioObssCoexistenceEnable(INT apIndex, BOOL enable)
8112{
developera3511852023-06-14 14:12:59 +08008113 char config_file[64] = {'\0'};
8114 char config_dat_file[64] = {'\0'};
8115 char buf[64] = {'\0'};
8116 struct params list = {0};
8117 struct params dat = {0};
8118 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08008119 int res;
developereef7d562023-10-21 16:04:21 +08008120 unsigned char ht_coex = 0;
8121 int ret = 0;
developer72fb0bb2023-01-11 09:46:29 +08008122
developera3511852023-06-14 14:12:59 +08008123 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developereef7d562023-10-21 16:04:21 +08008124
8125 if (enable)
8126 ht_coex = 1;
8127
developera3511852023-06-14 14:12:59 +08008128 list.name = "ht_coex";
developere40952c2023-06-15 18:46:43 +08008129 res = snprintf(buf, sizeof(buf), "%d", enable);
8130 if (os_snprintf_error(sizeof(buf), res)) {
8131 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8132 return RETURN_ERR;
8133 }
8134
developera3511852023-06-14 14:12:59 +08008135 list.value = buf;
developer72fb0bb2023-01-11 09:46:29 +08008136
developera3511852023-06-14 14:12:59 +08008137 dat.name = "HT_BSSCoexistence";
8138 dat.value = buf;
developerd1824452023-05-18 12:30:04 +08008139
developera3511852023-06-14 14:12:59 +08008140 band = wifi_index_to_band(apIndex);
developere40952c2023-06-15 18:46:43 +08008141 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
8142 if (os_snprintf_error(sizeof(config_file), res)) {
8143 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8144 return RETURN_ERR;
8145 }
8146
8147 res = snprintf(config_dat_file, sizeof(config_dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
8148 if (os_snprintf_error(sizeof(config_dat_file), res)) {
8149 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8150 return RETURN_ERR;
8151 }
8152
developera3511852023-06-14 14:12:59 +08008153 wifi_hostapdWrite(config_file, &list, 1);
8154 wifi_datfileWrite(config_dat_file, &dat, 1);
8155 wifi_hostapdProcessUpdate(apIndex, &list, 1);
developer72fb0bb2023-01-11 09:46:29 +08008156
developereef7d562023-10-21 16:04:21 +08008157 /*do ht_coex quick setting*/
8158 ret = wifi_setChannel_netlink(band, NULL, NULL, NULL, &ht_coex);
8159 if (ret != RETURN_OK)
8160 wifi_debug(DEBUG_ERROR, "ht_coex quick setting fail\n");
developer72fb0bb2023-01-11 09:46:29 +08008161
developereef7d562023-10-21 16:04:21 +08008162 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developera3511852023-06-14 14:12:59 +08008163 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008164}
8165
8166//P3 // sets the fragmentation threshold in bytes for the radio used by this ap
8167INT wifi_setRadioFragmentationThreshold(INT apIndex, UINT threshold)
8168{
developera3511852023-06-14 14:12:59 +08008169 char config_file[MAX_BUF_SIZE] = {'\0'};
8170 char buf[MAX_BUF_SIZE] = {'\0'};
8171 struct params list;
developere40952c2023-06-15 18:46:43 +08008172 int res;
developer72fb0bb2023-01-11 09:46:29 +08008173
developera3511852023-06-14 14:12:59 +08008174 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
8175 if (threshold < 256 || threshold > 2346 )
8176 return RETURN_ERR;
8177 list.name = "fragm_threshold";
developere40952c2023-06-15 18:46:43 +08008178 res = snprintf(buf, sizeof(buf), "%d", threshold);
8179 if (os_snprintf_error(sizeof(buf), res)) {
8180 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8181 return RETURN_ERR;
8182 }
8183
developera3511852023-06-14 14:12:59 +08008184 list.value = buf;
developer72fb0bb2023-01-11 09:46:29 +08008185
developere40952c2023-06-15 18:46:43 +08008186 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
8187 if (os_snprintf_error(sizeof(config_file), res)) {
8188 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8189 return RETURN_ERR;
8190 }
8191
developera3511852023-06-14 14:12:59 +08008192 wifi_hostapdWrite(config_file, &list, 1);
8193 wifi_hostapdProcessUpdate(apIndex, &list, 1);
developer72fb0bb2023-01-11 09:46:29 +08008194
developera3511852023-06-14 14:12:59 +08008195 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008196
developera3511852023-06-14 14:12:59 +08008197 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008198}
8199
8200// enable STBC mode in the hardwarwe, 0 == not enabled, 1 == enabled
8201INT wifi_setRadioSTBCEnable(INT radioIndex, BOOL STBC_Enable)
8202{
developera3511852023-06-14 14:12:59 +08008203 char config_file[64] = {'\0'};
developer8078acf2023-08-04 18:52:48 +08008204
developera3511852023-06-14 14:12:59 +08008205 char buf[512] = {'\0'};
8206 char stbc_config[16] = {'\0'};
8207 wifi_band band;
8208 int iterator = 0;
8209 BOOL current_stbc = FALSE;
8210 int ant_count = 0;
8211 int ant_bitmap = 0;
8212 struct params list;
8213 char dat_file[64] = {'\0'};
developere40952c2023-06-15 18:46:43 +08008214 int res;
developer72fb0bb2023-01-11 09:46:29 +08008215
developera3511852023-06-14 14:12:59 +08008216 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008217
developera3511852023-06-14 14:12:59 +08008218 band = wifi_index_to_band(radioIndex);
8219 if (band == band_invalid)
8220 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008221
developera3511852023-06-14 14:12:59 +08008222 if (band == band_2_4)
8223 iterator = 1;
8224 else if ((band == band_5) || (band == band_6))
8225 iterator = 2;
8226 else
8227 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008228
developera3511852023-06-14 14:12:59 +08008229 wifi_getRadioTxChainMask(radioIndex, &ant_bitmap);
8230 for (; ant_bitmap > 0; ant_bitmap >>= 1)
8231 ant_count += ant_bitmap & 1;
developer72fb0bb2023-01-11 09:46:29 +08008232
developera3511852023-06-14 14:12:59 +08008233 if (ant_count == 1 && STBC_Enable == TRUE) {
developer75bd10c2023-06-27 11:34:08 +08008234 wifi_debug(DEBUG_ERROR, "can not enable STBC when using only one antenna\n");
developera3511852023-06-14 14:12:59 +08008235 return RETURN_OK;
8236 }
developer72fb0bb2023-01-11 09:46:29 +08008237
developere40952c2023-06-15 18:46:43 +08008238 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
8239 if (os_snprintf_error(sizeof(config_file), res)) {
8240 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8241 return RETURN_ERR;
8242 }
developer72fb0bb2023-01-11 09:46:29 +08008243
developera3511852023-06-14 14:12:59 +08008244 // set ht and vht config
8245 for (int i = 0; i < iterator; i++) {
8246 memset(stbc_config, 0, sizeof(stbc_config));
developer8078acf2023-08-04 18:52:48 +08008247
developera3511852023-06-14 14:12:59 +08008248 memset(buf, 0, sizeof(buf));
8249 list.name = (i == 0)?"ht_capab":"vht_capab";
developere40952c2023-06-15 18:46:43 +08008250 res = snprintf(stbc_config, sizeof(stbc_config), "%s", list.name);
8251 if (os_snprintf_error(sizeof(stbc_config), res)) {
8252 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8253 return RETURN_ERR;
8254 }
8255
developer8078acf2023-08-04 18:52:48 +08008256 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep -E '^%s' | grep 'STBC'", config_file, stbc_config);
8257 if (res) {
8258 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008259 }
8260
developera3511852023-06-14 14:12:59 +08008261 if (strlen(buf) != 0)
8262 current_stbc = TRUE;
8263 if (current_stbc == STBC_Enable)
8264 continue;
developer72fb0bb2023-01-11 09:46:29 +08008265
developera3511852023-06-14 14:12:59 +08008266 if (STBC_Enable == TRUE) {
8267 // Append the STBC flags in capab config
developer8078acf2023-08-04 18:52:48 +08008268
developera3511852023-06-14 14:12:59 +08008269 if (i == 0)
developer8078acf2023-08-04 18:52:48 +08008270 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^ht_capab=.*/s/$/[TX-STBC][RX-STBC1]/' %s", config_file);
developera3511852023-06-14 14:12:59 +08008271 else
developer8078acf2023-08-04 18:52:48 +08008272 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^vht_capab=.*/s/$/[TX-STBC-2BY1][RX-STBC-1]/' %s", config_file);
8273 if (res) {
8274 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008275 }
8276
developera3511852023-06-14 14:12:59 +08008277 } else if (STBC_Enable == FALSE) {
8278 // Remove the STBC flags and remain other flags in capab
developer8078acf2023-08-04 18:52:48 +08008279 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[TX-STBC(-2BY1)?*\\]//' %s", config_file);
8280 if (res) {
8281 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008282 }
developer8078acf2023-08-04 18:52:48 +08008283 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[RX-STBC-?[1-3]*\\]//' %s", config_file);
8284 if (res) {
8285 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008286 }
8287
developera3511852023-06-14 14:12:59 +08008288 }
8289 wifi_hostapdRead(config_file, list.name, buf, sizeof(buf));
8290 list.value = buf;
8291 wifi_hostapdProcessUpdate(radioIndex, &list, 1);
8292 }
developere40952c2023-06-15 18:46:43 +08008293 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
8294 if (os_snprintf_error(sizeof(dat_file), res)) {
8295 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8296 return RETURN_ERR;
8297 }
8298
developer8078acf2023-08-04 18:52:48 +08008299 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/^HT_STBC=.*/HT_STBC=%d/g' %s", STBC_Enable, dat_file);
8300 if (res) {
8301 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008302 }
8303
developera1255e42023-05-13 17:45:02 +08008304 if ((band == band_5) || (band == band_6)) {
developer8078acf2023-08-04 18:52:48 +08008305 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/^VHT_STBC=.*/VHT_STBC=%d/g' %s", STBC_Enable, dat_file);
8306 if (res) {
8307 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008308 }
8309
developera1255e42023-05-13 17:45:02 +08008310 }
developera3511852023-06-14 14:12:59 +08008311 /*wifi_reloadAp(radioIndex);
developera1255e42023-05-13 17:45:02 +08008312 the caller do this.*/
developer72fb0bb2023-01-11 09:46:29 +08008313
developera3511852023-06-14 14:12:59 +08008314 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
8315 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008316}
8317
developer37ad6bf2023-10-09 11:31:05 +08008318int mtk_get_ap_amsdu_callback(struct nl_msg *msg, void *data) {
8319 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8320 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_AP_BSS_ATTR_MAX + 1];
8321 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8322 unsigned char status;
8323 unsigned char *out_status = data;
8324 int err = 0;
8325
8326 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8327 genlmsg_attrlen(gnlh, 0), NULL);
8328 if (err < 0){
8329 wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
8330 return err;
8331 }
8332
8333 if (tb[NL80211_ATTR_VENDOR_DATA]) {
8334 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_AP_BSS_ATTR_MAX,
8335 tb[NL80211_ATTR_VENDOR_DATA], NULL);
8336 if (err < 0){
8337 wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_AP_BA_ATTR_MAX fails\n");
8338 return err;
8339 }
8340
8341 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN]) {
8342 status = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN]);
8343 if (status == 0) {
8344 wifi_debug(DEBUG_INFO, "disabled\n");
8345 } else {
8346 wifi_debug(DEBUG_INFO, "enabled\n");
8347 }
8348 *out_status = status;
8349 }
8350 }
8351 return 0;
8352}
8353
developer72fb0bb2023-01-11 09:46:29 +08008354// outputs A-MSDU enable status, 0 == not enabled, 1 == enabled
8355INT wifi_getRadioAMSDUEnable(INT radioIndex, BOOL *output_bool)
8356{
developer37ad6bf2023-10-09 11:31:05 +08008357 char inf_name[IF_NAME_SIZE] = {0};
8358 unsigned int if_idx = 0;
8359 int ret = -1;
8360 struct unl unl_ins;
8361 struct nl_msg *msg = NULL;
8362 struct nlattr * msg_data = NULL;
8363 struct mtk_nl80211_param param;
developer72fb0bb2023-01-11 09:46:29 +08008364
developer37ad6bf2023-10-09 11:31:05 +08008365 if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
8366 return RETURN_ERR;
8367 if_idx = if_nametoindex(inf_name);
8368 /*init mtk nl80211 vendor cmd*/
8369 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_BSS;
8370 param.if_type = NL80211_ATTR_IFINDEX;
8371 param.if_idx = if_idx;
developer72fb0bb2023-01-11 09:46:29 +08008372
developer37ad6bf2023-10-09 11:31:05 +08008373 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
8374 if (ret) {
8375 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
developer2c22d832023-05-18 17:46:26 +08008376 return RETURN_ERR;
8377 }
developer37ad6bf2023-10-09 11:31:05 +08008378 /*add mtk vendor cmd data*/
8379 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN, 0xf)) {
8380 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN);
8381 nlmsg_free(msg);
8382 goto err;
developere40952c2023-06-15 18:46:43 +08008383 }
8384
developer37ad6bf2023-10-09 11:31:05 +08008385 /*send mtk nl80211 vendor msg*/
8386 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, mtk_get_ap_amsdu_callback, output_bool);
8387 if (ret) {
8388 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
8389 goto err;
8390 }
8391 /*deinit mtk nl80211 vendor msg*/
8392 mtk_nl80211_deint(&unl_ins);
8393 wifi_debug(DEBUG_INFO,"send cmd success, get output_bool:%d\n", *output_bool);
developer2c22d832023-05-18 17:46:26 +08008394 return RETURN_OK;
developer37ad6bf2023-10-09 11:31:05 +08008395err:
8396 mtk_nl80211_deint(&unl_ins);
8397 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
8398 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008399}
8400
8401// enables A-MSDU in the hardware, 0 == not enabled, 1 == enabled
8402INT wifi_setRadioAMSDUEnable(INT radioIndex, BOOL amsduEnable)
8403{
developer37ad6bf2023-10-09 11:31:05 +08008404 char inf_name[IF_NAME_SIZE] = {0};
8405 unsigned int if_idx = 0;
8406 struct unl unl_ins;
8407 struct nl_msg *msg = NULL;
8408 struct nlattr * msg_data = NULL;
8409 struct mtk_nl80211_param param;
8410 int ret = -1;
developer72fb0bb2023-01-11 09:46:29 +08008411
developer37ad6bf2023-10-09 11:31:05 +08008412 if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
developer2c22d832023-05-18 17:46:26 +08008413 return RETURN_ERR;
developer37ad6bf2023-10-09 11:31:05 +08008414 if_idx = if_nametoindex(inf_name);
8415 /*init mtk nl80211 vendor cmd*/
8416 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_BSS;
8417 param.if_type = NL80211_ATTR_IFINDEX;
8418 param.if_idx = if_idx;
8419 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
8420 if (ret) {
8421 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
developere40952c2023-06-15 18:46:43 +08008422 return RETURN_ERR;
8423 }
developer37ad6bf2023-10-09 11:31:05 +08008424 /*add mtk vendor cmd data*/
8425 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN, amsduEnable)) {
8426 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN);
8427 nlmsg_free(msg);
8428 goto err;
8429 }
developer72fb0bb2023-01-11 09:46:29 +08008430
developer37ad6bf2023-10-09 11:31:05 +08008431 /*send mtk nl80211 vendor msg*/
8432 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
8433 if (ret) {
8434 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
8435 goto err;
8436 }
8437 /*deinit mtk nl80211 vendor msg*/
8438 mtk_nl80211_deint(&unl_ins);
developera3511852023-06-14 14:12:59 +08008439 return RETURN_OK;
developer37ad6bf2023-10-09 11:31:05 +08008440err:
8441 mtk_nl80211_deint(&unl_ins);
8442 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
8443 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008444}
8445
8446//P2 // outputs the number of Tx streams
8447INT wifi_getRadioTxChainMask(INT radioIndex, INT *output_int)
8448{
developera3511852023-06-14 14:12:59 +08008449 char buf[8] = {0};
developera3511852023-06-14 14:12:59 +08008450 int phyId = 0;
developere40952c2023-06-15 18:46:43 +08008451 int res;
developerc14d83a2023-06-29 20:09:42 +08008452 long int tmp;
developer72fb0bb2023-01-11 09:46:29 +08008453
developera3511852023-06-14 14:12:59 +08008454 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008455
developera3511852023-06-14 14:12:59 +08008456 phyId = radio_index_to_phy(radioIndex);
developer8078acf2023-08-04 18:52:48 +08008457
8458 res = _syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep 'Configured Antennas' | awk '{print $4}'", phyId);
8459 if (res) {
8460 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008461 }
8462
developer72fb0bb2023-01-11 09:46:29 +08008463
developerc14d83a2023-06-29 20:09:42 +08008464 if (hal_strtol(buf, 16, &tmp) < 0) {
8465 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08008466 }
developerc14d83a2023-06-29 20:09:42 +08008467 *output_int = tmp;
developer72fb0bb2023-01-11 09:46:29 +08008468
developera3511852023-06-14 14:12:59 +08008469 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008470
developera3511852023-06-14 14:12:59 +08008471 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008472}
8473
8474INT fitChainMask(INT radioIndex, int antcount)
8475{
developera3511852023-06-14 14:12:59 +08008476 char buf[128] = {0};
developer8078acf2023-08-04 18:52:48 +08008477
developera3511852023-06-14 14:12:59 +08008478 char config_file[64] = {0};
8479 wifi_band band;
8480 struct params list[2] = {0};
developere40952c2023-06-15 18:46:43 +08008481 int res;
developer72fb0bb2023-01-11 09:46:29 +08008482
developera3511852023-06-14 14:12:59 +08008483 band = wifi_index_to_band(radioIndex);
8484 if (band == band_invalid)
8485 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008486
developera3511852023-06-14 14:12:59 +08008487 list[0].name = "he_mu_beamformer";
8488 list[1].name = "he_su_beamformer";
developer72fb0bb2023-01-11 09:46:29 +08008489
developere40952c2023-06-15 18:46:43 +08008490 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
8491 if (os_snprintf_error(sizeof(config_file), res)) {
8492 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8493 return RETURN_ERR;
8494 }
8495
developera3511852023-06-14 14:12:59 +08008496 if (antcount == 1) {
8497 // remove config about multiple antennas
developer8078acf2023-08-04 18:52:48 +08008498 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[TX-STBC(-2BY1)?*\\]//' %s", config_file);
8499 if (res) {
8500 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008501 }
8502
developer8078acf2023-08-04 18:52:48 +08008503 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[SOUNDING-DIMENSION-.\\]//' %s", config_file);
8504 if (res) {
8505 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008506 }
8507
developer8078acf2023-08-04 18:52:48 +08008508 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[SU-BEAMFORMER\\]//' %s", config_file);
8509 if (res) {
8510 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008511 }
8512
developer8078acf2023-08-04 18:52:48 +08008513 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[MU-BEAMFORMER\\]//' %s", config_file);
8514 if (res) {
8515 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008516 }
8517
developera3511852023-06-14 14:12:59 +08008518 list[0].value = "0";
8519 list[1].value = "0";
8520 } else {
8521 // If we only set RX STBC means STBC is enable and TX STBC is disable when last time set one antenna. so we need to add it back.
8522 if (band == band_2_4 || band == band_5) {
developer8078acf2023-08-04 18:52:48 +08008523 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '^ht_capab=.*RX-STBC' | grep -v 'TX-STBC'", config_file);
8524 if (res) {
8525 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008526 }
8527
developera3511852023-06-14 14:12:59 +08008528 if (strlen(buf) > 0) {
developer8078acf2023-08-04 18:52:48 +08008529 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^ht_capab=.*/s/$/[TX-STBC]/' %s", config_file);
8530 if (res) {
8531 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008532 }
developera3511852023-06-14 14:12:59 +08008533 }
8534 }
8535 if (band == band_5) {
developer8078acf2023-08-04 18:52:48 +08008536 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '^vht_capab=.*RX-STBC' | grep -v 'TX-STBC'", config_file);
8537 if (res) {
8538 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008539 }
developera3511852023-06-14 14:12:59 +08008540 if (strlen(buf) > 0) {
developer8078acf2023-08-04 18:52:48 +08008541 res = _syscmd_secure(buf, sizeof(buf) , "sed -r -i '/^vht_capab=.*/s/$/[TX-STBC-2BY1]/' %s", config_file);
8542 if (res) {
8543 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008544 }
developera3511852023-06-14 14:12:59 +08008545 }
8546 }
developer72fb0bb2023-01-11 09:46:29 +08008547
developer8078acf2023-08-04 18:52:48 +08008548 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '\\[SU-BEAMFORMER\\]'", config_file);
8549 if (res) {
8550 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008551 }
8552
developera3511852023-06-14 14:12:59 +08008553 if (strlen(buf) == 0) {
developer8078acf2023-08-04 18:52:48 +08008554 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^vht_capab=.*/s/$/[SU-BEAMFORMER]/' %s", config_file);
8555 if (res) {
8556 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008557 }
developera3511852023-06-14 14:12:59 +08008558 }
developer72fb0bb2023-01-11 09:46:29 +08008559
developer8078acf2023-08-04 18:52:48 +08008560 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '\\[MU-BEAMFORMER\\]'", config_file);
8561 if (res) {
8562 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developerc14d83a2023-06-29 20:09:42 +08008563 }
developera3511852023-06-14 14:12:59 +08008564 if (strlen(buf) == 0) {
developer8078acf2023-08-04 18:52:48 +08008565 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^vht_capab=.*/s/$/[MU-BEAMFORMER]/' %s", config_file);
8566 if (res) {
8567 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08008568 }
developere40952c2023-06-15 18:46:43 +08008569 }
8570
developer8078acf2023-08-04 18:52:48 +08008571 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '\\[SOUNDING-DIMENSION-.\\]'", config_file);
8572 if (res) {
8573 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developera3511852023-06-14 14:12:59 +08008574 }
developera3511852023-06-14 14:12:59 +08008575 if (strlen(buf) == 0) {
developer8078acf2023-08-04 18:52:48 +08008576 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^vht_capab=.*/s/$/[SOUNDING-DIMENSION-%d]/' %s", antcount, config_file);
developera3511852023-06-14 14:12:59 +08008577 } else {
developer8078acf2023-08-04 18:52:48 +08008578 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/(SOUNDING-DIMENSION-)./\\1%d/' %s", antcount, config_file);
developere40952c2023-06-15 18:46:43 +08008579 }
developer8078acf2023-08-04 18:52:48 +08008580 if (res) {
8581 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developera3511852023-06-14 14:12:59 +08008582 }
developere40952c2023-06-15 18:46:43 +08008583
developera3511852023-06-14 14:12:59 +08008584 list[0].value = "1";
8585 list[1].value = "1";
8586 }
8587 wifi_hostapdWrite(config_file, list, 2);
developerdaf24792023-06-06 11:40:04 +08008588 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008589}
8590
8591//P2 // sets the number of Tx streams to an enviornment variable
8592INT wifi_setRadioTxChainMask(INT radioIndex, INT numStreams)
8593{
developera3511852023-06-14 14:12:59 +08008594 char cmd[128] = {0};
8595 char buf[128] = {0};
8596 int phyId = 0;
8597 int cur_mask = 0;
8598 int antcountmsk = 0;
developera1255e42023-05-13 17:45:02 +08008599 INT cur_nss = 0;
developer863a4a62023-06-06 16:55:59 +08008600 CHAR dat_file[64] = {0};
developera3511852023-06-14 14:12:59 +08008601 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +08008602 int res;
developer72fb0bb2023-01-11 09:46:29 +08008603
developera3511852023-06-14 14:12:59 +08008604 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008605
developera3511852023-06-14 14:12:59 +08008606 if (numStreams <= 0) {
developer75bd10c2023-06-27 11:34:08 +08008607 wifi_debug(DEBUG_ERROR, "chainmask is not supported %d.\n", numStreams);
developera3511852023-06-14 14:12:59 +08008608 return RETURN_ERR;
8609 }
developer72fb0bb2023-01-11 09:46:29 +08008610
developera3511852023-06-14 14:12:59 +08008611 wifi_getRadioTxChainMask(radioIndex, &cur_mask);//this is mask value
developera1255e42023-05-13 17:45:02 +08008612 for(; cur_mask > 0; cur_mask >>= 1)//convert to number of streams.
8613 cur_nss += 1;
8614 WIFI_ENTRY_EXIT_DEBUG("%s:cur_nss=%d, new_nss=%d\n", __func__, cur_nss, numStreams);
developera3511852023-06-14 14:12:59 +08008615 if (cur_nss == numStreams)
8616 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008617
developera3511852023-06-14 14:12:59 +08008618 wifi_setRadioEnable(radioIndex, FALSE);
developer72fb0bb2023-01-11 09:46:29 +08008619
developera3511852023-06-14 14:12:59 +08008620 phyId = radio_index_to_phy(radioIndex);
developera1255e42023-05-13 17:45:02 +08008621 //iw need mask value.
8622 for (;numStreams > 0; numStreams--)
8623 antcountmsk |= 0x1 << (numStreams - 1);
developere40952c2023-06-15 18:46:43 +08008624 res = snprintf(cmd, sizeof(cmd), "iw phy%d set antenna 0x%x 2>&1", phyId, antcountmsk);
8625 if (os_snprintf_error(sizeof(cmd), res)) {
8626 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8627 return RETURN_ERR;
8628 }
developerb758dfd2023-06-21 17:32:07 +08008629
developer8078acf2023-08-04 18:52:48 +08008630 res=_syscmd_secure(buf, sizeof(buf), "iw phy%d set antenna 0x%x 2>&1", phyId, antcountmsk);
8631 if (res) {
8632 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
8633 }
8634
developera3511852023-06-14 14:12:59 +08008635 if (strlen(buf) > 0) {
developer75bd10c2023-06-27 11:34:08 +08008636 wifi_debug(DEBUG_ERROR, "cmd %s error, output: %s\n", cmd, buf);
developera3511852023-06-14 14:12:59 +08008637 return RETURN_ERR;
8638 }
8639 band = wifi_index_to_band(radioIndex);
developera1255e42023-05-13 17:45:02 +08008640 if (band == band_invalid) {
8641 printf("%s:Band Error\n", __func__);
8642 return RETURN_ERR;
8643 }
developere40952c2023-06-15 18:46:43 +08008644 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
8645 if (os_snprintf_error(sizeof(dat_file), res)) {
8646 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8647 return RETURN_ERR;
8648 }
developerb758dfd2023-06-21 17:32:07 +08008649
developere40952c2023-06-15 18:46:43 +08008650 res = snprintf(cmd, sizeof(cmd), "sed -r -i 's/^HT_TxStream=.*/HT_TxStream=%d/g' %s", numStreams, dat_file);
8651 if (os_snprintf_error(sizeof(cmd), res)) {
8652 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8653 return RETURN_ERR;
8654 }
developerb758dfd2023-06-21 17:32:07 +08008655
developer8078acf2023-08-04 18:52:48 +08008656 res=_syscmd_secure(buf, sizeof(buf), "sed -r -i 's/^HT_TxStream=.*/HT_TxStream=%d/g' %s", numStreams, dat_file);
8657 if (res) {
8658 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
8659 }
8660
developera3511852023-06-14 14:12:59 +08008661 if (strlen(buf) > 0) {
developer75bd10c2023-06-27 11:34:08 +08008662 wifi_debug(DEBUG_ERROR, "cmd %s error, output: %s\n", cmd, buf);
developera3511852023-06-14 14:12:59 +08008663 return RETURN_ERR;
8664 }
developer8078acf2023-08-04 18:52:48 +08008665
developere40952c2023-06-15 18:46:43 +08008666 res = snprintf(cmd, sizeof(cmd), "sed -r -i 's/^HT_RxStream=.*/HT_RxStream=%d/g' %s", numStreams, dat_file);
8667 if (os_snprintf_error(sizeof(cmd), res)) {
8668 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8669 return RETURN_ERR;
8670 }
developerb758dfd2023-06-21 17:32:07 +08008671
developer8078acf2023-08-04 18:52:48 +08008672 res=_syscmd_secure(buf, sizeof(buf), "sed -r -i 's/^HT_RxStream=.*/HT_RxStream=%d/g' %s", numStreams, dat_file);
8673 if (res) {
8674 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
8675 }
8676
developera3511852023-06-14 14:12:59 +08008677 if (strlen(buf) > 0) {
developer75bd10c2023-06-27 11:34:08 +08008678 wifi_debug(DEBUG_ERROR, "cmd %s error, output: %s\n", cmd, buf);
developera3511852023-06-14 14:12:59 +08008679 return RETURN_ERR;
8680 }
8681 fitChainMask(radioIndex, numStreams);
8682 wifi_setRadioEnable(radioIndex, TRUE);
developer72fb0bb2023-01-11 09:46:29 +08008683
developera3511852023-06-14 14:12:59 +08008684 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
8685 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008686}
8687
8688//P2 // outputs the number of Rx streams
8689INT wifi_getRadioRxChainMask(INT radioIndex, INT *output_int)
8690{
developera3511852023-06-14 14:12:59 +08008691 char buf[8] = {0};
developera3511852023-06-14 14:12:59 +08008692 int phyId = 0;
developer75bd10c2023-06-27 11:34:08 +08008693 int res;
developerc14d83a2023-06-29 20:09:42 +08008694 long int tmp;
developer72fb0bb2023-01-11 09:46:29 +08008695
developera3511852023-06-14 14:12:59 +08008696 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008697
developera3511852023-06-14 14:12:59 +08008698 phyId = radio_index_to_phy(radioIndex);
developer75bd10c2023-06-27 11:34:08 +08008699
developer8078acf2023-08-04 18:52:48 +08008700 res=_syscmd_secure(buf, sizeof(buf), "iw phy%d info | grep 'Configured Antennas' | awk '{print $6}'", phyId);
8701 if (res) {
8702 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +08008703 }
developer72fb0bb2023-01-11 09:46:29 +08008704
developerc14d83a2023-06-29 20:09:42 +08008705 if (hal_strtol(buf, 16, &tmp) < 0) {
8706 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08008707 }
developerc14d83a2023-06-29 20:09:42 +08008708 *output_int = tmp;
developer72fb0bb2023-01-11 09:46:29 +08008709
developera3511852023-06-14 14:12:59 +08008710 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08008711
developera3511852023-06-14 14:12:59 +08008712 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008713}
8714
8715//P2 // sets the number of Rx streams to an enviornment variable
8716INT wifi_setRadioRxChainMask(INT radioIndex, INT numStreams)
8717{
developera3511852023-06-14 14:12:59 +08008718 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
8719 if (wifi_setRadioTxChainMask(radioIndex, numStreams) == RETURN_ERR) {
developer75bd10c2023-06-27 11:34:08 +08008720 wifi_debug(DEBUG_ERROR, "wifi_setRadioTxChainMask return error.\n");
developera3511852023-06-14 14:12:59 +08008721 return RETURN_ERR;
8722 }
8723 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
8724 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008725}
8726
8727//Get radio RDG enable setting
8728INT wifi_getRadioReverseDirectionGrantSupported(INT radioIndex, BOOL *output_bool)
8729{
developer47cc27a2023-05-17 23:09:58 +08008730 if (NULL == output_bool)
8731 return RETURN_ERR;
8732
8733 *output_bool = TRUE;
8734 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008735}
8736
8737//Get radio RDG enable setting
8738INT wifi_getRadioReverseDirectionGrantEnable(INT radioIndex, BOOL *output_bool)
8739{
developer47cc27a2023-05-17 23:09:58 +08008740 char rdg_status[2] = {0};
8741 char dat_file[MAX_CMD_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08008742 int res;
developer47cc27a2023-05-17 23:09:58 +08008743
8744 if (NULL == output_bool)
8745 return RETURN_ERR;
8746
8747 /*prepare dat file path*/
developere40952c2023-06-15 18:46:43 +08008748 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, radioIndex);
8749 if (os_snprintf_error(sizeof(dat_file), res)) {
8750 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8751 return RETURN_ERR;
8752 }
developer47cc27a2023-05-17 23:09:58 +08008753
8754 wifi_datfileRead(dat_file, "HT_RDG", rdg_status, sizeof(rdg_status));
8755 if (!strncmp(rdg_status, "1", sizeof(rdg_status)))
8756 *output_bool = TRUE;
8757 else
8758 *output_bool = FALSE;
8759
8760 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008761}
8762
8763//Set radio RDG enable setting
8764INT wifi_setRadioReverseDirectionGrantEnable(INT radioIndex, BOOL enable)
8765{
developer47cc27a2023-05-17 23:09:58 +08008766 char dat_file[MAX_CMD_SIZE] = {0};
8767 struct params params = {0};
developere40952c2023-06-15 18:46:43 +08008768 int res;
developer47cc27a2023-05-17 23:09:58 +08008769
8770 /*prepare dat file path*/
developere40952c2023-06-15 18:46:43 +08008771 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, radioIndex);
8772 if (os_snprintf_error(sizeof(dat_file), res)) {
8773 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
8774 return RETURN_ERR;
8775 }
developer47cc27a2023-05-17 23:09:58 +08008776
8777 params.name = "HT_RDG";
8778
developera3511852023-06-14 14:12:59 +08008779 if (enable) {
8780 params.value = "1";
8781 } else {
8782 params.value = "0";
8783 }
developer47cc27a2023-05-17 23:09:58 +08008784
8785 wifi_datfileWrite(dat_file, &params, 1);
8786
8787 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08008788}
8789
developer5cd4c862023-05-26 09:34:42 +08008790
8791int mtk_get_ba_auto_status_callback(struct nl_msg *msg, void *data)
developer72fb0bb2023-01-11 09:46:29 +08008792{
developer5cd4c862023-05-26 09:34:42 +08008793 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8794 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_AP_BA_ATTR_MAX + 1];
8795 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8796 unsigned char status;
8797 unsigned char *out_status = data;
8798 int err = 0;
developer8e6583c2023-05-23 13:36:06 +08008799
developer5cd4c862023-05-26 09:34:42 +08008800 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8801 genlmsg_attrlen(gnlh, 0), NULL);
8802 if (err < 0){
8803 wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
8804 return err;
8805 }
developer8e6583c2023-05-23 13:36:06 +08008806
developer5cd4c862023-05-26 09:34:42 +08008807 if (tb[NL80211_ATTR_VENDOR_DATA]) {
8808 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_AP_BA_ATTR_MAX,
8809 tb[NL80211_ATTR_VENDOR_DATA], NULL);
8810 if (err < 0){
8811 wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_AP_BA_ATTR_MAX fails\n");
8812 return err;
8813 }
developer8e6583c2023-05-23 13:36:06 +08008814
developer5cd4c862023-05-26 09:34:42 +08008815 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO]) {
8816 status = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO]);
8817 if (status == 0) {
8818 wifi_debug(DEBUG_NOTICE, "disabled\n");
8819 } else {
8820 wifi_debug(DEBUG_NOTICE, "enabled\n");
8821 }
8822 *out_status = status;
8823 }
8824 }
developer8e6583c2023-05-23 13:36:06 +08008825
developer5cd4c862023-05-26 09:34:42 +08008826 return 0;
8827}
developer8e6583c2023-05-23 13:36:06 +08008828
developer5cd4c862023-05-26 09:34:42 +08008829int mtk_get_ba_decline_status_callback(struct nl_msg *msg, void *data)
8830{
8831 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8832 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_AP_BA_ATTR_MAX + 1];
8833 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8834 unsigned char status;
8835 unsigned char *out_status = data;
8836 int err = 0;
8837
8838 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8839 genlmsg_attrlen(gnlh, 0), NULL);
8840 if (err < 0) {
8841 wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
8842 return err;
8843 }
8844
8845 if (tb[NL80211_ATTR_VENDOR_DATA]) {
8846 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_AP_BA_ATTR_MAX,
8847 tb[NL80211_ATTR_VENDOR_DATA], NULL);
8848 if (err < 0) {
8849 wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_AP_BA_ATTR_MAX fails\n");
8850 return err;
8851 }
8852
8853 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_BA_DECLINE_INFO]) {
8854 status = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_BA_DECLINE_INFO]);
8855 if (status == 0) {
8856 wifi_debug(DEBUG_NOTICE, "disabled\n");
8857 } else {
8858 wifi_debug(DEBUG_NOTICE, "enabled\n");
8859 }
8860 *out_status = status;
8861 }
8862 }
8863
8864 return NL_OK;
developer72fb0bb2023-01-11 09:46:29 +08008865}
8866
developer5cd4c862023-05-26 09:34:42 +08008867INT mtk_wifi_get_ba_decl_auto_status(
8868 INT apIndex, INT vendor_data_attr, mtk_nl80211_cb call_back, BOOL *output_bool)
8869{
8870 char inf_name[IF_NAME_SIZE] = {0};
developer5cd4c862023-05-26 09:34:42 +08008871 unsigned int if_idx = 0;
8872 int ret = -1;
8873 struct unl unl_ins;
8874 struct nl_msg *msg = NULL;
8875 struct nlattr * msg_data = NULL;
8876 struct mtk_nl80211_param param;
8877
8878 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
8879 return RETURN_ERR;
8880 if_idx = if_nametoindex(inf_name);
8881 if (!if_idx) {
8882 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
8883 return RETURN_ERR;
8884 }
8885 /*init mtk nl80211 vendor cmd*/
8886 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_BA;
8887 param.if_type = NL80211_ATTR_IFINDEX;
8888 param.if_idx = if_idx;
8889
8890 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
8891 if (ret) {
8892 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
8893 return RETURN_ERR;
8894 }
8895 /*add mtk vendor cmd data*/
8896 if (nla_put_u8(msg, vendor_data_attr, 0xf)) {
8897 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", vendor_data_attr);
8898 nlmsg_free(msg);
8899 goto err;
8900 }
8901
8902 /*send mtk nl80211 vendor msg*/
8903 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, call_back, output_bool);
8904 if (ret) {
8905 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
8906 goto err;
8907 }
8908 /*deinit mtk nl80211 vendor msg*/
8909 mtk_nl80211_deint(&unl_ins);
8910 wifi_debug(DEBUG_NOTICE,"send cmd success, get output_bool:%d\n", *output_bool);
8911 return RETURN_OK;
8912err:
8913 mtk_nl80211_deint(&unl_ins);
8914 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
8915 return RETURN_ERR;
8916}
developere0ff7232023-06-08 16:33:14 +08008917
8918INT mtk_wifi_set_auto_ba_en(
8919 INT apIndex, INT vendor_data_attr, BOOL enable)
8920{
8921 char inf_name[IF_NAME_SIZE] = {0};
8922 unsigned int if_idx = 0;
8923 int ret = -1;
8924 struct unl unl_ins;
8925 struct nl_msg *msg = NULL;
8926 struct nlattr * msg_data = NULL;
8927 struct mtk_nl80211_param param;
8928
8929 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
8930 return RETURN_ERR;
8931 if_idx = if_nametoindex(inf_name);
8932 if (!if_idx) {
8933 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
8934 return RETURN_ERR;
8935 }
8936 /*init mtk nl80211 vendor cmd*/
8937 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_BA;
8938 param.if_type = NL80211_ATTR_IFINDEX;
8939 param.if_idx = if_idx;
8940
8941 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
8942 if (ret) {
8943 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
8944 return RETURN_ERR;
8945 }
8946 /*add mtk vendor cmd data*/
8947 if (nla_put_u8(msg, vendor_data_attr, enable)) {
8948 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", vendor_data_attr);
8949 nlmsg_free(msg);
8950 goto err;
8951 }
8952
8953 /*send mtk nl80211 vendor msg*/
8954 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
8955 if (ret) {
8956 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
8957 goto err;
8958 }
8959 /*deinit mtk nl80211 vendor msg*/
8960 mtk_nl80211_deint(&unl_ins);
8961 return RETURN_OK;
8962err:
8963 mtk_nl80211_deint(&unl_ins);
8964 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
8965 return RETURN_ERR;
8966}
8967
developer5cd4c862023-05-26 09:34:42 +08008968//Get radio ADDBA enable setting
8969INT wifi_getRadioDeclineBARequestEnable(INT radioIndex, BOOL *output_bool)
8970{
8971 if (output_bool == NULL) {
8972 wifi_debug(DEBUG_ERROR, "invalid: output_bool is null\n");
8973 return RETURN_ERR;
8974 }
8975 if (mtk_wifi_get_ba_decl_auto_status(radioIndex,
8976 MTK_NL80211_VENDOR_ATTR_AP_BA_DECLINE_INFO, mtk_get_ba_decline_status_callback, output_bool) != RETURN_OK) {
8977 wifi_debug(DEBUG_ERROR, "cmd MTK_NL80211_VENDOR_ATTR_AP_BA_DECLINE_INFO(0x%x) fails\n",
8978 MTK_NL80211_VENDOR_ATTR_AP_BA_DECLINE_INFO);
8979 return RETURN_ERR;
8980 }
8981 wifi_debug(DEBUG_NOTICE, "cmd success:output_bool(%d)\n", *output_bool);
8982 return RETURN_OK;
8983}
8984
developer72fb0bb2023-01-11 09:46:29 +08008985//Set radio ADDBA enable setting
8986INT wifi_setRadioDeclineBARequestEnable(INT radioIndex, BOOL enable)
8987{
developera3511852023-06-14 14:12:59 +08008988 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08008989}
8990
8991//Get radio auto block ack enable setting
8992INT wifi_getRadioAutoBlockAckEnable(INT radioIndex, BOOL *output_bool)
8993{
developer5cd4c862023-05-26 09:34:42 +08008994 if (output_bool == NULL) {
8995 wifi_debug(DEBUG_ERROR, "invalid: output_bool is null\n");
8996 return RETURN_ERR;
8997 }
developer8e6583c2023-05-23 13:36:06 +08008998
developera3511852023-06-14 14:12:59 +08008999 if (mtk_wifi_get_ba_decl_auto_status(radioIndex,
developer5cd4c862023-05-26 09:34:42 +08009000 MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO,
9001 mtk_get_ba_auto_status_callback, output_bool) != RETURN_OK) {
9002 wifi_debug(DEBUG_ERROR, "cmd MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO(0x%x) fails\n",
9003 MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO);
9004 return RETURN_ERR;
9005 }
9006 wifi_debug(DEBUG_NOTICE, "cmd success:output_bool(%d)\n", *output_bool);
9007 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009008}
9009
9010//Set radio auto block ack enable setting
9011INT wifi_setRadioAutoBlockAckEnable(INT radioIndex, BOOL enable)
9012{
developera3511852023-06-14 14:12:59 +08009013 if (mtk_wifi_set_auto_ba_en
developere0ff7232023-06-08 16:33:14 +08009014 (radioIndex, MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO, enable) != RETURN_OK) {
9015 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_BA_EN_INFO cmd fails\n");
9016 return RETURN_ERR;
9017 }
9018 wifi_debug(DEBUG_ERROR, "send cmd success: set auto ba enable(%d)\n", enable);
developera3511852023-06-14 14:12:59 +08009019 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009020}
9021
9022//Get radio 11n pure mode enable support
9023INT wifi_getRadio11nGreenfieldSupported(INT radioIndex, BOOL *output_bool)
9024{
developera3511852023-06-14 14:12:59 +08009025 if (NULL == output_bool)
9026 return RETURN_ERR;
9027 *output_bool = TRUE;
9028 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009029}
9030
9031//Get radio 11n pure mode enable setting
9032INT wifi_getRadio11nGreenfieldEnable(INT radioIndex, BOOL *output_bool)
9033{
developera3511852023-06-14 14:12:59 +08009034 if (NULL == output_bool)
9035 return RETURN_ERR;
9036 *output_bool = TRUE;
9037 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009038}
9039
9040//Set radio 11n pure mode enable setting
developer86035662023-06-28 19:21:12 +08009041INT wifi_setRadio11nGreenfieldEnable(INT radioIndex, BOOL enable)
developer72fb0bb2023-01-11 09:46:29 +08009042{
developer82533be2023-06-28 17:21:01 +08009043 char interface_name[16] = {0};
9044 int if_idx, ret = 0;
9045 struct nl_msg *msg = NULL;
9046 struct nlattr * msg_data = NULL;
9047 struct mtk_nl80211_param param;
9048 struct unl unl_ins;
9049
9050 if (radioIndex > MAX_APS) {
9051 wifi_debug(DEBUG_ERROR, "Invalid apIndex %d\n", radioIndex);
9052 return RETURN_ERR;
9053 }
9054 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
9055 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
9056 return RETURN_ERR;
developerd14dff12023-06-28 22:47:44 +08009057
developer82533be2023-06-28 17:21:01 +08009058 if_idx = if_nametoindex(interface_name);
9059 /*init mtk nl80211 vendor cmd*/
9060 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_BSS;
9061 param.if_type = NL80211_ATTR_IFINDEX;
9062 param.if_idx = if_idx;
9063 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
9064 if (ret) {
9065 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
9066 return RETURN_ERR;
9067 }
9068 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_HT_OP_MODE, enable)) {
9069 printf("Nla put attribute error\n");
9070 nlmsg_free(msg);
9071 goto err;
9072 }
9073 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
9074 if (ret) {
9075 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
9076 goto err;
9077 }
9078 mtk_nl80211_deint(&unl_ins);
9079 //wifi_debug(DEBUG_NOTICE, "set Gf cmd success.\n");
9080 printf("set gf=%d cmd success.\n", enable);
9081 return RETURN_OK;
9082err:
9083 mtk_nl80211_deint(&unl_ins);
9084 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
developera3511852023-06-14 14:12:59 +08009085 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009086}
9087
developer5cd4c862023-05-26 09:34:42 +08009088int mtk_get_igmp_status_callback(struct nl_msg *msg, void *data)
developer72fb0bb2023-01-11 09:46:29 +08009089{
developer5cd4c862023-05-26 09:34:42 +08009090 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9091 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_MCAST_SNOOP_ATTR_MAX + 1];
9092 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9093 unsigned char status = 0, *out_status = data;
9094 int err = 0;
developer72fb0bb2023-01-11 09:46:29 +08009095
developer5cd4c862023-05-26 09:34:42 +08009096 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9097 genlmsg_attrlen(gnlh, 0), NULL);
9098 if (err < 0) {
9099 wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
9100 return err;
9101 }
developer72fb0bb2023-01-11 09:46:29 +08009102
developer5cd4c862023-05-26 09:34:42 +08009103 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9104 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_MCAST_SNOOP_ATTR_MAX,
9105 tb[NL80211_ATTR_VENDOR_DATA], NULL);
9106 if (err < 0){
9107 wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_MCAST_SNOOP_ATTR_MAX fails\n");
9108 return err;
9109 }
developer72fb0bb2023-01-11 09:46:29 +08009110
developer5cd4c862023-05-26 09:34:42 +08009111 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_MCAST_SNOOP_ENABLE]) {
9112 status = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_MCAST_SNOOP_ENABLE]);
9113 if (status == 0) {
9114 wifi_debug(DEBUG_NOTICE, "disabled\n");
9115 } else {
9116 wifi_debug(DEBUG_NOTICE, "enabled\n");
9117 }
9118 *out_status = status;
9119 wifi_debug(DEBUG_NOTICE, "status: %d\n", *out_status);
9120 }
9121 }
9122
9123 return 0;
9124}
9125
9126INT mtk_wifi_set_igmp_en_status(
9127 INT apIndex, INT vendor_data_attr, mtk_nl80211_cb call_back,
9128 unsigned char in_en_stat, BOOL *output_bool)
9129{
9130 char inf_name[IF_NAME_SIZE] = {0};
developer5cd4c862023-05-26 09:34:42 +08009131 unsigned int if_idx = 0;
9132 int ret = -1;
9133 struct unl unl_ins;
9134 struct nl_msg *msg = NULL;
9135 struct nlattr * msg_data = NULL;
9136 struct mtk_nl80211_param param;
9137
9138 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
9139 return RETURN_ERR;
9140 if_idx = if_nametoindex(inf_name);
9141 if (!if_idx) {
9142 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
9143 return RETURN_ERR;
9144 }
9145 /*init mtk nl80211 vendor cmd*/
9146 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_MULTICAST_SNOOPING;
9147 param.if_type = NL80211_ATTR_IFINDEX;
9148 param.if_idx = if_idx;
9149
9150 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
9151 if (ret) {
9152 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
9153 return RETURN_ERR;
9154 }
9155 /*add mtk vendor cmd data*/
9156 if (nla_put_u8(msg, vendor_data_attr, in_en_stat)) {
9157 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", vendor_data_attr);
9158 nlmsg_free(msg);
9159 goto err;
9160 }
9161
9162 /*send mtk nl80211 vendor msg*/
9163 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, call_back, output_bool);
9164 if (ret) {
9165 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
9166 goto err;
9167 }
9168 /*deinit mtk nl80211 vendor msg*/
9169 mtk_nl80211_deint(&unl_ins);
9170 if (output_bool) {
9171 wifi_debug(DEBUG_NOTICE, "send cmd success, get output_bool:%d\n", *output_bool);
9172 } else {
9173 wifi_debug(DEBUG_NOTICE, "send cmd success.\n");
9174 }
9175 return RETURN_OK;
9176err:
9177 mtk_nl80211_deint(&unl_ins);
9178 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
9179 return RETURN_ERR;
9180}
9181
9182
9183//Get radio IGMP snooping enable setting
9184INT wifi_getRadioIGMPSnoopingEnable(INT radioIndex, BOOL *output_bool)
9185{
9186 if (output_bool == NULL) {
9187 wifi_debug(DEBUG_ERROR, "invalid: output_bool is null\n");
9188 return RETURN_ERR;
9189 }
developera3511852023-06-14 14:12:59 +08009190 if (mtk_wifi_set_igmp_en_status
developer5cd4c862023-05-26 09:34:42 +08009191 (radioIndex, MTK_NL80211_VENDOR_ATTR_MCAST_SNOOP_ENABLE,
9192 mtk_get_igmp_status_callback, 0xf, output_bool)!= RETURN_OK) {
9193 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_MCAST_SNOOP_ENABLE cmd fails\n");
9194 return RETURN_ERR;
9195 }
9196 wifi_debug(DEBUG_ERROR, "send cmd success: get igmp status:(%d)\n", *output_bool);
developera3511852023-06-14 14:12:59 +08009197 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009198}
9199
9200//Set radio IGMP snooping enable setting
9201INT wifi_setRadioIGMPSnoopingEnable(INT radioIndex, BOOL enable)
9202{
developera3511852023-06-14 14:12:59 +08009203 if (mtk_wifi_set_igmp_en_status
developer5cd4c862023-05-26 09:34:42 +08009204 (radioIndex, MTK_NL80211_VENDOR_ATTR_MCAST_SNOOP_ENABLE,
9205 NULL, enable, NULL) != RETURN_OK) {
9206 wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_MCAST_SNOOP_ENABLE cmd fails\n");
9207 return RETURN_ERR;
9208 }
9209 wifi_debug(DEBUG_ERROR, "send cmd success: set igmp enable(%d)\n", enable);
developera3511852023-06-14 14:12:59 +08009210 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009211}
9212
9213//Get the Reset count of radio
developer69b61b02023-03-07 17:17:44 +08009214INT wifi_getRadioResetCount(INT radioIndex, ULONG *output_int)
developer72fb0bb2023-01-11 09:46:29 +08009215{
developera3511852023-06-14 14:12:59 +08009216 if (NULL == output_int)
9217 return RETURN_ERR;
9218 *output_int = get_radio_reset_cnt(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +08009219
developera3511852023-06-14 14:12:59 +08009220 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009221}
9222
9223
9224//---------------------------------------------------------------------------------------------------
9225//
9226// Additional Wifi AP level APIs used for Access Point devices
9227//
9228//---------------------------------------------------------------------------------------------------
9229
9230// creates a new ap and pushes these parameters to the hardware
9231INT wifi_createAp(INT apIndex, INT radioIndex, CHAR *essid, BOOL hideSsid)
9232{
developera3511852023-06-14 14:12:59 +08009233 // Deprecated when use hal version 3, use wifi_createVap() instead.
9234 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009235}
9236
9237// deletes this ap entry on the hardware, clears all internal variables associaated with this ap
9238INT wifi_deleteAp(INT apIndex)
9239{
developer7e4a2a62023-04-06 19:56:03 +08009240 char interface_name[16] = {0};
9241 char buf[MAX_BUF_SIZE];
developere40952c2023-06-15 18:46:43 +08009242 int res;
developer72fb0bb2023-01-11 09:46:29 +08009243
developer7e4a2a62023-04-06 19:56:03 +08009244 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
9245 return RETURN_ERR;
developer8a3bbbf2023-03-15 17:47:23 +08009246
developer8078acf2023-08-04 18:52:48 +08009247 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw REMOVE %s", interface_name);
9248 if (res) {
9249 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08009250 }
developer72fb0bb2023-01-11 09:46:29 +08009251
developer7e4a2a62023-04-06 19:56:03 +08009252 wifi_removeApSecVaribles(apIndex);
developer72fb0bb2023-01-11 09:46:29 +08009253
developer7e4a2a62023-04-06 19:56:03 +08009254 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009255}
9256
9257// Outputs a 16 byte or less name assocated with the AP. String buffer must be pre-allocated by the caller
9258INT wifi_getApName(INT apIndex, CHAR *output_string)
9259{
developer7e4a2a62023-04-06 19:56:03 +08009260 char interface_name[IF_NAME_SIZE] = {0};
developer47cc27a2023-05-17 23:09:58 +08009261 int radio_idx = 0;
9262 int bss_idx = 0;
developere40952c2023-06-15 18:46:43 +08009263 int res;
developer72fb0bb2023-01-11 09:46:29 +08009264
developer7e4a2a62023-04-06 19:56:03 +08009265 if(!output_string)
9266 return RETURN_ERR;
9267
9268 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK) {
9269 vap_index_to_array_index(apIndex, &radio_idx, &bss_idx);
9270
developere40952c2023-06-15 18:46:43 +08009271 res = snprintf(output_string, IF_NAME_SIZE, "%s%d", ext_prefix[radio_idx], bss_idx); // For wifiagent generating data model.
developer7e4a2a62023-04-06 19:56:03 +08009272 } else
developere40952c2023-06-15 18:46:43 +08009273 res = snprintf(output_string, IF_NAME_SIZE, "%s", interface_name);
9274
9275 if (os_snprintf_error(IF_NAME_SIZE, res)) {
9276 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9277 return RETURN_ERR;
9278 }
developer7e4a2a62023-04-06 19:56:03 +08009279
9280 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009281}
9282
9283// Outputs the index number in that corresponds to the SSID string
9284INT wifi_getIndexFromName(CHAR *inputSsidString, INT *output_int)
9285{
developer7e4a2a62023-04-06 19:56:03 +08009286 char buf[32] = {0};
9287 char ap_idx = 0;
9288 char *apIndex_str = NULL;
9289 char radio_idx = 0;
9290 char bss_idx = 0;
developere40952c2023-06-15 18:46:43 +08009291 int res;
developerc14d83a2023-06-29 20:09:42 +08009292 long int tmp;
developer72fb0bb2023-01-11 09:46:29 +08009293
developer8078acf2023-08-04 18:52:48 +08009294 res = _syscmd_secure(buf, sizeof(buf), "grep -rn ^interface=%s$ /nvram/hostapd*.conf | cut -d '.' -f1 | cut -d 'd' -f2 | tr -d '\\n'", inputSsidString);
9295 if (res) {
9296 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08009297 }
9298
developer7e4a2a62023-04-06 19:56:03 +08009299 if (strlen(buf)) {
9300 apIndex_str = strtok(buf, "\n");
developerd14dff12023-06-28 22:47:44 +08009301 if (apIndex_str == NULL) {
9302 wifi_debug(DEBUG_ERROR, "strtok fail\n");
9303 return RETURN_ERR;
9304 }
developerc14d83a2023-06-29 20:09:42 +08009305 if (hal_strtol(apIndex_str, 10, &tmp) < 0) {
9306 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +08009307 }
developerc14d83a2023-06-29 20:09:42 +08009308 *output_int = tmp;
developer7e4a2a62023-04-06 19:56:03 +08009309 return RETURN_OK;
9310 }
developer72fb0bb2023-01-11 09:46:29 +08009311
developer7e4a2a62023-04-06 19:56:03 +08009312 /* If interface name is not in hostapd config, the caller maybe wifi agent to generate data model.*/
9313 if (strstr(inputSsidString, PREFIX_WIFI6G)) {
9314 bss_idx = atoi(inputSsidString + strlen(PREFIX_WIFI6G));
9315 radio_idx = 2;
9316 } else if (strstr(inputSsidString, PREFIX_WIFI5G)) {
9317 bss_idx = atoi(inputSsidString + strlen(PREFIX_WIFI5G));
9318 radio_idx = 1;
9319 } else if (strstr(inputSsidString, PREFIX_WIFI2G)) {
9320 bss_idx = atoi(inputSsidString + strlen(PREFIX_WIFI2G));
9321 radio_idx = 0;
9322 } else {
9323 printf("%s: hostapd conf not find, unknow inf(%s), return ERROR!!!(%d).\n",
9324 __func__, inputSsidString, ap_idx);
developera3511852023-06-14 14:12:59 +08009325 *output_int = -1;
9326 return RETURN_ERR;
developer7e4a2a62023-04-06 19:56:03 +08009327 }
9328
9329 ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
9330
developer6c6ef372023-11-08 10:59:14 +08009331 if (ap_idx >= 0 && ap_idx < MAX_APS) {
developer7e4a2a62023-04-06 19:56:03 +08009332 printf("%s: hostapd conf not find, inf(%s), use inf idx(%d).\n",
9333 __func__, inputSsidString, ap_idx);
9334 *output_int = ap_idx;
9335 return RETURN_OK;
9336 }
9337
9338 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009339}
9340
9341INT wifi_getApIndexFromName(CHAR *inputSsidString, INT *output_int)
9342{
developera3511852023-06-14 14:12:59 +08009343 return wifi_getIndexFromName(inputSsidString, output_int);
developer72fb0bb2023-01-11 09:46:29 +08009344}
9345
9346// Outputs a 32 byte or less string indicating the beacon type as "None", "Basic", "WPA", "11i", "WPAand11i"
9347INT wifi_getApBeaconType(INT apIndex, CHAR *output_string)
9348{
developera3511852023-06-14 14:12:59 +08009349 char buf[MAX_BUF_SIZE] = {0};
9350 char config_file[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08009351 int res;
developer72fb0bb2023-01-11 09:46:29 +08009352
developera3511852023-06-14 14:12:59 +08009353 if(NULL == output_string)
9354 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009355
developer32f2a182023-06-27 19:50:41 +08009356 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,apIndex);
9357 if (os_snprintf_error(sizeof(config_file), res)) {
9358 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9359 return RETURN_ERR;
9360 }
developera3511852023-06-14 14:12:59 +08009361 wifi_hostapdRead(config_file, "wpa", buf, sizeof(buf));
9362 if((strcmp(buf,"3")==0))
developere40952c2023-06-15 18:46:43 +08009363 res = snprintf(output_string, 32, "WPAand11i");
developera3511852023-06-14 14:12:59 +08009364 else if((strcmp(buf,"2")==0))
developere40952c2023-06-15 18:46:43 +08009365 res = snprintf(output_string, 32, "11i");
developera3511852023-06-14 14:12:59 +08009366 else if((strcmp(buf,"1")==0))
developere40952c2023-06-15 18:46:43 +08009367 res = snprintf(output_string, 32, "WPA");
developera3511852023-06-14 14:12:59 +08009368 else
developere40952c2023-06-15 18:46:43 +08009369 res = snprintf(output_string, 32, "None");
9370 if (os_snprintf_error(32, res)) {
9371 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9372 return RETURN_ERR;
9373 }
developer72fb0bb2023-01-11 09:46:29 +08009374
developera3511852023-06-14 14:12:59 +08009375 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009376}
9377
9378// Sets the beacon type enviornment variable. Allowed input strings are "None", "Basic", "WPA, "11i", "WPAand11i"
9379INT wifi_setApBeaconType(INT apIndex, CHAR *beaconTypeString)
9380{
developera3511852023-06-14 14:12:59 +08009381 char config_file[MAX_BUF_SIZE] = {0};
9382 struct params list;
developer75bd10c2023-06-27 11:34:08 +08009383 int res;
developer72fb0bb2023-01-11 09:46:29 +08009384
developera3511852023-06-14 14:12:59 +08009385 if (NULL == beaconTypeString)
9386 return RETURN_ERR;
9387 list.name = "wpa";
9388 list.value = "0";
developer72fb0bb2023-01-11 09:46:29 +08009389
developera3511852023-06-14 14:12:59 +08009390 if((strcmp(beaconTypeString,"WPAand11i")==0))
9391 list.value="3";
9392 else if((strcmp(beaconTypeString,"11i")==0))
9393 list.value="2";
9394 else if((strcmp(beaconTypeString,"WPA")==0))
9395 list.value="1";
developer72fb0bb2023-01-11 09:46:29 +08009396
developer75bd10c2023-06-27 11:34:08 +08009397 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9398 if (os_snprintf_error(sizeof(config_file), res)) {
9399 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9400 return RETURN_ERR;
9401 }
developera3511852023-06-14 14:12:59 +08009402 wifi_hostapdWrite(config_file, &list, 1);
9403 wifi_hostapdProcessUpdate(apIndex, &list, 1);
9404 //save the beaconTypeString to wifi config and hostapd config file. Wait for wifi reset or hostapd restart to apply
9405 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009406}
9407
9408// sets the beacon interval on the hardware for this AP
9409INT wifi_setApBeaconInterval(INT apIndex, INT beaconInterval)
9410{
developera3511852023-06-14 14:12:59 +08009411 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
9412 struct params params={'\0'};
9413 char buf[MAX_BUF_SIZE] = {'\0'};
9414 char config_file[MAX_BUF_SIZE] = {'\0'};
developere40952c2023-06-15 18:46:43 +08009415 int res;
developer72fb0bb2023-01-11 09:46:29 +08009416
developera3511852023-06-14 14:12:59 +08009417 params.name = "beacon_int";
developere40952c2023-06-15 18:46:43 +08009418 res = snprintf(buf, sizeof(buf), "%u", beaconInterval);
9419 if (os_snprintf_error(sizeof(buf), res)) {
9420 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9421 return RETURN_ERR;
9422 }
developera3511852023-06-14 14:12:59 +08009423 params.value = buf;
developer72fb0bb2023-01-11 09:46:29 +08009424
developer75bd10c2023-06-27 11:34:08 +08009425 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9426 if (os_snprintf_error(sizeof(config_file), res)) {
9427 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9428 return RETURN_ERR;
9429 }
developera3511852023-06-14 14:12:59 +08009430 wifi_hostapdWrite(config_file, &params, 1);
developer69b61b02023-03-07 17:17:44 +08009431
developera3511852023-06-14 14:12:59 +08009432 wifi_hostapdProcessUpdate(apIndex, &params, 1);
9433 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
9434 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009435}
9436
9437INT wifi_setDTIMInterval(INT apIndex, INT dtimInterval)
9438{
developera3511852023-06-14 14:12:59 +08009439 if (wifi_setApDTIMInterval(apIndex, dtimInterval) != RETURN_OK)
9440 return RETURN_ERR;
9441 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009442}
9443
9444// Get the packet size threshold supported.
9445INT wifi_getApRtsThresholdSupported(INT apIndex, BOOL *output_bool)
9446{
developera3511852023-06-14 14:12:59 +08009447 //save config and apply instantly
9448 if (NULL == output_bool)
9449 return RETURN_ERR;
9450 *output_bool = TRUE;
9451 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009452}
9453
9454// sets the packet size threshold in bytes to apply RTS/CTS backoff rules.
9455INT wifi_setApRtsThreshold(INT apIndex, UINT threshold)
9456{
developera3511852023-06-14 14:12:59 +08009457 char buf[16] = {0};
9458 char config_file[128] = {0};
9459 struct params param = {0};
developere40952c2023-06-15 18:46:43 +08009460 int res;
developer72fb0bb2023-01-11 09:46:29 +08009461
developera3511852023-06-14 14:12:59 +08009462 if (threshold > 65535) {
developer75bd10c2023-06-27 11:34:08 +08009463 wifi_debug(DEBUG_ERROR, "rts threshold %u is too big.\n", threshold);
developera3511852023-06-14 14:12:59 +08009464 return RETURN_ERR;
9465 }
developer72fb0bb2023-01-11 09:46:29 +08009466
developere40952c2023-06-15 18:46:43 +08009467 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9468 if (os_snprintf_error(sizeof(config_file), res)) {
9469 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9470 return RETURN_ERR;
9471 }
9472
9473 res = snprintf(buf, sizeof(buf), "%u", threshold);
9474 if (os_snprintf_error(sizeof(buf), res)) {
9475 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9476 return RETURN_ERR;
9477 }
developera3511852023-06-14 14:12:59 +08009478 param.name = "rts_threshold";
9479 param.value = buf;
9480 wifi_hostapdWrite(config_file, &param, 1);
9481 wifi_hostapdProcessUpdate(apIndex, &param, 1);
9482 wifi_reloadAp(apIndex);
developer72fb0bb2023-01-11 09:46:29 +08009483
developera3511852023-06-14 14:12:59 +08009484 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009485}
9486
9487// outputs up to a 32 byte string as either "TKIPEncryption", "AESEncryption", or "TKIPandAESEncryption"
9488INT wifi_getApWpaEncryptoinMode(INT apIndex, CHAR *output_string)
9489{
developere40952c2023-06-15 18:46:43 +08009490 int res;
9491
developera3511852023-06-14 14:12:59 +08009492 if (NULL == output_string)
9493 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08009494 res = snprintf(output_string, 32, "TKIPandAESEncryption");
9495 if (os_snprintf_error(32, res)) {
9496 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9497 return RETURN_ERR;
9498 }
developera3511852023-06-14 14:12:59 +08009499 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009500
9501}
9502
9503// outputs up to a 32 byte string as either "TKIPEncryption", "AESEncryption", or "TKIPandAESEncryption"
9504INT wifi_getApWpaEncryptionMode(INT apIndex, CHAR *output_string)
9505{
developera3511852023-06-14 14:12:59 +08009506 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
9507 char *param_name = NULL;
9508 char buf[32] = {0}, config_file[MAX_BUF_SIZE] = {0};
developerc79e9172023-06-06 19:48:03 +08009509 unsigned int len;
developere40952c2023-06-15 18:46:43 +08009510 int res;
developer72fb0bb2023-01-11 09:46:29 +08009511
developera3511852023-06-14 14:12:59 +08009512 if(NULL == output_string)
9513 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009514
developer75bd10c2023-06-27 11:34:08 +08009515 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9516 if (os_snprintf_error(sizeof(config_file), res)) {
9517 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9518 return RETURN_ERR;
9519 }
9520
developera3511852023-06-14 14:12:59 +08009521 wifi_hostapdRead(config_file,"wpa",buf,sizeof(buf));
developer72fb0bb2023-01-11 09:46:29 +08009522
developera3511852023-06-14 14:12:59 +08009523 if(strcmp(buf,"0")==0)
9524 {
9525 printf("%s: wpa_mode is %s ......... \n", __func__, buf);
developere40952c2023-06-15 18:46:43 +08009526 res = snprintf(output_string, 32, "None");
9527 if (os_snprintf_error(32, res)) {
9528 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9529 return RETURN_ERR;
9530 }
developera3511852023-06-14 14:12:59 +08009531 return RETURN_OK;
9532 }
9533 else if((strcmp(buf,"3")==0) || (strcmp(buf,"2")==0))
9534 param_name = "rsn_pairwise";
9535 else if((strcmp(buf,"1")==0))
9536 param_name = "wpa_pairwise";
9537 else
9538 return RETURN_ERR;
9539 memset(output_string,'\0',32);
9540 wifi_hostapdRead(config_file,param_name,output_string,32);
9541 if (strlen(output_string) == 0) { // rsn_pairwise is optional. When it is empty use wpa_pairwise instead.
9542 param_name = "wpa_pairwise";
9543 memset(output_string, '\0', 32);
9544 wifi_hostapdRead(config_file, param_name, output_string, 32);
9545 }
9546 wifi_dbg_printf("\n%s output_string=%s",__func__,output_string);
developer72fb0bb2023-01-11 09:46:29 +08009547
developera3511852023-06-14 14:12:59 +08009548 if(strcmp(output_string,"TKIP CCMP") == 0) {
developerc79e9172023-06-06 19:48:03 +08009549 len = strlen("TKIPandAESEncryption");
9550 memcpy(output_string,"TKIPandAESEncryption", len);
9551 output_string[len] = '\0';
9552 } else if(strcmp(output_string,"TKIP") == 0) {
9553 len = strlen("TKIPEncryption");
9554 memcpy(output_string,"TKIPEncryption", len);
9555 output_string[len] = '\0';
9556 } else if(strcmp(output_string,"CCMP") == 0) {
9557 len = strlen("AESEncryption");
9558 memcpy(output_string,"AESEncryption", len);
9559 output_string[len] = '\0';
9560 }
developer72fb0bb2023-01-11 09:46:29 +08009561
developera3511852023-06-14 14:12:59 +08009562 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
9563 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009564}
9565
9566// sets the encyption mode enviornment variable. Valid string format is "TKIPEncryption", "AESEncryption", or "TKIPandAESEncryption"
9567INT wifi_setApWpaEncryptionMode(INT apIndex, CHAR *encMode)
9568{
developera3511852023-06-14 14:12:59 +08009569 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
9570 struct params params={'\0'};
9571 char output_string[32];
9572 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +08009573 int res;
developer72fb0bb2023-01-11 09:46:29 +08009574
developera3511852023-06-14 14:12:59 +08009575 memset(output_string,'\0',32);
9576 wifi_getApBeaconType(apIndex,output_string);
developer72fb0bb2023-01-11 09:46:29 +08009577
developera3511852023-06-14 14:12:59 +08009578 if(strcmp(encMode, "TKIPEncryption") == 0)
9579 params.value = "TKIP";
9580 else if(strcmp(encMode,"AESEncryption") == 0)
9581 params.value = "CCMP";
9582 else if(strcmp(encMode,"TKIPandAESEncryption") == 0)
9583 params.value = "TKIP CCMP";
developer72fb0bb2023-01-11 09:46:29 +08009584
developera3511852023-06-14 14:12:59 +08009585 if((strcmp(output_string,"WPAand11i")==0))
9586 {
9587 params.name = "wpa_pairwise";
developer75bd10c2023-06-27 11:34:08 +08009588 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9589 if (os_snprintf_error(sizeof(config_file), res)) {
9590 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9591 return RETURN_ERR;
9592 }
developera3511852023-06-14 14:12:59 +08009593 wifi_hostapdWrite(config_file, &params, 1);
9594 wifi_hostapdProcessUpdate(apIndex, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +08009595
developera3511852023-06-14 14:12:59 +08009596 params.name = "rsn_pairwise";
developer75bd10c2023-06-27 11:34:08 +08009597 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9598 if (os_snprintf_error(sizeof(config_file), res)) {
9599 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9600 return RETURN_ERR;
9601 }
developera3511852023-06-14 14:12:59 +08009602 wifi_hostapdWrite(config_file, &params, 1);
9603 wifi_hostapdProcessUpdate(apIndex, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +08009604
developera3511852023-06-14 14:12:59 +08009605 return RETURN_OK;
9606 }
9607 else if((strcmp(output_string,"11i")==0))
9608 {
9609 params.name = "rsn_pairwise";
developer75bd10c2023-06-27 11:34:08 +08009610 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9611 if (os_snprintf_error(sizeof(config_file), res)) {
9612 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9613 return RETURN_ERR;
9614 }
developera3511852023-06-14 14:12:59 +08009615 wifi_hostapdWrite(config_file, &params, 1);
9616 wifi_hostapdProcessUpdate(apIndex, &params, 1);
9617 return RETURN_OK;
9618 }
9619 else if((strcmp(output_string,"WPA")==0))
9620 {
9621 params.name = "wpa_pairwise";
developer75bd10c2023-06-27 11:34:08 +08009622 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9623 if (os_snprintf_error(sizeof(config_file), res)) {
9624 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9625 return RETURN_ERR;
9626 }
developera3511852023-06-14 14:12:59 +08009627 wifi_hostapdWrite(config_file, &params, 1);
9628 wifi_hostapdProcessUpdate(apIndex, &params, 1);
9629 return RETURN_OK;
9630 }
developer72fb0bb2023-01-11 09:46:29 +08009631
developera3511852023-06-14 14:12:59 +08009632 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
9633 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009634}
9635
9636// deletes internal security varable settings for this ap
9637INT wifi_removeApSecVaribles(INT apIndex)
9638{
developer0155a502023-06-19 20:33:57 +08009639 char config_file[MAX_BUF_SIZE] = {0};
9640 struct params list;
developer75bd10c2023-06-27 11:34:08 +08009641 int res;
developer0155a502023-06-19 20:33:57 +08009642
9643 list.name = "wpa";
9644 list.value = "0";
9645
developer75bd10c2023-06-27 11:34:08 +08009646 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9647 if (os_snprintf_error(sizeof(config_file), res)) {
9648 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9649 return RETURN_ERR;
9650 }
developer0155a502023-06-19 20:33:57 +08009651 wifi_hostapdWrite(config_file, &list, 1);
9652
9653 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009654}
9655
9656// changes the hardware settings to disable encryption on this ap
9657INT wifi_disableApEncryption(INT apIndex)
9658{
developer0155a502023-06-19 20:33:57 +08009659 char config_file[MAX_BUF_SIZE] = {0};
9660 struct params list;
developer75bd10c2023-06-27 11:34:08 +08009661 int res;
developer0155a502023-06-19 20:33:57 +08009662
9663 list.name = "wpa";
9664 list.value = "0";
9665
developer75bd10c2023-06-27 11:34:08 +08009666 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9667 if (os_snprintf_error(sizeof(config_file), res)) {
9668 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9669 return RETURN_ERR;
9670 }
developer0155a502023-06-19 20:33:57 +08009671 wifi_hostapdWrite(config_file, &list, 1);
9672 wifi_hostapdProcessUpdate(apIndex, &list, 1);
9673 wifi_reloadAp(apIndex);
9674
9675 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009676}
9677
9678// set the authorization mode on this ap
9679// mode mapping as: 1: open, 2: shared, 4:auto
9680INT wifi_setApAuthMode(INT apIndex, INT mode)
9681{
developera3511852023-06-14 14:12:59 +08009682 struct params params={0};
9683 char config_file[64] = {0};
developer75bd10c2023-06-27 11:34:08 +08009684 int res;
developer72fb0bb2023-01-11 09:46:29 +08009685
developera3511852023-06-14 14:12:59 +08009686 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08009687
developera3511852023-06-14 14:12:59 +08009688 wifi_dbg_printf("\n%s algo_mode=%d", __func__, mode);
9689 params.name = "auth_algs";
developer72fb0bb2023-01-11 09:46:29 +08009690
developere5750452023-05-15 16:46:42 +08009691 if ((mode & 1 && mode & 2) || mode & 4)
developera3511852023-06-14 14:12:59 +08009692 params.value = "3";
9693 else if (mode & 2)
9694 params.value = "2";
9695 else if (mode & 1)
9696 params.value = "1";
9697 else
9698 params.value = "0";
developer72fb0bb2023-01-11 09:46:29 +08009699
developer75bd10c2023-06-27 11:34:08 +08009700 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
9701 if (os_snprintf_error(sizeof(config_file), res)) {
9702 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9703 return RETURN_ERR;
9704 }
developera3511852023-06-14 14:12:59 +08009705 wifi_hostapdWrite(config_file, &params, 1);
9706 wifi_hostapdProcessUpdate(apIndex, &params, 1);
developere5750452023-05-15 16:46:42 +08009707 wifi_reloadAp(apIndex);
developera3511852023-06-14 14:12:59 +08009708 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08009709
developera3511852023-06-14 14:12:59 +08009710 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009711}
9712
9713// sets an enviornment variable for the authMode. Valid strings are "None", "EAPAuthentication" or "SharedAuthentication"
9714INT wifi_setApBasicAuthenticationMode(INT apIndex, CHAR *authMode)
9715{
developera3511852023-06-14 14:12:59 +08009716 //save to wifi config, and wait for wifi restart to apply
9717 struct params params={'\0'};
9718 char config_file[MAX_BUF_SIZE] = {0};
9719 int ret;
developer72fb0bb2023-01-11 09:46:29 +08009720
developera3511852023-06-14 14:12:59 +08009721 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
9722 if(authMode == NULL)
9723 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009724
developera3511852023-06-14 14:12:59 +08009725 wifi_dbg_printf("\n%s AuthMode=%s",__func__,authMode);
9726 params.name = "wpa_key_mgmt";
developer72fb0bb2023-01-11 09:46:29 +08009727
developera3511852023-06-14 14:12:59 +08009728 if((strcmp(authMode,"PSKAuthentication") == 0) || (strcmp(authMode,"SharedAuthentication") == 0))
9729 params.value = "WPA-PSK";
9730 else if(strcmp(authMode,"EAPAuthentication") == 0)
9731 params.value = "WPA-EAP";
9732 else if (strcmp(authMode, "SAEAuthentication") == 0)
9733 params.value = "SAE";
9734 else if (strcmp(authMode, "EAP_192-bit_Authentication") == 0)
9735 params.value = "WPA-EAP-SUITE-B-192";
9736 else if (strcmp(authMode, "PSK-SAEAuthentication") == 0)
9737 params.value = "WPA-PSK WPA-PSK-SHA256 SAE";
9738 else if (strcmp(authMode, "Enhanced_Open") == 0)
9739 params.value = "OWE";
9740 else if(strcmp(authMode,"None") == 0) //Donot change in case the authMode is None
9741 return RETURN_OK; //This is taken careof in beaconType
developer72fb0bb2023-01-11 09:46:29 +08009742
developer32f2a182023-06-27 19:50:41 +08009743 ret = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,apIndex);
9744 if (os_snprintf_error(sizeof(config_file), ret)) {
9745 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9746 return RETURN_ERR;
9747 }
developera3511852023-06-14 14:12:59 +08009748 ret=wifi_hostapdWrite(config_file,&params,1);
9749 if(!ret)
9750 ret=wifi_hostapdProcessUpdate(apIndex, &params, 1);
9751 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +08009752
developera3511852023-06-14 14:12:59 +08009753 return ret;
developer72fb0bb2023-01-11 09:46:29 +08009754}
9755
9756// sets an enviornment variable for the authMode. Valid strings are "None", "EAPAuthentication" or "SharedAuthentication"
9757INT wifi_getApBasicAuthenticationMode(INT apIndex, CHAR *authMode)
9758{
developera3511852023-06-14 14:12:59 +08009759 //save to wifi config, and wait for wifi restart to apply
9760 char BeaconType[50] = {0};
9761 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +08009762 int res;
developer32f2a182023-06-27 19:50:41 +08009763 unsigned long len;
developer72fb0bb2023-01-11 09:46:29 +08009764
developera3511852023-06-14 14:12:59 +08009765 *authMode = 0;
9766 wifi_getApBeaconType(apIndex,BeaconType);
9767 printf("%s____%s \n",__FUNCTION__,BeaconType);
developer72fb0bb2023-01-11 09:46:29 +08009768
developer32f2a182023-06-27 19:50:41 +08009769 if(strcmp(BeaconType,"None") == 0) {
9770 memcpy(authMode, "None", 4);
9771 authMode[4] = '\0';
9772 } else {
9773 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,apIndex);
developer75bd10c2023-06-27 11:34:08 +08009774 if (os_snprintf_error(sizeof(config_file), res)) {
9775 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
9776 return RETURN_ERR;
9777 }
developera3511852023-06-14 14:12:59 +08009778 wifi_hostapdRead(config_file, "wpa_key_mgmt", authMode, 32);
9779 wifi_dbg_printf("\n[%s]: AuthMode Name is : %s",__func__,authMode);
developer32f2a182023-06-27 19:50:41 +08009780 if(strcmp(authMode,"WPA-PSK") == 0) {
9781 len = strlen("SharedAuthentication");
9782 memcpy(authMode, "SharedAuthentication", len);
9783 authMode[len] = '\0';
9784 } else if(strcmp(authMode,"WPA-EAP") == 0) {
9785 len = strlen("EAPAuthentication");
9786 memcpy(authMode, "EAPAuthentication", len);
9787 authMode[len] = '\0';
9788 }
developera3511852023-06-14 14:12:59 +08009789 }
developer72fb0bb2023-01-11 09:46:29 +08009790
developera3511852023-06-14 14:12:59 +08009791 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009792}
9793
9794// Outputs the number of stations associated per AP
9795INT wifi_getApNumDevicesAssociated(INT apIndex, ULONG *output_ulong)
9796{
developera3511852023-06-14 14:12:59 +08009797 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +08009798 char buf[128]={0};
9799 BOOL status = false;
developer75bd10c2023-06-27 11:34:08 +08009800 int res;
developer72fb0bb2023-01-11 09:46:29 +08009801
developera3511852023-06-14 14:12:59 +08009802 if(apIndex > MAX_APS)
9803 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009804
developera3511852023-06-14 14:12:59 +08009805 wifi_getApEnable(apIndex,&status);
9806 if (!status)
9807 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009808
developera3511852023-06-14 14:12:59 +08009809 //sprintf(cmd, "iw dev %s station dump | grep Station | wc -l", interface_name);//alternate method
9810 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
9811 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +08009812
9813 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s list_sta | wc -l", interface_name);
9814 if (res) {
9815 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +08009816 }
developer8078acf2023-08-04 18:52:48 +08009817
9818
developerd14dff12023-06-28 22:47:44 +08009819 if (sscanf(buf,"%lu", output_ulong) != 1) {
9820 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
9821 return RETURN_ERR;
9822 }
developer72fb0bb2023-01-11 09:46:29 +08009823
developera3511852023-06-14 14:12:59 +08009824 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009825}
9826
9827// manually removes any active wi-fi association with the device specified on this ap
9828INT wifi_kickApAssociatedDevice(INT apIndex, CHAR *client_mac)
9829{
developera3511852023-06-14 14:12:59 +08009830 char inf_name[16] = {0};
developera3511852023-06-14 14:12:59 +08009831 char buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +08009832 int res;
developer72fb0bb2023-01-11 09:46:29 +08009833
developera3511852023-06-14 14:12:59 +08009834 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
9835 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +08009836
developer8078acf2023-08-04 18:52:48 +08009837 res = _syscmd_secure(buf, sizeof(buf),"hostapd_cli -i %s disassociate %s", inf_name, client_mac);
9838 if (res) {
9839 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +08009840 }
developer7e4a2a62023-04-06 19:56:03 +08009841
developera3511852023-06-14 14:12:59 +08009842 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009843}
9844
9845// outputs the radio index for the specified ap. similar as wifi_getSsidRadioIndex
9846INT wifi_getApRadioIndex(INT apIndex, INT *output_int)
9847{
developer7e4a2a62023-04-06 19:56:03 +08009848 int max_radio_num = 0;
9849
9850 if(NULL == output_int)
9851 return RETURN_ERR;
9852
9853 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +08009854 if(max_radio_num == 0){
9855 return RETURN_ERR;
9856 }
developer7e4a2a62023-04-06 19:56:03 +08009857 *output_int = apIndex % max_radio_num;
9858
9859 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +08009860}
9861
9862// sets the radio index for the specific ap
9863INT wifi_setApRadioIndex(INT apIndex, INT radioIndex)
9864{
developera3511852023-06-14 14:12:59 +08009865 //set to config only and wait for wifi reset to apply settings
9866 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +08009867}
9868
developer0155a502023-06-19 20:33:57 +08009869int mtk_get_ap_metrics(struct nl_msg *msg, void *cb)
9870{
9871 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9872 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_STATISTIC_MAX + 1];
developerc14d83a2023-06-29 20:09:42 +08009873 struct genlmsghdr *gnlh;
developer0155a502023-06-19 20:33:57 +08009874 wdev_ap_metric ap_metric;
9875 wdev_ap_metric *p_ap_metric = &ap_metric;
9876 int err = 0;
9877 struct mtk_nl80211_cb_data *cb_data = cb;
9878
9879 if (!msg || !cb_data) {
developerc14d83a2023-06-29 20:09:42 +08009880 wifi_debug(DEBUG_ERROR, "msgor cb_data is null,error.\n");
developer0155a502023-06-19 20:33:57 +08009881 return NL_SKIP;
9882 }
developerc14d83a2023-06-29 20:09:42 +08009883 gnlh = nlmsg_data(nlmsg_hdr(msg));
developer0155a502023-06-19 20:33:57 +08009884
9885 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9886 genlmsg_attrlen(gnlh, 0), NULL);
9887 if (err < 0) {
9888 wifi_debug(DEBUG_ERROR, "nla_parse ap_metrics nl80211 msg fails,error.\n");
9889 return err;
9890 }
9891
9892 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9893 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_GET_STATISTIC_MAX,
9894 tb[NL80211_ATTR_VENDOR_DATA], NULL);
9895 if (err < 0) {
9896 wifi_debug(DEBUG_ERROR, "GET_STATISTIC_MAX fails,error.\n");
9897 return err;
9898 }
9899
9900 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_AP_METRICS]) {
9901 p_ap_metric = nla_data(vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_AP_METRICS]);
9902 if (p_ap_metric) {
9903 memcpy(cb_data->out_buf , &p_ap_metric->cu, sizeof(unsigned char));
9904 }
9905 }
9906 }
9907
9908 return NL_OK;
9909}
9910
developer121a8e72023-05-22 09:19:39 +08009911
9912#define MAX_ACL_DUMP_LEN 4096
9913int mtk_acl_list_dump_callback(struct nl_msg *msg, void *cb)
9914{
9915 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9916 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_AP_ACL_ATTR_MAX + 1];
developerc14d83a2023-06-29 20:09:42 +08009917 struct genlmsghdr *gnlh;
developer121a8e72023-05-22 09:19:39 +08009918 char *show_str = NULL;
developer2edaf012023-05-24 14:24:53 +08009919 int err = 0;
developer121a8e72023-05-22 09:19:39 +08009920 unsigned short acl_result_len = 0;
9921 struct mtk_nl80211_cb_data *cb_data = cb;
developer121a8e72023-05-22 09:19:39 +08009922 if (!msg || !cb_data) {
developerdaf24792023-06-06 11:40:04 +08009923 wifi_debug(DEBUG_ERROR, "msg(%p) or cb_data(%p) is null,error.\n", msg, cb_data);
developer121a8e72023-05-22 09:19:39 +08009924 return NL_SKIP;
9925 }
developerc14d83a2023-06-29 20:09:42 +08009926
9927 gnlh = nlmsg_data(nlmsg_hdr(msg));
developer121a8e72023-05-22 09:19:39 +08009928 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9929 genlmsg_attrlen(gnlh, 0), NULL);
9930 if (err < 0) {
developer2edaf012023-05-24 14:24:53 +08009931 wifi_debug(DEBUG_ERROR, "nla_parse acl list nl80211 msg fails,error.\n");
developer121a8e72023-05-22 09:19:39 +08009932 return NL_SKIP;
9933 }
developer121a8e72023-05-22 09:19:39 +08009934 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9935 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_AP_ACL_ATTR_MAX,
9936 tb[NL80211_ATTR_VENDOR_DATA], NULL);
9937 if (err < 0)
9938 return NL_SKIP;
9939 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_ACL_LIST_INFO]) {
9940 acl_result_len = nla_len(vndr_tb[MTK_NL80211_VENDOR_ATTR_ACL_LIST_INFO]);
9941 show_str = nla_data(vndr_tb[MTK_NL80211_VENDOR_ATTR_ACL_LIST_INFO]);
9942 if (acl_result_len > MAX_ACL_DUMP_LEN) {
9943 wifi_debug(DEBUG_ERROR,"the scan result len is invalid !!!\n");
9944 return NL_SKIP;
9945 } else if (*(show_str + acl_result_len - 1) != '\0') {
9946 wifi_debug(DEBUG_INFO, "the result string is not ended with right terminator, handle it!!!\n");
9947 *(show_str + acl_result_len - 1) = '\0';
9948 }
9949 wifi_debug(DEBUG_INFO, "driver msg:%s\n", show_str);
developer2edaf012023-05-24 14:24:53 +08009950
9951 if (cb_data->out_len >= acl_result_len) {
9952 memset(cb_data->out_buf, 0, cb_data->out_len);
9953 /*skip the first line: 'policy=1\n' to find the acl mac addrs*/
9954 memmove(cb_data->out_buf, show_str, acl_result_len);
9955 wifi_debug(DEBUG_INFO, "out buff:%s\n", cb_data->out_buf);
9956 } else {
9957 memset(cb_data->out_buf, 0, cb_data->out_len);
developer121a8e72023-05-22 09:19:39 +08009958 }
developer121a8e72023-05-22 09:19:39 +08009959 } else
9960 wifi_debug(DEBUG_ERROR, "no acl result attr\n");
9961 } else
9962 wifi_debug(DEBUG_ERROR, "no any acl result from driver\n");
9963 return NL_OK;
9964}
developer72fb0bb2023-01-11 09:46:29 +08009965// Get the ACL MAC list per AP
developer2edaf012023-05-24 14:24:53 +08009966INT mtk_wifi_getApAclDevices(INT apIndex, CHAR *macArray, UINT buf_size)
developer72fb0bb2023-01-11 09:46:29 +08009967{
developer7e4a2a62023-04-06 19:56:03 +08009968 char inf_name[IF_NAME_SIZE] = {0};
developer121a8e72023-05-22 09:19:39 +08009969 unsigned int if_idx = 0;
9970 int ret = -1;
9971 struct unl unl_ins;
9972 struct nl_msg *msg = NULL;
9973 struct nlattr * msg_data = NULL;
9974 struct mtk_nl80211_param param;
9975 struct mtk_nl80211_cb_data cb_data;
developer7e4a2a62023-04-06 19:56:03 +08009976 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
9977 return RETURN_ERR;
developer121a8e72023-05-22 09:19:39 +08009978 if_idx = if_nametoindex(inf_name);
9979 if (!if_idx) {
developer2edaf012023-05-24 14:24:53 +08009980 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
developer121a8e72023-05-22 09:19:39 +08009981 return RETURN_ERR;
9982 }
9983 /*init mtk nl80211 vendor cmd*/
9984 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_ACL;
9985 param.if_type = NL80211_ATTR_IFINDEX;
9986 param.if_idx = if_idx;
9987
9988 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
9989 if (ret) {
9990 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
9991 return RETURN_ERR;
9992 }
developer121a8e72023-05-22 09:19:39 +08009993 /*add mtk vendor cmd data*/
9994 if (nla_put_flag(msg, MTK_NL80211_VENDOR_ATTR_ACL_SHOW_ALL)) {
developer2edaf012023-05-24 14:24:53 +08009995 wifi_debug(DEBUG_ERROR, "Nla put ACL_SHOW_ALL attribute error\n");
developer121a8e72023-05-22 09:19:39 +08009996 nlmsg_free(msg);
9997 goto err;
9998 }
developer72fb0bb2023-01-11 09:46:29 +08009999
developer121a8e72023-05-22 09:19:39 +080010000 /*send mtk nl80211 vendor msg*/
10001 cb_data.out_buf = macArray;
10002 cb_data.out_len = buf_size;
10003
10004 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, mtk_acl_list_dump_callback, &cb_data);
10005 if (ret) {
10006 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
10007 goto err;
10008 }
10009 /*deinit mtk nl80211 vendor msg*/
10010 mtk_nl80211_deint(&unl_ins);
developer2edaf012023-05-24 14:24:53 +080010011 wifi_debug(DEBUG_NOTICE,"send cmd success, get out_buf:%s\n", macArray);
developera3511852023-06-14 14:12:59 +080010012 return RETURN_OK;
developer121a8e72023-05-22 09:19:39 +080010013err:
10014 mtk_nl80211_deint(&unl_ins);
developer2edaf012023-05-24 14:24:53 +080010015 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
developer121a8e72023-05-22 09:19:39 +080010016 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010017}
10018
developer2edaf012023-05-24 14:24:53 +080010019INT wifi_getApAclDevices(INT apIndex, CHAR *macArray, UINT buf_size)
10020{
10021 char *mac_arry_buf = NULL;
10022
10023 mac_arry_buf = malloc(buf_size);
10024 if (!mac_arry_buf) {
10025 wifi_debug(DEBUG_ERROR,"malloc mac_arry_buf fails\n");
10026 return RETURN_ERR;
10027 }
10028 memset(mac_arry_buf, 0, buf_size);
10029 if (mtk_wifi_getApAclDevices(apIndex, mac_arry_buf, buf_size) != RETURN_OK) {
10030 wifi_debug(DEBUG_ERROR,"mtk_wifi_getApAclDevices get fails\n");
10031 free(mac_arry_buf);
10032 mac_arry_buf = NULL;
10033 return RETURN_ERR;
10034 }
10035 /*
10036 mtk format to wifi hal format:
10037 "policy=1
10038 00:11:22:33:44:55
10039 00:11:22:33:44:66
10040 "
10041 -->
10042 "00:11:22:33:44:55
10043 00:11:22:33:44:66
10044 "
10045 */
10046 memset(macArray, 0, buf_size);
10047 if (*mac_arry_buf != '\0' && strchr(mac_arry_buf,'\n')) {
10048 memmove(macArray, strchr(mac_arry_buf,'\n')+1, strlen(strchr(mac_arry_buf,'\n')+1)+1);
10049 wifi_debug(DEBUG_NOTICE,"macArray:\n%s\n", macArray);
10050 }
10051 free(mac_arry_buf);
10052 mac_arry_buf = NULL;
10053 return RETURN_OK;
10054}
10055
developer72fb0bb2023-01-11 09:46:29 +080010056INT wifi_getApDenyAclDevices(INT apIndex, CHAR *macArray, UINT buf_size)
10057{
developer72fb0bb2023-01-11 09:46:29 +080010058
developer7e4a2a62023-04-06 19:56:03 +080010059 wifi_getApAclDevices(apIndex, macArray, buf_size);
developer72fb0bb2023-01-11 09:46:29 +080010060
developera3511852023-06-14 14:12:59 +080010061 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010062}
10063
10064
10065// Get the list of stations associated per AP
10066INT wifi_getApDevicesAssociated(INT apIndex, CHAR *macArray, UINT buf_size)
10067{
developer7e4a2a62023-04-06 19:56:03 +080010068 char interface_name[IF_NAME_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +080010069 int res;
developer72fb0bb2023-01-11 09:46:29 +080010070
developer7e4a2a62023-04-06 19:56:03 +080010071 if(apIndex > 3) //Currently supporting apIndex upto 3
developera3511852023-06-14 14:12:59 +080010072 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010073
developer7e4a2a62023-04-06 19:56:03 +080010074 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
developera3511852023-06-14 14:12:59 +080010075 return RETURN_ERR;
developer7e4a2a62023-04-06 19:56:03 +080010076
developer8078acf2023-08-04 18:52:48 +080010077 res = _syscmd_secure(macArray, buf_size, "hostapd_cli -i %s list_sta", interface_name);
10078 if (res) {
10079 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
10080 }
10081
developer7e4a2a62023-04-06 19:56:03 +080010082 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010083}
10084
developer8dd72532023-05-17 19:58:35 +080010085int hex2num(char c)
10086{
10087 if (c >= '0' && c <= '9')
10088 return c - '0';
10089 if (c >= 'a' && c <= 'f')
10090 return c - 'a' + 10;
10091 if (c >= 'A' && c <= 'F')
10092 return c - 'A' + 10;
10093 return -1;
10094}
10095
10096/**
10097 * hwaddr_aton2 - Convert ASCII string to MAC address (in any known format)
10098 * @txt: MAC address as a string (e.g., 00:11:22:33:44:55 or 0011.2233.4455)
10099 * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
10100 * Returns: Characters used (> 0) on success, -1 on failure
10101 */
10102int hwaddr_aton2(const char *txt, unsigned char *addr)
10103{
10104 int i;
10105 const char *pos = txt;
10106
10107 for (i = 0; i < 6; i++) {
10108 int a, b;
10109
10110 while (*pos == ':' || *pos == '.' || *pos == '-')
10111 pos++;
10112
10113 a = hex2num(*pos++);
10114 if (a < 0)
10115 return -1;
10116 b = hex2num(*pos++);
10117 if (b < 0)
10118 return -1;
10119 *addr++ = (a << 4) | b;
10120 }
10121
10122 return pos - txt;
10123}
10124
developer72fb0bb2023-01-11 09:46:29 +080010125// adds the mac address to the filter list
10126//DeviceMacAddress is in XX:XX:XX:XX:XX:XX format
10127INT wifi_addApAclDevice(INT apIndex, CHAR *DeviceMacAddress)
10128{
developer7e4a2a62023-04-06 19:56:03 +080010129 char inf_name[IF_NAME_SIZE] = {0};
developer8dd72532023-05-17 19:58:35 +080010130 int if_idx, ret = 0;
developer49b17232023-05-19 16:35:19 +080010131 struct nl_msg *msg = NULL;
10132 struct nlattr * msg_data = NULL;
10133 struct mtk_nl80211_param param;
developer8dd72532023-05-17 19:58:35 +080010134 unsigned char mac[ETH_ALEN] = {0x00, 0x0c, 0x43, 0x11, 0x22, 0x33};
10135 struct unl unl_ins;
developer7e4a2a62023-04-06 19:56:03 +080010136 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
10137 return RETURN_ERR;
developer7e4a2a62023-04-06 19:56:03 +080010138 if (!DeviceMacAddress)
10139 return RETURN_ERR;
developer8dd72532023-05-17 19:58:35 +080010140 if (hwaddr_aton2(DeviceMacAddress, mac) < 0) {
developer2edaf012023-05-24 14:24:53 +080010141 wifi_debug(DEBUG_ERROR, "error device mac address=%s\n", DeviceMacAddress);
developer8dd72532023-05-17 19:58:35 +080010142 return RETURN_ERR;
10143 }
developer8dd72532023-05-17 19:58:35 +080010144 if_idx = if_nametoindex(inf_name);
developer2edaf012023-05-24 14:24:53 +080010145 if (!if_idx) {
10146 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", inf_name);
10147 return RETURN_ERR;
10148 }
developer49b17232023-05-19 16:35:19 +080010149 /*init mtk nl80211 vendor cmd*/
10150 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_ACL;
10151 param.if_type = NL80211_ATTR_IFINDEX;
10152 param.if_idx = if_idx;
10153 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10154 if (ret) {
10155 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
developer8dd72532023-05-17 19:58:35 +080010156 return RETURN_ERR;
10157 }
developer49b17232023-05-19 16:35:19 +080010158 /*add mtk vendor cmd data*/
10159 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_ACL_ADD_MAC, ETH_ALEN, mac)) {
developer2edaf012023-05-24 14:24:53 +080010160 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
developer8dd72532023-05-17 19:58:35 +080010161 nlmsg_free(msg);
10162 goto err;
10163 }
developer49b17232023-05-19 16:35:19 +080010164 /*send mtk nl80211 vendor msg*/
10165 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10166 if (ret) {
10167 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
developer8dd72532023-05-17 19:58:35 +080010168 goto err;
10169 }
developer49b17232023-05-19 16:35:19 +080010170 /*deinit mtk nl80211 vendor msg*/
10171 mtk_nl80211_deint(&unl_ins);
10172 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
developer8dd72532023-05-17 19:58:35 +080010173 return RETURN_OK;
10174err:
developer49b17232023-05-19 16:35:19 +080010175 mtk_nl80211_deint(&unl_ins);
10176 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
developer8dd72532023-05-17 19:58:35 +080010177 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010178}
10179
10180// deletes the mac address from the filter list
10181//DeviceMacAddress is in XX:XX:XX:XX:XX:XX format
10182INT wifi_delApAclDevice(INT apIndex, CHAR *DeviceMacAddress)
10183{
developer2edaf012023-05-24 14:24:53 +080010184 struct unl unl_ins;
10185 int if_idx = 0, ret = 0;
10186 struct nl_msg *msg = NULL;
10187 struct nlattr * msg_data = NULL;
10188 struct mtk_nl80211_param param;
developer7e4a2a62023-04-06 19:56:03 +080010189 char inf_name[IF_NAME_SIZE] = {0};
developer2edaf012023-05-24 14:24:53 +080010190 unsigned char mac[ETH_ALEN] = {0};
developer72fb0bb2023-01-11 09:46:29 +080010191
developer7e4a2a62023-04-06 19:56:03 +080010192 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
10193 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010194
developer7e4a2a62023-04-06 19:56:03 +080010195 if (!DeviceMacAddress)
10196 return RETURN_ERR;
10197
developer2edaf012023-05-24 14:24:53 +080010198 if (hwaddr_aton2(DeviceMacAddress, mac) < 0) {
10199 wifi_debug(DEBUG_ERROR, "error device mac address=%s\n", DeviceMacAddress);
10200 return RETURN_ERR;
10201 }
developer72fb0bb2023-01-11 09:46:29 +080010202
developer2edaf012023-05-24 14:24:53 +080010203 if_idx = if_nametoindex(inf_name);
10204 if (!if_idx) {
10205 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", inf_name);
10206 return RETURN_ERR;
10207 }
10208 /*init mtk nl80211 vendor cmd*/
10209 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_ACL;
10210 param.if_type = NL80211_ATTR_IFINDEX;
10211 param.if_idx = if_idx;
10212 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10213 if (ret) {
10214 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10215 return RETURN_ERR;
10216 }
10217 /*add mtk vendor cmd data*/
10218 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_ACL_DEL_MAC, ETH_ALEN, mac)) {
10219 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
10220 nlmsg_free(msg);
10221 goto err;
10222 }
10223 /*send mtk nl80211 vendor msg*/
10224 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10225 if (ret) {
10226 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
10227 goto err;
10228 }
10229 /*deinit mtk nl80211 vendor msg*/
10230 mtk_nl80211_deint(&unl_ins);
10231 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
10232 return RETURN_OK;
10233err:
10234 mtk_nl80211_deint(&unl_ins);
10235 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
10236 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010237}
10238
10239// outputs the number of devices in the filter list
10240INT wifi_getApAclDeviceNum(INT apIndex, UINT *output_uint)
10241{
developer2edaf012023-05-24 14:24:53 +080010242 char *mac_arry = NULL, *ptr = NULL, mac_str[18] = {0};
10243 UINT buf_size = 1024;
10244 UINT sta_num = 0;
10245 unsigned char mac[ETH_ALEN] = {0};
developera3511852023-06-14 14:12:59 +080010246 if(output_uint == NULL)
developerdaf24792023-06-06 11:40:04 +080010247 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010248
developer2edaf012023-05-24 14:24:53 +080010249 mac_arry = (char *)malloc(buf_size);
10250 if (mac_arry == NULL) {
10251 wifi_debug(DEBUG_ERROR, "malloc mac_arry fails\n");
developer7e4a2a62023-04-06 19:56:03 +080010252 return RETURN_ERR;
developer2edaf012023-05-24 14:24:53 +080010253 }
developerdaf24792023-06-06 11:40:04 +080010254 memset(mac_arry, 0, buf_size);
developer2edaf012023-05-24 14:24:53 +080010255 /*mac_arry str format: 00:11:22:33:44:55\n00:11:22:33:44:66\0*/
10256 if (wifi_getApAclDevices(apIndex, mac_arry, buf_size)!= RETURN_OK) {
10257 wifi_debug(DEBUG_ERROR, "get acl list entries fails\n");
developer9ce44382023-06-28 11:09:37 +080010258 free(mac_arry);
developer2edaf012023-05-24 14:24:53 +080010259 return RETURN_ERR;
10260 }
10261 /*count the acl str nums:*/
10262 wifi_debug(DEBUG_NOTICE, "mac_arry: %s\n", mac_arry);
developer7e4a2a62023-04-06 19:56:03 +080010263
developer2edaf012023-05-24 14:24:53 +080010264 /*mac addr string format:
10265 exp1: 00:11:22:33:44:55\0
10266 exp2: 00:11:22:33:44:55\n00:11:22:33:44:66\0
10267 */
10268 ptr = mac_arry;
10269 while (sscanf(ptr, "%17s", mac_str) == 1) {
10270 if (hwaddr_aton2(mac_str, mac) >= 0)
10271 sta_num++;
10272 ptr = strstr(ptr, mac_str) + strlen(mac_str);
10273 }
10274 *output_uint = sta_num;
10275 wifi_debug(DEBUG_NOTICE, "output_uint: %d\n", *output_uint);
10276 free(mac_arry);
10277 mac_arry = NULL;
developer7e4a2a62023-04-06 19:56:03 +080010278 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010279}
10280
10281INT apply_rules(INT apIndex, CHAR *client_mac,CHAR *action,CHAR *interface)
10282{
developer75bd10c2023-06-27 11:34:08 +080010283 int res;
developer72fb0bb2023-01-11 09:46:29 +080010284
developera3511852023-06-14 14:12:59 +080010285 if(strcmp(action,"DENY")==0)
10286 {
developer33f13ba2023-07-12 16:19:06 +080010287 res = v_secure_system("iptables -A WifiServices%d -m physdev --physdev-in %s -m mac --mac-source %s -j DROP",
developer32f2a182023-06-27 19:50:41 +080010288 apIndex, interface, client_mac);
developer33f13ba2023-07-12 16:19:06 +080010289 if (res) {
10290 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developer75bd10c2023-06-27 11:34:08 +080010291 return RETURN_ERR;
10292 }
developera3511852023-06-14 14:12:59 +080010293 return RETURN_OK;
10294 }
developer72fb0bb2023-01-11 09:46:29 +080010295
developera3511852023-06-14 14:12:59 +080010296 if(strcmp(action,"ALLOW")==0)
10297 {
developer33f13ba2023-07-12 16:19:06 +080010298 res = v_secure_system("iptables -I WifiServices%d -m physdev --physdev-in %s -m mac --mac-source %s -j RETURN",
developer32f2a182023-06-27 19:50:41 +080010299 apIndex, interface, client_mac);
developer33f13ba2023-07-12 16:19:06 +080010300 if (res) {
10301 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developer75bd10c2023-06-27 11:34:08 +080010302 return RETURN_ERR;
10303 }
developera3511852023-06-14 14:12:59 +080010304 return RETURN_OK;
10305 }
developer72fb0bb2023-01-11 09:46:29 +080010306
developera3511852023-06-14 14:12:59 +080010307 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010308
10309}
10310
10311// enable kick for devices on acl black list
10312INT wifi_kickApAclAssociatedDevices(INT apIndex, BOOL enable)
10313{
developera3511852023-06-14 14:12:59 +080010314 char aclArray[MAX_BUF_SIZE] = {0}, *acl = NULL;
10315 char assocArray[MAX_BUF_SIZE] = {0};
developer72fb0bb2023-01-11 09:46:29 +080010316
developera3511852023-06-14 14:12:59 +080010317 wifi_getApDenyAclDevices(apIndex, aclArray, sizeof(aclArray));
10318 wifi_getApDevicesAssociated(apIndex, assocArray, sizeof(assocArray));
developer72fb0bb2023-01-11 09:46:29 +080010319
developera3511852023-06-14 14:12:59 +080010320 /* if there are no devices connected there is nothing to do */
10321 if (strlen(assocArray) < 17)
10322 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010323
developera3511852023-06-14 14:12:59 +080010324 if (enable == TRUE) {
10325 /* kick off the MAC which is in ACL array (deny list) */
10326 acl = strtok(aclArray, "\n");
10327 while (acl != NULL) {
10328 if (strlen(acl) >= 17 && strcasestr(assocArray, acl))
10329 wifi_kickApAssociatedDevice(apIndex, acl);
developer72fb0bb2023-01-11 09:46:29 +080010330
developera3511852023-06-14 14:12:59 +080010331 acl = strtok(NULL, "\n");
10332 }
developer72fb0bb2023-01-11 09:46:29 +080010333 wifi_setApMacAddressControlMode(apIndex, 2);
developera3511852023-06-14 14:12:59 +080010334 } else
developer72fb0bb2023-01-11 09:46:29 +080010335 wifi_setApMacAddressControlMode(apIndex, 0);
developer72fb0bb2023-01-11 09:46:29 +080010336
developera3511852023-06-14 14:12:59 +080010337 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010338}
10339
10340INT wifi_setPreferPrivateConnection(BOOL enable)
10341{
developera3511852023-06-14 14:12:59 +080010342 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010343}
10344
10345// sets the mac address filter control mode. 0 == filter disabled, 1 == filter as whitelist, 2 == filter as blacklist
10346INT wifi_setApMacAddressControlMode(INT apIndex, INT filterMode)
10347{
developer2edaf012023-05-24 14:24:53 +080010348 int if_idx = 0, ret = 0;
10349 struct unl unl_ins;
10350 struct nl_msg *msg = NULL;
10351 struct nlattr * msg_data = NULL;
10352 struct mtk_nl80211_param param;
10353 int acl_policy = -1;
developer7e4a2a62023-04-06 19:56:03 +080010354 char inf_name[IF_NAME_SIZE] = {0};
developer72fb0bb2023-01-11 09:46:29 +080010355
developer7e4a2a62023-04-06 19:56:03 +080010356 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
10357 return RETURN_ERR;
developer2edaf012023-05-24 14:24:53 +080010358 if_idx = if_nametoindex(inf_name);
10359 if (!if_idx) {
10360 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", inf_name);
10361 return RETURN_ERR;
10362 }
10363 /*init mtk nl80211 vendor cmd*/
10364 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_ACL;
10365 param.if_type = NL80211_ATTR_IFINDEX;
10366 param.if_idx = if_idx;
10367 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10368 if (ret) {
10369 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10370 return RETURN_ERR;
10371 }
10372 /*add mtk vendor cmd data*/
10373 if (filterMode == 0) {
10374 acl_policy = MTK_NL80211_VENDOR_ATTR_ACL_DISABLE;
10375 } else if (filterMode == 1) {
10376 acl_policy = MTK_NL80211_VENDOR_ATTR_ACL_ENABLE_WHITE_LIST;
10377 } else if (filterMode == 2) {
10378 acl_policy = MTK_NL80211_VENDOR_ATTR_ACL_ENABLE_BLACK_LIST;
10379 } else {
10380 wifi_debug(DEBUG_ERROR, "filtermode(%d) not support error\n", filterMode);
10381 nlmsg_free(msg);
10382 goto err;
10383 }
10384 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_ACL_POLICY, acl_policy)) {
10385 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
10386 nlmsg_free(msg);
10387 goto err;
10388 }
10389 /*send mtk nl80211 vendor msg*/
10390 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10391 if (ret) {
10392 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
10393 goto err;
10394 }
10395 /*deinit mtk nl80211 vendor msg*/
10396 mtk_nl80211_deint(&unl_ins);
10397 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
developer7e4a2a62023-04-06 19:56:03 +080010398 return RETURN_OK;
developer2edaf012023-05-24 14:24:53 +080010399err:
10400 mtk_nl80211_deint(&unl_ins);
10401 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
10402 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010403}
10404
10405// enables internal gateway VLAN mode. In this mode a Vlan tag is added to upstream (received) data packets before exiting the Wifi driver. VLAN tags in downstream data are stripped from data packets before transmission. Default is FALSE.
10406INT wifi_setApVlanEnable(INT apIndex, BOOL VlanEnabled)
10407{
developera3511852023-06-14 14:12:59 +080010408 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010409}
10410
10411// gets the vlan ID for this ap from an internal enviornment variable
10412INT wifi_getApVlanID(INT apIndex, INT *output_int)
10413{
developera3511852023-06-14 14:12:59 +080010414 if(apIndex==0)
10415 {
10416 *output_int=100;
10417 return RETURN_OK;
10418 }
developer72fb0bb2023-01-11 09:46:29 +080010419
developera3511852023-06-14 14:12:59 +080010420 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010421}
10422
10423// sets the vlan ID for this ap to an internal enviornment variable
10424INT wifi_setApVlanID(INT apIndex, INT vlanId)
10425{
developera3511852023-06-14 14:12:59 +080010426 //save the vlanID to config and wait for wifi reset to apply (wifi up module would read this parameters and tag the AP with vlan id)
developer82533be2023-06-28 17:21:01 +080010427 char interface_name[16] = {0};
10428 int if_idx, ret = 0;
10429 struct nl_msg *msg = NULL;
10430 struct nlattr * msg_data = NULL;
10431 struct mtk_nl80211_param param;
10432 struct unl unl_ins;
10433
10434 if (apIndex > MAX_APS) {
10435 wifi_debug(DEBUG_ERROR, "Invalid apIndex %d\n", apIndex);
10436 return RETURN_ERR;
10437 }
10438 if (vlanId > 4095 || vlanId < 1) {
10439 wifi_debug(DEBUG_ERROR, "Invalid vlanId %d\n", vlanId);
10440 return RETURN_ERR;
10441 }
10442 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
10443 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
10444 return RETURN_ERR;
10445 /*step 1. mwctl dev %s set vlan_tag 0*/
10446 if_idx = if_nametoindex(interface_name);
10447 /*init mtk nl80211 vendor cmd*/
10448 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_VLAN;
10449 param.if_type = NL80211_ATTR_IFINDEX;
10450 param.if_idx = if_idx;
10451 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10452 if (ret) {
10453 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10454 return RETURN_ERR;
10455 }
10456 if (nla_put_u16(msg, MTK_NL80211_VENDOR_ATTR_VLAN_ID_INFO, vlanId)) {
10457 printf("Nla put attribute error\n");
10458 nlmsg_free(msg);
10459 goto err;
10460 }
10461 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10462 if (ret) {
10463 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10464 goto err;
10465 }
10466 mtk_nl80211_deint(&unl_ins);
10467 //wifi_debug(DEBUG_NOTICE, "set vlanId cmd success.\n", vlanId);
10468 printf("set vlanId=%d cmd success.\n", vlanId);
10469 return RETURN_OK;
10470err:
10471 mtk_nl80211_deint(&unl_ins);
10472 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
developera3511852023-06-14 14:12:59 +080010473 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010474}
10475
developercc5cbfb2023-06-13 18:29:52 +080010476char br_name[IFNAMSIZ] = "brlan0";
10477
developer72fb0bb2023-01-11 09:46:29 +080010478// gets bridgeName, IP address and Subnet. bridgeName is a maximum of 32 characters,
10479INT wifi_getApBridgeInfo(INT index, CHAR *bridgeName, CHAR *IP, CHAR *subnet)
10480{
developercc5cbfb2023-06-13 18:29:52 +080010481 int sock = socket(AF_INET, SOCK_DGRAM, 0);
10482 struct ifreq ifr;
10483 struct sockaddr_in *sin;
10484
10485 memcpy(bridgeName, br_name, strlen(br_name));
10486
10487 if (sock == -1) {
10488 wifi_debug(DEBUG_ERROR, "socket failed");
10489 return RETURN_ERR;
10490 }
10491
developerd14dff12023-06-28 22:47:44 +080010492 strncpy(ifr.ifr_name, br_name, strlen(br_name));
developercc5cbfb2023-06-13 18:29:52 +080010493 ifr.ifr_addr.sa_family = AF_INET;
10494 if (ioctl(sock, SIOCGIFADDR, &ifr) < 0) {
10495 wifi_debug(DEBUG_ERROR, "ioctl(SIOCGIFADDR) failed, %s, bridge_name=%s\n",
10496 strerror(errno), br_name);
developer9ce44382023-06-28 11:09:37 +080010497 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010498 return RETURN_ERR;
10499 }
10500
10501 sin = (struct sockaddr_in *)&ifr.ifr_addr;
10502 wifi_debug(DEBUG_ERROR, "Bridge device %s has IP address: %s\n", br_name, inet_ntoa(sin->sin_addr));
10503 memcpy(IP, inet_ntoa(sin->sin_addr), strlen(inet_ntoa(sin->sin_addr)));
10504
10505 if (ioctl(sock, SIOCGIFNETMASK, &ifr) < 0) {
10506 wifi_debug(DEBUG_ERROR, "ioctl(SIOCGIFNETMASK) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010507 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010508 return RETURN_ERR;
10509 }
10510
10511 wifi_debug(DEBUG_ERROR, "Bridge device %s has subnet mask: %s\n", br_name, inet_ntoa(sin->sin_addr));
10512 memcpy(subnet, inet_ntoa(sin->sin_addr), strlen(inet_ntoa(sin->sin_addr)));
10513 close(sock);
developer72fb0bb2023-01-11 09:46:29 +080010514
developera3511852023-06-14 14:12:59 +080010515 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010516}
10517
10518//sets bridgeName, IP address and Subnet to internal enviornment variables. bridgeName is a maximum of 32 characters
10519INT wifi_setApBridgeInfo(INT apIndex, CHAR *bridgeName, CHAR *IP, CHAR *subnet)
10520{
developera3511852023-06-14 14:12:59 +080010521 //save settings, wait for wifi reset or wifi_pushBridgeInfo to apply.
developercc5cbfb2023-06-13 18:29:52 +080010522 struct ifreq ifr;
10523 struct sockaddr_in sin;
10524 int sock = socket(AF_INET, SOCK_DGRAM, 0);
10525
developerc14d83a2023-06-29 20:09:42 +080010526 if(sock < 0) {
10527 wifi_debug(DEBUG_ERROR, "sock init fail\n");
10528 return RETURN_ERR;
10529 }
developer5b23cd02023-07-19 20:26:03 +080010530
developercc5cbfb2023-06-13 18:29:52 +080010531 if (strlen(bridgeName) >= IFNAMSIZ) {
10532 wifi_debug(DEBUG_ERROR, "invalide bridgeName length=%ld\n", strlen(bridgeName));
developer9ce44382023-06-28 11:09:37 +080010533 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010534 return RETURN_ERR;
10535 }
10536
10537 if (strlen(br_name) >= IFNAMSIZ) {
10538 wifi_debug(DEBUG_ERROR, "invalide br_name length=%ld in strorage\n", strlen(br_name));
developer9ce44382023-06-28 11:09:37 +080010539 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010540 return RETURN_ERR;
10541 }
10542
10543 if (sock == -1) {
developera3511852023-06-14 14:12:59 +080010544 wifi_debug(DEBUG_ERROR, "socket failed");
developercc5cbfb2023-06-13 18:29:52 +080010545 return RETURN_ERR;
10546 }
10547
10548 memset(&ifr, 0, sizeof(ifr));
10549 strncpy(ifr.ifr_name, br_name, strlen(br_name));
10550 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
10551 wifi_debug(DEBUG_ERROR, "ioctl(SIOCGIFFLAGS) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010552 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010553 return RETURN_ERR;
10554 }
10555
10556 ifr.ifr_flags = (short)(ifr.ifr_flags & ~IFF_UP);
10557 if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
10558 wifi_debug(DEBUG_ERROR, "ioctl(SIOCSIFFLAGS) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010559 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010560 return RETURN_ERR;
10561 }
10562
10563 memset(&ifr, 0, sizeof(ifr));
10564 strncpy(ifr.ifr_name, br_name, IFNAMSIZ);
developerd14dff12023-06-28 22:47:44 +080010565 strncpy(ifr.ifr_newname, bridgeName, strlen(bridgeName));
developercc5cbfb2023-06-13 18:29:52 +080010566 if (ioctl(sock, SIOCSIFNAME, &ifr) < 0) {
10567 wifi_debug(DEBUG_ERROR, "ioctl(SIOCSIFNAME) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010568 close(sock);
developera3511852023-06-14 14:12:59 +080010569 return RETURN_ERR;
developercc5cbfb2023-06-13 18:29:52 +080010570 }
10571
10572 memset(br_name, 0, sizeof(br_name));
10573 memcpy(br_name, bridgeName, strlen(bridgeName));
10574
10575 memset(&ifr, 0, sizeof(ifr));
10576 strncpy(ifr.ifr_name, bridgeName, IFNAMSIZ);
10577 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
10578 wifi_debug(DEBUG_ERROR, "ioctl(SIOCGIFFLAGS) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010579 close(sock);
developera3511852023-06-14 14:12:59 +080010580 return RETURN_ERR;
developercc5cbfb2023-06-13 18:29:52 +080010581 }
10582 ifr.ifr_flags = (short)(ifr.ifr_flags | IFF_UP);
10583 if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
10584 wifi_debug(DEBUG_ERROR, "ioctl(SIOCSIFFLAGS) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010585 close(sock);
developera3511852023-06-14 14:12:59 +080010586 return RETURN_ERR;
developercc5cbfb2023-06-13 18:29:52 +080010587 }
10588
10589 memset(&ifr, 0, sizeof(ifr));
10590 memcpy(ifr.ifr_name, bridgeName, strlen(bridgeName));
10591
10592 memset(&sin, 0, sizeof(struct sockaddr_in));
10593 sin.sin_family = AF_INET;
10594 if (inet_aton(IP, &(sin.sin_addr)) == 0) {
10595 wifi_debug(DEBUG_ERROR, "inet_aton failed");
developer9ce44382023-06-28 11:09:37 +080010596 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010597 return RETURN_ERR;
10598 }
10599 memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr_in));
10600 if (ioctl(sock, SIOCSIFADDR, &ifr) < 0) {
10601 wifi_debug(DEBUG_ERROR, "ioctl(SIOCSIFADDR) failed, %s", strerror(errno));
developer9ce44382023-06-28 11:09:37 +080010602 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010603 return RETURN_ERR;
10604 }
10605
10606 if (inet_aton(subnet, &((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr) == 0) {
10607 wifi_debug(DEBUG_ERROR, "inet_aton failed");
developerc14d83a2023-06-29 20:09:42 +080010608 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010609 return RETURN_ERR;
10610 }
10611 if (ioctl(sock, SIOCSIFNETMASK, &ifr) < -1) {
10612 wifi_debug(DEBUG_ERROR, "ioctl(SIOCSIFNETMASK) failed, %s", strerror(errno));
developerc14d83a2023-06-29 20:09:42 +080010613 close(sock);
developercc5cbfb2023-06-13 18:29:52 +080010614 return RETURN_ERR;
10615 }
10616
10617 close(sock);
developera3511852023-06-14 14:12:59 +080010618 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010619}
10620
10621// reset the vlan configuration for this ap
10622INT wifi_resetApVlanCfg(INT apIndex)
10623{
developera1255e42023-05-13 17:45:02 +080010624 char interface_name[16] = {0};
developer2202b332023-05-24 16:23:22 +080010625 int if_idx, ret = 0;
10626 struct nl_msg *msg = NULL;
10627 struct nlattr * msg_data = NULL;
10628 struct mtk_nl80211_param param;
10629 struct unl unl_ins;
10630 struct vlan_policy_param vlan_param;
developer72fb0bb2023-01-11 09:46:29 +080010631
developer2202b332023-05-24 16:23:22 +080010632 if (apIndex > MAX_APS) {
10633 wifi_debug(DEBUG_ERROR, "Invalid apIndex %d\n", apIndex);
10634 return RETURN_ERR;
10635 }
developer72fb0bb2023-01-11 09:46:29 +080010636
developer2202b332023-05-24 16:23:22 +080010637 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
10638 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
10639 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010640
developer2202b332023-05-24 16:23:22 +080010641 /*step 1. mwctl dev %s set vlan_tag 0*/
10642 if_idx = if_nametoindex(interface_name);
10643 /*init mtk nl80211 vendor cmd*/
10644 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_VLAN;
10645 param.if_type = NL80211_ATTR_IFINDEX;
10646 param.if_idx = if_idx;
10647 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
developer72fb0bb2023-01-11 09:46:29 +080010648
developer2202b332023-05-24 16:23:22 +080010649 if (ret) {
10650 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10651 return RETURN_ERR;
10652 }
developer72fb0bb2023-01-11 09:46:29 +080010653
developer2202b332023-05-24 16:23:22 +080010654 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_VLAN_TAG_INFO, 0)) {
10655 printf("Nla put attribute error\n");
10656 nlmsg_free(msg);
10657 goto err;
10658 }
developer72fb0bb2023-01-11 09:46:29 +080010659
developer2202b332023-05-24 16:23:22 +080010660 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10661 if (ret) {
10662 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10663 goto err;
10664 }
10665 mtk_nl80211_deint(&unl_ins);
10666 wifi_debug(DEBUG_NOTICE, "set vlan_tag 0 cmd success.\n");
developer72fb0bb2023-01-11 09:46:29 +080010667
developer2202b332023-05-24 16:23:22 +080010668 /*step 2. mwctl dev %s set vlan_priority 0*/
10669 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10670 if (ret) {
10671 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10672 return RETURN_ERR;
10673 }
developer72fb0bb2023-01-11 09:46:29 +080010674
developer2202b332023-05-24 16:23:22 +080010675 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_VLAN_PRIORITY_INFO, 0)) {
10676 printf("Nla put attribute error\n");
10677 nlmsg_free(msg);
10678 goto err;
10679 }
developer72fb0bb2023-01-11 09:46:29 +080010680
developer2202b332023-05-24 16:23:22 +080010681 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10682 if (ret) {
10683 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10684 goto err;
10685 }
10686 mtk_nl80211_deint(&unl_ins);
10687 wifi_debug(DEBUG_NOTICE, "set vlan_priority 0 cmd success.\n");
10688
10689 /*step 3. mwctl dev %s set vlan_id 0*/
10690 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10691 if (ret) {
10692 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
developera1255e42023-05-13 17:45:02 +080010693 return RETURN_ERR;
developer2202b332023-05-24 16:23:22 +080010694 }
developer72fb0bb2023-01-11 09:46:29 +080010695
developer2202b332023-05-24 16:23:22 +080010696 if (nla_put_u16(msg, MTK_NL80211_VENDOR_ATTR_VLAN_ID_INFO, 0)) {
10697 printf("Nla put attribute error\n");
10698 nlmsg_free(msg);
10699 goto err;
10700 }
10701
10702 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10703 if (ret) {
10704 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10705 goto err;
10706 }
10707 mtk_nl80211_deint(&unl_ins);
10708 wifi_debug(DEBUG_NOTICE, "set vlan_id cmd success.\n");
10709
10710 /*step 4. mwctl dev %s set vlan_en 0*/
10711 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10712 if (ret) {
10713 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10714 return RETURN_ERR;
10715 }
10716
10717 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_VLAN_EN_INFO, 0)) {
10718 printf("Nla put attribute error\n");
10719 nlmsg_free(msg);
10720 goto err;
10721 }
10722
10723 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10724 if (ret) {
10725 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10726 goto err;
10727 }
10728 mtk_nl80211_deint(&unl_ins);
10729 wifi_debug(DEBUG_NOTICE, "set vlan_id cmd success.\n");
10730
10731 /*step 5. mwctl dev %s set vlan_policy 0:4*/
10732 vlan_param.direction = 0;
10733 vlan_param.policy = 4;
10734 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10735 if (ret) {
10736 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10737 return RETURN_ERR;
10738 }
10739 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_VLAN_POLICY_INFO, sizeof(vlan_param), &vlan_param)) {
10740 printf("Nla put attribute error\n");
10741 nlmsg_free(msg);
10742 goto err;
10743 }
10744
10745 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10746 if (ret) {
10747 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10748 goto err;
10749 }
10750 mtk_nl80211_deint(&unl_ins);
10751 wifi_debug(DEBUG_NOTICE, "set vlan_policy 0:4 cmd success.\n");
10752
10753 /*step 6. mwctl dev %s set vlan_policy 1:0*/
10754 vlan_param.direction = 1;
10755 vlan_param.policy = 0;
10756 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
10757 if (ret) {
10758 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
10759 return RETURN_ERR;
10760 }
10761
10762 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_VLAN_POLICY_INFO, sizeof(vlan_param), &vlan_param)) {
10763 printf("Nla put attribute error\n");
10764 nlmsg_free(msg);
10765 goto err;
10766 }
10767
10768 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
10769 if (ret) {
10770 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
10771 goto err;
10772 }
10773 /*deinit mtk nl80211 vendor msg*/
10774 mtk_nl80211_deint(&unl_ins);
10775 wifi_debug(DEBUG_NOTICE, "set vlan_policy 1:0 cmd success.\n");
10776
10777 /*TODO need to modify VLAN config in dat file*/
10778 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
10779
10780 return RETURN_OK;
10781err:
10782 mtk_nl80211_deint(&unl_ins);
10783 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
10784 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010785}
10786
10787// creates configuration variables needed for WPA/WPS. These variables are implementation dependent and in some implementations these variables are used by hostapd when it is started. Specific variables that are needed are dependent on the hostapd implementation. These variables are set by WPA/WPS security functions in this wifi HAL. If not needed for a particular implementation this function may simply return no error.
10788INT wifi_createHostApdConfig(INT apIndex, BOOL createWpsCfg)
10789{
developera3511852023-06-14 14:12:59 +080010790 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010791}
10792
10793// starts hostapd, uses the variables in the hostapd config with format compatible with the specific hostapd implementation
10794INT wifi_startHostApd()
10795{
developera3511852023-06-14 14:12:59 +080010796 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer33f13ba2023-07-12 16:19:06 +080010797 v_secure_system("systemctl start hostapd.service");
developera3511852023-06-14 14:12:59 +080010798 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
10799 return RETURN_OK;
10800 //sprintf(cmd, "hostapd -B `cat /tmp/conf_filename` -e /nvram/etc/wpa2/entropy -P /tmp/hostapd.pid 1>&2");
developer72fb0bb2023-01-11 09:46:29 +080010801}
10802
10803// stops hostapd
developer69b61b02023-03-07 17:17:44 +080010804INT wifi_stopHostApd()
developer72fb0bb2023-01-11 09:46:29 +080010805{
developera3511852023-06-14 14:12:59 +080010806 char buf[128] = {0};
developer75bd10c2023-06-27 11:34:08 +080010807 int res;
developer72fb0bb2023-01-11 09:46:29 +080010808
developer8078acf2023-08-04 18:52:48 +080010809 res = _syscmd_secure(buf, sizeof(buf), "systemctl stop hostapd");
10810 if (res) {
10811 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080010812 }
developer72fb0bb2023-01-11 09:46:29 +080010813
developera3511852023-06-14 14:12:59 +080010814 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010815}
10816
10817// restart hostapd dummy function
10818INT wifi_restartHostApd()
10819{
developera3511852023-06-14 14:12:59 +080010820 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer33f13ba2023-07-12 16:19:06 +080010821 v_secure_system("systemctl restart hostapd-global");
developera3511852023-06-14 14:12:59 +080010822 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080010823
developera3511852023-06-14 14:12:59 +080010824 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010825}
10826
10827// sets the AP enable status variable for the specified ap.
10828INT wifi_setApEnable(INT apIndex, BOOL enable)
10829{
developer7e4a2a62023-04-06 19:56:03 +080010830 char interface_name[16] = {0};
developerb149d9d2023-06-06 16:14:22 +080010831 char config_file[MAX_SUB_CMD_SIZE] = {0};
developer8078acf2023-08-04 18:52:48 +080010832
developer7e4a2a62023-04-06 19:56:03 +080010833 char buf[MAX_BUF_SIZE] = {0};
developer47cc27a2023-05-17 23:09:58 +080010834 BOOL status = FALSE;
developer7e4a2a62023-04-06 19:56:03 +080010835 int max_radio_num = 0;
10836 int phyId = 0;
developere40952c2023-06-15 18:46:43 +080010837 int res;
developer72fb0bb2023-01-11 09:46:29 +080010838
developer7e4a2a62023-04-06 19:56:03 +080010839 wifi_getApEnable(apIndex, &status);
developer72fb0bb2023-01-11 09:46:29 +080010840
developer7e4a2a62023-04-06 19:56:03 +080010841 wifi_getMaxRadioNumber(&max_radio_num);
10842 if (enable == status)
10843 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010844
developer7e4a2a62023-04-06 19:56:03 +080010845 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
10846 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010847
developer7e4a2a62023-04-06 19:56:03 +080010848 if (enable == TRUE) {
10849 int radioIndex = apIndex % max_radio_num;
10850 phyId = radio_index_to_phy(radioIndex);
developer8078acf2023-08-04 18:52:48 +080010851
10852 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up", interface_name);
10853 if (res) {
10854 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080010855 }
developer8a3bbbf2023-03-15 17:47:23 +080010856
developere40952c2023-06-15 18:46:43 +080010857 res = snprintf(config_file, MAX_BUF_SIZE, "%s%d.conf", CONFIG_PREFIX, apIndex);
10858 if (os_snprintf_error(MAX_BUF_SIZE, res)) {
10859 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
10860 return RETURN_ERR;
10861 }
developer8078acf2023-08-04 18:52:48 +080010862 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw ADD bss_config=phy%d:%s", phyId, config_file);
10863 if (res) {
10864 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080010865 }
developer7e4a2a62023-04-06 19:56:03 +080010866 } else {
developer8078acf2023-08-04 18:52:48 +080010867 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw REMOVE %s", interface_name);
10868 if (res) {
10869 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080010870 }
developer8078acf2023-08-04 18:52:48 +080010871 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
10872 if (res) {
10873 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080010874 }
developer7e4a2a62023-04-06 19:56:03 +080010875 }
developer8078acf2023-08-04 18:52:48 +080010876 res = _syscmd_secure(buf, sizeof(buf), "sed -i -n -e '/^%s=/!p' -e '$a%s=%d' %s",
developer7e4a2a62023-04-06 19:56:03 +080010877 interface_name, interface_name, enable, VAP_STATUS_FILE);
developer8078acf2023-08-04 18:52:48 +080010878 if (res) {
10879 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080010880 }
developer7e4a2a62023-04-06 19:56:03 +080010881 //Wait for wifi up/down to apply
10882 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010883}
10884
10885// Outputs the setting of the internal variable that is set by wifi_setApEnable().
10886INT wifi_getApEnable(INT apIndex, BOOL *output_bool)
10887{
developer7e4a2a62023-04-06 19:56:03 +080010888 char interface_name[IF_NAME_SIZE] = {0};
developerc1aa6532023-06-09 09:37:01 +080010889 char buf[MAX_BUF_SIZE] = {0};
developerc338aba2023-08-09 13:56:42 +080010890 int res, len;
10891 char ctrl_interface[64] = {0};
10892 char config_file[128] = {0};
developer72fb0bb2023-01-11 09:46:29 +080010893
developer7e4a2a62023-04-06 19:56:03 +080010894 if ((!output_bool) || (apIndex < 0) || (apIndex >= MAX_APS))
10895 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010896
developer7e4a2a62023-04-06 19:56:03 +080010897 *output_bool = 0;
developer72fb0bb2023-01-11 09:46:29 +080010898
developer7e4a2a62023-04-06 19:56:03 +080010899 if ((apIndex >= 0) && (apIndex < MAX_APS)) {
10900 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK) {
10901 *output_bool = FALSE;
10902 return RETURN_OK;
10903 }
developerc338aba2023-08-09 13:56:42 +080010904 if (strlen(interface_name) == 0)
10905 return RETURN_ERR;
10906
10907 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
10908 if (os_snprintf_error(sizeof(config_file), res)) {
10909 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
10910 return RETURN_ERR;
10911 }
10912 if (wifi_hostapdRead(config_file, "ctrl_interface", ctrl_interface, sizeof(ctrl_interface))) {
10913 wifi_debug(DEBUG_ERROR, "ctrl_interface for %s not exist\n", interface_name);
10914 }
10915
10916 _syscmd_secure(buf, sizeof(buf), "ls %s | grep %s",
10917 strlen(ctrl_interface) == 0 ? "/var/run/hostapd/" : ctrl_interface, interface_name);
10918 len = strlen(buf) >= strlen(interface_name) ? strlen(interface_name) : strlen(buf);
10919
10920 if (len == 0 || strncmp(buf, interface_name, len)) {
10921 return RETURN_OK;
10922 }
10923 memset(buf, 0, sizeof(buf));
developerc1aa6532023-06-09 09:37:01 +080010924
developer8078acf2023-08-04 18:52:48 +080010925 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s status | grep state | cut -d '=' -f2", interface_name);
10926 if (res) {
10927 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080010928 }
developerc1aa6532023-06-09 09:37:01 +080010929
10930 if(strncmp(buf, "ENABLED", 7) == 0 || strncmp(buf, "ACS", 3) == 0 ||
10931 strncmp(buf, "HT_SCAN", 7) == 0 || strncmp(buf, "DFS", 3) == 0) {
10932 *output_bool = TRUE;
10933 }
developer7e4a2a62023-04-06 19:56:03 +080010934 }
developer72fb0bb2023-01-11 09:46:29 +080010935
developer7e4a2a62023-04-06 19:56:03 +080010936 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010937}
10938
developer69b61b02023-03-07 17:17:44 +080010939// Outputs the AP "Enabled" "Disabled" status from driver
10940INT wifi_getApStatus(INT apIndex, CHAR *output_string)
developer72fb0bb2023-01-11 09:46:29 +080010941{
developer9ce44382023-06-28 11:09:37 +080010942 BOOL output_bool = 0;
developere40952c2023-06-15 18:46:43 +080010943 int res;
developer72fb0bb2023-01-11 09:46:29 +080010944
developer7e4a2a62023-04-06 19:56:03 +080010945 if (!output_string) {
10946 printf("%s: null pointer!", __func__);
10947 return RETURN_ERR;
10948 }
developer72fb0bb2023-01-11 09:46:29 +080010949
developer7e4a2a62023-04-06 19:56:03 +080010950 wifi_getApEnable(apIndex, &output_bool);
developer72fb0bb2023-01-11 09:46:29 +080010951
developer7e4a2a62023-04-06 19:56:03 +080010952 if(output_bool == 1)
developere40952c2023-06-15 18:46:43 +080010953 res = snprintf(output_string, 32, "Up");
developer7e4a2a62023-04-06 19:56:03 +080010954 else
developere40952c2023-06-15 18:46:43 +080010955 res = snprintf(output_string, 32, "Disable");
10956 if (os_snprintf_error(32, res)) {
10957 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
10958 return RETURN_ERR;
10959 }
developer7e4a2a62023-04-06 19:56:03 +080010960
10961 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010962}
10963
10964//Indicates whether or not beacons include the SSID name.
10965// outputs a 1 if SSID on the AP is enabled, else outputs 0
10966INT wifi_getApSsidAdvertisementEnable(INT apIndex, BOOL *output)
10967{
developera3511852023-06-14 14:12:59 +080010968 //get the running status
10969 char config_file[MAX_BUF_SIZE] = {0};
10970 char buf[16] = {0};
developer75bd10c2023-06-27 11:34:08 +080010971 int res;
developer72fb0bb2023-01-11 09:46:29 +080010972
developera3511852023-06-14 14:12:59 +080010973 if (!output)
10974 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080010975
developer32f2a182023-06-27 19:50:41 +080010976 res = snprintf(config_file, sizeof(config_file),
10977 "%s%d.conf", CONFIG_PREFIX, apIndex);
developer75bd10c2023-06-27 11:34:08 +080010978 if (os_snprintf_error(sizeof(config_file), res)) {
10979 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
10980 return RETURN_ERR;
10981 }
developera3511852023-06-14 14:12:59 +080010982 wifi_hostapdRead(config_file, "ignore_broadcast_ssid", buf, sizeof(buf));
10983 // default is enable
10984 if (strlen(buf) == 0 || strncmp("0", buf, 1) == 0)
10985 *output = TRUE;
developer72fb0bb2023-01-11 09:46:29 +080010986
developera3511852023-06-14 14:12:59 +080010987 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080010988}
10989
10990// sets an internal variable for ssid advertisement. Set to 1 to enable, set to 0 to disable
10991INT wifi_setApSsidAdvertisementEnable(INT apIndex, BOOL enable)
10992{
developera3511852023-06-14 14:12:59 +080010993 //store the config, apply instantly
10994 char config_file[MAX_BUF_SIZE] = {0};
10995 struct params list;
developer75bd10c2023-06-27 11:34:08 +080010996 int res;
developer72fb0bb2023-01-11 09:46:29 +080010997
developera3511852023-06-14 14:12:59 +080010998 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
10999 list.name = "ignore_broadcast_ssid";
11000 list.value = enable?"0":"1";
developer72fb0bb2023-01-11 09:46:29 +080011001
developer32f2a182023-06-27 19:50:41 +080011002 res = snprintf(config_file, sizeof(config_file),
11003 "%s%d.conf", CONFIG_PREFIX, apIndex);
developer75bd10c2023-06-27 11:34:08 +080011004 if (os_snprintf_error(sizeof(config_file), res)) {
11005 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11006 return RETURN_ERR;
11007 }
developera3511852023-06-14 14:12:59 +080011008 wifi_hostapdWrite(config_file, &list, 1);
11009 wifi_hostapdProcessUpdate(apIndex, &list, 1);
11010 //TODO: call hostapd_cli for dynamic_config_control
11011 wifi_reloadAp(apIndex);
11012 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011013
developera3511852023-06-14 14:12:59 +080011014 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011015}
11016
11017//The maximum number of retransmission for a packet. This corresponds to IEEE 802.11 parameter dot11ShortRetryLimit.
11018INT wifi_getApRetryLimit(INT apIndex, UINT *output_uint)
11019{
developer47cc27a2023-05-17 23:09:58 +080011020 /* get the running status */
11021 if(!output_uint)
developera3511852023-06-14 14:12:59 +080011022 return RETURN_ERR;
developer47cc27a2023-05-17 23:09:58 +080011023
11024 *output_uint = 15;
11025 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011026}
11027
developer47cc27a2023-05-17 23:09:58 +080011028/*Do not support AP retry limit fix*/
developer72fb0bb2023-01-11 09:46:29 +080011029INT wifi_setApRetryLimit(INT apIndex, UINT number)
11030{
developer47cc27a2023-05-17 23:09:58 +080011031 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011032}
11033
developer95c045d2023-05-24 19:26:28 +080011034int get_wmm_cap_status_callback(struct nl_msg *msg, void *data)
11035{
11036 struct nlattr *tb[NL80211_ATTR_MAX + 1];
11037 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_WMM_ATTR_MAX + 1];
11038 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
developer2f79c922023-06-02 17:33:42 +080011039 unsigned char *status = (unsigned char *)data;
developer95c045d2023-05-24 19:26:28 +080011040 int err = 0;
developer95c045d2023-05-24 19:26:28 +080011041
11042 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
11043 genlmsg_attrlen(gnlh, 0), NULL);
11044 if (err < 0)
11045 return err;
11046
11047 if (tb[NL80211_ATTR_VENDOR_DATA]) {
11048 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_WMM_ATTR_MAX,
11049 tb[NL80211_ATTR_VENDOR_DATA], NULL);
11050 if (err < 0)
11051 return err;
11052
11053 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_WMM_AP_CAP_INFO]) {
developer95c045d2023-05-24 19:26:28 +080011054 *status = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_WMM_AP_CAP_INFO]);
11055 }
11056 }
11057
11058 return 0;
11059}
11060
developer72fb0bb2023-01-11 09:46:29 +080011061//Indicates whether this access point supports WiFi Multimedia (WMM) Access Categories (AC).
11062INT wifi_getApWMMCapability(INT apIndex, BOOL *output)
11063{
developer95c045d2023-05-24 19:26:28 +080011064 int if_idx, ret = 0;
developera3511852023-06-14 14:12:59 +080011065 char interface_name[16] = {0};
developer95c045d2023-05-24 19:26:28 +080011066 unsigned char status = 0;
11067 struct nl_msg *msg = NULL;
11068 struct nlattr * msg_data = NULL;
11069 struct mtk_nl80211_param param;
11070 struct unl unl_ins;
developer8e6583c2023-05-23 13:36:06 +080011071
developera3511852023-06-14 14:12:59 +080011072 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
11073 if(!output)
developerdaf24792023-06-06 11:40:04 +080011074 return RETURN_ERR;
developer8e6583c2023-05-23 13:36:06 +080011075
developer95c045d2023-05-24 19:26:28 +080011076 if (apIndex > MAX_APS) {
11077 wifi_debug(DEBUG_ERROR, "Invalid apIndex %d\n", apIndex);
11078 return RETURN_ERR;
11079 }
11080
developera3511852023-06-14 14:12:59 +080011081 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
developerdaf24792023-06-06 11:40:04 +080011082 return RETURN_ERR;
developer95c045d2023-05-24 19:26:28 +080011083
11084 if_idx = if_nametoindex(interface_name);
11085 /*init mtk nl80211 vendor cmd*/
11086 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_WMM;
11087 param.if_type = NL80211_ATTR_IFINDEX;
11088 param.if_idx = if_idx;
11089 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
11090
11091 if (ret) {
11092 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
11093 return RETURN_ERR;
11094 }
11095
11096 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_WMM_AP_CAP_INFO, 0xf)) {
11097 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
11098 nlmsg_free(msg);
11099 goto err;
11100 }
11101
11102 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, get_wmm_cap_status_callback,
11103 (void *)&status);
11104 if (ret) {
11105 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
11106 goto err;
11107 }
11108 mtk_nl80211_deint(&unl_ins);
11109
11110 *output = status == 0 ? FALSE : TRUE;
11111 wifi_debug(DEBUG_NOTICE, "wmm cap (%u).\n", (unsigned int)(*output));
developer8e6583c2023-05-23 13:36:06 +080011112
developera3511852023-06-14 14:12:59 +080011113 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
11114 return RETURN_OK;
11115err:
developer95c045d2023-05-24 19:26:28 +080011116 mtk_nl80211_deint(&unl_ins);
11117 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
11118 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011119}
11120
11121//Indicates whether this access point supports WMM Unscheduled Automatic Power Save Delivery (U-APSD). Note: U-APSD support implies WMM support.
11122INT wifi_getApUAPSDCapability(INT apIndex, BOOL *output)
11123{
developera3511852023-06-14 14:12:59 +080011124 //get the running status from driver
developera3511852023-06-14 14:12:59 +080011125 char buf[128] = {0};
11126 int max_radio_num = 0, radioIndex = 0;
11127 int phyId = 0;
developere40952c2023-06-15 18:46:43 +080011128 int res;
developer72fb0bb2023-01-11 09:46:29 +080011129
developera3511852023-06-14 14:12:59 +080011130 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011131
developera3511852023-06-14 14:12:59 +080011132 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +080011133 if(max_radio_num == 0){
11134 return RETURN_ERR;
11135 }
developera3511852023-06-14 14:12:59 +080011136 radioIndex = apIndex % max_radio_num;
11137 phyId = radio_index_to_phy(radioIndex);
developer8078acf2023-08-04 18:52:48 +080011138
11139 res = _syscmd_secure(buf, sizeof(buf), "iw phy phy%d info | grep u-APSD", phyId);
11140 if (res) {
11141 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080011142 }
developer72fb0bb2023-01-11 09:46:29 +080011143
developera3511852023-06-14 14:12:59 +080011144 if (strlen(buf) > 0)
11145 *output = true;
developer72fb0bb2023-01-11 09:46:29 +080011146
developera3511852023-06-14 14:12:59 +080011147 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011148
developera3511852023-06-14 14:12:59 +080011149 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011150}
11151
11152//Whether WMM support is currently enabled. When enabled, this is indicated in beacon frames.
11153INT wifi_getApWmmEnable(INT apIndex, BOOL *output)
11154{
developera3511852023-06-14 14:12:59 +080011155 return wifi_getApWMMCapability(apIndex, output);
developer72fb0bb2023-01-11 09:46:29 +080011156}
11157
11158// enables/disables WMM on the hardwawre for this AP. enable==1, disable == 0
11159INT wifi_setApWmmEnable(INT apIndex, BOOL enable)
11160{
developer95c045d2023-05-24 19:26:28 +080011161 int if_idx, ret = 0;
11162 char interface_name[16] = {0};
developer95c045d2023-05-24 19:26:28 +080011163 struct nl_msg *msg = NULL;
11164 struct nlattr * msg_data = NULL;
11165 struct mtk_nl80211_param param;
11166 struct unl unl_ins;
developer72fb0bb2023-01-11 09:46:29 +080011167
developer95c045d2023-05-24 19:26:28 +080011168 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011169
developer95c045d2023-05-24 19:26:28 +080011170 if (apIndex > MAX_APS) {
11171 wifi_debug(DEBUG_ERROR, "Invalid apIndex %d\n", apIndex);
11172 return RETURN_ERR;
11173 }
developer72fb0bb2023-01-11 09:46:29 +080011174
developer95c045d2023-05-24 19:26:28 +080011175 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
11176 return RETURN_ERR;
developer8e6583c2023-05-23 13:36:06 +080011177
developer95c045d2023-05-24 19:26:28 +080011178 if_idx = if_nametoindex(interface_name);
11179 /*init mtk nl80211 vendor cmd*/
11180 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_WMM;
11181 param.if_type = NL80211_ATTR_IFINDEX;
11182 param.if_idx = if_idx;
11183 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
11184
11185 if (ret) {
11186 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
11187 return RETURN_ERR;
11188 }
11189
11190 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_WMM_AP_CAP_INFO, enable ? 1 : 0)) {
11191 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
11192 nlmsg_free(msg);
11193 goto err;
11194 }
11195
11196 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
11197 if (ret) {
11198 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vendor msg fails\n");
11199 goto err;
11200 }
11201 mtk_nl80211_deint(&unl_ins);
11202
11203 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
11204 return RETURN_OK;
11205err:
11206 mtk_nl80211_deint(&unl_ins);
11207 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
11208 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011209}
11210
developer95c045d2023-05-24 19:26:28 +080011211
developer72fb0bb2023-01-11 09:46:29 +080011212//Whether U-APSD support is currently enabled. When enabled, this is indicated in beacon frames. Note: U-APSD can only be enabled if WMM is also enabled.
11213INT wifi_getApWmmUapsdEnable(INT apIndex, BOOL *output)
11214{
developer75bd10c2023-06-27 11:34:08 +080011215 int res;
11216
developera3511852023-06-14 14:12:59 +080011217 //get the running status from driver
11218 if(!output)
11219 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011220
developera3511852023-06-14 14:12:59 +080011221 char config_file[128] = {0};
11222 char buf[16] = {0};
developer72fb0bb2023-01-11 09:46:29 +080011223
developer75bd10c2023-06-27 11:34:08 +080011224 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11225 if (os_snprintf_error(sizeof(config_file), res)) {
11226 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11227 return RETURN_ERR;
11228 }
developera3511852023-06-14 14:12:59 +080011229 wifi_hostapdRead(config_file, "uapsd_advertisement_enabled", buf, sizeof(buf));
11230 if (strlen(buf) == 0 || strncmp("1", buf, 1) == 0)
11231 *output = TRUE;
11232 else
11233 *output = FALSE;
developer72fb0bb2023-01-11 09:46:29 +080011234
developera3511852023-06-14 14:12:59 +080011235 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011236}
11237
11238// enables/disables Automatic Power Save Delivery on the hardwarwe for this AP
11239INT wifi_setApWmmUapsdEnable(INT apIndex, BOOL enable)
11240{
developera3511852023-06-14 14:12:59 +080011241 //save config and apply instantly.
11242 char config_file[MAX_BUF_SIZE] = {0};
11243 struct params list;
developer75bd10c2023-06-27 11:34:08 +080011244 int res;
developer72fb0bb2023-01-11 09:46:29 +080011245
developera3511852023-06-14 14:12:59 +080011246 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
11247 list.name = "uapsd_advertisement_enabled";
11248 list.value = enable?"1":"0";
developer72fb0bb2023-01-11 09:46:29 +080011249
developer75bd10c2023-06-27 11:34:08 +080011250 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11251 if (os_snprintf_error(sizeof(config_file), res)) {
11252 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11253 return RETURN_ERR;
11254 }
developera3511852023-06-14 14:12:59 +080011255 wifi_hostapdWrite(config_file, &list, 1);
11256 wifi_hostapdProcessUpdate(apIndex, &list, 1);
11257 wifi_quick_reload_ap(apIndex);
11258 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011259
developera3511852023-06-14 14:12:59 +080011260 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011261}
11262
11263// Sets the WMM ACK policy on the hardware. AckPolicy false means do not acknowledge, true means acknowledge
11264INT wifi_setApWmmOgAckPolicy(INT apIndex, INT class, BOOL ackPolicy) //RDKB
11265{
developera3511852023-06-14 14:12:59 +080011266 char interface_name[16] = {0};
11267 // assume class 0->BE, 1->BK, 2->VI, 3->VO
developer8078acf2023-08-04 18:52:48 +080011268
developera3511852023-06-14 14:12:59 +080011269 char buf[128] = {0};
11270 char ack_filepath[128] = {0};
11271 uint16_t bitmap = 0;
11272 uint16_t class_map[4] = {0x0009, 0x0006, 0x0030, 0x00C0};
11273 FILE *f = NULL;
developere40952c2023-06-15 18:46:43 +080011274 int res;
developerc14d83a2023-06-29 20:09:42 +080011275 unsigned long tmp;
developer72fb0bb2023-01-11 09:46:29 +080011276
developera3511852023-06-14 14:12:59 +080011277 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011278
developera3511852023-06-14 14:12:59 +080011279 // Get current setting
developere40952c2023-06-15 18:46:43 +080011280 res = snprintf(ack_filepath, sizeof(ack_filepath), "%s%d.txt", NOACK_MAP_FILE, apIndex);
11281 if (os_snprintf_error(sizeof(ack_filepath), res)) {
11282 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11283 return RETURN_ERR;
11284 }
developer8078acf2023-08-04 18:52:48 +080011285 res = _syscmd_secure(buf, sizeof(buf), "cat %s 2> /dev/null", ack_filepath);
11286 if (res) {
11287 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080011288 }
developer8078acf2023-08-04 18:52:48 +080011289
developerd14dff12023-06-28 22:47:44 +080011290 if (strlen(buf) > 0) {
developerc14d83a2023-06-29 20:09:42 +080011291 if (hal_strtoul(buf, 10, &tmp) < 0) {
11292 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +080011293 }
developerc14d83a2023-06-29 20:09:42 +080011294 bitmap = tmp;
developerd14dff12023-06-28 22:47:44 +080011295 }
developer72fb0bb2023-01-11 09:46:29 +080011296
developera3511852023-06-14 14:12:59 +080011297 if (ackPolicy == TRUE) { // True, unset this class
11298 bitmap &= ~class_map[class];
11299 } else { // False, set this class
11300 bitmap |= class_map[class];
11301 }
developer72fb0bb2023-01-11 09:46:29 +080011302
developera3511852023-06-14 14:12:59 +080011303 f = fopen(ack_filepath, "w");
11304 if (f == NULL) {
developer37646972023-06-29 10:58:43 +080011305 if (fprintf(stderr, "%s: fopen failed\n", __func__) < 0)
11306 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
developera3511852023-06-14 14:12:59 +080011307 return RETURN_ERR;
11308 }
developer37646972023-06-29 10:58:43 +080011309 if (fprintf(f, "%hu", bitmap) < 0)
11310 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
11311
11312 if (fclose(f) == EOF) {
11313 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
11314 return RETURN_ERR;
11315 }
developer72fb0bb2023-01-11 09:46:29 +080011316
developera3511852023-06-14 14:12:59 +080011317 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
11318 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080011319
11320 res = _syscmd_secure(buf, sizeof(buf), "iw dev %s set noack_map 0x%04x\n", interface_name, bitmap);
11321 if (res) {
11322 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080011323 }
developer72fb0bb2023-01-11 09:46:29 +080011324
developera3511852023-06-14 14:12:59 +080011325 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
11326 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011327}
11328
11329//The maximum number of devices that can simultaneously be connected to the access point. A value of 0 means that there is no specific limit.
11330INT wifi_getApMaxAssociatedDevices(INT apIndex, UINT *output_uint)
11331{
developer75bd10c2023-06-27 11:34:08 +080011332 int res;
11333
developera3511852023-06-14 14:12:59 +080011334 //get the running status from driver
11335 if(!output_uint)
11336 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011337
developera3511852023-06-14 14:12:59 +080011338 char output[16]={'\0'};
11339 char config_file[MAX_BUF_SIZE] = {0};
developer72fb0bb2023-01-11 09:46:29 +080011340
developer75bd10c2023-06-27 11:34:08 +080011341 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11342 if (os_snprintf_error(sizeof(config_file), res)) {
11343 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11344 return RETURN_ERR;
11345 }
developera3511852023-06-14 14:12:59 +080011346 wifi_hostapdRead(config_file, "max_num_sta", output, sizeof(output));
11347 if (strlen(output) == 0) *output_uint = MAX_ASSOCIATED_STA_NUM;
11348 else {
11349 int device_num = atoi(output);
11350 if (device_num > MAX_ASSOCIATED_STA_NUM || device_num < 0) {
11351 wifi_dbg_printf("\n[%s]: get max_num_sta error: %d", __func__, device_num);
11352 return RETURN_ERR;
11353 }
11354 else {
11355 *output_uint = device_num;
11356 }
11357 }
developer72fb0bb2023-01-11 09:46:29 +080011358
developera3511852023-06-14 14:12:59 +080011359 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011360}
11361
11362INT wifi_setApMaxAssociatedDevices(INT apIndex, UINT number)
11363{
developera3511852023-06-14 14:12:59 +080011364 //store to wifi config, apply instantly
11365 char str[MAX_BUF_SIZE]={'\0'};
11366 struct params params;
11367 char config_file[MAX_BUF_SIZE] = {0};
developer32f2a182023-06-27 19:50:41 +080011368 int res, ret;
developer72fb0bb2023-01-11 09:46:29 +080011369
developera3511852023-06-14 14:12:59 +080011370 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
11371 if (number > MAX_ASSOCIATED_STA_NUM) {
11372 WIFI_ENTRY_EXIT_DEBUG("%s: Invalid input\n",__func__);
11373 return RETURN_ERR;
11374 }
developer75bd10c2023-06-27 11:34:08 +080011375 res = snprintf(str, sizeof(str), "%d", number);
11376 if (os_snprintf_error(sizeof(str), res)) {
11377 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11378 return RETURN_ERR;
11379 }
developera3511852023-06-14 14:12:59 +080011380 params.name = "max_num_sta";
11381 params.value = str;
developer72fb0bb2023-01-11 09:46:29 +080011382
developer32f2a182023-06-27 19:50:41 +080011383 res = snprintf(config_file,
11384 sizeof(config_file), "%s%d.conf",CONFIG_PREFIX, apIndex);
developer75bd10c2023-06-27 11:34:08 +080011385 if (os_snprintf_error(sizeof(config_file), res)) {
11386 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11387 return RETURN_ERR;
11388 }
developer32f2a182023-06-27 19:50:41 +080011389 ret = wifi_hostapdWrite(config_file, &params, 1);
developera3511852023-06-14 14:12:59 +080011390 if (ret) {
11391 WIFI_ENTRY_EXIT_DEBUG("Inside %s: wifi_hostapdWrite() return %d\n"
11392 ,__func__, ret);
11393 }
developer72fb0bb2023-01-11 09:46:29 +080011394
developera3511852023-06-14 14:12:59 +080011395 ret = wifi_hostapdProcessUpdate(apIndex, &params, 1);
11396 if (ret) {
11397 WIFI_ENTRY_EXIT_DEBUG("Inside %s: wifi_hostapdProcessUpdate() return %d\n"
11398 ,__func__, ret);
11399 }
11400 wifi_reloadAp(apIndex);
11401 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011402
developera3511852023-06-14 14:12:59 +080011403 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011404}
11405
11406//The HighWatermarkThreshold value that is lesser than or equal to MaxAssociatedDevices. Setting this parameter does not actually limit the number of clients that can associate with this access point as that is controlled by MaxAssociatedDevices. MaxAssociatedDevices or 50. The default value of this parameter should be equal to MaxAssociatedDevices. In case MaxAssociatedDevices is 0 (zero), the default value of this parameter should be 50. A value of 0 means that there is no specific limit and Watermark calculation algorithm should be turned off.
11407INT wifi_getApAssociatedDevicesHighWatermarkThreshold(INT apIndex, UINT *output_uint)
11408{
developera3511852023-06-14 14:12:59 +080011409 //get the current threshold
11410 if(!output_uint)
11411 return RETURN_ERR;
11412 wifi_getApMaxAssociatedDevices(apIndex, output_uint);
11413 if (*output_uint == 0)
11414 *output_uint = 50;
11415 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011416}
11417
11418INT wifi_setApAssociatedDevicesHighWatermarkThreshold(INT apIndex, UINT Threshold)
11419{
developera3511852023-06-14 14:12:59 +080011420 //store the config, reset threshold, reset AssociatedDevicesHighWatermarkThresholdReached, reset AssociatedDevicesHighWatermarkDate to current time
11421 if (!wifi_setApMaxAssociatedDevices(apIndex, Threshold))
11422 return RETURN_OK;
11423 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011424}
11425
11426//Number of times the current total number of associated device has reached the HighWatermarkThreshold value. This calculation can be based on the parameter AssociatedDeviceNumberOfEntries as well. Implementation specifics about this parameter are left to the product group and the device vendors. It can be updated whenever there is a new client association request to the access point.
11427INT wifi_getApAssociatedDevicesHighWatermarkThresholdReached(INT apIndex, UINT *output_uint)
11428{
developera3511852023-06-14 14:12:59 +080011429 if(!output_uint)
11430 return RETURN_ERR;
11431 *output_uint = 3;
11432 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011433}
11434
11435//Maximum number of associated devices that have ever associated with the access point concurrently since the last reset of the device or WiFi module.
11436INT wifi_getApAssociatedDevicesHighWatermark(INT apIndex, UINT *output_uint)
11437{
developera3511852023-06-14 14:12:59 +080011438 if(!output_uint)
11439 return RETURN_ERR;
11440 *output_uint = 3;
11441 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011442}
11443
11444//Date and Time at which the maximum number of associated devices ever associated with the access point concurrenlty since the last reset of the device or WiFi module (or in short when was X_COMCAST-COM_AssociatedDevicesHighWatermark updated). This dateTime value is in UTC.
11445INT wifi_getApAssociatedDevicesHighWatermarkDate(INT apIndex, ULONG *output_in_seconds)
11446{
developera3511852023-06-14 14:12:59 +080011447 if(!output_in_seconds)
11448 return RETURN_ERR;
11449 *output_in_seconds = 0;
11450 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011451}
11452
11453//Comma-separated list of strings. Indicates which security modes this AccessPoint instance is capable of supporting. Each list item is an enumeration of: None,WEP-64,WEP-128,WPA-Personal,WPA2-Personal,WPA-WPA2-Personal,WPA-Enterprise,WPA2-Enterprise,WPA-WPA2-Enterprise
11454INT wifi_getApSecurityModesSupported(INT apIndex, CHAR *output)
11455{
developere40952c2023-06-15 18:46:43 +080011456 int res;
11457
developera3511852023-06-14 14:12:59 +080011458 if(!output || apIndex>=MAX_APS)
11459 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +080011460 //res = snprintf(output, 128, "None,WPA-Personal,WPA2-Personal,WPA-WPA2-Personal,WPA-Enterprise,WPA2-Enterprise,WPA-WPA2-Enterprise");
11461 res = snprintf(output, 128, "None,WPA2-Personal,WPA-WPA2-Personal,WPA2-Enterprise,WPA-WPA2-Enterprise,WPA3-Personal,WPA3-Enterprise");
11462 if (os_snprintf_error(128, res)) {
11463 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11464 return RETURN_ERR;
11465 }
developera3511852023-06-14 14:12:59 +080011466 return RETURN_OK;
developer69b61b02023-03-07 17:17:44 +080011467}
developer72fb0bb2023-01-11 09:46:29 +080011468
11469//The value MUST be a member of the list reported by the ModesSupported parameter. Indicates which security mode is enabled.
11470INT wifi_getApSecurityModeEnabled(INT apIndex, CHAR *output)
11471{
developera3511852023-06-14 14:12:59 +080011472 char config_file[128] = {0};
11473 char wpa[16] = {0};
11474 char key_mgmt[64] = {0};
developer9ce44382023-06-28 11:09:37 +080011475 int res = -1;
developere40952c2023-06-15 18:46:43 +080011476
developera3511852023-06-14 14:12:59 +080011477 if (!output)
11478 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011479
developer75bd10c2023-06-27 11:34:08 +080011480 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11481 if (os_snprintf_error(sizeof(config_file), res)) {
11482 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11483 return RETURN_ERR;
11484 }
developera3511852023-06-14 14:12:59 +080011485 wifi_hostapdRead(config_file, "wpa", wpa, sizeof(wpa));
developer72fb0bb2023-01-11 09:46:29 +080011486
developer32f2a182023-06-27 19:50:41 +080011487 memcpy(output, "None", 4);//Copying "None" to output string for default case
11488 output[4] = '\0';
developera3511852023-06-14 14:12:59 +080011489 wifi_hostapdRead(config_file, "wpa_key_mgmt", key_mgmt, sizeof(key_mgmt));
11490 if (strstr(key_mgmt, "WPA-PSK") && strstr(key_mgmt, "SAE") == NULL) {
11491 if (!strcmp(wpa, "1"))
developere40952c2023-06-15 18:46:43 +080011492 res = snprintf(output, 32, "WPA-Personal");
developera3511852023-06-14 14:12:59 +080011493 else if (!strcmp(wpa, "2"))
developere40952c2023-06-15 18:46:43 +080011494 res = snprintf(output, 32, "WPA2-Personal");
developera3511852023-06-14 14:12:59 +080011495 else if (!strcmp(wpa, "3"))
developere40952c2023-06-15 18:46:43 +080011496 res = snprintf(output, 32, "WPA-WPA2-Personal");
developer72fb0bb2023-01-11 09:46:29 +080011497
developera3511852023-06-14 14:12:59 +080011498 } else if (strstr(key_mgmt, "WPA-EAP-SUITE-B-192")) {
developere40952c2023-06-15 18:46:43 +080011499 res = snprintf(output, 32, "WPA3-Enterprise");
developera3511852023-06-14 14:12:59 +080011500 } else if (strstr(key_mgmt, "WPA-EAP")) {
11501 if (!strcmp(wpa, "1"))
developere40952c2023-06-15 18:46:43 +080011502 res = snprintf(output, 32, "WPA-Enterprise");
developera3511852023-06-14 14:12:59 +080011503 else if (!strcmp(wpa, "2"))
developere40952c2023-06-15 18:46:43 +080011504 res = snprintf(output, 32, "WPA2-Enterprise");
developera3511852023-06-14 14:12:59 +080011505 else if (!strcmp(wpa, "3"))
developere40952c2023-06-15 18:46:43 +080011506 res = snprintf(output, 32, "WPA-WPA2-Enterprise");
developera3511852023-06-14 14:12:59 +080011507 } else if (strstr(key_mgmt, "SAE")) {
11508 if (strstr(key_mgmt, "WPA-PSK") == NULL)
developere40952c2023-06-15 18:46:43 +080011509 res = snprintf(output, 32, "WPA3-Personal");
developera3511852023-06-14 14:12:59 +080011510 else
developere40952c2023-06-15 18:46:43 +080011511 res = snprintf(output, 32, "WPA3-Personal-Transition");
11512 }
11513 if (os_snprintf_error(32, res)) {
11514 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11515 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +080011516 }
developer72fb0bb2023-01-11 09:46:29 +080011517
developera3511852023-06-14 14:12:59 +080011518 //save the beaconTypeString to wifi config and hostapd config file. Wait for wifi reset or hostapd restart to apply
11519 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011520}
developer69b61b02023-03-07 17:17:44 +080011521
developer72fb0bb2023-01-11 09:46:29 +080011522INT wifi_setApSecurityModeEnabled(INT apIndex, CHAR *encMode)
11523{
developer32f2a182023-06-27 19:50:41 +080011524 char securityType[32] = {0};
11525 char authMode[32] = {0};
11526 unsigned long len_sec, len_auth;
developera3511852023-06-14 14:12:59 +080011527 //store settings and wait for wifi up to apply
11528 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
11529 if(!encMode)
11530 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011531
developera3511852023-06-14 14:12:59 +080011532 if (strcmp(encMode, "None")==0)
11533 {
developer32f2a182023-06-27 19:50:41 +080011534 len_sec = strlen("None");
11535 len_auth = strlen("None");
11536 memcpy(securityType, "None", len_sec);
11537 memcpy(authMode, "None", len_auth);
11538 } else if (strcmp(encMode, "WPA-WPA2-Personal")==0) {
11539 len_sec = strlen("WPAand11i");
11540 memcpy(securityType, "WPAand11i", len_sec);
11541 len_auth = strlen("PSKAuthentication");
11542 memcpy(authMode, "PSKAuthentication", len_auth);
11543 } else if (strcmp(encMode, "WPA-WPA2-Enterprise")==0) {
11544 len_sec = strlen("WPAand11i");
11545 memcpy(securityType, "WPAand11i", len_sec);
11546 len_auth = strlen("EAPAuthentication");
11547 memcpy(authMode, "EAPAuthentication", len_auth);
11548 } else if (strcmp(encMode, "WPA-Personal")==0) {
11549 len_sec = strlen("WPA");
11550 memcpy(securityType, "WPA", len_sec);
11551 len_auth = strlen("PSKAuthentication");
11552 memcpy(authMode, "PSKAuthentication", len_auth);
11553 } else if (strcmp(encMode, "WPA-Enterprise")==0) {
11554 len_sec = strlen("WPA");
11555 memcpy(securityType, "WPA", len_sec);
11556 len_auth = strlen("EAPAuthentication");
11557 memcpy(authMode, "EAPAuthentication", len_auth);
11558 } else if (strcmp(encMode, "WPA2-Personal")==0) {
11559 len_sec = strlen("11i");
11560 memcpy(securityType, "11i", len_sec);
11561 len_auth = strlen("PSKAuthentication");
11562 memcpy(authMode, "PSKAuthentication", len_auth);
11563 } else if (strcmp(encMode, "WPA2-Enterprise")==0) {
11564 len_sec = strlen("11i");
11565 memcpy(securityType, "11i", len_sec);
11566 len_auth = strlen("EAPAuthentication");
11567 memcpy(authMode, "EAPAuthentication", len_auth);
11568 } else if (strcmp(encMode, "WPA3-Personal") == 0) {
11569 len_sec = strlen("11i");
11570 memcpy(securityType, "11i", len_sec);
11571 len_auth = strlen("SAEAuthentication");
11572 memcpy(authMode, "SAEAuthentication", len_auth);
11573 } else if (strcmp(encMode, "WPA3-Personal-Transition") == 0) {
11574 len_sec = strlen("11i");
11575 memcpy(securityType, "11i", len_sec);
11576 len_auth = strlen("PSK-SAEAuthentication");
11577 memcpy(authMode, "PSK-SAEAuthentication", len_auth);
11578 } else if (strcmp(encMode, "WPA3-Enterprise") == 0) {
11579 len_sec = strlen("11i");
11580 memcpy(securityType, "11i", len_sec);
11581 len_auth = strlen("EAP_192-bit_Authentication");
11582 memcpy(authMode, "EAP_192-bit_Authentication", len_auth);
11583 } else if (strcmp(encMode, "OWE") == 0) {
11584 len_sec = strlen("11i");
11585 memcpy(securityType, "11i", len_sec);
11586 len_auth = strlen("Enhanced_Open");
11587 memcpy(authMode, "Enhanced_Open", len_auth);
11588 } else {
11589 len_sec = strlen("None");
11590 memcpy(securityType, "None", len_sec);
11591 len_auth = strlen("None");
11592 memcpy(authMode, "None", len_auth);
developera3511852023-06-14 14:12:59 +080011593 }
developer32f2a182023-06-27 19:50:41 +080011594 securityType[len_sec] = '\0';
11595 authMode[len_auth] = '\0';
developera3511852023-06-14 14:12:59 +080011596 wifi_setApBeaconType(apIndex, securityType);
11597 wifi_setApBasicAuthenticationMode(apIndex, authMode);
11598 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011599
developera3511852023-06-14 14:12:59 +080011600 return RETURN_OK;
developer69b61b02023-03-07 17:17:44 +080011601}
developer72fb0bb2023-01-11 09:46:29 +080011602
11603
11604//A literal PreSharedKey (PSK) expressed as a hexadecimal string.
11605// output_string must be pre-allocated as 64 character string by caller
11606// PSK Key of 8 to 63 characters is considered an ASCII string, and 64 characters are considered as HEX value
11607INT wifi_getApSecurityPreSharedKey(INT apIndex, CHAR *output_string)
11608{
developera3511852023-06-14 14:12:59 +080011609 char buf[16] = {0};
11610 char config_file[MAX_BUF_SIZE] = {0};
11611 int res;
developer72fb0bb2023-01-11 09:46:29 +080011612
developera3511852023-06-14 14:12:59 +080011613 if(output_string==NULL)
11614 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011615
developera3511852023-06-14 14:12:59 +080011616 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,apIndex);
11617 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080011618 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11619 return RETURN_ERR;
11620 }
developera3511852023-06-14 14:12:59 +080011621 wifi_hostapdRead(config_file,"wpa",buf,sizeof(buf));
developer72fb0bb2023-01-11 09:46:29 +080011622
developera3511852023-06-14 14:12:59 +080011623 if(strcmp(buf,"0")==0)
11624 {
11625 printf("wpa_mode is %s ......... \n",buf);
11626 return RETURN_ERR;
11627 }
developer72fb0bb2023-01-11 09:46:29 +080011628
developera3511852023-06-14 14:12:59 +080011629 wifi_dbg_printf("\nFunc=%s\n",__func__);
11630 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,apIndex);
11631 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080011632 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11633 return RETURN_ERR;
11634 }
developere5750452023-05-15 16:46:42 +080011635 wifi_hostapdRead(config_file,"wpa_psk",output_string,65);
developera3511852023-06-14 14:12:59 +080011636 wifi_dbg_printf("\noutput_string=%s\n",output_string);
developer72fb0bb2023-01-11 09:46:29 +080011637
developera3511852023-06-14 14:12:59 +080011638 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011639}
11640
11641// sets an enviornment variable for the psk. Input string preSharedKey must be a maximum of 64 characters
11642// PSK Key of 8 to 63 characters is considered an ASCII string, and 64 characters are considered as HEX value
11643INT wifi_setApSecurityPreSharedKey(INT apIndex, CHAR *preSharedKey)
11644{
developera3511852023-06-14 14:12:59 +080011645 //save to wifi config and hotapd config. wait for wifi reset or hostapd restet to apply
11646 struct params params={'\0'};
developer32f2a182023-06-27 19:50:41 +080011647 int ret;
developera3511852023-06-14 14:12:59 +080011648 char config_file[MAX_BUF_SIZE] = {0};
developer72fb0bb2023-01-11 09:46:29 +080011649
developera3511852023-06-14 14:12:59 +080011650 if(NULL == preSharedKey)
11651 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011652
developera3511852023-06-14 14:12:59 +080011653 params.name = "wpa_psk";
developer72fb0bb2023-01-11 09:46:29 +080011654
developera3511852023-06-14 14:12:59 +080011655 if(strlen(preSharedKey) != 64)
11656 {
11657 wifi_dbg_printf("\nCannot Set Preshared Key length of preshared key should be 64 chars\n");
11658 return RETURN_ERR;
11659 }
11660 params.value = preSharedKey;
developer32f2a182023-06-27 19:50:41 +080011661 ret = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11662 if (os_snprintf_error(sizeof(config_file), ret)) {
developer75bd10c2023-06-27 11:34:08 +080011663 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11664 return RETURN_ERR;
11665 }
developera3511852023-06-14 14:12:59 +080011666 ret = wifi_hostapdWrite(config_file, &params, 1);
11667 if(!ret) {
11668 ret = wifi_hostapdProcessUpdate(apIndex, &params, 1);
11669 wifi_reloadAp(apIndex);
11670 }
11671 return ret;
11672 //TODO: call hostapd_cli for dynamic_config_control
developer72fb0bb2023-01-11 09:46:29 +080011673}
11674
11675//A passphrase from which the PreSharedKey is to be generated, for WPA-Personal or WPA2-Personal or WPA-WPA2-Personal security modes.
11676// outputs the passphrase, maximum 63 characters
11677INT wifi_getApSecurityKeyPassphrase(INT apIndex, CHAR *output_string)
11678{
developera3511852023-06-14 14:12:59 +080011679 char config_file[MAX_BUF_SIZE] = {0}, buf[32] = {0};
developer75bd10c2023-06-27 11:34:08 +080011680 int res;
developer72fb0bb2023-01-11 09:46:29 +080011681
developera3511852023-06-14 14:12:59 +080011682 wifi_dbg_printf("\nFunc=%s\n",__func__);
11683 if (NULL == output_string)
11684 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011685
developer75bd10c2023-06-27 11:34:08 +080011686 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11687 if (os_snprintf_error(sizeof(config_file), res)) {
11688 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11689 return RETURN_ERR;
11690 }
11691
developera3511852023-06-14 14:12:59 +080011692 wifi_hostapdRead(config_file,"wpa",buf,sizeof(buf));
11693 if(strcmp(buf,"0")==0)
11694 {
11695 printf("wpa_mode is %s ......... \n",buf);
11696 return RETURN_ERR;
11697 }
developer72fb0bb2023-01-11 09:46:29 +080011698
developera3511852023-06-14 14:12:59 +080011699 wifi_hostapdRead(config_file,"wpa_passphrase",output_string,64);
11700 wifi_dbg_printf("\noutput_string=%s\n",output_string);
developer72fb0bb2023-01-11 09:46:29 +080011701
developera3511852023-06-14 14:12:59 +080011702 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011703}
11704
11705// sets the passphrase enviornment variable, max 63 characters
11706INT wifi_setApSecurityKeyPassphrase(INT apIndex, CHAR *passPhrase)
11707{
developera3511852023-06-14 14:12:59 +080011708 //save to wifi config and hotapd config. wait for wifi reset or hostapd restet to apply
11709 struct params params={'\0'};
11710 char config_file[MAX_BUF_SIZE] = {0};
11711 int ret;
developer72fb0bb2023-01-11 09:46:29 +080011712
developera3511852023-06-14 14:12:59 +080011713 if(NULL == passPhrase)
11714 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011715
developera3511852023-06-14 14:12:59 +080011716 if(strlen(passPhrase)<8 || strlen(passPhrase)>63)
11717 {
11718 wifi_dbg_printf("\nCannot Set Preshared Key length of preshared key should be 8 to 63 chars\n");
11719 return RETURN_ERR;
11720 }
11721 params.name = "wpa_passphrase";
11722 params.value = passPhrase;
developer32f2a182023-06-27 19:50:41 +080011723 ret = snprintf(config_file, sizeof(config_file),
11724 "%s%d.conf", CONFIG_PREFIX, apIndex);
11725 if (os_snprintf_error(sizeof(config_file), ret)) {
developer75bd10c2023-06-27 11:34:08 +080011726 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11727 return RETURN_ERR;
11728 }
developera3511852023-06-14 14:12:59 +080011729 ret=wifi_hostapdWrite(config_file,&params,1);
11730 if(!ret) {
11731 wifi_hostapdProcessUpdate(apIndex, &params, 1);
developere5750452023-05-15 16:46:42 +080011732 wifi_reloadAp(apIndex);
developera3511852023-06-14 14:12:59 +080011733 }
developer72fb0bb2023-01-11 09:46:29 +080011734
developera3511852023-06-14 14:12:59 +080011735 return ret;
developer72fb0bb2023-01-11 09:46:29 +080011736}
11737
11738//When set to true, this AccessPoint instance's WiFi security settings are reset to their factory default values. The affected settings include ModeEnabled, WEPKey, PreSharedKey and KeyPassphrase.
11739INT wifi_setApSecurityReset(INT apIndex)
11740{
developera3511852023-06-14 14:12:59 +080011741 char original_config_file[64] = {0};
11742 char current_config_file[64] = {0};
11743 char buf[64] = {0};
developer8078acf2023-08-04 18:52:48 +080011744
developera3511852023-06-14 14:12:59 +080011745 char wpa[4] = {0};
11746 char wpa_psk[64] = {0};
11747 char wpa_passphrase[64] = {0};
11748 char wpa_psk_file[128] = {0};
11749 char wpa_key_mgmt[64] = {0};
11750 char wpa_pairwise[32] = {0};
11751 wifi_band band;
11752 struct params list[6];
developere40952c2023-06-15 18:46:43 +080011753 int res;
developer72fb0bb2023-01-11 09:46:29 +080011754
developera3511852023-06-14 14:12:59 +080011755 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011756
developera3511852023-06-14 14:12:59 +080011757 band = wifi_index_to_band(apIndex);
developer37646972023-06-29 10:58:43 +080011758 if (band == band_2_4) {
11759 res = snprintf(original_config_file, sizeof(original_config_file),
11760 "/etc/hostapd-2G.conf");
11761 if (os_snprintf_error(sizeof(original_config_file), res)) {
11762 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11763 return RETURN_ERR;
11764 }
developer8078acf2023-08-04 18:52:48 +080011765
developer37646972023-06-29 10:58:43 +080011766 } else if (band == band_5) {
11767 res = snprintf(original_config_file, sizeof(original_config_file),
11768 "/etc/hostapd-5G.conf");
11769 if (os_snprintf_error(sizeof(original_config_file), res)) {
11770 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11771 return RETURN_ERR;
11772 }
11773 } else if (band == band_6) {
11774 res = snprintf(original_config_file, sizeof(original_config_file),
11775 "/etc/hostapd-6G.conf");
11776 if (os_snprintf_error(sizeof(original_config_file), res)) {
11777 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11778 return RETURN_ERR;
11779 }
11780 } else
developera3511852023-06-14 14:12:59 +080011781 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011782
developera3511852023-06-14 14:12:59 +080011783 wifi_hostapdRead(original_config_file, "wpa", wpa, sizeof(wpa));
11784 list[0].name = "wpa";
11785 list[0].value = wpa;
developer69b61b02023-03-07 17:17:44 +080011786
developera3511852023-06-14 14:12:59 +080011787 wifi_hostapdRead(original_config_file, "wpa_psk", wpa_psk, sizeof(wpa_psk));
11788 list[1].name = "wpa_psk";
11789 list[1].value = wpa_psk;
developer72fb0bb2023-01-11 09:46:29 +080011790
developera3511852023-06-14 14:12:59 +080011791 wifi_hostapdRead(original_config_file, "wpa_passphrase", wpa_passphrase, sizeof(wpa_passphrase));
11792 list[2].name = "wpa_passphrase";
11793 list[2].value = wpa_passphrase;
developer72fb0bb2023-01-11 09:46:29 +080011794
developera3511852023-06-14 14:12:59 +080011795 wifi_hostapdRead(original_config_file, "wpa_psk_file", wpa_psk_file, sizeof(wpa_psk_file));
developer72fb0bb2023-01-11 09:46:29 +080011796
developera3511852023-06-14 14:12:59 +080011797 if (strlen(wpa_psk_file) == 0)
developer32f2a182023-06-27 19:50:41 +080011798 memcpy(wpa_psk_file, PSK_FILE, strlen(PSK_FILE));
developer72fb0bb2023-01-11 09:46:29 +080011799
developera3511852023-06-14 14:12:59 +080011800 if (access(wpa_psk_file, F_OK) != 0) {
developer8078acf2023-08-04 18:52:48 +080011801 res = _syscmd_secure(buf, sizeof(buf),"touch %s", wpa_psk_file);
11802 if (res) {
11803 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080011804 }
developera3511852023-06-14 14:12:59 +080011805 }
11806 list[3].name = "wpa_psk_file";
11807 list[3].value = wpa_psk_file;
developer72fb0bb2023-01-11 09:46:29 +080011808
developera3511852023-06-14 14:12:59 +080011809 wifi_hostapdRead(original_config_file, "wpa_key_mgmt", wpa_key_mgmt, sizeof(wpa_key_mgmt));
11810 list[4].name = "wpa_key_mgmt";
11811 list[4].value = wpa_key_mgmt;
developer72fb0bb2023-01-11 09:46:29 +080011812
developera3511852023-06-14 14:12:59 +080011813 wifi_hostapdRead(original_config_file, "wpa_pairwise", wpa_pairwise, sizeof(wpa_pairwise));
11814 list[5].name = "wpa_pairwise";
11815 list[5].value = wpa_pairwise;
developer72fb0bb2023-01-11 09:46:29 +080011816
developer32f2a182023-06-27 19:50:41 +080011817 res = snprintf(current_config_file, sizeof(current_config_file),
11818 "%s%d.conf", CONFIG_PREFIX, apIndex);
11819 if (os_snprintf_error(sizeof(current_config_file), res)) {
11820 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11821 return RETURN_ERR;
11822 }
developera3511852023-06-14 14:12:59 +080011823 wifi_hostapdWrite(current_config_file, list, 6);
developer72fb0bb2023-01-11 09:46:29 +080011824
developera3511852023-06-14 14:12:59 +080011825 wifi_setApEnable(apIndex, FALSE);
11826 wifi_setApEnable(apIndex, TRUE);
developer72fb0bb2023-01-11 09:46:29 +080011827
developera3511852023-06-14 14:12:59 +080011828 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
11829 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011830}
11831
11832//The IP Address and port number of the RADIUS server used for WLAN security. RadiusServerIPAddr is only applicable when ModeEnabled is an Enterprise type (i.e. WPA-Enterprise, WPA2-Enterprise or WPA-WPA2-Enterprise).
11833INT wifi_getApSecurityRadiusServer(INT apIndex, CHAR *IP_output, UINT *Port_output, CHAR *RadiusSecret_output)
11834{
developera3511852023-06-14 14:12:59 +080011835 char config_file[64] = {0};
11836 char buf[64] = {0};
developer8078acf2023-08-04 18:52:48 +080011837
developere40952c2023-06-15 18:46:43 +080011838 int res;
developer72fb0bb2023-01-11 09:46:29 +080011839
developera3511852023-06-14 14:12:59 +080011840 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011841
developera3511852023-06-14 14:12:59 +080011842 if(!IP_output || !Port_output || !RadiusSecret_output)
11843 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011844
developera3511852023-06-14 14:12:59 +080011845 // Read the first matched config
developere40952c2023-06-15 18:46:43 +080011846 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11847 if (os_snprintf_error(sizeof(config_file), res)) {
11848 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11849 return RETURN_ERR;
11850 }
developer8078acf2023-08-04 18:52:48 +080011851 res = _syscmd_secure(buf, sizeof(buf),
developer32f2a182023-06-27 19:50:41 +080011852 "cat %s | grep \"^auth_server_addr=\" | cut -d \"=\" -f 2 | head -n1 | tr -d \"\\n\"", config_file);
developer8078acf2023-08-04 18:52:48 +080011853 if (res) {
11854 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080011855 }
developera3511852023-06-14 14:12:59 +080011856 strncpy(IP_output, buf, 64);
developer72fb0bb2023-01-11 09:46:29 +080011857
developera3511852023-06-14 14:12:59 +080011858 memset(buf, 0, sizeof(buf));
developer8078acf2023-08-04 18:52:48 +080011859 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep \"^auth_server_port=\" | cut -d \"=\" -f 2 | head -n1 | tr -d \"\\n\"", config_file);
11860 if (res) {
11861 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080011862 }
developera3511852023-06-14 14:12:59 +080011863 *Port_output = atoi(buf);
developer72fb0bb2023-01-11 09:46:29 +080011864
developera3511852023-06-14 14:12:59 +080011865 memset(buf, 0, sizeof(buf));
developer8078acf2023-08-04 18:52:48 +080011866 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep \"^auth_server_shared_secret=\" | cut -d \"=\" -f 2 | head -n1 | tr -d \"\\n\"", config_file);
11867 if (res) {
11868 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080011869 }
developera3511852023-06-14 14:12:59 +080011870 strncpy(RadiusSecret_output, buf, 64);
developer72fb0bb2023-01-11 09:46:29 +080011871
developera3511852023-06-14 14:12:59 +080011872 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
11873 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011874}
11875
11876INT wifi_setApSecurityRadiusServer(INT apIndex, CHAR *IPAddress, UINT port, CHAR *RadiusSecret)
11877{
developera3511852023-06-14 14:12:59 +080011878 char config_file[64] = {0};
11879 char port_str[8] = {0};
11880 char cmd[256] = {0};
11881 char buf[128] = {0};
11882 int res;
developer72fb0bb2023-01-11 09:46:29 +080011883
developera3511852023-06-14 14:12:59 +080011884 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011885
developere5750452023-05-15 16:46:42 +080011886 if (wifi_getApSecurityModeEnabled(apIndex, buf) != RETURN_OK)
developera3511852023-06-14 14:12:59 +080011887 return RETURN_ERR;
developere5750452023-05-15 16:46:42 +080011888
developera3511852023-06-14 14:12:59 +080011889 if (strstr(buf, "Enterprise") == NULL) // non Enterprise mode sould not set radius server info
11890 return RETURN_ERR;
developere5750452023-05-15 16:46:42 +080011891
developera3511852023-06-14 14:12:59 +080011892 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11893 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080011894 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11895 return RETURN_ERR;
11896 }
developer72fb0bb2023-01-11 09:46:29 +080011897
developer8078acf2023-08-04 18:52:48 +080011898 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '# radius 1'", config_file);
11899 if (res) {
11900 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer46506162023-06-12 10:09:39 +080011901 }
developer8078acf2023-08-04 18:52:48 +080011902
developera3511852023-06-14 14:12:59 +080011903 memset(cmd, 0, sizeof(cmd));
developer72fb0bb2023-01-11 09:46:29 +080011904
developere40952c2023-06-15 18:46:43 +080011905 res = snprintf(port_str, sizeof(port_str), "%d", port);
developer37646972023-06-29 10:58:43 +080011906 if (os_snprintf_error(sizeof(port_str), res)) {
11907 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11908 return RETURN_ERR;
11909 }
developera3511852023-06-14 14:12:59 +080011910 if (strlen(buf) == 0) {
11911 // Append
11912 res = snprintf(cmd, sizeof(cmd), "echo -e '# radius 1\\n"
11913 "auth_server_addr=%s\\n"
11914 "auth_server_port=%s\\n"
11915 "auth_server_shared_secret=%s' >> %s", IPAddress, port_str, RadiusSecret, config_file);
11916 if (os_snprintf_error(sizeof(cmd), res)) {
11917 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11918 return RETURN_ERR;
11919 }
developer8078acf2023-08-04 18:52:48 +080011920
11921 if(_syscmd_secure(buf, sizeof(buf), "echo -e '# radius 1\\n"
11922 "auth_server_addr=%s\\n"
11923 "auth_server_port=%s\\n"
11924 "auth_server_shared_secret=%s' >> %s", IPAddress, port_str, RadiusSecret, config_file)) {
11925 wifi_dbg_printf("%s: command failed, cmd: %s\n", __func__, cmd);
11926 return RETURN_ERR;
11927 }
developera3511852023-06-14 14:12:59 +080011928 } else {
11929 // Delete the three lines setting after the "# radius 1" comment
developer8078acf2023-08-04 18:52:48 +080011930 res = _syscmd_secure(buf, sizeof(buf), "sed -i '/# radius 1/{n;N;N;d}' %s", config_file);
11931 if (res) {
11932 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developera3511852023-06-14 14:12:59 +080011933 }
developera3511852023-06-14 14:12:59 +080011934 memset(cmd, 0, sizeof(cmd));
11935 // Use "# radius 1" comment to find the location to insert the radius setting
11936 res = snprintf(cmd, sizeof(cmd), "sed -i 's/# radius 1/"
11937 "# radius 1\\n"
11938 "auth_server_addr=%s\\n"
11939 "auth_server_port=%s\\n"
11940 "auth_server_shared_secret=%s/' %s", IPAddress, port_str, RadiusSecret, config_file);
11941 if (os_snprintf_error(sizeof(cmd), res)) {
11942 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11943 return RETURN_ERR;
11944 }
developer8078acf2023-08-04 18:52:48 +080011945
11946 if(_syscmd_secure(buf, sizeof(buf), "sed -i 's/# radius 1/"
11947 "# radius 1\\n"
11948 "auth_server_addr=%s\\n"
11949 "auth_server_port=%s\\n"
11950 "auth_server_shared_secret=%s/' %s", IPAddress, port_str, RadiusSecret, config_file)) {
11951 wifi_dbg_printf("%s: command failed, cmd: %s\n", __func__, cmd);
11952 return RETURN_ERR;
11953 }
developera3511852023-06-14 14:12:59 +080011954 }
developer72fb0bb2023-01-11 09:46:29 +080011955
developera3511852023-06-14 14:12:59 +080011956 wifi_reloadAp(apIndex);
11957 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
11958 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080011959}
11960
11961INT wifi_getApSecuritySecondaryRadiusServer(INT apIndex, CHAR *IP_output, UINT *Port_output, CHAR *RadiusSecret_output)
11962{
developera3511852023-06-14 14:12:59 +080011963 char config_file[64] = {0};
11964 char buf[64] = {0};
developer8078acf2023-08-04 18:52:48 +080011965
developere40952c2023-06-15 18:46:43 +080011966 int res;
developer72fb0bb2023-01-11 09:46:29 +080011967
developera3511852023-06-14 14:12:59 +080011968 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080011969
developera3511852023-06-14 14:12:59 +080011970 if(!IP_output || !Port_output || !RadiusSecret_output)
11971 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080011972
developera3511852023-06-14 14:12:59 +080011973 // Read the second matched config
developere40952c2023-06-15 18:46:43 +080011974 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
11975 if (os_snprintf_error(sizeof(config_file), res)) {
11976 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
11977 return RETURN_ERR;
11978 }
11979
developer8078acf2023-08-04 18:52:48 +080011980 res = _syscmd_secure(buf, sizeof(buf),
developer32f2a182023-06-27 19:50:41 +080011981 "cat %s | grep \"^auth_server_addr=\" | cut -d \"=\" -f 2 | tail -n +2 | head -n1 | tr -d \"\\n\"",
11982 config_file);
developer8078acf2023-08-04 18:52:48 +080011983 if (res) {
11984 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080011985 }
developer8078acf2023-08-04 18:52:48 +080011986
developera3511852023-06-14 14:12:59 +080011987 strncpy(IP_output, buf, 64);
developer72fb0bb2023-01-11 09:46:29 +080011988
developera3511852023-06-14 14:12:59 +080011989 memset(buf, 0, sizeof(buf));
developer8078acf2023-08-04 18:52:48 +080011990 res = _syscmd_secure(buf, sizeof(buf),
developer32f2a182023-06-27 19:50:41 +080011991 "cat %s | grep \"^auth_server_port=\" | cut -d \"=\" -f 2 | tail -n +2 | head -n1 | tr -d \"\\n\"",
11992 config_file);
developer8078acf2023-08-04 18:52:48 +080011993 if (res) {
11994 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080011995 }
developer8078acf2023-08-04 18:52:48 +080011996
developera3511852023-06-14 14:12:59 +080011997 *Port_output = atoi(buf);
developer72fb0bb2023-01-11 09:46:29 +080011998
developera3511852023-06-14 14:12:59 +080011999 memset(buf, 0, sizeof(buf));
developer8078acf2023-08-04 18:52:48 +080012000 res = _syscmd_secure(buf, sizeof(buf),
developer32f2a182023-06-27 19:50:41 +080012001 "cat %s | grep \"^auth_server_shared_secret=\" | cut -d \"=\" -f 2 | tail -n +2 | head -n1 | tr -d \"\\n\"",
12002 config_file);
developer8078acf2023-08-04 18:52:48 +080012003 if (res) {
12004 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080012005 }
12006
developera3511852023-06-14 14:12:59 +080012007 strncpy(RadiusSecret_output, buf, 64);
developer72fb0bb2023-01-11 09:46:29 +080012008
developera3511852023-06-14 14:12:59 +080012009 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
12010 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012011}
12012
12013INT wifi_setApSecuritySecondaryRadiusServer(INT apIndex, CHAR *IPAddress, UINT port, CHAR *RadiusSecret)
12014{
developera3511852023-06-14 14:12:59 +080012015 char config_file[64] = {0};
12016 char port_str[8] = {0};
12017 char cmd[256] = {0};
12018 char buf[128] = {0};
12019 int res;
developer72fb0bb2023-01-11 09:46:29 +080012020
developera3511852023-06-14 14:12:59 +080012021 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080012022
developere5750452023-05-15 16:46:42 +080012023 if (wifi_getApSecurityModeEnabled(apIndex, buf) != RETURN_OK)
developera3511852023-06-14 14:12:59 +080012024 return RETURN_ERR;
developere5750452023-05-15 16:46:42 +080012025
developera3511852023-06-14 14:12:59 +080012026 if (strstr(buf, "Enterprise") == NULL) // non Enterprise mode sould not set radius server info
12027 return RETURN_ERR;
developere5750452023-05-15 16:46:42 +080012028
developera3511852023-06-14 14:12:59 +080012029 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
12030 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080012031 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12032 return RETURN_ERR;
12033 }
developer72fb0bb2023-01-11 09:46:29 +080012034
developer8078acf2023-08-04 18:52:48 +080012035 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep '# radius 2'", config_file);
12036 if (res) {
12037 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer46506162023-06-12 10:09:39 +080012038 }
developer8078acf2023-08-04 18:52:48 +080012039
developera3511852023-06-14 14:12:59 +080012040 memset(cmd, 0, sizeof(cmd));
developer72fb0bb2023-01-11 09:46:29 +080012041
developera3511852023-06-14 14:12:59 +080012042 res = snprintf(port_str, sizeof(port_str), "%d", port);
12043 if (os_snprintf_error(sizeof(port_str), res)) {
developer46506162023-06-12 10:09:39 +080012044 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12045 return RETURN_ERR;
12046 }
developera3511852023-06-14 14:12:59 +080012047 if (strlen(buf) == 0) {
12048 // Append
12049 res = snprintf(cmd, sizeof(cmd), "echo -e '# radius 2\\n"
12050 "auth_server_addr=%s\\n"
12051 "auth_server_port=%s\\n"
12052 "auth_server_shared_secret=%s' >> %s", IPAddress, port_str, RadiusSecret, config_file);
12053 if (os_snprintf_error(sizeof(cmd), res)) {
12054 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12055 return RETURN_ERR;
12056 }
developer8078acf2023-08-04 18:52:48 +080012057
12058 if(_syscmd_secure(buf, sizeof(buf), "echo -e '# radius 2\\n"
12059 "auth_server_addr=%s\\n"
12060 "auth_server_port=%s\\n"
12061 "auth_server_shared_secret=%s' >> %s", IPAddress, port_str, RadiusSecret, config_file)){
12062 wifi_dbg_printf("%s: command failed, cmd: %s\n", __func__, cmd);
12063 return RETURN_ERR;
12064 }
developera3511852023-06-14 14:12:59 +080012065 } else {
12066 // Delete the three lines setting after the "# radius 2" comment
developer8078acf2023-08-04 18:52:48 +080012067 res = _syscmd_secure(buf, sizeof(buf), "sed -i '/# radius 2/{n;N;N;d}' %s", config_file);
12068 if (res) {
12069 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developera3511852023-06-14 14:12:59 +080012070 }
developer8078acf2023-08-04 18:52:48 +080012071
developera3511852023-06-14 14:12:59 +080012072 memset(cmd, 0, sizeof(cmd));
12073 // Use "# radius 2" comment to find the location to insert the radius setting
12074 res = snprintf(cmd, sizeof(cmd), "sed -i 's/# radius 2/"
12075 "# radius 2\\n"
12076 "auth_server_addr=%s\\n"
12077 "auth_server_port=%s\\n"
12078 "auth_server_shared_secret=%s/' %s", IPAddress, port_str, RadiusSecret, config_file);
12079 if (os_snprintf_error(sizeof(cmd), res)) {
12080 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12081 return RETURN_ERR;
12082 }
developer8078acf2023-08-04 18:52:48 +080012083
12084 if(_syscmd_secure(buf, sizeof(buf), "sed -i 's/# radius 2/"
12085 "# radius 2\\n"
12086 "auth_server_addr=%s\\n"
12087 "auth_server_port=%s\\n"
12088 "auth_server_shared_secret=%s/' %s", IPAddress, port_str, RadiusSecret, config_file)){
12089 wifi_dbg_printf("%s: command failed, cmd: %s\n", __func__, cmd);
12090 return RETURN_ERR;
12091 }
developera3511852023-06-14 14:12:59 +080012092 }
developer72fb0bb2023-01-11 09:46:29 +080012093
developera3511852023-06-14 14:12:59 +080012094 wifi_reloadAp(apIndex);
12095 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
12096 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012097}
12098
12099//RadiusSettings
12100INT wifi_getApSecurityRadiusSettings(INT apIndex, wifi_radius_setting_t *output)
12101{
developera3511852023-06-14 14:12:59 +080012102 if(!output)
12103 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012104
developera3511852023-06-14 14:12:59 +080012105 output->RadiusServerRetries = 3; //Number of retries for Radius requests.
12106 output->RadiusServerRequestTimeout = 5; //Radius request timeout in seconds after which the request must be retransmitted for the # of retries available.
12107 output->PMKLifetime = 28800; //Default time in seconds after which a Wi-Fi client is forced to ReAuthenticate (def 8 hrs).
12108 output->PMKCaching = FALSE; //Enable or disable caching of PMK.
12109 output->PMKCacheInterval = 300; //Time interval in seconds after which the PMKSA (Pairwise Master Key Security Association) cache is purged (def 5 minutes).
12110 output->MaxAuthenticationAttempts = 3; //Indicates the # of time, a client can attempt to login with incorrect credentials. When this limit is reached, the client is blacklisted and not allowed to attempt loging into the network. Settings this parameter to 0 (zero) disables the blacklisting feature.
12111 output->BlacklistTableTimeout = 600; //Time interval in seconds for which a client will continue to be blacklisted once it is marked so.
12112 output->IdentityRequestRetryInterval = 5; //Time Interval in seconds between identity requests retries. A value of 0 (zero) disables it.
12113 output->QuietPeriodAfterFailedAuthentication = 5; //The enforced quiet period (time interval) in seconds following failed authentication. A value of 0 (zero) disables it.
developere40952c2023-06-15 18:46:43 +080012114 //res = snprintf(output->RadiusSecret, 64, "12345678"); //The secret used for handshaking with the RADIUS server [RFC2865]. When read, this parameter returns an empty string, regardless of the actual value.
developer72fb0bb2023-01-11 09:46:29 +080012115
developera3511852023-06-14 14:12:59 +080012116 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012117}
12118
12119INT wifi_setApSecurityRadiusSettings(INT apIndex, wifi_radius_setting_t *input)
12120{
developera3511852023-06-14 14:12:59 +080012121 //store the paramters, and apply instantly
12122 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012123}
12124
12125//Device.WiFi.AccessPoint.{i}.WPS.Enable
12126//Enables or disables WPS functionality for this access point.
12127// outputs the WPS enable state of this ap in output_bool
12128INT wifi_getApWpsEnable(INT apIndex, BOOL *output_bool)
12129{
developera3511852023-06-14 14:12:59 +080012130 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +080012131 char buf[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +080012132 int res;
12133
developera3511852023-06-14 14:12:59 +080012134 if(!output_bool)
12135 return RETURN_ERR;
12136 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12137 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080012138 res = _syscmd_secure(buf, sizeof(buf),
developer32f2a182023-06-27 19:50:41 +080012139 "hostapd_cli -i %s get_config | grep wps_state | cut -d '=' -f2",
12140 interface_name);
developer8078acf2023-08-04 18:52:48 +080012141 if (res) {
12142 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080012143 }
developera3511852023-06-14 14:12:59 +080012144 if(strstr(buf, "configured"))
12145 *output_bool=TRUE;
12146 else
12147 *output_bool=FALSE;
developer72fb0bb2023-01-11 09:46:29 +080012148
developera3511852023-06-14 14:12:59 +080012149 return RETURN_OK;
developer69b61b02023-03-07 17:17:44 +080012150}
developer72fb0bb2023-01-11 09:46:29 +080012151
12152//Device.WiFi.AccessPoint.{i}.WPS.Enable
12153// sets the WPS enable enviornment variable for this ap to the value of enableValue, 1==enabled, 0==disabled
12154INT wifi_setApWpsEnable(INT apIndex, BOOL enable)
12155{
developera3511852023-06-14 14:12:59 +080012156 char config_file[MAX_BUF_SIZE] = {0};
12157 char buf[128] = {0};
12158 struct params params;
developere40952c2023-06-15 18:46:43 +080012159 int res;
developer72fb0bb2023-01-11 09:46:29 +080012160
developera3511852023-06-14 14:12:59 +080012161 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
12162 //store the paramters, and wait for wifi up to apply
12163 params.name = "wps_state";
12164 if (enable == TRUE) {
12165 wifi_getApBeaconType(apIndex, buf);
12166 if (strncmp(buf, "None", 4) == 0) // If ap didn't set encryption
12167 params.value = "1";
12168 else // If ap set encryption
12169 params.value = "2";
12170 } else {
12171 params.value = "0";
12172 }
developer72fb0bb2023-01-11 09:46:29 +080012173
developere40952c2023-06-15 18:46:43 +080012174 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
12175 if (os_snprintf_error(sizeof(config_file), res)) {
12176 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12177 return RETURN_ERR;
12178 }
developera3511852023-06-14 14:12:59 +080012179 wifi_hostapdWrite(config_file, &params, 1);
12180 wifi_hostapdProcessUpdate(apIndex, &params, 1);
12181 wifi_reloadAp(apIndex);
developer72fb0bb2023-01-11 09:46:29 +080012182
developera3511852023-06-14 14:12:59 +080012183 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
12184 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012185}
12186
12187//Comma-separated list of strings. Indicates WPS configuration methods supported by the device. Each list item is an enumeration of: USBFlashDrive,Ethernet,ExternalNFCToken,IntegratedNFCToken,NFCInterface,PushButton,PIN
12188INT wifi_getApWpsConfigMethodsSupported(INT apIndex, CHAR *output)
12189{
developere40952c2023-06-15 18:46:43 +080012190 int res;
developera3511852023-06-14 14:12:59 +080012191 if(!output)
12192 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +080012193 res = snprintf(output, 128, "PushButton,PIN");
12194 if (os_snprintf_error(128, res)) {
12195 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12196 return RETURN_ERR;
12197 }
12198
developera3511852023-06-14 14:12:59 +080012199 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012200}
12201
12202//Device.WiFi.AccessPoint.{i}.WPS.ConfigMethodsEnabled
12203//Comma-separated list of strings. Each list item MUST be a member of the list reported by the ConfigMethodsSupported parameter. Indicates WPS configuration methods enabled on the device.
12204// Outputs a common separated list of the enabled WPS config methods, 64 bytes max
12205INT wifi_getApWpsConfigMethodsEnabled(INT apIndex, CHAR *output)
12206{
developere40952c2023-06-15 18:46:43 +080012207 int res;
developera3511852023-06-14 14:12:59 +080012208 if(!output)
12209 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +080012210 res = snprintf(output, 64, "PushButton,PIN");//Currently, supporting these two methods
12211 if (os_snprintf_error(64, res)) {
12212 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12213 return RETURN_ERR;
12214 }
developer72fb0bb2023-01-11 09:46:29 +080012215
developera3511852023-06-14 14:12:59 +080012216 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012217}
12218
12219//Device.WiFi.AccessPoint.{i}.WPS.ConfigMethodsEnabled
12220// sets an enviornment variable that specifies the WPS configuration method(s). methodString is a comma separated list of methods USBFlashDrive,Ethernet,ExternalNFCToken,IntegratedNFCToken,NFCInterface,PushButton,PIN
12221INT wifi_setApWpsConfigMethodsEnabled(INT apIndex, CHAR *methodString)
12222{
developera3511852023-06-14 14:12:59 +080012223 //apply instantly. No setting need to be stored.
12224 char methods[MAX_BUF_SIZE], *token, *next_token;
12225 char config_file[MAX_BUF_SIZE], config_methods[MAX_BUF_SIZE] = {0};
12226 struct params params;
developere40952c2023-06-15 18:46:43 +080012227 int res;
developer72fb0bb2023-01-11 09:46:29 +080012228
developera3511852023-06-14 14:12:59 +080012229 if(!methodString)
12230 return RETURN_ERR;
12231 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
12232 //store the paramters, and wait for wifi up to apply
developer72fb0bb2023-01-11 09:46:29 +080012233
developere40952c2023-06-15 18:46:43 +080012234 res = snprintf(methods, sizeof(methods), "%s", methodString);
12235 if (os_snprintf_error(sizeof(methods), res)) {
12236 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12237 return RETURN_ERR;
12238 }
developera3511852023-06-14 14:12:59 +080012239 for(token=methods; *token; token=next_token) {
12240 strtok_r(token, ",", &next_token);
12241 if(*token=='U' && !strcmp(methods, "USBFlashDrive"))
developere40952c2023-06-15 18:46:43 +080012242 res = snprintf(config_methods, sizeof(config_methods), "%s ", "usba");
developera3511852023-06-14 14:12:59 +080012243 else if(*token=='E')
12244 {
12245 if(!strcmp(methods, "Ethernet"))
developere40952c2023-06-15 18:46:43 +080012246 res = snprintf(config_methods, sizeof(config_methods), "%s ", "ethernet");
developera3511852023-06-14 14:12:59 +080012247 else if(!strcmp(methods, "ExternalNFCToken"))
developere40952c2023-06-15 18:46:43 +080012248 res = snprintf(config_methods, sizeof(config_methods), "%s ", "ext_nfc_token");
developera3511852023-06-14 14:12:59 +080012249 else
12250 printf("%s: Unknown WpsConfigMethod\n", __func__);
12251 }
12252 else if(*token=='I' && !strcmp(token, "IntegratedNFCToken"))
developere40952c2023-06-15 18:46:43 +080012253 res = snprintf(config_methods, sizeof(config_methods), "%s ", "int_nfc_token");
developera3511852023-06-14 14:12:59 +080012254 else if(*token=='N' && !strcmp(token, "NFCInterface"))
developere40952c2023-06-15 18:46:43 +080012255 res = snprintf(config_methods, sizeof(config_methods), "%s ", "nfc_interface");
developera3511852023-06-14 14:12:59 +080012256 else if(*token=='P' )
12257 {
12258 if(!strcmp(token, "PushButton"))
developere40952c2023-06-15 18:46:43 +080012259 res = snprintf(config_methods, sizeof(config_methods), "%s ", "push_button");
developera3511852023-06-14 14:12:59 +080012260 else if(!strcmp(token, "PIN"))
developere40952c2023-06-15 18:46:43 +080012261 res = snprintf(config_methods, sizeof(config_methods), "%s ", "keypad");
developera3511852023-06-14 14:12:59 +080012262 else
12263 printf("%s: Unknown WpsConfigMethod\n", __func__);
12264 }
12265 else
12266 printf("%s: Unknown WpsConfigMethod\n", __func__);
developere40952c2023-06-15 18:46:43 +080012267
developer37646972023-06-29 10:58:43 +080012268 if (os_snprintf_error(sizeof(config_methods), res)) {
12269 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12270 return RETURN_ERR;
12271 }
12272 }
developera3511852023-06-14 14:12:59 +080012273 params.name = "config_methods";
12274 params.value = config_methods;
developere40952c2023-06-15 18:46:43 +080012275 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
12276 if (os_snprintf_error(sizeof(config_file), res)) {
12277 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12278 return RETURN_ERR;
12279 }
developera3511852023-06-14 14:12:59 +080012280 wifi_hostapdWrite(config_file, &params, 1);
12281 wifi_hostapdProcessUpdate(apIndex, &params, 1);
12282 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080012283
developera3511852023-06-14 14:12:59 +080012284 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012285}
12286
12287// outputs the pin value, ulong_pin must be allocated by the caller
12288INT wifi_getApWpsDevicePIN(INT apIndex, ULONG *output_ulong)
12289{
developera3511852023-06-14 14:12:59 +080012290 char buf[MAX_BUF_SIZE] = {0};
developer8078acf2023-08-04 18:52:48 +080012291
developere40952c2023-06-15 18:46:43 +080012292 int res;
developer72fb0bb2023-01-11 09:46:29 +080012293
developera3511852023-06-14 14:12:59 +080012294 if(!output_ulong)
12295 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080012296 res = _syscmd_secure(buf, sizeof(buf), "cat %s%d.conf | grep ap_pin | cut -d '=' -f2", CONFIG_PREFIX, apIndex);
12297 if (res) {
12298 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080012299 }
developerd14dff12023-06-28 22:47:44 +080012300 if(strlen(buf) > 0) {
developerc14d83a2023-06-29 20:09:42 +080012301 if (hal_strtoul(buf, 10, output_ulong) < 0) {
12302 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +080012303 }
12304 }
developer72fb0bb2023-01-11 09:46:29 +080012305
developera3511852023-06-14 14:12:59 +080012306 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012307}
12308
12309// set an enviornment variable for the WPS pin for the selected AP. Normally, Device PIN should not be changed.
12310INT wifi_setApWpsDevicePIN(INT apIndex, ULONG pin)
12311{
developera3511852023-06-14 14:12:59 +080012312 //set the pin to wifi config and hostpad config. wait for wifi reset or hostapd reset to apply
12313 char ap_pin[16] = {0};
12314 char config_file[MAX_BUF_SIZE] = {0};
12315 struct params params;
developere40952c2023-06-15 18:46:43 +080012316 int res;
developer72fb0bb2023-01-11 09:46:29 +080012317
developera3511852023-06-14 14:12:59 +080012318 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developere40952c2023-06-15 18:46:43 +080012319 res = snprintf(ap_pin, sizeof(ap_pin), "%lu", pin);
12320 if (os_snprintf_error(sizeof(ap_pin), res)) {
12321 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12322 return RETURN_ERR;
12323 }
developera3511852023-06-14 14:12:59 +080012324 params.name = "ap_pin";
12325 params.value = ap_pin;
developere40952c2023-06-15 18:46:43 +080012326 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
12327 if (os_snprintf_error(sizeof(config_file), res)) {
12328 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12329 return RETURN_ERR;
12330 }
developera3511852023-06-14 14:12:59 +080012331 wifi_hostapdWrite(config_file, &params, 1);
12332 wifi_hostapdProcessUpdate(apIndex, &params, 1);
12333 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080012334
developera3511852023-06-14 14:12:59 +080012335 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012336}
12337
12338// Output string is either Not configured or Configured, max 32 characters
12339INT wifi_getApWpsConfigurationState(INT apIndex, CHAR *output_string)
12340{
developera3511852023-06-14 14:12:59 +080012341 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +080012342 char buf[MAX_BUF_SIZE]={0};
developere40952c2023-06-15 18:46:43 +080012343 int res;
developer72fb0bb2023-01-11 09:46:29 +080012344
developera3511852023-06-14 14:12:59 +080012345 if(!output_string)
12346 return RETURN_ERR;
12347 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developere40952c2023-06-15 18:46:43 +080012348 res = snprintf(output_string, 32, "Not configured");
12349 if (os_snprintf_error(32, res)) {
12350 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12351 return RETURN_ERR;
12352 }
developera3511852023-06-14 14:12:59 +080012353 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12354 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080012355 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s get_config | grep wps_state | cut -d'=' -f2", interface_name);
12356 if (res) {
12357 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080012358 }
developer72fb0bb2023-01-11 09:46:29 +080012359
developerc14d83a2023-06-29 20:09:42 +080012360 if(!strncmp(buf, "configured", 10)) {
developere40952c2023-06-15 18:46:43 +080012361 res = snprintf(output_string, 32, "Configured");
developerc14d83a2023-06-29 20:09:42 +080012362 if (os_snprintf_error(32, res)) {
12363 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
12364 return RETURN_ERR;
12365 }
12366 }
developera3511852023-06-14 14:12:59 +080012367 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080012368
developera3511852023-06-14 14:12:59 +080012369 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012370}
12371
12372// sets the WPS pin for this AP
12373INT wifi_setApWpsEnrolleePin(INT apIndex, CHAR *pin)
12374{
developera3511852023-06-14 14:12:59 +080012375 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +080012376 char buf[MAX_BUF_SIZE]={0};
developer9ce44382023-06-28 11:09:37 +080012377 BOOL enable = 0;
developere40952c2023-06-15 18:46:43 +080012378 int res;
developer72fb0bb2023-01-11 09:46:29 +080012379
developera3511852023-06-14 14:12:59 +080012380 wifi_getApEnable(apIndex, &enable);
12381 if (!enable)
12382 return RETURN_ERR;
12383 wifi_getApWpsEnable(apIndex, &enable);
12384 if (!enable)
12385 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012386
developera3511852023-06-14 14:12:59 +080012387 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12388 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080012389 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i%s wps_pin any %s", interface_name, pin);
12390 if (res) {
12391 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080012392 }
developer8078acf2023-08-04 18:52:48 +080012393
developera3511852023-06-14 14:12:59 +080012394 if((strstr(buf, "OK"))!=NULL)
12395 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012396
developera3511852023-06-14 14:12:59 +080012397 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012398}
12399
12400// This function is called when the WPS push button has been pressed for this AP
12401INT wifi_setApWpsButtonPush(INT apIndex)
12402{
developera3511852023-06-14 14:12:59 +080012403 char buf[MAX_BUF_SIZE]={0};
12404 char interface_name[16] = {0};
12405 BOOL enable=FALSE;
developere40952c2023-06-15 18:46:43 +080012406 int res;
developer72fb0bb2023-01-11 09:46:29 +080012407
developera3511852023-06-14 14:12:59 +080012408 wifi_getApEnable(apIndex, &enable);
12409 if (!enable)
12410 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012411
developera3511852023-06-14 14:12:59 +080012412 wifi_getApWpsEnable(apIndex, &enable);
12413 if (!enable)
12414 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012415
developera3511852023-06-14 14:12:59 +080012416 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12417 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012418
developer8078acf2023-08-04 18:52:48 +080012419 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i%s wps_cancel; hostapd_cli -i%s wps_pbc", interface_name, interface_name);
12420 if (res) {
12421 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080012422 }
developer72fb0bb2023-01-11 09:46:29 +080012423
developera3511852023-06-14 14:12:59 +080012424 if((strstr(buf, "OK"))!=NULL)
12425 return RETURN_OK;
12426 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012427}
12428
12429// cancels WPS mode for this AP
12430INT wifi_cancelApWPS(INT apIndex)
12431{
developera3511852023-06-14 14:12:59 +080012432 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +080012433 char buf[MAX_BUF_SIZE]={0};
developere40952c2023-06-15 18:46:43 +080012434 int res;
developer72fb0bb2023-01-11 09:46:29 +080012435
developera3511852023-06-14 14:12:59 +080012436 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12437 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080012438
12439 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i%s wps_cancel", interface_name);
12440 if (res) {
12441 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080012442 }
developer72fb0bb2023-01-11 09:46:29 +080012443
developera3511852023-06-14 14:12:59 +080012444 if((strstr(buf, "OK"))!=NULL)
12445 return RETURN_OK;
12446 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012447}
12448
12449//Device.WiFi.AccessPoint.{i}.AssociatedDevice.*
12450//HAL funciton should allocate an data structure array, and return to caller with "associated_dev_array"
12451INT wifi_getApAssociatedDeviceDiagnosticResult(INT apIndex, wifi_associated_dev_t **associated_dev_array, UINT *output_array_size)
12452{
developera3511852023-06-14 14:12:59 +080012453 char interface_name[16] = {0};
12454 FILE *f = NULL;
12455 int read_flag=0, auth_temp=0, mac_temp=0;
developer8078acf2023-08-04 18:52:48 +080012456 char buf[2048] = {0};
developera3511852023-06-14 14:12:59 +080012457 char *param = NULL, *value = NULL, *line=NULL;
12458 size_t len = 0;
12459 wifi_associated_dev_t *dev=NULL;
12460 int res;
developer72fb0bb2023-01-11 09:46:29 +080012461
developera3511852023-06-14 14:12:59 +080012462 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
12463 *associated_dev_array = NULL;
12464 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12465 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080012466 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i%s all_sta | grep AUTHORIZED | wc -l", interface_name);
12467 if (res) {
12468 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer46506162023-06-12 10:09:39 +080012469 }
developer8078acf2023-08-04 18:52:48 +080012470
developera3511852023-06-14 14:12:59 +080012471 *output_array_size = atoi(buf);
developer72fb0bb2023-01-11 09:46:29 +080012472
developera3511852023-06-14 14:12:59 +080012473 if (*output_array_size <= 0)
12474 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012475
developera3511852023-06-14 14:12:59 +080012476 dev=(wifi_associated_dev_t *) calloc (*output_array_size, sizeof(wifi_associated_dev_t));
developere75ba632023-06-29 16:03:33 +080012477 if (!dev) {
12478 wifi_debug(DEBUG_ERROR, "Unexpected calloc fail\n");
12479 return RETURN_ERR;
12480 }
developera3511852023-06-14 14:12:59 +080012481 *associated_dev_array = dev;
developer8078acf2023-08-04 18:52:48 +080012482 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i%s all_sta > /tmp/connected_devices.txt" , interface_name);
12483 if (res) {
12484 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer46506162023-06-12 10:09:39 +080012485 }
developer8078acf2023-08-04 18:52:48 +080012486
developera3511852023-06-14 14:12:59 +080012487 f = fopen("/tmp/connected_devices.txt", "r");
12488 if (f==NULL)
12489 {
12490 *output_array_size=0;
12491 return RETURN_ERR;
12492 }
12493 while ((getline(&line, &len, f)) != -1)
12494 {
12495 param = strtok(line,"=");
developere75ba632023-06-29 16:03:33 +080012496 if (!param)
12497 continue;
developera3511852023-06-14 14:12:59 +080012498 value = strtok(NULL,"=");
developere75ba632023-06-29 16:03:33 +080012499 if (!value)
12500 continue;
developer72fb0bb2023-01-11 09:46:29 +080012501
developera3511852023-06-14 14:12:59 +080012502 if( strcmp("flags",param) == 0 )
12503 {
12504 value[strlen(value)-1]='\0';
12505 if(strstr (value,"AUTHORIZED") != NULL )
12506 {
12507 dev[auth_temp].cli_AuthenticationState = 1;
12508 dev[auth_temp].cli_Active = 1;
12509 auth_temp++;
12510 read_flag=1;
12511 }
12512 }
12513 if(read_flag==1)
12514 {
12515 if( strcmp("dot11RSNAStatsSTAAddress",param) == 0 )
12516 {
12517 value[strlen(value)-1]='\0';
developere75ba632023-06-29 16:03:33 +080012518 if (sscanf(value, "%x:%x:%x:%x:%x:%x",
developera3511852023-06-14 14:12:59 +080012519 (unsigned int *)&dev[mac_temp].cli_MACAddress[0],
12520 (unsigned int *)&dev[mac_temp].cli_MACAddress[1],
12521 (unsigned int *)&dev[mac_temp].cli_MACAddress[2],
12522 (unsigned int *)&dev[mac_temp].cli_MACAddress[3],
12523 (unsigned int *)&dev[mac_temp].cli_MACAddress[4],
developere75ba632023-06-29 16:03:33 +080012524 (unsigned int *)&dev[mac_temp].cli_MACAddress[5] ) == EOF)
12525 continue;
developera3511852023-06-14 14:12:59 +080012526 mac_temp++;
12527 read_flag=0;
12528 }
12529 }
12530 }
12531 *output_array_size = auth_temp;
12532 auth_temp=0;
12533 mac_temp=0;
12534 free(line);
developere75ba632023-06-29 16:03:33 +080012535 if (fclose(f) == EOF) {
12536 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
12537 return RETURN_ERR;
12538 }
developera3511852023-06-14 14:12:59 +080012539 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
12540 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012541}
12542
12543#define MACADDRESS_SIZE 6
12544
12545INT wifihal_AssociatedDevicesstats3(INT apIndex,CHAR *interface_name,wifi_associated_dev3_t **associated_dev_array, UINT *output_array_size)
12546{
developera3511852023-06-14 14:12:59 +080012547 FILE *fp = NULL;
12548 char str[MAX_BUF_SIZE] = {0};
12549 int wificlientindex = 0 ;
12550 int count = 0;
12551 int signalstrength = 0;
12552 int arr[MACADDRESS_SIZE] = {0};
12553 unsigned char mac[MACADDRESS_SIZE] = {0};
12554 UINT wifi_count = 0;
developere40952c2023-06-15 18:46:43 +080012555 int res;
developerc14d83a2023-06-29 20:09:42 +080012556 wifi_associated_dev3_t* temp = NULL;
developer72fb0bb2023-01-11 09:46:29 +080012557
developera3511852023-06-14 14:12:59 +080012558 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
12559 *output_array_size = 0;
12560 *associated_dev_array = NULL;
developer72fb0bb2023-01-11 09:46:29 +080012561
developer33f13ba2023-07-12 16:19:06 +080012562 fp = v_secure_popen("r", "iw dev %s station dump | grep %s | wc -l",
12563 interface_name, interface_name);
developera3511852023-06-14 14:12:59 +080012564 if (fp == NULL)
12565 {
12566 printf("Failed to run command inside function %s\n",__FUNCTION__ );
12567 return RETURN_ERR;
12568 }
developer72fb0bb2023-01-11 09:46:29 +080012569
developera3511852023-06-14 14:12:59 +080012570 /* Read the output a line at a time - output it. */
developer86035662023-06-28 19:21:12 +080012571 if (fgets(str, sizeof(str)-1, fp) == NULL) {
12572 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer33f13ba2023-07-12 16:19:06 +080012573 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080012574 return RETURN_ERR;
12575 }
developera3511852023-06-14 14:12:59 +080012576 wifi_count = (unsigned int) atoi ( str );
12577 *output_array_size = wifi_count;
12578 printf(" In rdkb hal ,Wifi Client Counts and index %d and %d \n",*output_array_size,apIndex);
developer33f13ba2023-07-12 16:19:06 +080012579 v_secure_pclose(fp);
developer72fb0bb2023-01-11 09:46:29 +080012580
developera3511852023-06-14 14:12:59 +080012581 if(wifi_count == 0)
12582 {
12583 return RETURN_OK;
12584 }
12585 else
12586 {
developer9ce44382023-06-28 11:09:37 +080012587 if(wifi_count <= 0 || wifi_count > MAX_ASSOCIATED_STA_NUM){
12588 return RETURN_ERR;
12589 }
developera3511852023-06-14 14:12:59 +080012590 temp = (wifi_associated_dev3_t*)calloc(1, sizeof(wifi_associated_dev3_t)*wifi_count) ;
12591 if(temp == NULL)
12592 {
12593 printf("Error Statement. Insufficient memory \n");
12594 return RETURN_ERR;
12595 }
developer72fb0bb2023-01-11 09:46:29 +080012596
developer33f13ba2023-07-12 16:19:06 +080012597 res = v_secure_system("iw dev %s station dump > /tmp/AssociatedDevice_Stats.txt", interface_name);
12598 if (res) {
12599 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developer9ce44382023-06-28 11:09:37 +080012600 free(temp);
developere40952c2023-06-15 18:46:43 +080012601 return RETURN_ERR;
12602 }
developer33f13ba2023-07-12 16:19:06 +080012603
developera3511852023-06-14 14:12:59 +080012604 if(apIndex == 0)
developer33f13ba2023-07-12 16:19:06 +080012605 res = v_secure_system("iw dev %s station dump | grep Station >> /tmp/AllAssociated_Devices_2G.txt", interface_name);
developera3511852023-06-14 14:12:59 +080012606 else if(apIndex == 1)
developer33f13ba2023-07-12 16:19:06 +080012607 res = v_secure_system("iw dev %s station dump | grep Station >> /tmp/AllAssociated_Devices_5G.txt", interface_name);
12608 if (res) {
12609 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developer9ce44382023-06-28 11:09:37 +080012610 free(temp);
developere40952c2023-06-15 18:46:43 +080012611 return RETURN_ERR;
12612 }
developer72fb0bb2023-01-11 09:46:29 +080012613
developera3511852023-06-14 14:12:59 +080012614 fp = fopen("/tmp/AssociatedDevice_Stats.txt", "r");
12615 if(fp == NULL)
12616 {
12617 printf("/tmp/AssociatedDevice_Stats.txt not exists \n");
12618 free(temp);
12619 return RETURN_ERR;
12620 }
developere75ba632023-06-29 16:03:33 +080012621 if (fclose(fp) == EOF) {
12622 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
developerc14d83a2023-06-29 20:09:42 +080012623 free(temp);
developere75ba632023-06-29 16:03:33 +080012624 return RETURN_ERR;
12625 }
developer72fb0bb2023-01-11 09:46:29 +080012626
developer33f13ba2023-07-12 16:19:06 +080012627 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep Station | cut -d ' ' -f 2");
developera3511852023-06-14 14:12:59 +080012628 if(fp)
12629 {
12630 for(count =0 ; count < wifi_count; count++)
12631 {
developer86035662023-06-28 19:21:12 +080012632 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12633 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012634 goto err;
developer86035662023-06-28 19:21:12 +080012635 }
developera3511852023-06-14 14:12:59 +080012636 if( MACADDRESS_SIZE == sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5]) )
12637 {
12638 for( wificlientindex = 0; wificlientindex < MACADDRESS_SIZE; ++wificlientindex )
12639 {
12640 mac[wificlientindex] = (unsigned char) arr[wificlientindex];
developer72fb0bb2023-01-11 09:46:29 +080012641
developera3511852023-06-14 14:12:59 +080012642 }
12643 memcpy(temp[count].cli_MACAddress,mac,(sizeof(unsigned char))*6);
12644 printf("MAC %d = %X:%X:%X:%X:%X:%X \n", count, temp[count].cli_MACAddress[0],temp[count].cli_MACAddress[1], temp[count].cli_MACAddress[2], temp[count].cli_MACAddress[3], temp[count].cli_MACAddress[4], temp[count].cli_MACAddress[5]);
12645 }
12646 temp[count].cli_AuthenticationState = 1; //TODO
12647 temp[count].cli_Active = 1; //TODO
12648 }
developer33f13ba2023-07-12 16:19:06 +080012649 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080012650 }
12651
developer33f13ba2023-07-12 16:19:06 +080012652 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep signal | tr -s ' ' | cut -d ' ' -f 2 > /tmp/wifi_signalstrength.txt");
developera3511852023-06-14 14:12:59 +080012653 if(fp)
12654 {
developer33f13ba2023-07-12 16:19:06 +080012655 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012656 }
developer33f13ba2023-07-12 16:19:06 +080012657 fp = v_secure_popen("r", "cat /tmp/wifi_signalstrength.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012658 if(fp)
12659 {
12660 for(count =0 ; count < wifi_count ;count++)
12661 {
developer86035662023-06-28 19:21:12 +080012662 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12663 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012664 goto err;
developer86035662023-06-28 19:21:12 +080012665 }
developera3511852023-06-14 14:12:59 +080012666 signalstrength = atoi(str);
12667 temp[count].cli_SignalStrength = signalstrength;
12668 temp[count].cli_RSSI = signalstrength;
12669 temp[count].cli_SNR = signalstrength + 95;
12670 }
developer33f13ba2023-07-12 16:19:06 +080012671 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012672 }
developer72fb0bb2023-01-11 09:46:29 +080012673
12674
developera3511852023-06-14 14:12:59 +080012675 if((apIndex == 0) || (apIndex == 4))
12676 {
12677 for(count =0 ; count < wifi_count ;count++)
12678 {
developer32f2a182023-06-27 19:50:41 +080012679 memcpy(temp[count].cli_OperatingStandard,"g", 1);
12680 temp[count].cli_OperatingStandard[1] = '\0';
12681 memcpy(temp[count].cli_OperatingChannelBandwidth, "20MHz", 5);
12682 temp[count].cli_OperatingChannelBandwidth[5] = '\0';
developera3511852023-06-14 14:12:59 +080012683 }
developer72fb0bb2023-01-11 09:46:29 +080012684
developera3511852023-06-14 14:12:59 +080012685 //BytesSent
developer33f13ba2023-07-12 16:19:06 +080012686 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'tx bytes' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Bytes_Send.txt");
developera3511852023-06-14 14:12:59 +080012687 if(fp)
12688 {
developer33f13ba2023-07-12 16:19:06 +080012689 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012690 }
developer33f13ba2023-07-12 16:19:06 +080012691 fp = v_secure_popen("r", "cat /tmp/Ass_Bytes_Send.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012692 if(fp)
12693 {
12694 for (count = 0; count < wifi_count; count++)
12695 {
developer86035662023-06-28 19:21:12 +080012696 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12697 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer33f13ba2023-07-12 16:19:06 +080012698 v_secure_pclose(fp);
developerc14d83a2023-06-29 20:09:42 +080012699 free(temp);
developer86035662023-06-28 19:21:12 +080012700 return RETURN_ERR;
developer5b23cd02023-07-19 20:26:03 +080012701 }
developerc14d83a2023-06-29 20:09:42 +080012702 if (hal_strtoul(str, 10, &(temp[count].cli_BytesSent)) < 0) {
12703 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012704 }
developera3511852023-06-14 14:12:59 +080012705 }
developer33f13ba2023-07-12 16:19:06 +080012706 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012707 }
developer72fb0bb2023-01-11 09:46:29 +080012708
developera3511852023-06-14 14:12:59 +080012709 //BytesReceived
developer86035662023-06-28 19:21:12 +080012710
developer33f13ba2023-07-12 16:19:06 +080012711 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'rx bytes' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Bytes_Received.txt");
developera3511852023-06-14 14:12:59 +080012712 if (fp)
12713 {
developer33f13ba2023-07-12 16:19:06 +080012714 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012715 }
developer33f13ba2023-07-12 16:19:06 +080012716 fp = v_secure_popen("r", "cat /tmp/Ass_Bytes_Received.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012717 if (fp)
12718 {
12719 for (count = 0; count < wifi_count; count++)
12720 {
developer86035662023-06-28 19:21:12 +080012721 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12722 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012723 goto err;
12724 }
12725 if (hal_strtoul(str, 10, &(temp[count].cli_BytesReceived)) < 0) {
12726 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012727 }
developera3511852023-06-14 14:12:59 +080012728 }
developer33f13ba2023-07-12 16:19:06 +080012729 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012730 }
developer72fb0bb2023-01-11 09:46:29 +080012731
developera3511852023-06-14 14:12:59 +080012732 //PacketsSent
developer33f13ba2023-07-12 16:19:06 +080012733 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'tx packets' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Packets_Send.txt");
developera3511852023-06-14 14:12:59 +080012734 if (fp)
12735 {
developer33f13ba2023-07-12 16:19:06 +080012736 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012737 }
developer72fb0bb2023-01-11 09:46:29 +080012738
developer33f13ba2023-07-12 16:19:06 +080012739 fp = v_secure_popen("r", "cat /tmp/Ass_Packets_Send.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012740 if (fp)
12741 {
12742 for (count = 0; count < wifi_count; count++)
12743 {
developer86035662023-06-28 19:21:12 +080012744 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12745 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012746 goto err;
developer5b23cd02023-07-19 20:26:03 +080012747 }
developerc14d83a2023-06-29 20:09:42 +080012748 if (hal_strtoul(str, 10, &(temp[count].cli_PacketsSent)) < 0) {
12749 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012750 }
developera3511852023-06-14 14:12:59 +080012751 }
developer33f13ba2023-07-12 16:19:06 +080012752 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012753 }
developer72fb0bb2023-01-11 09:46:29 +080012754
developera3511852023-06-14 14:12:59 +080012755 //PacketsReceived
developer33f13ba2023-07-12 16:19:06 +080012756 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'rx packets' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Packets_Received.txt");
developera3511852023-06-14 14:12:59 +080012757 if (fp)
12758 {
developer33f13ba2023-07-12 16:19:06 +080012759 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012760 }
developer33f13ba2023-07-12 16:19:06 +080012761 fp = v_secure_popen("r", "cat /tmp/Ass_Packets_Received.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012762 if (fp)
12763 {
12764 for (count = 0; count < wifi_count; count++)
12765 {
developer86035662023-06-28 19:21:12 +080012766 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12767 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012768 goto err;
developer5b23cd02023-07-19 20:26:03 +080012769 }
developerc14d83a2023-06-29 20:09:42 +080012770 if (hal_strtoul(str, 10, &(temp[count].cli_PacketsReceived)) < 0) {
12771 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012772 }
developera3511852023-06-14 14:12:59 +080012773 }
developer33f13ba2023-07-12 16:19:06 +080012774 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012775 }
developer72fb0bb2023-01-11 09:46:29 +080012776
developera3511852023-06-14 14:12:59 +080012777 //ErrorsSent
developer33f13ba2023-07-12 16:19:06 +080012778 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'tx failed' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Tx_Failed.txt");
developera3511852023-06-14 14:12:59 +080012779 if (fp)
12780 {
developer33f13ba2023-07-12 16:19:06 +080012781 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012782 }
developer33f13ba2023-07-12 16:19:06 +080012783 fp = v_secure_popen("r", "cat /tmp/Ass_Tx_Failed.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012784 if (fp)
12785 {
12786 for (count = 0; count < wifi_count; count++)
12787 {
developer86035662023-06-28 19:21:12 +080012788 if (fgets(str, MAX_BUF_SIZE, fp) == NULL){
12789 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012790 goto err;
developer5b23cd02023-07-19 20:26:03 +080012791 }
developerc14d83a2023-06-29 20:09:42 +080012792 if (hal_strtoul(str, 10, &(temp[count].cli_ErrorsSent)) < 0) {
12793 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012794 }
developera3511852023-06-14 14:12:59 +080012795 }
developer33f13ba2023-07-12 16:19:06 +080012796 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012797 }
developer72fb0bb2023-01-11 09:46:29 +080012798
developera3511852023-06-14 14:12:59 +080012799 //ErrorsSent
developer86035662023-06-28 19:21:12 +080012800
developer33f13ba2023-07-12 16:19:06 +080012801 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'tx failed' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Tx_Failed.txt");
developera3511852023-06-14 14:12:59 +080012802 if (fp)
12803 {
developer33f13ba2023-07-12 16:19:06 +080012804 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012805 }
developer33f13ba2023-07-12 16:19:06 +080012806 fp = v_secure_popen("r", "cat /tmp/Ass_Tx_Failed.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012807 if (fp)
12808 {
12809 for (count = 0; count < wifi_count; count++)
12810 {
developer86035662023-06-28 19:21:12 +080012811 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12812 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012813 goto err;
developer5b23cd02023-07-19 20:26:03 +080012814 }
developerc14d83a2023-06-29 20:09:42 +080012815 if (hal_strtoul(str, 10, &(temp[count].cli_ErrorsSent)) < 0) {
12816 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012817 }
developera3511852023-06-14 14:12:59 +080012818 }
developer33f13ba2023-07-12 16:19:06 +080012819 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012820 }
developer72fb0bb2023-01-11 09:46:29 +080012821
developera3511852023-06-14 14:12:59 +080012822 //LastDataDownlinkRate
developer33f13ba2023-07-12 16:19:06 +080012823 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'tx bitrate' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Bitrate_Send.txt");
developera3511852023-06-14 14:12:59 +080012824 if (fp)
12825 {
developer33f13ba2023-07-12 16:19:06 +080012826 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012827 }
developer33f13ba2023-07-12 16:19:06 +080012828 fp = v_secure_popen("r", "cat /tmp/Ass_Bitrate_Send.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012829 if (fp)
developer5b23cd02023-07-19 20:26:03 +080012830 {
developerc14d83a2023-06-29 20:09:42 +080012831 unsigned long tmp_u;
developera3511852023-06-14 14:12:59 +080012832 for (count = 0; count < wifi_count; count++)
12833 {
developer86035662023-06-28 19:21:12 +080012834 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12835 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012836 goto err;
12837 }
developer5b23cd02023-07-19 20:26:03 +080012838
developerc14d83a2023-06-29 20:09:42 +080012839 if (hal_strtoul(str, 10, &tmp_u) < 0) {
12840 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012841 }
developerc14d83a2023-06-29 20:09:42 +080012842 temp[count].cli_LastDataDownlinkRate = tmp_u;
developera3511852023-06-14 14:12:59 +080012843 temp[count].cli_LastDataDownlinkRate = (temp[count].cli_LastDataDownlinkRate * 1024); //Mbps -> Kbps
12844 }
developer33f13ba2023-07-12 16:19:06 +080012845 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012846 }
developer72fb0bb2023-01-11 09:46:29 +080012847
developera3511852023-06-14 14:12:59 +080012848 //LastDataUplinkRate
developer33f13ba2023-07-12 16:19:06 +080012849 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'rx bitrate' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Bitrate_Received.txt");
developera3511852023-06-14 14:12:59 +080012850 if (fp)
12851 {
developer33f13ba2023-07-12 16:19:06 +080012852 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012853 }
developer33f13ba2023-07-12 16:19:06 +080012854 fp = v_secure_popen("r", "cat /tmp/Ass_Bitrate_Received.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080012855 if (fp)
12856 {
developerc14d83a2023-06-29 20:09:42 +080012857 unsigned long tmp_u;
developera3511852023-06-14 14:12:59 +080012858 for (count = 0; count < wifi_count; count++)
12859 {
developer86035662023-06-28 19:21:12 +080012860 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
12861 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080012862 goto err;
12863 }
12864 if (hal_strtoul(str, 10, &tmp_u) < 0) {
12865 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer86035662023-06-28 19:21:12 +080012866 }
developerc14d83a2023-06-29 20:09:42 +080012867 temp[count].cli_LastDataUplinkRate = tmp_u;
12868
developera3511852023-06-14 14:12:59 +080012869 temp[count].cli_LastDataUplinkRate = (temp[count].cli_LastDataUplinkRate * 1024); //Mbps -> Kbps
12870 }
developer33f13ba2023-07-12 16:19:06 +080012871 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080012872 }
developer72fb0bb2023-01-11 09:46:29 +080012873
developera3511852023-06-14 14:12:59 +080012874 }
12875 else if ((apIndex == 1) || (apIndex == 5))
12876 {
12877 for (count = 0; count < wifi_count; count++)
12878 {
developer32f2a182023-06-27 19:50:41 +080012879 memcpy(temp[count].cli_OperatingStandard, "a", 1);
12880 temp[count].cli_OperatingStandard[1] = '\0';
12881 memcpy(temp[count].cli_OperatingChannelBandwidth, "20MHz", 5);
12882 temp[count].cli_OperatingChannelBandwidth[5] = '\0';
developera3511852023-06-14 14:12:59 +080012883 temp[count].cli_BytesSent = 0;
12884 temp[count].cli_BytesReceived = 0;
12885 temp[count].cli_LastDataUplinkRate = 0;
12886 temp[count].cli_LastDataDownlinkRate = 0;
12887 temp[count].cli_PacketsSent = 0;
12888 temp[count].cli_PacketsReceived = 0;
12889 temp[count].cli_ErrorsSent = 0;
12890 }
12891 }
developer72fb0bb2023-01-11 09:46:29 +080012892
developera3511852023-06-14 14:12:59 +080012893 for (count = 0; count < wifi_count; count++)
12894 {
12895 temp[count].cli_Retransmissions = 0;
12896 temp[count].cli_DataFramesSentAck = 0;
12897 temp[count].cli_DataFramesSentNoAck = 0;
12898 temp[count].cli_MinRSSI = 0;
12899 temp[count].cli_MaxRSSI = 0;
12900 strncpy(temp[count].cli_InterferenceSources, "", 64);
12901 memset(temp[count].cli_IPAddress, 0, 64);
12902 temp[count].cli_RetransCount = 0;
12903 temp[count].cli_FailedRetransCount = 0;
12904 temp[count].cli_RetryCount = 0;
12905 temp[count].cli_MultipleRetryCount = 0;
12906 }
12907 *associated_dev_array = temp;
12908 }
12909 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
12910 return RETURN_OK;
developerc14d83a2023-06-29 20:09:42 +080012911err:
12912 if (temp)
12913 free(temp);
developer8078acf2023-08-04 18:52:48 +080012914 v_secure_pclose(fp);
developerc14d83a2023-06-29 20:09:42 +080012915 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080012916}
12917
developer7e4a2a62023-04-06 19:56:03 +080012918int wifihal_interfacestatus(CHAR *wifi_status, CHAR *interface_name)
developer72fb0bb2023-01-11 09:46:29 +080012919{
developer7e4a2a62023-04-06 19:56:03 +080012920 char buf[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +080012921 int res;
developer32f2a182023-06-27 19:50:41 +080012922 unsigned long len;
developer72fb0bb2023-01-11 09:46:29 +080012923
developera3511852023-06-14 14:12:59 +080012924 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer7e4a2a62023-04-06 19:56:03 +080012925
developer8078acf2023-08-04 18:52:48 +080012926 res = _syscmd_secure(buf, MAX_BUF_SIZE, "ifconfig %s | grep RUNNING | tr -s ' ' | cut -d ' ' -f4 | tr -d '\\n'",
developer7e4a2a62023-04-06 19:56:03 +080012927 interface_name);
developer8078acf2023-08-04 18:52:48 +080012928 if (res) {
12929 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080012930 }
12931
developer32f2a182023-06-27 19:50:41 +080012932 len = strlen(buf);
12933 if (len >= sizeof(buf)) {
12934 wifi_debug(DEBUG_ERROR, "Unexpected buf size\n");
12935 return RETURN_ERR;
12936 }
12937 strncpy(wifi_status, buf, len); /* TBD: check wifi_status mem lenth and replace with strcpy later */
12938 wifi_status[len] = '\0';
developer72fb0bb2023-01-11 09:46:29 +080012939
developera3511852023-06-14 14:12:59 +080012940 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
12941 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012942}
12943
developer72fb0bb2023-01-11 09:46:29 +080012944static const char *get_line_from_str_buf(const char *buf, char *line)
12945{
developera3511852023-06-14 14:12:59 +080012946 int i;
12947 int n = strlen(buf);
developer72fb0bb2023-01-11 09:46:29 +080012948
developera3511852023-06-14 14:12:59 +080012949 for (i = 0; i < n; i++) {
12950 line[i] = buf[i];
12951 if (buf[i] == '\n') {
12952 line[i] = '\0';
12953 return &buf[i + 1];
12954 }
12955 }
developer72fb0bb2023-01-11 09:46:29 +080012956
developera3511852023-06-14 14:12:59 +080012957 return NULL;
developer72fb0bb2023-01-11 09:46:29 +080012958}
12959
12960INT wifi_getApAssociatedDeviceDiagnosticResult3(INT apIndex, wifi_associated_dev3_t **associated_dev_array, UINT *output_array_size)
12961{
developera3511852023-06-14 14:12:59 +080012962 char interface_name[16] = {0};
12963 FILE *f = NULL;
12964 int auth_temp= -1;
developer8078acf2023-08-04 18:52:48 +080012965 char buf[2048] = {0};
developera3511852023-06-14 14:12:59 +080012966 char *param = NULL, *value = NULL, *line=NULL;
12967 size_t len = 0;
12968 wifi_associated_dev3_t *dev=NULL;
developer75bd10c2023-06-27 11:34:08 +080012969 int res;
developer72fb0bb2023-01-11 09:46:29 +080012970
developera3511852023-06-14 14:12:59 +080012971 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
12972 *associated_dev_array = NULL;
12973 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
12974 return RETURN_ERR;
developer75bd10c2023-06-27 11:34:08 +080012975
developer8078acf2023-08-04 18:52:48 +080012976 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i%s all_sta | grep AUTHORIZED | wc -l", interface_name);
12977 if (res) {
12978 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080012979 }
12980
developera3511852023-06-14 14:12:59 +080012981 *output_array_size = atoi(buf);
developer72fb0bb2023-01-11 09:46:29 +080012982
developera3511852023-06-14 14:12:59 +080012983 if (*output_array_size <= 0)
12984 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080012985
developera3511852023-06-14 14:12:59 +080012986 dev=(wifi_associated_dev3_t *) calloc (*output_array_size, sizeof(wifi_associated_dev3_t));
developer86035662023-06-28 19:21:12 +080012987
12988 if (dev == NULL) {
12989 wifi_debug(DEBUG_ERROR, "calloc fail\n");
12990 return RETURN_ERR;
12991 }
developera3511852023-06-14 14:12:59 +080012992 *associated_dev_array = dev;
developer8078acf2023-08-04 18:52:48 +080012993 res = _syscmd_secure(buf, sizeof(buf),
developer32f2a182023-06-27 19:50:41 +080012994 "hostapd_cli -i%s all_sta > /tmp/diagnostic3_devices.txt" , interface_name);
developer8078acf2023-08-04 18:52:48 +080012995 if (res) {
12996 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developer75bd10c2023-06-27 11:34:08 +080012997 }
12998
developera3511852023-06-14 14:12:59 +080012999 f = fopen("/tmp/diagnostic3_devices.txt", "r");
13000 if (f == NULL)
13001 {
13002 *output_array_size=0;
13003 return RETURN_ERR;
13004 }
13005 while ((getline(&line, &len, f)) != -1)
13006 {
13007 param = strtok(line, "=");
developere75ba632023-06-29 16:03:33 +080013008 if (!param)
13009 continue;
developera3511852023-06-14 14:12:59 +080013010 value = strtok(NULL, "=");
developere75ba632023-06-29 16:03:33 +080013011 if (!value)
13012 continue;
developer72fb0bb2023-01-11 09:46:29 +080013013
developera3511852023-06-14 14:12:59 +080013014 if( strcmp("flags",param) == 0 )
13015 {
13016 value[strlen(value)-1]='\0';
13017 if(strstr (value,"AUTHORIZED") != NULL )
13018 {
13019 auth_temp++;
13020 dev[auth_temp].cli_AuthenticationState = 1;
13021 dev[auth_temp].cli_Active = 1;
13022 }
13023 } else if (auth_temp < 0) {
13024 continue;
13025 } else if( strcmp("dot11RSNAStatsSTAAddress", param) == 0 )
13026 {
13027 value[strlen(value)-1]='\0';
developere75ba632023-06-29 16:03:33 +080013028 if (sscanf(value, "%x:%x:%x:%x:%x:%x",
13029 (unsigned int *)&dev[auth_temp].cli_MACAddress[0],
13030 (unsigned int *)&dev[auth_temp].cli_MACAddress[1],
13031 (unsigned int *)&dev[auth_temp].cli_MACAddress[2],
13032 (unsigned int *)&dev[auth_temp].cli_MACAddress[3],
13033 (unsigned int *)&dev[auth_temp].cli_MACAddress[4],
13034 (unsigned int *)&dev[auth_temp].cli_MACAddress[5]) == EOF)
13035 continue;
developera3511852023-06-14 14:12:59 +080013036 } else if (strcmp("signal", param) == 0) {
13037 value[strlen(value)-1]='\0';
developere75ba632023-06-29 16:03:33 +080013038 if (sscanf(value, "%d", &dev[auth_temp].cli_RSSI) == EOF)
13039 continue;
developera3511852023-06-14 14:12:59 +080013040 dev[auth_temp].cli_SNR = 95 + dev[auth_temp].cli_RSSI;
13041 }
13042 }
developer0d26f2c2023-05-25 19:46:36 +080013043 if (line)
developera3511852023-06-14 14:12:59 +080013044 free(line);
developerc14d83a2023-06-29 20:09:42 +080013045
13046 if (fclose(f) != 0) {
13047 wifi_debug(DEBUG_ERROR, "fclose fail\n");
13048 }
13049
developera3511852023-06-14 14:12:59 +080013050 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
13051 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013052}
developer72fb0bb2023-01-11 09:46:29 +080013053
13054/* getIPAddress function */
13055/**
13056* @description Returning IpAddress of the Matched String
13057*
developer69b61b02023-03-07 17:17:44 +080013058* @param
developer72fb0bb2023-01-11 09:46:29 +080013059* @str Having MacAddress
developer69b61b02023-03-07 17:17:44 +080013060* @ipaddr Having ipaddr
developer72fb0bb2023-01-11 09:46:29 +080013061* @return The status of the operation
13062* @retval RETURN_OK if successful
13063* @retval RETURN_ERR if any error is detected
13064*
13065*/
13066
13067INT getIPAddress(char *str,char *ipaddr)
13068{
developera3511852023-06-14 14:12:59 +080013069 FILE *fp = NULL;
13070 char buf[1024] = {0},ipAddr[50] = {0},phyAddr[100] = {0},hostName[100] = {0};
13071 int LeaseTime = 0,ret = 0;
developer32f2a182023-06-27 19:50:41 +080013072 unsigned long len;
13073
developera3511852023-06-14 14:12:59 +080013074 if ( (fp=fopen("/nvram/dnsmasq.leases", "r")) == NULL )
13075 {
13076 return RETURN_ERR;
13077 }
developer72fb0bb2023-01-11 09:46:29 +080013078
developera3511852023-06-14 14:12:59 +080013079 while ( fgets(buf, sizeof(buf), fp)!= NULL )
13080 {
13081 /*
13082 Sample:sss
13083 1560336751 00:cd:fe:f3:25:e6 10.0.0.153 NallamousiPhone 01:00:cd:fe:f3:25:e6
13084 1560336751 12:34:56:78:9a:bc 10.0.0.154 NallamousiPhone 01:00:cd:fe:f3:25:e6
13085 */
13086 ret = sscanf(buf, LM_DHCP_CLIENT_FORMAT,
13087 &(LeaseTime),
13088 phyAddr,
13089 ipAddr,
13090 hostName
13091 );
13092 if(ret != 4)
13093 continue;
developer32f2a182023-06-27 19:50:41 +080013094 if (strcmp(str,phyAddr) == 0) {
13095 len = strlen(ipAddr);
13096 strncpy(ipaddr, ipAddr, len);
13097 ipaddr[len] = '\0';
13098 }
developera3511852023-06-14 14:12:59 +080013099 }
developer37646972023-06-29 10:58:43 +080013100 if (fclose(fp) == EOF) {
13101 wifi_debug(DEBUG_ERROR, "fclose fail\n");
13102 return RETURN_ERR;
13103 }
developera3511852023-06-14 14:12:59 +080013104 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013105}
13106
13107/* wifi_getApInactiveAssociatedDeviceDiagnosticResult function */
13108/**
13109* @description Returning Inactive wireless connected clients informations
13110*
developer69b61b02023-03-07 17:17:44 +080013111* @param
developer72fb0bb2023-01-11 09:46:29 +080013112* @filename Holding private_wifi 2g/5g content files
13113* @associated_dev_array Having inactiv wireless clients informations
13114* @output_array_size Returning Inactive wireless counts
13115* @return The status of the operation
13116* @retval RETURN_OK if successful
13117* @retval RETURN_ERR if any error is detected
13118*
13119*/
13120
13121INT wifi_getApInactiveAssociatedDeviceDiagnosticResult(char *filename,wifi_associated_dev3_t **associated_dev_array, UINT *output_array_size)
13122{
developera3511852023-06-14 14:12:59 +080013123 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
13124 int count = 0,maccount = 0,i = 0,wificlientindex = 0;
13125 FILE *fp = NULL;
13126 int arr[MACADDRESS_SIZE] = {0};
13127 unsigned char mac[MACADDRESS_SIZE] = {0};
13128 char path[1024] = {0},str[1024] = {0},ipaddr[50] = {0},buf[512] = {0};
developer86035662023-06-28 19:21:12 +080013129 int res;
13130
developer8078acf2023-08-04 18:52:48 +080013131
13132
13133
13134
13135
13136 fp = v_secure_popen("r","cat %s | grep Station | sort | uniq | wc -l",filename);
developera3511852023-06-14 14:12:59 +080013137 if(fp == NULL)
13138 return RETURN_ERR;
13139 else
13140 {
developerd14dff12023-06-28 22:47:44 +080013141 if (fgets(path,sizeof(path),fp) == NULL) {
13142 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080013143 v_secure_pclose(fp);
developerd14dff12023-06-28 22:47:44 +080013144 return RETURN_ERR;
13145 }
developera3511852023-06-14 14:12:59 +080013146 maccount = atoi(path);
13147 }
developer8078acf2023-08-04 18:52:48 +080013148 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080013149 *output_array_size = maccount;
13150 wifi_associated_dev3_t* temp = NULL;
developer9ce44382023-06-28 11:09:37 +080013151 if(*output_array_size > 0 && *output_array_size < MAX_ASSOCIATED_STA_NUM){
13152 temp = (wifi_associated_dev3_t *) calloc (*output_array_size, sizeof(wifi_associated_dev3_t));
13153 } else {
13154 return RETURN_ERR;
13155 }
developer37646972023-06-29 10:58:43 +080013156
developera3511852023-06-14 14:12:59 +080013157 *associated_dev_array = temp;
13158 if(temp == NULL)
13159 {
13160 printf("Error Statement. Insufficient memory \n");
13161 return RETURN_ERR;
13162 }
13163 memset(buf,0,sizeof(buf));
developer32f2a182023-06-27 19:50:41 +080013164 res = snprintf(buf, sizeof(buf),
13165 "cat %s | grep Station | cut -d ' ' -f2 | sort | uniq",filename);
13166 if (os_snprintf_error(sizeof(buf), res)) {
13167 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13168 return RETURN_ERR;
13169 }
developer8078acf2023-08-04 18:52:48 +080013170 fp = v_secure_popen("r", "cat %s | grep Station | cut -d ' ' -f2 | sort | uniq",filename);
developera3511852023-06-14 14:12:59 +080013171 if (fp == NULL) {
developer37646972023-06-29 10:58:43 +080013172 res = fprintf(stderr, "%s: failed pipe command %s.\n", __func__, buf);
13173 if (res < 0) {
13174 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
13175 }
developera3511852023-06-14 14:12:59 +080013176 return RETURN_ERR;
13177 }
13178 for(count = 0; count < maccount ; count++)
13179 {
developer37646972023-06-29 10:58:43 +080013180 if (fgets(path,sizeof(path),fp) == NULL)
13181 continue;
developera3511852023-06-14 14:12:59 +080013182 for(i = 0; path[i]!='\n';i++)
13183 str[i]=path[i];
13184 str[i]='\0';
13185 getIPAddress(str,ipaddr);
developera3511852023-06-14 14:12:59 +080013186 if(strlen(ipaddr) > 0)
13187 {
developer33f13ba2023-07-12 16:19:06 +080013188 if (v_secure_system("ping -q -c 1 -W 1 \"%s\" > /dev/null 2>&1", ipaddr)) //InActive wireless clients info
developera3511852023-06-14 14:12:59 +080013189 {
13190 if( MACADDRESS_SIZE == sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5]) )
13191 {
13192 for( wificlientindex = 0; wificlientindex < MACADDRESS_SIZE; ++wificlientindex )
13193 {
13194 mac[wificlientindex] = (unsigned char) arr[wificlientindex];
developer72fb0bb2023-01-11 09:46:29 +080013195
developera3511852023-06-14 14:12:59 +080013196 }
13197 memcpy(temp[count].cli_MACAddress,mac,(sizeof(unsigned char))*6);
developer37646972023-06-29 10:58:43 +080013198 if (fprintf(stderr,"%sMAC %d = %X:%X:%X:%X:%X:%X \n", __FUNCTION__,count, temp[count].cli_MACAddress[0],
13199 temp[count].cli_MACAddress[1], temp[count].cli_MACAddress[2],
13200 temp[count].cli_MACAddress[3], temp[count].cli_MACAddress[4],
13201 temp[count].cli_MACAddress[5]) < 0) {
13202 wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
13203 break;
13204 }
developera3511852023-06-14 14:12:59 +080013205 }
13206 temp[count].cli_AuthenticationState = 0; //TODO
13207 temp[count].cli_Active = 0; //TODO
13208 temp[count].cli_SignalStrength = 0;
13209 }
13210 else //Active wireless clients info
13211 {
13212 if( MACADDRESS_SIZE == sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5]) )
13213 {
13214 for( wificlientindex = 0; wificlientindex < MACADDRESS_SIZE; ++wificlientindex )
13215 {
13216 mac[wificlientindex] = (unsigned char) arr[wificlientindex];
developer72fb0bb2023-01-11 09:46:29 +080013217
developera3511852023-06-14 14:12:59 +080013218 }
13219 memcpy(temp[count].cli_MACAddress,mac,(sizeof(unsigned char))*6);
developer12fb9f62023-06-30 15:26:27 +080013220 wifi_debug(DEBUG_ERROR, "%sMAC %d = %X:%X:%X:%X:%X:%X \n", __FUNCTION__,count, temp[count].cli_MACAddress[0],temp[count].cli_MACAddress[1], temp[count].cli_MACAddress[2], temp[count].cli_MACAddress[3], temp[count].cli_MACAddress[4], temp[count].cli_MACAddress[5]);
developera3511852023-06-14 14:12:59 +080013221 }
13222 temp[count].cli_Active = 1;
13223 }
13224 }
13225 memset(ipaddr,0,sizeof(ipaddr));
13226 }
developer8078acf2023-08-04 18:52:48 +080013227 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080013228 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
13229 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013230}
13231//Device.WiFi.X_RDKCENTRAL-COM_BandSteering object
13232//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.Capability bool r/o
13233//To get Band Steering Capability
13234INT wifi_getBandSteeringCapability(BOOL *support)
13235{
developera3511852023-06-14 14:12:59 +080013236 *support = FALSE;
13237 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013238}
13239
13240
13241//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.Enable bool r/w
13242//To get Band Steering enable status
13243INT wifi_getBandSteeringEnable(BOOL *enable)
13244{
developera3511852023-06-14 14:12:59 +080013245 *enable = FALSE;
13246 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013247}
13248
13249//To turn on/off Band steering
13250INT wifi_setBandSteeringEnable(BOOL enable)
13251{
developera3511852023-06-14 14:12:59 +080013252 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013253}
13254
13255//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.APGroup string r/w
13256//To get Band Steering AP group
13257INT wifi_getBandSteeringApGroup(char *output_ApGroup)
13258{
developera3511852023-06-14 14:12:59 +080013259 if (NULL == output_ApGroup)
13260 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013261
developer32f2a182023-06-27 19:50:41 +080013262 memcpy(output_ApGroup, "1,2", 3);
13263 output_ApGroup[3] = '\0';
developera3511852023-06-14 14:12:59 +080013264 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013265}
13266
13267//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.BandSetting.{i}.UtilizationThreshold int r/w
13268//to set and read the band steering BandUtilizationThreshold parameters
13269INT wifi_getBandSteeringBandUtilizationThreshold (INT radioIndex, INT *pBuThreshold)
13270{
developera3511852023-06-14 14:12:59 +080013271 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013272}
13273
13274INT wifi_setBandSteeringBandUtilizationThreshold (INT radioIndex, INT buThreshold)
13275{
developera3511852023-06-14 14:12:59 +080013276 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013277}
13278
13279//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.BandSetting.{i}.RSSIThreshold int r/w
13280//to set and read the band steering RSSIThreshold parameters
13281INT wifi_getBandSteeringRSSIThreshold (INT radioIndex, INT *pRssiThreshold)
13282{
developera3511852023-06-14 14:12:59 +080013283 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013284}
13285
13286INT wifi_setBandSteeringRSSIThreshold (INT radioIndex, INT rssiThreshold)
13287{
developera3511852023-06-14 14:12:59 +080013288 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013289}
13290
13291
13292//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.BandSetting.{i}.PhyRateThreshold int r/w
13293//to set and read the band steering physical modulation rate threshold parameters
13294INT wifi_getBandSteeringPhyRateThreshold (INT radioIndex, INT *pPrThreshold)
13295{
developera3511852023-06-14 14:12:59 +080013296 //If chip is not support, return -1
13297 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013298}
13299
13300INT wifi_setBandSteeringPhyRateThreshold (INT radioIndex, INT prThreshold)
13301{
developera3511852023-06-14 14:12:59 +080013302 //If chip is not support, return -1
13303 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013304}
13305
13306//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.BandSetting.{i}.OverloadInactiveTime int r/w
13307//to set and read the inactivity time (in seconds) for steering under overload condition
13308INT wifi_getBandSteeringOverloadInactiveTime(INT radioIndex, INT *pPrThreshold)
13309{
developera3511852023-06-14 14:12:59 +080013310 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013311}
13312
13313INT wifi_setBandSteeringOverloadInactiveTime(INT radioIndex, INT prThreshold)
13314{
developera3511852023-06-14 14:12:59 +080013315 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013316}
13317
13318//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.BandSetting.{i}.IdleInactiveTime int r/w
13319//to set and read the inactivity time (in seconds) for steering under Idle condition
13320INT wifi_getBandSteeringIdleInactiveTime(INT radioIndex, INT *pPrThreshold)
13321{
developera3511852023-06-14 14:12:59 +080013322 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013323}
13324
13325INT wifi_setBandSteeringIdleInactiveTime(INT radioIndex, INT prThreshold)
13326{
developera3511852023-06-14 14:12:59 +080013327 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013328}
13329
13330//Device.WiFi.X_RDKCENTRAL-COM_BandSteering.History string r/o
13331//pClientMAC[64]
13332//pSourceSSIDIndex[64]
13333//pDestSSIDIndex[64]
13334//pSteeringReason[256]
13335INT wifi_getBandSteeringLog(INT record_index, ULONG *pSteeringTime, CHAR *pClientMAC, INT *pSourceSSIDIndex, INT *pDestSSIDIndex, INT *pSteeringReason)
13336{
developera3511852023-06-14 14:12:59 +080013337 //if no steering or redord_index is out of boundary, return -1. pSteeringTime returns the UTC time in seconds. pClientMAC is pre allocated as 64bytes. pSteeringReason returns the predefined steering trigger reason
developer12fb9f62023-06-30 15:26:27 +080013338 long int tim_tmp = time(NULL);
13339 if (tim_tmp < 0)
13340 return RETURN_ERR;
13341 *pSteeringTime = tim_tmp;
developera3511852023-06-14 14:12:59 +080013342 *pSteeringReason = 0; //TODO: need to assign correct steering reason (INT numeric, i suppose)
13343 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013344}
13345
13346INT wifi_ifConfigDown(INT apIndex)
13347{
developera3511852023-06-14 14:12:59 +080013348 INT status = RETURN_OK;
13349 char cmd[64];
developere40952c2023-06-15 18:46:43 +080013350 int res;
developer72fb0bb2023-01-11 09:46:29 +080013351
developer33f13ba2023-07-12 16:19:06 +080013352 res = v_secure_system("ifconfig ath%d down", apIndex);
13353 if (res) {
13354 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developere40952c2023-06-15 18:46:43 +080013355 return RETURN_ERR;
13356 }
developera3511852023-06-14 14:12:59 +080013357 printf("%s: %s\n", __func__, cmd);
developer72fb0bb2023-01-11 09:46:29 +080013358
developera3511852023-06-14 14:12:59 +080013359 return status;
developer72fb0bb2023-01-11 09:46:29 +080013360}
13361
13362INT wifi_ifConfigUp(INT apIndex)
13363{
developera3511852023-06-14 14:12:59 +080013364 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +080013365 char buf[1024];
developere40952c2023-06-15 18:46:43 +080013366 int res;
developer72fb0bb2023-01-11 09:46:29 +080013367
developera3511852023-06-14 14:12:59 +080013368 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
13369 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080013370 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up 2>/dev/null", interface_name);
13371 if (res) {
13372 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080013373 }
developera3511852023-06-14 14:12:59 +080013374 return 0;
developer72fb0bb2023-01-11 09:46:29 +080013375}
13376
13377//>> Deprecated. Replace with wifi_applyRadioSettings
13378INT wifi_pushBridgeInfo(INT apIndex)
13379{
developerb2977562023-05-24 17:54:12 +080013380 char ip[32] = {0};
13381 char subnet[32] = {0};
13382 char bridge[32] = {0};
developerb2977562023-05-24 17:54:12 +080013383 char buf[1024] = {0};
developere40952c2023-06-15 18:46:43 +080013384 int res;
developer72fb0bb2023-01-11 09:46:29 +080013385
developerb2977562023-05-24 17:54:12 +080013386 wifi_getApBridgeInfo(apIndex, bridge, ip, subnet);
developer72fb0bb2023-01-11 09:46:29 +080013387
developer8078acf2023-08-04 18:52:48 +080013388 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s %s netmask %s ", bridge, ip, subnet);
13389 if (res) {
13390 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080013391 }
developer72fb0bb2023-01-11 09:46:29 +080013392
developerb2977562023-05-24 17:54:12 +080013393 return 0;
developer72fb0bb2023-01-11 09:46:29 +080013394}
13395
13396INT wifi_pushChannel(INT radioIndex, UINT channel)
13397{
developera3511852023-06-14 14:12:59 +080013398 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +080013399 char buf[1024];
developere40952c2023-06-15 18:46:43 +080013400 int res;
developer72fb0bb2023-01-11 09:46:29 +080013401
developera3511852023-06-14 14:12:59 +080013402 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
13403 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080013404 res = _syscmd_secure(buf, sizeof(buf), "iwconfig %s freq %d",interface_name,channel);
13405 if (res) {
13406 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080013407 }
developer72fb0bb2023-01-11 09:46:29 +080013408
developera3511852023-06-14 14:12:59 +080013409 return 0;
developer72fb0bb2023-01-11 09:46:29 +080013410}
13411
13412INT wifi_pushChannelMode(INT radioIndex)
13413{
developera3511852023-06-14 14:12:59 +080013414 //Apply Channel mode, pure mode, etc that been set by wifi_setRadioChannelMode() instantly
13415 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013416}
13417
13418INT wifi_pushDefaultValues(INT radioIndex)
13419{
developera3511852023-06-14 14:12:59 +080013420 //Apply Comcast specified default radio settings instantly
13421 //AMPDU=1
13422 //AMPDUFrames=32
13423 //AMPDULim=50000
13424 //txqueuelen=1000
developer72fb0bb2023-01-11 09:46:29 +080013425
developera3511852023-06-14 14:12:59 +080013426 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013427}
13428
13429INT wifi_pushTxChainMask(INT radioIndex)
13430{
developera3511852023-06-14 14:12:59 +080013431 //Apply default TxChainMask instantly
13432 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013433}
13434
13435INT wifi_pushRxChainMask(INT radioIndex)
13436{
developera3511852023-06-14 14:12:59 +080013437 //Apply default RxChainMask instantly
13438 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013439}
13440
13441INT wifi_pushSSID(INT apIndex, CHAR *ssid)
13442{
developer7e4a2a62023-04-06 19:56:03 +080013443 INT status;
developer72fb0bb2023-01-11 09:46:29 +080013444
developer7e4a2a62023-04-06 19:56:03 +080013445 status = wifi_setSSIDName(apIndex, ssid);
13446 wifi_quick_reload_ap(apIndex);
developer72fb0bb2023-01-11 09:46:29 +080013447
developer7e4a2a62023-04-06 19:56:03 +080013448 return status;
developer72fb0bb2023-01-11 09:46:29 +080013449}
13450
13451INT wifi_pushSsidAdvertisementEnable(INT apIndex, BOOL enable)
13452{
developera3511852023-06-14 14:12:59 +080013453 int ret;
developerc1aa6532023-06-09 09:37:01 +080013454 ret = wifi_setApSsidAdvertisementEnable(apIndex, enable);
13455
13456 return ret;
developer72fb0bb2023-01-11 09:46:29 +080013457}
13458
13459INT wifi_getRadioUpTime(INT radioIndex, ULONG *output)
13460{
developera3511852023-06-14 14:12:59 +080013461 time_t now;
developere82c0ca2023-05-10 16:25:35 +080013462
developerd14dff12023-06-28 22:47:44 +080013463 now = time(NULL);
13464 if (now < 0) {
13465 wifi_debug(DEBUG_ERROR, "GET time fail\n");
13466 return RETURN_ERR;
13467 }
developere82c0ca2023-05-10 16:25:35 +080013468 if (now > radio_up_time[radioIndex])
13469 *output = now - radio_up_time[radioIndex];
13470 else {
13471 *output = 0;
13472 return RETURN_ERR;
13473 }
13474
developera3511852023-06-14 14:12:59 +080013475 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013476}
13477
13478INT wifi_getApEnableOnLine(INT wlanIndex, BOOL *enabled)
13479{
developera3511852023-06-14 14:12:59 +080013480 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013481}
13482
13483INT wifi_getApSecurityWpaRekeyInterval(INT apIndex, INT *output_int)
13484{
developera3511852023-06-14 14:12:59 +080013485 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013486}
13487
13488//To-do
13489INT wifi_getApSecurityMFPConfig(INT apIndex, CHAR *output_string)
13490{
developera3511852023-06-14 14:12:59 +080013491 char output[16]={'\0'};
13492 char config_file[MAX_BUF_SIZE] = {0};
13493 int res;
developer72fb0bb2023-01-11 09:46:29 +080013494
developera3511852023-06-14 14:12:59 +080013495 if (!output_string)
13496 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013497
developera3511852023-06-14 14:12:59 +080013498 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
13499 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080013500 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13501 return RETURN_ERR;
13502 }
developera3511852023-06-14 14:12:59 +080013503 wifi_hostapdRead(config_file, "ieee80211w", output, sizeof(output));
developer72fb0bb2023-01-11 09:46:29 +080013504
developera3511852023-06-14 14:12:59 +080013505 if (strlen(output) == 0)
developere40952c2023-06-15 18:46:43 +080013506 res = snprintf(output_string, 64, "Disabled");
developera3511852023-06-14 14:12:59 +080013507 else if (strncmp(output, "0", 1) == 0)
developere40952c2023-06-15 18:46:43 +080013508 res = snprintf(output_string, 64, "Disabled");
developera3511852023-06-14 14:12:59 +080013509 else if (strncmp(output, "1", 1) == 0)
developere40952c2023-06-15 18:46:43 +080013510 res = snprintf(output_string, 64, "Optional");
developera3511852023-06-14 14:12:59 +080013511 else if (strncmp(output, "2", 1) == 0)
developere40952c2023-06-15 18:46:43 +080013512 res = snprintf(output_string, 64, "Required");
developera3511852023-06-14 14:12:59 +080013513 else {
13514 wifi_dbg_printf("\n[%s]: Unexpected ieee80211w=%s", __func__, output);
13515 return RETURN_ERR;
13516 }
developere40952c2023-06-15 18:46:43 +080013517 if (os_snprintf_error(64, res)) {
13518 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13519 return RETURN_ERR;
13520 }
developer72fb0bb2023-01-11 09:46:29 +080013521
developera3511852023-06-14 14:12:59 +080013522 wifi_dbg_printf("\n[%s]: ieee80211w is : %s", __func__, output);
13523 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013524}
13525INT wifi_setApSecurityMFPConfig(INT apIndex, CHAR *MfpConfig)
13526{
developera3511852023-06-14 14:12:59 +080013527 struct params params;
13528 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +080013529 int res;
developer9f2358c2023-09-22 18:42:12 +080013530 bool temp_multiple_set = multiple_set;
developer72fb0bb2023-01-11 09:46:29 +080013531
developera3511852023-06-14 14:12:59 +080013532 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
13533 if(NULL == MfpConfig || strlen(MfpConfig) >= 32 )
13534 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013535
developera3511852023-06-14 14:12:59 +080013536 params.name = "ieee80211w";
13537 if (strncmp(MfpConfig, "Disabled", strlen("Disabled")) == 0)
13538 params.value = "0";
13539 else if (strncmp(MfpConfig, "Optional", strlen("Optional")) == 0)
13540 params.value = "1";
13541 else if (strncmp(MfpConfig, "Required", strlen("Required")) == 0)
13542 params.value = "2";
13543 else{
13544 wifi_dbg_printf("%s: invalid MfpConfig. Input has to be Disabled, Optional or Required \n", __func__);
13545 return RETURN_ERR;
13546 }
developer75bd10c2023-06-27 11:34:08 +080013547
13548 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
13549 if (os_snprintf_error(sizeof(config_file), res)) {
13550 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13551 return RETURN_ERR;
13552 }
13553
developera3511852023-06-14 14:12:59 +080013554 wifi_hostapdWrite(config_file, &params, 1);
developer9f2358c2023-09-22 18:42:12 +080013555 multiple_set = false;
13556 wifi_hostapdProcessUpdate(apIndex, &params, 1);
13557 wifi_quick_reload_ap(apIndex);
13558 multiple_set = temp_multiple_set;
13559
developera3511852023-06-14 14:12:59 +080013560 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
13561 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013562}
13563INT wifi_getRadioAutoChannelEnable(INT radioIndex, BOOL *output_bool)
13564{
developera3511852023-06-14 14:12:59 +080013565 char output[16]={'\0'};
13566 char config_file[MAX_BUF_SIZE] = {0};
13567 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +080013568 int res;
developer72fb0bb2023-01-11 09:46:29 +080013569
developera3511852023-06-14 14:12:59 +080013570 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
13571 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +080013572 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
13573 if (os_snprintf_error(sizeof(config_file), res)) {
13574 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13575 return RETURN_ERR;
13576 }
developera3511852023-06-14 14:12:59 +080013577 wifi_datfileRead(config_file, "AutoChannelSelect" , output, sizeof(output));
developer72fb0bb2023-01-11 09:46:29 +080013578
developera3511852023-06-14 14:12:59 +080013579 if (strncmp(output, "0", 1) == 0)
13580 *output_bool = FALSE;
13581 else if (strncmp(output, "1", 1) == 0)
13582 *output_bool = TRUE;
13583 else if (strncmp(output, "2", 1) == 0)
13584 *output_bool = TRUE;
13585 else if (strncmp(output, "3", 1) == 0)
13586 *output_bool = TRUE;
13587 else
13588 *output_bool = FALSE;
13589 WIFI_ENTRY_EXIT_DEBUG("Exit %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080013590
developera3511852023-06-14 14:12:59 +080013591 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013592}
13593
13594INT wifi_getRouterEnable(INT wlanIndex, BOOL *enabled)
13595{
developera3511852023-06-14 14:12:59 +080013596 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013597}
13598
13599INT wifi_setApSecurityWpaRekeyInterval(INT apIndex, INT *rekeyInterval)
13600{
developera3511852023-06-14 14:12:59 +080013601 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013602}
13603
13604INT wifi_setRouterEnable(INT wlanIndex, INT *RouterEnabled)
13605{
developera3511852023-06-14 14:12:59 +080013606 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013607}
13608
13609INT wifi_getRadioSupportedDataTransmitRates(INT wlanIndex,CHAR *output)
13610{
developera3511852023-06-14 14:12:59 +080013611 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
13612 char config_file[MAX_BUF_SIZE] = {0};
developer32f2a182023-06-27 19:50:41 +080013613 char tmp_output[MAX_BUF_SIZE] = {0};
developera3511852023-06-14 14:12:59 +080013614 int res;
developer72fb0bb2023-01-11 09:46:29 +080013615
developera3511852023-06-14 14:12:59 +080013616 if (NULL == output)
13617 return RETURN_ERR;
13618 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,wlanIndex);
13619 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080013620 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13621 return RETURN_ERR;
13622 }
developera3511852023-06-14 14:12:59 +080013623 wifi_hostapdRead(config_file,"hw_mode",output,64);
developer72fb0bb2023-01-11 09:46:29 +080013624
developer32f2a182023-06-27 19:50:41 +080013625 if(strcmp(output,"b")==0) {
13626 res = snprintf(tmp_output, sizeof(tmp_output), "%s", "1,2,5.5,11");
13627 if (os_snprintf_error(sizeof(tmp_output), res)) {
13628 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13629 return RETURN_ERR;
13630 }
13631 } else if (strcmp(output,"a")==0) {
13632 res = snprintf(tmp_output, sizeof(tmp_output), "%s", "6,9,11,12,18,24,36,48,54");
13633 if (os_snprintf_error(sizeof(tmp_output), res)) {
13634 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13635 return RETURN_ERR;
developer5b23cd02023-07-19 20:26:03 +080013636 }
developer32f2a182023-06-27 19:50:41 +080013637 } else if ((strcmp(output,"n")==0) | (strcmp(output,"g")==0)) {
13638 res = snprintf(tmp_output, sizeof(tmp_output), "%s", "1,2,5.5,6,9,11,12,18,24,36,48,54");
13639 if (os_snprintf_error(sizeof(tmp_output), res)) {
13640 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13641 return RETURN_ERR;
13642 }
developer75bd10c2023-06-27 11:34:08 +080013643 }
developer32f2a182023-06-27 19:50:41 +080013644 memcpy(output, tmp_output, strlen(tmp_output));
13645 output[strlen(tmp_output)] = '\0';
developer72fb0bb2023-01-11 09:46:29 +080013646
developera3511852023-06-14 14:12:59 +080013647 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
13648 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013649}
13650
13651INT wifi_getRadioOperationalDataTransmitRates(INT wlanIndex,CHAR *output)
13652{
developera3511852023-06-14 14:12:59 +080013653 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
13654 char *temp;
developer32f2a182023-06-27 19:50:41 +080013655 char temp_output[128] = {0};
13656 char temp_TransmitRates[128] = {0};
developera3511852023-06-14 14:12:59 +080013657 char config_file[MAX_BUF_SIZE] = {0};
13658 int res;
developer32f2a182023-06-27 19:50:41 +080013659 unsigned long len;
developer72fb0bb2023-01-11 09:46:29 +080013660
developera3511852023-06-14 14:12:59 +080013661 if (NULL == output)
13662 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080013663
developera3511852023-06-14 14:12:59 +080013664 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,wlanIndex);
13665 if (os_snprintf_error(sizeof(config_file), res)) {
developer46506162023-06-12 10:09:39 +080013666 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13667 return RETURN_ERR;
13668 }
developera3511852023-06-14 14:12:59 +080013669 wifi_hostapdRead(config_file,"supported_rates",output,64);
developer72fb0bb2023-01-11 09:46:29 +080013670
developera3511852023-06-14 14:12:59 +080013671 if (strlen(output) == 0) {
13672 wifi_getRadioSupportedDataTransmitRates(wlanIndex, output);
13673 return RETURN_OK;
13674 }
developer32f2a182023-06-27 19:50:41 +080013675 len = strlen(output);
13676 if (len >= sizeof(temp_TransmitRates)) {
13677 wifi_debug(DEBUG_ERROR, "Unexpected strlen(output)\n");
13678 return RETURN_ERR;
13679 }
13680 strncpy(temp_TransmitRates, output, len);
developera3511852023-06-14 14:12:59 +080013681 temp = strtok(temp_TransmitRates," ");
13682 while(temp!=NULL)
13683 {
13684 temp[strlen(temp)-1]=0;
13685 if((temp[0]=='5') && (temp[1]=='\0'))
13686 {
13687 temp="5.5";
13688 }
developer32f2a182023-06-27 19:50:41 +080013689 if ((sizeof(temp_output) - strlen(temp_output)) <= strlen(temp)) {
13690 wifi_debug(DEBUG_ERROR, "not enough room in temp_output\n");
13691 return RETURN_ERR;
13692 }
13693 strncat(temp_output, temp, sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +080013694 temp = strtok(NULL," ");
13695 if(temp!=NULL)
13696 {
developer32f2a182023-06-27 19:50:41 +080013697 if ((sizeof(temp_output) - strlen(temp_output)) <= 1) {
13698 wifi_debug(DEBUG_ERROR, "not enough room in temp_output\n");
13699 return RETURN_ERR;
13700 }
13701 strncat(temp_output, ",", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +080013702 }
13703 }
developer32f2a182023-06-27 19:50:41 +080013704 len = strlen(temp_output);
13705 strncpy(output, temp_output, len);
13706 output[len] = '\0';
developera3511852023-06-14 14:12:59 +080013707 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080013708
developera3511852023-06-14 14:12:59 +080013709 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013710}
13711
13712INT wifi_setRadioSupportedDataTransmitRates(INT wlanIndex,CHAR *output)
13713{
developera3511852023-06-14 14:12:59 +080013714 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013715}
13716
13717
13718INT wifi_setRadioOperationalDataTransmitRates(INT wlanIndex,CHAR *output)
13719{
developera3511852023-06-14 14:12:59 +080013720 int i=0;
13721 char *temp;
13722 char temp1[128] = {0};
13723 char temp_output[128] = {0};
13724 char temp_TransmitRates[128] = {0};
13725 struct params params={'\0'};
13726 char config_file[MAX_BUF_SIZE] = {0};
13727 wifi_band band = wifi_index_to_band(wlanIndex);
developer32f2a182023-06-27 19:50:41 +080013728 unsigned long len;
13729 int res;
developer9f2358c2023-09-22 18:42:12 +080013730 bool temp_multiple_set = multiple_set;
developer72fb0bb2023-01-11 09:46:29 +080013731
developera3511852023-06-14 14:12:59 +080013732 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
13733 if(NULL == output)
13734 return RETURN_ERR;
developer32f2a182023-06-27 19:50:41 +080013735
13736 len = strlen(output);
13737 if (len >= sizeof(temp_TransmitRates)) {
13738 wifi_debug(DEBUG_ERROR, "not enough room in temp_TransmitRates\n");
13739 return RETURN_ERR;
13740 }
13741 strncpy(temp_TransmitRates, output, len);
13742 temp_TransmitRates[len] = '\0';
developer72fb0bb2023-01-11 09:46:29 +080013743
developera3511852023-06-14 14:12:59 +080013744 for(i=0;i<strlen(temp_TransmitRates);i++)
13745 {
13746 if (((temp_TransmitRates[i]>='0') && (temp_TransmitRates[i]<='9')) || (temp_TransmitRates[i]==' ') || (temp_TransmitRates[i]=='.') || (temp_TransmitRates[i]==','))
13747 {
13748 continue;
13749 }
13750 else
13751 {
13752 return RETURN_ERR;
13753 }
13754 }
developera3511852023-06-14 14:12:59 +080013755 temp = strtok(temp_TransmitRates,",");
13756 while(temp!=NULL)
13757 {
developer32f2a182023-06-27 19:50:41 +080013758 len = strlen(temp);
13759 if (len >= sizeof(temp1)) {
13760 wifi_debug(DEBUG_ERROR, "not enough room in temp1\n");
13761 return RETURN_ERR;
13762 }
13763 strncpy(temp1, temp, len);
13764 temp1[len] = '\0';
developera3511852023-06-14 14:12:59 +080013765 if(band == band_5)
13766 {
13767 if((strcmp(temp,"1")==0) || (strcmp(temp,"2")==0) || (strcmp(temp,"5.5")==0))
13768 {
13769 return RETURN_ERR;
13770 }
13771 }
developer72fb0bb2023-01-11 09:46:29 +080013772
developer32f2a182023-06-27 19:50:41 +080013773 if(strcmp(temp,"5.5")==0) {
13774 strncpy(temp1, "55", 2);
13775 temp1[2] = '\0';
13776 } else {
13777 if ((sizeof(temp1) - strlen(temp1)) <= 1) {
13778 wifi_debug(DEBUG_ERROR, "not enough room in temp1\n");
13779 return RETURN_ERR;
13780 }
13781 strncat(temp1, "0", sizeof(temp1) - strlen(temp1) - 1);
developera3511852023-06-14 14:12:59 +080013782 }
developer5b23cd02023-07-19 20:26:03 +080013783
developer32f2a182023-06-27 19:50:41 +080013784 if ((sizeof(temp_output) - strlen(temp_output)) <= strlen(temp1)) {
13785 wifi_debug(DEBUG_ERROR, "not enough room in temp_output\n");
13786 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +080013787 }
developer32f2a182023-06-27 19:50:41 +080013788 strncat(temp_output, temp1, sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +080013789 temp = strtok(NULL,",");
13790 if(temp!=NULL)
13791 {
developer32f2a182023-06-27 19:50:41 +080013792 if ((sizeof(temp_output) - strlen(temp_output)) <= 1) {
13793 wifi_debug(DEBUG_ERROR, "not enough room in temp1\n");
13794 return RETURN_ERR;
13795 }
13796 strncat(temp_output, " ", sizeof(temp_output) - strlen(temp_output) - 1);
developera3511852023-06-14 14:12:59 +080013797 }
13798 }
developer32f2a182023-06-27 19:50:41 +080013799 len = strlen(temp_output);
13800 strncpy(output, temp_output, len);
13801 output[len] = '\0';
developer72fb0bb2023-01-11 09:46:29 +080013802
developera3511852023-06-14 14:12:59 +080013803 params.name = "supported_rates";
13804 params.value = output;
developer72fb0bb2023-01-11 09:46:29 +080013805
developera3511852023-06-14 14:12:59 +080013806 wifi_dbg_printf("\n%s:",__func__);
13807 wifi_dbg_printf("params.value=%s\n",params.value);
developer32f2a182023-06-27 19:50:41 +080013808 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,wlanIndex);
13809 if (os_snprintf_error(sizeof(config_file), res)) {
13810 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
13811 return RETURN_ERR;
developer5b23cd02023-07-19 20:26:03 +080013812 }
developer9f2358c2023-09-22 18:42:12 +080013813
developera3511852023-06-14 14:12:59 +080013814 wifi_hostapdWrite(config_file,&params,1);
developer9f2358c2023-09-22 18:42:12 +080013815 multiple_set = false;
13816 wifi_hostapdProcessUpdate(wlanIndex, &params, 1);
13817 wifi_quick_reload_ap(wlanIndex);
13818 multiple_set = temp_multiple_set;
13819
developera3511852023-06-14 14:12:59 +080013820 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080013821
developera3511852023-06-14 14:12:59 +080013822 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080013823}
13824
13825
13826static char *sncopy(char *dst, int dst_sz, const char *src)
13827{
developera3511852023-06-14 14:12:59 +080013828 if (src && dst && dst_sz > 0) {
13829 strncpy(dst, src, dst_sz);
13830 dst[dst_sz - 1] = '\0';
13831 }
13832 return dst;
developer72fb0bb2023-01-11 09:46:29 +080013833}
13834
13835static int util_get_sec_chan_offset(int channel, const char* ht_mode)
13836{
developera3511852023-06-14 14:12:59 +080013837 if (0 == strcmp(ht_mode, "HT40") ||
13838 0 == strcmp(ht_mode, "HT80") ||
13839 0 == strcmp(ht_mode, "HT160")) {
13840 switch (channel) {
13841 case 1 ... 7:
13842 case 36:
13843 case 44:
13844 case 52:
13845 case 60:
13846 case 100:
13847 case 108:
13848 case 116:
13849 case 124:
13850 case 132:
13851 case 140:
13852 case 149:
13853 case 157:
13854 return 1;
13855 case 8 ... 13:
13856 case 40:
13857 case 48:
13858 case 56:
13859 case 64:
13860 case 104:
13861 case 112:
13862 case 120:
13863 case 128:
13864 case 136:
13865 case 144:
13866 case 153:
13867 case 161:
13868 return -1;
13869 default:
13870 return -EINVAL;
13871 }
13872 }
developer72fb0bb2023-01-11 09:46:29 +080013873
developera3511852023-06-14 14:12:59 +080013874 return -EINVAL;
developer72fb0bb2023-01-11 09:46:29 +080013875}
13876
13877static int util_get_6g_sec_chan_offset(int channel, const char* ht_mode)
13878{
developera3511852023-06-14 14:12:59 +080013879 int idx = channel%8;
13880 if (0 == strcmp(ht_mode, "HT40") ||
13881 0 == strcmp(ht_mode, "HT80") ||
13882 0 == strcmp(ht_mode, "HT160")) {
13883 switch (idx) {
13884 case 1:
13885 return 1;
13886 case 5:
13887 return -1;
13888 default:
13889 return -EINVAL;
13890 }
13891 }
developer72fb0bb2023-01-11 09:46:29 +080013892
developera3511852023-06-14 14:12:59 +080013893 return -EINVAL;
developer72fb0bb2023-01-11 09:46:29 +080013894}
13895static void util_hw_mode_to_bw_mode(const char* hw_mode, char *bw_mode, int bw_mode_len)
13896{
developera3511852023-06-14 14:12:59 +080013897 if (NULL == hw_mode) return;
developer72fb0bb2023-01-11 09:46:29 +080013898
developera3511852023-06-14 14:12:59 +080013899 if (0 == strcmp(hw_mode, "ac"))
13900 sncopy(bw_mode, bw_mode_len, "ht vht");
developer72fb0bb2023-01-11 09:46:29 +080013901
developera3511852023-06-14 14:12:59 +080013902 if (0 == strcmp(hw_mode, "n"))
13903 sncopy(bw_mode, bw_mode_len, "ht");
developer72fb0bb2023-01-11 09:46:29 +080013904
developera3511852023-06-14 14:12:59 +080013905 return;
developer72fb0bb2023-01-11 09:46:29 +080013906}
13907
13908static int util_chan_to_freq(int chan)
13909{
developera3511852023-06-14 14:12:59 +080013910 if (chan == 14)
13911 return 2484;
13912 else if (chan < 14)
13913 return 2407 + chan * 5;
13914 else if (chan >= 182 && chan <= 196)
13915 return 4000 + chan * 5;
13916 else
13917 return 5000 + chan * 5;
13918 return 0;
developer72fb0bb2023-01-11 09:46:29 +080013919}
13920
13921static int util_6G_chan_to_freq(int chan)
13922{
developera3511852023-06-14 14:12:59 +080013923 if (chan)
13924 return 5950 + chan * 5;
13925 else
13926 return 0;
developer69b61b02023-03-07 17:17:44 +080013927
developer72fb0bb2023-01-11 09:46:29 +080013928}
13929const int *util_unii_5g_chan2list(int chan, int width)
13930{
developera3511852023-06-14 14:12:59 +080013931 static const int lists[] = {
13932 // <width>, <chan1>, <chan2>..., 0,
13933 20, 36, 0,
13934 20, 40, 0,
13935 20, 44, 0,
13936 20, 48, 0,
13937 20, 52, 0,
13938 20, 56, 0,
13939 20, 60, 0,
13940 20, 64, 0,
13941 20, 100, 0,
13942 20, 104, 0,
13943 20, 108, 0,
13944 20, 112, 0,
13945 20, 116, 0,
13946 20, 120, 0,
13947 20, 124, 0,
13948 20, 128, 0,
13949 20, 132, 0,
13950 20, 136, 0,
13951 20, 140, 0,
13952 20, 144, 0,
13953 20, 149, 0,
13954 20, 153, 0,
13955 20, 157, 0,
13956 20, 161, 0,
13957 20, 165, 0,
13958 40, 36, 40, 0,
13959 40, 44, 48, 0,
13960 40, 52, 56, 0,
13961 40, 60, 64, 0,
13962 40, 100, 104, 0,
13963 40, 108, 112, 0,
13964 40, 116, 120, 0,
13965 40, 124, 128, 0,
13966 40, 132, 136, 0,
13967 40, 140, 144, 0,
13968 40, 149, 153, 0,
13969 40, 157, 161, 0,
13970 80, 36, 40, 44, 48, 0,
13971 80, 52, 56, 60, 64, 0,
13972 80, 100, 104, 108, 112, 0,
13973 80, 116, 120, 124, 128, 0,
13974 80, 132, 136, 140, 144, 0,
13975 80, 149, 153, 157, 161, 0,
13976 160, 36, 40, 44, 48, 52, 56, 60, 64, 0,
13977 160, 100, 104, 108, 112, 116, 120, 124, 128, 0,
13978 -1 // final delimiter
13979 };
13980 const int *start;
13981 const int *p;
developer72fb0bb2023-01-11 09:46:29 +080013982
developera3511852023-06-14 14:12:59 +080013983 for (p = lists; *p != -1; p++) {
13984 if (*p == width) {
13985 for (start = ++p; *p != 0; p++) {
13986 if (*p == chan)
13987 return start;
13988 }
13989 }
13990 // move to the end of channel list of given width
13991 while (*p != 0) {
13992 p++;
13993 }
13994 }
developer72fb0bb2023-01-11 09:46:29 +080013995
developera3511852023-06-14 14:12:59 +080013996 return NULL;
developer72fb0bb2023-01-11 09:46:29 +080013997}
13998
13999static int util_unii_5g_centerfreq(const char *ht_mode, int channel)
14000{
developera3511852023-06-14 14:12:59 +080014001 if (NULL == ht_mode)
14002 return 0;
developer72fb0bb2023-01-11 09:46:29 +080014003
developera3511852023-06-14 14:12:59 +080014004 const int width = atoi(strlen(ht_mode) > 2 ? ht_mode + 2 : "20");
14005 const int *chans = util_unii_5g_chan2list(channel, width);
14006 int sum = 0;
14007 int cnt = 0;
developer72fb0bb2023-01-11 09:46:29 +080014008
developera3511852023-06-14 14:12:59 +080014009 if (NULL == chans)
14010 return 0;
developer72fb0bb2023-01-11 09:46:29 +080014011
developera3511852023-06-14 14:12:59 +080014012 while (*chans) {
14013 sum += *chans;
14014 cnt++;
14015 chans++;
14016 }
14017 if (cnt == 0)
14018 return 0;
14019 return sum / cnt;
developer72fb0bb2023-01-11 09:46:29 +080014020}
14021
14022static int util_unii_6g_centerfreq(const char *ht_mode, int channel)
14023{
developerc14d83a2023-06-29 20:09:42 +080014024 long int width;
developera3511852023-06-14 14:12:59 +080014025 int idx = 0 ;
14026 int centerchan = 0;
14027 int chan_ofs = 1;
developer72fb0bb2023-01-11 09:46:29 +080014028
developerc14d83a2023-06-29 20:09:42 +080014029 if (NULL == ht_mode)
14030 return 0;
14031
14032 if (hal_strtol((char *)(ht_mode + 2), 10, &width) < 0) {
14033 wifi_debug(DEBUG_ERROR, "strtol fail\n");
14034 }
14035
developera3511852023-06-14 14:12:59 +080014036 if (width == 40){
14037 idx = ((channel/4) + chan_ofs)%2;
14038 switch (idx) {
14039 case 0:
14040 centerchan = (channel - 2);
14041 break;
14042 case 1:
14043 centerchan = (channel + 2);
14044 break;
14045 default:
14046 return -EINVAL;
14047 }
14048 }else if (width == 80){
14049 idx = ((channel/4) + chan_ofs)%4;
14050 switch (idx) {
14051 case 0:
14052 centerchan = (channel - 6);
14053 break;
14054 case 1:
14055 centerchan = (channel + 6);
14056 break;
14057 case 2:
14058 centerchan = (channel + 2);
14059 break;
14060 case 3:
14061 centerchan = (channel - 2);
14062 break;
14063 default:
14064 return -EINVAL;
14065 }
14066 }else if (width == 160){
14067 switch (channel) {
14068 case 1 ... 29:
14069 centerchan = 15;
14070 break;
14071 case 33 ... 61:
14072 centerchan = 47;
14073 break;
14074 case 65 ... 93:
14075 centerchan = 79;
14076 break;
14077 case 97 ... 125:
14078 centerchan = 111;
14079 break;
14080 case 129 ... 157:
14081 centerchan = 143;
14082 break;
14083 case 161 ... 189:
14084 centerchan = 175;
14085 break;
14086 case 193 ... 221:
14087 centerchan = 207;
14088 break;
14089 default:
14090 return -EINVAL;
14091 }
14092 }
14093 return centerchan;
developer72fb0bb2023-01-11 09:46:29 +080014094}
14095static int util_radio_get_hw_mode(int radioIndex, char *hw_mode, int hw_mode_size)
14096{
developera3511852023-06-14 14:12:59 +080014097 BOOL onlyG, onlyN, onlyA;
14098 CHAR tmp[64];
14099 int ret = wifi_getRadioStandard(radioIndex, tmp, &onlyG, &onlyN, &onlyA);
14100 if (ret == RETURN_OK) {
14101 sncopy(hw_mode, hw_mode_size, tmp);
14102 }
14103 return ret;
developer72fb0bb2023-01-11 09:46:29 +080014104}
14105
14106INT wifi_pushRadioChannel2(INT radioIndex, UINT channel, UINT channel_width_MHz, UINT csa_beacon_count)
14107{
developera3511852023-06-14 14:12:59 +080014108 // Sample commands:
14109 // hostapd_cli -i wifi1 chan_switch 30 5200 sec_channel_offset=-1 center_freq1=5190 bandwidth=40 ht vht
14110 // hostapd_cli -i wifi0 chan_switch 30 2437
14111 int ret = 0;
14112 char center_freq1_str[32] = ""; // center_freq1=%d
14113 char opt_chan_info_str[32] = ""; // bandwidth=%d ht vht
14114 char sec_chan_offset_str[32] = ""; // sec_channel_offset=%d
14115 char hw_mode[16] = ""; // n|ac
14116 char bw_mode[16] = ""; // ht|ht vht
14117 char ht_mode[16] = ""; // HT20|HT40|HT80|HT160
14118 char interface_name[16] = {0};
14119 int sec_chan_offset;
14120 int width;
14121 char config_file[64] = {0};
14122 char *ext_str = "None";
14123 wifi_band band = band_invalid;
14124 int center_chan = 0;
14125 int center_freq1 = 0;
developere40952c2023-06-15 18:46:43 +080014126 int res;
developer72fb0bb2023-01-11 09:46:29 +080014127
developere40952c2023-06-15 18:46:43 +080014128 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
14129 if (os_snprintf_error(sizeof(config_file), res)) {
14130 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14131 return RETURN_ERR;
14132 }
developer72fb0bb2023-01-11 09:46:29 +080014133
developera3511852023-06-14 14:12:59 +080014134 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
14135 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080014136
developera3511852023-06-14 14:12:59 +080014137 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080014138
developera3511852023-06-14 14:12:59 +080014139 band = wifi_index_to_band(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +080014140
developera3511852023-06-14 14:12:59 +080014141 width = channel_width_MHz > 20 ? channel_width_MHz : 20;
developer72fb0bb2023-01-11 09:46:29 +080014142
developera3511852023-06-14 14:12:59 +080014143 // Get radio mode HT20|HT40|HT80 etc.
14144 if (channel){
developere40952c2023-06-15 18:46:43 +080014145 res = snprintf(ht_mode, sizeof(ht_mode), "HT%d", width);
14146 if (os_snprintf_error(sizeof(ht_mode), res)) {
14147 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14148 return RETURN_ERR;
14149 }
developer72fb0bb2023-01-11 09:46:29 +080014150
developera3511852023-06-14 14:12:59 +080014151 // Provide bandwith if specified
14152 if (channel_width_MHz > 20) {
14153 // Select bandwidth mode from hardware n --> ht | ac --> ht vht
14154 util_radio_get_hw_mode(radioIndex, hw_mode, sizeof(hw_mode));
14155 util_hw_mode_to_bw_mode(hw_mode, bw_mode, sizeof(bw_mode));
developer72fb0bb2023-01-11 09:46:29 +080014156
developere40952c2023-06-15 18:46:43 +080014157 res = snprintf(opt_chan_info_str, sizeof(opt_chan_info_str), "bandwidth=%d %s", width, bw_mode);
developera3511852023-06-14 14:12:59 +080014158 }else if (channel_width_MHz == 20){
developere40952c2023-06-15 18:46:43 +080014159 res = snprintf(opt_chan_info_str, sizeof(opt_chan_info_str), "bandwidth=%d ht", width);
developera3511852023-06-14 14:12:59 +080014160 }
developer72fb0bb2023-01-11 09:46:29 +080014161
developere40952c2023-06-15 18:46:43 +080014162 if (os_snprintf_error(sizeof(opt_chan_info_str), res)) {
14163 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14164 return RETURN_ERR;
14165 }
developer72fb0bb2023-01-11 09:46:29 +080014166
developera3511852023-06-14 14:12:59 +080014167 if (channel_width_MHz > 20) {
14168 if (band == band_6){
14169 center_chan = util_unii_6g_centerfreq(ht_mode, channel);
14170 if(center_chan){
14171 center_freq1 = util_6G_chan_to_freq(center_chan);
14172 }
14173 }else{
14174 center_chan = util_unii_5g_centerfreq(ht_mode, channel);
14175 if(center_chan){
14176 center_freq1 = util_chan_to_freq(center_chan);
14177 }
14178 }
developer69b61b02023-03-07 17:17:44 +080014179
developera3511852023-06-14 14:12:59 +080014180 if (center_freq1)
developere40952c2023-06-15 18:46:43 +080014181 res = snprintf(center_freq1_str, sizeof(center_freq1_str), "center_freq1=%d", center_freq1);
developer69b61b02023-03-07 17:17:44 +080014182
developera3511852023-06-14 14:12:59 +080014183 }
developere40952c2023-06-15 18:46:43 +080014184 if (os_snprintf_error(sizeof(center_freq1_str), res)) {
14185 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14186 return RETURN_ERR;
14187 }
developer72fb0bb2023-01-11 09:46:29 +080014188
developera3511852023-06-14 14:12:59 +080014189 // Find channel offset +1/-1 for wide modes (HT40|HT80|HT160)
14190 if (band == band_6){
14191 sec_chan_offset = util_get_6g_sec_chan_offset(channel, ht_mode);
14192 }else{
14193 sec_chan_offset = util_get_sec_chan_offset(channel, ht_mode);
14194 }
developere40952c2023-06-15 18:46:43 +080014195 if (sec_chan_offset != -EINVAL) {
14196 res = snprintf(sec_chan_offset_str, sizeof(sec_chan_offset_str), "sec_channel_offset=%d", sec_chan_offset);
14197 if (os_snprintf_error(sizeof(sec_chan_offset_str), res)) {
14198 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14199 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080014200 }
developere40952c2023-06-15 18:46:43 +080014201 }
developera3511852023-06-14 14:12:59 +080014202 // Only the first AP, other are hanging on the same radio
developera3511852023-06-14 14:12:59 +080014203 /* wifi_dbg_printf("execute: '%s'\n", cmd);
14204 ret = _syscmd(cmd, buf, sizeof(buf));
14205 wifi_reloadAp(radioIndex); */
developer72fb0bb2023-01-11 09:46:29 +080014206
developera3511852023-06-14 14:12:59 +080014207 ret = wifi_setRadioChannel(radioIndex, channel);
14208 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080014209 wifi_debug(DEBUG_ERROR,"wifi_setRadioChannel return error.\n");
developera3511852023-06-14 14:12:59 +080014210 return RETURN_ERR;
14211 }
developer72fb0bb2023-01-11 09:46:29 +080014212
developera3511852023-06-14 14:12:59 +080014213 if (sec_chan_offset == 1)
14214 ext_str = "Above";
14215 else if (sec_chan_offset == -1)
14216 ext_str = "Below";
developer72fb0bb2023-01-11 09:46:29 +080014217
developera3511852023-06-14 14:12:59 +080014218 /*wifi_setRadioCenterChannel(radioIndex, center_chan); */
developer72fb0bb2023-01-11 09:46:29 +080014219
developera3511852023-06-14 14:12:59 +080014220 } else {
14221 if (channel_width_MHz > 20)
14222 ext_str = "Above";
14223 }
developer72fb0bb2023-01-11 09:46:29 +080014224
developera3511852023-06-14 14:12:59 +080014225 wifi_setRadioExtChannel(radioIndex, ext_str);
developer72fb0bb2023-01-11 09:46:29 +080014226
developera3511852023-06-14 14:12:59 +080014227 char mhz_str[16];
developere40952c2023-06-15 18:46:43 +080014228 res = snprintf(mhz_str, sizeof(mhz_str), "%dMHz", width);
14229 if (os_snprintf_error(sizeof(mhz_str), res)) {
14230 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14231 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080014232 }
developera3511852023-06-14 14:12:59 +080014233 wifi_setRadioOperatingChannelBandwidth(radioIndex, mhz_str);
developer72fb0bb2023-01-11 09:46:29 +080014234
developera3511852023-06-14 14:12:59 +080014235 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080014236
developera3511852023-06-14 14:12:59 +080014237 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080014238}
14239
14240INT wifi_getNeighboringWiFiStatus(INT radio_index, wifi_neighbor_ap2_t **neighbor_ap_array, UINT *output_array_size)
14241{
developera3511852023-06-14 14:12:59 +080014242 int index = -1;
14243 wifi_neighbor_ap2_t *scan_array = NULL;
14244 char cmd[256]={0};
14245 char buf[128]={0};
14246 char file_name[32] = {0};
14247 char filter_SSID[32] = {0};
14248 char line[256] = {0};
14249 char interface_name[16] = {0};
14250 char *ret = NULL;
14251 int freq=0;
14252 FILE *f = NULL;
developer86035662023-06-28 19:21:12 +080014253 long int channels_num = 0;
developera3511852023-06-14 14:12:59 +080014254 int vht_channel_width = 0;
14255 int get_noise_ret = RETURN_ERR;
14256 bool filter_enable = false;
14257 bool filter_BSS = false; // The flag determine whether the BSS information need to be filterd.
14258 int phyId = 0;
developere40952c2023-06-15 18:46:43 +080014259 int res;
developer32f2a182023-06-27 19:50:41 +080014260 unsigned long len;
developerb14b3462023-07-01 18:02:42 +080014261 struct channels_noise *channels_noise_arr = NULL;
developer72fb0bb2023-01-11 09:46:29 +080014262
developera3511852023-06-14 14:12:59 +080014263 WIFI_ENTRY_EXIT_DEBUG("Inside %s: %d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080014264
developere40952c2023-06-15 18:46:43 +080014265 res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, radio_index);
14266 if (os_snprintf_error(sizeof(file_name), res)) {
14267 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14268 return RETURN_ERR;
developer5b23cd02023-07-19 20:26:03 +080014269 }
developera3511852023-06-14 14:12:59 +080014270 f = fopen(file_name, "r");
14271 if (f != NULL) {
developer86035662023-06-28 19:21:12 +080014272 if (fgets(filter_SSID, sizeof(file_name), f) == NULL) {
14273 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developerc14d83a2023-06-29 20:09:42 +080014274 if (fclose(f) != 0) {
14275 wifi_debug(DEBUG_ERROR, "fclose fail\n");
14276 }
developer86035662023-06-28 19:21:12 +080014277 return RETURN_ERR;
14278 }
developera3511852023-06-14 14:12:59 +080014279 if (strlen(filter_SSID) != 0)
14280 filter_enable = true;
developerd14dff12023-06-28 22:47:44 +080014281 if (fclose(f) != 0) {
14282 wifi_debug(DEBUG_ERROR, "fclose fail\n");
14283 return RETURN_ERR;
14284 }
developera3511852023-06-14 14:12:59 +080014285 }
developer72fb0bb2023-01-11 09:46:29 +080014286
developera3511852023-06-14 14:12:59 +080014287 if (wifi_GetInterfaceName(radio_index, interface_name) != RETURN_OK)
14288 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080014289
developera3511852023-06-14 14:12:59 +080014290 phyId = radio_index_to_phy(radio_index);
developer72fb0bb2023-01-11 09:46:29 +080014291
developer8078acf2023-08-04 18:52:48 +080014292 res = _syscmd_secure(buf, sizeof(buf), "iw phy phy%d channels | grep * | grep -v disable | wc -l", phyId);
14293 if (res) {
14294 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080014295 }
developer86035662023-06-28 19:21:12 +080014296 if (hal_strtol(buf, 10, &channels_num) < 0) {
14297 wifi_debug(DEBUG_ERROR, "strtol fail\n");
14298 return RETURN_ERR;
14299 }
developer72fb0bb2023-01-11 09:46:29 +080014300
developer5b23cd02023-07-19 20:26:03 +080014301 res = snprintf(cmd, sizeof(cmd), "iw dev %s scan | grep '%s\\|SSID\\|freq\\|beacon interval\\|capabilities\\|signal\\|Supported rates\\|DTIM\\| \
developera3511852023-06-14 14:12:59 +080014302 // WPA\\|RSN\\|Group cipher\\|HT operation\\|secondary channel offset\\|channel width\\|HE.*GHz' | grep -v -e '*.*BSS'", interface_name, interface_name);
developer32f2a182023-06-27 19:50:41 +080014303 if (os_snprintf_error(sizeof(cmd), res)) {
14304 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14305 return RETURN_ERR;
developer5b23cd02023-07-19 20:26:03 +080014306 }
developer32f2a182023-06-27 19:50:41 +080014307
developer86035662023-06-28 19:21:12 +080014308 wifi_debug(DEBUG_ERROR, "cmd: %s\n", cmd);
developer8078acf2023-08-04 18:52:48 +080014309
14310 f = v_secure_popen("r", "iw dev %s scan | grep '%s\\|SSID\\|freq\\|beacon interval\\|capabilities\\|signal\\|Supported rates\\|DTIM\\| \
14311 // WPA\\|RSN\\|Group cipher\\|HT operation\\|secondary channel offset\\|channel width\\|HE.*GHz' | grep -v -e '*.*BSS'", interface_name, interface_name);
14312
14313 if (f == NULL) {
14314 wifi_dbg_printf("%s: v_secure_popen %s error\n", __func__, cmd);
developera3511852023-06-14 14:12:59 +080014315 return RETURN_ERR;
14316 }
developer69b61b02023-03-07 17:17:44 +080014317
developerb14b3462023-07-01 18:02:42 +080014318 if (channels_num > 0 && channels_num <= 243) {
14319 channels_noise_arr = calloc(channels_num, sizeof(struct channels_noise));
developer86035662023-06-28 19:21:12 +080014320
developerb14b3462023-07-01 18:02:42 +080014321 if (channels_noise_arr == NULL) {
14322 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14323 goto err;
14324 }
14325 get_noise_ret = get_noise(radio_index, channels_noise_arr, channels_num);
developer9ce44382023-06-28 11:09:37 +080014326 }
developer86035662023-06-28 19:21:12 +080014327
developera3511852023-06-14 14:12:59 +080014328 ret = fgets(line, sizeof(line), f);
14329 while (ret != NULL) {
14330 if(strstr(line, "BSS") != NULL) { // new neighbor info
14331 // The SSID field is not in the first field. So, we should store whole BSS informations and the filter flag.
14332 // And we will determine whether we need the previous BSS infomation when parsing the next BSS field or end of while loop.
14333 // If we don't want the BSS info, we don't realloc more space, and just clean the previous BSS.
developer72fb0bb2023-01-11 09:46:29 +080014334
developera3511852023-06-14 14:12:59 +080014335 if (!filter_BSS) {
14336 index++;
developer5b23cd02023-07-19 20:26:03 +080014337 wifi_debug(DEBUG_OFF, "index=%d\n", index);
developera3511852023-06-14 14:12:59 +080014338 wifi_neighbor_ap2_t *tmp;
14339 tmp = realloc(scan_array, sizeof(wifi_neighbor_ap2_t)*(index+1));
14340 if (tmp == NULL) { // no more memory to use
14341 index--;
14342 wifi_dbg_printf("%s: realloc failed\n", __func__);
14343 break;
14344 }
14345 scan_array = tmp;
14346 }
14347 memset(&(scan_array[index]), 0, sizeof(wifi_neighbor_ap2_t));
developer72fb0bb2023-01-11 09:46:29 +080014348
developera3511852023-06-14 14:12:59 +080014349 filter_BSS = false;
developer86035662023-06-28 19:21:12 +080014350 if (sscanf(line, "BSS %17s", scan_array[index].ap_BSSID) != 1) {
14351 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14352 goto err;
14353 }
developerc79e9172023-06-06 19:48:03 +080014354 memset(scan_array[index].ap_Mode, 0, sizeof(scan_array[index].ap_Mode));
developera3511852023-06-14 14:12:59 +080014355 memcpy(scan_array[index].ap_Mode, "Infrastructure", strlen("Infrastructure"));
developerc79e9172023-06-06 19:48:03 +080014356 memset(scan_array[index].ap_SecurityModeEnabled, 0, sizeof(scan_array[index].ap_SecurityModeEnabled));
developera3511852023-06-14 14:12:59 +080014357 memcpy(scan_array[index].ap_SecurityModeEnabled, "None", strlen("None"));
developerc79e9172023-06-06 19:48:03 +080014358 memset(scan_array[index].ap_EncryptionMode, 0, sizeof(scan_array[index].ap_EncryptionMode));
developera3511852023-06-14 14:12:59 +080014359 memcpy(scan_array[index].ap_EncryptionMode, "None", strlen("None"));
14360 } else if (strstr(line, "freq") != NULL) {
developer86035662023-06-28 19:21:12 +080014361 if (sscanf(line," freq: %d", &freq) != 1) {
14362 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
developerb14b3462023-07-01 18:02:42 +080014363 //goto err;
developer86035662023-06-28 19:21:12 +080014364 }
developera3511852023-06-14 14:12:59 +080014365 scan_array[index].ap_Channel = ieee80211_frequency_to_channel(freq);
developer72fb0bb2023-01-11 09:46:29 +080014366
developera3511852023-06-14 14:12:59 +080014367 if (freq >= 2412 && freq <= 2484) {
developerc79e9172023-06-06 19:48:03 +080014368 memset(scan_array[index].ap_OperatingFrequencyBand, 0, sizeof(scan_array[index].ap_OperatingFrequencyBand));
developera3511852023-06-14 14:12:59 +080014369 memcpy(scan_array[index].ap_OperatingFrequencyBand, "2.4GHz", strlen("2.4GHz"));
developerc79e9172023-06-06 19:48:03 +080014370 memset(scan_array[index].ap_SupportedStandards, 0, sizeof(scan_array[index].ap_SupportedStandards));
developera3511852023-06-14 14:12:59 +080014371 memcpy(scan_array[index].ap_SupportedStandards, "b,g", strlen("b,g"));
developerc79e9172023-06-06 19:48:03 +080014372 memset(scan_array[index].ap_OperatingStandards, 0, sizeof(scan_array[index].ap_OperatingStandards));
developera3511852023-06-14 14:12:59 +080014373 memcpy(scan_array[index].ap_OperatingStandards, "g", strlen("g"));
14374 }
14375 else if (freq >= 5160 && freq <= 5805) {
developerc79e9172023-06-06 19:48:03 +080014376 memset(scan_array[index].ap_OperatingFrequencyBand, 0, sizeof(scan_array[index].ap_OperatingFrequencyBand));
developera3511852023-06-14 14:12:59 +080014377 memcpy(scan_array[index].ap_OperatingFrequencyBand, "5GHz", strlen("5GHz"));
developerc79e9172023-06-06 19:48:03 +080014378 memset(scan_array[index].ap_SupportedStandards, 0, sizeof(scan_array[index].ap_SupportedStandards));
developera3511852023-06-14 14:12:59 +080014379 memcpy(scan_array[index].ap_SupportedStandards, "a", strlen("a"));
developerc79e9172023-06-06 19:48:03 +080014380 memset(scan_array[index].ap_OperatingStandards, 0, sizeof(scan_array[index].ap_OperatingStandards));
developera3511852023-06-14 14:12:59 +080014381 memcpy(scan_array[index].ap_OperatingStandards, "a", strlen("a"));
14382 }
developer72fb0bb2023-01-11 09:46:29 +080014383
developera3511852023-06-14 14:12:59 +080014384 scan_array[index].ap_Noise = 0;
14385 if (get_noise_ret == RETURN_OK) {
14386 for (int i = 0; i < channels_num; i++) {
14387 if (scan_array[index].ap_Channel == channels_noise_arr[i].channel) {
14388 scan_array[index].ap_Noise = channels_noise_arr[i].noise;
14389 break;
14390 }
14391 }
14392 }
14393 } else if (strstr(line, "beacon interval") != NULL) {
developer86035662023-06-28 19:21:12 +080014394 if (sscanf(line," beacon interval: %d TUs", &(scan_array[index].ap_BeaconPeriod)) != 1) {
14395 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14396 goto err;
14397 }
developera3511852023-06-14 14:12:59 +080014398 } else if (strstr(line, "signal") != NULL) {
developer86035662023-06-28 19:21:12 +080014399 if (sscanf(line," signal: %d", &(scan_array[index].ap_SignalStrength)) != 1) {
14400 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14401 goto err;
14402 }
developer5b23cd02023-07-19 20:26:03 +080014403 } else if (strstr(line,"SSID:") != NULL) {
14404 int i;
14405 char *new_line = NULL;
14406
14407 for (i = 0; line[i] == '\t'; i++) {
14408 ;
developer86035662023-06-28 19:21:12 +080014409 }
developer5b23cd02023-07-19 20:26:03 +080014410 new_line = &line[i];
14411
14412 if (strncmp(new_line, "SSID: \n", strlen("SSID: \n")) == 0) {
14413 ret = fgets(line, sizeof(line), f);
14414 continue;
14415 }
14416 if (strstr(new_line, "HESSID") == NULL) {
14417 if (sscanf(new_line, "SSID: %63s", scan_array[index].ap_SSID) != 1) {
14418 wifi_debug(DEBUG_ERROR, "sscanf fail, index = %d\n", index);
14419 goto err;
14420 } else
14421 wifi_debug(DEBUG_ERROR, "index = %d, ssid=%s\n", index, scan_array[index].ap_SSID);
14422 if (filter_enable && strcmp(scan_array[index].ap_SSID, filter_SSID) == 0) {
14423 filter_BSS = true;
14424 }
developera3511852023-06-14 14:12:59 +080014425 }
14426 } else if (strstr(line, "Supported rates") != NULL) {
14427 char SRate[80] = {0}, *tmp = NULL;
14428 memset(buf, 0, sizeof(buf));
developer32f2a182023-06-27 19:50:41 +080014429 len = strlen(line);
14430 if (len >= sizeof(SRate)) {
14431 wifi_debug(DEBUG_ERROR, "not enough room in SRate\n");
developer86035662023-06-28 19:21:12 +080014432 goto err;
developer32f2a182023-06-27 19:50:41 +080014433 }
14434 strncpy(SRate, line, len);
developera3511852023-06-14 14:12:59 +080014435 tmp = strtok(SRate, ":");
developer86035662023-06-28 19:21:12 +080014436 if (tmp == NULL)
14437 goto err;
developera3511852023-06-14 14:12:59 +080014438 tmp = strtok(NULL, ":");
developer5b23cd02023-07-19 20:26:03 +080014439 if (tmp == NULL)
developer86035662023-06-28 19:21:12 +080014440 goto err;
developer5b23cd02023-07-19 20:26:03 +080014441
developer32f2a182023-06-27 19:50:41 +080014442 len = strlen(tmp);
14443 if (len >= sizeof(buf)) {
14444 wifi_debug(DEBUG_ERROR, "not enough room in buf\n");
developer86035662023-06-28 19:21:12 +080014445 goto err;
developer32f2a182023-06-27 19:50:41 +080014446 }
14447 strncpy(buf, tmp, len);
developera3511852023-06-14 14:12:59 +080014448 memset(SRate, 0, sizeof(SRate));
developer72fb0bb2023-01-11 09:46:29 +080014449
developera3511852023-06-14 14:12:59 +080014450 tmp = strtok(buf, " \n");
14451 while (tmp != NULL) {
developer32f2a182023-06-27 19:50:41 +080014452 if ((sizeof(SRate) - strlen(SRate)) <= strlen(tmp)) {
14453 wifi_debug(DEBUG_ERROR, "not enough room in SRate\n");
developer86035662023-06-28 19:21:12 +080014454 goto err;
developer32f2a182023-06-27 19:50:41 +080014455 }
14456 strncat(SRate, tmp, sizeof(SRate) - strlen(SRate) - 1);
developera3511852023-06-14 14:12:59 +080014457 if (SRate[strlen(SRate) - 1] == '*') {
14458 SRate[strlen(SRate) - 1] = '\0';
14459 }
developer32f2a182023-06-27 19:50:41 +080014460 if ((sizeof(SRate) - strlen(SRate)) <= 1) {
14461 wifi_debug(DEBUG_ERROR, "not enough room in SRate\n");
developer86035662023-06-28 19:21:12 +080014462 goto err;
developer32f2a182023-06-27 19:50:41 +080014463 }
14464 strncat(SRate, ",", sizeof(SRate) - strlen(SRate) - 1);
developer72fb0bb2023-01-11 09:46:29 +080014465
developera3511852023-06-14 14:12:59 +080014466 tmp = strtok(NULL, " \n");
14467 }
14468 SRate[strlen(SRate) - 1] = '\0';
developer32f2a182023-06-27 19:50:41 +080014469 len = strlen(SRate);
14470 if (len >= sizeof(scan_array[index].ap_SupportedDataTransferRates)) {
14471 wifi_debug(DEBUG_ERROR, "not enough room in scan_array[index].ap_SupportedDataTransferRates\n");
developer86035662023-06-28 19:21:12 +080014472 goto err;
developer32f2a182023-06-27 19:50:41 +080014473 }
14474 strncpy(scan_array[index].ap_SupportedDataTransferRates, SRate, len);
14475 scan_array[index].ap_SupportedDataTransferRates[len] = '\0';
developera3511852023-06-14 14:12:59 +080014476 } else if (strstr(line, "DTIM") != NULL) {
developer5b23cd02023-07-19 20:26:03 +080014477 if (sscanf(line," TIM: DTIM Count %*d DTIM Period %d %*s", &(scan_array[index].ap_DTIMPeriod)) != 1) {
developer86035662023-06-28 19:21:12 +080014478 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
developer5b23cd02023-07-19 20:26:03 +080014479 goto err;
developer86035662023-06-28 19:21:12 +080014480 }
developera3511852023-06-14 14:12:59 +080014481 } else if (strstr(line, "VHT capabilities") != NULL) {
developer32f2a182023-06-27 19:50:41 +080014482 if ((sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards)) <= 3) {
14483 wifi_debug(DEBUG_ERROR, "not enough room in scan_array[index].ap_SupportedStandards\n");
developer86035662023-06-28 19:21:12 +080014484 goto err;
developer32f2a182023-06-27 19:50:41 +080014485 }
14486 strncat(scan_array[index].ap_SupportedStandards, ",ac",
14487 sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) - 1);
14488 memcpy(scan_array[index].ap_OperatingStandards, "ac", 2);
14489 scan_array[index].ap_OperatingStandards[2] = '\0';
developera3511852023-06-14 14:12:59 +080014490 } else if (strstr(line, "HT capabilities") != NULL) {
developer32f2a182023-06-27 19:50:41 +080014491 if ((sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards)) <= 2) {
14492 wifi_debug(DEBUG_ERROR, "not enough room in scan_array[index].ap_SupportedStandards\n");
developer86035662023-06-28 19:21:12 +080014493 goto err;
developer32f2a182023-06-27 19:50:41 +080014494 }
14495 strncat(scan_array[index].ap_SupportedStandards, ",n",
14496 sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) - 1);
14497 memcpy(scan_array[index].ap_OperatingStandards, "n", 1);
14498 scan_array[index].ap_OperatingStandards[1] = '\0';
developera3511852023-06-14 14:12:59 +080014499 } else if (strstr(line, "VHT operation") != NULL) {
developer86035662023-06-28 19:21:12 +080014500 if (fgets(line, sizeof(line), f) == NULL) {
14501 wifi_debug(DEBUG_ERROR, "fgets fail\n");
14502 goto err;
14503 }
14504 if (sscanf(line," * channel width: %d", &vht_channel_width) != 1) {
14505 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14506 goto err;
14507 }
developera3511852023-06-14 14:12:59 +080014508 if(vht_channel_width == 1) {
developere40952c2023-06-15 18:46:43 +080014509 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11AC_VHT80");
developera3511852023-06-14 14:12:59 +080014510 } else {
developere40952c2023-06-15 18:46:43 +080014511 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11AC_VHT40");
developera3511852023-06-14 14:12:59 +080014512 }
developere40952c2023-06-15 18:46:43 +080014513 if (os_snprintf_error(sizeof(scan_array[index].ap_OperatingChannelBandwidth), res)) {
14514 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developer86035662023-06-28 19:21:12 +080014515 goto err;
developer5b23cd02023-07-19 20:26:03 +080014516 }
developere40952c2023-06-15 18:46:43 +080014517
developera3511852023-06-14 14:12:59 +080014518 if (strstr(line, "BSS") != NULL) // prevent to get the next neighbor information
14519 continue;
14520 } else if (strstr(line, "HT operation") != NULL) {
developer86035662023-06-28 19:21:12 +080014521 if (fgets(line, sizeof(line), f) == NULL) {
14522 wifi_debug(DEBUG_ERROR, "fgets fail\n");
14523 goto err;
14524 }
developer86035662023-06-28 19:21:12 +080014525 if (sscanf(line," * secondary channel offset: %127s", buf) != 1) {
14526 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14527 goto err;
14528 }
developera3511852023-06-14 14:12:59 +080014529 if (!strcmp(buf, "above")) {
14530 //40Mhz +
developere40952c2023-06-15 18:46:43 +080014531 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11N%s_HT40PLUS", radio_index%1 ? "A": "G");
developera3511852023-06-14 14:12:59 +080014532 }
14533 else if (!strcmp(buf, "below")) {
14534 //40Mhz -
developere40952c2023-06-15 18:46:43 +080014535 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11N%s_HT40MINUS", radio_index%1 ? "A": "G");
developera3511852023-06-14 14:12:59 +080014536 } else {
14537 //20Mhz
developere40952c2023-06-15 18:46:43 +080014538 res = snprintf(scan_array[index].ap_OperatingChannelBandwidth, sizeof(scan_array[index].ap_OperatingChannelBandwidth), "11N%s_HT20", radio_index%1 ? "A": "G");
developera3511852023-06-14 14:12:59 +080014539 }
developere40952c2023-06-15 18:46:43 +080014540 if (os_snprintf_error(sizeof(scan_array[index].ap_OperatingChannelBandwidth), res)) {
14541 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developer86035662023-06-28 19:21:12 +080014542 goto err;
developer5b23cd02023-07-19 20:26:03 +080014543 }
developere40952c2023-06-15 18:46:43 +080014544
developer5b23cd02023-07-19 20:26:03 +080014545 if (strstr(line, "BSS") != NULL) { // prevent to get the next neighbor information
14546 wifi_debug(DEBUG_OFF, "continue\n");
developera3511852023-06-14 14:12:59 +080014547 continue;
developer5b23cd02023-07-19 20:26:03 +080014548 }
developera3511852023-06-14 14:12:59 +080014549 } else if (strstr(line, "HE capabilities") != NULL) {
developer32f2a182023-06-27 19:50:41 +080014550 if ((sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards)) <= 3) {
14551 wifi_debug(DEBUG_ERROR, "not enough room in scan_array[index].ap_SupportedStandards\n");
developer86035662023-06-28 19:21:12 +080014552 goto err;
developer32f2a182023-06-27 19:50:41 +080014553 }
14554 strncat(scan_array[index].ap_SupportedStandards, ",ax",
14555 sizeof(scan_array[index].ap_SupportedStandards) - strlen(scan_array[index].ap_SupportedStandards) - 1);
14556 memcpy(scan_array[index].ap_OperatingStandards, "ax", 2);
14557 scan_array[index].ap_OperatingStandards[2] = '\0';
developerc14d83a2023-06-29 20:09:42 +080014558 if (fgets(line, sizeof(line), f) == NULL) {
14559 wifi_debug(DEBUG_ERROR, "fgets fail\n");
14560 goto err;
14561 }
developera3511852023-06-14 14:12:59 +080014562 if (strncmp(scan_array[index].ap_OperatingFrequencyBand, "2.4GHz", strlen("2.4GHz")) == 0) {
developer32f2a182023-06-27 19:50:41 +080014563 if (strstr(line, "HE40/2.4GHz") != NULL) {
14564 len = strlen("11AXHE40PLUS");
14565 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE40PLUS", len);
14566 } else {
14567 len = strlen("11AXHE20");
14568 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE20", len);
14569 }
14570 scan_array[index].ap_OperatingChannelBandwidth[len] = '\0';
developera3511852023-06-14 14:12:59 +080014571 } else if (strncmp(scan_array[index].ap_OperatingFrequencyBand, "5GHz", strlen("5GHz")) == 0) {
14572 if (strstr(line, "HE80/5GHz") != NULL) {
developer32f2a182023-06-27 19:50:41 +080014573 len = strlen("11AXHE80");
14574 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE80", len);
14575 scan_array[index].ap_OperatingChannelBandwidth[len] = '\0';
developera3511852023-06-14 14:12:59 +080014576 ret = fgets(line, sizeof(line), f);
developer5b23cd02023-07-19 20:26:03 +080014577 } else {
14578 wifi_debug(DEBUG_OFF, "continue\n");
developera3511852023-06-14 14:12:59 +080014579 continue;
developer5b23cd02023-07-19 20:26:03 +080014580 }
developer32f2a182023-06-27 19:50:41 +080014581 if (strstr(line, "HE160/5GHz") != NULL) {
14582 len = strlen("11AXHE160");
14583 memcpy(scan_array[index].ap_OperatingChannelBandwidth, "11AXHE160", len);
14584 scan_array[index].ap_OperatingChannelBandwidth[len] = '\0';
14585 }
developera3511852023-06-14 14:12:59 +080014586 }
developer5b23cd02023-07-19 20:26:03 +080014587 wifi_debug(DEBUG_OFF, "continue\n");
developera3511852023-06-14 14:12:59 +080014588 continue;
14589 } else if (strstr(line, "WPA") != NULL) {
developer32f2a182023-06-27 19:50:41 +080014590 memcpy(scan_array[index].ap_SecurityModeEnabled, "WPA", 3);
14591 scan_array[index].ap_SecurityModeEnabled[3] = '\0';
developera3511852023-06-14 14:12:59 +080014592 } else if (strstr(line, "RSN") != NULL) {
developer32f2a182023-06-27 19:50:41 +080014593 memcpy(scan_array[index].ap_SecurityModeEnabled, "RSN", 3);
14594 scan_array[index].ap_SecurityModeEnabled[3] = '\0';
developera3511852023-06-14 14:12:59 +080014595 } else if (strstr(line, "Group cipher") != NULL) {
developer86035662023-06-28 19:21:12 +080014596 if (sscanf(line, " * Group cipher: %63s", scan_array[index].ap_EncryptionMode) != 1) {
14597 wifi_debug(DEBUG_ERROR, "sscanf fail\n");
14598 goto err;
14599 }
developera3511852023-06-14 14:12:59 +080014600 if (strncmp(scan_array[index].ap_EncryptionMode, "CCMP", strlen("CCMP")) == 0) {
developer32f2a182023-06-27 19:50:41 +080014601 memcpy(scan_array[index].ap_EncryptionMode, "AES", 3);
14602 scan_array[index].ap_EncryptionMode[3] = '\0';
developera3511852023-06-14 14:12:59 +080014603 }
14604 }
14605 ret = fgets(line, sizeof(line), f);
14606 }
developer72fb0bb2023-01-11 09:46:29 +080014607
developera3511852023-06-14 14:12:59 +080014608 if (!filter_BSS) {
14609 *output_array_size = index + 1;
14610 } else {
14611 memset(&(scan_array[index]), 0, sizeof(wifi_neighbor_ap2_t));
14612 *output_array_size = index;
14613 }
14614 *neighbor_ap_array = scan_array;
developer8078acf2023-08-04 18:52:48 +080014615 v_secure_pclose(f);
developera3511852023-06-14 14:12:59 +080014616 free(channels_noise_arr);
14617 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
14618 return RETURN_OK;
developer86035662023-06-28 19:21:12 +080014619err:
developer8078acf2023-08-04 18:52:48 +080014620 v_secure_pclose(f);
developer86035662023-06-28 19:21:12 +080014621 free(channels_noise_arr);
developerc14d83a2023-06-29 20:09:42 +080014622 if (scan_array)
14623 free(scan_array);
developer86035662023-06-28 19:21:12 +080014624 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080014625}
14626
14627INT wifi_getApAssociatedDeviceStats(
developera3511852023-06-14 14:12:59 +080014628 INT apIndex,
14629 mac_address_t *clientMacAddress,
14630 wifi_associated_dev_stats_t *associated_dev_stats,
14631 u64 *handle)
developer72fb0bb2023-01-11 09:46:29 +080014632{
developera3511852023-06-14 14:12:59 +080014633 wifi_associated_dev_stats_t *dev_stats = associated_dev_stats;
14634 char interface_name[50] = {0};
14635 char cmd[1024] = {0};
14636 char mac_str[18] = {0};
14637 char *key = NULL;
14638 char *val = NULL;
14639 FILE *f = NULL;
14640 char *line = NULL;
14641 size_t len = 0;
developer75bd10c2023-06-27 11:34:08 +080014642 int res;
developer72fb0bb2023-01-11 09:46:29 +080014643
developera3511852023-06-14 14:12:59 +080014644 if(wifi_getApName(apIndex, interface_name) != RETURN_OK) {
14645 wifi_dbg_printf("%s: wifi_getApName failed\n", __FUNCTION__);
14646 return RETURN_ERR;
14647 }
developer72fb0bb2023-01-11 09:46:29 +080014648
developer32f2a182023-06-27 19:50:41 +080014649 res = snprintf(mac_str, sizeof(mac_str), "%x:%x:%x:%x:%x:%x",
14650 (*clientMacAddress)[0], (*clientMacAddress)[1], (*clientMacAddress)[2],
14651 (*clientMacAddress)[3], (*clientMacAddress)[4], (*clientMacAddress)[5]);
developer75bd10c2023-06-27 11:34:08 +080014652 if (os_snprintf_error(sizeof(mac_str), res)) {
14653 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14654 return RETURN_ERR;
14655 }
14656
14657 res = snprintf(cmd, sizeof(cmd), "iw dev %s station get %s | grep 'rx\\|tx' | tr -d '\t'", interface_name, mac_str);
14658 if (os_snprintf_error(sizeof(cmd), res)) {
14659 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14660 return RETURN_ERR;
14661 }
developer8078acf2023-08-04 18:52:48 +080014662 f = v_secure_popen("r", "iw dev %s station get %s | grep 'rx\\|tx' | tr -d '\t'", interface_name, mac_str);
14663 if(f == NULL) {
14664 wifi_dbg_printf("%s: v_secure_popen %s error\n", __func__, cmd);
developera3511852023-06-14 14:12:59 +080014665 return RETURN_ERR;
14666 }
developer72fb0bb2023-01-11 09:46:29 +080014667
developera3511852023-06-14 14:12:59 +080014668 while ((getline(&line, &len, f)) != -1) {
14669 key = strtok(line,":");
developer37646972023-06-29 10:58:43 +080014670 if (key == NULL)
14671 continue;
developera3511852023-06-14 14:12:59 +080014672 val = strtok(NULL,":");
developer37646972023-06-29 10:58:43 +080014673 if (val == NULL)
14674 continue;
developer72fb0bb2023-01-11 09:46:29 +080014675
developerb61d3362023-06-29 14:10:19 +080014676 if(!strncmp(key,"rx bytes",8))
14677 if (sscanf(val, "%llu", &dev_stats->cli_rx_bytes) != 1) {
14678 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
developer37646972023-06-29 10:58:43 +080014679 continue;
developerb61d3362023-06-29 14:10:19 +080014680 }
14681 if(!strncmp(key,"tx bytes",8))
14682 if (sscanf(val, "%llu", &dev_stats->cli_tx_bytes) != 1) {
14683 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
developer37646972023-06-29 10:58:43 +080014684 continue;
developerb61d3362023-06-29 14:10:19 +080014685 }
developer37646972023-06-29 10:58:43 +080014686 if(!strncmp(key,"rx packets",10)) {
14687 if (sscanf(val, "%llu", &dev_stats->cli_tx_frames) == EOF) {
14688 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14689 continue;
14690 }
14691 }
14692 if(!strncmp(key,"tx packets",10)) {
14693 if (sscanf(val, "%llu", &dev_stats->cli_tx_frames) == EOF) {
14694 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14695 continue;
14696 }
14697 }
14698 if(!strncmp(key,"tx retries",10)) {
14699 if (sscanf(val, "%llu", &dev_stats->cli_tx_retries) == EOF) {
14700 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14701 continue;
14702 }
14703 }
14704 if(!strncmp(key,"tx failed",9)) {
14705 if (sscanf(val, "%llu", &dev_stats->cli_tx_errors) == EOF) {
14706 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14707 continue;
14708 }
14709 }
14710 if(!strncmp(key,"rx drop misc",13)) {
14711 if (sscanf(val, "%llu", &dev_stats->cli_rx_errors) == EOF) {
14712 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14713 continue;
14714 }
developerd14dff12023-06-28 22:47:44 +080014715 }
developera3511852023-06-14 14:12:59 +080014716 if(!strncmp(key,"rx bitrate",10)) {
14717 val = strtok(val, " ");
developerc14d83a2023-06-29 20:09:42 +080014718 if (val == NULL)
14719 continue;
developer37646972023-06-29 10:58:43 +080014720 if (sscanf(val, "%lf", &dev_stats->cli_rx_rate) == EOF) {
14721 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14722 continue;
14723 }
developera3511852023-06-14 14:12:59 +080014724 }
14725 if(!strncmp(key,"tx bitrate",10)) {
14726 val = strtok(val, " ");
developerc14d83a2023-06-29 20:09:42 +080014727 if (val == NULL)
14728 continue;
developer37646972023-06-29 10:58:43 +080014729 if (sscanf(val, "%lf", &dev_stats->cli_tx_rate) == EOF) {
14730 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
14731 continue;
14732 }
developera3511852023-06-14 14:12:59 +080014733 }
14734 }
14735 free(line);
developer8078acf2023-08-04 18:52:48 +080014736 v_secure_pclose(f);
developera3511852023-06-14 14:12:59 +080014737 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080014738}
14739
14740INT wifi_getSSIDNameStatus(INT apIndex, CHAR *output_string)
14741{
developera3511852023-06-14 14:12:59 +080014742 char interface_name[IF_NAME_SIZE] = {0};
developer8078acf2023-08-04 18:52:48 +080014743 char buf[32] = {0};
developere40952c2023-06-15 18:46:43 +080014744 int res;
developer72fb0bb2023-01-11 09:46:29 +080014745
developera3511852023-06-14 14:12:59 +080014746 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer7e4a2a62023-04-06 19:56:03 +080014747
developera3511852023-06-14 14:12:59 +080014748 if (NULL == output_string)
14749 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080014750
developera3511852023-06-14 14:12:59 +080014751 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
14752 return RETURN_ERR;
developer7e4a2a62023-04-06 19:56:03 +080014753
developer8078acf2023-08-04 18:52:48 +080014754 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s get_config | grep ^ssid | cut -d '=' -f2 | tr -d '\\n'", interface_name);
14755 if (res) {
14756 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080014757 }
developer72fb0bb2023-01-11 09:46:29 +080014758
developera3511852023-06-14 14:12:59 +080014759 //size of SSID name restricted to value less than 32 bytes
developere40952c2023-06-15 18:46:43 +080014760 res = snprintf(output_string, 32, "%s", buf);
14761 if (os_snprintf_error(32, res)) {
14762 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
14763 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080014764 }
developera3511852023-06-14 14:12:59 +080014765 WIFI_ENTRY_EXIT_DEBUG("Exit %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080014766
developera3511852023-06-14 14:12:59 +080014767 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080014768}
14769
14770INT wifi_getApMacAddressControlMode(INT apIndex, INT *output_filterMode)
14771{
developer2edaf012023-05-24 14:24:53 +080014772 char *mac_arry_buf = NULL;
14773 INT policy = -1;
14774 INT buf_size = 1024;
developer72fb0bb2023-01-11 09:46:29 +080014775
developer2edaf012023-05-24 14:24:53 +080014776 mac_arry_buf = malloc(buf_size);
14777 if (!mac_arry_buf) {
14778 wifi_debug(DEBUG_ERROR,"malloc mac_arry_buf fails\n");
developer7e4a2a62023-04-06 19:56:03 +080014779 return RETURN_ERR;
developer2edaf012023-05-24 14:24:53 +080014780 }
14781 memset(mac_arry_buf, 0, buf_size);
14782 if (mtk_wifi_getApAclDevices(apIndex, mac_arry_buf, buf_size) != RETURN_OK) {
14783 wifi_debug(DEBUG_ERROR,"mtk_wifi_getApAclDevices get fails\n");
14784 goto err;
14785 }
14786 /*
14787 mtk format to get policy:
14788 "policy=1
14789 00:11:22:33:44:55
14790 00:11:22:33:44:66
14791 "
14792 */
14793 if (strlen(mac_arry_buf) < strlen("policy=1") || sscanf(mac_arry_buf, "policy=%01d", &policy) != 1) {
14794 wifi_debug(DEBUG_ERROR,"mac_arry_buf(%s) invalid\n", mac_arry_buf);
14795 goto err;
14796 }
14797 if (!(policy >=0 && policy <= 2)){
14798 wifi_debug(DEBUG_ERROR,"policy(%d) is invalid\n", policy);
14799 goto err;
14800 }
14801 *output_filterMode = policy;
14802 wifi_debug(DEBUG_NOTICE, "output_filterMode(%d), success\n", *output_filterMode);
14803 free(mac_arry_buf);
14804 mac_arry_buf = NULL;
14805 return RETURN_OK;
14806err:
14807 free(mac_arry_buf);
14808 mac_arry_buf = NULL;
14809 wifi_debug(DEBUG_NOTICE, "output_filterMode(%d), fails\n", *output_filterMode);
14810 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080014811}
14812
developer2edaf012023-05-24 14:24:53 +080014813
developer72fb0bb2023-01-11 09:46:29 +080014814INT wifi_getApAssociatedDeviceDiagnosticResult2(INT apIndex,wifi_associated_dev2_t **associated_dev_array,UINT *output_array_size)
14815{
developera3511852023-06-14 14:12:59 +080014816 FILE *fp = NULL;
14817 char str[MAX_BUF_SIZE] = {0};
14818 int wificlientindex = 0 ;
14819 int count = 0;
14820 int signalstrength = 0;
14821 int arr[MACADDRESS_SIZE] = {0};
14822 unsigned char mac[MACADDRESS_SIZE] = {0};
14823 UINT wifi_count = 0;
developer8078acf2023-08-04 18:52:48 +080014824
developere40952c2023-06-15 18:46:43 +080014825 int res;
developer72fb0bb2023-01-11 09:46:29 +080014826
developera3511852023-06-14 14:12:59 +080014827 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
14828 *output_array_size = 0;
14829 *associated_dev_array = NULL;
14830 char interface_name[50] = {0};
developer72fb0bb2023-01-11 09:46:29 +080014831
developera3511852023-06-14 14:12:59 +080014832 if(wifi_getApName(apIndex, interface_name) != RETURN_OK) {
14833 wifi_dbg_printf("%s: wifi_getApName failed\n", __FUNCTION__);
14834 return RETURN_ERR;
14835 }
developer72fb0bb2023-01-11 09:46:29 +080014836
developer8078acf2023-08-04 18:52:48 +080014837 fp = v_secure_popen( "r", "iw dev %s station dump | grep %s | wc -l", interface_name, interface_name);
developera3511852023-06-14 14:12:59 +080014838 if (fp == NULL)
14839 {
14840 printf("Failed to run command inside function %s\n",__FUNCTION__ );
14841 return RETURN_ERR;
14842 }
developer72fb0bb2023-01-11 09:46:29 +080014843
developera3511852023-06-14 14:12:59 +080014844 /* Read the output a line at a time - output it. */
developer86035662023-06-28 19:21:12 +080014845 if (fgets(str, sizeof(str)-1, fp) == NULL) {
14846 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080014847 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080014848 return RETURN_ERR;
14849 }
developera3511852023-06-14 14:12:59 +080014850 wifi_count = (unsigned int) atoi ( str );
14851 *output_array_size = wifi_count;
14852 wifi_dbg_printf(" In rdkb hal ,Wifi Client Counts and index %d and %d \n",*output_array_size,apIndex);
developer8078acf2023-08-04 18:52:48 +080014853 v_secure_pclose(fp);
developer72fb0bb2023-01-11 09:46:29 +080014854
developera3511852023-06-14 14:12:59 +080014855 if(wifi_count == 0)
14856 {
14857 return RETURN_OK;
14858 }
14859 else
14860 {
14861 wifi_associated_dev2_t* temp = NULL;
14862 temp = (wifi_associated_dev2_t*)calloc(wifi_count, sizeof(wifi_associated_dev2_t));
14863 *associated_dev_array = temp;
14864 if(temp == NULL)
14865 {
14866 printf("Error Statement. Insufficient memory \n");
14867 return RETURN_ERR;
14868 }
developer72fb0bb2023-01-11 09:46:29 +080014869
developer33f13ba2023-07-12 16:19:06 +080014870 res = v_secure_system("iw dev %s station dump > /tmp/AssociatedDevice_Stats.txt", interface_name);
14871 if (res) {
14872 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developere40952c2023-06-15 18:46:43 +080014873 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080014874 }
developere40952c2023-06-15 18:46:43 +080014875
developera3511852023-06-14 14:12:59 +080014876 fp = fopen("/tmp/AssociatedDevice_Stats.txt", "r");
14877 if(fp == NULL)
14878 {
14879 printf("/tmp/AssociatedDevice_Stats.txt not exists \n");
14880 return RETURN_ERR;
14881 }
developere75ba632023-06-29 16:03:33 +080014882 if (fclose(fp) == EOF) {
14883 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
14884 return RETURN_ERR;
14885 }
developer72fb0bb2023-01-11 09:46:29 +080014886
developer8078acf2023-08-04 18:52:48 +080014887 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep Station | cut -d ' ' -f 2");
developera3511852023-06-14 14:12:59 +080014888 if(fp)
14889 {
14890 for(count =0 ; count < wifi_count; count++)
14891 {
developer86035662023-06-28 19:21:12 +080014892 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
14893 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080014894 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080014895 return RETURN_ERR;
14896 }
developera3511852023-06-14 14:12:59 +080014897 if( MACADDRESS_SIZE == sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5]) )
14898 {
14899 for( wificlientindex = 0; wificlientindex < MACADDRESS_SIZE; ++wificlientindex )
14900 {
14901 mac[wificlientindex] = (unsigned char) arr[wificlientindex];
developer72fb0bb2023-01-11 09:46:29 +080014902
developera3511852023-06-14 14:12:59 +080014903 }
14904 memcpy(temp[count].cli_MACAddress,mac,(sizeof(unsigned char))*6);
14905 wifi_dbg_printf("MAC %d = %X:%X:%X:%X:%X:%X \n", count, temp[count].cli_MACAddress[0],temp[count].cli_MACAddress[1], temp[count].cli_MACAddress[2], temp[count].cli_MACAddress[3], temp[count].cli_MACAddress[4], temp[count].cli_MACAddress[5]);
14906 }
14907 temp[count].cli_AuthenticationState = 1; //TODO
14908 temp[count].cli_Active = 1; //TODO
14909 }
developer8078acf2023-08-04 18:52:48 +080014910 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014911 }
developer72fb0bb2023-01-11 09:46:29 +080014912
developera3511852023-06-14 14:12:59 +080014913 //Updating RSSI per client
developer8078acf2023-08-04 18:52:48 +080014914 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep signal | tr -s ' ' | cut -d ' ' -f 2 > /tmp/wifi_signalstrength.txt");
developera3511852023-06-14 14:12:59 +080014915 if(fp)
14916 {
developer8078acf2023-08-04 18:52:48 +080014917 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014918 }
developer8078acf2023-08-04 18:52:48 +080014919 fp = v_secure_popen("r", "cat /tmp/wifi_signalstrength.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080014920 if(fp)
14921 {
14922 for(count =0 ; count < wifi_count ;count++)
14923 {
developer86035662023-06-28 19:21:12 +080014924 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
14925 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080014926 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080014927 return RETURN_ERR;
14928 }
developera3511852023-06-14 14:12:59 +080014929 signalstrength = atoi(str);
14930 temp[count].cli_RSSI = signalstrength;
14931 }
developer8078acf2023-08-04 18:52:48 +080014932 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014933 }
developer72fb0bb2023-01-11 09:46:29 +080014934
14935
developera3511852023-06-14 14:12:59 +080014936 //LastDataDownlinkRate
developer8078acf2023-08-04 18:52:48 +080014937 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'tx bitrate' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Bitrate_Send.txt");
developera3511852023-06-14 14:12:59 +080014938 if (fp)
14939 {
developer8078acf2023-08-04 18:52:48 +080014940 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014941 }
developer8078acf2023-08-04 18:52:48 +080014942 fp = v_secure_popen("r", "cat /tmp/Ass_Bitrate_Send.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080014943 if (fp)
14944 {
developerc14d83a2023-06-29 20:09:42 +080014945 unsigned long tmp_u;
developera3511852023-06-14 14:12:59 +080014946 for (count = 0; count < wifi_count; count++)
14947 {
developer86035662023-06-28 19:21:12 +080014948 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
14949 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080014950 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080014951 return RETURN_ERR;
14952 }
developerc14d83a2023-06-29 20:09:42 +080014953 if (hal_strtoul(str, 10, &tmp_u) < 0) {
14954 wifi_debug(DEBUG_ERROR, "strtol fail\n");
14955 }
14956 temp[count].cli_LastDataDownlinkRate = tmp_u;
developera3511852023-06-14 14:12:59 +080014957 temp[count].cli_LastDataDownlinkRate = (temp[count].cli_LastDataDownlinkRate * 1024); //Mbps -> Kbps
14958 }
developer8078acf2023-08-04 18:52:48 +080014959 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014960 }
developer72fb0bb2023-01-11 09:46:29 +080014961
developera3511852023-06-14 14:12:59 +080014962 //LastDataUplinkRate
developer8078acf2023-08-04 18:52:48 +080014963 fp = v_secure_popen("r", "cat /tmp/AssociatedDevice_Stats.txt | grep 'rx bitrate' | tr -s ' ' | cut -d ' ' -f 2 > /tmp/Ass_Bitrate_Received.txt");
developera3511852023-06-14 14:12:59 +080014964 if (fp)
14965 {
developer8078acf2023-08-04 18:52:48 +080014966 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014967 }
developer8078acf2023-08-04 18:52:48 +080014968 fp = v_secure_popen("r", "cat /tmp/Ass_Bitrate_Received.txt | tr -s ' ' | cut -f 2");
developera3511852023-06-14 14:12:59 +080014969 if (fp)
14970 {
developerc14d83a2023-06-29 20:09:42 +080014971 unsigned long tmp_u;
developera3511852023-06-14 14:12:59 +080014972 for (count = 0; count < wifi_count; count++)
14973 {
developer86035662023-06-28 19:21:12 +080014974 if (fgets(str, MAX_BUF_SIZE, fp) == NULL) {
14975 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080014976 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080014977 return RETURN_ERR;
14978 }
developerc14d83a2023-06-29 20:09:42 +080014979 if (hal_strtoul(str, 10, &tmp_u) < 0) {
14980 wifi_debug(DEBUG_ERROR, "strtol fail\n");
14981 }
14982 temp[count].cli_LastDataUplinkRate = tmp_u;
developera3511852023-06-14 14:12:59 +080014983 temp[count].cli_LastDataUplinkRate = (temp[count].cli_LastDataUplinkRate * 1024); //Mbps -> Kbps
14984 }
developer8078acf2023-08-04 18:52:48 +080014985 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080014986 }
14987 }
14988 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
14989 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080014990
14991}
14992
14993INT wifi_getSSIDTrafficStats2(INT ssidIndex,wifi_ssidTrafficStats2_t *output_struct)
14994{
developera3511852023-06-14 14:12:59 +080014995 FILE *fp = NULL;
14996 char interface_name[50] = {0};
developer8078acf2023-08-04 18:52:48 +080014997
developera3511852023-06-14 14:12:59 +080014998 char str[256] = {0};
14999 wifi_ssidTrafficStats2_t *out = output_struct;
developer8078acf2023-08-04 18:52:48 +080015000
developerd14dff12023-06-28 22:47:44 +080015001 unsigned int recv;
developer72fb0bb2023-01-11 09:46:29 +080015002
developera3511852023-06-14 14:12:59 +080015003 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
15004 if (!output_struct)
15005 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015006
developera3511852023-06-14 14:12:59 +080015007 memset(out, 0, sizeof(wifi_ssidTrafficStats2_t));
15008 if (wifi_GetInterfaceName(ssidIndex, interface_name) != RETURN_OK)
15009 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080015010
15011
15012
15013
developer72fb0bb2023-01-11 09:46:29 +080015014
developer8078acf2023-08-04 18:52:48 +080015015
15016 fp = v_secure_popen("r", "cat /proc/net/dev | grep %s", interface_name);
developera3511852023-06-14 14:12:59 +080015017 if (fp == NULL) {
developer8078acf2023-08-04 18:52:48 +080015018 wifi_debug(DEBUG_ERROR, "%s: v_secure_popen failed\n", __func__);
developer86035662023-06-28 19:21:12 +080015019 return RETURN_ERR;
15020 }
15021 if (fgets(str, sizeof(str), fp) == NULL) {
15022 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080015023 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080015024 return RETURN_ERR;
15025 }
developer5b23cd02023-07-19 20:26:03 +080015026
developer8078acf2023-08-04 18:52:48 +080015027 v_secure_pclose(fp);
developer72fb0bb2023-01-11 09:46:29 +080015028
developera3511852023-06-14 14:12:59 +080015029 if (strlen(str) == 0) // interface not exist
15030 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015031
developerd14dff12023-06-28 22:47:44 +080015032 recv = sscanf(str, "%*[^:]: %lu %lu %lu %lu %*d %*d %*d %*d %lu %lu %lu %lu", &out->ssid_BytesReceived, &out->ssid_PacketsReceived, &out->ssid_ErrorsReceived, \
developera3511852023-06-14 14:12:59 +080015033 &out->ssid_DiscardedPacketsReceived, &out->ssid_BytesSent, &out->ssid_PacketsSent, &out->ssid_ErrorsSent, &out->ssid_DiscardedPacketsSent);
developerd14dff12023-06-28 22:47:44 +080015034 if (recv != 8) {
15035 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
15036 return RETURN_ERR;
15037 }
developer72fb0bb2023-01-11 09:46:29 +080015038
developera3511852023-06-14 14:12:59 +080015039 memset(str, 0, sizeof(str));
developer75bd10c2023-06-27 11:34:08 +080015040
developer8078acf2023-08-04 18:52:48 +080015041
15042
15043
15044
15045
15046 fp = v_secure_popen("r", "tail -n1 /proc/net/netstat");
developera3511852023-06-14 14:12:59 +080015047 if (fp == NULL) {
developer8078acf2023-08-04 18:52:48 +080015048 wifi_debug(DEBUG_ERROR, "v_secure_popen failed\n");
developera3511852023-06-14 14:12:59 +080015049 return RETURN_ERR;
15050 }
developer86035662023-06-28 19:21:12 +080015051
15052 if (fgets(str, sizeof(str), fp) == NULL) {
15053 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080015054 v_secure_pclose(fp);
developer86035662023-06-28 19:21:12 +080015055 return RETURN_ERR;
15056 }
developer72fb0bb2023-01-11 09:46:29 +080015057
developer37646972023-06-29 10:58:43 +080015058 if (sscanf(str, "%*[^:]: %lu %lu %lu %lu", &out->ssid_MulticastPacketsReceived, &out->ssid_MulticastPacketsSent, &out->ssid_BroadcastPacketsRecevied, \
15059 &out->ssid_BroadcastPacketsSent) == EOF)
15060 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
developer8078acf2023-08-04 18:52:48 +080015061 v_secure_pclose(fp);
developer72fb0bb2023-01-11 09:46:29 +080015062
developera3511852023-06-14 14:12:59 +080015063 out->ssid_UnicastPacketsSent = out->ssid_PacketsSent - out->ssid_MulticastPacketsSent - out->ssid_BroadcastPacketsSent - out->ssid_DiscardedPacketsSent;
15064 out->ssid_UnicastPacketsReceived = out->ssid_PacketsReceived - out->ssid_MulticastPacketsReceived - out->ssid_BroadcastPacketsRecevied - out->ssid_DiscardedPacketsReceived;
developer72fb0bb2023-01-11 09:46:29 +080015065
developera3511852023-06-14 14:12:59 +080015066 // Not supported
15067 output_struct->ssid_RetransCount = 0;
15068 output_struct->ssid_FailedRetransCount = 0;
15069 output_struct->ssid_RetryCount = 0;
15070 output_struct->ssid_MultipleRetryCount = 0;
15071 output_struct->ssid_ACKFailureCount = 0;
15072 output_struct->ssid_AggregatedPacketCount = 0;
developer72fb0bb2023-01-11 09:46:29 +080015073
developera3511852023-06-14 14:12:59 +080015074 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015075}
15076
developer37ad6bf2023-10-09 11:31:05 +080015077int mtk_get_ap_isolation_callback(struct nl_msg *msg, void *data) {
15078 struct nlattr *tb[NL80211_ATTR_MAX + 1];
15079 struct nlattr *vndr_tb[MTK_NL80211_VENDOR_AP_BSS_ATTR_MAX + 1];
15080 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
15081 unsigned char status;
15082 unsigned char *out_status = data;
15083 int err = 0;
15084
15085 err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
15086 genlmsg_attrlen(gnlh, 0), NULL);
15087 if (err < 0){
15088 wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
15089 return err;
15090 }
15091
15092 if (tb[NL80211_ATTR_VENDOR_DATA]) {
15093 err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_AP_BSS_ATTR_MAX,
15094 tb[NL80211_ATTR_VENDOR_DATA], NULL);
15095 if (err < 0){
15096 wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_AP_BA_ATTR_MAX fails\n");
15097 return err;
15098 }
15099
15100 if (vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_ISOLATION]) {
15101 status = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_AP_ISOLATION]);
15102 if (status == 0) {
15103 wifi_debug(DEBUG_INFO, "disabled\n");
15104 } else {
15105 wifi_debug(DEBUG_INFO, "enabled\n");
15106 }
15107 *out_status = status;
15108 }
15109 }
15110 return 0;
15111
15112}
15113
developer72fb0bb2023-01-11 09:46:29 +080015114//Enables or disables device isolation. A value of true means that the devices connected to the Access Point are isolated from all other devices within the home network (as is typically the case for a Wireless Hotspot).
15115INT wifi_getApIsolationEnable(INT apIndex, BOOL *output)
15116{
developer37ad6bf2023-10-09 11:31:05 +080015117 char inf_name[IF_NAME_SIZE] = {0};
15118 unsigned int if_idx = 0;
15119 int ret = -1;
15120 struct unl unl_ins;
15121 struct nl_msg *msg = NULL;
15122 struct nlattr * msg_data = NULL;
15123 struct mtk_nl80211_param param;
developer72fb0bb2023-01-11 09:46:29 +080015124
developer37ad6bf2023-10-09 11:31:05 +080015125 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
15126 return RETURN_ERR;
15127 if_idx = if_nametoindex(inf_name);
developer75bd10c2023-06-27 11:34:08 +080015128
developer37ad6bf2023-10-09 11:31:05 +080015129 /*init mtk nl80211 vendor cmd*/
15130 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_BSS;
15131 param.if_type = NL80211_ATTR_IFINDEX;
15132 param.if_idx = if_idx;
developer72fb0bb2023-01-11 09:46:29 +080015133
developer37ad6bf2023-10-09 11:31:05 +080015134 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
15135 if (ret) {
15136 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
15137 return RETURN_ERR;
15138 }
15139 /*add mtk vendor cmd data*/
15140 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_ISOLATION, 0xf)) {
15141 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", MTK_NL80211_VENDOR_ATTR_AP_AMSDU_EN);
15142 nlmsg_free(msg);
15143 goto err;
15144 }
developer72fb0bb2023-01-11 09:46:29 +080015145
developer37ad6bf2023-10-09 11:31:05 +080015146 /*send mtk nl80211 vendor msg*/
15147 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, mtk_get_ap_isolation_callback, output);
15148 if (ret) {
15149 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
15150 goto err;
15151 }
15152 /*deinit mtk nl80211 vendor msg*/
15153 mtk_nl80211_deint(&unl_ins);
15154 wifi_debug(DEBUG_INFO,"send cmd success, get output_bool:%d\n", *output);
15155 return RETURN_OK;
15156err:
15157 mtk_nl80211_deint(&unl_ins);
15158 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
15159 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015160}
15161
15162INT wifi_setApIsolationEnable(INT apIndex, BOOL enable)
15163{
developer37ad6bf2023-10-09 11:31:05 +080015164 char inf_name[IF_NAME_SIZE] = {0};
15165 unsigned int if_idx = 0;
15166 int ret = -1;
15167 struct unl unl_ins;
15168 struct nl_msg *msg = NULL;
15169 struct nlattr * msg_data = NULL;
15170 struct mtk_nl80211_param nl_param;
developer72fb0bb2023-01-11 09:46:29 +080015171
developer37ad6bf2023-10-09 11:31:05 +080015172 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
15173 return RETURN_ERR;
15174 if_idx = if_nametoindex(inf_name);
developer72fb0bb2023-01-11 09:46:29 +080015175
developer37ad6bf2023-10-09 11:31:05 +080015176 nl_param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_AP_BSS;
15177 nl_param.if_type = NL80211_ATTR_IFINDEX;
15178 nl_param.if_idx = if_idx;
15179 /*init mtk nl80211 vendor cmd*/
15180 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &nl_param);
15181 if (ret) {
15182 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
15183 return RETURN_ERR;
15184 }
15185 /*add mtk vendor cmd data*/
15186 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_AP_ISOLATION, enable)) {
15187 wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", MTK_NL80211_VENDOR_ATTR_AP_ISOLATION);
15188 nlmsg_free(msg);
15189 goto err;
15190 }
developer75bd10c2023-06-27 11:34:08 +080015191
developer37ad6bf2023-10-09 11:31:05 +080015192 /*send mtk nl80211 vendor msg*/
15193 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
15194 if (ret) {
15195 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
15196 goto err;
15197 }
15198 /*deinit mtk nl80211 vendor msg*/
15199 mtk_nl80211_deint(&unl_ins);
15200 return RETURN_OK;
15201err:
15202 mtk_nl80211_deint(&unl_ins);
15203 wifi_debug(DEBUG_ERROR,"send cmd fails\n");
15204 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015205}
15206
15207INT wifi_getApManagementFramePowerControl(INT apIndex, INT *output_dBm)
15208{
developera3511852023-06-14 14:12:59 +080015209 char mgmtpwr_file[32] = {0};
developer8078acf2023-08-04 18:52:48 +080015210
developera3511852023-06-14 14:12:59 +080015211 char buf[32]={0};
developere40952c2023-06-15 18:46:43 +080015212 int res;
developerc14d83a2023-06-29 20:09:42 +080015213 long int tmp;
developera1255e42023-05-13 17:45:02 +080015214
developera3511852023-06-14 14:12:59 +080015215 if (NULL == output_dBm)
15216 return RETURN_ERR;
developere40952c2023-06-15 18:46:43 +080015217 res = snprintf(mgmtpwr_file, sizeof(mgmtpwr_file), "%s%d.txt", MGMT_POWER_CTRL, apIndex);
15218 if (os_snprintf_error(sizeof(mgmtpwr_file), res)) {
15219 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15220 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080015221 }
developere40952c2023-06-15 18:46:43 +080015222
developer8078acf2023-08-04 18:52:48 +080015223 res = _syscmd_secure(buf, sizeof(buf), "cat %s 2> /dev/null", mgmtpwr_file);
15224 if (res) {
15225 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080015226 }
developer5b23cd02023-07-19 20:26:03 +080015227 if (strlen(buf) > 0) {
developerc14d83a2023-06-29 20:09:42 +080015228 if (hal_strtol(buf, 10, &tmp) < 0) {
15229 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +080015230 }
developerc14d83a2023-06-29 20:09:42 +080015231 *output_dBm = tmp;
developerd14dff12023-06-28 22:47:44 +080015232 } else
developera1255e42023-05-13 17:45:02 +080015233 *output_dBm = 23;
developera3511852023-06-14 14:12:59 +080015234 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015235}
15236
15237INT wifi_setApManagementFramePowerControl(INT wlanIndex, INT dBm)
15238{
developera1255e42023-05-13 17:45:02 +080015239 char interface_name[16] = {0};
developera1255e42023-05-13 17:45:02 +080015240 char mgmt_pwr_file[128]={0};
15241 FILE *f = NULL;
developerfead3972023-05-25 20:15:02 +080015242 int if_idx, ret = 0;
15243 struct nl_msg *msg = NULL;
15244 struct nlattr * msg_data = NULL;
15245 struct mtk_nl80211_param param;
15246 struct unl unl_ins;
15247 char power[16] = {0};
developere40952c2023-06-15 18:46:43 +080015248 int res;
developera1255e42023-05-13 17:45:02 +080015249
15250 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
15251
15252 if (wifi_GetInterfaceName(wlanIndex, interface_name) != RETURN_OK)
15253 return RETURN_ERR;
developerfead3972023-05-25 20:15:02 +080015254
15255 if_idx = if_nametoindex(interface_name);
15256 /*init mtk nl80211 vendor cmd*/
15257 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_TXPOWER;
15258 param.if_type = NL80211_ATTR_IFINDEX;
15259 param.if_idx = if_idx;
15260
15261 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
15262 if (ret) {
15263 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
15264 return RETURN_ERR;
15265 }
15266
15267 /*add mtk vendor cmd data*/
developere40952c2023-06-15 18:46:43 +080015268 res = snprintf(power, sizeof(power), "%d", dBm);
15269 if (os_snprintf_error(sizeof(power), res)) {
15270 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15271 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080015272 }
developere40952c2023-06-15 18:46:43 +080015273
developerfead3972023-05-25 20:15:02 +080015274 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_TXPWR_MGMT, strlen(power), power)) {
15275 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
15276 nlmsg_free(msg);
15277 goto err;
15278 }
15279
15280 /*send mtk nl80211 vendor msg*/
15281 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
15282 if (ret) {
15283 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
15284 goto err;
15285 }
15286
15287 /*deinit mtk nl80211 vendor msg*/
15288 mtk_nl80211_deint(&unl_ins);
15289 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
15290
developere40952c2023-06-15 18:46:43 +080015291 res = snprintf(mgmt_pwr_file, sizeof(mgmt_pwr_file), "%s%d.txt", MGMT_POWER_CTRL, wlanIndex);
15292 if (os_snprintf_error(sizeof(mgmt_pwr_file), res)) {
15293 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15294 return RETURN_ERR;
developerb758dfd2023-06-21 17:32:07 +080015295 }
developere40952c2023-06-15 18:46:43 +080015296
developera1255e42023-05-13 17:45:02 +080015297 f = fopen(mgmt_pwr_file, "w");
15298 if (f == NULL) {
developerc14d83a2023-06-29 20:09:42 +080015299 wifi_debug(DEBUG_ERROR, "%s: fopen failed\n", __func__);
developera1255e42023-05-13 17:45:02 +080015300 return RETURN_ERR;
15301 }
15302 fprintf(f, "%d", dBm);
developerc14d83a2023-06-29 20:09:42 +080015303 if (fclose(f) == EOF)
15304 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
15305
developer72fb0bb2023-01-11 09:46:29 +080015306 return RETURN_OK;
developerfead3972023-05-25 20:15:02 +080015307err:
15308 mtk_nl80211_deint(&unl_ins);
15309 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
15310 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015311}
15312INT wifi_getRadioDcsChannelMetrics(INT radioIndex,wifi_channelMetrics_t *input_output_channelMetrics_array,INT size)
15313{
developera3511852023-06-14 14:12:59 +080015314 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015315}
15316INT wifi_setRadioDcsDwelltime(INT radioIndex, INT ms)
15317{
developera3511852023-06-14 14:12:59 +080015318 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015319}
15320INT wifi_getRadioDcsDwelltime(INT radioIndex, INT *ms)
15321{
developera3511852023-06-14 14:12:59 +080015322 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015323}
15324INT wifi_setRadioDcsScanning(INT radioIndex, BOOL enable)
15325{
developera3511852023-06-14 14:12:59 +080015326 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015327}
developer9f2358c2023-09-22 18:42:12 +080015328
developer72fb0bb2023-01-11 09:46:29 +080015329INT wifi_setBSSTransitionActivation(UINT apIndex, BOOL activate)
15330{
developera3511852023-06-14 14:12:59 +080015331 char config_file[MAX_BUF_SIZE] = {0};
15332 struct params list;
developere40952c2023-06-15 18:46:43 +080015333 int res;
developer9f2358c2023-09-22 18:42:12 +080015334 bool temp_multiple_set = multiple_set;
developer72fb0bb2023-01-11 09:46:29 +080015335
developera3511852023-06-14 14:12:59 +080015336 list.name = "bss_transition";
15337 list.value = activate?"1":"0";
developere40952c2023-06-15 18:46:43 +080015338 res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,apIndex);
15339 if (os_snprintf_error(sizeof(config_file), res)) {
15340 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15341 return RETURN_ERR;
15342 }
developera3511852023-06-14 14:12:59 +080015343 wifi_hostapdWrite(config_file, &list, 1);
developer9f2358c2023-09-22 18:42:12 +080015344 multiple_set = false;
15345 wifi_hostapdProcessUpdate(apIndex, &list, 1);
15346 wifi_quick_reload_ap(apIndex);
15347 multiple_set = temp_multiple_set;
developer72fb0bb2023-01-11 09:46:29 +080015348
developera3511852023-06-14 14:12:59 +080015349 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015350}
developer9f2358c2023-09-22 18:42:12 +080015351
15352
developer72fb0bb2023-01-11 09:46:29 +080015353wifi_apAuthEvent_callback apAuthEvent_cb = NULL;
15354
15355void wifi_apAuthEvent_callback_register(wifi_apAuthEvent_callback callback_proc)
15356{
developera3511852023-06-14 14:12:59 +080015357 return;
developer72fb0bb2023-01-11 09:46:29 +080015358}
15359
15360INT wifi_setApCsaDeauth(INT apIndex, INT mode)
15361{
developera3511852023-06-14 14:12:59 +080015362 // TODO Implement me!
15363 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015364}
15365
15366INT wifi_setApScanFilter(INT apIndex, INT mode, CHAR *essid)
15367{
developera3511852023-06-14 14:12:59 +080015368 char file_name[128] = {0};
15369 FILE *f = NULL;
15370 int max_num_radios = 0;
developer75bd10c2023-06-27 11:34:08 +080015371 int res, ret;
developer72fb0bb2023-01-11 09:46:29 +080015372
developera3511852023-06-14 14:12:59 +080015373 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080015374
developera3511852023-06-14 14:12:59 +080015375 wifi_getMaxRadioNumber(&max_num_radios);
15376 if (essid == NULL || strlen(essid) == 0 || apIndex == -1) {
15377 for (int index = 0; index < max_num_radios; index++) {
developere40952c2023-06-15 18:46:43 +080015378 res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, index);
15379 if (os_snprintf_error(sizeof(file_name), res)) {
15380 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15381 return RETURN_ERR;
15382 }
15383
developera3511852023-06-14 14:12:59 +080015384 f = fopen(file_name, "w");
15385 if (f == NULL)
15386 return RETURN_ERR;
15387 // For mode == 0 is to disable filter, just don't write to the file.
developer75bd10c2023-06-27 11:34:08 +080015388 if (mode) {
15389 ret = fprintf(f, "%s", essid);
15390 if (ret < 0)
15391 wifi_debug(DEBUG_ERROR, "fprintf fail\n");
15392 }
developer72fb0bb2023-01-11 09:46:29 +080015393
developerd14dff12023-06-28 22:47:44 +080015394 if (fclose(f) != 0) {
15395 wifi_debug(DEBUG_ERROR, "fclose fail\n");
15396 return RETURN_ERR;
15397 }
developera3511852023-06-14 14:12:59 +080015398 }
15399 } else { // special case, need to set AP's SSID as filter for each radio.
developere40952c2023-06-15 18:46:43 +080015400 res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, apIndex);
15401 if (os_snprintf_error(sizeof(file_name), res)) {
15402 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15403 return RETURN_ERR;
15404 }
15405
developera3511852023-06-14 14:12:59 +080015406 f = fopen(file_name, "w");
15407 if (f == NULL)
15408 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015409
developera3511852023-06-14 14:12:59 +080015410 // For mode == 0 is to disable filter, just don't write to the file.
developer75bd10c2023-06-27 11:34:08 +080015411 if (mode) {
15412 ret = fprintf(f, "%s", essid);
15413 if (ret < 0)
15414 wifi_debug(DEBUG_ERROR, "fprintf fail\n");
15415 }
developer72fb0bb2023-01-11 09:46:29 +080015416
developer37646972023-06-29 10:58:43 +080015417 if (fclose(f) == EOF) {
15418 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
15419 return RETURN_ERR;
15420 }
developera3511852023-06-14 14:12:59 +080015421 }
developer72fb0bb2023-01-11 09:46:29 +080015422
developera3511852023-06-14 14:12:59 +080015423 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
15424 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015425}
15426
15427INT wifi_pushRadioChannel(INT radioIndex, UINT channel)
15428{
developera3511852023-06-14 14:12:59 +080015429 // TODO Implement me!
15430 //Apply wifi_pushRadioChannel() instantly
15431 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015432}
15433
15434INT wifi_setRadioStatsEnable(INT radioIndex, BOOL enable)
15435{
developera3511852023-06-14 14:12:59 +080015436 // TODO Implement me!
15437 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015438}
15439
developer72fb0bb2023-01-11 09:46:29 +080015440
developera3511852023-06-14 14:12:59 +080015441static int tidStats_callback(struct nl_msg *msg, void *arg) {
15442 struct nlattr *tb[NL80211_ATTR_MAX + 1];
15443 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
15444 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
15445 struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1],*tidattr;
15446 int rem , tid_index = 0;
developer72fb0bb2023-01-11 09:46:29 +080015447
developera3511852023-06-14 14:12:59 +080015448 wifi_associated_dev_tid_stats_t *out = (wifi_associated_dev_tid_stats_t*)arg;
15449 wifi_associated_dev_tid_entry_t *stats_entry;
developer72fb0bb2023-01-11 09:46:29 +080015450
developera3511852023-06-14 14:12:59 +080015451 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
15452 [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED },
15453 };
15454 static struct nla_policy tid_policy[NL80211_TID_STATS_MAX + 1] = {
15455 [NL80211_TID_STATS_TX_MSDU] = { .type = NLA_U64 },
15456 };
developer72fb0bb2023-01-11 09:46:29 +080015457
developera3511852023-06-14 14:12:59 +080015458 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
15459 genlmsg_attrlen(gnlh, 0), NULL);
developer72fb0bb2023-01-11 09:46:29 +080015460
developer72fb0bb2023-01-11 09:46:29 +080015461
developera3511852023-06-14 14:12:59 +080015462 if (!tb[NL80211_ATTR_STA_INFO]) {
developer75bd10c2023-06-27 11:34:08 +080015463 wifi_debug(DEBUG_ERROR, "station stats missing!\n");
developera3511852023-06-14 14:12:59 +080015464 return NL_SKIP;
15465 }
developer72fb0bb2023-01-11 09:46:29 +080015466
developera3511852023-06-14 14:12:59 +080015467 if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
15468 tb[NL80211_ATTR_STA_INFO],
15469 stats_policy)) {
developer75bd10c2023-06-27 11:34:08 +080015470 wifi_debug(DEBUG_ERROR, "failed to parse nested attributes!\n");
developera3511852023-06-14 14:12:59 +080015471 return NL_SKIP;
15472 }
developer72fb0bb2023-01-11 09:46:29 +080015473
developera3511852023-06-14 14:12:59 +080015474 if (sinfo[NL80211_STA_INFO_TID_STATS]) {
15475 nla_for_each_nested(tidattr, sinfo[NL80211_STA_INFO_TID_STATS], rem)
15476 {
15477 stats_entry = &out->tid_array[tid_index];
developer72fb0bb2023-01-11 09:46:29 +080015478
developera3511852023-06-14 14:12:59 +080015479 stats_entry->tid = tid_index;
15480 stats_entry->ac = _tid_ac_index_get[tid_index];
developer72fb0bb2023-01-11 09:46:29 +080015481
developera3511852023-06-14 14:12:59 +080015482 if(sinfo[NL80211_STA_INFO_TID_STATS])
15483 {
15484 if(nla_parse_nested(stats_info, NL80211_TID_STATS_MAX,tidattr, tid_policy)) {
15485 printf("failed to parse nested stats attributes!");
15486 return NL_SKIP;
15487 }
15488 }
15489 if(stats_info[NL80211_TID_STATS_TX_MSDU])
15490 stats_entry->num_msdus = (unsigned long long)nla_get_u64(stats_info[NL80211_TID_STATS_TX_MSDU]);
developer72fb0bb2023-01-11 09:46:29 +080015491
developera3511852023-06-14 14:12:59 +080015492 if(tid_index < (PS_MAX_TID - 1))
15493 tid_index++;
15494 }
15495 }
15496 //ToDo: sum_time_ms, ewma_time_ms
15497 return NL_SKIP;
15498}
developer72fb0bb2023-01-11 09:46:29 +080015499
developera3511852023-06-14 14:12:59 +080015500INT wifi_getApAssociatedDeviceTidStatsResult(INT radioIndex, mac_address_t *clientMacAddress, wifi_associated_dev_tid_stats_t *tid_stats, ULLONG *handle)
15501{
15502 Netlink nl;
15503 char if_name[IF_NAME_SIZE];
15504 char interface_name[IF_NAME_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +080015505 int res;
developer72fb0bb2023-01-11 09:46:29 +080015506
developera3511852023-06-14 14:12:59 +080015507 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
15508 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015509
developere40952c2023-06-15 18:46:43 +080015510 res = snprintf(if_name, sizeof(if_name), "%s", interface_name);
15511 if (os_snprintf_error(sizeof(if_name), res)) {
15512 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15513 return RETURN_ERR;
15514 }
developer72fb0bb2023-01-11 09:46:29 +080015515
developera3511852023-06-14 14:12:59 +080015516 nl.id = initSock80211(&nl);
developer72fb0bb2023-01-11 09:46:29 +080015517
developera3511852023-06-14 14:12:59 +080015518 if (nl.id < 0) {
developer75bd10c2023-06-27 11:34:08 +080015519 wifi_debug(DEBUG_ERROR, "Error initializing netlink \n");
developera3511852023-06-14 14:12:59 +080015520 return -1;
15521 }
developer72fb0bb2023-01-11 09:46:29 +080015522
developera3511852023-06-14 14:12:59 +080015523 struct nl_msg* msg = nlmsg_alloc();
developer72fb0bb2023-01-11 09:46:29 +080015524
developera3511852023-06-14 14:12:59 +080015525 if (!msg) {
developer75bd10c2023-06-27 11:34:08 +080015526 wifi_debug(DEBUG_ERROR, "Failed to allocate netlink message.\n");
developera3511852023-06-14 14:12:59 +080015527 nlfree(&nl);
15528 return -2;
15529 }
developer72fb0bb2023-01-11 09:46:29 +080015530
developera3511852023-06-14 14:12:59 +080015531 genlmsg_put(msg,
15532 NL_AUTO_PID,
15533 NL_AUTO_SEQ,
15534 nl.id,
15535 0,
15536 0,
15537 NL80211_CMD_GET_STATION,
15538 0);
developer72fb0bb2023-01-11 09:46:29 +080015539
developera3511852023-06-14 14:12:59 +080015540 nla_put(msg, NL80211_ATTR_MAC, MAC_ALEN, clientMacAddress);
15541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(if_name));
15542 nl_cb_set(nl.cb,NL_CB_VALID,NL_CB_CUSTOM,tidStats_callback,tid_stats);
15543 nl_send_auto_complete(nl.socket, msg);
15544 nl_recvmsgs(nl.socket, nl.cb);
15545 nlmsg_free(msg);
15546 nlfree(&nl);
15547 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015548}
15549
15550
15551INT wifi_startNeighborScan(INT apIndex, wifi_neighborScanMode_t scan_mode, INT dwell_time, UINT chan_num, UINT *chan_list)
15552{
developera3511852023-06-14 14:12:59 +080015553 char interface_name[16] = {0};
developera3511852023-06-14 14:12:59 +080015554 char buf[128]={0};
15555 int freq = 0;
developere40952c2023-06-15 18:46:43 +080015556 int res;
developer72fb0bb2023-01-11 09:46:29 +080015557
developera3511852023-06-14 14:12:59 +080015558 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080015559
developera3511852023-06-14 14:12:59 +080015560 // full mode is used to scan all channels.
15561 // multiple channels is ambiguous, iw can not set multiple frequencies in one time.
15562 if (scan_mode != WIFI_RADIO_SCAN_MODE_FULL)
15563 ieee80211_channel_to_frequency(chan_list[0], &freq);
developer72fb0bb2023-01-11 09:46:29 +080015564
developera3511852023-06-14 14:12:59 +080015565 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
15566 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015567
developera3511852023-06-14 14:12:59 +080015568 if (freq)
developer8078acf2023-08-04 18:52:48 +080015569 res = _syscmd_secure(buf, sizeof(buf), "iw dev %s scan trigger duration %d freq %d", interface_name, dwell_time, freq);
developera3511852023-06-14 14:12:59 +080015570 else
developer8078acf2023-08-04 18:52:48 +080015571 res = _syscmd_secure(buf, sizeof(buf), "iw dev %s scan trigger duration %d", interface_name, dwell_time);
15572 if (res) {
15573 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080015574 }
developer72fb0bb2023-01-11 09:46:29 +080015575
developera3511852023-06-14 14:12:59 +080015576 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080015577
developera3511852023-06-14 14:12:59 +080015578 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015579}
15580
15581
15582INT wifi_steering_setGroup(UINT steeringgroupIndex, wifi_steering_apConfig_t *cfg_2, wifi_steering_apConfig_t *cfg_5)
15583{
developera3511852023-06-14 14:12:59 +080015584 // TODO Implement me!
15585 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015586}
15587
15588INT wifi_steering_clientSet(UINT steeringgroupIndex, INT apIndex, mac_address_t client_mac, wifi_steering_clientConfig_t *config)
15589{
developera3511852023-06-14 14:12:59 +080015590 // TODO Implement me!
15591 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015592}
15593
15594INT wifi_steering_clientRemove(UINT steeringgroupIndex, INT apIndex, mac_address_t client_mac)
15595{
developera3511852023-06-14 14:12:59 +080015596 // TODO Implement me!
15597 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015598}
15599
15600INT wifi_steering_clientMeasure(UINT steeringgroupIndex, INT apIndex, mac_address_t client_mac)
15601{
developera3511852023-06-14 14:12:59 +080015602 // TODO Implement me!
15603 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015604}
15605
15606INT wifi_steering_clientDisconnect(UINT steeringgroupIndex, INT apIndex, mac_address_t client_mac, wifi_disconnectType_t type, UINT reason)
15607{
developera3511852023-06-14 14:12:59 +080015608 // TODO Implement me!
15609 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015610}
15611
15612INT wifi_steering_eventRegister(wifi_steering_eventCB_t event_cb)
15613{
developera3511852023-06-14 14:12:59 +080015614 // TODO Implement me!
15615 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015616}
15617
15618INT wifi_steering_eventUnregister(void)
15619{
developera3511852023-06-14 14:12:59 +080015620 // TODO Implement me!
15621 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015622}
15623
15624INT wifi_delApAclDevices(INT apIndex)
15625{
developer7e4a2a62023-04-06 19:56:03 +080015626 char inf_name[IF_NAME_SIZE] = {0};
developer2edaf012023-05-24 14:24:53 +080015627 struct unl unl_ins;
15628 int if_idx = 0, ret = 0;
15629 struct nl_msg *msg = NULL;
15630 struct nlattr * msg_data = NULL;
15631 struct mtk_nl80211_param param;
developer72fb0bb2023-01-11 09:46:29 +080015632
developer7e4a2a62023-04-06 19:56:03 +080015633 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
15634 return RETURN_ERR;
developer2edaf012023-05-24 14:24:53 +080015635 if_idx = if_nametoindex(inf_name);
15636 if (!if_idx) {
15637 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
15638 return RETURN_ERR;
15639 }
15640 /*init mtk nl80211 vendor cmd*/
15641 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_ACL;
15642 param.if_type = NL80211_ATTR_IFINDEX;
15643 param.if_idx = if_idx;
15644 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
15645 if (ret) {
15646 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
15647 return RETURN_ERR;
15648 }
15649 /*add mtk vendor cmd data*/
15650 if (nla_put_flag(msg, MTK_NL80211_VENDOR_ATTR_ACL_CLEAR_ALL)) {
15651 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
15652 nlmsg_free(msg);
15653 goto err;
15654 }
15655 /*send mtk nl80211 vendor msg*/
15656 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
15657 if (ret) {
15658 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
15659 goto err;
15660 }
15661 /*deinit mtk nl80211 vendor msg*/
15662 mtk_nl80211_deint(&unl_ins);
15663 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
15664 return RETURN_OK;
15665err:
15666 mtk_nl80211_deint(&unl_ins);
15667 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
15668 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015669
developera3511852023-06-14 14:12:59 +080015670 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015671}
15672
developer72fb0bb2023-01-11 09:46:29 +080015673static int rxStatsInfo_callback(struct nl_msg *msg, void *arg) {
developera3511852023-06-14 14:12:59 +080015674 struct nlattr *tb[NL80211_ATTR_MAX + 1];
15675 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
developerc14d83a2023-06-29 20:09:42 +080015676 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1] = {NULL};
15677 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1] = {NULL};
developera3511852023-06-14 14:12:59 +080015678 struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1];
15679 char mac_addr[20],dev[20];
developer72fb0bb2023-01-11 09:46:29 +080015680
developera3511852023-06-14 14:12:59 +080015681 nla_parse(tb,
15682 NL80211_ATTR_MAX,
15683 genlmsg_attrdata(gnlh, 0),
15684 genlmsg_attrlen(gnlh, 0),
15685 NULL);
developer72fb0bb2023-01-11 09:46:29 +080015686
developera3511852023-06-14 14:12:59 +080015687 if (!tb[NL80211_ATTR_STA_INFO]) {
developer75bd10c2023-06-27 11:34:08 +080015688 wifi_debug(DEBUG_ERROR, "sta stats missing!\n");
developera3511852023-06-14 14:12:59 +080015689 return NL_SKIP;
15690 }
developer72fb0bb2023-01-11 09:46:29 +080015691
developera3511852023-06-14 14:12:59 +080015692 if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,tb[NL80211_ATTR_STA_INFO], stats_policy)) {
developer75bd10c2023-06-27 11:34:08 +080015693 wifi_debug(DEBUG_ERROR, "failed to parse nested attributes!\n");
developera3511852023-06-14 14:12:59 +080015694 return NL_SKIP;
15695 }
15696 mac_addr_ntoa(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
developer72fb0bb2023-01-11 09:46:29 +080015697
developera3511852023-06-14 14:12:59 +080015698 if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
developer72fb0bb2023-01-11 09:46:29 +080015699
developera3511852023-06-14 14:12:59 +080015700 if (sinfo[NL80211_STA_INFO_RX_BITRATE]) {
15701 if(nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, sinfo[NL80211_STA_INFO_RX_BITRATE], rate_policy )) {
developer75bd10c2023-06-27 11:34:08 +080015702 wifi_debug(DEBUG_ERROR, "failed to parse nested rate attributes!");
developera3511852023-06-14 14:12:59 +080015703 return NL_SKIP;
15704 }
15705 }
developer72fb0bb2023-01-11 09:46:29 +080015706
developera3511852023-06-14 14:12:59 +080015707 if (sinfo[NL80211_STA_INFO_TID_STATS]) {
15708 if(nla_parse_nested(stats_info, NL80211_TID_STATS_MAX,sinfo[NL80211_STA_INFO_TID_STATS], tid_policy)) {
15709 printf("failed to parse nested stats attributes!");
15710 return NL_SKIP;
15711 }
15712 }
15713 if (tb[NL80211_ATTR_VHT_CAPABILITY]) {
developer72fb0bb2023-01-11 09:46:29 +080015714
developera3511852023-06-14 14:12:59 +080015715 if( nla_data(tb[NL80211_ATTR_VHT_CAPABILITY]) )
15716 {
15717 printf("Type is VHT\n");
15718 if(rinfo[NL80211_RATE_INFO_VHT_NSS])
15719 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->nss = nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS]);
developer72fb0bb2023-01-11 09:46:29 +080015720
developera3511852023-06-14 14:12:59 +080015721 if(rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
15722 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bw = 1;
15723 if(rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH])
15724 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bw = 2;
15725 if(rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH])
15726 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bw = 2;
15727 if(rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH])
15728 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bw = 2;
15729 if((rinfo[NL80211_RATE_INFO_10_MHZ_WIDTH]) || (rinfo[NL80211_RATE_INFO_5_MHZ_WIDTH]) )
15730 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bw = 0;
15731 } else {
15732 printf(" OFDM or CCK \n");
15733 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bw = 0;
15734 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->nss = 0;
15735 }
15736 }
developer72fb0bb2023-01-11 09:46:29 +080015737
developera3511852023-06-14 14:12:59 +080015738 if (sinfo[NL80211_STA_INFO_RX_BITRATE]) {
developereff896f2023-05-29 14:52:55 +080015739 if(rinfo[NL80211_RATE_INFO_MCS])
15740 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->mcs = nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]);
15741 }
developera3511852023-06-14 14:12:59 +080015742 if (sinfo[NL80211_STA_INFO_RX_BYTES64])
developereff896f2023-05-29 14:52:55 +080015743 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bytes = nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64]);
15744 else if (sinfo[NL80211_STA_INFO_RX_BYTES])
15745 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->bytes = nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES]);
developer72fb0bb2023-01-11 09:46:29 +080015746
developera3511852023-06-14 14:12:59 +080015747 if (sinfo[NL80211_STA_INFO_TID_STATS]) {
15748 if (stats_info[NL80211_TID_STATS_RX_MSDU])
developereff896f2023-05-29 14:52:55 +080015749 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->msdus = nla_get_u64(stats_info[NL80211_TID_STATS_RX_MSDU]);
15750 }
developer72fb0bb2023-01-11 09:46:29 +080015751
developereff896f2023-05-29 14:52:55 +080015752 if (sinfo[NL80211_STA_INFO_SIGNAL])
15753 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->rssi_combined = nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
15754 //Assigning 0 for RETRIES ,PPDUS and MPDUS as we dont have rx retries attribute in libnl_3.3.0
15755 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->retries = 0;
15756 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->ppdus = 0;
15757 ((wifi_associated_dev_rate_info_rx_stats_t*)arg)->msdus = 0;
15758 //rssi_array need to be filled
15759 return NL_SKIP;
developer72fb0bb2023-01-11 09:46:29 +080015760}
developer72fb0bb2023-01-11 09:46:29 +080015761
15762INT wifi_getApAssociatedDeviceRxStatsResult(INT radioIndex, mac_address_t *clientMacAddress, wifi_associated_dev_rate_info_rx_stats_t **stats_array, UINT *output_array_size, ULLONG *handle)
15763{
developera3511852023-06-14 14:12:59 +080015764 Netlink nl;
15765 char if_name[32];
15766 if (wifi_GetInterfaceName(radioIndex, if_name) != RETURN_OK)
15767 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015768
developera3511852023-06-14 14:12:59 +080015769 *output_array_size = sizeof(wifi_associated_dev_rate_info_rx_stats_t);
developer72fb0bb2023-01-11 09:46:29 +080015770
developera3511852023-06-14 14:12:59 +080015771 if (*output_array_size <= 0)
15772 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015773
developera3511852023-06-14 14:12:59 +080015774 nl.id = initSock80211(&nl);
developer72fb0bb2023-01-11 09:46:29 +080015775
developera3511852023-06-14 14:12:59 +080015776 if (nl.id < 0) {
developer75bd10c2023-06-27 11:34:08 +080015777 wifi_debug(DEBUG_ERROR, "Error initializing netlink \n");
developera3511852023-06-14 14:12:59 +080015778 return 0;
15779 }
developer72fb0bb2023-01-11 09:46:29 +080015780
developera3511852023-06-14 14:12:59 +080015781 struct nl_msg* msg = nlmsg_alloc();
developer72fb0bb2023-01-11 09:46:29 +080015782
developera3511852023-06-14 14:12:59 +080015783 if (!msg) {
developer75bd10c2023-06-27 11:34:08 +080015784 wifi_debug(DEBUG_ERROR, "Failed to allocate netlink message.\n");
developera3511852023-06-14 14:12:59 +080015785 nlfree(&nl);
15786 return 0;
15787 }
developer72fb0bb2023-01-11 09:46:29 +080015788
developera3511852023-06-14 14:12:59 +080015789 genlmsg_put(msg,
15790 NL_AUTO_PID,
15791 NL_AUTO_SEQ,
15792 nl.id,
15793 0,
15794 0,
15795 NL80211_CMD_GET_STATION,
15796 0);
developer72fb0bb2023-01-11 09:46:29 +080015797
developera3511852023-06-14 14:12:59 +080015798 nla_put(msg, NL80211_ATTR_MAC, MAC_ALEN, *clientMacAddress);
15799 nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(if_name));
15800 nl_cb_set(nl.cb, NL_CB_VALID , NL_CB_CUSTOM, rxStatsInfo_callback, stats_array);
15801 nl_send_auto_complete(nl.socket, msg);
15802 nl_recvmsgs(nl.socket, nl.cb);
15803 nlmsg_free(msg);
15804 nlfree(&nl);
15805 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015806}
15807
developer72fb0bb2023-01-11 09:46:29 +080015808static int txStatsInfo_callback(struct nl_msg *msg, void *arg) {
developera3511852023-06-14 14:12:59 +080015809 struct nlattr *tb[NL80211_ATTR_MAX + 1];
15810 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
developerc14d83a2023-06-29 20:09:42 +080015811 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1] = {NULL};
15812 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1] = {NULL};
developera3511852023-06-14 14:12:59 +080015813 struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1];
15814 char mac_addr[20],dev[20];
developer72fb0bb2023-01-11 09:46:29 +080015815
developera3511852023-06-14 14:12:59 +080015816 nla_parse(tb,
15817 NL80211_ATTR_MAX,
15818 genlmsg_attrdata(gnlh, 0),
15819 genlmsg_attrlen(gnlh, 0),
15820 NULL);
developer72fb0bb2023-01-11 09:46:29 +080015821
developera3511852023-06-14 14:12:59 +080015822 if(!tb[NL80211_ATTR_STA_INFO]) {
developer75bd10c2023-06-27 11:34:08 +080015823 wifi_debug(DEBUG_ERROR, "sta stats missing!\n");
developera3511852023-06-14 14:12:59 +080015824 return NL_SKIP;
15825 }
developer72fb0bb2023-01-11 09:46:29 +080015826
developera3511852023-06-14 14:12:59 +080015827 if(nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,tb[NL80211_ATTR_STA_INFO], stats_policy)) {
developer75bd10c2023-06-27 11:34:08 +080015828 wifi_debug(DEBUG_ERROR, "failed to parse nested attributes!\n");
developera3511852023-06-14 14:12:59 +080015829 return NL_SKIP;
15830 }
developer72fb0bb2023-01-11 09:46:29 +080015831
developera3511852023-06-14 14:12:59 +080015832 mac_addr_ntoa(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
developer72fb0bb2023-01-11 09:46:29 +080015833
developera3511852023-06-14 14:12:59 +080015834 if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
developer72fb0bb2023-01-11 09:46:29 +080015835
developera3511852023-06-14 14:12:59 +080015836 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
15837 if(nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, sinfo[NL80211_STA_INFO_TX_BITRATE], rate_policy)) {
developer75bd10c2023-06-27 11:34:08 +080015838 wifi_debug(DEBUG_ERROR, "failed to parse nested rate attributes!");
developera3511852023-06-14 14:12:59 +080015839 return NL_SKIP;
15840 }
15841 }
developer72fb0bb2023-01-11 09:46:29 +080015842
developera3511852023-06-14 14:12:59 +080015843 if(sinfo[NL80211_STA_INFO_TID_STATS])
15844 {
15845 if(nla_parse_nested(stats_info, NL80211_TID_STATS_MAX,sinfo[NL80211_STA_INFO_TID_STATS], tid_policy)) {
15846 printf("failed to parse nested stats attributes!");
15847 return NL_SKIP;
15848 }
15849 }
15850 if (tb[NL80211_ATTR_VHT_CAPABILITY]) {
15851 if(nla_data(tb[NL80211_ATTR_VHT_CAPABILITY]))
15852 {
15853 printf("Type is VHT\n");
15854 if(rinfo[NL80211_RATE_INFO_VHT_NSS])
15855 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->nss = nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS]);
developer72fb0bb2023-01-11 09:46:29 +080015856
developera3511852023-06-14 14:12:59 +080015857 if(rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
15858 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bw = 1;
15859 if(rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH])
15860 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bw = 2;
15861 if(rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH])
15862 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bw = 2;
15863 if(rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH])
15864 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bw = 2;
15865 if((rinfo[NL80211_RATE_INFO_10_MHZ_WIDTH]) || (rinfo[NL80211_RATE_INFO_5_MHZ_WIDTH]))
15866 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bw = 0;
15867 }
15868 else
15869 {
15870 printf(" OFDM or CCK \n");
15871 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bw = 0;
15872 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->nss = 0;
15873 }
15874 }
developer72fb0bb2023-01-11 09:46:29 +080015875
developera3511852023-06-14 14:12:59 +080015876 if(sinfo[NL80211_STA_INFO_TX_BITRATE]) {
15877 if(rinfo[NL80211_RATE_INFO_MCS])
15878 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->mcs = nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]);
15879 }
developer72fb0bb2023-01-11 09:46:29 +080015880
developera3511852023-06-14 14:12:59 +080015881 if(sinfo[NL80211_STA_INFO_TX_BYTES64])
15882 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bytes = nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64]);
15883 else if (sinfo[NL80211_STA_INFO_TX_BYTES])
15884 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->bytes = nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES]);
developer72fb0bb2023-01-11 09:46:29 +080015885
developera3511852023-06-14 14:12:59 +080015886 //Assigning 0 for mpdus and ppdus , as we do not have attributes in netlink
15887 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->mpdus = 0;
15888 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->mpdus = 0;
developer72fb0bb2023-01-11 09:46:29 +080015889
developera3511852023-06-14 14:12:59 +080015890 if(sinfo[NL80211_STA_INFO_TID_STATS]) {
15891 if(stats_info[NL80211_TID_STATS_TX_MSDU])
15892 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->msdus = nla_get_u64(stats_info[NL80211_TID_STATS_TX_MSDU]);
15893 }
developer72fb0bb2023-01-11 09:46:29 +080015894
developera3511852023-06-14 14:12:59 +080015895 if(sinfo[NL80211_STA_INFO_TX_RETRIES])
15896 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->retries = nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES]);
developer72fb0bb2023-01-11 09:46:29 +080015897
developera3511852023-06-14 14:12:59 +080015898 if(sinfo[NL80211_STA_INFO_TX_FAILED] && sinfo[NL80211_STA_INFO_TX_PACKETS])
15899 ((wifi_associated_dev_rate_info_tx_stats_t*)arg)->attempts = nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS]) + nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED]);
developer72fb0bb2023-01-11 09:46:29 +080015900
developera3511852023-06-14 14:12:59 +080015901 return NL_SKIP;
developer72fb0bb2023-01-11 09:46:29 +080015902}
developer72fb0bb2023-01-11 09:46:29 +080015903
15904INT wifi_getApAssociatedDeviceTxStatsResult(INT radioIndex, mac_address_t *clientMacAddress, wifi_associated_dev_rate_info_tx_stats_t **stats_array, UINT *output_array_size, ULLONG *handle)
15905{
developera3511852023-06-14 14:12:59 +080015906 Netlink nl;
15907 char if_name[IF_NAME_SIZE];
15908 char interface_name[IF_NAME_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +080015909 int res;
15910
developera3511852023-06-14 14:12:59 +080015911 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
15912 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080015913
developera3511852023-06-14 14:12:59 +080015914 *output_array_size = sizeof(wifi_associated_dev_rate_info_tx_stats_t);
developer72fb0bb2023-01-11 09:46:29 +080015915
developera3511852023-06-14 14:12:59 +080015916 if (*output_array_size <= 0)
15917 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015918
developere40952c2023-06-15 18:46:43 +080015919 res = snprintf(if_name, sizeof(if_name), "%s", interface_name);
15920 if (os_snprintf_error(sizeof(if_name), res)) {
15921 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15922 return RETURN_ERR;
15923 }
developer72fb0bb2023-01-11 09:46:29 +080015924
developera3511852023-06-14 14:12:59 +080015925 nl.id = initSock80211(&nl);
developer72fb0bb2023-01-11 09:46:29 +080015926
developera3511852023-06-14 14:12:59 +080015927 if(nl.id < 0) {
developer75bd10c2023-06-27 11:34:08 +080015928 wifi_debug(DEBUG_ERROR, "Error initializing netlink \n");
developera3511852023-06-14 14:12:59 +080015929 return 0;
15930 }
developer72fb0bb2023-01-11 09:46:29 +080015931
developera3511852023-06-14 14:12:59 +080015932 struct nl_msg* msg = nlmsg_alloc();
developer72fb0bb2023-01-11 09:46:29 +080015933
developera3511852023-06-14 14:12:59 +080015934 if(!msg) {
developer75bd10c2023-06-27 11:34:08 +080015935 wifi_debug(DEBUG_ERROR, "Failed to allocate netlink message.\n");
developera3511852023-06-14 14:12:59 +080015936 nlfree(&nl);
15937 return 0;
15938 }
developer72fb0bb2023-01-11 09:46:29 +080015939
developera3511852023-06-14 14:12:59 +080015940 genlmsg_put(msg,
15941 NL_AUTO_PID,
15942 NL_AUTO_SEQ,
15943 nl.id,
15944 0,
15945 0,
15946 NL80211_CMD_GET_STATION,
15947 0);
developer72fb0bb2023-01-11 09:46:29 +080015948
developera3511852023-06-14 14:12:59 +080015949 nla_put(msg, NL80211_ATTR_MAC, MAC_ALEN, clientMacAddress);
15950 nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(if_name));
15951 nl_cb_set(nl.cb, NL_CB_VALID , NL_CB_CUSTOM, txStatsInfo_callback, stats_array);
15952 nl_send_auto_complete(nl.socket, msg);
15953 nl_recvmsgs(nl.socket, nl.cb);
15954 nlmsg_free(msg);
15955 nlfree(&nl);
15956 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015957}
15958
15959INT wifi_getBSSTransitionActivation(UINT apIndex, BOOL *activate)
15960{
developera3511852023-06-14 14:12:59 +080015961 // TODO Implement me!
15962 char buf[MAX_BUF_SIZE] = {0};
15963 char config_file[MAX_BUF_SIZE] = {0};
developere40952c2023-06-15 18:46:43 +080015964 int res;
developer72fb0bb2023-01-11 09:46:29 +080015965
developere40952c2023-06-15 18:46:43 +080015966 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
15967 if (os_snprintf_error(sizeof(config_file), res)) {
15968 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15969 return RETURN_ERR;
15970 }
developera3511852023-06-14 14:12:59 +080015971 wifi_hostapdRead(config_file, "bss_transition", buf, sizeof(buf));
15972 *activate = (strncmp("1",buf,1) == 0);
developer72fb0bb2023-01-11 09:46:29 +080015973
developera3511852023-06-14 14:12:59 +080015974 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080015975}
15976
15977INT wifi_setNeighborReportActivation(UINT apIndex, BOOL activate)
15978{
developera3511852023-06-14 14:12:59 +080015979 char config_file[MAX_BUF_SIZE] = {0};
15980 struct params list;
developer75bd10c2023-06-27 11:34:08 +080015981 int res;
developer9f2358c2023-09-22 18:42:12 +080015982 bool temp_multiple_set = multiple_set;
developer72fb0bb2023-01-11 09:46:29 +080015983
developera3511852023-06-14 14:12:59 +080015984 list.name = "rrm_neighbor_report";
15985 list.value = activate?"1":"0";
developer75bd10c2023-06-27 11:34:08 +080015986 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
15987 if (os_snprintf_error(sizeof(config_file), res)) {
15988 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
15989 return RETURN_ERR;
15990 }
developer9f2358c2023-09-22 18:42:12 +080015991
developera3511852023-06-14 14:12:59 +080015992 wifi_hostapdWrite(config_file, &list, 1);
developer72fb0bb2023-01-11 09:46:29 +080015993
developer9f2358c2023-09-22 18:42:12 +080015994 multiple_set = false;
15995 wifi_hostapdProcessUpdate(apIndex, &list, 1);
15996 wifi_quick_reload_ap(apIndex);
15997 multiple_set = temp_multiple_set;
15998
developera3511852023-06-14 14:12:59 +080015999 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016000}
16001
developer9f2358c2023-09-22 18:42:12 +080016002
developer72fb0bb2023-01-11 09:46:29 +080016003INT wifi_getNeighborReportActivation(UINT apIndex, BOOL *activate)
16004{
developera3511852023-06-14 14:12:59 +080016005 char buf[32] = {0};
16006 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +080016007 int res;
developer72fb0bb2023-01-11 09:46:29 +080016008
developer75bd10c2023-06-27 11:34:08 +080016009 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
16010 if (os_snprintf_error(sizeof(config_file), res)) {
16011 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16012 return RETURN_ERR;
16013 }
developera3511852023-06-14 14:12:59 +080016014 wifi_hostapdRead(config_file, "rrm_neighbor_report", buf, sizeof(buf));
16015 *activate = (strncmp("1",buf,1) == 0);
developer72fb0bb2023-01-11 09:46:29 +080016016
developera3511852023-06-14 14:12:59 +080016017 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016018}
16019#undef HAL_NETLINK_IMPL
16020#ifdef HAL_NETLINK_IMPL
16021static int chanSurveyInfo_callback(struct nl_msg *msg, void *arg) {
developera3511852023-06-14 14:12:59 +080016022 struct nlattr *tb[NL80211_ATTR_MAX + 1];
16023 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
16024 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
16025 char dev[20];
16026 int freq =0 ;
16027 static int i=0;
developer72fb0bb2023-01-11 09:46:29 +080016028
developera3511852023-06-14 14:12:59 +080016029 wifi_channelStats_t_loc *out = (wifi_channelStats_t_loc*)arg;
developer72fb0bb2023-01-11 09:46:29 +080016030
developera3511852023-06-14 14:12:59 +080016031 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
16032 };
developer72fb0bb2023-01-11 09:46:29 +080016033
developera3511852023-06-14 14:12:59 +080016034 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),genlmsg_attrlen(gnlh, 0), NULL);
developer72fb0bb2023-01-11 09:46:29 +080016035
developera3511852023-06-14 14:12:59 +080016036 if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
developer72fb0bb2023-01-11 09:46:29 +080016037
developera3511852023-06-14 14:12:59 +080016038 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
16039 fprintf(stderr, "survey data missing!\n");
16040 return NL_SKIP;
16041 }
developer72fb0bb2023-01-11 09:46:29 +080016042
developera3511852023-06-14 14:12:59 +080016043 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,tb[NL80211_ATTR_SURVEY_INFO],survey_policy))
16044 {
16045 fprintf(stderr, "failed to parse nested attributes!\n");
16046 return NL_SKIP;
16047 }
developer72fb0bb2023-01-11 09:46:29 +080016048
16049
developera3511852023-06-14 14:12:59 +080016050 if(out[0].array_size == 1 )
16051 {
16052 if(sinfo[NL80211_SURVEY_INFO_IN_USE])
16053 {
16054 if (sinfo[NL80211_SURVEY_INFO_FREQUENCY])
16055 freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
16056 out[0].ch_number = ieee80211_frequency_to_channel(freq);
developer72fb0bb2023-01-11 09:46:29 +080016057
developera3511852023-06-14 14:12:59 +080016058 if (sinfo[NL80211_SURVEY_INFO_NOISE])
16059 out[0].ch_noise = nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
16060 if (sinfo[NL80211_SURVEY_INFO_TIME_RX])
16061 out[0].ch_utilization_busy_rx = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_RX]);
16062 if (sinfo[NL80211_SURVEY_INFO_TIME_TX])
16063 out[0].ch_utilization_busy_tx = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_TX]);
16064 if (sinfo[NL80211_SURVEY_INFO_TIME_BUSY])
16065 out[0].ch_utilization_busy = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_BUSY]);
16066 if (sinfo[NL80211_SURVEY_INFO_TIME_EXT_BUSY])
16067 out[0].ch_utilization_busy_ext = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_EXT_BUSY]);
16068 if (sinfo[NL80211_SURVEY_INFO_TIME])
16069 out[0].ch_utilization_total = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME]);
16070 return NL_STOP;
16071 }
16072 } else {
16073 if ( i <= out[0].array_size ) {
16074 if (sinfo[NL80211_SURVEY_INFO_FREQUENCY])
16075 freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
16076 out[i].ch_number = ieee80211_frequency_to_channel(freq);
developer72fb0bb2023-01-11 09:46:29 +080016077
developera3511852023-06-14 14:12:59 +080016078 if (sinfo[NL80211_SURVEY_INFO_NOISE])
16079 out[i].ch_noise = nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
16080 if (sinfo[NL80211_SURVEY_INFO_TIME_RX])
16081 out[i].ch_utilization_busy_rx = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_RX]);
16082 if (sinfo[NL80211_SURVEY_INFO_TIME_TX])
16083 out[i].ch_utilization_busy_tx = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_TX]);
16084 if (sinfo[NL80211_SURVEY_INFO_TIME_BUSY])
16085 out[i].ch_utilization_busy = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_BUSY]);
16086 if (sinfo[NL80211_SURVEY_INFO_TIME_EXT_BUSY])
16087 out[i].ch_utilization_busy_ext = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME_EXT_BUSY]);
16088 if (sinfo[NL80211_SURVEY_INFO_TIME])
16089 out[i].ch_utilization_total = nla_get_u64(sinfo[NL80211_SURVEY_INFO_TIME]);
16090 }
16091 }
developer72fb0bb2023-01-11 09:46:29 +080016092
developera3511852023-06-14 14:12:59 +080016093 i++;
16094 return NL_SKIP;
developer72fb0bb2023-01-11 09:46:29 +080016095}
16096#endif
16097
16098static int ieee80211_channel_to_frequency(int channel, int *freqMHz)
16099{
developer8078acf2023-08-04 18:52:48 +080016100 char output[MAX_BUF_SIZE];
developera3511852023-06-14 14:12:59 +080016101 FILE *fp;
developer8078acf2023-08-04 18:52:48 +080016102
developer72fb0bb2023-01-11 09:46:29 +080016103
developera3511852023-06-14 14:12:59 +080016104 if(access("/tmp/freq-channel-map.txt", F_OK)==-1)
16105 {
16106 printf("Creating Frequency-Channel Map\n");
developer33f13ba2023-07-12 16:19:06 +080016107 v_secure_system("iw phy | grep 'MHz \\[' | cut -d' ' -f2,4 > /tmp/freq-channel-map.txt");
developera3511852023-06-14 14:12:59 +080016108 }
developere40952c2023-06-15 18:46:43 +080016109
developer8078acf2023-08-04 18:52:48 +080016110 if((fp = v_secure_popen("r", "cat /tmp/freq-channel-map.txt | grep '\\[%d\\]$' | cut -d' ' -f1", channel)))
developera3511852023-06-14 14:12:59 +080016111 {
developerc14d83a2023-06-29 20:09:42 +080016112 if (fgets(output, sizeof(output), fp) == NULL) {
16113 wifi_debug(DEBUG_ERROR, "fgets fail\n");
developer8078acf2023-08-04 18:52:48 +080016114 v_secure_pclose(fp);
developerc14d83a2023-06-29 20:09:42 +080016115 return RETURN_ERR;
16116 }
developera3511852023-06-14 14:12:59 +080016117 *freqMHz = atoi(output);
developer8078acf2023-08-04 18:52:48 +080016118 v_secure_pclose(fp);
developera3511852023-06-14 14:12:59 +080016119 }
developer72fb0bb2023-01-11 09:46:29 +080016120
developera3511852023-06-14 14:12:59 +080016121 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016122}
16123
developer2f79c922023-06-02 17:33:42 +080016124static int get_survey_dump_buf(INT radioIndex, int channel, char *buf, size_t bufsz)
developer72fb0bb2023-01-11 09:46:29 +080016125{
developera3511852023-06-14 14:12:59 +080016126 int freqMHz = -1;
16127 char cmd[MAX_CMD_SIZE] = {'\0'};
16128 char interface_name[16] = {0};
developer32f2a182023-06-27 19:50:41 +080016129 int res;
developer72fb0bb2023-01-11 09:46:29 +080016130
developera3511852023-06-14 14:12:59 +080016131 ieee80211_channel_to_frequency(channel, &freqMHz);
16132 if (freqMHz == -1) {
16133 wifi_dbg_printf("%s: failed to get channel frequency for channel: %d\n", __func__, channel);
16134 return -1;
16135 }
developer72fb0bb2023-01-11 09:46:29 +080016136
developer86035662023-06-28 19:21:12 +080016137 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK) {
16138 wifi_debug(DEBUG_ERROR, "wifi_GetInterfaceName fail\n");
16139 }
developer32f2a182023-06-27 19:50:41 +080016140 res = snprintf(cmd, sizeof(cmd), "iw dev %s survey dump | grep -A5 %d | tr -d '\\t'", interface_name, freqMHz);
16141 if (os_snprintf_error(sizeof(cmd), res)) {
16142 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16143 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +080016144 }
developer72fb0bb2023-01-11 09:46:29 +080016145
developer8078acf2023-08-04 18:52:48 +080016146 if (_syscmd_secure(buf, bufsz, "iw dev %s survey dump | grep -A5 %d | tr -d '\\t'", interface_name, freqMHz) == RETURN_ERR) {
developera3511852023-06-14 14:12:59 +080016147 wifi_dbg_printf("%s: failed to execute '%s' for radioIndex=%d\n", __FUNCTION__, cmd, radioIndex);
16148 return -1;
16149 }
developer72fb0bb2023-01-11 09:46:29 +080016150
developera3511852023-06-14 14:12:59 +080016151 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016152}
16153
16154static int fetch_survey_from_buf(INT radioIndex, const char *buf, wifi_channelStats_t *stats)
16155{
developera3511852023-06-14 14:12:59 +080016156 const char *ptr = buf;
16157 char *key = NULL;
16158 char *val = NULL;
16159 char line[256] = { '\0' };
developer72fb0bb2023-01-11 09:46:29 +080016160
developera3511852023-06-14 14:12:59 +080016161 while ((ptr = get_line_from_str_buf(ptr, line))) {
16162 if (strstr(line, "Frequency")) continue;
developer72fb0bb2023-01-11 09:46:29 +080016163
developera3511852023-06-14 14:12:59 +080016164 key = strtok(line, ":");
developerc14d83a2023-06-29 20:09:42 +080016165 if (key == NULL)
16166 continue;
developera3511852023-06-14 14:12:59 +080016167 val = strtok(NULL, " ");
developer37646972023-06-29 10:58:43 +080016168 if (val == NULL)
16169 continue;
developera3511852023-06-14 14:12:59 +080016170 wifi_dbg_printf("%s: key='%s' val='%s'\n", __func__, key, val);
developer72fb0bb2023-01-11 09:46:29 +080016171
developera3511852023-06-14 14:12:59 +080016172 if (!strcmp(key, "noise")) {
developer37646972023-06-29 10:58:43 +080016173 if (sscanf(val, "%d", &stats->ch_noise) == EOF)
16174 continue;
developera3511852023-06-14 14:12:59 +080016175 if (stats->ch_noise == 0) {
16176 // Workaround for missing noise information.
16177 // Assume -95 for 2.4G and -103 for 5G
16178 if (radioIndex == 0) stats->ch_noise = -95;
16179 if (radioIndex == 1) stats->ch_noise = -103;
16180 }
16181 }
16182 else if (!strcmp(key, "channel active time")) {
developer37646972023-06-29 10:58:43 +080016183 if (sscanf(val, "%llu", &stats->ch_utilization_total) == EOF)
16184 continue;
developera3511852023-06-14 14:12:59 +080016185 }
16186 else if (!strcmp(key, "channel busy time")) {
developer37646972023-06-29 10:58:43 +080016187 if (sscanf(val, "%llu", &stats->ch_utilization_busy) == EOF)
16188 continue;
developera3511852023-06-14 14:12:59 +080016189 }
16190 else if (!strcmp(key, "channel receive time")) {
developer37646972023-06-29 10:58:43 +080016191 if (sscanf(val, "%llu", &stats->ch_utilization_busy_rx) == EOF)
16192 continue;
developera3511852023-06-14 14:12:59 +080016193 }
16194 else if (!strcmp(key, "channel transmit time")) {
developer37646972023-06-29 10:58:43 +080016195 if (sscanf(val, "%llu", &stats->ch_utilization_busy_tx) == EOF)
16196 continue;
developera3511852023-06-14 14:12:59 +080016197 }
16198 };
developer72fb0bb2023-01-11 09:46:29 +080016199
developera3511852023-06-14 14:12:59 +080016200 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016201}
16202
16203INT wifi_getRadioChannelStats(INT radioIndex,wifi_channelStats_t *input_output_channelStats_array,INT array_size)
16204{
developera3511852023-06-14 14:12:59 +080016205 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080016206#ifdef HAL_NETLINK_IMPL
developera3511852023-06-14 14:12:59 +080016207 Netlink nl;
16208 wifi_channelStats_t_loc local[array_size];
16209 char if_name[32];
developer72fb0bb2023-01-11 09:46:29 +080016210
developera3511852023-06-14 14:12:59 +080016211 local[0].array_size = array_size;
developer72fb0bb2023-01-11 09:46:29 +080016212
developera3511852023-06-14 14:12:59 +080016213 if (wifi_GetInterfaceName(radioIndex, if_name) != RETURN_OK)
16214 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016215
developera3511852023-06-14 14:12:59 +080016216 nl.id = initSock80211(&nl);
developer72fb0bb2023-01-11 09:46:29 +080016217
developera3511852023-06-14 14:12:59 +080016218 if (nl.id < 0) {
developerc14d83a2023-06-29 20:09:42 +080016219 wifi_debug(DEBUG_ERROR,, "Error initializing netlink \n");
developera3511852023-06-14 14:12:59 +080016220 return -1;
16221 }
developer72fb0bb2023-01-11 09:46:29 +080016222
developera3511852023-06-14 14:12:59 +080016223 struct nl_msg* msg = nlmsg_alloc();
developer72fb0bb2023-01-11 09:46:29 +080016224
developera3511852023-06-14 14:12:59 +080016225 if (!msg) {
developerc14d83a2023-06-29 20:09:42 +080016226 wifi_debug(DEBUG_ERROR,, "Failed to allocate netlink message.\n");
developera3511852023-06-14 14:12:59 +080016227 nlfree(&nl);
16228 return -2;
16229 }
developer72fb0bb2023-01-11 09:46:29 +080016230
developera3511852023-06-14 14:12:59 +080016231 genlmsg_put(msg,
16232 NL_AUTO_PID,
16233 NL_AUTO_SEQ,
16234 nl.id,
16235 0,
16236 NLM_F_DUMP,
16237 NL80211_CMD_GET_SURVEY,
16238 0);
developer72fb0bb2023-01-11 09:46:29 +080016239
developera3511852023-06-14 14:12:59 +080016240 nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(if_name));
16241 nl_send_auto_complete(nl.socket, msg);
16242 nl_cb_set(nl.cb,NL_CB_VALID,NL_CB_CUSTOM,chanSurveyInfo_callback,local);
16243 nl_recvmsgs(nl.socket, nl.cb);
16244 nlmsg_free(msg);
16245 nlfree(&nl);
16246 //Copying the Values
16247 for(int i=0;i<array_size;i++)
16248 {
16249 input_output_channelStats_array[i].ch_number = local[i].ch_number;
16250 input_output_channelStats_array[i].ch_noise = local[i].ch_noise;
16251 input_output_channelStats_array[i].ch_utilization_busy_rx = local[i].ch_utilization_busy_rx;
16252 input_output_channelStats_array[i].ch_utilization_busy_tx = local[i].ch_utilization_busy_tx;
16253 input_output_channelStats_array[i].ch_utilization_busy = local[i].ch_utilization_busy;
16254 input_output_channelStats_array[i].ch_utilization_busy_ext = local[i].ch_utilization_busy_ext;
16255 input_output_channelStats_array[i].ch_utilization_total = local[i].ch_utilization_total;
16256 //TODO: ch_radar_noise, ch_max_80211_rssi, ch_non_80211_noise, ch_utilization_busy_self
16257 }
developer72fb0bb2023-01-11 09:46:29 +080016258#else
developera3511852023-06-14 14:12:59 +080016259 ULONG channel = 0;
16260 int i;
16261 int number_of_channels = array_size;
16262 char buf[512];
developer72fb0bb2023-01-11 09:46:29 +080016263
developera3511852023-06-14 14:12:59 +080016264 if (number_of_channels == 0) {
16265 if (wifi_getRadioChannel(radioIndex, &channel) != RETURN_OK) {
16266 wifi_dbg_printf("%s: cannot get current channel for radioIndex=%d\n", __func__, radioIndex);
16267 return RETURN_ERR;
16268 }
16269 number_of_channels = 1;
16270 input_output_channelStats_array[0].ch_number = channel;
16271 }
developer72fb0bb2023-01-11 09:46:29 +080016272
developera3511852023-06-14 14:12:59 +080016273 for (i = 0; i < number_of_channels; i++) {
developer72fb0bb2023-01-11 09:46:29 +080016274
developera3511852023-06-14 14:12:59 +080016275 input_output_channelStats_array[i].ch_noise = 0;
16276 input_output_channelStats_array[i].ch_utilization_busy_rx = 0;
16277 input_output_channelStats_array[i].ch_utilization_busy_tx = 0;
16278 input_output_channelStats_array[i].ch_utilization_busy = 0;
16279 input_output_channelStats_array[i].ch_utilization_busy_ext = 0; // XXX: unavailable
16280 input_output_channelStats_array[i].ch_utilization_total = 0;
developer72fb0bb2023-01-11 09:46:29 +080016281
developera3511852023-06-14 14:12:59 +080016282 memset(buf, 0, sizeof(buf));
16283 if (get_survey_dump_buf(radioIndex, input_output_channelStats_array[i].ch_number, buf, sizeof(buf))) {
16284 return RETURN_ERR;
16285 }
16286 if (fetch_survey_from_buf(radioIndex, buf, &input_output_channelStats_array[i])) {
16287 wifi_dbg_printf("%s: cannot fetch survey from buf for radioIndex=%d\n", __func__, radioIndex);
16288 return RETURN_ERR;
16289 }
developer72fb0bb2023-01-11 09:46:29 +080016290
developera3511852023-06-14 14:12:59 +080016291 // XXX: fake missing 'self' counter which is not available in iw survey output
16292 // the 'self' counter (a.k.a 'bss') requires Linux Kernel update
16293 input_output_channelStats_array[i].ch_utilization_busy_self = input_output_channelStats_array[i].ch_utilization_busy_rx / 8;
developer72fb0bb2023-01-11 09:46:29 +080016294
developera3511852023-06-14 14:12:59 +080016295 input_output_channelStats_array[i].ch_utilization_busy_rx *= 1000;
16296 input_output_channelStats_array[i].ch_utilization_busy_tx *= 1000;
16297 input_output_channelStats_array[i].ch_utilization_busy_self *= 1000;
16298 input_output_channelStats_array[i].ch_utilization_busy *= 1000;
16299 input_output_channelStats_array[i].ch_utilization_total *= 1000;
developer72fb0bb2023-01-11 09:46:29 +080016300
developera3511852023-06-14 14:12:59 +080016301 wifi_dbg_printf("%s: ch_number=%d ch_noise=%d total=%llu busy=%llu busy_rx=%llu busy_tx=%llu busy_self=%llu busy_ext=%llu\n",
16302 __func__,
16303 input_output_channelStats_array[i].ch_number,
16304 input_output_channelStats_array[i].ch_noise,
16305 input_output_channelStats_array[i].ch_utilization_total,
16306 input_output_channelStats_array[i].ch_utilization_busy,
16307 input_output_channelStats_array[i].ch_utilization_busy_rx,
16308 input_output_channelStats_array[i].ch_utilization_busy_tx,
16309 input_output_channelStats_array[i].ch_utilization_busy_self,
16310 input_output_channelStats_array[i].ch_utilization_busy_ext);
16311 }
developer72fb0bb2023-01-11 09:46:29 +080016312#endif
developera3511852023-06-14 14:12:59 +080016313 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
16314 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016315}
16316#define HAL_NETLINK_IMPL
16317
16318/* Hostapd events */
16319
16320#ifndef container_of
16321#define offset_of(st, m) ((size_t)&(((st *)0)->m))
16322#define container_of(ptr, type, member) \
developera3511852023-06-14 14:12:59 +080016323 ((type *)((char *)ptr - offset_of(type, member)))
developer72fb0bb2023-01-11 09:46:29 +080016324#endif /* container_of */
16325
16326struct ctrl {
developera3511852023-06-14 14:12:59 +080016327 char sockpath[128];
16328 char sockdir[128];
16329 char bss[IFNAMSIZ];
16330 char reply[4096];
16331 int ssid_index;
16332 void (*cb)(struct ctrl *ctrl, int level, const char *buf, size_t len);
16333 void (*overrun)(struct ctrl *ctrl);
16334 struct wpa_ctrl *wpa;
16335 unsigned int ovfl;
16336 size_t reply_len;
16337 int initialized;
16338 ev_timer retry;
16339 ev_timer watchdog;
16340 ev_stat stat;
16341 ev_io io;
developer72fb0bb2023-01-11 09:46:29 +080016342};
16343static wifi_newApAssociatedDevice_callback clients_connect_cb;
16344static wifi_apDisassociatedDevice_callback clients_disconnect_cb;
16345static struct ctrl wpa_ctrl[MAX_APS];
16346static int initialized;
16347
16348static unsigned int ctrl_get_drops(struct ctrl *ctrl)
16349{
developera3511852023-06-14 14:12:59 +080016350 char cbuf[256] = {};
16351 struct msghdr msg = { .msg_control = cbuf, .msg_controllen = sizeof(cbuf) };
16352 struct cmsghdr *cmsg;
16353 unsigned int ovfl = ctrl->ovfl;
developer86035662023-06-28 19:21:12 +080016354 unsigned int drop = 0;
developer72fb0bb2023-01-11 09:46:29 +080016355
developer86035662023-06-28 19:21:12 +080016356 if (recvmsg(ctrl->io.fd, &msg, MSG_DONTWAIT) < 0)
16357 return drop;
developera3511852023-06-14 14:12:59 +080016358 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
16359 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_RXQ_OVFL)
16360 ovfl = *(unsigned int *)CMSG_DATA(cmsg);
developer72fb0bb2023-01-11 09:46:29 +080016361
developera3511852023-06-14 14:12:59 +080016362 drop = ovfl - ctrl->ovfl;
16363 ctrl->ovfl = ovfl;
developer72fb0bb2023-01-11 09:46:29 +080016364
developera3511852023-06-14 14:12:59 +080016365 return drop;
developer72fb0bb2023-01-11 09:46:29 +080016366}
16367
16368static void ctrl_close(struct ctrl *ctrl)
16369{
developera3511852023-06-14 14:12:59 +080016370 if (ctrl->io.cb)
16371 ev_io_stop(EV_DEFAULT_ &ctrl->io);
16372 if (ctrl->retry.cb)
16373 ev_timer_stop(EV_DEFAULT_ &ctrl->retry);
16374 if (!ctrl->wpa)
16375 return;
developer72fb0bb2023-01-11 09:46:29 +080016376
developera3511852023-06-14 14:12:59 +080016377 wpa_ctrl_detach(ctrl->wpa);
16378 wpa_ctrl_close(ctrl->wpa);
16379 ctrl->wpa = NULL;
16380 printf("WPA_CTRL: closed index=%d\n", ctrl->ssid_index);
developer72fb0bb2023-01-11 09:46:29 +080016381}
16382
16383static void ctrl_process(struct ctrl *ctrl)
16384{
developera3511852023-06-14 14:12:59 +080016385 const char *str;
16386 int drops;
16387 int level;
developer72fb0bb2023-01-11 09:46:29 +080016388
developera3511852023-06-14 14:12:59 +080016389 /* Example events:
16390 *
16391 * <3>AP-STA-CONNECTED 60:b4:f7:f0:0a:19
16392 * <3>AP-STA-CONNECTED 60:b4:f7:f0:0a:19 keyid=sample_keyid
16393 * <3>AP-STA-DISCONNECTED 60:b4:f7:f0:0a:19
16394 * <3>CTRL-EVENT-CONNECTED - Connection to 00:1d:73:73:88:ea completed [id=0 id_str=]
16395 * <3>CTRL-EVENT-DISCONNECTED bssid=00:1d:73:73:88:ea reason=3 locally_generated=1
16396 */
16397 if (!(str = index(ctrl->reply, '>')))
16398 return;
16399 if (sscanf(ctrl->reply, "<%d>", &level) != 1)
16400 return;
developer72fb0bb2023-01-11 09:46:29 +080016401
developera3511852023-06-14 14:12:59 +080016402 str++;
developer72fb0bb2023-01-11 09:46:29 +080016403
developera3511852023-06-14 14:12:59 +080016404 if (strncmp("AP-STA-CONNECTED ", str, 17) == 0) {
16405 if (!(str = index(ctrl->reply, ' ')))
16406 return;
16407 wifi_associated_dev_t sta;
16408 memset(&sta, 0, sizeof(sta));
developer72fb0bb2023-01-11 09:46:29 +080016409
developere75ba632023-06-29 16:03:33 +080016410 if (sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
16411 &sta.cli_MACAddress[0], &sta.cli_MACAddress[1], &sta.cli_MACAddress[2],
16412 &sta.cli_MACAddress[3], &sta.cli_MACAddress[4], &sta.cli_MACAddress[5]) == EOF) {
16413 wifi_debug(DEBUG_ERROR, "Unexpected sscanf fail\n");
16414 return;
16415 }
developer72fb0bb2023-01-11 09:46:29 +080016416
developera3511852023-06-14 14:12:59 +080016417 sta.cli_Active=true;
developer72fb0bb2023-01-11 09:46:29 +080016418
developera3511852023-06-14 14:12:59 +080016419 (clients_connect_cb)(ctrl->ssid_index, &sta);
16420 goto handled;
16421 }
developer72fb0bb2023-01-11 09:46:29 +080016422
developera3511852023-06-14 14:12:59 +080016423 if (strncmp("AP-STA-DISCONNECTED ", str, 20) == 0) {
16424 if (!(str = index(ctrl->reply, ' ')))
16425 return;
developer72fb0bb2023-01-11 09:46:29 +080016426
developera3511852023-06-14 14:12:59 +080016427 (clients_disconnect_cb)(ctrl->ssid_index, (char*)str, 0);
16428 goto handled;
16429 }
developer72fb0bb2023-01-11 09:46:29 +080016430
developera3511852023-06-14 14:12:59 +080016431 if (strncmp("CTRL-EVENT-TERMINATING", str, 22) == 0) {
16432 printf("CTRL_WPA: handle TERMINATING event\n");
16433 goto retry;
16434 }
developer72fb0bb2023-01-11 09:46:29 +080016435
developera3511852023-06-14 14:12:59 +080016436 if (strncmp("AP-DISABLED", str, 11) == 0) {
16437 printf("CTRL_WPA: handle AP-DISABLED\n");
16438 goto retry;
16439 }
developer72fb0bb2023-01-11 09:46:29 +080016440
developera3511852023-06-14 14:12:59 +080016441 printf("Event not supported!!\n");
developer72fb0bb2023-01-11 09:46:29 +080016442
16443handled:
16444
developera3511852023-06-14 14:12:59 +080016445 if ((drops = ctrl_get_drops(ctrl))) {
16446 printf("WPA_CTRL: dropped %d messages index=%d\n", drops, ctrl->ssid_index);
16447 if (ctrl->overrun)
16448 ctrl->overrun(ctrl);
16449 }
developer72fb0bb2023-01-11 09:46:29 +080016450
developera3511852023-06-14 14:12:59 +080016451 return;
developer72fb0bb2023-01-11 09:46:29 +080016452
16453retry:
developera3511852023-06-14 14:12:59 +080016454 printf("WPA_CTRL: closing\n");
16455 ctrl_close(ctrl);
16456 printf("WPA_CTRL: retrying from ctrl prcoess\n");
16457 ev_timer_again(EV_DEFAULT_ &ctrl->retry);
developer72fb0bb2023-01-11 09:46:29 +080016458}
16459
16460static void ctrl_ev_cb(EV_P_ struct ev_io *io, int events)
16461{
developera3511852023-06-14 14:12:59 +080016462 struct ctrl *ctrl = container_of(io, struct ctrl, io);
16463 int err;
developer72fb0bb2023-01-11 09:46:29 +080016464
developera3511852023-06-14 14:12:59 +080016465 memset(ctrl->reply, 0, sizeof(ctrl->reply));
16466 ctrl->reply_len = sizeof(ctrl->reply) - 1;
16467 err = wpa_ctrl_recv(ctrl->wpa, ctrl->reply, &ctrl->reply_len);
16468 ctrl->reply[ctrl->reply_len] = 0;
16469 if (err < 0) {
16470 if (errno == EAGAIN || errno == EWOULDBLOCK)
16471 return;
16472 ctrl_close(ctrl);
16473 ev_timer_again(EV_A_ &ctrl->retry);
16474 return;
16475 }
developer72fb0bb2023-01-11 09:46:29 +080016476
developera3511852023-06-14 14:12:59 +080016477 ctrl_process(ctrl);
developer72fb0bb2023-01-11 09:46:29 +080016478}
16479
16480static int ctrl_open(struct ctrl *ctrl)
16481{
developera3511852023-06-14 14:12:59 +080016482 int fd;
developer72fb0bb2023-01-11 09:46:29 +080016483
developera3511852023-06-14 14:12:59 +080016484 if (ctrl->wpa)
16485 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016486
developera3511852023-06-14 14:12:59 +080016487 ctrl->wpa = wpa_ctrl_open(ctrl->sockpath);
16488 if (!ctrl->wpa)
16489 goto err;
developer72fb0bb2023-01-11 09:46:29 +080016490
developera3511852023-06-14 14:12:59 +080016491 if (wpa_ctrl_attach(ctrl->wpa) < 0)
16492 goto err_close;
developer72fb0bb2023-01-11 09:46:29 +080016493
developera3511852023-06-14 14:12:59 +080016494 fd = wpa_ctrl_get_fd(ctrl->wpa);
16495 if (fd < 0)
16496 goto err_detach;
developer72fb0bb2023-01-11 09:46:29 +080016497
developera3511852023-06-14 14:12:59 +080016498 if (setsockopt(fd, SOL_SOCKET, SO_RXQ_OVFL, (int[]){1}, sizeof(int)) < 0)
16499 goto err_detach;
developer72fb0bb2023-01-11 09:46:29 +080016500
developera3511852023-06-14 14:12:59 +080016501 ev_io_init(&ctrl->io, ctrl_ev_cb, fd, EV_READ);
16502 ev_io_start(EV_DEFAULT_ &ctrl->io);
developer72fb0bb2023-01-11 09:46:29 +080016503
developera3511852023-06-14 14:12:59 +080016504 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016505
16506err_detach:
developera3511852023-06-14 14:12:59 +080016507 wpa_ctrl_detach(ctrl->wpa);
developer72fb0bb2023-01-11 09:46:29 +080016508err_close:
developera3511852023-06-14 14:12:59 +080016509 wpa_ctrl_close(ctrl->wpa);
developer72fb0bb2023-01-11 09:46:29 +080016510err:
developera3511852023-06-14 14:12:59 +080016511 ctrl->wpa = NULL;
16512 return -1;
developer72fb0bb2023-01-11 09:46:29 +080016513}
16514
16515static void ctrl_stat_cb(EV_P_ ev_stat *stat, int events)
16516{
developera3511852023-06-14 14:12:59 +080016517 struct ctrl *ctrl = container_of(stat, struct ctrl, stat);
developer72fb0bb2023-01-11 09:46:29 +080016518
developera3511852023-06-14 14:12:59 +080016519 printf("WPA_CTRL: index=%d file state changed\n", ctrl->ssid_index);
16520 ctrl_open(ctrl);
developer72fb0bb2023-01-11 09:46:29 +080016521}
16522
16523static void ctrl_retry_cb(EV_P_ ev_timer *timer, int events)
16524{
developera3511852023-06-14 14:12:59 +080016525 struct ctrl *ctrl = container_of(timer, struct ctrl, retry);
developer72fb0bb2023-01-11 09:46:29 +080016526
developera3511852023-06-14 14:12:59 +080016527 printf("WPA_CTRL: index=%d retrying\n", ctrl->ssid_index);
16528 if (ctrl_open(ctrl) == 0) {
16529 printf("WPA_CTRL: retry successful\n");
16530 ev_timer_stop(EV_DEFAULT_ &ctrl->retry);
16531 }
developer72fb0bb2023-01-11 09:46:29 +080016532}
16533
16534int ctrl_enable(struct ctrl *ctrl)
16535{
developera3511852023-06-14 14:12:59 +080016536 if (ctrl->wpa)
16537 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016538
developera3511852023-06-14 14:12:59 +080016539 if (!ctrl->stat.cb) {
16540 ev_stat_init(&ctrl->stat, ctrl_stat_cb, ctrl->sockpath, 0.);
16541 ev_stat_start(EV_DEFAULT_ &ctrl->stat);
16542 }
developer72fb0bb2023-01-11 09:46:29 +080016543
developera3511852023-06-14 14:12:59 +080016544 if (!ctrl->retry.cb) {
16545 ev_timer_init(&ctrl->retry, ctrl_retry_cb, 0., 5.);
16546 }
developer72fb0bb2023-01-11 09:46:29 +080016547
developera3511852023-06-14 14:12:59 +080016548 return ctrl_open(ctrl);
developer72fb0bb2023-01-11 09:46:29 +080016549}
16550
16551static void
16552ctrl_msg_cb(char *buf, size_t len)
16553{
developera3511852023-06-14 14:12:59 +080016554 struct ctrl *ctrl = container_of(buf, struct ctrl, reply);
developer72fb0bb2023-01-11 09:46:29 +080016555
developera3511852023-06-14 14:12:59 +080016556 printf("WPA_CTRL: unsolicited message: index=%d len=%zu msg=%s", ctrl->ssid_index, len, buf);
16557 ctrl_process(ctrl);
developer72fb0bb2023-01-11 09:46:29 +080016558}
16559
16560static int ctrl_request(struct ctrl *ctrl, const char *cmd, size_t cmd_len, char *reply, size_t *reply_len)
16561{
developera3511852023-06-14 14:12:59 +080016562 int err;
developer72fb0bb2023-01-11 09:46:29 +080016563
developera3511852023-06-14 14:12:59 +080016564 if (!ctrl->wpa)
16565 return -1;
16566 if (*reply_len < 2)
16567 return -1;
developer72fb0bb2023-01-11 09:46:29 +080016568
developera3511852023-06-14 14:12:59 +080016569 (*reply_len)--;
16570 ctrl->reply_len = sizeof(ctrl->reply);
16571 err = wpa_ctrl_request(ctrl->wpa, cmd, cmd_len, ctrl->reply, &ctrl->reply_len, ctrl_msg_cb);
16572 printf("WPA_CTRL: index=%d cmd='%s' err=%d\n", ctrl->ssid_index, cmd, err);
16573 if (err < 0)
16574 return err;
developer72fb0bb2023-01-11 09:46:29 +080016575
developera3511852023-06-14 14:12:59 +080016576 if (ctrl->reply_len > *reply_len)
16577 ctrl->reply_len = *reply_len;
developer72fb0bb2023-01-11 09:46:29 +080016578
developera3511852023-06-14 14:12:59 +080016579 *reply_len = ctrl->reply_len;
16580 memcpy(reply, ctrl->reply, *reply_len);
16581 reply[*reply_len - 1] = 0;
16582 printf("WPA_CTRL: index=%d reply='%s'\n", ctrl->ssid_index, reply);
16583 return 0;
developer72fb0bb2023-01-11 09:46:29 +080016584}
16585
16586static void ctrl_watchdog_cb(EV_P_ ev_timer *timer, int events)
16587{
developera3511852023-06-14 14:12:59 +080016588 const char *pong = "PONG";
16589 const char *ping = "PING";
16590 char reply[1024];
16591 size_t len = sizeof(reply);
16592 int err;
16593 ULONG s, snum;
16594 INT ret;
16595 BOOL status;
developer72fb0bb2023-01-11 09:46:29 +080016596
developera3511852023-06-14 14:12:59 +080016597 printf("WPA_CTRL: watchdog cb\n");
developer72fb0bb2023-01-11 09:46:29 +080016598
developera3511852023-06-14 14:12:59 +080016599 ret = wifi_getSSIDNumberOfEntries(&snum);
16600 if (ret != RETURN_OK) {
16601 printf("%s: failed to get SSID count", __func__);
16602 return;
16603 }
developer72fb0bb2023-01-11 09:46:29 +080016604
developera3511852023-06-14 14:12:59 +080016605 if (snum > MAX_APS) {
16606 printf("more ssid than supported! %lu\n", snum);
16607 return;
16608 }
developer72fb0bb2023-01-11 09:46:29 +080016609
developera3511852023-06-14 14:12:59 +080016610 for (s = 0; s < snum; s++) {
16611 if (wifi_getApEnable(s, &status) != RETURN_OK) {
16612 printf("%s: failed to get AP Enable for index: %lu\n", __func__, s);
16613 continue;
16614 }
16615 if (status == false) continue;
developer72fb0bb2023-01-11 09:46:29 +080016616
developera3511852023-06-14 14:12:59 +080016617 memset(reply, 0, sizeof(reply));
16618 len = sizeof(reply);
16619 printf("WPA_CTRL: pinging index=%d\n", wpa_ctrl[s].ssid_index);
16620 err = ctrl_request(&wpa_ctrl[s], ping, strlen(ping), reply, &len);
16621 if (err == 0 && len > strlen(pong) && !strncmp(reply, pong, strlen(pong)))
16622 continue;
developer72fb0bb2023-01-11 09:46:29 +080016623
developera3511852023-06-14 14:12:59 +080016624 printf("WPA_CTRL: ping timeout index=%d\n", wpa_ctrl[s].ssid_index);
16625 ctrl_close(&wpa_ctrl[s]);
16626 printf("WPA_CTRL: ev_timer_again %lu\n", s);
16627 ev_timer_again(EV_DEFAULT_ &wpa_ctrl[s].retry);
16628 }
developer72fb0bb2023-01-11 09:46:29 +080016629}
16630
16631static int init_wpa()
16632{
developer9ce44382023-06-28 11:09:37 +080016633 int ret = 0;
developera3511852023-06-14 14:12:59 +080016634 ULONG s, snum;
developer72fb0bb2023-01-11 09:46:29 +080016635
developera3511852023-06-14 14:12:59 +080016636 ret = wifi_getSSIDNumberOfEntries(&snum);
16637 if (ret != RETURN_OK) {
16638 printf("%s: failed to get SSID count", __func__);
16639 return RETURN_ERR;
16640 }
developer72fb0bb2023-01-11 09:46:29 +080016641
developera3511852023-06-14 14:12:59 +080016642 if (snum > MAX_APS) {
16643 printf("more ssid than supported! %lu\n", snum);
16644 return RETURN_ERR;
16645 }
developer72fb0bb2023-01-11 09:46:29 +080016646
developera3511852023-06-14 14:12:59 +080016647 for (s = 0; s < snum; s++) {
16648 memset(&wpa_ctrl[s], 0, sizeof(struct ctrl));
developer32f2a182023-06-27 19:50:41 +080016649 ret = snprintf(wpa_ctrl[s].sockpath, sizeof(wpa_ctrl[s].sockpath), "%s%lu", SOCK_PREFIX, s);
16650 if (os_snprintf_error(sizeof(wpa_ctrl[s].sockpath), ret)) {
16651 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16652 return RETURN_ERR;
16653 }
developera3511852023-06-14 14:12:59 +080016654 wpa_ctrl[s].ssid_index = s;
16655 ctrl_enable(&wpa_ctrl[s]);
16656 }
developer72fb0bb2023-01-11 09:46:29 +080016657
developera3511852023-06-14 14:12:59 +080016658 ev_timer_init(&wpa_ctrl->watchdog, ctrl_watchdog_cb, 0., 30.);
16659 ev_timer_again(EV_DEFAULT_ &wpa_ctrl->watchdog);
developer72fb0bb2023-01-11 09:46:29 +080016660
developera3511852023-06-14 14:12:59 +080016661 initialized = 1;
16662 printf("WPA_CTRL: initialized\n");
developer72fb0bb2023-01-11 09:46:29 +080016663
developera3511852023-06-14 14:12:59 +080016664 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016665}
16666
16667void wifi_newApAssociatedDevice_callback_register(wifi_newApAssociatedDevice_callback callback_proc)
16668{
developera3511852023-06-14 14:12:59 +080016669 clients_connect_cb = callback_proc;
16670 if (!initialized)
16671 init_wpa();
developer72fb0bb2023-01-11 09:46:29 +080016672}
16673
16674void wifi_apDisassociatedDevice_callback_register(wifi_apDisassociatedDevice_callback callback_proc)
16675{
developera3511852023-06-14 14:12:59 +080016676 clients_disconnect_cb = callback_proc;
16677 if (!initialized)
16678 init_wpa();
developer72fb0bb2023-01-11 09:46:29 +080016679}
16680
16681INT wifi_setBTMRequest(UINT apIndex, CHAR *peerMac, wifi_BTMRequest_t *request)
16682{
developera3511852023-06-14 14:12:59 +080016683 // TODO Implement me!
16684 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016685}
16686
16687INT wifi_setRMBeaconRequest(UINT apIndex, CHAR *peer, wifi_BeaconRequest_t *in_request, UCHAR *out_DialogToken)
16688{
developera3511852023-06-14 14:12:59 +080016689 // TODO Implement me!
16690 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016691}
16692
16693INT wifi_getRadioChannels(INT radioIndex, wifi_channelMap_t *outputMap, INT outputMapSize)
16694{
developera3511852023-06-14 14:12:59 +080016695 int i;
16696 int phyId = -1;
16697 char cmd[256] = {0};
16698 char channel_numbers_buf[256] = {0};
16699 char dfs_state_buf[256] = {0};
16700 char line[256] = {0};
16701 const char *ptr;
16702 BOOL dfs_enable = false;
developere40952c2023-06-15 18:46:43 +080016703 int res;
developer72fb0bb2023-01-11 09:46:29 +080016704
developera3511852023-06-14 14:12:59 +080016705 memset(outputMap, 0, outputMapSize*sizeof(wifi_channelMap_t)); // all unused entries should be zero
developer72fb0bb2023-01-11 09:46:29 +080016706
developera3511852023-06-14 14:12:59 +080016707 wifi_getRadioDfsEnable(radioIndex, &dfs_enable);
16708 phyId = radio_index_to_phy(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +080016709
developere40952c2023-06-15 18:46:43 +080016710 res = snprintf(cmd, sizeof (cmd), "iw phy phy%d info | grep -e '\\*.*MHz .*dBm' | grep -v '%sno IR\\|5340\\|5480' | awk '{print $4}' | tr -d '[]'", phyId, dfs_enable?"":"radar\\|");
16711 if (os_snprintf_error(sizeof(cmd), res)) {
16712 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16713 return RETURN_ERR;
16714 }
developer72fb0bb2023-01-11 09:46:29 +080016715
developer8078acf2023-08-04 18:52:48 +080016716 if (_syscmd_secure(channel_numbers_buf, sizeof(channel_numbers_buf), "iw phy phy%d info | grep -e '\\*.*MHz .*dBm' | grep -v '%sno IR\\|5340\\|5480' | awk '{print $4}' | tr -d '[]'", phyId, dfs_enable?"":"radar\\|") == RETURN_ERR) {
developera3511852023-06-14 14:12:59 +080016717 wifi_dbg_printf("%s: failed to execute '%s'\n", __FUNCTION__, cmd);
16718 return RETURN_ERR;
16719 }
developer72fb0bb2023-01-11 09:46:29 +080016720
developera3511852023-06-14 14:12:59 +080016721 ptr = channel_numbers_buf;
16722 i = 0;
16723 while ((ptr = get_line_from_str_buf(ptr, line))) {
16724 if (i >= outputMapSize) {
16725 wifi_dbg_printf("%s: DFS map size too small\n", __FUNCTION__);
16726 return RETURN_ERR;
16727 }
developerd14dff12023-06-28 22:47:44 +080016728 if (sscanf(line, "%d", &outputMap[i].ch_number) != 1) {
16729 wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
16730 return RETURN_ERR;
16731 }
developerd1824452023-05-18 12:30:04 +080016732
developera3511852023-06-14 14:12:59 +080016733 memset(cmd, 0, sizeof(cmd));
16734 // Below command should fetch string for DFS state (usable, available or unavailable)
16735 // Example line: "DFS state: usable (for 78930 sec)"
16736 if (sprintf(cmd,"iw list | grep -A 2 '\\[%d\\]' | tr -d '\\t' | grep 'DFS state' | awk '{print $3}' | tr -d '\\n'", outputMap[i].ch_number) < 0) {
16737 wifi_dbg_printf("%s: failed to build dfs state command\n", __FUNCTION__);
16738 return RETURN_ERR;
16739 }
developer72fb0bb2023-01-11 09:46:29 +080016740
developera3511852023-06-14 14:12:59 +080016741 memset(dfs_state_buf, 0, sizeof(dfs_state_buf));
developer8078acf2023-08-04 18:52:48 +080016742 if (_syscmd_secure(dfs_state_buf, sizeof(dfs_state_buf),"iw list | grep -A 2 '\\[%d\\]' | tr -d '\\t' | grep 'DFS state' | awk '{print $3}' | tr -d '\\n'", outputMap[i].ch_number) == RETURN_ERR) {
developera3511852023-06-14 14:12:59 +080016743 wifi_dbg_printf("%s: failed to execute '%s'\n", __FUNCTION__, cmd);
16744 return RETURN_ERR;
16745 }
developer72fb0bb2023-01-11 09:46:29 +080016746
developera3511852023-06-14 14:12:59 +080016747 wifi_dbg_printf("DFS state = '%s'\n", dfs_state_buf);
developer59fda4f2023-05-16 15:47:38 +080016748
developera3511852023-06-14 14:12:59 +080016749 if (!strcmp(dfs_state_buf, "usable")) {
16750 outputMap[i].ch_state = CHAN_STATE_DFS_NOP_FINISHED;
16751 } else if (!strcmp(dfs_state_buf, "available")) {
16752 outputMap[i].ch_state = CHAN_STATE_DFS_CAC_COMPLETED;
16753 } else if (!strcmp(dfs_state_buf, "unavailable")) {
16754 outputMap[i].ch_state = CHAN_STATE_DFS_NOP_START;
16755 } else {
16756 outputMap[i].ch_state = CHAN_STATE_AVAILABLE;
16757 }
16758 i++;
16759 }
developer40ba1762023-05-13 11:03:49 +080016760
developera3511852023-06-14 14:12:59 +080016761 return RETURN_OK;
developerd1824452023-05-18 12:30:04 +080016762
developera3511852023-06-14 14:12:59 +080016763 wifi_dbg_printf("%s: wrong radio index (%d)\n", __FUNCTION__, radioIndex);
16764 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016765}
16766
16767INT wifi_chan_eventRegister(wifi_chan_eventCB_t eventCb)
16768{
developera3511852023-06-14 14:12:59 +080016769 // TODO Implement me!
16770 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016771}
16772
16773INT wifi_getRadioBandUtilization (INT radioIndex, INT *output_percentage)
16774{
developer0155a502023-06-19 20:33:57 +080016775 int ret = -1;
16776 char inf_name[IF_NAME_SIZE] = {0};
16777 int if_idx = 0;
16778 struct unl unl_ins;
16779 struct nl_msg *msg = NULL;
16780 struct nlattr * msg_data = NULL;
16781 struct mtk_nl80211_param param;
16782 struct mtk_nl80211_cb_data cb_data;
16783 wdev_ap_metric ap_metric;
16784
16785 /*init mtk nl80211 vendor cmd*/
16786
16787 if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
16788 return RETURN_ERR;
16789 if_idx = if_nametoindex(inf_name);
16790 if (!if_idx) {
16791 wifi_debug(DEBUG_ERROR,"can't finde ifname(%s) index,ERROR\n", inf_name);
16792 return RETURN_ERR;
16793 }
16794
16795 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_GET_STATISTIC;
16796 param.if_type = NL80211_ATTR_IFINDEX;
16797 param.if_idx = if_idx;
16798
16799 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
16800 if (ret) {
16801 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
16802 return RETURN_ERR;
16803 }
16804
16805 /*add mtk vendor cmd data*/
16806
16807 if (nla_put(msg, MTK_NL80211_VENDOR_ATTR_GET_AP_METRICS, sizeof(wdev_ap_metric), (char *)&ap_metric)) {
16808 wifi_debug(DEBUG_ERROR, "Nla put GET_AP_METRICS attribute error\n");
16809 nlmsg_free(msg);
16810 goto err;
16811 }
16812
16813 /*send mtk nl80211 vendor msg*/
16814 cb_data.out_buf = (char *)output_percentage;
16815 cb_data.out_len = sizeof(wdev_ap_metric);
16816 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, mtk_get_ap_metrics, &cb_data);
16817 if (ret) {
16818 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
16819 goto err;
16820 }
16821
16822 /*deinit mtk nl80211 vendor msg*/
16823 mtk_nl80211_deint(&unl_ins);
16824 wifi_debug(DEBUG_NOTICE, "set cmd success.\n");
16825 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
16826
developera3511852023-06-14 14:12:59 +080016827 return RETURN_OK;
developer0155a502023-06-19 20:33:57 +080016828err:
16829 mtk_nl80211_deint(&unl_ins);
16830 wifi_debug(DEBUG_ERROR, "set cmd fails.\n");
16831 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016832}
16833
developer0155a502023-06-19 20:33:57 +080016834
developer72fb0bb2023-01-11 09:46:29 +080016835INT wifi_getApAssociatedClientDiagnosticResult(INT apIndex, char *mac_addr, wifi_associated_dev3_t *dev_conn)
16836{
developera3511852023-06-14 14:12:59 +080016837 // TODO Implement me!
16838 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016839}
16840
16841INT wifi_switchBand(char *interface_name,INT radioIndex,char *freqBand)
16842{
developera3511852023-06-14 14:12:59 +080016843 // TODO API refrence Implementaion is present on RPI hal
16844 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016845}
16846
16847INT wifi_getRadioPercentageTransmitPower(INT apIndex, ULONG *txpwr_pcntg)
16848{
developera3511852023-06-14 14:12:59 +080016849 ULONG pwr_percentage = 0;
developer72fb0bb2023-01-11 09:46:29 +080016850
developera3511852023-06-14 14:12:59 +080016851 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
16852 if(txpwr_pcntg == NULL)
developerdaf24792023-06-06 11:40:04 +080016853 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080016854
developera1255e42023-05-13 17:45:02 +080016855 wifi_getRadioTransmitPower(apIndex, &pwr_percentage);
16856 *txpwr_pcntg = pwr_percentage;
developera3511852023-06-14 14:12:59 +080016857 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
16858 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016859}
16860
16861INT wifi_setZeroDFSState(UINT radioIndex, BOOL enable, BOOL precac)
16862{
developera3511852023-06-14 14:12:59 +080016863 // TODO precac feature.
16864 struct params params[2] = {0};
16865 char config_file[128] = {0};
16866 BOOL dfs_enable = false;
16867 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +080016868 int res;
developer72fb0bb2023-01-11 09:46:29 +080016869
developera3511852023-06-14 14:12:59 +080016870 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
16871 band = wifi_index_to_band(radioIndex);
16872 wifi_getRadioDfsEnable(radioIndex, &dfs_enable);
developer72fb0bb2023-01-11 09:46:29 +080016873
developera3511852023-06-14 14:12:59 +080016874 if (dfs_enable == false) {
16875 WIFI_ENTRY_EXIT_DEBUG("Please enable DFS firstly!: %s\n", __func__);
16876 return RETURN_ERR;
16877 }
16878 params[0].name = "DfsZeroWaitDefault";
16879 params[0].value = enable?"1":"0";
16880 params[1].name = "DfsDedicatedZeroWait";
16881 params[1].value = enable?"1":"0";
developere40952c2023-06-15 18:46:43 +080016882 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
16883 if (os_snprintf_error(sizeof(config_file), res)) {
16884 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16885 return RETURN_ERR;
16886 }
developera3511852023-06-14 14:12:59 +080016887 wifi_datfileWrite(config_file, params, 2);
16888 wifi_reloadAp(radioIndex);
16889 /* TODO precac feature */
developer72fb0bb2023-01-11 09:46:29 +080016890
developera3511852023-06-14 14:12:59 +080016891 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
16892 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016893}
16894
16895INT wifi_getZeroDFSState(UINT radioIndex, BOOL *enable, BOOL *precac)
16896{
developera3511852023-06-14 14:12:59 +080016897 char config_file[128] = {0};
16898 char buf1[32] = {0};
16899 char buf2[32] = {0};
16900 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +080016901 int res;
developer72fb0bb2023-01-11 09:46:29 +080016902
developera3511852023-06-14 14:12:59 +080016903 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
16904 if (NULL == enable || NULL == precac)
16905 return RETURN_ERR;
16906 band = wifi_index_to_band(radioIndex);
developere40952c2023-06-15 18:46:43 +080016907 res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
16908 if (os_snprintf_error(sizeof(config_file), res)) {
16909 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16910 return RETURN_ERR;
16911 }
developera3511852023-06-14 14:12:59 +080016912 wifi_datfileRead(config_file, "DfsZeroWaitDefault", buf1, sizeof(buf1));
16913 wifi_datfileRead(config_file, "DfsDedicatedZeroWait", buf2, sizeof(buf2));
16914 if ((strncmp(buf1, "1", 1) == 0) && (strncmp(buf2, "1", 1) == 0))
16915 *enable = true;
16916 else
16917 *enable = false;
developer72fb0bb2023-01-11 09:46:29 +080016918
developera3511852023-06-14 14:12:59 +080016919 /* TODO precac feature */
developer72fb0bb2023-01-11 09:46:29 +080016920
developera3511852023-06-14 14:12:59 +080016921 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
16922 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016923}
16924
16925INT wifi_isZeroDFSSupported(UINT radioIndex, BOOL *supported)
16926{
developera3511852023-06-14 14:12:59 +080016927 *supported = TRUE;
16928 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080016929}
16930
16931INT wifi_setDownlinkMuType(INT radio_index, wifi_dl_mu_type_t mu_type)
16932{
developer863a4a62023-06-06 16:55:59 +080016933 CHAR dat_file[64] = {0};
developera3511852023-06-14 14:12:59 +080016934 wifi_band band = band_invalid;
16935 char ofdmabuf[32] = {'\0'};
16936 char mimobuf[32] = {'\0'};
16937 char new_ofdmabuf[32] = {'\0'};
16938 char new_mimobuf[32] = {'\0'};
16939 struct params params[2];
developera1255e42023-05-13 17:45:02 +080016940 char *str_zero = "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0";/*default 15bss per band.*/
16941 char *str_one = "1;1;1;1;1;1;1;1;1;1;1;1;1;1;1";
16942 UCHAR bss_cnt = 0;
16943 UCHAR val_cnt = 0;
developere40952c2023-06-15 18:46:43 +080016944 int res;
developer72fb0bb2023-01-11 09:46:29 +080016945
developera3511852023-06-14 14:12:59 +080016946 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developera1255e42023-05-13 17:45:02 +080016947 if ((mu_type < WIFI_DL_MU_TYPE_NONE)
16948 || (mu_type > WIFI_DL_MU_TYPE_OFDMA_MIMO)) {
16949 printf("%s:mu_type input Error", __func__);
16950 return RETURN_ERR;
16951 }
developera3511852023-06-14 14:12:59 +080016952 band = wifi_index_to_band(radio_index);
developera1255e42023-05-13 17:45:02 +080016953 if (band == band_invalid) {
16954 printf("%s:Band Error\n", __func__);
16955 return RETURN_ERR;
16956 }
developere40952c2023-06-15 18:46:43 +080016957 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
16958 if (os_snprintf_error(sizeof(dat_file), res)) {
16959 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
16960 return RETURN_ERR;
16961 }
16962
developera1255e42023-05-13 17:45:02 +080016963 /*get current value in dat file*/
developera3511852023-06-14 14:12:59 +080016964 wifi_datfileRead(dat_file, "MuOfdmaDlEnable", ofdmabuf, sizeof(ofdmabuf));
16965 wifi_datfileRead(dat_file, "MuMimoDlEnable", mimobuf, sizeof(mimobuf));
developera1255e42023-05-13 17:45:02 +080016966 WIFI_ENTRY_EXIT_DEBUG("%s:ofdma-%s, mimo-%s\n", __func__, ofdmabuf, mimobuf);
16967 get_bssnum_byindex(radio_index, &bss_cnt);
16968 val_cnt = 2*bss_cnt - 1;
16969 WIFI_ENTRY_EXIT_DEBUG("bss number: %d\n", bss_cnt);
16970 if ((val_cnt >= sizeof(new_ofdmabuf))
16971 || (val_cnt >= sizeof(new_mimobuf))) {
developer49c83812023-06-06 14:23:53 +080016972 printf("%s:bss cnt Error", __func__);
developera1255e42023-05-13 17:45:02 +080016973 return RETURN_ERR;
16974 }
16975 /*translate set value*/
16976 if (mu_type == WIFI_DL_MU_TYPE_NONE) {
16977 strncpy(new_ofdmabuf, str_zero, val_cnt);
16978 strncpy(new_mimobuf, str_zero, val_cnt);
developera3511852023-06-14 14:12:59 +080016979 } else if (mu_type == WIFI_DL_MU_TYPE_OFDMA) {
developera1255e42023-05-13 17:45:02 +080016980 strncpy(new_ofdmabuf, str_one, val_cnt);
16981 strncpy(new_mimobuf, str_zero, val_cnt);
developera3511852023-06-14 14:12:59 +080016982 } else if (mu_type == WIFI_DL_MU_TYPE_MIMO) {
developera1255e42023-05-13 17:45:02 +080016983 strncpy(new_ofdmabuf, str_zero, val_cnt);
16984 strncpy(new_mimobuf, str_one, val_cnt);
developera3511852023-06-14 14:12:59 +080016985 } else if (mu_type == WIFI_DL_MU_TYPE_OFDMA_MIMO) {
developera1255e42023-05-13 17:45:02 +080016986 strncpy(new_ofdmabuf, str_one, val_cnt);
16987 strncpy(new_mimobuf, str_one, val_cnt);
developera3511852023-06-14 14:12:59 +080016988 }
developera1255e42023-05-13 17:45:02 +080016989 WIFI_ENTRY_EXIT_DEBUG("%s:new_ofdmabuf-%s, new_mimobuf-%s\n", __func__, new_ofdmabuf, new_mimobuf);
16990 /*same value, not operation*/
16991 if ((strncmp(new_mimobuf, mimobuf, 1) ==0)
16992 && (strncmp(new_ofdmabuf, ofdmabuf, 1) ==0)) {
16993 printf("%s:Reduntant value\n", __func__);
16994 return RETURN_OK;
16995 }
16996 /*modify dat file to new file*/
16997 params[0].name="MuOfdmaDlEnable";
16998 params[0].value=new_ofdmabuf;
16999 params[1].name="MuMimoDlEnable";
17000 params[1].value=new_mimobuf;
17001 wifi_datfileWrite(dat_file, params, 2);
17002 /*hostapd control restarp ap to take effect on these new value*/
17003 wifi_reloadAp(radio_index);
developera3511852023-06-14 14:12:59 +080017004 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17005 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017006}
17007
17008INT wifi_getDownlinkMuType(INT radio_index, wifi_dl_mu_type_t *mu_type)
17009{
developer5a333cf2023-06-06 18:18:50 +080017010 CHAR dat_file[64] = {0};
developera3511852023-06-14 14:12:59 +080017011 wifi_band band = band_invalid;
17012 char ofdmabuf[32] = {'\0'};
17013 char mimobuf[32] = {'\0'};
developera1255e42023-05-13 17:45:02 +080017014 char *token = NULL;
developerc14d83a2023-06-29 20:09:42 +080017015 long int ofdma = 0;
17016 long int mimo = 0;
developere40952c2023-06-15 18:46:43 +080017017 int res;
developer72fb0bb2023-01-11 09:46:29 +080017018
developera3511852023-06-14 14:12:59 +080017019 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080017020
developera3511852023-06-14 14:12:59 +080017021 if (mu_type == NULL)
17022 return RETURN_ERR;
17023 band = wifi_index_to_band(radio_index);
developera1255e42023-05-13 17:45:02 +080017024 if (band == band_invalid) {
17025 printf("%s:Band Error\n", __func__);
17026 return RETURN_ERR;
17027 }
developere40952c2023-06-15 18:46:43 +080017028 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
17029 if (os_snprintf_error(sizeof(dat_file), res)) {
17030 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17031 return RETURN_ERR;
17032 }
developera1255e42023-05-13 17:45:02 +080017033 /*get current value in dat file*/
developera3511852023-06-14 14:12:59 +080017034 wifi_datfileRead(dat_file, "MuOfdmaDlEnable", ofdmabuf, sizeof(ofdmabuf));
17035 wifi_datfileRead(dat_file, "MuMimoDlEnable", mimobuf, sizeof(mimobuf));
developer72fb0bb2023-01-11 09:46:29 +080017036
developera1255e42023-05-13 17:45:02 +080017037 token = strtok(ofdmabuf, ";");
developerd14dff12023-06-28 22:47:44 +080017038 if (token == NULL) {
17039 wifi_debug(DEBUG_ERROR, "strtok fail\n");
17040 return RETURN_ERR;
17041 }
developerc14d83a2023-06-29 20:09:42 +080017042 if (hal_strtol(token, 10, &ofdma) < 0) {
17043 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developerd14dff12023-06-28 22:47:44 +080017044 }
developerc14d83a2023-06-29 20:09:42 +080017045
developera1255e42023-05-13 17:45:02 +080017046 token = strtok(mimobuf, ";");
developer37646972023-06-29 10:58:43 +080017047 if (token == NULL) {
17048 wifi_debug(DEBUG_ERROR, "Unexpected strtok fail\n");
17049 return RETURN_ERR;
17050 }
developerc14d83a2023-06-29 20:09:42 +080017051
17052 if (hal_strtol(token, 10, &mimo) < 0) {
17053 wifi_debug(DEBUG_ERROR, "strtol fail\n");
developer37646972023-06-29 10:58:43 +080017054 }
developerc14d83a2023-06-29 20:09:42 +080017055
developer9f2358c2023-09-22 18:42:12 +080017056 WIFI_ENTRY_EXIT_DEBUG("%s:ofdma=%ld,mimo=%ld\n", __func__, ofdma, mimo);
developera1255e42023-05-13 17:45:02 +080017057 if ((ofdma == 1) && (mimo == 1))
17058 *mu_type = WIFI_DL_MU_TYPE_OFDMA_MIMO;
17059 else if ((ofdma == 0) && (mimo == 1))
17060 *mu_type = WIFI_DL_MU_TYPE_MIMO;
17061 else if ((ofdma == 1) && (mimo == 0))
17062 *mu_type = WIFI_DL_MU_TYPE_OFDMA;
17063 else
17064 *mu_type = WIFI_DL_MU_TYPE_NONE;
developera3511852023-06-14 14:12:59 +080017065 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17066 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017067}
17068
17069INT wifi_setUplinkMuType(INT radio_index, wifi_ul_mu_type_t mu_type)
17070{
developera3511852023-06-14 14:12:59 +080017071 // hemu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))
developer863a4a62023-06-06 16:55:59 +080017072 CHAR dat_file[64] = {0};
developera3511852023-06-14 14:12:59 +080017073 wifi_band band = band_invalid;
17074 char ofdmabuf[32] = {'\0'};
17075 char mimobuf[32] = {'\0'};
17076 char new_ofdmabuf[32] = {'\0'};
17077 char new_mimobuf[32] = {'\0'};
17078 struct params params[2];
developera1255e42023-05-13 17:45:02 +080017079 char *str_zero = "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0";/*default 15bss per band.*/
17080 char *str_one = "1;1;1;1;1;1;1;1;1;1;1;1;1;1;1";
17081 UCHAR bss_cnt = 0;
17082 UCHAR val_cnt = 0;
developere40952c2023-06-15 18:46:43 +080017083 int res;
developer72fb0bb2023-01-11 09:46:29 +080017084
developera3511852023-06-14 14:12:59 +080017085 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
17086 band = wifi_index_to_band(radio_index);
developera1255e42023-05-13 17:45:02 +080017087 if (band == band_invalid) {
17088 printf("%s:Band Error\n", __func__);
17089 return RETURN_ERR;
17090 }
17091 if ((mu_type < WIFI_UL_MU_TYPE_NONE)
17092 || (mu_type > WIFI_UL_MU_TYPE_OFDMA)) {
17093 printf("%s:mu_type input Error\n", __func__);
17094 return RETURN_ERR;
17095 }
developere40952c2023-06-15 18:46:43 +080017096 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
17097 if (os_snprintf_error(sizeof(dat_file), res)) {
17098 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17099 return RETURN_ERR;
17100 }
developera1255e42023-05-13 17:45:02 +080017101 /*get current value in dat file*/
developera3511852023-06-14 14:12:59 +080017102 wifi_datfileRead(dat_file, "MuOfdmaUlEnable", ofdmabuf, sizeof(ofdmabuf));
17103 wifi_datfileRead(dat_file, "MuMimoUlEnable", mimobuf, sizeof(mimobuf));
developera1255e42023-05-13 17:45:02 +080017104 WIFI_ENTRY_EXIT_DEBUG("%s:ofdma-%s, mimo-%s\n", __func__, ofdmabuf, mimobuf);
17105 get_bssnum_byindex(radio_index, &bss_cnt);
17106 val_cnt = 2*bss_cnt - 1;
17107 printf("bssNumber:%d,ValCnt:%d\n", bss_cnt, val_cnt);
17108 if ((val_cnt >= sizeof(new_ofdmabuf))
17109 || (val_cnt >= sizeof(new_mimobuf))) {
developer49c83812023-06-06 14:23:53 +080017110 printf("%s:bss cnt Error\n", __func__);
developera1255e42023-05-13 17:45:02 +080017111 return RETURN_ERR;
17112 }
17113 /*translate set value*/
17114 if (mu_type == WIFI_UL_MU_TYPE_NONE) {
17115 strncpy(new_ofdmabuf, str_zero, val_cnt);
17116 strncpy(new_mimobuf, str_zero, val_cnt);
developera3511852023-06-14 14:12:59 +080017117 }
developera1255e42023-05-13 17:45:02 +080017118 if (mu_type == WIFI_UL_MU_TYPE_OFDMA) {
17119 strncpy(new_ofdmabuf, str_one, val_cnt);
17120 strncpy(new_mimobuf, str_zero, val_cnt);
developera3511852023-06-14 14:12:59 +080017121 }
developera1255e42023-05-13 17:45:02 +080017122 printf("%s:new_ofdmabuf-%s, new_mimobuf-%s\n", __func__, new_ofdmabuf, new_mimobuf);
17123 /*same value, not operation*/
17124 if ((strncmp(new_mimobuf, mimobuf, 1) ==0)
17125 && (strncmp(new_ofdmabuf, ofdmabuf, 1) ==0)) {
17126 printf("%s:Reduntant value\n", __func__);
17127 return RETURN_OK;
17128 }
17129 /*modify dat file to new file*/
17130 params[0].name="MuOfdmaUlEnable";
17131 params[0].value=new_ofdmabuf;
17132 params[1].name="MuMimoUlEnable";
17133 params[1].value=new_mimobuf;
17134 wifi_datfileWrite(dat_file, params, 2);
17135 wifi_reloadAp(radio_index);
developera3511852023-06-14 14:12:59 +080017136 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17137 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017138}
17139
17140INT wifi_getUplinkMuType(INT radio_index, wifi_ul_mu_type_t *mu_type)
17141{
developer863a4a62023-06-06 16:55:59 +080017142 CHAR dat_file[64] = {0};
developera3511852023-06-14 14:12:59 +080017143 wifi_band band = band_invalid;
17144 char ofdmabuf[32] = {'\0'};
17145 char mimobuf[32] = {'\0'};
developera1255e42023-05-13 17:45:02 +080017146 char *token = NULL;
17147 UCHAR ofdma = 0;
17148 UCHAR mimo = 0;
developere40952c2023-06-15 18:46:43 +080017149 int res;
developerc14d83a2023-06-29 20:09:42 +080017150 unsigned long tmp;
developer72fb0bb2023-01-11 09:46:29 +080017151
developera3511852023-06-14 14:12:59 +080017152 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080017153
developera3511852023-06-14 14:12:59 +080017154 if (mu_type == NULL)
17155 return RETURN_ERR;
developera1255e42023-05-13 17:45:02 +080017156 band = wifi_index_to_band(radio_index);
17157 if (band == band_invalid) {
17158 printf("%s:Band Error", __func__);
17159 return RETURN_ERR;
17160 }
developere40952c2023-06-15 18:46:43 +080017161 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
17162 if (os_snprintf_error(sizeof(dat_file), res)) {
17163 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17164 return RETURN_ERR;
17165 }
developera1255e42023-05-13 17:45:02 +080017166 /*get current value in dat file*/
17167 wifi_datfileRead(dat_file, "MuOfdmaUlEnable", ofdmabuf, sizeof(ofdmabuf));
17168 wifi_datfileRead(dat_file, "MuMimoUlEnable", mimobuf, sizeof(mimobuf));
developer72fb0bb2023-01-11 09:46:29 +080017169
developera1255e42023-05-13 17:45:02 +080017170 token = strtok(ofdmabuf, ";");
developerd14dff12023-06-28 22:47:44 +080017171 if (token == NULL) {
17172 wifi_debug(DEBUG_ERROR, "strtok fail\n");
17173 return RETURN_ERR;
17174 }
developerc14d83a2023-06-29 20:09:42 +080017175
17176 if (hal_strtoul(token, 10, &tmp) < 0) {
17177 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerd14dff12023-06-28 22:47:44 +080017178 }
developerc14d83a2023-06-29 20:09:42 +080017179 ofdma = tmp;
developera1255e42023-05-13 17:45:02 +080017180 token = strtok(mimobuf, ";");
developer37646972023-06-29 10:58:43 +080017181 if (token == NULL) {
17182 wifi_debug(DEBUG_ERROR, "strtok fail\n");
17183 return RETURN_ERR;
17184 }
developer5b23cd02023-07-19 20:26:03 +080017185
developerc14d83a2023-06-29 20:09:42 +080017186 if (hal_strtoul(token, 10, &tmp) < 0) {
17187 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developer37646972023-06-29 10:58:43 +080017188 }
developerc14d83a2023-06-29 20:09:42 +080017189 mimo = tmp;
17190
developera1255e42023-05-13 17:45:02 +080017191 WIFI_ENTRY_EXIT_DEBUG("%s:ofdma=%d, mimo=%d\n", __func__, ofdma, mimo);
17192 if ((ofdma == 1) && (mimo == 0))
17193 *mu_type = WIFI_UL_MU_TYPE_OFDMA;
17194 else
17195 *mu_type = WIFI_UL_MU_TYPE_NONE;
developera3511852023-06-14 14:12:59 +080017196 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17197 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017198}
17199
17200
17201INT wifi_setGuardInterval(INT radio_index, wifi_guard_interval_t guard_interval)
17202{
developer8078acf2023-08-04 18:52:48 +080017203
developera3511852023-06-14 14:12:59 +080017204 char buf[256] = {0};
17205 char config_file[64] = {0};
17206 char GI[8] = {0};
17207 UINT mode_map = 0;
17208 FILE *f = NULL;
17209 wifi_band band = band_invalid;
17210 char dat_file[64] = {'\0'};
17211 struct params params[3];
developere40952c2023-06-15 18:46:43 +080017212 int res;
developer72fb0bb2023-01-11 09:46:29 +080017213
developera3511852023-06-14 14:12:59 +080017214 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080017215
developera3511852023-06-14 14:12:59 +080017216 if (wifi_getRadioMode(radio_index, buf, &mode_map) == RETURN_ERR) {
17217 wifi_dbg_printf("%s: wifi_getRadioMode return error\n", __func__);
17218 return RETURN_ERR;
17219 }
developera1255e42023-05-13 17:45:02 +080017220 /*sanity check*/
17221 if (((guard_interval == wifi_guard_interval_1600)
17222 || (guard_interval == wifi_guard_interval_3200))
developerdaf24792023-06-06 11:40:04 +080017223 && ((mode_map & (WIFI_MODE_BE | WIFI_MODE_AX)) == 0)) {
developera3511852023-06-14 14:12:59 +080017224 wifi_dbg_printf("%s: N/AC Mode not support 1600/3200ns GI\n", __func__);
17225 return RETURN_ERR;
developera1255e42023-05-13 17:45:02 +080017226 }
developere40952c2023-06-15 18:46:43 +080017227 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radio_index);
17228 if (os_snprintf_error(sizeof(config_file), res)) {
17229 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17230 return RETURN_ERR;
17231 }
developera3511852023-06-14 14:12:59 +080017232 band = wifi_index_to_band(radio_index);
developer72fb0bb2023-01-11 09:46:29 +080017233
developera3511852023-06-14 14:12:59 +080017234 // Hostapd are not supported HE mode GI 1600, 3200 ns.
17235 if (guard_interval == wifi_guard_interval_800) { // remove all capab about short GI
developer8078acf2023-08-04 18:52:48 +080017236 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i 's/\\[SHORT-GI-(.){1,2}0\\]//g' %s", config_file);
17237 if (res) {
17238 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
17239
developere40952c2023-06-15 18:46:43 +080017240 }
developer8078acf2023-08-04 18:52:48 +080017241
developera3511852023-06-14 14:12:59 +080017242 } else if (guard_interval == wifi_guard_interval_400 || guard_interval == wifi_guard_interval_auto){
17243 wifi_hostapdRead(config_file, "ht_capab", buf, sizeof(buf));
17244 if (strstr(buf, "[SHORT-GI-") == NULL) {
developer8078acf2023-08-04 18:52:48 +080017245 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^ht_capab=.*/s/$/[SHORT-GI-20][SHORT-GI-40]/' %s", config_file);
17246 if (res) {
17247 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
17248
developere40952c2023-06-15 18:46:43 +080017249 }
developer8078acf2023-08-04 18:52:48 +080017250
developera3511852023-06-14 14:12:59 +080017251 }
17252 if (band == band_5) {
17253 wifi_hostapdRead(config_file, "vht_capab", buf, sizeof(buf));
17254 if (strstr(buf, "[SHORT-GI-") == NULL) {
developer8078acf2023-08-04 18:52:48 +080017255 res = _syscmd_secure(buf, sizeof(buf), "sed -r -i '/^vht_capab=.*/s/$/[SHORT-GI-80][SHORT-GI-160]/' %s", config_file);
17256 if (res) {
17257 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
17258
developere40952c2023-06-15 18:46:43 +080017259 }
developer8078acf2023-08-04 18:52:48 +080017260
developera3511852023-06-14 14:12:59 +080017261 }
17262 }
17263 }
17264 /*wifi_reloadAp(radio_index);
developera1255e42023-05-13 17:45:02 +080017265 caller "wifi_setRadioOperatingParameters" have done this step.
17266 */
developere40952c2023-06-15 18:46:43 +080017267 res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, band);
17268 if (os_snprintf_error(sizeof(dat_file), res)) {
17269 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17270 return RETURN_ERR;
17271 }
developera3511852023-06-14 14:12:59 +080017272 if (guard_interval == wifi_guard_interval_400) {
developera1255e42023-05-13 17:45:02 +080017273 params[0].name = "HT_GI";
17274 params[0].value = "1";
17275 params[1].name = "VHT_SGI";
17276 params[1].value = "1";
17277 wifi_datfileWrite(dat_file, params, 2);
developer32f2a182023-06-27 19:50:41 +080017278 memcpy(GI, "0.4", 3);
developera1255e42023-05-13 17:45:02 +080017279 } else {
17280 params[0].name = "HT_GI";
17281 params[0].value = "0";
17282 params[1].name = "VHT_SGI";
17283 params[1].value = "0";
17284 /*should enable FIXED_HE_GI_SUPPORT in driver*/
17285 params[2].name = "FgiFltf";
17286 if (guard_interval == wifi_guard_interval_800) {
17287 params[2].value = "800";
developer32f2a182023-06-27 19:50:41 +080017288 memcpy(GI, "0.8", 3);
developera1255e42023-05-13 17:45:02 +080017289 } else if (guard_interval == wifi_guard_interval_1600) {
17290 params[2].value = "1600";
developer32f2a182023-06-27 19:50:41 +080017291 memcpy(GI, "1.6", 3);
developera1255e42023-05-13 17:45:02 +080017292 } else if (guard_interval == wifi_guard_interval_3200) {
17293 params[2].value = "3200";
developer32f2a182023-06-27 19:50:41 +080017294 memcpy(GI, "3.2", 3);
developera1255e42023-05-13 17:45:02 +080017295 } else if (guard_interval == wifi_guard_interval_auto) {
17296 params[2].value = "0";
developer32f2a182023-06-27 19:50:41 +080017297 memcpy(GI, "auto", 4);
developera1255e42023-05-13 17:45:02 +080017298 }
17299 wifi_datfileWrite(dat_file, params, 3);
17300 }
developera3511852023-06-14 14:12:59 +080017301 // Record GI for get GI function
developere40952c2023-06-15 18:46:43 +080017302 res = snprintf(buf, sizeof(buf), "%s%d.txt", GUARD_INTERVAL_FILE, radio_index);
17303 if (os_snprintf_error(sizeof(buf), res)) {
17304 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17305 return RETURN_ERR;
17306 }
developera3511852023-06-14 14:12:59 +080017307 f = fopen(buf, "w");
17308 if (f == NULL)
17309 return RETURN_ERR;
17310 fprintf(f, "%s", GI);
developerc14d83a2023-06-29 20:09:42 +080017311 if (fclose(f) == EOF)
17312 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
developera3511852023-06-14 14:12:59 +080017313 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17314 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017315}
17316
17317INT wifi_getGuardInterval(INT radio_index, wifi_guard_interval_t *guard_interval)
17318{
developera3511852023-06-14 14:12:59 +080017319 char buf[32] = {0};
developere40952c2023-06-15 18:46:43 +080017320 int res;
developer72fb0bb2023-01-11 09:46:29 +080017321
developera3511852023-06-14 14:12:59 +080017322 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080017323
developera3511852023-06-14 14:12:59 +080017324 if (guard_interval == NULL)
17325 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080017326
developer8078acf2023-08-04 18:52:48 +080017327 res = _syscmd_secure(buf, sizeof(buf), "cat %s%d.txt 2> /dev/null", GUARD_INTERVAL_FILE, radio_index);
17328 if (res) {
17329 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
developere40952c2023-06-15 18:46:43 +080017330 }
developer72fb0bb2023-01-11 09:46:29 +080017331
developera3511852023-06-14 14:12:59 +080017332 if (strncmp(buf, "0.4", 3) == 0)
17333 *guard_interval = wifi_guard_interval_400;
17334 else if (strncmp(buf, "0.8", 3) == 0)
17335 *guard_interval = wifi_guard_interval_800;
17336 else if (strncmp(buf, "1.6", 3) == 0)
17337 *guard_interval = wifi_guard_interval_1600;
17338 else if (strncmp(buf, "3.2", 3) == 0)
17339 *guard_interval = wifi_guard_interval_3200;
17340 else
17341 *guard_interval = wifi_guard_interval_auto;
developer72fb0bb2023-01-11 09:46:29 +080017342
developera3511852023-06-14 14:12:59 +080017343 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17344 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017345}
17346
17347INT wifi_setBSSColor(INT radio_index, UCHAR color)
17348{
developera3511852023-06-14 14:12:59 +080017349 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
17350 struct params params = {0};
17351 char config_file[128] = {0};
17352 char bss_color[4] ={0};
developere40952c2023-06-15 18:46:43 +080017353 int res;
developer72fb0bb2023-01-11 09:46:29 +080017354
developera1255e42023-05-13 17:45:02 +080017355 if (color < 1 || color > 63) {
17356 wifi_dbg_printf("color value is err:%d.\n", color);
17357 return RETURN_ERR;
17358 }
developera3511852023-06-14 14:12:59 +080017359 params.name = "he_bss_color";
developere40952c2023-06-15 18:46:43 +080017360 res = snprintf(bss_color, sizeof(bss_color), "%hhu", color);
17361 if (os_snprintf_error(sizeof(bss_color), res)) {
17362 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17363 return RETURN_ERR;
17364 }
developera3511852023-06-14 14:12:59 +080017365 params.value = bss_color;
developer75bd10c2023-06-27 11:34:08 +080017366
17367 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radio_index);
17368 if (os_snprintf_error(sizeof(config_file), res)) {
17369 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17370 return RETURN_ERR;
17371 }
developera3511852023-06-14 14:12:59 +080017372 wifi_hostapdWrite(config_file, &params, 1);
17373 //wifi_hostapdProcessUpdate(radio_index, &params, 1);
developera1255e42023-05-13 17:45:02 +080017374 wifi_reloadAp(radio_index);
developer69b61b02023-03-07 17:17:44 +080017375
developera3511852023-06-14 14:12:59 +080017376 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
17377 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017378}
17379
17380INT wifi_getBSSColor(INT radio_index, UCHAR *color)
17381{
developera3511852023-06-14 14:12:59 +080017382 char config_file[128] = {0};
17383 char buf[64] = {0};
17384 char temp_output[128] = {'\0'};
developere40952c2023-06-15 18:46:43 +080017385 int res;
developerc14d83a2023-06-29 20:09:42 +080017386 unsigned long tmp;
developer72fb0bb2023-01-11 09:46:29 +080017387
developera3511852023-06-14 14:12:59 +080017388 wifi_dbg_printf("\nFunc=%s\n", __func__);
17389 if (NULL == color)
17390 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080017391
developer75bd10c2023-06-27 11:34:08 +080017392 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radio_index);
17393 if (os_snprintf_error(sizeof(config_file), res)) {
17394 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17395 return RETURN_ERR;
17396 }
developera3511852023-06-14 14:12:59 +080017397 wifi_hostapdRead(config_file, "he_bss_color", buf, sizeof(buf));
developer72fb0bb2023-01-11 09:46:29 +080017398
developera3511852023-06-14 14:12:59 +080017399 if(strlen(buf) > 0) {
developere40952c2023-06-15 18:46:43 +080017400 res = snprintf(temp_output, sizeof(temp_output), "%s", buf);
developera3511852023-06-14 14:12:59 +080017401 } else {
developere40952c2023-06-15 18:46:43 +080017402 res = snprintf(temp_output, sizeof(temp_output), "1"); // default value
17403 }
17404 if (os_snprintf_error(sizeof(temp_output), res)) {
17405 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17406 return RETURN_ERR;
developera3511852023-06-14 14:12:59 +080017407 }
developer72fb0bb2023-01-11 09:46:29 +080017408
developerc14d83a2023-06-29 20:09:42 +080017409 if (hal_strtoul(temp_output, 10, &tmp) < 0) {
17410 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerd14dff12023-06-28 22:47:44 +080017411 }
developerc14d83a2023-06-29 20:09:42 +080017412 *color = tmp;
developera3511852023-06-14 14:12:59 +080017413 wifi_dbg_printf("\noutput_string=%s\n", color);
developer72fb0bb2023-01-11 09:46:29 +080017414
developera3511852023-06-14 14:12:59 +080017415 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017416}
17417
17418/* multi-psk support */
17419INT wifi_getMultiPskClientKey(INT apIndex, mac_address_t mac, wifi_key_multi_psk_t *key)
17420{
developera3511852023-06-14 14:12:59 +080017421 char cmd[256];
17422 char interface_name[16] = {0};
developer75bd10c2023-06-27 11:34:08 +080017423 int res;
developer72fb0bb2023-01-11 09:46:29 +080017424
developera3511852023-06-14 14:12:59 +080017425 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
17426 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080017427
developer75bd10c2023-06-27 11:34:08 +080017428 res = snprintf(cmd, sizeof(cmd), "hostapd_cli -i %s sta %x:%x:%x:%x:%x:%x |grep '^keyid' | cut -f 2 -d = | tr -d '\n'",
developera3511852023-06-14 14:12:59 +080017429 interface_name,
17430 mac[0],
17431 mac[1],
17432 mac[2],
17433 mac[3],
17434 mac[4],
17435 mac[5]
17436 );
developer75bd10c2023-06-27 11:34:08 +080017437 if (os_snprintf_error(sizeof(cmd), res)) {
17438 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17439 return RETURN_ERR;
17440 }
developera3511852023-06-14 14:12:59 +080017441 printf("DEBUG LOG wifi_getMultiPskClientKey(%s)\n",cmd);
developer8078acf2023-08-04 18:52:48 +080017442
17443 res = _syscmd_secure(key->wifi_keyId, 64, "hostapd_cli -i %s sta %x:%x:%x:%x:%x:%x |grep '^keyid' | cut -f 2 -d = | tr -d '\n'",interface_name,mac[0],mac[1],mac[2], mac[3], mac[4], mac[5]);
17444 if(res) {
17445 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
17446 }
developer72fb0bb2023-01-11 09:46:29 +080017447
17448
developera3511852023-06-14 14:12:59 +080017449 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017450}
17451
17452INT wifi_pushMultiPskKeys(INT apIndex, wifi_key_multi_psk_t *keys, INT keysNumber)
17453{
developera3511852023-06-14 14:12:59 +080017454 char interface_name[16] = {0};
17455 FILE *fd = NULL;
17456 char fname[100];
developer8078acf2023-08-04 18:52:48 +080017457
developera3511852023-06-14 14:12:59 +080017458 char out[64] = {0};
17459 wifi_key_multi_psk_t * key = NULL;
developer75bd10c2023-06-27 11:34:08 +080017460 int res, ret;
developere40952c2023-06-15 18:46:43 +080017461
developera3511852023-06-14 14:12:59 +080017462 if(keysNumber < 0)
17463 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080017464
developere40952c2023-06-15 18:46:43 +080017465 res = snprintf(fname, sizeof(fname), "%s%d.psk", PSK_FILE, apIndex);
17466 if (os_snprintf_error(sizeof(fname), res)) {
17467 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17468 return RETURN_ERR;
17469 }
developera3511852023-06-14 14:12:59 +080017470 fd = fopen(fname, "w");
17471 if (!fd) {
17472 return RETURN_ERR;
17473 }
17474 key= (wifi_key_multi_psk_t *) keys;
17475 for(int i=0; i<keysNumber; ++i, key++) {
developer75bd10c2023-06-27 11:34:08 +080017476 ret = fprintf(fd, "keyid=%s 00:00:00:00:00:00 %s\n", key->wifi_keyId, key->wifi_psk);
17477 if (ret < 0)
17478 wifi_debug(DEBUG_ERROR, "fprintf fail\n");
developera3511852023-06-14 14:12:59 +080017479 }
developerd14dff12023-06-28 22:47:44 +080017480 if (fclose(fd) != 0) {
17481 wifi_debug(DEBUG_ERROR, "fclose fail\n");
17482 return RETURN_ERR;
17483 }
developer72fb0bb2023-01-11 09:46:29 +080017484
developera3511852023-06-14 14:12:59 +080017485 //reload file
17486 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
17487 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080017488 res = _syscmd_secure(out, 64, "hostapd_cli -i%s raw RELOAD_WPA_PSK", interface_name);
developer32f2a182023-06-27 19:50:41 +080017489
developer8078acf2023-08-04 18:52:48 +080017490 if (res) {
17491 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
17492
developer32f2a182023-06-27 19:50:41 +080017493 }
developer8078acf2023-08-04 18:52:48 +080017494
developera3511852023-06-14 14:12:59 +080017495 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017496}
17497
17498INT wifi_getMultiPskKeys(INT apIndex, wifi_key_multi_psk_t *keys, INT keysNumber)
17499{
developera3511852023-06-14 14:12:59 +080017500 FILE *fd = NULL;
17501 char fname[100];
17502 char * line = NULL;
17503 char * pos = NULL;
17504 size_t len = 0;
17505 ssize_t read = 0;
17506 INT ret = RETURN_OK;
17507 wifi_key_multi_psk_t *keys_it = NULL;
developere40952c2023-06-15 18:46:43 +080017508 int res;
developer72fb0bb2023-01-11 09:46:29 +080017509
developera3511852023-06-14 14:12:59 +080017510 if (keysNumber < 1) {
17511 return RETURN_ERR;
17512 }
developer72fb0bb2023-01-11 09:46:29 +080017513
developere40952c2023-06-15 18:46:43 +080017514 res = snprintf(fname, sizeof(fname), "%s%d.psk", PSK_FILE, apIndex);
17515 if (os_snprintf_error(sizeof(fname), res)) {
17516 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17517 return RETURN_ERR;
17518 }
developera3511852023-06-14 14:12:59 +080017519 fd = fopen(fname, "r");
17520 if (!fd) {
17521 return RETURN_ERR;
17522 }
developer72fb0bb2023-01-11 09:46:29 +080017523
developera3511852023-06-14 14:12:59 +080017524 if (keys == NULL) {
17525 ret = RETURN_ERR;
17526 goto close;
17527 }
developer72fb0bb2023-01-11 09:46:29 +080017528
developera3511852023-06-14 14:12:59 +080017529 keys_it = keys;
17530 while ((read = getline(&line, &len, fd)) != -1) {
17531 //Strip trailing new line if present
17532 if (read > 0 && line[read-1] == '\n') {
17533 line[read-1] = '\0';
17534 }
developer72fb0bb2023-01-11 09:46:29 +080017535
developera3511852023-06-14 14:12:59 +080017536 if(strcmp(line,"keyid=")) {
developer37646972023-06-29 10:58:43 +080017537 if (sscanf(line, "keyid=%63s", keys_it->wifi_keyId) == EOF)
17538 continue;
developera3511852023-06-14 14:12:59 +080017539 if (!(pos = index(line, ' '))) {
17540 ret = RETURN_ERR;
17541 goto close;
17542 }
17543 pos++;
17544 //Here should be 00:00:00:00:00:00
17545 if (!(strcmp(pos,"00:00:00:00:00:00"))) {
17546 printf("Not supported MAC: %s\n", pos);
17547 }
17548 if (!(pos = index(pos, ' '))) {
17549 ret = RETURN_ERR;
17550 goto close;
17551 }
17552 pos++;
developer72fb0bb2023-01-11 09:46:29 +080017553
developera3511852023-06-14 14:12:59 +080017554 //The rest is PSK
developere40952c2023-06-15 18:46:43 +080017555 res = snprintf(&keys_it->wifi_psk[0], sizeof(keys_it->wifi_psk), "%s", pos);
17556 if (os_snprintf_error(sizeof(keys_it->wifi_psk), res)) {
17557 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developerc14d83a2023-06-29 20:09:42 +080017558 if (fclose(fd) == EOF)
17559 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
developer5b23cd02023-07-19 20:26:03 +080017560
developere40952c2023-06-15 18:46:43 +080017561 return RETURN_ERR;
17562 }
17563
developera3511852023-06-14 14:12:59 +080017564 keys_it++;
developer72fb0bb2023-01-11 09:46:29 +080017565
developera3511852023-06-14 14:12:59 +080017566 if(--keysNumber <= 0)
developer72fb0bb2023-01-11 09:46:29 +080017567 break;
developera3511852023-06-14 14:12:59 +080017568 }
17569 }
developer72fb0bb2023-01-11 09:46:29 +080017570
17571close:
developera3511852023-06-14 14:12:59 +080017572 free(line);
developer37646972023-06-29 10:58:43 +080017573 if (fclose(fd) == EOF)
17574 wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
developera3511852023-06-14 14:12:59 +080017575 return ret;
developer72fb0bb2023-01-11 09:46:29 +080017576}
17577/* end of multi-psk support */
17578
17579INT wifi_setNeighborReports(UINT apIndex,
developera3511852023-06-14 14:12:59 +080017580 UINT numNeighborReports,
17581 wifi_NeighborReport_t *neighborReports)
developer72fb0bb2023-01-11 09:46:29 +080017582{
developera3511852023-06-14 14:12:59 +080017583 char hex_bssid[13] = { 0 };
17584 char bssid[18] = { 0 };
17585 char nr[100] = { 0 };
17586 char ssid[32];
17587 char hex_ssid[32];
17588 char interface_name[16] = {0};
17589 INT ret;
developere40952c2023-06-15 18:46:43 +080017590 int res;
developerd14dff12023-06-28 22:47:44 +080017591 unsigned char hex_ssid_len;
developer72fb0bb2023-01-11 09:46:29 +080017592
developera3511852023-06-14 14:12:59 +080017593 /*rmeove all neighbors*/
17594 wifi_dbg_printf("\n[%s]: removing all neighbors from %s\n", __func__, interface_name);
17595 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
17596 return RETURN_ERR;
developer33f13ba2023-07-12 16:19:06 +080017597
17598 res = v_secure_system("hostapd_cli show_neighbor -i %s | awk '{print $1 \" \" $2}' | xargs -n2 -r hostapd_cli remove_neighbor -i %s",
developer32f2a182023-06-27 19:50:41 +080017599 interface_name, interface_name);
17600
developer33f13ba2023-07-12 16:19:06 +080017601 if (res) {
17602 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developer75bd10c2023-06-27 11:34:08 +080017603 return RETURN_ERR;
17604 }
developer72fb0bb2023-01-11 09:46:29 +080017605
developera3511852023-06-14 14:12:59 +080017606 for(unsigned int i = 0; i < numNeighborReports; i++)
17607 {
17608 memset(ssid, 0, sizeof(ssid));
17609 ret = wifi_getSSIDName(apIndex, ssid);
17610 if (ret != RETURN_OK)
17611 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080017612
developera3511852023-06-14 14:12:59 +080017613 memset(hex_ssid, 0, sizeof(hex_ssid));
developerd14dff12023-06-28 22:47:44 +080017614 hex_ssid_len = sizeof(hex_ssid);
17615 for(size_t j = 0,k = 0; ssid[j] != '\0' && k < sizeof(hex_ssid); j++,k+=2 ) {
17616 res = snprintf(hex_ssid + k, hex_ssid_len, "%02x", ssid[j]);
17617
17618 if (os_snprintf_error(hex_ssid_len, res)) {
17619 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17620 return RETURN_ERR;
17621 }
17622 hex_ssid_len = sizeof(hex_ssid) - strlen(hex_ssid);
17623 }
developer72fb0bb2023-01-11 09:46:29 +080017624
developere40952c2023-06-15 18:46:43 +080017625 res = snprintf(hex_bssid, sizeof(hex_bssid),
developera3511852023-06-14 14:12:59 +080017626 "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
17627 neighborReports[i].bssid[0], neighborReports[i].bssid[1], neighborReports[i].bssid[2], neighborReports[i].bssid[3], neighborReports[i].bssid[4], neighborReports[i].bssid[5]);
developere40952c2023-06-15 18:46:43 +080017628 if (os_snprintf_error(sizeof(hex_bssid), res)) {
17629 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17630 return RETURN_ERR;
17631 }
17632 res = snprintf(bssid, sizeof(bssid),
developera3511852023-06-14 14:12:59 +080017633 "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
17634 neighborReports[i].bssid[0], neighborReports[i].bssid[1], neighborReports[i].bssid[2], neighborReports[i].bssid[3], neighborReports[i].bssid[4], neighborReports[i].bssid[5]);
developere40952c2023-06-15 18:46:43 +080017635 if (os_snprintf_error(sizeof(bssid), res)) {
17636 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17637 return RETURN_ERR;
17638 }
developer72fb0bb2023-01-11 09:46:29 +080017639
developere40952c2023-06-15 18:46:43 +080017640 res = snprintf(nr, sizeof(nr),
developera3511852023-06-14 14:12:59 +080017641 "%s" // bssid
17642 "%02hhx%02hhx%02hhx%02hhx" // bssid_info
17643 "%02hhx" // operclass
17644 "%02hhx" // channel
17645 "%02hhx", // phy_mode
17646 hex_bssid,
17647 neighborReports[i].info & 0xff, (neighborReports[i].info >> 8) & 0xff,
17648 (neighborReports[i].info >> 16) & 0xff, (neighborReports[i].info >> 24) & 0xff,
17649 neighborReports[i].opClass,
17650 neighborReports[i].channel,
17651 neighborReports[i].phyTable);
developere40952c2023-06-15 18:46:43 +080017652 if (os_snprintf_error(sizeof(nr), res)) {
17653 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
17654 return RETURN_ERR;
17655 }
developer72fb0bb2023-01-11 09:46:29 +080017656
developer33f13ba2023-07-12 16:19:06 +080017657 res = v_secure_system("hostapd_cli set_neighbor %s ssid=%s nr=%s -i %s",
17658 bssid, hex_ssid, nr, interface_name);
17659 if (res) {
17660 wifi_debug(DEBUG_ERROR, "v_secure_system fail\n");
developere40952c2023-06-15 18:46:43 +080017661 return RETURN_ERR;
17662 }
developera3511852023-06-14 14:12:59 +080017663 }
developer72fb0bb2023-01-11 09:46:29 +080017664
developera3511852023-06-14 14:12:59 +080017665 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017666}
17667
17668INT wifi_getApInterworkingElement(INT apIndex, wifi_InterworkingElement_t *output_struct)
17669{
developera3511852023-06-14 14:12:59 +080017670 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080017671}
17672
17673#ifdef _WIFI_HAL_TEST_
17674int main(int argc,char **argv)
17675{
developera3511852023-06-14 14:12:59 +080017676 int index;
17677 INT ret=0;
17678 char buf[1024]="";
developer72fb0bb2023-01-11 09:46:29 +080017679
developera3511852023-06-14 14:12:59 +080017680 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
17681 if(argc<3)
17682 {
17683 if(argc==2)
17684 {
17685 if(!strcmp(argv[1], "init"))
17686 return wifi_init();
17687 if(!strcmp(argv[1], "reset"))
17688 return wifi_reset();
17689 if(!strcmp(argv[1], "wifi_getHalVersion"))
17690 {
17691 char buffer[64];
17692 if(wifi_getHalVersion(buffer)==RETURN_OK)
17693 printf("Version: %s\n", buffer);
17694 else
17695 printf("Error in wifi_getHalVersion\n");
17696 return RETURN_OK;
17697 }
17698 }
17699 printf("wifihal <API> <radioIndex> <arg1> <arg2> ...\n");
17700 exit(-1);
17701 }
developer72fb0bb2023-01-11 09:46:29 +080017702
developera3511852023-06-14 14:12:59 +080017703 index = atoi(argv[2]);
developer33f13ba2023-07-12 16:19:06 +080017704 if (strstr(argv[1], "test_system")!=NULL) {
17705 ret = v_secure_system("iw phy | grep 'MHz \\[' | cut -d' ' -f2,4 > /tmp/freq-channel-map.txt");
17706 printf("ret = %d\n", ret);
17707
17708 ret = v_secure_system("hostapd_cli show_neighbor -i %s | awk '{print $1 \" \" $2}' | xargs -n2 -r hostapd_cli remove_neighbor -i %s",
17709 "ra0", "ra0");
17710 printf("ret = %d\n", ret);
17711
17712 ret = v_secure_system("echo %s > /var/prevchanval2G_AutoChannelEnable", "1,2,3");
17713 printf("ret = %d\n", ret);
17714
17715 ret = v_secure_system("ifconfig -a %s > /tmp/Radio_Stats.txt", "rai0");
17716 printf("ret = %d\n", ret);
17717
17718 ret = v_secure_system("ifconfig %s > /tmp/SSID_Stats.txt", "rax0");
17719 printf("ret = %d\n", ret);
17720
17721 ret = v_secure_system("iw dev %s station dump > /tmp/AssociatedDevice_Stats.txt", "ra0");
17722 printf("ret = %d\n", ret);
17723 ret = v_secure_system("iw dev %s station dump | grep Station >> /tmp/AllAssociated_Devices_5G.txt", "ra0");
17724 printf("ret = %d\n", ret);
17725 ret = v_secure_system("ping -q -c 1 -W 1 \"%s\" > /dev/console 2>&1", "20.1.1.101");
17726 printf("ret = %d\n", ret);
17727
17728 return 0;
17729 }
17730
17731 if (strstr(argv[1], "test_popen")!=NULL) {
17732 FILE *fp = v_secure_popen("w", "cat");
17733 fprintf(fp, "popen write success\n");
17734 fclose(fp);
17735
17736 char buf[1024];
17737 memset(buf, 0, sizeof(buf));
17738 fp = v_secure_popen("r", "echo popen read success");
17739 if (fp == NULL) {
17740 printf("v_secure_popen failed\n");
17741 } else {
17742 if (fgets(buf, sizeof(buf), fp) == NULL) {
17743 printf("v_secure_popen read error\n");
17744 } else {
17745 printf("%s\n", buf);
17746 }
17747 v_secure_pclose(fp);
17748 }
17749
17750#if 0
17751 fp = v_secure_popen("r", "hostapd_cli -i %s reload", "ra0");
17752 if (fp == NULL) {
17753 printf("v_secure_popen failed\n");
17754 } else {
17755 if (fgets(buf, sizeof(buf), fp) == NULL) {
17756 printf("v_secure_popen read error\n");
17757 } else {
17758 printf("%s", buf);
17759 }
17760 v_secure_pclose(fp);
17761 }
17762#endif
17763
17764 long int band;
17765 memset(buf, 0, sizeof(buf));
17766 ret = _syscmd_secure(buf, sizeof(buf),
17767 "iw phy%d info | grep 'Band .:' | tail -n 1 | tr -d ':\\n' | awk '{print $2}'", 0);
17768 if (hal_strtol(buf, 16, &band) < 0) {
17769 wifi_debug(DEBUG_ERROR, "strtol fail\n");
17770 }
17771 printf("ret = %d, band0=%ld\n", ret, band);
17772
17773 memset(buf, 0, sizeof(buf));
17774 ret = _syscmd_secure(buf, sizeof(buf),
17775 "iw phy%d info | grep 'Band .:' | tail -n 1 | tr -d ':\\n' | awk '{print $2}'", 1);
17776 if (hal_strtol(buf, 16, &band) < 0) {
17777 wifi_debug(DEBUG_ERROR, "strtol fail\n");
17778 }
17779 printf("ret = %d, band1=%ld\n", ret, band);
17780
17781 memset(buf, 0, sizeof(buf));
17782 ret = _syscmd_secure(buf, sizeof(buf),
17783 "iw phy%d info | grep 'Band .:' | tail -n 1 | tr -d ':\\n' | awk '{print $2}'", 2);
17784 if (hal_strtol(buf, 16, &band) < 0) {
17785 wifi_debug(DEBUG_ERROR, "strtol fail\n");
17786 }
17787 printf("ret = %d, band2=%ld\n", ret, band);
17788 }
17789
developera3511852023-06-14 14:12:59 +080017790 if(strstr(argv[1], "wifi_getApName")!=NULL)
17791 {
17792 wifi_getApName(index,buf);
17793 printf("Ap name is %s \n",buf);
17794 return 0;
17795 }
developerb14b3462023-07-01 18:02:42 +080017796 if(strstr(argv[1], "wifi_getRadioExtChannel")!=NULL)
17797 {
17798 wifi_getRadioExtChannel(index,buf);
17799 printf("extchannel is %s \n",buf);
17800 return 0;
17801 }
developer37ad6bf2023-10-09 11:31:05 +080017802 if (strstr(argv[1], "wifi_setRadioAMSDUEnable")!=NULL) {
17803 unsigned char enable = atoi(argv[3]);
17804 BOOL out_put;
17805 if (enable)
17806 wifi_setRadioAMSDUEnable(index, TRUE);
17807 else
17808 wifi_setRadioAMSDUEnable(index, FALSE);
17809 wifi_getRadioAMSDUEnable(index, &out_put);
17810 printf("amsdu = %d\n", out_put);
17811 }
17812 if (strstr(argv[1], "wifi_setApIsolationEnable")!=NULL) {
17813 unsigned char enable = atoi(argv[3]);
17814 BOOL out_put;
17815 if (enable)
17816 wifi_setApIsolationEnable(index, TRUE);
17817 else
17818 wifi_setApIsolationEnable(index, FALSE);
17819 wifi_getApIsolationEnable(index, &out_put);
17820 printf("isolation input=%d, output=%d\n", enable, out_put);
17821 }
developerfead3972023-05-25 20:15:02 +080017822 if(strstr(argv[1], "wifi_setRadioMode")!=NULL)
developera3511852023-06-14 14:12:59 +080017823 {
developer2a6abc92023-10-17 17:19:14 +080017824 UINT pureMode;
17825 if(argc <= 3)
17826 {
17827 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17828 exit(-1);
17829 }
developerfead3972023-05-25 20:15:02 +080017830
developer2a6abc92023-10-17 17:19:14 +080017831 pureMode = atoi(argv[3]);
developera3511852023-06-14 14:12:59 +080017832 wifi_setRadioMode(index, NULL, pureMode);
17833 printf("Ap SET Radio mode 0x%x\n", pureMode);
17834 return 0;
17835 }
17836 if (strstr(argv[1], "wifi_setRadioAutoBlockAckEnable") != NULL) {
developer2a6abc92023-10-17 17:19:14 +080017837 unsigned char enable;
17838 if(argc <= 3)
17839 {
17840 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17841 exit(-1);
17842 }
17843 enable = atoi(argv[3]);
developera3511852023-06-14 14:12:59 +080017844 if (enable)
17845 wifi_setRadioAutoBlockAckEnable(index, TRUE);
17846 else
17847 wifi_setRadioAutoBlockAckEnable(index, FALSE);
17848 printf("%s handle wifi_setRadioAutoBlockAckEnable\n", __FUNCTION__);
17849 }
developera39cfb22023-06-20 16:28:17 +080017850 if(strstr(argv[1], "wifi_setRadioTrafficStatsRadioStatisticsEnable")!=NULL)
17851 {
17852 wifi_setRadioTrafficStatsRadioStatisticsEnable(index, TRUE);
17853 printf("Ap SET wifi_setRadioTrafficStatsRadioStatisticsEnable\n");
17854 return 0;
17855 }
17856 if(strstr(argv[1], "wifi_setRadioTrafficStatsMeasure")!=NULL)
17857 {
17858 wifi_radioTrafficStatsMeasure_t input = {30, 200};
17859
17860 wifi_setRadioTrafficStatsMeasure(index, &input);
17861 printf("Ap SET wifi_setRadioTrafficStatsMeasure\n");
17862 return 0;
17863 }
developerfead3972023-05-25 20:15:02 +080017864 if(strstr(argv[1], "wifi_setRadioTransmitPower")!=NULL)
developera3511852023-06-14 14:12:59 +080017865 {
developer2a6abc92023-10-17 17:19:14 +080017866 ULONG TransmitPower;
17867 if(argc <= 3)
17868 {
17869 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17870 exit(-1);
17871 }
17872 TransmitPower = atoi(argv[3]);
developera3511852023-06-14 14:12:59 +080017873 wifi_setRadioTransmitPower(index, TransmitPower);
17874 printf("Ap SET TransmitPower %lu\n", TransmitPower);
17875 return 0;
17876 }
developerfead3972023-05-25 20:15:02 +080017877 if(strstr(argv[1], "wifi_setApManagementFramePowerControl")!=NULL)
developera3511852023-06-14 14:12:59 +080017878 {
developer2a6abc92023-10-17 17:19:14 +080017879 INT TransmitPower;
17880 if(argc <= 3)
17881 {
17882 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17883 exit(-1);
17884 }
17885 TransmitPower = atoi(argv[3]);
developera3511852023-06-14 14:12:59 +080017886 wifi_setApManagementFramePowerControl(index, TransmitPower);
17887 printf("Ap SET Mgnt TransmitPower %d\n", TransmitPower);
17888 return 0;
17889 }
developereef7d562023-10-21 16:04:21 +080017890 if(strstr(argv[1], "wifi_setRadioBW") != NULL)
developera3511852023-06-14 14:12:59 +080017891 {
developer2a6abc92023-10-17 17:19:14 +080017892 if(argc <= 3)
17893 {
17894 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17895 exit(-1);
17896 }
developerfead3972023-05-25 20:15:02 +080017897
developer2a6abc92023-10-17 17:19:14 +080017898 wifi_setRadioOperatingChannelBandwidth(index, argv[3]);
17899 printf("Ap SET bw %s\n", argv[3]);
developera3511852023-06-14 14:12:59 +080017900 return 0;
17901 }
developereef7d562023-10-21 16:04:21 +080017902
17903 if(strstr(argv[1], "wifi_setChannel") != NULL)
17904 {
17905 UINT channel;
17906 if(argc <= 3)
17907 {
17908 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17909 exit(-1);
17910 }
17911 channel = atoi(argv[3]);
17912
17913 wifi_setRadioChannel(index, channel);
17914 printf("Ap SET channel %d\n", channel);
17915 return 0;
17916 }
17917
17918 if(strstr(argv[1], "wifi_setExtCh") != NULL)
17919 {
17920 if(argc <= 3)
17921 {
17922 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17923 exit(-1);
17924 }
17925
17926 wifi_setRadioExtChannel(index, argv[3]);
17927 printf("Ap SET ExtChannel %s\n", argv[3]);
17928 return 0;
17929 }
17930
17931 if(strstr(argv[1], "wifi_setHtCoex") != NULL)
17932 {
17933 UINT ht_coex;
17934 BOOL enable = FALSE;
17935 if(argc <= 3)
17936 {
17937 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17938 exit(-1);
17939 }
17940 ht_coex = atoi(argv[3]);
17941
17942 if (ht_coex == 1)
17943 enable = TRUE;
17944 wifi_setRadioObssCoexistenceEnable(index, enable);
17945 printf("Ap SET ht_coex %d\n", enable);
17946 return 0;
17947 }
17948
17949 if(strstr(argv[1], "wifi_setChMode") != NULL)
17950 {
17951 if(argc <= 3)
17952 {
17953 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17954 exit(-1);
17955 }
17956
17957 wifi_setRadioChannelMode(index, argv[3], FALSE, FALSE, FALSE);
17958 printf("Ap SET ChannelMode %s\n", argv[3]);
17959 return 0;
17960 }
17961
17962 if(strstr(argv[1], "wifi_set80211h") != NULL)
17963 {
17964 UINT en_11h;
17965 BOOL enable = FALSE;
17966 if(argc <= 3)
17967 {
17968 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17969 exit(-1);
17970 }
17971 en_11h = atoi(argv[3]);
17972
17973 if (en_11h == 1)
17974 enable = TRUE;
17975 wifi_setRadioIEEE80211hEnabled(index, enable);
17976 printf("Ap SET 80211h %d\n", enable);
17977 return 0;
17978 }
17979
developerfead3972023-05-25 20:15:02 +080017980 if(strstr(argv[1], "wifi_factoryResetRadio")!=NULL)
developera3511852023-06-14 14:12:59 +080017981 {
17982 wifi_factoryResetRadio(index);
17983 printf("wifi_factoryResetRadio ok!\n");
17984 return 0;
17985 }
developerfead3972023-05-25 20:15:02 +080017986 if(strstr(argv[1], "wifi_getRadioResetCount")!=NULL)
developera3511852023-06-14 14:12:59 +080017987 {
17988 ULONG rst_cnt;
17989 wifi_getRadioResetCount(index, &rst_cnt);
17990 printf("wifi_factoryResetRadio rst_cnt = %lu\n", rst_cnt);
17991 return 0;
17992 }
developer2edaf012023-05-24 14:24:53 +080017993 if (strncmp(argv[1], "wifi_addApAclDevice", strlen(argv[1])) == 0) {
developer49b17232023-05-19 16:35:19 +080017994 if(argc <= 3 )
developera3511852023-06-14 14:12:59 +080017995 {
17996 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
17997 exit(-1);
17998 }
developer49b17232023-05-19 16:35:19 +080017999 wifi_addApAclDevice(index, argv[3]);
18000 return 0;
18001 }
developer2edaf012023-05-24 14:24:53 +080018002 if (strncmp(argv[1], "wifi_getApAclDevices", strlen(argv[1])) == 0) {
18003 wifi_getApAclDevices(index, buf, 1024);
18004 wifi_debug(DEBUG_NOTICE, "Ap acl Devices: %s\n", buf);
developer121a8e72023-05-22 09:19:39 +080018005 return 0;
18006 }
developer2edaf012023-05-24 14:24:53 +080018007 if (strncmp(argv[1], "wifi_delApAclDevice", strlen(argv[1])) == 0) {
18008 if(argc <= 3 )
developera3511852023-06-14 14:12:59 +080018009 {
18010 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18011 exit(-1);
18012 }
developer2edaf012023-05-24 14:24:53 +080018013 wifi_delApAclDevice(index, argv[3]);
18014 return 0;
18015 }
18016 if (strncmp(argv[1], "wifi_delApAclDevices", strlen(argv[1])) == 0) {
18017 wifi_delApAclDevices(index);
18018 return 0;
18019 }
18020 if (strncmp(argv[1], "wifi_getApAclDeviceNum", strlen(argv[1])) == 0) {
developer863a4a62023-06-06 16:55:59 +080018021 UINT acl_num = 0;
developer2edaf012023-05-24 14:24:53 +080018022 wifi_getApAclDeviceNum(index, &acl_num);
18023 wifi_debug(DEBUG_NOTICE, "Ap acl numbers: %d\n", acl_num);
18024 return 0;
18025 }
18026 if (strncmp(argv[1], "wifi_getApDenyAclDevices", strlen(argv[1])) == 0) {
18027 wifi_getApDenyAclDevices(index, buf, 1024);
18028 wifi_debug(DEBUG_NOTICE, "Ap Deny Acl Devices: %s\n", buf);
18029 return 0;
18030 }
18031 if (strncmp(argv[1], "wifi_setApMacAddressControlMode", strlen(argv[1])) == 0) {
18032 int filter_mode = 0;
18033 if(argc <= 3 )
developera3511852023-06-14 14:12:59 +080018034 {
18035 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18036 exit(-1);
18037 }
developer2edaf012023-05-24 14:24:53 +080018038 filter_mode = atoi(argv[3]);
18039 wifi_setApMacAddressControlMode(index,filter_mode);
18040 return 0;
18041 }
developer5cd4c862023-05-26 09:34:42 +080018042 if (strncmp(argv[1], "wifi_getRadioDeclineBARequestEnable", strlen(argv[1])) == 0) {
18043 BOOL output_bool = 0;
18044 wifi_getRadioDeclineBARequestEnable(index, &output_bool);
18045 wifi_debug(DEBUG_NOTICE, "Ap get radio ba decline enable: %d\n", output_bool);
18046 return 0;
18047 }
18048 if (strncmp(argv[1], "wifi_getRadioAutoBlockAckEnable", strlen(argv[1])) == 0) {
18049 BOOL output_bool = 0;
18050 wifi_getRadioAutoBlockAckEnable(index, &output_bool);
18051 wifi_debug(DEBUG_NOTICE, "Ap get radio auto_ba enable: %d\n", output_bool);
18052 return 0;
18053 }
18054
18055 if (strncmp(argv[1], "wifi_getApMacAddressControlMode", strlen(argv[1])) == 0) {
18056 int filter_mode = 0;
18057 wifi_getApMacAddressControlMode(index, &filter_mode);
18058 wifi_debug(DEBUG_NOTICE, "Ap MacAddress Control Mode: %d\n", filter_mode);
18059 return 0;
18060 }
18061 if (strncmp(argv[1], "wifi_setRadioIGMPSnoopingEnable", strlen(argv[1])) == 0) {
18062 int enable = 0;
18063 if(argc <= 3 )
developera3511852023-06-14 14:12:59 +080018064 {
18065 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18066 exit(-1);
18067 }
developer5cd4c862023-05-26 09:34:42 +080018068 enable = (BOOL)atoi(argv[3]);
18069 wifi_setRadioIGMPSnoopingEnable(index, enable);
18070 wifi_debug(DEBUG_NOTICE, "Ap set IGMP Snooping Enable: %d\n", enable);
18071 return 0;
18072 }
developer2a6abc92023-10-17 17:19:14 +080018073 if (strncmp(argv[1], "wifi_setRadioDCSEnable", strlen(argv[1])) == 0) {
developer326d4232023-06-15 16:45:30 +080018074 int enable = 0;
18075 if(argc <= 3 )
18076 {
18077 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18078 exit(-1);
18079 }
18080 enable = (BOOL)atoi(argv[3]);
18081 wifi_setRadioDCSEnable(index, enable);
18082 wifi_debug(DEBUG_NOTICE, "Ap set DCS Enable: %d\n", enable);
18083 return 0;
18084 }
developer2a6abc92023-10-17 17:19:14 +080018085 if (strncmp(argv[1], "wifi_getRadioAutoChannelRefreshPeriod", strlen(argv[1])) == 0) {
developer326d4232023-06-15 16:45:30 +080018086 ULONG period = 0;
developer5cd4c862023-05-26 09:34:42 +080018087
developer326d4232023-06-15 16:45:30 +080018088 wifi_getRadioAutoChannelRefreshPeriod(index, &period);
18089 wifi_debug(DEBUG_NOTICE, "Get RefreshPeriod: %ld\n", period);
18090 return 0;
18091 }
developer2a6abc92023-10-17 17:19:14 +080018092 if (strncmp(argv[1], "wifi_setRadioDfsRefreshPeriod", strlen(argv[1])) == 0) {
developer326d4232023-06-15 16:45:30 +080018093 ULONG period = 0;
developer2a6abc92023-10-17 17:19:14 +080018094 if(argc <= 3)
18095 {
18096 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18097 exit(-1);
18098 }
developer326d4232023-06-15 16:45:30 +080018099 period = (ULONG)atoi(argv[3]);
18100 wifi_setRadioDfsRefreshPeriod(index, period);
18101 wifi_debug(DEBUG_NOTICE, "Set RefreshPeriod: %ld\n", period);
18102 return 0;
18103 }
developer2a6abc92023-10-17 17:19:14 +080018104 if (strncmp(argv[1], "wifi_setRadioDCSChannelPool", strlen(argv[1])) == 0) {
developer326d4232023-06-15 16:45:30 +080018105 char pool[256] = {'\0'};
developer2a6abc92023-10-17 17:19:14 +080018106 if(argc <= 3)
18107 {
18108 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18109 exit(-1);
18110 }
developerc14d83a2023-06-29 20:09:42 +080018111 strncpy(pool, argv[3], strlen(argv[3]));
developer326d4232023-06-15 16:45:30 +080018112 wifi_setRadioDCSChannelPool(index, pool);
18113 wifi_debug(DEBUG_NOTICE, "Set DCSChannelPool: %s\n", pool);
18114 return 0;
18115 }
developer2a6abc92023-10-17 17:19:14 +080018116 if (strncmp(argv[1], "wifi_getRadioDCSChannelPool", strlen(argv[1])) == 0) {
developer326d4232023-06-15 16:45:30 +080018117 char pool[256] = {'\0'};
18118
18119 wifi_getRadioDCSChannelPool(index, pool);
18120 wifi_debug(DEBUG_NOTICE, "Get DCSChannelPool: %s\n", pool);
18121 return 0;
18122 }
developer5cd4c862023-05-26 09:34:42 +080018123 if (strncmp(argv[1], "wifi_getRadioIGMPSnoopingEnable", strlen(argv[1])) == 0) {
18124 BOOL out_status = 0;
18125 wifi_getRadioIGMPSnoopingEnable(index, &out_status);
18126 wifi_debug(DEBUG_NOTICE, "Ap get IGMP Snooping Enable: %d\n", out_status);
18127 return 0;
18128 }
developer121a8e72023-05-22 09:19:39 +080018129
developer95c045d2023-05-24 19:26:28 +080018130 if (strncmp(argv[1], "wifi_setApWmmEnable", strlen(argv[1])) == 0) {
18131 int enable = 0;
18132 if(argc <= 3)
18133 {
18134 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18135 exit(-1);
18136 }
18137 enable = atoi(argv[3]);
18138 wifi_setApWmmEnable(index,enable);
18139 return 0;
18140 }
developerc1aa6532023-06-09 09:37:01 +080018141 if (strncmp(argv[1], "wifi_pushSsidAdvertisementEnable", strlen(argv[1])) == 0) {
18142 int enable = 0;
18143 if(argc <= 3)
18144 {
18145 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18146 exit(-1);
18147 }
18148 enable = atoi(argv[3]);
18149 wifi_pushSsidAdvertisementEnable(index,enable);
18150 return 0;
18151 }
developer56fbedb2023-05-30 16:47:05 +080018152 if (strncmp(argv[1], "wifi_down", strlen(argv[1])) == 0) {
18153 wifi_down();
18154 return 0;
18155 }
developer95c045d2023-05-24 19:26:28 +080018156
developer56fbedb2023-05-30 16:47:05 +080018157 if (strncmp(argv[1], "wifi_getRadioStatus", strlen(argv[1])) == 0) {
18158 BOOL enable = 0;
18159
18160 wifi_getRadioStatus(index, &enable);
18161 wifi_debug(DEBUG_NOTICE, "wifi_getRadioStatus enable: %d\n", (int)enable);
18162 return 0;
18163 }
developer333c1eb2023-05-31 14:59:39 +080018164
developer95c045d2023-05-24 19:26:28 +080018165 if (strncmp(argv[1], "wifi_getApWMMCapability", strlen(argv[1])) == 0) {
18166 BOOL enable = 0;
18167
18168 wifi_getApWMMCapability(index, &enable);
18169 wifi_debug(DEBUG_NOTICE, "wifi_getApWMMCapability enable: %d\n", (int)enable);
18170 return 0;
18171 }
18172
18173 if (strncmp(argv[1], "wifi_getApWmmEnable", strlen(argv[1])) == 0) {
18174 BOOL enable = 0;
18175
18176 wifi_getApWmmEnable(index, &enable);
18177 wifi_debug(DEBUG_NOTICE, "wifi_getApWmmEnable enable: %d\n", (int)enable);
18178 return 0;
18179 }
18180
developer2edaf012023-05-24 14:24:53 +080018181 if (strncmp(argv[1], "wifi_getApMacAddressControlMode", strlen(argv[1])) == 0) {
18182 int filter_mode = 0;
18183 wifi_getApMacAddressControlMode(index, &filter_mode);
18184 wifi_debug(DEBUG_NOTICE, "Ap MacAddress Control Mode: %d\n", filter_mode);
18185 return 0;
18186 }
developer0f10c772023-05-16 21:43:39 +080018187 if(strstr(argv[1], "wifi_getRadioMode")!=NULL)
developera3511852023-06-14 14:12:59 +080018188 {
developer863a4a62023-06-06 16:55:59 +080018189 UINT mode = 0;
developer0f10c772023-05-16 21:43:39 +080018190
developera3511852023-06-14 14:12:59 +080018191 wifi_getRadioMode(index, buf, &mode);
18192 printf("Ap Radio mode is %s , mode = 0x%x\n", buf, mode);
18193 return 0;
18194 }
18195 if(strstr(argv[1], "wifi_getRadioAutoChannelEnable")!=NULL)
18196 {
18197 BOOL b = FALSE;
18198 BOOL *output_bool = &b;
18199 wifi_getRadioAutoChannelEnable(index,output_bool);
18200 printf("Channel enabled = %d \n",b);
18201 return 0;
18202 }
18203 if(strstr(argv[1], "wifi_getApWpaEncryptionMode")!=NULL)
18204 {
18205 wifi_getApWpaEncryptionMode(index,buf);
18206 printf("encryption enabled = %s\n",buf);
18207 return 0;
18208 }
18209 if(strstr(argv[1], "wifi_getApSsidAdvertisementEnable")!=NULL)
18210 {
18211 BOOL b = FALSE;
18212 BOOL *output_bool = &b;
18213 wifi_getApSsidAdvertisementEnable(index,output_bool);
18214 printf("advertisment enabled = %d\n",b);
18215 return 0;
18216 }
18217 if(strstr(argv[1],"wifi_getApAssociatedDeviceTidStatsResult")!=NULL)
18218 {
18219 if(argc <= 3 )
18220 {
18221 printf("Insufficient arguments \n");
18222 exit(-1);
18223 }
developer72fb0bb2023-01-11 09:46:29 +080018224
developera3511852023-06-14 14:12:59 +080018225 char sta[20] = {'\0'};
18226 ULLONG handle= 0;
developerc14d83a2023-06-29 20:09:42 +080018227 strncpy(sta,argv[3], strlen(argv[3]));
developera3511852023-06-14 14:12:59 +080018228 mac_address_t st;
developer72fb0bb2023-01-11 09:46:29 +080018229 mac_addr_aton(st,sta);
18230
developera3511852023-06-14 14:12:59 +080018231 wifi_associated_dev_tid_stats_t tid_stats;
18232 wifi_getApAssociatedDeviceTidStatsResult(index,&st,&tid_stats,&handle);
18233 for(int tid_index=0; tid_index<PS_MAX_TID; tid_index++) //print tid stats
18234 printf(" tid=%d \t ac=%d \t num_msdus=%lld \n" ,tid_stats.tid_array[tid_index].tid,tid_stats.tid_array[tid_index].ac,tid_stats.tid_array[tid_index].num_msdus);
18235 }
developer72fb0bb2023-01-11 09:46:29 +080018236
developera3511852023-06-14 14:12:59 +080018237 if(strstr(argv[1], "getApEnable")!=NULL) {
18238 BOOL enable;
18239 ret=wifi_getApEnable(index, &enable);
18240 printf("%s %d: %d, returns %d\n", argv[1], index, enable, ret);
18241 }
18242 else if(strstr(argv[1], "setApEnable")!=NULL) {
developer2a6abc92023-10-17 17:19:14 +080018243 BOOL enable;
18244 if(argc <= 3)
18245 {
18246 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18247 exit(-1);
18248 }
18249 enable = atoi(argv[3]);
developera3511852023-06-14 14:12:59 +080018250 ret=wifi_setApEnable(index, enable);
18251 printf("%s %d: %d, returns %d\n", argv[1], index, enable, ret);
18252 }
18253 else if(strstr(argv[1], "getApStatus")!=NULL) {
18254 char status[64];
18255 ret=wifi_getApStatus(index, status);
18256 printf("%s %d: %s, returns %d\n", argv[1], index, status, ret);
18257 }
18258 else if(strstr(argv[1], "wifi_getSSIDNameStatus")!=NULL)
18259 {
18260 wifi_getSSIDNameStatus(index,buf);
18261 printf("%s %d: active ssid : %s\n",argv[1], index,buf);
18262 return 0;
18263 } else if(strstr(argv[1], "wifi_resetApVlanCfg")!=NULL) {
18264 wifi_resetApVlanCfg(index);
18265 printf("%s %d: wifi_resetApVlanCfg : %s\n",argv[1], index,buf);
18266 return 0;
18267 }
18268 else if(strstr(argv[1], "getSSIDTrafficStats2")!=NULL) {
18269 wifi_ssidTrafficStats2_t stats={0};
18270 ret=wifi_getSSIDTrafficStats2(index, &stats); //Tr181
18271 printf("%s %d: returns %d\n", argv[1], index, ret);
18272 printf(" ssid_BytesSent =%lu\n", stats.ssid_BytesSent);
18273 printf(" ssid_BytesReceived =%lu\n", stats.ssid_BytesReceived);
18274 printf(" ssid_PacketsSent =%lu\n", stats.ssid_PacketsSent);
18275 printf(" ssid_PacketsReceived =%lu\n", stats.ssid_PacketsReceived);
18276 printf(" ssid_RetransCount =%lu\n", stats.ssid_RetransCount);
18277 printf(" ssid_FailedRetransCount =%lu\n", stats.ssid_FailedRetransCount);
18278 printf(" ssid_RetryCount =%lu\n", stats.ssid_RetryCount);
18279 printf(" ssid_MultipleRetryCount =%lu\n", stats.ssid_MultipleRetryCount);
18280 printf(" ssid_ACKFailureCount =%lu\n", stats.ssid_ACKFailureCount);
18281 printf(" ssid_AggregatedPacketCount =%lu\n", stats.ssid_AggregatedPacketCount);
18282 printf(" ssid_ErrorsSent =%lu\n", stats.ssid_ErrorsSent);
18283 printf(" ssid_ErrorsReceived =%lu\n", stats.ssid_ErrorsReceived);
18284 printf(" ssid_UnicastPacketsSent =%lu\n", stats.ssid_UnicastPacketsSent);
18285 printf(" ssid_UnicastPacketsReceived =%lu\n", stats.ssid_UnicastPacketsReceived);
18286 printf(" ssid_DiscardedPacketsSent =%lu\n", stats.ssid_DiscardedPacketsSent);
18287 printf(" ssid_DiscardedPacketsReceived =%lu\n", stats.ssid_DiscardedPacketsReceived);
18288 printf(" ssid_MulticastPacketsSent =%lu\n", stats.ssid_MulticastPacketsSent);
18289 printf(" ssid_MulticastPacketsReceived =%lu\n", stats.ssid_MulticastPacketsReceived);
18290 printf(" ssid_BroadcastPacketsSent =%lu\n", stats.ssid_BroadcastPacketsSent);
18291 printf(" ssid_BroadcastPacketsRecevied =%lu\n", stats.ssid_BroadcastPacketsRecevied);
18292 printf(" ssid_UnknownPacketsReceived =%lu\n", stats.ssid_UnknownPacketsReceived);
18293 }
18294 else if(strstr(argv[1], "getNeighboringWiFiDiagnosticResult2")!=NULL) {
18295 wifi_neighbor_ap2_t *neighbor_ap_array=NULL, *pt=NULL;
18296 UINT array_size=0;
18297 UINT i=0;
18298 ret=wifi_getNeighboringWiFiDiagnosticResult2(index, &neighbor_ap_array, &array_size);
18299 printf("%s %d: array_size=%d, returns %d\n", argv[1], index, array_size, ret);
18300 for(i=0, pt=neighbor_ap_array; i<array_size; i++, pt++) {
18301 printf(" neighbor %d:\n", i);
18302 printf(" ap_SSID =%s\n", pt->ap_SSID);
18303 printf(" ap_BSSID =%s\n", pt->ap_BSSID);
18304 printf(" ap_Mode =%s\n", pt->ap_Mode);
18305 printf(" ap_Channel =%d\n", pt->ap_Channel);
18306 printf(" ap_SignalStrength =%d\n", pt->ap_SignalStrength);
18307 printf(" ap_SecurityModeEnabled =%s\n", pt->ap_SecurityModeEnabled);
18308 printf(" ap_EncryptionMode =%s\n", pt->ap_EncryptionMode);
18309 printf(" ap_SupportedStandards =%s\n", pt->ap_SupportedStandards);
18310 printf(" ap_OperatingStandards =%s\n", pt->ap_OperatingStandards);
18311 printf(" ap_OperatingChannelBandwidth =%s\n", pt->ap_OperatingChannelBandwidth);
18312 printf(" ap_SecurityModeEnabled =%s\n", pt->ap_SecurityModeEnabled);
18313 printf(" ap_BeaconPeriod =%d\n", pt->ap_BeaconPeriod);
18314 printf(" ap_Noise =%d\n", pt->ap_Noise);
18315 printf(" ap_BasicDataTransferRates =%s\n", pt->ap_BasicDataTransferRates);
18316 printf(" ap_SupportedDataTransferRates =%s\n", pt->ap_SupportedDataTransferRates);
18317 printf(" ap_DTIMPeriod =%d\n", pt->ap_DTIMPeriod);
18318 printf(" ap_ChannelUtilization =%d\n", pt->ap_ChannelUtilization);
18319 }
18320 if(neighbor_ap_array)
18321 free(neighbor_ap_array); //make sure to free the list
18322 }
18323 else if(strstr(argv[1], "getApAssociatedDeviceDiagnosticResult")!=NULL) {
18324 wifi_associated_dev_t *associated_dev_array=NULL, *pt=NULL;
18325 UINT array_size=0;
18326 UINT i=0;
18327 ret=wifi_getApAssociatedDeviceDiagnosticResult(index, &associated_dev_array, &array_size);
18328 printf("%s %d: array_size=%d, returns %d\n", argv[1], index, array_size, ret);
18329 for(i=0, pt=associated_dev_array; i<array_size; i++, pt++) {
18330 printf(" associated_dev %d:\n", i);
18331 printf(" cli_OperatingStandard =%s\n", pt->cli_OperatingStandard);
18332 printf(" cli_OperatingChannelBandwidth =%s\n", pt->cli_OperatingChannelBandwidth);
18333 printf(" cli_SNR =%d\n", pt->cli_SNR);
18334 printf(" cli_InterferenceSources =%s\n", pt->cli_InterferenceSources);
18335 printf(" cli_DataFramesSentAck =%lu\n", pt->cli_DataFramesSentAck);
18336 printf(" cli_DataFramesSentNoAck =%lu\n", pt->cli_DataFramesSentNoAck);
18337 printf(" cli_BytesSent =%lu\n", pt->cli_BytesSent);
18338 printf(" cli_BytesReceived =%lu\n", pt->cli_BytesReceived);
18339 printf(" cli_RSSI =%d\n", pt->cli_RSSI);
18340 printf(" cli_MinRSSI =%d\n", pt->cli_MinRSSI);
18341 printf(" cli_MaxRSSI =%d\n", pt->cli_MaxRSSI);
18342 printf(" cli_Disassociations =%d\n", pt->cli_Disassociations);
18343 printf(" cli_AuthenticationFailures =%d\n", pt->cli_AuthenticationFailures);
18344 }
18345 if(associated_dev_array)
18346 free(associated_dev_array); //make sure to free the list
18347 }
developer72fb0bb2023-01-11 09:46:29 +080018348
developera3511852023-06-14 14:12:59 +080018349 if(strstr(argv[1],"wifi_getRadioChannelStats")!=NULL)
18350 {
developer72fb0bb2023-01-11 09:46:29 +080018351#define MAX_ARRAY_SIZE 64
developera3511852023-06-14 14:12:59 +080018352 int i, array_size;
18353 char *p, *ch_str;
18354 wifi_channelStats_t input_output_channelStats_array[MAX_ARRAY_SIZE];
developer72fb0bb2023-01-11 09:46:29 +080018355
developera3511852023-06-14 14:12:59 +080018356 if(argc != 5)
18357 {
18358 printf("Insufficient arguments, Usage: wifihal wifi_getRadioChannelStats <AP-Index> <Array-Size> <Comma-seperated-channel-numbers>\n");
18359 exit(-1);
18360 }
18361 memset(input_output_channelStats_array, 0, sizeof(input_output_channelStats_array));
developer72fb0bb2023-01-11 09:46:29 +080018362
developera3511852023-06-14 14:12:59 +080018363 for (i=0, array_size=atoi(argv[3]), ch_str=argv[4]; i<array_size; i++, ch_str=p)
18364 {
18365 strtok_r(ch_str, ",", &p);
18366 input_output_channelStats_array[i].ch_number = atoi(ch_str);
18367 }
18368 wifi_getRadioChannelStats(atoi(argv[2]), input_output_channelStats_array, array_size);
18369 if(!array_size)
18370 array_size=1;//Need to print current channel statistics
18371 for(i=0; i<array_size; i++)
18372 printf("chan num = %d \t, noise =%d\t ch_utilization_busy_rx = %lld \t,\
18373 ch_utilization_busy_tx = %lld \t,ch_utilization_busy = %lld \t,\
18374 ch_utilization_busy_ext = %lld \t, ch_utilization_total = %lld \t \n",\
18375 input_output_channelStats_array[i].ch_number,\
18376 input_output_channelStats_array[i].ch_noise,\
18377 input_output_channelStats_array[i].ch_utilization_busy_rx,\
18378 input_output_channelStats_array[i].ch_utilization_busy_tx,\
18379 input_output_channelStats_array[i].ch_utilization_busy,\
18380 input_output_channelStats_array[i].ch_utilization_busy_ext,\
18381 input_output_channelStats_array[i].ch_utilization_total);
18382 }
developer72fb0bb2023-01-11 09:46:29 +080018383
developera3511852023-06-14 14:12:59 +080018384 if(strstr(argv[1],"wifi_getAssociatedDeviceDetail")!=NULL)
18385 {
18386 if(argc <= 3 )
18387 {
18388 printf("Insufficient arguments \n");
18389 exit(-1);
18390 }
18391 char mac_addr[20] = {'\0'};
18392 wifi_device_t output_struct;
18393 int dev_index = atoi(argv[3]);
developer72fb0bb2023-01-11 09:46:29 +080018394
developera3511852023-06-14 14:12:59 +080018395 wifi_getAssociatedDeviceDetail(index,dev_index,&output_struct);
18396 mac_addr_ntoa(mac_addr,output_struct.wifi_devMacAddress);
18397 printf("wifi_devMacAddress=%s \t wifi_devAssociatedDeviceAuthentiationState=%d \t, wifi_devSignalStrength=%d \t,wifi_devTxRate=%d \t, wifi_devRxRate =%d \t\n ", mac_addr,output_struct.wifi_devAssociatedDeviceAuthentiationState,output_struct.wifi_devSignalStrength,output_struct.wifi_devTxRate,output_struct.wifi_devRxRate);
18398 }
developer72fb0bb2023-01-11 09:46:29 +080018399
developera3511852023-06-14 14:12:59 +080018400 if(strstr(argv[1],"wifi_setNeighborReports")!=NULL)
18401 {
18402 if (argc <= 3)
18403 {
18404 printf("Insufficient arguments\n");
18405 exit(-1);
18406 }
18407 char args[256];
18408 wifi_NeighborReport_t *neighborReports;
developer72fb0bb2023-01-11 09:46:29 +080018409
developera3511852023-06-14 14:12:59 +080018410 neighborReports = calloc(argc - 2, sizeof(neighborReports));
18411 if (!neighborReports)
18412 {
18413 printf("Failed to allocate memory");
18414 exit(-1);
18415 }
developer72fb0bb2023-01-11 09:46:29 +080018416
developera3511852023-06-14 14:12:59 +080018417 for (int i = 3; i < argc; ++i)
18418 {
18419 char *val;
18420 int j = 0;
developerc14d83a2023-06-29 20:09:42 +080018421 unsigned long tmp;
developera3511852023-06-14 14:12:59 +080018422 memset(args, 0, sizeof(args));
18423 strncpy(args, argv[i], sizeof(args));
18424 val = strtok(args, ";");
18425 while (val != NULL)
18426 {
18427 if (j == 0)
18428 {
18429 mac_addr_aton(neighborReports[i - 3].bssid, val);
18430 } else if (j == 1)
18431 {
developerc14d83a2023-06-29 20:09:42 +080018432 if (hal_strtoul(val, 16, &tmp) < 0) {
18433 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080018434 }
18435 neighborReports[i - 3].info = tmp;
developera3511852023-06-14 14:12:59 +080018436 } else if (j == 2)
18437 {
developerc14d83a2023-06-29 20:09:42 +080018438 if (hal_strtoul(val, 16, &tmp) < 0) {
18439 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080018440 }
18441 neighborReports[i - 3].opClass = tmp;
developer5b23cd02023-07-19 20:26:03 +080018442
developera3511852023-06-14 14:12:59 +080018443 } else if (j == 3)
18444 {
developerc14d83a2023-06-29 20:09:42 +080018445 if (hal_strtoul(val, 16, &tmp) < 0) {
18446 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080018447 }
18448 neighborReports[i - 3].channel = tmp;
developera3511852023-06-14 14:12:59 +080018449 } else if (j == 4)
18450 {
developerc14d83a2023-06-29 20:09:42 +080018451 if (hal_strtoul(val, 16, &tmp) < 0) {
18452 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080018453 }
18454 neighborReports[i - 3].phyTable = tmp;
developera3511852023-06-14 14:12:59 +080018455 } else {
18456 printf("Insufficient arguments]n\n");
18457 exit(-1);
18458 }
18459 val = strtok(NULL, ";");
18460 j++;
18461 }
18462 }
developer72fb0bb2023-01-11 09:46:29 +080018463
developera3511852023-06-14 14:12:59 +080018464 INT ret = wifi_setNeighborReports(index, argc - 3, neighborReports);
18465 if (ret != RETURN_OK)
18466 {
18467 printf("wifi_setNeighborReports ret = %d", ret);
18468 exit(-1);
18469 }
18470 }
18471 if(strstr(argv[1],"wifi_getRadioIfName")!=NULL)
18472 {
18473 if((ret=wifi_getRadioIfName(index, buf))==RETURN_OK)
18474 printf("%s.\n", buf);
18475 else
18476 printf("Error returned\n");
18477 }
18478 if(strstr(argv[1],"wifi_getApSecurityModesSupported")!=NULL)
18479 {
18480 if((ret=wifi_getApSecurityModesSupported(index, buf))==RETURN_OK)
18481 printf("%s.\n", buf);
18482 else
18483 printf("Error returned\n");
18484 }
18485 if(strstr(argv[1],"wifi_getRadioOperatingChannelBandwidth")!=NULL)
18486 {
18487 if (argc <= 2)
18488 {
18489 printf("Insufficient arguments\n");
18490 exit(-1);
18491 }
18492 char buf[64]= {'\0'};
18493 wifi_getRadioOperatingChannelBandwidth(index,buf);
18494 printf("Current bandwidth is %s \n",buf);
18495 return 0;
18496 }
18497 if(strstr(argv[1],"pushRadioChannel2")!=NULL)
18498 {
18499 if (argc <= 5)
18500 {
18501 printf("Insufficient arguments\n");
18502 exit(-1);
18503 }
18504 UINT channel = atoi(argv[3]);
18505 UINT width = atoi(argv[4]);
18506 UINT beacon = atoi(argv[5]);
18507 INT ret = wifi_pushRadioChannel2(index,channel,width,beacon);
18508 printf("Result = %d", ret);
18509 }
developer408cde72023-10-19 13:44:02 +080018510 if(strstr(argv[1],"wifi_getRadioChannel")!=NULL)
18511 {
18512 ULONG channel = 0;
18513 wifi_getRadioChannel(index, &channel);
18514 printf("channel is %ld \n",channel);
18515 return 0;
18516 }
developercc5cbfb2023-06-13 18:29:52 +080018517 if(strstr(argv[1],"wifi_getApBridgeInfo")!=NULL)
developera3511852023-06-14 14:12:59 +080018518 {
developercc5cbfb2023-06-13 18:29:52 +080018519 char br_name[64], ip[64], subset[64] = {0};
18520 wifi_getApBridgeInfo(0, br_name, ip, subset);
18521 printf("wifi_getApBridgeInfo br_name = %s, ip = %s, subset = %s\n", br_name, ip, subset);
developera3511852023-06-14 14:12:59 +080018522 }
developercc5cbfb2023-06-13 18:29:52 +080018523 if(strstr(argv[1],"wifi_enableGreylistAccessControl")!=NULL)
developera3511852023-06-14 14:12:59 +080018524 {
developer2a6abc92023-10-17 17:19:14 +080018525 int enable;
18526 if(argc <= 3)
18527 {
18528 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18529 exit(-1);
18530 }
18531 enable = atoi(argv[3]);
developercc5cbfb2023-06-13 18:29:52 +080018532 wifi_enableGreylistAccessControl(enable == 0 ? FALSE : TRUE);
18533 printf("wifi_enableGreylistAccessControl enable=%d\n", enable);
developera3511852023-06-14 14:12:59 +080018534 }
developercc5cbfb2023-06-13 18:29:52 +080018535 if(strstr(argv[1],"wifi_setApBridgeInfo")!=NULL)
developera3511852023-06-14 14:12:59 +080018536 {
developer2a6abc92023-10-17 17:19:14 +080018537 if(argc <= 5)
18538 {
18539 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18540 exit(-1);
18541 }
developercc5cbfb2023-06-13 18:29:52 +080018542 wifi_setApBridgeInfo(0, argv[3], argv[4], argv[5]);
18543 printf("wifi_setApBridgeInfo br_name = %s, ip = %s, subset = %s\n", argv[3], argv[4], argv[5]);
developera3511852023-06-14 14:12:59 +080018544 }
developer72fb0bb2023-01-11 09:46:29 +080018545
developer6e578302023-06-21 10:11:16 +080018546 if(strstr(argv[1], "wifi_getATMCapable")!=NULL)
18547 {
18548 BOOL b = FALSE;
18549 BOOL *output_bool = &b;
18550 wifi_getATMCapable(output_bool);
18551 printf("ATM capable = %d \n",b);
18552 return 0;
18553 }
18554 if (strncmp(argv[1], "wifi_setATMEnable", strlen(argv[1])) == 0) {
18555 int enable = 0;
18556 if(argc <= 3)
18557 {
18558 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18559 exit(-1);
18560 }
18561 enable = atoi(argv[3]);
18562 wifi_setATMEnable(enable);
18563 return 0;
18564 }
18565 if (strncmp(argv[1], "wifi_getATMEnable", strlen(argv[1])) == 0) {
18566 BOOL b = FALSE;
18567 BOOL *output_bool = &b;
18568 wifi_getATMEnable(output_bool);
18569 printf("ATM enable = %d \n", b);
18570 return 0;
18571 }
18572 if (strncmp(argv[1], "wifi_setApATMAirTimePercent", strlen(argv[1])) == 0) {
18573 unsigned int percent = 0;
18574 if(argc <= 3)
18575 {
18576 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18577 exit(-1);
18578 }
18579 percent = atoi(argv[3]);
18580 wifi_setApATMAirTimePercent(index, percent);
18581 return 0;
18582 }
18583 if (strncmp(argv[1], "wifi_getApATMAirTimePercent", strlen(argv[1])) == 0) {
18584 unsigned int percent = 0;
18585 unsigned int *output = &percent;
18586
18587 wifi_getApATMAirTimePercent(index, output);
18588 printf("ATM percent = %d \n", percent);
18589 return 0;
18590 }
developer82533be2023-06-28 17:21:01 +080018591 if (strstr(argv[1],"setGF")!=NULL)
18592 {
developer2a6abc92023-10-17 17:19:14 +080018593 BOOL enable;
18594 if(argc <= 3)
18595 {
18596 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18597 exit(-1);
18598 }
18599 enable = atoi(argv[3]);
developer82533be2023-06-28 17:21:01 +080018600 if((ret=wifi_setRadio11nGreenfieldEnable(index, enable))==RETURN_OK)
18601 printf("wifi_setRadio11nGreenfieldEnable success\n");
18602 else
18603 printf("wifi_setRadio11nGreenfieldEnable Error\n");
18604 }
18605 if (strstr(argv[1],"setVID")!=NULL)
18606 {
developer2a6abc92023-10-17 17:19:14 +080018607 INT vid;
18608 if(argc <= 3)
18609 {
18610 wifi_debug(DEBUG_ERROR, "Insufficient arguments \n");
18611 exit(-1);
18612 }
18613 vid = atoi(argv[3]);
developer82533be2023-06-28 17:21:01 +080018614 if((ret=wifi_setApVlanID(index, vid))==RETURN_OK)
18615 printf("wifi_setApVlanID success.\n");
18616 else
18617 printf("wifi_setApVlanID Error\n");
developerd14dff12023-06-28 22:47:44 +080018618 }
18619 if (strncmp(argv[1], "wifi_getApATMSta", strlen(argv[1])) == 0) {
18620 UCHAR outbuf[256]={0};
18621
18622 wifi_getApATMSta(index, outbuf, sizeof(outbuf));
18623 printf("sta air time percent is %s \n", outbuf);
18624 return 0;
18625 }
developera3511852023-06-14 14:12:59 +080018626 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
18627 return 0;
developer72fb0bb2023-01-11 09:46:29 +080018628}
18629
18630#endif
18631
18632#ifdef WIFI_HAL_VERSION_3
18633
developer32f2a182023-06-27 19:50:41 +080018634INT BitMapToTransmitRates(UINT bitMap, char *BasicRate, unsigned long size)
developer72fb0bb2023-01-11 09:46:29 +080018635{
developera3511852023-06-14 14:12:59 +080018636 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer32f2a182023-06-27 19:50:41 +080018637 if (bitMap & WIFI_BITRATE_1MBPS) {
18638 if ((size - strlen(BasicRate)) <= 2)
18639 return RETURN_ERR;
18640 strncat(BasicRate, "1,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18641 }
18642 if (bitMap & WIFI_BITRATE_2MBPS) {
18643 if ((size - strlen(BasicRate)) <= 2)
18644 return RETURN_ERR;
18645 strncat(BasicRate, "2,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18646 }
18647 if (bitMap & WIFI_BITRATE_5_5MBPS) {
18648 if ((size - strlen(BasicRate)) <= 4)
18649 return RETURN_ERR;
18650 strncat(BasicRate, "5.5,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18651 }
18652 if (bitMap & WIFI_BITRATE_6MBPS) {
18653 if ((size - strlen(BasicRate)) <= 2)
18654 return RETURN_ERR;
18655 strncat(BasicRate, "6,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18656 }
18657 if (bitMap & WIFI_BITRATE_9MBPS) {
18658 if ((size - strlen(BasicRate)) <= 2)
18659 return RETURN_ERR;
18660 strncat(BasicRate, "9,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18661 }
18662 if (bitMap & WIFI_BITRATE_11MBPS) {
18663 if ((size - strlen(BasicRate)) <= 3)
18664 return RETURN_ERR;
18665 strncat(BasicRate, "11,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18666 }
18667 if (bitMap & WIFI_BITRATE_12MBPS) {
18668 if ((size - strlen(BasicRate)) <= 3)
18669 return RETURN_ERR;
18670 strncat(BasicRate, "12,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18671 }
18672 if (bitMap & WIFI_BITRATE_18MBPS) {
18673 if ((size - strlen(BasicRate)) <= 3)
18674 return RETURN_ERR;
18675 strncat(BasicRate, "18,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18676 }
18677 if (bitMap & WIFI_BITRATE_24MBPS) {
18678 if ((size - strlen(BasicRate)) <= 3)
18679 return RETURN_ERR;
18680 strncat(BasicRate, "24,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18681 }
18682 if (bitMap & WIFI_BITRATE_36MBPS) {
18683 if ((size - strlen(BasicRate)) <= 3)
18684 return RETURN_ERR;
18685 strncat(BasicRate, "36,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18686 }
18687 if (bitMap & WIFI_BITRATE_48MBPS) {
18688 if ((size - strlen(BasicRate)) <= 3)
18689 return RETURN_ERR;
18690 strncat(BasicRate, "48,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18691 }
18692 if (bitMap & WIFI_BITRATE_54MBPS) {
18693 if ((size - strlen(BasicRate)) <= 3)
18694 return RETURN_ERR;
18695 strncat(BasicRate, "54,", sizeof(BasicRate) - strlen(BasicRate) - 1);
18696 }
developera3511852023-06-14 14:12:59 +080018697 if (strlen(BasicRate) != 0) // remove last comma
18698 BasicRate[strlen(BasicRate) - 1] = '\0';
18699 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
18700 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080018701}
18702
18703INT TransmitRatesToBitMap (char *BasicRatesList, UINT *basicRateBitMap)
18704{
developera3511852023-06-14 14:12:59 +080018705 UINT BitMap = 0;
18706 char *rate;
developer72fb0bb2023-01-11 09:46:29 +080018707
developera3511852023-06-14 14:12:59 +080018708 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
18709 rate = strtok(BasicRatesList, ",");
18710 while(rate != NULL)
18711 {
18712 if (strcmp(rate, "1") == 0)
18713 BitMap |= WIFI_BITRATE_1MBPS;
18714 else if (strcmp(rate, "2") == 0)
18715 BitMap |= WIFI_BITRATE_2MBPS;
18716 else if (strcmp(rate, "5.5") == 0)
18717 BitMap |= WIFI_BITRATE_5_5MBPS;
18718 else if (strcmp(rate, "6") == 0)
18719 BitMap |= WIFI_BITRATE_6MBPS;
18720 else if (strcmp(rate, "9") == 0)
18721 BitMap |= WIFI_BITRATE_9MBPS;
18722 else if (strcmp(rate, "11") == 0)
18723 BitMap |= WIFI_BITRATE_11MBPS;
18724 else if (strcmp(rate, "12") == 0)
18725 BitMap |= WIFI_BITRATE_12MBPS;
18726 else if (strcmp(rate, "18") == 0)
18727 BitMap |= WIFI_BITRATE_18MBPS;
18728 else if (strcmp(rate, "24") == 0)
18729 BitMap |= WIFI_BITRATE_24MBPS;
18730 else if (strcmp(rate, "36") == 0)
18731 BitMap |= WIFI_BITRATE_36MBPS;
18732 else if (strcmp(rate, "48") == 0)
18733 BitMap |= WIFI_BITRATE_48MBPS;
18734 else if (strcmp(rate, "54") == 0)
18735 BitMap |= WIFI_BITRATE_54MBPS;
18736 rate = strtok(NULL, ",");
18737 }
18738 *basicRateBitMap = BitMap;
18739 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
18740 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080018741}
18742
18743// This API is used to configured all radio operation parameter in a single set. it includes channel number, channelWidth, mode and auto chammel configuration.
18744INT wifi_setRadioOperatingParameters(wifi_radio_index_t index, wifi_radio_operationParam_t *operationParam)
18745{
developera3511852023-06-14 14:12:59 +080018746 char buf[128] = {0};
18747 int bandwidth = 20;
18748 int set_mode = 0;
developer56fbedb2023-05-30 16:47:05 +080018749 BOOL drv_dat_change = 0, hapd_conf_change = 0;
developera3511852023-06-14 14:12:59 +080018750 wifi_radio_operationParam_t current_param;
developer82160f02023-08-19 15:30:44 +080018751 int ApIndex;
developer72fb0bb2023-01-11 09:46:29 +080018752
developera3511852023-06-14 14:12:59 +080018753 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080018754
developera3511852023-06-14 14:12:59 +080018755 multiple_set = TRUE;
18756 if (wifi_getRadioOperatingParameters(index, &current_param) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018757 wifi_debug(DEBUG_ERROR, "wifi_getRadioOperatingParameters return error.\n");
developera3511852023-06-14 14:12:59 +080018758 return RETURN_ERR;
18759 }
18760 if (current_param.autoChannelEnabled != operationParam->autoChannelEnabled) {
18761 if (wifi_setRadioAutoChannelEnable(index, operationParam->autoChannelEnabled) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018762 wifi_debug(DEBUG_ERROR, "wifi_setRadioAutoChannelEnable return error.\n");
developera3511852023-06-14 14:12:59 +080018763 return RETURN_ERR;
18764 }
18765 drv_dat_change = TRUE;
18766 }
18767 if (current_param.channelWidth != operationParam->channelWidth ||
18768 current_param.channel != operationParam->channel ||
18769 current_param.autoChannelEnabled != operationParam->autoChannelEnabled) {
18770 if (operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_20MHZ)
18771 bandwidth = 20;
18772 else if (operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_40MHZ)
18773 bandwidth = 40;
18774 else if (operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_80MHZ)
18775 bandwidth = 80;
18776 else if (operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_160MHZ || operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_80_80MHZ)
18777 bandwidth = 160;
developer72fb0bb2023-01-11 09:46:29 +080018778
developera3511852023-06-14 14:12:59 +080018779 if (operationParam->autoChannelEnabled) {
18780 if (wifi_pushRadioChannel2(index, 0, bandwidth, operationParam->csa_beacon_count) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018781 wifi_debug(DEBUG_ERROR, "wifi_pushRadioChannel2 return error.\n");
developera3511852023-06-14 14:12:59 +080018782 return RETURN_ERR;
18783 }
18784 } else {
18785 if (wifi_pushRadioChannel2(index, operationParam->channel, bandwidth, operationParam->csa_beacon_count) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018786 wifi_debug(DEBUG_ERROR, "wifi_pushRadioChannel2 return error.\n");
developera3511852023-06-14 14:12:59 +080018787 return RETURN_ERR;
18788 }
18789 }
developer56fbedb2023-05-30 16:47:05 +080018790 drv_dat_change = TRUE;
developera3511852023-06-14 14:12:59 +080018791 }
18792 if (current_param.variant != operationParam->variant) {
18793 // Two different definition bit map, so need to check every bit.
18794 if (operationParam->variant & WIFI_80211_VARIANT_A)
18795 set_mode |= WIFI_MODE_A;
18796 if (operationParam->variant & WIFI_80211_VARIANT_B)
18797 set_mode |= WIFI_MODE_B;
18798 if (operationParam->variant & WIFI_80211_VARIANT_G)
18799 set_mode |= WIFI_MODE_G;
18800 if (operationParam->variant & WIFI_80211_VARIANT_N)
18801 set_mode |= WIFI_MODE_N;
18802 if (operationParam->variant & WIFI_80211_VARIANT_AC)
18803 set_mode |= WIFI_MODE_AC;
18804 if (operationParam->variant & WIFI_80211_VARIANT_AX)
18805 set_mode |= WIFI_MODE_AX;
developer408cde72023-10-19 13:44:02 +080018806 if (operationParam->variant & WIFI_80211_VARIANT_BE)
18807 set_mode |= WIFI_MODE_BE;
developera3511852023-06-14 14:12:59 +080018808 // Second parameter is to set channel band width, it is done by wifi_pushRadioChannel2 if changed.
18809 memset(buf, 0, sizeof(buf));
18810 drv_dat_change = TRUE;
18811 if (wifi_setRadioMode_by_dat(index, set_mode) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018812 wifi_debug(DEBUG_ERROR, "wifi_setRadioMode return error.\n");
developera3511852023-06-14 14:12:59 +080018813 return RETURN_ERR;
18814 }
18815 }
18816 if (current_param.dtimPeriod != operationParam->dtimPeriod) {
developer56fbedb2023-05-30 16:47:05 +080018817 hapd_conf_change = TRUE;
developera3511852023-06-14 14:12:59 +080018818 if (wifi_setApDTIMInterval(index, operationParam->dtimPeriod) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018819 wifi_debug(DEBUG_ERROR, "wifi_setApDTIMInterval return error.\n");
developera3511852023-06-14 14:12:59 +080018820 return RETURN_ERR;
18821 }
18822 }
18823 if (current_param.beaconInterval != operationParam->beaconInterval) {
developer56fbedb2023-05-30 16:47:05 +080018824 hapd_conf_change = TRUE;
developera3511852023-06-14 14:12:59 +080018825 if (wifi_setRadioBeaconPeriod(index, operationParam->beaconInterval) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018826 wifi_debug(DEBUG_ERROR, "wifi_setRadioBeaconPeriod return error.\n");
developera3511852023-06-14 14:12:59 +080018827 return RETURN_ERR;
18828 }
18829 }
18830 if (current_param.operationalDataTransmitRates != operationParam->operationalDataTransmitRates) {
developer56fbedb2023-05-30 16:47:05 +080018831 hapd_conf_change = TRUE;
developer32f2a182023-06-27 19:50:41 +080018832 BitMapToTransmitRates(operationParam->operationalDataTransmitRates, buf, sizeof(buf));
developera3511852023-06-14 14:12:59 +080018833 if (wifi_setRadioBasicDataTransmitRates(index, buf) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018834 wifi_debug(DEBUG_ERROR, "wifi_setRadioBasicDataTransmitRates return error.\n");
developera3511852023-06-14 14:12:59 +080018835 return RETURN_ERR;
18836 }
18837 }
18838 if (current_param.fragmentationThreshold != operationParam->fragmentationThreshold) {
developer56fbedb2023-05-30 16:47:05 +080018839 hapd_conf_change = TRUE;
developera3511852023-06-14 14:12:59 +080018840 if (wifi_setRadioFragmentationThreshold(index, operationParam->fragmentationThreshold) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018841 wifi_debug(DEBUG_ERROR, "wifi_setRadioFragmentationThreshold return error.\n");
developera3511852023-06-14 14:12:59 +080018842 return RETURN_ERR;
18843 }
18844 }
18845 if (current_param.guardInterval != operationParam->guardInterval) {
developer56fbedb2023-05-30 16:47:05 +080018846 hapd_conf_change = TRUE;
18847 drv_dat_change = TRUE;
18848 if (wifi_setGuardInterval(index, operationParam->guardInterval) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018849 wifi_debug(DEBUG_ERROR, "wifi_setGuardInterval return error.\n");
developera3511852023-06-14 14:12:59 +080018850 return RETURN_ERR;
18851 }
18852 }
18853 if (current_param.transmitPower != operationParam->transmitPower) {
developer56fbedb2023-05-30 16:47:05 +080018854 drv_dat_change = TRUE;
developera3511852023-06-14 14:12:59 +080018855 if (wifi_setRadioTransmitPower(index, operationParam->transmitPower) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018856 wifi_debug(DEBUG_ERROR, "wifi_setRadioTransmitPower return error.\n");
developera3511852023-06-14 14:12:59 +080018857 return RETURN_ERR;
18858 }
18859 }
18860 if (current_param.rtsThreshold != operationParam->rtsThreshold) {
developer56fbedb2023-05-30 16:47:05 +080018861 hapd_conf_change = TRUE;
developera3511852023-06-14 14:12:59 +080018862 if (wifi_setApRtsThreshold(index, operationParam->rtsThreshold) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018863 wifi_debug(DEBUG_ERROR, "wifi_setApRtsThreshold return error.\n");
developera3511852023-06-14 14:12:59 +080018864 return RETURN_ERR;
18865 }
18866 }
18867 if (current_param.obssCoex != operationParam->obssCoex) {
developer56fbedb2023-05-30 16:47:05 +080018868 hapd_conf_change = TRUE;
developera3511852023-06-14 14:12:59 +080018869 if (wifi_setRadioObssCoexistenceEnable(index, operationParam->obssCoex) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018870 wifi_debug(DEBUG_ERROR, "wifi_setRadioObssCoexistenceEnable return error.\n");
developera3511852023-06-14 14:12:59 +080018871 return RETURN_ERR;
18872 }
18873 }
18874 if (current_param.stbcEnable != operationParam->stbcEnable) {
developer56fbedb2023-05-30 16:47:05 +080018875 hapd_conf_change = TRUE;
18876 drv_dat_change = TRUE;
developera3511852023-06-14 14:12:59 +080018877 if (wifi_setRadioSTBCEnable(index, operationParam->stbcEnable) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018878 wifi_debug(DEBUG_ERROR, "wifi_setRadioSTBCEnable return error.\n");
developera3511852023-06-14 14:12:59 +080018879 return RETURN_ERR;
18880 }
18881 }
18882 if (current_param.greenFieldEnable != operationParam->greenFieldEnable) {
18883 if (wifi_setRadio11nGreenfieldEnable(index, operationParam->greenFieldEnable) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018884 wifi_debug(DEBUG_ERROR, "wifi_setRadio11nGreenfieldEnable return error.\n");
developera3511852023-06-14 14:12:59 +080018885 return RETURN_ERR;
18886 }
18887 }
developer72fb0bb2023-01-11 09:46:29 +080018888
developera3511852023-06-14 14:12:59 +080018889 /* only down/up interface when dat file has been changed,
18890 * if enable is true, then restart the radio.
18891 */
18892 if (drv_dat_change == TRUE) {
18893 wifi_setRadioEnable(index, FALSE);
developer56fbedb2023-05-30 16:47:05 +080018894 if (operationParam->enable == TRUE)
developera3511852023-06-14 14:12:59 +080018895 wifi_setRadioEnable(index, TRUE);
18896 } else if (hapd_conf_change == TRUE) {
developer82160f02023-08-19 15:30:44 +080018897 int ret, bss_num, i;
18898 char ret_buf[MAX_BUF_SIZE] = {0};
18899
18900 ret = wifi_BandProfileRead(0, index, "BssidNum", ret_buf, sizeof(ret_buf), "1");
18901 if (ret != 0) {
18902 wifi_debug(DEBUG_ERROR, "wifi_BandProfileRead BssidNum failed\n");
18903 return RETURN_ERR;
18904 }
18905 bss_num = atoi(ret_buf);
18906 if (bss_num <= 0) {
18907 wifi_debug(DEBUG_ERROR, "invalid BssidNum %s\n", ret_buf);
18908 return RETURN_ERR;
18909 }
developerbb9b20f2023-10-17 18:46:37 +080018910 if (bss_num > LOGAN_MAX_NUM_VAP_PER_RADIO) {
18911 wifi_debug(DEBUG_ERROR, "bss_num is larger than %d, use %d\n", LOGAN_MAX_NUM_VAP_PER_RADIO, LOGAN_MAX_NUM_VAP_PER_RADIO);
18912 bss_num = LOGAN_MAX_NUM_VAP_PER_RADIO;
18913 }
developer82160f02023-08-19 15:30:44 +080018914 wifi_debug(DEBUG_ERROR, "band %d BssidNum %d\n", index, bss_num);
18915
18916 for (i = 0; i < bss_num; i++) {
18917 ApIndex = array_index_to_vap_index(index, i);
18918 hostapd_raw_remove_bss(ApIndex);
18919 if (operationParam->enable == TRUE)
18920 hostapd_raw_add_bss(ApIndex);
18921 }
developera3511852023-06-14 14:12:59 +080018922 }
developer56fbedb2023-05-30 16:47:05 +080018923
developera3511852023-06-14 14:12:59 +080018924 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080018925
developera3511852023-06-14 14:12:59 +080018926 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080018927}
18928
18929INT wifi_getRadioOperatingParameters(wifi_radio_index_t index, wifi_radio_operationParam_t *operationParam)
18930{
developera3511852023-06-14 14:12:59 +080018931 char band[64] = {0};
18932 char buf[256] = {0};
18933 char config_file[64] = {0};
developer8078acf2023-08-04 18:52:48 +080018934
developera3511852023-06-14 14:12:59 +080018935 UINT mode = 0;
18936 BOOL enabled = FALSE;
developer863a4a62023-06-06 16:55:59 +080018937 int dtimPeriod;
developer2f79c922023-06-02 17:33:42 +080018938 UINT beaconInterval;
18939 UINT basicDataTransmitRates;
18940 UINT operationalDataTransmitRates;
18941 wifi_guard_interval_t guardInterval;
18942 UINT transmitPower;
developere40952c2023-06-15 18:46:43 +080018943 int res;
developerc14d83a2023-06-29 20:09:42 +080018944 unsigned long tmp;
developer72fb0bb2023-01-11 09:46:29 +080018945
developera3511852023-06-14 14:12:59 +080018946 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
18947 printf("Entering %s index = %d\n", __func__, (int)index);
developer72fb0bb2023-01-11 09:46:29 +080018948
developera3511852023-06-14 14:12:59 +080018949 memset(operationParam, 0, sizeof(wifi_radio_operationParam_t));
developere40952c2023-06-15 18:46:43 +080018950 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, index);
18951 if (os_snprintf_error(sizeof(config_file), res)) {
18952 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
18953 return RETURN_ERR;
18954 }
developera3511852023-06-14 14:12:59 +080018955 if (wifi_getRadioEnable(index, &enabled) != RETURN_OK)
18956 {
developer75bd10c2023-06-27 11:34:08 +080018957 wifi_debug(DEBUG_ERROR, "wifi_getRadioEnable return error.\n");
developera3511852023-06-14 14:12:59 +080018958 return RETURN_ERR;
18959 }
18960 operationParam->enable = enabled;
developer72fb0bb2023-01-11 09:46:29 +080018961
developera3511852023-06-14 14:12:59 +080018962 memset(band, 0, sizeof(band));
18963 if (wifi_getRadioOperatingFrequencyBand(index, band) != RETURN_OK)
18964 {
developer75bd10c2023-06-27 11:34:08 +080018965 wifi_debug(DEBUG_ERROR, "wifi_getRadioOperatingFrequencyBand return error.\n");
developera3511852023-06-14 14:12:59 +080018966 return RETURN_ERR;
18967 }
developer72fb0bb2023-01-11 09:46:29 +080018968
developera3511852023-06-14 14:12:59 +080018969 if (!strcmp(band, "2.4GHz"))
18970 operationParam->band = WIFI_FREQUENCY_2_4_BAND;
18971 else if (!strcmp(band, "5GHz"))
18972 operationParam->band = WIFI_FREQUENCY_5_BAND;
18973 else if (!strcmp(band, "6GHz"))
18974 operationParam->band = WIFI_FREQUENCY_6_BAND;
18975 else
18976 {
developer75bd10c2023-06-27 11:34:08 +080018977 wifi_debug(DEBUG_ERROR, "cannot decode band for radio index %d ('%s')\n", index, band);
developera3511852023-06-14 14:12:59 +080018978 }
developer72fb0bb2023-01-11 09:46:29 +080018979
developera3511852023-06-14 14:12:59 +080018980 wifi_hostapdRead(config_file, "channel", buf, sizeof(buf));
18981 if (strcmp(buf, "0") == 0 || strcmp(buf, "acs_survey") == 0) {
18982 operationParam->channel = 0;
18983 operationParam->autoChannelEnabled = TRUE;
18984 } else {
developerc14d83a2023-06-29 20:09:42 +080018985 if (hal_strtoul(buf, 10, &tmp) < 0) {
18986 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080018987 }
18988 operationParam->channel = tmp;
developer5b23cd02023-07-19 20:26:03 +080018989
developera3511852023-06-14 14:12:59 +080018990 operationParam->autoChannelEnabled = FALSE;
18991 }
developer72fb0bb2023-01-11 09:46:29 +080018992
developera3511852023-06-14 14:12:59 +080018993 memset(buf, 0, sizeof(buf));
18994 if (wifi_getRadioOperatingChannelBandwidth(index, buf) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080018995 wifi_debug(DEBUG_ERROR, "wifi_getRadioOperatingChannelBandwidth return error.\n");
developera3511852023-06-14 14:12:59 +080018996 return RETURN_ERR;
18997 }
18998 if (!strcmp(buf, "20MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_20MHZ;
18999 else if (!strcmp(buf, "40MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_40MHZ;
19000 else if (!strcmp(buf, "80MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_80MHZ;
19001 else if (!strcmp(buf, "160MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_160MHZ;
19002 else
19003 {
developer75bd10c2023-06-27 11:34:08 +080019004 wifi_debug(DEBUG_ERROR, "Unknown channel bandwidth: %s\n", buf);
developera3511852023-06-14 14:12:59 +080019005 return false;
19006 }
developer72fb0bb2023-01-11 09:46:29 +080019007
developera3511852023-06-14 14:12:59 +080019008 if (wifi_getRadioMode(index, buf, &mode) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019009 wifi_debug(DEBUG_ERROR, "wifi_getRadioMode return error.\n");
developera3511852023-06-14 14:12:59 +080019010 return RETURN_ERR;
19011 }
19012 // Two different definition bit map, so need to check every bit.
19013 if (mode & WIFI_MODE_A)
19014 operationParam->variant |= WIFI_80211_VARIANT_A;
19015 if (mode & WIFI_MODE_B)
19016 operationParam->variant |= WIFI_80211_VARIANT_B;
19017 if (mode & WIFI_MODE_G)
19018 operationParam->variant |= WIFI_80211_VARIANT_G;
19019 if (mode & WIFI_MODE_N)
19020 operationParam->variant |= WIFI_80211_VARIANT_N;
19021 if (mode & WIFI_MODE_AC)
19022 operationParam->variant |= WIFI_80211_VARIANT_AC;
19023 if (mode & WIFI_MODE_AX)
19024 operationParam->variant |= WIFI_80211_VARIANT_AX;
19025 if (wifi_getRadioDCSEnable(index, &operationParam->DCSEnabled) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019026 wifi_debug(DEBUG_ERROR, "wifi_getRadioDCSEnable return error.\n");
developera3511852023-06-14 14:12:59 +080019027 return RETURN_ERR;
19028 }
19029 if (wifi_getApDTIMInterval(index, &dtimPeriod) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019030 wifi_debug(DEBUG_ERROR, "wifi_getApDTIMInterval return error.\n");
developera3511852023-06-14 14:12:59 +080019031 return RETURN_ERR;
19032 }
developer2f79c922023-06-02 17:33:42 +080019033 operationParam->dtimPeriod = dtimPeriod;
developera3511852023-06-14 14:12:59 +080019034 if (wifi_getRadioBeaconPeriod(index, &beaconInterval) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019035 wifi_debug(DEBUG_ERROR, "wifi_getRadioBeaconPeriod return error.\n");
developera3511852023-06-14 14:12:59 +080019036 return RETURN_ERR;
19037 }
developer2f79c922023-06-02 17:33:42 +080019038 operationParam->beaconInterval = beaconInterval;
developer72fb0bb2023-01-11 09:46:29 +080019039
developera3511852023-06-14 14:12:59 +080019040 memset(buf, 0, sizeof(buf));
19041 if (wifi_getRadioSupportedDataTransmitRates(index, buf) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019042 wifi_debug(DEBUG_ERROR, "wifi_getRadioSupportedDataTransmitRates return error.\n");
developera3511852023-06-14 14:12:59 +080019043 return RETURN_ERR;
19044 }
19045 TransmitRatesToBitMap(buf, &basicDataTransmitRates);
developer2f79c922023-06-02 17:33:42 +080019046 operationParam->basicDataTransmitRates = basicDataTransmitRates;
developer72fb0bb2023-01-11 09:46:29 +080019047
developera3511852023-06-14 14:12:59 +080019048 memset(buf, 0, sizeof(buf));
19049 if (wifi_getRadioBasicDataTransmitRates(index, buf) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019050 wifi_debug(DEBUG_ERROR, "wifi_getRadioBasicDataTransmitRates return error.\n");
developera3511852023-06-14 14:12:59 +080019051 return RETURN_ERR;
19052 }
19053 TransmitRatesToBitMap(buf, &operationalDataTransmitRates);
developer2f79c922023-06-02 17:33:42 +080019054 operationParam->operationalDataTransmitRates = operationalDataTransmitRates;
developer72fb0bb2023-01-11 09:46:29 +080019055
developera3511852023-06-14 14:12:59 +080019056 memset(buf, 0, sizeof(buf));
19057 wifi_hostapdRead(config_file, "fragm_threshold", buf, sizeof(buf));
developerc14d83a2023-06-29 20:09:42 +080019058 if (hal_strtoul(buf, 10, &tmp) < 0) {
19059 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
19060 }
19061 operationParam->fragmentationThreshold = tmp;
developer72fb0bb2023-01-11 09:46:29 +080019062
developera3511852023-06-14 14:12:59 +080019063 if (wifi_getGuardInterval(index, &guardInterval) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019064 wifi_debug(DEBUG_ERROR, "wifi_getGuardInterval return error.\n");
developera3511852023-06-14 14:12:59 +080019065 return RETURN_ERR;
19066 }
developer2f79c922023-06-02 17:33:42 +080019067 operationParam->guardInterval = guardInterval;
19068
developera3511852023-06-14 14:12:59 +080019069 if (wifi_getRadioPercentageTransmitPower(index, (ULONG *)&transmitPower) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019070 wifi_debug(DEBUG_ERROR, "wifi_getRadioPercentageTransmitPower return error.\n");
developera3511852023-06-14 14:12:59 +080019071 return RETURN_ERR;
19072 }
developer2f79c922023-06-02 17:33:42 +080019073 operationParam->transmitPower = transmitPower;
developer72fb0bb2023-01-11 09:46:29 +080019074
developera3511852023-06-14 14:12:59 +080019075 memset(buf, 0, sizeof(buf));
19076 wifi_hostapdRead(config_file, "rts_threshold", buf, sizeof(buf));
19077 if (strcmp(buf, "-1") == 0) {
19078 operationParam->rtsThreshold = (UINT)-1; // maxuimum unsigned integer value
19079 operationParam->ctsProtection = FALSE;
19080 } else {
developerc14d83a2023-06-29 20:09:42 +080019081 if (hal_strtoul(buf, 10, &tmp) < 0) {
19082 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
19083 }
19084 operationParam->rtsThreshold = tmp;
developera3511852023-06-14 14:12:59 +080019085 operationParam->ctsProtection = TRUE;
19086 }
developer72fb0bb2023-01-11 09:46:29 +080019087
developera3511852023-06-14 14:12:59 +080019088 memset(buf, 0, sizeof(buf));
19089 wifi_hostapdRead(config_file, "ht_coex", buf, sizeof(buf));
19090 if (strcmp(buf, "0") == 0)
19091 operationParam->obssCoex = FALSE;
19092 else
19093 operationParam->obssCoex = TRUE;
developer72fb0bb2023-01-11 09:46:29 +080019094
developer8078acf2023-08-04 18:52:48 +080019095 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep STBC", config_file);
19096 if (res) {
19097 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19098
developere40952c2023-06-15 18:46:43 +080019099 }
developer8078acf2023-08-04 18:52:48 +080019100
developera3511852023-06-14 14:12:59 +080019101 if (strlen(buf) != 0)
19102 operationParam->stbcEnable = TRUE;
19103 else
19104 operationParam->stbcEnable = FALSE;
developer72fb0bb2023-01-11 09:46:29 +080019105
developera3511852023-06-14 14:12:59 +080019106 if (wifi_getRadio11nGreenfieldEnable(index, &operationParam->greenFieldEnable) != RETURN_OK) {
developer75bd10c2023-06-27 11:34:08 +080019107 wifi_debug(DEBUG_ERROR, "wifi_getRadio11nGreenfieldEnable return error.\n");
developera3511852023-06-14 14:12:59 +080019108 return RETURN_ERR;
19109 }
developer72fb0bb2023-01-11 09:46:29 +080019110
developera3511852023-06-14 14:12:59 +080019111 // Below value is hardcoded
developer72fb0bb2023-01-11 09:46:29 +080019112
developera3511852023-06-14 14:12:59 +080019113 operationParam->numSecondaryChannels = 0;
19114 for (int i = 0; i < MAXNUMSECONDARYCHANNELS; i++) {
19115 operationParam->channelSecondary[i] = 0;
19116 }
19117 operationParam->csa_beacon_count = 15;
19118 operationParam->countryCode = wifi_countrycode_US; // hard to convert string to corresponding enum
developer72fb0bb2023-01-11 09:46:29 +080019119
developera3511852023-06-14 14:12:59 +080019120 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
19121 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080019122}
19123
19124static int array_index_to_vap_index(UINT radioIndex, int arrayIndex)
19125{
developera3511852023-06-14 14:12:59 +080019126 int max_radio_num = 0;
developer72fb0bb2023-01-11 09:46:29 +080019127
developera3511852023-06-14 14:12:59 +080019128 wifi_getMaxRadioNumber(&max_radio_num);
19129 if (radioIndex >= max_radio_num) {
developer75bd10c2023-06-27 11:34:08 +080019130 wifi_debug(DEBUG_ERROR, "Wrong radio index (%d)\n", radioIndex);
developera3511852023-06-14 14:12:59 +080019131 return RETURN_ERR;
19132 }
developer72fb0bb2023-01-11 09:46:29 +080019133
developera3511852023-06-14 14:12:59 +080019134 return (arrayIndex * max_radio_num) + radioIndex;
developer72fb0bb2023-01-11 09:46:29 +080019135}
19136
developer96b38512023-02-22 11:17:45 +080019137static int vap_index_to_array_index(int vapIndex, int *radioIndex, int *arrayIndex)
19138{
developera3511852023-06-14 14:12:59 +080019139 int max_radio_num = 0;
developer96b38512023-02-22 11:17:45 +080019140
developera3511852023-06-14 14:12:59 +080019141 if ((vapIndex < 0) || (vapIndex > MAX_NUM_VAP_PER_RADIO*MAX_NUM_RADIOS))
developer96b38512023-02-22 11:17:45 +080019142 return -1;
19143
developera3511852023-06-14 14:12:59 +080019144 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +080019145 if(max_radio_num == 0){
19146 return RETURN_ERR;
19147 }
developera3511852023-06-14 14:12:59 +080019148 (*radioIndex) = vapIndex % max_radio_num;
19149 (*arrayIndex) = vapIndex / max_radio_num;
developer96b38512023-02-22 11:17:45 +080019150
developera3511852023-06-14 14:12:59 +080019151 return 0;
developer96b38512023-02-22 11:17:45 +080019152}
19153
19154
developer72fb0bb2023-01-11 09:46:29 +080019155wifi_bitrate_t beaconRate_string_to_enum(char *beaconRate) {
developera3511852023-06-14 14:12:59 +080019156 if (strncmp(beaconRate, "1Mbps", 5) == 0)
19157 return WIFI_BITRATE_1MBPS;
19158 else if (strncmp(beaconRate, "2Mbps", 5) == 0)
19159 return WIFI_BITRATE_2MBPS;
19160 else if (strncmp(beaconRate, "5.5Mbps", 7) == 0)
19161 return WIFI_BITRATE_5_5MBPS;
19162 else if (strncmp(beaconRate, "6Mbps", 5) == 0)
19163 return WIFI_BITRATE_6MBPS;
19164 else if (strncmp(beaconRate, "9Mbps", 5) == 0)
19165 return WIFI_BITRATE_9MBPS;
19166 else if (strncmp(beaconRate, "11Mbps", 6) == 0)
19167 return WIFI_BITRATE_11MBPS;
19168 else if (strncmp(beaconRate, "12Mbps", 6) == 0)
19169 return WIFI_BITRATE_12MBPS;
19170 else if (strncmp(beaconRate, "18Mbps", 6) == 0)
19171 return WIFI_BITRATE_18MBPS;
19172 else if (strncmp(beaconRate, "24Mbps", 6) == 0)
19173 return WIFI_BITRATE_24MBPS;
19174 else if (strncmp(beaconRate, "36Mbps", 6) == 0)
19175 return WIFI_BITRATE_36MBPS;
19176 else if (strncmp(beaconRate, "48Mbps", 6) == 0)
19177 return WIFI_BITRATE_48MBPS;
19178 else if (strncmp(beaconRate, "54Mbps", 6) == 0)
19179 return WIFI_BITRATE_54MBPS;
19180 return WIFI_BITRATE_DEFAULT;
developer72fb0bb2023-01-11 09:46:29 +080019181}
19182
developer32f2a182023-06-27 19:50:41 +080019183struct beacon_rate_2_string {
19184 wifi_bitrate_t beacon;
19185 char beacon_str[8];
19186};
19187
19188struct beacon_rate_2_string br2str[12] = {
19189 {WIFI_BITRATE_1MBPS, "1Mbps"},
19190 {WIFI_BITRATE_2MBPS, "2Mbps"},
19191 {WIFI_BITRATE_5_5MBPS, "5.5Mbps"},
19192 {WIFI_BITRATE_6MBPS, "6Mbps"},
19193 {WIFI_BITRATE_9MBPS, "9Mbps"},
19194 {WIFI_BITRATE_11MBPS, "11Mbps"},
19195 {WIFI_BITRATE_12MBPS, "12Mbps"},
19196 {WIFI_BITRATE_18MBPS, "18Mbps"},
19197 {WIFI_BITRATE_24MBPS, "24Mbps"},
19198 {WIFI_BITRATE_36MBPS, "36Mbps"},
19199 {WIFI_BITRATE_48MBPS, "48Mbps"},
19200 {WIFI_BITRATE_54MBPS, "54Mbps"}
19201};
19202
19203INT beaconRate_enum_to_string(wifi_bitrate_t beacon, char *beacon_str, unsigned long str_size)
developer72fb0bb2023-01-11 09:46:29 +080019204{
developer32f2a182023-06-27 19:50:41 +080019205 int i;
19206 unsigned long len;
19207
19208 for (i = 0; i < (sizeof(br2str)/sizeof(br2str[0])); i++) {
19209 if (beacon == br2str[i].beacon) {
19210 len = strlen(br2str[i].beacon_str);
19211 if (len >= str_size)
19212 return RETURN_ERR;
19213 memcpy(beacon_str, br2str[i].beacon_str, len);
19214 beacon_str[len] = '\0';
19215 break;
19216 }
19217 }
developera3511852023-06-14 14:12:59 +080019218 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080019219}
19220
19221INT wifi_getRadioVapInfoMap(wifi_radio_index_t index, wifi_vap_info_map_t *map)
19222{
developera3511852023-06-14 14:12:59 +080019223 INT mode = 0;
19224 INT ret = -1;
19225 UINT output = 0;
19226 int i = 0;
19227 int vap_index = 0;
19228 BOOL enabled = FALSE;
19229 char buf[32] = {0};
19230 wifi_vap_security_t security = {0};
developerbb9b20f2023-10-17 18:46:37 +080019231 int res = RETURN_OK;
developer6c6ef372023-11-08 10:59:14 +080019232 wifi_vap_info_t *vap;
19233 wifi_mld_info_t *mld_info;
19234 unsigned char mld_index;
developer72fb0bb2023-01-11 09:46:29 +080019235
developera3511852023-06-14 14:12:59 +080019236 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
19237 printf("Entering %s index = %d\n", __func__, (int)index);
developer72fb0bb2023-01-11 09:46:29 +080019238
developerbb9b20f2023-10-17 18:46:37 +080019239 memset((void *)map, 0, sizeof(*map));
developera3511852023-06-14 14:12:59 +080019240 ret = wifi_BandProfileRead(0, index, "BssidNum", buf, sizeof(buf), "0");
19241 if (ret != 0) {
developer75bd10c2023-06-27 11:34:08 +080019242 wifi_debug(DEBUG_ERROR, "wifi_BandProfileRead BssidNum failed\n");
developera3511852023-06-14 14:12:59 +080019243 return RETURN_ERR;
19244 }
developerfde01262023-05-22 15:15:24 +080019245
developera3511852023-06-14 14:12:59 +080019246 map->num_vaps = atoi(buf);
19247 if (map->num_vaps <= 0) {
developer75bd10c2023-06-27 11:34:08 +080019248 wifi_debug(DEBUG_ERROR, "invalid BssidNum %s\n", buf);
developera3511852023-06-14 14:12:59 +080019249 return RETURN_ERR;
19250 }
developerbb9b20f2023-10-17 18:46:37 +080019251 if (map->num_vaps > LOGAN_MAX_NUM_VAP_PER_RADIO) {
19252 wifi_debug(DEBUG_ERROR, "bss_num is larger than %d, use %d\n", LOGAN_MAX_NUM_VAP_PER_RADIO, LOGAN_MAX_NUM_VAP_PER_RADIO);
19253 map->num_vaps = LOGAN_MAX_NUM_VAP_PER_RADIO;
19254 }
developerfde01262023-05-22 15:15:24 +080019255
developera3511852023-06-14 14:12:59 +080019256 for (i = 0; i < map->num_vaps; i++)
19257 {
19258 map->vap_array[i].radio_index = index;
developer72fb0bb2023-01-11 09:46:29 +080019259
developera3511852023-06-14 14:12:59 +080019260 vap_index = array_index_to_vap_index(index, i);
developerbb9b20f2023-10-17 18:46:37 +080019261 if (vap_index < 0) {
19262 res = RETURN_ERR;
19263 continue;
19264 }
developer72fb0bb2023-01-11 09:46:29 +080019265
developer9ce44382023-06-28 11:09:37 +080019266 strncpy(map->vap_array[i].bridge_name, BRIDGE_NAME,sizeof(map->vap_array[i].bridge_name) - 1);
19267 map->vap_array[i].bridge_name[sizeof(map->vap_array[i].bridge_name) - 1] = '\0';
developer72fb0bb2023-01-11 09:46:29 +080019268
developera3511852023-06-14 14:12:59 +080019269 map->vap_array[i].vap_index = vap_index;
developer72fb0bb2023-01-11 09:46:29 +080019270
developera3511852023-06-14 14:12:59 +080019271 memset(buf, 0, sizeof(buf));
19272 ret = wifi_getApName(vap_index, buf);
19273 if (ret != RETURN_OK) {
19274 printf("%s: wifi_getApName return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019275 res = RETURN_ERR;
19276 continue;
developera3511852023-06-14 14:12:59 +080019277 }
developerbb9b20f2023-10-17 18:46:37 +080019278 ret = snprintf(map->vap_array[i].vap_name, sizeof(map->vap_array[i].vap_name), "%s", buf);
19279 if (os_snprintf_error(sizeof(map->vap_array[i].vap_name), ret)) {
developere40952c2023-06-15 18:46:43 +080019280 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developerbb9b20f2023-10-17 18:46:37 +080019281 res = RETURN_ERR;
19282 continue;
developere40952c2023-06-15 18:46:43 +080019283 }
developer72fb0bb2023-01-11 09:46:29 +080019284
developera3511852023-06-14 14:12:59 +080019285 memset(buf, 0, sizeof(buf));
19286 ret = wifi_getSSIDName(vap_index, buf);
19287 if (ret != RETURN_OK) {
19288 printf("%s: wifi_getSSIDName return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019289 res = RETURN_ERR;
19290 continue;
developera3511852023-06-14 14:12:59 +080019291 }
developerbb9b20f2023-10-17 18:46:37 +080019292 ret = snprintf(map->vap_array[i].u.bss_info.ssid, sizeof(map->vap_array[i].u.bss_info.ssid), "%s", buf);
19293 if (os_snprintf_error(sizeof(map->vap_array[i].u.bss_info.ssid), ret)) {
developere40952c2023-06-15 18:46:43 +080019294 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
developerbb9b20f2023-10-17 18:46:37 +080019295 res = RETURN_ERR;
19296 continue;
developere40952c2023-06-15 18:46:43 +080019297 }
developer72fb0bb2023-01-11 09:46:29 +080019298
developera3511852023-06-14 14:12:59 +080019299 map->vap_array[i].u.bss_info.enabled = true;
developer72fb0bb2023-01-11 09:46:29 +080019300
developera3511852023-06-14 14:12:59 +080019301 ret = wifi_getApSsidAdvertisementEnable(vap_index, &enabled);
19302 if (ret != RETURN_OK) {
19303 printf("%s: wifi_getApSsidAdvertisementEnable return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019304 res = RETURN_ERR;
19305 continue;
developera3511852023-06-14 14:12:59 +080019306 }
19307 map->vap_array[i].u.bss_info.showSsid = enabled;
developer69b61b02023-03-07 17:17:44 +080019308
developera3511852023-06-14 14:12:59 +080019309 ret = wifi_getApMaxAssociatedDevices(vap_index, &output);
19310 if (ret != RETURN_OK) {
19311 printf("%s: wifi_getApMaxAssociatedDevices return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019312 res = RETURN_ERR;
19313 continue;
developera3511852023-06-14 14:12:59 +080019314 }
19315 map->vap_array[i].u.bss_info.bssMaxSta = output;
developer72fb0bb2023-01-11 09:46:29 +080019316
developera3511852023-06-14 14:12:59 +080019317 ret = wifi_getBSSTransitionActivation(vap_index, &enabled);
19318 if (ret != RETURN_OK) {
19319 printf("%s: wifi_getBSSTransitionActivation return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019320 res = RETURN_ERR;
19321 continue;
developera3511852023-06-14 14:12:59 +080019322 }
19323 map->vap_array[i].u.bss_info.bssTransitionActivated = enabled;
developer72fb0bb2023-01-11 09:46:29 +080019324
developera3511852023-06-14 14:12:59 +080019325 ret = wifi_getNeighborReportActivation(vap_index, &enabled);
19326 if (ret != RETURN_OK) {
19327 printf("%s: wifi_getNeighborReportActivation return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019328 res = RETURN_ERR;
19329 continue;
developera3511852023-06-14 14:12:59 +080019330 }
19331 map->vap_array[i].u.bss_info.nbrReportActivated = enabled;
developer72fb0bb2023-01-11 09:46:29 +080019332
developera3511852023-06-14 14:12:59 +080019333 ret = wifi_getApSecurity(vap_index, &security);
19334 if (ret != RETURN_OK) {
19335 printf("%s: wifi_getApSecurity return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019336 res = RETURN_ERR;
19337 continue;
developera3511852023-06-14 14:12:59 +080019338 }
19339 map->vap_array[i].u.bss_info.security = security;
developer72fb0bb2023-01-11 09:46:29 +080019340
developera3511852023-06-14 14:12:59 +080019341 ret = wifi_getApMacAddressControlMode(vap_index, &mode);
19342 if (ret != RETURN_OK) {
19343 printf("%s: wifi_getApMacAddressControlMode return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019344 res = RETURN_ERR;
19345 continue;
developera3511852023-06-14 14:12:59 +080019346 }
19347 if (mode == 0)
19348 map->vap_array[i].u.bss_info.mac_filter_enable = FALSE;
19349 else
19350 map->vap_array[i].u.bss_info.mac_filter_enable = TRUE;
19351 if (mode == 1)
19352 map->vap_array[i].u.bss_info.mac_filter_mode = wifi_mac_filter_mode_white_list;
19353 else if (mode == 2)
19354 map->vap_array[i].u.bss_info.mac_filter_mode = wifi_mac_filter_mode_black_list;
developer72fb0bb2023-01-11 09:46:29 +080019355
developera3511852023-06-14 14:12:59 +080019356 ret = wifi_getApWmmEnable(vap_index, &enabled);
19357 if (ret != RETURN_OK) {
19358 printf("%s: wifi_getApWmmEnable return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019359 res = RETURN_ERR;
19360 continue;
developera3511852023-06-14 14:12:59 +080019361 }
19362 map->vap_array[i].u.bss_info.wmm_enabled = enabled;
developer72fb0bb2023-01-11 09:46:29 +080019363
developera3511852023-06-14 14:12:59 +080019364 ret = wifi_getApUAPSDCapability(vap_index, &enabled);
19365 if (ret != RETURN_OK) {
19366 printf("%s: wifi_getApUAPSDCapability return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019367 res = RETURN_ERR;
19368 continue;
developera3511852023-06-14 14:12:59 +080019369 }
19370 map->vap_array[i].u.bss_info.UAPSDEnabled = enabled;
developer72fb0bb2023-01-11 09:46:29 +080019371
developera3511852023-06-14 14:12:59 +080019372 memset(buf, 0, sizeof(buf));
19373 ret = wifi_getApBeaconRate(map->vap_array[i].radio_index, buf);
19374 if (ret != RETURN_OK) {
19375 printf("%s: wifi_getApBeaconRate return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019376 res = RETURN_ERR;
19377 continue;
developera3511852023-06-14 14:12:59 +080019378 }
19379 map->vap_array[i].u.bss_info.beaconRate = beaconRate_string_to_enum(buf);
developer72fb0bb2023-01-11 09:46:29 +080019380
developera3511852023-06-14 14:12:59 +080019381 memset(buf, 0, sizeof(buf));
19382 ret = wifi_getBaseBSSID(vap_index, buf);
19383 if (ret != RETURN_OK) {
19384 printf("%s: wifi_getBaseBSSID return error\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019385 res = RETURN_ERR;
19386 continue;
developera3511852023-06-14 14:12:59 +080019387 }
developer5b2f10c2023-05-25 17:02:21 +080019388 if (hwaddr_aton2(buf, map->vap_array[i].u.bss_info.bssid) < 0) {
19389 printf("%s: hwaddr_aton2 fail\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019390 res = RETURN_ERR;
19391 continue;
developer5b2f10c2023-05-25 17:02:21 +080019392 }
developer72fb0bb2023-01-11 09:46:29 +080019393
developera3511852023-06-14 14:12:59 +080019394 ret = wifi_getRadioIGMPSnoopingEnable(map->vap_array[i].radio_index, &enabled);
19395 if (ret != RETURN_OK) {
developerc14d83a2023-06-29 20:09:42 +080019396 wifi_debug(DEBUG_ERROR, "%s: wifi_getRadioIGMPSnoopingEnable\n", __func__);
developerbb9b20f2023-10-17 18:46:37 +080019397 res = RETURN_ERR;
19398 continue;
developera3511852023-06-14 14:12:59 +080019399 }
19400 map->vap_array[i].u.bss_info.mcast2ucast = enabled;
developer72fb0bb2023-01-11 09:46:29 +080019401
developer6c6ef372023-11-08 10:59:14 +080019402 ret = wifi_getApIsolationEnable(vap_index, &enabled);
19403 if (ret != RETURN_OK) {
19404 printf("%s: wifi_getApIsolationEnable return error\n", __func__);
19405// res = RETURN_ERR;
19406 continue;
19407 }
19408 map->vap_array[i].u.bss_info.isolation = enabled;
19409 }
19410
19411 for (i = 0; i < map->num_vaps; i++)
19412 {
19413 map->vap_array[i].radio_index = index;
19414 vap = &(map->vap_array[i]);
19415
19416 mld_info = &(vap->u.bss_info.mld_info);
19417 memset(mld_info, 0, sizeof(*mld_info));
19418 memcpy(mld_info->local_addr, map->vap_array[i].u.bss_info.bssid, 6);
19419
19420 mld_index = mld_ap_test_all_mlds(vap->vap_index);
19421 if (mld_index) {
19422 memcpy(mld_info->common_info.mld_addr, mld_config.mld[mld_index].mld_mac, 6);
19423 mld_info->common_info.mld_enable = TRUE;
19424 mld_info->common_info.mld_index = mld_index;
19425 }
19426 wifi_debug(DEBUG_ERROR,
19427 "vap_index[%d], mld_enable=%d, mld_index[%d]\n",
19428 vap->vap_index, mld_info->common_info.mld_enable, mld_info->common_info.mld_index);
developera3511852023-06-14 14:12:59 +080019429 }
19430 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developerbb9b20f2023-10-17 18:46:37 +080019431 return res;
developer72fb0bb2023-01-11 09:46:29 +080019432}
19433
developer47cc27a2023-05-17 23:09:58 +080019434void checkVapStatus(int apIndex, BOOL *enable)
developer72fb0bb2023-01-11 09:46:29 +080019435{
developera3511852023-06-14 14:12:59 +080019436 char if_name[16] = {0};
developera3511852023-06-14 14:12:59 +080019437 char buf[128] = {0};
developere40952c2023-06-15 18:46:43 +080019438 int res;
developer72fb0bb2023-01-11 09:46:29 +080019439
developera3511852023-06-14 14:12:59 +080019440 *enable = FALSE;
19441 if (wifi_GetInterfaceName(apIndex, if_name) != RETURN_OK)
19442 return;
developer72fb0bb2023-01-11 09:46:29 +080019443
developer8078acf2023-08-04 18:52:48 +080019444 res = _syscmd_secure(buf, sizeof(buf), "cat %s | grep ^%s=1", VAP_STATUS_FILE, if_name);
19445 if (res) {
19446 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19447
developere40952c2023-06-15 18:46:43 +080019448 }
developer8078acf2023-08-04 18:52:48 +080019449
developera3511852023-06-14 14:12:59 +080019450 if (strlen(buf) > 0)
19451 *enable = TRUE;
19452 return;
developer72fb0bb2023-01-11 09:46:29 +080019453}
19454
developer56fbedb2023-05-30 16:47:05 +080019455int hostapd_manage_bss(INT apIndex, BOOL enable)
19456{
19457 char interface_name[16] = {0};
developerb149d9d2023-06-06 16:14:22 +080019458 char config_file[MAX_SUB_CMD_SIZE] = {0};
developer8078acf2023-08-04 18:52:48 +080019459
developer56fbedb2023-05-30 16:47:05 +080019460 char buf[MAX_BUF_SIZE] = {0};
19461 BOOL status = FALSE;
19462 int max_radio_num = 0;
19463 int phyId = 0;
developere40952c2023-06-15 18:46:43 +080019464 int res;
developer56fbedb2023-05-30 16:47:05 +080019465
19466 wifi_getApEnable(apIndex, &status);
19467
19468 wifi_getMaxRadioNumber(&max_radio_num);
19469 if (enable == status)
19470 return RETURN_OK;
19471
19472 if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
19473 return RETURN_ERR;
19474
19475 if (enable == TRUE) {
19476 int radioIndex = apIndex % max_radio_num;
19477 phyId = radio_index_to_phy(radioIndex);
developere40952c2023-06-15 18:46:43 +080019478 res = snprintf(config_file, MAX_BUF_SIZE, "%s%d.conf", CONFIG_PREFIX, apIndex);
19479 if (os_snprintf_error(MAX_CMD_SIZE, res)) {
19480 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19481 return RETURN_ERR;
19482 }
developer82160f02023-08-19 15:30:44 +080019483
19484 wifi_debug(DEBUG_ERROR, "raw ADD bss_config config_file=%s\n", config_file);
19485
developer8078acf2023-08-04 18:52:48 +080019486 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw ADD bss_config=phy%d:%s", phyId, config_file);
19487 if (res) {
19488 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19489
developere40952c2023-06-15 18:46:43 +080019490 }
developer8078acf2023-08-04 18:52:48 +080019491
developer56fbedb2023-05-30 16:47:05 +080019492 } else {
developerc14d83a2023-06-29 20:09:42 +080019493 wifi_debug(DEBUG_ERROR, "%s %d\n", __func__, __LINE__);
developer82160f02023-08-19 15:30:44 +080019494
19495 wifi_debug(DEBUG_ERROR, "global raw REMOVE %s\n", interface_name);
developer8078acf2023-08-04 18:52:48 +080019496 res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw REMOVE %s", interface_name);
19497 if (res) {
19498 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19499
developere40952c2023-06-15 18:46:43 +080019500 }
developer56fbedb2023-05-30 16:47:05 +080019501 }
developer8078acf2023-08-04 18:52:48 +080019502 res = _syscmd_secure(buf, sizeof(buf), "sed -i -n -e '/^%s=/!p' -e '$a%s=%d' %s",
developer56fbedb2023-05-30 16:47:05 +080019503 interface_name, interface_name, enable, VAP_STATUS_FILE);
developer8078acf2023-08-04 18:52:48 +080019504 if (res) {
19505 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19506
developere40952c2023-06-15 18:46:43 +080019507 }
developer56fbedb2023-05-30 16:47:05 +080019508 //Wait for wifi up/down to apply
19509 return RETURN_OK;
19510}
19511
19512int hostapd_raw_add_bss(int apIndex)
19513{
19514 return hostapd_manage_bss(apIndex, TRUE);
19515}
19516
19517int hostapd_raw_remove_bss(int apIndex)
19518{
19519 return hostapd_manage_bss(apIndex, FALSE);
19520}
19521
19522int hostapd_raw_restart_bss(int apIndex)
developer333c1eb2023-05-31 14:59:39 +080019523{
developerdaf24792023-06-06 11:40:04 +080019524 int ret = 0;
19525
19526 ret = hostapd_raw_remove_bss(apIndex);
19527 if(ret != RETURN_OK)
19528 return RETURN_ERR;
19529
19530 ret = hostapd_raw_add_bss(apIndex);
19531 if(ret != RETURN_OK)
19532 return RETURN_ERR;
19533
19534 return RETURN_OK;
developer56fbedb2023-05-30 16:47:05 +080019535}
19536
developer72fb0bb2023-01-11 09:46:29 +080019537INT wifi_createVAP(wifi_radio_index_t index, wifi_vap_info_map_t *map)
19538{
developera3511852023-06-14 14:12:59 +080019539 unsigned int i;
19540 wifi_vap_info_t *vap_info = NULL;
19541 int acl_mode;
19542 int ret = 0;
19543 char buf[256] = {0};
19544 char cmd[128] = {0};
19545 char config_file[64] = {0};
19546 char psk_file[64] = {0};
19547 BOOL enable = FALSE;
19548 int band_idx;
developere40952c2023-06-15 18:46:43 +080019549 int res;
developer6c6ef372023-11-08 10:59:14 +080019550 wifi_mld_common_info_t *mld_info;
19551 unsigned char mld_index;
19552 unsigned char ap_index_array[MAX_APS] = {0};
19553 unsigned char ap_array_num;
19554 char interface_name[IF_NAME_SIZE] = {0};
developer72fb0bb2023-01-11 09:46:29 +080019555
developera3511852023-06-14 14:12:59 +080019556 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
19557 printf("Entering %s index = %d\n", __func__, (int)index);
developer6bfd6462023-08-24 14:28:18 +080019558 for (i = 0; i < map->num_vaps; i++)
developera3511852023-06-14 14:12:59 +080019559 {
19560 multiple_set = TRUE;
19561 vap_info = &map->vap_array[i];
developer72fb0bb2023-01-11 09:46:29 +080019562
developera3511852023-06-14 14:12:59 +080019563 // Check vap status file to enable multiple ap if the system boot.
19564 checkVapStatus(vap_info->vap_index, &enable);
19565 if (vap_info->u.bss_info.enabled == FALSE && enable == FALSE)
19566 continue;
developer72fb0bb2023-01-11 09:46:29 +080019567
developer75bd10c2023-06-27 11:34:08 +080019568 wifi_debug(DEBUG_ERROR, "\nCreate VAP for ssid_index=%d (vap_num=%d)\n", vap_info->vap_index, i);
developer72fb0bb2023-01-11 09:46:29 +080019569
developera3511852023-06-14 14:12:59 +080019570 band_idx = radio_index_to_band(index);
developere40952c2023-06-15 18:46:43 +080019571 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, vap_info->vap_index);
19572 if (os_snprintf_error(sizeof(config_file), res)) {
19573 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19574 return RETURN_ERR;
19575 }
developer9ce44382023-06-28 11:09:37 +080019576 if(band_idx >= 0 && band_idx < sizeof(wifi_band_str)/sizeof(wifi_band_str[0])){
19577 res = snprintf(cmd, sizeof(cmd), "cp /etc/hostapd-%s.conf %s", wifi_band_str[band_idx], config_file);
19578 } else{
19579 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19580 return RETURN_ERR;
19581 }
developere40952c2023-06-15 18:46:43 +080019582 if (os_snprintf_error(sizeof(cmd), res)) {
19583 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19584 return RETURN_ERR;
19585 }
developer8078acf2023-08-04 18:52:48 +080019586
19587 res = _syscmd_secure(buf, sizeof(buf), "cp /etc/hostapd-%s.conf %s", wifi_band_str[band_idx], config_file);
19588 if (res) {
19589 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19590
19591 }
developer72fb0bb2023-01-11 09:46:29 +080019592
developera3511852023-06-14 14:12:59 +080019593 struct params params[3];
19594 params[0].name = "interface";
19595 params[0].value = vap_info->vap_name;
developere40952c2023-06-15 18:46:43 +080019596 res = snprintf(psk_file, sizeof(psk_file), "\\/nvram\\/hostapd%d.psk", vap_info->vap_index);
19597 if (os_snprintf_error(sizeof(psk_file), res)) {
19598 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19599 return RETURN_ERR;
19600 }
developera3511852023-06-14 14:12:59 +080019601 params[1].name = "wpa_psk_file";
19602 params[1].value = psk_file;
19603 params[2].name = "ssid";
19604 params[2].value = vap_info->u.bss_info.ssid;
developer72fb0bb2023-01-11 09:46:29 +080019605
developer37646972023-06-29 10:58:43 +080019606 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, vap_info->vap_index);
19607 if (os_snprintf_error(sizeof(config_file), res)) {
19608 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19609 return RETURN_ERR;
19610 }
developera3511852023-06-14 14:12:59 +080019611 wifi_hostapdWrite(config_file, params, 3);
developer72fb0bb2023-01-11 09:46:29 +080019612
developer8078acf2023-08-04 18:52:48 +080019613 res = _syscmd_secure(buf, sizeof(buf), "touch %s", psk_file);
19614 if (res) {
19615 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19616
developere40952c2023-06-15 18:46:43 +080019617 }
developer72fb0bb2023-01-11 09:46:29 +080019618
developera3511852023-06-14 14:12:59 +080019619 ret = wifi_setSSIDName(vap_info->vap_index, vap_info->u.bss_info.ssid);
19620 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019621 wifi_debug(DEBUG_ERROR,"wifi_setSSIDName return error\n");
developera3511852023-06-14 14:12:59 +080019622 return RETURN_ERR;
19623 }
developer72fb0bb2023-01-11 09:46:29 +080019624
developera3511852023-06-14 14:12:59 +080019625 ret = wifi_setApSsidAdvertisementEnable(vap_info->vap_index, vap_info->u.bss_info.showSsid);
19626 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019627 wifi_debug(DEBUG_ERROR, "wifi_setApSsidAdvertisementEnable return error\n");
developera3511852023-06-14 14:12:59 +080019628 return RETURN_ERR;
19629 }
developer72fb0bb2023-01-11 09:46:29 +080019630
developera3511852023-06-14 14:12:59 +080019631 ret = wifi_setApMaxAssociatedDevices(vap_info->vap_index, vap_info->u.bss_info.bssMaxSta);
19632 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019633 wifi_debug(DEBUG_ERROR, "wifi_setApMaxAssociatedDevices return error\n");
developera3511852023-06-14 14:12:59 +080019634 return RETURN_ERR;
19635 }
developer72fb0bb2023-01-11 09:46:29 +080019636
developera3511852023-06-14 14:12:59 +080019637 ret = wifi_setBSSTransitionActivation(vap_info->vap_index, vap_info->u.bss_info.bssTransitionActivated);
19638 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019639 wifi_debug(DEBUG_ERROR, "wifi_setBSSTransitionActivation return error\n");
developera3511852023-06-14 14:12:59 +080019640 return RETURN_ERR;
19641 }
developer72fb0bb2023-01-11 09:46:29 +080019642
developera3511852023-06-14 14:12:59 +080019643 ret = wifi_setNeighborReportActivation(vap_info->vap_index, vap_info->u.bss_info.nbrReportActivated);
19644 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019645 wifi_debug(DEBUG_ERROR, "wifi_setNeighborReportActivation return error\n");
developera3511852023-06-14 14:12:59 +080019646 return RETURN_ERR;
19647 }
developer72fb0bb2023-01-11 09:46:29 +080019648
developera3511852023-06-14 14:12:59 +080019649 if (vap_info->u.bss_info.mac_filter_enable == false){
19650 acl_mode = 0;
19651 }else {
19652 if (vap_info->u.bss_info.mac_filter_mode == wifi_mac_filter_mode_black_list){
19653 acl_mode = 2;
developer8078acf2023-08-04 18:52:48 +080019654 res = _syscmd_secure(buf, sizeof(buf), "touch %s%d", DENY_PREFIX, vap_info->vap_index);
19655 if (res) {
19656 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19657
developere40952c2023-06-15 18:46:43 +080019658 }
developer8078acf2023-08-04 18:52:48 +080019659
developera3511852023-06-14 14:12:59 +080019660 }else{
19661 acl_mode = 1;
19662 }
19663 }
developer72fb0bb2023-01-11 09:46:29 +080019664
developera3511852023-06-14 14:12:59 +080019665 ret = wifi_setApWmmUapsdEnable(vap_info->vap_index, vap_info->u.bss_info.UAPSDEnabled);
19666 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019667 wifi_debug(DEBUG_ERROR, "wifi_setApWmmUapsdEnable return error\n");
developera3511852023-06-14 14:12:59 +080019668 return RETURN_ERR;
19669 }
developer72fb0bb2023-01-11 09:46:29 +080019670
developera3511852023-06-14 14:12:59 +080019671 memset(buf, 0, sizeof(buf));
developer32f2a182023-06-27 19:50:41 +080019672 beaconRate_enum_to_string(vap_info->u.bss_info.beaconRate, buf, sizeof(buf));
developera3511852023-06-14 14:12:59 +080019673 ret = wifi_setApBeaconRate(vap_info->radio_index, buf);
19674 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019675 wifi_debug(DEBUG_ERROR, "wifi_setApBeaconRate return error\n");
developera3511852023-06-14 14:12:59 +080019676 return RETURN_ERR;
19677 }
developer72fb0bb2023-01-11 09:46:29 +080019678
developera3511852023-06-14 14:12:59 +080019679 ret = wifi_setRadioIGMPSnoopingEnable(vap_info->radio_index, vap_info->u.bss_info.mcast2ucast);
19680 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019681 wifi_debug(DEBUG_ERROR, "wifi_setRadioIGMPSnoopingEnable\n");
developera3511852023-06-14 14:12:59 +080019682 return RETURN_ERR;
19683 }
developer72fb0bb2023-01-11 09:46:29 +080019684
developera3511852023-06-14 14:12:59 +080019685 ret = wifi_setApSecurity(vap_info->vap_index, &vap_info->u.bss_info.security);
19686 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019687 wifi_debug(DEBUG_ERROR, "wifi_setApSecurity return error\n");
developera3511852023-06-14 14:12:59 +080019688 return RETURN_ERR;
19689 }
developer333c1eb2023-05-31 14:59:39 +080019690
developer56fbedb2023-05-30 16:47:05 +080019691 hostapd_raw_restart_bss(vap_info->vap_index);
developer72fb0bb2023-01-11 09:46:29 +080019692
developera3511852023-06-14 14:12:59 +080019693 multiple_set = FALSE;
developer23e71282023-01-18 10:25:19 +080019694
developera3511852023-06-14 14:12:59 +080019695 // If config use hostapd_cli to set, we calling these type of functions after enable the ap.
19696 ret = wifi_setApMacAddressControlMode(vap_info->vap_index, acl_mode);
19697 if (ret != RETURN_OK) {
developer86035662023-06-28 19:21:12 +080019698 wifi_debug(DEBUG_ERROR, "wifi_setApMacAddressControlMode return error\n");
developera3511852023-06-14 14:12:59 +080019699 return RETURN_ERR;
19700 }
developer72fb0bb2023-01-11 09:46:29 +080019701
developer6bfd6462023-08-24 14:28:18 +080019702 ret = wifi_setApWmmEnable(vap_info->vap_index, vap_info->u.bss_info.wmm_enabled);
19703 if (ret != RETURN_OK) {
19704 wifi_debug(DEBUG_ERROR, "wifi_setApWmmEnable return error\n");
19705 return RETURN_ERR;
19706 }
19707
developer68aaecb2023-11-03 10:36:23 +080019708 ret = wifi_setApIsolationEnable(vap_info->vap_index, vap_info->u.bss_info.isolation);
19709 if (ret != RETURN_OK) {
19710 wifi_debug(DEBUG_ERROR, "wifi_setApIsolationEnable return error\n");
developer6c6ef372023-11-08 10:59:14 +080019711// return RETURN_ERR;
developer68aaecb2023-11-03 10:36:23 +080019712 }
19713
developera3511852023-06-14 14:12:59 +080019714 // TODO mgmtPowerControl, interworking, wps
19715 }
developer6c6ef372023-11-08 10:59:14 +080019716
19717 /*process mlo operation*/
19718 for (i = 0; i < map->num_vaps; i++)
19719 {
19720 vap_info = &map->vap_array[i];
19721 mld_info = &vap_info->u.bss_info.mld_info.common_info;
19722
19723 wifi_debug(DEBUG_ERROR, "process mlo operation\n");
19724 if (!mld_info->mld_enable) {
19725 wifi_debug(DEBUG_ERROR, "disable mlo on vap[%d]\n",
19726 (int)vap_info->vap_index);
19727 mld_index = mld_ap_test_all_mlds((int)vap_info->vap_index);
19728 if (mld_index) {
19729 wifi_debug(DEBUG_ERROR, "mlo disabled, remove ap(%d) from mld group(%d)\n",
19730 (int)vap_info->vap_index, (int)mld_index);
19731 if (wifi_eht_remove_from_ap_mld(mld_index, vap_info->vap_index)) {
19732 wifi_debug(DEBUG_ERROR, "fail to remove ap(%d) from mld(%d)\n",
19733 (int)vap_info->vap_index, (int)mld_index);
19734 continue;
19735 }
19736
19737 if (wifi_GetInterfaceName(vap_info->vap_index, interface_name) == RETURN_OK) {
19738 return RETURN_ERR;
19739 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
19740 if (res) {
19741 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19742 }
19743 res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up", interface_name);
19744 if (res) {
19745 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
19746 }
19747 }
19748
19749 if (wifi_eht_get_ap_from_mld(mld_index, ap_index_array, &ap_array_num)) {
19750 wifi_debug(DEBUG_ERROR,
19751 "fail to get all aps from mld(%d), destroy it.\n", mld_index);
19752 continue;
19753 }
19754
19755 if (ap_array_num == 0) {
19756 wifi_debug(DEBUG_ERROR,
19757 "there's no affiliated ap in mld(%d), destroy it.\n", mld_index);
19758 wifi_eht_destroy_ap_mld(mld_index);
19759 }
19760 }
19761 } else {
19762 if (mld_info->mld_index == 0 || mld_info->mld_index > MAX_ML_MLD_CNT) {
19763 wifi_debug(DEBUG_ERROR, "invalid mld index %d, ignore it.\n",
19764 (int)mld_info->mld_index);
19765 continue;
19766 }
19767
19768 if (!mld_test(mld_info->mld_index)) {
19769 if (wifi_eht_create_ap_mld(mld_info->mld_index, mld_info->mld_addr)) {
19770 wifi_debug(DEBUG_ERROR,
19771 "fail to create ap mld(%d)\n", mld_info->mld_index);
19772 continue;
19773 }
19774 } else {
19775 if(mld_ap_test(&(mld_config.mld[mld_info->mld_index]), vap_info->vap_index)) {
19776 wifi_debug(DEBUG_ERROR,
19777 "current vap(%d) is already the affiliated ap of mld(%d)\n",
19778 vap_info->vap_index, mld_info->mld_index);
19779 continue;
19780 }
19781 }
19782 mld_index = mld_ap_test_all_mlds(vap_info->vap_index);
19783
19784 if (mld_index != 0) {
19785 /*transfer*/
19786 wifi_eht_mld_ap_transfer(mld_index, mld_info->mld_index, vap_info->vap_index);
19787
19788 if (wifi_eht_get_ap_from_mld(mld_index, ap_index_array, &ap_array_num)) {
19789 wifi_debug(DEBUG_ERROR,
19790 "fail to get all aps from mld(%d), destroy it.\n", mld_index);
19791 continue;
19792 }
19793 if (ap_array_num == 0) {
19794 wifi_debug(DEBUG_ERROR,
19795 "there's no affiliated ap in mld(%d), destroy it.\n", mld_index);
19796 wifi_eht_destroy_ap_mld(mld_index);
19797 }
19798 } else {
19799 /*join*/
19800 wifi_eht_add_to_ap_mld(mld_info->mld_index, vap_info->vap_index);
19801 }
19802 }
19803 }
19804 mld_info_display();
19805 wifi_eht_config_sync2_dat_by_radio(index);
developera3511852023-06-14 14:12:59 +080019806 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
19807 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080019808}
19809
19810int parse_channel_list_int_arr(char *pchannels, wifi_channels_list_t* chlistptr)
19811{
developera3511852023-06-14 14:12:59 +080019812 char *token, *next;
19813 const char s[2] = ",";
19814 int count =0;
developer72fb0bb2023-01-11 09:46:29 +080019815
developera3511852023-06-14 14:12:59 +080019816 /* get the first token */
19817 token = strtok_r(pchannels, s, &next);
developer72fb0bb2023-01-11 09:46:29 +080019818
developera3511852023-06-14 14:12:59 +080019819 /* walk through other tokens */
19820 while( token != NULL && count < MAX_CHANNELS) {
19821 chlistptr->channels_list[count++] = atoi(token);
19822 token = strtok_r(NULL, s, &next);
19823 }
developer72fb0bb2023-01-11 09:46:29 +080019824
developera3511852023-06-14 14:12:59 +080019825 return count;
developer72fb0bb2023-01-11 09:46:29 +080019826}
19827
19828static int getRadioCapabilities(int radioIndex, wifi_radio_capabilities_t *rcap)
19829{
developera3511852023-06-14 14:12:59 +080019830 INT status;
19831 wifi_channels_list_t *chlistp;
19832 CHAR output_string[64];
19833 CHAR pchannels[128];
19834 CHAR interface_name[16] = {0};
19835 wifi_band band;
developere40952c2023-06-15 18:46:43 +080019836 int res;
developer72fb0bb2023-01-11 09:46:29 +080019837
developera3511852023-06-14 14:12:59 +080019838 if(rcap == NULL)
19839 {
19840 return RETURN_ERR;
19841 }
developer72fb0bb2023-01-11 09:46:29 +080019842
developera3511852023-06-14 14:12:59 +080019843 rcap->numSupportedFreqBand = 1;
19844 band = wifi_index_to_band(radioIndex);
developer72fb0bb2023-01-11 09:46:29 +080019845
developera3511852023-06-14 14:12:59 +080019846 if (band == band_2_4)
19847 rcap->band[0] = WIFI_FREQUENCY_2_4_BAND;
19848 else if (band == band_5)
19849 rcap->band[0] = WIFI_FREQUENCY_5_BAND;
19850 else if (band == band_6)
19851 rcap->band[0] = WIFI_FREQUENCY_6_BAND;
developer72fb0bb2023-01-11 09:46:29 +080019852
developera3511852023-06-14 14:12:59 +080019853 chlistp = &(rcap->channel_list[0]);
19854 memset(pchannels, 0, sizeof(pchannels));
developer72fb0bb2023-01-11 09:46:29 +080019855
developera3511852023-06-14 14:12:59 +080019856 /* possible number of radio channels */
19857 status = wifi_getRadioPossibleChannels(radioIndex, pchannels);
19858 {
19859 printf("[wifi_hal dbg] : func[%s] line[%d] error_ret[%d] radio_index[%d] output[%s]\n", __FUNCTION__, __LINE__, status, radioIndex, pchannels);
19860 }
19861 /* Number of channels and list*/
19862 chlistp->num_channels = parse_channel_list_int_arr(pchannels, chlistp);
developer72fb0bb2023-01-11 09:46:29 +080019863
developera3511852023-06-14 14:12:59 +080019864 /* autoChannelSupported */
19865 /* always ON with wifi_getRadioAutoChannelSupported */
19866 rcap->autoChannelSupported = TRUE;
developer72fb0bb2023-01-11 09:46:29 +080019867
developera3511852023-06-14 14:12:59 +080019868 /* DCSSupported */
19869 /* always ON with wifi_getRadioDCSSupported */
19870 rcap->DCSSupported = TRUE;
developer72fb0bb2023-01-11 09:46:29 +080019871
developera3511852023-06-14 14:12:59 +080019872 /* zeroDFSSupported - TBD */
19873 rcap->zeroDFSSupported = FALSE;
developer72fb0bb2023-01-11 09:46:29 +080019874
developera3511852023-06-14 14:12:59 +080019875 /* Supported Country List*/
19876 memset(output_string, 0, sizeof(output_string));
19877 status = wifi_getRadioCountryCode(radioIndex, output_string);
19878 if( status != 0 ) {
19879 printf("[wifi_hal dbg] : func[%s] line[%d] error_ret[%d] radio_index[%d] output[%s]\n", __FUNCTION__, __LINE__, status, radioIndex, output_string);
19880 return RETURN_ERR;
19881 } else {
19882 printf("[wifi_hal dbg] : func[%s] line[%d], output [%s]\n", __FUNCTION__, __LINE__, output_string);
19883 }
19884 if(!strcmp(output_string,"US")){
19885 rcap->countrySupported[0] = wifi_countrycode_US;
19886 rcap->countrySupported[1] = wifi_countrycode_CA;
19887 } else if (!strcmp(output_string,"CA")) {
19888 rcap->countrySupported[0] = wifi_countrycode_CA;
19889 rcap->countrySupported[1] = wifi_countrycode_US;
19890 } else {
19891 printf("[wifi_hal dbg] : func[%s] line[%d] radio_index[%d] Invalid Country [%s]\n", __FUNCTION__, __LINE__, radioIndex, output_string);
19892 }
developer72fb0bb2023-01-11 09:46:29 +080019893
developera3511852023-06-14 14:12:59 +080019894 rcap->numcountrySupported = 2;
developer72fb0bb2023-01-11 09:46:29 +080019895
developera3511852023-06-14 14:12:59 +080019896 /* csi */
19897 rcap->csi.maxDevices = 8;
19898 rcap->csi.soudingFrameSupported = TRUE;
developer72fb0bb2023-01-11 09:46:29 +080019899
developer86035662023-06-28 19:21:12 +080019900 if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK) {
19901 wifi_debug(DEBUG_ERROR, "wifi_GetInterfaceName fail\n");
19902 }
developere40952c2023-06-15 18:46:43 +080019903 res = snprintf(rcap->ifaceName, sizeof(interface_name), "%s",interface_name);
19904 if (os_snprintf_error(sizeof(interface_name), res)) {
19905 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
19906 return RETURN_ERR;
19907 }
developer72fb0bb2023-01-11 09:46:29 +080019908
developera3511852023-06-14 14:12:59 +080019909 /* channelWidth - all supported bandwidths */
19910 int i=0;
19911 rcap->channelWidth[i] = 0;
19912 if (rcap->band[i] & WIFI_FREQUENCY_2_4_BAND) {
19913 rcap->channelWidth[i] |= (WIFI_CHANNELBANDWIDTH_20MHZ |
19914 WIFI_CHANNELBANDWIDTH_40MHZ);
developer72fb0bb2023-01-11 09:46:29 +080019915
developera3511852023-06-14 14:12:59 +080019916 }
19917 else if (rcap->band[i] & (WIFI_FREQUENCY_5_BAND ) || rcap->band[i] & (WIFI_FREQUENCY_6_BAND)) {
19918 rcap->channelWidth[i] |= (WIFI_CHANNELBANDWIDTH_20MHZ |
19919 WIFI_CHANNELBANDWIDTH_40MHZ |
19920 WIFI_CHANNELBANDWIDTH_80MHZ | WIFI_CHANNELBANDWIDTH_160MHZ);
19921 }
developer72fb0bb2023-01-11 09:46:29 +080019922
19923
developera3511852023-06-14 14:12:59 +080019924 /* mode - all supported variants */
19925 // rcap->mode[i] = WIFI_80211_VARIANT_H;
19926 if (rcap->band[i] & WIFI_FREQUENCY_2_4_BAND ) {
19927 rcap->mode[i] = ( WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX );
19928 }
19929 else if (rcap->band[i] & WIFI_FREQUENCY_5_BAND ) {
19930 rcap->mode[i] = ( WIFI_80211_VARIANT_A | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX );
19931 }
19932 else if (rcap->band[i] & WIFI_FREQUENCY_6_BAND) {
19933 rcap->mode[i] = ( WIFI_80211_VARIANT_AX );
19934 }
19935 rcap->maxBitRate[i] = ( rcap->band[i] & WIFI_FREQUENCY_2_4_BAND ) ? 300 :
19936 ((rcap->band[i] & WIFI_FREQUENCY_5_BAND) ? 1734 : 0);
developer72fb0bb2023-01-11 09:46:29 +080019937
developera3511852023-06-14 14:12:59 +080019938 /* supportedBitRate - all supported bitrates */
19939 rcap->supportedBitRate[i] = 0;
19940 if (rcap->band[i] & WIFI_FREQUENCY_2_4_BAND) {
19941 rcap->supportedBitRate[i] |= (WIFI_BITRATE_6MBPS | WIFI_BITRATE_9MBPS |
19942 WIFI_BITRATE_11MBPS | WIFI_BITRATE_12MBPS);
19943 }
19944 else if ((rcap->band[i] & (WIFI_FREQUENCY_5_BAND )) || (rcap->band[i] & (WIFI_FREQUENCY_6_BAND))) {
19945 rcap->supportedBitRate[i] |= (WIFI_BITRATE_6MBPS | WIFI_BITRATE_9MBPS |
19946 WIFI_BITRATE_12MBPS | WIFI_BITRATE_18MBPS | WIFI_BITRATE_24MBPS |
19947 WIFI_BITRATE_36MBPS | WIFI_BITRATE_48MBPS | WIFI_BITRATE_54MBPS);
19948 }
developer72fb0bb2023-01-11 09:46:29 +080019949
19950
developera3511852023-06-14 14:12:59 +080019951 rcap->transmitPowerSupported_list[i].numberOfElements = 5;
19952 rcap->transmitPowerSupported_list[i].transmitPowerSupported[0]=12;
19953 rcap->transmitPowerSupported_list[i].transmitPowerSupported[1]=25;
19954 rcap->transmitPowerSupported_list[i].transmitPowerSupported[2]=50;
19955 rcap->transmitPowerSupported_list[i].transmitPowerSupported[3]=75;
19956 rcap->transmitPowerSupported_list[i].transmitPowerSupported[4]=100;
19957 rcap->cipherSupported = 0;
19958 rcap->cipherSupported |= WIFI_CIPHER_CAPA_ENC_TKIP | WIFI_CIPHER_CAPA_ENC_CCMP;
19959 rcap->maxNumberVAPs = MAX_NUM_VAP_PER_RADIO;
developer72fb0bb2023-01-11 09:46:29 +080019960
developera3511852023-06-14 14:12:59 +080019961 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080019962}
19963
19964INT wifi_getHalCapability(wifi_hal_capability_t *cap)
19965{
developera3511852023-06-14 14:12:59 +080019966 INT status = 0, radioIndex = 0;
19967 char output[MAX_BUF_SIZE] = {0};
19968 int iter = 0;
19969 unsigned int j = 0;
developer9ce44382023-06-28 11:09:37 +080019970 int max_num_radios = 0;
developera3511852023-06-14 14:12:59 +080019971 wifi_interface_name_idex_map_t *iface_info = NULL;
developer72fb0bb2023-01-11 09:46:29 +080019972
developera3511852023-06-14 14:12:59 +080019973 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080019974
developera3511852023-06-14 14:12:59 +080019975 memset(cap, 0, sizeof(wifi_hal_capability_t));
developer72fb0bb2023-01-11 09:46:29 +080019976
developera3511852023-06-14 14:12:59 +080019977 /* version */
19978 cap->version.major = WIFI_HAL_MAJOR_VERSION;
19979 cap->version.minor = WIFI_HAL_MINOR_VERSION;
developer72fb0bb2023-01-11 09:46:29 +080019980
developera3511852023-06-14 14:12:59 +080019981 /* number of radios platform property */
19982 wifi_getMaxRadioNumber(&max_num_radios);
19983 cap->wifi_prop.numRadios = max_num_radios;
developer72fb0bb2023-01-11 09:46:29 +080019984
developera3511852023-06-14 14:12:59 +080019985 for(radioIndex=0; radioIndex < cap->wifi_prop.numRadios; radioIndex++)
19986 {
19987 status = getRadioCapabilities(radioIndex, &(cap->wifi_prop.radiocap[radioIndex]));
19988 if (status != 0) {
19989 printf("%s: getRadioCapabilities idx = %d\n", __FUNCTION__, radioIndex);
19990 return RETURN_ERR;
19991 }
developer72fb0bb2023-01-11 09:46:29 +080019992
developera3511852023-06-14 14:12:59 +080019993 for (j = 0; j < cap->wifi_prop.radiocap[radioIndex].maxNumberVAPs; j++)
19994 {
19995 if (iter >= MAX_NUM_RADIOS * MAX_NUM_VAP_PER_RADIO)
19996 {
19997 printf("%s: to many vaps for index map (%d)\n", __func__, iter);
19998 return RETURN_ERR;
19999 }
20000 iface_info = &cap->wifi_prop.interface_map[iter];
20001 iface_info->phy_index = radioIndex; // XXX: parse phyX index instead
20002 iface_info->rdk_radio_index = radioIndex;
20003 memset(output, 0, sizeof(output));
20004 if (wifi_getRadioIfName(radioIndex, output) == RETURN_OK)
20005 {
20006 strncpy(iface_info->interface_name, output, sizeof(iface_info->interface_name) - 1);
20007 }
20008 // TODO: bridge name
20009 // TODO: vlan id
20010 // TODO: primary
20011 iface_info->index = array_index_to_vap_index(radioIndex, j);
20012 memset(output, 0, sizeof(output));
20013 if (wifi_getApName(iface_info->index, output) == RETURN_OK)
20014 {
20015 strncpy(iface_info->vap_name, output, sizeof(iface_info->vap_name) - 1);
20016 }
20017 iter++;
20018 }
20019 }
developer72fb0bb2023-01-11 09:46:29 +080020020
developera3511852023-06-14 14:12:59 +080020021 cap->BandSteeringSupported = FALSE;
20022 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
20023 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020024}
20025
20026INT wifi_setOpportunisticKeyCaching(int ap_index, BOOL okc_enable)
20027{
developera3511852023-06-14 14:12:59 +080020028 struct params h_config={0};
20029 char config_file[64] = {0};
developere40952c2023-06-15 18:46:43 +080020030 int res;
developer72fb0bb2023-01-11 09:46:29 +080020031
developera3511852023-06-14 14:12:59 +080020032 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020033
developera3511852023-06-14 14:12:59 +080020034 h_config.name = "okc";
20035 h_config.value = okc_enable?"1":"0";
developer72fb0bb2023-01-11 09:46:29 +080020036
developere40952c2023-06-15 18:46:43 +080020037 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
20038 if (os_snprintf_error(sizeof(config_file), res)) {
20039 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20040 return RETURN_ERR;
20041 }
developera3511852023-06-14 14:12:59 +080020042 wifi_hostapdWrite(config_file, &h_config, 1);
20043 wifi_hostapdProcessUpdate(ap_index, &h_config, 1);
developer72fb0bb2023-01-11 09:46:29 +080020044
developera3511852023-06-14 14:12:59 +080020045 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
20046 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020047}
20048
20049INT wifi_setSAEMFP(int ap_index, BOOL enable)
20050{
developera3511852023-06-14 14:12:59 +080020051 struct params h_config={0};
20052 char config_file[64] = {0};
developere40952c2023-06-15 18:46:43 +080020053 int res;
developer72fb0bb2023-01-11 09:46:29 +080020054
developera3511852023-06-14 14:12:59 +080020055 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020056
developera3511852023-06-14 14:12:59 +080020057 h_config.name = "sae_require_mfp";
20058 h_config.value = enable?"1":"0";
developer72fb0bb2023-01-11 09:46:29 +080020059
developere40952c2023-06-15 18:46:43 +080020060 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
20061 if (os_snprintf_error(sizeof(config_file), res)) {
20062 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20063 return RETURN_ERR;
20064 }
developera3511852023-06-14 14:12:59 +080020065 wifi_hostapdWrite(config_file, &h_config, 1);
20066 wifi_hostapdProcessUpdate(ap_index, &h_config, 1);
developer72fb0bb2023-01-11 09:46:29 +080020067
developera3511852023-06-14 14:12:59 +080020068 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
20069 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020070}
20071
20072INT wifi_setSAEpwe(int ap_index, int sae_pwe)
20073{
developera3511852023-06-14 14:12:59 +080020074 struct params h_config={0};
20075 char config_file[64] = {0};
20076 char buf[128] = {0};
developere40952c2023-06-15 18:46:43 +080020077 int res;
developer72fb0bb2023-01-11 09:46:29 +080020078
developera3511852023-06-14 14:12:59 +080020079 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020080
developera3511852023-06-14 14:12:59 +080020081 h_config.name = "sae_pwe";
developere40952c2023-06-15 18:46:43 +080020082 res = snprintf(buf, sizeof(buf), "%d", sae_pwe);
20083 if (os_snprintf_error(sizeof(buf), res)) {
20084 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20085 return RETURN_ERR;
20086 }
20087
developera3511852023-06-14 14:12:59 +080020088 h_config.value = buf;
developer72fb0bb2023-01-11 09:46:29 +080020089
developere40952c2023-06-15 18:46:43 +080020090 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
20091 if (os_snprintf_error(sizeof(config_file), res)) {
20092 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20093 return RETURN_ERR;
20094 }
developera3511852023-06-14 14:12:59 +080020095 wifi_hostapdWrite(config_file, &h_config, 1);
20096 wifi_hostapdProcessUpdate(ap_index, &h_config, 1);
developer72fb0bb2023-01-11 09:46:29 +080020097
developera3511852023-06-14 14:12:59 +080020098 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
20099 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020100}
20101
20102INT wifi_setDisable_EAPOL_retries(int ap_index, BOOL disable_EAPOL_retries)
20103{
developera3511852023-06-14 14:12:59 +080020104 // wpa3 use SAE instead of PSK, so we need to disable this feature when using wpa3.
20105 struct params h_config={0};
20106 char config_file[64] = {0};
developere40952c2023-06-15 18:46:43 +080020107 int res;
developer72fb0bb2023-01-11 09:46:29 +080020108
developera3511852023-06-14 14:12:59 +080020109 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020110
developera3511852023-06-14 14:12:59 +080020111 h_config.name = "wpa_disable_eapol_key_retries";
20112 h_config.value = disable_EAPOL_retries?"1":"0";
developer72fb0bb2023-01-11 09:46:29 +080020113
developere40952c2023-06-15 18:46:43 +080020114 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
20115 if (os_snprintf_error(sizeof(config_file), res)) {
20116 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20117 return RETURN_ERR;
20118 }
developera3511852023-06-14 14:12:59 +080020119 wifi_hostapdWrite(config_file, &h_config, 1);
20120 wifi_hostapdProcessUpdate(ap_index, &h_config, 1);
developer72fb0bb2023-01-11 09:46:29 +080020121
developera3511852023-06-14 14:12:59 +080020122 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
20123 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020124}
20125
20126INT wifi_setApSecurity(INT ap_index, wifi_vap_security_t *security)
20127{
developera3511852023-06-14 14:12:59 +080020128 char buf[128] = {0};
20129 char config_file[128] = {0};
developer8078acf2023-08-04 18:52:48 +080020130
developera3511852023-06-14 14:12:59 +080020131 char password[65] = {0};
20132 char mfp[32] = {0};
20133 char wpa_mode[32] = {0};
20134 BOOL okc_enable = FALSE;
20135 BOOL sae_MFP = FALSE;
20136 BOOL disable_EAPOL_retries = TRUE;
20137 int sae_pwe = 0;
20138 struct params params = {0};
20139 wifi_band band = band_invalid;
developere40952c2023-06-15 18:46:43 +080020140 int res;
developer72fb0bb2023-01-11 09:46:29 +080020141
developera3511852023-06-14 14:12:59 +080020142 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020143
developera3511852023-06-14 14:12:59 +080020144 multiple_set = TRUE;
developer37646972023-06-29 10:58:43 +080020145 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
20146 if (os_snprintf_error(sizeof(config_file), res)) {
20147 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20148 return RETURN_ERR;
20149 }
developera3511852023-06-14 14:12:59 +080020150 if (security->mode == wifi_security_mode_none) {
developer9ce44382023-06-28 11:09:37 +080020151 strncpy(wpa_mode, "None",sizeof(wpa_mode) - 1);
20152 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20153 } else if (security->mode == wifi_security_mode_wpa_personal) {
20154 strncpy(wpa_mode, "WPA-Personal",sizeof(wpa_mode) - 1);
20155 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20156 } else if (security->mode == wifi_security_mode_wpa2_personal){
20157 strncpy(wpa_mode, "WPA2-Personal",sizeof(wpa_mode) - 1);
20158 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20159 } else if (security->mode == wifi_security_mode_wpa_wpa2_personal){
20160 strncpy(wpa_mode, "WPA-WPA2-Personal",sizeof(wpa_mode) - 1);
20161 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20162 } else if (security->mode == wifi_security_mode_wpa_enterprise){
20163 strncpy(wpa_mode, "WPA-Enterprise",sizeof(wpa_mode) - 1);
20164 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20165 } else if (security->mode == wifi_security_mode_wpa2_enterprise){
20166 strncpy(wpa_mode, "WPA2-Enterprise",sizeof(wpa_mode) - 1);
20167 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20168 } else if (security->mode == wifi_security_mode_wpa_wpa2_enterprise){
20169 strncpy(wpa_mode, "WPA-WAP2-Enterprise",sizeof(wpa_mode) - 1);
20170 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
20171 } else if (security->mode == wifi_security_mode_wpa3_personal) {
20172 strncpy(wpa_mode, "WPA3-Personal",sizeof(wpa_mode) - 1);
20173 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
developera3511852023-06-14 14:12:59 +080020174 okc_enable = TRUE;
20175 sae_MFP = TRUE;
20176 sae_pwe = 2;
20177 disable_EAPOL_retries = FALSE;
20178 } else if (security->mode == wifi_security_mode_wpa3_transition) {
developer9ce44382023-06-28 11:09:37 +080020179 strncpy(wpa_mode, "WPA3-Personal-Transition",sizeof(wpa_mode) - 1);
20180 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
developera3511852023-06-14 14:12:59 +080020181 okc_enable = TRUE;
20182 sae_MFP = TRUE;
20183 sae_pwe = 2;
20184 disable_EAPOL_retries = FALSE;
20185 } else if (security->mode == wifi_security_mode_wpa3_enterprise) {
developer9ce44382023-06-28 11:09:37 +080020186 strncpy(wpa_mode, "WPA3-Enterprise",sizeof(wpa_mode) - 1);
20187 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
developera3511852023-06-14 14:12:59 +080020188 sae_MFP = TRUE;
20189 sae_pwe = 2;
20190 disable_EAPOL_retries = FALSE;
20191 } else if (security->mode == wifi_security_mode_enhanced_open) {
developer9ce44382023-06-28 11:09:37 +080020192 strncpy(wpa_mode, "OWE",sizeof(wpa_mode) - 1);
20193 wpa_mode[sizeof(wpa_mode) - 1] = '\0';
developera3511852023-06-14 14:12:59 +080020194 sae_MFP = TRUE;
20195 sae_pwe = 2;
20196 disable_EAPOL_retries = FALSE;
20197 }
developer72fb0bb2023-01-11 09:46:29 +080020198
developera3511852023-06-14 14:12:59 +080020199 band = wifi_index_to_band(ap_index);
20200 if (band == band_6 && strstr(wpa_mode, "WPA3") == NULL) {
developerc14d83a2023-06-29 20:09:42 +080020201 wifi_debug(DEBUG_ERROR, "%s: 6G band must set with wpa3.\n", __func__);
developera3511852023-06-14 14:12:59 +080020202 return RETURN_ERR;
20203 }
developer72fb0bb2023-01-11 09:46:29 +080020204
developera3511852023-06-14 14:12:59 +080020205 wifi_setApSecurityModeEnabled(ap_index, wpa_mode);
20206 wifi_setOpportunisticKeyCaching(ap_index, okc_enable);
20207 wifi_setSAEMFP(ap_index, sae_MFP);
20208 wifi_setSAEpwe(ap_index, sae_pwe);
20209 wifi_setDisable_EAPOL_retries(ap_index, disable_EAPOL_retries);
developer72fb0bb2023-01-11 09:46:29 +080020210
developera3511852023-06-14 14:12:59 +080020211 if (security->mode != wifi_security_mode_none && security->mode != wifi_security_mode_enhanced_open) {
20212 if (security->u.key.type == wifi_security_key_type_psk || security->u.key.type == wifi_security_key_type_pass || security->u.key.type == wifi_security_key_type_psk_sae) {
20213 int key_len = strlen(security->u.key.key);
20214 // wpa_psk and wpa_passphrase cann;t use at the same time, the command replace one with the other.
20215 if (key_len == 64) { // set wpa_psk
20216 strncpy(password, security->u.key.key, 64); // 64 characters
20217 password[64] = '\0';
20218 wifi_setApSecurityPreSharedKey(ap_index, password);
developer8078acf2023-08-04 18:52:48 +080020219 res = _syscmd_secure(buf, sizeof(buf), "sed -i -n -e '/^wpa_passphrase=/!p' %s", config_file);
20220 if (res) {
20221 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
20222
developere40952c2023-06-15 18:46:43 +080020223 }
developera3511852023-06-14 14:12:59 +080020224 } else if (key_len >= 8 && key_len < 64) { // set wpa_passphrase
20225 strncpy(password, security->u.key.key, 63);
20226 password[63] = '\0';
20227 wifi_setApSecurityKeyPassphrase(ap_index, password);
developer8078acf2023-08-04 18:52:48 +080020228 res = _syscmd_secure(buf, sizeof(buf), "sed -i -n -e '/^wpa_psk=/!p' %s", config_file);
20229 if (res) {
20230 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
20231
developer9ce44382023-06-28 11:09:37 +080020232 }
developera3511852023-06-14 14:12:59 +080020233 } else
20234 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080020235
developera3511852023-06-14 14:12:59 +080020236 }
20237 if (security->u.key.type == wifi_security_key_type_sae || security->u.key.type == wifi_security_key_type_psk_sae) {
20238 params.name = "sae_password";
20239 params.value = security->u.key.key;
20240 wifi_hostapdWrite(config_file, &params, 1);
20241 } else { // remove sae_password
developer8078acf2023-08-04 18:52:48 +080020242 res = _syscmd_secure(buf, sizeof(buf), "sed -i -n -e '/^sae_password=/!p' %s", config_file);
20243 if (res) {
20244 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
20245
developere40952c2023-06-15 18:46:43 +080020246 }
developera3511852023-06-14 14:12:59 +080020247 }
20248 }
developer72fb0bb2023-01-11 09:46:29 +080020249
developera3511852023-06-14 14:12:59 +080020250 if (security->mode != wifi_security_mode_none) {
20251 memset(&params, 0, sizeof(params));
20252 params.name = "wpa_pairwise";
20253 if (security->encr == wifi_encryption_tkip)
20254 params.value = "TKIP";
20255 else if (security->encr == wifi_encryption_aes)
20256 params.value = "CCMP";
20257 else if (security->encr == wifi_encryption_aes_tkip)
20258 params.value = "TKIP CCMP";
20259 wifi_hostapdWrite(config_file, &params, 1);
20260 }
developer72fb0bb2023-01-11 09:46:29 +080020261
developer9ce44382023-06-28 11:09:37 +080020262 if (security->mfp == wifi_mfp_cfg_disabled){
20263 strncpy(mfp,"Disabled",sizeof(mfp)-1);
20264 mfp[sizeof(mfp)-1] = '\0';
20265 } else if (security->mfp == wifi_mfp_cfg_optional){
20266 strncpy(mfp,"Optional",sizeof(mfp)-1);
20267 mfp[sizeof(mfp)-1] = '\0';
20268 } else if (security->mfp == wifi_mfp_cfg_required){
20269 strncpy(mfp,"Required",sizeof(mfp)-1);
20270 mfp[sizeof(mfp)-1] = '\0';
20271 }
developera3511852023-06-14 14:12:59 +080020272 wifi_setApSecurityMFPConfig(ap_index, mfp);
developer72fb0bb2023-01-11 09:46:29 +080020273
developera3511852023-06-14 14:12:59 +080020274 memset(&params, 0, sizeof(params));
20275 params.name = "transition_disable";
20276 if (security->wpa3_transition_disable == TRUE)
20277 params.value = "0x01";
20278 else
20279 params.value = "0x00";
20280 wifi_hostapdWrite(config_file, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +080020281
developera3511852023-06-14 14:12:59 +080020282 memset(&params, 0, sizeof(params));
20283 params.name = "wpa_group_rekey";
developere40952c2023-06-15 18:46:43 +080020284 res = snprintf(buf, sizeof(buf), "%d", security->rekey_interval);
20285 if (os_snprintf_error(sizeof(buf), res)) {
20286 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20287 return RETURN_ERR;
20288 }
developera3511852023-06-14 14:12:59 +080020289 params.value = buf;
20290 wifi_hostapdWrite(config_file, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +080020291
developera3511852023-06-14 14:12:59 +080020292 memset(&params, 0, sizeof(params));
20293 params.name = "wpa_strict_rekey";
20294 params.value = security->strict_rekey?"1":"0";
20295 wifi_hostapdWrite(config_file, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +080020296
developera3511852023-06-14 14:12:59 +080020297 memset(&params, 0, sizeof(params));
20298 params.name = "wpa_pairwise_update_count";
20299 if (security->eapol_key_retries == 0)
20300 security->eapol_key_retries = 4; // 0 is invalid, set to default value.
developere40952c2023-06-15 18:46:43 +080020301 res = snprintf(buf, sizeof(buf), "%u", security->eapol_key_retries);
20302 if (os_snprintf_error(sizeof(buf), res)) {
20303 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20304 return RETURN_ERR;
20305 }
developera3511852023-06-14 14:12:59 +080020306 params.value = buf;
20307 wifi_hostapdWrite(config_file, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +080020308
developera3511852023-06-14 14:12:59 +080020309 memset(&params, 0, sizeof(params));
20310 params.name = "disable_pmksa_caching";
20311 params.value = security->disable_pmksa_caching?"1":"0";
20312 wifi_hostapdWrite(config_file, &params, 1);
developer72fb0bb2023-01-11 09:46:29 +080020313
developera3511852023-06-14 14:12:59 +080020314 if (multiple_set == FALSE) {
20315 wifi_setApEnable(ap_index, FALSE);
20316 wifi_setApEnable(ap_index, TRUE);
20317 }
developer72fb0bb2023-01-11 09:46:29 +080020318
developera3511852023-06-14 14:12:59 +080020319 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020320
developera3511852023-06-14 14:12:59 +080020321 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020322}
20323
20324INT wifi_getApSecurity(INT ap_index, wifi_vap_security_t *security)
20325{
developera3511852023-06-14 14:12:59 +080020326 char buf[256] = {0};
20327 char config_file[128] = {0};
developer86035662023-06-28 19:21:12 +080020328 long int disable = 0;
20329 long int tmp;
developera3511852023-06-14 14:12:59 +080020330 bool set_sae = FALSE;
developere75ba632023-06-29 16:03:33 +080020331 int res;
developer72fb0bb2023-01-11 09:46:29 +080020332
developera3511852023-06-14 14:12:59 +080020333 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developere75ba632023-06-29 16:03:33 +080020334 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
20335 if (os_snprintf_error(sizeof(config_file), res)) {
20336 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20337 return RETURN_ERR;
20338 }
developera3511852023-06-14 14:12:59 +080020339 wifi_getApSecurityModeEnabled(ap_index, buf); // Get wpa config
20340 security->mode = wifi_security_mode_none;
20341 if (strlen(buf) != 0) {
20342 if (!strcmp(buf, "WPA-Personal"))
20343 security->mode = wifi_security_mode_wpa_personal;
20344 else if (!strcmp(buf, "WPA2-Personal"))
20345 security->mode = wifi_security_mode_wpa2_personal;
20346 else if (!strcmp(buf, "WPA-WPA2-Personal"))
20347 security->mode = wifi_security_mode_wpa_wpa2_personal;
20348 else if (!strcmp(buf, "WPA-Enterprise"))
20349 security->mode = wifi_security_mode_wpa_enterprise;
20350 else if (!strcmp(buf, "WPA2-Enterprise"))
20351 security->mode = wifi_security_mode_wpa2_enterprise;
20352 else if (!strcmp(buf, "WPA-WPA2-Enterprise"))
20353 security->mode = wifi_security_mode_wpa_wpa2_enterprise;
20354 else if (!strcmp(buf, "WPA3-Personal"))
20355 security->mode = wifi_security_mode_wpa3_personal;
20356 else if (!strcmp(buf, "WPA3-Personal-Transition"))
20357 security->mode = wifi_security_mode_wpa3_transition;
20358 else if (!strcmp(buf, "WPA3-Enterprise"))
20359 security->mode = wifi_security_mode_wpa3_enterprise;
20360 else if (!strcmp(buf, "OWE"))
20361 security->mode = wifi_security_mode_enhanced_open;
20362 }
developer72fb0bb2023-01-11 09:46:29 +080020363
developera3511852023-06-14 14:12:59 +080020364 wifi_hostapdRead(config_file,"wpa_pairwise",buf,sizeof(buf));
20365 if (security->mode == wifi_security_mode_none)
20366 security->encr = wifi_encryption_none;
20367 else {
20368 if (strcmp(buf, "TKIP") == 0)
20369 security->encr = wifi_encryption_tkip;
20370 else if (strcmp(buf, "CCMP") == 0)
20371 security->encr = wifi_encryption_aes;
20372 else
20373 security->encr = wifi_encryption_aes_tkip;
20374 }
developer72fb0bb2023-01-11 09:46:29 +080020375
developera3511852023-06-14 14:12:59 +080020376 if (security->mode != wifi_security_mode_none) {
20377 memset(buf, 0, sizeof(buf));
20378 // wpa3 can use one or both configs as password, so we check sae_password first.
20379 wifi_hostapdRead(config_file, "sae_password", buf, sizeof(buf));
20380 if (strlen(buf) != 0) {
20381 if (security->mode == wifi_security_mode_wpa3_personal || security->mode == wifi_security_mode_wpa3_transition)
20382 security->u.key.type = wifi_security_key_type_sae;
20383 set_sae = TRUE;
20384 strncpy(security->u.key.key, buf, sizeof(buf));
20385 }
20386 wifi_hostapdRead(config_file, "wpa_passphrase", buf, sizeof(buf));
20387 if (strlen(buf) != 0){
20388 if (set_sae == TRUE)
20389 security->u.key.type = wifi_security_key_type_psk_sae;
20390 else if (strlen(buf) == 64)
20391 security->u.key.type = wifi_security_key_type_psk;
20392 else
20393 security->u.key.type = wifi_security_key_type_pass;
20394 strncpy(security->u.key.key, buf, sizeof(security->u.key.key));
20395 }
20396 security->u.key.key[255] = '\0';
20397 }
developer72fb0bb2023-01-11 09:46:29 +080020398
developera3511852023-06-14 14:12:59 +080020399 memset(buf, 0, sizeof(buf));
20400 wifi_getApSecurityMFPConfig(ap_index, buf);
20401 if (strcmp(buf, "Disabled") == 0)
20402 security->mfp = wifi_mfp_cfg_disabled;
20403 else if (strcmp(buf, "Optional") == 0)
20404 security->mfp = wifi_mfp_cfg_optional;
20405 else if (strcmp(buf, "Required") == 0)
20406 security->mfp = wifi_mfp_cfg_required;
developer72fb0bb2023-01-11 09:46:29 +080020407
developera3511852023-06-14 14:12:59 +080020408 memset(buf, 0, sizeof(buf));
20409 security->wpa3_transition_disable = FALSE;
20410 wifi_hostapdRead(config_file, "transition_disable", buf, sizeof(buf));
developer3de255a2023-06-29 10:35:45 +080020411 if (strlen(buf) == 0)
20412 disable = 0;
20413 else {
20414 if (hal_strtol(buf, 16, &disable) < 0) {
20415 wifi_debug(DEBUG_ERROR, "strtol fail\n");
20416 return RETURN_ERR;
20417 }
developer86035662023-06-28 19:21:12 +080020418 }
developera3511852023-06-14 14:12:59 +080020419 if (disable != 0)
20420 security->wpa3_transition_disable = TRUE;
developer72fb0bb2023-01-11 09:46:29 +080020421
developera3511852023-06-14 14:12:59 +080020422 memset(buf, 0, sizeof(buf));
20423 wifi_hostapdRead(config_file, "wpa_group_rekey", buf, sizeof(buf));
20424 if (strlen(buf) == 0)
20425 security->rekey_interval = 86400;
developer86035662023-06-28 19:21:12 +080020426 else {
20427 if (hal_strtol(buf, 10, &tmp) < 0) {
20428 wifi_debug(DEBUG_ERROR, "strtol fail\n");
20429 return RETURN_ERR;
20430 }
20431 security->rekey_interval = tmp;
20432 }
developer72fb0bb2023-01-11 09:46:29 +080020433
developera3511852023-06-14 14:12:59 +080020434 memset(buf, 0, sizeof(buf));
20435 wifi_hostapdRead(config_file, "wpa_strict_rekey", buf, sizeof(buf));
20436 if (strlen(buf) == 0)
20437 security->strict_rekey = 1;
developer86035662023-06-28 19:21:12 +080020438 else {
20439 if (hal_strtol(buf, 10, &tmp) < 0) {
20440 wifi_debug(DEBUG_ERROR, "strtol fail\n");
20441 return RETURN_ERR;
20442 }
20443 security->strict_rekey = tmp;
20444 }
developer72fb0bb2023-01-11 09:46:29 +080020445
developera3511852023-06-14 14:12:59 +080020446 memset(buf, 0, sizeof(buf));
20447 wifi_hostapdRead(config_file, "wpa_pairwise_update_count", buf, sizeof(buf));
20448 if (strlen(buf) == 0)
20449 security->eapol_key_retries = 4;
developer86035662023-06-28 19:21:12 +080020450 else {
20451 if (hal_strtol(buf, 10, &tmp) < 0) {
20452 wifi_debug(DEBUG_ERROR, "strtol fail\n");
20453 return RETURN_ERR;
20454 }
20455 security->eapol_key_retries = tmp;
20456 }
developer72fb0bb2023-01-11 09:46:29 +080020457
developera3511852023-06-14 14:12:59 +080020458 memset(buf, 0, sizeof(buf));
20459 wifi_hostapdRead(config_file, "disable_pmksa_caching", buf, sizeof(buf));
20460 if (strlen(buf) == 0)
20461 security->disable_pmksa_caching = FALSE;
developer86035662023-06-28 19:21:12 +080020462 else {
20463 if (hal_strtol(buf, 10, &(tmp)) < 0) {
20464 wifi_debug(DEBUG_ERROR, "strtol fail\n");
20465 return RETURN_ERR;
20466 }
20467 security->disable_pmksa_caching = tmp ? TRUE : FALSE;
20468 }
developera3511852023-06-14 14:12:59 +080020469 /* TODO
20470 eapol_key_timeout, eap_identity_req_timeout, eap_identity_req_retries, eap_req_timeout, eap_req_retries
20471 */
20472 security->eapol_key_timeout = 1000; // Unit is ms. The default value in protocol.
20473 security->eap_identity_req_timeout = 0;
20474 security->eap_identity_req_retries = 0;
20475 security->eap_req_timeout = 0;
20476 security->eap_req_retries = 0;
20477 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
20478 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020479}
20480
20481#endif /* WIFI_HAL_VERSION_3 */
20482
20483#ifdef WIFI_HAL_VERSION_3_PHASE2
20484INT wifi_getApAssociatedDevice(INT ap_index, mac_address_t *output_deviceMacAddressArray, UINT maxNumDevices, UINT *output_numDevices)
20485{
developera3511852023-06-14 14:12:59 +080020486 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +080020487
developera3511852023-06-14 14:12:59 +080020488 char buf[128] = {0};
20489 char *mac_addr = NULL;
20490 BOOL status = FALSE;
20491 size_t len = 0;
developer8078acf2023-08-04 18:52:48 +080020492 int res;
developer72fb0bb2023-01-11 09:46:29 +080020493
developera3511852023-06-14 14:12:59 +080020494 if(ap_index > MAX_APS)
20495 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080020496
developera3511852023-06-14 14:12:59 +080020497 *output_numDevices = 0;
20498 wifi_getApEnable(ap_index, &status);
20499 if (status == FALSE)
20500 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020501
developera3511852023-06-14 14:12:59 +080020502 if (wifi_GetInterfaceName(ap_index, interface_name) != RETURN_OK)
20503 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080020504
20505 _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s list_sta", interface_name);
20506 if (res) {
20507 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
20508 }
developer72fb0bb2023-01-11 09:46:29 +080020509
developera3511852023-06-14 14:12:59 +080020510 mac_addr = strtok(buf, "\n");
20511 for (int i = 0; i < maxNumDevices && mac_addr != NULL; i++) {
20512 *output_numDevices = i + 1;
developerc14d83a2023-06-29 20:09:42 +080020513 wifi_debug(DEBUG_ERROR,, "mac_addr: %s\n", mac_addr);
developera3511852023-06-14 14:12:59 +080020514 addr_ptr = output_deviceMacAddressArray[i];
20515 mac_addr_aton(addr_ptr, mac_addr);
20516 mac_addr = strtok(NULL, "\n");
20517 }
developer72fb0bb2023-01-11 09:46:29 +080020518
developera3511852023-06-14 14:12:59 +080020519 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020520}
20521#else
20522INT wifi_getApAssociatedDevice(INT ap_index, CHAR *output_buf, INT output_buf_size)
20523{
developera3511852023-06-14 14:12:59 +080020524 char interface_name[16] = {0};
developer8078acf2023-08-04 18:52:48 +080020525
developera3511852023-06-14 14:12:59 +080020526 BOOL status = false;
developer75bd10c2023-06-27 11:34:08 +080020527 int res;
developer72fb0bb2023-01-11 09:46:29 +080020528
developera3511852023-06-14 14:12:59 +080020529 if(ap_index > MAX_APS || output_buf == NULL || output_buf_size <= 0)
20530 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080020531
developera3511852023-06-14 14:12:59 +080020532 output_buf[0] = '\0';
developer72fb0bb2023-01-11 09:46:29 +080020533
developera3511852023-06-14 14:12:59 +080020534 wifi_getApEnable(ap_index,&status);
20535 if (!status)
20536 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020537
developera3511852023-06-14 14:12:59 +080020538 if (wifi_GetInterfaceName(ap_index, interface_name) != RETURN_OK)
20539 return RETURN_ERR;
developer8078acf2023-08-04 18:52:48 +080020540 res = _syscmd_secure(output_buf, output_buf_size, "hostapd_cli -i %s list_sta | tr '\\n' ',' | sed 's/.$//'", interface_name);
20541 if (res) {
20542 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
20543
developer75bd10c2023-06-27 11:34:08 +080020544 }
developer5b23cd02023-07-19 20:26:03 +080020545
developer8078acf2023-08-04 18:52:48 +080020546
developer69b61b02023-03-07 17:17:44 +080020547
developera3511852023-06-14 14:12:59 +080020548 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020549}
20550#endif
20551
20552INT wifi_getProxyArp(INT apIndex, BOOL *enable)
20553{
developera3511852023-06-14 14:12:59 +080020554 char output[16]={'\0'};
20555 char config_file[MAX_BUF_SIZE] = {0};
developer75bd10c2023-06-27 11:34:08 +080020556 int res;
developer72fb0bb2023-01-11 09:46:29 +080020557
developera3511852023-06-14 14:12:59 +080020558 if (!enable)
20559 return RETURN_ERR;
developer72fb0bb2023-01-11 09:46:29 +080020560
developer75bd10c2023-06-27 11:34:08 +080020561 res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
20562 if (os_snprintf_error(sizeof(config_file), res)) {
20563 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20564 return RETURN_ERR;
20565 }
developera3511852023-06-14 14:12:59 +080020566 wifi_hostapdRead(config_file, "proxy_arp", output, sizeof(output));
developer72fb0bb2023-01-11 09:46:29 +080020567
developera3511852023-06-14 14:12:59 +080020568 if (strlen(output) == 0)
20569 *enable = FALSE;
20570 else if (strncmp(output, "1", 1) == 0)
20571 *enable = TRUE;
20572 else
20573 *enable = FALSE;
developer72fb0bb2023-01-11 09:46:29 +080020574
developera3511852023-06-14 14:12:59 +080020575 wifi_dbg_printf("\n[%s]: proxy_arp is : %s", __func__, output);
20576 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020577}
20578
20579INT wifi_getRadioStatsEnable(INT radioIndex, BOOL *output_enable)
20580{
developera3511852023-06-14 14:12:59 +080020581 if (NULL == output_enable || radioIndex >=MAX_NUM_RADIOS)
20582 return RETURN_ERR;
20583 *output_enable=TRUE;
20584 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020585}
20586
20587INT wifi_getTWTsessions(INT ap_index, UINT maxNumberSessions, wifi_twt_sessions_t *twtSessions, UINT *numSessionReturned)
20588{
developera3511852023-06-14 14:12:59 +080020589 char cmd[128] = {0};
20590 char buf[128] = {0};
20591 char line[128] = {0};
20592 FILE *f = NULL;
20593 int index = 0;
20594 int exp = 0;
20595 int mantissa = 0;
20596 int duration = 0;
20597 int radio_index = 0;
20598 int max_radio_num = 0;
20599 uint twt_wake_interval = 0;
20600 int phyId = 0;
developer75bd10c2023-06-27 11:34:08 +080020601 int res;
developerc14d83a2023-06-29 20:09:42 +080020602 unsigned long tmp_u, tmp_l;
developer75bd10c2023-06-27 11:34:08 +080020603
developera3511852023-06-14 14:12:59 +080020604 WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
developer72fb0bb2023-01-11 09:46:29 +080020605
developera3511852023-06-14 14:12:59 +080020606 wifi_getMaxRadioNumber(&max_radio_num);
developer9ce44382023-06-28 11:09:37 +080020607 if(max_radio_num == 0){
20608 return RETURN_ERR;
20609 }
developera3511852023-06-14 14:12:59 +080020610 radio_index = ap_index % max_radio_num;
developer72fb0bb2023-01-11 09:46:29 +080020611
developera3511852023-06-14 14:12:59 +080020612 phyId = radio_index_to_phy(radio_index);
developer75bd10c2023-06-27 11:34:08 +080020613
developer8078acf2023-08-04 18:52:48 +080020614 res = _syscmd_secure(buf, sizeof(buf),"cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | wc -l", phyId);
20615 if (res) {
20616 wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
20617
developer75bd10c2023-06-27 11:34:08 +080020618 }
developer8078acf2023-08-04 18:52:48 +080020619
developerc14d83a2023-06-29 20:09:42 +080020620 if (hal_strtoul(buf, 10, &tmp_u) < 0) {
20621 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080020622 }
20623 *numSessionReturned = tmp_u - 1;
developer5b23cd02023-07-19 20:26:03 +080020624
developera3511852023-06-14 14:12:59 +080020625 if (*numSessionReturned > maxNumberSessions)
20626 *numSessionReturned = maxNumberSessions;
20627 else if (*numSessionReturned < 1) {
20628 *numSessionReturned = 0;
20629 return RETURN_OK;
20630 }
developer72fb0bb2023-01-11 09:46:29 +080020631
developer75bd10c2023-06-27 11:34:08 +080020632 res = snprintf(cmd, sizeof(cmd), "cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | tail -n %d | tr '|' ' ' | tr -s ' '", phyId, *numSessionReturned);
20633 if (os_snprintf_error(sizeof(cmd), res)) {
20634 wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
20635 return RETURN_ERR;
20636 }
developer8078acf2023-08-04 18:52:48 +080020637 f = v_secure_popen("r", "cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | tail -n %d | tr '|' ' ' | tr -s ' '", phyId, *numSessionReturned);
20638 if (f == NULL) {
20639 wifi_dbg_printf("%s: v_secure_popen %s error\n", __func__, cmd);
developera3511852023-06-14 14:12:59 +080020640 return RETURN_ERR;
20641 }
developer72fb0bb2023-01-11 09:46:29 +080020642
developera3511852023-06-14 14:12:59 +080020643 // the format of each line is "[wcid] [id] [flags] [exp] [mantissa] [duration] [tsf]"
20644 while((fgets(line, sizeof(line), f)) != NULL) {
20645 char *tmp = NULL;
developer9ce44382023-06-28 11:09:37 +080020646 size_t len = strlen(line);
20647 strncpy(buf, line,len);
20648 buf[len] = '\0';
developera3511852023-06-14 14:12:59 +080020649 tmp = strtok(buf, " ");
developerd14dff12023-06-28 22:47:44 +080020650 if (tmp == NULL)
20651 break;
developer5b23cd02023-07-19 20:26:03 +080020652
developerc14d83a2023-06-29 20:09:42 +080020653 if (hal_strtoul(tmp, 10, &tmp_u) < 0) {
20654 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
20655 }
20656 twtSessions[index].numDevicesInSession = tmp_u;
developera3511852023-06-14 14:12:59 +080020657 tmp = strtok(NULL, " ");
developerd14dff12023-06-28 22:47:44 +080020658 if (tmp == NULL)
20659 break;
developer5b23cd02023-07-19 20:26:03 +080020660
developerc14d83a2023-06-29 20:09:42 +080020661 if (hal_strtoul(tmp, 10, &tmp_u) < 0) {
20662 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
20663 }
20664 twtSessions[index].twtParameters.operation.flowID = tmp_u;
developera3511852023-06-14 14:12:59 +080020665 tmp = strtok(NULL, " ");
20666 if (strstr(tmp, "t")) {
20667 twtSessions[index].twtParameters.operation.trigger_enabled = TRUE;
20668 }
20669 if (strstr(tmp, "a")) {
20670 twtSessions[index].twtParameters.operation.announced = TRUE;
20671 }
20672 tmp = strtok(NULL, " ");
developer37646972023-06-29 10:58:43 +080020673 if (tmp == NULL)
20674 continue;
developer5b23cd02023-07-19 20:26:03 +080020675
developerc14d83a2023-06-29 20:09:42 +080020676 if (hal_strtoul(tmp, 10, &tmp_l) < 0) {
20677 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
20678 }
20679 exp = tmp_l;
developer5b23cd02023-07-19 20:26:03 +080020680
developera3511852023-06-14 14:12:59 +080020681 tmp = strtok(NULL, " ");
developer37646972023-06-29 10:58:43 +080020682 if (tmp == NULL)
20683 continue;
developerc14d83a2023-06-29 20:09:42 +080020684 if (hal_strtoul(tmp, 10, &tmp_l) < 0) {
20685 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080020686 }
20687 mantissa = tmp_l;
developer5b23cd02023-07-19 20:26:03 +080020688
developera3511852023-06-14 14:12:59 +080020689 tmp = strtok(NULL, " ");
developerc14d83a2023-06-29 20:09:42 +080020690
20691 if (hal_strtoul(tmp, 10, &tmp_l) < 0) {
20692 wifi_debug(DEBUG_ERROR, "Unexpected strtoul fail\n");
developerc14d83a2023-06-29 20:09:42 +080020693 }
20694 duration = tmp_l;
developer72fb0bb2023-01-11 09:46:29 +080020695
developera3511852023-06-14 14:12:59 +080020696 // only implicit supported
20697 twtSessions[index].twtParameters.operation.implicit = TRUE;
20698 // only individual agreement supported
20699 twtSessions[index].twtParameters.agreement = wifi_twt_agreement_type_individual;
developer72fb0bb2023-01-11 09:46:29 +080020700
developera3511852023-06-14 14:12:59 +080020701 // wakeInterval_uSec is a unsigned integer, but the maximum TWT wake interval could be 2^15 (mantissa) * 2^32 = 2^47.
20702 twt_wake_interval = mantissa * (1 << exp);
20703 if (mantissa == 0 || twt_wake_interval/mantissa != (1 << exp)) {
20704 // Overflow handling
20705 twtSessions[index].twtParameters.params.individual.wakeInterval_uSec = -1; // max unsigned int
20706 } else {
20707 twtSessions[index].twtParameters.params.individual.wakeInterval_uSec = twt_wake_interval;
20708 }
20709 twtSessions[index].twtParameters.params.individual.minWakeDuration_uSec = duration * 256;
20710 index++;
20711 }
developer72fb0bb2023-01-11 09:46:29 +080020712
developer8078acf2023-08-04 18:52:48 +080020713 v_secure_pclose(f);
developera3511852023-06-14 14:12:59 +080020714 WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
20715 return RETURN_OK;
developer72fb0bb2023-01-11 09:46:29 +080020716}
developercc5cbfb2023-06-13 18:29:52 +080020717
20718INT wifi_enableGreylistAccessControl(BOOL enable)
20719{
20720 char inf_name[IFNAMSIZ] = {0};
20721 int if_idx, ret = 0;
20722 struct nl_msg *msg = NULL;
20723 struct nlattr * msg_data = NULL;
20724 struct mtk_nl80211_param param;
20725 struct unl unl_ins;
20726 unsigned short apIndex = 0;
20727
20728 for (apIndex = 0; apIndex < MAX_APS; apIndex++) {
20729 if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
20730 continue;
20731
20732 if_idx = if_nametoindex(inf_name);
20733 if (!if_idx) {
20734 wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", inf_name);
20735 continue;
20736 }
20737
20738 /*init mtk nl80211 vendor cmd*/
20739 param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_SET_ACL;
20740 param.if_type = NL80211_ATTR_IFINDEX;
20741 param.if_idx = if_idx;
20742 ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
20743 if (ret) {
20744 wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
20745 return RETURN_ERR;
20746 }
20747
20748 if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_ACL_POLICY, enable == FALSE ? 0 : 1)) {
20749 wifi_debug(DEBUG_ERROR, "Nla put attribute error\n");
20750 nlmsg_free(msg);
20751 mtk_nl80211_deint(&unl_ins);
20752 continue;
20753 }
20754
20755 /*send mtk nl80211 vendor msg*/
20756 ret = mtk_nl80211_send(&unl_ins, msg, msg_data, NULL, NULL);
20757 if (ret) {
20758 wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
20759 mtk_nl80211_deint(&unl_ins);
20760 continue;
20761 }
20762 /*deinit mtk nl80211 vendor msg*/
20763 mtk_nl80211_deint(&unl_ins);
20764 wifi_debug(DEBUG_NOTICE, " %s cmd success.\n", inf_name);
20765 }
20766
20767 return RETURN_OK;
20768}