2 * Copyright (C) 2012 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_numeric_version.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_ietf_attr_numeric_version_t private_ietf_attr_numeric_version_t
;
26 * PA-TNC Numeric Version type (see section 4.2.3 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 * | Major Version Number |
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Minor Version Number |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Service Pack Major | Service Pack Minor |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 #define NUMERIC_VERSION_SIZE 16
44 * Private data of an ietf_attr_numeric_version_t object.
46 struct private_ietf_attr_numeric_version_t
{
49 * Public members of ietf_attr_numeric_version_t
51 ietf_attr_numeric_version_t
public;
54 * Vendor-specific attribute type
69 * Major Version Number
71 u_int32_t major_version
;
74 * Minor Version Number
76 u_int32_t minor_version
;
84 * Service Pack Major Number
86 u_int16_t service_pack_major
;
89 * Service Pack Minor Number
91 u_int16_t service_pack_minor
;
99 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
100 private_ietf_attr_numeric_version_t
*this)
105 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
106 private_ietf_attr_numeric_version_t
*this)
111 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
112 private_ietf_attr_numeric_version_t
*this)
114 return this->noskip_flag
;
117 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
118 private_ietf_attr_numeric_version_t
*this, bool noskip
)
120 this->noskip_flag
= noskip
;
123 METHOD(pa_tnc_attr_t
, build
, void,
124 private_ietf_attr_numeric_version_t
*this)
126 bio_writer_t
*writer
;
133 writer
= bio_writer_create(NUMERIC_VERSION_SIZE
);
134 writer
->write_uint32(writer
, this->major_version
);
135 writer
->write_uint32(writer
, this->minor_version
);
136 writer
->write_uint32(writer
, this->build
);
137 writer
->write_uint32(writer
, this->service_pack_major
);
138 writer
->write_uint32(writer
, this->service_pack_minor
);
140 this->value
= chunk_clone(writer
->get_buf(writer
));
141 writer
->destroy(writer
);
144 METHOD(pa_tnc_attr_t
, process
, status_t
,
145 private_ietf_attr_numeric_version_t
*this, u_int32_t
*offset
)
147 bio_reader_t
*reader
;
149 if (this->value
.len
< NUMERIC_VERSION_SIZE
)
151 DBG1(DBG_TNC
, "insufficient data for IETF numeric version");
155 reader
= bio_reader_create(this->value
);
156 reader
->read_uint32(reader
, &this->major_version
);
157 reader
->read_uint32(reader
, &this->minor_version
);
158 reader
->read_uint32(reader
, &this->build
);
159 reader
->read_uint16(reader
, &this->service_pack_major
);
160 reader
->read_uint16(reader
, &this->service_pack_minor
);
161 reader
->destroy(reader
);
166 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
167 private_ietf_attr_numeric_version_t
*this)
170 return &this->public.pa_tnc_attribute
;
173 METHOD(pa_tnc_attr_t
, destroy
, void,
174 private_ietf_attr_numeric_version_t
*this)
176 if (ref_put(&this->ref
))
178 free(this->value
.ptr
);
183 METHOD(ietf_attr_numeric_version_t
, get_version
, void,
184 private_ietf_attr_numeric_version_t
*this, u_int32_t
*major
, u_int32_t
*minor
)
188 *major
= this->major_version
;
192 *minor
= this->minor_version
;
196 METHOD(ietf_attr_numeric_version_t
, get_build
, u_int32_t
,
197 private_ietf_attr_numeric_version_t
*this)
202 METHOD(ietf_attr_numeric_version_t
, get_service_pack
, void,
203 private_ietf_attr_numeric_version_t
*this, u_int16_t
*major
, u_int16_t
*minor
)
207 *major
= this->service_pack_major
;
211 *minor
= this->service_pack_minor
;
216 * Described in header.
218 pa_tnc_attr_t
*ietf_attr_numeric_version_create(u_int32_t major
, u_int32_t minor
,
220 u_int16_t service_pack_major
,
221 u_int16_t service_pack_minor
)
223 private_ietf_attr_numeric_version_t
*this;
227 .pa_tnc_attribute
= {
228 .get_type
= _get_type
,
229 .get_value
= _get_value
,
230 .get_noskip_flag
= _get_noskip_flag
,
231 .set_noskip_flag
= _set_noskip_flag
,
237 .get_version
= _get_version
,
238 .get_build
= _get_build
,
239 .get_service_pack
= _get_service_pack
,
241 .type
= { PEN_IETF
, IETF_ATTR_NUMERIC_VERSION
},
242 .major_version
= major
,
243 .minor_version
= minor
,
245 .service_pack_major
= service_pack_major
,
246 .service_pack_minor
= service_pack_minor
,
250 return &this->public.pa_tnc_attribute
;
254 * Described in header.
256 pa_tnc_attr_t
*ietf_attr_numeric_version_create_from_data(chunk_t data
)
258 private_ietf_attr_numeric_version_t
*this;
262 .pa_tnc_attribute
= {
263 .get_type
= _get_type
,
264 .get_value
= _get_value
,
270 .get_version
= _get_version
,
271 .get_build
= _get_build
,
272 .get_service_pack
= _get_service_pack
,
274 .type
= { PEN_IETF
, IETF_ATTR_NUMERIC_VERSION
},
275 .value
= chunk_clone(data
),
279 return &this->public.pa_tnc_attribute
;