Deleted unnecessary debug statement
[strongswan.git] / src / libimcv / tcg / tcg_pts_attr_req_file_meas.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_req_file_meas.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_req_file_meas_t private_tcg_pts_attr_req_file_meas_t;
24
25 /**
26 * Request File Measurement
27 * see section 3.19.1 of PTS Protocol: Binding to TNC IF-M Specification
28 *
29 * 1 2 3
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
31 *
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Flags | Reserved | Request ID |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Delimiter |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * ~ Fully Qualified File Path Name (Variable Length) ~
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 */
40
41 #define PTS_REQ_FILE_MEAS_SIZE 8
42 #define PTS_REQ_FILE_MEAS_RESERVED 0x00
43
44 /**
45 * Private data of an tcg_pts_attr_req_file_meas_t object.
46 */
47 struct private_tcg_pts_attr_req_file_meas_t {
48
49 /**
50 * Public members of tcg_pts_attr_req_file_meas_t
51 */
52 tcg_pts_attr_req_file_meas_t public;
53
54 /**
55 * Attribute vendor ID
56 */
57 pen_t vendor_id;
58
59 /**
60 * Attribute type
61 */
62 u_int32_t type;
63
64 /**
65 * Attribute value
66 */
67 chunk_t value;
68
69 /**
70 * Noskip flag
71 */
72 bool noskip_flag;
73
74 /**
75 * Directory Contents flag
76 */
77 bool directory_flag;
78
79 /**
80 * Request ID
81 */
82 u_int16_t request_id;
83
84 /**
85 * UTF8 Encoding of Delimiter Character
86 */
87 u_int32_t delimiter;
88
89 /**
90 * Fully Qualified File Path Name
91 */
92 chunk_t path;
93
94 };
95
96 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
97 private_tcg_pts_attr_req_file_meas_t *this)
98 {
99 return this->vendor_id;
100 }
101
102 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
103 private_tcg_pts_attr_req_file_meas_t *this)
104 {
105 return this->type;
106 }
107
108 METHOD(pa_tnc_attr_t, get_value, chunk_t,
109 private_tcg_pts_attr_req_file_meas_t *this)
110 {
111 return this->value;
112 }
113
114 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
115 private_tcg_pts_attr_req_file_meas_t *this)
116 {
117 return this->noskip_flag;
118 }
119
120 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
121 private_tcg_pts_attr_req_file_meas_t *this, bool noskip)
122 {
123 this->noskip_flag = noskip;
124 }
125
126 METHOD(pa_tnc_attr_t, build, void,
127 private_tcg_pts_attr_req_file_meas_t *this)
128 {
129 bio_writer_t *writer;
130 u_int8_t flags = 0;
131
132 writer = bio_writer_create(PTS_REQ_FILE_MEAS_SIZE);
133
134 if (this->directory_flag)
135 {
136 flags += 128;
137 }
138 writer->write_uint8(writer, flags);
139 writer->write_uint8(writer, PTS_REQ_FILE_MEAS_RESERVED);
140 writer->write_uint16(writer, this->request_id);
141 writer->write_uint32(writer, this->delimiter);
142 writer->write_data (writer, this->path);
143
144 this->value = chunk_clone(writer->get_buf(writer));
145 writer->destroy(writer);
146 }
147
148 METHOD(pa_tnc_attr_t, process, status_t,
149 private_tcg_pts_attr_req_file_meas_t *this, u_int32_t *offset)
150 {
151 bio_reader_t *reader;
152 u_int8_t flags;
153 u_int8_t reserved;
154 u_int32_t file_path_len;
155
156 if (this->value.len < PTS_REQ_FILE_MEAS_SIZE)
157 {
158 DBG1(DBG_TNC, "insufficient data for Request File Measurement");
159 *offset = 0;
160 return FAILED;
161 }
162 reader = bio_reader_create(this->value);
163
164 reader->read_uint8(reader, &flags);
165 if((flags >> 7) & 1) this->directory_flag = true;
166
167 reader->read_uint8(reader, &reserved);
168 reader->read_uint16(reader, &this->request_id);
169 reader->read_uint32(reader, &this->delimiter);
170 file_path_len = reader->remaining(reader);
171
172 reader->read_data(reader, file_path_len, &this->path);
173 this->path = chunk_clone(this->path);
174
175 reader->destroy(reader);
176 return SUCCESS;
177 }
178
179 METHOD(pa_tnc_attr_t, destroy, void,
180 private_tcg_pts_attr_req_file_meas_t *this)
181 {
182 free(this->value.ptr);
183 free(this->path.ptr);
184 free(this);
185 }
186
187 METHOD(tcg_pts_attr_req_file_meas_t, get_directory_flag, bool,
188 private_tcg_pts_attr_req_file_meas_t *this)
189 {
190 return this->directory_flag;
191 }
192
193 METHOD(tcg_pts_attr_req_file_meas_t, set_directory_flag, void,
194 private_tcg_pts_attr_req_file_meas_t *this, bool directory_flag)
195 {
196 this->directory_flag = directory_flag;
197 }
198
199 METHOD(tcg_pts_attr_req_file_meas_t, get_request_id, u_int16_t,
200 private_tcg_pts_attr_req_file_meas_t *this)
201 {
202 return this->request_id;
203 }
204
205 METHOD(tcg_pts_attr_req_file_meas_t, set_request_id, void,
206 private_tcg_pts_attr_req_file_meas_t *this, u_int16_t request_id)
207 {
208 this->request_id = request_id;
209 }
210
211 METHOD(tcg_pts_attr_req_file_meas_t, get_delimiter, u_int32_t,
212 private_tcg_pts_attr_req_file_meas_t *this)
213 {
214 return this->delimiter;
215 }
216
217 METHOD(tcg_pts_attr_req_file_meas_t, set_delimiter, void,
218 private_tcg_pts_attr_req_file_meas_t *this, u_int32_t delimiter)
219 {
220 this->delimiter = delimiter;
221 }
222
223 METHOD(tcg_pts_attr_req_file_meas_t, get_file_path, chunk_t,
224 private_tcg_pts_attr_req_file_meas_t *this)
225 {
226 return this->path;
227 }
228
229 METHOD(tcg_pts_attr_req_file_meas_t, set_file_path, void,
230 private_tcg_pts_attr_req_file_meas_t *this, chunk_t path)
231 {
232 this->path = path;
233 }
234
235 /**
236 * Described in header.
237 */
238 pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create(
239 bool directory_flag,
240 u_int16_t request_id,
241 u_int32_t delimiter,
242 chunk_t path)
243 {
244 private_tcg_pts_attr_req_file_meas_t *this;
245
246 INIT(this,
247 .public = {
248 .pa_tnc_attribute = {
249 .get_vendor_id = _get_vendor_id,
250 .get_type = _get_type,
251 .get_value = _get_value,
252 .get_noskip_flag = _get_noskip_flag,
253 .set_noskip_flag = _set_noskip_flag,
254 .build = _build,
255 .process = _process,
256 .destroy = _destroy,
257 },
258 .get_directory_flag= _get_directory_flag,
259 .set_directory_flag= _set_directory_flag,
260 .get_request_id = _get_request_id,
261 .set_request_id = _set_request_id,
262 .get_delimiter = _get_delimiter,
263 .set_delimiter = _set_delimiter,
264 .get_file_path = _get_file_path,
265 .set_file_path = _set_file_path,
266 },
267 .vendor_id = PEN_TCG,
268 .type = TCG_PTS_REQ_FILE_MEAS,
269 .directory_flag = directory_flag,
270 .request_id = request_id,
271 .delimiter = delimiter,
272 .path = path,
273 );
274
275 return &this->public.pa_tnc_attribute;
276 }
277
278
279 /**
280 * Described in header.
281 */
282 pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create_from_data(chunk_t data)
283 {
284 private_tcg_pts_attr_req_file_meas_t *this;
285
286 INIT(this,
287 .public = {
288 .pa_tnc_attribute = {
289 .get_vendor_id = _get_vendor_id,
290 .get_type = _get_type,
291 .get_value = _get_value,
292 .get_noskip_flag = _get_noskip_flag,
293 .set_noskip_flag = _set_noskip_flag,
294 .build = _build,
295 .process = _process,
296 .destroy = _destroy,
297 },
298 .get_directory_flag= _get_directory_flag,
299 .set_directory_flag= _set_directory_flag,
300 .get_request_id = _get_request_id,
301 .set_request_id = _set_request_id,
302 .get_delimiter = _get_delimiter,
303 .set_delimiter = _set_delimiter,
304 .get_file_path = _get_file_path,
305 .set_file_path = _set_file_path,
306 },
307 .vendor_id = PEN_TCG,
308 .type = TCG_PTS_REQ_FILE_MEAS,
309 .value = chunk_clone(data),
310 );
311
312 return &this->public.pa_tnc_attribute;
313 }