DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
getModuleInfo_include_src.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  * Copyright © 2001 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
29 /*
30 -- getpModuleInfo_source - Common Code
31 --
32 -- Get module info from module info descriptor in DII message (compatible with
33 -- contiguous or managed/MemSeq memory)
34 --
35 -- Uses/assumes the following vars:
36 -- valid, mpModuleInfoDescStart, *pModuleInfo
37 --
38 -- mpModuleInfoDescStart references ('points' to) first byte of module info
39 -- descriptor, valid (BOOLEAN) indicates whether module info was valid
40 --
41 -- mpModuleInfoDescStart = const pUInt8/MemSeqRef,
42 -- pModuleInfo = P_ModuleInfo
43 -- valid = BOOLEAN
44 --
45 -- NB. Only DVB (UK Profile 1) spec. currently implemented
46 */
47 
48 {
49  MemPtr mpModuleInfoDesc;
50  U8BIT tapsCount;
51  U8BIT infoLength;
52  MemPos currPos, endPos;
53  U8BIT descriptorTag;
54  U8BIT descriptorLength;
55  U8BIT ui8 = 0;
56  U16BIT ui16 = 0;
57 
58  dsmAssert((mpModuleInfoDescStart != NULL));
59  dsmAssert((pModuleInfo != NULL));
60 
61  /* -- Open MemPtr for accessing module descriptor info */
62  MEMPTR_OPEN( mpModuleInfoDescStart, mpModuleInfoDesc );
63 
64  /* -- Read moduleId */
65  READ_UINT16( mpModuleInfoDesc, pModuleInfo->moduleId );
66 
67  /* -- Read moduleSize */
68  READ_UINT32( mpModuleInfoDesc, pModuleInfo->moduleSize );
69  if ( pModuleInfo->moduleSize == 0 )
70  {
71  /* 0 length modules are not useful! */
72  dsmDP2(("DATA ERROR: Zero module size\n"));
73  valid = FALSE;
74  }
75  else
76  {
77  #ifndef NDEBUG
78  /* Initialise debug monitor flag */
79  pModuleInfo->blkRcvd = 0;
80  #endif
81 
82  /* -- Read moduleVersion */
83  READ_UINT8( mpModuleInfoDesc, pModuleInfo->version );
84 
85  /* -- Initialise module compression info */
86  pModuleInfo->compressed = FALSE;
87  pModuleInfo->originalSize = pModuleInfo->moduleSize;
88 
89  if ( pModuleInfo->crslMagic == OC_MAGIC )
90  {
91  /* -- Skip pModuleInfoLength */
92  SET_POS_REL( mpModuleInfoDesc, 1 );
93 
94  /* -- mpModuleInfoDesc -> BIOP::pModuleInfo */
95  /* -- Read moduleTimeOut */
96  READ_UINT32( mpModuleInfoDesc, pModuleInfo->u.mhgp.moduleTimeout );
97 
98  /* -- Read blockTimeOut */
99  READ_UINT32( mpModuleInfoDesc, pModuleInfo->u.mhgp.blockTimeout );
100 
101  /* -- Read minBlockTime */
102  READ_UINT32( mpModuleInfoDesc, pModuleInfo->u.mhgp.minBlockTime );
103 
104  /* -- Read/check tapsCount >= 1 (DVB) */
105  /* -- L1 check because this should be correct */
106  READ_UINT8( mpModuleInfoDesc, tapsCount );
107  if ( !tapsCount )
108  {
109  dsmDP2(("DATA ERROR: Module info tapsCount zero\n"));
110  valid = FALSE;
111  }
112  else
113  {
114  /* -- mpModuleInfoDesc -> start of first BIOP::Tap */
115  /* -- Read info from first Tap */
116  /* -- Read tapId - TODO: Not required ? */
117  READ_UINT16( mpModuleInfoDesc, pModuleInfo->u.mhgp.tapBiopId );
118 
119  /* -- tapUse = BIOP_OBJECT_USE (in BIOP::pModuleInfoMessage - DVB/UK DTT) */
120  /* -- L0 check because this must be correct */
121  READ_UINT16( mpModuleInfoDesc, ui16 );
122  if (ui16 != BIOP_OBJECT_USE)
123  {
124  dsmDP2(("DATA ERROR: Module info 1st tapUse (!= BIOP_OBJECT_USE) = %u\n", ui16));
125  valid = FALSE;
126  }
127  else
128  {
129  /* -- Read associationTag */
130  READ_UINT16( mpModuleInfoDesc, pModuleInfo->associationTag );
131 
132  /* -- selectorLength = 0 (DVB/UK DTT) */
133  READ_UINT8( mpModuleInfoDesc, ui8 );
134  if (ui8 != 0x00)
135  {
136  dsmDP2(("DATA ERROR: Module info tap selectorLength (!= 0) = %u\n", ui8));
137  valid = FALSE;
138  }
139  else
140  {
141  valid = TRUE;
142 
143  /* -- Skip any remaining Taps */
144  while (--tapsCount > 0)
145  {
146  /* -- Skip tapId, tapUse, associationTag */
147  SET_POS_REL( mpModuleInfoDesc, 6 );
148  /* -- Read selectorLength */
149  READ_UINT8( mpModuleInfoDesc, ui8 );
150  /* -- Skip selector field */
151  SET_POS_REL( mpModuleInfoDesc, (S32BIT)ui8 );
152  }
153 
154  /* -- mpModuleInfoDesc -> infoLength */
155  /* -- Read infoLength */
156  READ_UINT8( mpModuleInfoDesc, infoLength );
157 
158  if (infoLength != 0)
159  {
160  /* -- Search module descriptor loop for compressed module descriptor */
161  /* -- Determine end position of search data */
162  GET_POS( mpModuleInfoDesc, currPos );
163  endPos = currPos + infoLength;
164  while (currPos < endPos)
165  {
166  /* -- mpModuleInfoDesc -> current module descriptor */
167 
168  /* -- Read descriptorTag */
169  READ_UINT8( mpModuleInfoDesc, descriptorTag );
170 
171  /* -- Read descriptorLength */
172  READ_UINT8( mpModuleInfoDesc, descriptorLength );
173 
174  switch (descriptorTag)
175  {
176  case DESCRIPTOR_COMP_MODULE_TAG:
177  /* -- compressionMethod LSNibble == 0x8 (DVB/RFC1950)*/
178  /* -- L1 check because this should be correct (subsequently
179  -- zlib inflate should also check compression method of
180  -- module data/stream before attempting to decompress) */
181  READ_UINT8( mpModuleInfoDesc, ui8 );
182  if ( (ui8 & 0x0f) != 0x08 )
183  {
184  dsmDP2(("DATA ERROR: Module info compressionMethod (!= 0x08) = %u\n", ui8));
185  SET_POS_REL( mpModuleInfoDesc, 4 );
186  }
187  else
188  {
189  /* -- Indicate module is compressed */
190  pModuleInfo->compressed = TRUE;
191  /* -- Read originalSize */
192  READ_UINT32( mpModuleInfoDesc, pModuleInfo->originalSize );
193  }
194  /* -- Found the required info so quit the loop */
195  break;
196 
197  case DESCRIPTOR_MHP_CACHING_PRIORITY:
198  /* TS 101 812, section B.2.2.4.2 Caching priority descriptor */
199  READ_UINT8( mpModuleInfoDesc, pModuleInfo->u.mhgp.priority );
200  READ_UINT8( mpModuleInfoDesc, pModuleInfo->u.mhgp.transparency );
201  break;
202 
203  default:
204  dsmDP2(("INFO: Module - Unknown descriptor tag: %x\n", descriptorTag));
205  /* -- Skip this module descriptor */
206  SET_POS_REL( mpModuleInfoDesc, (S32BIT)descriptorLength );
207  }
208  /* -- Find next (potential) descriptor start position */
209  GET_POS( mpModuleInfoDesc, currPos );
210  }
211  }
212  }
213  }
214  }
215  }
216 
217  else if ( pModuleInfo->crslMagic == UC_MAGIC )
218  {
219  valid = TRUE;
220  READ_UINT8( mpModuleInfoDesc, infoLength );
221  if (infoLength != 0)
222  {
223  GET_POS( mpModuleInfoDesc, currPos );
224  endPos = currPos + infoLength;
225  while (currPos < endPos)
226  {
227  READ_UINT8( mpModuleInfoDesc, descriptorTag );
228  READ_UINT8( mpModuleInfoDesc, descriptorLength );
229  switch (descriptorTag)
230  {
231  case DESCRIPTOR_TYPE_TAG:
232  {
233  pModuleInfo->u.ssup.typeLen = descriptorLength;
234  pModuleInfo->u.ssup.mpType = mpModuleInfoDesc;
235  break;
236  }
237  case DESCRIPTOR_NAME_TAG:
238  {
239  pModuleInfo->u.ssup.nameLen = descriptorLength;
240  pModuleInfo->u.ssup.mpName = mpModuleInfoDesc;
241  break;
242  }
243  case DESCRIPTOR_INFO_TAG:
244  {
245  if (descriptorLength > 3)
246  {
247  READ_UINT24( mpModuleInfoDesc, pModuleInfo->u.ssup.infoLang );
248  pModuleInfo->u.ssup.infoLen = descriptorLength - 3;
249  pModuleInfo->u.ssup.mpInfo = mpModuleInfoDesc;
250  }
251  break;
252  }
253  case DESCRIPTOR_MODULE_LINK_TAG:
254  {
255  READ_UINT8( mpModuleInfoDesc, ui8 );
256  READ_UINT16( mpModuleInfoDesc, pModuleInfo->u.ssup.nextModuleId );
257  pModuleInfo->u.ssup.positionType = ui8 + 1; /* increment so know received desc */
258  DBG3(DD_DC,"mod=%x module_link pos=%d, nxt=%x",
259  pModuleInfo->moduleId, ui8, pModuleInfo->u.ssup.nextModuleId )
260  break;
261  }
262  case DESCRIPTOR_CRC32_TAG:
263  {
264  READ_UINT32( mpModuleInfoDesc, pModuleInfo->u.ssup.moduleCrc );
265  break;
266  }
267  case DESCRIPTOR_LOCATION_TAG:
268  {
269  READ_UINT8( mpModuleInfoDesc, ui8 );
270  pModuleInfo->associationTag = ui8;
271  break;
272  }
273  case DESCRIPTOR_EST_DOWNLOAD_TIME_TAG:
274  {
275  break;
276  }
277  case DESCRIPTOR_COMP_MODULE_TAG:
278  {
279  READ_UINT8( mpModuleInfoDesc, ui8 );
280  if ( (ui8 & 0x0f) != 0x08 )
281  {
282  dsmDP2(("DATA ERROR: Module info compressionMethod (!= 0x08) = %u\n", ui8));
283  }
284  else
285  {
286  /* -- Indicate module is compressed */
287  pModuleInfo->compressed = TRUE;
288  /* -- Read originalSize */
289  READ_UINT32( mpModuleInfoDesc, pModuleInfo->originalSize );
290  }
291  break;
292  }
293  case DESCRIPTOR_SSU_MODULE_TYPE_TAG:
294  {
295  READ_UINT8( mpModuleInfoDesc, pModuleInfo->u.ssup.moduleType );
296  break;
297  }
298  default:
299  {
300  DBG2(DD_DC,"Module - Unknown descriptor tag: %x", descriptorTag);
301  break;
302  }
303  }
304  SET_POS_ABS( mpModuleInfoDesc, currPos + 2 + descriptorLength );
305  GET_POS( mpModuleInfoDesc, currPos );
306  }
307  }
308  }
309 
310  else
311  {
312  DBG2(DD_DC,"Module Info magic unknown =%x",pModuleInfo->crslMagic)
313  valid = FALSE;
314  }
315  }
316  MEMPTR_CLOSE( mpModuleInfoDesc );
317  DEBUG_CHK( valid == TRUE,
318  dsmDP1(("ERROR: getpModuleInfo failure (invalid)\n")));
319 }
320 
321 
322 /*----------------------------------------------------------------------------*/
323 
324 
325