]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/Projects/Webserver/Lib/DHCPCommon.h
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / Projects / Webserver / Lib / DHCPCommon.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * Header file for common DHCP defines.
34 */
35
36 #ifndef _DHCP_COMMON_H_
37 #define _DHCP_COMMON_H_
38
39 /* Includes: */
40 #include <stdint.h>
41 #include <stdbool.h>
42 #include <string.h>
43
44 #include "Config/AppConfig.h"
45
46 #include <uip.h>
47
48 /* Macros: */
49 /** UDP listen port for a BOOTP server. */
50 #define DHCP_SERVER_PORT 67
51
52 /** UDP listen port for a BOOTP client. */
53 #define DHCP_CLIENT_PORT 68
54
55 /** BOOTP message type for a BOOTP REQUEST message. */
56 #define DHCP_OP_BOOTREQUEST 0x01
57
58 /** BOOTP message type for a BOOTP REPLY message. */
59 #define DHCP_OP_BOOTREPLY 0x02
60
61 /** BOOTP flag for a BOOTP broadcast message. */
62 #define BOOTP_BROADCAST 0x8000
63
64 /** Magic DHCP cookie for a BOOTP message to identify it as a DHCP message. */
65 #define DHCP_MAGIC_COOKIE 0x63538263
66
67 /** Unique transaction ID used to identify DHCP responses to the client. */
68 #define DHCP_TRANSACTION_ID 0x13245466
69
70 /** DHCP message type for a DISCOVER message. */
71 #define DHCP_DISCOVER 1
72
73 /** DHCP message type for an OFFER message. */
74 #define DHCP_OFFER 2
75
76 /** DHCP message type for a REQUEST message. */
77 #define DHCP_REQUEST 3
78
79 /** DHCP message type for a DECLINE message. */
80 #define DHCP_DECLINE 4
81
82 /** DHCP message type for an ACK message. */
83 #define DHCP_ACK 5
84
85 /** DHCP message type for a NAK message. */
86 #define DHCP_NAK 6
87
88 /** DHCP message type for a RELEASE message. */
89 #define DHCP_RELEASE 7
90
91 /** DHCP medium type for standard Ethernet. */
92 #define DHCP_HTYPE_ETHERNET 1
93
94 /** DHCP message option for the network subnet mask. */
95 #define DHCP_OPTION_SUBNET_MASK 1
96
97 /** DHCP message option for the network gateway IP. */
98 #define DHCP_OPTION_ROUTER 3
99
100 /** DHCP message option for the network DNS server. */
101 #define DHCP_OPTION_DNS_SERVER 6
102
103 /** DHCP message option for the requested client IP address. */
104 #define DHCP_OPTION_REQ_IPADDR 50
105
106 /** DHCP message option for the IP address lease time. */
107 #define DHCP_OPTION_LEASE_TIME 51
108
109 /** DHCP message option for the DHCP message type. */
110 #define DHCP_OPTION_MSG_TYPE 53
111
112 /** DHCP message option for the DHCP server IP. */
113 #define DHCP_OPTION_SERVER_ID 54
114
115 /** DHCP message option for the list of required options from the server. */
116 #define DHCP_OPTION_REQ_LIST 55
117
118 /** DHCP message option for the options list terminator. */
119 #define DHCP_OPTION_END 255
120
121 /* Type Defines: */
122 /** Type define for a DHCP packet inside an Ethernet frame. */
123 typedef struct
124 {
125 uint8_t Operation; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */
126 uint8_t HardwareType; /**< Hardware carrier type constant */
127 uint8_t HardwareAddressLength; /**< Length in bytes of a hardware (MAC) address on the network */
128 uint8_t Hops; /**< Number of hops required to reach the server, unused */
129
130 uint32_t TransactionID; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
131
132 uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */
133 uint16_t Flags; /**< BOOTP packet flags */
134
135 uip_ipaddr_t ClientIP; /**< Client IP address, if already leased an IP */
136 uip_ipaddr_t YourIP; /**< Client IP address */
137 uip_ipaddr_t NextServerIP; /**< Legacy BOOTP protocol field, unused for DHCP */
138 uip_ipaddr_t RelayAgentIP; /**< Legacy BOOTP protocol field, unused for DHCP */
139
140 uint8_t ClientHardwareAddress[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */
141 uint8_t ServerHostnameString[64]; /**< Legacy BOOTP protocol field, unused for DHCP */
142 uint8_t BootFileName[128]; /**< Legacy BOOTP protocol field, unused for DHCP */
143
144 uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */
145
146 uint8_t Options[]; /**< DHCP message options */
147 } DHCP_Header_t;
148
149 /* Function Prototypes: */
150 uint8_t DHCPCommon_SetOption(uint8_t* DHCPOptionList,
151 const uint8_t Option,
152 const uint8_t DataLen,
153 void* const OptionData);
154 bool DHCPCommon_GetOption(const uint8_t* DHCPOptionList,
155 const uint8_t Option,
156 void* const Destination);
157
158 #endif
159
Imprint / Impressum