1 /*
2 * Copyright (C) 2021-2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 /* ****************************************************************************
20 1 头文件包含
21 **************************************************************************** */
22 #include "hmac_ext_if.h"
23 #include "wal_customize.h"
24 #include "wal_11d.h"
25 #include "wal_hipriv.h"
26 #include "wal_ioctl.h"
27 #include "net_adpater.h"
28 #include "wal_event.h"
29
30 #include "mac_pm_driver.h"
31 #include "oal_chr.h"
32 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
33 #include "lwip/netifapi.h"
34 #include "wal_cfg80211_apt.h"
35 #include "hi_wifi_api.h"
36 #include "oal_sdio_host_if.h"
37 #endif
38
39 #include "wal_event_msg.h"
40 #include "wal_main.h"
41 #ifdef _PRE_WLAN_FEATURE_ANY
42 #include "hi_any_api.h"
43 #endif
44 #ifdef LOSCFG_APP_MESH
45 #include "hi_wifi_mesh_api.h"
46 #endif
47 #include "hcc_host.h"
48 #include "plat_pm_wlan.h"
49 #include "wifi_base.h"
50 #include "hdf_wifi_product.h"
51 #include "hi_wifi_driver_wpa_if.h"
52
53 #ifdef __cplusplus
54 #if __cplusplus
55 extern "C" {
56 #endif
57 #endif
58
59 /* ****************************************************************************
60 2 全局变量定义
61 **************************************************************************** */
62 /* ****************************************************************************
63 3 函数实现
64 **************************************************************************** */
65 #if defined(_PRE_WLAN_FEATURE_HIPRIV) || defined(_PRE_WLAN_FEATURE_SIGMA)
66 /* ****************************************************************************
67 功能描述 : 启动hipriv命令
68 输入参数 : [1]argc
69 [2]argv[]
70 返 回 值 : 无
71 **************************************************************************** */
hi_wifi_hipriv(hi_s32 argc,const hi_u8 * argv[])72 hi_void hi_wifi_hipriv(hi_s32 argc, const hi_u8 *argv[])
73 {
74 hi_u32 len;
75 hi_u32 total_len;
76 hi_s32 index;
77 hi_char *pc_buffer = NULL;
78 hi_char *pc_buffer_index = NULL;
79
80 if (argc == 0 || argc > HI_WIFI_HIPRIV_ARGC_MAX) {
81 oam_warning_log0(0, OAM_SF_ANY, "hi_wifi_hipriv: Invalid argc!");
82 return;
83 }
84 if (argv == HI_NULL) {
85 oam_warning_log0(0, OAM_SF_ANY, "hi_wifi_hipriv: Invalid argv!");
86 return;
87 }
88
89 total_len = 0;
90 for (index = 0; index < argc; index++) {
91 total_len += strlen((hi_char *)argv[index]) + 1;
92 }
93 if (total_len > WAL_HIPRIV_CMD_MAX_LEN) {
94 oam_error_log0(0, OAM_SF_ANY, "hi_wifi_hipriv: cmd too large");
95 return;
96 }
97
98 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
99 pc_buffer = malloc(total_len * sizeof(hi_char));
100 #elif (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
101 pc_buffer = oal_memalloc(total_len * sizeof(hi_char));
102 #endif
103 if (pc_buffer == NULL) {
104 oam_error_log0(0, OAM_SF_ANY, "hi_wifi_hipriv: malloc failed!");
105 return;
106 }
107
108 pc_buffer_index = pc_buffer;
109 for (index = 0; index < argc; index++) {
110 len = strlen((hi_char *)argv[index]);
111 if (memcpy_s(pc_buffer_index, len, argv[index], len) != EOK) {
112 oam_error_log0(0, 0, "{hi_wifi_hipriv::mem safe function err!}");
113 continue;
114 }
115 pc_buffer_index[len] = ' ';
116 pc_buffer_index += len + 1;
117 }
118
119 pc_buffer[total_len - 1] = '\0';
120 if (wal_hipriv_entry(pc_buffer, (hi_u32)total_len) != total_len) {
121 oam_warning_log0(0, OAM_SF_ANY, "hipriv failed!");
122 }
123 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
124 free(pc_buffer);
125 #elif (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
126 oal_free(pc_buffer);
127 #endif
128 pc_buffer = NULL;
129
130 return;
131 }
132 #endif
133
134 hi_u8 g_wifi_inited_flag = HI_FALSE;
135 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
136 /* ****************************************************************************
137 功能描述 : 初始化WiFi驱动
138 返 回 值 : 错误码
139 **************************************************************************** */
hi_wifi_init(uint8_t max_port_count,struct BusDev * bus)140 hi_s32 hi_wifi_init(uint8_t max_port_count, struct BusDev *bus)
141 {
142 hi_u8 const vap_res_num = max_port_count;
143 hi_u8 const user_res_num = 4;
144
145 if ((vap_res_num < 1 || vap_res_num > WIFI_MAX_NUM_VAP) ||
146 (user_res_num < 1 || user_res_num > WIFI_MAX_NUM_USER)) {
147 oam_error_log0(0, OAM_SF_ANY, "WiFi initialization failed, vap/user num is wrong.");
148 goto fail;
149 }
150
151 if (g_wifi_inited_flag == HI_TRUE) {
152 oam_error_log0(0, OAM_SF_ANY, "WiFi have inited, do not inited again.");
153 goto fail;
154 }
155
156 if (hi_wifi_plat_init(vap_res_num, user_res_num) != HI_SUCCESS) {
157 oam_error_log0(0, OAM_SF_ANY, "WiFi platform initialize failed.");
158 goto fail;
159 }
160
161 if (hi_wifi_host_init(bus) != HI_SUCCESS) {
162 oam_error_log0(0, OAM_SF_ANY, "WiFi host initialize failed.");
163 goto hi_wifi_host_init_fail;
164 }
165 g_wifi_inited_flag = HI_TRUE;
166 printk("WiFi driver init successfully!\r\n");
167 return HI_SUCCESS;
168
169 hi_wifi_host_init_fail:
170 hi_wifi_plat_exit();
171 fail:
172 return HI_FAIL;
173 }
174 #endif
175
176 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
177 /* ****************************************************************************
178 功能描述 : 初始化WiFi驱动
179 返 回 值 : 错误码
180 **************************************************************************** */
hi_wifi_init(uint8_t max_port_count,struct BusDev * bus)181 hi_s32 hi_wifi_init(uint8_t max_port_count, struct BusDev *bus)
182 {
183 hi_u8 const vap_res_num = max_port_count;
184 hi_u8 const user_res_num = 4;
185
186 printk("[VERSION]:Hi3881V100R001C00SPC020 2020-08-20 17:10:00\n");
187 if (g_wifi_inited_flag == HI_TRUE) {
188 oam_error_log0(0, OAM_SF_ANY, "WiFi have inited, do not inited again.");
189 goto fail;
190 }
191 if (oal_register_ioctl() != HI_SUCCESS) {
192 oam_error_log0(0, OAM_SF_ANY, "oal_register_ioctl failed!\n");
193 goto fail;
194 }
195 if (hi_wifi_plat_init(vap_res_num, user_res_num) != HI_SUCCESS) {
196 oam_error_log0(0, OAM_SF_ANY, "WiFi platform initialize failed.");
197 goto ioctl_clear;
198 }
199
200 if (hi_wifi_host_init(bus) != HI_SUCCESS) {
201 oam_error_log0(0, OAM_SF_ANY, "WiFi host initialize failed.");
202 goto wifi_host_init_fail;
203 }
204
205 g_wifi_inited_flag = HI_TRUE;
206 printk("WiFi driver init successfully!\r\n");
207
208 return HI_SUCCESS;
209 wifi_host_init_fail:
210 hi_wifi_plat_exit();
211 ioctl_clear:
212 oal_unregister_ioctl();
213 fail:
214 return -HI_FAIL;
215 }
216 #endif
217
218 /* ****************************************************************************
219 功能描述 : 去初始化WiFi驱动
220 返 回 值 : 错误码
221 **************************************************************************** */
222 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
hi_wifi_deinit(hi_void)223 hi_s32 hi_wifi_deinit(hi_void)
224 {
225 if (g_wifi_inited_flag == HI_FALSE) {
226 oam_error_log0(0, OAM_SF_ANY, "WiFi have deinited or have not inited.");
227 return HI_FAIL;
228 }
229 wlan_pm_exit();
230 /* WIFI Host Exit */
231 hi_wifi_host_exit();
232 /* WIFI Plat Exit */
233 hi_wifi_plat_exit();
234 printk("WiFi driver deinit successfully!\r\n");
235 g_wifi_inited_flag = HI_FALSE;
236 return HI_SUCCESS;
237 }
238 #endif
239
240 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
hi_wifi_deinit(hi_void)241 hi_s32 hi_wifi_deinit(hi_void)
242 {
243 if (g_wifi_inited_flag == HI_FALSE) {
244 oam_error_log0(0, OAM_SF_ANY, "WiFi have deinited or have not inited.");
245 return HI_FAIL;
246 }
247 oal_unregister_ioctl();
248 wlan_pm_exit();
249 /* WIFI Host Exit */
250 hi_wifi_host_exit();
251 /* WIFI Plat Exit */
252 hi_wifi_plat_exit();
253 printk("WiFi driver deinit successfully!\r\n");
254 g_wifi_inited_flag = HI_FALSE;
255 return HI_SUCCESS;
256 }
257 #endif
258
259 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
260 /* ****************************************************************************
261 功能描述 : 提供产测功率参数定制化接口
262 返 回 值 : 错误码
263 **************************************************************************** */
hi_wifi_set_customize_params(hi_wifi_customize_params * params)264 hi_u32 hi_wifi_set_customize_params(hi_wifi_customize_params *params)
265 {
266 hi_u8 ret;
267 const hi_u8 size = 3;
268 hi_char data[size];
269 if (params == HI_NULL) {
270 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_set_customize_params: pst_param is NULL! }");
271 return HI_ERR_CODE_PTR_NULL;
272 }
273 ret = wal_customize_init();
274 if (ret != HI_SUCCESS) {
275 return ret;
276 }
277 /* dbb配置参数 */
278 ret = wal_cfg_dbb(params->dbb_params, HI_WIFI_DBB_PARAM_CNT);
279 if (ret != HI_SUCCESS) {
280 return ret;
281 }
282 /* fcc发送功率配置 */
283 ret = wal_cfg_fcc_tx_pwr(params->ch_txpwr_offset, HI_WIFI_CH_TX_PWR_PARAM_CNT);
284 if (ret != HI_SUCCESS) {
285 return ret;
286 }
287 /* 高温频偏配置参数 */
288 ret = wal_cfg_freq_comp_val(params->freq_comp, HI_WIFI_FREQ_COMP_PARAM_CNT);
289 if (ret != HI_SUCCESS) {
290 return ret;
291 }
292 /* RSSI配置参数 */
293 ret = wal_cfg_rssi_ofset(params->rssi_offset);
294 if (ret != HI_SUCCESS) {
295 return ret;
296 }
297 /* 拷贝国家码,顺序交叉 */
298 data[0] = params->country_code[1];
299 data[1] = params->country_code[0];
300 data[2] = '\0'; /* 下标2 */
301 ret = wal_cfg_country_code(data, size);
302 if (ret != HI_SUCCESS) {
303 return ret;
304 }
305 return HI_SUCCESS;
306 }
307 #endif
308
309 /* ****************************************************************************
310 功能描述 : 设置起始mac地址
311 返 回 值 : 错误码
312 **************************************************************************** */
hi_wifi_set_macaddr(const hi_char * mac_addr,hi_u8 mac_len)313 hi_s32 hi_wifi_set_macaddr(const hi_char *mac_addr, hi_u8 mac_len)
314 {
315 hi_char mac_addr_tmp[ETHER_ADDR_LEN] = {0};
316
317 if (mac_addr == HI_NULL) {
318 oam_error_log0(0, OAM_SF_ANY, "hi_wifi_set_macaddr:: macaddr is NULL!");
319 return HI_FAIL;
320 }
321 if (memcpy_s(mac_addr_tmp, ETHER_ADDR_LEN, mac_addr, mac_len) != EOK) {
322 oam_error_log0(0, 0, "hi_wifi_set_macaddr:: memcpy_s failed.");
323 return HI_FAIL;
324 }
325 /* 建议5.5 这里强制类型转换会不会出问题 */
326 if (wal_macaddr_check((hi_u8 *)mac_addr_tmp) != HI_SUCCESS) {
327 oam_warning_log0(0, OAM_SF_ANY, "hi_wifi_set_macaddr:: Mac address invalid!");
328 return HI_FAIL;
329 }
330 if (wal_set_dev_addr(mac_addr_tmp, ETHER_ADDR_LEN) != HI_SUCCESS) {
331 return HI_FAIL;
332 }
333
334 return HI_SUCCESS;
335 }
336
337 /* ****************************************************************************
338 功能描述 : 获取起始mac地址
339 返 回 值 : 错误码
340 **************************************************************************** */
hi_wifi_get_macaddr(hi_char * mac_addr,hi_u8 addr_len)341 hi_s32 hi_wifi_get_macaddr(hi_char *mac_addr, hi_u8 addr_len)
342 {
343 if (mac_addr == HI_NULL) {
344 oam_error_log0(0, OAM_SF_ANY, "hi_wifi_get_macaddr:: macaddr is NULL!");
345 return HI_FAIL;
346 }
347
348 if (wal_get_dev_addr((hi_u8 *)mac_addr, addr_len, 2) != HI_SUCCESS) { /* 2: nl80211_iftype */
349 oam_error_log0(0, OAM_SF_ANY, "hi_wifi_get_macaddr:: get macaddr failed");
350 return HI_FAIL;
351 }
352
353 return HI_SUCCESS;
354 }
355
356 /* ****************************************************************************
357 功能描述 : 获取关联ap的rssi值
358 返 回 值 : rssi值
359 **************************************************************************** */
hi_wifi_sta_get_ap_rssi(hi_void)360 hi_s32 hi_wifi_sta_get_ap_rssi(hi_void)
361 {
362 hi_s32 l_ret;
363 oal_net_device_stru *netdev = HI_NULL;
364 mac_vap_stru *mac_vap = HI_NULL;
365 hmac_vap_stru *hmac_vap = HI_NULL;
366 wal_msg_write_stru write_msg;
367 mac_device_stru *mac_dev = mac_res_get_dev();
368 hi_u8 vap_idx;
369
370 /* 寻找STA */
371 for (vap_idx = 0; vap_idx < mac_dev->vap_num; vap_idx++) {
372 mac_vap = mac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
373 if (mac_vap == HI_NULL) {
374 continue;
375 }
376 if (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) {
377 break;
378 }
379 }
380
381 if (mac_vap == HI_NULL) {
382 oam_error_log0(0, 0, "hi_wifi_sta_get_ap_rssi:: mac_vap is NULL");
383 return WLAN_RSSI_DUMMY_MARKER;
384 }
385
386 netdev = hmac_vap_get_net_device(mac_vap->vap_id);
387 if (netdev == HI_NULL) {
388 oam_error_log0(0, 0, "hi_wifi_sta_get_ap_rssi sta device not found.");
389 return WLAN_RSSI_DUMMY_MARKER;
390 }
391
392 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
393 if (hmac_vap == HI_NULL) {
394 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_sta_get_ap_rssi::hmac_vap_get_vap_stru, return NULL!}");
395 return WLAN_RSSI_DUMMY_MARKER;
396 }
397
398 hmac_vap->query_ap_rssi_flag = HI_FALSE;
399 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_RSSI, sizeof(wlan_rssi_stru));
400 l_ret = (hi_s32)wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE,
401 WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(wlan_rssi_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
402 if (oal_unlikely(l_ret != HI_SUCCESS)) {
403 oam_warning_log1(mac_vap->vap_id, OAM_SF_ANY,
404 "{hi_wifi_sta_get_ap_rssi::wal_send_cfg_event return err code %d!}", l_ret);
405 return WLAN_RSSI_DUMMY_MARKER;
406 }
407
408 // 使用非wifi目录定义宏函数,误报告警,lin_t e26告警屏蔽
409 l_ret = hi_wait_event_timeout((hmac_vap->query_wait_q),
410 (HI_TRUE == hmac_vap->query_ap_rssi_flag), (5 * HZ)); // 5 频率
411 if (l_ret <= 0) {
412 oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hi_wifi_sta_get_ap_rssi: query timeout.");
413 return WLAN_RSSI_DUMMY_MARKER;
414 }
415
416 return hmac_vap->ap_rssi;
417 }
418
419 /* ****************************************************************************
420 功能描述 : 设置国家码
421 输入参数 : *cc 两个大写字符的国家码,数组大小至少3个字节,带字符串结束符
422 返 回 值 : 错误码
423 **************************************************************************** */
hi_wifi_set_country(const hi_char * cc,unsigned char cc_len)424 hi_s32 hi_wifi_set_country(const hi_char *cc, unsigned char cc_len)
425 {
426 oal_net_device_stru *netdev = HI_NULL;
427
428 if (cc == HI_NULL) {
429 oam_error_log0(0, 0, "wifi_set_country parameter is NULL.");
430 return HI_FAIL;
431 }
432
433 if (cc_len < MAC_CONTRY_CODE_LEN) {
434 oam_error_log0(0, 0, "wifi_set_country invalid country code length.");
435 return HI_FAIL;
436 }
437
438 /* 国家码两个字符 */
439 if (strlen(cc) != 2) { /* 2 国家码2个字符 */
440 oam_error_log0(0, 0, "wifi_set_country invalid country code.");
441 return HI_FAIL;
442 }
443
444 netdev = oal_get_netdev_by_name(WLAN_CFG_VAP_NAME);
445 if (netdev == HI_NULL) {
446 oam_error_log0(0, 0, "wifi_set_country Hisilicon0 device not found.");
447 return HI_FAIL;
448 }
449 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
450 oal_dev_put(netdev);
451 #endif
452 if (wal_regdomain_update(netdev, cc, MAC_CONTRY_CODE_LEN) != HI_SUCCESS) {
453 oam_error_log0(0, 0, "wifi_set_country regdomain update failed.");
454 return HI_FAIL;
455 }
456
457 return HI_SUCCESS;
458 }
459
460 /* ****************************************************************************
461 功能描述 : 获取当前国家码
462 输出参数 : [1]cc 两个大写字符的国家码,数组大小至少3个字节
463 [2]len 返回字符串长度
464 返 回 值 : 错误码
465 **************************************************************************** */
hi_wifi_get_country(hi_char * cc,hi_s32 * len)466 hi_s32 hi_wifi_get_country(hi_char *cc, hi_s32 *len)
467 {
468 oal_net_device_stru *netdev = HI_NULL;
469
470 if ((cc == HI_NULL) || (len == HI_NULL)) {
471 oam_error_log0(0, 0, "wifi_get_country parameter is NULL.");
472 return HI_FAIL;
473 }
474
475 if (*len < MAC_CONTRY_CODE_LEN) {
476 oam_error_log0(0, 0, "hi_wifi_get_country invalid country code length.");
477 return HI_FAIL;
478 }
479
480 netdev = oal_get_netdev_by_name(WLAN_CFG_VAP_NAME);
481 if (netdev == HI_NULL) {
482 oam_error_log0(0, 0, "wifi_get_country Hisilicon0 device not found.");
483 return HI_FAIL;
484 }
485 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
486 oal_dev_put(netdev);
487 #endif
488 if (wal_hipriv_getcountry(netdev, cc) != HI_SUCCESS) {
489 oam_error_log0(0, 0, "wifi_get_country failed.");
490 return HI_FAIL;
491 }
492 *len = (hi_s32)strlen(cc);
493
494 return HI_SUCCESS;
495 }
496
497 /* ****************************************************************************
498 功能描述 : 开启/关闭系统低功耗模式并配置预期休眠时间
499 输入参数 : [1]enable 使能开关
500 [2]sleeptime 预期休眠时间
501 返 回 值 : 错误码
502 ***************************************************************************** */
hi_wifi_set_pm_switch(hi_u8 enable)503 hi_s32 hi_wifi_set_pm_switch(hi_u8 enable)
504 {
505 oal_net_device_stru *net_dev = HI_NULL;
506 wal_msg_write_stru write_msg;
507 hi_u32 ret;
508 hi_u32 pm_cfg;
509
510 net_dev = oal_get_netdev_by_name(WLAN_CFG_VAP_NAME);
511 if (net_dev == HI_NULL) {
512 oam_error_log0(0, 0, "hi_wifi_set_pm_switch Hisilicon0 device not found.");
513 return HI_FAIL;
514 }
515
516 /* 缓存低功耗标志 */
517 set_under_ps(enable == PM_SWITCH_ON);
518 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
519 oal_dev_put(net_dev);
520 #endif
521 if (enable == PM_SWITCH_ON) {
522 pm_cfg = PM_SWITCH_ON;
523 } else if (enable == PM_SWITCH_OFF) {
524 /* 关低功耗 */
525 pm_cfg = PM_SWITCH_OFF;
526 } else {
527 oam_warning_log0(0, OAM_SF_COEX, "{hi_wifi_set_pm_switch::input parameter error!}\r\n");
528 return HI_FAIL;
529 }
530
531 /* **************************************************************************
532 抛事件到wal层处理
533 ************************************************************************** */
534 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_SET_PM_SWITCH, sizeof(hi_u32));
535 *((hi_u32 *)(write_msg.auc_value)) = pm_cfg;
536 ret = wal_send_cfg_event(net_dev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_u32),
537 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
538 if (oal_unlikely(ret != HI_SUCCESS)) {
539 oam_warning_log1(0, OAM_SF_ANY, "{wal_hipriv_pm_switch::return err code [%u]!}\r\n", ret);
540 return ret;
541 }
542
543 return HI_SUCCESS;
544 }
545
546 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
547 /* ****************************************************************************
548 功能描述 : 设置接口带宽
549 输入参数 : [1]ifname
550 [2]bw 带宽
551 返 回 值 : 错误码
552 **************************************************************************** */
hi_wifi_set_bandwidth(const hi_char * ifname,unsigned char ifname_len,hi_wifi_bw bw)553 hi_s32 hi_wifi_set_bandwidth(const hi_char *ifname, unsigned char ifname_len, hi_wifi_bw bw)
554 {
555 hi_char ac_bw[WAL_BW_STR_MAX_LEN] = {0};
556 hi_char ifname_cpy[WIFI_IFNAME_MAX_SIZE + 1] = {0};
557 hi_char *ptr_ifname_cpy = ifname_cpy;
558
559 if (memcpy_s(ifname_cpy, sizeof(ifname_cpy), ifname, ifname_len) != EOK) {
560 return HI_FAIL;
561 }
562 oal_net_device_stru *netdev = oal_get_netdev_by_name(ptr_ifname_cpy);
563 if (netdev == HI_NULL) {
564 oam_error_log0(0, 0, "hi_wifi_set_bandwidth device not found.");
565 return HI_FAIL;
566 }
567
568 if ((bw > HI_WIFI_BW_LEGACY_20M) || (bw < HI_WIFI_BW_HIEX_5M)) {
569 oam_error_log0(0, 0, "hi_wifi_set_bandwidth invalid bw.");
570 return HI_FAIL;
571 }
572
573 strcpy_s(ac_bw, WAL_BW_STR_MAX_LEN, "20");
574 if (bw == HI_WIFI_BW_HIEX_5M) {
575 strcpy_s(ac_bw, WAL_BW_STR_MAX_LEN, "5");
576 } else if (bw == HI_WIFI_BW_HIEX_10M) {
577 strcpy_s(ac_bw, WAL_BW_STR_MAX_LEN, "10");
578 }
579
580 if (wal_netdev_stop(netdev) != HI_SUCCESS) {
581 oam_error_log0(0, 0, "wal_netdev_stop failed.");
582 return HI_FAIL;
583 }
584
585 if (wal_hipriv_set_bw(netdev, ac_bw) != HI_SUCCESS) {
586 oam_error_log0(0, 0, "wal_hipriv_set_bw failed.");
587 return HI_FAIL;
588 }
589
590 if (wal_netdev_open(netdev) != HI_SUCCESS) {
591 oam_error_log0(0, 0, "wal_netdev_open failed.");
592 return HI_FAIL;
593 }
594
595 return HI_SUCCESS;
596 }
597
598 /* ****************************************************************************
599 功能描述 : 获取接口带宽
600 输入参数 : [1]ifname
601 返 回 值 : hi_wifi_bw 带宽
602 **************************************************************************** */
hi_wifi_get_bandwidth(const hi_char * ifname,unsigned char ifname_len)603 hi_wifi_bw hi_wifi_get_bandwidth(const hi_char *ifname, unsigned char ifname_len)
604 {
605 oal_net_device_stru *netdev = HI_NULL;
606 hal_channel_assemble_enum_uint8 bw_index = WLAN_BAND_ASSEMBLE_20M;
607 hi_wifi_bw bw = HI_WIFI_BW_BUTT;
608 hi_char ifname_cpy[WIFI_IFNAME_MAX_SIZE + 1] = {0};
609 hi_char *ptr_ifname_cpy = ifname_cpy;
610
611 if (memcpy_s(ifname_cpy, sizeof(ifname_cpy), ifname, ifname_len) != EOK) {
612 return HI_WIFI_BW_BUTT;
613 }
614
615 netdev = oal_get_netdev_by_name(ptr_ifname_cpy);
616 if (netdev == HI_NULL) {
617 oam_error_log0(0, 0, "hi_wifi_get_bandwidth device not found.");
618 return HI_WIFI_BW_BUTT;
619 }
620
621 if (wal_hipriv_get_bw(netdev, &bw_index) != HI_SUCCESS) {
622 oam_error_log0(0, 0, "hi_wifi_get_bandwidth failed.");
623 return HI_WIFI_BW_BUTT;
624 }
625
626 if (bw_index == WLAN_BAND_ASSEMBLE_5M) {
627 bw = HI_WIFI_BW_HIEX_5M;
628 } else if (bw_index == WLAN_BAND_ASSEMBLE_10M) {
629 bw = HI_WIFI_BW_HIEX_10M;
630 } else if (bw_index == WLAN_BAND_ASSEMBLE_20M) {
631 bw = HI_WIFI_BW_LEGACY_20M;
632 }
633
634 return bw;
635 }
636
637 /* ****************************************************************************
638 功能描述 : 发送用户定制的报文
639 输入参数 : [1]ifname
640 [2]buf : 报文内容
641 [3]len : 报文长度
642 返 回 值 : 错误码
643 **************************************************************************** */
hi_wifi_send_custom_pkt(const hi_char * ifname,const hi_u8 * buf,hi_u32 len)644 hi_s32 hi_wifi_send_custom_pkt(const hi_char *ifname, const hi_u8 *buf, hi_u32 len)
645 {
646 hi_s32 l_ret;
647 wal_msg_write_stru write_msg;
648 wlan_custom_pkt_stru *pkt = HI_NULL;
649
650 if (buf == HI_NULL) {
651 oam_error_log0(0, 0, "hi_wifi_send_custom_pkt input param is NULL.");
652 return HI_FAIL;
653 }
654
655 if ((len < HI_WIFI_CUSTOM_PKT_MIN_LEN) || (len > HI_WIFI_CUSTOM_PKT_MAX_LEN)) {
656 oam_error_log0(0, 0, "hi_wifi_send_custom_pkt invalid len.");
657 return HI_FAIL;
658 }
659
660 oal_net_device_stru *netdev = oal_get_netdev_by_name(ifname);
661 if (netdev == HI_NULL) {
662 oam_error_log0(0, 0, "hi_wifi_send_custom_pkt device not found.");
663 return HI_FAIL;
664 }
665
666 /* 复制用户数据 */
667 hi_u8 *frame_data = (hi_u8 *)hi_malloc(HI_MOD_ID_WIFI_DRV, len);
668 if (frame_data == HI_NULL) {
669 oam_error_log0(0, 0, "{hi_wifi_send_custom_pkt: mem alloc err!}");
670 return HI_FAIL;
671 }
672
673 if (memcpy_s(frame_data, len, (hi_u8 *)buf, len) != EOK) {
674 hi_free(HI_MOD_ID_WIFI_DRV, frame_data);
675 oam_error_log0(0, 0, "{hi_wifi_any_send::copy user data err!}");
676 return HI_FAIL;
677 }
678
679 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_CUSTOM_PKT, sizeof(wlan_custom_pkt_stru));
680 pkt = (wlan_custom_pkt_stru *)(write_msg.auc_value);
681 pkt->puc_data = frame_data;
682 pkt->us_len = len;
683
684 l_ret = (hi_s32)wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE,
685 WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(wlan_custom_pkt_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
686 if (oal_unlikely(l_ret != HI_SUCCESS)) {
687 hi_free(HI_MOD_ID_WIFI_DRV, frame_data);
688 oam_error_log0(0, 0, "hi_wifi_send_custom_pkt failed.");
689 }
690
691 return l_ret;
692 }
693
hi_wifi_set_plat_ps_mode(hi_u8 sleep_mode)694 hi_s32 hi_wifi_set_plat_ps_mode(hi_u8 sleep_mode)
695 {
696 wal_msg_write_stru write_msg;
697 hi_u32 ret;
698
699 if (sleep_mode > HI_DEEP_SLEEP) {
700 oam_error_log1(0, 0, "hi_wifi_set_plat_ps_mode:: invalid sleep_mode[%hhu]", sleep_mode);
701 return HI_FAIL;
702 }
703
704 oal_net_device_stru *netdev = oal_get_netdev_by_name(WLAN_CFG_VAP_NAME);
705 if (netdev == HI_NULL) {
706 oam_error_log0(0, 0, "hi_wifi_arp_offload_setting:: device not found.");
707 return HI_FAIL;
708 }
709
710 /* **************************************************************************
711 抛事件到wal层处理
712 ************************************************************************** */
713 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_SET_STA_HW_PS_MODE, sizeof(hi_u8));
714 *(hi_u8 *)(write_msg.auc_value) = sleep_mode;
715
716 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_u8),
717 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
718 if (oal_unlikely(ret != HI_SUCCESS)) {
719 oam_warning_log1(0, OAM_SF_PWR, "{wal_hipriv_sta_set_hw_ps_mode::return err code [%u]!}", ret);
720 return ret;
721 }
722
723 return HI_SUCCESS;
724 }
725
726 #ifdef _PRE_WLAN_FEATURE_PROMIS
727 hi_u8 g_promis_filter = 0;
728
hwal_get_promis_filter(void)729 hi_u8 hwal_get_promis_filter(void)
730 {
731 return g_promis_filter;
732 }
733
734 /* ****************************************************************************
735 功能描述 : 设置混杂模式
736 输入参数 : [1]net_dev
737 [2]mode
738 返 回 值 : 错误码
739 **************************************************************************** */
wifi_promis_set(oal_net_device_stru * netdev,hi_u8 filter_value)740 hi_s32 wifi_promis_set(oal_net_device_stru *netdev, hi_u8 filter_value)
741 {
742 hi_s32 l_ret;
743 wal_msg_write_stru write_msg;
744
745 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_MONITOR_EN, sizeof(hi_u8));
746 *((hi_u8 *)(write_msg.auc_value)) = filter_value; /* 设置配置命令参数 */
747 g_promis_filter = filter_value;
748
749 l_ret = (hi_s32)wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_u8),
750 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
751 if (oal_unlikely(l_ret != HI_SUCCESS)) {
752 oam_error_log1(0, 0, "wifi_promis_set failed,mode=%u.", filter_value);
753 return l_ret;
754 }
755
756 return l_ret;
757 }
758
759 /* ****************************************************************************
760 功能描述 : 使能混杂模式
761 输入参数 : [1]ifname
762 [2]enable
763 返 回 值 : 错误码
764 **************************************************************************** */
hi_wifi_promis_enable(const hi_char * ifname,hi_s32 enable,const hi_wifi_ptype_filter * filter)765 hi_s32 hi_wifi_promis_enable(const hi_char *ifname, hi_s32 enable, const hi_wifi_ptype_filter *filter)
766 {
767 hi_s32 l_ret;
768 hi_u8 filter_value;
769 oal_net_device_stru *netdev = HI_NULL;
770
771 if ((ifname == HI_NULL) || (filter == HI_NULL)) {
772 oam_error_log0(0, 0, "hi_wifi_promis_enable parameter NULL.");
773 return HI_FAIL;
774 }
775
776 filter_value = *((hi_u8 *)((hi_void *)filter)) & 0x0F;
777 netdev = oal_get_netdev_by_name(ifname);
778 if (netdev == HI_NULL) {
779 oam_error_log0(0, 0, "hi_wifi_promis_enable device not found.");
780 return HI_FAIL;
781 }
782
783 if ((enable != HI_FALSE) && (enable != HI_TRUE)) {
784 oam_error_log0(0, 0, "hi_wifi_promis_enable invalid parameter.");
785 return HI_FAIL;
786 }
787
788 if (enable == HI_FALSE) {
789 filter_value = 0;
790 }
791 l_ret = wifi_promis_set(netdev, filter_value);
792 return l_ret;
793 }
794
795 /* ****************************************************************************
796 功能描述 : 注册混杂模式收包回调函数
797 输入参数 : hi_wifi_promis_cb data_cb 收包回调函数
798 返 回 值 : 错误码
799 **************************************************************************** */
hi_wifi_promis_set_rx_callback(hi_wifi_promis_cb data_cb)800 hi_s32 hi_wifi_promis_set_rx_callback(hi_wifi_promis_cb data_cb)
801 {
802 if (hisi_wlan_register_upload_frame_cb(data_cb) != 0) {
803 oam_error_log0(0, 0, "wifi_set_promiscuous_rx_cb failed.");
804 return HI_FAIL;
805 }
806
807 return HI_SUCCESS;
808 }
809 #endif /* _PRE_WLAN_FEATURE_PROMIS */
810 #endif /* (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) */
811
812 #ifdef _PRE_WLAN_FEATURE_CSI
813 /* ****************************************************************************
814 功能描述 : 打开CSI数据上报开关
815 返 回 值 : 错误码
816 **************************************************************************** */
hi_wifi_csi_start(hi_void)817 hi_s32 hi_wifi_csi_start(hi_void)
818 {
819 return wal_csi_switch(HI_SWITCH_ON);
820 }
821
822 /* ****************************************************************************
823 功能描述 : 关闭CSI数据上报开关
824 返 回 值 : 错误码
825 **************************************************************************** */
hi_wifi_csi_stop(hi_void)826 hi_s32 hi_wifi_csi_stop(hi_void)
827 {
828 return wal_csi_switch(HI_SWITCH_OFF);
829 }
830
831 /* ****************************************************************************
832 功能描述 : 注册CSI数据上报回调函数
833 返 回 值 : 错误码
834 **************************************************************************** */
hi_wifi_csi_register_data_recv_func(hi_wifi_csi_data_cb data_cb)835 hi_s32 hi_wifi_csi_register_data_recv_func(hi_wifi_csi_data_cb data_cb)
836 {
837 wal_csi_register_data_report_cb(data_cb);
838 return HI_SUCCESS;
839 }
840
841 /* ****************************************************************************
842 功能描述 : CSI参数配置
843 输入参数 : ifname 接口名字
844 hi_wifi_csi_entry 配置参数结构体数组
845 report_min_interval CSI数据上报最小间隔
846 entry_num 配置参数结构体数组长度
847 返 回 值 : 错误码
848 **************************************************************************** */
hi_wifi_csi_set_config(const hi_char * ifname,hi_u32 report_min_interval,const hi_wifi_csi_entry * entry_list,hi_s32 entry_num)849 hi_s32 hi_wifi_csi_set_config(const hi_char *ifname, hi_u32 report_min_interval, const hi_wifi_csi_entry *entry_list,
850 hi_s32 entry_num)
851 {
852 if (ifname == HI_NULL || entry_list == HI_NULL || entry_num == 0) {
853 oam_error_log0(0, OAM_SF_CSI, "{hi_wifi_csi_set_config::param is error.}");
854 return HI_ERR_CODE_PTR_NULL;
855 }
856
857 if (report_min_interval < OAL_CSI_DATA_REPORT_PERIOD) {
858 report_min_interval = OAL_CSI_DATA_REPORT_PERIOD;
859 oam_warning_log0(0, OAM_SF_CSI, "{hi_wifi_csi_set_config::csi smaller than 50ms, set to 50ms.}");
860 }
861
862 if (entry_num > OAL_CSI_MAX_MAC_NUM) {
863 entry_num = OAL_CSI_MAX_MAC_NUM;
864 oam_warning_log0(0, OAM_SF_CSI, "{hi_wifi_csi_set_config::num more than 6, ignore the entry num more than 6.}");
865 }
866 return wal_csi_set_config(ifname, report_min_interval, entry_list, entry_num);
867 }
868 #endif
869
870 /* ****************************************************************************
871 功能描述 : 设置信道
872 输入参数 : [1]ifname
873 [2]channel
874 返 回 值 : 错误码
875 **************************************************************************** */
hi_wifi_set_channel(const hi_char * ifname,unsigned char ifname_len,hi_s32 channel)876 hi_s32 hi_wifi_set_channel(const hi_char *ifname, unsigned char ifname_len, hi_s32 channel)
877 {
878 hi_s32 l_ret;
879 wal_msg_write_stru write_msg;
880 oal_net_device_stru *netdev = HI_NULL;
881 wal_msg_stru *rsp_msg = HI_NULL;
882 hi_char ifname_cpy[WIFI_IFNAME_MAX_SIZE + 1] = {0};
883 hi_char *ptr_ifname_cpy = ifname_cpy;
884
885 if (memcpy_s(ifname_cpy, sizeof(ifname_cpy), ifname, ifname_len) != EOK) {
886 return HI_FAIL;
887 }
888
889 netdev = oal_get_netdev_by_name(ptr_ifname_cpy);
890 if (netdev == HI_NULL) {
891 oam_error_log0(0, 0, "hi_wifi_set_channel device not found.");
892 return HI_FAIL;
893 }
894
895 if ((channel > MAC_CHANNEL_FREQ_2_BUTT) || (channel <= 0)) {
896 oam_error_log0(0, 0, "hi_wifi_set_channel invalid channel.");
897 return HI_FAIL;
898 }
899
900 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_CURRENT_CHANEL, sizeof(hi_s32));
901 *((hi_s32 *)(write_msg.auc_value)) = channel;
902 l_ret = (hi_s32)wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_s32),
903 (hi_u8 *)&write_msg, HI_TRUE, &rsp_msg);
904 if ((l_ret != HI_SUCCESS) || (rsp_msg == HI_NULL)) {
905 oam_error_log0(0, 0, "hi_wifi_set_channel failed.");
906 return l_ret;
907 }
908
909 if (HI_SUCCESS != wal_check_and_release_msg_resp(rsp_msg)) {
910 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_set_channel::wal_check_and_release_msg_resp failed.}");
911 return HI_FAIL;
912 }
913
914 return l_ret;
915 }
916
917 /* ****************************************************************************
918 功能描述 : 获取当前信道
919 输入参数 : [1]ifname
920 返 回 值 : 当前信道号
921 **************************************************************************** */
hi_wifi_get_channel(const hi_char * ifname,unsigned char ifname_len)922 hi_s32 hi_wifi_get_channel(const hi_char *ifname, unsigned char ifname_len)
923 {
924 oal_net_device_stru *netdev = HI_NULL;
925 hi_u32 l_ret;
926 wal_msg_stru *rsp_msg = HI_NULL;
927 wal_msg_query_stru query_msg;
928 wal_msg_rsp_stru *queue_rsp_msg = HI_NULL;
929 hi_s32 channel;
930 hi_char ifname_cpy[WIFI_IFNAME_MAX_SIZE + 1] = {0};
931 hi_char *ptr_ifname_cpy = ifname_cpy;
932
933 if (memcpy_s(ifname_cpy, sizeof(ifname_cpy), ifname, ifname_len) != EOK) {
934 return HI_WIFI_INVALID_CHANNEL;
935 }
936
937 netdev = oal_get_netdev_by_name(ptr_ifname_cpy);
938 if (netdev == HI_NULL) {
939 oam_error_log0(0, 0, "hi_wifi_get_channel device not found.");
940 return HI_WIFI_INVALID_CHANNEL;
941 }
942
943 query_msg.wid = WLAN_CFGID_CURRENT_CHANEL;
944
945 /* 发送消息 */
946 l_ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_QUERY, WAL_MSG_WID_LENGTH, (hi_u8 *)&query_msg, HI_TRUE, &rsp_msg);
947 if ((l_ret != HI_SUCCESS) || (rsp_msg == HI_NULL)) {
948 oam_error_log1(0, OAM_SF_ANY, "{hi_wifi_get_channel::return err code %d!}\r\n", l_ret);
949 return HI_WIFI_INVALID_CHANNEL;
950 }
951
952 /* 处理返回消息 */
953 queue_rsp_msg = (wal_msg_rsp_stru *)(rsp_msg->auc_msg_data);
954 channel = *((hi_s32 *)(queue_rsp_msg->auc_value));
955 oal_free(rsp_msg);
956
957 return channel;
958 }
959
960 #ifdef _PRE_WLAN_FEATURE_ANY
961 /* ****************************************************************************
962 2 全局变量定义
963 **************************************************************************** */
964 oal_net_device_stru *g_any_netdev = HI_NULL;
965
966 /* ****************************************************************************
967 3 函数实现
968 **************************************************************************** */
969 /* ****************************************************************************
970 函 数 名 : hi_wifi_any_init
971 功能描述 : ANY初始化,主要是分配内存,方便后续维护对端设备信息。
972 输入参数 : ifname是字符串"wlan0"或"wlan1"等,表示用于收发ANY帧的接口名称
973 返 回 值 : HI_SUCCESS 上报成功,其它错误码 上报失败
974
975 修改历史 :
976 1.日 期 : 2019年1月24日
977 作 者 : HiSilicon
978 修改内容 : 新生成函数
979 **************************************************************************** */
hi_wifi_any_init(const hi_char * ifname)980 hi_s32 hi_wifi_any_init(const hi_char *ifname)
981 {
982 if (ifname == HI_NULL) {
983 oam_error_log0(0, 0, "{hi_wifi_any_init:ifname is NULL.}");
984 return HI_FAIL;
985 }
986
987 /* 一个设备只允许在一个VAP初始化ANY,已经初始化则需要先调用去初始化 */
988 if (g_any_netdev != HI_NULL) {
989 oam_error_log0(0, 0, "{hi_wifi_any_init:any has already been initialized, please deinit first.}");
990 return HI_FAIL;
991 }
992
993 g_any_netdev = oal_get_netdev_by_name(ifname);
994 if (g_any_netdev == HI_NULL) {
995 oam_error_log0(0, 0, "{hi_wifi_any_init:invalid ifname.}");
996 return HI_FAIL;
997 }
998
999 return wal_any_global_config(WLAN_CFGID_ANY_INIT, g_any_netdev);
1000 }
1001
1002 /* ****************************************************************************
1003 函 数 名 : hi_wifi_any_deinit
1004 功能描述 : ANY去初始化,做清理工作,释放内存
1005 返 回 值 : HI_SUCCESS 上报成功,其它错误码 上报失败
1006
1007 修改历史 :
1008 1.日 期 : 2019年1月24日
1009 作 者 : HiSilicon
1010 修改内容 : 新生成函数
1011 **************************************************************************** */
hi_wifi_any_deinit(hi_void)1012 hi_s32 hi_wifi_any_deinit(hi_void)
1013 {
1014 (hi_void)wal_any_global_config(WLAN_CFGID_ANY_DEINIT, g_any_netdev);
1015 g_any_netdev = HI_NULL;
1016 return HI_SUCCESS;
1017 }
1018
1019 /* ****************************************************************************
1020 函 数 名 : hi_wifi_any_add_peer
1021 功能描述 : 添加指定的点对点对端设备信息
1022 输入参数 : wal_any_peer_info_stru包含用户下发的对端MAC和信道以及密钥等信息
1023 返 回 值 : HI_SUCCESS 上报成功,其它错误码 上报失败
1024
1025 修改历史 :
1026 1.日 期 : 2019年1月24日
1027 作 者 : HiSilicon
1028 修改内容 : 新生成函数
1029 **************************************************************************** */
hi_wifi_any_add_peer(const hi_wifi_any_peer_info * puc_peer_info)1030 hi_s32 hi_wifi_any_add_peer(const hi_wifi_any_peer_info *puc_peer_info)
1031 {
1032 wal_msg_write_stru write_msg;
1033 hi_wifi_any_peer_info *msg_peer_info = HI_NULL;
1034 hi_s32 l_ret;
1035 hi_u8 auc_mac[ETH_ALEN] = {0};
1036
1037 if (puc_peer_info == HI_NULL) {
1038 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_any_add_peer:puc_peer_info is NULL.}");
1039 return HI_FAIL;
1040 }
1041
1042 /* 检查对端MAC是否有效,需要为单播地址 */
1043 if (ether_is_multicast(puc_peer_info->mac) || (memcmp(auc_mac, puc_peer_info->mac, ETH_ALEN) == 0)) {
1044 oam_error_log0(0, 0, "{hi_wifi_any_add_peer:MAC address should be non-zero unicast address.}");
1045 return HI_FAIL;
1046 }
1047
1048 if (g_any_netdev == HI_NULL) {
1049 oam_error_log0(0, 0, "{hi_wifi_any_add_peer:g_pst_netdev is NULL, need to initialize ANY.}");
1050 return HI_FAIL;
1051 }
1052 /* **************************************************************************
1053 抛事件到wal层处理
1054 ************************************************************************** */
1055 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_ANY_ADD_PEER_INFO, sizeof(hi_wifi_any_peer_info));
1056
1057 /* 设置配置命令参数 */
1058 msg_peer_info = (hi_wifi_any_peer_info *)(write_msg.auc_value);
1059 if (memcpy_s(msg_peer_info, sizeof(hi_wifi_any_peer_info), puc_peer_info, sizeof(hi_wifi_any_peer_info)) != EOK) {
1060 oam_error_log0(0, 0, "{hi_wifi_any_del_peer::mem safe function err!}");
1061 return HI_FAIL;
1062 }
1063
1064 l_ret = (hi_s32)wal_send_cfg_event(g_any_netdev, WAL_MSG_TYPE_WRITE,
1065 WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_wifi_any_peer_info), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1066 if (oal_unlikely(l_ret != HI_SUCCESS)) {
1067 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_any_add_peer::return err code [%d]!}", l_ret);
1068 return l_ret;
1069 }
1070
1071 return HI_SUCCESS;
1072 }
1073
1074 /* ****************************************************************************
1075 函 数 名 : hi_wifi_any_del_peer
1076 功能描述 : 删除指定的点对点对端设备信息
1077 输入参数 : mac 对端MAC地址数组,只取前六字节
1078 len 数组长度
1079 返 回 值 : HI_SUCCESS 上报成功,其它错误码 上报失败
1080
1081 修改历史 :
1082 1.日 期 : 2019年1月24日
1083 作 者 : HiSilicon
1084 修改内容 : 新生成函数
1085
1086 **************************************************************************** */
hi_wifi_any_del_peer(const hi_u8 * mac,hi_u8 len)1087 hi_s32 hi_wifi_any_del_peer(const hi_u8 *mac, hi_u8 len)
1088 {
1089 wal_msg_write_stru write_msg;
1090 hi_u8 *mac_addr = HI_NULL;
1091 hi_s32 l_ret;
1092 hi_u8 auc_mac[ETH_ALEN] = {0};
1093
1094 if ((mac == HI_NULL) || (len < ETH_ALEN)) {
1095 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_any_del_peer:mac or length is invalid.}");
1096 return HI_FAIL;
1097 }
1098
1099 /* 检查对端MAC是否有效,需要为单播地址 */
1100 if (ether_is_multicast(mac) || (memcmp(auc_mac, mac, ETH_ALEN) == 0)) {
1101 oam_error_log0(0, 0, "{hi_wifi_any_del_peer:MAC address should be non-zero unicast address.}");
1102 return HI_FAIL;
1103 }
1104
1105 if (g_any_netdev == HI_NULL) {
1106 oam_error_log0(0, 0, "{hi_wifi_any_del_peer:g_pst_netdev is NULL, need to initialize ANY.}");
1107 return HI_FAIL;
1108 }
1109 /* **************************************************************************
1110 抛事件到wal层处理
1111 ************************************************************************** */
1112 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_ANY_DEL_PEER_INFO, ETH_ALEN);
1113
1114 /* 设置配置命令参数 */
1115 mac_addr = (hi_u8 *)(write_msg.auc_value);
1116 if (memcpy_s(mac_addr, ETH_ALEN, mac, ETH_ALEN) != EOK) {
1117 oam_error_log0(0, 0, "{hi_wifi_any_del_peer::mem safe function err!}");
1118 return HI_FAIL;
1119 }
1120
1121 l_ret = (hi_s32)wal_send_cfg_event(g_any_netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + ETH_ALEN,
1122 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1123 if (oal_unlikely(l_ret != HI_SUCCESS)) {
1124 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_any_del_peer::return err code [%d]!}", l_ret);
1125 return l_ret;
1126 }
1127
1128 return HI_SUCCESS;
1129 }
1130
1131 /* ****************************************************************************
1132 函 数 名 : hi_wifi_any_send
1133 功能描述 : 处理用户下发的数据,发送到ANY对端
1134 输入参数 : mac 对端MAC地址
1135 mac_len mac数组长度
1136 data 用户数据
1137 data_len 用户数据长度
1138 seq 用户下发的序列号
1139 返 回 值 : 发送成功返回HI_SUCCESS,否则返回其他值
1140
1141 修改历史 :
1142 1.日 期 : 2019年1月24日
1143 作 者 : HiSilicon
1144 修改内容 : 新生成函数
1145
1146 **************************************************************************** */
hi_wifi_any_send(const hi_u8 * mac,hi_u8 mac_len,hi_u8 * data,hi_u16 data_len,hi_u8 seq)1147 hi_s32 hi_wifi_any_send(const hi_u8 *mac, hi_u8 mac_len, hi_u8 *data, hi_u16 data_len, hi_u8 seq)
1148 {
1149 wal_msg_write_stru write_msg;
1150 oal_any_peer_param_stru peer_param;
1151 hi_u32 ret;
1152
1153 if ((mac == HI_NULL) || (mac_len != ETH_ALEN)) {
1154 oam_error_log0(0, 0, "hi_wifi_any_send: parameter NULL.");
1155 return HI_FAIL;
1156 }
1157
1158 if ((data == HI_NULL) || (data_len == 0) || (data_len > WIFI_ANY_MAX_USER_DATA)) {
1159 oam_error_log0(0, 0, "hi_wifi_any_send: data length is invalid [1-250].");
1160 return HI_FAIL;
1161 }
1162
1163 if (g_any_netdev == HI_NULL) {
1164 oam_error_log0(0, 0, "{hi_wifi_any_send: need to initialize ANY first!}");
1165 return HI_FAIL;
1166 }
1167
1168 if (memcpy_s(peer_param.auc_mac, sizeof(oal_any_peer_param_stru), mac, ETH_ALEN) != EOK) {
1169 oam_error_log0(0, 0, "{hi_wifi_any_send: mem safe function err!}");
1170 return HI_FAIL;
1171 }
1172
1173 peer_param.puc_data = data;
1174 peer_param.us_len = data_len; /* 用户真实有效的数据长度 */
1175 peer_param.seq_num = seq;
1176 peer_param.pad_num = 0; /* 后面的加密功能会自动填充对齐字节,这里不用考虑填充 */
1177 peer_param.channel = 0;
1178 peer_param.encrypt = 0;
1179 /* **************************************************************************
1180 抛事件到wal层处理
1181 ************************************************************************** */
1182 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_ANY_SEND_PEER_DATA, sizeof(oal_any_peer_param_stru));
1183
1184 /* 设置配置命令参数 */
1185 if (memcpy_s(write_msg.auc_value, WAL_MSG_WRITE_MAX_LEN, &peer_param, sizeof(oal_any_peer_param_stru)) != EOK) {
1186 oam_error_log0(0, 0, "{hi_wifi_any_send::mem safe function err!}");
1187 return HI_FAIL;
1188 }
1189
1190 ret = wal_send_cfg_event(g_any_netdev, WAL_MSG_TYPE_WRITE,
1191 WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(oal_any_peer_param_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1192 if (oal_unlikely(ret != HI_SUCCESS)) {
1193 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_any_send::return err code [%d]!}", ret);
1194 return HI_FAIL;
1195 }
1196
1197 return HI_SUCCESS;
1198 }
1199
1200 /* ****************************************************************************
1201 函 数 名 : hi_wifi_any_set_callback
1202 功能描述 : 注册ANY设备接口的报文发送和接收回调函数,之前注册过的会被覆盖替换掉
1203 输入参数 : send_cb从用户传过来的发送回调函数
1204 recv_cb从用户传过来的接收回调函数
1205 返 回 值 : 无
1206
1207 修改历史 :
1208 1.日 期 : 2019年1月24日
1209 作 者 : HiSilicon
1210 修改内容 : 新生成函数
1211
1212 **************************************************************************** */
hi_wifi_any_set_callback(hi_wifi_any_send_complete_cb send_cb,hi_wifi_any_recv_cb recv_cb)1213 hi_void hi_wifi_any_set_callback(hi_wifi_any_send_complete_cb send_cb, hi_wifi_any_recv_cb recv_cb)
1214 {
1215 wal_any_set_callback(send_cb, recv_cb);
1216 return;
1217 }
1218
1219 /* ****************************************************************************
1220 函 数 名 : hi_wifi_any_fetch_peer
1221 功能描述 : 获取指定索引对应的对端信息
1222 输入参数 : index索引值,从0开始,不超过对端个数,否则获取失败
1223 输出参数 : hi_wifi_any_peer_info 存储对端信息的结构
1224 返 回 值 : HI_SUCCESS 上报成功,其它错误码上报失败
1225
1226 修改历史 :
1227 1.日 期 : 2019年1月24日
1228 作 者 : HiSilicon
1229 修改内容 : 新生成函数
1230
1231 **************************************************************************** */
hi_wifi_any_fetch_peer(hi_u8 index,hi_wifi_any_peer_info * peer)1232 hi_s32 hi_wifi_any_fetch_peer(hi_u8 index, hi_wifi_any_peer_info *peer)
1233 {
1234 wal_msg_write_stru write_msg;
1235 hi_u32 ret;
1236 mac_vap_stru *mac_vap = HI_NULL;
1237 hmac_vap_stru *hmac_vap = HI_NULL;
1238
1239 if ((index >= HMAC_ANY_MAX_PEER_NUM) || (peer == HI_NULL)) {
1240 oam_error_log0(0, 0, "{hi_wifi_any_fetch_peer:parameter is invalid.}");
1241 return HI_FAIL;
1242 }
1243
1244 if (g_any_netdev == HI_NULL) {
1245 oam_error_log0(0, 0, "{hi_wifi_any_fetch_peer:g_pst_netdev is NULL, need to initialize ANY.}");
1246 return HI_FAIL;
1247 }
1248
1249 mac_vap = oal_net_dev_priv(g_any_netdev);
1250 if (oal_unlikely(mac_vap == HI_NULL)) {
1251 oam_error_log0(0, 0, "{hi_wifi_any_fetch_peer:the vap is NULL.}");
1252 return HI_FAIL;
1253 }
1254
1255 /* 填写事件头 */
1256 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_ANY_FETCH_PEER_INFO, 4); /* 4 事件头长度 */
1257 /* 填写消息体 */
1258 write_msg.auc_value[0] = index;
1259 ret = wal_send_cfg_event(g_any_netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + 4, /* 4 长度增4 */
1260 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1261 if (ret != HI_SUCCESS) {
1262 oam_error_log1(0, OAM_SF_ANY, "{hi_wifi_any_fetch_peer::wal_send_cfg_event return err code %d!}\r\n", ret);
1263 return HI_FAIL;
1264 }
1265
1266 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1267 if (oal_unlikely(hmac_vap == HI_NULL)) {
1268 oam_error_log0(0, 0, "{hi_wifi_any_fetch_peer:the hmac vap is NULL.}");
1269 return HI_FAIL;
1270 }
1271
1272 ret = wal_any_wait_query_result(hmac_vap, peer);
1273 if (ret != HI_SUCCESS) {
1274 return HI_FAIL;
1275 }
1276
1277 return HI_SUCCESS;
1278 }
1279
1280 /* ****************************************************************************
1281 函 数 名 : hi_wifi_any_discover_peer
1282 功能描述 : 发起扫描发现ANY对端设备信息,包括MAC地址,信道和接收到的cookie等信息
1283 输入参数 : hi_wifi_any_scan_result_cb 扫描完成之后的结果回调处理函数
1284 返 回 值 : 成功返回0,失败返回-1
1285
1286 修改历史 :
1287 1.日 期 : 2019年1月24日
1288 作 者 : HiSilicon
1289 修改内容 : 新生成函数
1290
1291 **************************************************************************** */
hi_wifi_any_discover_peer(hi_wifi_any_scan_result_cb cb)1292 hi_s32 hi_wifi_any_discover_peer(hi_wifi_any_scan_result_cb cb)
1293 {
1294 wal_any_set_scan_callback(cb);
1295
1296 /* 发起扫描 */
1297 return wal_any_global_config(WLAN_CFGID_ANY_SCAN, g_any_netdev);
1298 }
1299 #endif
1300
1301 #ifdef _PRE_WLAN_FEATURE_WOW
1302 /* 设置 唤醒包帧体内容 */
hi_wifi_wow_set_pattern(const hi_char * ifname,hi_u32 type,hi_u8 index,hi_char * pattern)1303 hi_u8 hi_wifi_wow_set_pattern(const hi_char *ifname, hi_u32 type, hi_u8 index, hi_char *pattern)
1304 {
1305 hi_u32 ret;
1306 wal_msg_write_stru write_msg;
1307 oal_net_device_stru *netdev = HI_NULL;
1308 hmac_cfg_wow_pattern_param_stru cfg_wow_param = { 0 };
1309
1310 netdev = oal_get_netdev_by_name(ifname);
1311 if (netdev == HI_NULL) {
1312 oam_error_log0(0, 0, "hi_wifi_wow_set_pattern:: device not found.");
1313 return HI_FAIL;
1314 }
1315
1316 if (type > HI_WOW_PATTERN_CLR) {
1317 oam_error_log0(0, 0, "hi_wifi_wow_set_pattern:: type is invalid");
1318 return HI_FAIL;
1319 }
1320
1321 if (type == HI_WOW_PATTERN_ADD) {
1322 ret = wal_get_add_wow_pattern_param(index, pattern, &cfg_wow_param);
1323 if (ret != HI_SUCCESS) {
1324 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_wow_set_pattern::get add param failed.}");
1325 return HI_FAIL;
1326 }
1327 /* 设置pattern value参数 */
1328 if (memcpy_s(&((hmac_cfg_wow_pattern_param_stru *)(write_msg.auc_value))->auc_pattern_value[0],
1329 WAL_HIPRIV_CMD_NAME_MAX_LEN, cfg_wow_param.auc_pattern_value, cfg_wow_param.pattern_len) != EOK) {
1330 oam_error_log0(0, OAM_SF_ANY, "{wal_hipriv_set_wow_pattern::copy pattern value failed.}");
1331 return HI_FAIL;
1332 }
1333 } else if (type == HI_WOW_PATTERN_DEL) {
1334 if (index >= WOW_NETPATTERN_MAX_NUM) {
1335 oam_error_log1(0, 0, "hi_wifi_wow_set_pattern:: invalid_index[%d]", index);
1336 return HI_FAIL;
1337 }
1338 cfg_wow_param.us_pattern_option = MAC_WOW_PATTERN_PARAM_OPTION_DEL;
1339 cfg_wow_param.us_pattern_index = index;
1340 } else if (type == HI_WOW_PATTERN_CLR) {
1341 cfg_wow_param.us_pattern_option = MAC_WOW_PATTERN_PARAM_OPTION_CLR;
1342 } else {
1343 oam_warning_log0(0, 0, "hi_wifi_wow_set_pattern:: invaliad patter OPTION");
1344 return HI_FAIL;
1345 }
1346
1347 /* **************************************************************************
1348 抛事件到wal层处理
1349 ************************************************************************** */
1350 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_SET_WOW_PATTERN, sizeof(hmac_cfg_wow_pattern_param_stru));
1351 /* 设置pattern option参数 */
1352 ((hmac_cfg_wow_pattern_param_stru *)(write_msg.auc_value))->us_pattern_option = cfg_wow_param.us_pattern_option;
1353 /* 设置pattern index参数 */
1354 ((hmac_cfg_wow_pattern_param_stru *)(write_msg.auc_value))->us_pattern_index = cfg_wow_param.us_pattern_index;
1355 /* 设置pattern pattern len参数 */
1356 ((hmac_cfg_wow_pattern_param_stru *)(write_msg.auc_value))->pattern_len = cfg_wow_param.pattern_len;
1357 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE,
1358 WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hmac_cfg_wow_pattern_param_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1359 if (oal_unlikely(ret != HI_SUCCESS)) {
1360 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_wow_set_pattern:: return err code[%u]!}", ret);
1361 }
1362 return ret;
1363 }
1364
1365 /* wow 唤醒/睡眠请求 */
hi_wifi_wow_host_sleep_switch(const hi_char * ifname,hi_u8 en)1366 hi_u8 hi_wifi_wow_host_sleep_switch(const hi_char *ifname, hi_u8 en)
1367 {
1368 wal_msg_write_stru write_msg;
1369 oal_net_device_stru *netdev = HI_NULL;
1370 hi_u32 ret;
1371
1372 netdev = oal_get_netdev_by_name(ifname);
1373 if (netdev == HI_NULL) {
1374 oam_error_log0(0, 0, "hi_wifi_wow_enable_switch:: device not found.");
1375 return HI_FAIL;
1376 }
1377
1378 if ((en != 0) && (en != 1)) { /* 0: disable, 1: enable */
1379 oam_error_log1(0, 0, "hi_wifi_wow_host_sleep_switch:: invalid enable value[%d]", en);
1380 return HI_FAIL;
1381 }
1382
1383 /* **************************************************************************
1384 抛事件到wal层处理
1385 ************************************************************************** */
1386 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_WOW_ACTIVATE_EN, sizeof(hi_s32));
1387 *((hi_u8 *)(write_msg.auc_value)) = en; /* 设置配置命令参数 */
1388
1389 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_s32),
1390 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1391 if (oal_unlikely(ret != HI_SUCCESS)) {
1392 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_wow_enable_switch::return err code[%u]!}", ret);
1393 return ret;
1394 }
1395
1396 /* **************************************************************************
1397 抛事件到wal层处理
1398 ************************************************************************** */
1399 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_HOST_SLEEP_EN, sizeof(hi_s32));
1400 *((hi_s32 *)(write_msg.auc_value)) = en; /* 设置配置命令参数 */
1401
1402 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_s32),
1403 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1404 if (oal_unlikely(ret != HI_SUCCESS)) {
1405 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_wow_host_sleep_switch::return err code[%u]!}\r\n", ret);
1406 return ret;
1407 }
1408
1409 return HI_SUCCESS;
1410 }
1411 #endif
1412
1413 #ifdef _PRE_WLAN_FEATURE_ARP_OFFLOAD
1414 /* ****************************************************************************
1415 功能描述 : arp offload 开启/关闭
1416 输入参数 : [1] en 1-开启,0-关闭
1417 [2] ip ip地址,注意必须是32bit主机字节序
1418 返 回 值 : 成功返回0,失败返回-1
1419
1420 修改历史 :
1421 1.日 期 : 2019年10月17日
1422 作 者 : HiSilicon
1423 修改内容 : 新生成函数
1424 **************************************************************************** */
hi_wifi_arp_offload_setting(const hi_char * ifname,hi_u8 en,hi_u32 ip)1425 hi_u8 hi_wifi_arp_offload_setting(const hi_char *ifname, hi_u8 en, hi_u32 ip)
1426 {
1427 wal_msg_write_stru write_msg;
1428 oal_net_device_stru *netdev = HI_NULL;
1429 hi_u32 ret;
1430 hi_u16 len;
1431 mac_ip_addr_config_stru ip_addr_cfg = {0};
1432
1433 netdev = oal_get_netdev_by_name(ifname);
1434 if (netdev == HI_NULL) {
1435 oam_error_log0(0, 0, "hi_wifi_arp_offload_setting:: device not found.");
1436 return HI_FAIL;
1437 }
1438
1439 if (en >= MAC_IP_OPER_BUTT) {
1440 oam_error_log0(0, 0, "hi_wifi_arp_offload_setting:: en error.");
1441 return HI_FAIL;
1442 }
1443
1444 ip_addr_cfg.type = MAC_CONFIG_IPV4;
1445 ip_addr_cfg.oper = en;
1446 ip_addr_cfg.ip.ipv4 = ip;
1447 /* 打印IPV4地址[2]和[3] */
1448 oam_info_log3(0, 0, "{hi_wifi_arp_offload_setting:: oper: %d, ip[xx.xx.%d.%d] succ.}", en,
1449 *(((hi_char *)&ip_addr_cfg.ip.ipv4) + 2), *(((hi_char *)&ip_addr_cfg.ip.ipv4) + 3)); /* 2/3 偏置 */
1450
1451 /* **************************************************************************
1452 抛事件到wal层处理
1453 ************************************************************************** */
1454 if (memcpy_s(write_msg.auc_value, sizeof(mac_ip_addr_config_stru), (const hi_void *)&ip_addr_cfg,
1455 sizeof(mac_ip_addr_config_stru)) != EOK) {
1456 oam_error_log0(0, 0, "{hi_wifi_arp_offload_setting:: mem safe function err!}");
1457 return HI_FAIL;
1458 }
1459 len = sizeof(mac_ip_addr_config_stru);
1460
1461 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_ARP_OFFLOAD_SETTING, len);
1462 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + len, (hi_u8 *)&write_msg,
1463 HI_FALSE, HI_NULL);
1464 if (oal_unlikely(ret != HI_SUCCESS)) {
1465 oam_warning_log1(0, OAM_SF_PWR, "{hi_wifi_arp_offload_setting:: wal_send_cfg_event error[%u]!}\r\n", ret);
1466 return ret;
1467 }
1468
1469 return HI_SUCCESS;
1470 }
1471 #endif
1472
1473 #ifdef _PRE_WLAN_FEATURE_DHCP_OFFLOAD
1474 /* ****************************************************************************
1475 功能描述 : dhcp offload 开启/关闭
1476 输入参数 : [1] en 1-开启,0-关闭
1477 [2] ip ip地址,注意必须是32bit主机字节序
1478 返 回 值 : 成功返回0,失败返回-1
1479
1480 修改历史 :
1481 1.日 期 : 2019年10月17日
1482 作 者 : HiSilicon
1483 修改内容 : 新生成函数
1484 **************************************************************************** */
hi_wifi_dhcp_offload_setting(const hi_char * ifname,hi_u8 en,hi_u32 ip)1485 hi_u8 hi_wifi_dhcp_offload_setting(const hi_char *ifname, hi_u8 en, hi_u32 ip)
1486 {
1487 wal_msg_write_stru write_msg;
1488 oal_net_device_stru *netdev = HI_NULL;
1489 hi_u32 ret;
1490 hi_u16 len;
1491 mac_ip_addr_config_stru ip_addr_cfg = {0};
1492
1493 if (ifname == HI_NULL) {
1494 oam_error_log0(0, 0, "{hi_wifi_dhcp_offload_setting:: ifname is NULL.}");
1495 return HI_FAIL;
1496 }
1497
1498 netdev = oal_get_netdev_by_name(ifname);
1499 if (netdev == HI_NULL) {
1500 oam_error_log0(0, 0, "hi_wifi_dhcp_offload_setting:: device not found.");
1501 return HI_FAIL;
1502 }
1503
1504 if (en >= MAC_IP_OPER_BUTT) {
1505 oam_error_log0(0, 0, "hi_wifi_dhcp_offload_setting:: en error.");
1506 return HI_FAIL;
1507 }
1508
1509 ip_addr_cfg.type = MAC_CONFIG_IPV4;
1510 ip_addr_cfg.oper = en;
1511 ip_addr_cfg.ip.ipv4 = ip;
1512 /* 打印IPV4地址[2]和[3] */
1513 oam_info_log3(0, 0, "{hi_wifi_dhcp_offload_setting:: oper: %d, ip[xx.xx.%d.%d] succ.}", en,
1514 *(((hi_char *)&ip_addr_cfg.ip.ipv4) + 2), *(((hi_char *)&ip_addr_cfg.ip.ipv4) + 3)); /* 2/3 偏置 */
1515
1516 /* **************************************************************************
1517 抛事件到wal层处理
1518 ************************************************************************** */
1519 if (memcpy_s(write_msg.auc_value, sizeof(mac_ip_addr_config_stru), (const hi_void *)&ip_addr_cfg,
1520 sizeof(mac_ip_addr_config_stru)) != EOK) {
1521 oam_error_log0(0, 0, "{hi_wifi_dhcp_offload_setting:: mem safe function err!}");
1522 return HI_FAIL;
1523 }
1524 len = sizeof(mac_ip_addr_config_stru);
1525
1526 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_DHCP_OFFLOAD_SETTING, len);
1527 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + len, (hi_u8 *)&write_msg,
1528 HI_FALSE, HI_NULL);
1529 if (oal_unlikely(ret != HI_SUCCESS)) {
1530 oam_warning_log1(0, OAM_SF_PWR, "{hi_wifi_dhcp_offload_setting:: wal_send_cfg_event error[%u]!}\r\n", ret);
1531 return ret;
1532 }
1533
1534 return HI_SUCCESS;
1535 }
1536 #endif
1537
1538 #ifdef _PRE_WLAN_FEATURE_BTCOEX
hi_wifi_btcoex_enable(const hi_char * ifname,hi_bool enable,hi_u8 mode,hi_u8 share_ant)1539 hi_u32 hi_wifi_btcoex_enable(const hi_char *ifname, hi_bool enable, hi_u8 mode, hi_u8 share_ant)
1540 {
1541 wal_msg_write_stru write_msg;
1542 oal_net_device_stru *netdev = HI_NULL;
1543 hi_u32 ret;
1544 hi_u16 len;
1545
1546 if (ifname == HI_NULL) {
1547 oam_error_log0(0, 0, "{hi_wifi_btcoex_enable:: ifname is NULL.}");
1548 return HI_FAIL;
1549 }
1550
1551 netdev = oal_get_netdev_by_name(ifname);
1552 if (netdev == HI_NULL) {
1553 oam_error_log0(0, 0, "hi_wifi_btcoex_enable:: device not found.");
1554 return HI_FAIL;
1555 }
1556
1557 if (enable == 0) {
1558 *(hi_u8 *)(write_msg.auc_value) = enable;
1559 len = sizeof(hi_u8);
1560 } else if (enable == 1) {
1561 write_msg.auc_value[0] = enable;
1562 write_msg.auc_value[1] = mode;
1563 write_msg.auc_value[2] = share_ant; /* 2: 第3位 */
1564 len = sizeof(hi_u8) * 3; /* 个数为3 */
1565 } else {
1566 oam_warning_log0(0, OAM_SF_COEX, "{hi_wifi_btcoex_enable::input parameter error!}\r\n");
1567 return HI_SUCCESS;
1568 }
1569 /* **************************************************************************
1570 抛事件到wal层处理
1571 ************************************************************************** */
1572 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_BTCOEX_ENABLE, len);
1573 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + len, (hi_u8 *)&write_msg,
1574 HI_FALSE, HI_NULL);
1575 if (oal_unlikely(ret != HI_SUCCESS)) {
1576 oam_warning_log1(0, OAM_SF_PWR, "{hi_wifi_btcoex_enable:: wal_send_cfg_event error[%u]!}\r\n", ret);
1577 return ret;
1578 }
1579
1580 return HI_SUCCESS;
1581 }
1582 #endif
1583
1584 /* ****************************************************************************
1585 功能描述 :
1586 输入参数 : [1]type 重传设置类型:1、设置数据帧重传 2、设置管理帧重传 3、设置时间重传
1587 [2]limit 重传限制:重传次数0~15,重传时间0~200
1588 输出参数 : 无
1589 返 回 值: 是否成功
1590 **************************************************************************** */
hi_wifi_set_retry_params(const hi_char * ifname,hi_u8 type,hi_u8 limit)1591 hi_u32 hi_wifi_set_retry_params(const hi_char *ifname, hi_u8 type, hi_u8 limit)
1592 {
1593 oal_net_device_stru *netdev = HI_NULL;
1594 mac_cfg_retry_param_stru *set_param = HI_NULL;
1595 wal_msg_write_stru write_msg;
1596 hi_u32 ret;
1597
1598 if (ifname == HI_NULL) {
1599 oam_error_log0(0, 0, "{hi_wifi_set_retry_params:: ifname is NULL.}");
1600 return HI_FAIL;
1601 }
1602
1603 netdev = oal_get_netdev_by_name(ifname);
1604 if (netdev == HI_NULL) {
1605 oam_error_log0(0, 0, "hi_wifi_set_retry_params:: device not found.");
1606 return HI_FAIL;
1607 }
1608
1609 if (type >= MAC_CFG_RETRY_TYPE_BUTT) {
1610 oam_error_log0(0, 0, "hi_wifi_set_retry_params:: type is invalid.");
1611 return HI_FAIL;
1612 }
1613
1614 if (type == MAC_CFG_RETRY_DATA || type == MAC_CFG_RETRY_MGMT) {
1615 if (limit > HI_WIFI_RETRY_MAX_NUM) {
1616 oam_error_log0(0, 0, "hi_wifi_set_retry_params:: tpye is date or mgmt,limit is invalid.");
1617 return HI_FAIL;
1618 }
1619 }
1620
1621 if (type == MAC_CFG_RETRY_TIMEOUT) {
1622 if (limit > HI_WIFI_RETRY_MAX_TIME) {
1623 oam_error_log0(0, 0, "hi_wifi_set_retry_params:: tpye is timeout,limit is invalid.");
1624 return HI_FAIL;
1625 }
1626 }
1627
1628 set_param = (mac_cfg_retry_param_stru *)(write_msg.auc_value);
1629 set_param->type = type;
1630 set_param->limit = limit;
1631
1632 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_SET_RETRY_LIMIT, sizeof(mac_cfg_retry_param_stru));
1633
1634 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE,
1635 WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(mac_cfg_retry_param_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1636 if (oal_unlikely(ret != HI_SUCCESS)) {
1637 oam_warning_log1(0, OAM_SF_ANY, "{wal_hipriv_set_retry_limit::return err code [%u]!}\r\n", ret);
1638 return HI_FAIL;
1639 }
1640
1641 return HI_SUCCESS;
1642 }
1643
hi_wifi_set_cca_threshold(const hi_char * ifname,hi_s8 threshold)1644 hi_u32 hi_wifi_set_cca_threshold(const hi_char *ifname, hi_s8 threshold)
1645 {
1646 wal_msg_write_stru write_msg = {0};
1647 hi_s32 *param = HI_NULL;
1648 oal_net_device_stru *netdev = HI_NULL;
1649 hi_u32 ret;
1650
1651 if (ifname == HI_NULL) {
1652 oam_error_log0(0, 0, "{hi_wifi_set_cca_threshold:: ifname is NULL.}");
1653 return HI_FAIL;
1654 }
1655 netdev = oal_get_netdev_by_name(ifname);
1656 if (netdev == HI_NULL) {
1657 oam_error_log0(0, 0, "hi_wifi_set_cca_threshold:: device not found.");
1658 return HI_FAIL;
1659 }
1660 /* 低功耗状态下不允许执行 */
1661 if (is_under_ps()) {
1662 oam_warning_log0(0, 0, "under ps mode,can not exec cmd");
1663 return HI_FAIL;
1664 }
1665 /* 解析并设置配置命令参数 */
1666 param = (hi_s32 *)(write_msg.auc_value);
1667 *param = threshold;
1668
1669 /* **************************************************************************
1670 抛事件到wal层处理
1671 ************************************************************************** */
1672 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_SET_CCA_TH, sizeof(hi_s32));
1673
1674 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_s32),
1675 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1676 if (oal_unlikely(ret != HI_SUCCESS)) {
1677 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_set_cca_threshold::return err code [%u]!}\r\n", ret);
1678 return ret;
1679 }
1680
1681 return HI_SUCCESS;
1682 }
1683
hi_wifi_set_tpc(const char * ifname,unsigned char ifname_len,hi_u32 tpc_value)1684 hi_u32 hi_wifi_set_tpc(const char *ifname, unsigned char ifname_len, hi_u32 tpc_value)
1685 {
1686 oal_net_device_stru *netdev = HI_NULL;
1687 hi_u32 mode;
1688 hi_char ifname_cpy[WIFI_IFNAME_MAX_SIZE + 1] = {0};
1689 hi_char *ptr_ifname_cpy = ifname_cpy;
1690
1691 if (memcpy_s(ifname_cpy, sizeof(ifname_cpy), ifname, ifname_len) != EOK) {
1692 return HI_FAIL;
1693 }
1694 /* 低功耗状态下不允许执行 */
1695 if (is_under_ps()) {
1696 oam_warning_log0(0, 0, "under ps mode,can not exec cmd");
1697 return HI_FAIL;
1698 }
1699 netdev = oal_get_netdev_by_name(ptr_ifname_cpy);
1700 if (netdev == HI_NULL) {
1701 oam_error_log0(0, 0, "hi_wifi_set_tpc:: device not found.");
1702 return HI_FAIL;
1703 }
1704 if ((tpc_value != 0) && (tpc_value != 1)) {
1705 oam_error_log0(0, OAM_SF_ANY, "{hi_wifi_set_tpc::tpc_value invalid!}");
1706 return HI_FAIL;
1707 }
1708 mode = (tpc_value == 0) ? 0 : 2; /* 0:禁用tpc模式,2:自适应功率模式 */
1709 wal_set_tpc_mode(netdev, mode);
1710
1711 return HI_SUCCESS;
1712 }
1713
1714 /* 从device侧获取算法计算的各种不同业务类型的实际流量
1715 * 由于3881芯片host、device分离,没有直接从device获取数据的途径,因此采用异步流程
1716 * 在host发送事件通知device进行处理,随后device通过sdio report机制异步上报host
1717 */
hi_wifi_get_tx_params(const char * ifname,unsigned char ifname_len)1718 hi_u32 hi_wifi_get_tx_params(const char *ifname, unsigned char ifname_len)
1719 {
1720 hi_u32 ret;
1721 oal_net_device_stru *netdev = HI_NULL;
1722 wal_msg_write_stru write_msg = { 0 };
1723 hi_char ifname_cpy[WIFI_IFNAME_MAX_SIZE + 1] = {0};
1724
1725 if (ifname == HI_NULL) {
1726 oam_error_log0(0, 0, "{hi_wifi_get_tx_params:: input point is NULL}");
1727 return HI_FAIL;
1728 }
1729
1730 if (memcpy_s(ifname_cpy, sizeof(ifname_cpy), ifname, ifname_len) != EOK) {
1731 oam_error_log0(0, 0, "{hi_wifi_get_tx_params:: input param is invalid}");
1732 return HI_FAIL;
1733 }
1734
1735 netdev = oal_get_netdevice_by_name(ifname_cpy, sizeof(ifname_cpy));
1736 if (netdev == HI_NULL) {
1737 oam_error_log0(0, 0, "hi_wifi_get_tx_params:: device not found.");
1738 return HI_FAIL;
1739 }
1740
1741 wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_NOTIFY_GET_TX_PARAMS, sizeof(hi_u32));
1742 ret = wal_send_cfg_event(netdev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_u32),
1743 (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1744 if (oal_unlikely(ret != HI_SUCCESS)) {
1745 oam_warning_log1(0, OAM_SF_ANY, "{hi_wifi_get_tx_params::return err code [%u]!}\r\n", ret);
1746 return ret;
1747 }
1748
1749 return HI_SUCCESS;
1750 }
1751
hi_wifi_register_tx_params_callback(hi_wifi_report_tx_params_callback func)1752 hi_void hi_wifi_register_tx_params_callback(hi_wifi_report_tx_params_callback func)
1753 {
1754 wal_register_tx_params_callback(func);
1755 }
1756
1757
hi_wifi_register_driver_event_callback(hi_wifi_driver_event_cb event_cb)1758 int hi_wifi_register_driver_event_callback(hi_wifi_driver_event_cb event_cb)
1759 {
1760 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
1761 if (oal_register_ioctl(event_cb) != HI_SUCCESS) {
1762 return HISI_FAIL;
1763 }
1764 return HISI_OK;
1765 #else
1766 return HISI_OK;
1767 #endif
1768 }
1769
hi_wifi_soft_reset_device(hi_void)1770 hi_s32 hi_wifi_soft_reset_device(hi_void)
1771 {
1772 hi_wifi_plat_pm_disable();
1773 oal_sdio_sleep_dev(oal_get_sdio_default_handler());
1774 return oal_sdio_send_msg(oal_get_sdio_default_handler(), H2D_MSG_PM_WLAN_OFF);
1775 }
1776
1777 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
1778 oal_module_init(hi_linux_wifi_init);
1779 oal_module_exit(hi_linux_wifi_deinit);
1780
1781 MODULE_LICENSE("GPL");
1782 MODULE_DESCRIPTION("Hisilicon Wireless Lan Driver");
1783 MODULE_AUTHOR("Hisilicon Wifi Team");
1784 MODULE_VERSION("V1.0.0_000.20191223");
1785 #endif
1786
1787 #ifdef __cplusplus
1788 #if __cplusplus
1789 }
1790 #endif
1791 #endif
1792