blob: 0c2d178473f4d2067e4d9a86b85052b484fc8c1f [file] [log] [blame]
Shawn Willden62de2662014-08-20 14:14:49 -06001/*
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 <keymaster/keymaster_openssl.h>
20
21#include <keystore/keystore.h>
22
23#include <hardware/hardware.h>
24#include <hardware/keymaster.h>
25
26/*
27 * Generic device handling
28 */
29static int trusty_keymaster__open(const hw_module_t* module, const char* name,
30 hw_device_t** device) {
31 if (strcmp(name, KEYSTORE_KEYMASTER) != 0)
32 return -EINVAL;
33
34 GoogleKeymasterDevice* dev = new GoogleKeymasterDevice(module);
35 if (dev == NULL)
36 return -ENOMEM;
37 *device = dev->hw_device();
38 // Do not delete dev; it will get cleaned up when the caller calls device->close(), and must
39 // exist until then.
40 return 0;
41}
42
43static struct hw_module_methods_t keystore_module_methods = {
44 .open = trusty_keymaster_open,
45};
46
47struct keystore_module HAL_MODULE_INFO_SYM __attribute__((visibility("default"))) = {
48 .common = {
49 .tag = HARDWARE_MODULE_TAG,
50 .module_api_version = KEYMASTER_MODULE_API_VERSION_0_3,
51 .hal_api_version = HARDWARE_HAL_API_VERSION,
52 .id = KEYSTORE_HARDWARE_MODULE_ID,
53 .name = "Keymaster OpenSSL HAL",
54 .author = "The Android Open Source Project",
55 .methods = &keystore_module_methods,
56 .dso = 0,
57 .reserved = {},
58 },
59};