cell_frequency_link_descriptor.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_CELL_FREQUENCY_LINK_DESCRIPTOR
  22. #define _UCSI_DVB_CELL_FREQUENCY_LINK_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * dvb_cell_frequency_link_descriptor structure.
  31. */
  32. struct dvb_cell_frequency_link_descriptor {
  33. struct descriptor d;
  34. /* struct dvb_cell_frequency_link_cell cells[] */
  35. } __ucsi_packed;
  36. /**
  37. * An entry in the cells field of a dvb_cell_frequency_link_descriptor.
  38. */
  39. struct dvb_cell_frequency_link_cell {
  40. uint16_t cell_id;
  41. uint32_t frequency;
  42. uint8_t subcell_loop_info_length;
  43. /* struct dvb_cell_frequency_link_subcell subcells[] */
  44. } __ucsi_packed;
  45. /**
  46. * An entry in the subcells field of a dvb_cell_frequency_link_cell.
  47. */
  48. struct dvb_cell_frequency_link_cell_subcell {
  49. uint8_t cell_id_extension;
  50. uint32_t transposer_frequency;
  51. } __ucsi_packed;
  52. /**
  53. * Process a dvb_cell_frequency_link_descriptor.
  54. *
  55. * @param d Generic descriptor pointer.
  56. * @return dvb_cell_frequency_link_descriptor pointer, or NULL on error.
  57. */
  58. static inline struct dvb_cell_frequency_link_descriptor*
  59. dvb_cell_frequency_link_descriptor_codec(struct descriptor* d)
  60. {
  61. uint32_t pos = 0;
  62. uint32_t pos2 = 0;
  63. uint8_t* buf = (uint8_t*) d + 2;
  64. uint32_t len = d->len;
  65. while(pos < len) {
  66. struct dvb_cell_frequency_link_cell *e =
  67. (struct dvb_cell_frequency_link_cell*) (buf+pos);
  68. if ((pos + sizeof(struct dvb_cell_frequency_link_cell)) > len)
  69. return NULL;
  70. bswap16(buf+pos);
  71. bswap32(buf+pos+2);
  72. pos += sizeof(struct dvb_cell_frequency_link_cell);
  73. if ((pos + e->subcell_loop_info_length) > len)
  74. return NULL;
  75. if (e->subcell_loop_info_length % sizeof(struct dvb_cell_frequency_link_cell_subcell))
  76. return NULL;
  77. pos2 = 0;
  78. while(pos2 < e->subcell_loop_info_length) {
  79. bswap32(buf+pos+pos2+1);
  80. pos2 += sizeof(struct dvb_cell_frequency_link_cell_subcell);
  81. }
  82. pos += e->subcell_loop_info_length;
  83. }
  84. return (struct dvb_cell_frequency_link_descriptor*) d;
  85. }
  86. /**
  87. * Iterator for the cells field of a dvb_cell_frequency_link_descriptor.
  88. *
  89. * @param d dvb_cell_frequency_link_descriptor pointer.
  90. * @param pos Variable holding a pointer to the current dvb_cell_frequency_link_cell.
  91. */
  92. #define dvb_cell_frequency_link_descriptor_cells_for_each(d, pos) \
  93. for ((pos) = dvb_cell_frequency_link_descriptor_cells_first(d); \
  94. (pos); \
  95. (pos) = dvb_cell_frequency_link_descriptor_cells_next(d, pos))
  96. /**
  97. * Iterator for the subcells field of a dvb_cell_frequency_link_cell.
  98. *
  99. * @param cell dvb_cell_frequency_link_cell pointer.
  100. * @param pos Variable holding a pointer to the current dvb_cell_frequency_link_cell_subcell.
  101. */
  102. #define dvb_cell_frequency_link_cell_subcells_for_each(cell, pos) \
  103. for ((pos) = dvb_cell_frequency_link_cell_subcells_first(cell); \
  104. (pos); \
  105. (pos) = dvb_cell_frequency_link_cell_subcells_next(cell, pos))
  106. /******************************** PRIVATE CODE ********************************/
  107. static inline struct dvb_cell_frequency_link_cell*
  108. dvb_cell_frequency_link_descriptor_cells_first(struct dvb_cell_frequency_link_descriptor *d)
  109. {
  110. if (d->d.len == 0)
  111. return NULL;
  112. return (struct dvb_cell_frequency_link_cell *)
  113. ((uint8_t*) d + sizeof(struct dvb_cell_frequency_link_descriptor));
  114. }
  115. static inline struct dvb_cell_frequency_link_cell*
  116. dvb_cell_frequency_link_descriptor_cells_next(struct dvb_cell_frequency_link_descriptor *d,
  117. struct dvb_cell_frequency_link_cell *pos)
  118. {
  119. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  120. uint8_t *next = (uint8_t *) pos +
  121. sizeof(struct dvb_cell_frequency_link_cell) +
  122. pos->subcell_loop_info_length;
  123. if (next >= end)
  124. return NULL;
  125. return (struct dvb_cell_frequency_link_cell *) next;
  126. }
  127. static inline struct dvb_cell_frequency_link_cell_subcell*
  128. dvb_cell_frequency_link_cell_subcells_first(struct dvb_cell_frequency_link_cell *d)
  129. {
  130. if (d->subcell_loop_info_length == 0)
  131. return NULL;
  132. return (struct dvb_cell_frequency_link_cell_subcell*)
  133. ((uint8_t*) d + sizeof(struct dvb_cell_frequency_link_cell));
  134. }
  135. static inline struct dvb_cell_frequency_link_cell_subcell*
  136. dvb_cell_frequency_link_cell_subcells_next(struct dvb_cell_frequency_link_cell *cell,
  137. struct dvb_cell_frequency_link_cell_subcell *pos)
  138. {
  139. uint8_t *end = (uint8_t*) cell + cell->subcell_loop_info_length;
  140. uint8_t *next = (uint8_t*) pos +
  141. sizeof(struct dvb_cell_frequency_link_cell_subcell);
  142. if (next >= end)
  143. return NULL;
  144. return (struct dvb_cell_frequency_link_cell_subcell *) next;
  145. }
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif