]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libimcv/plugins/imc_swima/imc_swima_state.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libimcv / plugins / imc_swima / imc_swima_state.c
CommitLineData
2821c0f7
AS
1/*
2 * Copyright (C) 2017 Andreas Steffen
19ef2aec
TB
3 *
4 * Copyright (C) secunet Security Networks AG
2821c0f7
AS
5 *
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>.
10 *
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
14 * for more details.
15 */
16
17#include "imc_swima_state.h"
18
19#include <tncif_names.h>
20
21#include <utils/debug.h>
22
23typedef struct private_imc_swima_state_t private_imc_swima_state_t;
24
25/**
26 * Private data of an imc_swima_state_t object.
27 */
28struct private_imc_swima_state_t {
29
30 /**
31 * Public members of imc_swima_state_t
32 */
33 imc_swima_state_t public;
34
35 /**
36 * TNCCS connection ID
37 */
38 TNC_ConnectionID connection_id;
39
40 /**
41 * TNCCS connection state
42 */
43 TNC_ConnectionState state;
44
45 /**
46 * Assessment/Evaluation Result
47 */
48 TNC_IMV_Evaluation_Result result;
49
50 /**
51 * Does the TNCCS connection support long message types?
52 */
53 bool has_long;
54
55 /**
56 * Does the TNCCS connection support exclusive delivery?
57 */
58 bool has_excl;
59
60 /**
61 * Maximum PA-TNC message size for this TNCCS connection
62 */
63 uint32_t max_msg_len;
64
65 /**
66 * PA-TNC attribute segmentation contracts associated with TNCCS connection
67 */
68 seg_contract_manager_t *contracts;
f649a13c
AS
69
70 /**
71 * Has a subscription been established?
72 */
73 bool has_subscription;
74
75 /**
76 * State information on subscriptions
77 */
78 imc_swima_subscription_t *subscription;
79
80 /**
81 * Earliest EID for the next subscription round
82 */
83 uint32_t earliest_eid;
84
2821c0f7
AS
85};
86
f649a13c
AS
87static void free_subscription(imc_swima_subscription_t *this)
88{
89 if (this)
90 {
91 this->targets->destroy(this->targets);
92 free(this);
93 }
94}
95
2821c0f7
AS
96METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
97 private_imc_swima_state_t *this)
98{
99 return this->connection_id;
100}
101
102METHOD(imc_state_t, has_long, bool,
103 private_imc_swima_state_t *this)
104{
105 return this->has_long;
106}
107
108METHOD(imc_state_t, has_excl, bool,
109 private_imc_swima_state_t *this)
110{
111 return this->has_excl;
112}
113
114METHOD(imc_state_t, set_flags, void,
115 private_imc_swima_state_t *this, bool has_long, bool has_excl)
116{
117 this->has_long = has_long;
118 this->has_excl = has_excl;
119}
120
121METHOD(imc_state_t, set_max_msg_len, void,
122 private_imc_swima_state_t *this, uint32_t max_msg_len)
123{
124 this->max_msg_len = max_msg_len;
125}
126
127METHOD(imc_state_t, get_max_msg_len, uint32_t,
128 private_imc_swima_state_t *this)
129{
130 return this->max_msg_len;
131}
132
133METHOD(imc_state_t, get_contracts, seg_contract_manager_t*,
134 private_imc_swima_state_t *this)
135{
136 return this->contracts;
137}
138
731e043c 139METHOD(imc_state_t, change_state, TNC_ConnectionState,
2821c0f7
AS
140 private_imc_swima_state_t *this, TNC_ConnectionState new_state)
141{
731e043c
AS
142 TNC_ConnectionState old_state;
143
144 old_state = this->state;
2821c0f7 145 this->state = new_state;
731e043c 146 return old_state;
2821c0f7
AS
147}
148
149METHOD(imc_state_t, set_result, void,
150 private_imc_swima_state_t *this, TNC_IMCID id,
151 TNC_IMV_Evaluation_Result result)
152{
153 this->result = result;
154}
155
156METHOD(imc_state_t, get_result, bool,
157 private_imc_swima_state_t *this, TNC_IMCID id,
158 TNC_IMV_Evaluation_Result *result)
159{
160 if (result)
161 {
162 *result = this->result;
163 }
164 return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
165}
166
731e043c
AS
167METHOD(imc_state_t, reset, void,
168 private_imc_swima_state_t *this)
169{
170 this->result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
171}
172
2821c0f7
AS
173METHOD(imc_state_t, destroy, void,
174 private_imc_swima_state_t *this)
175{
f649a13c 176 free(this->subscription);
2821c0f7
AS
177 this->contracts->destroy(this->contracts);
178 free(this);
179}
180
f649a13c
AS
181METHOD(imc_swima_state_t, set_subscription, void,
182 private_imc_swima_state_t *this, imc_swima_subscription_t *subscription,
183 bool set)
184{
185 free_subscription(this->subscription);
186 this->has_subscription = set;
187
188 if (set)
189 {
190 this->subscription = subscription;
191 }
192 else
193 {
194 this->subscription = NULL;
195 }
196}
197
198METHOD(imc_swima_state_t, get_subscription, bool,
199 private_imc_swima_state_t *this, imc_swima_subscription_t **subscription)
200{
201 if (subscription)
202 {
203 *subscription = this->subscription;
204 }
205 return this->has_subscription;
206}
207
208METHOD(imc_swima_state_t, set_earliest_eid, void,
209 private_imc_swima_state_t *this, uint32_t eid)
210{
211 this->earliest_eid = eid;
212}
213
214METHOD(imc_swima_state_t, get_earliest_eid, uint32_t,
215 private_imc_swima_state_t *this)
216{
217 return this->earliest_eid;
218}
219
2821c0f7
AS
220/**
221 * Described in header.
222 */
223imc_state_t *imc_swima_state_create(TNC_ConnectionID connection_id)
224{
225 private_imc_swima_state_t *this;
226
227 INIT(this,
228 .public = {
229 .interface = {
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,
731e043c 240 .reset = _reset,
2821c0f7
AS
241 .destroy = _destroy,
242 },
f649a13c
AS
243 .set_subscription = _set_subscription,
244 .get_subscription = _get_subscription,
245 .set_earliest_eid = _set_earliest_eid,
246 .get_earliest_eid = _get_earliest_eid,
2821c0f7
AS
247 },
248 .state = TNC_CONNECTION_STATE_CREATE,
249 .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
250 .connection_id = connection_id,
251 .contracts = seg_contract_manager_create(),
252 );
f649a13c 253
2821c0f7
AS
254 return &this->public.interface;
255}
256
257