Use PWG HCD PA-TNC subtypes to transport HCD attributes
[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, *pos, *string_version, *hex_version;
396 chunk_t num_version;
397 enumerator_t *enumerator;
398
399 enumerator = lib->settings->create_section_enumerator(lib->settings,
400 "%s.plugins.imc-hcd.subtypes.%s.%s",
401 lib->ns, section, quad->section);
402 while (enumerator->enumerate(enumerator, &app))
403 {
404 name = lib->settings->get_str(lib->settings,
405 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.name",
406 "", lib->ns, section, quad->section, app);
407 patches = lib->settings->get_str(lib->settings,
408 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.patches",
409 "", lib->ns, section, quad->section, app);
410 string_version = lib->settings->get_str(lib->settings,
411 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.string_version",
412 "", lib->ns, section, quad->section, app);
413 hex_version = lib->settings->get_str(lib->settings,
414 "%s.plugins.imc-hcd.subtypes.%s.%s.%s.version",
415 hex_version_default, lib->ns, section, quad->section, app);
416
417 /* replace \n escape character by CRLF */
418 pos = patches;
419 while (TRUE)
420 {
421 pos = strchr(pos, '\\');
422 if (pos == NULL)
423 {
424 break;
425 }
426 if (pos[1] == 'n')
427 {
428 pos[0] = '\r';
429 pos[1] = '\n';
430 pos++;
431 }
432 pos++;
433 }
434
435 /* convert hex string into binary chunk */
436 if (strlen(hex_version) > 2 * version_len)
437 {
438 hex_version = hex_version_default;
439 }
440 num_version = chunk_from_hex(chunk_from_str(hex_version), version);
441
442 DBG2(DBG_IMC, "--- %s ---", app);
443
444 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, quad->name_attr, name);
445 attr = generic_attr_string_create(chunk_from_str(name),
446 pen_type_create(PEN_PWG, quad->name_attr));
447 msg->add_attribute(msg, attr);
448
449 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, quad->patches_attr, patches);
450 attr = generic_attr_string_create(chunk_from_str(patches),
451 pen_type_create(PEN_PWG, quad->patches_attr));
452 msg->add_attribute(msg, attr);
453
454 DBG2(DBG_IMC, " %N: %s", pwg_attr_names, quad->string_version_attr,
455 string_version);
456 attr = generic_attr_string_create(chunk_from_str(string_version),
457 pen_type_create(PEN_PWG, quad->string_version_attr));
458 msg->add_attribute(msg, attr);
459
460 DBG2(DBG_IMC, " %N: %#B", pwg_attr_names, quad->version_attr, &num_version);
461 attr = generic_attr_chunk_create(num_version,
462 pen_type_create(PEN_PWG, quad->version_attr));
463 msg->add_attribute(msg, attr);
464 }
465 enumerator->destroy(enumerator);
466 }
467
468 /**
469 * see section 3.8.3 of TCG TNC IF-IMC Specification 1.3
470 */
471 TNC_Result TNC_IMC_API TNC_IMC_BeginHandshake(TNC_IMCID imc_id,
472 TNC_ConnectionID connection_id)
473 {
474 imc_state_t *state;
475 imc_msg_t *out_msg;
476 TNC_Result result = TNC_RESULT_SUCCESS;
477 pa_subtype_pwg_t subtype;
478 pen_type_t msg_type;
479 enumerator_t *enumerator;
480 char *section;
481 int i;
482
483 if (!imc_hcd)
484 {
485 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
486 return TNC_RESULT_NOT_INITIALIZED;
487 }
488 if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
489 {
490 return TNC_RESULT_FATAL;
491 }
492
493 /* Enumerate over all HCD subtype sections */
494 enumerator = lib->settings->create_section_enumerator(lib->settings,
495 "%s.plugins.imc-hcd.subtypes", lib->ns);
496 while (enumerator->enumerate(enumerator, &section) &&
497 result == TNC_RESULT_SUCCESS)
498 {
499 subtype = PA_SUBTYPE_PWG_HCD_UNKNOWN;
500
501 for (i = 0; i < countof(section_subtypes); i++)
502 {
503 if (streq(section, section_subtypes[i].section))
504 {
505 subtype = section_subtypes[i].subtype;
506 break;
507 }
508 }
509 if (subtype == PA_SUBTYPE_PWG_HCD_UNKNOWN)
510 {
511 DBG1(DBG_IMC, "HCD subtype '%s' not supported", section);
512 continue;
513 }
514 DBG2(DBG_IMC, "retrieving attributes for PA subtype %N/%N",
515 pen_names, PEN_PWG, pa_subtype_pwg_names, subtype);
516
517 msg_type = pen_type_create(PEN_PWG, subtype);
518 out_msg = imc_msg_create(imc_hcd, state, connection_id, imc_id,
519 TNC_IMVID_ANY, msg_type);
520
521 /* mandatory attributes that are always sent without request */
522 add_attrs_natural_lang(out_msg, section);
523 if (subtype == PA_SUBTYPE_PWG_HCD_SYSTEM)
524 {
525 add_default_pwd_enabled(out_msg);
526 add_forwarding_enabled(out_msg);
527 add_machine_type_model(out_msg);
528 add_pstn_fax_enabled(out_msg);
529 add_time_source(out_msg);
530 add_vendor_name(out_msg);
531 add_vendor_smi_code(out_msg);
532 add_user_app_enabled(out_msg);
533 add_user_app_persist_enabled(out_msg);
534 }
535 if (lib->settings->get_bool(lib->settings,
536 "%s.plugins.imc-hcd.push_info", FALSE, lib->ns))
537 {
538 /* correlated attributes */
539 for (i = 0; i < countof(quadruples); i++)
540 {
541 add_quadruple(out_msg, section, &quadruples[i]);
542 }
543 }
544
545 /* send PA-TNC message with the excl flag not set */
546 result = out_msg->send(out_msg, FALSE);
547 out_msg->destroy(out_msg);
548 }
549 enumerator->destroy(enumerator);
550
551 return result;
552 }
553
554 static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
555 {
556 imc_msg_t *out_msg;
557 enumerator_t *enumerator;
558 pa_tnc_attr_t *attr;
559 pen_type_t type, msg_type;
560 TNC_Result result;
561 char *section = NULL;
562 int i;
563 bool fatal_error = FALSE, pushed_info;
564
565 /* generate an outgoing PA-TNC message - we might need it */
566 out_msg = imc_msg_create_as_reply(in_msg);
567
568 /* parse received PA-TNC message and handle local and remote errors */
569 result = in_msg->receive(in_msg, out_msg, &fatal_error);
570 if (result != TNC_RESULT_SUCCESS)
571 {
572 out_msg->destroy(out_msg);
573 return result;
574 }
575 msg_type = in_msg->get_msg_type(in_msg);
576
577 for (i = 0; i < countof(section_subtypes); i++)
578 {
579 if (msg_type.type == section_subtypes[i].subtype)
580 {
581 section = section_subtypes[i].section;
582 break;
583 }
584 }
585 pushed_info = lib->settings->get_bool(lib->settings,
586 "%s.plugins.imc-hcd.push_info", FALSE, lib->ns);
587
588 /* analyze PA-TNC attributes */
589 enumerator = in_msg->create_attribute_enumerator(in_msg);
590 while (enumerator->enumerate(enumerator, &attr))
591 {
592 type = attr->get_type(attr);
593
594 if (type.vendor_id == PEN_IETF)
595 {
596 if (type.type == IETF_ATTR_ATTRIBUTE_REQUEST)
597 {
598 ietf_attr_attr_request_t *attr_cast;
599 pen_type_t *entry;
600 enumerator_t *e;
601
602 attr_cast = (ietf_attr_attr_request_t*)attr;
603
604 e = attr_cast->create_enumerator(attr_cast);
605 while (e->enumerate(e, &entry))
606 {
607 if (entry->vendor_id == PEN_PWG)
608 {
609 switch (entry->type)
610 {
611 case PWG_HCD_ATTRS_NATURAL_LANG:
612 add_attrs_natural_lang(out_msg, section);
613 break;
614 case PWG_HCD_DEFAULT_PWD_ENABLED:
615 add_default_pwd_enabled(out_msg);
616 break;
617 case PWG_HCD_FORWARDING_ENABLED:
618 add_forwarding_enabled(out_msg);
619 break;
620 case PWG_HCD_MACHINE_TYPE_MODEL:
621 add_machine_type_model(out_msg);
622 break;
623 case PWG_HCD_PSTN_FAX_ENABLED:
624 add_pstn_fax_enabled(out_msg);
625 break;
626 case PWG_HCD_TIME_SOURCE:
627 add_time_source(out_msg);
628 break;
629 case PWG_HCD_USER_APP_ENABLED:
630 add_user_app_enabled(out_msg);
631 break;
632 case PWG_HCD_USER_APP_PERSIST_ENABLED:
633 add_user_app_persist_enabled(out_msg);
634 break;
635 case PWG_HCD_VENDOR_NAME:
636 add_vendor_name(out_msg);
637 break;
638 case PWG_HCD_VENDOR_SMI_CODE:
639 add_vendor_smi_code(out_msg);
640 break;
641 case PWG_HCD_CERTIFICATION_STATE:
642 add_certification_state(out_msg);
643 break;
644 case PWG_HCD_CONFIGURATION_STATE:
645 add_configuration_state(out_msg);
646 break;
647 default:
648 if (pushed_info)
649 {
650 continue;
651 }
652 }
653
654 /* if not pushed, deliver on request */
655 switch (entry->type)
656 {
657 case PWG_HCD_FIRMWARE_NAME:
658 add_quadruple(out_msg, section, &quadruples[0]);
659 break;
660 case PWG_HCD_RESIDENT_APP_NAME:
661 add_quadruple(out_msg, section, &quadruples[1]);
662 break;
663 case PWG_HCD_USER_APP_NAME:
664 add_quadruple(out_msg, section, &quadruples[2]);
665 break;
666 default:
667 break;
668 }
669 }
670 }
671 e->destroy(e);
672 }
673 }
674 }
675 enumerator->destroy(enumerator);
676
677 if (fatal_error)
678 {
679 result = TNC_RESULT_FATAL;
680 }
681 else
682 {
683 /* send PA-TNC message with the EXCL flag set */
684 result = out_msg->send(out_msg, TRUE);
685 }
686 out_msg->destroy(out_msg);
687
688 return result;
689 }
690
691 /**
692 * see section 3.8.4 of TCG TNC IF-IMC Specification 1.3
693 */
694 TNC_Result TNC_IMC_API TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
695 TNC_ConnectionID connection_id,
696 TNC_BufferReference msg,
697 TNC_UInt32 msg_len,
698 TNC_MessageType msg_type)
699 {
700 imc_state_t *state;
701 imc_msg_t *in_msg;
702 TNC_Result result;
703
704 if (!imc_hcd)
705 {
706 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
707 return TNC_RESULT_NOT_INITIALIZED;
708 }
709 if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
710 {
711 return TNC_RESULT_FATAL;
712 }
713 in_msg = imc_msg_create_from_data(imc_hcd, state, connection_id, msg_type,
714 chunk_create(msg, msg_len));
715 result = receive_message(state, in_msg);
716 in_msg->destroy(in_msg);
717
718 return result;
719 }
720
721 /**
722 * see section 3.8.6 of TCG TNC IF-IMV Specification 1.3
723 */
724 TNC_Result TNC_IMC_API TNC_IMC_ReceiveMessageLong(TNC_IMCID imc_id,
725 TNC_ConnectionID connection_id,
726 TNC_UInt32 msg_flags,
727 TNC_BufferReference msg,
728 TNC_UInt32 msg_len,
729 TNC_VendorID msg_vid,
730 TNC_MessageSubtype msg_subtype,
731 TNC_UInt32 src_imv_id,
732 TNC_UInt32 dst_imc_id)
733 {
734 imc_state_t *state;
735 imc_msg_t *in_msg;
736 TNC_Result result;
737
738 if (!imc_hcd)
739 {
740 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
741 return TNC_RESULT_NOT_INITIALIZED;
742 }
743 if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
744 {
745 return TNC_RESULT_FATAL;
746 }
747 in_msg = imc_msg_create_from_long_data(imc_hcd, state, connection_id,
748 src_imv_id, dst_imc_id,msg_vid, msg_subtype,
749 chunk_create(msg, msg_len));
750 result =receive_message(state, in_msg);
751 in_msg->destroy(in_msg);
752
753 return result;
754 }
755
756 /**
757 * see section 3.8.7 of TCG TNC IF-IMC Specification 1.3
758 */
759 TNC_Result TNC_IMC_API TNC_IMC_BatchEnding(TNC_IMCID imc_id,
760 TNC_ConnectionID connection_id)
761 {
762 if (!imc_hcd)
763 {
764 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
765 return TNC_RESULT_NOT_INITIALIZED;
766 }
767 return TNC_RESULT_SUCCESS;
768 }
769
770 /**
771 * see section 3.8.8 of TCG TNC IF-IMC Specification 1.3
772 */
773 TNC_Result TNC_IMC_API TNC_IMC_Terminate(TNC_IMCID imc_id)
774 {
775 if (!imc_hcd)
776 {
777 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
778 return TNC_RESULT_NOT_INITIALIZED;
779 }
780 imc_hcd->destroy(imc_hcd);
781 imc_hcd = NULL;
782
783 os->destroy(os);
784 os = NULL;
785
786 return TNC_RESULT_SUCCESS;
787 }
788
789 /**
790 * see section 4.2.8.1 of TCG TNC IF-IMC Specification 1.3
791 */
792 TNC_Result TNC_IMC_API TNC_IMC_ProvideBindFunction(TNC_IMCID imc_id,
793 TNC_TNCC_BindFunctionPointer bind_function)
794 {
795 if (!imc_hcd)
796 {
797 DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
798 return TNC_RESULT_NOT_INITIALIZED;
799 }
800 return imc_hcd->bind_functions(imc_hcd, bind_function);
801 }