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
22 #include <threading/mutex.h>
24 typedef struct private_tnc_imv_t private_tnc_imv_t
;
27 * Private data of an imv_t object.
29 struct private_tnc_imv_t
{
32 * Public members of imv_t.
47 * Handle of loaded IMV
57 * List of message types supported by IMC
59 TNC_MessageTypeList supported_types
;
62 * Number of supported message types
64 TNC_UInt32 type_count
;
67 * mutex to lock the imv_t object
72 METHOD(imv_t
, set_id
, void,
73 private_tnc_imv_t
*this, TNC_IMVID id
)
78 METHOD(imv_t
, get_id
, TNC_IMVID
,
79 private_tnc_imv_t
*this)
84 METHOD(imv_t
, get_name
, char*,
85 private_tnc_imv_t
*this)
90 METHOD(imv_t
, set_message_types
, void,
91 private_tnc_imv_t
*this, TNC_MessageTypeList supported_types
,
92 TNC_UInt32 type_count
)
96 int len
= sizeof(buf
);
99 /* lock the imv_t instance */
100 this->mutex
->lock(this->mutex
);
102 /* Free an existing MessageType list */
103 free(this->supported_types
);
104 this->supported_types
= NULL
;
106 /* Store the new MessageType list */
107 this->type_count
= type_count
;
108 if (type_count
&& supported_types
)
110 size_t size
= type_count
* sizeof(TNC_MessageType
);
114 for (i
= 0; i
< type_count
; i
++)
116 written
= snprintf(pos
, len
, " 0x%08x", supported_types
[i
]);
124 this->supported_types
= malloc(size
);
125 memcpy(this->supported_types
, supported_types
, size
);
128 DBG2(DBG_TNC
, "IMV %u supports %u message type%s:%s",
129 this->id
, type_count
, (type_count
== 1) ?
"":"s", buf
);
131 /* lock the imv_t instance */
132 this->mutex
->unlock(this->mutex
);
135 METHOD(imv_t
, type_supported
, bool,
136 private_tnc_imv_t
*this, TNC_MessageType message_type
)
138 TNC_VendorID msg_vid
, vid
;
139 TNC_MessageSubtype msg_subtype
, subtype
;
142 msg_vid
= (message_type
>> 8) & TNC_VENDORID_ANY
;
143 msg_subtype
= message_type
& TNC_SUBTYPE_ANY
;
145 for (i
= 0; i
< this->type_count
; i
++)
147 vid
= (this->supported_types
[i
] >> 8) & TNC_VENDORID_ANY
;
148 subtype
= this->supported_types
[i
] & TNC_SUBTYPE_ANY
;
150 if (this->supported_types
[i
] == message_type
151 || (subtype
== TNC_SUBTYPE_ANY
152 && (msg_vid
== vid
|| vid
== TNC_VENDORID_ANY
))
153 || (vid
== TNC_VENDORID_ANY
154 && (msg_subtype
== subtype
|| subtype
== TNC_SUBTYPE_ANY
)))
162 METHOD(imv_t
, destroy
, void,
163 private_tnc_imv_t
*this)
165 //dlclose(this->handle);
166 this->mutex
->destroy(this->mutex
);
167 free(this->supported_types
);
174 * Described in header.
176 imv_t
* tnc_imv_create(char *name
, char *path
)
178 private_tnc_imv_t
*this;
184 .get_name
= _get_name
,
185 .set_message_types
= _set_message_types
,
186 .type_supported
= _type_supported
,
191 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
194 this->handle
= dlopen(path
, RTLD_LAZY
);
197 DBG1(DBG_TNC
, "IMV \"%s\" failed to load: %s", name
, dlerror());
202 this->public.initialize
= dlsym(this->handle
, "TNC_IMV_Initialize");
203 if (!this->public.initialize
)
205 DBG1(DBG_TNC
, "could not resolve TNC_IMV_Initialize in %s: %s\n",
207 dlclose(this->handle
);
211 this->public.notify_connection_change
=
212 dlsym(this->handle
, "TNC_IMV_NotifyConnectionChange");
213 this->public.solicit_recommendation
=
214 dlsym(this->handle
, "TNC_IMV_SolicitRecommendation");
215 if (!this->public.solicit_recommendation
)
217 DBG1(DBG_TNC
, "could not resolve TNC_IMV_SolicitRecommendation in %s: %s\n",
219 dlclose(this->handle
);
223 this->public.receive_message
=
224 dlsym(this->handle
, "TNC_IMV_ReceiveMessage");
225 this->public.batch_ending
=
226 dlsym(this->handle
, "TNC_IMV_BatchEnding");
227 this->public.terminate
=
228 dlsym(this->handle
, "TNC_IMV_Terminate");
229 this->public.provide_bind_function
=
230 dlsym(this->handle
, "TNC_IMV_ProvideBindFunction");
231 if (!this->public.provide_bind_function
)
233 DBG1(DBG_TNC
, "could not resolve TNC_IMV_ProvideBindFunction in %s: %s\n",
235 dlclose(this->handle
);
240 return &this->public;