int_section.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. * Copyright (C) 2005 Patrick Boettcher (pb@linuxtv.org)
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  21. */
  22. #ifndef _UCSI_DVB_INT_SECTION_H
  23. #define _UCSI_DVB_INT_SECTION_H
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #include <libucsi/section.h>
  29. /**
  30. * dvb_int_section structure - IP/MAC notification section.
  31. */
  32. struct dvb_int_section {
  33. struct section_ext head;
  34. EBIT2(uint32_t platform_id :24; ,
  35. uint32_t processing_order : 8; );
  36. EBIT2(uint16_t reserved2 : 4; ,
  37. uint16_t platform_descriptors_length :12; );
  38. /* struct descriptor platform_descriptors[] */
  39. /* struct dvb_int_target target_loop[] */
  40. } __ucsi_packed;
  41. /**
  42. * An entry in the target_loop field of a dvb_int_section.
  43. */
  44. struct dvb_int_target {
  45. EBIT2(uint16_t reserved3 : 4; ,
  46. uint16_t target_descriptors_length :12; );
  47. /* struct descriptor target_descriptors[] */
  48. /* struct dvb_int_operational_loop operational_loop */
  49. } __ucsi_packed;
  50. /**
  51. * The operational_loop field in a dvb_int_target.
  52. */
  53. struct dvb_int_operational_loop {
  54. EBIT2(uint16_t reserved4 : 4; ,
  55. uint16_t operational_descriptors_length :12; );
  56. /* struct descriptor operational_descriptors[] */
  57. } __ucsi_packed;
  58. /**
  59. * Process a dvb_int_section.
  60. *
  61. * @param section Generic section_ext pointer.
  62. * @return dvb_int_section pointer, or NULL on error.
  63. */
  64. extern struct dvb_int_section * dvb_int_section_codec(struct section_ext *section);
  65. /**
  66. * Accessor for the action_type field of an INT.
  67. *
  68. * @param intp INT pointer.
  69. * @return The action_type.
  70. */
  71. static inline uint8_t dvb_int_section_action_type(struct dvb_int_section *intp)
  72. {
  73. return intp->head.table_id_ext >> 8;
  74. }
  75. /**
  76. * Accessor for the platform_id_hash field of an INT.
  77. *
  78. * @param intp INT pointer.
  79. * @return The platform_id_hash.
  80. */
  81. static inline uint8_t dvb_int_section_platform_id_hash(struct dvb_int_section *intp)
  82. {
  83. return intp->head.table_id_ext & 0xff;
  84. }
  85. /**
  86. * Iterator for platform_descriptors field in a dvb_int_section.
  87. *
  88. * @param intp dvb_int_section pointer.
  89. * @param pos Variable holding a pointer to the current descriptor.
  90. */
  91. #define dvb_int_section_platform_descriptors_for_each(intp, pos) \
  92. for ((pos) = dvb_int_section_platform_descriptors_first(intp); \
  93. (pos); \
  94. (pos) = dvb_int_section_platform_descriptors_next(intp, pos))
  95. /**
  96. * Iterator for the target_loop field in a dvb_int_section.
  97. *
  98. * @param intp dvb_int_section pointer.
  99. * @param pos Variable holding a pointer to the current dvb_int_target.
  100. */
  101. #define dvb_int_section_target_loop_for_each(intp,pos) \
  102. for ((pos) = dvb_int_section_target_loop_first(intp); \
  103. (pos); \
  104. (pos) = dvb_int_section_target_loop_next(intp, pos))
  105. /**
  106. * Iterator for the target_descriptors field in a dvb_int_target.
  107. *
  108. * @param target dvb_int_target pointer.
  109. * @param pos Variable holding a pointer to the current descriptor.
  110. */
  111. #define dvb_int_target_target_descriptors_for_each(target, pos) \
  112. for ((pos) = dvb_int_target_target_descriptors_first(target); \
  113. (pos); \
  114. (pos) = dvb_int_target_target_descriptors_next(target, pos))
  115. /**
  116. * Accessor for the operational_loop field of a dvb_int_target.
  117. *
  118. * @param target dvb_int_target pointer.
  119. * @return Pointer to a dvb_int_operational_loop.
  120. */
  121. static inline struct dvb_int_operational_loop *
  122. dvb_int_target_operational_loop(struct dvb_int_target *target)
  123. {
  124. return (struct dvb_int_operational_loop *)
  125. ((uint8_t *) target + sizeof(struct dvb_int_target) + target->target_descriptors_length);
  126. }
  127. /**
  128. * Iterator for the operational_descriptors field in a dvb_int_operational_loop.
  129. *
  130. * @param oploop dvb_int_operational_loop pointer.
  131. * @param pos Variable holding a pointer to the current descriptor.
  132. */
  133. #define dvb_int_operational_loop_operational_descriptors_for_each(oploop, pos) \
  134. for ((pos) = dvb_int_operational_loop_operational_descriptors_first(oploop); \
  135. (pos); \
  136. (pos) = dvb_int_operational_loop_operational_descriptors_next(oploop, pos))
  137. /******************************** PRIVATE CODE ********************************/
  138. static inline struct descriptor *
  139. dvb_int_section_platform_descriptors_first(struct dvb_int_section *in)
  140. {
  141. if (in->platform_descriptors_length == 0)
  142. return NULL;
  143. return (struct descriptor *)
  144. ((uint8_t *) in + sizeof(struct dvb_int_section));
  145. }
  146. static inline struct descriptor *
  147. dvb_int_section_platform_descriptors_next(struct dvb_int_section *in,
  148. struct descriptor* pos)
  149. {
  150. return next_descriptor((uint8_t*) in + sizeof(struct dvb_int_section),
  151. in->platform_descriptors_length,
  152. pos);
  153. }
  154. static inline struct dvb_int_target *
  155. dvb_int_section_target_loop_first(struct dvb_int_section *in)
  156. {
  157. if (sizeof(struct dvb_int_section) + in->platform_descriptors_length >= (uint32_t) section_ext_length((struct section_ext *) in))
  158. return NULL;
  159. return (struct dvb_int_target *)
  160. ((uint8_t *) in + sizeof(struct dvb_int_section) + in->platform_descriptors_length);
  161. }
  162. static inline struct dvb_int_target *
  163. dvb_int_section_target_loop_next(struct dvb_int_section *in,
  164. struct dvb_int_target *pos)
  165. {
  166. struct dvb_int_operational_loop *ol = dvb_int_target_operational_loop(pos);
  167. struct dvb_int_target *next =
  168. (struct dvb_int_target *) ( (uint8_t *) pos +
  169. sizeof(struct dvb_int_target) + pos->target_descriptors_length +
  170. sizeof(struct dvb_int_operational_loop) + ol->operational_descriptors_length);
  171. struct dvb_int_target *end =
  172. (struct dvb_int_target *) ((uint8_t *) in + section_ext_length((struct section_ext *) in) );
  173. if (next >= end)
  174. return 0;
  175. return next;
  176. }
  177. static inline struct descriptor *
  178. dvb_int_target_target_descriptors_first(struct dvb_int_target *tl)
  179. {
  180. if (tl->target_descriptors_length == 0)
  181. return NULL;
  182. return (struct descriptor *)
  183. ((uint8_t *) tl + sizeof(struct dvb_int_target));
  184. }
  185. static inline struct descriptor *
  186. dvb_int_target_target_descriptors_next(struct dvb_int_target *tl,
  187. struct descriptor* pos)
  188. {
  189. return next_descriptor((uint8_t*) tl + sizeof(struct dvb_int_target),
  190. tl->target_descriptors_length,
  191. pos);
  192. }
  193. static inline struct descriptor *
  194. dvb_int_operational_loop_operational_descriptors_first(struct dvb_int_operational_loop *ol)
  195. {
  196. if (ol->operational_descriptors_length == 0)
  197. return NULL;
  198. return (struct descriptor *)
  199. ((uint8_t *) ol + sizeof(struct dvb_int_operational_loop));
  200. }
  201. static inline struct descriptor *
  202. dvb_int_operational_loop_operational_descriptors_next(struct dvb_int_operational_loop *ol,
  203. struct descriptor* pos)
  204. {
  205. return next_descriptor((uint8_t*) ol + sizeof(struct dvb_int_operational_loop),
  206. ol->operational_descriptors_length,
  207. pos);
  208. }
  209. #ifdef __cplusplus
  210. }
  211. #endif
  212. #endif