• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 /* ****************************************************************************
20   1 头文件包含
21 **************************************************************************** */
22 #include "oam_ext_if.h"
23 #include "mac_ie.h"
24 #include "mac_regdomain.h"
25 #include "mac_device.h"
26 #include "mac_resource.h"
27 #include "hmac_fsm.h"
28 #include "hmac_sme_sta.h"
29 #include "hmac_device.h"
30 #include "hmac_scan.h"
31 #include "hmac_mgmt_sta.h"
32 #include "hmac_mgmt_ap.h"
33 #include "frw_timer.h"
34 #include "hmac_chan_mgmt.h"
35 #include "hmac_event.h"
36 #include "hcc_hmac_if.h"
37 #include "wal_customize.h"
38 
39 #ifdef __cplusplus
40 #if __cplusplus
41 extern "C" {
42 #endif
43 #endif
44 
45 /* ****************************************************************************
46   函数实现
47 **************************************************************************** */
48 /* ****************************************************************************
49  功能描述  : 申请内存,存储扫描到的bss信息
50  输入参数  : hi_u32 ul_mgmt_len, 上报的管理帧的长度
51  修改历史      :
52   1.日    期   : 2015年2月2日
53     作    者   : HiSilicon
54     修改内容   : 新生成函数
55 **************************************************************************** */
hmac_scan_alloc_scanned_bss(hi_u32 mgmt_len)56 hmac_scanned_bss_info *hmac_scan_alloc_scanned_bss(hi_u32 mgmt_len)
57 {
58     hmac_scanned_bss_info *scanned_bss = HI_NULL;
59 
60     /* 申请内存,存储扫描到的bss信息 */
61     scanned_bss = oal_memalloc(sizeof(hmac_scanned_bss_info) + mgmt_len -
62                                    sizeof(scanned_bss->bss_dscr_info.auc_mgmt_buff));
63     if (oal_unlikely(scanned_bss == HI_NULL)) {
64         oam_warning_log0(0, OAM_SF_SCAN,
65             "{hmac_scan_alloc_scanned_bss::alloc memory failed for storing scanned result.}");
66         return HI_NULL;
67     }
68 
69     /* 安全编程规则6.6例外(3)从堆中分配内存后,赋予初值 */
70     memset_s(scanned_bss, sizeof(hmac_scanned_bss_info) + mgmt_len - sizeof(scanned_bss->bss_dscr_info.auc_mgmt_buff),
71         0, sizeof(hmac_scanned_bss_info) + mgmt_len - sizeof(scanned_bss->bss_dscr_info.auc_mgmt_buff));
72 
73     /* 初始化链表头节点指针 */
74     hi_list_init(&(scanned_bss->dlist_head));
75 
76     return scanned_bss;
77 }
78 
79 /* ****************************************************************************
80  功能描述  : 将扫描到的bss添加到链表
81  输入参数  : hmac_scanned_bss_info *pst_scanned_bss,        待添加到链表上的扫描到的bss节点
82              hmac_device_stru *pst_hmac_device,             hmac device结构体
83  修改历史      :
84   1.日    期   : 2015年2月2日
85     作    者   : HiSilicon
86     修改内容   : 新生成函数
87 **************************************************************************** */
hmac_scan_add_bss_to_list(hmac_scanned_bss_info * scanned_bss,hmac_device_stru * hmac_dev)88 hi_void hmac_scan_add_bss_to_list(hmac_scanned_bss_info *scanned_bss, hmac_device_stru *hmac_dev)
89 {
90     hmac_bss_mgmt_stru *bss_mgmt = HI_NULL; /* 管理扫描结果的结构体 */
91 
92     bss_mgmt = &(hmac_dev->scan_mgmt.scan_record_mgmt.bss_mgmt);
93     scanned_bss->bss_dscr_info.new_scan_bss = HI_TRUE;
94 
95     /* 对链表写操作前加锁 */
96     oal_spin_lock_bh(&(bss_mgmt->st_lock));
97 
98     /* 添加扫描结果到链表中,并更新扫描到的bss计数 */
99     hi_list_tail_insert_optimize(&(scanned_bss->dlist_head), &(bss_mgmt->bss_list_head));
100 
101     bss_mgmt->bss_num++;
102     /* 解锁 */
103     oal_spin_unlock_bh(&(bss_mgmt->st_lock));
104 }
105 
106 /* ****************************************************************************
107  功能描述  : 删除扫描结果链表中的bss节点
108  输入参数  : hmac_scanned_bss_info *pst_scanned_bss,        待删除的扫描到的bss节点
109              hmac_device_stru *pst_hmac_device,             hmac device结构体
110  修改历史      :
111   1.日    期   : 2015年2月2日
112     作    者   : HiSilicon
113     修改内容   : 新生成函数
114 **************************************************************************** */
hmac_scan_del_bss_from_list_nolock(hmac_scanned_bss_info * scanned_bss,hmac_device_stru * hmac_dev)115 static hi_void hmac_scan_del_bss_from_list_nolock(hmac_scanned_bss_info *scanned_bss, hmac_device_stru *hmac_dev)
116 {
117     hmac_bss_mgmt_stru *bss_mgmt = HI_NULL; /* 管理扫描结果的结构体 */
118 
119     bss_mgmt = &(hmac_dev->scan_mgmt.scan_record_mgmt.bss_mgmt);
120 
121     /* 从链表中删除节点,并更新扫描到的bss计数 */
122     hi_list_delete_optimize(&(scanned_bss->dlist_head));
123 
124     bss_mgmt->bss_num--;
125 }
126 
127 /* ****************************************************************************
128  功能描述  : 清除上次扫描请求相关的扫描记录信息: 包括扫描到的bss信息,并释放内存空间、以及其他信息清零
129  输入参数  : hmac_scan_record_stru  *pst_scan_record
130  修改历史      :
131   1.日    期   : 2015年2月2日
132     作    者   : HiSilicon
133     修改内容   : 新生成函数
134 **************************************************************************** */
hmac_scan_clean_scan_record(hmac_scan_record_stru * scan_record)135 hi_void hmac_scan_clean_scan_record(hmac_scan_record_stru *scan_record)
136 {
137     hi_list *entry = HI_NULL;
138     hmac_scanned_bss_info *scanned_bss = HI_NULL;
139     hmac_bss_mgmt_stru *bss_mgmt = HI_NULL;
140 
141     /* 参数合法性检查 */
142     if (scan_record == HI_NULL) {
143         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_clean_scan_record::pst_scan_record is null.}");
144         return;
145     }
146 
147     /* 1.一定要先清除扫描到的bss信息,再进行清零处理 */
148     bss_mgmt = &(scan_record->bss_mgmt);
149 
150     /* 对链表写操作前加锁 */
151     oal_spin_lock_bh(&(bss_mgmt->st_lock));
152 
153     /* 遍历链表,删除扫描到的bss信息 */
154     while (HI_FALSE == hi_is_list_empty_optimize(&(bss_mgmt->bss_list_head))) {
155         entry = hi_list_delete_head_optimize(&(bss_mgmt->bss_list_head));
156         scanned_bss = hi_list_entry(entry, hmac_scanned_bss_info, dlist_head);
157 
158         bss_mgmt->bss_num--;
159 
160         /* 释放扫描队列里的内存 */
161         oal_free(scanned_bss);
162     }
163 
164     /* 对链表写操作前加锁 */
165     oal_spin_unlock_bh(&(bss_mgmt->st_lock));
166 
167     /* 2.其它信息清零 */
168     if (memset_s(scan_record, sizeof(hmac_scan_record_stru), 0, sizeof(hmac_scan_record_stru)) != EOK) {
169         return;
170     }
171     scan_record->scan_rsp_status = MAC_SCAN_STATUS_BUTT; /* 初始化扫描完成时状态码为无效值 */
172 
173     /* 3.重新初始化bss管理结果链表和锁 */
174     bss_mgmt = &(scan_record->bss_mgmt);
175     hi_list_init(&(bss_mgmt->bss_list_head));
176 
177     oam_info_log0(0, OAM_SF_SCAN, "{hmac_scan_clean_scan_record::cleaned scan record success.}");
178 
179     return;
180 }
181 
182 /* ****************************************************************************
183  功能描述  : 判断输入bssid参数是否是关联的AP的bssid,用于不老化已经关联的AP
184  输入参数  : hi_u8 auc_bssid[WLAN_MAC_ADDR_LEN]
185  返 回 值  : HI_TRUE:是,HI_FALSE:否
186  修改历史      :
187   1.日    期   : 2016年1月5日
188     作    者   : HiSilicon
189     修改内容   : 新生成函数
190 **************************************************************************** */
hmac_is_connected_ap_bssid(const hi_u8 auc_bssid[WLAN_MAC_ADDR_LEN])191 static hi_s32 hmac_is_connected_ap_bssid(const hi_u8 auc_bssid[WLAN_MAC_ADDR_LEN])
192 {
193     hi_u8 vap_idx;
194     mac_vap_stru *mac_vap = HI_NULL;
195     mac_device_stru *mac_dev = HI_NULL;
196 
197     mac_dev = mac_res_get_dev();
198     for (vap_idx = 0; vap_idx < mac_dev->vap_num; vap_idx++) {
199         mac_vap = mac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
200         if (oal_unlikely(mac_vap == HI_NULL)) {
201             oam_warning_log1(0, OAM_SF_P2P, "{hmac_is_connected_ap_bssid::mac_vap_get_vap_stru fail! vap id is %d}",
202                 mac_dev->auc_vap_id[vap_idx]);
203             continue;
204         }
205         if ((is_legacy_vap(mac_vap) && (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA)) &&
206             ((mac_vap->vap_state == MAC_VAP_STATE_UP) || (mac_vap->vap_state == MAC_VAP_STATE_PAUSE))) {
207             if (0 == memcmp(auc_bssid, mac_vap->auc_bssid, WLAN_MAC_ADDR_LEN)) {
208                 /* 不老化当前关联的AP */
209                 oam_info_log3(mac_vap->vap_id, OAM_SF_SCAN,
210                     "{hmac_is_connected_ap_bssid::connected AP bssid:XX:XX:XX:%02X:%02X:%02X}", auc_bssid[3],
211                     auc_bssid[4], auc_bssid[5]); /* 3 4 5 元素索引 */
212 
213                 return HI_TRUE;
214             }
215         }
216     }
217 
218     return HI_FALSE;
219 }
220 
221 /* ****************************************************************************
222  功能描述  : 本次扫描请求发起时,清除上次扫描结果中到期的bss信息
223  输入参数  : hmac_scan_record_stru  *pst_scan_record
224  修改历史      :
225   1.日    期   : 2015年8月10日
226     作    者   : HiSilicon
227     修改内容   : 新生成函数
228 **************************************************************************** */
hmac_scan_clean_expire_scanned_bss(hmac_scan_record_stru * scan_record,hi_u8 clean_flag)229 static hi_void hmac_scan_clean_expire_scanned_bss(hmac_scan_record_stru *scan_record, hi_u8 clean_flag)
230 {
231     hi_list *entry = HI_NULL;
232     hi_list *entry_tmp = HI_NULL;
233     hmac_bss_mgmt_stru *bss_mgmt = HI_NULL;
234     hmac_scanned_bss_info *scanned_bss = HI_NULL;
235     mac_bss_dscr_stru *bss_dscr = HI_NULL;
236     hi_u32 curr_time_stamp = 0;
237 
238     /* 参数合法性检查 */
239     if (scan_record == HI_NULL) {
240         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_clean_expire_scanned_bss::scan record is null.}");
241         return;
242     }
243 
244     /* 管理扫描的bss结果的结构体 */
245     bss_mgmt = &(scan_record->bss_mgmt);
246 
247     if (clean_flag != HI_TRUE) {
248         curr_time_stamp = (hi_u32)hi_get_milli_seconds();
249     }
250     /* 对链表写操作前加锁 */
251     oal_spin_lock_bh(&(bss_mgmt->st_lock));
252 
253     /* 遍历链表,删除上一次扫描结果中到期的bss信息 */
254     hi_list_for_each_safe(entry, entry_tmp, &(bss_mgmt->bss_list_head)) {
255         scanned_bss = hi_list_entry(entry, hmac_scanned_bss_info, dlist_head);
256         bss_dscr = &(scanned_bss->bss_dscr_info);
257         if (clean_flag != HI_TRUE) {
258             if (curr_time_stamp - bss_dscr->timestamp < HMAC_SCAN_MAX_SCANNED_BSS_EXPIRE) {
259                 continue;
260             }
261         }
262         /* 不老化当前正在关联的AP */
263         if (hmac_is_connected_ap_bssid(bss_dscr->auc_bssid)) {
264             continue;
265         }
266 
267         /* 从链表中删除节点,并更新扫描到的bss计数 */
268         hi_list_delete_optimize(&(scanned_bss->dlist_head));
269         bss_mgmt->bss_num--;
270         /* 释放对应内存 */
271         oal_free(scanned_bss);
272     }
273     /* 对链表写操作前加锁 */
274     oal_spin_unlock_bh(&(bss_mgmt->st_lock));
275 
276     return;
277 }
278 
279 #ifdef _PRE_DEBUG_MODE
280 /* ****************************************************************************
281  功能描述  : 根据bss index查找对应的bss dscr结构信息
282  输入参数  : hi_u32 ul_bss_index,        bss    index
283  修改历史      :
284   1.日    期   : 2015年2月2日
285     作    者   : HiSilicon
286     修改内容   : 新生成函数
287 **************************************************************************** */
hmac_scan_find_scanned_bss_dscr_by_index(hi_u32 bss_index)288 mac_bss_dscr_stru *hmac_scan_find_scanned_bss_dscr_by_index(hi_u32 bss_index)
289 {
290     hi_list *entry = HI_NULL;
291     hmac_scanned_bss_info *scanned_bss = HI_NULL;
292     hmac_device_stru *hmac_dev = HI_NULL;
293     hmac_bss_mgmt_stru *bss_mgmt = HI_NULL;
294     hi_u8 loop;
295 
296     /* 获取hmac device 结构 */
297     hmac_dev = hmac_get_device_stru();
298     bss_mgmt = &(hmac_dev->scan_mgmt.scan_record_mgmt.bss_mgmt);
299 
300     /* 对链表删操作前加锁 */
301     oal_spin_lock_bh(&(bss_mgmt->st_lock));
302 
303     /* 如果索引大于总共扫描的bss个数,返回异常 */
304     if (bss_index >= bss_mgmt->bss_num) {
305         oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_find_scanned_bss_by_index::no such bss in bss list!}");
306 
307         /* 解锁 */
308         oal_spin_unlock_bh(&(bss_mgmt->st_lock));
309         return HI_NULL;
310     }
311 
312     loop = 0;
313     /* 遍历链表,返回对应index的bss dscr信息 */
314     hi_list_for_each(entry, &(bss_mgmt->bss_list_head)) {
315         scanned_bss = hi_list_entry(entry, hmac_scanned_bss_info, dlist_head);
316 
317         /* 相同的bss index返回 */
318         if (bss_index == loop) {
319             /* 解锁 */
320             oal_spin_unlock_bh(&(bss_mgmt->st_lock));
321             return &(scanned_bss->bss_dscr_info);
322         }
323 
324         loop++;
325     }
326     /* 解锁 */
327     oal_spin_unlock_bh(&(bss_mgmt->st_lock));
328 
329     return HI_NULL;
330 }
331 #endif
332 
333 /* ****************************************************************************
334  功能描述  : 查找相同的bssid的bss是否出现过
335  输入参数  : hi_u8 *puc_bssid,          bssid信息
336  修改历史      :
337   1.日    期   : 2015年2月2日
338     作    者   : HiSilicon
339     修改内容   : 新生成函数
340 **************************************************************************** */
hmac_scan_find_scanned_bss_by_bssid(const hmac_bss_mgmt_stru * bss_mgmt,const hi_u8 * puc_bssid)341 hmac_scanned_bss_info *hmac_scan_find_scanned_bss_by_bssid(const hmac_bss_mgmt_stru *bss_mgmt, const hi_u8 *puc_bssid)
342 {
343     hi_list *entry = HI_NULL;
344     hmac_scanned_bss_info *scanned_bss = HI_NULL;
345 
346     /* 遍历链表,查找链表中是否已经存在相同bssid的bss信息 */
347     hi_list_for_each(entry, &(bss_mgmt->bss_list_head)) {
348         scanned_bss = hi_list_entry(entry, hmac_scanned_bss_info, dlist_head);
349         /* 相同的bssid地址 */
350         if (0 == oal_compare_mac_addr(scanned_bss->bss_dscr_info.auc_bssid, puc_bssid, WLAN_MAC_ADDR_LEN)) {
351             return scanned_bss;
352         }
353     }
354 
355     return HI_NULL;
356 }
357 
358 #if defined(_PRE_WLAN_FEATURE_WPA2)
359 /* ****************************************************************************
360  功能描述  : STA 更新从 scan, probe response 帧接收到的AP RSN安全信息
361  输入参数  : [1]bss_dscr
362              [2]puc_ie
363  返 回 值  : static hi_u8
364 **************************************************************************** */
hmac_scan_update_bss_list_rsn(mac_bss_dscr_stru * bss_dscr,const hi_u8 * puc_ie)365 static hi_u8 hmac_scan_update_bss_list_rsn(mac_bss_dscr_stru *bss_dscr, const hi_u8 *puc_ie)
366 {
367     hi_u8 auc_oui[MAC_OUI_LEN] = {MAC_WLAN_OUI_RSN0, MAC_WLAN_OUI_RSN1, MAC_WLAN_OUI_RSN2};
368     hi_u16 suite_temp, us_temp;
369 
370     /* *********************************************************************** */
371     /*                  RSN Element Format                                   */
372     /* --------------------------------------------------------------------- */
373     /* |Element ID | Length | Version | Group Cipher Suite | Pairwise Cipher */
374     /* --------------------------------------------------------------------- */
375     /* |     1     |    1   |    2    |         4          |       2         */
376     /* --------------------------------------------------------------------- */
377     /* --------------------------------------------------------------------- */
378     /* Suite Count| Pairwise Cipher Suite List | AKM Suite Count | AKM Suite List */
379     /* --------------------------------------------------------------------- */
380     /*            |         4*m                |     2           |   4*n     */
381     /* --------------------------------------------------------------------- */
382     /* --------------------------------------------------------------------- */
383     /* |RSN Capabilities|PMKID Count|PMKID List|Group Management Cipher Suite */
384     /* --------------------------------------------------------------------- */
385     /* |        2       |    2      |   16 *s  |               4           | */
386     /* --------------------------------------------------------------------- */
387     /*                                                                       */
388     /* *********************************************************************** */
389     /* 规则6.6:禁止使用内存操作类危险函数 例外(1)对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
390     memset_s(bss_dscr->bss_sec_info.auc_rsn_pairwise_policy, MAC_PAIRWISE_CIPHER_SUITES_NUM, 0xFF,
391         MAC_PAIRWISE_CIPHER_SUITES_NUM);
392     memset_s(bss_dscr->bss_sec_info.auc_rsn_auth_policy, MAC_AUTHENTICATION_SUITE_NUM, 0xFF,
393         MAC_AUTHENTICATION_SUITE_NUM);
394 
395     /* 忽略 RSN IE 和 IE 长度 */
396     hi_u8 index = MAC_IE_HDR_LEN;
397 
398     /* 获取RSN 版本号 */
399     hi_u16 us_ver = hi_makeu16(puc_ie[index], puc_ie[index + 1]);
400     if (us_ver != MAC_RSN_IE_VERSION) {
401         oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_rsn::invalid us_ver[%d].}", us_ver);
402         return HI_FALSE;
403     }
404 
405     /* 忽略 RSN 版本号长度 */
406     index += 2; /* 2 忽略 RSN 版本号长度 */
407 
408     /* 获取组播密钥套件 */
409     if (memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN) != 0) {
410         oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_rsn::invalid RSN group OUI.}");
411         return HI_FALSE;
412     }
413     bss_dscr->bss_sec_info.rsn_grp_policy = puc_ie[index + MAC_OUI_LEN];
414 
415     /* 忽略 组播密钥套件 长度 */
416     index += 4; /* 4 忽略组播密钥套件长度 */
417 
418     /* 获取成对密钥套件 */
419     hi_u16 us_suite_count = 0;
420     hi_u16 us_pcip_num = hi_makeu16(puc_ie[index], puc_ie[index + 1]);
421     index += 2; /* 索引自增2 */
422     for (suite_temp = 0; suite_temp < us_pcip_num; suite_temp++, index += 4) { /* 4 对于不识别的成对密钥套件,忽略保存 */
423         if (memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN) != 0) {
424             oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_rsn:invalid RSN paerwise OUI,ignore this ie}");
425             /* 对于不识别的成对密钥套件,忽略保存 */
426             continue;
427         }
428 
429         if (us_suite_count >= MAC_PAIRWISE_CIPHER_SUITES_NUM) {
430             oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa:ignore this ie,pcip_num:%d}", us_pcip_num);
431         } else {
432             /* 成对密钥套件个数驱动最大为2,超过则不再继续保存 */
433             bss_dscr->bss_sec_info.auc_rsn_pairwise_policy[us_suite_count++] = puc_ie[index + MAC_OUI_LEN];
434         }
435     }
436 
437     us_suite_count = 0;
438     /* 获取认证套件计数 */
439     hi_u16 us_auth_num = hi_makeu16(puc_ie[index], puc_ie[index + 1]);
440     index += 2; /* 索引自增2 */
441     /* 获取认证类型 */
442     for (us_temp = 0; us_temp < us_auth_num; us_temp++, index += 4) { /* 4 对于不识别的AKM套件,忽略保存 */
443         if (0 != memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN)) {
444             oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_rsn::invalid RSN auth OUI,ignore this ie.}");
445             /* 对于不识别的AKM套件,忽略保存 */
446             continue;
447         } else if (us_suite_count < WLAN_AUTHENTICATION_SUITES) {
448             /* AKM套件个数驱动最大为2,超过则不再继续保存 */
449             bss_dscr->bss_sec_info.auc_rsn_auth_policy[us_suite_count++] = puc_ie[index + MAC_OUI_LEN];
450         } else {
451             oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa:ignore this ie,auth_num:%d}", us_auth_num);
452         }
453     }
454 
455     /* 获取 RSN 能力 */
456     bss_dscr->bss_sec_info.auc_rsn_cap[0] = *(puc_ie + index++);
457     bss_dscr->bss_sec_info.auc_rsn_cap[1] = *(puc_ie + index++);
458 
459     /* 设置 RSNA */
460     bss_dscr->bss_sec_info.bss_80211i_mode |= DMAC_RSNA_802_11I;
461     return HI_TRUE;
462 }
463 #endif
464 
465 #if defined(_PRE_WLAN_FEATURE_WPA)
466 /* ****************************************************************************
467  功能描述  : STA 更新从 scan, probe response 帧接收到的AP WPA 安全信息
468  输入参数  : [1]bss_dscr
469              [2]puc_ie
470  返回值  : static hi_u8
471 **************************************************************************** */
hmac_scan_update_bss_list_wpa(mac_bss_dscr_stru * bss_dscr,const hi_u8 * puc_ie)472 static hi_u8 hmac_scan_update_bss_list_wpa(mac_bss_dscr_stru *bss_dscr, const hi_u8 *puc_ie)
473 {
474     hi_u16 us_suite_count = 0;
475     hi_u8 auc_oui[MAC_OUI_LEN] = {(hi_u8)MAC_WLAN_OUI_MICRO0, (hi_u8)MAC_WLAN_OUI_MICRO1, (hi_u8)MAC_WLAN_OUI_MICRO2};
476     mac_bss_80211i_info_stru *bss_80211i_info = &(bss_dscr->bss_sec_info);
477     hi_u16 suite_temp, us_temp;
478 
479     /* *********************************************************************** */
480     /*                  WPA Element Format                                   */
481     /* --------------------------------------------------------------------- */
482     /* |Element ID | Length |    WPA OUI    |  Version |  Group Cipher Suite */
483     /* --------------------------------------------------------------------- */
484     /* |     1     |   1    |        4      |     2    |         4           */
485     /* --------------------------------------------------------------------- */
486     /* --------------------------------------------------------------------- */
487     /* Pairwise Cipher |  Pairwise Cipher   |                 |              */
488     /* Suite Count     |    Suite List      | AKM Suite Count |AKM Suite List */
489     /* --------------------------------------------------------------------- */
490     /*        2        |          4*m       |         2       |     4*n      */
491     /* --------------------------------------------------------------------- */
492     /*                                                                       */
493     /* *********************************************************************** */
494     /* 忽略 WPA IE(1 字节) ,IE 长度(1 字节) ,WPA OUI(4 字节)  */
495     hi_u8 index = 2 + 4; /* 2 4 忽略 WPA IE(1 字节) ,IE 长度(1 字节) ,WPA OUI(4 字节)  */
496 
497     /* 对比WPA 版本信息 */
498     if (hi_makeu16(puc_ie[index], puc_ie[index + 1]) != MAC_WPA_IE_VERSION) {
499         oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa::invalid WPA version.}");
500         return HI_FALSE;
501     }
502 
503     /* 忽略 版本号 长度 */
504     index += 2; /* 2 忽略 版本号 长度 */
505 
506     /* 获取组播密钥套件 */
507     if (0 != memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN)) {
508         oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa::invalid WPA group OUI.}");
509         return HI_FALSE;
510     }
511     bss_80211i_info->wpa_grp_policy = puc_ie[index + MAC_OUI_LEN];
512 
513     /* 忽略组播密钥套件长度 */
514     index += 4; /* 4 忽略组播密钥套件长度 */
515 
516     /* 获取成对密钥套件 */
517     hi_u16 us_pcip_num = hi_makeu16(puc_ie[index], puc_ie[index + 1]);
518     index += 2; /* 索引自增2 */
519     for (suite_temp = 0; suite_temp < us_pcip_num; suite_temp++) {
520         if (0 != memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN)) {
521             oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa::invalid WPA pairwise OUI,ignore ie.}");
522             /* 对于不识别的成对密钥套件,忽略保存 */
523             index += 4; /* 4 对于不识别的成对密钥套件,忽略保存 */
524             continue;
525         }
526         if (us_suite_count < MAC_PAIRWISE_CIPHER_SUITES_NUM) {
527             /* 成对密钥套件个数驱动最大为2,超过则不再继续保存 */
528             bss_80211i_info->auc_wpa_pairwise_policy[us_suite_count++] = puc_ie[index + MAC_OUI_LEN];
529         } else {
530             oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa::ignore ie,pcip_num:%d.}", us_pcip_num);
531         }
532 
533         index += 4; /* 索引自增4 */
534     }
535 
536     /* 获取认证套件计数 */
537     hi_u16 us_auth_num = hi_makeu16(puc_ie[index], puc_ie[index + 1]);
538     index += 2; /* 索引自增2 */
539     /* 获取认证类型 */
540     us_suite_count = 0;
541     for (us_temp = 0; us_temp < us_auth_num; us_temp++) {
542         if (0 != memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN)) {
543             oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa::invalid WPA auth OUI,ignore this ie.}");
544             /* 对于不识别的AKM套件,忽略保存 */
545             index += 4; /* 4 对于不识别的AKM套件,忽略保存 */
546             continue;
547         } else if (us_suite_count >= WLAN_AUTHENTICATION_SUITES) {
548             oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_wpa::ignore ie,us_auth_num:%d.}", us_auth_num);
549         } else {
550             /* AKM套件个数驱动最大为2,超过则不再继续保存 */
551             bss_80211i_info->auc_wpa_auth_policy[us_suite_count++] = puc_ie[index + MAC_OUI_LEN];
552         }
553         index += 4; /* 索引自增4 */
554     }
555 
556     /* 设置 WPA */
557     bss_dscr->bss_sec_info.bss_80211i_mode |= DMAC_WPA_802_11I;
558 
559     return HI_TRUE;
560 }
561 #endif
562 
563 #if defined(_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2)
564 /* ****************************************************************************
565  功能描述  : STA 更新从 scan, probe response 帧接收到的AP 安全信息
566  输入参数  : [1]bss_dscr
567              [2]puc_frame_body
568              [3]us_frame_len
569              [4]us_offset
570  返 回 值  : 无
571 **************************************************************************** */
hmac_scan_update_bss_list_security(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_len,hi_u16 us_offset)572 static hi_void hmac_scan_update_bss_list_security(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body,
573     hi_u16 us_frame_len, hi_u16 us_offset)
574 {
575     hi_u8 *puc_ie = HI_NULL;
576 
577     /* 安全相关信息元素 */
578     /* 清空当前 bss_info 结构中的安全信息 */
579     if (memset_s(&(bss_dscr->bss_sec_info), sizeof(mac_bss_80211i_info_stru), 0xff,
580                  sizeof(mac_bss_80211i_info_stru)) != EOK) {
581         return;
582     }
583     bss_dscr->bss_sec_info.bss_80211i_mode = 0;
584     bss_dscr->bss_sec_info.auc_rsn_cap[0] = 0;
585     bss_dscr->bss_sec_info.auc_rsn_cap[1] = 0;
586 
587 #if defined(_PRE_WLAN_FEATURE_WPA2)
588     if (us_frame_len > us_offset) {
589         puc_ie = mac_find_ie(MAC_EID_RSN, puc_frame_body + us_offset, (us_frame_len - us_offset));
590         if (puc_ie != HI_NULL) {
591             /* 更新从beacon 中收到的 RSN 安全相关信息到 pst_bss_dscr 中 */
592             hmac_scan_update_bss_list_rsn(bss_dscr, puc_ie);
593         }
594     }
595 #endif
596 
597 #if defined(_PRE_WLAN_FEATURE_WPA)
598     puc_ie = mac_find_vendor_ie(MAC_WLAN_OUI_MICROSOFT, MAC_OUITYPE_WPA, puc_frame_body + us_offset,
599         (hi_s32)(us_frame_len - us_offset));
600     if (puc_ie != HI_NULL) {
601         /* 更新从beacon 中收到的 WPA 安全相关信息到 pst_bss_dscr 中 */
602         hmac_scan_update_bss_list_wpa(bss_dscr, puc_ie);
603     }
604 #endif
605 }
606 #endif /* defined(_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2) */
607 
608 /* ****************************************************************************
609  功能描述  : 更新wmm相关信息
610  修改历史      :
611   1.日    期   : 2013年10月23日
612     作    者   : HiSilicon
613     修改内容   : 新生成函数
614 **************************************************************************** */
hmac_scan_update_bss_list_wmm(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_len)615 static hi_void hmac_scan_update_bss_list_wmm(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body, hi_u16 us_frame_len)
616 {
617     hi_u8 *puc_ie = HI_NULL;
618     hi_u8 offset;
619 
620     offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
621 
622     bss_dscr->wmm_cap = HI_FALSE;
623     bss_dscr->uapsd_cap = HI_FALSE;
624 
625     puc_ie = mac_get_wmm_ie(puc_frame_body, us_frame_len, offset);
626     if (puc_ie != HI_NULL) {
627         bss_dscr->wmm_cap = HI_TRUE;
628 
629         /* Check if Bit 7 is set indicating U-APSD capability */
630         if (puc_ie[8] & BIT7) { /* wmm ie的第8个字节是QoS info字节 */
631             bss_dscr->uapsd_cap = HI_TRUE;
632         }
633     } else {
634         if (us_frame_len > offset) {
635             puc_ie = mac_find_ie(MAC_EID_HT_CAP, puc_frame_body + offset, us_frame_len - offset);
636             if (puc_ie != HI_NULL) {
637                 bss_dscr->wmm_cap = HI_TRUE;
638             }
639         }
640     }
641 }
642 
643 #ifdef _PRE_WLAN_FEATURE_11D
644 /* ****************************************************************************
645  功能描述  : 解析country IE
646  修改历史      :
647   1.日    期   : 2013年10月22日
648     作    者   : HiSilicon
649     修改内容   : 新生成函数
650 **************************************************************************** */
hmac_scan_update_bss_list_country(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_len)651 static hi_void hmac_scan_update_bss_list_country(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body,
652     hi_u16 us_frame_len)
653 {
654     hi_u8 *puc_ie = HI_NULL;
655     hi_u8 offset;
656 
657     offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
658     /* 国家码默认标记为0 */
659     bss_dscr->ac_country[0] = 0;
660     bss_dscr->ac_country[1] = 0;
661     bss_dscr->ac_country[2] = 0; /* 第2个字节 */
662 
663     if (us_frame_len > offset) {
664         puc_ie = mac_find_ie(MAC_EID_COUNTRY, puc_frame_body + offset, us_frame_len - offset);
665         if (puc_ie != HI_NULL) {
666             bss_dscr->ac_country[0] = (hi_s8)puc_ie[MAC_IE_HDR_LEN];
667             bss_dscr->ac_country[1] = (hi_s8)puc_ie[MAC_IE_HDR_LEN + 1];
668             bss_dscr->ac_country[2] = 0; /* 第2个字节 */
669         }
670     }
671 }
672 #endif
673 
674 /* ****************************************************************************
675  功能描述  : 更新11n相关信息
676  修改历史      :
677   1.日    期   : 2013年10月23日
678     作    者   : HiSilicon
679     修改内容   : 新生成函数
680 **************************************************************************** */
hmac_scan_update_bss_list_11n(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_len,hi_u16 us_offset)681 static hi_void hmac_scan_update_bss_list_11n(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body, hi_u16 us_frame_len,
682     hi_u16 us_offset)
683 {
684     hi_u8 *puc_ie = HI_NULL;
685     mac_ht_opern_stru *ht_op = HI_NULL;
686     hi_u8 sec_chan_offset;
687     wlan_bw_cap_enum_uint8 ht_cap_bw = WLAN_BW_CAP_20M;
688     wlan_bw_cap_enum_uint8 ht_op_bw = WLAN_BW_CAP_20M;
689 
690     /* 11n */
691     if (us_frame_len > us_offset) {
692         puc_ie = mac_find_ie(MAC_EID_HT_CAP, puc_frame_body + us_offset, us_frame_len - us_offset);
693         if ((puc_ie != HI_NULL) && (puc_ie[1] >= 2)) { /* 增加ie长度异常检查 2: 与2比较 */
694             /* puc_ie[2]是HT Capabilities Info的第1个字节 */
695             bss_dscr->ht_capable = HI_TRUE;                /* 支持ht */
696             bss_dscr->ht_ldpc = (puc_ie[2] & BIT0);        /* 支持ldpc 2: 数组下标 */
697             ht_cap_bw = ((puc_ie[2] & BIT1) >> 1);         /* 取出支持的带宽 2: 数组下标 */
698             bss_dscr->ht_stbc = ((puc_ie[2] & BIT7) >> 7); /* 支持stbc 2: 数组下标,右移7位 */
699         }
700     }
701 
702     /* 默认20M,如果帧内容未携带HT_OPERATION则可以直接采用默认值 */
703     bss_dscr->channel_bandwidth = WLAN_BAND_WIDTH_20M;
704 
705     if (us_frame_len > us_offset) {
706         puc_ie = mac_find_ie(MAC_EID_HT_OPERATION, puc_frame_body + us_offset, us_frame_len - us_offset);
707     }
708     if ((puc_ie != HI_NULL) && (puc_ie[1] >= 2)) { /* 增加ie长度异常检查 2: 与2比较 */
709         ht_op = (mac_ht_opern_stru *)(puc_ie + MAC_IE_HDR_LEN);
710 
711         /* 提取次信道偏移 */
712         sec_chan_offset = ht_op->secondary_chan_offset;
713 
714         /* 防止ap的channel width=0, 但channel offset = 1或者3 此时以channel width为主 */
715         /* ht cap 20/40 enabled && ht operation 40 enabled */
716         if ((ht_op->sta_chan_width != 0) && (ht_cap_bw > WLAN_BW_CAP_20M)) { /* cap > 20M才取channel bw */
717             if (sec_chan_offset == MAC_SCB) {
718                 bss_dscr->channel_bandwidth = WLAN_BAND_WIDTH_40MINUS;
719                 ht_op_bw = WLAN_BW_CAP_40M;
720             } else if (sec_chan_offset == MAC_SCA) {
721                 bss_dscr->channel_bandwidth = WLAN_BAND_WIDTH_40PLUS;
722                 ht_op_bw = WLAN_BW_CAP_40M;
723             }
724         }
725     }
726 
727     /* 将AP带宽能力取声明能力的最小值,防止AP异常发送超过带宽能力数据,造成数据不通 */
728     bss_dscr->bw_cap = oal_min(ht_cap_bw, ht_op_bw);
729 
730     if (us_frame_len > us_offset) {
731         puc_ie = mac_find_ie(MAC_EID_EXT_CAPS, puc_frame_body + us_offset, us_frame_len - us_offset);
732         if ((puc_ie != HI_NULL) && (puc_ie[1] >= 1)) {
733             /* Extract 20/40 BSS Coexistence Management Support */
734             bss_dscr->coex_mgmt_supp = (puc_ie[2] & BIT0);
735         }
736     }
737 }
738 
739 /* ****************************************************************************
740  功能描述  : 更新协议类 bss信息
741  修改历史      :
742   1.日    期   : 2013年6月25日
743     作    者   : HiSilicon
744     修改内容   : 新生成函数
745   2.日    期   : 2013年8月21日
746     作    者   : HiSilicon
747     修改内容   : 补充11i 加密信息
748 **************************************************************************** */
hmac_scan_update_bss_list_protocol(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_len)749 static hi_void hmac_scan_update_bss_list_protocol(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body,
750     hi_u16 us_frame_len)
751 {
752     hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
753 
754     /* *********************************************************************** */
755     /*                       Beacon Frame - Frame Body                       */
756     /* ---------------------------------------------------------------------- */
757     /* |Timestamp|BcnInt|CapInfo|SSID|SupRates|DSParamSet|TIM  |CountryElem | */
758     /* ---------------------------------------------------------------------- */
759     /* |8        |2     |2      |2-34|3-10    |3         |6-256|8-256       | */
760     /* ---------------------------------------------------------------------- */
761     /* |PowerConstraint |Quiet|TPC Report|ERP |RSN  |WMM |Extended Sup Rates| */
762     /* ---------------------------------------------------------------------- */
763     /* |3               |8    |4         |3   |4-255|26  | 3-257            | */
764     /* ---------------------------------------------------------------------- */
765     /* |BSS Load |HT Capabilities |HT Operation |Overlapping BSS Scan       | */
766     /* ---------------------------------------------------------------------- */
767     /* |7        |28              |24           |16                         | */
768     /* ---------------------------------------------------------------------- */
769     /* |Extended Capabilities |                                              */
770     /* ---------------------------------------------------------------------- */
771     /* |3-8                   |                                              */
772     /* *********************************************************************** */
773     /* wmm */
774     hmac_scan_update_bss_list_wmm(bss_dscr, puc_frame_body, us_frame_len);
775 
776 #if defined(_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2)
777     /* 11i */
778     hmac_scan_update_bss_list_security(bss_dscr, puc_frame_body, us_frame_len, us_offset);
779 #endif
780 #ifdef _PRE_WLAN_FEATURE_11D
781     /* 11d */
782     hmac_scan_update_bss_list_country(bss_dscr, puc_frame_body, us_frame_len);
783 #endif
784     /* 11n */
785     hmac_scan_update_bss_list_11n(bss_dscr, puc_frame_body, us_frame_len, us_offset);
786 }
787 
788 /* ****************************************************************************
789  功能描述  : 检查速率
790  修改历史      :
791   1.日    期   : 2016年04月12日
792     作    者   : HiSilicon
793     修改内容   : 新生成函数
794 **************************************************************************** */
hmac_scan_check_bss_supp_rates(mac_device_stru * mac_dev,const hi_u8 * puc_rate,hi_u8 bss_rate_num,hi_u8 * puc_update_rate,hi_u8 rate_len)795 hi_u8 hmac_scan_check_bss_supp_rates(mac_device_stru *mac_dev, const hi_u8 *puc_rate, hi_u8 bss_rate_num,
796     hi_u8 *puc_update_rate, hi_u8 rate_len)
797 {
798     mac_data_rate_stru *rates = HI_NULL;
799     hi_u32 i, j;
800     hi_u8 rate_num = 0;
801 
802     rates = &mac_dev->mac_rates_11g[0];
803 
804     if (puc_rate == HI_NULL) {
805         return rate_num;
806     }
807 
808     for (i = 0; i < bss_rate_num; i++) {
809         for (j = 0; j < rate_len; j++) {
810             if (((rates[j].mac_rate & 0x7f) == (puc_rate[i] & 0x7f)) && (rate_num < MAC_DATARATES_PHY_80211G_NUM)) {
811                 puc_update_rate[rate_num] = puc_rate[i];
812                 rate_num++;
813                 break;
814             }
815         }
816     }
817 
818     return rate_num;
819 }
820 
821 /* ****************************************************************************
822  功能描述  : 更新扫描到bss的速率集
823  修改历史      :
824   1.日    期   : 2013年7月25日
825     作    者   : HiSilicon
826     修改内容   : 新生成函数
827 **************************************************************************** */
hmac_scan_update_bss_list_rates(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_len,mac_device_stru * mac_dev)828 static hi_u32 hmac_scan_update_bss_list_rates(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body, hi_u16 us_frame_len,
829     mac_device_stru *mac_dev)
830 {
831     hi_u8 *puc_ie = HI_NULL;
832     hi_u8 num_rates = 0;
833     hi_u8 num_ex_rates;
834     hi_u8 us_offset;
835     hi_u8 auc_rates[MAC_DATARATES_PHY_80211G_NUM] = {0};
836 
837     /* 设置Beacon帧的field偏移量 */
838     us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
839     if (us_frame_len <= us_offset) {
840         oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_rates::frame_len[%d].}", us_frame_len);
841         return HI_FAIL;
842     }
843 
844     puc_ie = mac_find_ie(MAC_EID_RATES, puc_frame_body + us_offset, us_frame_len - us_offset);
845     if (puc_ie != HI_NULL) {
846         num_rates = hmac_scan_check_bss_supp_rates(mac_dev, puc_ie + MAC_IE_HDR_LEN, puc_ie[1], auc_rates,
847             MAC_DATARATES_PHY_80211G_NUM);
848         if (num_rates > WLAN_MAX_SUPP_RATES) {
849             oam_warning_log1(0, OAM_SF_SCAN, "{hmac_scan_update_bss_list_rates::uc_num_rates=%d.}", num_rates);
850             num_rates = WLAN_MAX_SUPP_RATES;
851         }
852 
853         if (memcpy_s(bss_dscr->auc_supp_rates, WLAN_MAX_SUPP_RATES, auc_rates, num_rates) != EOK) {
854             oam_error_log0(0, OAM_SF_CFG, "hmac_scan_update_bss_list_rates:: auc_rates memcpy_s fail.");
855             return HI_FAIL;
856         }
857 
858         bss_dscr->num_supp_rates = num_rates;
859     }
860     puc_ie = mac_find_ie(MAC_EID_XRATES, puc_frame_body + us_offset, us_frame_len - us_offset);
861     if (puc_ie != HI_NULL) {
862         num_ex_rates = hmac_scan_check_bss_supp_rates(mac_dev, puc_ie + MAC_IE_HDR_LEN, puc_ie[1], auc_rates,
863             MAC_DATARATES_PHY_80211G_NUM);
864         if (num_rates + num_ex_rates > WLAN_MAX_SUPP_RATES) { /* 超出支持速率个数 */
865             oam_warning_log2(0, OAM_SF_SCAN,
866                 "{hmac_scan_update_bss_list_rates::number of rates too large, num_rates=%d, num_ex_rates=%d.}",
867                 num_rates, num_ex_rates);
868 
869             num_ex_rates = WLAN_MAX_SUPP_RATES - num_rates;
870         }
871 
872         if (num_ex_rates > 0) {
873             if (memcpy_s(&(bss_dscr->auc_supp_rates[num_rates]), WLAN_MAX_SUPP_RATES, auc_rates,
874                          num_ex_rates) != EOK) {
875                 oam_error_log0(0, OAM_SF_CFG, "hmac_scan_update_bss_list_rates:: auc_rates memcpy_s fail.");
876                 return HI_FAIL;
877             }
878         }
879         bss_dscr->num_supp_rates += num_ex_rates;
880     }
881 
882     return HI_SUCCESS;
883 }
884 
hmac_scan_update_bss_ssid(mac_bss_dscr_stru * bss_dscr,hmac_scanned_bss_info * scanned_bss,hi_u8 * puc_frame_body,hi_u16 us_frame_body_len)885 static hi_u32 hmac_scan_update_bss_ssid(mac_bss_dscr_stru *bss_dscr, hmac_scanned_bss_info *scanned_bss,
886     hi_u8 *puc_frame_body, hi_u16 us_frame_body_len)
887 {
888     hi_unref_param(scanned_bss);
889     hi_u8 ssid_len;
890     /* 解析并保存ssid */
891     hi_u8 *puc_ssid = mac_get_ssid(puc_frame_body, (hi_s32)us_frame_body_len, &ssid_len);
892     if ((puc_ssid != HI_NULL) && (ssid_len != 0)) {
893         /* 将查找到的ssid保存到bss描述结构体中 */
894         if (memcpy_s(bss_dscr->ac_ssid, WLAN_SSID_MAX_LEN, puc_ssid, ssid_len) != EOK) {
895             oam_warning_log1(0, OAM_SF_SCAN, "hmac_scan_update_bss_ssid:memcpy_s fail, ssid=[%p]", (uintptr_t)puc_ssid);
896             return HI_FAIL;
897         }
898         bss_dscr->ac_ssid[ssid_len] = '\0';
899 #ifdef _PRE_WLAN_FEATURE_MESH
900     } else {
901         /* 同WPA,Mesh的beacon和probe rsp会将ssid回复在私有meshid字段中,获取出来将meshid更新填充到ssid中 */
902         /* mac_get_meshid()函数返回值类型就是hi_u8*,误报lin_t64告警,申请屏蔽 */
903         puc_ssid = mac_get_meshid(puc_frame_body, (hi_s32)us_frame_body_len, &ssid_len);
904         /* 将查找到的ssid保存到bss描述结构体中 */
905         if (puc_ssid != HI_NULL) {
906             if (memcpy_s(bss_dscr->ac_ssid, WLAN_SSID_MAX_LEN, puc_ssid, ssid_len) != EOK) {
907                 oam_warning_log1(0, OAM_SF_SCAN, "hmac_scan_update_bss_ssid:memcpy_s fail, ssid=[%p]",
908                     (uintptr_t)puc_ssid);
909                 return HI_FAIL;
910             }
911         } else {
912             ssid_len = 0;
913         }
914         bss_dscr->ac_ssid[ssid_len] = '\0';
915 #endif
916     }
917 #ifdef _PRE_WLAN_FEATURE_SCAN_BY_SSID
918     /* 检查本次扫描请求是否为指定ssid扫描,判断是否需要驱动过滤非指定ssid的扫描信息 */
919     hmac_scan_proc_check_ssid(scanned_bss, puc_ssid, ssid_len);
920 #endif
921     return HI_SUCCESS;
922 }
923 
hmac_scan_update_bss_bssid(mac_bss_dscr_stru * bss_dscr,const mac_ieee80211_frame_stru * frame_header)924 static hi_u32 hmac_scan_update_bss_bssid(mac_bss_dscr_stru *bss_dscr, const mac_ieee80211_frame_stru *frame_header)
925 {
926     if (memcpy_s(bss_dscr->auc_mac_addr, WLAN_MAC_ADDR_LEN, frame_header->auc_address2, WLAN_MAC_ADDR_LEN) != EOK) {
927         oam_error_log0(0, 0, "{hmac_scan_update_bss_bssid::mem safe function err!}");
928         return HI_FAIL;
929     }
930     if (memcpy_s(bss_dscr->auc_bssid, WLAN_MAC_ADDR_LEN, frame_header->auc_address3, WLAN_MAC_ADDR_LEN) != EOK) {
931         oam_error_log0(0, 0, "{hmac_scan_update_bss_bssid::mem safe function err!}");
932         return HI_FAIL;
933     }
934     return HI_SUCCESS;
935 }
936 
hmac_scan_update_bss_base(hmac_vap_stru * hmac_vap,const dmac_tx_event_stru * dtx_event,mac_bss_dscr_stru * bss_dscr,hi_u8 frame_channel)937 static hi_void hmac_scan_update_bss_base(hmac_vap_stru *hmac_vap, const dmac_tx_event_stru *dtx_event,
938     mac_bss_dscr_stru *bss_dscr, hi_u8 frame_channel)
939 {
940     hi_unref_param(hmac_vap);
941 
942     oal_netbuf_stru *netbuf = dtx_event->netbuf;
943     mac_scanned_result_extend_info_stru *scan_result_extend_info = HI_NULL;
944     mac_device_stru *mac_dev = mac_res_get_dev();
945     hi_u16 us_netbuf_len = (hi_u16)(dtx_event->us_frame_len + MAC_80211_FRAME_LEN);
946     /* 获取device上报的扫描结果信息,并将其更新到bss描述结构体中 */
947     hi_u16 us_frame_len = us_netbuf_len - sizeof(mac_scanned_result_extend_info_stru);
948     hi_u8 *puc_mgmt_frame = (hi_u8 *)oal_netbuf_data(netbuf);
949     /* 指向netbuf中的上报的扫描结果的扩展信息的位置 */
950     scan_result_extend_info = (mac_scanned_result_extend_info_stru *)(puc_mgmt_frame + us_frame_len);
951     /* 获取管理帧的帧头和帧体指针 */
952     mac_ieee80211_frame_stru *frame_header = (mac_ieee80211_frame_stru *)puc_mgmt_frame;
953     hi_u8 *puc_frame_body = (hi_u8 *)(puc_mgmt_frame + MAC_80211_FRAME_LEN);
954     hi_u16 us_frame_body_len = us_frame_len - MAC_80211_FRAME_LEN;
955 
956     /* bss基本信息 */
957     bss_dscr->bss_type = scan_result_extend_info->bss_type;
958 
959     bss_dscr->us_cap_info = *((hi_u16 *)(puc_frame_body + MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN));
960 
961     bss_dscr->rssi = (hi_s8)scan_result_extend_info->l_rssi;
962 
963     /* 解析beacon周期 */
964     bss_dscr->us_beacon_period = mac_get_beacon_period(puc_frame_body);
965 
966     /* 解析 TIM 周期,仅 Beacon 帧有该元素 */
967     if (frame_header->frame_control.sub_type == WLAN_BEACON) {
968         bss_dscr->dtim_period = mac_get_dtim_period(puc_frame_body, us_frame_body_len);
969         bss_dscr->dtim_cnt = mac_get_dtim_cnt(puc_frame_body, us_frame_body_len);
970     }
971 
972     /* 信道 */
973     bss_dscr->channel.chan_number = frame_channel;
974     bss_dscr->channel.band = mac_get_band_by_channel_num(frame_channel);
975 
976     /* 记录速率集 */
977     if (hmac_scan_update_bss_list_rates(bss_dscr, puc_frame_body, us_frame_body_len, mac_dev) != HI_SUCCESS) {
978         oam_warning_log0(0, OAM_SF_SCAN, "hmac_scan_update_bss_list_rates return NON SUCCESS. ");
979     }
980 
981     /* 协议类相关信息元素的获取 */
982     hmac_scan_update_bss_list_protocol(bss_dscr, puc_frame_body, us_frame_body_len);
983 
984 #ifdef _PRE_WLAN_FEATURE_MESH
985     /* Probe Rsp和Beacon帧中前面为Timestamp,beacon interval,capability字段,非tlv结构,不能直接用于mac_find_ie函数,
986     此处加上偏移,以Element ID为0的SSID做为起始地址查找指定IE */
987     hi_u8 *puc_frame_ie_body = puc_frame_body + MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
988 
989     if (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) {
990         /* 新增Mesh Configuration Element解析获取Accepting Peer字段值 */
991         if (us_frame_body_len > MAC_SSID_OFFSET) {
992             mac_mesh_conf_ie_stru *puc_mesh_conf_ie = (mac_mesh_conf_ie_stru *)mac_find_ie(MAC_EID_MESH_CONF,
993                 puc_frame_ie_body, us_frame_body_len - MAC_SSID_OFFSET);
994             if (puc_mesh_conf_ie != HI_NULL) {
995                 bss_dscr->is_mesh_accepting_peer =
996                     (puc_mesh_conf_ie->mesh_capa.accepting_add_mesh_peerings == 1) ? HI_TRUE : HI_FALSE;
997             }
998         } else {
999             bss_dscr->is_mesh_accepting_peer = HI_FALSE;
1000         }
1001     }
1002     /* 查找Hisi-Mesh私有IE字段,过滤使用 */
1003     bss_dscr->is_hisi_mesh = mac_check_is_mesh_vap(puc_frame_ie_body, (hi_u8)(us_frame_body_len - MAC_SSID_OFFSET));
1004     if (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) {
1005         oam_info_log4(0, OAM_SF_SCAN, "hmac_scan_update_bss_base:mac address: 0x%x::0x%x, peer = %d, mesh = %d",
1006             bss_dscr->auc_mac_addr[4], bss_dscr->auc_mac_addr[5], /* 4 5 元素索引 */
1007             bss_dscr->is_mesh_accepting_peer, bss_dscr->is_hisi_mesh);
1008     }
1009 #endif
1010 }
1011 
hmac_scan_update_bss_any(mac_bss_dscr_stru * bss_dscr,hi_u8 * puc_frame_body,hi_u16 us_frame_body_len)1012 static hi_void hmac_scan_update_bss_any(mac_bss_dscr_stru *bss_dscr, hi_u8 *puc_frame_body, hi_u16 us_frame_body_len)
1013 {
1014 #ifdef _PRE_WLAN_FEATURE_ANY
1015     /* Probe Rsp和Beacon帧中前面为Timestamp,beacon interval,capability字段,非tlv结构,不能直接用于mac_find_ie函数,
1016     此处加上偏移,以Element ID为0的SSID做为起始地址查找指定IE */
1017     hi_u8 *puc_frame_ie_start = puc_frame_body + MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
1018     /* 查找对应的ANY IE */
1019     hi_u8 *puc_any_ie = mac_find_vendor_ie(MAC_WLAN_OUI_VENDOR, MAC_OUITYPE_ANY, puc_frame_ie_start,
1020         us_frame_body_len - MAC_SSID_OFFSET);
1021     if ((puc_any_ie != HI_NULL) && ((puc_any_ie[6] == MAC_ANY_STA_TYPE) || /* 6元素索引 */
1022         (puc_any_ie[6] == MAC_ANY_AP_TYPE))) {                             /* 6元素索引 */
1023         bss_dscr->supp_any = HI_TRUE;
1024         bss_dscr->is_any_sta = HI_FALSE;
1025         if (puc_any_ie[6] == MAC_ANY_STA_TYPE) { /* 6 元素索引 */
1026             bss_dscr->is_any_sta = HI_TRUE;
1027         }
1028     }
1029 #else
1030     hi_unref_param(bss_dscr);
1031     hi_unref_param(puc_frame_body);
1032     hi_unref_param(us_frame_body_len);
1033 #endif
1034     return;
1035 }
1036 
1037 /* ****************************************************************************
1038  功能描述  : 更新描述扫描结构的bss dscr结构体
1039  输入参数  : hmac_scanned_bss_info   *pst_scanned_bss,
1040              dmac_tx_event_stru      *pst_dtx_event,
1041              hi_u8                uc_vap_id
1042  修改历史      :
1043   1.日    期   : 2015年2月2日
1044     作    者   : HiSilicon
1045     修改内容   : 新生成函数
1046 **************************************************************************** */
hmac_scan_update_bss_dscr(hmac_scanned_bss_info * scanned_bss,const dmac_tx_event_stru * dtx_event,hi_u8 vap_id)1047 hi_u32 hmac_scan_update_bss_dscr(hmac_scanned_bss_info *scanned_bss, const dmac_tx_event_stru *dtx_event, hi_u8 vap_id)
1048 {
1049     oal_netbuf_stru *netbuf = dtx_event->netbuf;
1050     mac_scanned_result_extend_info_stru *scan_result_extend_info = HI_NULL;
1051     hi_u16 us_netbuf_len = (hi_u16)(dtx_event->us_frame_len + MAC_80211_FRAME_LEN);
1052     hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
1053 
1054     /* 获取hmac vap */
1055     hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(vap_id);
1056     if (hmac_vap == HI_NULL) {
1057         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_update_bss_dscr::pst_hmac_vap is null.}");
1058         return HI_FAIL;
1059     }
1060 
1061     /* 获取device上报的扫描结果信息,并将其更新到bss描述结构体中 */
1062     hi_u16 us_frame_len = us_netbuf_len - sizeof(mac_scanned_result_extend_info_stru);
1063     hi_u8 *puc_mgmt_frame = (hi_u8 *)oal_netbuf_data(netbuf);
1064     if (puc_mgmt_frame == HI_NULL) {
1065         oam_error_log0(0, OAM_SF_CFG, "hmac_scan_update_bss_dscr:: puc_mgmt_frame fail.");
1066         return HI_FAIL;
1067     }
1068 
1069     /* 指向netbuf中的上报的扫描结果的扩展信息的位置 */
1070     scan_result_extend_info = (mac_scanned_result_extend_info_stru *)(puc_mgmt_frame + us_frame_len);
1071     /* 获取管理帧的帧头和帧体指针 */
1072     mac_ieee80211_frame_stru *frame_header = (mac_ieee80211_frame_stru *)puc_mgmt_frame;
1073     hi_u8 *puc_frame_body = (hi_u8 *)(puc_mgmt_frame + MAC_80211_FRAME_LEN);
1074     hi_u16 us_frame_body_len = us_frame_len - MAC_80211_FRAME_LEN;
1075 
1076     /* 获取管理帧中的信道 */
1077     hi_u8 frame_channel = mac_ie_get_chan_num(puc_frame_body, us_frame_body_len, us_offset, 0);
1078     /* 如果信道非法,直接返回 */
1079     if (frame_channel == 0) {
1080         oam_info_log0(0, OAM_SF_SCAN, "hmac_scan_update_bss_dscr:: Received a frame from unregulated domain.");
1081         return HI_FAIL;
1082     }
1083 
1084     /* 如果收到的帧信道和当前扫描信道不一致,则检查帧信道是否在扫描信道列表中, 若不在则过滤 */
1085     hmac_device_stru *hmac_dev = hmac_get_device_stru();
1086     hmac_scan_stru *scan_mgmt = &(hmac_dev->scan_mgmt);
1087     if ((frame_channel != scan_result_extend_info->channel) &&
1088         (scan_mgmt->scan_2g_ch_list_map & (BIT0 << frame_channel)) == HI_FALSE) {
1089         scanned_bss->bss_dscr_info.need_drop = HI_TRUE;
1090     }
1091 
1092     /* 更新bss信息 */
1093     mac_bss_dscr_stru *bss_dscr = &(scanned_bss->bss_dscr_info);
1094 
1095     /* ****************************************************************************
1096         解析beacon/probe rsp帧,记录到pst_bss_dscr
1097     **************************************************************************** */
1098     /* 解析并保存ssid 和 bssid */
1099     if ((hmac_scan_update_bss_ssid(bss_dscr, scanned_bss, puc_frame_body, us_frame_body_len) != HI_SUCCESS) ||
1100         (hmac_scan_update_bss_bssid(bss_dscr, frame_header) != HI_SUCCESS)) {
1101         return HI_FAIL;
1102     }
1103 
1104     /* bss基本信息 */
1105     hmac_scan_update_bss_base(hmac_vap, dtx_event, bss_dscr, frame_channel);
1106 
1107     /* 更新时间戳 */
1108     bss_dscr->timestamp = (hi_u32)hi_get_milli_seconds();
1109     bss_dscr->mgmt_len = us_frame_len;
1110     /* 更新any相关信息 */
1111     hmac_scan_update_bss_any(bss_dscr, puc_frame_body, us_frame_body_len);
1112 
1113     /* 拷贝管理帧内容 */
1114     if (memcpy_s((hi_u8 *)scanned_bss->bss_dscr_info.auc_mgmt_buff, (hi_u32)us_frame_len, puc_mgmt_frame,
1115         (hi_u32)us_frame_len) != EOK) {
1116         oam_error_log0(0, OAM_SF_CFG, "hmac_scan_update_bss_dscr:: puc_mgmt_frame memcpy_s fail.");
1117         return HI_FAIL;
1118     }
1119 
1120     return HI_SUCCESS;
1121 }
1122 
hmac_scan_proc_scanned_bss_mgmt(hmac_device_stru * hmac_dev,hmac_scanned_bss_info * new_scanned_bss,oal_netbuf_stru * bss_mgmt_netbuf)1123 static hi_u32 hmac_scan_proc_scanned_bss_mgmt(hmac_device_stru *hmac_dev, hmac_scanned_bss_info *new_scanned_bss,
1124     oal_netbuf_stru *bss_mgmt_netbuf)
1125 {
1126     /* 获取管理扫描的bss结果的结构体 */
1127     hmac_bss_mgmt_stru *bss_mgmt = &(hmac_dev->scan_mgmt.scan_record_mgmt.bss_mgmt);
1128     /* 对链表删操作前加锁 */
1129     oal_spin_lock_bh(&(bss_mgmt->st_lock));
1130 
1131     /* 判断相同bssid的bss是否已经扫描到 */
1132     hmac_scanned_bss_info *old_scanned_bss =
1133         hmac_scan_find_scanned_bss_by_bssid(bss_mgmt, new_scanned_bss->bss_dscr_info.auc_bssid);
1134     if (old_scanned_bss == HI_NULL) {
1135         /* 解锁 */
1136         oal_spin_unlock_bh(&(bss_mgmt->st_lock));
1137 
1138         goto add_bss; /* goto语句使用,lin_t e801告警屏蔽 */
1139     }
1140 
1141     /* 如果老的扫描的bss的信号强度大于当前扫描到的bss的信号强度,更新当前扫描到的信号强度为最强的信号强度 */
1142     if (old_scanned_bss->bss_dscr_info.rssi > new_scanned_bss->bss_dscr_info.rssi) {
1143         /* 1s中以内就采用之前的BSS保存的RSSI信息,否则就采用新的RSSI信息 */
1144         if ((hi_get_milli_seconds() - old_scanned_bss->bss_dscr_info.timestamp) < HMAC_SCAN_MAX_SCANNED_RSSI_EXPIRE) {
1145             new_scanned_bss->bss_dscr_info.rssi = old_scanned_bss->bss_dscr_info.rssi;
1146         }
1147     }
1148 
1149     if ((new_scanned_bss->bss_dscr_info.ac_ssid[0] == '\0') && (old_scanned_bss->bss_dscr_info.ac_ssid[0] != '\0')) {
1150         /* 隐藏SSID,如果保存过此AP信息,且ssid不为空,此次通过BEACON帧扫描到此AP信息,且SSID为空,则不进行更新 */
1151         oam_warning_log3(0, OAM_SF_SCAN, "{hmac_scan_proc_scanned_bss::ssid:%.2x:%.2x:%.2x}",
1152             new_scanned_bss->bss_dscr_info.auc_bssid[3], new_scanned_bss->bss_dscr_info.auc_bssid[4], /* 3 4 元素索引 */
1153             new_scanned_bss->bss_dscr_info.auc_bssid[5]); /* 5 元素索引 */
1154 
1155         old_scanned_bss->bss_dscr_info.timestamp = (hi_u32)hi_get_milli_seconds();
1156         old_scanned_bss->bss_dscr_info.rssi = new_scanned_bss->bss_dscr_info.rssi;
1157 
1158         /* 解锁 */
1159         oal_spin_unlock_bh(&(bss_mgmt->st_lock));
1160 
1161         /* 释放申请的存储bss信息的内存 */
1162         oal_free(new_scanned_bss);
1163 
1164         /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1165         oal_netbuf_free(bss_mgmt_netbuf);
1166 
1167         return HI_SUCCESS;
1168     }
1169 
1170     /* 从链表中将原先扫描到的相同bssid的bss节点删除 */
1171     hmac_scan_del_bss_from_list_nolock(old_scanned_bss, hmac_dev);
1172     /* 解锁 */
1173     oal_spin_unlock_bh(&(bss_mgmt->st_lock));
1174 
1175     /* 释放内存 */
1176     oal_free(old_scanned_bss);
1177 
1178 add_bss: /* lint_t e801告警屏蔽 */
1179 #ifdef _PRE_WLAN_FEATURE_QUICK_START
1180     hi_s8 *pc_ssid = new_scanned_bss->bss_dscr_info.ac_ssid;
1181     databk_quick_start_stru *quick_start_param = hisi_get_quick_start_param();
1182     if ((quick_start_param->ssid_len != 0) && (quick_start_param->ssid_len == strlen(pc_ssid)) &&
1183         (SSID_MAX_LEN >= strlen(pc_ssid)) && (memcmp(quick_start_param->auc_ssid, pc_ssid, strlen(pc_ssid)) == 0)) {
1184         hi_u16 bsslen = sizeof(hmac_scanned_bss_info) + mgmt_len - sizeof(new_scanned_bss->bss_dscr_info.auc_mgmt_buff);
1185         /* 备份扫描结果 */
1186         if (memcpy_s(quick_start_param->auc_bss_frame, bsslen, new_scanned_bss, bsslen) != EOK) {
1187             oam_error_log0(0, OAM_SF_CFG, "hmac_scan_proc_scanned_bss:: pst_new_scanned_bss memcpy_s fail.");
1188             oal_free(new_scanned_bss);
1189             return HI_FAIL;
1190         }
1191         quick_start_param->us_bss_frame_len = mgmt_len;
1192         quick_start_param->uc_update_flag = PARAM_NEED_UPDATE;
1193     }
1194 #endif
1195 
1196     /* 将扫描结果添加到链表中 */
1197     hmac_scan_add_bss_to_list(new_scanned_bss, hmac_dev);
1198 
1199     /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1200     oal_netbuf_free(bss_mgmt_netbuf);
1201 
1202     return HI_SUCCESS;
1203 }
1204 
1205 /* ****************************************************************************
1206  功能描述  : 接收每个信道的扫描结果到host侧进行处理
1207  修改历史      :
1208   1.日    期   : 2015年2月7日
1209     作    者   : HiSilicon
1210     修改内容   : 新生成函数
1211 **************************************************************************** */
hmac_scan_proc_scanned_bss(frw_event_mem_stru * event_mem)1212 hi_u32 hmac_scan_proc_scanned_bss(frw_event_mem_stru *event_mem)
1213 {
1214     if (oal_unlikely(event_mem == HI_NULL)) {
1215         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scanned_bss::event_mem null.}");
1216         return HI_ERR_CODE_PTR_NULL;
1217     }
1218 
1219     /* 获取事件头和事件结构体指针 */
1220     frw_event_stru *event = (frw_event_stru *)event_mem->puc_data;
1221     frw_event_hdr_stru *event_hdr = &(event->event_hdr);
1222     dmac_tx_event_stru *dtx_event = (dmac_tx_event_stru *)event->auc_event_data;
1223     oal_netbuf_stru *bss_mgmt_netbuf = dtx_event->netbuf;
1224 
1225     hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(event_hdr->vap_id);
1226     if (oal_unlikely(hmac_vap == HI_NULL)) {
1227         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scanned_bss::pst_hmac_vap null.}");
1228 
1229         /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1230         oal_netbuf_free(bss_mgmt_netbuf);
1231         return HI_ERR_CODE_PTR_NULL;
1232     }
1233 
1234     /* 获取hmac device 结构 */
1235     hmac_device_stru *hmac_dev = hmac_get_device_stru();
1236     /* 对dmac上报的netbuf内容进行解析,内容如下所示 */
1237     /* ********************************************************************************************* */
1238     /*            netbuf data域的上报的扫描结果的字段的分布                                        */
1239     /* ------------------------------------------------------------------------------------------  */
1240     /* beacon/probe rsp body  |     帧体后面附加字段(mac_scanned_result_extend_info_stru)          */
1241     /* -----------------------------------------------------------------------------------------   */
1242     /* 收到的beacon/rsp的body | rssi(4字节) | channel num(1字节)| band(1字节)|bss_tye(1字节)|填充  */
1243     /* ------------------------------------------------------------------------------------------  */
1244     /*                                                                                             */
1245     /* ********************************************************************************************* */
1246     /* 管理帧的长度等于上报的netbuf的长度减去上报的扫描结果的扩展字段的长度 */
1247     hi_u16 us_mgmt_len =
1248         (hi_u16)(dtx_event->us_frame_len + MAC_80211_FRAME_LEN - sizeof(mac_scanned_result_extend_info_stru));
1249 
1250     /* 申请存储扫描结果的内存 */
1251     hmac_scanned_bss_info *new_scanned_bss = hmac_scan_alloc_scanned_bss(us_mgmt_len);
1252     if (oal_unlikely(new_scanned_bss == HI_NULL)) {
1253         oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_SCAN, "{hmac_scan_proc_scanned_bss::alloc memory failed }");
1254 
1255         /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1256         oal_netbuf_free(bss_mgmt_netbuf);
1257         return HI_FAIL;
1258     }
1259 
1260     /* 更新描述扫描结果的bss dscr结构体 */
1261     if (oal_unlikely(hmac_scan_update_bss_dscr(new_scanned_bss, dtx_event, event_hdr->vap_id) != HI_SUCCESS)) {
1262         oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_SCAN, "{hmac_scan_proc_scanned_bss::hmac_scan_update fail}");
1263 
1264         /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1265         oal_netbuf_free(bss_mgmt_netbuf);
1266 
1267         /* 释放申请的存储bss信息的内存 */
1268         oal_free(new_scanned_bss);
1269         return HI_FAIL;
1270     }
1271 
1272 #ifdef _PRE_WLAN_FEATURE_MESH
1273     /* MESH VAP过滤非MESH VAP发出的Beacon/Probe Rsp
1274        过滤规则:1.en_is_hisi_mesh为FALSE 2.en_is_mesh_accepting_peer为FALSE,
1275        如果扫描是ANY下发的扫描,则这里不过滤 */
1276     if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) &&
1277         (((new_scanned_bss->bss_dscr_info.is_hisi_mesh == HI_FALSE) ||
1278         (new_scanned_bss->bss_dscr_info.is_mesh_accepting_peer == HI_FALSE)) &&
1279         (hmac_dev->scan_mgmt.scan_record_mgmt.is_any_scan == HI_FALSE))) {
1280         /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1281         oal_netbuf_free(bss_mgmt_netbuf);
1282 
1283         /* 释放申请的存储bss信息的内存 */
1284         oal_free(new_scanned_bss);
1285 
1286         return HI_SUCCESS;
1287     }
1288 #endif
1289 
1290     /* 如果之前的判断需要过滤 */
1291     if (new_scanned_bss->bss_dscr_info.need_drop == HI_TRUE) {
1292         /* 释放上报的bss信息和beacon或者probe rsp帧的内存 */
1293         oal_netbuf_free(bss_mgmt_netbuf);
1294 
1295         /* 释放申请的存储bss信息的内存 */
1296         oal_free(new_scanned_bss);
1297 
1298         return HI_SUCCESS;
1299     }
1300 
1301     return hmac_scan_proc_scanned_bss_mgmt(hmac_dev, new_scanned_bss, bss_mgmt_netbuf);
1302 }
1303 
hmac_scan_proc_scan_comp_event_vap(const mac_device_stru * mac_dev,hmac_scan_stru * scan_mgmt,hmac_vap_stru * hmac_vap)1304 static hi_void hmac_scan_proc_scan_comp_event_vap(const mac_device_stru *mac_dev, hmac_scan_stru *scan_mgmt,
1305     hmac_vap_stru *hmac_vap)
1306 {
1307     if ((mac_is_dbac_running(mac_dev) != HI_TRUE) || (mac_dev->dbac_same_ch == HI_TRUE)) {
1308         /* 根据当前扫描的类型和当前vap的状态,决定切换vap的状态,如果是前景扫描,才需要切换vap的状态 */
1309         if (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) {
1310             if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_STA_WAIT_SCAN) {
1311                 /* 改变vap状态到SCAN_COMP */
1312                 hmac_fsm_change_state(hmac_vap, MAC_VAP_STATE_STA_SCAN_COMP);
1313             } else if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_UP) {
1314                 /* 背景扫描时需要进行帧过滤的配置 */
1315                 hmac_set_rx_filter_value(hmac_vap->base_vap);
1316             }
1317         }
1318 
1319         if (((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_BSS_AP) ||
1320             (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH)) &&
1321             (scan_mgmt->scan_record_mgmt.vap_last_state != MAC_VAP_STATE_BUTT)) {
1322             hmac_fsm_change_state(hmac_vap, scan_mgmt->scan_record_mgmt.vap_last_state);
1323             scan_mgmt->scan_record_mgmt.vap_last_state = MAC_VAP_STATE_BUTT;
1324         }
1325     }
1326 }
1327 
1328 /* ****************************************************************************
1329  功能描述  : DMAC扫描完成事件处理
1330  修改历史      :
1331   1.日    期   : 2013年6月25日
1332     作    者   : HiSilicon
1333     修改内容   : 新生成函数
1334 **************************************************************************** */
hmac_scan_proc_scan_comp_event(frw_event_mem_stru * event_mem)1335 hi_u32 hmac_scan_proc_scan_comp_event(frw_event_mem_stru *event_mem)
1336 {
1337     /* 获取事件头和事件结构体指针 */
1338     frw_event_stru *event = (frw_event_stru *)event_mem->puc_data;
1339     frw_event_hdr_stru *event_hdr = &(event->event_hdr);
1340 
1341     /* 获取hmac device */
1342     hmac_device_stru *hmac_dev = hmac_get_device_stru();
1343     mac_device_stru *mac_dev = mac_res_get_dev();
1344     mac_scan_rsp_stru *d2h_scan_rsp_info = (mac_scan_rsp_stru *)(event->auc_event_data);
1345     hmac_scan_stru *scan_mgmt = &(hmac_dev->scan_mgmt);
1346 
1347     /* 如果下发的是ANY扫描,结束扫描的时候设置为非ANY扫描,下发的若非ANY扫描,这里赋该值无影响 */
1348     hmac_dev->scan_mgmt.scan_record_mgmt.is_any_scan = HI_FALSE;
1349 
1350     if ((event_hdr->vap_id != scan_mgmt->scan_record_mgmt.vap_id) ||
1351         (d2h_scan_rsp_info->ull_cookie != scan_mgmt->scan_record_mgmt.ull_cookie)) {
1352         oam_warning_log4(event_hdr->vap_id, OAM_SF_SCAN,
1353             "{hmac_scan_proc_scan_comp_event::vap(%d) Scancomplete(cookie %d), anoter vap(%d) scanning(cookie %d) !}",
1354             event_hdr->vap_id, d2h_scan_rsp_info->ull_cookie, scan_mgmt->scan_record_mgmt.vap_id,
1355             scan_mgmt->scan_record_mgmt.ull_cookie);
1356         return HI_SUCCESS;
1357     }
1358 
1359     /* 删除扫描超时保护定时器 */
1360     if (scan_mgmt->scan_timeout.is_registerd == HI_TRUE) {
1361         frw_timer_immediate_destroy_timer(&(scan_mgmt->scan_timeout));
1362     }
1363 
1364     /* 获取hmac vap */
1365     hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(event_hdr->vap_id);
1366     if (oal_unlikely(hmac_vap == HI_NULL)) {
1367         oam_error_log0(event_hdr->vap_id, OAM_SF_SCAN, "{hmac_scan_proc_scan_comp_event::pst_hmac_vap null.}");
1368 
1369         /* 设置当前处于非扫描状态 */
1370         scan_mgmt->is_scanning = HI_FALSE;
1371         return HI_ERR_CODE_PTR_NULL;
1372     }
1373 
1374     hmac_scan_proc_scan_comp_event_vap(mac_dev, scan_mgmt, hmac_vap);
1375 
1376 #ifdef _PRE_WLAN_FEATURE_ANY
1377     if ((hmac_vap->base_vap->support_any == HI_TRUE) && (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) &&
1378         (mac_dev->vap_num == 1) && (mac_dev->scan_params.scan_mode == WLAN_SCAN_MODE_FOREGROUND)) {
1379         oam_warning_log1(0, OAM_SF_SCAN, "{[ANY]switch to original channel %d.}",
1380             hmac_vap->base_vap->channel.chan_number);
1381         hmac_config_set_freq(hmac_vap->base_vap, 1, &hmac_vap->base_vap->channel.chan_number);
1382     }
1383 #endif
1384     /* 1102 作为ap ,40M 带宽下执行扫描,扫描完成后VAP 状态修改为扫描前的状态 */
1385     /* 根据device上报的扫描结果,上报sme */
1386     /* 将扫描执行情况(扫描执行成功、还是失败等返回结果)记录到扫描运行记录结构体中 */
1387     scan_mgmt->scan_record_mgmt.scan_rsp_status = d2h_scan_rsp_info->scan_rsp_status;
1388     scan_mgmt->scan_record_mgmt.ull_cookie = d2h_scan_rsp_info->ull_cookie;
1389 
1390     /* 上报扫描结果前,清除下到期的扫描bss,防止上报过多到期的bss */
1391     hmac_scan_clean_expire_scanned_bss(&(scan_mgmt->scan_record_mgmt), HI_FALSE);
1392     /* 如果扫描回调函数不为空,则调用回调函数 */
1393     if (scan_mgmt->scan_record_mgmt.fn_cb != HI_NULL) {
1394         scan_mgmt->scan_record_mgmt.fn_cb(&(scan_mgmt->scan_record_mgmt));
1395     }
1396 
1397     /* 设置当前处于非扫描状态 */
1398     scan_mgmt->is_scanning = HI_FALSE;
1399 
1400 #ifdef _PRE_WLAN_FEATURE_P2P
1401     if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_STA_LISTEN) {
1402         hmac_p2p_listen_timeout(hmac_vap->base_vap);
1403     }
1404     if (hmac_vap->en_wait_roc_end == HI_TRUE) {
1405         oam_warning_log1(event_hdr->vap_id, OAM_SF_SCAN, "{hmac_scan_proc_scan_comp_event::scan rsp status[%d]}",
1406             d2h_scan_rsp_info->scan_rsp_status);
1407         OAL_COMPLETE(&(hmac_vap->st_roc_end_ready));
1408         hmac_vap->en_wait_roc_end = HI_FALSE;
1409     }
1410 #endif
1411     return HI_SUCCESS;
1412 }
1413 
1414 /* ****************************************************************************
1415  功能描述  : 异常扫描请求,抛事件到wal 层,执行扫描完成
1416  输入参数  : pst_mac_device: 指向device结构体
1417              p_params: 本次扫描请求的参数
1418  修改历史      :
1419   1.日    期   : 2013年12月26日
1420     作    者   : HiSilicon
1421     修改内容   : 新生成函数
1422 **************************************************************************** */
hmac_scan_proc_scan_req_event_exception(hmac_vap_stru * hmac_vap)1423 hi_u32 hmac_scan_proc_scan_req_event_exception(hmac_vap_stru *hmac_vap)
1424 {
1425     hmac_scan_rsp_stru scan_rsp;
1426 
1427     if (oal_unlikely(hmac_vap == HI_NULL)) {
1428         oam_error_log1(0, OAM_SF_SCAN, "{hmac_mgmt_scan_req_exception::param null, %p.}", (uintptr_t)hmac_vap);
1429         return HI_ERR_CODE_PTR_NULL;
1430     }
1431 
1432     /* 不支持发起扫描的状态发起了扫描 */
1433     oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_SCAN, "{hmac_mgmt_scan_req_exception::vap state is=%x.}",
1434         hmac_vap->base_vap->vap_state);
1435 
1436     if (memset_s(&scan_rsp, sizeof(hmac_scan_rsp_stru), 0, sizeof(hmac_scan_rsp_stru)) != EOK) {
1437         return HI_FAIL;
1438     }
1439 
1440     scan_rsp.result_code = HMAC_MGMT_REFUSED;
1441     scan_rsp.num_dscr = 0;
1442 
1443     return hmac_send_event_to_host(hmac_vap->base_vap, (const hi_u8 *)(&scan_rsp), sizeof(hmac_scan_rsp_stru),
1444         HMAC_HOST_CTX_EVENT_SUB_TYPE_SCAN_COMP_STA);
1445 }
1446 
1447 /* ****************************************************************************
1448  功能描述  : 设置probe req帧中携带的源mac addr,如果随机mac addr特性开启,则携带随机mac addr
1449  输入参数  : [1]pst_hmac_vap
1450              [2]puc_sour_mac_addr
1451              [3]is_rand_mac_addr_scan
1452              [4]is_p2p0_scan
1453  返 回 值  : 无
1454 **************************************************************************** */
hmac_scan_set_sour_mac_addr_in_probe_req(const hmac_vap_stru * hmac_vap,hi_u8 * sa_mac_addr,hi_u8 mac_addr_len,hi_u8 is_rand_mac_addr_scan,hi_u8 is_p2p0_scan)1455 hi_void hmac_scan_set_sour_mac_addr_in_probe_req(const hmac_vap_stru *hmac_vap, hi_u8 *sa_mac_addr, hi_u8 mac_addr_len,
1456     hi_u8 is_rand_mac_addr_scan, hi_u8 is_p2p0_scan)
1457 {
1458 #ifdef _PRE_WLAN_FEATURE_P2P
1459     /* WLAN/P2P 特性情况下,p2p0 和p2p-p2p0 cl 扫描时候,需要使用不同设备 */
1460     if (is_p2p0_scan == HI_TRUE) {
1461         if (memcpy_s(sa_mac_addr, mac_addr_len,
1462             hmac_vap->base_vap->mib_info->wlan_mib_sta_config.auc_p2p0_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
1463             return;
1464         }
1465     } else
1466 #else
1467     hi_unref_param(is_p2p0_scan);
1468 #endif /* _PRE_WLAN_FEATURE_P2P */
1469     {
1470         /* 如果随机mac addr扫描特性开启且非P2P场景,设置随机mac addr到probe req帧中 */
1471         if ((is_rand_mac_addr_scan == HI_TRUE) && (is_legacy_vap(hmac_vap->base_vap))) {
1472             oal_random_ether_addr(sa_mac_addr, mac_addr_len);
1473             sa_mac_addr[0] &= (~0x02); /* wlan0 MAC[0] bit1 需要设置为0 */
1474             sa_mac_addr[1] = 0x11;
1475             sa_mac_addr[2] = 0x02; /* 2 元素索引 */
1476 
1477             oam_warning_log3(hmac_vap->base_vap->vap_id, OAM_SF_SCAN,
1478                 "{hmac_scan_set_sour_mac_addr_in_probe_req::rand_mac_addr[XX:XX:XX:%02X:%02X:%02X].}",
1479                 sa_mac_addr[3],                  /* 3 元素索引 */
1480                 sa_mac_addr[4], sa_mac_addr[5]); /* 4 5 元素索引 */
1481         } else {
1482             /* 设置地址为自己的MAC地址 */
1483             if (memcpy_s(sa_mac_addr, mac_addr_len,
1484                 hmac_vap->base_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
1485                 return;
1486             }
1487         }
1488     }
1489     return;
1490 }
1491 
1492 /* ****************************************************************************
1493  功能描述  : 根据device下所有的vap状态以及其它信息,更新扫描参数:
1494              包括发起扫描者的vap id、扫描模式、每信道扫描次数、probe req帧携带的源mac addr
1495  输入参数  : hmac_vap_stru *pst_hmac_vap,
1496              mac_scan_req_stru *pst_scan_params,
1497              hi_u8   en_is_random_mac_addr_scan,      是否为随机mac addr扫描的标记
1498  修改历史      :
1499   1.日    期   : 2015年2月4日
1500     作    者   : HiSilicon
1501     修改内容   : 新生成函数
1502 **************************************************************************** */
hmac_scan_update_scan_params(const hmac_vap_stru * hmac_vap,mac_scan_req_stru * scan_params,hi_u8 is_random_mac_addr_scan)1503 static hi_u32 hmac_scan_update_scan_params(const hmac_vap_stru *hmac_vap, mac_scan_req_stru *scan_params,
1504     hi_u8 is_random_mac_addr_scan)
1505 {
1506     mac_device_stru *mac_dev = HI_NULL;
1507     mac_vap_stru *mac_vap_temp = HI_NULL;
1508     wlan_vap_mode_enum_uint8 vap_mode;
1509 
1510     /* 获取mac device */
1511     mac_dev = mac_res_get_dev();
1512     /* 1.记录发起扫描的vap id到扫描参数 */
1513     scan_params->vap_id = hmac_vap->base_vap->vap_id;
1514     scan_params->scan_mode = WLAN_SCAN_MODE_FOREGROUND;
1515     scan_params->need_switch_back_home_channel = HI_FALSE;
1516 
1517     /* 2.修改扫描模式和信道扫描次数: 根据是否存在up状态下的vap,如果是,则是背景扫描,如果不是,则是前景扫描 */
1518     mac_device_find_up_vap(mac_dev, &mac_vap_temp);
1519     if (mac_vap_temp != HI_NULL) {
1520         /* 判断vap的类型,如果是sta则为sta的背景扫描,如果是ap,则是ap的背景扫描,其它类型的vap暂不支持背景扫描 */
1521         vap_mode = hmac_vap->base_vap->vap_mode;
1522         if (vap_mode == WLAN_VAP_MODE_BSS_STA) {
1523             /* 修改扫描参数为sta的背景扫描 */
1524             scan_params->scan_mode = WLAN_SCAN_MODE_BACKGROUND_STA;
1525         } else if (vap_mode == WLAN_VAP_MODE_BSS_AP
1526 #ifdef _PRE_WLAN_FEATURE_MESH
1527             || (vap_mode == WLAN_VAP_MODE_MESH)
1528 #endif
1529         ) {
1530             /* 修改扫描参数为sta的背景扫描 */
1531             scan_params->scan_mode = WLAN_SCAN_MODE_BACKGROUND_AP;
1532         } else {
1533             oam_error_log1(0, OAM_SF_SCAN, "{hmac_scan_update_scan_params::vap mode[%d], not support bg scan.}",
1534                 vap_mode);
1535             return HI_FAIL;
1536         }
1537         scan_params->need_switch_back_home_channel = HI_TRUE;
1538     }
1539     /* 3.设置发送的probe req帧中源mac addr */
1540     scan_params->is_random_mac_addr_scan = is_random_mac_addr_scan;
1541     hmac_scan_set_sour_mac_addr_in_probe_req(hmac_vap, scan_params->auc_sour_mac_addr, WLAN_MAC_ADDR_LEN,
1542         is_random_mac_addr_scan, scan_params->is_p2p0_scan);
1543 
1544     return HI_SUCCESS;
1545 }
1546 
1547 /* ****************************************************************************
1548  功能描述  : 检测是否能够发起扫描,如果可以,则记录扫描请求者的信息,并清空上一次扫描结果
1549  输入参数  : hmac_vap_stru       *pst_hmac_vap,
1550              hmac_device_stru    *pst_hmac_device
1551  修改历史      :
1552   1.日    期   : 2015年5月18日
1553     作    者   : HiSilicon
1554     修改内容   : 新生成函数
1555 **************************************************************************** */
hmac_scan_check_is_dispatch_scan_req(const hmac_vap_stru * hmac_vap,const hmac_device_stru * hmac_dev)1556 static hi_u32 hmac_scan_check_is_dispatch_scan_req(const hmac_vap_stru *hmac_vap, const hmac_device_stru *hmac_dev)
1557 {
1558 #ifdef _PRE_WLAN_FEATURE_P2P
1559     hi_u32 ret;
1560     /* 1.先检测其它vap的状态从而判断是否可进入扫描状态,使得扫描尽量不打断其它的入网流程 */
1561     ret = hmac_p2p_check_can_enter_state(hmac_vap->base_vap, HMAC_FSM_INPUT_SCAN_REQ);
1562     if (ret != HI_SUCCESS) {
1563         oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_SCAN,
1564             "{hmac_scan_check_is_dispatch_scan_req::Because of err_code[%d], can't enter into scan state.}", ret);
1565         return ret;
1566     }
1567 #else
1568     hi_unref_param(hmac_vap);
1569 #endif
1570     /* 2.判断当前扫描是否正在执行 */
1571     if (hmac_dev->scan_mgmt.is_scanning == HI_TRUE) {
1572         oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_SCAN,
1573             "{hmac_scan_check_is_dispatch_scan_req::the scan request is rejected.}");
1574         return HI_FAIL;
1575     }
1576     return HI_SUCCESS;
1577 }
1578 
1579 /* ****************************************************************************
1580  功能描述  : 处理上一次的扫描记录,接口封装,从而便于可扩展(未来可能使用老化机制判断是否清除)
1581  输入参数  : hmac_vap_stru       *pst_hmac_vap,
1582              hmac_device_stru    *pst_hmac_device
1583  修改历史      :
1584   1.日    期   : 2015年5月22日
1585     作    者   : HiSilicon
1586     修改内容   : 新生成函数
1587 **************************************************************************** */
hmac_scan_proc_last_scan_record(hmac_device_stru * hmac_dev)1588 static hi_void hmac_scan_proc_last_scan_record(hmac_device_stru *hmac_dev)
1589 {
1590     oam_info_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scan_req_event:: start clean last scan record.}");
1591 
1592     /* 本次扫描请求发起时,清除上一次扫描结果中过期的bss信息 */
1593     hmac_scan_clean_expire_scanned_bss(&(hmac_dev->scan_mgmt.scan_record_mgmt), HI_FALSE);
1594     return;
1595 }
1596 
1597 /* ****************************************************************************
1598  功能描述  : host侧抛扫描请求时间到device侧,防止因核间通信、抛事件等异常情况,host侧接收不到
1599              扫描响应的超时回调函数处理,属于扫描模块内的超时保护
1600  修改历史      :
1601   1.日    期   : 2015年5月19日
1602     作    者   : HiSilicon
1603     修改内容   : 新生成函数
1604 **************************************************************************** */
hmac_scan_proc_scan_timeout_fn(hi_void * arg)1605 static hi_u32 hmac_scan_proc_scan_timeout_fn(hi_void *arg)
1606 {
1607     hmac_device_stru *hmac_dev = (hmac_device_stru *)arg;
1608     hmac_vap_stru *hmac_vap = HI_NULL;
1609     hmac_scan_record_stru *scan_record = HI_NULL;
1610     hi_u32 pedding_data = 0;
1611 
1612     /* 获取扫描记录信息 */
1613     scan_record = &(hmac_dev->scan_mgmt.scan_record_mgmt);
1614 
1615     /* 若下发的是ANY扫描,结束扫描的时候恢复标志为非ANY扫描,若下发的非ANY扫描,这里赋该值无影响 */
1616     scan_record->is_any_scan = HI_FALSE;
1617 
1618     /* 获取hmac vap */
1619     hmac_vap = hmac_vap_get_vap_stru(scan_record->vap_id);
1620     if (oal_unlikely(hmac_vap == HI_NULL)) {
1621         oam_error_log0(scan_record->vap_id, OAM_SF_SCAN, "{hmac_scan_proc_scan_timeout_fn::pst_hmac_vap null.}");
1622 
1623         /* 扫描状态恢复为未在执行的状态 */
1624         hmac_dev->scan_mgmt.is_scanning = HI_FALSE;
1625         return HI_ERR_CODE_PTR_NULL;
1626     }
1627 
1628     /* 根据当前扫描的类型和当前vap的状态,决定切换vap的状态,如果是前景扫描,才需要切换vap的状态 */
1629     if (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) {
1630         if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_STA_WAIT_SCAN) {
1631             /* 改变vap状态到SCAN_COMP */
1632             hmac_fsm_change_state(hmac_vap, MAC_VAP_STATE_STA_SCAN_COMP);
1633         } else if (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_UP) {
1634             /* 背景扫描时需要进行帧过滤的配置 */
1635             hmac_set_rx_filter_value(hmac_vap->base_vap);
1636         }
1637     }
1638 
1639     /* 1102 作为ap ,40M 带宽下执行扫描,扫描完成后VAP 状态修改为扫描前的状态 */
1640     if (((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_BSS_AP)
1641 #ifdef _PRE_WLAN_FEATURE_MESH
1642         || (hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH)
1643 #endif
1644         ) && (scan_record->vap_last_state != MAC_VAP_STATE_BUTT)) {
1645         hmac_fsm_change_state(hmac_vap, scan_record->vap_last_state);
1646         scan_record->vap_last_state = MAC_VAP_STATE_BUTT;
1647     }
1648     /* 1102 作为ap ,40M 带宽下执行扫描,扫描完成后VAP 状态修改为扫描前的状态 */
1649     /* 设置扫描响应状态为超时 */
1650     scan_record->scan_rsp_status = MAC_SCAN_TIMEOUT;
1651     oam_warning_log1(scan_record->vap_id, OAM_SF_SCAN, "{hmac_scan_proc_scan_timeout_fn::scan time out cookie [%x].}",
1652         scan_record->ull_cookie);
1653 
1654     /* 如果扫描回调函数不为空,则调用回调函数 */
1655     if (scan_record->fn_cb != HI_NULL) {
1656         oam_warning_log0(scan_record->vap_id, OAM_SF_SCAN,
1657             "{hmac_scan_proc_scan_timeout_fn::scan callback func proc.}");
1658         scan_record->fn_cb(scan_record);
1659     }
1660 
1661     /* DMAC 超时未上报扫描完成,HMAC 下发扫描结束命令,停止DMAC 扫描 */
1662     hmac_config_scan_abort(hmac_vap->base_vap, sizeof(hi_u32), (hi_u8 *)&pedding_data);
1663 
1664     /* 扫描状态恢复为未在执行的状态 */
1665     hmac_dev->scan_mgmt.is_scanning = HI_FALSE;
1666 
1667     return HI_SUCCESS;
1668 }
1669 
1670 /* ****************************************************************************
1671  功能描述  : 填写扫描请求事件并通知dmac进行扫描
1672 **************************************************************************** */
hmac_scan_dispatch_req_event(const hmac_vap_stru * hmac_vap,const mac_scan_req_stru * scan_params)1673 hi_u32 hmac_scan_dispatch_req_event(const hmac_vap_stru *hmac_vap, const mac_scan_req_stru *scan_params)
1674 {
1675     frw_event_mem_stru *event_mem = HI_NULL;
1676     frw_event_stru *event = HI_NULL;
1677     mac_scan_req_stru *h2d_scan_req_params = HI_NULL; /* hmac发送到dmac的扫描请求参数 */
1678     hmac_device_stru *hmac_dev = hmac_get_device_stru();
1679     hi_u32 scan_timeout;
1680 
1681     /* 抛扫描请求事件到DMAC, 申请事件内存 */
1682     event_mem = frw_event_alloc(sizeof(mac_scan_req_stru));
1683     if (event_mem == HI_NULL) {
1684         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scan_req_event::event_mem null.}");
1685         /* 恢复扫描状态为非运行状态 */
1686         hmac_dev->scan_mgmt.is_scanning = HI_FALSE;
1687         return HI_ERR_CODE_PTR_NULL;
1688     }
1689     /* 填写事件 */
1690     event = (frw_event_stru *)event_mem->puc_data;
1691     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX, DMAC_WLAN_CTX_EVENT_SUB_TYPE_SCAN_REQ,
1692         sizeof(mac_scan_req_stru), FRW_EVENT_PIPELINE_STAGE_1, hmac_vap->base_vap->vap_id);
1693     h2d_scan_req_params = (mac_scan_req_stru *)(event->auc_event_data);
1694     /* 拷贝扫描请求参数到事件data区域 */
1695     /* h2d_scan_req_params: event->auc_event_data, 可变数组 */
1696     if (memcpy_s(h2d_scan_req_params, sizeof(mac_scan_req_stru), scan_params, sizeof(mac_scan_req_stru)) != EOK) {
1697         frw_event_free(event_mem);
1698         oam_error_log0(0, OAM_SF_CFG, "hmac_scan_proc_scan_req_event:: pst_scan_params memcpy_s fail.");
1699         return HI_FAIL;
1700     }
1701 
1702     /* 如果是P2P 发起监听,则设置HMAC 扫描超时时间为P2P 监听时间 */
1703     if (MAC_SCAN_FUNC_P2P_LISTEN == scan_params->scan_func) {
1704         scan_timeout = scan_params->us_scan_time * 2; /* 2倍超出监听时间 */
1705     } else {
1706         scan_timeout = WLAN_MAX_TIME_PER_SCAN;
1707     }
1708 
1709     oam_warning_log4(scan_params->vap_id, OAM_SF_SCAN,
1710         "Scan_params::Now Scan channel_num[%d] p2p_scan[%d],scan_cnt_per_ch[%d],need back home_ch[%d]!",
1711         scan_params->channel_nums, scan_params->is_p2p0_scan, scan_params->max_scan_cnt_per_channel,
1712         scan_params->need_switch_back_home_channel);
1713 
1714     /* 启动扫描保护定时器,防止因拋事件、核间通信失败等情况下的异常保护,定时器初步的超时时间为4.5秒 */
1715     frw_timer_create_timer(&(hmac_dev->scan_mgmt.scan_timeout), hmac_scan_proc_scan_timeout_fn, scan_timeout, hmac_dev,
1716         HI_FALSE);
1717     /* 如果是p2p listen 记录下listen的信道 */
1718     if (MAC_SCAN_FUNC_P2P_LISTEN == scan_params->scan_func) {
1719         hmac_dev->scan_mgmt.p2p_listen_channel = scan_params->ast_channel_list[0];
1720     }
1721     /* 分发事件 */
1722     hcc_hmac_tx_control_event(event_mem, sizeof(mac_scan_req_stru));
1723     frw_event_free(event_mem);
1724     return HI_SUCCESS;
1725 }
1726 
1727 /* ****************************************************************************
1728  功能描述  : 处理扫描请求的总入口
1729  输入参数  : pst_mac_device: 指向device结构体
1730              p_params: 本次扫描请求的参数
1731  修改历史      :
1732   1.日    期   : 2015年2月5日
1733     作    者   : HiSilicon
1734     修改内容   : 新生成函数
1735 **************************************************************************** */
hmac_scan_proc_scan_req_event(hmac_vap_stru * hmac_vap,mac_scan_req_stru * scan_params)1736 hi_u32 hmac_scan_proc_scan_req_event(hmac_vap_stru *hmac_vap, mac_scan_req_stru *scan_params)
1737 {
1738     hmac_device_stru *hmac_dev = hmac_get_device_stru();
1739     mac_device_stru *mac_dev = mac_res_get_dev();
1740     hmac_scan_record_stru *scan_record = &(hmac_dev->scan_mgmt.scan_record_mgmt);
1741     hi_u8 is_random_mac_addr_scan;
1742 
1743     /* 异常判断: 扫描的信道个数为0 */
1744     if (scan_params->channel_nums == 0) {
1745         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scan_req_event::channel_nums=0.}");
1746         return HI_FAIL;
1747     }
1748 
1749     /* 更新此次扫描请求的扫描参数 */
1750     is_random_mac_addr_scan = hmac_dev->scan_mgmt.is_random_mac_addr_scan;
1751     if (scan_params->scan_func == MAC_SCAN_FUNC_P2P_LISTEN) {
1752         is_random_mac_addr_scan = HI_FALSE;
1753     }
1754     if (hmac_scan_update_scan_params(hmac_vap, scan_params, is_random_mac_addr_scan) != HI_SUCCESS) {
1755         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scan_req_event::update scan mode failed.}");
1756         return HI_FAIL;
1757     }
1758 
1759     /* 检测是否符合发起扫描请求的条件,如果不符合,直接返回 */
1760     if (hmac_scan_check_is_dispatch_scan_req(hmac_vap, hmac_dev) != HI_SUCCESS) {
1761         if (scan_params->scan_func == MAC_SCAN_FUNC_P2P_LISTEN) {
1762             mac_vap_state_change(hmac_vap->base_vap, mac_dev->p2p_info.last_vap_state);
1763         }
1764         oam_warning_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_scan_req_event:: can't dispatch scan req.}");
1765         return HI_FAIL;
1766     }
1767 
1768     /* 设置扫描模块处于扫描状态,其它扫描请求将丢弃 */
1769     hmac_dev->scan_mgmt.is_scanning = HI_TRUE;
1770     /* 处理上一次扫描记录,目前直接清楚上一次结果,后续可能需要老化时间处理 */
1771     hmac_scan_proc_last_scan_record(hmac_dev);
1772     /* 记录扫描发起者的信息,某些模块回调函数使用 */
1773     scan_record->vap_id = scan_params->vap_id;
1774     scan_record->chan_numbers = scan_params->channel_nums;
1775     scan_record->fn_cb = scan_params->fn_cb;
1776 
1777     if (is_ap(hmac_vap->base_vap)) {
1778         oam_warning_log1(0, 0, "{hmac_scan_proc_scan_req_event::save vap_state:%d}", hmac_vap->base_vap->vap_state);
1779         scan_record->vap_last_state = hmac_vap->base_vap->vap_state;
1780     }
1781 
1782     scan_record->ull_cookie = scan_params->ull_cookie;
1783     /* 如果发起扫描的vap的模式为sta,并且,其关联状态为非up状态,且非p2p监听状态,则切换其扫描状态 */
1784     if (is_sta(hmac_vap->base_vap) && (scan_params->scan_func != MAC_SCAN_FUNC_P2P_LISTEN)) {
1785         if (hmac_vap->base_vap->vap_state != MAC_VAP_STATE_UP) {
1786             /* 切换vap的状态为WAIT_SCAN状态 */
1787             hmac_fsm_change_state(hmac_vap, MAC_VAP_STATE_STA_WAIT_SCAN);
1788         } else {
1789             /* 背景扫描时需要进行帧过滤的配置 */
1790             hmac_vap->base_vap->vap_state = MAC_VAP_STATE_STA_WAIT_SCAN;
1791             hmac_set_rx_filter_value(hmac_vap->base_vap);
1792             hmac_vap->base_vap->vap_state = MAC_VAP_STATE_UP;
1793         }
1794     }
1795 
1796     /* AP的启动扫描做特殊处理,当hostapd下发扫描请求时,VAP还处于INIT状态 */
1797     if (is_ap(hmac_vap->base_vap) && (hmac_vap->base_vap->vap_state == MAC_VAP_STATE_INIT)) {
1798         hmac_fsm_change_state(hmac_vap, MAC_VAP_STATE_AP_WAIT_START);
1799     }
1800 
1801     return hmac_scan_dispatch_req_event(hmac_vap, scan_params);
1802 }
1803 
1804 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
1805 /* ****************************************************************************
1806  功能描述  : 处理pno调度扫描请求的入口
1807  输入参数  : pst_mac_device: 指向device结构体
1808              p_params: 本次扫描请求的参数
1809  修改历史      :
1810   1.日    期   : 2015年6月9日
1811     作    者   : HiSilicon
1812     修改内容   : 新生成函数
1813 **************************************************************************** */
hmac_scan_proc_sched_scan_req_event(const hmac_vap_stru * hmac_vap,const mac_pno_scan_stru * pno_scan_params)1814 hi_u32 hmac_scan_proc_sched_scan_req_event(const hmac_vap_stru *hmac_vap, const mac_pno_scan_stru *pno_scan_params)
1815 {
1816     frw_event_mem_stru *event_mem = HI_NULL;
1817     frw_event_stru *event = HI_NULL;
1818     hmac_device_stru *hmac_dev = HI_NULL;
1819     hmac_scan_record_stru *scan_record = HI_NULL;
1820     hi_u32 ret;
1821 
1822     /* 判断PNO调度扫描下发的过滤的ssid个数小于等于0 */
1823     if (pno_scan_params->l_ssid_count <= 0) {
1824         oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_SCAN,
1825             "{hmac_scan_proc_sched_scan_req_event::ssid_count <=0.}");
1826         return HI_FAIL;
1827     }
1828 
1829     /* 获取hmac device */
1830     hmac_dev = hmac_get_device_stru();
1831     /* 检测是否符合发起扫描请求的条件,如果不符合,直接返回 */
1832     ret = hmac_scan_check_is_dispatch_scan_req(hmac_vap, hmac_dev);
1833     if (ret != HI_SUCCESS) {
1834         oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_SCAN,
1835             "{hmac_scan_proc_sched_scan_req_event::Because of error[%d], can't dispatch scan req.}", ret);
1836         return ret;
1837     }
1838 
1839     /* 清空上一次的扫描结果 */
1840     hmac_scan_proc_last_scan_record(hmac_dev);
1841 
1842     /* 记录扫描发起者的信息,某些模块回调函数使用 */
1843     scan_record = &(hmac_dev->scan_mgmt.scan_record_mgmt);
1844     scan_record->vap_id = hmac_vap->base_vap->vap_id;
1845     scan_record->fn_cb = pno_scan_params->fn_cb;
1846 
1847     /* 抛扫描请求事件到DMAC, 申请事件内存 */
1848     event_mem = frw_event_alloc(sizeof(uintptr_t));
1849     if (event_mem == HI_NULL) {
1850         oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_SCAN,
1851             "{hmac_scan_proc_sched_scan_req_event::event_mem null.}");
1852         return HI_ERR_CODE_PTR_NULL;
1853     }
1854 
1855     /* 填写事件 */
1856     event = (frw_event_stru *)event_mem->puc_data;
1857 
1858     frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_WLAN_CTX, DMAC_WLAN_CTX_EVENT_SUB_TYPE_SCHED_SCAN_REQ,
1859         sizeof(uintptr_t), FRW_EVENT_PIPELINE_STAGE_1, hmac_vap->base_vap->vap_id);
1860 
1861     /* 事件data域内携带PNO扫描请求参数 */
1862     if (memcpy_s(frw_get_event_payload(event_mem), sizeof(mac_pno_scan_stru *), (hi_u8 *)&pno_scan_params,
1863         sizeof(mac_pno_scan_stru *)) != EOK) {
1864         frw_event_free(event_mem);
1865         oam_error_log0(0, OAM_SF_CFG, "hmac_scan_proc_sched_scan_req_event:: pst_pno_scan_params memcpy_s fail.");
1866         return HI_FAIL;
1867     }
1868 
1869     /* 分发事件 */
1870     hcc_hmac_tx_control_event(event_mem, sizeof(uintptr_t));
1871     frw_event_free(event_mem);
1872 
1873     return HI_SUCCESS;
1874 }
1875 #endif
1876 
1877 /* ****************************************************************************
1878  功能描述  : 扫描模块初始化
1879  修改历史      :
1880   1.日    期   : 2015年5月14日
1881     作    者   : HiSilicon
1882     修改内容   : 新生成函数
1883 **************************************************************************** */
hmac_scan_init(hmac_device_stru * hmac_dev)1884 hi_void hmac_scan_init(hmac_device_stru *hmac_dev)
1885 {
1886     hmac_scan_stru *scan_mgmt = HI_NULL;
1887     hmac_bss_mgmt_stru *bss_mgmt = HI_NULL;
1888 
1889     /* 初始化扫描管理结构体信息 */
1890     scan_mgmt = &(hmac_dev->scan_mgmt);
1891     scan_mgmt->is_scanning = HI_FALSE;
1892     scan_mgmt->request = HI_NULL;
1893 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
1894     scan_mgmt->sched_scan_req = HI_NULL;
1895 #endif
1896     scan_mgmt->complete = HI_TRUE;
1897 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
1898     scan_mgmt->sched_scan_complete = HI_TRUE;
1899     oal_spin_lock_init(&scan_mgmt->st_scan_request_spinlock);
1900 #endif
1901     scan_mgmt->scan_record_mgmt.vap_last_state = MAC_VAP_STATE_BUTT;
1902     scan_mgmt->is_random_mac_addr_scan = HI_FALSE; /* 随机mac 扫描开关,默认关闭 */
1903     scan_mgmt->scan_record_mgmt.is_any_scan = HI_FALSE;
1904     /* 初始化bss管理结果链表和锁 */
1905     bss_mgmt = &(scan_mgmt->scan_record_mgmt.bss_mgmt);
1906     hi_list_init(&(bss_mgmt->bss_list_head));
1907     oal_spin_lock_init(&bss_mgmt->st_lock);
1908 
1909     /* 初始化内核下发扫描request资源锁 */
1910     return;
1911 }
1912 
1913 /* ****************************************************************************
1914  功能描述  : hmac扫描模块退出
1915  修改历史      :
1916   1.日    期   : 2015年5月14日
1917     作    者   : HiSilicon
1918     修改内容   : 新生成函数
1919 **************************************************************************** */
hmac_scan_exit(hmac_device_stru * hmac_dev)1920 hi_void hmac_scan_exit(hmac_device_stru *hmac_dev)
1921 {
1922     hmac_scan_stru *scan_mgmt = HI_NULL;
1923 
1924     scan_mgmt = &(hmac_dev->scan_mgmt);
1925 
1926     /* 清空扫描记录信息 */
1927     hmac_scan_clean_scan_record(&scan_mgmt->scan_record_mgmt);
1928 
1929     /* 删除扫描超时保护定时器 */
1930     if (scan_mgmt->scan_timeout.is_registerd == HI_TRUE) {
1931         frw_timer_immediate_destroy_timer(&(scan_mgmt->scan_timeout));
1932     }
1933 
1934     /* 清除扫描管理结构体信息 */
1935     if (scan_mgmt->request == HI_NULL) {
1936         return;
1937     }
1938     if (scan_mgmt->request->ie != HI_NULL) {
1939         oal_free(scan_mgmt->request->ie);
1940         scan_mgmt->request->ie = HI_NULL;
1941     }
1942     if (scan_mgmt->request->ssids != HI_NULL) {
1943         oal_free(scan_mgmt->request->ssids);
1944         scan_mgmt->request->ssids = HI_NULL;
1945     }
1946     oal_free(scan_mgmt->request);
1947 
1948     scan_mgmt->request = HI_NULL;
1949     scan_mgmt->is_scanning = HI_FALSE;
1950     scan_mgmt->complete = HI_TRUE;
1951 }
1952 #ifdef _PRE_WLAN_FEATURE_SCAN_BY_SSID
hmac_scan_proc_check_prefix_ssid(hmac_scanned_bss_info * scanned_bss,const oal_cfg80211_ssid_stru * req_ssid,const hi_u8 * puc_ssid,hi_u8 ssid_len)1953 static hi_void hmac_scan_proc_check_prefix_ssid(hmac_scanned_bss_info *scanned_bss,
1954     const oal_cfg80211_ssid_stru *req_ssid, const hi_u8 *puc_ssid, hi_u8 ssid_len)
1955 {
1956     hi_u8 req_ssid_len;
1957     hi_u8 loop;
1958 
1959     if (oal_unlikely(puc_ssid == HI_NULL)) {
1960         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_proc_check_prefix_ssid::puc_ssid null.}");
1961         return;
1962     }
1963 
1964     if (oal_unlikely(req_ssid == HI_NULL)) {
1965         return;
1966     }
1967     req_ssid_len = req_ssid[0].ssid_len;
1968     if (req_ssid_len <= ssid_len) {
1969         for (loop = 0; loop < req_ssid_len; loop++) {
1970             if (req_ssid[0].ssid[loop] != puc_ssid[loop]) {
1971                 break;
1972             }
1973         }
1974         if (loop == req_ssid_len) {
1975             return;
1976         }
1977     }
1978 
1979     scanned_bss->bss_dscr_info.need_drop = HI_TRUE;
1980 }
1981 
1982 /* ****************************************************************************
1983  功能描述  : hmac扫描模块上报前判断beacon/probe rsp中的ssid与指定ssid的扫描请求是否一致
1984  输入参数  : hmac_scanned_bss_info *pst_scanned_bss :扫描信息结构体
1985                             hi_u8 *puc_ssid: 帧中的ssid
1986                             hi_u8 uc_ssid_len:帧中ssid的长度
1987  修改历史      :
1988   1.日    期   : 2019年2月26日
1989     作    者   : HiSilicon
1990     修改内容   : 新生成函数
1991 **************************************************************************** */
hmac_scan_proc_check_ssid(hmac_scanned_bss_info * scanned_bss,const hi_u8 * puc_ssid,hi_u8 ssid_len)1992 hi_void hmac_scan_proc_check_ssid(hmac_scanned_bss_info *scanned_bss, const hi_u8 *puc_ssid, hi_u8 ssid_len)
1993 {
1994     hmac_scan_stru *scan_mgmt = HI_NULL;
1995     hmac_device_stru *hmac_dev = HI_NULL;
1996     hi_u32 l_index;
1997     hi_u8 req_ssid_len;
1998     oal_cfg80211_ssid_stru *ssids = HI_NULL;
1999 
2000     /* 获取hmac device 结构 */
2001     hmac_dev = hmac_get_device_stru();
2002     scan_mgmt = &(hmac_dev->scan_mgmt);
2003     if (scan_mgmt->request == HI_NULL) {
2004         return;
2005     }
2006 
2007     /* 当下发的ssid中有通配ssid时,不进行任何过滤 */
2008     for (l_index = 0; l_index < scan_mgmt->request->n_ssids; l_index++) {
2009         if (scan_mgmt->request->ssids[l_index].ssid[0] == '\0') {
2010             return;
2011         }
2012     }
2013 
2014     if (puc_ssid == HI_NULL) {
2015         scanned_bss->bss_dscr_info.need_drop = HI_TRUE;
2016         return;
2017     }
2018 
2019     ssids = scan_mgmt->request->ssids;
2020     hi_u32 l_ssid_num = scan_mgmt->request->n_ssids;
2021 
2022     /* 如果是前缀ssid扫描,则执行前缀过滤规则 */
2023     if (scan_mgmt->request->prefix_ssid_scan_flag == HI_TRUE) {
2024         hmac_scan_proc_check_prefix_ssid(scanned_bss, ssids, puc_ssid, ssid_len);
2025         return;
2026     }
2027     /* pst_request 在驱动判断指定ssid扫描最大个数之前赋值,需在这里进行检查 */
2028     /* 如果未指定ssid,则直接返回 */
2029     if (l_ssid_num == 0) {
2030         return;
2031     }
2032 
2033     if (l_ssid_num > WLAN_SCAN_REQ_MAX_BSS) {
2034         /* 如果用户下发的指定ssid的个数大于驱动支持的最大个数,则取驱动支持的指定ssid的最大个数 */
2035         l_ssid_num = WLAN_SCAN_REQ_MAX_BSS;
2036     }
2037 
2038     for (l_index = 0; l_index < l_ssid_num; l_index++) {
2039         req_ssid_len = ssids[l_index].ssid_len;
2040         if (req_ssid_len > OAL_IEEE80211_MAX_SSID_LEN) {
2041             req_ssid_len = OAL_IEEE80211_MAX_SSID_LEN;
2042         }
2043 
2044         if (req_ssid_len != ssid_len) {
2045             continue;
2046         }
2047 
2048         if (memcmp(puc_ssid, ssids[l_index].ssid, req_ssid_len) != 0) {
2049             continue;
2050         } else {
2051             return;
2052         }
2053     }
2054 
2055     scanned_bss->bss_dscr_info.need_drop = HI_TRUE;
2056     return;
2057 }
2058 #endif /* #ifdef _PRE_WLAN_FEATURE_SCAN_BY_SSID */
2059 
hmac_scan_clean_result(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)2060 hi_u32 hmac_scan_clean_result(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
2061 {
2062     hmac_device_stru *hmac_dev = hmac_get_device_stru();
2063 
2064     hi_unref_param(mac_vap);
2065     hi_unref_param(us_len);
2066     hi_unref_param(puc_param);
2067 
2068     if (hmac_dev == HI_NULL) {
2069         oam_error_log0(0, OAM_SF_SCAN, "{hmac_scan_clean_result::hmac_dev null.}");
2070         return HI_ERR_CODE_PTR_NULL;
2071     }
2072     oam_info_log0(0, OAM_SF_SCAN, "{hmac_scan_clean_result::clean driver scan results.}");
2073     hmac_scan_clean_expire_scanned_bss(&(hmac_dev->scan_mgmt.scan_record_mgmt), HI_TRUE);
2074     return HI_SUCCESS;
2075 }
2076 
2077 #ifdef __cplusplus
2078 #if __cplusplus
2079 }
2080 #endif
2081 #endif
2082