8bb435aa08bf210537c44c76df1ff5fe112d027b
[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 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
86 {
87 DBG1(DBG_TNC, "ignoring SendMessage() from unregistered IMV %u",
88 imv_id);
89 return TNC_RESULT_INVALID_PARAMETER;
90 }
91 return tnc->tnccs->send_message(tnc->tnccs, TNC_IMCID_ANY, imv_id,
92 connection_id, msg, msg_len, msg_type);
93 }
94
95 /**
96 * Called by the IMV to deliver its IMV Action Recommendation and IMV Evaluation
97 * Result to the TNCS
98 */
99 TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
100 TNC_ConnectionID connection_id,
101 TNC_IMV_Action_Recommendation recommendation,
102 TNC_IMV_Evaluation_Result evaluation)
103 {
104 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
105 {
106 DBG1(DBG_TNC, "ignoring ProvideRecommendation() from unregistered IMV %u",
107 imv_id);
108 return TNC_RESULT_INVALID_PARAMETER;
109 }
110 return tnc->tnccs->provide_recommendation(tnc->tnccs, imv_id, connection_id,
111 recommendation, evaluation);
112 }
113
114 /**
115 * Called by the IMV to get the value of an attribute associated with a
116 * connection or with the TNCS as a whole.
117 */
118 TNC_Result TNC_TNCS_GetAttribute(TNC_IMVID imv_id,
119 TNC_ConnectionID connection_id,
120 TNC_AttributeID attribute_id,
121 TNC_UInt32 buffer_len,
122 TNC_BufferReference buffer,
123 TNC_UInt32 *out_value_len)
124 {
125 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
126 {
127 DBG1(DBG_TNC, "ignoring GetAttribute() from unregistered IMV %u",
128 imv_id);
129 return TNC_RESULT_INVALID_PARAMETER;
130 }
131 return tnc->tnccs->get_attribute(tnc->tnccs, imv_id, connection_id,
132 attribute_id, buffer_len, buffer, out_value_len);
133 }
134
135 /**
136 * Called by the IMV to set the value of an attribute associated with a
137 * connection or with the TNCS as a whole.
138 */
139 TNC_Result TNC_TNCS_SetAttribute(TNC_IMVID imv_id,
140 TNC_ConnectionID connection_id,
141 TNC_AttributeID attribute_id,
142 TNC_UInt32 buffer_len,
143 TNC_BufferReference buffer)
144 {
145 if (!tnc->imvs->is_registered(tnc->imvs, imv_id))
146 {
147 DBG1(DBG_TNC, "ignoring SetAttribute() from unregistered IMV %u",
148 imv_id);
149 return TNC_RESULT_INVALID_PARAMETER;
150 }
151 return tnc->tnccs->set_attribute(tnc->tnccs, imv_id, connection_id,
152 attribute_id, buffer_len, buffer);
153 }
154
155 /**
156 * Called by the IMV when it needs a function pointer
157 */
158 TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
159 char *function_name,
160 void **function_pointer)
161 {
162 if (streq(function_name, "TNC_TNCS_ReportMessageTypes"))
163 {
164 *function_pointer = (void*)TNC_TNCS_ReportMessageTypes;
165 }
166 else if (streq(function_name, "TNC_TNCS_ReportMessageTypesLong"))
167 {
168 *function_pointer = (void*)TNC_TNCS_ReportMessageTypesLong;
169 }
170 else if (streq(function_name, "TNC_TNCS_RequestHandshakeRetry"))
171 {
172 *function_pointer = (void*)TNC_TNCS_RequestHandshakeRetry;
173 }
174 else if (streq(function_name, "TNC_TNCS_SendMessage"))
175 {
176 *function_pointer = (void*)TNC_TNCS_SendMessage;
177 }
178 else if (streq(function_name, "TNC_TNCS_ProvideRecommendation"))
179 {
180 *function_pointer = (void*)TNC_TNCS_ProvideRecommendation;
181 }
182 else if (streq(function_name, "TNC_TNCS_GetAttribute"))
183 {
184 *function_pointer = (void*)TNC_TNCS_GetAttribute;
185 }
186 else if (streq(function_name, "TNC_TNCS_SetAttribute"))
187 {
188 *function_pointer = (void*)TNC_TNCS_SetAttribute;
189 }
190 else
191 {
192 return TNC_RESULT_INVALID_PARAMETER;
193 }
194 return TNC_RESULT_SUCCESS;
195 }