| 1 | /* |
|---|
| 2 | * utils.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2007 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 | |
|---|
| 23 | #include <stdio.h> |
|---|
| 24 | #include <stdlib.h> |
|---|
| 25 | #include <string.h> |
|---|
| 26 | #include <errno.h> |
|---|
| 27 | #include <net/if.h> |
|---|
| 28 | #include <dirent.h> |
|---|
| 29 | #include <unistd.h> |
|---|
| 30 | #include <ctype.h> |
|---|
| 31 | #include <syslog.h> |
|---|
| 32 | #include <sys/socket.h> |
|---|
| 33 | #include <sys/stat.h> |
|---|
| 34 | #include <fcntl.h> |
|---|
| 35 | #include <netinet/in.h> |
|---|
| 36 | #include <stdarg.h> |
|---|
| 37 | #include <sys/ioctl.h> |
|---|
| 38 | #include <sys/sysinfo.h> |
|---|
| 39 | #include <arpa/inet.h> |
|---|
| 40 | #include <netpacket/packet.h> |
|---|
| 41 | #include <netdb.h> |
|---|
| 42 | #include <resolv.h> |
|---|
| 43 | #include <signal.h> |
|---|
| 44 | #ifdef HAVE_ATH9K |
|---|
| 45 | #include <glob.h> |
|---|
| 46 | #endif |
|---|
| 47 | |
|---|
| 48 | #include <utils.h> |
|---|
| 49 | #include <wlutils.h> |
|---|
| 50 | #include <bcmnvram.h> |
|---|
| 51 | #include <shutils.h> |
|---|
| 52 | #include <cy_conf.h> |
|---|
| 53 | #include <code_pattern.h> |
|---|
| 54 | #include <bcmdevs.h> |
|---|
| 55 | #include <net/route.h> |
|---|
| 56 | #include <cy_conf.h> |
|---|
| 57 | #include <bcmdevs.h> |
|---|
| 58 | #include <linux/if_ether.h> |
|---|
| 59 | // #include <linux/mii.h> |
|---|
| 60 | #include <linux/sockios.h> |
|---|
| 61 | #include <cymac.h> |
|---|
| 62 | #include <broadcom.h> |
|---|
| 63 | |
|---|
| 64 | #ifndef IP_ALEN |
|---|
| 65 | #define IP_ALEN 4 |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | #ifndef unlikely |
|---|
| 69 | #define unlikely(x) __builtin_expect((x),0) |
|---|
| 70 | #endif |
|---|
| 71 | |
|---|
| 72 | #define SIOCGMIIREG 0x8948 /* Read MII PHY register. */ |
|---|
| 73 | #define SIOCSMIIREG 0x8949 /* Write MII PHY register. */ |
|---|
| 74 | |
|---|
| 75 | struct mii_ioctl_data { |
|---|
| 76 | unsigned short phy_id; |
|---|
| 77 | unsigned short reg_num; |
|---|
| 78 | unsigned short val_in; |
|---|
| 79 | unsigned short val_out; |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | #define TRX_MAGIC_F7D3301 0x20100322 /* Belkin Share Max; router's birthday ? */ |
|---|
| 83 | #define TRX_MAGIC_F7D3302 0x20090928 /* Belkin Share; router's birthday ? */ |
|---|
| 84 | #define TRX_MAGIC_F7D4302 0x20091006 /* Belkin Play; router's birthday ? */ |
|---|
| 85 | |
|---|
| 86 | #ifdef HAVE_FONERA |
|---|
| 87 | static void inline getBoardMAC(char *mac) |
|---|
| 88 | { |
|---|
| 89 | // 102 |
|---|
| 90 | int i; |
|---|
| 91 | char op[32]; |
|---|
| 92 | unsigned char data[256]; |
|---|
| 93 | FILE *in; |
|---|
| 94 | |
|---|
| 95 | sprintf(op, "/dev/mtdblock/%d", getMTD("board_config")); |
|---|
| 96 | in = fopen(op, "rb"); |
|---|
| 97 | if (in == NULL) |
|---|
| 98 | return; |
|---|
| 99 | fread(data, 256, 1, in); |
|---|
| 100 | fclose(in); |
|---|
| 101 | sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", data[102] & 0xff, |
|---|
| 102 | data[103] & 0xff, data[104] & 0xff, data[105] & 0xff, |
|---|
| 103 | data[106] & 0xff, data[107] & 0xff); |
|---|
| 104 | } |
|---|
| 105 | #endif |
|---|
| 106 | |
|---|
| 107 | int count_processes(char *pidName) |
|---|
| 108 | { |
|---|
| 109 | FILE *fp; |
|---|
| 110 | char line[254]; |
|---|
| 111 | char safename[64]; |
|---|
| 112 | |
|---|
| 113 | sprintf(safename, " %s ", pidName); |
|---|
| 114 | char zombie[64]; |
|---|
| 115 | |
|---|
| 116 | sprintf(zombie, "Z [%s]", pidName); // do not count zombies |
|---|
| 117 | int i = 0; |
|---|
| 118 | |
|---|
| 119 | cprintf("Search for %s\n", pidName); |
|---|
| 120 | if ((fp = popen("ps", "r"))) { |
|---|
| 121 | while (fgets(line, sizeof(line), fp) != NULL) { |
|---|
| 122 | int len = strlen(line); |
|---|
| 123 | if (len > 254) |
|---|
| 124 | len = 254; |
|---|
| 125 | line[len - 1] = ' '; |
|---|
| 126 | line[len] = 0; |
|---|
| 127 | if (strstr(line, safename) && !strstr(line, zombie)) { |
|---|
| 128 | i++; |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | pclose(fp); |
|---|
| 132 | } |
|---|
| 133 | cprintf("Search done... %d\n", i); |
|---|
| 134 | |
|---|
| 135 | return i; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /* |
|---|
| 139 | * This function returns the number of days for the given month in the given |
|---|
| 140 | * year |
|---|
| 141 | */ |
|---|
| 142 | unsigned int daysformonth(unsigned int month, unsigned int year) |
|---|
| 143 | { |
|---|
| 144 | return (30 + (((month & 9) == 8) || ((month & 9) == 1)) - |
|---|
| 145 | (month == 2) - (!(((year % 4) == 0) |
|---|
| 146 | && (((year % 100) != 0) |
|---|
| 147 | || ((year % 400) == 0))) |
|---|
| 148 | && (month == 2))); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | #ifdef HAVE_AQOS |
|---|
| 152 | |
|---|
| 153 | /* obsolete |
|---|
| 154 | static char *get_wshaper_dev(void) |
|---|
| 155 | { |
|---|
| 156 | // if (nvram_match("wshaper_dev", "WAN")) |
|---|
| 157 | return get_wan_face(); |
|---|
| 158 | // else |
|---|
| 159 | // return "br0"; |
|---|
| 160 | } |
|---|
| 161 | */ |
|---|
| 162 | |
|---|
| 163 | static char *get_wanface(void) |
|---|
| 164 | { |
|---|
| 165 | char *dev = get_wan_face(); |
|---|
| 166 | |
|---|
| 167 | if (!strcmp(dev, "br0")) |
|---|
| 168 | dev = NULL; |
|---|
| 169 | return dev; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | void add_userip(char *ip, int idx, char *upstream, char *downstream, |
|---|
| 173 | char *lanstream) |
|---|
| 174 | { |
|---|
| 175 | system2("iptables -t mangle -D FILTER_IN -j CONNMARK --save"); |
|---|
| 176 | system2 |
|---|
| 177 | ("iptables -t mangle -D FILTER_IN -p tcp -m length --length 0:64 --tcp-flags ACK ACK -j MARK --set-mark 0x64"); |
|---|
| 178 | system2("iptables -t mangle -D FILTER_IN -j RETURN"); |
|---|
| 179 | |
|---|
| 180 | system2("iptables -t mangle -D FILTER_OUT -j CONNMARK --save"); |
|---|
| 181 | system2("iptables -t mangle -D FILTER_OUT -j RETURN"); |
|---|
| 182 | |
|---|
| 183 | int base = 1200 + idx; |
|---|
| 184 | char *dev = get_wanface(); |
|---|
| 185 | |
|---|
| 186 | long int lanlevel = atol(lanstream); |
|---|
| 187 | if (lanlevel < 1) |
|---|
| 188 | lanlevel = 1000000; |
|---|
| 189 | |
|---|
| 190 | if (dev) { |
|---|
| 191 | /* egress */ |
|---|
| 192 | if (nvram_match("qos_type", "0")) |
|---|
| 193 | sysprintf |
|---|
| 194 | ("tc class add dev %s parent 1:2 classid 1:%d htb rate %skbit ceil %skbit prio 5", |
|---|
| 195 | dev, base, upstream, upstream); |
|---|
| 196 | else |
|---|
| 197 | sysprintf |
|---|
| 198 | ("tc class add dev %s parent 1:1 classid 1:%d hfsc sc rate %skbit ul rate %skbit", |
|---|
| 199 | dev, base, upstream, upstream); |
|---|
| 200 | |
|---|
| 201 | sysprintf |
|---|
| 202 | ("tc qdisc add dev %s handle %d: parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 203 | dev, base, base); |
|---|
| 204 | sysprintf |
|---|
| 205 | ("tc filter add dev %s protocol ip pref 5 handle 0x%x fw classid 1:%d", |
|---|
| 206 | dev, base, base); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | /* ingress */ |
|---|
| 210 | if (nvram_match("qos_type", "0")) { |
|---|
| 211 | sysprintf |
|---|
| 212 | ("tc class add dev %s parent 1:2 classid 1:%d htb rate %skbit ceil %skbit prio 5", |
|---|
| 213 | "imq0", base, downstream, downstream); |
|---|
| 214 | sysprintf |
|---|
| 215 | ("tc class add dev %s parent 1:2 classid 1:%d htb rate %dkbit ceil %dkbit prio 5", |
|---|
| 216 | "imq1", base, lanlevel, lanlevel); |
|---|
| 217 | } else { |
|---|
| 218 | sysprintf |
|---|
| 219 | ("tc class add dev %s parent 1:1 classid 1:%d hfsc sc rate %skbit ul rate %skbit", |
|---|
| 220 | "imq0", base, downstream, downstream); |
|---|
| 221 | sysprintf |
|---|
| 222 | ("tc class add dev %s parent 1:2 classid 1:%d hfsc sc rate %dkbit ul rate %dkbit", |
|---|
| 223 | "imq1", base, lanlevel, lanlevel); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | sysprintf |
|---|
| 227 | ("tc qdisc add dev %s handle %d: parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 228 | "imq0", base, base); |
|---|
| 229 | |
|---|
| 230 | sysprintf |
|---|
| 231 | ("tc filter add dev %s protocol ip pref 5 handle 0x%x fw classid 1:%d", |
|---|
| 232 | "imq0", base, base); |
|---|
| 233 | sysprintf |
|---|
| 234 | ("tc filter add dev %s protocol ip pref 5 handle 0x%x fw classid 1:%d", |
|---|
| 235 | "imq1", base, base); |
|---|
| 236 | |
|---|
| 237 | sysprintf |
|---|
| 238 | ("iptables -t mangle -A FILTER_IN -d %s -m mark --mark 1 -j MARK --set-mark %d", |
|---|
| 239 | ip, base); |
|---|
| 240 | sysprintf |
|---|
| 241 | ("iptables -t mangle -A FILTER_IN -s %s -m mark --mark 1 -j MARK --set-mark %d", |
|---|
| 242 | ip, base); |
|---|
| 243 | sysprintf |
|---|
| 244 | ("iptables -t mangle -A FILTER_OUT -d %s -m mark --mark 0 -j MARK --set-mark %d", |
|---|
| 245 | ip, base); |
|---|
| 246 | sysprintf |
|---|
| 247 | ("iptables -t mangle -A FILTER_OUT -s %s -m mark --mark 0 -j MARK --set-mark %d", |
|---|
| 248 | ip, base); |
|---|
| 249 | |
|---|
| 250 | system2("iptables -t mangle -A FILTER_IN -j CONNMARK --save"); |
|---|
| 251 | system2 |
|---|
| 252 | ("iptables -t mangle -A FILTER_IN -p tcp -m length --length 0:64 --tcp-flags ACK ACK -j MARK --set-mark 0x64"); |
|---|
| 253 | system2("iptables -t mangle -A FILTER_IN -j RETURN"); |
|---|
| 254 | |
|---|
| 255 | system2("iptables -t mangle -A FILTER_OUT -j CONNMARK --save"); |
|---|
| 256 | system2("iptables -t mangle -A FILTER_OUT -j RETURN"); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | void add_usermac(char *mac, int idx, char *upstream, char *downstream, |
|---|
| 260 | char *lanstream) |
|---|
| 261 | { |
|---|
| 262 | int base = 1200 + idx; |
|---|
| 263 | char *dev = get_wanface(); |
|---|
| 264 | long int lanlevel = atol(lanstream); |
|---|
| 265 | |
|---|
| 266 | if (lanlevel < 1) |
|---|
| 267 | lanlevel = 1000000; |
|---|
| 268 | |
|---|
| 269 | if (dev) { |
|---|
| 270 | /* egress */ |
|---|
| 271 | if (nvram_match("qos_type", "0")) |
|---|
| 272 | sysprintf |
|---|
| 273 | ("tc class add dev %s parent 1:2 classid 1:%d htb rate %skbit ceil %skbit prio 5", |
|---|
| 274 | dev, base, upstream, upstream); |
|---|
| 275 | else |
|---|
| 276 | sysprintf |
|---|
| 277 | ("tc class add dev %s parent 1:1 classid 1:%d hfsc sc rate %skbit ul rate %skbit", |
|---|
| 278 | dev, base, upstream, upstream); |
|---|
| 279 | |
|---|
| 280 | sysprintf |
|---|
| 281 | ("tc qdisc add dev %s handle %d: parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 282 | dev, base, base); |
|---|
| 283 | sysprintf |
|---|
| 284 | ("tc filter add dev %s protocol ip pref 5 handle 0x%x fw classid 1:%d", |
|---|
| 285 | dev, base, base); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | /* ingress */ |
|---|
| 289 | if (nvram_match("qos_type", "0")) { |
|---|
| 290 | sysprintf |
|---|
| 291 | ("tc class add dev %s parent 1:2 classid 1:%d htb rate %skbit ceil %skbit prio 5", |
|---|
| 292 | "imq0", base, downstream, downstream); |
|---|
| 293 | sysprintf |
|---|
| 294 | ("tc class add dev %s parent 1:2 classid 1:%d htb rate %dkbit ceil %dkbit prio 5", |
|---|
| 295 | "imq1", base, lanlevel, lanlevel); |
|---|
| 296 | } else { |
|---|
| 297 | sysprintf |
|---|
| 298 | ("tc class add dev %s parent 1:1 classid 1:%d hfsc sc rate %skbit ul rate %skbit", |
|---|
| 299 | "imq0", base, downstream, downstream); |
|---|
| 300 | sysprintf |
|---|
| 301 | ("tc class add dev %s parent 1:2 classid 1:%d hfsc sc rate %dkbit ul rate %dkbit", |
|---|
| 302 | "imq1", base, lanlevel, lanlevel); |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | sysprintf |
|---|
| 306 | ("tc qdisc add dev %s handle %d: parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 307 | "imq0", base, base); |
|---|
| 308 | |
|---|
| 309 | sysprintf |
|---|
| 310 | ("tc filter add dev %s protocol ip pref 5 handle 0x%x fw classid 1:%d", |
|---|
| 311 | "imq0", base, base); |
|---|
| 312 | sysprintf |
|---|
| 313 | ("tc filter add dev %s protocol ip pref 5 handle 0x%x fw classid 1:%d", |
|---|
| 314 | "imq1", base, base); |
|---|
| 315 | |
|---|
| 316 | sysprintf |
|---|
| 317 | ("iptables -t mangle -I FILTER_IN 2 -m mac --mac-source %s -m mark --mark 1 -j MARK --set-mark %d", |
|---|
| 318 | mac, base); |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | #endif |
|---|
| 322 | int buf_to_file(char *path, char *buf) |
|---|
| 323 | { |
|---|
| 324 | FILE *fp; |
|---|
| 325 | |
|---|
| 326 | if ((fp = fopen(path, "w"))) { |
|---|
| 327 | fprintf(fp, "%s", buf); |
|---|
| 328 | fclose(fp); |
|---|
| 329 | return 1; |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | return 0; |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | int check_action(void) |
|---|
| 336 | { |
|---|
| 337 | char buf[80] = ""; |
|---|
| 338 | |
|---|
| 339 | if (file_to_buf(ACTION_FILE, buf, sizeof(buf))) { |
|---|
| 340 | if (!strcmp(buf, "ACT_TFTP_UPGRADE")) { |
|---|
| 341 | fprintf(stderr, "Upgrading from tftp now ...\n"); |
|---|
| 342 | return ACT_TFTP_UPGRADE; |
|---|
| 343 | } |
|---|
| 344 | #ifdef HAVE_HTTPS |
|---|
| 345 | else if (!strcmp(buf, "ACT_WEBS_UPGRADE")) { |
|---|
| 346 | fprintf(stderr, "Upgrading from web (https) now ...\n"); |
|---|
| 347 | return ACT_WEBS_UPGRADE; |
|---|
| 348 | } |
|---|
| 349 | #endif |
|---|
| 350 | else if (!strcmp(buf, "ACT_WEB_UPGRADE")) { |
|---|
| 351 | fprintf(stderr, "Upgrading from web (http) now ...\n"); |
|---|
| 352 | return ACT_WEB_UPGRADE; |
|---|
| 353 | } else if (!strcmp(buf, "ACT_SW_RESTORE")) { |
|---|
| 354 | fprintf(stderr, |
|---|
| 355 | "Receiving restore command from web ...\n"); |
|---|
| 356 | return ACT_SW_RESTORE; |
|---|
| 357 | } else if (!strcmp(buf, "ACT_HW_RESTORE")) { |
|---|
| 358 | fprintf(stderr, |
|---|
| 359 | "Receiving restore command from resetbutton ...\n"); |
|---|
| 360 | return ACT_HW_RESTORE; |
|---|
| 361 | } else if (!strcmp(buf, "ACT_NVRAM_COMMIT")) { |
|---|
| 362 | fprintf(stderr, "Committing nvram now ...\n"); |
|---|
| 363 | return ACT_NVRAM_COMMIT; |
|---|
| 364 | } else if (!strcmp(buf, "ACT_ERASE_NVRAM")) { |
|---|
| 365 | fprintf(stderr, "Erasing nvram now ...\n"); |
|---|
| 366 | return ACT_ERASE_NVRAM; |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | // fprintf(stderr, "Waiting for upgrading....\n"); |
|---|
| 370 | return ACT_IDLE; |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | int check_vlan_support(void) |
|---|
| 374 | { |
|---|
| 375 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA) || defined(HAVE_MERAKI) || defined(HAVE_LS2) || defined(HAVE_WHRAG108) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_OPENRISC) |
|---|
| 376 | return 0; |
|---|
| 377 | #else |
|---|
| 378 | |
|---|
| 379 | int brand = getRouterBrand(); |
|---|
| 380 | |
|---|
| 381 | switch (brand) { |
|---|
| 382 | #ifndef HAVE_BUFFALO |
|---|
| 383 | case ROUTER_ASUS_WL500GD: |
|---|
| 384 | return 1; |
|---|
| 385 | break; |
|---|
| 386 | #endif |
|---|
| 387 | case ROUTER_BUFFALO_WLAG54C: |
|---|
| 388 | case ROUTER_BUFFALO_WLA2G54C: |
|---|
| 389 | #ifndef HAVE_BUFFALO |
|---|
| 390 | case ROUTER_LINKSYS_WRT55AG: |
|---|
| 391 | case ROUTER_MOTOROLA_V1: |
|---|
| 392 | case ROUTER_MOTOROLA_WE800G: |
|---|
| 393 | case ROUTER_WAP54G_V1: |
|---|
| 394 | case ROUTER_SITECOM_WL105B: |
|---|
| 395 | case ROUTER_SITECOM_WL111: |
|---|
| 396 | case ROUTER_BUFFALO_WLI2_TX1_G54: |
|---|
| 397 | case ROUTER_BUFFALO_WLI_TX4_G54HP: |
|---|
| 398 | case ROUTER_BRCM4702_GENERIC: |
|---|
| 399 | case ROUTER_ASUS_WL500G: |
|---|
| 400 | case ROUTER_BELKIN_F5D7230_V2000: |
|---|
| 401 | case ROUTER_ASKEY_RT220XD: |
|---|
| 402 | #endif |
|---|
| 403 | return 0; |
|---|
| 404 | break; |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | unsigned long boardflags = |
|---|
| 408 | strtoul(nvram_safe_get("boardflags"), NULL, 0); |
|---|
| 409 | |
|---|
| 410 | if (boardflags & BFL_ENETVLAN) |
|---|
| 411 | return 1; |
|---|
| 412 | |
|---|
| 413 | if (nvram_match("boardtype", "bcm94710dev") |
|---|
| 414 | || nvram_match("boardtype", "0x0101") || (boardflags & 0x0100)) |
|---|
| 415 | return 1; |
|---|
| 416 | else |
|---|
| 417 | return 0; |
|---|
| 418 | #endif |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | void setRouter(char *name) |
|---|
| 422 | { |
|---|
| 423 | #ifdef HAVE_POWERNOC_WORT54G |
|---|
| 424 | nvram_set(NVROUTER, "WORT54G"); |
|---|
| 425 | #elif HAVE_POWERNOC_WOAP54G |
|---|
| 426 | nvram_set(NVROUTER, "WOAP54G"); |
|---|
| 427 | #elif HAVE_ERC |
|---|
| 428 | nvram_set(NVROUTER, "ServiceGate v1.0"); |
|---|
| 429 | #elif HAVE_OMNI |
|---|
| 430 | nvram_set(NVROUTER, "Omni Wifi Router"); |
|---|
| 431 | #elif HAVE_ALFA_BRANDING |
|---|
| 432 | nvram_set(NVROUTER, "WLAN base-station"); |
|---|
| 433 | if (name) |
|---|
| 434 | nvram_set("DD_BOARD2", name); |
|---|
| 435 | #elif HAVE_MAKSAT |
|---|
| 436 | if (name) |
|---|
| 437 | nvram_set("DD_BOARD2", name); |
|---|
| 438 | #ifdef HAVE_MAKSAT_BLANK |
|---|
| 439 | nvram_set(NVROUTER, "default"); |
|---|
| 440 | #else |
|---|
| 441 | nvram_set(NVROUTER, "MAKSAT"); |
|---|
| 442 | #endif |
|---|
| 443 | #elif HAVE_TMK |
|---|
| 444 | if (name) |
|---|
| 445 | nvram_set("DD_BOARD2", name); |
|---|
| 446 | nvram_set(NVROUTER, "KMT-WAS"); |
|---|
| 447 | #elif HAVE_BKM |
|---|
| 448 | if (name) |
|---|
| 449 | nvram_set("DD_BOARD2", name); |
|---|
| 450 | nvram_set(NVROUTER, "BKM-HSDL"); |
|---|
| 451 | #elif HAVE_TRIMAX |
|---|
| 452 | if (name) |
|---|
| 453 | nvram_set("DD_BOARD2", name); |
|---|
| 454 | nvram_set(NVROUTER, "M2M Dynamics"); |
|---|
| 455 | #elif HAVE_WIKINGS |
|---|
| 456 | if (name) |
|---|
| 457 | nvram_set("DD_BOARD2", name); |
|---|
| 458 | #ifdef HAVE_SUB3 |
|---|
| 459 | nvram_set(NVROUTER, "ExcelMin"); |
|---|
| 460 | #elif HAVE_SUB6 |
|---|
| 461 | nvram_set(NVROUTER, "ExcelMed"); |
|---|
| 462 | #else |
|---|
| 463 | nvram_set(NVROUTER, "Excellent"); |
|---|
| 464 | #endif |
|---|
| 465 | #elif HAVE_ESPOD |
|---|
| 466 | if (name) |
|---|
| 467 | nvram_set("DD_BOARD2", name); |
|---|
| 468 | #ifdef HAVE_SUB3 |
|---|
| 469 | nvram_set(NVROUTER, "ESPOD ES-3680"); |
|---|
| 470 | #elif HAVE_SUB6 |
|---|
| 471 | nvram_set(NVROUTER, "ESPOD ES-3680"); |
|---|
| 472 | #else |
|---|
| 473 | nvram_set(NVROUTER, "ESPOD ES-3680"); |
|---|
| 474 | #endif |
|---|
| 475 | #elif HAVE_CARLSONWIRELESS |
|---|
| 476 | nvram_set(NVROUTER, "LH-135/270 ST"); |
|---|
| 477 | #else |
|---|
| 478 | if (name) |
|---|
| 479 | nvram_set(NVROUTER, name); |
|---|
| 480 | #endif |
|---|
| 481 | cprintf("router is %s\n", getRouter()); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | char *getRouter() |
|---|
| 485 | { |
|---|
| 486 | char *n = nvram_get(NVROUTER); |
|---|
| 487 | |
|---|
| 488 | return n != NULL ? n : "Unknown Model"; |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | int internal_getRouterBrand() |
|---|
| 492 | { |
|---|
| 493 | #if defined(HAVE_ALLNETWRT) && !defined(HAVE_ECB9750) |
|---|
| 494 | unsigned long boardnum = strtoul(nvram_safe_get("boardnum"), NULL, 0); |
|---|
| 495 | |
|---|
| 496 | if (boardnum == 8 && nvram_match("boardtype", "0x048e") |
|---|
| 497 | && nvram_match("boardrev", "0x11")) { |
|---|
| 498 | setRouter("ALLNET EUROWRT 54"); |
|---|
| 499 | return ROUTER_ALLNET01; |
|---|
| 500 | } |
|---|
| 501 | eval("event", "3", "1", "15"); |
|---|
| 502 | return 0; |
|---|
| 503 | #elif defined(HAVE_ALLNETWRT) && defined(HAVE_EOC5610) |
|---|
| 504 | setRouter("Allnet Outdoor A/B/G CPE"); |
|---|
| 505 | return ROUTER_BOARD_LS2; |
|---|
| 506 | #else |
|---|
| 507 | #ifdef HAVE_NP28G |
|---|
| 508 | setRouter("Compex NP28G"); |
|---|
| 509 | return ROUTER_BOARD_NP28G; |
|---|
| 510 | #elif HAVE_WP54G |
|---|
| 511 | setRouter("Compex WP54G"); |
|---|
| 512 | return ROUTER_BOARD_WP54G; |
|---|
| 513 | #elif HAVE_ADM5120 |
|---|
| 514 | if (!nvram_match("DD_BOARD", "OSBRiDGE 5LXi")) |
|---|
| 515 | setRouter("Tonze AP-120"); |
|---|
| 516 | return ROUTER_BOARD_ADM5120; |
|---|
| 517 | #elif HAVE_RB500 |
|---|
| 518 | setRouter("Mikrotik RB500"); |
|---|
| 519 | return ROUTER_BOARD_500; |
|---|
| 520 | #elif HAVE_GEMTEK |
|---|
| 521 | setRouter("SuperGerry"); |
|---|
| 522 | return ROUTER_SUPERGERRY; |
|---|
| 523 | #elif HAVE_LAGUNA |
|---|
| 524 | char *filename = "/sys/devices/platform/cns3xxx-i2c.0/i2c-0/0-0050/eeprom"; /* bank2=0x100 kernel 3.0 */ |
|---|
| 525 | FILE *file = fopen(filename, "rb"); |
|---|
| 526 | if (!file) { |
|---|
| 527 | filename = "/sys/devices/platform/cns3xxx-i2c.0/i2c-adapter/i2c-0/0-0050/eeprom"; /* bank2=0x100 older kernel */ |
|---|
| 528 | file = fopen(filename, "r"); |
|---|
| 529 | } |
|---|
| 530 | if (file) { |
|---|
| 531 | fseek(file, 0x130, SEEK_SET); |
|---|
| 532 | char gwid[9]; |
|---|
| 533 | fread(&gwid[0], 9, 1, file); |
|---|
| 534 | fclose(file); |
|---|
| 535 | if (!strncmp(gwid, "GW2388", 6)) { |
|---|
| 536 | setRouter("Gateworks Laguna GW2388"); |
|---|
| 537 | return ROUTER_BOARD_GW2388; |
|---|
| 538 | } else if (!strncmp(gwid, "GW2380", 6)) { |
|---|
| 539 | setRouter("Gateworks Laguna GW2380"); |
|---|
| 540 | return ROUTER_BOARD_GW2380; |
|---|
| 541 | } else { |
|---|
| 542 | setRouter("Gateworks Laguna GWXXXX"); |
|---|
| 543 | return ROUTER_BOARD_GW2388; |
|---|
| 544 | } |
|---|
| 545 | } else { |
|---|
| 546 | setRouter("Gateworks Laguna UNKNOWN"); |
|---|
| 547 | return ROUTER_BOARD_GW2388; |
|---|
| 548 | |
|---|
| 549 | } |
|---|
| 550 | #elif HAVE_MI424WR |
|---|
| 551 | setRouter("Actiontec MI424WR"); |
|---|
| 552 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 553 | #elif HAVE_USR8200 |
|---|
| 554 | setRouter("US Robotics USR8200"); |
|---|
| 555 | return ROUTER_BOARD_GATEWORX; |
|---|
| 556 | #elif HAVE_TONZE |
|---|
| 557 | setRouter("Tonze AP-425"); |
|---|
| 558 | return ROUTER_BOARD_GATEWORX; |
|---|
| 559 | #elif HAVE_NOP8670 |
|---|
| 560 | setRouter("Senao NOP-8670"); |
|---|
| 561 | return ROUTER_BOARD_GATEWORX; |
|---|
| 562 | #elif HAVE_WRT300NV2 |
|---|
| 563 | setRouter("Linksys WRT300N v2"); |
|---|
| 564 | return ROUTER_BOARD_GATEWORX; |
|---|
| 565 | #elif HAVE_WG302V1 |
|---|
| 566 | setRouter("Netgear WG302 v1"); |
|---|
| 567 | return ROUTER_BOARD_GATEWORX; |
|---|
| 568 | #elif HAVE_WG302 |
|---|
| 569 | setRouter("Netgear WG302 v2"); |
|---|
| 570 | return ROUTER_BOARD_GATEWORX; |
|---|
| 571 | #elif HAVE_PRONGHORN |
|---|
| 572 | setRouter("ADI Engineering Pronghorn Metro"); |
|---|
| 573 | return ROUTER_BOARD_GATEWORX; |
|---|
| 574 | #elif HAVE_GATEWORX |
|---|
| 575 | char *filename = "/sys/devices/platform/IXP4XX-I2C.0/i2c-adapter:i2c-0/0-0051/eeprom"; /* bank2=0x100 |
|---|
| 576 | */ |
|---|
| 577 | FILE *file = fopen(filename, "r"); |
|---|
| 578 | if (!file) { |
|---|
| 579 | filename = "/sys/devices/platform/IXP4XX-I2C.0/i2c-0/0-0051/eeprom"; //for 2.6.34.6 |
|---|
| 580 | file = fopen(filename, "r"); |
|---|
| 581 | } |
|---|
| 582 | if (file) // new detection scheme |
|---|
| 583 | { |
|---|
| 584 | |
|---|
| 585 | char *gwid; |
|---|
| 586 | char temp[64]; |
|---|
| 587 | int ret = fread(temp, 40, 1, file); |
|---|
| 588 | if (ret < 1) { |
|---|
| 589 | fclose(file); |
|---|
| 590 | goto old_way; |
|---|
| 591 | } |
|---|
| 592 | gwid = &temp[32]; |
|---|
| 593 | gwid[8] = 0; |
|---|
| 594 | fclose(file); |
|---|
| 595 | if (!strncmp(gwid, "GW2347", 6)) { |
|---|
| 596 | setRouter("Gateworks Avila GW2347"); |
|---|
| 597 | return ROUTER_BOARD_GATEWORX_SWAP; |
|---|
| 598 | } |
|---|
| 599 | if (!strncmp(gwid, "GW2357", 6)) { |
|---|
| 600 | setRouter("Gateworks Avila GW2357"); |
|---|
| 601 | return ROUTER_BOARD_GATEWORX_SWAP; |
|---|
| 602 | } |
|---|
| 603 | if (!strncmp(gwid, "GW2353", 6)) { |
|---|
| 604 | setRouter("Gateworks Avila GW2353"); |
|---|
| 605 | return ROUTER_BOARD_GATEWORX; |
|---|
| 606 | } |
|---|
| 607 | if (!strncmp(gwid, "GW2348-2", 8)) { |
|---|
| 608 | setRouter("Gateworks Avila GW2348-2"); |
|---|
| 609 | return ROUTER_BOARD_GATEWORX; |
|---|
| 610 | } |
|---|
| 611 | if (!strncmp(gwid, "GW2348-4", 8)) { |
|---|
| 612 | setRouter("Gateworks Avila GW2348-4"); |
|---|
| 613 | return ROUTER_BOARD_GATEWORX; |
|---|
| 614 | } |
|---|
| 615 | if (!strncmp(gwid, "GW2348", 6)) { |
|---|
| 616 | setRouter("Gateworks Avila GW2348-4/2"); |
|---|
| 617 | return ROUTER_BOARD_GATEWORX; |
|---|
| 618 | } |
|---|
| 619 | if (!strncmp(gwid, "GW2358", 6)) { |
|---|
| 620 | setRouter("Gateworks Cambria GW2358-4"); |
|---|
| 621 | return ROUTER_BOARD_GATEWORX; |
|---|
| 622 | } |
|---|
| 623 | if (!strncmp(gwid, "GW2350", 6)) { |
|---|
| 624 | setRouter("Gateworks Cambria GW2350"); |
|---|
| 625 | return ROUTER_BOARD_GATEWORX; |
|---|
| 626 | } |
|---|
| 627 | if (!strncmp(gwid, "GW2369", 6)) { |
|---|
| 628 | setRouter("Gateworks Avila GW2369"); |
|---|
| 629 | return ROUTER_BOARD_GATEWORX_GW2369; |
|---|
| 630 | } |
|---|
| 631 | if (!strncmp(gwid, "GW2355", 6)) { |
|---|
| 632 | setRouter("Gateworks Avila GW2355"); |
|---|
| 633 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 634 | } |
|---|
| 635 | if (!strncmp(gwid, "GW2345", 6)) { |
|---|
| 636 | setRouter("Gateworks Avila GW2345"); |
|---|
| 637 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 638 | } |
|---|
| 639 | } |
|---|
| 640 | old_way:; |
|---|
| 641 | struct mii_ioctl_data *data; |
|---|
| 642 | struct ifreq iwr; |
|---|
| 643 | int s = socket(AF_INET, SOCK_DGRAM, 0); |
|---|
| 644 | |
|---|
| 645 | if (s < 0) { |
|---|
| 646 | fprintf(stderr, "socket(SOCK_DRAGM)\n"); |
|---|
| 647 | setRouter("Gateworks Avila"); |
|---|
| 648 | return ROUTER_BOARD_GATEWORX; |
|---|
| 649 | } |
|---|
| 650 | (void)strncpy(iwr.ifr_name, "ixp0", sizeof("ixp0")); |
|---|
| 651 | data = (struct mii_ioctl_data *)&iwr.ifr_data; |
|---|
| 652 | data->phy_id = 1; |
|---|
| 653 | #define IX_ETH_ACC_MII_PHY_ID1_REG 0x2 /* PHY identifier 1 Register */ |
|---|
| 654 | #define IX_ETH_ACC_MII_PHY_ID2_REG 0x3 /* PHY identifier 2 Register */ |
|---|
| 655 | data->reg_num = IX_ETH_ACC_MII_PHY_ID1_REG; |
|---|
| 656 | ioctl(s, SIOCGMIIREG, &iwr); |
|---|
| 657 | data->phy_id = 1; |
|---|
| 658 | data->reg_num = IX_ETH_ACC_MII_PHY_ID1_REG; |
|---|
| 659 | ioctl(s, SIOCGMIIREG, &iwr); |
|---|
| 660 | int reg1 = data->val_out; |
|---|
| 661 | |
|---|
| 662 | data->phy_id = 1; |
|---|
| 663 | data->reg_num = IX_ETH_ACC_MII_PHY_ID2_REG; |
|---|
| 664 | ioctl(s, SIOCGMIIREG, &iwr); |
|---|
| 665 | int reg2 = data->val_out; |
|---|
| 666 | |
|---|
| 667 | close(s); |
|---|
| 668 | fprintf(stderr, "phy id %X:%X\n", reg1, reg2); |
|---|
| 669 | if (reg1 == 0x2000 && reg2 == 0x5c90) { |
|---|
| 670 | setRouter("Avila GW2347"); |
|---|
| 671 | return ROUTER_BOARD_GATEWORX_SWAP; |
|---|
| 672 | } else if (reg1 == 0x13 && reg2 == 0x7a11) { |
|---|
| 673 | #if HAVE_ALFA_BRANDING |
|---|
| 674 | setRouter("WLAN base-station"); |
|---|
| 675 | #else |
|---|
| 676 | setRouter("Gateworks Avila GW2348-4/2"); |
|---|
| 677 | #endif |
|---|
| 678 | return ROUTER_BOARD_GATEWORX; |
|---|
| 679 | } else if (reg1 == 0x143 && reg2 == 0xbc31) // broadcom phy |
|---|
| 680 | { |
|---|
| 681 | setRouter("ADI Engineering Pronghorn Metro"); |
|---|
| 682 | return ROUTER_BOARD_GATEWORX; |
|---|
| 683 | } else if (reg1 == 0x22 && reg2 == 0x1450) // kendin switch |
|---|
| 684 | { |
|---|
| 685 | setRouter("Gateworks Avila GW2345"); |
|---|
| 686 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 687 | } else if (reg1 == 0x0 && reg2 == 0x8201) // realtek |
|---|
| 688 | { |
|---|
| 689 | setRouter("Compex WP188"); |
|---|
| 690 | return ROUTER_BOARD_GATEWORX; |
|---|
| 691 | } else { |
|---|
| 692 | setRouter("Unknown"); |
|---|
| 693 | return ROUTER_BOARD_GATEWORX; |
|---|
| 694 | } |
|---|
| 695 | #elif HAVE_RT2880 |
|---|
| 696 | |
|---|
| 697 | #ifdef HAVE_ECB9750 |
|---|
| 698 | #ifdef HAVE_ALLNETWRT |
|---|
| 699 | setRouter("Allnet 802.11n Router"); |
|---|
| 700 | #else |
|---|
| 701 | setRouter("Senao ECB-9750"); |
|---|
| 702 | #endif |
|---|
| 703 | return ROUTER_BOARD_ECB9750; |
|---|
| 704 | #elif HAVE_ALLNET11N |
|---|
| 705 | setRouter("Allnet 802.11n Router"); |
|---|
| 706 | return ROUTER_BOARD_WHRG300N; |
|---|
| 707 | #elif HAVE_TECHNAXX3G |
|---|
| 708 | setRouter("Technaxx 3G Router"); |
|---|
| 709 | return ROUTER_BOARD_TECHNAXX3G; |
|---|
| 710 | #elif HAVE_AR670W |
|---|
| 711 | setRouter("Airlink 101 AR670W"); |
|---|
| 712 | return ROUTER_BOARD_AR670W; |
|---|
| 713 | #elif HAVE_AR690W |
|---|
| 714 | setRouter("Airlink 101 AR690W"); |
|---|
| 715 | return ROUTER_BOARD_AR690W; |
|---|
| 716 | #elif HAVE_RT15N |
|---|
| 717 | setRouter("Asus RT-N15"); |
|---|
| 718 | return ROUTER_BOARD_RT15N; |
|---|
| 719 | #elif HAVE_BR6574N |
|---|
| 720 | setRouter("Edimax BR-6574N"); |
|---|
| 721 | return ROUTER_BOARD_BR6574N; |
|---|
| 722 | #elif HAVE_ESR6650 |
|---|
| 723 | setRouter("Senao ESR-6650"); |
|---|
| 724 | return ROUTER_BOARD_ESR6650; |
|---|
| 725 | #elif HAVE_EAP9550 |
|---|
| 726 | setRouter("Senao EAP-9550"); |
|---|
| 727 | return ROUTER_BOARD_EAP9550; |
|---|
| 728 | #elif HAVE_ESR9752 |
|---|
| 729 | setRouter("Senao ESR-9752"); |
|---|
| 730 | return ROUTER_BOARD_ESR9752; |
|---|
| 731 | #elif HAVE_ACXNR22 |
|---|
| 732 | setRouter("Aceex NR22"); |
|---|
| 733 | return ROUTER_BOARD_ACXNR22; |
|---|
| 734 | #elif HAVE_W502U |
|---|
| 735 | setRouter("Alfa AIP-W502U"); |
|---|
| 736 | return ROUTER_BOARD_W502U; |
|---|
| 737 | #elif HAVE_DIR615 |
|---|
| 738 | setRouter("Dlink-DIR615 rev d"); |
|---|
| 739 | return ROUTER_BOARD_DIR615D; |
|---|
| 740 | #elif HAVE_RT3352 |
|---|
| 741 | setRouter("Ralink RT3352 Device"); |
|---|
| 742 | return ROUTER_BOARD_RT3352; |
|---|
| 743 | #elif HAVE_NEPTUNE |
|---|
| 744 | setRouter("Neptune-Mini"); |
|---|
| 745 | return ROUTER_BOARD_NEPTUNE; |
|---|
| 746 | #elif HAVE_TECHNAXX |
|---|
| 747 | setRouter("TECHNAXX Router-150 Wifi-N"); |
|---|
| 748 | return ROUTER_BOARD_TECHNAXX; |
|---|
| 749 | #elif HAVE_RT10N |
|---|
| 750 | setRouter("Asus RT-N10+"); |
|---|
| 751 | return ROUTER_ASUS_RTN10PLUS; |
|---|
| 752 | #elif HAVE_DIR600 |
|---|
| 753 | #ifdef HAVE_DIR300 |
|---|
| 754 | setRouter("Dlink-DIR300 rev b"); |
|---|
| 755 | #else |
|---|
| 756 | setRouter("Dlink-DIR600 rev b"); |
|---|
| 757 | #endif |
|---|
| 758 | return ROUTER_BOARD_DIR600B; |
|---|
| 759 | #elif HAVE_RT13NB1 |
|---|
| 760 | setRouter("Asus RT-N13U B1"); |
|---|
| 761 | return ROUTER_BOARD_WHRG300N; |
|---|
| 762 | #elif HAVE_ASUSRTN13U |
|---|
| 763 | setRouter("Asus RT-N13U"); |
|---|
| 764 | return ROUTER_BOARD_WHRG300N; |
|---|
| 765 | #elif HAVE_F5D8235 |
|---|
| 766 | setRouter("Belkin F5D8235-4 v2"); |
|---|
| 767 | return ROUTER_BOARD_F5D8235; |
|---|
| 768 | #elif HAVE_WCRGN |
|---|
| 769 | setRouter("Buffalo WCR-GN"); |
|---|
| 770 | return ROUTER_BOARD_WCRGN; |
|---|
| 771 | #elif HAVE_WHRG300N |
|---|
| 772 | setRouter("Buffalo WHR-G300N"); |
|---|
| 773 | return ROUTER_BOARD_WHRG300N; |
|---|
| 774 | #elif HAVE_WR5422 |
|---|
| 775 | setRouter("Repotec RP-WR5422"); |
|---|
| 776 | return ROUTER_BOARD_WR5422; |
|---|
| 777 | #else |
|---|
| 778 | setRouter("Generic RT2880"); |
|---|
| 779 | return ROUTER_BOARD_RT2880; |
|---|
| 780 | #endif |
|---|
| 781 | #elif HAVE_X86 |
|---|
| 782 | #ifdef HAVE_CORENET |
|---|
| 783 | setRouter("CORENET X86i"); |
|---|
| 784 | return ROUTER_BOARD_X86; |
|---|
| 785 | #else |
|---|
| 786 | setRouter("Generic X86"); |
|---|
| 787 | return ROUTER_BOARD_X86; |
|---|
| 788 | #endif |
|---|
| 789 | #elif HAVE_XSCALE |
|---|
| 790 | setRouter("NewMedia Dual A/B/G"); |
|---|
| 791 | return ROUTER_BOARD_XSCALE; |
|---|
| 792 | #elif HAVE_MAGICBOX |
|---|
| 793 | setRouter("OpenRB PowerPC Board"); |
|---|
| 794 | return ROUTER_BOARD_MAGICBOX; |
|---|
| 795 | #elif HAVE_RB1000 |
|---|
| 796 | setRouter("Mikrotik RB1000"); |
|---|
| 797 | return ROUTER_BOARD_RB600; |
|---|
| 798 | #elif HAVE_RB800 |
|---|
| 799 | setRouter("Mikrotik RB800"); |
|---|
| 800 | return ROUTER_BOARD_RB600; |
|---|
| 801 | #elif HAVE_RB600 |
|---|
| 802 | setRouter("Mikrotik RB600"); |
|---|
| 803 | return ROUTER_BOARD_RB600; |
|---|
| 804 | #elif HAVE_GWMF54G2 |
|---|
| 805 | setRouter("Planex GW-MF54G2"); |
|---|
| 806 | char mac[32]; |
|---|
| 807 | getBoardMAC(mac); |
|---|
| 808 | if (!strncmp(mac, "00:19:3B", 8) || !strncmp(mac, "00:02:6F", 8) |
|---|
| 809 | || !strncmp(mac, "00:15:6D", 8)) { |
|---|
| 810 | fprintf(stderr, "unsupported board\n"); |
|---|
| 811 | sys_reboot(); |
|---|
| 812 | } |
|---|
| 813 | return ROUTER_BOARD_FONERA; |
|---|
| 814 | #elif HAVE_WRT54GV7 |
|---|
| 815 | setRouter("Linksys WRT54G v7"); |
|---|
| 816 | return ROUTER_BOARD_FONERA; |
|---|
| 817 | #elif HAVE_WRK54G |
|---|
| 818 | setRouter("Linksys WRK54G v3"); |
|---|
| 819 | return ROUTER_BOARD_FONERA; |
|---|
| 820 | #elif HAVE_WGT624 |
|---|
| 821 | setRouter("Netgear WGT624 v4"); |
|---|
| 822 | return ROUTER_BOARD_FONERA; |
|---|
| 823 | #elif HAVE_WPE53G |
|---|
| 824 | setRouter("Compex WPE53G"); |
|---|
| 825 | return ROUTER_BOARD_FONERA; |
|---|
| 826 | #elif HAVE_NP25G |
|---|
| 827 | setRouter("Compex NP25G"); |
|---|
| 828 | return ROUTER_BOARD_FONERA; |
|---|
| 829 | #elif HAVE_MR3202A |
|---|
| 830 | setRouter("MR3202A"); |
|---|
| 831 | return ROUTER_BOARD_FONERA; |
|---|
| 832 | #elif HAVE_DLM101 |
|---|
| 833 | setRouter("Doodle Labs DLM-101"); |
|---|
| 834 | return ROUTER_BOARD_FONERA; |
|---|
| 835 | #elif HAVE_AR430W |
|---|
| 836 | setRouter("Airlink-101 AR430W"); |
|---|
| 837 | return ROUTER_BOARD_FONERA; |
|---|
| 838 | #elif HAVE_DIR400 |
|---|
| 839 | setRouter("D-Link DIR-400"); |
|---|
| 840 | return ROUTER_BOARD_FONERA2200; |
|---|
| 841 | #elif HAVE_WRT54G2 |
|---|
| 842 | setRouter("Linksys WRT54G2 v1.1"); |
|---|
| 843 | return ROUTER_BOARD_FONERA; |
|---|
| 844 | #elif HAVE_RTG32 |
|---|
| 845 | setRouter("Asus RT-G32"); |
|---|
| 846 | return ROUTER_BOARD_FONERA; |
|---|
| 847 | #elif HAVE_DIR300 |
|---|
| 848 | setRouter("D-Link DIR-300"); |
|---|
| 849 | return ROUTER_BOARD_FONERA; |
|---|
| 850 | #elif HAVE_CNC |
|---|
| 851 | setRouter("WiFi4You Outdoor AP"); |
|---|
| 852 | return ROUTER_BOARD_FONERA; |
|---|
| 853 | #elif defined(HAVE_CORENET) && defined(HAVE_NS2) |
|---|
| 854 | setRouter("CORENET XNS2"); |
|---|
| 855 | return ROUTER_BOARD_LS2; |
|---|
| 856 | #elif defined(HAVE_CORENET) && defined(HAVE_LC2) |
|---|
| 857 | setRouter("CORENET XLO2"); |
|---|
| 858 | return ROUTER_BOARD_LS2; |
|---|
| 859 | #elif defined(HAVE_CORENET) && defined(HAVE_EOC2610) |
|---|
| 860 | setRouter("CORENET XC61"); |
|---|
| 861 | return ROUTER_BOARD_FONERA; |
|---|
| 862 | #elif defined(HAVE_CORENET) && defined(HAVE_EOC1650) |
|---|
| 863 | setRouter("CORENET XC65"); |
|---|
| 864 | return ROUTER_BOARD_FONERA; |
|---|
| 865 | #elif defined(HAVE_CORENET) && defined(HAVE_BS2) |
|---|
| 866 | setRouter("CORENET XBU2"); |
|---|
| 867 | return ROUTER_BOARD_LS2; |
|---|
| 868 | #elif defined(HAVE_CORENET) && defined(HAVE_BS2HP) |
|---|
| 869 | setRouter("CORENET MBU2i"); |
|---|
| 870 | return ROUTER_BOARD_LS2; |
|---|
| 871 | #elif HAVE_WBD500 |
|---|
| 872 | setRouter("Wiligear WBD-500"); |
|---|
| 873 | return ROUTER_BOARD_FONERA; |
|---|
| 874 | #elif HAVE_EOC1650 |
|---|
| 875 | setRouter("Senao EOC-1650"); |
|---|
| 876 | return ROUTER_BOARD_FONERA; |
|---|
| 877 | #elif HAVE_EOC2611 |
|---|
| 878 | setRouter("Senao EOC-2611"); |
|---|
| 879 | return ROUTER_BOARD_FONERA; |
|---|
| 880 | #elif HAVE_EOC2610 |
|---|
| 881 | #ifdef HAVE_TRIMAX |
|---|
| 882 | setRouter("M2M-1200"); |
|---|
| 883 | #else |
|---|
| 884 | setRouter("Senao EOC-2610"); |
|---|
| 885 | #endif |
|---|
| 886 | return ROUTER_BOARD_FONERA; |
|---|
| 887 | #elif HAVE_ECB3500 |
|---|
| 888 | setRouter("Senao ECB-3500"); |
|---|
| 889 | return ROUTER_BOARD_FONERA; |
|---|
| 890 | #elif HAVE_EAP3660 |
|---|
| 891 | setRouter("Senao EAP-3660"); |
|---|
| 892 | return ROUTER_BOARD_FONERA; |
|---|
| 893 | #elif HAVE_MR3201A |
|---|
| 894 | setRouter("Accton MR3201A"); |
|---|
| 895 | return ROUTER_BOARD_FONERA; |
|---|
| 896 | #elif HAVE_FONERA |
|---|
| 897 | struct mii_ioctl_data *data; |
|---|
| 898 | struct ifreq iwr; |
|---|
| 899 | char mac[32]; |
|---|
| 900 | getBoardMAC(mac); |
|---|
| 901 | if (!strncmp(mac, "00:19:3B", 8) || !strncmp(mac, "00:02:6F", 8) |
|---|
| 902 | || !strncmp(mac, "00:15:6D", 8) || !strncmp(mac, "00:C0:CA", 8)) { |
|---|
| 903 | fprintf(stderr, "unsupported board\n"); |
|---|
| 904 | sys_reboot(); |
|---|
| 905 | } |
|---|
| 906 | int s = socket(AF_INET, SOCK_DGRAM, 0); |
|---|
| 907 | |
|---|
| 908 | if (s < 0) { |
|---|
| 909 | fprintf(stderr, "socket(SOCK_DRAGM)\n"); |
|---|
| 910 | setRouter("Fonera 2100/2200"); |
|---|
| 911 | return ROUTER_BOARD_FONERA; |
|---|
| 912 | } |
|---|
| 913 | (void)strncpy(iwr.ifr_name, "eth0", sizeof("eth0")); |
|---|
| 914 | data = (struct mii_ioctl_data *)&iwr.ifr_data; |
|---|
| 915 | data->phy_id = 0x10; |
|---|
| 916 | data->reg_num = 0x2; |
|---|
| 917 | ioctl(s, SIOCGMIIREG, &iwr); |
|---|
| 918 | data->phy_id = 0x10; |
|---|
| 919 | data->reg_num = 0x2; |
|---|
| 920 | ioctl(s, SIOCGMIIREG, &iwr); |
|---|
| 921 | if (data->val_out == 0x0141) { |
|---|
| 922 | data->phy_id = 0x10; |
|---|
| 923 | data->reg_num = 0x3; |
|---|
| 924 | ioctl(s, SIOCGMIIREG, &iwr); |
|---|
| 925 | close(s); |
|---|
| 926 | if ((data->val_out & 0xfc00) != 0x0c00) // marvell phy |
|---|
| 927 | { |
|---|
| 928 | setRouter("Fonera 2100/2200"); |
|---|
| 929 | return ROUTER_BOARD_FONERA; |
|---|
| 930 | } else { |
|---|
| 931 | setRouter("Fonera 2201"); |
|---|
| 932 | return ROUTER_BOARD_FONERA2200; |
|---|
| 933 | } |
|---|
| 934 | } else { |
|---|
| 935 | setRouter("Fonera 2100/2200"); |
|---|
| 936 | return ROUTER_BOARD_FONERA; |
|---|
| 937 | } |
|---|
| 938 | #elif HAVE_MERAKI |
|---|
| 939 | setRouter("Meraki Mini"); |
|---|
| 940 | return ROUTER_BOARD_MERAKI; |
|---|
| 941 | #elif HAVE_BWRG1000 |
|---|
| 942 | setRouter("Bountiful BWRG-1000"); |
|---|
| 943 | return ROUTER_BOARD_LS2; |
|---|
| 944 | #elif HAVE_WNR2200 |
|---|
| 945 | setRouter("Netgear WNR2200"); |
|---|
| 946 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 947 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 948 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 949 | #elif HAVE_WNR2000 |
|---|
| 950 | setRouter("Netgear WNR2000v3"); |
|---|
| 951 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 952 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 953 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 954 | #elif HAVE_WLAEAG300N |
|---|
| 955 | #ifdef HAVE_BUFFALO |
|---|
| 956 | setRouter("WLAE-AG300N"); |
|---|
| 957 | #else |
|---|
| 958 | setRouter("Buffalo WLAE-AG300N"); |
|---|
| 959 | #endif |
|---|
| 960 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 961 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 962 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 963 | #elif HAVE_HORNET |
|---|
| 964 | setRouter("Atheros Hornet"); |
|---|
| 965 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 966 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 967 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 968 | #elif HAVE_DIR825C1 |
|---|
| 969 | setRouter("Atheros DIR825-C1"); |
|---|
| 970 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 971 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 972 | nvram_default_get("ath1_rxantenna", "3"); |
|---|
| 973 | nvram_default_get("ath1_txantenna", "3"); |
|---|
| 974 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 975 | #elif HAVE_WASP |
|---|
| 976 | setRouter("Atheros Wasp"); |
|---|
| 977 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 978 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 979 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 980 | #elif HAVE_WHRHPG300N |
|---|
| 981 | #ifdef HAVE_BUFFALO |
|---|
| 982 | setRouter("WHR-HP-G300N"); |
|---|
| 983 | #else |
|---|
| 984 | setRouter("Buffalo WHR-HP-G300N"); |
|---|
| 985 | #endif |
|---|
| 986 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 987 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 988 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 989 | #elif HAVE_WHRG300NV2 |
|---|
| 990 | #ifdef HAVE_BUFFALO |
|---|
| 991 | setRouter("WHR-G300N"); |
|---|
| 992 | #else |
|---|
| 993 | setRouter("Buffalo WHR-G300N"); |
|---|
| 994 | #endif |
|---|
| 995 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 996 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 997 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 998 | #elif HAVE_WHRHPGN |
|---|
| 999 | #ifdef HAVE_BUFFALO |
|---|
| 1000 | setRouter("WHR-HP-GN"); |
|---|
| 1001 | #else |
|---|
| 1002 | setRouter("Buffalo WHR-HP-GN"); |
|---|
| 1003 | #endif |
|---|
| 1004 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1005 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1006 | return ROUTER_BOARD_WHRHPGN; |
|---|
| 1007 | #elif HAVE_JJAP93 |
|---|
| 1008 | setRouter("JJPLUS AP93"); |
|---|
| 1009 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1010 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1011 | return ROUTER_BOARD_PB42; |
|---|
| 1012 | #elif HAVE_JJAP005 |
|---|
| 1013 | setRouter("JJPLUS AP005"); |
|---|
| 1014 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1015 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1016 | return ROUTER_BOARD_PB42; |
|---|
| 1017 | #elif HAVE_JJAP501 |
|---|
| 1018 | setRouter("JJPLUS AP501"); |
|---|
| 1019 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1020 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1021 | return ROUTER_BOARD_PB42; |
|---|
| 1022 | #elif HAVE_AC722 |
|---|
| 1023 | setRouter("ACCTON AC722"); |
|---|
| 1024 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1025 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1026 | return ROUTER_BOARD_PB42; |
|---|
| 1027 | #elif HAVE_AC622 |
|---|
| 1028 | setRouter("ACCTON AC622"); |
|---|
| 1029 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1030 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1031 | return ROUTER_BOARD_PB42; |
|---|
| 1032 | #elif HAVE_UBNTM |
|---|
| 1033 | typedef struct UBNTDEV { |
|---|
| 1034 | char *devicename; // device name |
|---|
| 1035 | unsigned short devid; // pci subdevice id |
|---|
| 1036 | char *rxchain; // rx chainmask |
|---|
| 1037 | char *txchain; // tx chainmask |
|---|
| 1038 | int dddev; // dd-wrt device id |
|---|
| 1039 | int offset; // frequency offset |
|---|
| 1040 | }; |
|---|
| 1041 | |
|---|
| 1042 | /* these values are guessed and need to be validated */ |
|---|
| 1043 | #define M900 (- (2427 - 907)) |
|---|
| 1044 | #define M365 (- (5540 - 3650)) |
|---|
| 1045 | #define M35 (- (5540 - 3540)) |
|---|
| 1046 | #define M10 (- (5540 - 10322)) |
|---|
| 1047 | struct UBNTDEV dev[] = { |
|---|
| 1048 | {"Ubiquiti NanoStation M2", 0xe002, "3", "3", ROUTER_BOARD_NS2M, 0}, // |
|---|
| 1049 | {"Ubiquiti NanoStation M2", 0xe012, "3", "3", ROUTER_BOARD_NS2M, 0}, // |
|---|
| 1050 | {"Ubiquiti NanoStation M5", 0xe005, "3", "3", ROUTER_BOARD_NS5M, 0}, // |
|---|
| 1051 | {"Ubiquiti NanoStation M3", 0xe035, "3", "3", ROUTER_BOARD_NS5M, M35}, // |
|---|
| 1052 | {"Ubiquiti NanoStation M365", 0xe003, "3", "3", ROUTER_BOARD_NS5M, M365}, // |
|---|
| 1053 | // {"Ubiquiti NanoStation M900 GPS", 0xe0b9, "3", "3", ROUTER_BOARD_NS5M, M900}, // |
|---|
| 1054 | {"Ubiquiti Rocket M2", 0xe102, "3", "3", ROUTER_BOARD_R2M, 0}, // |
|---|
| 1055 | {"Ubiquiti Rocket M2", 0xe112, "3", "3", ROUTER_BOARD_R2M, 0}, // |
|---|
| 1056 | {"Ubiquiti Rocket M2", 0xe1b2, "3", "3", ROUTER_BOARD_R2M, 0}, // |
|---|
| 1057 | {"Ubiquiti Rocket M2 GPS", 0xe1c2, "3", "3", ROUTER_BOARD_R2M, 0}, // |
|---|
| 1058 | {"Ubiquiti Rocket M2 Titanium", 0xe1d2, "3", "3", ROUTER_BOARD_R2M, 0}, // Titanium |
|---|
| 1059 | {"Ubiquiti Rocket M5", 0xe105, "3", "3", ROUTER_BOARD_R5M, 0}, // |
|---|
| 1060 | {"Ubiquiti Rocket M5", 0xe1b5, "3", "3", ROUTER_BOARD_R5M, 0}, // |
|---|
| 1061 | {"Ubiquiti Rocket M5 GPS", 0xe1c5, "3", "3", ROUTER_BOARD_R5M, 0}, // |
|---|
| 1062 | {"Ubiquiti Rocket M5 Titanium", 0xe1d5, "3", "3", ROUTER_BOARD_R5M, 0}, // Titanium |
|---|
| 1063 | {"Ubiquiti Rocket M3", 0xe1c3, "3", "3", ROUTER_BOARD_R5M, M35}, // |
|---|
| 1064 | {"Ubiquiti Rocket M3 GPS", 0xe1e3, "3", "3", ROUTER_BOARD_R5M, M35}, // |
|---|
| 1065 | {"Ubiquiti Rocket M5 X3", 0xe3a5, "3", "3", ROUTER_BOARD_R5M, 0}, // |
|---|
| 1066 | {"Ubiquiti Rocket M365", 0xe1b3, "3", "3", ROUTER_BOARD_R5M, M365}, // |
|---|
| 1067 | {"Ubiquiti Rocket M365 GPS", 0xe1d3, "3", "3", ROUTER_BOARD_R5M, M365}, // |
|---|
| 1068 | {"Ubiquiti Rocket M900", 0xe1b9, "3", "3", ROUTER_BOARD_R2M, M900}, // |
|---|
| 1069 | {"Ubiquiti Rocket M900 GPS", 0xe1d9, "3", "3", ROUTER_BOARD_R2M, M900}, // |
|---|
| 1070 | {"Ubiquiti Bullet M2", 0xe202, "1", "1", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1071 | {"Ubiquiti Bullet M5", 0xe205, "1", "1", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1072 | {"Ubiquiti Airgrid M2", 0xe212, "1", "1", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1073 | {"Ubiquiti Airgrid M2", 0xe242, "1", "1", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1074 | {"Ubiquiti Airgrid M5", 0xe215, "1", "1", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1075 | {"Ubiquiti Airgrid M5", 0xe245, "1", "1", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1076 | {"Ubiquiti AirRouter", 0xe4a2, "3", "3", ROUTER_BOARD_NS2M, 0}, // |
|---|
| 1077 | {"Ubiquiti AirRouter", 0xe4b2, "3", "3", ROUTER_BOARD_NS2M, 0}, // |
|---|
| 1078 | {"Ubiquiti Pico M2", 0xe302, "1", "1", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1079 | {"Ubiquiti Pico M5", 0xe305, "1", "1", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1080 | {"Ubiquiti Airwire", 0xe405, "3", "3", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1081 | {"Ubiquiti Airwire", 0xe4a5, "3", "3", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1082 | {"Ubiquiti Loco M5", 0xe0a5, "3", "3", ROUTER_BOARD_NS5M, 0}, // |
|---|
| 1083 | {"Ubiquiti Loco M5", 0xe8a5, "3", "3", ROUTER_BOARD_NS5M, 0}, // |
|---|
| 1084 | {"Ubiquiti Loco M2", 0xe0a2, "3", "3", ROUTER_BOARD_NS5M, 0}, // |
|---|
| 1085 | // {"Ubiquiti Loco M2", 0xe8a2, "3", "3", ROUTER_BOARD_NS5M, 0}, // |
|---|
| 1086 | {"Ubiquiti Loco M900", 0xe009, "3", "3", ROUTER_BOARD_NS5M, M900}, // |
|---|
| 1087 | {"Ubiquiti NanoStation M900 Sector", 0xe0b9, "3", "3", ROUTER_BOARD_NS5M, M900}, // |
|---|
| 1088 | {"Ubiquiti LiteStation M25", 0xe115, "3", "3", ROUTER_BOARD_NS5M, 0}, // |
|---|
| 1089 | {"Ubiquiti PowerAP N", 0xe402, "3", "3", ROUTER_BOARD_NS2M, 0}, // |
|---|
| 1090 | {"Ubiquiti Simple AP", 0xe4a2, "3", "3", ROUTER_BOARD_R2M, 0}, // |
|---|
| 1091 | {"Ubiquiti PowerBridge M3", 0xe2a3, "3", "3", ROUTER_BOARD_R5M, M35}, // |
|---|
| 1092 | {"Ubiquiti PowerBridge M5", 0xe1a5, "3", "3", ROUTER_BOARD_R5M, 0}, // |
|---|
| 1093 | {"Ubiquiti PowerBridge M365", 0xe1a3, "3", "3", ROUTER_BOARD_R5M, M365}, // |
|---|
| 1094 | {"Ubiquiti PowerBridge M10", 0xe110, "3", "3", ROUTER_BOARD_R5M, M10}, // |
|---|
| 1095 | {"Ubiquiti NanoBridge M3", 0xe243, "3", "3", ROUTER_BOARD_BS5M, M35}, // |
|---|
| 1096 | {"Ubiquiti NanoBridge M365", 0xe233, "3", "3", ROUTER_BOARD_BS5M, M365}, // |
|---|
| 1097 | {"Ubiquiti NanoBridge M900", 0xe239, "3", "3", ROUTER_BOARD_BS5M, M900}, // |
|---|
| 1098 | {"Ubiquiti NanoBridge M5", 0xe235, "3", "3", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1099 | {"Ubiquiti NanoBridge M5", 0xe2b5, "3", "3", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1100 | {"Ubiquiti NanoBridge M2", 0xe232, "3", "3", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1101 | {"Ubiquiti 3G Station", 0xe6a2, "3", "3", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1102 | {"Ubiquiti 3G Station Professional", 0xe6b2, "3", "3", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1103 | {"Ubiquiti 3G Station Outdoor", 0xe6c2, "3", "3", ROUTER_BOARD_BS2M, 0}, // |
|---|
| 1104 | {"Ubiquiti WispStation M5", 0xe2a5, "3", "3", ROUTER_BOARD_BS5M, 0}, // |
|---|
| 1105 | {"Ubiquiti UniFi AP", 0xe502, "3", "3", ROUTER_BOARD_UNIFI, 0}, // |
|---|
| 1106 | {NULL, 0, NULL, NULL, 0}, // |
|---|
| 1107 | }; |
|---|
| 1108 | |
|---|
| 1109 | #undef M35 |
|---|
| 1110 | #undef M365 |
|---|
| 1111 | #undef M900 |
|---|
| 1112 | #undef M10 |
|---|
| 1113 | |
|---|
| 1114 | #if 0 |
|---|
| 1115 | FILE *fp = |
|---|
| 1116 | fopen("/sys/bus/pci/devices/0000:00:00.0/subsystem_device", "rb"); |
|---|
| 1117 | if (fp == NULL) |
|---|
| 1118 | return ROUTER_BOARD_PB42; |
|---|
| 1119 | int device; |
|---|
| 1120 | fscanf(fp, "0x%04X", &device); |
|---|
| 1121 | fclose(fp); |
|---|
| 1122 | #else |
|---|
| 1123 | FILE *fp = fopen("/dev/mtdblock5", "rb"); //open board config |
|---|
| 1124 | int device = 0; |
|---|
| 1125 | if (fp) { |
|---|
| 1126 | fseek(fp, 0x1006, SEEK_SET); |
|---|
| 1127 | unsigned short cal[128]; |
|---|
| 1128 | fread(&cal[0], 1, 256, fp); |
|---|
| 1129 | fclose(fp); |
|---|
| 1130 | int calcnt = 0; |
|---|
| 1131 | while (((cal[calcnt] & 0xffff) != 0xffff)) { |
|---|
| 1132 | unsigned short reg = cal[calcnt++] & 0xffff; |
|---|
| 1133 | if (reg == 0x602c || reg == 0x502c) { |
|---|
| 1134 | calcnt++; |
|---|
| 1135 | device = cal[calcnt++] & 0xffff; |
|---|
| 1136 | break; |
|---|
| 1137 | } else { |
|---|
| 1138 | calcnt += 2; |
|---|
| 1139 | } |
|---|
| 1140 | } |
|---|
| 1141 | } |
|---|
| 1142 | #endif |
|---|
| 1143 | int devcnt = 0; |
|---|
| 1144 | while (dev[devcnt].devicename != NULL) { |
|---|
| 1145 | if (dev[devcnt].devid == device) { |
|---|
| 1146 | nvram_default_get("ath0_rxantenna", |
|---|
| 1147 | dev[devcnt].rxchain); |
|---|
| 1148 | nvram_default_get("ath0_txantenna", |
|---|
| 1149 | dev[devcnt].txchain); |
|---|
| 1150 | if (dev[devcnt].offset) { |
|---|
| 1151 | char foff[32]; |
|---|
| 1152 | sprintf(foff, "%d", dev[devcnt].offset); |
|---|
| 1153 | nvram_set("ath0_offset", foff); |
|---|
| 1154 | } |
|---|
| 1155 | setRouter(dev[devcnt].devicename); |
|---|
| 1156 | return dev[devcnt].dddev; |
|---|
| 1157 | } |
|---|
| 1158 | devcnt++; |
|---|
| 1159 | } |
|---|
| 1160 | setRouter("Ubiquiti Unknown Model"); |
|---|
| 1161 | return ROUTER_BOARD_PB42; |
|---|
| 1162 | #elif HAVE_NS2 |
|---|
| 1163 | setRouter("Ubiquiti NanoStation 2"); |
|---|
| 1164 | return ROUTER_BOARD_LS2; |
|---|
| 1165 | #elif HAVE_EOC5510 |
|---|
| 1166 | setRouter("Senao EOC-5510"); |
|---|
| 1167 | return ROUTER_BOARD_LS2; |
|---|
| 1168 | #elif HAVE_EOC5611 |
|---|
| 1169 | setRouter("Senao EOC-5611"); |
|---|
| 1170 | return ROUTER_BOARD_LS2; |
|---|
| 1171 | #elif HAVE_EOC5610 |
|---|
| 1172 | setRouter("Senao EOC-5610"); |
|---|
| 1173 | return ROUTER_BOARD_LS2; |
|---|
| 1174 | #elif HAVE_NS5 |
|---|
| 1175 | setRouter("Ubiquiti NanoStation 5"); |
|---|
| 1176 | return ROUTER_BOARD_LS2; |
|---|
| 1177 | #elif HAVE_SOLO51 |
|---|
| 1178 | setRouter("Alfa SoLo48-N"); |
|---|
| 1179 | return ROUTER_BOARD_LS2; |
|---|
| 1180 | #elif HAVE_NS3 |
|---|
| 1181 | setRouter("Ubiquiti NanoStation 3"); |
|---|
| 1182 | return ROUTER_BOARD_LS2; |
|---|
| 1183 | #elif HAVE_BS5 |
|---|
| 1184 | setRouter("Ubiquiti Bullet 5"); |
|---|
| 1185 | return ROUTER_BOARD_LS2; |
|---|
| 1186 | #elif HAVE_BS2 |
|---|
| 1187 | setRouter("Ubiquiti Bullet 2"); |
|---|
| 1188 | return ROUTER_BOARD_LS2; |
|---|
| 1189 | #elif HAVE_PICO2 |
|---|
| 1190 | setRouter("Ubiquiti PicoStation 2"); |
|---|
| 1191 | return ROUTER_BOARD_LS2; |
|---|
| 1192 | #elif HAVE_PICO2HP |
|---|
| 1193 | setRouter("Ubiquiti PicoStation 2 HP"); |
|---|
| 1194 | return ROUTER_BOARD_LS2; |
|---|
| 1195 | #elif HAVE_PICO5 |
|---|
| 1196 | setRouter("Ubiquiti PicoStation 5"); |
|---|
| 1197 | return ROUTER_BOARD_LS2; |
|---|
| 1198 | #elif HAVE_MS2 |
|---|
| 1199 | setRouter("Ubiquiti MiniStation"); |
|---|
| 1200 | return ROUTER_BOARD_LS2; |
|---|
| 1201 | #elif HAVE_BS2HP |
|---|
| 1202 | setRouter("Ubiquiti Bullet 2 HP"); |
|---|
| 1203 | return ROUTER_BOARD_LS2; |
|---|
| 1204 | #elif HAVE_LC2 |
|---|
| 1205 | setRouter("Ubiquiti NanoStation 2 Loco"); |
|---|
| 1206 | return ROUTER_BOARD_LS2; |
|---|
| 1207 | #elif HAVE_LC5 |
|---|
| 1208 | setRouter("Ubiquiti NanoStation 5 Loco"); |
|---|
| 1209 | return ROUTER_BOARD_LS2; |
|---|
| 1210 | #elif HAVE_PS2 |
|---|
| 1211 | setRouter("Ubiquiti PowerStation 2"); |
|---|
| 1212 | return ROUTER_BOARD_LS2; |
|---|
| 1213 | #elif HAVE_PS5 |
|---|
| 1214 | setRouter("Ubiquiti PowerStation 5"); |
|---|
| 1215 | return ROUTER_BOARD_LS2; |
|---|
| 1216 | #elif HAVE_LS2 |
|---|
| 1217 | setRouter("Ubiquiti LiteStation 2"); |
|---|
| 1218 | return ROUTER_BOARD_LS2; |
|---|
| 1219 | #elif HAVE_LS5 |
|---|
| 1220 | setRouter("Ubiquiti LiteStation 5"); |
|---|
| 1221 | return ROUTER_BOARD_LS2; |
|---|
| 1222 | #elif HAVE_WHRAG108 |
|---|
| 1223 | setRouter("Buffalo WHR-HP-AG108"); |
|---|
| 1224 | return ROUTER_BOARD_WHRAG108; |
|---|
| 1225 | #elif HAVE_PB42 |
|---|
| 1226 | setRouter("Atheros PB42"); |
|---|
| 1227 | return ROUTER_BOARD_PB42; |
|---|
| 1228 | #elif HAVE_RSPRO |
|---|
| 1229 | setRouter("Ubiquiti RouterStation Pro"); |
|---|
| 1230 | return ROUTER_BOARD_PB42; |
|---|
| 1231 | #elif HAVE_RS |
|---|
| 1232 | #ifdef HAVE_DDLINK |
|---|
| 1233 | setRouter("ddlink1x1"); |
|---|
| 1234 | #else |
|---|
| 1235 | setRouter("Ubiquiti RouterStation"); |
|---|
| 1236 | #endif |
|---|
| 1237 | return ROUTER_BOARD_PB42; |
|---|
| 1238 | #elif HAVE_E2100 |
|---|
| 1239 | setRouter("Linksys E2100L"); |
|---|
| 1240 | return ROUTER_BOARD_PB42; |
|---|
| 1241 | #elif HAVE_WRT160NL |
|---|
| 1242 | setRouter("Linksys WRT160NL"); |
|---|
| 1243 | return ROUTER_BOARD_PB42; |
|---|
| 1244 | #elif HAVE_TG2521 |
|---|
| 1245 | setRouter("ZCom TG-2521"); |
|---|
| 1246 | return ROUTER_BOARD_PB42; |
|---|
| 1247 | #elif HAVE_WZRG300NH2 |
|---|
| 1248 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1249 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1250 | #ifdef HAVE_BUFFALO |
|---|
| 1251 | setRouter("WZR-HP-G300NH2"); |
|---|
| 1252 | #else |
|---|
| 1253 | setRouter("Buffalo WZR-HP-G300NH2"); |
|---|
| 1254 | #endif |
|---|
| 1255 | return ROUTER_BOARD_PB42; |
|---|
| 1256 | #elif HAVE_WZRG450 |
|---|
| 1257 | nvram_default_get("ath0_rxantenna", "7"); |
|---|
| 1258 | nvram_default_get("ath0_txantenna", "7"); |
|---|
| 1259 | #ifdef HAVE_BUFFALO |
|---|
| 1260 | setRouter("WZR-HP-G450H"); |
|---|
| 1261 | #else |
|---|
| 1262 | setRouter("Buffalo WZR-HP-G450H"); |
|---|
| 1263 | #endif |
|---|
| 1264 | return ROUTER_BOARD_PB42; |
|---|
| 1265 | #elif HAVE_WZRG300NH |
|---|
| 1266 | #ifdef HAVE_BUFFALO |
|---|
| 1267 | setRouter("WZR-HP-G300NH"); |
|---|
| 1268 | #else |
|---|
| 1269 | setRouter("Buffalo WZR-HP-G300NH"); |
|---|
| 1270 | #endif |
|---|
| 1271 | nvram_default_get("ath0_rxantenna", "7"); |
|---|
| 1272 | nvram_default_get("ath0_txantenna", "7"); |
|---|
| 1273 | return ROUTER_BOARD_PB42; |
|---|
| 1274 | #elif HAVE_WZRHPAG300NH |
|---|
| 1275 | #ifdef HAVE_BUFFALO |
|---|
| 1276 | setRouter("WZR-HP-AG300H"); |
|---|
| 1277 | #else |
|---|
| 1278 | setRouter("Buffalo WZR-HP-AG300H"); |
|---|
| 1279 | #endif |
|---|
| 1280 | return ROUTER_BOARD_PB42; |
|---|
| 1281 | #elif HAVE_DIR632 |
|---|
| 1282 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1283 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1284 | setRouter("Dlink-DIR-632A"); |
|---|
| 1285 | return ROUTER_BOARD_PB42; |
|---|
| 1286 | #elif HAVE_WNDR3700V2 |
|---|
| 1287 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1288 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1289 | nvram_default_get("ath1_rxantenna", "3"); |
|---|
| 1290 | nvram_default_get("ath1_txantenna", "3"); |
|---|
| 1291 | setRouter("Netgear WNDR3700 v2"); |
|---|
| 1292 | return ROUTER_BOARD_PB42; |
|---|
| 1293 | #elif HAVE_WNDR3700 |
|---|
| 1294 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1295 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1296 | nvram_default_get("ath1_rxantenna", "3"); |
|---|
| 1297 | nvram_default_get("ath1_txantenna", "3"); |
|---|
| 1298 | setRouter("Netgear WNDR3700"); |
|---|
| 1299 | return ROUTER_BOARD_PB42; |
|---|
| 1300 | #elif HAVE_DIR825 |
|---|
| 1301 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1302 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1303 | nvram_default_get("ath1_rxantenna", "3"); |
|---|
| 1304 | nvram_default_get("ath1_txantenna", "3"); |
|---|
| 1305 | setRouter("Dlink DIR-825"); |
|---|
| 1306 | return ROUTER_BOARD_PB42; |
|---|
| 1307 | #elif HAVE_TEW673GRU |
|---|
| 1308 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1309 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1310 | nvram_default_get("ath1_rxantenna", "3"); |
|---|
| 1311 | nvram_default_get("ath1_txantenna", "3"); |
|---|
| 1312 | setRouter("Trendnet TEW-673GRU"); |
|---|
| 1313 | return ROUTER_BOARD_PB42; |
|---|
| 1314 | #elif HAVE_WRT400 |
|---|
| 1315 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1316 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1317 | nvram_default_get("ath1_rxantenna", "3"); |
|---|
| 1318 | nvram_default_get("ath1_txantenna", "3"); |
|---|
| 1319 | setRouter("Linksys WRT400N"); |
|---|
| 1320 | return ROUTER_BOARD_PB42; |
|---|
| 1321 | #elif HAVE_DIR615C1 |
|---|
| 1322 | setRouter("D-Link DIR-615-C1"); |
|---|
| 1323 | return ROUTER_BOARD_PB42; |
|---|
| 1324 | #elif HAVE_DIR601A1 |
|---|
| 1325 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1326 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1327 | setRouter("D-Link DIR-601-A1"); |
|---|
| 1328 | return ROUTER_BOARD_PB42; |
|---|
| 1329 | #elif HAVE_DIR615E1 |
|---|
| 1330 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1331 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1332 | setRouter("D-Link DIR-615-E1"); |
|---|
| 1333 | return ROUTER_BOARD_PB42; |
|---|
| 1334 | #elif HAVE_DIR615E |
|---|
| 1335 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1336 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1337 | setRouter("D-Link DIR-615-E3/E4"); |
|---|
| 1338 | return ROUTER_BOARD_PB42; |
|---|
| 1339 | #elif HAVE_TEW652BRP |
|---|
| 1340 | setRouter("Trendnet TEW-652BRP"); |
|---|
| 1341 | return ROUTER_BOARD_PB42; |
|---|
| 1342 | #elif HAVE_TEW632BRP |
|---|
| 1343 | setRouter("Trendnet TEW-632BRP"); |
|---|
| 1344 | return ROUTER_BOARD_PB42; |
|---|
| 1345 | #elif HAVE_WR841v3 |
|---|
| 1346 | setRouter("TP-Link TL-WR841ND v3"); |
|---|
| 1347 | return ROUTER_BOARD_PB42; |
|---|
| 1348 | #elif HAVE_WR941 |
|---|
| 1349 | setRouter("TP-Link TL-WR941ND v2/v3"); |
|---|
| 1350 | return ROUTER_BOARD_PB42; |
|---|
| 1351 | #elif HAVE_WR841v5 |
|---|
| 1352 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1353 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1354 | setRouter("TP-Link TL-WR841ND v5"); |
|---|
| 1355 | return ROUTER_BOARD_PB42; |
|---|
| 1356 | #elif HAVE_WR840v1 |
|---|
| 1357 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1358 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1359 | setRouter("TP-Link TL-WR840N v1"); |
|---|
| 1360 | return ROUTER_BOARD_PB42; |
|---|
| 1361 | #elif HAVE_WR841v7 |
|---|
| 1362 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1363 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1364 | setRouter("TP-Link TL-WR841ND v7"); |
|---|
| 1365 | return ROUTER_BOARD_PB42; |
|---|
| 1366 | #elif HAVE_WR842 |
|---|
| 1367 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1368 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1369 | setRouter("TP-Link TL-WR842ND v1"); |
|---|
| 1370 | return ROUTER_BOARD_PB42; |
|---|
| 1371 | #elif HAVE_WR740v1 |
|---|
| 1372 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1373 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1374 | setRouter("TP-Link TL-WR740N"); |
|---|
| 1375 | return ROUTER_BOARD_PB42; |
|---|
| 1376 | #elif HAVE_WA901v1 |
|---|
| 1377 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1378 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1379 | setRouter("TP-Link TL-WA901ND v1"); |
|---|
| 1380 | return ROUTER_BOARD_PB42; |
|---|
| 1381 | #elif HAVE_WR941v4 |
|---|
| 1382 | setRouter("TP-Link TL-WR941ND v4"); |
|---|
| 1383 | return ROUTER_BOARD_PB42; |
|---|
| 1384 | #elif HAVE_WR743 |
|---|
| 1385 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1386 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1387 | setRouter("TP-Link TL-WR743ND v1"); |
|---|
| 1388 | return ROUTER_BOARD_PB42; |
|---|
| 1389 | #elif HAVE_WR703 |
|---|
| 1390 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1391 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1392 | setRouter("TP-Link TL-WR703N v1"); |
|---|
| 1393 | return ROUTER_BOARD_PB42; |
|---|
| 1394 | #elif HAVE_WR740V4 |
|---|
| 1395 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1396 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1397 | setRouter("TP-Link TL-WR740N v4"); |
|---|
| 1398 | return ROUTER_BOARD_PB42; |
|---|
| 1399 | #elif HAVE_WR741V4 |
|---|
| 1400 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1401 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1402 | setRouter("TP-Link TL-WR741ND v4"); |
|---|
| 1403 | return ROUTER_BOARD_PB42; |
|---|
| 1404 | #elif HAVE_WR741 |
|---|
| 1405 | nvram_default_get("ath0_rxantenna", "1"); |
|---|
| 1406 | nvram_default_get("ath0_txantenna", "1"); |
|---|
| 1407 | setRouter("TP-Link TL-WR741ND v1"); |
|---|
| 1408 | return ROUTER_BOARD_PB42; |
|---|
| 1409 | #elif HAVE_WR1043 |
|---|
| 1410 | nvram_default_get("ath0_rxantenna", "7"); |
|---|
| 1411 | nvram_default_get("ath0_txantenna", "7"); |
|---|
| 1412 | setRouter("TP-Link TL-WR1043ND"); |
|---|
| 1413 | return ROUTER_BOARD_PB42; |
|---|
| 1414 | #elif HAVE_AP83 |
|---|
| 1415 | setRouter("Atheros AP83"); |
|---|
| 1416 | return ROUTER_BOARD_PB42; |
|---|
| 1417 | #elif HAVE_WP543 |
|---|
| 1418 | setRouter("Compex WP543"); |
|---|
| 1419 | return ROUTER_BOARD_PB42; |
|---|
| 1420 | #elif HAVE_JA76PF |
|---|
| 1421 | setRouter("JJPLUS JA76PF"); |
|---|
| 1422 | return ROUTER_BOARD_PB42; |
|---|
| 1423 | #elif HAVE_JWAP003 |
|---|
| 1424 | setRouter("JJPLUS JWAP003"); |
|---|
| 1425 | return ROUTER_BOARD_PB42; |
|---|
| 1426 | #elif HAVE_ALFAAP94 |
|---|
| 1427 | setRouter("Alfa AP94 Board"); |
|---|
| 1428 | return ROUTER_BOARD_PB42; |
|---|
| 1429 | #elif HAVE_LSX |
|---|
| 1430 | setRouter("Ubiquiti LiteStation-SR71"); |
|---|
| 1431 | return ROUTER_BOARD_PB42; |
|---|
| 1432 | #elif HAVE_WMBR_G300NH |
|---|
| 1433 | setRouter("Buffalo WBMR-HP-G300H"); |
|---|
| 1434 | nvram_default_get("ath0_rxantenna", "3"); |
|---|
| 1435 | nvram_default_get("ath0_txantenna", "3"); |
|---|
| 1436 | return ROUTER_BOARD_DANUBE; |
|---|
| 1437 | #elif HAVE_VF802 |
|---|
| 1438 | setRouter("Vodafone Easybox 802"); |
|---|
| 1439 | return ROUTER_BOARD_DANUBE; |
|---|
| 1440 | #elif HAVE_VF803 |
|---|
| 1441 | setRouter("Vodafone Easybox 803"); |
|---|
| 1442 | return ROUTER_BOARD_DANUBE; |
|---|
| 1443 | #elif HAVE_SX763 |
|---|
| 1444 | setRouter("Gigaset SX763"); |
|---|
| 1445 | return ROUTER_BOARD_DANUBE; |
|---|
| 1446 | #elif HAVE_DANUBE |
|---|
| 1447 | setRouter("Infineon Danube"); |
|---|
| 1448 | return ROUTER_BOARD_DANUBE; |
|---|
| 1449 | #elif HAVE_WBD222 |
|---|
| 1450 | setRouter("Wiligear WBD-222"); |
|---|
| 1451 | return ROUTER_BOARD_STORM; |
|---|
| 1452 | #elif HAVE_STORM |
|---|
| 1453 | setRouter("Wiligear WBD-111"); |
|---|
| 1454 | return ROUTER_BOARD_STORM; |
|---|
| 1455 | #elif HAVE_OPENRISC |
|---|
| 1456 | setRouter("Alekto OpenRisc"); |
|---|
| 1457 | return ROUTER_BOARD_OPENRISC; |
|---|
| 1458 | #elif HAVE_TW6600 |
|---|
| 1459 | setRouter("AW-6660"); |
|---|
| 1460 | return ROUTER_BOARD_TW6600; |
|---|
| 1461 | #elif HAVE_ALPHA |
|---|
| 1462 | setRouter("Alfa Networks AP48"); |
|---|
| 1463 | return ROUTER_BOARD_CA8; |
|---|
| 1464 | #elif HAVE_USR5453 |
|---|
| 1465 | setRouter("US Robotics USR5453"); |
|---|
| 1466 | return ROUTER_BOARD_CA8; |
|---|
| 1467 | #elif HAVE_RDAT81 |
|---|
| 1468 | setRouter("Wistron RDAT-81"); |
|---|
| 1469 | return ROUTER_BOARD_RDAT81; |
|---|
| 1470 | #elif HAVE_RCAA01 |
|---|
| 1471 | setRouter("Airlive WLA-9000AP"); |
|---|
| 1472 | return ROUTER_BOARD_RCAA01; |
|---|
| 1473 | #elif HAVE_CA8PRO |
|---|
| 1474 | setRouter("Wistron CA8-4 PRO"); |
|---|
| 1475 | return ROUTER_BOARD_CA8PRO; |
|---|
| 1476 | #elif HAVE_CA8 |
|---|
| 1477 | #ifdef HAVE_WHA5500CPE |
|---|
| 1478 | setRouter("Airlive WHA-5500CPE"); |
|---|
| 1479 | #elif HAVE_AIRMAX5 |
|---|
| 1480 | setRouter("Airlive AirMax 5"); |
|---|
| 1481 | #else |
|---|
| 1482 | setRouter("Airlive WLA-5000AP"); |
|---|
| 1483 | #endif |
|---|
| 1484 | return ROUTER_BOARD_CA8; |
|---|
| 1485 | #else |
|---|
| 1486 | |
|---|
| 1487 | unsigned long boardnum = strtoul(nvram_safe_get("boardnum"), NULL, 0); |
|---|
| 1488 | unsigned long melco_id = strtoul(nvram_safe_get("melco_id"), NULL, 0); |
|---|
| 1489 | |
|---|
| 1490 | if (boardnum == 42 && nvram_match("boardtype", "bcm94710ap")) { |
|---|
| 1491 | setRouter("Buffalo WBR-G54 / WLA-G54"); |
|---|
| 1492 | return ROUTER_BUFFALO_WBR54G; |
|---|
| 1493 | } |
|---|
| 1494 | #ifndef HAVE_BUFFALO |
|---|
| 1495 | if (nvram_match("boardnum", "mn700") && |
|---|
| 1496 | nvram_match("boardtype", "bcm94710ap")) { |
|---|
| 1497 | setRouter("Microsoft MN-700"); |
|---|
| 1498 | return ROUTER_MICROSOFT_MN700; |
|---|
| 1499 | } |
|---|
| 1500 | |
|---|
| 1501 | if (nvram_match("boardnum", "asusX") && |
|---|
| 1502 | nvram_match("boardtype", "bcm94710dev")) { |
|---|
| 1503 | setRouter("Asus WL-300g / WL-500g"); |
|---|
| 1504 | return ROUTER_ASUS_WL500G; |
|---|
| 1505 | } |
|---|
| 1506 | |
|---|
| 1507 | if (boardnum == 44 && nvram_match("boardtype", "bcm94710ap")) { |
|---|
| 1508 | setRouter("Dell TrueMobile 2300"); |
|---|
| 1509 | return ROUTER_DELL_TRUEMOBILE_2300; |
|---|
| 1510 | } |
|---|
| 1511 | #endif |
|---|
| 1512 | |
|---|
| 1513 | if (boardnum == 100 && nvram_match("boardtype", "bcm94710dev")) { |
|---|
| 1514 | setRouter("Buffalo WLA-G54C"); |
|---|
| 1515 | return ROUTER_BUFFALO_WLAG54C; |
|---|
| 1516 | } |
|---|
| 1517 | #ifndef HAVE_BUFFALO |
|---|
| 1518 | if (boardnum == 45 && nvram_match("boardtype", "bcm95365r")) { |
|---|
| 1519 | setRouter("Asus WL-500g Deluxe"); |
|---|
| 1520 | return ROUTER_ASUS_WL500GD; |
|---|
| 1521 | } |
|---|
| 1522 | |
|---|
| 1523 | if (boardnum == 45 && nvram_match("boardtype", "0x0472") |
|---|
| 1524 | && nvram_match("boardrev", "0x23") && nvram_match("parkid", "1")) { |
|---|
| 1525 | setRouter("Asus WL-500W"); |
|---|
| 1526 | return ROUTER_ASUS_WL500W; |
|---|
| 1527 | } |
|---|
| 1528 | |
|---|
| 1529 | if (boardnum == 45 && nvram_match("boardtype", "0x467")) { |
|---|
| 1530 | char *hwver0 = nvram_safe_get("hardware_version"); |
|---|
| 1531 | |
|---|
| 1532 | if (startswith(hwver0, "WL320G")) { |
|---|
| 1533 | setRouter("Asus WL-320gE/gP"); |
|---|
| 1534 | return ROUTER_ASUS_WL550GE; |
|---|
| 1535 | } else { |
|---|
| 1536 | setRouter("Asus WL-550gE"); |
|---|
| 1537 | return ROUTER_ASUS_WL550GE; |
|---|
| 1538 | } |
|---|
| 1539 | } |
|---|
| 1540 | #ifdef HAVE_BCMMODERN |
|---|
| 1541 | if (boardnum == 45 && nvram_match("boardtype", "0x04EC") |
|---|
| 1542 | && nvram_match("boardrev", "0x1402")) { |
|---|
| 1543 | setRouter("Asus RT-N10"); |
|---|
| 1544 | return ROUTER_ASUS_RTN10; |
|---|
| 1545 | } |
|---|
| 1546 | |
|---|
| 1547 | if (boardnum == 45 && nvram_match("boardtype", "0x0550") |
|---|
| 1548 | && nvram_match("boardrev", "0x1102")) { |
|---|
| 1549 | setRouter("Asus RT-N10U"); |
|---|
| 1550 | return ROUTER_ASUS_RTN10U; |
|---|
| 1551 | } |
|---|
| 1552 | |
|---|
| 1553 | if (boardnum == 45 && nvram_match("boardtype", "0x0550") |
|---|
| 1554 | && nvram_match("boardrev", "0x1442")) { |
|---|
| 1555 | setRouter("Asus RT-N53"); |
|---|
| 1556 | return ROUTER_ASUS_RTN53; |
|---|
| 1557 | } |
|---|
| 1558 | |
|---|
| 1559 | if (boardnum == 0 && nvram_match("boardtype", "0xF5B2") |
|---|
| 1560 | && nvram_match("boardrev", "0x1100")) { |
|---|
| 1561 | setRouter("Asus RT-N66U"); |
|---|
| 1562 | return ROUTER_ASUS_RTN66; |
|---|
| 1563 | } |
|---|
| 1564 | |
|---|
| 1565 | if (nvram_match("boardnum", "1") && nvram_match("boardtype", "0x054d") |
|---|
| 1566 | && nvram_match("boardrev", "0x1109")) { |
|---|
| 1567 | setRouter("NetCore NW715P"); |
|---|
| 1568 | return ROUTER_NETCORE_NW715P; |
|---|
| 1569 | } |
|---|
| 1570 | |
|---|
| 1571 | if (boardnum == 45 && nvram_match("boardtype", "0x04CD") |
|---|
| 1572 | && nvram_match("boardrev", "0x1201")) { |
|---|
| 1573 | setRouter("Asus RT-N12"); |
|---|
| 1574 | return ROUTER_ASUS_RTN12; |
|---|
| 1575 | } |
|---|
| 1576 | |
|---|
| 1577 | if (boardnum == 45 && nvram_match("boardtype", "0x054D") |
|---|
| 1578 | && nvram_match("boardrev", "0x1101")) { |
|---|
| 1579 | char *hwrev = nvram_safe_get("hardware_version"); |
|---|
| 1580 | if (!strncmp(hwrev, "RTN12C1", 7)) |
|---|
| 1581 | setRouter("Asus RT-N12C1"); |
|---|
| 1582 | else |
|---|
| 1583 | setRouter("Asus RT-N12B"); |
|---|
| 1584 | return ROUTER_ASUS_RTN12B; |
|---|
| 1585 | } |
|---|
| 1586 | |
|---|
| 1587 | if (boardnum == 45 && nvram_match("boardtype", "0x04cf") |
|---|
| 1588 | && nvram_match("boardrev", "0x1218")) { |
|---|
| 1589 | setRouter("Asus RT-N16"); |
|---|
| 1590 | return ROUTER_ASUS_RTN16; |
|---|
| 1591 | } |
|---|
| 1592 | |
|---|
| 1593 | if (nvram_match("boardtype", "0xa4cf") |
|---|
| 1594 | && nvram_match("boardrev", "0x1100")) { |
|---|
| 1595 | setRouter("Belkin F5D8235-4 v3"); |
|---|
| 1596 | return ROUTER_BELKIN_F5D8235V3; |
|---|
| 1597 | } |
|---|
| 1598 | |
|---|
| 1599 | if (nvram_match("boardtype", "0xd4cf") |
|---|
| 1600 | && nvram_match("boardrev", "0x1204")) { |
|---|
| 1601 | setRouter("Belkin F7D4301 / F7D8301 v1"); |
|---|
| 1602 | return ROUTER_BELKIN_F7D4301; |
|---|
| 1603 | } |
|---|
| 1604 | |
|---|
| 1605 | if (nvram_match("boardtype", "0xa4cf") |
|---|
| 1606 | && nvram_match("boardrev", "0x1102")) { |
|---|
| 1607 | FILE *mtd1 = fopen("/dev/mtdblock/1", "rb"); |
|---|
| 1608 | unsigned long trxhd; |
|---|
| 1609 | if (mtd1) { |
|---|
| 1610 | fread(&trxhd, 4, 1, mtd1); |
|---|
| 1611 | fclose(mtd1); |
|---|
| 1612 | if (trxhd == TRX_MAGIC_F7D3301) { |
|---|
| 1613 | setRouter("Belkin F7D3301 / F7D7301 v1"); |
|---|
| 1614 | return ROUTER_BELKIN_F7D3301; |
|---|
| 1615 | } |
|---|
| 1616 | if (trxhd == TRX_MAGIC_F7D3302) { |
|---|
| 1617 | setRouter("Belkin F7D3302 / F7D7302 v1"); |
|---|
| 1618 | return ROUTER_BELKIN_F7D3302; |
|---|
| 1619 | } |
|---|
| 1620 | } |
|---|
| 1621 | setRouter("Belkin F7D4302 / F7D8302 v1"); |
|---|
| 1622 | return ROUTER_BELKIN_F7D4302; |
|---|
| 1623 | } |
|---|
| 1624 | #endif |
|---|
| 1625 | |
|---|
| 1626 | #endif |
|---|
| 1627 | if (nvram_match("boardnum", "00") && nvram_match("boardtype", "0x0101") |
|---|
| 1628 | && nvram_match("boardrev", "0x10")) { |
|---|
| 1629 | setRouter("Buffalo WBR2-G54 / WBR2-G54S"); |
|---|
| 1630 | return ROUTER_BUFFALO_WBR2G54S; |
|---|
| 1631 | } |
|---|
| 1632 | |
|---|
| 1633 | if (boardnum == 2 && nvram_match("boardtype", "0x0101") |
|---|
| 1634 | && nvram_match("boardrev", "0x10")) { |
|---|
| 1635 | setRouter("Buffalo WLA2-G54C / WLI3-TX1-G54"); |
|---|
| 1636 | return ROUTER_BUFFALO_WLA2G54C; |
|---|
| 1637 | } |
|---|
| 1638 | if (boardnum == 0 && melco_id == 29090 |
|---|
| 1639 | && nvram_match("boardrev", "0x10")) { |
|---|
| 1640 | setRouter("Buffalo WLAH-G54"); |
|---|
| 1641 | return ROUTER_BUFFALO_WLAH_G54; |
|---|
| 1642 | |
|---|
| 1643 | } |
|---|
| 1644 | if (boardnum == 0 && melco_id == 31070 |
|---|
| 1645 | && nvram_match("boardflags", "0x2288") |
|---|
| 1646 | && nvram_match("boardrev", "0x10")) { |
|---|
| 1647 | setRouter("Buffalo WAPM-HP-AM54G54"); |
|---|
| 1648 | return ROUTER_BUFFALO_WAPM_HP_AM54G54; |
|---|
| 1649 | } |
|---|
| 1650 | if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x11") |
|---|
| 1651 | && nvram_match("boardtype", "0x048e") && melco_id == 32093) { |
|---|
| 1652 | setRouter("Buffalo WHR-G125"); |
|---|
| 1653 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 1654 | } |
|---|
| 1655 | |
|---|
| 1656 | if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x10") |
|---|
| 1657 | && nvram_match("boardtype", "0x048e") && melco_id == 32139) { |
|---|
| 1658 | setRouter("Buffalo WCA-G"); |
|---|
| 1659 | return ROUTER_BUFFALO_WCAG; //vlan1 is lan, vlan0 is unused, implementation not done. will me made after return to germany |
|---|
| 1660 | } |
|---|
| 1661 | |
|---|
| 1662 | if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x11") |
|---|
| 1663 | && nvram_match("boardtype", "0x048e") && melco_id == 32064) { |
|---|
| 1664 | setRouter("Buffalo WHR-HP-G125"); |
|---|
| 1665 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 1666 | } |
|---|
| 1667 | |
|---|
| 1668 | if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x13") |
|---|
| 1669 | && nvram_match("boardtype", "0x467")) { |
|---|
| 1670 | if (nvram_match("boardflags", "0x1658") |
|---|
| 1671 | || nvram_match("boardflags", "0x2658") |
|---|
| 1672 | || nvram_match("boardflags", "0x3658")) { |
|---|
| 1673 | setRouter("Buffalo WLI-TX4-G54HP"); |
|---|
| 1674 | return ROUTER_BUFFALO_WLI_TX4_G54HP; |
|---|
| 1675 | } |
|---|
| 1676 | if (!nvram_match("buffalo_hp", "1") |
|---|
| 1677 | && nvram_match("boardflags", "0x2758")) { |
|---|
| 1678 | setRouter("Buffalo WHR-G54S"); |
|---|
| 1679 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 1680 | } |
|---|
| 1681 | if (nvram_match("buffalo_hp", "1") |
|---|
| 1682 | || nvram_match("boardflags", "0x1758")) { |
|---|
| 1683 | #ifndef HAVE_BUFFALO |
|---|
| 1684 | setRouter("Buffalo WHR-HP-G54"); |
|---|
| 1685 | #else |
|---|
| 1686 | #ifdef BUFFALO_JP |
|---|
| 1687 | setRouter("Buffalo AS-A100"); |
|---|
| 1688 | #else |
|---|
| 1689 | setRouter("Buffalo WHR-HP-G54DD"); |
|---|
| 1690 | #endif |
|---|
| 1691 | #endif |
|---|
| 1692 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 1693 | } |
|---|
| 1694 | } |
|---|
| 1695 | |
|---|
| 1696 | if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x10") |
|---|
| 1697 | && nvram_match("boardtype", "0x470")) { |
|---|
| 1698 | setRouter("Buffalo WHR-AM54G54"); |
|---|
| 1699 | return ROUTER_BUFFALO_WHRAM54G54; |
|---|
| 1700 | } |
|---|
| 1701 | |
|---|
| 1702 | if (boardnum == 42 && nvram_match("boardtype", "0x042f")) { |
|---|
| 1703 | |
|---|
| 1704 | if (nvram_match("product_name", "WZR-RS-G54") |
|---|
| 1705 | || melco_id == 30083) { |
|---|
| 1706 | setRouter("Buffalo WZR-RS-G54"); |
|---|
| 1707 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1708 | } |
|---|
| 1709 | if (nvram_match("product_name", "WZR-HP-G54") |
|---|
| 1710 | || melco_id == 30026) { |
|---|
| 1711 | setRouter("Buffalo WZR-HP-G54"); |
|---|
| 1712 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1713 | } |
|---|
| 1714 | if (nvram_match("product_name", "WZR-G54") || melco_id == 30061) { |
|---|
| 1715 | setRouter("Buffalo WZR-G54"); |
|---|
| 1716 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1717 | } |
|---|
| 1718 | if (nvram_match("melco_id", "290441dd")) { |
|---|
| 1719 | setRouter("Buffalo WHR2-A54G54"); |
|---|
| 1720 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1721 | } |
|---|
| 1722 | if (nvram_match("product_name", "WHR3-AG54") |
|---|
| 1723 | || nvram_match("product_name", "WHR3-B11") |
|---|
| 1724 | || melco_id == 29130) { |
|---|
| 1725 | setRouter("Buffalo WHR3-AG54"); |
|---|
| 1726 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1727 | } |
|---|
| 1728 | if (nvram_match("product_name", "WVR-G54-NF") |
|---|
| 1729 | || melco_id == 28100) { |
|---|
| 1730 | setRouter("Buffalo WVR-G54-NF"); |
|---|
| 1731 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1732 | } |
|---|
| 1733 | if (nvram_match("product_name", "WZR-G108") || melco_id == 31095 |
|---|
| 1734 | || melco_id == 30153) { |
|---|
| 1735 | setRouter("Buffalo WZR-G108"); |
|---|
| 1736 | return ROUTER_BRCM4702_GENERIC; |
|---|
| 1737 | } |
|---|
| 1738 | if (melco_id > 0) // e.g. 29115 |
|---|
| 1739 | { |
|---|
| 1740 | setRouter("Buffalo WZR series"); |
|---|
| 1741 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 1742 | } |
|---|
| 1743 | } |
|---|
| 1744 | #ifndef HAVE_BUFFALO |
|---|
| 1745 | if (boardnum == 42 && nvram_match("boardtype", "0x042f") |
|---|
| 1746 | && nvram_match("boardrev", "0x10")) |
|---|
| 1747 | // nvram_match ("boardflags","0x0018")) |
|---|
| 1748 | { |
|---|
| 1749 | setRouter("Linksys WRTSL54GS"); |
|---|
| 1750 | return ROUTER_WRTSL54GS; |
|---|
| 1751 | } |
|---|
| 1752 | |
|---|
| 1753 | if (boardnum == 42 && nvram_match("boardtype", "0x0101") |
|---|
| 1754 | && nvram_match("boardrev", "0x10") |
|---|
| 1755 | && nvram_match("boot_ver", "v3.6")) { |
|---|
| 1756 | setRouter("Linksys WRT54G3G"); |
|---|
| 1757 | return ROUTER_WRT54G3G; |
|---|
| 1758 | } |
|---|
| 1759 | |
|---|
| 1760 | if (nvram_match("boardtype", "0x042f") |
|---|
| 1761 | && nvram_match("boardrev", "0x10")) { |
|---|
| 1762 | char *hwver = nvram_safe_get("hardware_version"); |
|---|
| 1763 | |
|---|
| 1764 | if (boardnum == 45 || startswith(hwver, "WL500gp") |
|---|
| 1765 | || startswith(hwver, "WL500gH")) { |
|---|
| 1766 | setRouter("Asus WL-500g Premium"); |
|---|
| 1767 | return ROUTER_ASUS_WL500G_PRE; |
|---|
| 1768 | } |
|---|
| 1769 | if (boardnum == 44 || startswith(hwver, "WL700g")) { |
|---|
| 1770 | setRouter("Asus WL-700gE"); |
|---|
| 1771 | return ROUTER_ASUS_WL700GE; |
|---|
| 1772 | } |
|---|
| 1773 | } |
|---|
| 1774 | |
|---|
| 1775 | char *et0 = nvram_safe_get("et0macaddr"); |
|---|
| 1776 | |
|---|
| 1777 | if (boardnum == 100 && nvram_match("boardtype", "bcm94710r4")) { |
|---|
| 1778 | if (startswith(et0, "00:11:50")) { |
|---|
| 1779 | setRouter("Belkin F5D7130 / F5D7330"); |
|---|
| 1780 | return ROUTER_RT210W; |
|---|
| 1781 | } |
|---|
| 1782 | if (startswith(et0, "00:30:BD") || startswith(et0, "00:30:bd")) { |
|---|
| 1783 | setRouter("Belkin F5D7230-4 v1000"); |
|---|
| 1784 | return ROUTER_RT210W; |
|---|
| 1785 | } |
|---|
| 1786 | if (startswith(et0, "00:01:E3") || |
|---|
| 1787 | startswith(et0, "00:01:e3") || startswith(et0, "00:90:96")) |
|---|
| 1788 | { |
|---|
| 1789 | setRouter("Siemens SE505 v1"); |
|---|
| 1790 | return ROUTER_RT210W; |
|---|
| 1791 | } else { |
|---|
| 1792 | setRouter("Askey RT210W generic"); |
|---|
| 1793 | return ROUTER_RT210W; |
|---|
| 1794 | } |
|---|
| 1795 | } |
|---|
| 1796 | |
|---|
| 1797 | if (nvram_match("boardtype", "bcm94710r4") |
|---|
| 1798 | && nvram_match("boardnum", "")) { |
|---|
| 1799 | setRouter("Askey board RT2100W-D65)"); |
|---|
| 1800 | return ROUTER_BRCM4702_GENERIC; |
|---|
| 1801 | } |
|---|
| 1802 | |
|---|
| 1803 | if (boardnum == 0 && nvram_match("boardtype", "0x0100") |
|---|
| 1804 | && nvram_match("boardrev", "0x10")) { |
|---|
| 1805 | if (startswith(et0, "00:11:50") || |
|---|
| 1806 | startswith(et0, "00:30:BD") || startswith(et0, "00:30:bd")) |
|---|
| 1807 | { |
|---|
| 1808 | setRouter("Askey board RT2205(6)D-D56"); |
|---|
| 1809 | } else { |
|---|
| 1810 | setRouter("Belkin board F5D8230"); |
|---|
| 1811 | } |
|---|
| 1812 | return ROUTER_ASKEY_RT220XD; |
|---|
| 1813 | } |
|---|
| 1814 | |
|---|
| 1815 | if (nvram_match("boardtype", "0x0101")) { |
|---|
| 1816 | if (startswith(et0, "00:11:50") || |
|---|
| 1817 | startswith(et0, "00:30:BD") || startswith(et0, "00:30:bd")) |
|---|
| 1818 | { |
|---|
| 1819 | if (nvram_match("Belkin_ver", "2000")) { |
|---|
| 1820 | setRouter("Belkin F5D7230-4 v2000"); |
|---|
| 1821 | return ROUTER_BELKIN_F5D7230_V2000; |
|---|
| 1822 | } else { |
|---|
| 1823 | setRouter("Belkin F5D7230-4 v1444"); |
|---|
| 1824 | return ROUTER_RT480W; |
|---|
| 1825 | } |
|---|
| 1826 | } |
|---|
| 1827 | if (startswith(et0, "00:01:E3") || |
|---|
| 1828 | startswith(et0, "00:01:e3") || startswith(et0, "00:90:96")) |
|---|
| 1829 | { |
|---|
| 1830 | setRouter("Siemens SE505 v2"); |
|---|
| 1831 | return ROUTER_RT480W; |
|---|
| 1832 | } |
|---|
| 1833 | } |
|---|
| 1834 | if (boardnum == 1 && nvram_match("boardtype", "0x456") |
|---|
| 1835 | && nvram_match("test_led_gpio", "2")) { |
|---|
| 1836 | setRouter("Belkin F5D7230-4 v3000"); |
|---|
| 1837 | return ROUTER_BELKIN_F5D7230_V3000; |
|---|
| 1838 | } |
|---|
| 1839 | |
|---|
| 1840 | if (nvram_match("boardtype", "0x456") |
|---|
| 1841 | && nvram_match("hw_model", "F5D7231-4")) { |
|---|
| 1842 | setRouter("Belkin F5D7231-4 v1212UK"); |
|---|
| 1843 | return ROUTER_BELKIN_F5D7231; |
|---|
| 1844 | } |
|---|
| 1845 | |
|---|
| 1846 | if (boardnum == 8 && nvram_match("boardtype", "0x0467")) // fccid: |
|---|
| 1847 | // K7SF5D7231B |
|---|
| 1848 | { |
|---|
| 1849 | setRouter("Belkin F5D7231-4 v2000"); |
|---|
| 1850 | return ROUTER_BELKIN_F5D7231_V2000; |
|---|
| 1851 | } |
|---|
| 1852 | |
|---|
| 1853 | if (nvram_match("boardtype", "0x467")) { |
|---|
| 1854 | if (startswith(et0, "00:11:50") || |
|---|
| 1855 | startswith(et0, "00:30:BD") || startswith(et0, "00:30:bd")) |
|---|
| 1856 | { |
|---|
| 1857 | setRouter("Belkin F5D7231-4 v2000"); |
|---|
| 1858 | return ROUTER_BELKIN_F5D7231; |
|---|
| 1859 | } |
|---|
| 1860 | } |
|---|
| 1861 | #endif |
|---|
| 1862 | if (boardnum == 2 && nvram_match("boardtype", "bcm94710dev") && melco_id == 29016) // Buffalo |
|---|
| 1863 | // WLI2-TX1-G54) |
|---|
| 1864 | { |
|---|
| 1865 | setRouter("Buffalo WLI2-TX1-G54"); |
|---|
| 1866 | return ROUTER_BUFFALO_WLI2_TX1_G54; |
|---|
| 1867 | } |
|---|
| 1868 | #ifndef HAVE_BUFFALO |
|---|
| 1869 | |
|---|
| 1870 | char *gemtek = nvram_safe_get("GemtekPmonVer"); |
|---|
| 1871 | unsigned long gemteknum = strtoul(gemtek, NULL, 0); |
|---|
| 1872 | |
|---|
| 1873 | if (boardnum == 2 && (gemteknum == 10 || gemteknum == 11) && |
|---|
| 1874 | (startswith(et0, "00:0C:E5") || |
|---|
| 1875 | startswith(et0, "00:0c:e5") || |
|---|
| 1876 | startswith(et0, "00:11:22") || |
|---|
| 1877 | startswith(et0, "00:0C:10") || |
|---|
| 1878 | startswith(et0, "00:0c:10") || |
|---|
| 1879 | startswith(et0, "00:0C:11") || startswith(et0, "00:0c:11"))) { |
|---|
| 1880 | setRouter("Motorola WE800G v1"); |
|---|
| 1881 | return ROUTER_MOTOROLA_WE800G; |
|---|
| 1882 | } |
|---|
| 1883 | |
|---|
| 1884 | if (boardnum == 2 |
|---|
| 1885 | && (startswith(gemtek, "RC") || gemteknum == 1 || gemteknum == 10)) |
|---|
| 1886 | { |
|---|
| 1887 | setRouter("Linksys WAP54G v1.x"); |
|---|
| 1888 | return ROUTER_WAP54G_V1; |
|---|
| 1889 | } |
|---|
| 1890 | |
|---|
| 1891 | if (boardnum == 2 && gemteknum == 1) { |
|---|
| 1892 | setRouter("Sitecom WL-105(b)"); |
|---|
| 1893 | return ROUTER_SITECOM_WL105B; |
|---|
| 1894 | } |
|---|
| 1895 | |
|---|
| 1896 | if (boardnum == 2 && gemteknum == 7 |
|---|
| 1897 | && nvram_match("boardtype", "bcm94710dev")) { |
|---|
| 1898 | setRouter("Sitecom WL-111"); |
|---|
| 1899 | return ROUTER_SITECOM_WL111; |
|---|
| 1900 | } |
|---|
| 1901 | |
|---|
| 1902 | if (gemteknum == 9) // Must be Motorola wr850g v1 or we800g v1 or |
|---|
| 1903 | // Linksys wrt55ag v1 |
|---|
| 1904 | { |
|---|
| 1905 | if (startswith(et0, "00:0C:E5") || |
|---|
| 1906 | startswith(et0, "00:0c:e5") || |
|---|
| 1907 | startswith(et0, "00:0C:10") || |
|---|
| 1908 | startswith(et0, "00:0c:10") || |
|---|
| 1909 | startswith(et0, "00:0C:11") || |
|---|
| 1910 | startswith(et0, "00:0c:11") || |
|---|
| 1911 | startswith(et0, "00:11:22") || |
|---|
| 1912 | startswith(et0, "00:0C:90") || startswith(et0, "00:0c:90")) |
|---|
| 1913 | { |
|---|
| 1914 | if (!strlen(nvram_safe_get("phyid_num"))) { |
|---|
| 1915 | insmod("switch-core"); // get phy type |
|---|
| 1916 | insmod("switch-robo"); |
|---|
| 1917 | rmmod("switch-robo"); |
|---|
| 1918 | rmmod("switch-core"); |
|---|
| 1919 | nvram_set("boardnum", "2"); |
|---|
| 1920 | nvram_set("boardtype", "bcm94710dev"); |
|---|
| 1921 | } |
|---|
| 1922 | if (nvram_match("phyid_num", "0x00000000")) { |
|---|
| 1923 | setRouter("Motorola WE800G v1"); |
|---|
| 1924 | return ROUTER_MOTOROLA_WE800G; |
|---|
| 1925 | } else // phyid_num == 0xffffffff |
|---|
| 1926 | { |
|---|
| 1927 | setRouter("Motorola WR850G v1"); |
|---|
| 1928 | return ROUTER_MOTOROLA_V1; |
|---|
| 1929 | } |
|---|
| 1930 | } else { |
|---|
| 1931 | setRouter("Linksys WRT55AG v1"); |
|---|
| 1932 | return ROUTER_LINKSYS_WRT55AG; |
|---|
| 1933 | } |
|---|
| 1934 | } |
|---|
| 1935 | #endif |
|---|
| 1936 | if (boardnum == 0 && nvram_match("boardtype", "0x478") |
|---|
| 1937 | && nvram_match("cardbus", "0") && nvram_match("boardrev", "0x10") |
|---|
| 1938 | && nvram_match("boardflags", "0x110") && melco_id == 32027) { |
|---|
| 1939 | setRouter("Buffalo WZR-G144NH"); |
|---|
| 1940 | return ROUTER_BUFFALO_WZRG144NH; |
|---|
| 1941 | } |
|---|
| 1942 | |
|---|
| 1943 | if (boardnum == 20060330 && nvram_match("boardtype", "0x0472")) { |
|---|
| 1944 | setRouter("Buffalo WZR-G300N"); |
|---|
| 1945 | return ROUTER_BUFFALO_WZRG300N; |
|---|
| 1946 | } |
|---|
| 1947 | #ifndef HAVE_BUFFALO |
|---|
| 1948 | |
|---|
| 1949 | if (boardnum == 8 && nvram_match("boardtype", "0x0472") |
|---|
| 1950 | && nvram_match("cardbus", "1")) { |
|---|
| 1951 | setRouter("Netgear WNR834B"); |
|---|
| 1952 | return ROUTER_NETGEAR_WNR834B; |
|---|
| 1953 | } |
|---|
| 1954 | |
|---|
| 1955 | if (boardnum == 1 && nvram_match("boardtype", "0x0472") |
|---|
| 1956 | && nvram_match("boardrev", "0x23")) { |
|---|
| 1957 | if (nvram_match("cardbus", "1")) { |
|---|
| 1958 | setRouter("Netgear WNR834B v2"); |
|---|
| 1959 | return ROUTER_NETGEAR_WNR834BV2; |
|---|
| 1960 | } else { |
|---|
| 1961 | setRouter("Netgear WNDR3300"); |
|---|
| 1962 | return ROUTER_NETGEAR_WNDR3300; |
|---|
| 1963 | } |
|---|
| 1964 | } |
|---|
| 1965 | |
|---|
| 1966 | if (boardnum == 42) // Get Linksys N models |
|---|
| 1967 | { |
|---|
| 1968 | if (nvram_match("boot_hw_model", "WRT300N") |
|---|
| 1969 | && nvram_match("boot_hw_ver", "1.1")) { |
|---|
| 1970 | setRouter("Linksys WRT300N v1.1"); |
|---|
| 1971 | return ROUTER_WRT300NV11; |
|---|
| 1972 | } else if (nvram_match("boot_hw_model", "WRT150N") |
|---|
| 1973 | && nvram_match("boot_hw_ver", "1")) { |
|---|
| 1974 | setRouter("Linksys WRT150N v1"); |
|---|
| 1975 | return ROUTER_WRT150N; |
|---|
| 1976 | } else if (nvram_match("boot_hw_model", "WRT150N") |
|---|
| 1977 | && nvram_match("boot_hw_ver", "1.1")) { |
|---|
| 1978 | setRouter("Linksys WRT150N v1.1"); |
|---|
| 1979 | return ROUTER_WRT150N; |
|---|
| 1980 | } else if (nvram_match("boot_hw_model", "WRT150N") |
|---|
| 1981 | && nvram_match("boot_hw_ver", "1.2")) { |
|---|
| 1982 | setRouter("Linksys WRT150N v1.2"); |
|---|
| 1983 | return ROUTER_WRT150N; |
|---|
| 1984 | } else if (nvram_match("boot_hw_model", "WRT160N") |
|---|
| 1985 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 1986 | setRouter("Linksys WRT160N"); |
|---|
| 1987 | return ROUTER_WRT160N; |
|---|
| 1988 | } else if (nvram_match("boot_hw_model", "WRT160N") |
|---|
| 1989 | && nvram_match("boot_hw_ver", "3.0")) { |
|---|
| 1990 | setRouter("Linksys WRT160N v3"); |
|---|
| 1991 | return ROUTER_WRT160NV3; |
|---|
| 1992 | } else if (nvram_match("boot_hw_model", "M10") |
|---|
| 1993 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 1994 | setRouter("Cisco Valet M10 v1"); // renamed wrt160nv3 |
|---|
| 1995 | return ROUTER_WRT160NV3; |
|---|
| 1996 | } else if (nvram_match("boot_hw_model", "E100") |
|---|
| 1997 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 1998 | setRouter("Linksys E1000 v1"); // renamed wrt160nv3 |
|---|
| 1999 | return ROUTER_WRT160NV3; |
|---|
| 2000 | } else if (nvram_match("boot_hw_model", "E900") |
|---|
| 2001 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2002 | setRouter("Linksys E900"); |
|---|
| 2003 | return ROUTER_LINKSYS_E900; |
|---|
| 2004 | } else if (nvram_match("boot_hw_model", "E1000") |
|---|
| 2005 | && nvram_match("boot_hw_ver", "2.0")) { |
|---|
| 2006 | setRouter("Linksys E1000 v2"); |
|---|
| 2007 | return ROUTER_LINKSYS_E1000V2; |
|---|
| 2008 | } else if (nvram_match("boot_hw_model", "E1000") |
|---|
| 2009 | && nvram_match("boot_hw_ver", "2.1")) { |
|---|
| 2010 | setRouter("Linksys E1000 v2.1"); |
|---|
| 2011 | return ROUTER_LINKSYS_E1000V2; |
|---|
| 2012 | } else if (nvram_match("boot_hw_model", "E1200") |
|---|
| 2013 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2014 | setRouter("Linksys E1200 v1"); |
|---|
| 2015 | return ROUTER_LINKSYS_E1500; |
|---|
| 2016 | } else if (nvram_match("boot_hw_model", "E1200") |
|---|
| 2017 | && nvram_match("boot_hw_ver", "2.0")) { |
|---|
| 2018 | setRouter("Linksys E1200 v2"); |
|---|
| 2019 | return ROUTER_LINKSYS_E900; |
|---|
| 2020 | } else if (nvram_match("boot_hw_model", "E1500") |
|---|
| 2021 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2022 | setRouter("Linksys E1500"); |
|---|
| 2023 | return ROUTER_LINKSYS_E1500; |
|---|
| 2024 | } else if (nvram_match("boot_hw_model", "E1550") |
|---|
| 2025 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2026 | setRouter("Linksys E1550"); |
|---|
| 2027 | return ROUTER_LINKSYS_E1550; |
|---|
| 2028 | } else if (nvram_match("boot_hw_model", "WRT310N") |
|---|
| 2029 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2030 | setRouter("Linksys WRT310N"); |
|---|
| 2031 | return ROUTER_WRT310N; |
|---|
| 2032 | } else if (nvram_match("boot_hw_model", "WRT310N") |
|---|
| 2033 | && nvram_match("boot_hw_ver", "2.0")) { |
|---|
| 2034 | setRouter("Linksys WRT310N v2"); |
|---|
| 2035 | return ROUTER_WRT310NV2; |
|---|
| 2036 | } else if (nvram_match("boot_hw_model", "M20") |
|---|
| 2037 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2038 | setRouter("Cisco Valet Plus M20"); // ranamed wrt310nv2 |
|---|
| 2039 | return ROUTER_WRT310NV2; |
|---|
| 2040 | } else if (nvram_match("boot_hw_model", "E2500") |
|---|
| 2041 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2042 | setRouter("Linksys E2500"); |
|---|
| 2043 | return ROUTER_LINKSYS_E2500; |
|---|
| 2044 | } else if (nvram_match("boot_hw_model", "E3200") |
|---|
| 2045 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2046 | setRouter("Linksys E3200"); |
|---|
| 2047 | return ROUTER_LINKSYS_E3200; |
|---|
| 2048 | } else if (nvram_match("boot_hw_model", "E4200") |
|---|
| 2049 | && nvram_match("boot_hw_ver", "1.0")) { |
|---|
| 2050 | setRouter("Linksys E4200"); |
|---|
| 2051 | return ROUTER_LINKSYS_E4200; |
|---|
| 2052 | } |
|---|
| 2053 | } |
|---|
| 2054 | |
|---|
| 2055 | if (boardnum == 42 && nvram_match("boardtype", "0x0472") |
|---|
| 2056 | && nvram_match("cardbus", "1")) { |
|---|
| 2057 | setRouter("Linksys WRT300N v1"); |
|---|
| 2058 | return ROUTER_WRT300N; |
|---|
| 2059 | } |
|---|
| 2060 | |
|---|
| 2061 | if (boardnum == 42 && |
|---|
| 2062 | nvram_match("boardtype", "0x478") && nvram_match("cardbus", "1")) { |
|---|
| 2063 | setRouter("Linksys WRT350N"); |
|---|
| 2064 | return ROUTER_WRT350N; |
|---|
| 2065 | } |
|---|
| 2066 | |
|---|
| 2067 | if (nvram_match("boardnum", "20070615") && |
|---|
| 2068 | nvram_match("boardtype", "0x478") && nvram_match("cardbus", "0")) { |
|---|
| 2069 | if (nvram_match("switch_type", "BCM5395")) { |
|---|
| 2070 | setRouter("Linksys WRT600N v1.1"); |
|---|
| 2071 | return ROUTER_WRT600N; |
|---|
| 2072 | } else { |
|---|
| 2073 | setRouter("Linksys WRT600N"); |
|---|
| 2074 | return ROUTER_WRT600N; |
|---|
| 2075 | } |
|---|
| 2076 | } |
|---|
| 2077 | |
|---|
| 2078 | if (nvram_match("boardtype", "0x478") |
|---|
| 2079 | && nvram_match("boot_hw_model", "WRT610N")) { |
|---|
| 2080 | setRouter("Linksys WRT610N"); |
|---|
| 2081 | return ROUTER_WRT610N; |
|---|
| 2082 | } |
|---|
| 2083 | #ifdef HAVE_BCMMODERN |
|---|
| 2084 | if (nvram_match("boardtype", "0x04cf") |
|---|
| 2085 | && nvram_match("boot_hw_model", "WRT610N")) { |
|---|
| 2086 | setRouter("Linksys WRT610N v2"); |
|---|
| 2087 | return ROUTER_WRT610NV2; |
|---|
| 2088 | } |
|---|
| 2089 | |
|---|
| 2090 | if (nvram_match("boardtype", "0x04cf") |
|---|
| 2091 | && nvram_match("boot_hw_model", "E300")) { |
|---|
| 2092 | setRouter("Linksys E3000"); // renamed wrt610nv2 |
|---|
| 2093 | return ROUTER_WRT610NV2; |
|---|
| 2094 | } |
|---|
| 2095 | #endif |
|---|
| 2096 | |
|---|
| 2097 | if (boardnum == 42 && nvram_match("boardtype", "bcm94710dev")) { |
|---|
| 2098 | setRouter("Linksys WRT54G v1.x"); |
|---|
| 2099 | return ROUTER_WRT54G1X; |
|---|
| 2100 | } |
|---|
| 2101 | |
|---|
| 2102 | if ((boardnum == 1 || boardnum == 0) |
|---|
| 2103 | && nvram_match("boardtype", "0x0446")) { |
|---|
| 2104 | setRouter("U.S.Robotics USR5430"); |
|---|
| 2105 | return ROUTER_USR_5430; |
|---|
| 2106 | } |
|---|
| 2107 | |
|---|
| 2108 | if (boardnum == 1 && nvram_match("boardtype", "0x456") |
|---|
| 2109 | && nvram_match("test_led_gpio", "0")) { |
|---|
| 2110 | setRouter("Netgear WG602 v3"); |
|---|
| 2111 | return ROUTER_NETGEAR_WG602_V3; |
|---|
| 2112 | } |
|---|
| 2113 | |
|---|
| 2114 | if (boardnum == 10496 && nvram_match("boardtype", "0x456")) { |
|---|
| 2115 | setRouter("U.S.Robotics USR5461"); |
|---|
| 2116 | return ROUTER_USR_5461; |
|---|
| 2117 | } |
|---|
| 2118 | |
|---|
| 2119 | if (boardnum == 10500 && nvram_match("boardtype", "0x456")) { |
|---|
| 2120 | setRouter("U.S.Robotics USR5432"); |
|---|
| 2121 | return ROUTER_USR_5461; // should work in the same way |
|---|
| 2122 | } |
|---|
| 2123 | |
|---|
| 2124 | if (boardnum == 10506 && nvram_match("boardtype", "0x456")) { |
|---|
| 2125 | setRouter("U.S.Robotics USR5451"); |
|---|
| 2126 | return ROUTER_USR_5461; // should work in the same way |
|---|
| 2127 | } |
|---|
| 2128 | |
|---|
| 2129 | if (boardnum == 10512 && nvram_match("boardtype", "0x456")) { |
|---|
| 2130 | setRouter("U.S.Robotics USR5441"); |
|---|
| 2131 | return ROUTER_USR_5461; // should work in the same way |
|---|
| 2132 | } |
|---|
| 2133 | |
|---|
| 2134 | if ((boardnum == 35324 || boardnum == 38256) |
|---|
| 2135 | && nvram_match("boardtype", "0x048e")) { |
|---|
| 2136 | setRouter("U.S.Robotics USR5465"); |
|---|
| 2137 | return ROUTER_USR_5465; |
|---|
| 2138 | } |
|---|
| 2139 | |
|---|
| 2140 | if (boardnum == 35334 && nvram_match("boardtype", "0x048e")) { |
|---|
| 2141 | setRouter("U.S.Robotics USR5455"); |
|---|
| 2142 | return ROUTER_USR_5465; // should work in the same way |
|---|
| 2143 | } |
|---|
| 2144 | |
|---|
| 2145 | if (boardnum == 1024 && nvram_match("boardtype", "0x0446")) { |
|---|
| 2146 | char *cfe = nvram_safe_get("cfe_version"); |
|---|
| 2147 | |
|---|
| 2148 | if (strstr(cfe, "WRE54G")) { |
|---|
| 2149 | setRouter("Linksys WRE54G v1"); |
|---|
| 2150 | return ROUTER_WAP54G_V2; |
|---|
| 2151 | } else if (strstr(cfe, "iewsonic")) { |
|---|
| 2152 | setRouter("Viewsonic WAPBR-100"); |
|---|
| 2153 | return ROUTER_VIEWSONIC_WAPBR_100; |
|---|
| 2154 | } else { |
|---|
| 2155 | setRouter("Linksys WAP54G v2"); |
|---|
| 2156 | return ROUTER_WAP54G_V2; |
|---|
| 2157 | } |
|---|
| 2158 | } |
|---|
| 2159 | |
|---|
| 2160 | if (nvram_invmatch("CFEver", "")) { |
|---|
| 2161 | char *cfe = nvram_safe_get("CFEver"); |
|---|
| 2162 | |
|---|
| 2163 | if (!strncmp(cfe, "MotoWR", 6)) { |
|---|
| 2164 | setRouter("Motorola WR850G v2/v3"); |
|---|
| 2165 | return ROUTER_MOTOROLA; |
|---|
| 2166 | } |
|---|
| 2167 | } |
|---|
| 2168 | |
|---|
| 2169 | if (boardnum == 44 && (nvram_match("boardtype", "0x0101") |
|---|
| 2170 | || nvram_match("boardtype", "0x0101\r"))) { |
|---|
| 2171 | char *cfe = nvram_safe_get("CFEver"); |
|---|
| 2172 | |
|---|
| 2173 | if (!strncmp(cfe, "GW_WR110G", 9)) { |
|---|
| 2174 | setRouter("Sparklan WX-6615GT"); |
|---|
| 2175 | return ROUTER_DELL_TRUEMOBILE_2300_V2; |
|---|
| 2176 | } else { |
|---|
| 2177 | setRouter("Dell TrueMobile 2300 v2"); |
|---|
| 2178 | return ROUTER_DELL_TRUEMOBILE_2300_V2; |
|---|
| 2179 | } |
|---|
| 2180 | } |
|---|
| 2181 | #endif |
|---|
| 2182 | if (nvram_match("boardtype", "bcm94710ap")) { |
|---|
| 2183 | setRouter("Buffalo WBR-B11"); |
|---|
| 2184 | return ROUTER_BUFFALO_WBR54G; |
|---|
| 2185 | } |
|---|
| 2186 | if (boardnum == 00 && nvram_match("boardtype", "0xf52e") |
|---|
| 2187 | && nvram_match("boardrev", "0x1204")) { |
|---|
| 2188 | #ifdef HAVE_BUFFALO |
|---|
| 2189 | setRouter("WZR-D1800H"); // renamed (and fixed reset button) wrt320n |
|---|
| 2190 | #else |
|---|
| 2191 | setRouter("Buffalo WZR-D1800H"); // renamed (and fixed reset button) wrt320n |
|---|
| 2192 | #endif |
|---|
| 2193 | return ROUTER_D1800H; |
|---|
| 2194 | } |
|---|
| 2195 | #ifndef HAVE_BUFFALO |
|---|
| 2196 | if (boardnum == 0 && nvram_match("boardtype", "0x048e") && // cfe sets boardnum="", strtoul -> 0 |
|---|
| 2197 | nvram_match("boardrev", "0x35")) { |
|---|
| 2198 | setRouter("D-Link DIR-320"); |
|---|
| 2199 | // apply some fixes |
|---|
| 2200 | if (nvram_get("vlan2ports") != NULL) { |
|---|
| 2201 | nvram_unset("vlan2ports"); |
|---|
| 2202 | nvram_unset("vlan2hwname"); |
|---|
| 2203 | } |
|---|
| 2204 | return ROUTER_DLINK_DIR320; |
|---|
| 2205 | } |
|---|
| 2206 | if (nvram_match("model_name", "DIR-330") && |
|---|
| 2207 | nvram_match("boardrev", "0x10")) { |
|---|
| 2208 | setRouter("D-Link DIR-330"); |
|---|
| 2209 | nvram_set("wan_ifnames", "eth0"); // quirk |
|---|
| 2210 | nvram_set("wan_ifname", "eth0"); |
|---|
| 2211 | if (nvram_match("et0macaddr", "00:90:4c:4e:00:0c")) { |
|---|
| 2212 | FILE *in = fopen("/dev/mtdblock/1", "rb"); |
|---|
| 2213 | |
|---|
| 2214 | fseek(in, 0x7a0022, SEEK_SET); |
|---|
| 2215 | char mac[32]; |
|---|
| 2216 | |
|---|
| 2217 | fread(mac, 32, 1, in); |
|---|
| 2218 | fclose(in); |
|---|
| 2219 | mac[17] = 0; |
|---|
| 2220 | if (sv_valid_hwaddr(mac)) { |
|---|
| 2221 | nvram_set("et0macaddr", mac); |
|---|
| 2222 | fprintf(stderr, "restore D-Link MAC\n"); |
|---|
| 2223 | nvram_commit(); |
|---|
| 2224 | sys_reboot(); |
|---|
| 2225 | } |
|---|
| 2226 | } |
|---|
| 2227 | /* |
|---|
| 2228 | * if (nvram_get("vlan2ports")!=NULL) { nvram_unset("vlan2ports"); |
|---|
| 2229 | * nvram_unset("vlan2hwname"); } |
|---|
| 2230 | */ |
|---|
| 2231 | return ROUTER_DLINK_DIR330; |
|---|
| 2232 | } |
|---|
| 2233 | if (boardnum == 42 && nvram_match("boardtype", "0x048e") |
|---|
| 2234 | && nvram_match("boardrev", "0x10")) { |
|---|
| 2235 | if (nvram_match("boardflags", "0x20750")) { |
|---|
| 2236 | setRouter("Linksys WRT54G2 / GS2"); // router is wrt54g2v1/v1.3/gs2v1 |
|---|
| 2237 | } else { |
|---|
| 2238 | setRouter("Linksys WRT54Gv8 / GSv7"); |
|---|
| 2239 | } |
|---|
| 2240 | return ROUTER_WRT54G_V8; |
|---|
| 2241 | } |
|---|
| 2242 | |
|---|
| 2243 | if (boardnum == 8 && nvram_match("boardtype", "0x048e") |
|---|
| 2244 | && nvram_match("boardrev", "0x11")) { |
|---|
| 2245 | setRouter("ALLNET EUROWRT 54"); //ALLNET01 |
|---|
| 2246 | return ROUTER_ALLNET01; |
|---|
| 2247 | } |
|---|
| 2248 | |
|---|
| 2249 | if (boardnum == 01 && nvram_match("boardtype", "0x048e") |
|---|
| 2250 | && nvram_match("boardrev", "0x11") |
|---|
| 2251 | && (nvram_match("boardflags", "0x650") |
|---|
| 2252 | || nvram_match("boardflags", "0x0458"))) { |
|---|
| 2253 | setRouter("Netgear WG602 v4"); |
|---|
| 2254 | return ROUTER_NETGEAR_WG602_V4; |
|---|
| 2255 | } |
|---|
| 2256 | |
|---|
| 2257 | if (boardnum == 1 && nvram_match("boardtype", "0x048e") |
|---|
| 2258 | && nvram_match("boardrev", "0x35") |
|---|
| 2259 | && nvram_match("parefldovoltage", "0x28")) { |
|---|
| 2260 | setRouter("NetCore NW618 / Rosewill RNX-GX4"); |
|---|
| 2261 | return ROUTER_NETCORE_NW618; |
|---|
| 2262 | } |
|---|
| 2263 | |
|---|
| 2264 | if (boardnum == 42 && nvram_match("boardtype", "0x048E") |
|---|
| 2265 | && nvram_match("boardrev", "0x10")) { |
|---|
| 2266 | setRouter("Linksys WRH54G"); |
|---|
| 2267 | return ROUTER_LINKSYS_WRH54G; |
|---|
| 2268 | } |
|---|
| 2269 | |
|---|
| 2270 | if (nvram_match("boardnum", "00") && nvram_match("boardtype", "0x048E") |
|---|
| 2271 | && nvram_match("boardrev", "0x10")) { |
|---|
| 2272 | setRouter("Linksys WRT54G v8.1"); |
|---|
| 2273 | return ROUTER_WRT54G_V81; |
|---|
| 2274 | } |
|---|
| 2275 | |
|---|
| 2276 | if (boardnum == 45 && nvram_match("boardtype", "0x456")) { |
|---|
| 2277 | setRouter("Asus WL-520G"); |
|---|
| 2278 | return ROUTER_ASUS_WL520G; |
|---|
| 2279 | } |
|---|
| 2280 | |
|---|
| 2281 | if (nvram_match("boardtype", "0x48E") |
|---|
| 2282 | && nvram_match("boardrev", "0x10")) { |
|---|
| 2283 | char *hwver = nvram_safe_get("hardware_version"); |
|---|
| 2284 | |
|---|
| 2285 | if (boardnum == 45 && startswith(hwver, "WL500GPV2")) { |
|---|
| 2286 | setRouter("Asus WL-500G Premium v2"); |
|---|
| 2287 | return ROUTER_ASUS_WL500G_PRE_V2; |
|---|
| 2288 | } else if (boardnum == 45 && startswith(hwver, "WL330GE")) { |
|---|
| 2289 | setRouter("Asus WL-330GE"); |
|---|
| 2290 | return ROUTER_ASUS_330GE; |
|---|
| 2291 | } else if (boardnum == 45 || startswith(hwver, "WL500GU") |
|---|
| 2292 | || startswith(hwver, "WL500GC")) { |
|---|
| 2293 | setRouter("Asus WL-520GU/GC"); |
|---|
| 2294 | return ROUTER_ASUS_WL520GUGC; |
|---|
| 2295 | } |
|---|
| 2296 | } |
|---|
| 2297 | |
|---|
| 2298 | if ((boardnum == 83258 || boardnum == 1 || boardnum == 0123) //or 01 or 001 or 0x01 |
|---|
| 2299 | && (nvram_match("boardtype", "0x048e") || nvram_match("boardtype", "0x48E")) && (nvram_match("boardrev", "0x11") || nvram_match("boardrev", "0x10")) && (nvram_match("boardflags", "0x750") || nvram_match("boardflags", "0x0750")) && nvram_match("sdram_init", "0x000A")) //16 MB ram |
|---|
| 2300 | { |
|---|
| 2301 | setRouter("Netgear WGR614v8/L/WW"); |
|---|
| 2302 | return ROUTER_NETGEAR_WGR614L; |
|---|
| 2303 | } |
|---|
| 2304 | |
|---|
| 2305 | if (boardnum == 3805 && nvram_match("boardtype", "0x48E") |
|---|
| 2306 | && nvram_match("boardrev", "0x10")) { |
|---|
| 2307 | setRouter("Netgear WGR614v9"); |
|---|
| 2308 | return ROUTER_NETGEAR_WGR614V9; |
|---|
| 2309 | } |
|---|
| 2310 | |
|---|
| 2311 | if (boardnum == 56 && nvram_match("boardtype", "0x456") |
|---|
| 2312 | && nvram_match("boardrev", "0x10")) { |
|---|
| 2313 | setRouter("Linksys WTR54GS"); |
|---|
| 2314 | return ROUTER_LINKSYS_WTR54GS; |
|---|
| 2315 | } |
|---|
| 2316 | |
|---|
| 2317 | if (nvram_match("boardnum", "WAP54GV3_8M_0614") |
|---|
| 2318 | && (nvram_match("boardtype", "0x0467") |
|---|
| 2319 | || nvram_match("boardtype", "0x467")) |
|---|
| 2320 | && nvram_match("WAPver", "3")) { |
|---|
| 2321 | setRouter("Linksys WAP54G v3.x"); |
|---|
| 2322 | return ROUTER_WAP54G_V3; |
|---|
| 2323 | } |
|---|
| 2324 | #ifdef HAVE_BCMMODERN |
|---|
| 2325 | if (boardnum == 1 && nvram_match("boardtype", "0xE4CD") |
|---|
| 2326 | && nvram_match("boardrev", "0x1700")) { |
|---|
| 2327 | setRouter("Netgear WNR2000 v2"); |
|---|
| 2328 | return ROUTER_NETGEAR_WNR2000V2; |
|---|
| 2329 | } |
|---|
| 2330 | |
|---|
| 2331 | if ((boardnum == 1 || boardnum == 3500) |
|---|
| 2332 | && nvram_match("boardtype", "0x04CF") |
|---|
| 2333 | && (nvram_match("boardrev", "0x1213") |
|---|
| 2334 | || nvram_match("boardrev", "02"))) { |
|---|
| 2335 | setRouter("Netgear WNR3500v2/U/L"); |
|---|
| 2336 | return ROUTER_NETGEAR_WNR3500L; |
|---|
| 2337 | } |
|---|
| 2338 | |
|---|
| 2339 | if (nvram_match("boardnum", "01") && nvram_match("boardtype", "0xb4cf") |
|---|
| 2340 | && nvram_match("boardrev", "0x1100")) { |
|---|
| 2341 | setRouter("Netgear WNDR3400"); |
|---|
| 2342 | return ROUTER_NETGEAR_WNDR3400; |
|---|
| 2343 | } |
|---|
| 2344 | |
|---|
| 2345 | if (nvram_match("boardnum", "01") && nvram_match("boardtype", "0xF52C") |
|---|
| 2346 | && nvram_match("boardrev", "0x1101")) { |
|---|
| 2347 | setRouter("Netgear WNDR4000"); |
|---|
| 2348 | return ROUTER_NETGEAR_WNDR4000; |
|---|
| 2349 | } |
|---|
| 2350 | |
|---|
| 2351 | if (nvram_match("boardnum", "4536") |
|---|
| 2352 | && nvram_match("boardtype", "0xf52e") |
|---|
| 2353 | && nvram_match("boardrev", "0x1102")) { |
|---|
| 2354 | setRouter("Netgear WNDR4500"); |
|---|
| 2355 | return ROUTER_NETGEAR_WNDR4500; |
|---|
| 2356 | } |
|---|
| 2357 | |
|---|
| 2358 | if ((boardnum == 42 || boardnum == 66) |
|---|
| 2359 | && nvram_match("boardtype", "0x04EF") |
|---|
| 2360 | && (nvram_match("boardrev", "0x1304") |
|---|
| 2361 | || nvram_match("boardrev", "0x1305"))) { |
|---|
| 2362 | setRouter("Linksys WRT320N"); |
|---|
| 2363 | return ROUTER_WRT320N; |
|---|
| 2364 | } |
|---|
| 2365 | |
|---|
| 2366 | if (boardnum == 42 && nvram_match("boardtype", "0x04EF") |
|---|
| 2367 | && nvram_match("boardrev", "0x1307")) { |
|---|
| 2368 | setRouter("Linksys E2000"); // renamed (and fixed reset button) wrt320n |
|---|
| 2369 | return ROUTER_WRT320N; |
|---|
| 2370 | } |
|---|
| 2371 | |
|---|
| 2372 | #endif |
|---|
| 2373 | |
|---|
| 2374 | if (boardnum == 94703 && nvram_match("boardtype", "0x04c0") |
|---|
| 2375 | && nvram_match("boardrev", "0x1100")) { |
|---|
| 2376 | setRouter("Dynex DX-NRUTER"); |
|---|
| 2377 | return ROUTER_DYNEX_DX_NRUTER; |
|---|
| 2378 | } |
|---|
| 2379 | |
|---|
| 2380 | setRouter("Linksys WRT54G/GL/GS"); |
|---|
| 2381 | return ROUTER_WRT54G; |
|---|
| 2382 | #else |
|---|
| 2383 | eval("event", "3", "1", "15"); |
|---|
| 2384 | return 0; |
|---|
| 2385 | #endif |
|---|
| 2386 | #endif |
|---|
| 2387 | #endif |
|---|
| 2388 | } |
|---|
| 2389 | |
|---|
| 2390 | static int router_type = -1; |
|---|
| 2391 | int getRouterBrand() |
|---|
| 2392 | { |
|---|
| 2393 | if (router_type == -1) |
|---|
| 2394 | router_type = internal_getRouterBrand(); |
|---|
| 2395 | return router_type; |
|---|
| 2396 | } |
|---|
| 2397 | |
|---|
| 2398 | int get_ppp_pid(char *file) |
|---|
| 2399 | { |
|---|
| 2400 | char buf[80]; |
|---|
| 2401 | int pid = -1; |
|---|
| 2402 | |
|---|
| 2403 | if (file_to_buf(file, buf, sizeof(buf))) { |
|---|
| 2404 | char tmp[80], tmp1[80]; |
|---|
| 2405 | |
|---|
| 2406 | snprintf(tmp, sizeof(tmp), "/var/run/%s.pid", buf); |
|---|
| 2407 | file_to_buf(tmp, tmp1, sizeof(tmp1)); |
|---|
| 2408 | pid = atoi(tmp1); |
|---|
| 2409 | } |
|---|
| 2410 | return pid; |
|---|
| 2411 | } |
|---|
| 2412 | |
|---|
| 2413 | int check_wan_link(int num) |
|---|
| 2414 | { |
|---|
| 2415 | int wan_link = 0; |
|---|
| 2416 | |
|---|
| 2417 | if ((nvram_match("wan_proto", "pptp") |
|---|
| 2418 | #ifdef HAVE_L2TP |
|---|
| 2419 | || nvram_match("wan_proto", "l2tp") |
|---|
| 2420 | #endif |
|---|
| 2421 | #ifdef HAVE_PPPOE |
|---|
| 2422 | || nvram_match("wan_proto", "pppoe") |
|---|
| 2423 | #endif |
|---|
| 2424 | #ifdef HAVE_PPPOA |
|---|
| 2425 | || nvram_match("wan_proto", "pppoa") |
|---|
| 2426 | #endif |
|---|
| 2427 | #ifdef HAVE_3G |
|---|
| 2428 | || nvram_match("wan_proto", "3g") |
|---|
| 2429 | #endif |
|---|
| 2430 | || nvram_match("wan_proto", "heartbeat")) |
|---|
| 2431 | && !nvram_match("3gdata", "hso")) { |
|---|
| 2432 | FILE *fp; |
|---|
| 2433 | char filename[80]; |
|---|
| 2434 | char *name; |
|---|
| 2435 | |
|---|
| 2436 | if (num == 0) |
|---|
| 2437 | strcpy(filename, "/tmp/ppp/link"); |
|---|
| 2438 | if ((fp = fopen(filename, "r"))) { |
|---|
| 2439 | int pid = -1; |
|---|
| 2440 | |
|---|
| 2441 | fclose(fp); |
|---|
| 2442 | if (nvram_match("wan_proto", "heartbeat")) { |
|---|
| 2443 | char buf[20]; |
|---|
| 2444 | |
|---|
| 2445 | file_to_buf("/tmp/ppp/link", buf, sizeof(buf)); |
|---|
| 2446 | pid = atoi(buf); |
|---|
| 2447 | } else |
|---|
| 2448 | pid = get_ppp_pid(filename); |
|---|
| 2449 | |
|---|
| 2450 | name = find_name_by_proc(pid); |
|---|
| 2451 | if (!strncmp(name, "pppoecd", 7) || // for PPPoE |
|---|
| 2452 | !strncmp(name, "pppd", 4) || // for PPTP |
|---|
| 2453 | !strncmp(name, "bpalogin", 8)) // for HeartBeat |
|---|
| 2454 | wan_link = 1; // connect |
|---|
| 2455 | else { |
|---|
| 2456 | printf("The %s had been died, remove %s\n", |
|---|
| 2457 | nvram_safe_get("wan_proto"), filename); |
|---|
| 2458 | wan_link = 0; // For some reason, the pppoed had been died, |
|---|
| 2459 | // by link file still exist. |
|---|
| 2460 | unlink(filename); |
|---|
| 2461 | } |
|---|
| 2462 | } |
|---|
| 2463 | } else { |
|---|
| 2464 | if (nvram_invmatch("wan_ipaddr", "0.0.0.0")) |
|---|
| 2465 | wan_link = 1; |
|---|
| 2466 | } |
|---|
| 2467 | |
|---|
| 2468 | return wan_link; |
|---|
| 2469 | } |
|---|
| 2470 | |
|---|
| 2471 | #if defined(HAVE_BUFFALO) || defined(HAVE_BUFFALO_BL_DEFAULTS) || defined(HAVE_WMBR_G300NH) |
|---|
| 2472 | void *getUEnv(char *name) |
|---|
| 2473 | { |
|---|
| 2474 | #ifdef HAVE_WZRG300NH |
|---|
| 2475 | #define UOFFSET 0x40000 |
|---|
| 2476 | #elif HAVE_WZRHPAG300NH |
|---|
| 2477 | #define UOFFSET 0x40000 |
|---|
| 2478 | #elif HAVE_WZRG450 |
|---|
| 2479 | #define UOFFSET 0x40000 |
|---|
| 2480 | #elif HAVE_WMBR_G300NH |
|---|
| 2481 | #define UOFFSET 0x0 |
|---|
| 2482 | #else |
|---|
| 2483 | #define UOFFSET 0x3E000 |
|---|
| 2484 | #endif |
|---|
| 2485 | // static char res[64]; |
|---|
| 2486 | static char res[256]; |
|---|
| 2487 | memset(res, 0, sizeof(res)); |
|---|
| 2488 | //fprintf(stderr,"[u-boot env]%s\n",name); |
|---|
| 2489 | #ifdef HAVE_WMBR_G300NH |
|---|
| 2490 | FILE *fp = fopen("/dev/mtdblock/1", "rb"); |
|---|
| 2491 | #else |
|---|
| 2492 | FILE *fp = fopen("/dev/mtdblock/0", "rb"); |
|---|
| 2493 | #endif |
|---|
| 2494 | fseek(fp, UOFFSET, SEEK_SET); |
|---|
| 2495 | char *mem = safe_malloc(0x2000); |
|---|
| 2496 | fread(mem, 0x2000, 1, fp); |
|---|
| 2497 | fclose(fp); |
|---|
| 2498 | int s = (0x2000 - 1) - strlen(name); |
|---|
| 2499 | int i; |
|---|
| 2500 | int l = strlen(name); |
|---|
| 2501 | for (i = 0; i < s; i++) { |
|---|
| 2502 | if (!strncmp(mem + i, name, l)) { |
|---|
| 2503 | strncpy(res, mem + i + l + 1, sizeof(res) - 1); |
|---|
| 2504 | free(mem); |
|---|
| 2505 | return res; |
|---|
| 2506 | } |
|---|
| 2507 | } |
|---|
| 2508 | free(mem); |
|---|
| 2509 | return NULL; |
|---|
| 2510 | } |
|---|
| 2511 | #endif |
|---|
| 2512 | |
|---|
| 2513 | char *get_wan_ipaddr(void) |
|---|
| 2514 | { |
|---|
| 2515 | char *wan_ipaddr; |
|---|
| 2516 | char *wan_proto = nvram_safe_get("wan_proto"); |
|---|
| 2517 | int wan_link = check_wan_link(0); |
|---|
| 2518 | |
|---|
| 2519 | if (!strcmp(wan_proto, "pptp")) { |
|---|
| 2520 | wan_ipaddr = |
|---|
| 2521 | wan_link ? nvram_safe_get("pptp_get_ip") : |
|---|
| 2522 | nvram_safe_get("wan_ipaddr"); |
|---|
| 2523 | } else if (!strcmp(wan_proto, "pppoe") |
|---|
| 2524 | #ifdef HAVE_PPPOATM |
|---|
| 2525 | || !strcmp(wan_proto, "pppoa") |
|---|
| 2526 | #endif |
|---|
| 2527 | #ifdef HAVE_3G |
|---|
| 2528 | || !strcmp(wan_proto, "3g") |
|---|
| 2529 | #endif |
|---|
| 2530 | ) { |
|---|
| 2531 | wan_ipaddr = |
|---|
| 2532 | wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; |
|---|
| 2533 | #ifdef HAVE_L2TP |
|---|
| 2534 | } else if (!strcmp(wan_proto, "l2tp")) { |
|---|
| 2535 | wan_ipaddr = |
|---|
| 2536 | wan_link ? nvram_safe_get("l2tp_get_ip") : |
|---|
| 2537 | nvram_safe_get("wan_ipaddr"); |
|---|
| 2538 | #endif |
|---|
| 2539 | } else { |
|---|
| 2540 | wan_ipaddr = nvram_safe_get("wan_ipaddr"); |
|---|
| 2541 | } |
|---|
| 2542 | return wan_ipaddr; |
|---|
| 2543 | } |
|---|
| 2544 | |
|---|
| 2545 | /* |
|---|
| 2546 | * Find process name by pid from /proc directory |
|---|
| 2547 | */ |
|---|
| 2548 | char *find_name_by_proc(int pid) |
|---|
| 2549 | { |
|---|
| 2550 | FILE *fp; |
|---|
| 2551 | char line[254]; |
|---|
| 2552 | char filename[80]; |
|---|
| 2553 | static char name[80]; |
|---|
| 2554 | |
|---|
| 2555 | snprintf(filename, sizeof(filename), "/proc/%d/status", pid); |
|---|
| 2556 | |
|---|
| 2557 | if ((fp = fopen(filename, "r"))) { |
|---|
| 2558 | fgets(line, sizeof(line), fp); |
|---|
| 2559 | /* |
|---|
| 2560 | * Buffer should contain a string like "Name: binary_name" |
|---|
| 2561 | */ |
|---|
| 2562 | sscanf(line, "%*s %s", name); |
|---|
| 2563 | fclose(fp); |
|---|
| 2564 | return name; |
|---|
| 2565 | } |
|---|
| 2566 | |
|---|
| 2567 | return ""; |
|---|
| 2568 | } |
|---|
| 2569 | |
|---|
| 2570 | int diag_led_4702(int type, int act) |
|---|
| 2571 | { |
|---|
| 2572 | |
|---|
| 2573 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_LAGUNA) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA) || defined(HAVE_MERAKI) || defined(HAVE_LS2) || defined(HAVE_WHRAG108) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_FONERA) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_OPENRISC) |
|---|
| 2574 | return 0; |
|---|
| 2575 | #else |
|---|
| 2576 | if (act == START_LED) { |
|---|
| 2577 | switch (type) { |
|---|
| 2578 | case DMZ: |
|---|
| 2579 | writeproc("/proc/sys/diag","1"); |
|---|
| 2580 | break; |
|---|
| 2581 | } |
|---|
| 2582 | } else { |
|---|
| 2583 | switch (type) { |
|---|
| 2584 | case DMZ: |
|---|
| 2585 | writeproc("/proc/sys/diag","0"); |
|---|
| 2586 | break; |
|---|
| 2587 | } |
|---|
| 2588 | } |
|---|
| 2589 | return 0; |
|---|
| 2590 | #endif |
|---|
| 2591 | } |
|---|
| 2592 | |
|---|
| 2593 | int C_led_4702(int i) |
|---|
| 2594 | { |
|---|
| 2595 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_LAGUNA) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA) || defined(HAVE_MERAKI) || defined(HAVE_LS2) || defined(HAVE_WHRAG108) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_OPENRISC) |
|---|
| 2596 | return 0; |
|---|
| 2597 | #else |
|---|
| 2598 | FILE *fp; |
|---|
| 2599 | char string[10]; |
|---|
| 2600 | int flg; |
|---|
| 2601 | |
|---|
| 2602 | memset(string, 0, 10); |
|---|
| 2603 | /* |
|---|
| 2604 | * get diag before set |
|---|
| 2605 | */ |
|---|
| 2606 | if ((fp = fopen("/proc/sys/diag", "r"))) { |
|---|
| 2607 | fgets(string, sizeof(string), fp); |
|---|
| 2608 | fclose(fp); |
|---|
| 2609 | } else |
|---|
| 2610 | perror("/proc/sys/diag"); |
|---|
| 2611 | |
|---|
| 2612 | if (i) |
|---|
| 2613 | flg = atoi(string) | 0x10; |
|---|
| 2614 | else |
|---|
| 2615 | flg = atoi(string) & 0xef; |
|---|
| 2616 | |
|---|
| 2617 | memset(string, 0, 10); |
|---|
| 2618 | sprintf(string, "%d", flg); |
|---|
| 2619 | writeproc("/proc/sys/diag",string); |
|---|
| 2620 | |
|---|
| 2621 | return 0; |
|---|
| 2622 | #endif |
|---|
| 2623 | } |
|---|
| 2624 | |
|---|
| 2625 | unsigned int read_gpio(char *device) |
|---|
| 2626 | { |
|---|
| 2627 | FILE *fp; |
|---|
| 2628 | unsigned int val; |
|---|
| 2629 | |
|---|
| 2630 | if ((fp = fopen(device, "r"))) { |
|---|
| 2631 | fread(&val, 4, 1, fp); |
|---|
| 2632 | fclose(fp); |
|---|
| 2633 | // fprintf(stderr, "----- gpio %s = [%X]\n",device,val); |
|---|
| 2634 | return val; |
|---|
| 2635 | } else { |
|---|
| 2636 | perror(device); |
|---|
| 2637 | return 0; |
|---|
| 2638 | } |
|---|
| 2639 | } |
|---|
| 2640 | |
|---|
| 2641 | unsigned int write_gpio(char *device, unsigned int val) |
|---|
| 2642 | { |
|---|
| 2643 | FILE *fp; |
|---|
| 2644 | |
|---|
| 2645 | if ((fp = fopen(device, "w"))) { |
|---|
| 2646 | fwrite(&val, 4, 1, fp); |
|---|
| 2647 | fclose(fp); |
|---|
| 2648 | // fprintf(stderr, "----- set gpio %s = [%X]\n",device,val); |
|---|
| 2649 | return 1; |
|---|
| 2650 | } else { |
|---|
| 2651 | perror(device); |
|---|
| 2652 | return 0; |
|---|
| 2653 | } |
|---|
| 2654 | } |
|---|
| 2655 | |
|---|
| 2656 | static char hw_error = 0; |
|---|
| 2657 | int diag_led_4704(int type, int act) |
|---|
| 2658 | { |
|---|
| 2659 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_LAGUNA) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA) || defined(HAVE_MERAKI)|| defined(HAVE_LS2) || defined(HAVE_WHRAG108) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_OPENRISC) |
|---|
| 2660 | return 0; |
|---|
| 2661 | #else |
|---|
| 2662 | unsigned int control, in, outen, out; |
|---|
| 2663 | |
|---|
| 2664 | #ifdef BCM94712AGR |
|---|
| 2665 | /* |
|---|
| 2666 | * The router will crash, if we load the code into broadcom demo board. |
|---|
| 2667 | */ |
|---|
| 2668 | return 1; |
|---|
| 2669 | #endif |
|---|
| 2670 | // int brand; |
|---|
| 2671 | control = read_gpio("/dev/gpio/control"); |
|---|
| 2672 | in = read_gpio("/dev/gpio/in"); |
|---|
| 2673 | out = read_gpio("/dev/gpio/out"); |
|---|
| 2674 | outen = read_gpio("/dev/gpio/outen"); |
|---|
| 2675 | |
|---|
| 2676 | write_gpio("/dev/gpio/outen", (outen & 0x7c) | 0x83); |
|---|
| 2677 | switch (type) { |
|---|
| 2678 | case DIAG: // GPIO 1 |
|---|
| 2679 | if (hw_error) { |
|---|
| 2680 | write_gpio("/dev/gpio/out", (out & 0x7c) | 0x00); |
|---|
| 2681 | return 1; |
|---|
| 2682 | } |
|---|
| 2683 | |
|---|
| 2684 | if (act == STOP_LED) { // stop blinking |
|---|
| 2685 | write_gpio("/dev/gpio/out", (out & 0x7c) | 0x83); |
|---|
| 2686 | // cprintf("tallest:=====( DIAG STOP_LED !!)=====\n"); |
|---|
| 2687 | } else if (act == START_LED) { // start blinking |
|---|
| 2688 | write_gpio("/dev/gpio/out", (out & 0x7c) | 0x81); |
|---|
| 2689 | // cprintf("tallest:=====( DIAG START_LED !!)=====\n"); |
|---|
| 2690 | } else if (act == MALFUNCTION_LED) { // start blinking |
|---|
| 2691 | write_gpio("/dev/gpio/out", (out & 0x7c) | 0x00); |
|---|
| 2692 | hw_error = 1; |
|---|
| 2693 | // cprintf("tallest:=====( DIAG MALFUNCTION_LED !!)=====\n"); |
|---|
| 2694 | } |
|---|
| 2695 | break; |
|---|
| 2696 | |
|---|
| 2697 | } |
|---|
| 2698 | return 1; |
|---|
| 2699 | #endif |
|---|
| 2700 | } |
|---|
| 2701 | |
|---|
| 2702 | int diag_led_4712(int type, int act) |
|---|
| 2703 | { |
|---|
| 2704 | unsigned int control, in, outen, out, ctr_mask, out_mask; |
|---|
| 2705 | |
|---|
| 2706 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_LAGUNA) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA)|| defined(HAVE_MERAKI) || defined(HAVE_LS2) || defined(HAVE_WHRAG108) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_OPENRISC) |
|---|
| 2707 | return 0; |
|---|
| 2708 | #else |
|---|
| 2709 | |
|---|
| 2710 | #ifdef BCM94712AGR |
|---|
| 2711 | /* |
|---|
| 2712 | * The router will crash, if we load the code into broadcom demo board. |
|---|
| 2713 | */ |
|---|
| 2714 | return 1; |
|---|
| 2715 | #endif |
|---|
| 2716 | control = read_gpio("/dev/gpio/control"); |
|---|
| 2717 | in = read_gpio("/dev/gpio/in"); |
|---|
| 2718 | out = read_gpio("/dev/gpio/out"); |
|---|
| 2719 | outen = read_gpio("/dev/gpio/outen"); |
|---|
| 2720 | |
|---|
| 2721 | ctr_mask = ~(1 << type); |
|---|
| 2722 | out_mask = (1 << type); |
|---|
| 2723 | |
|---|
| 2724 | write_gpio("/dev/gpio/control", control & ctr_mask); |
|---|
| 2725 | write_gpio("/dev/gpio/outen", outen | out_mask); |
|---|
| 2726 | |
|---|
| 2727 | if (act == STOP_LED) { // stop blinking |
|---|
| 2728 | // cprintf("%s: Stop GPIO %d\n", __FUNCTION__, type); |
|---|
| 2729 | write_gpio("/dev/gpio/out", out | out_mask); |
|---|
| 2730 | } else if (act == START_LED) { // start blinking |
|---|
| 2731 | // cprintf("%s: Start GPIO %d\n", __FUNCTION__, type); |
|---|
| 2732 | write_gpio("/dev/gpio/out", out & ctr_mask); |
|---|
| 2733 | } |
|---|
| 2734 | |
|---|
| 2735 | return 1; |
|---|
| 2736 | #endif |
|---|
| 2737 | } |
|---|
| 2738 | |
|---|
| 2739 | int C_led_4712(int i) |
|---|
| 2740 | { |
|---|
| 2741 | if (i == 1) |
|---|
| 2742 | return diag_led(DIAG, START_LED); |
|---|
| 2743 | else |
|---|
| 2744 | return diag_led(DIAG, STOP_LED); |
|---|
| 2745 | } |
|---|
| 2746 | |
|---|
| 2747 | int C_led(int i) |
|---|
| 2748 | { |
|---|
| 2749 | int brand = getRouterBrand(); |
|---|
| 2750 | |
|---|
| 2751 | if (brand == ROUTER_WRT54G1X || brand == ROUTER_LINKSYS_WRT55AG) |
|---|
| 2752 | return C_led_4702(i); |
|---|
| 2753 | else if (brand == ROUTER_WRT54G) |
|---|
| 2754 | return C_led_4712(i); |
|---|
| 2755 | else |
|---|
| 2756 | return 0; |
|---|
| 2757 | } |
|---|
| 2758 | |
|---|
| 2759 | int diag_led(int type, int act) |
|---|
| 2760 | { |
|---|
| 2761 | int brand = getRouterBrand(); |
|---|
| 2762 | |
|---|
| 2763 | if (brand == ROUTER_WRT54G || brand == ROUTER_WRT54G3G |
|---|
| 2764 | || brand == ROUTER_WRT300NV11) |
|---|
| 2765 | return diag_led_4712(type, act); |
|---|
| 2766 | else if (brand == ROUTER_WRT54G1X || brand == ROUTER_LINKSYS_WRT55AG) |
|---|
| 2767 | return diag_led_4702(type, act); |
|---|
| 2768 | else if ((brand == ROUTER_WRTSL54GS |
|---|
| 2769 | || brand == ROUTER_WRT310N || brand == ROUTER_WRT350N |
|---|
| 2770 | || brand == ROUTER_BUFFALO_WZRG144NH) && type == DIAG) |
|---|
| 2771 | return diag_led_4704(type, act); |
|---|
| 2772 | else { |
|---|
| 2773 | if (type == DMZ) { |
|---|
| 2774 | if (act == START_LED) |
|---|
| 2775 | return led_control(LED_DMZ, LED_ON); |
|---|
| 2776 | if (act == STOP_LED) |
|---|
| 2777 | return led_control(LED_DMZ, LED_OFF); |
|---|
| 2778 | return 1; |
|---|
| 2779 | } |
|---|
| 2780 | } |
|---|
| 2781 | return 0; |
|---|
| 2782 | } |
|---|
| 2783 | |
|---|
| 2784 | #ifdef HAVE_MADWIFI |
|---|
| 2785 | static char *stalist[] = { |
|---|
| 2786 | "ath0", "ath1", "ath2", "ath3", "ath4", "ath5", "ath6", "ath8", "ath9" |
|---|
| 2787 | }; |
|---|
| 2788 | |
|---|
| 2789 | char *getWifi(char *ifname) |
|---|
| 2790 | { |
|---|
| 2791 | if (!strncmp(ifname, "ath0", 4)) |
|---|
| 2792 | return "wifi0"; |
|---|
| 2793 | if (!strncmp(ifname, "ath1", 4)) |
|---|
| 2794 | return "wifi1"; |
|---|
| 2795 | if (!strncmp(ifname, "ath2", 4)) |
|---|
| 2796 | return "wifi2"; |
|---|
| 2797 | if (!strncmp(ifname, "ath3", 4)) |
|---|
| 2798 | return "wifi3"; |
|---|
| 2799 | return NULL; |
|---|
| 2800 | } |
|---|
| 2801 | |
|---|
| 2802 | char *getWDSSTA(void) |
|---|
| 2803 | { |
|---|
| 2804 | |
|---|
| 2805 | int c = getdevicecount(); |
|---|
| 2806 | int i; |
|---|
| 2807 | |
|---|
| 2808 | for (i = 0; i < c; i++) { |
|---|
| 2809 | char mode[32]; |
|---|
| 2810 | char netmode[32]; |
|---|
| 2811 | |
|---|
| 2812 | sprintf(mode, "ath%d_mode", i); |
|---|
| 2813 | sprintf(netmode, "ath%d_net_mode", i); |
|---|
| 2814 | if (nvram_match(mode, "wdssta") |
|---|
| 2815 | && !nvram_match(netmode, "disabled")) { |
|---|
| 2816 | return stalist[i]; |
|---|
| 2817 | } |
|---|
| 2818 | |
|---|
| 2819 | } |
|---|
| 2820 | return NULL; |
|---|
| 2821 | } |
|---|
| 2822 | |
|---|
| 2823 | char *getSTA(void) |
|---|
| 2824 | { |
|---|
| 2825 | |
|---|
| 2826 | #ifdef HAVE_WAVESAT |
|---|
| 2827 | if (nvram_match("ofdm_mode", "sta")) |
|---|
| 2828 | return "ofdm"; |
|---|
| 2829 | #endif |
|---|
| 2830 | int c = getdevicecount(); |
|---|
| 2831 | int i; |
|---|
| 2832 | |
|---|
| 2833 | for (i = 0; i < c; i++) { |
|---|
| 2834 | if (nvram_nmatch("sta", "ath%d_mode", i) |
|---|
| 2835 | && !nvram_nmatch("disabled", "ath%d_net_mode", i)) { |
|---|
| 2836 | return stalist[i]; |
|---|
| 2837 | } |
|---|
| 2838 | |
|---|
| 2839 | } |
|---|
| 2840 | return NULL; |
|---|
| 2841 | } |
|---|
| 2842 | |
|---|
| 2843 | char *getWET(void) |
|---|
| 2844 | { |
|---|
| 2845 | #ifdef HAVE_WAVESAT |
|---|
| 2846 | if (nvram_match("ofdm_mode", "bridge")) |
|---|
| 2847 | return "ofdm"; |
|---|
| 2848 | #endif |
|---|
| 2849 | int c = getdevicecount(); |
|---|
| 2850 | int i; |
|---|
| 2851 | |
|---|
| 2852 | for (i = 0; i < c; i++) { |
|---|
| 2853 | if (nvram_nmatch("wet", "ath%d_mode", i) |
|---|
| 2854 | && !nvram_nmatch("disabled", "ath%d_net_mode", i)) { |
|---|
| 2855 | return stalist[i]; |
|---|
| 2856 | } |
|---|
| 2857 | |
|---|
| 2858 | } |
|---|
| 2859 | return NULL; |
|---|
| 2860 | } |
|---|
| 2861 | |
|---|
| 2862 | #elif defined(HAVE_RT2880) || defined(HAVE_RT61) |
|---|
| 2863 | |
|---|
| 2864 | char *getSTA() |
|---|
| 2865 | { |
|---|
| 2866 | int c = get_wl_instances(); |
|---|
| 2867 | int i; |
|---|
| 2868 | |
|---|
| 2869 | for (i = 0; i < c; i++) { |
|---|
| 2870 | if (nvram_nmatch("sta", "wl%d_mode", i)) { |
|---|
| 2871 | if (!nvram_nmatch("disabled", "wl%d_net_mode", i)) |
|---|
| 2872 | return "ra0"; |
|---|
| 2873 | } |
|---|
| 2874 | |
|---|
| 2875 | if (nvram_nmatch("apsta", "wl%d_mode", i)) { |
|---|
| 2876 | if (!nvram_nmatch("disabled", "wl%d_net_mode", i)) |
|---|
| 2877 | return "apcli0"; |
|---|
| 2878 | } |
|---|
| 2879 | |
|---|
| 2880 | } |
|---|
| 2881 | return NULL; |
|---|
| 2882 | } |
|---|
| 2883 | |
|---|
| 2884 | char *getWET() |
|---|
| 2885 | { |
|---|
| 2886 | int c = get_wl_instances(); |
|---|
| 2887 | int i; |
|---|
| 2888 | |
|---|
| 2889 | for (i = 0; i < c; i++) { |
|---|
| 2890 | if (!nvram_nmatch("disabled", "wl%d_net_mode", i) |
|---|
| 2891 | && nvram_nmatch("wet", "wl%d_mode", i)) |
|---|
| 2892 | return "ra0"; |
|---|
| 2893 | |
|---|
| 2894 | if (!nvram_nmatch("disabled", "wl%d_net_mode", i) |
|---|
| 2895 | && nvram_nmatch("apstawet", "wl%d_mode", i)) |
|---|
| 2896 | return "apcli0"; |
|---|
| 2897 | |
|---|
| 2898 | } |
|---|
| 2899 | return NULL; |
|---|
| 2900 | } |
|---|
| 2901 | |
|---|
| 2902 | #else |
|---|
| 2903 | char *getSTA() |
|---|
| 2904 | { |
|---|
| 2905 | int c = get_wl_instances(); |
|---|
| 2906 | int i; |
|---|
| 2907 | |
|---|
| 2908 | for (i = 0; i < c; i++) { |
|---|
| 2909 | if (nvram_nmatch("sta", "wl%d_mode", i) |
|---|
| 2910 | || nvram_nmatch("apsta", "wl%d_mode", i)) { |
|---|
| 2911 | if (!nvram_nmatch("disabled", "wl%d_net_mode", i)) |
|---|
| 2912 | return get_wl_instance_name(i); |
|---|
| 2913 | // else |
|---|
| 2914 | // return nvram_nget ("wl%d_ifname", i); |
|---|
| 2915 | } |
|---|
| 2916 | |
|---|
| 2917 | } |
|---|
| 2918 | return NULL; |
|---|
| 2919 | } |
|---|
| 2920 | |
|---|
| 2921 | char *getWET() |
|---|
| 2922 | { |
|---|
| 2923 | int c = get_wl_instances(); |
|---|
| 2924 | int i; |
|---|
| 2925 | |
|---|
| 2926 | for (i = 0; i < c; i++) { |
|---|
| 2927 | if (nvram_nmatch("wet", "wl%d_mode", i) |
|---|
| 2928 | || nvram_nmatch("apstawet", "wl%d_mode", i)) { |
|---|
| 2929 | if (!nvram_nmatch("disabled", "wl%d_net_mode", i)) |
|---|
| 2930 | return get_wl_instance_name(i); |
|---|
| 2931 | // else |
|---|
| 2932 | // return nvram_nget ("wl%d_ifname", i); |
|---|
| 2933 | |
|---|
| 2934 | } |
|---|
| 2935 | |
|---|
| 2936 | } |
|---|
| 2937 | return NULL; |
|---|
| 2938 | } |
|---|
| 2939 | |
|---|
| 2940 | #endif |
|---|
| 2941 | // note - broadcast addr returned in ipaddr |
|---|
| 2942 | void get_broadcast(char *ipaddr, char *netmask) |
|---|
| 2943 | { |
|---|
| 2944 | int ip2[4], mask2[4]; |
|---|
| 2945 | unsigned char ip[4], mask[4]; |
|---|
| 2946 | |
|---|
| 2947 | if (!ipaddr || !netmask) |
|---|
| 2948 | return; |
|---|
| 2949 | |
|---|
| 2950 | sscanf(ipaddr, "%d.%d.%d.%d", &ip2[0], &ip2[1], &ip2[2], &ip2[3]); |
|---|
| 2951 | sscanf(netmask, "%d.%d.%d.%d", &mask2[0], &mask2[1], &mask2[2], |
|---|
| 2952 | &mask2[3]); |
|---|
| 2953 | int i = 0; |
|---|
| 2954 | |
|---|
| 2955 | for (i = 0; i < 4; i++) { |
|---|
| 2956 | ip[i] = ip2[i]; |
|---|
| 2957 | mask[i] = mask2[i]; |
|---|
| 2958 | // ip[i] = (ip[i] & mask[i]) | !mask[i]; |
|---|
| 2959 | ip[i] = (ip[i] & mask[i]) | (0xff & ~mask[i]); |
|---|
| 2960 | } |
|---|
| 2961 | |
|---|
| 2962 | sprintf(ipaddr, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
|---|
| 2963 | #ifdef WDS_DEBUG |
|---|
| 2964 | fprintf(fp, "get_broadcast return %s\n", value); |
|---|
| 2965 | #endif |
|---|
| 2966 | |
|---|
| 2967 | } |
|---|
| 2968 | |
|---|
| 2969 | char *get_wan_face(void) |
|---|
| 2970 | { |
|---|
| 2971 | static char localwanface[IFNAMSIZ]; |
|---|
| 2972 | if (nvram_match("wan_proto", "disabled")) |
|---|
| 2973 | return "br0"; |
|---|
| 2974 | |
|---|
| 2975 | /* |
|---|
| 2976 | * if (nvram_match ("pptpd_client_enable", "1")) { strncpy (localwanface, |
|---|
| 2977 | * "ppp0", IFNAMSIZ); return localwanface; } |
|---|
| 2978 | */ |
|---|
| 2979 | if (nvram_match("wan_proto", "pptp") |
|---|
| 2980 | #ifdef HAVE_L2TP |
|---|
| 2981 | || nvram_match("wan_proto", "l2tp") |
|---|
| 2982 | #endif |
|---|
| 2983 | #ifdef HAVE_3G |
|---|
| 2984 | || nvram_match("wan_proto", "3g") |
|---|
| 2985 | #endif |
|---|
| 2986 | #ifdef HAVE_PPPOATM |
|---|
| 2987 | || nvram_match("wan_proto", "pppoa") |
|---|
| 2988 | #endif |
|---|
| 2989 | || nvram_match("wan_proto", "pppoe")) { |
|---|
| 2990 | if (nvram_match("pppd_pppifname", "")) |
|---|
| 2991 | strncpy(localwanface, "ppp0", IFNAMSIZ); |
|---|
| 2992 | else |
|---|
| 2993 | strncpy(localwanface, nvram_safe_get("pppd_pppifname"), |
|---|
| 2994 | IFNAMSIZ); |
|---|
| 2995 | } |
|---|
| 2996 | #ifndef HAVE_MADWIFI |
|---|
| 2997 | else if (getSTA()) { |
|---|
| 2998 | strcpy(localwanface, getSTA()); |
|---|
| 2999 | } |
|---|
| 3000 | #else |
|---|
| 3001 | else if (getSTA()) { |
|---|
| 3002 | if (nvram_match("wifi_bonding", "1")) |
|---|
| 3003 | strcpy(localwanface, "bond0"); |
|---|
| 3004 | else |
|---|
| 3005 | strcpy(localwanface, getSTA()); |
|---|
| 3006 | } |
|---|
| 3007 | #endif |
|---|
| 3008 | #ifdef HAVE_IPETH |
|---|
| 3009 | else if (nvram_match("wan_proto", "iphone")) { |
|---|
| 3010 | strncpy(localwanface, "iph0",IFNAMSIZ); |
|---|
| 3011 | } |
|---|
| 3012 | #endif |
|---|
| 3013 | else |
|---|
| 3014 | strncpy(localwanface, nvram_safe_get("wan_ifname"), IFNAMSIZ); |
|---|
| 3015 | |
|---|
| 3016 | return localwanface; |
|---|
| 3017 | } |
|---|
| 3018 | |
|---|
| 3019 | static int _pidof(const char *name, pid_t ** pids) |
|---|
| 3020 | { |
|---|
| 3021 | const char *p; |
|---|
| 3022 | char *e; |
|---|
| 3023 | DIR *dir; |
|---|
| 3024 | struct dirent *de; |
|---|
| 3025 | pid_t i; |
|---|
| 3026 | int count; |
|---|
| 3027 | char buf[256]; |
|---|
| 3028 | |
|---|
| 3029 | count = 0; |
|---|
| 3030 | *pids = NULL; |
|---|
| 3031 | if ((p = strchr(name, '/')) != NULL) |
|---|
| 3032 | name = p + 1; |
|---|
| 3033 | if ((dir = opendir("/proc")) != NULL) { |
|---|
| 3034 | while ((de = readdir(dir)) != NULL) { |
|---|
| 3035 | i = strtol(de->d_name, &e, 10); |
|---|
| 3036 | if (*e != 0) |
|---|
| 3037 | continue; |
|---|
| 3038 | if (strcmp(name, psname(i, buf, sizeof(buf))) == 0) { |
|---|
| 3039 | if ((*pids = |
|---|
| 3040 | realloc(*pids, |
|---|
| 3041 | sizeof(pid_t) * (count + 1))) == |
|---|
| 3042 | NULL) { |
|---|
| 3043 | return -1; |
|---|
| 3044 | } |
|---|
| 3045 | (*pids)[count++] = i; |
|---|
| 3046 | } |
|---|
| 3047 | } |
|---|
| 3048 | } |
|---|
| 3049 | closedir(dir); |
|---|
| 3050 | return count; |
|---|
| 3051 | } |
|---|
| 3052 | |
|---|
| 3053 | int pidof(const char *name) |
|---|
| 3054 | { |
|---|
| 3055 | pid_t *pids; |
|---|
| 3056 | pid_t p; |
|---|
| 3057 | |
|---|
| 3058 | if (_pidof(name, &pids) > 0) { |
|---|
| 3059 | p = *pids; |
|---|
| 3060 | free(pids); |
|---|
| 3061 | return p; |
|---|
| 3062 | } |
|---|
| 3063 | return -1; |
|---|
| 3064 | } |
|---|
| 3065 | |
|---|
| 3066 | int killall(const char *name, int sig) |
|---|
| 3067 | { |
|---|
| 3068 | pid_t *pids; |
|---|
| 3069 | int i; |
|---|
| 3070 | int r; |
|---|
| 3071 | |
|---|
| 3072 | if ((i = _pidof(name, &pids)) > 0) { |
|---|
| 3073 | r = 0; |
|---|
| 3074 | do { |
|---|
| 3075 | r |= kill(pids[--i], sig); |
|---|
| 3076 | } |
|---|
| 3077 | while (i > 0); |
|---|
| 3078 | free(pids); |
|---|
| 3079 | return r; |
|---|
| 3080 | } |
|---|
| 3081 | return -2; |
|---|
| 3082 | } |
|---|
| 3083 | |
|---|
| 3084 | void set_ip_forward(char c) |
|---|
| 3085 | { |
|---|
| 3086 | FILE *fp; |
|---|
| 3087 | char ch[8]; |
|---|
| 3088 | sprintf(ch,"%c",c); |
|---|
| 3089 | writeproc("/proc/sys/net/ipv4/ip_forward",ch); |
|---|
| 3090 | } |
|---|
| 3091 | |
|---|
| 3092 | int ifexists(const char *ifname) |
|---|
| 3093 | { |
|---|
| 3094 | return getifcount(ifname) > 0 ? 1 : 0; |
|---|
| 3095 | } |
|---|
| 3096 | |
|---|
| 3097 | int getdevicecount(void) |
|---|
| 3098 | { |
|---|
| 3099 | int count = 0; |
|---|
| 3100 | #ifdef HAVE_ATH9K |
|---|
| 3101 | count += getath9kdevicecount(); |
|---|
| 3102 | #endif |
|---|
| 3103 | count += getifcount("wifi"); |
|---|
| 3104 | |
|---|
| 3105 | return count; |
|---|
| 3106 | } |
|---|
| 3107 | |
|---|
| 3108 | int getifcount(const char *ifprefix) |
|---|
| 3109 | { |
|---|
| 3110 | /* |
|---|
| 3111 | * char devcall[128]; |
|---|
| 3112 | * |
|---|
| 3113 | * sprintf (devcall, "cat /proc/net/dev|grep \"%s\"|wc -l", ifprefix); |
|---|
| 3114 | * FILE *in = popen (devcall, "rb"); if (in == NULL) return 0; int count; |
|---|
| 3115 | * fscanf (in, "%d", &count); pclose (in); return count; |
|---|
| 3116 | */ |
|---|
| 3117 | char *iflist = safe_malloc(256); |
|---|
| 3118 | |
|---|
| 3119 | memset(iflist, 0, 256); |
|---|
| 3120 | int c = getIfList(iflist, ifprefix); |
|---|
| 3121 | |
|---|
| 3122 | free(iflist); |
|---|
| 3123 | return c; |
|---|
| 3124 | } |
|---|
| 3125 | |
|---|
| 3126 | static void skipline(FILE * in) |
|---|
| 3127 | { |
|---|
| 3128 | while (1) { |
|---|
| 3129 | int c = getc(in); |
|---|
| 3130 | |
|---|
| 3131 | if (c == EOF) |
|---|
| 3132 | return; |
|---|
| 3133 | if (c == 0x0) |
|---|
| 3134 | return; |
|---|
| 3135 | if (c == 0xa) |
|---|
| 3136 | return; |
|---|
| 3137 | } |
|---|
| 3138 | } |
|---|
| 3139 | |
|---|
| 3140 | /* |
|---|
| 3141 | * strips trailing char(s) c from string |
|---|
| 3142 | */ |
|---|
| 3143 | void strtrim_right(char *p, int c) |
|---|
| 3144 | { |
|---|
| 3145 | char *end; |
|---|
| 3146 | int len; |
|---|
| 3147 | |
|---|
| 3148 | len = strlen(p); |
|---|
| 3149 | while (*p && len) { |
|---|
| 3150 | end = p + len - 1; |
|---|
| 3151 | if (c == *end) |
|---|
| 3152 | *end = 0; |
|---|
| 3153 | else |
|---|
| 3154 | break; |
|---|
| 3155 | len = strlen(p); |
|---|
| 3156 | } |
|---|
| 3157 | return; |
|---|
| 3158 | } |
|---|
| 3159 | |
|---|
| 3160 | // returns a physical interfacelist filtered by ifprefix. if ifprefix is |
|---|
| 3161 | // NULL, all valid interfaces will be returned |
|---|
| 3162 | int getIfList(char *buffer, const char *ifprefix) |
|---|
| 3163 | { |
|---|
| 3164 | FILE *in = fopen("/proc/net/dev", "rb"); |
|---|
| 3165 | char ifname[32]; |
|---|
| 3166 | |
|---|
| 3167 | // skip the first 2 lines |
|---|
| 3168 | skipline(in); |
|---|
| 3169 | skipline(in); |
|---|
| 3170 | int ifcount = 0; |
|---|
| 3171 | int count = 0; |
|---|
| 3172 | |
|---|
| 3173 | while (1) { |
|---|
| 3174 | int c = getc(in); |
|---|
| 3175 | |
|---|
| 3176 | if (c == 0 || c == EOF) { |
|---|
| 3177 | if (count) |
|---|
| 3178 | buffer[strlen(buffer) - 1] = 0; // fixup last space |
|---|
| 3179 | fclose(in); |
|---|
| 3180 | return count; |
|---|
| 3181 | } |
|---|
| 3182 | if (c == 0x20) |
|---|
| 3183 | continue; |
|---|
| 3184 | if (c == ':' || ifcount == 30) { |
|---|
| 3185 | ifname[ifcount++] = 0; |
|---|
| 3186 | int skip = 0; |
|---|
| 3187 | |
|---|
| 3188 | if (ifprefix) { |
|---|
| 3189 | if (strncmp(ifname, ifprefix, strlen(ifprefix))) { |
|---|
| 3190 | skip = 1; |
|---|
| 3191 | } |
|---|
| 3192 | } else { |
|---|
| 3193 | if (!strncmp(ifname, "wifi", 4)) |
|---|
| 3194 | skip = 1; |
|---|
| 3195 | if (!strncmp(ifname, "ifb", 3)) |
|---|
| 3196 | skip = 1; |
|---|
| 3197 | if (!strncmp(ifname, "imq", 3)) |
|---|
| 3198 | skip = 1; |
|---|
| 3199 | if (!strncmp(ifname, "etherip", 7)) |
|---|
| 3200 | skip = 1; |
|---|
| 3201 | if (!strncmp(ifname, "lo", 2)) |
|---|
| 3202 | skip = 1; |
|---|
| 3203 | if (!strncmp(ifname, "teql", 4)) |
|---|
| 3204 | skip = 1; |
|---|
| 3205 | if (!strncmp(ifname, "gre", 3)) |
|---|
| 3206 | skip = 1; |
|---|
| 3207 | if (!strncmp(ifname, "ppp", 3)) |
|---|
| 3208 | skip = 1; |
|---|
| 3209 | if (!strncmp(ifname, "tun", 3)) |
|---|
| 3210 | skip = 1; |
|---|
| 3211 | if (!strncmp(ifname, "tap", 3)) |
|---|
| 3212 | skip = 1; |
|---|
| 3213 | } |
|---|
| 3214 | if (!skip) { |
|---|
| 3215 | strcat(buffer, ifname); |
|---|
| 3216 | strcat(buffer, " "); |
|---|
| 3217 | count++; |
|---|
| 3218 | } |
|---|
| 3219 | skip = 0; |
|---|
| 3220 | ifcount = 0; |
|---|
| 3221 | memset(ifname, 0, 32); |
|---|
| 3222 | skipline(in); |
|---|
| 3223 | continue; |
|---|
| 3224 | } |
|---|
| 3225 | if (ifcount < 30) |
|---|
| 3226 | ifname[ifcount++] = c; |
|---|
| 3227 | } |
|---|
| 3228 | } |
|---|
| 3229 | |
|---|
| 3230 | /* |
|---|
| 3231 | * Example: legal_hwaddr("00:11:22:33:44:aB"); return true; |
|---|
| 3232 | * legal_hwaddr("00:11:22:33:44:5"); return false; |
|---|
| 3233 | * legal_hwaddr("00:11:22:33:44:HH"); return false; |
|---|
| 3234 | */ |
|---|
| 3235 | int sv_valid_hwaddr(char *value) |
|---|
| 3236 | { |
|---|
| 3237 | unsigned int hwaddr[6]; |
|---|
| 3238 | int tag = TRUE; |
|---|
| 3239 | int i, count; |
|---|
| 3240 | |
|---|
| 3241 | /* |
|---|
| 3242 | * Check for bad, multicast, broadcast, or null address |
|---|
| 3243 | */ |
|---|
| 3244 | for (i = 0, count = 0; *(value + i); i++) { |
|---|
| 3245 | if (*(value + i) == ':') { |
|---|
| 3246 | if ((i + 1) % 3 != 0) { |
|---|
| 3247 | tag = FALSE; |
|---|
| 3248 | break; |
|---|
| 3249 | } |
|---|
| 3250 | count++; |
|---|
| 3251 | } else if (ishexit(*(value + i))) /* one of 0 1 2 3 4 5 6 7 8 9 |
|---|
| 3252 | * a b c d e f A B C D E F */ |
|---|
| 3253 | continue; |
|---|
| 3254 | else { |
|---|
| 3255 | tag = FALSE; |
|---|
| 3256 | break; |
|---|
| 3257 | } |
|---|
| 3258 | } |
|---|
| 3259 | |
|---|
| 3260 | if (!tag || i != 17 || count != 5) /* must have 17's characters and 5's |
|---|
| 3261 | * ':' */ |
|---|
| 3262 | tag = FALSE; |
|---|
| 3263 | else if (sscanf(value, "%x:%x:%x:%x:%x:%x", |
|---|
| 3264 | &hwaddr[0], &hwaddr[1], &hwaddr[2], |
|---|
| 3265 | &hwaddr[3], &hwaddr[4], &hwaddr[5]) != 6) { |
|---|
| 3266 | tag = FALSE; |
|---|
| 3267 | } else |
|---|
| 3268 | tag = TRUE; |
|---|
| 3269 | #ifdef WDS_DEBUG |
|---|
| 3270 | if (tag == FALSE) |
|---|
| 3271 | fprintf(fp, "failed valid_hwaddr\n"); |
|---|
| 3272 | #endif |
|---|
| 3273 | |
|---|
| 3274 | return tag; |
|---|
| 3275 | } |
|---|
| 3276 | |
|---|
| 3277 | char *cpustring(void) |
|---|
| 3278 | { |
|---|
| 3279 | static char buf[256]; |
|---|
| 3280 | #ifdef HAVE_RB600 |
|---|
| 3281 | strcpy(buf, "FreeScale MPC8343"); |
|---|
| 3282 | return buf; |
|---|
| 3283 | #else |
|---|
| 3284 | FILE *fcpu = fopen("/proc/cpuinfo", "r"); |
|---|
| 3285 | |
|---|
| 3286 | if (fcpu == NULL) { |
|---|
| 3287 | return NULL; |
|---|
| 3288 | } |
|---|
| 3289 | int i; |
|---|
| 3290 | |
|---|
| 3291 | #ifdef HAVE_MAGICBOX |
|---|
| 3292 | int cnt = 0; |
|---|
| 3293 | #endif |
|---|
| 3294 | #ifdef HAVE_X86 |
|---|
| 3295 | int cnt = 0; |
|---|
| 3296 | #endif |
|---|
| 3297 | for (i = 0; i < 256; i++) { |
|---|
| 3298 | int c = getc(fcpu); |
|---|
| 3299 | |
|---|
| 3300 | if (c == EOF) { |
|---|
| 3301 | fclose(fcpu); |
|---|
| 3302 | return NULL; |
|---|
| 3303 | } |
|---|
| 3304 | if (c == ':') |
|---|
| 3305 | #ifdef HAVE_MAGICBOX |
|---|
| 3306 | cnt++; |
|---|
| 3307 | if (cnt == 2) |
|---|
| 3308 | break; |
|---|
| 3309 | #elif HAVE_X86 |
|---|
| 3310 | cnt++; |
|---|
| 3311 | if (cnt == 5) |
|---|
| 3312 | break; |
|---|
| 3313 | #else |
|---|
| 3314 | break; |
|---|
| 3315 | #endif |
|---|
| 3316 | } |
|---|
| 3317 | getc(fcpu); |
|---|
| 3318 | for (i = 0; i < 256; i++) { |
|---|
| 3319 | int c = getc(fcpu); |
|---|
| 3320 | |
|---|
| 3321 | if (c == EOF) { |
|---|
| 3322 | fclose(fcpu); |
|---|
| 3323 | return NULL; |
|---|
| 3324 | } |
|---|
| 3325 | if (c == 0xa || c == 0xd) |
|---|
| 3326 | break; |
|---|
| 3327 | buf[i] = c; |
|---|
| 3328 | } |
|---|
| 3329 | buf[i] = 0; |
|---|
| 3330 | fclose(fcpu); |
|---|
| 3331 | return buf; |
|---|
| 3332 | #endif |
|---|
| 3333 | } |
|---|
| 3334 | |
|---|
| 3335 | #if defined(HAVE_MADWIFI_MIMO) || defined(HAVE_ATH9K) |
|---|
| 3336 | |
|---|
| 3337 | int isap8x(void) |
|---|
| 3338 | { |
|---|
| 3339 | #define CPUSTR "Atheros AR91" |
|---|
| 3340 | char *str = cpustring(); |
|---|
| 3341 | if (str && !strncmp(str, CPUSTR, 12)) |
|---|
| 3342 | return 1; |
|---|
| 3343 | else |
|---|
| 3344 | return 0; |
|---|
| 3345 | #undef CPUSTR |
|---|
| 3346 | |
|---|
| 3347 | } |
|---|
| 3348 | |
|---|
| 3349 | #endif |
|---|
| 3350 | |
|---|
| 3351 | int led_control(int type, int act) |
|---|
| 3352 | /* |
|---|
| 3353 | * type: LED_POWER, LED_DIAG, LED_DMZ, LED_CONNECTED, LED_BRIDGE, LED_VPN, |
|---|
| 3354 | * LED_SES, LED_SES2, LED_WLAN0, LED_WLAN1, LED_SEC0, LED_SEC1, USB_POWER |
|---|
| 3355 | * act: LED_ON, LED_OFF, LED_FLASH |
|---|
| 3356 | */ |
|---|
| 3357 | { |
|---|
| 3358 | #if (defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_MERAKI) || defined(HAVE_LS2) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_LS5)) && (!defined(HAVE_DIR300) && !defined(HAVE_WRT54G2) && !defined(HAVE_RTG32) && !defined(HAVE_DIR400) && !defined(HAVE_BWRG1000)) |
|---|
| 3359 | return 0; |
|---|
| 3360 | #else |
|---|
| 3361 | int use_gpio = 0x0ff; |
|---|
| 3362 | int gpio_value; |
|---|
| 3363 | int enable; |
|---|
| 3364 | int disable; |
|---|
| 3365 | |
|---|
| 3366 | int power_gpio = 0x0ff; |
|---|
| 3367 | int diag_gpio = 0x0ff; |
|---|
| 3368 | int dmz_gpio = 0x0ff; |
|---|
| 3369 | int connected_gpio = 0x0ff; |
|---|
| 3370 | int disconnected_gpio = 0x0ff; |
|---|
| 3371 | int bridge_gpio = 0x0ff; |
|---|
| 3372 | int vpn_gpio = 0x0ff; |
|---|
| 3373 | int ses_gpio = 0x0ff; // use for SES1 (Linksys), AOSS (Buffalo) |
|---|
| 3374 | int ses2_gpio = 0x0ff; |
|---|
| 3375 | int wlan0_gpio = 0x0ff; // use this only if wlan led is not controlled by hardware! |
|---|
| 3376 | int wlan1_gpio = 0x0ff; // use this only if wlan led is not controlled by hardware! |
|---|
| 3377 | int usb_gpio = 0x0ff; |
|---|
| 3378 | int sec0_gpio = 0x0ff; // security leds, wrt600n |
|---|
| 3379 | int sec1_gpio = 0x0ff; |
|---|
| 3380 | int usb_power = 0x0ff; |
|---|
| 3381 | int v1func = 0; |
|---|
| 3382 | int connblue = nvram_match("connblue", "1") ? 1 : 0; |
|---|
| 3383 | |
|---|
| 3384 | switch (getRouterBrand()) // gpio definitions here: 0xYZ, |
|---|
| 3385 | // Y=0:normal, Y=1:inverted, Z:gpio |
|---|
| 3386 | // number (f=disabled) |
|---|
| 3387 | { |
|---|
| 3388 | #ifndef HAVE_BUFFALO |
|---|
| 3389 | case ROUTER_BOARD_TECHNAXX3G: |
|---|
| 3390 | usb_gpio = 0x109; |
|---|
| 3391 | diag_gpio = 0x10c; |
|---|
| 3392 | connected_gpio = 0x10b; |
|---|
| 3393 | ses_gpio = 0x10c; |
|---|
| 3394 | break; |
|---|
| 3395 | case ROUTER_BOARD_UNIFI: |
|---|
| 3396 | diag_gpio = 0x001; |
|---|
| 3397 | break; |
|---|
| 3398 | case ROUTER_BOARD_DANUBE: |
|---|
| 3399 | #ifdef HAVE_WMBR_G300NH |
|---|
| 3400 | diag_gpio = 0x105; |
|---|
| 3401 | ses_gpio = 0x10e; |
|---|
| 3402 | sec0_gpio = 0x10e; |
|---|
| 3403 | connected_gpio = 0x111; |
|---|
| 3404 | disconnected_gpio = 0x112; |
|---|
| 3405 | power_gpio = 0x101; |
|---|
| 3406 | #endif |
|---|
| 3407 | #ifdef HAVE_SX763 |
|---|
| 3408 | // diag_gpio = 0x105; |
|---|
| 3409 | // ses_gpio = 0x10e; |
|---|
| 3410 | // sec0_gpio = 0x10e; |
|---|
| 3411 | connected_gpio = 0x1de; |
|---|
| 3412 | // disconnected_gpio = 0x112; |
|---|
| 3413 | // power_gpio = 0x101; |
|---|
| 3414 | #endif |
|---|
| 3415 | break; |
|---|
| 3416 | case ROUTER_BOARD_PB42: |
|---|
| 3417 | #ifdef HAVE_WR941 |
|---|
| 3418 | diag_gpio = 0x102; |
|---|
| 3419 | ses_gpio = 0x005; |
|---|
| 3420 | // usb_gpio = 0x101; |
|---|
| 3421 | #endif |
|---|
| 3422 | #ifdef HAVE_WR703 |
|---|
| 3423 | diag_gpio = 0x11b; |
|---|
| 3424 | ses_gpio = 0x001; |
|---|
| 3425 | sec0_gpio = 0x001; |
|---|
| 3426 | usb_power = 0x008; |
|---|
| 3427 | #elif HAVE_WR842 |
|---|
| 3428 | diag_gpio = 0x101; |
|---|
| 3429 | ses_gpio = 0x000; |
|---|
| 3430 | usb_power = 0x006; |
|---|
| 3431 | |
|---|
| 3432 | #elif HAVE_WR741V4 |
|---|
| 3433 | diag_gpio = 0x11b; |
|---|
| 3434 | ses_gpio = 0x001; |
|---|
| 3435 | sec0_gpio = 0x001; |
|---|
| 3436 | |
|---|
| 3437 | #elif HAVE_WR741 |
|---|
| 3438 | diag_gpio = 0x101; |
|---|
| 3439 | ses_gpio = 0x000; |
|---|
| 3440 | // usb_gpio = 0x101; |
|---|
| 3441 | #endif |
|---|
| 3442 | #ifdef HAVE_WR1043 |
|---|
| 3443 | diag_gpio = 0x102; |
|---|
| 3444 | ses_gpio = 0x005; |
|---|
| 3445 | // usb_gpio = 0x101; |
|---|
| 3446 | #endif |
|---|
| 3447 | #ifdef HAVE_WRT160NL |
|---|
| 3448 | power_gpio = 0x10e; |
|---|
| 3449 | connected_gpio = 0x109; |
|---|
| 3450 | ses_gpio = 0x108; |
|---|
| 3451 | #endif |
|---|
| 3452 | #ifdef HAVE_TG2521 |
|---|
| 3453 | ses_gpio = 0x103; |
|---|
| 3454 | diag_gpio = 0x103; |
|---|
| 3455 | usb_power = 0x105; |
|---|
| 3456 | #endif |
|---|
| 3457 | #ifdef HAVE_TEW632BRP |
|---|
| 3458 | diag_gpio = 0x101; |
|---|
| 3459 | ses_gpio = 0x103; |
|---|
| 3460 | #endif |
|---|
| 3461 | #ifdef HAVE_WP543 |
|---|
| 3462 | diag_gpio = 0x107; |
|---|
| 3463 | connected_gpio = 0x106; |
|---|
| 3464 | #endif |
|---|
| 3465 | #ifdef HAVE_DIR825 |
|---|
| 3466 | power_gpio = 0x102; |
|---|
| 3467 | diag_gpio = 0x101; |
|---|
| 3468 | connected_gpio = 0x10b; |
|---|
| 3469 | disconnected_gpio = 0x106; |
|---|
| 3470 | ses_gpio = 0x104; |
|---|
| 3471 | #endif |
|---|
| 3472 | #ifdef HAVE_WNDR3700 |
|---|
| 3473 | power_gpio = 0x102; |
|---|
| 3474 | diag_gpio = 0x101; |
|---|
| 3475 | connected_gpio = 0x106; |
|---|
| 3476 | ses_gpio = 0x104; |
|---|
| 3477 | #endif |
|---|
| 3478 | #ifdef HAVE_WZRG300NH |
|---|
| 3479 | diag_gpio = 0x101; |
|---|
| 3480 | connected_gpio = 0x112; |
|---|
| 3481 | ses_gpio = 0x111; |
|---|
| 3482 | sec0_gpio = 0x111; |
|---|
| 3483 | #endif |
|---|
| 3484 | #ifdef HAVE_DIR632 |
|---|
| 3485 | power_gpio = 0x001; |
|---|
| 3486 | diag_gpio = 0x100; |
|---|
| 3487 | connected_gpio = 0x111; |
|---|
| 3488 | usb_gpio = 0x10b; |
|---|
| 3489 | #endif |
|---|
| 3490 | #ifdef HAVE_WZRG450 |
|---|
| 3491 | diag_gpio = 0x10e; |
|---|
| 3492 | ses_gpio = 0x10d; |
|---|
| 3493 | sec0_gpio = 0x10d; |
|---|
| 3494 | usb_power = 0x010; |
|---|
| 3495 | connected_gpio = 0x12e; // card 1, gpio 14 |
|---|
| 3496 | #endif |
|---|
| 3497 | #ifdef HAVE_WZRG300NH2 |
|---|
| 3498 | diag_gpio = 0x110; |
|---|
| 3499 | ses_gpio = 0x126; // card 1, gpio 6 |
|---|
| 3500 | sec0_gpio = 0x126; |
|---|
| 3501 | usb_power = 0x00d; |
|---|
| 3502 | connected_gpio = 0x127; // card 1, gpio 7 |
|---|
| 3503 | #endif |
|---|
| 3504 | #ifdef HAVE_WZRHPAG300NH |
|---|
| 3505 | diag_gpio = 0x101; |
|---|
| 3506 | connected_gpio = 0x133; // card 2 gpio 3 |
|---|
| 3507 | sec0_gpio = 0x125; |
|---|
| 3508 | sec1_gpio = 0x131; |
|---|
| 3509 | ses_gpio = 0x125; // card 1 gpio 5 |
|---|
| 3510 | ses2_gpio = 0x131; // card 2 gpio 5 |
|---|
| 3511 | usb_power = 0x002; |
|---|
| 3512 | #endif |
|---|
| 3513 | #ifdef HAVE_DIR615E |
|---|
| 3514 | power_gpio = 0x006; |
|---|
| 3515 | diag_gpio = 0x001; |
|---|
| 3516 | connected_gpio = 0x111; |
|---|
| 3517 | disconnected_gpio = 0x007; |
|---|
| 3518 | ses_gpio = 0x100; |
|---|
| 3519 | #endif |
|---|
| 3520 | #ifdef HAVE_WRT400 |
|---|
| 3521 | power_gpio = 0x001; |
|---|
| 3522 | diag_gpio = 0x105; |
|---|
| 3523 | ses_gpio = 0x104; |
|---|
| 3524 | connected_gpio = 0x007; |
|---|
| 3525 | #endif |
|---|
| 3526 | #ifdef HAVE_ALFAAP94 |
|---|
| 3527 | power_gpio = 0x005; |
|---|
| 3528 | #endif |
|---|
| 3529 | break; |
|---|
| 3530 | case ROUTER_ALLNET01: |
|---|
| 3531 | connected_gpio = 0x100; |
|---|
| 3532 | break; |
|---|
| 3533 | case ROUTER_BOARD_WP54G: |
|---|
| 3534 | diag_gpio = 0x102; |
|---|
| 3535 | connected_gpio = 0x107; |
|---|
| 3536 | break; |
|---|
| 3537 | case ROUTER_BOARD_NP28G: |
|---|
| 3538 | diag_gpio = 0x102; |
|---|
| 3539 | connected_gpio = 0x106; |
|---|
| 3540 | break; |
|---|
| 3541 | case ROUTER_BOARD_GATEWORX_GW2369: |
|---|
| 3542 | connected_gpio = 0x102; |
|---|
| 3543 | break; |
|---|
| 3544 | case ROUTER_BOARD_GW2388: |
|---|
| 3545 | case ROUTER_BOARD_GW2380: |
|---|
| 3546 | connected_gpio = 0x110; // 16 is mapped to front led |
|---|
| 3547 | break; |
|---|
| 3548 | case ROUTER_BOARD_GATEWORX: |
|---|
| 3549 | #ifdef HAVE_WG302V1 |
|---|
| 3550 | diag_gpio = 0x104; |
|---|
| 3551 | wlan0_gpio = 0x105; |
|---|
| 3552 | #elif HAVE_WG302 |
|---|
| 3553 | diag_gpio = 0x102; |
|---|
| 3554 | wlan0_gpio = 0x104; |
|---|
| 3555 | #else |
|---|
| 3556 | if (nvram_match("DD_BOARD", "Gateworks Cambria GW2350") |
|---|
| 3557 | || nvram_match("DD_BOARD2", "Gateworks Cambria GW2350")) |
|---|
| 3558 | connected_gpio = 0x105; |
|---|
| 3559 | else if (nvram_match("DD_BOARD", "Gateworks Cambria GW2358-4") |
|---|
| 3560 | || nvram_match("DD_BOARD2", |
|---|
| 3561 | "Gateworks Cambria GW2358-4")) |
|---|
| 3562 | connected_gpio = 0x118; |
|---|
| 3563 | else |
|---|
| 3564 | connected_gpio = 0x003; |
|---|
| 3565 | #endif |
|---|
| 3566 | break; |
|---|
| 3567 | case ROUTER_BOARD_GATEWORX_SWAP: |
|---|
| 3568 | connected_gpio = 0x004; |
|---|
| 3569 | break; |
|---|
| 3570 | case ROUTER_BOARD_STORM: |
|---|
| 3571 | connected_gpio = 0x005; |
|---|
| 3572 | diag_gpio = 0x003; |
|---|
| 3573 | break; |
|---|
| 3574 | case ROUTER_LINKSYS_WRH54G: |
|---|
| 3575 | diag_gpio = 0x101; // power led blink / off to indicate factory |
|---|
| 3576 | // defaults |
|---|
| 3577 | break; |
|---|
| 3578 | case ROUTER_WRT54G: |
|---|
| 3579 | case ROUTER_WRT54G_V8: |
|---|
| 3580 | power_gpio = 0x001; |
|---|
| 3581 | dmz_gpio = 0x107; |
|---|
| 3582 | connected_gpio = 0x103; // ses orange |
|---|
| 3583 | ses_gpio = 0x102; // ses white |
|---|
| 3584 | ses2_gpio = 0x103; // ses orange |
|---|
| 3585 | break; |
|---|
| 3586 | case ROUTER_WRT54G_V81: |
|---|
| 3587 | power_gpio = 0x101; |
|---|
| 3588 | dmz_gpio = 0x102; |
|---|
| 3589 | connected_gpio = 0x104; // ses orange |
|---|
| 3590 | ses_gpio = 0x103; // ses white |
|---|
| 3591 | ses2_gpio = 0x104; // ses orange |
|---|
| 3592 | break; |
|---|
| 3593 | case ROUTER_WRT54G1X: |
|---|
| 3594 | connected_gpio = 0x103; |
|---|
| 3595 | v1func = 1; |
|---|
| 3596 | break; |
|---|
| 3597 | case ROUTER_WRT350N: |
|---|
| 3598 | connected_gpio = 0x103; |
|---|
| 3599 | power_gpio = 0x001; |
|---|
| 3600 | ses2_gpio = 0x103; // ses orange |
|---|
| 3601 | sec0_gpio = 0x109; |
|---|
| 3602 | usb_gpio = 0x10b; |
|---|
| 3603 | break; |
|---|
| 3604 | case ROUTER_WRT600N: |
|---|
| 3605 | power_gpio = 0x102; |
|---|
| 3606 | diag_gpio = 0x002; |
|---|
| 3607 | usb_gpio = 0x103; |
|---|
| 3608 | sec0_gpio = 0x109; |
|---|
| 3609 | sec1_gpio = 0x10b; |
|---|
| 3610 | break; |
|---|
| 3611 | case ROUTER_LINKSYS_WRT55AG: |
|---|
| 3612 | connected_gpio = 0x103; |
|---|
| 3613 | break; |
|---|
| 3614 | case ROUTER_DLINK_DIR330: |
|---|
| 3615 | diag_gpio = 0x106; |
|---|
| 3616 | connected_gpio = 0x100; |
|---|
| 3617 | usb_gpio = 0x104; |
|---|
| 3618 | break; |
|---|
| 3619 | case ROUTER_ASUS_RTN10PLUS: |
|---|
| 3620 | // diag_gpio = 0x10d; |
|---|
| 3621 | // connected_gpio = 0x108; |
|---|
| 3622 | // power_gpio = 0x109; |
|---|
| 3623 | break; |
|---|
| 3624 | case ROUTER_BOARD_DIR600B: |
|---|
| 3625 | diag_gpio = 0x10d; |
|---|
| 3626 | connected_gpio = 0x108; |
|---|
| 3627 | power_gpio = 0x109; |
|---|
| 3628 | break; |
|---|
| 3629 | case ROUTER_BOARD_DIR615D: |
|---|
| 3630 | diag_gpio = 0x108; |
|---|
| 3631 | connected_gpio = 0x10c; |
|---|
| 3632 | disconnected_gpio = 0x10e; |
|---|
| 3633 | ses_gpio = 0x10b; |
|---|
| 3634 | power_gpio = 0x109; |
|---|
| 3635 | break; |
|---|
| 3636 | case ROUTER_BOARD_W502U: |
|---|
| 3637 | connected_gpio = 0x10d; |
|---|
| 3638 | break; |
|---|
| 3639 | case ROUTER_BOARD_OPENRISC: |
|---|
| 3640 | #ifndef HAVE_ERC |
|---|
| 3641 | // ERC: diag button is used different / wlan button is handled by a script |
|---|
| 3642 | diag_gpio = 0x003; |
|---|
| 3643 | ses_gpio = 0x005; |
|---|
| 3644 | #endif |
|---|
| 3645 | break; |
|---|
| 3646 | case ROUTER_BOARD_WR5422: |
|---|
| 3647 | ses_gpio = 0x10d; |
|---|
| 3648 | break; |
|---|
| 3649 | case ROUTER_BOARD_F5D8235: |
|---|
| 3650 | usb_gpio = 0x117; |
|---|
| 3651 | diag_gpio = 0x109; |
|---|
| 3652 | disconnected_gpio = 0x106; |
|---|
| 3653 | connected_gpio = 0x105; |
|---|
| 3654 | ses_gpio = 0x10c; |
|---|
| 3655 | break; |
|---|
| 3656 | #else |
|---|
| 3657 | case ROUTER_BOARD_DANUBE: |
|---|
| 3658 | #ifdef HAVE_WMBR_G300NH |
|---|
| 3659 | diag_gpio = 0x105; |
|---|
| 3660 | ses_gpio = 0x10e; |
|---|
| 3661 | sec0_gpio = 0x10e; |
|---|
| 3662 | connected_gpio = 0x111; |
|---|
| 3663 | disconnected_gpio = 0x112; |
|---|
| 3664 | power_gpio = 0x101; |
|---|
| 3665 | #endif |
|---|
| 3666 | break; |
|---|
| 3667 | case ROUTER_BOARD_PB42: |
|---|
| 3668 | #ifdef HAVE_WZRG300NH |
|---|
| 3669 | diag_gpio = 0x101; |
|---|
| 3670 | connected_gpio = 0x112; |
|---|
| 3671 | ses_gpio = 0x111; |
|---|
| 3672 | sec0_gpio = 0x111; |
|---|
| 3673 | #endif |
|---|
| 3674 | #ifdef HAVE_WZRHPAG300NH |
|---|
| 3675 | diag_gpio = 0x101; |
|---|
| 3676 | connected_gpio = 0x133; |
|---|
| 3677 | ses_gpio = 0x125; |
|---|
| 3678 | ses2_gpio = 0x131; |
|---|
| 3679 | sec0_gpio = 0x125; |
|---|
| 3680 | sec1_gpio = 0x131; |
|---|
| 3681 | usb_power = 0x002; |
|---|
| 3682 | #endif |
|---|
| 3683 | #ifdef HAVE_WZRG450 |
|---|
| 3684 | diag_gpio = 0x10e; |
|---|
| 3685 | ses_gpio = 0x10d; |
|---|
| 3686 | sec0_gpio = 0x10d; |
|---|
| 3687 | usb_power = 0x010; |
|---|
| 3688 | connected_gpio = 0x12e; // card 1, gpio 14 |
|---|
| 3689 | #endif |
|---|
| 3690 | #ifdef HAVE_WZRG300NH2 |
|---|
| 3691 | diag_gpio = 0x110; |
|---|
| 3692 | ses_gpio = 0x126; |
|---|
| 3693 | sec0_gpio = 0x126; |
|---|
| 3694 | usb_power = 0x00d; |
|---|
| 3695 | connected_gpio = 0x127; |
|---|
| 3696 | #endif |
|---|
| 3697 | break; |
|---|
| 3698 | #endif |
|---|
| 3699 | case ROUTER_BOARD_WCRGN: |
|---|
| 3700 | diag_gpio = 0x107; |
|---|
| 3701 | connected_gpio = 0x10b; |
|---|
| 3702 | // ses_gpio = 0x10e; |
|---|
| 3703 | break; |
|---|
| 3704 | case ROUTER_BOARD_WHRG300N: |
|---|
| 3705 | diag_gpio = 0x107; |
|---|
| 3706 | connected_gpio = 0x109; |
|---|
| 3707 | ses_gpio = 0x10e; |
|---|
| 3708 | break; |
|---|
| 3709 | #ifdef HAVE_WNR2200 |
|---|
| 3710 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3711 | power_gpio = 0x122; |
|---|
| 3712 | diag_gpio = 0x121; |
|---|
| 3713 | connected_gpio = 0x107; |
|---|
| 3714 | usb_power = 0x024; // enable usb port |
|---|
| 3715 | // ses_gpio = 0x104; |
|---|
| 3716 | // sec0_gpio = 0x104; |
|---|
| 3717 | break; |
|---|
| 3718 | #elif HAVE_WNR2000 |
|---|
| 3719 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3720 | power_gpio = 0x123; |
|---|
| 3721 | diag_gpio = 0x122; |
|---|
| 3722 | connected_gpio = 0x100; |
|---|
| 3723 | // ses_gpio = 0x104; |
|---|
| 3724 | // sec0_gpio = 0x104; |
|---|
| 3725 | break; |
|---|
| 3726 | #elif HAVE_WLAEAG300N |
|---|
| 3727 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3728 | power_gpio = 0x110; |
|---|
| 3729 | diag_gpio = 0x111; |
|---|
| 3730 | connected_gpio = 0x106; |
|---|
| 3731 | ses_gpio = 0x10e; |
|---|
| 3732 | sec0_gpio = 0x10e; |
|---|
| 3733 | break; |
|---|
| 3734 | #elif HAVE_HORNET |
|---|
| 3735 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3736 | usb_power = 0x01a; |
|---|
| 3737 | usb_gpio = 0x001; |
|---|
| 3738 | ses_gpio = 0x11b; |
|---|
| 3739 | break; |
|---|
| 3740 | #elif HAVE_DIR825C1 |
|---|
| 3741 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3742 | diag_gpio = 0x10f; |
|---|
| 3743 | connected_gpio = 0x112; |
|---|
| 3744 | disconnected_gpio = 0x113; |
|---|
| 3745 | power_gpio = 0x10e; |
|---|
| 3746 | // usb_power = 0x01a; |
|---|
| 3747 | // usb_gpio = 0x001; |
|---|
| 3748 | // ses_gpio = 0x11b; |
|---|
| 3749 | break; |
|---|
| 3750 | #elif HAVE_WASP |
|---|
| 3751 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3752 | // usb_power = 0x01a; |
|---|
| 3753 | // usb_gpio = 0x001; |
|---|
| 3754 | // ses_gpio = 0x11b; |
|---|
| 3755 | break; |
|---|
| 3756 | #else |
|---|
| 3757 | case ROUTER_BOARD_WHRHPGN: |
|---|
| 3758 | diag_gpio = 0x101; |
|---|
| 3759 | connected_gpio = 0x106; |
|---|
| 3760 | ses_gpio = 0x100; |
|---|
| 3761 | sec0_gpio = 0x100; |
|---|
| 3762 | break; |
|---|
| 3763 | #endif |
|---|
| 3764 | case ROUTER_BUFFALO_WBR54G: |
|---|
| 3765 | diag_gpio = 0x107; |
|---|
| 3766 | break; |
|---|
| 3767 | case ROUTER_BUFFALO_WBR2G54S: |
|---|
| 3768 | diag_gpio = 0x001; |
|---|
| 3769 | ses_gpio = 0x006; |
|---|
| 3770 | break; |
|---|
| 3771 | case ROUTER_BUFFALO_WLA2G54C: |
|---|
| 3772 | diag_gpio = 0x104; |
|---|
| 3773 | ses_gpio = 0x103; |
|---|
| 3774 | break; |
|---|
| 3775 | case ROUTER_BUFFALO_WLAH_G54: |
|---|
| 3776 | diag_gpio = 0x107; |
|---|
| 3777 | ses_gpio = 0x106; |
|---|
| 3778 | break; |
|---|
| 3779 | case ROUTER_BUFFALO_WAPM_HP_AM54G54: |
|---|
| 3780 | diag_gpio = 0x107; |
|---|
| 3781 | ses_gpio = 0x101; |
|---|
| 3782 | break; |
|---|
| 3783 | case ROUTER_BOARD_WHRAG108: |
|---|
| 3784 | diag_gpio = 0x107; |
|---|
| 3785 | bridge_gpio = 0x104; |
|---|
| 3786 | ses_gpio = 0x100; |
|---|
| 3787 | break; |
|---|
| 3788 | case ROUTER_BUFFALO_WHRG54S: |
|---|
| 3789 | case ROUTER_BUFFALO_WLI_TX4_G54HP: |
|---|
| 3790 | diag_gpio = 0x107; |
|---|
| 3791 | if (nvram_match("DD_BOARD", "Buffalo WHR-G125")) { |
|---|
| 3792 | connected_gpio = 0x101; |
|---|
| 3793 | sec0_gpio = 0x106; |
|---|
| 3794 | } else { |
|---|
| 3795 | bridge_gpio = 0x101; |
|---|
| 3796 | ses_gpio = 0x106; |
|---|
| 3797 | } |
|---|
| 3798 | break; |
|---|
| 3799 | case ROUTER_BUFFALO_WZRRSG54: |
|---|
| 3800 | diag_gpio = 0x107; |
|---|
| 3801 | vpn_gpio = 0x101; |
|---|
| 3802 | ses_gpio = 0x106; |
|---|
| 3803 | break; |
|---|
| 3804 | case ROUTER_BUFFALO_WZRG300N: |
|---|
| 3805 | diag_gpio = 0x107; |
|---|
| 3806 | bridge_gpio = 0x101; |
|---|
| 3807 | break; |
|---|
| 3808 | case ROUTER_BUFFALO_WZRG144NH: |
|---|
| 3809 | diag_gpio = 0x103; |
|---|
| 3810 | bridge_gpio = 0x101; |
|---|
| 3811 | ses_gpio = 0x102; |
|---|
| 3812 | break; |
|---|
| 3813 | #ifndef HAVE_BUFFALO |
|---|
| 3814 | #ifdef HAVE_DIR300 |
|---|
| 3815 | case ROUTER_BOARD_FONERA: |
|---|
| 3816 | diag_gpio = 0x003; |
|---|
| 3817 | bridge_gpio = 0x004; |
|---|
| 3818 | ses_gpio = 0x001; |
|---|
| 3819 | break; |
|---|
| 3820 | #endif |
|---|
| 3821 | #ifdef HAVE_WRT54G2 |
|---|
| 3822 | case ROUTER_BOARD_FONERA: |
|---|
| 3823 | bridge_gpio = 0x004; |
|---|
| 3824 | ses_gpio = 0x104; |
|---|
| 3825 | diag_gpio = 0x103; |
|---|
| 3826 | break; |
|---|
| 3827 | #endif |
|---|
| 3828 | #ifdef HAVE_RTG32 |
|---|
| 3829 | case ROUTER_BOARD_FONERA: |
|---|
| 3830 | break; |
|---|
| 3831 | #endif |
|---|
| 3832 | #ifdef HAVE_BWRG1000 |
|---|
| 3833 | case ROUTER_BOARD_LS2: |
|---|
| 3834 | diag_gpio = 0x007; |
|---|
| 3835 | break; |
|---|
| 3836 | #endif |
|---|
| 3837 | #ifdef HAVE_DIR400 |
|---|
| 3838 | case ROUTER_BOARD_FONERA2200: |
|---|
| 3839 | diag_gpio = 0x003; |
|---|
| 3840 | bridge_gpio = 0x004; |
|---|
| 3841 | ses_gpio = 0x001; |
|---|
| 3842 | break; |
|---|
| 3843 | #endif |
|---|
| 3844 | #ifdef HAVE_WRK54G |
|---|
| 3845 | case ROUTER_BOARD_FONERA: |
|---|
| 3846 | diag_gpio = 0x107; |
|---|
| 3847 | dmz_gpio = 0x005; |
|---|
| 3848 | break; |
|---|
| 3849 | #endif |
|---|
| 3850 | case ROUTER_BOARD_TW6600: |
|---|
| 3851 | diag_gpio = 0x107; |
|---|
| 3852 | bridge_gpio = 0x104; |
|---|
| 3853 | ses_gpio = 0x100; |
|---|
| 3854 | break; |
|---|
| 3855 | case ROUTER_MOTOROLA: |
|---|
| 3856 | power_gpio = 0x001; |
|---|
| 3857 | diag_gpio = 0x101; // power led blink / off to indicate factory |
|---|
| 3858 | // defaults |
|---|
| 3859 | break; |
|---|
| 3860 | case ROUTER_RT210W: |
|---|
| 3861 | power_gpio = 0x105; |
|---|
| 3862 | diag_gpio = 0x005; // power led blink / off to indicate factory |
|---|
| 3863 | // defaults |
|---|
| 3864 | connected_gpio = 0x100; |
|---|
| 3865 | wlan0_gpio = 0x103; |
|---|
| 3866 | break; |
|---|
| 3867 | case ROUTER_RT480W: |
|---|
| 3868 | case ROUTER_BELKIN_F5D7230_V2000: |
|---|
| 3869 | case ROUTER_BELKIN_F5D7231: |
|---|
| 3870 | power_gpio = 0x105; |
|---|
| 3871 | diag_gpio = 0x005; // power led blink / off to indicate factory |
|---|
| 3872 | // defaults |
|---|
| 3873 | connected_gpio = 0x100; |
|---|
| 3874 | break; |
|---|
| 3875 | case ROUTER_MICROSOFT_MN700: |
|---|
| 3876 | power_gpio = 0x006; |
|---|
| 3877 | diag_gpio = 0x106; // power led blink / off to indicate factory |
|---|
| 3878 | // defaults |
|---|
| 3879 | break; |
|---|
| 3880 | case ROUTER_ASUS_WL500GD: |
|---|
| 3881 | case ROUTER_ASUS_WL520GUGC: |
|---|
| 3882 | diag_gpio = 0x000; // power led blink / off to indicate factory |
|---|
| 3883 | // defaults |
|---|
| 3884 | break; |
|---|
| 3885 | case ROUTER_ASUS_WL500G_PRE: |
|---|
| 3886 | case ROUTER_ASUS_WL700GE: |
|---|
| 3887 | power_gpio = 0x101; |
|---|
| 3888 | diag_gpio = 0x001; // power led blink / off to indicate factory |
|---|
| 3889 | // defaults |
|---|
| 3890 | break; |
|---|
| 3891 | case ROUTER_ASUS_WL550GE: |
|---|
| 3892 | power_gpio = 0x102; |
|---|
| 3893 | diag_gpio = 0x002; // power led blink / off to indicate factory |
|---|
| 3894 | // defaults |
|---|
| 3895 | break; |
|---|
| 3896 | case ROUTER_WRT54G3G: |
|---|
| 3897 | case ROUTER_WRTSL54GS: |
|---|
| 3898 | power_gpio = 0x001; |
|---|
| 3899 | dmz_gpio = 0x100; |
|---|
| 3900 | connected_gpio = 0x107; // ses orange |
|---|
| 3901 | ses_gpio = 0x105; // ses white |
|---|
| 3902 | ses2_gpio = 0x107; // ses orange |
|---|
| 3903 | break; |
|---|
| 3904 | case ROUTER_MOTOROLA_WE800G: |
|---|
| 3905 | case ROUTER_MOTOROLA_V1: |
|---|
| 3906 | diag_gpio = 0x103; |
|---|
| 3907 | wlan0_gpio = 0x101; |
|---|
| 3908 | bridge_gpio = 0x105; |
|---|
| 3909 | break; |
|---|
| 3910 | case ROUTER_DELL_TRUEMOBILE_2300: |
|---|
| 3911 | case ROUTER_DELL_TRUEMOBILE_2300_V2: |
|---|
| 3912 | power_gpio = 0x107; |
|---|
| 3913 | diag_gpio = 0x007; // power led blink / off to indicate factory |
|---|
| 3914 | // defaults |
|---|
| 3915 | wlan0_gpio = 0x106; |
|---|
| 3916 | break; |
|---|
| 3917 | case ROUTER_NETGEAR_WNR834B: |
|---|
| 3918 | power_gpio = 0x104; |
|---|
| 3919 | diag_gpio = 0x105; |
|---|
| 3920 | wlan0_gpio = 0x106; |
|---|
| 3921 | break; |
|---|
| 3922 | case ROUTER_SITECOM_WL105B: |
|---|
| 3923 | power_gpio = 0x003; |
|---|
| 3924 | diag_gpio = 0x103; // power led blink / off to indicate factory |
|---|
| 3925 | // defaults |
|---|
| 3926 | wlan0_gpio = 0x104; |
|---|
| 3927 | break; |
|---|
| 3928 | case ROUTER_WRT300N: |
|---|
| 3929 | power_gpio = 0x001; |
|---|
| 3930 | diag_gpio = 0x101; // power led blink / off to indicate fac.def. |
|---|
| 3931 | break; |
|---|
| 3932 | case ROUTER_WRT150N: |
|---|
| 3933 | power_gpio = 0x001; |
|---|
| 3934 | diag_gpio = 0x101; // power led blink / off to indicate fac.def. |
|---|
| 3935 | sec0_gpio = 0x105; |
|---|
| 3936 | break; |
|---|
| 3937 | case ROUTER_WRT300NV11: |
|---|
| 3938 | ses_gpio = 0x105; |
|---|
| 3939 | // diag_gpio = 0x11; //power led blink / off to indicate fac.def. |
|---|
| 3940 | break; |
|---|
| 3941 | case ROUTER_WRT310N: |
|---|
| 3942 | connected_gpio = 0x103; //ses orange |
|---|
| 3943 | power_gpio = 0x001; |
|---|
| 3944 | diag_gpio = 0x101; // power led blink / off to indicate fac.def. |
|---|
| 3945 | ses_gpio = 0x109; // ses blue |
|---|
| 3946 | break; |
|---|
| 3947 | case ROUTER_WRT310NV2: |
|---|
| 3948 | connected_gpio = 0x102; // ses orange |
|---|
| 3949 | power_gpio = 0x001; |
|---|
| 3950 | diag_gpio = 0x101; // power led blink / off to indicate fac.def. |
|---|
| 3951 | ses_gpio = 0x104; // ses blue |
|---|
| 3952 | break; |
|---|
| 3953 | case ROUTER_WRT160N: |
|---|
| 3954 | power_gpio = 0x001; |
|---|
| 3955 | diag_gpio = 0x101; // power led blink / off to indicate fac.def. |
|---|
| 3956 | connected_gpio = 0x103; // ses orange |
|---|
| 3957 | ses_gpio = 0x105; // ses blue |
|---|
| 3958 | break; |
|---|
| 3959 | case ROUTER_WRT160NV3: |
|---|
| 3960 | power_gpio = 0x001; |
|---|
| 3961 | diag_gpio = 0x101; // power led blink / off to indicate fac.def. |
|---|
| 3962 | connected_gpio = 0x102; // ses orange |
|---|
| 3963 | ses_gpio = 0x104; // ses blue |
|---|
| 3964 | break; |
|---|
| 3965 | case ROUTER_LINKSYS_E900: |
|---|
| 3966 | case ROUTER_LINKSYS_E1500: |
|---|
| 3967 | case ROUTER_LINKSYS_E1550: |
|---|
| 3968 | power_gpio = 0x106; |
|---|
| 3969 | diag_gpio = 0x006; // power led blink / off to indicate fac.def. |
|---|
| 3970 | ses_gpio = 0x108; // ses blue |
|---|
| 3971 | break; |
|---|
| 3972 | case ROUTER_LINKSYS_E1000V2: |
|---|
| 3973 | power_gpio = 0x106; |
|---|
| 3974 | diag_gpio = 0x006; // power led blink / off to indicate fac.def. |
|---|
| 3975 | connected_gpio = 0x007; // ses orange |
|---|
| 3976 | ses_gpio = 0x008; // ses blue |
|---|
| 3977 | break; |
|---|
| 3978 | case ROUTER_LINKSYS_E2500: |
|---|
| 3979 | case ROUTER_LINKSYS_E3200: |
|---|
| 3980 | power_gpio = 0x103; |
|---|
| 3981 | diag_gpio = 0x003; // power led blink / off to indicate fac.def. |
|---|
| 3982 | break; |
|---|
| 3983 | case ROUTER_LINKSYS_E4200: |
|---|
| 3984 | power_gpio = 0x105; // white LED1 |
|---|
| 3985 | diag_gpio = 0x005; // power led blink / off to indicate fac.def. |
|---|
| 3986 | connected_gpio = 0x103; // white LED2 |
|---|
| 3987 | break; |
|---|
| 3988 | case ROUTER_ASUS_WL500G: |
|---|
| 3989 | power_gpio = 0x100; |
|---|
| 3990 | diag_gpio = 0x000; // power led blink /off to indicate factory |
|---|
| 3991 | // defaults |
|---|
| 3992 | break; |
|---|
| 3993 | case ROUTER_ASUS_WL500W: |
|---|
| 3994 | power_gpio = 0x105; |
|---|
| 3995 | diag_gpio = 0x005; // power led blink /off to indicate factory |
|---|
| 3996 | // defaults |
|---|
| 3997 | break; |
|---|
| 3998 | case ROUTER_LINKSYS_WTR54GS: |
|---|
| 3999 | diag_gpio = 0x001; |
|---|
| 4000 | break; |
|---|
| 4001 | case ROUTER_WAP54G_V1: |
|---|
| 4002 | diag_gpio = 0x103; |
|---|
| 4003 | wlan0_gpio = 0x104; // LINK led |
|---|
| 4004 | break; |
|---|
| 4005 | case ROUTER_WAP54G_V3: |
|---|
| 4006 | ses_gpio = 0x10c; |
|---|
| 4007 | connected_gpio = 0x006; |
|---|
| 4008 | break; |
|---|
| 4009 | case ROUTER_NETGEAR_WNR834BV2: |
|---|
| 4010 | power_gpio = 0x002; |
|---|
| 4011 | diag_gpio = 0x003; // power led amber |
|---|
| 4012 | connected_gpio = 0x007; // WAN led green |
|---|
| 4013 | break; |
|---|
| 4014 | case ROUTER_NETGEAR_WNDR3300: |
|---|
| 4015 | power_gpio = 0x005; |
|---|
| 4016 | diag_gpio = 0x105; // power led blink /off to indicate factory defaults |
|---|
| 4017 | connected_gpio = 0x007; // WAN led green |
|---|
| 4018 | break; |
|---|
| 4019 | case ROUTER_ASKEY_RT220XD: |
|---|
| 4020 | wlan0_gpio = 0x100; |
|---|
| 4021 | dmz_gpio = 0x101; // not soldered |
|---|
| 4022 | break; |
|---|
| 4023 | case ROUTER_WRT610N: |
|---|
| 4024 | power_gpio = 0x001; |
|---|
| 4025 | connected_gpio = 0x103; // ses amber |
|---|
| 4026 | ses_gpio = 0x109; // ses blue |
|---|
| 4027 | usb_gpio = 0x100; |
|---|
| 4028 | break; |
|---|
| 4029 | case ROUTER_WRT610NV2: |
|---|
| 4030 | power_gpio = 0x005; |
|---|
| 4031 | connected_gpio = 0x100; // ses amber |
|---|
| 4032 | ses_gpio = 0x103; // ses blue |
|---|
| 4033 | usb_gpio = 0x007; |
|---|
| 4034 | break; |
|---|
| 4035 | case ROUTER_USR_5461: |
|---|
| 4036 | usb_gpio = 0x001; |
|---|
| 4037 | break; |
|---|
| 4038 | case ROUTER_USR_5465: |
|---|
| 4039 | //usb_gpio = 0x002; //or 0x001 ?? |
|---|
| 4040 | break; |
|---|
| 4041 | case ROUTER_NETGEAR_WGR614L: |
|---|
| 4042 | case ROUTER_NETGEAR_WGR614V9: |
|---|
| 4043 | // power_gpio = 0x107; // don't use - resets router |
|---|
| 4044 | diag_gpio = 0x006; |
|---|
| 4045 | connected_gpio = 0x104; |
|---|
| 4046 | break; |
|---|
| 4047 | case ROUTER_NETGEAR_WG602_V4: |
|---|
| 4048 | power_gpio = 0x101; // trick: make lan led green for 100Mbps |
|---|
| 4049 | break; |
|---|
| 4050 | case ROUTER_BELKIN_F5D7231_V2000: |
|---|
| 4051 | connected_gpio = 0x104; |
|---|
| 4052 | diag_gpio = 0x001; // power led blink /off to indicate factory defaults |
|---|
| 4053 | break; |
|---|
| 4054 | case ROUTER_NETGEAR_WNR3500L: |
|---|
| 4055 | power_gpio = 0x003; //power led green |
|---|
| 4056 | diag_gpio = 0x007; // power led amber |
|---|
| 4057 | ses_gpio = 0x001; // WPS led green |
|---|
| 4058 | connected_gpio = 0x002; //wan led green |
|---|
| 4059 | break; |
|---|
| 4060 | case ROUTER_NETGEAR_WNDR3400: |
|---|
| 4061 | power_gpio = 0x003; //power led green |
|---|
| 4062 | diag_gpio = 0x007; // power led amber |
|---|
| 4063 | connected_gpio = 0x001; //wan led green |
|---|
| 4064 | usb_gpio = 0x102; //usb led green |
|---|
| 4065 | wlan1_gpio = 0x000; // radio 1 led blue |
|---|
| 4066 | break; |
|---|
| 4067 | case ROUTER_NETGEAR_WNDR4000: |
|---|
| 4068 | power_gpio = 0x000; //power led green |
|---|
| 4069 | diag_gpio = 0x001; // power led amber |
|---|
| 4070 | connected_gpio = 0x002; //wan led green |
|---|
| 4071 | wlan0_gpio = 0x003; //radio 0 led green |
|---|
| 4072 | wlan1_gpio = 0x004; // radio 1 led blue |
|---|
| 4073 | usb_gpio = 0x005; //usb led green |
|---|
| 4074 | ses_gpio = 0x106; // WPS led green - inverse |
|---|
| 4075 | ses2_gpio = 0x107; // WLAN led green - inverse |
|---|
| 4076 | break; |
|---|
| 4077 | case ROUTER_NETGEAR_WNR2000V2: |
|---|
| 4078 | //power_gpio = ??; |
|---|
| 4079 | diag_gpio = 0x002; |
|---|
| 4080 | ses_gpio = 0x007; //WPS led |
|---|
| 4081 | connected_gpio = 0x006; |
|---|
| 4082 | break; |
|---|
| 4083 | case ROUTER_WRT320N: |
|---|
| 4084 | power_gpio = 0x002; //power/diag (disabled=blink) |
|---|
| 4085 | ses_gpio = 0x103; // ses blue |
|---|
| 4086 | connected_gpio = 0x104; //ses orange |
|---|
| 4087 | break; |
|---|
| 4088 | case ROUTER_ASUS_RTN12: |
|---|
| 4089 | power_gpio = 0x102; |
|---|
| 4090 | diag_gpio = 0x002; // power blink |
|---|
| 4091 | break; |
|---|
| 4092 | case ROUTER_BOARD_NEPTUNE: |
|---|
| 4093 | // usb_gpio = 0x108; |
|---|
| 4094 | // 0x10c //unknown gpio label, use as diag |
|---|
| 4095 | diag_gpio = 0x10c; |
|---|
| 4096 | break; |
|---|
| 4097 | case ROUTER_ASUS_RTN10U: |
|---|
| 4098 | ses_gpio = 0x007; |
|---|
| 4099 | usb_gpio = 0x008; |
|---|
| 4100 | break; |
|---|
| 4101 | case ROUTER_ASUS_RTN12B: |
|---|
| 4102 | connected_gpio = 0x105; |
|---|
| 4103 | break; |
|---|
| 4104 | case ROUTER_ASUS_RTN10: |
|---|
| 4105 | case ROUTER_ASUS_RTN16: |
|---|
| 4106 | case ROUTER_NETCORE_NW618: |
|---|
| 4107 | power_gpio = 0x101; |
|---|
| 4108 | diag_gpio = 0x001; // power blink |
|---|
| 4109 | break; |
|---|
| 4110 | case ROUTER_BELKIN_F7D3301: |
|---|
| 4111 | case ROUTER_BELKIN_F7D3302: |
|---|
| 4112 | case ROUTER_BELKIN_F7D4301: |
|---|
| 4113 | case ROUTER_BELKIN_F7D4302: |
|---|
| 4114 | power_gpio = 0x10a; // green |
|---|
| 4115 | diag_gpio = 0x10b; // red |
|---|
| 4116 | ses_gpio = 0x10d; // wps orange |
|---|
| 4117 | break; |
|---|
| 4118 | case ROUTER_DYNEX_DX_NRUTER: |
|---|
| 4119 | power_gpio = 0x001; |
|---|
| 4120 | diag_gpio = 0x101; // power blink |
|---|
| 4121 | connected_gpio = 0x100; |
|---|
| 4122 | sec0_gpio = 0x103; |
|---|
| 4123 | break; |
|---|
| 4124 | #endif |
|---|
| 4125 | } |
|---|
| 4126 | if (type == LED_DIAG && v1func == 1) { |
|---|
| 4127 | if (act == LED_ON) |
|---|
| 4128 | C_led(1); |
|---|
| 4129 | else |
|---|
| 4130 | C_led(0); |
|---|
| 4131 | } |
|---|
| 4132 | |
|---|
| 4133 | switch (type) { |
|---|
| 4134 | case LED_POWER: |
|---|
| 4135 | use_gpio = power_gpio; |
|---|
| 4136 | break; |
|---|
| 4137 | case USB_POWER: |
|---|
| 4138 | use_gpio = usb_power; |
|---|
| 4139 | break; |
|---|
| 4140 | case LED_DIAG: |
|---|
| 4141 | use_gpio = diag_gpio; |
|---|
| 4142 | break; |
|---|
| 4143 | case LED_DMZ: |
|---|
| 4144 | use_gpio = dmz_gpio; |
|---|
| 4145 | break; |
|---|
| 4146 | case LED_CONNECTED: |
|---|
| 4147 | if (act == LED_ON) |
|---|
| 4148 | led_control(LED_DISCONNECTED, LED_OFF); |
|---|
| 4149 | else |
|---|
| 4150 | led_control(LED_DISCONNECTED, LED_ON); |
|---|
| 4151 | use_gpio = connblue ? ses_gpio : connected_gpio; |
|---|
| 4152 | break; |
|---|
| 4153 | case LED_DISCONNECTED: |
|---|
| 4154 | use_gpio = disconnected_gpio; |
|---|
| 4155 | break; |
|---|
| 4156 | case LED_BRIDGE: |
|---|
| 4157 | use_gpio = bridge_gpio; |
|---|
| 4158 | break; |
|---|
| 4159 | case LED_VPN: |
|---|
| 4160 | use_gpio = vpn_gpio; |
|---|
| 4161 | break; |
|---|
| 4162 | case LED_SES: |
|---|
| 4163 | use_gpio = connblue ? connected_gpio : ses_gpio; |
|---|
| 4164 | break; |
|---|
| 4165 | case LED_SES2: |
|---|
| 4166 | use_gpio = ses2_gpio; |
|---|
| 4167 | break; |
|---|
| 4168 | case LED_WLAN0: |
|---|
| 4169 | use_gpio = wlan0_gpio; |
|---|
| 4170 | break; |
|---|
| 4171 | case LED_WLAN1: |
|---|
| 4172 | use_gpio = wlan1_gpio; |
|---|
| 4173 | break; |
|---|
| 4174 | case LED_USB: |
|---|
| 4175 | use_gpio = usb_gpio; |
|---|
| 4176 | break; |
|---|
| 4177 | case LED_SEC0: |
|---|
| 4178 | use_gpio = sec0_gpio; |
|---|
| 4179 | break; |
|---|
| 4180 | case LED_SEC1: |
|---|
| 4181 | use_gpio = sec1_gpio; |
|---|
| 4182 | break; |
|---|
| 4183 | } |
|---|
| 4184 | if ((use_gpio & 0x0ff) != 0x0ff) { |
|---|
| 4185 | gpio_value = use_gpio & 0x0ff; |
|---|
| 4186 | enable = (use_gpio & 0x100) == 0 ? 1 : 0; |
|---|
| 4187 | disable = (use_gpio & 0x100) == 0 ? 0 : 1; |
|---|
| 4188 | switch (act) { |
|---|
| 4189 | case LED_ON: |
|---|
| 4190 | set_gpio(gpio_value, enable); |
|---|
| 4191 | break; |
|---|
| 4192 | case LED_OFF: |
|---|
| 4193 | set_gpio(gpio_value, disable); |
|---|
| 4194 | break; |
|---|
| 4195 | case LED_FLASH: // will lit the led for 1 sec. |
|---|
| 4196 | set_gpio(gpio_value, enable); |
|---|
| 4197 | sleep(1); |
|---|
| 4198 | set_gpio(gpio_value, disable); |
|---|
| 4199 | break; |
|---|
| 4200 | } |
|---|
| 4201 | } |
|---|
| 4202 | return 1; |
|---|
| 4203 | |
|---|
| 4204 | #endif |
|---|
| 4205 | } |
|---|
| 4206 | |
|---|
| 4207 | int file_to_buf(char *path, char *buf, int len) |
|---|
| 4208 | { |
|---|
| 4209 | FILE *fp; |
|---|
| 4210 | |
|---|
| 4211 | memset(buf, 0, len); |
|---|
| 4212 | |
|---|
| 4213 | if ((fp = fopen(path, "r"))) { |
|---|
| 4214 | fgets(buf, len, fp); |
|---|
| 4215 | fclose(fp); |
|---|
| 4216 | return 1; |
|---|
| 4217 | } |
|---|
| 4218 | |
|---|
| 4219 | return 0; |
|---|
| 4220 | } |
|---|
| 4221 | |
|---|
| 4222 | int ishexit(char c) |
|---|
| 4223 | { |
|---|
| 4224 | |
|---|
| 4225 | if (strchr("01234567890abcdefABCDEF", c) != (char *)0) |
|---|
| 4226 | return 1; |
|---|
| 4227 | |
|---|
| 4228 | return 0; |
|---|
| 4229 | } |
|---|
| 4230 | |
|---|
| 4231 | int getMTD(char *name) |
|---|
| 4232 | { |
|---|
| 4233 | char buf[128]; |
|---|
| 4234 | int device; |
|---|
| 4235 | |
|---|
| 4236 | sprintf(buf, "cat /proc/mtd|grep \"%s\"", name); |
|---|
| 4237 | FILE *fp = popen(buf, "rb"); |
|---|
| 4238 | |
|---|
| 4239 | fscanf(fp, "%s", &buf[0]); |
|---|
| 4240 | device = buf[3] - '0'; |
|---|
| 4241 | pclose(fp); |
|---|
| 4242 | return device; |
|---|
| 4243 | } |
|---|
| 4244 | |
|---|
| 4245 | int insmod(char *module) |
|---|
| 4246 | { |
|---|
| 4247 | return eval("insmod", module); |
|---|
| 4248 | } |
|---|
| 4249 | |
|---|
| 4250 | void rmmod(char *module) |
|---|
| 4251 | { |
|---|
| 4252 | eval("rmmod", module); |
|---|
| 4253 | } |
|---|
| 4254 | |
|---|
| 4255 | #include "revision.h" |
|---|
| 4256 | |
|---|
| 4257 | char *getSoftwareRevision(void) |
|---|
| 4258 | { |
|---|
| 4259 | return "" SVN_REVISION ""; |
|---|
| 4260 | } |
|---|
| 4261 | |
|---|
| 4262 | #ifdef HAVE_OLED |
|---|
| 4263 | void initlcd() |
|---|
| 4264 | { |
|---|
| 4265 | |
|---|
| 4266 | } |
|---|
| 4267 | |
|---|
| 4268 | void lcdmessage(char *message) |
|---|
| 4269 | { |
|---|
| 4270 | eval("oled-print", "DD-WRT v24 sp2", "build:" SVN_REVISION, |
|---|
| 4271 | "3G/UMTS Router", message); |
|---|
| 4272 | } |
|---|
| 4273 | |
|---|
| 4274 | void lcdmessaged(char *dual, char *message) |
|---|
| 4275 | { |
|---|
| 4276 | |
|---|
| 4277 | } |
|---|
| 4278 | |
|---|
| 4279 | #endif |
|---|
| 4280 | |
|---|
| 4281 | #if 0 |
|---|
| 4282 | |
|---|
| 4283 | static int fd; |
|---|
| 4284 | |
|---|
| 4285 | void SetEnvironment() |
|---|
| 4286 | { |
|---|
| 4287 | system("stty ispeed 2400 < /dev/tts/1"); |
|---|
| 4288 | system("stty raw < /dev/tts/1"); |
|---|
| 4289 | } |
|---|
| 4290 | |
|---|
| 4291 | int Cmd = 254; /* EZIO Command */ |
|---|
| 4292 | int cls = 1; /* Clear screen */ |
|---|
| 4293 | void Cls() |
|---|
| 4294 | { |
|---|
| 4295 | write(fd, &Cmd, 1); |
|---|
| 4296 | write(fd, &cls, 1); |
|---|
| 4297 | } |
|---|
| 4298 | |
|---|
| 4299 | int init = 0x28; |
|---|
| 4300 | void Init() |
|---|
| 4301 | { |
|---|
| 4302 | write(fd, &Cmd, 1); |
|---|
| 4303 | write(fd, &init, 1); |
|---|
| 4304 | } |
|---|
| 4305 | |
|---|
| 4306 | int stopsend = 0x37; |
|---|
| 4307 | void StopSend() |
|---|
| 4308 | { |
|---|
| 4309 | write(fd, &Cmd, 1); |
|---|
| 4310 | write(fd, &init, 1); |
|---|
| 4311 | } |
|---|
| 4312 | |
|---|
| 4313 | int home = 2; /* Home cursor */ |
|---|
| 4314 | void Home() |
|---|
| 4315 | { |
|---|
| 4316 | write(fd, &Cmd, 1); |
|---|
| 4317 | write(fd, &home, 1); |
|---|
| 4318 | } |
|---|
| 4319 | |
|---|
| 4320 | int readkey = 6; /* Read key */ |
|---|
| 4321 | void ReadKey() |
|---|
| 4322 | { |
|---|
| 4323 | write(fd, &Cmd, 1); |
|---|
| 4324 | write(fd, &readkey, 1); |
|---|
| 4325 | } |
|---|
| 4326 | |
|---|
| 4327 | int blank = 8; /* Blank display */ |
|---|
| 4328 | void Blank() |
|---|
| 4329 | { |
|---|
| 4330 | write(fd, &Cmd, 1); |
|---|
| 4331 | write(fd, &blank, 1); |
|---|
| 4332 | } |
|---|
| 4333 | |
|---|
| 4334 | int hide = 12; /* Hide cursor & display blanked characters */ |
|---|
| 4335 | void Hide() |
|---|
| 4336 | { |
|---|
| 4337 | write(fd, &Cmd, 1); |
|---|
| 4338 | write(fd, &hide, 1); |
|---|
| 4339 | } |
|---|
| 4340 | |
|---|
| 4341 | int turn = 13; /* Turn On (blinking block cursor) */ |
|---|
| 4342 | void TurnOn() |
|---|
| 4343 | { |
|---|
| 4344 | write(fd, &Cmd, 1); |
|---|
| 4345 | write(fd, &turn, 1); |
|---|
| 4346 | } |
|---|
| 4347 | |
|---|
| 4348 | int show = 14; /* Show underline cursor */ |
|---|
| 4349 | void Show() |
|---|
| 4350 | { |
|---|
| 4351 | write(fd, &Cmd, 1); |
|---|
| 4352 | write(fd, &show, 1); |
|---|
| 4353 | } |
|---|
| 4354 | |
|---|
| 4355 | int movel = 16; /* Move cursor 1 character left */ |
|---|
| 4356 | void MoveL() |
|---|
| 4357 | { |
|---|
| 4358 | write(fd, &Cmd, 1); |
|---|
| 4359 | write(fd, &movel, 1); |
|---|
| 4360 | } |
|---|
| 4361 | |
|---|
| 4362 | int mover = 20; /* Move cursor 1 character right */ |
|---|
| 4363 | void MoveR() |
|---|
| 4364 | { |
|---|
| 4365 | write(fd, &Cmd, 1); |
|---|
| 4366 | write(fd, &mover, 1); |
|---|
| 4367 | } |
|---|
| 4368 | |
|---|
| 4369 | int scl = 24; /* Scroll cursor 1 character left */ |
|---|
| 4370 | void ScrollL() |
|---|
| 4371 | { |
|---|
| 4372 | write(fd, &Cmd, 1); |
|---|
| 4373 | write(fd, &scl, 1); |
|---|
| 4374 | } |
|---|
| 4375 | |
|---|
| 4376 | int scr = 28; /* Scroll cursor 1 character right */ |
|---|
| 4377 | void ScrollR() |
|---|
| 4378 | { |
|---|
| 4379 | write(fd, &Cmd, 1); |
|---|
| 4380 | write(fd, &scr, 1); |
|---|
| 4381 | } |
|---|
| 4382 | |
|---|
| 4383 | int setdis = 64; /* Command */ |
|---|
| 4384 | void SetDis() |
|---|
| 4385 | { |
|---|
| 4386 | write(fd, &Cmd, 1); |
|---|
| 4387 | write(fd, &setdis, 1); |
|---|
| 4388 | |
|---|
| 4389 | } |
|---|
| 4390 | |
|---|
| 4391 | int a, b; |
|---|
| 4392 | void ShowMessage(char *str1, char *str2) |
|---|
| 4393 | { |
|---|
| 4394 | char nul[] = " "; |
|---|
| 4395 | |
|---|
| 4396 | a = strlen(str1); |
|---|
| 4397 | b = 40 - a; |
|---|
| 4398 | write(fd, str1, a); |
|---|
| 4399 | write(fd, nul, b); |
|---|
| 4400 | write(fd, str2, strlen(str2)); |
|---|
| 4401 | } |
|---|
| 4402 | |
|---|
| 4403 | void initlcd() |
|---|
| 4404 | { |
|---|
| 4405 | |
|---|
| 4406 | fd = open("/dev/tts/1", O_RDWR); |
|---|
| 4407 | |
|---|
| 4408 | /** Open Serial port (COM2) */ |
|---|
| 4409 | if (fd > 0) { |
|---|
| 4410 | close(fd); |
|---|
| 4411 | SetEnvironment(); /* Set RAW mode */ |
|---|
| 4412 | fd = open("/dev/tts/1", O_RDWR); |
|---|
| 4413 | Init(); /* Initialize EZIO twice */ |
|---|
| 4414 | Init(); |
|---|
| 4415 | |
|---|
| 4416 | Cls(); /* Clear screen */ |
|---|
| 4417 | } |
|---|
| 4418 | close(fd); |
|---|
| 4419 | } |
|---|
| 4420 | |
|---|
| 4421 | void lcdmessage(char *message) |
|---|
| 4422 | { |
|---|
| 4423 | |
|---|
| 4424 | fd = open("/dev/tts/1", O_RDWR); |
|---|
| 4425 | /** Open Serial port (COM2) */ |
|---|
| 4426 | |
|---|
| 4427 | if (fd > 0) { |
|---|
| 4428 | Init(); /* Initialize EZIO twice */ |
|---|
| 4429 | Init(); |
|---|
| 4430 | SetDis(); |
|---|
| 4431 | Cls(); |
|---|
| 4432 | Home(); |
|---|
| 4433 | ShowMessage("State", message); |
|---|
| 4434 | close(fd); |
|---|
| 4435 | } |
|---|
| 4436 | } |
|---|
| 4437 | |
|---|
| 4438 | void lcdmessaged(char *dual, char *message) |
|---|
| 4439 | { |
|---|
| 4440 | |
|---|
| 4441 | fd = open("/dev/tts/1", O_RDWR); |
|---|
| 4442 | |
|---|
| 4443 | /** Open Serial port (COM2) */ |
|---|
| 4444 | |
|---|
| 4445 | if (fd > 0) { |
|---|
| 4446 | Init(); /* Initialize EZIO twice */ |
|---|
| 4447 | Init(); |
|---|
| 4448 | SetDis(); |
|---|
| 4449 | Cls(); /* Clear screen */ |
|---|
| 4450 | Home(); |
|---|
| 4451 | ShowMessage(dual, message); |
|---|
| 4452 | close(fd); |
|---|
| 4453 | } |
|---|
| 4454 | } |
|---|
| 4455 | |
|---|
| 4456 | #endif |
|---|
| 4457 | static int i64c(int i) |
|---|
| 4458 | { |
|---|
| 4459 | i &= 0x3f; |
|---|
| 4460 | if (i == 0) |
|---|
| 4461 | return '.'; |
|---|
| 4462 | if (i == 1) |
|---|
| 4463 | return '/'; |
|---|
| 4464 | if (i < 12) |
|---|
| 4465 | return ('0' - 2 + i); |
|---|
| 4466 | if (i < 38) |
|---|
| 4467 | return ('A' - 12 + i); |
|---|
| 4468 | return ('a' - 38 + i); |
|---|
| 4469 | } |
|---|
| 4470 | |
|---|
| 4471 | int crypt_make_salt(char *p, int cnt, int x) |
|---|
| 4472 | { |
|---|
| 4473 | x += getpid() + time(NULL); |
|---|
| 4474 | do { |
|---|
| 4475 | /* |
|---|
| 4476 | * x = (x*1664525 + 1013904223) % 2^32 generator is lame (low-order |
|---|
| 4477 | * bit is not "random", etc...), but for our purposes it is good |
|---|
| 4478 | * enough |
|---|
| 4479 | */ |
|---|
| 4480 | x = x * 1664525 + 1013904223; |
|---|
| 4481 | /* |
|---|
| 4482 | * BTW, Park and Miller's "minimal standard generator" is x = x*16807 |
|---|
| 4483 | * % ((2^31)-1) It has no problem with visibly alternating lowest bit |
|---|
| 4484 | * but is also weak in cryptographic sense + needs div, which needs |
|---|
| 4485 | * more code (and slower) on many CPUs |
|---|
| 4486 | */ |
|---|
| 4487 | *p++ = i64c(x >> 16); |
|---|
| 4488 | *p++ = i64c(x >> 22); |
|---|
| 4489 | } |
|---|
| 4490 | while (--cnt); |
|---|
| 4491 | *p = '\0'; |
|---|
| 4492 | return x; |
|---|
| 4493 | } |
|---|
| 4494 | |
|---|
| 4495 | #include <crypt.h> |
|---|
| 4496 | #define MD5_OUT_BUFSIZE 36 |
|---|
| 4497 | |
|---|
| 4498 | char *zencrypt(char *passwd) |
|---|
| 4499 | { |
|---|
| 4500 | char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */ |
|---|
| 4501 | static char passout[MD5_OUT_BUFSIZE]; |
|---|
| 4502 | |
|---|
| 4503 | strcpy(salt, "$1$"); |
|---|
| 4504 | crypt_make_salt(salt + 3, 4, 0); |
|---|
| 4505 | strcpy(passout, crypt((unsigned char *)passwd, (unsigned char *)salt)); |
|---|
| 4506 | return passout; |
|---|
| 4507 | } |
|---|
| 4508 | |
|---|
| 4509 | int has_gateway(void) |
|---|
| 4510 | { |
|---|
| 4511 | if (nvram_match("wk_mode", "gateway")) |
|---|
| 4512 | return 1; |
|---|
| 4513 | if (nvram_match("wk_mode", "olsr") && nvram_match("olsrd_gateway", "1")) |
|---|
| 4514 | return 1; |
|---|
| 4515 | return 0; |
|---|
| 4516 | } |
|---|
| 4517 | |
|---|
| 4518 | #ifdef HAVE_ATH9K |
|---|
| 4519 | int getath9kdevicecount(void) |
|---|
| 4520 | { |
|---|
| 4521 | glob_t globbuf; |
|---|
| 4522 | int globresult; |
|---|
| 4523 | int count = 0; |
|---|
| 4524 | #ifndef HAVE_MADWIFI_MIMO |
|---|
| 4525 | if (1) { |
|---|
| 4526 | #else |
|---|
| 4527 | if (nvram_match("mimo_driver", "ath9k")) { |
|---|
| 4528 | #endif |
|---|
| 4529 | globresult = |
|---|
| 4530 | glob("/sys/class/ieee80211/phy*", GLOB_NOSORT, NULL, |
|---|
| 4531 | &globbuf); |
|---|
| 4532 | if (globresult == 0) |
|---|
| 4533 | count = (int)globbuf.gl_pathc; |
|---|
| 4534 | globfree(&globbuf); |
|---|
| 4535 | } |
|---|
| 4536 | return (count); |
|---|
| 4537 | } |
|---|
| 4538 | |
|---|
| 4539 | int get_ath9k_phy_idx(int idx) |
|---|
| 4540 | { |
|---|
| 4541 | // fprintf(stderr,"channel number %d of %d\n", i,achans.ic_nchans); |
|---|
| 4542 | return idx - getifcount("wifi"); |
|---|
| 4543 | } |
|---|
| 4544 | |
|---|
| 4545 | int is_ath9k(const char *prefix) |
|---|
| 4546 | { |
|---|
| 4547 | glob_t globbuf; |
|---|
| 4548 | int count = 0; |
|---|
| 4549 | char globstring[1024]; |
|---|
| 4550 | int globresult; |
|---|
| 4551 | int devnum; |
|---|
| 4552 | // get legacy interface count |
|---|
| 4553 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 4554 | if (!nvram_match("mimo_driver", "ath9k")) |
|---|
| 4555 | return (0); |
|---|
| 4556 | #endif |
|---|
| 4557 | if (!sscanf(prefix, "ath%d", &devnum)) |
|---|
| 4558 | return (0); |
|---|
| 4559 | // correct index if there are legacy cards arround |
|---|
| 4560 | devnum = get_ath9k_phy_idx(devnum); |
|---|
| 4561 | sprintf(globstring, "/sys/class/ieee80211/phy%d", devnum); |
|---|
| 4562 | globresult = glob(globstring, GLOB_NOSORT, NULL, &globbuf); |
|---|
| 4563 | if (globresult == 0) |
|---|
| 4564 | count = (int)globbuf.gl_pathc; |
|---|
| 4565 | globfree(&globbuf); |
|---|
| 4566 | return (count); |
|---|
| 4567 | } |
|---|
| 4568 | #endif |
|---|
| 4569 | |
|---|
| 4570 | double HTTxRate20_800(unsigned int index) |
|---|
| 4571 | { |
|---|
| 4572 | static const double vHTTxRate20_800[24] = |
|---|
| 4573 | { 6.5, 13.0, 19.5, 26.0, 39.0, 52.0, 58.5, 65.0, 13.0, 26.0, 39.0, |
|---|
| 4574 | 52.0, 78.0, 104.0, 117.0, 130.0, |
|---|
| 4575 | 19.5, 39.0, 58.5, 78.0, 117.0, 156.0, 175.5, 195.0 |
|---|
| 4576 | }; |
|---|
| 4577 | if (index > sizeof(HTTxRate20_800) / sizeof(double) - 1) { |
|---|
| 4578 | fprintf(stderr, "utils.c HTTxRate20_800() index overflow\n"); |
|---|
| 4579 | return 0.0; |
|---|
| 4580 | } |
|---|
| 4581 | return vHTTxRate20_800[index]; |
|---|
| 4582 | } |
|---|
| 4583 | |
|---|
| 4584 | double HTTxRate20_400(unsigned int index) |
|---|
| 4585 | { |
|---|
| 4586 | static const double vHTTxRate20_400[24] = |
|---|
| 4587 | { 7.2, 14.4, 21.7, 28.9, 43.3, 57.8, 65.0, 72.2, 14.444, 28.889, |
|---|
| 4588 | 43.333, 57.778, 86.667, 115.556, 130.000, 144.444, |
|---|
| 4589 | 21.7, 43.3, 65.0, 86.7, 130.0, 173.3, 195.0, 216.7 |
|---|
| 4590 | }; |
|---|
| 4591 | if (index > sizeof(vHTTxRate20_400) / sizeof(double) - 1) { |
|---|
| 4592 | fprintf(stderr, "utils.c HTTxRate20_400() index overflow\n"); |
|---|
| 4593 | return 0.0; |
|---|
| 4594 | } |
|---|
| 4595 | return vHTTxRate20_400[index]; |
|---|
| 4596 | } |
|---|
| 4597 | |
|---|
| 4598 | double HTTxRate40_800(unsigned int index) |
|---|
| 4599 | { |
|---|
| 4600 | static const double vHTTxRate40_800[25] = |
|---|
| 4601 | { 13.5, 27.0, 40.5, 54.0, 81.0, 108.0, 121.5, 135.0, 27.0, 54.0, |
|---|
| 4602 | 81.0, 108.0, 162.0, 216.0, 243.0, 270.0, |
|---|
| 4603 | 40.5, 81.0, 121.5, 162.0, 243.0, 324.0, 364.5, 405.0, 6.0 |
|---|
| 4604 | }; |
|---|
| 4605 | if (index > sizeof(vHTTxRate40_800) / sizeof(double) - 1) { |
|---|
| 4606 | fprintf(stderr, "utils.c HTTxRate40_800() index overflow\n"); |
|---|
| 4607 | return 0.0; |
|---|
| 4608 | } |
|---|
| 4609 | return vHTTxRate40_800[index]; |
|---|
| 4610 | } |
|---|
| 4611 | |
|---|
| 4612 | double HTTxRate40_400(unsigned int index) |
|---|
| 4613 | { |
|---|
| 4614 | static const double vHTTxRate40_400[25] = |
|---|
| 4615 | { 15.0, 30.0, 45.0, 60.0, 90.0, 120.0, 135.0, 150.0, 30.0, 60.0, |
|---|
| 4616 | 90.0, 120.0, 180.0, 240.0, 270.0, 300.0, |
|---|
| 4617 | 45.0, 90.0, 135.0, 180.0, 270.0, 360.0, 405.0, 450.0, 6.7 |
|---|
| 4618 | }; |
|---|
| 4619 | if (index > sizeof(vHTTxRate40_400) / sizeof(double) - 1) { |
|---|
| 4620 | fprintf(stderr, "utils.c HTTxRate40_400() index overflow\n"); |
|---|
| 4621 | return 0.0; |
|---|
| 4622 | } |
|---|
| 4623 | return vHTTxRate40_400[index]; |
|---|
| 4624 | } |
|---|
| 4625 | |
|---|
| 4626 | |
|---|
| 4627 | int writeproc(char *path,char *value) |
|---|
| 4628 | { |
|---|
| 4629 | FILE *fp; |
|---|
| 4630 | fp = fopen(path,"wb"); |
|---|
| 4631 | if (fp==NULL) { |
|---|
| 4632 | return -1; |
|---|
| 4633 | } |
|---|
| 4634 | fprintf(fp,value); |
|---|
| 4635 | fclose(fp); |
|---|
| 4636 | return 0; |
|---|
| 4637 | } |
|---|
| 4638 | |
|---|
| 4639 | int writevaproc(char *value, char *fmt,...) |
|---|
| 4640 | { |
|---|
| 4641 | char varbuf[256]; |
|---|
| 4642 | va_list args; |
|---|
| 4643 | |
|---|
| 4644 | va_start(args, (char *)fmt); |
|---|
| 4645 | vsnprintf(varbuf, sizeof(varbuf), fmt, args); |
|---|
| 4646 | va_end(args); |
|---|
| 4647 | return writeproc(varbuf,value);; |
|---|
| 4648 | |
|---|
| 4649 | } |
|---|
| 4650 | /* gartarp */ |
|---|
| 4651 | |
|---|
| 4652 | struct arph { |
|---|
| 4653 | uint16_t hw_type; |
|---|
| 4654 | |
|---|
| 4655 | #define ARPHDR_ETHER 1 |
|---|
| 4656 | |
|---|
| 4657 | uint16_t proto_type; |
|---|
| 4658 | |
|---|
| 4659 | char ha_len; |
|---|
| 4660 | char pa_len; |
|---|
| 4661 | |
|---|
| 4662 | #define ARPOP_BROADCAST 1 |
|---|
| 4663 | #define ARPOP_REPLY 2 |
|---|
| 4664 | uint16_t opcode; |
|---|
| 4665 | char source_add[ETH_ALEN]; |
|---|
| 4666 | char source_ip[IP_ALEN]; |
|---|
| 4667 | char dest_add[ETH_ALEN]; |
|---|
| 4668 | char dest_ip[IP_ALEN]; |
|---|
| 4669 | |
|---|
| 4670 | } __attribute__((packed)); |
|---|
| 4671 | |
|---|
| 4672 | #define ARP_HLEN sizeof(struct arph) + ETH_HLEN |
|---|
| 4673 | #define BCAST "\xff\xff\xff\xff\xff\xff" |
|---|
| 4674 | |
|---|
| 4675 | static inline int get_iface_attr(int sk, char *iface, char *hw, char *paddr) |
|---|
| 4676 | { |
|---|
| 4677 | int ret; |
|---|
| 4678 | struct ifreq ifr; |
|---|
| 4679 | |
|---|
| 4680 | strcpy(ifr.ifr_name, iface); |
|---|
| 4681 | |
|---|
| 4682 | ret = ioctl(sk, SIOCGIFHWADDR, &ifr); |
|---|
| 4683 | if (unlikely(ret == -1)) { |
|---|
| 4684 | perror("ioctl SIOCGIFHWADDR"); |
|---|
| 4685 | return ret; |
|---|
| 4686 | } |
|---|
| 4687 | memcpy(hw, ifr.ifr_hwaddr.sa_data, ETH_ALEN); |
|---|
| 4688 | |
|---|
| 4689 | ret = ioctl(sk, SIOCGIFADDR, &ifr); |
|---|
| 4690 | if (unlikely(ret == -1)) { |
|---|
| 4691 | perror("ioctl SIOCGIFADDR"); |
|---|
| 4692 | return ret; |
|---|
| 4693 | } |
|---|
| 4694 | memcpy(paddr, ifr.ifr_addr.sa_data + 2, IP_ALEN); |
|---|
| 4695 | |
|---|
| 4696 | return ret; |
|---|
| 4697 | } |
|---|
| 4698 | |
|---|
| 4699 | static inline void setup_eth(struct ether_header *eth, char *hw_addr) |
|---|
| 4700 | { |
|---|
| 4701 | memcpy(eth->ether_shost, hw_addr, ETH_ALEN); |
|---|
| 4702 | memcpy(eth->ether_dhost, BCAST, ETH_ALEN); |
|---|
| 4703 | eth->ether_type = htons(ETH_P_ARP); |
|---|
| 4704 | } |
|---|
| 4705 | |
|---|
| 4706 | static inline void setup_garp(struct arph *arp, char *hw_addr, char *paddr) |
|---|
| 4707 | { |
|---|
| 4708 | arp->hw_type = htons(ARPHDR_ETHER); |
|---|
| 4709 | arp->proto_type = htons(ETH_P_IP); |
|---|
| 4710 | arp->ha_len = ETH_ALEN; |
|---|
| 4711 | arp->pa_len = IP_ALEN; |
|---|
| 4712 | |
|---|
| 4713 | memcpy(arp->source_add, hw_addr, ETH_ALEN); |
|---|
| 4714 | memcpy(arp->source_ip, paddr, IP_ALEN); |
|---|
| 4715 | } |
|---|
| 4716 | |
|---|
| 4717 | static inline void setup_garp_broadcast(struct arph *arp, char *paddr) |
|---|
| 4718 | { |
|---|
| 4719 | arp->opcode = htons(ARPOP_BROADCAST); |
|---|
| 4720 | |
|---|
| 4721 | memset(arp->dest_add, 0, ETH_ALEN); |
|---|
| 4722 | memcpy(arp->dest_ip, paddr, IP_ALEN); |
|---|
| 4723 | } |
|---|
| 4724 | |
|---|
| 4725 | static inline void setup_garp_reply(struct arph *arp, char *hw_addr, |
|---|
| 4726 | char *paddr) |
|---|
| 4727 | { |
|---|
| 4728 | arp->opcode = htons(ARPOP_REPLY); |
|---|
| 4729 | |
|---|
| 4730 | memcpy(arp->dest_add, hw_addr, ETH_ALEN); |
|---|
| 4731 | memcpy(arp->dest_ip, paddr, IP_ALEN); |
|---|
| 4732 | } |
|---|
| 4733 | |
|---|
| 4734 | /* |
|---|
| 4735 | * send_garp |
|---|
| 4736 | * |
|---|
| 4737 | * - sends 20 gartuitous arps |
|---|
| 4738 | * in a 200 millisec interval. |
|---|
| 4739 | * One as braadcast and one as reply. |
|---|
| 4740 | * |
|---|
| 4741 | * |
|---|
| 4742 | * parameter iface: sending interface name |
|---|
| 4743 | * |
|---|
| 4744 | * returns false on failure |
|---|
| 4745 | * true on success |
|---|
| 4746 | */ |
|---|
| 4747 | static int send_garp(char *iface) |
|---|
| 4748 | { |
|---|
| 4749 | char pkt[ARP_HLEN]; |
|---|
| 4750 | char iface_hw[ETH_ALEN]; |
|---|
| 4751 | char iface_paddr[IP_ALEN]; |
|---|
| 4752 | struct sockaddr_ll link; |
|---|
| 4753 | struct ether_header *eth; |
|---|
| 4754 | struct arph *arp; |
|---|
| 4755 | int rc; |
|---|
| 4756 | int sk; |
|---|
| 4757 | int n_garps = 10; |
|---|
| 4758 | |
|---|
| 4759 | eth = (struct ether_header *)pkt; |
|---|
| 4760 | arp = (struct arph *)(pkt + ETH_HLEN); |
|---|
| 4761 | |
|---|
| 4762 | sk = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ARP)); |
|---|
| 4763 | if (unlikely(sk == -1)) { |
|---|
| 4764 | perror("socket"); |
|---|
| 4765 | return sk; |
|---|
| 4766 | } |
|---|
| 4767 | |
|---|
| 4768 | rc = get_iface_attr(sk, iface, iface_hw, iface_paddr); |
|---|
| 4769 | if (unlikely(rc == -1)) |
|---|
| 4770 | goto out; |
|---|
| 4771 | |
|---|
| 4772 | /* set link layer information for driver */ |
|---|
| 4773 | memset(&link, 0, sizeof(link)); |
|---|
| 4774 | link.sll_family = AF_PACKET; |
|---|
| 4775 | link.sll_ifindex = if_nametoindex(iface); |
|---|
| 4776 | |
|---|
| 4777 | setup_eth(eth, iface_hw); |
|---|
| 4778 | setup_garp(arp, iface_hw, iface_paddr); |
|---|
| 4779 | |
|---|
| 4780 | while (n_garps--) { |
|---|
| 4781 | setup_garp_broadcast(arp, iface_paddr); |
|---|
| 4782 | rc = sendto(sk, |
|---|
| 4783 | pkt, |
|---|
| 4784 | ARP_HLEN, |
|---|
| 4785 | 0, |
|---|
| 4786 | (struct sockaddr *)&link, sizeof(struct sockaddr_ll) |
|---|
| 4787 | ); |
|---|
| 4788 | if (unlikely(rc == -1)) { |
|---|
| 4789 | perror("sendto"); |
|---|
| 4790 | goto out; |
|---|
| 4791 | } |
|---|
| 4792 | |
|---|
| 4793 | setup_garp_reply(arp, iface_hw, iface_paddr); |
|---|
| 4794 | rc = sendto(sk, |
|---|
| 4795 | pkt, |
|---|
| 4796 | ARP_HLEN, |
|---|
| 4797 | 0, |
|---|
| 4798 | (struct sockaddr *)&link, sizeof(struct sockaddr_ll) |
|---|
| 4799 | ); |
|---|
| 4800 | if (unlikely(rc == -1)) { |
|---|
| 4801 | perror("sendto"); |
|---|
| 4802 | goto out; |
|---|
| 4803 | } |
|---|
| 4804 | usleep(200000); |
|---|
| 4805 | } |
|---|
| 4806 | |
|---|
| 4807 | out: |
|---|
| 4808 | close(sk); |
|---|
| 4809 | return rc; |
|---|
| 4810 | } |
|---|
| 4811 | |
|---|
| 4812 | int gratarp_main(char *iface) |
|---|
| 4813 | { |
|---|
| 4814 | if (iface) { |
|---|
| 4815 | usleep(500000); |
|---|
| 4816 | send_garp(iface); |
|---|
| 4817 | } |
|---|
| 4818 | |
|---|
| 4819 | return 0; |
|---|
| 4820 | } |
|---|
| 4821 | |
|---|
| 4822 | /* NF Mark/Mask |
|---|
| 4823 | * |
|---|
| 4824 | * since multiple services needs a NF packet mark, |
|---|
| 4825 | * we need to use masks to split the 32bit value into several pieces |
|---|
| 4826 | * |
|---|
| 4827 | * 31 23 15 7 0 |
|---|
| 4828 | * port_forwards 1 bit(s) offset 31 > 10000000 00000000 00000000 00000000 |
|---|
| 4829 | * sputnik agent 8 bit(s) offset 23 > 01111111 10000000 00000000 00000000 |
|---|
| 4830 | * quality of service 12 bit(s) offset 11 > 00000000 01111111 11111000 00000000 |
|---|
| 4831 | * |
|---|
| 4832 | * the remaining 11 bits are currently not in use |
|---|
| 4833 | */ |
|---|
| 4834 | |
|---|
| 4835 | struct NF_MASKS { |
|---|
| 4836 | char *service_name; // name of the service |
|---|
| 4837 | int bits_used; // bits used by this service |
|---|
| 4838 | int bit_offset; // position of the fist bit |
|---|
| 4839 | }; |
|---|
| 4840 | |
|---|
| 4841 | static struct NF_MASKS service_masks[] = { |
|---|
| 4842 | {"FORWARD", 1, 31}, |
|---|
| 4843 | {"SPUTNIK", 8, 23}, |
|---|
| 4844 | {"QOS", 12, 11}, |
|---|
| 4845 | }; |
|---|
| 4846 | |
|---|
| 4847 | char * |
|---|
| 4848 | get_NFServiceMark(char *service, uint32 mark) |
|---|
| 4849 | { |
|---|
| 4850 | int x, offset, bitpos; |
|---|
| 4851 | uint32 nfmark = 0, nfmask = 0; |
|---|
| 4852 | |
|---|
| 4853 | static char buffer[24]; |
|---|
| 4854 | |
|---|
| 4855 | for (x=0; x < sizeof(service_masks) / sizeof(struct NF_MASKS); x++) { |
|---|
| 4856 | if (strcmp(service, service_masks[x].service_name) == 0) |
|---|
| 4857 | { |
|---|
| 4858 | if (mark >= (1<<service_masks[x].bits_used)) |
|---|
| 4859 | return "0xffffffff/0xffffffff"; |
|---|
| 4860 | |
|---|
| 4861 | offset = service_masks[x].bit_offset; |
|---|
| 4862 | bitpos = offset + service_masks[x].bits_used - 1; |
|---|
| 4863 | |
|---|
| 4864 | nfmark = (mark << offset); |
|---|
| 4865 | |
|---|
| 4866 | for(; bitpos>=offset; bitpos--) |
|---|
| 4867 | nfmask |= (1 << bitpos); |
|---|
| 4868 | |
|---|
| 4869 | sprintf(buffer, "0x%x/0x%x", nfmark, nfmask); |
|---|
| 4870 | //fprintf(stderr, "%s\n", buffer); |
|---|
| 4871 | |
|---|
| 4872 | return buffer; |
|---|
| 4873 | } |
|---|
| 4874 | } |
|---|
| 4875 | return "0xffffffff/0xffffffff"; |
|---|
| 4876 | } |
|---|
| 4877 | |
|---|