implemented provide_recommendation callback function
authorAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 8 Nov 2010 18:25:25 +0000 (19:25 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 9 Nov 2010 19:43:51 +0000 (20:43 +0100)
src/libcharon/plugins/tnc_imv/tnc_imv_bind_function.c
src/libcharon/plugins/tnccs_20/tnccs_20.c
src/libcharon/tnc/tnccs/tnccs.h
src/libcharon/tnc/tnccs/tnccs_manager.c
src/libcharon/tnc/tnccs/tnccs_manager.h

index 48de93c..ba2fe5d 100644 (file)
@@ -67,7 +67,8 @@ TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
                                                                TNC_IMV_Evaluation_Result evaluation)
 {
        DBG2(DBG_TNC,"TNCS_ProvideRecommendation %u %u", imv_id, connection_id);
-       return TNC_RESULT_SUCCESS;
+       return charon->tnccs->provide_recommendation(charon->tnccs, imv_id,
+                                                       connection_id, recommendation, evaluation);
 }
 
 /**
index 8f6f11e..3b19e91 100644 (file)
@@ -60,6 +60,14 @@ METHOD(tnccs_t, send_message, void,
        this->batch = chunk_cat("mc", batch, msg);
 }
 
+METHOD(tnccs_t, provide_recommendation, void,
+       private_tnccs_20_t* this, TNC_IMVID imv_id,
+                                                         TNC_IMV_Action_Recommendation recommendation,
+                                                         TNC_IMV_Evaluation_Result evaluation)
+{
+       DBG1(DBG_TNC, "TNCCS 2.0 provide recommendation");
+}
+
 METHOD(tls_t, process, status_t,
        private_tnccs_20_t *this, void *buf, size_t buflen)
 {
@@ -69,7 +77,8 @@ METHOD(tls_t, process, status_t,
        if (this->is_server && !this->connection_id)
        {
                this->connection_id = charon->tnccs->create_connection(charon->tnccs,
-                                                                                               (tnccs_t*)this, _send_message);
+                                                                               (tnccs_t*)this,
+                                                                               _send_message, _provide_recommendation);
                charon->imvs->notify_connection_change(charon->imvs,
                                                        this->connection_id, TNC_CONNECTION_STATE_CREATE);
        }
@@ -111,7 +120,7 @@ METHOD(tls_t, build, status_t,
        if (!this->is_server && !this->connection_id)
        {
                this->connection_id = charon->tnccs->create_connection(charon->tnccs,
-                                                                                               (tnccs_t*)this, _send_message);
+                                                                               (tnccs_t*)this, _send_message, NULL);
                charon->imcs->notify_connection_change(charon->imcs,
                                                        this->connection_id, TNC_CONNECTION_STATE_CREATE);
                charon->imcs->notify_connection_change(charon->imcs,
index 2be8852..86759a1 100644 (file)
@@ -22,6 +22,7 @@
 #define TNCCS_H_
 
 #include <tnc/tncif.h>
+#include <tnc/tncifimv.h>
 #include <library.h>
 
 typedef enum tnccs_type_t tnccs_type_t;
@@ -53,13 +54,27 @@ 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
+ * @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);
 
+
+/**
+ * Callback function delivering an IMV Action Recommendation and
+ * IMV Evaluation Result to the TNCS
+ *
+ * @param imv_id                       ID of the IMV providing the recommendation
+ * @param recommendation       action recommendation
+ * @param evaluation           evaluation result
+ */
+typedef void (*tnccs_provide_recommendation_t)(tnccs_t* tncss,
+                                                               TNC_IMVID imv_id,
+                                                               TNC_IMV_Action_Recommendation recommendation,
+                                                               TNC_IMV_Evaluation_Result evaluation);
+
 #endif /** TNCCS_H_ @}*/
index 4d0dc24..5df214f 100644 (file)
@@ -58,6 +58,11 @@ struct tnccs_connection_entry_t {
         *
         */
        tnccs_send_message_t send_message;
+
+       /** TNCS provide recommendation function
+        *
+        */
+       tnccs_provide_recommendation_t provide_recommendation;
 };
 
 /**
@@ -198,7 +203,7 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
 {
        enumerator_t *enumerator;
        tnccs_connection_entry_t *entry;
-       tnccs_send_message_t send_message;
+       tnccs_send_message_t send_message = NULL;
        tnccs_t *tnccs = NULL;
 
        this->lock->write_lock(this->lock);
@@ -215,7 +220,7 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
        enumerator->destroy(enumerator);
        this->lock->unlock(this->lock);
 
-       if (tnccs)
+       if (tnccs && send_message)
        {
                send_message(tnccs, message, message_len, message_type);
                return TNC_RESULT_SUCCESS;
@@ -223,6 +228,39 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
        return TNC_RESULT_FATAL;
 }
 
+METHOD(tnccs_manager_t, provide_recommendation, TNC_Result,
+       private_tnccs_manager_t *this, TNC_IMVID imv_id,
+                                                                  TNC_ConnectionID id,
+                                                                  TNC_IMV_Action_Recommendation recommendation,
+                                                                  TNC_IMV_Evaluation_Result evaluation)
+{
+       enumerator_t *enumerator;
+       tnccs_connection_entry_t *entry;
+       tnccs_provide_recommendation_t provide_recommendation = NULL;
+       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;
+                       provide_recommendation = entry->provide_recommendation;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->lock->unlock(this->lock);
+
+       if (tnccs && provide_recommendation)
+       {
+               provide_recommendation(tnccs, imv_id, recommendation, evaluation);
+               return TNC_RESULT_SUCCESS;
+        }
+       return TNC_RESULT_FATAL;
+}
+
 METHOD(tnccs_manager_t, destroy, void,
        private_tnccs_manager_t *this)
 {
@@ -247,6 +285,7 @@ tnccs_manager_t *tnccs_manager_create()
                                .create_connection = _create_connection,
                                .remove_connection = _remove_connection,
                                .send_message = _send_message,
+                               .provide_recommendation = _provide_recommendation,
                                .destroy = _destroy,
                        },
                        .protocols = linked_list_create(),
index adcb2a7..11a5fa0 100644 (file)
@@ -61,14 +61,18 @@ struct tnccs_manager_t {
                                                                bool is_server);
 
        /**
-        * Create a TNCCS connection and assign a unique connection ID
+        * Create a TNCCS connection and assign a unique connection ID as well as
+        * callback functions for adding a message to a TNCCS batch and delivering
+        * an IMV recommendation, respectively
         *
-        * @param tnccs                 TNCCS connection instance
-        * @param send_message  callback function adding a message to a TNCCS batch
-        * @return                              assigned connection ID
+        * @param tnccs                                         TNCCS connection instance
+        * @param send_message                          TNCCS callback function 
+        * @param provide_recommendation        TNCS callback function 
+        * @return                                                      assigned connection ID
         */
        TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs,
-                                                                                 tnccs_send_message_t send_message);
+                                                tnccs_send_message_t send_message,
+                                                tnccs_provide_recommendation_t provide_recommendation);
 
        /**
         * Remove a TNCCS connection using its connection ID.
@@ -93,6 +97,20 @@ struct tnccs_manager_t {
                                                           TNC_MessageType message_type);
 
        /**
+        * Deliver an IMV Action Recommendation and IMV Evaluation Result to the TNCS
+        *
+        * @param imv_id                        ID of the IMV providing the recommendation
+        * @param connection_id         target connection ID
+        * @param recommendation        action recommendation
+        * @param evaluation            evaluation result
+        */
+       TNC_Result (*provide_recommendation)(tnccs_manager_t *this,
+                                                               TNC_IMVID imv_id,
+                                                               TNC_ConnectionID connection_id,
+                                                               TNC_IMV_Action_Recommendation recommendation,
+                                                               TNC_IMV_Evaluation_Result evaluation);
+
+       /**
         * Destroy a tnccs_manager instance.
         */
        void (*destroy)(tnccs_manager_t *this);