2 * Copyright (C) 2012-2014 Andreas Steffen
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 "ietf_attr_assess_result.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <utils/debug.h>
23 typedef struct private_ietf_attr_assess_result_t private_ietf_attr_assess_result_t
;
26 * PA-TNC Product Information type (see section 4.2.2 of RFC 5792)
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 * | Assessment Result |
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 #define ASSESS_RESULT_SIZE 4
38 * Private data of an ietf_attr_assess_result_t object.
40 struct private_ietf_attr_assess_result_t
{
43 * Public members of ietf_attr_assess_result_t
45 ietf_attr_assess_result_t
public;
48 * Vendor-specific attribute type
53 * Length of attribute value
58 * Attribute value or segment
78 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
79 private_ietf_attr_assess_result_t
*this)
84 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
85 private_ietf_attr_assess_result_t
*this)
90 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
91 private_ietf_attr_assess_result_t
*this)
93 return this->noskip_flag
;
96 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
97 private_ietf_attr_assess_result_t
*this, bool noskip
)
99 this->noskip_flag
= noskip
;
102 METHOD(pa_tnc_attr_t
, build
, void,
103 private_ietf_attr_assess_result_t
*this)
105 bio_writer_t
*writer
;
112 writer
= bio_writer_create(ASSESS_RESULT_SIZE
);
113 writer
->write_uint32(writer
, this->result
);
114 this->value
= writer
->extract_buf(writer
);
115 this->length
= this->value
.len
;
116 writer
->destroy(writer
);
119 METHOD(pa_tnc_attr_t
, process
, status_t
,
120 private_ietf_attr_assess_result_t
*this, u_int32_t
*offset
)
122 bio_reader_t
*reader
;
126 if (this->value
.len
< this->length
)
130 if (this->value
.len
< ASSESS_RESULT_SIZE
)
132 DBG1(DBG_TNC
, "insufficient data for IETF assessment result");
135 reader
= bio_reader_create(this->value
);
136 reader
->read_uint32(reader
, &this->result
);
137 reader
->destroy(reader
);
142 METHOD(pa_tnc_attr_t
, add_segment
, void,
143 private_ietf_attr_assess_result_t
*this, chunk_t segment
)
145 this->value
= chunk_cat("mc", this->value
, segment
);
148 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
149 private_ietf_attr_assess_result_t
*this)
152 return &this->public.pa_tnc_attribute
;
155 METHOD(pa_tnc_attr_t
, destroy
, void,
156 private_ietf_attr_assess_result_t
*this)
158 if (ref_put(&this->ref
))
160 free(this->value
.ptr
);
165 METHOD(ietf_attr_assess_result_t
, get_result
, u_int32_t
,
166 private_ietf_attr_assess_result_t
*this)
172 * Described in header.
174 pa_tnc_attr_t
*ietf_attr_assess_result_create(u_int32_t result
)
176 private_ietf_attr_assess_result_t
*this;
180 .pa_tnc_attribute
= {
181 .get_type
= _get_type
,
182 .get_value
= _get_value
,
183 .get_noskip_flag
= _get_noskip_flag
,
184 .set_noskip_flag
= _set_noskip_flag
,
187 .add_segment
= _add_segment
,
191 .get_result
= _get_result
,
193 .type
= { PEN_IETF
, IETF_ATTR_ASSESSMENT_RESULT
},
198 return &this->public.pa_tnc_attribute
;
202 * Described in header.
204 pa_tnc_attr_t
*ietf_attr_assess_result_create_from_data(size_t length
,
207 private_ietf_attr_assess_result_t
*this;
211 .pa_tnc_attribute
= {
212 .get_type
= _get_type
,
213 .get_value
= _get_value
,
214 .get_noskip_flag
= _get_noskip_flag
,
215 .set_noskip_flag
= _set_noskip_flag
,
218 .add_segment
= _add_segment
,
222 .get_result
= _get_result
,
224 .type
= { PEN_IETF
, IETF_ATTR_ASSESSMENT_RESULT
},
226 .value
= chunk_clone(data
),
230 return &this->public.pa_tnc_attribute
;