1 /* 2 * Copyright (C) 2017 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_HAL_H_ 18 19 #define DRM_HAL_H_ 20 21 #include <android/hardware/drm/1.0/IDrmPlugin.h> 22 #include <android/hardware/drm/1.0/IDrmPluginListener.h> 23 #include <android/hardware/drm/1.0/IDrmFactory.h> 24 25 #include <media/IDrm.h> 26 #include <media/IDrmClient.h> 27 #include <utils/threads.h> 28 29 using ::android::hardware::drm::V1_0::EventType; 30 using ::android::hardware::drm::V1_0::IDrmFactory; 31 using ::android::hardware::drm::V1_0::IDrmPlugin; 32 using ::android::hardware::drm::V1_0::IDrmPluginListener; 33 using ::android::hardware::drm::V1_0::KeyStatus; 34 using ::android::hardware::hidl_vec; 35 using ::android::hardware::Return; 36 using ::android::hardware::Void; 37 38 namespace android { 39 40 struct DrmSessionClientInterface; 41 42 struct DrmHal : public BnDrm, 43 public IBinder::DeathRecipient, 44 public IDrmPluginListener { 45 DrmHal(); 46 virtual ~DrmHal(); 47 48 virtual status_t initCheck() const; 49 50 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType); 51 52 virtual status_t createPlugin(const uint8_t uuid[16], 53 const String8 &appPackageName); 54 55 virtual status_t destroyPlugin(); 56 57 virtual status_t openSession(Vector<uint8_t> &sessionId); 58 59 virtual status_t closeSession(Vector<uint8_t> const &sessionId); 60 61 virtual status_t 62 getKeyRequest(Vector<uint8_t> const &sessionId, 63 Vector<uint8_t> const &initData, 64 String8 const &mimeType, DrmPlugin::KeyType keyType, 65 KeyedVector<String8, String8> const &optionalParameters, 66 Vector<uint8_t> &request, String8 &defaultUrl, 67 DrmPlugin::KeyRequestType *keyRequestType); 68 69 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId, 70 Vector<uint8_t> const &response, 71 Vector<uint8_t> &keySetId); 72 73 virtual status_t removeKeys(Vector<uint8_t> const &keySetId); 74 75 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId, 76 Vector<uint8_t> const &keySetId); 77 78 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId, 79 KeyedVector<String8, String8> &infoMap) const; 80 81 virtual status_t getProvisionRequest(String8 const &certType, 82 String8 const &certAuthority, 83 Vector<uint8_t> &request, 84 String8 &defaulUrl); 85 86 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response, 87 Vector<uint8_t> &certificate, 88 Vector<uint8_t> &wrappedKey); 89 90 virtual status_t getSecureStops(List<Vector<uint8_t>> &secureStops); 91 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop); 92 93 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease); 94 virtual status_t releaseAllSecureStops(); 95 96 virtual status_t getPropertyString(String8 const &name, String8 &value ) const; 97 virtual status_t getPropertyByteArray(String8 const &name, 98 Vector<uint8_t> &value ) const; 99 virtual status_t setPropertyString(String8 const &name, String8 const &value ) const; 100 virtual status_t setPropertyByteArray(String8 const &name, 101 Vector<uint8_t> const &value ) const; 102 103 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, 104 String8 const &algorithm); 105 106 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, 107 String8 const &algorithm); 108 109 virtual status_t encrypt(Vector<uint8_t> const &sessionId, 110 Vector<uint8_t> const &keyId, 111 Vector<uint8_t> const &input, 112 Vector<uint8_t> const &iv, 113 Vector<uint8_t> &output); 114 115 virtual status_t decrypt(Vector<uint8_t> const &sessionId, 116 Vector<uint8_t> const &keyId, 117 Vector<uint8_t> const &input, 118 Vector<uint8_t> const &iv, 119 Vector<uint8_t> &output); 120 121 virtual status_t sign(Vector<uint8_t> const &sessionId, 122 Vector<uint8_t> const &keyId, 123 Vector<uint8_t> const &message, 124 Vector<uint8_t> &signature); 125 126 virtual status_t verify(Vector<uint8_t> const &sessionId, 127 Vector<uint8_t> const &keyId, 128 Vector<uint8_t> const &message, 129 Vector<uint8_t> const &signature, 130 bool &match); 131 132 virtual status_t signRSA(Vector<uint8_t> const &sessionId, 133 String8 const &algorithm, 134 Vector<uint8_t> const &message, 135 Vector<uint8_t> const &wrappedKey, 136 Vector<uint8_t> &signature); 137 138 virtual status_t setListener(const sp<IDrmClient>& listener); 139 140 // Methods of IDrmPluginListener 141 Return<void> sendEvent(EventType eventType, 142 const hidl_vec<uint8_t>& sessionId, const hidl_vec<uint8_t>& data); 143 144 Return<void> sendExpirationUpdate(const hidl_vec<uint8_t>& sessionId, 145 int64_t expiryTimeInMS); 146 147 Return<void> sendKeysChange(const hidl_vec<uint8_t>& sessionId, 148 const hidl_vec<KeyStatus>& keyStatusList, bool hasNewUsableKey); 149 150 virtual void binderDied(const wp<IBinder> &the_late_who); 151 152 private: 153 static Mutex mLock; 154 155 sp<DrmSessionClientInterface> mDrmSessionClient; 156 157 sp<IDrmClient> mListener; 158 mutable Mutex mEventLock; 159 mutable Mutex mNotifyLock; 160 161 const Vector<sp<IDrmFactory>> mFactories; 162 sp<IDrmPlugin> mPlugin; 163 164 /** 165 * mInitCheck is: 166 * NO_INIT if a plugin hasn't been created yet 167 * ERROR_UNSUPPORTED if a plugin can't be created for the uuid 168 * OK after a plugin has been created and mPlugin is valid 169 */ 170 status_t mInitCheck; 171 172 Vector<sp<IDrmFactory>> makeDrmFactories(); 173 sp<IDrmPlugin> makeDrmPlugin(const sp<IDrmFactory>& factory, 174 const uint8_t uuid[16], const String8& appPackageName); 175 176 void writeByteArray(Parcel &obj, const hidl_vec<uint8_t>& array); 177 178 DISALLOW_EVIL_CONSTRUCTORS(DrmHal); 179 }; 180 181 } // namespace android 182 183 #endif // DRM_HAL_H_ 184