Home/Support/Support Forum/dhcp disable
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

dhcp disable

0 votes
Code:
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
asked Sep 17, 2013 in NET+OS by gavello New to the Community (16 points)

Please log in or register to answer this question.

2 Answers

+1 vote
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tx_api.h>
#include <http_awsapi.h>
#include <sysAccess.h>
#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.\n");
// first lets update the ip address of this puppy
printf("Updating the ip address of this puppy\n");

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

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

// get static info
iamStatus = customizeIamGetStaticConfig("eth0", &myIamStaticParams);
if(iamStatus != BP_SUCCESS)
{
printf("get function failed\n");
}
// 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\n");
}

// let the system settle
tx_thread_sleep(250);

printf("setting to static\n");

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

// disable DHCP
theIamStatus = naIamDisable("eth0", myMethod);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
printf("Disable function failed\n");
}
else
{
printf("disable was successful\n");
}

// enable static
theIamStatus = naIamEnable("eth0", NA_IAM_METHOD_STATIC);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
printf("enable function failed\n");
}
else
{
printf("Enable was successful\n");
}

// let system settle
tx_thread_sleep(1000);


// ok, now lets go back to DHCP

printf("Putting DHCP address back\n");

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

// Enable DHCP
myIamDhcpParams.isEnabled = TRUE;
// Write config back to NVRAM
iamStatus = customizeIamSetDhcpConfig("eth0", &myIamDhcpParams);
if(iamStatus != BP_SUCCESS)
{
printf("set function failed\n");
}
// get static info
iamStatus = customizeIamGetStaticConfig("eth0", &myIamStaticParams);
if(iamStatus != BP_SUCCESS)
{
printf("get function failed\n");
}

// 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\n");
}

// let system settle
tx_thread_sleep(250);


printf("setting to DHCP\n");
// what method did we use?
theIamStatus = naIamGetCurrentMethod("eth0", &myMethod);
printf("current method is %d\n", myMethod);

// disable static
theIamStatus = naIamDisable("eth0", NA_IAM_METHOD_STATIC);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
printf("Disable function failed\n");
}
else
{
printf("disable was successful\n");
}


// enable DHCP
theIamStatus = naIamEnable("eth0", NA_IAM_METHOD_DHCP);
if(theIamStatus != NA_IAM_STATUS_SUCCESS)
{
printf("enable function failed\n");
}
else
{
printf("Enable was successful\n");
}


// 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].\n", result);
return;
}
}
answered Sep 17, 2013 by dakotas_dad Veteran of the Digi Community (694 points)
Thanks for the support!
+1 vote
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
answered Sep 17, 2013 by dakotas_dad Veteran of the Digi Community (694 points)
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?
...