5877d1efd0dfc009cd0044f47c7795ca473845a7
[strongswan.git] / src / libimcv / plugins / imc_test / imc_test_state.c
1 /*
2 * Copyright (C) 2011-2012 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_test_state.h"
17
18 #include <debug.h>
19 #include <utils/linked_list.h>
20
21 typedef struct private_imc_test_state_t private_imc_test_state_t;
22
23 /**
24 * Private data of an imc_test_state_t object.
25 */
26 struct private_imc_test_state_t {
27
28 /**
29 * Public members of imc_test_state_t
30 */
31 imc_test_state_t public;
32
33 /**
34 * TNCCS connection ID
35 */
36 TNC_ConnectionID connection_id;
37
38 /**
39 * TNCCS connection state
40 */
41 TNC_ConnectionState state;
42
43 /**
44 * Does the TNCCS connection support long message types?
45 */
46 bool has_long;
47
48 /**
49 * Does the TNCCS connection support exclusive delivery?
50 */
51 bool has_excl;
52
53 /**
54 * Maximum PA-TNC message size for this TNCCS connection
55 */
56 u_int32_t max_msg_len;
57
58 /**
59 * Command to transmit to IMV
60 */
61 char *command;
62
63 /**
64 * Size of the dummy attribute value to transmit to IMV
65 */
66 int dummy_size;
67
68 /**
69 * Is it the first handshake?
70 */
71 bool first_handshake;
72
73 /**
74 * Do a handshake retry
75 */
76 bool handshake_retry;
77
78 };
79
80 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
81 private_imc_test_state_t *this)
82 {
83 return this->connection_id;
84 }
85
86 METHOD(imc_state_t, has_long, bool,
87 private_imc_test_state_t *this)
88 {
89 return this->has_long;
90 }
91
92 METHOD(imc_state_t, has_excl, bool,
93 private_imc_test_state_t *this)
94 {
95 return this->has_excl;
96 }
97
98 METHOD(imc_state_t, set_flags, void,
99 private_imc_test_state_t *this, bool has_long, bool has_excl)
100 {
101 this->has_long = has_long;
102 this->has_excl = has_excl;
103 }
104
105 METHOD(imc_state_t, set_max_msg_len, void,
106 private_imc_test_state_t *this, u_int32_t max_msg_len)
107 {
108 this->max_msg_len = max_msg_len;
109 }
110
111 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
112 private_imc_test_state_t *this)
113 {
114 return this->max_msg_len;
115 }
116
117 METHOD(imc_state_t, change_state, void,
118 private_imc_test_state_t *this, TNC_ConnectionState new_state)
119 {
120 this->state = new_state;
121 }
122
123 METHOD(imc_state_t, destroy, void,
124 private_imc_test_state_t *this)
125 {
126 free(this->command);
127 free(this);
128 }
129
130 METHOD(imc_test_state_t, get_command, char*,
131 private_imc_test_state_t *this)
132 {
133 return this->command;
134 }
135
136 METHOD(imc_test_state_t, set_command, void,
137 private_imc_test_state_t *this, char* command)
138 {
139 char *old_command;
140
141 old_command = this->command;
142 this->command = strdup(command);
143 free(old_command);
144 }
145
146 METHOD(imc_test_state_t, get_dummy_size, int,
147 private_imc_test_state_t *this)
148 {
149 return this->dummy_size;
150 }
151
152
153 METHOD(imc_test_state_t, is_first_handshake, bool,
154 private_imc_test_state_t *this)
155 {
156 bool first;
157
158 /* test and reset first_handshake flag */
159 first= this->first_handshake;
160 this->first_handshake = FALSE;
161 return first;
162 }
163
164 METHOD(imc_test_state_t, do_handshake_retry, bool,
165 private_imc_test_state_t *this)
166 {
167 bool retry;
168
169 /* test and reset handshake_retry flag */
170 retry = this->handshake_retry;
171 this->handshake_retry = FALSE;
172 return retry;
173 }
174
175 /**
176 * Described in header.
177 */
178 imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
179 char *command, int dummy_size, bool retry)
180 {
181 private_imc_test_state_t *this;
182
183 INIT(this,
184 .public = {
185 .interface = {
186 .get_connection_id = _get_connection_id,
187 .has_long = _has_long,
188 .has_excl = _has_excl,
189 .set_flags = _set_flags,
190 .set_max_msg_len = _set_max_msg_len,
191 .get_max_msg_len = _get_max_msg_len,
192 .change_state = _change_state,
193 .destroy = _destroy,
194 },
195 .get_command = _get_command,
196 .set_command = _set_command,
197 .get_dummy_size = _get_dummy_size,
198 .is_first_handshake = _is_first_handshake,
199 .do_handshake_retry = _do_handshake_retry,
200 },
201 .state = TNC_CONNECTION_STATE_CREATE,
202 .connection_id = connection_id,
203 .command = strdup(command),
204 .dummy_size = dummy_size,
205 .first_handshake = TRUE,
206 .handshake_retry = retry,
207 );
208
209 return &this->public.interface;
210 }
211