4 * Copyright (C) 2013, Broadcom Corporation
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: nas.h 409124 2013-06-22 04:35:15Z $
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
27 #include <proto/ethernet.h>
28 #include <proto/802.11.h>
29 #include <proto/eapol.h>
30 #include <proto/wpa.h>
35 #include <wlif_utils.h>
44 #define dbg(nas, fmt, args...) (\
49 fprintf(stderr, "%s: %s: " fmt "\n", __FUNCTION__, \
50 tmp->interface , ## args); \
54 fprintf(stderr, "%s: " fmt "\n", __FUNCTION__ , ## args); \
58 #define dump(nas, mem, size) (\
63 prhex("", mem, size); \
69 #define dbg(nas, fmt, args...)
70 #define dump(nas, mem, size)
72 #define err(nas, fmt, args...) (\
76 printf("%s: %s: " fmt "\n", __FUNCTION__, tmp->interface , ## args); \
79 printf("%s: " fmt "\n", __FUNCTION__ , ## args); \
84 /* Maximum number of supplicants */
85 #define MAX_SUPPLICANTS 128
88 typedef struct binstring
{
104 /* 802.1x Port Access Entity */
106 pae_state_t state
; /* PAE state */
107 int id
; /* EAP current request ID */
109 binstring_t username
; /* RADIUS User Name */
110 binstring_t state
; /* RADIUS State */
111 radius_header_t
*request
; /* Last request */
113 struct pae
*next
; /* Linked list */
115 uint32 ssnto
; /* session timeout */
118 #define PAE_FLAG_EAP_SUCCESS 0x00000001
119 #define PAE_FLAG_RADIUS_ACCESS_REJECT 0x00000002
121 #define MAX_NAS_ID_LEN 32
128 WPA
= WPA_AUTH_UNSPECIFIED
,
129 WPA_PSK
= WPA_AUTH_PSK
,
130 WPA2
= WPA2_AUTH_UNSPECIFIED
,
131 WPA2_PSK
= WPA2_AUTH_PSK
,
135 /* RADIUS Network Access Server (NAS) */
137 char interface
[IFNAMSIZ
+1]; /* LAN interface name */
138 char ssid
[DOT11_MAX_SSID_LEN
+1]; /* SSID */
139 nas_mode_t mode
; /* 0:Radius, 1:WPA, 2:WPA-PSK */
140 uint32 wsec
; /* crypto algorithm config, same as wl driver */
141 struct ether_addr ea
; /* LAN Ethernet address */
142 wpa_t
*wpa
; /* WPA struct (NULL if wpa not in use) */
143 int wan
; /* RADIUS interface handle */
144 struct sockaddr_in client
; /* RADIUS interface IP address */
145 struct sockaddr_in server
; /* RADIUS server IP address */
146 binstring_t key
; /* PSK shared secret */
147 unsigned int type
; /* RADIUS NAS Port Type */
148 nas_sta_t sta
[MAX_SUPPLICANTS
]; /* STAs */
149 nas_sta_t
*sta_hashed
[MAX_SUPPLICANTS
]; /* STA cache */
150 bcm_timer_module_id timer
; /* timer module ID */
151 /* MIC error stuff needs to be per-interface */
152 uint32 MIC_failures
; /* how many detected */
153 bool MIC_countermeasures
; /* flags lock-out period */
154 time_t prev_MIC_error
; /* seconds since last one */
155 /* various flags see below */
157 /* wds remote address */
158 uint8 remote
[ETHER_ADDR_LEN
];
159 /* application data */
166 /* session timeout - global */
168 bcm_timer_id watchdog_td
;
169 /* RADIUS shared secret */
171 uint32 disable_preauth
; /* Internal Flags to disable the WPA2 preauth */
172 uint32 auth_blockout_time
; /* seconds to block out client after auth. fail */
173 char nas_id
[MAX_NAS_ID_LEN
+1]; /* nas mac address */
176 #define NAS_FLAG_SUPPLICANT WLIFU_WSEC_SUPPL /* nas is supplicant, exclusive */
177 #define NAS_FLAG_AUTHENTICATOR WLIFU_WSEC_AUTH /* nas is authenticator, exclusive */
178 #define NAS_FLAG_WDS WLIFU_WSEC_WDS /* nas in WDS mode */
179 #define NAS_FLAG_GTK_PLUMBED 0x40000000 /* GTK has been plumbed */
180 #define NAS_FLAG_IGTK_PLUMBED 0x80000000 /* IGTK has been plumbed */
183 /* Supplicant cache */
184 #define pae_hash(ea) \
185 ((((unsigned char *) ea)[3] ^ ((unsigned char *) ea)[4] ^ ((unsigned char *) ea)[5]) & \
186 (MAX_SUPPLICANTS - 1))
189 /* Always clear the descriptor when deleting a timer! */
190 #define TIMER_DELETE(td) {(void) bcm_timer_delete(td); td = 0;}
192 /* Driver specific */
193 extern int nas_send_wnm_on_radius_access_accept(nas_t
*nas
, char* url
, struct ether_addr
*ea
);
194 extern int nas_authorize(nas_t
*nas
, struct ether_addr
*ea
);
195 extern int nas_deauthorize(nas_t
*nas
, struct ether_addr
*ea
);
196 extern int nas_deauthenticate(nas_t
*nas
, struct ether_addr
*ea
, int reason
);
197 extern int nas_disassoc(nas_t
*nas
);
198 extern int nas_set_key(nas_t
*nas
, struct ether_addr
*ea
, unsigned char *key
, int len
, int index
,
199 int tx_flag
, uint32 hi
, uint16 lo
);
200 extern int nas_set_mode(nas_t
*nas
, int mode
);
201 extern int nas_get_group_rsc(nas_t
*nas
, uint8
*buf
, int index
);
202 extern void nas_wl_init(nas_t
*nas
);
203 extern int nas_wl_tkip_countermeasures(nas_t
*nas
, int enable
);
204 extern void nas_wl_cleanup(nas_t
*nas
);
205 extern int nas_set_ssid(nas_t
*nas
, char *ssid
);
206 extern int nas_join_bss(nas_t
*nas
, char *ssid
);
207 extern int nas_get_wpawsec(nas_t
*nas
, uint32
*wsec
);
208 extern int nas_get_wpaauth(nas_t
*nas
, uint32
*wpa_auth
);
209 extern int nas_get_wpacap(nas_t
*nas
, uint8
*cap
);
210 extern int nas_get_wpa_ie(nas_t
*nas
, char *ret_buf
, int ret_buf_len
, uint32 sta_mode
);
212 extern int nas_set_eventmsgs(nas_t
*nas
, uchar
*msgs
, int size
);
213 extern int nas_get_eventmsgs(nas_t
*nas
, uchar
*msgs
, int size
);
215 extern void nas_rand128(uint8
*rand128
);
216 extern int nas_eapol_send_packet(nas_t
*nas
, struct iovec
*frags
, int nfrags
);
218 /* Main dispatch functions */
219 extern void eapol_dispatch(nas_t
*nas
, eapol_header_t
*eapol
, int bytes
);
221 extern void eapol_sup_dispatch(nas_t
*nas
, eapol_header_t
*eapol
);
224 extern int nas_preauth_send_packet(nas_t
*nas
, struct iovec
*frags
, int nfrags
);
225 extern void preauth_dispatch(nas_t
*nas
, eapol_header_t
*eapol
, int bytes
);
227 extern void driver_message_dispatch(nas_t
*nas
, bcm_event_t
*dpkt
);
228 extern void driver_message_sup_dispatch(nas_t
*nas
, bcm_event_t
*dpkt
);
229 extern void cleanup_sta(nas_t
*nas
, nas_sta_t
*sta
, int reason
, int driver_signal
);
231 typedef enum { SEARCH_ONLY
, SEARCH_ENTER
} sta_lookup_mode_t
;
233 extern nas_sta_t
*lookup_sta(nas_t
*nas
, struct ether_addr
*sta
,
234 sta_lookup_mode_t mode
);
236 extern void nas_start(nas_t
*nas
);
237 extern void nas_sleep_ms(uint ms
);
239 extern void send_identity_req(nas_t
*nas
, nas_sta_t
*sta
);
241 extern void nas_reset_board(void);
242 extern int nas_handle_error(nas_t
*nas
, int error
);
243 extern void nas_force_rekey(nas_t
*nas
);
245 extern void pae_state(nas_t
*nas
, nas_sta_t
*sta
, int state
);
246 extern void eapol_key(nas_t
*nas
, nas_sta_t
*sta
,
247 unsigned char *send_key
, int send_key_len
,
248 unsigned char *recv_key
, int recv_key_len
,
249 unsigned char *key
, int key_len
, int index
, int unicast
);
250 extern void fix_wpa(nas_t
*nas
, nas_sta_t
*sta
, char *key
, int len
);
252 /* bcmcrypto/hmac.c */
253 extern void hmac_md5(unsigned char* text
, int text_len
, unsigned char *key
,
254 int key_len
, unsigned char*digest
);
255 extern void hmac_sha1(unsigned char *text
, int text_len
, unsigned char *key
,
256 int key_len
, unsigned char *digest
);
257 extern int nas_send_brcm_event(nas_t
*nas
, uint8
* mac
, int reason
);
259 #define MIC_RATE_LIMIT 60 /* seconds */
261 #define STA_DEAUTH_DELAY_MS 50 /* delay before call wl ioctl deauth */
262 #define STA_REAUTH_MAX 2 /* reAuthMax */
263 #define STA_TXPERIOD_MAX 30 /* max txPeriod in second */
264 #define STA_AUTHWHILE_MAX 60 /* max authWhile in second */
265 #define STA_QUIETWHILE_MAX 60 /* max quietWhile in second */
267 #define CHECK_NAS(mode) ((mode) & (WPA | WPA_PSK | WPA2 | WPA2_PSK))
268 #define CHECK_PSK(mode) ((mode) & (WPA_PSK | WPA2_PSK))
269 #define CHECK_WPA(mode) ((mode) & (WPA | WPA2))
270 #define CHECK_RADIUS(mode) ((mode) & (WPA | RADIUS | WPA2))
271 #define CHECK_AUTH(mode) ((mode) & (RADIUS | WPA | WPA_PSK | WPA2 | WPA2_PSK))