42 #ifdef CI_TA_HANDLES_KEYS 51 #define EVEN_KEY_REGISTER 0 52 #define ODD_KEY_REGISTER 1 75 #ifdef CI_TA_HANDLES_KEYS 76 typedef struct s_cikey_avail
86 static BOOLEAN *desc_allocated = NULL;
88 static void *cikeys_mutex;
89 #ifdef CI_TA_HANDLES_KEYS 90 static S_CIKEY_AVAIL *cikeys_avail = NULL;
94 static void AllocateDescramblers(U8BIT path, U8BIT cipher);
95 static BOOLEAN SetDescramblerKey(U8BIT path, E_STB_DMX_DESC_KEY_PARITY parity,
121 slot_info = FindSlot(slot_id);
122 if (slot_info != NULL)
124 slot_info->disabled = TRUE;
140 pslot = &cikeys_slots;
145 if (slot->slot_id == slot_id)
151 pslot = &(slot->next);
168 U8BIT *key, U8BIT *civ)
171 U8BIT path, num_paths;
175 DBGPRINT(
"slot_id = %u, cipher = %s, key_register = %u",
177 cipher == STB_CI_CIPHER_DES ?
"STB_CI_CIPHER_DES" :
178 cipher == STB_CI_CIPHER_AES ?
"STB_CI_CIPHER_AES" :
182 slot_info = FindSlot(slot_id);
184 if (slot_info == NULL)
187 if (slot_info != NULL)
189 slot_info->disabled = FALSE;
190 slot_info->keys[EVEN_KEY_REGISTER].applied = (BOOLEAN*)(slot_info + 1);
191 memset(slot_info->keys[EVEN_KEY_REGISTER].applied, 0, 2 * num_paths *
sizeof(BOOLEAN));
192 slot_info->keys[ODD_KEY_REGISTER].applied = slot_info->keys[EVEN_KEY_REGISTER].applied + num_paths;
193 slot_info->keys[EVEN_KEY_REGISTER].valid = FALSE;
194 slot_info->keys[ODD_KEY_REGISTER].valid = FALSE;
195 slot_info->slot_id = slot_id;
196 DBGPRINT(
"Add slot info; id=%u", slot_id)
199 slot_info->next = cikeys_slots;
200 cikeys_slots = slot_info;
203 if (desc_allocated == NULL)
206 if (desc_allocated != NULL)
208 for (path = 0; path != num_paths; path++)
210 desc_allocated[path] = FALSE;
216 if (slot_info != NULL)
219 if ((key_register == EVEN_KEY_REGISTER) ||
220 (key_register == ODD_KEY_REGISTER))
222 slot_info->cipher = cipher;
223 if (cipher == STB_CI_CIPHER_AES)
225 memcpy(slot_info->keys[key_register].key, key, 16);
226 memcpy(slot_info->keys[key_register].civ, civ, 16);
230 memcpy(slot_info->keys[key_register].key, key, 8);
232 slot_info->keys[key_register].valid = TRUE;
234 for (path = 0; path != num_paths; path++)
236 slot_info->keys[key_register].applied[path] = FALSE;
239 DBGPRINT(
"Send CI KEYS changed/updated slot=%u", slot_id)
240 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_CI, EV_TYPE_CI_KEYS_UPDATED, &slot_id,
sizeof(U8BIT));
247 #ifdef CI_TA_HANDLES_KEYS 258 void STB_CINotifyCckAvailable(U8BIT slot_id, U32BIT obj_ref)
261 FUNCTION_START(STB_CINotifyCckAvailable);
262 DBGPRINT(
"slot=%u oref=%x", slot_id, obj_ref)
263 num_slots = STB_CIGetSlotCount();
264 if (slot_id > num_slots)
266 DBGPRINT(
"Error: bad slot_id %u", slot_id)
270 if (cikeys_avail == NULL)
272 cikeys_avail = (S_CIKEY_AVAIL *)
STB_GetMemory(num_slots *
sizeof(S_CIKEY_AVAIL));
273 if (cikeys_avail != NULL)
275 memset(cikeys_avail, 0, num_slots *
sizeof(S_CIKEY_AVAIL));
278 if (cikeys_avail != NULL)
280 cikeys_avail[slot_id].obj_ref = obj_ref;
281 cikeys_avail[slot_id].notify = TRUE;
283 DBGPRINT(
"Send CI KEYS changed/updated slot=%u", slot_id)
284 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_CI, EV_TYPE_CI_KEYS_UPDATED, &slot_id,
sizeof(U8BIT));
287 FUNCTION_FINISH(STB_CINotifyCckAvailable);
303 DBGPRINT(
"(path=%u,slot=%u)", path, slot_id)
305 slot_info = FindSlot(slot_id);
306 if (slot_info != NULL)
308 if (((slot_info->keys[EVEN_KEY_REGISTER].valid) &&
309 (!slot_info->keys[EVEN_KEY_REGISTER].applied[path])) ||
310 ((slot_info->keys[ODD_KEY_REGISTER].valid) &&
311 (!slot_info->keys[ODD_KEY_REGISTER].applied[path])))
315 if ((desc_allocated != NULL) && (!desc_allocated[path]))
319 AllocateDescramblers(path, slot_info->cipher);
322 if ((desc_allocated != NULL) && (desc_allocated[path]))
324 if ((slot_info->keys[EVEN_KEY_REGISTER].valid) &&
325 (!slot_info->keys[EVEN_KEY_REGISTER].applied[path]))
327 DBGPRINT(
"Setting descrambler even keys")
328 if (SetDescramblerKey(path, KEY_PARITY_EVEN, slot_info->cipher,
329 &slot_info->keys[EVEN_KEY_REGISTER]))
331 slot_info->keys[EVEN_KEY_REGISTER].applied[path] = TRUE;
334 if ((slot_info->keys[ODD_KEY_REGISTER].valid) &&
335 (!slot_info->keys[ODD_KEY_REGISTER].applied[path]))
337 DBGPRINT(
"Setting descrambler odd keys")
338 if (SetDescramblerKey(path, KEY_PARITY_ODD, slot_info->cipher,
339 &slot_info->keys[ODD_KEY_REGISTER]))
341 slot_info->keys[ODD_KEY_REGISTER].applied[path] = TRUE;
350 if ((slot_info->keys[EVEN_KEY_REGISTER].valid) &&
351 (!slot_info->keys[EVEN_KEY_REGISTER].applied[path]))
353 DBGPRINT(
"(%u) Saving descrambler even keys", path)
355 STB_PVRSetDescramblerKey(path, slot_info->cipher, KEY_PARITY_EVEN,
356 slot_info->keys[EVEN_KEY_REGISTER].key, slot_info->keys[EVEN_KEY_REGISTER].civ);
357 slot_info->keys[EVEN_KEY_REGISTER].applied[path] = TRUE;
360 if ((slot_info->keys[ODD_KEY_REGISTER].valid) &&
361 (!slot_info->keys[ODD_KEY_REGISTER].applied[path]))
363 DBGPRINT(
"(%u): Saving descrambler odd keys", path)
365 STB_PVRSetDescramblerKey(path, slot_info->cipher, KEY_PARITY_ODD,
366 slot_info->keys[ODD_KEY_REGISTER].key, slot_info->keys[ODD_KEY_REGISTER].civ);
367 slot_info->keys[ODD_KEY_REGISTER].applied[path] = TRUE;
372 #ifdef CI_TA_HANDLES_KEYS 373 else if (cikeys_avail != NULL && cikeys_avail[slot_id].notify)
378 STB_CISendCckToDemuxTa(slot_id, cikeys_avail[slot_id].obj_ref, path);
380 cikeys_avail[slot_id].notify = FALSE;
402 DBGPRINT(
"(%u): demux=%u", path, demux)
403 if (demux != INVALID_RES_ID)
405 if ((desc_allocated != NULL) && (desc_allocated[path]))
411 desc_allocated[path] = FALSE;
414 slot_info = FindSlot(slot_id);
415 if (slot_info != NULL)
417 slot_info->keys[EVEN_KEY_REGISTER].applied[path] = FALSE;
418 slot_info->keys[ODD_KEY_REGISTER].applied[path] = FALSE;
431 slot_info = cikeys_slots;
432 while (slot_info != NULL)
434 if (slot_info->slot_id == slot_id)
436 if (slot_info->disabled)
442 slot_info = slot_info->next;
454 static void AllocateDescramblers(U8BIT path, U8BIT cipher)
457 E_STB_DMX_DESC_TYPE type;
460 FUNCTION_START(AllocateDescramblers);
463 if (desc_allocated != NULL && demux != INVALID_RES_ID)
467 case STB_CI_CIPHER_DES:
468 type = DESC_TYPE_DES;
470 case STB_CI_CIPHER_AES:
471 type = DESC_TYPE_AES;
493 DBGPRINT(
"Descramblers allocated successfully")
494 desc_allocated[path] = TRUE;
508 if (!desc_allocated[path])
510 DBGPRINT(
"Could not allocate descramblers")
514 FUNCTION_FINISH(AllocateDescramblers);
523 static BOOLEAN SetDescramblerKey(U8BIT path, E_STB_DMX_DESC_KEY_PARITY parity,
527 U8BIT key_buffer[32];
531 FUNCTION_START(SetDescramblerKey);
536 if (key_info->valid && demux != INVALID_RES_ID)
540 case STB_CI_CIPHER_DES:
541 key_data = key_info->key;
543 case STB_CI_CIPHER_AES:
544 memcpy(key_buffer, key_info->key, 16);
545 memcpy(key_buffer + 16, key_info->civ, 16);
546 key_data = key_buffer;
551 DBGPRINT(
"STB_DMXSetDescramblerKeyData(%d, DESC_TRACK_AUDIO) returned %d", demux, result)
553 DBGPRINT(
"STB_DMXSetDescramblerKeyData(%d, DESC_TRACK_VIDEO) returned %d", demux, result)
555 DBGPRINT(
"STB_DMXSetDescramblerKeyData(%d, DESC_TRACK_TEXT) returned %d", demux, result)
558 FUNCTION_FINISH(SetDescramblerKey);
void * STB_GetMemory(U32BIT bytes)
Attempts to allocate memory from the heap.
BOOLEAN STB_DMXGetDescramblerKey(U8BIT path, E_STB_DMX_DESC_TRACK track)
Acquires a descrambler for the specified track on this path.
void STB_CiKeysApply(U8BIT path, U8BIT slot_id)
Apply stored CC keys (if any) on given path.
Header file - macros and function prototypes for public use.
void STB_OSMutexUnlock(void *mutex)
Unlock a mutex (a.k.a. 'leave', 'signal' or 'release')
void STB_CiKeysRemove(U8BIT slot_id)
Notify module removal.
Header file - macros and function prototypes for public use.
void STB_ERSendEvent(BOOLEAN latched, BOOLEAN repeat, U16BIT path_class, U16BIT type, void *data, U32BIT data_size)
Sends an event to event reporting control module.
BOOLEAN STB_DMXSetDescramblerKeyData(U8BIT path, E_STB_DMX_DESC_TRACK track, E_STB_DMX_DESC_KEY_PARITY parity, U8BIT *data)
Set the descrambler key data for the specified track on this path.
U8BIT STB_DPGetNumPaths(void)
Returns the maximum number of decode paths.
void STB_CiKeysDisable(U8BIT slot_id)
Disable CC keys for slot, as CAM has been removed.
void STB_FreeMemory(void *addr)
Releases previously allocated heap memory.
BOOLEAN STB_DPIsDecodingPath(U8BIT path)
Is the given decode path being used for decoding.
BOOLEAN STB_DMXSetDescramblerType(U8BIT path, E_STB_DMX_DESC_TRACK track, E_STB_DMX_DESC_TYPE type)
Set the descrambler type for the specified track on this path.
Debug functions header file.
void STB_OSMutexLock(void *mutex)
Lock a mutex (a.k.a. 'enter', 'wait' or 'get').
CI Content Control - descrambler keys.
Header file - Function prototypes for Event Reporting.
CI Content Control support - internal header.
BOOLEAN STB_DMXSetKeyUsage(U8BIT path, E_STB_DMX_DESC_TRACK track, E_STB_DMX_KEY_USAGE key_usage)
Set the descrambler key usage for the specified track on this path.
void STB_CINotifyCCKey(U8BIT slot_id, U8BIT cipher, U8BIT key_register, U8BIT *key, U8BIT *civ)
Handle content control keys.
Header file - Function prototypes for operating system.
System Wide Global Technical Data Type Definitions.
BOOLEAN STB_DPIsRecordingPath(U8BIT path)
Is the given decode path being used for recording.
void STB_CiKeysInitialise(void)
CI descrambler keys support initialise.
Header file - Function prototypes for heap memory.
void * STB_OSCreateMutex(void)
Create a mutex.
void STB_CiKeysClear(U8BIT path, U8BIT slot_id)
Clear CC keys (if any) from given path.
BOOLEAN STB_DMXFreeDescramblerKey(U8BIT path, E_STB_DMX_DESC_TRACK track)
Frees the descrambler for the specified track on this path.
U8BIT STB_DPGetPathDemux(U8BIT path)
Returns the demux path ID acquired by the given decode path.