2 * Copyright (C) 2011-2012 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "imc_test_state.h"
18 #include <tncif_names.h>
21 #include <utils/linked_list.h>
23 typedef struct private_imc_test_state_t private_imc_test_state_t
;
24 typedef struct entry_t entry_t
;
27 * Private data of an imc_test_state_t object.
29 struct private_imc_test_state_t
{
32 * Public members of imc_test_state_t
34 imc_test_state_t
public;
39 TNC_ConnectionID connection_id
;
42 * TNCCS connection state
44 TNC_ConnectionState state
;
47 * Assessment/Evaluation Results for all IMC IDs
49 linked_list_t
*results
;
52 * Does the TNCCS connection support long message types?
57 * Does the TNCCS connection support exclusive delivery?
62 * Maximum PA-TNC message size for this TNCCS connection
64 u_int32_t max_msg_len
;
67 * Command to transmit to IMV
72 * Size of the dummy attribute value to transmit to IMV
77 * Is it the first handshake?
82 * Do a handshake retry
89 * Stores the Assessment/Evaluation Result for a given IMC ID
93 TNC_IMV_Evaluation_Result result
;
96 METHOD(imc_state_t
, get_connection_id
, TNC_ConnectionID
,
97 private_imc_test_state_t
*this)
99 return this->connection_id
;
102 METHOD(imc_state_t
, has_long
, bool,
103 private_imc_test_state_t
*this)
105 return this->has_long
;
108 METHOD(imc_state_t
, has_excl
, bool,
109 private_imc_test_state_t
*this)
111 return this->has_excl
;
114 METHOD(imc_state_t
, set_flags
, void,
115 private_imc_test_state_t
*this, bool has_long
, bool has_excl
)
117 this->has_long
= has_long
;
118 this->has_excl
= has_excl
;
121 METHOD(imc_state_t
, set_max_msg_len
, void,
122 private_imc_test_state_t
*this, u_int32_t max_msg_len
)
124 this->max_msg_len
= max_msg_len
;
127 METHOD(imc_state_t
, get_max_msg_len
, u_int32_t
,
128 private_imc_test_state_t
*this)
130 return this->max_msg_len
;
133 METHOD(imc_state_t
, change_state
, void,
134 private_imc_test_state_t
*this, TNC_ConnectionState new_state
)
136 this->state
= new_state
;
139 METHOD(imc_state_t
, set_result
, void,
140 private_imc_test_state_t
*this, TNC_IMCID id
,
141 TNC_IMV_Evaluation_Result result
)
143 enumerator_t
*enumerator
;
147 DBG1(DBG_IMC
, "set assessment result for IMC %u to '%N'",
148 id
, TNC_IMV_Evaluation_Result_names
, result
);
150 enumerator
= this->results
->create_enumerator(this->results
);
151 while (enumerator
->enumerate(enumerator
, &entry
))
155 entry
->result
= result
;
160 enumerator
->destroy(enumerator
);
164 entry
= malloc_thing(entry_t
);
166 entry
->result
= result
;
167 this->results
->insert_last(this->results
, entry
);
171 METHOD(imc_state_t
, get_result
, bool,
172 private_imc_test_state_t
*this, TNC_IMCID id
,
173 TNC_IMV_Evaluation_Result
*result
)
175 enumerator_t
*enumerator
;
177 TNC_IMV_Evaluation_Result eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
179 enumerator
= this->results
->create_enumerator(this->results
);
180 while (enumerator
->enumerate(enumerator
, &entry
))
184 eval
= entry
->result
;
188 enumerator
->destroy(enumerator
);
194 return eval
!= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
197 METHOD(imc_state_t
, destroy
, void,
198 private_imc_test_state_t
*this)
200 this->results
->destroy_function(this->results
, free
);
205 METHOD(imc_test_state_t
, get_command
, char*,
206 private_imc_test_state_t
*this)
208 return this->command
;
211 METHOD(imc_test_state_t
, set_command
, void,
212 private_imc_test_state_t
*this, char* command
)
216 old_command
= this->command
;
217 this->command
= strdup(command
);
221 METHOD(imc_test_state_t
, get_dummy_size
, int,
222 private_imc_test_state_t
*this)
224 return this->dummy_size
;
228 METHOD(imc_test_state_t
, is_first_handshake
, bool,
229 private_imc_test_state_t
*this)
233 /* test and reset first_handshake flag */
234 first
= this->first_handshake
;
235 this->first_handshake
= FALSE
;
239 METHOD(imc_test_state_t
, do_handshake_retry
, bool,
240 private_imc_test_state_t
*this)
244 /* test and reset handshake_retry flag */
245 retry
= this->handshake_retry
;
246 this->handshake_retry
= FALSE
;
251 * Described in header.
253 imc_state_t
*imc_test_state_create(TNC_ConnectionID connection_id
,
254 char *command
, int dummy_size
, bool retry
)
256 private_imc_test_state_t
*this;
261 .get_connection_id
= _get_connection_id
,
262 .has_long
= _has_long
,
263 .has_excl
= _has_excl
,
264 .set_flags
= _set_flags
,
265 .set_max_msg_len
= _set_max_msg_len
,
266 .get_max_msg_len
= _get_max_msg_len
,
267 .change_state
= _change_state
,
268 .set_result
= _set_result
,
269 .get_result
= _get_result
,
272 .get_command
= _get_command
,
273 .set_command
= _set_command
,
274 .get_dummy_size
= _get_dummy_size
,
275 .is_first_handshake
= _is_first_handshake
,
276 .do_handshake_retry
= _do_handshake_retry
,
278 .state
= TNC_CONNECTION_STATE_CREATE
,
279 .results
= linked_list_create(),
280 .connection_id
= connection_id
,
281 .command
= strdup(command
),
282 .dummy_size
= dummy_size
,
283 .first_handshake
= TRUE
,
284 .handshake_retry
= retry
,
287 return &this->public.interface
;