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