d429b90b7a2f74e876853780d4b7790337d4459c
[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 * TCG Platform Trust Service (PTS)
67 */
68 pts_t *pts;
69 };
70
71 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
72 private_imc_android_state_t *this)
73 {
74 return this->connection_id;
75 }
76
77 METHOD(imc_state_t, has_long, bool,
78 private_imc_android_state_t *this)
79 {
80 return this->has_long;
81 }
82
83 METHOD(imc_state_t, has_excl, bool,
84 private_imc_android_state_t *this)
85 {
86 return this->has_excl;
87 }
88
89 METHOD(imc_state_t, set_flags, void,
90 private_imc_android_state_t *this, bool has_long, bool has_excl)
91 {
92 this->has_long = has_long;
93 this->has_excl = has_excl;
94 }
95
96 METHOD(imc_state_t, set_max_msg_len, void,
97 private_imc_android_state_t *this, u_int32_t max_msg_len)
98 {
99 this->max_msg_len = max_msg_len;
100 }
101
102 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
103 private_imc_android_state_t *this)
104 {
105 return this->max_msg_len;
106 }
107
108 METHOD(imc_state_t, change_state, void,
109 private_imc_android_state_t *this, TNC_ConnectionState new_state)
110 {
111 this->state = new_state;
112 }
113
114 METHOD(imc_state_t, set_result, void,
115 private_imc_android_state_t *this, TNC_IMCID id, TNC_IMV_Evaluation_Result result)
116 {
117 this->result = result;
118 }
119
120 METHOD(imc_state_t, get_result, bool,
121 private_imc_android_state_t *this, TNC_IMCID id, TNC_IMV_Evaluation_Result *result)
122 {
123 if (result)
124 {
125 *result = this->result;
126 }
127 return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
128 }
129
130 METHOD(imc_state_t, destroy, void,
131 private_imc_android_state_t *this)
132 {
133 this->pts->destroy(this->pts);
134 free(this);
135 }
136
137 METHOD(imc_android_state_t, get_pts, pts_t*,
138 private_imc_android_state_t *this)
139 {
140 return this->pts;
141 }
142
143 /**
144 * Described in header.
145 */
146 imc_state_t *imc_android_state_create(TNC_ConnectionID connection_id)
147 {
148 private_imc_android_state_t *this;
149
150 INIT(this,
151 .public = {
152 .interface = {
153 .get_connection_id = _get_connection_id,
154 .has_long = _has_long,
155 .has_excl = _has_excl,
156 .set_flags = _set_flags,
157 .set_max_msg_len = _set_max_msg_len,
158 .get_max_msg_len = _get_max_msg_len,
159 .change_state = _change_state,
160 .set_result = _set_result,
161 .get_result = _get_result,
162 .destroy = _destroy,
163 },
164 .get_pts = _get_pts,
165 },
166 .state = TNC_CONNECTION_STATE_CREATE,
167 .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
168 .connection_id = connection_id,
169 .pts = pts_create(TRUE),
170 );
171
172 return &this->public.interface;
173 }