• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: hmac_m2u.c的头文件
15  */
16 
17 #ifndef __HMAC_M2U_H__
18 #define __HMAC_M2U_H__
19 
20 /*****************************************************************************
21   1 其他头文件包含
22 *****************************************************************************/
23 #include "oal_netbuf_ext.h"
24 #include "oal_ext_if.h"
25 #include "oam_ext_if.h"
26 #include "mac_frame.h"
27 #include "hmac_main.h"
28 #include "hmac_user.h"
29 #include "hmac_vap.h"
30 #include "frw_ext_if.h"
31 
32 #ifdef __cplusplus
33 #if __cplusplus
34 extern "C" {
35 #endif
36 #endif
37 
38 #undef  THIS_FILE_ID
39 #define THIS_FILE_ID OAM_FILE_ID_HMAC_M2U_H
40 
41 typedef enum {
42     HMAC_H2U_DENY_TABLE_LIST = 0,
43     HMAC_H2U_DENY_TABLE_CLEAR,
44     HMAC_H2U_DENY_TABLE_ADD_IPV4,
45     HMAC_H2U_DENY_TABLE_ADD_IPV6,
46     HMAC_H2U_DENY_TABLE_DEL_IPV4,
47     HMAC_H2U_DENY_TABLE_DEL_IPV6,
48 
49     HMAC_M2U_DENY_TABLE_BUTT
50 } hmac_m2u_deny_table_cfg;
51 
52 /*****************************************************************************
53   2 宏定义
54 *****************************************************************************/
55 #define HMAC_M2U_GRPADDR_FILTEROUT_NUM 8
56 #define HMAC_M2U_DENY_GROUP 4026531585UL     /* 组播组黑名单 239.255.255.1 */
57 #define HMAC_M2U_MIN_DENY_GROUP 3758096384UL /* 最小组播组地址 224.0.0.0 */
58 #define HMAC_M2U_MAX_DENY_GROUP 4026531839UL /* 最大组播组地址 239.255.255.255 */
59 #define HMAC_M2U_SPECIAL_GROUP1 3758096385UL    /* SPECIAL  GROUP1 224.0.0.1 */
60 #define HMAC_M2U_SPECIAL_GROUP2 3758096386UL    /* SPECIAL  GROUP2 224.0.0.2 */
61 #define HMAC_M2U_RIPV2_GROUP 3758096393UL       /* RIPV2  GROUP 224.0.0.9 */
62 #define HMAC_M2U_SPECIAL_GROUP3 3758096406UL    /* SPECIAL  GROUP3 224.0.0.22 */
63 #define HMAC_M2U_UPNP_GROUP 4026531834UL        /* UPNP GROUP 239.255.255.250 */
64 
65 #define DEFAULT_IPV4_DENY_GROUP_COUNT 1      /* 默认额外添加1个ipv4组播黑名单 */
66 #define DEFAULT_IPV6_DENY_GROUP_COUNT 1      /* 默认添加1个ipv6组播黑名单 */
67 #define SPECIAL_M2U_GROUP_COUNT_IPV4  5      /* 默认添加5个特殊ipv4业务组播 */
68 #define SPECIAL_M2U_GROUP_COUNT_IPV6  5      /* 默认添加5个特殊ipv6业务组播 */
69 #define HMAC_M2U_ADAPTIVE_STA_HASHSIZE 16    /* 配网报文统计HASH桶为16 */
70 
71 
72 #define MAC_ETH_PROTOCOL_SUBTYPE  0x17
73 #define OAL_SNAP_LEN              8    /* SNAP 头的长度 */
74 #define MIN_IP_HDR_LEN            5    /* 最小IP头长度 */
75 
76 #define HMAC_DEF_M2U_TIMER        30000     /* timer interval as 30 secs */
77 #define HMAC_DEF_M2U_TIMEOUT      120000    /* 2 minutes for timeout  */
78 
79 #define HMAC_DEF_ADAPTIVE_TIMEOUT      1000      /* 配网模式老化时间  */
80 #define HMAC_DEF_THRESHOLD_TIME        500       /* 配网模式门限时间  */
81 #define HMAC_DEF_NUM_OF_ADAPTIVE       16        /* 配网模式门限个数  */
82 
83 #define ETHER_TYPE_VLAN_88A8      0x88a8  /* VLAN TAG TPID ,有运营商的情况 */
84 #define ETHER_TYPE_VLAN_9100      0x9100  /* VLAN TAG TPID */
85 #define MAX_STA_NUM_OF_ALL_GROUP  1000    /* 最多1000个叶子节点(sta个数) */
86 #define MAX_STA_NUM_OF_ADAPTIVE   128     /* 最多128个配网sta个数 */
87 #define MAX_STR_SIZE_OF_U8         4       /* U8类型转换成字符串最多3个字符,+1个'\0'占用4个字符 */
88 
89 #define HMAC_M2U_MAX_PRINT_SIZE 100 /* 最大打印字节数 */
90 
91 #define ether_is_with_vlan_tag(_a) \
92         (((_a) == oal_host2net_short(ETHER_TYPE_VLAN_88A8)) ||    \
93          ((_a) == oal_host2net_short(ETHER_TYPE_VLAN_9100)) ||    \
94          ((_a) == oal_host2net_short(ETHER_TYPE_VLAN)))
95 
96 #define oal_is_mdnsv4_mac(_a, _b)   (((osal_u8)((_a)[0]) == 0x01) && ((osal_u8)((_a)[1]) == 0x00) && \
97                                     ((osal_u8)((_a)[2]) == 0x5e) && ((osal_u8)((_a)[3]) == 0x00) && \
98                                     ((osal_u8)((_a)[4]) == 0x00) && ((osal_u8)((_a)[5]) == 0xfb) && \
99                                     ((_b) == oal_host2net_short(ETHER_TYPE_IP)))
100 #define oal_is_mdnsv6_mac(_a, _b)   (((osal_u8)((_a)[0]) == 0x33) && ((osal_u8)((_a)[1]) == 0x33) && \
101                                     ((osal_u8)((_a)[2]) == 0x00) && ((osal_u8)((_a)[3]) == 0x00) && \
102                                     ((osal_u8)((_a)[4]) == 0x00) && ((osal_u8)((_a)[5]) == 0xfb) && \
103                                     ((_b) == oal_host2net_short(ETHER_TYPE_IPV6)))
104 
105 #ifdef _PRE_WLAN_FEATURE_HERA_MCAST
106 /* 配网报文哈希函数定义 */
107 #define hmac_adaptive_cal_hash_value(_puc_mac_addr)     \
108     ((_puc_mac_addr)[ETHER_ADDR_LEN - 1] & (HMAC_M2U_ADAPTIVE_STA_HASHSIZE - 1))
109 #endif
110 
111 /*****************************************************************************
112   3 枚举定义
113 *****************************************************************************/
114 typedef enum {
115     HMAC_M2U_CMD_EXCLUDE_LIST  = 0,
116     HMAC_M2U_CMD_INCLUDE_LIST  = 1,
117 
118     HMAC_M2U_IGMP_CMD_BUTT
119 } hmac_m2u_update_cmd_enum;
120 typedef osal_u8 hmac_m2u_igmp_cmd_enum_uint8;
121 
122 typedef enum {
123     HMAC_M2U_MCAST_MAITAIN         = 0,
124     HMAC_M2U_MCAST_TUNNEL          = 1,
125     HMAC_M2U_MCAST_TRANSLATE       = 2,
126 
127     HMAC_M2U_MCAST_BUTT
128 } hmac_m2u_mcast_mode_enum;
129 typedef osal_u8 hmac_m2u_mcast_mode_enum_uint8;
130 
131 typedef struct {
132 #if defined(OAL_BYTE_ORDER) && defined(OAL_LITTLE_ENDIAN) && (OAL_BYTE_ORDER == OAL_LITTLE_ENDIAN)
133     osal_u32 offset                : 11,
134              seq_num               : 11,
135              opt_hdr_len32         : 2,
136              frame_type            : 2,
137              proto                 : 6;
138 #else /* big endian */
139     osal_u32 proto                 : 6,
140              frame_type            : 2,
141              opt_hdr_len32         : 2,
142              seq_num               : 11,
143              offset                : 11;
144 #endif
145 } mcast_tunnel_hdr_stru;
146 
147 /*****************************************************************************
148   4 全局变量声明
149 *****************************************************************************/
150 
151 
152 /*****************************************************************************
153   5 消息头定义
154 *****************************************************************************/
155 
156 
157 /*****************************************************************************
158   6 消息定义
159 *****************************************************************************/
160 
161 
162 /*****************************************************************************
163   7 STRUCT定义
164 *****************************************************************************/
165 
166 /* hmac_m2u_grp_list_entry通过各组的不同地址来存储组,挂到snoop_list下 */
167 // 组播组结构体
168 typedef struct {
169     struct osal_list_head               src_list;                        /* 组播组内成员的链表头 */
170     osal_u8                         group_mac[WLAN_MAC_ADDR_LEN];   /* 这个组播组的组mac地址 */
171     osal_u8                         sta_num;                         /* 记录当前组播组下sta个数 */
172     osal_u8                         reserve;
173     struct osal_list_head               grp_entry;
174     mac_vlan_tag_stru                 outer_vlan_tag;                  /*  外层vlan tag */
175     mac_vlan_tag_stru                 inner_vlan_tag;                  /*  内层vlan tag */
176 } hmac_m2u_grp_list_entry_stru;
177 
178 /* 管理组播组的snoop链表结构 */
179 typedef struct {
180     osal_u32               deny_group[HMAC_M2U_GRPADDR_FILTEROUT_NUM];
181     osal_u8                deny_group_ipv6[HMAC_M2U_GRPADDR_FILTEROUT_NUM][OAL_IPV6_ADDR_SIZE];
182     struct osal_list_head      grp_list;            /* 组链表头 */
183     osal_u16               group_list_count;    /* 组播组个数 */
184     osal_u16               misc;
185     osal_u16               total_sta_num;       /* 记录当前各组播组下sta总数 */
186     osal_u8                deny_count_ipv4;     /* ipv4黑名单个数 */
187     osal_u8                deny_count_ipv6;     /* ipv6黑名单个数 */
188     osal_u32               special_group_ipv4[SPECIAL_M2U_GROUP_COUNT_IPV4]; /* ipv4特殊组播IP */
189     osal_u8             special_group_ipv6[SPECIAL_M2U_GROUP_COUNT_IPV6][OAL_IPV6_ADDR_SIZE]; /* ipv6特殊组播IP */
190 } hmac_m2u_snoop_list_stru;
191 
192 /**
193  * hmac_m2u_grp_member_stru 用来存储一个组成员的详细信息
194  * 每一个成员拥有
195  * src_ip_addr - 源ip地址
196  * grp_member_address - 报告报文发送者的地址
197  * mode - include / exclude src_ip_address.
198  **/
199 // 组内成员站点信息 (STA )
200 typedef struct {
201     osal_u8                        src_ip_addr[OAL_IPV6_ADDR_SIZE];    // 组播源IP地址
202     osal_u32                       timestamp;
203     hmac_user_stru                  *hmac_user;
204     osal_u8                        grp_member_mac[WLAN_MAC_ADDR_LEN]; // 该STA MAC 地址
205     osal_u8                        mode;
206     osal_u8                        src_ip_addr_len;                    // ip 地址长度,用于兼容IPV4、IPV6
207     struct osal_list_head              member_entry;
208 } hmac_m2u_grp_member_stru;
209 
210 
211 /* hmac_m2u_list_update_stru 结构用来传递参数给list update函数来完成特定group的成员更新 */
212 typedef struct {
213     osal_u8                        src_ip_addr[OAL_IPV6_ADDR_SIZE];   /* 源地址 */
214     osal_u8                        grp_mac[WLAN_MAC_ADDR_LEN];        /* 需要加入的组播组mac地址 */
215     osal_u8                        new_member_mac[WLAN_MAC_ADDR_LEN]; /* 需要进行更新的组播成员mac地址 */
216     osal_u32                       timestamp;                          /* 时间戳 */
217     hmac_vap_stru                   *hmac_vap;                          /* vap指针 */
218     hmac_user_stru                  *hmac_user;                         /* user指针 */
219     mac_vlan_tag_stru                outer_vlan_tag;                     /* 外层vlan tag */
220     mac_vlan_tag_stru                inner_vlan_tag;                     /* 内层vlan tag */
221     hmac_m2u_igmp_cmd_enum_uint8     cmd;                                /* 加入、删除命令 */
222     osal_u8                        src_ip_addr_len;
223     osal_u8                        reserve[2];
224 } hmac_m2u_list_update_stru;
225 
226 #ifdef _PRE_WLAN_FEATURE_HERA_MCAST
227 /* 管理配网模式STA链表结构 */
228 typedef struct {
229     struct osal_list_head               adaptive_entry;
230     osal_u8                         adaptive_mac[WLAN_MAC_ADDR_LEN];   /* 配网STA的mac地址 */
231     osal_u8                         adaptive_num;                       /* 记录当前收到配网组播包的个数 */
232     oal_bool_enum_uint8               m2u_adaptive;                       /* 配网模式判据 */
233     osal_u32                        timestamp;
234     mac_vlan_tag_stru                 outer_vlan_tag;                     /* 外层vlan tag */
235     mac_vlan_tag_stru                 inner_vlan_tag;                     /* 内层vlan tag */
236 } hmac_m2u_adaptive_hash_stru;
237 
238 typedef struct {
239     osal_u8                        new_member_mac[WLAN_MAC_ADDR_LEN]; /* 需要进行更新的配网设备mac地址 */
240     osal_u8                        reserve[2];
241     osal_u32                       timestamp;                          /* 时间戳 */
242     hmac_vap_stru                   *hmac_vap;                          /* vap指针 */
243     mac_vlan_tag_stru                outer_vlan_tag;                     /* 外层vlan tag */
244     mac_vlan_tag_stru                inner_vlan_tag;                     /* 内层vlan tag */
245 } hmac_m2u_adaptive_list_update_stru;
246 #endif
247 
248 /* 管理整个snoop链表 */
249 typedef struct {
250     hmac_m2u_snoop_list_stru        m2u_snooplist;
251     oal_bool_enum_uint8             snoop_enable;    /* 控制组播转单播是否使能 */
252     hmac_m2u_mcast_mode_enum_uint8  mcast_mode;      /* 控制组播帧的发送方式 */
253     oal_bool_enum_uint8             discard_mcast;   /* 控制组播帧是否直接丢弃 */
254     wlan_tidno_enum_uint8           tid_num;
255     frw_timeout_stru                snooplist_timer;
256     osal_u32                      timeout;         /* 组播组成员沉默时间 */
257 #ifdef _PRE_WLAN_FEATURE_HERA_MCAST
258     struct osal_list_head             m2u_adaptive_hash[HMAC_M2U_ADAPTIVE_STA_HASHSIZE]; /* 配网配网报文统计HASH表 */
259     oal_bool_enum_uint8             frequency_enable; /* 控制异频组播帧转发开关使能 */
260     oal_bool_enum_uint8             adaptive_enable; /* 控制配网模式识别使能 */
261     frw_timeout_stru                adaptivelist_timer;
262     osal_u32                      threshold_time;   /* 配网模式门限时间 */
263     osal_u32                      adaptive_timeout; /* 配网模式老化时间 */
264     osal_u8                       adaptive_num;     /* 配网模式门限个数 */
265     osal_u8                       adaptive_sta_count; /* 配网STA个数 */
266     osal_u8                       reserve[2];
267 #endif
268 } hmac_m2u_stru;
269 /*****************************************************************************
270   8 UNION定义
271 *****************************************************************************/
272 
273 
274 /*****************************************************************************
275   9 OTHERS定义
276 *****************************************************************************/
277 
278 
279 /*****************************************************************************
280   10 函数声明
281 *****************************************************************************/
282 extern osal_u32 hmac_m2u_snoop_convert(hmac_vap_stru *hmac_vap, oal_netbuf_stru *buf);
283 extern osal_void hmac_m2u_snoop_inspecting(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
284     oal_netbuf_stru *buf);
285 extern osal_void hmac_m2u_attach(hmac_vap_stru *hmac_vap);
286 extern osal_void hmac_m2u_detach(hmac_vap_stru *hmac_vap);
287 extern osal_u32 hmac_m2u_update_snoop_list(hmac_m2u_list_update_stru *list_entry);
288 extern osal_void hmac_m2u_add_snoop_ipv4_deny_entry(hmac_vap_stru *hmac_vap, osal_u32 *pul_grpaddr);
289 extern osal_void hmac_m2u_add_snoop_ipv6_deny_entry(hmac_vap_stru *hmac_vap, osal_u8 *grpaddr);
290 extern osal_void hmac_m2u_del_ipv4_deny_entry(hmac_vap_stru *hmac_vap, const osal_u32 *pul_grpaddr);
291 extern osal_void hmac_m2u_del_ipv6_deny_entry(hmac_vap_stru *hmac_vap, osal_u8 *grpaddr);
292 extern osal_void hmac_m2u_clear_deny_table(hmac_vap_stru *hmac_vap);
293 extern osal_void hmac_m2u_show_snoop_deny_table(hmac_vap_stru *hmac_vap);
294 extern osal_u32 hmac_m2u_print_all_snoop_list(hmac_vap_stru *hmac_vap,
295     oal_snoop_all_group_stru *snoop_all_grp);
296 extern osal_void hmac_m2u_cleanup_snoopwds_node(hmac_user_stru *hmac_user);
297 extern osal_u32 hmac_m2u_igmp_v1v2_update(hmac_vap_stru *hmac_vap, hmac_m2u_list_update_stru *list_entry,
298     mac_igmp_header_stru *igmp);
299 extern osal_void hmac_m2u_unicast_convert_multicast(hmac_vap_stru *hmac_vap, oal_netbuf_stru *pst_netbuf,
300     hmac_msdu_stru *msdu);
301 
302 #ifdef _PRE_WLAN_FEATURE_HERA_MCAST
303 extern osal_u32 hmac_m2u_multicast_drop(hmac_vap_stru *hmac_vap, oal_netbuf_stru *buf);
304 extern osal_void hmac_m2u_adaptive_inspecting(hmac_vap_stru *hmac_vap, oal_netbuf_stru *buf);
305 #endif
306 
307 osal_s32 hmac_config_m2u_snoop_on(hmac_vap_stru *hmac_vap, frw_msg *msg);
308 osal_s32 hmac_config_m2u_deny_table(hmac_vap_stru *hmac_vap, frw_msg *msg);
309 osal_s32 hmac_config_show_m2u_snoop_table(hmac_vap_stru *hmac_vap, frw_msg *msg);
310 osal_s32 hmac_config_igmp_packet_xmit(hmac_vap_stru *hmac_vap, frw_msg *msg);
311 
312 typedef osal_bool (*hmac_m2u_tx_classify_special_cb)(hmac_vap_stru *hmac_vap, mac_tx_ctl_stru *tx_ctl,
313     osal_u8 *tid);
314 typedef osal_void (*hmac_m2u_snoop_inspecting_cb)(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
315     oal_netbuf_stru *buf);
316 typedef osal_void (*hmac_m2u_cleanup_snoopwds_node_cb)(hmac_user_stru *hmac_user);
317 typedef osal_u32 (*hmac_m2u_snoop_convert_cb)(hmac_vap_stru *hmac_vap, oal_netbuf_stru *buf);
318 typedef osal_void (*hmac_m2u_unicast_convert_multicast_cb)(hmac_vap_stru *hmac_vap,
319     oal_netbuf_stru *pst_netbuf, hmac_msdu_stru *msdu);
320 typedef osal_void (*hmac_m2u_attach_cb)(hmac_vap_stru *hmac_vap);
321 typedef osal_void (*hmac_m2u_detach_cb)(hmac_vap_stru *hmac_vap);
322 
323 static osal_u32 hmac_m2u_init_weakref(osal_void) __attribute__ ((weakref("hmac_m2u_init"), used));
324 static osal_void hmac_m2u_deinit_weakref(osal_void) __attribute__ ((weakref("hmac_m2u_deinit"), used));
325 
326 #ifdef __cplusplus
327 #if __cplusplus
328 }
329 #endif
330 #endif
331 
332 #endif /* end of hmac_m2u.h */
333