Defined functional components within ITA namespace
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_req_funct_comp_evid.c
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
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 "tcg_pts_attr_req_funct_comp_evid.h"
17
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <debug.h>
22
23 typedef struct private_tcg_pts_attr_req_funct_comp_evid_t private_tcg_pts_attr_req_funct_comp_evid_t;
24
25 /**
26 * Request Functional Component Evidence
27 * see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification
28 *
29 * 1 2 3
30 * 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
31 *
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Flags | Sub-component Depth |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Component Functional Name |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 *
38 */
39
40 /**
41 * Component Functional Name Structure (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
42 *
43 * 1 2 3
44 * 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
45 *
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Component Functional Name Vendor ID |Fam| Qualifier |
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | Component Functional Name |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 *
52 */
53
54 /**
55 * Qualifier for Functional Component
56 * see section 5.2 of PTS Protocol: Binding to TNC IF-M Specification
57 *
58 *
59 * 0 1 2 3 4 5
60 * +-+-+-+-+-+-+
61 * |K|S| Type |
62 * +-+-+-+-+-+-+
63 */
64
65 #define PTS_REQ_FUNCT_COMP_EVID_SIZE 12
66 #define PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM 0x00
67
68 /**
69 * Private data of an tcg_pts_attr_req_funct_comp_evid_t object.
70 */
71 struct private_tcg_pts_attr_req_funct_comp_evid_t {
72
73 /**
74 * Public members of tcg_pts_attr_req_funct_comp_evid_t
75 */
76 tcg_pts_attr_req_funct_comp_evid_t public;
77
78 /**
79 * Attribute vendor ID
80 */
81 pen_t vendor_id;
82
83 /**
84 * Attribute type
85 */
86 u_int32_t type;
87
88 /**
89 * Attribute value
90 */
91 chunk_t value;
92
93 /**
94 * Noskip flag
95 */
96 bool noskip_flag;
97
98 /**
99 * Set of flags for Request Functional Component
100 */
101 pts_attr_req_funct_comp_evid_flag_t flags;
102
103 /**
104 * Sub-component Depth
105 */
106 u_int32_t depth;
107
108 /**
109 * Component Functional Name Vendor ID
110 */
111 u_int32_t comp_vendor_id;
112
113 /**
114 * Functional Name Encoding Family
115 */
116 u_int8_t family;
117
118 /**
119 * Functional Name Category Qualifier
120 */
121 pts_qualifier_t qualifier;
122
123 /**
124 * Component Functional Name
125 */
126 pts_ita_funct_comp_name_t name;
127 };
128
129 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
130 private_tcg_pts_attr_req_funct_comp_evid_t *this)
131 {
132 return this->vendor_id;
133 }
134
135 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
136 private_tcg_pts_attr_req_funct_comp_evid_t *this)
137 {
138 return this->type;
139 }
140
141 METHOD(pa_tnc_attr_t, get_value, chunk_t,
142 private_tcg_pts_attr_req_funct_comp_evid_t *this)
143 {
144 return this->value;
145 }
146
147 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
148 private_tcg_pts_attr_req_funct_comp_evid_t *this)
149 {
150 return this->noskip_flag;
151 }
152
153 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
154 private_tcg_pts_attr_req_funct_comp_evid_t *this, bool noskip)
155 {
156 this->noskip_flag = noskip;
157 }
158
159 METHOD(pa_tnc_attr_t, build, void,
160 private_tcg_pts_attr_req_funct_comp_evid_t *this)
161 {
162 bio_writer_t *writer;
163 u_int8_t qualifier = 0;
164
165 writer = bio_writer_create(PTS_REQ_FUNCT_COMP_EVID_SIZE);
166
167 writer->write_uint8(writer, this->flags);
168 writer->write_uint24 (writer, this->depth);
169 writer->write_uint24 (writer, this->comp_vendor_id);
170
171 if (this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
172 {
173 DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
174 }
175
176 qualifier += this->qualifier.type;
177 if (this->qualifier.kernel)
178 {
179 qualifier += 16;
180 }
181 if (this->qualifier.sub_component)
182 {
183 qualifier += 32;
184 }
185 writer->write_uint8 (writer, qualifier);
186 writer->write_uint32 (writer, this->name);
187
188 this->value = chunk_clone(writer->get_buf(writer));
189 writer->destroy(writer);
190 }
191
192 METHOD(pa_tnc_attr_t, process, status_t,
193 private_tcg_pts_attr_req_funct_comp_evid_t *this, u_int32_t *offset)
194 {
195 bio_reader_t *reader;
196 u_int8_t flags;
197 u_int8_t fam_and_qualifier;
198
199 if (this->value.len < PTS_REQ_FUNCT_COMP_EVID_SIZE)
200 {
201 DBG1(DBG_TNC, "insufficient data for Request Functional Component Evidence");
202 *offset = 0;
203 return FAILED;
204 }
205 reader = bio_reader_create(this->value);
206
207 reader->read_uint8(reader, &flags);
208 this->flags = flags;
209
210 reader->read_uint24(reader, &this->depth);
211 reader->read_uint24(reader, &this->comp_vendor_id);
212 reader->read_uint8(reader, &fam_and_qualifier);
213
214 if (((fam_and_qualifier >> 6) & 1) )
215 {
216 this->family += 1;
217 }
218 if (((fam_and_qualifier >> 7) & 1) )
219 {
220 this->family += 2;
221 }
222
223 if (((fam_and_qualifier >> 5) & 1) )
224 {
225 this->qualifier.kernel = true;
226 }
227 if (((fam_and_qualifier >> 4) & 1) )
228 {
229 this->qualifier.sub_component = true;
230 }
231 this->qualifier.type = ( fam_and_qualifier & 0xF );
232 reader->read_uint32(reader, &this->name);
233
234 reader->destroy(reader);
235 return SUCCESS;
236 }
237
238 METHOD(pa_tnc_attr_t, destroy, void,
239 private_tcg_pts_attr_req_funct_comp_evid_t *this)
240 {
241 free(this->value.ptr);
242 free(this);
243 }
244
245 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_flags, pts_attr_req_funct_comp_evid_flag_t,
246 private_tcg_pts_attr_req_funct_comp_evid_t *this)
247 {
248 return this->flags;
249 }
250
251 METHOD(tcg_pts_attr_req_funct_comp_evid_t, set_flags, void,
252 private_tcg_pts_attr_req_funct_comp_evid_t *this, pts_attr_req_funct_comp_evid_flag_t flags)
253 {
254 this->flags = flags;
255 }
256
257 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_sub_component_depth, u_int32_t,
258 private_tcg_pts_attr_req_funct_comp_evid_t *this)
259 {
260 return this->depth;
261 }
262
263 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_comp_funct_name_vendor_id, u_int32_t,
264 private_tcg_pts_attr_req_funct_comp_evid_t *this)
265 {
266 return this->comp_vendor_id;
267 }
268
269 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_family, u_int8_t,
270 private_tcg_pts_attr_req_funct_comp_evid_t *this)
271 {
272 return this->family;
273 }
274
275 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_qualifier, pts_qualifier_t,
276 private_tcg_pts_attr_req_funct_comp_evid_t *this)
277 {
278 return this->qualifier;
279 }
280
281 METHOD(tcg_pts_attr_req_funct_comp_evid_t, set_qualifier, void,
282 private_tcg_pts_attr_req_funct_comp_evid_t *this, pts_qualifier_t qualifier)
283 {
284 this->qualifier = qualifier;
285 }
286
287 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_comp_funct_name, pts_ita_funct_comp_name_t,
288 private_tcg_pts_attr_req_funct_comp_evid_t *this)
289 {
290 return this->name;
291 }
292
293 METHOD(tcg_pts_attr_req_funct_comp_evid_t, set_comp_funct_name, void,
294 private_tcg_pts_attr_req_funct_comp_evid_t *this, pts_ita_funct_comp_name_t name)
295 {
296 this->name = name;
297 }
298
299 /**
300 * Described in header.
301 */
302 pa_tnc_attr_t *tcg_pts_attr_req_funct_comp_evid_create(
303 pts_attr_req_funct_comp_evid_flag_t flags,
304 u_int32_t depth, u_int32_t vendor_id,
305 pts_qualifier_t qualifier,
306 pts_ita_funct_comp_name_t name)
307 {
308 private_tcg_pts_attr_req_funct_comp_evid_t *this;
309
310 INIT(this,
311 .public = {
312 .pa_tnc_attribute = {
313 .get_vendor_id = _get_vendor_id,
314 .get_type = _get_type,
315 .get_value = _get_value,
316 .get_noskip_flag = _get_noskip_flag,
317 .set_noskip_flag = _set_noskip_flag,
318 .build = _build,
319 .process = _process,
320 .destroy = _destroy,
321 },
322 .get_flags= _get_flags,
323 .set_flags= _set_flags,
324 .get_sub_component_depth = _get_sub_component_depth,
325 .get_comp_funct_name_vendor_id = _get_comp_funct_name_vendor_id,
326 .get_family = _get_family,
327 .get_qualifier = _get_qualifier,
328 .set_qualifier = _set_qualifier,
329 .get_comp_funct_name = _get_comp_funct_name,
330 .set_comp_funct_name = _set_comp_funct_name,
331 },
332 .vendor_id = PEN_TCG,
333 .type = TCG_PTS_REQ_FUNCT_COMP_EVID,
334 .flags = flags,
335 .depth = depth,
336 .comp_vendor_id = vendor_id,
337 .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
338 .qualifier = qualifier,
339 .name = name,
340 );
341
342 return &this->public.pa_tnc_attribute;
343 }
344
345
346 /**
347 * Described in header.
348 */
349 pa_tnc_attr_t *tcg_pts_attr_req_funct_comp_evid_create_from_data(chunk_t data)
350 {
351 private_tcg_pts_attr_req_funct_comp_evid_t *this;
352
353 INIT(this,
354 .public = {
355 .pa_tnc_attribute = {
356 .get_vendor_id = _get_vendor_id,
357 .get_type = _get_type,
358 .get_value = _get_value,
359 .get_noskip_flag = _get_noskip_flag,
360 .set_noskip_flag = _set_noskip_flag,
361 .build = _build,
362 .process = _process,
363 .destroy = _destroy,
364 },
365 .get_flags= _get_flags,
366 .set_flags= _set_flags,
367 .get_sub_component_depth = _get_sub_component_depth,
368 .get_comp_funct_name_vendor_id = _get_comp_funct_name_vendor_id,
369 .get_family = _get_family,
370 .get_qualifier = _get_qualifier,
371 .set_qualifier = _set_qualifier,
372 .get_comp_funct_name = _get_comp_funct_name,
373 .set_comp_funct_name = _set_comp_funct_name,
374 },
375 .vendor_id = PEN_TCG,
376 .type = TCG_PTS_REQ_FUNCT_COMP_EVID,
377 .value = chunk_clone(data),
378 );
379
380 return &this->public.pa_tnc_attribute;
381 }