summaryrefslogtreecommitdiff
path: root/cesar/cp
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-08-31 17:38:48 +0200
committerNélio Laranjeiro2010-09-24 15:03:37 +0200
commited4f6ab158005331c43e73c77cdc3a9ba6efc1ec (patch)
tree3069be290ae98bf07f0da8d756dc8423eee7da36 /cesar/cp
parent1c80cf177f1e7f621941903df24823f0f3a479c1 (diff)
cesar/cp/msg: add MME drop explanation, closes #705
Diffstat (limited to 'cesar/cp')
-rw-r--r--cesar/cp/msg/src/msg.c96
-rw-r--r--cesar/cp/src/trace.c64
2 files changed, 119 insertions, 41 deletions
diff --git a/cesar/cp/msg/src/msg.c b/cesar/cp/msg/src/msg.c
index 7f20cf1e74..dbadd4db62 100644
--- a/cesar/cp/msg/src/msg.c
+++ b/cesar/cp/msg/src/msg.c
@@ -256,6 +256,27 @@ cp_msg_mme_allowed_t cp_msg_mme_allowed[] =
uint cp_msg_mme_allowed_count = COUNT (cp_msg_mme_allowed);
+/** Enum type for allowed MME error code. */
+enum cp_msg_allowed_mme_t
+{
+ /** MME Allowed. */
+ CP_MSG_ALLOWED_MME_OK,
+ /** MME is not handled by CP. */
+ CP_MSG_ALLOWED_MME_NOT_HANDLED,
+ /** MME not allowed to be received from the PHY. */
+ CP_MSG_ALLOWED_MME_PHY_NOT_ALLOWED,
+ /** MME not allowed to be received from H1. */
+ CP_MSG_ALLOWED_MME_H1_NOT_ALLOWED,
+ /** Station status is not sufficient, MME require a high level status
+ * (Associated or Authenticated) and the station does not respect it. */
+ CP_MSG_ALLOWED_MME_STA_STATUS_NOK,
+ /** The OUI embedded in the MME is not from SPiDCOM. */
+ CP_MSG_ALLOWED_MME_SPC_OUI_WRONG,
+ /** Bad encryption key used, the STA is unable to decrypt it. */
+ CP_MSG_ALLOWED_MME_ENC_BAD,
+ CP_MSG_ALLOWED_MME_NB
+};
+
/**
* Compute the current length of the MME fragmented or not.
* \param msg the MME to send.
@@ -385,9 +406,9 @@ cp_msg_dispatch__read_enc_header (cp_t *ctx, cp_mme_rx_t *mme)
* \param mme the mme context.
* \param status_min the minimum status required to continue with the MME.
* \param type the variable to store the FSM event type.
- * \return true if the MME is allowed, false otherwise.
+ * \return value code.
*/
-bool
+enum cp_msg_allowed_mme_t
cp_msg_dispatch__allowed_mme (cp_t *ctx, cp_mme_rx_t *mme,
enum cp_msg_mme_sta_status_t *status_min,
cp_fsm_event_type_t *type)
@@ -406,21 +427,28 @@ cp_msg_dispatch__allowed_mme (cp_t *ctx, cp_mme_rx_t *mme,
*status_min = cp_msg_mme_allowed[i].min_sta_status;
*type = cp_msg_mme_allowed[i].fsm_event;
/* First case, MME comes from the PLC. */
- if ((mme->peer.tei != MAC_TEI_FOREIGN)
- && (cp_msg_mme_allowed[i].nek_encrypted
- <= mme->encrypt)
- && ((mme->encrypt == CP_MME_RX_NOT_ENCRYPTED)
- || (mme->encrypt == CP_MME_RX_SOFT_ENCRYPTED)
- || ((mme->encrypt == CP_MME_RX_NEK_ENCRYPTED)
- && (MAC_TEI_IS_STA(mme->peer.tei)))))
- return true;
+ if (mme->peer.tei != MAC_TEI_FOREIGN)
+ {
+ if ((cp_msg_mme_allowed[i].nek_encrypted
+ <= mme->encrypt)
+ && ((mme->encrypt == CP_MME_RX_NOT_ENCRYPTED)
+ || (mme->encrypt == CP_MME_RX_SOFT_ENCRYPTED)
+ || ((mme->encrypt == CP_MME_RX_NEK_ENCRYPTED)
+ && (MAC_TEI_IS_STA(mme->peer.tei)))))
+ return CP_MSG_ALLOWED_MME_OK;
+ else
+ return CP_MSG_ALLOWED_MME_PHY_NOT_ALLOWED;
+ }
/* Second case, MME comes from the H1. */
- else if ((mme->peer.tei == MAC_TEI_FOREIGN)
- && (cp_msg_mme_allowed[i].from_h1))
- return true;
+ else if (mme->peer.tei == MAC_TEI_FOREIGN)
+ {
+ if (cp_msg_mme_allowed[i].from_h1)
+ return CP_MSG_ALLOWED_MME_OK;
+ else
+ return CP_MSG_ALLOWED_MME_H1_NOT_ALLOWED;
+ }
}
-
- return false;
+ return CP_MSG_ALLOWED_MME_NOT_HANDLED;
}
/**
@@ -429,13 +457,13 @@ cp_msg_dispatch__allowed_mme (cp_t *ctx, cp_mme_rx_t *mme,
* \param ctx the ctx module.
* \param mme the mme context.
* \param type the event FSM event type.
- * \return true on success.
+ * \return code value on cp_msg_allowed_mme_t type.
*/
-static bool
+static enum cp_msg_allowed_mme_t
cp_msg_dispatch__allowed_mme_testing (cp_t *ctx, cp_mme_rx_t *mme,
cp_fsm_event_type_t *type)
{
- bool ok = false;
+ enum cp_msg_allowed_mme_t ok;
enum cp_msg_mme_sta_status_t status_min;
enum cp_msg_mme_sta_status_t sta_own_current_status;
@@ -444,7 +472,7 @@ cp_msg_dispatch__allowed_mme_testing (cp_t *ctx, cp_mme_rx_t *mme,
dbg_assert (type);
ok = cp_msg_dispatch__allowed_mme (ctx, mme, &status_min, type);
- if (ok
+ if (ok == CP_MSG_ALLOWED_MME_OK
&& (mme->peer.tei != MAC_TEI_FOREIGN))
{
if (cp_sta_own_data_get_authenticated_status (ctx))
@@ -454,9 +482,10 @@ cp_msg_dispatch__allowed_mme_testing (cp_t *ctx, cp_mme_rx_t *mme,
else
sta_own_current_status = CP_MSG_MME_STA_UNASSOC;
- ok = (sta_own_current_status >= status_min);
+ ok = (sta_own_current_status >= status_min) ?
+ CP_MSG_ALLOWED_MME_OK:
+ CP_MSG_ALLOWED_MME_STA_STATUS_NOK;
}
-
return ok;
}
@@ -475,7 +504,7 @@ cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme)
{
cp_fsm_event_t *event;
cp_fsm_event_type_t type;
- bool ok;
+ enum cp_msg_allowed_mme_t ok;
dbg_assert (ctx);
dbg_assert (mme);
@@ -488,40 +517,45 @@ cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme)
if (oui == SPC_OUI)
ok = cp_msg_dispatch__allowed_mme_testing (ctx, mme, &type);
else
- ok = false;
+ ok = CP_MSG_ALLOWED_MME_SPC_OUI_WRONG;
}
else
ok = cp_msg_dispatch__allowed_mme_testing (ctx, mme, &type);
- if (ok)
+ if (ok == CP_MSG_ALLOWED_MME_OK)
{
/* If the MME is embedded in a CM_ENCRYPTED_PAYLOAD, it should
* continue reading the MME to reach the embedded MME. By the same way
* if the embedded MME is encrypted it decrypts it. */
if (mme->mmtype == CM_ENCRYPTED_PAYLOAD_IND)
{
- ok = cp_msg_dispatch__read_enc_header (ctx, mme);
- if (ok)
+ if (cp_msg_dispatch__read_enc_header (ctx, mme))
{
/* Test if the embedded MME is allowed to be received. */
mme->encrypt = CP_MME_RX_SOFT_ENCRYPTED;
ok = cp_msg_dispatch__allowed_mme_testing (ctx, mme, &type);
}
+ else
+ ok = CP_MSG_ALLOWED_MME_ENC_BAD;
}
-
- if (ok && (type < CP_FSM_EVENT_TYPE_NB))
+ if (ok == CP_MSG_ALLOWED_MME_OK && type < CP_FSM_EVENT_TYPE_NB)
{
CP_TRACE (MSG_DISPATCH, phy_date (), mme->mmtype, mme->peer.tei);
-
event = cp_fsm_event_mme_new (ctx, type, mme);
cp_fsm_post (ctx, event);
}
else
+ {
+ if (type == CP_FSM_EVENT_TYPE_NB
+ && ok != CP_MSG_ALLOWED_MME_ENC_BAD)
+ ok = CP_MSG_ALLOWED_MME_NOT_HANDLED;
CP_TRACE (MSG_DISPATCH_DROP, phy_date (), mme->mmtype,
- mme->peer.tei);
+ mme->peer.tei, ok);
+ }
}
else
- CP_TRACE (MSG_DISPATCH_DROP, phy_date (), mme->mmtype, mme->peer.tei);
+ CP_TRACE (MSG_DISPATCH_DROP, phy_date (), mme->mmtype, mme->peer.tei,
+ ok);
slab_release (mme);
}
diff --git a/cesar/cp/src/trace.c b/cesar/cp/src/trace.c
index bea0cfe430..5189d4d2a8 100644
--- a/cesar/cp/src/trace.c
+++ b/cesar/cp/src/trace.c
@@ -42,6 +42,22 @@ const char *cp_trace_ce_tx_mme_error_code_table[] =
};
/**
+ * Table to associate an MME dispatch error code and its string translation.
+ */
+const char *cp_trace_rx_mme_error_code_table[] =
+{
+ "OK",
+ "NOT_HANDLED",
+ "PHY_NOT_ALLOWED",
+ "H1_NOT_ALLOWED",
+ "STA_STATUS_NOK",
+ "SPC_OUI_NOT_SPIDCOM",
+ "BAD_ENCRYPTION",
+ "UNKNOWN"
+};
+
+
+/**
* Format a FSM state.
* \see trace_format_t.
*/
@@ -117,6 +133,26 @@ cp_trace_format_mmtype (char *text, uint text_size, int data)
}
/**
+ * Copy an error into trace buffer.
+ * \param error_name the error to trace.
+ * \return error_name length on success, -1 otherwise.
+ */
+static int
+cp_trace_format_copy_error (char *text, uint text_size,
+ const char *error_name)
+{
+ /* Copy if we can. */
+ uint error_name_len = strlen (error_name);
+ if (error_name_len > text_size)
+ return -1;
+ else
+ {
+ memcpy (text, error_name, error_name_len);
+ return error_name_len;
+ }
+}
+
+/**
* Format an error of CE MME.
* \see trace_format_t.
*/
@@ -135,16 +171,22 @@ cp_trace_format_ce_mme_error (char *text, uint text_size, int data)
dbg_assert ((uint) data <= COUNT (cp_trace_ce_tx_mme_error_code_table));
/* Get error message. */
error_name = cp_trace_ce_tx_mme_error_code_table[data];
+ return cp_trace_format_copy_error (text, text_size, error_name);
+}
- /* Copy if we can. */
- uint error_name_len = strlen (error_name);
- if (error_name_len > text_size)
- return -1;
- else
- {
- memcpy (text, error_name, error_name_len);
- return error_name_len;
- }
+/**
+ * Format an dispatch error of cp_msg_dispatch.
+ * \see trace_format_t
+ */
+static int
+cp_trace_format_msg_dispatch_error (char *text, uint text_size, int data)
+{
+ const char *error_name;
+ /* Sanity check. */
+ dbg_assert ((uint) data <= COUNT (cp_trace_rx_mme_error_code_table));
+ /* Get error message. */
+ error_name = cp_trace_rx_mme_error_code_table[data];
+ return cp_trace_format_copy_error (text, text_size, error_name);
}
void
@@ -170,7 +212,7 @@ cp_trace_init (cp_t *ctx)
TIMESTAMP),
TRACE_EVENT (CP_TRACE_MSG_DISPATCH, "[MSG] receive %M from %d",
TIMESTAMP),
- TRACE_EVENT (CP_TRACE_MSG_DISPATCH_DROP, "[MSG] drop %M from %d",
+ TRACE_EVENT (CP_TRACE_MSG_DISPATCH_DROP, "[MSG] drop %M from %d, cause %Y",
TIMESTAMP),
TRACE_EVENT (CP_TRACE_MSG_SEND, "[MSG] send %M to %d",
TIMESTAMP),
@@ -216,6 +258,8 @@ cp_trace_init (cp_t *ctx)
cp_trace_format_mmtype);
trace_namespace_register_format (&namespace, 'Z',
cp_trace_format_ce_mme_error);
+ trace_namespace_register_format (&namespace, 'Y',
+ cp_trace_format_msg_dispatch_error);
trace_buffer_add (&ctx->trace, "cp", 8, 1, false, &namespace);
trace_buffer_add (&ctx->trace_verbose, "cp-verbose", 8, 8, true, &namespace);
}