391572d0edbb99a6eced544e853af6361a2e6c39
[strongswan.git] / src / libpts / plugins / imc_attestation / imc_attestation_state.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 "imc_attestation_state.h"
17
18 #include <utils/linked_list.h>
19 #include <debug.h>
20
21 typedef struct private_imc_attestation_state_t private_imc_attestation_state_t;
22
23 /**
24 * Private data of an imc_attestation_state_t object.
25 */
26 struct private_imc_attestation_state_t {
27
28 /**
29 * Public members of imc_attestation_state_t
30 */
31 imc_attestation_state_t public;
32
33 /**
34 * TNCCS connection ID
35 */
36 TNC_ConnectionID connection_id;
37
38 /**
39 * TNCCS connection state
40 */
41 TNC_ConnectionState state;
42
43 /**
44 * Does the TNCCS connection support long message types?
45 */
46 bool has_long;
47
48 /**
49 * Does the TNCCS connection support exclusive delivery?
50 */
51 bool has_excl;
52
53 /**
54 * Maximum PA-TNC message size for this TNCCS connection
55 */
56 u_int32_t max_msg_len;
57
58 /**
59 * PTS object
60 */
61 pts_t *pts;
62
63 /**
64 * PTS Component Evidence list
65 */
66 linked_list_t *list;
67
68 };
69
70 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
71 private_imc_attestation_state_t *this)
72 {
73 return this->connection_id;
74 }
75
76 METHOD(imc_state_t, has_long, bool,
77 private_imc_attestation_state_t *this)
78 {
79 return this->has_long;
80 }
81
82 METHOD(imc_state_t, has_excl, bool,
83 private_imc_attestation_state_t *this)
84 {
85 return this->has_excl;
86 }
87
88 METHOD(imc_state_t, set_flags, void,
89 private_imc_attestation_state_t *this, bool has_long, bool has_excl)
90 {
91 this->has_long = has_long;
92 this->has_excl = has_excl;
93 }
94
95 METHOD(imc_state_t, set_max_msg_len, void,
96 private_imc_attestation_state_t *this, u_int32_t max_msg_len)
97 {
98 this->max_msg_len = max_msg_len;
99 }
100
101 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
102 private_imc_attestation_state_t *this)
103 {
104 return this->max_msg_len;
105 }
106
107 METHOD(imc_state_t, change_state, void,
108 private_imc_attestation_state_t *this, TNC_ConnectionState new_state)
109 {
110 this->state = new_state;
111 }
112
113
114 METHOD(imc_state_t, destroy, void,
115 private_imc_attestation_state_t *this)
116 {
117 this->pts->destroy(this->pts);
118 this->list->destroy_offset(this->list, offsetof(pts_comp_evidence_t, destroy));
119 free(this);
120 }
121
122 METHOD(imc_attestation_state_t, get_pts, pts_t*,
123 private_imc_attestation_state_t *this)
124 {
125 return this->pts;
126 }
127
128 METHOD(imc_attestation_state_t, add_evidence, void,
129 private_imc_attestation_state_t *this, pts_comp_evidence_t *evidence)
130 {
131 this->list->insert_last(this->list, evidence);
132 }
133
134 METHOD(imc_attestation_state_t, next_evidence, bool,
135 private_imc_attestation_state_t *this, pts_comp_evidence_t **evid)
136 {
137 return this->list->remove_first(this->list, (void**)evid) == SUCCESS;
138 }
139
140 /**
141 * Described in header.
142 */
143 imc_state_t *imc_attestation_state_create(TNC_ConnectionID connection_id)
144 {
145 private_imc_attestation_state_t *this;
146 char *platform_info;
147
148 INIT(this,
149 .public = {
150 .interface = {
151 .get_connection_id = _get_connection_id,
152 .has_long = _has_long,
153 .has_excl = _has_excl,
154 .set_flags = _set_flags,
155 .set_max_msg_len = _set_max_msg_len,
156 .get_max_msg_len = _get_max_msg_len,
157 .change_state = _change_state,
158 .destroy = _destroy,
159 },
160 .get_pts = _get_pts,
161 .add_evidence = _add_evidence,
162 .next_evidence = _next_evidence,
163 },
164 .connection_id = connection_id,
165 .state = TNC_CONNECTION_STATE_CREATE,
166 .pts = pts_create(TRUE),
167 .list = linked_list_create(),
168 );
169
170 platform_info = lib->settings->get_str(lib->settings,
171 "libimcv.plugins.imc-attestation.platform_info", NULL);
172 if (platform_info)
173 {
174 this->pts->set_platform_info(this->pts, platform_info);
175 }
176
177 return &this->public.interface;
178 }
179
180