Ejemplo n.º 1
0
int QuectelM10::configandwait(char* pin)
{
  _tf.setTimeout(_GSM_CONNECTION_TOUT_);

  if(pin) setPIN(pin); //syv

  // Try 5 times to register in the network. Note this can take some time!
  for(int i=0; i<10; i++)
  {  	
    //Ask for register status to GPRS network.
    _cell << "AT+CGREG?" <<  _BYTE(cr) << endl; 

    //Se espera la unsolicited response de registered to network.
    if (_tf.find("+CGREG: 0,1")) 
    {
      setStatus(READY);
      
 	_cell << "AT+CMGF=1" <<  _BYTE(cr) << endl; //SMS text mode.
  	delay(200);
      // Buah, we should take this to readCall()
	_cell << "AT+CLIP=1" <<  _BYTE(cr) << endl; //SMS text mode.
  	delay(200);
  	//_cell << "AT+QIDEACT" <<  _BYTE(cr) << endl; //To make sure not pending connection.
  	//delay(1000);
  
      return 1;
    }
    //Attach GPRS service.
    //_cell << "AT+CGATT=1" <<  _BYTE(cr) << endl; 
    //delay(500);
  }
  return 0;
}
Ejemplo n.º 2
0
int SIMCOM900::configandwait(char* pin)
{
     int connCode;
     //_tf.setTimeout(_GSM_CONNECTION_TOUT_);

     if(pin) setPIN(pin); //syv

     // Try 10 times to register in the network. Note this can take some time!
     for(int i=0; i<10; i++) {
          //Ask for register status to GPRS network.
          SimpleWriteln(F("AT+CGREG?"));

          //Se espera la unsolicited response de registered to network.
          while(gsm.WaitResp(5000, 50, "+CGREG: 0,")!=RX_FINISHED_STR_RECV)
               //while (_tf.find("+CGREG: 0,"))  // CHANGE!!!!
          {
               //connCode=_tf.getValue();
               connCode=_cell.read();
               if((connCode==1)||(connCode==5)) {
                    setStatus(READY);

                    SimpleWriteln(F("AT+CMGF=1")); //SMS text mode.
                    delay(200);
                    // Buah, we should take this to readCall()
                    SimpleWriteln(F("AT+CLIP=1")); //SMS text mode.
                    delay(200);
                    //_cell << "AT+QIDEACT" <<  _DEC(cr) << endl; //To make sure not pending connection.
                    //delay(1000);

                    return 1;
               }
          }
     }
     return 0;
}
Ejemplo n.º 3
0
ESC::ESC()
{
	setMinMicro(MINM);
	setMaxMicro(MAXM);
	setPvalue(0);
	setSvalue(0);
	setPIN(defaultPIN++);
}
Ejemplo n.º 4
0
ESC::ESC(int MinM, int MaxM, int PIN)
{
	setMinMicro(MinM);
	setMaxMicro(MaxM);
	setPvalue(0);
	setSvalue(0);
	setPIN(PIN);
}
Ejemplo n.º 5
0
bool Account::createAccount(const std::string& accountName, const int& accountNum, const std::string& pin, const std::string& bankSalt)
{
	if(accountName == "")
	{
		return false;
	}
	this->accountName = accountName;
	if(accountNum <= 0)
	{
		return false;
	}
	this->accountNum = accountNum;

	this->salt = makeHash(randomString(128));

	std::string card = makeHash(to_string(this->accountNum) + salt);

	this->card = card;

	std::ofstream outfile;

	std::string cardFile = "cards/" + this->accountName + ".card";

	std::ofstream file_out(cardFile.c_str());
	// write values to cards
	if(file_out.is_open())
	{
		file_out << card;
	} 
	file_out.close();

	//If oin sucessfully set then the account can be unlocked for use.
	if(setPIN(pin, bankSalt))
	{
		islocked = false;
	} else {
		islocked = true;
	}

	return true;
}
Ejemplo n.º 6
0
void led::OFF()
{
	setPIN();
}
Ejemplo n.º 7
0
int asus_ate_command(const char *command, const char *value, const char *value2){
	_dprintf("===[ATE %s %s]===\n", command, value);
	if(!strcmp(command, "Set_StartATEMode")) {
                nvram_set("asus_mfg", "1");
                if(nvram_match("asus_mfg", "1")) {
			puts("1");
#ifdef RTCONFIG_FANCTRL
			stop_phy_tempsense();
#endif
#ifdef TODO
	                stop_wsc();
#endif
        	        stop_lltd();    
                	stop_wanduck();
	                stop_logger();
        	        stop_wanduck();
#ifdef RTCONFIG_DNSMASQ
                	stop_dnsmasq();
#else
	                stop_dns();
	                stop_dhcpd();
#endif
        	        stop_ots();
                	stop_networkmap();
#ifdef RTCONFIG_USB
	                stop_usbled();
#endif
		}
		else
			puts("ATE_ERROR");
                return 0;
        }
        else if (!strcmp(command, "Set_AllLedOn")) {
                return setAllLedOn();
        }
        else if (!strcmp(command, "Set_AllLedOff")) {
                return setAllLedOff();
        }
        else if (!strcmp(command, "Set_AllLedOn_Half")) {
                puts("Not support"); //Need to implement for EA-N66U
                return 0;
        }
        else if (!strcmp(command, "Set_MacAddr_2G")) {
                if( !setMAC_2G(value) )
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
        }
        else if (!strcmp(command, "Set_MacAddr_5G")) {
                if( !setMAC_5G(value))
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_RegulationDomain_2G")) {
                if ( !setCountryCode_2G(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
#ifdef CONFIG_BCMWL5
        else if (!strcmp(command, "Set_RegulationDomain_5G")) {
                if ( !setCountryCode_5G(value))
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_Regrev_2G")) {
                if( !setRegrev_2G(value) )
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_Regrev_5G")) {
                if( !setRegrev_5G(value))
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
#endif
        else if (!strcmp(command, "Set_PINCode")) {
                if (!setPIN(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_40M_Channel_2G")) {
                if(!set40M_Channel_2G(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_40M_Channel_5G")) {
                if(!set40M_Channel_5G(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
#ifdef RTCONFIG_FANCTRL
        else if (!strcmp(command, "Set_FanOn")) {
                setFanOn();
                return 0;
        }
        else if (!strcmp(command, "Set_FanOff")) {
                setFanOff();
                return 0;
        }
#endif
	else if (!strcmp(command, "Set_RestoreDefault")) {
		ResetDefault();
                return 0;
        }
#ifdef CONFIG_BCMWL5
        else if (!strcmp(command, "Set_Commit")) {
                setCommit();
                return 0;
        }
#endif
        else if (!strcmp(command, "Get_FWVersion")) {
	        char fwver[12];
        	sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno"));
	        puts(fwver);
                return 0;
        }
        else if (!strcmp(command, "Get_BootLoaderVersion")) {
                getBootVer();
                return 0;
        }
        else if (!strcmp(command, "Get_ResetButtonStatus")) {
                puts(nvram_safe_get("btn_rst"));
                return 0;
        }
        else if (!strcmp(command, "Get_WpsButtonStatus")) {
                puts(nvram_safe_get("btn_ez"));
                return 0;
        }
        else if (!strcmp(command, "Get_SWMode")) {
                puts(nvram_safe_get("sw_mode"));
                return 0;
        }
        else if (!strcmp(command, "Get_MacAddr_2G")) {
                getMAC_2G();
                return 0;
        }
        else if (!strcmp(command, "Get_MacAddr_5G")) {
                getMAC_5G();
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port1_Infor")) {
		Get_USB_Port_Info(1);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port1_Folder")) {
                Get_USB_Port_Folder(1);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) {
                Get_USB_Port_Info(2);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) {
                Get_USB_Port_Folder(2);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_SD_Infor")) {
		Get_SD_Card_Info();
                return 0;
        }
        else if (!strcmp(command, "Get_SD_Folder")) {
                Get_SD_Card_Folder();
                return 0;
        }
        else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getCountryCode_2G();
                return 0;
        }
#ifdef CONFIG_BCMWL5
        else if (!strcmp(command, "Get_RegulationDomain_5G")) {
           	getCountryCode_5G();
                return 0;
        }
	else if (!strcmp(command, "Get_Regrev_2G")) {
		getRegrev_2G();
		return 0;
	}
        else if (!strcmp(command, "Get_Regrev_5G")) {
		getRegrev_5G();
                return 0;
        }
#endif
        else if (!strcmp(command, "Get_PINCode")) {
                getPIN();
                return 0;
        }
        else if (!strcmp(command, "Get_WanLanStatus")) {
                if( !GetPhyStatus())
			puts("ATE_ERROR");
		return 0;
        }
        else if (!strcmp(command, "Get_FwReadyStatus")) {
                puts(nvram_safe_get("success_start_service"));
                return 0;
        }
	else if (!strcmp(command, "Get_Build_Info")) {
		puts(nvram_safe_get("buildinfo"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
        else if (!strcmp(command, "Get_RSSI_2G")) {
                getrssi(0);
                return 0;
        }
        else if (!strcmp(command, "Get_RSSI_5G")) {
                getrssi(1);
                return 0;
        }
#endif
        else if (!strcmp(command, "Get_ChannelList_2G")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_ChannelList_5G")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) {
                puts("Not support"); //Need to implement
                return 0;
        }
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Ra_FWRITE")) {
		return FWRITE(value, value2);
	}
        else if (!strcmp(command, "Ra_Asuscfe_2G")) {
                return asuscfe(value, WIF_2G);
        }
        else if (!strcmp(command, "Ra_Asuscfe_5G")) {
		return asuscfe(value, WIF_5G);
        }

#endif
        else 
	{
		puts("ATE_ERROR");
                return EINVAL;
	}
}
Ejemplo n.º 8
0
int asus_ate_command(const char *command, const char *value, const char *value2)
{
	_dprintf("===[ATE %s %s]===\n", command, value);
#ifdef RTCONFIG_QTN
	if(!nvram_match("qtn_ready", "1")){
		_dprintf("ATE Error: wireless 5G not ready\n");
		return 0;
	}
#endif
	/*** ATE Set function ***/
	if(!strcmp(command, "Set_StartATEMode")) {
		nvram_set("asus_mfg", "1");
		if(nvram_match("asus_mfg", "1")) {
			puts("1");
#ifdef RTCONFIG_FANCTRL
			stop_phy_tempsense();
#endif
			stop_wpsaide();
			stop_wps();
#ifdef RTCONFIG_BCMWL6
			stop_igmp_proxy();
#ifdef RTCONFIG_HSPOT
			stop_hspotap();
#endif
			stop_acsd();
#ifdef BCM_BSD
			stop_bsd();
#endif
#ifdef BCM_SSD
			stop_ssd();
#endif
#endif
			stop_upnp();
			stop_lltd();
			stop_rstats();
			stop_wanduck();
			stop_logger();
			stop_wanduck();
			stop_dnsmasq(0);
			stop_ots();
			stop_networkmap();
#ifdef RTCONFIG_USB
			stop_usbled();
#ifdef RTCONFIG_USB_PRINTER
			stop_lpd();
			stop_u2ec();
#endif
#endif
			platform_start_ate_mode();
		}
		else
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Set_AllLedOn")) {
		return setAllLedOn();
	}
	else if (!strcmp(command, "Set_AllLedOn2")) {
		return setAllLedOn2();
	}
	else if (!strcmp(command, "Set_AllLedOff")) {
		return setAllLedOff();
	}
	else if (!strcmp(command, "Set_AllLedOn_Half")) {
		puts("ATE_ERROR"); //Need to implement for EA-N66U
		return EINVAL;
	}
#ifdef RTCONFIG_BCMARM
	else if (!strcmp(command, "Set_AteModeLedOn")) {
		return setATEModeLedOn();
	}
#endif
	else if (!strcmp(command, "Set_MacAddr_2G")) {
		if( !setMAC_2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_MacAddr_5G")) {
#ifdef RTCONFIG_QTN
		if( !setMAC_5G_qtn(value))
#else
		if( !setMAC_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Set_MacAddr_5G_2")) {
		if( !setMAC_5G_2(value))
                {
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                        return EINVAL;
                }
                return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
#if defined(RTN14U)
	else if (!strcmp(command, "eeprom")) {
		if ( !eeprom_upgrade(value, 1))
			return EINVAL;
		return 0;
	}
	else if (!strcmp(command, "eeover")) {
		if ( !eeprom_upgrade(value, 0))
			return EINVAL;
		return 0;
	}
#endif
#if defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	else if (!strcmp(command, "Set_RegSpec")) {
		if (setRegSpec(value) < 0)
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegSpec();
		return 0;
	}
	else if (!strcmp(command, "Set_RegulationDomain_2G")) {
		if (setRegDomain_2G(value) == -1) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegDomain_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_RegulationDomain_5G")) {
		if (setRegDomain_5G(value) == -1) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegDomain_5G();
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	else if (!strcmp(command, "Set_RegulationDomain_2G")) {
		if ( !setCountryCode_2G(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
#ifdef RTCONFIG_QCA
		if ((value2==NULL) || strcmp(value2,"noctl"))
			setCTL(value);
#endif
		return 0;
	}
#endif /* RTCONFIG_NEW_REGULATION_DOMAIN */
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Set_RegulationDomain_5G")) {
#ifdef RTCONFIG_QTN
		if ( !setCountryCode_5G_qtn(value))
#else
		if ( !setCountryCode_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Regrev_2G")) {
		if( !setRegrev_2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Regrev_5G")) {
#ifdef RTCONFIG_QTN
		if( !setRegrev_5G_qtn(value))
#else
		if( !setRegrev_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Commit")) {
		setCommit();
		return 0;
	}
#endif
#if defined(RTN14U)
	else if (!strcmp(command, "pkt_flood")) {
		if (nvram_invmatch("asus_mfg", "0"))
		{
#if 0 // TBD
			struct sockaddr_ll dev,dev2;
			int fd,fd2,do_flag=3;
			unsigned char buffer[1514];
			fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
			dev.sll_family = AF_PACKET;
			dev.sll_protocol = htons(ETH_P_ALL);
			dev.sll_ifindex = 4; // LAN
			bind( fd, (struct sockaddr *) &dev, sizeof(dev));

			fd2 = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
			dev2.sll_family = AF_PACKET;
			dev2.sll_protocol = htons(ETH_P_ALL);
			dev2.sll_ifindex = 5; // WAN
			bind( fd2, (struct sockaddr *) &dev2, sizeof(dev2));

			if (value) {
				if(strcmp(value,"WAN")==0)
					do_flag = 2;
				else if(strcmp(value,"LAN")==0)
					do_flag = 1;
			}
			memset(buffer,0xff,6);
			FRead(buffer+6, OFFSET_MAC_ADDR_2G, 6);
			memset(buffer+12,0x55,1502);
			while(1)
			{
				if (do_flag & 1)
					send( fd, buffer, 1514, 0);
				if (do_flag & 2)
					send( fd2, buffer, 1514, 0);
			}
#endif
		}
		return 0;
 	}
#endif
	else if (!strcmp(command, "Set_SerialNumber")) {
		if(!setSN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
 	}
#ifdef RTCONFIG_ODMPID
	else if (!strcmp(command, "Set_ModelName")) {
		if(!setMN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif
	else if (!strcmp(command, "Set_PINCode")) {
		if (!setPIN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_40M_Channel_2G")) {
		if(!set40M_Channel_2G((char*)value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_40M_Channel_5G")) {
		if(!set40M_Channel_5G((char*)value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Set_RestoreDefault")) {
		nvram_set("restore_defaults", "1");
		ResetDefault();
		nvram_set(ASUS_STOP_COMMIT, "1");
		return 0;
	}
	else if (!strcmp(command, "Set_Eject")) {
		if( !Ej_device(value)) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#ifdef RTCONFIG_FANCTRL
	else if (!strcmp(command, "Set_FanOn")) {
		setFanOn();
		return 0;
	}
	else if (!strcmp(command, "Set_FanOff")) {
		setFanOff();
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Set_WaitTime")) {
		if( !setWaitTime(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_WiFi_2G")) {
		if( !setWiFi2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_WiFi_5G")) {
		if( !setWiFi5G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Set_DevFlags")) {
		if( Set_Device_Flags(value) < 0 )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_WanToLan")) {
	   	set_wantolan();
		modprobe_r("hw_nat");
		modprobe("hw_nat");
		system("killall -9 wanduck");
		system("killall -9 udhcpc");
		return 0;
	}
#if defined(RTAC1200HP) || defined(RTN56UB1)
        else if (!strcmp(command, "Set_FixChannel")) {
	   	 FWrite("1", OFFSET_FIX_CHANNEL, 1);	
                 puts("1");
                 return 0;
         }
        else if (!strcmp(command, "Set_FreeChannel")) {
	   	 FWrite("0", OFFSET_FIX_CHANNEL, 1);	
		 nvram_set("wl0_channel","0");
		 nvram_set("wl1_channel","0");
		 nvram_set("lan_stp","1");
		 nvram_commit();
                 puts("1");
                 return 0;
         }
#endif
#endif
	else if (!strcmp(command, "Set_XSetting")) {
		if(value == NULL || strcmp(value, "1")) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		else {
			nvram_set("x_Setting", "1");
			puts(nvram_get("x_Setting"));
		}
		return 0;
	}
	/*** ATE Get functions ***/
	else if (!strcmp(command, "Get_FWVersion")) {
		char fwver[12];
		sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno"));
		puts(fwver);
		return 0;
	}
	else if (!strcmp(command, "Get_BootLoaderVersion")) {
		getBootVer();
		return 0;
	}
	else if (!strcmp(command, "Get_ResetButtonStatus")) {
		puts(nvram_safe_get("btn_rst"));
		return 0;
	}
	else if (!strcmp(command, "Get_WpsButtonStatus")) {
		puts(nvram_safe_get("btn_ez"));
		return 0;
	}
#ifdef RT4GAC55U
	else if (!strcmp(command, "Get_LteButtonStatus")) {
		puts(nvram_safe_get("btn_lte"));
		return 0;
	}
#endif
#ifdef RTCONFIG_WIFI_TOG_BTN
	else if (!strcmp(command, "Get_WirelessButtonStatus")) {
		puts(nvram_safe_get("btn_wifi_toggle"));
		return 0;
	}
#endif
	else if (!strcmp(command, "Get_SWMode")) {
		puts(nvram_safe_get("sw_mode"));
		return 0;
	}
	else if (!strcmp(command, "Get_MacAddr_2G")) {
		getMAC_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_MacAddr_5G")) {
#ifdef RTCONFIG_QTN
		getMAC_5G_qtn();
#else
		getMAC_5G();
#endif
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Get_MacAddr_5G_2")) {
		getMAC_5G_2();
		return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Get_Usb2p0_Port1_Infor")) {
		Get_USB_Port_Info("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port1_Folder")) {
		Get_USB_Port_Folder("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) {
		Get_USB_Port_Info("2");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) {
		Get_USB_Port_Folder("2");
		return 0;
	}
	else if (!strcmp(command, "Get_SD_Infor")) {
		Get_SD_Card_Info();
		return 0;
	}
	else if (!strcmp(command, "Get_SD_Folder")) {
		Get_SD_Card_Folder();
		return 0;
	}
#if defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	else if (!strcmp(command, "Get_RegSpec")) {
		getRegSpec();
		return 0;
	}
	else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getRegDomain_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_RegulationDomain_5G")) {
		getRegDomain_5G();
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getCountryCode_2G();
		return 0;
	}
#endif	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Get_RegulationDomain_5G")) {
#ifdef RTCONFIG_QTN
		getCountryCode_5G_qtn();
#else
	   	getCountryCode_5G();
#endif
		return 0;
	}
	else if (!strcmp(command, "Get_Regrev_2G")) {
		getRegrev_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_Regrev_5G")) {
#ifdef RTCONFIG_QTN
		getRegrev_5G_qtn();
#else
		getRegrev_5G();
#endif
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Get_SerialNumber")) {
		getSN();
		return 0;
	}
#ifdef RTCONFIG_ODMPID
	else if (!strcmp(command, "Get_ModelName")) {
		getMN();
		return 0;
	}
#endif
	else if (!strcmp(command, "Get_PINCode")) {
		getPIN();
		return 0;
	}
	else if (!strcmp(command, "Get_WanLanStatus")) {
		if( !GetPhyStatus())
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_FwReadyStatus")) {
		puts(nvram_safe_get("success_start_service"));
		return 0;
	}
	else if (!strcmp(command, "Get_Build_Info")) {
		puts(nvram_safe_get("buildinfo"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Get_RSSI_2G")) {
		getrssi(0);
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_RSSI_5G")) {
		getrssi(1);
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Get_ChannelList_2G")) {
		if(!Get_ChannelList_2G())
			puts("ATE_ERROR");
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_ChannelList_5G")) {
#ifdef RTCONFIG_QTN
		if (!Get_ChannelList_5G_qtn())
#else
		if (!Get_ChannelList_5G())
#endif
			puts("ATE_ERROR");
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Get_ChannelList_5G_2")) {
		if (!Get_ChannelList_5G_2())
			puts("ATE_ERROR");
		return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
#if defined(RTCONFIG_USB_XHCI)
	else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) {
		if (!Get_USB3_Port_Info("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) {
		if (!Get_USB3_Port_Info("2"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) {
		puts("ATE_ERROR"); //Need to implement
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) {
		if (!Get_USB3_Port_Folder("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) {
		if (!Get_USB3_Port_Folder("2"))
			puts("ATE_ERROR");
		return 0;
	}
 	else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) {
		puts("ATE_ERROR"); //Need to implement
		return EINVAL;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) {
		if (!Get_USB3_Port_DataRate("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) {
		if (!Get_USB3_Port_DataRate("2"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) {
		puts("ATE_ERROR"); //Need to implement
		return EINVAL;
	}
#endif	/* RTCONFIG_USB_XHCI */
	else if (!strcmp(command, "Get_fail_ret")) {
		Get_fail_ret();
		return 0;
	}
	else if (!strcmp(command, "Get_fail_reboot_log")) {
		Get_fail_reboot_log();
		return 0;
	}
	else if (!strcmp(command, "Get_fail_dev_log")) {
		Get_fail_dev_log();
		return 0;
	}
#ifdef RTCONFIG_RALINK
#if !defined(RTN14U) && !defined(RTAC52U) && !defined(RTAC51U) && !defined(RTN11P) && !defined(RTN54U) && !defined(RTAC1200HP) && !defined(RTN56UB1) && !defined(RTAC54U)
	else if (!strcmp(command, "Ra_FWRITE")) {
		return FWRITE(value, value2);
	}
	else if (!strcmp(command, "Ra_Asuscfe_2G")) {
		return asuscfe(value, WIF_2G);
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Ra_Asuscfe_5G")) {
		return asuscfe(value, WIF_5G);
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Set_SwitchPort_LEDs")) {
		if(Set_SwitchPort_LEDs(value, value2) < 0)
		{
			puts("ATE_ERROR");
			return EINVAL;
		}
		return 0;
	}
#endif
#endif
#ifdef RTCONFIG_WIRELESS_SWITCH
	else if (!strcmp(command, "Get_WifiSwStatus")) {
		puts(nvram_safe_get("btn_wifi_sw"));
		return 0;
	}
#endif

#ifdef RTCONFIG_WIFI_TOG_BTN
	else if (!strcmp(command, "Get_WifiButtonStatus")) {
		puts(nvram_safe_get("btn_wifi_toggle"));
		return 0;
	}
#endif
#ifdef RTCONFIG_TURBO
	else if (!strcmp(command, "Get_Turbo")) {
		puts(nvram_safe_get("btn_turbo"));
		return 0;
	}
#endif
#ifdef RTCONFIG_LED_BTN
	else if (!strcmp(command, "Get_LedButtonStatus")) {
		puts(nvram_safe_get("btn_led"));
		return 0;
	}
#endif
#ifdef RTCONFIG_QTN
	else if (!strcmp(command, "Enable_Qtn_TelnetSrv")) {
		enable_qtn_telnetsrv(1);
		puts("1");
		return 0;
	}
	else if (!strcmp(command, "Disable_Qtn_TelnetSrv")) {
		enable_qtn_telnetsrv(0);
		puts("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Qtn_TelnetSrv_Status")) {
		getstatus_qtn_telnetsrv();
		return 0;
	}
	else if (!strcmp(command, "Del_Qtn_Cal_Files")) {
		del_qtn_cal_files();
		puts("1");
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Get_WiFiStatus_2G")) {
		if(!getWiFiStatus("2G"))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
	}
	else if (!strcmp(command, "Get_WiFiStatus_5G")) {
		if(!getWiFiStatus("5G"))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
	}
#else
	else if (!strcmp(command, "Get_WiFiStatus_2G")) {
		if(get_radio(0, 0))
			puts("1");
		else
			puts("0");
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_WiFiStatus_5G")) {
		if(get_radio(1, 0))
			puts("1");
		else
			puts("0");
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Set_WiFiStatus_2G")) {
		int act = !strcmp(value, "on");

		if(!strcmp(value, "on") && !strcmp(value, "off"))
			puts("ATE_UNSUPPORT");

		set_radio(act, 0, 0);

		if(get_radio(0, 0)){
			if(act)
				puts("success=on");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		} else{
			if(!act)
				puts("success=off");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_WiFiStatus_5G")) {
		int act = !strcmp(value, "on");

		if(!strcmp(value, "on") && !strcmp(value, "off"))
			puts("ATE_UNSUPPORT");

		set_radio(act, 1, 0);

		if(get_radio(1, 0)){
			if(act)
				puts("success=on");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		} else{
			if(!act)
				puts("success=off");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Get_ATEVersion")) {
		puts(nvram_safe_get("Ate_version"));
		return 0;
	}
	else if (!strcmp(command, "Get_XSetting")) {
		puts(nvram_safe_get("x_Setting"));
		return 0;
	}
	else if (!strcmp(command, "Get_WaitTime")) {
		puts(nvram_safe_get("wait_time"));
		return 0;
	}
	else if (!strcmp(command, "Get_ExtendNo")) {
		puts(nvram_safe_get("extendno"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Get_DevFlags")) {
		if( Get_Device_Flags() < 0)
		{
			puts("ATE_ERROR");
			return EINVAL;
		}
		return 0;
	}
#endif
#ifdef RTCONFIG_QCA
/*
	else if (!strcmp(command, "Set_ART2")) {
		// temp solution
		system("killall rstats");
		system("killall udhcpc");
		system("killall wanduck");
		system("killall networkmap");
		system("killall -9 hostapd");
		system("ifconfig ath0 down");
		system("ifconfig ath1 down");
		system("killall -9 hostapd");
		system("brctl delif br0 ath0");
		system("brctl delif br0 ath1");
		system("wlanconfig ath0 destroy");
		system("wlanconfig ath1 destroy");
		system("ifconfig wifi0 down");
		system("ifconfig wifi1 down");
		modprobe_r("umac");
		modprobe_r("ath_dfs");
		modprobe_r("ath_dev");
		modprobe_r("ath_rate_atheros");
		modprobe_r("ath_spectral");
		modprobe_r("ath_hal");
		modprobe_r("adf");
		modprobe_r("asf");
		modprobe("art");
		system("nart.out -port 2390 -console &");
		system("nart.out -port 2391 -console &");
		return 0;
	}
*/
	else if (!strncmp(command, "Get_EEPROM_", 11)) {
		unsigned char buffer[2560];
		unsigned short len;
		int lret;
		char *pt;
		len=sizeof(buffer);
		pt = (char*) command + 11;
		if (!strcmp(pt, "2G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "5G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "CAL_2G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "CAL_5G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else {
			puts("ATE_UNSUPPORT");
			return EINVAL;
		}
		if ( !lret )
			hexdump(&buffer[0], len);
		return 0;
	}
	else if (!strcmp(command, "Get_CalCompare")) {
		unsigned char buffer[2560], buffer2[2560];
		unsigned short len, len2;
		int lret=0, cret=0;
		len=sizeof(buffer);
		len2=sizeof(buffer2);
		lret+=getEEPROM(&buffer[0], &len, "2G");
		lret+=getEEPROM(&buffer2[0], &len2, "CAL_2G");
		if (lret)
			return EINVAL;
		if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) {
			puts("2G EEPROM different!");
			cret++;
		}
		len=sizeof(buffer);
		len2=sizeof(buffer2);
		lret+=getEEPROM(&buffer[0], &len, "5G");
		lret+=getEEPROM(&buffer2[0], &len2, "CAL_5G");
		if (lret)
			return EINVAL;
		if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) {
			puts("5G EEPROM different!");
			cret++;
		}
		if (!cret)
			puts("1");
		else
			puts("0");
		return 0;
	}
#ifdef RTCONFIG_ATEUSB3_FORCE
	else if (!strcmp(command, "Set_ForceUSB3")) {
		if (setForceU3(value) < 0)
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getForceU3();
		return 0;
	}
	else if (!strcmp(command, "Get_ForceUSB3")) {
		getForceU3();
		return 0;
	}
#endif
#endif	/* RTCONFIG_QCA */
#ifdef RT4GAC55U
	else if(!strcmp(command, "Get_GobiSimCard")) {
		char line[128];
		if (!Gobi_SimCardReady(Gobi_SimCard(line, sizeof(line))))
		{
			puts("FAIL");
			return EINVAL;
		}
		puts("PASS");
	}
	else if(!strcmp(command, "Get_GobiIMEI")) {
		char line[128];
		const char *IMEI = Gobi_IMEI(line, sizeof(line));
		if (IMEI == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(IMEI);
	}
	else if(!strcmp(command, "Get_GobiConnectISP")) {
		char line[128];
		const char *ISP = Gobi_ConnectISP(line, sizeof(line));
		if (ISP == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(ISP);
	}
	else if(!strcmp(command, "Get_GobiConnectStatus")) {
		const char *status = Gobi_ConnectStatus_Str(Gobi_ConnectStatus_Int());
		if (status == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(status);
	}
	else if(!strcmp(command, "Get_GobiSignal_Percent")) {
		int percent = Gobi_SignalQuality_Percent(Gobi_SignalQuality_Int());
		if (percent < 0)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%d\n", percent);
	}
	else if(!strcmp(command, "Get_GobiSignal_dbm")) {
		int dbm = Gobi_SignalLevel_Int();
		if (dbm >= 0)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%d dBm\n", dbm);
	}
	else if(!strcmp(command, "Get_GobiVersion")) {
		char line[128];
		if (Gobi_Version(line, sizeof(line)) == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%s\n", line);
	}
#endif	/* RT4GAC55U */
	else
	{
		puts("ATE_UNSUPPORT");
		return EINVAL;
	}

	return 0;
}
Ejemplo n.º 9
0
int main( int argc, char* argv[] )
{
    uint8_t addr[20] = {0};
    uint8_t* paddr = NULL;
    uint16_t port = USE_RANDOM_PORT;
    xmpp_ctx_t *ctx = NULL;
    xmpp_conn_t* conn = NULL;    
    int reg_act = DMC_REGISTER;
    int errornum=0;
    void *ptr;

    pthread_attr_init(&attr1);
    pthread_attr_setstacksize(&attr1, PTHREAD_STACK_MIN * 2);
   	
    if(!setPIN("2345678901"))
    { 	
	fprintf(stderr, "PIN read error\n");
	return 1;
    }	
    else
	printf("\t\tRead PIN : %s\n", getPIN());

    if( argc < 2 )
    {
	exit(-1);
    }
    uint8_t *ifname = (uint8_t *)argv[1];
	
    /*Get Ip address on defined interface and initialize coap on it with random port number
     * this port number will be used as a source port in all coap communications*/
    if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
                sizeof(addr)) == ERR_SUCCESS)
    {
        OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
        paddr = addr;
    }

    /* Initialize OCStack*/
    if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) {
        OC_LOG(ERROR, TAG, "OCStack init error");
        return 0;
    }

    time(&last_discovery_time);
    InitDiscovery();
//    conn = XMPP_Init( xmpp_un , xmpp_pw ,  xmpp_server, &ctx);
       
    // Break from loop with Ctrl+C
    OC_LOG(INFO, TAG, "Entering occlient main loop...");

    signal(SIGINT, handleSigInt);

    while (!gQuitFlag) 
	{	
		
		if( cmd_head != NULL )
		{
			switch( cmd_head->command )
			{
				case COMMAND_DISCOVERY:
					InitDiscovery();
					break;
				case COMMAND_GET:
					InitGetRequest(cmd_head);
					break;
				case COMMAND_PUT:
					InitPutRequest(cmd_head);
					break;
				case COMMAND_POST:
                                        InitPutRequest(cmd_head);
                                        break;
				case COMMAND_OBSERVE:
					break;
				default:
					break;
			}
		
			struct cmd *cmd_temp = cmd_head;
			cmd_head = cmd_head->next;
			free(cmd_temp);
		}
		else
		{
			//do discovery every 10 seconds
			time_t now;
			time(&now);
			if( now - last_discovery_time > DMC_INTERVAL )
			{
				struct dmc_result *res = dmc_discovery_finish(reg_act);                                			
				if( res->state == REG_SUCCEED )
				{
					reg_act = DMC_UPDATE;
					snprintf( xmpp_un, sizeof(xmpp_un), "%s", res->username );
					snprintf( xmpp_pw, sizeof(xmpp_pw), "%s", res->password );
					snprintf( xmpp_server, sizeof(xmpp_server), "%s", res->server );
					free( res );
					printf("%s\n%s\n%s\n", xmpp_server, xmpp_un, xmpp_pw);
					if(conn==NULL)
 					{ 

                                            conn = XMPP_Init( \
					    xmpp_un , xmpp_pw,
                                            xmpp_server, &ctx);
         
                                            if(ctx !=NULL)
                                                pthread_create(&pid1, \
				&attr1, (void*)xmpp_run, (void*)ctx );
                                            else 
						printf("ctx null\n");

					}
				}
				else
					free(res);	

				OC_LOG_V( INFO, TAG, "DM client returns state %s", get_dmcresult_char(res->state) );
				InitDiscovery();
				time(&last_discovery_time);
			}
		}

        if (OCProcess() != OC_STACK_OK) 
		{
            OC_LOG(ERROR, TAG, "OCStack process error");
            return 0;
        }

        usleep(200*1000);
    }
    
    printf("Quit\n");	
     
    OC_LOG(INFO, TAG, "Exiting occlient main loop...");
    
    if (OCStop() != OC_STACK_OK) {
        OC_LOG_V(ERROR, TAG, "OCStack stop error");
    }

    xmpp_stop(ctx);
    sleep(1);
    XMPP_Close(ctx, conn);
   

    if ((errornum = pthread_cancel(pid1)) != 0)
      	OC_LOG_V(INFO, TAG, "pthread_cancel: %s", strerror(errornum));
    if ((errornum = pthread_join(pid1, &ptr)) != 0)
	OC_LOG_V(INFO, TAG, "pthread_join: %s", strerror(errornum));


    printf("Done\n");
    return 0;
}