Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / tests / hwsim / tnc / hostap_imc.c
1 /*
2  * Minimal example IMC for TNC testing
3  * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8
9 #include "includes.h"
10
11 #include "common.h"
12 #include "common/tnc.h"
13
14 static int initialized = 0;
15 static TNC_IMCID my_id = -1;
16
17 TNC_Result TNC_IMC_Initialize(
18         /*in*/ TNC_IMCID imcID,
19         /*in*/ TNC_Version minVersion,
20         /*in*/ TNC_Version maxVersion,
21         /*out*/ TNC_Version *pOutActualVersion)
22 {
23         wpa_printf(MSG_INFO, "IMC(hostap) %s", __func__);
24
25         if (initialized)
26                 return TNC_RESULT_ALREADY_INITIALIZED;
27
28         if (minVersion < TNC_IFIMC_VERSION_1 ||
29             maxVersion > TNC_IFIMC_VERSION_1)
30                 return TNC_RESULT_NO_COMMON_VERSION;
31
32         if (!pOutActualVersion)
33                 return TNC_RESULT_INVALID_PARAMETER;
34         *pOutActualVersion = TNC_IFIMC_VERSION_1;
35         my_id = imcID;
36
37         initialized = 1;
38
39         return TNC_RESULT_SUCCESS;
40 }
41
42
43 TNC_Result TNC_IMC_BeginHandshake(
44         /*in*/ TNC_IMCID imcID,
45         /*in*/ TNC_ConnectionID connectionID)
46 {
47         wpa_printf(MSG_INFO, "IMC(hostap) %s", __func__);
48
49         if (!initialized)
50                 return TNC_RESULT_NOT_INITIALIZED;
51
52         if (imcID != my_id)
53                 return TNC_RESULT_INVALID_PARAMETER;
54
55         return TNC_RESULT_SUCCESS;
56 }
57
58
59 TNC_Result TNC_IMC_ProvideBindFunction(
60         /*in*/ TNC_IMCID imcID,
61         /*in*/ TNC_TNCC_BindFunctionPointer bindFunction)
62 {
63         wpa_printf(MSG_INFO, "IMC(hostap) %s", __func__);
64
65         if (!initialized)
66                 return TNC_RESULT_NOT_INITIALIZED;
67
68         if (imcID != my_id)
69                 return TNC_RESULT_INVALID_PARAMETER;
70
71         return TNC_RESULT_SUCCESS;
72 }