2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <utils/Errors.h>
21 #include <cutils/native_handle.h>
25 // Two different kinds of modules are covered under the same HDCPModule
26 // structure below, a module either implements decryption or encryption.
28 typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2);
30 // The msg argument in calls to the observer notification function.
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
37 // unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE
38 // holds the local TCP port the module is listening on.
39 HDCP_INITIALIZATION_COMPLETE,
40 HDCP_INITIALIZATION_FAILED,
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,
47 HDCP_UNAUTHENTICATED_CONNECTION,
48 HDCP_UNAUTHORIZED_CONNECTION,
49 HDCP_REVOKED_CONNECTION,
50 HDCP_TOPOLOGY_EXECEEDED,
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,
59 // HDCPModule capability bit masks
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),
72 // Module can call the notification function to signal completion/failure
73 // of asynchronous operations (such as initialization) or out of band
75 HDCPModule(void * /*cookie*/, ObserverFunc /*observerNotify*/) {};
77 virtual ~HDCPModule() {};
79 // 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;
87 // Request to shutdown the active HDCP session.
88 virtual status_t shutdownAsync() = 0;
90 // Returns the capability bitmask of this HDCP session.
91 virtual uint32_t getCaps() {
92 return HDCP_CAPS_ENCRYPT;
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).
100 // 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)
104 // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
105 virtual status_t encrypt(
106 const void * /*inData*/, size_t /*size*/, uint32_t /*streamCTR*/,
107 uint64_t * /*outInputCTR*/, void * /*outData*/) {
108 return INVALID_OPERATION;
111 // 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(
121 buffer_handle_t /*buffer*/, size_t /*offset*/, size_t /*size*/,
122 uint32_t /*streamCTR*/, uint64_t * /*outInputCTR*/, void * /*outData*/) {
123 return INVALID_OPERATION;
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(
135 const void * /*inData*/, size_t /*size*/,
136 uint32_t /*streamCTR*/, uint64_t /*inputCTR*/,
137 void * /*outData*/) {
138 return INVALID_OPERATION;
142 HDCPModule(const HDCPModule &);
143 HDCPModule &operator=(const HDCPModule &);
146 } // namespace android
148 // A shared library exporting the following methods should be included to
149 // support HDCP functionality. The shared library must be called
150 // "libstagefright_hdcp.so", it will be dynamically loaded into the
151 // mediaserver process.
153 // Create a module for ENCRYPTION.
154 extern android::HDCPModule *createHDCPModule(
155 void *cookie, android::HDCPModule::ObserverFunc);
157 // Create a module for DECRYPTION.
158 extern android::HDCPModule *createHDCPModuleForDecryption(
159 void *cookie, android::HDCPModule::ObserverFunc);
162 #endif // HDCP_API_H_