1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description: oal net interface
15 * Create: 2020-05-02
16 */
17
18 #ifndef __OAL_NET_HCM_H__
19 #define __OAL_NET_HCM_H__
20 #if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
21 #include <linux/version.h>
22 #include <net/iw_handler.h>
23 #include <linux/netdevice.h>
24 #endif
25 #if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
26 #include "oal_mm.h"
27 #include "lwip/netif.h"
28 #include "lwip/dhcp.h"
29 #include "eth_ip_common_rom.h"
30 #endif
31 #include "oal_util.h"
32 #include "oal_skbuff.h"
33 #include "oal_netbuf_ext.h"
34 #include "oal_net_cfg80211.h"
35
36 #ifdef __cplusplus
37 #if __cplusplus
38 extern "C" {
39 #endif
40 #endif
41
42 /*****************************************************************************
43 2 宏定义
44 *****************************************************************************/
45 /* xr util还未融合,OAL_DECLARE_PACKED暂时在此处重复定义 */
46 #define OAL_DECLARE_PACKED __attribute__((__packed__))
47 #define OAL_NETBUF_DEFAULT_DATA_OFFSET 48 /* 5115上实际测得data比head大48,用于netbuf data指针复位 */
48
49 #define OAL_ASSOC_REQ_IE_OFFSET 28 /* 上报内核关联请求帧偏移量 */
50 #define OAL_ASSOC_RSP_IE_OFFSET 30 /* 上报内核关联响应帧偏移量 */
51 #define OAL_AUTH_IE_OFFSET 30
52 #define OAL_FT_ACTION_IE_OFFSET 40
53 #define OAL_ASSOC_RSP_FIXED_OFFSET 6 /* 关联响应帧帧长FIXED PARAMETERS偏移量 */
54 #define OAL_PMKID_LEN 16
55 #define OAL_WPA_KEY_LEN 32
56 #define OAL_WPA_SEQ_LEN 16
57 #define OAL_WLAN_SA_QUERY_TR_ID_LEN 2
58 #define OAL_BITFIELD_LITTLE_ENDIAN 0
59 #define OAL_BITFIELD_BIG_ENDIAN 1
60 /*
61 * Byte order/swapping support.
62 */
63 #define OAL_LITTLE_ENDIAN 1234
64 #define OAL_BIG_ENDIAN 4321
65 #define OAL_BYTE_ORDER OAL_BIG_ENDIAN
66 #define OAL_BYTE_HALF_WIDTH 4
67
68 /* ICMP协议报文 */
69 #define MAC_ICMP_PROTOCAL 1
70 #define MAC_ICMP_REQUEST 0x08
71 #define MAC_ICMP_RESPONSE 0x00
72
73 /*****************************************************************************
74 2.10 IP宏定义
75 *****************************************************************************/
76 #define IPV6_ADDR_MULTICAST 0x0002U
77 #define IPV6_ADDR_UNICAST 0x0001U
78 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
79 #define IPV6_ADDR_SCOPE_NODELOCAL 0x01
80 #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
81 #define IPV6_ADDR_SCOPE_SITELOCAL 0x05
82 #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08
83 #define IPV6_ADDR_SCOPE_GLOBAL 0x0e
84 #define IPV6_ADDR_LOOPBACK 0x0010U
85 #define IPV6_ADDR_LINKLOCAL 0x0020U
86 #define IPV6_ADDR_SITELOCAL 0x0040U
87 #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
88
89 #define WLAN_DSCP_PRI_SHIFT 2
90 #define WLAN_IP_PRI_SHIFT 5
91 #define WLAN_IPV6_PRIORITY_MASK 0x0FF00000
92 #define WLAN_IPV6_PRIORITY_SHIFT 20
93
94 /* ICMP codes for neighbour discovery messages */
95 #define OAL_NDISC_ROUTER_SOLICITATION 133
96 #define OAL_NDISC_ROUTER_ADVERTISEMENT 134
97 #define OAL_NDISC_NEIGHBOUR_SOLICITATION 135
98 #define OAL_NDISC_NEIGHBOUR_ADVERTISEMENT 136
99 #define OAL_NDISC_REDIRECT 137
100
101 #define OAL_ND_OPT_TARGET_LL_ADDR 2
102 #define OAL_ND_OPT_SOURCE_LL_ADDR 1
103 #define OAL_IPV6_ADDR_ANY 0x0000U
104 #define OAL_IPV6_ADDR_MULTICAST 0x0002U
105 #define OAL_IPV6_MAC_ADDR_LEN 16
106
107 /*
108 * support for ARP/ND offload. add 2015.6.12
109 */
110 #define OAL_IPV4_ADDR_SIZE 4
111 #define OAL_IPV6_ADDR_SIZE 16
112 #define OAL_IPV6_ADDR16_SIZE 8
113 #define OAL_IPV6_ADDR32_SIZE 4
114 #define OAL_IP_ADDR_MAX_SIZE OAL_IPV6_ADDR_SIZE
115
116 #define OAL_IP4_ADDR IP4_ADDR
117
118 /* ip头到协议类型字段的偏移 */
119 #define IP_HDR_LEN 20
120
121 #define OAL_IPPROTO_UDP 17 /* User Datagram Protocot */
122 #define OAL_IPPROTO_ICMPV6 58 /* ICMPv6 */
123
124 /*****************************************************************************
125 2.12 LLC SNAP宏定义
126 *****************************************************************************/
127 #define LLC_UI 0x3
128 #define SNAP_LLC_FRAME_LEN 8
129 #define SNAP_LLC_LSAP 0xaa
130 #define SNAP_RFC1042_ORGCODE_0 0x00
131 #define SNAP_RFC1042_ORGCODE_1 0x00
132 #define SNAP_RFC1042_ORGCODE_2 0x00
133 #define SNAP_BTEP_ORGCODE_0 0x00
134 #define SNAP_BTEP_ORGCODE_1 0x00
135 #define SNAP_BTEP_ORGCODE_2 0xf8
136
137 /*****************************************************************************
138 2.13 ETHER宏定义
139 *****************************************************************************/
140 #define IP6_ETHER_ADDR_LEN 16 /* efuse中ipv6 MAC地址大小 */
141
142 #if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
143 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
144 #define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
145 #define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */
146 #define ETHER_HDR_LEN 14
147 #define ETHER_MAX_LEN 1518
148 #endif
149 #if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
150 #define ETH_ALEN 6
151 #define ETH_HLEN 14
152 #define ETH_FRAME_LEN 1514
153 #ifndef ETHER_HDR_LEN
154 #define ETHER_HDR_LEN ETH_HLEN
155 #endif
156 #ifndef ETHER_MAX_LEN
157 #define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN)
158 #endif
159 #endif
160 #define ETHER_MTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
161
162 #define ETH_SENDER_IP_ADDR_LEN 4 /* length of an Ethernet send ip address */
163 #define ETH_TARGET_IP_ADDR_LEN 4 /* length of an Ethernet target ip address */
164
165 /* ether type */
166 #define ETHER_TYPE_START 0x0600
167 #define ETHER_TYPE_RARP 0x8035
168 #define ETHER_TYPE_PAE 0x888e /* EAPOL PAE/802.1x */
169 #define ETHER_TYPE_IP 0x0800 /* IP protocol */
170 #define ETHER_TYPE_AARP 0x80f3 /* Appletalk AARP protocol */
171 #define ETHER_TYPE_IPX 0x8137 /* IPX over DIX protocol */
172 #define ETHER_TYPE_ARP 0x0806 /* ARP protocol */
173 #define ETHER_TYPE_IPV6 0x86dd /* IPv6 */
174 #define ETHER_TYPE_VLAN 0x8100 /* VLAN TAG protocol */
175 #define ETHER_TYPE_TDLS 0x890d /* TDLS */
176 #define ETHER_TYPE_WAI 0x88b4 /* WAI/WAPI */
177 #define ETHER_LLTD_TYPE 0x88D9 /* LLTD */
178 #define ETHER_ONE_X_TYPE 0x888E /* 802.1x Authentication */
179 #define ETHER_TUNNEL_TYPE 0x88bd /* 自定义tunnel协议 */
180 #define ETHER_TYPE_PPP_DISC 0x8863 /* PPPoE discovery messages */
181 #define ETHER_TYPE_PPP_SES 0x8864 /* PPPoE session messages */
182 #define ETHER_TYPE_6LO 0xa0ed /* 6lowpan */
183
184 #define BROADCAST_MACADDR ((const osal_u8 *)"\xFF\xFF\xFF\xFF\xFF\xFF") /* 广播MAC地址 */
185
186
187 /*****************************************************************************
188 WLAN MAC宏定义
189 *****************************************************************************/
190 /* CCMP加密字节数 */
191 #define WLAN_CCMP_ENCRYP_LEN 16
192 /* CCMP256加密字节数 */
193 #define WLAN_CCMP256_GCMP_ENCRYP_LEN 24
194
195 /* Probe Rsp APP IE长度超过该值,发送帧netbuf采用大包 */
196 #define OAL_MGMT_NETBUF_APP_PROBE_RSP_IE_LEN_LIMIT 450
197
198 #define WLAN_DATA_VIP_TID WLAN_TIDNO_BCAST
199
200 /* MAC地址占的字符长度 */
201 #define WLAN_MAC_ADDR_BYTE_LEN 17
202
203 #define OAL_MAX_FT_ALL_LEN 518 /* MD:5 FT:257 RSN:256 */
204
205 #define AP_WPS_P2P_IE_CMD_BEACON 0x1
206 #define AP_WPS_P2P_IE_CMD_PROBE_RSP 0x2
207 #define AP_WPS_P2P_IE_CMD_ASSOC_RSP 0x4
208
209
210 #if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
211 #define oal_smp_mb() smp_mb()
212 #else
213 #define oal_smp_mb()
214 #endif
215 #define OAL_CONTAINER_OF(_member_ptr, _stru_type, _stru_member_name) \
216 container_of(_member_ptr, _stru_type, _stru_member_name)
217 #define ETHER_IS_MULTICAST(_a) (*(_a) & 0x01)
218
219 /* is address bcast */
220 #define ETHER_IS_BROADCAST(_a) \
221 ((_a)[0] == 0xff && \
222 (_a)[1] == 0xff && \
223 (_a)[2] == 0xff && \
224 (_a)[3] == 0xff && \
225 (_a)[4] == 0xff && \
226 (_a)[5] == 0xff)
227
228 /* IPv4永久组地址判断: 224.0.0.0~224.0.0.255为永久组地址 */
229 #define OAL_IPV4_PERMANET_GROUP_ADDR 0x000000E0
230 #define OAL_IPV4_IS_PERMANENT_GROUP(_a) ((((_a) & 0x00FFFFFF) ^ OAL_IPV4_PERMANET_GROUP_ADDR) == 0)
231
232 /*****************************************************************************
233 3 枚举定义
234 *****************************************************************************/
235 typedef gfp_t oal_gfp_enum_uint8;
236
237 typedef enum _wlan_net_queue_type_ {
238 WLAN_HI_QUEUE = 0,
239 WLAN_NORMAL_QUEUE,
240
241 WLAN_TCP_DATA_QUEUE,
242 WLAN_TCP_ACK_QUEUE,
243
244 WLAN_UDP_DATA_QUEUE,
245
246 WLAN_NET_QUEUE_BUTT
247 } wlan_net_queue_type;
248
249 #if defined(_PRE_WLAN_FEATURE_QUE_CLASSIFY)
wlan_data_queue_to_hcc(osal_u16 qid)250 static inline osal_u8 wlan_data_queue_to_hcc(osal_u16 qid)
251 {
252 return ((qid == WLAN_UDP_DATA_QUEUE) ? DATA_UDP_DATA_QUEUE :
253 (qid == WLAN_TCP_DATA_QUEUE) ? DATA_TCP_DATA_QUEUE :
254 (qid == WLAN_TCP_ACK_QUEUE) ? DATA_TCP_ACK_QUEUE : DATA_LO_QUEUE);
255 }
256
hcc_data_queue_to_wlan(osal_u8 qid)257 static inline osal_u16 hcc_data_queue_to_wlan(osal_u8 qid)
258 {
259 return ((qid == DATA_UDP_DATA_QUEUE) ? WLAN_UDP_DATA_QUEUE :
260 (qid == DATA_TCP_DATA_QUEUE) ? WLAN_TCP_DATA_QUEUE :
261 (qid == DATA_TCP_ACK_QUEUE) ? WLAN_TCP_ACK_QUEUE : WLAN_NORMAL_QUEUE);
262 }
263 #endif
264
265 typedef enum {
266 OAL_IEEE80211_MLME_AUTH = 0, /* MLME下发认证帧相关内容 */
267 OAL_IEEE80211_MLME_ASSOC = 1, /* MLME下发关联帧相关内容 */
268 OAL_IEEE80211_MLME_REASSOC = 2, /* MLME下发重关联帧相关内容 */
269 OAL_IEEE80211_MLME_NUM
270 }mlme_type_enum;
271 typedef osal_u8 mlme_type_enum_uint8;
272
273 /* 以下不区分操作系统 */
274 /* 内核下发的扫描类型 */
275 typedef enum {
276 OAL_PASSIVE_SCAN = 0,
277 OAL_ACTIVE_SCAN = 1,
278
279 OAL_SCAN_BUTT
280 } oal_scan_enum;
281 typedef osal_u8 oal_scan_enum_uint8;
282
283 /* 内核下发的扫描频段 */
284 typedef enum {
285 OAL_SCAN_2G_BAND = 1,
286 OAL_SCAN_5G_BAND = 2,
287 OAL_SCAN_ALL_BAND = 3,
288
289 OAL_SCAN_BAND_BUTT
290 } oal_scan_band_enum;
291 typedef osal_u8 oal_scan_band_enum_uint8;
292
293 enum APP_IE_BITMAP {
294 BEACON_IE = (1 << 0),
295 PROBE_REQ_IE = (1 << 1),
296 PROBE_RSP_IE = (1 << 2),
297 ASSOC_REQ_IE = (1 << 3),
298 ASSOC_RSP_IE = (1 << 4),
299 REASSOC_REQ_IE = (1 << 5),
300 AUTH_REQ_IE = (1 << 6)
301 };
302 typedef osal_u8 app_ie_bitmap;
303
304 enum APP_IE_TYPE {
305 OAL_APP_BEACON_IE = 0,
306 OAL_APP_PROBE_REQ_IE = 1,
307 OAL_APP_PROBE_RSP_IE = 2,
308 OAL_APP_ASSOC_REQ_IE = 3,
309 OAL_APP_ASSOC_RSP_IE = 4,
310 OAL_APP_FT_IE = 5,
311 OAL_APP_REASSOC_REQ_IE = 6,
312 OAL_APP_EXTEND_IE1 = 7,
313 OAL_APP_EXTEND_IE2 = 8,
314 OAL_APP_EXTEND_IE3 = 9,
315 OAL_APP_EXTEND_IE4 = 10,
316 OAL_APP_VENDOR_IE = 11, /* vendor IE管理帧上报 */
317 OAL_APP_IE_NUM
318 };
319 typedef osal_u8 app_ie_type_uint8;
320
321 /*****************************************************************************
322 7 STRUCT定义
323 *****************************************************************************/
324 /* 不分平台通用结构体 */
325 typedef struct {
326 osal_u8 ssid[OAL_IEEE80211_MAX_SSID_LEN]; /* ssid array */
327 osal_u8 ssid_len; /* length of the array */
328 osal_u8 arry[3]; /* 3字节存储其他数据 */
329 } oal_ssids_stru;
330
331 typedef union {
332 td_u8 byte;
333 struct {
334 td_u8 high : 4,
335 low : 4;
336 } bits;
337 } bitfield_un;
338
a2x(const osal_char c)339 static inline osal_u8 a2x(const osal_char c)
340 {
341 if (c >= '0' && c <= '9') {
342 return (osal_u8)(c - '0');
343 }
344 if (c >= 'a' && c <= 'f') {
345 return (osal_u8)0xa + (osal_u8)(c - 'a');
346 }
347 if (c >= 'A' && c <= 'F') {
348 return (osal_u8)0xa + (osal_u8)(c - 'A');
349 }
350 return 0;
351 }
352
353 /* ipv6 组播mac地址 */
354 #define ETHER_IS_IPV6_MULTICAST(_a) (((_a)[0]) == 0x33 && ((_a)[1]) == 0x33)
355 /* IPv6未指定地址: ::/128 ,该地址仅用于接口还没有被分配IPv6地址时与其它节点
356 通讯作为源地址,例如在重复地址检测DAD中会出现. */
357 #define OAL_IPV6_IS_UNSPECIFIED_ADDR(_a) \
358 ((_a)[0] == 0x00 && (_a)[1] == 0x00 && (_a)[2] == 0x00 && \
359 (_a)[3] == 0x00 && (_a)[4] == 0x00 && (_a)[5] == 0x00 && \
360 (_a)[6] == 0x00 && (_a)[7] == 0x00 && (_a)[8] == 0x00 && \
361 (_a)[9] == 0x00 && (_a)[10] == 0x00 && (_a)[11] == 0x00 && \
362 (_a)[12] == 0x00 && (_a)[13] == 0x00 && (_a)[14] == 0x00 && \
363 (_a)[15] == 0x00)
364
365 /* IPv6链路本地地址: 最高10位值为1111111010, 例如:FE80:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX */
366 #define OAL_IPV6_IS_LINK_LOCAL_ADDR(_a) (((_a)[0] == 0xFE) && ((_a)[1] >> 6 == 2))
367
368 /* IGMP record type */
369 #define MAC_IGMP_QUERY_TYPE 0x11
370 #define MAC_IGMPV1_REPORT_TYPE 0x12
371 #define MAC_IGMPV2_REPORT_TYPE 0x16
372 #define MAC_IGMPV2_LEAVE_TYPE 0x17
373 #define MAC_IGMPV3_REPORT_TYPE 0x22
374
375 /* V3 group record types [grec_type] */
376 #define IGMPV3_MODE_IS_INCLUDE 1
377 #define IGMPV3_MODE_IS_EXCLUDE 2
378 #define IGMPV3_CHANGE_TO_INCLUDE 3
379 #define IGMPV3_CHANGE_TO_EXCLUDE 4
380 #define IGMPV3_ALLOW_NEW_SOURCES 5
381 #define IGMPV3_BLOCK_OLD_SOURCES 6
382
383 /* IGMP record type */
384 #define MLD_QUERY_TYPE 130
385 #define MLDV1_REPORT_TYPE 131
386 #define MLDV1_DONE_TYPE 132
387 #define MLDV2_REPORT_TYPE 143
388
389 /* MLD V2 group record types [grec_type] */
390 #define MLDV2_MODE_IS_INCLUDE 1
391 #define MLDV2_MODE_IS_EXCLUDE 2
392 #define MLDV2_CHANGE_TO_INCLUDE 3
393 #define MLDV2_CHANGE_TO_EXCLUDE 4
394 #define MLDV2_ALLOW_NEW_SOURCES 5
395 #define MLDV2_BLOCK_OLD_SOURCES 6
396
397 #define SERVERNAME_LEN 64
398 #define BOOTFILE_LEN 128
399
400 /* DHCP message type */
401 #define DHCP_DISCOVER 1
402 #define DHCP_OFFER 2
403 #define DHCP_REQUEST 3
404 #define DHCP_ACK 5
405 #define DHCP_NAK 6
406
407 #define DHO_PAD 0
408 #define DHO_IPADDRESS 50
409 #define DHO_MESSAGETYPE 53
410 #define DHO_SERVERID 54
411 #define DHO_END 255
412
413 #define DNS_MAX_DOMAIN_LEN (100)
414
415 #define DHCP_SERVER_PORT (67)
416 #define DHCP_CLIENT_PORT (68)
417 #define DNS_SERVER_PORT (53)
418
419 #define OAL_NETDEVICE_OPS(_pst_dev) ((_pst_dev)->netdev_ops)
420 #define OAL_NETDEVICE_MAC_ADDR(_pst_dev) ((_pst_dev)->dev_addr)
421 #define OAL_NETDEVICE_IFALIAS(_pst_dev) ((_pst_dev)->ifalias)
422 #define OAL_NETDEVICE_WDEV(_pst_dev) ((_pst_dev)->ieee80211_ptr)
423 #define OAL_NETDEVICE_HEADROOM(_pst_dev) ((_pst_dev)->needed_headroom)
424 #define OAL_NETDEVICE_TAILROOM(_pst_dev) ((_pst_dev)->needed_tailroom)
425 #define OAL_NETDEVICE_FLAGS(_pst_dev) ((_pst_dev)->flags)
426 #define OAL_NETDEVICE_WATCHDOG_TIMEO(_pst_dev) ((_pst_dev)->watchdog_timeo)
427 #define OAL_WIRELESS_DEV_WIPHY(_pst_wireless_dev) ((_pst_wireless_dev)->wiphy)
428 #define oal_netdevice_master(_pst_dev) ((_pst_dev)->master)
429
430 #define OAL_IFF_RUNNING 0x40
431 #define OAL_IFF_UP 0x01
432
433 #if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS != _PRE_OS_VERSION)
434 #define oal_is_broadcast_ether_addr(a) (((a)[0] & (a)[1] & (a)[2] & (a)[3] & (a)[4] & (a)[5]) == 0xff)
435 /* is address mcast */
436 typedef struct {
437 osal_u16 ar_hrd; /* format of hardware address */
438 osal_u16 ar_pro; /* format of protocol address */
439
440 osal_u8 ar_hln; /* length of hardware address */
441 osal_u8 ar_pln; /* length of protocol address */
442 osal_u16 ar_op; /* ARP opcode (command) */
443
444 osal_u8 ar_sha[ETHER_ADDR_LEN]; /* sender hardware address */
445 osal_u8 ar_sip[ETH_SENDER_IP_ADDR_LEN]; /* sender IP address */
446 osal_u8 ar_tha[ETHER_ADDR_LEN]; /* target hardware address */
447 osal_u8 ar_tip[ETH_TARGET_IP_ADDR_LEN]; /* target IP address */
448 } oal_eth_arphdr_stru;
449
450 /* WIN32和linux共用结构体 */
451 typedef struct {
452 osal_u8 type;
453 osal_u8 len;
454 osal_u8 addr[6]; /* hardware address6字节 */
455 } oal_eth_icmp6_lladdr_stru;
456
457 typedef struct {
458 osal_u8 op; /* packet opcode type */
459 osal_u8 htype; /* hardware addr type */
460 osal_u8 hlen; /* hardware addr length */
461 osal_u8 hops; /* gateway hops */
462 osal_u32 xid; /* transaction ID */
463 osal_u16 secs; /* seconds since boot began */
464 osal_u16 flags; /* flags */
465 osal_u32 ciaddr; /* client IP address */
466 osal_u32 yiaddr; /* 'your' IP address */
467 osal_u32 siaddr; /* server IP address */
468 osal_u32 giaddr; /* gateway IP address */
469 osal_u8 chaddr[16]; /* client hardware address16字节 */
470 osal_u8 sname[64]; /* server host name字符串长度64 */
471 osal_u8 file[128]; /* boot file name字符串长度128 */
472 osal_u8 options[4]; /* variable-length options field 4字节 */
473 } oal_dhcp_packet_stru;
474
475 struct oal_ip_header {
476 #if (_PRE_LITTLE_CPU_ENDIAN == _PRE_CPU_ENDIAN) /* LITTLE_ENDIAN */
477 osal_u8 ihl : 4,
478 version_ihl : 4;
479 #else
480 osal_u8 version_ihl : 4,
481 ihl : 4;
482 #endif
483 osal_u8 tos;
484 osal_u16 tot_len;
485 osal_u16 id;
486 osal_u16 frag_off;
487 osal_u8 ttl;
488 osal_u8 protocol;
489 osal_u16 check;
490 osal_u32 saddr;
491 osal_u32 daddr;
492 } OAL_DECLARE_PACKED;
493 typedef struct oal_ip_header oal_ip_header_stru;
494
495 typedef struct {
496 osal_u16 sport;
497 osal_u16 dport;
498 osal_u32 seqnum;
499 osal_u32 acknum;
500 osal_u8 offset;
501 osal_u8 flags;
502 osal_u16 window;
503 osal_u16 check;
504 osal_u16 urgent;
505 }oal_tcp_header_stru;
506
507 typedef struct {
508 osal_u16 source;
509 osal_u16 dest;
510 osal_u16 len;
511 osal_u16 check;
512 }oal_udp_header_stru;
513
514 struct oal_ether_header {
515 osal_u8 ether_dhost[ETHER_ADDR_LEN];
516 osal_u8 ether_shost[ETHER_ADDR_LEN];
517 osal_u16 ether_type;
518 } OAL_DECLARE_PACKED;
519 typedef struct oal_ether_header oal_ether_header_stru;
520 #endif
521
522 /*
523 wal 层到hmac侧传递使用该数据, WLAN_WPS_IE_MAX_SIZE扩容到608字节,超过事件队列大小,
524 wal到hmac ie data采用指针传递
525 */
526 struct oal_w2h_app_ie {
527 osal_u32 ie_len;
528 app_ie_type_uint8 app_ie_type;
529 osal_u8 rsv[3];
530 osal_u8 *data_ie;
531 } OAL_DECLARE_PACKED;
532 typedef struct oal_w2h_app_ie oal_w2h_app_ie_stru;
533
534 struct oal_mlme_ie {
535 mlme_type_enum_uint8 mlme_type; /* MLME类型 */
536 osal_u8 seq; /* 认证帧序列号 */
537 osal_u16 reason; /* 原因码 */
538 osal_u8 macaddr[6];
539 osal_u16 optie_len;
540 osal_u8 optie[OAL_MAX_FT_ALL_LEN];
541 };
542 typedef struct oal_mlme_ie oal_mlme_ie_stru;
543
544 /*
545 * Header in on cable format
546 */
547 struct mac_igmp_header {
548 osal_u8 type;
549 osal_u8 code; /* For newer IGMP */
550 osal_u16 csum;
551 osal_u32 group;
552 } OAL_DECLARE_PACKED;
553 typedef struct mac_igmp_header mac_igmp_header_stru;
554
555 /* Group record format
556 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
557 | Record Type | Aux Data Len | Number of Sources (N) |
558 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
559 | Multicast Address |
560 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
561 | Source Address [1] |
562 +- -+
563 | Source Address [2] |
564 +- -+
565 . . .
566 . . .
567 . . .
568 +- -+
569 | Source Address [N] |
570 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
571 | |
572 . .
573 . Auxiliary Data .
574 . .
575 | |
576 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
577 */
578 struct mac_igmp_v3_grec {
579 osal_u8 grec_type;
580 osal_u8 grec_auxwords;
581 osal_u16 grec_nsrcs;
582 osal_u32 grec_group_ip;
583 } OAL_DECLARE_PACKED;
584 typedef struct mac_igmp_v3_grec mac_igmp_v3_grec_stru;
585
586 /* IGMPv3 report format
587 0 1 2 3
588 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
589 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
590 | Type = 0x22 | Reserved | Checksum |
591 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
592 | Reserved | Number of Group Records (M) |
593 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
594 | |
595 . .
596 . Group Record [1] .
597 . .
598 | |
599 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
600 | |
601 . .
602 . Group Record [2] .
603 . .
604 | |
605 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
606 | . |
607 . . .
608 | . |
609 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
610 | |
611 . .
612 . Group Record [M] .
613 . .
614 | |
615 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
616 */
617 struct mac_igmp_v3_report {
618 osal_u8 type;
619 osal_u8 resv1;
620 osal_u16 csum;
621 osal_u16 resv2;
622 osal_u16 ngrec;
623 } OAL_DECLARE_PACKED;
624 typedef struct mac_igmp_v3_report mac_igmp_v3_report_stru;
625
626
627 struct mac_mld_v1_head {
628 osal_u8 type;
629 osal_u8 code;
630 osal_u16 check_sum;
631 osal_u16 max_response_delay;
632 osal_u16 reserved;
633 osal_u8 group_ip[OAL_IPV6_ADDR_SIZE];
634 } OAL_DECLARE_PACKED;
635 typedef struct mac_mld_v1_head mac_mld_v1_head_stru;
636
637 struct mac_mld_v2_report {
638 osal_u8 type;
639 osal_u8 code;
640 osal_u16 check_sum;
641 osal_u16 reserved;
642 osal_u16 group_address_num;
643 } OAL_DECLARE_PACKED;
644 typedef struct mac_mld_v2_report mac_mld_v2_report_stru;
645
646 struct mac_mld_v2_group_record {
647 osal_u8 grec_type;
648 osal_u8 grec_auxwords; // 辅助数据长度
649 osal_u16 grec_srcaddr_num; // 原地址个数
650 osal_u8 group_ip[OAL_IPV6_ADDR_SIZE]; // 组播组地址
651 } OAL_DECLARE_PACKED;
652 typedef struct mac_mld_v2_group_record mac_mld_v2_group_record_stru;
653
654 struct mac_vlan_tag {
655 osal_u16 tpid; // tag ID
656 osal_u16 user_pri : 3, // 帧的优先级
657 cfi : 1,
658 vlan_id : 12; // 可配置的VLAN ID
659 } OAL_DECLARE_PACKED;
660 typedef struct mac_vlan_tag mac_vlan_tag_stru;
661
662 typedef struct {
663 osal_u16 id; /* transaction id */
664 osal_u16 flags; /* message future */
665 osal_u16 qdcount; /* question record count */
666 osal_u16 ancount; /* answer record count */
667 osal_u16 nscount; /* authority record count */
668 osal_u16 arcount; /* additional record count */
669 }oal_dns_hdr_stru;
670
671 typedef enum {
672 OAL_NS_Q_REQUEST = 0, /* request */
673 OAL_NS_Q_RESPONSE = 1, /* response */
674 } oal_ns_qrcode;
675
676 typedef enum {
677 OAL_NS_O_QUERY = 0, /* Standard query. */
678 OAL_NS_O_IQUERY = 1, /* Inverse query (deprecated/unsupported). */
679 }oal_ns_opcode;
680
681 /*
682 * Currently defined response codes.
683 */
684 typedef enum {
685 OAL_NS_R_NOERROR = 0, /* No error occurred. */
686 }oal_ns_rcode;
687
688 typedef enum {
689 OAL_NS_T_INVALID = 0, /* Cookie. */
690 OAL_NS_T_A = 1, /* Host address. */
691 }oal_ns_type;
692
693 /* 邻居AP列表的BSS描述信息结构体 */
694 struct oal_bssid_infomation {
695 osal_u8 ap_reachability : 2, /* AP的可到达性 */
696 security : 1, /* 该AP的加密规则与当前连接是否一致 */
697 key_scope : 1, /* 该AP的认证信息是否与当前上报一直 */
698 spectrum_mgmt : 1, /* 能力位: 支持频谱管理 */ /* 能力位字段与beacon定义一致 */
699 qos : 1, /* 能力位: 支持QOS */
700 apsd : 1, /* 能力位: 支持APSD */
701 radio_meas : 1; /* 能力位: 波长测量 */
702 osal_u8 delay_block_ack : 1, /* 能力位: 阻塞延迟应答 */
703 immediate_block_ack : 1, /* 能力位: 阻塞立即应答 */
704 mobility_domain : 1, /* 该AP的beacon帧中是否含有MDE,且与此次上报一致 */
705 high_throughput : 1, /* 该AP的beacon帧中是否含有高吞吐量元素,且与此次上报一致 */
706 resv1 : 4; /* 预留 */
707 osal_u8 resv2;
708 osal_u8 resv3;
709 } OAL_DECLARE_PACKED;
710 typedef struct oal_bssid_infomation oal_bssid_infomation_stru;
711
712 #if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS != _PRE_OS_VERSION)
713 /*****************************************************************************
714 函 数 名 : ether_is_multicast
715 功能描述 : 判断一个地址是否为组播地址
716 *****************************************************************************/
ether_is_multicast(const osal_u8 * addr)717 static INLINE__ osal_u8 ether_is_multicast(const osal_u8 *addr)
718 {
719 return ((*addr) & 0x01);
720 }
721
722 /*****************************************************************************
723 函 数 名 : ether_is_broadcast
724 功能描述 : 判断一个地址是否为广播地址
725 *****************************************************************************/
ether_is_broadcast(const osal_u8 * addr)726 static INLINE__ osal_u8 ether_is_broadcast(const osal_u8 *addr)
727 {
728 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
729 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
730 }
731
732 /*****************************************************************************
733 函 数 名 : ether_is_ipv4_multicast
734 功能描述 : 判断一个地址是否为IPv4组播地址
735 *****************************************************************************/
ether_is_ipv4_multicast(const osal_u8 * addr)736 static INLINE__ osal_u8 ether_is_ipv4_multicast(const osal_u8 *addr)
737 {
738 return ((addr[0] == 0x01) && (addr[1] == 0x00) && (addr[2] == 0x5e));
739 }
740
741 /*****************************************************************************
742 函 数 名 : oal_ipv4_is_permanent_group
743 功能描述 : 判断一个IPv4地址是否为永久组地址:224.0.0.0~224.0.0.255
744 *****************************************************************************/
oal_ipv4_is_permanent_group(osal_u32 addr)745 static INLINE__ osal_u8 oal_ipv4_is_permanent_group(osal_u32 addr)
746 {
747 return (((addr & 0x00FFFFFF) ^ OAL_IPV4_PERMANET_GROUP_ADDR) == 0);
748 }
749
750 /*****************************************************************************
751 函 数 名 : oal_ipv6_is_multicast
752 功能描述 : 判断一个地址是否为IPv6组播地址:FFXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
753 *****************************************************************************/
oal_ipv6_is_multicast(const osal_u8 * addr)754 static INLINE__ osal_u8 oal_ipv6_is_multicast(const osal_u8 *addr)
755 {
756 return ((osal_u8)(addr[0]) == 0xff);
757 }
758
759 /*****************************************************************************
760 函 数 名 : oal_ipv6_is_unspecified_addr
761 功能描述 : 判断一个地址是否为IPv6未指定地址
762 IPv6未指定地址: ::/128 ,该地址仅用于接口还没有被分配IPv6地址时
763 与其它节点通讯作为源地址,例如在重复地址检测DAD中会出现.
764 *****************************************************************************/
oal_ipv6_is_unspecified_addr(const osal_u8 * addr)765 static INLINE__ osal_u8 oal_ipv6_is_unspecified_addr(const osal_u8 *addr)
766 {
767 return ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00) &&
768 (addr[4] == 0x00) && (addr[5] == 0x00) && (addr[6] == 0x00) && (addr[7] == 0x00) &&
769 (addr[8] == 0x00) && (addr[9] == 0x00) && (addr[10] == 0x00) && (addr[11] == 0x00) &&
770 (addr[12] == 0x00) && (addr[13] == 0x00) && (addr[14] == 0x00) && (addr[15] == 0x00));
771 }
772
773 /*****************************************************************************
774 函 数 名 : oal_ipv6_is_link_local_addr
775 功能描述 : 判断一个地址是否为IPv6链路本地地址.最高10位值为1111111010.
776 例如:FE80:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
777 *****************************************************************************/
oal_ipv6_is_link_local_addr(const osal_u8 * addr)778 static INLINE__ osal_u8 oal_ipv6_is_link_local_addr(const osal_u8 *addr)
779 {
780 return ((addr[0] == 0xFE) && ((addr[1] >> 6) == 2));
781 }
782
oal_netbuf_put_rsv(const oal_netbuf_stru * netbuf,osal_u32 len)783 static INLINE__ osal_u8 *oal_netbuf_put_rsv(const oal_netbuf_stru *netbuf, osal_u32 len)
784 {
785 /* device侧注空啥都不做 */
786 unref_param(netbuf);
787 unref_param(len);
788 return 0;
789 }
790 #endif
791
792 /***************************************xr 分界线***************************************************/
793 #if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
794 typedef iw_handler oal_iw_handler;
795 #define oal_netif_running(_pst_net_dev) netif_running(_pst_net_dev)
796 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0))
797 #define OAL_NETDEVICE_DESTRUCTOR(_pst_dev) ((_pst_dev)->priv_destructor)
798 #else
799 #define OAL_NETDEVICE_LAST_RX(_pst_dev) ((_pst_dev)->last_rx)
800 #define OAL_NETDEVICE_DESTRUCTOR(_pst_dev) ((_pst_dev)->destructor)
801 #endif
802 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)
803 #define oal_netdevice_qdisc(_pst_dev, val) ((_pst_dev)->qdisc = val)
804 #else
805 #define oal_netdevice_qdisc(_pst_dev, val)
806 #endif
807
808 #define OAL_SIOCIWFIRSTPRIV SIOCIWFIRSTPRIV
809
810 /* iw_priv参数类型OAL封装 */
811 #define OAL_IW_PRIV_TYPE_BYTE IW_PRIV_TYPE_BYTE /* Char as number */
812 #define OAL_IW_PRIV_TYPE_CHAR IW_PRIV_TYPE_CHAR /* Char as character */
813 #define OAL_IW_PRIV_TYPE_INT IW_PRIV_TYPE_INT /* 32 bits int */
814 #define OAL_IW_PRIV_TYPE_ADDR IW_PRIV_TYPE_ADDR /* struct sockaddr */
815 #define OAL_IW_PRIV_SIZE_FIXED IW_PRIV_SIZE_FIXED /* Variable or fixed number of args */
816 #define OAL_IW_PRIV_SIZE_MASK IW_PRIV_SIZE_MASK /* Max number of those args */
817
818 /* iwconfig mode oal封装 */
819 #define OAL_IW_MODE_AUTO IW_MODE_AUTO /* Let the driver decides */
820 #define OAL_IW_MODE_INFRA IW_MODE_INFRA /* Multi cell network, roaming, ... */
821
822 /* Transmit Power flags available */
823 #define OAL_IW_TXPOW_DBM IW_TXPOW_DBM /* Value is in dBm */
824
825 /* 主机与网络字节序转换 */
826 #define oal_host2net_short(_x) htons(_x)
827 #define oal_net2host_short(_x) ntohs(_x)
828 #define oal_host2net_long(_x) htonl(_x)
829 #define oal_net2host_long(_x) ntohl(_x)
830
831 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
832 #define OAL_VLAN_PRIO_SHIFT VLAN_PRIO_SHIFT
833 #else
834 #define OAL_VLAN_PRIO_SHIFT 13
835 #endif
836
837 /* ARP protocol opcodes. */
838 #define OAL_ARPOP_REQUEST ARPOP_REQUEST /* ARP request */
839 #define OAL_ARPOP_REPLY ARPOP_REPLY /* ARP reply */
840
841 #define OAL_IPPROTO_TCP IPPROTO_TCP /* Transmission Control Protocol */
842
843 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
844 #define oal_wdev_match(_netif, _req) ((_netif)->ieee80211_ptr == (_req)->wdev)
845 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34))
846 #define oal_wdev_match(_netif, _req) ((_netif) == (_req)->dev)
847 #else
848 #define oal_wdev_match(_netif, _req) ((_netif)->ifindex == (_req)->ifidx)
849 #endif
850
851 typedef struct sock oal_sock_stru;
852 typedef struct net oal_net_stru;
853 typedef struct module oal_module_stru;
854 typedef struct nlmsghdr oal_nlmsghdr_stru;
855
856 typedef struct ethhdr oal_ethhdr;
857 typedef struct nf_hook_ops oal_nf_hook_ops_stru;
858 typedef struct net_bridge_port oal_net_bridge_port;
859
860 typedef struct ipv6hdr oal_ipv6hdr_stru;
861 typedef struct icmp6hdr oal_icmp6hdr_stru;
862 typedef struct in6_addr oal_in6_addr;
863 typedef struct nd_msg oal_nd_msg_stru;
864 typedef struct nd_opt_hdr oal_nd_opt_hdr;
865 typedef struct netlink_skb_parms oal_netlink_skb_parms;
866 #ifdef _PRE_WLAN_FEATURE_WPA3
867 typedef struct cfg80211_external_auth_params oal_external_auth_stru;
868 #endif
869
870 /* netlink���� */
871 #define OAL_NLMSG_HDRLEN NLMSG_HDRLEN
872
873 #define OAL_NLA_FOR_EACH_ATTR(pos, head, len, rem) nla_for_each_attr(pos, head, len, rem)
874
875 typedef struct ieee80211_iface_limit oal_ieee80211_iface_limit;
876 typedef struct ieee80211_iface_combination oal_ieee80211_iface_combination;
877
878 #elif defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
879 #define OAL_NETDEVICE_DESTRUCTOR(_pst_dev) ((_pst_dev)->destructor)
880 #define oal_netdevice_qdisc(_pst_dev, val) ((_pst_dev)->qdisc = val)
881
882 #define IEEE80211_MAX_SSID_LEN 32
883 #define OAL_VLAN_PRIO_SHIFT 13
884 #define OAL_SIOCIWFIRSTPRIV 0x8BE0
885
886 /* iw_priv参数类型OAL封装 */
887 #define OAL_IW_PRIV_TYPE_BYTE 0x1000 /* Char as number */
888 #define OAL_IW_PRIV_TYPE_CHAR 0x2000 /* Char as character */
889 #define OAL_IW_PRIV_TYPE_INT 0x4000 /* 32 bits int */
890 #define OAL_IW_PRIV_TYPE_ADDR 0x6000 /* struct sockaddr */
891 #define OAL_IW_PRIV_SIZE_FIXED 0x0800 /* Variable or fixed number of args */
892 #define OAL_IW_PRIV_SIZE_MASK 0x07FF /* Max number of those args */
893
894 /* iwconfig mode oal封装 */
895 #define OAL_IW_MODE_AUTO 0 /* Let the driver decides */
896 #define OAL_IW_MODE_ADHOC 1 /* Single cell network */
897 #define OAL_IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */
898 #define OAL_IW_MODE_MASTER 3 /* Synchronisation master or Access Point */
899 #define OAL_IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */
900 #define OAL_IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */
901 #define OAL_IW_MODE_MONITOR 6 /* Passive monitor (listen only) */
902 #define OAL_IW_MODE_MESH 7 /* Mesh (IEEE 802.11s) network */
903
904 /* Transmit Power flags available */
905 #define OAL_IW_TXPOW_TYPE 0x00FF /* Type of value */
906 #define OAL_IW_TXPOW_DBM 0x0000 /* Value is in dBm */
907 #define OAL_IW_TXPOW_MWATT 0x0001 /* Value is in mW */
908 #define OAL_IW_TXPOW_RELATIVE 0x0002 /* Value is in arbitrary units */
909 #define OAL_IW_TXPOW_RANGE 0x1000 /* Range of value between min/max */
910
911 /* 主机与网络字节序转换 */
912
913 #define oal_host2net_short(_x) oal_swap_byteorder_16(_x)
914 #define oal_net2host_short(_x) oal_swap_byteorder_16(_x)
915 #define oal_host2net_long(_x) oal_swap_byteorder_32(_x)
916 #define oal_net2host_long(_x) oal_swap_byteorder_32(_x)
917
918 /* ARP protocol opcodes. */
919 #define OAL_ARPOP_REQUEST 1 /* ARP request */
920 #define OAL_ARPOP_REPLY 2 /* ARP reply */
921
922
923 #define OAL_IPPROTO_TCP 6 /* Transmission Control Protocol */
924
925 #define OAL_INIT_NET init_net
926 #define OAL_THIS_MODULE THIS_MODULE
927 #define OAL_MSG_DONTWAIT MSG_DONTWAIT
928
929 /* 管制域相关结构体定义 */
930 #define mhz_to_khz(freq) ((freq) * 1000)
931 #define dbi_to_mbi(gain) ((gain) * 100)
932 #define dbm_to_mbm(gain) ((gain) * 100)
933
934 #define reg_rule(start, end, bw, gain, eirp, reg_flags) \
935 { \
936 .freq_range.start_freq_khz = mhz_to_khz(start), \
937 .freq_range.end_freq_khz = mhz_to_khz(end), \
938 .freq_range.max_bandwidth_khz = mhz_to_khz(bw), \
939 .power_rule.max_antenna_gain = dbi_to_mbi(gain), \
940 .power_rule.max_eirp = dbm_to_mbm(eirp), \
941 .flags = (reg_flags), \
942 }
943
944 /* netlink相关 */
945 #define OAL_NLMSG_ALIGNTO 4
946 #define oal_nlmsg_align(_len) (((_len) + OAL_NLMSG_ALIGNTO - 1) & ~(OAL_NLMSG_ALIGNTO - 1))
947
948 /* VLAN以太网头 win32封装 */
949 typedef struct {
950 td_u8 h_dest[6]; /* 6字节目的地址 */
951 td_u8 h_source[6]; /* 6字节源地址 */
952 td_u16 h_vlan_proto;
953 td_u16 h_vlan_TCI;
954 td_u16 h_vlan_encapsulated_proto;
955 } oal_vlan_ethhdr_stru;
956 #endif
957
oal_ieee80211_channel_to_frequency(td_s32 l_channel,oal_ieee80211_band_enum_uint8 band)958 static inline td_s32 oal_ieee80211_channel_to_frequency(td_s32 l_channel,
959 oal_ieee80211_band_enum_uint8 band)
960 {
961 if (l_channel <= 0) {
962 return 0; /* not supported */
963 }
964
965 if (band == OAL_IEEE80211_BAND_2GHZ) {
966 /* 14:信道 2484/2407:频率 5:两个信道中心频率相差5MHZ */
967 return ((l_channel == 14) ? 2484 : (2407 + l_channel * 5));
968 } else if (band == OAL_IEEE80211_BAND_5GHZ) {
969 /* 182/196:信道 4000/5000:频率 5:两个信道中心频率相差5MHZ */
970 return ((l_channel >= 182 && l_channel <= 196) ? (4000 + l_channel * 5) : (5000 + l_channel * 5));
971 }
972
973 /* not supported */
974 return 0;
975 }
976
oal_ieee80211_frequency_to_channel(td_s32 l_center_freq)977 static inline td_s32 oal_ieee80211_frequency_to_channel(td_s32 l_center_freq)
978 {
979 td_s32 l_channel;
980
981 /* see 802.11 17.3.8.3.2 and Annex J */
982 if (l_center_freq == 0) {
983 l_channel = 0;
984 #ifdef _PRE_WLAN_FEATURE_015CHANNEL_EXP
985 } else if (l_center_freq == 2512) { // 频率为2512
986 l_channel = 15; // 频率为2512对应信道号为15
987 } else if (l_center_freq == 2384) { // 频率为2384
988 l_channel = 16; // 频率为2384对应信道号为16
989 #endif
990 } else if (l_center_freq == 2484) { /* 频率为2484 */
991 l_channel = 14; /* 14信道对应2484 */
992 } else if (l_center_freq < 2484) { /* 频率小于2484 */
993 l_channel = (l_center_freq - 2407) / 5; /* 频率小于2484对应的信道号 = (频率 - 2407)/ 5 */
994 } else if (l_center_freq >= 4910 && l_center_freq <= 4980) { /* 频率在[4910, 4980] */
995 l_channel = (l_center_freq - 4000) / 5; /* 对应的信道号 =(频率 - 4000) / 5 */
996 } else if (l_center_freq <= 45000) { /* DMG band lower limit 45000 */
997 l_channel = (l_center_freq - 5000) / 5; /* 对应的信道号 =(频率 - 5000) / 5 */
998 } else if (l_center_freq >= 58320 && l_center_freq <= 64800) { /* 频率在[58320, 64800] */
999 l_channel = (l_center_freq - 56160) / 2160; /* 对应的信道号 =(频率 - 56160)/2160 */
1000 } else {
1001 l_channel = 0;
1002 }
1003 return l_channel;
1004 }
1005
1006 #if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
oal_ieee80211_get_channel(oal_wiphy_stru * wiphy,td_s32 freq)1007 static inline oal_ieee80211_channel_stru* oal_ieee80211_get_channel(oal_wiphy_stru *wiphy,
1008 td_s32 freq)
1009 {
1010 return ieee80211_get_channel(wiphy, freq);
1011 }
1012
oal_wiphy_new(oal_cfg80211_ops_stru * ops,td_s32 sizeof_priv)1013 static inline oal_wiphy_stru* oal_wiphy_new(oal_cfg80211_ops_stru *ops, td_s32 sizeof_priv)
1014 {
1015 return wiphy_new(ops, sizeof_priv);
1016 }
1017
oal_wiphy_register(oal_wiphy_stru * wiphy)1018 static inline td_s32 oal_wiphy_register(oal_wiphy_stru *wiphy)
1019 {
1020 return wiphy_register(wiphy);
1021 }
1022
1023
oal_wiphy_unregister(oal_wiphy_stru * wiphy)1024 static inline td_void oal_wiphy_unregister(oal_wiphy_stru *wiphy)
1025 {
1026 return wiphy_unregister(wiphy);
1027 }
1028
1029
oal_wiphy_free(oal_wiphy_stru * wiphy)1030 static inline void oal_wiphy_free(oal_wiphy_stru *wiphy)
1031 {
1032 wiphy_free(wiphy);
1033 }
1034
oal_wiphy_priv(oal_wiphy_stru * wiphy)1035 static inline void *oal_wiphy_priv(oal_wiphy_stru *wiphy)
1036 {
1037 return wiphy_priv(wiphy);
1038 }
1039
1040
oal_wiphy_apply_custom_regulatory(oal_wiphy_stru * wiphy,const oal_ieee80211_regdomain_stru * regd)1041 static inline void oal_wiphy_apply_custom_regulatory(oal_wiphy_stru *wiphy,
1042 const oal_ieee80211_regdomain_stru *regd)
1043 {
1044 wiphy_apply_custom_regulatory(wiphy, regd);
1045 }
1046
oal_eth_type_trans(oal_netbuf_stru * pst_netbuf,oal_net_device_stru * device)1047 static inline td_u16 oal_eth_type_trans(oal_netbuf_stru *pst_netbuf, oal_net_device_stru *device)
1048 {
1049 return eth_type_trans(pst_netbuf, device);
1050 }
1051
oal_ether_setup(oal_net_device_stru * p_net_device)1052 static inline td_void oal_ether_setup(oal_net_device_stru *p_net_device)
1053 {
1054 if (TD_NULL == p_net_device) {
1055 return;
1056 }
1057
1058 ether_setup(p_net_device);
1059
1060 return;
1061 }
1062
oal_dev_get_by_name(const td_s8 * pc_name)1063 static inline oal_net_device_stru* oal_dev_get_by_name(const td_s8 *pc_name)
1064 {
1065 return dev_get_by_name(&init_net, pc_name);
1066 }
1067
1068
1069 #define oal_dev_put(_pst_dev) dev_put(_pst_dev)
1070
oal_net_close_dev(oal_net_device_stru * netdev)1071 static inline td_void oal_net_close_dev(oal_net_device_stru *netdev)
1072 {
1073 rtnl_lock();
1074 dev_close(netdev);
1075 rtnl_unlock();
1076 }
1077
oal_net_alloc_netdev(td_u32 sizeof_priv,td_s8 * name,td_void * p_set_up)1078 static inline oal_net_device_stru* oal_net_alloc_netdev(td_u32 sizeof_priv, td_s8 *name,
1079 td_void *p_set_up)
1080 {
1081 if ((TD_NULL == name) || (TD_NULL == p_set_up)) {
1082 return TD_NULL;
1083 }
1084 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0))
1085 return alloc_netdev(sizeof_priv, name, NET_NAME_UNKNOWN, p_set_up);
1086 #else
1087 return alloc_netdev(sizeof_priv, name, p_set_up);
1088 #endif
1089 }
1090
oal_net_alloc_netdev_mqs(td_u32 sizeof_priv,td_s8 * name,td_void * p_set_up,td_u32 txqs,td_u32 rxqs)1091 static inline oal_net_device_stru* oal_net_alloc_netdev_mqs(td_u32 sizeof_priv, td_s8 *name,
1092 td_void *p_set_up, td_u32 txqs, td_u32 rxqs)
1093 {
1094 if ((TD_NULL == name) || (TD_NULL == p_set_up)) {
1095 return TD_NULL;
1096 }
1097 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0))
1098 return alloc_netdev_mq(sizeof_priv, name, NET_NAME_UNKNOWN, p_set_up, txqs);
1099 #else
1100 return alloc_netdev_mq(sizeof_priv, name, p_set_up, txqs);
1101 #endif
1102 }
1103
oal_net_tx_wake_all_queues(oal_net_device_stru * dev)1104 static inline td_void oal_net_tx_wake_all_queues(oal_net_device_stru *dev)
1105 {
1106 if (TD_NULL == dev) {
1107 return;
1108 }
1109
1110 return netif_tx_wake_all_queues(dev);
1111 }
1112
1113
oal_net_tx_stop_all_queues(oal_net_device_stru * dev)1114 static inline td_void oal_net_tx_stop_all_queues(oal_net_device_stru *dev)
1115 {
1116 if (TD_NULL == dev) {
1117 return;
1118 }
1119
1120 return netif_tx_stop_all_queues(dev);
1121 }
1122
oal_net_wake_subqueue(oal_net_device_stru * dev,td_u16 queue_idx)1123 static inline td_void oal_net_wake_subqueue(oal_net_device_stru *dev, td_u16 queue_idx)
1124 {
1125 if (TD_NULL == dev) {
1126 return;
1127 }
1128
1129 return netif_wake_subqueue(dev, queue_idx);
1130 }
1131
1132
oal_net_stop_subqueue(oal_net_device_stru * dev,td_u16 queue_idx)1133 static inline td_void oal_net_stop_subqueue(oal_net_device_stru *dev, td_u16 queue_idx)
1134 {
1135 if (TD_NULL == dev) {
1136 return;
1137 }
1138
1139 return netif_stop_subqueue(dev, queue_idx);
1140 }
1141
oal_net_free_netdev(oal_net_device_stru * netdev)1142 static inline td_void oal_net_free_netdev(oal_net_device_stru *netdev)
1143 {
1144 if (TD_NULL == netdev) {
1145 return ;
1146 }
1147
1148 free_netdev(netdev);
1149 }
1150
oal_net_register_netdev(oal_net_device_stru * p_net_device)1151 static inline td_s32 oal_net_register_netdev(oal_net_device_stru *p_net_device)
1152 {
1153 if (TD_NULL == p_net_device) {
1154 return OAL_ERR_CODE_PTR_NULL;
1155 }
1156
1157 /* Just For HCC */
1158 #ifdef _PRE_WLAN_FEATURE_MULTI_NETBUF_AMSDU
1159 /* ETHER HEAD 4bytes */
1160 OAL_NETDEVICE_HEADROOM(p_net_device) = 74; /* netdevice headroom指定大小74 */
1161 #else
1162 OAL_NETDEVICE_HEADROOM(p_net_device) = 64; /* netdevice headroom指定大小64 */
1163 #endif
1164 OAL_NETDEVICE_TAILROOM(p_net_device) = 32; /* netdevice tailroom指定大小32 */
1165
1166 return register_netdev(p_net_device);
1167 }
1168
oal_net_unregister_netdev(oal_net_device_stru * p_net_device)1169 static inline td_void oal_net_unregister_netdev(oal_net_device_stru *p_net_device)
1170 {
1171 if (TD_NULL == p_net_device) {
1172 return ;
1173 }
1174
1175 if (p_net_device->reg_state != NETREG_REGISTERED) {
1176 wifi_printf("net device not registed regstate:%d!!\n", p_net_device->reg_state);
1177 return;
1178 }
1179 unregister_netdev(p_net_device);
1180 }
1181
oal_net_device_open(oal_net_device_stru * dev)1182 static inline td_s32 oal_net_device_open(oal_net_device_stru *dev)
1183 {
1184 dev->flags |= OAL_IFF_RUNNING;
1185
1186 return OAL_SUCC;
1187 }
1188
oal_net_device_close(oal_net_device_stru * dev)1189 static inline td_s32 oal_net_device_close(oal_net_device_stru *dev)
1190 {
1191 dev->flags &= ~OAL_IFF_RUNNING;
1192
1193 return OAL_SUCC;
1194 }
1195
oal_net_device_set_macaddr(oal_net_device_stru * dev,td_void * addr)1196 static inline td_s32 oal_net_device_set_macaddr(oal_net_device_stru *dev, td_void *addr)
1197 {
1198 oal_sockaddr_stru *mac;
1199
1200 mac = (oal_sockaddr_stru *)addr;
1201
1202 (td_void)memcpy_s(dev->dev_addr, ETHER_ADDR_LEN, mac->sa_data, ETHER_ADDR_LEN);
1203 return OAL_SUCC;
1204 }
1205
oal_net_device_init(oal_net_device_stru * dev)1206 static inline td_s32 oal_net_device_init(oal_net_device_stru *dev)
1207 {
1208 return OAL_SUCC;
1209 }
1210
oal_net_device_get_stats(oal_net_device_stru * dev)1211 static inline oal_net_device_stats_stru *oal_net_device_get_stats(oal_net_device_stru *dev)
1212 {
1213 oal_net_device_stats_stru *stats;
1214
1215 stats = &dev->stats;
1216
1217 stats->tx_errors = 0;
1218 stats->tx_dropped = 0;
1219 stats->tx_packets = 0;
1220 stats->rx_packets = 0;
1221 stats->rx_errors = 0;
1222 stats->rx_dropped = 0;
1223 stats->rx_crc_errors = 0;
1224
1225 return stats;
1226 }
1227
oal_net_device_ioctl(oal_net_device_stru * dev,oal_ifreq_stru * ifr,td_s32 ul_cmd)1228 static inline td_s32 oal_net_device_ioctl(oal_net_device_stru *dev, oal_ifreq_stru *ifr, td_s32 ul_cmd)
1229 {
1230 return -OAL_EINVAL;
1231 }
1232
oal_net_device_change_mtu(oal_net_device_stru * dev,td_s32 mtu)1233 static inline td_s32 oal_net_device_change_mtu(oal_net_device_stru *dev, td_s32 mtu)
1234 {
1235 dev->mtu = mtu;
1236 return OAL_SUCC;
1237 }
1238
1239 #ifdef _PRE_SKB_TRACE
1240 #define oal_netif_rx_ni(pst_netbuf) \
1241 ({ \
1242 mem_trace_delete_node((osal_ulong)(pst_netbuf)); \
1243 netif_rx_ni(pst_netbuf); \
1244 })
1245 #else
oal_netif_rx_ni(oal_netbuf_stru * pst_netbuf)1246 static inline td_s32 oal_netif_rx_ni(oal_netbuf_stru *pst_netbuf)
1247 {
1248 return netif_rx_ni(pst_netbuf);
1249 }
1250 #endif
1251
oal_nla_put_u32(oal_netbuf_stru * skb,td_s32 l_attrtype,td_u32 value)1252 static inline td_s32 oal_nla_put_u32(oal_netbuf_stru *skb, td_s32 l_attrtype, td_u32 value)
1253 {
1254 return nla_put_u32(skb, l_attrtype, value);
1255 }
1256
oal_nla_put_u16(oal_netbuf_stru * skb,td_s32 l_attrtype,td_u32 value)1257 static inline td_s32 oal_nla_put_u16(oal_netbuf_stru *skb, td_s32 l_attrtype, td_u32 value)
1258 {
1259 return nla_put_u16(skb, l_attrtype, value);
1260 }
1261
oal_nla_put_flag(oal_netbuf_stru * skb,td_s32 l_attrtype)1262 static inline td_s32 oal_nla_put_flag(oal_netbuf_stru *skb, td_s32 l_attrtype)
1263 {
1264 return nla_put_flag(skb, l_attrtype);
1265 }
1266
oal_nla_put(oal_netbuf_stru * skb,td_s32 l_attrtype,td_s32 l_attrlen,const td_void * p_data)1267 static inline td_s32 oal_nla_put(oal_netbuf_stru *skb, td_s32 l_attrtype, td_s32 l_attrlen, const td_void *p_data)
1268 {
1269 return nla_put(skb, l_attrtype, l_attrlen, p_data);
1270 }
1271
1272 /*
1273 * nla_put_nohdr - Add a netlink attribute without header
1274 * @skb: socket buffer to add attribute to
1275 * @attrlen: length of attribute payload
1276 * @data: head of attribute payload
1277 *
1278 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
1279 * the attribute payload.
1280 */
oal_nla_put_nohdr(oal_netbuf_stru * skb,td_s32 l_attrlen,const td_void * p_data)1281 static inline td_s32 oal_nla_put_nohdr(oal_netbuf_stru *skb, td_s32 l_attrlen, const td_void *p_data)
1282 {
1283 return nla_put_nohdr(skb, l_attrlen, p_data);
1284 }
1285
oal_nlmsg_new(td_s32 payload,oal_gfp_enum_uint8 flags)1286 static inline oal_netbuf_stru *oal_nlmsg_new(td_s32 payload, oal_gfp_enum_uint8 flags)
1287 {
1288 return nlmsg_new(payload, flags);
1289 }
1290
oal_nlmsg_free(oal_netbuf_stru * skb)1291 static inline td_void oal_nlmsg_free(oal_netbuf_stru *skb)
1292 {
1293 return nlmsg_free(skb);
1294 }
1295
oal_genlmsg_multicast(oal_genl_family_stru * family,oal_netbuf_stru * skb,td_u32 pid,td_u32 group,oal_gfp_enum_uint8 flags)1296 static inline td_s32 oal_genlmsg_multicast(oal_genl_family_stru *family, oal_netbuf_stru *skb, td_u32 pid,
1297 td_u32 group, oal_gfp_enum_uint8 flags)
1298 {
1299 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0))
1300 return genlmsg_multicast(skb, pid, group, flags);
1301 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0))
1302 return genlmsg_multicast(family, skb, pid, group, flags);
1303 #else
1304 /* Linux genlmsg_multicast */
1305 return OAL_SUCC;
1306 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) */
1307 }
1308
oal_genlmsg_put(oal_netbuf_stru * skb,td_u32 pid,td_u32 seq,oal_genl_family_stru * family,td_s32 flags,td_u8 cmd)1309 static inline td_void *oal_genlmsg_put(oal_netbuf_stru *skb, td_u32 pid, td_u32 seq,
1310 oal_genl_family_stru *family, td_s32 flags, td_u8 cmd)
1311 {
1312 return genlmsg_put(skb, pid, seq, family, flags, cmd);
1313 }
1314
oal_nla_nest_start(oal_netbuf_stru * skb,td_s32 l_attrtype)1315 static inline oal_nlattr_stru *oal_nla_nest_start(oal_netbuf_stru *skb, td_s32 l_attrtype)
1316 {
1317 return nla_nest_start(skb, l_attrtype);
1318 }
1319
oal_genlmsg_cancel(oal_netbuf_stru * skb,td_void * hdr)1320 static inline td_void oal_genlmsg_cancel(oal_netbuf_stru *skb, td_void *hdr)
1321 {
1322 return genlmsg_cancel(skb, hdr);
1323 }
1324
oal_nla_nest_end(oal_netbuf_stru * skb,oal_nlattr_stru * start)1325 static inline td_s32 oal_nla_nest_end(oal_netbuf_stru *skb, oal_nlattr_stru *start)
1326 {
1327 return nla_nest_end(skb, start);
1328 }
1329
oal_genlmsg_end(oal_netbuf_stru * skb,td_void * hdr)1330 static inline td_s32 oal_genlmsg_end(oal_netbuf_stru *skb, td_void *hdr)
1331 {
1332 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0))
1333 return genlmsg_end(skb, hdr);
1334 #else
1335 genlmsg_end(skb, hdr);
1336 return OAL_SUCC;
1337 #endif
1338 }
1339
oal_nla_data(const oal_nlattr_stru * nla)1340 static inline td_void *oal_nla_data(const oal_nlattr_stru *nla)
1341 {
1342 return nla_data(nla);
1343 }
1344
oal_nla_get_u8(const oal_nlattr_stru * nla)1345 static inline td_u32 oal_nla_get_u8(const oal_nlattr_stru *nla)
1346 {
1347 return nla_get_u8(nla);
1348 }
1349
oal_nla_get_u16(const oal_nlattr_stru * nla)1350 static inline td_u32 oal_nla_get_u16(const oal_nlattr_stru *nla)
1351 {
1352 return nla_get_u16(nla);
1353 }
1354
oal_nla_get_u32(const oal_nlattr_stru * nla)1355 static inline td_u32 oal_nla_get_u32(const oal_nlattr_stru *nla)
1356 {
1357 return nla_get_u32(nla);
1358 }
1359
1360
oal_nla_total_size(const oal_nlattr_stru * nla)1361 static inline td_u32 oal_nla_total_size(const oal_nlattr_stru *nla)
1362 {
1363 td_s32 payload = nla_len(nla);
1364 return nla_total_size(payload);
1365 }
1366
oal_nla_len(const oal_nlattr_stru * nla)1367 static inline td_s32 oal_nla_len(const oal_nlattr_stru *nla)
1368 {
1369 return nla_len(nla);
1370 }
1371
1372
oal_nla_type(const oal_nlattr_stru * nla)1373 static inline td_s32 oal_nla_type(const oal_nlattr_stru *nla)
1374 {
1375 return nla_type(nla);
1376 }
1377
oal_wiphy_to_dev(oal_wiphy_stru * wiphy)1378 static inline oal_cfg80211_registered_device_stru *oal_wiphy_to_dev(oal_wiphy_stru *wiphy)
1379 {
1380 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0))
1381 return wiphy_to_dev(wiphy);
1382 #else
1383 return wiphy_to_rdev(wiphy);
1384 #endif
1385 }
1386
oal_csum_ipv6_magic(oal_in6_addr * ipv6_s,oal_in6_addr * ipv6_d,td_u32 len,td_u16 proto,td_u32 sum)1387 static inline td_u16 oal_csum_ipv6_magic(oal_in6_addr *ipv6_s, oal_in6_addr *ipv6_d,
1388 td_u32 len, td_u16 proto, td_u32 sum)
1389 {
1390 return csum_ipv6_magic(ipv6_s, ipv6_d, len, proto, sum);
1391 }
1392
oal_csum_partial(const td_void * p_buff,td_s32 l_len,td_u32 sum)1393 static inline td_u32 oal_csum_partial(const td_void *p_buff, td_s32 l_len, td_u32 sum)
1394 {
1395 return csum_partial(p_buff, l_len, sum);
1396 }
1397
oal_ipv6_addr_type(oal_in6_addr * ipv6)1398 static inline td_s32 oal_ipv6_addr_type(oal_in6_addr *ipv6)
1399 {
1400 #ifdef _PRE_WLAN_FEATURE_SUPPORT_IPV6
1401 return ipv6_addr_type(ipv6);
1402 #else
1403 return (td_s32)IPV6_ADDR_RESERVED;
1404 #endif
1405 }
1406
oal_pskb_may_pull(oal_netbuf_stru * nb,td_u32 len)1407 static inline td_s32 oal_pskb_may_pull(oal_netbuf_stru *nb, td_u32 len)
1408 {
1409 return pskb_may_pull(nb, len);
1410 }
1411
oal_arp_create(td_s32 l_type,td_s32 l_ptype,td_u32 dest_ip,oal_net_device_stru * dev,td_u32 src_ip,td_u8 * dest_hw,td_u8 * src_hw,td_u8 * target_hw)1412 static inline oal_netbuf_stru *oal_arp_create(td_s32 l_type, td_s32 l_ptype, td_u32 dest_ip,
1413 oal_net_device_stru *dev, td_u32 src_ip, td_u8 *dest_hw, td_u8 *src_hw, td_u8 *target_hw)
1414 {
1415 return arp_create(l_type, l_ptype, dest_ip, dev, src_ip, dest_hw, src_hw, target_hw);
1416 }
1417 extern oal_bool_enum_uint8 oal_netbuf_is_dhcp_port_etc(const oal_udp_header_stru *udp_hdr);
1418 extern oal_bool_enum_uint8 oal_netbuf_is_dhcp6_etc(oal_ipv6hdr_stru *ipv6hdr);
1419 extern oal_bool_enum_uint8 oal_netbuf_is_tcp_ack6_etc(oal_ipv6hdr_stru *ipv6hdr);
1420 extern osal_u16 oal_netbuf_select_queue_etc(oal_netbuf_stru *buf);
1421 extern oal_bool_enum_uint8 oal_netbuf_is_tcp_ack_etc(oal_ip_header_stru *ip_hdr);
1422 extern oal_bool_enum_uint8 oal_netbuf_is_icmp_etc(oal_ip_header_stru *ip_hdr);
1423
1424 #elif defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
1425
1426 typedef struct ieee80211_channel_sw_ie {
1427 osal_u8 mode;
1428 osal_u8 new_ch_num;
1429 osal_u8 count;
1430 osal_u8 rsv[1];
1431 } oal_ieee80211_channel_sw_ie;
1432
1433 td_u32 hwal_netif_rx(oal_net_device_stru* netdev, oal_netbuf_stru* netbuf);
1434
1435 #define chan2g(_channel, _freq, _flags) \
1436 { \
1437 .band = OAL_IEEE80211_BAND_2GHZ, \
1438 .center_freq = (_freq), \
1439 .hw_value = (_channel), \
1440 .flags = (_flags), \
1441 .max_antenna_gain = 0, \
1442 .max_power = 30, \
1443 }
1444
1445 #define ratetab_ent(_rate, _rateid, _flags) \
1446 { \
1447 .bitrate = (_rate), \
1448 .hw_value = (_rateid), \
1449 .flags = (_flags), \
1450 }
1451
oal_net_tx_stop_all_queues(const oal_net_device_stru * dev)1452 static inline osal_void oal_net_tx_stop_all_queues(const oal_net_device_stru *dev)
1453 {
1454 if (dev == OAL_PTR_NULL) {
1455 return;
1456 }
1457
1458 return;
1459 }
1460
oal_net_tx_wake_all_queues(const oal_net_device_stru * dev)1461 static inline osal_void oal_net_tx_wake_all_queues(const oal_net_device_stru *dev)
1462 {
1463 if (dev == OAL_PTR_NULL) {
1464 return;
1465 }
1466
1467 return ;
1468 }
1469
oal_net_stop_subqueue(const oal_net_device_stru * dev,osal_u16 queue_idx)1470 static inline osal_void oal_net_stop_subqueue(const oal_net_device_stru *dev, osal_u16 queue_idx)
1471 {
1472 unref_param(queue_idx);
1473 if (dev == OAL_PTR_NULL) {
1474 return;
1475 }
1476
1477 return ;
1478 }
1479
1480
oal_netif_rx(oal_netbuf_stru * pst_netbuf)1481 static inline osal_s32 oal_netif_rx(oal_netbuf_stru *pst_netbuf)
1482 {
1483 return (osal_s32)hwal_netif_rx(pst_netbuf->dev, pst_netbuf);
1484 }
1485
1486
oal_netbuf_get_bitfield(osal_void)1487 static inline osal_u8 oal_netbuf_get_bitfield(osal_void)
1488 {
1489 bitfield_un un_bitfield;
1490
1491 un_bitfield.byte = 0x12;
1492 if (un_bitfield.bits.low == 0x2) {
1493 return OAL_BITFIELD_LITTLE_ENDIAN;
1494 } else {
1495 return OAL_BITFIELD_BIG_ENDIAN;
1496 }
1497 }
1498
1499
1500 #ifdef _PRE_SKB_TRACE
1501 #define oal_netbuf_copy(pst_netbuf, priority) \
1502 ({ \
1503 oal_netbuf_stru *__no_pst_copy_netbuf; \
1504 __no_pst_copy_netbuf = skb_copy(pst_netbuf, priority); \
1505 if (__no_pst_copy_netbuf) \
1506 { \
1507 mem_trace_add_node((osal_ulong)__no_pst_copy_netbuf); \
1508 } \
1509 __no_pst_copy_netbuf; \
1510 })
1511 #else
1512 #define oal_netbuf_copy(pst_netbuf, priority) _oal_netbuf_copy(pst_netbuf, priority)
1513 #endif
1514
oal_net_wake_subqueue(const oal_net_device_stru * dev,osal_u16 queue_idx)1515 static inline osal_void oal_net_wake_subqueue(const oal_net_device_stru *dev, osal_u16 queue_idx)
1516 {
1517 unref_param(queue_idx);
1518 if (dev == OAL_PTR_NULL) {
1519 return;
1520 }
1521
1522 return ;
1523 }
1524
oal_eth_type_trans(oal_netbuf_stru * pst_netbuf,oal_net_device_stru * device)1525 static inline osal_u16 oal_eth_type_trans(oal_netbuf_stru *pst_netbuf, oal_net_device_stru *device)
1526 {
1527 unref_param(device);
1528 oal_netbuf_pull(pst_netbuf, sizeof(oal_ether_header_stru));
1529 return 0;
1530 }
1531
oal_net_close_dev(oal_net_device_stru * netdev)1532 static inline osal_void oal_net_close_dev(oal_net_device_stru *netdev)
1533 {
1534 OAL_NETDEVICE_FLAGS(netdev) &= ~OAL_IFF_RUNNING;
1535 }
1536
oal_net_device_open(oal_net_device_stru * dev)1537 static inline osal_s32 oal_net_device_open(oal_net_device_stru *dev)
1538 {
1539 dev->flags |= OAL_IFF_RUNNING;
1540
1541 return OAL_SUCC;
1542 }
1543
oal_net_device_close(oal_net_device_stru * dev)1544 static inline osal_s32 oal_net_device_close(oal_net_device_stru *dev)
1545 {
1546 dev->flags &= ~OAL_IFF_RUNNING;
1547
1548 return OAL_SUCC;
1549 }
1550
oal_net_device_set_macaddr(oal_net_device_stru * dev,osal_void * addr)1551 static inline osal_s32 oal_net_device_set_macaddr(oal_net_device_stru *dev, osal_void *addr)
1552 {
1553 oal_sockaddr_stru *mac;
1554
1555 mac = (oal_sockaddr_stru *)addr;
1556
1557 (osal_void)memcpy_s(dev->dev_addr, 6, mac->sa_data, 6); /* 6:mac长度 */
1558 return OAL_SUCC;
1559 }
1560
oal_net_device_init(oal_net_device_stru * dev)1561 static inline osal_s32 oal_net_device_init(oal_net_device_stru *dev)
1562 {
1563 unref_param(dev);
1564 return OAL_SUCC;
1565 }
1566
oal_net_device_get_stats(oal_net_device_stru * dev)1567 static inline oal_net_device_stats_stru *oal_net_device_get_stats(oal_net_device_stru *dev)
1568 {
1569 oal_net_device_stats_stru *stats;
1570
1571 stats = &dev->stats;
1572
1573 stats->tx_errors = 0;
1574 stats->tx_dropped = 0;
1575 stats->tx_packets = 0;
1576 stats->rx_packets = 0;
1577 stats->rx_errors = 0;
1578 stats->rx_dropped = 0;
1579 stats->rx_crc_errors = 0;
1580
1581 return stats;
1582 }
1583
oal_net_device_ioctl(oal_net_device_stru * dev,oal_ifreq_stru * ifr,osal_s32 ul_cmd)1584 static inline osal_s32 oal_net_device_ioctl(oal_net_device_stru *dev, oal_ifreq_stru *ifr, osal_s32 ul_cmd)
1585 {
1586 unref_param(dev);
1587 unref_param(ifr);
1588 unref_param(ul_cmd);
1589 return -OAL_EINVAL;
1590 }
1591
oal_net_device_change_mtu(oal_net_device_stru * dev,osal_s32 mtu)1592 static inline osal_s32 oal_net_device_change_mtu(oal_net_device_stru *dev, osal_s32 mtu)
1593 {
1594 dev->mtu = (osal_u32)mtu;
1595 return OAL_SUCC;
1596 }
1597
1598 #ifdef _PRE_SKB_TRACE
1599 #define oal_netif_rx_ni(pst_netbuf) \
1600 ({ \
1601 mem_trace_delete_node((osal_ulong)(pst_netbuf)); \
1602 netif_rx_ni(pst_netbuf); \
1603 })
1604 #else
oal_netif_rx_ni(oal_netbuf_stru * pst_netbuf)1605 static inline osal_s32 oal_netif_rx_ni(oal_netbuf_stru *pst_netbuf)
1606 {
1607 #if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
1608 return (osal_s32)hwal_netif_rx(pst_netbuf->dev, pst_netbuf);
1609 #elif defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
1610 return netif_rx_ni(pst_netbuf);
1611 #endif
1612 }
1613 #endif
1614
1615 oal_bool_enum_uint8 oal_netbuf_is_dhcp_port_etc(const oal_udp_header_stru *udp_hdr);
1616 oal_bool_enum_uint8 oal_netbuf_is_dhcp6_etc(oal_ipv6hdr_stru *ipv6hdr);
1617 oal_net_device_stru* oal_net_alloc_netdev(const td_char *name, td_u8 max_name_len);
1618 td_void oal_net_free_netdev(oal_net_device_stru *netdev);
1619 td_u32 oal_net_register_netdev(oal_net_device_stru* netdev);
1620 td_void oal_net_unregister_netdev(oal_net_device_stru* netdev);
1621
1622 oal_bool_enum_uint8 oal_netbuf_is_tcp_ack6_etc(oal_ipv6hdr_stru *ipv6hdr);
1623 osal_u16 oal_netbuf_select_queue_etc(oal_netbuf_stru *buf);
1624 oal_bool_enum_uint8 oal_netbuf_is_tcp_ack_etc(oal_ip_header_stru *ip_hdr);
1625 oal_bool_enum_uint8 oal_netbuf_is_icmp_etc(oal_ip_header_stru *ip_hdr);
1626
1627 /* ws61 */
1628 oal_net_device_stru* oal_get_past_net_device_by_index(td_u32 netdev_index);
1629 td_void oal_set_past_net_device_by_index(td_u32 netdev_index, oal_net_device_stru *netdev);
1630 oal_net_device_stru* oal_get_netdev_by_name(const td_char* pc_name);
1631 oal_net_device_stru* oal_get_netdev_by_type(nl80211_iftype_uint8 type);
1632 td_u32 oal_net_check_and_get_devname(nl80211_iftype_uint8 type, char* dev_name, td_u32* len);
1633 td_void oal_net_tx_wake_all_queues(const oal_net_device_stru *dev);
1634
1635
1636 #endif
1637
1638
1639 #ifdef __cplusplus
1640 #if __cplusplus
1641 }
1642 #endif
1643 #endif
1644
1645 #endif /* end of file */
1646