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.

NDK: remove lease when link is lost?



Hi,

I have a problem in maintaining an older project. The devices are based on DM642, built with CCS 3.0 and NDK 1.71. Yes I know this versions are very old, but the project is not under development, only maintainance.

Here is the problem: On startup the device is configured do be a DHCP client usingthis code, similar to the example in the manual:

    bzero( &dhcpc, sizeof(dhcpc) );
    dhcpc.cisargs.Mode   = CIS_FLG_IFIDXVALID;
    dhcpc.cisargs.IfIdx  = 1;
    dhcpc.cisargs.pCbSrv = NDK_serviceReport;
    status = CfgAddEntry(NDK_Data.hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
                         sizeof(dhcpc), (UINT8 *) &dhcpc, 0);
    assert(status == 0);

Everything is fine after booting, the DHCP server respond and the devices get a lease. Now we disconnect the network cable from the device, a "link lost" event is found and reported. Now we expect that the lease is removed but it is not! If the device is reconnected then it uses its old IP address, but we recommend to get a new lease, like a Windows PC does.

How can we force the DHCP client to remove its lease on lost network connections?

Thanx,
Andi

  • I think this may be a bug in the NDK.  According to the docs, all ITEM values for CFGTAG_SYSINFO are reserved for DHCP options.  I believe that you should be able to do this by doing something like:

        int leaseTime = 123456;
        CfgAddEntry( hCfg,       CFGTAG_SYSINFO, 51, 0, 4,  (UINT8 *)(&leaseTime),       0 );

    However, I tried this and didn't see it showing up in wireshark.

    But, if you edit the NDK DHCP source file dhcpbild.c, in the function dhcpBuildHeader() to add the following code, it should work:

        /* add least time request here */
            int leaseTime = 12345;
           *pv++ = DHCPOPT_IP_ADDRESS_LEASE_TIME;
           *pv++ = 4;
           bcopy( &pLease->IPServer, (void *)(&leaseTime), 4 );
           pv += 4;

     

    Since you're on a much older release, I'm not sure that you have the source code.  If not, I've attached it, but I'm not sure what the differences between the attached version and the version of the files that shipped in NDK 1.71 may be ...

     

    You can try adding the attached to your project and rebuild and see if that works for you.

    Newer versions of the NDK ship with sources, so moving to the latest is another option.

    Steve7230.dhcpbild.zip

  • Thank you Steve for investigating. I will try out with source code you posted here. Best case would be if I could get the file from original version 1.71, which was closed source in the past. Anyway, I try this one.

    Kind regards, Andi

  • Steve,

    a quick test shows that I cannot compile this file. Some internal definitions are required, like DHCPLEASE. Is it possible to get all files I will need?

    Thanx, Andi

  • whoops ... you need the header file of course!

    4061.dhcp.zip

    Also, you can get the latest NDK release here.  It ships with all of the sources:

    http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/ndk/index.html

    Steve

  • Hi Steve,

    I tried it with the header file, it compiles now but the code does not work. Wireshark shows now "unknown BOOTP" packages instead of DHCP discover. I guess that is because the source code from NDK 2.20 is not compatible with the rest of NDK 1.71?

    Since I'm not familiar with the NDK internal, I don't understand your code fix. What is the "12345" value for lease time, a hard coded example? Can you please explain your patch?

    Thanx, Andi

  • Andi,

    The NDK 1.71 release is very old, and since then the NDK itself has changed ownership between different sites within TI.  I'm not sure that we have the source code here, but I can look into that.

    It's very possible that the file I gave you (from a much newer NDK) isn't compatible with 1.71, but I figured it was worth a shot.  If you like, you can try to omit the changes that I added:

       /* add least time request here */
         //   int leaseTime = 12345;
         //  *pv++ = DHCPOPT_IP_ADDRESS_LEASE_TIME;
         //  *pv++ = 4;
         //  bcopy( &pLease->IPServer, (void *)(&leaseTime), 4 );
         //  pv += 4;

    and rebuilding.  If it still doesn't work, then it's probably safe to say that it's incompatible.

    regarding the "12345" - this code was meant to be 'pseudo code' but I wasn't clear enough on that, sorry about that!

    I meant for you to replace the "12345" with whatever timeout value you would like.

    Steve

  • Steve,

    sorry for the delay. I tried the source code without the new code lines, as you suggested. And it still does not work. Therefor, the source code is not compatible with NDK 1.71 :( But thanks for your help, maybe I can contact someone from the NDK team.

    Kind regards,
    Andi