dhcp disable


int method;
NaIamStaticParams_t static_params;

customizeIamGetStaticConfig(BP_ETH_INTERFACE, &static_params);

interface->staticParams.isEnabled = TRUE;

//Set IP Address
//Set Gateway
//Set  Subnet Mask
//Set DNS

customizeIamSetStaticConfig(BP_ETH_INTERFACE, &static_params);
naIamGetCurrentMethod(interface, &method);
naIamRelease(interface, method);


But DHCP is still on so after -> IAM:Lost DHCP IPv4 address
I still get -> IAM:Lost DHCP IPv4 address instead of static IPv4 address

Hello

The following is some code I wrote some time ago to do what you are trying to do. You can safely ignore the peripheral code dealing with AWS and concentrate only on the code dealing with switching between DHCP and static and back.

#include
#include
#include
#include
#include
#include
#include “appconf.h”
#include “server.h” /* For username/password */
#include “iam.hh”

/*
*

  • Function: void applicationTcpDown (void)
  • Description:
  •  This routine will be called by the NET+OS root thread once every 
    
  •  clock tick while it is waiting for the TCP/IP stack to come up.  
    
  •  This function can increment a counter everytime it's called to 
    
  •  keep track of how long we've been waiting for the stack to start.
    
  •  If we've been waiting too long, then this function can do something
    
  •  to handle the error.  
    
  •  This function will not be called once the stack has started.
    
  • Parameters:
  •  none
    
  • Return Values:
  •  none
    

*/

void applicationTcpDown (void)

{
static int ticksPassed = 0;

ticksPassed++;

/*

  • Code to handle error condition if the stack doesn’t come up goes here.
    */
    }

/*
*

  • Function: void applicationStart (void)
  • Description:
  •  This routine is responsible for starting the user application.  It should 
    
  •  create any threads or other resources the application needs.
    
  •  ThreadX, the NET+OS device drivers, and the TCP/IP stack will be running
    
  •  when this function is called.
    
  • Parameters:
  •  none
    
  • Return Values:
  •  none
    

*/

void applicationStart (void)
{
HS_SERVER_PARAMETER appParams;
int result;
int iamStatus = 0;
NaIamStaticParams_t myIamStaticParams = {0};
NaIamDhcpParams_t myIamDhcpParams = {0};
NaIamStatus_t theIamStatus = NA_IAM_STATUS_SUCCESS;
int myMethod = 0;

printf ("Start the AWS Web Server Sample Application.

");
// first lets update the ip address of this puppy
printf("Updating the ip address of this puppy
");

// get DHCP config
iamStatus = customizeIamGetDhcpConfig("eth0", &myIamDhcpParams);
if(iamStatus != BP_SUCCESS)
{
    printf("get of DHCP function failed

");
}

// disable DHCP
myIamDhcpParams.isEnabled = FALSE;
// write the config data back to NVRAM
iamStatus = customizeIamSetDhcpConfig("eth0", &myIamDhcpParams);
if(iamStatus != BP_SUCCESS)
{
    printf("set function failed

");
}

// get static info
iamStatus = customizeIamGetStaticConfig("eth0", &myIamStaticParams);
if(iamStatus != BP_SUCCESS)
{
    printf("get function failed

");
}
// now that we have the config info, lets update and enable
myIamStaticParams.ipAddress.addr.ipv4.sin_addr.s_addr = 0xA34217C; // 10.52.33.124
myIamStaticParams.isEnabled = TRUE;
myIamStaticParams.subnetMask = 0xfffff80; //255.255.248.0
myIamStaticParams.gateway.addr.ipv4.sin_addr.s_addr = 0xA342001; //10.52.32.1
// write config info back to NVRAM
iamStatus = customizeIamSetStaticConfig(“eth0”, &myIamStaticParams);
if(iamStatus != BP_SUCCESS)
{
printf("set function failed
");
}

// let the system settle
tx_thread_sleep(250);

printf("setting to static

");

// what method did we use?
theIamStatus = naIamGetCurrentMethod("eth0", &myMethod);
printf("Current method is %d

", myMethod);

// disable DHCP
theIamStatus = naIamDisable("eth0", myMethod);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
    printf("Disable function failed

");
}
else
{
printf("disable was successful
");
}

// enable static
theIamStatus = naIamEnable("eth0", NA_IAM_METHOD_STATIC);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
    printf("enable function failed

");
}
else
{
printf("Enable was successful
");
}

// let system settle
tx_thread_sleep(1000);


// ok, now lets go back to DHCP

printf("Putting DHCP address back

");

// get DHCP config info
iamStatus = customizeIamGetDhcpConfig(“eth0”, &myIamDhcpParams);
if(iamStatus != BP_SUCCESS)
{
printf("get of DHCP function failed
");
}

// Enable DHCP
myIamDhcpParams.isEnabled = TRUE;
// Write config back to NVRAM
iamStatus = customizeIamSetDhcpConfig("eth0", &myIamDhcpParams);
if(iamStatus != BP_SUCCESS)
{
    printf("set function failed

");
}
// get static info
iamStatus = customizeIamGetStaticConfig(“eth0”, &myIamStaticParams);
if(iamStatus != BP_SUCCESS)
{
printf("get function failed
");
}

// now that we have the config info, lets update and enable
// zero out fields so that system knows we are NOT using static
myIamStaticParams.ipAddress.addr.ipv4.sin_addr.s_addr = 0x00000000; // 10.52.33.124
myIamStaticParams.isEnabled = FALSE;
myIamStaticParams.subnetMask = 0x00000000;  //255.255.248.0
myIamStaticParams.gateway.addr.ipv4.sin_addr.s_addr = 0x00000000; //10.52.32.1

// write static config info back to NVRAM
iamStatus = customizeIamSetStaticConfig("eth0", &myIamStaticParams);
if(iamStatus != BP_SUCCESS)
{
    printf("set function failed

");
}

// let system settle
tx_thread_sleep(250);


printf("setting to DHCP

");
// what method did we use?
theIamStatus = naIamGetCurrentMethod(“eth0”, &myMethod);
printf("current method is %d
", myMethod);

// disable static
theIamStatus = naIamDisable("eth0", NA_IAM_METHOD_STATIC);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
    printf("Disable function failed

");
}
else
{
printf("disable was successful
");
}

// enable DHCP
theIamStatus = naIamEnable("eth0", NA_IAM_METHOD_DHCP);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
    printf("enable function failed

");
}
else
{
printf("Enable was successful
");
}

// system will now request a DHCP address


naHSDefaultSetting(&appParams);

appParams.ServerStartDate.tm_mday       = 3;
appParams.ServerStartDate.tm_mon        = 11;
appParams.ServerStartDate.tm_year       = 2006;
appParams.connections                   = 6;
appParams.persistent_timeout            = (60 * 3);
appParams.session_timeout               = (60 * 5);
appParams.http_buffer_size              = 8096;
appParams.Server_thread_sysstack        = 2048;
appParams.Server_thread_usrstack        = 2048;

/*  Insecure account Netsilicon password sysadm can be used anywhere to access HTTP Realm 1 and FTP */
NAsetSysAccess (NASYSACC_ADD, APP_USERNAME, APP_PASSWORD, NASYSACC_LEVEL_HTTP_R1 | NASYSACC_LEVEL_RW, NULL);

/*  Secure account Safe can only be used through the Secure Gateway -- this account's password will never be exposed!   */
NAsetSysAccess (NASYSACC_ADD, "safe", "netsilicon", NASYSACC_LEVEL_HTTP_R1 | NASYSACC_LEVEL_RW, NULL);

result = NAHSStartServer(appParams);
if (result != 0)
{
    printf("root: NAHSStartServer failure[%d].

", result);
return;
}
}

1 Like

http://ftp1.digi.com/support/patches/switch_ip_acquisition.zip

The link above provides a fancier version of the application from the prior link. This application in the zip file is larger than will fit in a posting, thus the .zip file

1 Like

Thanks for the support!

Thanks for the link!
It’s me or finding resources like the one you kindly linked isn’t a strait forward task on support website?