2 * Ecos-specific portion of EAPD
5 * Copyright (C) 2010, Broadcom Corporation
8 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
9 * the contents of this file may not be disclosed to third parties, copied
10 * or duplicated in any form, in whole or in part, without the prior
11 * written permission of Broadcom Corporation.
13 * $Id: eapd_ecos.c 241391 2011-02-18 03:35:48Z stakita $
20 #include <ecos_oslib.h>
21 #include <proto/ethernet.h>
22 #include <proto/eapol.h>
23 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #include <cyg/io/file.h>
27 #include <netinet/ip.h>
28 #include <netinet/udp.h>
29 #include <proto/eap.h>
33 static eapd_wksp_t
*eapd_nwksp
= NULL
;
35 static cyg_handle_t eapd_main_hdl
;
36 static char eapd_main_stack
[8*1024];
37 static cyg_thread eapd_thread
;
38 static int _eapd_pid
= 0;
41 eapd_hup_hdlr(int sig
)
44 eapd_nwksp
->flags
|= EAPD_WKSP_FLAG_SHUTDOWN
;
50 eapd_dump_hdlr(int sig
)
53 eapd_nwksp
->flags
|= EAPD_WKSP_FLAG_DUMP
;
58 /* Send a canned EAPOL packet */
60 eapd_eapol_canned_send(eapd_wksp_t
*nwksp
, struct eapd_socket
*Socket
, eapd_sta_t
*sta
,
61 unsigned char code
, unsigned char type
)
69 memcpy(&eapol
.eth
.ether_dhost
, &sta
->ea
, ETHER_ADDR_LEN
);
70 memcpy(&eapol
.eth
.ether_shost
, &sta
->bssid
, ETHER_ADDR_LEN
);
72 eapol
.eth
.ether_type
= htons(ETHER_TYPE_802_1X
);
73 eapol
.version
= sta
->eapol_version
;
74 eapol
.type
= EAP_PACKET
;
75 /* With type, eap.type is used. So, the legnth will be 4+1 */
76 len
= type
? (EAP_HEADER_LEN
+ 1) : EAP_HEADER_LEN
;
77 eapol
.length
= htons(len
);
81 eap
.length
= eapol
.length
;
83 /* This is optional, if type is 0, this field won't be used. */
86 /* Allocate a buffer to send ? */
87 packet
= (char *)malloc(EAPOL_HEADER_LEN
+ len
);
92 memcpy(ptr
, &eapol
, EAPOL_HEADER_LEN
);
94 ptr
+= EAPOL_HEADER_LEN
;
95 memcpy(ptr
, &eap
, len
);
98 write(Socket
->drvSocket
, packet
, len
+ EAPOL_HEADER_LEN
);
105 eapd_message_send(eapd_wksp_t
*nwksp
, struct eapd_socket
*Socket
, uint8
*pData
, int pLen
)
107 /* We should handle fragment here */
108 write(Socket
->drvSocket
, pData
, pLen
);
112 eapd_brcm_open(eapd_wksp_t
*nwksp
, eapd_brcm_socket_t
*sock
)
116 if (nwksp
== NULL
|| sock
== NULL
) {
117 EAPD_ERROR("Wrong arguments...\n");
121 sprintf(devname
, "/dev/net/eapol/%s/%d", sock
->ifname
, ETHER_TYPE_BRCM
);
122 sock
->drvSocket
= open(devname
, O_RDWR
);
123 if (sock
->drvSocket
< 0) {
124 EAPD_ERROR("open socket error!!\n");
128 /* at least one use it */
129 sock
->inuseCount
= 1;
131 EAPD_INFO("%s: BRCM socket %d opened\n", sock
->ifname
, sock
->drvSocket
);
137 eapd_brcm_close(int drvSocket
)
145 eapd_preauth_open(eapd_wksp_t
*nwksp
, eapd_preauth_socket_t
*sock
)
149 if (nwksp
== NULL
|| sock
== NULL
) {
150 EAPD_ERROR("Wrong arguments...\n");
154 sprintf(devname
, "/dev/net/eapol/%s/%d", sock
->ifname
, ETHER_TYPE_802_1X_PREAUTH
);
155 sock
->drvSocket
= open(devname
, O_RDWR
);
156 if (sock
->drvSocket
< 0) {
157 EAPD_ERROR("open socket error!!\n");
161 /* at least one use it */
162 sock
->inuseCount
= 1;
164 EAPD_INFO("%s: preauth socket %d opened\n", sock
->ifname
, sock
->drvSocket
);
170 eapd_preauth_close(int drvSocket
)
180 int eapd_safe_get_conf(char *outval
, int outval_size
, char *name
)
184 if (name
== NULL
|| outval
== NULL
) {
186 memset(outval
, 0, outval_size
);
190 val
= nvram_safe_get(name
);
191 if (!strcmp(val
, ""))
192 memset(outval
, 0, outval_size
);
194 snprintf(outval
, outval_size
, "%s", val
);
203 /* get eapd_msg_level from nvram */
204 if ((dbg
= nvram_safe_get("eapd_dbg"))) {
205 eapd_msg_level
= (uint
)strtoul(dbg
, NULL
, 0);
209 EAPD_INFO("EAP Dispatch Start...\n");
211 /* fill up EAPD task pid */
212 _eapd_pid
= oslib_pid();
214 /* alloc eapd work space */
215 if (!(eapd_nwksp
= eapd_wksp_alloc_workspace())) {
216 EAPD_ERROR("Unable to allocate wksp memory. Quitting...\n");
220 if (eapd_wksp_auto_config(eapd_nwksp
)) {
221 EAPD_ERROR("Unable to auto config. Quitting...\n");
222 eapd_wksp_cleanup(eapd_nwksp
);
226 /* run main loop to dispatch messages */
227 eapd_wksp_main_loop(eapd_nwksp
);
236 !oslib_waitpid(_eapd_pid
, NULL
)) {
238 (cyg_thread_entry_t
*)eapd_main
,
239 (cyg_addrword_t
)NULL
,
242 sizeof(eapd_main_stack
),
245 cyg_thread_resume(eapd_main_hdl
);
246 EAPD_PRINT("EAPD task started\n");
257 /* wait till the eapd_main task is dead */
258 while (oslib_waitpid(_eapd_pid
, NULL
))
259 cyg_thread_delay(10);
261 EAPD_PRINT("EAPD task stopped\n");