• 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   头文件包含
21 **************************************************************************** */
22 #include "dmac_ext_if.h"
23 #include "frw_event.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 /* ****************************************************************************
32   函数定义
33 **************************************************************************** */
34 /* dmac -> hmac cb字段转换 */
get_mac_rx_ctl(hmac_rx_ctl_stru * hmac_rx_ctl,const dmac_rx_ctl_stru * dmac_rx_ctl)35 hi_void get_mac_rx_ctl(hmac_rx_ctl_stru *hmac_rx_ctl, const dmac_rx_ctl_stru *dmac_rx_ctl)
36 {
37     hmac_rx_ctl->amsdu_enable    = dmac_rx_ctl->rx_info.amsdu_enable;
38     hmac_rx_ctl->buff_nums       = dmac_rx_ctl->rx_info.buff_nums;
39     hmac_rx_ctl->us_da_user_idx  = dmac_rx_ctl->rx_info.da_user_idx;
40     hmac_rx_ctl->is_first_buffer = dmac_rx_ctl->rx_info.is_first_buffer;
41     hmac_rx_ctl->is_fragmented   = dmac_rx_ctl->rx_info.is_fragmented;
42     hmac_rx_ctl->mac_header_len  = dmac_rx_ctl->rx_info.mac_header_len;
43     hmac_rx_ctl->us_ta_user_idx  = dmac_rx_ctl->rx_info.ta_user_idx;
44     hmac_rx_ctl->vap_id          = dmac_rx_ctl->rx_info.vap_id;
45     hmac_rx_ctl->msdu_in_buffer  = dmac_rx_ctl->rx_info.msdu_in_buffer;
46     hmac_rx_ctl->us_frame_len    = dmac_rx_ctl->rx_info.us_frame_len;
47     hmac_rx_ctl->mac_vap_id      = dmac_rx_ctl->rx_info.mac_vap_id;
48     hmac_rx_ctl->channel_number  = dmac_rx_ctl->rx_info.channel_number;
49     hmac_rx_ctl->is_beacon       = dmac_rx_ctl->rx_info.is_beacon;
50     hmac_rx_ctl->rssi_dbm        = dmac_rx_ctl->rx_statistic.rssi_dbm;
51 }
52 
hmac_hcc_rx_event_comm_adapt(const frw_event_mem_stru * hcc_event_mem)53 hi_u32 hmac_hcc_rx_event_comm_adapt(const frw_event_mem_stru *hcc_event_mem)
54 {
55     hi_u8                       mac_header_len;
56     frw_event_hdr_stru         *event_hdr = HI_NULL;
57     hcc_event_stru             *hcc_event_payload = HI_NULL;
58 
59     hmac_rx_ctl_stru           *pst_rx_ctrl = HI_NULL;
60     hi_u8                      *hcc_extend_hdr = HI_NULL;
61 
62     /* step1 提取嵌套的业务事件类型 */
63     event_hdr           = frw_get_event_hdr(hcc_event_mem);
64     hcc_event_payload   = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
65     /* 完成从51Mac rx ctl 到02 Mac rx ctl的拷贝,传到此处,pad_payload已经是0 */
66     /* hcc protocol header
67         |-------hcc total(64B)-----|-----------package mem--------------|
68         |hcc hdr|pad hdr|hcc extend|pad_payload|--------payload---------|
69     */
70     if (OAL_WARN_ON(hcc_event_payload->netbuf == HI_NULL)) {
71         oam_error_log0(0, OAM_SF_ANY, "hmac_hcc_rx_event_comm_adapt: did't found netbuf!");
72         return HI_FAIL;
73     }
74     hcc_extend_hdr = oal_netbuf_data((oal_netbuf_stru *)hcc_event_payload->netbuf);
75     mac_header_len = ((dmac_rx_ctl_stru *)hcc_extend_hdr)->rx_info.mac_header_len;
76     if (mac_header_len) {
77         if (mac_header_len > WLAN_MAX_MAC_HDR_LEN) {
78             oam_error_log3(event_hdr->vap_id, OAM_SF_ANY, "invalid mac header len: %d,main: %d,sub: %d",
79                            mac_header_len, event_hdr->type, event_hdr->sub_type);
80             oal_print_hex_dump(hcc_extend_hdr,
81                 (hi_s32)oal_netbuf_len((oal_netbuf_stru *)hcc_event_payload->netbuf),
82                 32, "invalid mac header len");  /* group size 32 */
83             return HI_FAIL;
84         }
85 
86         pst_rx_ctrl = (hmac_rx_ctl_stru *)oal_netbuf_cb((oal_netbuf_stru *)hcc_event_payload->netbuf);
87         get_mac_rx_ctl(pst_rx_ctrl, (dmac_rx_ctl_stru *)hcc_extend_hdr);
88 
89         /* 需要修改pst_rx_ctrl中所有指针 */
90         pst_rx_ctrl->pul_mac_hdr_start_addr =
91             (hi_u32 *)(hcc_extend_hdr + HI_MAX_DEV_CB_LEN + WLAN_MAX_MAC_HDR_LEN - pst_rx_ctrl->mac_header_len);
92 
93         /* 将mac header的内容向高地址偏移8个字节拷贝,使得mac header和payload的内容连续 */
94         if (memmove_s((hi_u8 *)pst_rx_ctrl->pul_mac_hdr_start_addr, pst_rx_ctrl->mac_header_len,
95             (hi_u8 *)((hi_u8 *)pst_rx_ctrl->pul_mac_hdr_start_addr -
96             (WLAN_MAX_MAC_HDR_LEN - pst_rx_ctrl->mac_header_len)),
97             pst_rx_ctrl->mac_header_len) != EOK) {
98             return HI_FAIL;
99         }
100 
101         /* 将netbuff data指针移到payload位置 */
102         oal_netbuf_pull(hcc_event_payload->netbuf,
103             HI_MAX_DEV_CB_LEN + (WLAN_MAX_MAC_HDR_LEN - pst_rx_ctrl->mac_header_len));
104     } else {
105         oal_netbuf_pull(hcc_event_payload->netbuf, (HI_MAX_DEV_CB_LEN + WLAN_MAX_MAC_HDR_LEN));
106     }
107 
108     return HI_SUCCESS;
109 }
110 
hmac_hcc_expand_rx_adpat_event(const frw_event_mem_stru * hcc_event_mem,hi_u32 event_size)111 frw_event_mem_stru *hmac_hcc_expand_rx_adpat_event(const frw_event_mem_stru *hcc_event_mem, hi_u32 event_size)
112 {
113     frw_event_hdr_stru             *hcc_event_hdr;
114     hcc_event_stru                 *hcc_event_payload;
115     oal_netbuf_stru                *hcc_netbuf;
116     frw_event_type_enum_uint8       en_type;
117     hi_u8                           sub_type;
118     hi_u8                           vap_id;
119     frw_event_mem_stru             *event_mem;              /* 业务事件相关信息 */
120 
121     /* 提取HCC事件信息 */
122     hcc_event_hdr       = frw_get_event_hdr(hcc_event_mem);
123     hcc_event_payload   = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
124     hcc_netbuf          = hcc_event_payload->netbuf;
125     en_type             = hcc_event_hdr->type;
126     sub_type            = hcc_event_hdr->sub_type;
127     vap_id              = hcc_event_hdr->vap_id;
128 
129     /* 申请业务事件 */
130     event_mem = frw_event_alloc((hi_u16)event_size);
131     if (OAL_WARN_ON(event_mem == HI_NULL)) {
132         oam_warning_log1(0, 0, "hmac_hcc_expand_rx_adpat_event:: alloc event failed, event len[%d]", event_size);
133         /* 释放hcc事件中申请的netbuf内存 */
134         oal_netbuf_free(hcc_netbuf);
135         return HI_NULL;
136     }
137 
138     /* 填业务事件头 */
139     frw_event_hdr_init(frw_get_event_hdr(event_mem),
140                        en_type,
141                        sub_type,
142                        (hi_u16)event_size,
143                        FRW_EVENT_PIPELINE_STAGE_1,
144                        vap_id);
145 
146     return event_mem;
147 }
148 
149 /* Hmac 模块将netbuf中的事件内容还原到事件内存中 */
hmac_hcc_rx_netbuf_convert_to_event(const frw_event_mem_stru * hcc_event_mem,hi_u32 revert_size)150 frw_event_mem_stru *hmac_hcc_rx_netbuf_convert_to_event(const frw_event_mem_stru *hcc_event_mem, hi_u32 revert_size)
151 {
152     hcc_event_stru                 *hcc_event_payload = HI_NULL;
153     oal_netbuf_stru                *hcc_netbuf = HI_NULL;
154     frw_event_mem_stru             *event_mem = HI_NULL;              /* 业务事件相关信息 */
155     hi_u32 ret;
156 
157     if (OAL_WARN_ON(hcc_event_mem == HI_NULL)) {
158         return HI_NULL;
159     }
160 
161     /* filter the extend buf */
162     ret = hmac_hcc_rx_event_comm_adapt(hcc_event_mem);
163     if (ret != HI_SUCCESS) {
164         oam_error_log0(0, 0, "hmac_hcc_rx_netbuf_convert_to_event: call hmac_hcc_rx_event_comm_adapt fail!");
165     }
166 
167     hcc_event_payload   = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
168     hcc_netbuf          = hcc_event_payload->netbuf;
169 
170     if (OAL_WARN_ON(hcc_netbuf == HI_NULL)) {
171         oam_error_log0(0, OAM_SF_ANY, "Fatal Error, payload did't contain any netbuf!");
172         return HI_NULL;
173     }
174 
175     if (revert_size > oal_netbuf_len(hcc_netbuf)) {
176         revert_size = oal_netbuf_len(hcc_netbuf);
177     }
178 
179     event_mem = hmac_hcc_expand_rx_adpat_event(hcc_event_mem, revert_size);
180     if (event_mem == HI_NULL) {
181         return HI_NULL;
182     }
183 
184     if (revert_size) {
185         if (memcpy_s((hi_u8 *)frw_get_event_payload(event_mem), revert_size, (hi_u8 *)oal_netbuf_data(hcc_netbuf),
186             revert_size) != EOK) {
187             return HI_NULL;
188         }
189     }
190 
191     /* 释放hcc事件中申请的netbuf内存 */
192     oal_netbuf_free(hcc_netbuf);
193 
194     return event_mem;
195 }
196 
hmac_hcc_rx_convert_netbuf_to_event_default(frw_event_mem_stru * hcc_event_mem)197 frw_event_mem_stru *hmac_hcc_rx_convert_netbuf_to_event_default(frw_event_mem_stru *hcc_event_mem)
198 {
199     hcc_event_stru *hcc_event_payload = HI_NULL;
200 
201     if (OAL_WARN_ON(hcc_event_mem == HI_NULL)) {
202         return HI_NULL;
203     }
204 
205     hcc_event_payload = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
206     return hmac_hcc_rx_netbuf_convert_to_event(hcc_event_mem, hcc_event_payload->buf_len);
207 }
208 
hmac_rx_convert_netbuf_to_netbuf_default(frw_event_mem_stru * hcc_event_mem)209 frw_event_mem_stru *hmac_rx_convert_netbuf_to_netbuf_default(frw_event_mem_stru *hcc_event_mem)
210 {
211     hcc_event_stru                  *hcc_event_payload = HI_NULL;
212     frw_event_mem_stru              *event_mem = HI_NULL;
213     dmac_tx_event_stru              *dmax_ctx_event = HI_NULL;
214     hmac_rx_ctl_stru                *hmac_rx_ctrl = HI_NULL;
215     hi_u32 ret;
216 
217     hcc_event_payload = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
218 
219     /* filter the extend buf */
220     ret = hmac_hcc_rx_event_comm_adapt(hcc_event_mem);
221     if (ret != HI_SUCCESS) {
222         oam_error_log0(0, 0, "hmac_hcc_rx_netbuf_convert_to_event: call hmac_hcc_rx_event_comm_adapt fail!");
223     }
224 
225     event_mem = hmac_hcc_expand_rx_adpat_event(hcc_event_mem, sizeof(dmac_tx_event_stru));
226     if (event_mem == HI_NULL) {
227         return HI_NULL;
228     }
229 
230     hmac_rx_ctrl                 = (hmac_rx_ctl_stru *)oal_netbuf_cb((oal_netbuf_stru *)hcc_event_payload->netbuf);
231     dmax_ctx_event               = (dmac_tx_event_stru *)frw_get_event_payload(event_mem);
232 
233     dmax_ctx_event->netbuf       = hcc_event_payload->netbuf;
234     dmax_ctx_event->us_frame_len = oal_netbuf_len((oal_netbuf_stru *)hcc_event_payload->netbuf) -
235                                    hmac_rx_ctrl->mac_header_len;
236 
237     return event_mem;
238 }
239 
hmac_rx_process_data_sta_rx_adapt(frw_event_mem_stru * hcc_event_mem)240 frw_event_mem_stru *hmac_rx_process_data_sta_rx_adapt(frw_event_mem_stru *hcc_event_mem)
241 {
242     hcc_event_stru                  *hcc_event_payload;
243     frw_event_mem_stru              *event_mem = HI_NULL;
244     dmac_wlan_drx_event_stru        *wlan_rx_event = HI_NULL;
245     hi_u32 ret;
246 
247     hcc_event_payload = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
248 
249     /* filter the extend buf */
250     ret = hmac_hcc_rx_event_comm_adapt(hcc_event_mem);
251     if (ret != HI_SUCCESS) {
252         oam_error_log0(0, 0, "hmac_hcc_rx_netbuf_convert_to_event: call hmac_hcc_rx_event_comm_adapt fail!");
253     }
254 
255     event_mem = hmac_hcc_expand_rx_adpat_event(hcc_event_mem, sizeof(dmac_wlan_drx_event_stru));
256     if (event_mem == HI_NULL) {
257         return HI_NULL;
258     }
259 
260     /* 填业务事件信息 */
261     wlan_rx_event                 = (dmac_wlan_drx_event_stru *)frw_get_event_payload(event_mem);
262     wlan_rx_event->netbuf         = hcc_event_payload->netbuf;
263     wlan_rx_event->us_netbuf_num  = 1; /* 目前不支持通过SDIO后组链,默认都是单帧 */
264 
265     return event_mem;
266 }
267 
hmac_rx_process_mgmt_event_rx_adapt(frw_event_mem_stru * hcc_event_mem)268 frw_event_mem_stru *hmac_rx_process_mgmt_event_rx_adapt(frw_event_mem_stru *hcc_event_mem)
269 {
270     hcc_event_stru                  *hcc_event_payload;
271     frw_event_mem_stru              *event_mem = HI_NULL;
272     dmac_wlan_crx_event_stru        *wlan_rx_event = HI_NULL;
273     hi_u32 ret;
274 
275     /* 取HCC事件信息 */
276     hcc_event_payload = (hcc_event_stru *)frw_get_event_payload(hcc_event_mem);
277 
278     /* filter the extend buf */
279     ret = hmac_hcc_rx_event_comm_adapt(hcc_event_mem);
280     if (ret != HI_SUCCESS) {
281         oam_error_log0(0, 0, "hmac_hcc_rx_netbuf_convert_to_event: call hmac_hcc_rx_event_comm_adapt fail!");
282     }
283 
284     event_mem = hmac_hcc_expand_rx_adpat_event(hcc_event_mem, sizeof(dmac_wlan_crx_event_stru));
285     if (event_mem == HI_NULL) {
286         return HI_NULL;
287     }
288 
289     /* 填业务事件信息 */
290     wlan_rx_event                 = (dmac_wlan_crx_event_stru *)frw_get_event_payload(event_mem);
291     wlan_rx_event->netbuf         = hcc_event_payload->netbuf;
292 
293     return event_mem;
294 }
295 
296 #ifdef __cplusplus
297 #if __cplusplus
298 }
299 #endif
300 #endif
301