Added add_segment() method to IETF attributes
[strongswan.git] / src / libimcv / plugins / imc_swid / imc_swid_state.c
1 /*
2 * Copyright (C) 2013-2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "imc_swid_state.h"
17
18 #include <tncif_names.h>
19
20 #include <utils/debug.h>
21
22 typedef struct private_imc_swid_state_t private_imc_swid_state_t;
23
24 /**
25 * Private data of an imc_swid_state_t object.
26 */
27 struct private_imc_swid_state_t {
28
29 /**
30 * Public members of imc_swid_state_t
31 */
32 imc_swid_state_t public;
33
34 /**
35 * TNCCS connection ID
36 */
37 TNC_ConnectionID connection_id;
38
39 /**
40 * TNCCS connection state
41 */
42 TNC_ConnectionState state;
43
44 /**
45 * Assessment/Evaluation Result
46 */
47 TNC_IMV_Evaluation_Result result;
48
49 /**
50 * Does the TNCCS connection support long message types?
51 */
52 bool has_long;
53
54 /**
55 * Does the TNCCS connection support exclusive delivery?
56 */
57 bool has_excl;
58
59 /**
60 * Maximum PA-TNC message size for this TNCCS connection
61 */
62 u_int32_t max_msg_len;
63
64 /**
65 * PA-TNC attribute segmentation contracts associated with TNCCS connection
66 */
67 seg_contract_manager_t *contracts;
68
69 /**
70 * Event ID Epoch
71 */
72 u_int32_t eid_epoch;
73 };
74
75 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
76 private_imc_swid_state_t *this)
77 {
78 return this->connection_id;
79 }
80
81 METHOD(imc_state_t, has_long, bool,
82 private_imc_swid_state_t *this)
83 {
84 return this->has_long;
85 }
86
87 METHOD(imc_state_t, has_excl, bool,
88 private_imc_swid_state_t *this)
89 {
90 return this->has_excl;
91 }
92
93 METHOD(imc_state_t, set_flags, void,
94 private_imc_swid_state_t *this, bool has_long, bool has_excl)
95 {
96 this->has_long = has_long;
97 this->has_excl = has_excl;
98 }
99
100 METHOD(imc_state_t, set_max_msg_len, void,
101 private_imc_swid_state_t *this, u_int32_t max_msg_len)
102 {
103 this->max_msg_len = max_msg_len;
104 }
105
106 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
107 private_imc_swid_state_t *this)
108 {
109 return this->max_msg_len;
110 }
111
112 METHOD(imc_state_t, get_contracts, seg_contract_manager_t*,
113 private_imc_swid_state_t *this)
114 {
115 return this->contracts;
116 }
117
118 METHOD(imc_state_t, change_state, void,
119 private_imc_swid_state_t *this, TNC_ConnectionState new_state)
120 {
121 this->state = new_state;
122 }
123
124 METHOD(imc_state_t, set_result, void,
125 private_imc_swid_state_t *this, TNC_IMCID id,
126 TNC_IMV_Evaluation_Result result)
127 {
128 this->result = result;
129 }
130
131 METHOD(imc_state_t, get_result, bool,
132 private_imc_swid_state_t *this, TNC_IMCID id,
133 TNC_IMV_Evaluation_Result *result)
134 {
135 if (result)
136 {
137 *result = this->result;
138 }
139 return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
140 }
141
142 METHOD(imc_state_t, destroy, void,
143 private_imc_swid_state_t *this)
144 {
145 this->contracts->destroy(this->contracts);
146 free(this);
147 }
148
149 METHOD(imc_swid_state_t, get_eid_epoch, u_int32_t,
150 private_imc_swid_state_t *this)
151 {
152 return this->eid_epoch;
153 }
154
155 /**
156 * Described in header.
157 */
158 imc_state_t *imc_swid_state_create(TNC_ConnectionID connection_id)
159 {
160 private_imc_swid_state_t *this;
161 u_int32_t eid_epoch;
162 nonce_gen_t *ng;
163
164 ng = lib->crypto->create_nonce_gen(lib->crypto);
165 if (!ng || !ng->get_nonce(ng, 4, (u_int8_t*)&eid_epoch))
166 {
167 DBG1(DBG_TNC, "failed to generate random EID epoch value");
168 DESTROY_IF(ng);
169 return NULL;
170 }
171 ng->destroy(ng);
172
173 DBG1(DBG_IMC, "creating random EID epoch 0x%08x", eid_epoch);
174
175 INIT(this,
176 .public = {
177 .interface = {
178 .get_connection_id = _get_connection_id,
179 .has_long = _has_long,
180 .has_excl = _has_excl,
181 .set_flags = _set_flags,
182 .set_max_msg_len = _set_max_msg_len,
183 .get_max_msg_len = _get_max_msg_len,
184 .get_contracts = _get_contracts,
185 .change_state = _change_state,
186 .set_result = _set_result,
187 .get_result = _get_result,
188 .destroy = _destroy,
189 },
190 .get_eid_epoch = _get_eid_epoch,
191 },
192 .state = TNC_CONNECTION_STATE_CREATE,
193 .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
194 .connection_id = connection_id,
195 .contracts = seg_contract_manager_create(),
196 .eid_epoch = eid_epoch,
197 );
198
199
200 return &this->public.interface;
201 }
202
203