Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 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 | |
| 19 | #define HDCP_API_H_ |
| 20 | |
| 21 | #include <utils/Errors.h> |
Chong Zhang | 685e681 | 2013-05-16 13:11:27 -0700 | [diff] [blame] | 22 | #include <system/window.h> |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 26 | // Two different kinds of modules are covered under the same HDCPModule |
| 27 | // structure below, a module either implements decryption or encryption. |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 28 | struct HDCPModule { |
Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 29 | typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2); |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 30 | |
| 31 | // The msg argument in calls to the observer notification function. |
| 32 | enum { |
| 33 | // Sent in response to a call to "HDCPModule::initAsync" once |
| 34 | // initialization has either been successfully completed, |
| 35 | // i.e. the HDCP session is now fully setup (AKE, Locality Check, |
| 36 | // SKE and any authentication with repeaters completed) or failed. |
| 37 | // ext1 should be a suitable error code (status_t), ext2 is |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 38 | // unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE |
| 39 | // holds the local TCP port the module is listening on. |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 40 | HDCP_INITIALIZATION_COMPLETE, |
Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 41 | HDCP_INITIALIZATION_FAILED, |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 42 | |
| 43 | // Sent upon completion of a call to "HDCPModule::shutdownAsync". |
| 44 | // ext1 should be a suitable error code, ext2 is unused. |
| 45 | HDCP_SHUTDOWN_COMPLETE, |
Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 46 | HDCP_SHUTDOWN_FAILED, |
| 47 | |
| 48 | HDCP_UNAUTHENTICATED_CONNECTION, |
| 49 | HDCP_UNAUTHORIZED_CONNECTION, |
| 50 | HDCP_REVOKED_CONNECTION, |
| 51 | HDCP_TOPOLOGY_EXECEEDED, |
| 52 | HDCP_UNKNOWN_ERROR, |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 53 | |
| 54 | // DECRYPTION only: Indicates that a client has successfully connected, |
| 55 | // a secure session established and the module is ready to accept |
| 56 | // future calls to "decrypt". |
| 57 | HDCP_SESSION_ESTABLISHED, |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Chong Zhang | a3a9185 | 2013-09-03 14:17:58 -0700 | [diff] [blame] | 60 | // HDCPModule capability bit masks |
| 61 | enum { |
| 62 | // HDCP_CAPS_ENCRYPT: mandatory, meaning the HDCP module can encrypt |
| 63 | // from an input byte-array buffer to an output byte-array buffer |
| 64 | HDCP_CAPS_ENCRYPT = (1 << 0), |
| 65 | // HDCP_CAPS_ENCRYPT_NATIVE: the HDCP module supports encryption from |
| 66 | // a native buffer to an output byte-array buffer. The format of the |
| 67 | // input native buffer is specific to vendor's encoder implementation. |
| 68 | // It is the same format as that used by the encoder when |
| 69 | // "storeMetaDataInBuffers" extension is enabled on its output port. |
| 70 | HDCP_CAPS_ENCRYPT_NATIVE = (1 << 1), |
| 71 | }; |
| 72 | |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 73 | // Module can call the notification function to signal completion/failure |
| 74 | // of asynchronous operations (such as initialization) or out of band |
| 75 | // events. |
Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 76 | HDCPModule(void *cookie, ObserverFunc observerNotify) {}; |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 77 | |
Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 78 | virtual ~HDCPModule() {}; |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 79 | |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 80 | // ENCRYPTION: Request to setup an HDCP session with the host specified |
| 81 | // by addr and listening on the specified port. |
| 82 | // DECRYPTION: Request to setup an HDCP session, addr is the interface |
| 83 | // address the module should bind its socket to. port will be 0. |
| 84 | // The module will pick the port to listen on itself and report its choice |
| 85 | // in the "ext2" argument of the HDCP_INITIALIZATION_COMPLETE callback. |
| 86 | virtual status_t initAsync(const char *addr, unsigned port) = 0; |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 87 | |
| 88 | // Request to shutdown the active HDCP session. |
| 89 | virtual status_t shutdownAsync() = 0; |
| 90 | |
Chong Zhang | b344adf | 2013-09-03 14:17:58 -0700 | [diff] [blame] | 91 | // Returns the capability bitmask of this HDCP session. |
| 92 | virtual uint32_t getCaps() { |
| 93 | return HDCP_CAPS_ENCRYPT; |
| 94 | } |
| 95 | |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 96 | // ENCRYPTION only: |
| 97 | // Encrypt data according to the HDCP spec. "size" bytes of data are |
| 98 | // available at "inData" (virtual address), "size" may not be a multiple |
| 99 | // of 128 bits (16 bytes). An equal number of encrypted bytes should be |
| 100 | // written to the buffer at "outData" (virtual address). |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 101 | // This operation is to be synchronous, i.e. this call does not return |
| 102 | // until outData contains size bytes of encrypted data. |
| 103 | // streamCTR will be assigned by the caller (to 0 for the first PES stream, |
| 104 | // 1 for the second and so on) |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 105 | // inputCTR _will_be_maintained_by_the_callee_ for each PES stream. |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 106 | virtual status_t encrypt( |
| 107 | const void *inData, size_t size, uint32_t streamCTR, |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 108 | uint64_t *outInputCTR, void *outData) { |
| 109 | return INVALID_OPERATION; |
| 110 | } |
| 111 | |
Chong Zhang | 685e681 | 2013-05-16 13:11:27 -0700 | [diff] [blame] | 112 | // Encrypt data according to the HDCP spec. "size" bytes of data starting |
| 113 | // at location "offset" are available in "buffer" (buffer handle). "size" |
| 114 | // may not be a multiple of 128 bits (16 bytes). An equal number of |
| 115 | // encrypted bytes should be written to the buffer at "outData" (virtual |
| 116 | // address). This operation is to be synchronous, i.e. this call does not |
| 117 | // return until outData contains size bytes of encrypted data. |
| 118 | // streamCTR will be assigned by the caller (to 0 for the first PES stream, |
| 119 | // 1 for the second and so on) |
| 120 | // inputCTR _will_be_maintained_by_the_callee_ for each PES stream. |
| 121 | virtual status_t encryptNative( |
| 122 | buffer_handle_t buffer, size_t offset, size_t size, |
| 123 | uint32_t streamCTR, uint64_t *outInputCTR, void *outData) { |
| 124 | return INVALID_OPERATION; |
| 125 | } |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 126 | // DECRYPTION only: |
| 127 | // Decrypt data according to the HDCP spec. |
| 128 | // "size" bytes of encrypted data are available at "inData" |
| 129 | // (virtual address), "size" may not be a multiple of 128 bits (16 bytes). |
| 130 | // An equal number of decrypted bytes should be written to the buffer |
| 131 | // at "outData" (virtual address). |
| 132 | // This operation is to be synchronous, i.e. this call does not return |
| 133 | // until outData contains size bytes of decrypted data. |
| 134 | // Both streamCTR and inputCTR will be provided by the caller. |
| 135 | virtual status_t decrypt( |
| 136 | const void *inData, size_t size, |
| 137 | uint32_t streamCTR, uint64_t inputCTR, |
| 138 | void *outData) { |
| 139 | return INVALID_OPERATION; |
| 140 | } |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 141 | |
| 142 | private: |
| 143 | HDCPModule(const HDCPModule &); |
| 144 | HDCPModule &operator=(const HDCPModule &); |
| 145 | }; |
| 146 | |
| 147 | } // namespace android |
| 148 | |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 149 | // A shared library exporting the following methods should be included to |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 150 | // support HDCP functionality. The shared library must be called |
| 151 | // "libstagefright_hdcp.so", it will be dynamically loaded into the |
| 152 | // mediaserver process. |
| 153 | extern "C" { |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 154 | // Create a module for ENCRYPTION. |
Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 155 | extern android::HDCPModule *createHDCPModule( |
| 156 | void *cookie, android::HDCPModule::ObserverFunc); |
Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 157 | |
| 158 | // Create a module for DECRYPTION. |
| 159 | extern android::HDCPModule *createHDCPModuleForDecryption( |
| 160 | void *cookie, android::HDCPModule::ObserverFunc); |
Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | #endif // HDCP_API_H_ |
| 164 | |