summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburet2008-03-12 18:07:08 +0000
committerburet2008-03-12 18:07:08 +0000
commitf0b33b90efa6e8be3b4a905b52dfa172e6fe44ed (patch)
tree0843a4ce95dc22721c974f16d9e0243b203003f7
parent4135487d8996da51edf67b349dc47d75bfcf858c (diff)
Maximus V2: - HAL HLE => modify the INTERFACE message format of the IPMBox. - Maximus Python => add a function to automatically reallocate released buffers.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1593 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--hal/hle/defs.h2
-rw-r--r--hal/hle/maximus/inc/maximus_ether.h4
-rw-r--r--hal/hle/maximus/src/maximus_ether.c180
-rw-r--r--hal/hle/maximus/src/maximus_ipmbox.c140
-rw-r--r--hal/hle/maximus/test/src/test_maximus_ether.c128
-rw-r--r--hal/hle/maximus/test/src/test_maximus_ipmbox.c126
-rw-r--r--interface/sniffer/src/sniffer.c4
-rw-r--r--interface/sniffer/test/src/test-sniffer.c8
-rw-r--r--maximus/common/interfaces/Maximus.h8
-rw-r--r--maximus/common/types/ethernet_types.h29
-rw-r--r--maximus/coreengine/inc/MaximusTest.h2
-rw-r--r--maximus/coreengine/src/Maximus.cpp15
-rw-r--r--maximus/coreengine/src/MaximusTest.cpp21
-rw-r--r--maximus/ethernet/src/EtherSciMsg.cpp5
-rw-r--r--maximus/python/lib/cesar/sta_cesar.py8
-rw-r--r--maximus/python/maximus/ethernet/__init__.py2
-rw-r--r--maximus/python/maximus/ethernet/buffer.py103
-rw-r--r--maximus/python/maximus/ethernet/sniffer.py2
-rw-r--r--maximus/python/maximus/macframe/msdu.py1
-rw-r--r--maximus/python/maximus/station/sta.py70
-rw-r--r--maximus/python/py/test_ether.py48
-rw-r--r--maximus/python/src/interface_module.cpp30
-rw-r--r--maximus/python/test/test_ethernet.py85
-rw-r--r--maximus/python/test/test_interface.py6
-rw-r--r--maximus/stationtest/src/test_ether.c41
-rw-r--r--maximus/stationtest/src/test_station.c4
26 files changed, 687 insertions, 385 deletions
diff --git a/hal/hle/defs.h b/hal/hle/defs.h
index a936068b95..aab3e53a76 100644
--- a/hal/hle/defs.h
+++ b/hal/hle/defs.h
@@ -45,7 +45,7 @@ enum hle_msg_type_t
HLE_MSG_TYPE_DATA = 0x00, /*< Data or MME message type. */
HLE_MSG_TYPE_BUFFER_ADD = 0x01, /*< Buffer alloc message type. */
HLE_MSG_TYPE_SEND_DONE = 0x02, /*< Buffer dealloc message type. */
- HLE_MSG_TYPE_INTERFACE_SNIFFER = 0x03,/*< Sniffer message type. */
+ HLE_MSG_TYPE_INTERFACE = 0x03, /*< Interface message type. */
HLE_MSG_TYPE_NB, /*< Number of defined message types. */
HLE_MSG_TYPE_NONE = HLE_MSG_TYPE_NB /*< Invalid message type. */
};
diff --git a/hal/hle/maximus/inc/maximus_ether.h b/hal/hle/maximus/inc/maximus_ether.h
index b63d72df16..3d03f17f53 100644
--- a/hal/hle/maximus/inc/maximus_ether.h
+++ b/hal/hle/maximus/inc/maximus_ether.h
@@ -50,9 +50,7 @@ int maximus_ether_recv (sci_msg_t *msg, void *ipmbox);
*/
int maximus_ether_recv_invalid (ipmbox_t *ctx, sci_msg_t *msg);
int maximus_ether_recv_data (ipmbox_t *ctx, sci_msg_t *msg);
-int maximus_ether_recv_mme (ipmbox_t *ctx, sci_msg_t *msg);
-int maximus_ether_recv_data_buffer_add (ipmbox_t *ctx, sci_msg_t *msg);
-int maximus_ether_recv_mme_buffer_add (ipmbox_t *ctx, sci_msg_t *msg);
+int maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg);
/**
* Send an Ether SCI message of type DATA, MME, BUFFER_RELEASED, or SNIFFER to Maximus.
diff --git a/hal/hle/maximus/src/maximus_ether.c b/hal/hle/maximus/src/maximus_ether.c
index 3434df32b1..3281eaa0fa 100644
--- a/hal/hle/maximus/src/maximus_ether.c
+++ b/hal/hle/maximus/src/maximus_ether.c
@@ -27,10 +27,11 @@
typedef int (*maximus_ether_recv_function)(ipmbox_t *ctx, sci_msg_t *msg);
maximus_ether_recv_function maximus_ether_function_array[ETHERNET_TYPE_NB] = { &maximus_ether_recv_invalid, // none
- &maximus_ether_recv_data,
- &maximus_ether_recv_mme,
- &maximus_ether_recv_data_buffer_add,
- &maximus_ether_recv_mme_buffer_add,
+ &maximus_ether_recv_data, // data
+ &maximus_ether_recv_data, // mme
+ &maximus_ether_recv_buffer_add, // data buffer add
+ &maximus_ether_recv_buffer_add, // mme buffer add
+ &maximus_ether_recv_buffer_add, // interface buffer add
&maximus_ether_recv_invalid, // buffer released
&maximus_ether_recv_invalid }; // sniffer
@@ -38,7 +39,7 @@ maximus_ether_recv_function maximus_ether_function_array[ETHERNET_TYPE_NB] = { &
* Fill a blank ether header
* \param ctx current ipmbox context
* \param msg pointer to sci message to fill header
- * \param type type of message (DATA, MME, DATA_BUFFER_ADD, MME_BUFFER_ADD, BUFFER_RELEASED, or SNIFFER)
+ * \param type type of message (DATA, MME, DATA_BUFFER_ADD, MME_BUFFER_ADD, INTERFACE_BUFFER_ADD, BUFFER_RELEASED, or SNIFFER)
* \param sniffer_type type of sniffed packet (MME or BEACON)
* \param flags indicates sniffed packet encryption and way
* \return 0 if ok, -1 if it fails with errno =
@@ -197,63 +198,24 @@ maximus_ether_recv_data (ipmbox_t *ctx, sci_msg_t *msg)
// set hdr param
// DATA length (11 bits): length of data into DATA buffer
- // type (1 bit): 0 for DATA type
+ // type (1 bit):
+ // 0 for DATA type
+ // 1 for MME type
hdr.param = msg->length << 1;
+ if (ETHERNET_TYPE_MME == msg->hdr.ether->type)
+ {
+ hdr.param |= 1;
+ }
- /* Update mailbox. */
- // set hdr
- memcpy(&ctx->rx.mailbox[ctx->rx.length], &hdr, sizeof(ipmbox_msg_hdr_t));
- // set buffer pointer (32 bits): pointer to DATA buffer
- ctx->rx.mailbox[ctx->rx.length + 1] = (u32)msg->data_begin;
- sci_msg_pop(msg, msg->length);
- // update total length of messages
- ctx->rx.length += hdr.length + 1;
-
- // raise interruption
- maximus_pending_isrs |= (1 << HAL_HLE_INTERRUPT_IPMBOX);
-
- ret = 0;
- }
-
- return ret;
-}
-
-int
-maximus_ether_recv_mme (ipmbox_t *ctx, sci_msg_t *msg)
-{
- int ret = -1;
-
- dbg_assert_ptr(ctx);
- dbg_assert_ptr(msg);
- dbg_assert_ptr(msg->hdr.ether);
- dbg_assert_ptr(msg->sci_hdr);
- dbg_assert((ETH_PACKET_MIN_SIZE <= msg->length) && (ETH_PACKET_MAX_SIZE >= msg->length));
- dbg_assert_ptr(msg->data_begin);
- if((NULL == ctx)
- || (NULL == msg)
- || (NULL == msg->hdr.ether)
- || (NULL == msg->sci_hdr)
- || ((ETH_PACKET_MIN_SIZE > msg->length) || (ETH_PACKET_MAX_SIZE < msg->length))
- || (NULL == msg->data_begin))
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- ipmbox_msg_hdr_t hdr;
-
- // set hdr type
- hdr.type = HLE_MSG_TYPE_DATA;
-
- // set hdr length
- hdr.length = 1;
-
- // set hdr param
- // DATA length (11 bits): length of data into DATA buffer
- // type (1 bit): 1 for MME type
- hdr.param = (msg->length << 1) | 1;
+ if (MAXIMUS_HLE_MAILBOX_MAX_SIZE <= ctx->rx.length + hdr.length + 1)
+ {
+ errno = ENOSPC;
+ station_log(&my_station, STATION_LOG_WARNING, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d because mailbox is full", __FUNCTION__, errno);
+ dbg_assert_print(!ctx->warning_assert, "errno = %d because mailbox is full", errno);
+ // reset total length of messages
+ ctx->rx.length = 0;
+ }
/* Update mailbox. */
// set hdr
@@ -274,7 +236,7 @@ maximus_ether_recv_mme (ipmbox_t *ctx, sci_msg_t *msg)
}
int
-maximus_ether_recv_data_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
+maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
{
int ret = -1;
@@ -308,87 +270,33 @@ maximus_ether_recv_data_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
hdr.length = 1;
// set hdr param
- // alloc type (1 bit): 0 for DATA allocation
+ // alloc type (3 bits):
+ // 0 for DATA buffer allocation
+ // 1 for MME buffer allocation
+ // 2 for INTERFACE buffer allocation
hdr.param = 0;
+ if (ETHERNET_TYPE_MME_BUFFER_ADD == msg->hdr.ether->type)
+ {
+ hdr.param = 1;
+ }
+ if (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == msg->hdr.ether->type)
+ {
+ hdr.param = 2;
+ }
// get requested buffer nb
memcpy(&buffer_nb, msg->data_begin, sizeof(u32));
sci_msg_pop(msg, sizeof(u32));
- /* Update mailbox. */
- for (i = ctx->rx.length; i < ctx->rx.length + (hdr.length + 1) * buffer_nb; i += hdr.length + 1)
+ if (MAXIMUS_HLE_MAILBOX_MAX_SIZE <= ctx->rx.length + (hdr.length + 1) * buffer_nb)
{
- u32 buffer_id;
- maximus_hle_buffer_t *buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
-
- // get buffer id
- memcpy(&buffer_id, msg->data_begin, sizeof(u32));
- sci_msg_pop(msg, sizeof(u32));
-
- // set hdr
- memcpy(&ctx->rx.mailbox[i], &hdr, sizeof(ipmbox_msg_hdr_t));
-
- // set buffer pointer (32 bits): pointer to allocated buffer
- ctx->last_buffer->next = buffer;
- ctx->last_buffer = buffer;
- ctx->last_buffer->next = NULL;
- ctx->last_buffer->id = buffer_id;
- ctx->last_buffer->data = (u32 *)malloc(2048);
- ctx->rx.mailbox[i+1] = (u32)ctx->last_buffer->data;
+ errno = ENOSPC;
+ station_log(&my_station, STATION_LOG_WARNING, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d because mailbox is full", __FUNCTION__, errno);
+ dbg_assert_print(!ctx->warning_assert, "errno = %d because mailbox is full", errno);
+ // reset total length of messages
+ ctx->rx.length = 0;
}
- // update total length of messages
- ctx->rx.length += (hdr.length + 1) * buffer_nb;
-
- // raise interruption
- maximus_pending_isrs |= (1 << HAL_HLE_INTERRUPT_IPMBOX);
-
- ret = 0;
- }
-
- return ret;
-}
-
-int
-maximus_ether_recv_mme_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
-{
- int ret = -1;
-
- dbg_assert_ptr(ctx);
- dbg_assert_ptr(msg);
- dbg_assert_ptr(msg->hdr.ether);
- dbg_assert_ptr(msg->sci_hdr);
- dbg_assert((int)(2 * sizeof(u32)) <= msg->length);
- dbg_assert_ptr(msg->data_begin);
- if((NULL == ctx)
- || (NULL == msg)
- || (NULL == msg->hdr.ether)
- || (NULL == msg->sci_hdr)
- || ((int)(2 * sizeof(u32)) > msg->length)
- || (NULL == msg->data_begin))
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- ipmbox_msg_hdr_t hdr;
- u32 buffer_nb; // number of buffers to be allocated
- uint i;
-
- // set hdr type
- hdr.type = HLE_MSG_TYPE_BUFFER_ADD;
-
- // set hdr length
- hdr.length = 1;
-
- // set hdr param
- // alloc type (1 bit): 1 for MME allocation
- hdr.param = 1;
-
- // get requested buffer nb
- memcpy(&buffer_nb, msg->data_begin, sizeof(u32));
- sci_msg_pop(msg, sizeof(u32));
/* Update mailbox. */
for (i = ctx->rx.length; i < ctx->rx.length + (hdr.length + 1) * buffer_nb; i += hdr.length + 1)
@@ -444,7 +352,8 @@ maximus_ether_send (ipmbox_t *ctx, u8 type, u8 sniffer_type, u8 flags, uint data
dbg_assert((ETHERNET_TYPE_NB > type)
&& (ETHERNET_TYPE_NONE < type)
&& (ETHERNET_TYPE_DATA_BUFFER_ADD != type)
- && (ETHERNET_TYPE_MME_BUFFER_ADD != type));
+ && (ETHERNET_TYPE_MME_BUFFER_ADD != type)
+ && (ETHERNET_TYPE_INTERFACE_BUFFER_ADD != type));
dbg_assert((SNIFFER_BEACON == sniffer_type) || (SNIFFER_MME == sniffer_type));
dbg_assert(ETHERNET_FLAG_MAX >= flags);
dbg_assert(0 != data_length);
@@ -454,6 +363,7 @@ maximus_ether_send (ipmbox_t *ctx, u8 type, u8 sniffer_type, u8 flags, uint data
|| (ETHERNET_TYPE_NONE >= type)
|| (ETHERNET_TYPE_DATA_BUFFER_ADD == type)
|| (ETHERNET_TYPE_MME_BUFFER_ADD == type)
+ || (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == type)
|| ((SNIFFER_BEACON != sniffer_type) && (SNIFFER_MME != sniffer_type))
|| (ETHERNET_FLAG_MAX < flags)
|| (0 == data_length)
diff --git a/hal/hle/maximus/src/maximus_ipmbox.c b/hal/hle/maximus/src/maximus_ipmbox.c
index 6f1cbd71b3..f8a142e517 100644
--- a/hal/hle/maximus/src/maximus_ipmbox.c
+++ b/hal/hle/maximus/src/maximus_ipmbox.c
@@ -188,10 +188,11 @@ ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
{
dbg_assert_ptr(ctx);
dbg_assert_ptr(first_msg);
- dbg_assert(2 == length);
+ dbg_assert((2 <= length) && (3 >= length));
if ((NULL == ctx)
|| (NULL == first_msg)
- || (2 != length))
+ || (2 > length)
+ || (3 < length))
{
errno = EINVAL;
station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
@@ -201,8 +202,12 @@ ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
{
ipmbox_msg_hdr_t hdr = *(ipmbox_msg_hdr_t *)first_msg;
dbg_assert(HLE_MSG_TYPE_NB > hdr.type);
- dbg_assert(1 == hdr.length);
- if ((HLE_MSG_TYPE_NB <= hdr.type) || (1 != hdr.length))
+ dbg_assert(((HLE_MSG_TYPE_INTERFACE != hdr.type) && (2 == length))
+ || (HLE_MSG_TYPE_INTERFACE == hdr.type));
+ dbg_assert(length - 1 == hdr.length);
+ if ((HLE_MSG_TYPE_NB <= hdr.type)
+ || ((HLE_MSG_TYPE_INTERFACE != hdr.type) && (2 != length))
+ || (length - 1 != hdr.length))
{
errno = EINVAL;
station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
@@ -210,31 +215,88 @@ ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
}
else
{
- if (HLE_MSG_TYPE_DATA == hdr.type)
+ if ((HLE_MSG_TYPE_DATA == hdr.type)
+ || (HLE_MSG_TYPE_INTERFACE == hdr.type))
{
+ // to send message
+ u8 type = ETHERNET_TYPE_NONE;
+ u8 sniffer_type = 0;
+ u8 flags = ETHERNET_FLAG_NONE;
+ uint data_length = 0;
+ u32 data = 0;
+
// to release buffer
bool found = false;
maximus_hle_buffer_t *current_buffer = ctx->first_buffer;
maximus_hle_buffer_t *previous_buffer = current_buffer;
- // get DATA or MME length (11 bits): length of data into DATA or MME buffer
- uint data_length = (uint)((hdr.param & 0xFFE) >> 1);
-
- // get type (1 bit): DATA or MME type
- // 0: DATA type
- // 1: MME type
- u8 type = (u8)(hdr.param & 0x001);
- if (0 == type)
+ if (HLE_MSG_TYPE_DATA == hdr.type)
{
- type = ETHERNET_TYPE_DATA;
+ // get type (1 bit): DATA or MME type
+ // 0: DATA type
+ // 1: MME type
+ if (0 == (u8)(hdr.param & 0x00001))
+ {
+ type = ETHERNET_TYPE_DATA;
+ }
+ else // (1 == (u8)(hdr.param & 0x001))
+ {
+ type = ETHERNET_TYPE_MME;
+ }
+
+ // get DATA or MME length (11 bits): length of data into DATA or MME buffer
+ data_length = (uint)((hdr.param & 0x00FFE) >> 1);
+
+ // get buffer pointer (32 bits): pointer to DATA or MME buffer
+ data = *(first_msg + 1);
}
- else
+
+ else // (HLE_MSG_TYPE_INTERFACE == hdr.type)
{
- type = ETHERNET_TYPE_MME;
+ int data_index = 1;
+
+ // get module type (8 bits):
+ // 0: sniffer
+ // 1-255: unused
+ if (0 == (u8)(hdr.param & 0x000FF))
+ {
+ type = ETHERNET_TYPE_SNIFFER;
+ }
+
+ // get data length (11 bits): length of data into buffer
+ data_length = (uint)((hdr.param & 0x7FF00) >> 8);
+
+ if (3 == length) // get module param (32 bits)
+ {
+ u32 module_param = *(first_msg + data_index);
+ data_index++;
+
+ // get way (1 bit): Tx or Rx
+ // 0: Tx
+ // 1: Rx
+ // get encryption (1 bit): encrypted or not
+ // 0: false
+ // 1: true
+ flags = (u8)(module_param & 0x00000003);
+
+ // get data type (3 bits): Beacon or MME type
+ // 0: Beacon type
+ // 1: MME type
+ // 2-7: unused
+ sniffer_type = (u8)((module_param & 0x0000001C) >> 2);
+ }
+
+ // get buffer pointer (32 bits): pointer to buffer
+ data = *(first_msg + data_index);
}
- // get buffer pointer (32 bits): pointer to DATA or MME buffer
- u32 data = *(first_msg + 1);
+ // send DATA, MME or SNIFFER (sniffed Beacon or MME) to Maximus
+ if (0 != maximus_ether_send(ctx, type, sniffer_type, flags, data_length, (u32 *)data))
+ {
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ dbg_assert_print(false, "errno = %d when transmitting an Ethernet or a sniffed packet", errno);
+ }
// check that this pointer is still allocated
while ((NULL != current_buffer->next) && !found)
@@ -255,14 +317,6 @@ ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
// for BUFFER RELEASED message
u32 id = current_buffer->id;
- // send DATA or MME to Maximus
- if (0 != maximus_ether_send(ctx, type, 0 /* sniffer_type */, ETHERNET_FLAG_NONE, data_length, (u32 *)data))
- {
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- dbg_assert_print(false, "errno = %d when transmitting an Ethernet packet", errno);
- }
-
// before deallocating buffer, link previous to next,
// and update last buffer if needed
previous_buffer->next = current_buffer->next;
@@ -286,45 +340,15 @@ ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
{
/* Nothing to do:
* buffers are released when a TX is done
- * (messages of type 'HLE_MSG_TYPE_DATA'). */
+ * (messages of type 'HLE_MSG_TYPE_DATA' or 'HLE_MSG_TYPE_INTERFACE'). */
}
- else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
+ else // (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
{
errno = EINVAL;
station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
"%s: errno = %d", __FUNCTION__, errno);
dbg_assert_print(false, "errno = %d because cannot transmit an Ethernet packet of type BUFFER_ADD", errno);
}
- else // HLE_MSG_TYPE_INTERFACE_SNIFFER
- {
- // get data length (11 bits): length of data into buffer
- uint data_length = (uint)((hdr.param & 0xFFE0) >> 5);
-
- // get data type (3 bits): Beacon or MME type
- // 0: Beacon type
- // 1: MME type
- // 2-7: unused
- u8 sniffer_type = (u8)((hdr.param & 0x001C) >> 2);
-
- // get encryption (1 bit): encrypted or not
- // 0: false
- // 1: true
- // and get way (1 bit): Tx or Rx
- // 0: Tx
- // 1: Rx
- u8 flags = (u8)(hdr.param & 0x0003);
-
- // get buffer pointer (32 bits): pointer to buffer
- u32 data = *(first_msg + 1);
-
- // send sniffed Beacon or MME to Maximus
- if (0 != maximus_ether_send(ctx, ETHERNET_TYPE_SNIFFER, sniffer_type, flags, data_length, (u32 *)data))
- {
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- dbg_assert_print(false, "errno = %d when transmitting a sniffed packet", errno);
- }
- }
}
}
}
diff --git a/hal/hle/maximus/test/src/test_maximus_ether.c b/hal/hle/maximus/test/src/test_maximus_ether.c
index d6441c73b0..952a39abe5 100644
--- a/hal/hle/maximus/test/src/test_maximus_ether.c
+++ b/hal/hle/maximus/test/src/test_maximus_ether.c
@@ -179,6 +179,12 @@ void maximus_ether_recv_test_case(test_t t)
test_begin(t, "recv")
{
+ u32 buf_nb = 1;
+ u32 buf_id = 1;
+ u32 total_buf_nb = buf_nb;
+ maximus_hle_buffer_t *first_buffer = NULL;
+ maximus_hle_buffer_t *current_buffer = NULL;
+
// ether header
ether_msg_hdr_t ether_hdr;
@@ -220,34 +226,50 @@ void maximus_ether_recv_test_case(test_t t)
// ether type data buffer add
else if (ETHERNET_TYPE_DATA_BUFFER_ADD == ether_hdr.type)
{
- u32 buffer_nb = 1;
- u32 buffer_id = 1;
test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
&& (EINVAL != errno)
&& (ENOSPC != errno));
- memcpy(msg.data_begin, &buffer_nb, sizeof(u32));
+ memcpy(msg.data_begin, &buf_nb, sizeof(u32));
test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
&& (EINVAL != errno)
&& (ENOSPC != errno));
- memcpy(msg.data_begin, &buffer_id, sizeof(u32));
+ memcpy(msg.data_begin, &buf_id, sizeof(u32));
}
// ether type mme buffer add
- else // ETHERNET_TYPE_MME_BUFFER_ADD
+ else if (ETHERNET_TYPE_MME_BUFFER_ADD == ether_hdr.type)
{
- u32 buffer_nb = 10;
- u32 buffer_id;
- for (buffer_id = buffer_nb + 1; buffer_id > 1; buffer_id--)
+ buf_nb = 10;
+ for (buf_id = total_buf_nb + buf_nb; buf_id > total_buf_nb; buf_id--)
{
test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
&& (EINVAL != errno)
&& (ENOSPC != errno));
- memcpy(msg.data_begin, &buffer_id, sizeof(u32));
+ memcpy(msg.data_begin, &buf_id, sizeof(u32));
}
test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
&& (EINVAL != errno)
&& (ENOSPC != errno));
- memcpy(msg.data_begin, &buffer_nb, sizeof(u32));
+ memcpy(msg.data_begin, &buf_nb, sizeof(u32));
+ total_buf_nb += buf_nb;
+ }
+
+ // ether type interface buffer add
+ else // (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == ether_hdr.type)
+ {
+ buf_nb = 2;
+ for (buf_id = total_buf_nb + buf_nb; buf_id > total_buf_nb; buf_id--)
+ {
+ test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &buf_id, sizeof(u32));
+ }
+ test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &buf_nb, sizeof(u32));
+ total_buf_nb += buf_nb;
}
// fill ether header
@@ -306,16 +328,18 @@ void maximus_ether_recv_test_case(test_t t)
{
test_begin(t, "ether type data buffer add")
{
- u32 mailbox[2];
+ u32 mailbox[2 * buf_nb];
mailbox[0] = (1 << 8) | HLE_MSG_TYPE_BUFFER_ADD; // ipmbox msg hdr
mailbox[1] = (u32)ctx->last_buffer->data; // ipmbox msg data
+ first_buffer = ctx->first_buffer->next;
+ current_buffer = first_buffer;
test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
- && (2 == ctx->rx.length)
- && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * sizeof(u32)))
- && (NULL == ctx->last_buffer->next)
- && (1 == ctx->last_buffer->id)
- && (NULL != ctx->last_buffer->data));
+ && (2 * buf_nb == ctx->rx.length)
+ && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * buf_nb * sizeof(u32)))
+ && (NULL == current_buffer->next)
+ && (total_buf_nb == current_buffer->id)
+ && (NULL != current_buffer->data));
(*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
ctx->rx.length = 0;
@@ -323,15 +347,16 @@ void maximus_ether_recv_test_case(test_t t)
}
// test ether type mme buffer add
- else // ETHERNET_TYPE_MME_BUFFER_ADD
+ else if (ETHERNET_TYPE_MME_BUFFER_ADD == ether_hdr.type)
{
test_begin(t, "ether type mme buffer add")
{
uint i;
- u32 mailbox[20];
+ u32 mailbox[2 * buf_nb];
u32 hdr = (1 << 12) | (1 << 8) | HLE_MSG_TYPE_BUFFER_ADD; // ipmbox msg hdr
- maximus_hle_buffer_t *current_buffer = ctx->first_buffer->next->next;
- for (i=0; i<20; i+=2)
+ first_buffer = current_buffer->next;
+ current_buffer = first_buffer;
+ for (i=0; i<2*buf_nb; i+=2)
{
mailbox[i] = hdr;
mailbox[i+1] = (u32)current_buffer->data; // ipmbox msg data
@@ -340,20 +365,62 @@ void maximus_ether_recv_test_case(test_t t)
// check mailbox contents
test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
- && (20 == ctx->rx.length)
- && (0 == memcmp(ctx->rx.mailbox, mailbox, 20 * sizeof(u32))));
+ && (2 * buf_nb == ctx->rx.length)
+ && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * buf_nb * sizeof(u32))));
// check list of the 10 allocated buffers
- current_buffer = ctx->first_buffer->next->next;
- for (i=1; i<10; i++)
+ current_buffer = first_buffer;
+ for (i=total_buf_nb-buf_nb+1; i<total_buf_nb; i++)
+ {
+ test_fail_unless ((NULL != current_buffer->next)
+ && (i == current_buffer->id)
+ && (NULL != current_buffer->data));
+ current_buffer = current_buffer->next;
+ }
+ test_fail_unless ((NULL == current_buffer->next)
+ && (total_buf_nb == current_buffer->id)
+ && (NULL != current_buffer->data));
+
+ // call rx_cb
+ (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
+ maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ ctx->rx.length = 0;
+ } test_end;
+ }
+
+ // test ether type interface buffer add
+ else // (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == ether_hdr.type)
+ {
+ test_begin(t, "ether type interface buffer add")
+ {
+ uint i;
+ u32 mailbox[2 * buf_nb];
+ u32 hdr = (2 << 12) | (1 << 8) | HLE_MSG_TYPE_BUFFER_ADD; // ipmbox msg hdr
+ first_buffer = current_buffer->next;
+ current_buffer = first_buffer;
+ for (i=0; i<2*buf_nb; i+=2)
+ {
+ mailbox[i] = hdr;
+ mailbox[i+1] = (u32)current_buffer->data; // ipmbox msg data
+ current_buffer = current_buffer->next;
+ }
+
+ // check mailbox contents
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
+ && (2 * buf_nb == ctx->rx.length)
+ && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * buf_nb * sizeof(u32))));
+
+ // check list of the 2 allocated buffers
+ current_buffer = first_buffer;
+ for (i=total_buf_nb-buf_nb+1; i<total_buf_nb; i++)
{
test_fail_unless ((NULL != current_buffer->next)
- && (i+1 == current_buffer->id)
+ && (i == current_buffer->id)
&& (NULL != current_buffer->data));
current_buffer = current_buffer->next;
}
test_fail_unless ((NULL == current_buffer->next)
- && (11 == current_buffer->id)
+ && (total_buf_nb == current_buffer->id)
&& (NULL != current_buffer->data));
// call rx_cb
@@ -364,18 +431,18 @@ void maximus_ether_recv_test_case(test_t t)
test_begin(t, "release allocated buffers")
{
- maximus_hle_buffer_t *current_buffer = ctx->first_buffer->next;
+ uint rls_buf_nb = 0;
maximus_hle_buffer_t *next_buffer = NULL;
- uint buffer_nb = 0;
+ current_buffer = ctx->first_buffer->next;
while (NULL != current_buffer)
{
next_buffer = current_buffer->next;
free(current_buffer->data);
free(current_buffer);
current_buffer = next_buffer;
- buffer_nb++;
+ rls_buf_nb++;
}
- test_fail_unless (11 == buffer_nb);
+ test_fail_unless (total_buf_nb == rls_buf_nb);
} test_end;
}
}
@@ -672,6 +739,7 @@ void ether_test_suite(test_t t)
ctx = ipmbox_init ((void*)&user_data,
&ipmbox_rx_cb);
ctx->warning_assert = true;
+ ipmbox_activate (ctx, true);
test_suite_begin(t, "ether");
maximus_ether_fill_hdr_test_case(t);
diff --git a/hal/hle/maximus/test/src/test_maximus_ipmbox.c b/hal/hle/maximus/test/src/test_maximus_ipmbox.c
index d19ac25248..98a242fc32 100644
--- a/hal/hle/maximus/test/src/test_maximus_ipmbox.c
+++ b/hal/hle/maximus/test/src/test_maximus_ipmbox.c
@@ -120,12 +120,12 @@ void ipmbox_tx_test_case(test_t t)
// mailbox msg
ipmbox_msg_hdr_t hdr;
- u32 mailbox[2];
+ u32 mailbox[3];
uint length = 2; // init length
hdr.type = HLE_MSG_TYPE_NONE; // init hdr type
hdr.length = 1; // init hdr length
hdr.param = 0; // init hdr param
- memset(mailbox, '\0', length * sizeof(u32)); // init mailbox
+ memset(mailbox, '\0', 3 * sizeof(u32)); // init mailbox
printf("tx\n");
test_case_begin(t, "tx");
@@ -137,7 +137,7 @@ void ipmbox_tx_test_case(test_t t)
// set mailbox
memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
- ipmbox_tx(ctx, mailbox, length);
+ ipmbox_tx (ctx, mailbox, length);
test_fail_unless (EINVAL == errno);
}
dbg_fatal_try_catch (const char *fatal_message)
@@ -154,10 +154,11 @@ void ipmbox_tx_test_case(test_t t)
{
/* Fill sci data. */
- // hle type data
- if (HLE_MSG_TYPE_DATA == hdr.type)
+ // hle type data or hle type interface
+ if ((HLE_MSG_TYPE_DATA == hdr.type) || (HLE_MSG_TYPE_INTERFACE == hdr.type))
{
int i;
+ int msg_index = 1; // init message index
maximus_hle_buffer_t *second_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
maximus_hle_buffer_t *last_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
last_buffer->next = NULL;
@@ -173,16 +174,43 @@ void ipmbox_tx_test_case(test_t t)
}
ctx->first_buffer->next = second_buffer;
- // set hdr param
- hdr.param = frame_length << 1;
+ if (HLE_MSG_TYPE_DATA == hdr.type)
+ {
+ // set hdr param
+ hdr.param = frame_length << 1;
+ }
+ else // (HLE_MSG_TYPE_INTERFACE == hdr.type)
+ {
+ u32 module_param = 0; // init module param
+
+ // set length
+ length = 3;
+
+ // set hdr length
+ hdr.length = 2;
+
+ // set hdr param
+ hdr.param = frame_length << 8; // data length
+
+ // set module param
+ module_param = 1 << 2; // data type
+ module_param |= 1 << 1; // encryption
+ module_param |= 1; // way
+
+ // set mailbox
+ mailbox[msg_index] = module_param; // set module param
+
+ // update message index
+ msg_index++;
+ }
// set mailbox
memcpy(&mailbox[0], &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
- mailbox[1] = (u32)second_buffer->data; // set data
+ mailbox[msg_index] = (u32)second_buffer->data; // set data
- test_begin(t, "tx data")
+ test_begin(t, "tx data or interface")
{
- ipmbox_tx(ctx, mailbox, length);
+ ipmbox_tx (ctx, mailbox, length);
test_fail_unless (EINVAL != errno);
} test_end;
}
@@ -227,32 +255,12 @@ void ipmbox_tx_test_case(test_t t)
} test_end;
}
- // hle type interface sniffer
- else // HLE_MSG_TYPE_INTERFACE_SNIFFER
- {
- test_begin(t, "tx interface sniffer")
- {
- // set hdr param
- hdr.param = frame_length << 5; // data length
- hdr.param |= 1 << 2; // data type
- hdr.param |= 1 << 1; // encryption
- hdr.param |= 1; // way
-
- // set mailbox
- memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
- mailbox[1] = (u32)frame; // set data
-
- ipmbox_tx(ctx, mailbox, length);
- test_fail_unless (EINVAL != errno);
- } test_end;
- }
-
/* Check results. */
// hle type data
if (HLE_MSG_TYPE_DATA == hdr.type)
{
- // check that correct ether messages have been sent to Maximus
+ // check that the correct ether message has been sent to Maximus
test_begin(t, "ether message DATA")
{
unsigned char buffer[SCI_MSG_MAX_SIZE];
@@ -287,8 +295,25 @@ void ipmbox_tx_test_case(test_t t)
// close pipe
maximus_ether_close(fd_in);
} test_end;
+ }
- test_begin(t, "ether message BUFFER RELEASED")
+ // hle type buffer add
+ else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
+ {
+ // nothing to check
+ }
+
+ // hle type send done
+ else if (HLE_MSG_TYPE_SEND_DONE == hdr.type)
+ {
+ // nothing to check
+ }
+
+ // hle type interface
+ else // HLE_MSG_TYPE_INTERFACE
+ {
+ // check that the correct ether message has been sent to Maximus
+ test_begin(t, "ether message SNIFFER")
{
unsigned char buffer[SCI_MSG_MAX_SIZE];
sci_msg_hdr_t *sci_hdr;
@@ -309,36 +334,25 @@ void ipmbox_tx_test_case(test_t t)
ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
// check ether header
- test_fail_unless ((ETHERNET_TYPE_BUFFER_RELEASED == ether_hdr->type)
- && (0 == ether_hdr->sniffer_type)
- && (ETHERNET_FLAG_NONE == ether_hdr->flags));
+ test_fail_unless ((ETHERNET_TYPE_SNIFFER == ether_hdr->type)
+ && (1 == ether_hdr->sniffer_type)
+ && (ETHERNET_FLAG_MAX == ether_hdr->flags));
// read the remaining part of message
- test_fail_unless (sizeof(u32) == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), sizeof(u32)));
+ test_fail_unless (frame_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
// check ether data
- test_fail_unless (32 == *(buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t)));
+ test_fail_unless (0 == memcmp(frame, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
// close pipe
maximus_ether_close(fd_in);
} test_end;
}
- // hle type buffer add
- else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
- {
- // nothing to check
- }
-
- // hle type send done
- else if (HLE_MSG_TYPE_SEND_DONE == hdr.type)
- {
- // nothing to check
- }
- else // HLE_MSG_TYPE_INTERFACE_SNIFFER
+ // hle type data or hle type interface
+ if ((HLE_MSG_TYPE_DATA == hdr.type) || (HLE_MSG_TYPE_INTERFACE == hdr.type))
{
- // check that the correct ether message has been sent to Maximus
- test_begin(t, "ether message SNIFFER")
+ test_begin(t, "ether message BUFFER RELEASED")
{
unsigned char buffer[SCI_MSG_MAX_SIZE];
sci_msg_hdr_t *sci_hdr;
@@ -359,15 +373,15 @@ void ipmbox_tx_test_case(test_t t)
ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
// check ether header
- test_fail_unless ((ETHERNET_TYPE_SNIFFER == ether_hdr->type)
- && (1 == ether_hdr->sniffer_type)
- && (ETHERNET_FLAG_MAX == ether_hdr->flags));
+ test_fail_unless ((ETHERNET_TYPE_BUFFER_RELEASED == ether_hdr->type)
+ && (0 == ether_hdr->sniffer_type)
+ && (ETHERNET_FLAG_NONE == ether_hdr->flags));
// read the remaining part of message
- test_fail_unless (frame_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
+ test_fail_unless (sizeof(u32) == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), sizeof(u32)));
// check ether data
- test_fail_unless (0 == memcmp(frame, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
+ test_fail_unless (32 == *(buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t)));
// close pipe
maximus_ether_close(fd_in);
diff --git a/interface/sniffer/src/sniffer.c b/interface/sniffer/src/sniffer.c
index 8d1d538ce3..28b648789b 100644
--- a/interface/sniffer/src/sniffer.c
+++ b/interface/sniffer/src/sniffer.c
@@ -92,7 +92,7 @@ interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
bitstream_memcpy (buffer, mme, length);
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE_SNIFFER),
+ word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
(MSG_LENGTH, 1), (PARAM_SNIFFER_WAY, !tx),
(PARAM_SNIFFER_EKC, encrypted),
(PARAM_SNIFFER_TYPE, SNIFFER_MME),
@@ -166,7 +166,7 @@ interface_sniffer_copy_beacon (interface_sniffer_t *ctx, pb_beacon_t *beacon,
bitstream_access (&bitstream, &length, 16);
bitstream_finalise (&bitstream);
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE_SNIFFER),
+ word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
(MSG_LENGTH, 1), (PARAM_SNIFFER_WAY, !tx),
(PARAM_SNIFFER_EKC, false),
(PARAM_SNIFFER_TYPE, SNIFFER_BEACON),
diff --git a/interface/sniffer/test/src/test-sniffer.c b/interface/sniffer/test/src/test-sniffer.c
index 7118c9a080..b247fc8f70 100644
--- a/interface/sniffer/test/src/test-sniffer.c
+++ b/interface/sniffer/test/src/test-sniffer.c
@@ -157,7 +157,7 @@ main (void)
test_begin (test, "Verify message posted in the IPMBOX")
{
- test_fail_if (type != HLE_MSG_TYPE_INTERFACE_SNIFFER, "Error on message type");
+ test_fail_if (type != HLE_MSG_TYPE_INTERFACE, "Error on message type");
test_fail_if (msg_len != 1, "Error on message length");
test_fail_if (data_ekc != false, "Error on message encryption");
test_fail_if (data_tx != false, "Error on message way");
@@ -186,7 +186,7 @@ main (void)
test_begin (test, "Verify message posted in the IPMBOX")
{
- test_fail_if (type != HLE_MSG_TYPE_INTERFACE_SNIFFER, "Error on message type");
+ test_fail_if (type != HLE_MSG_TYPE_INTERFACE, "Error on message type");
test_fail_if (msg_len != 1, "Error on message length");
test_fail_if (data_ekc != true, "Error on message encryption");
test_fail_if (data_tx != true, "Error on message way");
@@ -249,7 +249,7 @@ main (void)
test_begin (test, "verify beacon data")
{
- test_fail_if (type != HLE_MSG_TYPE_INTERFACE_SNIFFER, "Error on message type");
+ test_fail_if (type != HLE_MSG_TYPE_INTERFACE, "Error on message type");
test_fail_if (msg_len != 1, "Error on message length");
test_fail_if (data_tx != false, "Error on message way");
test_fail_if (data_ekc != false, "Error on message encryption");
@@ -277,7 +277,7 @@ main (void)
test_begin (test, "verify beacon data")
{
- test_fail_if (type != HLE_MSG_TYPE_INTERFACE_SNIFFER, "Error on message type");
+ test_fail_if (type != HLE_MSG_TYPE_INTERFACE, "Error on message type");
test_fail_if (msg_len != 1, "Error on message length");
test_fail_if (data_tx != true, "Error on message way");
test_fail_if (data_ekc != false, "Error on message encryption");
diff --git a/maximus/common/interfaces/Maximus.h b/maximus/common/interfaces/Maximus.h
index eb643f87b6..f87358d976 100644
--- a/maximus/common/interfaces/Maximus.h
+++ b/maximus/common/interfaces/Maximus.h
@@ -36,6 +36,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/interfa
#include "networkclock_types.h" // for 'tick_t'
#include "channel_types.h" // for 'MAXIMUS_CHANNEL_INTERVAL_MAX_NB'
+#include "sci_types.h" // for 'Sci_Msg_Station_Id'
#include <fstream> // for 'std::ofstream'
#include <string> // for 'std::string'
@@ -225,6 +226,13 @@ public:
*/
void deactivate_false_alarm ( );
+ /**
+ * Indicate if the station is IDLE or not.
+ * @param station_id the ID of the station
+ * @return 'true' if the station is IDLE, 'false' otherwise
+ */
+ const bool is_station_idle ( Sci_Msg_Station_Id station_id );
+
private:
// private attributes
diff --git a/maximus/common/types/ethernet_types.h b/maximus/common/types/ethernet_types.h
index d1f3c2ac86..752f6c185f 100644
--- a/maximus/common/types/ethernet_types.h
+++ b/maximus/common/types/ethernet_types.h
@@ -37,7 +37,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/types/e
// Ethernet_Header.flags
//
-typedef uint8_t Ethernet_Flags;
+typedef uint8_t Ethernet_Flags; // used in case of ETHERNET_TYPE_SNIFFER only
#define ETHERNET_FLAG_NONE 0x00
#define ETHERNET_FLAG_WAY 0x01 // Rx if set, Tx if none
#define ETHERNET_FLAG_ENCRYPTED 0x02 // If set, Ether SCI msg is encrypted
@@ -58,14 +58,25 @@ struct Ethernet_Header
enum Ethernet_Type
{
ETHERNET_TYPE_NONE = 0x00,
- ETHERNET_TYPE_DATA = 0x01, // Ether SCI msg data contain the MSDU (Ethernet Frame)
- ETHERNET_TYPE_MME = 0x02, // Ether SCI msg data contain the MSDU (MME)
- ETHERNET_TYPE_DATA_BUFFER_ADD = 0x03, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
- // and IDs of each buffer to allocate (uint32_t)
- ETHERNET_TYPE_MME_BUFFER_ADD = 0x04, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
- // and IDs of each buffer to allocate (uint32_t)
- ETHERNET_TYPE_BUFFER_RELEASED = 0x05, // Ether SCI msg data contain the ID of released buffer (uint32_t)
- ETHERNET_TYPE_SNIFFER = 0x06, // Ether SCI msg data contain a sniffed packet
+
+ /* HLE_MSG_TYPE_DATA > Data or MME message type. */
+ ETHERNET_TYPE_DATA = 0x01, // Ether SCI msg data contain the MSDU (Ethernet Frame)
+ ETHERNET_TYPE_MME = 0x02, // Ether SCI msg data contain the MSDU (MME)
+
+ /* HLE_MSG_TYPE_BUFFER_ADD > Buffer alloc message type. */
+ ETHERNET_TYPE_DATA_BUFFER_ADD = 0x03, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ // and IDs of each buffer to allocate (uint32_t)
+ ETHERNET_TYPE_MME_BUFFER_ADD = 0x04, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ // and IDs of each buffer to allocate (uint32_t)
+ ETHERNET_TYPE_INTERFACE_BUFFER_ADD = 0x05, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ // and IDs of each buffer to allocate (uint32_t)
+
+ /* HLE_MSG_TYPE_SEND_DONE > Buffer dealloc message type. */
+ ETHERNET_TYPE_BUFFER_RELEASED = 0x06, // Ether SCI msg data contain the ID of released buffer (uint32_t)
+
+ /* HLE_MSG_TYPE_INTERFACE > Interface message type. */
+ ETHERNET_TYPE_SNIFFER = 0x07, // Ether SCI msg data contain a sniffed packet
+
ETHERNET_TYPE_NB
};
diff --git a/maximus/coreengine/inc/MaximusTest.h b/maximus/coreengine/inc/MaximusTest.h
index a791534933..726cbc24d8 100644
--- a/maximus/coreengine/inc/MaximusTest.h
+++ b/maximus/coreengine/inc/MaximusTest.h
@@ -29,6 +29,7 @@ class MaximusTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (set_freq_test);
CPPUNIT_TEST (activate_false_alarm_test);
CPPUNIT_TEST (deactivate_false_alarm_test);
+ CPPUNIT_TEST (is_station_idle_test);
CPPUNIT_TEST_SUITE_END ();
public:
@@ -55,6 +56,7 @@ protected:
void set_freq_test (void);
void activate_false_alarm_test (void);
void deactivate_false_alarm_test (void);
+ void is_station_idle_test (void);
private:
diff --git a/maximus/coreengine/src/Maximus.cpp b/maximus/coreengine/src/Maximus.cpp
index b9ac579ff9..dfa37a30c3 100644
--- a/maximus/coreengine/src/Maximus.cpp
+++ b/maximus/coreengine/src/Maximus.cpp
@@ -908,6 +908,21 @@ void Maximus::deactivate_false_alarm ( )
}
+const bool Maximus::is_station_idle ( Sci_Msg_Station_Id station_id )
+{
+ logFunction();
+ bool isIdle = false;
+
+ try
+ {
+ isIdle = getSystemManager()->isStationIdle(station_id);
+ }
+ catchFunction(this);
+
+ return isIdle;
+}
+
+
// private methods
//
diff --git a/maximus/coreengine/src/MaximusTest.cpp b/maximus/coreengine/src/MaximusTest.cpp
index 055108f140..e9532c9b2c 100644
--- a/maximus/coreengine/src/MaximusTest.cpp
+++ b/maximus/coreengine/src/MaximusTest.cpp
@@ -421,3 +421,24 @@ void MaximusTest::deactivate_false_alarm_test (void)
}
}
+
+void MaximusTest::is_station_idle_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", !mpMaximus->is_station_idle(sta.getStationId()) );
+ mpMaximus->wait(1);
+ CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", mpMaximus->is_station_idle(sta.getStationId()) );
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
diff --git a/maximus/ethernet/src/EtherSciMsg.cpp b/maximus/ethernet/src/EtherSciMsg.cpp
index bb05317557..7869fb9cd3 100644
--- a/maximus/ethernet/src/EtherSciMsg.cpp
+++ b/maximus/ethernet/src/EtherSciMsg.cpp
@@ -229,9 +229,12 @@ void EtherSciMsg::displaySpecializedSciMsgType ( int log_level ) const
clog << logger(log_level) << "\ttype = ETHERNET_TYPE_MME_BUFFER_ADD" << endl;
break;
case 5:
- clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_RELEASED" << endl;
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_INTERFACE_BUFFER_ADD" << endl;
break;
case 6:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_RELEASED" << endl;
+ break;
+ case 7:
clog << logger(log_level) << "\ttype = ETHERNET_TYPE_SNIFFER" << endl;
break;
default:
diff --git a/maximus/python/lib/cesar/sta_cesar.py b/maximus/python/lib/cesar/sta_cesar.py
index 90f3675d85..bf02b23e4e 100644
--- a/maximus/python/lib/cesar/sta_cesar.py
+++ b/maximus/python/lib/cesar/sta_cesar.py
@@ -24,7 +24,9 @@ def STACesar(maximus,\
executable = None,\
debug = False,\
name = None,\
- mme_buffer_nb = 1,\
+ data_buffer_nb=0,\
+ mme_buffer_nb=1,\
+ interface_buffer_nb=0,\
config_mode = 'MME',\
config = Config()):
"""This function creates a STA object with the given arguments,
@@ -35,6 +37,8 @@ def STACesar(maximus,\
executable = executable,\
debug = debug,\
name = name,\
- mme_buffer_nb = mme_buffer_nb + INTERFACE_BUFFER_LIST_NUM_SLOTS,\
+ data_buffer_nb=data_buffer_nb,\
+ mme_buffer_nb=mme_buffer_nb,\
+ interface_buffer_nb=INTERFACE_BUFFER_LIST_NUM_SLOTS,\
config_mode = config_mode,\
config = config)
diff --git a/maximus/python/maximus/ethernet/__init__.py b/maximus/python/maximus/ethernet/__init__.py
index f4b1d9ba75..fa21730e37 100644
--- a/maximus/python/maximus/ethernet/__init__.py
+++ b/maximus/python/maximus/ethernet/__init__.py
@@ -4,7 +4,7 @@
#__all__ = ["buffer", "create", "eth", "scapy"]
-from buffer import alloc_data_buffer, alloc_mme_buffer, get_buffer_dict
+from buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer, realloc_buffer, get_buffer_dict
from eth import Eth
from scapy import *
from maximus.macframe.msdu import MSDU_TYPES
diff --git a/maximus/python/maximus/ethernet/buffer.py b/maximus/python/maximus/ethernet/buffer.py
index b4831abedd..1b2f2b13af 100644
--- a/maximus/python/maximus/ethernet/buffer.py
+++ b/maximus/python/maximus/ethernet/buffer.py
@@ -11,22 +11,37 @@ MAX_VALUE_OF_BUFFER_NB = MAX_VALUE_OF_U32
SIZE_OF_BUFFER_ID = SIZE_OF_U32
class Buffer(MSDU):
- """The Buffer object is composed of the 2 following fields:
- number of buffers to allocate (u32)
- ID of each buffer to allocate (u32)
+ """The Buffer object is composed of the 6 following fields:
+ buffer_id - the current buffer ID
+ buffer_dict - the list of current allocated buffers (ID and type)
+ buffer_realloc - indicates if buffer reallocation is automatic
+ maximus - the Maximus object
+ type - type of buffer
+ buffer_nb - number of buffers to allocate
"""
# Static attributes of the class
buffer_id = 0
buffer_dict = {}
-
- def __init__(self, type, buffer_nb=1):
+ buffer_realloc = False
+ __maximus = None
+
+ def __init__(self, type, buffer_nb=1, maximus=None):
+ """Initialize the Buffer with following attributes:
+ type - a Python string
+ buffer_nb - a Python integer
+ maximus - the Maximus object
+ """
self.set_type(type)
self.set_buffer_nb(buffer_nb)
+ self.__set_maximus(maximus)
def set_type(self, type):
"""This function sets the Buffer object type.
- The Buffer type can be a Python integer (uint8_t)
- or a Python string equals to 'ETHERNET_TYPE_DATA_BUFFER_ADD', 'ETHERNET_TYPE_MME_BUFFER_ADD' or 'ETHERNET_TYPE_BUFFER_RELEASED'.
+ The Buffer type can be a Python integer (u8)
+ or a Python string equals to 'ETHERNET_TYPE_DATA_BUFFER_ADD',
+ 'ETHERNET_TYPE_MME_BUFFER_ADD',
+ 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',
+ or 'ETHERNET_TYPE_BUFFER_RELEASED'.
"""
self.__type = 0
for i, j in enumerate(MSDU_TYPES):
@@ -45,6 +60,21 @@ class Buffer(MSDU):
else:
self.__buffer_nb = buffer_nb
+ def set_buffer_realloc(self, auto):
+ """This function enables or disables the automatic buffer allocation.
+ Auto must be a Python boolean.
+ """
+ if type(auto) is not bool:
+ raise TypeError("Auto")
+ else:
+ self.__class__.buffer_realloc = auto
+
+ def __set_maximus(self, maximus):
+ """This function sets the Maximus object.
+ """
+ if maximus is not None and self.__class__.__maximus is None:
+ self.__class__.__maximus = maximus
+
def __inc_buffer_id(self):
"""This function increments the buffer ID (static attribute of the class).
"""
@@ -60,15 +90,32 @@ class Buffer(MSDU):
"""
del self.__class__.buffer_dict[id]
+ def realloc(self, station_id, payload):
+ """If requested by user, this function allocates a new buffer to replace released buffer.
+ """
+ from maximus.simu.rx import recv
+ if self.get_buffer_realloc():
+ if len(payload) != SIZE_OF_BUFFER_ID:
+ raise Error('Buffer ID length')
+ else:
+ buffer = Buffer(type=self.__class__.buffer_dict[hptoh32(payload)], maximus=self.__get_maximus())
+ # Request to Maximus to send the MSDU asynchronously
+ while not self.__get_maximus().is_station_idle(station_id):
+ self.__get_maximus().process()
+ self.__get_maximus().send_msdu(buffer, station_id)
+
def set_msdu_attr(self, payload):
"""This function sets the MSDU attributes from the received Ethernet Frame.
"""
if len(payload) != SIZE_OF_BUFFER_ID:
raise Error('Buffer ID length')
- self.__remove_buffer(hptoh32(payload))
+ else:
+ self.__remove_buffer(hptoh32(payload))
def get(self):
- """This function returns the Buffer object into a string.
+ """This function returns the Buffer object into a string composed of the 2 following fields:
+ number of buffers to allocate (u32)
+ ID of each buffer to allocate (u32)
"""
buffer = htohp32(self.get_buffer_nb())
for n in range(0, self.get_buffer_nb()):
@@ -80,14 +127,17 @@ class Buffer(MSDU):
return buffer
def get_ether_type(self):
- """This function returns the Buffer object type into a Python integer (uint8_t).
+ """This function returns the Buffer object type into a Python integer (u8).
"""
- return self.__type # 3, 4 or 5
+ return self.__type # 3, 4, 5 or 6
def get_type(self):
"""This function returns the Buffer object type into a Python string.
"""
- return MSDU_TYPES[self.get_ether_type()] # 'ETHERNET_TYPE_DATA_BUFFER_ADD', 'ETHERNET_TYPE_MME_BUFFER_ADD' or 'ETHERNET_TYPE_BUFFER_RELEASED'
+ return MSDU_TYPES[self.get_ether_type()] # 'ETHERNET_TYPE_DATA_BUFFER_ADD',
+ # 'ETHERNET_TYPE_MME_BUFFER_ADD',
+ # 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',
+ # or 'ETHERNET_TYPE_BUFFER_RELEASED'
def get_buffer_nb(self):
"""This function gets the number of buffers to allocate.
@@ -105,13 +155,34 @@ class Buffer(MSDU):
"""
return self.__class__.buffer_dict
+ def get_buffer_realloc(self):
+ """This function gets if the current buffer reallocation is enabled or disabled.
+ """
+ return self.__class__.buffer_realloc
+
+ def __get_maximus(self):
+ """This function gets the Maximus object.
+ """
+ if self.__class__.__maximus is None:
+ raise Error("Maximus object not set")
+ return self.__class__.__maximus
+
+
def alloc_data_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=buffer_nb)
- buffer.send(maximus, station)
+ buffer = Buffer(type='ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+ buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
def alloc_mme_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=buffer_nb)
- buffer.send(maximus, station)
+ buffer = Buffer(type='ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+ buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
+
+def alloc_interface_buffer(maximus, station, buffer_nb=1):
+ buffer = Buffer(type='ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+ buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
+
+def realloc_buffer(auto):
+ buffer = Buffer('ETHERNET_TYPE_NONE')
+ buffer.set_buffer_realloc(auto)
def get_buffer_dict():
buffer = Buffer('ETHERNET_TYPE_NONE')
diff --git a/maximus/python/maximus/ethernet/sniffer.py b/maximus/python/maximus/ethernet/sniffer.py
index def45d9199..65abfa2d35 100644
--- a/maximus/python/maximus/ethernet/sniffer.py
+++ b/maximus/python/maximus/ethernet/sniffer.py
@@ -83,7 +83,7 @@ class Sniffer(MSDU):
for i in range (0,len(MSDU_TYPES)):
if MSDU_TYPES[i] == self.get_type():
ether_type = i
- return ether_type # 6
+ return ether_type # 7
def get_type(self):
"""This function returns the Sniffer object type into a Python string.
diff --git a/maximus/python/maximus/macframe/msdu.py b/maximus/python/maximus/macframe/msdu.py
index 9bf4504d45..26d8997c5d 100644
--- a/maximus/python/maximus/macframe/msdu.py
+++ b/maximus/python/maximus/macframe/msdu.py
@@ -14,6 +14,7 @@ MSDU_TYPES = ['ETHERNET_TYPE_NONE',\
'ETHERNET_TYPE_MME',\
'ETHERNET_TYPE_DATA_BUFFER_ADD',\
'ETHERNET_TYPE_MME_BUFFER_ADD',\
+ 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',\
'ETHERNET_TYPE_BUFFER_RELEASED',\
'ETHERNET_TYPE_SNIFFER']
diff --git a/maximus/python/maximus/station/sta.py b/maximus/python/maximus/station/sta.py
index 0e1e56f0c6..95d3942ecd 100644
--- a/maximus/python/maximus/station/sta.py
+++ b/maximus/python/maximus/station/sta.py
@@ -3,7 +3,7 @@
#print __name__
from maximus.station.config import *
-from maximus.ethernet.buffer import alloc_mme_buffer
+from maximus.ethernet.buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer
from maximus.macframe.msdu import MSDU_TYPES
from maximus.mme import *
from maximus.mme.mmheader import SIZE_OF_MMHEADER, SIZE_OF_MMTYPE, SIZE_OF_FMI
@@ -40,7 +40,7 @@ ERROR_CODES = {0x00:'Bad parameter', 0x01:'Unknown ID', 0x02:'Invalid value'}
def mme_filter(rsp):
if rsp.get_type() is MSDU_TYPES[2]: # ETHERNET_TYPE_MME
return True
- elif rsp.get_type() is MSDU_TYPES[5]: # ETHERNET_TYPE_BUFFER_RELEASED
+ elif rsp.get_type() is MSDU_TYPES[6]: # ETHERNET_TYPE_BUFFER_RELEASED
return False
else:
raise Error("Received unexpected message of type " + rsp.get_type())
@@ -51,7 +51,9 @@ class STA:
maximus - a Maximus object
station - a Sta object
name - a Python string
+ data_buffer_nb - a Python integer
mme_buffer_nb - a Python integer
+ interface_buffer_nb - a Python integer
mme_config - a Python boolean
mac_address - a Python tuple of 6 Python integers
cco_preference - a Python boolean
@@ -65,14 +67,25 @@ class STA:
tonemask - a Python tuple of Python integers
snid - a Python integer from 0 to 15
"""
- def __init__(self, maximus, executable=None, debug=False, name=None, mme_buffer_nb=1, config_mode=CONFIG_MODES[0], config=Config()):
+ def __init__(self,\
+ maximus,\
+ executable=None,\
+ debug=False,\
+ name=None,\
+ data_buffer_nb=0,\
+ mme_buffer_nb=1,\
+ interface_buffer_nb=0,\
+ config_mode=CONFIG_MODES[0],\
+ config=Config()):
"""Initialize the STA with following attributes:
maximus - a Maximus object (already initialized)
executable - a Python string
debug - a Python boolean
name - a Python string
+ data_buffer_nb - a Python integer
mme_buffer_nb - a Python integer
- mme_config - a Python boolean
+ interface_buffer_nb - a Python integer
+ config_mode - a Python string
config - a Python Config object
"""
@@ -84,7 +97,9 @@ class STA:
# Set station configuration
self.set_name(name)
+ self.set_data_buffer_nb(data_buffer_nb)
self.set_mme_buffer_nb(mme_buffer_nb)
+ self.set_interface_buffer_nb(interface_buffer_nb)
self.set_config_mode(config_mode)
self.set_config(config)
@@ -178,6 +193,22 @@ class STA:
if self.get_name() is not None:
self.get().set_name(name)
+ def set_data_buffer_nb(self, data_buffer_nb):
+ """Set the number of data buffers to allocate into the station.
+ The number of data buffers must be a Python integer.
+ """
+ if type(data_buffer_nb) is int:
+ if data_buffer_nb >= 0:
+ self.__data_buffer_nb = data_buffer_nb
+ else:
+ raise OutOfRangeError("Number of data buffers")
+ else:
+ raise TypeError
+
+ # Allocate data buffers
+ if data_buffer_nb > 0:
+ alloc_data_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=data_buffer_nb)
+
def set_mme_buffer_nb(self, mme_buffer_nb):
"""Set the number of MME buffers to allocate into the station.
The number of MME buffers must be a Python integer.
@@ -191,7 +222,24 @@ class STA:
raise TypeError
# Allocate MME buffers
- alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=mme_buffer_nb)
+ if mme_buffer_nb > 0:
+ alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=mme_buffer_nb)
+
+ def set_interface_buffer_nb(self, interface_buffer_nb):
+ """Set the number of interface buffers to allocate into the station.
+ The number of interface buffers must be a Python integer.
+ """
+ if type(interface_buffer_nb) is int:
+ if interface_buffer_nb >= 0:
+ self.__interface_buffer_nb = interface_buffer_nb
+ else:
+ raise OutOfRangeError("Number of interface buffers")
+ else:
+ raise TypeError
+
+ # Allocate interface buffers
+ if interface_buffer_nb > 0:
+ alloc_interface_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=interface_buffer_nb)
def set_config_mode(self, config_mode):
"""Set the configuration mode.
@@ -459,12 +507,24 @@ class STA:
"""
return self.__name
+ def get_data_buffer_nb(self):
+ """Get the number of data buffers allocated into the station.
+ The number of data buffers is a Python integer.
+ """
+ return self.__data_buffer_nb
+
def get_mme_buffer_nb(self):
"""Get the number of MME buffers allocated into the station.
The number of MME buffers is a Python integer.
"""
return self.__mme_buffer_nb
+ def get_interface_buffer_nb(self):
+ """Get the number of interface buffers allocated into the station.
+ The number of interface buffers is a Python integer.
+ """
+ return self.__interface_buffer_nb
+
def get_config_mode(self):
"""Get the configuration mode.
The configuration mode is a Python string of the CONFIG_MODES Python list.
diff --git a/maximus/python/py/test_ether.py b/maximus/python/py/test_ether.py
index 42a6b7a0d8..00c2ca4081 100644
--- a/maximus/python/py/test_ether.py
+++ b/maximus/python/py/test_ether.py
@@ -55,31 +55,9 @@ frame1.type = type
msdu1 = 'This is the Ethernet payload'
frame1.payload = msdu1
alloc_data_buffer(m, sta1, buffer_nb=2)
-snif = recv(m)[0]
frame1.send(m, sta1)
rsp1 = recv(m, count=4)
-# Test the sniffed received MSDU (Sniffer) object
-snif.display()
-if snif.get()[0:48] != "This is a sniffed packet coming from the station":
- print "packet =", snif.get()
- raise Error("packet")
-if snif.get_ether_type() != 6:
- print "ether type =", snif.get_ether_type()
- raise Error("ether type")
-if snif.get_type() != 'ETHERNET_TYPE_SNIFFER':
- print "type =", snif.get_type()
- raise Error("type")
-if snif.get_way() != True:
- print "way =", snif.get_way()
- raise Error("way")
-if snif.get_encryption() != True:
- print "encryption =", snif.get_encryption()
- raise Error("encryption")
-if snif.get_sniffer_type() != 1:
- print "sniffer type =", snif.get_sniffer_type()
- raise Error("sniffer type")
-
# Test the 1st received MSDU (Eth) object
i = 0
if rsp1[i].dst.lower() != dst:
@@ -119,7 +97,6 @@ frame2.type = type
msdu2 = 'This is the Ethernet payload'
frame2.payload = msdu2
alloc_data_buffer(m, sta1, buffer_nb=2)
-recv(m)
rsp2 = frame2.sendnrecv(m, sta1, count=4)
# Test the 1st received MSDU (Eth) object
@@ -154,7 +131,6 @@ m.wait(100000)
# Send an MME asynchronously
mme3 = MME(MMHeader=mmheader, MMEntry=mmentry)
alloc_data_buffer(m, sta1, buffer_nb=2)
-recv(m)
mme3.send(m, sta1)
rsp3 = recv(m, count=4)
@@ -190,7 +166,6 @@ m.wait(100000)
# Send an MME synchronously
mme4 = MME(MMHeader=mmheader, MMEntry=mmentry)
alloc_data_buffer(m, sta1, buffer_nb=2)
-recv(m)
rsp4 = mme4.sendnrecv(m, sta1, count=4)
# Test the 1st received MSDU (Eth) object
@@ -222,6 +197,29 @@ if rsp4[i].get_mmentry() != mmentry:
m.wait(100000)
+# Test the sniffed received MSDU (Sniffer) object
+alloc_interface_buffer(m, sta1)
+snif = recv(m, count=2)[0] # the second received frame is the BUFFER RELEASED message
+snif.display()
+if snif.get()[0:48] != "This is a sniffed packet coming from the station":
+ print "packet =", snif.get()
+ raise Error("packet")
+if snif.get_ether_type() != 7:
+ print "ether type =", snif.get_ether_type()
+ raise Error("ether type")
+if snif.get_type() != 'ETHERNET_TYPE_SNIFFER':
+ print "type =", snif.get_type()
+ raise Error("type")
+if snif.get_way() != True:
+ print "way =", snif.get_way()
+ raise Error("way")
+if snif.get_encryption() != True:
+ print "encryption =", snif.get_encryption()
+ raise Error("encryption")
+if snif.get_sniffer_type() != 1:
+ print "sniffer type =", snif.get_sniffer_type()
+ raise Error("sniffer type")
+
# Uninit ether
fcall2 = m.create_fcall('uninit_ether')
fcall2.send(sta1)
diff --git a/maximus/python/src/interface_module.cpp b/maximus/python/src/interface_module.cpp
index cc8234595a..cd60b16d55 100644
--- a/maximus/python/src/interface_module.cpp
+++ b/maximus/python/src/interface_module.cpp
@@ -119,9 +119,13 @@ void recv_ether_cb ( EtherSciMsg & ether )
{
logFunction();
- if (ether_rx_param.activated)
+ if ( ether_rx_param.activated
+ || (ETHERNET_TYPE_BUFFER_RELEASED == ether.getSpecializedSciMsgType()) )
{
- // Create a new MSDU Python object (Eth or MME)
+ // Get Ethernet SCI message attributes
+ string payload((char *)ether.getSpecializedSciMsgData(), ether.getSpecializedSciMsgDataLength());
+
+ // Create a new MSDU Python object (Eth, MME, Buffer or Sniffer)
object rx_msdu;
if (ETHERNET_TYPE_DATA == ether.getSpecializedSciMsgType())
{
@@ -151,14 +155,20 @@ void recv_ether_cb ( EtherSciMsg & ether )
throw Error(__PRETTY_FUNCTION__, "receive an Ether SCI message with a bad type (should be DATA, MME, BUFFER_RELEASED or SNIFFER)", errno);
}
- // Get Ethernet SCI message attributes
- // and set the MSDU object attributes
- // (payload)
- string payload((char *)ether.getSpecializedSciMsgData(), ether.getSpecializedSciMsgDataLength());
+ if (ETHERNET_TYPE_BUFFER_RELEASED == ether.getSpecializedSciMsgType())
+ {
+ // Reallocate a buffer if requested by user
+ rx_msdu.attr("realloc")(ether.getSciMsgStationId(), payload);
+ }
+
+ // Set the MSDU object attributes (payload)
rx_msdu.attr("set_msdu_attr")(payload);
- // Call the Python reception callback
- ether_rx_param.activated = !ether_rx_param.cb(rx_msdu);
+ if (ether_rx_param.activated)
+ {
+ // Call the Python reception callback
+ ether_rx_param.activated = !ether_rx_param.cb(rx_msdu);
+ }
}
}
@@ -439,7 +449,8 @@ void send_ether ( Maximus & m, object msdu, int station_id )
}
-void set_ether_rx ( Maximus & m, object user_cb,
+void set_ether_rx ( Maximus & m,
+ object user_cb,
object create_eth_function,
object create_mme_function,
object create_buffer_function,
@@ -631,6 +642,7 @@ BOOST_PYTHON_MODULE(interface)
.def("set_snr_from_src_to_dst", set_snr_from_src_to_dstx2)
.def("activate_false_alarm", &Maximus::activate_false_alarm)
.def("deactivate_false_alarm", &Maximus::deactivate_false_alarm)
+ .def("is_station_idle", &Maximus::is_station_idle)
;
/* class Sta */
diff --git a/maximus/python/test/test_ethernet.py b/maximus/python/test/test_ethernet.py
index 795c043942..aba2f62a2b 100644
--- a/maximus/python/test/test_ethernet.py
+++ b/maximus/python/test/test_ethernet.py
@@ -6,7 +6,7 @@ import sys, startup
from maximus.ethernet import *
from maximus.ethernet.buffer import Buffer
-from maximus.ethernet.create import create_buffer, create_eth
+from maximus.ethernet.create import create_eth, create_buffer, create_sniffer
from maximus.ethernet.eth import SIZE_OF_HEADER
from maximus.ethernet.sniffer import Sniffer
from maximus.macframe.msdu import MIN_SIZE_OF_MSDU
@@ -186,7 +186,6 @@ class TestEthFunctions(unittest.TestCase):
none_buffer = Buffer('ETHERNET_TYPE_NONE')
length = len(none_buffer.get_buffer_dict())
alloc_data_buffer(self.m, sta, buffer_nb=2)
- recv(self.m, count=1)
rsp = self.eth.sendnrecv(self.m, sta, count=4)
# 1st received frame is the Ethernet frame
@@ -195,9 +194,11 @@ class TestEthFunctions(unittest.TestCase):
self.assertEqual(rsp[0].vlantag, 0)
self.assertEqual(rsp[0].type, 0)
- # 2nd received frame is the BUFFER RELEASED message
- self.assertEqual(rsp[1].get_ether_type(), 5)
+ # 2nd and 4th received frames are BUFFER RELEASED messages
+ self.assertEqual(rsp[1].get_ether_type(), 6)
self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ self.assertEqual(rsp[3].get_ether_type(), 6)
+ self.assertEqual(rsp[3].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
self.assertEqual(len(rsp[1].get_buffer_dict()), length)
self.m.create_fcall('uninit_ether').send(sta)
@@ -242,6 +243,10 @@ class TestBufferFunctions(unittest.TestCase):
self.assertEqual(self.mme_buffer.get_ether_type(), 4)
self.assertEqual(self.mme_buffer.get_type(), 'ETHERNET_TYPE_MME_BUFFER_ADD')
self.assertEqual(self.mme_buffer.get_buffer_nb(), 2)
+ self.interface_buffer = Buffer('ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=3)
+ self.assertEqual(self.interface_buffer.get_ether_type(), 5)
+ self.assertEqual(self.interface_buffer.get_type(), 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD')
+ self.assertEqual(self.interface_buffer.get_buffer_nb(), 3)
self.m = m
def tearDown(self):
@@ -249,7 +254,7 @@ class TestBufferFunctions(unittest.TestCase):
def test_set_type(self):
self.data_buffer.set_type('ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(self.data_buffer.get_ether_type(), 5)
+ self.assertEqual(self.data_buffer.get_ether_type(), 6)
self.assertEqual(self.data_buffer.get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
try:
self.mme_buffer.set_type('ETHERNET_TYPE_MME')
@@ -265,17 +270,45 @@ class TestBufferFunctions(unittest.TestCase):
except OutOfRangeError:
self.assertEqual(self.mme_buffer.get_buffer_nb(), 0)
+ def test_set_buffer_realloc(self):
+ self.assertEqual(self.data_buffer.get_buffer_realloc(), False)
+ self.data_buffer.set_buffer_realloc(True)
+ self.assertEqual(self.data_buffer.get_buffer_realloc(), True)
+ self.data_buffer.set_buffer_realloc(False)
+
+ def test_realloc(self):
+ sta = self.m.create_sta()
+ self.m.create_fcall('init_ether').send(sta)
+ realloc_buffer(True)
+ buffer_id = 123
+ self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_DATA_BUFFER_ADD'
+ self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
+ buffer_id = 456
+ self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_MME_BUFFER_ADD'
+ self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
+ buffer_id = 789
+ self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD'
+ self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
+ rsp = recv(self.m, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ realloc_buffer(False)
+ self.m.create_fcall('uninit_ether').send(sta)
+ sta.remove()
+
def test_set_msdu_attr(self):
- self.assert_(self.data_buffer.get_buffer_dict().has_key(10))
- self.data_buffer.set_msdu_attr(pack('I', 10))
- self.assert_(not self.data_buffer.get_buffer_dict().has_key(10))
+ id = len(self.data_buffer.get_buffer_dict())
+ self.assert_(self.data_buffer.get_buffer_dict().has_key(id))
+ self.data_buffer.set_msdu_attr(pack('I', id))
+ self.assert_(not self.data_buffer.get_buffer_dict().has_key(id))
def test_sendnrecv(self):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
- data_buffer = Buffer('ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=2)
- rsp = data_buffer.sendnrecv(self.m, sta)[0]
- self.assertEqual(rsp.get_type(), 'ETHERNET_TYPE_SNIFFER')
+ interface_buffer = Buffer('ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=2)
+ rsp = interface_buffer.sendnrecv(self.m, sta, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
@@ -312,6 +345,28 @@ class TestBufferFunctions(unittest.TestCase):
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
+ def test_alloc_interface_buffer(self):
+ sta = self.m.create_sta()
+ self.m.create_fcall('init_ether').send(sta)
+ realloc_buffer(True)
+ alloc_interface_buffer(self.m, sta)
+ rsp = recv(self.m, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ realloc_buffer(False)
+ alloc_interface_buffer(self.m, sta)
+ rsp = recv(self.m, count=2)
+ self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
+ self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ self.m.create_fcall('uninit_ether').send(sta)
+ sta.remove()
+
+ def test_realloc_buffer(self):
+ self.assertEqual(self.interface_buffer.get_buffer_realloc(), False)
+ realloc_buffer(True)
+ self.assertEqual(self.interface_buffer.get_buffer_realloc(), True)
+ realloc_buffer(False)
+
def test_get_buffer_dict(self):
get_buffer_dict()
@@ -322,7 +377,7 @@ class TestSnifferFunctions(unittest.TestCase):
def setUp(self):
self.sniffer = Sniffer(way=False, encryption=False, sniffer_type=0)
self.assertEqual(self.sniffer.get(), None)
- self.assertEqual(self.sniffer.get_ether_type(), 6)
+ self.assertEqual(self.sniffer.get_ether_type(), 7)
self.assertEqual(self.sniffer.get_type(), 'ETHERNET_TYPE_SNIFFER')
self.assertEqual(self.sniffer.get_way(), False)
self.assertEqual(self.sniffer.get_encryption(), False)
@@ -360,6 +415,12 @@ class TestSnifferFunctions(unittest.TestCase):
self.sniffer.set_msdu_attr("ABCD")
self.sniffer.display()
+ def test_create_sniffer(self):
+ way = True
+ encryption = True
+ sniffer_type = 1
+ self.assertNotEqual(create_sniffer(way, encryption, sniffer_type), None)
+
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSnifferFunctions))
try:
diff --git a/maximus/python/test/test_interface.py b/maximus/python/test/test_interface.py
index cd0bcacfc5..fa0e18d21e 100644
--- a/maximus/python/test/test_interface.py
+++ b/maximus/python/test/test_interface.py
@@ -179,6 +179,12 @@ class TestInterfaceFunctions(unittest.TestCase):
self.m.activate_false_alarm(duration, deviation)
self.m.deactivate_false_alarm()
+ def test_is_station_idle(self):
+ self.m.wait(1) # to process the system IDLE message coming from the station
+ self.assert_(self.m.is_station_idle(self.station.get_station_id()))
+ self.station.deactivate()
+ self.assert_(not self.m.is_station_idle(self.station.get_station_id()))
+
def test_remove(self):
# Remove station
diff --git a/maximus/stationtest/src/test_ether.c b/maximus/stationtest/src/test_ether.c
index 3e2539afc2..83a8452774 100644
--- a/maximus/stationtest/src/test_ether.c
+++ b/maximus/stationtest/src/test_ether.c
@@ -21,6 +21,7 @@
#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+#include <stdlib.h> // for 'malloc()'
extern station_ctx_t my_station;
ipmbox_t * ctx;
@@ -57,21 +58,35 @@ void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
}
else if (HLE_MSG_TYPE_BUFFER_ADD == hdr->type)
{
- /* When receiving an Ether SCI message of type DATA_BUFFER_ADD or MME_BUFFER_ADD from Maximus,
- * answer by sending an Ether SCI message of type SNIFFER. */
-
- uint data_length = 64;
- char data[data_length];
- memset(data, '\0', data_length);
- strcpy(data, "This is a sniffed packet coming from the station");
-
hdr->type = HLE_MSG_TYPE_SEND_DONE;
ipmbox_tx (ctx, ctx->rx.mailbox, 2); // do nothing
- hdr->type = HLE_MSG_TYPE_INTERFACE_SNIFFER;
- hdr->param = (data_length << 5) | 0x7;
- ctx->rx.mailbox[1] = (u32)data;
- ipmbox_tx (ctx, ctx->rx.mailbox, 2);
+ if (2 == hdr->param)
+ {
+ /* When receiving an Ether SCI message of type INTERFACE_BUFFER_ADD from Maximus,
+ * answer by sending an Ether SCI message of type SNIFFER,
+ * with an Ether SCI message of type BUFFER_RELEASED. */
+
+ uint data_length = 64;
+ char * p_data = malloc(data_length);
+ memset(p_data, '\0', data_length);
+ strcpy(p_data, "This is a sniffed packet coming from the station");
+
+ maximus_hle_buffer_t *p_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
+ u32 id = ctx->last_buffer->id;
+ ctx->last_buffer->next = p_buffer;
+ ctx->last_buffer = p_buffer;
+ ctx->last_buffer->next = NULL;
+ ctx->last_buffer->id = id;
+ ctx->last_buffer->data = (u32 *)p_data;
+
+ hdr->type = HLE_MSG_TYPE_INTERFACE;
+ hdr->length = 2;
+ hdr->param = (data_length << 8) & 0x7FF00;
+ ctx->rx.mailbox[1] = 0x00000007;
+ ctx->rx.mailbox[2] = (u32)p_data;
+ ipmbox_tx (ctx, ctx->rx.mailbox, 3);
+ }
}
return;
@@ -89,7 +104,7 @@ int init_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void
ctx->warning_assert = true;
// Activate ipmbox interruptions
- ipmbox_activate(ctx, true);
+ ipmbox_activate (ctx, true);
/* now make the return parameter list */
fcall_param_reset(*param);
diff --git a/maximus/stationtest/src/test_station.c b/maximus/stationtest/src/test_station.c
index 557a67c952..b31ba7c24c 100644
--- a/maximus/stationtest/src/test_station.c
+++ b/maximus/stationtest/src/test_station.c
@@ -48,7 +48,7 @@ void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
}
else if (HLE_MSG_TYPE_BUFFER_ADD == hdr->type)
{
- /* Receive an Ether SCI message of type MME_BUFFER_ADD from Maximus. */
+ /* Receive an Ether SCI message of type DATA_BUFFER_ADD, MME_BUFFER_ADD or INTERFACE_BUFFER_ADD from Maximus. */
hdr->type = HLE_MSG_TYPE_SEND_DONE;
ipmbox_tx (ctx, ctx->rx.mailbox, 2); // do nothing
@@ -83,7 +83,7 @@ int main(void)
ctx->warning_assert = true;
// Activate ipmbox interruptions
- ipmbox_activate(ctx, true);
+ ipmbox_activate (ctx, true);
fcall_register(my_station.fcall, "uninit_ether", (void*)&uninit_ether, NULL);