| 1 |
/* |
|---|
| 2 |
* sysinit-ca8.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 |
|
|---|
| 55 |
#include <bcmnvram.h> |
|---|
| 56 |
#include <shutils.h> |
|---|
| 57 |
#include <utils.h> |
|---|
| 58 |
#include <cymac.h> |
|---|
| 59 |
|
|---|
| 60 |
// highly experimental |
|---|
| 61 |
|
|---|
| 62 |
void start_sysinit(void) |
|---|
| 63 |
{ |
|---|
| 64 |
struct utsname name; |
|---|
| 65 |
time_t tm = 0; |
|---|
| 66 |
|
|---|
| 67 |
unlink("/etc/nvram/.lock"); |
|---|
| 68 |
cprintf("sysinit() proc\n"); |
|---|
| 69 |
/* |
|---|
| 70 |
* /proc |
|---|
| 71 |
*/ |
|---|
| 72 |
mount("proc", "/proc", "proc", MS_MGC_VAL, NULL); |
|---|
| 73 |
mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL); |
|---|
| 74 |
cprintf("sysinit() tmp\n"); |
|---|
| 75 |
|
|---|
| 76 |
/* |
|---|
| 77 |
* /tmp |
|---|
| 78 |
*/ |
|---|
| 79 |
mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL); |
|---|
| 80 |
// fix for linux kernel 2.6 |
|---|
| 81 |
mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL); |
|---|
| 82 |
eval("mkdir", "/tmp/www"); |
|---|
| 83 |
eval("mknod", "/dev/nvram", "c", "229", "0"); |
|---|
| 84 |
eval("mknod", "/dev/ppp", "c", "108", "0"); |
|---|
| 85 |
|
|---|
| 86 |
unlink("/tmp/nvram/.lock"); |
|---|
| 87 |
eval("mkdir", "/tmp/nvram"); |
|---|
| 88 |
eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); |
|---|
| 89 |
FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); |
|---|
| 90 |
|
|---|
| 91 |
if (in != NULL) { |
|---|
| 92 |
fclose(in); |
|---|
| 93 |
eval("/usr/sbin/convertnvram"); |
|---|
| 94 |
eval("/sbin/mtd", "erase", "nvram"); |
|---|
| 95 |
nvram_commit(); |
|---|
| 96 |
} |
|---|
| 97 |
cprintf("sysinit() var\n"); |
|---|
| 98 |
|
|---|
| 99 |
/* |
|---|
| 100 |
* /var |
|---|
| 101 |
*/ |
|---|
| 102 |
mkdir("/tmp/var", 0777); |
|---|
| 103 |
mkdir("/var/lock", 0777); |
|---|
| 104 |
mkdir("/var/log", 0777); |
|---|
| 105 |
mkdir("/var/run", 0777); |
|---|
| 106 |
mkdir("/var/tmp", 0777); |
|---|
| 107 |
cprintf("sysinit() setup console\n"); |
|---|
| 108 |
if (!nvram_match("disable_watchdog", "1")) |
|---|
| 109 |
eval("watchdog"); |
|---|
| 110 |
/* |
|---|
| 111 |
* Setup console |
|---|
| 112 |
*/ |
|---|
| 113 |
|
|---|
| 114 |
cprintf("sysinit() klogctl\n"); |
|---|
| 115 |
klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); |
|---|
| 116 |
cprintf("sysinit() get router\n"); |
|---|
| 117 |
|
|---|
| 118 |
/* |
|---|
| 119 |
* Modules |
|---|
| 120 |
*/ |
|---|
| 121 |
uname(&name); |
|---|
| 122 |
|
|---|
| 123 |
/* |
|---|
| 124 |
* network drivers |
|---|
| 125 |
*/ |
|---|
| 126 |
insmod("ar2313"); |
|---|
| 127 |
insmod("ath_hal"); |
|---|
| 128 |
if (nvram_get("rate_control") != NULL) { |
|---|
| 129 |
char rate[64]; |
|---|
| 130 |
|
|---|
| 131 |
sprintf(rate, "ratectl=%s", nvram_safe_get("rate_control")); |
|---|
| 132 |
eval("insmod", "ath_ahb", rate); |
|---|
| 133 |
} else { |
|---|
| 134 |
insmod("ath_ahb"); |
|---|
| 135 |
} |
|---|
| 136 |
// eval ("ifconfig", "wifi0", "up"); |
|---|
| 137 |
if (getRouterBrand() == ROUTER_BOARD_RDAT81) { |
|---|
| 138 |
system2("echo 7 >/proc/sys/dev/wifi0/ledpin"); |
|---|
| 139 |
system2("echo 1 >/proc/sys/dev/wifi0/softled"); |
|---|
| 140 |
system2("echo 5 >/proc/sys/dev/wifi1/ledpin"); |
|---|
| 141 |
system2("echo 1 >/proc/sys/dev/wifi1/softled"); |
|---|
| 142 |
} |
|---|
| 143 |
if (getRouterBrand() == ROUTER_BOARD_RCAA01) { |
|---|
| 144 |
insmod("mvswitch"); |
|---|
| 145 |
eval("ifconfig", "eth0", "up", "promisc"); // required for vlan config |
|---|
| 146 |
eval("/sbin/vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); |
|---|
| 147 |
eval("/sbin/vconfig", "add", "eth0", "0"); |
|---|
| 148 |
eval("/sbin/vconfig", "add", "eth0", "1"); |
|---|
| 149 |
struct ifreq ifr; |
|---|
| 150 |
int s; |
|---|
| 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. |
|---|
| 161 |
ifr_hwaddr.sa_data, eabuf)); |
|---|
| 162 |
nvram_set("et0macaddr", macaddr); |
|---|
| 163 |
// MAC_ADD( macaddr ); |
|---|
| 164 |
ether_atoe(macaddr, |
|---|
| 165 |
(unsigned char *)ifr.ifr_hwaddr.sa_data); |
|---|
| 166 |
strncpy(ifr.ifr_name, "vlan1", IFNAMSIZ); |
|---|
| 167 |
ioctl(s, SIOCSIFHWADDR, &ifr); |
|---|
| 168 |
close(s); |
|---|
| 169 |
} |
|---|
| 170 |
system2("echo 4 >/proc/sys/dev/wifi0/ledpin"); |
|---|
| 171 |
system2("echo 1 >/proc/sys/dev/wifi0/softled"); |
|---|
| 172 |
system2("echo 5 >/proc/sys/dev/wifi1/ledpin"); |
|---|
| 173 |
system2("echo 1 >/proc/sys/dev/wifi1/softled"); |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
insmod("ipv6"); |
|---|
| 177 |
|
|---|
| 178 |
/* |
|---|
| 179 |
* Set a sane date |
|---|
| 180 |
*/ |
|---|
| 181 |
stime(&tm); |
|---|
| 182 |
nvram_set("wl0_ifname", "ath0"); |
|---|
| 183 |
|
|---|
| 184 |
return; |
|---|
| 185 |
cprintf("done\n"); |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
int check_cfe_nv(void) |
|---|
| 189 |
{ |
|---|
| 190 |
nvram_set("portprio_support", "0"); |
|---|
| 191 |
return 0; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
int check_pmon_nv(void) |
|---|
| 195 |
{ |
|---|
| 196 |
return 0; |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
void start_overclocking(void) |
|---|
| 200 |
{ |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|
| 203 |
void enable_dtag_vlan(int enable) |
|---|
| 204 |
{ |
|---|
| 205 |
|
|---|
| 206 |
} |
|---|