summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/common/defs/homeplugAV.h3
-rw-r--r--cesar/cp/defs.h4
-rw-r--r--cesar/cp/msg/src/msg_cc.c4
-rw-r--r--cesar/interface/sniffer/src/sniffer.c40
-rw-r--r--cesar/interface/sniffer/test/src/test-sniffer.c38
5 files changed, 74 insertions, 15 deletions
diff --git a/cesar/common/defs/homeplugAV.h b/cesar/common/defs/homeplugAV.h
index a90c0c2276..1228374f82 100644
--- a/cesar/common/defs/homeplugAV.h
+++ b/cesar/common/defs/homeplugAV.h
@@ -26,6 +26,9 @@
/** Define the offset of the MMTYPE when the vlan is not present. */
#define HPAV_MMTYPE_OFFSET 15
+/** Max payload size in bytes. */
+#define HPAV_MME_PAYLOAD_MAX_SIZE_WITH_VLAN 1495
+#define HPAV_MME_PAYLOAD_MAX_SIZE 1499
/** MMV version for the MME HomePlug 1.0 see section 11.1.5 */
#define HPAV_MMV0 0x0
diff --git a/cesar/cp/defs.h b/cesar/cp/defs.h
index 0511876472..8a3951c3b0 100644
--- a/cesar/cp/defs.h
+++ b/cesar/cp/defs.h
@@ -94,10 +94,6 @@
#define CP_NID_SIZE 7
#define CP_NID_SIZE_BITS 54
-/** Max payload size in bytes. */
-#define CP_MME_PAYLOAD_MAX_SIZE_WITH_VLAN 1495
-#define CP_MME_PAYLOAD_MAX_SIZE 1499
-
/** Specific allocation time in ATU. Calulated from their size in byte and their
* transmission in ROBO modulation*/
diff --git a/cesar/cp/msg/src/msg_cc.c b/cesar/cp/msg/src/msg_cc.c
index 79038ad0b1..3b73975f7b 100644
--- a/cesar/cp/msg/src/msg_cc.c
+++ b/cesar/cp/msg/src/msg_cc.c
@@ -519,8 +519,8 @@ cp_msg_cc_set_tei_map_ind_send_begin (
dbg_assert (mode < CP_MSG_CC_SET_TEI_MAP_IND_MODE_NB);
dbg_assert (sta_nb);
- if (sta_nb * 8 > (peer->vlan_tag ? CP_MME_PAYLOAD_MAX_SIZE_WITH_VLAN :
- CP_MME_PAYLOAD_MAX_SIZE) - 2)
+ if (sta_nb * 8 > (peer->vlan_tag ? HPAV_MME_PAYLOAD_MAX_SIZE_WITH_VLAN :
+ HPAV_MME_PAYLOAD_MAX_SIZE) - 2)
{
msg = cp_msg_mme_init_frag (ctx, peer, CC_SET_TEI_MAP_IND, 1, 0, 0);
diff --git a/cesar/interface/sniffer/src/sniffer.c b/cesar/interface/sniffer/src/sniffer.c
index da12418c48..836e940abb 100644
--- a/cesar/interface/sniffer/src/sniffer.c
+++ b/cesar/interface/sniffer/src/sniffer.c
@@ -23,6 +23,9 @@
#include "interface/sniffer/inc/context.h"
#include "interface/def.h"
+/* The TX and Interface sniffer type data. */
+#define INTERFACE_SNIFFER_IDENTIFY_LENGTH 2
+
/* Static declaration. */
static interface_sniffer_t sniffer_global;
@@ -79,6 +82,10 @@ void
interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
u8 *buffer, bool tx, bool encrypted)
{
+ bitstream_t bitstream;
+ uint header_length;
+ uint embedded_length;
+ uint offset;
uint word[2];
dbg_assert (ctx);
@@ -88,9 +95,36 @@ interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
dbg_assert (buffer);
dbg_assert (ctx->send_func);
- /* Change the destination MAC address of the MME. */
- bitstream_memcpy (buffer, mme, length);
- bitstream_direct_write_large (buffer, 0, ctx->da, 48);
+ /* Compute the header size. */
+ if (ctx->vlan_tag == 0)
+ header_length = HPAV_MME_HEADER + OUI_SIZE +
+ INTERFACE_SNIFFER_IDENTIFY_LENGTH;
+ else
+ header_length = HPAV_MME_HEADER_LEN_WITH_VLAN + OUI_SIZE
+ + INTERFACE_SNIFFER_IDENTIFY_LENGTH;
+
+ if (length + header_length > ETH_PACKET_MAX_SIZE)
+ embedded_length = length - header_length;
+ else
+ embedded_length = length;
+
+ /* Create the header of the MME. */
+ bitstream_write_init (&bitstream, buffer, header_length);
+ bitstream_write_large (&bitstream, ctx->da, 48);
+ bitstream_write_large (&bitstream, ctx->mac_config->sta_mac_address, 48);
+ if (ctx->vlan_tag)
+ bitstream_write (&bitstream, ctx->vlan_tag, 32);
+ bitstream_write (&bitstream, swap16(HPAV_MTYPE_MME), 16);
+ bitstream_write (&bitstream, HPAV_MMV, 8);
+ bitstream_write (&bitstream, VS_SNIFFER_IND, 16);
+ bitstream_write (&bitstream, 0, 16);
+ bitstream_write (&bitstream, SPC_OUI, OUI_SIZE_BITS);
+
+ bitstream_write (&bitstream, INTERFACE_SNIFFER_TYPE_MME, 8);
+ /* 0 for TX, 1 for RX. */
+ bitstream_write (&bitstream, !tx, 8);
+ offset = bitstream_finalise (&bitstream) / 8;
+ bitstream_memcpy (buffer + offset, mme, embedded_length);
word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
(MSG_LENGTH, 1),
diff --git a/cesar/interface/sniffer/test/src/test-sniffer.c b/cesar/interface/sniffer/test/src/test-sniffer.c
index d83d5c3267..6c1f5ac015 100644
--- a/cesar/interface/sniffer/test/src/test-sniffer.c
+++ b/cesar/interface/sniffer/test/src/test-sniffer.c
@@ -372,9 +372,9 @@ test_sniffer_mme (test_t test)
/* Prepare the MME to be sniffed. */
bitstream_write_init (&stream, request, 1518);
- bitstream_write_large (&stream, STA_MAC_ADDR, 48);
+ bitstream_write_large (&stream, OSA2, 48);
bitstream_write_large (&stream, OSA1, 48);
- bitstream_write (&stream, HPAV_MTYPE_MME, 16);
+ bitstream_write (&stream, swap16(HPAV_MTYPE_MME), 16);
bitstream_write (&stream, HPAV_MMV, 8);
/* WHO are you request. */
bitstream_write (&stream, 0x2c, 16);
@@ -385,13 +385,39 @@ test_sniffer_mme (test_t test)
memset (answer, 0, 1518);
interface_sniffer_copy_mme_tx (sniffer, request, 60, answer, false);
- test_fail_unless (bitstream_direct_read_large (answer, 0, 48) == sniffer->da);
- test_fail_unless (memcmp (request + 6, answer + 6, length - 6) == 0);
+
+ bitstream_read_init (&stream, answer, ETH_PACKET_MAX_SIZE);
+ test_fail_unless (bitstream_read_large (&stream, 48) == sniffer->da);
+ test_fail_unless (bitstream_read_large (&stream, 48) == STA_MAC_ADDR);
+ test_fail_unless (bitstream_read (&stream, 16) ==
+ swap16(HPAV_MTYPE_MME));
+ test_fail_unless (bitstream_read (&stream, 8) == HPAV_MMV);
+ test_fail_unless (bitstream_read (&stream, 16) == VS_SNIFFER_IND);
+ test_fail_unless (bitstream_read (&stream, 16) == 0);
+ test_fail_unless (bitstream_read (&stream, OUI_SIZE_BITS) == SPC_OUI);
+ test_fail_unless (bitstream_read (&stream, 8) ==
+ INTERFACE_SNIFFER_TYPE_MME);
+ test_fail_unless (bitstream_read (&stream, 8) == 0);
+ bitstream_finalise (&stream);
+ test_fail_unless (memcmp (request, answer + 24, length) == 0);
memset (answer, 0, 1518);
interface_sniffer_copy_mme_rx (sniffer, request, 60, answer, false);
- test_fail_unless (bitstream_direct_read_large (answer, 0, 48) == sniffer->da);
- test_fail_unless (memcmp (request + 6, answer + 6, length - 6) == 0);
+
+ bitstream_read_init (&stream, answer, ETH_PACKET_MAX_SIZE);
+ test_fail_unless (bitstream_read_large (&stream, 48) == sniffer->da);
+ test_fail_unless (bitstream_read_large (&stream, 48) == STA_MAC_ADDR);
+ test_fail_unless (bitstream_read (&stream, 16) ==
+ swap16(HPAV_MTYPE_MME));
+ test_fail_unless (bitstream_read (&stream, 8) == HPAV_MMV);
+ test_fail_unless (bitstream_read (&stream, 16) == VS_SNIFFER_IND);
+ test_fail_unless (bitstream_read (&stream, 16) == 0);
+ test_fail_unless (bitstream_read (&stream, OUI_SIZE_BITS) == SPC_OUI);
+ test_fail_unless (bitstream_read (&stream, 8) ==
+ INTERFACE_SNIFFER_TYPE_MME);
+ test_fail_unless (bitstream_read (&stream, 8) == 1);
+ bitstream_finalise (&stream);
+ test_fail_unless (memcmp (request, answer + 24, length) == 0);
}
test_end;
}