2 * Copyright (C) 2006 Mike McCauley
3 * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "tnc_imc_manager.h"
18 #include <tnc/imc/imc_manager.h>
19 #include <tnc/tncifimc.h>
23 #include <utils/linked_list.h>
25 typedef struct private_tnc_imc_manager_t private_tnc_imc_manager_t
;
27 struct private_tnc_imc_manager_t
{
30 * Public members of imc_manager_t.
40 * Next IMC ID to be assigned
42 TNC_IMCID next_imc_id
;
45 METHOD(imc_manager_t
, add
, bool,
46 private_tnc_imc_manager_t
*this, imc_t
*imc
)
50 /* Initialize the module */
51 imc
->set_id(imc
, this->next_imc_id
);
52 if (imc
->initialize(imc
->get_id(imc
), TNC_IFIMC_VERSION_1
,
53 TNC_IFIMC_VERSION_1
, &version
) != TNC_RESULT_SUCCESS
)
55 DBG1(DBG_TNC
, "could not initialize IMC '%s'",
59 if (imc
->provide_bind_function(imc
->get_id(imc
), TNC_TNCC_BindFunction
)
60 != TNC_RESULT_SUCCESS
)
62 DBG1(DBG_TNC
, "could not provide bind function for IMC '%s'",
66 this->imcs
->insert_last(this->imcs
, imc
);
72 METHOD(imc_manager_t
, notify_connection_change
, void,
73 private_tnc_imc_manager_t
*this, TNC_ConnectionID id
,
74 TNC_ConnectionState state
)
76 enumerator_t
*enumerator
;
79 enumerator
= this->imcs
->create_enumerator(this->imcs
);
80 while (enumerator
->enumerate(enumerator
, &imc
))
82 if (imc
->notify_connection_change
)
84 imc
->notify_connection_change(imc
->get_id(imc
), id
, state
);
87 enumerator
->destroy(enumerator
);
90 METHOD(imc_manager_t
, begin_handshake
, void,
91 private_tnc_imc_manager_t
*this, TNC_ConnectionID id
)
93 enumerator_t
*enumerator
;
96 enumerator
= this->imcs
->create_enumerator(this->imcs
);
97 while (enumerator
->enumerate(enumerator
, &imc
))
99 imc
->begin_handshake(imc
->get_id(imc
), id
);
101 enumerator
->destroy(enumerator
);
104 METHOD(imc_manager_t
, set_message_types
, TNC_Result
,
105 private_tnc_imc_manager_t
*this, TNC_IMCID id
,
106 TNC_MessageTypeList supported_types
,
107 TNC_UInt32 type_count
)
109 enumerator_t
*enumerator
;
111 TNC_Result result
= TNC_RESULT_FATAL
;
113 enumerator
= this->imcs
->create_enumerator(this->imcs
);
114 while (enumerator
->enumerate(enumerator
, &imc
))
116 if (id
== imc
->get_id(imc
))
118 imc
->set_message_types(imc
, supported_types
, type_count
);
119 result
= TNC_RESULT_SUCCESS
;
123 enumerator
->destroy(enumerator
);
128 METHOD(imc_manager_t
, destroy
, void,
129 private_tnc_imc_manager_t
*this)
133 while (this->imcs
->remove_last(this->imcs
, (void**)&imc
) == SUCCESS
)
135 if (imc
->terminate
&&
136 imc
->terminate(imc
->get_id(imc
)) != TNC_RESULT_SUCCESS
)
138 DBG1(DBG_TNC
, "IMC '%s' not terminated successfully",
143 this->imcs
->destroy(this->imcs
);
148 * Described in header.
150 imc_manager_t
* tnc_imc_manager_create(void)
152 private_tnc_imc_manager_t
*this;
157 .notify_connection_change
= _notify_connection_change
,
158 .begin_handshake
= _begin_handshake
,
159 .set_message_types
= _set_message_types
,
162 .imcs
= linked_list_create(),
167 return &this->public;