1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2016 - 2017 Realtek Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 *****************************************************************************/
16 #ifndef __INC_WAPI_H
17 #define __INC_WAPI_H
18
19
20 #define CONFIG_WAPI_SW_SMS4
21 #define WAPI_DEBUG
22
23 #define SMS4_MIC_LEN 16
24 #define WAPI_EXT_LEN 18
25 #define MAX_WAPI_IE_LEN 256
26 #define sMacHdrLng 24 /* octets in data header, no WEP */
27
28 #ifdef WAPI_DEBUG
29
30 /* WAPI trace debug */
31 extern u32 wapi_debug_component;
32
dump_buf(u8 * buf,u32 len)33 static inline void dump_buf(u8 *buf, u32 len)
34 {
35 u32 i;
36 printk("-----------------Len %d----------------\n", len);
37 for (i = 0; i < len; i++)
38 printk("%2.2x-", *(buf + i));
39 printk("\n");
40 }
41
42 #define WAPI_TRACE(component, x, args...) \
43 do { if (wapi_debug_component & (component)) \
44 printk(KERN_DEBUG "WAPI" ":" x "" , \
45 ##args);\
46 } while (0);
47
48 #define WAPI_DATA(component, x, buf, len) \
49 do { if (wapi_debug_component & (component)) { \
50 printk("%s:\n", x);\
51 dump_buf((buf), (len)); } \
52 } while (0);
53
54 #define RT_ASSERT_RET(_Exp) \
55 if (!(_Exp)) { \
56 printk("RTWLAN: "); \
57 printk("Assertion failed! %s,%s, line=%d\n", \
58 #_Exp, __FUNCTION__, __LINE__); \
59 return; \
60 }
61 #define RT_ASSERT_RET_VALUE(_Exp, Ret) \
62 if (!(_Exp)) { \
63 printk("RTWLAN: "); \
64 printk("Assertion failed! %s,%s, line=%d\n", \
65 #_Exp, __FUNCTION__, __LINE__); \
66 return Ret; \
67 }
68
69 #else
70 #define RT_ASSERT_RET(_Exp) do {} while (0)
71 #define RT_ASSERT_RET_VALUE(_Exp, Ret) do {} while (0)
72 #define WAPI_TRACE(component, x, args...) do {} while (0)
73 #define WAPI_DATA(component, x, buf, len) do {} while (0)
74 #endif
75
76
77 enum WAPI_DEBUG {
78 WAPI_INIT = 1,
79 WAPI_API = 1 << 1,
80 WAPI_TX = 1 << 2,
81 WAPI_RX = 1 << 3,
82 WAPI_MLME = 1 << 4,
83 WAPI_IOCTL = 1 << 5,
84 WAPI_ERR = 1 << 31
85 };
86
87 #define WAPI_MAX_BKID_NUM 4
88 #define WAPI_MAX_STAINFO_NUM 4
89 #define WAPI_CAM_ENTRY_NUM 14 /* 28/2 = 14 */
90
91 typedef struct _RT_WAPI_BKID {
92 struct list_head list;
93 u8 bkid[16];
94 } RT_WAPI_BKID, *PRT_WAPI_BKID;
95
96 typedef struct _RT_WAPI_KEY {
97 u8 dataKey[16];
98 u8 micKey[16];
99 u8 keyId;
100 bool bSet;
101 bool bTxEnable;
102 } RT_WAPI_KEY, *PRT_WAPI_KEY;
103
104 typedef enum _RT_WAPI_PACKET_TYPE {
105 WAPI_NONE = 0,
106 WAPI_PREAUTHENTICATE = 1,
107 WAPI_STAKEY_REQUEST = 2,
108 WAPI_AUTHENTICATE_ACTIVE = 3,
109 WAPI_ACCESS_AUTHENTICATE_REQUEST = 4,
110 WAPI_ACCESS_AUTHENTICATE_RESPONSE = 5,
111 WAPI_CERTIFICATE_AUTHENTICATE_REQUEST = 6,
112 WAPI_CERTIFICATE_AUTHENTICATE_RESPONSE = 7,
113 WAPI_USK_REQUEST = 8,
114 WAPI_USK_RESPONSE = 9,
115 WAPI_USK_CONFIRM = 10,
116 WAPI_MSK_NOTIFICATION = 11,
117 WAPI_MSK_RESPONSE = 12
118 } RT_WAPI_PACKET_TYPE;
119
120 typedef struct _RT_WAPI_STA_INFO {
121 struct list_head list;
122 u8 PeerMacAddr[6];
123 RT_WAPI_KEY wapiUsk;
124 RT_WAPI_KEY wapiUskUpdate;
125 RT_WAPI_KEY wapiMsk;
126 RT_WAPI_KEY wapiMskUpdate;
127 u8 lastRxUnicastPN[16];
128 u8 lastTxUnicastPN[16];
129 u8 lastRxMulticastPN[16];
130 u8 lastRxUnicastPNBEQueue[16];
131 u8 lastRxUnicastPNBKQueue[16];
132 u8 lastRxUnicastPNVIQueue[16];
133 u8 lastRxUnicastPNVOQueue[16];
134 bool bSetkeyOk;
135 bool bAuthenticateInProgress;
136 bool bAuthenticatorInUpdata;
137 } RT_WAPI_STA_INFO, *PRT_WAPI_STA_INFO;
138
139 /* Added for HW wapi en/decryption */
140 typedef struct _RT_WAPI_CAM_ENTRY {
141 /* RT_LIST_ENTRY list; */
142 u8 IsUsed;
143 u8 entry_idx;/* for cam entry */
144 u8 keyidx; /* 0 or 1,new or old key */
145 u8 PeerMacAddr[6];
146 u8 type; /* should be 110,wapi */
147 } RT_WAPI_CAM_ENTRY, *PRT_WAPI_CAM_ENTRY;
148
149 typedef struct _RT_WAPI_T {
150 /* BKID */
151 RT_WAPI_BKID wapiBKID[WAPI_MAX_BKID_NUM];
152 struct list_head wapiBKIDIdleList;
153 struct list_head wapiBKIDStoreList;
154 /* Key for Tx Multicast/Broadcast */
155 RT_WAPI_KEY wapiTxMsk;
156
157 /* sec related */
158 u8 lastTxMulticastPN[16];
159 /* STA list */
160 RT_WAPI_STA_INFO wapiSta[WAPI_MAX_STAINFO_NUM];
161 struct list_head wapiSTAIdleList;
162 struct list_head wapiSTAUsedList;
163 /* */
164 bool bWapiEnable;
165
166 /* store WAPI IE */
167 u8 wapiIE[256];
168 u8 wapiIELength;
169 bool bWapiPSK;
170 /* last sequece number for wai packet */
171 u16 wapiSeqnumAndFragNum;
172 int extra_prefix_len;
173 int extra_postfix_len;
174
175 RT_WAPI_CAM_ENTRY wapiCamEntry[WAPI_CAM_ENTRY_NUM];
176 } RT_WAPI_T, *PRT_WAPI_T;
177
178 typedef struct _WLAN_HEADER_WAPI_EXTENSION {
179 u8 KeyIdx;
180 u8 Reserved;
181 u8 PN[16];
182 } WLAN_HEADER_WAPI_EXTENSION, *PWLAN_HEADER_WAPI_EXTENSION;
183
184 u32 WapiComparePN(u8 *PN1, u8 *PN2);
185
186
187 void rtw_wapi_init(_adapter *padapter);
188
189 void rtw_wapi_free(_adapter *padapter);
190
191 void rtw_wapi_disable_tx(_adapter *padapter);
192
193 u8 rtw_wapi_is_wai_packet(_adapter *padapter, u8 *pkt_data);
194
195 void rtw_wapi_update_info(_adapter *padapter, union recv_frame *precv_frame);
196
197 u8 rtw_wapi_check_for_drop(_adapter *padapter, union recv_frame *precv_frame, u8 *ehdr_ops);
198
199 void rtw_build_probe_resp_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib);
200
201 void rtw_build_beacon_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib);
202
203 void rtw_build_assoc_req_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib);
204
205 void rtw_wapi_on_assoc_ok(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
206
207 void rtw_wapi_return_one_sta_info(_adapter *padapter, u8 *MacAddr);
208
209 void rtw_wapi_return_all_sta_info(_adapter *padapter);
210
211 void rtw_wapi_clear_cam_entry(_adapter *padapter, u8 *pMacAddr);
212
213 void rtw_wapi_clear_all_cam_entry(_adapter *padapter);
214
215 void rtw_wapi_set_key(_adapter *padapter, RT_WAPI_KEY *pWapiKey, RT_WAPI_STA_INFO *pWapiSta, u8 bGroupKey, u8 bUseDefaultKey);
216
217 int rtw_wapi_create_event_send(_adapter *padapter, u8 EventId, u8 *MacAddr, u8 *Buff, u16 BufLen);
218
219 u32 rtw_sms4_encrypt(_adapter *padapter, u8 *pxmitframe);
220
221 u32 rtw_sms4_decrypt(_adapter *padapter, u8 *precvframe);
222
223 void rtw_wapi_get_iv(_adapter *padapter, u8 *pRA, u8 *IV);
224
225 u8 WapiIncreasePN(u8 *PN, u8 AddCount);
226
227 bool rtw_wapi_drop_for_key_absent(_adapter *padapter, u8 *pRA);
228
229 void rtw_wapi_set_set_encryption(_adapter *padapter, struct ieee_param *param);
230
231 #endif
232