25a6a1cc4bc63a6112462e551e148ac7f36f62e7
[strongswan.git] / src / libcharon / 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_imc.h"
17
18 #include <debug.h>
19 #include <daemon.h>
20
21 #define TNC_IMVID_ANY 0xffff
22
23 /**
24 * Called by the IMC to inform a TNCC about the set of message types the IMC
25 * is able to receive
26 */
27 TNC_Result TNC_TNCC_ReportMessageTypes(TNC_IMCID imc_id,
28 TNC_MessageTypeList supported_types,
29 TNC_UInt32 type_count)
30 {
31 if (!charon->imcs->is_registered(charon->imcs, imc_id))
32 {
33 DBG1(DBG_TNC, "ignoring ReportMessageTypes() from unregistered IMC %u",
34 imc_id);
35 return TNC_RESULT_INVALID_PARAMETER;
36 }
37 return charon->imcs->set_message_types(charon->imcs, imc_id,
38 supported_types, type_count);
39 }
40
41 /**
42 * Called by the IMC to ask a TNCC to retry an Integrity Check Handshake
43 */
44 TNC_Result TNC_TNCC_RequestHandshakeRetry(TNC_IMCID imc_id,
45 TNC_ConnectionID connection_id,
46 TNC_RetryReason reason)
47 {
48 if (!charon->imcs->is_registered(charon->imcs, imc_id))
49 {
50 DBG1(DBG_TNC, "ignoring RequestHandshakeRetry() from unregistered IMC %u",
51 imc_id);
52 return TNC_RESULT_INVALID_PARAMETER;
53 }
54 return charon->tnccs->request_handshake_retry(charon->tnccs, TRUE, imc_id,
55 connection_id, reason);
56 }
57
58 /**
59 * Called by the IMC when an IMC-IMV message is to be sent
60 */
61 TNC_Result TNC_TNCC_SendMessage(TNC_IMCID imc_id,
62 TNC_ConnectionID connection_id,
63 TNC_BufferReference msg,
64 TNC_UInt32 msg_len,
65 TNC_MessageType msg_type)
66 {
67 if (!charon->imcs->is_registered(charon->imcs, imc_id))
68 {
69 DBG1(DBG_TNC, "ignoring SendMessage() from unregistered IMC %u",
70 imc_id);
71 return TNC_RESULT_INVALID_PARAMETER;
72 }
73 return charon->tnccs->send_message(charon->tnccs, imc_id, TNC_IMVID_ANY,
74 connection_id, msg, msg_len, msg_type);
75 }
76
77 /**
78 * Called by the IMC when it needs a function pointer
79 */
80 TNC_Result TNC_TNCC_BindFunction(TNC_IMCID id,
81 char *function_name,
82 void **function_pointer)
83 {
84 if (streq(function_name, "TNC_TNCC_ReportMessageTypes"))
85 {
86 *function_pointer = (void*)TNC_TNCC_ReportMessageTypes;
87 }
88 else if (streq(function_name, "TNC_TNCC_RequestHandshakeRetry"))
89 {
90 *function_pointer = (void*)TNC_TNCC_RequestHandshakeRetry;
91 }
92 else if (streq(function_name, "TNC_TNCC_SendMessage"))
93 {
94 *function_pointer = (void*)TNC_TNCC_SendMessage;
95 }
96 else
97 {
98 return TNC_RESULT_INVALID_PARAMETER;
99 }
100 return TNC_RESULT_SUCCESS;
101 }