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>
20 #include <utils/debug.h>
21 #include <collections/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 enumerator
= this->results
->create_enumerator(this->results
);
148 while (enumerator
->enumerate(enumerator
, &entry
))
152 entry
->result
= result
;
157 enumerator
->destroy(enumerator
);
161 entry
= malloc_thing(entry_t
);
163 entry
->result
= result
;
164 this->results
->insert_last(this->results
, entry
);
168 METHOD(imc_state_t
, get_result
, bool,
169 private_imc_test_state_t
*this, TNC_IMCID id
,
170 TNC_IMV_Evaluation_Result
*result
)
172 enumerator_t
*enumerator
;
174 TNC_IMV_Evaluation_Result eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
176 enumerator
= this->results
->create_enumerator(this->results
);
177 while (enumerator
->enumerate(enumerator
, &entry
))
181 eval
= entry
->result
;
185 enumerator
->destroy(enumerator
);
191 return eval
!= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
194 METHOD(imc_state_t
, destroy
, void,
195 private_imc_test_state_t
*this)
197 this->results
->destroy_function(this->results
, free
);
202 METHOD(imc_test_state_t
, get_command
, char*,
203 private_imc_test_state_t
*this)
205 return this->command
;
208 METHOD(imc_test_state_t
, set_command
, void,
209 private_imc_test_state_t
*this, char* command
)
213 old_command
= this->command
;
214 this->command
= strdup(command
);
218 METHOD(imc_test_state_t
, get_dummy_size
, int,
219 private_imc_test_state_t
*this)
221 return this->dummy_size
;
225 METHOD(imc_test_state_t
, is_first_handshake
, bool,
226 private_imc_test_state_t
*this)
230 /* test and reset first_handshake flag */
231 first
= this->first_handshake
;
232 this->first_handshake
= FALSE
;
236 METHOD(imc_test_state_t
, do_handshake_retry
, bool,
237 private_imc_test_state_t
*this)
241 /* test and reset handshake_retry flag */
242 retry
= this->handshake_retry
;
243 this->handshake_retry
= FALSE
;
248 * Described in header.
250 imc_state_t
*imc_test_state_create(TNC_ConnectionID connection_id
,
251 char *command
, int dummy_size
, bool retry
)
253 private_imc_test_state_t
*this;
258 .get_connection_id
= _get_connection_id
,
259 .has_long
= _has_long
,
260 .has_excl
= _has_excl
,
261 .set_flags
= _set_flags
,
262 .set_max_msg_len
= _set_max_msg_len
,
263 .get_max_msg_len
= _get_max_msg_len
,
264 .change_state
= _change_state
,
265 .set_result
= _set_result
,
266 .get_result
= _get_result
,
269 .get_command
= _get_command
,
270 .set_command
= _set_command
,
271 .get_dummy_size
= _get_dummy_size
,
272 .is_first_handshake
= _is_first_handshake
,
273 .do_handshake_retry
= _do_handshake_retry
,
275 .state
= TNC_CONNECTION_STATE_CREATE
,
276 .results
= linked_list_create(),
277 .connection_id
= connection_id
,
278 .command
= strdup(command
),
279 .dummy_size
= dummy_size
,
280 .first_handshake
= TRUE
,
281 .handshake_retry
= retry
,
284 return &this->public.interface
;