data_broadcast_id_descriptor.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #ifndef _UCSI_DVB_DATA_BROADCAST_ID_DESCRIPTOR
  22. #define _UCSI_DVB_DATA_BROADCAST_ID_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * Possible values for data_broadcast_id.
  31. */
  32. enum {
  33. DVB_BROADCAST_ID_DATA_PIPE = 0X0001,
  34. DVB_BROADCAST_ID_ASYNCHRONOUS_DATA_STREAM = 0X0002,
  35. DVB_BROADCAST_ID_SYNCHRONOUS_DATA_STREAM = 0X0003,
  36. DVB_BROADCAST_ID_SYNCHRONISED_DATA_STREAM = 0X0004,
  37. DVB_BROADCAST_ID_MULTI_PROTOCOL_ENCAPSULATION = 0X0005,
  38. DVB_BROADCAST_ID_DATA_CAROUSEL = 0X0006,
  39. DVB_BROADCAST_ID_OBJECT_CAROUSEL = 0X0007,
  40. DVB_BROADCAST_ID_DVB_ATM_STREAMS = 0X0008,
  41. DVB_BROADCAST_ID_HIGHER_PROTOCOLS = 0X0009,
  42. DVB_BROADCAST_ID_SOFTWARE_UPDATE = 0x000A,
  43. DVB_BROADCAST_ID_IP_MAC_NOTIFICATION_TABLE = 0x000B,
  44. };
  45. /**
  46. * dvb_data_broadcast_id_descriptor structure.
  47. */
  48. struct dvb_data_broadcast_id_descriptor {
  49. struct descriptor d;
  50. uint16_t data_broadcast_id;
  51. /* uint8_t id_selector_byte[] */
  52. } __ucsi_packed;
  53. /**
  54. * id_selector_byte for 0x000b data_broadcast_id (IP/MAC Notification Table).
  55. */
  56. struct dvb_id_selector_byte_000b {
  57. uint8_t platform_id_data_length;
  58. /* struct dvb_ip_mac_notification_info infos[] */
  59. /* uint8_t private_data[] */
  60. } __ucsi_packed;
  61. /**
  62. * Entries in the infos field of a dvb_id_selector_byte_0b.
  63. */
  64. struct dvb_ip_mac_notification_info {
  65. EBIT2(uint32_t platform_id : 24; ,
  66. uint8_t action_type : 8; );
  67. EBIT3(uint8_t reserved : 2; ,
  68. uint8_t INT_versioning_flag : 1; ,
  69. uint8_t INT_version : 5; );
  70. } __ucsi_packed;
  71. /**
  72. * Process a dvb_data_broadcast_id_descriptor.
  73. *
  74. * @param d Generic descriptor structure.
  75. * @return dvb_data_broadcast_id_descriptor pointer, or NULL on error.
  76. */
  77. static inline struct dvb_data_broadcast_id_descriptor*
  78. dvb_data_broadcast_id_descriptor_codec(struct descriptor* d)
  79. {
  80. if (d->len < (sizeof(struct dvb_data_broadcast_id_descriptor) - 2))
  81. return NULL;
  82. bswap16((uint8_t*) d + 2);
  83. return (struct dvb_data_broadcast_id_descriptor*) d;
  84. }
  85. /**
  86. * Accessor for the selector_byte field of a dvb_data_broadcast_id_descriptor.
  87. *
  88. * @param d dvb_data_broadcast_id_descriptor pointer.
  89. * @return Pointer to the field.
  90. */
  91. static inline uint8_t *
  92. dvb_data_broadcast_id_descriptor_id_selector_byte(struct dvb_data_broadcast_id_descriptor *d)
  93. {
  94. return (uint8_t *) d + sizeof(struct dvb_data_broadcast_id_descriptor);
  95. }
  96. /**
  97. * Determine the length of the selector_byte field of a dvb_data_broadcast_id_descriptor.
  98. *
  99. * @param d dvb_data_broadcast_id_descriptor pointer.
  100. * @return Length of the field in bytes.
  101. */
  102. static inline int
  103. dvb_data_broadcast_id_descriptor_id_selector_byte_length(struct dvb_data_broadcast_id_descriptor *d)
  104. {
  105. return d->d.len - 2;
  106. }
  107. /**
  108. * Accessor for a dvb_id_selector_byte_000b pointer.
  109. *
  110. * @param d dvb_data_broadcast_id_descriptor pointer.
  111. * @return Pointer to the data field.
  112. */
  113. static inline struct dvb_id_selector_byte_000b *
  114. dvb_id_selector_byte_000b(struct dvb_data_broadcast_id_descriptor *d)
  115. {
  116. if (d->data_broadcast_id != DVB_BROADCAST_ID_IP_MAC_NOTIFICATION_TABLE)
  117. return NULL;
  118. return (struct dvb_id_selector_byte_000b *) dvb_data_broadcast_id_descriptor_id_selector_byte(d);
  119. }
  120. /**
  121. * Iterator for the dvb_ip_mac_notification_info field of a dvb_id_selector_byte_000b.
  122. *
  123. * @param id_selector_byte dvb_id_selector_byte_000b pointer.
  124. * @param pos Variable containing a pointer to the current dvb_ip_mac_notification_info.
  125. */
  126. #define dvb_id_selector_byte_000b_ip_mac_notification_info_for_each(id_selector_byte, pos) \
  127. for ((pos) = dvb_ip_mac_notification_info_first(id_selector_byte); \
  128. (pos); \
  129. (pos) = dvb_ip_mac_notification_info_next(id_selector_byte, pos))
  130. /**
  131. * Length of the private_data field of a dvb_id_selector_byte_000b.
  132. *
  133. * @param d descriptor pointer.
  134. * @param i dvb_id_selector_byte_000b pointer.
  135. * @return Length of the field.
  136. */
  137. static inline uint8_t
  138. dvb_id_selector_byte_000b_private_data_length(struct descriptor *d,
  139. struct dvb_id_selector_byte_000b *i)
  140. {
  141. return (uint8_t) (d->len -
  142. sizeof(struct descriptor) -
  143. i->platform_id_data_length -
  144. sizeof(struct dvb_id_selector_byte_000b));
  145. }
  146. /**
  147. * Accessor for the private_data field of a dvb_id_selector_byte_000b.
  148. *
  149. * @param d descriptor pointer.
  150. * @param i dvb_id_selector_byte_000b pointer.
  151. * @return Pointer to the field.
  152. */
  153. static inline uint8_t *
  154. dvb_id_selector_byte_000b_private_data(struct descriptor *d,
  155. struct dvb_id_selector_byte_000b *i)
  156. {
  157. if (dvb_id_selector_byte_000b_private_data_length(d, i) <= 0)
  158. return NULL;
  159. return (uint8_t *) i + i->platform_id_data_length + sizeof(struct dvb_id_selector_byte_000b);
  160. }
  161. /******************************** PRIVATE CODE ********************************/
  162. static inline struct dvb_ip_mac_notification_info *
  163. dvb_ip_mac_notification_info_first(struct dvb_id_selector_byte_000b *d)
  164. {
  165. if (d->platform_id_data_length == 0)
  166. return NULL;
  167. bswap32((uint8_t *) d + sizeof(struct dvb_id_selector_byte_000b));
  168. return (struct dvb_ip_mac_notification_info *) ((uint8_t *) d + sizeof(struct dvb_id_selector_byte_000b));
  169. }
  170. static inline struct dvb_ip_mac_notification_info *
  171. dvb_ip_mac_notification_info_next(struct dvb_id_selector_byte_000b *d,
  172. struct dvb_ip_mac_notification_info *pos)
  173. {
  174. uint8_t *end = (uint8_t *) d + d->platform_id_data_length;
  175. uint8_t *next = (uint8_t *) pos +
  176. sizeof(struct dvb_id_selector_byte_000b) +
  177. sizeof(struct dvb_ip_mac_notification_info);
  178. if (next >= end)
  179. return NULL;
  180. bswap32(next);
  181. return (struct dvb_ip_mac_notification_info *) next;
  182. }
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif
  187. #include <libucsi/dvb/mhp_data_broadcast_id_descriptor.h>