telephone_descriptor.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_TELEPHONE_DESCRIPTOR
  22. #define _UCSI_DVB_TELEPHONE_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * dvb_telephone_descriptor stucture.
  31. */
  32. struct dvb_telephone_descriptor {
  33. struct descriptor d;
  34. EBIT3(uint8_t reserved_1 : 2; ,
  35. uint8_t foreign_availability : 1; ,
  36. uint8_t connection_type : 5; );
  37. EBIT4(uint8_t reserved_2 : 1; ,
  38. uint8_t country_prefix_length : 2; ,
  39. uint8_t international_area_code_length : 3; ,
  40. uint8_t operator_code_length : 2; );
  41. EBIT3(uint8_t reserved_3 : 1; ,
  42. uint8_t national_area_code_length : 3; ,
  43. uint8_t core_number_length : 4; );
  44. /* uint8_t country_prefix[] */
  45. /* uint8_t international_area_code[] */
  46. /* uint8_t operator_code[] */
  47. /* uint8_t national_area_code[] */
  48. /* uint8_t core_number[] */
  49. } __ucsi_packed;
  50. /**
  51. * Process a dvb_telephone_descriptor.
  52. *
  53. * @param d Generic descriptor.
  54. * @return dvb_telephone_descriptor pointer, or NULL on error.
  55. */
  56. static inline struct dvb_telephone_descriptor*
  57. dvb_telephone_descriptor_codec(struct descriptor* d)
  58. {
  59. struct dvb_telephone_descriptor* p =
  60. (struct dvb_telephone_descriptor*) d;
  61. uint32_t pos = sizeof(struct dvb_telephone_descriptor) - 2;
  62. uint32_t len = d->len;
  63. if (pos > len)
  64. return NULL;
  65. pos += p->country_prefix_length +
  66. p->international_area_code_length +
  67. p->operator_code_length +
  68. p->national_area_code_length +
  69. p->core_number_length;
  70. if (pos != len)
  71. return NULL;
  72. return p;
  73. }
  74. /**
  75. * Retrieve pointer to country_prefix field of a dvb_telephone_descriptor.
  76. *
  77. * @param d dvb_telephone_descriptor pointer.
  78. * @return Pointer to the field.
  79. */
  80. static inline uint8_t*
  81. dvb_telephone_descriptor_country_prefix(struct dvb_telephone_descriptor* d)
  82. {
  83. return (uint8_t*) d + sizeof(struct dvb_telephone_descriptor);
  84. }
  85. /**
  86. * Retrieve pointer to international_area_code field of a dvb_telephone_descriptor.
  87. *
  88. * @param d dvb_telephone_descriptor pointer.
  89. * @return Pointer to the field.
  90. */
  91. static inline uint8_t*
  92. dvb_telephone_descriptor_international_area_code(struct dvb_telephone_descriptor* d)
  93. {
  94. return dvb_telephone_descriptor_country_prefix(d) + d->country_prefix_length;
  95. }
  96. /**
  97. * Retrieve pointer to operator_code field of a dvb_telephone_descriptor.
  98. *
  99. * @param d dvb_telephone_descriptor pointer.
  100. * @return Pointer to the field.
  101. */
  102. static inline uint8_t*
  103. dvb_telephone_descriptor_operator_code(struct dvb_telephone_descriptor* d)
  104. {
  105. return dvb_telephone_descriptor_international_area_code(d) + d->international_area_code_length;
  106. }
  107. /**
  108. * Retrieve pointer to national_area_code field of a dvb_telephone_descriptor.
  109. *
  110. * @param d dvb_telephone_descriptor pointer.
  111. * @return Pointer to the field.
  112. */
  113. static inline uint8_t*
  114. dvb_telephone_descriptor_national_area_code(struct dvb_telephone_descriptor* d)
  115. {
  116. return dvb_telephone_descriptor_operator_code(d) + d->operator_code_length;
  117. }
  118. /**
  119. * Retrieve pointer to core_number field of a dvb_telephone_descriptor.
  120. *
  121. * @param d dvb_telephone_descriptor pointer.
  122. * @return Pointer to the field.
  123. */
  124. static inline uint8_t*
  125. dvb_telephone_descriptor_core_number(struct dvb_telephone_descriptor* d)
  126. {
  127. return dvb_telephone_descriptor_national_area_code(d) + d->national_area_code_length;
  128. }
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif