source: src/router/services/networking/rt2880.c @ 10785

Last change on this file since 10785 was 10785, checked in by BrainSlayer, 5 years ago

adjustments for buffalo

File size: 22.1 KB
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
53extern int br_add_interface( const char *br, const char *dev );
54
55// returns the number of installed atheros devices/cards
56
57static char iflist[1024];
58
59char *getiflist( void )
60{
61    return iflist;
62}
63
64static int need_commit = 0;
65
66static int getMaxPower( char *ifname )
67{
68}
69
70/*
71 * MADWIFI Encryption Setup
72 */
73void setupSupplicant( char *prefix, char *ssidoverride )
74{
75
76}
77void supplicant_main( int argc, char *argv[] )
78{
79    setupSupplicant( argv[1], argv[2] );
80}
81
82void setupHostAP( char *prefix, int iswan )
83{
84
85}
86void start_hostapdwan( void )
87{
88
89}
90
91void setMacFilter( char *iface )
92{
93    char *next;
94    char var[32];
95
96    sysprintf( "ifconfig %s down", iface );
97    sysprintf( "iwpriv %s maccmd 3", iface );
98
99    char nvvar[32];
100
101    sprintf( nvvar, "%s_macmode", iface );
102    if( nvram_match( nvvar, "deny" ) )
103    {
104        sysprintf( "iwpriv %s maccmd 2", iface );
105        sysprintf( "ifconfig %s up", iface );
106        char nvlist[32];
107
108        sprintf( nvlist, "%s_maclist", iface );
109
110        foreach( var, nvram_safe_get( nvlist ), next )
111        {
112            sysprintf( "iwpriv %s addmac %s", iface, var );
113        }
114    }
115    if( nvram_match( nvvar, "allow" ) )
116    {
117        sysprintf( "iwpriv %s maccmd 1", iface );
118        sysprintf( "ifconfig %s up", iface );
119
120        char nvlist[32];
121
122        sprintf( nvlist, "%s_maclist", iface );
123
124        foreach( var, nvram_safe_get( nvlist ), next )
125        {
126            sysprintf( "iwpriv %s addmac %s", iface, var );
127        }
128    }
129
130}
131
132#define IFUP (IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST)
133
134void start_vifs( void )
135{
136
137}
138
139void stop_vifs( void )
140{
141
142}
143extern void adjust_regulatory( int count );
144
145char *getWDSDev( char *wdsdev )
146{
147    char *newdev = "";
148
149    if( !strcmp( wdsdev, "wds0.1" ) )
150        newdev = "wds0";
151    if( !strcmp( wdsdev, "wds0.2" ) )
152        newdev = "wds1";
153    if( !strcmp( wdsdev, "wds0.3" ) )
154        newdev = "wds2";
155    if( !strcmp( wdsdev, "wds0.4" ) )
156        newdev = "wds3";
157    if( !strcmp( wdsdev, "wds0.5" ) )
158        newdev = "wds4";
159    if( !strcmp( wdsdev, "wds0.6" ) )
160        newdev = "wds5";
161    if( !strcmp( wdsdev, "wds0.7" ) )
162        newdev = "wds6";
163    if( !strcmp( wdsdev, "wds0.8" ) )
164        newdev = "wds7";
165    if( !strcmp( wdsdev, "wds0.9" ) )
166        newdev = "wds8";
167    if( !strcmp( wdsdev, "wds0.10" ) )
168        newdev = "wds9";
169    return newdev;
170}
171
172void deconfigure_wifi( void )
173{
174
175}
176
177void start_radius( void )
178{
179    char psk[64];
180
181    // wrt-radauth $IFNAME $server $port $share $override $mackey $maxun &
182    char ifname[32];
183
184    char *prefix = "wl0";
185
186    strcpy( ifname, "ra0" );
187
188    if( nvram_nmatch( "1", "%s_radauth", prefix )
189        && nvram_nmatch( "ap", "%s_mode", prefix ) )
190    {
191        char *server = nvram_nget( "%s_radius_ipaddr", prefix );
192        char *port = nvram_nget( "%s_radius_port", prefix );
193        char *share = nvram_nget( "%s_radius_key", prefix );
194        char type[32];
195
196        sprintf( type, "%s_radmactype", prefix );
197        char *pragma = "";
198
199        if( nvram_default_match( type, "0", "0" ) )
200            pragma = "-n1 ";
201        if( nvram_match( type, "1" ) )
202            pragma = "-n2 ";
203        if( nvram_match( type, "2" ) )
204            pragma = "-n3 ";
205        if( nvram_match( type, "3" ) )
206            pragma = "";
207        sleep( 1 );             // some delay is usefull
208        sysprintf( "wrt-radauth %s %s %s %s %s %s %s %s &", pragma, ifname,
209                   server, port, share, nvram_nget( "%s_radius_override",
210                                                    prefix ),
211                   nvram_nget( "%s_radmacpassword", prefix ),
212                   nvram_nget( "%s_max_unauth_users", prefix ) );
213    }
214
215}
216
217void configure_wifi( void )     // madwifi implementation for atheros based
218                                // cards
219{
220    char var[64];
221    char *next;
222
223    deconfigure_wifi(  );
224    eval( "ifconfig", "ra0", "down" );
225    eval( "ifconfig", "ra1", "down" );
226    eval( "ifconfig", "ra2", "down" );
227    eval( "ifconfig", "ra3", "down" );
228    eval( "ifconfig", "ra4", "down" );
229    eval( "ifconfig", "ra5", "down" );
230    eval( "ifconfig", "ra6", "down" );
231    eval( "ifconfig", "ra7", "down" );
232    eval( "ifconfig", "wds0", "down" );
233    eval( "ifconfig", "wds1", "down" );
234    eval( "ifconfig", "wds2", "down" );
235    eval( "ifconfig", "wds3", "down" );
236    eval( "ifconfig", "wds4", "down" );
237    eval( "ifconfig", "wds5", "down" );
238    eval( "ifconfig", "wds6", "down" );
239    eval( "ifconfig", "wds7", "down" );
240    eval( "ifconfig", "wds8", "down" );
241    eval( "ifconfig", "wds9", "down" );
242    eval( "ifconfig", "apcli0", "down" );
243
244    rmmod( "rt2860v2_ap" );
245    FILE *fp = fopen( "/tmp/RT2860.dat", "wb" );        // config file for driver (don't ask me, its really the worst config thing i have seen)
246
247    fprintf( fp, "Default\n" );
248#ifdef BUFFALO_JP
249    fprintf( fp, "CountryRegion=5\n" );
250    fprintf( fp, "CountryRegionABand=7\n" );
251    fprintf( fp, "CountryCode=JP\n" );
252#else
253    fprintf( fp, "CountryRegion=1\n" );
254    fprintf( fp, "CountryRegionABand=7\n" );
255    fprintf( fp, "CountryCode=DE\n" );
256#endif
257 int count = 2;
258// if( nvram_match( "wl0_mode", "apsta" )
259//    {
260//     int count--;
261//    }
262
263    fprintf( fp, "SSID1=%s\n", nvram_safe_get( "wl0_ssid" ) );
264    char *vifs = nvram_nget( "wl0_vifs" );
265
266
267    if( vifs != NULL )
268        foreach( var, vifs, next )
269    {
270        fprintf( fp, "SSID%d=%s\n", count, nvram_nget( "%s_ssid", var ) );
271        count++;
272    }
273    fprintf( fp, "BssidNum=%d\n", count - 1 );
274    if( nvram_match( "wl0_net_mode", "bg-mixed" ) )
275        fprintf( fp, "WirelessMode=0\n" );
276    if( nvram_match( "wl0_net_mode", "b-only" ) )
277        fprintf( fp, "WirelessMode=1\n" );
278    if( nvram_match( "wl0_net_mode", "g-only" ) )
279        fprintf( fp, "WirelessMode=4\n" );
280    if( nvram_match( "wl0_net_mode", "n-only" ) )
281        fprintf( fp, "WirelessMode=6\n" );
282    if( nvram_match( "wl0_net_mode", "mixed" ) )
283        fprintf( fp, "WirelessMode=9\n" );
284
285    char hidestr[64];
286
287    hidestr[0] = 0;
288
289    if( nvram_nmatch( "1", "wl0_closed" ) )
290        strcat( hidestr, "1" );
291    else
292        strcat( hidestr, "0" );
293
294    vifs = nvram_get( "wl0_vifs" );
295    if( vifs != NULL )
296        foreach( var, vifs, next )
297    {
298        if( nvram_nmatch( "1", "%s_closed", var ) )
299            strcat( hidestr, ";1" );
300        else
301            strcat( hidestr, ";0" );
302    }
303    fprintf( fp, "HideSSID=%s\n", hidestr );
304    fprintf( fp, "ShortSlot=%s\n",
305             nvram_match( "wl0_shortslot", "long" ) ? "0" : "1" );
306    if( nvram_match( "wl0_channel", "0" ) )
307        fprintf( fp, "AutoChannelSelect=1\n" );
308    else
309        fprintf( fp, "AutoChannelSelect=0\n" );
310
311//encryption setup
312    fprintf( fp, "IEEE8021X=0\n" );
313    fprintf( fp, "IEEE80211H=0\n" );
314    char keyidstr[64] = { 0 };
315    char encryptype[64] = { 0 };
316    char authmode[64] = { 0 };
317
318    if( nvram_match( "wl0_key", "" ) )
319        strcat( keyidstr, "1" );
320    else
321        strcat( keyidstr, nvram_safe_get( "wl0_key" ) );
322    if( nvram_match( "wl0_akm", "wep" ) )
323    {
324        strcat( authmode, "OPEN" );
325        strcat( encryptype, "WEP" );
326        fprintf( fp, "Key1Str1=%s\n", nvram_safe_get( "wl0_key1" ) );
327        fprintf( fp, "Key2Str1=%s\n", nvram_safe_get( "wl0_key2" ) );
328        fprintf( fp, "Key3Str1=%s\n", nvram_safe_get( "wl0_key3" ) );
329        fprintf( fp, "Key4Str1=%s\n", nvram_safe_get( "wl0_key4" ) );
330        fprintf( fp, "Key1Type=0\n" );
331        fprintf( fp, "Key2Type=0\n" );
332        fprintf( fp, "Key3Type=0\n" );
333        fprintf( fp, "Key4Type=0\n" );
334
335    }
336    if( nvram_match( "wl0_akm", "disabled" ) )
337    {
338        strcat( authmode, "OPEN" );
339        strcat( encryptype, "NONE" );
340    }
341    if( nvram_match( "wl0_akm", "psk2" ) )
342    {
343        fprintf( fp, "WPAPSK1=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
344        strcat( authmode, "WPAPSK2" );
345        if( nvram_match( "wl0_crypto", "tkip" ) )
346            strcat( encryptype, "TKIP" );
347        if( nvram_match( "wl0_crypto", "aes" ) )
348            strcat( encryptype, "AES" );
349        if( nvram_match( "wl0_crypto", "tkip+aes" ) )
350            strcat( encryptype, "TKIPAES" );
351    }
352    if( nvram_match( "wl0_akm", "psk psk2" ) )
353    {
354        fprintf( fp, "WPAPSK1=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
355        strcat( authmode, "WPAPSKWPAPSK2" );
356        if( nvram_match( "wl0_crypto", "tkip" ) )
357            strcat( encryptype, "TKIP" );
358        if( nvram_match( "wl0_crypto", "aes" ) )
359            strcat( encryptype, "AES" );
360        if( nvram_match( "wl0_crypto", "tkip+aes" ) )
361            strcat( encryptype, "TKIPAES" );
362    }
363
364    if( nvram_match( "wl0_akm", "psk" ) )
365    {
366        fprintf( fp, "WPAPSK1=%s\n", nvram_safe_get( "wl0_wpa_psk" ) );
367        strcat( authmode, "WPAPSK" );
368        if( nvram_match( "wl0_crypto", "tkip" ) )
369            strcat( encryptype, "TKIP" );
370        if( nvram_match( "wl0_crypto", "aes" ) )
371            strcat( encryptype, "AES" );
372        if( nvram_match( "wl0_crypto", "tkip+aes" ) )
373            strcat( encryptype, "TKIPAES" );
374    }
375
376    count = 2;
377    vifs = nvram_get( "wl0_vifs" );
378    if( vifs != NULL )
379        foreach( var, vifs, next )
380    {
381        strcat( keyidstr, ";" );
382        if( nvram_nmatch( "", "%s_key", var ) )
383            strcat( keyidstr, "1" );
384        else
385            strcat( keyidstr, nvram_nget( "%s_key", var ) );
386        if( nvram_nmatch( "wep", "%s_akm", var ) )
387        {
388            fprintf( fp, "Key1Str%d=%s\n", count,
389                     nvram_nget( "%s_key1", var ) );
390            fprintf( fp, "Key2Str%d=%s\n", count,
391                     nvram_nget( "%s_key2", var ) );
392            fprintf( fp, "Key3Str%d=%s\n", count,
393                     nvram_nget( "%s_key3", var ) );
394            fprintf( fp, "Key4Str%d=%s\n", count,
395                     nvram_nget( "%s_key4", var ) );
396        }
397        if( nvram_nmatch( "psk", "%s_akm", var ) )
398        {
399            fprintf( fp, "WPAPSK%d=%s\n", count,
400                     nvram_nget( "%s_wpa_psk", var ) );
401            strcat( authmode, ";WPAPSK" );
402            if( nvram_nmatch( "tkip", "%s_crypto", var ) )
403                strcat( encryptype, ";TKIP" );
404            if( nvram_nmatch( "aes", "%s_crypto", var ) )
405                strcat( encryptype, ";AES" );
406            if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
407                strcat( encryptype, ";TKIPAES" );
408        }
409        if( nvram_nmatch( "disabled", "%s_akm", var ) )
410        {
411            strcat( authmode, ";OPEN" );
412            strcat( encryptype, ";NONE" );
413        }
414        if( nvram_nmatch( "psk psk2", "%s_akm", var ) )
415        {
416            fprintf( fp, "WPAPSK%d=%s\n", count,
417                     nvram_nget( "%s_wpa_psk", var ) );
418            strcat( authmode, ";WPAPSKWPA2PSK" );
419            if( nvram_nmatch( "tkip", "%s_crypto", var ) )
420                strcat( encryptype, ";TKIP" );
421            if( nvram_nmatch( "aes", "%s_crypto", var ) )
422                strcat( encryptype, ";AES" );
423            if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
424                strcat( encryptype, ";TKIPAES" );
425        }
426        if( nvram_nmatch( "psk2", "%s_akm", var ) )
427        {
428            fprintf( fp, "WPAPSK%d=%s\n", count,
429                     nvram_nget( "%s_wpa_psk", var ) );
430            strcat( authmode, ";WPAPSK2" );
431            if( nvram_nmatch( "tkip", "%s_crypto", var ) )
432                strcat( encryptype, ";TKIP" );
433            if( nvram_nmatch( "aes", "%s_crypto", var ) )
434                strcat( encryptype, ";AES" );
435            if( nvram_nmatch( "tkip+aes", "%s_crypto", var ) )
436                strcat( encryptype, ";TKIPAES" );
437        }
438
439        count++;
440    }
441
442    fprintf( fp, "DefaultKeyID=%s\n", keyidstr );
443    fprintf( fp, "EncrypType=%s\n", encryptype );
444    fprintf( fp, "AuthMode=%s\n", authmode );
445
446//wds entries
447    char wdsentries[128] = { 0 };
448    int wdscount = 0;
449    int s;
450
451    for( s = 1; s <= 10; s++ )
452    {
453        char wdsvarname[32] = { 0 };
454        char wdsdevname[32] = { 0 };
455        char wdsmacname[32] = { 0 };
456        char *wdsdev;
457        char *hwaddr;
458        char *dev = "wl0";
459
460        sprintf( wdsvarname, "%s_wds%d_enable", dev, s );
461        sprintf( wdsdevname, "%s_wds%d_if", dev, s );
462        sprintf( wdsmacname, "%s_wds%d_hwaddr", dev, s );
463        wdsdev = nvram_safe_get( wdsdevname );
464        if( strlen( wdsdev ) == 0 )
465            continue;
466        if( nvram_match( wdsvarname, "0" ) )
467            continue;
468        hwaddr = nvram_get( wdsmacname );
469        if( hwaddr != NULL )
470        {
471            sprintf( wdsentries, "%s;%s", wdsentries, hwaddr );
472            wdscount++;
473        }
474    }
475
476    if( wdscount )
477    {
478        if( nvram_match( "wl0_lazy_wds", "1" ) )
479            fprintf( fp, "WdsEnable=4\n" );     // 2 is exclusive
480        else
481            fprintf( fp, "WdsEnable=3\n" );     // 2 is exclusive
482        fprintf( fp, "WdsEncrypType=NONE\n" );  //for now we do not support encryption
483        fprintf( fp, "WdsList=%s\n", wdsentries );
484        fprintf( fp, "WdsKey=\n" );
485    }
486    else
487    {
488        fprintf( fp, "WdsEnable=0\n" );
489        fprintf( fp, "WdsEncrypType=NONE\n" );
490        fprintf( fp, "WdsList=\n" );
491        fprintf( fp, "WdsKey=\n" );
492
493    }
494
495//channel width
496    if( nvram_match( "wl0_nbw", "20" ) )
497        fprintf( fp, "HT_BW=0\n" );
498    else
499        fprintf( fp, "HT_BW=1\n" );
500
501    int channel = atoi( nvram_safe_get( "wl0_channel" ) );
502
503    if( channel <= 4 )
504        fprintf( fp, "HT_EXTCHA=1\n" );
505    else if( channel >= 8 )
506        fprintf( fp, "HT_EXTCHA=0\n" );
507    else
508        fprintf( fp, "HT_EXTCHA=0\n" );
509
510    if( nvram_default_match( "wl0_greenfield", "1", "0" ) )
511        fprintf( fp, "HT_OpMode=1\n" ); // green field mode
512    else
513        fprintf( fp, "HT_OpMode=0\n" );
514
515    int mcs = atoi( nvram_default_get( "wl0_nmcsidx", "-1" ) );
516
517    if( mcs == -1 )
518        fprintf( fp, "HT_MCS=33\n" );
519    else
520        fprintf( fp, "HT_MCS=%d\n", mcs );
521
522//txrate
523    if( nvram_match( "wl0_rate", "0" ) )
524        fprintf( fp, "TxRate=0\n" );
525    else if( nvram_match( "wl0_rate", "1000000" ) )
526        fprintf( fp, "TxRate=1\n" );
527    else if( nvram_match( "wl0_rate", "2000000" ) )
528        fprintf( fp, "TxRate=2\n" );
529    else if( nvram_match( "wl0_rate", "5500000" ) )
530        fprintf( fp, "TxRate=3\n" );
531    else if( nvram_match( "wl0_rate", "6000000" ) )
532        fprintf( fp, "TxRate=5\n" );
533    else if( nvram_match( "wl0_rate", "9000000" ) )
534        fprintf( fp, "TxRate=6\n" );
535    else if( nvram_match( "wl0_rate", "1100000" ) )
536        fprintf( fp, "TxRate=4\n" );
537    else if( nvram_match( "wl0_rate", "1200000" ) )
538        fprintf( fp, "TxRate=7\n" );
539    else if( nvram_match( "wl0_rate", "1800000" ) )
540        fprintf( fp, "TxRate=8\n" );
541    else if( nvram_match( "wl0_rate", "2400000" ) )
542        fprintf( fp, "TxRate=9\n" );
543    else if( nvram_match( "wl0_rate", "3600000" ) )
544        fprintf( fp, "TxRate=10\n" );
545    else if( nvram_match( "wl0_rate", "4800000" ) )
546        fprintf( fp, "TxRate=11\n" );
547    else if( nvram_match( "wl0_rate", "5400000" ) )
548        fprintf( fp, "TxRate=12\n" );
549    else
550        fprintf( fp, "TxRate=0\n" );
551
552    fprintf( fp, "Channel=%s\n", nvram_safe_get( "wl0_channel" ) );
553    if( nvram_match( "wl0_rateset", "12" ) )
554        fprintf( fp, "BasicRate=3\n" );
555    if( nvram_match( "wl0_rateset", "default" ) )
556        fprintf( fp, "BasicRate=15\n" );
557    if( nvram_match( "wl0_rateset", "all" ) )
558        fprintf( fp, "BasicRate=351\n" );
559    fprintf( fp, "BeaconPeriod=%s\n", nvram_safe_get( "wl0_bcn" ) );
560    fprintf( fp, "DtimPeriod=%s\n", nvram_safe_get( "wl0_dtim" ) );
561    fprintf( fp, "TxPower=%s\n", nvram_safe_get( "wl0_txpwr" ) );       // warning. percentage this time
562    fprintf( fp, "DisableOLBC=0\n" );   //what is this?
563    fprintf( fp, "BGProtection=%s\n",
564             nvram_match( "wl0_gmode_protection", "auto" ) ? "0" : "2" );
565    fprintf( fp, "TXPreamble=%s\n",
566             nvram_match( "wl0_plcphdr", "long" ) ? "0" : "1" );
567    fprintf( fp, "RTSThreshold=%s\n", nvram_safe_get( "wl0_rts" ) );
568    fprintf( fp, "FragThreshold=%s\n", nvram_safe_get( "wl0_frag" ) );
569    fprintf( fp, "TxBurst=%s\n",
570             nvram_match( "wl0_frameburst", "on" ) ? "0" : "1" );
571    fprintf( fp, "PktAggregate=0\n" );
572    fprintf( fp, "TurboRate=0\n" );
573    fprintf( fp, "wmm=%s\n", nvram_match( "wl0_wme", "on" ) ? "1" : "0" );
574    fprintf( fp, "APAifsn=3;7;1;1\n" );
575    fprintf( fp, "APCwmin=4;4;3;2\n" );
576    fprintf( fp, "APCwmax=6;10;4;3\n" );
577    fprintf( fp, "APTxop=0;0;94;47\n" );
578    fprintf( fp, "APACM=0;0;0;0\n" );
579    fprintf( fp, "BSSAifsn=3;7;2;2\n" );
580    fprintf( fp, "BSSCwmin=4;4;3;2\n" );
581    fprintf( fp, "BSSCwmax=10;10;4;3\n" );
582    fprintf( fp, "BSSTxop=0;0;94;47\n" );
583    fprintf( fp, "BSSACM=0;0;0;0\n" );
584    fprintf( fp, "AckPolicy=0;0;0;0\n" );
585    fprintf( fp, "NoForwarding=%s\n", nvram_safe_get( "wl0_ap_isolate" ) );     //between lan and ap
586    fprintf( fp, "NoForwardingBTNBSSID=%s\n", nvram_safe_get( "wl0_ap_isolate" ) );     // between bssid
587
588//station
589
590    if( getSTA(  ) || getWET(  ) )
591    {
592        fprintf( fp, "ApCliEnable=1\n" );
593        fprintf( fp, "ApCliSsid=%s\n", nvram_safe_get( "wl0_ssid" ) );
594        if( nvram_match( "wl0_akm", "psk" )
595            || nvram_match( "wl0_akm", "psk2" )
596            || nvram_match( "wl0_akm", "psk psk2" ) )
597        {
598            if( nvram_match( "wl0_akm", "psk" ) )
599            {
600                if( nvram_match( "wl0_crypto", "tkip" ) )
601                    fprintf( fp, "ApCliEncrypType=TKIP\n" );
602                if( nvram_match( "wl0_crypto", "aes" ) )
603                    fprintf( fp, "ApCliEncrypType=AES\n" );
604                if( nvram_match( "wl0_crypto", "tkip+aes" ) )
605                    fprintf( fp, "ApCliEncrypType=TKIPAES\n" );
606                fprintf( fp, "ApCliAuthMode=WPAPSK\n" );
607            }
608            if( nvram_match( "wl0_akm", "psk2" ) )
609            {
610                if( nvram_match( "wl0_crypto", "tkip" ) )
611                    fprintf( fp, "ApCliEncrypType=TKIP\n" );
612                if( nvram_match( "wl0_crypto", "aes" ) )
613                    fprintf( fp, "ApCliEncrypType=AES\n" );
614                if( nvram_match( "wl0_crypto", "tkip+aes" ) )
615                    fprintf( fp, "ApCliEncrypType=TKIPAES\n" );
616                fprintf( fp, "ApCliAuthMode=WPA2PSK\n" );
617            }
618            fprintf( fp, "ApCliWPAPSK=%s\n",
619                     nvram_safe_get( "wl0_wpa_psk" ) );
620        }
621        if( nvram_match( "wl0_akm", "disabled" ) )
622        {
623            fprintf( fp, "ApCliEncrypType=NONE\n" );
624            fprintf( fp, "ApCliAuthMode=OPEN\n" );
625        }
626        if( nvram_match( "wl0_akm", "wep" ) )
627        {
628            fprintf( fp, "ApCliEncrypType=WEP\n" );
629            fprintf( fp, "ApCliAuthMode=OPEN\n" );
630            fprintf( fp, "ApCliDefaultKeyID=%s\n",
631                     nvram_safe_get( "wl0_key" ) );
632            fprintf( fp, "ApCliKey1Type=0\n" );
633            fprintf( fp, "ApCliKey2Type=0\n" );
634            fprintf( fp, "ApCliKey3Type=0\n" );
635            fprintf( fp, "ApCliKey4Type=0\n" );
636            fprintf( fp, "ApCliKey1Str=%s\n", nvram_safe_get( "wl0_key1" ) );
637            fprintf( fp, "ApCliKey2Str=%s\n", nvram_safe_get( "wl0_key2" ) );
638            fprintf( fp, "ApCliKey3Str=%s\n", nvram_safe_get( "wl0_key3" ) );
639            fprintf( fp, "ApCliKey4Str=%s\n", nvram_safe_get( "wl0_key4" ) );
640        }
641    }
642    else
643    {
644        fprintf( fp, "ApCliEnable=0\n" );
645    }
646
647    fprintf( fp, "CSPeriod=10\n" );
648    fprintf( fp, "WirelessEvent=0\n" );
649    fprintf( fp, "PreAuth=0\n" );
650    fprintf( fp, "RekeyInterval=0\n" );
651    fprintf( fp, "RekeyMethod=DISABLE\n" );
652    fprintf( fp, "PMKCachePeriod=10\n" );
653    fprintf( fp, "HSCounter=0\n" );
654    fprintf( fp, "AccessPolicy0=0\n" );
655    fprintf( fp, "AccessControlList0=\n" );
656    fprintf( fp, "AccessPolicy1=0\n" );
657    fprintf( fp, "AccessControlList1=\n" );
658    fprintf( fp, "AccessPolicy2=0\n" );
659    fprintf( fp, "AccessControlList2=\n" );
660    fprintf( fp, "AccessPolicy3=0\n" );
661    fprintf( fp, "AccessControlList3=\n" );
662    fprintf( fp, "RADIUS_Server=192.168.2.3\n" );
663    fprintf( fp, "RADIUS_Port=1812\n" );
664    fprintf( fp, "RADIUS_Key=ralink\n" );
665    fprintf( fp, "own_ip_addr=192.168.5.234\n" );
666    fprintf( fp, "EAPifname=br0\n" );
667    fprintf( fp, "PreAuthifname=br0\n" );
668    fprintf( fp, "HT_HTC=0\n" );
669    fprintf( fp, "HT_RDG=1\n" );
670    fprintf( fp, "HT_LinkAdapt=0\n" );
671    fprintf( fp, "HT_MpduDensity=5\n" );
672    fprintf( fp, "HT_AutoBA=1\n" );
673    fprintf( fp, "HT_AMSDU=0\n" );
674    fprintf( fp, "HT_BAWinSize=64\n" );
675    fprintf( fp, "HT_GI=1\n" );
676    fprintf( fp, "HT_STBC=1\n" );
677
678    fclose( fp );
679    insmod( "rt2860v2_ap" );
680
681    char *dev = "wl0";
682    char bridged[32];
683
684
685
686    sprintf( bridged, "%s_bridged", getRADev( dev ) );
687    if( nvram_default_match( bridged, "1", "1" ) )
688    {
689    if( getSTA(  ) || getWET(  ) )
690        {
691        sysprintf( "ifconfig ra0 0.0.0.0 up");
692        sysprintf( "ifconfig %s 0.0.0.0 up", "apcli0" );       
693        br_add_interface( getBridge( "ra0" ), "ra0" );
694        }else{
695        sysprintf( "ifconfig %s 0.0.0.0 up", "ra0" );
696        br_add_interface( getBridge( "ra0" ), "ra0" );
697        }
698    }
699    else
700    {
701    if( getSTA(  ) || getWET(  ) )
702        {
703        sysprintf( "ifconfig ra0 0.0.0.0 up");
704        sysprintf( "ifconfig %s mtu 1500", "apcli0" );
705        sysprintf( "ifconfig %s %s netmask %s up", "ra0",
706                   nvram_nget( "%s_ipaddr", getRADev( dev ) ),
707                   nvram_nget( "%s_netmask", getRADev( dev ) ) );       
708        }else
709        {
710        sysprintf( "ifconfig %s mtu 1500", "ra0" );
711        sysprintf( "ifconfig %s %s netmask %s up", "ra0",
712                   nvram_nget( "%s_ipaddr", getRADev( dev ) ),
713                   nvram_nget( "%s_netmask", getRADev( dev ) ) );
714        }
715    }
716    char vathmac[32];
717
718    sprintf( vathmac, "wl0_hwaddr" );
719    char vmacaddr[32];
720
721    getMacAddr( "ra0", vmacaddr );
722    nvram_set( vathmac, vmacaddr );
723
724    vifs = nvram_safe_get( "wl0_vifs" );
725    if( vifs != NULL && strlen( vifs ) > 0 )
726    {
727        int count = 1;
728
729        foreach( var, vifs, next )
730        {
731
732            sprintf( bridged, "%s_bridged", getRADev( var ) );
733            if( nvram_default_match( bridged, "1", "1" ) )
734            {
735                char ra[32];
736
737                sprintf( ra, "ra%d", count );
738                sysprintf( "ifconfig ra%d 0.0.0.0 up", count );
739                br_add_interface( getBridge( getRADev( var ) ), ra );
740            }
741            else
742            {
743                char ip[32];
744                char mask[32];
745
746                sprintf( ip, "%s_ipaddr", getRADev( var ) );
747                sprintf( mask, "%s_netmask", getRADev( var ) );
748                sysprintf( "ifconfig ra%d mtu 1500", count );
749                sysprintf( "ifconfig ra%d %s netmask %s up", count,
750                           nvram_safe_get( ip ), nvram_safe_get( mask ) );
751            }
752
753            sprintf( vathmac, "%s_hwaddr", var );
754            getMacAddr( getRADev( var ), vmacaddr );
755            nvram_set( vathmac, vmacaddr );
756
757            count++;
758        }
759    }
760
761    for( s = 1; s <= 10; s++ )
762    {
763        char wdsvarname[32] = { 0 };
764        char wdsdevname[32] = { 0 };
765        char wdsmacname[32] = { 0 };
766        char *wdsdev;
767        char *dev = "wl0";
768        char *hwaddr;
769
770        sprintf( wdsvarname, "%s_wds%d_enable", dev, ( 11 - s ) );
771        sprintf( wdsdevname, "%s_wds%d_if", dev, ( 11 - s ) );
772        sprintf( wdsmacname, "%s_wds%d_hwaddr", dev, ( 11 - s ) );
773        wdsdev = nvram_safe_get( wdsdevname );
774        if( strlen( wdsdev ) == 0 )
775            continue;
776        if( nvram_match( wdsvarname, "0" ) )
777            continue;
778        hwaddr = nvram_get( wdsmacname );
779        if( hwaddr != NULL )
780        {
781            char *newdev = getWDSDev( wdsdev );
782
783            sysprintf( "ifconfig %s 0.0.0.0 up", newdev );
784        }
785    }
786    start_radius(  );
787}
788
789void start_configurewifi( void )
790{
791    configure_wifi(  );
792}
793
794void start_deconfigurewifi( void )
795{
796    deconfigure_wifi(  );
797}
798#endif
Note: See TracBrowser for help on using the repository browser.