9562dee9262ea57bbdd38e939dba1f35840ba3f2
[strongswan.git] / src / libtnccs / plugins / tnccs_20 / messages / pb_tnc_msg.c
1 /*
2 * Copyright (C) 2010 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 "pb_tnc_msg.h"
17 #include "ietf/pb_experimental_msg.h"
18 #include "ietf/pb_pa_msg.h"
19 #include "ietf/pb_error_msg.h"
20 #include "ietf/pb_language_preference_msg.h"
21 #include "ietf/pb_assessment_result_msg.h"
22 #include "ietf/pb_access_recommendation_msg.h"
23 #include "ietf/pb_remediation_parameters_msg.h"
24 #include "ietf/pb_reason_string_msg.h"
25 #include "ita/pb_mutual_capability_msg.h"
26 #include "tcg/pb_pdp_referral_msg.h"
27
28 #include <library.h>
29
30 ENUM(pb_tnc_msg_type_names, PB_MSG_EXPERIMENTAL, PB_MSG_REASON_STRING,
31 "PB-Experimental",
32 "PB-PA",
33 "PB-Assessment-Result",
34 "PB-Access-Recommendation",
35 "PB-Remediation-Parameters",
36 "PB-Error",
37 "PB-Language-Preference",
38 "PB-Reason-String"
39 );
40
41 ENUM(pb_tnc_tcg_msg_type_names, PB_TCG_MSG_PDP_REFERRAL,
42 PB_TCG_MSG_PDP_REFERRAL,
43 "PB-PDP-Referral"
44 );
45
46 ENUM(pb_tnc_ita_msg_type_names, PB_ITA_MSG_MUTUAL_CAPABILITY,
47 PB_ITA_MSG_MUTUAL_CAPABILITY,
48 "PB-Mutual-Capability"
49 );
50
51 pb_tnc_msg_info_t pb_tnc_msg_infos[] = {
52 { 12, FALSE, FALSE, TRUE_OR_FALSE },
53 { 24, FALSE, FALSE, TRUE },
54 { 16, TRUE, TRUE, TRUE },
55 { 16, TRUE, TRUE, FALSE },
56 { 20, FALSE, TRUE, FALSE },
57 { 20, FALSE, FALSE, TRUE },
58 { 12, FALSE, FALSE, FALSE },
59 { 17, FALSE, TRUE, FALSE },
60 };
61
62 pb_tnc_msg_info_t pb_tnc_tcg_msg_infos[] = {
63 { 0 }, /* dummy entry because pb_tnc_tcg_msg_type_t starts with 1 */
64 { 20, FALSE, FALSE, FALSE },
65 };
66
67 pb_tnc_msg_info_t pb_tnc_ita_msg_infos[] = {
68 { 0 }, /* dummy entry because pb_tnc_ita_msg_type_t starts with 1 */
69 { 16, FALSE, FALSE, FALSE },
70 };
71
72 /**
73 * See header
74 */
75 pb_tnc_msg_t* pb_tnc_msg_create_from_data(pen_type_t msg_type, chunk_t value)
76 {
77 if (msg_type.vendor_id == PEN_IETF)
78 {
79 switch (msg_type.type)
80 {
81 case PB_MSG_PA:
82 return pb_pa_msg_create_from_data(value);
83 case PB_MSG_ERROR:
84 return pb_error_msg_create_from_data(value);
85 case PB_MSG_EXPERIMENTAL:
86 return pb_experimental_msg_create_from_data(value);
87 case PB_MSG_LANGUAGE_PREFERENCE:
88 return pb_language_preference_msg_create_from_data(value);
89 case PB_MSG_ASSESSMENT_RESULT:
90 return pb_assessment_result_msg_create_from_data(value);
91 case PB_MSG_ACCESS_RECOMMENDATION:
92 return pb_access_recommendation_msg_create_from_data(value);
93 case PB_MSG_REMEDIATION_PARAMETERS:
94 return pb_remediation_parameters_msg_create_from_data(value);
95 case PB_MSG_REASON_STRING:
96 return pb_reason_string_msg_create_from_data(value);
97 }
98 }
99 else if (msg_type.vendor_id == PEN_TCG)
100 {
101 if (msg_type.type == PB_TCG_MSG_PDP_REFERRAL)
102 {
103 return pb_pdp_referral_msg_create_from_data(value);
104 }
105 }
106 else if (msg_type.vendor_id == PEN_ITA)
107 {
108 if (msg_type.type == PB_ITA_MSG_MUTUAL_CAPABILITY)
109 {
110 return pb_mutual_capability_msg_create_from_data(value);
111 }
112 }
113 return NULL;
114 }