Lines Matching refs:netif
60 * dhcp_start(struct netif *netif);
64 * Use dhcp_release(netif) to end the lease and use dhcp_stop(netif)
77 #include "lwip/netif.h"
82 #include "netif/etharp.h"
104 #define DHCP_MAX_MSG_LEN(netif) (netif->mtu)
149 static err_t dhcp_discover(struct netif *netif);
150 static err_t dhcp_select(struct netif *netif);
151 static void dhcp_bind(struct netif *netif);
153 static err_t dhcp_decline(struct netif *netif);
155 static err_t dhcp_rebind(struct netif *netif);
156 static err_t dhcp_reboot(struct netif *netif);
163 static void dhcp_timeout(struct netif *netif);
164 static void dhcp_t1_timeout(struct netif *netif);
165 static void dhcp_t2_timeout(struct netif *netif);
169 static err_t dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type);
179 static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif);
194 * @param netif the netif under DHCP control
197 dhcp_handle_nak(struct netif *netif)
199 struct dhcp *dhcp = netif->dhcp;
200 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n",
201 (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
203 netif_set_down(netif);
205 netif_set_ipaddr(netif, IP_ADDR_ANY);
206 netif_set_gw(netif, IP_ADDR_ANY);
207 netif_set_netmask(netif, IP_ADDR_ANY);
211 dhcp_discover(netif);
222 * @param netif the netif under DHCP control
225 dhcp_check(struct netif *netif)
227 struct dhcp *dhcp = netif->dhcp;
230 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0],
231 (s16_t)netif->name[1]));
235 result = etharp_query(netif, &dhcp->offered_ip_addr, NULL);
249 * @param netif the netif under DHCP control
252 dhcp_handle_offer(struct netif *netif)
254 struct dhcp *dhcp = netif->dhcp;
255 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n",
256 (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
267 dhcp_select(netif);
270 ("dhcp_handle_offer(netif=%p) did not get server ID!\n", (void*)netif));
279 * @param netif the netif under DHCP control
283 dhcp_select(struct netif *netif)
285 struct dhcp *dhcp = netif->dhcp;
289 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_select(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
293 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
296 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
312 dhcp_option_hostname(dhcp, netif);
320 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
339 struct netif *netif = netif_list;
342 while (netif != NULL) {
344 if (netif->dhcp != NULL) {
346 if (netif->dhcp->t2_timeout-- == 1) {
349 dhcp_t2_timeout(netif);
351 } else if (netif->dhcp->t1_timeout-- == 1) {
354 dhcp_t1_timeout(netif);
357 /* proceed to next netif */
358 netif = netif->next;
371 struct netif *netif = netif_list;
372 /* loop through netif's */
373 while (netif != NULL) {
375 if (netif->dhcp != NULL) {
377 if (netif->dhcp->request_timeout > 1) {
378 netif->dhcp->request_timeout--;
380 else if (netif->dhcp->request_timeout == 1) {
381 netif->dhcp->request_timeout--;
382 /* { netif->dhcp->request_timeout == 0 } */
385 dhcp_timeout(netif);
389 netif = netif->next;
399 * @param netif the netif under DHCP control
402 dhcp_timeout(struct netif *netif)
404 struct dhcp *dhcp = netif->dhcp;
409 dhcp_discover(netif);
414 dhcp_select(netif);
417 dhcp_release(netif);
418 dhcp_discover(netif);
425 dhcp_check(netif);
430 dhcp_bind(netif);
439 dhcp_renew(netif);
444 dhcp_rebind(netif);
447 dhcp_release(netif);
448 dhcp_discover(netif);
452 dhcp_reboot(netif);
454 dhcp_discover(netif);
462 * @param netif the netif under DHCP control
465 dhcp_t1_timeout(struct netif *netif)
467 struct dhcp *dhcp = netif->dhcp;
477 dhcp_renew(netif);
484 * @param netif the netif under DHCP control
487 dhcp_t2_timeout(struct netif *netif)
489 struct dhcp *dhcp = netif->dhcp;
498 dhcp_rebind(netif);
505 * @param netif the netif under DHCP control
508 dhcp_handle_ack(struct netif *netif)
510 struct dhcp *dhcp = netif->dhcp;
583 * @param netif the netif for which to set the struct dhcp
587 dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
589 LWIP_ASSERT("netif != NULL", netif != NULL);
591 LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL);
596 netif->dhcp = dhcp;
599 /** Removes a struct dhcp from a netif.
604 * @param netif the netif from which to remove the struct dhcp
606 void dhcp_cleanup(struct netif *netif)
608 LWIP_ASSERT("netif != NULL", netif != NULL);
610 if (netif->dhcp != NULL) {
611 mem_free(netif->dhcp);
612 netif->dhcp = NULL;
623 * @param netif The lwIP network interface
629 dhcp_start(struct netif *netif)
634 LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
635 dhcp = netif->dhcp;
636 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
637 /* Remove the flag that says this netif is handled by DHCP,
639 netif->flags &= ~NETIF_FLAG_DHCP;
641 /* check hwtype of the netif */
642 if ((netif->flags & NETIF_FLAG_ETHARP) == 0) {
643 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): No ETHARP netif\n"));
647 /* check MTU of the netif */
648 if (netif->mtu < DHCP_MAX_MSG_LEN_MIN_REQUIRED) {
649 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): Cannot use this netif with DHCP: MTU is too small\n"));
661 /* store this dhcp client in the netif */
662 netif->dhcp = dhcp;
688 udp_recv(dhcp->pcb, dhcp_recv, netif);
691 result = dhcp_discover(netif);
694 dhcp_stop(netif);
697 /* Set the flag that says this netif is handled by DHCP. */
698 netif->flags |= NETIF_FLAG_DHCP;
709 * @param netif The lwIP network interface
712 dhcp_inform(struct netif *netif)
718 LWIP_ERROR("netif != NULL", (netif != NULL), return;);
723 if ((netif->dhcp != NULL) && (netif->dhcp->pcb != NULL)) {
725 pcb = netif->dhcp->pcb;
738 result = dhcp_create_msg(netif, &dhcp, DHCP_INFORM);
741 dhcp_option_short(&dhcp, DHCP_MAX_MSG_LEN(netif));
748 udp_sendto_if(pcb, dhcp.p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
766 dhcp_network_changed(struct netif *netif)
768 struct dhcp *dhcp = netif->dhcp;
776 netif_set_down(netif);
778 dhcp_reboot(netif);
787 autoip_stop(netif);
791 dhcp_discover(netif);
800 * @param netif the network interface on which the reply was received
803 void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr)
805 LWIP_ERROR("netif != NULL", (netif != NULL), return;);
808 if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) {
813 if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {
817 dhcp_decline(netif);
829 * @param netif the netif under DHCP control
832 dhcp_decline(struct netif *netif)
834 struct dhcp *dhcp = netif->dhcp;
840 result = dhcp_create_msg(netif, dhcp, DHCP_DECLINE);
850 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
869 * @param netif the netif under DHCP control
872 dhcp_discover(struct netif *netif)
874 struct dhcp *dhcp = netif->dhcp;
881 result = dhcp_create_msg(netif, dhcp, DHCP_DISCOVER);
886 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
900 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
911 autoip_start(netif);
924 * @param netif network interface to bind to the offered address
927 dhcp_bind(struct netif *netif)
932 LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;);
933 dhcp = netif->dhcp;
935 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
996 autoip_stop(netif);
1003 netif_set_ipaddr(netif, &dhcp->offered_ip_addr);
1006 netif_set_netmask(netif, &sn_mask);
1009 netif_set_gw(netif, &gw_addr);
1011 netif_set_up(netif);
1012 /* netif is now bound to DHCP leased address */
1019 * @param netif network interface which must renew its lease
1022 dhcp_renew(struct netif *netif)
1024 struct dhcp *dhcp = netif->dhcp;
1031 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
1034 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
1047 dhcp_option_hostname(dhcp, netif);
1055 udp_sendto_if(dhcp->pcb, dhcp->p_out, &dhcp->server_ip_addr, DHCP_SERVER_PORT, netif);
1073 * @param netif network interface which must rebind with a DHCP server
1076 dhcp_rebind(struct netif *netif)
1078 struct dhcp *dhcp = netif->dhcp;
1085 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
1088 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
1091 dhcp_option_hostname(dhcp, netif);
1107 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
1123 * @param netif network interface which must reboot
1126 dhcp_reboot(struct netif *netif)
1128 struct dhcp *dhcp = netif->dhcp;
1135 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
1148 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
1165 * @param netif network interface which must release its lease
1168 dhcp_release(struct netif *netif)
1170 struct dhcp *dhcp = netif->dhcp;
1188 result = dhcp_create_msg(netif, dhcp, DHCP_RELEASE);
1194 udp_sendto_if(dhcp->pcb, dhcp->p_out, &dhcp->server_ip_addr, DHCP_SERVER_PORT, netif);
1205 netif_set_down(netif);
1207 netif_set_ipaddr(netif, IP_ADDR_ANY);
1208 netif_set_gw(netif, IP_ADDR_ANY);
1209 netif_set_netmask(netif, IP_ADDR_ANY);
1217 * @param netif The network interface to stop DHCP on
1220 dhcp_stop(struct netif *netif)
1223 LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;);
1224 dhcp = netif->dhcp;
1225 /* Remove the flag that says this netif is handled by DHCP. */
1226 netif->flags &= ~NETIF_FLAG_DHCP;
1229 /* netif is DHCP configured? */
1233 autoip_stop(netif);
1305 dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif)
1307 if (netif->hostname != NULL) {
1308 size_t namelen = strlen(netif->hostname);
1311 const char *p = netif->hostname;
1539 struct netif *netif = (struct netif *)arg;
1540 struct dhcp *dhcp = netif->dhcp;
1565 for (i = 0; i < netif->hwaddr_len; i++) {
1566 if (netif->hwaddr[i] != reply_msg->chaddr[i]) {
1568 ("netif->hwaddr[%"U16_F"]==%02"X16_F" != reply_msg->chaddr[%"U16_F"]==%02"X16_F"\n",
1569 (u16_t)i, (u16_t)netif->hwaddr[i], (u16_t)i, (u16_t)reply_msg->chaddr[i]));
1600 dhcp_handle_ack(netif);
1603 dhcp_check(netif);
1606 dhcp_bind(netif);
1611 dhcp_bind(netif);
1619 dhcp_handle_nak(netif);
1626 dhcp_handle_offer(netif);
1636 * @param netif the netif under DHCP control
1641 dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type)
1660 LWIP_ERROR("dhcp_create_msg: netif != NULL", (netif != NULL), return ERR_ARG;);
1690 dhcp->msg_out->hlen = netif->hwaddr_len;
1698 /* set ciaddr to netif->ip_addr based on message_type and state */
1702 ip_addr_copy(dhcp->msg_out->ciaddr, netif->ip_addr);
1708 /* copy netif hardware address, pad with zeroes */
1709 dhcp->msg_out->chaddr[i] = (i < netif->hwaddr_len) ? netif->hwaddr[i] : 0/* pad byte*/;