• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "oam_ext_if.h"
23 #include "frw_timer.h"
24 #include "dmac_ext_if.h"
25 #include "hmac_user.h"
26 #include "hmac_main.h"
27 #include "hmac_protection.h"
28 #include "hmac_ext_if.h"
29 #include "hmac_config.h"
30 #include "hmac_chan_mgmt.h"
31 #include "hmac_event.h"
32 #include "hcc_hmac_if.h"
33 #ifdef _PRE_WLAN_FEATURE_MESH
34 #include "wlan_types.h"
35 #include "hmac_vap.h"
36 #endif
37 
38 #ifdef __cplusplus
39 #if __cplusplus
40 extern "C" {
41 #endif
42 #endif
43 
44 /* ****************************************************************************
45   2 全局变量定义
46 **************************************************************************** */
47 /* hmac user资源指针 根据配置的user数量在hmac main init时申请,exit时释放 */
48 hi_u8 *g_puc_hmac_user_res = HI_NULL;
49 
50 /* ****************************************************************************
51   3 函数实现
52 **************************************************************************** */
53 /* ****************************************************************************
54  功能描述  : hmac 用户资源池初始化
55  修改历史      :
56   1.日    期   : 2019年5月30日
57     作    者   : HiSilicon
58     修改内容   : 新生成函数
59 **************************************************************************** */
hmac_user_res_init(hi_void)60 hi_u32 hmac_user_res_init(hi_void)
61 {
62     hi_u8       index;
63     hi_u8       user_num = mac_user_get_user_num();
64     hi_u32      ret;
65     /* 有逻辑保证size不可能为0或者溢出 此处不做判断 */
66     hi_u32      user_size = sizeof(hmac_user_stru) * user_num;
67     hmac_user_stru  *hmac_user = HI_NULL;
68     mac_user_stru   *mac_user  = HI_NULL;
69 
70     ret = mac_user_res_init(user_num);
71     if (ret != HI_SUCCESS) {
72         oam_error_log0(0, OAM_SF_ANY, "{hmac_user_res_init::mac_user_res_init failed.}");
73         return HI_ERR_CODE_ALLOC_MEM_FAIL;
74     }
75     /* 不为空,重复调用初始化函数,不允许,失败 */
76     if (g_puc_hmac_user_res != HI_NULL) {
77         oam_error_log0(0, OAM_SF_ANY, "{hmac_user_res_init::re-mem alloc user res.}");
78         return HI_FAIL;
79     }
80     /* 动态申请用户资源池相关内存 */
81     g_puc_hmac_user_res = (hi_u8 *)oal_memalloc(user_size);
82     if (g_puc_hmac_user_res == HI_NULL) {
83         oam_error_log0(0, OAM_SF_ANY, "{hmac_user_res_init::mem alloc user res null.}");
84         return HI_ERR_CODE_ALLOC_MEM_FAIL;
85     }
86     /* 安全编程规则6.6例外(3)从堆中分配内存后,赋予初值 */
87     memset_s(g_puc_hmac_user_res, user_size, 0, user_size);
88     /* 将mac user资源一一匹配到hmac user */
89     for (index = 0; index < user_num; index++) {
90         hmac_user = ((hmac_user_stru *)g_puc_hmac_user_res) + index;
91         mac_user  = (mac_user_stru *)mac_user_init_get_user_stru(index);
92         hmac_user->base_user = mac_user;
93     }
94     return HI_SUCCESS;
95 }
96 
97 /* ****************************************************************************
98  功能描述  : hmac 用户资源池去初始化
99  修改历史      :
100   1.日    期   : 2019年5月30日
101     作    者   : HiSilicon
102     修改内容   : 新生成函数
103 **************************************************************************** */
hmac_user_res_exit(hi_void)104 hi_void hmac_user_res_exit(hi_void)
105 {
106     mac_user_res_exit(); /* 先释放mac user资源 */
107     if (g_puc_hmac_user_res != HI_NULL) {
108         oal_free(g_puc_hmac_user_res);
109         g_puc_hmac_user_res = HI_NULL;
110     }
111 }
112 
113 /* ****************************************************************************
114  功能描述  : 获取对应HMAC USER索引的内存 由HMAC层强转为自己的内存解析
115  输入参数  : 对应HMAC USER内存索引
116  返 回 值  : 对应内存地址
117  修改历史      :
118   1.日    期   : 2019年5月30日
119     作    者   : HiSilicon
120     修改内容   : 新生成函数
121 **************************************************************************** */
hmac_user_get_user_stru(hi_u8 idx)122 hi_u8 *hmac_user_get_user_stru(hi_u8 idx)
123 {
124     hi_u8 user_num = mac_user_get_user_num();
125     if ((g_puc_hmac_user_res == HI_NULL) || (idx >= user_num)) {
126         return HI_NULL;
127     }
128     return (g_puc_hmac_user_res + sizeof(hmac_user_stru) * idx);
129 }
130 
131 /* ****************************************************************************
132  功能描述  : 创建HMAC用户实体
133  输出参数  : puc_user_idx-用户内存索引
134  返 回 值  : 成功或失败原因
135  修改历史      :
136   1.日    期   : 2012年12月11日
137     作    者   : HiSilicon
138     修改内容   : 新生成函数
139 **************************************************************************** */
hmac_user_alloc(hi_u8 * puc_user_idx)140 hi_u32 hmac_user_alloc(hi_u8 *puc_user_idx)
141 {
142     mac_user_stru   *mac_user  = HI_NULL;
143     hmac_user_stru  *hmac_user = HI_NULL;
144     hi_u8            user_idx;
145 
146     /* 申请hmac user内存 */
147     user_idx = mac_user_alloc_user_res();
148     if (user_idx == MAC_INVALID_USER_ID) {
149         oam_error_log0(0, OAM_SF_UM, "{hmac_user_alloc::alloc user id failed.}");
150         return HI_FAIL;
151     }
152     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_idx);
153     if (hmac_user == HI_NULL) {
154         mac_user_free_user_res(user_idx);
155         oam_error_log1(0, OAM_SF_UM, "{hmac_user_alloc::pst_hmac_user null,user_idx=%d.}", user_idx);
156         return HI_ERR_CODE_PTR_NULL;
157     }
158     /* 重复申请异常,避免影响业务,暂时打印error但正常申请 */
159     if ((hmac_user->base_user) && (hmac_user->base_user->is_user_alloced == MAC_USER_ALLOCED)) {
160         oam_warning_log1(0, OAM_SF_UM, "{hmac_user_get_user_stru::[E]user has been alloced,user_idx=%d.}", user_idx);
161     }
162     /* 保存mac user指针,保持对应关系 */
163     mac_user = hmac_user->base_user;
164     if (memset_s(hmac_user, sizeof(hmac_user_stru), 0, sizeof(hmac_user_stru) - sizeof(uintptr_t)) != EOK) {
165         mac_user_free_user_res(user_idx);
166         return HI_FAIL;
167     }
168     hmac_user->base_user = mac_user;
169     /* 重新获取user指针并hmac与mac的一一匹配关系 匹配关系被修改返回失败 */
170     mac_user = (mac_user_stru *)mac_user_init_get_user_stru(user_idx);
171     if (hmac_user->base_user != mac_user) {
172         mac_user_free_user_res(user_idx);
173         oam_error_log1(0, OAM_SF_UM, "{hmac_user_alloc::idx mismatch, user_idx=%d.}", user_idx);
174         return HI_FAIL;
175     }
176     /* 标记user资源已被alloc */
177     mac_user->is_user_alloced = MAC_USER_ALLOCED;
178     *puc_user_idx = user_idx;
179     return HI_SUCCESS;
180 }
181 
182 /* ****************************************************************************
183  功能描述  : 释放对应HMAC USER的内存
184  输入参数  : 对应HMAC USER内存索引
185  修改历史      :
186   1.日    期   : 2015年11月3日
187     作    者   : HiSilicon
188     修改内容   : 新生成函数
189 **************************************************************************** */
hmac_user_free(hi_u8 idx)190 hi_u32 hmac_user_free(hi_u8 idx)
191 {
192     hmac_user_stru *hmac_user = HI_NULL;
193 
194     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(idx);
195     if ((hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL)) {
196         oam_error_log1(0, OAM_SF_UM, "{hmac_user_free::user point null,user_idx=%d.}", idx);
197         return HI_ERR_CODE_PTR_NULL;
198     }
199     /* 重复释放异常, 继续释放不返回 */
200     if (hmac_user->base_user->is_user_alloced == MAC_USER_FREED) {
201         oam_warning_log1(0, OAM_SF_UM, "{hmac_user_free::[E]user has been freed,user_idx=%d.}", idx);
202     }
203     hmac_user->base_user->is_user_alloced = MAC_USER_FREED;
204     mac_user_free_user_res(idx);
205     oam_warning_log1(0, OAM_SF_ANY, "{hmac_user_free::user_idx=%d.}", idx);
206     return HI_SUCCESS;
207 }
208 
209 /* ****************************************************************************
210  函 数 名  : hmac_user_set_avail_num_space_stream
211  功能描述  : 获取用户和VAP公共可用的空间流数
212  输入参数  : 无
213  输出参数  : 无
214  返 回 值  :
215  调用函数  :
216  被调函数  :
217 
218  修改历史      :
219   1.日    期   : 2013年10月16日
220     作    者   : HiSilicon
221     修改内容   : 新生成函数
222 
223 **************************************************************************** */
hmac_user_set_avail_num_space_stream(mac_user_stru * mac_user,wlan_nss_enum_uint8 vap_nss)224 hi_u32 hmac_user_set_avail_num_space_stream(mac_user_stru *mac_user, wlan_nss_enum_uint8 vap_nss)
225 {
226     hi_u32                        ret = HI_SUCCESS;
227 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
228     mac_vap_stru                 *mac_vap = HI_NULL;
229     mac_user_nss_stru             user_nss;
230 #endif
231     hi_unref_param(vap_nss);
232     mac_user_set_num_spatial_stream(mac_user, WLAN_SINGLE_NSS);
233     mac_user_set_avail_num_spatial_stream(mac_user, WLAN_SINGLE_NSS);
234 
235 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
236     /* 空间流信息同步dmac */
237     mac_vap = mac_vap_get_vap_stru(mac_user->vap_id);
238     if (mac_vap == HI_NULL) {
239         oam_error_log1(mac_user->vap_id, OAM_SF_CFG, "hmac_user_set_avail_num_space_stream::mac vap(idx=%d) is null!",
240             mac_user->vap_id);
241         return ret;
242     }
243     user_nss.avail_num_spatial_stream = mac_user->avail_num_spatial_stream;
244     user_nss.num_spatial_stream       = mac_user->num_spatial_stream;
245     user_nss.user_idx = (hi_u8)mac_user->us_assoc_id;
246     ret = hmac_config_send_event(mac_vap, WLAN_CFGID_NSS, sizeof(mac_user_nss_stru), (hi_u8 *)(&user_nss));
247     if (oal_unlikely(ret != HI_SUCCESS)) {
248         oam_warning_log1(mac_user->vap_id, OAM_SF_CFG,
249             "{hmac_user_set_avail_num_space_stream::hmac_config_send_event failed[%d].}", ret);
250     }
251 #endif
252     return ret;
253 }
254 
255 #ifdef _PRE_WLAN_FEATURE_PMF
256 /* ****************************************************************************
257  函 数 名  : hmac_stop_sa_query_timer
258  功能描述  : 删除sa query timer
259  输入参数  : 无
260  输出参数  : 无
261  返 回 值  :
262  调用函数  :
263  被调函数  :
264 
265  修改历史      :
266   1.日    期   : 2015年2月27日
267     作    者   : HiSilicon
268     修改内容   : 新生成函数
269 
270 **************************************************************************** */
hmac_stop_sa_query_timer(hmac_user_stru * hmac_user)271 static hi_void hmac_stop_sa_query_timer(hmac_user_stru *hmac_user)
272 {
273     frw_timeout_stru *sa_query_interval_timer = HI_NULL;
274 
275     sa_query_interval_timer = &(hmac_user->sa_query_info.sa_query_interval_timer);
276     if (sa_query_interval_timer->is_registerd != HI_FALSE) {
277         frw_timer_immediate_destroy_timer(sa_query_interval_timer);
278     }
279 
280     /* 删除timers的入参存储空间 */
281     if (sa_query_interval_timer->timeout_arg != HI_NULL) {
282         oal_mem_free((hi_void *)sa_query_interval_timer->timeout_arg);
283         sa_query_interval_timer->timeout_arg = HI_NULL;
284     }
285 }
286 #endif
287 
288 /* ****************************************************************************
289  函 数 名  : hmac_user_get_wapi_ptr
290  功能描述  : 获取用户的wapi对象指针
291  输入参数  :
292  输出参数  : hi_void
293  返 回 值  : 无
294  调用函数  : 无
295  被调函数  : 无
296 
297  修改历史      :
298   1.日    期   : 2015年5月29日
299     作    者   : HiSilicon
300     修改内容   : 新生成函数
301 **************************************************************************** */
302 #ifdef _PRE_WLAN_FEATURE_WAPI
hmac_user_get_wapi_ptr(const mac_vap_stru * mac_vap,hi_bool pairwise,hi_u8 pairwise_idx)303 hmac_wapi_stru *hmac_user_get_wapi_ptr(const mac_vap_stru *mac_vap, hi_bool pairwise, hi_u8 pairwise_idx)
304 {
305     hmac_user_stru             *hmac_user = HI_NULL;
306     hi_u8                       user_index;
307 
308     if (pairwise == HI_TRUE) {
309         user_index = pairwise_idx;
310     } else {
311         user_index = mac_vap->multi_user_idx;
312     }
313 
314     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_index);
315     if (hmac_user == HI_NULL) {
316         oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_user_get_wapi_ptr::pst_hmac_user null.}");
317         return HI_NULL;
318     }
319 
320     return &hmac_user->wapi;
321 }
322 #endif
323 
hmac_user_del_wapi_sta_mesh_proc(hmac_user_stru * hmac_user,mac_vap_stru * mac_vap,const mac_user_stru * mac_user)324 hi_u32 hmac_user_del_wapi_sta_mesh_proc(hmac_user_stru *hmac_user, mac_vap_stru *mac_vap, const mac_user_stru *mac_user)
325 {
326 #ifdef _PRE_WLAN_FEATURE_WAPI
327     mac_device_stru *mac_dev = mac_res_get_dev();
328 
329     if (hmac_wapi_deinit(&hmac_user->wapi) != HI_SUCCESS) {
330         oam_warning_log0(mac_vap->vap_id, OAM_SF_UM, "hmac_wapi_deinit return NON SUCCESS. ");
331     }
332 
333     /* STA模式下,清组播wapi加密端口 */
334     hmac_user_stru *hmac_user_multi = (hmac_user_stru *)hmac_user_get_user_stru(mac_vap->multi_user_idx);
335     if (hmac_user_multi == HI_NULL) {
336         oam_error_log1(0, OAM_SF_ANY, "{hmac_user_del::hmac_user_get_user_stru fail! user_idx[%u]}",
337             mac_vap->multi_user_idx);
338         return HI_ERR_CODE_PTR_NULL;
339     }
340 
341     hmac_wapi_reset_port(&hmac_user_multi->wapi);
342     mac_dev->wapi = HI_FALSE;
343 #else
344     hi_unref_param(hmac_user);
345     hi_unref_param(mac_user);
346 #endif
347 
348     if (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) {
349 #ifdef _PRE_WLAN_FEATURE_STA_PM
350         mac_vap_set_aid(mac_vap, 0);
351 #endif
352     }
353 
354 #ifdef _PRE_WLAN_FEATURE_MESH
355     if (mac_vap->vap_mode == WLAN_VAP_MODE_MESH) {
356         if (mac_user->is_mesh_user == HI_TRUE) {
357             /* 通知dmac从白名单中删除该用户 */
358             if (hmac_del_multicast_user_whitelist(mac_vap, mac_user->user_mac_addr, WLAN_MAC_ADDR_LEN) != HI_SUCCESS) {
359                 return HI_FAIL;
360             }
361         }
362     }
363 #endif
364 
365     return HI_SUCCESS;
366 }
367 
368 /* ****************************************************************************
369  功能描述  : hmac抛事件删除dmac用户
370  修改历史      :
371   1.日    期   : 2015年8月6日
372     作    者   : HiSilicon
373     修改内容   : 新生成函数
374 **************************************************************************** */
hmac_send_del_user_event(const mac_vap_stru * mac_vap,const hi_u8 * da_mac_addr,hi_u8 user_idx)375 hi_u32 hmac_send_del_user_event(const mac_vap_stru *mac_vap, const hi_u8 *da_mac_addr, hi_u8 user_idx)
376 {
377     frw_event_mem_stru *event_mem = HI_NULL;
378     frw_event_stru *event = HI_NULL;
379     dmac_ctx_del_user_stru *del_user_payload = HI_NULL;
380 
381     event_mem = frw_event_alloc(sizeof(dmac_ctx_del_user_stru));
382     if (oal_unlikely(event_mem == HI_NULL)) {
383         oam_error_log1(mac_vap->vap_id, OAM_SF_UM, "{hmac_send_del_user_event::cannot alloc event,size[%d].}",
384             sizeof(dmac_ctx_del_user_stru));
385         return HI_ERR_CODE_ALLOC_MEM_FAIL;
386     }
387 
388     event = (frw_event_stru *)event_mem->puc_data;
389     del_user_payload = (dmac_ctx_del_user_stru *)event->auc_event_data;
390     del_user_payload->user_idx = user_idx;
391     if (memcpy_s(del_user_payload->auc_user_mac_addr, WLAN_MAC_ADDR_LEN, da_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
392         frw_event_free(event_mem);
393         oam_error_log0(0, OAM_SF_CFG, "hmac_send_del_user_event:: puc_da memcpy_s fail.");
394         return HI_FAIL;
395     }
396 
397     /* 填充事件头 */
398     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX, DMAC_WLAN_CTX_EVENT_SUB_TYPE_DEL_USER,
399         sizeof(dmac_ctx_del_user_stru), FRW_EVENT_PIPELINE_STAGE_1, mac_vap->vap_id);
400 
401     hcc_hmac_tx_control_event(event_mem, sizeof(dmac_ctx_del_user_stru));
402     frw_event_free(event_mem);
403 
404     return HI_SUCCESS;
405 }
406 
hmac_sync_del_user(mac_vap_stru * mac_vap,hmac_user_stru * hmac_user,const mac_user_stru * mac_user,hi_u8 user_index)407 hi_u32 hmac_sync_del_user(mac_vap_stru *mac_vap, hmac_user_stru *hmac_user, const mac_user_stru *mac_user,
408     hi_u8 user_index)
409 {
410     mac_device_stru *mac_dev = mac_res_get_dev();
411 
412     if (hmac_send_del_user_event(mac_vap, mac_user->user_mac_addr, user_index) != HI_SUCCESS) {
413         return HI_FAIL;
414     }
415     hmac_tid_clear(mac_vap, hmac_user);
416     if (hmac_user->mgmt_timer.is_registerd == HI_TRUE) {
417         frw_timer_immediate_destroy_timer(&hmac_user->mgmt_timer);
418     }
419     if (hmac_user->ch_text != HI_NULL) {
420         oal_mem_free(hmac_user->ch_text);
421         hmac_user->ch_text = HI_NULL;
422     }
423     if (hmac_user->defrag_timer.is_registerd == HI_TRUE) {
424         frw_timer_immediate_destroy_timer(&hmac_user->defrag_timer);
425     }
426     /* 从vap中删除用户 */
427     mac_vap_del_user(mac_vap, user_index);
428 
429     /* 释放用户内存 */
430     hi_u32 ret = hmac_user_free(user_index);
431     if (ret == HI_SUCCESS) {
432         if (mac_dev->asoc_user_cnt > 0) {
433             /* device下已关联user个数-- */
434             mac_dev->asoc_user_cnt--;
435         }
436     } else {
437         oam_error_log1(0, OAM_SF_UM, "{hmac_user_del::mac_user_free_user_res fail[%d].}", ret);
438     }
439 
440     return HI_SUCCESS;
441 }
442 
443 /* ****************************************************************************
444  函 数 名  : hmac_del_user
445  功能描述  : 删除user
446  输入参数  : 无
447  输出参数  : 无
448  返 回 值  :
449  调用函数  :
450  被调函数  :
451 
452  修改历史      :
453   1.日    期   : 2013年7月1日
454     作    者   : HiSilicon
455     修改内容   : 新生成函数
456 
457 **************************************************************************** */
hmac_user_del(mac_vap_stru * mac_vap,hmac_user_stru * hmac_user)458 hi_u32 hmac_user_del(mac_vap_stru *mac_vap, hmac_user_stru *hmac_user)
459 {
460     if ((mac_vap == HI_NULL) || (hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL)) {
461         oam_error_log2(0, OAM_SF_UM, "{hmac_user_del::param null,%p %p.}", (uintptr_t)mac_vap, (uintptr_t)hmac_user);
462         return HI_ERR_CODE_PTR_NULL;
463     }
464 
465     mac_user_stru *mac_user = hmac_user->base_user;
466     oam_warning_log4(mac_vap->vap_id, OAM_SF_UM,
467         "{hmac_user_del::del user[%d] start,is multi user[%d], user mac:XX:XX:XX:XX:%02X:%02X}", mac_user->us_assoc_id,
468         mac_user->is_multi_user, mac_user->user_mac_addr[4], mac_user->user_mac_addr[5]); /* 4 5 元素索引 */
469 
470     /* 删除user时候,需要更新保护机制 */
471     if (hmac_protection_del_user(mac_vap, mac_user) != HI_SUCCESS) {
472         oam_warning_log0(0, OAM_SF_UM, "{hmac_user_del::hmac_protection_del_user return Err}");
473     }
474 
475     /* 获取用户对应的索引 */
476     hi_u8 user_index = (hi_u8)hmac_user->base_user->us_assoc_id;
477 
478     /* 删除hmac user 的关联请求帧空间 */
479     if (hmac_user->puc_assoc_req_ie_buff != HI_NULL) {
480         oal_mem_free(hmac_user->puc_assoc_req_ie_buff);
481         hmac_user->puc_assoc_req_ie_buff = HI_NULL;
482         hmac_user->assoc_req_ie_len      = 0;
483     }
484 
485 #ifdef _PRE_WLAN_FEATURE_PMF
486     hmac_stop_sa_query_timer(hmac_user);
487 #endif
488 
489     hi_u32 ret = hmac_user_del_wapi_sta_mesh_proc(hmac_user, mac_vap, mac_user);
490     if (ret != HI_SUCCESS) {
491         return ret;
492     }
493 
494     /* 抛事件到DMAC层, 删除dmac用户 */
495     return hmac_sync_del_user(mac_vap, hmac_user, mac_user, user_index);
496 }
497 
hmac_user_add_check(mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 mac_addr_len)498 hi_u32 hmac_user_add_check(mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len)
499 {
500     hi_u8 user_res_num = oal_mem_get_user_res_num();
501     hi_u8 user_idx = 0;
502     hi_u8 user_spec;
503 
504     if (oal_unlikely((mac_vap == HI_NULL) || (mac_addr == HI_NULL))) {
505         hi_diag_log_msg_e2(0, "{hmac_user_add::param null, %p %p}", (uintptr_t)mac_vap, (uintptr_t)mac_addr);
506         return HI_ERR_CODE_PTR_NULL;
507     }
508 
509     hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
510     if (hmac_vap == HI_NULL) {
511         hi_diag_log_msg_e1(0, "{hmac_user_add:: hmac vap is null, id = %d.}", mac_vap->vap_id);
512         return HI_ERR_CODE_PTR_NULL;
513     }
514 
515     /* 判断用户数量是否超出规格 */
516     mac_device_stru *mac_dev = mac_res_get_dev();
517     /* _PRE_WLAN_FEATURE_MESH + */
518     if (mac_vap->vap_mode == WLAN_VAP_MODE_MESH) {
519         user_spec = (hi_u8)WLAN_MESHAP_ASSOC_USER_MAX_NUM;
520     } else if (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP) {
521         user_spec = WLAN_SOFTAP_ASSOC_USER_MAX_NUM;
522 #ifdef _PRE_WLAN_FEATURE_P2P
523     } else if (is_p2p_cl(mac_vap)) {
524         user_spec = 2; /* P2P作为CL时可以添加2个用户,一个用于发送管理帧,一个用户发送数据帧 */
525 #endif
526     } else {
527         user_spec = 1; /* STA 1个用户 */
528     }
529     if ((mac_dev->asoc_user_cnt >= user_res_num) || (mac_vap->user_nums >= user_spec)) {
530         hi_diag_log_msg_w3(0, "{hmac_user_add_check::user cnt Err.asoc_user_cnt=%d, user_res_num=%d, user_nums=%d}",
531             mac_dev->asoc_user_cnt, user_res_num, mac_vap->user_nums);
532         return HI_ERR_CODE_CONFIG_EXCEED_SPEC;
533     }
534 
535     /* 如果此用户已经创建,则返回失败 */
536     hi_u32 ret = mac_vap_find_user_by_macaddr(mac_vap, mac_addr, mac_addr_len, &user_idx);
537     if (ret == HI_SUCCESS) {
538         oam_warning_log1(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::mac_vap_find_user_by_macaddr failed[%d].}", ret);
539         return HI_FAIL;
540     }
541     return HI_SUCCESS;
542 }
543 
hmac_user_init_proc(const mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 * puc_user_index,hi_u8 * user_idx)544 hi_u32 hmac_user_init_proc(const mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 *puc_user_index, hi_u8 *user_idx)
545 {
546     /* 申请hmac用户内存,并初始清0 */
547     hi_u32 ret = hmac_user_alloc(user_idx);
548     if (ret != HI_SUCCESS) {
549         oam_warning_log1(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::hmac_user_alloc failed[%d].}", ret);
550         return ret;
551     }
552 
553     /* 单播用户不能使用userid为0,需重新申请一个。将userid作为aid分配给对端,处理psm时会出错 */
554     if ((*user_idx) == 0) {
555         /* 重新申请一个新的userid, 此处不可能再申请到0 */
556         ret = hmac_user_alloc(user_idx);
557         if (hmac_user_free(0) != HI_SUCCESS) { /* 0不可作为单播用户的userid,将0还回用户资源池 先申请后释放 */
558             oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hmac_user_free return NON SUCCESS. ");
559         }
560         if (ret != HI_SUCCESS) {
561             oam_warning_log2(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::Err=%d, idx=%p}", ret, (uintptr_t)user_idx);
562             return ret;
563         }
564     }
565 
566     *puc_user_index = *user_idx; /* 出参赋值 */
567     hmac_user_stru *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(*user_idx);
568     if ((hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL)) {
569         oam_warning_log0(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::pst_hmac_user null.}");
570         return HI_ERR_CODE_PTR_NULL;
571     }
572     /* 清空hmac user结构体 不清base_user保持与mac user的匹配关系 */
573     if (memset_s(((hi_u8 *)hmac_user), hi_offset_of_member(hmac_user_stru, base_user), 0,
574         hi_offset_of_member(hmac_user_stru, base_user)) != EOK) {
575         oam_warning_log0(0, 0, "hmac_user_init_proc::memset_s 0 fail!");
576         return HI_FAIL;
577     }
578 
579     /* 初始化mac_user_stru */
580     mac_user_init(hmac_user->base_user, (*user_idx), mac_addr, mac_vap->vap_id);
581 
582     /* mesh不支持wpai */
583     if (mac_vap->vap_mode != WLAN_VAP_MODE_MESH) {
584 #ifdef _PRE_WLAN_FEATURE_WAPI
585         mac_device_stru *mac_dev = mac_res_get_dev();
586         /* 初始化单播wapi对象 */
587         hmac_wapi_init(&hmac_user->wapi, HI_TRUE);
588         mac_dev->wapi = HI_FALSE;
589 #endif
590     }
591     /* 设置amsdu域 */
592     hmac_user->us_amsdu_maxsize = WLAN_AMSDU_FRAME_MAX_LEN_LONG;
593     hmac_user->amsdu_supported  = AMSDU_ENABLE_ALL_TID;
594 
595     return HI_SUCCESS;
596 }
597 
hmac_user_add_send_event(const mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 mac_addr_len,hi_u8 user_idx)598 hi_u32 hmac_user_add_send_event(const mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len, hi_u8 user_idx)
599 {
600     frw_event_mem_stru *event_mem = frw_event_alloc(sizeof(dmac_ctx_add_user_stru));
601 
602     if (oal_unlikely(event_mem == HI_NULL) || (event_mem->puc_data == HI_NULL)) {
603         /* 异常处理,释放内存,device下关联用户数还没有++,这里不需要判断返回值做--操作 */
604         if (hmac_user_free(user_idx) != HI_SUCCESS) {
605             oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hmac_user_free return NON SUCCESS. ");
606         }
607         oam_error_log0(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::event_mem null.}");
608         return HI_ERR_CODE_ALLOC_MEM_FAIL;
609     }
610 
611     frw_event_stru         *event            = (frw_event_stru *)event_mem->puc_data;
612     dmac_ctx_add_user_stru *add_user_payload = (dmac_ctx_add_user_stru *)event->auc_event_data;
613     add_user_payload->user_idx = user_idx;
614     if (memcpy_s(add_user_payload->auc_user_mac_addr, WLAN_MAC_ADDR_LEN, mac_addr, mac_addr_len) != EOK) {
615         frw_event_free(event_mem);
616         return HI_FAIL;
617     }
618 
619     /* 填充事件头 */
620     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX, DMAC_WLAN_CTX_EVENT_SUB_TYPE_ADD_USER,
621         sizeof(dmac_ctx_add_user_stru), FRW_EVENT_PIPELINE_STAGE_1, mac_vap->vap_id);
622 
623     hi_u32 ret = hcc_hmac_tx_control_event(event_mem, sizeof(dmac_ctx_add_user_stru));
624     if (oal_unlikely(ret != HI_SUCCESS)) {
625         /* 异常处理,释放内存,device下关联用户数还没有++,这里不需要判断返回值做--操作 */
626         if (hmac_user_free(user_idx) != HI_SUCCESS) {
627             oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hmac_user_free return NON SUCCESS. ");
628         }
629         frw_event_free(event_mem);
630 
631         oam_warning_log1(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::frw_event_dispatch_event failed[%d].}", ret);
632         return ret;
633     }
634 
635     frw_event_free(event_mem);
636 
637     return HI_SUCCESS;
638 }
639 
640 /* ****************************************************************************
641  功能描述  : 添加用户配置命令
642  修改历史      :
643   1.日    期   : 2013年6月5日
644     作    者   : HiSilicon
645     修改内容   : 新生成函数
646 **************************************************************************** */
hmac_user_add(mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 mac_addr_len,hi_u8 * puc_user_index)647 hi_u32 hmac_user_add(mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len, hi_u8 *puc_user_index)
648 {
649     hi_u8                   user_idx;
650     mac_device_stru        *mac_dev  = mac_res_get_dev();
651     hi_u8                   tid_loop;
652 
653     hi_u32 ret = hmac_user_add_check(mac_vap, mac_addr, mac_addr_len);
654     if (ret != HI_SUCCESS) {
655         return ret;
656     }
657 
658     ret = hmac_user_init_proc(mac_vap, mac_addr, puc_user_index, &user_idx);
659     if (ret != HI_SUCCESS) {
660         return ret;
661     }
662 
663     hmac_user_stru *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_idx);
664     if (hmac_user == HI_NULL) {
665         return HI_FAIL;
666     }
667 
668     /* 抛事件到DMAC层, 创建dmac用户 */
669     ret = hmac_user_add_send_event(mac_vap, mac_addr, mac_addr_len, user_idx);
670     if (ret != HI_SUCCESS) {
671         return ret;
672     }
673 
674     /* 添加用户到MAC VAP */
675     ret = mac_vap_add_assoc_user(mac_vap, user_idx);
676     if (ret != HI_SUCCESS) {
677         oam_warning_log1(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::mac_vap_add_assoc_user failed[%d].}", ret);
678 
679         /* 异常处理,释放内存,device下关联用户数还没有++,这里不需要判断返回值做--操作 */
680         if (hmac_user_free(user_idx) != HI_SUCCESS) {
681             oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hmac_user_free return NON SUCCESS. ");
682         }
683         return HI_FAIL;
684     }
685 
686     /* 初始化tid信息 统一由申请时清0,此处仅进行非零初始化 */
687     for (tid_loop = 0; tid_loop < WLAN_TID_MAX_NUM; tid_loop++) {
688         hmac_user->ast_tid_info[tid_loop].tid_no = (hi_u8)tid_loop;
689     }
690     mac_dev->asoc_user_cnt++;
691     oam_warning_log4(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add::user[%d] mac:XX:XX:XX:%02X:%02X:%02X}", user_idx,
692         mac_addr[3], mac_addr[4], mac_addr[5]); /* 3 4 5 元素索引 */
693 
694     return HI_SUCCESS;
695 }
696 
697 /* ****************************************************************************
698  功能描述  : hmac层创建组播用户
699  修改历史      :
700   1.日    期   : 2013年8月23日
701     作    者   : HiSilicon
702     修改内容   : 新生成函数
703 **************************************************************************** */
hmac_user_add_multi_user(const mac_vap_stru * mac_vap,hi_u8 * puc_user_index)704 hi_u32 hmac_user_add_multi_user(const mac_vap_stru *mac_vap, hi_u8 *puc_user_index)
705 {
706     hi_u32      ret;
707     hi_u8       user_index;
708     mac_user_stru  *mac_user  = HI_NULL;
709 #ifdef _PRE_WLAN_FEATURE_WAPI
710     hmac_user_stru *hmac_user = HI_NULL;
711 #endif
712 
713     ret = hmac_user_alloc(&user_index);
714     if (ret != HI_SUCCESS) {
715         oam_error_log1(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add_multi_user::hmac_user_alloc failed[%d].}", ret);
716         return ret;
717     }
718 
719     /* 初始化组播用户基本信息 */
720     mac_user = mac_user_get_user_stru(user_index);
721     if (mac_user == HI_NULL) {
722         oam_warning_log0(mac_vap->vap_id, OAM_SF_UM, "{hmac_user_add_multi_user::pst_mac_user null.}");
723         return HI_ERR_CODE_PTR_NULL;
724     }
725 
726     mac_user_init(mac_user, user_index, HI_NULL, mac_vap->vap_id);
727     *puc_user_index = user_index;
728 
729 #ifdef _PRE_WLAN_FEATURE_WAPI
730     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_index);
731     if (hmac_user == HI_NULL) {
732         oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_user_add_multi_user::get hmac_user fail.}");
733         return HI_ERR_CODE_PTR_NULL;
734     }
735 
736     /* 初始化wapi对象 */
737     hmac_wapi_init(&hmac_user->wapi, HI_FALSE);
738 #endif
739 
740     oam_info_log1(mac_vap->vap_id, OAM_SF_ANY, "{hmac_user_add_multi_user:: user index[%d].}", user_index);
741 
742     return HI_SUCCESS;
743 }
744 
745 /* ****************************************************************************
746  函 数 名  : hmac_user_del_multi_user
747  功能描述  : hmac层删除multiuser
748  输入参数  : 无
749  输出参数  : 无
750  返 回 值  :
751  调用函数  :
752  被调函数  :
753 
754  修改历史      :
755   1.日    期   : 2015年7月23日
756     作    者   : HiSilicon
757     修改内容   : 新生成函数
758 
759 **************************************************************************** */
hmac_user_del_multi_user(hi_u8 idx)760 hi_u32 hmac_user_del_multi_user(hi_u8 idx)
761 {
762 #ifdef _PRE_WLAN_FEATURE_WAPI
763     hmac_user_stru *hmac_user = HI_NULL;
764 #endif
765     hi_u32 ret;
766 
767 #ifdef _PRE_WLAN_FEATURE_WAPI
768     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(idx);
769     if (hmac_user == HI_NULL) {
770         oam_error_log0(0, OAM_SF_ANY, "{hmac_user_add_multi_user::get hmac_user fail.}");
771         return HI_ERR_CODE_PTR_NULL;
772     }
773 
774     ret = hmac_wapi_deinit(&hmac_user->wapi);
775     if (ret != HI_SUCCESS) {
776         oam_warning_log0(0, OAM_SF_ANY, "hmac_wapi_deinit return NON SUCCESS. ");
777     }
778 #endif
779 
780     ret = hmac_user_free(idx);
781     if (ret != HI_SUCCESS) {
782         oam_warning_log0(0, OAM_SF_ANY, "hmac_user_free return NON SUCCESS. ");
783     }
784 
785     return HI_SUCCESS;
786 }
787 
788 /* ****************************************************************************
789  功能描述  : 判断wapi设备是否关连
790  修改历史      :
791   1.日    期   : 2015年12月23日
792     作    者   : HiSilicon
793     修改内容   : 新生成函数
794 **************************************************************************** */
795 #ifdef _PRE_WLAN_FEATURE_WAPI
hmac_user_is_wapi_connected(hi_void)796 hi_u8 hmac_user_is_wapi_connected(hi_void)
797 {
798     hi_u8                  vap_idx;
799     hmac_user_stru         *hmac_user = HI_NULL;
800     mac_device_stru        *mac_dev      = HI_NULL;
801     mac_vap_stru           *mac_vap         = HI_NULL;
802 
803     mac_dev = mac_res_get_dev();
804     for (vap_idx = 0; vap_idx < mac_dev->vap_num; vap_idx++) {
805         mac_vap = mac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
806         if (oal_unlikely(mac_vap == HI_NULL)) {
807             oam_warning_log1(0, OAM_SF_CFG, "vap is null! vap id is %d", mac_dev->auc_vap_id[vap_idx]);
808             continue;
809         }
810 
811         if (!is_sta(mac_vap)) {
812             continue;
813         }
814 
815         hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(mac_vap->multi_user_idx);
816         if ((hmac_user != HI_NULL) && (hmac_user->wapi.port_valid == HI_TRUE)) {
817             return HI_TRUE;
818         }
819     }
820 
821     return HI_FALSE;
822 }
823 #endif /* #ifdef _PRE_WLAN_FEATURE_WAPI */
824 
825 /* ****************************************************************************
826  函 数 名  : hmac_user_add_notify_alg
827  功能描述  : 抛事件给dmac,让其在dmac挂算法钩子
828  输入参数  : 无
829  输出参数  : 无
830  返 回 值  :
831  调用函数  :
832  被调函数  :
833 
834  修改历史      :
835   1.日    期   : 2013年11月25日
836     作    者   : HiSilicon
837     修改内容   : 新生成函数
838 
839 **************************************************************************** */
hmac_user_add_notify_alg(const mac_vap_stru * mac_vap,hi_u8 user_idx)840 hi_u32 hmac_user_add_notify_alg(const mac_vap_stru *mac_vap, hi_u8 user_idx)
841 {
842     frw_event_mem_stru             *event_mem        = HI_NULL;
843     frw_event_stru                 *event            = HI_NULL;
844     dmac_ctx_add_user_stru         *add_user_payload = HI_NULL;
845     hi_u32                         ret;
846     hmac_user_stru                 *hmac_user        = HI_NULL;
847 
848     /* 抛事件给Dmac,在dmac层挂用户算法钩子 */
849     event_mem = frw_event_alloc(sizeof(dmac_ctx_add_user_stru));
850     if (oal_unlikely(event_mem == HI_NULL)) {
851         oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_user_add_notify_alg::event_mem null.}");
852         return HI_ERR_CODE_ALLOC_MEM_FAIL;
853     }
854 
855     event = (frw_event_stru *)event_mem->puc_data;
856     add_user_payload = (dmac_ctx_add_user_stru *)event->auc_event_data;
857     add_user_payload->user_idx = user_idx;
858     add_user_payload->us_sta_aid = mac_vap->us_sta_aid;
859     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_idx);
860     if (oal_unlikely((hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL))) {
861         oam_error_log1(0, OAM_SF_CFG, "{hmac_user_add_notify_alg::null param,pst_hmac_user[%d].}", user_idx);
862         frw_event_free(event_mem);
863         return HI_ERR_CODE_PTR_NULL;
864     }
865     mac_user_get_ht_hdl(hmac_user->base_user, &add_user_payload->ht_hdl);
866     /* 填充事件头 */
867     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX, DMAC_WLAN_CTX_EVENT_SUB_TYPE_NOTIFY_ALG_ADD_USER,
868         sizeof(dmac_ctx_add_user_stru), FRW_EVENT_PIPELINE_STAGE_1, mac_vap->vap_id);
869 
870     ret = hcc_hmac_tx_control_event(event_mem, sizeof(dmac_ctx_add_user_stru));
871     if (oal_unlikely(ret != HI_SUCCESS)) {
872         /* 异常处理,释放内存 */
873         frw_event_free(event_mem);
874 
875         oam_warning_log1(mac_vap->vap_id, OAM_SF_ANY,
876             "{hmac_user_add_notify_alg::frw_event_dispatch_event failed[%d].}", ret);
877         return ret;
878     }
879     frw_event_free(event_mem);
880 
881     return HI_SUCCESS;
882 }
883 
884 /* ****************************************************************************
885  函 数 名  : mac_vap_get_hmac_user_by_addr
886  功能描述  : 根据mac地址获取mac_user指针
887  输入参数  :
888  输出参数  : 无
889  返 回 值  :
890  调用函数  :
891  被调函数  :
892 
893  修改历史      :
894   1.日    期   : 2015年1月8日
895     作    者   : HiSilicon
896     修改内容   : 新生成函数
897 
898 **************************************************************************** */
mac_vap_get_hmac_user_by_addr(mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 addr_len)899 hmac_user_stru *mac_vap_get_hmac_user_by_addr(mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 addr_len)
900 {
901     hi_u32              ret;
902     hi_u8               user_idx   = 0xff;
903     hmac_user_stru         *hmac_user = HI_NULL;
904 
905     /* 根据mac addr找sta索引 */
906     ret = mac_vap_find_user_by_macaddr(mac_vap, mac_addr, addr_len, &user_idx);
907     if (ret != HI_SUCCESS) {
908         oam_warning_log1(0, OAM_SF_ANY, "{mac_vap_get_hmac_user_by_addr::find_user_by_macaddr failed[%d].}", ret);
909         if (mac_addr != HI_NULL) {
910             oam_warning_log3(0, OAM_SF_ANY, "{mac_vap_get_hmac_user_by_addr:: mac_addr[XX:XX:XX:XX:%02x:%02x:%02x]!.}",
911                 mac_addr[3], mac_addr[4], mac_addr[5]); /* 3 4 5 元素索引 */
912         }
913         return HI_NULL;
914     }
915 
916     /* 根据sta索引找到user内存区域 */
917     hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_idx);
918     if (hmac_user == HI_NULL) {
919         oam_error_log0(0, OAM_SF_ANY, "{mac_vap_get_hmac_user_by_addr::user ptr null.}");
920     }
921     return hmac_user;
922 }
923 
924 #ifdef _PRE_WLAN_FEATURE_MESH
925 /* ****************************************************************************
926  功能描述  : 配置Mesh用户的Mac地址到白名单中,接收广播/组播数据帧
927  输入参数  :  mac_vap_stru *pst_mac_vap, hi_u8 *puc_mac_addr
928  返 回 值  : HI_SUCCESS 或 失败错误码
929  修改历史      :
930   1.日    期   : 2019年7月4日
931     作    者   : HiSilicon
932     修改内容   : 新生成函数
933 **************************************************************************** */
hmac_set_multicast_user_whitelist(const mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 mac_addr_len)934 hi_u32 hmac_set_multicast_user_whitelist(const mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len)
935 {
936     frw_event_mem_stru *event_mem = HI_NULL;
937     frw_event_stru *event = HI_NULL;
938     hmac_vap_stru *hmac_vap = HI_NULL;
939     dmac_ctx_mesh_mac_addr_whitelist_stru *mesh_wl = HI_NULL;
940     hi_u32 ret;
941 
942     hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
943     if (hmac_vap == HI_NULL) {
944         oam_error_log0(0, 0, "{hmac_set_multicast_user_whitelist::pst_hmac_vap null!}");
945         return HI_FAIL;
946     }
947     /* **************************************************************************
948         抛事件到DMAC层, 添加白名单
949     ************************************************************************** */
950     event_mem = frw_event_alloc(sizeof(dmac_ctx_mesh_mac_addr_whitelist_stru));
951     if (oal_unlikely(event_mem == HI_NULL)) {
952         /* 异常处理,释放内存,无法添加到硬件,该远端无法正常通信 */
953         hmac_handle_close_peer_mesh(hmac_vap, mac_addr, mac_addr_len, HMAC_REPORT_DISASSOC, DMAC_DISASOC_MISC_KICKUSER);
954         oam_error_log0(mac_vap->vap_id, OAM_SF_UM, "{hmac_set_multicast_user_whitelist::event_mem null.}");
955         return HI_ERR_CODE_ALLOC_MEM_FAIL;
956     }
957 
958     event = (frw_event_stru *)event_mem->puc_data;
959     mesh_wl = (dmac_ctx_mesh_mac_addr_whitelist_stru *)event->auc_event_data;
960     mesh_wl->set = HI_TRUE;
961     if (memcpy_s(mesh_wl->auc_addr, WLAN_MAC_ADDR_LEN, mac_addr, mac_addr_len) != EOK) {
962         frw_event_free(event_mem);
963         return HI_FAIL;
964     }
965 
966     /* 填充事件头 */
967     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX,
968         DMAC_WLAN_CTX_EVENT_SUB_TYPE_SET_MESH_USER_WHITELIST, sizeof(dmac_ctx_mesh_mac_addr_whitelist_stru),
969         FRW_EVENT_PIPELINE_STAGE_1, mac_vap->vap_id);
970 
971     ret = hcc_hmac_tx_control_event(event_mem, sizeof(dmac_ctx_mesh_mac_addr_whitelist_stru));
972     if (oal_unlikely(ret != HI_SUCCESS)) {
973         /* 异常处理,释放内存,无法添加到硬件,该远端无法正常通信 */
974         hmac_handle_close_peer_mesh(hmac_vap, mac_addr, mac_addr_len, HMAC_REPORT_DISASSOC, DMAC_DISASOC_MISC_KICKUSER);
975         frw_event_free(event_mem);
976         oam_warning_log1(mac_vap->vap_id, OAM_SF_UM,
977             "{hmac_set_multicast_user_whitelist::frw_event_dispatch_event failed[%d].}", ret);
978         return ret;
979     }
980 
981     frw_event_free(event_mem);
982     return HI_SUCCESS;
983 }
984 
985 /* ****************************************************************************
986  功能描述  : 删除白名单中的某个Mesh用户的Mac地址
987  输入参数  :  mac_vap_stru *pst_mac_vap, hi_u8 *puc_mac_addr
988  返 回 值  : HI_SUCCESS 或 失败错误码
989  修改历史      :
990   1.日    期   : 2019年7月4日
991     作    者   : HiSilicon
992     修改内容   : 新生成函数
993 **************************************************************************** */
hmac_del_multicast_user_whitelist(const mac_vap_stru * mac_vap,const hi_u8 * mac_addr,hi_u8 mac_addr_len)994 hi_u32 hmac_del_multicast_user_whitelist(const mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len)
995 {
996     frw_event_mem_stru *event_mem = HI_NULL;
997     frw_event_stru *event = HI_NULL;
998     dmac_ctx_mesh_mac_addr_whitelist_stru *mesh_wl = HI_NULL;
999     hi_u32 ret;
1000 
1001     /* **************************************************************************
1002         抛事件到DMAC层, 删除白名单
1003     ************************************************************************** */
1004     event_mem = frw_event_alloc(sizeof(dmac_ctx_mesh_mac_addr_whitelist_stru));
1005     if (oal_unlikely(event_mem == HI_NULL)) {
1006         oam_error_log0(mac_vap->vap_id, OAM_SF_UM, "{hmac_unset_multicast_user_whitelist::event_mem null.}");
1007         return HI_ERR_CODE_ALLOC_MEM_FAIL;
1008     }
1009 
1010     event = (frw_event_stru *)event_mem->puc_data;
1011     mesh_wl = (dmac_ctx_mesh_mac_addr_whitelist_stru *)event->auc_event_data;
1012     mesh_wl->set = HI_FALSE;
1013     if (memcpy_s(mesh_wl->auc_addr, WLAN_MAC_ADDR_LEN, mac_addr, mac_addr_len) != EOK) {
1014         frw_event_free(event_mem);
1015         oam_error_log0(mac_vap->vap_id, OAM_SF_UM, "{hmac_unset_multicast_user_whitelist::memcpy_s Err.}");
1016         return HI_FAIL;
1017     }
1018 
1019     /* 填充事件头 */
1020     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX,
1021         DMAC_WLAN_CTX_EVENT_SUB_TYPE_UNSET_MESH_USER_WHITELIST, sizeof(dmac_ctx_mesh_mac_addr_whitelist_stru),
1022         FRW_EVENT_PIPELINE_STAGE_1, mac_vap->vap_id);
1023 
1024     ret = hcc_hmac_tx_control_event(event_mem, sizeof(dmac_ctx_mesh_mac_addr_whitelist_stru));
1025     if (oal_unlikely(ret != HI_SUCCESS)) {
1026         frw_event_free(event_mem);
1027 
1028         oam_warning_log1(mac_vap->vap_id, OAM_SF_UM,
1029             "{hmac_unset_multicast_user_whitelist::frw_event_dispatch_event failed[%d].}", ret);
1030         return ret;
1031     }
1032 
1033     frw_event_free(event_mem);
1034     return HI_SUCCESS;
1035 }
1036 #endif
1037 
1038 #ifdef __cplusplus
1039 #if __cplusplus
1040 }
1041 #endif
1042 #endif
1043