• 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_frame.h"
24 #include "mac_vap.h"
25 #include "mac_device.h"
26 #include "mac_resource.h"
27 #include "mac_regdomain.h"
28 #include "mac_data.h"
29 #include "frw_main.h"
30 
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif
36 /* ****************************************************************************
37   全局变量定义
38 **************************************************************************** */
39 #define __WIFI_ROM_SECTION__ /* 代码ROM段起始位置 */
40 /* ****************************************************************************
41   函数实现
42 **************************************************************************** */
43 /* ****************************************************************************
44  功能描述  : 查找指定的IE
45  输入参数  : [1]eid
46              [2]puc_ies
47              [3]l_len
48  返 回 值  : const hi_u8 *
49 **************************************************************************** */
mac_find_ie(hi_u8 eid,hi_u8 * puc_ies,hi_u32 l_len)50 WIFI_ROM_TEXT hi_u8 *mac_find_ie(hi_u8 eid, hi_u8 *puc_ies, hi_u32 l_len)
51 {
52     if (puc_ies == HI_NULL) {
53         return HI_NULL;
54     }
55     while (l_len > MAC_IE_HDR_LEN && puc_ies[0] != eid) {
56         if (l_len < (hi_u32)(puc_ies[1] + MAC_IE_HDR_LEN)) {
57             break;
58         }
59         l_len -= puc_ies[1] + MAC_IE_HDR_LEN;
60         puc_ies += puc_ies[1] + MAC_IE_HDR_LEN;
61     }
62     if ((l_len < MAC_IE_HDR_LEN) || (l_len < (hi_u32)(MAC_IE_HDR_LEN + puc_ies[1])) ||
63         ((l_len == MAC_IE_HDR_LEN) && (puc_ies[0] != eid))) {
64         return HI_NULL;
65     }
66     return puc_ies;
67 }
68 
69 /* ****************************************************************************
70  功能描述  : 查找厂家自定义 IE
71  输入参数  : [1]oui
72              [2]oui_type
73              [3]puc_ies
74              [4]l_len
75  返 回 值  : const hi_u8 * 摘自linux 内核
76 **************************************************************************** */
mac_find_vendor_ie(hi_u32 oui,hi_u8 oui_type,hi_u8 * puc_ies,hi_s32 l_len)77 WIFI_ROM_TEXT hi_u8 *mac_find_vendor_ie(hi_u32 oui, hi_u8 oui_type, hi_u8 *puc_ies, hi_s32 l_len)
78 {
79     mac_ieee80211_vendor_ie_stru *ie = HI_NULL;
80     hi_u8 *puc_pos = HI_NULL;
81     hi_u8 *puc_end = HI_NULL;
82     hi_u32 ie_oui;
83 
84     if (puc_ies == HI_NULL) {
85         return HI_NULL;
86     }
87     puc_pos = puc_ies;
88     puc_end = puc_ies + l_len;
89     while (puc_pos < puc_end) {
90         puc_pos = mac_find_ie(MAC_EID_VENDOR, puc_pos, (hi_u32)(puc_end - puc_pos));
91         if (puc_pos == HI_NULL) {
92             return HI_NULL;
93         }
94         ie = (mac_ieee80211_vendor_ie_stru *)puc_pos;
95         if (ie->len >= (sizeof(mac_ieee80211_vendor_ie_stru) - MAC_IE_HDR_LEN)) {
96             ie_oui = (ie->auc_oui[0] << 16) |           /* auc_oui[0]存于最高16bit */
97                 (ie->auc_oui[1] << 8) | ie->auc_oui[2]; /* auc_oui[1]存于次高8bit,auc_oui[2]存于最低8bit */
98             if ((ie_oui == oui) && (ie->oui_type == oui_type)) {
99                 return puc_pos;
100             }
101         }
102         puc_pos += 2 + ie->len; /* 每次循环偏移(2 + ie->len)byte */
103     }
104     return HI_NULL;
105 }
106 
107 /* ****************************************************************************
108  功能描述  : 作为ap时,根据mib值,设置cap info
109  输入参数  : pst_vap      : 指向vap
110              puc_cap_info : 指向存储能力位信息的buffer
111  修改历史      :
112   1.日    期   : 2013年4月9日
113     作    者   : HiSilicon
114     修改内容   : 新生成函数
115 **************************************************************************** */
mac_set_cap_info_ap(hi_void * vap,hi_u8 * puc_cap_info)116 WIFI_ROM_TEXT hi_void mac_set_cap_info_ap(hi_void *vap, hi_u8 *puc_cap_info)
117 {
118     mac_cap_info_stru  *cap_info = (mac_cap_info_stru *)puc_cap_info;
119     mac_vap_stru       *mac_vap  = (mac_vap_stru *)vap;
120 
121     wlan_mib_ieee802dot11_stru *mib = mac_vap->mib_info;
122     /* *************************************************************************
123          -------------------------------------------------------------------
124          |B0 |B1  |B2        |B3    |B4     |B5      |B6  |B7     |B8      |
125          -------------------------------------------------------------------
126          |ESS|IBSS|CFPollable|CFPReq|Privacy|Preamble|PBCC|Agility|SpecMgmt|
127          -------------------------------------------------------------------
128          |B9 |B10      |B11 |B12     |B13      |B14        |B15            |
129          -------------------------------------------------------------------
130          |QoS|ShortSlot|APSD|RM      |DSSS-OFDM|Delayed BA |Immediate BA   |
131          -------------------------------------------------------------------
132     ************************************************************************** */
133     /* 初始清零 */
134     puc_cap_info[0] = 0;
135     puc_cap_info[1] = 0;
136 
137     if (WLAN_MIB_DESIRED_BSSTYPE_INDEPENDENT == mib->wlan_mib_sta_config.dot11_desired_bss_type) {
138         cap_info->ibss = 1;
139     } else if (WLAN_MIB_DESIRED_BSSTYPE_INFRA == mib->wlan_mib_sta_config.dot11_desired_bss_type) {
140         cap_info->ess = 1;
141     }
142 
143     /* The Privacy bit is set if WEP is enabled */
144     cap_info->privacy = mib->wlan_mib_privacy.dot11_privacy_invoked;
145     /* preamble */
146     cap_info->short_preamble = mac_mib_get_short_preamble_option_implemented(mac_vap);
147     /* packet binary convolutional code (PBCC) modulation */
148     cap_info->pbcc = mib->phy_hrdsss.dot11_pbcc_option_implemented;
149     /* Channel Agility */
150     cap_info->channel_agility = mib->phy_hrdsss.dot11_channel_agility_present;
151     /* Spectrum Management */
152     cap_info->spectrum_mgmt = mib->wlan_mib_sta_config.dot11_spectrum_management_required;
153     /* QoS subfield */
154     cap_info->qos = mib->wlan_mib_sta_config.dot11_qos_option_implemented;
155     /* short slot */
156     cap_info->short_slot_time = 1;
157     /* APSD */
158     cap_info->apsd = mib->wlan_mib_sta_config.dot11_apsd_option_implemented;
159     /* Radio Measurement */
160     cap_info->radio_measurement = mib->wlan_mib_sta_config.dot11_radio_measurement_activated;
161     /* DSSS-OFDM */
162     cap_info->dsss_ofdm = HI_FALSE;
163     /* Delayed BA */
164     cap_info->delayed_block_ack = mib->wlan_mib_sta_config.dot11_delayed_block_ack_option_implemented;
165     /* Immediate Block Ack 参考STA及AP标杆,此能力一直为0,实际通过addba协商。此处修改为标杆一致。mib值不修改 */
166     cap_info->immediate_block_ack = 0;
167 }
168 
169 WIFI_ROM_RODATA const hi_char g_dmac_p2p_wildcard_ssid[MAC_P2P_WILDCARD_SSID] = "DIRECT-";
170 /* ****************************************************************************
171  功能描述  : 设置ssid ie
172  输入参数  : pst_vap: 指向vap
173              puc_buffer : 指向buffer
174  输出参数  : puc_ie_len : element的长度
175  修改历史      :
176   1.日    期   : 2013年4月9日
177     作    者   : HiSilicon
178     修改内容   : 新生成函数
179 **************************************************************************** */
mac_set_ssid_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len,hi_u16 us_frm_type)180 WIFI_ROM_TEXT hi_u16 mac_set_ssid_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len, hi_u16 us_frm_type)
181 {
182     hi_u8 *puc_ssid = HI_NULL;
183     hi_u8 ssid_len;
184     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
185 
186     /* **************************************************************************
187                     ----------------------------
188                     |Element ID | Length | SSID|
189                     ----------------------------
190            Octets:  |1          | 1      | 0~32|
191                     ----------------------------
192     ************************************************************************** */
193     /* **************************************************************************
194       A SSID  field  of length 0 is  used  within Probe
195       Request management frames to indicate the wildcard SSID.
196     ************************************************************************** */
197     *puc_buffer = MAC_EID_SSID;
198 
199     /* 只有beacon会隐藏ssid */
200     if ((mac_vap->cap_flag.hide_ssid) && (WLAN_FC0_SUBTYPE_BEACON == us_frm_type)) {
201         /* ssid len */
202         *(puc_buffer + 1) = 0;
203         *puc_ie_len = MAC_IE_HDR_LEN;
204         return 0;
205     }
206 
207     if (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA && mac_vap->p2p_mode == WLAN_P2P_DEV_MODE) {
208         ssid_len = (hi_u8)sizeof(g_dmac_p2p_wildcard_ssid) - 1; /* 不包含'\0' */
209         *(puc_buffer + 1) = ssid_len;
210 
211         if (memcpy_s(puc_buffer + MAC_IE_HDR_LEN, ssid_len, g_dmac_p2p_wildcard_ssid, ssid_len) != EOK) {
212             oam_error_log0(0, OAM_SF_P2P, "{mac_set_ssid_ie::mem safe func err!}");
213             /* ssid len */
214             *(puc_buffer + 1) = 0;
215             *puc_ie_len = MAC_IE_HDR_LEN;
216             return 0;
217         }
218     } else {
219         puc_ssid = mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_desired_ssid;
220         ssid_len = (hi_u8)strlen((hi_char *)puc_ssid); /* 不包含'\0' */
221         *(puc_buffer + 1) = ssid_len;
222         if (memcpy_s(puc_buffer + MAC_IE_HDR_LEN, ssid_len, puc_ssid, ssid_len) != EOK) {
223             oam_error_log0(0, 0, "{mac_set_ssid_ie::mem safe func err!}");
224             /* ssid len */
225             *(puc_buffer + 1) = 0;
226             *puc_ie_len = MAC_IE_HDR_LEN;
227             return 0;
228         }
229     }
230     *puc_ie_len = ssid_len + MAC_IE_HDR_LEN;
231     return ssid_len;
232 }
233 
234 /* ****************************************************************************
235  功能描述  : 设置速率集
236  输入参数  : pst_vap: 指向vap
237              puc_buffer: 指向buffer
238  输出参数  : puc_ie_len: element的长度
239  修改历史      :
240   1.日    期   : 2013年4月11日
241     作    者   : HiSilicon
242     修改内容   : 新生成函数
243 **************************************************************************** */
mac_set_supported_rates_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)244 WIFI_ROM_TEXT hi_void mac_set_supported_rates_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
245 {
246     mac_vap_stru     *mac_vap   = (mac_vap_stru *)vap;
247     mac_rateset_stru *rates_set = HI_NULL;
248     hi_u8 nrates;
249     hi_u8 idx;
250 
251     rates_set = &(mac_vap->curr_sup_rates.rate);
252     /* *************************************************************************
253                         ---------------------------------------
254                         |Element ID | Length | Supported Rates|
255                         ---------------------------------------
256              Octets:    |1          | 1      | 1~8            |
257                         ---------------------------------------
258     The Information field is encoded as 1 to 8 octets, where each octet describes a single Supported
259     Rate or BSS membership selector.
260     ************************************************************************* */
261     puc_buffer[0] = MAC_EID_RATES;
262     nrates = rates_set->rs_nrates;
263     if (nrates > MAC_MAX_SUPRATES) {
264         nrates = MAC_MAX_SUPRATES;
265     }
266     for (idx = 0; idx < nrates; idx++) {
267         puc_buffer[MAC_IE_HDR_LEN + idx] = rates_set->ast_rs_rates[idx].mac_rate;
268     }
269     puc_buffer[1] = nrates;
270     *puc_ie_len = MAC_IE_HDR_LEN + nrates;
271 }
272 
273 #ifdef _PRE_WLAN_FEATURE_MESH_ROM
274 /* ****************************************************************************
275  功能描述  : Mesh填充回复给Mesh节点的rsn信息
276  输入参数  : pst_vap   : 指向vap
277              puc_buffer: 指向buffer
278              hi_u16 us_frm_type
279  输出参数  : puc_ie_len: element的长度
280  修改历史      :
281   1.日    期   : 2019年1月22日
282     作    者   : HiSilicon
283     修改内容   : 新生成函数
284 **************************************************************************** */
mac_set_rsn_mesh_cap(mac_rsn_cap_stru * rsn_cap,const mac_vap_stru * mac_vap)285 WIFI_ROM_TEXT hi_void mac_set_rsn_mesh_cap(mac_rsn_cap_stru *rsn_cap, const mac_vap_stru *mac_vap)
286 {
287     rsn_cap->mfpr        = mac_vap->mib_info->wlan_mib_privacy.dot11_rsnamfpr;
288     rsn_cap->mfpc        = mac_vap->mib_info->wlan_mib_privacy.dot11_rsnamfpc;
289     rsn_cap->pre_auth    =
290         mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_preauthentication_activated;
291     rsn_cap->no_pairwise = 0;
292     rsn_cap->ptska_relay_counter =
293         mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_number_of_ptksa_replay_counters_implemented;
294     rsn_cap->gtska_relay_counter =
295         mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_number_of_gtksa_replay_counters_implemented;
296 }
297 
mac_set_rsn_group_cipher_suite_field(const mac_vap_stru * mac_vap,hi_u8 * puc_buffer,hi_u16 us_frm_type,hi_u8 * puc_ie_len)298 WIFI_ROM_TEXT static hi_void mac_set_rsn_group_cipher_suite_field(const mac_vap_stru *mac_vap,
299     hi_u8 *puc_buffer, hi_u16 us_frm_type, hi_u8 *puc_ie_len)
300 {
301     hi_u8 auc_oui[MAC_OUI_LEN];
302     hi_u8 index = 0;
303 
304     if (us_frm_type == WLAN_FC0_SUBTYPE_PROBE_RSP) {
305         index = MAC_IE_HDR_LEN;
306         /* 设置RSN ie的EID */
307         puc_buffer[0] = MAC_EID_RSN;
308     } else if (us_frm_type == WLAN_FC0_SUBTYPE_BEACON) {
309         index = MAC_IE_VENDOR_SPEC_MESH_HDR_LEN;
310         puc_buffer[0] = MAC_EID_VENDOR;
311         auc_oui[0] = (hi_u8)MAC_WLAN_OUI_VENDOR0;
312         auc_oui[1] = (hi_u8)MAC_WLAN_OUI_VENDOR1;
313         auc_oui[2] = (hi_u8)MAC_WLAN_OUI_VENDOR2; /* auc_oui[2]赋值为MAC_WLAN_OUI_VENDOR2 */
314         if (memcpy_s(&puc_buffer[2], MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) { /* puc_buffer[2]赋值 */
315             return;
316         }
317         puc_buffer[5] = MAC_OUITYPE_MESH;             /* puc_buffer[5]赋值为MAC_OUITYPE_MESH */
318         puc_buffer[6] = MAC_OUISUBTYPE_MESH_HISI_RSN; /* puc_buffer[6]赋值为MAC_OUISUBTYPE_MESH_HISI_RSN */
319     }
320     auc_oui[0] = (hi_u8)MAC_WLAN_OUI_RSN0;
321     auc_oui[1] = (hi_u8)MAC_WLAN_OUI_RSN1;
322     auc_oui[2] = (hi_u8)MAC_WLAN_OUI_RSN2; /* auc_oui[2]赋值为MAC_WLAN_OUI_RSN2 */
323     /* 设置version字段 */
324     puc_buffer[index++] = MAC_RSN_IE_VERSION;
325     puc_buffer[index++] = 0;
326 
327     /* 设置Group Cipher Suite */
328     /* *********************************************************************** */
329     /*                  Group Cipher Suite                                   */
330     /* --------------------------------------------------------------------- */
331     /*                  | OUI | Suite type |                                 */
332     /* --------------------------------------------------------------------- */
333     /*          Octets: |  3  |     1      |                                 */
334     /* --------------------------------------------------------------------- */
335     /* *********************************************************************** */
336     if (memcpy_s(&puc_buffer[index], MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) {
337         return;
338     }
339     index += MAC_OUI_LEN;
340     puc_buffer[index++] = mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher;
341     /* 设置成对加密套件数量 */
342     puc_buffer[index++] = 1;
343     puc_buffer[index++] = 0;
344     if (memcpy_s(&puc_buffer[index], MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) {
345         return;
346     }
347     index += MAC_OUI_LEN;
348     puc_buffer[index++] = WLAN_80211_CIPHER_SUITE_CCMP; /* Mesh 下只使用CCMP-128 ,暂不考虑其他 */
349     /* 设置认证套件数 (Mesh下只支持SAE) */
350     puc_buffer[index++] = 1;
351     puc_buffer[index++] = 0;
352     /* 根据MIB 值,设置认证套件内容 */
353     if (memcpy_s(&puc_buffer[index], MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) {
354         return;
355     }
356     index += MAC_OUI_LEN;
357     puc_buffer[index++] = WLAN_AUTH_SUITE_SAE_SHA256; /* MESH 下只支持SAE */
358 
359     *puc_ie_len = index;
360 }
361 
mac_set_rsn_mesh_ie_authenticator(hi_void * vap,hi_u8 * puc_buffer,hi_u16 us_frm_type,hi_u8 * puc_ie_len)362 WIFI_ROM_TEXT hi_void mac_set_rsn_mesh_ie_authenticator(hi_void *vap, hi_u8 *puc_buffer, hi_u16 us_frm_type,
363     hi_u8 *puc_ie_len)
364 {
365     mac_vap_stru        *mac_vap = (mac_vap_stru *)vap;
366     mac_rsn_cap_stru    *rsn_cap = HI_NULL;
367     hi_u8               index = 0;
368     hi_u8               ie_len = 0;
369 
370     if (mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_activated != HI_TRUE) {
371         *puc_ie_len = 0;
372         return;
373     }
374     if (mac_vap->mib_info->wlan_mib_mesh_sta_cfg.dot11_mesh_security_activated != HI_TRUE) {
375         *puc_ie_len = 0;
376         return;
377     }
378     if (mac_vap->mib_info->wlan_mib_mesh_sta_cfg.dot11_mesh_active_authentication_protocol !=
379         MAC_MIB_AUTH_PROTOCOL_SAE) {
380         *puc_ie_len = 0;
381         return;
382     }
383     /* *********************************************************************** */
384     /*                  RSN Element Format              */
385     /* --------------------------------------------------------------------- */
386     /* |Element ID | Length | Version | Group Cipher Suite | Pairwise Cipher */
387     /* --------------------------------------------------------------------- */
388     /* | 1         | 1      | 2       |      4             |     2           */
389     /* --------------------------------------------------------------------- */
390     /* --------------------------------------------------------------------- */
391     /* Suite | Pairwise Cipher Suite List | AKM Suite Count | AKM Suite List */
392     /* --------------------------------------------------------------------- */
393     /*       | 4-m                        |     2          | 4-n             */
394     /* --------------------------------------------------------------------- */
395     /* --------------------------------------------------------------------- */
396     /* |RSN Capabilities|PMKID Count|PMKID List|Group Management Cipher Suite */
397     /* --------------------------------------------------------------------- */
398     /* |    2           |    2      |16 -s     |         4                 | */
399     /* --------------------------------------------------------------------- */
400     /*                                                                       */
401     /* *********************************************************************** */
402     mac_set_rsn_group_cipher_suite_field(mac_vap, &puc_buffer[index], us_frm_type, &ie_len);
403     index += ie_len;
404     /* 设置 RSN Capabilities字段 */
405     /* *********************************************************************** */
406     /* --------------------------------------------------------------------- */
407     /* | B15 - B6  |  B5 - B4      | B3 - B2     |       B1    |     B0    | */
408     /* --------------------------------------------------------------------- */
409     /* | Reserved  |  GTSKA Replay | PTSKA Replay| No Pairwise | Pre - Auth| */
410     /* |           |    Counter    |   Counter   |             |           | */
411     /* --------------------------------------------------------------------- */
412     /*                                                                       */
413     /* *********************************************************************** */
414     /* 设置RSN Capabilities 值,包括Pre_Auth, no_pairwise */
415     /* Replay counters (PTKSA and GTKSA)                    */
416     rsn_cap = (mac_rsn_cap_stru *)(puc_buffer + index);
417     if (memset_s(rsn_cap, sizeof(mac_rsn_cap_stru), 0, sizeof(mac_rsn_cap_stru)) != EOK) {
418         return;
419     }
420     index += MAC_RSN_CAP_LEN;
421 
422     mac_set_rsn_mesh_cap(rsn_cap, mac_vap);
423 
424     /* 设置RSN element的长度 */
425     puc_buffer[1] = index - MAC_IE_HDR_LEN;
426 
427     *puc_ie_len = index;
428 }
429 
430 /* ****************************************************************************
431  功能描述  : 查找mesh自定义 IE(精确到subtype)
432  输入参数  : [1]oui_sub_type,
433              [2]puc_ies,
434              [3]l_len
435  返 回 值  : hi_u8 *
436 **************************************************************************** */
mac_find_mesh_vendor_ie(hi_u8 oui_sub_type,hi_u8 * puc_ies,hi_u32 l_len)437 WIFI_ROM_TEXT hi_u8 *mac_find_mesh_vendor_ie(hi_u8 oui_sub_type, hi_u8 *puc_ies, hi_u32 l_len)
438 {
439     mac_ieee80211_vendor_ie_stru *ie = HI_NULL;
440     hi_u8 *puc_pos = HI_NULL;
441     hi_u8 *puc_end = HI_NULL;
442     hi_u32 ie_oui;
443 
444     puc_pos = puc_ies;
445     puc_end = puc_ies + l_len;
446     while (puc_pos < puc_end) {
447         puc_pos = mac_find_ie(MAC_EID_VENDOR, puc_pos, (hi_u32)(puc_end - puc_pos));
448         if (puc_pos == HI_NULL) {
449             return HI_NULL;
450         }
451         ie = (mac_ieee80211_vendor_ie_stru *)puc_pos;
452         if (ie->len > (sizeof(mac_ieee80211_vendor_ie_stru) - MAC_IE_HDR_LEN)) {
453             ie_oui = (ie->auc_oui[0] << 16) |           /* auc_oui[0]存于最高16bit */
454                 (ie->auc_oui[1] << 8) | ie->auc_oui[2]; /* auc_oui[1]存于次高8bit,auc_oui[2]存于最低8bit */
455             if ((ie_oui == MAC_WLAN_OUI_VENDOR) && (ie->oui_type == MAC_OUITYPE_MESH) &&
456                 (puc_pos[MAC_IE_VENDOR_SPEC_MESH_SUBTYPE_POS] == oui_sub_type)) {
457                 return puc_pos;
458             }
459         }
460         puc_pos += 2 + ie->len; /* 每次偏移(2 + ie->len) byte */
461     }
462     return HI_NULL;
463 }
464 
465 /* ****************************************************************************
466  功能描述  : 接收时检查私有字段,判断包的发送端是否为Mesh VAP
467  输入参数  :
468              [1]puc_buffer
469              [2]puc_ie_len
470  返 回 值  : hi_u8
471 **************************************************************************** */
mac_check_is_mesh_vap(hi_u8 * puc_buffer,hi_u8 puc_ie_len)472 WIFI_ROM_TEXT hi_u8 mac_check_is_mesh_vap(hi_u8 *puc_buffer, hi_u8 puc_ie_len)
473 {
474     hi_u8 *hisi_beacon_ie = HI_NULL;
475     hi_u8 *hisi_prb_rsp_ie = HI_NULL;
476 
477     hisi_beacon_ie = mac_find_mesh_vendor_ie(MAC_OUISUBTYPE_MESH_HISI_BEACON, puc_buffer, puc_ie_len);
478     hisi_prb_rsp_ie = mac_find_mesh_vendor_ie(MAC_OUISUBTYPE_MESH_HISI_RSP, puc_buffer, puc_ie_len);
479     if ((hisi_beacon_ie == HI_NULL) && (hisi_prb_rsp_ie == HI_NULL)) {
480         return HI_FALSE;
481     }
482     return HI_TRUE;
483 }
484 
485 /* ****************************************************************************
486  功能描述  : 获取beacon帧中的meshid(私有字段中)
487  输入参数  : puc_beacon_body:Beacon or probe rsp帧体
488                             hi_s32 l_frame_body_len:帧体长度
489  输出参数  : puc_meshid_len:meshid长度
490  返 回 值  : 指向meshid
491  修改历史      :
492   1.日    期   : 2019年4月17日
493     作    者   : HiSilicon
494     修改内容   : 新生成函数
495 
496 **************************************************************************** */
mac_get_meshid(hi_u8 * puc_beacon_body,hi_s32 l_frame_body_len,hi_u8 * puc_meshid_len)497 WIFI_ROM_TEXT hi_u8 *mac_get_meshid(hi_u8 *puc_beacon_body, hi_s32 l_frame_body_len, hi_u8 *puc_meshid_len)
498 {
499     const hi_u8 *puc_meshid_ie = HI_NULL;
500     hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
501 
502     /* *********************************************************************** */
503     /*                       Beacon Frame - Frame Body                       */
504     /* --------------------------------------------------------------------- */
505     /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm   | */
506     /* --------------------------------------------------------------------- */
507     /* |8         |2         |2       |2-34 |3-10     |3        |4-256     | */
508     /* --------------------------------------------------------------------- */
509     /*                                                                       */
510     /* *********************************************************************** */
511     /* **************************************************************************
512          Vendor Spec |Length| OUI|TYPE|SUBTYPE|MESHID LEN|MESHID|
513            1                |1        |3    |1     |1           |  1               |Var       |
514     ************************************************************************** */
515     /* meshid的长度初始赋值为0 */
516     *puc_meshid_len = 0;
517 
518     /* 检测beacon帧或者probe rsp帧的长度的合法性 */
519     if (l_frame_body_len <= us_offset) {
520         oam_warning_log0(0, OAM_SF_ANY, "{mac_get_meshid:: the length of beacon/probe rsp frame body is invalid.}");
521         return HI_NULL;
522     }
523 
524     puc_meshid_ie = mac_find_mesh_vendor_ie(MAC_OUISUBTYPE_MESH_HISI_MESHID, (puc_beacon_body + us_offset),
525         (hi_u32)(l_frame_body_len - us_offset));
526     /* 查找meshid的ie */
527     if ((puc_meshid_ie != HI_NULL) && (puc_meshid_ie[MAC_MESH_MESHID_LEN_POS] < WLAN_MESHID_MAX_LEN)) {
528         /* 获取ssid ie的长度 */
529         *puc_meshid_len = puc_meshid_ie[MAC_MESH_MESHID_LEN_POS];
530 
531         return (hi_u8 *)(puc_meshid_ie + MAC_MESH_MESHID_OFFSET);
532     }
533 
534     return HI_NULL;
535 }
536 
537 /* ****************************************************************************
538  功能描述  : 获取beacon帧中的beacon priority字段,上报new peer candidate时使用(私有字段中)
539  输入参数  : puc_beacon_body:Beacon or probe rsp帧体
540                             hi_s32 l_frame_body_len:帧体长度
541  返 回 值  : uc_bcn_prio:beacon priority
542  修改历史      :
543   1.日    期   : 2019年5月25日
544     作    者   : HiSilicon
545     修改内容   : 新生成函数
546 **************************************************************************** */
mac_get_hisi_beacon_prio(hi_u8 * puc_beacon_body,hi_s32 l_frame_body_len)547 WIFI_ROM_TEXT hi_u8 mac_get_hisi_beacon_prio(hi_u8 *puc_beacon_body, hi_s32 l_frame_body_len)
548 {
549     hi_u8 bcn_prio = 0;
550     hi_u8 *puc_bcn_prio_ie = HI_NULL;
551     hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
552 
553     /* *********************************************************************** */
554     /*                       Beacon Frame - Frame Body                       */
555     /* --------------------------------------------------------------------- */
556     /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm   | */
557     /* --------------------------------------------------------------------- */
558     /* |8         |2         |2       |2-34 |3-10     |3        |4-256     | */
559     /* --------------------------------------------------------------------- */
560     /*                                                                       */
561     /* *********************************************************************** */
562     /* **************************************************************************
563          Vendor Spec |Length| OUI|TYPE|SUBTYPE|Beacon Priority|
564            1                |1        |3    |1     |1            |  1                  |
565     ************************************************************************** */
566     /* 检测beacon帧或者probe rsp帧的长度的合法性 */
567     if (l_frame_body_len <= us_offset) {
568         oam_warning_log0(0, OAM_SF_ANY,
569             "{mac_get_hisi_mesh_optimization_ie:: the length of beacon/probe rsp frame body is invalid.}");
570         return 0;
571     }
572 
573     puc_bcn_prio_ie = mac_find_mesh_vendor_ie(MAC_OUISUBTYPE_MESH_HISI_OPTIMIZATION, (puc_beacon_body + us_offset),
574         (hi_u32)(l_frame_body_len - us_offset));
575     /* 查找beacon prio的ie */
576     if (puc_bcn_prio_ie != HI_NULL) {
577         /* 获取beacon prio */
578         bcn_prio = puc_bcn_prio_ie[MAC_MESH_HISI_BEACON_PRIO_POS];
579     }
580 
581     return bcn_prio;
582 }
583 
584 /* ****************************************************************************
585  功能描述  : 获取beacon帧中的is mbr标识字段,上报new peer candidate时使用(私有字段中)
586  输入参数  : puc_beacon_body:Beacon or probe rsp帧体
587                             hi_s32 l_frame_body_len:帧体长度
588  返 回 值  : hi_u8 en_is_mbr
589  修改历史      :
590   1.日    期   : 2019年6月29日
591     作    者   : HiSilicon
592     修改内容   : 新生成函数
593 **************************************************************************** */
mac_get_hisi_en_is_mbr(hi_u8 * puc_beacon_body,hi_s32 l_frame_body_len)594 WIFI_ROM_TEXT hi_u8 mac_get_hisi_en_is_mbr(hi_u8 *puc_beacon_body, hi_s32 l_frame_body_len)
595 {
596     hi_u8 is_mbr = 0;
597     hi_u8 *puc_hisi_optimization_ie = HI_NULL;
598     hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
599 
600     /* *********************************************************************** */
601     /*                       Beacon Frame - Frame Body                       */
602     /* --------------------------------------------------------------------- */
603     /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm   | */
604     /* --------------------------------------------------------------------- */
605     /* |8         |2         |2       |2-34 |3-10     |3        |4-256     | */
606     /* --------------------------------------------------------------------- */
607     /*                                                                       */
608     /* *********************************************************************** */
609     /* **************************************************************************
610          Vendor Spec |Length| OUI|TYPE|SUBTYPE|Beacon Priority|
611            1                |1        |3    |1     |1            |  1                  |
612     ************************************************************************** */
613     /* 检测beacon帧或者probe rsp帧的长度的合法性 */
614     if (l_frame_body_len <= us_offset) {
615         oam_warning_log0(0, OAM_SF_ANY,
616             "{mac_get_hisi_en_is_mbr:: the length of beacon/probe rsp frame body is invalid.}");
617         return 0;
618     }
619 
620     puc_hisi_optimization_ie = mac_find_mesh_vendor_ie(MAC_OUISUBTYPE_MESH_HISI_OPTIMIZATION,
621         (puc_beacon_body + us_offset), (hi_u32)(l_frame_body_len - us_offset));
622     /* 查找beacon prio的ie */
623     if (puc_hisi_optimization_ie != HI_NULL) {
624         /* 获取beacon prio */
625         is_mbr = puc_hisi_optimization_ie[MAC_MESH_HISI_IS_MBR_POS];
626     }
627 
628     return is_mbr;
629 }
630 
631 /* ****************************************************************************
632  功能描述  : 获取beacon帧中的Accept sta标识字段,上报new peer candidate时使用(私有字段中)
633  输入参数  : puc_beacon_body:Beacon or probe rsp帧体
634                             hi_s32 l_frame_body_len:帧体长度
635  返 回 值  : hi_u8 accept_sta
636  修改历史      :
637   1.日    期   : 2019年6月29日
638     作    者   : HiSilicon
639     修改内容   : 新生成函数
640 **************************************************************************** */
mac_get_hisi_accept_sta(hi_u8 * puc_beacon_body,hi_s32 l_frame_body_len)641 WIFI_ROM_TEXT hi_u8 mac_get_hisi_accept_sta(hi_u8 *puc_beacon_body, hi_s32 l_frame_body_len)
642 {
643     hi_u8 accept_sta = 0;
644     hi_u8 *puc_hisi_optimization_ie = HI_NULL;
645     hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
646 
647     /* *********************************************************************** */
648     /*                       Beacon Frame - Frame Body                       */
649     /* --------------------------------------------------------------------- */
650     /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm   | */
651     /* --------------------------------------------------------------------- */
652     /* |8         |2         |2       |2-34 |3-10     |3        |4-256     | */
653     /* --------------------------------------------------------------------- */
654     /*                                                                       */
655     /* *********************************************************************** */
656     /* **************************************************************************
657          Vendor Spec |Length| OUI|TYPE|SUBTYPE|Beacon Priority|
658            1                |1        |3    |1     |1            |  1                  |
659     ************************************************************************** */
660     /* 检测beacon帧或者probe rsp帧的长度的合法性 */
661     if (l_frame_body_len <= us_offset) {
662         oam_warning_log0(0, OAM_SF_ANY,
663             "{mac_get_hisi_accept_sta:: the length of beacon/probe rsp frame body is invalid.}");
664         return 0;
665     }
666 
667     puc_hisi_optimization_ie = mac_find_mesh_vendor_ie(MAC_OUISUBTYPE_MESH_HISI_OPTIMIZATION,
668         (puc_beacon_body + us_offset), (hi_u32)(l_frame_body_len - us_offset));
669     /* 查找beacon prio的ie */
670     if (puc_hisi_optimization_ie != HI_NULL) {
671         /* 获取beacon prio */
672         accept_sta = puc_hisi_optimization_ie[MAC_MESH_HISI_ACCEPT_STA_POS];
673     }
674 
675     return accept_sta;
676 }
677 
678 #endif
679 
680 #ifdef _PRE_WLAN_FEATURE_STA_UAPSD
681 /* ****************************************************************************
682  功能描述  : 设置sta qos info字段
683  输入参数  : pst_mac_vap: 指向vap
684              puc_buffer : 指向buffer
685  修改历史      :
686   1.日    期   : 2015年2月10日
687     作    者   : HiSilicon
688     修改内容   : 新生成函数
689 **************************************************************************** */
mac_set_qos_info_wmm_sta(const mac_vap_stru * mac_vap,hi_u8 * puc_buffer)690 WIFI_ROM_TEXT static hi_void mac_set_qos_info_wmm_sta(const mac_vap_stru *mac_vap, hi_u8 *puc_buffer)
691 {
692     hi_u8 qos_info = 0;
693     hi_u8 max_sp_bits;
694     hi_u8 max_sp_length;
695     /* QoS Information field                                          */
696     /* -------------------------------------------------------------- */
697     /* | B0    | B1    | B2    | B3    | B4      | B5:B6 | B7       | */
698     /* -------------------------------------------------------------- */
699     /* | AC_VO | AC_VI | AC_BK | AC_BE |         | Max SP|          | */
700     /* | U-APSD| U-APSD| U-APSD| U-APSD| Reserved| Length| Reserved | */
701     /* | Flag  | Flag  | Flag  | Flag  |         |       |          | */
702     /* -------------------------------------------------------------- */
703     /* Set the UAPSD configuration information in the QoS info field if the  */
704     /* BSS type is Infrastructure and the AP supports UAPSD.                 */
705     if (mac_vap->uapsd_cap) {
706         max_sp_length = mac_vap->sta_uapsd_cfg.max_sp_len;
707         qos_info = mac_vap->sta_uapsd_cfg.trigger_map;
708         if (max_sp_length <= 6) { /* sp最大长度为6 byte */
709             max_sp_bits = max_sp_length >> 1;
710             qos_info |= ((max_sp_bits & 0x03) << 5); /* sp bit数从qos_info的第5bit开始存储 */
711         }
712     }
713     puc_buffer[0] = qos_info;
714 }
715 #endif
716 
717 /* ****************************************************************************
718  功能描述  : 设置qos info字段
719  输入参数  : pst_mac_vap: 指向vap
720              puc_buffer : 指向buffer
721  修改历史      :
722   1.日    期   : 2013年4月16日
723     作    者   : HiSilicon
724     修改内容   : 新生成函数
725 **************************************************************************** */
mac_set_qos_info_field(const mac_vap_stru * mac_vap,hi_u8 * puc_buffer)726 WIFI_ROM_TEXT static hi_void mac_set_qos_info_field(const mac_vap_stru *mac_vap, hi_u8 *puc_buffer)
727 {
728     mac_qos_info_stru *qos_info = (mac_qos_info_stru *)puc_buffer;
729 
730     /* QoS Information field  (AP MODE)            */
731     /* ------------------------------------------- */
732     /* | B0:B3               | B4:B6    | B7     | */
733     /* ------------------------------------------- */
734     /* | Parameter Set Count | Reserved | U-APSD | */
735     if ((mac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP)
736 #ifdef _PRE_WLAN_FEATURE_MESH_ROM
737         || (mac_vap->vap_mode == WLAN_VAP_MODE_MESH)
738 #endif
739     ) {
740         qos_info->params_count = mac_vap->wmm_params_update_count;
741         qos_info->uapsd        = mac_vap->cap_flag.uapsd;
742         qos_info->bit_resv     = 0;
743     }
744 
745     /* QoS Information field  (STA MODE)           */
746     /* ---------------------------------------------------------------------------------------------------------- */
747     /* | B0              | B1              | B2              | B3              | B4      |B5   B6      | B7     | */
748     /* ---------------------------------------------------------------------------------------------------------- */
749     /* |AC_VO U-APSD Flag|AC_VI U-APSD Flag|AC_BK U-APSD Flag|AC_BE U-APSD Flag|Reserved |Max SP Length|Reserved| */
750     /* ---------------------------------------------------------------------------------------------------------- */
751     if (mac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) {
752 #ifdef _PRE_WLAN_FEATURE_STA_UAPSD
753         mac_set_qos_info_wmm_sta(mac_vap, puc_buffer);
754 #else
755         puc_buffer[0] = 0;
756         puc_buffer[0] |= 0x0;
757 #endif
758     }
759 }
760 
761 /* ****************************************************************************
762  功能描述  : 设置一个ac的参数
763  输入参数  : pst_mac_vap: 指向vap
764              puc_buffer : 指向buffer
765              en_ac      : AC类型
766  修改历史      :
767   1.日    期   : 2013年4月16日
768     作    者   : HiSilicon
769     修改内容   : 新生成函数
770 **************************************************************************** */
mac_set_wmm_ac_params(const mac_vap_stru * mac_vap,hi_u8 * puc_buffer,hi_u8 ac)771 WIFI_ROM_TEXT static hi_void mac_set_wmm_ac_params(const mac_vap_stru *mac_vap, hi_u8 *puc_buffer, hi_u8 ac)
772 {
773     mac_wmm_ac_params_stru *ac_params = (mac_wmm_ac_params_stru *)puc_buffer;
774 
775     /* AC_** Parameter Record field               */
776     /* ------------------------------------------ */
777     /* | Byte 1    | Byte 2        | Byte 3:4   | */
778     /* ------------------------------------------ */
779     /* | ACI/AIFSN | ECWmin/ECWmax | TXOP Limit | */
780     /* ------------------------------------------ */
781     /* ACI/AIFSN Field                    */
782     /* ---------------------------------- */
783     /* | B0:B3 | B4  | B5:B6 | B7       | */
784     /* ---------------------------------- */
785     /* | AIFSN | ACM | ACI   | Reserved | */
786     /* ---------------------------------- */
787     /* AIFSN */
788     ac_params->aifsn = mac_vap->mib_info->ast_wlan_mib_edca[ac].dot11_edca_table_aifsn;
789     /* ACM */
790     ac_params->acm = mac_vap->mib_info->ast_wlan_mib_edca[ac].dot11_edca_table_mandatory;
791     /* ACI */
792     ac_params->aci = ac;
793     ac_params->bit_resv = 0;
794 
795     /* ECWmin/ECWmax Field */
796     /* ------------------- */
797     /* | B0:B3  | B4:B7  | */
798     /* ------------------- */
799     /* | ECWmin | ECWmax | */
800     /* ------------------- */
801     /* ECWmin */
802     ac_params->ecwmin = mac_vap->mib_info->ast_wlan_mib_edca[ac].dot11_edca_table_c_wmin;
803     /* ECWmax */
804     ac_params->ecwmax = mac_vap->mib_info->ast_wlan_mib_edca[ac].dot11_edca_table_c_wmax;
805     /* TXOP Limit. The value saved in MIB is in usec while the value to be   */
806     /* set in this element should be in multiple of 32us                     */
807     ac_params->us_txop =
808         (hi_u16)((mac_vap->mib_info->ast_wlan_mib_edca[ac].dot11_edca_table_txop_limit) >> 5); /* 右移5bit获取txop */
809 }
810 
811 /* ****************************************************************************
812  功能描述  : 设置wmm信息元素
813  输入参数  : pst_vap   : 指向vap
814              puc_buffer: 指向buffer
815              en_is_qos : 是否支持QOS。如果是BEACON/Probe Req/Probe Rsp/ASSOC Req帧,则取AP/STA自身的QOS能力;
816              如果ASSOC RSP,则需要根据对方STA的QOS能力,来判断是否带WMM IE。
817  输出参数  : puc_ie_len: ie的总长度
818  修改历史      :
819   1.日    期   : 2013年4月16日
820     作    者   : HiSilicon
821     修改内容   : 新生成函数
822 **************************************************************************** */
mac_set_wmm_params_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 is_qos,hi_u8 * puc_ie_len)823 WIFI_ROM_TEXT hi_void mac_set_wmm_params_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 is_qos, hi_u8 *puc_ie_len)
824 {
825     hi_u8 index;
826     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
827     hi_u8     auc_oui[MAC_OUI_LEN] = {(hi_u8)MAC_WLAN_OUI_MICRO0,
828                                       (hi_u8)MAC_WLAN_OUI_MICRO1, (hi_u8)MAC_WLAN_OUI_MICRO2};
829 
830     if (!is_qos) {
831         *puc_ie_len = 0;
832         return;
833     }
834     /* WMM Parameter Element Format                                          */
835     /* --------------------------------------------------------------------- */
836     /* | 3Byte | 1        | 1           | 1             | 1        | 1     | */
837     /* --------------------------------------------------------------------- */
838     /* | OUI   | OUI Type | OUI Subtype | Version field | QoS Info | Resvd | */
839     /* --------------------------------------------------------------------- */
840     /* | 4              | 4              | 4              | 4              | */
841     /* --------------------------------------------------------------------- */
842     /* | AC_BE ParamRec | AC_BK ParamRec | AC_VI ParamRec | AC_VO ParamRec | */
843     /* --------------------------------------------------------------------- */
844     puc_buffer[0] = MAC_EID_WMM;
845     puc_buffer[1] = MAC_WMM_PARAM_LEN;
846     index = MAC_IE_HDR_LEN;
847     /* OUI */
848     if (memcpy_s(&puc_buffer[index], MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) {
849         return;
850     }
851     index += MAC_OUI_LEN;
852     /* OUI Type */
853     puc_buffer[index++] = MAC_OUITYPE_WMM;
854     /* OUI Subtype */
855     puc_buffer[index++] = MAC_OUISUBTYPE_WMM_PARAM;
856     /* Version field */
857     puc_buffer[index++] = MAC_OUI_WMM_VERSION;
858     /* QoS Information Field */
859     mac_set_qos_info_field(mac_vap, &puc_buffer[index]);
860     index += MAC_QOS_INFO_LEN;
861     /* Reserved */
862     puc_buffer[index++] = 0;
863     /* Set the AC_BE, AC_BK, AC_VI, AC_VO Parameter Record fields */
864     mac_set_wmm_ac_params(mac_vap, &puc_buffer[index], WLAN_WME_AC_BE);
865     index += MAC_AC_PARAM_LEN;
866     mac_set_wmm_ac_params(mac_vap, &puc_buffer[index], WLAN_WME_AC_BK);
867     index += MAC_AC_PARAM_LEN;
868     mac_set_wmm_ac_params(mac_vap, &puc_buffer[index], WLAN_WME_AC_VI);
869     index += MAC_AC_PARAM_LEN;
870     mac_set_wmm_ac_params(mac_vap, &puc_buffer[index], WLAN_WME_AC_VO);
871     *puc_ie_len = MAC_IE_HDR_LEN + MAC_WMM_PARAM_LEN;
872 }
873 
874 /* ****************************************************************************
875  功能描述  : 填充extended supported rates信息
876  输入参数  : pst_vap: 指向vap
877              puc_buffer: 指向buffer
878  输出参数  : puc_ie_len: element的长度
879  修改历史      :
880   1.日    期   : 2013年4月12日
881     作    者   : HiSilicon
882     修改内容   : 新生成函数
883 **************************************************************************** */
mac_set_exsup_rates_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)884 WIFI_ROM_TEXT hi_void mac_set_exsup_rates_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
885 {
886     mac_vap_stru     *mac_vap   = (mac_vap_stru *)vap;
887     mac_rateset_stru *rates_set = HI_NULL;
888     hi_u8 nrates;
889     hi_u8 idx;
890 
891     rates_set = &(mac_vap->curr_sup_rates.rate);
892     /* **************************************************************************
893                    -----------------------------------------------
894                    |ElementID | Length | Extended Supported Rates|
895                    -----------------------------------------------
896        Octets:     |1         | 1      | 1-255                   |
897                    -----------------------------------------------
898     ************************************************************************** */
899     if (rates_set->rs_nrates <= MAC_MAX_SUPRATES) {
900         *puc_ie_len = 0;
901         return;
902     }
903     puc_buffer[0] = MAC_EID_XRATES;
904     nrates = rates_set->rs_nrates - MAC_MAX_SUPRATES;
905     puc_buffer[1] = nrates;
906     for (idx = 0; idx < nrates; idx++) {
907         puc_buffer[MAC_IE_HDR_LEN + idx] = rates_set->ast_rs_rates[idx + MAC_MAX_SUPRATES].mac_rate;
908     }
909     *puc_ie_len = MAC_IE_HDR_LEN + nrates;
910 }
911 
912 /* ****************************************************************************
913  功能描述  : 填写ht capabilities info域
914  输入参数  : pst_vap :指向vap
915              puc_buffer :指向buffer
916  修改历史      :
917   1.日    期   : 2013年4月15日
918     作    者   : HiSilicon
919     修改内容   : 新生成函数
920 **************************************************************************** */
mac_set_ht_capinfo_field(hi_void * vap,hi_u8 * puc_buffer)921 WIFI_ROM_TEXT static hi_void mac_set_ht_capinfo_field(hi_void *vap, hi_u8 *puc_buffer)
922 {
923     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
924     mac_frame_ht_cap_stru *ht_capinfo = (mac_frame_ht_cap_stru *)puc_buffer;
925     /* ********************** HT Capabilities Info field*************************
926     ----------------------------------------------------------------------------
927      |-------------------------------------------------------------------|
928      | LDPC   | Supp    | SM    | Green- | Short  | Short  |  Tx  |  Rx  |
929      | Coding | Channel | Power | field  | GI for | GI for | STBC | STBC |
930      | Cap    | Wth Set | Save  |        | 20 MHz | 40 MHz |      |      |
931      |-------------------------------------------------------------------|
932      |   B0   |    B1   |B2   B3|   B4   |   B5   |    B6  |  B7  |B8  B9|
933      |-------------------------------------------------------------------|
934      |-------------------------------------------------------------------|
935      |    HT     |  Max   | DSS/CCK | Reserved | 40 MHz     | L-SIG TXOP |
936      |  Delayed  | AMSDU  | Mode in |          | Intolerant | Protection |
937      | Block-Ack | Length | 40MHz   |          |            | Support    |
938      |-------------------------------------------------------------------|
939      |    B10    |   B11  |   B12   |   B13    |    B14     |    B15     |
940      |-------------------------------------------------------------------|
941     ************************************************************************** */
942     /* 初始清0 */
943     puc_buffer[0] = 0;
944     puc_buffer[1] = 0;
945     ht_capinfo->ldpc_coding_cap = mac_vap->mib_info->phy_ht.dot11_ldpc_coding_option_implemented;
946     /* 设置所支持的信道宽度集",0:仅20MHz运行; 1:20MHz与40MHz运行 */
947     ht_capinfo->supported_channel_width = mac_mib_get_forty_mhz_operation_implemented(mac_vap);
948     ht_capinfo->sm_power_save = MAC_SMPS_MIMO_MODE;
949     ht_capinfo->ht_green_field = 0;
950     ht_capinfo->short_gi_20mhz = mac_vap->mib_info->phy_ht.dot11_short_gi_option_in_twenty_implemented;
951     ht_capinfo->short_gi_40mhz = mac_mib_get_shortgi_option_in_forty_implemented(mac_vap);
952     ht_capinfo->tx_stbc = mac_vap->mib_info->phy_ht.dot11_tx_stbc_option_implemented;
953     ht_capinfo->rx_stbc = (HI_TRUE == mac_vap->mib_info->phy_ht.dot11_rx_stbc_option_implemented) ? 1 : 0;
954     ht_capinfo->ht_delayed_block_ack =
955         mac_vap->mib_info->wlan_mib_sta_config.dot11_delayed_block_ack_option_implemented;
956     ht_capinfo->max_amsdu_length = 0; /* 0表示最大amsdu长度为3839bytes */
957     /* 1131H只支持2.4g 20M 配置为默认值 */
958     ht_capinfo->dsss_cck_mode_40mhz = 0;
959     ht_capinfo->forty_mhz_intolerant = mac_mib_get_forty_mhz_intolerant(mac_vap);
960     ht_capinfo->lsig_txop_protection = HI_TRUE;
961 }
962 
963 /* ****************************************************************************
964  功能描述  : 填充ht a-mpdu parameters域信息
965  输入参数  : pst_vap :指向vap
966              puc_buffer :指向buffer
967  修改历史      :
968   1.日    期   : 2013年4月16日
969     作    者   : HiSilicon
970     修改内容   : 新生成函数
971 **************************************************************************** */
mac_set_ampdu_params_field(hi_u8 * puc_buffer)972 WIFI_ROM_TEXT static hi_void mac_set_ampdu_params_field(hi_u8 *puc_buffer)
973 {
974     mac_ampdu_params_stru *ampdu_params = (mac_ampdu_params_stru *)puc_buffer;
975 
976     /* ******************* AMPDU Parameters Field ******************************
977      |-----------------------------------------------------------------------|
978      | Maximum AMPDU Length Exponent | Minimum MPDU Start Spacing | Reserved |
979      |-----------------------------------------------------------------------|
980      | B0                         B1 | B2                      B4 | B5     B7|
981      |-----------------------------------------------------------------------|
982     ************************************************************************* */
983     /* 初始清0 */
984     puc_buffer[0] = 0;
985     if (frw_get_offload_mode()) {
986         ampdu_params->max_ampdu_len_exponent = 2; /* IPC 最大接收的ampdu长度 32k=(2^(13+2))-1 */
987     } else {
988         /* IOT 31H受限PACKET B大小,最大接收的ampdu长度 8k=(2^(13))-1 */
989         ampdu_params->max_ampdu_len_exponent = 0;
990     }
991     ampdu_params->min_mpdu_start_spacing = 5; /* AMPDU中两个mpdu的最小间隔,取值5(= 4ms) */
992 }
993 
994 /* ****************************************************************************
995  功能描述  : 填充supported mcs set域信息
996  输入参数  : pst_vap :指向vap
997              puc_buffer :指向buffer
998  修改历史      :
999   1.日    期   : 2013年4月16日
1000     作    者   : HiSilicon
1001     修改内容   : 新生成函数
1002 **************************************************************************** */
mac_set_sup_mcs_set_field(hi_void * vap,hi_u8 * puc_buffer)1003 WIFI_ROM_TEXT static hi_void mac_set_sup_mcs_set_field(hi_void *vap, hi_u8 *puc_buffer)
1004 {
1005     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1006     mac_sup_mcs_set_stru *sup_mcs_set = (mac_sup_mcs_set_stru *)puc_buffer;
1007 
1008     /* ************************ Supported MCS Set Field **********************
1009     |-------------------------------------------------------------------|
1010     | Rx MCS Bitmask | Reserved | Rx Highest    | Reserved |  Tx MCS    |
1011     |                |          | Supp Data Rate|          |Set Defined |
1012     |-------------------------------------------------------------------|
1013     | B0         B76 | B77  B79 | B80       B89 | B90  B95 |    B96     |
1014     |-------------------------------------------------------------------|
1015     | Tx Rx MCS Set  | Tx Max Number     |   Tx Unequal     | Reserved  |
1016     |  Not Equal     | Spat Stream Supp  | Modulation Supp  |           |
1017     |-------------------------------------------------------------------|
1018     |      B97       | B98           B99 |       B100       | B101 B127 |
1019     |-------------------------------------------------------------------|
1020     ************************************************************************ */
1021     /* 初始清零 */
1022     if (memset_s(puc_buffer, sizeof(mac_sup_mcs_set_stru), 0, sizeof(mac_sup_mcs_set_stru)) != EOK) {
1023         return;
1024     }
1025     if (memcpy_s(sup_mcs_set->auc_rx_mcs, sizeof(sup_mcs_set->auc_rx_mcs),
1026         mac_vap->mib_info->supported_mcsrx.auc_dot11_supported_mcs_rx_value, WLAN_HT_MCS_BITMASK_LEN) != EOK) {
1027         return;
1028     }
1029     sup_mcs_set->rx_highest_rate = MAC_MAX_RATE_SINGLE_NSS_20M_11N;
1030     sup_mcs_set->tx_mcs_set_def = 1;
1031     /* reserve位清0 */
1032     sup_mcs_set->resv1 = 0;
1033     sup_mcs_set->resv2 = 0;
1034 }
1035 
1036 /* ****************************************************************************
1037  函 数 名  : mac_set_ht_extcap_field
1038  功能描述  : 填充ht extended capabilities field信息
1039  输入参数  : pst_vap :指向vap
1040              puc_buffer :指向buffer
1041  修改历史      :
1042   1.日    期   : 2013年4月16日
1043     作    者   : HiSilicon
1044     修改内容   : 新生成函数
1045 **************************************************************************** */
mac_set_ht_extcap_field(hi_u8 * puc_buffer)1046 WIFI_ROM_TEXT static hi_void mac_set_ht_extcap_field(hi_u8 *puc_buffer)
1047 {
1048     mac_ext_cap_stru *ext_cap = (mac_ext_cap_stru *)puc_buffer;
1049 
1050     /* **************** HT Extended Capabilities Field **********************
1051       |-----------------------------------------------------------------|
1052       | PCO | PCO Trans | Reserved | MCS  |  +HTC   |  RD    | Reserved |
1053       |     |   Time    |          | Fdbk | Support | Resp   |          |
1054       |-----------------------------------------------------------------|
1055       | B0  | B1     B2 | B3    B7 | B8 B9|   B10   |  B11   | B12  B15 |
1056       |-----------------------------------------------------------------|
1057     ********************************************************************** */
1058     /* 初始清0 */
1059     puc_buffer[0] = 0;
1060     puc_buffer[1] = 0;
1061     ext_cap->mcs_fdbk = (hi_u16)WLAN_MIB_MCS_FEEDBACK_OPT_IMPLT_NONE;
1062     ext_cap->htc_sup = HI_FALSE;
1063     ext_cap->rd_resp = HI_FALSE;
1064 }
1065 
1066 
1067 /* ****************************************************************************
1068  功能描述  : 填充ht capabilities信息
1069  输入参数  : pst_vap: 指向vap
1070              puc_buffer: 指向buffer
1071  输出参数  : puc_ie_len: element的长度
1072  修改历史      :
1073   1.日    期   : 2013年4月12日
1074     作    者   : HiSilicon
1075     修改内容   : 新生成函数
1076 **************************************************************************** */
mac_set_ht_capabilities_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1077 WIFI_ROM_TEXT hi_void mac_set_ht_capabilities_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1078 {
1079     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1080 
1081     if (!mac_vap->mib_info->wlan_mib_sta_config.dot11_high_throughput_option_implemented) {
1082         *puc_ie_len = 0;
1083         return;
1084     }
1085     /* **************************************************************************
1086     -------------------------------------------------------------------------
1087     |EID |Length |HT Capa. Info |A-MPDU Parameters |Supported MCS Set|
1088     -------------------------------------------------------------------------
1089     |1   |1      |2             |1                 |16               |
1090     -------------------------------------------------------------------------
1091     |HT Extended Cap. |Transmit Beamforming Cap. |ASEL Cap.          |
1092     -------------------------------------------------------------------------
1093     |2                |4                         |1                  |
1094     -------------------------------------------------------------------------
1095     ************************************************************************** */
1096     *puc_buffer = MAC_EID_HT_CAP;
1097     *(puc_buffer + 1) = MAC_HT_CAP_LEN;
1098     puc_buffer += MAC_IE_HDR_LEN;
1099     /* 填充ht capabilities information域信息 */
1100     mac_set_ht_capinfo_field(vap, puc_buffer);
1101     puc_buffer += MAC_HT_CAPINFO_LEN;
1102     /* 填充A-MPDU parameters域信息 */
1103     mac_set_ampdu_params_field(puc_buffer);
1104     puc_buffer += MAC_HT_AMPDU_PARAMS_LEN;
1105     /* 填充supported MCS set域信息 */
1106     mac_set_sup_mcs_set_field(vap, puc_buffer);
1107     puc_buffer += MAC_HT_SUP_MCS_SET_LEN;
1108     /* 填充ht extended capabilities域信息 */
1109     mac_set_ht_extcap_field(puc_buffer);
1110     puc_buffer += MAC_HT_EXT_CAP_LEN;
1111     /* 填充 transmit beamforming capabilities域信息 */
1112     mac_set_txbf_cap_field(puc_buffer);
1113     puc_buffer += MAC_HT_TXBF_CAP_LEN;
1114     /* 填充asel(antenna selection) capabilities域信息 */
1115     mac_set_asel_cap_field(puc_buffer);
1116     *puc_ie_len = MAC_IE_HDR_LEN + MAC_HT_CAP_LEN;
1117 }
1118 
1119 /* ****************************************************************************
1120  功能描述  : 填充ht operation信息
1121  输入参数  : pst_vap: 指向vap
1122              puc_buffer: 指向buffer
1123  输出参数  : puc_ie_len: element的长度
1124  修改历史      :
1125   1.日    期   : 2013年4月12日
1126     作    者   : HiSilicon
1127     修改内容   : 新生成函数
1128 **************************************************************************** */
mac_set_ht_opern_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1129 WIFI_ROM_TEXT hi_void mac_set_ht_opern_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1130 {
1131     mac_vap_stru      *mac_vap = (mac_vap_stru *)vap;
1132     mac_ht_opern_stru *ht_opern = HI_NULL;
1133     hi_u8              obss_non_ht = 0;
1134 
1135     if (!mac_mib_get_high_throughput_option_implemented(mac_vap)) {
1136         *puc_ie_len = 0;
1137         return;
1138     }
1139     /* **************************************************************************
1140       ----------------------------------------------------------------------
1141       |EID |Length |PrimaryChannel |HT Operation Information |Basic MCS Set|
1142       ----------------------------------------------------------------------
1143       |1   |1      |1              |5                        |16           |
1144       ----------------------------------------------------------------------
1145     ************************************************************************** */
1146     /* *********************** HT Information Field ****************************
1147      |--------------------------------------------------------------------|
1148      | Primary | Seconday  | STA Ch | RIFS |           reserved           |
1149      | Channel | Ch Offset | Width  | Mode |                              |
1150      |--------------------------------------------------------------------|
1151      |    1    | B0     B1 |   B2   |  B3  |    B4                     B7 |
1152      |--------------------------------------------------------------------|
1153      |----------------------------------------------------------------|
1154      |     HT     | Non-GF STAs | resv      | OBSS Non-HT  | Reserved |
1155      | Protection |   Present   |           | STAs Present |          |
1156      |----------------------------------------------------------------|
1157      | B0     B1  |     B2      |    B3     |     B4       | B5   B15 |
1158      |----------------------------------------------------------------|
1159      |-------------------------------------------------------------|
1160      | Reserved |  Dual  |  Dual CTS  | Seconday | LSIG TXOP Protn |
1161      |          | Beacon | Protection |  Beacon  | Full Support    |
1162      |-------------------------------------------------------------|
1163      | B0    B5 |   B6   |     B7     |     B8   |       B9        |
1164      |-------------------------------------------------------------|
1165      |---------------------------------------|
1166      |  PCO   |  PCO  | Reserved | Basic MCS |
1167      | Active | Phase |          |    Set    |
1168      |---------------------------------------|
1169      |  B10   |  B11  | B12  B15 |    16     |
1170      |---------------------------------------|
1171     ************************************************************************* */
1172     *puc_buffer = MAC_EID_HT_OPERATION;
1173     *(puc_buffer + 1) = MAC_HT_OPERN_LEN;
1174     ht_opern = (mac_ht_opern_stru *)(puc_buffer + MAC_IE_HDR_LEN);
1175     /* 主信道编号 */
1176     ht_opern->primary_channel = mac_vap->channel.chan_number;
1177     ht_opern->secondary_chan_offset = MAC_SCN;
1178     /* 设置"STA信道宽度",当BSS运行信道宽度 >= 40MHz时,需要将此field设置为1 */
1179     ht_opern->sta_chan_width = (mac_vap->channel.en_bandwidth > WLAN_BAND_WIDTH_20M) ? 1 : 0;
1180     /* 指示基本服务集里是否允许使用减小的帧间距 */
1181     ht_opern->rifs_mode = mac_mib_get_rifs_mode(mac_vap);
1182     /* B4-B7保留 */
1183     ht_opern->resv1 = 0;
1184     /* 指示ht传输的保护要求 */
1185     ht_opern->ht_protection = mac_mib_get_ht_protection(mac_vap);
1186     /* Non-GF STAs */
1187     ht_opern->nongf_sta_present = mac_mib_get_non_gfentities_present(mac_vap);
1188     /* B3 resv */
1189     ht_opern->resv2 = 0;
1190     /* B4  obss_nonht_sta_present */
1191     if ((mac_vap->protection.obss_non_ht_present != 0) || (mac_vap->protection.sta_non_ht_num != 0)) {
1192         obss_non_ht = 1;
1193     }
1194     ht_opern->obss_nonht_sta_present = obss_non_ht;
1195     /* B5-B15 保留 */
1196     ht_opern->resv3 = 0;
1197     ht_opern->resv4 = 0;
1198     /* B0-B5 保留 */
1199     ht_opern->resv5 = 0;
1200     /* B6  dual_beacon */
1201     ht_opern->dual_beacon = 0;
1202     /* Dual CTS protection */
1203     ht_opern->dual_cts_protection = 0;
1204     /* secondary_beacon: Set to 0 in a primary beacon */
1205     ht_opern->secondary_beacon = 0;
1206     /* BSS support L-SIG TXOP Protection */
1207     ht_opern->lsig_txop_protection_full_support = mac_mib_get_lsig_txop_full_protection_activated(mac_vap);
1208     /* PCO active */
1209     ht_opern->pco_active = 0;
1210     /* PCO phase */
1211     ht_opern->pco_phase = 0;
1212     /* B12-B15  保留 */
1213     ht_opern->resv6 = 0;
1214     /* Basic MCS Set: set all bit zero,Indicates the MCS values that are supported by all HT STAs in the BSS. */
1215     /* 安全编程规则6.6例外(1) 对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
1216     memset_s(ht_opern->auc_basic_mcs_set, MAC_HT_BASIC_MCS_SET_LEN, 0, MAC_HT_BASIC_MCS_SET_LEN);
1217     *puc_ie_len = MAC_IE_HDR_LEN + MAC_HT_OPERN_LEN;
1218 }
1219 
1220 /* ****************************************************************************
1221  功能描述  : 填充extended capabilities element信息
1222  输入参数  : pst_vap: 指向vap
1223              puc_buffer: 指向buffer
1224  输出参数  : puc_ie_len: element的长度
1225  修改历史      :
1226   1.日    期   : 2013年4月12日
1227     作    者   : HiSilicon
1228     修改内容   : 新生成函数
1229 **************************************************************************** */
mac_set_ext_capabilities_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1230 WIFI_ROM_TEXT hi_void mac_set_ext_capabilities_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1231 {
1232     mac_vap_stru        *mac_vap = (mac_vap_stru *)vap;
1233     mac_ext_cap_ie_stru *ext_cap = HI_NULL;
1234 
1235     if (!mac_mib_get_high_throughput_option_implemented(mac_vap)) {
1236         *puc_ie_len = 0;
1237         return;
1238     }
1239     /* **************************************************************************
1240                          ----------------------------------
1241                          |Element ID |Length |Capabilities|
1242                          ----------------------------------
1243           Octets:        |1          |1      |n           |
1244                          ----------------------------------
1245     ------------------------------------------------------------------------------------------
1246     |  B0       | B1 | B2             | B3   | B4   |  B5  |  B6    |  B7   | ...|  B38    |   B39      |
1247     ----------------------------------------------------------------------------
1248     |20/40 coex |resv|extended channel| resv | PSMP | resv | S-PSMP | Event |    |TDLS Pro-  TDLS Channel
1249                                                                                              Switching
1250     |mgmt supp  |    |switching       |      |      |      |        |       | ...| hibited | Prohibited |
1251     --------------------------------------------------------------------------------------------
1252     ************************************************************************** */
1253     puc_buffer[0] = MAC_EID_EXT_CAPS;
1254     puc_buffer[1] = MAC_XCAPS_EX_LEN;
1255     /* 初始清零 */
1256     if (memset_s(puc_buffer + MAC_IE_HDR_LEN, sizeof(mac_ext_cap_ie_stru), 0, sizeof(mac_ext_cap_ie_stru)) != EOK) {
1257         return;
1258     }
1259     ext_cap = (mac_ext_cap_ie_stru *)(puc_buffer + MAC_IE_HDR_LEN);
1260     /* 设置20/40 BSS Coexistence Management Support fieid */
1261     if ((HI_TRUE == mac_mib_get_2040bss_coexistence_management_support(mac_vap)) &&
1262         (WLAN_BAND_2G == mac_vap->channel.band)) {
1263         ext_cap->coexistence_mgmt = 1;
1264     }
1265     /* 设置TDLS prohibited */
1266     ext_cap->tdls_prhibited = mac_vap->cap_flag.tdls_prohibited;
1267     /* 设置TDLS channel switch prohibited */
1268     ext_cap->tdls_channel_switch_prhibited = mac_vap->cap_flag.tdls_channel_switch_prohibited;
1269 #ifdef _PRE_WLAN_FEATURE_OPMODE_NOTIFY
1270     /* 如果是11ac 站点 设置OPMODE NOTIFY标志 */
1271     if (mac_mib_get_VHTOptionImplemented(mac_vap)) {
1272         ext_cap->operating_mode_notification = mac_mib_get_operating_mode_notification_implemented(mac_vap);
1273     }
1274 #endif
1275     *puc_ie_len = MAC_IE_HDR_LEN + MAC_XCAPS_EX_LEN;
1276 }
1277 
1278 /* ****************************************************************************
1279  功能描述  : 获取beacon帧中的ssid
1280  输入参数  : puc_beacon_body,               Beacon or probe rsp帧体
1281              hi_s32 l_frame_body_len,    帧体长度
1282  输出参数  : puc_ssid_len,                  ssid 长度
1283  返 回 值  : 指向ssid
1284  修改历史      :
1285   1.日    期   : 2013年6月20日
1286     作    者   : HiSilicon
1287     修改内容   : 新生成函数
1288 **************************************************************************** */
mac_get_ssid(hi_u8 * puc_beacon_body,hi_s32 l_frame_body_len,hi_u8 * puc_ssid_len)1289 WIFI_ROM_TEXT hi_u8 *mac_get_ssid(hi_u8 *puc_beacon_body, hi_s32 l_frame_body_len, hi_u8 *puc_ssid_len)
1290 {
1291     const hi_u8 *puc_ssid_ie = HI_NULL;
1292     const hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
1293     /* *********************************************************************** */
1294     /*                       Beacon Frame - Frame Body                       */
1295     /* --------------------------------------------------------------------- */
1296     /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm   | */
1297     /* --------------------------------------------------------------------- */
1298     /* |8         |2         |2       |2-34 |3-10     |3        |4-256     | */
1299     /* --------------------------------------------------------------------- */
1300     /*                                                                       */
1301     /* *********************************************************************** */
1302     /* **************************************************************************
1303                     ----------------------------
1304                     |Element ID | Length | SSID|
1305                     ----------------------------
1306            Octets:  |1          | 1      | 0~32|
1307                     ----------------------------
1308     ************************************************************************** */
1309     /* ssid的长度初始赋值为0 */
1310     *puc_ssid_len = 0;
1311     /* 检测beacon帧或者probe rsp帧的长度的合法性 */
1312     if (l_frame_body_len <= us_offset) {
1313         oam_warning_log0(0, OAM_SF_ANY, "{mac_get_ssid:: the length of beacon/probe rsp frame body is invalid.}");
1314         return HI_NULL;
1315     }
1316     /* 查找ssid的ie */
1317     puc_ssid_ie = mac_find_ie(MAC_EID_SSID, (puc_beacon_body + us_offset), (hi_u32)(l_frame_body_len - us_offset));
1318     if ((puc_ssid_ie != HI_NULL) && (puc_ssid_ie[1] < WLAN_SSID_MAX_LEN)) {
1319         /* 获取ssid ie的长度 */
1320         *puc_ssid_len = puc_ssid_ie[1];
1321         return (hi_u8 *)(puc_ssid_ie + MAC_IE_HDR_LEN);
1322     }
1323     return HI_NULL;
1324 }
1325 
1326 /* ****************************************************************************
1327  功能描述  : 填充用户态下发的信息元素到管理帧中
1328  输入参数  : [1]vap
1329              [2]puc_buffer
1330              [3]puc_ie_len
1331              [4]type
1332  返 回 值  : 无
1333 **************************************************************************** */
mac_add_app_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u16 * pus_ie_len,en_app_ie_type_uint8 type)1334 WIFI_ROM_TEXT hi_void mac_add_app_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u16 *pus_ie_len, en_app_ie_type_uint8 type)
1335 {
1336     mac_vap_stru *mac_vap    = HI_NULL;
1337     hi_u8        *puc_app_ie = HI_NULL;
1338     hi_u32        app_ie_len;
1339 
1340     mac_vap = (mac_vap_stru *)vap;
1341     puc_app_ie = mac_vap->ast_app_ie[type].puc_ie;
1342     app_ie_len = mac_vap->ast_app_ie[type].ie_len;
1343     if (app_ie_len == 0) {
1344         *pus_ie_len = 0;
1345         return;
1346     } else {
1347         if (memcpy_s(puc_buffer, app_ie_len, puc_app_ie, app_ie_len) != EOK) {
1348             return;
1349         }
1350         *pus_ie_len = (hi_u16)app_ie_len;
1351     }
1352 }
1353 
1354 #ifdef _PRE_WLAN_FEATURE_MESH_ROM
1355 /* ****************************************************************************
1356  功能描述  : 设置mesh ssid ie
1357  输入参数  : pst_vap: 指向vap
1358              puc_buffer : 指向buffer
1359  输出参数  : puc_ie_len : element的长度
1360  修改历史      :
1361   1.日    期   : 2019年1月21日
1362     作    者   : HiSilicon
1363     修改内容   : 新生成函数
1364 **************************************************************************** */
mac_set_mesh_ssid_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len,hi_u8 is_mesh_req)1365 WIFI_ROM_TEXT hi_void mac_set_mesh_ssid_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len, hi_u8 is_mesh_req)
1366 {
1367     hi_u8 ssid_len;
1368     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1369 
1370     /* **************************************************************************
1371                     ----------------------------
1372                     |Element ID | Length | SSID|
1373                     ----------------------------
1374            Octets:  |1          | 1      | 0~32|
1375                     ----------------------------
1376     ************************************************************************** */
1377     /* Mesh中Probe req节点若为非Mesh 节点,回复非空SSID,若为Mesh节点,回复空SSID */
1378     if (is_mesh_req == HI_TRUE) {
1379         /* ssid ie */
1380         *puc_buffer = MAC_EID_SSID;
1381         /* ssid len */
1382         *(puc_buffer + 1) = 0;
1383         *puc_ie_len = MAC_IE_HDR_LEN;
1384         return;
1385     } else {
1386         hi_u8 *puc_ssid = HI_NULL;
1387         *puc_buffer = MAC_EID_SSID;
1388         puc_ssid = mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_desired_ssid;
1389         ssid_len = (hi_u8)strlen((hi_char *)puc_ssid); /* 不包含'\0' */
1390         *(puc_buffer + 1) = ssid_len;
1391         if (memcpy_s(puc_buffer + MAC_IE_HDR_LEN, ssid_len, puc_ssid, ssid_len) != EOK) {
1392             return;
1393         }
1394         *puc_ie_len = ssid_len + MAC_IE_HDR_LEN;
1395         return;
1396     }
1397 }
1398 
1399 #ifdef _PRE_WLAN_FEATURE_MESH_ROM
1400 
1401 /* ****************************************************************************
1402  功能描述  : 填充mesh相关的Vendor Specific IE字段域头部信息
1403  输入参数  : [1]puc_buffer
1404  输出参数  : [1]puc_len
1405  返 回 值  : 无
1406 **************************************************************************** */
mac_set_mesh_vendor_ie_hdr(hi_u8 * puc_buffer,hi_u8 * puc_len)1407 WIFI_ROM_TEXT hi_void mac_set_mesh_vendor_ie_hdr(hi_u8 *puc_buffer, hi_u8 *puc_len)
1408 {
1409     mac_ieee80211_vendor_ie_stru *vendor_ie = HI_NULL;
1410     hi_u8  auc_oui[MAC_OUI_LEN] = { (hi_u8)MAC_WLAN_OUI_VENDOR0, (hi_u8)MAC_WLAN_OUI_VENDOR1,
1411                                     (hi_u8)MAC_WLAN_OUI_VENDOR2 };
1412 
1413     vendor_ie = (mac_ieee80211_vendor_ie_stru *)puc_buffer;
1414     vendor_ie->element_id = MAC_EID_VENDOR;
1415     vendor_ie->len = sizeof(mac_ieee80211_vendor_ie_stru) - MAC_IE_HDR_LEN;
1416     if (memcpy_s(vendor_ie->auc_oui, MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) {
1417         puc_len = 0;
1418         return;
1419     }
1420     vendor_ie->oui_type = MAC_OUITYPE_MESH;
1421     *puc_len = sizeof(mac_ieee80211_vendor_ie_stru);
1422 }
1423 
1424 #endif
1425 
1426 /* ****************************************************************************
1427  功能描述  : 填充meshid字段(Hi1131Hmesh 方案meshid携带在私有字段)
1428  输入参数  : [1]vap
1429              [2]puc_buffer
1430  输出参数  : [3]puc_ie_len
1431  返 回 值  : 无
1432 **************************************************************************** */
mac_set_meshid_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1433 WIFI_ROM_TEXT hi_void mac_set_meshid_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1434 {
1435     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1436     hi_u8 mesh_vendor_ie_hdr_len = 0;
1437     hi_u8 meshid_len;
1438 
1439     meshid_len = (hi_u8)strlen((const hi_char *)mac_vap->mib_info->wlan_mib_mesh_sta_cfg.auc_dot11_mesh_id);
1440 
1441     /* Vendor Spec |Length| OUI|TYPE|SUBTYPE|MESHID LEN|MESHID|
1442            1                |1        |3    |1     |1           |  1               |Var       | */
1443     mac_set_mesh_vendor_ie_hdr(puc_buffer, &mesh_vendor_ie_hdr_len);
1444     *(puc_buffer + mesh_vendor_ie_hdr_len) = MAC_OUISUBTYPE_MESH_HISI_MESHID;
1445     *(puc_buffer + mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN) = meshid_len;
1446     if (memcpy_s(puc_buffer + mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN + 1, meshid_len,
1447         mac_vap->mib_info->wlan_mib_mesh_sta_cfg.auc_dot11_mesh_id, meshid_len) != EOK) {
1448         return;
1449     }
1450 
1451     /* 更新Element 长度 */
1452     *(puc_buffer + 1) += MAC_OUISUBTYPE_LEN + 1 + meshid_len;
1453     *(puc_ie_len) = mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN + 1 + meshid_len;
1454 
1455     return;
1456 }
1457 
1458 /* ****************************************************************************
1459  功能描述  : 填充Mesh Formation Info域信息
1460  输入参数  : [1]vap
1461              [2]puc_buffer
1462  返 回 值  : 无
1463 **************************************************************************** */
mac_set_mesh_formation_info_field(hi_void * vap,hi_u8 * puc_buffer)1464 WIFI_ROM_TEXT hi_void mac_set_mesh_formation_info_field(hi_void *vap, hi_u8 *puc_buffer)
1465 {
1466     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1467     mesh_formation_info_stru *mesh_formation_info = (mesh_formation_info_stru *)puc_buffer;
1468     /* *********** mesh formation info field******************
1469     --------------------------------------------------
1470     |Connected to Mesh Gate |Number of Peerings|Connected to AS|
1471     --------------------------------------------------
1472     |BIT0                                |BIT1-BIT6             |BIT7                   |
1473     --------------------------------------------------
1474     ************************************************* */
1475     /* 初始清零 */
1476     if (memset_s(puc_buffer, sizeof(mesh_formation_info_stru), 0, sizeof(mesh_formation_info_stru)) != EOK) {
1477         return;
1478     }
1479     mesh_formation_info->connected_to_mesh_gate = 0;
1480     mesh_formation_info->number_of_peerings = mac_vap->user_nums;
1481     mesh_formation_info->connected_to_as = 0;
1482 }
1483 
1484 /* ****************************************************************************
1485  功能描述  : 填充Mesh Capability域信息
1486  输入参数  : [1]vap
1487              [2]puc_buffer
1488  返 回 值  : 无
1489 **************************************************************************** */
mac_set_mesh_capability_field(hi_void * vap,hi_u8 * puc_buffer)1490 WIFI_ROM_TEXT hi_void mac_set_mesh_capability_field(hi_void *vap, hi_u8 *puc_buffer)
1491 {
1492     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1493     mesh_capability_stru *mesh_capability = (mesh_capability_stru *)puc_buffer;
1494     /* *********** mesh capability field*********************************
1495     -------------------------------------------------------------
1496     |Accepting Additional Mesh Peering|MCCA Supported|MCCA Enabled|Forwarding|
1497     -------------------------------------------------------------
1498     |BIT0                                           |BIT1                   |BIT2              |BIT3          |
1499     -------------------------------------------------------------
1500     |MBCA Enabled|TBTT Adjusting|Mesh Power Save Level|Reserved|
1501     |BIT4               |BIT5               |BIT6                           |BIT7         |
1502     -------------------------------------------------------------
1503     ************************************************************* */
1504     /* 初始清零 */
1505     if (memset_s(mesh_capability, sizeof(mesh_capability_stru), 0, sizeof(mesh_capability_stru)) != EOK) {
1506         return;
1507     }
1508     mesh_capability->accepting_add_mesh_peerings =
1509         mac_vap->mib_info->wlan_mib_mesh_sta_cfg.dot11_mesh_accepting_additional_peerings;
1510     mesh_capability->mbca_enabled = mac_vap->mib_info->wlan_mib_mesh_sta_cfg.dot11_mbca_activated;
1511     mesh_capability->tbtt_adjusting = mac_vap->mesh_tbtt_adjusting;
1512 }
1513 
1514 /* ****************************************************************************
1515  功能描述  : 填充mesh configuration字段
1516  输入参数  : [1]vap
1517              [2]puc_buffer
1518  输出参数  : [1]puc_ie_len
1519  返 回 值  : 无
1520 **************************************************************************** */
mac_set_mesh_configuration_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1521 WIFI_ROM_TEXT hi_void mac_set_mesh_configuration_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1522 {
1523     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1524 
1525     if (mac_vap->vap_mode != WLAN_VAP_MODE_MESH) {
1526         *puc_ie_len = 0;
1527         return;
1528     }
1529 
1530     if (mac_vap->mib_info->wlan_mib_sta_config.dot11_mesh_activated != HI_TRUE) {
1531         *puc_ie_len = 0;
1532         return;
1533     }
1534 
1535     /* ********************** Mesh Configuration Element*************************
1536     -------------------------------------------------------------------------
1537     |EID |Length |Active Path Selection Protocol Id |Active Path Selection Metric Id |Congestion Control Mode Id|
1538     -------------------------------------------------------------------------
1539     |1   |1      |1                                 |1                               |1                         |
1540     -------------------------------------------------------------------------
1541     |Sync Method ID |Auth Protocol ID |Mesh Formation Info|Mesh Capability|
1542     -------------------------------------------------------------------------
1543     |1              |1                |1                  |1              |
1544     -------------------------------------------------------------------------
1545     ************************************************************************** */
1546     *puc_buffer = MAC_EID_MESH_CONF;
1547     *(puc_buffer + 1) = MAC_MESH_CONF_LEN;
1548 
1549     puc_buffer += MAC_IE_HDR_LEN;
1550 
1551     /* 填充Active Path Selection Protocol Id域信息 */
1552     *puc_buffer = MAC_MIB_MESH_VENDOR_SPECIFIC; /* Vendor Specific */
1553     /* 填充Active Path Selection Metric Id域信息 */
1554     *(puc_buffer + 1) = MAC_MIB_MESH_VENDOR_SPECIFIC; /* Vendor Specific: byte 1 */
1555     /* 填充Congestion Control Mode Id域信息 */
1556     *(puc_buffer + 2) = 0; /* Not activated: byte 2 */
1557     /* 填充Sync Method ID域信息 */
1558     *(puc_buffer + 3) = MAC_MIB_MESH_VENDOR_SPECIFIC; /* Neighbor offset synchronization Method: byte 3 */
1559     /* 填充Auth Protocol ID域信息 */
1560     *(puc_buffer + 4) = /* SAE(1): byte 4 */
1561         mac_vap->mib_info->wlan_mib_mesh_sta_cfg.dot11_mesh_active_authentication_protocol;
1562     puc_buffer += 5; /* Active Path Selection Protocol Id域长度为5 byte */
1563 
1564     /* 填充Mesh Formation Info域信息 */
1565     mac_set_mesh_formation_info_field(vap, puc_buffer);
1566     puc_buffer += MAC_MESH_FORMATION_LEN;
1567     /* 填充Mesh Capability Field 域信息 */
1568     mac_set_mesh_capability_field(vap, puc_buffer);
1569     *puc_ie_len = MAC_IE_HDR_LEN + MAC_MESH_CONF_LEN;
1570 
1571     return;
1572 }
1573 
1574 /* ****************************************************************************
1575  功能描述  : 填充HISI Mesh Optimization域信息
1576  输入参数  : [1]pst_vap
1577              [2]puc_buffer
1578  输出参数  : [1]puc_ie_len
1579  返 回 值  : 无
1580 **************************************************************************** */
mac_set_hisi_mesh_optimization_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1581 WIFI_ROM_TEXT hi_void mac_set_hisi_mesh_optimization_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1582 {
1583     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1584     hi_u8 mesh_vendor_ie_hdr_len = 0;
1585     if (mac_vap->vap_mode != WLAN_VAP_MODE_MESH) {
1586         *puc_ie_len = 0;
1587         return;
1588     }
1589     /* Mesh Optimization: Node Priority, En is MBR, Mesh Accept Sta */
1590     mac_set_mesh_vendor_ie_hdr(puc_buffer, &mesh_vendor_ie_hdr_len);
1591     *(puc_buffer + mesh_vendor_ie_hdr_len) = MAC_OUISUBTYPE_MESH_HISI_OPTIMIZATION;
1592     *(puc_buffer + mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN) = mac_vap->priority;
1593     *(puc_buffer + mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN + 1) = mac_vap->is_mbr;
1594     *(puc_buffer + mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN + 2) = /* accept_sta标志,在IE头部信息后的byte(1+2)位填写 */
1595         mac_vap->mesh_accept_sta;
1596 
1597     /* 更新Element 长度 */
1598     *(puc_buffer + 1) += MAC_MESH_HISI_OPTIMIZATION_LEN + MAC_OUISUBTYPE_LEN;
1599     *(puc_ie_len) = mesh_vendor_ie_hdr_len + MAC_OUISUBTYPE_LEN + MAC_MESH_HISI_OPTIMIZATION_LEN;
1600     return;
1601 }
1602 
1603 /* ****************************************************************************
1604  功能描述  : 填充HISI Mesh Vendor字段(Subtype)
1605  输入参数  : [1]puc_buffer
1606              [2]subtype
1607  输出参数  : [1]puc_ie_len
1608  返 回 值  : 无
1609 **************************************************************************** */
mac_set_mesh_vendor_subtype(hi_u8 * puc_buffer,hi_u8 subtype,hi_u8 * puc_ie_len)1610 WIFI_ROM_TEXT hi_void mac_set_mesh_vendor_subtype(hi_u8 *puc_buffer, hi_u8 subtype, hi_u8 *puc_ie_len)
1611 {
1612     hi_u8 mesh_vendor_ie_hdr_len = 0;
1613 
1614     mac_set_mesh_vendor_ie_hdr(puc_buffer, &mesh_vendor_ie_hdr_len);
1615     *(puc_buffer + mesh_vendor_ie_hdr_len) = subtype;
1616     mesh_vendor_ie_hdr_len += MAC_OUISUBTYPE_LEN;
1617     *(puc_ie_len) = mesh_vendor_ie_hdr_len;
1618     /* 更新IE 长度 */
1619     *(puc_buffer + 1) += MAC_OUISUBTYPE_LEN;
1620 }
1621 #endif
1622 
1623 /* ****************************************************************************
1624  功能描述  : 填充DS参数集
1625  输入参数  : [1]vap
1626              [2]us_frm_type
1627              [3]puc_buffer
1628  输出参数  : [1]puc_ie_len
1629  返 回 值  : 无
1630 **************************************************************************** */
mac_set_dsss_params(hi_void * vap,hi_u16 us_frm_type,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1631 WIFI_ROM_TEXT hi_void mac_set_dsss_params(hi_void *vap, hi_u16 us_frm_type, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1632 {
1633     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1634     hi_u8 chan_num;
1635     mac_device_stru *mac_dev = HI_NULL;
1636 #ifndef _PRE_WLAN_FEATURE_MESH_ROM
1637     hi_unref_param(us_frm_type);
1638 #endif
1639     /* **************************************************************************
1640                         ----------------------------------------
1641                         | Element ID  | Length |Current Channel|
1642                         ----------------------------------------
1643               Octets:   | 1           | 1      | 1             |
1644                         ----------------------------------------
1645     The DSSS Parameter Set element contains information to allow channel number identification for STAs.
1646     ************************************************************************** */
1647     mac_dev = mac_res_get_dev();
1648     chan_num = mac_vap->channel.chan_number;
1649     if ((is_sta(mac_vap)
1650 #ifdef _PRE_WLAN_FEATURE_MESH_ROM
1651         || ((mac_vap->vap_mode == WLAN_VAP_MODE_MESH) && (us_frm_type == WLAN_FC0_SUBTYPE_PROBE_REQ))
1652 #endif
1653         ) && (mac_dev->curr_scan_state == MAC_SCAN_STATE_RUNNING)) {
1654         chan_num = mac_dev->scan_params.ast_channel_list[mac_dev->scan_chan_idx].chan_number;
1655     }
1656     puc_buffer[0] = MAC_EID_DSPARMS;
1657     puc_buffer[1] = MAC_DSPARMS_LEN;
1658     puc_buffer[2] = chan_num; /* DS参数集 byte 2 指示为信道个数 */
1659     *puc_ie_len = MAC_IE_HDR_LEN + MAC_DSPARMS_LEN;
1660 }
1661 
1662 /* ****************************************************************************
1663  功能描述  : 填充Country信息
1664  输入参数  : pst_vap: 指向vap
1665              puc_buffer: 指向buffer
1666  输出参数  : puc_ie_len: element的长度
1667  修改历史      :
1668   1.日    期   : 2013年4月11日
1669     作    者   : HiSilicon
1670     修改内容   : 新生成函数
1671 **************************************************************************** */
mac_set_country_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1672 WIFI_ROM_TEXT hi_void mac_set_country_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1673 {
1674     mac_vap_stru                *mac_vap = (mac_vap_stru *)vap;
1675     mac_regdomain_info_stru     *rd_info = HI_NULL;
1676     hi_u8                    band;
1677     hi_u8                    index;
1678     hi_u8                    len = 0;
1679 
1680     if (mac_vap->mib_info->wlan_mib_sta_config.dot11_multi_domain_capability_activated != HI_TRUE &&
1681         mac_vap->mib_info->wlan_mib_sta_config.dot11_spectrum_management_required != HI_TRUE &&
1682         mac_vap->mib_info->wlan_mib_sta_config.dot11_radio_measurement_activated != HI_TRUE) {
1683         /* 没有使能管制域ie */
1684         *puc_ie_len = 0;
1685         return;
1686     }
1687     /* **************************************************************************
1688                                |....These three fields are repeated...|
1689     -------------------------------------------------------------------------------
1690     |EID | Len | CountryString | First Channel |Number of |Maximum    | Pad       |
1691     |    |     |               |   Number/     |Channels/ |Transmit   |(if needed)|
1692     |    |     |               |   Operating   | Operating|Power Level|           |
1693     |    |     |               |   Extension   | Class    |/Coverage  |           |
1694     |    |     |               |   Identifier  |          |Class      |           |
1695     -------------------------------------------------------------------------------
1696     |1   |1    |3              |1              |1         |1          |0 or 1     |
1697     -------------------------------------------------------------------------------
1698     ************************************************************************** */
1699     /* 读取管制域信息 */
1700     rd_info = mac_get_regdomain_info();
1701     /* 获取当前工作频段 */
1702     band = mac_vap->channel.band;
1703     /* 填写EID, 长度最后填 */
1704     puc_buffer[0] = MAC_EID_COUNTRY;
1705     /* 初始化填写buffer的位置 */
1706     index = MAC_IE_HDR_LEN;
1707     /* 国家码 */
1708     puc_buffer[index++] = (hi_u8)(rd_info->ac_country[0]);
1709     puc_buffer[index++] = (hi_u8)(rd_info->ac_country[1]);
1710     puc_buffer[index++] = ' '; /* 0表示室内室外规定相同 */
1711     if (WLAN_BAND_2G == band) {
1712         mac_set_country_ie_2g(rd_info, &(puc_buffer[index]), &len);
1713     }
1714 
1715     if (len == 0) {
1716         /* 无管制域内容 */
1717         *puc_ie_len = 0;
1718         return;
1719     }
1720     index += len;
1721     /* 如果总长度为奇数,则补1字节pad */
1722     if (index & BIT0) {
1723         puc_buffer[index] = 0;
1724         index += 1;
1725     }
1726     /* 设置信息元素长度 */
1727     puc_buffer[1] = index - MAC_IE_HDR_LEN;
1728     *puc_ie_len = index;
1729 }
1730 
1731 /* ****************************************************************************
1732  功能描述  : 填充power constraint信息
1733  输入参数  : pst_vap: 指向vap
1734              puc_buffer: 指向buffer
1735  输出参数  : puc_ie_len: element的长度
1736  修改历史      :
1737   1.日    期   : 2013年4月12日
1738     作    者   : HiSilicon
1739     修改内容   : 新生成函数
1740 **************************************************************************** */
mac_set_pwrconstraint_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1741 WIFI_ROM_TEXT hi_void mac_set_pwrconstraint_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1742 {
1743     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1744 
1745     /* **************************************************************************
1746                    -------------------------------------------
1747                    |ElementID | Length | LocalPowerConstraint|
1748                    -------------------------------------------
1749        Octets:     |1         | 1      | 1                   |
1750                    -------------------------------------------
1751 
1752     向工作站描述其所允许的最大传输功率,此信息元素记录规定最大值
1753     减去实际使用时的最大值
1754     ************************************************************************** */
1755     if (mac_vap->mib_info->wlan_mib_sta_config.dot11_spectrum_management_required == HI_FALSE) {
1756         *puc_ie_len = 0;
1757         return;
1758     }
1759     *puc_buffer = MAC_EID_PWRCNSTR;
1760     *(puc_buffer + 1) = MAC_PWR_CONSTRAINT_LEN;
1761     /* Note that this field is always set to 0 currently. Ideally            */
1762     /* this field can be updated by having an algorithm to decide transmit   */
1763     /* power to be used in the BSS by the AP.                                */
1764     *(puc_buffer + MAC_IE_HDR_LEN) = 0;
1765     *puc_ie_len = MAC_IE_HDR_LEN + MAC_PWR_CONSTRAINT_LEN;
1766 }
1767 
1768 /* ****************************************************************************
1769  功能描述  : 填充quiet信息
1770  输入参数  : pst_vap: 指向vap
1771              puc_buffer: 指向buffer
1772              uc_qcount  : Quiet Count
1773              uc_qperiod : Quiet Period
1774              us_qdur    : Quiet Duration
1775              us_qoffset : Quiet Offset
1776  输出参数  : puc_ie_len: element的长度
1777  修改历史      :
1778   1.日    期   : 2013年4月12日
1779     作    者   : HiSilicon
1780     修改内容   : 新生成函数
1781 **************************************************************************** */
mac_set_quiet_ie(hi_void * vap,hi_u8 * puc_buffer,const mac_set_quiet_ie_info_stru * mac_set_quiet_ie_info,hi_u8 * puc_ie_len)1782 WIFI_ROM_TEXT hi_void mac_set_quiet_ie(hi_void *vap, hi_u8 *puc_buffer,
1783     const mac_set_quiet_ie_info_stru *mac_set_quiet_ie_info, hi_u8 *puc_ie_len)
1784 {
1785     mac_quiet_ie_stru *quiet = HI_NULL;
1786     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1787     if ((mac_vap->mib_info->wlan_mib_sta_config.dot11_spectrum_management_required != HI_TRUE) &&
1788         (mac_vap->mib_info->wlan_mib_sta_config.dot11_radio_measurement_activated != HI_TRUE)) {
1789         *puc_ie_len = 0;
1790         return;
1791     }
1792     /* **************************************************************************
1793     -----------------------------------------------------------------------------
1794     |ElementID | Length | QuietCount | QuietPeriod | QuietDuration | QuietOffset|
1795     -----------------------------------------------------------------------------
1796     |1         | 1      | 1          | 1           | 2             | 2          |
1797     -----------------------------------------------------------------------------
1798     ************************************************************************** */
1799     if (mac_set_quiet_ie_info->us_qduration == 0 || mac_set_quiet_ie_info->qcount == 0) {
1800         *puc_ie_len = 0;
1801         return;
1802     }
1803     *puc_buffer = MAC_EID_QUIET;
1804     *(puc_buffer + 1) = MAC_QUIET_IE_LEN;
1805     quiet = (mac_quiet_ie_stru *)(puc_buffer + MAC_IE_HDR_LEN);
1806     quiet->quiet_count    = mac_set_quiet_ie_info->qcount;
1807     quiet->quiet_period   = mac_set_quiet_ie_info->qperiod;
1808     quiet->quiet_duration = oal_byteorder_to_le16(mac_set_quiet_ie_info->us_qduration);
1809     quiet->quiet_offset   = oal_byteorder_to_le16(mac_set_quiet_ie_info->us_qoffset);
1810     *puc_ie_len = MAC_IE_HDR_LEN + MAC_QUIET_IE_LEN;
1811 }
1812 
1813 /* ****************************************************************************
1814  功能描述  : 填充tpc report信息
1815  输入参数  : pst_vap: 指向vap
1816              puc_buffer: 指向buffer
1817  输出参数  : puc_ie_len: element的长度
1818  修改历史      :
1819   1.日    期   : 2013年4月12日
1820     作    者   : HiSilicon
1821     修改内容   : 新生成函数
1822 **************************************************************************** */
mac_set_tpc_report_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1823 WIFI_ROM_TEXT hi_void mac_set_tpc_report_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1824 {
1825     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
1826     /* **************************************************************************
1827                 -------------------------------------------------
1828                 |ElementID  |Length  |TransmitPower  |LinkMargin|
1829                 -------------------------------------------------
1830        Octets:  |1          |1       |1              |1         |
1831                 -------------------------------------------------
1832 
1833     TransimitPower, 此帧的传送功率,以dBm为单位
1834     ************************************************************************** */
1835     if (mac_vap->mib_info->wlan_mib_sta_config.dot11_spectrum_management_required == HI_FALSE &&
1836         mac_vap->mib_info->wlan_mib_sta_config.dot11_radio_measurement_activated == HI_FALSE) {
1837         *puc_ie_len = 0;
1838         return;
1839     }
1840     *puc_buffer = MAC_EID_TPCREP;
1841     *(puc_buffer + 1) = MAC_TPCREP_IE_LEN;
1842     *(puc_buffer + 2) = mac_vap->tx_power; /* tpc report byte 2 存储tx_power */
1843     *(puc_buffer + 3) = 0;                 /* tpc report byte 3 字段管理帧中不用 */
1844     *puc_ie_len = MAC_IE_HDR_LEN + MAC_TPCREP_IE_LEN;
1845 }
1846 
1847 /* ****************************************************************************
1848  功能描述  : 填充Quiet信息
1849  输入参数  : pst_vap: 指向vap
1850              puc_buffer: 指向buffer
1851  输出参数  : puc_ie_len: element的长度
1852  修改历史      :
1853   1.日    期   : 2013年4月12日
1854     作    者   : HiSilicon
1855     修改内容   : 新生成函数
1856 **************************************************************************** */
mac_set_erp_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1857 WIFI_ROM_TEXT hi_void mac_set_erp_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1858 {
1859     mac_vap_stru         *mac_vap    = (mac_vap_stru *)vap;
1860     mac_erp_params_stru  *erp_params = HI_NULL;
1861     /***************************************************************************
1862     --------------------------------------------------------------------------
1863     |EID  |Len  |NonERP_Present|Use_Protection|Barker_Preamble_Mode|Reserved|
1864     --------------------------------------------------------------------------
1865     |B0-B7|B0-B7|B0            |B1            |B2                  |B3-B7   |
1866     --------------------------------------------------------------------------
1867     ************************************************************************** */
1868     if (WLAN_LEGACY_11B_MODE == mac_vap->protocol) {
1869         *puc_ie_len = 0;
1870         return; /* 5G频段和11b协议模式 没有erp信息 */
1871     }
1872     *puc_buffer       = MAC_EID_ERP;
1873     *(puc_buffer + 1) = MAC_ERP_IE_LEN;
1874     *(puc_buffer + 2) = 0;  /* Quiet信息byte 2 初始清0 */
1875     erp_params = (mac_erp_params_stru *)(puc_buffer + MAC_IE_HDR_LEN);
1876     /* 如果存在non erp站点与ap关联, 或者obss中存在non erp站点 */
1877     if ((mac_vap->protection.sta_non_erp_num != 0) || (mac_vap->protection.obss_non_erp_present)) {
1878         erp_params->non_erp = 1;
1879     }
1880     /* 如果ap已经启用erp保护 */
1881     if (mac_vap->protection.protection_mode == WLAN_PROT_ERP) {
1882         erp_params->use_protection = 1;
1883     }
1884     /* 如果存在不支持short preamble的站点与ap关联, 或者ap自身不支持short preamble */
1885     if ((mac_vap->protection.sta_no_short_preamble_num != 0) ||
1886         (mac_mib_get_short_preamble_option_implemented(mac_vap) == HI_FALSE)) {
1887         erp_params->preamble_mode = 1;
1888     }
1889     *puc_ie_len = MAC_IE_HDR_LEN + MAC_ERP_IE_LEN;
1890 }
1891 
1892 /* ****************************************************************************
1893  功能描述  : 填充bss load信息
1894  输入参数  : pst_vap: 指向vap
1895              puc_buffer: 指向buffer
1896  输出参数  : puc_ie_len: element的长度
1897  修改历史      :
1898   1.日    期   : 2013年4月12日
1899     作    者   : HiSilicon
1900     修改内容   : 新生成函数
1901 **************************************************************************** */
mac_set_bssload_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)1902 WIFI_ROM_TEXT hi_void mac_set_bssload_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
1903 {
1904     mac_bss_load_stru  *bss_load = HI_NULL;
1905     mac_vap_stru       *mac_vap  = (mac_vap_stru *)vap;
1906     if (mac_vap->mib_info->wlan_mib_sta_config.dot11_qos_option_implemented == HI_FALSE ||
1907         mac_vap->mib_info->wlan_mib_sta_config.dot11_qbss_load_implemented == HI_FALSE) {
1908         *puc_ie_len = 0;
1909         return;
1910     }
1911     /* **************************************************************************
1912     ------------------------------------------------------------------------
1913     |EID |Len |StationCount |ChannelUtilization |AvailableAdmissionCapacity|
1914     ------------------------------------------------------------------------
1915     |1   |1   |2            |1                  |2                         |
1916     ------------------------------------------------------------------------
1917     ************************************************************************** */
1918     puc_buffer[0] = MAC_EID_QBSS_LOAD;
1919     puc_buffer[1] = MAC_BSS_LOAD_IE_LEN;
1920     bss_load = (mac_bss_load_stru *)(puc_buffer + MAC_IE_HDR_LEN);
1921     bss_load->us_sta_count = oal_byteorder_to_le16(mac_vap->user_nums);
1922     bss_load->chan_utilization = 0;
1923     bss_load->us_aac = 0;
1924     *puc_ie_len = MAC_IE_HDR_LEN + MAC_BSS_LOAD_IE_LEN;
1925 }
1926 
1927 /* ****************************************************************************
1928  功能描述  : 填充用户态下发的信息元素到管理帧中
1929  输入参数  : [1]vap
1930              [2]puc_buffer
1931              [3]puc_ie_len
1932              [4]type
1933  返 回 值  : 无
1934 **************************************************************************** */
mac_add_wps_ie(hi_void * vap,hi_u8 * puc_buffer,hi_u16 * pus_ie_len,en_app_ie_type_uint8 type)1935 WIFI_ROM_TEXT hi_void mac_add_wps_ie(hi_void *vap, hi_u8 *puc_buffer, hi_u16 *pus_ie_len, en_app_ie_type_uint8 type)
1936 {
1937     mac_vap_stru    *mac_vap = HI_NULL;
1938     hi_u8           *puc_app_ie  = HI_NULL;
1939     hi_u8           *puc_wps_ie  = HI_NULL;
1940     hi_u32          app_ie_len;
1941 
1942     mac_vap    = (mac_vap_stru *)vap;
1943     puc_app_ie = mac_vap->ast_app_ie[type].puc_ie;
1944     app_ie_len = mac_vap->ast_app_ie[type].ie_len;
1945 
1946     if (app_ie_len == 0) {
1947         *pus_ie_len = 0;
1948         return;
1949     }
1950     puc_wps_ie =
1951         mac_find_vendor_ie(MAC_WLAN_OUI_MICROSOFT, MAC_WLAN_OUI_TYPE_MICROSOFT_WPS, puc_app_ie, (hi_s32)app_ie_len);
1952     if ((puc_wps_ie == HI_NULL) || (puc_wps_ie[1] < MAC_MIN_WPS_IE_LEN)) {
1953         *pus_ie_len = 0;
1954         return;
1955     }
1956     /* 将WPS ie 信息拷贝到buffer 中 */
1957     if (memcpy_s(puc_buffer, puc_wps_ie[1] + MAC_IE_HDR_LEN, puc_wps_ie, puc_wps_ie[1] + MAC_IE_HDR_LEN) != EOK) {
1958         oam_warning_log0(0, 0, "{mac_add_wps_ie::memcpy_s fail!}");
1959         *pus_ie_len = 0;
1960         return;
1961     }
1962 
1963     *pus_ie_len = puc_wps_ie[1] + MAC_IE_HDR_LEN;
1964 }
1965 
1966 /* ****************************************************************************
1967  功能描述  : 封装空桢
1968  输入参数  : header-80211头部指针
1969              us_fc frame control类型
1970              puc_da: 目的mac地址
1971              puc_sa: 源mac地址
1972 **************************************************************************** */
mac_null_data_encap(hi_u8 * header,hi_u16 us_fc,const hi_u8 * da_mac_addr,const hi_u8 * sa_mac_addr)1973 WIFI_ROM_TEXT hi_void mac_null_data_encap(hi_u8 *header, hi_u16 us_fc, const hi_u8 *da_mac_addr,
1974     const hi_u8 *sa_mac_addr)
1975 {
1976     mac_hdr_set_frame_control(header, us_fc);
1977     /* 设置ADDR1为DA|BSSID */
1978     if (memcpy_s((header + WLAN_HDR_ADDR1_OFFSET), WLAN_MAC_ADDR_LEN, da_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
1979         oam_warning_log0(0, 0, "{mac_null_data_encap::memcpy_s fail!}");
1980         return;
1981     }
1982     /* 设置ADDR2为BSSID|SA */
1983     if (memcpy_s((header + WLAN_HDR_ADDR2_OFFSET), WLAN_MAC_ADDR_LEN, sa_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
1984         oam_warning_log0(0, 0, "{mac_null_data_encap::memcpy_s fail!}");
1985         return;
1986     }
1987     if ((us_fc & WLAN_FRAME_FROME_AP) && !(us_fc & WLAN_FRAME_TO_AP)) {
1988         /* 设置ADDR3为SA */
1989         if (memcpy_s((header + WLAN_HDR_ADDR3_OFFSET), WLAN_MAC_ADDR_LEN, sa_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
1990             oam_warning_log0(0, 0, "{mac_null_data_encap::memcpy_s fail!}");
1991             return;
1992         }
1993     } else if (!(us_fc & WLAN_FRAME_FROME_AP) && (us_fc & WLAN_FRAME_TO_AP)) {
1994         /* 设置ADDR3为DA */
1995         if (memcpy_s((header + WLAN_HDR_ADDR3_OFFSET), WLAN_MAC_ADDR_LEN, da_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
1996             oam_warning_log0(0, 0, "{mac_null_data_encap::memcpy_s fail!}");
1997             return;
1998         }
1999     }
2000     /* NULL帧不存在其他DS位 不处理 */
2001 }
2002 
2003 /* ****************************************************************************
2004  功能描述  : 封装action帧头
2005  输入参数  : header-80211头部指针
2006              puc_da: 目的mac地址
2007              puc_sa: 源mac地址
2008  修改历史      :
2009   1.日    期   : 2019年03月08日
2010     作    者   : HiSilicon
2011     修改内容   : 新生成函数
2012 **************************************************************************** */
mac_prepare_action_frame_head(hi_u8 * puc_header,const hi_u8 * da_mac_addr,const hi_u8 * sa_mac_addr)2013 WIFI_ROM_TEXT hi_u32 mac_prepare_action_frame_head(hi_u8 *puc_header, const hi_u8 *da_mac_addr,
2014     const hi_u8 *sa_mac_addr)
2015 {
2016     /* 帧控制字段全为0,除了type和subtype */
2017     mac_hdr_set_frame_control(puc_header, WLAN_PROTOCOL_VERSION | WLAN_FC0_TYPE_MGT | WLAN_FC0_SUBTYPE_ACTION);
2018     /* 设置分片序号为0 */
2019     mac_hdr_set_fragment_number(puc_header, 0);
2020     /* 设置地址1,一般是广播地址 */
2021     if (memcpy_s(puc_header + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN, da_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
2022         oam_error_log0(0, 0, "{mac_prepare_action_frame_head::mem safe func err!}");
2023         return HI_FAIL;
2024     }
2025     /* 设置地址2为自己的MAC地址 */
2026     if (memcpy_s(puc_header + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN, sa_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
2027         oam_error_log0(0, 0, "{mac_prepare_action_frame_head::mem safe func err!}");
2028         return HI_FAIL;
2029     }
2030     /* 地址3,为VAP自己的MAC地址 */
2031     if (memcpy_s(puc_header + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, sa_mac_addr, WLAN_MAC_ADDR_LEN) != EOK) {
2032         oam_error_log0(0, 0, "{mac_prepare_action_frame_head::mem safe func err!}");
2033         return HI_FAIL;
2034     }
2035     return HI_SUCCESS;
2036 }
2037 
2038 /* ****************************************************************************
2039  功能描述  : 封装action帧体
2040  修改历史      :
2041   1.日    期   : 2019年03月08日
2042     作    者   : HiSilicon
2043     修改内容   : 新生成函数
2044 **************************************************************************** */
mac_prepare_action_frame_body(hi_u8 * puc_body,hi_u8 body_len,hi_u8 category,const hi_u8 * puc_elements,hi_u8 element_len)2045 WIFI_ROM_TEXT hi_u8 mac_prepare_action_frame_body(hi_u8 *puc_body, hi_u8 body_len, hi_u8 category,
2046     const hi_u8 *puc_elements, hi_u8 element_len)
2047 {
2048     if (body_len < (WLAN_ACTION_BODY_ELEMENT_OFFSET + element_len)) {
2049         return HI_FALSE;
2050     }
2051 
2052     /* category :127,表示是厂商自定义帧 */
2053     puc_body[WLAN_ACTION_BODY_CATEGORY_OFFSET] = category;
2054     /* 初始化vendor OUI */
2055     puc_body[MAC_ACTION_OUI_POS]     = MAC_WLAN_OUI_VENDOR0;
2056     puc_body[MAC_ACTION_OUI_POS + 1] = MAC_WLAN_OUI_VENDOR1; /* vendor OUI byte(1+1)设置 */
2057     puc_body[MAC_ACTION_OUI_POS + 2] = MAC_WLAN_OUI_VENDOR2; /* vendor OUI byte(1+2)设置 */
2058     /* 设置action类型和子类型 */
2059     puc_body[MAC_ACTION_VENDOR_TYPE_POS] = MAC_OUITYPE_DBAC;
2060     puc_body[MAC_ACTION_VENDOR_SUBTYPE_POS] = MAC_OUISUBTYPE_DBAC_NOA;
2061     /* 设置IE字段 */
2062     if (0 != memcpy_s(puc_body + WLAN_ACTION_BODY_ELEMENT_OFFSET, body_len, puc_elements, element_len)) {
2063         return HI_FALSE;
2064     }
2065 
2066     return HI_TRUE;
2067 }
2068 
2069 /* 代码ROM段结束位置 新增ROM代码请放在SECTION中 */
2070 #undef __WIFI_ROM_SECTION__
2071 
2072 /* ****************************************************************************
2073  功能描述  : STA根据关联用户的能力信息,设置关联请求帧中的cap info
2074  输入参数  : pst_vap      : 指向vap
2075              puc_cap_info : 指向存储能力位信息的buffer
2076  修改历史      :
2077   1.日    期   : 2015年9月7日
2078     作    者   : HiSilicon
2079     修改内容   : 新生成函数
2080 **************************************************************************** */
mac_set_cap_info_sta(hi_void * vap,hi_u8 * puc_cap_info)2081 hi_void mac_set_cap_info_sta(hi_void *vap, hi_u8 *puc_cap_info)
2082 {
2083     mac_cap_info_stru   *cap_info = (mac_cap_info_stru *)puc_cap_info;
2084     mac_vap_stru        *mac_vap  = (mac_vap_stru *)vap;
2085 
2086     /* *************************************************************************
2087          -------------------------------------------------------------------
2088          |B0 |B1  |B2        |B3    |B4     |B5      |B6  |B7     |B8      |
2089          -------------------------------------------------------------------
2090          |ESS|IBSS|CFPollable|CFPReq|Privacy|Preamble|PBCC|Agility|SpecMgmt|
2091          -------------------------------------------------------------------
2092          |B9 |B10      |B11 |B12     |B13      |B14        |B15            |
2093          -------------------------------------------------------------------
2094          |QoS|ShortSlot|APSD|RM      |DSSS-OFDM|Delayed BA |Immediate BA   |
2095          -------------------------------------------------------------------
2096     ************************************************************************** */
2097     /* 学习对端的能力信息 */
2098     if (memcpy_s(puc_cap_info, sizeof(mac_cap_info_stru), (hi_u8 *)(&mac_vap->us_assoc_user_cap_info),
2099         sizeof(mac_cap_info_stru)) != EOK) {
2100         return;
2101     }
2102     /* 以下能力位不学习,保持默认值 */
2103     cap_info->ibss              = 0;
2104     cap_info->cf_pollable       = 0;
2105     cap_info->cf_poll_request   = 0;
2106     cap_info->radio_measurement =
2107         mac_vap->mib_info->wlan_mib_sta_config.dot11_radio_measurement_activated;
2108 }
2109 
2110 #ifdef _PRE_WLAN_FEATURE_PMF
2111 /* ****************************************************************************
2112  功能描述  : 设置Timeout_Interval信息元素
2113  输入参数  : pst_mac_vap   : 指向vap
2114              puc_buffer: 指向buffer
2115              ul_type: Timeout_Interval的类型
2116              puc_sta_addr: ap发送带Timeout_Interval的assoc rsp帧中的DA
2117              puc_ie_len: ie的总长度
2118              pst_sa_query_info :组ASSOCIATION_COMEBACK_TIME时需要吧
2119  修改历史      :
2120   1.日    期   : 2014年4月22日
2121     作    者   : HiSilicon
2122     修改内容   : 新生成函数
2123 **************************************************************************** */
mac_set_timeout_interval_ie(hi_u8 * puc_buffer,hi_u8 * puc_ie_len,hi_u32 type,hi_u32 timeout)2124 hi_void mac_set_timeout_interval_ie(hi_u8 *puc_buffer, hi_u8 *puc_ie_len, hi_u32 type, hi_u32 timeout)
2125 {
2126     mac_timeout_interval_type_enum tie_type;
2127 
2128     tie_type = (mac_timeout_interval_type_enum)type;
2129     *puc_ie_len = 0;
2130     /* 判断是否需要设置timeout_interval IE */
2131     if (tie_type >= MAC_TIE_BUTT) {
2132         return;
2133     }
2134     /* Timeout Interval Parameter Element Format
2135     -----------------------------------------------------------------------
2136     |ElementID | Length | Timeout Interval Type| Timeout Interval Value  |
2137     -----------------------------------------------------------------------
2138     |1         | 1      | 1                    |  4                      |
2139     ----------------------------------------------------------------------- */
2140     puc_buffer[0] = MAC_EID_TIMEOUT_INTERVAL;
2141     puc_buffer[1] = MAC_TIMEOUT_INTERVAL_INFO_LEN;
2142     puc_buffer[2] = tie_type; /* Timeout_Interval byte2 为tie_type */
2143     /* 设置Timeout Interval Value */
2144     puc_buffer[3] = timeout & 0x000000FF;       /* Timeout_Interval byte3 为timeout最低8byte */
2145     puc_buffer[4] = (timeout & 0x0000FF00)>>8;  /* Timeout_Interval byte4 为timeout的bit8 ~ 15 */
2146     puc_buffer[5] = (timeout & 0x00FF0000)>>16; /* Timeout_Interval byte5 为timeout的bit16 ~ 23 */
2147     puc_buffer[6] = (timeout & 0xFF000000)>>24; /* Timeout_Interval byte6 为timeout的bit24 ~ 31 */
2148     *puc_ie_len = MAC_IE_HDR_LEN + MAC_TIMEOUT_INTERVAL_INFO_LEN;
2149 }
2150 #endif /* #ifdef HI_ON_FLASH */
2151 
2152 /* ****************************************************************************
2153  功能描述  : 从RSN ie中获取pmf能力信息
2154  修改历史      :
2155   1.日    期   : 2015年2月7日
2156     作    者   : HiSilicon
2157     修改内容   : 新生成函数
2158 **************************************************************************** */
mac_get_pmf_cap(hi_u8 * puc_ie,hi_u32 ie_len)2159 wlan_pmf_cap_status_uint8 mac_get_pmf_cap(hi_u8 *puc_ie, hi_u32 ie_len)
2160 {
2161     hi_u8 *puc_rsn_ie = HI_NULL;
2162     hi_u16 us_rsn_cap;
2163 
2164     if (oal_unlikely(puc_ie == HI_NULL)) {
2165         return MAC_PMF_DISABLED;
2166     }
2167 
2168     /* 查找RSN信息元素,如果没有RSN信息元素,则按照不支持处理 */
2169     puc_rsn_ie = mac_find_ie(MAC_EID_RSN, puc_ie, ie_len);
2170     /* 根据RSN信息元素, 判断RSN能力是否匹配 */
2171     us_rsn_cap = mac_get_rsn_capability(puc_rsn_ie);
2172     if ((us_rsn_cap & BIT6) && (us_rsn_cap & BIT7)) {
2173         return MAC_PME_REQUIRED;
2174     }
2175     if (us_rsn_cap & BIT7) {
2176         return MAC_PMF_ENABLED;
2177     }
2178     return MAC_PMF_DISABLED;
2179 }
2180 
2181 /* ****************************************************************************
2182  功能描述  : 从beacon帧中获得beacon period
2183  修改历史      :
2184   1.日    期   : 2013年6月20日
2185     作    者   : HiSilicon
2186     修改内容   : 新生成函数
2187 **************************************************************************** */
mac_get_beacon_period(const hi_u8 * puc_beacon_body)2188 hi_u16 mac_get_beacon_period(const hi_u8 *puc_beacon_body)
2189 {
2190     /* *********************************************************************** */
2191     /*                       Beacon Frame - Frame Body                       */
2192     /* --------------------------------------------------------------------- */
2193     /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm   | */
2194     /* --------------------------------------------------------------------- */
2195     /* |8         |2         |2       |2-34 |3-10     |3        |4-256     | */
2196     /* --------------------------------------------------------------------- */
2197     /*                                                                       */
2198     /* *********************************************************************** */
2199     return *((hi_u16 *)(puc_beacon_body + MAC_TIME_STAMP_LEN));
2200 }
2201 
2202 /* ****************************************************************************
2203  功能描述  : 获取dtim period值
2204  修改历史      :
2205   1.日    期   : 2013年10月23日
2206     作    者   : HiSilicon
2207     修改内容   : 新生成函数
2208 **************************************************************************** */
mac_get_dtim_period(hi_u8 * puc_frame_body,hi_u16 us_frame_body_len)2209 hi_u8 mac_get_dtim_period(hi_u8 *puc_frame_body, hi_u16 us_frame_body_len)
2210 {
2211     hi_u8 *puc_ie = HI_NULL;
2212     hi_u16 us_offset;
2213 
2214     us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
2215     if (us_frame_body_len > us_offset) {
2216         puc_ie = mac_find_ie(MAC_EID_TIM, puc_frame_body + us_offset, us_frame_body_len - us_offset);
2217         if ((puc_ie != HI_NULL) && (puc_ie[1] >= MAC_MIN_TIM_LEN)) {
2218             return puc_ie[3]; /* byte 3 为dtim period值 */
2219         }
2220     }
2221     return 0;
2222 }
2223 
2224 /* ****************************************************************************
2225  功能描述  : 获取dtim cnt值
2226  修改历史      :
2227   1.日    期   : 2013年10月23日
2228     作    者   : HiSilicon
2229     修改内容   : 新生成函数
2230 **************************************************************************** */
mac_get_dtim_cnt(hi_u8 * puc_frame_body,hi_u16 us_frame_body_len)2231 hi_u8 mac_get_dtim_cnt(hi_u8 *puc_frame_body, hi_u16 us_frame_body_len)
2232 {
2233     hi_u8 *puc_ie = HI_NULL;
2234     const hi_u16 us_offset = MAC_TIME_STAMP_LEN + MAC_BEACON_INTERVAL_LEN + MAC_CAP_INFO_LEN;
2235 
2236     if (us_frame_body_len > us_offset) {
2237         puc_ie = mac_find_ie(MAC_EID_TIM, puc_frame_body + us_offset, us_frame_body_len - us_offset);
2238         if ((puc_ie != HI_NULL) && (puc_ie[1] >= MAC_MIN_TIM_LEN)) {
2239             return puc_ie[2]; /* byte 2 为dtim cnt值 */
2240         }
2241     }
2242     return 0;
2243 }
2244 
2245 /* ****************************************************************************
2246  功能描述  : 从管理帧中获取wmm ie
2247  修改历史      :
2248   1.日    期   : 2013年6月25日
2249     作    者   : HiSilicon
2250     修改内容   : 新生成函数
2251 **************************************************************************** */
mac_get_wmm_ie(hi_u8 * puc_beacon_body,hi_u16 us_frame_len,hi_u16 us_offset)2252 hi_u8 *mac_get_wmm_ie(hi_u8 *puc_beacon_body, hi_u16 us_frame_len, hi_u16 us_offset)
2253 {
2254     hi_u16 us_index = us_offset;
2255 
2256     /* 寻找TIM信息元素 */
2257     while (us_index < us_frame_len) {
2258         if (mac_is_wmm_ie(puc_beacon_body + us_index) == HI_TRUE) {
2259             return (&puc_beacon_body[us_index]);
2260         } else {
2261             us_index += (MAC_IE_HDR_LEN + puc_beacon_body[us_index + 1]);
2262         }
2263     }
2264     return HI_NULL;
2265 }
2266 
2267 /* ****************************************************************************
2268  功能描述  : 根据rsn_ie获取rsn能力
2269  输入参数  : [1]puc_rsn_ie
2270  返 回 值  : 无
2271 ***************************************************************************** */
mac_get_rsn_capability(const hi_u8 * puc_rsn_ie)2272 hi_u16 mac_get_rsn_capability(const hi_u8 *puc_rsn_ie)
2273 {
2274     hi_u16 us_pairwise_count;
2275     hi_u16 us_akm_count;
2276     hi_u16 us_rsn_capability;
2277     hi_u16 us_index = 0;
2278 
2279     if (puc_rsn_ie == HI_NULL) {
2280         return 0;
2281     }
2282     /* *********************************************************************** */
2283     /*                  RSN Element Format                                   */
2284     /* --------------------------------------------------------------------- */
2285     /* |Element ID | Length | Version | Group Cipher Suite | Pairwise Cipher */
2286     /* --------------------------------------------------------------------- */
2287     /* |     1     |    1   |    2    |         4          |       2         */
2288     /* --------------------------------------------------------------------- */
2289     /* --------------------------------------------------------------------- */
2290     /* Suite Count| Pairwise Cipher Suite List | AKM Suite Count | AKM Suite List */
2291     /* --------------------------------------------------------------------- */
2292     /*            |         4*m                |     2           |   4*n     */
2293     /* --------------------------------------------------------------------- */
2294     /* --------------------------------------------------------------------- */
2295     /* |RSN Capabilities|PMKID Count|PMKID List|Group Management Cipher Suite */
2296     /* --------------------------------------------------------------------- */
2297     /* |        2       |    2      |   16 *s  |               4           | */
2298     /* --------------------------------------------------------------------- */
2299     /*                                                                       */
2300     /* *********************************************************************** */
2301     if (puc_rsn_ie[1] < MAC_MIN_RSN_LEN) {
2302         oam_warning_log1(0, OAM_SF_WPA, "{hmac_get_rsn_capability::invalid rsn ie len[%d].}", puc_rsn_ie[1]);
2303         return 0;
2304     }
2305     us_index += 8; /* 偏移8 byte,获取pairwise_count */
2306     us_pairwise_count = hi_makeu16(puc_rsn_ie[us_index], puc_rsn_ie[us_index + 1]);
2307     if (us_pairwise_count > MAC_PAIRWISE_CIPHER_SUITES_NUM) {
2308         oam_warning_log1(0, OAM_SF_WPA, "{hmac_get_rsn_capability::invalid us_pairwise_count[%d].}", us_pairwise_count);
2309         return 0;
2310     }
2311     us_index += 2 + 4 * (hi_u8)us_pairwise_count; /* 再偏移(2 + 4 * pairwise_count) byte,获取akm_count */
2312     us_akm_count = hi_makeu16(puc_rsn_ie[us_index], puc_rsn_ie[us_index + 1]);
2313     if (us_akm_count > MAC_AUTHENTICATION_SUITE_NUM) {
2314         oam_warning_log1(0, OAM_SF_WPA, "{hmac_get_rsn_capability::invalid us_akm_count[%d].}", us_akm_count);
2315         return 0;
2316     }
2317     us_index += 2 + 4 * (hi_u8)us_akm_count; /* 再偏移(2 + 4 * akm_count) byte,获取rsn_capability */
2318     us_rsn_capability = hi_makeu16(puc_rsn_ie[us_index], puc_rsn_ie[us_index + 1]);
2319     return us_rsn_capability;
2320 }
2321 
2322 /* ****************************************************************************
2323  功能描述  : 设置power capability信息元素
2324  输入参数  : mac_vap_stru *pst_vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len
2325  修改历史      :
2326   1.日    期   : 2013年6月29日
2327     作    者   : HiSilicon
2328     修改内容   : 新生成函数
2329 **************************************************************************** */
mac_set_power_cap_ie(hi_u8 * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)2330 hi_void mac_set_power_cap_ie(hi_u8 *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
2331 {
2332     mac_vap_stru           *mac_vap       = (mac_vap_stru *)vap;
2333     mac_regclass_info_stru *regclass_info = HI_NULL;
2334 
2335     /* *******************************************************************************************
2336             ------------------------------------------------------------------------------------
2337             |ElementID | Length | MinimumTransmitPowerCapability| MaximumTransmitPowerCapability|
2338             ------------------------------------------------------------------------------------
2339     Octets: |1         | 1      | 1                             | 1                             |
2340             -------------------------------------------------------------------------------------
2341 
2342     ******************************************************************************************** */
2343     *puc_buffer       = MAC_EID_PWRCAP;
2344     *(puc_buffer + 1) = MAC_PWR_CAP_LEN;
2345     /* 成功获取管制域信息则根据国家码和TPC设置最大和最小发射功率,否则默认为0 */
2346     regclass_info = mac_get_channel_num_rc_info(mac_vap->channel.band, mac_vap->channel.chan_number);
2347     if (regclass_info != HI_NULL) {
2348         *(puc_buffer + 2) = /* puc_buffer第2 byte 表示最大发射功率 */
2349             (hi_u8)((mac_vap->channel.band == WLAN_BAND_2G) ? 4 : 3); /* 2G场景下最大发射功率为4,否则为3 */
2350         *(puc_buffer + 3) = /* puc_buffer第3 byte 表示最小发射功率 */
2351             oal_min(regclass_info->max_reg_tx_pwr, regclass_info->max_tx_pwr);
2352     } else {
2353         *(puc_buffer + 2) = 0; /* 未获取管制域信息, 将puc_buffer第2 byte(最大发射功率)置为0 */
2354         *(puc_buffer + 3) = 0; /* 未获取管制域信息, 将puc_buffer第3 byte(最小发射功率)置为0 */
2355     }
2356     *puc_ie_len = MAC_IE_HDR_LEN + MAC_PWR_CAP_LEN;
2357 }
2358 
2359 /* ****************************************************************************
2360  功能描述  : 设置支持信道信息元素
2361  输入参数  : [1]vap,
2362              [2]puc_buffer
2363              [3]puc_ie_len
2364  返 回 值  : 无
2365 **************************************************************************** */
mac_set_supported_channel_ie(hi_u8 * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)2366 hi_void mac_set_supported_channel_ie(hi_u8 *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
2367 {
2368     hi_u8 channel_max_num;
2369     hi_u8 channel_idx;
2370     hi_u8 us_channel_ie_len = 0;
2371     hi_u8 *puc_ie_len_buffer = 0;
2372     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
2373     hi_u8 channel_idx_cnt = 0;
2374     if (mac_vap->mib_info->wlan_mib_sta_config.dot11_spectrum_management_required == HI_FALSE ||
2375         mac_vap->mib_info->wlan_mib_sta_config.dot11_extended_channel_switch_activated == HI_TRUE) {
2376         *puc_ie_len = 0;
2377         return;
2378     }
2379 
2380     /* *******************************************************************************************
2381             长度不定,信道号与信道数成对出现
2382             ------------------------------------------------------------------------------------
2383             |ElementID | Length | Fisrt Channel Number| Number of Channels|
2384             ------------------------------------------------------------------------------------
2385     Octets: |1         | 1      | 1                   | 1                 |
2386             -------------------------------------------------------------------------------------
2387 
2388     ******************************************************************************************** */
2389     /* 根据支持的频段获取最大信道个数 */
2390     if (WLAN_BAND_2G == mac_vap->channel.band) {
2391         channel_max_num = (hi_u8)MAC_CHANNEL_FREQ_2_BUTT;
2392     } else {
2393         *puc_ie_len = 0;
2394         return;
2395     }
2396 
2397     *puc_buffer = MAC_EID_SUPPCHAN;
2398     puc_buffer++;
2399     puc_ie_len_buffer = puc_buffer;
2400     /* 填写信道信息 */
2401     for (channel_idx = 0; channel_idx < channel_max_num; channel_idx++) {
2402         /* 修改管制域结构体后,需要增加该是否支持信号的判断 */
2403         if (mac_is_channel_idx_valid(mac_vap->channel.band, channel_idx, HI_NULL) == HI_SUCCESS) {
2404             channel_idx_cnt++;
2405             /* uc_channel_idx_cnt为1的时候表示是第一个可用信道,需要写到Fisrt Channel Number */
2406             if (channel_idx_cnt == 1) {
2407                 puc_buffer++;
2408                 mac_get_channel_num_from_idx(mac_vap->channel.band, channel_idx, puc_buffer);
2409             } else if ((channel_max_num - 1) == channel_idx) {
2410                 /* 将Number of Channels写入帧体中 */
2411                 puc_buffer++;
2412                 *puc_buffer = channel_idx_cnt;
2413                 us_channel_ie_len += 2; /* 信道IE长度每次增加2 byte */
2414             }
2415         } else {
2416             /* uc_channel_idx_cnt不为0的时候表示之前有可用信道,需要将可用信道的长度写到帧体中 */
2417             if (channel_idx_cnt != 0) {
2418                 /* 将Number of Channels写入帧体中 */
2419                 puc_buffer++;
2420                 *puc_buffer = channel_idx_cnt;
2421                 us_channel_ie_len += 2; /* 信道IE长度每次增加2 byte */
2422             }
2423             /* 将Number of Channels统计清零 */
2424             channel_idx_cnt = 0;
2425         }
2426     }
2427     *puc_ie_len_buffer = us_channel_ie_len;
2428     *puc_ie_len = us_channel_ie_len + MAC_IE_HDR_LEN;
2429 }
2430 
2431 /* ****************************************************************************
2432  功能描述  : 设置WMM info element
2433  输入参数  : mac_vap_stru  *pst_vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len
2434  修改历史      :
2435   1.日    期   : 2013年7月1日
2436     作    者   : HiSilicon
2437     修改内容   : 新生成函数
2438   2.日    期   : 2013年10月23日
2439     作    者   : HiSilicon
2440     修改内容   : 修改函数名和填充内容
2441 **************************************************************************** */
mac_set_wmm_ie_sta(hi_u8 * vap,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)2442 hi_void mac_set_wmm_ie_sta(hi_u8 *vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
2443 {
2444     hi_u8 index;
2445     mac_vap_stru *mac_vap = (mac_vap_stru *)vap;
2446     hi_u8     auc_oui[MAC_OUI_LEN] = {(hi_u8)MAC_WLAN_OUI_MICRO0,
2447                                       (hi_u8)MAC_WLAN_OUI_MICRO1, (hi_u8)MAC_WLAN_OUI_MICRO2};
2448 
2449     /* WMM Information Element Format                                */
2450     /* ------------------------------------------------------------- */
2451     /* | 3     | 1        | 1           | 1             | 1        | */
2452     /* ------------------------------------------------------------- */
2453     /* | OUI   | OUI Type | OUI Subtype | Version field | QoS Info | */
2454     /* ------------------------------------------------------------- */
2455     /* 判断STA是否支持WMM */
2456     if (!mac_vap->mib_info->wlan_mib_sta_config.dot11_qos_option_implemented) {
2457         *puc_ie_len = 0;
2458         return;
2459     }
2460 
2461     puc_buffer[0] = MAC_EID_WMM;
2462     puc_buffer[1] = MAC_WMM_INFO_LEN;
2463     index = MAC_IE_HDR_LEN;
2464     /* OUI */
2465     if (memcpy_s(&puc_buffer[index], MAC_OUI_LEN, auc_oui, MAC_OUI_LEN) != EOK) {
2466         return;
2467     }
2468     index += MAC_OUI_LEN;
2469     /* OUI Type */
2470     puc_buffer[index++] = MAC_OUITYPE_WMM;
2471     /* OUI Subtype */
2472     puc_buffer[index++] = MAC_OUISUBTYPE_WMM_INFO;
2473     /* Version field */
2474     puc_buffer[index++] = MAC_OUI_WMM_VERSION;
2475     /* QoS Information Field */
2476     mac_set_qos_info_field(mac_vap, &puc_buffer[index]);
2477     index += MAC_QOS_INFO_LEN;
2478     /* Reserved */
2479     puc_buffer[index++] = 0;
2480     *puc_ie_len = MAC_IE_HDR_LEN + MAC_WMM_INFO_LEN;
2481 }
2482 
2483 /* ****************************************************************************
2484  功能描述  : 设置listen interval信息元素
2485  输入参数  : mac_vap_stru *pst_vap, hi_u8 *puc_buffer, hi_u8 *puc_ie_len
2486  修改历史      :
2487   1.日    期   : 2013年7月1日
2488     作    者   : HiSilicon
2489     修改内容   : 新生成函数
2490 **************************************************************************** */
mac_set_listen_interval_ie(hi_u8 * puc_buffer,hi_u8 * puc_ie_len)2491 hi_void mac_set_listen_interval_ie(hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
2492 {
2493     puc_buffer[0] = 0x03;
2494     puc_buffer[1] = 0x00;
2495     *puc_ie_len = MAC_LIS_INTERVAL_IE_LEN;
2496 }
2497 
2498 /* ****************************************************************************
2499  功能描述  : 设置状态码信息元素
2500  返 回 值  : hi_void
2501  修改历史      :
2502   1.日    期   : 2013年7月1日
2503     作    者   : HiSilicon
2504     修改内容   : 新生成函数
2505 **************************************************************************** */
mac_set_status_code_ie(hi_u8 * puc_buffer,mac_status_code_enum_uint16 status_code)2506 hi_void mac_set_status_code_ie(hi_u8 *puc_buffer, mac_status_code_enum_uint16 status_code)
2507 {
2508     puc_buffer[0] = (hi_u8)(status_code & 0x00FF);
2509     puc_buffer[1] = (hi_u8)((status_code & 0xFF00) >> 8); /* 状态码信息元素byte 1,赋值为status_code高8 byte */
2510 }
2511 
2512 /* ****************************************************************************
2513  功能描述  : 设置AID(扫描ID)信息元素
2514  输入参数  : hi_u8 *puc_buffer, hi_u16 uc_status_code
2515  修改历史      :
2516   1.日    期   : 2013年7月1日
2517     作    者   : HiSilicon
2518     修改内容   : 新生成函数
2519 **************************************************************************** */
mac_set_aid_ie(hi_u8 * puc_buffer,hi_u16 aid)2520 hi_void mac_set_aid_ie(hi_u8 *puc_buffer, hi_u16 aid)
2521 {
2522     /* The 2 MSB bits of Association ID is set to 1 as required by the standard. */
2523     aid |= 0xC000;
2524     puc_buffer[0] = (aid & 0x00FF);
2525     puc_buffer[1] = (aid & 0xFF00) >> 8; /* 扫描ID信息元素byte 1,赋值为aid高8 byte */
2526 }
2527 
2528 /* ****************************************************************************
2529  函 数 名  : mac_get_bss_type
2530  功能描述  : 获取BSS的类型
2531  修改历史      :
2532   1.日    期   : 2013年7月8日
2533     作    者   : HiSilicon
2534     修改内容   : 新生成函数
2535 **************************************************************************** */
mac_get_bss_type(hi_u16 us_cap_info)2536 hi_u8 mac_get_bss_type(hi_u16 us_cap_info)
2537 {
2538     mac_cap_info_stru *cap_info = (mac_cap_info_stru *)&us_cap_info;
2539 
2540     if (cap_info->ess != 0) {
2541         return (hi_u8)WLAN_MIB_DESIRED_BSSTYPE_INFRA;
2542     }
2543     if (cap_info->ibss != 0) {
2544         return (hi_u8)WLAN_MIB_DESIRED_BSSTYPE_INDEPENDENT;
2545     }
2546     return (hi_u8)WLAN_MIB_DESIRED_BSSTYPE_ANY;
2547 }
2548 
2549 /* ****************************************************************************
2550  功能描述  : 检查CAP INFO中privacy 是否加密
2551  修改历史      :
2552   1.日    期   : 2013年7月8日
2553     作    者   : HiSilicon
2554     修改内容   : 新生成函数
2555 **************************************************************************** */
mac_check_mac_privacy(hi_u16 us_cap_info,hi_u8 * vap)2556 hi_u8 mac_check_mac_privacy(hi_u16 us_cap_info, hi_u8 *vap)
2557 {
2558     mac_vap_stru       *mac_vap = HI_NULL;
2559     mac_cap_info_stru  *cap_info = (mac_cap_info_stru *)&us_cap_info;
2560 
2561     mac_vap = (mac_vap_stru *)vap;
2562     if (mac_vap->mib_info->wlan_mib_privacy.dot11_privacy_invoked) {
2563         /* 该VAP有Privacy invoked但其他VAP没有 */
2564         if (cap_info->privacy == 0) {
2565             return HI_FALSE;
2566         }
2567     }
2568     /* 考虑兼容性,当vap不支持加密时,不检查用户的能力 */
2569     return HI_TRUE;
2570 }
2571 
2572 /* ****************************************************************************
2573  功能描述  : 设置LLC SNAP, TX流程上调用
2574  输入参数  : pst_buf netbuf结构体 us_ether_type 以太网类型
2575 **************************************************************************** */
mac_set_snap(oal_netbuf_stru * netbuf,hi_u16 us_ether_type,hi_u8 offset)2576 hi_void mac_set_snap(oal_netbuf_stru *netbuf, hi_u16 us_ether_type, hi_u8 offset)
2577 {
2578     mac_llc_snap_stru *llc = HI_NULL;
2579     hi_u16 use_btep1;
2580     hi_u16 use_btep2;
2581 
2582     /* LLC */
2583     llc = (mac_llc_snap_stru *)(oal_netbuf_data(netbuf) + offset);
2584     llc->llc_dsap = SNAP_LLC_LSAP;
2585     llc->llc_ssap = SNAP_LLC_LSAP;
2586     llc->control  = LLC_UI;
2587 
2588     use_btep1 = hi_swap_byteorder_16(ETHER_TYPE_AARP);
2589     use_btep2 = hi_swap_byteorder_16(ETHER_TYPE_IPX);
2590     if (oal_unlikely((use_btep1 == us_ether_type) || (use_btep2 == us_ether_type))) {
2591         llc->auc_org_code[0] = SNAP_BTEP_ORGCODE_0; /* org_code[0]:0x0 */
2592         llc->auc_org_code[1] = SNAP_BTEP_ORGCODE_1; /* org_code[1]:0x0 */
2593         llc->auc_org_code[2] = SNAP_BTEP_ORGCODE_2; /* org_code[2]:0xf8 */
2594     } else {
2595         llc->auc_org_code[0] = SNAP_RFC1042_ORGCODE_0; /* org_code[0]:0x0 */
2596         llc->auc_org_code[1] = SNAP_RFC1042_ORGCODE_1; /* org_code[1]:0x0 */
2597         llc->auc_org_code[2] = SNAP_RFC1042_ORGCODE_2; /* org_code[2]:0x0 */
2598     }
2599     llc->us_ether_type = us_ether_type;
2600     oal_netbuf_pull(netbuf, offset);
2601 }
2602 
2603 /* ****************************************************************************
2604  功能描述  : 获取mac头中的qos ctrl字段
2605 **************************************************************************** */
mac_get_qos_ctrl(const hi_u8 * puc_mac_hdr,hi_u8 * puc_qos_ctrl)2606 hi_void mac_get_qos_ctrl(const hi_u8 *puc_mac_hdr, hi_u8 *puc_qos_ctrl)
2607 {
2608     if (!mac_is_4addr(puc_mac_hdr)) {
2609         if (memcpy_s(puc_qos_ctrl, MAC_QOS_CTL_LEN, puc_mac_hdr + MAC_QOS_CTRL_FIELD_OFFSET, MAC_QOS_CTL_LEN) != EOK) {
2610             oam_error_log0(0, 0, "{mac_get_qos_ctrl::memcpy_s fail.}");
2611             return;
2612         }
2613         return;
2614     }
2615     if (memcpy_s(puc_qos_ctrl, MAC_QOS_CTL_LEN, puc_mac_hdr + MAC_QOS_CTRL_FIELD_OFFSET_4ADDR, MAC_QOS_CTL_LEN) !=  EOK) {
2616         oam_error_log0(0, 0, "{mac_get_qos_ctrl::memcpy_s fail.}");
2617         return;
2618     }
2619 }
2620 
2621 /* ****************************************************************************
2622  功能描述  : 填充厂商自定义ie
2623  输入参数  : pst_vap: 指向vap
2624              puc_buffer: 指向buffer
2625  输出参数  : puc_ie_len: element的长度
2626  修改历史      :
2627   1.日    期   : 2014年6月12日
2628     作    者   : HiSilicon
2629     修改内容   : 新生成函数
2630   2.日    期   : 2015年11月18日
2631     作    者   : HiSilicon
2632     修改内容   : 分配2.4G 11ac私有增强OUI和Type
2633 **************************************************************************** */
mac_set_vendor_hisi_ie(hi_u8 * puc_buffer,hi_u8 * puc_ie_len)2634 hi_void mac_set_vendor_hisi_ie(hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
2635 {
2636     mac_ieee80211_vendor_ie_stru *vendor_ie;
2637 
2638     vendor_ie = (mac_ieee80211_vendor_ie_stru *)puc_buffer;
2639     vendor_ie->element_id = MAC_EID_VENDOR;
2640     vendor_ie->len = sizeof(mac_ieee80211_vendor_ie_stru) - MAC_IE_HDR_LEN;
2641 
2642     /* 此值参照a公司所写 */
2643     vendor_ie->oui_type = MAC_EID_VHT_TYPE;
2644     vendor_ie->auc_oui[0] = (hi_u8)((MAC_VENDER_IE >> 16) & 0xff); /* oui[0]由最低HW IE次最高16 bit获取 */
2645     vendor_ie->auc_oui[1] = (hi_u8)((MAC_VENDER_IE >> 8) & 0xff);  /* oui[1]由最低HW IE次低8 bit获取 */
2646     vendor_ie->auc_oui[2] = (hi_u8)((MAC_VENDER_IE) & 0xff);       /* oui[2]由最低HW IE最低8 bit获取 */
2647     *puc_ie_len = sizeof(mac_ieee80211_vendor_ie_stru);
2648 }
2649 
2650 
2651 /* ****************************************************************************
2652  功能描述  : 判断是否是厂家自定义Action类型
2653  修改历史      :
2654   1.日    期   : 2019年4月15日
2655     作    者   : HiSilicon
2656     修改内容   : 新生成函数
2657 **************************************************************************** */
mac_check_is_vendor_action(hi_u32 oui,const hi_u8 * puc_ies,hi_u16 us_len)2658 WIFI_ROM_TEXT hi_u8 mac_check_is_vendor_action(hi_u32 oui, const hi_u8 *puc_ies, hi_u16 us_len)
2659 {
2660     hi_u32 ie_oui;
2661 
2662     if (us_len < 4) { /* puc_ies大小不小于4字节 */
2663         return HI_FALSE;
2664     }
2665 
2666     ie_oui = (puc_ies[1] << 16) | (puc_ies[2] << 8) | puc_ies[3]; /* 获OUI类型,byte 1在高16bit,byte 2在bit8~15,byte 3 */
2667     if (ie_oui == oui) {
2668         return HI_TRUE;
2669     }
2670 
2671     return HI_FALSE;
2672 }
2673 
2674 /* ****************************************************************************
2675  功能描述  : 判断是否是厂家自定义Action类型帧
2676  输入参数  : [1]oui
2677              [2]oui_type
2678              [3]puc_ies
2679              [4]l_len
2680  返 回 值  : hi_u8 *类型指针,HI_NULL表示没有找到对应vendor action位置
2681 **************************************************************************** */
mac_find_vendor_action(hi_u32 oui,hi_u8 oui_type,const hi_u8 * puc_ies,hi_s32 l_len)2682 hi_u8 mac_find_vendor_action(hi_u32 oui, hi_u8 oui_type, const hi_u8 *puc_ies, hi_s32 l_len)
2683 {
2684     hi_u32 ie_oui;
2685     hi_u8 type;
2686 
2687     if ((puc_ies == HI_NULL) || (l_len <= MAC_ACTION_VENDOR_TYPE_POS)) {
2688         return HI_FALSE;
2689     }
2690 
2691     if (puc_ies[0] != MAC_ACTION_CATEGORY_VENDOR) {
2692         return HI_FALSE;
2693     }
2694 
2695     type = puc_ies[MAC_ACTION_VENDOR_TYPE_POS];
2696     ie_oui = (puc_ies[1] << 16) | (puc_ies[2] << 8) | puc_ies[3]; /* 16:左移位数;2:数组位数;8:左移位数;3:数组位数 */
2697     if ((ie_oui == oui) && (type == oui_type)) {
2698         return HI_TRUE;
2699     }
2700 
2701     return HI_FALSE;
2702 }
2703 
2704 /* ****************************************************************************
2705  * 功能描述  : 设置管理帧头
2706  * 输入参数  : mac_header MAC 头指针,frame_type : Frame Control,
2707  * addr1,addr2,addr3: mac addrsss
2708  * *************************************************************************** */
mac_set_mgmt_frame_header(hi_u8 * mac_header,hi_u16 frame_type,const hi_u8 * addr1,const hi_u8 * addr2,const hi_u8 * addr3)2709 WIFI_ROM_TEXT hi_u16 mac_set_mgmt_frame_header(hi_u8 *mac_header, hi_u16 frame_type, const hi_u8 *addr1,
2710     const hi_u8 *addr2, const hi_u8 *addr3)
2711 {
2712     /* *********************************************************************** */
2713     /*                        Management Frame Format                        */
2714     /* --------------------------------------------------------------------  */
2715     /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS|  */
2716     /* --------------------------------------------------------------------  */
2717     /* | 2           |2       |6 |6 |6    |2               |0 - 2312  |4  |  */
2718     /* --------------------------------------------------------------------  */
2719     /*                                                                       */
2720     /* *********************************************************************** */
2721     mac_hdr_set_frame_control(mac_header, frame_type);
2722 
2723     /* 设置duration为0,由硬件填 */
2724     mac_hdr_set_duration(mac_header, frame_type, 0);
2725 
2726     /* 设置地址1, 2, 3  */
2727     if (mac_hdr_set_mac_addrsss(mac_header, addr1, addr2, addr3) == 0) {
2728         return 0;
2729     }
2730 
2731     /* 设置分片序号, 管理帧为0 */
2732     mac_hdr_set_fragment_number(mac_header, 0);
2733 
2734     return MAC_80211_FRAME_LEN;
2735 }
2736 
2737 #ifdef __cplusplus
2738 #if __cplusplus
2739 }
2740 #endif
2741 #endif
2742