2 * NAS WorkSpace - NAS application common code
4 * Copyright (C) 2010, 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 241388 2011-02-18 03:33:22Z stakita $
15 #ifndef __NAS_WKSP_H__
16 #define __NAS_WKSP_H__
22 extern int debug_nwksp
;
23 #define NASDBG(fmt, arg...) (\
26 printf("%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 16
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 */
80 /* nas/wpa combo and lots of goodies, one per NAS instance */
81 typedef struct nas_wpa_cb
86 /* user-supplied psk passphrase */
87 uint8 psk
[NAS_WKSP_MAX_USER_KEY_LEN
+ 1];
88 /* user-supplied radius secret */
89 uint8 secret
[NAS_WKSP_MAX_USER_KEY_LEN
+ 1];
90 /* user-supplied wep key */
91 uint8 wep
[NAS_WKSP_MAX_USER_KEY_LEN
+ 1];
99 struct nas_wksp
*nwksp
;
103 typedef struct nas_wksp
105 /* packet buffer for reading socket */
106 uint8 packet
[RADIUS_MAX_LEN
];
107 /* file dscc set for select() */
110 /* receive/send eapol/bcmevent/preauth type packets to eapd */
112 /* timer module id */
113 bcm_timer_module_id timer
;
116 /* # of i/f (in/out) */
118 /* nas_wpa_cb_t list */
119 nas_wpa_cb_t
*nwcb
[NAS_WKSP_MAX_NUM_INTERFACES
];
123 NAS_WKSP_NWCB_SEARCH_ONLY
= 0,
124 NAS_WKSP_NWCB_SEARCH_ENTER
125 } nwcb_lookup_mode_t
;
127 #ifdef NAS_WKSP_ON_DEMAND
128 #define NAS_WKSP_NWCB_AUTO NAS_WKSP_NWCB_SEARCH_ENTER
129 #define NAS_WKSP_ADD_NWCB(nwksp, mac, osifname) nas_wksp_add_nwcb(nwksp, mac, osifname)
131 #define NAS_WKSP_NWCB_AUTO NAS_WKSP_NWCB_SEARCH_ONLY
132 #define NAS_WKSP_ADD_NWCB(nwksp, mac, osifname) (NULL)
133 #endif /* #ifdef NAS_WKSP_ON_DEMAND */
141 void nas_wksp_display_usage(void);
142 int nas_wksp_parse_cmd(int argc
, char *argv
[], nas_wksp_t
*nwksp
);
143 nas_wksp_t
*nas_wksp_alloc_workspace(void);
144 void nas_wksp_free_workspace(nas_wksp_t
*nwksp
);
145 nas_wpa_cb_t
*nas_wksp_find_nwcb(nas_wksp_t
*nwksp
, uint8
*mac
, char *osifname
, int mode
);
146 int nas_wksp_init(nas_wksp_t
*nwksp
);
147 void nas_wksp_cleanup(nas_wksp_t
*nwksp
);
148 int nas_wksp_main_loop(nas_wksp_t
*nwksp
);
149 void nas_wksp_dispatch_packet(nas_wksp_t
*rootnwksp
);
150 void nas_wksp_clear_inited(void);
151 int nas_wksp_is_inited(void);
154 /* Socket specific */
155 int nas_wksp_open_eapd(nas_wksp_t
*rootnwksp
);
156 void nas_wksp_close_eapd(nas_wksp_t
*rootnwksp
);
158 int nas_validate_wlpvt_message(int bytes
, uint8
*pkt
);
159 int nas_handle_wlpvt_messages(nas_wpa_cb_t
*nwcb
, void *dpkt
, int bytes
);
160 void nas_eapol_message_dispatch(nas_wpa_cb_t
*nwcb
, void *eapol
, int bytes
);
163 int nas_safe_get_conf(char *outval
, int outval_size
, char *name
);
170 #endif /* ifndef __NAS_WKSP_H__ */