Documented plugin move from libcharon to libtnccs in strongswan.conf
[strongswan.git] / src / libcharon / plugins / tnc_imv / tnc_imv_bind_function.c
1 /*
2 * Copyright (C) 2006 Mike McCauley
3 * Copyright (C) 2010-2011 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <tnc/tnc.h>
18 #include <tnc/imv/imv_manager.h>
19 #include <tnc/tnccs/tnccs_manager.h>
20
21 #include <utils/debug.h>
22
23 /**
24 * Called by the IMV to inform a TNCS about the set of message types the IMV
25 * is able to receive
26 */
27 TNC_Result TNC_TNCS_ReportMessageTypes(TNC_IMVID imv_id,
28 TNC_MessageTypeList supported_types,
29 TNC_UInt32 type_count)
30 {
31 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
32 {
33 DBG1(DBG_TNC, "ignoring ReportMessageTypes() from unregistered IMV %u",
34 imv_id);
35 return TNC_RESULT_INVALID_PARAMETER;
36 }
37 return tnc->imvs->set_message_types(tnc->imvs, imv_id, supported_types,
38 type_count);
39 }
40
41 /**
42 * Called by the IMV to inform a TNCS about the set of message types the IMV
43 * is able to receive. This function supports long message types.
44 */
45 TNC_Result TNC_TNCS_ReportMessageTypesLong(TNC_IMVID imv_id,
46 TNC_VendorIDList supported_vids,
47 TNC_MessageSubtypeList supported_subtypes,
48 TNC_UInt32 type_count)
49 {
50 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
51 {
52 DBG1(DBG_TNC, "ignoring ReportMessageTypesLong() from unregistered IMV %u",
53 imv_id);
54 return TNC_RESULT_INVALID_PARAMETER;
55 }
56 return tnc->imvs->set_message_types_long(tnc->imvs, imv_id, supported_vids,
57 supported_subtypes, type_count);
58 }
59
60 /**
61 * Called by the IMV to ask a TNCS to retry an Integrity Check Handshake
62 */
63 TNC_Result TNC_TNCS_RequestHandshakeRetry(TNC_IMVID imv_id,
64 TNC_ConnectionID connection_id,
65 TNC_RetryReason reason)
66 {
67 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
68 {
69 DBG1(DBG_TNC, "ignoring RequestHandshakeRetry() from unregistered IMV %u",
70 imv_id);
71 return TNC_RESULT_INVALID_PARAMETER;
72 }
73 return tnc->tnccs->request_handshake_retry(tnc->tnccs, FALSE, imv_id,
74 connection_id, reason);
75 }
76
77 /**
78 * Called by the IMV when an IMV-IMC message is to be sent
79 */
80 TNC_Result TNC_TNCS_SendMessage(TNC_IMVID imv_id,
81 TNC_ConnectionID connection_id,
82 TNC_BufferReference msg,
83 TNC_UInt32 msg_len,
84 TNC_MessageType msg_type)
85 {
86 TNC_VendorID msg_vid;
87 TNC_MessageSubtype msg_subtype;
88
89 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
90 {
91 DBG1(DBG_TNC, "ignoring SendMessage() from unregistered IMV %u",
92 imv_id);
93 return TNC_RESULT_INVALID_PARAMETER;
94 }
95 msg_vid = (msg_type >> 8) & TNC_VENDORID_ANY;
96 msg_subtype = msg_type & TNC_SUBTYPE_ANY;
97
98 return tnc->tnccs->send_message(tnc->tnccs, TNC_IMCID_ANY, imv_id,
99 connection_id, 0, msg, msg_len, msg_vid, msg_subtype);
100 }
101
102 /**
103 * Called by the IMV when an IMV-IMC message is to be sent over IF-TNCCS 2.0
104 */
105 TNC_Result TNC_TNCS_SendMessageLong(TNC_IMVID imv_id,
106 TNC_ConnectionID connection_id,
107 TNC_UInt32 msg_flags,
108 TNC_BufferReference msg,
109 TNC_UInt32 msg_len,
110 TNC_VendorID msg_vid,
111 TNC_MessageSubtype msg_subtype,
112 TNC_UInt32 imc_id)
113 {
114 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
115 {
116 DBG1(DBG_TNC, "ignoring SendMessageLong() from unregistered IMV %u",
117 imv_id);
118 return TNC_RESULT_INVALID_PARAMETER;
119 }
120 return tnc->tnccs->send_message(tnc->tnccs, imc_id, imv_id, connection_id,
121 msg_flags, msg, msg_len, msg_vid, msg_subtype);
122 }
123
124 /**
125 * Called by the IMV to deliver its IMV Action Recommendation and IMV Evaluation
126 * Result to the TNCS
127 */
128 TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
129 TNC_ConnectionID connection_id,
130 TNC_IMV_Action_Recommendation recommendation,
131 TNC_IMV_Evaluation_Result evaluation)
132 {
133 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
134 {
135 DBG1(DBG_TNC, "ignoring ProvideRecommendation() from unregistered IMV %u",
136 imv_id);
137 return TNC_RESULT_INVALID_PARAMETER;
138 }
139 return tnc->tnccs->provide_recommendation(tnc->tnccs, imv_id, connection_id,
140 recommendation, evaluation);
141 }
142
143 /**
144 * Called by the IMV to get the value of an attribute associated with a
145 * connection or with the TNCS as a whole.
146 */
147 TNC_Result TNC_TNCS_GetAttribute(TNC_IMVID imv_id,
148 TNC_ConnectionID connection_id,
149 TNC_AttributeID attribute_id,
150 TNC_UInt32 buffer_len,
151 TNC_BufferReference buffer,
152 TNC_UInt32 *out_value_len)
153 {
154 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
155 {
156 DBG1(DBG_TNC, "ignoring GetAttribute() from unregistered IMV %u",
157 imv_id);
158 return TNC_RESULT_INVALID_PARAMETER;
159 }
160 return tnc->tnccs->get_attribute(tnc->tnccs, FALSE, imv_id, connection_id,
161 attribute_id, buffer_len, buffer, out_value_len);
162 }
163
164 /**
165 * Called by the IMV to set the value of an attribute associated with a
166 * connection or with the TNCS as a whole.
167 */
168 TNC_Result TNC_TNCS_SetAttribute(TNC_IMVID imv_id,
169 TNC_ConnectionID connection_id,
170 TNC_AttributeID attribute_id,
171 TNC_UInt32 buffer_len,
172 TNC_BufferReference buffer)
173 {
174 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
175 {
176 DBG1(DBG_TNC, "ignoring SetAttribute() from unregistered IMV %u",
177 imv_id);
178 return TNC_RESULT_INVALID_PARAMETER;
179 }
180 return tnc->tnccs->set_attribute(tnc->tnccs, FALSE, imv_id, connection_id,
181 attribute_id, buffer_len, buffer);
182 }
183
184 /**
185 * Called by the IMV when it wants to reserve an additional IMV ID for itself
186 */
187 TNC_Result TNC_TNCS_ReserveAdditionalIMVID(TNC_IMVID imv_id, TNC_UInt32 *new_id)
188 {
189 if (tnc->imvs->reserve_id(tnc->imvs, imv_id, new_id))
190 {
191 return TNC_RESULT_SUCCESS;
192 }
193 DBG1(DBG_TNC, "ignoring ReserveAdditionalIMVID() from unregistered IMV %u",
194 imv_id);
195 return TNC_RESULT_INVALID_PARAMETER;
196 }
197
198 /**
199 * Called by the IMV when it needs a function pointer
200 */
201 TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
202 char *function_name,
203 void **function_pointer)
204 {
205 if (streq(function_name, "TNC_TNCS_ReportMessageTypes"))
206 {
207 *function_pointer = (void*)TNC_TNCS_ReportMessageTypes;
208 }
209 else if (streq(function_name, "TNC_TNCS_ReportMessageTypesLong"))
210 {
211 *function_pointer = (void*)TNC_TNCS_ReportMessageTypesLong;
212 }
213 else if (streq(function_name, "TNC_TNCS_RequestHandshakeRetry"))
214 {
215 *function_pointer = (void*)TNC_TNCS_RequestHandshakeRetry;
216 }
217 else if (streq(function_name, "TNC_TNCS_SendMessage"))
218 {
219 *function_pointer = (void*)TNC_TNCS_SendMessage;
220 }
221 else if (streq(function_name, "TNC_TNCS_SendMessageLong"))
222 {
223 *function_pointer = (void*)TNC_TNCS_SendMessageLong;
224 }
225 else if (streq(function_name, "TNC_TNCS_ProvideRecommendation"))
226 {
227 *function_pointer = (void*)TNC_TNCS_ProvideRecommendation;
228 }
229 else if (streq(function_name, "TNC_TNCS_GetAttribute"))
230 {
231 *function_pointer = (void*)TNC_TNCS_GetAttribute;
232 }
233 else if (streq(function_name, "TNC_TNCS_SetAttribute"))
234 {
235 *function_pointer = (void*)TNC_TNCS_SetAttribute;
236 }
237 else if (streq(function_name, "TNC_TNCS_ReserveAdditionalIMVID"))
238 {
239 *function_pointer = (void*)TNC_TNCS_ReserveAdditionalIMVID;
240 }
241 else
242 {
243 return TNC_RESULT_INVALID_PARAMETER;
244 }
245 return TNC_RESULT_SUCCESS;
246 }