2 * Network Authentication Service deamon (Linux)
4 * Copyright (C) 2010, Broadcom Corporation
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_linux.c 241388 2011-02-18 03:33:22Z stakita $
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/ioctl.h>
25 #include <netinet/in.h>
27 #include <net/if_arp.h>
28 #include <arpa/inet.h>
32 #include <linux/if_packet.h>
33 #include <linux/if_ether.h>
34 #include <linux/types.h>
35 #include <linux/filter.h>
40 #include <proto/ethernet.h>
41 #include <proto/eapol.h>
42 #include <bcmcrypto/md5.h>
48 static nas_wksp_t
* nas_nwksp
= NULL
;
57 nas_rand128(uint8
*rand128
)
59 static int dev_random_fd
= -1;
63 if (dev_random_fd
== -1)
64 /* Use /dev/urandom because /dev/random, when it works at all,
65 * won't return anything when its entropy pool runs short and
66 * we can't control that. /dev/urandom look good enough.
68 dev_random_fd
= open("/dev/urandom", O_RDONLY
|O_NONBLOCK
);
69 if (dev_random_fd
!= -1)
70 read(dev_random_fd
, rand128
, 16);
72 gettimeofday(&tv
, &tz
);
75 MD5Update(&md5
, (unsigned char *) &tv
, sizeof(tv
));
76 MD5Update(&md5
, (unsigned char *) &tz
, sizeof(tz
));
77 MD5Final(rand128
, &md5
);
85 nas_nwksp
->flags
= NAS_WKSP_FLAG_SHUTDOWN
;
93 nas_safe_get_conf(char *outval
, int outval_size
, char *name
)
97 if (name
== NULL
|| outval
== NULL
) {
99 memset(outval
, 0, outval_size
);
103 val
= nvram_safe_get(name
);
104 if (!strcmp(val
, ""))
105 memset(outval
, 0, outval_size
);
107 snprintf(outval
, outval_size
, "%s", val
);
111 /* service main entry */
113 main(int argc
, char *argv
[])
115 /* display usage if nothing is specified */
117 (!strncmp(argv
[1], "-h", 2) ||
118 !strncmp(argv
[1], "-H", 2))) {
119 nas_wksp_display_usage();
123 /* alloc nas/wpa work space */
124 if (!(nas_nwksp
= nas_wksp_alloc_workspace())) {
125 NASMSG("Unable to allocate work space memory. Quitting...\n");
129 if (argc
> 1 && nas_wksp_parse_cmd(argc
, argv
, nas_nwksp
)) {
130 NASMSG("Command line parsing error. Quitting...\n");
131 nas_wksp_free_workspace(nas_nwksp
);
136 /* verbose - 0:no | others:yes */
139 if (nas_safe_get_conf(debug
, sizeof(debug
), "nas_dbg") == 0)
140 debug_nwksp
= (int)atoi(debug
);
144 /* establish a handler to handle SIGTERM. */
145 signal(SIGTERM
, hup_hdlr
);
147 /* run main loop to dispatch messages */
148 nas_wksp_main_loop(nas_nwksp
);