added TNC_TNCC_ReserveAdditionalIMCID() function

This commit is contained in:
Andreas Steffen
2011-12-07 17:31:49 +01:00
parent 8b8fcfd631
commit 80ca4e50c9
5 changed files with 123 additions and 4 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_imc_t private_tnc_imc_t;
@@ -55,6 +57,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
*/
@@ -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),
);
@@ -120,6 +120,19 @@ TNC_Result TNC_TNCC_SendMessageLong(TNC_IMCID imc_id,
msg_flags, msg, msg_len, msg_vid, msg_subtype);
}
/**
* 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
*/
@@ -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;
@@ -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,7 +131,7 @@ 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;
@@ -141,6 +142,28 @@ METHOD(imc_manager_t, is_registered, bool,
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;
}
}
enumerator->destroy(enumerator);
return found;
}
METHOD(imc_manager_t, get_preferred_language, char*,
private_tnc_imc_manager_t *this)
{
@@ -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,
+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 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.
*
+9
View File
@@ -65,6 +65,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
*