2 * Copyright (C) 2011-2012 Sansar Choinyambuu, 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_attestation_state.h"
20 #include <utils/linked_list.h>
23 typedef struct private_imc_attestation_state_t private_imc_attestation_state_t
;
24 typedef struct func_comp_t func_comp_t
;
27 * Private data of an imc_attestation_state_t object.
29 struct private_imc_attestation_state_t
{
32 * Public members of imc_attestation_state_t
34 imc_attestation_state_t
public;
39 TNC_ConnectionID connection_id
;
42 * TNCCS connection state
44 TNC_ConnectionState state
;
47 * Does the TNCCS connection support long message types?
52 * Does the TNCCS connection support exclusive delivery?
57 * Maximum PA-TNC message size for this TNCCS connection
59 u_int32_t max_msg_len
;
67 * List of Functional Components
69 linked_list_t
*components
;
72 * Functional Component Evidence cache list
78 METHOD(imc_state_t
, get_connection_id
, TNC_ConnectionID
,
79 private_imc_attestation_state_t
*this)
81 return this->connection_id
;
84 METHOD(imc_state_t
, has_long
, bool,
85 private_imc_attestation_state_t
*this)
87 return this->has_long
;
90 METHOD(imc_state_t
, has_excl
, bool,
91 private_imc_attestation_state_t
*this)
93 return this->has_excl
;
96 METHOD(imc_state_t
, set_flags
, void,
97 private_imc_attestation_state_t
*this, bool has_long
, bool has_excl
)
99 this->has_long
= has_long
;
100 this->has_excl
= has_excl
;
103 METHOD(imc_state_t
, set_max_msg_len
, void,
104 private_imc_attestation_state_t
*this, u_int32_t max_msg_len
)
106 this->max_msg_len
= max_msg_len
;
109 METHOD(imc_state_t
, get_max_msg_len
, u_int32_t
,
110 private_imc_attestation_state_t
*this)
112 return this->max_msg_len
;
115 METHOD(imc_state_t
, change_state
, void,
116 private_imc_attestation_state_t
*this, TNC_ConnectionState new_state
)
118 this->state
= new_state
;
121 METHOD(imc_state_t
, destroy
, void,
122 private_imc_attestation_state_t
*this)
124 this->pts
->destroy(this->pts
);
125 this->components
->destroy_offset(this->components
,
126 offsetof(pts_component_t
, destroy
));
127 this->list
->destroy_offset(this->list
,
128 offsetof(pts_comp_evidence_t
, destroy
));
132 METHOD(imc_attestation_state_t
, get_pts
, pts_t
*,
133 private_imc_attestation_state_t
*this)
138 METHOD(imc_attestation_state_t
, create_component
, pts_component_t
*,
139 private_imc_attestation_state_t
*this, pts_comp_func_name_t
*name
,
142 enumerator_t
*enumerator
;
143 pts_component_t
*component
;
146 enumerator
= this->components
->create_enumerator(this->components
);
147 while (enumerator
->enumerate(enumerator
, &component
))
149 if (name
->equals(name
, component
->get_comp_func_name(component
)))
155 enumerator
->destroy(enumerator
);
159 component
= pts_components
->create(pts_components
, name
, depth
, NULL
);
164 this->components
->insert_last(this->components
, component
);
170 METHOD(imc_attestation_state_t
, add_evidence
, void,
171 private_imc_attestation_state_t
*this, pts_comp_evidence_t
*evid
)
173 this->list
->insert_last(this->list
, evid
);
176 METHOD(imc_attestation_state_t
, next_evidence
, bool,
177 private_imc_attestation_state_t
*this, pts_comp_evidence_t
**evid
)
179 return this->list
->remove_first(this->list
, (void**)evid
) == SUCCESS
;
183 * Described in header.
185 imc_state_t
*imc_attestation_state_create(TNC_ConnectionID connection_id
)
187 private_imc_attestation_state_t
*this;
193 .get_connection_id
= _get_connection_id
,
194 .has_long
= _has_long
,
195 .has_excl
= _has_excl
,
196 .set_flags
= _set_flags
,
197 .set_max_msg_len
= _set_max_msg_len
,
198 .get_max_msg_len
= _get_max_msg_len
,
199 .change_state
= _change_state
,
203 .create_component
= _create_component
,
204 .add_evidence
= _add_evidence
,
205 .next_evidence
= _next_evidence
,
207 .connection_id
= connection_id
,
208 .state
= TNC_CONNECTION_STATE_CREATE
,
209 .pts
= pts_create(TRUE
),
210 .components
= linked_list_create(),
211 .list
= linked_list_create(),
214 platform_info
= lib
->settings
->get_str(lib
->settings
,
215 "libimcv.plugins.imc-attestation.platform_info", NULL
);
218 this->pts
->set_platform_info(this->pts
, platform_info
);
221 return &this->public.interface
;