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.

DHCPCommon.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 common DHCP defines.
  29. */
  30. #ifndef _DHCP_COMMON_H_
  31. #define _DHCP_COMMON_H_
  32. /* Includes: */
  33. #include <stdint.h>
  34. #include <stdbool.h>
  35. #include <string.h>
  36. #include "Config/AppConfig.h"
  37. #include <uip.h>
  38. /* Macros: */
  39. /** UDP listen port for a BOOTP server. */
  40. #define DHCP_SERVER_PORT 67
  41. /** UDP listen port for a BOOTP client. */
  42. #define DHCP_CLIENT_PORT 68
  43. /** BOOTP message type for a BOOTP REQUEST message. */
  44. #define DHCP_OP_BOOTREQUEST 0x01
  45. /** BOOTP message type for a BOOTP REPLY message. */
  46. #define DHCP_OP_BOOTREPLY 0x02
  47. /** BOOTP flag for a BOOTP broadcast message. */
  48. #define BOOTP_BROADCAST 0x8000
  49. /** Magic DHCP cookie for a BOOTP message to identify it as a DHCP message. */
  50. #define DHCP_MAGIC_COOKIE 0x63538263
  51. /** Unique transaction ID used to identify DHCP responses to the client. */
  52. #define DHCP_TRANSACTION_ID 0x13245466
  53. /** DHCP message type for a DISCOVER message. */
  54. #define DHCP_DISCOVER 1
  55. /** DHCP message type for an OFFER message. */
  56. #define DHCP_OFFER 2
  57. /** DHCP message type for a REQUEST message. */
  58. #define DHCP_REQUEST 3
  59. /** DHCP message type for a DECLINE message. */
  60. #define DHCP_DECLINE 4
  61. /** DHCP message type for an ACK message. */
  62. #define DHCP_ACK 5
  63. /** DHCP message type for a NAK message. */
  64. #define DHCP_NAK 6
  65. /** DHCP message type for a RELEASE message. */
  66. #define DHCP_RELEASE 7
  67. /** DHCP medium type for standard Ethernet. */
  68. #define DHCP_HTYPE_ETHERNET 1
  69. /** DHCP message option for the network subnet mask. */
  70. #define DHCP_OPTION_SUBNET_MASK 1
  71. /** DHCP message option for the network gateway IP. */
  72. #define DHCP_OPTION_ROUTER 3
  73. /** DHCP message option for the network DNS server. */
  74. #define DHCP_OPTION_DNS_SERVER 6
  75. /** DHCP message option for the requested client IP address. */
  76. #define DHCP_OPTION_REQ_IPADDR 50
  77. /** DHCP message option for the IP address lease time. */
  78. #define DHCP_OPTION_LEASE_TIME 51
  79. /** DHCP message option for the DHCP message type. */
  80. #define DHCP_OPTION_MSG_TYPE 53
  81. /** DHCP message option for the DHCP server IP. */
  82. #define DHCP_OPTION_SERVER_ID 54
  83. /** DHCP message option for the list of required options from the server. */
  84. #define DHCP_OPTION_REQ_LIST 55
  85. /** DHCP message option for the options list terminator. */
  86. #define DHCP_OPTION_END 255
  87. /* Type Defines: */
  88. /** Type define for a DHCP packet inside an Ethernet frame. */
  89. typedef struct
  90. {
  91. uint8_t Operation; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */
  92. uint8_t HardwareType; /**< Hardware carrier type constant */
  93. uint8_t HardwareAddressLength; /**< Length in bytes of a hardware (MAC) address on the network */
  94. uint8_t Hops; /**< Number of hops required to reach the server, unused */
  95. uint32_t TransactionID; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
  96. uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */
  97. uint16_t Flags; /**< BOOTP packet flags */
  98. uip_ipaddr_t ClientIP; /**< Client IP address, if already leased an IP */
  99. uip_ipaddr_t YourIP; /**< Client IP address */
  100. uip_ipaddr_t NextServerIP; /**< Legacy BOOTP protocol field, unused for DHCP */
  101. uip_ipaddr_t RelayAgentIP; /**< Legacy BOOTP protocol field, unused for DHCP */
  102. uint8_t ClientHardwareAddress[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */
  103. uint8_t ServerHostnameString[64]; /**< Legacy BOOTP protocol field, unused for DHCP */
  104. uint8_t BootFileName[128]; /**< Legacy BOOTP protocol field, unused for DHCP */
  105. uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */
  106. uint8_t Options[]; /**< DHCP message options */
  107. } DHCP_Header_t;
  108. /* Function Prototypes: */
  109. uint8_t DHCPCommon_SetOption(uint8_t* DHCPOptionList,
  110. const uint8_t Option,
  111. const uint8_t DataLen,
  112. void* const OptionData);
  113. bool DHCPCommon_GetOption(const uint8_t* DHCPOptionList,
  114. const uint8_t Option,
  115. void* const Destination);
  116. #endif