1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description:
15 * Date: 2020-07-07
16 */
17 #include "hmac_slp.h"
18 #include "mac_resource_ext.h"
19 #include "mac_ie.h"
20 #include "mac_device_ext.h"
21 #include "oal_mem_hcm.h"
22 #include "oal_netbuf_data.h"
23 #include "hmac_tx_mgmt.h"
24 #include "hmac_user.h"
25 #include "hmac_11i.h"
26 #include "msg_slp_rom.h"
27 #include "hmac_hook.h"
28 #include "hmac_ccpriv.h"
29 #include "frw_util_notifier.h"
30 #include "hmac_feature_interface.h"
31
32 #ifdef __cplusplus
33 #if __cplusplus
34 extern "C" {
35 #endif
36 #endif
37
38 #undef THIS_FILE_ID
39 #define THIS_FILE_ID OAM_FILE_ID_HMAC_SLP_C
40 #undef THIS_MOD_ID
41 #define THIS_MOD_ID DIAG_MOD_ID_WIFI_HOST
42
43 osal_bool g_slp_switch = OSAL_FALSE;
44 osal_u8 frame_data[WLAN_SHORT_NETBUF_SIZE];
45 osal_u8 g_gtk_idx[WLAN_VAP_SUPPORT_MAX_NUM_LIMIT] = {
46 WLAN_SLP_GTK_IDX_INVAILD, WLAN_SLP_GTK_IDX_INVAILD, WLAN_SLP_GTK_IDX_INVAILD, WLAN_SLP_GTK_IDX_INVAILD
47 };
48
49 /*****************************************************************************
50 函 数 名 : hmac_get_slp_switch_status
51 功能描述 : 获取SLP特性是否开启
52 *****************************************************************************/
hmac_get_slp_switch_status(osal_void)53 OSAL_STATIC osal_bool hmac_get_slp_switch_status(osal_void)
54 {
55 return g_slp_switch;
56 }
57
58 /*****************************************************************************
59 函 数 名 : hmac_set_slp_gtk_idx
60 功能描述 : 设置vap的gtk密钥索引(用于添加或者删除key索引)
61 *****************************************************************************/
hmac_slp_add_gtk_idx(osal_void * notify_data)62 OSAL_STATIC osal_bool hmac_slp_add_gtk_idx(osal_void *notify_data)
63 {
64 hmac_add_gtk_notify_stru *add_gtk_data = (hmac_add_gtk_notify_stru *)notify_data;
65 wlan_ciper_protocol_type_enum_uint8 cipher_type = add_gtk_data->cipher_type;
66 osal_u8 vap_id = add_gtk_data->vap_id;
67 osal_u8 gtk_idx = add_gtk_data->key_idx;
68
69 if (vap_id >= WLAN_VAP_SUPPORT_MAX_NUM_LIMIT) {
70 oam_error_log1(0, OAM_SF_SLP, "{hmac_slp_add_gtk_idx:: vap id[%d] is error}", vap_id);
71 return OSAL_FALSE;
72 }
73
74 if ((cipher_type == WLAN_80211_CIPHER_SUITE_BIP) ||
75 (cipher_type == WLAN_80211_CIPHER_SUITE_BIP_GMAC_128) ||
76 (cipher_type == WLAN_80211_CIPHER_SUITE_BIP_GMAC_256) ||
77 (cipher_type == WLAN_80211_CIPHER_SUITE_BIP_CMAC_256)) {
78 return OSAL_TRUE;
79 }
80
81 oam_warning_log3(0, OAM_SF_SLP, "{hmac_slp_add_gtk_idx:: set vap[%d] new gtk[%d] old gtk[%d]}", vap_id, gtk_idx,
82 g_gtk_idx[vap_id]);
83
84 g_gtk_idx[vap_id] = gtk_idx;
85
86 return OSAL_TRUE;
87 }
88
hmac_slp_del_gtk_idx(osal_void * notify_data)89 OSAL_STATIC osal_bool hmac_slp_del_gtk_idx(osal_void *notify_data)
90 {
91 hmac_del_gtk_notify_stru *del_gtk_data = (hmac_add_gtk_notify_stru *)notify_data;
92 wlan_ciper_protocol_type_enum_uint8 cipher_type = del_gtk_data->cipher_type;
93 osal_u8 vap_id = del_gtk_data->vap_id;
94
95 if (vap_id >= WLAN_VAP_SUPPORT_MAX_NUM_LIMIT) {
96 oam_error_log1(0, OAM_SF_SLP, "{hmac_slp_del_gtk_idx:: vap id[%d] is error}", vap_id);
97 return OSAL_FALSE;
98 }
99
100 if ((cipher_type == WLAN_80211_CIPHER_SUITE_BIP) ||
101 (cipher_type == WLAN_80211_CIPHER_SUITE_BIP_GMAC_128) ||
102 (cipher_type == WLAN_80211_CIPHER_SUITE_BIP_GMAC_256) ||
103 (cipher_type == WLAN_80211_CIPHER_SUITE_BIP_CMAC_256)) {
104 return OSAL_TRUE;
105 }
106 oam_warning_log2(0, OAM_SF_SLP, "{hmac_slp_del_gtk_idx::vap[%d] gtk[%d]}", vap_id, g_gtk_idx[vap_id]);
107
108 g_gtk_idx[vap_id] = WLAN_SLP_GTK_IDX_INVAILD;
109
110 return OSAL_TRUE;
111 }
112
113 /*****************************************************************************
114 函 数 名 : hmac_set_slp_gtk_idx
115 功能描述 : 获取vap的gtk密钥索引
116 *****************************************************************************/
hmac_get_slp_gtk_idx(osal_u8 vap_id,osal_u8 * gtk_idx)117 OSAL_STATIC osal_void hmac_get_slp_gtk_idx(osal_u8 vap_id, osal_u8 *gtk_idx)
118 {
119 if (vap_id >= WLAN_VAP_SUPPORT_MAX_NUM_LIMIT) {
120 oam_error_log1(0, OAM_SF_SLP, "{hmac_get_slp_gtk_idx:: vap id[%d] is error}", vap_id);
121 return;
122 }
123
124 *gtk_idx = g_gtk_idx[vap_id];
125 oam_warning_log2(0, OAM_SF_SLP, "{hmac_get_slp_gtk_idx:: get vap[%d] gtk[%d]}", vap_id, *gtk_idx);
126 }
127
128 /*****************************************************************************
129 函 数 名 : hmac_slp_encap_cts
130 功能描述 : 组ba request帧
131 *****************************************************************************/
hmac_slp_encap_cts(const hmac_vap_stru * hmac_vap,osal_u8 * frame_buf,osal_u8 * mac_addr,osal_u16 duration)132 OSAL_STATIC osal_u16 hmac_slp_encap_cts(const hmac_vap_stru *hmac_vap, osal_u8 *frame_buf,
133 osal_u8 *mac_addr, osal_u16 duration)
134 {
135 osal_u8 *mac_hdr = OSAL_NULL;
136
137 if (hmac_vap == OSAL_NULL || frame_buf == OSAL_NULL || mac_addr == OSAL_NULL) {
138 oam_error_log0(0, OAM_SF_SLP, "{hmac_slp_encap_cts:: ptr is null}");
139 return 0;
140 }
141
142 mac_hdr = frame_buf + OAL_MAX_CB_LEN;
143
144 /*************************************************************************/
145 /* Head: Frame Control+Duration+DA */
146 /* SLP CTS Frame Format */
147 /* -------------------------------------------------------------------- */
148 /* |Frame Control|Duration| DA |FCS| */
149 /* | | | | | */
150 /* -------------------------------------------------------------------- */
151 /* | 2 |2 | 6 |4 | */
152 /* -------------------------------------------------------------------- */
153 /*************************************************************************/
154
155 /*************************************************************************/
156 /* Set the fields in the frame header */
157 /*************************************************************************/
158 /* All the fields of the Frame Control Field are set to zero. Only the */
159 /* Type/Subtype field is set. */
160 mac_hdr_set_frame_control(mac_hdr, (osal_u16)WLAN_PROTOCOL_VERSION | WLAN_FC0_TYPE_CTL | WLAN_FC0_SUBTYPE_CTS);
161
162 mac_hdr_set_duration(mac_hdr, duration);
163
164 /* 4表示将指针定位到DA,Set DA to the address of the STA requesting authentication */
165 oal_set_mac_addr(mac_hdr + WLAN_HDR_ADDR1_OFFSET, mac_addr);
166
167 return WLAN_MAX_CTS_LEN;
168 }
169
170 /*****************************************************************************
171 函 数 名 : hmac_slp_cts_set_tx_ctrl
172 功能描述 : 设置cts帧的tx_ctrl
173 *****************************************************************************/
hmac_slp_cts_set_tx_ctrl(const hmac_vap_stru * hmac_vap,mac_tx_ctl_stru * tx_ctl)174 OSAL_STATIC osal_void hmac_slp_cts_set_tx_ctrl(const hmac_vap_stru *hmac_vap, mac_tx_ctl_stru *tx_ctl)
175 {
176 /* 避免节能,将用户索引置为INVAILD */
177 tx_ctl->tx_user_idx = MAC_INVALID_USER_ID;
178 tx_ctl->ac = WLAN_WME_AC_MGMT;
179
180 tx_ctl->retried_num = 0;
181 tx_ctl->frame_header_length = WLAN_MAX_CTS_LEN;
182 tx_ctl->netbuf_num = 1;
183 tx_ctl->mpdu_payload_len = 0;
184 tx_ctl->duration_hw_bypass = 1;
185 tx_ctl->slp_frame_id = MAC_SLP_CTS_FRAME;
186
187 /* set mpdu num & seq num */
188 tx_ctl->mpdu_num = 1;
189 tx_ctl->msdu_num = 1;
190 tx_ctl->tx_vap_index = hmac_vap->vap_id;
191 if (hmac_vap->hal_vap != OSAL_NULL) {
192 tx_ctl->tx_hal_vap_index = hmac_vap->hal_vap->vap_id;
193 }
194
195 tx_ctl->frame_type = WLAN_CB_FRAME_TYPE_MGMT;
196 }
197
198 /*****************************************************************************
199 函 数 名 : hmac_slp_send_cts
200 功能描述 : 发送cts帧(host主要做封装操作)
201 *****************************************************************************/
hmac_slp_send_cts(hmac_vap_stru * hmac_vap,osal_u16 duration,osal_u8 * cst_frame)202 OSAL_STATIC osal_u32 hmac_slp_send_cts(hmac_vap_stru *hmac_vap, osal_u16 duration, osal_u8 *cst_frame)
203 {
204 osal_u16 cts_len;
205 mac_tx_ctl_stru *tx_ctl = (mac_tx_ctl_stru *)cst_frame;
206
207 cts_len = hmac_slp_encap_cts(hmac_vap, cst_frame, mac_mib_get_station_id(hmac_vap), duration);
208 if (cts_len == 0) {
209 oam_error_log1(0, OAM_SF_SLP, "vap_id[%d] {hmac_slp_send_cts::cts_len=0.}", hmac_vap->vap_id);
210 return OAL_FAIL;
211 }
212
213 /* 填写netbuf的cb字段,供发送管理帧和发送完成接口使用 */
214 hmac_slp_cts_set_tx_ctrl(hmac_vap, tx_ctl);
215
216 return OAL_SUCC;
217 }
218
219 /*****************************************************************************
220 函 数 名 : hmac_slp_encap_rts
221 功能描述 : 组rts帧
222 *****************************************************************************/
hmac_slp_encap_rts(const hmac_vap_stru * hmac_vap,osal_u8 * frame_buf,osal_u8 * mac_addr,osal_u16 duration)223 OSAL_STATIC osal_u16 hmac_slp_encap_rts(const hmac_vap_stru *hmac_vap, osal_u8 *frame_buf,
224 osal_u8 *mac_addr, osal_u16 duration)
225 {
226 osal_u8 *mac_hdr = OSAL_NULL;
227
228 if (hmac_vap == OSAL_NULL || frame_buf == OSAL_NULL || mac_addr == OSAL_NULL) {
229 oam_error_log0(0, OAM_SF_SLP, "{hmac_slp_encap_rts:: ptr is null}");
230 return 0;
231 }
232
233 mac_hdr = frame_buf + OAL_MAX_CB_LEN;
234
235 /*************************************************************************/
236 /* Head: Frame Control+Duration+DA+RA */
237 /* SLP RTS Frame Format */
238 /* -------------------------------------------------------------------- */
239 /* |Frame Control|Duration| DA | RA |FCS| */
240 /* | | | | | | */
241 /* -------------------------------------------------------------------- */
242 /* | 2 |2 | 6 | 6 |4 | */
243 /* -------------------------------------------------------------------- */
244 /*************************************************************************/
245
246 /*************************************************************************/
247 /* Set the fields in the frame header */
248 /*************************************************************************/
249 /* All the fields of the Frame Control Field are set to zero. Only the */
250 /* Type/Subtype field is set. */
251 mac_hdr_set_frame_control(mac_hdr, (osal_u16)WLAN_PROTOCOL_VERSION | WLAN_FC0_TYPE_CTL | WLAN_FC0_SUBTYPE_RTS);
252
253 mac_hdr_set_duration(mac_hdr, duration);
254
255 /* 4表示将指针定位到DA,Set DA to the address of the STA requesting authentication */
256 oal_set_mac_addr(mac_hdr + WLAN_HDR_ADDR1_OFFSET, mac_addr);
257
258 /* 4表示将指针定位到RA,Set RA to the address of the STA requesting authentication */
259 oal_set_mac_addr(mac_hdr + WLAN_HDR_ADDR2_OFFSET, mac_mib_get_station_id(hmac_vap));
260
261 return WLAN_MAX_RTS_LEN;
262 }
263
264 /*****************************************************************************
265 函 数 名 : hmac_slp_rts_set_tx_ctrl
266 功能描述 : 设置rts帧的tx_ctrl
267 *****************************************************************************/
hmac_slp_rts_set_tx_ctrl(const hmac_vap_stru * hmac_vap,mac_tx_ctl_stru * tx_ctl)268 OSAL_STATIC osal_void hmac_slp_rts_set_tx_ctrl(const hmac_vap_stru *hmac_vap, mac_tx_ctl_stru *tx_ctl)
269 {
270 /* 避免节能,将用户索引置为INVAILD */
271 tx_ctl->tx_user_idx = MAC_INVALID_USER_ID;
272 tx_ctl->ac = WLAN_WME_AC_MGMT;
273
274 tx_ctl->retried_num = 0;
275 tx_ctl->frame_header_length = WLAN_MAX_RTS_LEN;
276 tx_ctl->netbuf_num = 1;
277 tx_ctl->mpdu_payload_len = 0;
278 tx_ctl->duration_hw_bypass = 1;
279 tx_ctl->slp_frame_id = MAC_SLP_GPIO_FRAME; /* 设置脉冲帧的标识 */
280 tx_ctl->frame_type = WLAN_CB_FRAME_TYPE_MGMT;
281
282 /* set mpdu num & seq num */
283 tx_ctl->mpdu_num = 1;
284 tx_ctl->msdu_num = 1;
285 tx_ctl->tx_vap_index = hmac_vap->vap_id;
286 if (hmac_vap->hal_vap != OSAL_NULL) {
287 tx_ctl->tx_hal_vap_index = hmac_vap->hal_vap->vap_id;
288 }
289 }
290
291 /*****************************************************************************
292 函 数 名 : hmac_slp_send_rts_gpio
293 功能描述 : 发送rts脉冲帧
294 *****************************************************************************/
hmac_slp_send_rts_gpio(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,osal_u16 duration,osal_u8 * rst_frame)295 OSAL_STATIC osal_u32 hmac_slp_send_rts_gpio(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user, osal_u16 duration,
296 osal_u8 *rst_frame)
297 {
298 osal_u16 rts_len;
299 mac_tx_ctl_stru *tx_ctl = (mac_tx_ctl_stru *)rst_frame;
300
301 rts_len = hmac_slp_encap_rts(hmac_vap, rst_frame, hmac_user->user_mac_addr, duration);
302 if (rts_len == 0) {
303 oam_error_log1(0, OAM_SF_SLP, "vap_id[%d] {hmac_slp_send_rts::frame_len=0.}", hmac_vap->vap_id);
304 return OAL_FAIL;
305 }
306
307 /* 填写netbuf的cb字段,供发送管理帧和发送完成接口使用 */
308 hmac_slp_rts_set_tx_ctrl(hmac_vap, tx_ctl);
309
310 return OAL_SUCC;
311 }
312
313 /*****************************************************************************
314 函 数 名 : hmac_slp_send_cts_gpio
315 功能描述 : 发送cts脉冲帧
316 *****************************************************************************/
hmac_slp_send_cts_gpio(osal_u8 * src_frame,osal_u8 * gpio_frame)317 OSAL_STATIC osal_u32 hmac_slp_send_cts_gpio(osal_u8 *src_frame, osal_u8 *gpio_frame)
318 {
319 errno_t ret;
320 mac_tx_ctl_stru *tx_ctl = (mac_tx_ctl_stru *)gpio_frame;
321
322 ret = memcpy_s(gpio_frame, OAL_MAX_CB_LEN + OAL_MAX_MAC_HDR_LEN, src_frame, OAL_MAX_CB_LEN + OAL_MAX_MAC_HDR_LEN);
323 if (ret != EOK) {
324 oam_error_log0(0, OAM_SF_SLP, "{hmac_slp_send_cts_gpio::memcpy fail.}");
325 }
326 /* 设置脉冲帧的标识 */
327 tx_ctl->slp_frame_id = MAC_SLP_GPIO_FRAME;
328
329 return OAL_SUCC;
330 }
331
332 /*****************************************************************************
333 函 数 名 : hmac_slp_encap_rm_request
334 功能描述 : 组slp测距协商帧
335 *****************************************************************************/
hmac_slp_encap_rm_request(hmac_vap_stru * hmac_vap,const osal_u8 * mac_addr,osal_u8 * frame_buf,const osal_u8 * data,osal_u16 data_len)336 OSAL_STATIC osal_u16 hmac_slp_encap_rm_request(hmac_vap_stru *hmac_vap, const osal_u8 *mac_addr,
337 osal_u8 *frame_buf, const osal_u8 *data, osal_u16 data_len)
338 {
339 osal_u8 *mac_header = OAL_PTR_NULL;
340 osal_u8 *payload_addr = OAL_PTR_NULL;
341 osal_u16 *payload_temp = OAL_PTR_NULL;
342 errno_t ret;
343 osal_u32 idx = 0;
344
345 mac_header = frame_buf + OAL_MAX_CB_LEN;
346 payload_addr = mac_header + OAL_MAX_MAC_HDR_LEN;
347
348 /*************************************************************************/
349 /* Management Frame Format */
350 /* -------------------------------------------------------------------- */
351 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
352 /* -------------------------------------------------------------------- */
353 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
354 /* -------------------------------------------------------------------- */
355 /*************************************************************************/
356 /*************************************************************************/
357 /* Set the fields in the frame header */
358 /* 帧控制字段全为0,除了type和subtype */
359 mac_hdr_set_frame_control(mac_header, WLAN_PROTOCOL_VERSION | WLAN_FC0_TYPE_MGT | WLAN_FC0_SUBTYPE_ACTION);
360
361 /* 设置分片序号为0 */
362 mac_hdr_set_fragment_number(mac_header, 0);
363
364 /* 设置地址1,与STA连接的AP MAC地址 */
365 oal_set_mac_addr(mac_header + WLAN_HDR_ADDR1_OFFSET, mac_addr);
366
367 /* 设置地址2为自己的MAC地址 */
368 oal_set_mac_addr(mac_header + WLAN_HDR_ADDR2_OFFSET, mac_mib_get_station_id(hmac_vap));
369
370 /* 设置地址3,为VAP的MAC地址 */
371 oal_set_mac_addr(mac_header + WLAN_HDR_ADDR3_OFFSET, hmac_vap->bssid);
372
373 payload_addr[idx++] = MAC_ACTION_CATEGORY_VENDOR;
374 payload_addr[idx++] = ((osal_u32)MAC_WLAN_OUI_PUBLIC >> NUM_16_BITS) & 0xff;
375 payload_addr[idx++] = ((osal_u32)MAC_WLAN_OUI_PUBLIC >> NUM_8_BITS) & 0xff;
376 payload_addr[idx++] = ((osal_u32)MAC_WLAN_OUI_PUBLIC) & 0xff;
377 payload_addr[idx++] = MAC_SLP_RM_IE;
378 payload_addr[idx++] = SLP_RM_REQUEST; /* subtype not used */
379
380 payload_temp = (osal_u16 *)&payload_addr[idx];
381 *payload_temp = data_len;
382 idx = idx + 2; /* 采用u16保存数据长度,往后偏移2个u8 */
383
384 ret = memcpy_s(&payload_addr[idx], data_len, data, data_len);
385 if (ret != EOK) {
386 oam_error_log1(0, OAM_SF_SLP, "{hmac_slp_encap_rm_request::memory copy failed[%d].}", ret);
387 return 0;
388 }
389
390 return (osal_u16)(MAC_80211_FRAME_LEN + idx + data_len);
391 }
392
393 /*****************************************************************************
394 函 数 名 : hmac_slp_rm_action_set_tx_ctrl
395 功能描述 : 设置SLP协商帧的tx_ctrl
396 *****************************************************************************/
hmac_slp_rm_action_set_tx_ctrl(const hmac_vap_stru * hmac_vap,mac_tx_ctl_stru * tx_ctl,osal_u16 user_idx,osal_u16 frame_len)397 OSAL_STATIC osal_void hmac_slp_rm_action_set_tx_ctrl(const hmac_vap_stru* hmac_vap, mac_tx_ctl_stru *tx_ctl,
398 osal_u16 user_idx, osal_u16 frame_len)
399 {
400 tx_ctl->tx_user_idx = (osal_u8)user_idx;
401 tx_ctl->ac = WLAN_WME_AC_MGMT;
402
403 tx_ctl->retried_num = 0;
404 tx_ctl->frame_header_length = MAC_80211_FRAME_LEN;
405 tx_ctl->netbuf_num = 1;
406 tx_ctl->mpdu_payload_len = frame_len - MAC_80211_FRAME_LEN;
407 tx_ctl->slp_frame_id = MAC_SLP_RM_ACTION_FRAME;
408
409 tx_ctl->frame_type = WLAN_CB_FRAME_TYPE_MGMT;
410
411 /* slp的管理帧默认不加密 */
412 tx_ctl->cipher_key_type = WLAN_KEY_TYPE_TX_GTK;
413 tx_ctl->cipher_protocol_type = WLAN_80211_CIPHER_SUITE_NO_ENCRYP;
414 tx_ctl->cipher_key_id = 0;
415
416 /* set mpdu num & seq num */
417 tx_ctl->mpdu_num = 1;
418 tx_ctl->msdu_num = 1;
419 tx_ctl->tx_vap_index = hmac_vap->vap_id;
420 if (hmac_vap->hal_vap != OSAL_NULL) {
421 tx_ctl->tx_hal_vap_index = hmac_vap->hal_vap->vap_id;
422 }
423
424 tx_ctl->ismcast = (hmac_vap->multi_user_idx == user_idx) ? OSAL_TRUE : OSAL_FALSE;
425 }
426
427 /*****************************************************************************
428 函 数 名 : hmac_slp_send_rm_request
429 功能描述 : 发送SLP协商帧
430 *****************************************************************************/
hmac_slp_send_rm_request(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,osal_u8 * data,osal_u16 data_len,osal_u8 * rm_request_frame)431 OSAL_STATIC osal_u32 hmac_slp_send_rm_request(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
432 osal_u8 *data, osal_u16 data_len, osal_u8 *rm_request_frame)
433 {
434 osal_u16 frame_len;
435 mac_tx_ctl_stru *tx_ctl = (mac_tx_ctl_stru *)rm_request_frame;
436 const osal_u8 *mac_addr = BROADCAST_MACADDR;
437 osal_u16 user_idx;
438
439 user_idx = hmac_vap->multi_user_idx;
440 if (hmac_user != OSAL_NULL) {
441 mac_addr = hmac_user->user_mac_addr;
442 user_idx = hmac_user->assoc_id;
443 }
444
445 /* 帧长度不能超过申请的netbuf长度 */
446 frame_len = hmac_slp_encap_rm_request(hmac_vap, mac_addr, rm_request_frame, data, data_len);
447 if (frame_len == 0) {
448 oam_error_log1(0, OAM_SF_SLP, "vap_id[%d] {hmac_slp_send_rm_request::frame_len=0.}", hmac_vap->vap_id);
449 return OAL_FAIL;
450 }
451
452 /* 填写netbuf的cb字段,供发送管理帧和发送完成接口使用 */
453 hmac_slp_rm_action_set_tx_ctrl(hmac_vap, tx_ctl, user_idx, frame_len);
454
455 return OAL_SUCC;
456 }
457
458 /*****************************************************************************
459 函 数 名 : hmac_handle_slp_rm_request
460 功能描述 : 处理SLP协商请求(发送参数准备)
461 *****************************************************************************/
hmac_handle_slp_rm_request(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,osal_u8 rm_type)462 OSAL_STATIC osal_u32 hmac_handle_slp_rm_request(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user, osal_u8 rm_type)
463 {
464 mac_slp_rm_stru slp_rm;
465 osal_u16 i;
466 frw_msg msg_to_device = {0};
467 osal_u32 ret;
468
469 memset_s(&msg_to_device, sizeof(frw_msg), 0, sizeof(frw_msg));
470
471 for (i = 0; i < WLAN_SHORT_NETBUF_SIZE; i++) {
472 frame_data[i] = 1;
473 }
474
475 if (rm_type > BROADCAST) {
476 return OAL_FAIL;
477 }
478
479 oam_warning_log1(0, OAM_SF_ANY, "hmac_handle_slp_rm_request: start rm request[%d]", rm_type);
480
481 memset_s(&slp_rm, sizeof(slp_rm), 0, sizeof(slp_rm));
482 slp_rm.rm_type = rm_type;
483 slp_rm.slp_timer_val = MAC_SLP_SESSION_TIME;
484
485 if (rm_type == BROADCAST) {
486 /* ms转化为us * 1000 */
487 hmac_slp_send_cts(hmac_vap, MAC_SLP_CTS_RTS_TIME * 1000, &slp_rm.slp_cts_data[0]);
488 hmac_slp_send_rm_request(hmac_vap, OSAL_NULL, frame_data, sizeof(frame_data), &slp_rm.slp_rm_request_data[0]);
489 hmac_slp_send_cts_gpio(&slp_rm.slp_cts_data[0], &slp_rm.slp_gpio_data[0]);
490 } else if (rm_type == UNICAST) {
491 /* ms转化为us * 1000 */
492 hmac_slp_send_cts(hmac_vap, MAC_SLP_CTS_RTS_TIME * 1000, &slp_rm.slp_cts_data[0]);
493 hmac_slp_send_rm_request(hmac_vap, hmac_user, frame_data, sizeof(frame_data), &slp_rm.slp_rm_request_data[0]);
494 /* ms转化为us * 1000 */
495 hmac_slp_send_rts_gpio(hmac_vap, hmac_user, MAC_SLP_CTS_RTS_TIME * 1000, &slp_rm.slp_gpio_data[0]);
496 }
497
498 frw_msg_init((osal_u8 *)&slp_rm, sizeof(slp_rm), OSAL_NULL, 0, &msg_to_device);
499 ret = (osal_u32)frw_send_msg_to_device(hmac_vap->vap_id, WLAN_MSG_H2D_C_CFG_SLP_RM_START, &msg_to_device,
500 OSAL_TRUE);
501 if (ret != OAL_SUCC) {
502 oam_warning_log1(0, OAM_SF_SLP, "{hmac_handle_slp_rm_request:: send msg to device fail=%d!", ret);
503 return (osal_u32)ret;
504 }
505
506 return OAL_SUCC;
507 }
508
509 /*****************************************************************************
510 函 数 名 : hmac_slp_tx_disable
511 功能描述 : 获取当前SLP运行状态
512 *****************************************************************************/
hmac_slp_tx_disable(osal_void)513 OSAL_STATIC osal_bool hmac_slp_tx_disable(osal_void)
514 {
515 if (hmac_get_slp_switch_status() == OSAL_FALSE) {
516 return OSAL_FALSE;
517 }
518
519 return (osal_bool)hal_gp_get_slp_tx_ctrl();
520 }
521
522 /*****************************************************************************
523 函 数 名 : hmac_rx_slp_action
524 功能描述 : 处理接收到的slp action帧
525 *****************************************************************************/
hmac_rx_slp_action(oal_netbuf_stru ** netbuf,hmac_vap_stru * hmac_vap)526 OSAL_STATIC osal_u32 hmac_rx_slp_action(oal_netbuf_stru **netbuf, hmac_vap_stru *hmac_vap)
527 {
528 dmac_rx_ctl_stru *rx_ctrl = (dmac_rx_ctl_stru *)oal_netbuf_cb(*netbuf); /* 获取帧头信息 */
529 osal_u8 *frame_hdr = (osal_u8 *)mac_get_rx_cb_mac_hdr(&(rx_ctrl->rx_info));
530 slp_nb_payload_and_cfo_req slp_req;
531 mac_slp_action_hdr_stru *slp_action_hdr = OSAL_NULL;
532 osal_u8 frame_type = mac_get_frame_type(frame_hdr);
533 osal_u8 frame_sub_type = mac_get_frame_sub_type(frame_hdr);
534
535 if (hmac_get_slp_switch_status() == OSAL_FALSE) {
536 return OAL_CONTINUE;
537 }
538
539 if ((hmac_vap->vap_state != MAC_VAP_STATE_UP) && (hmac_vap->vap_state != MAC_VAP_STATE_PAUSE)) {
540 return OAL_CONTINUE;
541 }
542
543 if ((frame_type != WLAN_FC0_TYPE_MGT) || (frame_sub_type != WLAN_FC0_SUBTYPE_ACTION)) {
544 return OAL_CONTINUE;
545 }
546
547 slp_action_hdr = (mac_slp_action_hdr_stru *)oal_netbuf_rx_data(*netbuf);
548 if (slp_action_hdr->category != MAC_ACTION_CATEGORY_VENDOR) {
549 return OAL_CONTINUE;
550 }
551
552 memset_s(&slp_req, sizeof(slp_req), 0, sizeof(slp_req));
553
554 switch (slp_action_hdr->oui_sub_type) {
555 case SLP_RM_REQUEST:
556 case SLP_RM_RESULT_REPORT:
557 slp_req.cfo_req.cfo = rx_ctrl->rx_statistic.phase_incr;
558 /* 适配后需要申请内存的方式,并拷贝数据 */
559 slp_req.payload_req.payload = (osal_u8 *)slp_action_hdr + sizeof(mac_slp_action_hdr_stru);
560 slp_req.payload_req.payload_len = slp_action_hdr->len;
561 oam_warning_log3(0, OAM_SF_ANY, "hmac_rx_slp_action:type[%d] cfo[%d] payload_len[%d]",
562 slp_action_hdr->oui_sub_type, slp_req.cfo_req.cfo, slp_req.payload_req.payload_len);
563 break;
564 default:
565 break;
566 }
567
568 return OAL_CONTINUE;
569 }
570
571 /*****************************************************************************
572 函 数 名 : hmac_slp_encap_rm_result
573 功能描述 : 组slp测距报告帧
574 *****************************************************************************/
hmac_slp_encap_rm_result(hmac_vap_stru * hmac_vap,osal_u8 * mac_addr,oal_netbuf_stru * netbuf,const osal_u8 * data,osal_u16 data_len)575 OSAL_STATIC osal_u16 hmac_slp_encap_rm_result(hmac_vap_stru *hmac_vap, osal_u8 *mac_addr,
576 oal_netbuf_stru *netbuf, const osal_u8 *data, osal_u16 data_len)
577 {
578 osal_u8 *mac_header = OAL_PTR_NULL;
579 osal_u8 *payload = OAL_PTR_NULL;
580 osal_u16 *payload_temp = OAL_PTR_NULL;
581 errno_t ret;
582 osal_u32 idx = 0;
583
584 mac_header = oal_netbuf_header(netbuf);
585 payload = oal_netbuf_data_offset(netbuf, MAC_80211_FRAME_LEN);
586
587 /*************************************************************************/
588 /* Management Frame Format */
589 /* -------------------------------------------------------------------- */
590 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
591 /* -------------------------------------------------------------------- */
592 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
593 /* -------------------------------------------------------------------- */
594 /*************************************************************************/
595 /*************************************************************************/
596 /* Set the fields in the frame header */
597 /* 帧控制字段全为0,除了type和subtype */
598 mac_hdr_set_frame_control(mac_header, WLAN_PROTOCOL_VERSION | WLAN_FC0_TYPE_MGT | WLAN_FC0_SUBTYPE_ACTION);
599
600 /* 设置分片序号为0 */
601 mac_hdr_set_fragment_number(mac_header, 0);
602
603 /* 设置地址1,与STA连接的AP MAC地址 */
604 oal_set_mac_addr(mac_header + WLAN_HDR_ADDR1_OFFSET, mac_addr);
605
606 /* 设置地址2为自己的MAC地址 */
607 oal_set_mac_addr(mac_header + WLAN_HDR_ADDR2_OFFSET, mac_mib_get_station_id(hmac_vap));
608
609 /* 设置地址3,为VAP的MAC地址 */
610 oal_set_mac_addr(mac_header + WLAN_HDR_ADDR3_OFFSET, hmac_vap->bssid);
611
612 payload[idx++] = MAC_ACTION_CATEGORY_VENDOR;
613 payload[idx++] = ((osal_u32)MAC_WLAN_OUI_PUBLIC >> NUM_16_BITS) & 0xff;
614 payload[idx++] = ((osal_u32)MAC_WLAN_OUI_PUBLIC >> NUM_8_BITS) & 0xff;
615 payload[idx++] = ((osal_u32)MAC_WLAN_OUI_PUBLIC) & 0xff;
616 payload[idx++] = MAC_SLP_RM_IE;
617 payload[idx++] = SLP_RM_RESULT_REPORT; /* subtype not used */
618
619 payload_temp = (osal_u16 *)&payload[idx];
620 *payload_temp = data_len;
621 idx = idx + 2; /* 采用u16保存数据长度,往后偏移2个u8 */
622
623 ret = memcpy_s(&payload[idx], data_len, data, data_len);
624 if (ret != EOK) {
625 oam_error_log1(0, OAM_SF_SLP, "{hmac_slp_encap_rm_result::memory copy failed[%d].}", ret);
626 return 0;
627 }
628
629 return (osal_u16)(MAC_80211_FRAME_LEN + idx + data_len);
630 }
631
632 /*****************************************************************************
633 函 数 名 : hmac_handle_slp_rm_result
634 功能描述 : 处理SLP测距结果报告请求(发送参数准备)
635 *****************************************************************************/
hmac_handle_slp_rm_result(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user)636 OSAL_STATIC osal_u32 hmac_handle_slp_rm_result(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user)
637 {
638 oal_netbuf_stru *netbuf = OSAL_NULL;
639 osal_u16 i;
640 osal_u32 ret;
641 osal_u16 frame_len = 0;
642 mac_tx_ctl_stru *tx_ctl = OAL_PTR_NULL;
643
644 for (i = 0; i < WLAN_SHORT_NETBUF_SIZE; i++) {
645 frame_data[i] = 0xa;
646 }
647
648 oam_warning_log0(0, OAM_SF_SLP, "hmac_handle_slp_rm_result: start report rm result");
649
650 /* 申请管理帧内存 */
651 netbuf = oal_netbuf_alloc_ext(WLAN_SMGMT_NETBUF_SIZE);
652 if (netbuf == OSAL_NULL) {
653 oam_error_log1(0, OAM_SF_SLP, "vap_id[%d] {hmac_handle_slp_rm_result::netbuf null.}", hmac_vap->vap_id);
654 return OAL_ERR_CODE_PTR_NULL;
655 }
656
657 frame_len = hmac_slp_encap_rm_result(hmac_vap, hmac_user->user_mac_addr, netbuf, frame_data, sizeof(frame_data));
658 if (frame_len == 0) {
659 oam_error_log1(0, OAM_SF_SLP, "vap_id[%d] {hmac_handle_slp_rm_result::frame_len=0.}", hmac_vap->vap_id);
660 return OAL_FAIL;
661 }
662
663 /* 填写netbuf的cb字段,供发送管理帧和发送完成接口使用 */
664 tx_ctl = (mac_tx_ctl_stru *)oal_netbuf_cb(netbuf);
665
666 tx_ctl->tx_user_idx = (osal_u8)hmac_user->assoc_id;
667 tx_ctl->ac = WLAN_WME_AC_MGMT;
668 // 发送需要填写tx_vap_index
669 tx_ctl->tx_vap_index = hmac_vap->vap_id;
670 tx_ctl->retried_num = 0;
671 tx_ctl->mpdu_num = 1;
672 tx_ctl->netbuf_num = 1;
673 tx_ctl->mpdu_payload_len = frame_len;
674 tx_ctl->slp_frame_id = MAC_SLP_REPORT_ACTION_FRAME; /* SLP结果上报帧走正常的发送流程 */
675 tx_ctl->frame_type = WLAN_CB_FRAME_TYPE_MGMT;
676
677 /* 调用发送管理帧接口 */
678 ret = hmac_tx_mgmt(hmac_vap, netbuf, frame_len, OSAL_FALSE);
679 if (ret != OAL_SUCC) {
680 oal_netbuf_free(netbuf);
681 }
682 return ret;
683 }
684
685 /*****************************************************************************
686 函 数 名 : hmac_slp_send_rm_request_test
687 功能描述 : 发送SLP测距请求(发送参数准备)
688 *****************************************************************************/
hmac_slp_send_rm_request_test(hmac_vap_stru * hmac_vap,slp_nb_payload_and_device_req * rm_req)689 OSAL_STATIC osal_s32 hmac_slp_send_rm_request_test(hmac_vap_stru *hmac_vap, slp_nb_payload_and_device_req *rm_req)
690 {
691 hmac_user_stru *hmac_user = OSAL_NULL;
692 slp_communication_mode communication_mode;
693 osal_u8 mac_addr[WLAN_MAC_ADDR_LEN] = { 0 };
694 hmac_device_stru *hmac_device = hmac_res_get_mac_dev_etc(0);
695
696 if (hmac_vap == OSAL_NULL || rm_req == OSAL_NULL) {
697 return OAL_ERR_CODE_PTR_NULL;
698 }
699
700 if (hmac_get_slp_switch_status() == OSAL_FALSE) {
701 oam_warning_log0(0, OAM_SF_SLP, "hmac_slp_send_rm_request_test: SLP NOT ENABLE");
702 return OAL_FAIL;
703 }
704
705 communication_mode = rm_req->device_para.communication_mode;
706
707 if (hmac_device_calc_up_vap_num_etc(hmac_device) > 1) {
708 oam_warning_log0(0, OAM_SF_SLP, "{hmac_slp_send_rm_request::not support more than one vap up slp rm");
709 return OAL_FAIL;
710 }
711
712 if (hmac_vap->p2p_mode != WLAN_LEGACY_VAP_MODE) {
713 oam_warning_log1(0, OAM_SF_SLP, "vap_id[%d]{hmac_slp_send_rm_request:p2p not support SLP RM", hmac_vap->vap_id);
714 return OAL_FAIL;
715 }
716
717 if (hmac_vap->vap_state != MAC_VAP_STATE_UP && hmac_vap->vap_state != MAC_VAP_STATE_PAUSE) {
718 oam_warning_log1(0, OAM_SF_SLP, "{hmac_slp_send_rm_request::device not assoc[%d]", hmac_vap->vap_state);
719 return OAL_FAIL;
720 }
721
722 memcpy_s(mac_addr, WLAN_MAC_ADDR_LEN, rm_req->device_para.addr, WLAN_MAC_ADDR_LEN);
723
724 switch (communication_mode) {
725 case UNICAST:
726 hmac_user = hmac_vap_get_user_by_addr_etc(hmac_vap, mac_addr, sizeof(mac_addr));
727 if (hmac_user != OSAL_NULL) {
728 hmac_handle_slp_rm_request(hmac_vap, hmac_user, UNICAST);
729 } else {
730 oam_warning_log4(0, OAM_SF_SLP, "hmac_slp_send_rm_request_test: user not found[%x:%x:%x:%x:x:x]",
731 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]); /* 打印mac地址0:1:2:3地址 */
732 return OAL_FAIL;
733 }
734 break;
735 case BROADCAST:
736 hmac_handle_slp_rm_request(hmac_vap, OSAL_NULL, BROADCAST);
737 break;
738
739 default:
740 oam_warning_log1(0, OAM_SF_SLP, "hmac_slp_send_rm_request: err communication_mode[%d]", communication_mode);
741 break;
742 }
743 return OAL_SUCC;
744 }
745
746 /*****************************************************************************
747 函 数 名 : hmac_slp_report_rm_result_test
748 功能描述 : 发送SLP测距报告请求(发送参数准备)
749 *****************************************************************************/
hmac_slp_report_rm_result_test(hmac_vap_stru * hmac_vap,slp_nb_payload_and_device_req * rm_req)750 OSAL_STATIC osal_s32 hmac_slp_report_rm_result_test(hmac_vap_stru *hmac_vap, slp_nb_payload_and_device_req *rm_req)
751 {
752 hmac_user_stru *hmac_user = OSAL_NULL;
753 osal_u8 mac_addr[WLAN_MAC_ADDR_LEN];
754
755 if (osal_unlikely((hmac_vap == OSAL_NULL) || (rm_req == OSAL_NULL))) {
756 return OAL_ERR_CODE_PTR_NULL;
757 }
758
759 if (hmac_get_slp_switch_status() == OSAL_FALSE) {
760 oam_warning_log0(0, OAM_SF_SLP, "hmac_slp_report_rm_result_test: SLP NOT ENABLE");
761 return OAL_FAIL;
762 }
763
764 memcpy_s(mac_addr, WLAN_MAC_ADDR_LEN, rm_req->device_para.addr, WLAN_MAC_ADDR_LEN);
765
766 hmac_user = hmac_vap_get_user_by_addr_etc(hmac_vap, mac_addr, sizeof(mac_addr));
767 if (hmac_user != OSAL_NULL) {
768 hmac_handle_slp_rm_result(hmac_vap, hmac_user);
769 } else {
770 oam_warning_log4(0, OAM_SF_SLP, "hmac_slp_report_rm_result: user not found[%x:%x:%x:%x:x:x]",
771 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]); /* 打印mac地址0:1:2:3地址 */
772 return OAL_FAIL;
773 }
774
775 return OAL_SUCC;
776 }
777
778 /*****************************************************************************
779 函 数 名 : hmac_slp_get_gtk
780 功能描述 : 获取设备GTK密钥
781 *****************************************************************************/
hmac_ccpriv_slp_get_gtk(hmac_vap_stru * hmac_vap,const osal_s8 * param)782 OSAL_STATIC osal_s32 hmac_ccpriv_slp_get_gtk(hmac_vap_stru *hmac_vap, const osal_s8 *param)
783 {
784 hmac_user_stru *hmac_user = OSAL_NULL;
785 osal_u8 gtk_idx = 0;
786 osal_u8 gtk_key[WLAN_WPA_KEY_LEN] = { 0 }; /* 密钥 */
787 errno_t ret;
788
789 unref_param(param);
790
791 if (hmac_get_slp_switch_status() == OSAL_FALSE) {
792 oam_warning_log0(0, OAM_SF_SLP, "hmac_ccpriv_slp_get_gtk: SLP NOT ENABLE");
793 return OAL_FAIL;
794 }
795
796 if (hmac_vap->vap_state != MAC_VAP_STATE_UP && hmac_vap->vap_state != MAC_VAP_STATE_PAUSE) {
797 oam_warning_log1(0, OAM_SF_SLP, "hmac_ccpriv_slp_get_gtk: device not assoc[%d]", hmac_vap->vap_state);
798 return OAL_FAIL;
799 }
800
801 hmac_user = mac_res_get_hmac_user_etc(hmac_vap->multi_user_idx);
802 if (hmac_user == OSAL_NULL) {
803 return OAL_FAIL;
804 }
805
806 hmac_get_slp_gtk_idx(hmac_vap->vap_id, >k_idx);
807
808 if (gtk_idx > (WLAN_NUM_TK + WLAN_NUM_IGTK - 1) || gtk_idx == WLAN_SLP_GTK_IDX_INVAILD) {
809 oam_warning_log1(0, OAM_SF_SLP, "hmac_ccpriv_slp_get_gtk:gtk_idx[%d] is invaild", gtk_idx);
810 return OAL_FAIL;
811 }
812
813 ret = memcpy_s(gtk_key, WLAN_WPA_KEY_LEN, hmac_user->key_info.key[gtk_idx].key,
814 hmac_user->key_info.key[gtk_idx].key_len);
815 if (ret != EOK) {
816 oam_warning_log1(0, OAM_SF_SLP, "hmac_slp_get_gtk: memcpy fail[%d]", hmac_user->key_info.key[gtk_idx].key_len);
817 return OAL_FAIL;
818 }
819
820 wifi_printf("[SLP] GTK get\r\n"); // 联调后修改为组播密钥上报
821
822 return OAL_SUCC;
823 }
824
825 hmac_netbuf_hook_stru slp_netbuf_hook = {
826 .hooknum = HMAC_FRAME_MGMT_RX_EVENT_D2H,
827 .priority = HMAC_HOOK_PRI_MIDDLE,
828 .hook_func = hmac_rx_slp_action,
829 };
830
831 /*****************************************************************************
832 函 数 名 : hmac_slp_set_enable
833 功能描述 : 使能/去使能SLP特性开关
834 *****************************************************************************/
hmac_slp_set_enable(hmac_vap_stru * hmac_vap,osal_u8 slp_en)835 OSAL_STATIC osal_s32 hmac_slp_set_enable(hmac_vap_stru *hmac_vap, osal_u8 slp_en)
836 {
837 frw_msg msg_to_device = {0};
838 osal_s32 ret;
839
840 frw_msg_init((osal_u8 *)&slp_en, sizeof(osal_u8), OSAL_NULL, 0, &msg_to_device);
841 ret = frw_send_msg_to_device(hmac_vap->vap_id, WLAN_MSG_H2D_C_CFG_SLP_ENABLE, &msg_to_device, OSAL_TRUE);
842 if (ret != OAL_SUCC) {
843 oam_warning_log1(0, OAM_SF_SLP, "{hmac_slp_set_enable:: send msg to device fail=%d!", ret);
844 return ret;
845 }
846
847 g_slp_switch = (osal_bool)slp_en;
848
849 if (g_slp_switch == OSAL_TRUE) {
850 ret = (osal_s32)hmac_register_netbuf_hook(&slp_netbuf_hook);
851 if (ret != OAL_SUCC) {
852 oam_error_log0(0, OAM_SF_RX, "{hmac_slp_set_enable:: MGMT RX IN register_netbuf_hooks error!");
853 return ret;
854 }
855 /* 对外接口注册 */
856 hmac_feature_hook_register(HMAC_FHOOK_SLP_TX_DISABLE, hmac_slp_tx_disable);
857 } else {
858 hmac_unregister_netbuf_hook(&slp_netbuf_hook);
859 /* 对外接口去注册 */
860 hmac_feature_hook_unregister(HMAC_FHOOK_SLP_TX_DISABLE);
861 }
862
863 oam_warning_log1(0, OAM_SF_SLP, "hmac_slp_set_enable:slp_en[%d]", slp_en);
864
865 return OAL_SUCC;
866 }
867
hmac_ccpriv_slp_set_enable(hmac_vap_stru * hmac_vap,const osal_s8 * param)868 OSAL_STATIC osal_s32 hmac_ccpriv_slp_set_enable(hmac_vap_stru *hmac_vap, const osal_s8 *param)
869 {
870 int32_t ret;
871 osal_u8 value;
872
873 ret = hmac_ccpriv_get_u8_with_check_max(¶m, 1, &value);
874 if (ret != OAL_SUCC) {
875 oam_warning_log0(0, OAM_SF_CFG, "{hmac_ccpriv_slp_set_enable:: value invalid.}");
876 return ret;
877 }
878
879 ret = hmac_slp_set_enable(hmac_vap, value);
880 if (ret != OAL_SUCC) {
881 return OAL_FAIL;
882 }
883
884 return OAL_SUCC;
885 }
886
887 /*****************************************************************************
888 函 数 名 : hmac_slp_get_user_info_test
889 功能描述 : 获取设备下挂用户信息
890 *****************************************************************************/
hmac_ccpriv_slp_get_userinfo(hmac_vap_stru * hmac_vap,const osal_s8 * param)891 OSAL_STATIC osal_s32 hmac_ccpriv_slp_get_userinfo(hmac_vap_stru *hmac_vap, const osal_s8 *param)
892 {
893 hmac_user_stru *hmac_user = OSAL_NULL;
894 struct osal_list_head *entry, *dlist_tmp;
895 osal_u8 *mac_addr = OSAL_NULL;
896
897 unref_param(param);
898
899 if (hmac_get_slp_switch_status() == OSAL_FALSE) {
900 oam_warning_log0(0, OAM_SF_SLP, "hmac_slp_get_user_info_test: SLP NOT ENABLE");
901 return OAL_FAIL;
902 }
903
904 if (hmac_vap->vap_state != MAC_VAP_STATE_UP && hmac_vap->vap_state != MAC_VAP_STATE_PAUSE) {
905 oam_warning_log1(0, OAM_SF_SLP, "hmac_ccpriv_slp_get_userinfo: device not assoc[%d]", hmac_vap->vap_state);
906 return OAL_FAIL;
907 }
908
909 osal_list_for_each_safe(entry, dlist_tmp, &(hmac_vap->mac_user_list_head)) {
910 hmac_user = osal_list_entry(entry, hmac_user_stru, user_dlist);
911 if (hmac_user == OSAL_NULL) {
912 continue;
913 }
914
915 mac_addr = hmac_user->user_mac_addr;
916 oam_warning_log4(0, OAM_SF_SLP, "[SLP]hmac_ccpriv_slp_get_userinfo: user info[%x:%x:%x:%x:xx:xx]",
917 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]); /* 打印mac地址0:1:2:3地址 */
918 }
919
920 return OAL_SUCC;
921 }
922
hmac_ccpriv_slp_start_rm_request(hmac_vap_stru * hmac_vap,const osal_s8 * param)923 OSAL_STATIC osal_s32 hmac_ccpriv_slp_start_rm_request(hmac_vap_stru *hmac_vap, const osal_s8 *param)
924 {
925 slp_nb_payload_and_device_req rm_req;
926 int32_t ret;
927 uint32_t value;
928
929 memset_s(&rm_req, sizeof(slp_nb_payload_and_device_req), 0, sizeof(slp_nb_payload_and_device_req));
930
931 ret = hmac_ccpriv_get_u8_with_check_max(¶m, 1, (osal_u8 *)&value);
932 if (ret != OAL_SUCC) {
933 oam_warning_log0(0, OAM_SF_CFG, "{uapi_ccpriv_slp_start_rm_request::tid num invalid.}");
934 return ret;
935 }
936 rm_req.device_para.communication_mode = value;
937
938 if (rm_req.device_para.communication_mode == UNICAST) {
939 /* 解析bssid */
940 ret = (osal_s32)hmac_ccpriv_get_mac_addr_etc(¶m, rm_req.device_para.addr);
941 if (ret != OAL_SUCC) {
942 oam_error_log0(0, OAM_SF_CFG, "{hmac_ccpriv_slp_start_rm_request::get addr error.}");
943 return OAL_FAIL;
944 }
945 }
946
947 hmac_slp_send_rm_request_test(hmac_vap, &rm_req);
948
949 return OAL_SUCC;
950 }
951
hmac_ccpriv_slp_report_rm_result(hmac_vap_stru * hmac_vap,const osal_s8 * param)952 OSAL_STATIC osal_s32 hmac_ccpriv_slp_report_rm_result(hmac_vap_stru *hmac_vap, const osal_s8 *param)
953 {
954 slp_nb_payload_and_device_req rm_req;
955 uint32_t ret;
956
957 memset_s(&rm_req, sizeof(slp_nb_payload_and_device_req), 0, sizeof(slp_nb_payload_and_device_req));
958
959 /* 解析bssid */
960 ret = hmac_ccpriv_get_mac_addr_etc(¶m, rm_req.device_para.addr);
961 if (ret != OAL_SUCC) {
962 oam_error_log0(0, OAM_SF_CFG, "{hmac_ccpriv_slp_report_rm_result::get addr error.}");
963 return OAL_FAIL;
964 }
965
966 hmac_slp_report_rm_result_test(hmac_vap, &rm_req);
967
968 return OAL_SUCC;
969 }
970
hmac_slp_init(osal_void)971 osal_u32 hmac_slp_init(osal_void)
972 {
973 frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_ADD_GTK, hmac_slp_add_gtk_idx);
974 frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_DEL_GTK, hmac_slp_del_gtk_idx);
975
976 hmac_ccpriv_register((const osal_s8 *)"slp_set_enable", hmac_ccpriv_slp_set_enable);
977 hmac_ccpriv_register((const osal_s8 *)"slp_get_userinfo", hmac_ccpriv_slp_get_userinfo);
978 hmac_ccpriv_register((const osal_s8 *)"slp_get_gtk", hmac_ccpriv_slp_get_gtk);
979 hmac_ccpriv_register((const osal_s8 *)"slp_start_rm_request", hmac_ccpriv_slp_start_rm_request);
980 hmac_ccpriv_register((const osal_s8 *)"slp_report_rm_result", hmac_ccpriv_slp_report_rm_result);
981
982 return OAL_SUCC;
983 }
984
hmac_slp_deinit(osal_void)985 osal_void hmac_slp_deinit(osal_void)
986 {
987 frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_ADD_GTK, hmac_slp_add_gtk_idx);
988 frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_DEL_GTK, hmac_slp_del_gtk_idx);
989
990 hmac_ccpriv_unregister((const osal_s8 *)"slp_set_enable");
991 hmac_ccpriv_unregister((const osal_s8 *)"slp_get_userinfo");
992 hmac_ccpriv_unregister((const osal_s8 *)"slp_get_gtk");
993 hmac_ccpriv_unregister((const osal_s8 *)"slp_start_rm_request");
994 hmac_ccpriv_unregister((const osal_s8 *)"slp_report_rm_result");
995 }
996 #ifdef __cplusplus
997 #if __cplusplus
998 }
999 #endif
1000 #endif
1001