blob: b472680fbc5d4bbe2bfc23cd5efcfc1643d56ba5 [file] [log] [blame]
Andres Moralesb33c9b82015-09-08 17:56:07 -07001/*
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
22#include "trusty_keymaster_device.h"
23
24using keymaster::TrustyKeymasterDevice;
25
26/*
27 * Generic device handling
28 */
Jocelyn Bohre194e272017-02-09 16:58:41 -080029static int trusty_keymaster_open(const hw_module_t* module, const char* name, hw_device_t** device) {
30 if (strcmp(name, KEYSTORE_KEYMASTER) != 0) {
Andres Moralesb33c9b82015-09-08 17:56:07 -070031 return -EINVAL;
Jocelyn Bohre194e272017-02-09 16:58:41 -080032 }
Andres Moralesb33c9b82015-09-08 17:56:07 -070033
34 TrustyKeymasterDevice* dev = new TrustyKeymasterDevice(module);
Jocelyn Bohre194e272017-02-09 16:58:41 -080035 if (dev == NULL) {
Andres Moralesb33c9b82015-09-08 17:56:07 -070036 return -ENOMEM;
Jocelyn Bohre194e272017-02-09 16:58:41 -080037 }
Andres Moralesb33c9b82015-09-08 17:56:07 -070038 *device = dev->hw_device();
39 // Do not delete dev; it will get cleaned up when the caller calls device->close(), and must
40 // exist until then.
41 return 0;
42}
43
44static struct hw_module_methods_t keystore_module_methods = {
45 .open = trusty_keymaster_open,
46};
47
48struct keystore_module HAL_MODULE_INFO_SYM __attribute__((visibility("default"))) = {
49 .common =
50 {
Jocelyn Bohre194e272017-02-09 16:58:41 -080051 .tag = HARDWARE_MODULE_TAG,
52 .module_api_version = KEYMASTER_MODULE_API_VERSION_2_0,
53 .hal_api_version = HARDWARE_HAL_API_VERSION,
54 .id = KEYSTORE_HARDWARE_MODULE_ID,
55 .name = "Trusty Keymaster HAL",
56 .author = "The Android Open Source Project",
57 .methods = &keystore_module_methods,
58 .dso = 0,
59 .reserved = {},
Andres Moralesb33c9b82015-09-08 17:56:07 -070060 },
61};