summaryrefslogtreecommitdiff
path: root/cesar/cp/eoc/sta/mgr/test/utest/src/sta-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/eoc/sta/mgr/test/utest/src/sta-test.c')
-rw-r--r--cesar/cp/eoc/sta/mgr/test/utest/src/sta-test.c689
1 files changed, 689 insertions, 0 deletions
diff --git a/cesar/cp/eoc/sta/mgr/test/utest/src/sta-test.c b/cesar/cp/eoc/sta/mgr/test/utest/src/sta-test.c
new file mode 100644
index 0000000000..dd1d4b80d4
--- /dev/null
+++ b/cesar/cp/eoc/sta/mgr/test/utest/src/sta-test.c
@@ -0,0 +1,689 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/sta-test.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/bitstream.h"
+
+#include "cp/sta/mgr/sta_own_data.h"
+
+#include "cp/inc/context.h"
+#include "cp/sta/mgr/inc/sta_own_data.h"
+
+#include "cl/inc/context.h"
+#include "mac/sar/inc/context.h"
+#include <string.h>
+#include "cp/fsm/fsm.h"
+
+static void
+test_sta_own_init (cp_t *cp)
+{
+ static mac_config_t mac_config;
+ static cl_t cl;
+ static sar_t sar;
+ memset (&mac_config, 0, sizeof (mac_config));
+ memset (&cl, 0, sizeof (cl_t));
+ memset (&sar, 0, sizeof (sar_t));
+ memset (cp, 0, sizeof (cp_t));
+ cp->mac_config = &mac_config;
+ cp->cl = &cl;
+ cp->sar = &sar;
+ cp->mac_store = sar.mac_store = mac_store_init ();
+ lib_rnd_init (&cp->rnd, 1234);
+ lib_stats_init ();
+ cp_eoc_sta_mgr_init (cp);
+}
+
+static void
+test_sta_own_uninit (cp_t *cp)
+{
+ cp_sta_mgr_uninit (cp);
+ mac_store_uninit (cp->mac_store);
+ lib_stats_uninit ();
+}
+
+void
+test_case_cp_sta_own_data_init (test_t test)
+{
+ test_case_begin (test, "init");
+
+ test_begin (test, "init")
+ {
+ cp_t cp;
+ cp_sta_own_data_private_t cmp;
+ cp_sta_own_data_private_t *real;
+
+ memset (&cmp, 0, sizeof (cp_sta_own_data_private_t));
+ cmp.public.hybrid_mode = MAC_COEXISTENCE_AV_ONLY_MODE; /* EoC spec. */
+
+ test_sta_own_init (&cp);
+ cmp.snid = cp_sta_own_data_get_snid (&cp);
+
+ real = (cp_sta_own_data_private_t*) cp_sta_mgr_get_sta_own_data(&cp);
+ test_fail_if (
+ memcmp(&cmp, real, sizeof (cp_sta_own_data_private_t)) != 0);
+
+ test_sta_own_uninit (&cp);
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__set_and_get_tei (test_t test)
+{
+ test_case_begin (test, "Set Get tei");
+
+ test_begin (test, "Set")
+ {
+ cp_t cp;
+ cp_net_t *net;
+ test_sta_own_init (&cp);
+ // Add an AVLN.
+ net = cp_sta_mgr_add_avln (&cp, 1, 1);
+ cp_sta_mgr_set_our_avln (&cp, net);
+
+ cp_sta_own_data_set_tei (&cp, 2);
+
+ test_fail_if (cp_sta_own_data_get_tei (&cp) != 2);
+
+ cp_sta_own_data_set_tei (&cp, 2);
+ test_fail_if (cp_sta_own_data_get_tei (&cp) != 2);
+
+ cp_sta_own_data_set_tei (&cp, MAC_TEI_UNASSOCIATED);
+ test_fail_unless (cp_sta_own_data_get_tei (&cp) ==
+ MAC_TEI_UNASSOCIATED);
+ test_sta_own_uninit (&cp);
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__mac_address (test_t test)
+{
+ test_case_begin (test, "Mac address");
+
+ test_begin (test, "Set and Get the mac address")
+ {
+ cp_t cp;
+
+ mac_config_t mac_config;
+ cp.mac_config = &mac_config;
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+
+ cp_eoc_sta_mgr_init (&cp);
+ cp_sta_own_data_set_mac_address (&cp, 0x123456789ABCull);
+
+ test_fail_if (cp_sta_own_data_get_mac_address (&cp) !=
+ 0x123456789ABCull);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__npw (test_t test)
+{
+ test_case_begin (test, "Set and get the NPW");
+
+ test_begin (test, "NPW")
+ {
+ cp_t cp;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ cp_sta_own_data_set_npw (&cp, "Hello world");
+
+ test_fail_if (
+ strcmp (cp_sta_own_data_get_npw (&cp), "Hello world") != 0);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__nmk (test_t test)
+{
+ test_case_begin (test, "Set and get the NMK");
+
+ test_begin (test, "NMK")
+ {
+ cp_t cp;
+ cp_key_t key;
+ cp_key_t res;
+ bool changed;
+
+ key.key[0] = 0x1234;
+ key.key[1] = 0x5678;
+ key.key[2] = 0x9abc;
+ key.key[3] = 0xdef0;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ changed = cp_sta_own_data_set_nmk (&cp, key, 0);
+
+ res = cp_sta_own_data_get_nmk (&cp);
+
+ test_fail_if (changed == false);
+ test_fail_if (memcmp (&res, &key, sizeof (cp_key_t)) != 0);
+
+ changed = cp_sta_own_data_set_nmk (&cp, key, 0);
+ test_fail_if (changed == true);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__dpw (test_t test)
+{
+ test_case_begin (test, "Set and get the DPW");
+
+ test_begin (test, "DPW")
+ {
+ cp_t cp;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ cp_sta_own_data_set_dpw (&cp, "Hello world");
+
+ test_fail_if (
+ strcmp (cp_sta_own_data_get_dpw (&cp), "Hello world") != 0);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__security_level (test_t test)
+{
+ test_case_begin (test, "Set and get the SL");
+
+ test_begin (test, "SL")
+ {
+ cp_t cp;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ cp_sta_own_data_set_security_level (&cp, CP_SECURITY_LEVEL_SC);
+
+ test_fail_if (cp_sta_own_data_get_security_level (&cp) !=
+ CP_SECURITY_LEVEL_SC);
+
+ cp_sta_own_data_set_security_level (&cp, CP_SECURITY_LEVEL_HS);
+
+ test_fail_if (cp_sta_own_data_get_security_level (&cp) !=
+ CP_SECURITY_LEVEL_HS);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__was_cco (test_t test)
+{
+ test_case_begin (test, "Set and get was_cco");
+
+ test_begin (test, "was_cco")
+ {
+ cp_t cp;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ cp_sta_own_data_set_was_cco (&cp, true);
+ test_fail_if (cp_sta_own_data_get_was_cco(&cp) != true);
+ cp_sta_own_data_set_was_cco (&cp, false);
+ test_fail_if (cp_sta_own_data_get_was_cco (&cp) != false);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+
+}
+
+void
+test_case_cp_sta_own_data__hfid_avln (test_t test)
+{
+ test_case_begin (test, "Set and get the AVLN HFID");
+
+ test_begin (test, "AVLN HFID")
+ {
+ cp_t cp;
+ cp_sta_own_data_t *sta;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_hfid_avln (&cp, "Hello world");
+
+ test_fail_if (
+ strcmp (sta->hfid_avln, "Hello world") != 0);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__hfid_user (test_t test)
+{
+ test_case_begin (test, "Set and get the USER HFID");
+
+ test_begin (test, "USER HFID")
+ {
+ cp_t cp;
+ cp_sta_own_data_t *sta;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_hfid_user (&cp, "Hello world");
+
+ test_fail_if (
+ strcmp (sta->hfid_user, "Hello world") != 0);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__hfid_manufacturer (test_t test)
+{
+ test_case_begin (test, "Set and get the MANUFACTURER HFID");
+
+ test_begin (test, "MANUFACTURER HFID")
+ {
+ cp_t cp;
+ cp_sta_own_data_t *sta;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_hfid_manufacturer (&cp, "Hello world");
+
+ test_fail_if (
+ strcmp (sta->hfid_manufacturer, "Hello world") != 0);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__pco_glid (test_t test)
+{
+ test_case_begin (test, "Set and get the PCO glid");
+
+ test_begin (test, "PCo")
+ {
+ cp_t cp;
+ cp_sta_own_data_t *sta;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_pco_glid (&cp, 0x90);
+ test_fail_if (cp_sta_own_data_get_pco_glid (&cp) != 0x90);
+ cp_sta_own_data_set_pco_glid (&cp, 0x0);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__pco_status (test_t test)
+{
+ test_case_begin (test, "Set and get the PCO status");
+
+ test_begin (test, "PCo")
+ {
+ cp_t cp;
+ cp_sta_own_data_t *sta;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+
+ cp_sta_own_data_set_pco_status (&cp, true);
+ test_fail_if (cp_sta_own_data_get_pco_status (&cp) != true);
+
+ cp_sta_own_data_set_pco_status (&cp, true);
+ test_fail_if (cp_sta_own_data_get_pco_status (&cp) != true);
+
+ cp_sta_own_data_set_pco_status (&cp, false);
+ test_fail_if (cp_sta_own_data_get_pco_status (&cp) != false);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+
+ test_begin (test, "PCo and glid")
+ {
+ cp_t cp;
+ cp_sta_own_data_t *sta;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_pco_status (&cp, true);
+ cp_sta_own_data_set_pco_glid (&cp, 0x85);
+
+ test_fail_if (cp_sta_own_data_get_pco_status (&cp) != true);
+ test_fail_if (cp_sta_own_data_get_pco_glid (&cp) != 0x85);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__cco_status (test_t test)
+{
+ test_case_begin (test, "Set and get the CCo status");
+
+ test_begin (test, "CCo")
+ {
+ cp_t cp;
+ cp_net_t *net;
+ mac_config_t mac_config;
+ cp_sta_own_data_t *sta;
+ cl_t cl;
+ sar_t sar;
+
+ cp.mac_config = &mac_config;
+ cl.mactotei = NULL;
+ cp.cl = &cl;
+ cp.sar = &sar;
+ cp.mac_store = mac_store_init ();
+ sar.mac_store = cp.mac_store;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ net = cp_sta_mgr_add_avln (&cp, 1, 1);
+ cp_sta_mgr_set_our_avln (&cp, net);
+
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_tei (&cp, 1);
+
+ cp_sta_own_data_set_cco_status (&cp, true);
+ test_fail_if (cp_sta_own_data_get_cco_status (&cp) != true);
+
+ cp_sta_own_data_set_cco_status (&cp, true);
+ test_fail_if (cp_sta_own_data_get_cco_status (&cp) != true);
+
+ cp_sta_own_data_set_cco_status (&cp, false);
+ test_fail_if (cp_sta_own_data_get_cco_status (&cp) != false);
+
+ cp_sta_mgr_uninit (&cp);
+ mac_store_uninit (cp.mac_store);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__authenticated_status (test_t test)
+{
+ test_case_begin (test, "Set and get the CCo authenticated");
+
+ test_begin (test, "CCo")
+ {
+ cp_t cp;
+ cp_net_t *net;
+ mac_config_t mac_config;
+ cp_sta_own_data_t *sta;
+ cl_t cl;
+ sar_t sar;
+
+ cp.mac_config = &mac_config;
+ cl.mactotei = NULL;
+ cp.cl = &cl;
+ cp.sar = &sar;
+ cp.mac_store = mac_store_init ();
+ sar.mac_store = cp.mac_store;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+ net = cp_sta_mgr_add_avln (&cp, 1, 1);
+ cp_sta_mgr_set_our_avln (&cp, net);
+
+ sta = cp_sta_mgr_get_sta_own_data (&cp);
+ cp_sta_own_data_set_tei (&cp, 1);
+
+ cp_sta_own_data_set_authenticated_status (&cp, true);
+ test_fail_if (cp_sta_own_data_get_authenticated_status (&cp) != true);
+
+ cp_sta_own_data_set_authenticated_status (&cp, true);
+ test_fail_if (cp_sta_own_data_get_authenticated_status (&cp) != true);
+
+ cp_sta_own_data_set_authenticated_status (&cp, false);
+ test_fail_if (cp_sta_own_data_get_authenticated_status (&cp) != false);
+
+ cp_sta_mgr_uninit (&cp);
+ mac_store_uninit (cp.mac_store);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__nid (test_t test)
+{
+ test_case_begin (test, "Set/Get NID & SL");
+
+ test_begin (test, "")
+ {
+ cp_t cp;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+
+ lib_rnd_t rnd;
+ lib_rnd_init (&rnd, 0x4224);
+
+ cp_security_level_t sl;
+ for (sl = CP_SECURITY_LEVEL_SC; sl < CP_SECURITY_LEVEL_NB; sl++)
+ {
+ uint i;
+ for (i = 0; i < 1234; i++)
+ {
+ cp_nid_t nid = ((u64) sl) << (HPAV_NID_SIZE_BITS - 2)
+ | lib_rnd_uniform (&rnd, -1);
+ cp_sta_own_data_set_nid (&cp, nid);
+ test_fail_if (cp_sta_own_data_get_nid (&cp) != nid);
+ test_fail_if (cp_sta_own_data_get_security_level (&cp) != sl);
+ }
+ }
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__snid (test_t test)
+{
+ test_case_begin (test, "Set and GET SNID");
+
+ test_begin (test, "")
+ {
+ cp_t cp;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+
+ cp_sta_own_data_set_snid (&cp, 0x2);
+ test_fail_if (cp_sta_own_data_get_snid (&cp) != 0x2);
+ cp_sta_own_data_set_snid (&cp, 0x1);
+ test_fail_if (cp_sta_own_data_get_snid (&cp) != 0x1);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__tek (test_t test)
+{
+ test_case_begin (test, "Set the TEK");
+
+ test_begin (test, "TEK")
+ {
+ cp_t cp;
+ cp_key_t key;
+ cp_key_t tek;
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+
+ key.key[0] = 0x12345678;
+ key.key[1] = 0x12345678;
+ key.key[2] = 0x12345678;
+ key.key[3] = 0x12345678;
+
+ cp_sta_own_data_set_tek (&cp, key);
+
+ tek = cp_sta_own_data_get_tek (&cp);
+
+ test_fail_unless (memcmp (&tek, &key, sizeof (cp_key_t)) == 0);
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__dak (test_t test)
+{
+ test_case_begin (test, "DAK");
+
+ test_begin (test, "store dak")
+ {
+ cp_t cp;
+ uint i;
+ cp_key_t dak = { {0x11111111, 0x22222222, 0x33333333, 0x44444444} };
+ cp_key_t own_dak;
+
+ memset (&cp, 0, sizeof (cp_t));
+
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+
+ cp_sta_own_data_set_dak (&cp, dak);
+ own_dak = cp_sta_own_data_get_dak (&cp);
+
+ for (i = 0; i < COUNT (dak.key); i++)
+ test_fail_unless (dak.key[i] == own_dak.key[i]);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_case_cp_sta_own_data__sc (test_t test)
+{
+ test_case_begin (test, "Simple connect");
+
+ test_begin (test, "")
+ {
+ cp_t cp;
+
+ memset (&cp, 0, sizeof (cp_t));
+ lib_stats_init ();
+ lib_rnd_init (&cp.rnd, 0x432);
+ cp_eoc_sta_mgr_init (&cp);
+
+ cp_sta_own_data_set_sc (&cp, true);
+ test_fail_unless (cp.sta_mgr.sta_own_data.sc == true);
+ test_fail_unless (cp_sta_own_data_get_sc (&cp) == true);
+
+ cp_sta_own_data_set_sc (&cp, true);
+ test_fail_unless (cp.sta_mgr.sta_own_data.sc == true);
+ test_fail_unless (cp_sta_own_data_get_sc (&cp) == true);
+
+ cp_sta_own_data_set_sc (&cp, false);
+ test_fail_unless (cp.sta_mgr.sta_own_data.sc == false);
+ test_fail_unless (cp_sta_own_data_get_sc (&cp) == false);
+
+ cp_sta_mgr_uninit (&cp);
+ lib_stats_uninit ();
+ }
+ test_end;
+}
+
+void
+test_suite_sta_own (test_t test)
+{
+ test_suite_begin (test, "station own data");
+ test_case_cp_sta_own_data_init (test);
+ test_case_cp_sta_own_data__set_and_get_tei (test);
+ test_case_cp_sta_own_data__mac_address (test);
+ test_case_cp_sta_own_data__npw (test);
+ test_case_cp_sta_own_data__nmk (test);
+ test_case_cp_sta_own_data__dpw (test);
+ test_case_cp_sta_own_data__security_level (test);
+ test_case_cp_sta_own_data__was_cco (test);
+ test_case_cp_sta_own_data__hfid_avln (test);
+ test_case_cp_sta_own_data__hfid_user (test);
+ test_case_cp_sta_own_data__hfid_manufacturer (test);
+ test_case_cp_sta_own_data__pco_glid (test);
+ test_case_cp_sta_own_data__pco_status (test);
+ test_case_cp_sta_own_data__cco_status (test);
+ test_case_cp_sta_own_data__authenticated_status (test);
+ test_case_cp_sta_own_data__nid (test);
+ test_case_cp_sta_own_data__snid (test);
+ test_case_cp_sta_own_data__tek (test);
+ test_case_cp_sta_own_data__dak (test);
+ test_case_cp_sta_own_data__sc (test);
+}