| 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_ | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 18 | #define HDCP_API_H_ | 
|  | 19 |  | 
|  | 20 | #include <utils/Errors.h> | 
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 21 | #include <cutils/native_handle.h> | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 |  | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 25 | // Two different kinds of modules are covered under the same HDCPModule | 
|  | 26 | // structure below, a module either implements decryption or encryption. | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 27 | struct HDCPModule { | 
| Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 28 | typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2); | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 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 | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 37 | // unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE | 
|  | 38 | // holds the local TCP port the module is listening on. | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 39 | HDCP_INITIALIZATION_COMPLETE, | 
| Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 40 | HDCP_INITIALIZATION_FAILED, | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 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, | 
| Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 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, | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 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, | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 57 | }; | 
|  | 58 |  | 
| Chong Zhang | a3a9185 | 2013-09-03 14:17:58 -0700 | [diff] [blame] | 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 |  | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 72 | // Module can call the notification function to signal completion/failure | 
|  | 73 | // of asynchronous operations (such as initialization) or out of band | 
|  | 74 | // events. | 
| Dan Willemsen | 2013192 | 2016-12-13 21:20:13 -0800 | [diff] [blame] | 75 | HDCPModule(void * /*cookie*/, ObserverFunc /*observerNotify*/) {}; | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 76 |  | 
| Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 77 | virtual ~HDCPModule() {}; | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 78 |  | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 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; | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 86 |  | 
|  | 87 | // Request to shutdown the active HDCP session. | 
|  | 88 | virtual status_t shutdownAsync() = 0; | 
|  | 89 |  | 
| Chong Zhang | b344adf | 2013-09-03 14:17:58 -0700 | [diff] [blame] | 90 | // Returns the capability bitmask of this HDCP session. | 
|  | 91 | virtual uint32_t getCaps() { | 
|  | 92 | return HDCP_CAPS_ENCRYPT; | 
|  | 93 | } | 
|  | 94 |  | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 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). | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 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) | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 104 | // inputCTR _will_be_maintained_by_the_callee_ for each PES stream. | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 105 | virtual status_t encrypt( | 
| Dan Willemsen | 2013192 | 2016-12-13 21:20:13 -0800 | [diff] [blame] | 106 | const void * /*inData*/, size_t /*size*/, uint32_t /*streamCTR*/, | 
|  | 107 | uint64_t * /*outInputCTR*/, void * /*outData*/) { | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 108 | return INVALID_OPERATION; | 
|  | 109 | } | 
|  | 110 |  | 
| Chong Zhang | 685e681 | 2013-05-16 13:11:27 -0700 | [diff] [blame] | 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( | 
| Dan Willemsen | 2013192 | 2016-12-13 21:20:13 -0800 | [diff] [blame] | 121 | buffer_handle_t /*buffer*/, size_t /*offset*/, size_t /*size*/, | 
|  | 122 | uint32_t /*streamCTR*/, uint64_t * /*outInputCTR*/, void * /*outData*/) { | 
| Chong Zhang | 685e681 | 2013-05-16 13:11:27 -0700 | [diff] [blame] | 123 | return INVALID_OPERATION; | 
|  | 124 | } | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 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. | 
|  | 134 | virtual status_t decrypt( | 
| Dan Willemsen | 2013192 | 2016-12-13 21:20:13 -0800 | [diff] [blame] | 135 | const void * /*inData*/, size_t /*size*/, | 
|  | 136 | uint32_t /*streamCTR*/, uint64_t /*inputCTR*/, | 
|  | 137 | void * /*outData*/) { | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 138 | return INVALID_OPERATION; | 
|  | 139 | } | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 140 |  | 
|  | 141 | private: | 
|  | 142 | HDCPModule(const HDCPModule &); | 
|  | 143 | HDCPModule &operator=(const HDCPModule &); | 
|  | 144 | }; | 
|  | 145 |  | 
|  | 146 | }  // namespace android | 
|  | 147 |  | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 148 | // A shared library exporting the following methods should be included to | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 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" { | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 153 | // Create a module for ENCRYPTION. | 
| Deva Ramasubramanian | dbaaa38 | 2012-09-18 16:15:32 -0700 | [diff] [blame] | 154 | extern android::HDCPModule *createHDCPModule( | 
|  | 155 | void *cookie, android::HDCPModule::ObserverFunc); | 
| Andreas Huber | 0dcde52 | 2013-01-30 10:40:28 -0800 | [diff] [blame] | 156 |  | 
|  | 157 | // Create a module for DECRYPTION. | 
|  | 158 | extern android::HDCPModule *createHDCPModuleForDecryption( | 
|  | 159 | void *cookie, android::HDCPModule::ObserverFunc); | 
| Andreas Huber | a8fc772 | 2012-08-29 13:26:55 -0700 | [diff] [blame] | 160 | } | 
|  | 161 |  | 
|  | 162 | #endif  // HDCP_API_H_ | 
|  | 163 |  |