dcct_section.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include <libucsi/atsc/dcct_section.h>
  22. struct atsc_dcct_section *atsc_dcct_section_codec(struct atsc_section_psip *psip)
  23. {
  24. uint8_t * buf = (uint8_t *) psip;
  25. size_t pos = 0;
  26. size_t len = section_ext_length(&(psip->ext_head));
  27. int testidx;
  28. int termidx;
  29. if (len < sizeof(struct atsc_dcct_section))
  30. return NULL;
  31. struct atsc_dcct_section *dcct = (struct atsc_dcct_section *) psip;
  32. pos += sizeof(struct atsc_dcct_section);
  33. for(testidx =0; testidx < dcct->dcc_test_count; testidx++) {
  34. if (len < (pos + sizeof(struct atsc_dcct_test)))
  35. return NULL;
  36. struct atsc_dcct_test *test = (struct atsc_dcct_test *) (buf+pos);
  37. bswap24(buf+pos);
  38. bswap24(buf+pos+3);
  39. bswap32(buf+pos+6);
  40. bswap32(buf+pos+10);
  41. pos += sizeof(struct atsc_dcct_test);
  42. for(termidx =0; termidx < test->dcc_term_count; termidx++) {
  43. if (len < (pos + sizeof(struct atsc_dcct_term)))
  44. return NULL;
  45. struct atsc_dcct_term *term = (struct atsc_dcct_term *) (buf+pos);
  46. bswap64(buf+pos+1);
  47. bswap16(buf+pos+9);
  48. pos += sizeof(struct atsc_dcct_term);
  49. if (len < (pos + term->descriptors_length))
  50. return NULL;
  51. if (verify_descriptors(buf + pos, term->descriptors_length))
  52. return NULL;
  53. pos += term->descriptors_length;
  54. }
  55. if (len < (pos + sizeof(struct atsc_dcct_test_part2)))
  56. return NULL;
  57. struct atsc_dcct_test_part2 *part2 = (struct atsc_dcct_test_part2 *) (buf+pos);
  58. bswap16(buf+pos);
  59. pos += sizeof(struct atsc_dcct_test_part2);
  60. if (len < (pos + part2->descriptors_length))
  61. return NULL;
  62. if (verify_descriptors(buf + pos, part2->descriptors_length))
  63. return NULL;
  64. pos += part2->descriptors_length;
  65. }
  66. if (len < (pos + sizeof(struct atsc_dcct_section_part2)))
  67. return NULL;
  68. struct atsc_dcct_section_part2 *part2 = (struct atsc_dcct_section_part2 *) (buf+pos);
  69. bswap16(buf+pos);
  70. pos += sizeof(struct atsc_dcct_section_part2);
  71. if (len < (pos + part2->descriptors_length))
  72. return NULL;
  73. if (verify_descriptors(buf + pos, part2->descriptors_length))
  74. return NULL;
  75. pos += part2->descriptors_length;
  76. if (pos != len)
  77. return NULL;
  78. return (struct atsc_dcct_section *) psip;
  79. }