1 /* 2 * Copyright (C) 2014 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 #include <errno.h> 17 #include <string.h> 18 19 #include <hardware/hardware.h> 20 #include <hardware/keymaster0.h> 21 #include <keymaster/soft_keymaster_device.h> 22 23 #include "trusty_keymaster_device.h" 24 #include "trusty_keymaster_ipc.h" 25 26 using keymaster::TrustyKeymasterDevice; 27 28 /* 29 * Generic device handling 30 */ 31 static int trusty_keymaster_open(const hw_module_t* module __unused, const char* name, hw_device_t** device) { 32 if (strcmp(name, KEYSTORE_KEYMASTER) != 0) { 33 return -EINVAL; 34 } 35 // Use softkeymaster in guest instead of connecting to host implementation of softkeymaster 36 *device = reinterpret_cast<hw_device_t*>((new keymaster::SoftKeymasterDevice())->keymaster2_device()); 37 return 0; 38 } 39 40 static struct hw_module_methods_t keystore_module_methods = { 41 .open = trusty_keymaster_open, 42 }; 43 44 struct keystore_module HAL_MODULE_INFO_SYM __attribute__((visibility("default"))) = { 45 .common = 46 { 47 .tag = HARDWARE_MODULE_TAG, 48 .module_api_version = KEYMASTER_MODULE_API_VERSION_2_0, 49 .hal_api_version = HARDWARE_HAL_API_VERSION, 50 .id = KEYSTORE_HARDWARE_MODULE_ID, 51 .name = "Trusty Keymaster HAL", 52 .author = "The Android Open Source Project", 53 .methods = &keystore_module_methods, 54 .dso = 0, 55 .reserved = {}, 56 }, 57 }; 58