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.

IP.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 IP.c.
  29. */
  30. #ifndef _IP_H_
  31. #define _IP_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. #include "Config/AppConfig.h"
  39. /* Macros: */
  40. /** Protocol IP address of the broadcast address. */
  41. #define BROADCAST_IP_ADDRESS {0xFF, 0xFF, 0xFF, 0xFF}
  42. /** Default Time To Live (TTL) value for sent packets, indicating the maximum allowable hops until their destination
  43. * is reached.
  44. */
  45. #define DEFAULT_TTL 128
  46. /** Performs a comparison between two IP addresses, indicating if they are identical.
  47. *
  48. * \param[in] IP1 First IP address
  49. * \param[in] IP2 Second IP address
  50. *
  51. * \return True if the addresses match, \c false otherwise
  52. */
  53. #define IP_COMPARE(IP1, IP2) (memcmp(IP1, IP2, sizeof(IP_Address_t)) == 0)
  54. /* Type Defines: */
  55. /** Type define of an IP packet header. */
  56. typedef struct
  57. {
  58. unsigned HeaderLength : 4; /**< Total length of the packet header, in 4-byte blocks */
  59. unsigned Version : 4; /**< IP protocol version */
  60. uint8_t TypeOfService; /**< Special service type identifier, indicating delay/throughput/reliability levels */
  61. uint16_t TotalLength; /**< Total length of the IP packet, in bytes */
  62. uint16_t Identification; /**< Identification value for identifying fragmented packets */
  63. unsigned FragmentOffset : 13; /**< Offset of this IP fragment */
  64. unsigned Flags : 3; /**< Fragment flags, to indicate if a packet is fragmented */
  65. uint8_t TTL; /**< Maximum allowable number of hops to reach the packet destination */
  66. uint8_t Protocol; /**< Encapsulated protocol type */
  67. uint16_t HeaderChecksum; /**< Ethernet checksum of the IP header */
  68. IP_Address_t SourceAddress; /**< Source protocol IP address of the packet */
  69. IP_Address_t DestinationAddress; /**< Destination protocol IP address of the packet */
  70. } IP_Header_t;
  71. /* Function Prototypes: */
  72. int16_t IP_ProcessIPPacket(Ethernet_Frame_Info_t* const FrameIN,
  73. void* InDataStart,
  74. void* OutDataStart);
  75. #endif