summaryrefslogtreecommitdiff
path: root/DRM/cc54/inc/wv_drm_api.h
blob: ff14ca90982bd75d18167cf629c0403b4a3c1695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * Copyright (C) 2014 Intel Corporation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*!
 * NOTE: Don't include this file. It is recommended to include sepdrm.h
 */
#ifndef __WV_DRM_API_H__
#define __WV_DRM_API_H__

#include <inttypes.h>
#include "drm_common_api.h"
#include "wv_fkp.h"

/*!
 * Defines
 */
#define NEW_FRAME_FLAG                  (1)
#define PREV_PACKET_PARTIAL_BLOCK_FLAG  (1 << 1)
#define CLEAR_CONTENT_FLAG              (1 << 2)

/*!
 * Structs
 */

/*
 * This structure is used to provide necessary information for Widevine audio
 * ciphertext decryption.
 *
 * The members are:
 *
 *   iv                     - AES initialization vector.
 *   input_ciphertext_size  - Input ciphertext data size in bytes.
 *   p_input_ciphertext     - Pointer to the input ciphertext data buffer.
 *   output_plaintext_size  - Output plaintext data size in bytes.
 *   p_output_plaintext     - Pointer to the output plaintext data buffer.
 */
struct drm_wv_audio_data
{
    uint8_t iv[AES_IV_COUNTER_SIZE_IN_BYTES];
    uint32_t input_ciphertext_size;
    uint8_t *p_input_ciphertext;
    uint32_t output_plaintext_size;
    uint8_t *p_output_plaintext;
};


/*
 * This structure is used to provide necessary information for Widevine video
 * ciphertext decryption.
 *
 * The members are:
 *
 *   iv                     - AES initialization vector.
 *   input_ciphertext_size  - Input ciphertext data size in bytes.
 *   p_input_ciphertext     - Pointer to the input ciphertext data.
 */
struct drm_wv_video_cipher
{
    uint8_t iv[AES_IV_COUNTER_SIZE_IN_BYTES];
    uint32_t input_ciphertext_size;
    uint8_t *p_input_ciphertext;
    uint8_t flags;
    uint8_t *p_output_enc_ciphertext;
    uint32_t output_ciphertext_size;
};

struct drm_wv_nalu_headers
{
    uint32_t frame_size;
    uint32_t parse_size;
    uint8_t *p_enc_ciphertext;
    uint32_t hdrs_buf_len;
    uint8_t *p_hdrs_buf;
};

/*!
 * Functions
 */


/*
 * Set Widevine Asset Key
 */
uint32_t drm_wv_set_entitlementkey(
    uint8_t *emm_keyptr,
    uint32_t emm_keylen);

/*
 * Derive Widevine Control Word
 */
uint32_t drm_wv_derive_controlword(
    uint8_t *cw_ptr,
    uint32_t cw_len,
    uint32_t *flags_ptr);

/*
 * Get Widevine Keybox infomation
 * Retrieve the encypted kbox data and decrypt the encrypted kbox data
 */
uint32_t drm_wv_get_keyboxinfo(
    uint8_t *key_data,
    uint32_t *key_data_size,
    uint8_t *device_id,
    uint32_t *device_id_size);


/*!
   *@brief Create a widevine session
 *
 */
uint32_t drm_wv_create_session(
    uint32_t *session_id);


/*
 * @brief Creates a Widevine session for HLS content.
 * @param[out] pSessionID Pointer to a variable that contains the session's ID
 *             number.
 */
uint32_t drm_wv_hls_create_session(
    uint32_t *session_id);

/*
 * @brief Decrypts Widevine encrypted audio data
 *
 * @param session_id DRM Session ID number
 * @param audio_info Pointer to a buffer containing Widevine audio information
 *
 * @return DRM_SUCCESSFUL The Widevine audio ciphertext was decrypted
 */
uint32_t drm_wv_decrypt_audio(
    uint32_t session_id,
    struct drm_wv_audio_data *audio_info);


/*
 * @brief Decrypts Widevine video ciphertext data into the IMR decryption buffer
 * @param session_id DRM Session ID number
 * @param video_info Pointer to the Widevine video data
 */
uint32_t drm_wv_decrypt_video(
    uint32_t session_id,
    struct drm_wv_video_cipher *video_info);


uint32_t drm_wv_return_naluheaders(
    uint32_t session_id,
    struct drm_wv_nalu_headers *nalu_info);

uint32_t drm_wv_keybox_provision(
    struct wv_keybox *buf);


/*
 * @brief Encrypts a Widevine keybox with a device specific key.
 *
 * @param[in] p_keybox Pointer to a Widevine keybox. May be NULL if
 *            keybox_length is zero.
 *
 * @param[in] keybox_length Length of the Widevine keybox in bytes. If zero then
 *            only the size of an encrypted Widevine keybox is returned.
 *
 * @param[out] p_wrapped_keybox Pointer to a buffer for the returned encrypted
 *             Widevine keybox. May be NULL if keybox_length is zero.
 *
 * @param[out] p_wrapped_keybox_length Length of the encrypted Widevine keybox
 *             in bytes.
 *
 * @param[in] p_transport_key Pointer to a transport key. May be NULL if
 *            transport_key_length is zero.
 *
 * @param[in] transport_key_length Length of the transport key in bytes.
 *
 * A Widevine keybox encrypted with the transport key is not supported.
 */
uint32_t drm_wv_wrap_keybox(const uint8_t * const p_keybox,
                            const uint32_t keybox_length,
                            uint8_t * const p_wrapped_keybox,
                            uint32_t * const p_wrapped_keybox_length,
                            const uint8_t * const p_transport_key,
                            const uint32_t transport_key_length);


/*
 * @brief Decrypts a wrapped Widevine keybox and installs it into the device.
 *
 * @param[in] p_keybox Pointer to a wrapped Widevine keybox.
 *
 * @param[in] keybox_length Length of the Widevine keybox in bytes.
 */
uint32_t drm_wv_install_keybox(const uint8_t * const p_keybox,
                               const uint32_t keybox_length);




#endif //__WV_DRM_API_H__