1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMTYPES_H 17 #define OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMTYPES_H 18 19 #include <cstdbool> 20 #include <cstdint> 21 #include <map> 22 #include <string> 23 #include <vector> 24 25 #ifndef HDI_BUFF_MAX_SIZE 26 #define HDI_BUFF_MAX_SIZE (1024 * 200) 27 #endif 28 29 #ifndef HDI_CHECK_VALUE_RETURN 30 #define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) \ 31 do { \ 32 if ((lv)compare(rv)) { \ 33 return ret; \ 34 } \ 35 } while (false) 36 #endif 37 38 #ifndef HDI_CHECK_VALUE_RET_GOTO 39 #define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) \ 40 do { \ 41 if ((lv)compare(rv)) { \ 42 ret = value; \ 43 goto table; \ 44 } \ 45 } while (false) 46 #endif 47 48 namespace OHOS { 49 class MessageParcel; 50 } 51 52 namespace OHOS { 53 namespace HDI { 54 namespace Drm { 55 namespace V1_0 { 56 using namespace OHOS; 57 58 enum ContentProtectionLevel : int32_t { 59 SECURE_UNKNOWN = 0, 60 SW_SECURE_CRYPTO, 61 HW_SECURE_CRYPTO, 62 HW_ENHANCED_SECURE_CRYPTO, 63 HW_SECURE_MAX, 64 }; 65 66 enum MediaKeyRequestType : int32_t { 67 MEDIA_KEY_REQUEST_TYPE_UNKNOWN = 0, 68 MEDIA_KEY_REQUEST_TYPE_INITIAL, 69 MEDIA_KEY_REQUEST_TYPE_RENEWAL, 70 MEDIA_KEY_REQUEST_TYPE_RELEASE, 71 MEDIA_KEY_REQUEST_TYPE_NONE, 72 MEDIA_KEY_REQUEST_TYPE_UPDATE, 73 }; 74 75 enum EventType : int32_t { 76 EVENTTYPE_PROVISIONREQUIRED = 0, 77 EVENTTYPE_KEYREQUIRED, 78 EVENTTYPE_KEYEXPIRED, 79 EVENTTYPE_VENDOR_DEFINED, 80 EVENTTYPE_EXPIRATIONUPDATE, 81 EVENTTYPE_KEYCHANGE, 82 }; 83 84 enum CryptoAlgorithmType : int32_t { 85 ALGTYPE_UNENCRYPTED = 0, 86 ALGTYPE_AES_CTR, 87 ALGTYPE_AES_WV, 88 ALGTYPE_AES_CBC, 89 ALGTYPE_SM4_CBC, 90 ALGTYPE_SM4_CTR, 91 }; 92 93 enum OfflineMediaKeyStatus : int32_t { 94 OFFLINE_MEDIA_KEY_STATUS_UNKNOWN = 0, 95 OFFLINE_MEDIA_KEY_STATUS_USABLE, 96 OFFLINE_MEDIA_KEY_STATUS_INACTIVE, 97 }; 98 99 enum MediaKeyType : int32_t { 100 MEDIA_KEY_TYPE_OFFLINE = 0, 101 MEDIA_KEY_TYPE_ONLINE, 102 }; 103 104 enum CertificateStatus : int32_t { 105 CERT_STATUS_PROVISIONED = 0, 106 CERT_STATUS_NOT_PROVISIONED, 107 CERT_STATUS_EXPIRED, 108 CERT_STATUS_INVALID, 109 CERT_STATUS_UNAVAILABLE, 110 }; 111 112 enum MediaKeySessionKeyStatus : int32_t { 113 MEDIA_KEY_SESSION_KEY_STATUS_USABLE = 0, 114 MEDIA_KEY_SESSION_KEY_STATUS_EXPIRED, 115 MEDIA_KEY_SESSION_KEY_STATUS_OUTPUT_NOT_ALLOWED, 116 MEDIA_KEY_SESSION_KEY_STATUS_PENDING, 117 MEDIA_KEY_SESSION_KEY_STATUS_INTERNAL_ERROR, 118 MEDIA_KEY_SESSION_KEY_STATUS_USABLE_IN_FUTURE, 119 }; 120 121 struct MediaKeyRequestInfo { 122 OHOS::HDI::Drm::V1_0::MediaKeyType mediaKeyType; 123 std::string mimeType; 124 std::vector<uint8_t> initData; 125 std::map<std::string, std::string> optionalData; 126 }; 127 128 struct MediaKeyRequest { 129 OHOS::HDI::Drm::V1_0::MediaKeyRequestType requestType; 130 std::vector<uint8_t> data; 131 std::string defaultUrl; 132 }; 133 134 struct Pattern { 135 uint32_t encryptBlocks; 136 uint32_t skipBlocks; 137 } __attribute__((aligned(8))); 138 139 struct SubSample { 140 uint32_t clearHeaderLen; 141 uint32_t payLoadLen; 142 } __attribute__((aligned(8))); 143 144 struct CryptoInfo { 145 OHOS::HDI::Drm::V1_0::CryptoAlgorithmType type; 146 std::vector<uint8_t> keyId; 147 std::vector<uint8_t> iv; 148 OHOS::HDI::Drm::V1_0::Pattern pattern; 149 std::vector<OHOS::HDI::Drm::V1_0::SubSample> subSamples; 150 }; 151 152 struct DrmBuffer { 153 uint32_t bufferType; 154 int fd; 155 uint32_t bufferLen; 156 uint32_t allocLen; 157 uint32_t filledLen; 158 uint32_t offset; 159 uint32_t sharedMemType; 160 }; 161 162 bool MediaKeyRequestInfoBlockMarshalling(OHOS::MessageParcel &data, 163 const OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo &dataBlock); 164 165 bool MediaKeyRequestInfoBlockUnmarshalling(OHOS::MessageParcel &data, 166 OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo &dataBlock); 167 168 bool MediaKeyRequestBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::MediaKeyRequest &dataBlock); 169 170 bool MediaKeyRequestBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::MediaKeyRequest &dataBlock); 171 172 bool PatternBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::Pattern &dataBlock); 173 174 bool PatternBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::Pattern &dataBlock); 175 176 bool SubSampleBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::SubSample &dataBlock); 177 178 bool SubSampleBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::SubSample &dataBlock); 179 180 bool CryptoInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::CryptoInfo &dataBlock); 181 182 bool CryptoInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::CryptoInfo &dataBlock); 183 184 bool DrmBufferBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::DrmBuffer &dataBlock); 185 186 bool DrmBufferBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::DrmBuffer &dataBlock); 187 } // V1_0 188 } // Drm 189 } // HDI 190 } // OHOS 191 192 #endif // OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMTYPES_H