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.

RTOS/TDA2EX17EVM: Retrieve IPv6 address

Part Number: TDA2EX17EVM

Tool/software: TI-RTOS

Hello,

One of our customers is trying to use NDK with IPv4 and IPv6. Below are some queries/douts in using same.

1. How is IPv6 address enabled? If both v4 and v6 are enabled, does device gets two addresses each for v4 and v6?

Is enabling through "Global.IPv6 = true" enough? This post says some extra configuration is done for IPv6 examples, what is that configuration?

2. How to retrieve IPv6 address during runtime at use case level? For IPv4, we are using NtIfIdx2Ip function, is there similar function for IPv6?

  • Hello Prasad,

    To enable IPv6 it must be enabled on the cgf as you stated and the code also has to be compiled with _INCLUDE_IPv6_CODE defined.

    Which version of the NDK are you using?

    BR,
    Gerardo
  • Hello Gerardo,

    Thanks for your reply. I am using ndk_2_24_02_31.
    How can I get IPv6 address assigned and retrieved?
  • Hi Prasad,

    In addition to what I stated above you'll also need to call IPv6InterfaceInit() and give it Duplicate Address Detection callback, this will be called when your address is bound so you can use that same callback to store your IP address. This can be found in the tcpEchoIPv6 example included on TI_RTOS, I have attached the file from that example that shows this.

    Thanks,
    Gerardo

    tcpEchoHooksIPv6.c
    /*
     * Copyright (c) 2014-2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *    ======== tcpEchoHooks.c ========
     *    Contains non-BSD sockets code: NDK Hooks and IPv6 set up code.
     */
    
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    /* NDK Header files */
    #include <netmain.h>
    #include <stkmain.h>
    
    #define TCPPORT 1000
    
    #define TCPHANDLERSTACK 1024
    
    /* Prototypes */
    Void tcpHandler(UArg arg0, UArg arg1);
    
    /*
     *  ======== IPv6DADStatus ========
     *  IPv6 initialization callback function
     */
    static void IPv6DADStatus(IP6N Address, unsigned short dev_index,
            unsigned char Status)
    {
        char strIPAddress[40];
    
        /* Convert the IP Address to String Format. */
        inet_ntop(AF_INET6, &Address, strIPAddress, 40);
    
        /* Print the status of the address. */
        System_printf("Address: %s on device %d is %s\n", strIPAddress, dev_index,
                (Status == 1) ? "UNIQUE" : "DUPLICATE");
    
        System_flush();
    
        return;
    }
    
    /*
     *  ======== netOpenHook ========
     *  NDK network open hook used to initialize IPv6
     */
    void netOpenHook()
    {
        Task_Handle taskHandle;
        Task_Params taskParams;
        Error_Block eb;
        int status;
        int dev_index = 1;
    
        /* Make sure Error_Block is initialized */
        Error_init(&eb);
    
        status = IPv6InterfaceInit(dev_index, IPv6DADStatus);
        if (status < 0) {
            System_printf("Error %d: failed to add IPv6 interface\n", status);
        }
    
        /*
         *  Create the Task that farms out incoming TCP connections.
         *  arg0 will be the port that this task listens to. arg1 is the family,
         *  set for IPv6 in this example.
         */
        Task_Params_init(&taskParams);
        taskParams.stackSize = TCPHANDLERSTACK;
        taskParams.priority = 1;
        taskParams.arg0 = TCPPORT;
        taskParams.arg1 = AF_INET6;
        taskHandle = Task_create((Task_FuncPtr)tcpHandler, &taskParams, &eb);
        if (taskHandle == NULL) {
            System_printf("Error: Failed to create tcpHandler Task\n");
        }
    
        System_flush();
    }
    
    /*
     *  ======== netCloseHook ========
     *  NDK network close hook used to de-initialize IPv6
     */
    void netCloseHook()
    {
        int status = 0;
        int dev_index = 1;
    
        /* Enter the kernel Mode. */
        llEnter ();
        status = IPv6InterfaceDeInit(dev_index);
        llExit ();
    
        /* Were we able to deinitialize the stack? */
        if (status < 0) {
            System_printf(
                    "Error: Unable to de-initialize the IPv6 stack on device %d\n",
                    dev_index);
        }
        else {
            System_printf("IPv6 stack has been deinitialized on %d\n", dev_index);
        }
    
        System_flush();
    }
    

  • Hello Gerardo,

    Currently, I am using below APIs to retrieve IPv4 address.  Are there equivalent for IPv6? how can i confirm the DHCP client was able to acquire address from IPv6 DHCP server and what is that address? is there any example to show IPv6 DHCP?

    NtIfIdx2Ip(NET_IF_IDX, &ipAddr);

    NtIPN2Str(ipAddr, ipAddrStr);

  • Hello Gerardo,

    Just to add, would really appreciate ready example or detailed steps as this is blocking issue for customer and fact that we wouldn't be able to take help from you till next day due to differnt timezones.
    Thanks, appreciate your help.
  • Prasad,

    Prasad Jondhale said:
    Currently, I am using below APIs to retrieve IPv4 address.  Are there equivalent for IPv6?

    No, that API is missing for IPv6. The following Jira was filed for this:

        NDK-88 need IPv6 API to get address, given the interface number

    Prasad Jondhale said:
    how can i confirm the DHCP client was able to acquire address from IPv6 DHCP server and what is that address? is there any example to show IPv6 DHCP?

    DHCP is not supported for IPv6 in the NDK. The DHCP client is for IPv4 only.

    When you enable IPv6, you will get a link local address by default (starts with "FE80::")

    ----

    Can you try the following to enable IPv6 in your app? I've also attached an updated copy of the file Gerardo attached, in which I stripped out stuff you don't need:

    1. In the *.cfg file, add the following line:
      1. Global.IPv6 = true;
      2. Global.networkOpenHook = "&netOpenHook";
        Global.networkCloseHook = '&netCloseHook';
    2. add the following define to the compiler options:
      1. -D _INCLUDE_IPv6_CODE
    3. rebuild the app

    You should see the IPv6 address print out.

    Also, you can open wireshark and set the filter to "ipv6".

    If you're not seeing the IP address, please verify with b/p's that you are hitting:

    a. netOpenHook()

    b. IPv6DADStatus()

    Steve

  • Hello Steve,

    I think attachment is missing. Can you please share again?
  • tcpEchoHooksIPv6_minimized.c
    /*
     * Copyright (c) 2014-2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *    ======== tcpEchoHooks.c ========
     *    Contains non-BSD sockets code: NDK Hooks and IPv6 set up code.
     */
    
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* NDK Header files */
    #include <netmain.h>
    #include <stkmain.h>
    
    /*
     *  ======== IPv6DADStatus ========
     *  IPv6 initialization callback function
     */
    static void IPv6DADStatus(IP6N Address, unsigned short dev_index,
            unsigned char Status)
    {
        char strIPAddress[40];
    
        /* Convert the IP Address to String Format. */
        inet_ntop(AF_INET6, &Address, strIPAddress, 40);
    
        /* Print the status of the address. */
        System_printf("Address: %s on device %d is %s\n", strIPAddress, dev_index,
                (Status == 1) ? "UNIQUE" : "DUPLICATE");
    
        System_flush();
    
        return;
    }
    
    /*
     *  ======== netOpenHook ========
     *  NDK network open hook used to initialize IPv6
     */
    void netOpenHook()
    {
        int status;
        int dev_index = 1;
    
        /* Make sure Error_Block is initialized */
        Error_init(&eb);
    
        status = IPv6InterfaceInit(dev_index, IPv6DADStatus);
        if (status < 0) {
            System_printf("Error %d: failed to add IPv6 interface\n", status);
        }
        
        System_flush();
    }
    
    /*
     *  ======== netCloseHook ========
     *  NDK network close hook used to de-initialize IPv6
     */
    void netCloseHook()
    {
        int status = 0;
        int dev_index = 1;
    
        /* Enter the kernel Mode. */
        llEnter ();
        status = IPv6InterfaceDeInit(dev_index);
        llExit ();
    
        /* Were we able to deinitialize the stack? */
        if (status < 0) {
            System_printf(
                    "Error: Unable to de-initialize the IPv6 stack on device %d\n",
                    dev_index);
        }
        else {
            System_printf("IPv6 stack has been deinitialized on %d\n", dev_index);
        }
    
        System_flush();
    }
    

  • Hello Steve,

    Good news! With changes suggested by you, I am able to get IPv6 address and ping using it!!

    Few of the doubts
    1. How is IPv6 link local address generated? Is this fixed from configuration? If needs to be changed how it can be done?
    2. I see DHCP for IPv4 and static IPv6. Hope that is correct and both needn't be always static.
    3. We are calling deinit function in the netclose hook. Isn't it called from NDK stack? Is similar call needs to be done for IPv4?
    /* Enter the kernel Mode. */
    llEnter ();
    status = IPv6InterfaceDeInit(dev_index);
    llExit ();
    4. Can you please share code for tcpHandler? I think i will keep this for testing IPv6 TCP traffic.

    Thanks a lot for detailed answer. Appreaciate all your help!
  • Great new!

    Prasad Jondhale said:
    1. How is IPv6 link local address generated? Is this fixed from configuration? If needs to be changed how it can be done?

    The link local address is generated automatically from the MAC address. All IPv6 interfaces *must* have this (it is an IPv6 requirement) and it must be assigned automatically, which the NDK does for you. Note that this address is not routable.

    For more info, see the wikipedia page, under IPv6.

    Prasad Jondhale said:
    2. I see DHCP for IPv4 and static IPv6. Hope that is correct and both needn't be always static

    See above answer.

    Prasad Jondhale said:
    3. We are calling deinit function in the netclose hook. Isn't it called from NDK stack? Is similar call needs to be done for IPv4?

    The user must call the IPv6 init and deinit APIs, this is not necessary for IPv4. IPv6 was added many years after the NDK was first written, and was designed to be enabled at run time like this.

    Prasad Jondhale said:
    4. Can you please share code for tcpHandler? I think i will keep this for testing IPv6 TCP traffic.

    You can download this from resource explorer in CCS:

    Steve

  • Hello Everyone,

    Has anybody tried this in VSDK , i added changes suggested by Steven , when i connect CCS i could see fe80::c6f3:12ff:feb5:1ba2 but when i ping i can not see the response back. 

    Basically once IPV6 address is assigned , i want to send some UDP packets to another IPV6 address over socket.

    Thanks for any suggestions.

  • Hello Everyone,

    Is it possible to set specific IPv6 address to TDA i.e. I want to set fd53:7cb8:383:2::1:50 address.

    Is there possibility of setting static IPv6 address to TDA ?

    Thanks,

    Kapil Mehta

  • Can you please attach your *.cfg file?

    Thanks,

    Steve

  • Hello Steven ,

    Which cfg file are you talking about ?

    To update the current status , now i am able to assign local link address and i can ping it as well. I have already opened another thread for assigning specific IPv6 address.

    e2e.ti.com/.../2496140

    Thanks for your help.
  • The .cfg file that is used in the project.
  • Hello Todd,

    I am using Vision SDK 3.1
    Do you want network_config.cfg file?

    Thanks ,
    Kapil Mehta
  • Kapil,

    Yes, that's probably the one. Can you please attach that?

    Steve
  • Yes, can you please attach network_config.cfg?

    This will help Dalton to help you in your other thread you made.

  • Hi Steven,

    Here you have NDK_Config.cfg file attached.