source: src/router/services/sysinit/sysinit-danube.c @ 18249

Last change on this file since 18249 was 18249, checked in by BrainSlayer, 16 months ago

format

File size: 6.2 KB
Line 
1/*
2 * sysinit-danube.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#include <cymac.h>
55#include "devices/wireless.c"
56
57/*
58        option unit             0
59        option encaps   llc
60        option vpi              1
61        option vci              32
62        option payload  bridged # some ISPs need this set to 'routed'
63
64        local cfg="$1"
65
66        local atmdev
67        config_get atmdev "$cfg" atmdev 0
68
69        local unit
70        config_get unit "$cfg" unit 0
71
72        local vpi
73        config_get vpi "$cfg" vpi 8
74
75        local vci
76        config_get vci "$cfg" vci 35
77
78        local encaps
79        config_get encaps "$cfg" encaps
80
81        case "$encaps" in
82                1|vc) encaps=1;;
83                *) encaps=0;;
84        esac
85
86        local payload
87        config_get payload "$cfg" payload
88
89        case "$payload" in
90                0|routed) payload=0;;
91                *) payload=1;;
92        esac
93
94        local qos
95        config_get qos "$cfg" qos
96
97        local circuit="$atmdev.$vpi.$vci"
98        local pid="/var/run/br2684ctl-$circuit.pid"
99
100        start-stop-daemon -S -b -x /usr/sbin/br2684ctl -m -p "$pid" -- \
101                -c "$unit" -e "$encaps" -p "$payload" \
102                -a "$circuit" ${qos:+-q "$qos"}
103
104*/
105
106void start_sysinit(void)
107{
108        char buf[PATH_MAX];
109        struct stat tmp_stat;
110        time_t tm = 0;
111
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        int brand = getRouterBrand();
124        char *annex;
125
126        /*
127         * Modules
128         */
129
130        /*
131         * network drivers
132         */
133        // insmod("ag7100_mod");
134        // sleep(1);
135        //load dsl drivers
136        insmod("lantiq_mei");
137        insmod("lantiq_atm");
138        insmod("drv_dsl_cpe_api");
139#ifdef HAVE_TELCOM
140        nvram_default_get("annex", "a");
141        nvram_default_get("vpi", "0");
142        nvram_default_get("vci", "35");
143#else
144        nvram_default_get("vpi", "1");
145        nvram_default_get("vci", "32");
146#endif
147        nvram_set("dsl_iface_status", "DOWN");
148        nvram_set("dsl_snr_down", "");
149        nvram_set("dsl_snr_up", "");
150        nvram_set("dsl_datarate_ds", "");
151        nvram_set("dsl_datarate_us", "");
152        nvram_set("dsl_xtu_status", "");
153        nvram_set("dsl_tcl_status", "");
154#ifdef HAVE_ANNEXB
155        sysprintf
156            ("/usr/sbin/dsl_cpe_control -i -f /usr/lib/firmware/annex_b.bin -n /usr/sbin/dsl_notification.sh &");
157#elif HAVE_ANNEXA
158        sysprintf
159            ("/usr/sbin/dsl_cpe_control -i -f /usr/lib/firmware/annex_a.bin -n /usr/sbin/dsl_notification.sh &");
160#else
161#ifdef HAVE_WMBR_G300NH
162        if (!strcmp(getUEnv("region"), "DE"))
163                annex = nvram_default_get("annex", "b");
164        else
165#endif
166                annex = nvram_default_get("annex", "a");
167
168        if (!strcmp(annex, "a"))
169                sysprintf
170                    ("/usr/sbin/dsl_cpe_control -i -f /usr/lib/firmware/annex_a.bin -n /usr/sbin/dsl_notification.sh &");
171        else if (!strcmp(annex, "m")) {
172                sysprintf
173                    ("/usr/sbin/dsl_cpe_control -i05_00_04_00_4c_01_04_00 -f /usr/lib/firmware/annex_a.bin -n /usr/sbin/dsl_notification.sh &");
174        } else
175                sysprintf
176                    ("/usr/sbin/dsl_cpe_control -i -f /usr/lib/firmware/annex_b.bin -n /usr/sbin/dsl_notification.sh &");
177#endif
178        eval("ifconfig", "eth0", "up");
179        detect_wireless_devices();
180        struct ifreq ifr;
181        int s;
182
183        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
184                char eabuf[32];
185
186                strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
187                ioctl(s, SIOCGIFHWADDR, &ifr);
188                nvram_set("et0macaddr",
189                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
190                                     eabuf));
191                nvram_set("et0macaddr_safe",
192                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
193                                     eabuf));
194                close(s);
195        }
196#ifdef HAVE_WMBR_G300NH
197        FILE *fp = fopen("/dev/mtdblock/6", "rb");
198        if (fp) {
199                char mactmp[6];
200                int copy[6];
201                int i;
202                char mac1[32];
203                fseek(fp, 0x1fd0024 + 12, SEEK_SET);
204                fread(mactmp, 6, 1, fp);
205                for (i = 0; i < 6; i++)
206                        copy[i] = mactmp[i];
207                for (i = 0; i < 6; i++)
208                        copy[i] &= 0xff;
209                sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0],
210                        copy[1], copy[2], copy[3], copy[4], copy[5]);
211                eval("ifconfig", "wifi0", "hw", "ether", mac1);
212        }
213#ifdef HAVE_ATH9K
214        sysprintf
215            ("echo phy0tpt > /sys/devices/platform/leds-gpio/leds/soc:green:wlan/trigger");
216#else
217        system2("echo 15 >/proc/sys/dev/wifi0/ledpin");
218        system2("echo 1 >/proc/sys/dev/wifi0/softled");
219#endif
220
221        led_control(LED_POWER, LED_ON);
222        led_control(LED_SES, LED_OFF);
223        led_control(LED_SES2, LED_OFF);
224        led_control(LED_DIAG, LED_OFF);
225        led_control(LED_BRIDGE, LED_OFF);
226        led_control(LED_WLAN0, LED_OFF);
227        led_control(LED_WLAN1, LED_OFF);
228        led_control(LED_CONNECTED, LED_OFF);
229        system2("gpio disable 1");
230        system2("gpio disable 18");
231#endif
232#ifdef HAVE_SX763
233        char mac[18];
234        strcpy(mac, nvram_safe_get("et0macaddr"));
235        MAC_ADD(mac);
236        eval("ifconfig", "wifi0", "hw", "ether", mac);
237        system2("echo 219 >/proc/sys/dev/wifi0/ledpin");
238        system2("echo 1 >/proc/sys/dev/wifi0/softled");
239#endif
240
241        /*
242         * Set a sane date
243         */
244        stime(&tm);
245        nvram_set("wl0_ifname", "ath0");
246
247        return;
248        cprintf("done\n");
249}
250
251int check_cfe_nv(void)
252{
253        nvram_set("portprio_support", "0");
254        return 0;
255}
256
257int check_pmon_nv(void)
258{
259        return 0;
260}
261
262void start_overclocking(void)
263{
264}
265
266void enable_dtag_vlan(int enable)
267{
268
269}
Note: See TracBrowser for help on using the repository browser.