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 * OS Installed Package request sent - mandatory response expected
99 typedef struct entry_t entry_t
;
102 * Define an internal reason string entry
110 * Table of multi-lingual reason string entries
112 static entry_t reasons
[] = {
119 METHOD(imv_state_t
, get_connection_id
, TNC_ConnectionID
,
120 private_imv_os_state_t
*this)
122 return this->connection_id
;
125 METHOD(imv_state_t
, has_long
, bool,
126 private_imv_os_state_t
*this)
128 return this->has_long
;
131 METHOD(imv_state_t
, has_excl
, bool,
132 private_imv_os_state_t
*this)
134 return this->has_excl
;
137 METHOD(imv_state_t
, set_flags
, void,
138 private_imv_os_state_t
*this, bool has_long
, bool has_excl
)
140 this->has_long
= has_long
;
141 this->has_excl
= has_excl
;
144 METHOD(imv_state_t
, set_max_msg_len
, void,
145 private_imv_os_state_t
*this, u_int32_t max_msg_len
)
147 this->max_msg_len
= max_msg_len
;
150 METHOD(imv_state_t
, get_max_msg_len
, u_int32_t
,
151 private_imv_os_state_t
*this)
153 return this->max_msg_len
;
156 METHOD(imv_state_t
, change_state
, void,
157 private_imv_os_state_t
*this, TNC_ConnectionState new_state
)
159 this->state
= new_state
;
162 METHOD(imv_state_t
, get_recommendation
, void,
163 private_imv_os_state_t
*this, TNC_IMV_Action_Recommendation
*rec
,
164 TNC_IMV_Evaluation_Result
*eval
)
170 METHOD(imv_state_t
, set_recommendation
, void,
171 private_imv_os_state_t
*this, TNC_IMV_Action_Recommendation rec
,
172 TNC_IMV_Evaluation_Result eval
)
178 METHOD(imv_state_t
, get_reason_string
, bool,
179 private_imv_os_state_t
*this, chunk_t preferred_language
,
180 chunk_t
*reason_string
, chunk_t
*reason_language
)
185 METHOD(imv_state_t
, destroy
, void,
186 private_imv_os_state_t
*this)
189 free(this->name
.ptr
);
190 free(this->version
.ptr
);
194 METHOD(imv_os_state_t
, set_info
, void,
195 private_imv_os_state_t
*this, os_type_t type
, chunk_t name
, chunk_t version
)
197 int len
= name
.len
+ 1 + version
.len
+ 1;
199 /* OS info is a concatenation of OS name and OS version */
201 this->info
= malloc(len
);
202 snprintf(this->info
, len
, "%.*s %.*s", name
.len
, name
.ptr
,
203 version
.len
, version
.ptr
);
205 this->name
= chunk_clone(name
);
206 this->version
= chunk_clone(version
);
209 METHOD(imv_os_state_t
, get_info
, char*,
210 private_imv_os_state_t
*this, os_type_t
*type
, chunk_t
*name
,
223 *version
= this->version
;
228 METHOD(imv_os_state_t
, get_type
, os_type_t
,
229 private_imv_os_state_t
*this)
234 METHOD(imv_os_state_t
, set_package_request
, void,
235 private_imv_os_state_t
*this, bool set
)
237 this->package_request
= set
;
240 METHOD(imv_os_state_t
, get_package_request
, bool,
241 private_imv_os_state_t
*this)
243 return this->package_request
;
246 METHOD(imv_os_state_t
, set_angel_count
, void,
247 private_imv_os_state_t
*this, bool start
)
249 this->angel_count
+= start ?
1 : -1;
252 METHOD(imv_os_state_t
, get_angel_count
, int,
253 private_imv_os_state_t
*this)
255 return this->angel_count
;
259 * Described in header.
261 imv_state_t
*imv_os_state_create(TNC_ConnectionID connection_id
)
263 private_imv_os_state_t
*this;
268 .get_connection_id
= _get_connection_id
,
269 .has_long
= _has_long
,
270 .has_excl
= _has_excl
,
271 .set_flags
= _set_flags
,
272 .set_max_msg_len
= _set_max_msg_len
,
273 .get_max_msg_len
= _get_max_msg_len
,
274 .change_state
= _change_state
,
275 .get_recommendation
= _get_recommendation
,
276 .set_recommendation
= _set_recommendation
,
277 .get_reason_string
= _get_reason_string
,
280 .set_info
= _set_info
,
281 .get_info
= _get_info
,
282 .set_package_request
= _set_package_request
,
283 .get_package_request
= _get_package_request
,
284 .set_angel_count
= _set_angel_count
,
285 .get_angel_count
= _get_angel_count
,
287 .state
= TNC_CONNECTION_STATE_CREATE
,
288 .rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
289 .eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
290 .connection_id
= connection_id
,
293 return &this->public.interface
;