added TNC_TNCS_ReserveAdditionalIMVID() function

This commit is contained in:
Andreas Steffen
2011-12-07 17:55:26 +01:00
parent 194b23bb6e
commit aae76e9ba0
5 changed files with 125 additions and 5 deletions
+56 -1
View 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_imv_t private_tnc_imv_t;
@@ -55,6 +57,11 @@ struct private_tnc_imv_t {
*/
TNC_IMVID id;
/**
* List of additional IMV IDs
*/
linked_list_t *additional_ids;
/**
* List of message types supported by IMV - Vendor ID part
*/
@@ -88,6 +95,50 @@ METHOD(imv_t, get_id, TNC_IMVID,
return this->id;
}
METHOD(imv_t, add_id, void,
private_tnc_imv_t *this, TNC_IMVID id)
{
TNC_IMVID *new_id;
new_id = malloc_thing(TNC_IMVID);
*new_id = id;
this->additional_ids->insert_last(this->additional_ids, new_id);
}
METHOD(imv_t, has_id, bool,
private_tnc_imv_t *this, TNC_IMVID id)
{
enumerator_t *enumerator;
TNC_IMVID *additional_id;
bool found = FALSE;
/* check primary IMV ID */
if (id == this->id)
{
return TRUE;
}
/* return if there are no additional IMV IDs */
if (this->additional_ids->get_count(this->additional_ids) == 0)
{
return FALSE;
}
/* check additional IMV 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(imv_t, get_name, char*,
private_tnc_imv_t *this)
{
@@ -257,6 +308,7 @@ METHOD(imv_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 @@ imv_t* tnc_imv_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 @@ imv_t* tnc_imv_create(char *name, char *path)
},
.name = name,
.path = path,
.additional_ids = linked_list_create(),
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
);
@@ -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
@@ -180,6 +181,20 @@ TNC_Result TNC_TNCS_SetAttribute(TNC_IMVID imv_id,
attribute_id, buffer_len, buffer);
}
/**
* Called by the IMV when it wants to reserve an additional IMV ID for itself
*/
TNC_Result TNC_TNCC_ReserveAdditionalIMVID(TNC_IMVID imv_id, TNC_UInt32 *new_id)
{
if (tnc->imvs->reserve_id(tnc->imvs, imv_id, new_id))
{
return TNC_RESULT_SUCCESS;
}
DBG1(DBG_TNC, "ignoring ReserveAdditionalIMVID() from unregistered IMV %u",
imv_id);
return TNC_RESULT_INVALID_PARAMETER;
}
/**
* Called by the IMV when it needs a function pointer
*/
@@ -219,6 +234,10 @@ TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
{
*function_pointer = (void*)TNC_TNCS_SetAttribute;
}
else if (streq(function_name, "TNC_TNCS_ReserveAdditionalIMVID"))
{
*function_pointer = (void*)TNC_TNCS_ReserveAdditionalIMVID;
}
else
{
return TNC_RESULT_INVALID_PARAMETER;
@@ -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
@@ -147,7 +148,7 @@ METHOD(imv_manager_t, is_registered, bool,
enumerator = this->imvs->create_enumerator(this->imvs);
while (enumerator->enumerate(enumerator, &imv))
{
if (id == imv->get_id(imv))
if (imv->has_id(imv, id))
{
found = TRUE;
break;
@@ -158,6 +159,28 @@ METHOD(imv_manager_t, is_registered, bool,
return found;
}
METHOD(imv_manager_t, reserve_id, bool,
private_tnc_imv_manager_t *this, TNC_IMVID id, TNC_UInt32 *new_id)
{
enumerator_t *enumerator;
imv_t *imv;
bool found = FALSE;
enumerator = this->imvs->create_enumerator(this->imvs);
while (enumerator->enumerate(enumerator, &imv))
{
if (imv->get_id(imv))
{
imv->add_id(imv, this->next_imv_id++);
found = TRUE;
break;
}
}
enumerator->destroy(enumerator);
return found;
}
METHOD(imv_manager_t, get_recommendation_policy, recommendation_policy_t,
private_tnc_imv_manager_t *this)
{
@@ -384,6 +407,7 @@ imv_manager_t* tnc_imv_manager_create(void)
.remove = _remove_, /* avoid name conflict with stdio.h */
.load = _load,
.is_registered = _is_registered,
.reserve_id = _reserve_id,
.get_recommendation_policy = _get_recommendation_policy,
.create_recommendations = _create_recommendations,
.enforce_recommendation = _enforce_recommendation,
+15 -1
View 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
@@ -143,6 +143,20 @@ struct imv_t {
*/
TNC_IMVID (*get_id)(imv_t *this);
/**
* Assign an additional ID to an imv_t object.
*
* @param id additional IMV ID to be assigned
*/
void (*add_id)(imv_t *this, TNC_IMVID id);
/**
* Checks if the ID is assigned to the imv_t object.
*
* @return TRUE if IMV ID is assigned to imv_t object
*/
bool (*has_id)(imv_t *this, TNC_IMVID id);
/**
* Returns the name of an imv_t object.
*
+8
View File
@@ -67,6 +67,14 @@ struct imv_manager_t {
*/
bool (*is_registered)(imv_manager_t *this, TNC_IMVID id);
/**
* Reserve an additional ID for an IMV
*
* @param id ID of IMV instance
* @param new_id reserved ID assigned to IMV
* @return TRUE if primary IMV ID was used
*/
bool (*reserve_id)(imv_manager_t *this, TNC_IMVID id, TNC_UInt32 *new_id);
/**
* Get the configured recommendation policy