Hi,
I had issues with this too. This is what I did and it has worked with
out change from lwIP V1.3.2 to current:
typedef struct _NVDHCP
{
uint8_t pbyIpAddress[4];
uint8_t pbyAddressMask[4];
uint8_t pbyGatewayAddress[4];
uint8_t byEnableDHCP;
} NVDHCP,
*PNVDHCP;
/******************************************************************************
* Function Name: ipReconfigure
* Description : Function to re-configure the interface
* Arguments : IN pszInterface - The symbolic link name of the interface
* IN pIpConfig - Pointer to the new configuration
* Return Value : 0 for success or -1 on error
******************************************************************************/
int32_t ipReconfigure(int8_t *pszInterface, PNVDHCP pIpConfig)
{
PRTEIP pEtherC = ipFindNetIf(&gpEtherC, pszInterface);
if (pEtherC)
{
if (pIpConfig->byEnableDHCP == 0U)
{
_Bool bfLinkUp = false;
pEtherC->ipConfig = *pIpConfig;
/* If DHCP was previously on */
if (pEtherC->ipConfig.byEnableDHCP)
{
/* Stop it */
tcpip_callback((void(*)(void*))dhcp_release,
&pEtherC->ipNetIf);
tcpip_callback((void(*)(void*))dhcp_stop,
&pEtherC->ipNetIf);
}
/* Set the fixed address */
memcpy(&pEtherC->ipNetIf.ip_addr.addr,
pEtherC->ipConfig.pbyIpAddress,
sizeof(struct ip_addr));
memcpy(&pEtherC->ipNetIf.netmask.addr,
pEtherC->ipConfig.pbyAddressMask,
sizeof(struct ip_addr));
memcpy(&pEtherC->ipNetIf.gw.addr,
pEtherC->ipConfig.pbyGatewayAddress,
sizeof(struct ip_addr));
/* Check the state of the link */
if ((control(pEtherC->iEtherC, CTL_GET_LINK_STATE,
&bfLinkUp) == 0U)
&& (bfLinkUp))
{
/* Tell lwIP that the data link is up */
tcpip_callback((void(*)(void*))netif_set_up,
&pEtherC->ipNetIf);
}
}
else
{
if (pEtherC->ipConfig.byEnableDHCP == 0U)
{
pEtherC->ipConfig = *pIpConfig;
/* Protect against concurrent access,
specifically in the ARP modules */
tcpip_callback((void(*)(void*))netif_set_link_down,
&pEtherC->ipNetIf);
/* Also have to do this one as well. Is it not obvious
that if the physical link has been set down that
the data link is down too? */
tcpip_callback((void(*)(void*))netif_set_down,
&pEtherC->ipNetIf);
/* Tell lwIP to start DHCP */
tcpip_callback((void(*)(void*))dhcp_start,
&pEtherC->ipNetIf);
}
else
{
pEtherC->ipConfig = *pIpConfig;
}
}
return 0;
}
return -1;
}
/******************************************************************************
End of function ipReconfigure
******************************************************************************/
I hope this helps!
Cheers,
Adam.
On 18/06/2015 16:08, Zach Smith wrote:
Maybe someone else could also comment on this and let me know if I am
wrong but as far as I know you don’t have to do anything once the IP
address is obtained from DHCP. I don’t think you should ever be
calling dhcp_stop() unless maybe you really don’t want to use dhcp
anymore. Maybe they are incorrectly doing that in the example to free
up the udp pcb being used by dhcp. But I don’t think dhcp_stop()
should be called because the dhcp client should continue to run to
renew IP leases when they expire and stay registered with the dhcp server.
As far as I know all you have to do is call dhcp_start() (which also
ends up calling autoip_start() if AUTOIP is enabled) then just call
dhcp_fine_tmr(),dhcp_coarse_tmr(), and autioip_tmr() at their
respective intervals. Once the address is obtained, your netif will be
updated with that address – you don’t have to do anything.
*From:*[email protected]
[mailto:[email protected]] *On
Behalf Of *Robert Deschambault
*Sent:* Thursday, June 18, 2015 8:29 AM
*To:* Mailing list for lwIP users
*Subject:* Re: [lwip-users] Strategy Question for DHCP
Hi,
Ok, did another little experiment and I notice that if I don't call
dhcp_stop() in the DHCP state machine when the IP address gets
assigned I can ping my target when I use AUTOIP. Autoip is in state 3
(bound) and everything is fine. When I call dhcp_stop() at any time,
autoip goes to state 0 (stop) and I lose comms with the target.
My question is this: What should I be doing once the IP address is
assigned by either DHCP or AUTOIP in coop mode? Any call to
dhcp_stop() seems to be the wrong answer. But all the examples I have
seen for an STM32F4xx call that function once the IP address has been
assigned. Any comments?
On Wed, Jun 17, 2015 at 8:28 PM, Robert Deschambault
<[email protected] <mailto:[email protected]>>
wrote:
Hi,
I did a quick test to see when the autoip state is set to stop.
It looks like that when the IP address becomes non-zero, the DHCP
code recognizes the assignment and makes a call to dhcp_stop()
which I believe is calling autoip_stop() function coop mode. Here
is what the printf debug looks like at assignment (my code is also
printing stuff too and please remember I have modified the default
IP address pool for my application):
...
dhcp_discover()
transaction id xid(abcd0001)
dhcp_discover: making request
dhcp_discover: realloc()ing
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, DHCP_SERVER_PORT)
dhcp_discover: deleting()ing
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 16000 msecs
autoip_tmr() AutoIP-State: 2, ttw=6
autoip_tmr() AutoIP-State: 2, ttw=5
autoip_tmr() AutoIP-State: 2, ttw=4
autoip_tmr() AutoIP-State: 2, ttw=3
autoip_tmr() AutoIP-State: 2, ttw=2
autoip_tmr() AutoIP-State: 2, ttw=1
autoip_tmr() AutoIP-State: 2, ttw=0
autoip_bind(netif=20000778) cd0 192.168.252.11
autoip_tmr() AutoIP-State: 2, ttw=20
autoip_tmr() AutoIP-State: 2, ttw=19
MAIN: Network assigned by DHCP server:
dhcp_stop()
MAIN: IP: 192.168.252.11
MAIN: SN: 255.255.255.0
MAIN: GW: 192.168.252.1
autoip_tmr() AutoIP-State: 0, ttw=18
autoip_tmr() AutoIP-State: 0, ttw=18
autoip_tmr() AutoIP-State: 0, ttw=18
...
after this the last line is repeated over and over again. ttw
always stays at 18 and the state is always 0 (stop). I don't know
if this the expected behavior?
--
Bob Deschambault
--
Bob Deschambault
6614 Astro Court, Mississauga
Ontario, Canada L5N 7J2
home: 905 824 7159
cell: 416 457 7163
twitter: @rdeschambault
1Fm3QkinyqiMbpnvSZMLM1AyjBvbuYeTBE
------------------------------------------------------------------------
Confidentiality Notice: This e-mail may contain confidential and
privileged material for the sole use of the intended recipient(s). Any
review, use, distribution or disclosure by others is strictly
prohibited. If you are not the intended recipient (or authorized to
receive from the recipient), please contact the sender by reply e-mail
and delete all copies of the message.
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users