]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libtnccs/plugins/tnc_imc/tnc_imc_bind_function.c
Moved tnc-tnccs, tnc-imc, tnccs-11, tnccs-20 and tnccs-dynamic libcharon plugins...
[thirdparty/strongswan.git] / src / libtnccs / plugins / tnc_imc / tnc_imc_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/imc/imc_manager.h>
18 #include <tnc/tnccs/tnccs_manager.h>
19
20 #include <utils/debug.h>
21
22 /**
23 * Called by the IMC to inform a TNCC about the set of message types the IMC
24 * is able to receive
25 */
26 TNC_Result TNC_TNCC_ReportMessageTypes(TNC_IMCID imc_id,
27 TNC_MessageTypeList supported_types,
28 TNC_UInt32 type_count)
29 {
30 if (!tnc->imcs->is_registered(tnc->imcs, imc_id))
31 {
32 DBG1(DBG_TNC, "ignoring ReportMessageTypes() from unregistered IMC %u",
33 imc_id);
34 return TNC_RESULT_INVALID_PARAMETER;
35 }
36 return tnc->imcs->set_message_types(tnc->imcs, imc_id, supported_types,
37 type_count);
38 }
39
40 /**
41 * Called by the IMC to inform a TNCC about the set of message types the IMC
42 * is able to receive. This function supports long message types.
43 */
44 TNC_Result TNC_TNCC_ReportMessageTypesLong(TNC_IMCID imc_id,
45 TNC_VendorIDList supported_vids,
46 TNC_MessageSubtypeList supported_subtypes,
47 TNC_UInt32 type_count)
48 {
49 if (!tnc->imcs->is_registered(tnc->imcs, imc_id))
50 {
51 DBG1(DBG_TNC, "ignoring ReportMessageTypesLong() from unregistered IMC %u",
52 imc_id);
53 return TNC_RESULT_INVALID_PARAMETER;
54 }
55 return tnc->imcs->set_message_types_long(tnc->imcs, imc_id, supported_vids,
56 supported_subtypes, type_count);
57 }
58
59 /**
60 * Called by the IMC to ask a TNCC to retry an Integrity Check Handshake
61 */
62 TNC_Result TNC_TNCC_RequestHandshakeRetry(TNC_IMCID imc_id,
63 TNC_ConnectionID connection_id,
64 TNC_RetryReason reason)
65 {
66 if (!tnc->imcs->is_registered(tnc->imcs, imc_id))
67 {
68 DBG1(DBG_TNC, "ignoring RequestHandshakeRetry() from unregistered IMC %u",
69 imc_id);
70 return TNC_RESULT_INVALID_PARAMETER;
71 }
72 return tnc->tnccs->request_handshake_retry(tnc->tnccs, TRUE, imc_id,
73 connection_id, reason);
74 }
75
76 /**
77 * Called by the IMC when an IMC-IMV message is to be sent
78 */
79 TNC_Result TNC_TNCC_SendMessage(TNC_IMCID imc_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->imcs->is_registered(tnc->imcs, imc_id))
89 {
90 DBG1(DBG_TNC, "ignoring SendMessage() from unregistered IMC %u",
91 imc_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, imc_id, TNC_IMVID_ANY,
98 connection_id, 0, msg, msg_len, msg_vid, msg_subtype);
99 }
100
101 /**
102 * Called by the IMC when an IMC-IMV message is to be sent over IF-TNCCS 2.0
103 */
104 TNC_Result TNC_TNCC_SendMessageLong(TNC_IMCID imc_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 imv_id)
112 {
113 if (!tnc->imcs->is_registered(tnc->imcs, imc_id))
114 {
115 DBG1(DBG_TNC, "ignoring SendMessage() from unregistered IMC %u",
116 imc_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 IMC to get the value of an attribute associated with a
125 * connection or with the TNCC as a whole.
126 */
127 TNC_Result TNC_TNCC_GetAttribute(TNC_IMCID imc_id,
128 TNC_ConnectionID connection_id,
129 TNC_AttributeID attribute_id,
130 TNC_UInt32 buffer_len,
131 TNC_BufferReference buffer,
132 TNC_UInt32 *out_value_len)
133 {
134 if (!tnc->imcs->is_registered(tnc->imcs, imc_id))
135 {
136 DBG1(DBG_TNC, "ignoring GetAttribute() from unregistered IMC %u",
137 imc_id);
138 return TNC_RESULT_INVALID_PARAMETER;
139 }
140 return tnc->tnccs->get_attribute(tnc->tnccs, TRUE, imc_id, connection_id,
141 attribute_id, buffer_len, buffer, out_value_len);
142 }
143
144 /**
145 * Called by the IMC to set the value of an attribute associated with a
146 * connection or with the TNCC as a whole.
147 */
148 TNC_Result TNC_TNCC_SetAttribute(TNC_IMCID imc_id,
149 TNC_ConnectionID connection_id,
150 TNC_AttributeID attribute_id,
151 TNC_UInt32 buffer_len,
152 TNC_BufferReference buffer)
153 {
154 if (!tnc->imcs->is_registered(tnc->imcs, imc_id))
155 {
156 DBG1(DBG_TNC, "ignoring SetAttribute() from unregistered IMC %u",
157 imc_id);
158 return TNC_RESULT_INVALID_PARAMETER;
159 }
160 return tnc->tnccs->set_attribute(tnc->tnccs, TRUE, imc_id, connection_id,
161 attribute_id, buffer_len, buffer);
162 }
163
164 /**
165 * Called by the IMC when it wants to reserve an additional IMC ID for itself
166 */
167 TNC_Result TNC_TNCC_ReserveAdditionalIMCID(TNC_IMCID imc_id, TNC_UInt32 *new_id)
168 {
169 if (tnc->imcs->reserve_id(tnc->imcs, imc_id, new_id))
170 {
171 return TNC_RESULT_SUCCESS;
172 }
173 DBG1(DBG_TNC, "ignoring ReserveAdditionalIMCID() from unregistered IMC %u",
174 imc_id);
175 return TNC_RESULT_INVALID_PARAMETER;
176 }
177
178 /**
179 * Called by the IMC when it needs a function pointer
180 */
181 TNC_Result TNC_TNCC_BindFunction(TNC_IMCID id,
182 char *function_name,
183 void **function_pointer)
184 {
185 if (streq(function_name, "TNC_TNCC_ReportMessageTypes"))
186 {
187 *function_pointer = (void*)TNC_TNCC_ReportMessageTypes;
188 }
189 else if (streq(function_name, "TNC_TNCC_ReportMessageTypesLong"))
190 {
191 *function_pointer = (void*)TNC_TNCC_ReportMessageTypesLong;
192 }
193 else if (streq(function_name, "TNC_TNCC_RequestHandshakeRetry"))
194 {
195 *function_pointer = (void*)TNC_TNCC_RequestHandshakeRetry;
196 }
197 else if (streq(function_name, "TNC_TNCC_SendMessage"))
198 {
199 *function_pointer = (void*)TNC_TNCC_SendMessage;
200 }
201 else if (streq(function_name, "TNC_TNCC_SendMessageLong"))
202 {
203 *function_pointer = (void*)TNC_TNCC_SendMessageLong;
204 }
205 else if (streq(function_name, "TNC_TNCC_GetAttribute"))
206 {
207 *function_pointer = (void*)TNC_TNCC_GetAttribute;
208 }
209 else if (streq(function_name, "TNC_TNCC_SetAttribute"))
210 {
211 *function_pointer = (void*)TNC_TNCC_SetAttribute;
212 }
213 else if (streq(function_name, "TNC_TNCC_ReserveAdditionalIMCID"))
214 {
215 *function_pointer = (void*)TNC_TNCC_ReserveAdditionalIMCID;
216 }
217 else
218 {
219 return TNC_RESULT_INVALID_PARAMETER;
220 }
221 return TNC_RESULT_SUCCESS;
222 }