268f4384b3f7ddc4bcce490df255f892bbb536f6
[strongswan.git] / src / libpts / libpts.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "libpts.h"
16 #include "tcg/tcg_attr.h"
17 #include "pts/components/pts_component.h"
18 #include "pts/components/pts_component_manager.h"
19 #include "pts/components/tcg/tcg_comp_func_name.h"
20 #include "pts/components/ita/ita_comp_func_name.h"
21 #include "pts/components/ita/ita_comp_tboot.h"
22 #include "pts/components/ita/ita_comp_tgrub.h"
23
24 #include <imcv.h>
25 #include <debug.h>
26
27 /**
28 * PTS Functional Component manager
29 */
30 pts_component_manager_t *pts_components;
31
32 /**
33 * Reference count for IMC/IMV instances
34 */
35 static refcount_t libpts_ref = 0;
36
37 /**
38 * Described in header.
39 */
40 bool libpts_init(void)
41 {
42 if (libpts_ref == 0)
43 {
44 if (!imcv_pa_tnc_attributes)
45 {
46 return FALSE;
47 }
48 imcv_pa_tnc_attributes->add_vendor(imcv_pa_tnc_attributes, PEN_TCG,
49 tcg_attr_create_from_data, tcg_attr_names);
50
51 pts_components = pts_component_manager_create();
52 pts_components->add_vendor(pts_components, PEN_TCG,
53 pts_tcg_comp_func_names, PTS_TCG_QUALIFIER_TYPE_SIZE,
54 pts_tcg_qualifier_flag_names, pts_tcg_qualifier_type_names);
55 pts_components->add_vendor(pts_components, PEN_ITA,
56 pts_ita_comp_func_names, PTS_ITA_QUALIFIER_TYPE_SIZE,
57 pts_ita_qualifier_flag_names, pts_ita_qualifier_type_names);
58
59 pts_components->add_component(pts_components, PEN_ITA,
60 PTS_ITA_COMP_FUNC_NAME_TGRUB,
61 pts_ita_comp_tgrub_create);
62 pts_components->add_component(pts_components, PEN_ITA,
63 PTS_ITA_COMP_FUNC_NAME_TBOOT,
64 pts_ita_comp_tboot_create);
65
66 DBG1(DBG_LIB, "libpts initialized");
67 }
68 ref_get(&libpts_ref);
69
70 return TRUE;
71 }
72
73 /**
74 * Described in header.
75 */
76 void libpts_deinit(void)
77 {
78 if (ref_put(&libpts_ref))
79 {
80 pts_components->remove_vendor(pts_components, PEN_TCG);
81 pts_components->remove_vendor(pts_components, PEN_ITA);
82 pts_components->destroy(pts_components);
83
84 if (!imcv_pa_tnc_attributes)
85 {
86 return;
87 }
88 imcv_pa_tnc_attributes->remove_vendor(imcv_pa_tnc_attributes, PEN_TCG);
89 DBG1(DBG_LIB, "libpts terminated");
90 }
91 }
92