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 "oal_util.h"
23 #include "hmac_ext_if.h"
24 #include "hmac_device.h"
25 #include "hmac_vap.h"
26 #include "hmac_rx_filter.h"
27 #include "hmac_fsm.h"
28 #include "hmac_mgmt_bss_comm.h"
29 #include "hmac_event.h"
30 #include "mac_frame.h"
31 #include "hmac_p2p.h"
32
33 #ifdef __cplusplus
34 #if __cplusplus
35 extern "C" {
36 #endif
37 #endif
38
39 /* ****************************************************************************
40 2 静态函数声明
41 **************************************************************************** */
42 /* ****************************************************************************
43 3 全局变量定义
44 **************************************************************************** */
45 /* ****************************************************************************
46 4 函数实现
47 **************************************************************************** */
48 typedef struct mac_vap_state_priority {
49 hi_u8 priority;
50 } mac_vap_state_priority_stru;
51
52 typedef struct hmac_input_req_priority {
53 hi_u8 priority;
54 } hmac_input_req_priority_stru;
55
56 mac_vap_state_priority_stru g_mac_vap_state_priority_table[MAC_VAP_STATE_BUTT] = {
57 { 0 }, /* MAC_VAP_STATE_INIT */
58 { 2 }, /* MAC_VAP_STATE_UP, VAP UP */
59 { 0 }, /* MAC_VAP_STATE_PAUSE, pause , for ap &sta */
60 { 0 }, /* MAC_VAP_STATE_AP_PAUSE, ap独有状态 */
61 { 0 }, /* MAC_VAP_STATE_STA_FAKE_UP, sta独有状态 */
62 { 10 }, /* MAC_VAP_STATE_STA_WAIT_SCAN, sta独有状态 */
63 { 0 }, /* MAC_VAP_STATE_STA_SCAN_COMP, sta独有状态 */
64 { 10 }, /* MAC_VAP_STATE_STA_JOIN_COMP, sta独有状态 */
65 { 10 }, /* MAC_VAP_STATE_STA_WAIT_AUTH_SEQ2, sta独有状态 */
66 { 10 }, /* MAC_VAP_STATE_STA_WAIT_AUTH_SEQ4, sta独有状态 */
67 { 10 }, /* MAC_VAP_STATE_STA_AUTH_COMP, sta独有状态 */
68 { 10 }, /* MAC_VAP_STATE_STA_WAIT_ASOC, sta独有状态 */
69 { 10 }, /* MAC_VAP_STATE_STA_OBSS_SCAN, sta独有状态 */
70 { 10 }, /* MAC_VAP_STATE_STA_BG_SCAN, sta独有状态 */
71 { 0 }, /* MAC_VAP_STATE_STA_LISTEN, p2p0 监听, sta独有状态 */
72 };
73
74 hmac_input_req_priority_stru g_mac_fsm_input_type_priority_table[HMAC_FSM_INPUT_TYPE_BUTT] = {
75 { 0 }, /* HMAC_FSM_INPUT_RX_MGMT */
76 { 0 }, /* HMAC_FSM_INPUT_RX_DATA */
77 { 0 }, /* HMAC_FSM_INPUT_TX_DATA */
78 { 0 }, /* HMAC_FSM_INPUT_TIMER0_OUT */
79 { 0 }, /* HMAC_FSM_INPUT_MISC */
80 { 0 }, /* HMAC_FSM_INPUT_START_REQ */
81 { 5 }, /* HMAC_FSM_INPUT_SCAN_REQ */
82 { 5 }, /* HMAC_FSM_INPUT_JOIN_REQ */
83 { 5 }, /* HMAC_FSM_INPUT_AUTH_REQ */
84 { 5 }, /* HMAC_FSM_INPUT_ASOC_REQ */
85 { 5 }, /* HMAC_FSM_INPUT_LISTEN_REQ, P2P 监听 */
86 { 0 } /* HMAC_FSM_INPUT_LISTEN_TIMEOUT, P2P 监听超时 */
87 };
88
89 /* ****************************************************************************
90 函 数 名 : hmac_p2p_check_can_enter_state
91 功能描述 : 检查外部输入事件是否允许执行
92 输入参数 : [1]mac_vap
93 [2]input_req
94 输出参数 : 无
95 返 回 值 : hi_u32
96 **************************************************************************** */
hmac_p2p_check_can_enter_state(const mac_vap_stru * mac_vap,hmac_fsm_input_type_enum_uint8 input_req)97 hi_u32 hmac_p2p_check_can_enter_state(const mac_vap_stru *mac_vap, hmac_fsm_input_type_enum_uint8 input_req)
98 {
99 mac_device_stru *mac_dev = HI_NULL;
100 mac_vap_stru *other_vap = HI_NULL;
101 hi_u8 vap_num;
102 hi_u8 vap_idx;
103
104 /* 检查其他vap 状态,判断输入事件优先级是否比vap 状态优先级高
105 * 如果输入事件优先级高,则可以执行输入事件
106 */
107 mac_dev = mac_res_get_dev();
108 vap_num = mac_dev->vap_num;
109
110 for (vap_idx = 0; vap_idx < vap_num; vap_idx++) {
111 other_vap = mac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
112 if (other_vap == HI_NULL) {
113 oam_warning_log1(0, OAM_SF_CFG,
114 "{hmac_p2p_check_can_enter_state::hmac_vap_get_vap_stru fail.vap_idx = %u}",
115 mac_dev->auc_vap_id[vap_idx]);
116 continue;
117 }
118
119 if (other_vap->vap_id == mac_vap->vap_id) {
120 /* 如果检测到是自己,则继续检查其他VAP 状态 */
121 continue;
122 }
123 if (g_mac_vap_state_priority_table[other_vap->vap_state].priority >
124 g_mac_fsm_input_type_priority_table[input_req].priority) {
125 return HI_ERR_CODE_CONFIG_BUSY;
126 }
127 }
128 return HI_SUCCESS;
129 }
130
131 /* ****************************************************************************
132 函 数 名 : hmac_p2p_get_home_channel
133 功能描述 : 返回已经UP 的vap 的信道
134 输入参数 : [1]mac_vap
135 [2]pul_home_channel
136 [3]pen_home_channel_type
137 输出参数 : 无
138 返 回 值 : hi_u32
139 **************************************************************************** */
hmac_p2p_get_home_channel(const mac_vap_stru * mac_vap,hi_u32 * pul_home_channel,wlan_channel_bandwidth_enum_uint8 * pen_home_channel_bandwidth)140 hi_u32 hmac_p2p_get_home_channel(const mac_vap_stru *mac_vap, hi_u32 *pul_home_channel,
141 wlan_channel_bandwidth_enum_uint8 *pen_home_channel_bandwidth)
142 {
143 mac_device_stru *mac_dev = HI_NULL;
144 hi_u8 vap_idx;
145 hi_u32 home_channel = 0;
146 hi_u32 last_home_channel = 0;
147 wlan_channel_bandwidth_enum_uint8 home_channel_bandwidth = WLAN_BAND_WIDTH_20M;
148 wlan_channel_bandwidth_enum_uint8 last_home_channel_bandwidth = WLAN_BAND_WIDTH_20M;
149
150 if (mac_vap == HI_NULL) {
151 oam_warning_log0(0, OAM_SF_CFG, "{hmac_p2p_get_home_channel::mac_vap is NULL.}");
152 return HI_ERR_CODE_PTR_NULL;
153 }
154
155 /* 初始化 */
156 mac_dev = mac_res_get_dev();
157 *pul_home_channel = 0;
158 *pen_home_channel_bandwidth = WLAN_BAND_WIDTH_20M;
159
160 /* 获取home 信道 */
161 for (vap_idx = 0; vap_idx < mac_dev->vap_num; vap_idx++) {
162 mac_vap = mac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
163 if (mac_vap == HI_NULL) {
164 oam_warning_log1(0, OAM_SF_CFG, "{hmac_p2p_get_home_channel::hmac_vap_get_vap_stru fail.vap_idx = %u}",
165 vap_idx);
166 continue;
167 }
168
169 if (mac_vap->vap_state == MAC_VAP_STATE_UP) {
170 home_channel = mac_vap->channel.chan_number;
171 home_channel_bandwidth = mac_vap->channel.en_bandwidth;
172 if (last_home_channel == 0) {
173 last_home_channel = home_channel;
174 last_home_channel_bandwidth = home_channel_bandwidth;
175 } else if (last_home_channel != home_channel || last_home_channel_bandwidth != home_channel_bandwidth) {
176 /* 目前暂不支持不同信道的listen */
177 oam_warning_log4(mac_vap->vap_id, OAM_SF_CFG,
178 "{hmac_p2p_get_home_channel::home_channel[%d], last_home_channel[%d],home bw[%d], last bw[%d].}",
179 home_channel, last_home_channel, home_channel_bandwidth, last_home_channel_bandwidth);
180 return HI_FAIL;
181 }
182 }
183 }
184
185 *pul_home_channel = home_channel;
186 *pen_home_channel_bandwidth = home_channel_bandwidth;
187
188 return HI_SUCCESS;
189 }
190
191 /* ****************************************************************************
192 函 数 名 : hmac_p2p_check_vap_num
193 功能描述 : 添加vap时检查P2P vap的num是否符合要求
194 输入参数 : 无
195 输出参数 : 无
196 返 回 值 :
197 调用函数 :
198 被调函数 :
199
200 修改历史 :
201 1.日 期 : 2014年11月25日
202 作 者 : HiSilicon
203 修改内容 : 新生成函数
204
205 **************************************************************************** */
hmac_p2p_check_vap_num(const mac_device_stru * mac_dev,wlan_p2p_mode_enum_uint8 p2p_mode)206 hi_u32 hmac_p2p_check_vap_num(const mac_device_stru *mac_dev, wlan_p2p_mode_enum_uint8 p2p_mode)
207 {
208 mac_vap_stru *mac_vap = HI_NULL;
209 hi_u8 vap_idx;
210
211 /* 剩余资源是否足够申请一份P2P_DEV */
212 if (mac_dev->sta_num > WLAN_STA_NUM_PER_DEVICE) {
213 oam_warning_log1(0, OAM_SF_CFG,
214 "{hmac_p2p_check_vap_num::can't create p2p vap, because sta num [%d] is more than 2.}", mac_dev->sta_num);
215 return HI_ERR_CODE_CONFIG_EXCEED_SPEC;
216 }
217
218 if (mac_dev->p2p_info.p2p_goclient_num >= WLAN_MAX_SERVICE_P2P_GOCLIENT_NUM) {
219 oam_warning_log0(0, OAM_SF_CFG,
220 "{hmac_p2p_check_vap_num::can't create p2p vap, because at least 1 GO/GC exist.}");
221 return HI_ERR_CODE_CONFIG_EXCEED_SPEC;
222 }
223
224 if (p2p_mode == WLAN_P2P_CL_MODE) {
225 /* 当前要创建的是GC,可以支持创建 */
226 return HI_ERR_SUCCESS;
227 }
228
229 for (vap_idx = 0; vap_idx < mac_dev->vap_num; vap_idx++) {
230 mac_vap = mac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
231 if (mac_vap != HI_NULL && (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP
232 #ifdef _PRE_WLAN_FEATURE_MESH
233 || mac_vap->vap_mode == WLAN_VAP_MODE_MESH
234 #endif
235 )) {
236 /* 已有AP创建 */
237 oam_warning_log0(0, OAM_SF_CFG, "{hmac_p2p_check_vap_num::can't create GO, because ap is exist.}");
238 return HI_ERR_CODE_CONFIG_EXCEED_SPEC;
239 }
240 }
241 return HI_SUCCESS;
242 }
243
244 /* ****************************************************************************
245 功能描述 : 设置P2P CL MAC地址到HAL层
246 修改历史 :
247 1.日 期 : 2019年9月6日
248 作 者 : HiSilicon
249 修改内容 : 新生成函数
250 **************************************************************************** */
hmac_p2p_set_gc_mac_addr(mac_device_stru * mac_dev,const hmac_vap_stru * hmac_vap,const mac_cfg_add_vap_param_stru * param)251 hi_u32 hmac_p2p_set_gc_mac_addr(mac_device_stru *mac_dev, const hmac_vap_stru *hmac_vap,
252 const mac_cfg_add_vap_param_stru *param)
253 {
254 mac_cfg_staion_id_param_stru station_id_param;
255 hi_u32 ret;
256 hi_u8 vap_id;
257
258 vap_id = mac_dev->p2p_info.p2p0_vap_idx;
259
260 /* 设置mac地址 */
261 if (memcpy_s(station_id_param.auc_station_id, WLAN_MAC_ADDR_LEN,
262 param->net_dev->macAddr, WLAN_MAC_ADDR_LEN) != EOK) {
263 /* 此处回退有误,需要对应mac_device_set_vap_id,做回退操作 */
264 mac_device_set_vap_id(mac_dev, hmac_vap->base_vap, param, vap_id, HI_FALSE);
265
266 /* 异常处理,释放内存 */
267 oal_mem_free(hmac_vap->base_vap->mib_info);
268
269 mac_vap_free_vap_res(vap_id);
270 oam_error_log0(0, OAM_SF_CFG, "{hmac_p2p_set_gc_mac_addr::mem safe function err!}");
271 return HI_FAIL;
272 }
273 station_id_param.p2p_mode = param->p2p_mode;
274
275 ret = hmac_config_set_mac_addr(hmac_vap->base_vap, sizeof(mac_cfg_staion_id_param_stru),
276 (hi_u8 *)(&station_id_param));
277 if (ret != HI_SUCCESS) {
278 /* 此处回退有误,需要对应mac_device_set_vap_id,做回退操作 */
279 mac_device_set_vap_id(mac_dev, hmac_vap->base_vap, param, vap_id, HI_FALSE);
280
281 /* 异常处理,释放内存 */
282 oal_mem_free(hmac_vap->base_vap->mib_info);
283
284 mac_vap_free_vap_res(vap_id);
285 oam_error_log1(0, OAM_SF_CFG, "{hmac_p2p_set_gc_mac_addr::hmac_config_set_mac_addr failed[%d].}", ret);
286 return ret;
287 }
288 return HI_SUCCESS;
289 }
290
291 /* ****************************************************************************
292 函 数 名 : hmac_p2p_add_gc_vap
293 功能描述 : 创建P2P CL 业务VAP
294 输入参数 : vap : 指向配置vap
295 us_len : 参数长度
296 puc_param : 参数
297 输出参数 : 无
298 返 回 值 : HI_SUCCESS 或其它错误码
299 调用函数 :
300 被调函数 :
301
302 修改历史 :
303 1.日 期 : 2014年12月31日
304 作 者 : HiSilicon
305 修改内容 : 新生成函数
306
307 **************************************************************************** */
hmac_p2p_add_gc_vap(mac_device_stru * mac_dev,hi_u16 us_len,const hi_u8 * puc_param)308 hi_u32 hmac_p2p_add_gc_vap(mac_device_stru *mac_dev, hi_u16 us_len, const hi_u8 *puc_param)
309 {
310 hmac_vap_stru *hmac_vap = HI_NULL;
311 hi_u32 ret;
312 hi_u8 vap_id;
313 wlan_p2p_mode_enum_uint8 p2p_mode;
314 mac_cfg_add_vap_param_stru *param = HI_NULL;
315
316 /* VAP个数判断 */
317 param = (mac_cfg_add_vap_param_stru *)puc_param;
318 p2p_mode = param->p2p_mode;
319 ret = hmac_p2p_check_vap_num(mac_dev, p2p_mode);
320 if (ret != HI_SUCCESS) {
321 oam_warning_log1(0, OAM_SF_CFG, "{hmac_p2p_add_gc_vap::check_vap_num failed[%d].}", ret);
322 return ret;
323 }
324
325 /* P2P CL 和P2P0 共用一个VAP 结构,创建P2P CL 时不需要申请VAP 资源,需要返回p2p0 的vap 结构 */
326 vap_id = mac_dev->p2p_info.p2p0_vap_idx;
327 hmac_vap = hmac_vap_get_vap_stru(vap_id);
328 if (oal_unlikely(hmac_vap == HI_NULL)) {
329 oam_error_log1(0, OAM_SF_CFG, "{hmac_p2p_add_gc_vap::hmac_vap_get_vap_stru failed.vap_id:[%d].}", vap_id);
330 return HI_ERR_CODE_PTR_NULL;
331 }
332
333 param->vap_id = vap_id;
334 hmac_vap->net_device = param->net_dev;
335
336 /* 将申请到的mac_vap空间挂到net_device priv指针上去 */
337 oal_net_dev_priv(param->net_dev) = hmac_vap->base_vap;
338 param->muti_user_id = hmac_vap->base_vap->multi_user_idx;
339
340 /* **************************************************************************
341 抛事件到DMAC层, 同步DMAC数据
342 ************************************************************************** */
343 ret = hmac_config_send_event(hmac_vap->base_vap, WLAN_CFGID_ADD_VAP, us_len, puc_param);
344 if (oal_unlikely(ret != HI_SUCCESS)) {
345 /* 异常处理,释放内存 */
346 oam_error_log1(0, OAM_SF_CFG, "{hmac_p2p_add_gc_vap::hmac_config_alloc_event failed[%d].}", ret);
347 return ret;
348 }
349
350 if (param->vap_mode == WLAN_VAP_MODE_BSS_STA) {
351 /* 初始化uc_assoc_vap_id为最大值代表ap未关联 */
352 mac_vap_set_assoc_id(hmac_vap->base_vap, 0xff);
353 }
354 mac_vap_set_p2p_mode(hmac_vap->base_vap, param->p2p_mode);
355 mac_inc_p2p_num(hmac_vap->base_vap);
356
357 /* 设置帧过滤 */
358 hmac_set_rx_filter_value(hmac_vap->base_vap);
359
360 ret = hmac_p2p_set_gc_mac_addr(mac_dev, hmac_vap, param);
361 if (ret != HI_SUCCESS) {
362 oam_error_log1(0, OAM_SF_CFG, "{hmac_p2p_add_gc_vap::hmac_p2p_set_gc_mac_addr failed [%d].}", ret);
363 return ret;
364 }
365
366 oam_info_log3(0, OAM_SF_P2P, "{hmac_p2p_add_gc_vap::func out.vap_mode[%d], p2p_mode[%d}, vap_id[%d]",
367 param->vap_mode, param->p2p_mode, param->vap_id);
368 return HI_SUCCESS;
369 }
370
371 /* ****************************************************************************
372 函 数 名 : hmac_p2p_del_gc_vap
373 功能描述 : 删除p2p cl vap
374 输入参数 : vap : 指向vap的指针
375 us_len : 参数长度
376 puc_param : 参数
377 输出参数 : 无
378 返 回 值 : HI_SUCCESS 或其它错误码
379 调用函数 :
380 被调函数 :
381
382 修改历史 :
383 1.日 期 : 2014年12月31日
384 作 者 : HiSilicon
385 修改内容 : 新生成函数
386
387 **************************************************************************** */
hmac_p2p_del_gc_vap(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)388 hi_u32 hmac_p2p_del_gc_vap(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
389 {
390 hmac_vap_stru *hmac_vap = HI_NULL;
391 hi_u32 ret;
392 mac_device_stru *mac_dev = HI_NULL;
393 hi_u8 vap_id;
394 mac_cfg_del_vap_param_stru *del_vap_param = HI_NULL;
395
396 hi_unref_param(mac_vap);
397
398 if (oal_unlikely((mac_vap == HI_NULL) || (puc_param == HI_NULL))) {
399 oam_error_log2(0, OAM_SF_CFG, "{hmac_config_del_vap::param null, vap=%p puc_param=%p.}", (uintptr_t)mac_vap,
400 (uintptr_t)puc_param);
401 return HI_ERR_CODE_PTR_NULL;
402 }
403
404 del_vap_param = (mac_cfg_del_vap_param_stru *)puc_param;
405 mac_dev = mac_res_get_dev();
406 /* 如果是删除P2P CL ,则不需要释放VAP 资源 */
407 vap_id = mac_dev->p2p_info.p2p0_vap_idx;
408 hmac_vap = hmac_vap_get_vap_stru(vap_id);
409 if (oal_unlikely(hmac_vap == HI_NULL)) {
410 oam_error_log1(mac_vap->vap_id, OAM_SF_CFG, "{hmac_config_del_vap::hmac_vap_get_vap_stru fail.vap_id[%d]}",
411 vap_id);
412 return HI_ERR_CODE_PTR_NULL;
413 }
414 /* p2p关联过程中,开始作为cl模式,切换到GO模式时需要停用vap,置为NULL */
415 oal_net_dev_priv(hmac_vap->net_device) = HI_NULL;
416 hmac_vap->net_device = hmac_vap->p2p0_net_device;
417 mac_dec_p2p_num(hmac_vap->base_vap);
418 mac_vap_set_p2p_mode(hmac_vap->base_vap, WLAN_P2P_DEV_MODE);
419 if (memcpy_s(hmac_vap->base_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN,
420 hmac_vap->base_vap->mib_info->wlan_mib_sta_config.auc_p2p0_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
421 oam_error_log0(0, OAM_SF_CFG, "hmac_p2p_del_gc_vap:: auc_p2p0_dot11StationID memcpy_s fail.");
422 return HI_FAIL;
423 }
424
425 if (hmac_vap->puc_asoc_req_ie_buff != HI_NULL) {
426 oal_mem_free(hmac_vap->puc_asoc_req_ie_buff);
427 hmac_vap->puc_asoc_req_ie_buff = HI_NULL;
428 }
429
430 /* **************************************************************************
431 抛事件到DMAC层, 同步DMAC数据
432 ************************************************************************** */
433 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_DEL_VAP, us_len, puc_param);
434 if (oal_unlikely(ret != HI_SUCCESS)) {
435 oam_warning_log1(mac_vap->vap_id, OAM_SF_CFG,
436 "{hmac_p2p_del_gc_vap::hmac_config_send_event failed[%d].}", ret);
437 return ret;
438 }
439
440 oam_info_log2(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_del_gc_vap::func out.vap_mode[%d], p2p_mode[%d]}",
441 del_vap_param->vap_mode, del_vap_param->p2p_mode);
442 return HI_SUCCESS;
443 }
444
445 /* ****************************************************************************
446 函 数 名 : hmac_p2p_send_listen_expired_to_host
447 功能描述 : 监听超时处理,通知WAL 监听超时
448 输入参数 : mac_device_stru *mac_device
449 输出参数 : 无
450 返 回 值 : hi_u32
451 调用函数 :
452 被调函数 :
453
454 修改历史 :
455 1.日 期 : 2014年11月25日
456 作 者 : HiSilicon
457 修改内容 : 新生成函数
458
459 **************************************************************************** */
hmac_p2p_send_listen_expired_to_host(const hmac_vap_stru * hmac_vap)460 hi_u32 hmac_p2p_send_listen_expired_to_host(const hmac_vap_stru *hmac_vap)
461 {
462 mac_device_stru *mac_dev = HI_NULL;
463 oal_wireless_dev *wdev = HI_NULL;
464 mac_p2p_info_stru *p2p_info = HI_NULL;
465 hmac_p2p_listen_expired_stru p2p_listen_expired = {0};
466
467 mac_dev = mac_res_get_dev();
468 p2p_info = &mac_dev->p2p_info;
469
470 /* 填写上报监听超时, 上报的网络设备应该采用p2p0 */
471 if (hmac_vap->p2p0_net_device != HI_NULL &&
472 hmac_vap->p2p0_net_device->ieee80211Ptr != HI_NULL) {
473 wdev = hmac_vap->p2p0_net_device->ieee80211Ptr;
474 } else {
475 wdev = hmac_vap->net_device->ieee80211Ptr;
476 }
477 p2p_listen_expired.st_listen_channel = p2p_info->st_listen_channel;
478 p2p_listen_expired.wdev = wdev;
479
480 return hmac_send_event_to_host(hmac_vap->base_vap, (const hi_u8 *)(&p2p_listen_expired),
481 sizeof(hmac_p2p_listen_expired_stru), HMAC_HOST_CTX_EVENT_SUB_TYPE_LISTEN_EXPIRED);
482 }
483
484 /* ****************************************************************************
485 函 数 名 : hmac_p2p_send_listen_expired_to_device
486 功能描述 : 监听超时处理,通知DMAC 返回home 信道
487 输入参数 : [1]hmac_vap
488 输出参数 : 无
489 返 回 值 : hi_u32
490 **************************************************************************** */
hmac_p2p_send_listen_expired_to_device(const hmac_vap_stru * hmac_vap)491 hi_u32 hmac_p2p_send_listen_expired_to_device(const hmac_vap_stru *hmac_vap)
492 {
493 mac_device_stru *mac_dev = HI_NULL;
494 mac_vap_stru *mac_vap = HI_NULL;
495 mac_p2p_info_stru *p2p_info = HI_NULL;
496 hi_u32 ret;
497 hmac_device_stru *hmac_dev = HI_NULL;
498
499 mac_dev = mac_res_get_dev();
500 /* **************************************************************************
501 抛事件到DMAC层, 同步DMAC数据
502 ************************************************************************** */
503 p2p_info = &mac_dev->p2p_info;
504 mac_vap = hmac_vap->base_vap;
505 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_CFG80211_CANCEL_REMAIN_ON_CHANNEL, sizeof(mac_p2p_info_stru),
506 (hi_u8 *)p2p_info);
507
508 /* 强制stop listen */
509 hmac_dev = hmac_get_device_stru();
510 hmac_dev->scan_mgmt.is_scanning = HI_FALSE;
511
512 if (oal_unlikely(ret != HI_SUCCESS)) {
513 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P,
514 "{hmac_p2p_send_listen_expired_to_device::hmac_config_send_event failed[%d].}", ret);
515 return ret;
516 }
517
518 return HI_SUCCESS;
519 }
520
521 /* ****************************************************************************
522 函 数 名 : hmac_p2p_disable_pm
523 功能描述 : 停止p2p noa,p2p oppps
524 输入参数 : [1]hmac_vap
525 输出参数 : 无
526 返 回 值 : 无
527 **************************************************************************** */
hmac_p2p_disable_pm(const hmac_vap_stru * hmac_vap)528 hi_void hmac_p2p_disable_pm(const hmac_vap_stru *hmac_vap)
529 {
530 mac_vap_stru *mac_vap = HI_NULL;
531 mac_cfg_p2p_ops_param_stru p2p_ops;
532 mac_cfg_p2p_noa_param_stru p2p_noa;
533 hi_u32 ret;
534
535 mac_vap = hmac_vap->base_vap;
536
537 if (memset_s(&p2p_noa, sizeof(p2p_noa), 0, sizeof(p2p_noa)) != EOK) {
538 return;
539 }
540 ret = hmac_p2p_set_ps_noa(mac_vap, sizeof(mac_cfg_p2p_noa_param_stru), (hi_u8 *)&p2p_noa);
541 if (ret != HI_SUCCESS) {
542 oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_P2P,
543 "{hmac_p2p_disable_pm::hmac_p2p_set_ps_noa disable p2p NoA fail.}");
544 }
545 if (memset_s(&p2p_ops, sizeof(p2p_ops), 0, sizeof(p2p_ops)) != EOK) {
546 return;
547 }
548 ret = hmac_p2p_set_ps_ops(mac_vap, sizeof(mac_cfg_p2p_ops_param_stru), (hi_u8 *)&p2p_ops);
549 if (ret != HI_SUCCESS) {
550 oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_P2P,
551 "{hmac_p2p_disable_pm::hmac_p2p_set_ps_ops disable p2p OppPS fail.}");
552 }
553 }
554
555 /* ****************************************************************************
556 函 数 名 : hmac_p2p_is_go_neg_req_frame
557 功能描述 : 是否是P2P GO negotiation request action帧
558 输入参数 : [1]puc_data
559 输出参数 : 无
560 返 回 值 : HI_TRUE 是P2P GO negotiation request action帧
561 **************************************************************************** */
hmac_p2p_is_go_neg_req_frame(const hi_u8 * puc_data)562 hi_u32 hmac_p2p_is_go_neg_req_frame(const hi_u8 *puc_data)
563 {
564 if ((puc_data[MAC_ACTION_OFFSET_CATEGORY + MAC_80211_FRAME_LEN] == MAC_ACTION_CATEGORY_PUBLIC) &&
565 (puc_data[P2P_PUB_ACT_OUI_OFF1 + MAC_80211_FRAME_LEN] == WFA_OUI_BYTE1) &&
566 (puc_data[P2P_PUB_ACT_OUI_OFF2 + MAC_80211_FRAME_LEN] == WFA_OUI_BYTE2) &&
567 (puc_data[P2P_PUB_ACT_OUI_OFF3 + MAC_80211_FRAME_LEN] == WFA_OUI_BYTE3) &&
568 (puc_data[P2P_PUB_ACT_OUI_TYPE_OFF + MAC_80211_FRAME_LEN] == WFA_P2P_V1_0) &&
569 (puc_data[P2P_PUB_ACT_OUI_SUBTYPE_OFF + MAC_80211_FRAME_LEN] == P2P_PAF_GON_REQ)) {
570 return HI_TRUE;
571 } else {
572 return HI_FALSE;
573 }
574 }
575
576 /* ****************************************************************************
577 函 数 名 : hmac_p2p_get_status
578 功能描述 : 判断p2p 是否为该状态
579 输入参数 : hi_u32 ul_p2p_status
580 wlan_p2p_status_enum_uint32 en_status
581 输出参数 : 无
582 返 回 值 : hi_u8
583 调用函数 :
584 被调函数 :
585
586 修改历史 :
587 1.日 期 : 2015年5月20日
588 作 者 : HiSilicon
589 修改内容 : 新生成函数
590
591 **************************************************************************** */
hmac_p2p_get_status(hi_u32 p2p_status,wlan_p2p_status_enum_uint32 status)592 hi_u32 hmac_p2p_get_status(hi_u32 p2p_status, wlan_p2p_status_enum_uint32 status)
593 {
594 if (p2p_status & bit(status)) {
595 return HI_TRUE;
596 } else {
597 return HI_FALSE;
598 }
599 }
600
601 /* ****************************************************************************
602 函 数 名 : hmac_p2p_set_status
603 功能描述 : 设置p2p 为对应状态
604 输入参数 : hi_u32 ul_p2p_status
605 wlan_p2p_status_enum_uint32 en_status
606 输出参数 : 无
607 返 回 值 : hi_u8
608 调用函数 :
609 被调函数 :
610
611 修改历史 :
612 1.日 期 : 2015年5月20日
613 作 者 : HiSilicon
614 修改内容 : 新生成函数
615
616 **************************************************************************** */
hmac_p2p_set_status(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)617 hi_u32 hmac_p2p_set_status(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
618 {
619 wlan_p2p_status_enum_uint32 *status = HI_NULL;
620 hmac_device_stru *hmac_dev = HI_NULL;
621
622 hi_unref_param(us_len);
623 hi_unref_param(mac_vap);
624 hmac_dev = hmac_get_device_stru();
625 status = (wlan_p2p_status_enum_uint32 *)puc_param;
626
627 hmac_dev->p2p_intf_status |= ((hi_u32)bit(*status));
628
629 return HI_SUCCESS;
630 }
631
632 /* ****************************************************************************
633 函 数 名 : hmac_p2p_clr_status
634 功能描述 : 清除p2p 对应状态
635 输入参数 : hi_u32 ul_p2p_status
636 wlan_p2p_status_enum_uint32 en_status
637 输出参数 : 无
638 返 回 值 : hi_u8
639 调用函数 :
640 被调函数 :
641
642 修改历史 :
643 1.日 期 : 2015年5月20日
644 作 者 : HiSilicon
645 修改内容 : 新生成函数
646
647 **************************************************************************** */
hmac_p2p_clr_status(hi_u32 * pul_p2p_status,wlan_p2p_status_enum_uint32 status)648 hi_void hmac_p2p_clr_status(hi_u32 *pul_p2p_status, wlan_p2p_status_enum_uint32 status)
649 {
650 *pul_p2p_status &= ~((hi_u32)bit(status));
651 }
652
653 /* ****************************************************************************
654 功能描述 : 封装p2p action帧
655 输入参数 : mac_vap: MAC VAP
656 pst_mgmt_buf: buffer起始地址
657 pst_peer_param: 上层数据信息
658 us_len: 长度
659 返 回 值 : 封装后的帧总长度
660
661 修改历史 :
662 1.日 期 : 2019年1月24日
663 作 者 : HiSilicon
664 修改内容 : 新生成函数
665 **************************************************************************** */
hmac_p2p_encap_action(hi_u8 * puc_data,const mac_action_data_stru * action_data)666 hi_u32 hmac_p2p_encap_action(hi_u8 *puc_data, const mac_action_data_stru *action_data)
667 {
668 hi_u8 *puc_frame_origin = HI_NULL;
669 hi_u32 us_frame_len;
670
671 /* 保存起始地址,便于计算长度 */
672 puc_frame_origin = puc_data;
673
674 /* *********************************************************************** */
675 /* Management Frame Format */
676 /* -------------------------------------------------------------------- */
677 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
678 /* -------------------------------------------------------------------- */
679 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
680 /* -------------------------------------------------------------------- */
681 /* */
682 /* *********************************************************************** */
683 /* *********************************************************************** */
684 /* Set the fields in the frame header */
685 /* *********************************************************************** */
686 /* 设置 Frame Control field */
687 mac_hdr_set_frame_control(puc_data, WLAN_FC0_SUBTYPE_ACTION);
688
689 /* 设置 DA address1: 远端节点MAC地址 */
690 if (memcpy_s(puc_data + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN,
691 action_data->dst, WLAN_MAC_ADDR_LEN) != EOK) {
692 oam_error_log0(0, 0, "{hmac_p2p_encap_action::memcpy_s fail.}");
693 return 0;
694 }
695 /* 设置 SA address2: dot11MACAddress */
696 if (memcpy_s(puc_data + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
697 action_data->src, WLAN_MAC_ADDR_LEN) != EOK) {
698 oam_error_log0(0, 0, "{hmac_p2p_encap_action::memcpy_s fail.}");
699 return 0;
700 }
701 /* 设置 DA address3::BSSID */
702 if (memcpy_s(puc_data + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN,
703 action_data->bssid, WLAN_MAC_ADDR_LEN) != EOK) {
704 oam_error_log0(0, 0, "{hmac_p2p_encap_action::memcpy_s fail.}");
705 return 0;
706 }
707 puc_data += MAC_80211_FRAME_LEN;
708
709 /* 填充payload信息 */
710 if (action_data->data_len > 0) {
711 if (memcpy_s(puc_data, action_data->data_len,
712 action_data->data, action_data->data_len) != EOK) {
713 oam_error_log0(0, 0, "{hmac_p2p_encap_action::memcpy_s fail.}");
714 return 0;
715 }
716 puc_data += action_data->data_len;
717 }
718 us_frame_len = (hi_u32)(puc_data - puc_frame_origin);
719
720 return us_frame_len;
721 }
722
723 /* ****************************************************************************
724 功能描述 : 1102 设置WPS/P2P 信息元素
725 输入参数 : [1]mac_vap
726 [2]us_len
727 [3]puc_param
728 返 回 值 : hi_u32
729 **************************************************************************** */
hmac_p2p_set_wps_p2p_ie(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)730 hi_u32 hmac_p2p_set_wps_p2p_ie(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
731 {
732 oal_app_ie_stru *wps_p2p_ie = HI_NULL;
733 hmac_vap_stru *hmac_vap = HI_NULL;
734 hi_u32 ret;
735
736 hi_unref_param(us_len);
737 wps_p2p_ie = (oal_app_ie_stru *)puc_param;
738
739 /* 设置WPS/P2P 信息 */
740 ret = hmac_config_set_app_ie_to_vap(mac_vap, wps_p2p_ie, wps_p2p_ie->app_ie_type);
741 if (ret != HI_SUCCESS) {
742 return ret;
743 }
744
745 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
746 if (hmac_vap == HI_NULL) {
747 oam_warning_log0(mac_vap->vap_id, OAM_SF_CFG, "{hmac_p2p_set_wps_p2p_ie::hmac_vap null.}");
748 return HI_ERR_CODE_PTR_NULL;
749 }
750
751 /* 检测beacon 信息中是否有WPS 信息元素 */
752 if (wps_p2p_ie->app_ie_type == OAL_APP_BEACON_IE) {
753 if (wps_p2p_ie->ie_len != 0 && mac_find_vendor_ie(MAC_WLAN_OUI_MICROSOFT, MAC_WLAN_OUI_TYPE_MICROSOFT_WPS,
754 wps_p2p_ie->auc_ie, (hi_s32)(wps_p2p_ie->ie_len)) != HI_NULL) {
755 /* 设置WPS 功能使能 */
756 hmac_vap->wps_active = HI_TRUE;
757 oam_info_log0(mac_vap->vap_id, OAM_SF_CFG, "{hmac_p2p_set_wps_p2p_ie::set wps enable.}");
758 } else {
759 hmac_vap->wps_active = HI_FALSE;
760 }
761 }
762
763 return ret;
764 }
765
766 /* ****************************************************************************
767 功能描述 : 查找P2P attribute信息元素
768 输入参数 : [1]eid
769 [2]puc_ies
770 [3]l_len
771 返 回 值 : hi_u8 *
772 **************************************************************************** */
hmac_p2p_find_attribute(hi_u8 eid,hi_u8 * puc_ies,hi_s32 l_len)773 static hi_u8 *hmac_p2p_find_attribute(hi_u8 eid, hi_u8 *puc_ies, hi_s32 l_len)
774 {
775 hi_s32 ie_len = 0;
776
777 /* 查找P2P IE,如果不是直接找下一个 */
778 while (l_len > MAC_P2P_ATTRIBUTE_HDR_LEN && puc_ies[0] != eid) {
779 ie_len = (hi_s32)((puc_ies[2] << 8) + puc_ies[1]); /* 2:下标,8:左移8位,1:下标 */
780 l_len -= ie_len + MAC_P2P_ATTRIBUTE_HDR_LEN;
781 puc_ies += ie_len + MAC_P2P_ATTRIBUTE_HDR_LEN;
782 }
783 /* 查找到P2P IE,剩余长度不匹配直接返回空指针 */
784 ie_len = (hi_s32)((puc_ies[2] << 8) + puc_ies[1]); /* 1:下标,2:下标,8:向左位移动8位 */
785 if ((l_len < MAC_P2P_ATTRIBUTE_HDR_LEN) || (l_len < (MAC_P2P_ATTRIBUTE_HDR_LEN + ie_len))) {
786 return HI_NULL;
787 }
788
789 return puc_ies;
790 }
791
792 /* ****************************************************************************
793 功能描述 : 查找wpa_supplicant 下发的IE 中的P2P IE中的listen channel
794 输入参数 : hi_u8 *puc_param wpa_supplicant 下发的ie
795 hi_u16 us_len wpa_supplicant 下发的ie 长度
796 修改历史 :
797 1.日 期 : 2015年9月10日
798 作 者 : HiSilicon
799 修改内容 : 新生成函数
800 **************************************************************************** */
hmac_p2p_find_listen_channel(mac_vap_stru * mac_vap,hi_u16 us_len,hi_u8 * puc_param)801 hi_u32 hmac_p2p_find_listen_channel(mac_vap_stru *mac_vap, hi_u16 us_len, hi_u8 *puc_param)
802 {
803 hi_u8 *puc_p2p_ie = HI_NULL;
804 hi_u8 *puc_listen_channel_ie = HI_NULL;
805
806 /* 查找P2P IE信息 */
807 puc_p2p_ie = mac_find_vendor_ie(MAC_WLAN_OUI_WFA, MAC_WLAN_OUI_TYPE_WFA_P2P, puc_param, (hi_s32)us_len);
808 if (puc_p2p_ie == HI_NULL) {
809 oam_error_log0(mac_vap->vap_id, OAM_SF_CFG, "{hmac_p2p_find_listen_channel::p2p ie is null.}");
810 return HI_ERR_CODE_PTR_NULL;
811 }
812
813 /* 长度校验 */
814 if (puc_p2p_ie[1] < MAC_P2P_MIN_IE_LEN) {
815 oam_warning_log1(mac_vap->vap_id, OAM_SF_CFG, "{hmac_p2p_find_listen_channel::invalid p2p ie len[%d].}",
816 puc_p2p_ie[1]);
817 return HI_FAIL;
818 }
819
820 /* 查找P2P Listen channel信息 */
821 puc_listen_channel_ie = hmac_p2p_find_attribute(MAC_P2P_ATTRIBUTE_LISTEN_CHAN, puc_p2p_ie + 6,
822 (puc_p2p_ie[1] - 4)); /* 1:下标,4:减4,6:加6 */
823 if (puc_listen_channel_ie == HI_NULL) {
824 oam_error_log0(mac_vap->vap_id, OAM_SF_CFG, "{hmac_p2p_find_listen_channel::p2p listen channel ie is null.}");
825 return HI_ERR_CODE_PTR_NULL;
826 }
827
828 /* listen channel长度校验,大端 1:下标,2:下标,8:向左位移8位 */
829 if ((hi_s32)((puc_listen_channel_ie[2] << 8) + puc_listen_channel_ie[1]) != MAC_P2P_LISTEN_CHN_ATTR_LEN) {
830 oam_warning_log1(mac_vap->vap_id, OAM_SF_CFG,
831 "{hmac_p2p_find_listen_channel::invalid p2p listen channel ie len[%d].}",
832 /* 1:下标,2:下标,8:向左位移8位 */
833 (hi_s32)((puc_listen_channel_ie[2] << 8) + puc_listen_channel_ie[1]));
834 return HI_FAIL;
835 }
836
837 /* 获取P2P Listen channel信息 */
838 mac_vap->p2p_listen_channel = puc_listen_channel_ie[7]; /* 7:下标 */
839 oam_info_log1(mac_vap->vap_id, OAM_SF_CFG, "{hmac_p2p_find_listen_channel::END CHANNEL[%d].}",
840 mac_vap->p2p_listen_channel);
841
842 return HI_SUCCESS;
843 }
844
845 /* ****************************************************************************
846 功能描述 : 删除wpa_supplicant 下发的IE 中的P2P IE
847 输入参数 : hi_u8 *puc_ie wpa_supplicant 下发的ie
848 hi_u32 *ie_len wpa_supplicant 下发的ie 长度
849 修改历史 :
850 1.日 期 : 2015年8月11日
851 作 者 : HiSilicon
852 修改内容 : 新生成函数
853 **************************************************************************** */
hmac_p2p_del_ie(hi_u8 * puc_ie,hi_u32 * ie_len)854 hi_void hmac_p2p_del_ie(hi_u8 *puc_ie, hi_u32 *ie_len)
855 {
856 hi_u8 *puc_p2p_ie = HI_NULL;
857 hi_u32 p2p_ie_len;
858 hi_u8 *puc_ie_end = HI_NULL;
859 hi_u8 *puc_p2p_ie_end = HI_NULL;
860
861 if ((puc_ie == HI_NULL) || (ie_len == HI_NULL) || (*ie_len == 0)) {
862 return;
863 }
864
865 puc_p2p_ie = mac_find_vendor_ie(MAC_WLAN_OUI_WFA, MAC_WLAN_OUI_TYPE_WFA_P2P, puc_ie, (hi_s32)(*ie_len));
866 if ((puc_p2p_ie == HI_NULL) || (puc_p2p_ie[1] < MAC_P2P_MIN_IE_LEN)) {
867 return;
868 }
869
870 p2p_ie_len = puc_p2p_ie[1] + MAC_IE_HDR_LEN;
871
872 /* 将p2p ie 后面的内容拷贝到p2p ie 所在位置 */
873 puc_ie_end = (puc_ie + *ie_len);
874 puc_p2p_ie_end = (puc_p2p_ie + p2p_ie_len);
875
876 if (puc_ie_end >= puc_p2p_ie_end) {
877 if (memmove_s(puc_p2p_ie, (hi_u32)(puc_ie_end - puc_p2p_ie_end), puc_p2p_ie_end,
878 (hi_u32)(puc_ie_end - puc_p2p_ie_end)) != EOK) {
879 oam_error_log0(0, OAM_SF_CFG, "{hmac_p2p_del_ie::memmove_s failed.}");
880 return;
881 }
882 *ie_len -= p2p_ie_len;
883 }
884 return;
885 }
886
887 /* ***************************************************************************
888 功能描述 : HMAC层抛p2p发送状态事件到wal
889 修改历史 :
890 1.日 期 : 2019年8月15日
891 作 者 : HiSilicon
892 修改内容 : 新生成函数
893 **************************************************************************** */
hmac_p2p_tx_status_event(const mac_vap_stru * mac_vap,const hi_u8 * puc_buf,hi_u32 len,hi_u8 ack)894 hi_u32 hmac_p2p_tx_status_event(const mac_vap_stru *mac_vap, const hi_u8 *puc_buf, hi_u32 len, hi_u8 ack)
895 {
896 mac_p2p_tx_status_stru p2p_tx_status = {0};
897 hi_u32 ret;
898
899 p2p_tx_status.puc_buf = oal_memalloc(len);
900 if (p2p_tx_status.puc_buf == HI_NULL) {
901 oam_error_log1(0, OAM_SF_P2P, "{hmac_p2p_action_tx_status_event::p2p_tx_status->puc_buf malloc error %p.}",
902 (uintptr_t)p2p_tx_status.puc_buf);
903 return HI_FALSE;
904 }
905 if (memcpy_s(p2p_tx_status.puc_buf, len, puc_buf, len) != EOK) {
906 oam_error_log0(0, OAM_SF_P2P, "{hmac_p2p_action_tx_status_event::mem safe function err!}");
907 oal_free(p2p_tx_status.puc_buf);
908 return HI_FALSE;
909 }
910 p2p_tx_status.len = len;
911 p2p_tx_status.ack = ack;
912
913 ret = hmac_send_event_to_host(mac_vap, (const hi_u8 *)(&p2p_tx_status), sizeof(mac_p2p_tx_status_stru),
914 HMAC_HOST_CTX_EVENT_SUB_TYPE_P2P_TX_STATUS);
915 if (ret != HI_SUCCESS) {
916 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P,
917 "{hmac_p2p_action_tx_status_event::frw_event_dispatch_event fail [%d].}", ret);
918 oal_free(p2p_tx_status.puc_buf);
919 }
920 return ret;
921 }
922
hmac_p2p_send_action_error(const mac_action_data_stru * action_data,oal_netbuf_stru * puc_data)923 static inline hi_u32 hmac_p2p_send_action_error(const mac_action_data_stru *action_data, oal_netbuf_stru *puc_data)
924 {
925 /* 释放上层申请的puc_data空间 */
926 if (action_data->data_len > 0) {
927 oal_free(action_data->data);
928 }
929 if (puc_data != HI_NULL) {
930 oal_netbuf_free(puc_data);
931 }
932 return HI_FAIL;
933 }
934
935 /* ****************************************************************************
936 功能描述 : P2P 发送Action 帧
937 修改历史 :
938 1.日 期 : 2019年4月29日
939 作 者 : HiSilicon
940 修改内容 : 新生成函数
941 **************************************************************************** */
hmac_p2p_send_action(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)942 hi_u32 hmac_p2p_send_action(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
943 {
944 hi_unref_param(us_len);
945 if (hmac_vap_get_vap_stru(mac_vap->vap_id) == HI_NULL) {
946 oam_warning_log0(0, OAM_SF_P2P, "{hmac_p2p_send_action::hmac_vap null.}");
947 return hmac_p2p_send_action_error((mac_action_data_stru *)puc_param, HI_NULL);
948 }
949
950 mac_action_data_stru *action_data = (mac_action_data_stru *)puc_param;
951 hi_u8 action_code = mac_get_action_code(action_data->data); /* 获取Action category、code */
952 oal_netbuf_stru *puc_data = (oal_netbuf_stru *)oal_netbuf_alloc(WLAN_MGMT_NETBUF_SIZE, 0, 4); /* align 4 */
953 if (puc_data == HI_NULL) {
954 oam_error_log0(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_send_action::[MESH]puc_data null.}");
955 return hmac_p2p_send_action_error(action_data, HI_NULL);
956 }
957
958 /* 安全编程规则6.6例外(3)从堆中分配内存后,赋予初值 */
959 memset_s(oal_netbuf_cb(puc_data), oal_netbuf_cb_size(), 0, oal_netbuf_cb_size());
960
961 if (memset_s((hi_u8 *)oal_netbuf_header(puc_data), MAC_80211_FRAME_LEN, 0, MAC_80211_FRAME_LEN) != EOK) {
962 oam_error_log0(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_send_action::[MESH]memset_s ERR.}");
963 return hmac_p2p_send_action_error(action_data, puc_data);
964 }
965
966 if (action_code != MAC_PUB_VENDOR_SPECIFIC) {
967 oam_error_log1(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_send_action::P2P:self-protected Err:%d}", action_code);
968 return hmac_p2p_send_action_error(action_data, puc_data);
969 }
970 hi_u8 *puc_data_header = HI_NULL;
971 hi_u32 action_len = hmac_p2p_encap_action((hi_u8 *)(oal_netbuf_header(puc_data)), action_data);
972 if (action_len == 0) { /* 组帧失败 */
973 return hmac_p2p_send_action_error(action_data, puc_data);
974 }
975 puc_data_header = oal_memalloc(action_len);
976 if (puc_data_header == HI_NULL) {
977 return hmac_p2p_send_action_error(action_data, puc_data);
978 }
979 memset_s(puc_data_header, action_len, 0, action_len);
980 if (memcpy_s(puc_data_header, action_len, oal_netbuf_header(puc_data), action_len) != EOK) {
981 oal_free(puc_data_header);
982 return hmac_p2p_send_action_error(action_data, puc_data);
983 }
984
985 oal_netbuf_put(puc_data, action_len);
986
987 /* 为填写发送描述符准备参数 */
988 hmac_tx_ctl_stru *tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(puc_data);
989 tx_ctl->us_mpdu_len = action_len; /* dmac发送需要的mpdu长度 */
990 tx_ctl->frame_header_length = MAC_80211_FRAME_LEN;
991 tx_ctl->frame_header = (mac_ieee80211_frame_stru *)oal_netbuf_header(puc_data);
992 tx_ctl->mac_head_type = 1;
993
994 /* 抛事件让dmac将该帧发送 */
995 hi_u32 ret = hmac_tx_mgmt_send_event(mac_vap, puc_data, action_len);
996 if (ret != HI_SUCCESS) {
997 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_send_action::P2P:hmac_tx_mgmt_send_event Err%d}", ret);
998
999 ret = hmac_p2p_tx_status_event(mac_vap, (hi_u8 *)(oal_netbuf_header(puc_data)), action_len, HI_FALSE);
1000 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_send_action:hmac_p2p_action_tx_status_event=%d}", ret);
1001 oal_free(puc_data_header);
1002 return hmac_p2p_send_action_error(action_data, puc_data);
1003 }
1004
1005 if (hmac_p2p_tx_status_event(mac_vap, puc_data_header, action_len, HI_TRUE) != HI_SUCCESS) {
1006 oam_warning_log0(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_send_action:hmac_p2p_action_tx_status_event ERR}");
1007 }
1008
1009 oal_free(puc_data_header);
1010 return HI_SUCCESS;
1011 }
1012
1013 /* ****************************************************************************
1014 功能描述 : 设置P2P OPS 节能
1015 输入参数 : [1]mac_vap
1016 [2]us_len
1017 [3]puc_param
1018 返 回 值 : hi_u32
1019 **************************************************************************** */
hmac_p2p_set_ps_ops(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)1020 hi_u32 hmac_p2p_set_ps_ops(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
1021 {
1022 hi_u32 ret;
1023
1024 /* **************************************************************************
1025 抛事件到DMAC层, 同步DMAC数据
1026 ************************************************************************** */
1027 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_SET_P2P_PS_OPS, us_len, puc_param);
1028 if (oal_unlikely(ret != HI_SUCCESS)) {
1029 oam_warning_log1(mac_vap->vap_id, OAM_SF_CFG,
1030 "{hmac_p2p_set_ps_ops::hmac_config_send_event failed[%d].}", ret);
1031 }
1032
1033 return ret;
1034 }
1035
1036 /* ****************************************************************************
1037 功能描述 : 设置P2P NOA 节能
1038 输入参数 : [1]mac_vap
1039 [2]us_len
1040 [3]puc_param
1041 返 回 值 : hi_u32
1042 **************************************************************************** */
hmac_p2p_set_ps_noa(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)1043 hi_u32 hmac_p2p_set_ps_noa(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
1044 {
1045 hi_u32 ret;
1046 mac_cfg_p2p_noa_param_stru *p2p_noa = HI_NULL;
1047
1048 p2p_noa = (mac_cfg_p2p_noa_param_stru *)puc_param;
1049
1050 /* ms to us */
1051 p2p_noa->start_time *= 1000; /* 1000:时间 */
1052 p2p_noa->duration *= 1000; /* 1000:时间 */
1053 p2p_noa->interval *= 1000; /* 1000:时间 */
1054 /***************************************************************************
1055 抛事件到DMAC层, 同步DMAC数据
1056 ************************************************************************** */
1057 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_SET_P2P_PS_NOA, us_len, puc_param);
1058 if (oal_unlikely(ret != HI_SUCCESS)) {
1059 oam_warning_log1(mac_vap->vap_id, OAM_SF_CFG,
1060 "{hmac_p2p_set_ps_noa::hmac_config_send_event failed[%d].}", ret);
1061 }
1062
1063 return ret;
1064 }
1065
1066 /* ****************************************************************************
1067 功能描述 : P2P 监听超时处理函数
1068 输入参数 : *p_arg
1069 修改历史 :
1070 1.日 期 : 2015年5月29日
1071 作 者 : HiSilicon
1072 修改内容 : 新生成函数
1073 **************************************************************************** */
hmac_p2p_listen_comp_cb(hi_void * arg)1074 hi_void hmac_p2p_listen_comp_cb(hi_void *arg)
1075 {
1076 hmac_vap_stru *hmac_vap = HI_NULL;
1077 mac_device_stru *mac_dev = HI_NULL;
1078 hmac_scan_record_stru *scan_record = HI_NULL;
1079
1080 scan_record = (hmac_scan_record_stru *)arg;
1081
1082 /* 判断listen完成时的状态 */
1083 if (scan_record->scan_rsp_status != MAC_SCAN_SUCCESS) {
1084 oam_warning_log1(0, OAM_SF_P2P, "{hmac_p2p_listen_comp_cb::listen failed, listen rsp status: %d.}",
1085 scan_record->scan_rsp_status);
1086 }
1087
1088 hmac_vap = hmac_vap_get_vap_stru(scan_record->vap_id);
1089 if ((hmac_vap == HI_NULL) || (hmac_vap->base_vap == HI_NULL)) {
1090 oam_error_log1(0, OAM_SF_P2P, "{hmac_p2p_listen_comp_cb::hmac_vap is null:vap_id %d.}", scan_record->vap_id);
1091 return;
1092 }
1093
1094 mac_dev = mac_res_get_dev();
1095 if (scan_record->ull_cookie == mac_dev->p2p_info.ull_last_roc_id) {
1096 if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_STA_LISTEN) {
1097 hmac_p2p_listen_timeout(hmac_vap->base_vap);
1098 }
1099 } else {
1100 oam_warning_log3(hmac_vap->base_vap->vap_id, OAM_SF_P2P,
1101 "{hmac_p2p_listen_comp_cb::ignore listen complete.scan_report_cookie[%x],"
1102 "current_listen_cookie[%x], ull_last_roc_id[%x].}",
1103 scan_record->ull_cookie, mac_dev->scan_params.ull_cookie, mac_dev->p2p_info.ull_last_roc_id);
1104 }
1105
1106 return;
1107 }
1108
1109
1110 /* ****************************************************************************
1111 功能描述 : 准备p2p监听请求的对应参数
1112 输入参数 : mac_scan_req_stru *scan_params, 扫描参数
1113 hi_s8 *puc_param, p2p监听参数
1114 修改历史 :
1115 1.日 期 : 2015年5月29日
1116 作 者 : HiSilicon
1117 修改内容 : 新生成函数
1118 **************************************************************************** */
hmac_p2p_prepare_listen_req_param(mac_scan_req_stru * scan_params,hi_s8 * puc_param)1119 static hi_void hmac_p2p_prepare_listen_req_param(mac_scan_req_stru *scan_params, hi_s8 *puc_param)
1120 {
1121 mac_remain_on_channel_param_stru *remain_on_channel = HI_NULL;
1122 mac_channel_stru *channel_tmp = HI_NULL;
1123
1124 remain_on_channel = (mac_remain_on_channel_param_stru *)puc_param;
1125
1126 if (memset_s(scan_params, sizeof(mac_scan_req_stru), 0, sizeof(mac_scan_req_stru)) != EOK) {
1127 return;
1128 }
1129
1130 /* 设置监听信道信息到扫描参数中 */
1131 scan_params->ast_channel_list[0].band = remain_on_channel->band;
1132 scan_params->ast_channel_list[0].en_bandwidth = remain_on_channel->listen_channel_type;
1133 scan_params->ast_channel_list[0].chan_number = remain_on_channel->uc_listen_channel;
1134 scan_params->ast_channel_list[0].idx = 0;
1135 channel_tmp = &(scan_params->ast_channel_list[0]);
1136 if (mac_get_channel_idx_from_num(channel_tmp->band, channel_tmp->chan_number, &(channel_tmp->idx)) != HI_SUCCESS) {
1137 oam_warning_log2(0, OAM_SF_P2P,
1138 "{hmac_p2p_prepare_listen_req_param::mac_get_channel_idx_from_num fail.band[%u] channel[%u]}",
1139 channel_tmp->band, channel_tmp->chan_number);
1140 }
1141
1142 /* 设置其它监听参数 */
1143 scan_params->max_scan_cnt_per_channel = 1;
1144 scan_params->channel_nums = 1;
1145 scan_params->scan_func = MAC_SCAN_FUNC_P2P_LISTEN;
1146 scan_params->us_scan_time = (hi_u16)remain_on_channel->listen_duration;
1147 scan_params->fn_cb = hmac_p2p_listen_comp_cb;
1148 scan_params->ull_cookie = remain_on_channel->ull_cookie;
1149
1150 return;
1151 }
1152
1153 /* ****************************************************************************
1154 功能描述 : 设置device 到指定信道监听,并设置监听超时定时器
1155 如果是从up 状态进入listen ,则返回up
1156 如果是从scan complete 状态进入,则返回scan complete
1157 输入参数 : [1]hmac_vap_sta
1158 [2]remain_on_channel
1159 返 回 值 : hi_u32
1160 **************************************************************************** */
hmac_p2p_remain_on_channel(const hmac_vap_stru * hmac_vap,mac_remain_on_channel_param_stru * remain_on_channel)1161 hi_u32 hmac_p2p_remain_on_channel(const hmac_vap_stru *hmac_vap, mac_remain_on_channel_param_stru *remain_on_channel)
1162 {
1163 mac_device_stru *mac_dev = HI_NULL;
1164 mac_vap_stru *mac_vap = HI_NULL;
1165 mac_scan_req_stru scan_params;
1166
1167 mac_vap = mac_vap_get_vap_stru(hmac_vap->base_vap->vap_id);
1168 if (mac_vap == HI_NULL) {
1169 oam_error_log1(0, OAM_SF_P2P, "{hmac_p2p_remain_on_channel::mac_vap_get_vap_stru fail.vap_id[%u]!}",
1170 hmac_vap->base_vap->vap_id);
1171 return HI_ERR_CODE_PTR_NULL;
1172 }
1173 mac_dev = mac_res_get_dev();
1174 if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_STA_LISTEN) {
1175 if (hmac_p2p_send_listen_expired_to_host(hmac_vap) != HI_SUCCESS) {
1176 oam_warning_log0(mac_vap->vap_id, OAM_SF_P2P, "hmac_p2p_send_listen_expired_to_host return NON SUCCESS. ");
1177 }
1178
1179 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P,
1180 "{hmac_p2p_remain_on_channel::listen nested, send remain on channel expired to host!curr_state[%d]\r\n}",
1181 hmac_vap->base_vap->vap_state);
1182 }
1183
1184 mac_vap_state_change(hmac_vap->base_vap, MAC_VAP_STATE_STA_LISTEN);
1185 hmac_set_rx_filter_value(hmac_vap->base_vap);
1186
1187 oam_info_log4(mac_vap->vap_id, OAM_SF_P2P,
1188 "{hmac_p2p_remain_on_channel::get in listen state!last_state %d, channel %d, duration %d, curr_state %d}\r\n",
1189 mac_dev->p2p_info.last_vap_state, remain_on_channel->uc_listen_channel, remain_on_channel->listen_duration,
1190 hmac_vap->base_vap->vap_state);
1191
1192 /* 准备监听参数 */
1193 hmac_p2p_prepare_listen_req_param(&scan_params, (hi_s8 *)remain_on_channel);
1194
1195 /* 调用扫描入口,准备进行监听动作,不管监听动作执行成功或失败,都返回监听成功 */
1196 return hmac_fsm_handle_scan_req(hmac_vap->base_vap, &scan_params);
1197 }
1198
1199 /* ****************************************************************************
1200 功能描述 : P2P_DEVICE 监听超时
1201 输入参数 : hmac_vap_stru *hmac_vap_sta
1202 hi_void *p_param
1203 修改历史 :
1204 1.日 期 : 2014年11月24日
1205 作 者 : HiSilicon
1206 修改内容 : 新生成函数
1207 **************************************************************************** */
hmac_p2p_listen_timeout(mac_vap_stru * mac_vap)1208 hi_u32 hmac_p2p_listen_timeout(mac_vap_stru *mac_vap)
1209 {
1210 mac_device_stru *mac_dev = HI_NULL;
1211 hmac_vap_stru *hmac_vap = HI_NULL;
1212
1213 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1214 if (hmac_vap == HI_NULL) {
1215 oam_error_log1(0, OAM_SF_P2P, "{hmac_p2p_listen_timeout::hmac_vap_get_vap_stru fail.vap_id[%u]!}",
1216 mac_vap->vap_id);
1217 return HI_ERR_CODE_PTR_NULL;
1218 }
1219 mac_dev = mac_res_get_dev();
1220 oam_info_log2(hmac_vap->base_vap->vap_id, OAM_SF_P2P,
1221 "{hmac_p2p_listen_timeout::current mac_vap channel is [%d] state[%d]}", mac_vap->channel.chan_number,
1222 hmac_vap->base_vap->vap_state);
1223
1224 oam_info_log2(hmac_vap->base_vap->vap_id, OAM_SF_P2P,
1225 "{hmac_p2p_listen_timeout::next mac_vap channel is [%d] state[%d]}", mac_vap->channel.chan_number,
1226 mac_dev->p2p_info.last_vap_state);
1227
1228 /* 由于P2P0 和P2P_CL 共用vap 结构体,监听超时,返回监听前保存的状态 */
1229 mac_vap_state_change(mac_vap, mac_dev->p2p_info.last_vap_state);
1230 hmac_device_stru *hmac_dev = hmac_get_device_stru();
1231 hmac_scan_record_stru *pst_scan_record = &(hmac_dev->scan_mgmt.scan_record_mgmt);
1232
1233 /* 3.1 抛事件到WAL ,上报监听结束 */
1234 if (pst_scan_record->ull_cookie == mac_dev->p2p_info.ull_last_roc_id) {
1235 if (hmac_p2p_send_listen_expired_to_host(hmac_vap) != HI_SUCCESS) {
1236 oam_warning_log0(mac_vap->vap_id, OAM_SF_P2P, "hmac_p2p_send_listen_expired_to_host return NON SUCCESS");
1237 }
1238 }
1239
1240 /* 3.2 抛事件到DMAC ,返回监听信道 */
1241 if (hmac_p2p_send_listen_expired_to_device(hmac_vap) != HI_SUCCESS) {
1242 oam_warning_log0(mac_vap->vap_id, OAM_SF_P2P, "hmac_p2p_send_listen_expired_to_device return NON SUCCESS. ");
1243 }
1244
1245 return HI_SUCCESS;
1246 }
1247
1248 /* ****************************************************************************
1249 功能描述 : P2P_DEVICE 在监听状态接收到管理帧处理,HS2.0查询过程的ACTION上报(原函数名为hmac_p2p_listen_rx_mgmt)
1250 输入参数 : [1]hmac_vap_sta,
1251 [2]crx_event
1252 返 回 值 : hi_u32
1253 **************************************************************************** */
hmac_p2p_sta_not_up_rx_mgmt(const hmac_vap_stru * hmac_vap,const dmac_wlan_crx_event_stru * crx_event)1254 hi_u32 hmac_p2p_sta_not_up_rx_mgmt(const hmac_vap_stru *hmac_vap, const dmac_wlan_crx_event_stru *crx_event)
1255 {
1256 mac_vap_stru *mac_vap = HI_NULL;
1257 hmac_rx_ctl_stru *rx_info = HI_NULL;
1258 hi_u8 *puc_mac_hdr = HI_NULL;
1259 hi_u8 mgmt_frm_type;
1260
1261 mac_vap = hmac_vap->base_vap;
1262 rx_info = (hmac_rx_ctl_stru *)oal_netbuf_cb((oal_netbuf_stru *)crx_event->netbuf);
1263 puc_mac_hdr = (hi_u8 *)(rx_info->pul_mac_hdr_start_addr);
1264 if (puc_mac_hdr == HI_NULL) {
1265 oam_error_log3(rx_info->mac_vap_id, OAM_SF_RX,
1266 "{hmac_p2p_sta_not_up_rx_mgmt::puc_mac_hdr null, vap_id %d,us_frame_len %d, uc_mac_header_len %d}",
1267 rx_info->vap_id, rx_info->us_frame_len, rx_info->mac_header_len);
1268 return HI_ERR_CODE_PTR_NULL;
1269 }
1270
1271 /* STA在NOT UP状态下接收到各种管理帧处理 */
1272 mgmt_frm_type = mac_get_frame_sub_type(puc_mac_hdr);
1273 switch (mgmt_frm_type) {
1274 /* 判断接收到的管理帧类型 */
1275 case WLAN_FC0_SUBTYPE_PROBE_REQ:
1276 /* 判断为P2P设备,则上报probe req帧到wpa_supplicant */
1277 if (!is_legacy_vap(mac_vap)) {
1278 hmac_rx_mgmt_send_to_host(hmac_vap, (oal_netbuf_stru *)crx_event->netbuf);
1279 }
1280 break;
1281 case WLAN_FC0_SUBTYPE_ACTION:
1282 /* 如果是Action 帧,则直接上报wpa_supplicant */
1283 hmac_rx_mgmt_send_to_host(hmac_vap, (oal_netbuf_stru *)crx_event->netbuf);
1284 break;
1285 default:
1286 break;
1287 }
1288 return HI_SUCCESS;
1289 }
1290
1291 /* ****************************************************************************
1292 功能描述 : 保持在指定信道
1293 输入参数 : [1]mac_vap
1294 [2]us_len
1295 [3]puc_param
1296 返 回 值 : hi_u32
1297 **************************************************************************** */
hmac_p2p_config_remain_on_channel(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)1298 hi_u32 hmac_p2p_config_remain_on_channel(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
1299 {
1300 hi_unref_param(us_len);
1301
1302 /* 1.1 判断入参 */
1303 if (mac_vap == HI_NULL || puc_param == HI_NULL) {
1304 oam_error_log2(0, OAM_SF_P2P, "{hmac_p2p_config_remain_on_channel::mac_vap=%p,puc_param=%p}",
1305 (uintptr_t)mac_vap, (uintptr_t)puc_param);
1306 return HI_ERR_CODE_PTR_NULL;
1307 }
1308
1309 #ifdef _PRE_WLAN_FEATURE_WAPI
1310 if (HI_TRUE == hmac_user_is_wapi_connected()) {
1311 oam_warning_log0(0, OAM_SF_P2P, "{stop p2p remaining under wapi!}");
1312 return HI_ERR_CODE_CONFIG_UNSUPPORT;
1313 }
1314 #endif
1315
1316 /* 1.2 检查是否能进入监听状态 */
1317 mac_remain_on_channel_param_stru *remain_on_channel = (mac_remain_on_channel_param_stru *)puc_param;
1318 mac_device_stru *mac_dev = mac_res_get_dev();
1319 hi_u32 ret = hmac_p2p_check_can_enter_state(mac_vap, HMAC_FSM_INPUT_LISTEN_REQ);
1320 if (ret != HI_SUCCESS) {
1321 /* 不能进入监听状态,返回设备忙 */
1322 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_config_remain_on_channel::device busy ret=%d}", ret);
1323 return HI_ERR_CODE_CONFIG_BUSY;
1324 }
1325
1326 /* 1.3 获取home 信道和信道类型。如果返回主信道为0,表示没有设备处于up 状态,监听后不需要返回主信道 */
1327 hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1328 if (hmac_vap == HI_NULL) {
1329 oam_error_log1(mac_vap->vap_id, OAM_SF_P2P,
1330 "{hmac_p2p_config_remain_on_channel::hmac_vap_get_vap_stru null.vap_id = %d}", mac_vap->vap_id);
1331 return HI_FAIL;
1332 }
1333
1334 /* 保存内核下发的监听信道信息,用于监听超时或取消监听时返回 */
1335 mac_dev->p2p_info.st_listen_channel = remain_on_channel->st_listen_channel;
1336
1337 /* 由于p2p0和 p2p cl 共用一个VAP 结构,故在进入监听时,需要保存之前的状态,便于监听结束时返回 */
1338 if (mac_vap->vap_state != MAC_VAP_STATE_STA_LISTEN) {
1339 mac_dev->p2p_info.last_vap_state = mac_vap->vap_state;
1340 }
1341 remain_on_channel->last_vap_state = mac_dev->p2p_info.last_vap_state;
1342
1343 oam_info_log3(mac_vap->vap_id, OAM_SF_P2P,
1344 "{hmac_p2p_config_remain_on_channel::listen_channel=%d, current_channel=%d, last_state=%d}\r\n",
1345 remain_on_channel->uc_listen_channel, mac_vap->channel.chan_number, mac_dev->p2p_info.last_vap_state);
1346
1347 /* 3.1 修改VAP 状态为监听 */
1348 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1349 if (hmac_vap == HI_NULL) {
1350 oam_error_log0(mac_vap->vap_id, OAM_SF_P2P, "{hmac_p2p_config_remain_on_channel fail!hmac_vap is null}\r\n");
1351 return HI_FAIL;
1352 }
1353
1354 /* 状态机调用: hmac_p2p_config_remain_on_channel */
1355 switch (mac_vap->vap_state) {
1356 case MAC_VAP_STATE_STA_FAKE_UP:
1357 case MAC_VAP_STATE_STA_SCAN_COMP:
1358 case MAC_VAP_STATE_STA_LISTEN:
1359 case MAC_VAP_STATE_UP:
1360 return hmac_p2p_remain_on_channel(hmac_vap, remain_on_channel);
1361 default:
1362 return HI_SUCCESS;
1363 }
1364 }
1365
1366 /* ****************************************************************************
1367 功能描述 : 停止保持在指定信道
1368 输入参数 : [1]mac_vap
1369 [2]us_len
1370 [3]puc_param
1371 返 回 值 : hi_u32
1372 **************************************************************************** */
hmac_p2p_cancel_remain_on_channel(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)1373 hi_u32 hmac_p2p_cancel_remain_on_channel(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
1374 {
1375 hmac_vap_stru *hmac_vap = HI_NULL;
1376
1377 hi_unref_param(us_len);
1378 hi_unref_param(puc_param);
1379
1380 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1381 if (hmac_vap == HI_NULL) {
1382 oam_warning_log1(mac_vap->vap_id, OAM_SF_P2P,
1383 "hmac_p2p_cancel_remain_on_channel::hmac_vap_get_vap_stru fail.vap_id = %u", mac_vap->vap_id);
1384 return HI_ERR_CODE_PTR_NULL;
1385 }
1386
1387 if (mac_vap->vap_state == MAC_VAP_STATE_STA_LISTEN) {
1388 hmac_p2p_listen_timeout(mac_vap);
1389 } else {
1390 if (hmac_p2p_send_listen_expired_to_host(hmac_vap) != HI_SUCCESS) {
1391 oam_warning_log0(mac_vap->vap_id, OAM_SF_P2P, "hmac_p2p_send_listen_expired_to_host return NON SUCCESS. ");
1392 }
1393 }
1394 return HI_SUCCESS;
1395 }
1396
1397 #ifdef __cplusplus
1398 #if __cplusplus
1399 }
1400 #endif
1401 #endif
1402