root/src/router/services/networking/rt2880.c

Revision 11399, 37.0 kB (checked in by BrainSlayer, 10 months ago)

correction

Line 
1 /*
2  * rt2880.c
3  *
4  * Copyright (C) 2008 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_RT2880
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 extern int br_add_interface( const char *br, const char *dev );
54
55 // returns the number of installed atheros devices/cards
56
57 static char iflist[1024];
58
59 char *getiflist( void )
60 {
61     return iflist;
62 }
63
64 static int need_commit = 0;
65
66 void setupSupplicant( char *prefix )
67 {
68     char akm[16];
69
70     sprintf( akm, "%s_akm", prefix );
71     char wmode[16];
72
73     sprintf( wmode, "%s_mode", prefix );
74     if( nvram_match( akm, "8021X" ) )
75     {
76         char fstr[32];
77         char psk[64];
78         char ath[64];
79
80         sprintf( fstr, "/tmp/%s_wpa_supplicant.conf", prefix );
81         FILE *fp = fopen( fstr, "wb" );
82
83         fprintf( fp, "ap_scan=1\n" );
84         fprintf( fp, "fast_reauth=1\n" );
85         fprintf( fp, "eapol_version=2\n" );
86         fprintf( fp, "network={\n" );
87         sprintf( psk, "%s_ssid", prefix );
88         fprintf( fp, "\tssid=\"%s\"\n", nvram_safe_get( psk ) );
89         fprintf( fp, "\tscan_ssid=1\n" );
90         if( nvram_prefix_match( "8021xtype", prefix, "tls" ) )
91         {
92             fprintf( fp, "\tkey_mgmt=IEEE8021X\n" );
93             fprintf( fp, "\teap=TLS\n" );
94             fprintf( fp, "\tidentity=\"%s\"\n",
95                      nvram_prefix_get( "tls8021xuser", prefix ) );
96             sprintf( psk, "/tmp/%s", prefix );
97             mkdir( psk );
98             sprintf( psk, "/tmp/%s/ca.pem", prefix );
99             sprintf( ath, "%s_tls8021xca", prefix );
100             write_nvram( psk, ath );
101             sprintf( psk, "/tmp/%s/user.pem", prefix );
102             sprintf( ath, "%s_tls8021xpem", prefix );
103             write_nvram( psk, ath );
104
105             sprintf( psk, "/tmp/%s/user.prv", prefix );
106             sprintf( ath, "%s_tls8021xprv", prefix );
107             write_nvram( psk, ath );
108             fprintf( fp, "\tca_cert=/tmp/%s/ca.pem\n", prefix );
109             fprintf( fp, "\tclient_cert=/tmp/%s/user.pem\n", prefix );
110             fprintf( fp, "\tprivate_key=/tmp/%s/user.prv\n", prefix );
111             fprintf( fp, "\tprivate_key_passwd=\"%s\"\n",
112                      nvram_prefix_get( "tls8021xpasswd", prefix ) );
113             fprintf( fp, "\teapol_flags=3\n" );
114             if( strlen( nvram_nget( "%s_tls8021xphase2", prefix ) ) > 0 )
115             {
116                 fprintf( fp, "\tphase2=\"%s\"\n",
117                          nvram_nget( "%s_tls8021xphase2", prefix ) );
118             }
119             if( strlen( nvram_nget( "%s_tls8021xanon", prefix ) ) > 0 )
120             {
121                 fprintf( fp, "\tanonymous_identity=\"%s\"\n",
122                          nvram_nget( "%s_tls8021xanon", prefix ) );
123             }
124         }
125         if( nvram_prefix_match( "8021xtype", prefix, "peap" ) )
126         {
127             fprintf( fp, "\tkey_mgmt=WPA-EAP\n" );
128             fprintf( fp, "\teap=PEAP\n" );
129             fprintf( fp, "\tpairwise=CCMP TKIP\n" );
130             fprintf( fp, "\tgroup=CCMP TKIP\n" );
131             fprintf( fp, "\tphase1=\"peapver=0\"\n" );
132             fprintf( fp, "\tidentity=\"%s\"\n",
133                      nvram_prefix_get( "peap8021xuser", prefix ) );
134             fprintf( fp, "\tpassword=\"%s\"\n",
135                      nvram_prefix_get( "peap8021xpasswd", prefix ) );
136             sprintf( psk, "/tmp/%s", prefix );
137             mkdir( psk );
138             sprintf( psk, "/tmp/%s/ca.pem", prefix );
139             sprintf( ath, "%s_peap8021xca", prefix );
140             write_nvram( psk, ath );
141             fprintf( fp, "\tca_cert=\"/tmp/%s/ca.pem\"\n", prefix );
142             if( strlen( nvram_nget( "%s_peap8021xphase2", prefix ) ) > 0 )
143             {
144                 fprintf( fp, "\tphase2=\"%s\"\n",
145                          nvram_nget( "%s_peap8021xphase2", prefix ) );
146             }
147             if( strlen( nvram_nget( "%s_peap8021xanon", prefix ) ) > 0 )
148             {
149                 fprintf( fp, "\tanonymous_identity=\"%s\"\n",
150                          nvram_nget( "%s_peap8021xanon", prefix ) );
151             }
152         }
153         if( nvram_prefix_match( "8021xtype", prefix, "ttls" ) )
154         {
155             fprintf( fp, "\tkey_mgmt=WPA-EAP\n" );
156             fprintf( fp, "\teap=TTLS\n" );
157             fprintf( fp, "\tpairwise=CCMP TKIP\n" );
158             fprintf( fp, "\tgroup=CCMP TKIP\n" );
159             fprintf( fp, "\tidentity=\"%s\"\n",
160                      nvram_prefix_get( "ttls8021xuser", prefix ) );
161             fprintf( fp, "\tpassword=\"%s\"\n",
162                      nvram_prefix_get( "ttls8021xpasswd", prefix ) );
163             if( strlen( nvram_nget( "%s_ttls8021xca", prefix ) ) > 0 )
164             {
165                 sprintf( psk, "/tmp/%s", prefix );
166                 mkdir( psk );
167                 sprintf( psk, "/tmp/%s/ca.pem", prefix );
168                 sprintf( ath, "%s_ttls8021xca", prefix );
169                 write_nvram( psk, ath );
170                 fprintf( fp, "\tca_cert=\"/tmp/%s/ca.pem\"\n", prefix );
171             }
172             if( strlen( nvram_nget( "%s_ttls8021xphase2", prefix ) ) > 0 )
173             {
174                 fprintf( fp, "\tphase2=\"%s\"\n",
175                          nvram_nget( "%s_ttls8021xphase2", prefix ) );
176             }
177             if( strlen( nvram_nget( "%s_ttls8021xanon", prefix ) ) > 0 )
178             {
179                 fprintf( fp, "\tanonymous_identity=\"%s\"\n",
180                          nvram_nget( "%s_ttls8021xanon", prefix ) );
181             }
182         }
183         if( nvram_prefix_match( "8021xtype", prefix, "leap" ) )
184         {
185             fprintf( fp, "\tkey_mgmt=WPA-EAP\n" );
186             fprintf( fp, "\teap=LEAP\n" );
187             fprintf( fp, "\tauth_alg=LEAP\n" );
188             fprintf( fp, "\tproto=WPA RSN\n" );
189             fprintf( fp, "\tpairwise=CCMP TKIP\n" );
190             fprintf( fp, "\tgroup=CCMP TKIP\n" );
191             fprintf( fp, "\tidentity=\"%s\"\n",
192                      nvram_prefix_get( "leap8021xuser", prefix ) );
193             fprintf( fp, "\tpassword=\"%s\"\n",
194                      nvram_prefix_get( "leap8021xpasswd", prefix ) );
195             if( strlen( nvram_nget( "%s_leap8021xphase2", prefix ) ) > 0 )
196             {
197                 fprintf( fp, "\tphase2=\"%s\"\n",
198                          nvram_nget( "%s_leap8021xphase2", prefix ) );
199             }
200             if( strlen( nvram_nget( "%s_leap8021xanon", prefix ) ) > 0 )
201             {
202                 fprintf( fp, "\tanonymous_identity=\"%s\"\n",
203                          nvram_nget( "%s_leap8021xanon", prefix ) );
204             }
205         }
206         fprintf( fp, "}\n" );
207         fclose( fp );
208         sprintf( psk, "-i%s", getRADev( prefix ) );
209
210         char bvar[32];
211
212         sprintf( bvar, "%s_bridged", prefix );
213         if( nvram_match( bvar, "1" )
214             && ( nvram_match( wmode, "wdssta" )
215                  || nvram_match( wmode, "wet" ) ) )
216             eval( "wpa_supplicant", "-b", nvram_safe_get( "lan_ifname" ),
217                   "-B", "-Dralink", psk, "-c", fstr );
218         else
219             eval( "wpa_supplicant", "-B", "-Dralink", psk, "-c", fstr );
220     }
221
222 }
223
224 void supplicant_main( int argc, char *argv[] )
225 {
226     setupSupplicant( argv[1] );
227 }
228
229 void setupHostAP( char *prefix, int iswan )
230 {
231
232 }
233
234 void setMacFilter( char *iface )
235 {
236     char *next;
237     char var[32];
238     char nvvar[32];
239
240     sysprintf( "iwpriv %s set ACLClearAll=1", getRADev( iface ) );
241     sysprintf( "iwpriv %s set AccessPolicy=0", getRADev( iface ) );
242
243     sprintf( nvvar, "%s_macmode", iface );
244     if( nvram_match( nvvar, "deny" ) )
245     {
246         sysprintf( "iwpriv %s set AccessPolicy=2", getRADev( iface ) );
247         char nvlist[32];
248
249         sprintf( nvlist, "%s_maclist", iface );
250
251         foreach( var, nvram_safe_get( nvlist ), next )
252         {
253             sysprintf( "iwpriv %s set ACLAddEntry=%s", getRADev( iface ),
254                        var );
255         }
256     }
257     if( nvram_match( nvvar, "allow" ) )
258     {
259         sysprintf( "iwpriv %s set AccessPolicy=1", getRADev( iface ) );
260
261         char nvlist[32];
262
263         sprintf( nvlist, "%s_maclist", iface );
264
265         foreach( var, nvram_safe_get( nvlist ), next )
266         {
267             sysprintf( "iwpriv %s set ACLAddEntry=%s", getRADev( iface ),
268                        var );
269         }
270     }
271
272 }
273
274 #define IFUP (IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST)
275
276 void start_vifs( void )
277 {
278
279 }
280
281 void stop_vifs( void )
282 {
283
284 }
285 extern void adjust_regulatory( int count );
286
287 char *getWDSDev( char *wdsdev )
288 {
289     char *newdev = "";
290
291     if( !strcmp( wdsdev, "wds0.1" ) )
292         newdev = "wds0";
293     if( !strcmp( wdsdev, "wds0.2" ) )
294         newdev = "wds1";
295     if( !strcmp( wdsdev, "wds0.3" ) )
296         newdev = "wds2";
297     if( !strcmp( wdsdev, "wds0.4" ) )
298         newdev = "wds3";
299     if( !strcmp( wdsdev, "wds0.5" ) )
300         newdev = "wds4";
301     if( !strcmp( wdsdev, "wds0.6" ) )
302         newdev = "wds5";
303     if( !strcmp( wdsdev, "wds0.7" ) )
304         newdev = "wds6";
305     if( !strcmp( wdsdev, "wds0.8" ) )
306         newdev = "wds7";
307     if( !strcmp( wdsdev, "wds0.9" ) )
308         newdev = "wds8";
309     if( !strcmp( wdsdev, "wds0.10" ) )
310         newdev = "wds9";
311     return newdev;
312 }
313
314 void deconfigure_wifi( void )
315 {
316
317 }
318
319 void start_radius( void )
320 {
321     char psk[64];
322
323     // wrt-radauth $IFNAME $server $port $share $override $mackey $maxun &
324     char ifname[32];
325
326     char *prefix = "wl0";
327
328     strcpy( ifname, "ra0" );
329
330     if( nvram_nmatch( "1", "%s_radauth", prefix )
331         && nvram_nmatch( "ap", "%s_mode", prefix ) )
332     {
333         char *server = nvram_nget( "%s_radius_ipaddr", prefix );
334         char *port = nvram_nget( "%s_radius_port", prefix );
335         char *share = nvram_nget( "%s_radius_key", prefix );
336         char type[32];
337
338         sprintf( type, "%s_radmactype", prefix );
339         char *pragma = "";
340
341         if( nvram_default_match( type, "0", "0" ) )
342             pragma = "-n1 ";
343         if( nvram_match( type, "1" ) )
344             pragma = "-n2 ";
345         if( nvram_match( type, "2" ) )
346             pragma = "-n3 ";
347         if( nvram_match( type, "3" ) )
348             pragma = "";
349         sleep( 1 );             // some delay is usefull
350         sysprintf( "wrt-radauth %s %s %s %s %s %s %s %s &", pragma, ifname,
351                    server, port, share, nvram_nget( "%s_radius_override",
352                                                     prefix ),
353                    nvram_nget( "%s_radmacpassword", prefix ),
354                    nvram_nget( "%s_max_unauth_users", prefix ) );
355     }
356
357 }
358 static int isSTA(  )
359 {
360
361     if( nvram_match( "wl0_mode", "sta" ) || nvram_match( "wl0_mode", "wet" )
362         || nvram_match( "wl0_mode", "infra" ) )
363         return 1;
364     return 0;
365 }
366 static int startradius = 0;
367 void configure_wifi( void )     // madwifi implementation for atheros based
368                                 // cards
369 {
370     char var[64];
371     char *next;
372
373     startradius = 0;
374     deconfigure_wifi(  );
375     killall( "rt2860apd", SIGTERM );
376     eval( "ifconfig", "ra0", "down" );
377     eval( "ifconfig", "ra1", "down" );
378     eval( "ifconfig", "ra2", "down" );
379     eval( "ifconfig", "ra3", "down" );
380     eval( "ifconfig", "ra4", "down" );
381     eval( "ifconfig", "ra5", "down" );
382     eval( "ifconfig", "ra6", "down" );
383     eval( "ifconfig", "ra7", "down" );
384     eval( "ifconfig", "wds0", "down" );
385     eval( "ifconfig", "wds1", "down" );
386     eval( "ifconfig", "wds2", "down" );
387     eval( "ifconfig", "wds3", "down" );
388     eval( "ifconfig", "wds4", "down" );
389     eval( "ifconfig", "wds5", "down" );
390     eval( "ifconfig", "wds6", "down" );
391     eval( "ifconfig", "wds7", "down" );
392     eval( "ifconfig", "wds8", "down" );
393     eval( "ifconfig", "wds9", "down" );
394     eval( "ifconfig", "apcli0", "down" );
395
396     rmmod( "rt2860v2_ap" );
397     rmmod( "rt2860v2_sta" );
398
399     FILE *fp = fopen( "/tmp/RT2860.dat", "wb" );        // config file for driver (don't ask me, its really the worst config thing i have seen)
400
401     fprintf( fp, "Default\n" );
402 #ifdef BUFFALO_JP
403     fprintf( fp, "CountryRegion=5\n" );
404     fprintf( fp, "CountryRegionABand=7\n" );
405     fprintf( fp, "CountryCode=JP\n" );
406 #else
407     fprintf( fp, "CountryRegion=1\n" );
408     fprintf( fp, "CountryRegionABand=7\n" );
409     fprintf( fp, "CountryCode=DE\n" );
410 #endif
411     int count = 2;
412
413 // if( nvram_match( "wl0_mode", "apsta" )
414 //    {
415 //     int count--;
416 //    }
417
418     char *vifs;
419
420
421     if( isSTA(  ) )
422     {
423         fprintf( fp, "SSID=%s\n", nvram_safe_get( "wl0_ssid" ) );
424         fprintf( fp, "BssidNum=1\n" );
425         if( nvram_match( "wl0_mode", "sta" )
426             || nvram_match( "wl0_mode", "wet" ) )
427             fprintf( fp, "NetworkType=Infra\n" );
428         if( nvram_match( "wl0_mode", "infra" ) )
429             fprintf( fp, "NetworkType=Adhoc\n" );
430         nvram_set( "wl0_vifs", "" );
431     }
432     else
433     {
434         fprintf( fp, "SSID1=%s\n", nvram_safe_get( "wl0_ssid" ) );
435         vifs = nvram_nget( "wl0_vifs" );
436
437         if( vifs != NULL )
438             foreach( var, vifs, next )
439         {
440             fprintf( fp, "SSID%d=%s\n", count, nvram_nget( "%s_ssid", var ) );
441             count++;
442         }
443         fprintf( fp, "BssidNum=%d\n", count - 1 );
444
445 /* need to check if these values are okay for RT3052 too */
446         fprintf( fp, "Ht_TxStream=2\n" );
447         fprintf( fp, "Ht_RxStream=3\n" );
448     }
449 /* suggestion by Jimmy */
450 //      fprintf( fp, "HtBw=1\n" );
451
452     if( nvram_match( "wl0_net_mode", "bg-mixed" ) )
453         fprintf( fp, "WirelessMode=0\n" );
454     if( nvram_match( "wl0_net_mode", "b-only" ) )
455         fprintf( fp, "WirelessMode=1\n" );
456     if( nvram_match( "wl0_net_mode", "g-only" ) )
457         fprintf( fp, "WirelessMode=4\n" );
458     if( nvram_match( "wl0_net_mode", "n-only" ) )
459         fprintf( fp, "WirelessMode=6\n" );
460     if( nvram_match( "wl0_net_mode", "mixed" ) )
461         fprintf( fp, "WirelessMode=9\n" );
462
463     char hidestr[64];
464
465     hidestr[0] = 0;
466
467     if( nvram_nmatch( "1", "wl0_closed" ) )
468         strcat( hidestr, "1" );
469     else
470         strcat( hidestr, "0" );
471
472     vifs = nvram_get( "wl0_vifs" );
473     if( vifs != NULL )
474         foreach( var, vifs, next )
475     {
476         if( nvram_nmatch( "1", "%s_closed", var ) )
477             strcat( hidestr, ";1" );
478         else
479             strcat( hidestr, ";0" );
480     }
481     fprintf( fp, "HideSSID=%s\n", hidestr );
482     fprintf( fp, "ShortSlot=%s\n",
483              nvram_match( "wl0_shortslot", "long" ) ? "0" : "1" );
484     if( nvram_match( "wl0_channel", "0" ) )
485         fprintf( fp, "AutoChannelSelect=1\n" );
486     else
487         fprintf( fp, "AutoChannelSelect=0\n" );
488
489 //encryption setup
490     fprintf( fp, "IEEE80211H=0\n" );
491     char keyidstr[64] = { 0 };
492     char encryptype[64] = { 0 };
493     char authmode[64] = { 0 };
494     char radius_server[256] = { 0 };
495     char radius_port[256] = { 0 };
496     char radius_key[1024] = { 0 };
497     char x80211[32] = { 0 };
498
499     fprintf( fp, "own_ip_addr=%s\n", nvram_safe_get( "lan_ipaddr" ) );
500
501     if( nvram_match( "wl0_key", "" ) )
502         strcat( keyidstr, "1" );
503     else
504         strcat( keyidstr, nvram_safe_get( "wl0_key" ) );
505
506     if( nvram_match( "wl0_akm", "wep" ) )
507     {
508         strcat( authmode, "OPEN" );
509         strcat( encryptype, "WEP" );
510         strcat( x80211, "0" );
511         if( isSTA(  ) )
512         {
513             fprintf( fp, "Key1=%s\n", nvram_safe_get( "wl0_key1" ) );
514             fprintf( fp, "Key2=%s\n", nvram_safe_get( "wl0_key2" ) );
515             fprintf( fp, "Key3=%s\n", nvram_safe_get( "wl0_key3" ) );
516             fprintf( fp, "Key4=%s\n", nvram_safe_get( "wl0_key4" ) );
517         }
518         else
519         {
520             fprintf( fp, "Key1Str1=%s\n", nvram_safe_get( "wl0_key1" ) );
521             fprintf( fp, "Key2Str1=%s\n", nvram_safe_get( "wl0_key2" ) );
522             fprintf( fp, "Key3Str1=%s\n", nvram_safe_get( "wl0_key3" ) );
523             fprintf( fp, "Key4Str1=%s\n", nvram_safe_get( "wl0_key4" ) );
524             fprintf( fp, "Key1Type=0\n" );
525             fprintf( fp, "Key2Type=0\n" );
526             fprintf( fp, "Key3Type=0\n" );
527             fprintf( fp, "Key4Type=0\n" );
528         }
529         strcat( radius_server, "0.0.0.0" );
530         strcat( radius_port, "1812" );
531         strcat( radius_key, "ralink" );
532     }
533     if( nvram_match( "wl0_akm", "disabled" ) )
534     {
535         strcat( authmode, "OPEN" );
536         strcat( encryptype, "NONE" );
537         strcat( x80211, "0" );
538         strcat( radius_server, "0.0.0.0" );
539         strcat( radius_port, "1812" );
540         strcat( radius_key, "ralink" );
541     }
542     if( nvram_match( "wl0_akm", "psk2" ) )
543     {
544         if( isSTA(  ) )
545             fprintf( fp, "WPAPSK=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
546         else
547             fprintf( fp, "WPAPSK1=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
548         if( nvram_match( "wl0_mode", "infra" ) )
549             strcat( authmode, "WPANONE" );
550         else
551             strcat( authmode, "WPAPSK2" );
552         strcat( radius_server, "0.0.0.0" );
553         strcat( radius_port, "1812" );
554         strcat( radius_key, "ralink" );
555         strcat( x80211, "0" );
556         if( nvram_match( "wl0_crypto", "tkip" ) )
557             strcat( encryptype, "TKIP" );
558         if( nvram_match( "wl0_crypto", "aes" ) )
559             strcat( encryptype, "AES" );
560         if( nvram_match( "wl0_crypto", "tkip+aes" ) )
561             strcat( encryptype, "TKIPAES" );
562     }
563     if( nvram_match( "wl0_akm", "psk psk2" ) )
564     {
565         if( isSTA(  ) )
566             fprintf( fp, "WPAPSK=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
567         else
568             fprintf( fp, "WPAPSK1=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
569         strcat( authmode, "WPAPSKWPAPSK2" );
570         strcat( radius_server, "0.0.0.0" );
571         strcat( radius_port, "1812" );
572         strcat( radius_key, "ralink" );
573         strcat( x80211, "0" );
574         if( nvram_match( "wl0_crypto", "tkip" ) )
575             strcat( encryptype, "TKIP" );
576         if( nvram_match( "wl0_crypto", "aes" ) )
577             strcat( encryptype, "AES" );
578         if( nvram_match( "wl0_crypto", "tkip+aes" ) )
579             strcat( encryptype, "TKIPAES" );
580     }
581
582     if( nvram_match( "wl0_akm", "psk" ) )
583     {
584         if( isSTA(  ) )
585             fprintf( fp, "WPAPSK=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
586         else
587             fprintf( fp, "WPAPSK1=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
588         if( nvram_match( "wl0_mode", "infra" ) )
589             strcat( authmode, "WPANONE" );
590         else
591             strcat( authmode, "WPAPSK" );
592         strcat( radius_server, "0.0.0.0" );
593         strcat( radius_port, "1812" );
594         strcat( radius_key, "ralink" );
595         strcat( x80211, "0" );
596         if( nvram_match( "wl0_crypto", "tkip" ) )
597             strcat( encryptype, "TKIP" );
598         if( nvram_match( "wl0_crypto", "aes" ) )
599             strcat( encryptype, "AES" );
600         if( nvram_match( "wl0_crypto", "tkip+aes" ) )
601             strcat( encryptype, "TKIPAES" );
602     }
603     if( nvram_match( "wl0_akm", "wpa" ) )
604     {
605         startradius = 1;
606         if( isSTA(  ) )
607             fprintf( fp, "WPAPSK=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
608         else
609             fprintf( fp, "WPAPSK1=\n" );
610         strcat( authmode, "WPA" );
611         strcat( radius_server, nvram_safe_get( "wl0_radius_ipaddr" ) );
612         strcat( radius_port, nvram_safe_get( "wl0_radius_port" ) );
613         strcat( radius_key, nvram_safe_get( "wl0_radius_key" ) );
614         strcat( x80211, "0" );
615         if( nvram_match( "wl0_crypto", "tkip" ) )
616             strcat( encryptype, "TKIP" );
617         if( nvram_match( "wl0_crypto", "aes" ) )
618             strcat( encryptype, "AES" );
619         if( nvram_match( "wl0_crypto", "tkip+aes" ) )
620             strcat( encryptype, "TKIPAES" );
621     }
622     if( nvram_match( "wl0_akm", "wpa2" ) )
623     {
624         startradius = 1;
625         if( isSTA(  ) )
626             fprintf( fp, "WPAPSK=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
627         else
628             fprintf( fp, "WPAPSK1=\n" );
629         strcat( authmode, "WPA" );
630         strcat( radius_server, nvram_safe_get( "wl0_radius_ipaddr" ) );
631         strcat( radius_port, nvram_safe_get( "wl0_radius_port" ) );
632         strcat( radius_key, nvram_safe_get( "wl0_radius_key" ) );
633         strcat( x80211, "0" );
634         if( nvram_match( "wl0_crypto", "tkip" ) )
635             strcat( encryptype, "TKIP" );
636         if( nvram_match( "wl0_crypto", "aes" ) )
637             strcat( encryptype, "AES" );
638         if( nvram_match( "wl0_crypto", "tkip+aes" ) )
639             strcat( encryptype, "TKIPAES" );
640     }
641     if( nvram_match( "wl0_akm", "wpa wpa2" ) )
642     {
643         startradius = 1;
644         if( isSTA(  ) )
645             fprintf( fp, "WPAPSK=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
646         else
647             fprintf( fp, "WPAPSK1=\n" );
648         strcat( authmode, "WPA1WPA2" );
649         strcat( radius_server, nvram_safe_get( "wl0_radius_ipaddr" ) );
650         strcat( radius_port, nvram_safe_get( "wl0_radius_port" ) );
651         strcat( radius_key, nvram_safe_get( "wl0_radius_key" ) );
652         strcat( x80211, "0" );
653         if( nvram_match( "wl0_crypto", "tkip" ) )
654             strcat( encryptype, "TKIP" );
655         if( nvram_match( "wl0_crypto", "aes" ) )
656             strcat( encryptype, "AES" );
657         if( nvram_match( "wl0_crypto", "tkip+aes" ) )
658             strcat( encryptype, "TKIPAES" );
659     }
660     if( nvram_match( "wl0_akm", "radius" ) )
661     {
662         startradius = 1;
663         if( isSTA(  ) )
664             fprintf( fp, "WPAPSK=\n" );
665         else
666             fprintf( fp, "WPAPSK1=\n" );
667         strcat( authmode, "OPEN" );
668         sprintf( radius_server, "%s", nvram_nget( "%s_radius_ipaddr", var ) );
669         sprintf( radius_port, "%s", nvram_nget( "%s_radius_port", var ) );
670         sprintf( radius_key, "%s", nvram_nget( "%s_radius_key", var ) );
671         strcat( x80211, "1" );
672         strcat( encryptype, "WEP" );
673     }
674
675     count = 2;
676     vifs = nvram_get( "wl0_vifs" );
677     if( vifs != NULL )
678         foreach( var, vifs, next )
679     {
680         strcat( keyidstr, ";" );
681         if( nvram_nmatch( "", "%s_key", var ) )
682             strcat( keyidstr, "1" );
683         else
684             strcat( keyidstr, nvram_nget( "%s_key", var ) );
685         if( nvram_nmatch( "disabled", "%s_akm", var ) )
686         {
687             strcat( authmode, ";OPEN" );
688             strcat( encryptype, ";NONE" );
689             strcat( radius_server, ";0.0.0.0" );
690             strcat( radius_port, ";1812" );
691             strcat( radius_key, ";ralink" );
692             strcat( x80211, ";0" );
693         }
694         if( nvram_nmatch( "wep", "%s_akm", var ) )
695         {
696             sprintf( radius_server, "%s;0.0.0.0", radius_server );
697             sprintf( radius_port, "%s;1812", radius_port );
698             sprintf( radius_key, "%s;ralink", radius_key );
699             strcat( authmode, ";OPEN" );
700             strcat( encryptype, ";WEP" );
701             strcat( x80211, ";0" );
702             fprintf( fp, "Key1Str%d=%s\n", count,
703                      nvram_nget( "%s_key1", var ) );
704             fprintf( fp, "Key2Str%d=%s\n", count,
705                      nvram_nget( "%s_key2", var ) );
706             fprintf( fp, "Key3Str%d=%s\n", count,
707                      nvram_nget( "%s_key3", var ) );
708             fprintf( fp, "Key4Str%d=%s\n", count,
709                      nvram_nget( "%s_key4", var ) );
710         }
711         if( nvram_nmatch( "psk", "%s_akm", var ) )
712         {
713             sprintf( radius_server, "%s;0.0.0.0", radius_server );
714             sprintf( radius_port, "%s;1812", radius_port );
715             sprintf( radius_key, "%s;ralink", radius_key );
716             strcat( x80211, ";0" );
717             fprintf( fp, "WPAPSK%d=%s\n", count,
718                      nvram_nget( "%s_wpa_psk", var ) );
719             strcat( authmode, ";WPAPSK" );
720             if( nvram_nmatch( "tkip", "%s_crypto", var ) )
721                 strcat( encryptype, ";TKIP" );
722             if( nvram_nmatch( "aes", "%s_crypto", var ) )
723                 strcat( encryptype, ";AES" );
724             if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
725                 strcat( encryptype, ";TKIPAES" );
726         }
727         if( nvram_nmatch( "psk psk2", "%s_akm", var ) )
728         {
729             sprintf( radius_server, "%s;0.0.0.0", radius_server );
730             sprintf( radius_port, "%s;1812", radius_port );
731             sprintf( radius_key, "%s;ralink", radius_key );
732             strcat( x80211, ";0" );
733             fprintf( fp, "WPAPSK%d=%s\n", count,
734                      nvram_nget( "%s_wpa_psk", var ) );
735             strcat( authmode, ";WPAPSKWPA2PSK" );
736             if( nvram_nmatch( "tkip", "%s_crypto", var ) )
737                 strcat( encryptype, ";TKIP" );
738             if( nvram_nmatch( "aes", "%s_crypto", var ) )
739                 strcat( encryptype, ";AES" );
740             if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
741                 strcat( encryptype, ";TKIPAES" );
742         }
743         if( nvram_nmatch( "psk2", "%s_akm", var ) )
744         {
745             sprintf( radius_server, "%s;0.0.0.0", radius_server );
746             sprintf( radius_port, "%s;1812", radius_port );
747             sprintf( radius_key, "%s;ralink", radius_key );
748             strcat( x80211, ";0" );
749             fprintf( fp, "WPAPSK%d=%s\n", count,
750                      nvram_nget( "%s_wpa_psk", var ) );
751             strcat( authmode, ";WPAPSK2" );
752             if( nvram_nmatch( "tkip", "%s_crypto", var ) )
753                 strcat( encryptype, ";TKIP" );
754             if( nvram_nmatch( "aes", "%s_crypto", var ) )
755                 strcat( encryptype, ";AES" );
756             if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
757                 strcat( encryptype, ";TKIPAES" );
758         }
759         if( nvram_nmatch( "wpa", "%s_akm", var ) )
760         {
761             startradius = 1;
762             fprintf( fp, "WPAPSK%d=\n", count );
763             strcat( authmode, ";WPA" );
764             sprintf( radius_server, "%s;%s", radius_server,
765                      nvram_nget( "%s_radius_ipaddr", var ) );
766             sprintf( radius_port, "%s;%s", radius_port,
767                      nvram_nget( "%s_radius_port", var ) );
768             sprintf( radius_key, "%s;%s", radius_key,
769                      nvram_nget( "%s_radius_key", var ) );
770             strcat( x80211, ";0" );
771             if( nvram_nmatch( "tkip", "%s_crypto", var ) )
772                 strcat( encryptype, ";TKIP" );
773             if( nvram_nmatch( "aes", "%s_crypto", var ) )
774                 strcat( encryptype, ";AES" );
775             if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
776                 strcat( encryptype, ";TKIPAES" );
777         }
778         if( nvram_nmatch( "wpa2", "%s_akm", var ) )
779         {
780             startradius = 1;
781             fprintf( fp, "WPAPSK%d=\n", count );
782             strcat( authmode, ";WPA2" );
783             sprintf( radius_server, "%s;%s", radius_server,
784                      nvram_nget( "%s_radius_ipaddr", var ) );
785             sprintf( radius_port, "%s;%s", radius_port,
786                      nvram_nget( "%s_radius_port", var ) );
787             sprintf( radius_key, "%s;%s", radius_key,
788                      nvram_nget( "%s_radius_key", var ) );
789             strcat( x80211, ";0" );
790             if( nvram_nmatch( "tkip", "%s_crypto", var ) )
791                 strcat( encryptype, ";TKIP" );
792             if( nvram_nmatch( "aes", "%s_crypto", var ) )
793                 strcat( encryptype, ";AES" );
794             if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
795                 strcat( encryptype, ";TKIPAES" );
796         }
797         if( nvram_nmatch( "wpa wpa2", "%s_akm", var ) )
798         {
799             startradius = 1;
800             fprintf( fp, "WPAPSK%d=\n", count );
801             strcat( authmode, ";WPA1WPA2" );
802             sprintf( radius_server, "%s;%s", radius_server,
803                      nvram_nget( "%s_radius_ipaddr", var ) );
804             sprintf( radius_port, "%s;%s", radius_port,
805                      nvram_nget( "%s_radius_port", var ) );
806             sprintf( radius_key, "%s;%s", radius_key,
807                      nvram_nget( "%s_radius_key", var ) );
808             strcat( x80211, ";0" );
809             if( nvram_nmatch( "tkip", "%s_crypto", var ) )
810                 strcat( encryptype, ";TKIP" );
811             if( nvram_nmatch( "aes", "%s_crypto", var ) )
812                 strcat( encryptype, ";AES" );
813             if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
814                 strcat( encryptype, ";TKIPAES" );
815         }
816         if( nvram_nmatch( "radius", "%s_akm", var ) )
817         {
818             startradius = 1;
819             fprintf( fp, "WPAPSK%d=\n", count );
820             strcat( authmode, ";OPEN" );
821             sprintf( radius_server, "%s;%s", radius_server,
822                      nvram_nget( "%s_radius_ipaddr", var ) );
823             sprintf( radius_port, "%s;%s", radius_port,
824                      nvram_nget( "%s_radius_port", var ) );
825             sprintf( radius_key, "%s;%s", radius_key,
826                      nvram_nget( "%s_radius_key", var ) );
827             strcat( x80211, ";1" );
828             strcat( encryptype, ";WEP" );
829         }
830
831         count++;
832     }
833
834     fprintf( fp, "DefaultKeyID=%s\n", keyidstr );
835     fprintf( fp, "EncrypType=%s\n", encryptype );
836     fprintf( fp, "AuthMode=%s\n", authmode );
837
838     fprintf( fp, "RADIUS_Server=%s\n", radius_server );
839     fprintf( fp, "RADIUS_Port=%s\n", radius_port );
840     fprintf( fp, "RADIUS_Key=%s\n", radius_key );
841     fprintf( fp, "IEEE8021X=%s\n", x80211 );
842 //wds entries
843     char wdsentries[128] = { 0 };
844     int wdscount = 0;
845     int s;
846
847     for( s = 1; s <= 10; s++ )
848     {
849         char wdsvarname[32] = { 0 };
850         char wdsdevname[32] = { 0 };
851         char wdsmacname[32] = { 0 };
852         char *wdsdev;
853         char *hwaddr;
854         char *dev = "wl0";
855
856         sprintf( wdsvarname, "%s_wds%d_enable", dev, s );
857         sprintf( wdsdevname, "%s_wds%d_if", dev, s );
858         sprintf( wdsmacname, "%s_wds%d_hwaddr", dev, s );
859         wdsdev = nvram_safe_get( wdsdevname );
860         if( strlen( wdsdev ) == 0 )
861             continue;
862         if( nvram_match( wdsvarname, "0" ) )
863             continue;
864         hwaddr = nvram_get( wdsmacname );
865         if( hwaddr != NULL )
866         {
867             sprintf( wdsentries, "%s;%s", wdsentries, hwaddr );
868             wdscount++;
869         }
870     }
871
872     if( wdscount )
873     {
874         if( nvram_match( "wl0_lazy_wds", "1" ) )
875             fprintf( fp, "WdsEnable=4\n" );     // 2 is exclusive
876         else
877             fprintf( fp, "WdsEnable=3\n" );     // 2 is exclusive
878         fprintf( fp, "WdsEncrypType=NONE\n" );  //for now we do not support encryption
879         fprintf( fp, "WdsList=%s\n", wdsentries );
880         fprintf( fp, "WdsKey=\n" );
881     }
882     else
883     {
884         fprintf( fp, "WdsEnable=0\n" );
885         fprintf( fp, "WdsEncrypType=NONE\n" );
886         fprintf( fp, "WdsList=\n" );
887         fprintf( fp, "WdsKey=\n" );
888
889     }
890
891 //channel width
892     if( nvram_match( "wl0_nbw", "20" ) )
893         fprintf( fp, "HT_BW=0\n" );
894     else
895         fprintf( fp, "HT_BW=1\n" );
896
897     int channel = atoi( nvram_safe_get( "wl0_channel" ) );
898
899     if( channel <= 4 )
900         fprintf( fp, "HT_EXTCHA=1\n" );
901     else if( channel >= 8 )
902         fprintf( fp, "HT_EXTCHA=0\n" );
903     else
904         fprintf( fp, "HT_EXTCHA=0\n" );
905
906     if( nvram_default_match( "wl0_greenfield", "1", "0" ) )
907         fprintf( fp, "HT_OpMode=1\n" ); // green field mode
908     else
909         fprintf( fp, "HT_OpMode=0\n" );
910
911     int mcs = atoi( nvram_default_get( "wl0_nmcsidx", "-1" ) );
912
913     if( mcs == -1 )
914         fprintf( fp, "HT_MCS=33\n" );
915     else
916         fprintf( fp, "HT_MCS=%d\n", mcs );
917
918 //txrate
919     if( nvram_match( "wl0_rate", "0" ) )
920         fprintf( fp, "TxRate=0\n" );
921     else if( nvram_match( "wl0_rate", "1000000" ) )
922         fprintf( fp, "TxRate=1\n" );
923     else if( nvram_match( "wl0_rate", "2000000" ) )
924         fprintf( fp, "TxRate=2\n" );
925     else if( nvram_match( "wl0_rate", "5500000" ) )
926         fprintf( fp, "TxRate=3\n" );
927     else if( nvram_match( "wl0_rate", "6000000" ) )
928         fprintf( fp, "TxRate=5\n" );
929     else if( nvram_match( "wl0_rate", "9000000" ) )
930         fprintf( fp, "TxRate=6\n" );
931     else if( nvram_match( "wl0_rate", "1100000" ) )
932         fprintf( fp, "TxRate=4\n" );
933     else if( nvram_match( "wl0_rate", "1200000" ) )
934         fprintf( fp, "TxRate=7\n" );
935     else if( nvram_match( "wl0_rate", "1800000" ) )
936         fprintf( fp, "TxRate=8\n" );
937     else if( nvram_match( "wl0_rate", "2400000" ) )
938         fprintf( fp, "TxRate=9\n" );
939     else if( nvram_match( "wl0_rate", "3600000" ) )
940         fprintf( fp, "TxRate=10\n" );
941     else if( nvram_match( "wl0_rate", "4800000" ) )
942         fprintf( fp, "TxRate=11\n" );
943     else if( nvram_match( "wl0_rate", "5400000" ) )
944         fprintf( fp, "TxRate=12\n" );
945     else
946         fprintf( fp, "TxRate=0\n" );
947
948     if( isSTA(  ) && !nvram_match( "wl0_mode", "infra" ) )
949         fprintf( fp, "Channel=0\n" );
950     else
951         fprintf( fp, "Channel=%s\n", nvram_safe_get( "wl0_channel" ) );
952     if( nvram_match( "wl0_rateset", "12" ) )
953         fprintf( fp, "BasicRate=3\n" );
954     if( nvram_match( "wl0_rateset", "default" ) )
955         fprintf( fp, "BasicRate=15\n" );
956     if( nvram_match( "wl0_rateset", "all" ) )
957         fprintf( fp, "BasicRate=351\n" );
958     fprintf( fp, "BeaconPeriod=%s\n", nvram_safe_get( "wl0_bcn" ) );
959     fprintf( fp, "DtimPeriod=%s\n", nvram_safe_get( "wl0_dtim" ) );
960     fprintf( fp, "TxPower=%s\n", nvram_safe_get( "wl0_txpwr" ) );       // warning. percentage this time
961     fprintf( fp, "DisableOLBC=0\n" );   //what is this?
962     fprintf( fp, "BGProtection=%s\n",
963              nvram_match( "wl0_gmode_protection", "auto" ) ? "0" : "2" );
964     fprintf( fp, "TXPreamble=%s\n",
965              nvram_match( "wl0_plcphdr", "long" ) ? "0" : "1" );
966     fprintf( fp, "RTSThreshold=%s\n", nvram_safe_get( "wl0_rts" ) );
967     fprintf( fp, "FragThreshold=%s\n", nvram_safe_get( "wl0_frag" ) );
968     fprintf( fp, "TxBurst=%s\n",
969              nvram_match( "wl0_frameburst", "on" ) ? "0" : "1" );
970     fprintf( fp, "PktAggregate=0\n" );
971     fprintf( fp, "TurboRate=0\n" );
972     fprintf( fp, "wmm=%s\n", nvram_match( "wl0_wme", "on" ) ? "1" : "0" );
973     fprintf( fp, "APAifsn=3;7;1;1\n" );
974     fprintf( fp, "APCwmin=4;4;3;2\n" );
975     fprintf( fp, "APCwmax=6;10;4;3\n" );
976     fprintf( fp, "APTxop=0;0;94;47\n" );
977     fprintf( fp, "APACM=0;0;0;0\n" );
978     fprintf( fp, "BSSAifsn=3;7;2;2\n" );
979     fprintf( fp, "BSSCwmin=4;4;3;2\n" );
980     fprintf( fp, "BSSCwmax=10;10;4;3\n" );
981     fprintf( fp, "BSSTxop=0;0;94;47\n" );
982     fprintf( fp, "BSSACM=0;0;0;0\n" );
983     fprintf( fp, "AckPolicy=0;0;0;0\n" );
984     fprintf( fp, "NoForwarding=%s\n", nvram_safe_get( "wl0_ap_isolate" ) );     //between lan and ap
985     fprintf( fp, "NoForwardingBTNBSSID=%s\n", nvram_safe_get( "wl0_ap_isolate" ) );     // between bssid
986
987 //station
988
989     if( getSTA(  ) || getWET(  ) && !isSTA(  ) )
990     {
991         fprintf( fp, "ApCliEnable=1\n" );
992         fprintf( fp, "ApCliSsid=%s\n", nvram_safe_get( "wl0_ssid" ) );
993         if( nvram_match( "wl0_akm", "psk" )
994             || nvram_match( "wl0_akm", "psk2" )
995             || nvram_match( "wl0_akm", "psk psk2" ) )
996         {
997             if( nvram_match( "wl0_akm", "psk" ) )
998             {
999                 if( nvram_match( "wl0_crypto", "tkip" ) )
1000                     fprintf( fp, "ApCliEncrypType=TKIP\n" );
1001                 if( nvram_match( "wl0_crypto", "aes" ) )
1002                     fprintf( fp, "ApCliEncrypType=AES\n" );
1003                 if( nvram_match( "wl0_crypto", "tkip+aes" ) )
1004                     fprintf( fp, "ApCliEncrypType=TKIPAES\n" );
1005                 fprintf( fp, "ApCliAuthMode=WPAPSK\n" );
1006             }
1007             if( nvram_match( "wl0_akm", "psk2" ) )
1008             {
1009                 if( nvram_match( "wl0_crypto", "tkip" ) )
1010                     fprintf( fp, "ApCliEncrypType=TKIP\n" );
1011                 if( nvram_match( "wl0_crypto", "aes" ) )
1012                     fprintf( fp, "ApCliEncrypType=AES\n" );
1013                 if( nvram_match( "wl0_crypto", "tkip+aes" ) )
1014                     fprintf( fp, "ApCliEncrypType=TKIPAES\n" );
1015                 fprintf( fp, "ApCliAuthMode=WPA2PSK\n" );
1016             }
1017             fprintf( fp, "ApCliWPAPSK=%s\n",
1018                      nvram_safe_get( "wl0_wpa_psk" ) );
1019         }
1020         if( nvram_match( "wl0_akm", "disabled" ) )
1021         {
1022             fprintf( fp, "ApCliEncrypType=NONE\n" );
1023             fprintf( fp, "ApCliAuthMode=OPEN\n" );
1024         }
1025         if( nvram_match( "wl0_akm", "wep" ) )
1026         {
1027             fprintf( fp, "ApCliEncrypType=WEP\n" );
1028             fprintf( fp, "ApCliAuthMode=OPEN\n" );
1029             fprintf( fp, "ApCliDefaultKeyID=%s\n",
1030                      nvram_safe_get( "wl0_key" ) );
1031             fprintf( fp, "ApCliKey1Type=0\n" );
1032             fprintf( fp, "ApCliKey2Type=0\n" );
1033             fprintf( fp, "ApCliKey3Type=0\n" );
1034             fprintf( fp, "ApCliKey4Type=0\n" );
1035             fprintf( fp, "ApCliKey1Str=%s\n", nvram_safe_get( "wl0_key1" ) );
1036             fprintf( fp, "ApCliKey2Str=%s\n", nvram_safe_get( "wl0_key2" ) );
1037             fprintf( fp, "ApCliKey3Str=%s\n", nvram_safe_get( "wl0_key3" ) );
1038             fprintf( fp, "ApCliKey4Str=%s\n", nvram_safe_get( "wl0_key4" ) );
1039         }
1040     }
1041     else
1042     {
1043         fprintf( fp, "ApCliEnable=0\n" );
1044     }
1045
1046     fprintf( fp, "CSPeriod=10\n" );
1047     fprintf( fp, "WirelessEvent=0\n" );
1048     fprintf( fp, "PreAuth=0\n" );
1049     fprintf( fp, "RekeyInterval=0\n" );
1050     fprintf( fp, "RekeyMethod=DISABLE\n" );
1051     fprintf( fp, "PMKCachePeriod=10\n" );
1052     fprintf( fp, "HSCounter=0\n" );
1053     fprintf( fp, "AccessPolicy0=0\n" );
1054     fprintf( fp, "AccessControlList0=\n" );
1055     fprintf( fp, "AccessPolicy1=0\n" );
1056     fprintf( fp, "AccessControlList1=\n" );
1057     fprintf( fp, "AccessPolicy2=0\n" );
1058     fprintf( fp, "AccessControlList2=\n" );
1059     fprintf( fp, "AccessPolicy3=0\n" );
1060     fprintf( fp, "AccessControlList3=\n" );
1061     fprintf( fp, "EAPifname=br0\n" );
1062     fprintf( fp, "PreAuthifname=br0\n" );
1063     fprintf( fp, "HT_HTC=0\n" );
1064     fprintf( fp, "HT_RDG=1\n" );
1065     fprintf( fp, "HT_LinkAdapt=0\n" );
1066     fprintf( fp, "HT_MpduDensity=5\n" );
1067     fprintf( fp, "HT_AutoBA=1\n" );
1068     fprintf( fp, "HT_AMSDU=0\n" );
1069     fprintf( fp, "HT_BAWinSize=64\n" );
1070     fprintf( fp, "HT_GI=1\n" );
1071     fprintf( fp, "HT_STBC=1\n" );
1072     fclose( fp );
1073
1074     if( isSTA(  ) )
1075     {
1076         insmod( "rt2860v2_sta" );
1077         char *dev = "wl0";
1078         char bridged[32];
1079
1080         sprintf( bridged, "%s_bridged", getRADev( dev ) );
1081         if( nvram_default_match( bridged, "1", "1" ) )
1082         {
1083             sysprintf( "ifconfig ra0 0.0.0.0 up" );
1084             if( nvram_match( "wl0_mode", "infra" ) )
1085             {
1086                 br_add_interface( getBridge( "ra0" ), "ra0" );
1087             }
1088         }
1089         else
1090         {
1091             sysprintf( "ifconfig %s mtu 1500", "ra0" );
1092             sysprintf( "ifconfig %s %s netmask %s up", "ra0",
1093                        nvram_nget( "%s_ipaddr", getRADev( dev ) ),
1094                        nvram_nget( "%s_netmask", getRADev( dev ) ) );
1095         }
1096         char vathmac[32];
1097
1098         sprintf( vathmac, "wl0_hwaddr" );
1099         char vmacaddr[32];
1100
1101         getMacAddr( "ra0", vmacaddr );
1102         nvram_set( vathmac, vmacaddr );
1103         setupSupplicant( "wl0" );
1104     }
1105     else
1106     {
1107         insmod( "rt2860v2_ap" );
1108
1109         char *dev = "wl0";
1110         char bridged[32];
1111
1112         sprintf( bridged, "%s_bridged", getRADev( dev ) );
1113         if( nvram_default_match( bridged, "1", "1" ) )
1114         {
1115             if( getSTA(  ) || getWET(  ) )
1116             {
1117                 sysprintf( "ifconfig ra0 0.0.0.0 up" );
1118                 sysprintf( "ifconfig %s 0.0.0.0 up", "apcli0" );
1119                 br_add_interface( getBridge( "ra0" ), "ra0" );
1120             }
1121             else
1122             {
1123                 sysprintf( "ifconfig %s 0.0.0.0 up", "ra0" );
1124                 br_add_interface( getBridge( "ra0" ), "ra0" );
1125             }
1126         }
1127         else
1128         {
1129             if( getSTA(  ) || getWET(  ) )
1130             {
1131                 sysprintf( "ifconfig ra0 0.0.0.0 up" );
1132                 sysprintf( "ifconfig %s mtu 1500", "apcli0" );
1133                 sysprintf( "ifconfig %s %s netmask %s up", "ra0",
1134                            nvram_nget( "%s_ipaddr", getRADev( dev ) ),
1135                            nvram_nget( "%s_netmask", getRADev( dev ) ) );
1136             }
1137             else
1138             {
1139                 sysprintf( "ifconfig %s mtu 1500", "ra0" );
1140                 sysprintf( "ifconfig %s %s netmask %s up", "ra0",
1141                            nvram_nget( "%s_ipaddr", getRADev( dev ) ),
1142                            nvram_nget( "%s_netmask", getRADev( dev ) ) );
1143             }
1144         }
1145         char vathmac[32];
1146
1147         sprintf( vathmac, "wl0_hwaddr" );
1148         char vmacaddr[32];
1149
1150         getMacAddr( "ra0", vmacaddr );
1151         nvram_set( vathmac, vmacaddr );
1152
1153         vifs = nvram_safe_get( "wl0_vifs" );
1154         if( vifs != NULL && strlen( vifs ) > 0 )
1155         {
1156             int count = 1;
1157
1158             foreach( var, vifs, next )
1159             {
1160
1161                 sprintf( bridged, "%s_bridged", getRADev( var ) );
1162                 if( nvram_default_match( bridged, "1", "1" ) )
1163                 {
1164                     char ra[32];
1165
1166                     sprintf( ra, "ra%d", count );
1167                     sysprintf( "ifconfig ra%d 0.0.0.0 up", count );
1168                     br_add_interface( getBridge( getRADev( var ) ), ra );
1169                 }
1170                 else
1171                 {
1172                     char ip[32];
1173                     char mask[32];
1174
1175                     sprintf( ip, "%s_ipaddr", getRADev( var ) );
1176                     sprintf( mask, "%s_netmask", getRADev( var ) );
1177                     sysprintf( "ifconfig ra%d mtu 1500", count );
1178                     sysprintf( "ifconfig ra%d %s netmask %s up", count,
1179                                nvram_safe_get( ip ), nvram_safe_get( mask ) );
1180                 }
1181
1182                 sprintf( vathmac, "%s_hwaddr", var );
1183                 getMacAddr( getRADev( var ), vmacaddr );
1184                 nvram_set( vathmac, vmacaddr );
1185
1186                 count++;
1187             }
1188         }
1189
1190         for( s = 1; s <= 10; s++ )
1191         {
1192             char wdsvarname[32] = { 0 };
1193             char wdsdevname[32] = { 0 };
1194             char wdsmacname[32] = { 0 };
1195             char *wdsdev;
1196             char *dev = "wl0";
1197             char *hwaddr;
1198
1199             sprintf( wdsvarname, "%s_wds%d_enable", dev, ( 11 - s ) );
1200             sprintf( wdsdevname, "%s_wds%d_if", dev, ( 11 - s ) );
1201             sprintf( wdsmacname, "%s_wds%d_hwaddr", dev, ( 11 - s ) );
1202             wdsdev = nvram_safe_get( wdsdevname );
1203             if( strlen( wdsdev ) == 0 )
1204                 continue;
1205             if( nvram_match( wdsvarname, "0" ) )
1206                 continue;
1207             hwaddr = nvram_get( wdsmacname );
1208             if( hwaddr != NULL )
1209             {
1210                 char *newdev = getWDSDev( wdsdev );
1211
1212                 sysprintf( "ifconfig %s 0.0.0.0 up", newdev );
1213             }
1214         }
1215
1216         /*
1217
1218            set macfilter
1219          */
1220
1221         if( startradius )
1222             eval( "rt2860apd" );
1223         setMacFilter( "wl0" );
1224     }
1225     vifs = nvram_safe_get( "wl0_vifs" );
1226     if( vifs != NULL && strlen( vifs ) > 0 )
1227     {
1228         foreach( var, vifs, next )
1229         {
1230             setMacFilter( var );
1231         }
1232
1233     }
1234
1235     start_radius(  );
1236 }
1237
1238 void start_hostapdwan( void )
1239 {
1240     if( !isSTA(  ) && startradius )
1241     {
1242         killall( "rt2860apd", SIGTERM );
1243         eval( "rt2860apd" );
1244     }
1245 }
1246
1247 void start_configurewifi( void )
1248 {
1249     configure_wifi(  );
1250 }
1251
1252 void start_deconfigurewifi( void )
1253 {
1254     deconfigure_wifi(  );
1255 }
1256 #endif
Note: See TracBrowser for help on using the browser.