Moved data structures to new collections subfolder
[strongswan.git] / src / libpts / plugins / imc_attestation / imc_attestation_state.c
1 /*
2 * Copyright (C) 2011-2012 Sansar Choinyambuu, Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "imc_attestation_state.h"
17
18 #include <libpts.h>
19
20 #include <tncif_names.h>
21
22 #include <collections/linked_list.h>
23 #include <debug.h>
24
25 typedef struct private_imc_attestation_state_t private_imc_attestation_state_t;
26 typedef struct func_comp_t func_comp_t;
27
28 /**
29 * Private data of an imc_attestation_state_t object.
30 */
31 struct private_imc_attestation_state_t {
32
33 /**
34 * Public members of imc_attestation_state_t
35 */
36 imc_attestation_state_t public;
37
38 /**
39 * TNCCS connection ID
40 */
41 TNC_ConnectionID connection_id;
42
43 /**
44 * TNCCS connection state
45 */
46 TNC_ConnectionState state;
47
48 /**
49 * Assessment/Evaluation Result
50 */
51 TNC_IMV_Evaluation_Result result;
52
53 /**
54 * Does the TNCCS connection support long message types?
55 */
56 bool has_long;
57
58 /**
59 * Does the TNCCS connection support exclusive delivery?
60 */
61 bool has_excl;
62
63 /**
64 * Maximum PA-TNC message size for this TNCCS connection
65 */
66 u_int32_t max_msg_len;
67
68 /**
69 * PTS object
70 */
71 pts_t *pts;
72
73 /**
74 * List of Functional Components
75 */
76 linked_list_t *components;
77
78 /**
79 * Functional Component Evidence cache list
80 */
81 linked_list_t *list;
82
83 };
84
85 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
86 private_imc_attestation_state_t *this)
87 {
88 return this->connection_id;
89 }
90
91 METHOD(imc_state_t, has_long, bool,
92 private_imc_attestation_state_t *this)
93 {
94 return this->has_long;
95 }
96
97 METHOD(imc_state_t, has_excl, bool,
98 private_imc_attestation_state_t *this)
99 {
100 return this->has_excl;
101 }
102
103 METHOD(imc_state_t, set_flags, void,
104 private_imc_attestation_state_t *this, bool has_long, bool has_excl)
105 {
106 this->has_long = has_long;
107 this->has_excl = has_excl;
108 }
109
110 METHOD(imc_state_t, set_max_msg_len, void,
111 private_imc_attestation_state_t *this, u_int32_t max_msg_len)
112 {
113 this->max_msg_len = max_msg_len;
114 }
115
116 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
117 private_imc_attestation_state_t *this)
118 {
119 return this->max_msg_len;
120 }
121
122 METHOD(imc_state_t, change_state, void,
123 private_imc_attestation_state_t *this, TNC_ConnectionState new_state)
124 {
125 this->state = new_state;
126 }
127
128 METHOD(imc_state_t, set_result, void,
129 private_imc_attestation_state_t *this, TNC_IMCID id,
130 TNC_IMV_Evaluation_Result result)
131 {
132 this->result = result;
133 }
134
135 METHOD(imc_state_t, get_result, bool,
136 private_imc_attestation_state_t *this, TNC_IMCID id,
137 TNC_IMV_Evaluation_Result *result)
138 {
139 if (result)
140 {
141 *result = this->result;
142 }
143 return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
144 }
145
146 METHOD(imc_state_t, destroy, void,
147 private_imc_attestation_state_t *this)
148 {
149 this->pts->destroy(this->pts);
150 this->components->destroy_offset(this->components,
151 offsetof(pts_component_t, destroy));
152 this->list->destroy_offset(this->list,
153 offsetof(pts_comp_evidence_t, destroy));
154 free(this);
155 }
156
157 METHOD(imc_attestation_state_t, get_pts, pts_t*,
158 private_imc_attestation_state_t *this)
159 {
160 return this->pts;
161 }
162
163 METHOD(imc_attestation_state_t, create_component, pts_component_t*,
164 private_imc_attestation_state_t *this, pts_comp_func_name_t *name,
165 u_int32_t depth)
166 {
167 enumerator_t *enumerator;
168 pts_component_t *component;
169 bool found = FALSE;
170
171 enumerator = this->components->create_enumerator(this->components);
172 while (enumerator->enumerate(enumerator, &component))
173 {
174 if (name->equals(name, component->get_comp_func_name(component)))
175 {
176 found = TRUE;
177 break;
178 }
179 }
180 enumerator->destroy(enumerator);
181
182 if (!found)
183 {
184 component = pts_components->create(pts_components, name, depth, NULL);
185 if (!component)
186 {
187 return NULL;
188 }
189 this->components->insert_last(this->components, component);
190
191 }
192 return component;
193 }
194
195 METHOD(imc_attestation_state_t, add_evidence, void,
196 private_imc_attestation_state_t *this, pts_comp_evidence_t *evid)
197 {
198 this->list->insert_last(this->list, evid);
199 }
200
201 METHOD(imc_attestation_state_t, next_evidence, bool,
202 private_imc_attestation_state_t *this, pts_comp_evidence_t **evid)
203 {
204 return this->list->remove_first(this->list, (void**)evid) == SUCCESS;
205 }
206
207 /**
208 * Described in header.
209 */
210 imc_state_t *imc_attestation_state_create(TNC_ConnectionID connection_id)
211 {
212 private_imc_attestation_state_t *this;
213
214 INIT(this,
215 .public = {
216 .interface = {
217 .get_connection_id = _get_connection_id,
218 .has_long = _has_long,
219 .has_excl = _has_excl,
220 .set_flags = _set_flags,
221 .set_max_msg_len = _set_max_msg_len,
222 .get_max_msg_len = _get_max_msg_len,
223 .change_state = _change_state,
224 .set_result = _set_result,
225 .get_result = _get_result,
226 .destroy = _destroy,
227 },
228 .get_pts = _get_pts,
229 .create_component = _create_component,
230 .add_evidence = _add_evidence,
231 .next_evidence = _next_evidence,
232 },
233 .connection_id = connection_id,
234 .state = TNC_CONNECTION_STATE_CREATE,
235 .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
236 .pts = pts_create(TRUE),
237 .components = linked_list_create(),
238 .list = linked_list_create(),
239 );
240
241 return &this->public.interface;
242 }
243
244