Debugged TCG PTS attributes implementations
[strongswan.git] / src / libimcv / tcg / tcg_pts_attr_get_tpm_version_info.c
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
3 * HSR Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "tcg_pts_attr_get_tpm_version_info.h"
17
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <debug.h>
22
23 typedef struct private_tcg_pts_attr_get_tpm_version_info_t private_tcg_pts_attr_get_tpm_version_info_t;
24
25 /**
26 * Get TPM Version Information (see section 3.10 of PTS Protocol: Binding to TNC IF-M Specification)
27 *
28 * 1 2 3
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
30 *
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Reserved |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 *
35 */
36
37 #define PTS_GET_TPM_VER_INFO_SIZE 4
38 #define PTS_GET_TPM_VER_INFO_RESERVED 0x00
39
40 /**
41 * Private data of an tcg_pts_attr_get_tpm_version_info_t object.
42 */
43 struct private_tcg_pts_attr_get_tpm_version_info_t {
44
45 /**
46 * Public members of tcg_pts_attr_get_tpm_version_info_t
47 */
48 tcg_pts_attr_get_tpm_version_info_t public;
49
50 /**
51 * Attribute vendor ID
52 */
53 pen_t vendor_id;
54
55 /**
56 * Attribute type
57 */
58 u_int32_t type;
59
60 /**
61 * Attribute value
62 */
63 chunk_t value;
64
65 /**
66 * Noskip flag
67 */
68 bool noskip_flag;
69 };
70
71 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
72 private_tcg_pts_attr_get_tpm_version_info_t *this)
73 {
74 return this->vendor_id;
75 }
76
77 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
78 private_tcg_pts_attr_get_tpm_version_info_t *this)
79 {
80 return this->type;
81 }
82
83 METHOD(pa_tnc_attr_t, get_value, chunk_t,
84 private_tcg_pts_attr_get_tpm_version_info_t *this)
85 {
86 return this->value;
87 }
88
89 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
90 private_tcg_pts_attr_get_tpm_version_info_t *this)
91 {
92 return this->noskip_flag;
93 }
94
95 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
96 private_tcg_pts_attr_get_tpm_version_info_t *this, bool noskip)
97 {
98 this->noskip_flag = noskip;
99 }
100
101 METHOD(pa_tnc_attr_t, build, void,
102 private_tcg_pts_attr_get_tpm_version_info_t *this)
103 {
104 bio_writer_t *writer;
105
106 writer = bio_writer_create(PTS_GET_TPM_VER_INFO_SIZE);
107 writer->write_uint32 (writer, PTS_GET_TPM_VER_INFO_RESERVED);
108
109 this->value = chunk_clone(writer->get_buf(writer));
110 writer->destroy(writer);
111 }
112
113 METHOD(pa_tnc_attr_t, process, status_t,
114 private_tcg_pts_attr_get_tpm_version_info_t *this, u_int32_t *offset)
115 {
116 bio_reader_t *reader;
117 u_int32_t reserved;
118
119 if (this->value.len < PTS_GET_TPM_VER_INFO_SIZE)
120 {
121 DBG1(DBG_TNC, "insufficient data for Get TPM Version Information");
122 *offset = 0;
123 return FAILED;
124 }
125 reader = bio_reader_create(this->value);
126 reader->read_uint32 (reader, &reserved);
127 reader->destroy(reader);
128
129 return SUCCESS;
130 }
131
132 METHOD(pa_tnc_attr_t, destroy, void,
133 private_tcg_pts_attr_get_tpm_version_info_t *this)
134 {
135 free(this->value.ptr);
136 free(this);
137 }
138
139 /**
140 * Described in header.
141 */
142 pa_tnc_attr_t *tcg_pts_attr_get_tpm_version_info_create()
143 {
144 private_tcg_pts_attr_get_tpm_version_info_t *this;
145
146 INIT(this,
147 .public = {
148 .pa_tnc_attribute = {
149 .get_vendor_id = _get_vendor_id,
150 .get_type = _get_type,
151 .get_value = _get_value,
152 .get_noskip_flag = _get_noskip_flag,
153 .set_noskip_flag = _set_noskip_flag,
154 .build = _build,
155 .process = _process,
156 .destroy = _destroy,
157 },
158 },
159 .vendor_id = PEN_TCG,
160 .type = TCG_PTS_GET_TPM_VERSION_INFO,
161 );
162
163 return &this->public.pa_tnc_attribute;
164 }
165
166
167 /**
168 * Described in header.
169 */
170 pa_tnc_attr_t *tcg_pts_attr_get_tpm_version_info_create_from_data(chunk_t data)
171 {
172 private_tcg_pts_attr_get_tpm_version_info_t *this;
173
174 INIT(this,
175 .public = {
176 .pa_tnc_attribute = {
177 .get_vendor_id = _get_vendor_id,
178 .get_type = _get_type,
179 .get_value = _get_value,
180 .get_noskip_flag = _get_noskip_flag,
181 .set_noskip_flag = _set_noskip_flag,
182 .build = _build,
183 .process = _process,
184 .destroy = _destroy,
185 },
186 },
187 .vendor_id = PEN_TCG,
188 .type = TCG_PTS_GET_TPM_VERSION_INFO,
189 .value = chunk_clone(data),
190 );
191
192 return &this->public.pa_tnc_attribute;
193 }