| 1 | // #define CDEBUG |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <stdlib.h> |
|---|
| 5 | #include <string.h> |
|---|
| 6 | #include <errno.h> |
|---|
| 7 | #include <net/if.h> |
|---|
| 8 | #include <dirent.h> |
|---|
| 9 | #include <unistd.h> |
|---|
| 10 | #include <ctype.h> |
|---|
| 11 | #include <syslog.h> |
|---|
| 12 | #include <sys/socket.h> |
|---|
| 13 | #include <sys/stat.h> |
|---|
| 14 | #include <fcntl.h> |
|---|
| 15 | #include <netinet/in.h> |
|---|
| 16 | #include <stdarg.h> |
|---|
| 17 | #include <sys/ioctl.h> |
|---|
| 18 | #include <sys/sysinfo.h> |
|---|
| 19 | #include <arpa/inet.h> |
|---|
| 20 | #include <netdb.h> |
|---|
| 21 | #include <resolv.h> |
|---|
| 22 | #include <signal.h> |
|---|
| 23 | |
|---|
| 24 | #include <utils.h> |
|---|
| 25 | #include <wlutils.h> |
|---|
| 26 | #include <bcmnvram.h> |
|---|
| 27 | #include <shutils.h> |
|---|
| 28 | #include <cy_conf.h> |
|---|
| 29 | #include <code_pattern.h> |
|---|
| 30 | #include <bcmdevs.h> |
|---|
| 31 | #include <net/route.h> |
|---|
| 32 | #include <cy_conf.h> |
|---|
| 33 | #include <bcmdevs.h> |
|---|
| 34 | #include <linux/if_ether.h> |
|---|
| 35 | // #include <linux/mii.h> |
|---|
| 36 | #include <linux/sockios.h> |
|---|
| 37 | #include <cymac.h> |
|---|
| 38 | #include <broadcom.h> |
|---|
| 39 | #define SIOCGMIIREG 0x8948 /* Read MII PHY register. */ |
|---|
| 40 | #define SIOCSMIIREG 0x8949 /* Write MII PHY register. */ |
|---|
| 41 | |
|---|
| 42 | struct mii_ioctl_data |
|---|
| 43 | { |
|---|
| 44 | unsigned short phy_id; |
|---|
| 45 | unsigned short reg_num; |
|---|
| 46 | unsigned short val_in; |
|---|
| 47 | unsigned short val_out; |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | int count_processes( char *pidName ) |
|---|
| 51 | { |
|---|
| 52 | FILE *fp; |
|---|
| 53 | char line[254]; |
|---|
| 54 | char safename[64]; |
|---|
| 55 | |
|---|
| 56 | sprintf( safename, " %s ", pidName ); |
|---|
| 57 | char zombie[64]; |
|---|
| 58 | |
|---|
| 59 | sprintf( zombie, "Z [%s]", pidName ); // do not count zombies |
|---|
| 60 | int i = 0; |
|---|
| 61 | |
|---|
| 62 | cprintf( "Search for %s\n", pidName ); |
|---|
| 63 | if( ( fp = popen( "ps", "r" ) ) ) |
|---|
| 64 | { |
|---|
| 65 | while( fgets( line, sizeof( line ), fp ) != NULL ) |
|---|
| 66 | { |
|---|
| 67 | if( strstr( line, safename ) && !strstr( line, zombie ) ) |
|---|
| 68 | { |
|---|
| 69 | i++; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | pclose( fp ); |
|---|
| 73 | } |
|---|
| 74 | cprintf( "Search done... %d\n", i ); |
|---|
| 75 | |
|---|
| 76 | return i; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /* |
|---|
| 80 | * This function returns the number of days for the given month in the given |
|---|
| 81 | * year |
|---|
| 82 | */ |
|---|
| 83 | unsigned int daysformonth( unsigned int month, unsigned int year ) |
|---|
| 84 | { |
|---|
| 85 | return ( 30 + ( ( ( month & 9 ) == 8 ) || ( ( month & 9 ) == 1 ) ) - |
|---|
| 86 | ( month == |
|---|
| 87 | 2 ) - ( !( ( ( year % 4 ) == 0 ) |
|---|
| 88 | && ( ( ( year % 100 ) != 0 ) |
|---|
| 89 | || ( ( year % 400 ) == 0 ) ) ) |
|---|
| 90 | && ( month == 2 ) ) ); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | #ifdef HAVE_AQOS |
|---|
| 94 | |
|---|
| 95 | static char *get_wshaper_dev( void ) |
|---|
| 96 | { |
|---|
| 97 | if( nvram_match( "wshaper_dev", "WAN" ) ) |
|---|
| 98 | return get_wan_face( ); |
|---|
| 99 | else |
|---|
| 100 | return "br0"; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void add_userip( char *ip, int idx, char *upstream, char *downstream ) |
|---|
| 104 | { |
|---|
| 105 | int base = 120 + idx; |
|---|
| 106 | char up[32]; |
|---|
| 107 | char down[32]; |
|---|
| 108 | char ups[32]; |
|---|
| 109 | char downs[32]; |
|---|
| 110 | |
|---|
| 111 | if( nvram_match( "qos_type", "1" ) ) |
|---|
| 112 | { |
|---|
| 113 | sprintf( up, "1:%d", base ); |
|---|
| 114 | sprintf( down, "1:%d", base + 1 ); |
|---|
| 115 | sprintf( ups, "%skbit", upstream ); |
|---|
| 116 | sprintf( downs, "%skbit", downstream ); |
|---|
| 117 | sysprintf |
|---|
| 118 | ( "tc class add dev %s parent 1:1 classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 119 | "imq0", base, upstream, upstream ); |
|---|
| 120 | sysprintf |
|---|
| 121 | ( "tc qdisc add dev %s parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 122 | "imq0", base ); |
|---|
| 123 | sysprintf |
|---|
| 124 | ( "tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match ip src %s flowid 1:%d", |
|---|
| 125 | "imq0", ip, base ); |
|---|
| 126 | |
|---|
| 127 | sysprintf |
|---|
| 128 | ( "tc class add dev imq0 parent 1:1 classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 129 | base + 1, downstream, downstream ); |
|---|
| 130 | sysprintf |
|---|
| 131 | ( "tc qdisc add dev imq0 parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 132 | base + 1, base + 1 ); |
|---|
| 133 | sysprintf |
|---|
| 134 | ( "tc filter add dev imq0 protocol ip parent 1:0 prio 1 u32 match ip dst %s flowid 1:%d", |
|---|
| 135 | ip, base + 1 ); |
|---|
| 136 | |
|---|
| 137 | } |
|---|
| 138 | else |
|---|
| 139 | { |
|---|
| 140 | sprintf( up, "1:%d", base ); |
|---|
| 141 | sprintf( down, "1:%d", base + 1 ); |
|---|
| 142 | sprintf( ups, "%skbit", upstream ); |
|---|
| 143 | sprintf( downs, "%skbit", downstream ); |
|---|
| 144 | sysprintf |
|---|
| 145 | ( "tc class add dev %s parent 1:2 classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 146 | "imq0", base, upstream, upstream ); |
|---|
| 147 | sysprintf |
|---|
| 148 | ( "tc qdisc add dev %s parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 149 | "imq0", base ); |
|---|
| 150 | sysprintf |
|---|
| 151 | ( "tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match ip src %s flowid 1:%d", |
|---|
| 152 | "imq0", ip, base ); |
|---|
| 153 | |
|---|
| 154 | sysprintf |
|---|
| 155 | ( "tc class add dev imq0 parent 1:2 classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 156 | base + 1, downstream, downstream ); |
|---|
| 157 | sysprintf |
|---|
| 158 | ( "tc qdisc add dev imq0 parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 159 | base + 1, base + 1 ); |
|---|
| 160 | sysprintf |
|---|
| 161 | ( "tc filter add dev imq0 protocol ip parent 1:0 prio 1 u32 match ip dst %s flowid 1:%d", |
|---|
| 162 | ip, base + 1 ); |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | void add_usermac( char *mac, int idx, char *upstream, char *downstream ) |
|---|
| 167 | { |
|---|
| 168 | unsigned char octet[6]; |
|---|
| 169 | |
|---|
| 170 | ether_atoe( mac, octet ); |
|---|
| 171 | int base = 120 + idx; |
|---|
| 172 | char up[32]; |
|---|
| 173 | char down[32]; |
|---|
| 174 | char ups[32]; |
|---|
| 175 | char downs[32]; |
|---|
| 176 | char oct2[32]; |
|---|
| 177 | char oct4[32]; |
|---|
| 178 | char doct2[32]; |
|---|
| 179 | char doct4[32]; |
|---|
| 180 | |
|---|
| 181 | sprintf( up, "1:%d", base ); |
|---|
| 182 | sprintf( down, "1:%d", base + 1 ); |
|---|
| 183 | sprintf( ups, "%skbit", upstream ); |
|---|
| 184 | sprintf( downs, "%skbit", downstream ); |
|---|
| 185 | |
|---|
| 186 | sprintf( oct2, "%02X%02X", octet[4], octet[5] ); |
|---|
| 187 | sprintf( oct4, "%02X%02X%02X%02X", octet[0], octet[1], octet[2], |
|---|
| 188 | octet[3] ); |
|---|
| 189 | |
|---|
| 190 | sprintf( doct4, "%02X%02X%02X%02X", octet[2], octet[3], octet[4], |
|---|
| 191 | octet[5] ); |
|---|
| 192 | sprintf( doct2, "%02X%02X", octet[0], octet[1] ); |
|---|
| 193 | |
|---|
| 194 | if( nvram_match( "qos_type", "1" ) ) |
|---|
| 195 | { |
|---|
| 196 | // up |
|---|
| 197 | sysprintf( "tc class add dev %s parent 1:1 classid 1:%d htb rate %skbit ceil %skbit", "imq0", base, upstream, upstream ); // |
|---|
| 198 | sysprintf |
|---|
| 199 | ( "tc qdisc add dev %s parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 200 | "imq0", base ); |
|---|
| 201 | sysprintf |
|---|
| 202 | ( "tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u16 0x%s 0xFFFF at -4 match u32 0x%s 0xFFFFFFFF at -8 flowid 1:%d", |
|---|
| 203 | "imq0", oct2, oct4, base ); |
|---|
| 204 | |
|---|
| 205 | // down |
|---|
| 206 | if( strcmp( get_wshaper_dev( ), "br0" ) ) |
|---|
| 207 | { |
|---|
| 208 | /* |
|---|
| 209 | * use separate root class, since no other class is created for br0 |
|---|
| 210 | * if qos is wan based |
|---|
| 211 | */ |
|---|
| 212 | sysprintf |
|---|
| 213 | ( "tc class add dev br0 parent 1: classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 214 | base + 1, downstream, downstream ); |
|---|
| 215 | sysprintf |
|---|
| 216 | ( "tc qdisc add dev br0 parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 217 | base + 1, base + 1 ); |
|---|
| 218 | sysprintf |
|---|
| 219 | ( "tc filter add dev br0 protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u32 0x%s 0xFFFFFFFF at -12 match u16 0x%s 0xFFFF at -14 flowid 1:%d", |
|---|
| 220 | doct4, doct2, base + 1 ); |
|---|
| 221 | } |
|---|
| 222 | else |
|---|
| 223 | { |
|---|
| 224 | /* |
|---|
| 225 | * use root class of br0 interface which was created by the wshaper |
|---|
| 226 | */ |
|---|
| 227 | sysprintf |
|---|
| 228 | ( "tc class add dev br0 parent 1:1 classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 229 | base + 1, downstream, downstream ); |
|---|
| 230 | sysprintf |
|---|
| 231 | ( "tc qdisc add dev br0 parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 232 | base + 1, base + 1 ); |
|---|
| 233 | sysprintf |
|---|
| 234 | ( "tc filter add dev br0 protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u32 0x%s 0xFFFFFFFF at -12 match u16 0x%s 0xFFFF at -14 flowid 1:%d", |
|---|
| 235 | doct4, doct2, base + 1 ); |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | } |
|---|
| 239 | else |
|---|
| 240 | { |
|---|
| 241 | // up |
|---|
| 242 | sysprintf( "tc class add dev %s parent 1:2 classid 1:%d htb rate %skbit ceil %skbit", "imq0", base, upstream, upstream ); // |
|---|
| 243 | sysprintf |
|---|
| 244 | ( "tc qdisc add dev %s parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 245 | "imq0", base ); |
|---|
| 246 | sysprintf |
|---|
| 247 | ( "tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u16 0x%s 0xFFFF at -4 match u32 0x%s 0xFFFFFFFF at -8 flowid 1:%d", |
|---|
| 248 | "imq0", oct2, oct4, base ); |
|---|
| 249 | |
|---|
| 250 | // down |
|---|
| 251 | if( strcmp( get_wshaper_dev( ), "br0" ) ) |
|---|
| 252 | { |
|---|
| 253 | /* |
|---|
| 254 | * use separate root class, since no other class is created for br0 |
|---|
| 255 | * if qos is wan based |
|---|
| 256 | */ |
|---|
| 257 | sysprintf |
|---|
| 258 | ( "tc class add dev br0 parent 1: classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 259 | base + 1, downstream, downstream ); |
|---|
| 260 | sysprintf |
|---|
| 261 | ( "tc qdisc add dev br0 parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 262 | base + 1, base + 1 ); |
|---|
| 263 | sysprintf |
|---|
| 264 | ( "tc filter add dev br0 protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u32 0x%s 0xFFFFFFFF at -12 match u16 0x%s 0xFFFF at -14 flowid 1:%d", |
|---|
| 265 | doct4, doct2, base + 1 ); |
|---|
| 266 | } |
|---|
| 267 | else |
|---|
| 268 | { |
|---|
| 269 | /* |
|---|
| 270 | * use root class of br0 interface which was created by the wshaper |
|---|
| 271 | */ |
|---|
| 272 | sysprintf |
|---|
| 273 | ( "tc class add dev br0 parent 1:2 classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 274 | base + 1, downstream, downstream ); |
|---|
| 275 | sysprintf |
|---|
| 276 | ( "tc qdisc add dev br0 parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 277 | base + 1, base + 1 ); |
|---|
| 278 | sysprintf |
|---|
| 279 | ( "tc filter add dev br0 protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u32 0x%s 0xFFFFFFFF at -12 match u16 0x%s 0xFFFF at -14 flowid 1:%d", |
|---|
| 280 | doct4, doct2, base + 1 ); |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | /* |
|---|
| 284 | * mac downstream matching can only be made directly on the connected |
|---|
| 285 | * interface |
|---|
| 286 | */ |
|---|
| 287 | char iflist[256]; |
|---|
| 288 | |
|---|
| 289 | getIfList( iflist, NULL ); |
|---|
| 290 | static char word[256]; |
|---|
| 291 | char *next, *wordlist; |
|---|
| 292 | |
|---|
| 293 | foreach( word, iflist, next ) |
|---|
| 294 | { |
|---|
| 295 | if( nvram_nmatch( "0", "%s_bridged", word ) ) |
|---|
| 296 | { |
|---|
| 297 | sysprintf |
|---|
| 298 | ( "tc class add dev %s parent 1: classid 1:%d htb rate %skbit ceil %skbit", |
|---|
| 299 | word, base + 1, downstream, downstream ); |
|---|
| 300 | sysprintf |
|---|
| 301 | ( "tc qdisc add dev %s parent 1:%d sfq quantum 1514b perturb 15", |
|---|
| 302 | word, base + 1, base + 1 ); |
|---|
| 303 | sysprintf |
|---|
| 304 | ( "tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match u16 0x0800 0xFFFF at -2 match u32 0x%s 0xFFFFFFFF at -12 match u16 0x%s 0xFFFF at -14 flowid 1:%d", |
|---|
| 305 | word, doct4, doct2, base + 1 ); |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | #endif |
|---|
| 312 | int buf_to_file( char *path, char *buf ) |
|---|
| 313 | { |
|---|
| 314 | FILE *fp; |
|---|
| 315 | |
|---|
| 316 | if( ( fp = fopen( path, "w" ) ) ) |
|---|
| 317 | { |
|---|
| 318 | fprintf( fp, "%s", buf ); |
|---|
| 319 | fclose( fp ); |
|---|
| 320 | return 1; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | return 0; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | int check_action( void ) |
|---|
| 327 | { |
|---|
| 328 | char buf[80] = ""; |
|---|
| 329 | |
|---|
| 330 | if( file_to_buf( ACTION_FILE, buf, sizeof( buf ) ) ) |
|---|
| 331 | { |
|---|
| 332 | if( !strcmp( buf, "ACT_TFTP_UPGRADE" ) ) |
|---|
| 333 | { |
|---|
| 334 | fprintf( stderr, "Upgrading from tftp now ...\n" ); |
|---|
| 335 | return ACT_TFTP_UPGRADE; |
|---|
| 336 | } |
|---|
| 337 | #ifdef HAVE_HTTPS |
|---|
| 338 | else if( !strcmp( buf, "ACT_WEBS_UPGRADE" ) ) |
|---|
| 339 | { |
|---|
| 340 | fprintf( stderr, "Upgrading from web (https) now ...\n" ); |
|---|
| 341 | return ACT_WEBS_UPGRADE; |
|---|
| 342 | } |
|---|
| 343 | #endif |
|---|
| 344 | else if( !strcmp( buf, "ACT_WEB_UPGRADE" ) ) |
|---|
| 345 | { |
|---|
| 346 | fprintf( stderr, "Upgrading from web (http) now ...\n" ); |
|---|
| 347 | return ACT_WEB_UPGRADE; |
|---|
| 348 | } |
|---|
| 349 | else if( !strcmp( buf, "ACT_SW_RESTORE" ) ) |
|---|
| 350 | { |
|---|
| 351 | fprintf( stderr, "Receiving restore command from web ...\n" ); |
|---|
| 352 | return ACT_SW_RESTORE; |
|---|
| 353 | } |
|---|
| 354 | else if( !strcmp( buf, "ACT_HW_RESTORE" ) ) |
|---|
| 355 | { |
|---|
| 356 | fprintf( stderr, |
|---|
| 357 | "Receiving restore command from resetbutton ...\n" ); |
|---|
| 358 | return ACT_HW_RESTORE; |
|---|
| 359 | } |
|---|
| 360 | else if( !strcmp( buf, "ACT_NVRAM_COMMIT" ) ) |
|---|
| 361 | { |
|---|
| 362 | fprintf( stderr, "Committing nvram now ...\n" ); |
|---|
| 363 | return ACT_NVRAM_COMMIT; |
|---|
| 364 | } |
|---|
| 365 | else if( !strcmp( buf, "ACT_ERASE_NVRAM" ) ) |
|---|
| 366 | { |
|---|
| 367 | fprintf( stderr, "Erasing nvram now ...\n" ); |
|---|
| 368 | return ACT_ERASE_NVRAM; |
|---|
| 369 | } |
|---|
| 370 | } |
|---|
| 371 | // fprintf(stderr, "Waiting for upgrading....\n"); |
|---|
| 372 | return ACT_IDLE; |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | int check_vlan_support( void ) |
|---|
| 376 | { |
|---|
| 377 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || 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) |
|---|
| 378 | return 0; |
|---|
| 379 | #else |
|---|
| 380 | |
|---|
| 381 | int brand = getRouterBrand( ); |
|---|
| 382 | |
|---|
| 383 | switch ( brand ) |
|---|
| 384 | { |
|---|
| 385 | #ifndef HAVE_BUFFALO |
|---|
| 386 | case ROUTER_ASUS_WL500GD: |
|---|
| 387 | return 1; |
|---|
| 388 | break; |
|---|
| 389 | #endif |
|---|
| 390 | case ROUTER_BUFFALO_WLAG54C: |
|---|
| 391 | case ROUTER_BUFFALO_WLA2G54C: |
|---|
| 392 | #ifndef HAVE_BUFFALO |
|---|
| 393 | case ROUTER_LINKSYS_WRT55AG: |
|---|
| 394 | case ROUTER_MOTOROLA_V1: |
|---|
| 395 | case ROUTER_MOTOROLA_WE800G: |
|---|
| 396 | case ROUTER_WAP54G_V1: |
|---|
| 397 | case ROUTER_SITECOM_WL105B: |
|---|
| 398 | case ROUTER_SITECOM_WL111: |
|---|
| 399 | case ROUTER_BUFFALO_WLI2_TX1_G54: |
|---|
| 400 | case ROUTER_BUFFALO_WLI_TX4_G54HP: |
|---|
| 401 | case ROUTER_BRCM4702_GENERIC: |
|---|
| 402 | case ROUTER_ASUS_WL500G: |
|---|
| 403 | case ROUTER_BELKIN_F5D7230_V2000: |
|---|
| 404 | #endif |
|---|
| 405 | return 0; |
|---|
| 406 | break; |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | uint boardflags = strtoul( nvram_safe_get( "boardflags" ), NULL, 0 ); |
|---|
| 410 | |
|---|
| 411 | if( boardflags & BFL_ENETVLAN ) |
|---|
| 412 | return 1; |
|---|
| 413 | |
|---|
| 414 | if( nvram_match( "boardtype", "bcm94710dev" ) |
|---|
| 415 | || nvram_match( "boardtype", "0x0101" ) || ( boardflags & 0x0100 ) ) |
|---|
| 416 | return 1; |
|---|
| 417 | else |
|---|
| 418 | return 0; |
|---|
| 419 | #endif |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | void setRouter( char *name ) |
|---|
| 423 | { |
|---|
| 424 | #ifdef HAVE_POWERNOC_WORT54G |
|---|
| 425 | nvram_set( NVROUTER, "WORT54G" ); |
|---|
| 426 | #elif HAVE_POWERNOC_WOAP54G |
|---|
| 427 | nvram_set( NVROUTER, "WOAP54G" ); |
|---|
| 428 | #elif HAVE_OMNI |
|---|
| 429 | nvram_set( NVROUTER, "Omni Wifi Router" ); |
|---|
| 430 | #elif HAVE_MAKSAT |
|---|
| 431 | if( name ) |
|---|
| 432 | nvram_set( "DD_BOARD2", name ); |
|---|
| 433 | nvram_set( NVROUTER, "MAKSAT" ); |
|---|
| 434 | #else |
|---|
| 435 | if( name ) |
|---|
| 436 | nvram_set( NVROUTER, name ); |
|---|
| 437 | #endif |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | char *getRouter( ) |
|---|
| 441 | { |
|---|
| 442 | char *n = nvram_get( NVROUTER ); |
|---|
| 443 | |
|---|
| 444 | return n != NULL ? n : "Unknown Model"; |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | int internal_getRouterBrand( ) |
|---|
| 448 | { |
|---|
| 449 | |
|---|
| 450 | #ifdef HAVE_ADM5120 |
|---|
| 451 | setRouter( "Tonze AP-120" ); |
|---|
| 452 | return ROUTER_BOARD_ADM5120; |
|---|
| 453 | #elif HAVE_RB500 |
|---|
| 454 | setRouter( "Mikrotik RB500" ); |
|---|
| 455 | return ROUTER_BOARD_500; |
|---|
| 456 | #elif HAVE_GEMTEK |
|---|
| 457 | setRouter( "SuperGerry" ); |
|---|
| 458 | return ROUTER_SUPERGERRY; |
|---|
| 459 | #elif HAVE_TONZE |
|---|
| 460 | setRouter( "Tonze AP-425" ); |
|---|
| 461 | return ROUTER_BOARD_GATEWORX; |
|---|
| 462 | #elif HAVE_NOP8670 |
|---|
| 463 | setRouter( "Senao NOP-8670" ); |
|---|
| 464 | return ROUTER_BOARD_GATEWORX; |
|---|
| 465 | #elif HAVE_WRT300NV2 |
|---|
| 466 | setRouter( "Linksys WRT300N v2" ); |
|---|
| 467 | return ROUTER_BOARD_GATEWORX; |
|---|
| 468 | #elif HAVE_GATEWORX |
|---|
| 469 | char *filename = "/sys/devices/platform/IXP4XX-I2C.0/i2c-adapter:i2c-0/0-0051/eeprom"; /* bank2=0x100 |
|---|
| 470 | */ |
|---|
| 471 | FILE *file = fopen( filename, "r" ); |
|---|
| 472 | |
|---|
| 473 | if( file ) // new detection scheme |
|---|
| 474 | { |
|---|
| 475 | fseek( file, 32, SEEK_SET ); |
|---|
| 476 | char gwid[7]; |
|---|
| 477 | |
|---|
| 478 | gwid[6] = 0; |
|---|
| 479 | int ret = fread( gwid, 6, 1, file ); |
|---|
| 480 | |
|---|
| 481 | if( ret < 1 ) |
|---|
| 482 | { |
|---|
| 483 | fclose( file ); |
|---|
| 484 | goto old_way; |
|---|
| 485 | } |
|---|
| 486 | fclose( file ); |
|---|
| 487 | if( !strcmp( gwid, "GW2347" ) ) |
|---|
| 488 | { |
|---|
| 489 | setRouter( "Avila GW2347" ); |
|---|
| 490 | return ROUTER_BOARD_GATEWORX_SWAP; |
|---|
| 491 | } |
|---|
| 492 | if( !strcmp( gwid, "GW2357" ) ) |
|---|
| 493 | { |
|---|
| 494 | setRouter( "Avila GW2357" ); |
|---|
| 495 | return ROUTER_BOARD_GATEWORX_SWAP; |
|---|
| 496 | } |
|---|
| 497 | if( !strcmp( gwid, "GW2353" ) ) |
|---|
| 498 | { |
|---|
| 499 | setRouter( "Avila GW2343" ); |
|---|
| 500 | return ROUTER_BOARD_GATEWORX; |
|---|
| 501 | } |
|---|
| 502 | if( !strcmp( gwid, "GW2348" ) ) |
|---|
| 503 | { |
|---|
| 504 | setRouter( "Avila GW2348-4/2" ); |
|---|
| 505 | return ROUTER_BOARD_GATEWORX; |
|---|
| 506 | } |
|---|
| 507 | if( !strcmp( gwid, "GW2358" ) ) |
|---|
| 508 | { |
|---|
| 509 | setRouter( "Cambria GW2358-4" ); |
|---|
| 510 | return ROUTER_BOARD_GATEWORX; |
|---|
| 511 | } |
|---|
| 512 | if( !strcmp( gwid, "GW2355" ) ) |
|---|
| 513 | { |
|---|
| 514 | setRouter( "Avila GW2355" ); |
|---|
| 515 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 516 | } |
|---|
| 517 | if( !strcmp( gwid, "GW2345" ) ) |
|---|
| 518 | { |
|---|
| 519 | setRouter( "Avila GW2345" ); |
|---|
| 520 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | old_way:; |
|---|
| 524 | struct mii_ioctl_data *data; |
|---|
| 525 | struct ifreq iwr; |
|---|
| 526 | int s = socket( AF_INET, SOCK_DGRAM, 0 ); |
|---|
| 527 | |
|---|
| 528 | if( s < 0 ) |
|---|
| 529 | { |
|---|
| 530 | fprintf( stderr, "socket(SOCK_DRAGM)\n" ); |
|---|
| 531 | setRouter( "Avila Gateworks" ); |
|---|
| 532 | return ROUTER_BOARD_GATEWORX; |
|---|
| 533 | } |
|---|
| 534 | ( void )strncpy( iwr.ifr_name, "ixp0", sizeof( "ixp0" ) ); |
|---|
| 535 | data = ( struct mii_ioctl_data * )&iwr.ifr_data; |
|---|
| 536 | data->phy_id = 1; |
|---|
| 537 | #define IX_ETH_ACC_MII_PHY_ID1_REG 0x2 /* PHY identifier 1 Register */ |
|---|
| 538 | #define IX_ETH_ACC_MII_PHY_ID2_REG 0x3 /* PHY identifier 2 Register */ |
|---|
| 539 | data->reg_num = IX_ETH_ACC_MII_PHY_ID1_REG; |
|---|
| 540 | ioctl( s, SIOCGMIIREG, &iwr ); |
|---|
| 541 | data->phy_id = 1; |
|---|
| 542 | data->reg_num = IX_ETH_ACC_MII_PHY_ID1_REG; |
|---|
| 543 | ioctl( s, SIOCGMIIREG, &iwr ); |
|---|
| 544 | int reg1 = data->val_out; |
|---|
| 545 | |
|---|
| 546 | data->phy_id = 1; |
|---|
| 547 | data->reg_num = IX_ETH_ACC_MII_PHY_ID2_REG; |
|---|
| 548 | ioctl( s, SIOCGMIIREG, &iwr ); |
|---|
| 549 | int reg2 = data->val_out; |
|---|
| 550 | |
|---|
| 551 | close( s ); |
|---|
| 552 | fprintf( stderr, "phy id %X:%X\n", reg1, reg2 ); |
|---|
| 553 | if( reg1 == 0x2000 && reg2 == 0x5c90 ) |
|---|
| 554 | { |
|---|
| 555 | setRouter( "Avila GW2347" ); |
|---|
| 556 | return ROUTER_BOARD_GATEWORX_SWAP; |
|---|
| 557 | } |
|---|
| 558 | else if( reg1 == 0x13 && reg2 == 0x7a11 ) |
|---|
| 559 | { |
|---|
| 560 | setRouter( "Avila GW2348-4/2" ); |
|---|
| 561 | return ROUTER_BOARD_GATEWORX; |
|---|
| 562 | } |
|---|
| 563 | else if( reg1 == 0x143 && reg2 == 0xbc31 ) // broadcom phy |
|---|
| 564 | { |
|---|
| 565 | setRouter( "ADI Engineering Pronghorn Metro" ); |
|---|
| 566 | return ROUTER_BOARD_GATEWORX; |
|---|
| 567 | } |
|---|
| 568 | else if( reg1 == 0x22 && reg2 == 0x1450 ) // kendin switch |
|---|
| 569 | { |
|---|
| 570 | setRouter( "Avila GW2345" ); |
|---|
| 571 | return ROUTER_BOARD_GATEWORX_GW2345; |
|---|
| 572 | } |
|---|
| 573 | else if( reg1 == 0x0 && reg2 == 0x8201 ) // realtek |
|---|
| 574 | { |
|---|
| 575 | setRouter( "Compex WP188" ); |
|---|
| 576 | return ROUTER_BOARD_GATEWORX; |
|---|
| 577 | } |
|---|
| 578 | else |
|---|
| 579 | { |
|---|
| 580 | setRouter( "Unknown" ); |
|---|
| 581 | return ROUTER_BOARD_GATEWORX; |
|---|
| 582 | } |
|---|
| 583 | #elif HAVE_X86 |
|---|
| 584 | setRouter( "Generic X86" ); |
|---|
| 585 | return ROUTER_BOARD_X86; |
|---|
| 586 | #elif HAVE_XSCALE |
|---|
| 587 | setRouter( "NewMedia Dual A/B/G" ); |
|---|
| 588 | return ROUTER_BOARD_XSCALE; |
|---|
| 589 | #elif HAVE_MAGICBOX |
|---|
| 590 | setRouter( "MagicBox" ); |
|---|
| 591 | return ROUTER_BOARD_MAGICBOX; |
|---|
| 592 | #elif HAVE_WRT54GV7 |
|---|
| 593 | setRouter( "Linksys WRT54G v7" ); |
|---|
| 594 | return ROUTER_BOARD_FONERA; |
|---|
| 595 | #elif HAVE_WRK54G |
|---|
| 596 | setRouter( "Linksys WRK54G v3" ); |
|---|
| 597 | return ROUTER_BOARD_FONERA; |
|---|
| 598 | #elif HAVE_MR3202A |
|---|
| 599 | setRouter( "MR3202A" ); |
|---|
| 600 | return ROUTER_BOARD_FONERA; |
|---|
| 601 | #elif HAVE_AR430W |
|---|
| 602 | setRouter( "Airlink-101 AR430W" ); |
|---|
| 603 | return ROUTER_BOARD_FONERA; |
|---|
| 604 | #elif HAVE_DIR400 |
|---|
| 605 | setRouter( "D-Link DIR-400" ); |
|---|
| 606 | return ROUTER_BOARD_FONERA2200; |
|---|
| 607 | #elif HAVE_DIR300 |
|---|
| 608 | setRouter( "D-Link DIR-300" ); |
|---|
| 609 | return ROUTER_BOARD_FONERA; |
|---|
| 610 | #elif HAVE_WBD500 |
|---|
| 611 | setRouter( "Wiligear WBD-500" ); |
|---|
| 612 | return ROUTER_BOARD_FONERA; |
|---|
| 613 | #elif HAVE_FONERA |
|---|
| 614 | struct mii_ioctl_data *data; |
|---|
| 615 | struct ifreq iwr; |
|---|
| 616 | int s = socket( AF_INET, SOCK_DGRAM, 0 ); |
|---|
| 617 | |
|---|
| 618 | if( s < 0 ) |
|---|
| 619 | { |
|---|
| 620 | fprintf( stderr, "socket(SOCK_DRAGM)\n" ); |
|---|
| 621 | setRouter( "Fonera 2100/2200" ); |
|---|
| 622 | return ROUTER_BOARD_FONERA; |
|---|
| 623 | } |
|---|
| 624 | ( void )strncpy( iwr.ifr_name, "eth0", sizeof( "eth0" ) ); |
|---|
| 625 | data = ( struct mii_ioctl_data * )&iwr.ifr_data; |
|---|
| 626 | data->phy_id = 0x10; |
|---|
| 627 | data->reg_num = 0x2; |
|---|
| 628 | ioctl( s, SIOCGMIIREG, &iwr ); |
|---|
| 629 | data->phy_id = 0x10; |
|---|
| 630 | data->reg_num = 0x2; |
|---|
| 631 | ioctl( s, SIOCGMIIREG, &iwr ); |
|---|
| 632 | if( data->val_out == 0x0141 ) |
|---|
| 633 | { |
|---|
| 634 | data->phy_id = 0x10; |
|---|
| 635 | data->reg_num = 0x3; |
|---|
| 636 | ioctl( s, SIOCGMIIREG, &iwr ); |
|---|
| 637 | close( s ); |
|---|
| 638 | if( ( data->val_out & 0xfc00 ) != 0x0c00 ) // marvell phy |
|---|
| 639 | { |
|---|
| 640 | setRouter( "Fonera 2100/2200" ); |
|---|
| 641 | return ROUTER_BOARD_FONERA; |
|---|
| 642 | } |
|---|
| 643 | else |
|---|
| 644 | { |
|---|
| 645 | setRouter( "Fonera 2201" ); |
|---|
| 646 | return ROUTER_BOARD_FONERA2200; |
|---|
| 647 | } |
|---|
| 648 | } |
|---|
| 649 | else |
|---|
| 650 | { |
|---|
| 651 | setRouter( "Fonera 2100/2200" ); |
|---|
| 652 | return ROUTER_BOARD_FONERA; |
|---|
| 653 | } |
|---|
| 654 | #elif HAVE_MERAKI |
|---|
| 655 | setRouter( "Meraki Mini" ); |
|---|
| 656 | return ROUTER_BOARD_MERAKI; |
|---|
| 657 | #elif HAVE_NS2 |
|---|
| 658 | setRouter( "Ubiquiti Nanostation 2" ); |
|---|
| 659 | return ROUTER_BOARD_LS2; |
|---|
| 660 | #elif HAVE_NS5 |
|---|
| 661 | setRouter( "Ubiquiti Nanostation 5" ); |
|---|
| 662 | return ROUTER_BOARD_LS2; |
|---|
| 663 | #elif HAVE_PS2 |
|---|
| 664 | setRouter( "Ubiquiti Powerstation 2" ); |
|---|
| 665 | return ROUTER_BOARD_LS2; |
|---|
| 666 | #elif HAVE_PS5 |
|---|
| 667 | setRouter( "Ubiquiti Powerstation 5" ); |
|---|
| 668 | return ROUTER_BOARD_LS2; |
|---|
| 669 | #elif HAVE_LS2 |
|---|
| 670 | setRouter( "Ubiquiti Litestation 2" ); |
|---|
| 671 | return ROUTER_BOARD_LS2; |
|---|
| 672 | #elif HAVE_LS5 |
|---|
| 673 | setRouter( "Ubiquiti Litestation 5" ); |
|---|
| 674 | return ROUTER_BOARD_LS2; |
|---|
| 675 | #elif HAVE_WHRAG108 |
|---|
| 676 | setRouter( "Buffalo WHR-HP-AG108" ); |
|---|
| 677 | return ROUTER_BOARD_WHRAG108; |
|---|
| 678 | #elif HAVE_PB42 |
|---|
| 679 | setRouter( "Atheros PB42" ); |
|---|
| 680 | return ROUTER_BOARD_PB42; |
|---|
| 681 | #elif HAVE_LSX |
|---|
| 682 | setRouter( "Ubiquiti LSX" ); |
|---|
| 683 | return ROUTER_BOARD_PB42; |
|---|
| 684 | #elif HAVE_DANUBE |
|---|
| 685 | setRouter( "Infineon Danube" ); |
|---|
| 686 | return ROUTER_BOARD_DANUBE; |
|---|
| 687 | #elif HAVE_STORM |
|---|
| 688 | setRouter( "Wiligear WBD-111" ); |
|---|
| 689 | return ROUTER_BOARD_STORM; |
|---|
| 690 | #elif HAVE_TW6600 |
|---|
| 691 | setRouter( "AW-6660" ); |
|---|
| 692 | return ROUTER_BOARD_TW6600; |
|---|
| 693 | #elif HAVE_ALPHA |
|---|
| 694 | setRouter( "Alfa Networks AP48" ); |
|---|
| 695 | return ROUTER_BOARD_CA8; |
|---|
| 696 | #elif HAVE_USR5453 |
|---|
| 697 | setRouter( "US Robotics USR5453" ); |
|---|
| 698 | return ROUTER_BOARD_CA8; |
|---|
| 699 | #elif HAVE_CA8PRO |
|---|
| 700 | setRouter( "Wistron CA8-4 PRO" ); |
|---|
| 701 | return ROUTER_BOARD_CA8PRO; |
|---|
| 702 | #elif HAVE_CA8 |
|---|
| 703 | setRouter( "Wistron CA8-4" ); |
|---|
| 704 | return ROUTER_BOARD_CA8; |
|---|
| 705 | #else |
|---|
| 706 | |
|---|
| 707 | uint boardnum = strtoul( nvram_safe_get( "boardnum" ), NULL, 0 ); |
|---|
| 708 | |
|---|
| 709 | if( boardnum == 42 && nvram_match( "boardtype", "bcm94710ap" ) ) |
|---|
| 710 | { |
|---|
| 711 | cprintf( "router is buffalo\n" ); |
|---|
| 712 | setRouter( "Buffalo WBR-G54 / WLA-G54" ); |
|---|
| 713 | return ROUTER_BUFFALO_WBR54G; |
|---|
| 714 | } |
|---|
| 715 | #ifndef HAVE_BUFFALO |
|---|
| 716 | if( nvram_match( "boardnum", "mn700" ) && |
|---|
| 717 | nvram_match( "boardtype", "bcm94710ap" ) ) |
|---|
| 718 | { |
|---|
| 719 | cprintf( "router is Microsoft MN-700\n" ); |
|---|
| 720 | setRouter( "Microsoft MN-700" ); |
|---|
| 721 | return ROUTER_MICROSOFT_MN700; |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | if( nvram_match( "boardnum", "asusX" ) && |
|---|
| 725 | nvram_match( "boardtype", "bcm94710dev" ) ) |
|---|
| 726 | { |
|---|
| 727 | cprintf( "router is Asus WL300g / WL500g\n" ); |
|---|
| 728 | setRouter( "Asus WL-300g / WL-500g" ); |
|---|
| 729 | return ROUTER_ASUS_WL500G; |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | if( boardnum == 44 && nvram_match( "boardtype", "bcm94710ap" ) ) |
|---|
| 733 | { |
|---|
| 734 | cprintf( "router is Dell TrueMobile 2300\n" ); |
|---|
| 735 | setRouter( "Dell TrueMobile 2300" ); |
|---|
| 736 | return ROUTER_DELL_TRUEMOBILE_2300; |
|---|
| 737 | } |
|---|
| 738 | #endif |
|---|
| 739 | |
|---|
| 740 | if( boardnum == 100 && nvram_match( "boardtype", "bcm94710dev" ) ) |
|---|
| 741 | { |
|---|
| 742 | cprintf( "router is buffalo\n" ); |
|---|
| 743 | setRouter( "Buffalo WLA-G54C" ); |
|---|
| 744 | return ROUTER_BUFFALO_WLAG54C; |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | #ifndef HAVE_BUFFALO |
|---|
| 748 | if( boardnum == 45 && nvram_match( "boardtype", "bcm95365r" ) ) |
|---|
| 749 | { |
|---|
| 750 | cprintf( "router is Asus WL-500GD\n" ); |
|---|
| 751 | setRouter( "Asus WL-500g Deluxe" ); |
|---|
| 752 | return ROUTER_ASUS_WL500GD; |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | if( boardnum == 45 && nvram_match( "boardtype", "0x0472" ) |
|---|
| 756 | && nvram_match( "boardrev", "0x23" ) && nvram_match( "parkid", "1" ) ) |
|---|
| 757 | { |
|---|
| 758 | cprintf( "router is Asus WL-500W\n" ); |
|---|
| 759 | setRouter( "Asus WL-500W" ); |
|---|
| 760 | return ROUTER_ASUS_WL500W; |
|---|
| 761 | } |
|---|
| 762 | |
|---|
| 763 | if( boardnum == 45 && nvram_match( "boardtype", "0x467" ) ) |
|---|
| 764 | { |
|---|
| 765 | cprintf( "router is Asus WL-550gE\n" ); |
|---|
| 766 | setRouter( "Asus WL-550gE" ); |
|---|
| 767 | return ROUTER_ASUS_WL550GE; |
|---|
| 768 | } |
|---|
| 769 | #endif |
|---|
| 770 | if( nvram_match( "boardnum", "00" ) && |
|---|
| 771 | nvram_match( "boardtype", "0x0101" ) |
|---|
| 772 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 773 | { |
|---|
| 774 | cprintf( "router is Buffalo wbr2\n" ); |
|---|
| 775 | setRouter( "Buffalo WBR2-G54 / WBR2-G54S" ); |
|---|
| 776 | return ROUTER_BUFFALO_WBR2G54S; |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | if( boardnum == 2 && |
|---|
| 780 | nvram_match( "boardtype", "0x0101" ) |
|---|
| 781 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 782 | { |
|---|
| 783 | cprintf( "router is buffalo wla2-g54c\n" ); |
|---|
| 784 | setRouter( "Buffalo WLA2-G54C / WLI3-TX1-G54" ); |
|---|
| 785 | return ROUTER_BUFFALO_WLA2G54C; |
|---|
| 786 | } |
|---|
| 787 | if( boardnum == 0 && nvram_match( "melco_id", "29090" ) |
|---|
| 788 | && nvram_match( "boardflags", "0x0010" ) |
|---|
| 789 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 790 | { |
|---|
| 791 | cprintf( "router is Buffalo WLAH-G54\n" ); |
|---|
| 792 | setRouter( "Buffalo WLAH-G54" ); |
|---|
| 793 | return ROUTER_BUFFALO_WLAH_G54; |
|---|
| 794 | |
|---|
| 795 | } |
|---|
| 796 | if( boardnum == 0 && nvram_match( "melco_id", "31070" ) |
|---|
| 797 | && nvram_match( "boardflags", "0x2288" ) |
|---|
| 798 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 799 | { |
|---|
| 800 | cprintf( "router is Buffalo WAPM-HP-AM54G54\n" ); |
|---|
| 801 | setRouter( "Buffalo WAPM-HP-AM54G54" ); |
|---|
| 802 | return ROUTER_BUFFALO_WAPM_HP_AM54G54; |
|---|
| 803 | } |
|---|
| 804 | if( nvram_match( "boardnum", "00" ) && nvram_match( "boardrev", "0x11" ) |
|---|
| 805 | && nvram_match( "boardtype", "0x048e" ) |
|---|
| 806 | && nvram_match( "melco_id", "32093" ) ) |
|---|
| 807 | { |
|---|
| 808 | cprintf( "router is Buffalo WHR-G125\n" ); |
|---|
| 809 | setRouter( "Buffalo WHR-G125" ); |
|---|
| 810 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | if( nvram_match( "boardnum", "00" ) && |
|---|
| 814 | nvram_match( "boardrev", "0x13" ) |
|---|
| 815 | && nvram_match( "boardtype", "0x467" ) ) |
|---|
| 816 | { |
|---|
| 817 | if( nvram_match( "boardflags", "0x1658" ) |
|---|
| 818 | || nvram_match( "boardflags", "0x2658" ) |
|---|
| 819 | || nvram_match( "boardflags", "0x3658" ) ) |
|---|
| 820 | { |
|---|
| 821 | cprintf( "router is Buffalo WLI-TX4-G54HP\n" ); |
|---|
| 822 | setRouter( "Buffalo WLI-TX4-G54HP" ); |
|---|
| 823 | return ROUTER_BUFFALO_WLI_TX4_G54HP; |
|---|
| 824 | } |
|---|
| 825 | if( !nvram_match( "buffalo_hp", "1" ) |
|---|
| 826 | && nvram_match( "boardflags", "0x2758" ) ) |
|---|
| 827 | { |
|---|
| 828 | cprintf( "router is Buffalo WHR-G54S\n" ); |
|---|
| 829 | setRouter( "Buffalo WHR-G54S" ); |
|---|
| 830 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 831 | } |
|---|
| 832 | if( nvram_match( "buffalo_hp", "1" ) |
|---|
| 833 | || nvram_match( "boardflags", "0x1758" ) ) |
|---|
| 834 | { |
|---|
| 835 | #ifndef HAVE_BUFFALO |
|---|
| 836 | cprintf( "router is Buffalo WHR-HP-G54\n" ); |
|---|
| 837 | setRouter( "Buffalo WHR-HP-G54" ); |
|---|
| 838 | #else |
|---|
| 839 | cprintf( "router is Buffalo WHR-HP-G54DD\n" ); |
|---|
| 840 | #ifdef BUFFALO_JP |
|---|
| 841 | setRouter( "Buffalo AS-A100" ); |
|---|
| 842 | #else |
|---|
| 843 | setRouter( "Buffalo WHR-HP-G54DD" ); |
|---|
| 844 | #endif |
|---|
| 845 | #endif |
|---|
| 846 | return ROUTER_BUFFALO_WHRG54S; |
|---|
| 847 | } |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | if( nvram_match( "boardnum", "00" ) && |
|---|
| 851 | nvram_match( "boardrev", "0x10" ) |
|---|
| 852 | && nvram_match( "boardtype", "0x470" ) ) |
|---|
| 853 | { |
|---|
| 854 | cprintf( "router is Buffalo WHR-AM54G54\n" ); |
|---|
| 855 | setRouter( "Buffalo WHR-AM54G54" ); |
|---|
| 856 | return ROUTER_BUFFALO_WHRAM54G54; |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | if( boardnum == 42 && nvram_match( "boardtype", "0x042f" ) ) |
|---|
| 860 | { |
|---|
| 861 | uint melco_id = strtoul( nvram_safe_get( "melco_id" ), NULL, 0 ); |
|---|
| 862 | |
|---|
| 863 | if( nvram_match( "product_name", "WZR-RS-G54" ) || melco_id == 30083 ) |
|---|
| 864 | { |
|---|
| 865 | cprintf( "router is Buffalo WZR-RS-G54\n" ); |
|---|
| 866 | setRouter( "Buffalo WZR-RS-G54" ); |
|---|
| 867 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 868 | } |
|---|
| 869 | if( nvram_match( "product_name", "WZR-HP-G54" ) || melco_id == 30026 ) |
|---|
| 870 | { |
|---|
| 871 | cprintf( "router is Buffalo WZR-HP-G54\n" ); |
|---|
| 872 | setRouter( "Buffalo WZR-HP-G54" ); |
|---|
| 873 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 874 | } |
|---|
| 875 | if( nvram_match( "product_name", "WZR-G54" ) || melco_id == 30061 ) |
|---|
| 876 | { |
|---|
| 877 | cprintf( "router is Buffalo WZR-G54\n" ); |
|---|
| 878 | setRouter( "Buffalo WZR-G54" ); |
|---|
| 879 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 880 | } |
|---|
| 881 | if( nvram_match( "melco_id", "290441dd" ) ) |
|---|
| 882 | { |
|---|
| 883 | cprintf( "router is Buffalo WHR2-A54G54\n" ); |
|---|
| 884 | setRouter( "Buffalo WHR2-A54G54" ); |
|---|
| 885 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 886 | } |
|---|
| 887 | if( nvram_match( "product_name", "WHR3-AG54" ) |
|---|
| 888 | || nvram_match( "product_name", "WHR3-B11" ) |
|---|
| 889 | || melco_id == 29130 ) |
|---|
| 890 | { |
|---|
| 891 | cprintf( "router is Buffalo WHR3-AG54\n" ); |
|---|
| 892 | setRouter( "Buffalo WHR3-AG54" ); |
|---|
| 893 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 894 | } |
|---|
| 895 | if( nvram_match( "product_name", "WVR-G54-NF" ) || melco_id == 28100 ) |
|---|
| 896 | { |
|---|
| 897 | cprintf( "router is Buffalo WVR-G54-NF\n" ); |
|---|
| 898 | setRouter( "Buffalo WVR-G54-NF" ); |
|---|
| 899 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 900 | } |
|---|
| 901 | if( nvram_match( "melco_id", "31095" ) ) |
|---|
| 902 | { |
|---|
| 903 | cprintf( "router is Buffalo WZR-G108\n" ); |
|---|
| 904 | setRouter( "Buffalo WZR-G108" ); |
|---|
| 905 | return ROUTER_BRCM4702_GENERIC; |
|---|
| 906 | } |
|---|
| 907 | if( melco_id > 0 ) // e.g. 29115 |
|---|
| 908 | { |
|---|
| 909 | cprintf( "router is Buffalo WZR series\n" ); |
|---|
| 910 | setRouter( "Buffalo WZR series" ); |
|---|
| 911 | return ROUTER_BUFFALO_WZRRSG54; |
|---|
| 912 | } |
|---|
| 913 | } |
|---|
| 914 | |
|---|
| 915 | #ifndef HAVE_BUFFALO |
|---|
| 916 | if( boardnum == 42 && |
|---|
| 917 | nvram_match( "boardtype", "0x042f" ) |
|---|
| 918 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 919 | // nvram_match ("boardflags","0x0018")) |
|---|
| 920 | { |
|---|
| 921 | cprintf( "router is Linksys WRTSL54GS\n" ); |
|---|
| 922 | setRouter( "Linksys WRTSL54GS" ); |
|---|
| 923 | return ROUTER_WRTSL54GS; |
|---|
| 924 | } |
|---|
| 925 | |
|---|
| 926 | if( boardnum == 42 && nvram_match( "boardtype", "0x0101" ) |
|---|
| 927 | && nvram_match( "boardrev", "0x10" ) |
|---|
| 928 | && nvram_match( "boot_ver", "v3.6" ) ) |
|---|
| 929 | { |
|---|
| 930 | cprintf( "router is Linksys WRT54G3G\n" ); |
|---|
| 931 | setRouter( "Linksys WRT54G3G" ); |
|---|
| 932 | return ROUTER_WRT54G3G; |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | if( boardnum == 45 && |
|---|
| 936 | nvram_match( "boardtype", "0x042f" ) |
|---|
| 937 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 938 | { |
|---|
| 939 | cprintf( "router is Asus WL-500g Premium\n" ); |
|---|
| 940 | setRouter( "Asus WL-500g Premium" ); |
|---|
| 941 | return ROUTER_ASUS_WL500G_PRE; |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | char *et0 = nvram_safe_get( "et0macaddr" ); |
|---|
| 945 | |
|---|
| 946 | if( boardnum == 100 && nvram_match( "boardtype", "bcm94710r4" ) ) |
|---|
| 947 | { |
|---|
| 948 | if( startswith( et0, "00:11:50" ) ) |
|---|
| 949 | { |
|---|
| 950 | cprintf( "router is Belkin F5D7130 / F5D7330\n" ); |
|---|
| 951 | setRouter( "Belkin F5D7130 / F5D7330" ); |
|---|
| 952 | return ROUTER_RT210W; |
|---|
| 953 | } |
|---|
| 954 | if( startswith( et0, "00:30:BD" ) || startswith( et0, "00:30:bd" ) ) |
|---|
| 955 | { |
|---|
| 956 | cprintf( "router is Belkin F5D7230 v1000\n" ); |
|---|
| 957 | setRouter( "Belkin F5D7230-4 v1000" ); |
|---|
| 958 | return ROUTER_RT210W; |
|---|
| 959 | } |
|---|
| 960 | if( startswith( et0, "00:01:E3" ) || |
|---|
| 961 | startswith( et0, "00:01:e3" ) || startswith( et0, "00:90:96" ) ) |
|---|
| 962 | { |
|---|
| 963 | cprintf( "router is Siemens\n" ); |
|---|
| 964 | setRouter( "Siemens SE505 v1" ); |
|---|
| 965 | return ROUTER_RT210W; |
|---|
| 966 | } |
|---|
| 967 | else |
|---|
| 968 | { |
|---|
| 969 | cprintf( "router is Askey generic\n" ); |
|---|
| 970 | setRouter( "RT210W generic" ); |
|---|
| 971 | return ROUTER_RT210W; |
|---|
| 972 | } |
|---|
| 973 | } |
|---|
| 974 | |
|---|
| 975 | if( nvram_match( "boardtype", "bcm94710r4" ) |
|---|
| 976 | && nvram_match( "boardnum", "" ) ) |
|---|
| 977 | { |
|---|
| 978 | cprintf( "router is Askey board RT2100W\n" ); |
|---|
| 979 | setRouter( "Askey board RT2100W-D65)" ); |
|---|
| 980 | return ROUTER_BRCM4702_GENERIC; |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | if( boardnum == 0 && nvram_match( "boardtype", "0x0100" ) |
|---|
| 984 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 985 | { |
|---|
| 986 | cprintf( "router is Askey board RT2205(6)D-D56\n" ); |
|---|
| 987 | if( startswith( et0, "00:11:50" ) || |
|---|
| 988 | startswith( et0, "00:30:BD" ) || startswith( et0, "00:30:bd" ) ) |
|---|
| 989 | { |
|---|
| 990 | setRouter( "Askey board RT2205(6)D-D56" ); |
|---|
| 991 | } |
|---|
| 992 | else |
|---|
| 993 | { |
|---|
| 994 | setRouter( "Belkin board F5D8230" ); |
|---|
| 995 | } |
|---|
| 996 | return ROUTER_ASKEY_RT220XD; |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | if( nvram_match( "boardtype", "0x0101" ) ) |
|---|
| 1000 | { |
|---|
| 1001 | if( startswith( et0, "00:11:50" ) || |
|---|
| 1002 | startswith( et0, "00:30:BD" ) || startswith( et0, "00:30:bd" ) ) |
|---|
| 1003 | { |
|---|
| 1004 | if( nvram_match( "Belkin_ver", "2000" ) ) |
|---|
| 1005 | { |
|---|
| 1006 | cprintf( "router is Belkin F5D7230-4 v2000\n" ); |
|---|
| 1007 | setRouter( "Belkin F5D7230-4 v2000" ); |
|---|
| 1008 | return ROUTER_BELKIN_F5D7230_V2000; |
|---|
| 1009 | } |
|---|
| 1010 | else |
|---|
| 1011 | { |
|---|
| 1012 | cprintf( "router is Belkin F5D7230-4 v1444\n" ); |
|---|
| 1013 | setRouter( "Belkin F5D7230-4 v1444" ); |
|---|
| 1014 | return ROUTER_RT480W; |
|---|
| 1015 | } |
|---|
| 1016 | } |
|---|
| 1017 | if( startswith( et0, "00:01:E3" ) || |
|---|
| 1018 | startswith( et0, "00:01:e3" ) || startswith( et0, "00:90:96" ) ) |
|---|
| 1019 | { |
|---|
| 1020 | cprintf( "router is Siemens / Askey\n" ); |
|---|
| 1021 | setRouter( "Siemens SE505 v2" ); |
|---|
| 1022 | return ROUTER_RT480W; |
|---|
| 1023 | } |
|---|
| 1024 | } |
|---|
| 1025 | if( boardnum == 1 && nvram_match( "boardtype", "0x456" ) |
|---|
| 1026 | && nvram_match( "test_led_gpio", "2" ) ) |
|---|
| 1027 | { |
|---|
| 1028 | cprintf( "router is Belkin F5D7230-4 v3000\n" ); |
|---|
| 1029 | setRouter( "Belkin F5D7230-4 v3000" ); |
|---|
| 1030 | return ROUTER_BELKIN_F5D7230_V3000; |
|---|
| 1031 | } |
|---|
| 1032 | |
|---|
| 1033 | if( nvram_match( "boardtype", "0x456" ) |
|---|
| 1034 | && nvram_match( "hw_model", "F5D7231-4" ) ) |
|---|
| 1035 | { |
|---|
| 1036 | cprintf( "router is Belkin F5D7231-4 v1212UK\n" ); |
|---|
| 1037 | setRouter( "Belkin F5D7231-4 v1212UK" ); |
|---|
| 1038 | return ROUTER_BELKIN_F5D7231; |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | if( boardnum == 8 && nvram_match( "boardtype", "0x0467" ) ) // fccid: |
|---|
| 1042 | // K7SF5D7231B |
|---|
| 1043 | { |
|---|
| 1044 | cprintf( "router is Belkin F5D7231-4 v2000\n" ); |
|---|
| 1045 | setRouter( "Belkin F5D7231-4 v2000" ); |
|---|
| 1046 | return ROUTER_BELKIN_F5D7231; |
|---|
| 1047 | } |
|---|
| 1048 | |
|---|
| 1049 | if( nvram_match( "boardtype", "0x467" ) ) |
|---|
| 1050 | { |
|---|
| 1051 | if( startswith( et0, "00:11:50" ) || |
|---|
| 1052 | startswith( et0, "00:30:BD" ) || startswith( et0, "00:30:bd" ) ) |
|---|
| 1053 | { |
|---|
| 1054 | cprintf( "router is Belkin F5D7231-4 v2000\n" ); |
|---|
| 1055 | setRouter( "Belkin F5D7231-4 v2000" ); |
|---|
| 1056 | return ROUTER_BELKIN_F5D7231; |
|---|
| 1057 | } |
|---|
| 1058 | } |
|---|
| 1059 | #endif |
|---|
| 1060 | if( boardnum == 2 && nvram_match( "boardtype", "bcm94710dev" ) && nvram_match( "melco_id", "29016" ) ) // Buffalo |
|---|
| 1061 | // WLI2-TX1-G54) |
|---|
| 1062 | { |
|---|
| 1063 | cprintf( "router is Buffalo WLI2-TX1-G54\n" ); |
|---|
| 1064 | setRouter( "Buffalo WLI2-TX1-G54" ); |
|---|
| 1065 | return ROUTER_BUFFALO_WLI2_TX1_G54; |
|---|
| 1066 | } |
|---|
| 1067 | #ifndef HAVE_BUFFALO |
|---|
| 1068 | |
|---|
| 1069 | char *gemtek = nvram_safe_get( "GemtekPmonVer" ); |
|---|
| 1070 | uint gemteknum = strtoul( gemtek, NULL, 0 ); |
|---|
| 1071 | |
|---|
| 1072 | if( boardnum == 2 && gemteknum == 10 && |
|---|
| 1073 | ( startswith( et0, "00:0C:E5" ) || |
|---|
| 1074 | startswith( et0, "00:0c:e5" ) || |
|---|
| 1075 | startswith( et0, "00:0C:10" ) || |
|---|
| 1076 | startswith( et0, "00:0c:10" ) || |
|---|
| 1077 | startswith( et0, "00:0C:11" ) || startswith( et0, "00:0c:11" ) ) ) |
|---|
| 1078 | { |
|---|
| 1079 | cprintf( "router Motorola WE800G v1\n" ); |
|---|
| 1080 | setRouter( "Motorola WE800G v1" ); |
|---|
| 1081 | return ROUTER_MOTOROLA_WE800G; |
|---|
| 1082 | } |
|---|
| 1083 | |
|---|
| 1084 | if( boardnum == 2 |
|---|
| 1085 | && ( startswith( gemtek, "RC" ) || gemteknum == 1 |
|---|
| 1086 | || gemteknum == 10 ) ) |
|---|
| 1087 | { |
|---|
| 1088 | cprintf( "router is Linksys wap54g v1.x\n" ); |
|---|
| 1089 | setRouter( "Linksys WAP54G v1.x" ); |
|---|
| 1090 | return ROUTER_WAP54G_V1; |
|---|
| 1091 | } |
|---|
| 1092 | |
|---|
| 1093 | if( boardnum == 2 && gemteknum == 1 ) |
|---|
| 1094 | { |
|---|
| 1095 | cprintf( "router is Sitecom wl-105b\n" ); |
|---|
| 1096 | setRouter( "Sitecom WL-105(b)" ); |
|---|
| 1097 | return ROUTER_SITECOM_WL105B; |
|---|
| 1098 | } |
|---|
| 1099 | |
|---|
| 1100 | if( boardnum == 2 && gemteknum == 7 |
|---|
| 1101 | && nvram_match( "boardtype", "bcm94710dev" ) ) |
|---|
| 1102 | { |
|---|
| 1103 | cprintf( "router is Sitecom wl-111\n" ); |
|---|
| 1104 | setRouter( "Sitecom WL-111" ); |
|---|
| 1105 | return ROUTER_SITECOM_WL111; |
|---|
| 1106 | } |
|---|
| 1107 | |
|---|
| 1108 | if( gemteknum == 9 ) // Must be Motorola wr850g v1 or we800g v1 or |
|---|
| 1109 | // Linksys wrt55ag v1 |
|---|
| 1110 | { |
|---|
| 1111 | if( startswith( et0, "00:0C:E5" ) || |
|---|
| 1112 | startswith( et0, "00:0c:e5" ) || |
|---|
| 1113 | startswith( et0, "00:0C:10" ) || |
|---|
| 1114 | startswith( et0, "00:0c:10" ) || |
|---|
| 1115 | startswith( et0, "00:0C:11" ) || |
|---|
| 1116 | startswith( et0, "00:0c:11" ) || |
|---|
| 1117 | startswith( et0, "00:11:22" ) || |
|---|
| 1118 | startswith( et0, "00:0C:90" ) || startswith( et0, "00:0c:90" ) ) |
|---|
| 1119 | { |
|---|
| 1120 | if( !strlen( nvram_safe_get( "phyid_num" ) ) ) |
|---|
| 1121 | { |
|---|
| 1122 | insmod( "switch-core" ); // get phy type |
|---|
| 1123 | insmod( "switch-robo" ); |
|---|
| 1124 | rmmod( "switch-robo" ); |
|---|
| 1125 | rmmod( "switch-core" ); |
|---|
| 1126 | nvram_set( "boardnum", "2" ); |
|---|
| 1127 | nvram_set( "boardtype", "bcm94710dev" ); |
|---|
| 1128 | } |
|---|
| 1129 | if( nvram_match( "phyid_num", "0x00000000" ) ) |
|---|
| 1130 | { |
|---|
| 1131 | cprintf( "router Motorola WE800G v1\n" ); |
|---|
| 1132 | setRouter( "Motorola WE800G v1" ); |
|---|
| 1133 | return ROUTER_MOTOROLA_WE800G; |
|---|
| 1134 | } |
|---|
| 1135 | else // phyid_num == 0xffffffff |
|---|
| 1136 | { |
|---|
| 1137 | cprintf( "router Motorola WR850G v1\n" ); |
|---|
| 1138 | setRouter( "Motorola WR850G v1" ); |
|---|
| 1139 | return ROUTER_MOTOROLA_V1; |
|---|
| 1140 | } |
|---|
| 1141 | } |
|---|
| 1142 | else |
|---|
| 1143 | { |
|---|
| 1144 | cprintf( "router is linksys WRT55AG\n" ); |
|---|
| 1145 | setRouter( "Linksys WRT55AG v1" ); |
|---|
| 1146 | return ROUTER_LINKSYS_WRT55AG; |
|---|
| 1147 | } |
|---|
| 1148 | } |
|---|
| 1149 | #endif |
|---|
| 1150 | if( boardnum == 0 && nvram_match( "boardtype", "0x478" ) |
|---|
| 1151 | && nvram_match( "cardbus", "0" ) && nvram_match( "boardrev", "0x10" ) |
|---|
| 1152 | && nvram_match( "boardflags", "0x110" ) |
|---|
| 1153 | && nvram_match( "melco_id", "32027" ) ) |
|---|
| 1154 | { |
|---|
| 1155 | setRouter( "Buffalo WZR-G144NH" ); |
|---|
| 1156 | return ROUTER_BUFFALO_WZRG144NH; |
|---|
| 1157 | } |
|---|
| 1158 | |
|---|
| 1159 | if( boardnum == 20060330 && nvram_match( "boardtype", "0x0472" ) ) |
|---|
| 1160 | { |
|---|
| 1161 | setRouter( "Buffalo WZR-G300N" ); |
|---|
| 1162 | return ROUTER_BUFFALO_WZRG300N; |
|---|
| 1163 | } |
|---|
| 1164 | #ifndef HAVE_BUFFALO |
|---|
| 1165 | |
|---|
| 1166 | if( boardnum == 8 && |
|---|
| 1167 | nvram_match( "boardtype", "0x0472" ) |
|---|
| 1168 | && nvram_match( "cardbus", "1" ) ) |
|---|
| 1169 | { |
|---|
| 1170 | cprintf( "router is Netgear WNR834B\n" ); |
|---|
| 1171 | setRouter( "Netgear WNR834B" ); |
|---|
| 1172 | return ROUTER_NETGEAR_WNR834B; |
|---|
| 1173 | } |
|---|
| 1174 | |
|---|
| 1175 | if( boardnum == 1 && |
|---|
| 1176 | nvram_match( "boardtype", "0x0472" ) |
|---|
| 1177 | && nvram_match( "cardbus", "1" ) ) |
|---|
| 1178 | { |
|---|
| 1179 | cprintf( "router is Netgear WNR834B v2\n" ); |
|---|
| 1180 | setRouter( "Netgear WNR834B v2" ); |
|---|
| 1181 | return ROUTER_NETGEAR_WNR834BV2; |
|---|
| 1182 | } |
|---|
| 1183 | |
|---|
| 1184 | if( boardnum == 1 && |
|---|
| 1185 | nvram_match( "boardtype", "0x0472" ) |
|---|
| 1186 | && nvram_match( "boardrev", "0x23" ) ) |
|---|
| 1187 | { |
|---|
| 1188 | cprintf( "router is Netgear WNDR-3300\n" ); |
|---|
| 1189 | setRouter( "Netgear WNDR3300" ); |
|---|
| 1190 | return ROUTER_NETGEAR_WNDR3300; |
|---|
| 1191 | } |
|---|
| 1192 | |
|---|
| 1193 | if( boardnum == 42 ) // Get Linksys N models |
|---|
| 1194 | { |
|---|
| 1195 | if( nvram_match( "boot_hw_model", "WRT300N" ) |
|---|
| 1196 | && nvram_match( "boot_hw_ver", "1.1" ) ) |
|---|
| 1197 | { |
|---|
| 1198 | setRouter( "Linksys WRT300N v1.1" ); |
|---|
| 1199 | return ROUTER_WRT300NV11; |
|---|
| 1200 | } |
|---|
| 1201 | else if( nvram_match( "boot_hw_model", "WRT150N" ) |
|---|
| 1202 | && nvram_match( "boot_hw_ver", "1" ) ) |
|---|
| 1203 | { |
|---|
| 1204 | setRouter( "Linksys WRT150N v1" ); |
|---|
| 1205 | return ROUTER_WRT150N; |
|---|
| 1206 | } |
|---|
| 1207 | else if( nvram_match( "boot_hw_model", "WRT150N" ) |
|---|
| 1208 | && nvram_match( "boot_hw_ver", "1.1" ) ) |
|---|
| 1209 | { |
|---|
| 1210 | setRouter( "Linksys WRT150N v1.1" ); |
|---|
| 1211 | // return ROUTER_WRT150NV11; |
|---|
| 1212 | return ROUTER_WRT150N; |
|---|
| 1213 | } |
|---|
| 1214 | else if( nvram_match( "boot_hw_model", "WRT150N" ) |
|---|
| 1215 | && nvram_match( "boot_hw_ver", "1.2" ) ) |
|---|
| 1216 | { |
|---|
| 1217 | setRouter( "Linksys WRT150N v1.2" ); |
|---|
| 1218 | // return ROUTER_WRT150NV12; |
|---|
| 1219 | return ROUTER_WRT150N; |
|---|
| 1220 | } |
|---|
| 1221 | else if( nvram_match( "boot_hw_model", "WRT160N" ) |
|---|
| 1222 | && nvram_match( "boot_hw_ver", "1.0" ) ) |
|---|
| 1223 | { |
|---|
| 1224 | setRouter( "Linksys WRT160N" ); |
|---|
| 1225 | return ROUTER_WRT160N; |
|---|
| 1226 | } |
|---|
| 1227 | else if( nvram_match( "boot_hw_model", "WRT310N" ) |
|---|
| 1228 | && nvram_match( "boot_hw_ver", "1.0" ) ) |
|---|
| 1229 | { |
|---|
| 1230 | setRouter( "Linksys WRT310N" ); |
|---|
| 1231 | return ROUTER_WRT310N; |
|---|
| 1232 | } |
|---|
| 1233 | } |
|---|
| 1234 | |
|---|
| 1235 | if( boardnum == 42 && |
|---|
| 1236 | nvram_match( "boardtype", "0x0472" ) |
|---|
| 1237 | && nvram_match( "cardbus", "1" ) ) |
|---|
| 1238 | { |
|---|
| 1239 | setRouter( "Linksys WRT300N v1" ); |
|---|
| 1240 | return ROUTER_WRT300N; |
|---|
| 1241 | } |
|---|
| 1242 | |
|---|
| 1243 | if( boardnum == 42 && |
|---|
| 1244 | nvram_match( "boardtype", "0x478" ) && nvram_match( "cardbus", "1" ) ) |
|---|
| 1245 | { |
|---|
| 1246 | cprintf( "router is Linksys WRT350N\n" ); |
|---|
| 1247 | setRouter( "Linksys WRT350N" ); |
|---|
| 1248 | return ROUTER_WRT350N; |
|---|
| 1249 | } |
|---|
| 1250 | |
|---|
| 1251 | if( nvram_match( "boardnum", "20070615" ) && |
|---|
| 1252 | nvram_match( "boardtype", "0x478" ) && nvram_match( "cardbus", "0" ) |
|---|
| 1253 | && nvram_match( "switch_type", "BCM5395" ) ) |
|---|
| 1254 | { |
|---|
| 1255 | cprintf( "router is Linksys WRT600N v1.1\n" ); |
|---|
| 1256 | setRouter( "Linksys WRT600N v1.1" ); |
|---|
| 1257 | return ROUTER_WRT600N; |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | if( nvram_match( "boardnum", "20070615" ) && |
|---|
| 1261 | nvram_match( "boardtype", "0x478" ) && nvram_match( "cardbus", "0" ) ) |
|---|
| 1262 | { |
|---|
| 1263 | cprintf( "router is Linksys WRT600N\n" ); |
|---|
| 1264 | setRouter( "Linksys WRT600N" ); |
|---|
| 1265 | return ROUTER_WRT600N; |
|---|
| 1266 | } |
|---|
| 1267 | |
|---|
| 1268 | if( nvram_match( "boardtype", "0x478" ) |
|---|
| 1269 | && nvram_match( "boot_hw_model", "WRT610N" ) ) |
|---|
| 1270 | { |
|---|
| 1271 | cprintf( "router is Linksys WRT610N\n" ); |
|---|
| 1272 | setRouter( "Linksys WRT610N" ); |
|---|
| 1273 | return ROUTER_WRT610N; |
|---|
| 1274 | } |
|---|
| 1275 | |
|---|
| 1276 | if( boardnum == 42 && nvram_match( "boardtype", "bcm94710dev" ) ) |
|---|
| 1277 | { |
|---|
| 1278 | cprintf( "router is Linksys WRT54G v1.x\n" ); |
|---|
| 1279 | setRouter( "Linksys WRT54G v1.x" ); |
|---|
| 1280 | return ROUTER_WRT54G1X; |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | if( ( boardnum == 1 || boardnum == 0 ) |
|---|
| 1284 | && nvram_match( "boardtype", "0x0446" ) ) |
|---|
| 1285 | { |
|---|
| 1286 | cprintf( "router is U.S. Robotics USR5430\n" ); |
|---|
| 1287 | setRouter( "U.S.Robotics USR5430" ); |
|---|
| 1288 | return ROUTER_USR_5430; |
|---|
| 1289 | } |
|---|
| 1290 | |
|---|
| 1291 | if( boardnum == 1 && nvram_match( "boardtype", "0x456" ) |
|---|
| 1292 | && nvram_match( "test_led_gpio", "0" ) ) |
|---|
| 1293 | { |
|---|
| 1294 | cprintf( "router is Netgear WG602 v3\n" ); |
|---|
| 1295 | setRouter( "Netgear WG602 v3" ); |
|---|
| 1296 | return ROUTER_NETGEAR_WG602_V3; |
|---|
| 1297 | } |
|---|
| 1298 | |
|---|
| 1299 | if( boardnum == 10496 && nvram_match( "boardtype", "0x456" ) ) |
|---|
| 1300 | { |
|---|
| 1301 | cprintf( "router is U.S. Robotics USR5461\n" ); |
|---|
| 1302 | setRouter( "U.S.Robotics USR5461" ); |
|---|
| 1303 | return ROUTER_USR_5461; |
|---|
| 1304 | } |
|---|
| 1305 | |
|---|
| 1306 | if( boardnum == 10500 && nvram_match( "boardtype", "0x456" ) ) |
|---|
| 1307 | { |
|---|
| 1308 | cprintf( "router is U.S. Robotics USR5432\n" ); |
|---|
| 1309 | setRouter( "U.S.Robotics USR5432" ); |
|---|
| 1310 | return ROUTER_USR_5461; // should work in the same way |
|---|
| 1311 | } |
|---|
| 1312 | |
|---|
| 1313 | if( boardnum == 10506 && nvram_match( "boardtype", "0x456" ) ) |
|---|
| 1314 | { |
|---|
| 1315 | cprintf( "router is U.S. Robotics USR5451\n" ); |
|---|
| 1316 | setRouter( "U.S.Robotics USR5451" ); |
|---|
| 1317 | return ROUTER_USR_5461; // should work in the same way |
|---|
| 1318 | } |
|---|
| 1319 | |
|---|
| 1320 | if( boardnum == 1024 && nvram_match( "boardtype", "0x0446" ) ) |
|---|
| 1321 | { |
|---|
| 1322 | char *cfe = nvram_safe_get( "cfe_version" ); |
|---|
| 1323 | |
|---|
| 1324 | if( strstr( cfe, "iewsonic" ) ) |
|---|
| 1325 | { |
|---|
| 1326 | cprintf( "router is Viewsonic WAPBR-100\n" ); |
|---|
| 1327 | setRouter( "Viewsonic WAPBR-100" ); |
|---|
| 1328 | return ROUTER_VIEWSONIC_WAPBR_100; |
|---|
| 1329 | } |
|---|
| 1330 | else |
|---|
| 1331 | { |
|---|
| 1332 | cprintf( "router is Linksys WAP54G v2\n" ); |
|---|
| 1333 | setRouter( "Linksys WAP54G v2" ); |
|---|
| 1334 | return ROUTER_WAP54G_V2; |
|---|
| 1335 | } |
|---|
| 1336 | } |
|---|
| 1337 | |
|---|
| 1338 | if( nvram_invmatch( "CFEver", "" ) ) |
|---|
| 1339 | { |
|---|
| 1340 | char *cfe = nvram_safe_get( "CFEver" ); |
|---|
| 1341 | |
|---|
| 1342 | if( !strncmp( cfe, "MotoWR", 6 ) ) |
|---|
| 1343 | { |
|---|
| 1344 | cprintf( "router is motorola\n" ); |
|---|
| 1345 | setRouter( "Motorola WR850G v2/v3" ); |
|---|
| 1346 | return ROUTER_MOTOROLA; |
|---|
| 1347 | } |
|---|
| 1348 | } |
|---|
| 1349 | |
|---|
| 1350 | if( boardnum == 44 && |
|---|
| 1351 | ( nvram_match( "boardtype", "0x0101" ) |
|---|
| 1352 | || nvram_match( "boardtype", "0x0101\r" ) ) ) |
|---|
| 1353 | { |
|---|
| 1354 | char *cfe = nvram_safe_get( "CFEver" ); |
|---|
| 1355 | |
|---|
| 1356 | if( !strncmp( cfe, "GW_WR110G", 9 ) ) |
|---|
| 1357 | { |
|---|
| 1358 | cprintf( "router is Sparklan WX-6615GT\n" ); |
|---|
| 1359 | setRouter( "Sparklan WX-6615GT" ); |
|---|
| 1360 | return ROUTER_DELL_TRUEMOBILE_2300_V2; |
|---|
| 1361 | } |
|---|
| 1362 | else |
|---|
| 1363 | { |
|---|
| 1364 | cprintf( "router is Dell TrueMobile 2300 v2\n" ); |
|---|
| 1365 | setRouter( "Dell TrueMobile 2300 v2" ); |
|---|
| 1366 | return ROUTER_DELL_TRUEMOBILE_2300_V2; |
|---|
| 1367 | } |
|---|
| 1368 | } |
|---|
| 1369 | #endif |
|---|
| 1370 | if( nvram_match( "boardtype", "bcm94710ap" ) ) |
|---|
| 1371 | { |
|---|
| 1372 | cprintf( "router is Buffalo old 4710\n" ); |
|---|
| 1373 | setRouter( "Buffalo WBR-B11" ); |
|---|
| 1374 | return ROUTER_BUFFALO_WBR54G; |
|---|
| 1375 | } |
|---|
| 1376 | #ifndef HAVE_BUFFALO |
|---|
| 1377 | if( nvram_match( "boardtype", "0x048e" ) && |
|---|
| 1378 | nvram_match( "boardrev", "0x35" ) && |
|---|
| 1379 | nvram_match( "sdram_init", "0x000b" ) ) |
|---|
| 1380 | { |
|---|
| 1381 | cprintf( "router is D-Link DIR-320\n" ); |
|---|
| 1382 | setRouter( "D-Link DIR-320" ); |
|---|
| 1383 | // apply some fixes |
|---|
| 1384 | if( nvram_get( "vlan2ports" ) != NULL ) |
|---|
| 1385 | { |
|---|
| 1386 | nvram_unset( "vlan2ports" ); |
|---|
| 1387 | nvram_unset( "vlan2hwname" ); |
|---|
| 1388 | } |
|---|
| 1389 | return ROUTER_DLINK_DIR320; |
|---|
| 1390 | } |
|---|
| 1391 | if( nvram_match( "model_name", "DIR-330" ) && |
|---|
| 1392 | nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1393 | { |
|---|
| 1394 | cprintf( "router is D-Link DIR-330\n" ); |
|---|
| 1395 | setRouter( "D-Link DIR-330" ); |
|---|
| 1396 | nvram_set( "wan_ifnames", "eth0" ); // quirk |
|---|
| 1397 | nvram_set( "wan_ifname", "eth0" ); |
|---|
| 1398 | if( nvram_match( "et0macaddr", "00:90:4c:4e:00:0c" ) ) |
|---|
| 1399 | { |
|---|
| 1400 | FILE *in = fopen( "/dev/mtdblock/1", "rb" ); |
|---|
| 1401 | |
|---|
| 1402 | fseek( in, 0x7a0022, SEEK_SET ); |
|---|
| 1403 | char mac[32]; |
|---|
| 1404 | |
|---|
| 1405 | fread( mac, 32, 1, in ); |
|---|
| 1406 | fclose( in ); |
|---|
| 1407 | mac[17] = 0; |
|---|
| 1408 | if( sv_valid_hwaddr( mac ) ) |
|---|
| 1409 | { |
|---|
| 1410 | nvram_set( "et0macaddr", mac ); |
|---|
| 1411 | fprintf( stderr, "restore D-Link MAC\n" ); |
|---|
| 1412 | nvram_commit( ); |
|---|
| 1413 | sys_reboot( ); |
|---|
| 1414 | } |
|---|
| 1415 | } |
|---|
| 1416 | /* |
|---|
| 1417 | * if (nvram_get("vlan2ports")!=NULL) { nvram_unset("vlan2ports"); |
|---|
| 1418 | * nvram_unset("vlan2hwname"); } |
|---|
| 1419 | */ |
|---|
| 1420 | return ROUTER_DLINK_DIR330; |
|---|
| 1421 | } |
|---|
| 1422 | if( boardnum == 42 && |
|---|
| 1423 | nvram_match( "boardtype", "0x048e" ) |
|---|
| 1424 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1425 | { |
|---|
| 1426 | cprintf( "router is wrt54g v8\n" ); |
|---|
| 1427 | setRouter( "Linksys WRT54Gv8 / GSv7" ); |
|---|
| 1428 | return ROUTER_WRT54G_V8; |
|---|
| 1429 | } |
|---|
| 1430 | |
|---|
| 1431 | if( boardnum == 8 && |
|---|
| 1432 | nvram_match( "boardtype", "0x048e" ) |
|---|
| 1433 | && nvram_match( "boardrev", "0x11" ) ) |
|---|
| 1434 | { |
|---|
| 1435 | cprintf( "router is ALLNET01\n" ); |
|---|
| 1436 | setRouter( "ALLNET01" ); |
|---|
| 1437 | return ROUTER_ALLNET01; |
|---|
| 1438 | } |
|---|
| 1439 | |
|---|
| 1440 | if( boardnum == 1 && |
|---|
| 1441 | nvram_match( "boardtype", "0x048e" ) |
|---|
| 1442 | && nvram_match( "boardrev", "0x11" ) ) |
|---|
| 1443 | { |
|---|
| 1444 | cprintf( "router is Netgear WG602 v4\n" ); |
|---|
| 1445 | setRouter( "Netgear WG602 v4" ); |
|---|
| 1446 | return ROUTER_NETGEAR_WG602_V4; |
|---|
| 1447 | } |
|---|
| 1448 | |
|---|
| 1449 | if( boardnum == 1 && |
|---|
| 1450 | nvram_match( "boardtype", "0x048e" ) |
|---|
| 1451 | && nvram_match( "boardrev", "0x35" ) |
|---|
| 1452 | && nvram_match( "parefldovoltage", "0x28" ) ) |
|---|
| 1453 | { |
|---|
| 1454 | cprintf( "router is netcore nw618\n" ); |
|---|
| 1455 | setRouter( "NetCore NW618" ); |
|---|
| 1456 | return ROUTER_WRT54G; |
|---|
| 1457 | } |
|---|
| 1458 | |
|---|
| 1459 | if( boardnum == 42 && |
|---|
| 1460 | nvram_match( "boardtype", "0x048E" ) |
|---|
| 1461 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1462 | { |
|---|
| 1463 | cprintf( "router is Linksys WRH54G\n" ); |
|---|
| 1464 | setRouter( "Linksys WRH54G" ); |
|---|
| 1465 | return ROUTER_LINKSYS_WRH54G; |
|---|
| 1466 | } |
|---|
| 1467 | |
|---|
| 1468 | if( nvram_match( "boardnum", "00" ) && |
|---|
| 1469 | nvram_match( "boardtype", "0x048E" ) |
|---|
| 1470 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1471 | { |
|---|
| 1472 | cprintf( "router is Linksys WRT54G v8.1\n" ); |
|---|
| 1473 | setRouter( "Linksys WRT54G v8.1" ); |
|---|
| 1474 | return ROUTER_WRT54G_V81; |
|---|
| 1475 | } |
|---|
| 1476 | |
|---|
| 1477 | if( boardnum == 45 && nvram_match( "boardtype", "0x456" ) ) |
|---|
| 1478 | { |
|---|
| 1479 | cprintf( "router is Asus WL-520G\n" ); |
|---|
| 1480 | setRouter( "Asus WL-520G" ); |
|---|
| 1481 | return ROUTER_ASUS_WL520G; |
|---|
| 1482 | } |
|---|
| 1483 | |
|---|
| 1484 | if( boardnum == 45 && |
|---|
| 1485 | nvram_match( "boardtype", "0x48E" ) |
|---|
| 1486 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1487 | { |
|---|
| 1488 | char *hwver = nvram_safe_get( "hardware_version" ); |
|---|
| 1489 | |
|---|
| 1490 | if( startswith( hwver, "WL500GPV2" ) ) |
|---|
| 1491 | { |
|---|
| 1492 | cprintf( "router is Asus WL-500G Premium V2\n" ); |
|---|
| 1493 | setRouter( "Asus WL-500G Premium V2" ); |
|---|
| 1494 | return ROUTER_ASUS_WL500G_PRE_V2; |
|---|
| 1495 | } |
|---|
| 1496 | else |
|---|
| 1497 | { |
|---|
| 1498 | cprintf( "router is Asus WL-520GU/GC\n" ); |
|---|
| 1499 | setRouter( "Asus WL-520GU/GC" ); |
|---|
| 1500 | return ROUTER_ASUS_WL520GUGC; |
|---|
| 1501 | } |
|---|
| 1502 | } |
|---|
| 1503 | |
|---|
| 1504 | if( ( boardnum == 83258 || nvram_match( "boardnum", "0x01" ) ) && |
|---|
| 1505 | nvram_match( "boardtype", "0x48E" ) |
|---|
| 1506 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1507 | { |
|---|
| 1508 | cprintf( "router is Netgear WGR614v8/v9/L\n" ); |
|---|
| 1509 | setRouter( "Netgear WGR614v8/v9/L" ); |
|---|
| 1510 | return ROUTER_NETGEAR_WGR614L; |
|---|
| 1511 | } |
|---|
| 1512 | |
|---|
| 1513 | if( boardnum == 56 && |
|---|
| 1514 | nvram_match( "boardtype", "0x456" ) |
|---|
| 1515 | && nvram_match( "boardrev", "0x10" ) ) |
|---|
| 1516 | { |
|---|
| 1517 | cprintf( "router is wtr54gs\n" ); |
|---|
| 1518 | setRouter( "Linksys WTR54GS" ); |
|---|
| 1519 | return ROUTER_LINKSYS_WTR54GS; |
|---|
| 1520 | } |
|---|
| 1521 | |
|---|
| 1522 | if( nvram_match( "boardnum", "WAP54GV3_8M_0614" ) |
|---|
| 1523 | && ( nvram_match( "boardtype", "0x0467" ) |
|---|
| 1524 | || nvram_match( "boardtype", "0x467" ) ) |
|---|
| 1525 | && nvram_match( "WAPver", "3" ) ) |
|---|
| 1526 | { |
|---|
| 1527 | cprintf( "router is WAP54G v3.x\n" ); |
|---|
| 1528 | setRouter( "Linksys WAP54G v3.x" ); |
|---|
| 1529 | return ROUTER_WAP54G_V3; |
|---|
| 1530 | } |
|---|
| 1531 | |
|---|
| 1532 | setRouter( "Linksys WRT54G/GL/GS" ); |
|---|
| 1533 | cprintf( "router is wrt54g\n" ); |
|---|
| 1534 | return ROUTER_WRT54G; |
|---|
| 1535 | #else |
|---|
| 1536 | eval( "event", "3", "1", "15" ); |
|---|
| 1537 | return 0; |
|---|
| 1538 | #endif |
|---|
| 1539 | #endif |
|---|
| 1540 | |
|---|
| 1541 | } |
|---|
| 1542 | static int router_type = -1; |
|---|
| 1543 | int getRouterBrand( ) |
|---|
| 1544 | { |
|---|
| 1545 | if( router_type == -1 ) |
|---|
| 1546 | router_type = internal_getRouterBrand( ); |
|---|
| 1547 | return router_type; |
|---|
| 1548 | } |
|---|
| 1549 | |
|---|
| 1550 | int get_ppp_pid( char *file ) |
|---|
| 1551 | { |
|---|
| 1552 | char buf[80]; |
|---|
| 1553 | int pid = -1; |
|---|
| 1554 | |
|---|
| 1555 | if( file_to_buf( file, buf, sizeof( buf ) ) ) |
|---|
| 1556 | { |
|---|
| 1557 | char tmp[80], tmp1[80]; |
|---|
| 1558 | |
|---|
| 1559 | snprintf( tmp, sizeof( tmp ), "/var/run/%s.pid", buf ); |
|---|
| 1560 | file_to_buf( tmp, tmp1, sizeof( tmp1 ) ); |
|---|
| 1561 | pid = atoi( tmp1 ); |
|---|
| 1562 | } |
|---|
| 1563 | return pid; |
|---|
| 1564 | } |
|---|
| 1565 | |
|---|
| 1566 | int check_wan_link( int num ) |
|---|
| 1567 | { |
|---|
| 1568 | int wan_link = 0; |
|---|
| 1569 | |
|---|
| 1570 | if( nvram_match( "wan_proto", "pptp" ) |
|---|
| 1571 | || nvram_match( "wan_proto", "l2tp" ) |
|---|
| 1572 | || nvram_match( "wan_proto", "pppoe" ) |
|---|
| 1573 | || nvram_match( "wan_proto", "heartbeat" ) ) |
|---|
| 1574 | { |
|---|
| 1575 | FILE *fp; |
|---|
| 1576 | char filename[80]; |
|---|
| 1577 | char *name; |
|---|
| 1578 | |
|---|
| 1579 | if( num == 0 ) |
|---|
| 1580 | strcpy( filename, "/tmp/ppp/link" ); |
|---|
| 1581 | if( ( fp = fopen( filename, "r" ) ) ) |
|---|
| 1582 | { |
|---|
| 1583 | int pid = -1; |
|---|
| 1584 | |
|---|
| 1585 | fclose( fp ); |
|---|
| 1586 | if( nvram_match( "wan_proto", "heartbeat" ) ) |
|---|
| 1587 | { |
|---|
| 1588 | char buf[20]; |
|---|
| 1589 | |
|---|
| 1590 | file_to_buf( "/tmp/ppp/link", buf, sizeof( buf ) ); |
|---|
| 1591 | pid = atoi( buf ); |
|---|
| 1592 | } |
|---|
| 1593 | else |
|---|
| 1594 | pid = get_ppp_pid( filename ); |
|---|
| 1595 | |
|---|
| 1596 | name = find_name_by_proc( pid ); |
|---|
| 1597 | if( !strncmp( name, "pppoecd", 7 ) || // for PPPoE |
|---|
| 1598 | !strncmp( name, "pppd", 4 ) || // for PPTP |
|---|
| 1599 | !strncmp( name, "bpalogin", 8 ) ) // for HeartBeat |
|---|
| 1600 | wan_link = 1; // connect |
|---|
| 1601 | else |
|---|
| 1602 | { |
|---|
| 1603 | printf( "The %s had been died, remove %s\n", |
|---|
| 1604 | nvram_safe_get( "wan_proto" ), filename ); |
|---|
| 1605 | wan_link = 0; // For some reason, the pppoed had been died, |
|---|
| 1606 | // by link file still exist. |
|---|
| 1607 | unlink( filename ); |
|---|
| 1608 | } |
|---|
| 1609 | } |
|---|
| 1610 | } |
|---|
| 1611 | else |
|---|
| 1612 | { |
|---|
| 1613 | if( nvram_invmatch( "wan_ipaddr", "0.0.0.0" ) ) |
|---|
| 1614 | wan_link = 1; |
|---|
| 1615 | } |
|---|
| 1616 | |
|---|
| 1617 | return wan_link; |
|---|
| 1618 | } |
|---|
| 1619 | |
|---|
| 1620 | /* |
|---|
| 1621 | * Find process name by pid from /proc directory |
|---|
| 1622 | */ |
|---|
| 1623 | char *find_name_by_proc( int pid ) |
|---|
| 1624 | { |
|---|
| 1625 | FILE *fp; |
|---|
| 1626 | char line[254]; |
|---|
| 1627 | char filename[80]; |
|---|
| 1628 | static char name[80]; |
|---|
| 1629 | |
|---|
| 1630 | snprintf( filename, sizeof( filename ), "/proc/%d/status", pid ); |
|---|
| 1631 | |
|---|
| 1632 | if( ( fp = fopen( filename, "r" ) ) ) |
|---|
| 1633 | { |
|---|
| 1634 | fgets( line, sizeof( line ), fp ); |
|---|
| 1635 | /* |
|---|
| 1636 | * Buffer should contain a string like "Name: binary_name" |
|---|
| 1637 | */ |
|---|
| 1638 | sscanf( line, "%*s %s", name ); |
|---|
| 1639 | fclose( fp ); |
|---|
| 1640 | return name; |
|---|
| 1641 | } |
|---|
| 1642 | |
|---|
| 1643 | return ""; |
|---|
| 1644 | } |
|---|
| 1645 | |
|---|
| 1646 | int diag_led_4702( int type, int act ) |
|---|
| 1647 | { |
|---|
| 1648 | |
|---|
| 1649 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || 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) |
|---|
| 1650 | return 0; |
|---|
| 1651 | #else |
|---|
| 1652 | if( act == START_LED ) |
|---|
| 1653 | { |
|---|
| 1654 | switch ( type ) |
|---|
| 1655 | { |
|---|
| 1656 | case DMZ: |
|---|
| 1657 | system2( "echo 1 > /proc/sys/diag" ); |
|---|
| 1658 | break; |
|---|
| 1659 | } |
|---|
| 1660 | } |
|---|
| 1661 | else |
|---|
| 1662 | { |
|---|
| 1663 | switch ( type ) |
|---|
| 1664 | { |
|---|
| 1665 | case DMZ: |
|---|
| 1666 | system2( "echo 0 > /proc/sys/diag" ); |
|---|
| 1667 | break; |
|---|
| 1668 | } |
|---|
| 1669 | } |
|---|
| 1670 | return 0; |
|---|
| 1671 | #endif |
|---|
| 1672 | } |
|---|
| 1673 | |
|---|
| 1674 | int C_led_4702( int i ) |
|---|
| 1675 | { |
|---|
| 1676 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || 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) |
|---|
| 1677 | return 0; |
|---|
| 1678 | #else |
|---|
| 1679 | FILE *fp; |
|---|
| 1680 | char string[10]; |
|---|
| 1681 | int flg; |
|---|
| 1682 | |
|---|
| 1683 | memset( string, 0, 10 ); |
|---|
| 1684 | /* |
|---|
| 1685 | * get diag before set |
|---|
| 1686 | */ |
|---|
| 1687 | if( ( fp = fopen( "/proc/sys/diag", "r" ) ) ) |
|---|
| 1688 | { |
|---|
| 1689 | fgets( string, sizeof( string ), fp ); |
|---|
| 1690 | fclose( fp ); |
|---|
| 1691 | } |
|---|
| 1692 | else |
|---|
| 1693 | perror( "/proc/sys/diag" ); |
|---|
| 1694 | |
|---|
| 1695 | if( i ) |
|---|
| 1696 | flg = atoi( string ) | 0x10; |
|---|
| 1697 | else |
|---|
| 1698 | flg = atoi( string ) & 0xef; |
|---|
| 1699 | |
|---|
| 1700 | memset( string, 0, 10 ); |
|---|
| 1701 | sprintf( string, "%d", flg ); |
|---|
| 1702 | if( ( fp = fopen( "/proc/sys/diag", "w" ) ) ) |
|---|
| 1703 | { |
|---|
| 1704 | fputs( string, fp ); |
|---|
| 1705 | fclose( fp ); |
|---|
| 1706 | } |
|---|
| 1707 | else |
|---|
| 1708 | perror( "/proc/sys/diag" ); |
|---|
| 1709 | |
|---|
| 1710 | return 0; |
|---|
| 1711 | #endif |
|---|
| 1712 | } |
|---|
| 1713 | |
|---|
| 1714 | unsigned int read_gpio( char *device ) |
|---|
| 1715 | { |
|---|
| 1716 | FILE *fp; |
|---|
| 1717 | unsigned int val; |
|---|
| 1718 | |
|---|
| 1719 | if( ( fp = fopen( device, "r" ) ) ) |
|---|
| 1720 | { |
|---|
| 1721 | fread( &val, 4, 1, fp ); |
|---|
| 1722 | fclose( fp ); |
|---|
| 1723 | // fprintf(stderr, "----- gpio %s = [%X]\n",device,val); |
|---|
| 1724 | return val; |
|---|
| 1725 | } |
|---|
| 1726 | else |
|---|
| 1727 | { |
|---|
| 1728 | perror( device ); |
|---|
| 1729 | return 0; |
|---|
| 1730 | } |
|---|
| 1731 | } |
|---|
| 1732 | |
|---|
| 1733 | unsigned int write_gpio( char *device, unsigned int val ) |
|---|
| 1734 | { |
|---|
| 1735 | FILE *fp; |
|---|
| 1736 | |
|---|
| 1737 | if( ( fp = fopen( device, "w" ) ) ) |
|---|
| 1738 | { |
|---|
| 1739 | fwrite( &val, 4, 1, fp ); |
|---|
| 1740 | fclose( fp ); |
|---|
| 1741 | // fprintf(stderr, "----- set gpio %s = [%X]\n",device,val); |
|---|
| 1742 | return 1; |
|---|
| 1743 | } |
|---|
| 1744 | else |
|---|
| 1745 | { |
|---|
| 1746 | perror( device ); |
|---|
| 1747 | return 0; |
|---|
| 1748 | } |
|---|
| 1749 | } |
|---|
| 1750 | |
|---|
| 1751 | static char hw_error = 0; |
|---|
| 1752 | int diag_led_4704( int type, int act ) |
|---|
| 1753 | { |
|---|
| 1754 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || 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) |
|---|
| 1755 | return 0; |
|---|
| 1756 | #else |
|---|
| 1757 | unsigned int control, in, outen, out; |
|---|
| 1758 | |
|---|
| 1759 | #ifdef BCM94712AGR |
|---|
| 1760 | /* |
|---|
| 1761 | * The router will crash, if we load the code into broadcom demo board. |
|---|
| 1762 | */ |
|---|
| 1763 | return 1; |
|---|
| 1764 | #endif |
|---|
| 1765 | // int brand; |
|---|
| 1766 | control = read_gpio( "/dev/gpio/control" ); |
|---|
| 1767 | in = read_gpio( "/dev/gpio/in" ); |
|---|
| 1768 | out = read_gpio( "/dev/gpio/out" ); |
|---|
| 1769 | outen = read_gpio( "/dev/gpio/outen" ); |
|---|
| 1770 | |
|---|
| 1771 | write_gpio( "/dev/gpio/outen", ( outen & 0x7c ) | 0x83 ); |
|---|
| 1772 | switch ( type ) |
|---|
| 1773 | { |
|---|
| 1774 | case DIAG: // GPIO 1 |
|---|
| 1775 | if( hw_error ) |
|---|
| 1776 | { |
|---|
| 1777 | write_gpio( "/dev/gpio/out", ( out & 0x7c ) | 0x00 ); |
|---|
| 1778 | return 1; |
|---|
| 1779 | } |
|---|
| 1780 | |
|---|
| 1781 | if( act == STOP_LED ) |
|---|
| 1782 | { // stop blinking |
|---|
| 1783 | write_gpio( "/dev/gpio/out", ( out & 0x7c ) | 0x83 ); |
|---|
| 1784 | // cprintf("tallest:=====( DIAG STOP_LED !!)=====\n"); |
|---|
| 1785 | } |
|---|
| 1786 | else if( act == START_LED ) |
|---|
| 1787 | { // start blinking |
|---|
| 1788 | write_gpio( "/dev/gpio/out", ( out & 0x7c ) | 0x81 ); |
|---|
| 1789 | // cprintf("tallest:=====( DIAG START_LED !!)=====\n"); |
|---|
| 1790 | } |
|---|
| 1791 | else if( act == MALFUNCTION_LED ) |
|---|
| 1792 | { // start blinking |
|---|
| 1793 | write_gpio( "/dev/gpio/out", ( out & 0x7c ) | 0x00 ); |
|---|
| 1794 | hw_error = 1; |
|---|
| 1795 | // cprintf("tallest:=====( DIAG MALFUNCTION_LED !!)=====\n"); |
|---|
| 1796 | } |
|---|
| 1797 | break; |
|---|
| 1798 | |
|---|
| 1799 | } |
|---|
| 1800 | return 1; |
|---|
| 1801 | #endif |
|---|
| 1802 | } |
|---|
| 1803 | |
|---|
| 1804 | int diag_led_4712( int type, int act ) |
|---|
| 1805 | { |
|---|
| 1806 | unsigned int control, in, outen, out, ctr_mask, out_mask; |
|---|
| 1807 | |
|---|
| 1808 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || 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) |
|---|
| 1809 | return 0; |
|---|
| 1810 | #else |
|---|
| 1811 | |
|---|
| 1812 | #ifdef BCM94712AGR |
|---|
| 1813 | /* |
|---|
| 1814 | * The router will crash, if we load the code into broadcom demo board. |
|---|
| 1815 | */ |
|---|
| 1816 | return 1; |
|---|
| 1817 | #endif |
|---|
| 1818 | control = read_gpio( "/dev/gpio/control" ); |
|---|
| 1819 | in = read_gpio( "/dev/gpio/in" ); |
|---|
| 1820 | out = read_gpio( "/dev/gpio/out" ); |
|---|
| 1821 | outen = read_gpio( "/dev/gpio/outen" ); |
|---|
| 1822 | |
|---|
| 1823 | ctr_mask = ~( 1 << type ); |
|---|
| 1824 | out_mask = ( 1 << type ); |
|---|
| 1825 | |
|---|
| 1826 | write_gpio( "/dev/gpio/control", control & ctr_mask ); |
|---|
| 1827 | write_gpio( "/dev/gpio/outen", outen | out_mask ); |
|---|
| 1828 | |
|---|
| 1829 | if( act == STOP_LED ) |
|---|
| 1830 | { // stop blinking |
|---|
| 1831 | // cprintf("%s: Stop GPIO %d\n", __FUNCTION__, type); |
|---|
| 1832 | write_gpio( "/dev/gpio/out", out | out_mask ); |
|---|
| 1833 | } |
|---|
| 1834 | else if( act == START_LED ) |
|---|
| 1835 | { // start blinking |
|---|
| 1836 | // cprintf("%s: Start GPIO %d\n", __FUNCTION__, type); |
|---|
| 1837 | write_gpio( "/dev/gpio/out", out & ctr_mask ); |
|---|
| 1838 | } |
|---|
| 1839 | |
|---|
| 1840 | return 1; |
|---|
| 1841 | #endif |
|---|
| 1842 | } |
|---|
| 1843 | |
|---|
| 1844 | int C_led_4712( int i ) |
|---|
| 1845 | { |
|---|
| 1846 | if( i == 1 ) |
|---|
| 1847 | return diag_led( DIAG, START_LED ); |
|---|
| 1848 | else |
|---|
| 1849 | return diag_led( DIAG, STOP_LED ); |
|---|
| 1850 | } |
|---|
| 1851 | |
|---|
| 1852 | int C_led( int i ) |
|---|
| 1853 | { |
|---|
| 1854 | // show_hw_type(check_hw_type()); |
|---|
| 1855 | int brand = getRouterBrand( ); |
|---|
| 1856 | |
|---|
| 1857 | if( brand == ROUTER_WRT54G1X || brand == ROUTER_LINKSYS_WRT55AG ) |
|---|
| 1858 | return C_led_4702( i ); |
|---|
| 1859 | else if( brand == ROUTER_WRT54G ) |
|---|
| 1860 | return C_led_4712( i ); |
|---|
| 1861 | else |
|---|
| 1862 | return 0; |
|---|
| 1863 | } |
|---|
| 1864 | |
|---|
| 1865 | int diag_led( int type, int act ) |
|---|
| 1866 | { |
|---|
| 1867 | int brand = getRouterBrand( ); |
|---|
| 1868 | |
|---|
| 1869 | if( brand == ROUTER_WRT54G || brand == ROUTER_WRT54G3G |
|---|
| 1870 | || brand == ROUTER_WRT300NV11 ) |
|---|
| 1871 | return diag_led_4712( type, act ); |
|---|
| 1872 | else if( brand == ROUTER_WRT54G1X || brand == ROUTER_LINKSYS_WRT55AG ) |
|---|
| 1873 | return diag_led_4702( type, act ); |
|---|
| 1874 | else if( ( brand == ROUTER_WRTSL54GS || brand == ROUTER_WRT350N |
|---|
| 1875 | || brand == ROUTER_WRT310N |
|---|
| 1876 | || brand == ROUTER_BUFFALO_WZRG144NH ) && type == DIAG ) |
|---|
| 1877 | return diag_led_4704( type, act ); |
|---|
| 1878 | else |
|---|
| 1879 | { |
|---|
| 1880 | if( type == DMZ ) |
|---|
| 1881 | { |
|---|
| 1882 | if( act == START_LED ) |
|---|
| 1883 | return led_control( LED_DMZ, LED_ON ); |
|---|
| 1884 | if( act == STOP_LED ) |
|---|
| 1885 | return led_control( LED_DMZ, LED_OFF ); |
|---|
| 1886 | return 1; |
|---|
| 1887 | } |
|---|
| 1888 | } |
|---|
| 1889 | return 0; |
|---|
| 1890 | } |
|---|
| 1891 | |
|---|
| 1892 | #ifdef HAVE_MADWIFI |
|---|
| 1893 | static char *stalist[] = { |
|---|
| 1894 | "ath0", "ath1", "ath2", "ath3", "ath4", "ath5", "ath6", "ath8", "ath9" |
|---|
| 1895 | }; |
|---|
| 1896 | char *getSTA( void ) |
|---|
| 1897 | { |
|---|
| 1898 | |
|---|
| 1899 | #ifdef HAVE_WAVESAT |
|---|
| 1900 | if( nvram_match( "ofdm_mode", "sta" ) ) |
|---|
| 1901 | return "ofdm"; |
|---|
| 1902 | #endif |
|---|
| 1903 | int c = getifcount( "wifi" ); |
|---|
| 1904 | int i; |
|---|
| 1905 | |
|---|
| 1906 | for( i = 0; i < c; i++ ) |
|---|
| 1907 | { |
|---|
| 1908 | char mode[32]; |
|---|
| 1909 | char netmode[32]; |
|---|
| 1910 | |
|---|
| 1911 | sprintf( mode, "ath%d_mode", i ); |
|---|
| 1912 | sprintf( netmode, "ath%d_net_mode", i ); |
|---|
| 1913 | if( nvram_match( mode, "sta" ) |
|---|
| 1914 | && !nvram_match( netmode, "disabled" ) ) |
|---|
| 1915 | { |
|---|
| 1916 | return stalist[i]; |
|---|
| 1917 | } |
|---|
| 1918 | |
|---|
| 1919 | } |
|---|
| 1920 | return NULL; |
|---|
| 1921 | } |
|---|
| 1922 | |
|---|
| 1923 | char *getWET( void ) |
|---|
| 1924 | { |
|---|
| 1925 | #ifdef HAVE_WAVESAT |
|---|
| 1926 | if( nvram_match( "ofdm_mode", "bridge" ) ) |
|---|
| 1927 | return "ofdm"; |
|---|
| 1928 | #endif |
|---|
| 1929 | int c = getifcount( "wifi" ); |
|---|
| 1930 | int i; |
|---|
| 1931 | |
|---|
| 1932 | for( i = 0; i < c; i++ ) |
|---|
| 1933 | { |
|---|
| 1934 | char mode[32]; |
|---|
| 1935 | char netmode[32]; |
|---|
| 1936 | |
|---|
| 1937 | sprintf( mode, "ath%d_mode", i ); |
|---|
| 1938 | sprintf( netmode, "ath%d_net_mode", i ); |
|---|
| 1939 | if( nvram_match( mode, "wet" ) |
|---|
| 1940 | && !nvram_match( netmode, "disabled" ) ) |
|---|
| 1941 | { |
|---|
| 1942 | return stalist[i]; |
|---|
| 1943 | } |
|---|
| 1944 | |
|---|
| 1945 | } |
|---|
| 1946 | return NULL; |
|---|
| 1947 | } |
|---|
| 1948 | #else |
|---|
| 1949 | char *getSTA( ) |
|---|
| 1950 | { |
|---|
| 1951 | int c = get_wl_instances( ); |
|---|
| 1952 | int i; |
|---|
| 1953 | |
|---|
| 1954 | for( i = 0; i < c; i++ ) |
|---|
| 1955 | { |
|---|
| 1956 | if( nvram_nmatch( "sta", "wl%d_mode", i ) |
|---|
| 1957 | || nvram_nmatch( "apsta", "wl%d_mode", i ) ) |
|---|
| 1958 | { |
|---|
| 1959 | if( !nvram_nmatch( "disabled", "wl%d_net_mode", i ) ) |
|---|
| 1960 | return get_wl_instance_name( i ); |
|---|
| 1961 | // else |
|---|
| 1962 | // return nvram_nget ("wl%d_ifname", i); |
|---|
| 1963 | } |
|---|
| 1964 | |
|---|
| 1965 | } |
|---|
| 1966 | return NULL; |
|---|
| 1967 | } |
|---|
| 1968 | |
|---|
| 1969 | char *getWET( ) |
|---|
| 1970 | { |
|---|
| 1971 | int c = get_wl_instances( ); |
|---|
| 1972 | int i; |
|---|
| 1973 | |
|---|
| 1974 | for( i = 0; i < c; i++ ) |
|---|
| 1975 | { |
|---|
| 1976 | if( nvram_nmatch( "wet", "wl%d_mode", i ) |
|---|
| 1977 | || nvram_nmatch( "apstawet", "wl%d_mode", i ) ) |
|---|
| 1978 | { |
|---|
| 1979 | if( !nvram_nmatch( "disabled", "wl%d_net_mode", i ) ) |
|---|
| 1980 | return get_wl_instance_name( i ); |
|---|
| 1981 | // else |
|---|
| 1982 | // return nvram_nget ("wl%d_ifname", i); |
|---|
| 1983 | |
|---|
| 1984 | } |
|---|
| 1985 | |
|---|
| 1986 | } |
|---|
| 1987 | return NULL; |
|---|
| 1988 | } |
|---|
| 1989 | |
|---|
| 1990 | #endif |
|---|
| 1991 | // note - broadcast addr returned in ipaddr |
|---|
| 1992 | void get_broadcast( char *ipaddr, char *netmask ) |
|---|
| 1993 | { |
|---|
| 1994 | int ip2[4], mask2[4]; |
|---|
| 1995 | unsigned char ip[4], mask[4]; |
|---|
| 1996 | |
|---|
| 1997 | if( !ipaddr || !netmask ) |
|---|
| 1998 | return; |
|---|
| 1999 | |
|---|
| 2000 | sscanf( ipaddr, "%d.%d.%d.%d", &ip2[0], &ip2[1], &ip2[2], &ip2[3] ); |
|---|
| 2001 | sscanf( netmask, "%d.%d.%d.%d", &mask2[0], &mask2[1], &mask2[2], |
|---|
| 2002 | &mask2[3] ); |
|---|
| 2003 | int i = 0; |
|---|
| 2004 | |
|---|
| 2005 | for( i = 0; i < 4; i++ ) |
|---|
| 2006 | { |
|---|
| 2007 | ip[i] = ip2[i]; |
|---|
| 2008 | mask[i] = mask2[i]; |
|---|
| 2009 | // ip[i] = (ip[i] & mask[i]) | !mask[i]; |
|---|
| 2010 | ip[i] = ( ip[i] & mask[i] ) | ( 0xff & ~mask[i] ); |
|---|
| 2011 | } |
|---|
| 2012 | |
|---|
| 2013 | sprintf( ipaddr, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3] ); |
|---|
| 2014 | #ifdef WDS_DEBUG |
|---|
| 2015 | fprintf( fp, "get_broadcast return %s\n", value ); |
|---|
| 2016 | #endif |
|---|
| 2017 | |
|---|
| 2018 | } |
|---|
| 2019 | |
|---|
| 2020 | char *get_wan_face( void ) |
|---|
| 2021 | { |
|---|
| 2022 | static char localwanface[IFNAMSIZ]; |
|---|
| 2023 | |
|---|
| 2024 | /* |
|---|
| 2025 | * if (nvram_match ("pptpd_client_enable", "1")) { strncpy (localwanface, |
|---|
| 2026 | * "ppp0", IFNAMSIZ); return localwanface; } |
|---|
| 2027 | */ |
|---|
| 2028 | if( nvram_match( "wan_proto", "pptp" ) |
|---|
| 2029 | || nvram_match( "wan_proto", "l2tp" ) |
|---|
| 2030 | || nvram_match( "wan_proto", "pppoe" ) ) |
|---|
| 2031 | { |
|---|
| 2032 | if( nvram_match( "pppd_pppifname", "" ) ) |
|---|
| 2033 | strncpy( localwanface, "ppp0", IFNAMSIZ ); |
|---|
| 2034 | else |
|---|
| 2035 | strncpy( localwanface, nvram_safe_get( "pppd_pppifname" ), |
|---|
| 2036 | IFNAMSIZ ); |
|---|
| 2037 | } |
|---|
| 2038 | #ifndef HAVE_MADWIFI |
|---|
| 2039 | else if( getSTA( ) ) |
|---|
| 2040 | { |
|---|
| 2041 | strcpy( localwanface, getSTA( ) ); |
|---|
| 2042 | } |
|---|
| 2043 | #else |
|---|
| 2044 | else if( getSTA( ) ) |
|---|
| 2045 | { |
|---|
| 2046 | if( nvram_match( "wifi_bonding", "1" ) ) |
|---|
| 2047 | strcpy( localwanface, "bond0" ); |
|---|
| 2048 | else |
|---|
| 2049 | strcpy( localwanface, getSTA( ) ); |
|---|
| 2050 | } |
|---|
| 2051 | #endif |
|---|
| 2052 | else |
|---|
| 2053 | strncpy( localwanface, nvram_safe_get( "wan_ifname" ), IFNAMSIZ ); |
|---|
| 2054 | |
|---|
| 2055 | return localwanface; |
|---|
| 2056 | } |
|---|
| 2057 | static int _pidof( const char *name, pid_t ** pids ) |
|---|
| 2058 | { |
|---|
| 2059 | const char *p; |
|---|
| 2060 | char *e; |
|---|
| 2061 | DIR *dir; |
|---|
| 2062 | struct dirent *de; |
|---|
| 2063 | pid_t i; |
|---|
| 2064 | int count; |
|---|
| 2065 | char buf[256]; |
|---|
| 2066 | |
|---|
| 2067 | count = 0; |
|---|
| 2068 | *pids = NULL; |
|---|
| 2069 | if( ( p = strchr( name, '/' ) ) != NULL ) |
|---|
| 2070 | name = p + 1; |
|---|
| 2071 | if( ( dir = opendir( "/proc" ) ) != NULL ) |
|---|
| 2072 | { |
|---|
| 2073 | while( ( de = readdir( dir ) ) != NULL ) |
|---|
| 2074 | { |
|---|
| 2075 | i = strtol( de->d_name, &e, 10 ); |
|---|
| 2076 | if( *e != 0 ) |
|---|
| 2077 | continue; |
|---|
| 2078 | if( strcmp( name, psname( i, buf, sizeof( buf ) ) ) == 0 ) |
|---|
| 2079 | { |
|---|
| 2080 | if( ( *pids = |
|---|
| 2081 | realloc( *pids, |
|---|
| 2082 | sizeof( pid_t ) * ( count + 1 ) ) ) == NULL ) |
|---|
| 2083 | { |
|---|
| 2084 | return -1; |
|---|
| 2085 | } |
|---|
| 2086 | ( *pids )[count++] = i; |
|---|
| 2087 | } |
|---|
| 2088 | } |
|---|
| 2089 | } |
|---|
| 2090 | closedir( dir ); |
|---|
| 2091 | return count; |
|---|
| 2092 | } |
|---|
| 2093 | |
|---|
| 2094 | int pidof( const char *name ) |
|---|
| 2095 | { |
|---|
| 2096 | pid_t *pids; |
|---|
| 2097 | pid_t p; |
|---|
| 2098 | |
|---|
| 2099 | if( _pidof( name, &pids ) > 0 ) |
|---|
| 2100 | { |
|---|
| 2101 | p = *pids; |
|---|
| 2102 | free( pids ); |
|---|
| 2103 | return p; |
|---|
| 2104 | } |
|---|
| 2105 | return -1; |
|---|
| 2106 | } |
|---|
| 2107 | |
|---|
| 2108 | int killall( const char *name, int sig ) |
|---|
| 2109 | { |
|---|
| 2110 | pid_t *pids; |
|---|
| 2111 | int i; |
|---|
| 2112 | int r; |
|---|
| 2113 | |
|---|
| 2114 | if( ( i = _pidof( name, &pids ) ) > 0 ) |
|---|
| 2115 | { |
|---|
| 2116 | r = 0; |
|---|
| 2117 | do |
|---|
| 2118 | { |
|---|
| 2119 | r |= kill( pids[--i], sig ); |
|---|
| 2120 | } |
|---|
| 2121 | while( i > 0 ); |
|---|
| 2122 | free( pids ); |
|---|
| 2123 | return r; |
|---|
| 2124 | } |
|---|
| 2125 | return -2; |
|---|
| 2126 | } |
|---|
| 2127 | |
|---|
| 2128 | void set_ip_forward( char c ) |
|---|
| 2129 | { |
|---|
| 2130 | FILE *fp; |
|---|
| 2131 | |
|---|
| 2132 | if( ( fp = fopen( "/proc/sys/net/ipv4/ip_forward", "r+" ) ) ) |
|---|
| 2133 | { |
|---|
| 2134 | fputc( c, fp ); |
|---|
| 2135 | fclose( fp ); |
|---|
| 2136 | } |
|---|
| 2137 | else |
|---|
| 2138 | { |
|---|
| 2139 | perror( "/proc/sys/net/ipv4/ip_forward" ); |
|---|
| 2140 | } |
|---|
| 2141 | } |
|---|
| 2142 | int ifexists( const char *ifname ) |
|---|
| 2143 | { |
|---|
| 2144 | return getifcount( ifname ) > 0 ? 1 : 0; |
|---|
| 2145 | } |
|---|
| 2146 | |
|---|
| 2147 | int getifcount( const char *ifprefix ) |
|---|
| 2148 | { |
|---|
| 2149 | /* |
|---|
| 2150 | * char devcall[128]; |
|---|
| 2151 | * |
|---|
| 2152 | * sprintf (devcall, "cat /proc/net/dev|grep \"%s\"|wc -l", ifprefix); |
|---|
| 2153 | * FILE *in = popen (devcall, "rb"); if (in == NULL) return 0; int count; |
|---|
| 2154 | * fscanf (in, "%d", &count); pclose (in); return count; |
|---|
| 2155 | */ |
|---|
| 2156 | char *iflist = malloc( 256 ); |
|---|
| 2157 | |
|---|
| 2158 | memset( iflist, 0, 256 ); |
|---|
| 2159 | int c = getIfList( iflist, ifprefix ); |
|---|
| 2160 | |
|---|
| 2161 | free( iflist ); |
|---|
| 2162 | return c; |
|---|
| 2163 | } |
|---|
| 2164 | |
|---|
| 2165 | static void skipline( FILE * in ) |
|---|
| 2166 | { |
|---|
| 2167 | while( 1 ) |
|---|
| 2168 | { |
|---|
| 2169 | int c = getc( in ); |
|---|
| 2170 | |
|---|
| 2171 | if( c == EOF ) |
|---|
| 2172 | return; |
|---|
| 2173 | if( c == 0x0 ) |
|---|
| 2174 | return; |
|---|
| 2175 | if( c == 0xa ) |
|---|
| 2176 | return; |
|---|
| 2177 | } |
|---|
| 2178 | } |
|---|
| 2179 | |
|---|
| 2180 | // returns a physical interfacelist filtered by ifprefix. if ifprefix is |
|---|
| 2181 | // NULL, all valid interfaces will be returned |
|---|
| 2182 | int getIfList( char *buffer, const char *ifprefix ) |
|---|
| 2183 | { |
|---|
| 2184 | FILE *in = fopen( "/proc/net/dev", "rb" ); |
|---|
| 2185 | char ifname[32]; |
|---|
| 2186 | |
|---|
| 2187 | // skip the first 2 lines |
|---|
| 2188 | skipline( in ); |
|---|
| 2189 | skipline( in ); |
|---|
| 2190 | int ifcount = 0; |
|---|
| 2191 | int count = 0; |
|---|
| 2192 | |
|---|
| 2193 | while( 1 ) |
|---|
| 2194 | { |
|---|
| 2195 | int c = getc( in ); |
|---|
| 2196 | |
|---|
| 2197 | if( c == EOF ) |
|---|
| 2198 | { |
|---|
| 2199 | if( count ) |
|---|
| 2200 | buffer[strlen( buffer ) - 1] = 0; // fixup last space |
|---|
| 2201 | fclose( in ); |
|---|
| 2202 | return count; |
|---|
| 2203 | } |
|---|
| 2204 | if( c == 0 ) |
|---|
| 2205 | { |
|---|
| 2206 | if( count ) |
|---|
| 2207 | buffer[strlen( buffer ) - 1] = 0; // fixup last space |
|---|
| 2208 | fclose( in ); |
|---|
| 2209 | return count; |
|---|
| 2210 | } |
|---|
| 2211 | if( c == 0x20 ) |
|---|
| 2212 | continue; |
|---|
| 2213 | if( c == ':' || ifcount == 30 ) |
|---|
| 2214 | { |
|---|
| 2215 | ifname[ifcount++] = 0; |
|---|
| 2216 | int skip = 0; |
|---|
| 2217 | |
|---|
| 2218 | if( ifprefix ) |
|---|
| 2219 | { |
|---|
| 2220 | if( strncmp( ifname, ifprefix, strlen( ifprefix ) ) ) |
|---|
| 2221 | { |
|---|
| 2222 | skip = 1; |
|---|
| 2223 | } |
|---|
| 2224 | } |
|---|
| 2225 | else |
|---|
| 2226 | { |
|---|
| 2227 | if( !strncmp( ifname, "wifi", 4 ) ) |
|---|
| 2228 | skip = 1; |
|---|
| 2229 | if( !strncmp( ifname, "imq", 3 ) ) |
|---|
| 2230 | skip = 1; |
|---|
| 2231 | if( !strncmp( ifname, "lo", 2 ) ) |
|---|
| 2232 | skip = 1; |
|---|
| 2233 | if( !strncmp( ifname, "teql", 4 ) ) |
|---|
| 2234 | skip = 1; |
|---|
| 2235 | if( !strncmp( ifname, "gre", 3 ) ) |
|---|
| 2236 | skip = 1; |
|---|
| 2237 | if( !strncmp( ifname, "ppp", 3 ) ) |
|---|
| 2238 | skip = 1; |
|---|
| 2239 | if( !strncmp( ifname, "tun", 3 ) ) |
|---|
| 2240 | skip = 1; |
|---|
| 2241 | if( !strncmp( ifname, "tap", 3 ) ) |
|---|
| 2242 | skip = 1; |
|---|
| 2243 | } |
|---|
| 2244 | if( !skip ) |
|---|
| 2245 | { |
|---|
| 2246 | strcat( buffer, ifname ); |
|---|
| 2247 | strcat( buffer, " " ); |
|---|
| 2248 | count++; |
|---|
| 2249 | } |
|---|
| 2250 | skip = 0; |
|---|
| 2251 | ifcount = 0; |
|---|
| 2252 | memset( ifname, 0, 32 ); |
|---|
| 2253 | skipline( in ); |
|---|
| 2254 | continue; |
|---|
| 2255 | } |
|---|
| 2256 | if( ifcount < 30 ) |
|---|
| 2257 | ifname[ifcount++] = c; |
|---|
| 2258 | } |
|---|
| 2259 | } |
|---|
| 2260 | |
|---|
| 2261 | /* |
|---|
| 2262 | * Example: legal_hwaddr("00:11:22:33:44:aB"); return true; |
|---|
| 2263 | * legal_hwaddr("00:11:22:33:44:5"); return false; |
|---|
| 2264 | * legal_hwaddr("00:11:22:33:44:HH"); return false; |
|---|
| 2265 | */ |
|---|
| 2266 | int sv_valid_hwaddr( char *value ) |
|---|
| 2267 | { |
|---|
| 2268 | unsigned int hwaddr[6]; |
|---|
| 2269 | int tag = TRUE; |
|---|
| 2270 | int i, count; |
|---|
| 2271 | |
|---|
| 2272 | /* |
|---|
| 2273 | * Check for bad, multicast, broadcast, or null address |
|---|
| 2274 | */ |
|---|
| 2275 | for( i = 0, count = 0; *( value + i ); i++ ) |
|---|
| 2276 | { |
|---|
| 2277 | if( *( value + i ) == ':' ) |
|---|
| 2278 | { |
|---|
| 2279 | if( ( i + 1 ) % 3 != 0 ) |
|---|
| 2280 | { |
|---|
| 2281 | tag = FALSE; |
|---|
| 2282 | break; |
|---|
| 2283 | } |
|---|
| 2284 | count++; |
|---|
| 2285 | } |
|---|
| 2286 | else if( ishexit( *( value + i ) ) ) /* one of 0 1 2 3 4 5 6 7 8 9 |
|---|
| 2287 | * a b c d e f A B C D E F */ |
|---|
| 2288 | continue; |
|---|
| 2289 | else |
|---|
| 2290 | { |
|---|
| 2291 | tag = FALSE; |
|---|
| 2292 | break; |
|---|
| 2293 | } |
|---|
| 2294 | } |
|---|
| 2295 | |
|---|
| 2296 | if( !tag || i != 17 || count != 5 ) /* must have 17's characters and 5's |
|---|
| 2297 | * ':' */ |
|---|
| 2298 | tag = FALSE; |
|---|
| 2299 | else if( sscanf( value, "%x:%x:%x:%x:%x:%x", |
|---|
| 2300 | &hwaddr[0], &hwaddr[1], &hwaddr[2], |
|---|
| 2301 | &hwaddr[3], &hwaddr[4], &hwaddr[5] ) != 6 ) |
|---|
| 2302 | { |
|---|
| 2303 | tag = FALSE; |
|---|
| 2304 | } |
|---|
| 2305 | else |
|---|
| 2306 | tag = TRUE; |
|---|
| 2307 | #ifdef WDS_DEBUG |
|---|
| 2308 | if( tag == FALSE ) |
|---|
| 2309 | fprintf( fp, "failed valid_hwaddr\n" ); |
|---|
| 2310 | #endif |
|---|
| 2311 | |
|---|
| 2312 | return tag; |
|---|
| 2313 | } |
|---|
| 2314 | |
|---|
| 2315 | int led_control( int type, int act ) |
|---|
| 2316 | /* |
|---|
| 2317 | * type: LED_POWER, LED_DIAG, LED_DMZ, LED_CONNECTED, LED_BRIDGE, LED_VPN, |
|---|
| 2318 | * LED_SES, LED_SES2, LED_WLAN act: LED_ON, LED_OFF, LED_FLASH |
|---|
| 2319 | */ |
|---|
| 2320 | { |
|---|
| 2321 | #if defined(HAVE_GEMTEK) || defined(HAVE_RB500) || defined(HAVE_MAGICBOX) || defined(HAVE_MERAKI) || defined(HAVE_LS2) || defined(HAVE_X86) || defined(HAVE_CA8) || defined(HAVE_LS5) && !defined(HAVE_DIR300) && !defined(HAVE_DIR400) |
|---|
| 2322 | return 0; |
|---|
| 2323 | #else |
|---|
| 2324 | |
|---|
| 2325 | int use_gpio = 0x0f; |
|---|
| 2326 | int gpio_value; |
|---|
| 2327 | int enable; |
|---|
| 2328 | int disable; |
|---|
| 2329 | |
|---|
| 2330 | int power_gpio = 0x0f; |
|---|
| 2331 | int diag_gpio = 0x0f; |
|---|
| 2332 | int dmz_gpio = 0x0f; |
|---|
| 2333 | int connected_gpio = 0x0f; |
|---|
| 2334 | int bridge_gpio = 0x0f; |
|---|
| 2335 | int vpn_gpio = 0x0f; |
|---|
| 2336 | int ses_gpio = 0x0f; // use for SES1 (Linksys), AOSS (Buffalo) |
|---|
| 2337 | |
|---|
| 2338 | // .... |
|---|
| 2339 | int ses2_gpio = 0x0f; |
|---|
| 2340 | int wlan_gpio = 0x0f; // use this only if wlan led is not |
|---|
| 2341 | |
|---|
| 2342 | // controlled by hardware! |
|---|
| 2343 | int usb_gpio = 0x0f; |
|---|
| 2344 | int v1func = 0; |
|---|
| 2345 | |
|---|
| 2346 | switch ( getRouterBrand( ) ) // gpio definitions here: 0xYZ, |
|---|
| 2347 | // Y=0:normal, Y=1:inverted, Z:gpio |
|---|
| 2348 | // number (f=disabled) |
|---|
| 2349 | { |
|---|
| 2350 | #ifndef HAVE_BUFFALO |
|---|
| 2351 | case ROUTER_BOARD_GATEWORX: |
|---|
| 2352 | connected_gpio = 0x3; |
|---|
| 2353 | break; |
|---|
| 2354 | case ROUTER_BOARD_GATEWORX_SWAP: |
|---|
| 2355 | connected_gpio = 0x4; |
|---|
| 2356 | break; |
|---|
| 2357 | case ROUTER_BOARD_STORM: |
|---|
| 2358 | connected_gpio = 0x5; |
|---|
| 2359 | diag_gpio = 0x3; |
|---|
| 2360 | break; |
|---|
| 2361 | case ROUTER_LINKSYS_WRH54G: |
|---|
| 2362 | diag_gpio = 0x11; // power led blink / off to indicate factory |
|---|
| 2363 | // defaults |
|---|
| 2364 | break; |
|---|
| 2365 | case ROUTER_WRT54G: |
|---|
| 2366 | case ROUTER_WRT54G_V8: |
|---|
| 2367 | power_gpio = 0x01; |
|---|
| 2368 | dmz_gpio = 0x17; |
|---|
| 2369 | connected_gpio = 0x13; // ses orange |
|---|
| 2370 | ses_gpio = 0x12; // ses white |
|---|
| 2371 | ses2_gpio = 0x13; // ses orange |
|---|
| 2372 | break; |
|---|
| 2373 | case ROUTER_WRT54G_V81: |
|---|
| 2374 | power_gpio = 0x11; |
|---|
| 2375 | dmz_gpio = 0x12; |
|---|
| 2376 | connected_gpio = 0x14; // ses orange |
|---|
| 2377 | ses_gpio = 0x13; // ses white |
|---|
| 2378 | ses2_gpio = 0x14; // ses orange |
|---|
| 2379 | break; |
|---|
| 2380 | case ROUTER_WRT54G1X: |
|---|
| 2381 | connected_gpio = 0x13; |
|---|
| 2382 | v1func = 1; |
|---|
| 2383 | break; |
|---|
| 2384 | case ROUTER_WRT350N: |
|---|
| 2385 | connected_gpio = 0x13; |
|---|
| 2386 | power_gpio = 0x01; |
|---|
| 2387 | ses2_gpio = 0x13; // ses orange |
|---|
| 2388 | // usb_gpio = 0x04; |
|---|
| 2389 | break; |
|---|
| 2390 | case ROUTER_WRT600N: |
|---|
| 2391 | connected_gpio = 0x13; |
|---|
| 2392 | // power_gpio = 0x01; |
|---|
| 2393 | ses2_gpio = 0x18; // ses orange |
|---|
| 2394 | break; |
|---|
| 2395 | case ROUTER_LINKSYS_WRT55AG: |
|---|
| 2396 | connected_gpio = 0x13; |
|---|
| 2397 | break; |
|---|
| 2398 | case ROUTER_DLINK_DIR330: |
|---|
| 2399 | diag_gpio = 0x16; |
|---|
| 2400 | connected_gpio = 0x14; |
|---|
| 2401 | break; |
|---|
| 2402 | #endif |
|---|
| 2403 | case ROUTER_BUFFALO_WBR54G: |
|---|
| 2404 | diag_gpio = 0x17; |
|---|
| 2405 | break; |
|---|
| 2406 | case ROUTER_BUFFALO_WBR2G54S: |
|---|
| 2407 | diag_gpio = 0x01; |
|---|
| 2408 | ses_gpio = 0x06; |
|---|
| 2409 | break; |
|---|
| 2410 | case ROUTER_BUFFALO_WLA2G54C: |
|---|
| 2411 | diag_gpio = 0x14; |
|---|
| 2412 | ses_gpio = 0x13; |
|---|
| 2413 | break; |
|---|
| 2414 | case ROUTER_BUFFALO_WLAH_G54: |
|---|
| 2415 | diag_gpio = 0x17; |
|---|
| 2416 | ses_gpio = 0x16; |
|---|
| 2417 | break; |
|---|
| 2418 | case ROUTER_BUFFALO_WAPM_HP_AM54G54: |
|---|
| 2419 | diag_gpio = 0x17; |
|---|
| 2420 | ses_gpio = 0x11; |
|---|
| 2421 | break; |
|---|
| 2422 | case ROUTER_BOARD_WHRAG108: |
|---|
| 2423 | diag_gpio = 0x17; |
|---|
| 2424 | bridge_gpio = 0x14; |
|---|
| 2425 | ses_gpio = 0x10; |
|---|
| 2426 | break; |
|---|
| 2427 | case ROUTER_BUFFALO_WHRG54S: |
|---|
| 2428 | case ROUTER_BUFFALO_WLI_TX4_G54HP: |
|---|
| 2429 | diag_gpio = 0x17; |
|---|
| 2430 | bridge_gpio = 0x11; |
|---|
| 2431 | ses_gpio = 0x16; |
|---|
| 2432 | break; |
|---|
| 2433 | case ROUTER_BUFFALO_WZRRSG54: |
|---|
| 2434 | diag_gpio = 0x17; |
|---|
| 2435 | vpn_gpio = 0x11; |
|---|
| 2436 | ses_gpio = 0x16; |
|---|
| 2437 | break; |
|---|
| 2438 | case ROUTER_BUFFALO_WZRG300N: |
|---|
| 2439 | diag_gpio = 0x17; |
|---|
| 2440 | bridge_gpio = 0x11; |
|---|
| 2441 | break; |
|---|
| 2442 | case ROUTER_BUFFALO_WZRG144NH: |
|---|
| 2443 | diag_gpio = 0x13; |
|---|
| 2444 | bridge_gpio = 0x11; |
|---|
| 2445 | ses_gpio = 0x12; |
|---|
| 2446 | break; |
|---|
| 2447 | #ifndef HAVE_BUFFALO |
|---|
| 2448 | #ifdef HAVE_DIR300 |
|---|
| 2449 | case ROUTER_BOARD_FONERA: |
|---|
| 2450 | diag_gpio = 0x03; |
|---|
| 2451 | bridge_gpio = 0x04; |
|---|
| 2452 | ses_gpio = 0x01; |
|---|
| 2453 | break; |
|---|
| 2454 | #endif |
|---|
| 2455 | #ifdef HAVE_DIR400 |
|---|
| 2456 | case ROUTER_BOARD_FONERA2200: |
|---|
| 2457 | diag_gpio = 0x03; |
|---|
| 2458 | bridge_gpio = 0x04; |
|---|
| 2459 | ses_gpio = 0x01; |
|---|
| 2460 | break; |
|---|
| 2461 | #endif |
|---|
| 2462 | #ifdef HAVE_WRK54G |
|---|
| 2463 | case ROUTER_BOARD_FONERA: |
|---|
| 2464 | diag_gpio = 0x17; |
|---|
| 2465 | dmz_gpio = 0x05; |
|---|
| 2466 | break; |
|---|
| 2467 | #endif |
|---|
| 2468 | case ROUTER_BOARD_TW6600: |
|---|
| 2469 | diag_gpio = 0x17; |
|---|
| 2470 | bridge_gpio = 0x14; |
|---|
| 2471 | ses_gpio = 0x10; |
|---|
| 2472 | break; |
|---|
| 2473 | case ROUTER_MOTOROLA: |
|---|
| 2474 | power_gpio = 0x01; |
|---|
| 2475 | diag_gpio = 0x11; // power led blink / off to indicate factory |
|---|
| 2476 | // defaults |
|---|
| 2477 | break; |
|---|
| 2478 | case ROUTER_RT210W: |
|---|
| 2479 | power_gpio = 0x15; |
|---|
| 2480 | diag_gpio = 0x05; // power led blink / off to indicate factory |
|---|
| 2481 | // defaults |
|---|
| 2482 | connected_gpio = 0x10; |
|---|
| 2483 | wlan_gpio = 0x13; |
|---|
| 2484 | break; |
|---|
| 2485 | case ROUTER_RT480W: |
|---|
| 2486 | case ROUTER_BELKIN_F5D7230_V2000: |
|---|
| 2487 | case ROUTER_BELKIN_F5D7231: |
|---|
| 2488 | power_gpio = 0x15; |
|---|
| 2489 | diag_gpio = 0x05; // power led blink / off to indicate factory |
|---|
| 2490 | // defaults |
|---|
| 2491 | connected_gpio = 0x10; |
|---|
| 2492 | break; |
|---|
| 2493 | case ROUTER_MICROSOFT_MN700: |
|---|
| 2494 | power_gpio = 0x06; |
|---|
| 2495 | diag_gpio = 0x16; // power led blink / off to indicate factory |
|---|
| 2496 | // defaults |
|---|
| 2497 | break; |
|---|
| 2498 | case ROUTER_ASUS_WL500GD: |
|---|
| 2499 | case ROUTER_ASUS_WL520GUGC: |
|---|
| 2500 | diag_gpio = 0x00; // power led blink / off to indicate factory |
|---|
| 2501 | // defaults |
|---|
| 2502 | break; |
|---|
| 2503 | case ROUTER_ASUS_WL500G_PRE: |
|---|
| 2504 | power_gpio = 0x11; |
|---|
| 2505 | diag_gpio = 0x01; // power led blink / off to indicate factory |
|---|
| 2506 | // defaults |
|---|
| 2507 | break; |
|---|
| 2508 | case ROUTER_ASUS_WL550GE: |
|---|
| 2509 | power_gpio = 0x12; |
|---|
| 2510 | diag_gpio = 0x02; // power led blink / off to indicate factory |
|---|
| 2511 | // defaults |
|---|
| 2512 | break; |
|---|
| 2513 | case ROUTER_WRT54G3G: |
|---|
| 2514 | case ROUTER_WRTSL54GS: |
|---|
| 2515 | power_gpio = 0x01; |
|---|
| 2516 | dmz_gpio = 0x10; |
|---|
| 2517 | connected_gpio = 0x17; // ses orange |
|---|
| 2518 | ses_gpio = 0x15; // ses white |
|---|
| 2519 | ses2_gpio = 0x17; // ses orange |
|---|
| 2520 | break; |
|---|
| 2521 | case ROUTER_MOTOROLA_WE800G: |
|---|
| 2522 | case ROUTER_MOTOROLA_V1: |
|---|
| 2523 | diag_gpio = 0x13; |
|---|
| 2524 | wlan_gpio = 0x11; |
|---|
| 2525 | bridge_gpio = 0x15; |
|---|
| 2526 | break; |
|---|
| 2527 | case ROUTER_DELL_TRUEMOBILE_2300: |
|---|
| 2528 | case ROUTER_DELL_TRUEMOBILE_2300_V2: |
|---|
| 2529 | power_gpio = 0x17; |
|---|
| 2530 | diag_gpio = 0x07; // power led blink / off to indicate factory |
|---|
| 2531 | // defaults |
|---|
| 2532 | wlan_gpio = 0x16; |
|---|
| 2533 | break; |
|---|
| 2534 | case ROUTER_NETGEAR_WNR834B: |
|---|
| 2535 | power_gpio = 0x14; |
|---|
| 2536 | diag_gpio = 0x15; |
|---|
| 2537 | wlan_gpio = 0x16; |
|---|
| 2538 | break; |
|---|
| 2539 | case ROUTER_SITECOM_WL105B: |
|---|
| 2540 | power_gpio = 0x03; |
|---|
| 2541 | diag_gpio = 0x13; // power led blink / off to indicate factory |
|---|
| 2542 | // defaults |
|---|
| 2543 | wlan_gpio = 0x14; |
|---|
| 2544 | break; |
|---|
| 2545 | case ROUTER_WRT150N: |
|---|
| 2546 | case ROUTER_WRT300N: |
|---|
| 2547 | power_gpio = 0x01; |
|---|
| 2548 | diag_gpio = 0x11; // power led blink / off to indicate fac.def. |
|---|
| 2549 | break; |
|---|
| 2550 | case ROUTER_WRT300NV11: |
|---|
| 2551 | ses_gpio = 0x15; |
|---|
| 2552 | // diag_gpio = 0x11; //power led blink / off to indicate fac.def. |
|---|
| 2553 | break; |
|---|
| 2554 | case ROUTER_WRT310N: |
|---|
| 2555 | connected_gpio = 0x13; |
|---|
| 2556 | power_gpio = 0x01; |
|---|
| 2557 | diag_gpio = 0x11; // power led blink / off to indicate fac.def. |
|---|
| 2558 | ses2_gpio = 0x13; // ses orange |
|---|
| 2559 | case ROUTER_WRT160N: |
|---|
| 2560 | power_gpio = 0x01; |
|---|
| 2561 | diag_gpio = 0x11; // power led blink / off to indicate fac.def. |
|---|
| 2562 | // |
|---|
| 2563 | connected_gpio = 0x13; // ses orange |
|---|
| 2564 | ses_gpio = 0x15; // ses blue |
|---|
| 2565 | break; |
|---|
| 2566 | case ROUTER_ASUS_WL500G: |
|---|
| 2567 | power_gpio = 0x10; |
|---|
| 2568 | diag_gpio = 0x00; // power led blink /off to indicate factory |
|---|
| 2569 | // defaults |
|---|
| 2570 | break; |
|---|
| 2571 | case ROUTER_ASUS_WL500W: |
|---|
| 2572 | power_gpio = 0x15; |
|---|
| 2573 | diag_gpio = 0x05; // power led blink /off to indicate factory |
|---|
| 2574 | // defaults |
|---|
| 2575 | break; |
|---|
| 2576 | case ROUTER_LINKSYS_WTR54GS: |
|---|
| 2577 | diag_gpio = 0x01; |
|---|
| 2578 | break; |
|---|
| 2579 | case ROUTER_WAP54G_V1: |
|---|
| 2580 | diag_gpio = 0x13; |
|---|
| 2581 | wlan_gpio = 0x14; // LINK led |
|---|
| 2582 | break; |
|---|
| 2583 | case ROUTER_WAP54G_V3: |
|---|
| 2584 | ses_gpio = 0x1c; |
|---|
| 2585 | connected_gpio = 0x06; |
|---|
| 2586 | break; |
|---|
| 2587 | case ROUTER_NETGEAR_WNR834BV2: |
|---|
| 2588 | power_gpio = 0x02; |
|---|
| 2589 | diag_gpio = 0x03; // power led amber |
|---|
| 2590 | connected_gpio = 0x07; // WAN led green |
|---|
| 2591 | break; |
|---|
| 2592 | case ROUTER_NETGEAR_WNDR3300: |
|---|
| 2593 | power_gpio = 0x05; |
|---|
| 2594 | diag_gpio = 0x15; // power led blink /off to indicate factory |
|---|
| 2595 | // defaults |
|---|
| 2596 | break; |
|---|
| 2597 | case ROUTER_ASKEY_RT220XD: |
|---|
| 2598 | wlan_gpio = 0x10; |
|---|
| 2599 | dmz_gpio = 0x11; // not soldered |
|---|
| 2600 | break; |
|---|
| 2601 | case ROUTER_WRT610N: |
|---|
| 2602 | power_gpio = 0x01; |
|---|
| 2603 | connected_gpio = 0x13; // ses amber |
|---|
| 2604 | ses_gpio = 0x19; // ses blue |
|---|
| 2605 | usb_gpio = 0x10; |
|---|
| 2606 | break; |
|---|
| 2607 | #endif |
|---|
| 2608 | } |
|---|
| 2609 | if( type == LED_DIAG && v1func == 1 ) |
|---|
| 2610 | { |
|---|
| 2611 | if( act == LED_ON ) |
|---|
| 2612 | C_led( 1 ); |
|---|
| 2613 | else |
|---|
| 2614 | C_led( 0 ); |
|---|
| 2615 | } |
|---|
| 2616 | |
|---|
| 2617 | switch ( type ) |
|---|
| 2618 | { |
|---|
| 2619 | case LED_POWER: |
|---|
| 2620 | use_gpio = power_gpio; |
|---|
| 2621 | break; |
|---|
| 2622 | case LED_DIAG: |
|---|
| 2623 | use_gpio = diag_gpio; |
|---|
| 2624 | break; |
|---|
| 2625 | case LED_DMZ: |
|---|
| 2626 | use_gpio = dmz_gpio; |
|---|
| 2627 | break; |
|---|
| 2628 | case LED_CONNECTED: |
|---|
| 2629 | use_gpio = connected_gpio; |
|---|
| 2630 | break; |
|---|
| 2631 | case LED_BRIDGE: |
|---|
| 2632 | use_gpio = bridge_gpio; |
|---|
| 2633 | break; |
|---|
| 2634 | case LED_VPN: |
|---|
| 2635 | use_gpio = vpn_gpio; |
|---|
| 2636 | break; |
|---|
| 2637 | case LED_SES: |
|---|
| 2638 | use_gpio = ses_gpio; |
|---|
| 2639 | break; |
|---|
| 2640 | case LED_SES2: |
|---|
| 2641 | use_gpio = ses2_gpio; |
|---|
| 2642 | break; |
|---|
| 2643 | case LED_WLAN: |
|---|
| 2644 | use_gpio = wlan_gpio; |
|---|
| 2645 | break; |
|---|
| 2646 | case LED_USB: |
|---|
| 2647 | use_gpio = usb_gpio; |
|---|
| 2648 | break; |
|---|
| 2649 | } |
|---|
| 2650 | if( ( use_gpio & 0x0f ) != 0x0f ) |
|---|
| 2651 | { |
|---|
| 2652 | gpio_value = use_gpio & 0x0f; |
|---|
| 2653 | enable = ( use_gpio & 0x10 ) == 0 ? 1 : 0; |
|---|
| 2654 | disable = ( use_gpio & 0x10 ) == 0 ? 0 : 1; |
|---|
| 2655 | switch ( act ) |
|---|
| 2656 | { |
|---|
| 2657 | case LED_ON: |
|---|
| 2658 | set_gpio( gpio_value, enable ); |
|---|
| 2659 | break; |
|---|
| 2660 | case LED_OFF: |
|---|
| 2661 | set_gpio( gpio_value, disable ); |
|---|
| 2662 | break; |
|---|
| 2663 | case LED_FLASH: // will lit the led for 1 sec. |
|---|
| 2664 | set_gpio( gpio_value, enable ); |
|---|
| 2665 | sleep( 1 ); |
|---|
| 2666 | set_gpio( gpio_value, disable ); |
|---|
| 2667 | break; |
|---|
| 2668 | } |
|---|
| 2669 | } |
|---|
| 2670 | return 1; |
|---|
| 2671 | |
|---|
| 2672 | #endif |
|---|
| 2673 | } |
|---|
| 2674 | |
|---|
| 2675 | int file_to_buf( char *path, char *buf, int len ) |
|---|
| 2676 | { |
|---|
| 2677 | FILE *fp; |
|---|
| 2678 | |
|---|
| 2679 | memset( buf, 0, len ); |
|---|
| 2680 | |
|---|
| 2681 | if( ( fp = fopen( path, "r" ) ) ) |
|---|
| 2682 | { |
|---|
| 2683 | fgets( buf, len, fp ); |
|---|
| 2684 | fclose( fp ); |
|---|
| 2685 | return 1; |
|---|
| 2686 | } |
|---|
| 2687 | |
|---|
| 2688 | return 0; |
|---|
| 2689 | } |
|---|
| 2690 | |
|---|
| 2691 | int ishexit( char c ) |
|---|
| 2692 | { |
|---|
| 2693 | |
|---|
| 2694 | if( strchr( "01234567890abcdefABCDEF", c ) != ( char * )0 ) |
|---|
| 2695 | return 1; |
|---|
| 2696 | |
|---|
| 2697 | return 0; |
|---|
| 2698 | } |
|---|
| 2699 | |
|---|
| 2700 | int getMTD( char *name ) |
|---|
| 2701 | { |
|---|
| 2702 | char buf[128]; |
|---|
| 2703 | int device; |
|---|
| 2704 | |
|---|
| 2705 | sprintf( buf, "cat /proc/mtd|grep \"%s\"", name ); |
|---|
| 2706 | FILE *fp = popen( buf, "rb" ); |
|---|
| 2707 | |
|---|
| 2708 | fscanf( fp, "%s", &buf[0] ); |
|---|
| 2709 | device = buf[3] - '0'; |
|---|
| 2710 | pclose( fp ); |
|---|
| 2711 | return device; |
|---|
| 2712 | } |
|---|
| 2713 | |
|---|
| 2714 | int insmod( char *module ) |
|---|
| 2715 | { |
|---|
| 2716 | return eval( "insmod", module ); |
|---|
| 2717 | } |
|---|
| 2718 | |
|---|
| 2719 | void rmmod( char *module ) |
|---|
| 2720 | { |
|---|
| 2721 | return eval( "rmmod", module ); |
|---|
| 2722 | } |
|---|
| 2723 | |
|---|
| 2724 | #ifdef HAVE_X86 |
|---|
| 2725 | |
|---|
| 2726 | static int fd; |
|---|
| 2727 | |
|---|
| 2728 | void SetEnvironment( ) |
|---|
| 2729 | { |
|---|
| 2730 | system( "stty ispeed 2400 < /dev/tts/1" ); |
|---|
| 2731 | system( "stty raw < /dev/tts/1" ); |
|---|
| 2732 | } |
|---|
| 2733 | |
|---|
| 2734 | int Cmd = 254; /* EZIO Command */ |
|---|
| 2735 | int cls = 1; /* Clear screen */ |
|---|
| 2736 | void Cls( ) |
|---|
| 2737 | { |
|---|
| 2738 | write( fd, &Cmd, 1 ); |
|---|
| 2739 | write( fd, &cls, 1 ); |
|---|
| 2740 | } |
|---|
| 2741 | |
|---|
| 2742 | int init = 0x28; |
|---|
| 2743 | void Init( ) |
|---|
| 2744 | { |
|---|
| 2745 | write( fd, &Cmd, 1 ); |
|---|
| 2746 | write( fd, &init, 1 ); |
|---|
| 2747 | } |
|---|
| 2748 | |
|---|
| 2749 | int stopsend = 0x37; |
|---|
| 2750 | void StopSend( ) |
|---|
| 2751 | { |
|---|
| 2752 | write( fd, &Cmd, 1 ); |
|---|
| 2753 | write( fd, &init, 1 ); |
|---|
| 2754 | } |
|---|
| 2755 | |
|---|
| 2756 | int home = 2; /* Home cursor */ |
|---|
| 2757 | void Home( ) |
|---|
| 2758 | { |
|---|
| 2759 | write( fd, &Cmd, 1 ); |
|---|
| 2760 | write( fd, &home, 1 ); |
|---|
| 2761 | } |
|---|
| 2762 | |
|---|
| 2763 | int readkey = 6; /* Read key */ |
|---|
| 2764 | void ReadKey( ) |
|---|
| 2765 | { |
|---|
| 2766 | write( fd, &Cmd, 1 ); |
|---|
| 2767 | write( fd, &readkey, 1 ); |
|---|
| 2768 | } |
|---|
| 2769 | |
|---|
| 2770 | int blank = 8; /* Blank display */ |
|---|
| 2771 | void Blank( ) |
|---|
| 2772 | { |
|---|
| 2773 | write( fd, &Cmd, 1 ); |
|---|
| 2774 | write( fd, &blank, 1 ); |
|---|
| 2775 | } |
|---|
| 2776 | |
|---|
| 2777 | int hide = 12; /* Hide cursor & display blanked characters */ |
|---|
| 2778 | void Hide( ) |
|---|
| 2779 | { |
|---|
| 2780 | write( fd, &Cmd, 1 ); |
|---|
| 2781 | write( fd, &hide, 1 ); |
|---|
| 2782 | } |
|---|
| 2783 | |
|---|
| 2784 | int turn = 13; /* Turn On (blinking block cursor) */ |
|---|
| 2785 | void TurnOn( ) |
|---|
| 2786 | { |
|---|
| 2787 | write( fd, &Cmd, 1 ); |
|---|
| 2788 | write( fd, &turn, 1 ); |
|---|
| 2789 | } |
|---|
| 2790 | |
|---|
| 2791 | int show = 14; /* Show underline cursor */ |
|---|
| 2792 | void Show( ) |
|---|
| 2793 | { |
|---|
| 2794 | write( fd, &Cmd, 1 ); |
|---|
| 2795 | write( fd, &show, 1 ); |
|---|
| 2796 | } |
|---|
| 2797 | |
|---|
| 2798 | int movel = 16; /* Move cursor 1 character left */ |
|---|
| 2799 | void MoveL( ) |
|---|
| 2800 | { |
|---|
| 2801 | write( fd, &Cmd, 1 ); |
|---|
| 2802 | write( fd, &movel, 1 ); |
|---|
| 2803 | } |
|---|
| 2804 | |
|---|
| 2805 | int mover = 20; /* Move cursor 1 character right */ |
|---|
| 2806 | void MoveR( ) |
|---|
| 2807 | { |
|---|
| 2808 | write( fd, &Cmd, 1 ); |
|---|
| 2809 | write( fd, &mover, 1 ); |
|---|
| 2810 | } |
|---|
| 2811 | |
|---|
| 2812 | int scl = 24; /* Scroll cursor 1 character left */ |
|---|
| 2813 | void ScrollL( ) |
|---|
| 2814 | { |
|---|
| 2815 | write( fd, &Cmd, 1 ); |
|---|
| 2816 | write( fd, &scl, 1 ); |
|---|
| 2817 | } |
|---|
| 2818 | |
|---|
| 2819 | int scr = 28; /* Scroll cursor 1 character right */ |
|---|
| 2820 | void ScrollR( ) |
|---|
| 2821 | { |
|---|
| 2822 | write( fd, &Cmd, 1 ); |
|---|
| 2823 | write( fd, &scr, 1 ); |
|---|
| 2824 | } |
|---|
| 2825 | |
|---|
| 2826 | int setdis = 64; /* Command */ |
|---|
| 2827 | void SetDis( ) |
|---|
| 2828 | { |
|---|
| 2829 | write( fd, &Cmd, 1 ); |
|---|
| 2830 | write( fd, &setdis, 1 ); |
|---|
| 2831 | |
|---|
| 2832 | } |
|---|
| 2833 | |
|---|
| 2834 | int a, b; |
|---|
| 2835 | void ShowMessage( char *str1, char *str2 ) |
|---|
| 2836 | { |
|---|
| 2837 | char nul[] = " "; |
|---|
| 2838 | |
|---|
| 2839 | a = strlen( str1 ); |
|---|
| 2840 | b = 40 - a; |
|---|
| 2841 | write( fd, str1, a ); |
|---|
| 2842 | write( fd, nul, b ); |
|---|
| 2843 | write( fd, str2, strlen( str2 ) ); |
|---|
| 2844 | } |
|---|
| 2845 | |
|---|
| 2846 | void initlcd( ) |
|---|
| 2847 | { |
|---|
| 2848 | |
|---|
| 2849 | fd = open( "/dev/tts/1", O_RDWR ); |
|---|
| 2850 | |
|---|
| 2851 | /** Open Serial port (COM2) */ |
|---|
| 2852 | if( fd > 0 ) |
|---|
| 2853 | { |
|---|
| 2854 | close( fd ); |
|---|
| 2855 | SetEnvironment( ); /* Set RAW mode */ |
|---|
| 2856 | fd = open( "/dev/tts/1", O_RDWR ); |
|---|
| 2857 | Init( ); /* Initialize EZIO twice */ |
|---|
| 2858 | Init( ); |
|---|
| 2859 | |
|---|
| 2860 | Cls( ); /* Clear screen */ |
|---|
| 2861 | } |
|---|
| 2862 | close( fd ); |
|---|
| 2863 | } |
|---|
| 2864 | |
|---|
| 2865 | void lcdmessage( char *message ) |
|---|
| 2866 | { |
|---|
| 2867 | |
|---|
| 2868 | fd = open( "/dev/tts/1", O_RDWR ); |
|---|
| 2869 | /** Open Serial port (COM2) */ |
|---|
| 2870 | |
|---|
| 2871 | if( fd > 0 ) |
|---|
| 2872 | { |
|---|
| 2873 | Init( ); /* Initialize EZIO twice */ |
|---|
| 2874 | Init( ); |
|---|
| 2875 | SetDis( ); |
|---|
| 2876 | Cls( ); |
|---|
| 2877 | Home( ); |
|---|
| 2878 | ShowMessage( "State", message ); |
|---|
| 2879 | close( fd ); |
|---|
| 2880 | } |
|---|
| 2881 | } |
|---|
| 2882 | void lcdmessaged( char *dual, char *message ) |
|---|
| 2883 | { |
|---|
| 2884 | |
|---|
| 2885 | fd = open( "/dev/tts/1", O_RDWR ); |
|---|
| 2886 | |
|---|
| 2887 | /** Open Serial port (COM2) */ |
|---|
| 2888 | |
|---|
| 2889 | if( fd > 0 ) |
|---|
| 2890 | { |
|---|
| 2891 | Init( ); /* Initialize EZIO twice */ |
|---|
| 2892 | Init( ); |
|---|
| 2893 | SetDis( ); |
|---|
| 2894 | Cls( ); /* Clear screen */ |
|---|
| 2895 | Home( ); |
|---|
| 2896 | ShowMessage( dual, message ); |
|---|
| 2897 | close( fd ); |
|---|
| 2898 | } |
|---|
| 2899 | } |
|---|
| 2900 | |
|---|
| 2901 | #endif |
|---|