igmp.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #ifndef _NETINET_IGMP_H_
  2. #define _NETINET_IGMP_H_
  3. /*
  4. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Copyright (c) 1988 Stephen Deering.
  36. * Copyright (c) 1992, 1993
  37. * The Regents of the University of California. All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. * 1. Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * 2. Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in the
  46. * documentation and/or other materials provided with the distribution.
  47. * 3. Neither the name of the University nor the names of its contributors
  48. * may be used to endorse or promote products derived from this software
  49. * without specific prior written permission.
  50. *
  51. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  52. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  55. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  56. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  57. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  58. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  59. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  60. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  61. * SUCH DAMAGE.
  62. */
  63. /*
  64. * $Log$
  65. * Revision 1.3 2008/08/11 07:00:23 haraldkipp
  66. * BSD types replaced by stdint types (feature request #1282721).
  67. *
  68. * Revision 1.2 2007/08/29 07:43:54 haraldkipp
  69. * Documentation updated and corrected.
  70. *
  71. * Revision 1.1 2007/05/02 11:18:32 haraldkipp
  72. * IGMP support added. Incomplete.
  73. *
  74. */
  75. #include <sys/types.h>
  76. #include <dev/netbuf.h>
  77. #include <net/if_var.h>
  78. /*!
  79. * \file netinet/igmp.h
  80. * \brief IGMP protocol definitions.
  81. */
  82. /*!
  83. * \addtogroup xgIGMP
  84. */
  85. /*@{*/
  86. /*!
  87. * \typedef IGMP
  88. * \brief IGMP packet type.
  89. */
  90. typedef struct NUT_PACKED_TYPE igmp IGMP;
  91. typedef struct NUT_PACKED_TYPE igmp_report IGMP_REPORT;
  92. /*!
  93. * \struct igmp igmp.h netinet/igmp.h
  94. * \brief IGMP packet structure.
  95. */
  96. struct NUT_PACKED_TYPE igmp
  97. {
  98. uint8_t igmp_type; /*!< \brief Version and type of IGMP message. */
  99. uint8_t igmp_code; /*!< \brief Subtype for routing messages. */
  100. uint16_t igmp_cksum; /*!< \brief IP-style checksum. */
  101. uint32_t igmp_group; /*!< \brief Group address being reported. */
  102. };
  103. /*!
  104. * \brief IGMPv3 query format
  105. */
  106. struct NUT_PACKED_TYPE igmpv3 {
  107. uint8_t igmp_type; /*!< \brief Version and type of IGMP message. */
  108. uint8_t igmp_code; /*!< \brief Subtype for routing messages. */
  109. uint16_t igmp_cksum; /*!< \brief IP-style checksum. */
  110. uint32_t igmp_group; /*!< \brief Group address being reported. */
  111. uint8_t igmp_misc; /*!< \brief Reserved, supress and robustness var. */
  112. uint8_t igmp_qqi; /*!< \brief Querier's query interval. */
  113. uint16_t igmp_numsrc; /*!< \brief Number of sources. */
  114. uint32_t igmp_sources[1]; /*!< \brief Source addresses. */
  115. };
  116. /*!
  117. * \brief IGMPv3 group record.
  118. */
  119. struct NUT_PACKED_TYPE igmp_grouprec {
  120. uint8_t ig_type; /*!< \brief Record type. */
  121. uint8_t ig_datalen; /*!< \brief Amount of aux data. */
  122. uint16_t ig_numsrc; /*!< \brief Number of sources. */
  123. uint32_t ig_group; /*!< \brief The group being reported. */
  124. uint32_t ig_sources[1]; /*!< \brief Source addresses. */
  125. };
  126. /*!
  127. * \brief IGMPv3 report.
  128. */
  129. struct NUT_PACKED_TYPE igmp_report {
  130. uint8_t ir_type; /*!< \brief Record type. */
  131. uint8_t ir_rsv1; /*!< \brief Reserved. */
  132. uint16_t ir_cksum; /*!< \brief Checksum. */
  133. uint16_t ir_rsv2; /*!< \brief Reserved. */
  134. uint16_t ir_numgrps; /*!< \brief Number of group records. */
  135. struct igmp_grouprec ir_groups[1]; /*!< \brief Group records. */
  136. };
  137. /*!
  138. * \brief Minimum IGMP packet length.
  139. */
  140. #define IGMP_MINLEN 8
  141. #define IGMP_MEMBERSHIP_QUERY 0x11 /*!< \brief Membership query. */
  142. #define IGMP_V1_MEMBERSHIP_REPORT 0x12 /*!< \brief Ver. 1 membership report. */
  143. #define IGMP_V2_MEMBERSHIP_REPORT 0x16 /*!< \brief Ver. 2 membership report. */
  144. #define IGMP_V3_MEMBERSHIP_REPORT 0x22 /*!< \brief Ver. 3 membership report. */
  145. #define IGMP_V2_LEAVE_GROUP 0x17 /*!< \brief Leave-group message. */
  146. /*!
  147. * \brief Maximum delay for response query.
  148. */
  149. #define IGMP_MAX_HOST_REPORT_DELAY 10
  150. /*!
  151. * \brief Code field time scale.
  152. */
  153. #define IGMP_TIMER_SCALE 10
  154. /*!
  155. * \name IGMPv3 Report Types
  156. */
  157. /*@{*/
  158. #define IGMP_REPORT_MODE_IN 1 /*!< \brief Mode-is-include. */
  159. #define IGMP_REPORT_MODE_EX 2 /*!< \brief Mode-is-exclude. */
  160. #define IGMP_REPORT_TO_IN 3 /*!< \brief Change-to-include. */
  161. #define IGMP_REPORT_TO_EX 4 /*!< \brief Change-to-exclude. */
  162. #define IGMP_REPORT_ALLOW_NEW 5 /*!< \brief Allow-new-sources. */
  163. #define IGMP_REPORT_BLOCK_OLD 6 /*!< \brief Block-old-sources. */
  164. /*@}*/
  165. /*!
  166. * \name IGMPv3 Report Type Flags
  167. */
  168. /*@{*/
  169. #define IGMP_MASK_CUR_STATE 0x01 /*!< \brief Report current-state. */
  170. #define IGMP_MASK_ALLOW_NEW 0x02 /*!< \brief Report source as allow-new. */
  171. #define IGMP_MASK_BLOCK_OLD 0x04 /*!< \brief Report source as block-old. */
  172. #define IGMP_MASK_TO_IN 0x08 /*!< \brief Report source as to_in. */
  173. #define IGMP_MASK_TO_EX 0x10 /*!< \brief Report source as to_ex. */
  174. #define IGMP_MASK_STATE_T1 0x20 /*!< \brief State at T1. */
  175. #define IGMP_MASK_STATE_T2 0x40 /*!< \brief State at T2. */
  176. #define IGMP_MASK_IF_STATE 0x80 /*!< \brief Report current-state per interface. */
  177. #define IGMP_MASK_STATE_TX (IGMP_MASK_STATE_T1 | IGMP_MASK_STATE_T2)
  178. #define IGMP_MASK_PENDING (IGMP_MASK_CUR_STATE | IGMP_MASK_ALLOW_NEW | IGMP_MASK_BLOCK_OLD)
  179. /*@}*/
  180. /*!
  181. * \brief List identifiers
  182. */
  183. #define IGMP_EXCLUDE_LIST 1 /* Exclude list used to tag report. */
  184. #define IGMP_INCLUDE_LIST 2 /* Include list used to tag report. */
  185. #define IGMP_RECORDED_LIST 3 /* Recorded list used to tag report. */
  186. extern void NutIgmpInput(NUTDEVICE * dev, NETBUF * nb);
  187. extern int NutIgmpOutput(uint8_t type, uint32_t dest, NETBUF * nb);
  188. extern void NutIgmpJoinGroup(NUTDEVICE *dev, uint32_t ip_addr);
  189. extern void NutIgmpLeaveGroup(NUTDEVICE *dev, uint32_t ip_addr);
  190. /*@}*/
  191. #endif