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
23 typedef struct private_tnc_imv_t private_tnc_imv_t
;
26 * Private data of an imv_t object.
28 struct private_tnc_imv_t
{
31 * Public members of imv_t.
46 * Handle of loaded IMV
56 * List of message types supported by IMC
58 TNC_MessageTypeList supported_types
;
61 * Number of supported message types
63 TNC_UInt32 type_count
;
66 METHOD(imv_t
, set_id
, void,
67 private_tnc_imv_t
*this, TNC_IMVID id
)
72 METHOD(imv_t
, get_id
, TNC_IMVID
,
73 private_tnc_imv_t
*this)
78 METHOD(imv_t
, get_name
, char*,
79 private_tnc_imv_t
*this)
84 METHOD(imv_t
, set_message_types
, void,
85 private_tnc_imv_t
*this, TNC_MessageTypeList supported_types
,
86 TNC_UInt32 type_count
)
88 /* Free an existing MessageType list */
89 free(this->supported_types
);
90 this->supported_types
= NULL
;
92 /* Store the new MessageType list */
93 this->type_count
= type_count
;
94 if (type_count
&& supported_types
)
96 size_t size
= type_count
* sizeof(TNC_MessageType
);
98 this->supported_types
= malloc(size
);
99 memcpy(this->supported_types
, supported_types
, size
);
101 DBG2(DBG_TNC
, "IMV %u supports %u message types", this->id
, type_count
);
104 METHOD(imv_t
, type_supported
, bool,
105 private_tnc_imv_t
*this, TNC_MessageType message_type
)
107 TNC_VendorID msg_vid
, vid
;
108 TNC_MessageSubtype msg_subtype
, subtype
;
111 msg_vid
= (message_type
>> 8) & TNC_VENDORID_ANY
;
112 msg_subtype
= message_type
& TNC_SUBTYPE_ANY
;
114 for (i
= 0; i
< this->type_count
; i
++)
116 vid
= (this->supported_types
[i
] >> 8) & TNC_VENDORID_ANY
;
117 subtype
= this->supported_types
[i
] & TNC_SUBTYPE_ANY
;
119 if (this->supported_types
[i
] == message_type
120 || (subtype
== TNC_SUBTYPE_ANY
121 && (msg_vid
== vid
|| vid
== TNC_VENDORID_ANY
))
122 || (vid
== TNC_VENDORID_ANY
123 && (msg_subtype
== subtype
|| subtype
== TNC_SUBTYPE_ANY
)))
131 METHOD(imv_t
, destroy
, void,
132 private_tnc_imv_t
*this)
134 dlclose(this->handle
);
135 free(this->supported_types
);
142 * Described in header.
144 imv_t
* tnc_imv_create(char *name
, char *path
)
146 private_tnc_imv_t
*this;
152 .get_name
= _get_name
,
153 .set_message_types
= _set_message_types
,
154 .type_supported
= _type_supported
,
161 this->handle
= dlopen(path
, RTLD_LAZY
);
164 DBG1(DBG_TNC
, "IMV \"%s\" failed to load: %s", name
, dlerror());
169 this->public.initialize
= dlsym(this->handle
, "TNC_IMV_Initialize");
170 if (!this->public.initialize
)
172 DBG1(DBG_TNC
, "could not resolve TNC_IMV_Initialize in %s: %s\n",
174 dlclose(this->handle
);
178 this->public.notify_connection_change
=
179 dlsym(this->handle
, "TNC_IMV_NotifyConnectionChange");
180 this->public.solicit_recommendation
=
181 dlsym(this->handle
, "TNC_IMV_SolicitRecommendation");
182 if (!this->public.solicit_recommendation
)
184 DBG1(DBG_TNC
, "could not resolve TNC_IMV_SolicitRecommendation in %s: %s\n",
186 dlclose(this->handle
);
190 this->public.receive_message
=
191 dlsym(this->handle
, "TNC_IMV_ReceiveMessage");
192 this->public.batch_ending
=
193 dlsym(this->handle
, "TNC_IMV_BatchEnding");
194 this->public.terminate
=
195 dlsym(this->handle
, "TNC_IMV_Terminate");
196 this->public.provide_bind_function
=
197 dlsym(this->handle
, "TNC_IMV_ProvideBindFunction");
198 if (!this->public.provide_bind_function
)
200 DBG1(DBG_TNC
, "could not resolve TNC_IMV_ProvideBindFunction in %s: %s\n",
202 dlclose(this->handle
);
207 return &this->public;