2 * Copyright (C) 2011 Sansar Choinyambuu
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 <utils/linked_list.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;
96 * 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_vendor_id
, pen_t
,
139 private_tcg_pts_attr_req_func_comp_evid_t
*this)
141 return this->vendor_id
;
144 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
145 private_tcg_pts_attr_req_func_comp_evid_t
*this)
150 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
151 private_tcg_pts_attr_req_func_comp_evid_t
*this)
156 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
157 private_tcg_pts_attr_req_func_comp_evid_t
*this)
159 return this->noskip_flag
;
162 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
163 private_tcg_pts_attr_req_func_comp_evid_t
*this, bool noskip
)
165 this->noskip_flag
= noskip
;
168 METHOD(pa_tnc_attr_t
, build
, void,
169 private_tcg_pts_attr_req_func_comp_evid_t
*this)
171 bio_writer_t
*writer
;
172 enumerator_t
*enumerator
;
175 writer
= bio_writer_create(PTS_REQ_FUNC_COMP_EVID_SIZE
);
177 enumerator
= this->list
->create_enumerator(this->list
);
178 while (enumerator
->enumerate(enumerator
, &entry
))
180 writer
->write_uint8 (writer
, entry
->flags
);
181 writer
->write_uint24(writer
, entry
->depth
);
182 writer
->write_uint24(writer
, entry
->name
->get_vendor_id(entry
->name
));
183 writer
->write_uint8 (writer
, entry
->name
->get_qualifier(entry
->name
));
184 writer
->write_uint32(writer
, entry
->name
->get_name(entry
->name
));
186 enumerator
->destroy(enumerator
);
188 this->value
= chunk_clone(writer
->get_buf(writer
));
189 writer
->destroy(writer
);
192 METHOD(pa_tnc_attr_t
, process
, status_t
,
193 private_tcg_pts_attr_req_func_comp_evid_t
*this, u_int32_t
*offset
)
195 bio_reader_t
*reader
;
196 u_int32_t depth
, vendor_id
, name
;
197 u_int8_t flags
, fam_and_qualifier
, qualifier
;
198 status_t status
= FAILED
;
199 entry_t
*entry
= NULL
;
201 if (this->value
.len
< PTS_REQ_FUNC_COMP_EVID_SIZE
)
203 DBG1(DBG_TNC
, "insufficient data for Request Functional "
204 "Component Evidence");
208 reader
= bio_reader_create(this->value
);
210 while (reader
->remaining(reader
))
212 if (!reader
->read_uint8(reader
, &flags
))
214 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
215 "Component Evidence Flags");
218 if (!reader
->read_uint24(reader
, &depth
))
220 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
221 "Component Evidence Sub Component Depth");
224 if (!reader
->read_uint24(reader
, &vendor_id
))
226 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
227 "Component Evidence Component Name Vendor ID");
230 if (!reader
->read_uint8(reader
, &fam_and_qualifier
))
232 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
233 "Component Evidence Family and Qualifier");
236 if (fam_and_qualifier
& PTS_REQ_FUNC_COMP_FAMILY_MASK
)
238 DBG1(DBG_TNC
, "the Functional Name Encoding Family "
239 "is not Binary Enumeration");
242 if (!reader
->read_uint32(reader
, &name
))
244 DBG1(DBG_TNC
, "insufficient data for PTS Request Functional "
245 "Component Evidence Component Functional Name");
248 qualifier
= fam_and_qualifier
& !PTS_REQ_FUNC_COMP_FAMILY_MASK
;
250 entry
= malloc_thing(entry_t
);
251 entry
->flags
= flags
;
252 entry
->depth
= depth
;
253 entry
->name
= pts_comp_func_name_create(vendor_id
, name
, qualifier
);
255 this->list
->insert_last(this->list
, entry
);
260 reader
->destroy(reader
);
264 METHOD(pa_tnc_attr_t
, destroy
, void,
265 private_tcg_pts_attr_req_func_comp_evid_t
*this)
267 this->list
->destroy_function(this->list
, (void *)free_entry
);
268 free(this->value
.ptr
);
272 METHOD(tcg_pts_attr_req_func_comp_evid_t
, add_component
, void,
273 private_tcg_pts_attr_req_func_comp_evid_t
*this, u_int8_t flags
,
274 u_int32_t depth
, pts_comp_func_name_t
*name
)
278 entry
= malloc_thing(entry_t
);
279 entry
->flags
= flags
;
280 entry
->depth
= depth
;
281 entry
->name
= name
->clone(name
);
282 this->list
->insert_last(this->list
, entry
);
285 METHOD(tcg_pts_attr_req_func_comp_evid_t
, get_count
, int,
286 private_tcg_pts_attr_req_func_comp_evid_t
*this)
288 return this->list
->get_count(this->list
);
291 METHOD(tcg_pts_attr_req_func_comp_evid_t
, create_enumerator
, enumerator_t
*,
292 private_tcg_pts_attr_req_func_comp_evid_t
*this)
294 return enumerator_create_filter(this->list
->create_enumerator(this->list
),
295 (void*)entry_filter
, NULL
, NULL
);
299 * Described in header.
301 pa_tnc_attr_t
*tcg_pts_attr_req_func_comp_evid_create(void)
303 private_tcg_pts_attr_req_func_comp_evid_t
*this;
307 .pa_tnc_attribute
= {
308 .get_vendor_id
= _get_vendor_id
,
309 .get_type
= _get_type
,
310 .get_value
= _get_value
,
311 .get_noskip_flag
= _get_noskip_flag
,
312 .set_noskip_flag
= _set_noskip_flag
,
317 .add_component
= _add_component
,
318 .get_count
= _get_count
,
319 .create_enumerator
= _create_enumerator
,
321 .vendor_id
= PEN_TCG
,
322 .type
= TCG_PTS_REQ_FUNC_COMP_EVID
,
323 .list
= linked_list_create(),
326 return &this->public.pa_tnc_attribute
;
330 * Described in header.
332 pa_tnc_attr_t
*tcg_pts_attr_req_func_comp_evid_create_from_data(chunk_t data
)
334 private_tcg_pts_attr_req_func_comp_evid_t
*this;
338 .pa_tnc_attribute
= {
339 .get_vendor_id
= _get_vendor_id
,
340 .get_type
= _get_type
,
341 .get_value
= _get_value
,
342 .get_noskip_flag
= _get_noskip_flag
,
343 .set_noskip_flag
= _set_noskip_flag
,
348 .add_component
= _add_component
,
349 .get_count
= _get_count
,
350 .create_enumerator
= _create_enumerator
,
352 .vendor_id
= PEN_TCG
,
353 .type
= TCG_PTS_REQ_FUNC_COMP_EVID
,
354 .list
= linked_list_create(),
355 .value
= chunk_clone(data
),
358 return &this->public.pa_tnc_attribute
;