source: src/router/services/sysinit/sysinit-hornet.c @ 18736

Last change on this file since 18736 was 18736, checked in by BrainSlayer, 15 months ago

some fixes

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