Moved all functionality into imv_os_agent_t class turning imv_os_t into an IF-IMV...
[strongswan.git] / src / libimcv / plugins / imv_os / imv_os.c
1 /*
2 * Copyright (C) 2012-2013 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_agent.h"
17
18 #include <utils/debug.h>
19
20 /* IMV definitions */
21
22 static const char imv_name[] = "OS";
23
24 static imv_os_agent_t *imv_agent;
25
26 /*
27 * see section 3.8.1 of TCG TNC IF-IMV Specification 1.3
28 */
29 TNC_Result TNC_IMV_Initialize(TNC_IMVID imv_id,
30 TNC_Version min_version,
31 TNC_Version max_version,
32 TNC_Version *actual_version)
33 {
34 if (imv_agent)
35 {
36 DBG1(DBG_IMV, "IMV \"%s\" has already been initialized", imv_name);
37 return TNC_RESULT_ALREADY_INITIALIZED;
38 }
39
40 imv_agent =imv_os_agent_create(imv_name, imv_id, actual_version);
41
42 if (!imv_agent)
43 {
44 return TNC_RESULT_FATAL;
45 }
46 if (min_version > TNC_IFIMV_VERSION_1 || max_version < TNC_IFIMV_VERSION_1)
47 {
48 DBG1(DBG_IMV, "no common IF-IMV version");
49 return TNC_RESULT_NO_COMMON_VERSION;
50 }
51 return TNC_RESULT_SUCCESS;
52 }
53
54 /**
55 * see section 3.8.2 of TCG TNC IF-IMV Specification 1.3
56 */
57 TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id,
58 TNC_ConnectionID connection_id,
59 TNC_ConnectionState new_state)
60 {
61 if (!imv_agent)
62 {
63 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
64 return TNC_RESULT_NOT_INITIALIZED;
65 }
66 return imv_agent->notify_connection_change(imv_agent, connection_id,
67 new_state);
68 }
69
70 /**
71 * see section 3.8.4 of TCG TNC IF-IMV Specification 1.3
72 */
73 TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
74 TNC_ConnectionID connection_id,
75 TNC_BufferReference msg,
76 TNC_UInt32 msg_len,
77 TNC_MessageType msg_type)
78 {
79 if (!imv_agent)
80 {
81 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
82 return TNC_RESULT_NOT_INITIALIZED;
83 }
84 return imv_agent->receive_message(imv_agent, connection_id, msg_type,
85 chunk_create(msg, msg_len));
86 }
87
88 /**
89 * see section 3.8.6 of TCG TNC IF-IMV Specification 1.3
90 */
91 TNC_Result TNC_IMV_ReceiveMessageLong(TNC_IMVID imv_id,
92 TNC_ConnectionID connection_id,
93 TNC_UInt32 msg_flags,
94 TNC_BufferReference msg,
95 TNC_UInt32 msg_len,
96 TNC_VendorID msg_vid,
97 TNC_MessageSubtype msg_subtype,
98 TNC_UInt32 src_imc_id,
99 TNC_UInt32 dst_imv_id)
100 {
101 if (!imv_agent)
102 {
103 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
104 return TNC_RESULT_NOT_INITIALIZED;
105 }
106 return imv_agent->receive_message_long(imv_agent, connection_id,
107 src_imc_id, dst_imv_id,
108 msg_vid, msg_subtype, chunk_create(msg, msg_len));
109 }
110
111 /**
112 * see section 3.8.7 of TCG TNC IF-IMV Specification 1.3
113 */
114 TNC_Result TNC_IMV_SolicitRecommendation(TNC_IMVID imv_id,
115 TNC_ConnectionID connection_id)
116 {
117
118 if (!imv_agent)
119 {
120 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
121 return TNC_RESULT_NOT_INITIALIZED;
122 }
123 return imv_agent->solicit_recommendation(imv_agent, connection_id);
124 }
125
126 /**
127 * see section 3.8.8 of TCG TNC IF-IMV Specification 1.3
128 */
129 TNC_Result TNC_IMV_BatchEnding(TNC_IMVID imv_id, TNC_ConnectionID connection_id)
130 {
131 if (!imv_agent)
132 {
133 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
134 return TNC_RESULT_NOT_INITIALIZED;
135 }
136 return imv_agent->batch_ending(imv_agent, connection_id);
137 }
138
139 /**
140 * see section 3.8.9 of TCG TNC IF-IMV Specification 1.3
141 */
142 TNC_Result TNC_IMV_Terminate(TNC_IMVID imv_id)
143 {
144 if (!imv_agent)
145 {
146 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
147 return TNC_RESULT_NOT_INITIALIZED;
148 }
149 imv_agent->destroy(imv_agent);
150 imv_agent = NULL;
151
152 return TNC_RESULT_SUCCESS;
153 }
154
155 /**
156 * see section 4.2.8.1 of TCG TNC IF-IMV Specification 1.3
157 */
158 TNC_Result TNC_IMV_ProvideBindFunction(TNC_IMVID imv_id,
159 TNC_TNCS_BindFunctionPointer bind_function)
160 {
161 if (!imv_agent)
162 {
163 DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name);
164 return TNC_RESULT_NOT_INITIALIZED;
165 }
166 return imv_agent->bind_functions(imv_agent, bind_function);
167 }