2 * Copyright (C) 2013 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_swid_state.h"
18 #include <tncif_names.h>
20 #include <utils/debug.h>
22 typedef struct private_imc_swid_state_t private_imc_swid_state_t
;
25 * Private data of an imc_swid_state_t object.
27 struct private_imc_swid_state_t
{
30 * Public members of imc_swid_state_t
32 imc_swid_state_t
public;
37 TNC_ConnectionID connection_id
;
40 * TNCCS connection state
42 TNC_ConnectionState state
;
45 * Assessment/Evaluation Result
47 TNC_IMV_Evaluation_Result result
;
50 * Does the TNCCS connection support long message types?
55 * Does the TNCCS connection support exclusive delivery?
60 * Maximum PA-TNC message size for this TNCCS connection
62 u_int32_t max_msg_len
;
70 METHOD(imc_state_t
, get_connection_id
, TNC_ConnectionID
,
71 private_imc_swid_state_t
*this)
73 return this->connection_id
;
76 METHOD(imc_state_t
, has_long
, bool,
77 private_imc_swid_state_t
*this)
79 return this->has_long
;
82 METHOD(imc_state_t
, has_excl
, bool,
83 private_imc_swid_state_t
*this)
85 return this->has_excl
;
88 METHOD(imc_state_t
, set_flags
, void,
89 private_imc_swid_state_t
*this, bool has_long
, bool has_excl
)
91 this->has_long
= has_long
;
92 this->has_excl
= has_excl
;
95 METHOD(imc_state_t
, set_max_msg_len
, void,
96 private_imc_swid_state_t
*this, u_int32_t max_msg_len
)
98 this->max_msg_len
= max_msg_len
;
101 METHOD(imc_state_t
, get_max_msg_len
, u_int32_t
,
102 private_imc_swid_state_t
*this)
104 return this->max_msg_len
;
107 METHOD(imc_state_t
, change_state
, void,
108 private_imc_swid_state_t
*this, TNC_ConnectionState new_state
)
110 this->state
= new_state
;
113 METHOD(imc_state_t
, set_result
, void,
114 private_imc_swid_state_t
*this, TNC_IMCID id
,
115 TNC_IMV_Evaluation_Result result
)
117 this->result
= result
;
120 METHOD(imc_state_t
, get_result
, bool,
121 private_imc_swid_state_t
*this, TNC_IMCID id
,
122 TNC_IMV_Evaluation_Result
*result
)
126 *result
= this->result
;
128 return this->result
!= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
131 METHOD(imc_state_t
, destroy
, void,
132 private_imc_swid_state_t
*this)
137 METHOD(imc_swid_state_t
, get_eid_epoch
, u_int32_t
,
138 private_imc_swid_state_t
*this)
140 return this->eid_epoch
;
144 * Described in header.
146 imc_state_t
*imc_swid_state_create(TNC_ConnectionID connection_id
)
148 private_imc_swid_state_t
*this;
152 ng
= lib
->crypto
->create_nonce_gen(lib
->crypto
);
153 if (!ng
|| !ng
->get_nonce(ng
, 4, (u_int8_t
*)&eid_epoch
))
155 DBG1(DBG_TNC
, "failed to generate random EID epoch value");
161 DBG1(DBG_IMC
, "creating random EID epoch 0x%08x", eid_epoch
);
166 .get_connection_id
= _get_connection_id
,
167 .has_long
= _has_long
,
168 .has_excl
= _has_excl
,
169 .set_flags
= _set_flags
,
170 .set_max_msg_len
= _set_max_msg_len
,
171 .get_max_msg_len
= _get_max_msg_len
,
172 .change_state
= _change_state
,
173 .set_result
= _set_result
,
174 .get_result
= _get_result
,
177 .get_eid_epoch
= _get_eid_epoch
,
179 .state
= TNC_CONNECTION_STATE_CREATE
,
180 .result
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
181 .connection_id
= connection_id
,
182 .eid_epoch
= eid_epoch
,
186 return &this->public.interface
;