/*****************************************************************************
 * FUNCTION: setDHCPState
 *
 * RETURNS: None
 *
 * PARAMS:  enable -- a boolean indicating whether to enable DHCP or not
 *
 * NOTES:   Enable or disable DHCP operation
 *****************************************************************************/
static void setDHCPState(bool enable)
{
    if ( enable )
    {
        AppConfig.Flags.bIsDHCPEnabled = true;
        DHCPEnable(0);
    }
    else
    {
        AppConfig.Flags.bIsDHCPEnabled = false;
        DHCPDisable(0);
    }
}
示例#2
0
/*****************************************************************************
 * FUNCTION: setDHCPState
 *
 * RETURNS: None
 *
 * PARAMS:  enable -- a boolean indicating whether to enable DHCP or not
 *
 * NOTES:   Enable or disable DHCP operation
 *****************************************************************************/
static void setDHCPState(BOOL enable)
{
    if ( enable )
    {
        AppConfig.Flags.bIsDHCPEnabled = TRUE;
        DHCPEnable(0);
    }
    else
    {
        AppConfig.Flags.bIsDHCPEnabled = FALSE;
        DHCPDisable(0);
    }
}
示例#3
0
void setIp() {
	IP_ADDR ip, netmask, gateway, dns1, dns2;

	if (!LMEnterHash()) {
		return;
	}
	if (!LMFindHashString("ip")) {
		return;
	}
	ip.Val = LMTakeInt();
	if (ip.Val == 0xFFFFFFFF) {
		AppConfig.Flags.bIsDHCPEnabled = TRUE;
		AppConfig.Flags.bInConfigMode = TRUE;
		DHCPEnable(0);
		return;
	}

	if (!LMFindHashString("netmask")) {
		return;
	}
	netmask.Val = LMTakeInt();

	if (!LMFindHashString("gateway")) {
		return;
	}
	gateway.Val = LMTakeInt();

	if (!LMFindHashString("dns1")) {
		return;
	}
	dns1.Val = LMTakeInt();

	if (!LMFindHashString("dns2")) {
		return;
	}
	dns2.Val = LMTakeInt();

	AppConfig.Flags.bIsDHCPEnabled = FALSE;
	AppConfig.MyIPAddr.Val = ip.Val;
	AppConfig.MyMask.Val = netmask.Val;
	AppConfig.MyGateway.Val = gateway.Val;
	AppConfig.PrimaryDNSServer.Val = dns1.Val;
	AppConfig.SecondaryDNSServer.Val = dns2.Val;
}
/*****************************************************************************
 * FUNCTION: setDHCPState
 *
 * RETURNS: None
 *
 * PARAMS:  enable -- a boolean indicating whether to enable DHCP or not
 *
 * NOTES:   Enable or disable DHCP operation
 *****************************************************************************/
static void setDHCPState(bool enable)
{
    NET_CONFIG *p_netConfig;
    TCPIP_NET_HANDLE handle;
    
    handle = TCPIP_STACK_NetHandle("MRF24W");
    
    
    
    p_netConfig = GetNetworkConfig();    
    
    if ( enable )
    {
        p_netConfig->Flags.bIsDHCPEnabled = true;
        DHCPEnable(handle);
    }
    else
    {
        p_netConfig->Flags.bIsDHCPEnabled = false;
        DHCPDisable(handle, false);
    }
}
/**************************************************************************
 * Function: BringUpNetwork
 * Functionality: start the network.
 * @IN :zDB: the database handle
IPConfig : the struct contain the ip address needed by setup network
NETWORK: render start wired or wifi network.
 * @OUT:   0 OK else error
 * Used description:
 start the wifi or wired network
 * Date: 20080117
 * Changed history:
 * Date          Who             Reason
 * 20080117     sandy           First  creation
 ***************************************************************************/
int  BringUpNetwork(PZDB_HANDLE zDB , PIPConfig IPConfig, NETWORK_TYPE NETWORK, PWifiConfig WifiParam)
{
	int ret = -1;
	char exec[512] = {0};
	//WifiConfig WifiParam;

	if(NETWORK == WIRE_NETWORK)
	{
		if(isRunning(WIFIDEVICE) == RUNNING)
		{
			if(downNetwork(WIFIDEVICE))
			{
				fprintf(stderr,"down the network wired error\n");
				return ret;
			}
			DHCPDisable(1);
		}
		if(isRunning(WIREDEVICE) == DOWN)
		{
			if(upNetwork(WIREDEVICE))
			{
				fprintf(stderr,"up the network  wired error\n");
				return ret;
			}              
		}       
		if(isRunning(WIREDEVICE) == RUNNING){
			if(strcmp(IPConfig->DHCPEnable, "1") == 0){
				ret = DHCPEnable(0,"");
				UpdateItem(zDB,"DHCPStatus","1");
			}
			else if(strcmp(IPConfig->DHCPEnable, "0") == 0){
				ret =  UpStaticNet(IPConfig, 0);
				UpdateItem(zDB,"DHCPStatus","0");
			}
		}
		updateDB(zDB, "WiEnable", "0");
		return ret;
	}
	else if(NETWORK == WIFI_NETWORK)
	{
		if(isRunning(WIREDEVICE) == RUNNING)
		{
			if(downNetwork(WIREDEVICE))
			{
				fprintf(stderr,"down the network mwl0 error\n");
				return ret;
			}
			DHCPDisable(0); 
		}
		/***********************************************************
		  if the wifi is down excute singal join or autojoin
		  else if wifi is up, just excute singal join
		 ***********************************************************/
		if(isRunning(WIFIDEVICE) == DOWN)
		{
			if(upNetwork(WIFIDEVICE))
			{
				fprintf(stderr,"Up the network mwl0 error\n");
				return ret;
			}

			if(isRunning(WIFIDEVICE) == RUNNING)	
			{
				//first signal join, if failed excute the auto join
				ret = StartWifiWithConfig(zDB, WifiParam);

				if(ret)
				{
					sprintf(exec,"%s/AutoJoin >/dev/null 2>&1 &",COMMAND_PATH);
					ret = OpenPipe(exec);
				}
				if(strcmp(IPConfig->DHCPEnable, "1") == 0){
					ret = DHCPEnable(1,"");
					UpdateItem(zDB,"DHCPStatus","1");
				}
				else if( strcmp(IPConfig->DHCPEnable, "0") == 0){
					ret = UpStaticNet(IPConfig, 1);
					UpdateItem(zDB,"DHCPStatus","0");
				}
			}
		}
		else if(isRunning(WIFIDEVICE) == RUNNING)	
		{
			//just excute signal join.
			ret = StartWifiWithConfig(zDB, WifiParam);

			if(strcmp(IPConfig->DHCPEnable, "1") == 0){
				ret = DHCPEnable(1,"");
				UpdateItem(zDB,"DHCPStatus","1");
			}
			else if( strcmp(IPConfig->DHCPEnable, "0") == 0){
				ret = UpStaticNet(IPConfig, 1);
				UpdateItem(zDB,"DHCPStatus","0");
			}
		}
		updateDB(zDB, "WireEnable", "0");       
		return ret;
	}
	else {
		fprintf(stderr, "unknown network type\n");
		return ret;
	}              

	return 0;
}