2012-08-29 20:26:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HDCP_API_H_
|
|
|
|
|
|
|
|
#define HDCP_API_H_
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
2013-05-16 20:11:27 +00:00
|
|
|
#include <system/window.h>
|
2012-08-29 20:26:55 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2013-01-30 18:40:28 +00:00
|
|
|
// Two different kinds of modules are covered under the same HDCPModule
|
|
|
|
// structure below, a module either implements decryption or encryption.
|
2012-08-29 20:26:55 +00:00
|
|
|
struct HDCPModule {
|
2012-09-18 23:15:32 +00:00
|
|
|
typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2);
|
2012-08-29 20:26:55 +00:00
|
|
|
|
|
|
|
// The msg argument in calls to the observer notification function.
|
|
|
|
enum {
|
|
|
|
// Sent in response to a call to "HDCPModule::initAsync" once
|
|
|
|
// initialization has either been successfully completed,
|
|
|
|
// i.e. the HDCP session is now fully setup (AKE, Locality Check,
|
|
|
|
// SKE and any authentication with repeaters completed) or failed.
|
|
|
|
// ext1 should be a suitable error code (status_t), ext2 is
|
2013-01-30 18:40:28 +00:00
|
|
|
// unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE
|
|
|
|
// holds the local TCP port the module is listening on.
|
2012-08-29 20:26:55 +00:00
|
|
|
HDCP_INITIALIZATION_COMPLETE,
|
2012-09-18 23:15:32 +00:00
|
|
|
HDCP_INITIALIZATION_FAILED,
|
2012-08-29 20:26:55 +00:00
|
|
|
|
|
|
|
// Sent upon completion of a call to "HDCPModule::shutdownAsync".
|
|
|
|
// ext1 should be a suitable error code, ext2 is unused.
|
|
|
|
HDCP_SHUTDOWN_COMPLETE,
|
2012-09-18 23:15:32 +00:00
|
|
|
HDCP_SHUTDOWN_FAILED,
|
|
|
|
|
|
|
|
HDCP_UNAUTHENTICATED_CONNECTION,
|
|
|
|
HDCP_UNAUTHORIZED_CONNECTION,
|
|
|
|
HDCP_REVOKED_CONNECTION,
|
|
|
|
HDCP_TOPOLOGY_EXECEEDED,
|
|
|
|
HDCP_UNKNOWN_ERROR,
|
2013-01-30 18:40:28 +00:00
|
|
|
|
|
|
|
// DECRYPTION only: Indicates that a client has successfully connected,
|
|
|
|
// a secure session established and the module is ready to accept
|
|
|
|
// future calls to "decrypt".
|
|
|
|
HDCP_SESSION_ESTABLISHED,
|
2012-08-29 20:26:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Module can call the notification function to signal completion/failure
|
|
|
|
// of asynchronous operations (such as initialization) or out of band
|
|
|
|
// events.
|
2012-09-18 23:15:32 +00:00
|
|
|
HDCPModule(void *cookie, ObserverFunc observerNotify) {};
|
2012-08-29 20:26:55 +00:00
|
|
|
|
2012-09-18 23:15:32 +00:00
|
|
|
virtual ~HDCPModule() {};
|
2012-08-29 20:26:55 +00:00
|
|
|
|
2013-01-30 18:40:28 +00:00
|
|
|
// ENCRYPTION: Request to setup an HDCP session with the host specified
|
|
|
|
// by addr and listening on the specified port.
|
|
|
|
// DECRYPTION: Request to setup an HDCP session, addr is the interface
|
|
|
|
// address the module should bind its socket to. port will be 0.
|
|
|
|
// The module will pick the port to listen on itself and report its choice
|
|
|
|
// in the "ext2" argument of the HDCP_INITIALIZATION_COMPLETE callback.
|
|
|
|
virtual status_t initAsync(const char *addr, unsigned port) = 0;
|
2012-08-29 20:26:55 +00:00
|
|
|
|
|
|
|
// Request to shutdown the active HDCP session.
|
|
|
|
virtual status_t shutdownAsync() = 0;
|
|
|
|
|
2013-01-30 18:40:28 +00:00
|
|
|
// ENCRYPTION only:
|
|
|
|
// Encrypt data according to the HDCP spec. "size" bytes of data are
|
|
|
|
// available at "inData" (virtual address), "size" may not be a multiple
|
|
|
|
// of 128 bits (16 bytes). An equal number of encrypted bytes should be
|
|
|
|
// written to the buffer at "outData" (virtual address).
|
2012-08-29 20:26:55 +00:00
|
|
|
// This operation is to be synchronous, i.e. this call does not return
|
|
|
|
// until outData contains size bytes of encrypted data.
|
|
|
|
// streamCTR will be assigned by the caller (to 0 for the first PES stream,
|
|
|
|
// 1 for the second and so on)
|
2013-01-30 18:40:28 +00:00
|
|
|
// inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
|
2012-08-29 20:26:55 +00:00
|
|
|
virtual status_t encrypt(
|
|
|
|
const void *inData, size_t size, uint32_t streamCTR,
|
2013-01-30 18:40:28 +00:00
|
|
|
uint64_t *outInputCTR, void *outData) {
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:11:27 +00:00
|
|
|
// Encrypt data according to the HDCP spec. "size" bytes of data starting
|
|
|
|
// at location "offset" are available in "buffer" (buffer handle). "size"
|
|
|
|
// may not be a multiple of 128 bits (16 bytes). An equal number of
|
|
|
|
// encrypted bytes should be written to the buffer at "outData" (virtual
|
|
|
|
// address). This operation is to be synchronous, i.e. this call does not
|
|
|
|
// return until outData contains size bytes of encrypted data.
|
|
|
|
// streamCTR will be assigned by the caller (to 0 for the first PES stream,
|
|
|
|
// 1 for the second and so on)
|
|
|
|
// inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
|
|
|
|
virtual status_t encryptNative(
|
|
|
|
buffer_handle_t buffer, size_t offset, size_t size,
|
|
|
|
uint32_t streamCTR, uint64_t *outInputCTR, void *outData) {
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
2013-01-30 18:40:28 +00:00
|
|
|
// DECRYPTION only:
|
|
|
|
// Decrypt data according to the HDCP spec.
|
|
|
|
// "size" bytes of encrypted data are available at "inData"
|
|
|
|
// (virtual address), "size" may not be a multiple of 128 bits (16 bytes).
|
|
|
|
// An equal number of decrypted bytes should be written to the buffer
|
|
|
|
// at "outData" (virtual address).
|
|
|
|
// This operation is to be synchronous, i.e. this call does not return
|
|
|
|
// until outData contains size bytes of decrypted data.
|
|
|
|
// Both streamCTR and inputCTR will be provided by the caller.
|
|
|
|
virtual status_t decrypt(
|
|
|
|
const void *inData, size_t size,
|
|
|
|
uint32_t streamCTR, uint64_t inputCTR,
|
|
|
|
void *outData) {
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
2012-08-29 20:26:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
HDCPModule(const HDCPModule &);
|
|
|
|
HDCPModule &operator=(const HDCPModule &);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace android
|
|
|
|
|
2013-01-30 18:40:28 +00:00
|
|
|
// A shared library exporting the following methods should be included to
|
2012-08-29 20:26:55 +00:00
|
|
|
// support HDCP functionality. The shared library must be called
|
|
|
|
// "libstagefright_hdcp.so", it will be dynamically loaded into the
|
|
|
|
// mediaserver process.
|
|
|
|
extern "C" {
|
2013-01-30 18:40:28 +00:00
|
|
|
// Create a module for ENCRYPTION.
|
2012-09-18 23:15:32 +00:00
|
|
|
extern android::HDCPModule *createHDCPModule(
|
|
|
|
void *cookie, android::HDCPModule::ObserverFunc);
|
2013-01-30 18:40:28 +00:00
|
|
|
|
|
|
|
// Create a module for DECRYPTION.
|
|
|
|
extern android::HDCPModule *createHDCPModuleForDecryption(
|
|
|
|
void *cookie, android::HDCPModule::ObserverFunc);
|
2012-08-29 20:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HDCP_API_H_
|
|
|
|
|