static upper size limit for PA-TNC messages
[strongswan.git] / src / libimcv / imc / imc_agent.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "imcv.h"
16 #include "imc_agent.h"
17
18 #include <tncif_names.h>
19
20 #include <debug.h>
21 #include <threading/rwlock.h>
22
23 typedef struct private_imc_agent_t private_imc_agent_t;
24
25 /**
26 * Private data of an imc_agent_t object.
27 */
28 struct private_imc_agent_t {
29
30 /**
31 * Public members of imc_agent_t
32 */
33 imc_agent_t public;
34
35 /**
36 * name of IMC
37 */
38 const char *name;
39
40 /**
41 * message vendor ID of IMC
42 */
43 TNC_VendorID vendor_id;
44
45 /**
46 * message subtype of IMC
47 */
48 TNC_MessageSubtype subtype;
49
50 /**
51 * Maximum PA-TNC Message size
52 */
53 size_t max_msg_len;
54
55 /**
56 * ID of IMC as assigned by TNCC
57 */
58 TNC_IMCID id;
59
60 /**
61 * List of additional IMC IDs assigned by TNCC
62 */
63 linked_list_t *additional_ids;
64
65 /**
66 * list of TNCC connection entries
67 */
68 linked_list_t *connections;
69
70 /**
71 * rwlock to lock TNCC connection entries
72 */
73 rwlock_t *connection_lock;
74
75 /**
76 * Inform a TNCC about the set of message types the IMC is able to receive
77 *
78 * @param imc_id IMC ID assigned by TNCC
79 * @param supported_types list of supported message types
80 * @param type_count number of list elements
81 * @return TNC result code
82 */
83 TNC_Result (*report_message_types)(TNC_IMCID imc_id,
84 TNC_MessageTypeList supported_types,
85 TNC_UInt32 type_count);
86
87 /**
88 * Inform a TNCC about the set of message types the IMC is able to receive
89 *
90 * @param imc_id IMC ID assigned by TNCC
91 * @param supported_vids list of supported message vendor IDs
92 * @param supported_subtypes list of supported message subtypes
93 * @param type_count number of list elements
94 * @return TNC result code
95 */
96 TNC_Result (*report_message_types_long)(TNC_IMCID imc_id,
97 TNC_VendorIDList supported_vids,
98 TNC_MessageSubtypeList supported_subtypes,
99 TNC_UInt32 type_count);
100
101 /**
102 * Call when an IMC-IMC message is to be sent
103 *
104 * @param imc_id IMC ID assigned by TNCC
105 * @param connection_id network connection ID assigned by TNCC
106 * @param msg message to send
107 * @param msg_len message length in bytes
108 * @param msg_type message type
109 * @return TNC result code
110 */
111 TNC_Result (*send_message)(TNC_IMCID imc_id,
112 TNC_ConnectionID connection_id,
113 TNC_BufferReference msg,
114 TNC_UInt32 msg_len,
115 TNC_MessageType msg_type);
116
117
118 /**
119 * Call when an IMC-IMC message is to be sent with long message types
120 *
121 * @param imc_id IMC ID assigned by TNCC
122 * @param connection_id network connection ID assigned by TNCC
123 * @param msg_flags message flags
124 * @param msg message to send
125 * @param msg_len message length in bytes
126 * @param msg_vid message vendor ID
127 * @param msg_subtype message subtype
128 * @param dst_imc_id destination IMV ID
129 * @return TNC result code
130 */
131 TNC_Result (*send_message_long)(TNC_IMCID imc_id,
132 TNC_ConnectionID connection_id,
133 TNC_UInt32 msg_flags,
134 TNC_BufferReference msg,
135 TNC_UInt32 msg_len,
136 TNC_VendorID msg_vid,
137 TNC_MessageSubtype msg_subtype,
138 TNC_UInt32 dst_imv_id);
139
140 /**
141 * Get the value of an attribute associated with a connection
142 * or with the TNCC as a whole.
143 *
144 * @param imc_id IMC ID assigned by TNCC
145 * @param connection_id network connection ID assigned by TNCC
146 * @param attribute_id attribute ID
147 * @param buffer_len length of buffer in bytes
148 * @param buffer buffer
149 * @param out_value_len size in bytes of attribute stored in buffer
150 * @return TNC result code
151 */
152 TNC_Result (*get_attribute)(TNC_IMCID imc_id,
153 TNC_ConnectionID connection_id,
154 TNC_AttributeID attribute_id,
155 TNC_UInt32 buffer_len,
156 TNC_BufferReference buffer,
157 TNC_UInt32 *out_value_len);
158
159 /**
160 * Set the value of an attribute associated with a connection
161 * or with the TNCC as a whole.
162 *
163 * @param imc_id IMV ID assigned by TNCC
164 * @param connection_id network connection ID assigned by TNCC
165 * @param attribute_id attribute ID
166 * @param buffer_len length of buffer in bytes
167 * @param buffer buffer
168 * @return TNC result code
169 */
170 TNC_Result (*set_attribute)(TNC_IMCID imc_id,
171 TNC_ConnectionID connection_id,
172 TNC_AttributeID attribute_id,
173 TNC_UInt32 buffer_len,
174 TNC_BufferReference buffer);
175
176 /**
177 * Reserve an additional IMC ID
178 *
179 * @param imc_id primary IMC ID assigned by TNCC
180 * @param out_imc_id additional IMC ID assigned by TNCC
181 * @return TNC result code
182 */
183 TNC_Result (*reserve_additional_id)(TNC_IMCID imc_id,
184 TNC_UInt32 *out_imc_id);
185
186 };
187
188 METHOD(imc_agent_t, bind_functions, TNC_Result,
189 private_imc_agent_t *this, TNC_TNCC_BindFunctionPointer bind_function)
190 {
191 if (!bind_function)
192 {
193 DBG1(DBG_IMC, "TNC client failed to provide bind function");
194 return TNC_RESULT_INVALID_PARAMETER;
195 }
196 if (bind_function(this->id, "TNC_TNCC_ReportMessageTypes",
197 (void**)&this->report_message_types) != TNC_RESULT_SUCCESS)
198 {
199 this->report_message_types = NULL;
200 }
201 if (bind_function(this->id, "TNC_TNCC_ReportMessageTypesLong",
202 (void**)&this->report_message_types_long) != TNC_RESULT_SUCCESS)
203 {
204 this->report_message_types_long = NULL;
205 }
206 if (bind_function(this->id, "TNC_TNCC_RequestHandshakeRetry",
207 (void**)&this->public.request_handshake_retry) != TNC_RESULT_SUCCESS)
208 {
209 this->public.request_handshake_retry = NULL;
210 }
211 if (bind_function(this->id, "TNC_TNCC_SendMessage",
212 (void**)&this->send_message) != TNC_RESULT_SUCCESS)
213 {
214 this->send_message = NULL;
215 }
216 if (bind_function(this->id, "TNC_TNCC_SendMessageLong",
217 (void**)&this->send_message_long) != TNC_RESULT_SUCCESS)
218 {
219 this->send_message_long = NULL;
220 }
221 if (bind_function(this->id, "TNC_TNCC_GetAttribute",
222 (void**)&this->get_attribute) != TNC_RESULT_SUCCESS)
223 {
224 this->get_attribute = NULL;
225 }
226 if (bind_function(this->id, "TNC_TNCC_SetAttribute",
227 (void**)&this->set_attribute) != TNC_RESULT_SUCCESS)
228 {
229 this->set_attribute = NULL;
230 }
231 if (bind_function(this->id, "TNC_TNCC_ReserveAdditionalIMCID",
232 (void**)&this->reserve_additional_id) != TNC_RESULT_SUCCESS)
233 {
234 this->reserve_additional_id = NULL;
235 }
236 DBG2(DBG_IMC, "IMC %u \"%s\" provided with bind function",
237 this->id, this->name);
238
239 if (this->report_message_types_long)
240 {
241 this->report_message_types_long(this->id, &this->vendor_id,
242 &this->subtype, 1);
243 }
244 else if (this->report_message_types &&
245 this->vendor_id <= TNC_VENDORID_ANY &&
246 this->subtype <= TNC_SUBTYPE_ANY)
247 {
248 TNC_MessageType type;
249
250 type = (this->vendor_id << 8) | this->subtype;
251 this->report_message_types(this->id, &type, 1);
252 }
253 return TNC_RESULT_SUCCESS;
254 }
255
256 /**
257 * finds a connection state based on its Connection ID
258 */
259 static imc_state_t* find_connection(private_imc_agent_t *this,
260 TNC_ConnectionID id)
261 {
262 enumerator_t *enumerator;
263 imc_state_t *state, *found = NULL;
264
265 this->connection_lock->read_lock(this->connection_lock);
266 enumerator = this->connections->create_enumerator(this->connections);
267 while (enumerator->enumerate(enumerator, &state))
268 {
269 if (id == state->get_connection_id(state))
270 {
271 found = state;
272 break;
273 }
274 }
275 enumerator->destroy(enumerator);
276 this->connection_lock->unlock(this->connection_lock);
277
278 return found;
279 }
280
281 /**
282 * delete a connection state with a given Connection ID
283 */
284 static bool delete_connection(private_imc_agent_t *this, TNC_ConnectionID id)
285 {
286 enumerator_t *enumerator;
287 imc_state_t *state;
288 bool found = FALSE;
289
290 this->connection_lock->write_lock(this->connection_lock);
291 enumerator = this->connections->create_enumerator(this->connections);
292 while (enumerator->enumerate(enumerator, &state))
293 {
294 if (id == state->get_connection_id(state))
295 {
296 found = TRUE;
297 state->destroy(state);
298 this->connections->remove_at(this->connections, enumerator);
299 break;
300 }
301 }
302 enumerator->destroy(enumerator);
303 this->connection_lock->unlock(this->connection_lock);
304
305 return found;
306 }
307
308 /**
309 * Read a boolean attribute
310 */
311 static bool get_bool_attribute(private_imc_agent_t *this, TNC_ConnectionID id,
312 TNC_AttributeID attribute_id)
313 {
314 TNC_UInt32 len;
315 char buf[4];
316
317 return this->get_attribute &&
318 this->get_attribute(this->id, id, attribute_id, 4, buf, &len) ==
319 TNC_RESULT_SUCCESS && len == 1 && *buf == 0x01;
320 }
321
322 /**
323 * Read a string attribute
324 */
325 static char* get_str_attribute(private_imc_agent_t *this, TNC_ConnectionID id,
326 TNC_AttributeID attribute_id)
327 {
328 TNC_UInt32 len;
329 char buf[BUF_LEN];
330
331 if (this->get_attribute &&
332 this->get_attribute(this->id, id, attribute_id, BUF_LEN, buf, &len) ==
333 TNC_RESULT_SUCCESS && len <= BUF_LEN)
334 {
335 return strdup(buf);
336 }
337 return NULL;
338 }
339
340 METHOD(imc_agent_t, create_state, TNC_Result,
341 private_imc_agent_t *this, imc_state_t *state)
342 {
343 TNC_ConnectionID conn_id;
344 char *tnccs_p = NULL, *tnccs_v = NULL, *t_p = NULL, *t_v = NULL;
345 bool has_long = FALSE, has_excl = FALSE, has_soh = FALSE;
346
347 conn_id = state->get_connection_id(state);
348 if (find_connection(this, conn_id))
349 {
350 DBG1(DBG_IMC, "IMC %u \"%s\" already created a state for Connection ID %u",
351 this->id, this->name, conn_id);
352 state->destroy(state);
353 return TNC_RESULT_OTHER;
354 }
355
356 /* Get and display attributes from TNCC via IF-IMC */
357 has_long = get_bool_attribute(this, conn_id, TNC_ATTRIBUTEID_HAS_LONG_TYPES);
358 has_excl = get_bool_attribute(this, conn_id, TNC_ATTRIBUTEID_HAS_EXCLUSIVE);
359 has_soh = get_bool_attribute(this, conn_id, TNC_ATTRIBUTEID_HAS_SOH);
360 tnccs_p = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFTNCCS_PROTOCOL);
361 tnccs_v = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFTNCCS_VERSION);
362 t_p = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFT_PROTOCOL);
363 t_v = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFT_VERSION);
364
365 state->set_flags(state, has_long, has_excl);
366
367 DBG2(DBG_IMC, "IMC %u \"%s\" created a state for Connection ID %u: "
368 "%s %s with %slong %sexcl %ssoh over %s %s",
369 this->id, this->name, conn_id, tnccs_p ? tnccs_p:"?",
370 tnccs_v ? tnccs_v:"?", has_long ? "+":"-", has_excl ? "+":"-",
371 has_soh ? "+":"-", t_p ? t_p:"?", t_v ? t_v :"?");
372 free(tnccs_p);
373 free(tnccs_v);
374 free(t_p);
375 free(t_v);
376
377 this->connection_lock->write_lock(this->connection_lock);
378 this->connections->insert_last(this->connections, state);
379 this->connection_lock->unlock(this->connection_lock);
380 return TNC_RESULT_SUCCESS;
381 }
382
383 METHOD(imc_agent_t, delete_state, TNC_Result,
384 private_imc_agent_t *this, TNC_ConnectionID connection_id)
385 {
386 if (!delete_connection(this, connection_id))
387 {
388 DBG1(DBG_IMC, "IMC %u \"%s\" has no state for Connection ID %u",
389 this->id, this->name, connection_id);
390 return TNC_RESULT_FATAL;
391 }
392 DBG2(DBG_IMC, "IMC %u \"%s\" deleted the state of Connection ID %u",
393 this->id, this->name, connection_id);
394 return TNC_RESULT_SUCCESS;
395 }
396
397 METHOD(imc_agent_t, change_state, TNC_Result,
398 private_imc_agent_t *this, TNC_ConnectionID connection_id,
399 TNC_ConnectionState new_state,
400 imc_state_t **state_p)
401 {
402 imc_state_t *state;
403
404 switch (new_state)
405 {
406 case TNC_CONNECTION_STATE_HANDSHAKE:
407 case TNC_CONNECTION_STATE_ACCESS_ALLOWED:
408 case TNC_CONNECTION_STATE_ACCESS_ISOLATED:
409 case TNC_CONNECTION_STATE_ACCESS_NONE:
410 state = find_connection(this, connection_id);
411
412 if (!state)
413 {
414 DBG1(DBG_IMC, "IMC %u \"%s\" has no state for Connection ID %u",
415 this->id, this->name, connection_id);
416 return TNC_RESULT_FATAL;
417 }
418 state->change_state(state, new_state);
419 DBG2(DBG_IMC, "IMC %u \"%s\" changed state of Connection ID %u to '%N'",
420 this->id, this->name, connection_id,
421 TNC_Connection_State_names, new_state);
422 if (state_p)
423 {
424 *state_p = state;
425 }
426 break;
427 case TNC_CONNECTION_STATE_CREATE:
428 DBG1(DBG_IMC, "state '%N' should be handled by create_state()",
429 TNC_Connection_State_names, new_state);
430 return TNC_RESULT_FATAL;
431 case TNC_CONNECTION_STATE_DELETE:
432 DBG1(DBG_IMC, "state '%N' should be handled by delete_state()",
433 TNC_Connection_State_names, new_state);
434 return TNC_RESULT_FATAL;
435 default:
436 DBG1(DBG_IMC, "IMC %u \"%s\" was notified of unknown state %u "
437 "for Connection ID %u",
438 this->id, this->name, new_state, connection_id);
439 return TNC_RESULT_INVALID_PARAMETER;
440 }
441 return TNC_RESULT_SUCCESS;
442 }
443
444 METHOD(imc_agent_t, get_state, bool,
445 private_imc_agent_t *this, TNC_ConnectionID connection_id,
446 imc_state_t **state)
447 {
448 *state = find_connection(this, connection_id);
449 if (!*state)
450 {
451 DBG1(DBG_IMC, "IMC %u \"%s\" has no state for Connection ID %u",
452 this->id, this->name, connection_id);
453 return FALSE;
454 }
455 return TRUE;
456 }
457
458 METHOD(imc_agent_t, send_message, TNC_Result,
459 private_imc_agent_t *this, TNC_ConnectionID connection_id, bool excl,
460 TNC_UInt32 src_imc_id, TNC_UInt32 dst_imv_id, linked_list_t *attr_list)
461 {
462 TNC_MessageType type;
463 TNC_UInt32 msg_flags;
464 TNC_Result result = TNC_RESULT_FATAL;
465 imc_state_t *state;
466 pa_tnc_attr_t *attr;
467 pa_tnc_msg_t *pa_tnc_msg;
468 chunk_t msg;
469 enumerator_t *enumerator;
470
471 state = find_connection(this, connection_id);
472 if (!state)
473 {
474 DBG1(DBG_IMV, "IMC %u \"%s\" has no state for Connection ID %u",
475 this->id, this->name, connection_id);
476 return TNC_RESULT_FATAL;
477 }
478
479 while (attr_list->get_count(attr_list))
480 {
481 pa_tnc_msg = pa_tnc_msg_create(this->max_msg_len);
482
483 enumerator = attr_list->create_enumerator(attr_list);
484 while (enumerator->enumerate(enumerator, &attr))
485 {
486 if (!pa_tnc_msg->add_attribute(pa_tnc_msg, attr))
487 {
488 break;
489 }
490 attr_list->remove_at(attr_list, enumerator);
491 }
492 enumerator->destroy(enumerator);
493
494 /* build and send the PA-TNC message via the IF-IMC interface */
495 pa_tnc_msg->build(pa_tnc_msg);
496 msg = pa_tnc_msg->get_encoding(pa_tnc_msg);
497
498 if (state->has_long(state) && this->send_message_long)
499 {
500 if (!src_imc_id)
501 {
502 src_imc_id = this->id;
503 }
504 msg_flags = excl ? TNC_MESSAGE_FLAGS_EXCLUSIVE : 0;
505
506 result = this->send_message_long(src_imc_id, connection_id,
507 msg_flags, msg.ptr, msg.len, this->vendor_id,
508 this->subtype, dst_imv_id);
509 }
510 else if (this->send_message)
511 {
512 type = (this->vendor_id << 8) | this->subtype;
513
514 result = this->send_message(this->id, connection_id, msg.ptr,
515 msg.len, type);
516 }
517
518 pa_tnc_msg->destroy(pa_tnc_msg);
519
520 if (result != TNC_RESULT_SUCCESS)
521 {
522 break;
523 }
524 }
525 return result;
526 }
527
528 METHOD(imc_agent_t, receive_message, TNC_Result,
529 private_imc_agent_t *this, imc_state_t *state, chunk_t msg,
530 TNC_VendorID msg_vid, TNC_MessageSubtype msg_subtype,
531 TNC_UInt32 src_imv_id, TNC_UInt32 dst_imc_id, pa_tnc_msg_t **pa_tnc_msg)
532 {
533 pa_tnc_msg_t *pa_msg, *error_msg;
534 pa_tnc_attr_t *error_attr;
535 enumerator_t *enumerator;
536 TNC_MessageType msg_type;
537 TNC_UInt32 msg_flags, src_imc_id, dst_imv_id;
538 TNC_ConnectionID connection_id;
539 TNC_Result result;
540
541 connection_id = state->get_connection_id(state);
542
543 if (state->has_long(state))
544 {
545 if (dst_imc_id != TNC_IMCID_ANY)
546 {
547 DBG2(DBG_IMC, "IMC %u \"%s\" received message for Connection ID %u "
548 "from IMV %u to IMC %u", this->id, this->name,
549 connection_id, src_imv_id, dst_imc_id);
550 }
551 else
552 {
553 DBG2(DBG_IMC, "IMC %u \"%s\" received message for Connection ID %u "
554 "from IMV %u", this->id, this->name, connection_id,
555 src_imv_id);
556 }
557 }
558 else
559 {
560 DBG2(DBG_IMC, "IMC %u \"%s\" received message for Connection ID %u",
561 this->id, this->name, connection_id);
562 }
563
564 *pa_tnc_msg = NULL;
565 pa_msg = pa_tnc_msg_create_from_data(msg);
566
567 switch (pa_msg->process(pa_msg))
568 {
569 case SUCCESS:
570 *pa_tnc_msg = pa_msg;
571 break;
572 case VERIFY_ERROR:
573 /* build error message */
574 error_msg = pa_tnc_msg_create(this->max_msg_len);
575 enumerator = pa_msg->create_error_enumerator(pa_msg);
576 while (enumerator->enumerate(enumerator, &error_attr))
577 {
578 error_msg->add_attribute(error_msg,
579 error_attr->get_ref(error_attr));
580 }
581 enumerator->destroy(enumerator);
582 error_msg->build(error_msg);
583
584 /* send error message */
585 if (state->has_long(state) && this->send_message_long)
586 {
587 if (state->has_excl(state))
588 {
589 msg_flags = TNC_MESSAGE_FLAGS_EXCLUSIVE;
590 dst_imv_id = src_imv_id;
591 }
592 else
593 {
594 msg_flags = 0;
595 dst_imv_id = TNC_IMVID_ANY;
596 }
597 src_imc_id = (dst_imc_id == TNC_IMCID_ANY) ? this->id
598 : dst_imc_id;
599
600 result = this->send_message_long(src_imc_id, connection_id,
601 msg_flags, msg.ptr, msg.len, msg_vid,
602 msg_subtype, dst_imv_id);
603 }
604 else if (this->send_message)
605 {
606 msg_type = (msg_vid << 8) | msg_subtype;
607
608 result = this->send_message(this->id, connection_id,
609 msg.ptr, msg.len, msg_type);
610 }
611 else
612 {
613 result = TNC_RESULT_FATAL;
614 }
615
616 /* clean up */
617 error_msg->destroy(error_msg);
618 pa_msg->destroy(pa_msg);
619 return result;
620 case FAILED:
621 default:
622 pa_msg->destroy(pa_msg);
623 return TNC_RESULT_FATAL;
624 }
625 return TNC_RESULT_SUCCESS;
626 }
627
628 METHOD(imc_agent_t, reserve_additional_ids, TNC_Result,
629 private_imc_agent_t *this, int count)
630 {
631 TNC_Result result;
632 TNC_UInt32 id;
633 void *pointer;
634
635 if (!this->reserve_additional_id)
636 {
637 DBG1(DBG_IMC, "IMC %u \"%s\" did not detect the capability to reserve "
638 "additional IMC IDs from the TNCC", this->id, this->name);
639 return TNC_RESULT_ILLEGAL_OPERATION;
640 }
641 while (count > 0)
642 {
643 result = this->reserve_additional_id(this->id, &id);
644 if (result != TNC_RESULT_SUCCESS)
645 {
646 DBG1(DBG_IMC, "IMC %u \"%s\" failed to reserve %d additional IMC IDs",
647 this->id, this->name, count);
648 return result;
649 }
650 count--;
651
652 /* store the scalar value in the pointer */
653 pointer = (void*)id;
654 this->additional_ids->insert_last(this->additional_ids, pointer);
655 DBG2(DBG_IMC, "IMC %u \"%s\" reserved additional ID %u",
656 this->id, this->name, id);
657 }
658 return TNC_RESULT_SUCCESS;
659 }
660
661 METHOD(imc_agent_t, count_additional_ids, int,
662 private_imc_agent_t *this)
663 {
664 return this->additional_ids->get_count(this->additional_ids);
665 }
666
667 METHOD(imc_agent_t, create_id_enumerator, enumerator_t*,
668 private_imc_agent_t *this)
669 {
670 return this->additional_ids->create_enumerator(this->additional_ids);
671 }
672
673 METHOD(imc_agent_t, destroy, void,
674 private_imc_agent_t *this)
675 {
676 DBG1(DBG_IMC, "IMC %u \"%s\" terminated", this->id, this->name);
677 this->additional_ids->destroy(this->additional_ids);
678 this->connections->destroy_function(this->connections, free);
679 this->connection_lock->destroy(this->connection_lock);
680 free(this);
681
682 /* decrease the reference count or terminate */
683 libimcv_deinit();
684 }
685
686 /**
687 * Described in header.
688 */
689 imc_agent_t *imc_agent_create(const char *name,
690 pen_t vendor_id, u_int32_t subtype,
691 TNC_IMCID id, TNC_Version *actual_version)
692 {
693 private_imc_agent_t *this;
694
695 /* initialize or increase the reference count */
696 if (!libimcv_init())
697 {
698 return NULL;
699 }
700
701 INIT(this,
702 .public = {
703 .bind_functions = _bind_functions,
704 .create_state = _create_state,
705 .delete_state = _delete_state,
706 .change_state = _change_state,
707 .get_state = _get_state,
708 .send_message = _send_message,
709 .receive_message = _receive_message,
710 .reserve_additional_ids = _reserve_additional_ids,
711 .count_additional_ids = _count_additional_ids,
712 .create_id_enumerator = _create_id_enumerator,
713 .destroy = _destroy,
714 },
715 .name = name,
716 .vendor_id = vendor_id,
717 .subtype = subtype,
718 .max_msg_len = 65490,
719 .id = id,
720 .additional_ids = linked_list_create(),
721 .connections = linked_list_create(),
722 .connection_lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
723 );
724
725 *actual_version = TNC_IFIMC_VERSION_1;
726 DBG1(DBG_IMC, "IMC %u \"%s\" initialized", this->id, this->name);
727
728 return &this->public;
729 }
730