1 /* Network Authentication Service deamon (Ecos)
3 * Copyright (C) 2010, Broadcom Corporation
6 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
7 * the contents of this file may not be disclosed to third parties, copied
8 * or duplicated in any form, in whole or in part, without the prior
9 * written permission of Broadcom Corporation.
11 * $Id: nas_ecos.c 241388 2011-02-18 03:33:22Z stakita $
20 #include <proto/ethernet.h>
21 #include <proto/eapol.h>
22 #include <bcmcrypto/md5.h>
25 #include <sys/socket.h>
27 #include <net/if_var.h>
29 #include <netinet/in.h>
30 #include <netinet/in_var.h>
31 #include <netinet/ip.h>
32 #include <netinet/udp.h>
33 #include <ecos_oslib.h>
38 #include <proto/eap.h>
40 #include <nas_radius.h>
44 extern int gettimeofday(struct timeval
*tv
, struct timezone
*tz
);
45 extern void sys_reboot(void);
47 static cyg_handle_t nas_main_hdl
;
48 static char nas_main_stack
[16*1024];
49 static cyg_thread nas_thread
;
50 static int _nas_pid
= 0, _nas_ready
= 0;
52 static nas_wksp_t
*nas_nwksp
= NULL
;
57 cyg_tick_count_t ostick
;
60 cyg_thread_delay(ostick
);
64 nas_rand128(uint8
*rand128
)
70 gettimeofday(&tv
, &tz
);
73 MD5Update(&md5
, (unsigned char *) &tv
, sizeof(tv
));
74 MD5Update(&md5
, (unsigned char *) &tz
, sizeof(tz
));
75 MD5Final(rand128
, &md5
);
82 nas_nwksp
->flags
= NAS_WKSP_FLAG_SHUTDOWN
;
91 nas_safe_get_conf(char *outval
, int outval_size
, char *name
)
95 if (name
== NULL
|| outval
== NULL
) {
97 memset(outval
, 0, outval_size
);
101 val
= nvram_safe_get(name
);
102 if (!strcmp(val
, ""))
103 memset(outval
, 0, outval_size
);
105 snprintf(outval
, outval_size
, "%s", val
);
121 /* clear _nas_ready */
124 /* fill up NAS task pid */
125 _nas_pid
= oslib_pid();
127 /* clear rootnwksp */
130 /* alloc nas/wpa work space */
131 if (!(nas_nwksp
= nas_wksp_alloc_workspace())) {
132 NASMSG("Unable to allocate work space memory. Quitting...\n");
137 /* verbose - 0:no | others:yes */
139 if (nas_safe_get_conf(debug
, sizeof(debug
), "nas_dbg") == 0)
140 debug_nwksp
= (int)atoi(debug
);
143 /* run main loop to dispatch message */
144 nas_wksp_main_loop(nas_nwksp
);
159 int wait_time
= 1 * 100; /* 1 second */
162 !oslib_waitpid(_nas_pid
, NULL
)) {
164 (cyg_thread_entry_t
*)nas_main
,
165 (cyg_addrword_t
)NULL
,
167 (void *)nas_main_stack
,
168 sizeof(nas_main_stack
),
171 cyg_thread_resume(nas_main_hdl
);
173 /* Make sure nas stared and initial completed. Otherwise,
174 * it may lost some wireless driver events.
176 while (_nas_ready
== 0 && wait_time
> 0) {
177 cyg_thread_delay(10);
181 NASMSG("NAS task started\n");
189 hup_hdlr(15 /* SIGTERM */);
191 /* wait until not running */
192 while (oslib_waitpid(_nas_pid
, NULL
))
193 cyg_thread_delay(10);
195 NASMSG("NAS task stopped\n");