source: src/router/services/sysinit/sysinit-whrag108.c @ 11280

Last change on this file since 11280 was 11280, checked in by BrainSlayer, 4 years ago

allow rate control settings for wisoc devices

File size: 6.3 KB
Line 
1/*
2 * sysinit-whrag108.c
3 *
4 * Copyright (C) 2006 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#include <stdio.h>
23#include <stdlib.h>
24#include <limits.h>
25#include <time.h>
26#include <unistd.h>
27#include <errno.h>
28#include <syslog.h>
29#include <signal.h>
30#include <string.h>
31#include <termios.h>
32#include <sys/klog.h>
33#include <sys/types.h>
34#include <sys/mount.h>
35#include <sys/reboot.h>
36#include <sys/stat.h>
37#include <sys/sysmacros.h>
38#include <sys/time.h>
39#include <sys/utsname.h>
40#include <sys/wait.h>
41#include <sys/ioctl.h>
42
43#include <bcmnvram.h>
44#include <shutils.h>
45#include <utils.h>
46
47#define SIOCGMIIREG     0x8948  /* Read MII PHY register.  */
48#define SIOCSMIIREG     0x8949  /* Write MII PHY register.  */
49#include <arpa/inet.h>
50#include <sys/socket.h>
51#include <linux/if.h>
52#include <linux/sockios.h>
53#include <linux/mii.h>
54
55// highly experimental
56
57void setRegister( int socket, short reg, short value )
58{
59    // struct mii_ioctl_data data;
60    struct ifreq ifr;
61    unsigned short *data = ( unsigned short * )( &ifr.ifr_data );
62
63    data[0] = 0;
64    data[1] = reg;
65    data[2] = value;
66    ( void )strncpy( ifr.ifr_name, "eth0", sizeof( "eth0" ) );
67    // data.reg_num = reg;
68    // data.val_in = value;
69    ioctl( socket, SIOCSMIIREG, &ifr );
70}
71
72void switch_main( int argc, char *argv[] )
73{
74    int reg = atoi( argv[1] );
75    int val = atoi( argv[2] );
76    int s = socket( AF_INET, SOCK_DGRAM, 0 );
77
78    if( s < 0 )
79    {
80        return;
81    }
82    setRegister( s, reg, val );
83    close( s );
84}
85
86void setupSwitch( void )
87{
88    int s = socket( AF_INET, SOCK_DGRAM, 0 );
89
90    if( s < 0 )
91    {
92        return;
93    }
94    // setRegister(s,0x02,0xa0);
95
96    // Enable 8021Q (80) and IGMP snooping (40)
97    // setRegister(s,0x05,0xa0);
98    // vlan1: valid,5,2,1 port fid=1 vid=1
99    // setRegister(s,0x76,0x21);
100    // setRegister(s,0x77,0x10);
101    // setRegister(s,0x78,0x01);
102    // write (04) and trigger address 0
103    // setRegister(s,0x6E,0x04);
104    // setRegister(s,0x6F,0x00);
105    // vlan2: valid,5,4,3 port fid=2 vid=2
106    // setRegister(s,0x76,0x3E);
107    // setRegister(s,0x77,0x20);
108    // setRegister(s,0x78,0x02);
109
110    // write (04) and trigger address 0
111    // setRegister(s,0x6E,0x04);
112    // setRegister(s,0x6F,0x01);
113
114    // config port 1,2 to VLAN id 1
115    setRegister( s, 0x14, 0x01 );
116    // config port 1,2 to filter vid 1
117    setRegister( s, 0x12, 0x46 );
118
119    // config port 3,4 to VLAN id 2
120    setRegister( s, 0x24, 0x02 );
121    setRegister( s, 0x34, 0x02 );
122    setRegister( s, 0x44, 0x02 );
123    setRegister( s, 0x54, 0x02 );
124    // config port 3,4 to filter vid 2
125    setRegister( s, 0x22, 0x46 );
126    setRegister( s, 0x32, 0x46 );
127    setRegister( s, 0x42, 0x46 );
128    setRegister( s, 0x52, 0x46 );
129
130    // for IGMP, disenable special tagging
131    // setRegister(s,0x0b,0x01);
132    // enable vlan tag insertion por 5
133    // setRegister(s,0x50,0x04);
134    // setRegister(s,0x52,0x06);
135    // remove it from all others
136    setRegister( s, 0x10, 0x02 );
137    setRegister( s, 0x20, 0x02 );
138    setRegister( s, 0x30, 0x02 );
139    setRegister( s, 0x40, 0x02 );
140    setRegister( s, 0x50, 0x02 );
141    // switch enable
142    setRegister( s, 0x01, 0x01 );
143    close( s );
144
145}
146
147void start_sysinit( void )
148{
149    char buf[PATH_MAX];
150    struct utsname name;
151    struct stat tmp_stat;
152    time_t tm = 0;
153
154    unlink( "/etc/nvram/.lock" );
155    cprintf( "sysinit() proc\n" );
156    /*
157     * /proc
158     */
159    mount( "proc", "/proc", "proc", MS_MGC_VAL, NULL );
160    mount( "sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL );
161    cprintf( "sysinit() tmp\n" );
162
163    /*
164     * /tmp
165     */
166    mount( "ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL );
167    // fix for linux kernel 2.6
168    mount( "devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL );
169    eval( "mkdir", "/tmp/www" );
170    eval( "mknod", "/dev/nvram", "c", "229", "0" );
171    eval( "mknod", "/dev/ppp", "c", "108", "0" );
172
173    unlink( "/tmp/nvram/.lock" );
174    eval( "mkdir", "/tmp/nvram" );
175    eval( "/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/" );
176    FILE *in = fopen( "/tmp/nvram/nvram.db", "rb" );
177
178    if( in != NULL )
179    {
180        fclose( in );
181        eval( "/usr/sbin/convertnvram" );
182        eval( "/sbin/mtd", "erase", "nvram" );
183        nvram_commit(  );
184    }
185    cprintf( "sysinit() var\n" );
186
187    /*
188     * /var
189     */
190    mkdir( "/tmp/var", 0777 );
191    mkdir( "/var/lock", 0777 );
192    mkdir( "/var/log", 0777 );
193    mkdir( "/var/run", 0777 );
194    mkdir( "/var/tmp", 0777 );
195    cprintf( "sysinit() setup console\n" );
196    eval( "watchdog" );
197    /*
198     * Setup console
199     */
200
201    cprintf( "sysinit() klogctl\n" );
202    klogctl( 8, NULL, atoi( nvram_safe_get( "console_loglevel" ) ) );
203    cprintf( "sysinit() get router\n" );
204
205    int brand = getRouterBrand(  );
206
207    /*
208     * Modules
209     */
210    uname( &name );
211
212    /*
213     * network drivers
214     */
215    insmod( "ar2313" );
216
217    insmod( "ath_hal" );
218    if( nvram_get( "rate_control" ) != NULL )
219    {
220        char rate[64];
221
222        sprintf( rate, "ratectl=%s", nvram_safe_get( "rate_control" ) );
223        eval( "insmod", "ath_ahb", rate );
224    }
225    else
226    {
227        insmod( "ath_ahb" );
228    }
229
230    system2( "echo 2 >/proc/sys/dev/wifi0/ledpin" );
231    system2( "echo 1 >/proc/sys/dev/wifi0/softled" );
232    system2( "echo 3 >/proc/sys/dev/wifi1/ledpin" );
233    system2( "echo 1 >/proc/sys/dev/wifi1/softled" );
234
235    // eval ("ifconfig", "wifi0", "up");
236    // eval ("ifconfig", "wifi1", "up");
237
238    insmod( "ipv6" );
239
240    /*
241     * Set a sane date
242     */
243    stime( &tm );
244    nvram_set( "wl0_ifname", "ath0" );
245
246    return;
247    cprintf( "done\n" );
248}
249
250int check_cfe_nv( void )
251{
252    nvram_set( "portprio_support", "0" );
253    return 0;
254}
255
256int check_pmon_nv( void )
257{
258    return 0;
259}
260
261void start_overclocking( void )
262{
263}
264void enable_dtag_vlan( int enable )
265{
266
267}
Note: See TracBrowser for help on using the repository browser.