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.
41 * Handle of loaded IMV
51 * List of message types supported by IMC
53 TNC_MessageTypeList supported_types
;
56 * Number of supported message types
58 TNC_UInt32 type_count
;
61 METHOD(imv_t
, set_id
, void,
62 private_tnc_imv_t
*this, TNC_IMVID id
)
67 METHOD(imv_t
, get_id
, TNC_IMVID
,
68 private_tnc_imv_t
*this)
73 METHOD(imv_t
, get_name
, char*,
74 private_tnc_imv_t
*this)
79 METHOD(imv_t
, set_message_types
, void,
80 private_tnc_imv_t
*this, TNC_MessageTypeList supported_types
,
81 TNC_UInt32 type_count
)
83 /* Free an existing MessageType list */
84 free(this->supported_types
);
85 this->supported_types
= NULL
;
87 /* Store the new MessageType list */
88 this->type_count
= type_count
;
89 if (type_count
&& supported_types
)
91 size_t size
= type_count
* sizeof(TNC_MessageType
);
93 this->supported_types
= malloc(size
);
94 memcpy(this->supported_types
, supported_types
, size
);
96 DBG2(DBG_TNC
, "IMV %u supports %u message types", this->id
, type_count
);
99 METHOD(imv_t
, type_supported
, bool,
100 private_tnc_imv_t
*this, TNC_MessageType message_type
)
102 TNC_VendorID msg_vid
, vid
;
103 TNC_MessageSubtype msg_subtype
, subtype
;
106 msg_vid
= (message_type
>> 8) & TNC_VENDORID_ANY
;
107 msg_subtype
= message_type
& TNC_SUBTYPE_ANY
;
109 for (i
= 0; i
< this->type_count
; i
++)
111 vid
= (this->supported_types
[i
] >> 8) & TNC_VENDORID_ANY
;
112 subtype
= this->supported_types
[i
] & TNC_SUBTYPE_ANY
;
114 if (this->supported_types
[i
] == message_type
115 || (subtype
== TNC_SUBTYPE_ANY
116 && (msg_vid
== vid
|| vid
== TNC_VENDORID_ANY
))
117 || (vid
== TNC_VENDORID_ANY
118 && (msg_subtype
== subtype
|| subtype
== TNC_SUBTYPE_ANY
)))
126 METHOD(imv_t
, destroy
, void,
127 private_tnc_imv_t
*this)
129 dlclose(this->handle
);
130 free(this->supported_types
);
136 * Described in header.
138 imv_t
* tnc_imv_create(char *name
, char *filename
)
140 private_tnc_imv_t
*this;
146 .get_name
= _get_name
,
147 .set_message_types
= _set_message_types
,
148 .type_supported
= _type_supported
,
153 this->handle
= dlopen(filename
, RTLD_NOW
);
156 DBG1(DBG_TNC
, "IMV '%s' failed to load from '%s': %s",
157 name
, filename
, dlerror());
162 this->public.initialize
= dlsym(this->handle
, "TNC_IMV_Initialize");
163 if (!this->public.initialize
)
165 DBG1(DBG_TNC
, "could not resolve TNC_IMV_Initialize in %s: %s\n",
166 filename
, dlerror());
167 dlclose(this->handle
);
171 this->public.notify_connection_change
=
172 dlsym(this->handle
, "TNC_IMV_NotifyConnectionChange");
173 this->public.solicit_recommendation
=
174 dlsym(this->handle
, "TNC_IMV_SolicitRecommendation");
175 if (!this->public.solicit_recommendation
)
177 DBG1(DBG_TNC
, "could not resolve TNC_IMV_SolicitRecommendation in %s: %s\n",
178 filename
, dlerror());
179 dlclose(this->handle
);
183 this->public.receive_message
=
184 dlsym(this->handle
, "TNC_IMV_ReceiveMessage");
185 this->public.batch_ending
=
186 dlsym(this->handle
, "TNC_IMV_BatchEnding");
187 this->public.terminate
=
188 dlsym(this->handle
, "TNC_IMV_Terminate");
189 this->public.provide_bind_function
=
190 dlsym(this->handle
, "TNC_IMV_ProvideBindFunction");
191 if (!this->public.provide_bind_function
)
193 DBG1(DBG_TNC
, "could not resolve TNC_IMV_ProvideBindFunction in %s: %s\n",
194 filename
, dlerror());
195 dlclose(this->handle
);
199 this->name
= strdup(name
);
201 return &this->public;