created OS IMC/IMV pair
[strongswan.git] / src / libimcv / plugins / imv_os / imv_os_state.c
1 /*
2 * Copyright (C) 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 "imv_os_state.h"
17
18 #include <debug.h>
19
20 typedef struct private_imv_os_state_t private_imv_os_state_t;
21
22 /**
23 * Private data of an imv_os_state_t object.
24 */
25 struct private_imv_os_state_t {
26
27 /**
28 * Public members of imv_os_state_t
29 */
30 imv_os_state_t public;
31
32 /**
33 * TNCCS connection ID
34 */
35 TNC_ConnectionID connection_id;
36
37 /**
38 * TNCCS connection state
39 */
40 TNC_ConnectionState state;
41
42 /**
43 * Does the TNCCS connection support long message types?
44 */
45 bool has_long;
46
47 /**
48 * Does the TNCCS connection support exclusive delivery?
49 */
50 bool has_excl;
51
52 /**
53 * Maximum PA-TNC message size for this TNCCS connection
54 */
55 u_int32_t max_msg_len;
56
57 /**
58 * IMV action recommendation
59 */
60 TNC_IMV_Action_Recommendation rec;
61
62 /**
63 * IMV evaluation result
64 */
65 TNC_IMV_Evaluation_Result eval;
66
67 /**
68 * OS Product Information
69 */
70 char *info;
71 };
72
73 typedef struct entry_t entry_t;
74
75 /**
76 * Define an internal reason string entry
77 */
78 struct entry_t {
79 char *lang;
80 char *string;
81 };
82
83 /**
84 * Table of multi-lingual reason string entries
85 */
86 static entry_t reasons[] = {
87 { "en", "" },
88 { "de", "" },
89 { "fr", "" },
90 { "pl", "" }
91 };
92
93 METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
94 private_imv_os_state_t *this)
95 {
96 return this->connection_id;
97 }
98
99 METHOD(imv_state_t, has_long, bool,
100 private_imv_os_state_t *this)
101 {
102 return this->has_long;
103 }
104
105 METHOD(imv_state_t, has_excl, bool,
106 private_imv_os_state_t *this)
107 {
108 return this->has_excl;
109 }
110
111 METHOD(imv_state_t, set_flags, void,
112 private_imv_os_state_t *this, bool has_long, bool has_excl)
113 {
114 this->has_long = has_long;
115 this->has_excl = has_excl;
116 }
117
118 METHOD(imv_state_t, set_max_msg_len, void,
119 private_imv_os_state_t *this, u_int32_t max_msg_len)
120 {
121 this->max_msg_len = max_msg_len;
122 }
123
124 METHOD(imv_state_t, get_max_msg_len, u_int32_t,
125 private_imv_os_state_t *this)
126 {
127 return this->max_msg_len;
128 }
129
130 METHOD(imv_state_t, change_state, void,
131 private_imv_os_state_t *this, TNC_ConnectionState new_state)
132 {
133 this->state = new_state;
134 }
135
136 METHOD(imv_state_t, get_recommendation, void,
137 private_imv_os_state_t *this, TNC_IMV_Action_Recommendation *rec,
138 TNC_IMV_Evaluation_Result *eval)
139 {
140 *rec = this->rec;
141 *eval = this->eval;
142 }
143
144 METHOD(imv_state_t, set_recommendation, void,
145 private_imv_os_state_t *this, TNC_IMV_Action_Recommendation rec,
146 TNC_IMV_Evaluation_Result eval)
147 {
148 this->rec = rec;
149 this->eval = eval;
150 }
151
152 METHOD(imv_state_t, get_reason_string, bool,
153 private_imv_os_state_t *this, chunk_t preferred_language,
154 chunk_t *reason_string, chunk_t *reason_language)
155 {
156 return FALSE;
157 }
158
159 METHOD(imv_state_t, destroy, void,
160 private_imv_os_state_t *this)
161 {
162 free(this->info);
163 free(this);
164 }
165
166 METHOD(imv_os_state_t, set_info, void,
167 private_imv_os_state_t *this, char *info)
168 {
169 this->info = strdup(info);
170 }
171
172 METHOD(imv_os_state_t, get_info, char*,
173 private_imv_os_state_t *this)
174 {
175 return this->info;
176 }
177
178 /**
179 * Described in header.
180 */
181 imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id)
182 {
183 private_imv_os_state_t *this;
184
185 INIT(this,
186 .public = {
187 .interface = {
188 .get_connection_id = _get_connection_id,
189 .has_long = _has_long,
190 .has_excl = _has_excl,
191 .set_flags = _set_flags,
192 .set_max_msg_len = _set_max_msg_len,
193 .get_max_msg_len = _get_max_msg_len,
194 .change_state = _change_state,
195 .get_recommendation = _get_recommendation,
196 .set_recommendation = _set_recommendation,
197 .get_reason_string = _get_reason_string,
198 .destroy = _destroy,
199 },
200 .set_info = _set_info,
201 .get_info = _get_info,
202 },
203 .state = TNC_CONNECTION_STATE_CREATE,
204 .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
205 .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
206 .connection_id = connection_id,
207 );
208
209 return &this->public.interface;
210 }
211
212