source: src/router/services/sysinit/sysinit-wrt400.c @ 18149

Last change on this file since 18149 was 18149, checked in by BrainSlayer, 18 months ago

test fix

File size: 8.4 KB
Line 
1/*
2 * sysinit-wrt400.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#include <cymac.h>
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#include "devices/wireless.c"
55
56void start_sysinit(void)
57{
58        time_t tm = 0;
59
60        if (!nvram_match("disable_watchdog", "1"))
61                eval("watchdog");
62        /*
63         * Setup console
64         */
65
66        cprintf("sysinit() klogctl\n");
67        klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
68        cprintf("sysinit() get router\n");
69
70        /*
71         * network drivers
72         */
73        fprintf(stderr, "load ag71xx or ag7100_mod Ethernet Driver\n");
74        system("insmod ag71xx || insmod ag7100_mod");
75        char mac1[32];
76        char mac2[32];
77        char wmac[32];
78        FILE *fp = fopen("/dev/mtdblock/7", "rb");
79        if (fp) {
80                char mactmp[6];
81                int copy[6];
82                int i;
83#ifdef HAVE_WNDR3700
84                system("swconfig dev rtl8366s set reset 1");
85                system("swconfig dev rtl8366s set enable_vlan 0");
86                system("swconfig dev rtl8366s set blinkrate 2");
87                system("swconfig dev rtl8366s port 1 set led 6");
88                system("swconfig dev rtl8366s port 2 set led 9");
89                system("swconfig dev rtl8366s port 5 set led 2");
90                system("swconfig dev rtl8366s set apply");
91
92#ifdef HAVE_WNDR3700V2
93                fseek(fp, 0xff0000, SEEK_SET);
94#else
95                fseek(fp, 0x7f0000, SEEK_SET);
96#endif
97                fread(mactmp, 6, 1, fp);
98                for (i = 0; i < 6; i++)
99                        copy[i] = mactmp[i];
100                for (i = 0; i < 6; i++)
101                        copy[i] &= 0xff;
102                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
103                        copy[1], copy[2], copy[3], copy[4], copy[5]);
104                fread(mactmp, 6, 1, fp);
105                for (i = 0; i < 6; i++)
106                        copy[i] = mactmp[i];
107                for (i = 0; i < 6; i++)
108                        copy[i] &= 0xff;
109                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
110                        copy[1], copy[2], copy[3], copy[4], copy[5]);
111                fread(mactmp, 6, 1, fp);
112                fclose(fp);
113                for (i = 0; i < 6; i++)
114                        copy[i] = mactmp[i];
115                for (i = 0; i < 6; i++)
116                        copy[i] &= 0xff;
117                sprintf(wmac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
118                        copy[1], copy[2], copy[3], copy[4], copy[5]);
119#elif HAVE_WZRHPAG300NH
120                system("swconfig dev eth0 set reset 1");
121                system("swconfig dev eth0 set enable_vlan 0");
122                system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 4\"");
123                system("swconfig dev eth0 set apply");
124                fseek(fp, 0x5120C, SEEK_SET);
125                fread(mactmp, 6, 1, fp);
126                fclose(fp);
127                for (i = 0; i < 6; i++)
128                        copy[i] = mactmp[i];
129                for (i = 0; i < 6; i++)
130                        copy[i] &= 0xff;
131                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
132                        copy[1], copy[2], copy[3], copy[4], copy[5]);
133                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
134                        copy[1], copy[2], copy[3], copy[4], copy[5]);
135                MAC_ADD(mac2);
136//              eval("gpio","enable","2");
137#elif HAVE_WZRG300NH2
138                sysprintf("startservice bootloader_check");
139                fseek(fp, 0x5120C, SEEK_SET);
140                fread(mactmp, 6, 1, fp);
141                fclose(fp);
142                for (i = 0; i < 6; i++)
143                        copy[i] = mactmp[i];
144                for (i = 0; i < 6; i++)
145                        copy[i] &= 0xff;
146                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
147                        copy[1], copy[2], copy[3], copy[4], copy[5]);
148                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
149                        copy[1], copy[2], copy[3], copy[4], copy[5]);
150//              eval("gpio","enable","13");
151                fprintf(stderr, "configure eth0 to %s\n", mac2);
152                eval("ifconfig", "eth0", "hw", "ether", mac2);
153                eval("ifconfig", "eth0", "up");
154                eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
155                eval("vconfig", "add", "eth0", "1");
156                eval("vconfig", "add", "eth0", "2");
157                fprintf(stderr, "configure vlan1 to %s\n", mac2);
158                eval("ifconfig", "vlan1", "hw", "ether", mac2);
159                fprintf(stderr, "configure vlan2 to %s\n", mac2);
160                eval("ifconfig", "vlan2", "hw", "ether", mac2);
161#elif HAVE_WZRG450
162                fseek(fp, 0x51002, SEEK_SET); //osprey eeprom mac location
163                fread(mactmp, 6, 1, fp);
164                fclose(fp);
165                for (i = 0; i < 6; i++)
166                        copy[i] = mactmp[i];
167                for (i = 0; i < 6; i++)
168                        copy[i] &= 0xff;
169                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
170                        copy[1], copy[2], copy[3], copy[4], copy[5]);
171                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
172                        copy[1], copy[2], copy[3], copy[4], copy[5]);
173//              mac1[0] |= 0x02; // add private bit
174//              mac2[0] |= 0x02;
175//              eval("gpio","disable","16");
176                fprintf(stderr, "configure eth0 to %s\n", mac2);
177                eval("ifconfig", "eth0", "hw", "ether", mac2);
178                eval("ifconfig", "eth0", "up");
179                eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
180                eval("vconfig", "add", "eth0", "1");
181                eval("vconfig", "add", "eth0", "2");
182                fprintf(stderr, "configure vlan1 to %s\n", mac2);
183                eval("ifconfig", "vlan1", "hw", "ether", mac2);
184                fprintf(stderr, "configure vlan2 to %s\n", mac2);
185                eval("ifconfig", "vlan2", "hw", "ether", mac2);
186#else
187                fseek(fp, 0x7f120c, SEEK_SET);
188                fread(mactmp, 6, 1, fp);
189                fclose(fp);
190                for (i = 5; i >= 3; i--)
191                        if (++mactmp[i] != 0x00)
192                                break;  // dont know what this is
193                for (i = 0; i < 6; i++)
194                        copy[i] = mactmp[i];
195                for (i = 0; i < 6; i++)
196                        copy[i] &= 0xff;
197                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
198                        copy[1], copy[2], copy[3], copy[4], copy[5]);
199                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
200                        copy[1], copy[2], copy[3], copy[4], copy[5]);
201                MAC_ADD(mac2);
202#endif
203
204        } else {
205                sprintf(mac1, "00:11:22:33:44:55");
206                sprintf(mac2, "00:11:22:33:44:66");
207        }
208#ifndef HAVE_WZRG450
209        eval("ifconfig", "eth0", "hw", "ether", mac1);
210        eval("ifconfig", "eth0", "up");
211        eval("ifconfig", "eth1", "hw", "ether", mac2);
212        eval("ifconfig", "eth1", "up");
213#else
214        eval("ifconfig", "eth0", "hw", "ether", mac2);
215        eval("ifconfig", "eth0", "up");
216#endif
217        struct ifreq ifr;
218        int s;
219
220        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
221                char eabuf[32];
222
223                strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
224                ioctl(s, SIOCGIFHWADDR, &ifr);
225                nvram_set("et0macaddr",
226                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
227                                     eabuf));
228                nvram_set("et0macaddr_safe",
229                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
230                                     eabuf));
231                close(s);
232        }
233        detect_wireless_devices();
234#ifdef HAVE_WZRHPAG300NH
235//      eval("ifconfig", "wifi1", "hw", "ether", wmac);
236        setWirelessLedPhy0(1);
237        setWirelessLedPhy1(5);
238
239#else
240#ifndef HAVE_WNDR3700
241
242#ifdef HAVE_WZRG300NH2
243        setWirelessLedPhy0(5);
244#else
245#ifndef HAVE_WZRG450
246        setWirelessLedGeneric(0,6);
247        setWirelessLedGeneric(1,6);
248#endif
249#endif
250#else
251        eval("ifconfig", "wifi0", "hw", "ether", mac1);
252        eval("ifconfig", "wifi1", "hw", "ether", wmac);
253        setWirelessLedPhy0(5);
254        setWirelessLedPhy1(5);
255#endif
256#endif
257
258        led_control(LED_POWER, LED_ON);
259        led_control(LED_SES, LED_OFF);
260        led_control(LED_SES2, LED_OFF);
261        led_control(LED_DIAG, LED_OFF);
262        led_control(LED_BRIDGE, LED_OFF);
263        led_control(LED_WLAN0, LED_OFF);
264        led_control(LED_WLAN1, LED_OFF);
265        led_control(LED_CONNECTED, LED_OFF);
266       
267        getRouterBrand(); // restore some default settings
268
269        if (!nvram_get("ath0_rxantenna"))
270                nvram_set("ath0_rxantenna", "3");
271        if (!nvram_get("ath0_txantenna"))
272                nvram_set("ath0_txantenna", "3");
273        if (!nvram_get("ath1_rxantenna"))
274                nvram_set("ath1_rxantenna", "3");
275        if (!nvram_get("ath1_txantenna"))
276                nvram_set("ath1_txantenna", "3");
277
278        /*
279         * Set a sane date
280         */
281        stime(&tm);
282        nvram_set("wl0_ifname", "ath0");
283
284        return;
285        cprintf("done\n");
286}
287
288int check_cfe_nv(void)
289{
290        nvram_set("portprio_support", "0");
291        return 0;
292}
293
294int check_pmon_nv(void)
295{
296        return 0;
297}
298
299void start_overclocking(void)
300{
301}
302
303char *enable_dtag_vlan(int enable)
304{
305        return "eth0";
306}
Note: See TracBrowser for help on using the repository browser.