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_tpm_version_info.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_tpm_version_info_t private_tcg_pts_attr_tpm_version_info_t
;
26 * TPM Version Information
27 * see section 3.11 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 * | TPM Version Information (Variable Lenght) |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * see TPM Structure Specification Part 2, section 21.6: TPM_CAP_VERSION_INFO
39 #define PTS_TPM_VER_INFO_SIZE 4
42 * Private data of an tcg_pts_attr_tpm_version_info_t object.
44 struct private_tcg_pts_attr_tpm_version_info_t
{
47 * Public members of tcg_pts_attr_tpm_version_info_t
49 tcg_pts_attr_tpm_version_info_t
public;
72 * TPM Version Information
74 chunk_t tpm_version_info
;
77 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
78 private_tcg_pts_attr_tpm_version_info_t
*this)
80 return this->vendor_id
;
83 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
84 private_tcg_pts_attr_tpm_version_info_t
*this)
89 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
90 private_tcg_pts_attr_tpm_version_info_t
*this)
95 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
96 private_tcg_pts_attr_tpm_version_info_t
*this)
98 return this->noskip_flag
;
101 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
102 private_tcg_pts_attr_tpm_version_info_t
*this, bool noskip
)
104 this->noskip_flag
= noskip
;
107 METHOD(pa_tnc_attr_t
, build
, void,
108 private_tcg_pts_attr_tpm_version_info_t
*this)
110 bio_writer_t
*writer
;
112 writer
= bio_writer_create(PTS_TPM_VER_INFO_SIZE
);
113 writer
->write_data(writer
, this->tpm_version_info
);
115 this->value
= chunk_clone(writer
->get_buf(writer
));
116 writer
->destroy(writer
);
119 METHOD(pa_tnc_attr_t
, process
, status_t
,
120 private_tcg_pts_attr_tpm_version_info_t
*this, u_int32_t
*offset
)
122 bio_reader_t
*reader
;
124 if (this->value
.len
< PTS_TPM_VER_INFO_SIZE
)
126 DBG1(DBG_TNC
, "insufficient data for TPM Version Information");
130 reader
= bio_reader_create(this->value
);
131 reader
->read_data (reader
, this->value
.len
, &this->tpm_version_info
);
132 this->tpm_version_info
= chunk_clone(this->tpm_version_info
);
133 reader
->destroy(reader
);
138 METHOD(pa_tnc_attr_t
, destroy
, void,
139 private_tcg_pts_attr_tpm_version_info_t
*this)
141 free(this->value
.ptr
);
142 free(this->tpm_version_info
.ptr
);
146 METHOD(tcg_pts_attr_tpm_version_info_t
, get_tpm_version_info
, chunk_t
,
147 private_tcg_pts_attr_tpm_version_info_t
*this)
149 return this->tpm_version_info
;
152 METHOD(tcg_pts_attr_tpm_version_info_t
, set_tpm_version_info
, void,
153 private_tcg_pts_attr_tpm_version_info_t
*this,
154 chunk_t tpm_version_info
)
156 this->tpm_version_info
= tpm_version_info
;
160 * Described in header.
162 pa_tnc_attr_t
*tcg_pts_attr_tpm_version_info_create(chunk_t tpm_version_info
)
164 private_tcg_pts_attr_tpm_version_info_t
*this;
168 .pa_tnc_attribute
= {
169 .get_vendor_id
= _get_vendor_id
,
170 .get_type
= _get_type
,
171 .get_value
= _get_value
,
172 .get_noskip_flag
= _get_noskip_flag
,
173 .set_noskip_flag
= _set_noskip_flag
,
178 .get_tpm_version_info
= _get_tpm_version_info
,
179 .set_tpm_version_info
= _set_tpm_version_info
,
181 .vendor_id
= PEN_TCG
,
182 .type
= TCG_PTS_TPM_VERSION_INFO
,
183 .tpm_version_info
= tpm_version_info
,
186 return &this->public.pa_tnc_attribute
;
191 * Described in header.
193 pa_tnc_attr_t
*tcg_pts_attr_tpm_version_info_create_from_data(chunk_t data
)
195 private_tcg_pts_attr_tpm_version_info_t
*this;
199 .pa_tnc_attribute
= {
200 .get_vendor_id
= _get_vendor_id
,
201 .get_type
= _get_type
,
202 .get_value
= _get_value
,
203 .get_noskip_flag
= _get_noskip_flag
,
204 .set_noskip_flag
= _set_noskip_flag
,
209 .get_tpm_version_info
= _get_tpm_version_info
,
210 .set_tpm_version_info
= _set_tpm_version_info
,
212 .vendor_id
= PEN_TCG
,
213 .type
= TCG_PTS_TPM_VERSION_INFO
,
214 .value
= chunk_clone(data
),
217 return &this->public.pa_tnc_attribute
;