1#include <rc.h> 2#include <shutils.h> 3#ifdef RTCONFIG_RALINK 4#include <ralink.h> 5#if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN54U) || defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTN56UB2) || defined(RTAC54U) 6#include <linux/if_packet.h> 7#include <linux/if_ether.h> 8#endif 9#endif 10#ifdef RTCONFIG_QCA 11#include <qca.h> 12#endif 13#include "ate.h" 14#ifdef RTCONFIG_INTERNAL_GOBI 15#include <at_cmd.h> 16#endif 17#ifdef RTCONFIG_QCA_PLC_UTILS 18#include <plc_utils.h> 19#endif 20 21 22#define MULTICAST_BIT 0x0001 23#define UNIQUE_OUI_BIT 0x0002 24 25int isValidMacAddr(const char* mac) 26{ 27 int sec_byte; 28 int i = 0, s = 0; 29 30 if( strlen(mac)!=17 || !strcmp("00:00:00:00:00:00", mac) ) 31 return 0; 32 33 while( *mac && i<12 ) { 34 if( isxdigit(*mac) ) { 35 if(i==1) { 36 sec_byte= strtol(mac, NULL, 16); 37 if((sec_byte & MULTICAST_BIT)||(sec_byte & UNIQUE_OUI_BIT)) 38 break; 39 } 40 i++; 41 } 42 else if( *mac==':') { 43 if( i==0 || i/2-1!=s ) 44 break; 45 ++s; 46 } 47 ++mac; 48 } 49 return( i==12 && s==5 ); 50} 51 52int 53isValidCountryCode(const char *Ccode) 54{ 55 const char *c = Ccode; 56 int i = 0; 57 58 if(strlen(Ccode)==2) { 59 while(i<2) { //0~9, A~F 60 if( (*c>0x2F && *c<0x3A) || (*c>0x40 && *c<0x5B) ) { 61 i++; 62 c++; 63 } 64 else 65 break; 66 } 67 } 68 if( i == 2 ) 69 return 1; 70 else 71 return 0; 72} 73 74int 75isNumber(const char *num) 76{ 77 const char *c = num; 78 int i = 0, len = 0; 79 80 len = strlen(num); 81 while(i<len) { //0~9 82 if( (*c>='0' && *c<='9') ) { 83 i++; 84 c++; 85 } 86 else 87 break; 88 } 89 if( i == len ) 90 return 1; 91 else 92 return 0; 93} 94 95int 96isValidRegrev(char *regrev) { 97 char *c = regrev; 98 int len, i = 0, ret=0; 99 100 len = strlen(regrev); 101 102 if( len==1 || len==2 || len ==3) { 103 while(i<len) { //0~9 104 if( (*c>0x2F && *c<0x3A) ) { 105 i++; 106 c++; 107 ret = 1; 108 } 109 else { 110 ret = 0; 111 break; 112 } 113 } 114 } 115 116 return ret; 117} 118 119int 120isValidChannel(int is_2G, char *channel) 121{ 122 char *c = channel; 123 int len, i = 0, ret=0; 124 125 len = strlen(channel); 126 127 if( (is_2G && (len==1 || len==2)) 128 || (!is_2G && (len==2 || len==3)) ) { 129 while(i<len) { //0~9 130 if( (*c>0x2F && *c<0x3A) ) { 131 i++; 132 c++; 133 ret = 1; 134 } 135 else { 136 ret = 0; 137 break; 138 } 139 } 140 } 141 142 return ret; 143} 144 145int 146pincheck(const char *a) 147{ 148 unsigned char *c = (unsigned char *) a; 149 unsigned long int uiPINtemp = atoi(a); 150 unsigned long int uiAccum = 0; 151 int i = 0; 152 153 for (;;) { 154 if (*c>0x39 || *c<0x30) 155 break; 156 else 157 i++; 158 if (!*c++ || i == 8) 159 break; 160 } 161 if(i == 8) { 162 uiAccum += 3 * ((uiPINtemp / 10000000) % 10); 163 uiAccum += 1 * ((uiPINtemp / 1000000) % 10); 164 uiAccum += 3 * ((uiPINtemp / 100000) % 10); 165 uiAccum += 1 * ((uiPINtemp / 10000) % 10); 166 uiAccum += 3 * ((uiPINtemp / 1000) % 10); 167 uiAccum += 1 * ((uiPINtemp / 100) % 10); 168 uiAccum += 3 * ((uiPINtemp / 10) % 10); 169 uiAccum += 1 * ((uiPINtemp / 1) % 10); 170 if (0 != (uiAccum % 10)){ 171 return 0; 172 } 173 return 1; 174 } 175 else 176 return 0; 177} 178 179int isValidSN(const char *sn) 180{ 181 int i; 182 unsigned char *c; 183 184 if(strlen(sn) != SERIAL_NUMBER_LENGTH) 185 return 0; 186 187 c = (unsigned char *)sn; 188 /* [1]year: C~Z (2012=C, 2013=D, ...) */ 189 if(*c<0x43 || *c>0x5A) 190 return 0; 191 c++; 192 /* [2]month: 1~9 & ABC */ 193 if(!((*c>0x30 && *c<0x3A) || *c==0x41||*c==0x42||*c==0x43)) 194 return 0; 195 c++; 196 /* [3]WLAN & ADSL: I(aye) */ 197 if(*c!=0x49) 198 return 0; 199 c++; 200 /* [4]Channel: AEJ0(zero) (A:11ch, E:13ch, J:14ch, 0:no ch) */ 201 if(*c!=0x41 && *c!=0x45 && *c!=0x4A && *c!=0x30) 202 return 0; 203 c++; 204 /* [5]factory: 0~9 & A~Z, except I(aye) & O(oh) */ 205 if(!((*c>0x2F && *c<0x3A) || (*c>0x40 && *c<0x5B)) || *c==0x49 || *c==0x4F ) 206 return 0; 207 c++; 208 /* [6]model: 0~9 & A~Z */ 209 if(!((*c>0x2F && *c<0x3A) || (*c>0x40 && *c<0x5B))) 210 return 0; 211 c++; 212 /* [7~12]serial: 0~9 */ 213 i=7; 214 while(i<13) { 215 if (*c<0x30 || *c>0x39) 216 return 0; 217 c++; 218 i++; 219 } 220 221 return 1; 222} 223 224int 225Get_USB_Port_Info(const char *port_x) 226{ 227 char output_buf[16]; 228 char usb_pid[14]; 229 char usb_vid[14]; 230 231 sprintf(usb_pid, "usb_path%s_pid", port_x); 232 sprintf(usb_vid, "usb_path%s_vid", port_x); 233 234 if( strcmp(nvram_safe_get(usb_pid),"") && strcmp(nvram_safe_get(usb_vid),"") ) { 235 sprintf(output_buf, "%s/%s",nvram_safe_get(usb_pid),nvram_safe_get(usb_vid)); 236 puts(output_buf); 237 } 238 else 239 puts("N/A"); 240 241 return 1; 242} 243 244int 245Get_USB_Port_Folder(const char *port_x) 246{ 247 char usb_folder[19]; 248 sprintf(usb_folder, "usb_path%s_fs_path0", port_x); 249 if( strcmp(nvram_safe_get(usb_folder),"") ) 250 puts(nvram_safe_get(usb_folder)); 251 else 252 puts("N/A"); 253 254 return 1; 255} 256 257int 258Get_USB_Port_DataRate(const char *port_x) 259{ 260 char output_buf[16]; 261 char usb_speed[19]; 262 sprintf(usb_speed, "usb_path%s_speed", port_x); 263 if( strcmp(nvram_safe_get(usb_speed),"") ) { 264 sprintf(output_buf, "%sMbps", nvram_safe_get(usb_speed)); 265 puts(output_buf); 266 } 267 else 268 puts("N/A"); 269 return 1; 270} 271 272int 273Get_SD_Card_Info(void) 274{ 275 char check_cmd[48]; 276 char sd_info_buf[128]; 277 int get_sd_card = 1; 278 FILE *fp; 279 280 if(!strcmp(nvram_safe_get("usb_path3_fs_path0"), "")){ 281 puts("0"); 282 return 1; 283 } 284 285 sprintf(check_cmd, "test_disk2 %s &> /var/sd_info.txt", nvram_safe_get("usb_path3_fs_path0")); 286 system(check_cmd); 287 288 if ((fp = fopen("/var/sd_info.txt", "r")) != NULL) { 289 while(fgets(sd_info_buf, 128, fp)!=NULL) { 290 if(strstr(sd_info_buf, "No partition")||strstr(sd_info_buf, "No disk")) 291 get_sd_card=0; 292 } 293 if(get_sd_card) 294 puts("1"); 295 else 296 puts("0"); 297 fclose(fp); 298 eval("rm", "-rf", "/var/sd_info.txt"); 299 } 300 else 301 puts("ATE_ERROR"); 302 303 return 1; 304} 305 306int 307Get_SD_Card_Folder(void) 308{ 309 if( strcmp(nvram_safe_get("usb_path3_fs_path0"),"") ) 310 puts(nvram_safe_get("usb_path3_fs_path0")); 311 else 312 puts("N/A"); 313 314 return 1; 315} 316 317int Ej_device(const char *dev_no) 318{ 319 if( dev_no==NULL || *dev_no<'1' || *dev_no>'9' ) 320 return 0; 321 else { 322 eval("ejusb", (char*)dev_no); 323 sleep(4); 324 puts("1"); 325 } 326 return 1; 327} 328 329int asus_ate_command(const char *command, const char *value, const char *value2) 330{ 331 _dprintf("===[ATE %s %s]===\n", command, value); 332#ifdef RTCONFIG_QTN 333 if(!nvram_match("qtn_ready", "1")){ 334 _dprintf("ATE Error: wireless 5G not ready\n"); 335 return 0; 336 } 337#endif 338 /*** ATE Set function ***/ 339 if(!strcmp(command, "Set_StartATEMode")) { 340 nvram_set("asus_mfg", "1"); 341 if(nvram_match("asus_mfg", "1")) { 342 puts("1"); 343#ifdef RTCONFIG_FANCTRL 344 stop_phy_tempsense(); 345#endif 346 stop_wpsaide(); 347 stop_wps(); 348#ifdef RTCONFIG_BCMWL6 349 stop_igmp_proxy(); 350#ifdef RTCONFIG_HSPOT 351 stop_hspotap(); 352#endif 353 stop_acsd(); 354#ifdef BCM_BSD 355 stop_bsd(); 356#endif 357#ifdef BCM_SSD 358 stop_ssd(); 359#endif 360#endif 361 stop_upnp(); 362 stop_lltd(); 363 stop_rstats(); 364 stop_wanduck(); 365 stop_logger(); 366 stop_wanduck(); 367 stop_dnsmasq(); 368#ifdef RTCONFIG_MDNS 369 stop_mdns(); 370#endif 371 stop_ots(); 372 stop_networkmap(); 373#ifdef RTCONFIG_DISK_MONITOR 374 stop_diskmon(); 375#endif 376#ifdef RTCONFIG_BWDPI 377 stop_bwdpi_check(); 378#endif 379 stop_ntpc(); 380 stop_udhcpc(-1); 381#ifdef RTCONFIG_USB 382 stop_usbled(); 383#ifdef RTCONFIG_USB_PRINTER 384 stop_lpd(); 385 stop_u2ec(); 386#endif 387#endif 388 platform_start_ate_mode(); 389#ifdef RTCONFIG_QCA_PLC_UTILS 390 ate_ctl_plc_led(); 391#endif 392#ifdef SW_DEVLED 393 stop_sw_devled(); 394#endif 395#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 396 start_envrams(); 397#endif 398 399 } 400 else 401 puts("ATE_ERROR"); 402 return 0; 403 } 404 else if (!strcmp(command, "Set_AllLedOn")) { 405#ifdef RTCONFIG_QCA_PLC_UTILS 406 set_plc_all_led_onoff(1); 407#endif 408 return setAllLedOn(); 409 } 410 else if (!strcmp(command, "Set_AllLedOn2")) { 411 return setAllLedOn2(); 412 } 413 else if (!strcmp(command, "Set_AllLedOff")) { 414#ifdef RTCONFIG_QCA_PLC_UTILS 415 set_plc_all_led_onoff(0); 416#endif 417 return setAllLedOff(); 418 } 419 else if (!strcmp(command, "Set_AllLedOn_Half")) { 420 puts("ATE_ERROR"); //Need to implement for EA-N66U 421 return EINVAL; 422 } 423#ifdef RTCONFIG_BCMARM 424 else if (!strcmp(command, "Set_AteModeLedOn")) { 425 return setATEModeLedOn(); 426 } 427#endif 428 else if (!strcmp(command, "Set_MacAddr_2G")) { 429#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 430 if (!chk_envrams_proc()) 431 return EINVAL; 432#endif 433 //Andy Chiu, 2016/02/04. 434 char *p = value; 435 char UpperMac[20] = {0}; 436 int i; 437 for(i = 0; p[i]; ++i) 438 { 439 UpperMac[i] = toupper(p[i]); 440 } 441 442 char tmp[256]; 443 snprintf(tmp, sizeof(tmp), "<%s;%s>", value, UpperMac); 444 puts(tmp); 445 446 if( !setMAC_2G(UpperMac) ) 447 { 448 puts("ATE_ERROR_INCORRECT_PARAMETER"); 449 return EINVAL; 450 } 451 return 0; 452 } 453#if defined(RTCONFIG_HAS_5G) 454 else if (!strcmp(command, "Set_MacAddr_5G")) { 455#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 456 if (!chk_envrams_proc()) 457 return EINVAL; 458#endif 459 //Andy Chiu, 2016/02/04. 460 char *p = value; 461 char UpperMac[20] = {0}; 462 int i; 463 for(i = 0; p[i]; ++i) 464 { 465 UpperMac[i] = toupper(p[i]); 466 } 467 468#ifdef RTCONFIG_QTN 469 if( !setMAC_5G_qtn(UpperMac)) 470#else 471 if( !setMAC_5G(UpperMac)) 472#endif 473 { 474 puts("ATE_ERROR_INCORRECT_PARAMETER"); 475 return EINVAL; 476 } 477 return 0; 478 } 479#if defined(RTAC3200) || defined(RTAC5300)|| defined(RTAC5300R) 480 else if (!strcmp(command, "Set_MacAddr_5G_2")) { 481#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 482 if (!chk_envrams_proc()) 483 return EINVAL; 484 485#endif 486 //Andy Chiu, 2016/02/04. 487 char *p = value; 488 char UpperMac[20] = {0}; 489 int i; 490 for(i = 0; p[i]; ++i) 491 { 492 UpperMac[i] = toupper(p[i]); 493 } 494 495 if( !setMAC_5G_2(UpperMac)) 496 { 497 puts("ATE_ERROR_INCORRECT_PARAMETER"); 498 return EINVAL; 499 } 500 return 0; 501 } 502#endif 503#endif /* RTCONFIG_HAS_5G */ 504#if defined(RTN14U) 505 else if (!strcmp(command, "eeprom")) { 506 if ( !eeprom_upgrade(value, 1)) 507 return EINVAL; 508 return 0; 509 } 510 else if (!strcmp(command, "eeover")) { 511 if ( !eeprom_upgrade(value, 0)) 512 return EINVAL; 513 return 0; 514 } 515#endif 516#if defined(RTCONFIG_NEW_REGULATION_DOMAIN) 517 else if (!strcmp(command, "Set_RegSpec")) { 518 if (setRegSpec(value, 1) < 0) 519 { 520 puts("ATE_ERROR_INCORRECT_PARAMETER"); 521 return EINVAL; 522 } 523 getRegSpec(); 524 return 0; 525 } 526 else if (!strcmp(command, "Set_RegulationDomain_2G")) { 527#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 528 if (!chk_envrams_proc()) 529 return EINVAL; 530#endif 531 if (setRegDomain_2G(value) == -1) { 532 puts("ATE_ERROR_INCORRECT_PARAMETER"); 533 return EINVAL; 534 } 535 getRegDomain_2G(); 536 return 0; 537 } 538#if defined(RTCONFIG_HAS_5G) 539 else if (!strcmp(command, "Set_RegulationDomain_5G")) { 540#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 541 if (!chk_envrams_proc()) 542 return EINVAL; 543#endif 544 if (setRegDomain_5G(value) == -1) { 545 puts("ATE_ERROR_INCORRECT_PARAMETER"); 546 return EINVAL; 547 } 548 getRegDomain_5G(); 549 return 0; 550 } 551#endif /* RTCONFIG_HAS_5G */ 552#else /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ 553 else if (!strcmp(command, "Set_RegulationDomain_2G")) { 554#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 555 if (!chk_envrams_proc()) 556 return EINVAL; 557#endif 558 if ( !setCountryCode_2G(value)) 559 { 560 puts("ATE_ERROR_INCORRECT_PARAMETER"); 561 return EINVAL; 562 } 563#ifdef RTCONFIG_QCA 564 if ((value2==NULL) || strcmp(value2,"noctl")) 565 setCTL(value); 566#endif 567 return 0; 568 } 569#endif /* RTCONFIG_NEW_REGULATION_DOMAIN */ 570#ifdef CONFIG_BCMWL5 571 else if (!strcmp(command, "Set_RegulationDomain_5G")) { 572#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 573 if (!chk_envrams_proc()) 574 return EINVAL; 575#endif 576 577#ifdef RTCONFIG_QTN 578 if ( !setCountryCode_5G_qtn(value)) 579#else 580 if ( !setCountryCode_5G(value)) 581#endif 582 { 583 puts("ATE_ERROR_INCORRECT_PARAMETER"); 584 return EINVAL; 585 } 586 return 0; 587 } 588 else if (!strcmp(command, "Set_Regrev_2G")) { 589#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 590 if (!chk_envrams_proc()) 591 return EINVAL; 592#endif 593 594 if( !setRegrev_2G(value) ) 595 { 596 puts("ATE_ERROR_INCORRECT_PARAMETER"); 597 return EINVAL; 598 } 599 return 0; 600 } 601 else if (!strcmp(command, "Set_Regrev_5G")) { 602#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 603 if (!chk_envrams_proc()) 604 return EINVAL; 605#endif 606 607#ifdef RTCONFIG_QTN 608 if( !setRegrev_5G_qtn(value)) 609#else 610 if( !setRegrev_5G(value)) 611#endif 612 { 613 puts("ATE_ERROR_INCORRECT_PARAMETER"); 614 return EINVAL; 615 } 616 return 0; 617 } 618 else if (!strcmp(command, "Set_Commit")) { 619#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 620 if (!chk_envrams_proc()) 621 return EINVAL; 622#endif 623 setCommit(); 624 return 0; 625 } 626#endif 627#if defined(RTN14U) 628 else if (!strcmp(command, "pkt_flood")) { 629 if (nvram_invmatch("asus_mfg", "0")) 630 { 631#if 0 // TBD 632 struct sockaddr_ll dev,dev2; 633 int fd,fd2,do_flag=3; 634 unsigned char buffer[1514]; 635 fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 636 dev.sll_family = AF_PACKET; 637 dev.sll_protocol = htons(ETH_P_ALL); 638 dev.sll_ifindex = 4; // LAN 639 bind( fd, (struct sockaddr *) &dev, sizeof(dev)); 640 641 fd2 = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 642 dev2.sll_family = AF_PACKET; 643 dev2.sll_protocol = htons(ETH_P_ALL); 644 dev2.sll_ifindex = 5; // WAN 645 bind( fd2, (struct sockaddr *) &dev2, sizeof(dev2)); 646 647 if (value) { 648 if(strcmp(value,"WAN")==0) 649 do_flag = 2; 650 else if(strcmp(value,"LAN")==0) 651 do_flag = 1; 652 } 653 memset(buffer,0xff,6); 654 FRead(buffer+6, OFFSET_MAC_ADDR_2G, 6); 655 memset(buffer+12,0x55,1502); 656 while(1) 657 { 658 if (do_flag & 1) 659 send( fd, buffer, 1514, 0); 660 if (do_flag & 2) 661 send( fd2, buffer, 1514, 0); 662 } 663#endif 664 } 665 return 0; 666 } 667#endif 668 else if (!strcmp(command, "Set_SerialNumber")) { 669#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 670 if (!chk_envrams_proc()) 671 return EINVAL; 672#endif 673 674 if(!setSN(value)) 675 { 676 puts("ATE_ERROR_INCORRECT_PARAMETER"); 677 return EINVAL; 678 } 679 return 0; 680 } 681#ifdef RTCONFIG_ODMPID 682 else if (!strcmp(command, "Set_ModelName")) { 683#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 684 if (!chk_envrams_proc()) 685 return EINVAL; 686#endif 687 688 if(!setMN(value)) 689 { 690 puts("ATE_ERROR_INCORRECT_PARAMETER"); 691 return EINVAL; 692 } 693 return 0; 694 } 695#endif 696 else if (!strcmp(command, "Set_PINCode")) { 697#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 698 if (!chk_envrams_proc()) 699 return EINVAL; 700#endif 701 702 if (!setPIN(value)) 703 { 704 puts("ATE_ERROR_INCORRECT_PARAMETER"); 705 return EINVAL; 706 } 707 return 0; 708 } 709 else if (!strcmp(command, "Set_40M_Channel_2G")) { 710 if(!set40M_Channel_2G((char*)value)) 711 { 712 puts("ATE_ERROR_INCORRECT_PARAMETER"); 713 return EINVAL; 714 } 715 return 0; 716 } 717#if defined(RTCONFIG_HAS_5G) 718 else if (!strcmp(command, "Set_40M_Channel_5G")) { 719 if(!set40M_Channel_5G((char*)value)) 720 { 721 puts("ATE_ERROR_INCORRECT_PARAMETER"); 722 return EINVAL; 723 } 724 return 0; 725 } 726#endif /* RTCONFIG_HAS_5G */ 727 else if (!strcmp(command, "Set_RestoreDefault")) { 728#ifdef RTAC87U 729 int ret_reset; 730#endif 731 nvram_set("restore_defaults", "1"); 732 nvram_set(ASUS_STOP_COMMIT, "1"); 733#ifdef RTAC87U 734 ret_reset = ResetDefault(); 735 if(ret_reset == 0){ 736 logmessage("ATE", "Set_RestoreDefault OK"); 737 sleep(3); 738 puts("1"); 739 }else{ 740 logmessage("ATE", "Set_RestoreDefault failed"); 741 sleep(3); 742 puts("0"); 743 } 744#else 745 ResetDefault(); 746#endif 747 return 0; 748 } 749 else if (!strcmp(command, "Set_Eject")) { 750 if( !Ej_device(value)) { 751 puts("ATE_ERROR_INCORRECT_PARAMETER"); 752 return EINVAL; 753 } 754 return 0; 755 } 756#ifdef RTCONFIG_FANCTRL 757 else if (!strcmp(command, "Set_FanOn")) { 758 setFanOn(); 759 return 0; 760 } 761 else if (!strcmp(command, "Set_FanOff")) { 762 setFanOff(); 763 return 0; 764 } 765#endif 766#ifdef CONFIG_BCMWL5 767 else if (!strcmp(command, "Set_WaitTime")) { 768#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 769 if (!chk_envrams_proc()) 770 return EINVAL; 771#endif 772 773 if( !setWaitTime(value) ) 774 { 775 puts("ATE_ERROR_INCORRECT_PARAMETER"); 776 return EINVAL; 777 } 778 return 0; 779 } 780 else if (!strcmp(command, "Set_WiFi_2G")) { 781 if( !setWiFi2G(value) ) 782 { 783 puts("ATE_ERROR_INCORRECT_PARAMETER"); 784 return EINVAL; 785 } 786 return 0; 787 } 788#if defined(RTCONFIG_HAS_5G) 789 else if (!strcmp(command, "Set_WiFi_5G")) { 790 if( !setWiFi5G(value) ) 791 { 792 puts("ATE_ERROR_INCORRECT_PARAMETER"); 793 return EINVAL; 794 } 795 return 0; 796 } 797#endif /* RTCONFIG_HAS_5G */ 798#endif 799#ifdef RTCONFIG_RALINK 800 else if (!strcmp(command, "Set_DevFlags")) { 801 if( Set_Device_Flags(value) < 0 ) 802 { 803 puts("ATE_ERROR_INCORRECT_PARAMETER"); 804 return EINVAL; 805 } 806 return 0; 807 } 808 else if (!strcmp(command, "Set_WanToLan")) { 809 set_wantolan(); 810 modprobe_r("hw_nat"); 811 modprobe("hw_nat"); 812 stop_wanduck(); 813 stop_udhcpc(-1); 814 return 0; 815 } 816#if defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTN56UB2) 817 else if (!strcmp(command, "Set_FixChannel")) { 818 FWrite("1", OFFSET_FIX_CHANNEL, 1); 819 puts("1"); 820 return 0; 821 } 822 else if (!strcmp(command, "Set_FreeChannel")) { 823 FWrite("0", OFFSET_FIX_CHANNEL, 1); 824 nvram_set("wl0_channel","0"); 825 nvram_set("wl1_channel","0"); 826 nvram_set("lan_stp","1"); 827 nvram_commit(); 828 puts("1"); 829 return 0; 830 } 831#endif 832#endif 833 else if (!strcmp(command, "Set_XSetting")) { 834 if(value == NULL || strcmp(value, "1")) { 835 puts("ATE_ERROR_INCORRECT_PARAMETER"); 836 return EINVAL; 837 } 838 else { 839 nvram_set("x_Setting", "1"); 840 puts(nvram_get("x_Setting")); 841 } 842 return 0; 843 } 844 /*** ATE Get functions ***/ 845 else if (!strcmp(command, "Get_FWVersion")) { 846 char fwver[12]; 847 sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno")); 848 puts(fwver); 849 return 0; 850 } 851 else if (!strcmp(command, "Get_BootLoaderVersion")) { 852 getBootVer(); 853 return 0; 854 } 855 else if (!strcmp(command, "Get_ResetButtonStatus")) { 856 puts(nvram_safe_get("btn_rst")); 857 return 0; 858 } 859 else if (!strcmp(command, "Get_WpsButtonStatus")) { 860 puts(nvram_safe_get("btn_ez")); 861 return 0; 862 } 863#ifdef RTCONFIG_WIFI_TOG_BTN 864 else if (!strcmp(command, "Get_WirelessButtonStatus")) { 865 puts(nvram_safe_get("btn_wifi_toggle")); 866 return 0; 867 } 868#endif 869#ifdef RTCONFIG_SWMODE_SWITCH 870#if defined(PLAC66U) 871 else if (!strcmp(command, "Get_SwitchStatus")) { 872 puts(nvram_safe_get("switch_mode")); 873 return 0; 874 } 875#endif /* Model */ 876#endif /* RTCONFIG_SWMODE_SWITCH */ 877 else if (!strcmp(command, "Get_SWMode")) { 878 puts(nvram_safe_get("sw_mode")); 879 return 0; 880 } 881 else if (!strcmp(command, "Get_MacAddr_2G")) { 882 getMAC_2G(); 883 return 0; 884 } 885#if defined(RTCONFIG_HAS_5G) 886 else if (!strcmp(command, "Get_MacAddr_5G")) { 887#ifdef RTCONFIG_QTN 888 getMAC_5G_qtn(); 889#else 890 getMAC_5G(); 891#endif 892 return 0; 893 } 894#if defined(RTAC3200) || defined(RTAC5300)|| defined(RTAC5300R) 895 else if (!strcmp(command, "Get_MacAddr_5G_2")) { 896 getMAC_5G_2(); 897 return 0; 898 } 899#endif 900#endif /* RTCONFIG_HAS_5G */ 901 else if (!strcmp(command, "Get_Usb2p0_Port1_Infor") || !strcmp(command, "Get_Usb_Port1_Infor")) { 902 Get_USB_Port_Info("1"); 903 return 0; 904 } 905 else if (!strcmp(command, "Get_Usb2p0_Port1_Folder") || !strcmp(command, "Get_Usb_Port1_Folder")) { 906 Get_USB_Port_Folder("1"); 907 return 0; 908 } 909 else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) { 910 Get_USB_Port_Info("2"); 911 return 0; 912 } 913 else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) { 914 Get_USB_Port_Folder("2"); 915 return 0; 916 } 917 else if (!strcmp(command, "Get_Usb_Port1_DataRate")) { 918 if (!Get_USB_Port_DataRate("1")) 919 puts("ATE_ERROR"); 920 return 0; 921 } 922#if defined(RTCONFIG_M2_SSD) 923 /* Because M.2 SSD is assigned to port 3 and BRT-AC828M2 doesn't have SD card. 924 * It's safe to call functions for SD card here. 925 */ 926 else if (!strcmp(command, "Get_M2Ssd_Infor")) { 927 Get_SD_Card_Info(); 928 return 0; 929 } 930 else if (!strcmp(command, "Get_M2Ssd_Folder")) { 931 Get_SD_Card_Folder(); 932 return 0; 933 } 934 else if (!strcmp(command, "Get_M2Ssd_DataRate")) { 935 if (!Get_USB_Port_DataRate("3")) 936 puts("ATE_ERROR"); 937 return 0; 938 } 939#endif 940 else if (!strcmp(command, "Get_SD_Infor")) { 941 Get_SD_Card_Info(); 942 return 0; 943 } 944 else if (!strcmp(command, "Get_SD_Folder")) { 945 Get_SD_Card_Folder(); 946 return 0; 947 } 948#if defined(RTCONFIG_NEW_REGULATION_DOMAIN) 949 else if (!strcmp(command, "Get_RegSpec")) { 950 getRegSpec(); 951 return 0; 952 } 953 else if (!strcmp(command, "Get_RegulationDomain_2G")) { 954 getRegDomain_2G(); 955 return 0; 956 } 957#if defined(RTCONFIG_HAS_5G) 958 else if (!strcmp(command, "Get_RegulationDomain_5G")) { 959 getRegDomain_5G(); 960 return 0; 961 } 962#endif /* RTCONFIG_HAS_5G */ 963#else /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ 964 else if (!strcmp(command, "Get_RegulationDomain_2G")) { 965 getCountryCode_2G(); 966 return 0; 967 } 968#endif /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ 969#ifdef CONFIG_BCMWL5 970 else if (!strcmp(command, "Get_RegulationDomain_5G")) { 971#ifdef RTCONFIG_QTN 972 getCountryCode_5G_qtn(); 973#else 974 getCountryCode_5G(); 975#endif 976 return 0; 977 } 978 else if (!strcmp(command, "Get_Regrev_2G")) { 979 getRegrev_2G(); 980 return 0; 981 } 982#if defined(RTCONFIG_HAS_5G) 983 else if (!strcmp(command, "Get_Regrev_5G")) { 984#ifdef RTCONFIG_QTN 985 getRegrev_5G_qtn(); 986#else 987 getRegrev_5G(); 988#endif 989 return 0; 990 } 991#endif /* RTCONFIG_HAS_5G */ 992#endif 993 else if (!strcmp(command, "Get_SerialNumber")) { 994 getSN(); 995 return 0; 996 } 997#ifdef RTCONFIG_ODMPID 998 else if (!strcmp(command, "Get_ModelName")) { 999 getMN(); 1000 return 0; 1001 } 1002#endif 1003 else if (!strcmp(command, "Get_PINCode")) { 1004 getPIN(); 1005 return 0; 1006 } 1007 else if (!strcmp(command, "Get_WanLanStatus")) { 1008#if defined(RTCONFIG_EXT_RTL8365MB) || defined(RTCONFIG_EXT_RTL8370MB) 1009 GetPhyStatus(1); 1010#else 1011 if( !GetPhyStatus(1)) 1012 puts("ATE_ERROR"); 1013#endif 1014 1015 return 0; 1016 } 1017 else if (!strcmp(command, "Get_FwReadyStatus")) { 1018 puts(nvram_safe_get("success_start_service")); 1019 return 0; 1020 } 1021 else if (!strcmp(command, "Get_Build_Info")) { 1022 puts(nvram_safe_get("buildinfo")); 1023 return 0; 1024 } 1025#ifdef RTCONFIG_RALINK 1026 else if (!strcmp(command, "Get_RSSI_2G")) { 1027 getrssi(0); 1028 return 0; 1029 } 1030#if defined(RTCONFIG_HAS_5G) 1031 else if (!strcmp(command, "Get_RSSI_5G")) { 1032 getrssi(1); 1033 return 0; 1034 } 1035#endif /* RTCONFIG_HAS_5G */ 1036#endif 1037 else if (!strcmp(command, "Get_ChannelList_2G")) { 1038 if(!Get_ChannelList_2G()) 1039 puts("ATE_ERROR"); 1040 return 0; 1041 } 1042#if defined(RTCONFIG_HAS_5G) 1043 else if (!strcmp(command, "Get_ChannelList_5G")) { 1044#ifdef RTCONFIG_QTN 1045 if (!Get_ChannelList_5G_qtn()) 1046#else 1047 if (!Get_ChannelList_5G()) 1048#endif 1049 puts("ATE_ERROR"); 1050 return 0; 1051 } 1052#if defined(RTAC3200) || defined(RTAC5300)|| defined(RTAC5300R) 1053 else if (!strcmp(command, "Get_ChannelList_5G_2")) { 1054 if (!Get_ChannelList_5G_2()) 1055 puts("ATE_ERROR"); 1056 return 0; 1057 } 1058#endif 1059#endif /* RTCONFIG_HAS_5G */ 1060#if defined(RTCONFIG_USB_XHCI) 1061 else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) { 1062 if (!Get_USB3_Port_Info("1")) 1063 puts("ATE_ERROR"); 1064 return 0; 1065 } 1066 else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) { 1067 if (!Get_USB3_Port_Info("2")) 1068 puts("ATE_ERROR"); 1069 return 0; 1070 } 1071 else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) { 1072 puts("ATE_ERROR"); //Need to implement 1073 return 0; 1074 } 1075 else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) { 1076 if (!Get_USB3_Port_Folder("1")) 1077 puts("ATE_ERROR"); 1078 return 0; 1079 } 1080 else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) { 1081 if (!Get_USB3_Port_Folder("2")) 1082 puts("ATE_ERROR"); 1083 return 0; 1084 } 1085 else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) { 1086 puts("ATE_ERROR"); //Need to implement 1087 return EINVAL; 1088 } 1089 else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) { 1090 if (!Get_USB3_Port_DataRate("1")) 1091 puts("ATE_ERROR"); 1092 return 0; 1093 } 1094 else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) { 1095 if (!Get_USB3_Port_DataRate("2")) 1096 puts("ATE_ERROR"); 1097 return 0; 1098 } 1099 else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) { 1100 puts("ATE_ERROR"); //Need to implement 1101 return EINVAL; 1102 } 1103#endif /* RTCONFIG_USB_XHCI */ 1104 else if (!strcmp(command, "Get_fail_ret")) { 1105 Get_fail_ret(); 1106 return 0; 1107 } 1108 else if (!strcmp(command, "Get_fail_reboot_log")) { 1109 Get_fail_reboot_log(); 1110 return 0; 1111 } 1112 else if (!strcmp(command, "Get_fail_dev_log")) { 1113 Get_fail_dev_log(); 1114 return 0; 1115 } 1116#ifdef RTCONFIG_RALINK 1117#if !defined(RTN14U) && !defined(RTAC52U) && !defined(RTAC51U) && !defined(RTN11P) && !defined(RTN300) && !defined(RTN54U) && !defined(RTAC1200HP) && !defined(RTN56UB1) && !defined(RTAC54U) && !defined(RTN56UB2) 1118 else if (!strcmp(command, "Ra_FWRITE")) { 1119 return FWRITE(value, value2); 1120 } 1121 else if (!strcmp(command, "Ra_Asuscfe_2G")) { 1122 return asuscfe(value, WIF_2G); 1123 } 1124#if defined(RTCONFIG_HAS_5G) 1125 else if (!strcmp(command, "Ra_Asuscfe_5G")) { 1126 return asuscfe(value, WIF_5G); 1127 } 1128#endif /* RTCONFIG_HAS_5G */ 1129 else if (!strcmp(command, "Set_SwitchPort_LEDs")) { 1130 if(Set_SwitchPort_LEDs(value, value2) < 0) 1131 { 1132 puts("ATE_ERROR"); 1133 return EINVAL; 1134 } 1135 return 0; 1136 } 1137#endif 1138#endif 1139#ifdef RTCONFIG_WIRELESS_SWITCH 1140 else if (!strcmp(command, "Get_WifiSwStatus")) { 1141 puts(nvram_safe_get("btn_wifi_sw")); 1142 return 0; 1143 } 1144#endif 1145 1146#ifdef RTCONFIG_WIFI_TOG_BTN 1147 else if (!strcmp(command, "Get_WifiButtonStatus")) { 1148 puts(nvram_safe_get("btn_wifi_toggle")); 1149 return 0; 1150 } 1151#endif 1152#ifdef RTCONFIG_TURBO 1153 else if (!strcmp(command, "Get_Turbo")) { 1154 puts(nvram_safe_get("btn_turbo")); 1155 return 0; 1156 } 1157#endif 1158#ifdef RTCONFIG_LED_BTN 1159 else if (!strcmp(command, "Get_LedButtonStatus")) { 1160 puts(nvram_safe_get("btn_led")); 1161 return 0; 1162 } 1163#endif 1164#ifdef RTCONFIG_QTN 1165 else if (!strcmp(command, "Enable_Qtn_TelnetSrv")) { 1166 enable_qtn_telnetsrv(1); 1167 puts("1"); 1168 return 0; 1169 } 1170 else if (!strcmp(command, "Disable_Qtn_TelnetSrv")) { 1171 enable_qtn_telnetsrv(0); 1172 puts("1"); 1173 return 0; 1174 } 1175 else if (!strcmp(command, "Get_Qtn_TelnetSrv_Status")) { 1176 getstatus_qtn_telnetsrv(); 1177 return 0; 1178 } 1179 else if (!strcmp(command, "Del_Qtn_Cal_Files")) { 1180 del_qtn_cal_files(); 1181 puts("1"); 1182 return 0; 1183 } 1184#endif 1185#ifdef CONFIG_BCMWL5 1186 else if (!strcmp(command, "Get_WiFiStatus_2G")) { 1187 if(!getWiFiStatus("2G")) 1188 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1189 return 0; 1190 } 1191 else if (!strcmp(command, "Get_WiFiStatus_5G")) { 1192 if(!getWiFiStatus("5G")) 1193 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1194 return 0; 1195 } 1196#else 1197 else if (!strcmp(command, "Get_WiFiStatus_2G")) { 1198 if(get_radio(0, 0)) 1199 puts("1"); 1200 else 1201 puts("0"); 1202 return 0; 1203 } 1204#if defined(RTCONFIG_HAS_5G) 1205 else if (!strcmp(command, "Get_WiFiStatus_5G")) { 1206 if(get_radio(1, 0)) 1207 puts("1"); 1208 else 1209 puts("0"); 1210 return 0; 1211 } 1212#endif /* RTCONFIG_HAS_5G */ 1213#endif 1214 else if (!strcmp(command, "Set_WiFiStatus_2G")) { 1215 int act = !strcmp(value, "on"); 1216 1217 if(!strcmp(value, "on") && !strcmp(value, "off")) 1218 puts("ATE_UNSUPPORT"); 1219 1220 set_radio(act, 0, 0); 1221 1222 if(get_radio(0, 0)){ 1223 if(act) 1224 puts("success=on"); 1225 else 1226 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1227 } else{ 1228 if(!act) 1229 puts("success=off"); 1230 else 1231 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1232 } 1233 return 0; 1234 } 1235#if defined(RTCONFIG_HAS_5G) 1236 else if (!strcmp(command, "Set_WiFiStatus_5G")) { 1237 int act = !strcmp(value, "on"); 1238 1239 if(!strcmp(value, "on") && !strcmp(value, "off")) 1240 puts("ATE_UNSUPPORT"); 1241 1242 set_radio(act, 1, 0); 1243 1244 if(get_radio(1, 0)){ 1245 if(act) 1246 puts("success=on"); 1247 else 1248 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1249 } else{ 1250 if(!act) 1251 puts("success=off"); 1252 else 1253 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1254 } 1255 return 0; 1256 } 1257#endif /* RTCONFIG_HAS_5G */ 1258 else if (!strcmp(command, "Get_ATEVersion")) { 1259 puts(nvram_safe_get("Ate_version")); 1260 return 0; 1261 } 1262 else if (!strcmp(command, "Get_XSetting")) { 1263 puts(nvram_safe_get("x_Setting")); 1264 return 0; 1265 } 1266 else if (!strcmp(command, "Get_WaitTime")) { 1267 puts(nvram_safe_get("wait_time")); 1268 return 0; 1269 } 1270 else if (!strcmp(command, "Get_ExtendNo")) { 1271 puts(nvram_safe_get("extendno")); 1272 return 0; 1273 } 1274#ifdef RTCONFIG_RALINK 1275 else if (!strcmp(command, "Get_DevFlags")) { 1276 if( Get_Device_Flags() < 0) 1277 { 1278 puts("ATE_ERROR"); 1279 return EINVAL; 1280 } 1281 return 0; 1282 } 1283#endif 1284#ifdef RTCONFIG_QCA 1285/* 1286 else if (!strcmp(command, "Set_ART2")) { 1287 // temp solution 1288 killall_tk("rstats"); 1289 stop_wanduck(); 1290 stop_udhcpc(-1); 1291 killall_tk("networkmap"); 1292 killall_tk("hostapd"); 1293 ifconfig("ath0", 0, NULL, NULL); 1294 ifconfig("ath1", 0, NULL, NULL); 1295 eval("brctl", "delif", "br0", "ath0"); 1296 eval("brctl", "delif", "br0", "ath1"); 1297 eval("wlanconfig", "ath0", "destroy"); 1298 eval("wlanconfig", "ath1", "destroy"); 1299 ifconfig("wifi0", 0, NULL, NULL); 1300 ifconfig("wifi1", 0, NULL, NULL); 1301 modprobe_r("umac"); 1302 modprobe_r("ath_dfs"); 1303 modprobe_r("ath_dev"); 1304 modprobe_r("ath_rate_atheros"); 1305 modprobe_r("ath_spectral"); 1306 modprobe_r("ath_hal"); 1307 modprobe_r("adf"); 1308 modprobe_r("asf"); 1309 modprobe("art"); 1310 system("nart.out -port 2390 -console &"); 1311 system("nart.out -port 2391 -console &"); 1312 return 0; 1313 } 1314*/ 1315 else if (!strncmp(command, "Get_EEPROM_", 11)) { 1316 unsigned char buffer[2560]; 1317 unsigned short len; 1318 int lret; 1319 char *pt; 1320 len=sizeof(buffer); 1321 pt = (char*) command + 11; 1322 if (!strcmp(pt, "2G")) 1323 lret=getEEPROM(&buffer[0], &len, pt); 1324 else if (!strcmp(pt, "5G")) 1325 lret=getEEPROM(&buffer[0], &len, pt); 1326 else if (!strcmp(pt, "CAL_2G")) 1327 lret=getEEPROM(&buffer[0], &len, pt); 1328 else if (!strcmp(pt, "CAL_5G")) 1329 lret=getEEPROM(&buffer[0], &len, pt); 1330 else { 1331 puts("ATE_UNSUPPORT"); 1332 return EINVAL; 1333 } 1334 if ( !lret ) 1335 hexdump(&buffer[0], len); 1336 return 0; 1337 } 1338 else if (!strcmp(command, "Get_CalCompare")) { 1339 unsigned char buffer[2560], buffer2[2560]; 1340 unsigned short len, len2; 1341 int lret=0, cret=0; 1342 len=sizeof(buffer); 1343 len2=sizeof(buffer2); 1344 lret+=getEEPROM(&buffer[0], &len, "2G"); 1345 lret+=getEEPROM(&buffer2[0], &len2, "CAL_2G"); 1346 if (lret) 1347 return EINVAL; 1348 if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) { 1349 puts("2G EEPROM different!"); 1350 cret++; 1351 } 1352 len=sizeof(buffer); 1353 len2=sizeof(buffer2); 1354 lret+=getEEPROM(&buffer[0], &len, "5G"); 1355 lret+=getEEPROM(&buffer2[0], &len2, "CAL_5G"); 1356 if (lret) 1357 return EINVAL; 1358 if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) { 1359 puts("5G EEPROM different!"); 1360 cret++; 1361 } 1362 if (!cret) 1363 puts("1"); 1364 else 1365 puts("0"); 1366 return 0; 1367 } 1368#ifdef RTCONFIG_ATEUSB3_FORCE 1369 else if (!strcmp(command, "Set_ForceUSB3")) { 1370 if (setForceU3(value) < 0) 1371 { 1372 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1373 return EINVAL; 1374 } 1375 getForceU3(); 1376 return 0; 1377 } 1378 else if (!strcmp(command, "Get_ForceUSB3")) { 1379 getForceU3(); 1380 return 0; 1381 } 1382#endif 1383#endif /* RTCONFIG_QCA */ 1384#ifdef RTCONFIG_INTERNAL_GOBI 1385 else if(!strcmp(command, "Get_LteButtonStatus")) { 1386 puts(nvram_safe_get("btn_lte")); 1387 return 0; 1388 } 1389 else if(!strcmp(command, "Get_GobiSimCard")) { 1390 char line[128]; 1391 if (!Gobi_SimCardReady(Gobi_SimCard(line, sizeof(line)))) 1392 { 1393 puts("FAIL"); 1394 return EINVAL; 1395 } 1396 puts("PASS"); 1397 } 1398 else if(!strcmp(command, "Get_GobiIMEI")) { 1399 char line[128]; 1400 const char *IMEI = Gobi_IMEI(line, sizeof(line)); 1401 if (IMEI == NULL) 1402 { 1403 puts("FAIL"); 1404 return EINVAL; 1405 } 1406 puts(IMEI); 1407 } 1408 else if(!strcmp(command, "Get_GobiConnectISP")) { 1409 char line[128]; 1410 const char *ISP = Gobi_ConnectISP(line, sizeof(line)); 1411 if (ISP == NULL) 1412 { 1413 puts("FAIL"); 1414 return EINVAL; 1415 } 1416 puts(ISP); 1417 } 1418 else if(!strcmp(command, "Get_GobiConnectStatus")) { 1419 const char *status = Gobi_ConnectStatus_Str(Gobi_ConnectStatus_Int()); 1420 if (status == NULL) 1421 { 1422 puts("FAIL"); 1423 return EINVAL; 1424 } 1425 puts(status); 1426 } 1427 else if(!strcmp(command, "Get_GobiSignal_Percent")) { 1428 int percent = Gobi_SignalQuality_Percent(Gobi_SignalQuality_Int()); 1429 if (percent < 0) 1430 { 1431 puts("FAIL"); 1432 return EINVAL; 1433 } 1434 printf("%d\n", percent); 1435 } 1436 else if(!strcmp(command, "Get_GobiSignal_dbm")) { 1437 int dbm = Gobi_SignalLevel_Int(); 1438 if (dbm >= 0) 1439 { 1440 puts("FAIL"); 1441 return EINVAL; 1442 } 1443 printf("%d dBm\n", dbm); 1444 } 1445 else if(!strcmp(command, "Get_GobiVersion")) { 1446 char line[128]; 1447 if (Gobi_FwVersion(line, sizeof(line)) == NULL) 1448 { 1449 puts("FAIL"); 1450 return EINVAL; 1451 } 1452 printf("%s\n", line); 1453 } 1454 else if(!strcmp(command, "Get_GobiQcnVersion")) { 1455 char line[128]; 1456 if (Gobi_QcnVersion(line, sizeof(line)) == NULL) 1457 { 1458 puts("FAIL"); 1459 return EINVAL; 1460 } 1461 printf("%s\n", line); 1462 } 1463 else if(!strcmp(command, "Set_GobiBand")) { 1464 char line[128]; 1465 if (Gobi_SelectBand(value, line, sizeof(line)) == NULL) 1466 { 1467 puts("FAIL"); 1468 return EINVAL; 1469 } 1470 printf("FINISH\n"); 1471 } 1472 else if(!strcmp(command, "Get_GobiBand")) { 1473 char line[128]; 1474 char *band; 1475 if ((band = Gobi_BandChannel(line, sizeof(line))) == NULL) 1476 { 1477 puts("FAIL"); 1478 return EINVAL; 1479 } 1480 cprintf("line(%p) band(%p)\n", line, band); 1481 printf("%s\n", band); 1482 } 1483#endif /* RTCONFIG_INTERNAL_GOBI */ 1484#if defined(RTCONFIG_TCODE) 1485 else if (!strcmp(command, "Set_TerritoryCode")) { 1486#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 1487 if (!chk_envrams_proc()) 1488 return EINVAL; 1489#endif 1490 1491 if (setTerritoryCode(value) < 0) 1492 { 1493 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1494 return EINVAL; 1495 } 1496#ifndef CONFIG_BCMWL5 1497 getTerritoryCode(); 1498#endif 1499 return 0; 1500 } 1501 else if (!strcmp(command, "Get_TerritoryCode")) { 1502 getTerritoryCode(); 1503 return 0; 1504 } 1505#if defined(CONFIG_BCMWL5) || defined(RTCONFIG_QCA) || defined(RTCONFIG_RALINK) 1506 else if (!strcmp(command, "Set_PSK")) { 1507#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 1508 if (!chk_envrams_proc()) 1509 return EINVAL; 1510#endif 1511 1512 if (setPSK(value) < 0) 1513 { 1514 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1515 return EINVAL; 1516 } 1517#ifndef CONFIG_BCMWL5 1518 getPSK(); 1519#endif 1520 return 0; 1521 } 1522 else if (!strcmp(command, "Get_PSK")) { 1523 getPSK(); 1524 return 0; 1525 } 1526#endif 1527#endif 1528#ifdef RTCONFIG_QCA_PLC_UTILS 1529 else if(!strcmp(command, "Set_MacAddr_Plc")) { 1530 if (!setPLC_para(value, OFFSET_PLC_MAC)) 1531 { 1532 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1533 return EINVAL; 1534 } 1535 return 0; 1536 } 1537 else if(!strcmp(command, "Get_MacAddr_Plc")) { 1538 getPLC_para(OFFSET_PLC_MAC); 1539 return 0; 1540 } 1541 else if(!strcmp(command, "Set_NMK_Plc")) { 1542 if (!setPLC_para(value, OFFSET_PLC_NMK)) 1543 { 1544 puts("ATE_ERROR_INCORRECT_PARAMETER"); 1545 return EINVAL; 1546 } 1547 return 0; 1548 } 1549 else if(!strcmp(command, "Get_NMK_Plc")) { 1550 getPLC_para(OFFSET_PLC_NMK); 1551 return 0; 1552 } 1553 else if(!strcmp(command, "Get_PWD_Plc")) { 1554 if (!getPLC_PWD()) { 1555 puts("ATE_ERROR"); 1556 return EINVAL; 1557 } 1558 return 0; 1559 } 1560#endif 1561#ifdef RTCONFIG_DEFAULT_AP_MODE 1562 else if(!strcmp(command, "Set_ForceDisableDHCP")) { 1563 FWrite("1", OFFSET_FORCE_DISABLE_DHCP, 1); 1564 puts("1"); 1565 return 0; 1566 } 1567 else if(!strcmp(command, "Set_FreeDisableDHCP")) { 1568 char buf[2]; 1569 FWrite("0", OFFSET_FORCE_DISABLE_DHCP, 1); 1570 if (FRead(buf, OFFSET_FORCE_DISABLE_DHCP, 1) < 0) 1571 puts("ATE_ERROR"); 1572 else { 1573 buf[1] = '\0'; 1574 puts(buf); 1575 } 1576 return 0; 1577 } 1578#endif 1579 else 1580 { 1581 puts("ATE_UNSUPPORT"); 1582 return EINVAL; 1583 } 1584 1585 return 0; 1586} 1587 1588int ate_dev_status(void) 1589{ 1590 int ret = 1, wl_band=1;; 1591 char wl_dev_name[12], dev_chk_buf[19], word[256], *next; 1592 1593 sprintf(wl_dev_name, nvram_safe_get("wl_ifnames")); 1594 if(switch_exist()) 1595 sprintf(dev_chk_buf, "switch=O"); 1596 else { 1597 sprintf(dev_chk_buf, "switch=X"); 1598#ifdef CONFIG_BCMWL5 //broadcom platform need to shift the interface name 1599 sprintf(wl_dev_name, "eth0 eth1"); 1600#endif 1601 ret = 0; 1602 } 1603 1604 foreach (word, wl_dev_name, next) { 1605 if (wl_exist(word, wl_band)) { 1606 if(wl_band==1) 1607 sprintf(dev_chk_buf,"%s,2G=O",dev_chk_buf); 1608 else 1609 sprintf(dev_chk_buf,"%s,5G=O",dev_chk_buf); 1610 } 1611 else { 1612 if(wl_band==1) 1613 sprintf(dev_chk_buf,"%s,2G=X",dev_chk_buf); 1614 else 1615 sprintf(dev_chk_buf,"%s,5G=X",dev_chk_buf); 1616 ret = 0; 1617 } 1618 wl_band++; 1619 } 1620 nvram_set("Ate_dev_status",dev_chk_buf); 1621 return ret; 1622} 1623 1624#if defined(RTCONFIG_CFEZ) && defined(RTCONFIG_BCMARM) 1625int chk_envrams_proc(void) 1626{ 1627 if (!pids("envrams")) 1628 { 1629 puts("ATE_ERROR_NOT_ALLOWED"); 1630 return 0; 1631 } 1632 1633 return 1; 1634} 1635 1636int start_envrams(void){ 1637 1638 int ret=eval("/usr/sbin/envrams"); 1639 return ret; 1640} 1641 1642#endif 1643