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_proto_caps.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_proto_caps_t private_tcg_pts_attr_req_proto_caps_t
;
26 * Request PTS Protocol Capabilities
27 * see section 3.6 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 * | Reserved |C|V|D|T|X|
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 #define PTS_PROTO_CAPS_SIZE 4
39 #define PTS_PROTO_CAPS_RESERVED 0x00
42 * Private data of an tcg_pts_attr_req_proto_caps_t object.
44 struct private_tcg_pts_attr_req_proto_caps_t
{
47 * Public members of tcg_pts_attr_req_proto_caps_t
49 tcg_pts_attr_req_proto_caps_t
public;
74 pts_proto_caps_flag_t flags
;
78 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
79 private_tcg_pts_attr_req_proto_caps_t
*this)
81 return this->vendor_id
;
84 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
85 private_tcg_pts_attr_req_proto_caps_t
*this)
90 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
91 private_tcg_pts_attr_req_proto_caps_t
*this)
96 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
97 private_tcg_pts_attr_req_proto_caps_t
*this)
99 return this->noskip_flag
;
102 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
103 private_tcg_pts_attr_req_proto_caps_t
*this, bool noskip
)
105 this->noskip_flag
= noskip
;
108 METHOD(pa_tnc_attr_t
, build
, void,
109 private_tcg_pts_attr_req_proto_caps_t
*this)
111 bio_writer_t
*writer
;
114 writer
= bio_writer_create(PTS_PROTO_CAPS_SIZE
);
115 writer
->write_uint24 (writer
, PTS_PROTO_CAPS_RESERVED
);
117 /* Determine the flags to set*/
118 if (this->flags
& PTS_PROTO_CAPS_XML
)
122 if (this->flags
& PTS_PROTO_CAPS_T
)
126 if (this->flags
& PTS_PROTO_CAPS_DH
)
130 if (this->flags
& PTS_PROTO_CAPS_VER
)
134 if (this->flags
& PTS_PROTO_CAPS_CURRENT
)
138 writer
->write_uint8(writer
, flags
);
140 this->value
= chunk_clone(writer
->get_buf(writer
));
141 writer
->destroy(writer
);
144 METHOD(pa_tnc_attr_t
, process
, status_t
,
145 private_tcg_pts_attr_req_proto_caps_t
*this, u_int32_t
*offset
)
147 bio_reader_t
*reader
;
151 if (this->value
.len
< PTS_PROTO_CAPS_SIZE
)
153 DBG1(DBG_TNC
, "insufficient data for Request PTS Protocol Capabilities");
157 reader
= bio_reader_create(this->value
);
158 reader
->read_uint24 (reader
, &reserved
);
159 reader
->read_uint8(reader
, &flags
);
161 if ((flags
>> 0) & 1)
163 this->flags
|= PTS_PROTO_CAPS_XML
;
165 if ((flags
>> 1) & 1)
167 this->flags
|= PTS_PROTO_CAPS_T
;
169 if ((flags
>> 2) & 1)
171 this->flags
|= PTS_PROTO_CAPS_DH
;
173 if ((flags
>> 3) & 1)
175 this->flags
|= PTS_PROTO_CAPS_VER
;
177 if ((flags
>> 4) & 1)
179 this->flags
|= PTS_PROTO_CAPS_CURRENT
;
182 reader
->destroy(reader
);
187 METHOD(pa_tnc_attr_t
, destroy
, void,
188 private_tcg_pts_attr_req_proto_caps_t
*this)
190 free(this->value
.ptr
);
194 METHOD(tcg_pts_attr_req_proto_caps_t
, get_flags
, pts_proto_caps_flag_t
,
195 private_tcg_pts_attr_req_proto_caps_t
*this)
200 METHOD(tcg_pts_attr_req_proto_caps_t
, set_flags
, void,
201 private_tcg_pts_attr_req_proto_caps_t
*this, pts_proto_caps_flag_t flags
)
207 * Described in header.
209 pa_tnc_attr_t
*tcg_pts_attr_req_proto_caps_create(pts_proto_caps_flag_t flags
)
211 private_tcg_pts_attr_req_proto_caps_t
*this;
215 .pa_tnc_attribute
= {
216 .get_vendor_id
= _get_vendor_id
,
217 .get_type
= _get_type
,
218 .get_value
= _get_value
,
219 .get_noskip_flag
= _get_noskip_flag
,
220 .set_noskip_flag
= _set_noskip_flag
,
225 .get_flags
= _get_flags
,
226 .set_flags
= _set_flags
,
228 .vendor_id
= PEN_TCG
,
229 .type
= TCG_PTS_REQ_PROTO_CAPS
,
233 return &this->public.pa_tnc_attribute
;
238 * Described in header.
240 pa_tnc_attr_t
*tcg_pts_attr_req_proto_caps_create_from_data(chunk_t data
)
242 private_tcg_pts_attr_req_proto_caps_t
*this;
246 .pa_tnc_attribute
= {
247 .get_vendor_id
= _get_vendor_id
,
248 .get_type
= _get_type
,
249 .get_value
= _get_value
,
250 .get_noskip_flag
= _get_noskip_flag
,
251 .set_noskip_flag
= _set_noskip_flag
,
256 .get_flags
= _get_flags
,
257 .set_flags
= _set_flags
,
259 .vendor_id
= PEN_TCG
,
260 .type
= TCG_PTS_REQ_PROTO_CAPS
,
261 .value
= chunk_clone(data
),
264 return &this->public.pa_tnc_attribute
;