Implemented TCG PTS Attributes
[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 private_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 private_tcg_pts_attr_req_proto_caps_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)
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 return FAILED;
123 }
124 reader = bio_reader_create(this->value);
125 reader->read_uint32 (reader, &reserved);
126 reader->destroy(reader);
127
128 return SUCCESS;
129 }
130
131 METHOD(pa_tnc_attr_t, destroy, void,
132 private_tcg_pts_attr_get_tpm_version_info_t *this)
133 {
134 free(this->value.ptr);
135 free(this);
136 }
137
138 /**
139 * Described in header.
140 */
141 pa_tnc_attr_t *tcg_pts_attr_get_tpm_version_info_create()
142 {
143 private_tcg_pts_attr_get_tpm_version_info_t *this;
144
145 INIT(this,
146 .public = {
147 .pa_tnc_attribute = {
148 .get_vendor_id = _get_vendor_id,
149 .get_type = _get_type,
150 .get_value = _get_value,
151 .get_noskip_flag = _get_noskip_flag,
152 .set_noskip_flag = _set_noskip_flag,
153 .build = _build,
154 .process = _process,
155 .destroy = _destroy,
156 },
157 },
158 .vendor_id = PEN_TCG,
159 .type = TCG_PTS_GET_TPM_VERSION_INFO,
160 );
161
162 return &this->public.pa_tnc_attribute;
163 }
164
165
166 /**
167 * Described in header.
168 */
169 pa_tnc_attr_t *tcg_pts_attr_get_tpm_version_info_create_from_data(chunk_t data)
170 {
171 private_tcg_pts_attr_get_tpm_version_info_t *this;
172
173 INIT(this,
174 .public = {
175 .pa_tnc_attribute = {
176 .get_vendor_id = _get_vendor_id,
177 .get_type = _get_type,
178 .get_value = _get_value,
179 .get_noskip_flag = _get_noskip_flag,
180 .set_noskip_flag = _set_noskip_flag,
181 .build = _build,
182 .process = _process,
183 .destroy = _destroy,
184 },
185 },
186 .vendor_id = PEN_TCG,
187 .type = TCG_PTS_GET_TPM_VERSION_INFO,
188 .value = chunk_clone(data),
189 );
190
191 return &this->public.pa_tnc_attribute;
192 }