RDK Documentation (Open Sourced RDK Components)
dtcpmgr.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file dtcpmgr.h
22  * DTCP Manager Interface
23  */
24 
25 /**
26  * @defgroup DTCP DTCP (Digital Transmission Content Protection)
27  *
28  * Digital Transmission Content Protection ("DTCP") technology protects high-value digital motion pictures,
29  * television programs and audio against unauthorized interception and copying in the home and personal environment
30  * (e.g., between a digital set top box and digital video recorder, or between a personal computer and a digital TV).
31  *
32  * @par Terminology
33  * Code | Description
34  * -----| -----------
35  * DTCP | Digital Transmission Content Protection
36  * DTCP-IP | Digital Transmission Content Protection Internet Protocol
37  * AKE | Authentication and Key Exchange
38  * CCI | Copy Control Information
39  * SRM | System Renewability Messages
40  * DLNA | Digital Living Network Alliance
41  * EMI | Encryption Mode Indicator
42  * E-EMI | Extended Encryption Mode Indicator
43  * PCP | Protected Content Packet
44  * SPTS | Single Program Transport Stream
45  *
46  * @par How does DTCP work?
47  * A device enabled with DTCP determines whether it is connected to other devices that implement
48  * the DTCP protection technology. Content encoded for DTCP protection is encrypted and securely transmitted
49  * only to recording and display devices that implement DTCP.
50  * The content carries information indicating whether and to what extent the content may be copied.
51  * @par DTCP overview & FAQ
52  * @see http://www.dtcp.com/documents/dtcp/dtcp-overview.pdf
53  * @see http://www.dtcp.com/faq.aspx
54  *
55  * @par Filter elements for content encryption and decryption
56  * There are two gstreamer filter elements are used for content encryption/decryption.
57  * @n
58  * - DTCP Encrypt: The "dtcpencrypt" is a gstreamer filter element which encrypts incomming MPEG2 SPTS
59  * stream and pushes encrypted data to the source pad. DTCP encrypt requires initialization of DTCP libs done
60  * in RMF applicaiton (e.g Media Streamer) which includes creating socket and listening for AKE request,
61  * authenticate and send exchange key to Sink device upon DTCP request from sink EMO
62  * @n It support Authentication and Key Exchange (AKE) from DTCP client.
63  * It encrypts the video stream using DTCP Encryption Mode Indicator (EMI).
64  * @n
65  * - DTCP Decrypt: The "dtcpdecrypt" is a gstreamer filter element is used to decrypt the MPEG2 SPTS video streams.
66  * It performs Authentication and Key Exchange (AKE) to DTCP server.
67  *
68  * @par DTCP Protection
69  * All DTCP encryption and dcryption uses common set of provided gstreamer elements, The gstreamer elements
70  * uses DTCP manager API. Each SoC provides binary DTCP encryption/decryption library to support the DTCP Manager API.
71  *
72  * @par DTCP Use Case: Live Playback using QAM Source
73  * @image html dtcp_usecase.png
74  * - The left side of the figure is considered for gateway device.
75  * - The right side of the figure is considered for client device.
76  * - In case of live stream the HTTPReqHandler will receive a request from client box and the MediaStreamer.
77  * - will sets an pipeline between QAM Source and HN Sink.
78  * - QAM Src element receives the data from the tuner and sends to the HN Sink.
79  * - In the client side another pipeline has created between HNSrc and MediaPlayerSink.
80  * - HNSrc receive the incoming data from HNSink and feeds to the MediaPlayerSink for live playback.
81  * - DTCP encryption and decryption are used for protecting contents over network.
82  *
83  * @par How to enable/disable DTCP
84  * @n
85  * At first, user need to verify that the current build of the box supports to enable/disable DTCP.
86  * @n If it's yes, following the next steps
87  * @n
88  * - Copy rmfconfig.ini under /etc to /opt
89  * @code
90  * cp /etc/rmfconfig.ini /opt
91  * @endcode
92  * @n
93  * - Change the configuration parameter "FEATURE.DTCP.SUPPORT" value to TRUE or FALSE in file /opt/rmfconfig.ini
94  * @code
95  * vi /opt/rmfconfig.ini
96  * @endcode
97  * @n
98  * Save the configuration file and reboot the box
99  * @code
100  * $ sync
101  * $ reboot
102  * @endcode
103  * @n
104  * Check AV for the box once it's up.
105  *
106  * @defgroup DTCPMGR_API DTCP Manager API
107  * DTCP manager manages source/sink DTCP-IP sessions and performs encryption/decryption.
108  *
109  * DTCP-IP is a specification for copy protection of copyrighted content that is
110  * transferred over digital interfaces in home IP networks.
111  *
112  * DTCP Manager sub-system performs data encryption and PCP packet decryption
113  * with authenticated DTCP-IP sessions.
114  * @ingroup DTCP
115  *
116  * @defgroup DTCPMGR_DS DTCP Manager Data Structure
117  * @ingroup DTCP
118  */
119 
120 
121 /**
122 * @defgroup dtcp
123 * @{
124 * @defgroup include
125 * @{
126 **/
127 
128 
129 #ifndef __DTCPMGR_H_
130 #define __DTCPMGR_H_
131 
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 
136 #include <stdint.h>
137 
138 /**
139  * @ingroup DTCPMGR_DS
140  * @{
141  */
142 /**
143  * @brief DTCP Manager return codes.
144  *
145  * This enumartion lists DTCP Manager error return codes.
146  * A non-zero value indicates an error.
147  */
148 typedef enum {
149  DTCP_SUCCESS = 0, /**< Operation successful, no errors. */
150  DTCP_ERR_NOT_INITIALIZED = -1, /**< DTCP Manager not initialized yet. */
151  DTCP_ERR_INVALID_PARAM = -2, /**< Invalid parameter supplied. */
152  DTCP_ERR_GENERAL = -3, /**< General unspecified error. */
153  DTCP_ERR_MEMORY_ALLOC = -4, /**< Memory allocation failure. */
154  DTCP_ERR_OUT_OF_SESSIONS = -5, /**< Too many active sessions. */
155  DTCP_ERR_INVALID_CERTIFICATE = -6, /**< Invalid certificate. */
156  DTCP_ERR_AKE = -7, /**< Authorization/Key Exchange error. */
157  DTCP_ERR_CONT_KEY_REQ = -8, /**< Content key error. */
158  DTCP_ERR_INVALID_KEY_LABEL = -9, /**< Invalid exchange key label supplied. */
159  DTCP_ERR_INVALID_IP_ADDRESS = -10, /**< Invalid IP address supplied. */
160  DTCP_ERR_SERVER_NOT_REACHABLE = -11 /**< DTCP Server not reachable. */
161 } dtcp_result_t;
162 
163 typedef unsigned char BOOLEAN;
164 
165 /**
166  * @brief DTCP-IP session handle.
167  *
168  * An opaque handle to a DTCP-IP source/sink session.
169  */
170 typedef unsigned long DTCP_SESSION_HANDLE;
171 
172 /**
173  * @brief DTCP-IP device types.
174  *
175  * This enumartion defines supported types of DTCP-IP devices.
176  */
177 typedef enum {
178  DTCP_SOURCE, /**< Source type. */
179  DTCP_SINK, /**< Sink type. */
180  DTCP_UNKNOWN /**< Unknown type. */
181 } DTCPDeviceType;
182 
183 /**
184  * @brief DTCP-IP packet stucture.
185  *
186  * This structure defines a DTCP-IP PCP packet.
187  */
188 typedef struct DTCPIP_Packet_s
189 {
190  DTCP_SESSION_HANDLE session; /**< (Input) The session to which this packet belongs. */
191  uint32_t emi; /**< (Input for source, Output for sink) EMI value. */
192  uint8_t *dataInPtr; /**< (Input) Virtual data buffer, allocated by the caller. */
193  uint8_t *dataInPhyPtr; /**< (Input) Physical data buffer, allocated by the caller.
194  (Set to NULL if not available.) */
195  uint8_t *dataOutPtr; /**< (Output) Virtual data buffer, allocated by DTCP Manager.
196  (This will be same as dataInPtr if encrypt/decrypt was done in-place.) */
197  uint8_t *dataOutPhyPtr; /**< (Output) Physical data buffer, allocated by DTCP Manager.
198  (This will be same as dataInPhyPtr if encrypt/decrypt was done in-place.) */
199  uint32_t dataLength; /**< (Input/Output) Length of the buffer. */
200  BOOLEAN isEOF; /**< (Input, source only) Flag specifying whether this is the last buffer for this session. */
201 
202  uint8_t *pcpHeader; /**< (Output, source only) PCP packet header, NULL if no header. */
203  uint32_t pcpHeaderLength; /**< (Output, source only) Length of pcpHeader in bytes, 0 if no header. */
204  int pcpHeaderOffset; /**< (Output, source only) Byte offset into the buffer where header needs to be inserted.
205  (If < 0, no insertion to be done.) */
206 } DTCPIP_Packet;
207 
208 /**
209  * @brief DTCP-IP session structure.
210  *
211  * This structure defines a DTCP-IP session.
212  */
213 typedef struct DTCPIP_Session_s
214 {
215  DTCP_SESSION_HANDLE session_handle; /**< Unique handle of the session. */
216  DTCPDeviceType device_type; /**< Type of device (source/sink). */
217  char * remote_ip; /**< Remote source/sink IP address. */
218  BOOLEAN uniqueKey; /**< Flag indicating unique key. */
220 
221 /** @} */ //End of Doxygen tag DTCPMGR_DS
222 
223 /**
224  * @ingroup DTCPMGR_API
225  * @{
226  */
227 
228 /**
229  * @brief Initializes the DTCP Manager.
230  *
231  * This function initializes the DTCP-IP Manager sub-system. It should be called during platform initialization.
232  *
233  * @note This function can be called multiple times from the multiple contexts. Once it's initialized,
234  * it will return DTCP_SUCCESS for all the subsequent calls.
235  *
236  * @param None.
237  *
238  * @return Error code.
239  * @retval DTCP_SUCCESS DTCP Manager successfully initialized.
240  */
242 
243 /**
244  * @brief Starts the DTCP-IP source.
245  *
246  * This function start the DTCP-IP source and begins listening for AKE requests
247  * on the specified interface and port number.
248  *
249  * @note Calling this function multiple times adds multiple listeners.
250  *
251  * @param[in] ifName Interface name (e.g. "eth0").
252  * @param[in] portNum TCP/IP port number that the source listens for AKE requests.
253  *
254  * @return Error code.
255  * @retval ::DTCP_SUCCESS Successfully started the DTCP-IP source and/or added a listener.
256  *
257  * @par Example usage
258  * @code
259  dtcp_result_t result = DTCPMgrStartSource("eth0", 5000);
260  @endcode
261  */
262 dtcp_result_t DTCPMgrStartSource(char* ifName, int portNum);
263 
264 /**
265  * @brief Stops the DTCP-IP source.
266  *
267  * This function stops the DTCP-IP source and removes all AKE request listeners
268  * added with ::DTCPMgrStartSource().
269  *
270  * @return Error code.
271  * @retval DTCP_SUCCESS Successfully stopped the DTCP-IP source and removed all listeners.
272  */
274 
275 /**
276  * @brief Creates a new DTCP-IP source session.
277  *
278  * This function creates a new authenticated session with a remote DTCP-IP sink.
279  *
280  * @param[in] sinkIpAddress IP address of the remote DTCP-IP sink.
281  * @param[in] key_label Exchange key label, if available from streaming request.
282  * If provided, the stream will be encrypted with the session key.
283  * @param [in] PCPPacketSize Minimum size of a packet. If the buffer provided in DTCPMgrProcessPacket() is less
284  * than @a PCPPacketSize, then the PCP packet is set to @a PCPPacketSize and fragmented across multiple DTCPIP_Packets.
285  * @n This is for reducing PCP space and processing overheads for low latency low bit-rate transfers
286  * where each buffer can be very small. @a PCPPacketSize of 0 would return every buffer as a PCP packet.
287  * @n i.e. If @a PCPPacketSize is 64 KB and if the buffer size in DTCPMgrProcessPacket() is 1 KB, the first decrypted
288  * buffer would be a PCP packet. And after first packet, decrypted buffer wouldn't have a PCP header until 64 KB.
289  * @param [in] maxPacketSize Maximum size of a packet.
290  * @n If the @a DataLength provided in DTCPMgrProcessPacket() is more than @a MaxPacketSize,
291  * the DTCP library can reject the process request.
292  *
293  * @param[out] handle The address of a location to hold the handle for the specified TCP/IP session on return.
294  *
295  * @return Error code.
296  * @retval DTCP_SUCCESS Successfully created a DTCP-IP source session.
297  */
298 dtcp_result_t DTCPMgrCreateSourceSession(char *sinkIpAddress, int key_label, int PCPPacketSize, int maxPacketSize, DTCP_SESSION_HANDLE *handle);
299 
300 /**
301  * @brief Creates a new DTCP-IP sink session.
302  *
303  * This function creates a new authenticated session with a remote DTCP-IP source.
304  *
305  * @param[in] srcIpAddress IP address of the remote DTCP-IP source.
306  * @param[in] srcIpPort TCP/IP port of the remote DTCP-IP source.
307  * @param[in] uniqueKey Flag to request unique exchange keys.
308  * (Both server and client should have 'session exchange key' support.)
309  * @param[in] maxPacketSize Maximum size of packet. If @a DataLength provided in DTCPMgrProcessPacket()
310  * is more than @a MaxPacketSize, the DTCP library can reject the process request.
311  * @param[out] handle The address of a location to hold the handle for the specified TCP/IP session on return.
312  *
313  * @return Error code.
314  * @retval DTCP_SUCCESS Successfully created a DTCP-IP sink session.
315  */
316 dtcp_result_t DTCPMgrCreateSinkSession(char *srcIpAddress, int srcIpPort, BOOLEAN uniqueKey, int maxPacketSize, DTCP_SESSION_HANDLE *handle);
317 
318 /**
319  * @brief Processes a DTCP-IP packet.
320  *
321  * This function processes a DTCP-IP packet - encrypts or decrypts buffers, depending on the session type:
322  * - Source - encrypt the provided buffers and create a DTCP-IP packet.
323  * - Sink - process the DTCP-IP packet and return decrypted buffers.
324  *
325  * @note All processing is done inside the ::DTCPIP_Packet data structure.
326  *
327  * @param[in] session Session handle.
328  * @param[in,out] packet Address of the location of the of the processed DTCP-IP packet.
329  *
330  * @return Error code.
331  * @retval DTCP_SUCCESS Successfully processed the packet.
332  */
334 
335 /**
336  * @brief Releases a processed DTCP-IP packet.
337  *
338  * This function releases the DTCP-IP packet. The processed packet may contain DTCP Manager allocated/owned
339  * buffers/memory - this call frees up these resources.
340  *
341  * @param [in] packet Address of the location of the DTCP-IP packet.
342  *
343  * @return Error code.
344  * @retval DTCP_SUCCESS Successfully released packet.
345  */
347 
348 /**
349  * @brief Deletes a DTCP-IP session.
350  *
351  * This function stops an active DTCP-IP session.
352  *
353  * @param[in] session Session handle.
354  *
355  * @return Error code.
356  * @retval DTCP_SUCCESS Successfully deleted the session.
357  */
359 
360 /**
361  * @brief Gets the number of active sessions.
362  *
363  * This function retrieves the total number of active sessions for the specified device type.
364  *
365  * @param[in] deviceType DTCP-IP device type (source/sink).
366  * DTCP_UNKNOWN returns total number of sessions of all types.
367  *
368  * @return Number of active sessions.
369  *
370  * @par Example usage
371  * @code
372  int source_session_count = getNumDTCPSessions(DTCP_SOURCE);
373  @endcode
374  */
375 int DTCPMgrGetNumSessions(DTCPDeviceType deviceType);
376 
377 /**
378  * @brief Gets session information.
379  *
380  * This function retrieves information related to an active session.
381  *
382  * @param[in] handle DTCP-IP session handle.
383  * @param[out] session The address of a location of the DTCP-IP session structure to fill on return.
384  *
385  * @return Error code.
386  * @retval DTCP_SUCCESS Successfully returned the session info.
387  */
389 
390 /**
391  * @brief Sets log level.
392  *
393  * This function sets DTCP Manager's logging verbosity level.
394  *
395  * @param [in] level Logging level.
396  *
397  * @return Error code.
398  * @retval DTCP_SUCCESS Logging level was set successfully.
399  */
401 
402 /** @} */ /* End of DTCPMGR_API doxygen group */
403 
404 #ifdef __cplusplus
405 }
406 #endif
407 
408 #endif //__DTCPMGR_H_
409 
DTCPMgrInitialize
dtcp_result_t DTCPMgrInitialize(void)
Initializes the DTCP Manager.
Definition: dtcpmgr.cpp:31
DTCP_ERR_SERVER_NOT_REACHABLE
@ DTCP_ERR_SERVER_NOT_REACHABLE
Definition: dtcpmgr.h:160
DTCPMgrDeleteDTCPSession
dtcp_result_t DTCPMgrDeleteDTCPSession(DTCP_SESSION_HANDLE session)
Deletes a DTCP-IP session.
Definition: dtcpmgr.cpp:121
DTCPMgrSetLogLevel
dtcp_result_t DTCPMgrSetLogLevel(int level)
Sets log level.
Definition: dtcpmgr.cpp:146
dtcp_result_t
dtcp_result_t
DTCP Manager return codes.
Definition: dtcpmgr.h:148
DTCPIP_Packet_s::emi
uint32_t emi
Definition: dtcpmgr.h:191
BOOLEAN
unsigned char BOOLEAN
DTCP Manager return codes.
Definition: dtcpmgr.h:163
DTCPDeviceType
DTCPDeviceType
DTCP-IP device types.
Definition: dtcpmgr.h:177
DTCPIP_Session_s::device_type
DTCPDeviceType device_type
Definition: dtcpmgr.h:216
DTCPIP_Session_s::session_handle
DTCP_SESSION_HANDLE session_handle
Definition: dtcpmgr.h:215
DTCP_ERR_CONT_KEY_REQ
@ DTCP_ERR_CONT_KEY_REQ
Definition: dtcpmgr.h:157
DTCPIP_Session
struct DTCPIP_Session_s DTCPIP_Session
DTCP-IP session structure.
DTCPMgrCreateSourceSession
dtcp_result_t DTCPMgrCreateSourceSession(char *sinkIpAddress, int key_label, int PCPPacketSize, int maxPacketSize, DTCP_SESSION_HANDLE *handle)
Creates a new DTCP-IP source session.
Definition: dtcpmgr.cpp:69
DTCP_SINK
@ DTCP_SINK
Definition: dtcpmgr.h:179
DTCPIP_Packet_s::dataOutPtr
uint8_t * dataOutPtr
Definition: dtcpmgr.h:195
DTCP_SOURCE
@ DTCP_SOURCE
Definition: dtcpmgr.h:178
DTCPMgrReleasePacket
dtcp_result_t DTCPMgrReleasePacket(DTCPIP_Packet *packet)
Releases a processed DTCP-IP packet.
Definition: dtcpmgr.cpp:115
DTCP_ERR_OUT_OF_SESSIONS
@ DTCP_ERR_OUT_OF_SESSIONS
Definition: dtcpmgr.h:154
DTCPIP_Packet_s::pcpHeader
uint8_t * pcpHeader
Definition: dtcpmgr.h:202
DTCPMgrGetSessionInfo
dtcp_result_t DTCPMgrGetSessionInfo(DTCP_SESSION_HANDLE handle, DTCPIP_Session *session)
Gets session information.
Definition: dtcpmgr.cpp:137
DTCPIP_Packet_s::pcpHeaderOffset
int pcpHeaderOffset
Definition: dtcpmgr.h:204
DTCP_ERR_AKE
@ DTCP_ERR_AKE
Definition: dtcpmgr.h:156
DTCPIP_Packet_s::dataInPtr
uint8_t * dataInPtr
Definition: dtcpmgr.h:192
DTCPMgrGetNumSessions
int DTCPMgrGetNumSessions(DTCPDeviceType deviceType)
Gets the number of active sessions.
Definition: dtcpmgr.cpp:130
DTCP_SUCCESS
@ DTCP_SUCCESS
Definition: dtcpmgr.h:149
DTCP_ERR_GENERAL
@ DTCP_ERR_GENERAL
Definition: dtcpmgr.h:152
DTCP_ERR_INVALID_CERTIFICATE
@ DTCP_ERR_INVALID_CERTIFICATE
Definition: dtcpmgr.h:155
DTCPMgrStartSource
dtcp_result_t DTCPMgrStartSource(char *ifName, int portNum)
Starts the DTCP-IP source.
Definition: dtcpmgr.cpp:46
DTCPIP_Packet_s::isEOF
BOOLEAN isEOF
Definition: dtcpmgr.h:200
DTCP_ERR_NOT_INITIALIZED
@ DTCP_ERR_NOT_INITIALIZED
Definition: dtcpmgr.h:150
DTCPIP_Packet_s::dataInPhyPtr
uint8_t * dataInPhyPtr
Definition: dtcpmgr.h:193
DTCPMgrStopSource
dtcp_result_t DTCPMgrStopSource(void)
Stops the DTCP-IP source.
Definition: dtcpmgr.cpp:53
DTCP_ERR_INVALID_KEY_LABEL
@ DTCP_ERR_INVALID_KEY_LABEL
Definition: dtcpmgr.h:158
DTCPIP_Session_s
DTCP-IP session structure.
Definition: dtcpmgr.h:213
DTCP_ERR_INVALID_PARAM
@ DTCP_ERR_INVALID_PARAM
Definition: dtcpmgr.h:151
DTCPIP_Packet_s::dataOutPhyPtr
uint8_t * dataOutPhyPtr
Definition: dtcpmgr.h:197
DTCP_UNKNOWN
@ DTCP_UNKNOWN
Definition: dtcpmgr.h:180
DTCPIP_Packet
struct DTCPIP_Packet_s DTCPIP_Packet
DTCP-IP packet stucture.
DTCPIP_Packet_s::session
DTCP_SESSION_HANDLE session
Definition: dtcpmgr.h:190
DTCPMgrCreateSinkSession
dtcp_result_t DTCPMgrCreateSinkSession(char *srcIpAddress, int srcIpPort, BOOLEAN uniqueKey, int maxPacketSize, DTCP_SESSION_HANDLE *handle)
Creates a new DTCP-IP sink session.
Definition: dtcpmgr.cpp:87
DTCP_ERR_MEMORY_ALLOC
@ DTCP_ERR_MEMORY_ALLOC
Definition: dtcpmgr.h:153
DTCPIP_Session_s::uniqueKey
BOOLEAN uniqueKey
Definition: dtcpmgr.h:218
DTCPMgrProcessPacket
dtcp_result_t DTCPMgrProcessPacket(DTCP_SESSION_HANDLE session, DTCPIP_Packet *packet)
Processes a DTCP-IP packet.
Definition: dtcpmgr.cpp:106
DTCPIP_Packet_s
DTCP-IP packet stucture.
Definition: dtcpmgr.h:188
DTCPIP_Packet_s::dataLength
uint32_t dataLength
Definition: dtcpmgr.h:199
DTCP_SESSION_HANDLE
unsigned long DTCP_SESSION_HANDLE
DTCP-IP session handle.
Definition: dtcpmgr.h:170
DTCPIP_Session_s::remote_ip
char * remote_ip
Definition: dtcpmgr.h:217
DTCP_ERR_INVALID_IP_ADDRESS
@ DTCP_ERR_INVALID_IP_ADDRESS
Definition: dtcpmgr.h:159
DTCPIP_Packet_s::pcpHeaderLength
uint32_t pcpHeaderLength
Definition: dtcpmgr.h:203