2 * Example IMC for TNC testing
3 * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "common/tnc.h"
14 static int initialized = 0;
15 static TNC_IMCID my_id = -1;
16 static TNC_TNCC_SendMessagePointer send_message = NULL;
17 static TNC_TNCC_ReportMessageTypesPointer report_message_types = NULL;
18 static TNC_TNCC_RequestHandshakeRetryPointer request_retry = NULL;
20 static TNC_MessageType message_types[] =
22 (TNC_VENDORID_ANY << 8) | TNC_SUBTYPE_ANY
26 TNC_Result TNC_IMC_Initialize(
27 /*in*/ TNC_IMCID imcID,
28 /*in*/ TNC_Version minVersion,
29 /*in*/ TNC_Version maxVersion,
30 /*out*/ TNC_Version *pOutActualVersion)
33 "IMC(hostap2) %s(imcID=%u, minVersion=%u, maxVersion=%u)",
34 __func__, (unsigned) imcID, (unsigned) minVersion,
35 (unsigned) maxVersion);
38 return TNC_RESULT_ALREADY_INITIALIZED;
40 if (minVersion < TNC_IFIMC_VERSION_1 ||
41 maxVersion > TNC_IFIMC_VERSION_1)
42 return TNC_RESULT_NO_COMMON_VERSION;
44 if (!pOutActualVersion)
45 return TNC_RESULT_INVALID_PARAMETER;
46 *pOutActualVersion = TNC_IFIMC_VERSION_1;
51 return TNC_RESULT_SUCCESS;
55 TNC_Result TNC_IMC_BeginHandshake(
56 /*in*/ TNC_IMCID imcID,
57 /*in*/ TNC_ConnectionID connectionID)
62 wpa_printf(MSG_INFO, "IMC(hostap2) %s(imcID=%u, connectionID=%u)",
63 __func__, (unsigned) imcID, (unsigned) connectionID);
66 return TNC_RESULT_NOT_INITIALIZED;
69 return TNC_RESULT_INVALID_PARAMETER;
72 return TNC_RESULT_FATAL;
74 res = send_message(imcID, connectionID, msg, os_strlen(msg), 1);
75 if (res != TNC_RESULT_SUCCESS)
78 return TNC_RESULT_SUCCESS;
82 TNC_Result TNC_IMC_ProvideBindFunction(
83 /*in*/ TNC_IMCID imcID,
84 /*in*/ TNC_TNCC_BindFunctionPointer bindFunction)
88 wpa_printf(MSG_INFO, "IMC(hostap2) %s(imcID=%u)",
89 __func__, (unsigned) imcID);
92 return TNC_RESULT_NOT_INITIALIZED;
94 if (imcID != my_id || !bindFunction)
95 return TNC_RESULT_INVALID_PARAMETER;
97 if (bindFunction(imcID, "TNC_TNCC_SendMessage",
98 (void **) &send_message) != TNC_RESULT_SUCCESS ||
100 return TNC_RESULT_FATAL;
102 if (bindFunction(imcID, "TNC_TNCC_ReportMessageTypes",
103 (void **) &report_message_types) !=
104 TNC_RESULT_SUCCESS ||
105 !report_message_types)
106 return TNC_RESULT_FATAL;
108 if (bindFunction(imcID, "TNC_TNCC_RequestHandshakeRetry",
109 (void **) &request_retry) != TNC_RESULT_SUCCESS ||
111 return TNC_RESULT_FATAL;
113 res = report_message_types(imcID, message_types,
114 ARRAY_SIZE(message_types));
115 if (res != TNC_RESULT_SUCCESS)
118 return TNC_RESULT_SUCCESS;
122 TNC_Result TNC_IMC_NotifyConnectionChange(
123 /*in*/ TNC_IMCID imcID,
124 /*in*/ TNC_ConnectionID connectionID,
125 /*in*/ TNC_ConnectionState newState)
128 "IMC(hostap2) %s(imcID=%u, connectionID=%u, newState=%u)",
129 __func__, (unsigned) imcID, (unsigned) connectionID,
130 (unsigned) newState);
132 return TNC_RESULT_SUCCESS;
136 TNC_Result TNC_IMC_ReceiveMessage(
137 /*in*/ TNC_IMCID imcID,
138 /*in*/ TNC_ConnectionID connectionID,
139 /*in*/ TNC_BufferReference message,
140 /*in*/ TNC_UInt32 messageLength,
141 /*in*/ TNC_MessageType messageType)
146 "IMC(hostap2) %s(imcID=%u, connectionID=%u, messageType=%u)",
147 __func__, (unsigned) imcID, (unsigned) connectionID,
148 (unsigned) messageType);
149 wpa_hexdump_ascii(MSG_INFO, "IMC(hostap2) message",
150 message, messageLength);
152 if (messageType == 1 && messageLength == 5 &&
153 os_memcmp(message, "hello", 5) == 0) {
154 char *msg = "i'm fine";
156 res = send_message(imcID, connectionID, msg, os_strlen(msg), 1);
157 if (res != TNC_RESULT_SUCCESS)
161 return TNC_RESULT_SUCCESS;
165 TNC_Result TNC_IMC_BatchEnding(
166 /*in*/ TNC_IMCID imcID,
167 /*in*/ TNC_ConnectionID connectionID)
169 wpa_printf(MSG_INFO, "IMC(hostap2) %s(imcID=%u, connectionID=%u)",
170 __func__, (unsigned) imcID, (unsigned) connectionID);
172 return TNC_RESULT_SUCCESS;
176 TNC_Result TNC_IMC_Terminate(
177 /*in*/ TNC_IMCID imcID)
179 wpa_printf(MSG_INFO, "IMC(hostap2) %s(imcID=%u)",
180 __func__, (unsigned) imcID);
182 return TNC_RESULT_SUCCESS;