libevent: updated to 2.0.22
[tomato.git] / release / src-rt-6.x.4708 / router / nas_arm / nas_wksp.h
blob13b5484cc1eff1dc5ac8c33b0f41e2c52621fed3
1 /*
2 * NAS WorkSpace - NAS application common code
4 * Copyright (C) 2013, Broadcom Corporation
5 * All Rights Reserved.
6 *
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__
18 /* debug stuff */
19 #ifdef BCMDBG
20 #include <stdio.h>
21 #include <string.h>
22 extern int debug_nwksp;
23 #define NASDBG(fmt, arg...) (\
24 { \
25 if (debug_nwksp) { \
26 fprintf(stderr, "%s: "fmt, __FUNCTION__ , ##arg); \
27 } \
28 } \
30 #define NASHEX(mem, size) (\
31 { \
32 if (debug_nwksp) { \
33 char buf[80]; \
34 int i, j, k; \
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); \
40 } \
41 } \
42 } \
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>
51 #include <net/if.h>
52 #include "bcmtimer.h"
53 #include "nas.h"
54 #include "wpa.h"
57 * The same source code can be built into either NAS server or
58 * NAS supplicant.
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
62 #endif
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
84 nas_t nas;
85 wpa_t wpa;
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];
93 /* wep key index */
94 int index;
95 /* run time flags */
96 uint32 flags;
97 /* wl unit # */
98 int unit;
99 /* back pointer */
100 struct nas_wksp *nwksp;
101 } nas_wpa_cb_t;
103 /* nas work space */
104 typedef struct nas_wksp
106 /* packet buffer for reading socket */
107 uint8 packet[RADIUS_MAX_LEN];
108 /* file dscc set for select() */
109 fd_set fdset;
110 int fdmax;
111 /* receive/send eapol/bcmevent/preauth type packets to eapd */
112 int eapd;
113 /* timer module id */
114 bcm_timer_module_id timer;
115 /* run time flags */
116 uint32 flags;
117 /* # of i/f (in/out) */
118 int nwcbs;
119 /* nas_wpa_cb_t list */
120 nas_wpa_cb_t *nwcb[NAS_WKSP_MAX_NUM_INTERFACES];
121 } nas_wksp_t;
123 typedef enum {
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)
131 #else
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 */
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
141 /* Common */
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);
163 /* OS dependent */
164 int nas_safe_get_conf(char *outval, int outval_size, char *name);
167 #ifdef __cplusplus
169 #endif
171 #endif /* ifndef __NAS_WKSP_H__ */