| 1 | /* |
|---|
| 2 | * madwifi.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2005 - 2007 Sebastian Gottschall <gottschall@dd-wrt.com> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of the GNU General Public License |
|---|
| 8 | * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | * of the License, or (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | * |
|---|
| 20 | * $Id: |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #ifdef HAVE_MADWIFI |
|---|
| 25 | #include <sys/mman.h> |
|---|
| 26 | #include <stdio.h> |
|---|
| 27 | #include <unistd.h> |
|---|
| 28 | #include <signal.h> |
|---|
| 29 | #include <fcntl.h> |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #include <sys/types.h> |
|---|
| 35 | #include <sys/file.h> |
|---|
| 36 | #include <sys/ioctl.h> |
|---|
| 37 | #include <sys/socket.h> |
|---|
| 38 | |
|---|
| 39 | #include <stdio.h> |
|---|
| 40 | #include <stdlib.h> |
|---|
| 41 | #include <string.h> |
|---|
| 42 | #include <stdint.h> |
|---|
| 43 | #include <ctype.h> |
|---|
| 44 | #include <getopt.h> |
|---|
| 45 | #include <err.h> |
|---|
| 46 | |
|---|
| 47 | #include <ctype.h> |
|---|
| 48 | #include <string.h> |
|---|
| 49 | #include <stdlib.h> |
|---|
| 50 | #include <stdio.h> |
|---|
| 51 | #include <bcmnvram.h> |
|---|
| 52 | #include <bcmutils.h> |
|---|
| 53 | #include <shutils.h> |
|---|
| 54 | #include <utils.h> |
|---|
| 55 | #include <unistd.h> |
|---|
| 56 | |
|---|
| 57 | #include "wireless.h" |
|---|
| 58 | #include "net80211/ieee80211.h" |
|---|
| 59 | #include "net80211/ieee80211_crypto.h" |
|---|
| 60 | #include "net80211/ieee80211_ioctl.h" |
|---|
| 61 | #include <iwlib.h> |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | static int socket_handle = -1; |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | static int |
|---|
| 69 | getsocket (void) |
|---|
| 70 | { |
|---|
| 71 | |
|---|
| 72 | if (socket_handle < 0) |
|---|
| 73 | { |
|---|
| 74 | socket_handle = socket (AF_INET, SOCK_DGRAM, 0); |
|---|
| 75 | if (socket_handle < 0) |
|---|
| 76 | err (1, "socket(SOCK_DGRAM)"); |
|---|
| 77 | } |
|---|
| 78 | return socket_handle; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | #define IOCTL_ERR(x) [x - SIOCIWFIRSTPRIV] "ioctl[" #x "]" |
|---|
| 82 | static int |
|---|
| 83 | set80211priv (struct iwreq *iwr, const char *ifname, int op, void *data, |
|---|
| 84 | size_t len) |
|---|
| 85 | { |
|---|
| 86 | #define N(a) (sizeof(a)/sizeof(a[0])) |
|---|
| 87 | |
|---|
| 88 | memset (iwr, 0, sizeof (struct iwreq)); |
|---|
| 89 | strncpy (iwr->ifr_name, ifname, IFNAMSIZ); |
|---|
| 90 | if (len < IFNAMSIZ) |
|---|
| 91 | { |
|---|
| 92 | /* |
|---|
| 93 | * Argument data fits inline; put it there. |
|---|
| 94 | */ |
|---|
| 95 | memcpy (iwr->u.name, data, len); |
|---|
| 96 | } |
|---|
| 97 | else |
|---|
| 98 | { |
|---|
| 99 | /* |
|---|
| 100 | * Argument data too big for inline transfer; setup a |
|---|
| 101 | * parameter block instead; the kernel will transfer |
|---|
| 102 | * the data for the driver. |
|---|
| 103 | */ |
|---|
| 104 | iwr->u.data.pointer = data; |
|---|
| 105 | iwr->u.data.length = len; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if (ioctl (getsocket (), op, iwr) < 0) |
|---|
| 109 | { |
|---|
| 110 | static const char *opnames[] = { |
|---|
| 111 | IOCTL_ERR (IEEE80211_IOCTL_SETPARAM), |
|---|
| 112 | IOCTL_ERR (IEEE80211_IOCTL_GETPARAM), |
|---|
| 113 | IOCTL_ERR (IEEE80211_IOCTL_SETMODE), |
|---|
| 114 | IOCTL_ERR (IEEE80211_IOCTL_GETMODE), |
|---|
| 115 | IOCTL_ERR (IEEE80211_IOCTL_SETWMMPARAMS), |
|---|
| 116 | IOCTL_ERR (IEEE80211_IOCTL_GETWMMPARAMS), |
|---|
| 117 | IOCTL_ERR (IEEE80211_IOCTL_SETCHANLIST), |
|---|
| 118 | IOCTL_ERR (IEEE80211_IOCTL_GETCHANLIST), |
|---|
| 119 | IOCTL_ERR (IEEE80211_IOCTL_CHANSWITCH), |
|---|
| 120 | IOCTL_ERR (IEEE80211_IOCTL_GETCHANINFO), |
|---|
| 121 | IOCTL_ERR (IEEE80211_IOCTL_SETOPTIE), |
|---|
| 122 | IOCTL_ERR (IEEE80211_IOCTL_GETOPTIE), |
|---|
| 123 | IOCTL_ERR (IEEE80211_IOCTL_SETMLME), |
|---|
| 124 | IOCTL_ERR (IEEE80211_IOCTL_SETKEY), |
|---|
| 125 | IOCTL_ERR (IEEE80211_IOCTL_DELKEY), |
|---|
| 126 | IOCTL_ERR (IEEE80211_IOCTL_ADDMAC), |
|---|
| 127 | IOCTL_ERR (IEEE80211_IOCTL_DELMAC), |
|---|
| 128 | IOCTL_ERR (IEEE80211_IOCTL_WDSADDMAC), |
|---|
| 129 | #ifdef OLD_MADWIFI |
|---|
| 130 | IOCTL_ERR (IEEE80211_IOCTL_WDSDELMAC), |
|---|
| 131 | #else |
|---|
| 132 | IOCTL_ERR (IEEE80211_IOCTL_WDSSETMAC), |
|---|
| 133 | #endif |
|---|
| 134 | }; |
|---|
| 135 | op -= SIOCIWFIRSTPRIV; |
|---|
| 136 | if (0 <= op && op < N (opnames)) |
|---|
| 137 | perror (opnames[op]); |
|---|
| 138 | else |
|---|
| 139 | perror ("ioctl[unknown???]"); |
|---|
| 140 | return -1; |
|---|
| 141 | } |
|---|
| 142 | return 0; |
|---|
| 143 | #undef N |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | int |
|---|
| 148 | do80211priv (const char *ifname, int op, void *data, size_t len) |
|---|
| 149 | { |
|---|
| 150 | struct iwreq iwr; |
|---|
| 151 | |
|---|
| 152 | if (set80211priv (&iwr, ifname, op, data, len) < 0) |
|---|
| 153 | return -1; |
|---|
| 154 | if (len < IFNAMSIZ) |
|---|
| 155 | memcpy (data, iwr.u.name, len); |
|---|
| 156 | return iwr.u.data.length; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | static int |
|---|
| 160 | set80211param (char *iface, int op, int arg) |
|---|
| 161 | { |
|---|
| 162 | struct iwreq iwr; |
|---|
| 163 | |
|---|
| 164 | memset (&iwr, 0, sizeof (iwr)); |
|---|
| 165 | strncpy (iwr.ifr_name, iface, IFNAMSIZ); |
|---|
| 166 | iwr.u.mode = op; |
|---|
| 167 | memcpy (iwr.u.name + sizeof (__u32), &arg, sizeof (arg)); |
|---|
| 168 | |
|---|
| 169 | if (ioctl (getsocket (), IEEE80211_IOCTL_SETPARAM, &iwr) < 0) |
|---|
| 170 | { |
|---|
| 171 | perror ("ioctl[IEEE80211_IOCTL_SETPARAM]"); |
|---|
| 172 | return -1; |
|---|
| 173 | } |
|---|
| 174 | return 0; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | extern int br_add_interface (const char *br, const char *dev); |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | static int |
|---|
| 185 | setsysctrl (const char *dev, const char *control, u_long value) |
|---|
| 186 | { |
|---|
| 187 | char buffer[256]; |
|---|
| 188 | // FILE *fd; |
|---|
| 189 | |
|---|
| 190 | snprintf (buffer, sizeof (buffer), "echo %li > /proc/sys/dev/%s/%s", value, |
|---|
| 191 | dev, control); |
|---|
| 192 | |
|---|
| 193 | system2 (buffer); |
|---|
| 194 | /* fd = fopen (buffer, "w"); |
|---|
| 195 | if (fd != NULL) |
|---|
| 196 | { |
|---|
| 197 | fprintf (fd, "%li", value); |
|---|
| 198 | } */ |
|---|
| 199 | return 0; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | static void |
|---|
| 203 | setdistance (char *device, int distance,int chanbw) |
|---|
| 204 | { |
|---|
| 205 | |
|---|
| 206 | if (distance >= 0) |
|---|
| 207 | { |
|---|
| 208 | int slottime = (distance / 300) + ((distance % 300) ? 1 : 0); |
|---|
| 209 | int acktimeout = slottime * 2 + 3; |
|---|
| 210 | int ctstimeout = slottime * 2 + 3; |
|---|
| 211 | |
|---|
| 212 | // printf("Setting distance on interface %s to %i meters\n", device, distance); |
|---|
| 213 | setsysctrl (device, "slottime", slottime); |
|---|
| 214 | setsysctrl (device, "acktimeout", acktimeout); |
|---|
| 215 | setsysctrl (device, "ctstimeout", ctstimeout); |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | //returns the number of installed atheros devices/cards |
|---|
| 220 | |
|---|
| 221 | static char iflist[1024]; |
|---|
| 222 | |
|---|
| 223 | char * |
|---|
| 224 | getiflist (void) |
|---|
| 225 | { |
|---|
| 226 | return iflist; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | static void |
|---|
| 230 | destroy_wds (char *ifname) |
|---|
| 231 | { |
|---|
| 232 | int s; |
|---|
| 233 | for (s = 1; s <= 10; s++) |
|---|
| 234 | { |
|---|
| 235 | char dev[16]; |
|---|
| 236 | sprintf (dev, "wds%s.%d", ifname, s); |
|---|
| 237 | if (ifexists (dev)) |
|---|
| 238 | { |
|---|
| 239 | br_del_interface ("br0", dev); |
|---|
| 240 | eval ("wlanconfig", dev, "destroy"); |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | static void |
|---|
| 247 | deconfigure_single (int count) |
|---|
| 248 | { |
|---|
| 249 | char *next; |
|---|
| 250 | char dev[16]; |
|---|
| 251 | char var[80]; |
|---|
| 252 | char wifivifs[16]; |
|---|
| 253 | sprintf (wifivifs, "ath%d_vifs", count); |
|---|
| 254 | sprintf (dev, "ath%d", count); |
|---|
| 255 | char vifs[128]; |
|---|
| 256 | sprintf (vifs, "%s.1 %s.2 %s.3 %s.4 %s.5 %s.6 %s.7 %s.8 %s.9", dev, dev, |
|---|
| 257 | dev, dev, dev, dev, dev, dev, dev); |
|---|
| 258 | int s; |
|---|
| 259 | for (s = 1; s <= 10; s++) |
|---|
| 260 | { |
|---|
| 261 | sprintf (dev, "wdsath%d.%d", count, s); |
|---|
| 262 | if (ifexists (dev)) |
|---|
| 263 | { |
|---|
| 264 | br_del_interface ("br0", dev); |
|---|
| 265 | eval ("ifconfig", dev, "down"); |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | sprintf (dev, "ath%d", count); |
|---|
| 269 | if (ifexists (dev)) |
|---|
| 270 | { |
|---|
| 271 | br_del_interface ("br0", dev); |
|---|
| 272 | eval ("ifconfig", dev, "down"); |
|---|
| 273 | } |
|---|
| 274 | foreach (var, vifs, next) |
|---|
| 275 | { |
|---|
| 276 | if (ifexists (var)) |
|---|
| 277 | { |
|---|
| 278 | eval ("ifconfig", var, "down"); |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | sprintf (dev, "ath%d", count); |
|---|
| 282 | #ifdef OLD_MADWIFI |
|---|
| 283 | destroy_wds (dev); |
|---|
| 284 | #endif |
|---|
| 285 | |
|---|
| 286 | if (ifexists (dev)) |
|---|
| 287 | eval ("wlanconfig", dev, "destroy"); |
|---|
| 288 | |
|---|
| 289 | foreach (var, vifs, next) |
|---|
| 290 | { |
|---|
| 291 | if (ifexists (var)) |
|---|
| 292 | { |
|---|
| 293 | eval ("wlanconfig", var, "destroy"); |
|---|
| 294 | } |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | void |
|---|
| 302 | deconfigure_wifi (void) |
|---|
| 303 | { |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | memset (iflist, 0, 1024); |
|---|
| 307 | killall ("wrt-radauth", SIGTERM); |
|---|
| 308 | killall ("hostapd", SIGTERM); |
|---|
| 309 | killall ("wpa_supplicant", SIGTERM); |
|---|
| 310 | sleep (1); |
|---|
| 311 | killall ("wrt-radauth", SIGKILL); |
|---|
| 312 | killall ("hostapd", SIGKILL); |
|---|
| 313 | killall ("wpa_supplicant", SIGKILL); |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | int c = getdevicecount (); |
|---|
| 317 | int i; |
|---|
| 318 | for (i = 0; i < c; i++) |
|---|
| 319 | deconfigure_single (i); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | static int need_commit = 0; |
|---|
| 328 | |
|---|
| 329 | char * |
|---|
| 330 | default_get (char *var, char *def) |
|---|
| 331 | { |
|---|
| 332 | char *v = nvram_get (var); |
|---|
| 333 | if (v == NULL || strlen (v) == 0) |
|---|
| 334 | { |
|---|
| 335 | nvram_set (var, def); |
|---|
| 336 | need_commit = 1; |
|---|
| 337 | } |
|---|
| 338 | return nvram_safe_get (var); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | int |
|---|
| 342 | default_match (char *var, char *match, char *def) |
|---|
| 343 | { |
|---|
| 344 | char *v = nvram_get (var); |
|---|
| 345 | if (v == NULL || strlen (v) == 0) |
|---|
| 346 | { |
|---|
| 347 | nvram_set (var, def); |
|---|
| 348 | need_commit = 1; |
|---|
| 349 | } |
|---|
| 350 | return nvram_match (var, match); |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | static int |
|---|
| 356 | getMaxPower (char *ifname) |
|---|
| 357 | { |
|---|
| 358 | char buf[128]; |
|---|
| 359 | sprintf (buf, "iwlist %s txpower|grep \"Maximum Power:\" > /tmp/.power", |
|---|
| 360 | ifname); |
|---|
| 361 | system2 (buf); |
|---|
| 362 | FILE *in = fopen ("/tmp/.power", "rb"); |
|---|
| 363 | if (in == NULL) |
|---|
| 364 | return 1000; |
|---|
| 365 | char buf2[16]; |
|---|
| 366 | int max; |
|---|
| 367 | fscanf (in, "%s %s %d", buf, buf2, &max); |
|---|
| 368 | fclose (in); |
|---|
| 369 | return max; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | /* |
|---|
| 373 | MADWIFI Encryption Setup |
|---|
| 374 | */ |
|---|
| 375 | void |
|---|
| 376 | setupSupplicant (char *prefix, char *ssidoverride) |
|---|
| 377 | { |
|---|
| 378 | char akm[16]; |
|---|
| 379 | char bridged[32]; |
|---|
| 380 | char wmode[16]; |
|---|
| 381 | sprintf (akm, "%s_akm", prefix); |
|---|
| 382 | sprintf (wmode, "%s_mode", prefix); |
|---|
| 383 | sprintf (bridged, "%s_bridged", prefix); |
|---|
| 384 | if (nvram_match (akm, "wep")) |
|---|
| 385 | { |
|---|
| 386 | char key[16]; |
|---|
| 387 | int cnt = 1; |
|---|
| 388 | int i; |
|---|
| 389 | char bul[8]; |
|---|
| 390 | for (i = 1; i < 5; i++) |
|---|
| 391 | { |
|---|
| 392 | sprintf (key, "%s_key%d", prefix, i); |
|---|
| 393 | char *athkey = nvram_safe_get (key); |
|---|
| 394 | if (athkey != NULL && strlen (athkey) > 0) |
|---|
| 395 | { |
|---|
| 396 | sprintf (bul, "[%d]", cnt++); |
|---|
| 397 | eval ("iwconfig", prefix, "key", bul, athkey); // setup wep encryption key |
|---|
| 398 | } |
|---|
| 399 | } |
|---|
| 400 | sprintf (key, "%s_key", prefix); |
|---|
| 401 | sprintf (bul, "[%s]", nvram_safe_get (key)); |
|---|
| 402 | eval ("iwconfig", prefix, "key", bul); |
|---|
| 403 | // eval ("iwpriv", prefix, "authmode", "2"); |
|---|
| 404 | } |
|---|
| 405 | else |
|---|
| 406 | if (nvram_match (akm, "psk") || |
|---|
| 407 | nvram_match (akm, "psk2") || nvram_match (akm, "psk psk2")) |
|---|
| 408 | { |
|---|
| 409 | char fstr[32]; |
|---|
| 410 | char psk[16]; |
|---|
| 411 | sprintf (fstr, "/tmp/%s_wpa_supplicant.conf", prefix); |
|---|
| 412 | FILE *fp = fopen (fstr, "wb"); |
|---|
| 413 | #ifdef HAVE_MAKSAT |
|---|
| 414 | fprintf (fp, "ap_scan=1\n"); |
|---|
| 415 | #elif HAVE_NEWMEDIA |
|---|
| 416 | fprintf (fp, "ap_scan=1\n"); |
|---|
| 417 | #else |
|---|
| 418 | fprintf (fp, "ap_scan=2\n"); |
|---|
| 419 | #endif |
|---|
| 420 | fprintf (fp, "fast_reauth=1\n"); |
|---|
| 421 | fprintf (fp, "eapol_version=1\n"); |
|---|
| 422 | // fprintf (fp, "ctrl_interface_group=0\n"); |
|---|
| 423 | // fprintf (fp, "ctrl_interface=/var/run/wpa_supplicant\n"); |
|---|
| 424 | |
|---|
| 425 | fprintf (fp, "network={\n"); |
|---|
| 426 | sprintf (psk, "%s_ssid", prefix); |
|---|
| 427 | if (!ssidoverride) |
|---|
| 428 | ssidoverride = nvram_safe_get (psk); |
|---|
| 429 | fprintf (fp, "\tssid=\"%s\"\n", ssidoverride); |
|---|
| 430 | // fprintf (fp, "\tmode=0\n"); |
|---|
| 431 | fprintf (fp, "\tscan_ssid=1\n"); |
|---|
| 432 | fprintf (fp, "\tkey_mgmt=WPA-PSK\n"); |
|---|
| 433 | |
|---|
| 434 | sprintf (psk, "%s_crypto", prefix); |
|---|
| 435 | if (nvram_match (psk, "aes")) |
|---|
| 436 | { |
|---|
| 437 | fprintf (fp, "\tpairwise=CCMP\n"); |
|---|
| 438 | fprintf (fp, "\tgroup=CCMP\n"); |
|---|
| 439 | } |
|---|
| 440 | if (nvram_match (psk, "tkip")) |
|---|
| 441 | { |
|---|
| 442 | fprintf (fp, "\tpairwise=TKIP\n"); |
|---|
| 443 | fprintf (fp, "\tgroup=TKIP\n"); |
|---|
| 444 | } |
|---|
| 445 | if (nvram_match (psk, "tkip+aes")) |
|---|
| 446 | { |
|---|
| 447 | fprintf (fp, "\tpairwise=CCMP TKIP\n"); |
|---|
| 448 | fprintf (fp, "\tgroup=CCMP TKIP\n"); |
|---|
| 449 | } |
|---|
| 450 | if (nvram_match (akm, "psk")) |
|---|
| 451 | fprintf (fp, "\tproto=WPA\n"); |
|---|
| 452 | if (nvram_match (akm, "psk2")) |
|---|
| 453 | fprintf (fp, "\tproto=RSN\n"); |
|---|
| 454 | if (nvram_match (akm, "psk psk2")) |
|---|
| 455 | fprintf (fp, "\tproto=WPA RSN\n"); |
|---|
| 456 | |
|---|
| 457 | sprintf (psk, "%s_wpa_psk", prefix); |
|---|
| 458 | fprintf (fp, "\tpsk=\"%s\"\n", nvram_safe_get (psk)); |
|---|
| 459 | fprintf (fp, "}\n"); |
|---|
| 460 | fclose (fp); |
|---|
| 461 | sprintf (psk, "-i%s", prefix); |
|---|
| 462 | if ((nvram_match (wmode, "wdssta") || nvram_match (wmode, "wet")) |
|---|
| 463 | && nvram_match (bridged, "1")) |
|---|
| 464 | eval ("wpa_supplicant", "-b", getBridge (prefix), "-B", "-Dmadwifi", |
|---|
| 465 | psk, "-c", fstr); |
|---|
| 466 | else |
|---|
| 467 | eval ("wpa_supplicant", "-B", "-Dmadwifi", psk, "-c", fstr); |
|---|
| 468 | } |
|---|
| 469 | else if (nvram_match (akm, "8021X")) |
|---|
| 470 | { |
|---|
| 471 | char fstr[32]; |
|---|
| 472 | char psk[64]; |
|---|
| 473 | char ath[64]; |
|---|
| 474 | sprintf (fstr, "/tmp/%s_wpa_supplicant.conf", prefix); |
|---|
| 475 | FILE *fp = fopen (fstr, "wb"); |
|---|
| 476 | #ifdef HAVE_MAKSAT |
|---|
| 477 | fprintf (fp, "ap_scan=1\n"); |
|---|
| 478 | #else |
|---|
| 479 | fprintf (fp, "ap_scan=2\n"); |
|---|
| 480 | #endif |
|---|
| 481 | fprintf (fp, "fast_reauth=1\n"); |
|---|
| 482 | fprintf (fp, "eapol_version=1\n"); |
|---|
| 483 | // fprintf (fp, "ctrl_interface_group=0\n"); |
|---|
| 484 | // fprintf (fp, "ctrl_interface=/var/run/wpa_supplicant\n"); |
|---|
| 485 | fprintf (fp, "network={\n"); |
|---|
| 486 | sprintf (psk, "%s_ssid", prefix); |
|---|
| 487 | if (!ssidoverride) |
|---|
| 488 | ssidoverride = nvram_safe_get (psk); |
|---|
| 489 | fprintf (fp, "\tssid=\"%s\"\n", ssidoverride); |
|---|
| 490 | fprintf (fp, "\tscan_ssid=1\n"); |
|---|
| 491 | if (nvram_prefix_match ("8021xtype", prefix, "tls")) |
|---|
| 492 | { |
|---|
| 493 | fprintf (fp, "\tkey_mgmt=IEEE8021X\n"); |
|---|
| 494 | fprintf (fp, "\teap=TLS\n"); |
|---|
| 495 | fprintf (fp, "\tidentity=\"%s\"\n", |
|---|
| 496 | nvram_prefix_get ("tls8021xuser", prefix)); |
|---|
| 497 | sprintf (psk, "/tmp/%s", prefix); |
|---|
| 498 | mkdir (psk); |
|---|
| 499 | sprintf (psk, "/tmp/%s/ca.pem", prefix); |
|---|
| 500 | sprintf (ath, "%s_tls8021xca", prefix); |
|---|
| 501 | write_nvram (psk, ath); |
|---|
| 502 | sprintf (psk, "/tmp/%s/user.pem", prefix); |
|---|
| 503 | sprintf (ath, "%s_tls8021xpem", prefix); |
|---|
| 504 | write_nvram (psk, ath); |
|---|
| 505 | |
|---|
| 506 | sprintf (psk, "/tmp/%s/user.prv", prefix); |
|---|
| 507 | sprintf (ath, "%s_tls8021xprv", prefix); |
|---|
| 508 | write_nvram (psk, ath); |
|---|
| 509 | fprintf (fp, "\tca_cert=/tmp/%s/ca.pem\n", prefix); |
|---|
| 510 | fprintf (fp, "\tclient_cert=/tmp/%s/user.pem\n", prefix); |
|---|
| 511 | fprintf (fp, "\tprivate_key=/tmp/%s/user.prv\n", prefix); |
|---|
| 512 | fprintf (fp, "\tprivate_key_passwd=\"%s\"\n", |
|---|
| 513 | nvram_prefix_get ("tls8021xpasswd", prefix)); |
|---|
| 514 | fprintf (fp, "\teapol_flags=3\n"); |
|---|
| 515 | } |
|---|
| 516 | if (nvram_prefix_match ("8021xtype", prefix, "peap")) |
|---|
| 517 | { |
|---|
| 518 | fprintf (fp, "\tkey_mgmt=IEEE8021X\n"); |
|---|
| 519 | fprintf (fp, "\teap=PEAP\n"); |
|---|
| 520 | fprintf (fp, "\tphase2=\"auth=MSCHAPV2\"\n"); |
|---|
| 521 | fprintf (fp, "\tidentity=\"%s\"\n", |
|---|
| 522 | nvram_prefix_get ("peap8021xuser", prefix)); |
|---|
| 523 | fprintf (fp, "\tpassword=\"%s\"\n", |
|---|
| 524 | nvram_prefix_get ("peap8021xpasswd", prefix)); |
|---|
| 525 | sprintf (psk, "/tmp/%s", prefix); |
|---|
| 526 | mkdir (psk); |
|---|
| 527 | sprintf (psk, "/tmp/%s/ca.pem", prefix); |
|---|
| 528 | sprintf (ath, "%s_peap8021xca", prefix); |
|---|
| 529 | write_nvram (psk, ath); |
|---|
| 530 | fprintf (fp, "\tca_cert=/tmp/%s/ca.pem\n", prefix); |
|---|
| 531 | } |
|---|
| 532 | if (nvram_prefix_match ("8021xtype", prefix, "leap")) |
|---|
| 533 | { |
|---|
| 534 | fprintf (fp, "\tkey_mgmt=WPA-EAP\n"); |
|---|
| 535 | fprintf (fp, "\teap=LEAP\n"); |
|---|
| 536 | fprintf (fp, "\tauth_alg=LEAP\n"); |
|---|
| 537 | fprintf (fp, "\tproto=WPA RSN\n"); |
|---|
| 538 | fprintf (fp, "\tpairwise=CCMP TKIP\n"); |
|---|
| 539 | fprintf (fp, "\tgroup=CCMP TKIP\n"); |
|---|
| 540 | fprintf (fp, "\tidentity=\"%s\"\n", |
|---|
| 541 | nvram_prefix_get ("peap8021xuser", prefix)); |
|---|
| 542 | fprintf (fp, "\tpassword=\"%s\"\n", |
|---|
| 543 | nvram_prefix_get ("peap8021xpasswd", prefix)); |
|---|
| 544 | // sprintf (psk, "/tmp/%s", prefix); |
|---|
| 545 | // mkdir (psk); |
|---|
| 546 | // sprintf (psk, "/tmp/%s/ca.pem", prefix); |
|---|
| 547 | // sprintf (ath, "%s_peap8021xca", prefix); |
|---|
| 548 | // write_nvram (psk, ath); |
|---|
| 549 | // fprintf (fp, "\tca_cert=/tmp/%s/ca.pem\n", prefix); |
|---|
| 550 | } |
|---|
| 551 | fprintf (fp, "}\n"); |
|---|
| 552 | fclose (fp); |
|---|
| 553 | sprintf (psk, "-i%s", prefix); |
|---|
| 554 | if (nvram_match (bridged, "1") |
|---|
| 555 | && (nvram_match (wmode, "wdssta") || nvram_match (wmode, "wet"))) |
|---|
| 556 | eval ("wpa_supplicant", "-b", nvram_safe_get ("lan_ifname"), "-B", |
|---|
| 557 | "-Dmadwifi", psk, "-c", fstr); |
|---|
| 558 | else |
|---|
| 559 | eval ("wpa_supplicant", "-B", "-Dmadwifi", psk, "-c", fstr); |
|---|
| 560 | } |
|---|
| 561 | else |
|---|
| 562 | { |
|---|
| 563 | eval ("iwconfig", prefix, "key", "off"); |
|---|
| 564 | // eval ("iwpriv", prefix, "authmode", "0"); |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | } |
|---|
| 569 | void |
|---|
| 570 | supplicant_main (int argc, char *argv[]) |
|---|
| 571 | { |
|---|
| 572 | setupSupplicant (argv[1], argv[2]); |
|---|
| 573 | } |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | void |
|---|
| 577 | setupHostAP (char *prefix, int iswan) |
|---|
| 578 | { |
|---|
| 579 | char psk[32]; |
|---|
| 580 | char akm[16]; |
|---|
| 581 | sprintf (akm, "%s_akm", prefix); |
|---|
| 582 | if (nvram_match (akm, "wpa") || nvram_match (akm, "wpa2") |
|---|
| 583 | || nvram_match (akm, "wpa wpa2") || nvram_match (akm, "radius")) |
|---|
| 584 | { |
|---|
| 585 | if (iswan == 0) |
|---|
| 586 | return; |
|---|
| 587 | } |
|---|
| 588 | if (nvram_match (akm, "psk") || |
|---|
| 589 | nvram_match (akm, "psk2") || |
|---|
| 590 | nvram_match (akm, "psk psk2") || nvram_match (akm, "wep")) |
|---|
| 591 | { |
|---|
| 592 | if (iswan == 1) |
|---|
| 593 | return; |
|---|
| 594 | } |
|---|
| 595 | //wep key support |
|---|
| 596 | if (nvram_match (akm, "wep")) |
|---|
| 597 | { |
|---|
| 598 | char key[16]; |
|---|
| 599 | int cnt = 1; |
|---|
| 600 | int i; |
|---|
| 601 | char bul[8]; |
|---|
| 602 | for (i = 1; i < 5; i++) |
|---|
| 603 | { |
|---|
| 604 | sprintf (key, "%s_key%d", prefix, i); |
|---|
| 605 | char *athkey = nvram_safe_get (key); |
|---|
| 606 | if (athkey != NULL && strlen (athkey) > 0) |
|---|
| 607 | { |
|---|
| 608 | sprintf (bul, "[%d]", cnt++); |
|---|
| 609 | eval ("iwconfig", prefix, "key", bul, athkey); // setup wep encryption key |
|---|
| 610 | } |
|---|
| 611 | } |
|---|
| 612 | sprintf (key, "%s_key", prefix); |
|---|
| 613 | sprintf (bul, "[%s]", nvram_safe_get (key)); |
|---|
| 614 | eval ("iwconfig", prefix, "key", bul); |
|---|
| 615 | // eval ("iwpriv", prefix, "authmode", "2"); |
|---|
| 616 | } |
|---|
| 617 | else |
|---|
| 618 | if (nvram_match (akm, "psk") || |
|---|
| 619 | nvram_match (akm, "psk2") || |
|---|
| 620 | nvram_match (akm, "psk psk2") || |
|---|
| 621 | nvram_match (akm, "wpa") || |
|---|
| 622 | nvram_match (akm, "wpa2") || nvram_match (akm, "wpa wpa2")) |
|---|
| 623 | { |
|---|
| 624 | char fstr[32]; |
|---|
| 625 | sprintf (fstr, "/tmp/%s_hostap.conf", prefix); |
|---|
| 626 | FILE *fp = fopen (fstr, "wb"); |
|---|
| 627 | fprintf (fp, "interface=%s\n", prefix); |
|---|
| 628 | //sprintf(buf, "rsn_preauth_interfaces=%s\n", "br0"); |
|---|
| 629 | char bvar[32]; |
|---|
| 630 | sprintf (bvar, "%s_bridged", prefix); |
|---|
| 631 | if (nvram_match (bvar, "1")) |
|---|
| 632 | fprintf (fp, "bridge=%s\n", getBridge (prefix)); |
|---|
| 633 | |
|---|
| 634 | fprintf (fp, "driver=madwifi\n"); |
|---|
| 635 | fprintf (fp, "logger_syslog=-1\n"); |
|---|
| 636 | fprintf (fp, "logger_syslog_level=2\n"); |
|---|
| 637 | fprintf (fp, "logger_stdout=-1\n"); |
|---|
| 638 | fprintf (fp, "logger_stdout_level=2\n"); |
|---|
| 639 | fprintf (fp, "debug=0\n"); |
|---|
| 640 | fprintf (fp, "dump_file=/tmp/hostapd.dump\n"); |
|---|
| 641 | // fprintf (fp, "eap_server=0\n"); |
|---|
| 642 | // fprintf (fp, "own_ip_addr=127.0.0.1\n"); |
|---|
| 643 | fprintf (fp, "eapol_version=1\n"); |
|---|
| 644 | fprintf (fp, "eapol_key_index_workaround=0\n"); |
|---|
| 645 | if (nvram_match (akm, "psk") || nvram_match (akm, "wpa")) |
|---|
| 646 | fprintf (fp, "wpa=1\n"); |
|---|
| 647 | if (nvram_match (akm, "psk2") || nvram_match (akm, "wpa2")) |
|---|
| 648 | fprintf (fp, "wpa=2\n"); |
|---|
| 649 | if (nvram_match (akm, "psk psk2") || nvram_match (akm, "wpa wpa2")) |
|---|
| 650 | fprintf (fp, "wpa=3\n"); |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | if (nvram_match (akm, "psk") || |
|---|
| 654 | nvram_match (akm, "psk2") || nvram_match (akm, "psk psk2")) |
|---|
| 655 | { |
|---|
| 656 | sprintf (psk, "%s_wpa_psk", prefix); |
|---|
| 657 | fprintf (fp, "wpa_passphrase=%s\n", nvram_safe_get (psk)); |
|---|
| 658 | fprintf (fp, "wpa_key_mgmt=WPA-PSK\n"); |
|---|
| 659 | } |
|---|
| 660 | else |
|---|
| 661 | { |
|---|
| 662 | // if (nvram_invmatch (akm, "radius")) |
|---|
| 663 | fprintf (fp, "wpa_key_mgmt=WPA-EAP\n"); |
|---|
| 664 | // else |
|---|
| 665 | // fprintf (fp, "macaddr_acl=2\n"); |
|---|
| 666 | fprintf (fp, "ieee8021x=1\n"); |
|---|
| 667 | // fprintf (fp, "accept_mac_file=/tmp/hostapd.accept\n"); |
|---|
| 668 | // fprintf (fp, "deny_mac_file=/tmp/hostapd.deny\n"); |
|---|
| 669 | fprintf (fp, "own_ip_addr=%s\n", nvram_safe_get ("lan_ipaddr")); |
|---|
| 670 | fprintf (fp, "eap_server=0\n"); |
|---|
| 671 | fprintf (fp, "auth_algs=1\n"); |
|---|
| 672 | fprintf (fp, "radius_retry_primary_interval=60\n"); |
|---|
| 673 | sprintf (psk, "%s_radius_ipaddr", prefix); |
|---|
| 674 | fprintf (fp, "auth_server_addr=%s\n", nvram_safe_get (psk)); |
|---|
| 675 | |
|---|
| 676 | sprintf (psk, "%s_radius_port", prefix); |
|---|
| 677 | fprintf (fp, "auth_server_port=%s\n", nvram_safe_get (psk)); |
|---|
| 678 | |
|---|
| 679 | sprintf (psk, "%s_radius_key", prefix); |
|---|
| 680 | fprintf (fp, "auth_server_shared_secret=%s\n", |
|---|
| 681 | nvram_safe_get (psk)); |
|---|
| 682 | } |
|---|
| 683 | if (nvram_invmatch (akm, "radius")) |
|---|
| 684 | { |
|---|
| 685 | sprintf (psk, "%s_crypto", prefix); |
|---|
| 686 | if (nvram_match (psk, "aes")) |
|---|
| 687 | fprintf (fp, "wpa_pairwise=CCMP\n"); |
|---|
| 688 | if (nvram_match (psk, "tkip")) |
|---|
| 689 | fprintf (fp, "wpa_pairwise=TKIP\n"); |
|---|
| 690 | if (nvram_match (psk, "tkip+aes")) |
|---|
| 691 | fprintf (fp, "wpa_pairwise=TKIP CCMP\n"); |
|---|
| 692 | sprintf (psk, "%s_wpa_gtk_rekey", prefix); |
|---|
| 693 | fprintf (fp, "wpa_group_rekey=%s\n", nvram_safe_get (psk)); |
|---|
| 694 | } |
|---|
| 695 | // fprintf (fp, "jumpstart_p1=1\n"); |
|---|
| 696 | fclose (fp); |
|---|
| 697 | eval ("hostapd", "-B", fstr); |
|---|
| 698 | } |
|---|
| 699 | else if (nvram_match (akm, "radius")) |
|---|
| 700 | { |
|---|
| 701 | // wrt-radauth $IFNAME $server $port $share $override $mackey $maxun & |
|---|
| 702 | char *ifname = prefix; |
|---|
| 703 | sprintf (psk, "%s_radius_ipaddr", prefix); |
|---|
| 704 | char *server = nvram_safe_get (psk); |
|---|
| 705 | sprintf (psk, "%s_radius_port", prefix); |
|---|
| 706 | char *port = nvram_safe_get (psk); |
|---|
| 707 | sprintf (psk, "%s_radius_key", prefix); |
|---|
| 708 | char *share = nvram_safe_get (psk); |
|---|
| 709 | char exec[64]; |
|---|
| 710 | char type[32]; |
|---|
| 711 | sprintf (type, "%s_radmactype", prefix); |
|---|
| 712 | char *pragma = ""; |
|---|
| 713 | if (default_match (type, "0", "0")) |
|---|
| 714 | pragma = "-n1 "; |
|---|
| 715 | if (nvram_match (type, "1")) |
|---|
| 716 | pragma = "-n2 "; |
|---|
| 717 | if (nvram_match (type, "2")) |
|---|
| 718 | pragma = "-n3 "; |
|---|
| 719 | if (nvram_match (type, "3")) |
|---|
| 720 | pragma = ""; |
|---|
| 721 | sleep (1); //some delay is usefull |
|---|
| 722 | sprintf (exec, "wrt-radauth %s %s %s %s %s 1 1 0 &", pragma, prefix, |
|---|
| 723 | server, port, share); |
|---|
| 724 | system2 (exec); |
|---|
| 725 | |
|---|
| 726 | // eval("wrt-radauth",prefix,server,port,share,"1","1","0"); |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | } |
|---|
| 730 | else |
|---|
| 731 | { |
|---|
| 732 | eval ("iwconfig", prefix, "key", "off"); |
|---|
| 733 | // eval ("iwpriv", prefix, "authmode", "0"); |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | } |
|---|
| 738 | void |
|---|
| 739 | start_hostapdwan (void) |
|---|
| 740 | { |
|---|
| 741 | char ath[32]; |
|---|
| 742 | char wifivifs[16]; |
|---|
| 743 | char *next; |
|---|
| 744 | char var[80]; |
|---|
| 745 | int c = getdevicecount (); |
|---|
| 746 | int i; |
|---|
| 747 | for (i = 0; i < c; i++) |
|---|
| 748 | { |
|---|
| 749 | sprintf (ath, "ath%d", i); |
|---|
| 750 | setupHostAP (ath, 1); |
|---|
| 751 | sprintf (wifivifs, "ath%d_vifs", i); |
|---|
| 752 | char *vifs = nvram_safe_get (wifivifs); |
|---|
| 753 | if (vifs != NULL) |
|---|
| 754 | foreach (var, vifs, next) |
|---|
| 755 | { |
|---|
| 756 | setupHostAP (var, 1); |
|---|
| 757 | } |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | #define SIOCSSCANLIST (SIOCDEVPRIVATE+6) |
|---|
| 763 | #ifdef MADWIFI_OLD |
|---|
| 764 | static void |
|---|
| 765 | set_scanlist (char *dev, char *wif) |
|---|
| 766 | { |
|---|
| 767 | |
|---|
| 768 | char *next; |
|---|
| 769 | struct iwreq iwr; |
|---|
| 770 | char scanlist[32]; |
|---|
| 771 | unsigned short list[1024]; |
|---|
| 772 | sprintf (scanlist, "%s_scanlist", dev); |
|---|
| 773 | char *sl = default_get (scanlist, "default"); |
|---|
| 774 | memset (list, 0, 1024 * sizeof (unsigned short)); |
|---|
| 775 | int c = 0; |
|---|
| 776 | if (strlen (sl) > 0 && strcmp (sl, "default")) |
|---|
| 777 | { |
|---|
| 778 | foreach (var, sl, next) |
|---|
| 779 | { |
|---|
| 780 | int ch = atoi (var); |
|---|
| 781 | if (ch < 1000 || ch > 7000) |
|---|
| 782 | { |
|---|
| 783 | c = 1; |
|---|
| 784 | break; |
|---|
| 785 | } |
|---|
| 786 | u_int16_t chan = ch; |
|---|
| 787 | |
|---|
| 788 | // fprintf(stderr,"scanlist %d\n",chan); |
|---|
| 789 | list[c++] = chan; |
|---|
| 790 | } |
|---|
| 791 | } |
|---|
| 792 | else |
|---|
| 793 | c = 1; |
|---|
| 794 | |
|---|
| 795 | memset (&iwr, 0, sizeof (struct iwreq)); |
|---|
| 796 | strncpy (iwr.ifr_name, wif, IFNAMSIZ); |
|---|
| 797 | { |
|---|
| 798 | /* |
|---|
| 799 | * Argument data too big for inline transfer; setup a |
|---|
| 800 | * parameter block instead; the kernel will transfer |
|---|
| 801 | * the data for the driver. |
|---|
| 802 | */ |
|---|
| 803 | iwr.u.data.pointer = &list[0]; |
|---|
| 804 | iwr.u.data.length = 1024 * sizeof (unsigned short); |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | int r = ioctl (getsocket (), SIOCSSCANLIST, &iwr); |
|---|
| 808 | if (r < 0) |
|---|
| 809 | { |
|---|
| 810 | fprintf (stderr, "error while setting scanlist on %s, %d\n", wif, r); |
|---|
| 811 | } |
|---|
| 812 | } |
|---|
| 813 | #else |
|---|
| 814 | static void |
|---|
| 815 | set_scanlist (char *dev, char *wif) |
|---|
| 816 | { |
|---|
| 817 | char var[32]; |
|---|
| 818 | char *next; |
|---|
| 819 | struct iwreq iwr; |
|---|
| 820 | char scanlist[32]; |
|---|
| 821 | unsigned short list[64]; |
|---|
| 822 | sprintf (scanlist, "%s_scanlist", dev); |
|---|
| 823 | char *sl = default_get (scanlist, "default"); |
|---|
| 824 | int c = 0; |
|---|
| 825 | eval("iwpriv",dev,"setscanlist","-ALL"); |
|---|
| 826 | if (strlen (sl) > 0 && strcmp (sl, "default")) |
|---|
| 827 | { |
|---|
| 828 | foreach (var, sl, next) |
|---|
| 829 | { |
|---|
| 830 | sprintf(list,"+%s",var); |
|---|
| 831 | eval("iwpriv",dev,"setscanlist",list); |
|---|
| 832 | } |
|---|
| 833 | } |
|---|
| 834 | else |
|---|
| 835 | { |
|---|
| 836 | eval("iwpriv",dev,"setscanlist","+ALL"); |
|---|
| 837 | } |
|---|
| 838 | } |
|---|
| 839 | #endif |
|---|
| 840 | |
|---|
| 841 | static void |
|---|
| 842 | set_rate (char *dev) |
|---|
| 843 | { |
|---|
| 844 | char rate[32]; |
|---|
| 845 | char maxrate[32]; |
|---|
| 846 | char net[32]; |
|---|
| 847 | char bw[32]; |
|---|
| 848 | char xr[32]; |
|---|
| 849 | char turbo[32]; |
|---|
| 850 | |
|---|
| 851 | sprintf (bw, "%s_channelbw", dev); |
|---|
| 852 | sprintf (net, "%s_net_mode", dev); |
|---|
| 853 | sprintf (rate, "%s_minrate", dev); |
|---|
| 854 | sprintf (maxrate, "%s_maxrate", dev); |
|---|
| 855 | sprintf (xr, "%s_xr", dev); |
|---|
| 856 | sprintf (turbo, "%s_turbo", dev); |
|---|
| 857 | char *r = default_get (rate, "0"); |
|---|
| 858 | char *mr = default_get (maxrate, "0"); |
|---|
| 859 | #ifdef HAVE_WHRAG108 |
|---|
| 860 | char *netmode; |
|---|
| 861 | if (!strcmp (dev, "ath0")) |
|---|
| 862 | netmode = default_get (net, "a-only"); |
|---|
| 863 | else |
|---|
| 864 | netmode = default_get (net, "mixed"); |
|---|
| 865 | #else |
|---|
| 866 | char *netmode = default_get (net, "mixed"); |
|---|
| 867 | #endif |
|---|
| 868 | |
|---|
| 869 | if (nvram_match (bw, "20") && nvram_match (xr, "0")) |
|---|
| 870 | if (atof (r) == 27.0f || atof (r) == 1.5f || atof (r) == 2.0f |
|---|
| 871 | || atof (r) == 3.0f || atof (r) == 4.5f || atof (r) == 9.0f |
|---|
| 872 | || atof (r) == 13.5f) |
|---|
| 873 | { |
|---|
| 874 | nvram_set (rate, "0"); |
|---|
| 875 | r = "0"; |
|---|
| 876 | } |
|---|
| 877 | if (nvram_match (turbo, "1")) |
|---|
| 878 | if (atof (r) == 27.0f || atof (r) == 1.5f || atof (r) == 2.0f |
|---|
| 879 | || atof (r) == 3.0f || atof (r) == 4.5f || atof (r) == 9.0f |
|---|
| 880 | || atof (r) == 13.5f) |
|---|
| 881 | { |
|---|
| 882 | nvram_set (rate, "0"); |
|---|
| 883 | r = "0"; |
|---|
| 884 | } |
|---|
| 885 | if (nvram_match (bw, "10")) |
|---|
| 886 | if (atof (r) > 27.0f || atof (r) == 1.5f || atof (r) == 2.0f |
|---|
| 887 | || atof (r) == 13.5f) |
|---|
| 888 | { |
|---|
| 889 | nvram_set (rate, "0"); |
|---|
| 890 | r = "0"; |
|---|
| 891 | } |
|---|
| 892 | if (nvram_match (bw, "5")) |
|---|
| 893 | if (atof (r) > 13.5) |
|---|
| 894 | { |
|---|
| 895 | nvram_set (rate, "0"); |
|---|
| 896 | r = "0"; |
|---|
| 897 | } |
|---|
| 898 | if (!strcmp (netmode, "b-only")) |
|---|
| 899 | eval ("iwconfig", dev, "rate", "11M", "auto"); |
|---|
| 900 | else |
|---|
| 901 | { |
|---|
| 902 | /* if (nvram_match (bw, "5")) |
|---|
| 903 | eval ("iwconfig", dev, "rate", "13500", "auto"); |
|---|
| 904 | else if (nvram_match (bw, "10")) |
|---|
| 905 | eval ("iwconfig", dev, "rate", "27000", "auto"); |
|---|
| 906 | else*/ |
|---|
| 907 | eval ("iwconfig", dev, "rate", "54M", "auto"); |
|---|
| 908 | } |
|---|
| 909 | if (atol (mr) > 0) |
|---|
| 910 | eval ("iwpriv", dev, "maxrate", mr); |
|---|
| 911 | if (atoi (mr) > 0) |
|---|
| 912 | eval ("iwpriv", dev, "minrate", r); |
|---|
| 913 | } |
|---|
| 914 | static void |
|---|
| 915 | set_netmode (char *wif, char *dev, char *use) |
|---|
| 916 | { |
|---|
| 917 | char net[16]; |
|---|
| 918 | char turbo[16]; |
|---|
| 919 | char mode[16]; |
|---|
| 920 | char xr[16]; |
|---|
| 921 | char comp[32]; |
|---|
| 922 | char ff[16]; |
|---|
| 923 | sprintf (mode, "%s_mode", dev); |
|---|
| 924 | sprintf (net, "%s_net_mode", dev); |
|---|
| 925 | sprintf (turbo, "%s_turbo", dev); |
|---|
| 926 | sprintf (xr, "%s_xr", dev); |
|---|
| 927 | sprintf (comp, "%s_compression", dev); |
|---|
| 928 | sprintf (ff, "%s_ff", dev); |
|---|
| 929 | #ifdef HAVE_WHRAG108 |
|---|
| 930 | char *netmode; |
|---|
| 931 | if (!strcmp (dev, "ath0")) |
|---|
| 932 | netmode = default_get (net, "a-only"); |
|---|
| 933 | else |
|---|
| 934 | netmode = default_get (net, "mixed"); |
|---|
| 935 | #else |
|---|
| 936 | char *netmode = default_get (net, "mixed"); |
|---|
| 937 | #endif |
|---|
| 938 | // fprintf (stderr, "set netmode of %s to %s\n", net, netmode); |
|---|
| 939 | cprintf ("configure net mode %s\n", netmode); |
|---|
| 940 | |
|---|
| 941 | // eval ("iwconfig", use, "channel", "0"); |
|---|
| 942 | // else |
|---|
| 943 | { |
|---|
| 944 | #ifdef HAVE_WHRAG108 |
|---|
| 945 | if (!strncmp (use, "ath0", 4)) |
|---|
| 946 | { |
|---|
| 947 | eval ("iwpriv", use, "mode", "1"); |
|---|
| 948 | } |
|---|
| 949 | else |
|---|
| 950 | #endif |
|---|
| 951 | #ifdef HAVE_TW6600 |
|---|
| 952 | if (!strncmp (use, "ath0", 4)) |
|---|
| 953 | { |
|---|
| 954 | eval ("iwpriv", use, "mode", "1"); |
|---|
| 955 | } |
|---|
| 956 | else |
|---|
| 957 | #endif |
|---|
| 958 | { |
|---|
| 959 | eval ("iwpriv", use, "turbo", "0"); |
|---|
| 960 | eval ("iwpriv", use, "xr", "0"); |
|---|
| 961 | if (!strcmp (netmode, "mixed")) |
|---|
| 962 | eval ("iwpriv", use, "mode", "0"); |
|---|
| 963 | if (!strcmp (netmode, "b-only")) |
|---|
| 964 | eval ("iwpriv", use, "mode", "2"); |
|---|
| 965 | if (!strcmp (netmode, "g-only")) |
|---|
| 966 | { |
|---|
| 967 | eval ("iwpriv", use, "mode", "3"); |
|---|
| 968 | eval ("iwpriv", use, "pureg", "1"); |
|---|
| 969 | } |
|---|
| 970 | if (!strcmp (netmode, "ng-only")) |
|---|
| 971 | { |
|---|
| 972 | eval ("iwpriv", use, "mode", "7"); |
|---|
| 973 | } |
|---|
| 974 | if (!strcmp (netmode, "na-only")) |
|---|
| 975 | { |
|---|
| 976 | eval ("iwpriv", use, "mode", "6"); |
|---|
| 977 | } |
|---|
| 978 | if (!strcmp (netmode, "bg-mixed")) |
|---|
| 979 | { |
|---|
| 980 | eval ("iwpriv", use, "mode", "3"); |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | if (!strcmp (netmode, "a-only")) |
|---|
| 984 | eval ("iwpriv", use, "mode", "1"); |
|---|
| 985 | } |
|---|
| 986 | } |
|---|
| 987 | if (default_match (turbo, "1", "0")) |
|---|
| 988 | { |
|---|
| 989 | { |
|---|
| 990 | if (!strcmp (netmode, "g-only")) |
|---|
| 991 | { |
|---|
| 992 | eval ("iwpriv", use, "mode", "6"); |
|---|
| 993 | } |
|---|
| 994 | if (!strcmp (netmode, "a-only")) |
|---|
| 995 | { |
|---|
| 996 | eval ("iwpriv", use, "mode", "5"); |
|---|
| 997 | } |
|---|
| 998 | eval ("iwpriv", use, "turbo", "1"); |
|---|
| 999 | } |
|---|
| 1000 | } |
|---|
| 1001 | else |
|---|
| 1002 | { |
|---|
| 1003 | char *ext = nvram_get (xr); |
|---|
| 1004 | if (ext) |
|---|
| 1005 | { |
|---|
| 1006 | if (strcmp (ext, "1") == 0) |
|---|
| 1007 | { |
|---|
| 1008 | eval ("iwpriv", use, "xr", "1"); |
|---|
| 1009 | } |
|---|
| 1010 | else |
|---|
| 1011 | { |
|---|
| 1012 | eval ("iwpriv", use, "xr", "0"); |
|---|
| 1013 | } |
|---|
| 1014 | } |
|---|
| 1015 | } |
|---|
| 1016 | if (default_match (comp, "1", "0")) |
|---|
| 1017 | eval ("iwpriv", use, "compression", "1"); |
|---|
| 1018 | else |
|---|
| 1019 | eval ("iwpriv", use, "compression", "0"); |
|---|
| 1020 | |
|---|
| 1021 | if (default_match (ff, "1", "0")) |
|---|
| 1022 | eval ("iwpriv", use, "ff", "1"); |
|---|
| 1023 | else |
|---|
| 1024 | eval ("iwpriv", use, "ff", "0"); |
|---|
| 1025 | |
|---|
| 1026 | |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | static |
|---|
| 1030 | set_compression (int count) |
|---|
| 1031 | { |
|---|
| 1032 | char comp[32]; |
|---|
| 1033 | char wif[32]; |
|---|
| 1034 | sprintf (wif, "wifi%d", count); |
|---|
| 1035 | sprintf (comp, "ath%d_compression", count); |
|---|
| 1036 | if (default_match (comp, "1", "0")) |
|---|
| 1037 | setsysctrl (wif, "compression", 1); |
|---|
| 1038 | else |
|---|
| 1039 | setsysctrl (wif, "compression", 0); |
|---|
| 1040 | } |
|---|
| 1041 | |
|---|
| 1042 | void |
|---|
| 1043 | setMacFilter (char *iface) |
|---|
| 1044 | { |
|---|
| 1045 | char *next; |
|---|
| 1046 | char var[32]; |
|---|
| 1047 | eval ("ifconfig", iface, "down"); |
|---|
| 1048 | eval ("iwpriv", iface, "maccmd", "3"); |
|---|
| 1049 | // set80211param (iface, IEEE80211_PARAM_MACCMD, IEEE80211_MACCMD_FLUSH); |
|---|
| 1050 | |
|---|
| 1051 | char nvvar[32]; |
|---|
| 1052 | sprintf (nvvar, "%s_macmode", iface); |
|---|
| 1053 | if (nvram_match (nvvar, "deny")) |
|---|
| 1054 | { |
|---|
| 1055 | eval ("iwpriv", iface, "maccmd", "2"); |
|---|
| 1056 | // set80211param (iface, IEEE80211_PARAM_MACCMD, |
|---|
| 1057 | // IEEE80211_MACCMD_POLICY_DENY); |
|---|
| 1058 | eval ("ifconfig", iface, "up"); |
|---|
| 1059 | char nvlist[32]; |
|---|
| 1060 | sprintf (nvlist, "%s_maclist", iface); |
|---|
| 1061 | |
|---|
| 1062 | foreach (var, nvram_safe_get (nvlist), next) |
|---|
| 1063 | { |
|---|
| 1064 | eval ("iwpriv", iface, "addmac", var); |
|---|
| 1065 | /* char ea[ETHER_ADDR_LEN]; |
|---|
| 1066 | if (ether_atoe (var, ea)) |
|---|
| 1067 | { |
|---|
| 1068 | struct sockaddr sa; |
|---|
| 1069 | memcpy (sa.sa_data, ea, IEEE80211_ADDR_LEN); |
|---|
| 1070 | do80211priv (iface, IEEE80211_IOCTL_ADDMAC, &sa, |
|---|
| 1071 | sizeof (struct sockaddr)); |
|---|
| 1072 | }*/ |
|---|
| 1073 | } |
|---|
| 1074 | } |
|---|
| 1075 | if (nvram_match (nvvar, "allow")) |
|---|
| 1076 | { |
|---|
| 1077 | eval ("iwpriv", iface, "maccmd", "1"); |
|---|
| 1078 | // set80211param (iface, IEEE80211_PARAM_MACCMD, |
|---|
| 1079 | // IEEE80211_MACCMD_POLICY_ALLOW); |
|---|
| 1080 | eval ("ifconfig", iface, "up"); |
|---|
| 1081 | char nvlist[32]; |
|---|
| 1082 | sprintf (nvlist, "%s_maclist", iface); |
|---|
| 1083 | |
|---|
| 1084 | foreach (var, nvram_safe_get (nvlist), next) |
|---|
| 1085 | { |
|---|
| 1086 | eval ("iwpriv", iface, "addmac", var); |
|---|
| 1087 | /* char ea[ETHER_ADDR_LEN]; |
|---|
| 1088 | if (ether_atoe (var, ea)) |
|---|
| 1089 | { |
|---|
| 1090 | struct sockaddr sa; |
|---|
| 1091 | memcpy (sa.sa_data, ea, IEEE80211_ADDR_LEN); |
|---|
| 1092 | do80211priv (iface, IEEE80211_IOCTL_ADDMAC, &sa, |
|---|
| 1093 | sizeof (struct sockaddr)); |
|---|
| 1094 | }*/ |
|---|
| 1095 | } |
|---|
| 1096 | } |
|---|
| 1097 | |
|---|
| 1098 | } |
|---|
| 1099 | |
|---|
| 1100 | #define IFUP (IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST) |
|---|
| 1101 | |
|---|
| 1102 | |
|---|
| 1103 | static void |
|---|
| 1104 | configure_single (int count) |
|---|
| 1105 | { |
|---|
| 1106 | char *next; |
|---|
| 1107 | char var[80]; |
|---|
| 1108 | char mode[80]; |
|---|
| 1109 | int cnt = 0; |
|---|
| 1110 | char dev[10]; |
|---|
| 1111 | char wif[10]; |
|---|
| 1112 | char wl[16]; |
|---|
| 1113 | char channel[16]; |
|---|
| 1114 | char ssid[16]; |
|---|
| 1115 | char net[16]; |
|---|
| 1116 | char wifivifs[16]; |
|---|
| 1117 | char broadcast[16]; |
|---|
| 1118 | char power[32]; |
|---|
| 1119 | char sens[32]; |
|---|
| 1120 | char basedev[16]; |
|---|
| 1121 | char diversity[32]; |
|---|
| 1122 | char rxantenna[32]; |
|---|
| 1123 | char txantenna[32]; |
|---|
| 1124 | char athmac[16]; |
|---|
| 1125 | char turbo[16]; |
|---|
| 1126 | sprintf (wif, "wifi%d", count); |
|---|
| 1127 | sprintf (dev, "ath%d", count); |
|---|
| 1128 | sprintf (turbo, "%s_turbo", dev); |
|---|
| 1129 | sprintf (wifivifs, "ath%d_vifs", count); |
|---|
| 1130 | sprintf (wl, "ath%d_mode", count); |
|---|
| 1131 | sprintf (channel, "ath%d_channel", count); |
|---|
| 1132 | sprintf (power, "ath%d_txpwrdbm", count); |
|---|
| 1133 | sprintf (sens, "ath%d_distance", count); |
|---|
| 1134 | sprintf (diversity, "ath%d_diversity", count); |
|---|
| 1135 | sprintf (txantenna, "ath%d_txantenna", count); |
|---|
| 1136 | sprintf (rxantenna, "ath%d_rxantenna", count); |
|---|
| 1137 | sprintf (athmac, "ath%d_hwaddr", count); |
|---|
| 1138 | //create base device |
|---|
| 1139 | cprintf ("configure base interface %d\n", count); |
|---|
| 1140 | eval ("ifconfig", wif, "up"); |
|---|
| 1141 | sprintf (net, "%s_net_mode", dev); |
|---|
| 1142 | if (nvram_match (net, "disabled")) |
|---|
| 1143 | return; |
|---|
| 1144 | if (!count) |
|---|
| 1145 | strcpy (iflist, dev); |
|---|
| 1146 | set_compression (count); |
|---|
| 1147 | //create wds interface(s) |
|---|
| 1148 | int s; |
|---|
| 1149 | |
|---|
| 1150 | char *m; |
|---|
| 1151 | int vif = 0; |
|---|
| 1152 | |
|---|
| 1153 | |
|---|
| 1154 | |
|---|
| 1155 | char *vifs = nvram_safe_get (wifivifs); |
|---|
| 1156 | if (vifs != NULL) |
|---|
| 1157 | foreach (var, vifs, next) |
|---|
| 1158 | { |
|---|
| 1159 | sprintf (mode, "%s_mode", var); |
|---|
| 1160 | m = default_get (mode, "ap"); |
|---|
| 1161 | //create device |
|---|
| 1162 | if (strlen (mode) > 0) |
|---|
| 1163 | { |
|---|
| 1164 | if (!strcmp (m, "wet") || !strcmp (m, "sta") |
|---|
| 1165 | || !strcmp (m, "wdssta")) |
|---|
| 1166 | eval ("wlanconfig", var, "create", "wlandev", wif, "wlanmode", |
|---|
| 1167 | "sta", "nosbeacon"); |
|---|
| 1168 | else if (!strcmp (m, "ap") || !strcmp (m, "wdsap")) |
|---|
| 1169 | eval ("wlanconfig", var, "create", "wlandev", wif, "wlanmode", |
|---|
| 1170 | "ap"); |
|---|
| 1171 | else |
|---|
| 1172 | eval ("wlanconfig", var, "create", "wlandev", wif, "wlanmode", |
|---|
| 1173 | "adhoc"); |
|---|
| 1174 | vif = 1; |
|---|
| 1175 | strcat (iflist, " "); |
|---|
| 1176 | strcat (iflist, var); |
|---|
| 1177 | char vathmac[16]; |
|---|
| 1178 | sprintf (vathmac, "%s_hwaddr", var); |
|---|
| 1179 | char vmacaddr[32]; |
|---|
| 1180 | getMacAddr (var, vmacaddr); |
|---|
| 1181 | nvram_set (vathmac, vmacaddr); |
|---|
| 1182 | |
|---|
| 1183 | } |
|---|
| 1184 | } |
|---|
| 1185 | |
|---|
| 1186 | |
|---|
| 1187 | //create original primary interface |
|---|
| 1188 | m = default_get (wl, "ap"); |
|---|
| 1189 | |
|---|
| 1190 | if (!strcmp (m, "wet") || !strcmp (m, "wdssta") || !strcmp (m, "sta")) |
|---|
| 1191 | { |
|---|
| 1192 | if (vif) |
|---|
| 1193 | eval ("wlanconfig", dev, "create", "wlandev", wif, "wlanmode", "sta", |
|---|
| 1194 | "nosbeacon"); |
|---|
| 1195 | else |
|---|
| 1196 | eval ("wlanconfig", dev, "create", "wlandev", wif, "wlanmode", "sta"); |
|---|
| 1197 | |
|---|
| 1198 | } |
|---|
| 1199 | else if (!strcmp (m, "ap") || !strcmp (m, "wdsap")) |
|---|
| 1200 | eval ("wlanconfig", dev, "create", "wlandev", wif, "wlanmode", "ap"); |
|---|
| 1201 | else |
|---|
| 1202 | eval ("wlanconfig", dev, "create", "wlandev", wif, "wlanmode", "adhoc"); |
|---|
| 1203 | |
|---|
| 1204 | |
|---|
| 1205 | for (s = 1; s <= 10; s++) |
|---|
| 1206 | { |
|---|
| 1207 | char wdsvarname[32] = { 0 }; |
|---|
| 1208 | char wdsdevname[32] = { 0 }; |
|---|
| 1209 | char wdsmacname[32] = { 0 }; |
|---|
| 1210 | char *wdsdev; |
|---|
| 1211 | char *hwaddr; |
|---|
| 1212 | |
|---|
| 1213 | sprintf (wdsvarname, "%s_wds%d_enable", dev, s); |
|---|
| 1214 | sprintf (wdsdevname, "%s_wds%d_if", dev, s); |
|---|
| 1215 | sprintf (wdsmacname, "%s_wds%d_hwaddr", dev, s); |
|---|
| 1216 | wdsdev = nvram_safe_get (wdsdevname); |
|---|
| 1217 | if (strlen (wdsdev) == 0) |
|---|
| 1218 | continue; |
|---|
| 1219 | if (nvram_match (wdsvarname, "0")) |
|---|
| 1220 | continue; |
|---|
| 1221 | hwaddr = nvram_get (wdsmacname); |
|---|
| 1222 | if (hwaddr != NULL) |
|---|
| 1223 | { |
|---|
| 1224 | #ifdef OLD_MADWIFI |
|---|
| 1225 | eval ("wlanconfig", wdsdev, "create", "wlandev", wif, "wlanmode", |
|---|
| 1226 | "wds", "nobssid"); |
|---|
| 1227 | eval ("ifconfig", wdsdev, "0.0.0.0", "up"); |
|---|
| 1228 | eval ("iwpriv", wdsdev, "wds_add", hwaddr); |
|---|
| 1229 | eval ("iwpriv", wdsdev, "wds", "1"); |
|---|
| 1230 | #else |
|---|
| 1231 | eval ("iwpriv", dev, "wds_add", hwaddr); |
|---|
| 1232 | // eval ("iwpriv", dev, "wds", "1"); |
|---|
| 1233 | #endif |
|---|
| 1234 | } |
|---|
| 1235 | } |
|---|
| 1236 | |
|---|
| 1237 | |
|---|
| 1238 | |
|---|
| 1239 | cprintf ("detect maxpower\n"); |
|---|
| 1240 | m = default_get (wl, "ap"); |
|---|
| 1241 | char maxp[16]; |
|---|
| 1242 | |
|---|
| 1243 | vifs = nvram_safe_get (wifivifs); |
|---|
| 1244 | //fprintf(stderr,"vifs %s\n",vifs); |
|---|
| 1245 | char *useif = NULL; |
|---|
| 1246 | char copyvap[64]; |
|---|
| 1247 | if (vifs != NULL) |
|---|
| 1248 | foreach (var, vifs, next) |
|---|
| 1249 | { |
|---|
| 1250 | //fprintf(stderr,"vifs %s, %s\n",vifs, var); |
|---|
| 1251 | if (!useif) |
|---|
| 1252 | { |
|---|
| 1253 | strcpy (copyvap, var); |
|---|
| 1254 | useif = copyvap; |
|---|
| 1255 | } |
|---|
| 1256 | } |
|---|
| 1257 | |
|---|
| 1258 | //config net mode |
|---|
| 1259 | if (useif) |
|---|
| 1260 | set_netmode (wif, dev, useif); |
|---|
| 1261 | set_netmode (wif, dev, dev); |
|---|
| 1262 | |
|---|
| 1263 | char wmm[32]; |
|---|
| 1264 | sprintf (wmm, "%s_wmm", dev); |
|---|
| 1265 | eval ("iwpriv", dev, "wmm", default_get (wmm, "0")); |
|---|
| 1266 | // eval ("iwpriv", dev, "uapsd","0"); |
|---|
| 1267 | eval ("iwpriv", dev, "scandisable", "0"); |
|---|
| 1268 | int disablescan = 0; |
|---|
| 1269 | #ifdef MADWIFI_OLD |
|---|
| 1270 | if (strcmp (m, "sta") && strcmp (m, "wdssta") && strcmp (m, "wet")) |
|---|
| 1271 | { |
|---|
| 1272 | cprintf ("set channel\n"); |
|---|
| 1273 | char *ch = default_get (channel, "0"); |
|---|
| 1274 | if (strcmp (ch, "0") == 0) |
|---|
| 1275 | { |
|---|
| 1276 | eval ("iwpriv", dev, "scandisable", "0"); |
|---|
| 1277 | eval ("iwconfig", dev, "channel", "0"); |
|---|
| 1278 | } |
|---|
| 1279 | else |
|---|
| 1280 | { |
|---|
| 1281 | char freq[64]; |
|---|
| 1282 | sprintf (freq, "%sM", ch); |
|---|
| 1283 | eval ("iwpriv", dev, "scandisable", "1"); |
|---|
| 1284 | disablescan = 1; |
|---|
| 1285 | eval ("iwconfig", dev, "freq", freq); |
|---|
| 1286 | } |
|---|
| 1287 | } |
|---|
| 1288 | else |
|---|
| 1289 | { |
|---|
| 1290 | set_scanlist (dev, wif); |
|---|
| 1291 | } |
|---|
| 1292 | #else |
|---|
| 1293 | set_scanlist(dev,wif); |
|---|
| 1294 | if (strcmp (m, "sta") && strcmp (m, "wdssta") && strcmp (m, "wet")) |
|---|
| 1295 | { |
|---|
| 1296 | char *ch = default_get (channel, "0"); |
|---|
| 1297 | if (strcmp (ch, "0") == 0) |
|---|
| 1298 | { |
|---|
| 1299 | eval ("iwconfig", dev, "channel", "0"); |
|---|
| 1300 | } |
|---|
| 1301 | else |
|---|
| 1302 | { |
|---|
| 1303 | char freq[64]; |
|---|
| 1304 | sprintf (freq, "%sM", ch); |
|---|
| 1305 | eval ("iwconfig", dev, "freq", freq); |
|---|
| 1306 | } |
|---|
| 1307 | } |
|---|
| 1308 | #endif |
|---|
| 1309 | |
|---|
| 1310 | |
|---|
| 1311 | if (useif) |
|---|
| 1312 | set_netmode (wif, dev, useif); |
|---|
| 1313 | set_netmode (wif, dev, dev); |
|---|
| 1314 | |
|---|
| 1315 | |
|---|
| 1316 | char macaddr[32]; |
|---|
| 1317 | getMacAddr (dev, macaddr); |
|---|
| 1318 | nvram_set (athmac, macaddr); |
|---|
| 1319 | |
|---|
| 1320 | cprintf ("adjust sensitivity\n"); |
|---|
| 1321 | |
|---|
| 1322 | int distance = atoi (default_get (sens, "2000")); //to meter |
|---|
| 1323 | if (distance > 0) |
|---|
| 1324 | { |
|---|
| 1325 | setsysctrl (wif, "dynack_count", 0); |
|---|
| 1326 | char *chanbw = nvram_nget("%s_channelbw",dev); |
|---|
| 1327 | setdistance (wif, distance,atoi(chanbw)); //sets the receiver sensitivity |
|---|
| 1328 | } |
|---|
| 1329 | else |
|---|
| 1330 | setsysctrl (wif, "dynack_count", 20); |
|---|
| 1331 | #if defined(HAVE_NS2) || defined(HAVE_NS5) |
|---|
| 1332 | int tx = atoi (default_get (txantenna, "0")); |
|---|
| 1333 | |
|---|
| 1334 | setsysctrl (wif, "diversity", 0); |
|---|
| 1335 | switch(tx) |
|---|
| 1336 | { |
|---|
| 1337 | case 0: |
|---|
| 1338 | setsysctrl (wif, "rxantenna", 2); |
|---|
| 1339 | setsysctrl (wif, "txantenna", 2); |
|---|
| 1340 | eval("gpio","enable","1"); |
|---|
| 1341 | break; |
|---|
| 1342 | case 1: |
|---|
| 1343 | setsysctrl (wif, "rxantenna", 1); |
|---|
| 1344 | setsysctrl (wif, "txantenna", 1); |
|---|
| 1345 | eval("gpio","enable","1"); |
|---|
| 1346 | break; |
|---|
| 1347 | case 2: |
|---|
| 1348 | setsysctrl (wif, "rxantenna", 1); |
|---|
| 1349 | setsysctrl (wif, "txantenna", 1); |
|---|
| 1350 | eval("gpio","disable","1"); |
|---|
| 1351 | break; |
|---|
| 1352 | } |
|---|
| 1353 | #else |
|---|
| 1354 | |
|---|
| 1355 | int rx = atoi (default_get (rxantenna, "1")); |
|---|
| 1356 | int tx = atoi (default_get (txantenna, "1")); |
|---|
| 1357 | int diva = atoi (default_get (diversity, "0")); |
|---|
| 1358 | |
|---|
| 1359 | setsysctrl (wif, "diversity", diva); |
|---|
| 1360 | setsysctrl (wif, "rxantenna", rx); |
|---|
| 1361 | setsysctrl (wif, "txantenna", tx); |
|---|
| 1362 | #endif |
|---|
| 1363 | //setup vif interfaces first |
|---|
| 1364 | |
|---|
| 1365 | vifs = nvram_safe_get (wifivifs); |
|---|
| 1366 | if (vifs != NULL) |
|---|
| 1367 | foreach (var, vifs, next) |
|---|
| 1368 | { |
|---|
| 1369 | sprintf (net, "%s_net_mode", var); |
|---|
| 1370 | if (nvram_match (net, "disabled")) |
|---|
| 1371 | continue; |
|---|
| 1372 | sprintf (ssid, "%s_ssid", var); |
|---|
| 1373 | sprintf (mode, "%s_mode", var); |
|---|
| 1374 | m = default_get (mode, "ap"); |
|---|
| 1375 | #ifndef OLD_MADWIFI |
|---|
| 1376 | set_scanlist (dev, wif); |
|---|
| 1377 | #endif |
|---|
| 1378 | |
|---|
| 1379 | if (strcmp (m, "sta") && strcmp (m, "wdssta") && strcmp (m, "wet")) |
|---|
| 1380 | { |
|---|
| 1381 | cprintf ("set channel\n"); |
|---|
| 1382 | char *ch = default_get (channel, "0"); |
|---|
| 1383 | if (strcmp (ch, "0") == 0) |
|---|
| 1384 | { |
|---|
| 1385 | #ifdef OLD_MADWIFI |
|---|
| 1386 | eval ("iwpriv", var, "scandisable", "0"); |
|---|
| 1387 | #endif |
|---|
| 1388 | eval ("iwconfig", var, "channel", "0"); |
|---|
| 1389 | } |
|---|
| 1390 | else |
|---|
| 1391 | { |
|---|
| 1392 | char freq[64]; |
|---|
| 1393 | sprintf (freq, "%sM", ch); |
|---|
| 1394 | #ifdef OLD_MADWIFI |
|---|
| 1395 | eval ("iwpriv", var, "scandisable", "1"); |
|---|
| 1396 | disablescan = 1; |
|---|
| 1397 | #endif |
|---|
| 1398 | eval ("iwconfig", var, "freq", freq); |
|---|
| 1399 | } |
|---|
| 1400 | } |
|---|
| 1401 | else |
|---|
| 1402 | { |
|---|
| 1403 | #ifdef OLD_MADWIFI |
|---|
| 1404 | set_scanlist (dev, wif); |
|---|
| 1405 | #endif |
|---|
| 1406 | } |
|---|
| 1407 | |
|---|
| 1408 | eval ("iwpriv", var, "bgscan", "0"); |
|---|
| 1409 | #ifdef HAVE_MAKSAT |
|---|
| 1410 | eval ("iwconfig", var, "essid", default_get (ssid, "maksat_vap")); |
|---|
| 1411 | #elif defined(HAVE_TRIMAX) |
|---|
| 1412 | eval ("iwconfig", var, "essid", default_get (ssid, "trimax_vap")); |
|---|
| 1413 | #else |
|---|
| 1414 | eval ("iwconfig", var, "essid", default_get (ssid, "dd-wrt_vap")); |
|---|
| 1415 | #endif |
|---|
| 1416 | cprintf ("set broadcast flag vif %s\n", var); //hide ssid |
|---|
| 1417 | sprintf (broadcast, "%s_closed", var); |
|---|
| 1418 | eval ("iwpriv", var, "hide_ssid", default_get (broadcast, "0")); |
|---|
| 1419 | sprintf (wmm, "%s_wmm", var); |
|---|
| 1420 | eval ("iwpriv", var, "wmm", default_get (wmm, "0")); |
|---|
| 1421 | // eval ("iwpriv", var, "uapsd", "0"); |
|---|
| 1422 | char isolate[32]; |
|---|
| 1423 | sprintf (isolate, "%s_ap_isolate", var); |
|---|
| 1424 | if (default_match (isolate, "1", "0")) |
|---|
| 1425 | eval ("iwpriv", var, "ap_bridge", "0"); |
|---|
| 1426 | if (!strcmp (m, "wdssta") || !strcmp (m, "wdsap")) |
|---|
| 1427 | eval ("iwpriv", var, "wds", "1"); |
|---|
| 1428 | if (!strcmp (m, "wdsap")) |
|---|
| 1429 | eval ("iwpriv", var, "wdsvlan", "0"); |
|---|
| 1430 | #ifdef OLD_MADWIFI |
|---|
| 1431 | if (disablescan) |
|---|
| 1432 | eval ("iwpriv", var, "scandisable", "1"); |
|---|
| 1433 | #endif |
|---|
| 1434 | cnt++; |
|---|
| 1435 | } |
|---|
| 1436 | |
|---|
| 1437 | |
|---|
| 1438 | |
|---|
| 1439 | if (!strcmp (m, "wdssta") || !strcmp (m, "wdsap")) |
|---|
| 1440 | eval ("iwpriv", dev, "wds", "1"); |
|---|
| 1441 | |
|---|
| 1442 | if (!strcmp (m, "wdsap")) |
|---|
| 1443 | eval ("iwpriv", dev, "wdsvlan", "0"); |
|---|
| 1444 | |
|---|
| 1445 | char isolate[32]; |
|---|
| 1446 | sprintf (isolate, "%s_ap_isolate", dev); |
|---|
| 1447 | if (default_match (isolate, "1", "0")) |
|---|
| 1448 | eval ("iwpriv", dev, "ap_bridge", "0"); |
|---|
| 1449 | |
|---|
| 1450 | |
|---|
| 1451 | sprintf (ssid, "ath%d_ssid", count); |
|---|
| 1452 | sprintf (broadcast, "ath%d_closed", count); |
|---|
| 1453 | |
|---|
| 1454 | |
|---|
| 1455 | memset (var, 0, 80); |
|---|
| 1456 | |
|---|
| 1457 | cprintf ("set ssid\n"); |
|---|
| 1458 | #ifdef HAVE_MAKSAT |
|---|
| 1459 | eval ("iwconfig", dev, "essid", default_get (ssid, "maksat")); |
|---|
| 1460 | #elif defined(HAVE_TRIMAX) |
|---|
| 1461 | eval ("iwconfig", dev, "essid", default_get (ssid, "trimax")); |
|---|
| 1462 | #else |
|---|
| 1463 | eval ("iwconfig", dev, "essid", default_get (ssid, "dd-wrt")); |
|---|
| 1464 | #endif |
|---|
| 1465 | cprintf ("set broadcast flag\n"); //hide ssid |
|---|
| 1466 | eval ("iwpriv", dev, "hide_ssid", default_get (broadcast, "0")); |
|---|
| 1467 | eval ("iwpriv", dev, "bgscan", "0"); |
|---|
| 1468 | m = default_get (wl, "ap"); |
|---|
| 1469 | |
|---|
| 1470 | |
|---|
| 1471 | char preamble[32]; |
|---|
| 1472 | sprintf (preamble, "%s_preamble", dev); |
|---|
| 1473 | if (default_match (preamble, "1", "0")) |
|---|
| 1474 | { |
|---|
| 1475 | eval ("iwpriv", dev, "shpreamble", "1"); |
|---|
| 1476 | } |
|---|
| 1477 | else |
|---|
| 1478 | eval ("iwpriv", dev, "shpreamble", "0"); |
|---|
| 1479 | |
|---|
| 1480 | if (strcmp (m, "sta") == 0 || strcmp (m, "infra") == 0 |
|---|
| 1481 | || strcmp (m, "wet") == 0 || strcmp (m, "wdssta") == 0) |
|---|
| 1482 | { |
|---|
| 1483 | cprintf ("set ssid\n"); |
|---|
| 1484 | #ifdef HAVE_MAKSAT |
|---|
| 1485 | eval ("iwconfig", dev, "essid", default_get (ssid, "maksat")); |
|---|
| 1486 | #elif defined(HAVE_TRIMAX) |
|---|
| 1487 | eval ("iwconfig", dev, "essid", default_get (ssid, "trimax")); |
|---|
| 1488 | #else |
|---|
| 1489 | eval ("iwconfig", dev, "essid", default_get (ssid, "dd-wrt")); |
|---|
| 1490 | #endif |
|---|
| 1491 | } |
|---|
| 1492 | |
|---|
| 1493 | |
|---|
| 1494 | |
|---|
| 1495 | |
|---|
| 1496 | cprintf ("adjust power\n"); |
|---|
| 1497 | |
|---|
| 1498 | int newpower = atoi (default_get (power, "16")); |
|---|
| 1499 | // fprintf (stderr, "new power limit %d\n", newpower); |
|---|
| 1500 | sprintf (var, "%ddBm", newpower); |
|---|
| 1501 | eval ("iwconfig", dev, "txpower", var); |
|---|
| 1502 | |
|---|
| 1503 | cprintf ("done()\n"); |
|---|
| 1504 | |
|---|
| 1505 | cprintf ("setup encryption"); |
|---|
| 1506 | //@todo ifup |
|---|
| 1507 | //netconfig |
|---|
| 1508 | |
|---|
| 1509 | |
|---|
| 1510 | |
|---|
| 1511 | |
|---|
| 1512 | setMacFilter (dev); |
|---|
| 1513 | |
|---|
| 1514 | set_rate (dev); |
|---|
| 1515 | |
|---|
| 1516 | set_netmode (wif, dev, dev); |
|---|
| 1517 | |
|---|
| 1518 | if (strcmp (m, "sta")) |
|---|
| 1519 | { |
|---|
| 1520 | char bridged[32]; |
|---|
| 1521 | sprintf (bridged, "%s_bridged", dev); |
|---|
| 1522 | if (default_match (bridged, "1", "1")) |
|---|
| 1523 | { |
|---|
| 1524 | ifconfig (dev, IFUP, NULL, NULL); |
|---|
| 1525 | br_add_interface (getBridge (dev), dev); |
|---|
| 1526 | eval ("ifconfig", dev, "0.0.0.0", "up"); |
|---|
| 1527 | } |
|---|
| 1528 | else |
|---|
| 1529 | { |
|---|
| 1530 | char ip[32]; |
|---|
| 1531 | char mask[32]; |
|---|
| 1532 | sprintf (ip, "%s_ipaddr", dev); |
|---|
| 1533 | sprintf (mask, "%s_netmask", dev); |
|---|
| 1534 | eval ("ifconfig", dev, "mtu", "1500"); |
|---|
| 1535 | eval ("ifconfig", dev, nvram_safe_get (ip), "netmask", |
|---|
| 1536 | nvram_safe_get (mask), "up"); |
|---|
| 1537 | } |
|---|
| 1538 | } |
|---|
| 1539 | else |
|---|
| 1540 | { |
|---|
| 1541 | char bridged[32]; |
|---|
| 1542 | sprintf (bridged, "%s_bridged", dev); |
|---|
| 1543 | if (default_match (bridged, "0", "1")) |
|---|
| 1544 | { |
|---|
| 1545 | char ip[32]; |
|---|
| 1546 | char mask[32]; |
|---|
| 1547 | sprintf (ip, "%s_ipaddr", dev); |
|---|
| 1548 | sprintf (mask, "%s_netmask", dev); |
|---|
| 1549 | eval ("ifconfig", dev, "mtu", "1500"); |
|---|
| 1550 | eval ("ifconfig", dev, nvram_safe_get (ip), "netmask", |
|---|
| 1551 | nvram_safe_get (mask), "up"); |
|---|
| 1552 | } |
|---|
| 1553 | } |
|---|
| 1554 | if (strcmp (m, "sta") && strcmp (m, "wdssta") && strcmp (m, "wet")) |
|---|
| 1555 | setupHostAP (dev, 0); |
|---|
| 1556 | else |
|---|
| 1557 | setupSupplicant (dev, NULL); |
|---|
| 1558 | |
|---|
| 1559 | |
|---|
| 1560 | //setup encryption |
|---|
| 1561 | |
|---|
| 1562 | vifs = nvram_safe_get (wifivifs); |
|---|
| 1563 | if (vifs != NULL) |
|---|
| 1564 | foreach (var, vifs, next) |
|---|
| 1565 | { |
|---|
| 1566 | sprintf (mode, "%s_mode", var); |
|---|
| 1567 | m = default_get (mode, "ap"); |
|---|
| 1568 | if (strcmp (m, "sta") && strcmp (m, "wdssta") && strcmp (m, "wet")) |
|---|
| 1569 | setupHostAP (var, 0); |
|---|
| 1570 | else |
|---|
| 1571 | setupSupplicant (var, NULL); |
|---|
| 1572 | } |
|---|
| 1573 | /* set_rate (dev);*/ |
|---|
| 1574 | |
|---|
| 1575 | |
|---|
| 1576 | // vif netconfig |
|---|
| 1577 | vifs = nvram_safe_get (wifivifs); |
|---|
| 1578 | if (vifs != NULL && strlen (vifs) > 0) |
|---|
| 1579 | { |
|---|
| 1580 | foreach (var, vifs, next) |
|---|
| 1581 | { |
|---|
| 1582 | setMacFilter (var); |
|---|
| 1583 | eval ("iwpriv", var, "scandisable", "1"); |
|---|
| 1584 | |
|---|
| 1585 | sprintf (mode, "%s_mode", var); |
|---|
| 1586 | char *m2 = default_get (mode, "ap"); |
|---|
| 1587 | |
|---|
| 1588 | if (strcmp (m2, "sta")) |
|---|
| 1589 | { |
|---|
| 1590 | char bridged[32]; |
|---|
| 1591 | sprintf (bridged, "%s_bridged", var); |
|---|
| 1592 | if (default_match (bridged, "1", "1")) |
|---|
| 1593 | { |
|---|
| 1594 | ifconfig (var, IFUP, NULL, NULL); |
|---|
| 1595 | br_add_interface (getBridge (var), var); |
|---|
| 1596 | if (!strcmp (m, "sta") || !strcmp (m, "wdssta") |
|---|
| 1597 | || !strcmp (m, "wet")) |
|---|
| 1598 | eval ("ifconfig", var, "0.0.0.0", "down"); |
|---|
| 1599 | else |
|---|
| 1600 | { |
|---|
| 1601 | eval ("ifconfig", var, "0.0.0.0", "down"); |
|---|
| 1602 | sleep (1); |
|---|
| 1603 | eval ("ifconfig", var, "0.0.0.0", "up"); |
|---|
| 1604 | } |
|---|
| 1605 | } |
|---|
| 1606 | else |
|---|
| 1607 | { |
|---|
| 1608 | char ip[32]; |
|---|
| 1609 | char mask[32]; |
|---|
| 1610 | sprintf (ip, "%s_ipaddr", var); |
|---|
| 1611 | sprintf (mask, "%s_netmask", var); |
|---|
| 1612 | eval ("ifconfig", var, "mtu", "1500"); |
|---|
| 1613 | ifconfig (var, IFUP, nvram_safe_get (ip), |
|---|
| 1614 | nvram_safe_get (mask)); |
|---|
| 1615 | if (!strcmp (m, "sta") || !strcmp (m, "wdssta") |
|---|
| 1616 | || !strcmp (m, "wet")) |
|---|
| 1617 | eval ("ifconfig", var, "down"); |
|---|
| 1618 | else |
|---|
| 1619 | { |
|---|
| 1620 | eval ("ifconfig", var, "down"); |
|---|
| 1621 | sleep (1); |
|---|
| 1622 | eval ("ifconfig", var, nvram_safe_get (ip), "netmask", |
|---|
| 1623 | nvram_safe_get (mask), "up"); |
|---|
| 1624 | } |
|---|
| 1625 | } |
|---|
| 1626 | } |
|---|
| 1627 | } |
|---|
| 1628 | } |
|---|
| 1629 | |
|---|
| 1630 | m = default_get (wl, "ap"); |
|---|
| 1631 | eval ("iwpriv", dev, "scandisable", "0"); |
|---|
| 1632 | if (strcmp (m, "sta") && strcmp (m, "wdssta") && strcmp (m, "wet")) |
|---|
| 1633 | { |
|---|
| 1634 | cprintf ("set channel\n"); |
|---|
| 1635 | char *ch = default_get (channel, "0"); |
|---|
| 1636 | if (strcmp (ch, "0") == 0) |
|---|
| 1637 | { |
|---|
| 1638 | eval ("iwconfig", dev, "channel", "0"); |
|---|
| 1639 | } |
|---|
| 1640 | else |
|---|
| 1641 | { |
|---|
| 1642 | char freq[64]; |
|---|
| 1643 | sprintf (freq, "%sM", ch); |
|---|
| 1644 | eval ("iwpriv", dev, "scandisable", "1"); |
|---|
| 1645 | eval ("iwconfig", dev, "freq", freq); |
|---|
| 1646 | sleep (1); |
|---|
| 1647 | eval ("ifconfig", dev, "down"); |
|---|
| 1648 | sleep (1); |
|---|
| 1649 | eval ("ifconfig", dev, "up"); |
|---|
| 1650 | } |
|---|
| 1651 | } |
|---|
| 1652 | |
|---|
| 1653 | for (s = 1; s <= 10; s++) |
|---|
| 1654 | { |
|---|
| 1655 | char wdsvarname[32] = { 0 }; |
|---|
| 1656 | char wdsdevname[32] = { 0 }; |
|---|
| 1657 | char wdsmacname[32] = { 0 }; |
|---|
| 1658 | char *wdsdev; |
|---|
| 1659 | char *hwaddr; |
|---|
| 1660 | |
|---|
| 1661 | sprintf (wdsvarname, "%s_wds%d_enable", dev, (11 - s)); |
|---|
| 1662 | sprintf (wdsdevname, "%s_wds%d_if", dev, (11 - s)); |
|---|
| 1663 | sprintf (wdsmacname, "%s_wds%d_hwaddr", dev, (11 - s)); |
|---|
| 1664 | wdsdev = nvram_safe_get (wdsdevname); |
|---|
| 1665 | if (strlen (wdsdev) == 0) |
|---|
| 1666 | continue; |
|---|
| 1667 | if (nvram_match (wdsvarname, "0")) |
|---|
| 1668 | continue; |
|---|
| 1669 | hwaddr = nvram_get (wdsmacname); |
|---|
| 1670 | if (hwaddr != NULL) |
|---|
| 1671 | { |
|---|
| 1672 | eval ("ifconfig", wdsdev, "0.0.0.0", "up"); |
|---|
| 1673 | } |
|---|
| 1674 | } |
|---|
| 1675 | |
|---|
| 1676 | |
|---|
| 1677 | } |
|---|
| 1678 | |
|---|
| 1679 | void |
|---|
| 1680 | start_vifs (void) |
|---|
| 1681 | { |
|---|
| 1682 | char *next; |
|---|
| 1683 | char var[80]; |
|---|
| 1684 | char *vifs; |
|---|
| 1685 | char mode[32]; |
|---|
| 1686 | char *m; |
|---|
| 1687 | char wifivifs[32]; |
|---|
| 1688 | int c = getdevicecount (); |
|---|
| 1689 | int count = 0; |
|---|
| 1690 | for (count = 0; count < c; count++) |
|---|
| 1691 | { |
|---|
| 1692 | sprintf (wifivifs, "ath%d_vifs", count); |
|---|
| 1693 | vifs = nvram_safe_get (wifivifs); |
|---|
| 1694 | if (vifs != NULL && strlen (vifs) > 0) |
|---|
| 1695 | { |
|---|
| 1696 | foreach (var, vifs, next) |
|---|
| 1697 | { |
|---|
| 1698 | setMacFilter (var); |
|---|
| 1699 | |
|---|
| 1700 | sprintf (mode, "%s_mode", var); |
|---|
| 1701 | m = default_get (mode, "ap"); |
|---|
| 1702 | |
|---|
| 1703 | if (strcmp (m, "sta")) |
|---|
| 1704 | { |
|---|
| 1705 | char bridged[32]; |
|---|
| 1706 | sprintf (bridged, "%s_bridged", var); |
|---|
| 1707 | if (default_match (bridged, "1", "1")) |
|---|
| 1708 | { |
|---|
| 1709 | ifconfig (var, IFUP, NULL, NULL); |
|---|
| 1710 | br_add_interface (getBridge (var), var); |
|---|
| 1711 | eval ("ifconfig", var, "0.0.0.0", "up"); |
|---|
| 1712 | } |
|---|
| 1713 | else |
|---|
| 1714 | { |
|---|
| 1715 | char ip[32]; |
|---|
| 1716 | char mask[32]; |
|---|
| 1717 | sprintf (ip, "%s_ipaddr", var); |
|---|
| 1718 | sprintf (mask, "%s_netmask", var); |
|---|
| 1719 | eval ("ifconfig", var, "mtu", "1500"); |
|---|
| 1720 | ifconfig (var, IFUP, nvram_safe_get (ip), |
|---|
| 1721 | nvram_safe_get (mask)); |
|---|
| 1722 | } |
|---|
| 1723 | } |
|---|
| 1724 | } |
|---|
| 1725 | } |
|---|
| 1726 | } |
|---|
| 1727 | |
|---|
| 1728 | } |
|---|
| 1729 | |
|---|
| 1730 | void |
|---|
| 1731 | stop_vifs (void) |
|---|
| 1732 | { |
|---|
| 1733 | char *next; |
|---|
| 1734 | char var[80]; |
|---|
| 1735 | char *vifs; |
|---|
| 1736 | char mode[32]; |
|---|
| 1737 | char *m; |
|---|
| 1738 | char wifivifs[32]; |
|---|
| 1739 | int c = getdevicecount (); |
|---|
| 1740 | int count = 0; |
|---|
| 1741 | for (count = 0; count < c; count++) |
|---|
| 1742 | { |
|---|
| 1743 | sprintf (wifivifs, "ath%d_vifs", count); |
|---|
| 1744 | vifs = nvram_safe_get (wifivifs); |
|---|
| 1745 | if (vifs != NULL && strlen (vifs) > 0) |
|---|
| 1746 | { |
|---|
| 1747 | foreach (var, vifs, next) |
|---|
| 1748 | { |
|---|
| 1749 | eval ("ifconfig", var, "down"); |
|---|
| 1750 | |
|---|
| 1751 | } |
|---|
| 1752 | } |
|---|
| 1753 | } |
|---|
| 1754 | |
|---|
| 1755 | } |
|---|
| 1756 | extern void adjust_regulatory (int count); |
|---|
| 1757 | |
|---|
| 1758 | void |
|---|
| 1759 | configure_wifi (void) //madwifi implementation for atheros based cards |
|---|
| 1760 | { |
|---|
| 1761 | deconfigure_wifi (); |
|---|
| 1762 | /*int s; |
|---|
| 1763 | int existed=0; |
|---|
| 1764 | for (s=0;s<10;s++) |
|---|
| 1765 | { |
|---|
| 1766 | char wif[32]; |
|---|
| 1767 | sprintf(wif,"wifi%d",s); |
|---|
| 1768 | if (ifexists(wif)) |
|---|
| 1769 | { |
|---|
| 1770 | eval("ifconfig",wif,"down"); |
|---|
| 1771 | existed=1; |
|---|
| 1772 | } |
|---|
| 1773 | } |
|---|
| 1774 | #if defined(HAVE_FONERA) || defined(HAVE_WHRAG108) |
|---|
| 1775 | eval("rmmod","ath_ahb"); |
|---|
| 1776 | eval ("insmod", "ath_ahb", "autocreate=none"); |
|---|
| 1777 | #else |
|---|
| 1778 | eval("rmmod","ath_pci"); |
|---|
| 1779 | eval ("insmod", "ath_pci", "autocreate=none"); |
|---|
| 1780 | #endif |
|---|
| 1781 | for (s=0;s<10;s++) |
|---|
| 1782 | { |
|---|
| 1783 | char wif[32]; |
|---|
| 1784 | sprintf(wif,"wifi%d",s); |
|---|
| 1785 | if (ifexists(wif)) |
|---|
| 1786 | eval("ifconfig",wif,"up"); |
|---|
| 1787 | } |
|---|
| 1788 | */ |
|---|
| 1789 | |
|---|
| 1790 | //bridge the virtual interfaces too |
|---|
| 1791 | memset (iflist, 0, 1024); |
|---|
| 1792 | /* |
|---|
| 1793 | char countrycode[64]; |
|---|
| 1794 | char xchanmode[64]; |
|---|
| 1795 | char outdoor[64]; |
|---|
| 1796 | |
|---|
| 1797 | if (strlen (nvram_safe_get ("wl_countrycode")) > 0) |
|---|
| 1798 | sprintf (countrycode, "countrycode=%s", |
|---|
| 1799 | nvram_safe_get ("wl_countrycode")); |
|---|
| 1800 | else |
|---|
| 1801 | sprintf (countrycode, "countrycode=0"); |
|---|
| 1802 | |
|---|
| 1803 | if (strlen (nvram_safe_get ("wl_xchanmode")) > 0) |
|---|
| 1804 | sprintf (xchanmode, "xchanmode=%s", nvram_safe_get ("wl_xchanmode")); |
|---|
| 1805 | else |
|---|
| 1806 | sprintf (xchanmode, "xchanmode=0"); |
|---|
| 1807 | |
|---|
| 1808 | if (strlen (nvram_safe_get ("wl_outdoor")) > 0) |
|---|
| 1809 | sprintf (outdoor, "outdoor=%s", nvram_safe_get ("wl_outdoor")); |
|---|
| 1810 | else |
|---|
| 1811 | sprintf (outdoor, "outdoor=0"); |
|---|
| 1812 | */ |
|---|
| 1813 | |
|---|
| 1814 | |
|---|
| 1815 | int c = getdevicecount (); |
|---|
| 1816 | int i; |
|---|
| 1817 | int changed = 0; |
|---|
| 1818 | for (i = 0; i < c; i++) |
|---|
| 1819 | adjust_regulatory (i); |
|---|
| 1820 | |
|---|
| 1821 | for (i = 0; i < c; i++) |
|---|
| 1822 | { |
|---|
| 1823 | #ifdef REGDOMAIN_OVERRIDE |
|---|
| 1824 | // SeG's dirty hack to make everything possible without any channel restrictions. regdomain 0x60 seems to be the best way |
|---|
| 1825 | char regdomain[16]; |
|---|
| 1826 | sprintf (regdomain, "ath%d_regdomain", i); |
|---|
| 1827 | |
|---|
| 1828 | // read current reg domain from atheros card |
|---|
| 1829 | // the base io 0x50010000 is hardcoded here and can be different on non RB500 ports |
|---|
| 1830 | // @fixme: detect io by reading pci data |
|---|
| 1831 | |
|---|
| 1832 | cprintf ("get reg domain()\n"); |
|---|
| 1833 | int reg_domain = get_regdomain ((0x50010000) + (0x10000 * i)); |
|---|
| 1834 | if (reg_domain > -1) //reg domain was successfully readed |
|---|
| 1835 | { |
|---|
| 1836 | if (nvram_get (regdomain) != NULL) // reg domain is defined in nvram |
|---|
| 1837 | { |
|---|
| 1838 | int destination = atoi (nvram_safe_get (regdomain)); // read new target regdomain |
|---|
| 1839 | if (destination != reg_domain) //check if changed |
|---|
| 1840 | { |
|---|
| 1841 | if (set_regdomain ((0x50010000) + (0x10000 * i), destination) == 0) //modifiy eeprom with new regdomain |
|---|
| 1842 | changed = 1; |
|---|
| 1843 | } |
|---|
| 1844 | } |
|---|
| 1845 | |
|---|
| 1846 | } |
|---|
| 1847 | cprintf ("configure next\n"); |
|---|
| 1848 | if (!changed) // if regdomain not changed, configure it |
|---|
| 1849 | #endif |
|---|
| 1850 | { |
|---|
| 1851 | configure_single (i); |
|---|
| 1852 | } |
|---|
| 1853 | } |
|---|
| 1854 | |
|---|
| 1855 | if (changed) // if changed, deconfigure myself and reconfigure me in the same way. |
|---|
| 1856 | { |
|---|
| 1857 | deconfigure_wifi (); |
|---|
| 1858 | configure_wifi (); |
|---|
| 1859 | } |
|---|
| 1860 | if (need_commit) |
|---|
| 1861 | { |
|---|
| 1862 | nvram_commit (); |
|---|
| 1863 | need_commit = 0; |
|---|
| 1864 | } |
|---|
| 1865 | eval ("killall", "-9", "roaming_daemon"); |
|---|
| 1866 | if (getSTA () || getWET ()) |
|---|
| 1867 | eval ("roaming_daemon"); |
|---|
| 1868 | } |
|---|
| 1869 | |
|---|
| 1870 | |
|---|
| 1871 | void |
|---|
| 1872 | start_deconfigurewifi (void) |
|---|
| 1873 | { |
|---|
| 1874 | deconfigure_wifi (); |
|---|
| 1875 | } |
|---|
| 1876 | |
|---|
| 1877 | |
|---|
| 1878 | void |
|---|
| 1879 | start_configurewifi (void) |
|---|
| 1880 | { |
|---|
| 1881 | configure_wifi (); |
|---|
| 1882 | } |
|---|
| 1883 | #endif |
|---|