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

Last change on this file since 17654 was 17654, checked in by BrainSlayer, 20 months ago

fix version check

File size: 7.9 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 ATH Ethernet Driver\n");
74        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
85#ifdef HAVE_WNDR3700V2
86                fseek(fp, 0xff0000, SEEK_SET);
87#else
88                fseek(fp, 0x7f0000, SEEK_SET);
89#endif
90                fread(mactmp, 6, 1, fp);
91                for (i = 0; i < 6; i++)
92                        copy[i] = mactmp[i];
93                for (i = 0; i < 6; i++)
94                        copy[i] &= 0xff;
95                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
96                        copy[1], copy[2], copy[3], copy[4], copy[5]);
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(mac2, "%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                fclose(fp);
106                for (i = 0; i < 6; i++)
107                        copy[i] = mactmp[i];
108                for (i = 0; i < 6; i++)
109                        copy[i] &= 0xff;
110                sprintf(wmac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
111                        copy[1], copy[2], copy[3], copy[4], copy[5]);
112#elif HAVE_WZRHPAG300NH
113                fseek(fp, 0x5120C, SEEK_SET);
114                fread(mactmp, 6, 1, fp);
115                fclose(fp);
116                for (i = 0; i < 6; i++)
117                        copy[i] = mactmp[i];
118                for (i = 0; i < 6; i++)
119                        copy[i] &= 0xff;
120                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
121                        copy[1], copy[2], copy[3], copy[4], copy[5]);
122                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
123                        copy[1], copy[2], copy[3], copy[4], copy[5]);
124                MAC_ADD(mac2);
125//              eval("gpio","enable","2");
126#elif HAVE_WZRG300NH2
127                sysprintf("startservice bootloader_check");
128                fseek(fp, 0x5120C, SEEK_SET);
129                fread(mactmp, 6, 1, fp);
130                fclose(fp);
131                for (i = 0; i < 6; i++)
132                        copy[i] = mactmp[i];
133                for (i = 0; i < 6; i++)
134                        copy[i] &= 0xff;
135                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
136                        copy[1], copy[2], copy[3], copy[4], copy[5]);
137                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
138                        copy[1], copy[2], copy[3], copy[4], copy[5]);
139//              eval("gpio","enable","13");
140                fprintf(stderr, "configure eth0 to %s\n", mac2);
141                eval("ifconfig", "eth0", "hw", "ether", mac2);
142                eval("ifconfig", "eth0", "up");
143                eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
144                eval("vconfig", "add", "eth0", "1");
145                eval("vconfig", "add", "eth0", "2");
146                fprintf(stderr, "configure vlan1 to %s\n", mac2);
147                eval("ifconfig", "vlan1", "hw", "ether", mac2);
148                fprintf(stderr, "configure vlan2 to %s\n", mac2);
149                eval("ifconfig", "vlan2", "hw", "ether", mac2);
150#elif HAVE_WZRG450
151                fseek(fp, 0x51002, SEEK_SET); //osprey eeprom mac location
152                fread(mactmp, 6, 1, fp);
153                fclose(fp);
154                for (i = 0; i < 6; i++)
155                        copy[i] = mactmp[i];
156                for (i = 0; i < 6; i++)
157                        copy[i] &= 0xff;
158                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
159                        copy[1], copy[2], copy[3], copy[4], copy[5]);
160                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
161                        copy[1], copy[2], copy[3], copy[4], copy[5]);
162//              mac1[0] |= 0x02; // add private bit
163//              mac2[0] |= 0x02;
164//              eval("gpio","disable","16");
165                fprintf(stderr, "configure eth0 to %s\n", mac2);
166                eval("ifconfig", "eth0", "hw", "ether", mac2);
167                eval("ifconfig", "eth0", "up");
168                eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
169                eval("vconfig", "add", "eth0", "1");
170                eval("vconfig", "add", "eth0", "2");
171                fprintf(stderr, "configure vlan1 to %s\n", mac2);
172                eval("ifconfig", "vlan1", "hw", "ether", mac2);
173                fprintf(stderr, "configure vlan2 to %s\n", mac2);
174                eval("ifconfig", "vlan2", "hw", "ether", mac2);
175#else
176                fseek(fp, 0x7f120c, SEEK_SET);
177                fread(mactmp, 6, 1, fp);
178                fclose(fp);
179                for (i = 5; i >= 3; i--)
180                        if (++mactmp[i] != 0x00)
181                                break;  // dont know what this is
182                for (i = 0; i < 6; i++)
183                        copy[i] = mactmp[i];
184                for (i = 0; i < 6; i++)
185                        copy[i] &= 0xff;
186                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
187                        copy[1], copy[2], copy[3], copy[4], copy[5]);
188                sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
189                        copy[1], copy[2], copy[3], copy[4], copy[5]);
190                MAC_ADD(mac2);
191#endif
192
193        } else {
194                sprintf(mac1, "00:11:22:33:44:55");
195                sprintf(mac2, "00:11:22:33:44:66");
196        }
197#ifndef HAVE_WZRG450
198        eval("ifconfig", "eth0", "hw", "ether", mac1);
199        eval("ifconfig", "eth0", "up");
200        eval("ifconfig", "eth1", "hw", "ether", mac2);
201        eval("ifconfig", "eth1", "up");
202#else
203        eval("ifconfig", "eth0", "hw", "ether", mac2);
204        eval("ifconfig", "eth0", "up");
205#endif
206        struct ifreq ifr;
207        int s;
208
209        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
210                char eabuf[32];
211
212                strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
213                ioctl(s, SIOCGIFHWADDR, &ifr);
214                nvram_set("et0macaddr",
215                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
216                                     eabuf));
217                nvram_set("et0macaddr_safe",
218                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
219                                     eabuf));
220                close(s);
221        }
222        detect_wireless_devices();
223#ifdef HAVE_WZRHPAG300NH
224//      eval("ifconfig", "wifi1", "hw", "ether", wmac);
225        setWirelessLedPhy0(1);
226        setWirelessLedPhy1(5);
227
228#else
229#ifndef HAVE_WNDR3700
230
231#ifdef HAVE_WZRG300NH2
232        setWirelessLedPhy0(5);
233#else
234#ifndef HAVE_WZRG450
235        setWirelessLedPhy0(6);
236        setWirelessLedPhy1(6);
237#endif
238#endif
239#else
240        eval("ifconfig", "wifi0", "hw", "ether", mac1);
241        eval("ifconfig", "wifi1", "hw", "ether", wmac);
242        setWirelessLedPhy0(5);
243        setWirelessLedPhy1(5);
244#endif
245#endif
246
247        led_control(LED_POWER, LED_ON);
248        led_control(LED_SES, LED_OFF);
249        led_control(LED_SES2, LED_OFF);
250        led_control(LED_DIAG, LED_OFF);
251        led_control(LED_BRIDGE, LED_OFF);
252        led_control(LED_WLAN0, LED_OFF);
253        led_control(LED_WLAN1, LED_OFF);
254        led_control(LED_CONNECTED, LED_OFF);
255       
256        getRouterBrand(); // restore some default settings
257
258        if (!nvram_get("ath0_rxantenna"))
259                nvram_set("ath0_rxantenna", "3");
260        if (!nvram_get("ath0_txantenna"))
261                nvram_set("ath0_txantenna", "3");
262        if (!nvram_get("ath1_rxantenna"))
263                nvram_set("ath1_rxantenna", "3");
264        if (!nvram_get("ath1_txantenna"))
265                nvram_set("ath1_txantenna", "3");
266
267        /*
268         * Set a sane date
269         */
270        stime(&tm);
271        nvram_set("wl0_ifname", "ath0");
272
273        return;
274        cprintf("done\n");
275}
276
277int check_cfe_nv(void)
278{
279        nvram_set("portprio_support", "0");
280        return 0;
281}
282
283int check_pmon_nv(void)
284{
285        return 0;
286}
287
288void start_overclocking(void)
289{
290}
291
292char *enable_dtag_vlan(int enable)
293{
294        return "eth0";
295}
Note: See TracBrowser for help on using the repository browser.