2 * Copyright (C) 2014 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_seg_attr_seg_env.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <utils/debug.h>
23 typedef struct private_tcg_seg_attr_seg_env_t private_tcg_seg_attr_seg_env_t
;
26 * Attribute Segment Envelope
27 * see TCG IF-M Segmentation 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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * |M|S| Reserved | Base Attribute ID |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Segment Value (Variable Length) |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * Private data of an tcg_seg_attr_seg_env_t object.
41 struct private_tcg_seg_attr_seg_env_t
{
44 * Public members of tcg_seg_attr_seg_env_t
46 tcg_seg_attr_seg_env_t
public;
49 * Vendor-specific attribute type
54 * Length of attribute value
59 * Attribute value or segment
69 * PA-TNC segmentation flags
76 uint32_t base_attr_id
;
89 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
90 private_tcg_seg_attr_seg_env_t
*this)
95 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
96 private_tcg_seg_attr_seg_env_t
*this)
101 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
102 private_tcg_seg_attr_seg_env_t
*this)
104 return this->noskip_flag
;
107 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
108 private_tcg_seg_attr_seg_env_t
*this, bool noskip
)
110 this->noskip_flag
= noskip
;
113 METHOD(pa_tnc_attr_t
, build
, void,
114 private_tcg_seg_attr_seg_env_t
*this)
116 /* constructor already allocated and built value */
117 this->length
= this->value
.len
;
121 METHOD(pa_tnc_attr_t
, process
, status_t
,
122 private_tcg_seg_attr_seg_env_t
*this, uint32_t *offset
)
124 bio_reader_t
*reader
;
128 if (this->value
.len
< this->length
)
130 DBG1(DBG_TNC
, "segmentation not allowed for %N/%N", pen_names
, PEN_TCG
,
131 tcg_attr_names
, this->type
.type
);
134 if (this->value
.len
< TCG_SEG_ATTR_SEG_ENV_HEADER
)
136 DBG1(DBG_TNC
, "insufficient data for %N/%N", pen_names
, PEN_TCG
,
137 tcg_attr_names
, this->type
.type
);
140 reader
= bio_reader_create(this->value
);
141 reader
->read_uint8 (reader
, &this->flags
);
142 reader
->read_uint24(reader
, &this->base_attr_id
);
143 reader
->destroy(reader
);
148 METHOD(pa_tnc_attr_t
, add_segment
, void,
149 private_tcg_seg_attr_seg_env_t
*this, chunk_t segment
)
151 /* no segments are expected */
154 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
155 private_tcg_seg_attr_seg_env_t
*this)
158 return &this->public.pa_tnc_attribute
;
161 METHOD(pa_tnc_attr_t
, destroy
, void,
162 private_tcg_seg_attr_seg_env_t
*this)
164 if (ref_put(&this->ref
))
166 free(this->value
.ptr
);
171 METHOD(tcg_seg_attr_seg_env_t
, get_segment
, chunk_t
,
172 private_tcg_seg_attr_seg_env_t
*this, uint8_t *flags
)
176 *flags
= this->flags
;
178 return chunk_skip(this->value
, TCG_SEG_ATTR_SEG_ENV_HEADER
);
181 METHOD(tcg_seg_attr_seg_env_t
, get_base_attr_id
, uint32_t,
182 private_tcg_seg_attr_seg_env_t
*this)
184 return this->base_attr_id
;
188 * Described in header.
190 pa_tnc_attr_t
* tcg_seg_attr_seg_env_create(chunk_t segment
, uint8_t flags
,
191 uint32_t base_attr_id
)
193 private_tcg_seg_attr_seg_env_t
*this;
197 .pa_tnc_attribute
= {
198 .get_type
= _get_type
,
199 .get_value
= _get_value
,
200 .get_noskip_flag
= _get_noskip_flag
,
201 .set_noskip_flag
= _set_noskip_flag
,
204 .add_segment
= _add_segment
,
208 .get_base_attr_id
= _get_base_attr_id
,
209 .get_segment
= _get_segment
,
211 .type
= { PEN_TCG
, TCG_SEG_ATTR_SEG_ENV
},
213 .base_attr_id
= base_attr_id
,
214 .value
= chunk_alloc(TCG_SEG_ATTR_SEG_ENV_HEADER
+ segment
.len
),
218 htoun32(this->value
.ptr
, base_attr_id
);
219 *this->value
.ptr
= flags
;
220 memcpy(this->value
.ptr
+ TCG_SEG_ATTR_SEG_ENV_HEADER
,
221 segment
.ptr
, segment
.len
);
223 return &this->public.pa_tnc_attribute
;
227 * Described in header.
229 pa_tnc_attr_t
*tcg_seg_attr_seg_env_create_from_data(size_t length
,
232 private_tcg_seg_attr_seg_env_t
*this;
236 .pa_tnc_attribute
= {
237 .get_type
= _get_type
,
238 .get_value
= _get_value
,
239 .get_noskip_flag
= _get_noskip_flag
,
240 .set_noskip_flag
= _set_noskip_flag
,
243 .add_segment
= _add_segment
,
247 .get_base_attr_id
= _get_base_attr_id
,
248 .get_segment
= _get_segment
,
250 .type
= { PEN_TCG
, TCG_SEG_ATTR_SEG_ENV
},
252 .value
= chunk_clone(data
),
256 return &this->public.pa_tnc_attribute
;