added TNC_TNCC_ReserveAdditionalIMCID() function
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 7 Dec 2011 16:31:49 +0000 (17:31 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 7 Dec 2011 16:31:49 +0000 (17:31 +0100)
src/libcharon/plugins/tnc_imc/tnc_imc.c
src/libcharon/plugins/tnc_imc/tnc_imc_bind_function.c
src/libcharon/plugins/tnc_imc/tnc_imc_manager.c
src/libtnccs/tnc/imc/imc.h
src/libtnccs/tnc/imc/imc_manager.h

index e13f770..6bd69dc 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Mike McCauley
- * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2010-2011 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
@@ -21,6 +22,7 @@
 
 #include <debug.h>
 #include <library.h>
+#include <utils/linked_list.h>
 #include <threading/mutex.h>
 
 typedef struct private_tnc_imc_t private_tnc_imc_t;
@@ -56,6 +58,11 @@ struct private_tnc_imc_t {
        TNC_IMCID id;
 
        /**
+        * list of additional IMC IDs
+        */
+       linked_list_t *additional_ids;
+
+       /**
         * List of message types supported by IMC - Vendor ID part
         */
        TNC_VendorIDList supported_vids;
@@ -88,6 +95,50 @@ METHOD(imc_t, get_id, TNC_IMCID,
        return this->id;
 }
 
+METHOD(imc_t, add_id, void,
+       private_tnc_imc_t *this, TNC_IMCID id)
+{
+       TNC_IMCID *new_id;
+
+       new_id = malloc_thing(TNC_IMCID);
+       *new_id = id;
+       this->additional_ids->insert_last(this->additional_ids, new_id);
+}
+
+METHOD(imc_t, has_id, bool,
+       private_tnc_imc_t *this, TNC_IMCID id)
+{
+       enumerator_t *enumerator;
+       TNC_IMCID *additional_id;
+       bool found = FALSE;
+
+       /* check primary IMC ID */
+       if (id == this->id)
+       {
+               return TRUE;
+       }
+
+       /* return if there are no additional IMC IDs */
+       if (this->additional_ids->get_count(this->additional_ids) == 0)
+       {
+               return FALSE;
+       }
+
+       /* check additional IMC IDs */
+       enumerator = this->additional_ids->create_enumerator(this->additional_ids);
+       while (enumerator->enumerate(enumerator, &additional_id))
+       {
+               if (id == *additional_id)
+               {
+                       found = TRUE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       return found;
+}
+
 METHOD(imc_t, get_name, char*,
        private_tnc_imc_t *this)
 {
@@ -257,6 +308,7 @@ METHOD(imc_t, destroy, void,
 {
        dlclose(this->handle);
        this->mutex->destroy(this->mutex);
+       this->additional_ids->destroy_function(this->additional_ids, free);
        free(this->supported_vids);
        free(this->supported_subtypes);
        free(this->name);
@@ -275,6 +327,8 @@ imc_t* tnc_imc_create(char *name, char *path)
                .public = {
                        .set_id = _set_id,
                        .get_id = _get_id,
+                       .add_id = _add_id,
+                       .has_id = _has_id,
                        .get_name = _get_name,
                        .set_message_types = _set_message_types,
                        .set_message_types_long = _set_message_types_long,
@@ -283,6 +337,7 @@ imc_t* tnc_imc_create(char *name, char *path)
         },
                .name = name,
                .path = path,
+               .additional_ids = linked_list_create(),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
        );
 
index b68899e..1df1078 100644 (file)
@@ -121,6 +121,19 @@ TNC_Result TNC_TNCC_SendMessageLong(TNC_IMCID imc_id,
 }
 
 /**
+ * Called by the IMC when it wants to reserve an additional IMC ID for itself
+ */
+TNC_Result TNC_TNCC_ReserveAdditionalIMCID(TNC_IMCID imc_id, TNC_UInt32 *new_id)
+{
+       if (!tnc->imcs->reserve_id(tnc->imcs, imc_id, new_id))
+       {
+               DBG1(DBG_TNC, "ignoring ReserveAdditionalIMCID() from unregistered IMC %u",
+                                          imc_id);
+               return TNC_RESULT_INVALID_PARAMETER;
+       }
+}
+
+/**
  * Called by the IMC when it needs a function pointer
  */
 TNC_Result TNC_TNCC_BindFunction(TNC_IMCID id,
@@ -147,6 +160,10 @@ TNC_Result TNC_TNCC_BindFunction(TNC_IMCID id,
        {
                *function_pointer = (void*)TNC_TNCC_SendMessageLong;
        }
+    else if (streq(function_name, "TNC_TNCC_ReserveAdditionalIMCID"))
+       {
+               *function_pointer = (void*)TNC_TNCC_ReserveAdditionalIMCID;
+       }
     else
        {
                return TNC_RESULT_INVALID_PARAMETER;
index 3c1db37..5e06d9e 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Mike McCauley
- * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2010-2011 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
@@ -130,8 +131,30 @@ METHOD(imc_manager_t, is_registered, bool,
        enumerator = this->imcs->create_enumerator(this->imcs);
        while (enumerator->enumerate(enumerator, &imc))
        {
-               if (id == imc->get_id(imc))
+               if (imc->has_id(imc, id))
+               {
+                       found = TRUE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       return found;
+}
+
+METHOD(imc_manager_t, reserve_id, bool,
+       private_tnc_imc_manager_t *this, TNC_IMCID id, TNC_UInt32 *new_id)
+{
+       enumerator_t *enumerator;
+       imc_t *imc;
+       bool found = FALSE;
+
+       enumerator = this->imcs->create_enumerator(this->imcs);
+       while (enumerator->enumerate(enumerator, &imc))
+       {
+               if (imc->get_id(imc))
                {
+                       imc->add_id(imc, this->next_imc_id++);
                        found = TRUE;
                        break;
                }
@@ -304,6 +327,7 @@ imc_manager_t* tnc_imc_manager_create(void)
                        .remove = _remove_, /* avoid name conflict with stdio.h */
                        .load = _load,
                        .is_registered = _is_registered,
+                       .reserve_id = _reserve_id,
                        .get_preferred_language = _get_preferred_language,
                        .notify_connection_change = _notify_connection_change,
                        .begin_handshake = _begin_handshake,
index 3545005..3794fd2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Andreas Steffen
+ * Copyright (C) 2010-2011 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -144,6 +144,20 @@ struct imc_t {
        TNC_IMCID (*get_id)(imc_t *this);
 
        /**
+        * Assign an additional ID to an imc_t object.
+        *
+        * @param id                                    additional IMC ID to be assigned
+        */
+       void (*add_id)(imc_t *this, TNC_IMCID id);
+
+       /**
+        * Checks if the ID is assigned to the imc_t object.
+        *
+        * @return                                              TRUE if IMC ID is assigned to imc_t object
+        */
+       bool (*has_id)(imc_t *this, TNC_IMCID id);
+
+       /**
         * Returns the name of an imc_t object.
         *
         * @return                                              name of IMC
index 38eafbb..ef2dcc6 100644 (file)
@@ -66,6 +66,15 @@ struct imc_manager_t {
        bool (*is_registered)(imc_manager_t *this, TNC_IMCID id);
 
        /**
+        * Reserve an additional ID for an IMC
+        *
+        * @param id                            ID of IMC instance
+        * @param new_id                        reserved ID assigned to IMC
+        * @return                                      TRUE if primary IMC ID was used
+        */
+       bool (*reserve_id)(imc_manager_t *this, TNC_IMCID id, TNC_UInt32 *new_id);
+
+       /**
         * Return the preferred language for recommendations
         *
         * @return                                      preferred language string