source: src/router/services/sysinit/sysinit-wr741.c @ 18403

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

wnr2000v3 work in progress

File size: 3.8 KB
Line 
1/*
2 * sysinit-wr741.c
3 *
4 * Copyright (C) 2009 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("ag7240_mod");
75
76        FILE *fp = fopen("/dev/mtdblock/0", "rb");
77        char mac[32];
78        if (fp) {
79                unsigned char buf2[256];
80                fseek(fp, 0x1fc00, SEEK_SET);
81                fread(buf2, 256, 1, fp);
82                fclose(fp);
83                unsigned int copy[256];
84                int i;
85                for (i = 0; i < 256; i++)
86                        copy[i] = buf2[i] & 0xff;
87                sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
88                        copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]);
89                fprintf(stderr, "configure eth0 to %s\n", mac);
90                eval("ifconfig", "eth0", "hw", "ether", mac);
91                MAC_ADD(mac);
92                fprintf(stderr, "configure eth1 to %s\n", mac);
93                eval("ifconfig", "eth1", "hw", "ether", mac);
94#ifndef HAVE_ATH9K
95                MAC_SUB(mac);
96#endif
97        }
98
99        eval("ifconfig", "eth0", "up");
100        eval("ifconfig", "eth1", "up");
101        struct ifreq ifr;
102        int s;
103
104        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
105                char eabuf[32];
106
107                strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
108                ioctl(s, SIOCGIFHWADDR, &ifr);
109                nvram_set("et0macaddr",
110                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
111                                     eabuf));
112                nvram_set("et0macaddr_safe",
113                          ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data,
114                                     eabuf));
115                close(s);
116        }
117        detect_wireless_devices();
118#ifndef HAVE_ATH9K
119        fprintf(stderr, "configure wifi0 to %s\n", mac);
120        eval("ifconfig", "wifi0", "hw", "ether", mac);
121#endif
122        //enable wlan led (card gpio based)
123        setWirelessLedPhy0(1);
124
125        led_control(LED_POWER, LED_ON);
126        led_control(LED_SES, LED_OFF);
127        led_control(LED_SES2, LED_OFF);
128        led_control(LED_DIAG, LED_OFF);
129        led_control(LED_BRIDGE, LED_OFF);
130        led_control(LED_WLAN0, LED_OFF);
131        led_control(LED_WLAN1, LED_OFF);
132        led_control(LED_CONNECTED, LED_OFF);
133
134        /*
135         * Set a sane date
136         */
137        stime(&tm);
138        nvram_set("wl0_ifname", "ath0");
139
140        return;
141        cprintf("done\n");
142}
143
144int check_cfe_nv(void)
145{
146        nvram_set("portprio_support", "0");
147        return 0;
148}
149
150int check_pmon_nv(void)
151{
152        return 0;
153}
154
155void start_overclocking(void)
156{
157}
158
159char *enable_dtag_vlan(int enable)
160{
161        return "eth0";
162}
Note: See TracBrowser for help on using the repository browser.