blob: 7797bb2ab40d0ea16397e5701c68a8373ece5829 [file] [log] [blame]
Andreas Hubera8fc7722012-08-29 13:26:55 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef HDCP_API_H_
Andreas Hubera8fc7722012-08-29 13:26:55 -070018#define HDCP_API_H_
19
20#include <utils/Errors.h>
Mathias Agopian6a3c05b2017-04-27 20:06:55 -070021#include <cutils/native_handle.h>
Andreas Hubera8fc7722012-08-29 13:26:55 -070022
23namespace android {
24
Andreas Huber0dcde522013-01-30 10:40:28 -080025// Two different kinds of modules are covered under the same HDCPModule
26// structure below, a module either implements decryption or encryption.
Andreas Hubera8fc7722012-08-29 13:26:55 -070027struct HDCPModule {
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -070028 typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2);
Andreas Hubera8fc7722012-08-29 13:26:55 -070029
30 // The msg argument in calls to the observer notification function.
31 enum {
32 // Sent in response to a call to "HDCPModule::initAsync" once
33 // initialization has either been successfully completed,
34 // i.e. the HDCP session is now fully setup (AKE, Locality Check,
35 // SKE and any authentication with repeaters completed) or failed.
36 // ext1 should be a suitable error code (status_t), ext2 is
Andreas Huber0dcde522013-01-30 10:40:28 -080037 // unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE
38 // holds the local TCP port the module is listening on.
Andreas Hubera8fc7722012-08-29 13:26:55 -070039 HDCP_INITIALIZATION_COMPLETE,
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -070040 HDCP_INITIALIZATION_FAILED,
Andreas Hubera8fc7722012-08-29 13:26:55 -070041
42 // Sent upon completion of a call to "HDCPModule::shutdownAsync".
43 // ext1 should be a suitable error code, ext2 is unused.
44 HDCP_SHUTDOWN_COMPLETE,
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -070045 HDCP_SHUTDOWN_FAILED,
46
47 HDCP_UNAUTHENTICATED_CONNECTION,
48 HDCP_UNAUTHORIZED_CONNECTION,
49 HDCP_REVOKED_CONNECTION,
50 HDCP_TOPOLOGY_EXECEEDED,
51 HDCP_UNKNOWN_ERROR,
Andreas Huber0dcde522013-01-30 10:40:28 -080052
53 // DECRYPTION only: Indicates that a client has successfully connected,
54 // a secure session established and the module is ready to accept
55 // future calls to "decrypt".
56 HDCP_SESSION_ESTABLISHED,
Andreas Hubera8fc7722012-08-29 13:26:55 -070057 };
58
Chong Zhanga3a91852013-09-03 14:17:58 -070059 // HDCPModule capability bit masks
60 enum {
61 // HDCP_CAPS_ENCRYPT: mandatory, meaning the HDCP module can encrypt
62 // from an input byte-array buffer to an output byte-array buffer
63 HDCP_CAPS_ENCRYPT = (1 << 0),
64 // HDCP_CAPS_ENCRYPT_NATIVE: the HDCP module supports encryption from
65 // a native buffer to an output byte-array buffer. The format of the
66 // input native buffer is specific to vendor's encoder implementation.
67 // It is the same format as that used by the encoder when
68 // "storeMetaDataInBuffers" extension is enabled on its output port.
69 HDCP_CAPS_ENCRYPT_NATIVE = (1 << 1),
70 };
71
Andreas Hubera8fc7722012-08-29 13:26:55 -070072 // Module can call the notification function to signal completion/failure
73 // of asynchronous operations (such as initialization) or out of band
74 // events.
Dan Willemsen20131922016-12-13 21:20:13 -080075 HDCPModule(void * /*cookie*/, ObserverFunc /*observerNotify*/) {};
Andreas Hubera8fc7722012-08-29 13:26:55 -070076
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -070077 virtual ~HDCPModule() {};
Andreas Hubera8fc7722012-08-29 13:26:55 -070078
Andreas Huber0dcde522013-01-30 10:40:28 -080079 // ENCRYPTION: Request to setup an HDCP session with the host specified
80 // by addr and listening on the specified port.
81 // DECRYPTION: Request to setup an HDCP session, addr is the interface
82 // address the module should bind its socket to. port will be 0.
83 // The module will pick the port to listen on itself and report its choice
84 // in the "ext2" argument of the HDCP_INITIALIZATION_COMPLETE callback.
85 virtual status_t initAsync(const char *addr, unsigned port) = 0;
Andreas Hubera8fc7722012-08-29 13:26:55 -070086
87 // Request to shutdown the active HDCP session.
88 virtual status_t shutdownAsync() = 0;
89
Chong Zhangb344adf2013-09-03 14:17:58 -070090 // Returns the capability bitmask of this HDCP session.
91 virtual uint32_t getCaps() {
92 return HDCP_CAPS_ENCRYPT;
93 }
94
Andreas Huber0dcde522013-01-30 10:40:28 -080095 // ENCRYPTION only:
96 // Encrypt data according to the HDCP spec. "size" bytes of data are
97 // available at "inData" (virtual address), "size" may not be a multiple
98 // of 128 bits (16 bytes). An equal number of encrypted bytes should be
99 // written to the buffer at "outData" (virtual address).
Andreas Hubera8fc7722012-08-29 13:26:55 -0700100 // This operation is to be synchronous, i.e. this call does not return
101 // until outData contains size bytes of encrypted data.
102 // streamCTR will be assigned by the caller (to 0 for the first PES stream,
103 // 1 for the second and so on)
Andreas Huber0dcde522013-01-30 10:40:28 -0800104 // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
Andreas Hubera8fc7722012-08-29 13:26:55 -0700105 virtual status_t encrypt(
Dan Willemsen20131922016-12-13 21:20:13 -0800106 const void * /*inData*/, size_t /*size*/, uint32_t /*streamCTR*/,
107 uint64_t * /*outInputCTR*/, void * /*outData*/) {
Andreas Huber0dcde522013-01-30 10:40:28 -0800108 return INVALID_OPERATION;
109 }
110
Chong Zhang685e6812013-05-16 13:11:27 -0700111 // Encrypt data according to the HDCP spec. "size" bytes of data starting
112 // at location "offset" are available in "buffer" (buffer handle). "size"
113 // may not be a multiple of 128 bits (16 bytes). An equal number of
114 // encrypted bytes should be written to the buffer at "outData" (virtual
115 // address). This operation is to be synchronous, i.e. this call does not
116 // return until outData contains size bytes of encrypted data.
117 // streamCTR will be assigned by the caller (to 0 for the first PES stream,
118 // 1 for the second and so on)
119 // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
120 virtual status_t encryptNative(
Dan Willemsen20131922016-12-13 21:20:13 -0800121 buffer_handle_t /*buffer*/, size_t /*offset*/, size_t /*size*/,
122 uint32_t /*streamCTR*/, uint64_t * /*outInputCTR*/, void * /*outData*/) {
Chong Zhang685e6812013-05-16 13:11:27 -0700123 return INVALID_OPERATION;
124 }
Andreas Huber0dcde522013-01-30 10:40:28 -0800125 // DECRYPTION only:
126 // Decrypt data according to the HDCP spec.
127 // "size" bytes of encrypted data are available at "inData"
128 // (virtual address), "size" may not be a multiple of 128 bits (16 bytes).
129 // An equal number of decrypted bytes should be written to the buffer
130 // at "outData" (virtual address).
131 // This operation is to be synchronous, i.e. this call does not return
132 // until outData contains size bytes of decrypted data.
133 // Both streamCTR and inputCTR will be provided by the caller.
134 virtual status_t decrypt(
Dan Willemsen20131922016-12-13 21:20:13 -0800135 const void * /*inData*/, size_t /*size*/,
136 uint32_t /*streamCTR*/, uint64_t /*inputCTR*/,
137 void * /*outData*/) {
Andreas Huber0dcde522013-01-30 10:40:28 -0800138 return INVALID_OPERATION;
139 }
Andreas Hubera8fc7722012-08-29 13:26:55 -0700140
141private:
142 HDCPModule(const HDCPModule &);
143 HDCPModule &operator=(const HDCPModule &);
144};
145
146} // namespace android
147
Andreas Huber0dcde522013-01-30 10:40:28 -0800148// A shared library exporting the following methods should be included to
Andreas Hubera8fc7722012-08-29 13:26:55 -0700149// support HDCP functionality. The shared library must be called
150// "libstagefright_hdcp.so", it will be dynamically loaded into the
151// mediaserver process.
152extern "C" {
Andreas Huber0dcde522013-01-30 10:40:28 -0800153 // Create a module for ENCRYPTION.
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -0700154 extern android::HDCPModule *createHDCPModule(
155 void *cookie, android::HDCPModule::ObserverFunc);
Andreas Huber0dcde522013-01-30 10:40:28 -0800156
157 // Create a module for DECRYPTION.
158 extern android::HDCPModule *createHDCPModuleForDecryption(
159 void *cookie, android::HDCPModule::ObserverFunc);
Andreas Hubera8fc7722012-08-29 13:26:55 -0700160}
161
162#endif // HDCP_API_H_
163