DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
clDsmUtils.c
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  *******************************************************************************/
26 /*---includes for this file--------------------------------------------------*/
27 #include "clDsmSystem.h"
28 #include "clDsmUtils.h"
29 
30 #include "cacheMgr.h"
31 
32 /* Include function to calculate CRC */
33 #include "calculateCRC.h"
34 
35 /*------------------------------- Local Macros -------------------------------*/
36 
37 #define SYSTEM_HARDWARE_DESC 0x01
38 #define SYSTEM_SOFTWARE_DESC 0x02
39 
40 /*------------------------------ Exported Data -----------------------------*/
41 
42 
43 /*--------------------------------Local Types --------------------------------*/
44 
45 
46 /*------------------------------- Local Statics ------------------------------*/
47 
48 
49 /*------------------- local prototypes/forward declarations ------------------*/
50 
51 
52 /*---------------------------- Exported Functions ----------------------------*/
53 
54 /* -- GENERAL UTILITIES */
55 
56 /*
57 -- Convert DSM-CC object kind to internal object kind
58 */
59 E_DsmObjectKind convertObjectKindStr( U32BIT objectKindStr )
60 {
61  E_DsmObjectKind kind;
62 
63  switch (objectKindStr)
64  {
65  case SRG_STR:
66  kind = SERVICE_GATEWAY_OBJ;
67  break;
68  case DIR_STR:
69  kind = DIRECTORY_OBJ;
70  break;
71  case FIL_STR:
72  kind = FILE_OBJ;
73  break;
74  case STR_STR:
75  kind = STREAM_OBJ;
76  break;
77  case STE_STR:
78  kind = STREAM_OBJ_WITH_EVENTS;
79  break;
80  default:
81  kind = ANON_OBJ;
82  break;
83  }
84  return(kind);
85 }
86 
87 /* /////////////////////////////////////////////////////////////////////////////
88 // handleInLoopError
89 //
90 // Notify any system or internal (ie. fatal) errors via errorFunc callback.
91 //
92 // Set error return value for an internal error and set it for a system error
93 // if one is not currently set.
94 //
95 // Don't notify CLDSM_ERR_MEM_HEAP_FULL or CLDSM_ERR_SECTION_FILTER_HEAP_FULL
96 // in since it may get cleared later in loop?!
97 //
99 E_DscError handleInLoopError( P_DsmCoreInst idp,
100  E_DscError currErr, E_DscError newErr )
101 {
102  E_DscError err = CLDSM_OK;
103 
104  switch (newErr)
105  {
106  /* -- NB. Fall-through is intentional */
107  case CLDSM_ERR_INTERNAL:
108  err = newErr;
109  case CLDSM_ERR_SYSTEM_ADD_SECTION_FILTER:
110  case CLDSM_ERR_SI_QUERY_FAILED:
111  if (idp->setup.errorFunc)
112  {
113  idp->setup.errorFunc( newErr, NULL );
114  }
115  err = currErr ? currErr : newErr;
116  break;
117 
118  default:
119  /* -- Do not notify or return any other errors */
120  break;
121  }
122  return err;
123 }
124 
125 /* -- MANAGED MEMORY ACCESS FUNCTIONS */
126 
127 #include "defMemUtilsMgd.h"
128 
129 /* /////////////////////////////////////////////////////////////////////////////
130 // readUInt16Seq
131 // Reads a 16 bit value from the current memory area (advances cursor by 2)
133 void readUInt16Seq( MemSeqRef memAreaRef, U16BIT *pUi16 )
134 {
135  U8BIT data[2];
136  U32BIT dummy;
137  U16BIT result;
138 
139  dsmDP4(("readUInt16Seq()\n"));
140  dsmAssert((memAreaRef != NULL));
141  dsmAssert((pUi16 != NULL));
142 
143  CHECK_MEM_ERR( memSeqRead( memAreaRef, data, 2, &dummy ));
144 
145  result = (U16BIT)data[0];
146  *pUi16 = (U16BIT)((result << 8) | data[1]);
147 
148  dsmDP4(("exit readUInt16Seq: %x\n", *pUi16));
149 }
150 
151 /* /////////////////////////////////////////////////////////////////////////////
152 // readUInt32Seq
153 // Reads a 32 bit value from the current memory area (advances cursor by 4)
155 void readUInt32Seq( MemSeqRef memAreaRef, U32BIT *pUi32 )
156 {
157  U8BIT data[4];
158  U32BIT dummy;
159  U32BIT result;
160 
161  dsmDP4(("readUInt32Seq()\n"));
162  dsmAssert((memAreaRef != NULL));
163  dsmAssert((pUi32 != NULL));
164 
165  CHECK_MEM_ERR( memSeqRead( memAreaRef, data, 4, &dummy ));
166 
167  result = (U32BIT)data[0];
168  result = (U32BIT)((result << 8) | data[1]);
169  result = (U32BIT)((result << 8) | data[2]);
170  *pUi32 = (U32BIT)((result << 8) | data[3]);
171 
172  dsmDP4(("exit readUInt32Seq: %x\n", *pUi32));
173 }
174 
175 /* /////////////////////////////////////////////////////////////////////////////
176 // getUInt8Seq
177 // Gets an 8 bit value from the current memory area (restores cursor to start)
179 void getUInt8Seq( MemSeqRef memAreaRef, U8BIT *pUi8 )
180 {
181  dsmDP4(("getUInt8Seq()\n"));
182  dsmAssert((memAreaRef != NULL));
183  dsmAssert((pUi8 != NULL));
184 
185  CHECK_MEM_ERR( memSeqReadByte( memAreaRef, pUi8 ));
186  CHECK_MEM_ERR( memSeqSetPosRel( memAreaRef, -1 ));
187 
188  dsmDP4(("exit getUInt8Seq: %x\n", *pUi8));
189 }
190 
191 /* /////////////////////////////////////////////////////////////////////////////
192 // getUInt16Seq
193 // Gets a 16 bit value from the current memory area (restores cursor to start)
195 void getUInt16Seq( MemSeqRef memAreaRef, U16BIT *pUi16 )
196 {
197  U8BIT data[2];
198  U32BIT dummy;
199  U16BIT result;
200 
201  dsmDP4(("getUInt16Seq()\n"));
202  dsmAssert((memAreaRef != NULL));
203  dsmAssert((pUi16 != NULL));
204 
205  CHECK_MEM_ERR( memSeqRead( memAreaRef, data, 2, &dummy ));
206  CHECK_MEM_ERR( memSeqSetPosRel( memAreaRef, -2 ));
207 
208  result = (U16BIT)data[0];
209  *pUi16 = (U16BIT)((result << 8) | data[1]);
210 
211  dsmDP4(("exit getUInt16Seq: %x\n", *pUi16));
212 }
213 
214 /* /////////////////////////////////////////////////////////////////////////////
215 // getUInt32Seq
216 // Gets a 32 bit value from the current memory area (restores cursor to start)
218 void getUInt32Seq( MemSeqRef memAreaRef, U32BIT *pUi32 )
219 {
220  U8BIT data[4];
221  U32BIT dummy;
222  U32BIT result;
223 
224  dsmDP4(("getUInt32Seq()\n"));
225  dsmAssert((memAreaRef != NULL));
226  dsmAssert((pUi32 != NULL));
227 
228  CHECK_MEM_ERR( memSeqRead( memAreaRef, data, 4, &dummy ));
229  CHECK_MEM_ERR( memSeqSetPosRel( memAreaRef, -4 ));
230 
231  result = (U32BIT)data[0];
232  result = (U32BIT)((result << 8) | data[1]);
233  result = (U32BIT)((result << 8) | data[2]);
234  *pUi32 = (U32BIT)((result << 8) | data[3]);
235 
236  dsmDP4(("exit getUInt32Seq: %x\n", *pUi32));
237 }
238 
239 /* /////////////////////////////////////////////////////////////////////////////
240 // readObjectKeySeq
241 //
242 // memAreaRef must be an already opened MemSeq area with the cursor pointing at
243 // the objectKeyLength field of required DVB (ie. 1-4 byte) objectKey data area
244 //
245 // pObjectKey returns the objectKey value.
246 //
247 // pValid indicates if objectKey successfully recovered
248 //
249 // On exit - If valid: cursor advanced by objectKeyLength + 1
250 // Else: cursor set back to initial position
252 void readObjectKeySeq( MemSeqRef memAreaRef,
253  P_ObjectKey pObjectKey, BOOLEAN *pValid )
254 {
255  U8BIT objKeyLen;
256  U32BIT numBytesActual;
257  E_DsmMemErr memErr;
258 
259  dsmDP4(("readObjectKeySeq()\n"));
260  dsmAssert((memAreaRef != NULL));
261  dsmAssert((pObjectKey != NULL));
262  dsmAssert((pValid != NULL));
263 
264 
265  *pValid = FALSE;
266  pObjectKey->length = 0;
267 
268  /* -- Read objectKey size */
269  CHECK_MEM_ERR( memSeqReadByte( memAreaRef, &objKeyLen ));
270 
271  if ((objKeyLen < 1) || (objKeyLen > 4))
272  {
273  dsmDP2(("DATA ERROR: ObjectKey length = %d\n", objKeyLen));
274  memSeqSetPosRel( memAreaRef, -1 );
275  }
276  else
277  {
278  memErr = memSeqRead(
279  memAreaRef, pObjectKey->data, objKeyLen, &numBytesActual );
280 
281  if (memErr != MEM_NO_ERR)
282  {
283  memSeqSetPosRel( memAreaRef, -(S32BIT)(numBytesActual + 1));
284  }
285  else
286  {
287  pObjectKey->length = objKeyLen;
288  *pValid = TRUE;
289  }
290  }
291 
292  dsmDP4(("exit readObjectKeySeq - length: %u, data: %02x%02x%02x%02x\n",
293  pObjectKey->length, pObjectKey->data[0], pObjectKey->data[1],
294  pObjectKey->data[2], pObjectKey->data[3]));
295 }
296 
297 #ifndef MEM_CONTIGUOUS
298 
299 /* /////////////////////////////////////////////////////////////////////////////
300 // getIorInfoSeq
301 // get location and tap info from IOR data held in managed (MemSeq) memory
302 // mpIorData (MemPtr) is normally an opened MemSeqRef with the cursor at the
303 // first byte of IOR (nb. if MEM_CONTIGUOUS MemPtr defined to U8BIT*)
304 // pValid indicates whether info was successfully recovered
305 //
306 // NB. Uses GET_IOR_INFO Common Code with getIorInfoContig
307 // mpIorData (MemSeqRef) cursor is left unaltered
308 //
310 U16BIT getIorInfoSeq( const MemPtr mpIorData, U32BIT *pIorTypeId,
311  P_ObjectLocation pLocation, P_DeliveryParaTap pTap )
312 {
313  U32BIT length_used;
314 
315  dsmDP3(("getIorInfoSeq()\n"));
316 
317 #include "getIopIor_include_src.h"
318 
319  dsmDP3(("exit getIorInfoSeq -> rtn: %u\n", length_used));
320  return (U16BIT)length_used;
321 }
322 
323 #endif
325 /* -- CONTIGUOUS MEMORY ACCESS FUNCTIONS */
326 
327 #include "defMemUtilsContig.h"
328 
329 /* /////////////////////////////////////////////////////////////////////////////
330 // getIorInfoContig
331 // get location and tap info from IOR data held in contiguous memory
332 // mpIorData points to first byte of IOR
333 // pValid indicates whether info was successfully recovered
334 //
335 // NB. Uses GET_IOR_INFO Common Code with getIorInfoMemSeq
337 U16BIT getIorInfoContig( const MemPtr mpIorData, U32BIT *pIorTypeId,
338  P_ObjectLocation pLocation, P_DeliveryParaTap pTap )
339 {
340  U32BIT length_used;
341 
342  dsmDP3(("getIorInfoContig()\n"));
343 
344 #include "getIopIor_include_src.h"
345 
346  dsmDP3(("exit getIorInfoContig -> rtn: %u\n", length_used));
347  return (U16BIT)length_used;
348 }
349 
350 P_Compatibility DSC_UtilParseCompatibilityDesc( P_DsmCoreInst idp,
351  MemPtr pData, U16BIT length, U32BIT specifier )
352 {
353  P_Compatibility pCompat;
354  S_modelVersion *pMV;
355  U32BIT oui;
356  U16BIT count, cnt;
357  U8BIT dlen, type;
358  MemPtr mp;
359  READ_UINT16( pData, count );
360  pCompat = (P_Compatibility)DSC_CmMemGet( idp, sizeof(S_Compatibility) + (count*sizeof(S_modelVersion)) );
361  if (pCompat != NULL)
362  {
363  pMV = (S_modelVersion *)(pCompat + 1);
364  pCompat->hwlist = pMV;
365  pCompat->hw_num = 0;
366  cnt = count;
367  mp = pData;
368  while (cnt--)
369  {
370  READ_UINT8( mp, type );
371  READ_UINT8( mp, dlen );
372  READ_UINT32( mp, oui );
373  if (type == SYSTEM_HARDWARE_DESC && oui == specifier)
374  {
375  pCompat->hw_num++;
376  READ_UINT16( mp, pMV->model );
377  READ_UINT16( mp, pMV->version );
378  pMV++;
379  }
380  else
381  {
382  SET_POS_REL( mp, 4 );
383  }
384  if (dlen > 8)
385  {
386  SET_POS_REL( mp, dlen - 8 );
387  }
388  }
389 
390  pCompat->swlist = pMV;
391  pCompat->sw_num = 0;
392  cnt = count;
393  mp = pData;
394  while (cnt--)
395  {
396  READ_UINT8( mp, type );
397  READ_UINT8( mp, dlen );
398  READ_UINT32( mp, oui );
399  if (type == SYSTEM_SOFTWARE_DESC && oui == specifier)
400  {
401  pCompat->sw_num++;
402  READ_UINT16( mp, pMV->model );
403  READ_UINT16( mp, pMV->version );
404  pMV++;
405  }
406  else
407  {
408  SET_POS_REL( mp, 4 );
409  }
410  if (dlen > 8)
411  {
412  /* Skip subDescriptor */
413  SET_POS_REL( mp, dlen - 8 );
414  }
415  }
416  }
417  return pCompat;
418 }
419 
420 
421 BOOLEAN DSC_UtilCheckCompatibility( U8BIT *pData, U16BIT len,
422  U32BIT specifier, S_SsuModelVersion smv )
423 {
424  U32BIT oui;
425  U16BIT count, match;
426  U16BIT model, version;
427  U8BIT dlen, type;
428  READ_UINT16( pData, count );
429  match = 0;
430  while (count--)
431  {
432  READ_UINT8( pData, type );
433  READ_UINT8( pData, dlen );
434  READ_UINT32( pData, oui );
435  READ_UINT16( pData, model );
436  READ_UINT16( pData, version );
437  if (oui == specifier)
438  {
439  if (type == SYSTEM_HARDWARE_DESC &&
440  smv.hw_model == model &&
441  smv.hw_version == version)
442  {
443  match |= 1;
444  }
445  else if (type == SYSTEM_SOFTWARE_DESC &&
446  smv.sw_model == model &&
447  smv.sw_version == version)
448  {
449  match |= 2;
450  }
451  if (match == 3)
452  {
453  break;
454  }
455  }
456  if (dlen > 8)
457  {
458  SET_POS_REL( pData, dlen - 8 );
459  }
460  }
461  return (match == 3)? TRUE : FALSE;
462 }
463 
464 /*------------------------------ Local Functions -----------------------------*/
465 
466 
467 /*----------------------------------------------------------------------------*/
General include file for clDsm library internal definitions.
Calculate CRC for a message.
Defines memory access utils to work with contiguous memory.
Header to the cacheMgr module.
Defines memory access utils to work with managed (MemMgr) memory.
eader to the clDsmUtils module.