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_funct_comp_evid.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
23 typedef struct private_tcg_pts_attr_req_funct_comp_evid_t private_tcg_pts_attr_req_funct_comp_evid_t
;
26 * Request Functional Component Evidence
27 * see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification
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
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Flags | Sub-component Depth |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Component Functional Name |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * Component Functional Name Structure (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
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
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Component Functional Name Vendor ID |Fam| Qualifier |
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | Component Functional Name |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * Qualifier for Functional Component
56 * see section 5.2 of PTS Protocol: Binding to TNC IF-M Specification
65 #define PTS_REQ_FUNCT_COMP_EVID_SIZE 12
66 #define PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM 0x00
69 * Private data of an tcg_pts_attr_req_funct_comp_evid_t object.
71 struct private_tcg_pts_attr_req_funct_comp_evid_t
{
74 * Public members of tcg_pts_attr_req_funct_comp_evid_t
76 tcg_pts_attr_req_funct_comp_evid_t
public;
99 * Set of flags for Request Functional Component
101 pts_attr_req_funct_comp_evid_flag_t flags
;
104 * Sub-component Depth
109 * Component Functional Name Vendor ID
111 u_int32_t comp_vendor_id
;
114 * Functional Name Encoding Family
119 * Functional Name Category Qualifier
121 tcg_pts_qualifier_t qualifier
;
124 * Component Functional Name
126 pts_attr_req_funct_comp_name_bin_enum_t name
;
129 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
130 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
132 return this->vendor_id
;
135 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
136 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
141 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
142 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
147 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
148 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
150 return this->noskip_flag
;
153 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
154 private_tcg_pts_attr_req_funct_comp_evid_t
*this, bool noskip
)
156 this->noskip_flag
= noskip
;
159 METHOD(pa_tnc_attr_t
, build
, void,
160 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
162 bio_writer_t
*writer
;
164 u_int8_t qualifier
= 0;
166 writer
= bio_writer_create(PTS_REQ_FUNCT_COMP_EVID_SIZE
);
168 /* Determine the flags to set*/
169 if (this->flags
& PTS_REQ_FUNC_COMP_FLAG_PCR
)
173 if (this->flags
& PTS_REQ_FUNC_COMP_FLAG_CURR
)
177 if (this->flags
& PTS_REQ_FUNC_COMP_FLAG_VER
)
181 if (this->flags
& PTS_REQ_FUNC_COMP_FLAG_TTC
)
185 writer
->write_uint8(writer
, flags
);
187 writer
->write_uint24 (writer
, this->depth
);
188 writer
->write_uint24 (writer
, this->comp_vendor_id
);
190 if(this->family
!= PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM
)
192 DBG1(DBG_TNC
, "Functional Name Encoding Family is not set to 00");
195 qualifier
+= this->qualifier
.type
;
196 if (this->qualifier
.kernel
)
200 if (this->qualifier
.sub_component
)
204 writer
->write_uint8 (writer
, qualifier
);
205 writer
->write_uint32 (writer
, this->name
);
207 this->value
= chunk_clone(writer
->get_buf(writer
));
208 writer
->destroy(writer
);
211 METHOD(pa_tnc_attr_t
, process
, status_t
,
212 private_tcg_pts_attr_req_funct_comp_evid_t
*this, u_int32_t
*offset
)
214 bio_reader_t
*reader
;
216 u_int8_t fam_and_qualifier
;
218 if (this->value
.len
< PTS_REQ_FUNCT_COMP_EVID_SIZE
)
220 DBG1(DBG_TNC
, "insufficient data for Request Functional Component Evidence");
224 reader
= bio_reader_create(this->value
);
226 reader
->read_uint8(reader
, &flags
);
227 if ((flags
>> 4) & 1)
229 this->flags
|= PTS_REQ_FUNC_COMP_FLAG_PCR
;
231 if ((flags
>> 5) & 1)
233 this->flags
|= PTS_REQ_FUNC_COMP_FLAG_CURR
;
235 if ((flags
>> 6) & 1)
237 this->flags
|= PTS_REQ_FUNC_COMP_FLAG_VER
;
239 if ((flags
>> 7) & 1)
241 this->flags
|= PTS_REQ_FUNC_COMP_FLAG_TTC
;
244 reader
->read_uint24(reader
, &this->depth
);
245 reader
->read_uint24(reader
, &this->comp_vendor_id
);
246 reader
->read_uint8(reader
, &fam_and_qualifier
);
248 if (((fam_and_qualifier
>> 6) & 1) )
252 if (((fam_and_qualifier
>> 7) & 1) )
257 /* TODO: Generate an IF-M error attribute indicating */
258 /* TCG_PTS_INVALID_NAME_FAM */
259 //if(&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
261 // DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
264 if (((fam_and_qualifier
>> 5) & 1) )
266 this->qualifier
.kernel
= true;
268 if (((fam_and_qualifier
>> 4) & 1) )
270 this->qualifier
.sub_component
= true;
272 this->qualifier
.type
= ( fam_and_qualifier
& 0xF );
273 /* TODO: Check the type is defined in pts_attr_req_funct_comp_type_t */
275 reader
->read_uint32(reader
, &this->name
);
276 /* TODO: Check the name is defined in pts_attr_req_funct_comp_name_bin_enum_t */
278 reader
->destroy(reader
);
282 METHOD(pa_tnc_attr_t
, destroy
, void,
283 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
285 free(this->value
.ptr
);
289 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_flags
, pts_attr_req_funct_comp_evid_flag_t
,
290 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
295 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, set_flags
, void,
296 private_tcg_pts_attr_req_funct_comp_evid_t
*this, pts_attr_req_funct_comp_evid_flag_t flags
)
301 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_sub_component_depth
, u_int32_t
,
302 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
307 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_comp_funct_name_vendor_id
, u_int32_t
,
308 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
310 return this->comp_vendor_id
;
313 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_family
, u_int8_t
,
314 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
319 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_qualifier
, tcg_pts_qualifier_t
,
320 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
322 return this->qualifier
;
325 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, set_qualifier
, void,
326 private_tcg_pts_attr_req_funct_comp_evid_t
*this,
327 tcg_pts_qualifier_t qualifier
)
329 this->qualifier
= qualifier
;
332 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_comp_funct_name
, pts_attr_req_funct_comp_name_bin_enum_t
,
333 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
338 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, set_comp_funct_name
, void,
339 private_tcg_pts_attr_req_funct_comp_evid_t
*this, pts_attr_req_funct_comp_name_bin_enum_t name
)
345 * Described in header.
347 pa_tnc_attr_t
*tcg_pts_attr_req_funct_comp_evid_create(
348 pts_attr_req_funct_comp_evid_flag_t flags
,
351 tcg_pts_qualifier_t qualifier
,
352 pts_attr_req_funct_comp_name_bin_enum_t name
)
354 private_tcg_pts_attr_req_funct_comp_evid_t
*this;
358 .pa_tnc_attribute
= {
359 .get_vendor_id
= _get_vendor_id
,
360 .get_type
= _get_type
,
361 .get_value
= _get_value
,
362 .get_noskip_flag
= _get_noskip_flag
,
363 .set_noskip_flag
= _set_noskip_flag
,
368 .get_flags
= _get_flags
,
369 .set_flags
= _set_flags
,
370 .get_sub_component_depth
= _get_sub_component_depth
,
371 .get_comp_funct_name_vendor_id
= _get_comp_funct_name_vendor_id
,
372 .get_family
= _get_family
,
373 .get_qualifier
= _get_qualifier
,
374 .set_qualifier
= _set_qualifier
,
375 .get_comp_funct_name
= _get_comp_funct_name
,
376 .set_comp_funct_name
= _set_comp_funct_name
,
378 .vendor_id
= PEN_TCG
,
379 .type
= TCG_PTS_REQ_FUNCT_COMP_EVID
,
382 .comp_vendor_id
= vendor_id
,
383 .family
= PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM
,
384 .qualifier
= qualifier
,
388 return &this->public.pa_tnc_attribute
;
393 * Described in header.
395 pa_tnc_attr_t
*tcg_pts_attr_req_funct_comp_evid_create_from_data(chunk_t data
)
397 private_tcg_pts_attr_req_funct_comp_evid_t
*this;
401 .pa_tnc_attribute
= {
402 .get_vendor_id
= _get_vendor_id
,
403 .get_type
= _get_type
,
404 .get_value
= _get_value
,
405 .get_noskip_flag
= _get_noskip_flag
,
406 .set_noskip_flag
= _set_noskip_flag
,
411 .get_flags
= _get_flags
,
412 .set_flags
= _set_flags
,
413 .get_sub_component_depth
= _get_sub_component_depth
,
414 .get_comp_funct_name_vendor_id
= _get_comp_funct_name_vendor_id
,
415 .get_family
= _get_family
,
416 .get_qualifier
= _get_qualifier
,
417 .set_qualifier
= _set_qualifier
,
418 .get_comp_funct_name
= _get_comp_funct_name
,
419 .set_comp_funct_name
= _set_comp_funct_name
,
421 .vendor_id
= PEN_TCG
,
422 .type
= TCG_PTS_REQ_FUNCT_COMP_EVID
,
423 .value
= chunk_clone(data
),
426 return &this->public.pa_tnc_attribute
;