2 * Copyright (C) 2012 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 "imv_os_state.h"
18 #include <utils/debug.h>
20 typedef struct private_imv_os_state_t private_imv_os_state_t
;
23 * Private data of an imv_os_state_t object.
25 struct private_imv_os_state_t
{
28 * Public members of imv_os_state_t
30 imv_os_state_t
public;
35 TNC_ConnectionID connection_id
;
38 * TNCCS connection state
40 TNC_ConnectionState state
;
43 * Does the TNCCS connection support long message types?
48 * Does the TNCCS connection support exclusive delivery?
53 * Maximum PA-TNC message size for this TNCCS connection
55 u_int32_t max_msg_len
;
58 * IMV action recommendation
60 TNC_IMV_Action_Recommendation rec
;
63 * IMV evaluation result
65 TNC_IMV_Evaluation_Result eval
;
68 * OS Product Information (concatenation of OS Name and Version)
88 * Number of processed packages
93 * Number of blacklisted or not updated packages
98 * Number of whitelisted packages
103 * OS Installed Package request sent - mandatory response expected
105 bool package_request
;
114 typedef struct entry_t entry_t
;
117 * Define an internal reason string entry
125 * Table of multi-lingual reason string entries
127 static entry_t reasons
[] = {
134 METHOD(imv_state_t
, get_connection_id
, TNC_ConnectionID
,
135 private_imv_os_state_t
*this)
137 return this->connection_id
;
140 METHOD(imv_state_t
, has_long
, bool,
141 private_imv_os_state_t
*this)
143 return this->has_long
;
146 METHOD(imv_state_t
, has_excl
, bool,
147 private_imv_os_state_t
*this)
149 return this->has_excl
;
152 METHOD(imv_state_t
, set_flags
, void,
153 private_imv_os_state_t
*this, bool has_long
, bool has_excl
)
155 this->has_long
= has_long
;
156 this->has_excl
= has_excl
;
159 METHOD(imv_state_t
, set_max_msg_len
, void,
160 private_imv_os_state_t
*this, u_int32_t max_msg_len
)
162 this->max_msg_len
= max_msg_len
;
165 METHOD(imv_state_t
, get_max_msg_len
, u_int32_t
,
166 private_imv_os_state_t
*this)
168 return this->max_msg_len
;
171 METHOD(imv_state_t
, change_state
, void,
172 private_imv_os_state_t
*this, TNC_ConnectionState new_state
)
174 this->state
= new_state
;
177 METHOD(imv_state_t
, get_recommendation
, void,
178 private_imv_os_state_t
*this, TNC_IMV_Action_Recommendation
*rec
,
179 TNC_IMV_Evaluation_Result
*eval
)
185 METHOD(imv_state_t
, set_recommendation
, void,
186 private_imv_os_state_t
*this, TNC_IMV_Action_Recommendation rec
,
187 TNC_IMV_Evaluation_Result eval
)
193 METHOD(imv_state_t
, get_reason_string
, bool,
194 private_imv_os_state_t
*this, enumerator_t
*language_enumerator
,
195 char **reason_string
, char **reason_language
)
200 METHOD(imv_state_t
, get_remediation_instructions
, bool,
201 private_imv_os_state_t
*this, enumerator_t
*language_enumerator
,
202 char **string
, char **lang_code
, char **uri
)
207 METHOD(imv_state_t
, destroy
, void,
208 private_imv_os_state_t
*this)
211 free(this->name
.ptr
);
212 free(this->version
.ptr
);
216 METHOD(imv_os_state_t
, set_info
, void,
217 private_imv_os_state_t
*this, os_type_t type
, chunk_t name
, chunk_t version
)
219 int len
= name
.len
+ 1 + version
.len
+ 1;
221 /* OS info is a concatenation of OS name and OS version */
223 this->info
= malloc(len
);
224 snprintf(this->info
, len
, "%.*s %.*s", name
.len
, name
.ptr
,
225 version
.len
, version
.ptr
);
227 this->name
= chunk_clone(name
);
228 this->version
= chunk_clone(version
);
231 METHOD(imv_os_state_t
, get_info
, char*,
232 private_imv_os_state_t
*this, os_type_t
*type
, chunk_t
*name
,
245 *version
= this->version
;
250 METHOD(imv_os_state_t
, set_count
, void,
251 private_imv_os_state_t
*this, int count
, int count_bad
, int count_ok
)
253 this->count
+= count
;
254 this->count_bad
+= count_bad
;
255 this->count_ok
+= count_ok
;
258 METHOD(imv_os_state_t
, get_count
, void,
259 private_imv_os_state_t
*this, int *count
, int *count_bad
, int *count_ok
)
263 *count
= this->count
;
267 *count_bad
= this->count_bad
;
271 *count_ok
= this->count_ok
;
275 METHOD(imv_os_state_t
, set_package_request
, void,
276 private_imv_os_state_t
*this, bool set
)
278 this->package_request
= set
;
281 METHOD(imv_os_state_t
, get_package_request
, bool,
282 private_imv_os_state_t
*this)
284 return this->package_request
;
287 METHOD(imv_os_state_t
, set_angel_count
, void,
288 private_imv_os_state_t
*this, bool start
)
290 this->angel_count
+= start ?
1 : -1;
293 METHOD(imv_os_state_t
, get_angel_count
, int,
294 private_imv_os_state_t
*this)
296 return this->angel_count
;
300 * Described in header.
302 imv_state_t
*imv_os_state_create(TNC_ConnectionID connection_id
)
304 private_imv_os_state_t
*this;
309 .get_connection_id
= _get_connection_id
,
310 .has_long
= _has_long
,
311 .has_excl
= _has_excl
,
312 .set_flags
= _set_flags
,
313 .set_max_msg_len
= _set_max_msg_len
,
314 .get_max_msg_len
= _get_max_msg_len
,
315 .change_state
= _change_state
,
316 .get_recommendation
= _get_recommendation
,
317 .set_recommendation
= _set_recommendation
,
318 .get_reason_string
= _get_reason_string
,
319 .get_remediation_instructions
= _get_remediation_instructions
,
322 .set_info
= _set_info
,
323 .get_info
= _get_info
,
324 .set_count
= _set_count
,
325 .get_count
= _get_count
,
326 .set_package_request
= _set_package_request
,
327 .get_package_request
= _get_package_request
,
328 .set_angel_count
= _set_angel_count
,
329 .get_angel_count
= _get_angel_count
,
331 .state
= TNC_CONNECTION_STATE_CREATE
,
332 .rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
333 .eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
334 .connection_id
= connection_id
,
337 return &this->public.interface
;