/*************************************************************************** * Copyright (c) 2008, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: * * Revision History: * * $brcm_Log: $ * ***************************************************************************/ #include "bstd.h" #include "ts_priv.h" #include "ca_parser.h" BDBG_MODULE(ca_parser); #ifndef CA_ASSERT #define CA_ASSERT BDBG_ASSERT #endif /* * This function is used to parse CA table to get pointer to CA descritor block * * Parameters: * cat_buf pointer to the beginning of CA table * psize pointer to the size of buffer, and will be length of section upon successfully * * Returns: * pointer to CA descriptor block if successful * NULL otherwise */ uint8_t *cat_parser(const uint8_t *cat_buf, size_t *psize) { uint8_t *p = (uint8_t *)cat_buf; int section_len; BDBG_MSG(("%s: enter", __func__)); CA_ASSERT((p && psize)); if (0x01 != *p) { BDBG_WRN(("%s: Invalid CA Table ID (0x%02x)", __func__, *p)); return NULL; } p++; section_len = (TS_READ_16(p) & 0xfff); p += 2; if (*psize < (section_len + 3)) { BDBG_WRN(("%s: Invalid CA Table", __func__)); return NULL; } /* skip version_number, current_next, last_section fields */ p += 5; *psize = section_len; BDBG_MSG(("%s: leave", __func__)); return p; } /* * This function is used to parse CA descriptor from either CAT (for system wide) * or PMT (for stream wide) * * Parameters: * ca_buf pointer to the beginning of CA descriptor block * size size of buffer * ca_desc pointer to ca_descriptor data structure * * Returns: * 0 if failed * 1 if parsing is successful */ int ca_parser(const uint8_t *ca_buf, size_t size, ca_descriptor *ca_desc) { uint8_t *p = (uint8_t *)ca_buf; int i, len; BDBG_MSG(("%s: enter", __func__)); CA_ASSERT((p && ca_desc)); if (TS_PSI_DT_CA != *p) { BDBG_WRN(("%s: Invalid CA Descriptor (0x%02x)", __func__, *p)); return 0; } ca_desc->sig = 0xDEADF00D; p++; len = *p; p++; ca_desc->CA_system_ID = TS_READ_16(p); p += 2; ca_desc->CA_PID = (TS_READ_16(p) & 0x1fff); p += 2; len -= 4; if (len > CA_MAX_PRIV_DATA) { BDBG_WRN(("%s: private data bytes %d exceed data buffer size %d", __func__, len, CA_MAX_PRIV_DATA)); len = CA_MAX_PRIV_DATA; } ca_desc->priv_length = len; for (i = 0; i < ca_desc->priv_length; i++) { ca_desc->priv_data[i] = *p; p++; } if (size <= (size_t)(p - ca_buf)) { BDBG_ERR(("%s: CA descriptor data exceed buffer boundary", __func__)); return 0; } if (ca_desc->sig != 0xDEADF00D) { BDBG_ERR(("%s: CA descriptor overflow", __func__)); } BDBG_MSG(("%s: leave", __func__)); return 1; } /* * This function is used to dump CA descriptor retrived from either CAT or PMT * * Parameters: * ca_desc pointer to ca_descriptor data structure with CA descriptor to dump * * Returns: * NONE */ void ca_dump_descriptor(ca_descriptor *ca_desc) { int i; CA_ASSERT(ca_desc); BDBG_MSG(("===dump CA descritpor===\n")); BDBG_MSG(("System ID = 0x%04x\n", ca_desc->CA_system_ID)); BDBG_MSG((" CA ID = 0x%04x\n", ca_desc->CA_PID)); BDBG_MSG(("Priv data = %d\n", ca_desc->priv_length)); for (i = 0; i < ca_desc->priv_length && i < CA_MAX_PRIV_DATA; i++) { if (0 == (i % 8)) BDBG_MSG(("\n\t")); BDBG_MSG(("0x%02x ", ca_desc->priv_data[i])); } BDBG_MSG(("\n")); }