Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DHCP.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. *
  28. * Header file for DHCP.c.
  29. */
  30. #ifndef _DHCP_H_
  31. #define _DHCP_H_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <string.h>
  35. #include "EthernetProtocols.h"
  36. #include "Ethernet.h"
  37. #include "ProtocolDecoders.h"
  38. /* Macros: */
  39. /** DHCP operation constant, indicating a request from a host to a DHCP server. */
  40. #define DHCP_OP_BOOTREQUEST 0x01
  41. /** DHCP operation constant, indicating a reply from a DHCP server to a host. */
  42. #define DHCP_OP_BOOTREPLY 0x02
  43. /** Hardware type constant, indicating Ethernet as a carrier. */
  44. #define DHCP_HTYPE_ETHERNET 0x01
  45. /** Magic boot protocol "cookie", inserted into all BOOTP packets (BOOTP is the carrier of DHCP). */
  46. #define DHCP_MAGIC_COOKIE 0x63825363
  47. /** DHCP option list entry header, indicating that a subnet mask will follow. */
  48. #define DHCP_OPTION_SUBNETMASK 1
  49. /** DHCP option list entry header, indicating that the DHCP message type constant will follow. */
  50. #define DHCP_OPTION_MESSAGETYPE 53
  51. /** DHCP option list entry header, indicating that the IP address of the DHCP server will follow. */
  52. #define DHCP_OPTION_DHCPSERVER 54
  53. /** DHCP option list entry header, used to pad out option data. */
  54. #define DHCP_OPTION_PAD 0
  55. /** DHCP option list entry header, indicating the end of option data. */
  56. #define DHCP_OPTION_END 255
  57. /** Message type constant, used in the DHCP option data field, requesting that a DHCP server offer an IP address. */
  58. #define DHCP_MESSAGETYPE_DISCOVER 1
  59. /** Message type constant, used in the DHCP option data field, indicating that a DHCP server is offering an IP address. */
  60. #define DHCP_MESSAGETYPE_OFFER 2
  61. /** Message type constant, used in the DHCP option data field, requesting that a DHCP server lease a given IP address. */
  62. #define DHCP_MESSAGETYPE_REQUEST 3
  63. /** Message type constant, used in the DHCP option data field, declining an offered DHCP server IP address lease. */
  64. #define DHCP_MESSAGETYPE_DECLINE 4
  65. /** Message type constant, used in the DHCP option data field, ACKing a host IP lease request. */
  66. #define DHCP_MESSAGETYPE_ACK 5
  67. /** Message type constant, used in the DHCP option data field, NACKing a host IP lease request. */
  68. #define DHCP_MESSAGETYPE_NACK 6
  69. /** Message type constant, used in the DHCP option data field, indicating that a host is releasing a leased IP address. */
  70. #define DHCP_MESSAGETYPE_RELEASE 7
  71. /* Type Defines: */
  72. /** Type define for a DHCP packet inside an Ethernet frame. */
  73. typedef struct
  74. {
  75. uint8_t Operation; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */
  76. uint8_t HardwareType; /**< Hardware carrier type constant */
  77. uint8_t HardwareAddressLength; /**< Length in bytes of a hardware (MAC) address on the network */
  78. uint8_t Hops; /**< Number of hops required to reach the server, unused */
  79. uint32_t TransactionID; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
  80. uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */
  81. uint16_t Flags; /**< BOOTP packet flags */
  82. IP_Address_t ClientIP; /**< Client IP address, if already leased an IP */
  83. IP_Address_t YourIP; /**< Client IP address */
  84. IP_Address_t NextServerIP; /**< Legacy BOOTP protocol field, unused for DHCP */
  85. IP_Address_t RelayAgentIP; /**< Legacy BOOTP protocol field, unused for DHCP */
  86. uint8_t ClientHardwareAddress[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */
  87. uint8_t ServerHostnameString[64]; /**< Legacy BOOTP protocol field, unused for DHCP */
  88. uint8_t BootFileName[128]; /**< Legacy BOOTP protocol field, unused for DHCP */
  89. uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */
  90. } DHCP_Header_t;
  91. /* Function Prototypes: */
  92. int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart,
  93. void* DHCPHeaderInStart,
  94. void* DHCPHeaderOutStart);
  95. #endif