blob: 147448ef6374eeb443f984878e385012f198a612 [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_
18
19#define HDCP_API_H_
20
21#include <utils/Errors.h>
22
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
59 // Module can call the notification function to signal completion/failure
60 // of asynchronous operations (such as initialization) or out of band
61 // events.
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -070062 HDCPModule(void *cookie, ObserverFunc observerNotify) {};
Andreas Hubera8fc7722012-08-29 13:26:55 -070063
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -070064 virtual ~HDCPModule() {};
Andreas Hubera8fc7722012-08-29 13:26:55 -070065
Andreas Huber0dcde522013-01-30 10:40:28 -080066 // 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;
Andreas Hubera8fc7722012-08-29 13:26:55 -070073
74 // Request to shutdown the active HDCP session.
75 virtual status_t shutdownAsync() = 0;
76
Andreas Huber0dcde522013-01-30 10:40:28 -080077 // ENCRYPTION only:
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).
Andreas Hubera8fc7722012-08-29 13:26:55 -070082 // 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)
Andreas Huber0dcde522013-01-30 10:40:28 -080086 // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
Andreas Hubera8fc7722012-08-29 13:26:55 -070087 virtual status_t encrypt(
88 const void *inData, size_t size, uint32_t streamCTR,
Andreas Huber0dcde522013-01-30 10:40:28 -080089 uint64_t *outInputCTR, void *outData) {
90 return INVALID_OPERATION;
91 }
92
93 // DECRYPTION only:
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,
105 void *outData) {
106 return INVALID_OPERATION;
107 }
Andreas Hubera8fc7722012-08-29 13:26:55 -0700108
109private:
110 HDCPModule(const HDCPModule &);
111 HDCPModule &operator=(const HDCPModule &);
112};
113
114} // namespace android
115
Andreas Huber0dcde522013-01-30 10:40:28 -0800116// A shared library exporting the following methods should be included to
Andreas Hubera8fc7722012-08-29 13:26:55 -0700117// support HDCP functionality. The shared library must be called
118// "libstagefright_hdcp.so", it will be dynamically loaded into the
119// mediaserver process.
120extern "C" {
Andreas Huber0dcde522013-01-30 10:40:28 -0800121 // Create a module for ENCRYPTION.
Deva Ramasubramaniandbaaa382012-09-18 16:15:32 -0700122 extern android::HDCPModule *createHDCPModule(
123 void *cookie, android::HDCPModule::ObserverFunc);
Andreas Huber0dcde522013-01-30 10:40:28 -0800124
125 // Create a module for DECRYPTION.
126 extern android::HDCPModule *createHDCPModuleForDecryption(
127 void *cookie, android::HDCPModule::ObserverFunc);
Andreas Hubera8fc7722012-08-29 13:26:55 -0700128}
129
130#endif // HDCP_API_H_
131