| 1 | /* |
|---|
| 2 | * sysinit-ubntm.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 | |
|---|
| 56 | void 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 | system("insmod ag71xx || insmod ag7240_mod"); |
|---|
| 75 | |
|---|
| 76 | FILE *fp = fopen("/dev/mtdblock/6", "rb"); |
|---|
| 77 | if (fp) { |
|---|
| 78 | unsigned char buf2[256]; |
|---|
| 79 | if (fseek(fp, 0x07f0000, SEEK_SET)) |
|---|
| 80 | fseek(fp, 0x03f0000, SEEK_SET); |
|---|
| 81 | fread(buf2, 256, 1, fp); |
|---|
| 82 | fclose(fp); |
|---|
| 83 | if ((!memcmp(buf2,"\xff\xff\xff\xff\xff\xff",6) || !memcmp(buf2,"\x00\x00\x00\x00\x00\x00",6)) |
|---|
| 84 | break; |
|---|
| 85 | char mac[32]; |
|---|
| 86 | unsigned int copy[256]; |
|---|
| 87 | int i; |
|---|
| 88 | for (i = 0; i < 256; i++) |
|---|
| 89 | copy[i] = buf2[i] & 0xff; |
|---|
| 90 | sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", |
|---|
| 91 | copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); |
|---|
| 92 | fprintf(stderr, "configure eth0 to %s\n", mac); |
|---|
| 93 | eval("ifconfig", "eth0", "hw", "ether", mac); |
|---|
| 94 | fprintf(stderr, "configure eth1 to %s\n", mac); |
|---|
| 95 | eval("ifconfig", "eth1", "hw", "ether", mac); |
|---|
| 96 | } |
|---|
| 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 | #ifdef HAVE_SWCONFIG |
|---|
| 118 | system("swconfig dev eth1 set reset 1"); |
|---|
| 119 | system("swconfig dev eth1 set enable_vlan 0"); |
|---|
| 120 | system("swconfig dev eth1 vlan 1 set ports \"0 1 2 3 4\""); |
|---|
| 121 | system("swconfig dev eth1 set apply"); |
|---|
| 122 | #endif |
|---|
| 123 | |
|---|
| 124 | detect_wireless_devices(); |
|---|
| 125 | |
|---|
| 126 | int brand = getRouterBrand(); |
|---|
| 127 | if (brand == ROUTER_BOARD_UNIFI) { |
|---|
| 128 | setWirelessLed(0, 0); |
|---|
| 129 | } else { |
|---|
| 130 | system2("echo 0 >/proc/sys/dev/wifi0/softled"); |
|---|
| 131 | sysprintf |
|---|
| 132 | ("/sbin/wlanled -l generic_0:-94 -l generic_1:-80 -l generic_11:-73 -l generic_7:-65"); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /* ubnt has a hardware fault as it seems, so the power bridge feature can break the hardware which causes endless reboot loops. we keep it disabled here. devices which are already broken will work again then */ |
|---|
| 136 | if (nvram_match("ubnt_power", "1")) |
|---|
| 137 | eval("gpio", "enable", "8"); //enable power passthrough |
|---|
| 138 | |
|---|
| 139 | /* |
|---|
| 140 | * Set a sane date |
|---|
| 141 | */ |
|---|
| 142 | stime(&tm); |
|---|
| 143 | nvram_set("wl0_ifname", "ath0"); |
|---|
| 144 | |
|---|
| 145 | return; |
|---|
| 146 | cprintf("done\n"); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | int check_cfe_nv(void) |
|---|
| 150 | { |
|---|
| 151 | nvram_set("portprio_support", "0"); |
|---|
| 152 | return 0; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | int check_pmon_nv(void) |
|---|
| 156 | { |
|---|
| 157 | return 0; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | void start_overclocking(void) |
|---|
| 161 | { |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | char *enable_dtag_vlan(int enable) |
|---|
| 165 | { |
|---|
| 166 | return "eth0"; |
|---|
| 167 | } |
|---|