]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libimcv/plugins/imc_hcd/imc_hcd.c
b631683cec8ec54f8bbdb99b0ddce441c511a82c
[thirdparty/strongswan.git] / src / libimcv / plugins / imc_hcd / imc_hcd.c
1 /*
2 * Copyright (C) 2015 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "imc_hcd_state.h"
17
18 #include <imc/imc_agent.h>
19 #include <imc/imc_msg.h>
20 #include <imc/imc_os_info.h>
21 #include <generic/generic_attr_bool.h>
22 #include <generic/generic_attr_chunk.h>
23 #include <generic/generic_attr_string.h>
24 #include <ietf/ietf_attr.h>
25 #include <ietf/ietf_attr_attr_request.h>
26 #include "ietf/ietf_attr_fwd_enabled.h"
27 #include <pwg/pwg_attr.h>
28 #include <pwg/pwg_attr_vendor_smi_code.h>
29
30 #include <tncif_pa_subtypes.h>
31
32 #include <pen/pen.h>
33 #include <utils/debug.h>
34
35 /* IMC definitions */
36
37 static const char imc_name[] = "HCD";
38
39 static pen_type_t msg_types[] = {
40 { PEN_PWG, PA_SUBTYPE_PWG_HCD_SYSTEM },
41 { PEN_PWG, PA_SUBTYPE_PWG_HCD_CONSOLE },
42 { PEN_PWG, PA_SUBTYPE_PWG_HCD_MARKER },
43 { PEN_PWG, PA_SUBTYPE_PWG_HCD_FINISHER },
44 { PEN_PWG, PA_SUBTYPE_PWG_HCD_INTERFACE },
45 { PEN_PWG, PA_SUBTYPE_PWG_HCD_SCANNER }
46 };
47
48 static imc_agent_t *imc_hcd;
49 static imc_os_info_t *os;
50
51 typedef struct section_subtype_t section_subtype_t;
52
53 struct section_subtype_t {
54 char *section;
55 pa_subtype_pwg_t subtype;
56 };
57
58 static section_subtype_t section_subtypes[] = {
59 { "system", PA_SUBTYPE_PWG_HCD_SYSTEM },
60 { "console", PA_SUBTYPE_PWG_HCD_CONSOLE },
61 { "marker", PA_SUBTYPE_PWG_HCD_MARKER },
62 { "finisher", PA_SUBTYPE_PWG_HCD_FINISHER },
63 { "interface", PA_SUBTYPE_PWG_HCD_INTERFACE },
64 { "scanner" , PA_SUBTYPE_PWG_HCD_SCANNER }
65 };
66
67 typedef struct quadruple_t quadruple_t;
68
69 struct quadruple_t {
70 char *section;
71 pwg_attr_t name_attr;
72 pwg_attr_t patches_attr;
73 pwg_attr_t string_version_attr;
74 pwg_attr_t version_attr;
75 };
76
77 static quadruple_t quadruples[] = {
78 { "firmware",
79 PWG_HCD_FIRMWARE_NAME, PWG_HCD_FIRMWARE_PATCHES,
80 PWG_HCD_FIRMWARE_STRING_VERSION, PWG_HCD_FIRMWARE_VERSION },
81 { "resident_application",
82 PWG_HCD_RESIDENT_APP_NAME, PWG_HCD_RESIDENT_APP_PATCHES,
83 PWG_HCD_RESIDENT_APP_STRING_VERSION, PWG_HCD_RESIDENT_APP_VERSION },
84 { "user_application",
85 PWG_HCD_USER_APP_NAME, PWG_HCD_USER_APP_PATCHES,
86 PWG_HCD_USER_APP_STRING_VERSION, PWG_HCD_USER_APP_VERSION }
87 };
88
89 /**
90 * see section 3.8.1 of TCG TNC IF-IMC Specification 1.3
91 */
92 TNC_Result TNC_IMC_API TNC_IMC_Initialize(TNC_IMCID imc_id,
93 TNC_Version min_version,
94 TNC_Version max_version,
95 TNC_Version *actual_version)
96 {
97 if (imc_hcd)
98 {
99 DBG1(DBG_IMC, "IMC \"%s\" has already been initialized", imc_name);
100 return TNC_RESULT_ALREADY_INITIALIZED;
101 }
102 imc_hcd = imc_agent_create(imc_name, msg_types, countof(msg_types),
103 imc_id, actual_version);
104 if (!imc_hcd)
105 {
106 return TNC_RESULT_FATAL;
107 }
108
109 os = imc_os_info_create();
110 if (!os)
111 {
112 imc_hcd->destroy(imc_hcd);
113 imc_hcd = NULL;
114
115 return TNC_RESULT_FATAL;
116 }
117
118 if (min_version > TNC_IFIMC_VERSION_1 || max_version < TNC_IFIMC_VERSION_1)
119 {
120 DBG1(DBG_IMC, "no common IF-IMC version");
121 return TNC_RESULT_NO_COMMON_VERSION;
122 }
123 return TNC_RESULT_SUCCESS;
124 }
125
126 /**
127 * see section 3.8.2 of TCG TNC IF-IMC Specification 1.3
128 */
129 TNC_Result TNC_IMC_API TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
130 TNC_ConnectionID connection_id, TNC_ConnectionState new_state)
131 {
132 imc_state_t *state;
133
134 if (!imc_hcd)
135 {
136 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
137 return TNC_RESULT_NOT_INITIALIZED;
138 }
139 switch (new_state)
140 {
141 case TNC_CONNECTION_STATE_CREATE:
142 state = imc_hcd_state_create(connection_id);
143 return imc_hcd->create_state(imc_hcd, state);
144 case TNC_CONNECTION_STATE_HANDSHAKE:
145 if (imc_hcd->change_state(imc_hcd, connection_id, new_state,
146 &state) != TNC_RESULT_SUCCESS)
147 {
148 return TNC_RESULT_FATAL;
149 }
150 state->set_result(state, imc_id,
151 TNC_IMV_EVALUATION_RESULT_DONT_KNOW);
152 return TNC_RESULT_SUCCESS;
153 case TNC_CONNECTION_STATE_DELETE:
154 return imc_hcd->delete_state(imc_hcd, connection_id);
155 default:
156 return imc_hcd->change_state(imc_hcd, connection_id,
157 new_state, NULL);
158 }
159 }
160
161 /**
162 * Add AttributesNaturalLanguage attribute to send queue
163 */
164 static void add_attrs_natural_lang(imc_msg_t *msg, char *section)
165 {
166 pa_tnc_attr_t *attr;
167 char *string;
168
169 string = lib->settings->get_str(lib->settings,
170 "%s.plugins.imc-hcd.subtypes.%s.attributes_natural_language",
171 "en", lib->ns, section);
172 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_ATTRS_NATURAL_LANG,
173 string);
174 attr = generic_attr_string_create(chunk_from_str(string),
175 pen_type_create(PEN_PWG, PWG_HCD_ATTRS_NATURAL_LANG));
176 msg->add_attribute(msg, attr);
177 }
178
179 /**
180 * Add DefaultPasswordEnabled attribute to send queue
181 */
182 static void add_default_pwd_enabled(imc_msg_t *msg)
183 {
184 pa_tnc_attr_t *attr;
185 bool status;
186
187 status = os->get_default_pwd_status(os);
188 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_DEFAULT_PWD_ENABLED,
189 status ? "yes" : "no");
190 attr = generic_attr_bool_create(status,
191 pen_type_create(PEN_PWG, PWG_HCD_DEFAULT_PWD_ENABLED));
192 msg->add_attribute(msg, attr);
193 }
194
195 /**
196 * Add ForwardingEnabled attribute to send queue
197 */
198 static void add_forwarding_enabled(imc_msg_t *msg)
199 {
200 pa_tnc_attr_t *attr;
201 os_fwd_status_t fwd_status;
202
203 fwd_status = os->get_fwd_status(os);
204 DBG2(DBG_IMC, " %N: %N", pwg_attr_names, PWG_HCD_FORWARDING_ENABLED,
205 os_fwd_status_names, fwd_status);
206 attr = ietf_attr_fwd_enabled_create(fwd_status,
207 pen_type_create(PEN_PWG, PWG_HCD_FORWARDING_ENABLED));
208 msg->add_attribute(msg, attr);
209 }
210
211 /**
212 * Add MachineTypeModel attribute to send queue
213 */
214 static void add_machine_type_model(imc_msg_t *msg)
215 {
216 pa_tnc_attr_t *attr;
217 char *string;
218
219 string = lib->settings->get_str(lib->settings,
220 "%s.plugins.imc-hcd.subtypes.system.machine_type_model",
221 "", lib->ns);
222 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_MACHINE_TYPE_MODEL,
223 string);
224 attr = generic_attr_string_create(chunk_from_str(string),
225 pen_type_create(PEN_PWG, PWG_HCD_MACHINE_TYPE_MODEL));
226 msg->add_attribute(msg, attr);
227 }
228
229 /**
230 * Add PSTNFaxEnabled attribute to send queue
231 */
232 static void add_pstn_fax_enabled(imc_msg_t *msg)
233 {
234 pa_tnc_attr_t *attr;
235 bool status;
236
237 status = lib->settings->get_bool(lib->settings,
238 "%s.plugins.imc-hcd.subtypes.system.pstn_fax_enabled",
239 FALSE, lib->ns);
240 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_PSTN_FAX_ENABLED,
241 status ? "yes" : "no");
242 attr = generic_attr_bool_create(status,
243 pen_type_create(PEN_PWG, PWG_HCD_PSTN_FAX_ENABLED));
244 msg->add_attribute(msg, attr);
245 }
246
247 /**
248 * Add TimeSource attribute to send queue
249 */
250 static void add_time_source(imc_msg_t *msg)
251 {
252 pa_tnc_attr_t *attr;
253 char *string;
254
255 string = lib->settings->get_str(lib->settings,
256 "%s.plugins.imc-hcd.subtypes.system.time_source",
257 "", lib->ns);
258 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_TIME_SOURCE,
259 string);
260 attr = generic_attr_string_create(chunk_from_str(string),
261 pen_type_create(PEN_PWG, PWG_HCD_TIME_SOURCE));
262 msg->add_attribute(msg, attr);
263 }
264
265 /**
266 * Add UserApplicationEnabled attribute to send queue
267 */
268 static void add_user_app_enabled(imc_msg_t *msg)
269 {
270 pa_tnc_attr_t *attr;
271 bool status;
272
273 status = lib->settings->get_bool(lib->settings,
274 "%s.plugins.imc-hcd.subtypes.system.user_application_enabled",
275 FALSE, lib->ns);
276 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_USER_APP_ENABLED,
277 status ? "yes" : "no");
278 attr = generic_attr_bool_create(status,
279 pen_type_create(PEN_PWG, PWG_HCD_USER_APP_ENABLED));
280 msg->add_attribute(msg, attr);
281 }
282
283 /**
284 * Add UserApplicationPersistenceEnabled attribute to send queue
285 */
286 static void add_user_app_persist_enabled(imc_msg_t *msg)
287 {
288 pa_tnc_attr_t *attr;
289 bool status;
290
291 status = lib->settings->get_bool(lib->settings,
292 "%s.plugins.imc-hcd.subtypes.system.user_application_persistence.enabled",
293 FALSE, lib->ns);
294 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_USER_APP_PERSIST_ENABLED,
295 status ? "yes" : "no");
296 attr = generic_attr_bool_create(status,
297 pen_type_create(PEN_PWG, PWG_HCD_USER_APP_PERSIST_ENABLED));
298 msg->add_attribute(msg, attr);
299 }
300
301 /**
302 * Add VendorName attribute to send queue
303 */
304 static void add_vendor_name(imc_msg_t *msg)
305 {
306 pa_tnc_attr_t *attr;
307 char *string;
308
309 string = lib->settings->get_str(lib->settings,
310 "%s.plugins.imc-hcd.subtypes.system.vendor_name",
311 "", lib->ns);
312 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, PWG_HCD_VENDOR_NAME,
313 string);
314 attr = generic_attr_string_create(chunk_from_str(string),
315 pen_type_create(PEN_PWG, PWG_HCD_VENDOR_NAME));
316 msg->add_attribute(msg, attr);
317 }
318
319 /**
320 * Add VendorSMICode attribute to send queue
321 */
322 static void add_vendor_smi_code(imc_msg_t *msg)
323 {
324 pa_tnc_attr_t *attr;
325 int smi_code;
326
327 smi_code = lib->settings->get_int(lib->settings,
328 "%s.plugins.imc-hcd.subtypes.system.vendor_smi_code",
329 0, lib->ns);
330 DBG2(DBG_IMC, " %N: 0x%06x (%d)", pwg_attr_names, PWG_HCD_VENDOR_SMI_CODE,
331 smi_code, smi_code);
332 attr = pwg_attr_vendor_smi_code_create(smi_code);
333 msg->add_attribute(msg, attr);
334 }
335
336 /**
337 * Add CertificationState attribute to send queue
338 */
339 static void add_certification_state(imc_msg_t *msg)
340 {
341 pa_tnc_attr_t *attr;
342 char *hex_string;
343 chunk_t blob;
344
345 hex_string = lib->settings->get_str(lib->settings,
346 "%s.plugins.imc-hcd.subtypes.system.certification_state",
347 NULL, lib->ns);
348 if (hex_string)
349 {
350 blob = chunk_from_hex(chunk_from_str(hex_string), NULL);
351
352 DBG2(DBG_IMC, " %N: %B", pwg_attr_names, PWG_HCD_CERTIFICATION_STATE,
353 &blob);
354 attr = generic_attr_chunk_create(blob,
355 pen_type_create(PEN_PWG, PWG_HCD_CERTIFICATION_STATE));
356 msg->add_attribute(msg, attr);
357 chunk_free(&blob);
358 }
359 }
360
361 /**
362 * Add CertificationState attribute to send queue
363 */
364 static void add_configuration_state(imc_msg_t *msg)
365 {
366 pa_tnc_attr_t *attr;
367 char *hex_string;
368 chunk_t blob;
369
370 hex_string = lib->settings->get_str(lib->settings,
371 "%s.plugins.imc-hcd.subtypes.system.configuration_state",
372 NULL, lib->ns);
373 if (hex_string)
374 {
375 blob = chunk_from_hex(chunk_from_str(hex_string), NULL);
376
377 DBG2(DBG_IMC, " %N: %B", pwg_attr_names, PWG_HCD_CONFIGURATION_STATE,
378 &blob);
379 attr = generic_attr_chunk_create(blob,
380 pen_type_create(PEN_PWG, PWG_HCD_CONFIGURATION_STATE));
381 msg->add_attribute(msg, attr);
382 chunk_free(&blob);
383 }
384 }
385
386 /**
387 * Add Correlated Attributes to send queue
388 */
389 static void add_quadruple(imc_msg_t *msg, char *section, quadruple_t *quad)
390 {
391 pa_tnc_attr_t *attr;
392 const size_t version_len = 16;
393 char version[version_len];
394 char hex_version_default[] = "00000000000000000000000000000000";
395 char *app, *name, *patches, *string_version, *hex_version;
396 size_t len;
397 chunk_t num_version;
398 enumerator_t *enumerator;
399
400 enumerator = lib->settings->create_section_enumerator(lib->settings,
401 "%s.plugins.imc-hcd.subtypes.%s.%s",
402 lib->ns, section, quad->section);
403 while (enumerator->enumerate(enumerator, &app))
404 {
405 name = lib->settings->get_str(lib->settings,
406 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.name",
407 "", lib->ns, section, quad->section, app);
408 patches = lib->settings->get_str(lib->settings,
409 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.patches",
410 "", lib->ns, section, quad->section, app);
411 string_version = lib->settings->get_str(lib->settings,
412 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.string_version",
413 "", lib->ns, section, quad->section, app);
414 hex_version = lib->settings->get_str(lib->settings,
415 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.version",
416 hex_version_default, lib->ns, section, quad->section, app);
417
418 /* convert hex string into binary chunk */
419 if (strlen(hex_version) > 2 * version_len)
420 {
421 hex_version = hex_version_default;
422 }
423 num_version = chunk_from_hex(chunk_from_str(hex_version), version);
424
425 DBG2(DBG_IMC, "--- %s ---", app);
426
427 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, quad->name_attr, name);
428 attr = generic_attr_string_create(chunk_from_str(name),
429 pen_type_create(PEN_PWG, quad->name_attr));
430 msg->add_attribute(msg, attr);
431
432 /* remove any trailing LF from patches string for logging */
433 len = strlen(patches);
434 if (len && (patches[len - 1] == '\n'))
435 {
436 len--;
437 }
438 DBG2(DBG_IMC, " %N:%s%.*s", pwg_attr_names, quad->patches_attr,
439 len ? "\n" : " ", len, patches);
440 attr = generic_attr_string_create(chunk_from_str(patches),
441 pen_type_create(PEN_PWG, quad->patches_attr));
442 msg->add_attribute(msg, attr);
443
444 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, quad->string_version_attr,
445 string_version);
446 attr = generic_attr_string_create(chunk_from_str(string_version),
447 pen_type_create(PEN_PWG, quad->string_version_attr));
448 msg->add_attribute(msg, attr);
449
450 DBG2(DBG_IMC, " %N: %#B", pwg_attr_names, quad->version_attr, &num_version);
451 attr = generic_attr_chunk_create(num_version,
452 pen_type_create(PEN_PWG, quad->version_attr));
453 msg->add_attribute(msg, attr);
454 }
455 enumerator->destroy(enumerator);
456 }
457
458 /**
459 * see section 3.8.3 of TCG TNC IF-IMC Specification 1.3
460 */
461 TNC_Result TNC_IMC_API TNC_IMC_BeginHandshake(TNC_IMCID imc_id,
462 TNC_ConnectionID connection_id)
463 {
464 imc_state_t *state;
465 imc_msg_t *out_msg;
466 TNC_Result result = TNC_RESULT_SUCCESS;
467 pa_subtype_pwg_t subtype;
468 pen_type_t msg_type;
469 enumerator_t *enumerator;
470 char *section;
471 int i;
472
473 if (!imc_hcd)
474 {
475 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
476 return TNC_RESULT_NOT_INITIALIZED;
477 }
478 if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
479 {
480 return TNC_RESULT_FATAL;
481 }
482
483 /* Enumerate over all HCD subtype sections */
484 enumerator = lib->settings->create_section_enumerator(lib->settings,
485 "%s.plugins.imc-hcd.subtypes", lib->ns);
486 while (enumerator->enumerate(enumerator, &section) &&
487 result == TNC_RESULT_SUCCESS)
488 {
489 subtype = PA_SUBTYPE_PWG_HCD_UNKNOWN;
490
491 for (i = 0; i < countof(section_subtypes); i++)
492 {
493 if (streq(section, section_subtypes[i].section))
494 {
495 subtype = section_subtypes[i].subtype;
496 break;
497 }
498 }
499 if (subtype == PA_SUBTYPE_PWG_HCD_UNKNOWN)
500 {
501 DBG1(DBG_IMC, "HCD subtype '%s' not supported", section);
502 continue;
503 }
504 DBG2(DBG_IMC, "retrieving attributes for PA subtype %N/%N",
505 pen_names, PEN_PWG, pa_subtype_pwg_names, subtype);
506
507 msg_type = pen_type_create(PEN_PWG, subtype);
508 out_msg = imc_msg_create(imc_hcd, state, connection_id, imc_id,
509 TNC_IMVID_ANY, msg_type);
510
511 /* mandatory attributes that are always sent without request */
512 add_attrs_natural_lang(out_msg, section);
513 if (subtype == PA_SUBTYPE_PWG_HCD_SYSTEM)
514 {
515 add_default_pwd_enabled(out_msg);
516 add_forwarding_enabled(out_msg);
517 add_machine_type_model(out_msg);
518 add_pstn_fax_enabled(out_msg);
519 add_time_source(out_msg);
520 add_vendor_name(out_msg);
521 add_vendor_smi_code(out_msg);
522 add_user_app_enabled(out_msg);
523 add_user_app_persist_enabled(out_msg);
524 }
525 if (lib->settings->get_bool(lib->settings,
526 "%s.plugins.imc-hcd.push_info", FALSE, lib->ns))
527 {
528 /* correlated attributes */
529 for (i = 0; i < countof(quadruples); i++)
530 {
531 add_quadruple(out_msg, section, &quadruples[i]);
532 }
533 }
534
535 /* send PA-TNC message with the excl flag not set */
536 result = out_msg->send(out_msg, FALSE);
537 out_msg->destroy(out_msg);
538 }
539 enumerator->destroy(enumerator);
540
541 return result;
542 }
543
544 static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
545 {
546 imc_msg_t *out_msg;
547 enumerator_t *enumerator;
548 pa_tnc_attr_t *attr;
549 pen_type_t type, msg_type;
550 TNC_Result result;
551 char *section = NULL;
552 int i;
553 bool fatal_error = FALSE, pushed_info;
554
555 /* generate an outgoing PA-TNC message - we might need it */
556 out_msg = imc_msg_create_as_reply(in_msg);
557
558 /* parse received PA-TNC message and handle local and remote errors */
559 result = in_msg->receive(in_msg, out_msg, &fatal_error);
560 if (result != TNC_RESULT_SUCCESS)
561 {
562 out_msg->destroy(out_msg);
563 return result;
564 }
565 msg_type = in_msg->get_msg_type(in_msg);
566
567 for (i = 0; i < countof(section_subtypes); i++)
568 {
569 if (msg_type.type == section_subtypes[i].subtype)
570 {
571 section = section_subtypes[i].section;
572 break;
573 }
574 }
575 pushed_info = lib->settings->get_bool(lib->settings,
576 "%s.plugins.imc-hcd.push_info", FALSE, lib->ns);
577
578 /* analyze PA-TNC attributes */
579 enumerator = in_msg->create_attribute_enumerator(in_msg);
580 while (enumerator->enumerate(enumerator, &attr))
581 {
582 type = attr->get_type(attr);
583
584 if (type.vendor_id == PEN_IETF)
585 {
586 if (type.type == IETF_ATTR_ATTRIBUTE_REQUEST)
587 {
588 ietf_attr_attr_request_t *attr_cast;
589 pen_type_t *entry;
590 enumerator_t *e;
591
592 attr_cast = (ietf_attr_attr_request_t*)attr;
593
594 e = attr_cast->create_enumerator(attr_cast);
595 while (e->enumerate(e, &entry))
596 {
597 if (entry->vendor_id == PEN_PWG)
598 {
599 switch (entry->type)
600 {
601 case PWG_HCD_ATTRS_NATURAL_LANG:
602 add_attrs_natural_lang(out_msg, section);
603 break;
604 case PWG_HCD_DEFAULT_PWD_ENABLED:
605 add_default_pwd_enabled(out_msg);
606 break;
607 case PWG_HCD_FORWARDING_ENABLED:
608 add_forwarding_enabled(out_msg);
609 break;
610 case PWG_HCD_MACHINE_TYPE_MODEL:
611 add_machine_type_model(out_msg);
612 break;
613 case PWG_HCD_PSTN_FAX_ENABLED:
614 add_pstn_fax_enabled(out_msg);
615 break;
616 case PWG_HCD_TIME_SOURCE:
617 add_time_source(out_msg);
618 break;
619 case PWG_HCD_USER_APP_ENABLED:
620 add_user_app_enabled(out_msg);
621 break;
622 case PWG_HCD_USER_APP_PERSIST_ENABLED:
623 add_user_app_persist_enabled(out_msg);
624 break;
625 case PWG_HCD_VENDOR_NAME:
626 add_vendor_name(out_msg);
627 break;
628 case PWG_HCD_VENDOR_SMI_CODE:
629 add_vendor_smi_code(out_msg);
630 break;
631 case PWG_HCD_CERTIFICATION_STATE:
632 add_certification_state(out_msg);
633 break;
634 case PWG_HCD_CONFIGURATION_STATE:
635 add_configuration_state(out_msg);
636 break;
637 default:
638 if (pushed_info)
639 {
640 continue;
641 }
642 }
643
644 /* if not pushed, deliver on request */
645 switch (entry->type)
646 {
647 case PWG_HCD_FIRMWARE_NAME:
648 add_quadruple(out_msg, section, &quadruples[0]);
649 break;
650 case PWG_HCD_RESIDENT_APP_NAME:
651 add_quadruple(out_msg, section, &quadruples[1]);
652 break;
653 case PWG_HCD_USER_APP_NAME:
654 add_quadruple(out_msg, section, &quadruples[2]);
655 break;
656 default:
657 break;
658 }
659 }
660 }
661 e->destroy(e);
662 }
663 }
664 }
665 enumerator->destroy(enumerator);
666
667 if (fatal_error)
668 {
669 result = TNC_RESULT_FATAL;
670 }
671 else
672 {
673 /* send PA-TNC message with the EXCL flag set */
674 result = out_msg->send(out_msg, TRUE);
675 }
676 out_msg->destroy(out_msg);
677
678 return result;
679 }
680
681 /**
682 * see section 3.8.4 of TCG TNC IF-IMC Specification 1.3
683 */
684 TNC_Result TNC_IMC_API TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
685 TNC_ConnectionID connection_id,
686 TNC_BufferReference msg,
687 TNC_UInt32 msg_len,
688 TNC_MessageType msg_type)
689 {
690 imc_state_t *state;
691 imc_msg_t *in_msg;
692 TNC_Result result;
693
694 if (!imc_hcd)
695 {
696 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
697 return TNC_RESULT_NOT_INITIALIZED;
698 }
699 if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
700 {
701 return TNC_RESULT_FATAL;
702 }
703 in_msg = imc_msg_create_from_data(imc_hcd, state, connection_id, msg_type,
704 chunk_create(msg, msg_len));
705 result = receive_message(state, in_msg);
706 in_msg->destroy(in_msg);
707
708 return result;
709 }
710
711 /**
712 * see section 3.8.6 of TCG TNC IF-IMV Specification 1.3
713 */
714 TNC_Result TNC_IMC_API TNC_IMC_ReceiveMessageLong(TNC_IMCID imc_id,
715 TNC_ConnectionID connection_id,
716 TNC_UInt32 msg_flags,
717 TNC_BufferReference msg,
718 TNC_UInt32 msg_len,
719 TNC_VendorID msg_vid,
720 TNC_MessageSubtype msg_subtype,
721 TNC_UInt32 src_imv_id,
722 TNC_UInt32 dst_imc_id)
723 {
724 imc_state_t *state;
725 imc_msg_t *in_msg;
726 TNC_Result result;
727
728 if (!imc_hcd)
729 {
730 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
731 return TNC_RESULT_NOT_INITIALIZED;
732 }
733 if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
734 {
735 return TNC_RESULT_FATAL;
736 }
737 in_msg = imc_msg_create_from_long_data(imc_hcd, state, connection_id,
738 src_imv_id, dst_imc_id,msg_vid, msg_subtype,
739 chunk_create(msg, msg_len));
740 result =receive_message(state, in_msg);
741 in_msg->destroy(in_msg);
742
743 return result;
744 }
745
746 /**
747 * see section 3.8.7 of TCG TNC IF-IMC Specification 1.3
748 */
749 TNC_Result TNC_IMC_API TNC_IMC_BatchEnding(TNC_IMCID imc_id,
750 TNC_ConnectionID connection_id)
751 {
752 if (!imc_hcd)
753 {
754 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
755 return TNC_RESULT_NOT_INITIALIZED;
756 }
757 return TNC_RESULT_SUCCESS;
758 }
759
760 /**
761 * see section 3.8.8 of TCG TNC IF-IMC Specification 1.3
762 */
763 TNC_Result TNC_IMC_API TNC_IMC_Terminate(TNC_IMCID imc_id)
764 {
765 if (!imc_hcd)
766 {
767 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
768 return TNC_RESULT_NOT_INITIALIZED;
769 }
770 imc_hcd->destroy(imc_hcd);
771 imc_hcd = NULL;
772
773 os->destroy(os);
774 os = NULL;
775
776 return TNC_RESULT_SUCCESS;
777 }
778
779 /**
780 * see section 4.2.8.1 of TCG TNC IF-IMC Specification 1.3
781 */
782 TNC_Result TNC_IMC_API TNC_IMC_ProvideBindFunction(TNC_IMCID imc_id,
783 TNC_TNCC_BindFunctionPointer bind_function)
784 {
785 if (!imc_hcd)
786 {
787 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
788 return TNC_RESULT_NOT_INITIALIZED;
789 }
790 return imc_hcd->bind_functions(imc_hcd, bind_function);
791 }