]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.h
Merge commit '20b787fc1284176834cbe7ca2134e4b36bec5828'
[tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / Demos / Device / LowLevel / RNDISEthernet / Lib / DHCP.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 DHCP.c.
34 */
35
36 #ifndef _DHCP_H_
37 #define _DHCP_H_
38
39 /* Includes: */
40 #include <avr/io.h>
41 #include <string.h>
42
43 #include "EthernetProtocols.h"
44 #include "Ethernet.h"
45 #include "ProtocolDecoders.h"
46
47 /* Macros: */
48 /** DHCP operation constant, indicating a request from a host to a DHCP server. */
49 #define DHCP_OP_BOOTREQUEST 0x01
50
51 /** DHCP operation constant, indicating a reply from a DHCP server to a host. */
52 #define DHCP_OP_BOOTREPLY 0x02
53
54 /** Hardware type constant, indicating Ethernet as a carrier. */
55 #define DHCP_HTYPE_ETHERNET 0x01
56
57 /** Magic boot protocol "cookie", inserted into all BOOTP packets (BOOTP is the carrier of DHCP). */
58 #define DHCP_MAGIC_COOKIE 0x63825363
59
60 /** DHCP option list entry header, indicating that a subnet mask will follow. */
61 #define DHCP_OPTION_SUBNETMASK 1
62
63 /** DHCP option list entry header, indicating that the DHCP message type constant will follow. */
64 #define DHCP_OPTION_MESSAGETYPE 53
65
66 /** DHCP option list entry header, indicating that the IP address of the DHCP server will follow. */
67 #define DHCP_OPTION_DHCPSERVER 54
68
69 /** DHCP option list entry header, used to pad out option data. */
70 #define DHCP_OPTION_PAD 0
71
72 /** DHCP option list entry header, indicating the end of option data. */
73 #define DHCP_OPTION_END 255
74
75 /** Message type constant, used in the DHCP option data field, requesting that a DHCP server offer an IP address. */
76 #define DHCP_MESSAGETYPE_DISCOVER 1
77
78 /** Message type constant, used in the DHCP option data field, indicating that a DHCP server is offering an IP address. */
79 #define DHCP_MESSAGETYPE_OFFER 2
80
81 /** Message type constant, used in the DHCP option data field, requesting that a DHCP server lease a given IP address. */
82 #define DHCP_MESSAGETYPE_REQUEST 3
83
84 /** Message type constant, used in the DHCP option data field, declining an offered DHCP server IP address lease. */
85 #define DHCP_MESSAGETYPE_DECLINE 4
86
87 /** Message type constant, used in the DHCP option data field, ACKing a host IP lease request. */
88 #define DHCP_MESSAGETYPE_ACK 5
89
90 /** Message type constant, used in the DHCP option data field, NACKing a host IP lease request. */
91 #define DHCP_MESSAGETYPE_NACK 6
92
93 /** Message type constant, used in the DHCP option data field, indicating that a host is releasing a leased IP address. */
94 #define DHCP_MESSAGETYPE_RELEASE 7
95
96 /* Type Defines: */
97 /** Type define for a DHCP packet inside an Ethernet frame. */
98 typedef struct
99 {
100 uint8_t Operation; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */
101 uint8_t HardwareType; /**< Hardware carrier type constant */
102 uint8_t HardwareAddressLength; /**< Length in bytes of a hardware (MAC) address on the network */
103 uint8_t Hops; /**< Number of hops required to reach the server, unused */
104
105 uint32_t TransactionID; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
106
107 uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */
108 uint16_t Flags; /**< BOOTP packet flags */
109
110 IP_Address_t ClientIP; /**< Client IP address, if already leased an IP */
111 IP_Address_t YourIP; /**< Client IP address */
112 IP_Address_t NextServerIP; /**< Legacy BOOTP protocol field, unused for DHCP */
113 IP_Address_t RelayAgentIP; /**< Legacy BOOTP protocol field, unused for DHCP */
114
115 uint8_t ClientHardwareAddress[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */
116 uint8_t ServerHostnameString[64]; /**< Legacy BOOTP protocol field, unused for DHCP */
117 uint8_t BootFileName[128]; /**< Legacy BOOTP protocol field, unused for DHCP */
118
119 uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */
120 } DHCP_Header_t;
121
122 /* Function Prototypes: */
123 int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart,
124 void* DHCPHeaderInStart,
125 void* DHCPHeaderOutStart);
126
127 #endif
128
Imprint / Impressum