root/src/router/services/sysinit/sysinit-wrt54g2v11.c

Revision 12405, 5.3 kB (checked in by BrainSlayer, 5 months ago)

vlan8 and vlan7 fix on wrt54g2v1.1 (tested)

Line 
1 /*
2  * sysinit-fonera.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/socket.h>
38 #include <sys/sysmacros.h>
39 #include <sys/ioctl.h>
40 #include <sys/time.h>
41 #include <sys/utsname.h>
42 #include <sys/wait.h>
43 #include <linux/if_ether.h>
44 #include <linux/mii.h>
45 #include <linux/sockios.h>
46 #include <net/if.h>
47
48 #include <arpa/inet.h>
49 #include <sys/socket.h>
50 #include <linux/sockios.h>
51 #include <linux/mii.h>
52
53 #include <bcmnvram.h>
54 #include <shutils.h>
55 #include <utils.h>
56 #include <cymac.h>
57
58 extern void vlan_init(int num);
59
60 void start_sysinit(void)
61 {
62         char buf[PATH_MAX];
63         struct utsname name;
64         struct stat tmp_stat;
65         time_t tm = 0;
66
67         unlink("/etc/nvram/.lock");
68         cprintf("sysinit() proc\n");
69         /*
70          * /proc
71          */
72         mount("proc", "/proc", "proc", MS_MGC_VAL, NULL);
73         mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL);
74         cprintf("sysinit() tmp\n");
75
76         /*
77          * /tmp
78          */
79         mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
80         // fix for linux kernel 2.6
81         mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL);
82         eval("mkdir", "/tmp/www");
83         eval("mknod", "/dev/nvram", "c", "229", "0");
84         eval("mknod", "/dev/ppp", "c", "108", "0");
85         eval("mknod", "-m", "0660", "/dev/mmc", "b", "126", "0");
86         eval("mknod", "-m", "0660", "/dev/mmc0", "b", "126", "1");
87         eval("mknod", "-m", "0660", "/dev/mmc1", "b", "126", "2");
88         eval("mknod", "-m", "0660", "/dev/mmc2", "b", "126", "3");
89         eval("mknod", "-m", "0660", "/dev/mmc3", "b", "126", "4");
90
91         unlink("/tmp/nvram/.lock");
92         eval("mkdir", "/tmp/nvram");
93         eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/");
94         FILE *in = fopen("/tmp/nvram/nvram.db", "rb");
95
96         if (in != NULL) {
97                 fclose(in);
98                 eval("/usr/sbin/convertnvram");
99                 eval("/sbin/mtd", "erase", "nvram");
100                 nvram_commit();
101         }
102         cprintf("sysinit() var\n");
103
104         /*
105          * /var
106          */
107         mkdir("/tmp/var", 0777);
108         mkdir("/var/lock", 0777);
109         mkdir("/var/log", 0777);
110         mkdir("/var/run", 0777);
111         mkdir("/var/tmp", 0777);
112         cprintf("sysinit() setup console\n");
113         if (!nvram_match("disable_watchdog", "1"))
114                 eval("watchdog");
115         /*
116          * Setup console
117          */
118
119         cprintf("sysinit() klogctl\n");
120         klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
121         cprintf("sysinit() get router\n");
122
123         /*
124          * Modules
125          */
126         uname(&name);
127         /*
128          * network drivers
129          */
130         insmod("ar2313");
131         insmod("ath_hal");
132         if (nvram_get("rate_control") != NULL) {
133                 char rate[64];
134
135                 sprintf(rate, "ratectl=%s", nvram_safe_get("rate_control"));
136                 eval("insmod", "ath_ahb", rate);
137         } else {
138                 insmod("ath_ahb");
139         }
140
141         eval("ifconfig", "eth0", "up"); // wan
142         system("swconfig dev eth0 set reset 1");
143         system("swconfig dev eth0 set vlan 1");
144         system("swconfig dev eth0 vlan 1 set ports \"0t 2 3 4 5\"");
145         system("swconfig dev eth0 vlan 2 set ports \"0t 1\"");
146         system("swconfig dev eth0 set apply");
147         eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
148         eval("vconfig", "add", "eth0", "1");
149         eval("vconfig", "add", "eth0", "2");
150
151         struct ifreq ifr;
152         int s;
153
154         if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
155                 char eabuf[32];
156
157                 strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
158                 ioctl(s, SIOCGIFHWADDR, &ifr);
159                 char macaddr[32];
160
161                 strcpy(macaddr,
162                        ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
163                                   eabuf));
164                 nvram_set("et0macaddr", macaddr);
165                 MAC_ADD(macaddr);
166                 ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data);
167                 strncpy(ifr.ifr_name, "vlan2", IFNAMSIZ);
168                 ioctl(s, SIOCSIFHWADDR, &ifr);
169                 close(s);
170         }
171         eval("gpio", "enable", "1");
172         system2("echo 0 >/proc/sys/dev/wifi0/ledpin");
173         system2("echo 1 >/proc/sys/dev/wifi0/softled");
174         /*
175          * Set a sane date
176          */
177         stime(&tm);
178         nvram_set("wl0_ifname", "ath0");
179
180         return;
181 }
182
183 int check_cfe_nv(void)
184 {
185         nvram_set("portprio_support", "0");
186         return 0;
187 }
188
189 int check_pmon_nv(void)
190 {
191         return 0;
192 }
193
194 void start_overclocking(void)
195 {
196 }
197
198 char *enable_dtag_vlan(int enable)
199 {
200     if (enable) {
201         system("swconfig dev eth0 set reset 1");
202         system("swconfig dev eth0 set vlan 1");
203         system("swconfig dev eth0 vlan 1 set ports \"0t 2 3 4 5\"");
204         system("swconfig dev eth0 vlan 7 set ports \"0t 1t\"");
205         system("swconfig dev eth0 vlan 8 set ports \"0t 1t\"");
206         system("swconfig dev eth0 set apply");
207     }else{
208         system("swconfig dev eth0 set reset 1");
209         system("swconfig dev eth0 set vlan 1");
210         system("swconfig dev eth0 vlan 1 set ports \"0t 2 3 4 5\"");
211         system("swconfig dev eth0 vlan 2 set ports \"0t 1\"");
212         system("swconfig dev eth0 set apply");
213    
214     }
215     return "eth0";
216 }
Note: See TracBrowser for help on using the browser.