summaryrefslogtreecommitdiff
path: root/cesar/cp/msg
diff options
context:
space:
mode:
authorThierry Carré2011-10-13 15:57:10 +0200
committerThierry Carré2011-10-20 10:46:36 +0200
commit8563c98f11d1704bc8289f7ccc4026d4523f7b29 (patch)
tree912e5588e0302e0f705489780f0c387c796473cd /cesar/cp/msg
parentbad50ae6e9bae07ced0ddb2b7c0930f7a94a60dd (diff)
cesar/cp/msg: factorise the code with a unique cp_msg_mme_init
Diffstat (limited to 'cesar/cp/msg')
-rw-r--r--cesar/cp/msg/msg.h14
-rw-r--r--cesar/cp/msg/src/msg.c48
-rw-r--r--cesar/cp/msg/src/msg_cc.c55
-rw-r--r--cesar/cp/msg/src/msg_cm.c22
-rw-r--r--cesar/cp/msg/src/msg_vs.c43
-rw-r--r--cesar/cp/msg/stub/src/msg.c4
-rw-r--r--cesar/cp/msg/test/src/relay.c2
7 files changed, 77 insertions, 111 deletions
diff --git a/cesar/cp/msg/msg.h b/cesar/cp/msg/msg.h
index 6eda939d20..0cab91342e 100644
--- a/cesar/cp/msg/msg.h
+++ b/cesar/cp/msg/msg.h
@@ -121,6 +121,18 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
* \param ctx control plane context
* \param peer peer information
* \param mmtype the MME MMTYPE.
+ * \param mme_payload_length total payload size in byte.
+ * \return the newly created message
+ */
+cp_mme_tx_t *
+cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
+ uint mme_payload_length);
+
+/**
+ * Initialise a MME handle for a new message fragment to be transmitted.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param mmtype the MME MMTYPE.
* \param fmi_nbFrag The number of fragments.
* \param fmi_nb the number of the fragment.
* \return the newly created message
@@ -133,7 +145,7 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
*/
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_nb);
+ uint fmi_nbFrag);
/**
* Finalise and send a MME.
diff --git a/cesar/cp/msg/src/msg.c b/cesar/cp/msg/src/msg.c
index 96f2a7fead..cce9e1d1cc 100644
--- a/cesar/cp/msg/src/msg.c
+++ b/cesar/cp/msg/src/msg.c
@@ -581,6 +581,48 @@ cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme)
slab_release (mme);
}
+cp_mme_tx_t *
+cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
+ uint mme_payload_length)
+{
+ cp_mme_tx_t *mme;
+ uint mme_header_length;
+ uint nf_mi;
+
+ dbg_assert (peer);
+
+ /* Compute the header length. */
+ mme_header_length = peer->vlan_tag ? HPAV_MME_HEADER_LEN_WITH_VLAN :
+ HPAV_MME_HEADER;
+
+ /* If it's a Vendor Specific MME, so we have a OUI field added
+ * See Page 576 of HomePlugAV spec , version 1.1, may 21 2007.*/
+ if (mmtype >= VS_MIN && mmtype <= VS_MAX)
+ mme_header_length += OUI_SIZE;
+
+ /* Fragmentation Management Information –
+ * 4 bits are Number of Fragments (NF_MI) of the MMENTRY
+ * 0x00 = MMENTRY is not Fragmented
+ * 0x01 = MMENTRY is Fragmented into two parts
+ * 0x02 = MMENTRY is Fragmented into three parts, and so on
+ **/
+ nf_mi = mme_payload_length / (ETH_PACKET_MAX_SIZE - mme_header_length);
+ dbg_assert (nf_mi < HPAV_MME_MAX_FRAG);
+
+ if (nf_mi == 0)
+ mme = cp_msg_mme_init_not_frag (ctx, peer, mmtype);
+ else
+ {
+ mme = cp_msg_mme_init_frag (ctx, peer, mmtype, nf_mi);
+ dbg_assert (mme);
+ bitstream_init_buffer_cb (
+ &mme->bitstream,
+ (bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, mme);
+ }
+
+ return mme;
+}
+
/**
* Initialise a MME handle for a new message to be transmitted.
* \param ctx control plane context
@@ -853,13 +895,13 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_nb)
+ uint fmi_nbFrag)
{
cp_mme_tx_t *msg;
dbg_assert (ctx);
dbg_assert (peer);
- dbg_assert (fmi_nb <= fmi_nbFrag);
+ dbg_assert (fmi_nbFrag < HPAV_MME_MAX_FRAG);
// Allocate the new message.
msg = cp_msg_mme_tx_init (ctx);
@@ -872,7 +914,7 @@ cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
msg->peks = CP_MME_PEKS_SPC_NOT_EMBEDDED;
msg->fmi_nbfrag = fmi_nbFrag;
- msg->fmi_nb = fmi_nb;
+ msg->fmi_nb = 0;
msg->fmi_fmsn = ctx->msg.fmsn;
msg->mmtype = mmtype;
cp_msg_mme_fmsn_increase (&ctx->msg);
diff --git a/cesar/cp/msg/src/msg_cc.c b/cesar/cp/msg/src/msg_cc.c
index 45f8b99454..0e62e7261e 100644
--- a/cesar/cp/msg/src/msg_cc.c
+++ b/cesar/cp/msg/src/msg_cc.c
@@ -516,23 +516,15 @@ cp_msg_cc_set_tei_map_ind_send_begin (
enum cp_msg_cc_set_tei_map_ind_mode_t mode, uint sta_nb)
{
cp_mme_tx_t *msg;
+ uint size;
dbg_assert (ctx);
dbg_assert (peer);
dbg_assert (mode < CP_MSG_CC_SET_TEI_MAP_IND_MODE_NB);
dbg_assert (sta_nb);
- 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);
-
- bitstream_init_buffer_cb (
- &msg->bitstream,
- (bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, msg);
- }
- else
- msg = cp_msg_mme_init_not_frag (ctx, peer, CC_SET_TEI_MAP_IND);
+ size = ( sta_nb * 8 ) + 2;
+ msg = cp_msg_mme_init (ctx, peer, CC_SET_TEI_MAP_IND, size);
dbg_check (msg);
bitstream_access (&msg->bitstream, &mode, 8);
@@ -914,8 +906,6 @@ cp_msg_cc_discover_list_cnf_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
{
cp_mme_tx_t *mme;
uint data_length;
- uint header_length;
- uint nf_mi;
uint nb_sta_length;
uint nb_net_length;
@@ -931,30 +921,8 @@ cp_msg_cc_discover_list_cnf_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
nb_sta_length = 1 + nb_sta * 12; // see Table 11-193.
nb_net_length = 1 + nb_net * 13; // see Table 11-193.
- header_length = peer->vlan_tag ? HPAV_MME_HEADER_LEN_WITH_VLAN :
- HPAV_MME_HEADER;
data_length = nb_sta_length + nb_net_length;
-
- /* Fragmentation Management Information –
- * 4 bits are Number of Fragments (NF_MI) of the MMENTRY
- * 0x00 = MMENTRY is not Fragmented
- * 0x01 = MMENTRY is Fragmented into two parts
- * 0x02 = MMENTRY is Fragmented into three parts, and so on
- **/
- nf_mi = data_length / (ETH_PACKET_MAX_SIZE - header_length);
-
- if (nf_mi == 0)
- mme = cp_msg_mme_init_not_frag (ctx, peer, CC_DISCOVER_LIST_CNF);
- else
- {
- mme = cp_msg_mme_init_frag (
- ctx, peer, CC_DISCOVER_LIST_CNF, nf_mi, 0);
-
- bitstream_init_buffer_cb (
- &mme->bitstream,
- (bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, mme);
- }
-
+ mme = cp_msg_mme_init (ctx, peer, CC_DISCOVER_LIST_CNF, data_length);
return mme;
}
@@ -1289,9 +1257,8 @@ cp_msg_cc_handover_info_ind_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
uint num_sta)
{
cp_mme_tx_t *mme;
+ uint size;
- dbg_assert (ctx);
- dbg_assert (peer);
dbg_assert (rsc < CP_MSG_CC_HANDOVER_INFO_IND_RSC_NB);
/* 166 stations maximum in the MME.
@@ -1300,16 +1267,8 @@ cp_msg_cc_handover_info_ind_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
* (1495 - 3) / 9 = 165.77 bytes.
* Without Vlan, 1518 - 19 = 1499.
* (1499 - 3) / 9 = 166.22 bytes. */
- if (((peer->vlan_tag) && (num_sta < 165))
- || (num_sta < 166))
- mme = cp_msg_mme_init_not_frag (ctx, peer, CC_HANDOVER_INFO_IND);
- else
- {
- mme = cp_msg_mme_init_frag (ctx, peer, CC_HANDOVER_INFO_IND, 1, 0);
- bitstream_init_buffer_cb (
- &mme->bitstream,
- (bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, mme);
- }
+ size = (num_sta * 9) + 3;
+ mme = cp_msg_mme_init (ctx, peer, CC_HANDOVER_INFO_IND, size);
dbg_assert (mme);
bitstream_write (&mme->bitstream, rsc, 8);
diff --git a/cesar/cp/msg/src/msg_cm.c b/cesar/cp/msg/src/msg_cm.c
index b95233a3bf..f5ce43f014 100644
--- a/cesar/cp/msg/src/msg_cm.c
+++ b/cesar/cp/msg/src/msg_cm.c
@@ -1706,31 +1706,17 @@ cp_msg_cm_nw_stats_cnf_send_begin (cp_t *ctx, cp_mme_peer_t *peer_info,
const uint num_stats)
{
cp_mme_tx_t *mme;
- uint mme_payload_length;
- uint mme_header_length;
+ uint size;
+
dbg_assert (ctx);
dbg_assert (peer_info);
/* Compute the payload length. */
- mme_payload_length = num_stats * 8 + 1;
- /* Add the header length. */
- mme_header_length = peer_info->vlan_tag ? HPAV_MME_HEADER_LEN_WITH_VLAN :
- HPAV_MME_HEADER;
-
- if (mme_payload_length + mme_header_length > ETH_PACKET_MAX_SIZE)
- {
- mme = cp_msg_mme_init_frag (ctx, peer_info, CM_NW_STATS_CNF, 1, 0);
-
- bitstream_init_buffer_cb (
- &mme->bitstream,
- (bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, mme);
- }
- else
- mme = cp_msg_mme_init_not_frag (ctx, peer_info, CM_NW_STATS_CNF);
+ size = num_stats * 8 + 1;
+ mme = cp_msg_mme_init (ctx, peer_info, CM_NW_STATS_CNF, size);
dbg_assert (mme);
bitstream_access (&mme->bitstream, &num_stats, 8);
-
return mme;
}
diff --git a/cesar/cp/msg/src/msg_vs.c b/cesar/cp/msg/src/msg_vs.c
index 6ad72c6da1..aef267e96b 100644
--- a/cesar/cp/msg/src/msg_vs.c
+++ b/cesar/cp/msg/src/msg_vs.c
@@ -853,47 +853,14 @@ cp_mme_tx_t *
cp_msg_vs_get_pb_stats_cnf_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
int nb_measures)
{
- cp_mme_tx_t * mme;
- uint mme_payload_length;
- uint mme_header_length;
- uint nf_mi;
+ cp_mme_tx_t* mme;
+ uint size;
cp_msg_vs_get_pb_stats_cnf_result_t result;
-
- dbg_assert (ctx);
- dbg_assert (peer);
-
/* Compute the payload length. */
- mme_payload_length = PB_STATS_SIZE_WITH_DATA(nb_measures);
- /* Compute the header length. */
- mme_header_length = peer->vlan_tag ? HPAV_MME_HEADER_LEN_WITH_VLAN :
- HPAV_MME_HEADER;
- /* It's a Vendor Specific MME, so we have a OUI field added
- * See Page 576 of HomePlugAV spec , version 1.1, may 21 2007.*/
- mme_header_length += OUI_SIZE;
-
- /* Fragmentation Management Information –
- * 4 bits are Number of Fragments (NF_MI) of the MMENTRY
- * 0x00 = MMENTRY is not Fragmented
- * 0x01 = MMENTRY is Fragmented into two parts
- * 0x02 = MMENTRY is Fragmented into three parts, and so on
- **/
- nf_mi = mme_payload_length / (ETH_PACKET_MAX_SIZE - mme_header_length);
-
- if (nf_mi == 0)
- {
- mme = cp_msg_mme_init_not_frag (ctx, peer, VS_GET_PB_STATS_CNF);
- dbg_assert (mme);
- }
- else
- {
- mme = cp_msg_mme_init_frag (ctx, peer, VS_GET_PB_STATS_CNF, nf_mi, 0);
- dbg_assert (mme);
-
- bitstream_init_buffer_cb (
- &mme->bitstream,
- (bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, mme);
- }
+ size = PB_STATS_SIZE_WITH_DATA(nb_measures);
+ mme = cp_msg_mme_init (ctx, peer, VS_GET_PB_STATS_CNF, size);
+ dbg_assert (mme);
if (nb_measures < 0)
{
diff --git a/cesar/cp/msg/stub/src/msg.c b/cesar/cp/msg/stub/src/msg.c
index 941eca8403..41c9c687e3 100644
--- a/cesar/cp/msg/stub/src/msg.c
+++ b/cesar/cp/msg/stub/src/msg.c
@@ -69,11 +69,11 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_fnmi) __attribute__((weak));
+ uint fmi_nbFrag) __attribute__((weak));
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_fnmi)
+ uint fmi_nbFrag)
{
return NULL;
}
diff --git a/cesar/cp/msg/test/src/relay.c b/cesar/cp/msg/test/src/relay.c
index 4def154286..f17fb26773 100644
--- a/cesar/cp/msg/test/src/relay.c
+++ b/cesar/cp/msg/test/src/relay.c
@@ -821,7 +821,7 @@ test_case_msg_mme_change_buffer_tx (test_t test)
test_this_test_init ();
- mme = cp_msg_mme_init_frag (&cp, &peer, CC_SET_TEI_MAP_REQ, 1, 0);
+ mme = cp_msg_mme_init_frag (&cp, &peer, CC_SET_TEI_MAP_REQ, 1);
test_fail_unless (mme->relay == true);
mme->bitstream.data_bits = 0;
mme->bitstream.data = NULL;