1 /* 2 * Copyright (c) 2023 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) do { \ 31 if ((lv) compare (rv)) { \ 32 return ret; \ 33 } \ 34 } while (false) 35 #endif 36 37 #ifndef HDI_CHECK_VALUE_RET_GOTO 38 #define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ 39 if ((lv) compare (rv)) { \ 40 ret = value; \ 41 goto table; \ 42 } \ 43 } while (false) 44 #endif 45 46 namespace OHOS { 47 class MessageParcel; 48 } 49 50 namespace OHOS { 51 namespace HDI { 52 namespace Drm { 53 namespace V1_0 { 54 55 using namespace OHOS; 56 57 enum ContentProtectionLevel : int32_t { 58 SECURE_UNKNOWN = 0, 59 SW_SECURE_CRYPTO, 60 HW_SECURE_CRYPTO, 61 HW_ENHANCED_SECURE_CRYPTO, 62 HW_SECURE_MAX, 63 }; 64 65 enum MediaKeyRequestType : int32_t { 66 MEDIA_KEY_REQUEST_TYPE_UNKNOWN = 0, 67 MEDIA_KEY_REQUEST_TYPE_INITIAL, 68 MEDIA_KEY_REQUEST_TYPE_RENEWAL, 69 MEDIA_KEY_REQUEST_TYPE_RELEASE, 70 MEDIA_KEY_REQUEST_TYPE_NONE, 71 MEDIA_KEY_REQUEST_TYPE_UPDATE, 72 }; 73 74 enum EventType : int32_t { 75 EVENTTYPE_PROVISIONREQUIRED = 0, 76 EVENTTYPE_KEYREQUIRED, 77 EVENTTYPE_KEYEXPIRED, 78 EVENTTYPE_VENDOR_DEFINED, 79 EVENTTYPE_EXPIRATIONUPDATE, 80 EVENTTYPE_KEYCHANGE, 81 }; 82 83 enum CryptoAlgorithmType : int32_t { 84 ALGTYPE_UNENCRYPTED = 0, 85 ALGTYPE_AES_CTR, 86 ALGTYPE_AES_WV, 87 ALGTYPE_AES_CBC, 88 ALGTYPE_SM4_CBC, 89 ALGTYPE_SM4_CTR, 90 }; 91 92 enum OfflineMediaKeyStatus : int32_t { 93 OFFLINE_MEDIA_KEY_STATUS_UNKNOWN = 0, 94 OFFLINE_MEDIA_KEY_STATUS_USABLE, 95 OFFLINE_MEDIA_KEY_STATUS_INACTIVE, 96 }; 97 98 enum MediaKeyType : int32_t { 99 MEDIA_KEY_TYPE_OFFLINE = 0, 100 MEDIA_KEY_TYPE_ONLINE, 101 }; 102 103 enum CertificateStatus : int32_t { 104 CERT_STATUS_PROVISIONED = 0, 105 CERT_STATUS_NOT_PROVISIONED, 106 CERT_STATUS_EXPIRED, 107 CERT_STATUS_INVALID, 108 CERT_STATUS_UNAVAILABLE, 109 }; 110 111 enum MediaKeySessionKeyStatus : int32_t { 112 MEDIA_KEY_SESSION_KEY_STATUS_USABLE = 0, 113 MEDIA_KEY_SESSION_KEY_STATUS_EXPIRED, 114 MEDIA_KEY_SESSION_KEY_STATUS_OUTPUT_NOT_ALLOWED, 115 MEDIA_KEY_SESSION_KEY_STATUS_PENDING, 116 MEDIA_KEY_SESSION_KEY_STATUS_INTERNAL_ERROR, 117 MEDIA_KEY_SESSION_KEY_STATUS_USABLE_IN_FUTURE, 118 }; 119 120 struct MediaKeyRequestInfo { 121 OHOS::HDI::Drm::V1_0::MediaKeyType mediaKeyType; 122 std::string mimeType; 123 std::vector<uint8_t> initData; 124 std::map<std::string, std::string> optionalData; 125 }; 126 127 struct MediaKeyRequest { 128 OHOS::HDI::Drm::V1_0::MediaKeyRequestType requestType; 129 std::vector<uint8_t> data; 130 std::string defaultUrl; 131 }; 132 133 struct Pattern { 134 uint32_t encryptBlocks; 135 uint32_t skipBlocks; 136 } __attribute__ ((aligned(8))); 137 138 struct SubSample { 139 uint32_t clearHeaderLen; 140 uint32_t payLoadLen; 141 } __attribute__ ((aligned(8))); 142 143 struct CryptoInfo { 144 OHOS::HDI::Drm::V1_0::CryptoAlgorithmType type; 145 std::vector<uint8_t> keyId; 146 std::vector<uint8_t> iv; 147 OHOS::HDI::Drm::V1_0::Pattern pattern; 148 std::vector<OHOS::HDI::Drm::V1_0::SubSample> subSamples; 149 }; 150 151 struct DrmBuffer { 152 uint32_t bufferType; 153 int fd; 154 uint32_t bufferLen; 155 uint32_t allocLen; 156 uint32_t filledLen; 157 uint32_t offset; 158 uint32_t sharedMemType; 159 }; 160 161 bool MediaKeyRequestInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo& dataBlock); 162 163 bool MediaKeyRequestInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo& dataBlock); 164 165 bool MediaKeyRequestBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::MediaKeyRequest& dataBlock); 166 167 bool MediaKeyRequestBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::MediaKeyRequest& dataBlock); 168 169 bool PatternBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::Pattern& dataBlock); 170 171 bool PatternBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::Pattern& dataBlock); 172 173 bool SubSampleBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::SubSample& dataBlock); 174 175 bool SubSampleBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::SubSample& dataBlock); 176 177 bool CryptoInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::CryptoInfo& dataBlock); 178 179 bool CryptoInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::CryptoInfo& dataBlock); 180 181 bool DrmBufferBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Drm::V1_0::DrmBuffer& dataBlock); 182 183 bool DrmBufferBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Drm::V1_0::DrmBuffer& dataBlock); 184 185 } // V1_0 186 } // Drm 187 } // HDI 188 } // OHOS 189 190 #endif // OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMTYPES_H