Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dhcp.h Source File

dhcp.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * DHCP client API
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Leon Woestenberg <leon.woestenberg@gmx.net>
00008  * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands.
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification,
00012  * are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice,
00015  *    this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright notice,
00017  *    this list of conditions and the following disclaimer in the documentation
00018  *    and/or other materials provided with the distribution.
00019  * 3. The name of the author may not be used to endorse or promote products
00020  *    derived from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00023  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00024  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00025  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00027  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00031  * OF SUCH DAMAGE.
00032  *
00033  * This file is part of the lwIP TCP/IP stack.
00034  *
00035  * Author: Leon Woestenberg <leon.woestenberg@gmx.net>
00036  *
00037  */
00038 #ifndef LWIP_HDR_DHCP_H
00039 #define LWIP_HDR_DHCP_H
00040 
00041 #include "lwip/opt.h"
00042 
00043 #if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
00044 
00045 #include "lwip/netif.h"
00046 #include "lwip/udp.h"
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 /** period (in seconds) of the application calling dhcp_coarse_tmr() */
00053 #define DHCP_COARSE_TIMER_SECS  60
00054 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
00055 #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
00056 /** period (in milliseconds) of the application calling dhcp_fine_tmr() */
00057 #define DHCP_FINE_TIMER_MSECS   500
00058 
00059 #define DHCP_BOOT_FILE_LEN      128U
00060 
00061 /* AutoIP cooperation flags (struct dhcp.autoip_coop_state) */
00062 typedef enum {
00063   DHCP_AUTOIP_COOP_STATE_OFF  = 0,
00064   DHCP_AUTOIP_COOP_STATE_ON   = 1
00065 } dhcp_autoip_coop_state_enum_t;
00066 
00067 struct dhcp
00068 {
00069   /** transaction identifier of last sent request */
00070   u32_t xid;
00071   /** incoming msg */
00072   struct dhcp_msg *msg_in;
00073   /** track PCB allocation state */
00074   u8_t pcb_allocated;
00075   /** current DHCP state machine state */
00076   u8_t state;
00077   /** retries of current request */
00078   u8_t tries;
00079 #if LWIP_DHCP_AUTOIP_COOP
00080   u8_t autoip_coop_state;
00081 #endif
00082   u8_t subnet_mask_given;
00083 
00084   struct pbuf *p_out; /* pbuf of outcoming msg */
00085   struct dhcp_msg *msg_out; /* outgoing msg */
00086   u16_t options_out_len; /* outgoing msg options length */
00087   u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
00088   u16_t t1_timeout;  /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
00089   u16_t t2_timeout;  /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
00090   u16_t t1_renew_time;  /* #ticks with period DHCP_COARSE_TIMER_SECS until next renew try */
00091   u16_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */
00092   u16_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */
00093   u16_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */
00094   ip_addr_t server_ip_addr; /* dhcp server address that offered this lease (ip_addr_t because passed to UDP) */
00095   ip4_addr_t offered_ip_addr;
00096   ip4_addr_t offered_sn_mask;
00097   ip4_addr_t offered_gw_addr;
00098 
00099   u32_t offered_t0_lease; /* lease period (in seconds) */
00100   u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
00101   u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period)  */
00102 #if LWIP_DHCP_BOOTP_FILE
00103   ip4_addr_t offered_si_addr;
00104   char boot_file_name[DHCP_BOOT_FILE_LEN];
00105 #endif /* LWIP_DHCP_BOOTPFILE */
00106 };
00107 
00108 
00109 void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
00110 /** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */
00111 #define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0)
00112 void dhcp_cleanup(struct netif *netif);
00113 err_t dhcp_start(struct netif *netif);
00114 err_t dhcp_renew(struct netif *netif);
00115 err_t dhcp_release(struct netif *netif);
00116 void dhcp_stop(struct netif *netif);
00117 void dhcp_inform(struct netif *netif);
00118 void dhcp_network_changed(struct netif *netif);
00119 #if DHCP_DOES_ARP_CHECK
00120 void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr);
00121 #endif
00122 u8_t dhcp_supplied_address(const struct netif *netif);
00123 /* to be called every minute */
00124 void dhcp_coarse_tmr(void);
00125 /* to be called every half second */
00126 void dhcp_fine_tmr(void);
00127 
00128 #if LWIP_DHCP_GET_NTP_SRV
00129 /** This function must exist, in other to add offered NTP servers to
00130  * the NTP (or SNTP) engine.
00131  * See LWIP_DHCP_MAX_NTP_SERVERS */
00132 extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, const ip4_addr_t* ntp_server_addrs);
00133 #endif /* LWIP_DHCP_GET_NTP_SRV */
00134 
00135 #define netif_dhcp_data(netif) ((struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP))
00136 
00137 #ifdef __cplusplus
00138 }
00139 #endif
00140 
00141 #endif /* LWIP_DHCP */
00142 
00143 #endif /*LWIP_HDR_DHCP_H*/