int_section.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <libucsi/dvb/int_section.h>
  23. struct dvb_int_section * dvb_int_section_codec(struct section_ext *ext)
  24. {
  25. uint8_t *buf = (uint8_t *) ext;
  26. struct dvb_int_section *in = (struct dvb_int_section *) ext;
  27. size_t pos = sizeof(struct section_ext);
  28. size_t len = section_ext_length(ext);
  29. if (len < sizeof(struct dvb_int_section))
  30. return NULL;
  31. bswap32(buf+8);
  32. bswap16(buf+12);
  33. pos += 6;
  34. if (len - pos < in->platform_descriptors_length)
  35. return NULL;
  36. if (verify_descriptors(buf + pos, in->platform_descriptors_length))
  37. return NULL;
  38. pos += in->platform_descriptors_length;
  39. while (pos < len) {
  40. struct dvb_int_target *s2 = (struct dvb_int_target *) (buf + pos);
  41. struct dvb_int_operational_loop *s3;
  42. bswap16(buf + pos); /* target_descriptor_loop_length swap */
  43. if (len - pos < s2->target_descriptors_length)
  44. return NULL;
  45. pos += sizeof(struct dvb_int_target);
  46. if (verify_descriptors(buf + pos, s2->target_descriptors_length))
  47. return NULL;
  48. pos += s2->target_descriptors_length;
  49. s3 = (struct dvb_int_operational_loop *) (buf + pos);
  50. bswap16(buf + pos); /* operational_descriptor_loop_length swap */
  51. if (len - pos < s3->operational_descriptors_length)
  52. return NULL;
  53. pos += sizeof(struct dvb_int_operational_loop);
  54. if (verify_descriptors(buf + pos, s3->operational_descriptors_length))
  55. return NULL;
  56. pos += s3->operational_descriptors_length;
  57. }
  58. return (struct dvb_int_section *) ext;
  59. }