1a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber/* 2a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * Copyright (C) 2012 The Android Open Source Project 3a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * 4a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 5a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * you may not use this file except in compliance with the License. 6a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * You may obtain a copy of the License at 7a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * 8a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 9a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * 10a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * Unless required by applicable law or agreed to in writing, software 11a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 12a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * See the License for the specific language governing permissions and 14a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber * limitations under the License. 15a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber */ 16a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 17a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber#ifndef HDCP_API_H_ 18a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 19a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber#define HDCP_API_H_ 20a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 21a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber#include <utils/Errors.h> 22685e68130b99d835a8846f6b70520af360213bb0Chong Zhang#include <system/window.h> 23a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 24a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Hubernamespace android { 25a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 260dcde5213ba6531f2895f340f523c09895275f51Andreas Huber// Two different kinds of modules are covered under the same HDCPModule 270dcde5213ba6531f2895f340f523c09895275f51Andreas Huber// structure below, a module either implements decryption or encryption. 28a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huberstruct HDCPModule { 29dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2); 30a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 31a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // The msg argument in calls to the observer notification function. 32a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber enum { 33a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // Sent in response to a call to "HDCPModule::initAsync" once 34a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // initialization has either been successfully completed, 35a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // i.e. the HDCP session is now fully setup (AKE, Locality Check, 36a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // SKE and any authentication with repeaters completed) or failed. 37a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // ext1 should be a suitable error code (status_t), ext2 is 380dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE 390dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // holds the local TCP port the module is listening on. 40a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber HDCP_INITIALIZATION_COMPLETE, 41dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_INITIALIZATION_FAILED, 42a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 43a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // Sent upon completion of a call to "HDCPModule::shutdownAsync". 44a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // ext1 should be a suitable error code, ext2 is unused. 45a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber HDCP_SHUTDOWN_COMPLETE, 46dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_SHUTDOWN_FAILED, 47dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian 48dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_UNAUTHENTICATED_CONNECTION, 49dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_UNAUTHORIZED_CONNECTION, 50dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_REVOKED_CONNECTION, 51dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_TOPOLOGY_EXECEEDED, 52dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian HDCP_UNKNOWN_ERROR, 530dcde5213ba6531f2895f340f523c09895275f51Andreas Huber 540dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // DECRYPTION only: Indicates that a client has successfully connected, 550dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // a secure session established and the module is ready to accept 560dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // future calls to "decrypt". 570dcde5213ba6531f2895f340f523c09895275f51Andreas Huber HDCP_SESSION_ESTABLISHED, 58a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber }; 59a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 60a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // HDCPModule capability bit masks 61a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang enum { 62a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // HDCP_CAPS_ENCRYPT: mandatory, meaning the HDCP module can encrypt 63a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // from an input byte-array buffer to an output byte-array buffer 64a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang HDCP_CAPS_ENCRYPT = (1 << 0), 65a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // HDCP_CAPS_ENCRYPT_NATIVE: the HDCP module supports encryption from 66a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // a native buffer to an output byte-array buffer. The format of the 67a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // input native buffer is specific to vendor's encoder implementation. 68a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // It is the same format as that used by the encoder when 69a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang // "storeMetaDataInBuffers" extension is enabled on its output port. 70a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang HDCP_CAPS_ENCRYPT_NATIVE = (1 << 1), 71a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang }; 72a3a918557dbe6413a233a63dd47eb1781cb00ea4Chong Zhang 73a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // Module can call the notification function to signal completion/failure 74a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // of asynchronous operations (such as initialization) or out of band 75a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // events. 7620131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen HDCPModule(void * /*cookie*/, ObserverFunc /*observerNotify*/) {}; 77a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 78dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian virtual ~HDCPModule() {}; 79a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 800dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // ENCRYPTION: Request to setup an HDCP session with the host specified 810dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // by addr and listening on the specified port. 820dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // DECRYPTION: Request to setup an HDCP session, addr is the interface 830dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // address the module should bind its socket to. port will be 0. 840dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // The module will pick the port to listen on itself and report its choice 850dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // in the "ext2" argument of the HDCP_INITIALIZATION_COMPLETE callback. 860dcde5213ba6531f2895f340f523c09895275f51Andreas Huber virtual status_t initAsync(const char *addr, unsigned port) = 0; 87a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 88a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // Request to shutdown the active HDCP session. 89a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber virtual status_t shutdownAsync() = 0; 90a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 91b344adf0892e37fe50aabcf7f8ad01f3473bbb4dChong Zhang // Returns the capability bitmask of this HDCP session. 92b344adf0892e37fe50aabcf7f8ad01f3473bbb4dChong Zhang virtual uint32_t getCaps() { 93b344adf0892e37fe50aabcf7f8ad01f3473bbb4dChong Zhang return HDCP_CAPS_ENCRYPT; 94b344adf0892e37fe50aabcf7f8ad01f3473bbb4dChong Zhang } 95b344adf0892e37fe50aabcf7f8ad01f3473bbb4dChong Zhang 960dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // ENCRYPTION only: 970dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // Encrypt data according to the HDCP spec. "size" bytes of data are 980dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // available at "inData" (virtual address), "size" may not be a multiple 990dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // of 128 bits (16 bytes). An equal number of encrypted bytes should be 1000dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // written to the buffer at "outData" (virtual address). 101a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // This operation is to be synchronous, i.e. this call does not return 102a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // until outData contains size bytes of encrypted data. 103a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // streamCTR will be assigned by the caller (to 0 for the first PES stream, 104a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber // 1 for the second and so on) 1050dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // inputCTR _will_be_maintained_by_the_callee_ for each PES stream. 106a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber virtual status_t encrypt( 10720131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen const void * /*inData*/, size_t /*size*/, uint32_t /*streamCTR*/, 10820131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen uint64_t * /*outInputCTR*/, void * /*outData*/) { 1090dcde5213ba6531f2895f340f523c09895275f51Andreas Huber return INVALID_OPERATION; 1100dcde5213ba6531f2895f340f523c09895275f51Andreas Huber } 1110dcde5213ba6531f2895f340f523c09895275f51Andreas Huber 112685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // Encrypt data according to the HDCP spec. "size" bytes of data starting 113685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // at location "offset" are available in "buffer" (buffer handle). "size" 114685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // may not be a multiple of 128 bits (16 bytes). An equal number of 115685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // encrypted bytes should be written to the buffer at "outData" (virtual 116685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // address). This operation is to be synchronous, i.e. this call does not 117685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // return until outData contains size bytes of encrypted data. 118685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // streamCTR will be assigned by the caller (to 0 for the first PES stream, 119685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // 1 for the second and so on) 120685e68130b99d835a8846f6b70520af360213bb0Chong Zhang // inputCTR _will_be_maintained_by_the_callee_ for each PES stream. 121685e68130b99d835a8846f6b70520af360213bb0Chong Zhang virtual status_t encryptNative( 12220131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen buffer_handle_t /*buffer*/, size_t /*offset*/, size_t /*size*/, 12320131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen uint32_t /*streamCTR*/, uint64_t * /*outInputCTR*/, void * /*outData*/) { 124685e68130b99d835a8846f6b70520af360213bb0Chong Zhang return INVALID_OPERATION; 125685e68130b99d835a8846f6b70520af360213bb0Chong Zhang } 1260dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // DECRYPTION only: 1270dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // Decrypt data according to the HDCP spec. 1280dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // "size" bytes of encrypted data are available at "inData" 1290dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // (virtual address), "size" may not be a multiple of 128 bits (16 bytes). 1300dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // An equal number of decrypted bytes should be written to the buffer 1310dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // at "outData" (virtual address). 1320dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // This operation is to be synchronous, i.e. this call does not return 1330dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // until outData contains size bytes of decrypted data. 1340dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // Both streamCTR and inputCTR will be provided by the caller. 1350dcde5213ba6531f2895f340f523c09895275f51Andreas Huber virtual status_t decrypt( 13620131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen const void * /*inData*/, size_t /*size*/, 13720131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen uint32_t /*streamCTR*/, uint64_t /*inputCTR*/, 13820131921f2750c47388625575b2ed91eb2ad0d5aDan Willemsen void * /*outData*/) { 1390dcde5213ba6531f2895f340f523c09895275f51Andreas Huber return INVALID_OPERATION; 1400dcde5213ba6531f2895f340f523c09895275f51Andreas Huber } 141a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 142a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huberprivate: 143a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber HDCPModule(const HDCPModule &); 144a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber HDCPModule &operator=(const HDCPModule &); 145a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber}; 146a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 147a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber} // namespace android 148a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 1490dcde5213ba6531f2895f340f523c09895275f51Andreas Huber// A shared library exporting the following methods should be included to 150a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber// support HDCP functionality. The shared library must be called 151a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber// "libstagefright_hdcp.so", it will be dynamically loaded into the 152a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber// mediaserver process. 153a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huberextern "C" { 1540dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // Create a module for ENCRYPTION. 155dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian extern android::HDCPModule *createHDCPModule( 156dbaaa38882b8f13c1ff3a0ea352584cdbbbcba72Deva Ramasubramanian void *cookie, android::HDCPModule::ObserverFunc); 1570dcde5213ba6531f2895f340f523c09895275f51Andreas Huber 1580dcde5213ba6531f2895f340f523c09895275f51Andreas Huber // Create a module for DECRYPTION. 1590dcde5213ba6531f2895f340f523c09895275f51Andreas Huber extern android::HDCPModule *createHDCPModuleForDecryption( 1600dcde5213ba6531f2895f340f523c09895275f51Andreas Huber void *cookie, android::HDCPModule::ObserverFunc); 161a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber} 162a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 163a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber#endif // HDCP_API_H_ 164a8fc772b5b13e359fa73d5867c0f617b8eae4a41Andreas Huber 165