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