return with TNC_RESULT_SUCCESS
[strongswan.git] / src / libcharon / plugins / tnc_imv / tnc_imv_bind_function.c
1 /*
2 * Copyright (C) 2006 Mike McCauley
3 * Copyright (C) 2010 Andreas Steffen, 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 <tnc/tnc.h>
17 #include <tnc/imv/imv_manager.h>
18 #include <tnc/tnccs/tnccs_manager.h>
19
20 #include <debug.h>
21
22 /**
23 * Called by the IMV to inform a TNCS about the set of message types the IMV
24 * is able to receive
25 */
26 TNC_Result TNC_TNCS_ReportMessageTypes(TNC_IMVID imv_id,
27 TNC_MessageTypeList supported_types,
28 TNC_UInt32 type_count)
29 {
30 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
31 {
32 DBG1(DBG_TNC, "ignoring ReportMessageTypes() from unregistered IMV %u",
33 imv_id);
34 return TNC_RESULT_INVALID_PARAMETER;
35 }
36 return tnc->imvs->set_message_types(tnc->imvs, imv_id, supported_types,
37 type_count);
38 }
39
40 /**
41 * Called by the IMV to inform a TNCS about the set of message types the IMV
42 * is able to receive. This function supports long message types.
43 */
44 TNC_Result TNC_TNCS_ReportMessageTypesLong(TNC_IMVID imv_id,
45 TNC_VendorIDList supported_vids,
46 TNC_MessageSubtypeList supported_subtypes,
47 TNC_UInt32 type_count)
48 {
49 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
50 {
51 DBG1(DBG_TNC, "ignoring ReportMessageTypesLong() from unregistered IMV %u",
52 imv_id);
53 return TNC_RESULT_INVALID_PARAMETER;
54 }
55 return tnc->imvs->set_message_types_long(tnc->imvs, imv_id, supported_vids,
56 supported_subtypes, type_count);
57 }
58
59 /**
60 * Called by the IMV to ask a TNCS to retry an Integrity Check Handshake
61 */
62 TNC_Result TNC_TNCS_RequestHandshakeRetry(TNC_IMVID imv_id,
63 TNC_ConnectionID connection_id,
64 TNC_RetryReason reason)
65 {
66 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
67 {
68 DBG1(DBG_TNC, "ignoring RequestHandshakeRetry() from unregistered IMV %u",
69 imv_id);
70 return TNC_RESULT_INVALID_PARAMETER;
71 }
72 return tnc->tnccs->request_handshake_retry(tnc->tnccs, FALSE, imv_id,
73 connection_id, reason);
74 }
75
76 /**
77 * Called by the IMV when an IMV-IMC message is to be sent
78 */
79 TNC_Result TNC_TNCS_SendMessage(TNC_IMVID imv_id,
80 TNC_ConnectionID connection_id,
81 TNC_BufferReference msg,
82 TNC_UInt32 msg_len,
83 TNC_MessageType msg_type)
84 {
85 TNC_VendorID msg_vid;
86 TNC_MessageSubtype msg_subtype;
87
88 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
89 {
90 DBG1(DBG_TNC, "ignoring SendMessage() from unregistered IMV %u",
91 imv_id);
92 return TNC_RESULT_INVALID_PARAMETER;
93 }
94 msg_vid = (msg_type >> 8) & TNC_VENDORID_ANY;
95 msg_subtype = msg_type & TNC_SUBTYPE_ANY;
96
97 return tnc->tnccs->send_message(tnc->tnccs, TNC_IMCID_ANY, imv_id,
98 connection_id, 0, msg, msg_len, msg_vid, msg_subtype);
99 }
100
101 /**
102 * Called by the IMV when an IMV-IMC message is to be sent over IF-TNCCS 2.0
103 */
104 TNC_Result TNC_TNCS_SendMessageLong(TNC_IMVID imv_id,
105 TNC_ConnectionID connection_id,
106 TNC_UInt32 msg_flags,
107 TNC_BufferReference msg,
108 TNC_UInt32 msg_len,
109 TNC_VendorID msg_vid,
110 TNC_MessageSubtype msg_subtype,
111 TNC_UInt32 imc_id)
112 {
113 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
114 {
115 DBG1(DBG_TNC, "ignoring SendMessageLong() from unregistered IMV %u",
116 imv_id);
117 return TNC_RESULT_INVALID_PARAMETER;
118 }
119 return tnc->tnccs->send_message(tnc->tnccs, imc_id, imv_id, connection_id,
120 msg_flags, msg, msg_len, msg_vid, msg_subtype);
121 }
122
123 /**
124 * Called by the IMV to deliver its IMV Action Recommendation and IMV Evaluation
125 * Result to the TNCS
126 */
127 TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
128 TNC_ConnectionID connection_id,
129 TNC_IMV_Action_Recommendation recommendation,
130 TNC_IMV_Evaluation_Result evaluation)
131 {
132 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
133 {
134 DBG1(DBG_TNC, "ignoring ProvideRecommendation() from unregistered IMV %u",
135 imv_id);
136 return TNC_RESULT_INVALID_PARAMETER;
137 }
138 return tnc->tnccs->provide_recommendation(tnc->tnccs, imv_id, connection_id,
139 recommendation, evaluation);
140 }
141
142 /**
143 * Called by the IMV to get the value of an attribute associated with a
144 * connection or with the TNCS as a whole.
145 */
146 TNC_Result TNC_TNCS_GetAttribute(TNC_IMVID imv_id,
147 TNC_ConnectionID connection_id,
148 TNC_AttributeID attribute_id,
149 TNC_UInt32 buffer_len,
150 TNC_BufferReference buffer,
151 TNC_UInt32 *out_value_len)
152 {
153 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
154 {
155 DBG1(DBG_TNC, "ignoring GetAttribute() from unregistered IMV %u",
156 imv_id);
157 return TNC_RESULT_INVALID_PARAMETER;
158 }
159 return tnc->tnccs->get_attribute(tnc->tnccs, imv_id, connection_id,
160 attribute_id, buffer_len, buffer, out_value_len);
161 }
162
163 /**
164 * Called by the IMV to set the value of an attribute associated with a
165 * connection or with the TNCS as a whole.
166 */
167 TNC_Result TNC_TNCS_SetAttribute(TNC_IMVID imv_id,
168 TNC_ConnectionID connection_id,
169 TNC_AttributeID attribute_id,
170 TNC_UInt32 buffer_len,
171 TNC_BufferReference buffer)
172 {
173 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
174 {
175 DBG1(DBG_TNC, "ignoring SetAttribute() from unregistered IMV %u",
176 imv_id);
177 return TNC_RESULT_INVALID_PARAMETER;
178 }
179 return tnc->tnccs->set_attribute(tnc->tnccs, imv_id, connection_id,
180 attribute_id, buffer_len, buffer);
181 }
182
183 /**
184 * Called by the IMV when it needs a function pointer
185 */
186 TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
187 char *function_name,
188 void **function_pointer)
189 {
190 if (streq(function_name, "TNC_TNCS_ReportMessageTypes"))
191 {
192 *function_pointer = (void*)TNC_TNCS_ReportMessageTypes;
193 }
194 else if (streq(function_name, "TNC_TNCS_ReportMessageTypesLong"))
195 {
196 *function_pointer = (void*)TNC_TNCS_ReportMessageTypesLong;
197 }
198 else if (streq(function_name, "TNC_TNCS_RequestHandshakeRetry"))
199 {
200 *function_pointer = (void*)TNC_TNCS_RequestHandshakeRetry;
201 }
202 else if (streq(function_name, "TNC_TNCS_SendMessage"))
203 {
204 *function_pointer = (void*)TNC_TNCS_SendMessage;
205 }
206 else if (streq(function_name, "TNC_TNCS_SendMessageLong"))
207 {
208 *function_pointer = (void*)TNC_TNCS_SendMessageLong;
209 }
210 else if (streq(function_name, "TNC_TNCS_ProvideRecommendation"))
211 {
212 *function_pointer = (void*)TNC_TNCS_ProvideRecommendation;
213 }
214 else if (streq(function_name, "TNC_TNCS_GetAttribute"))
215 {
216 *function_pointer = (void*)TNC_TNCS_GetAttribute;
217 }
218 else if (streq(function_name, "TNC_TNCS_SetAttribute"))
219 {
220 *function_pointer = (void*)TNC_TNCS_SetAttribute;
221 }
222 else
223 {
224 return TNC_RESULT_INVALID_PARAMETER;
225 }
226 return TNC_RESULT_SUCCESS;
227 }