2 * Ecos-specific portion of EAPD
5 * Copyright (C) 2013, 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 307774 2012-01-12 15:59:38Z $
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
)
144 eapd_preauth_open(eapd_wksp_t
*nwksp
, eapd_preauth_socket_t
*sock
)
148 if (nwksp
== NULL
|| sock
== NULL
) {
149 EAPD_ERROR("Wrong arguments...\n");
153 sprintf(devname
, "/dev/net/eapol/%s/%d", sock
->ifname
, ETHER_TYPE_802_1X_PREAUTH
);
154 sock
->drvSocket
= open(devname
, O_RDWR
);
155 if (sock
->drvSocket
< 0) {
156 EAPD_ERROR("open socket error!!\n");
160 /* at least one use it */
161 sock
->inuseCount
= 1;
163 EAPD_INFO("%s: preauth socket %d opened\n", sock
->ifname
, sock
->drvSocket
);
169 eapd_preauth_close(int drvSocket
)
178 int eapd_safe_get_conf(char *outval
, int outval_size
, char *name
)
182 if (name
== NULL
|| outval
== NULL
) {
184 memset(outval
, 0, outval_size
);
188 val
= nvram_safe_get(name
);
189 if (!strcmp(val
, ""))
190 memset(outval
, 0, outval_size
);
192 snprintf(outval
, outval_size
, "%s", val
);
201 /* get eapd_msg_level from nvram */
202 if ((dbg
= nvram_safe_get("eapd_dbg"))) {
203 eapd_msg_level
= (uint
)strtoul(dbg
, NULL
, 0);
207 EAPD_INFO("EAP Dispatch Start...\n");
209 /* fill up EAPD task pid */
210 _eapd_pid
= oslib_pid();
212 /* alloc eapd work space */
213 if (!(eapd_nwksp
= eapd_wksp_alloc_workspace())) {
214 EAPD_ERROR("Unable to allocate wksp memory. Quitting...\n");
218 if (eapd_wksp_auto_config(eapd_nwksp
)) {
219 EAPD_ERROR("Unable to auto config. Quitting...\n");
220 eapd_wksp_cleanup(eapd_nwksp
);
224 /* run main loop to dispatch messages */
225 eapd_wksp_main_loop(eapd_nwksp
);
234 !oslib_waitpid(_eapd_pid
, NULL
)) {
236 (cyg_thread_entry_t
*)eapd_main
,
237 (cyg_addrword_t
)NULL
,
240 sizeof(eapd_main_stack
),
243 cyg_thread_resume(eapd_main_hdl
);
244 EAPD_PRINT("EAPD task started\n");
255 /* wait till the eapd_main task is dead */
256 while (oslib_waitpid(_eapd_pid
, NULL
))
257 cyg_thread_delay(10);
259 EAPD_PRINT("EAPD task stopped\n");
264 eapd_message_read(int fd
, void *buf
, size_t nbytes
)
266 return (read(fd
,buf
,nbytes
));