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_next_seg.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_next_seg_t private_tcg_seg_attr_next_seg_t
;
26 NEXT_SEG_FLAG_NONE
= 0,
27 NEXT_SEG_FLAG_CANCEL
= 1
32 * see TCG IF-M Segmentation Specification
35 * 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
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * |C| Reserved | Base Attribute ID |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * Private data of an tcg_seg_attr_next_seg_t object.
44 struct private_tcg_seg_attr_next_seg_t
{
47 * Public members of tcg_seg_attr_next_seg_t
49 tcg_seg_attr_next_seg_t
public;
52 * Vendor-specific attribute type
57 * Length of attribute value
62 * Attribute value or segment
79 uint32_t base_attr_id
;
87 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
88 private_tcg_seg_attr_next_seg_t
*this)
93 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
94 private_tcg_seg_attr_next_seg_t
*this)
99 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
100 private_tcg_seg_attr_next_seg_t
*this)
102 return this->noskip_flag
;
105 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
106 private_tcg_seg_attr_next_seg_t
*this, bool noskip
)
108 this->noskip_flag
= noskip
;
111 METHOD(pa_tnc_attr_t
, build
, void,
112 private_tcg_seg_attr_next_seg_t
*this)
114 bio_writer_t
*writer
;
120 writer
= bio_writer_create(TCG_SEG_ATTR_NEXT_SEG_SIZE
);
121 writer
->write_uint8 (writer
, this->cancel_flag ? NEXT_SEG_FLAG_CANCEL
:
123 writer
->write_uint24(writer
, this->base_attr_id
);
125 this->value
= writer
->extract_buf(writer
);
126 this->length
= this->value
.len
;
127 writer
->destroy(writer
);
130 METHOD(pa_tnc_attr_t
, process
, status_t
,
131 private_tcg_seg_attr_next_seg_t
*this, u_int32_t
*offset
)
133 bio_reader_t
*reader
;
138 if (this->value
.len
< this->length
)
140 DBG1(DBG_TNC
, "segmentation not allowed for %N", tcg_attr_names
,
144 if (this->value
.len
< TCG_SEG_ATTR_NEXT_SEG_SIZE
)
146 DBG1(DBG_TNC
, "insufficient data for %N", tcg_attr_names
,
150 reader
= bio_reader_create(this->value
);
151 reader
->read_uint8 (reader
, &flags
);
152 reader
->read_uint24(reader
, &this->base_attr_id
);
153 reader
->destroy(reader
);
155 this->cancel_flag
= (flags
& NEXT_SEG_FLAG_CANCEL
);
160 METHOD(pa_tnc_attr_t
, destroy
, void,
161 private_tcg_seg_attr_next_seg_t
*this)
163 if (ref_put(&this->ref
))
165 free(this->value
.ptr
);
170 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
171 private_tcg_seg_attr_next_seg_t
*this)
174 return &this->public.pa_tnc_attribute
;
177 METHOD(tcg_seg_attr_next_seg_t
, get_base_attr_id
, uint32_t,
178 private_tcg_seg_attr_next_seg_t
*this)
180 return this->base_attr_id
;
183 METHOD(tcg_seg_attr_next_seg_t
, get_cancel_flag
, bool,
184 private_tcg_seg_attr_next_seg_t
*this)
186 return this->cancel_flag
;
190 * Described in header.
192 pa_tnc_attr_t
* tcg_seg_attr_next_seg_create(uint32_t base_attr_id
, bool cancel
)
194 private_tcg_seg_attr_next_seg_t
*this;
198 .pa_tnc_attribute
= {
199 .get_type
= _get_type
,
200 .get_value
= _get_value
,
201 .get_noskip_flag
= _get_noskip_flag
,
202 .set_noskip_flag
= _set_noskip_flag
,
208 .get_base_attr_id
= _get_base_attr_id
,
209 .get_cancel_flag
= _get_cancel_flag
,
211 .type
= { PEN_TCG
, TCG_SEG_NEXT_SEG_REQ
},
212 .base_attr_id
= base_attr_id
,
213 .cancel_flag
= cancel
,
217 return &this->public.pa_tnc_attribute
;
221 * Described in header.
223 pa_tnc_attr_t
*tcg_seg_attr_next_seg_create_from_data(size_t length
,
226 private_tcg_seg_attr_next_seg_t
*this;
230 .pa_tnc_attribute
= {
231 .get_type
= _get_type
,
232 .get_value
= _get_value
,
233 .get_noskip_flag
= _get_noskip_flag
,
234 .set_noskip_flag
= _set_noskip_flag
,
240 .get_base_attr_id
= _get_base_attr_id
,
241 .get_cancel_flag
= _get_cancel_flag
,
243 .type
= { PEN_TCG
, TCG_SEG_NEXT_SEG_REQ
},
245 .value
= chunk_clone(data
),
249 return &this->public.pa_tnc_attribute
;