1 /* Network Authentication Service deamon (vxWorks)
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_vx.c 241388 2011-02-18 03:33:22Z stakita $
29 #include <taskVarLib.h>
32 extern int gettimeofday(struct timeval
*tv
, struct timezone
*tz
);
33 extern int sysClkRateGet(void);
34 extern void sys_reboot();
39 #include <proto/ethernet.h>
40 #include <proto/eapol.h>
41 #include <bcmcrypto/md5.h>
47 static nas_wksp_t
* nas_nwksp
= NULL
;
52 taskDelay(ms
*sysClkRateGet()/1000);
56 nas_rand128(uint8
*rand128
)
62 gettimeofday(&tv
, &tz
);
65 MD5Update(&md5
, (unsigned char *) &tv
, sizeof(tv
));
66 MD5Update(&md5
, (unsigned char *) &tz
, sizeof(tz
));
67 MD5Final(rand128
, &md5
);
74 nas_nwksp
->flags
= NAS_WKSP_FLAG_SHUTDOWN
;
83 nas_safe_get_conf(char *outval
, int outval_size
, char *name
)
87 if (name
== NULL
|| outval
== NULL
) {
89 memset(outval
, 0, outval_size
);
93 val
= nvram_safe_get(name
);
95 memset(outval
, 0, outval_size
);
97 snprintf(outval
, outval_size
, "%s", val
);
109 /* clear rootnwksp */
112 /* alloc nas/wpa work space */
113 if (!(nas_nwksp
= nas_wksp_alloc_workspace())) {
114 NASMSG("Unable to allocate work space memory. Quitting...\n");
119 /* verbose - 0:no | others:yes */
121 if (nas_safe_get_conf(debug
, sizeof(debug
), "nas_dbg") == 0)
122 debug_nwksp
= (int)atoi(debug
);
124 /* establish a handler to handle SIGTERM. */
125 signal(SIGTERM
, hup_hdlr
);
127 /* run main loop to dispatch message */
128 nas_wksp_main_loop(nas_nwksp
);
143 int tid
= taskNameToId("NAS");
147 /* clear nas wksp initialization flag */
148 nas_wksp_clear_inited();
151 60, /* priority of new task */
152 0, /* task option word */
153 30000, /* size (bytes) of stack needed plus name */
154 (FUNCPTR
)nas_main
, /* entry point of new task */
157 0, 0, 0, 0, 0, 0, 0, 0);
158 printf("NAS task started.\n");
160 /* wait until nas initialization finished */
163 if (tickGet() - ticks
< 3 * sysClkRateGet())
164 taskDelay(sysClkRateGet());
166 printf("Unable to wait NAS initialization finished!.\n");
169 } while (taskNameToId("NAS") != ERROR
&& !nas_wksp_is_inited());
172 printf("NAS task is already running.\n");
178 int tid
= taskNameToId("NAS");
185 /* wait till the task is dead */
188 if (tickGet() - ticks
< 3 * sysClkRateGet())
189 taskDelay(sysClkRateGet());
191 printf("Unable to kill NAS task!.\n");
195 while (taskNameToId("NAS") != ERROR
);
196 printf("NAS task killed.\n");
199 printf("NAS task is not running.\n");