2 * Copyright (C) 2011-2014 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 * PA-TNC attribute segmentation contracts associated with TNCCS connection
69 seg_contract_manager_t
*contracts
;
72 * Command to transmit to IMV
77 * Size of the dummy attribute value to transmit to IMV
82 * Is it the first handshake?
87 * Do a handshake retry
94 * Stores the Assessment/Evaluation Result for a given IMC ID
98 TNC_IMV_Evaluation_Result result
;
101 METHOD(imc_state_t
, get_connection_id
, TNC_ConnectionID
,
102 private_imc_test_state_t
*this)
104 return this->connection_id
;
107 METHOD(imc_state_t
, has_long
, bool,
108 private_imc_test_state_t
*this)
110 return this->has_long
;
113 METHOD(imc_state_t
, has_excl
, bool,
114 private_imc_test_state_t
*this)
116 return this->has_excl
;
119 METHOD(imc_state_t
, set_flags
, void,
120 private_imc_test_state_t
*this, bool has_long
, bool has_excl
)
122 this->has_long
= has_long
;
123 this->has_excl
= has_excl
;
126 METHOD(imc_state_t
, set_max_msg_len
, void,
127 private_imc_test_state_t
*this, u_int32_t max_msg_len
)
129 this->max_msg_len
= max_msg_len
;
132 METHOD(imc_state_t
, get_max_msg_len
, u_int32_t
,
133 private_imc_test_state_t
*this)
135 return this->max_msg_len
;
138 METHOD(imc_state_t
, get_contracts
, seg_contract_manager_t
*,
139 private_imc_test_state_t
*this)
141 return this->contracts
;
144 METHOD(imc_state_t
, change_state
, void,
145 private_imc_test_state_t
*this, TNC_ConnectionState new_state
)
147 this->state
= new_state
;
150 METHOD(imc_state_t
, set_result
, void,
151 private_imc_test_state_t
*this, TNC_IMCID id
,
152 TNC_IMV_Evaluation_Result result
)
154 enumerator_t
*enumerator
;
158 enumerator
= this->results
->create_enumerator(this->results
);
159 while (enumerator
->enumerate(enumerator
, &entry
))
163 entry
->result
= result
;
168 enumerator
->destroy(enumerator
);
172 entry
= malloc_thing(entry_t
);
174 entry
->result
= result
;
175 this->results
->insert_last(this->results
, entry
);
179 METHOD(imc_state_t
, get_result
, bool,
180 private_imc_test_state_t
*this, TNC_IMCID id
,
181 TNC_IMV_Evaluation_Result
*result
)
183 enumerator_t
*enumerator
;
185 TNC_IMV_Evaluation_Result eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
187 enumerator
= this->results
->create_enumerator(this->results
);
188 while (enumerator
->enumerate(enumerator
, &entry
))
192 eval
= entry
->result
;
196 enumerator
->destroy(enumerator
);
202 return eval
!= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
205 METHOD(imc_state_t
, destroy
, void,
206 private_imc_test_state_t
*this)
208 this->results
->destroy_function(this->results
, free
);
209 this->contracts
->destroy(this->contracts
);
214 METHOD(imc_test_state_t
, get_command
, char*,
215 private_imc_test_state_t
*this)
217 return this->command
;
220 METHOD(imc_test_state_t
, set_command
, void,
221 private_imc_test_state_t
*this, char* command
)
225 old_command
= this->command
;
226 this->command
= strdup(command
);
230 METHOD(imc_test_state_t
, get_dummy_size
, int,
231 private_imc_test_state_t
*this)
233 return this->dummy_size
;
237 METHOD(imc_test_state_t
, is_first_handshake
, bool,
238 private_imc_test_state_t
*this)
242 /* test and reset first_handshake flag */
243 first
= this->first_handshake
;
244 this->first_handshake
= FALSE
;
248 METHOD(imc_test_state_t
, do_handshake_retry
, bool,
249 private_imc_test_state_t
*this)
253 /* test and reset handshake_retry flag */
254 retry
= this->handshake_retry
;
255 this->handshake_retry
= FALSE
;
260 * Described in header.
262 imc_state_t
*imc_test_state_create(TNC_ConnectionID connection_id
,
263 char *command
, int dummy_size
, bool retry
)
265 private_imc_test_state_t
*this;
270 .get_connection_id
= _get_connection_id
,
271 .has_long
= _has_long
,
272 .has_excl
= _has_excl
,
273 .set_flags
= _set_flags
,
274 .set_max_msg_len
= _set_max_msg_len
,
275 .get_max_msg_len
= _get_max_msg_len
,
276 .get_contracts
= _get_contracts
,
277 .change_state
= _change_state
,
278 .set_result
= _set_result
,
279 .get_result
= _get_result
,
282 .get_command
= _get_command
,
283 .set_command
= _set_command
,
284 .get_dummy_size
= _get_dummy_size
,
285 .is_first_handshake
= _is_first_handshake
,
286 .do_handshake_retry
= _do_handshake_retry
,
288 .state
= TNC_CONNECTION_STATE_CREATE
,
289 .results
= linked_list_create(),
290 .connection_id
= connection_id
,
291 .contracts
= seg_contract_manager_create(),
292 .command
= strdup(command
),
293 .dummy_size
= dummy_size
,
294 .first_handshake
= TRUE
,
295 .handshake_retry
= retry
,
298 return &this->public.interface
;