aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/tnc/tnccs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcharon/tnc/tnccs')
-rw-r--r--src/libcharon/tnc/tnccs/tnccs.h18
-rw-r--r--src/libcharon/tnc/tnccs/tnccs_manager.c43
-rw-r--r--src/libcharon/tnc/tnccs/tnccs_manager.h18
3 files changed, 75 insertions, 4 deletions
diff --git a/src/libcharon/tnc/tnccs/tnccs.h b/src/libcharon/tnc/tnccs/tnccs.h
index 583512e82..443e7e7d8 100644
--- a/src/libcharon/tnc/tnccs/tnccs.h
+++ b/src/libcharon/tnc/tnccs/tnccs.h
@@ -21,10 +21,12 @@
#ifndef TNCCS_H_
#define TNCCS_H_
-typedef enum tnccs_type_t tnccs_type_t;
-
#include <library.h>
+#include <tnc/tncif.h>
+
+typedef enum tnccs_type_t tnccs_type_t;
+
/**
* Type of TNC Client/Server protocol
*/
@@ -49,4 +51,16 @@ typedef struct tnccs_t tnccs_t;
*/
typedef tnccs_t* (*tnccs_constructor_t)(bool is_server);
+/**
+ * Callback function adding a message to a TNCCS batch
+ *
+ * @param message message to be added
+ * @param message_len message length
+ * @param message_type message type
+ */
+typedef void (*tnccs_send_message_t)(tnccs_t* tncss,
+ TNC_BufferReference message,
+ TNC_UInt32 message_len,
+ TNC_MessageType message_type);
+
#endif /** TNC_H_ @}*/
diff --git a/src/libcharon/tnc/tnccs/tnccs_manager.c b/src/libcharon/tnc/tnccs/tnccs_manager.c
index c0b496928..4d0dc24b8 100644
--- a/src/libcharon/tnc/tnccs/tnccs_manager.c
+++ b/src/libcharon/tnc/tnccs/tnccs_manager.c
@@ -53,6 +53,11 @@ struct tnccs_connection_entry_t {
* TNCCS instance
*/
tnccs_t *tnccs;
+
+ /** TNCCS send message function
+ *
+ */
+ tnccs_send_message_t send_message;
};
/**
@@ -147,12 +152,14 @@ METHOD(tnccs_manager_t, create_instance, tnccs_t*,
}
METHOD(tnccs_manager_t, create_connection, TNC_ConnectionID,
- private_tnccs_manager_t *this, tnccs_t *tnccs)
+ private_tnccs_manager_t *this, tnccs_t *tnccs,
+ tnccs_send_message_t send_message)
{
tnccs_connection_entry_t *entry = malloc_thing(tnccs_connection_entry_t);
entry->id = ++this->connection_id;
entry->tnccs = tnccs;
+ entry->send_message = send_message;
this->lock->write_lock(this->lock);
this->connections->insert_last(this->connections, entry);
@@ -183,6 +190,39 @@ METHOD(tnccs_manager_t, remove_connection, void,
this->lock->unlock(this->lock);
}
+METHOD(tnccs_manager_t, send_message, TNC_Result,
+ private_tnccs_manager_t *this, TNC_ConnectionID id,
+ TNC_BufferReference message,
+ TNC_UInt32 message_len,
+ TNC_MessageType message_type)
+{
+ enumerator_t *enumerator;
+ tnccs_connection_entry_t *entry;
+ tnccs_send_message_t send_message;
+ tnccs_t *tnccs = NULL;
+
+ this->lock->write_lock(this->lock);
+ enumerator = this->connections->create_enumerator(this->connections);
+ while (enumerator->enumerate(enumerator, &entry))
+ {
+ if (id == entry->id)
+ {
+ tnccs = entry->tnccs;
+ send_message = entry->send_message;
+ break;
+ }
+ }
+ enumerator->destroy(enumerator);
+ this->lock->unlock(this->lock);
+
+ if (tnccs)
+ {
+ send_message(tnccs, message, message_len, message_type);
+ return TNC_RESULT_SUCCESS;
+ }
+ return TNC_RESULT_FATAL;
+}
+
METHOD(tnccs_manager_t, destroy, void,
private_tnccs_manager_t *this)
{
@@ -206,6 +246,7 @@ tnccs_manager_t *tnccs_manager_create()
.create_instance = _create_instance,
.create_connection = _create_connection,
.remove_connection = _remove_connection,
+ .send_message = _send_message,
.destroy = _destroy,
},
.protocols = linked_list_create(),
diff --git a/src/libcharon/tnc/tnccs/tnccs_manager.h b/src/libcharon/tnc/tnccs/tnccs_manager.h
index 40c3d0a22..127147e26 100644
--- a/src/libcharon/tnc/tnccs/tnccs_manager.h
+++ b/src/libcharon/tnc/tnccs/tnccs_manager.h
@@ -65,9 +65,11 @@ struct tnccs_manager_t {
* Create a TNCCS connection and assign a unique connection ID
*
* @param tnccs TNCCS connection instance
+ * @param send_message callback function adding a message to a TNCCS batch
* @result assigned connection ID
*/
- TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs);
+ TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs,
+ tnccs_send_message_t send_message);
/**
* Remove a TNCCS connection using its connection ID.
@@ -77,6 +79,20 @@ struct tnccs_manager_t {
void (*remove_connection)(tnccs_manager_t *this, TNC_ConnectionID id);
/**
+ * Add an IMC/IMV message to the batch of a given connection ID.
+ *
+ * @param id target connection ID
+ * @param message message to be added
+ * @param message_len message length
+ * @param message_type message type
+ * @result return code
+ */
+ TNC_Result (*send_message)(tnccs_manager_t *this, TNC_ConnectionID id,
+ TNC_BufferReference message,
+ TNC_UInt32 message_len,
+ TNC_MessageType message_type);
+
+ /**
* Destroy a tnccs_manager instance.
*/
void (*destroy)(tnccs_manager_t *this);