K2.6 patches and update.
[tomato.git] / release / src-rt / wl / nas / nas_wksp.h
blobca3ab0d9d33d2d4349fb26979e67c63bd89604df
1 /*
2 * NAS WorkSpace - NAS application common code
4 * Copyright (C) 2010, 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 241388 2011-02-18 03:33:22Z stakita $
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 printf("%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 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
83 nas_t nas;
84 wpa_t wpa;
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];
92 /* wep key index */
93 int index;
94 /* run time flags */
95 uint32 flags;
96 /* wl unit # */
97 int unit;
98 /* back pointer */
99 struct nas_wksp *nwksp;
100 } nas_wpa_cb_t;
102 /* nas work space */
103 typedef struct nas_wksp
105 /* packet buffer for reading socket */
106 uint8 packet[RADIUS_MAX_LEN];
107 /* file dscc set for select() */
108 fd_set fdset;
109 int fdmax;
110 /* receive/send eapol/bcmevent/preauth type packets to eapd */
111 int eapd;
112 /* timer module id */
113 bcm_timer_module_id timer;
114 /* run time flags */
115 uint32 flags;
116 /* # of i/f (in/out) */
117 int nwcbs;
118 /* nas_wpa_cb_t list */
119 nas_wpa_cb_t *nwcb[NAS_WKSP_MAX_NUM_INTERFACES];
120 } nas_wksp_t;
122 typedef enum {
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)
130 #else
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 */
136 #ifdef __cplusplus
137 extern "C" {
138 #endif
140 /* Common */
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);
162 /* OS dependent */
163 int nas_safe_get_conf(char *outval, int outval_size, char *name);
166 #ifdef __cplusplus
168 #endif
170 #endif /* ifndef __NAS_WKSP_H__ */