cc4f5b27b0a6a34db53f4a9ada78d6b5b117f7aa
[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_imv.h"
17
18 #include <debug.h>
19 #include <daemon.h>
20
21 /**
22 * Called by the IMV to inform a TNCS about the set of message types the IMV
23 * is able to receive
24 */
25 TNC_Result TNC_TNCS_ReportMessageTypes(TNC_IMVID imv_id,
26 TNC_MessageTypeList supported_types,
27 TNC_UInt32 type_count)
28 {
29 return charon->imvs->set_message_types(charon->imvs, imv_id,
30 supported_types, type_count);
31 }
32
33 /**
34 * Called by the IMV to ask a TNCS to retry an Integrity Check Handshake
35 */
36 TNC_Result TNC_TNCS_RequestHandshakeRetry(TNC_IMVID imv_id,
37 TNC_ConnectionID connection_id,
38 TNC_RetryReason reason)
39 {
40 DBG2(DBG_TNC,"TNCS_RequestHandshakeRetry not supported yet");
41 return TNC_RESULT_CANT_RESPOND;
42 }
43
44 /**
45 * Called by the IMV when an IMV-IMC message is to be sent
46 */
47 TNC_Result TNC_TNCS_SendMessage(TNC_IMVID imv_id,
48 TNC_ConnectionID connection_id,
49 TNC_BufferReference message,
50 TNC_UInt32 message_len,
51 TNC_MessageType message_type)
52 {
53 return charon->tnccs->send_message(charon->tnccs, connection_id, message,
54 message_len, message_type);
55 }
56
57 /**
58 * Called by the IMV to deliver its IMV Action Recommendation and IMV Evaluation
59 * Result to the TNCS
60 */
61 TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
62 TNC_ConnectionID connection_id,
63 TNC_IMV_Action_Recommendation recommendation,
64 TNC_IMV_Evaluation_Result evaluation)
65 {
66 return charon->tnccs->provide_recommendation(charon->tnccs, imv_id,
67 connection_id, recommendation, evaluation);
68 }
69
70 /**
71 * Called by the IMV to get the value of an attribute associated with a
72 * connection or with the TNCS as a whole.
73 */
74 TNC_Result TNC_TNCS_GetAttribute(TNC_IMVID imv_id,
75 TNC_ConnectionID connection_id,
76 TNC_AttributeID attribute_id,
77 TNC_UInt32 buffer_len,
78 TNC_BufferReference buffer,
79 TNC_UInt32 *out_value_len)
80 {
81 return charon->tnccs->get_attribute(charon->tnccs, imv_id, connection_id,
82 attribute_id, buffer_len, buffer, out_value_len);
83 }
84
85 /**
86 * Called by the IMV to set the value of an attribute associated with a
87 * connection or with the TNCS as a whole.
88 */
89 TNC_Result TNC_TNCS_SetAttribute(TNC_IMVID imv_id,
90 TNC_ConnectionID connection_id,
91 TNC_AttributeID attribute_id,
92 TNC_UInt32 buffer_len,
93 TNC_BufferReference buffer)
94 {
95 return charon->tnccs->set_attribute(charon->tnccs, imv_id, connection_id,
96 attribute_id, buffer_len, buffer);
97 }
98
99 /**
100 * Called by the IMV when it needs a function pointer
101 */
102 TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
103 char *function_name,
104 void **function_pointer)
105 {
106 if (streq(function_name, "TNC_TNCS_ReportMessageTypes"))
107 {
108 *function_pointer = (void*)TNC_TNCS_ReportMessageTypes;
109 }
110 else if (streq(function_name, "TNC_TNCS_RequestHandshakeRetry"))
111 {
112 *function_pointer = (void*)TNC_TNCS_RequestHandshakeRetry;
113 }
114 else if (streq(function_name, "TNC_TNCS_SendMessage"))
115 {
116 *function_pointer = (void*)TNC_TNCS_SendMessage;
117 }
118 else if (streq(function_name, "TNC_TNCS_ProvideRecommendation"))
119 {
120 *function_pointer = (void*)TNC_TNCS_ProvideRecommendation;
121 }
122 else if (streq(function_name, "TNC_TNCS_GetAttribute"))
123 {
124 *function_pointer = (void*)TNC_TNCS_GetAttribute;
125 }
126 else if (streq(function_name, "TNC_TNCS_SetAttribute"))
127 {
128 *function_pointer = (void*)TNC_TNCS_SetAttribute;
129 }
130 else
131 {
132 return TNC_RESULT_INVALID_PARAMETER;
133 }
134 return TNC_RESULT_SUCCESS;
135 }