Added tnc/tnccs-20-fail-init and tnc/tnccs-20-fail-resp scenarios
[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_NOSKIP_TEST,
47 PB_ITA_MSG_MUTUAL_CAPABILITY,
48 "PB-Noskip-Test",
49 "PB-Mutual-Capability"
50 );
51
52 pb_tnc_msg_info_t pb_tnc_msg_infos[] = {
53 { 12, FALSE, FALSE, TRUE_OR_FALSE },
54 { 24, FALSE, FALSE, TRUE },
55 { 16, TRUE, TRUE, TRUE },
56 { 16, TRUE, TRUE, FALSE },
57 { 20, FALSE, TRUE, FALSE },
58 { 20, FALSE, FALSE, TRUE },
59 { 12, FALSE, FALSE, FALSE },
60 { 17, FALSE, TRUE, FALSE },
61 };
62
63 pb_tnc_msg_info_t pb_tnc_tcg_msg_infos[] = {
64 { 0 }, /* dummy entry because pb_tnc_tcg_msg_type_t starts with 1 */
65 { 20, FALSE, FALSE, FALSE },
66 };
67
68 pb_tnc_msg_info_t pb_tnc_ita_msg_infos[] = {
69 { 12, TRUE, FALSE, TRUE },
70 { 16, FALSE, FALSE, FALSE },
71 };
72
73 /**
74 * See header
75 */
76 pb_tnc_msg_t* pb_tnc_msg_create_from_data(pen_type_t msg_type, chunk_t value)
77 {
78 if (msg_type.vendor_id == PEN_IETF)
79 {
80 switch (msg_type.type)
81 {
82 case PB_MSG_PA:
83 return pb_pa_msg_create_from_data(value);
84 case PB_MSG_ERROR:
85 return pb_error_msg_create_from_data(value);
86 case PB_MSG_EXPERIMENTAL:
87 return pb_experimental_msg_create_from_data(value);
88 case PB_MSG_LANGUAGE_PREFERENCE:
89 return pb_language_preference_msg_create_from_data(value);
90 case PB_MSG_ASSESSMENT_RESULT:
91 return pb_assessment_result_msg_create_from_data(value);
92 case PB_MSG_ACCESS_RECOMMENDATION:
93 return pb_access_recommendation_msg_create_from_data(value);
94 case PB_MSG_REMEDIATION_PARAMETERS:
95 return pb_remediation_parameters_msg_create_from_data(value);
96 case PB_MSG_REASON_STRING:
97 return pb_reason_string_msg_create_from_data(value);
98 }
99 }
100 else if (msg_type.vendor_id == PEN_TCG)
101 {
102 if (msg_type.type == PB_TCG_MSG_PDP_REFERRAL)
103 {
104 return pb_pdp_referral_msg_create_from_data(value);
105 }
106 }
107 else if (msg_type.vendor_id == PEN_ITA)
108 {
109 if (msg_type.type == PB_ITA_MSG_MUTUAL_CAPABILITY)
110 {
111 return pb_mutual_capability_msg_create_from_data(value);
112 }
113 }
114 return NULL;
115 }