2 * NAS WorkSpace - NAS application common code
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_wksp.h 375254 2012-12-18 05:07:38Z $
15 #ifndef __NAS_WKSP_H__
16 #define __NAS_WKSP_H__
22 extern int debug_nwksp
;
23 #define NASDBG(fmt, arg...) (\
26 fprintf(stderr, "%s: "fmt, __FUNCTION__ , ##arg); \
30 #define NASHEX(mem, size) (\
35 for (i = 0; i < size; ) { \
36 j = sprintf(buf, "%04X: ", i); \
37 for (k = 0; k < 16 && i < size; k++, i++) \
38 j += sprintf(&buf[j], " %02X", mem[i]); \
39 printf("%s\n", buf); \
44 #else /* #if BCMDBG */
45 #define NASDBG(fmt, arg...)
46 #define NASHEX(mem, size)
47 #endif /* #if BCMDBG */
48 #define NASMSG(fmt, arg...) printf(fmt , ##arg)
50 #include <sys/types.h>
57 * The same source code can be built into either NAS server or
60 #if !defined(NAS_WKSP_BUILD_NAS_AUTH) && !defined(NAS_WKSP_BUILD_NAS_SUPPL)
61 #error must defined NAS_WKSP_BUILD_NAS_AUTH and/or NAS_WKSP_BUILD_NAS_SUPPL
64 #define NAS_WKSP_PSK_LEN 64
65 #define NAS_WKSP_PASSPHRASE_MIN 8
66 #define NAS_WKSP_PASSPHRASE_MAX 63
68 #define NAS_WKSP_MAX_USER_KEY_LEN 80
69 #define NAS_WKSP_MAX_NUM_INTERFACES 66
71 #define NAS_WKSP_UNK_FILE_DESC -1
73 #define NAS_WPA_CB_FLAG_SUPPL WLIFU_WSEC_SUPPL /* use nas as supplicant */
74 #define NAS_WPA_CB_FLAG_AUTH WLIFU_WSEC_AUTH /* use nas as authenticator */
75 #define NAS_WPA_CB_FLAG_WDS WLIFU_WSEC_WDS /* nas in WDS mode */
76 #define NAS_WPA_CB_FLAG_ERROR 0x80000000 /* error to init nas_t struct */
78 #define NAS_WKSP_FLAG_SHUTDOWN 1 /* Shutdown flag */
79 #define NAS_WKSP_FLAG_REKEY 2 /* Rekey flag */
81 /* nas/wpa combo and lots of goodies, one per NAS instance */
82 typedef struct nas_wpa_cb
87 /* user-supplied psk passphrase */
88 uint8 psk
[NAS_WKSP_MAX_USER_KEY_LEN
+ 1];
89 /* user-supplied radius secret */
90 uint8 secret
[NAS_WKSP_MAX_USER_KEY_LEN
+ 1];
91 /* user-supplied wep key */
92 uint8 wep
[NAS_WKSP_MAX_USER_KEY_LEN
+ 1];
100 struct nas_wksp
*nwksp
;
104 typedef struct nas_wksp
106 /* packet buffer for reading socket */
107 uint8 packet
[RADIUS_MAX_LEN
];
108 /* file dscc set for select() */
111 /* receive/send eapol/bcmevent/preauth type packets to eapd */
113 /* timer module id */
114 bcm_timer_module_id timer
;
117 /* # of i/f (in/out) */
119 /* nas_wpa_cb_t list */
120 nas_wpa_cb_t
*nwcb
[NAS_WKSP_MAX_NUM_INTERFACES
];
124 NAS_WKSP_NWCB_SEARCH_ONLY
= 0,
125 NAS_WKSP_NWCB_SEARCH_ENTER
126 } nwcb_lookup_mode_t
;
128 #ifdef NAS_WKSP_ON_DEMAND
129 #define NAS_WKSP_NWCB_AUTO NAS_WKSP_NWCB_SEARCH_ENTER
130 #define NAS_WKSP_ADD_NWCB(nwksp, mac, osifname) nas_wksp_add_nwcb(nwksp, mac, osifname)
132 #define NAS_WKSP_NWCB_AUTO NAS_WKSP_NWCB_SEARCH_ONLY
133 #define NAS_WKSP_ADD_NWCB(nwksp, mac, osifname) (NULL)
134 #endif /* #ifdef NAS_WKSP_ON_DEMAND */
142 void nas_wksp_display_usage(void);
143 int nas_wksp_parse_cmd(int argc
, char *argv
[], nas_wksp_t
*nwksp
);
144 nas_wksp_t
*nas_wksp_alloc_workspace(void);
145 void nas_wksp_free_workspace(nas_wksp_t
*nwksp
);
146 nas_wpa_cb_t
*nas_wksp_find_nwcb(nas_wksp_t
*nwksp
, uint8
*mac
, char *osifname
, int mode
);
147 int nas_wksp_init(nas_wksp_t
*nwksp
);
148 void nas_wksp_cleanup(nas_wksp_t
*nwksp
);
149 int nas_wksp_main_loop(nas_wksp_t
*nwksp
);
150 void nas_wksp_dispatch_packet(nas_wksp_t
*rootnwksp
);
151 void nas_wksp_clear_inited(void);
152 int nas_wksp_is_inited(void);
155 /* Socket specific */
156 int nas_wksp_open_eapd(nas_wksp_t
*rootnwksp
);
157 void nas_wksp_close_eapd(nas_wksp_t
*rootnwksp
);
159 int nas_validate_wlpvt_message(int bytes
, uint8
*pkt
);
160 int nas_handle_wlpvt_messages(nas_wpa_cb_t
*nwcb
, void *dpkt
, int bytes
);
161 void nas_eapol_message_dispatch(nas_wpa_cb_t
*nwcb
, void *eapol
, int bytes
);
164 int nas_safe_get_conf(char *outval
, int outval_size
, char *name
);
171 #endif /* ifndef __NAS_WKSP_H__ */