3 Copyright 2003, CyberTAN Inc. All Rights Reserved
5 This is UNPUBLISHED PROPRIETARY SOURCE CODE of CyberTAN Inc.
6 the contents of this file may not be disclosed to third parties,
7 copied or duplicated in any form without the prior written
8 permission of CyberTAN Inc.
10 This software should be used as a reference only, and it not
11 intended for production use!
13 THIS SOFTWARE IS OFFERED "AS IS", AND CYBERTAN GRANTS NO WARRANTIES OF ANY
14 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. CYBERTAN
15 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
16 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE
21 Copyright 2005, Broadcom Corporation
24 THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
25 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
26 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
27 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
33 #include <sys/sysinfo.h>
38 // ref: http://wiki.openwrt.org/OpenWrtDocs/nas
40 // #define DEBUG_TIMING
46 if ((nvram_match("wl_mode", "wet")) || (nvram_match("wl0_radio", "0")) ||
47 (nvram_match("security_mode", "disabled"))) {
54 _dprintf("%s: uptime=%ld\n", __FUNCTION__
, si
.uptime
);
56 _dprintf("%s\n", __FUNCTION__
);
60 xstart("nas", "/etc/nas.conf", "/var/run/nas.pid", nvram_match("wl_mode", "sta") ? "wan" : "lan");
69 _dprintf("%s: uptime=%ld\n", __FUNCTION__
, si
.uptime
);
71 _dprintf("%s\n", __FUNCTION__
);
74 killall("nas", SIGTERM
);
77 void notify_nas(const char *ifname
)
82 _dprintf("%s: ifname=%s uptime=%ld\n", __FUNCTION__
, ifname
, si
.uptime
);
84 _dprintf("%s: ifname=%s\n", __FUNCTION__
, ifname
);
87 if (nvram_match("security_mode", "disabled")) return;
92 while (pidof("nas") == -1) {
93 _dprintf("waiting for nas i=%d\n", i
);
95 syslog(LOG_ERR
, "Unable to find nas");
102 xstart("nas4not", "lan", ifname
, "up", "auto",
103 nvram_safe_get("wl_crypto"), // aes, tkip (aes+tkip ok?)
104 nvram_safe_get("wl_akm"), // psk (only?)
105 nvram_safe_get("wl_wpa_psk"), // shared key
106 nvram_safe_get("wl_ssid") // ssid
113 #if 0 // old stuff for ref
117 void del_wds_wsec(int unit, int which)
121 sprintf(name, "wl%d_wds%d", unit, which);
129 nvram_match("wl_mode", "sta") ? "-S" : "-A",
131 "-i", nvram_safe_get("wl_ifname"),
132 "-l", nvram_safe_get("lan_ifname"),
137 // WPA doesn't support shared key removed, handled during config set zzz
138 // if (strstr(nvram_safe_get("security_mode2"), "wpa") != NULL) {
139 // nvram_set("wl_auth", "0");
142 // if ((nvram_match("wl_mode", "sta")) && (nvram_match("wl_akm", "psk psk2"))) {
143 // nvram_set("wl_akm", "psk2");
151 static int get_wds_wsec(int unit, int which, char *mac, char *role, char *crypto, char *auth, char *ssid, char *pass)
156 sprintf(buf, "wl%d_wds%d", unit, which);
157 strlcpy(buf, nvram_safe_get(buf), sizeof(buf));
160 strcpy(mac, strsep(&next, ","));
163 strcpy(role, strsep(&next, ","));
166 strcpy(crypto, strsep(&next, ","));
169 strcpy(auth, strsep(&next, ","));
172 strcpy(ssid, strsep(&next, ","));
179 static void convert_wds(void)
184 if (nvram_match("wl_wds", "")) { // For Router, accept all WDS link
185 strcpy(wds_mac, "*");
187 else { // For AP, assign remote WDS MAC
188 strlcpy(wds_mac, nvram_safe_get("wl_wds"), sizeof(wds_mac));
192 // For WPA-PSK mode, we want to convert wl_wds_mac to wl0_wds0 ... wl0_wds255
193 if (strstr(nvram_safe_get("security_mode"), "psk")) {
200 foreach(mac, wds_mac, next) {
201 snprintf(wl_wds, sizeof(wl_wds), "wl0_wds%d", i);
202 snprintf(buf, sizeof(buf), "%s,auto,%s,%s,%s,%s",
204 nvram_safe_get("wl_crypto"),
205 nvram_safe_get("security_mode"),
206 nvram_safe_get("wl_ssid"),
207 nvram_safe_get("wl_wpa_psk"));
209 nvram_set(wl_wds, buf);
213 for (j = i; j < 20; j++)
220 void notify_nas(char *ifname
)
222 char *argv
[] = {"nas4not", "lan", ifname
, "up",
226 NULL
, /* passphrase */
229 char tmp
[100], prefix
[32];
231 char remote
[ETHER_ADDR_LEN
];
232 char ssid
[48], pass
[80], auth
[16], crypto
[16], role
[8];
235 /* the wireless interface must be configured to run NAS */
236 wl_ioctl(ifname
, WLC_GET_INSTANCE
, &unit
, sizeof(unit
));
237 sprintf(prefix
, "wl%d_", unit
);
238 if (nvram_match(strcat_r(prefix
, "akm", tmp
), "") && nvram_match(strcat_r(prefix
, "auth_mode", tmp
), "none")) {
242 // wait until nas is up and running
247 while (f_read("/tmp/nas.lan.pid", s
, sizeof(s
)) <= 0) {
249 cprintf("notify_nas: unable to find nas");
257 /* find WDS link configuration */
258 wl_ioctl(ifname
, WLC_WDS_GET_REMOTE_HWADDR
, remote
, ETHER_ADDR_LEN
);
259 for (i
= 0; i
< 20; ++i
) {
260 char mac
[ETHER_ADDR_STR_LEN
];
261 uint8 ea
[ETHER_ADDR_LEN
];
263 if (get_wds_wsec(unit
, i
, mac
, role
, crypto
, auth
, ssid
, pass
) &&
264 ether_atoe(mac
, ea
) && !bcmp(ea
, remote
, ETHER_ADDR_LEN
)) {
271 cprintf("notify_nas: get_wds_wsec(%d,%d) crypto=%s", unit
, i
, argv
[5]);
275 /* did not find WDS link configuration, use wireless' */
280 argv
[5] = nvram_safe_get(strcat_r(prefix
, "crypto", tmp
));
282 argv
[6] = nvram_safe_get(strcat_r(prefix
, "akm", tmp
));
284 argv
[7] = nvram_safe_get(strcat_r(prefix
, "wpa_psk", tmp
));
286 argv
[8] = nvram_safe_get(strcat_r(prefix
, "ssid", tmp
));
288 cprintf("notify_nas: i==MAX crypto=%s", argv
[5]);
294 for (i
= 0; argv
[i
]; ++i
) {
298 cprintf("notify_nas: %s", cl
);
302 _eval(argv
, ">/dev/console", 0, &pid
);