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_meas_algo.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_meas_algo_t private_tcg_pts_attr_meas_algo_t
;
26 * PTS Measurement Algorithm
27 * see section 3.9.1 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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Reserved | Hash Algorithm Set |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 #define PTS_MEAS_ALGO_SIZE 4
38 #define PTS_MEAS_ALGO_RESERVED 0x0000
41 * Private data of an tcg_pts_attr_meas_algo_t object.
43 struct private_tcg_pts_attr_meas_algo_t
{
46 * Public members of tcg_pts_attr_meas_algo_t
48 tcg_pts_attr_meas_algo_t
public;
73 pts_meas_algorithms_t algorithms
;
77 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
78 private_tcg_pts_attr_meas_algo_t
*this)
80 return this->vendor_id
;
83 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
84 private_tcg_pts_attr_meas_algo_t
*this)
89 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
90 private_tcg_pts_attr_meas_algo_t
*this)
95 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
96 private_tcg_pts_attr_meas_algo_t
*this)
98 return this->noskip_flag
;
101 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
102 private_tcg_pts_attr_meas_algo_t
*this, bool noskip
)
104 this->noskip_flag
= noskip
;
107 METHOD(pa_tnc_attr_t
, build
, void,
108 private_tcg_pts_attr_meas_algo_t
*this)
110 bio_writer_t
*writer
;
112 writer
= bio_writer_create(PTS_MEAS_ALGO_SIZE
);
113 writer
->write_uint16(writer
, PTS_MEAS_ALGO_RESERVED
);
114 writer
->write_uint16(writer
, this->algorithms
);
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_meas_algo_t
*this, u_int32_t
*offset
)
122 bio_reader_t
*reader
;
123 u_int16_t reserved
, algorithms
;
125 if (this->value
.len
< PTS_MEAS_ALGO_SIZE
)
127 DBG1(DBG_TNC
, "insufficient data for PTS Measurement Algorithm");
131 reader
= bio_reader_create(this->value
);
132 reader
->read_uint16(reader
, &reserved
);
133 reader
->read_uint16(reader
, &algorithms
);
134 this->algorithms
= algorithms
;
135 reader
->destroy(reader
);
140 METHOD(pa_tnc_attr_t
, destroy
, void,
141 private_tcg_pts_attr_meas_algo_t
*this)
143 free(this->value
.ptr
);
147 METHOD(tcg_pts_attr_meas_algo_t
, get_algorithms
, pts_meas_algorithms_t
,
148 private_tcg_pts_attr_meas_algo_t
*this)
150 return this->algorithms
;
154 * Described in header.
156 pa_tnc_attr_t
*tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms
,
159 private_tcg_pts_attr_meas_algo_t
*this;
163 .pa_tnc_attribute
= {
164 .get_vendor_id
= _get_vendor_id
,
165 .get_type
= _get_type
,
166 .get_value
= _get_value
,
167 .get_noskip_flag
= _get_noskip_flag
,
168 .set_noskip_flag
= _set_noskip_flag
,
173 .get_algorithms
= _get_algorithms
,
175 .vendor_id
= PEN_TCG
,
176 .type
= selection ? TCG_PTS_MEAS_ALGO_SELECTION
: TCG_PTS_MEAS_ALGO
,
177 .algorithms
= algorithms
,
180 return &this->public.pa_tnc_attribute
;
185 * Described in header.
187 pa_tnc_attr_t
*tcg_pts_attr_meas_algo_create_from_data(chunk_t data
,
190 private_tcg_pts_attr_meas_algo_t
*this;
194 .pa_tnc_attribute
= {
195 .get_vendor_id
= _get_vendor_id
,
196 .get_type
= _get_type
,
197 .get_value
= _get_value
,
198 .get_noskip_flag
= _get_noskip_flag
,
199 .set_noskip_flag
= _set_noskip_flag
,
204 .get_algorithms
= _get_algorithms
,
206 .vendor_id
= PEN_TCG
,
207 .type
= selection ? TCG_PTS_MEAS_ALGO_SELECTION
: TCG_PTS_MEAS_ALGO
,
208 .value
= chunk_clone(data
),
211 return &this->public.pa_tnc_attribute
;