| 1 | /* |
|---|
| 2 | * sysinit-fonera.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 <linux/if_ether.h> |
|---|
| 42 | #include <linux/mii.h> |
|---|
| 43 | #include <linux/sockios.h> |
|---|
| 44 | #include <net/if.h> |
|---|
| 45 | |
|---|
| 46 | #include <arpa/inet.h> |
|---|
| 47 | #include <sys/socket.h> |
|---|
| 48 | #include <linux/sockios.h> |
|---|
| 49 | #include <linux/mii.h> |
|---|
| 50 | |
|---|
| 51 | #include <bcmnvram.h> |
|---|
| 52 | #include <shutils.h> |
|---|
| 53 | #include <utils.h> |
|---|
| 54 | #include <cymac.h> |
|---|
| 55 | #include "devices/wireless.c" |
|---|
| 56 | |
|---|
| 57 | extern void vlan_init(int num); |
|---|
| 58 | |
|---|
| 59 | void start_sysinit(void) |
|---|
| 60 | { |
|---|
| 61 | char buf[PATH_MAX]; |
|---|
| 62 | struct stat tmp_stat; |
|---|
| 63 | time_t tm = 0; |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | mknod("/dev/mmc",S_IFBLK|0660,makedev(126,0)); |
|---|
| 67 | mknod("/dev/mmc0",S_IFBLK|0660,makedev(126,1)); |
|---|
| 68 | mknod("/dev/mmc1",S_IFBLK|0660,makedev(126,2)); |
|---|
| 69 | mknod("/dev/mmc2",S_IFBLK|0660,makedev(126,3)); |
|---|
| 70 | mknod("/dev/mmc3",S_IFBLK|0660,makedev(126,4)); |
|---|
| 71 | |
|---|
| 72 | eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); |
|---|
| 73 | FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); |
|---|
| 74 | |
|---|
| 75 | if (in != NULL) { |
|---|
| 76 | fclose(in); |
|---|
| 77 | eval("/usr/sbin/convertnvram"); |
|---|
| 78 | eval("/sbin/mtd", "erase", "nvram"); |
|---|
| 79 | nvram_commit(); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | cprintf("sysinit() setup console\n"); |
|---|
| 83 | if (!nvram_match("disable_watchdog", "1")) |
|---|
| 84 | eval("watchdog"); |
|---|
| 85 | /* |
|---|
| 86 | * Setup console |
|---|
| 87 | */ |
|---|
| 88 | |
|---|
| 89 | cprintf("sysinit() klogctl\n"); |
|---|
| 90 | klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); |
|---|
| 91 | cprintf("sysinit() get router\n"); |
|---|
| 92 | |
|---|
| 93 | /* |
|---|
| 94 | * network drivers |
|---|
| 95 | */ |
|---|
| 96 | #ifdef HAVE_HOTPLUG2 |
|---|
| 97 | insmod("ar231x"); |
|---|
| 98 | #else |
|---|
| 99 | insmod("ar2313"); |
|---|
| 100 | #endif |
|---|
| 101 | detect_wireless_devices(); |
|---|
| 102 | |
|---|
| 103 | #if defined(HAVE_EAP3660) || defined(HAVE_EOC2610) || defined(HAVE_ECB3500) || defined(HAVE_EOC1650) |
|---|
| 104 | writeproc("/proc/sys/dev/wifi0/ledpin","2"); |
|---|
| 105 | writeproc("/proc/sys/dev/wifi0/softled","1"); |
|---|
| 106 | #endif |
|---|
| 107 | #ifdef HAVE_GWMF54G2 |
|---|
| 108 | writeproc("/proc/sys/dev/wifi0/ledpin","4"); |
|---|
| 109 | writeproc("/proc/sys/dev/wifi0/softled","1"); |
|---|
| 110 | #endif |
|---|
| 111 | #ifdef HAVE_DLM101 |
|---|
| 112 | writeproc("/proc/sys/dev/wifi0/ledpin","7"); |
|---|
| 113 | writeproc("/proc/sys/dev/wifi0/softled","1"); |
|---|
| 114 | #endif |
|---|
| 115 | #ifdef HAVE_MERAKI |
|---|
| 116 | writeproc("/proc/sys/dev/wifi0/ledpin","3"); |
|---|
| 117 | writeproc("/proc/sys/dev/wifi0/softled","1"); |
|---|
| 118 | #endif |
|---|
| 119 | // eval ("ifconfig", "wifi0", "up"); |
|---|
| 120 | #ifdef HAVE_LS2 |
|---|
| 121 | eval("ifconfig", "eth0", "up"); // wan |
|---|
| 122 | vlan_init(5); // 4 lan + 1 wan, but only first one is used |
|---|
| 123 | #endif |
|---|
| 124 | int s; |
|---|
| 125 | struct ifreq ifr; |
|---|
| 126 | if (getRouterBrand() == ROUTER_BOARD_FONERA2200) { |
|---|
| 127 | eval("ifconfig", "eth0", "up", "promisc"); // required for vlan config |
|---|
| 128 | eval("/sbin/vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); |
|---|
| 129 | eval("/sbin/vconfig", "add", "eth0", "0"); |
|---|
| 130 | eval("/sbin/vconfig", "add", "eth0", "1"); |
|---|
| 131 | |
|---|
| 132 | if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { |
|---|
| 133 | char eabuf[32]; |
|---|
| 134 | |
|---|
| 135 | strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 136 | ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 137 | char macaddr[32]; |
|---|
| 138 | |
|---|
| 139 | strcpy(macaddr, |
|---|
| 140 | ether_etoa((unsigned char *)ifr.ifr_hwaddr. |
|---|
| 141 | sa_data, eabuf)); |
|---|
| 142 | nvram_set("et0macaddr", macaddr); |
|---|
| 143 | // MAC_ADD( macaddr ); |
|---|
| 144 | ether_atoe(macaddr, |
|---|
| 145 | (unsigned char *)ifr.ifr_hwaddr.sa_data); |
|---|
| 146 | strncpy(ifr.ifr_name, "vlan1", IFNAMSIZ); |
|---|
| 147 | ioctl(s, SIOCSIFHWADDR, &ifr); |
|---|
| 148 | close(s); |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { |
|---|
| 153 | char eabuf[32]; |
|---|
| 154 | |
|---|
| 155 | strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 156 | ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 157 | char macaddr[32]; |
|---|
| 158 | |
|---|
| 159 | strcpy(macaddr, |
|---|
| 160 | ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, |
|---|
| 161 | eabuf)); |
|---|
| 162 | nvram_set("et0macaddr", macaddr); |
|---|
| 163 | nvram_set("et0macaddr_safe", macaddr); |
|---|
| 164 | close(s); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | /* |
|---|
| 168 | * Set a sane date |
|---|
| 169 | */ |
|---|
| 170 | stime(&tm); |
|---|
| 171 | nvram_set("wl0_ifname", "ath0"); |
|---|
| 172 | |
|---|
| 173 | return; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | int check_cfe_nv(void) |
|---|
| 177 | { |
|---|
| 178 | nvram_set("portprio_support", "0"); |
|---|
| 179 | return 0; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | int check_pmon_nv(void) |
|---|
| 183 | { |
|---|
| 184 | return 0; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | void start_overclocking(void) |
|---|
| 188 | { |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | void enable_dtag_vlan(int enable) |
|---|
| 192 | { |
|---|
| 193 | |
|---|
| 194 | } |
|---|