00001 /*############################################################################## 00002 00003 nIP - nano IP stack 00004 00005 File : dhcp.h 00006 00007 Description : Dynamic Host Configuration Protocol 00008 00009 Copyright notice: 00010 00011 Copyright (C) 2005 - 00012 Andreas Dittrich, dittrich@informatik.hu-berlin.de 00013 Jon Kowal, kowal@informatik.hu-berlin.de 00014 00015 This program is free software; you can redistribute it and/or 00016 modify it under the terms of the GNU General Public License 00017 as published by the Free Software Foundation; either version 2 00018 of the License, or (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program; if not, write to the Free Software 00027 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00028 00029 ##############################################################################*/ 00030 00031 #ifndef _DHCP_H_ 00032 #define _DHCP_H_ 00033 00034 #include "nip_init.h" 00035 #include "nip_types.h" 00036 #include "net/net_if.h" 00037 #include "net/udp.h" 00038 #include NIP_ARCH_FILE(endianness.h) 00039 00040 #define NIP_DHCP_INIT_BACKOFF 4 /**< initial delay for exponential backoff algorithm */ 00041 #define NIP_DHCP_MAX_BACKOFF 64/**< maximum delay for exponential backoff algorithm */ 00042 00043 #define NIP_DHCP_OP_REQUEST 1 00044 #define NIP_DHCP_OP_REPLY 2 00045 00046 #define DHCP_OPTION_PADDING 0 00047 #define DHCP_OPTION_SUBNETMASK 1 00048 #define DHCP_OPTION_ROUTER 3 00049 #define DHCP_OPTION_DNS 6 00050 #define DHCP_OPTION_HOST_NAME 12 00051 #define DHCP_OPTION_DOMAINNAME 15 00052 #define DHCP_OPTION_ROUTERDSCVR 31 00053 #define DHCP_OPTION_NTPSERVERS 42 00054 #define DHCP_OPTION_REQUEST_IP 50 00055 #define DHCP_OPTION_LEASETIME 51 00056 #define DHCP_OPTION_MSGTYPE 53 00057 #define DHCP_OPTION_MSGTYPE_DISCOVER 1 00058 #define DHCP_OPTION_MSGTYPE_OFFER 2 00059 #define DHCP_OPTION_MSGTYPE_REQUEST 3 00060 #define DHCP_OPTION_MSGTYPE_DECLINE 4 00061 #define DHCP_OPTION_MSGTYPE_ACK 5 00062 #define DHCP_OPTION_MSGTYPE_NAK 6 00063 #define DHCP_OPTION_MSGTYPE_RELEASE 7 00064 #define DHCP_OPTION_SERVERID 54 00065 #define DHCP_OPTION_PARAMREQLIST 55 00066 #define DHCP_OPTION_RENEWAL_TIME 58 00067 #define DHCP_OPTION_REBINDING_TIME 59 00068 #define DHCP_OPTION_VENDOR_CLASSID 60 00069 #define DHCP_OPTION_CLIENT_IDENTIFIER 61 00070 #define DHCP_OPTION_AUTO_CONFIGURE 116 00071 #define DHCP_OPTION_END 255 00072 00073 00074 // #define NIP_DHCP_HTYPE_ETH 1 00075 // #define NIP_DHCP_HLEN_ETH 6 00076 00077 /** DHCP Magic Cookie Option in Network Byte Order (decimal 99.130.82.99) */ 00078 #if ( ENDIANNESS == BIG_ENDIAN ) 00079 #define NIP_DHCP_MAGIC_COOKIE 0x63825363 00080 #else // ENDIANNESS 00081 #define NIP_DHCP_MAGIC_COOKIE 0x63538263 00082 #endif // ENDIANNESS 00083 00084 typedef enum 00085 { 00086 NIP_DHCP_STAT_DISABLED = 0, 00087 NIP_DHCP_STAT_INIT, 00088 NIP_DHCP_STAT_SELECTING, 00089 NIP_DHCP_STAT_REQUESTING, 00090 NIP_DHCP_STAT_BOUND, 00091 NIP_DHCP_STAT_RENEWING, 00092 NIP_DHCP_STAT_REBINDING, 00093 NIP_DHCP_STAT_REBOOTING 00094 } 00095 #ifndef DOXYGEN 00096 __attribute__((packed)) 00097 #endif 00098 nip_dhcp_stat_t; 00099 00100 /** structure to evaluate known dhcp options */ 00101 struct nip_dhcp_option 00102 { 00103 uint8_t type; 00104 uint8_t valsize; 00105 union 00106 { 00107 uint8_t msgtype; 00108 uint8_t ipaddr[4]; 00109 uint32_t time; 00110 } value; 00111 } 00112 #ifndef DOXYGEN 00113 __attribute__((packed)) 00114 #endif 00115 ; 00116 00117 struct nip_dhcp_packet 00118 { 00119 uint8_t op; 00120 uint8_t htype; 00121 uint8_t hlen; 00122 uint8_t hops; 00123 uint32_t xid; 00124 uint16_t secs; 00125 uint8_t flags[2]; 00126 uint8_t ciaddr[4]; 00127 uint8_t yiaddr[4]; 00128 uint8_t siaddr[4]; 00129 uint8_t giaddr[4]; 00130 uint8_t chaddr[16]; 00131 uint8_t sname[64]; 00132 uint8_t file[128]; 00133 uint32_t magic_cookie; 00134 uint8_t options[60]; 00135 } 00136 #ifndef DOXYGEN 00137 __attribute__((packed)) 00138 #endif 00139 ; 00140 00141 struct nip_dhcp_config { 00142 nip_dhcp_stat_t state; 00143 uint32_t xid; 00144 uint8_t backoff_delay; 00145 nip_time_t leasetime; /** halt network when lease time is reached */ 00146 nip_time_t t1; /** renew (unicast) DHCP lease when timer t1 expires */ 00147 nip_time_t t2; /** renew (broadcast) DHCP lease when timer t2 expires*/ 00148 nip_time_t ts; /** time a packet will have to be resent at */ 00149 struct nip_udp_sock_addr serv_addr; /** address of dhcp server */ 00150 } 00151 #ifndef DOXYGEN 00152 __attribute__((packed)) 00153 #endif 00154 ; 00155 00156 void nip_dhcp_start( nip_net_if_id_t net_if ); 00157 void nip_dhcp_disable( nip_net_if_id_t net_if ); 00158 void nip_dhcp_disp_check( void ); 00159 00160 #endif // _DHCP_H_