21d0c4c58633d7715b26243a574988b91430c532
[strongswan.git] / src / libimcv / plugins / imv_test / imv_test_state.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "imv_test_state.h"
16
17 #include <debug.h>
18
19 typedef struct private_imv_test_state_t private_imv_test_state_t;
20
21 /**
22 * Private data of an imv_test_state_t object.
23 */
24 struct private_imv_test_state_t {
25
26 /**
27 * Public members of imv_test_state_t
28 */
29 imv_test_state_t public;
30
31 /**
32 * TNCCS connection ID
33 */
34 TNC_ConnectionID connection_id;
35
36 /**
37 * TNCCS connection state
38 */
39 TNC_ConnectionState state;
40
41 /**
42 * IMV action recommendation
43 */
44 TNC_IMV_Action_Recommendation rec;
45
46 /**
47 * IMV evaluation result
48 */
49 TNC_IMV_Evaluation_Result eval;
50
51 /**
52 * IMC-IMV round-trip count
53 */
54 int rounds;
55
56 };
57
58 METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
59 private_imv_test_state_t *this)
60 {
61 return this->connection_id;
62 }
63
64 METHOD(imv_state_t, change_state, void,
65 private_imv_test_state_t *this, TNC_ConnectionState new_state)
66 {
67 this->state = new_state;
68 }
69
70 METHOD(imv_state_t, get_recommendation, void,
71 private_imv_test_state_t *this, TNC_IMV_Action_Recommendation *rec,
72 TNC_IMV_Evaluation_Result *eval)
73 {
74 *rec = this->rec;
75 *eval = this->eval;
76 }
77
78 METHOD(imv_state_t, set_recommendation, void,
79 private_imv_test_state_t *this, TNC_IMV_Action_Recommendation rec,
80 TNC_IMV_Evaluation_Result eval)
81 {
82 this->rec = rec;
83 this->eval = eval;
84 }
85
86 METHOD(imv_state_t, destroy, void,
87 private_imv_test_state_t *this)
88 {
89 free(this);
90 }
91
92 METHOD(imv_test_state_t, another_round, bool,
93 private_imv_test_state_t *this)
94 {
95 return (this->rounds-- > 0);
96 }
97
98 /**
99 * Described in header.
100 */
101 imv_state_t *imv_test_state_create(TNC_ConnectionID connection_id, int rounds)
102 {
103 private_imv_test_state_t *this;
104
105 INIT(this,
106 .public = {
107 .interface = {
108 .get_connection_id = _get_connection_id,
109 .change_state = _change_state,
110 .get_recommendation = _get_recommendation,
111 .set_recommendation = _set_recommendation,
112 .destroy = _destroy,
113 },
114 .another_round = _another_round,
115 },
116 .state = TNC_CONNECTION_STATE_CREATE,
117 .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
118 .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
119 .connection_id = connection_id,
120 .rounds = rounds,
121 );
122
123 return &this->public.interface;
124 }
125
126