Added add_segment() method to TCG/SEG attributes
[strongswan.git] / src / libimcv / ita / ita_attr_device_id.c
1 /*
2 * Copyright (C) 2013-2014 Andreas Steffen
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 "ita_attr.h"
17 #include "ita_attr_device_id.h"
18
19 #include <pen/pen.h>
20
21 #include <utils/debug.h>
22
23 typedef struct private_ita_attr_device_id_t private_ita_attr_device_id_t;
24
25 /**
26 * Private data of an ita_attr_device_id_t object.
27 */
28 struct private_ita_attr_device_id_t {
29
30 /**
31 * Public members of ita_attr_device_id_t
32 */
33 ita_attr_device_id_t public;
34
35 /**
36 * Vendor-specific attribute type
37 */
38 pen_type_t type;
39
40 /**
41 * Length of attribute value
42 */
43 size_t length;
44
45 /**
46 * Attribute value or segment
47 */
48 chunk_t value;
49
50 /**
51 * Noskip flag
52 */
53 bool noskip_flag;
54
55 /**
56 * Reference count
57 */
58 refcount_t ref;
59 };
60
61 METHOD(pa_tnc_attr_t, get_type, pen_type_t,
62 private_ita_attr_device_id_t *this)
63 {
64 return this->type;
65 }
66
67 METHOD(pa_tnc_attr_t, get_value, chunk_t,
68 private_ita_attr_device_id_t *this)
69 {
70 return this->value;
71 }
72
73 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
74 private_ita_attr_device_id_t *this)
75 {
76 return this->noskip_flag;
77 }
78
79 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
80 private_ita_attr_device_id_t *this, bool noskip)
81 {
82 this->noskip_flag = noskip;
83 }
84
85 METHOD(pa_tnc_attr_t, build, void,
86 private_ita_attr_device_id_t *this)
87 {
88 return;
89 }
90
91 METHOD(pa_tnc_attr_t, process, status_t,
92 private_ita_attr_device_id_t *this, u_int32_t *offset)
93 {
94 *offset = 0;
95
96 if (this->value.len < this->length)
97 {
98 return NEED_MORE;
99 }
100 return SUCCESS;
101 }
102
103 METHOD(pa_tnc_attr_t, add_segment, void,
104 private_ita_attr_device_id_t *this, chunk_t segment)
105 {
106 this->value = chunk_cat("mc", this->value, segment);
107 }
108
109 METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
110 private_ita_attr_device_id_t *this)
111 {
112 ref_get(&this->ref);
113 return &this->public.pa_tnc_attribute;
114 }
115
116 METHOD(pa_tnc_attr_t, destroy, void,
117 private_ita_attr_device_id_t *this)
118 {
119 if (ref_put(&this->ref))
120 {
121 free(this->value.ptr);
122 free(this);
123 }
124 }
125
126 /**
127 * Described in header.
128 */
129 pa_tnc_attr_t *ita_attr_device_id_create_from_data(size_t length, chunk_t value)
130 {
131 private_ita_attr_device_id_t *this;
132
133 INIT(this,
134 .public = {
135 .pa_tnc_attribute = {
136 .get_type = _get_type,
137 .get_value = _get_value,
138 .get_noskip_flag = _get_noskip_flag,
139 .set_noskip_flag = _set_noskip_flag,
140 .build = _build,
141 .process = _process,
142 .add_segment = _add_segment,
143 .get_ref = _get_ref,
144 .destroy = _destroy,
145 },
146 },
147 .type = { PEN_ITA, ITA_ATTR_DEVICE_ID },
148 .length = length,
149 .value = chunk_clone(value),
150 .ref = 1,
151 );
152
153 return &this->public.pa_tnc_attribute;
154 }
155
156 /**
157 * Described in header.
158 */
159 pa_tnc_attr_t *ita_attr_device_id_create(chunk_t value)
160 {
161 return ita_attr_device_id_create_from_data(value.len, value);
162 }
163