#include "generator.h"
-#include <types.h>
+#include <library.h>
#include <daemon.h>
#include <utils/linked_list.h>
#include <encoding/payloads/payload.h>
break;
default:
- DBG1(SIG_DBG_ENC, "U_INT Type %N is not supported",
+ DBG1(DBG_ENC, "U_INT Type %N is not supported",
encoding_type_names, int_type);
return;
/* U_INT Types of multiple then 8 bits must be aligned */
if (((number_of_bits % 8) == 0) && (this->current_bit != 0))
{
- DBG1(SIG_DBG_ENC, "U_INT Type %N is not 8 Bit aligned",
+ DBG1(DBG_ENC, "U_INT Type %N is not 8 Bit aligned",
encoding_type_names, int_type);
/* current bit has to be zero for values multiple of 8 bits */
return;
u_int8_t low_val = *(this->out_position) & 0x0F;
/* highval is set, low_val is not changed */
*(this->out_position) = high_val | low_val;
- DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
+ DBG3(DBG_ENC, " => %d", *(this->out_position));
/* write position is not changed, just bit position is moved */
this->current_bit = 4;
}
/* lowval of current byte in buffer has to be set to the new value*/
u_int low_val = *((u_int8_t *)(this->data_struct + offset)) & 0x0F;
*(this->out_position) = high_val | low_val;
- DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
+ DBG3(DBG_ENC, " => %d", *(this->out_position));
this->out_position++;
this->current_bit = 0;
}
else
{
- DBG1(SIG_DBG_ENC, "U_INT_4 Type is not 4 Bit aligned");
+ DBG1(DBG_ENC, "U_INT_4 Type is not 4 Bit aligned");
/* 4 Bit integers must have a 4 bit alignment */
return;
};
{
/* 8 bit values are written as they are */
*this->out_position = *((u_int8_t *)(this->data_struct + offset));
- DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
+ DBG3(DBG_ENC, " => %d", *(this->out_position));
this->out_position++;
break;
/* attribute type must not change first bit uf current byte ! */
if (this->current_bit != 1)
{
- DBG1(SIG_DBG_ENC, "ATTRIBUTE FORMAT flag is not set");
+ DBG1(DBG_ENC, "ATTRIBUTE FORMAT flag is not set");
/* first bit has to be set! */
return;
}
/* get value of attribute format flag */
u_int8_t attribute_format_flag = *(this->out_position) & 0x80;
/* get attribute type value as 16 bit integer*/
- u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
- /* last bit must be unset */
- int16_val = int16_val & 0xFF7F;
-
- int16_val = int16_val | attribute_format_flag;
- DBG3(SIG_DBG_ENC, " => %d", int16_val);
+ u_int16_t int16_val = *((u_int16_t*)(this->data_struct + offset));
+ /* unset most significant bit */
+ int16_val &= 0x7FFF;
+ if (attribute_format_flag)
+ {
+ int16_val |= 0x8000;
+ }
+ int16_val = htons(int16_val);
+ DBG3(DBG_ENC, " => %d", int16_val);
/* write bytes to buffer (set bit is overwritten)*/
this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
this->current_bit = 0;
case CONFIGURATION_ATTRIBUTE_LENGTH:
{
u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
- DBG3(SIG_DBG_ENC, " => %b", (void*)&int16_val, sizeof(int16_val));
+ DBG3(DBG_ENC, " => %b", (void*)&int16_val, sizeof(int16_val));
this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
break;
}
case U_INT_32:
{
u_int32_t int32_val = htonl(*((u_int32_t*)(this->data_struct + offset)));
- DBG3(SIG_DBG_ENC, " => %b", (void*)&int32_val, sizeof(int32_val));
+ DBG3(DBG_ENC, " => %b", (void*)&int32_val, sizeof(int32_val));
this->write_bytes_to_buffer(this,&int32_val,sizeof(u_int32_t));
break;
}
/* 64 bit integers are written as two 32 bit integers */
u_int32_t int32_val_low = htonl(*((u_int32_t*)(this->data_struct + offset)));
u_int32_t int32_val_high = htonl(*((u_int32_t*)(this->data_struct + offset) + 1));
- DBG3(SIG_DBG_ENC, " => %b %b",
+ DBG3(DBG_ENC, " => %b %b",
(void*)&int32_val_low, sizeof(int32_val_low),
(void*)&int32_val_high, sizeof(int32_val_high));
/* TODO add support for big endian machines */
{
/* 64 bit are written as they come :-) */
this->write_bytes_to_buffer(this,(this->data_struct + offset),sizeof(u_int64_t));
- DBG3(SIG_DBG_ENC, " => %b", (void*)(this->data_struct + offset), sizeof(u_int64_t));
+ DBG3(DBG_ENC, " => %b", (void*)(this->data_struct + offset), sizeof(u_int64_t));
break;
}
default:
{
- DBG1(SIG_DBG_ENC, "U_INT Type %N is not supported",
+ DBG1(DBG_ENC, "U_INT Type %N is not supported",
encoding_type_names, int_type);
return;
}
/* only one bit or 8 bit fields are supported */
if ((bits != 1) && (bits != 8))
{
- DBG1(SIG_DBG_ENC, "reserved field of %d bits cannot be generated", bits);
+ DBG1(DBG_ENC, "reserved field of %d bits cannot be generated", bits);
return ;
}
/* make sure enough space is available in buffer */
/* one byte processing*/
if (this->current_bit > 0)
{
- DBG1(SIG_DBG_ENC, "reserved field cannot be written cause "
+ DBG1(DBG_ENC, "reserved field cannot be written cause "
"alignement of current bit is %d", this->current_bit);
return;
}
*(this->out_position) = *(this->out_position) | flag;
- DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
+ DBG3(DBG_ENC, " => %d", *(this->out_position));
this->current_bit++;
if (this->current_bit >= 8)
{
if (this->current_bit != 0)
{
- DBG1(SIG_DBG_ENC, "can not generate a chunk at Bitpos %d", this->current_bit);
+ DBG1(DBG_ENC, "can not generate a chunk at Bitpos %d", this->current_bit);
return ;
}
/* position in buffer */
chunk_t *attribute_value = (chunk_t *)(this->data_struct + offset);
- DBG3(SIG_DBG_ENC, " => %B", attribute_value);
+ DBG3(DBG_ENC, " => %B", attribute_value);
/* use write_bytes_to_buffer function to do the job */
this->write_bytes_to_buffer(this,attribute_value->ptr,attribute_value->len);
size_t new_buffer_size = old_buffer_size + GENERATOR_DATA_BUFFER_INCREASE_VALUE;
size_t out_position_offset = ((this->out_position) - (this->buffer));
- DBG2(SIG_DBG_ENC, "increased gen buffer from %d to %d byte",
+ DBG2(DBG_ENC, "increased gen buffer from %d to %d byte",
old_buffer_size, new_buffer_size);
/* Reallocate space for new buffer */
memcpy(data->ptr,this->buffer,data_length);
data->len = data_length;
- DBG3(SIG_DBG_ENC, "generated data of this generator %B", data);
+ DBG3(DBG_ENC, "generated data of this generator %B", data);
}
/**
payload_start = this->out_position;
- DBG2(SIG_DBG_ENC, "generating payload of type %N",
+ DBG2(DBG_ENC, "generating payload of type %N",
payload_type_names, payload_type);
/* each payload has its own encoding rules */
for (i = 0; i < rule_count;i++)
{
- DBG2(SIG_DBG_ENC, " generating rule %d %N",
+ DBG2(DBG_ENC, " generating rule %d %N",
i, encoding_type_names, rules[i].type);
switch (rules[i].type)
{
case SPIS:
case CONFIGURATION_ATTRIBUTE_VALUE:
case VID_DATA:
- case EAP_MESSAGE:
+ case EAP_DATA:
{
u_int32_t payload_length_position_offset;
u_int16_t length_of_payload;
case CONFIGURATION_ATTRIBUTE_VALUE:
header_length = CONFIGURATION_ATTRIBUTE_HEADER_LENGTH;
break;
- case EAP_MESSAGE:
+ case EAP_DATA:
header_length = EAP_PAYLOAD_HEADER_LENGTH;
break;
default:
u_int16_t int16_val;
/* proposals are stored in a linked list and so accessed */
linked_list_t *proposals = *((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_proposal;
+
/* create forward iterator */
iterator = proposals->create_iterator(proposals,TRUE);
/* every proposal is processed (iterative call )*/
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)¤t_proposal))
{
- payload_t *current_proposal;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)¤t_proposal);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_proposal);
after_generate_position_offset = this->get_current_buffer_offset(this);
int16_val = htons(length_of_sa_payload);
this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
break;
- }
+ }
case TRANSFORMS:
- {
+ {
/* before iterative generate the transforms, store the current length position */
u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
u_int16_t length_of_proposal = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH + this->last_spi_size;
u_int16_t int16_val;
linked_list_t *transforms = *((linked_list_t **)(this->data_struct + rules[i].offset));
iterator_t *iterator;
-
+ payload_t *current_transform;
+
/* create forward iterator */
iterator = transforms->create_iterator(transforms,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)¤t_transform))
{
- payload_t *current_transform;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)¤t_transform);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_transform);
after_generate_position_offset = this->get_current_buffer_offset(this);
}
iterator->destroy(iterator);
-
+
int16_val = htons(length_of_proposal);
this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
{
/* before iterative generate the transform attributes, store the current length position */
u_int32_t transform_length_position_offset = this->last_payload_length_position_offset;
-
u_int16_t length_of_transform = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
u_int16_t int16_val;
linked_list_t *transform_attributes =*((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_attribute;
+
/* create forward iterator */
iterator = transform_attributes->create_iterator(transform_attributes,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)¤t_attribute))
{
- payload_t *current_attribute;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)¤t_attribute);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_attribute);
after_generate_position_offset = this->get_current_buffer_offset(this);
{
/* before iterative generate the configuration attributes, store the current length position */
u_int32_t configurations_length_position_offset = this->last_payload_length_position_offset;
-
u_int16_t length_of_configurations = CP_PAYLOAD_HEADER_LENGTH;
u_int16_t int16_val;
linked_list_t *configuration_attributes =*((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_attribute;
+
/* create forward iterator */
iterator = configuration_attributes->create_iterator(configuration_attributes,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)¤t_attribute))
{
- payload_t *current_attribute;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)¤t_attribute);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_attribute);
after_generate_position_offset = this->get_current_buffer_offset(this);
{
if (this->attribute_format == FALSE)
{
- DBG2(SIG_DBG_ENC, "attribute value has not fixed size");
+ DBG2(DBG_ENC, "attribute value has not fixed size");
/* the attribute value is generated */
this->generate_from_chunk(this,rules[i].offset);
}
u_int16_t int16_val;
/* traffic selectors are stored in a linked list and so accessed */
linked_list_t *traffic_selectors = *((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_traffic_selector_substructure;
+
/* create forward iterator */
iterator = traffic_selectors->create_iterator(traffic_selectors,TRUE);
/* every proposal is processed (iterative call )*/
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void **)¤t_traffic_selector_substructure))
{
- payload_t *current_traffic_selector_substructure;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
-
- iterator->current(iterator,(void **)¤t_traffic_selector_substructure);
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_traffic_selector_substructure);
break;
}
default:
- DBG1(SIG_DBG_ENC, "field type %N is not supported",
+ DBG1(DBG_ENC, "field type %N is not supported",
encoding_type_names, rules[i].type);
return;
}
}
- DBG2(SIG_DBG_ENC, "generating %N payload finished",
+ DBG2(DBG_ENC, "generating %N payload finished",
payload_type_names, payload_type);
- DBG3(SIG_DBG_ENC, "generated data for this payload %b",
+ DBG3(DBG_ENC, "generated data for this payload %b",
payload_start, this->out_position-payload_start);
}