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 "hmac_user.h"
23 #include "hmac_vap.h"
24 #include "hmac_protection.h"
25 #include "mac_vap.h"
26 #include "hmac_config.h"
27 #include "frw_timer.h"
28
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
34
35 /* ****************************************************************************
36 2 函数实现
37 **************************************************************************** */
38 /* ****************************************************************************
39 功能描述 : 同步保护相关的参数到Dmac
40 输入参数 : pst_hmac_vap : hmac vap结构体指针
41 修改历史 :
42 1.日 期 : 2017年1月10日
43 作 者 : HiSilicon
44 修改内容 : 新生成函数
45 ************************************************************************** */
hmac_user_protection_sync_data(const mac_vap_stru * mac_vap)46 hi_u32 hmac_user_protection_sync_data(const mac_vap_stru *mac_vap)
47 {
48 mac_h2d_protection_stru h2d_prot;
49 hi_u8 lsig_txop_full_protection_activated;
50 hi_u8 non_gf_entities_present;
51 hi_u8 rifs_mode;
52 hi_u8 ht_protection;
53
54 /* 安全编程规则6.6例外(1) 对固定长度的结构体进行内存初始化 */
55 memset_s(&h2d_prot, sizeof(mac_h2d_protection_stru), 0x00, sizeof(h2d_prot));
56
57 /* 更新vap的en_dot11NonGFEntitiesPresent字段 */
58 non_gf_entities_present = (0 != mac_vap->protection.sta_non_gf_num) ? HI_TRUE : HI_FALSE;
59 mac_mib_set_non_gfentities_present(mac_vap, non_gf_entities_present);
60
61 /* 更新vap的en_dot11LSIGTXOPFullProtectionActivated字段 */
62 lsig_txop_full_protection_activated = (0 == mac_vap->protection.sta_no_lsig_txop_num) ? HI_TRUE : HI_FALSE;
63 mac_mib_set_lsig_txop_full_protection_activated(mac_vap, lsig_txop_full_protection_activated);
64
65 /* 更新vap的en_dot11HTProtection和en_dot11RIFSMode字段 */
66 if (mac_vap->protection.sta_non_ht_num != 0) {
67 ht_protection = WLAN_MIB_HT_NON_HT_MIXED;
68 rifs_mode = HI_FALSE;
69 } else if (mac_vap->protection.obss_non_ht_present == HI_TRUE) {
70 ht_protection = WLAN_MIB_HT_NONMEMBER_PROTECTION;
71 rifs_mode = HI_FALSE;
72 } else if ((WLAN_BAND_WIDTH_20M != mac_vap->channel.en_bandwidth)
73 && (mac_vap->protection.sta_20_m_only_num != 0)) {
74 ht_protection = WLAN_MIB_HT_20MHZ_PROTECTION;
75 rifs_mode = HI_TRUE;
76 } else {
77 ht_protection = WLAN_MIB_HT_NO_PROTECTION;
78 rifs_mode = HI_TRUE;
79 }
80
81 mac_mib_set_ht_protection(mac_vap, ht_protection);
82 mac_mib_set_rifs_mode(mac_vap, rifs_mode);
83
84 if (memcpy_s((hi_u8 *)&h2d_prot.protection, sizeof(mac_protection_stru), (hi_u8 *)&mac_vap->protection,
85 sizeof(mac_protection_stru)) != EOK) {
86 oam_error_log0(0, OAM_SF_CFG, "hmac_user_protection_sync_data:: st_protection memcpy_s fail.");
87 return HI_FAIL;
88 }
89
90 h2d_prot.dot11_ht_protection = mac_mib_get_ht_protection(mac_vap);
91 h2d_prot.dot11_rifs_mode = mac_mib_get_rifs_mode(mac_vap);
92 h2d_prot.dot11_lsigtxop_full_protection_activated = mac_mib_get_lsig_txop_full_protection_activated(mac_vap);
93 h2d_prot.dot11_non_gf_entities_present = mac_mib_get_non_gfentities_present(mac_vap);
94
95 return hmac_protection_update_from_user(mac_vap, sizeof(h2d_prot), (hi_u8 *)&h2d_prot);
96 }
97
98 /* ****************************************************************************
99 功能描述 : 删除保护模式相关user统计(legacy)
100 输入参数 : pst_mac_vap : mac vap结构体指针
101 pst_mac_user : mac user结构体指针
102 修改历史 :
103 1.日 期 : 2014年1月22日
104 作 者 : HiSilicon
105 修改内容 : 新生成函数
106 **************************************************************************** */
hmac_protection_del_user_stat_legacy_ap(mac_vap_stru * mac_vap,const mac_user_stru * mac_user)107 static hi_u32 hmac_protection_del_user_stat_legacy_ap(mac_vap_stru *mac_vap, const mac_user_stru *mac_user)
108 {
109 mac_protection_stru *protection = &(mac_vap->protection);
110 hmac_user_stru *hmac_user = HI_NULL;
111
112 hmac_user = (hmac_user_stru *)hmac_user_get_user_stru((hi_u8)mac_user->us_assoc_id);
113 if (hmac_user == HI_NULL) {
114 oam_error_log1(mac_vap->vap_id, OAM_SF_ANY,
115 "hmac_protection_del_user_stat_legacy_ap::Get Hmac_user(idx=%d) NULL POINT!", mac_user->us_assoc_id);
116 return HI_ERR_CODE_PTR_NULL;
117 }
118
119 /* 如果去关联的站点不支持ERP */
120 if ((hmac_user->hmac_cap_info.erp == HI_FALSE) && (hmac_user->user_stats_flag.no_erp_stats_flag == HI_TRUE) &&
121 (protection->sta_non_erp_num != 0)) {
122 protection->sta_non_erp_num--;
123 }
124
125 /* 如果去关联的站点不支持short preamble */
126 if ((hmac_user->hmac_cap_info.short_preamble == HI_FALSE) &&
127 (hmac_user->user_stats_flag.no_short_preamble_stats_flag == HI_TRUE) &&
128 (protection->sta_no_short_preamble_num != 0)) {
129 protection->sta_no_short_preamble_num--;
130 }
131
132 /* 如果去关联的站点不支持short slot */
133 if ((hmac_user->hmac_cap_info.short_slot_time == HI_FALSE) &&
134 (hmac_user->user_stats_flag.no_short_slot_stats_flag == HI_TRUE) && (protection->sta_no_short_slot_num != 0)) {
135 protection->sta_no_short_slot_num--;
136 }
137
138 hmac_user->user_stats_flag.no_short_slot_stats_flag = HI_FALSE;
139 hmac_user->user_stats_flag.no_short_preamble_stats_flag = HI_FALSE;
140 hmac_user->user_stats_flag.no_erp_stats_flag = HI_FALSE;
141
142 return HI_SUCCESS;
143 }
144
145 /* ****************************************************************************
146 功能描述 : 删除保护模式相关user统计(ht)
147 输入参数 : pst_mac_vap : mac vap结构体指针
148 pst_mac_user : mac user结构体指针
149 修改历史 :
150 1.日 期 : 2014年1月22日
151 作 者 : HiSilicon
152 修改内容 : 新生成函数
153 **************************************************************************** */
hmac_protection_del_user_stat_ht_ap(mac_vap_stru * mac_vap,mac_user_stru * mac_user)154 static hi_u32 hmac_protection_del_user_stat_ht_ap(mac_vap_stru *mac_vap, mac_user_stru *mac_user)
155 {
156 mac_user_ht_hdl_stru *ht_hdl = &(mac_user->ht_hdl);
157 mac_protection_stru *protection = &(mac_vap->protection);
158 hmac_user_stru *hmac_user = HI_NULL;
159
160 hmac_user = (hmac_user_stru *)hmac_user_get_user_stru((hi_u8)mac_user->us_assoc_id);
161 if (hmac_user == HI_NULL) {
162 oam_error_log1(mac_vap->vap_id, OAM_SF_ANY,
163 "hmac_protection_del_user_stat_ht_ap::Get Hmac_user(idx=%d) NULL POINT!", mac_user->us_assoc_id);
164 return HI_ERR_CODE_PTR_NULL;
165 }
166
167 /* 如果去关联的站点不支持HT */
168 if ((ht_hdl->ht_capable == HI_FALSE) && (hmac_user->user_stats_flag.no_ht_stats_flag == HI_TRUE) &&
169 (protection->sta_non_ht_num != 0)) {
170 protection->sta_non_ht_num--;
171 } else { /* 支持HT */
172 /* 如果去关联的站点不支持20/40Mhz频宽 */
173 if ((ht_hdl->ht_capinfo.supported_channel_width == HI_FALSE) &&
174 (hmac_user->user_stats_flag.m_only_stats_flag == HI_TRUE) && (protection->sta_20_m_only_num != 0)) {
175 protection->sta_20_m_only_num--;
176 }
177
178 /* 如果去关联的站点不支持GF */
179 if ((ht_hdl->ht_capinfo.ht_green_field == HI_FALSE) &&
180 (hmac_user->user_stats_flag.no_gf_stats_flag == HI_TRUE) && (protection->sta_non_gf_num != 0)) {
181 protection->sta_non_gf_num--;
182 }
183
184 /* 如果去关联的站点不支持L-SIG TXOP Protection */
185 if ((ht_hdl->ht_capinfo.lsig_txop_protection == HI_FALSE) &&
186 (hmac_user->user_stats_flag.no_lsig_txop_stats_flag == HI_TRUE) &&
187 (protection->sta_no_lsig_txop_num != 0)) {
188 protection->sta_no_lsig_txop_num--;
189 }
190
191 /* 如果去关联的站点不支持40Mhz cck */
192 if ((ht_hdl->ht_capinfo.dsss_cck_mode_40mhz == HI_FALSE) &&
193 (ht_hdl->ht_capinfo.supported_channel_width == HI_TRUE) &&
194 (hmac_user->user_stats_flag.no_40dsss_stats_flag == HI_TRUE) && (protection->sta_no_40dsss_cck_num != 0)) {
195 protection->sta_no_40dsss_cck_num--;
196 }
197 }
198
199 hmac_user->user_stats_flag.no_ht_stats_flag = HI_FALSE;
200 hmac_user->user_stats_flag.no_gf_stats_flag = HI_FALSE;
201 hmac_user->user_stats_flag.m_only_stats_flag = HI_FALSE;
202 hmac_user->user_stats_flag.no_40dsss_stats_flag = HI_FALSE;
203 hmac_user->user_stats_flag.no_lsig_txop_stats_flag = HI_FALSE;
204
205 return HI_SUCCESS;
206 }
207
208 /* ****************************************************************************
209 功能描述 : 删除保护模式相关user统计
210 输入参数 : pst_mac_vap : mac vap结构体指针
211 pst_mac_user : mac user结构体指针
212 修改历史 :
213 1.日 期 : 2014年1月22日
214 作 者 : HiSilicon
215 修改内容 : 新生成函数
216 **************************************************************************** */
hmac_protection_del_user_stat_ap(mac_vap_stru * mac_vap,mac_user_stru * mac_user)217 static hi_void hmac_protection_del_user_stat_ap(mac_vap_stru *mac_vap, mac_user_stru *mac_user)
218 {
219 hi_u32 ret;
220
221 ret = hmac_protection_del_user_stat_legacy_ap(mac_vap, mac_user);
222 if (ret != HI_SUCCESS) {
223 oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hmac_protection_del_user_stat_legacy_ap return NON SUCCESS. ");
224 }
225
226 ret = hmac_protection_del_user_stat_ht_ap(mac_vap, mac_user);
227 if (ret != HI_SUCCESS) {
228 oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "hmac_protection_del_user_stat_ht_ap return NON SUCCESS. ");
229 }
230 }
231
232 /* ****************************************************************************
233 功能描述 : AP:删除user统计, 并更新保护模式
234 STA: 更新为无保护模式
235 输入参数 : pst_mac_vap : mac vap结构体指针
236 pst_mac_user : mac user结构体指针
237 修改历史 :
238 1.日 期 : 2014年1月22日
239 作 者 : HiSilicon
240 修改内容 : 新生成函数
241 **************************************************************************** */
hmac_protection_del_user(mac_vap_stru * mac_vap,mac_user_stru * mac_user)242 hi_u32 hmac_protection_del_user(mac_vap_stru *mac_vap, mac_user_stru *mac_user)
243 {
244 hi_u32 ret = HI_SUCCESS;
245
246 /* AP 更新VAP结构体统计量,更新保护机制 */
247 if (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP
248 #ifdef _PRE_WLAN_FEATURE_MESH
249 || (mac_vap->vap_mode == WLAN_VAP_MODE_MESH)
250 #endif
251 ) {
252 /* 删除保护模式相关user统计 */
253 hmac_protection_del_user_stat_ap(mac_vap, mac_user);
254 /* 更新AP中保护相关mib量 */
255 ret = hmac_user_protection_sync_data(mac_vap);
256 if (ret != HI_SUCCESS) {
257 oam_warning_log0(0, OAM_SF_ANY, "{hmac_protection_del_user::protection update failed}");
258 return ret;
259 }
260 }
261
262 return ret;
263 }
264
265 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
266 /* ****************************************************************************
267 功能描述 : 处理保护模式同步事件
268 输入参数 :
269 修改历史 :
270 1.日 期 : 2016年12月23日
271 作 者 : HiSilicon
272 修改内容 : 新生成函数
273 **************************************************************************** */
hmac_protection_info_sync_event(frw_event_mem_stru * event_mem)274 hi_u32 hmac_protection_info_sync_event(frw_event_mem_stru *event_mem)
275 {
276 frw_event_stru *event = HI_NULL;
277 frw_event_hdr_stru *event_hdr = HI_NULL;
278 mac_h2d_protection_stru *h2d_prot = HI_NULL;
279 mac_vap_stru *mac_vap = HI_NULL;
280
281 if (oal_unlikely(event_mem == HI_NULL)) {
282 oam_error_log0(0, OAM_SF_ANY, "{hmac_protection_info_syn_event::event_mem null.}");
283 return HI_ERR_CODE_PTR_NULL;
284 }
285
286 /* 获取事件、事件头以及事件payload结构体 */
287 event = frw_get_event_stru(event_mem);
288 event_hdr = &(event->event_hdr);
289 h2d_prot = (mac_h2d_protection_stru *)event->auc_event_data;
290
291 mac_vap = (mac_vap_stru *)mac_vap_get_vap_stru(event_hdr->vap_id);
292 if (mac_vap == HI_NULL) {
293 oam_error_log1(0, OAM_SF_ANY, "{hmac_protection_info_syn_event::mac_res_get_mac_vap fail.vap_id:%u}",
294 event_hdr->vap_id);
295 return HI_ERR_CODE_PTR_NULL;
296 }
297
298 if (mac_vap->mib_info == HI_NULL) {
299 return HI_SUCCESS;
300 }
301 if (h2d_prot == HI_NULL) {
302 return HI_SUCCESS;
303 }
304 if (memcpy_s((hi_u8 *)&mac_vap->protection, sizeof(mac_protection_stru), (hi_u8 *)&h2d_prot->protection,
305 sizeof(mac_protection_stru)) != EOK) {
306 oam_error_log0(0, OAM_SF_CFG, "hmac_protection_info_sync_event:: st_protection memcpy_s fail.");
307 return HI_FAIL;
308 }
309
310 mac_mib_set_ht_protection(mac_vap, h2d_prot->dot11_ht_protection);
311 mac_mib_set_rifs_mode(mac_vap, h2d_prot->dot11_rifs_mode);
312 mac_mib_set_lsig_txop_full_protection_activated(mac_vap, h2d_prot->dot11_lsigtxop_full_protection_activated);
313 mac_mib_set_non_gfentities_present(mac_vap, h2d_prot->dot11_non_gf_entities_present);
314
315 return HI_SUCCESS;
316 }
317 #endif
318 #ifdef __cplusplus
319 #if __cplusplus
320 }
321 #endif
322 #endif
323