• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_
18 #define HDCP_API_H_
19 
20 #include <utils/Errors.h>
21 #include <cutils/native_handle.h>
22 
23 namespace android {
24 
25 // Two different kinds of modules are covered under the same HDCPModule
26 // structure below, a module either implements decryption or encryption.
27 struct HDCPModule {
28     typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2);
29 
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
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,
41 
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,
45         HDCP_SHUTDOWN_FAILED,
46 
47         HDCP_UNAUTHENTICATED_CONNECTION,
48         HDCP_UNAUTHORIZED_CONNECTION,
49         HDCP_REVOKED_CONNECTION,
50         HDCP_TOPOLOGY_EXECEEDED,
51         HDCP_UNKNOWN_ERROR,
52 
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,
57     };
58 
59     // 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 
72     // Module can call the notification function to signal completion/failure
73     // of asynchronous operations (such as initialization) or out of band
74     // events.
HDCPModuleHDCPModule75     HDCPModule(void * /*cookie*/, ObserverFunc /*observerNotify*/) {};
76 
~HDCPModuleHDCPModule77     virtual ~HDCPModule() {};
78 
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;
86 
87     // Request to shutdown the active HDCP session.
88     virtual status_t shutdownAsync() = 0;
89 
90     // Returns the capability bitmask of this HDCP session.
getCapsHDCPModule91     virtual uint32_t getCaps() {
92         return HDCP_CAPS_ENCRYPT;
93     }
94 
95     // 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).
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.
encryptHDCPModule105     virtual status_t encrypt(
106             const void * /*inData*/, size_t /*size*/, uint32_t /*streamCTR*/,
107             uint64_t * /*outInputCTR*/, void * /*outData*/) {
108         return INVALID_OPERATION;
109     }
110 
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.
encryptNativeHDCPModule120     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;
124     }
125     // 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.
decryptHDCPModule134     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;
139     }
140 
141 private:
142     HDCPModule(const HDCPModule &);
143     HDCPModule &operator=(const HDCPModule &);
144 };
145 
146 }  // namespace android
147 
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.
152 extern "C" {
153     // Create a module for ENCRYPTION.
154     extern android::HDCPModule *createHDCPModule(
155             void *cookie, android::HDCPModule::ObserverFunc);
156 
157     // Create a module for DECRYPTION.
158     extern android::HDCPModule *createHDCPModuleForDecryption(
159             void *cookie, android::HDCPModule::ObserverFunc);
160 }
161 
162 #endif  // HDCP_API_H_
163 
164