2b1cdcc6bc9deeff78d930e87f576f53b94d0d8f
[strongswan.git] / src / libimcv / plugins / imv_os / imv_os_state.h
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 /**
17 * @defgroup imv_os imv_os
18 * @ingroup libimcv_plugins
19 *
20 * @defgroup imv_os_state_t imv_os_state
21 * @{ @ingroup imv_os
22 */
23
24 #ifndef IMV_OS_STATE_H_
25 #define IMV_OS_STATE_H_
26
27 #include "os_info/os_info.h"
28 #include <imv/imv_state.h>
29 #include <library.h>
30
31 typedef struct imv_os_state_t imv_os_state_t;
32 typedef enum imv_os_handshake_state_t imv_os_handshake_state_t;
33 typedef enum imv_os_attr_t imv_os_attr_t;
34 typedef enum os_settings_t os_settings_t;
35
36 /**
37 * IMV OS Handshake States (state machine)
38 */
39 enum imv_os_handshake_state_t {
40 IMV_OS_STATE_INIT,
41 IMV_OS_STATE_ATTR_REQ,
42 IMV_OS_STATE_POLICY_START,
43 IMV_OS_STATE_WORKITEMS
44 };
45
46 /**
47 * Flag set when corresponding attribute has been received
48 */
49 enum imv_os_attr_t {
50 IMV_OS_ATTR_PRODUCT_INFORMATION = (1<<0),
51 IMV_OS_ATTR_STRING_VERSION = (1<<1),
52 IMV_OS_ATTR_NUMERIC_VERSION = (1<<2),
53 IMV_OS_ATTR_OPERATIONAL_STATUS = (1<<3),
54 IMV_OS_ATTR_FORWARDING_ENABLED = (1<<4),
55 IMV_OS_ATTR_FACTORY_DEFAULT_PWD_ENABLED = (1<<5),
56 IMV_OS_ATTR_DEVICE_ID = (1<<6),
57 IMV_OS_ATTR_MUST = (1<<7)-1,
58 IMV_OS_ATTR_INSTALLED_PACKAGES = (1<<7),
59 IMV_OS_ATTR_SETTINGS = (1<<8)
60 };
61
62 /**
63 * Flags for detected OS Settings
64 */
65 enum os_settings_t {
66 OS_SETTINGS_FWD_ENABLED = (1<<0),
67 OS_SETTINGS_DEFAULT_PWD_ENABLED = (1<<1),
68 OS_SETTINGS_UNKNOWN_SOURCE = (1<<2)
69 };
70
71 /**
72 * Internal state of an imv_os_t connection instance
73 */
74 struct imv_os_state_t {
75
76 /**
77 * imv_state_t interface
78 */
79 imv_state_t interface;
80
81 /**
82 * Set state of the handshake
83 *
84 * @param new_state the handshake state of IMV
85 */
86 void (*set_handshake_state)(imv_os_state_t *this,
87 imv_os_handshake_state_t new_state);
88
89 /**
90 * Get state of the handshake
91 *
92 * @return the handshake state of IMV
93 */
94 imv_os_handshake_state_t (*get_handshake_state)(imv_os_state_t *this);
95
96 /**
97 * Set OS Product Information
98 *
99 * @param type OS type (enumerated)
100 * @param name OS name (string)
101 * @param version OS version
102 */
103 void (*set_info)(imv_os_state_t *this, os_type_t os_type,
104 chunk_t name, chunk_t version);
105
106 /**
107 * Get OS Product Information
108 *
109 * @param type OS type (enumerated)
110 * @param name OS name (string)
111 * @param version OS version
112 * @return OS name & version as a concatenated string
113 */
114 char* (*get_info)(imv_os_state_t *this, os_type_t *os_type,
115 chunk_t *name, chunk_t *version);
116
117 /**
118 * Set [or with multiple attributes increment] package counters
119 *
120 * @param count Number of processed packages
121 * @param count_update Number of not updated packages
122 * @param count_blacklist Number of blacklisted packages
123 * @param count_ok Number of whitelisted packages
124 */
125 void (*set_count)(imv_os_state_t *this, int count, int count_update,
126 int count_blacklist, int count_ok);
127
128 /**
129 * Set [or with multiple attributes increment] package counters
130 *
131 * @param count Number of processed packages
132 * @param count_update Number of not updated packages
133 * @param count_blacklist Number of blacklisted packages
134 * @param count_ok Number of whitelisted packages
135 */
136 void (*get_count)(imv_os_state_t *this, int *count, int *count_update,
137 int *count_blacklist, int *count_ok);
138
139 /**
140 * Set flags for received attributes
141 *
142 * @param flags Flags to be set
143 */
144 void (*set_received)(imv_os_state_t *this, u_int flags);
145
146 /**
147 * Get flags set for received attributes
148 *
149 * @return Flags set for received attributes
150 */
151 u_int (*get_received)(imv_os_state_t *this);
152
153 /**
154 * Set device ID
155 *
156 * @param device_id Device ID primary database key
157 */
158 void (*set_device_id)(imv_os_state_t *this, int id);
159
160 /**
161 * Get device ID
162 *
163 * @return Device ID primary database key
164 */
165 int (*get_device_id)(imv_os_state_t *this);
166
167 /**
168 * Set OS settings
169 *
170 * @param settings OS settings
171 */
172 void (*set_os_settings)(imv_os_state_t *this, u_int settings);
173
174 /**
175 * Get OS settings
176 *
177 * @return OS settings
178 */
179 u_int (*get_os_settings)(imv_os_state_t *this);
180
181 /**
182 * Increase/Decrease the ITA Angel count
183 *
184 * @param start TRUE increases and FALSE decreases count by one
185 */
186 void (*set_angel_count)(imv_os_state_t *this, bool start);
187
188 /**
189 * Get the ITA Angel count
190 *
191 * @return ITA Angel count
192 */
193 int (*get_angel_count)(imv_os_state_t *this);
194
195 /**
196 * Store a bad package that has to be updated or removed
197 *
198 * @param package Name of software package
199 * @param package_state Security state of software package
200 */
201 void (*add_bad_package)(imv_os_state_t *this, char *package,
202 os_package_state_t package_state);
203
204 };
205
206 /**
207 * Create an imv_os_state_t instance
208 *
209 * @param id connection ID
210 */
211 imv_state_t* imv_os_state_create(TNC_ConnectionID id);
212
213 #endif /** IMV_OS_STATE_H_ @}*/