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_wapi.c的头文件. 15 */ 16 17 #ifndef __HMAC_WAPI_H__ 18 #define __HMAC_WAPI_H__ 19 20 /***************************************************************************** 21 1 头文件包含 22 *****************************************************************************/ 23 #include "oal_netbuf_ext.h" 24 #include "mac_resource_ext.h" 25 #include "hmac_vap.h" 26 #include "hmac_user.h" 27 28 #ifdef __cplusplus 29 #if __cplusplus 30 extern "C" { 31 #endif 32 #endif 33 34 #undef THIS_FILE_ID 35 #define THIS_FILE_ID OAM_FILE_ID_HMAC_WAPI_H 36 /*****************************************************************************/ 37 /***************************************************************************** 38 2 宏定义 39 *****************************************************************************/ 40 #define WAPI_UCAST_INC 2 /* 发送或者接收单播帧,pn的步进值 */ 41 #define WAPI_BCAST_INC 1 /* 发送或者接收组播帧,pn的步进值 */ 42 #define WAPI_WAI_TYPE (osal_u16)0x88B4 /* wapi的以太类型 */ 43 44 #define WAPI_BCAST_KEY_TYPE 1 45 #define WAPI_UCAST_KEY_TYPE 0 46 47 #define SMS4_MIC_LEN (osal_u8)16 /* SMS4封包MIC的长度 */ 48 49 #define SMS4_PN_LEN 16 /* wapi pn的长度 */ 50 #define SMS4_KEY_IDX 1 /* WAPI头中 keyidx占1个字节 */ 51 #define SMS4_WAPI_HDR_RESERVE 1 /* WAPI头中保留字段 */ 52 #define HMAC_WAPI_HDR_LEN (osal_u8)(SMS4_PN_LEN + SMS4_KEY_IDX + SMS4_WAPI_HDR_RESERVE) 53 #define WAPI_PDU_LEN 2 /* wapi头中,wapi pdu len字段所占字节数 */ 54 #define SMS4_PADDING_LEN 16 /* mic data按照16字节对齐 */ 55 56 #define SMS4_MIC_PART1_QOS_LEN 48 /* 按照协议,如果有qos字段,mic第一部分16字节对齐后的长度 */ 57 #define SMS4_MIC_PART1_NO_QOS_LEN 32 /* 按照协议,如果没有qos字段,mic第一部分16字节对齐后的长度 */ 58 59 #define WAPI_IE_VERSION 1 /* wapi的version */ 60 #define WAPI_IE_VER_SIZE 2 /* wapi ver-ie 所占字节数 */ 61 #define WAPI_IE_SUIT_TYPE_SIZE 1 /* suit type size */ 62 #define WAPI_IE_WAPICAP_SIZE 2 /* wapi cap字段所占字节数 */ 63 #define WAPI_IE_BKIDCNT_SIZE 2 /* wapi bkid数字段所占字节数 */ 64 #define WAPI_IE_BKID_SIZE 16 /* 一个bkid所占字节数 */ 65 #define WAPI_IE_OUI_SIZE 3 /* wapi oui字节数 */ 66 #define WAPI_IE_SMS4 1 /* wapi加密类型为sms4 */ 67 #define WAPI_IE_SUITCNT_SIZE 2 /* wapi suit count所占字节数 */ 68 /* wapi key len */ 69 #define WAPI_KEY_LEN 16 70 #define WAPI_PN_LEN 16 71 #define HMAC_WAPI_MAX_KEYID 2 72 73 /***************************************************************************** 74 3 枚举定义 75 *****************************************************************************/ 76 77 78 /***************************************************************************** 79 4 全局变量声明 80 *****************************************************************************/ 81 82 83 /***************************************************************************** 84 5 消息头定义 85 *****************************************************************************/ 86 87 88 /***************************************************************************** 89 6 消息定义 90 *****************************************************************************/ 91 92 93 /***************************************************************************** 94 7 STRUCT定义 95 *****************************************************************************/ 96 typedef struct { 97 osal_u8 framectl[2]; /* 帧控制 */ 98 osal_u8 adress1[OAL_MAC_ADDR_LEN]; /* 地址1 */ 99 osal_u8 adress2[OAL_MAC_ADDR_LEN]; /* 地址2 */ 100 osal_u8 seqctl[2]; /* 序列控制 */ 101 osal_u8 adress3[OAL_MAC_ADDR_LEN]; /* 地址3 */ 102 osal_u8 adress4[OAL_MAC_ADDR_LEN]; /* 地址4 */ 103 } wapi_mic_hdr_stru; 104 105 typedef struct { 106 osal_u8 wpi_ek[WAPI_KEY_LEN]; 107 osal_u8 wpi_ck[WAPI_KEY_LEN]; 108 osal_u8 pn_rx[WAPI_PN_LEN]; 109 osal_u8 pn_tx[WAPI_PN_LEN]; 110 osal_u8 key_en; 111 osal_u8 rsv[3]; 112 } hmac_wapi_key_stru; 113 114 typedef struct tag_hmac_wapi_stru { 115 osal_u8 port_valid; /* wapi控制端口 */ 116 osal_u8 keyidx; 117 osal_u8 keyupdate_flg; /* key更新标志 */ 118 osal_u8 pn_inc; /* pn步进值 */ 119 120 hmac_wapi_key_stru wapi_key[HMAC_WAPI_MAX_KEYID]; /* keyed: 0~1 */ 121 122 osal_u8(*wapi_filter_frame)(struct tag_hmac_wapi_stru *wapi, oal_netbuf_stru *netbuff); 123 oal_bool_enum_uint8(*wapi_is_pn_odd)(const osal_u8 *pn); /* 判断pn是否为奇数 */ 124 osal_u32(*wapi_decrypt)(struct tag_hmac_wapi_stru *wapi, oal_netbuf_stru *netbuff); 125 osal_u32(*wapi_encrypt)(struct tag_hmac_wapi_stru *wapi, oal_netbuf_stru *pst_netbuf); 126 oal_netbuf_stru *(*wapi_netbuff_txhandle)(struct tag_hmac_wapi_stru *wapi, oal_netbuf_stru *pst_netbuf); 127 oal_netbuf_stru *(*wapi_netbuff_rxhandle)(struct tag_hmac_wapi_stru *wapi, oal_netbuf_stru *pst_netbuf); 128 } hmac_wapi_stru; 129 130 /***************************************************************************** 131 8 UNION定义 132 *****************************************************************************/ 133 134 /***************************************************************************** 135 9 OTHERS定义 136 *****************************************************************************/ 137 138 /***************************************************************************** 139 10 函数声明 140 *****************************************************************************/ 141 typedef osal_void (*hmac_wapi_deinit_etc_cb)(osal_u16 user_idx); 142 typedef osal_u32 (*hmac_wapi_init_etc_cb)(osal_u16 user_idx, osal_u8 pairwise); 143 typedef oal_netbuf_stru* (*hmac_rx_frame_wapi_cb)(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf, 144 mac_ieee80211_frame_stru *frame_hdr, hmac_user_stru *hmac_user, mac_rx_ctl_stru **rx_ctrl); 145 typedef osal_u32 (*hmac_wapi_tx_classify_special_cb)(hmac_vap_stru *hmac_vap, osal_u16 type, 146 mac_tx_ctl_stru *tx_ctl, osal_u8 *tid); 147 typedef osal_u32 (*hmac_tx_lan_to_wlan_wapi_cb)(hmac_vap_stru *hmac_vap, oal_netbuf_stru **netbuf); 148 typedef osal_u32 (*hmac_11i_reset_wapi_cb)(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user); 149 typedef osal_u32 (*hmac_wapi_add_key_and_sync_etc_cb)(hmac_vap_stru *hmac_vap, osal_u32 type, 150 mac_addkey_param_stru *payload_addkey_param); 151 typedef osal_void (*hmac_wapi_update_legcy_only_cb)(mac_bss_dscr_stru *bss_dscr, oal_bool_enum_uint8 *legcy_only); 152 typedef osal_bool (*hmac_wapi_ether_type_check_cb)(osal_u16 ether_type); 153 typedef osal_u32 (*hmac_wapi_connect_check_bss_dscr_cb)(mac_bss_dscr_stru *bss_dscr, 154 hmac_vap_stru *hmac_vap, mac_conn_param_stru *connect_param); 155 typedef osal_bool (*hmac_wapi_disable_cb)(osal_u8 wapi); 156 typedef osal_s32 (*hmac_wapi_update_roam_cb)(hmac_vap_stru *hmac_vap, osal_u8 *roming_now); 157 typedef osal_u32 (*hmac_wapi_user_add_check_cb)(osal_u8 device_id); 158 typedef osal_bool (*hmac_wapi_get_ether_type_cb)(osal_u16 ether_type); 159 typedef osal_u8 (*hmac_wapi_connected_etc_cb)(osal_u8 device_id); 160 typedef osal_u8 (*hmac_wapi_update_connect_param_cb)(osal_u32 wpa_versions); 161 162 static osal_u32 hmac_wapi_init_weakref(osal_void) __attribute__ ((weakref("hmac_wapi_init"), used)); 163 static osal_void hmac_wapi_deinit_weakref(osal_void) __attribute__ ((weakref("hmac_wapi_deinit"), used)); 164 165 #ifdef __cplusplus 166 #if __cplusplus 167 } 168 #endif 169 #endif 170 171 #endif /* end of hmac_wapi.h */