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

Last change on this file since 18727 was 18727, checked in by BrainSlayer, 14 months ago

okay, the way is different

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