2 * LKM in TIMA(TZ based Integrity Measurement Architecture)
4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include "core/common.h"
27 #include "core/devices.h"
28 #include "core/udev.h"
42 #define TIMA_SUBSYSTEM "tima"
43 #define TIMA_STATUS "TIMA_STATUS"
44 #define TIMA_RESULT "TIMA_RESULT"
46 static struct udev *udev;
47 static struct udev_monitor *mon;
49 static Ecore_Fd_Handler *ufdh;
51 static int noti_id = 0;
53 static void tima_notification(int status)
57 _I("certification failed");
60 _E("internal error (%d)", status);
64 noti_id = tima_lkm_prevention_noti_on();
66 _E("FAIL: tima_lkm_prevention_noti_on()");
72 * tima_uevent_cb - uevent callback
74 * This callback receive the uevent from kernel module driver
76 static Eina_Bool tima_uevent_cb(void *data, Ecore_Fd_Handler *handler)
78 struct udev_device *dev;
79 struct udev_list_entry *list, *entry;
80 const char *name, *value, *msg;
83 dev = udev_monitor_receive_device(mon);
87 /* Getting the First element of the device entry list */
88 list = udev_device_get_properties_list_entry(dev);
90 _E("can't get udev_device_get_properties_list_entry()");
94 udev_list_entry_foreach(entry, list) {
95 name = udev_list_entry_get_name(entry);
97 if (!strcmp(name, TIMA_RESULT)) {
98 msg = udev_list_entry_get_value(entry);
99 _D("tzapp: msg(%s)", msg);
102 if (!strcmp(name, TIMA_STATUS)) {
103 value = udev_list_entry_get_value(entry);
104 status = atoi(value);
105 _D("tzapp: ret(%d)", status);
107 if (status != LKM_SUCCESS) {
108 tima_notification(status);
113 udev_device_unref(dev);
117 udev_device_unref(dev);
123 * tima_uevent_stop - disable udev event control
125 static int tima_uevent_stop(void)
128 ecore_main_fd_handler_del(ufdh);
138 struct udev_device *dev = udev_monitor_receive_device(mon);
140 udev_device_unref(dev);
143 udev_monitor_unref(mon);
156 * tima_uevent_start - enable udev event for TIMA
158 static int tima_uevent_start(void)
164 _E("can't create udev");
168 mon = udev_monitor_new_from_netlink(udev, UDEV);
170 _E("can't udev_monitor create");
174 ret = udev_monitor_set_receive_buffer_size(mon, 1024);
176 _E("fail to set receive buffer size");
180 ret = udev_monitor_filter_add_match_subsystem_devtype(mon, TIMA_SUBSYSTEM, NULL);
182 _E("can't apply subsystem filter");
186 ret = udev_monitor_filter_update(mon);
188 _E("error udev_monitor_filter_update");
190 ufd = udev_monitor_get_fd(mon);
192 _E("can't udev_monitor_get_fd");
196 ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, tima_uevent_cb, NULL, NULL, NULL);
198 _E("can't ecore_main_fd_handler_add");
202 ret = udev_monitor_enable_receiving(mon);
204 _E("can't unable to subscribe to udev events");
214 void tima_lkm_init(void)
219 void tima_lkm_exit(void)