2 * Copyright (C) 2011-2012 Sansar Choinyambuu
3 * Copyright (C) 2011-2014 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "imc_attestation_state.h"
21 #include <tncif_names.h>
23 #include <collections/linked_list.h>
24 #include <utils/debug.h>
26 typedef struct private_imc_attestation_state_t private_imc_attestation_state_t
;
27 typedef struct func_comp_t func_comp_t
;
30 * Private data of an imc_attestation_state_t object.
32 struct private_imc_attestation_state_t
{
35 * Public members of imc_attestation_state_t
37 imc_attestation_state_t
public;
42 TNC_ConnectionID connection_id
;
45 * TNCCS connection state
47 TNC_ConnectionState state
;
50 * Assessment/Evaluation Result
52 TNC_IMV_Evaluation_Result result
;
55 * Does the TNCCS connection support long message types?
60 * Does the TNCCS connection support exclusive delivery?
65 * Maximum PA-TNC message size for this TNCCS connection
67 u_int32_t max_msg_len
;
70 * PA-TNC attribute segmentation contracts associated with TNCCS connection
72 seg_contract_manager_t
*contracts
;
80 * List of Functional Components
82 linked_list_t
*components
;
85 * Functional Component Evidence cache list
91 METHOD(imc_state_t
, get_connection_id
, TNC_ConnectionID
,
92 private_imc_attestation_state_t
*this)
94 return this->connection_id
;
97 METHOD(imc_state_t
, has_long
, bool,
98 private_imc_attestation_state_t
*this)
100 return this->has_long
;
103 METHOD(imc_state_t
, has_excl
, bool,
104 private_imc_attestation_state_t
*this)
106 return this->has_excl
;
109 METHOD(imc_state_t
, set_flags
, void,
110 private_imc_attestation_state_t
*this, bool has_long
, bool has_excl
)
112 this->has_long
= has_long
;
113 this->has_excl
= has_excl
;
116 METHOD(imc_state_t
, set_max_msg_len
, void,
117 private_imc_attestation_state_t
*this, u_int32_t max_msg_len
)
119 this->max_msg_len
= max_msg_len
;
122 METHOD(imc_state_t
, get_max_msg_len
, u_int32_t
,
123 private_imc_attestation_state_t
*this)
125 return this->max_msg_len
;
128 METHOD(imc_state_t
, get_contracts
, seg_contract_manager_t
*,
129 private_imc_attestation_state_t
*this)
131 return this->contracts
;
134 METHOD(imc_state_t
, change_state
, void,
135 private_imc_attestation_state_t
*this, TNC_ConnectionState new_state
)
137 this->state
= new_state
;
140 METHOD(imc_state_t
, set_result
, void,
141 private_imc_attestation_state_t
*this, TNC_IMCID id
,
142 TNC_IMV_Evaluation_Result result
)
144 this->result
= result
;
147 METHOD(imc_state_t
, get_result
, bool,
148 private_imc_attestation_state_t
*this, TNC_IMCID id
,
149 TNC_IMV_Evaluation_Result
*result
)
153 *result
= this->result
;
155 return this->result
!= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
158 METHOD(imc_state_t
, destroy
, void,
159 private_imc_attestation_state_t
*this)
161 this->pts
->destroy(this->pts
);
162 this->components
->destroy_offset(this->components
,
163 offsetof(pts_component_t
, destroy
));
164 this->list
->destroy_offset(this->list
,
165 offsetof(pts_comp_evidence_t
, destroy
));
166 this->contracts
->destroy(this->contracts
);
170 METHOD(imc_attestation_state_t
, get_pts
, pts_t
*,
171 private_imc_attestation_state_t
*this)
176 METHOD(imc_attestation_state_t
, create_component
, pts_component_t
*,
177 private_imc_attestation_state_t
*this, pts_comp_func_name_t
*name
,
180 enumerator_t
*enumerator
;
181 pts_component_t
*component
;
184 enumerator
= this->components
->create_enumerator(this->components
);
185 while (enumerator
->enumerate(enumerator
, &component
))
187 if (name
->equals(name
, component
->get_comp_func_name(component
)))
193 enumerator
->destroy(enumerator
);
197 component
= pts_components
->create(pts_components
, name
, depth
, NULL
);
202 this->components
->insert_last(this->components
, component
);
208 METHOD(imc_attestation_state_t
, add_evidence
, void,
209 private_imc_attestation_state_t
*this, pts_comp_evidence_t
*evid
)
211 this->list
->insert_last(this->list
, evid
);
214 METHOD(imc_attestation_state_t
, next_evidence
, bool,
215 private_imc_attestation_state_t
*this, pts_comp_evidence_t
**evid
)
217 return this->list
->remove_first(this->list
, (void**)evid
) == SUCCESS
;
221 * Described in header.
223 imc_state_t
*imc_attestation_state_create(TNC_ConnectionID connection_id
)
225 private_imc_attestation_state_t
*this;
230 .get_connection_id
= _get_connection_id
,
231 .has_long
= _has_long
,
232 .has_excl
= _has_excl
,
233 .set_flags
= _set_flags
,
234 .set_max_msg_len
= _set_max_msg_len
,
235 .get_max_msg_len
= _get_max_msg_len
,
236 .get_contracts
= _get_contracts
,
237 .change_state
= _change_state
,
238 .set_result
= _set_result
,
239 .get_result
= _get_result
,
243 .create_component
= _create_component
,
244 .add_evidence
= _add_evidence
,
245 .next_evidence
= _next_evidence
,
247 .connection_id
= connection_id
,
248 .state
= TNC_CONNECTION_STATE_CREATE
,
249 .result
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
250 .contracts
= seg_contract_manager_create(),
251 .pts
= pts_create(TRUE
),
252 .components
= linked_list_create(),
253 .list
= linked_list_create(),
256 return &this->public.interface
;