Use PWG HCD PA-TNC subtypes to transport HCD attributes
[strongswan.git] / src / libimcv / plugins / imv_hcd / imv_hcd_state.c
1 /*
2 * Copyright (C) 2015 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 "imv_hcd_state.h"
17
18 #include <tncif_policy.h>
19
20 #include <utils/debug.h>
21
22 typedef struct private_imv_hcd_state_t private_imv_hcd_state_t;
23 typedef struct subtype_action_flags_t subtype_action_flags_t;
24
25 struct subtype_action_flags_t {
26 pa_subtype_pwg_t subtype;
27 uint32_t action_flags;
28 };
29
30 /**
31 * Private data of an imv_hcd_state_t object.
32 */
33 struct private_imv_hcd_state_t {
34
35 /**
36 * Public members of imv_hcd_state_t
37 */
38 imv_hcd_state_t public;
39
40 /**
41 * TNCCS connection ID
42 */
43 TNC_ConnectionID connection_id;
44
45 /**
46 * TNCCS connection state
47 */
48 TNC_ConnectionState state;
49
50 /**
51 * Does the TNCCS connection support long message types?
52 */
53 bool has_long;
54
55 /**
56 * Does the TNCCS connection support exclusive delivery?
57 */
58 bool has_excl;
59
60 /**
61 * Maximum PA-TNC message size for this TNCCS connection
62 */
63 uint32_t max_msg_len;
64
65 /**
66 * Current flags set for completed actions
67 */
68 uint32_t *action_flags;
69
70 /**
71 * Action flags for all PA subtypes
72 */
73 subtype_action_flags_t subtype_action_flags[6];
74
75 /**
76 * IMV database session associated with TNCCS connection
77 */
78 imv_session_t *session;
79
80 /**
81 * PA-TNC attribute segmentation contracts associated with TNCCS connection
82 */
83 seg_contract_manager_t *contracts;
84
85 /**
86 * IMV action recommendation
87 */
88 TNC_IMV_Action_Recommendation rec;
89
90 /**
91 * IMV evaluation result
92 */
93 TNC_IMV_Evaluation_Result eval;
94
95 /**
96 * IMV OS handshake state
97 */
98 imv_hcd_handshake_state_t handshake_state;
99
100 };
101
102 METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
103 private_imv_hcd_state_t *this)
104 {
105 return this->connection_id;
106 }
107
108 METHOD(imv_state_t, has_long, bool,
109 private_imv_hcd_state_t *this)
110 {
111 return this->has_long;
112 }
113
114 METHOD(imv_state_t, has_excl, bool,
115 private_imv_hcd_state_t *this)
116 {
117 return this->has_excl;
118 }
119
120 METHOD(imv_state_t, set_flags, void,
121 private_imv_hcd_state_t *this, bool has_long, bool has_excl)
122 {
123 this->has_long = has_long;
124 this->has_excl = has_excl;
125 }
126
127 METHOD(imv_state_t, set_max_msg_len, void,
128 private_imv_hcd_state_t *this, uint32_t max_msg_len)
129 {
130 this->max_msg_len = max_msg_len;
131 }
132
133 METHOD(imv_state_t, get_max_msg_len, uint32_t,
134 private_imv_hcd_state_t *this)
135 {
136 return this->max_msg_len;
137 }
138
139 METHOD(imv_state_t, set_action_flags, void,
140 private_imv_hcd_state_t *this, uint32_t flags)
141 {
142 *this->action_flags |= flags;
143 }
144
145 METHOD(imv_state_t, get_action_flags, uint32_t,
146 private_imv_hcd_state_t *this)
147 {
148 return *this->action_flags;
149 }
150
151 METHOD(imv_state_t, set_session, void,
152 private_imv_hcd_state_t *this, imv_session_t *session)
153 {
154 this->session = session;
155 }
156
157 METHOD(imv_state_t, get_session, imv_session_t*,
158 private_imv_hcd_state_t *this)
159 {
160 return this->session;
161 }
162
163 METHOD(imv_state_t, get_contracts, seg_contract_manager_t*,
164 private_imv_hcd_state_t *this)
165 {
166 return this->contracts;
167 }
168
169 METHOD(imv_state_t, get_recommendation, void,
170 private_imv_hcd_state_t *this, TNC_IMV_Action_Recommendation *rec,
171 TNC_IMV_Evaluation_Result *eval)
172 {
173 *rec = this->rec;
174 *eval = this->eval;
175 }
176
177 METHOD(imv_state_t, set_recommendation, void,
178 private_imv_hcd_state_t *this, TNC_IMV_Action_Recommendation rec,
179 TNC_IMV_Evaluation_Result eval)
180 {
181 this->rec = rec;
182 this->eval = eval;
183 }
184
185 METHOD(imv_state_t, update_recommendation, void,
186 private_imv_hcd_state_t *this, TNC_IMV_Action_Recommendation rec,
187 TNC_IMV_Evaluation_Result eval)
188 {
189 this->rec = tncif_policy_update_recommendation(this->rec, rec);
190 this->eval = tncif_policy_update_evaluation(this->eval, eval);
191 }
192
193 METHOD(imv_state_t, change_state, void,
194 private_imv_hcd_state_t *this, TNC_ConnectionState new_state)
195 {
196 this->state = new_state;
197 }
198
199 METHOD(imv_state_t, get_reason_string, bool,
200 private_imv_hcd_state_t *this, enumerator_t *language_enumerator,
201 chunk_t *reason_string, char **reason_language)
202 {
203 return FALSE;
204 }
205
206 METHOD(imv_state_t, get_remediation_instructions, bool,
207 private_imv_hcd_state_t *this, enumerator_t *language_enumerator,
208 chunk_t *string, char **lang_code, char **uri)
209 {
210 return FALSE;
211 }
212
213 METHOD(imv_state_t, destroy, void,
214 private_imv_hcd_state_t *this)
215 {
216 DESTROY_IF(this->session);
217 this->contracts->destroy(this->contracts);
218 free(this);
219 }
220
221 METHOD(imv_hcd_state_t, set_handshake_state, void,
222 private_imv_hcd_state_t *this, imv_hcd_handshake_state_t new_state)
223 {
224 this->handshake_state = new_state;
225 }
226
227 METHOD(imv_hcd_state_t, get_handshake_state, imv_hcd_handshake_state_t,
228 private_imv_hcd_state_t *this)
229 {
230 return this->handshake_state;
231 }
232
233 METHOD(imv_hcd_state_t, set_subtype, void,
234 private_imv_hcd_state_t *this, pa_subtype_pwg_t subtype)
235 {
236 int i;
237
238 for (i = 0; i < countof(this->subtype_action_flags); i++)
239 {
240 if (subtype == this->subtype_action_flags[i].subtype)
241 {
242 this->action_flags = &this->subtype_action_flags[i].action_flags;
243 break;
244 }
245 }
246 }
247
248 METHOD(imv_hcd_state_t, set_user_app_disabled, void,
249 private_imv_hcd_state_t *this)
250 {
251 int i;
252
253 for (i = 0; i < countof(this->subtype_action_flags); i++)
254 {
255 this->subtype_action_flags[i].action_flags |= IMV_HCD_ATTR_USER_APP_NAME;
256 }
257 }
258
259 /**
260 * Described in header.
261 */
262 imv_state_t *imv_hcd_state_create(TNC_ConnectionID connection_id)
263 {
264 private_imv_hcd_state_t *this;
265
266 INIT(this,
267 .public = {
268 .interface = {
269 .get_connection_id = _get_connection_id,
270 .has_long = _has_long,
271 .has_excl = _has_excl,
272 .set_flags = _set_flags,
273 .set_max_msg_len = _set_max_msg_len,
274 .get_max_msg_len = _get_max_msg_len,
275 .set_action_flags = _set_action_flags,
276 .get_action_flags = _get_action_flags,
277 .set_session = _set_session,
278 .get_session = _get_session,
279 .get_contracts = _get_contracts,
280 .change_state = _change_state,
281 .get_recommendation = _get_recommendation,
282 .set_recommendation = _set_recommendation,
283 .update_recommendation = _update_recommendation,
284 .get_reason_string = _get_reason_string,
285 .get_remediation_instructions = _get_remediation_instructions,
286 .destroy = _destroy,
287 },
288 .set_handshake_state = _set_handshake_state,
289 .get_handshake_state = _get_handshake_state,
290 .set_subtype = _set_subtype,
291 .set_user_app_disabled = _set_user_app_disabled,
292 },
293 .state = TNC_CONNECTION_STATE_CREATE,
294 .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
295 .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
296 .connection_id = connection_id,
297 .contracts = seg_contract_manager_create(),
298 .subtype_action_flags = {
299 { PA_SUBTYPE_PWG_HCD_SYSTEM, IMV_HCD_ATTR_NONE },
300 { PA_SUBTYPE_PWG_HCD_CONSOLE, IMV_HCD_ATTR_SYSTEM_ONLY },
301 { PA_SUBTYPE_PWG_HCD_MARKER, IMV_HCD_ATTR_SYSTEM_ONLY },
302 { PA_SUBTYPE_PWG_HCD_FINISHER, IMV_HCD_ATTR_SYSTEM_ONLY },
303 { PA_SUBTYPE_PWG_HCD_INTERFACE, IMV_HCD_ATTR_SYSTEM_ONLY },
304 { PA_SUBTYPE_PWG_HCD_SCANNER, IMV_HCD_ATTR_SYSTEM_ONLY },
305 }
306 );
307
308 this->action_flags = &this->subtype_action_flags[0].action_flags;
309
310 return &this->public.interface;
311 }
312
313