The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 __DRM_RIGHTS_MANAGER_H__ |
| 18 | #define __DRM_RIGHTS_MANAGER_H__ |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
Chia-chi Yeh | 64e69e8 | 2009-08-06 02:28:24 +0800 | [diff] [blame] | 24 | #include <openssl/aes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <drm_common_types.h> |
| 26 | #include <parser_rel.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | #ifdef DRM_DEVICE_ARCH_ARM |
| 29 | #define ANDROID_DRM_CORE_PATH "/data/drm/rights/" |
| 30 | #define DRM_UID_FILE_PATH "/data/drm/rights/uid.txt" |
| 31 | #else |
| 32 | #define ANDROID_DRM_CORE_PATH "/home/user/golf/esmertec/device/out/debug/host/linux-x86/product/sim/data/data/com.android.drm.mobile1/" |
| 33 | #define DRM_UID_FILE_PATH "/home/user/golf/esmertec/device/out/debug/host/linux-x86/product/sim/data/data/com.android.drm.mobile1/uid.txt" |
| 34 | #endif |
| 35 | |
| 36 | #define EXTENSION_NAME_INFO ".info" |
| 37 | |
| 38 | #define GET_ID 1 |
| 39 | #define GET_UID 2 |
| 40 | |
| 41 | #define GET_ROAMOUNT 1 |
| 42 | #define GET_ALL_RO 2 |
| 43 | #define SAVE_ALL_RO 3 |
| 44 | #define GET_A_RO 4 |
| 45 | #define SAVE_A_RO 5 |
| 46 | |
| 47 | /** |
| 48 | * Get the id or uid from the "uid.txt" file. |
| 49 | * |
| 50 | * \param Uid The content id for a specially DRM object. |
| 51 | * \param id The id number managed by DRM engine for a specially DRM object. |
| 52 | * \param option The option to get id or uid, the value includes: GET_ID, GET_UID. |
| 53 | * |
| 54 | * \return |
| 55 | * -TRUE, if the operation successfully. |
| 56 | * -FALSE, if the operation failed. |
| 57 | */ |
| 58 | int32_t drm_readFromUidTxt(uint8_t* Uid, int32_t* id, int32_t option); |
| 59 | |
| 60 | /** |
| 61 | * Save or read the rights information on the "id.info" file. |
| 62 | * |
| 63 | * \param id The id number managed by DRM engine for a specially DRM object. |
| 64 | * \param Ro The rights structure to save the rights information. |
| 65 | * \param RoAmount The number of rights for this DRM object. |
| 66 | * \param option The option include: GET_ROAMOUNT, GET_ALL_RO, SAVE_ALL_RO, GET_A_RO, SAVE_A_RO. |
| 67 | * |
| 68 | * \return |
| 69 | * -TRUE, if the operation successfully. |
| 70 | * -FALSE, if the operation failed. |
| 71 | */ |
| 72 | int32_t drm_writeOrReadInfo(int32_t id, T_DRM_Rights* Ro, int32_t* RoAmount, int32_t option); |
| 73 | |
| 74 | /** |
| 75 | * Append a rights information to DRM engine storage. |
| 76 | * |
| 77 | * \param Ro The rights structure to save the rights information. |
| 78 | * |
| 79 | * return |
| 80 | * -TRUE, if the operation successfully. |
| 81 | * -FALSE, if the operation failed. |
| 82 | */ |
| 83 | int32_t drm_appendRightsInfo(T_DRM_Rights* rights); |
| 84 | |
| 85 | /** |
| 86 | * Get the mex id number from the "uid.txt" file. |
| 87 | * |
| 88 | * \return |
| 89 | * -an integer to indicate the max id number. |
| 90 | * -(-1), if the operation failed. |
| 91 | */ |
| 92 | int32_t drm_getMaxIdFromUidTxt(); |
| 93 | |
| 94 | /** |
| 95 | * Remove the "id.info" file if all the rights for this DRM object has been deleted. |
| 96 | * |
| 97 | * \param id The id number managed by DRM engine for a specially DRM object. |
| 98 | * |
| 99 | * \return |
| 100 | * -TRUE, if the operation successfully. |
| 101 | * -FALSE, if the operation failed. |
| 102 | */ |
| 103 | int32_t drm_removeIdInfoFile(int32_t id); |
| 104 | |
| 105 | /** |
| 106 | * Update the "uid.txt" file when delete the rights object. |
| 107 | * |
| 108 | * \param id The id number managed by DRM engine for a specially DRM object. |
| 109 | * |
| 110 | * \return |
| 111 | * -TRUE, if the operation successfully. |
| 112 | * -FALSE, if the operation failed. |
| 113 | */ |
| 114 | int32_t drm_updateUidTxtWhenDelete(int32_t id); |
| 115 | |
| 116 | /** |
| 117 | * Get the CEK according the given content id. |
| 118 | * |
| 119 | * \param uid The content id for a specially DRM object. |
| 120 | * \param KeyValue The buffer to save the CEK. |
| 121 | * |
| 122 | * \return |
| 123 | * -TRUE, if the operation successfully. |
| 124 | * -FALSE, if the operation failed. |
| 125 | */ |
| 126 | int32_t drm_getKey(uint8_t* uid, uint8_t* KeyValue); |
| 127 | |
| 128 | /** |
| 129 | * Discard the padding bytes in DCF decrypted data. |
| 130 | * |
| 131 | * \param decryptedBuf The aes decrypted data buffer to be scanned. |
| 132 | * \param decryptedBufLen The length of the buffer. And save the output result. |
| 133 | * |
| 134 | * \return |
| 135 | * -0 |
| 136 | */ |
| 137 | void drm_discardPaddingByte(uint8_t *decryptedBuf, int32_t *decryptedBufLen); |
| 138 | |
| 139 | /** |
| 140 | * Decrypt the media data according the CEK. |
| 141 | * |
| 142 | * \param Buffer The buffer to decrypted and also used to save the output data. |
| 143 | * \param BufferLen The length of the buffer data and also save the output data length. |
Chia-chi Yeh | 64e69e8 | 2009-08-06 02:28:24 +0800 | [diff] [blame] | 144 | * \param key The structure of the CEK. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | * |
| 146 | * \return |
| 147 | * -0 |
| 148 | */ |
Chia-chi Yeh | 64e69e8 | 2009-08-06 02:28:24 +0800 | [diff] [blame] | 149 | int32_t drm_aesDecBuffer(uint8_t * Buffer, int32_t * BufferLen, AES_KEY *key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * Update the DCF data length according the CEK. |
| 153 | * |
| 154 | * \param pDcfLastData The last several byte for the DCF. |
| 155 | * \param keyValue The CEK of the DRM content. |
| 156 | * \param moreBytes Output the more bytes for discarded. |
| 157 | * |
| 158 | * \return |
| 159 | * -TRUE, if the operation successfully. |
| 160 | * -FALSE, if the operation failed. |
| 161 | */ |
| 162 | int32_t drm_updateDcfDataLen(uint8_t* pDcfLastData, uint8_t* keyValue, int32_t* moreBytes); |
| 163 | |
| 164 | /** |
| 165 | * Check and update the rights for a specially DRM content. |
| 166 | * |
| 167 | * \param id The id number managed by DRM engine for a specially DRM object. |
| 168 | * \param permission The permission to be check and updated. |
| 169 | * |
| 170 | * \return |
| 171 | * -DRM_SUCCESS, if there is a valid rights and update it successfully. |
| 172 | * -DRM_NO_RIGHTS, if there is no rights for this content. |
| 173 | * -DRM_RIGHTS_PENDING, if the rights is pending. |
| 174 | * -DRM_RIGHTS_EXPIRED, if the rights has expired. |
| 175 | * -DRM_RIGHTS_FAILURE, if there is some other error occur. |
| 176 | */ |
| 177 | int32_t drm_checkRoAndUpdate(int32_t id, int32_t permission); |
| 178 | |
| 179 | #ifdef __cplusplus |
| 180 | } |
| 181 | #endif |
| 182 | |
| 183 | #endif /* __DRM_RIGHTS_MANAGER_H__ */ |