]> git.donarmstrong.com Git - qmk_firmware.git/blob - lib/lufa/Demos/Device/ClassDriver/RNDISEthernet/Lib/DHCP.h
Merge commit '60b30c036397cb5627fa374bb930794b225daa29' as 'lib/lufa'
[qmk_firmware.git] / lib / lufa / Demos / Device / ClassDriver / RNDISEthernet / Lib / DHCP.h
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2017.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2017  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 Lease Time will follow. */
64                 #define DHCP_OPTION_LEASETIME     51
65
66                 /** DHCP option list entry header, indicating that the DHCP message type constant will follow. */
67                 #define DHCP_OPTION_MESSAGETYPE   53
68
69                 /** DHCP option list entry header, indicating that the IP address of the DHCP server will follow. */
70                 #define DHCP_OPTION_DHCPSERVER    54
71
72                 /** DHCP option list entry header, used to pad out option data. */
73                 #define DHCP_OPTION_PAD           0
74
75                 /** DHCP option list entry header, indicating the end of option data. */
76                 #define DHCP_OPTION_END           255
77
78                 /** Message type constant, used in the DHCP option data field, requesting that a DHCP server offer an IP address. */
79                 #define DHCP_MESSAGETYPE_DISCOVER 1
80
81                 /** Message type constant, used in the DHCP option data field, indicating that a DHCP server is offering an IP address. */
82                 #define DHCP_MESSAGETYPE_OFFER    2
83
84                 /** Message type constant, used in the DHCP option data field, requesting that a DHCP server lease a given IP address. */
85                 #define DHCP_MESSAGETYPE_REQUEST  3
86
87                 /** Message type constant, used in the DHCP option data field, declining an offered DHCP server IP address lease. */
88                 #define DHCP_MESSAGETYPE_DECLINE  4
89
90                 /** Message type constant, used in the DHCP option data field, ACKing a host IP lease request. */
91                 #define DHCP_MESSAGETYPE_ACK      5
92
93                 /** Message type constant, used in the DHCP option data field, NACKing a host IP lease request. */
94                 #define DHCP_MESSAGETYPE_NACK     6
95
96                 /** Message type constant, used in the DHCP option data field, indicating that a host is releasing a leased IP address. */
97                 #define DHCP_MESSAGETYPE_RELEASE  7
98
99         /* Type Defines: */
100                 /** Type define for a DHCP packet inside an Ethernet frame. */
101                 typedef struct
102                 {
103                         uint8_t  Operation; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */
104                         uint8_t  HardwareType; /**< Hardware carrier type constant */
105                         uint8_t  HardwareAddressLength;  /**< Length in bytes of a hardware (MAC) address on the network */
106                         uint8_t  Hops; /**< Number of hops required to reach the server, unused */
107
108                         uint32_t TransactionID; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
109
110                         uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */
111                         uint16_t Flags; /**< BOOTP packet flags */
112
113                         IP_Address_t ClientIP; /**< Client IP address, if already leased an IP */
114                         IP_Address_t YourIP; /**< Client IP address */
115                         IP_Address_t NextServerIP; /**< Legacy BOOTP protocol field, unused for DHCP */
116                         IP_Address_t RelayAgentIP; /**< Legacy BOOTP protocol field, unused for DHCP */
117
118                         uint8_t ClientHardwareAddress[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */
119                         uint8_t ServerHostnameString[64]; /**< Legacy BOOTP protocol field, unused for DHCP */
120                         uint8_t BootFileName[128]; /**< Legacy BOOTP protocol field, unused for DHCP */
121
122                         uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */
123                 } DHCP_Header_t;
124
125         /* Function Prototypes: */
126                 int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart,
127                                                void* DHCPHeaderInStart,
128                                                void* DHCPHeaderOutStart);
129
130 #endif
131