2 * Copyright (C) 2011-2012 Sansar Choinyambuu, Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "tcg_pts_attr_req_func_comp_evid.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <collections/linked_list.h>
22 #include <utils/debug.h>
24 typedef struct private_tcg_pts_attr_req_func_comp_evid_t private_tcg_pts_attr_req_func_comp_evid_t
;
27 * Request Functional Component Evidence
28 * see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification
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 * | Flags | Sub-component Depth (for Component #1) |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Component Functional Name #1 |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Component Functional Name #1 |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Flags | Sub-component Depth (for Component #N) |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | Component Functional Name #N |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * | Component Functional Name #N |
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * Component Functional Name Structure
51 * (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
54 * 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
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * | Component Functional Name Vendor ID |Fam| Qualifier |
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * | Component Functional Name |
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 #define PTS_REQ_FUNC_COMP_EVID_SIZE 12
63 #define PTS_REQ_FUNC_COMP_FAMILY_MASK 0xC0
66 * Private data of an tcg_pts_attr_req_func_comp_evid_t object.
68 struct private_tcg_pts_attr_req_func_comp_evid_t
{
71 * Public members of tcg_pts_attr_req_func_comp_evid_t
73 tcg_pts_attr_req_func_comp_evid_t
public;
76 * Vendor-specific attribute type
91 * List of Functional Components
101 typedef struct entry_t entry_t
;
104 * Functional component entry
109 pts_comp_func_name_t
*name
;
113 * Enumerate functional component entries
115 static bool entry_filter(void *null
, entry_t
**entry
, u_int8_t
*flags
,
116 void *i2
, u_int32_t
*depth
, void *i3
,
117 pts_comp_func_name_t
**name
)
119 *flags
= (*entry
)->flags
;
120 *depth
= (*entry
)->depth
;
121 *name
= (*entry
)->name
;
127 * Free an entry_t object
129 static void free_entry(entry_t
*this)
133 this->name
->destroy(this->name
);
138 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
139 private_tcg_pts_attr_req_func_comp_evid_t
*this)
144 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
145 private_tcg_pts_attr_req_func_comp_evid_t
*this)
150 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
151 private_tcg_pts_attr_req_func_comp_evid_t
*this)
153 return this->noskip_flag
;
156 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
157 private_tcg_pts_attr_req_func_comp_evid_t
*this, bool noskip
)
159 this->noskip_flag
= noskip
;
162 METHOD(pa_tnc_attr_t
, build
, void,
163 private_tcg_pts_attr_req_func_comp_evid_t
*this)
165 bio_writer_t
*writer
;
166 enumerator_t
*enumerator
;
173 writer
= bio_writer_create(PTS_REQ_FUNC_COMP_EVID_SIZE
);
175 enumerator
= this->list
->create_enumerator(this->list
);
176 while (enumerator
->enumerate(enumerator
, &entry
))
178 writer
->write_uint8 (writer
, entry
->flags
);
179 writer
->write_uint24(writer
, entry
->depth
);
180 writer
->write_uint24(writer
, entry
->name
->get_vendor_id(entry
->name
));
181 writer
->write_uint8 (writer
, entry
->name
->get_qualifier(entry
->name
));
182 writer
->write_uint32(writer
, entry
->name
->get_name(entry
->name
));
184 enumerator
->destroy(enumerator
);
186 this->value
= chunk_clone(writer
->get_buf(writer
));
187 writer
->destroy(writer
);
190 METHOD(pa_tnc_attr_t
, process
, status_t
,
191 private_tcg_pts_attr_req_func_comp_evid_t
*this, u_int32_t
*offset
)
193 bio_reader_t
*reader
;
194 u_int32_t depth
, vendor_id
, name
;
195 u_int8_t flags
, fam_and_qualifier
, qualifier
;
196 status_t status
= FAILED
;
197 entry_t
*entry
= NULL
;
199 if (this->value
.len
< PTS_REQ_FUNC_COMP_EVID_SIZE
)
201 DBG1(DBG_TNC
, "insufficient data for Request Functional "
202 "Component Evidence");
206 reader
= bio_reader_create(this->value
);
208 while (reader
->remaining(reader
))
210 if (!reader
->read_uint8(reader
, &flags
))
212 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
213 "Component Evidence Flags");
216 if (!reader
->read_uint24(reader
, &depth
))
218 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
219 "Component Evidence Sub Component Depth");
222 if (!reader
->read_uint24(reader
, &vendor_id
))
224 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
225 "Component Evidence Component Name Vendor ID");
228 if (!reader
->read_uint8(reader
, &fam_and_qualifier
))
230 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
231 "Component Evidence Family and Qualifier");
234 if (fam_and_qualifier
& PTS_REQ_FUNC_COMP_FAMILY_MASK
)
236 DBG1(DBG_TNC
, "the Functional Name Encoding Family "
237 "is not Binary Enumeration");
240 if (!reader
->read_uint32(reader
, &name
))
242 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
243 "Component Evidence Component Functional Name");
246 qualifier
= fam_and_qualifier
& ~PTS_REQ_FUNC_COMP_FAMILY_MASK
;
248 entry
= malloc_thing(entry_t
);
249 entry
->flags
= flags
;
250 entry
->depth
= depth
;
251 entry
->name
= pts_comp_func_name_create(vendor_id
, name
, qualifier
);
253 this->list
->insert_last(this->list
, entry
);
258 reader
->destroy(reader
);
262 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
263 private_tcg_pts_attr_req_func_comp_evid_t
*this)
266 return &this->public.pa_tnc_attribute
;
269 METHOD(pa_tnc_attr_t
, destroy
, void,
270 private_tcg_pts_attr_req_func_comp_evid_t
*this)
272 if (ref_put(&this->ref
))
274 this->list
->destroy_function(this->list
, (void *)free_entry
);
275 free(this->value
.ptr
);
280 METHOD(tcg_pts_attr_req_func_comp_evid_t
, add_component
, void,
281 private_tcg_pts_attr_req_func_comp_evid_t
*this, u_int8_t flags
,
282 u_int32_t depth
, pts_comp_func_name_t
*name
)
286 entry
= malloc_thing(entry_t
);
287 entry
->flags
= flags
;
288 entry
->depth
= depth
;
290 this->list
->insert_last(this->list
, entry
);
293 METHOD(tcg_pts_attr_req_func_comp_evid_t
, get_count
, int,
294 private_tcg_pts_attr_req_func_comp_evid_t
*this)
296 return this->list
->get_count(this->list
);
299 METHOD(tcg_pts_attr_req_func_comp_evid_t
, create_enumerator
, enumerator_t
*,
300 private_tcg_pts_attr_req_func_comp_evid_t
*this)
302 return enumerator_create_filter(this->list
->create_enumerator(this->list
),
303 (void*)entry_filter
, NULL
, NULL
);
307 * Described in header.
309 pa_tnc_attr_t
*tcg_pts_attr_req_func_comp_evid_create(void)
311 private_tcg_pts_attr_req_func_comp_evid_t
*this;
315 .pa_tnc_attribute
= {
316 .get_type
= _get_type
,
317 .get_value
= _get_value
,
318 .get_noskip_flag
= _get_noskip_flag
,
319 .set_noskip_flag
= _set_noskip_flag
,
325 .add_component
= _add_component
,
326 .get_count
= _get_count
,
327 .create_enumerator
= _create_enumerator
,
329 .type
= { PEN_TCG
, TCG_PTS_REQ_FUNC_COMP_EVID
},
330 .list
= linked_list_create(),
334 return &this->public.pa_tnc_attribute
;
338 * Described in header.
340 pa_tnc_attr_t
*tcg_pts_attr_req_func_comp_evid_create_from_data(chunk_t data
)
342 private_tcg_pts_attr_req_func_comp_evid_t
*this;
346 .pa_tnc_attribute
= {
347 .get_type
= _get_type
,
348 .get_value
= _get_value
,
349 .get_noskip_flag
= _get_noskip_flag
,
350 .set_noskip_flag
= _set_noskip_flag
,
356 .add_component
= _add_component
,
357 .get_count
= _get_count
,
358 .create_enumerator
= _create_enumerator
,
360 .type
= { PEN_TCG
, TCG_PTS_REQ_FUNC_COMP_EVID
},
361 .list
= linked_list_create(),
362 .value
= chunk_clone(data
),
366 return &this->public.pa_tnc_attribute
;