• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ashmem.h"
17 #include "drm_error_code.h"
18 #include "media_decrypt_module_service_proxy.h"
19 
20 namespace OHOS {
21 namespace DrmStandard {
MediaDecryptModuleServiceProxy(const sptr<IRemoteObject> & impl)22 MediaDecryptModuleServiceProxy::MediaDecryptModuleServiceProxy(const sptr<IRemoteObject> &impl)
23     : IRemoteProxy<IMediaDecryptModuleService>(impl)
24 {
25     DRM_DEBUG_LOG("MediaDecryptModuleServiceProxy::MediaKeySystemServiceProxy Initialized.");
26 }
27 
Release()28 int32_t MediaDecryptModuleServiceProxy::Release()
29 {
30     DRM_INFO_LOG("MediaDecryptModuleServiceProxy::Release enter.");
31     MessageParcel data;
32     MessageParcel reply;
33     MessageOption option;
34 
35     if (!data.WriteInterfaceToken(GetDescriptor())) {
36         DRM_ERR_LOG("MediaDecryptModuleServiceProxy Release Write interface token failed");
37         return IPC_PROXY_ERR;
38     }
39 
40     int32_t ret = Remote()->SendRequest(DECRYPT_MODULE_RELEASE, data, reply, option);
41     if (ret != ERR_NONE) {
42         DRM_ERR_LOG("MediaDecryptModuleServiceProxy::Release failed, ret: %{public}d", ret);
43         return ret;
44     }
45 
46     DRM_INFO_LOG("MediaDecryptModuleServiceProxy::Release exit.");
47     return ret;
48 }
49 
ProcessDrmBuffer(MessageParcel & data,IMediaDecryptModuleService::DrmBuffer & srcBuffer,IMediaDecryptModuleService::DrmBuffer & dstBuffer)50 int32_t MediaDecryptModuleServiceProxy::ProcessDrmBuffer(MessageParcel &data,
51     IMediaDecryptModuleService::DrmBuffer &srcBuffer, IMediaDecryptModuleService::DrmBuffer &dstBuffer)
52 {
53     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(srcBuffer.bufferType), IPC_PROXY_ERR,
54         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.bufferType failed");
55     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteFileDescriptor(srcBuffer.fd), IPC_PROXY_ERR,
56         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.fd failed");
57     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(srcBuffer.bufferLen), IPC_PROXY_ERR,
58         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.bufferLen failed");
59     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(srcBuffer.allocLen), IPC_PROXY_ERR,
60         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.allocLen failed");
61     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(srcBuffer.filledLen), IPC_PROXY_ERR,
62         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.filledLen failed");
63     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(srcBuffer.offset), IPC_PROXY_ERR,
64         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.offset failed");
65     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(srcBuffer.sharedMemType), IPC_PROXY_ERR,
66         "MediaDecryptModuleServiceProxy DecryptMediaData Write srcBuffer.sharedMemType failed");
67 
68     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(dstBuffer.bufferType), IPC_PROXY_ERR,
69         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.bufferType failed");
70     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteFileDescriptor(dstBuffer.fd), IPC_PROXY_ERR,
71         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.fd failed");
72     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(dstBuffer.bufferLen), IPC_PROXY_ERR,
73         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.bufferLen failed");
74     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(dstBuffer.allocLen), IPC_PROXY_ERR,
75         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.allocLen failed");
76     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(dstBuffer.filledLen), IPC_PROXY_ERR,
77         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.filledLen failed");
78     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(dstBuffer.offset), IPC_PROXY_ERR,
79         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.offset failed");
80     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(dstBuffer.sharedMemType), IPC_PROXY_ERR,
81         "MediaDecryptModuleServiceProxy DecryptMediaData Write dstBuffer.sharedMemType failed");
82     return DRM_OK;
83 }
84 
DecryptMediaData(bool secureDecodrtState,IMediaDecryptModuleService::CryptInfo & cryptInfo,IMediaDecryptModuleService::DrmBuffer & srcBuffer,IMediaDecryptModuleService::DrmBuffer & dstBuffer)85 int32_t MediaDecryptModuleServiceProxy::DecryptMediaData(bool secureDecodrtState,
86     IMediaDecryptModuleService::CryptInfo &cryptInfo, IMediaDecryptModuleService::DrmBuffer &srcBuffer,
87     IMediaDecryptModuleService::DrmBuffer &dstBuffer)
88 {
89     DRM_INFO_LOG("MediaDecryptModuleServiceProxy::DecryptMediaData enter.");
90     MessageParcel data;
91     MessageParcel reply;
92     MessageOption option;
93 
94     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), IPC_PROXY_ERR,
95         "MediaDecryptModuleServiceProxy DecryptMediaData Write interface token failed");
96 
97     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteBool(secureDecodrtState), IPC_PROXY_ERR,
98         "MediaDecryptModuleServiceProxy DecryptMediaData Write secureDecodrtState failed");
99 
100     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.type), IPC_PROXY_ERR,
101         "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.type failed");
102 
103     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.keyId.size()), IPC_PROXY_ERR,
104         "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.keyId size failed");
105     DRM_CHECK_AND_RETURN_RET_LOG(cryptInfo.keyId.size() < KEYID_MAX_LEN, DRM_MEMORY_ERROR,
106         "The size of keyId is too large.");
107     if (cryptInfo.keyId.size() != 0) {
108         DRM_CHECK_AND_RETURN_RET_LOG(data.WriteBuffer(cryptInfo.keyId.data(), cryptInfo.keyId.size()), IPC_PROXY_ERR,
109             "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.keyId failed");
110     }
111 
112     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.iv.size()), IPC_PROXY_ERR,
113         "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.iv size failed");
114     DRM_CHECK_AND_RETURN_RET_LOG(cryptInfo.iv.size() < IV_MAX_LEN, DRM_MEMORY_ERROR, "The size of iv is too large.");
115 
116     if (cryptInfo.iv.size() != 0) {
117         DRM_CHECK_AND_RETURN_RET_LOG(data.WriteBuffer(cryptInfo.iv.data(), cryptInfo.iv.size()), IPC_PROXY_ERR,
118             "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.iv failed");
119     }
120 
121     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.pattern.encryptBlocks), IPC_PROXY_ERR,
122         "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.pattern.encryptBlocks failed");
123 
124     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.pattern.skipBlocks), IPC_PROXY_ERR,
125         "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.pattern.skipBlocks failed");
126 
127     DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.subSample.size()), IPC_PROXY_ERR,
128         "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.subSample size failed");
129     for (size_t i = 0; i < cryptInfo.subSample.size(); i++) {
130         DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.subSample[i].clearHeaderLen), IPC_PROXY_ERR,
131             "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.subSample.clearHeaderLen failed");
132 
133         DRM_CHECK_AND_RETURN_RET_LOG(data.WriteUint32(cryptInfo.subSample[i].payLoadLen), IPC_PROXY_ERR,
134             "MediaDecryptModuleServiceProxy DecryptMediaData Write cryptInfo.subSample.payLoadLen failed");
135     }
136     int32_t ret = ProcessDrmBuffer(data, srcBuffer, dstBuffer);
137     DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, IPC_PROXY_ERR,
138         "MediaDecryptModuleServiceProxy DecryptMediaData failed, ret: %{public}d", ret);
139 
140     ret = Remote()->SendRequest(DECRYPT_MODULE_DECRYPT_DATA, data, reply, option);
141     DRM_CHECK_AND_RETURN_RET_LOG(ret == ERR_NONE, IPC_PROXY_ERR,
142         "MediaDecryptModuleServiceProxy DecryptMediaData failed, ret: %{public}d", ret);
143 
144     DRM_INFO_LOG("MediaDecryptModuleServiceProxy::DecryptMediaData exit.");
145     return ret;
146 }
147 } // DrmStandard
148 } // OHOS