diff options
Diffstat (limited to 'src/libimcv/plugins/imc_test/imc_test_state.c')
-rw-r--r-- | src/libimcv/plugins/imc_test/imc_test_state.c | 117 |
1 files changed, 114 insertions, 3 deletions
diff --git a/src/libimcv/plugins/imc_test/imc_test_state.c b/src/libimcv/plugins/imc_test/imc_test_state.c index 2adfd7d64..e70eb1492 100644 --- a/src/libimcv/plugins/imc_test/imc_test_state.c +++ b/src/libimcv/plugins/imc_test/imc_test_state.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil + * Copyright (C) 2011-2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -14,10 +15,13 @@ #include "imc_test_state.h" +#include <tncif_names.h> + #include <debug.h> #include <utils/linked_list.h> typedef struct private_imc_test_state_t private_imc_test_state_t; +typedef struct entry_t entry_t; /** * Private data of an imc_test_state_t object. @@ -40,6 +44,11 @@ struct private_imc_test_state_t { TNC_ConnectionState state; /** + * Assessment/Evaluation Results for all IMC IDs + */ + linked_list_t *results; + + /** * Does the TNCCS connection support long message types? */ bool has_long; @@ -50,11 +59,21 @@ struct private_imc_test_state_t { bool has_excl; /** + * Maximum PA-TNC message size for this TNCCS connection + */ + u_int32_t max_msg_len; + + /** * Command to transmit to IMV */ char *command; /** + * Size of the dummy attribute value to transmit to IMV + */ + int dummy_size; + + /** * Is it the first handshake? */ bool first_handshake; @@ -66,6 +85,14 @@ struct private_imc_test_state_t { }; +/** + * Stores the Assessment/Evaluation Result for a given IMC ID + */ +struct entry_t { + TNC_IMCID id; + TNC_IMV_Evaluation_Result result; +}; + METHOD(imc_state_t, get_connection_id, TNC_ConnectionID, private_imc_test_state_t *this) { @@ -91,15 +118,86 @@ METHOD(imc_state_t, set_flags, void, this->has_excl = has_excl; } +METHOD(imc_state_t, set_max_msg_len, void, + private_imc_test_state_t *this, u_int32_t max_msg_len) +{ + this->max_msg_len = max_msg_len; +} + +METHOD(imc_state_t, get_max_msg_len, u_int32_t, + private_imc_test_state_t *this) +{ + return this->max_msg_len; +} + METHOD(imc_state_t, change_state, void, private_imc_test_state_t *this, TNC_ConnectionState new_state) { this->state = new_state; } +METHOD(imc_state_t, set_result, void, + private_imc_test_state_t *this, TNC_IMCID id, + TNC_IMV_Evaluation_Result result) +{ + enumerator_t *enumerator; + entry_t *entry; + bool found = FALSE; + + DBG1(DBG_IMC, "set assessment result for IMC %u to '%N'", + id, TNC_IMV_Evaluation_Result_names, result); + + enumerator = this->results->create_enumerator(this->results); + while (enumerator->enumerate(enumerator, &entry)) + { + if (entry->id == id) + { + entry->result = result; + found = TRUE; + break; + } + } + enumerator->destroy(enumerator); + + if (!found) + { + entry = malloc_thing(entry_t); + entry->id = id; + entry->result = result; + this->results->insert_last(this->results, entry); + } +} + +METHOD(imc_state_t, get_result, bool, + private_imc_test_state_t *this, TNC_IMCID id, + TNC_IMV_Evaluation_Result *result) +{ + enumerator_t *enumerator; + entry_t *entry; + TNC_IMV_Evaluation_Result eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW; + + enumerator = this->results->create_enumerator(this->results); + while (enumerator->enumerate(enumerator, &entry)) + { + if (entry->id == id) + { + eval = entry->result; + break; + } + } + enumerator->destroy(enumerator); + + if (result) + { + *result = eval; + } + return eval != TNC_IMV_EVALUATION_RESULT_DONT_KNOW; +} + METHOD(imc_state_t, destroy, void, private_imc_test_state_t *this) { + this->results->destroy_function(this->results, free); free(this->command); free(this); } @@ -120,6 +218,13 @@ METHOD(imc_test_state_t, set_command, void, free(old_command); } +METHOD(imc_test_state_t, get_dummy_size, int, + private_imc_test_state_t *this) +{ + return this->dummy_size; +} + + METHOD(imc_test_state_t, is_first_handshake, bool, private_imc_test_state_t *this) { @@ -146,7 +251,7 @@ METHOD(imc_test_state_t, do_handshake_retry, bool, * Described in header. */ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id, - char *command, bool retry) + char *command, int dummy_size, bool retry) { private_imc_test_state_t *this; @@ -157,17 +262,24 @@ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id, .has_long = _has_long, .has_excl = _has_excl, .set_flags = _set_flags, + .set_max_msg_len = _set_max_msg_len, + .get_max_msg_len = _get_max_msg_len, .change_state = _change_state, + .set_result = _set_result, + .get_result = _get_result, .destroy = _destroy, }, .get_command = _get_command, .set_command = _set_command, + .get_dummy_size = _get_dummy_size, .is_first_handshake = _is_first_handshake, .do_handshake_retry = _do_handshake_retry, }, .state = TNC_CONNECTION_STATE_CREATE, + .results = linked_list_create(), .connection_id = connection_id, .command = strdup(command), + .dummy_size = dummy_size, .first_handshake = TRUE, .handshake_retry = retry, ); @@ -175,4 +287,3 @@ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id, return &this->public.interface; } - |