android: Implement get_contracts() method in IMC state object
[strongswan.git] / src / frontends / android / jni / libandroidbridge / byod / imc_android_state.c
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2012 Andreas Steffen
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "imc_android_state.h"
18
19 #include <tncif_names.h>
20
21 #include <utils/debug.h>
22
23 typedef struct private_imc_android_state_t private_imc_android_state_t;
24
25 /**
26 * Private data of an imc_state_t object.
27 */
28 struct private_imc_android_state_t {
29
30 /**
31 * Public interface
32 */
33 imc_android_state_t public;
34
35 /**
36 * TNCCS connection ID
37 */
38 TNC_ConnectionID connection_id;
39
40 /**
41 * TNCCS connection state
42 */
43 TNC_ConnectionState state;
44
45 /**
46 * Assessment/Evaluation Result
47 */
48 TNC_IMV_Evaluation_Result result;
49
50 /**
51 * Does the TNCCS connection support long message types?
52 */
53 bool has_long;
54
55 /**
56 * Does the TNCCS connection support exclusive delivery?
57 */
58 bool has_excl;
59
60 /**
61 * Maximum PA-TNC message size for this TNCCS connection
62 */
63 u_int32_t max_msg_len;
64
65 /**
66 * PA-TNC attribute segmentation contracts associated with TNCCS connection
67 */
68 seg_contract_manager_t *contracts;
69
70 /**
71 * TCG Platform Trust Service (PTS)
72 */
73 pts_t *pts;
74 };
75
76 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
77 private_imc_android_state_t *this)
78 {
79 return this->connection_id;
80 }
81
82 METHOD(imc_state_t, has_long, bool,
83 private_imc_android_state_t *this)
84 {
85 return this->has_long;
86 }
87
88 METHOD(imc_state_t, has_excl, bool,
89 private_imc_android_state_t *this)
90 {
91 return this->has_excl;
92 }
93
94 METHOD(imc_state_t, set_flags, void,
95 private_imc_android_state_t *this, bool has_long, bool has_excl)
96 {
97 this->has_long = has_long;
98 this->has_excl = has_excl;
99 }
100
101 METHOD(imc_state_t, set_max_msg_len, void,
102 private_imc_android_state_t *this, u_int32_t max_msg_len)
103 {
104 this->max_msg_len = max_msg_len;
105 }
106
107 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
108 private_imc_android_state_t *this)
109 {
110 return this->max_msg_len;
111 }
112
113 METHOD(imc_state_t, get_contracts, seg_contract_manager_t*,
114 private_imc_android_state_t *this)
115 {
116 return this->contracts;
117 }
118
119 METHOD(imc_state_t, change_state, void,
120 private_imc_android_state_t *this, TNC_ConnectionState new_state)
121 {
122 this->state = new_state;
123 }
124
125 METHOD(imc_state_t, set_result, void,
126 private_imc_android_state_t *this, TNC_IMCID id, TNC_IMV_Evaluation_Result result)
127 {
128 this->result = result;
129 }
130
131 METHOD(imc_state_t, get_result, bool,
132 private_imc_android_state_t *this, TNC_IMCID id, TNC_IMV_Evaluation_Result *result)
133 {
134 if (result)
135 {
136 *result = this->result;
137 }
138 return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
139 }
140
141 METHOD(imc_state_t, destroy, void,
142 private_imc_android_state_t *this)
143 {
144 this->contracts->destroy(this->contracts);
145 this->pts->destroy(this->pts);
146 free(this);
147 }
148
149 METHOD(imc_android_state_t, get_pts, pts_t*,
150 private_imc_android_state_t *this)
151 {
152 return this->pts;
153 }
154
155 /**
156 * Described in header.
157 */
158 imc_state_t *imc_android_state_create(TNC_ConnectionID connection_id)
159 {
160 private_imc_android_state_t *this;
161
162 INIT(this,
163 .public = {
164 .interface = {
165 .get_connection_id = _get_connection_id,
166 .has_long = _has_long,
167 .has_excl = _has_excl,
168 .set_flags = _set_flags,
169 .set_max_msg_len = _set_max_msg_len,
170 .get_max_msg_len = _get_max_msg_len,
171 .get_contracts = _get_contracts,
172 .change_state = _change_state,
173 .set_result = _set_result,
174 .get_result = _get_result,
175 .destroy = _destroy,
176 },
177 .get_pts = _get_pts,
178 },
179 .state = TNC_CONNECTION_STATE_CREATE,
180 .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
181 .connection_id = connection_id,
182 .contracts = seg_contract_manager_create(),
183 .pts = pts_create(TRUE),
184 );
185
186 return &this->public.interface;
187 }