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.
21 #include <utils/Errors.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 // Module can call the notification function to signal completion/failure
60 // of asynchronous operations (such as initialization) or out of band
62 HDCPModule(void *cookie, ObserverFunc observerNotify) {};
64 virtual ~HDCPModule() {};
66 // ENCRYPTION: Request to setup an HDCP session with the host specified
67 // by addr and listening on the specified port.
68 // DECRYPTION: Request to setup an HDCP session, addr is the interface
69 // address the module should bind its socket to. port will be 0.
70 // The module will pick the port to listen on itself and report its choice
71 // in the "ext2" argument of the HDCP_INITIALIZATION_COMPLETE callback.
72 virtual status_t initAsync(const char *addr, unsigned port) = 0;
74 // Request to shutdown the active HDCP session.
75 virtual status_t shutdownAsync() = 0;
78 // Encrypt data according to the HDCP spec. "size" bytes of data are
79 // available at "inData" (virtual address), "size" may not be a multiple
80 // of 128 bits (16 bytes). An equal number of encrypted bytes should be
81 // written to the buffer at "outData" (virtual address).
82 // This operation is to be synchronous, i.e. this call does not return
83 // until outData contains size bytes of encrypted data.
84 // streamCTR will be assigned by the caller (to 0 for the first PES stream,
85 // 1 for the second and so on)
86 // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
87 virtual status_t encrypt(
88 const void *inData, size_t size, uint32_t streamCTR,
89 uint64_t *outInputCTR, void *outData) {
90 return INVALID_OPERATION;
94 // Decrypt data according to the HDCP spec.
95 // "size" bytes of encrypted data are available at "inData"
96 // (virtual address), "size" may not be a multiple of 128 bits (16 bytes).
97 // An equal number of decrypted bytes should be written to the buffer
98 // at "outData" (virtual address).
99 // This operation is to be synchronous, i.e. this call does not return
100 // until outData contains size bytes of decrypted data.
101 // Both streamCTR and inputCTR will be provided by the caller.
102 virtual status_t decrypt(
103 const void *inData, size_t size,
104 uint32_t streamCTR, uint64_t inputCTR,
106 return INVALID_OPERATION;
110 HDCPModule(const HDCPModule &);
111 HDCPModule &operator=(const HDCPModule &);
114 } // namespace android
116 // A shared library exporting the following methods should be included to
117 // support HDCP functionality. The shared library must be called
118 // "libstagefright_hdcp.so", it will be dynamically loaded into the
119 // mediaserver process.
121 // Create a module for ENCRYPTION.
122 extern android::HDCPModule *createHDCPModule(
123 void *cookie, android::HDCPModule::ObserverFunc);
125 // Create a module for DECRYPTION.
126 extern android::HDCPModule *createHDCPModuleForDecryption(
127 void *cookie, android::HDCPModule::ObserverFunc);
130 #endif // HDCP_API_H_