Completed implementation of PWG HCD attributes
[strongswan.git] / src / libimcv / pwg / pwg_attr.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 "pwg_attr.h"
17
18 #include "generic/generic_attr_bool.h"
19 #include "generic/generic_attr_chunk.h"
20 #include "generic/generic_attr_string.h"
21 #include "ietf/ietf_attr_port_filter.h"
22 #include "pwg/pwg_attr_vendor_smi_code.h"
23
24 ENUM_BEGIN(pwg_attr_names, PWG_HCD_ATTRS_NATURAL_LANG,
25 PWG_HCD_VENDOR_SMI_CODE,
26 "HCD AttributesNaturalLanguage",
27 "HCD MachineTypeModel",
28 "HCD VendorName",
29 "HCD VendorSMICode");
30 ENUM_NEXT(pwg_attr_names, PWG_HCD_DEFAULT_PWD_ENABLED,
31 PWG_HCD_FORWARDING_ENABLED,
32 PWG_HCD_VENDOR_SMI_CODE,
33 "HCD DefaultPasswordEnabled",
34 "HCD FirewallSetting",
35 "HCD ForwardingEnabled");
36 ENUM_NEXT(pwg_attr_names, PWG_HCD_PSTN_FAX_ENABLED,
37 PWG_HCD_PSTN_FAX_ENABLED,
38 PWG_HCD_FORWARDING_ENABLED,
39 "HCD PSTNFaxEnabled");
40 ENUM_NEXT(pwg_attr_names, PWG_HCD_TIME_SOURCE,
41 PWG_HCD_TIME_SOURCE,
42 PWG_HCD_PSTN_FAX_ENABLED,
43 "HCD TimeSource");
44 ENUM_NEXT(pwg_attr_names, PWG_HCD_FIRMWARE_NAME,
45 PWG_HCD_FIRMWARE_VERSION,
46 PWG_HCD_TIME_SOURCE,
47 "HCD FirmwareName",
48 "HCD FirmwarePatches",
49 "HCD FirmwareStringVersion",
50 "HCD FirmwareVersion");
51 ENUM_NEXT(pwg_attr_names, PWG_HCD_RESIDENT_APP_NAME,
52 PWG_HCD_RESIDENT_APP_VERSION,
53 PWG_HCD_FIRMWARE_VERSION,
54 "HCD ResidentApplicationName",
55 "HCD ResidentApplicationPatches",
56 "HCD ResidentApplicationStringVersion",
57 "HCD ResidentApplicationVersion");
58 ENUM_NEXT(pwg_attr_names, PWG_HCD_USER_APP_NAME,
59 PWG_HCD_USER_APP_PERSIST_ENABLED,
60 PWG_HCD_RESIDENT_APP_VERSION,
61 "HCD UserApplicationName",
62 "HCD UserApplicationPatches",
63 "HCD UserApplicationStringVersion",
64 "HCD UserApplicationVersion",
65 "HCD UserApplicationEnabled",
66 "HCD UserApplicationPersistenceEnabled");
67 ENUM_NEXT(pwg_attr_names, PWG_HCD_CERTIFICATION_STATE,
68 PWG_HCD_CONFIGURATION_STATE,
69 PWG_HCD_USER_APP_PERSIST_ENABLED,
70 "HCD CertificationState",
71 "HCD ConfigurationState");
72 ENUM_END(pwg_attr_names, PWG_HCD_CONFIGURATION_STATE);
73
74 /**
75 * See header
76 */
77 pa_tnc_attr_t* pwg_attr_create_from_data(u_int32_t type, size_t length, chunk_t value)
78 {
79 switch (type)
80 {
81 case PWG_HCD_DEFAULT_PWD_ENABLED:
82 case PWG_HCD_FORWARDING_ENABLED:
83 case PWG_HCD_USER_APP_ENABLED:
84 case PWG_HCD_USER_APP_PERSIST_ENABLED:
85 case PWG_HCD_PSTN_FAX_ENABLED:
86 return generic_attr_bool_create_from_data(length, value,
87 pen_type_create(PEN_PWG, type));
88 case PWG_HCD_ATTRS_NATURAL_LANG:
89 case PWG_HCD_MACHINE_TYPE_MODEL:
90 case PWG_HCD_VENDOR_NAME:
91 case PWG_HCD_FIRMWARE_NAME:
92 case PWG_HCD_FIRMWARE_PATCHES:
93 case PWG_HCD_FIRMWARE_STRING_VERSION:
94 case PWG_HCD_TIME_SOURCE:
95 case PWG_HCD_USER_APP_NAME:
96 case PWG_HCD_USER_APP_PATCHES:
97 case PWG_HCD_USER_APP_STRING_VERSION:
98 case PWG_HCD_RESIDENT_APP_NAME:
99 case PWG_HCD_RESIDENT_APP_PATCHES:
100 case PWG_HCD_RESIDENT_APP_STRING_VERSION:
101 return generic_attr_string_create_from_data(length, value,
102 pen_type_create(PEN_PWG, type));
103 case PWG_HCD_FIRMWARE_VERSION:
104 case PWG_HCD_RESIDENT_APP_VERSION:
105 case PWG_HCD_USER_APP_VERSION:
106 return generic_attr_chunk_create_from_data(length, value, 16,
107 pen_type_create(PEN_PWG, type));
108 case PWG_HCD_CERTIFICATION_STATE:
109 case PWG_HCD_CONFIGURATION_STATE:
110 return generic_attr_chunk_create_from_data(length, value, 0,
111 pen_type_create(PEN_PWG, type));
112 case PWG_HCD_VENDOR_SMI_CODE:
113 return pwg_attr_vendor_smi_code_create_from_data(length, value);
114 case PWG_HCD_FIREWALL_SETTING:
115 return ietf_attr_port_filter_create_from_data(length, value,
116 pen_type_create(PEN_PWG, type));
117 default:
118 return NULL;
119 }
120 }