MQX RTCS Initialization procedure. Read the reached DHCP-IP ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX RTCS Initialization procedure. Read the reached DHCP-IP ?

700 Views
klausconzelmann
Contributor I

How can i read the received IP, from the DHCP server?

I will open a communication via Ethernet with:

  RTCS_create(), ENET_initialize(), RTCS_if_add(), RTCS_if_bind_DHCP() an open a socket.

So my system (MQX 4.1.1 with twrk70f120m) is reached a Ping korrect. My ftp-server is running.

After the initialise i will with:

  IPCFG_IP_ADDRESS_DATA ip_data = {0,0,0};

  error = ipcfg_get_ip (ENET_DEVICE_0, &ip_data);

read the received IP. But it always returns FALSE, but no IP. Which function is available for the IP-Read?

---------------------------------

#include "econ9_Device_config.h"

#include <rtcs.h>

#include <ipcfg.h>

#define ENET_DEVICE_0            0        // 1. Enet-Device

_enet_handle  ehandle;                    // (Bind TCP&MSK to Adapter)

unsigned int eth_init(void)

{

    uint32_t        error;

    _rtcs_if_handle ihandle;            // (Bind MAC to Eth-Device)

    uint32_t optlen = 580;

    unsigned char option_array[optlen];

    unsigned char * optptr;

    DHCP_DATA_STRUCT params;

    unsigned char parm_options[3] = {    DHCPOPT_SERVERNAME,    DHCPOPT_FILENAME,    DHCPOPT_FINGER_SRV};

    _enet_address   macadrarray;

                                                                      

     _mem_zero(&params, sizeof(params));

                                                                      

    /* Setup RTCS */

    _RTCSTASK_priority = RTCSTASK;

    error = RTCS_create();

    /* Init ETH Interface */

    _IP_forward = TRUE;

    error = ENET_initialize (ENET_DEVICE_0, econ9_Device_config.ethernet.ENET_MAC_0, 0, &ehandle);

    if (error != RTCS_OK)

    {

        DEBUGPRINTF("eth_init - Error: RTCS initialization failed\n");

        return 1;

    }

    error = RTCS_if_add (ehandle, RTCS_IF_ENET, &ihandle);

    if (error != RTCS_OK)

    {

        DEBUGPRINTF("eth_init - Error: RTCS_if_add failed\n");

        return 3;

    }

  

    /* IP Configuration */

    /* DHCP */

    optptr = option_array;

    DHCP_option_int32(&optptr, &optlen, DHCPOPT_LEASE, 180);

    DHCP_option_variable(&optptr, &optlen, DHCPOPT_PARAMLIST, parm_options, 3);

    error = RTCS_if_bind_DHCP(ihandle, &params, &option_array, optlen);

    if (error)

    {

        DEBUGPRINTF("eth_init - DHCP boot failed, error = %x.\n", error);

        return 5;

    }

    return 0;  

}

Labels (1)
0 Kudos
1 Reply

346 Views
RadekS
NXP Employee
NXP Employee

Hi Klaus,

I suppose that this problem is caused by fact that you used low level layer functions for initialize Ethernet interface (functions with RTCS_if_ prefix) while ipcfg_get_ip() function is high level initialization function.

Unfortunately there isn’t any specific function for read IP at this low layer of initialization code.

IP address is stored in dhcp_header structure. According ipcfg_bind_dhcp_func() function:

DHCP_HEADER_PTR dhcp_ptr = (DHCP_HEADER_PTR)buffer_ptr;

ipcfg_data[device].actual_ip_data.ip = mqx_ntohl (dhcp_ptr->YIADDR);

I would like to recommend use high level ipcfg functions for initialize Ethernet interface.

RTCS_create() followed by ipcfg_init_device() and ipcfg_bind_dhcp() or rather ipcfg_bind_dhcp_wait() function.

Please look at example in ipcfg_bind_dhcp_wait() function description inside RTCS User guide.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------