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