69cb3753e32b91c712b0c9a91267d8065db5fe38
[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
24 /**
25 * Private data of an imv_hcd_state_t object.
26 */
27 struct private_imv_hcd_state_t {
28
29 /**
30 * Public members of imv_hcd_state_t
31 */
32 imv_hcd_state_t public;
33
34 /**
35 * TNCCS connection ID
36 */
37 TNC_ConnectionID connection_id;
38
39 /**
40 * TNCCS connection state
41 */
42 TNC_ConnectionState state;
43
44 /**
45 * Does the TNCCS connection support long message types?
46 */
47 bool has_long;
48
49 /**
50 * Does the TNCCS connection support exclusive delivery?
51 */
52 bool has_excl;
53
54 /**
55 * Maximum PA-TNC message size for this TNCCS connection
56 */
57 uint32_t max_msg_len;
58
59 /**
60 * Flags set for completed actions
61 */
62 uint32_t action_flags;
63
64 /**
65 * IMV database session associated with TNCCS connection
66 */
67 imv_session_t *session;
68
69 /**
70 * PA-TNC attribute segmentation contracts associated with TNCCS connection
71 */
72 seg_contract_manager_t *contracts;
73
74 /**
75 * IMV action recommendation
76 */
77 TNC_IMV_Action_Recommendation rec;
78
79 /**
80 * IMV evaluation result
81 */
82 TNC_IMV_Evaluation_Result eval;
83
84 /**
85 * IMV OS handshake state
86 */
87 imv_hcd_handshake_state_t handshake_state;
88
89 };
90
91 METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
92 private_imv_hcd_state_t *this)
93 {
94 return this->connection_id;
95 }
96
97 METHOD(imv_state_t, has_long, bool,
98 private_imv_hcd_state_t *this)
99 {
100 return this->has_long;
101 }
102
103 METHOD(imv_state_t, has_excl, bool,
104 private_imv_hcd_state_t *this)
105 {
106 return this->has_excl;
107 }
108
109 METHOD(imv_state_t, set_flags, void,
110 private_imv_hcd_state_t *this, bool has_long, bool has_excl)
111 {
112 this->has_long = has_long;
113 this->has_excl = has_excl;
114 }
115
116 METHOD(imv_state_t, set_max_msg_len, void,
117 private_imv_hcd_state_t *this, uint32_t max_msg_len)
118 {
119 this->max_msg_len = max_msg_len;
120 }
121
122 METHOD(imv_state_t, get_max_msg_len, uint32_t,
123 private_imv_hcd_state_t *this)
124 {
125 return this->max_msg_len;
126 }
127
128 METHOD(imv_state_t, set_action_flags, void,
129 private_imv_hcd_state_t *this, uint32_t flags)
130 {
131 this->action_flags |= flags;
132 }
133
134 METHOD(imv_state_t, get_action_flags, uint32_t,
135 private_imv_hcd_state_t *this)
136 {
137 return this->action_flags;
138 }
139
140 METHOD(imv_state_t, set_session, void,
141 private_imv_hcd_state_t *this, imv_session_t *session)
142 {
143 this->session = session;
144 }
145
146 METHOD(imv_state_t, get_session, imv_session_t*,
147 private_imv_hcd_state_t *this)
148 {
149 return this->session;
150 }
151
152 METHOD(imv_state_t, get_contracts, seg_contract_manager_t*,
153 private_imv_hcd_state_t *this)
154 {
155 return this->contracts;
156 }
157
158 METHOD(imv_state_t, get_recommendation, void,
159 private_imv_hcd_state_t *this, TNC_IMV_Action_Recommendation *rec,
160 TNC_IMV_Evaluation_Result *eval)
161 {
162 *rec = this->rec;
163 *eval = this->eval;
164 }
165
166 METHOD(imv_state_t, set_recommendation, void,
167 private_imv_hcd_state_t *this, TNC_IMV_Action_Recommendation rec,
168 TNC_IMV_Evaluation_Result eval)
169 {
170 this->rec = rec;
171 this->eval = eval;
172 }
173
174 METHOD(imv_state_t, update_recommendation, void,
175 private_imv_hcd_state_t *this, TNC_IMV_Action_Recommendation rec,
176 TNC_IMV_Evaluation_Result eval)
177 {
178 this->rec = tncif_policy_update_recommendation(this->rec, rec);
179 this->eval = tncif_policy_update_evaluation(this->eval, eval);
180 }
181
182 METHOD(imv_state_t, change_state, void,
183 private_imv_hcd_state_t *this, TNC_ConnectionState new_state)
184 {
185 this->state = new_state;
186 }
187
188 METHOD(imv_state_t, get_reason_string, bool,
189 private_imv_hcd_state_t *this, enumerator_t *language_enumerator,
190 chunk_t *reason_string, char **reason_language)
191 {
192 return FALSE;
193 }
194
195 METHOD(imv_state_t, get_remediation_instructions, bool,
196 private_imv_hcd_state_t *this, enumerator_t *language_enumerator,
197 chunk_t *string, char **lang_code, char **uri)
198 {
199 return FALSE;
200 }
201
202 METHOD(imv_state_t, destroy, void,
203 private_imv_hcd_state_t *this)
204 {
205 DESTROY_IF(this->session);
206 this->contracts->destroy(this->contracts);
207 free(this);
208 }
209
210 METHOD(imv_hcd_state_t, set_handshake_state, void,
211 private_imv_hcd_state_t *this, imv_hcd_handshake_state_t new_state)
212 {
213 this->handshake_state = new_state;
214 }
215
216 METHOD(imv_hcd_state_t, get_handshake_state, imv_hcd_handshake_state_t,
217 private_imv_hcd_state_t *this)
218 {
219 return this->handshake_state;
220 }
221
222 /**
223 * Described in header.
224 */
225 imv_state_t *imv_hcd_state_create(TNC_ConnectionID connection_id)
226 {
227 private_imv_hcd_state_t *this;
228
229 INIT(this,
230 .public = {
231 .interface = {
232 .get_connection_id = _get_connection_id,
233 .has_long = _has_long,
234 .has_excl = _has_excl,
235 .set_flags = _set_flags,
236 .set_max_msg_len = _set_max_msg_len,
237 .get_max_msg_len = _get_max_msg_len,
238 .set_action_flags = _set_action_flags,
239 .get_action_flags = _get_action_flags,
240 .set_session = _set_session,
241 .get_session = _get_session,
242 .get_contracts = _get_contracts,
243 .change_state = _change_state,
244 .get_recommendation = _get_recommendation,
245 .set_recommendation = _set_recommendation,
246 .update_recommendation = _update_recommendation,
247 .get_reason_string = _get_reason_string,
248 .get_remediation_instructions = _get_remediation_instructions,
249 .destroy = _destroy,
250 },
251 .set_handshake_state = _set_handshake_state,
252 .get_handshake_state = _get_handshake_state,
253 },
254 .state = TNC_CONNECTION_STATE_CREATE,
255 .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
256 .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
257 .connection_id = connection_id,
258 .contracts = seg_contract_manager_create(),
259 );
260
261 return &this->public.interface;
262 }
263
264