This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DHCP client

Other Parts Discussed in Thread: SYSBIOS

Equipment:

            ICEv2 board,

            CCSv6 vs 6.0.1.00040,

            TI XDS100v2 USB Emulator,

            Windows7,

                  am335x_sysbios_ind_sdk_1.1.0.6

            NDK 2.24.1.18

            NDK's NSP 1.10.2.09

            SYSBIOS 6.40.3.39

            Compiler TI v5.1.10

            Project: 'standalone Ethernet switch' derived from the EthernetIp example of the SDK

 

 

Hello,

so far I could send TCP/IP data using a static IP address as shown in the EchoTcp() example taken from the manual.

Now the DHCP Client Module has been added using XGCONFIG. The hope was that the IP address would be provided automatically. But somehow not even the Network_IP_Address _Hook() has been reached,

 This is what the console view shows:

[CortxA8]

Stack_thread_beginn_hook() reached

Stack_thread_initialization_hook() reached

Service Status: DHCPC    : Enabled  :          : 000

Status_report_hook() reached

Service Status: DHCPC    : Disabled :          : 000

Status_report_hook() reached

Network_open_hook() reached

For some reason the DHCP client has been disabled. I should mention that the ICEv2 board is plugged to a router and with a static IP address it was ok.

 My guess is that something went wrong in Void ti_ndk_config_ip_init(HANDLE hCfg).

Does anybody know what the reason might be and how to correct it, i.e. how to get a IP address automatically?

 

Supposing this problem could be solved, another question arises: How would I tell the system to use a certain default IP address if it is connected directly to a PC (no router, no DHCP server)? It seems to me that with XGCONFIG one can only choose the static or the automatic version.

Thank you.

Regards,

Martin H.

  • After further tests(now having 'Use physical device index' disabled) , the text in the console view is a bit shorter:

    [CortxA8] Stack_thread_beginn_hook() reached
    Stack_thread_initialization_hook() reached
    Service Status: DHCPC    : Failed   :          : 000
    Status_report_hook() reached
    Network_open_hook() reached

    Martin. H.

  • Martin,

                 Have you commented out the line Global.stackThreadUser = "&NDKACD_stackThread"; from cfg file. Then only any changes in XGCONFIG will take into affect.

    I tried your setup at my side and was able to assign IP address from DHCP server. All i did was set the AutoIP = True.

    Regards,

    Prajith

  • Even though I have unchecked the DHCP Client Module in XGCONF and cleaned and rebuilt the project, I still get the message

    Service Status: DHCPC    : Enabled  :          : 000

    Service Status: DHCPC    : Disabled :          : 000

    and the Network_IP_Address _Hook() is not reached.

    Looks as if unchecking that module has been ignored (!).

     

    Regards,

    Martin H.

  • Hi Prajith,

     

    thanks for replying.

    Yes, this line was commented out. Doing that is part of the procedure to create Stand alone switch application from Ethernet/IP application:

    Compilation WITH this line leads to the error message that NDKAC_stackThread is an unresolved symbol.

     

    Do you mean

        Ip.autoIp = true;

    in the .cfg file? It was set to true. Could you point me to the source that has the explanation for that parameter? It does not seem to be in Ip.html.

    As a next step I went back to a previous backup of the project, one that had been stored before the DHCP Client Module was used.

    I set Ip.autoIp = true; in the .cfg file without having activated the DHCP Client Module.

    The description of IP (ti/ndk_2_24_01_18/docs/cdoc/ti/ndk/config/Ip.html#address) points out that a default IP address of null “signifies that this Ip instance (on this interface) will run as a DHCP Client, and will obtain the IP address automatically from a DHCP Server on the network”.

    So I commented out mask and gateway IP address in the .cfg file.

    And it works, i.e. an IP address is assigned and data can be sent periodically.

    So the intuition is that one does not necessarily need to activate the DHCP Client Module, provided one does not need to set flags or the domain name!

    That brings me to the second question mentioned earlier:

    Where can I set a default IP address, if there is no DHCP server in the network?

    In the Stack_thread_initialization_hook?

    Thank you.

    Regards,

    Martin H.

  • Martin,

           I hope your issue is resolved. 

    Martin H. said:
    Where can I set a default IP address, if there is no DHCP server in the network?

    What exactly do you mean by "default IP address"?  Do you want to change the IP address during run time?

    Regards,

    Prajith

  • Hi Prajith,

    yes, the main issue is resolved. Thank you very much.

    But supposing the ICEv2 board is just connected to a single pc and there is no DHCP server, how would the board get it's IP address? If I specify one in the .cfg file, it means "Take this IP, not the one a DHCP server might provide". But I would like to cover both cases.

    So I am looking for a place (a hook function most likely) that lets me ask "Was there a DHCP server that provided an IP address?"  And "If not take these network parameters and go on initializing the network.".

    It doesn't seem to be possible neither with the Stack_thread_initialization_hook() nor the "Network_IP_address_hook(). 

    Do you know a way to do it?

    Thanks.

    Regards,

    Martin H.

  • Hi Martin,

    I think the hook you are looking for is "Global.serviceReportHook".

    This is the hook that is called when the "DHCP: Fail" or "DHCP: Fault" happens, that you see in your output.

    You could try defining this hook function and adding some code in it to check for these conditions.

    If these conditions occur, you could update the NDK to add a static IP address.

    For an example of how to add an IP address at run time, please have a look at this thread.  Although it shows adding code to the IP init function, you would do it in your service report hook.

    Steve

  • Hi Steve,

    so I suppose that "Global.serviceReportHook" is what is called  “Status_report_hook” in XGCONF. Is that correct?

    To give priority to DHCP, the .cfg file does not specify any IP address. That means that a variable LocalIPAddr does not exist.

    Trying to use the workaround mentioned in the link, I ended up with CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr) returning 0.

     

    Also, with the ICEv2 board connected to a single PC, there is no “DHCP: Fail”  to be seen in the output. Also "myIPAddrHook()" is not reached.  This is all:

    [CortxA8]

    Stack_thread_beginn_hook() reached

    Stack_thread_initialization_hook() reached

    Service Status: DHCPC    : Enabled  :          : 000

    Status_report_hook() reached

    Network_open_hook() reached

    Service Status: DHCPC    : Enabled  : Running  : 000

    Status_report_hook() reached

     

    With the board getting it’s IP address from the DHCP server, this shows up:

    [CortxA8]

    Stack_thread_beginn_hook() reached

    Stack_thread_initialization_hook() reached

    Service Status: DHCPC    : Enabled  :          : 000

    Status_report_hook() reached

    Network_open_hook() reached

    Service Status: DHCPC    : Enabled  : Running  : 000

    Status_report_hook() reached

     

    Network Added: If-1:192.168.115.96

    myIPAddrHook reached,   Priorität bei IP-Wechsel: 5

    Service Status: DHCPC    : Enabled  : Running  : 017

    Status_report_hook() reached

     How can I figure out that DHCPC failed if the “Status_report_hook” does not report a “FAIL” because it has been called only twice? And where woul I set the new IP address?

    Any idea?

    Regards,

    Martin H.

  • Hi Steve, hi Prajith,

    could you make any progress with the problem we discussed? 

    Regards,

    Martin H.

  • Hi Martin,

    Martin H. said:
    so I suppose that "Global.serviceReportHook" is what is called  “Status_report_hook” in XGCONF. Is that correct?

    correct.


    Martin H. said:

    Also, with the ICEv2 board connected to a single PC, there is no “DHCP: Fail”  to be seen in the output. Also "myIPAddrHook()" is not reached.  This is all:

    [CortxA8]

    Stack_thread_beginn_hook() reached

    Stack_thread_initialization_hook() reached

    Service Status: DHCPC    : Enabled  :          : 000

    Status_report_hook() reached

    Network_open_hook() reached

    Service Status: DHCPC    : Enabled  : Running  : 000

    Status_report_hook() reached

    How long are you waiting?  If the app is running as a DHCP client, it will keep trying to discover a DHCP server for a few minutes.  Eventually, it gives up (after no response) and prints the fault message.  Also, you can run wireshark and see the DHCP discover messages being sent out as further verification.

    Can you try again and let it run for 5 minutes?  You should see the message within 5 minutes.

    Steve

  • Hi Martin try the following:

    In "Network open hook" put the function that will assign the new IP, "newIPAddr".
    After eg in main type the following function:

    void newIPAddr()
    {
        CI_IPNET NA;
        HANDLE      hCfgIpAddr;
        unsigned int x;
    
        System_printf("DHCP OFF \n");
        bzero(&NA, sizeof(NA));
        NA.IPAddr  = inet_addr("192.168.10.10");
        NA.IPMask  = inet_addr("255.255.255.0);
        strcpy(NA.Domain, "titexas.pt");
        NA.NetType = 0;
        // get the current static IP entry
        CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);
        // remove the current static IP entry
        CfgRemoveEntry(0, hCfgIpAddr);
        // add a new static IP entry
        CfgAddEntry(0, CFGTAG_IPNET, 1, 0,
                sizeof(CI_IPNET), (UINT8 *)&NA, 0);
                }
        System_flush();
    }

    I think that is what you are looking for.

    Regards

    Aquino

  • Hi Aquino and Steve,

    sorry for the late reply.

    Yes, I have not been patient enough. After less than 3 minutes the message showed up. newIPAddr() does an excellent job!

    However, 3 minutes can be a long time for a customer to wait for a connection and that might be irritating. Most likely I will build an additional version with a static IP address that only will be used if there is no DHCP server.

    Thanks a lot to all who contributed to solve this issue!

    Kind regards,

    Martin H.

     

     

  • Hi Martin,
    I agree with you.
    I set the "interface" for USB and a setting I do is if I want to enable DHCP or give a static IP.
    The client only have to configure (via USB) a static IP or DHCP then activate the "interface".
    So just wait 3 minutes if the DHCP server does not "reach" ip.
    I do not know if there is any solution to reduce this time.
    It was the best solution I found!

    Regards
    Aquino