summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaranjeiro2008-08-18 15:50:43 +0000
committerlaranjeiro2008-08-18 15:50:43 +0000
commitbc004dc8502f2f068a5bb7869009b4931dc71edc (patch)
tree394ab16f7dbc7ce1f0bbafdc1dadfe3a2cedbb39
parente78d84d27cfdf70261a7feb9176810762b6b7440 (diff)
cp2/cco/action: Tested the function to generate the nek key from nothing.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2735 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--cesar/cp2/cco/action/cco_action.h3
-rw-r--r--cesar/cp2/cco/action/src/cco_action.c34
-rw-r--r--cesar/cp2/cco/action/test/Makefile9
-rw-r--r--cesar/cp2/cco/action/test/src/action_gen_nek.c263
-rw-r--r--cesar/cp2/cco/action/test/src/secu_stub.c32
-rw-r--r--cesar/cp2/types.h3
6 files changed, 336 insertions, 8 deletions
diff --git a/cesar/cp2/cco/action/cco_action.h b/cesar/cp2/cco/action/cco_action.h
index 63fb0972b6..ae73747df3 100644
--- a/cesar/cp2/cco/action/cco_action.h
+++ b/cesar/cp2/cco/action/cco_action.h
@@ -58,7 +58,6 @@ cp_cco_action_garbage (cp_t *ctx);
/**
* generate a new NEK value.
* \param ctx the module context.
- * \param sl security level
*
* NEK shall be used no more than 1 hour, so must be changed after 1
* hour for that purpose, NEK expiration date is checked at every occurrence
@@ -66,7 +65,7 @@ cp_cco_action_garbage (cp_t *ctx);
* date reached, a new NEK value shall be generated by calling this function
*/
void
-cp_cco_action_gen_nek (cp_t *ctx, u8 sl);
+cp_cco_action_gen_nek (cp_t *ctx);
/**
* manage association of a station.
diff --git a/cesar/cp2/cco/action/src/cco_action.c b/cesar/cp2/cco/action/src/cco_action.c
index 8c4018d668..0a4b5400bf 100644
--- a/cesar/cp2/cco/action/src/cco_action.c
+++ b/cesar/cp2/cco/action/src/cco_action.c
@@ -221,7 +221,6 @@ cp_cco_action_garbage (cp_t *ctx)
/**
* generate a new NEK value.
* \param ctx the module context.
- * \param sl security level
*
* NEK shall be used no more than 1 hour, so must be changed after 1
* hour for that purpose, NEK expiration date is checked at every occurrence
@@ -229,7 +228,38 @@ cp_cco_action_garbage (cp_t *ctx)
* date reached, a new NEK value shall be generated by calling this function
*/
void
-cp_cco_action_gen_nek (cp_t *ctx, u8 sl);
+cp_cco_action_gen_nek (cp_t *ctx)
+{
+ u8 key[16];
+ uint random_num;
+ uint i;
+
+ dbg_assert (ctx);
+
+ // Get the key.
+ random_num = lib_rnd32 (&ctx->rnd);
+ cp_secu_aes_generate_key (random_num, key);
+
+ // Set the key.
+ if (ctx->mac_config->nek[0].nek[0] == 0)
+ {
+ for (i = 0; i < 4; i++)
+ ctx->mac_config->nek[0].nek[i] = ((u32*) key)[i];
+
+ // Get the key.
+ random_num = lib_rnd32 (&ctx->rnd);
+ cp_secu_aes_generate_key (random_num, key);
+
+ for (i = 0; i < 4; i++)
+ ctx->mac_config->nek[1].nek[i] = ((u32*) key)[i];
+ }
+ else
+ {
+ ctx->mac_config->nek[0] = ctx->mac_config->nek[1];
+ for (i = 0; i < 4; i++)
+ ctx->mac_config->nek[1].nek[i] = ((u32*) key)[i];
+ }
+}
/**
* manage association of a station.
diff --git a/cesar/cp2/cco/action/test/Makefile b/cesar/cp2/cco/action/test/Makefile
index c2fe292170..a09361ae48 100644
--- a/cesar/cp2/cco/action/test/Makefile
+++ b/cesar/cp2/cco/action/test/Makefile
@@ -4,12 +4,15 @@ ECOS = y
INCLUDES = cp2/cco/action/test/overide
-TARGET_PROGRAMS = action garbage
+TARGET_PROGRAMS = action garbage action_gen_nek
-action_SOURCES = action-test.c
+action_SOURCES = action-test.c secu_stub.c
action_MODULES = lib cp2/cco/action mac/common cp2/sta/mgr cl
-garbage_SOURCES = garbage.c fsm_stub.c
+garbage_SOURCES = garbage.c fsm_stub.c secu_stub.c
garbage_MODULES = lib cp2/cco/action mac/common cp2/sta/mgr cl
+action_gen_nek_SOURCES = action_gen_nek.c secu_stub.c fsm_stub.c
+action_gen_nek_MODULES = lib cp2/cco/action mac/common cp2/sta/mgr cl
+
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/cco/action/test/src/action_gen_nek.c b/cesar/cp2/cco/action/test/src/action_gen_nek.c
new file mode 100644
index 0000000000..51e647d70e
--- /dev/null
+++ b/cesar/cp2/cco/action/test/src/action_gen_nek.c
@@ -0,0 +1,263 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/action_gen_nek.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "string.h"
+
+#include "lib/test.h"
+#include "lib/utils.h"
+#include "lib/swap.h"
+#include "lib/read_word.h"
+
+#include "cl/cl_mactotei.h"
+
+#include "common/defs/homeplugAV.h"
+#include "common/defs/ethernet.h"
+
+#include "mac/common/ntb.h"
+
+#include "cp2/cp.h"
+#include "cp2/fsm/fsm.h"
+#include "cp2/msg/msg.h"
+#include "cp2/sta/mgr/sta.h"
+
+#include "cp2/cco/action/cco_action.h"
+#include "cp2/cco/action/inc/cco_action.h"
+
+#include "cp2/inc/context.h"
+#include "stdio.h"
+
+static cp_t cp;
+static test_t test;
+
+void
+test_case_gen_nek (void)
+{
+ uint i;
+ /* Initialise the seed of the random generator. */
+ lib_rnd_init (&cp.rnd, 0x12345678);
+
+ cp_cco_action_gen_nek (&cp);
+
+ test_begin (test, "Verify first shot")
+ {
+ for (i = 0; i < 4; i++)
+ {
+ test_fail_if (cp.mac_config->nek[0].nek[i] != 0xc6979343);
+ test_fail_if (cp.mac_config->nek[1].nek[i] != 0x962d2fa);
+ }
+ }
+ test_end;
+
+ cp_cco_action_gen_nek (&cp);
+
+ test_begin (test, "Verify second shot")
+ {
+ for (i = 0; i < 4; i++)
+ {
+ test_fail_if (cp.mac_config->nek[0].nek[i] != 0x962d2fa);
+ test_fail_if (cp.mac_config->nek[1].nek[i] != 0xa73a24a4);
+ }
+ }
+ test_end;
+
+ cp_cco_action_gen_nek (&cp);
+
+ test_begin (test, "Verify third shot")
+ {
+ for (i = 0; i < 4; i++)
+ {
+ test_fail_if (cp.mac_config->nek[0].nek[i] != 0xa73a24a4);
+ test_fail_if (cp.mac_config->nek[1].nek[i] != 0xe118a180);
+ }
+ }
+ test_end;
+
+ /* Re init the module. */
+ cp.mac_config->nek[0].nek[0] = 0;
+ cp.mac_config->nek[0].nek[1] = 0;
+
+ cp_cco_action_gen_nek (&cp);
+
+ test_begin (test, "Verify after reinit.")
+ {
+ for (i = 0; i < 4; i++)
+ {
+ test_fail_if (cp.mac_config->nek[0].nek[i] != 0xb5475abb);
+ test_fail_if (cp.mac_config->nek[1].nek[i] != 0x64613c7c);
+ }
+ }
+ test_end;
+}
+
+int
+main (void)
+{
+ mac_config_t mac_config;
+
+ test_init (test, 0, NULL);
+
+ cp.mac_config = &mac_config;
+
+ test_case_gen_nek ();
+
+ test_case_begin (test, "Memory leaks");
+
+ test_begin (test, "Memory leaks verification")
+ {
+ test_fail_if (blk_check_memory() == false, "Memory not freed");
+ }
+ test_end;
+
+ test_result (test);
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+
+}
+
+void
+cp_beacon_change_snid (cp_t *ctx, u8 snid)
+{
+}
+
+u32
+phy_date (phy_t *phy)
+{
+ return 42;
+}
+
+/**
+ * Begin a CC_SET_TEI_MAP.IND construction.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param mode update, add or delete
+ * \param sta_nb number of stations sent
+ * \return the MME being constructed
+ */
+cp_mme_tx_t *
+cp_msg_cc_set_tei_map_ind_send_begin (
+ cp_t *ctx, cp_mme_peer_t *peer,
+ enum cp_msg_cc_set_tei_map_ind_mode_t mode, uint sta_nb)
+{
+ return NULL;
+}
+
+/**
+ *
+ * Write a station to a CC_SET_TEI_MAP.IND being constructed.
+ * \param ctx control plane context
+ * \param mme MME being constructed
+ * \param tei STA TEI
+ * \param mac STA mac address
+ * \param status STA status
+ */
+void
+cp_msg_cc_set_tei_map_ind_send_sta (
+ cp_t *ctx, cp_mme_tx_t *mme, cp_tei_t tei, mac_t mac,
+ enum cp_msg_cc_set_tei_map_ind_status_t status)
+{
+}
+
+/**
+ * Finalise and send a CC_SET_TEI_MAP.IND message.
+ * \param ctx control plane context
+ * \param mme MME being constructed
+ */
+void
+cp_msg_cc_set_tei_map_ind_send_end (cp_t *ctx, cp_mme_tx_t *mme)
+{
+}
+
+/**
+ * Receive a CC_ASSOC.REQ.
+ * \param ctx control plane context
+ * \param mme MME handle
+ * \param data received MME data
+ * \return true on success
+ */
+bool
+cp_msg_cc_assoc_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
+ cp_msg_cc_assoc_req_t *data)
+{
+ return true;
+}
+
+/**
+ * Send a CC_ASSOC.CNF.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param data MME data to send
+ */
+void
+cp_msg_cc_assoc_cnf_send (cp_t *ctx, cp_mme_peer_t *peer,
+ const cp_msg_cc_assoc_cnf_t *data)
+{
+}
+
+/**
+ * Receive a CM_GET_KEY.REQ.
+ * \param ctx control plane context
+ * \param mme MME handle
+ * \param data received MME data
+ * \return true on success
+ *
+ * Encryption and protocol run information is available in the MME handle.
+ */
+bool
+cp_msg_cm_get_key_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
+ cp_msg_cm_get_key_req_t *data)
+{
+ return true;
+}
+
+/**
+ * Send a CM_GET_KEY.CNF.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param peks payload encryption key select
+ * \param prun protocol run information
+ * \param data MME data to send
+ */
+void
+cp_msg_cm_get_key_cnf_send (cp_t *ctx, cp_mme_peer_t *peer,
+ cp_mme_peks_t peks,
+ const cp_secu_protocol_run_t *prun,
+ const cp_msg_cm_get_key_cnf_t *data)
+{
+}
+
+/**
+ * Send a CC_LEAVE.CNF.
+ * \param ctx control plane context
+ * \param peer peer information
+ */
+void
+cp_msg_cc_leave_cnf_send (cp_t *ctx, cp_mme_peer_t *peer)
+{
+}
+
+/**
+ * Send a CC_LEAVE.IND.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param reason reason for the disassociation
+ * \param nid NID
+ */
+void
+cp_msg_cc_leave_ind_send (cp_t *ctx, cp_mme_peer_t *peer,
+ enum cp_msg_cc_leave_ind_reason_t reason,
+ cp_nid_t nid)
+{
+}
+
diff --git a/cesar/cp2/cco/action/test/src/secu_stub.c b/cesar/cp2/cco/action/test/src/secu_stub.c
new file mode 100644
index 0000000000..f295e26943
--- /dev/null
+++ b/cesar/cp2/cco/action/test/src/secu_stub.c
@@ -0,0 +1,32 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/secu_stub.c
+ * \brief The security functions.
+ * \ingroup cp2/cco/action
+ *
+ */
+#include "common/std.h"
+
+#include "cp2/secu/secu.h"
+
+/**
+ * Generate the AES key.
+ * \param num a random number.
+ * \param output the key generated.
+ */
+void
+cp_secu_aes_generate_key (uint num, u8 *output)
+{
+ uint i;
+ dbg_assert (num);
+ dbg_assert (output);
+
+ for (i = 0; i < 4; i++)
+ ((u32 *) output)[i] = num;
+}
diff --git a/cesar/cp2/types.h b/cesar/cp2/types.h
index a87292115d..fa273b88df 100644
--- a/cesar/cp2/types.h
+++ b/cesar/cp2/types.h
@@ -38,7 +38,8 @@ typedef struct cp_key_t cp_key_t;
enum cp_security_level_t
{
CP_SECURITY_LEVEL_SC,
- CP_SECURITY_LEVEL_HS
+ CP_SECURITY_LEVEL_HS,
+ CP_SECURITY_LEVEL_NB
};
typedef enum cp_security_level_t cp_security_level_t;