| 1 | /******************************************************************************************** |
|---|
| 2 | * (c)2004-2011 Broadcom Corporation * |
|---|
| 3 | * * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, * |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and * |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom * |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants* |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the * |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all * |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU * |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY * |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. * |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, * |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes * |
|---|
| 17 | * the valuable trade secrets of Broadcom, and you shall use all reasonable efforts to * |
|---|
| 18 | * protect the confidentiality thereof,and to use this information only in connection * |
|---|
| 19 | * with your use of Broadcom integrated circuit products. * |
|---|
| 20 | * * |
|---|
| 21 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" * |
|---|
| 22 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR * |
|---|
| 23 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO * |
|---|
| 24 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES * |
|---|
| 25 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, * |
|---|
| 26 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION * |
|---|
| 27 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF * |
|---|
| 28 | * USE OR PERFORMANCE OF THE SOFTWARE. * |
|---|
| 29 | * * |
|---|
| 30 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS * |
|---|
| 31 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR * |
|---|
| 32 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR * |
|---|
| 33 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF * |
|---|
| 34 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT * |
|---|
| 35 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE * |
|---|
| 36 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF * |
|---|
| 37 | * ANY LIMITED REMEDY. |
|---|
| 38 | * |
|---|
| 39 | * $brcm_Workfile: b_dtcp_content.h $ |
|---|
| 40 | * $brcm_Revision: 6 $ |
|---|
| 41 | * $brcm_Date: 2/11/11 5:37p $ |
|---|
| 42 | * |
|---|
| 43 | * Module Description: |
|---|
| 44 | * DTCP content management functions. |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /nexus/lib/dtcp_ip/include/b_dtcp_content.h $ |
|---|
| 49 | * |
|---|
| 50 | * 6 2/11/11 5:37p leisun |
|---|
| 51 | * SWSECURITY-32: Updated lib to V1SE1.3 conformance. |
|---|
| 52 | * |
|---|
| 53 | * 5 7/16/09 7:03p lwhite |
|---|
| 54 | * PR55693: Fixed signedness |
|---|
| 55 | * |
|---|
| 56 | * 4 7/13/09 11:23a leisun |
|---|
| 57 | * PR 55693: Re-design interfaces, and other cleanups |
|---|
| 58 | * |
|---|
| 59 | * 3 6/30/09 10:37p leisun |
|---|
| 60 | * PR 55693: Added exchange key expiration timer |
|---|
| 61 | * |
|---|
| 62 | * 2 6/25/09 4:30p leisun |
|---|
| 63 | * PR 55693: Fix memory leak for DTCP |
|---|
| 64 | * |
|---|
| 65 | * 1 6/5/09 4:07p leisun |
|---|
| 66 | * PR 55693: checking in DTCP-IP lib |
|---|
| 67 | *********************************************************************************************/ |
|---|
| 68 | /*! \file b_dtcp_content.h |
|---|
| 69 | * \brief define DTCP-IP content managment data and function prototypes. |
|---|
| 70 | */ |
|---|
| 71 | #ifndef __DTCP_CONTENT_MANAGEMENT_H__ |
|---|
| 72 | #define __DTCP_CONTENT_MANAGEMENT_H__ |
|---|
| 73 | |
|---|
| 74 | #include "b_dtcp_constants.h" |
|---|
| 75 | |
|---|
| 76 | /*! \struct B_DtcpIpPcpHeader |
|---|
| 77 | * |
|---|
| 78 | * This header is only applied for DTCP/IP |
|---|
| 79 | */ |
|---|
| 80 | typedef struct B_DtcpIpPcpHeader |
|---|
| 81 | { |
|---|
| 82 | #if BSTD_CPU_ENDIAN == BSTD_ENDIAN_BIG |
|---|
| 83 | unsigned int Reserved: 3; /* Reserved */ |
|---|
| 84 | unsigned int C_A : 1; /* Cipher algorithm, 0-AES128 1-Optional M6 */ |
|---|
| 85 | unsigned int Emi : 4; /* Extended EMI */ |
|---|
| 86 | #else |
|---|
| 87 | unsigned int Emi : 4; |
|---|
| 88 | unsigned int C_A : 1; |
|---|
| 89 | unsigned int Reserved: 3; |
|---|
| 90 | #endif |
|---|
| 91 | unsigned char ExchKeyLabel; |
|---|
| 92 | unsigned char Nc[DTCP_CONTENT_KEY_NONCE_SIZE]; |
|---|
| 93 | int CL; |
|---|
| 94 | } __attribute__((__packed__)) B_DTCP_IP_PCPHeader_T; |
|---|
| 95 | |
|---|
| 96 | /* PCP_UR header fromat |
|---|
| 97 | * DTCP-IP V1SE 1.3 or later |
|---|
| 98 | */ |
|---|
| 99 | typedef struct B_DtcpIpPCP_UR |
|---|
| 100 | { |
|---|
| 101 | #if BSTD_CPU_ENDIAN == BSTD_ENDIAN_BIG |
|---|
| 102 | unsigned int UR_Mode: 2; |
|---|
| 103 | unsigned int Content_type: 2; |
|---|
| 104 | unsigned int APS: 2; |
|---|
| 105 | unsigned int ICT: 1; |
|---|
| 106 | unsigned int Source: 1; |
|---|
| 107 | unsigned int AST: 1; |
|---|
| 108 | unsigned int Reserved: 7; |
|---|
| 109 | #else |
|---|
| 110 | unsigned int Source: 1; |
|---|
| 111 | unsigned int ICT: 1; |
|---|
| 112 | unsigned int APS: 2; |
|---|
| 113 | unsigned int Content_type: 2; |
|---|
| 114 | unsigned int UR_Mode: 2; |
|---|
| 115 | unsigned int Reserved: 7; |
|---|
| 116 | unsigned int AST: 1; |
|---|
| 117 | #endif |
|---|
| 118 | }__attribute__((__packed__)) B_DTCP_IP_PCP_UR_T; |
|---|
| 119 | /* |
|---|
| 120 | * PCP header format when PCP-UR is used. |
|---|
| 121 | * DTCP-IP spec V1SE 1.3 or later. |
|---|
| 122 | */ |
|---|
| 123 | typedef struct B_DtcpIpPcpURHeader |
|---|
| 124 | { |
|---|
| 125 | #if BSTD_CPU_ENDIAN == BSTD_ENDIAN_BIG |
|---|
| 126 | unsigned int Reserved: 3; /* Reserved */ |
|---|
| 127 | unsigned int C_A : 1; /* Cipher algorithm, 0-AES128 1-Optional M6 */ |
|---|
| 128 | unsigned int Emi : 4; /* Extended EMI */ |
|---|
| 129 | #else |
|---|
| 130 | unsigned int Emi : 4; |
|---|
| 131 | unsigned int C_A : 1; |
|---|
| 132 | unsigned int Reserved: 3; |
|---|
| 133 | #endif |
|---|
| 134 | unsigned char ExchKeyLabel; |
|---|
| 135 | B_DTCP_IP_PCP_UR_T pcp_ur; |
|---|
| 136 | unsigned char SNc[DTCP_CONTENT_KEY_NONCE_SIZE - 2]; |
|---|
| 137 | int CL; |
|---|
| 138 | }__attribute__((__packed__)) B_DTCP_IP_PCPURHeader_T; |
|---|
| 139 | |
|---|
| 140 | typedef void * B_PacketHandle_T; |
|---|
| 141 | |
|---|
| 142 | /*! \brief B_DTCP_Content_CreatePacketHeader create pcp header, called by source device only. |
|---|
| 143 | * \param[in] hAkehandle handle to AKE session. |
|---|
| 144 | * \param[in] Transport stream transport type. |
|---|
| 145 | * \param[in] StreamData point to source stream data structure. |
|---|
| 146 | * \param[in] ContentSize total size of the content. |
|---|
| 147 | * \param[in,out] pPacketHeader Buffer to hold created packet header |
|---|
| 148 | */ |
|---|
| 149 | BERR_Code B_DTCP_Content_CreatePacketHeader(B_AkeHandle_T hAkeHandle, B_StreamTransport_T Transport, |
|---|
| 150 | struct __b_dtcp_stream_data *StreamData, |
|---|
| 151 | int ContentSize, |
|---|
| 152 | unsigned char pPacketHeader[DTCP_CONTENT_PACKET_HEADER_SIZE]); |
|---|
| 153 | |
|---|
| 154 | /*! \brief B_DTCP_Content_ConsumePacketHeader consume pcp header, called by sink device only. |
|---|
| 155 | * \param[in] hAkeHandle handle to active AKE session. |
|---|
| 156 | * \param[in] pPacketHeader Buffer to hold packet header |
|---|
| 157 | * \param[in] StreamData pointer to sink stream data structure |
|---|
| 158 | */ |
|---|
| 159 | BERR_Code B_DTCP_Content_ConsumePacketHeader(B_AkeHandle_T hAkeHandle, |
|---|
| 160 | unsigned char * pPacketHeader, |
|---|
| 161 | struct __b_dtcp_stream_data *StreamData); |
|---|
| 162 | /*! \brief B_DTCP_Content_EncryptData encrypt protected content, called by source only. |
|---|
| 163 | * \param[in] aAkeHandle AKE session handle. |
|---|
| 164 | * \param[in] aPacketHandle handle to packet data (obtained from create packet header function). |
|---|
| 165 | * \param[in] aInBuffer input buffer. |
|---|
| 166 | * \param[in,out] aOutBuffer output buffer. |
|---|
| 167 | * \param[in] aBufferLength length of input buffer. |
|---|
| 168 | */ |
|---|
| 169 | BERR_Code B_DTCP_Content_EncryptData(B_AkeHandle_T aAkeHandle, B_PacketHandle_T aPacketHandle, |
|---|
| 170 | unsigned char *aInBuffer, |
|---|
| 171 | unsigned char *aOutBuffer, |
|---|
| 172 | unsigned int aBufferLength); |
|---|
| 173 | /*! \brief B_DTCP_Content_DecryptData decrypt protected content, called by source only. |
|---|
| 174 | * \param[in] aAkeHandle AKE session handle. |
|---|
| 175 | * \param[in] aPacketHandle handle to packet data (obtained from create packet header function). |
|---|
| 176 | * \param[in] aInBuffer input buffer. |
|---|
| 177 | * \param[in,out] aOutBuffer output buffer. |
|---|
| 178 | * \param[in] aBufferLength length of input buffer. |
|---|
| 179 | */ |
|---|
| 180 | BERR_Code B_DTCP_Content_DecryptData(B_AkeHandle_T aAkeHandle, B_PacketHandle_T aPacketHandle, |
|---|
| 181 | unsigned char *aInBuffer, |
|---|
| 182 | unsigned char *aOutBuffer, |
|---|
| 183 | unsigned int aBufferLength); |
|---|
| 184 | /*! \brief close packet , free packet handle and cipher context. |
|---|
| 185 | */ |
|---|
| 186 | void B_DTCP_Content_ClosePacket(B_PacketHandle_T aPacketHandle); |
|---|
| 187 | |
|---|
| 188 | #endif |
|---|