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