implemented the RFC 5792 PA-TNC protocol and an example IMC/IMV pair
[strongswan.git] / src / libimcv / ietf / ietf_attr_pa_tnc_error.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "ietf_attr_pa_tnc_error.h"
16
17 #include <debug.h>
18
19 ENUM(pa_tnc_error_code_names, PA_ERROR_RESERVED,
20 PA_ERROR_ATTR_TYPE_NOT_SUPPORTED,
21 "Reserved",
22 "Invalid Parameter",
23 "Version Not Supported",
24 "Attribute Type Not Supported"
25 );
26
27 /**
28 * PA-TNC Error Attribute Type (see section 4.2.8 of RFC 5792)
29 *
30 * 1 2 3
31 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
32 *
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Reserved | PA-TNC Error Code Vendor ID |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | PA-TNC Error Code |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | Error Information (Variable Length) |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 */
41
42 typedef struct private_ietf_attr_pa_tnc_error_t private_ietf_attr_pa_tnc_error_t;
43
44 /**
45 * Private data of an ietf_attr_pa_tnc_error_t object.
46 */
47 struct private_ietf_attr_pa_tnc_error_t {
48
49 /**
50 * Public members of ietf_attr_pa_tnc_error_t
51 */
52 ietf_attr_pa_tnc_error_t public;
53
54 /**
55 * Attribute vendor ID
56 */
57 pen_t vendor_id;
58
59 /**
60 * Attribute type
61 */
62 u_int32_t type;
63
64 /**
65 * Attribute value
66 */
67 chunk_t value;
68
69 /**
70 * Noskip flag
71 */
72 bool noskip_flag;
73
74 /**
75 * Error code vendor ID
76 */
77 pen_t error_vendor_id;
78
79 /**
80 * Error code
81 */
82 u_int32_t error_code;
83
84 };
85
86 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
87 private_ietf_attr_pa_tnc_error_t *this)
88 {
89 return this->vendor_id;
90 }
91
92 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
93 private_ietf_attr_pa_tnc_error_t *this)
94 {
95 return this->type;
96 }
97
98 METHOD(pa_tnc_attr_t, get_value, chunk_t,
99 private_ietf_attr_pa_tnc_error_t *this)
100 {
101 return this->value;
102 }
103
104 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
105 private_ietf_attr_pa_tnc_error_t *this)
106 {
107 return this->noskip_flag;
108 }
109
110 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
111 private_ietf_attr_pa_tnc_error_t *this, bool noskip)
112 {
113 this->noskip_flag = noskip;
114 }
115
116 METHOD(pa_tnc_attr_t, build, void,
117 private_ietf_attr_pa_tnc_error_t *this)
118 {
119
120 }
121
122 METHOD(pa_tnc_attr_t, process, status_t,
123 private_ietf_attr_pa_tnc_error_t *this)
124 {
125 return SUCCESS;
126 }
127
128 METHOD(pa_tnc_attr_t, destroy, void,
129 private_ietf_attr_pa_tnc_error_t *this)
130 {
131 free(this);
132 }
133
134 METHOD(ietf_attr_pa_tnc_error_t, get_error_vendor_id, pen_t,
135 private_ietf_attr_pa_tnc_error_t *this)
136 {
137 return this->error_vendor_id;
138 }
139
140 METHOD(ietf_attr_pa_tnc_error_t, get_error_code, u_int32_t,
141 private_ietf_attr_pa_tnc_error_t *this)
142 {
143 return this->error_code;
144 }
145
146 /**
147 * Described in header.
148 */
149 pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id,
150 u_int32_t error_code)
151 {
152 private_ietf_attr_pa_tnc_error_t *this;
153
154 INIT(this,
155 .public = {
156 .pa_tnc_attribute = {
157 .get_vendor_id = _get_vendor_id,
158 .get_type = _get_type,
159 .get_value = _get_value,
160 .get_noskip_flag = _get_noskip_flag,
161 .set_noskip_flag = _set_noskip_flag,
162 .build = _build,
163 .process = _process,
164 .destroy = _destroy,
165 },
166 .get_vendor_id = _get_error_vendor_id,
167 .get_error_code = _get_error_code,
168 },
169 .vendor_id = PEN_IETF,
170 .type = IETF_ATTR_PA_TNC_ERROR,
171 .error_vendor_id = vendor_id,
172 .error_code = error_code,
173 );
174
175 return &this->public.pa_tnc_attribute;
176 }
177
178 /**
179 * Described in header.
180 */
181 pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_from_data(chunk_t data)
182 {
183 private_ietf_attr_pa_tnc_error_t *this;
184
185 INIT(this,
186 .public = {
187 .pa_tnc_attribute = {
188 .get_vendor_id = _get_vendor_id,
189 .get_type = _get_type,
190 .get_value = _get_value,
191 .build = _build,
192 .process = _process,
193 .destroy = _destroy,
194 },
195 .get_vendor_id = _get_error_vendor_id,
196 .get_error_code = _get_error_code,
197 },
198 .vendor_id = PEN_IETF,
199 .type = IETF_ATTR_PA_TNC_ERROR,
200 .value = chunk_clone(data),
201 );
202
203 return &this->public.pa_tnc_attribute;
204 }
205
206