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 (see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification)
29 * 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 * | Flags | Sub-component Depth |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Component Functional Name |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * Component Functional Name Structure (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
43 * 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 * | Component Functional Name Vendor ID |Fam| Qualifier |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Component Functional Name |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * Qualifier for Functional Component (see section 5.2 of PTS Protocol: Binding to TNC IF-M Specification)
63 #define PTS_REQ_FUNCT_COMP_EVID_SIZE 12
64 #define PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM 0x00
67 * Private data of an tcg_pts_attr_req_funct_comp_evid_t object.
69 struct private_tcg_pts_attr_req_funct_comp_evid_t
{
72 * Public members of tcg_pts_attr_req_funct_comp_evid_t
74 tcg_pts_attr_req_funct_comp_evid_t
public;
97 * Set of flags for Request Functional Component
99 pts_attr_req_funct_comp_evid_flag_t flags
;
102 * Sub-component Depth
107 * Component Functional Name Vendor ID
109 u_int32_t comp_vendor_id
;
112 * Functional Name Encoding Family
117 * Functional Name Category Qualifier
119 tcg_pts_qualifier_t qualifier
;
122 * Component Functional Name
124 pts_attr_req_funct_comp_name_bin_enum_t name
;
127 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
128 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
130 return this->vendor_id
;
133 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
134 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
139 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
140 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
145 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
146 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
148 return this->noskip_flag
;
151 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
152 private_tcg_pts_attr_req_funct_comp_evid_t
*this, bool noskip
)
154 this->noskip_flag
= noskip
;
157 METHOD(pa_tnc_attr_t
, build
, void,
158 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
160 bio_writer_t
*writer
;
162 u_int8_t qualifier
= 0;
164 writer
= bio_writer_create(PTS_REQ_FUNCT_COMP_EVID_SIZE
);
166 /* Determine the flags to set*/
167 if(this->flags
& PTS_REQ_FUNC_COMP_FLAG_TTC
) flags
+= 1;
168 if(this->flags
& PTS_REQ_FUNC_COMP_FLAG_VER
) flags
+= 2;
169 if(this->flags
& PTS_REQ_FUNC_COMP_FLAG_CURR
) flags
+= 4;
170 if(this->flags
& PTS_REQ_FUNC_COMP_FLAG_PCR
) flags
+= 8;
171 writer
->write_uint8(writer
, flags
);
173 writer
->write_uint24 (writer
, this->depth
);
174 writer
->write_uint24 (writer
, this->comp_vendor_id
);
176 if(this->family
!= PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM
)
178 DBG1(DBG_TNC
, "Functional Name Encoding Family is not set to 00");
181 qualifier
+= this->qualifier
.type
;
182 if(this->qualifier
.kernel
) qualifier
+= 16;
183 if(this->qualifier
.sub_component
) qualifier
+= 32;
185 writer
->write_uint8 (writer
, qualifier
);
186 writer
->write_uint32 (writer
, this->name
);
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_funct_comp_evid_t
*this, u_int32_t
*offset
)
195 bio_reader_t
*reader
;
197 u_int8_t fam_and_qualifier
;
199 if (this->value
.len
< PTS_REQ_FUNCT_COMP_EVID_SIZE
)
201 DBG1(DBG_TNC
, "insufficient data for Request Functional Component Evidence");
205 reader
= bio_reader_create(this->value
);
207 reader
->read_uint8(reader
, &flags
);
208 if((flags
>> 0) & 1) this->flags
|= PTS_REQ_FUNC_COMP_FLAG_TTC
;
209 if((flags
>> 1) & 1) this->flags
|= PTS_REQ_FUNC_COMP_FLAG_VER
;
210 if((flags
>> 2) & 1) this->flags
|= PTS_REQ_FUNC_COMP_FLAG_CURR
;
211 if((flags
>> 3) & 1) this->flags
|= PTS_REQ_FUNC_COMP_FLAG_PCR
;
213 reader
->read_uint24(reader
, &this->depth
);
214 reader
->read_uint24(reader
, &this->comp_vendor_id
);
215 reader
->read_uint8(reader
, &fam_and_qualifier
);
217 if(((fam_and_qualifier
>> 6) & 1) ) this->family
+= 64;
218 if(((fam_and_qualifier
>> 7) & 1) ) this->family
+= 128;
220 /* TODO: Generate an IF-M error attribute indicating */
221 /* TCG_PTS_INVALID_NAME_FAM */
222 //if(&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
224 // DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
227 if(((fam_and_qualifier
>> 5) & 1) ) this->qualifier
.kernel
= true;
228 if(((fam_and_qualifier
>> 4) & 1) ) this->qualifier
.sub_component
= true;
229 this->qualifier
.type
= ( fam_and_qualifier
& 0xF );
231 /* TODO: Check the type is defined in pts_attr_req_funct_comp_type_t */
233 reader
->read_uint32(reader
, &this->name
);
235 /* TODO: Check the name is defined in pts_attr_req_funct_comp_name_bin_enum_t */
237 reader
->destroy(reader
);
241 METHOD(pa_tnc_attr_t
, destroy
, void,
242 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
244 free(this->value
.ptr
);
248 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_flags
, pts_attr_req_funct_comp_evid_flag_t
,
249 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
254 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, set_flags
, void,
255 private_tcg_pts_attr_req_funct_comp_evid_t
*this, pts_attr_req_funct_comp_evid_flag_t flags
)
260 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_sub_component_depth
, u_int32_t
,
261 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
266 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_comp_funct_name_vendor_id
, u_int32_t
,
267 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
269 return this->comp_vendor_id
;
272 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_family
, u_int8_t
,
273 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
278 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_qualifier
, tcg_pts_qualifier_t
,
279 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
281 return this->qualifier
;
284 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, set_qualifier
, void,
285 private_tcg_pts_attr_req_funct_comp_evid_t
*this,
286 tcg_pts_qualifier_t qualifier
)
288 this->qualifier
= qualifier
;
291 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, get_comp_funct_name
, pts_attr_req_funct_comp_name_bin_enum_t
,
292 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
297 METHOD(tcg_pts_attr_req_funct_comp_evid_t
, set_comp_funct_name
, void,
298 private_tcg_pts_attr_req_funct_comp_evid_t
*this, pts_attr_req_funct_comp_name_bin_enum_t name
)
304 * Described in header.
306 pa_tnc_attr_t
*tcg_pts_attr_req_funct_comp_evid_create(
307 pts_attr_req_funct_comp_evid_flag_t flags
,
310 tcg_pts_qualifier_t qualifier
,
313 private_tcg_pts_attr_req_funct_comp_evid_t
*this;
317 .pa_tnc_attribute
= {
318 .get_vendor_id
= _get_vendor_id
,
319 .get_type
= _get_type
,
320 .get_value
= _get_value
,
321 .get_noskip_flag
= _get_noskip_flag
,
322 .set_noskip_flag
= _set_noskip_flag
,
327 .get_flags
= _get_flags
,
328 .set_flags
= _set_flags
,
329 .get_sub_component_depth
= _get_sub_component_depth
,
330 .get_comp_funct_name_vendor_id
= _get_comp_funct_name_vendor_id
,
331 .get_family
= _get_family
,
332 .get_qualifier
= _get_qualifier
,
333 .set_qualifier
= _set_qualifier
,
334 .get_comp_funct_name
= _get_comp_funct_name
,
335 .set_comp_funct_name
= _set_comp_funct_name
,
337 .vendor_id
= PEN_TCG
,
338 .type
= TCG_PTS_REQ_FUNCT_COMP_EVID
,
341 .comp_vendor_id
= vendor_id
,
342 .family
= PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM
,
343 .qualifier
= qualifier
,
347 return &this->public.pa_tnc_attribute
;
352 * Described in header.
354 pa_tnc_attr_t
*tcg_pts_attr_req_funct_comp_evid_create_from_data(chunk_t data
)
356 private_tcg_pts_attr_req_funct_comp_evid_t
*this;
360 .pa_tnc_attribute
= {
361 .get_vendor_id
= _get_vendor_id
,
362 .get_type
= _get_type
,
363 .get_value
= _get_value
,
364 .get_noskip_flag
= _get_noskip_flag
,
365 .set_noskip_flag
= _set_noskip_flag
,
370 .get_flags
= _get_flags
,
371 .set_flags
= _set_flags
,
372 .get_sub_component_depth
= _get_sub_component_depth
,
373 .get_comp_funct_name_vendor_id
= _get_comp_funct_name_vendor_id
,
374 .get_family
= _get_family
,
375 .get_qualifier
= _get_qualifier
,
376 .set_qualifier
= _set_qualifier
,
377 .get_comp_funct_name
= _get_comp_funct_name
,
378 .set_comp_funct_name
= _set_comp_funct_name
,
380 .vendor_id
= PEN_TCG
,
381 .type
= TCG_PTS_REQ_FUNCT_COMP_EVID
,
382 .value
= chunk_clone(data
),
385 return &this->public.pa_tnc_attribute
;