summaryrefslogtreecommitdiff
path: root/cp
diff options
context:
space:
mode:
authorGuillaume2007-09-07 14:15:33 +0000
committerGuillaume2007-09-07 14:15:33 +0000
commit510b07e79ed1c6ae2d6b41d44dba1cf97ac0f700 (patch)
tree3cee6472bb7014963b1d63a835e9eb866877482e /cp
parent323290ec30a1e577a552f2ab5f8a3b2065c4f3f4 (diff)
work in progress...
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@680 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cp')
-rw-r--r--cp/cp_types.h13
-rw-r--r--cp/interf/inc/interf_private.h10
-rw-r--r--cp/interf/inc/interf_sar_layer.h26
-rw-r--r--cp/interf/inc/interf_types.h60
-rw-r--r--cp/interf/interf.h55
-rw-r--r--cp/interf/src/interf.c793
-rw-r--r--cp/interf/src/interf_sar_layer.c39
-rw-r--r--cp/msg/Module2
-rw-r--r--cp/msg/inc/msg_cc.h20
-rw-r--r--cp/msg/inc/msg_cm.h34
-rw-r--r--cp/msg/inc/msg_const.h200
-rw-r--r--cp/msg/msg.h89
-rw-r--r--cp/msg/src/msg.c122
-rw-r--r--cp/msg/src/msg_cc.c7
-rw-r--r--cp/msg/src/msg_cm.c48
-rw-r--r--cp/station/Makefile2
-rw-r--r--cp/station/Module2
-rw-r--r--cp/station/inc/station_events.h55
-rw-r--r--cp/station/inc/station_types.h68
-rw-r--r--cp/station/src/station.c95
-rw-r--r--cp/station/src/station_events.c95
-rw-r--r--cp/station/src/station_fsm.c228
-rw-r--r--cp/station/station.h66
-rw-r--r--cp/test/Makefile2
-rw-r--r--cp/test/inc/test_interf.h8
-rw-r--r--cp/test/inc/test_msg.h10
-rw-r--r--cp/test/inc/test_secu.h7
-rw-r--r--cp/test/inc/test_station.h22
-rw-r--r--cp/test/src/test_cp.c48
-rw-r--r--cp/test/src/test_interf.c565
-rw-r--r--cp/test/src/test_msg.c77
-rw-r--r--cp/test/src/test_secu.c487
-rw-r--r--cp/test/src/test_station.c125
33 files changed, 2094 insertions, 1386 deletions
diff --git a/cp/cp_types.h b/cp/cp_types.h
index def6bde85a..de7241ccc4 100644
--- a/cp/cp_types.h
+++ b/cp/cp_types.h
@@ -13,19 +13,21 @@
#ifndef cp_types__h__
#define cp_types__h__
-
+
#define MAX_STA_NB 64 // maximum number of STA within an AVLN
#define MAX_AVLN_NB 8 // maximum number of AVLN
+// if you'v got an idea to set the constant with only 6 byte, tell me ! (GL)
+#define BROADCAST_MAC_AD "\xFF\xFF\xFF\xFF\xFF\xFF"
+
+typedef u8 mac_adresse_t[6];
-typedef u8 mac_adresse_t[6];
-typedef u16 mm_type_t;
typedef enum E_ErrCode
{
Success = 0,
Failure,
- // SECU error codes
+ // SECU error codes
PWD_UnknowType,
PWD_ForbidenChar,
PWD_WrongSize,
@@ -34,10 +36,9 @@ typedef enum E_ErrCode
PRN_Wrong,
PMN_Wrong,
PRN_NotInitialised,
- // INTERF error codes
+ // INTERF error codes
NbBufIncoherent
} E_ErrCode;
-
#endif
diff --git a/cp/interf/inc/interf_private.h b/cp/interf/inc/interf_private.h
index d18bac05ac..bec7af56ea 100644
--- a/cp/interf/inc/interf_private.h
+++ b/cp/interf/inc/interf_private.h
@@ -19,8 +19,7 @@
* \param (void *) pointer to message fragment
* \return NULL or ptr to first part of message MME is complete
*/
-msg_mme_t *
-interf_received_frag(msg_mme_t *msg);
+msg_mme_t *interf_received_frag (msg_mme_t *msg);
/**
* \brief Add message in fifo
@@ -29,9 +28,7 @@ interf_received_frag(msg_mme_t *msg);
* \param pointer to message
* \return
*/
-void
-interf_msg_add(msg_mme_dest_t mme_dest, msg_mme_t *msg);
-
+void interf_msg_add (msg_mme_dest_t mme_dest, msg_mme_t *msg);
/**
* \brief release a buffer for CCO or STA
@@ -39,7 +36,6 @@ interf_msg_add(msg_mme_dest_t mme_dest, msg_mme_t *msg);
* \param
* \return
*/
-void
-interf_local_buf_release(msg_mme_t *msg);
+void interf_local_buf_release (msg_mme_t *msg);
#endif /*INTERF_PRIVATE_H_*/
diff --git a/cp/interf/inc/interf_sar_layer.h b/cp/interf/inc/interf_sar_layer.h
index a9d3bf81ba..7e6aa558c5 100644
--- a/cp/interf/inc/interf_sar_layer.h
+++ b/cp/interf/inc/interf_sar_layer.h
@@ -14,55 +14,45 @@
#ifndef INTERF_SAR_LAYER_H_
#define INTERF_SAR_LAYER_H_
-
-#include "cp/interf/inc/interf_types.h"
-#include "cp/interf/interf.h"
+//#include "cp/interf/inc/interf_types.h"
+//#include "cp/interf/interf.h"
#include "mac/sar/sar.h"
#include "mac/sar/inc/sar_public_interfaces.h"
+#include "cp/msg/inc/msg_const.h"
/**
* \brief init the interf_sar layer
* \param
* \return
*/
-void
-interf_sar_layer_init(void);
-
+void interf_sar_layer_init (void);
/**
* \brief function to give the buffer to the interface
* \param
* \return
*/
-void
-interf_sar_layer_add_buf(msg_mme_t *msg);
-
+void interf_sar_layer_add_buf (msg_mme_t *msg);
/**
* \brief to send a message through the interface
* \param
* \return
*/
-void
-interf_sar_layer_send_buf(msg_mme_t *msg);
+void interf_sar_layer_send_buf (msg_mme_t *msg);
/**
* \brief
* \param
* \return
*/
-int
-interf_sar_layer_rel_buf(void);
+int interf_sar_layer_rel_buf (void);
/**
* \brief
* \param
* \return
*/
-int
-interf_sar_layer_cb_rc(void);
-
-
-
+int interf_sar_layer_cb_rc (void);
#endif /*INTER_SAR_LAYER_H_*/
diff --git a/cp/interf/inc/interf_types.h b/cp/interf/inc/interf_types.h
index a1bf80b758..2476ac982b 100644
--- a/cp/interf/inc/interf_types.h
+++ b/cp/interf/inc/interf_types.h
@@ -13,12 +13,11 @@
#ifndef INTERF_TYPES_H_
#define INTERF_TYPES_H_
-
#include <cyg/kernel/kapi.h>
#include "lib/types.h"
#include "cp/cp_types.h"
-#include "cp/msg/msg.h"
+#include "cp/msg/inc/msg_const.h"
/*
* Homeplug AV constantes
@@ -34,61 +33,66 @@
/*
* check constant coherency
- */
+ */
#if (INTERF_NB_BUFFER < MAX_STA_NB)
#error "not enougth buffer"
#endif
#if (CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE < INTERF_NB_BUFFER)
- #warning "interf.h : CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE looks too small"
+ #warning "interf.h : CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE looks too small"
#endif
/*
* basic types for INTERF
*/
-
// !!! warning : don't change this enum order !!!
-typedef enum interf_id_t {INTERF_CP, INTERF_SAR, INTERF_CE, INTERF_HLE} interf_id_t;
+typedef enum interf_id_t
+{
+ INTERF_CP,
+ INTERF_SAR,
+ INTERF_CE,
+ INTERF_HLE,
+ INTERF_MAX // this is used for test purpose
+} interf_id_t;
typedef struct interf_buffer_t
{
- interf_id_t id;
- uint size;
- msg_mme_t msg;
- msg_mme_t *next_msg;
+ interf_id_t id;
+ uint size;
+ msg_mme_t msg;
+ msg_mme_t *next_msg;
} interf_buffer_t;
typedef struct interf_msg_file_t
{
- msg_mme_t *msg[INTERF_NB_BUFFER];
- uint start;
- uint current;
+ msg_mme_t *msg[INTERF_NB_BUFFER];
+ uint start;
+ uint current;
} interf_msg_file_t;
typedef struct interf_frag_msg_t
{
- mac_adresse_t osa;
- u8 fmsn;
- cyg_tick_count_t date_cyg_tick;
- u8 frag_counter; // also used to check if the slot is empty !
- msg_mme_t *msg[INTERF_MAX_FRAG_PER_MSG];
+ mac_adresse_t osa;
+ u8 fmsn;
+ cyg_tick_count_t date_cyg_tick;
+ u8 frag_counter; // also used to check if the slot is empty !
+ msg_mme_t *msg[INTERF_MAX_FRAG_PER_MSG];
} interf_frag_msg_t;
typedef struct interf_multicast_msg_t
{
- u8 nb_sta;
- mm_type_t mme_type;
- mac_adresse_t osa[MAX_STA_NB];
- msg_mme_t *msg;
+ u8 nb_sta;
+ mm_type_t mme_type;
+ mac_adresse_t osa[MAX_STA_NB];
+ msg_mme_t *msg;
} interf_multicast_msg_t;
typedef struct interf_desc_t
{
- u8 nb_buf; // nb of buff we allocate to this interface
- void (*pf_add_buf)(msg_mme_t *msg); // function to give the buffer to the interface
- void (*pf_send_buf)(msg_mme_t *msg); // to send a message through the interface
- int (*pf_rel_buf)(void);
- int (*pf_cb_rc)(void);
+ u8 nb_buf; // nb of buff we allocate to this interface
+ void (*pf_add_buf) (msg_mme_t *msg); // function to give the buffer to the interface
+ void (*pf_send_buf) (msg_mme_t *msg); // to send a message through the interface
+ int (*pf_rel_buf) (void);
+ int (*pf_cb_rc) (void);
} interf_desc_t;
-
#endif /*INTERF_TYPES_H_*/
diff --git a/cp/interf/interf.h b/cp/interf/interf.h
index 1d9ed7d77c..bdfaea2d9b 100644
--- a/cp/interf/interf.h
+++ b/cp/interf/interf.h
@@ -21,22 +21,20 @@
#include <cyg/kernel/kapi.h>
#include "lib/types.h"
-//#include "cp/station/inc/station_types.h"
-#include "cp/station/station.h"
-#include "cp/interf/inc/interf_sar_layer.h"
#include "cp/interf/inc/interf_types.h"
+#include "cp/interf/inc/interf_private.h"
+#include "cp/interf/inc/interf_sar_layer.h"
#include "cp/msg/msg.h"
+#include "cp/station/station.h"
#include "cp/cp_types.h"
-
-
/**
* \brief Init and check the MME interface
* \param
* \return 0 or Error code if failure
*/
E_ErrCode
-interf_init(void);
+interf_init (void);
/**
* \brief receive new MME message
@@ -45,7 +43,7 @@ interf_init(void);
* \return
*/
void
-interf_receive(msg_mme_t *msg);
+interf_receive (msg_mme_t *msg);
/**
* \brief Receive new MME message
@@ -55,8 +53,7 @@ interf_receive(msg_mme_t *msg);
* \return
*/
void
-interf_received(void);
-
+interf_received (void);
/**
* \brief Send new MME message
@@ -66,8 +63,8 @@ interf_received(void);
* \param IntId : the interface where to send the message
* \return
*/
-void
-interf_send(msg_mme_t *msg, uint msg_size, interf_id_t interf_id);
+void
+interf_send (msg_mme_t *msg, uint msg_size, interf_id_t interf_id);
/**
* \brief Remove a message from fifo
@@ -77,7 +74,7 @@ interf_send(msg_mme_t *msg, uint msg_size, interf_id_t interf_id);
* \return true if success
*/
bool
-interf_msg_remove(msg_mme_dest_t dest, msg_mme_t *msg);
+interf_msg_remove (msg_mme_dest_t dest, msg_mme_t *msg);
/**
* \brief retreive the last message entered in the fifo
@@ -86,7 +83,7 @@ interf_msg_remove(msg_mme_dest_t dest, msg_mme_t *msg);
* \return pointer to the message or NULL
*/
msg_mme_t *
-interf_msg_get_last(msg_mme_dest_t dest);
+interf_msg_get_last (msg_mme_dest_t dest);
/**
* \brief retreive the last of a given type entered in the fifo
@@ -96,8 +93,7 @@ interf_msg_get_last(msg_mme_dest_t dest);
* \return pointer to the message or NULL
*/
msg_mme_t *
-interf_msg_get_last_of_type(msg_mme_dest_t dest, mm_type_t mm_type);
-
+interf_msg_get_last_of_type (msg_mme_dest_t dest, mm_type_t mm_type);
/**
* \brief retreive the previous message of the fifo
@@ -106,7 +102,7 @@ interf_msg_get_last_of_type(msg_mme_dest_t dest, mm_type_t mm_type);
* \return pointer to the message or NULL
*/
msg_mme_t *
-interf_msg_get_previous(msg_mme_dest_t dest);
+interf_msg_get_previous (msg_mme_dest_t dest);
/**
* \brief retreive the previous message of a given type
@@ -116,8 +112,7 @@ interf_msg_get_previous(msg_mme_dest_t dest);
* \return pointer to the message or NULL
*/
msg_mme_t *
-interf_msg_get_previous_of_type(msg_mme_dest_t dest, mm_type_t mm_type);
-
+interf_msg_get_previous_of_type (msg_mme_dest_t dest, mm_type_t mm_type);
/**
* \brief retreive the next part of a fragmented message
@@ -126,7 +121,7 @@ interf_msg_get_previous_of_type(msg_mme_dest_t dest, mm_type_t mm_type);
* \return pointer to the message or NULL
*/
msg_mme_t *
-interf_msg_get_next_part(msg_mme_t *msg);
+interf_msg_get_next_part (msg_mme_t *msg);
/**
* \brief release the buffer of the given message
@@ -134,8 +129,8 @@ interf_msg_get_next_part(msg_mme_t *msg);
* \param msg : the given message
* \return
*/
-void
-interf_release_buf(msg_mme_t *msg);
+void
+interf_release_buf (msg_mme_t *msg);
/**
* \brief release buffer for any interface
@@ -143,10 +138,8 @@ interf_release_buf(msg_mme_t *msg);
* \param
* \return
*/
-void
-interf_buf_to_release(void);
-
-
+void
+interf_buf_to_release (void);
/**
* \brief give a buffer to the STA or CCO process
@@ -155,16 +148,15 @@ interf_buf_to_release(void);
* \return the given buffer
*/
msg_mme_t *
-interf_give_buf(void);
+interf_give_buf (void);
/**
* \brief purge the expired fragment of messages
* \param
* \return
*/
-void
-interf_msg_purge(void);
-
+void
+interf_msg_purge (void);
/**
* \brief convert a time in ms to a number of system tick
@@ -172,9 +164,8 @@ interf_msg_purge(void);
* \param the value to convert
* \return the converted value
*/
-cyg_tick_count_t
-interf_ms_to_cyg_tick(uint ms);
-
+cyg_tick_count_t
+interf_ms_to_cyg_tick (uint ms);
#endif
diff --git a/cp/interf/src/interf.c b/cp/interf/src/interf.c
index 7519f0c48e..0cbdf42ba6 100644
--- a/cp/interf/src/interf.c
+++ b/cp/interf/src/interf.c
@@ -15,39 +15,34 @@
#include "cp/interf/interf.h"
#include "cp/interf/inc/interf_private.h"
-
/*
* locale Variables
*/
-
-static interf_buffer_t pool[INTERF_NB_BUFFER];
-static interf_frag_msg_t frag_msg[INTERF_MAX_FRAG_MSG_SIM];
-const interf_desc_t interf_desc[]=
- { // nb_buf, pf_add_buf, pf_send_buf, pf_rel_buf, pf_cb_rc
- { 8, interf_local_buf_release, interf_receive, NULL, NULL}, // CP
- {88, NULL, NULL, NULL, NULL}, // SAR
- { 2, NULL, NULL, NULL, NULL}, // CE
- { 3, NULL, NULL, NULL, NULL} // HLE
- };
+
+static interf_buffer_t pool[INTERF_NB_BUFFER];
+static interf_frag_msg_t frag_msg[INTERF_MAX_FRAG_MSG_SIM];
+const interf_desc_t interf_desc[]=
+ { // nb_buf, pf_add_buf, pf_send_buf, pf_rel_buf, pf_cb_rc
+ { 8, interf_local_buf_release, interf_receive, NULL, NULL }, // CP
+ { 88, NULL, NULL, NULL, NULL }, // SAR
+ { 2, NULL, NULL, NULL, NULL }, // CE
+ { 3, NULL, NULL, NULL, NULL } // HLE
+ };
// FIFOs (STA and CCO)
-static interf_msg_file_t fifo[2];
-static cyg_mutex_t cco_fifo_lock;
+static interf_msg_file_t fifo[2];
+static cyg_mutex_t cco_fifo_lock;
// local buf ressources (for STA and CCO)
-static uint nb_local_buf_available;
-static cyg_mutex_t local_ressource_lock;
-static cyg_cond_t local_ressource_wait;
+static uint nb_local_buf_available;
+static cyg_mutex_t local_ressource_lock;
+static cyg_cond_t local_ressource_wait;
// mbox for incomming msg
-static cyg_handle_t incoming_mbox_handle;
-static cyg_mbox incoming_mbox;
+static cyg_handle_t incoming_mbox_handle;
+static cyg_mbox incoming_mbox;
// mbox for buf to release
-static cyg_handle_t buf_rel_mbox_handle;
-static cyg_mbox buf_rel_mbox;
+static cyg_handle_t buf_rel_mbox_handle;
+static cyg_mbox buf_rel_mbox;
// delay in ticks for the frag MMI timeout
-static cyg_tick_count_t frag_MMI_time_out_delay;
-
-
-
-extern cyg_flag_t station_flag;
+static cyg_tick_count_t frag_MMI_time_out_delay;
/***************************************************************/
@@ -58,198 +53,202 @@ extern cyg_flag_t station_flag;
/***************************************************************/
/***************************************************************/
-msg_mme_t *
-interf_received_frag(msg_mme_t *msg)
+msg_mme_t *
+interf_received_frag (msg_mme_t *msg)
{
- int i, j, checksum;
- msg_mme_t *first_frag;
- interf_buffer_t *buffer = NULL;
-
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
-
- // check if some old messages must be removed
- // this can be done anywhere, but i think here is a good place.
- interf_msg_purge();
- // now, process the received fragment
- // check if previous fragment has been received
- for(i=0 ; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
- {
- if( (frag_msg[i].fmsn == msg->fmi.fmsn) && (memcmp(frag_msg[i].osa, msg->osa, sizeof(msg->osa))==0) )
- {
- // we find previous fragment, so stop searching
- break;
- }
- }
- if(i == INTERF_MAX_FRAG_MSG_SIM)
- {
- // we did not find previous fragment
- // so look for first empty slot
- for(i=0 ; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
- {
- if( ! frag_msg[i].frag_counter)
- {
- // we found an empty slot
- frag_msg[i].fmsn = msg->fmi.fmsn;
- memcpy(frag_msg[i].osa, msg->osa, sizeof(msg->osa));
- break;
- }
- }
- }
- if(i == INTERF_MAX_FRAG_MSG_SIM)
- {
- // obviously, there is no more space...
- dbg_assert_print(0, "interf.c : frag_msg array is full, loose fragment");
- // and so, we loose the message
- interf_release_buf(msg);
- return NULL;
- }
- frag_msg[i].date_cyg_tick = cyg_current_time();
- // message are ordered in our structure
- frag_msg[i].msg[msg->fmi.fn_mi] = msg;
- frag_msg[i].frag_counter ++;
- // check if message is complete and return
- if( frag_msg[i].frag_counter == (msg->fmi.nf_mi + 1) )
- {
- // check if all fragment are coherent
- checksum = 0;
- for(j=0 ; j < frag_msg[i].frag_counter ; j++) checksum += frag_msg[i].msg[j]->fmi.fn_mi;
- if(checksum != (frag_msg[i].frag_counter * msg->fmi.nf_mi / 2))
- {
- // the message fragment are not coherent (and they will be purged later)
- dbg_assert_print(0, "interf.c : MME fragments incoherents\n");
- return NULL;
- }
- // update the buffer structure
- first_frag = frag_msg[i].msg[0];
- for(j=0 ; j<frag_msg[i].frag_counter ; j++)
- {
- buffer = PARENT_OF(interf_buffer_t, msg, frag_msg[i].msg[j]);
- dbg_assert(buffer);
- buffer->next_msg = frag_msg[i].msg[j+1];
- }
- // the last fragment has no NextPart
- dbg_assert(buffer);
- buffer->next_msg = NULL;
- // reset the current slot
- bzero(&frag_msg[i], sizeof(interf_frag_msg_t));
- // and return ptr to first part of MME
- return first_frag;
- }
- return NULL;
+ int i, j, checksum;
+ msg_mme_t *first_frag;
+ interf_buffer_t *buffer = NULL;
+
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+
+ // check if some old messages must be removed
+ // this can be done anywhere, but i think here is a good place.
+ interf_msg_purge ();
+ // now, process the received fragment
+ // check if previous fragment has been received
+ for (i=0; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
+ {
+ if ( (frag_msg[i].fmsn == msg->fmi.fmsn)
+ && (memcmp (frag_msg[i].osa,msg->osa, sizeof(msg->osa))==0)
+ )
+ {
+ // we find previous fragment, so stop searching
+ break;
+ }
+ }
+ if(i == INTERF_MAX_FRAG_MSG_SIM)
+ {
+ // we did not find previous fragment
+ // so look for first empty slot
+ for(i=0 ; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
+ {
+ if( ! frag_msg[i].frag_counter)
+ {
+ // we found an empty slot
+ frag_msg[i].fmsn = msg->fmi.fmsn;
+ memcpy(frag_msg[i].osa, msg->osa, sizeof(msg->osa));
+ break;
+ }
+ }
+ }
+ if(i == INTERF_MAX_FRAG_MSG_SIM)
+ {
+ // obviously, there is no more space...
+ dbg_assert_print(0, "interf.c : frag_msg array is full, loose fragment");
+ // and so, we loose the message
+ interf_release_buf(msg);
+ return NULL;
+ }
+ frag_msg[i].date_cyg_tick = cyg_current_time();
+ // message are ordered in our structure
+ frag_msg[i].msg[msg->fmi.fn_mi] = msg;
+ frag_msg[i].frag_counter ++;
+ // check if message is complete and return
+ if( frag_msg[i].frag_counter == (msg->fmi.nf_mi + 1) )
+ {
+ // check if all fragment are coherent
+ checksum = 0;
+ for(j=0 ; j<frag_msg[i].frag_counter ; j++)
+ checksum += frag_msg[i].msg[j]->fmi.fn_mi;
+ if(checksum != (frag_msg[i].frag_counter * msg->fmi.nf_mi / 2))
+ {
+ // the message fragment are not coherent (and they will be purged later)
+ dbg_assert_print(0, "interf.c : MME fragments incoherents\n");
+ return NULL;
+ }
+ // update the buffer structure
+ first_frag = frag_msg[i].msg[0];
+ for(j=0; j<frag_msg[i].frag_counter; j++)
+ {
+ buffer = PARENT_OF(interf_buffer_t, msg, frag_msg[i].msg[j]);
+ dbg_assert(buffer);
+ buffer->next_msg = frag_msg[i].msg[j+1];
+ }
+ // the last fragment has no NextPart
+ dbg_assert(buffer);
+ buffer->next_msg = NULL;
+ // reset the current slot
+ bzero(&frag_msg[i], sizeof(interf_frag_msg_t));
+ // and return ptr to first part of MME
+ return first_frag;
+ }
+ return NULL;
}
void
-interf_msg_add(msg_mme_dest_t dest, msg_mme_t *msg)
+interf_msg_add (msg_mme_dest_t dest, msg_mme_t *msg)
{
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- dbg_assert(dest <= MSG_CCO);
-
- // if requested, take the CCO mutex
- if(dest == MSG_CCO) cyg_mutex_lock( & cco_fifo_lock);
-
- if(fifo[dest].start >= INTERF_NB_BUFFER)
- {
- // this should never occur, but who knowes...
- dbg_assert_print(0, "interf.c : fifo %i is full\n", MSG_CCO);
- // and we loose the message
- interf_release_buf(msg);
- }
- else
- {
- fifo[dest].msg[fifo[dest].start] = msg;
- fifo[dest].start ++;
- }
-
- // if necessary, release the CCO mutex
- if(dest == MSG_CCO) cyg_mutex_unlock( & cco_fifo_lock);
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ dbg_assert (dest <= MSG_CCO);
+
+ // if requested, take the CCO mutex
+ if (dest == MSG_CCO)
+cyg_mutex_lock ( &cco_fifo_lock);
+
+ if (fifo[dest].start >= INTERF_NB_BUFFER)
+ {
+ // this should never occur, but who knowes...
+ dbg_assert_print (0, "interf.c : fifo %i is full\n", MSG_CCO);
+ // and we loose the message
+ interf_release_buf (msg);
+ }
+ else
+ {
+ fifo[dest].msg[fifo[dest].start] = msg;
+ fifo[dest].start ++;
+ }
+
+ // if necessary, release the CCO mutex
+ if (dest == MSG_CCO)
+cyg_mutex_unlock ( &cco_fifo_lock);
+
}
bool
-interf_msg_remove(msg_mme_dest_t dest, msg_mme_t *msg)
+interf_msg_remove (msg_mme_dest_t dest, msg_mme_t *msg)
{
- uint i;
- bool return_value = false;
-
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- dbg_assert(dest <= MSG_CCO);
-
- // if requested, take the CCO mutex
- if(dest == MSG_CCO) cyg_mutex_lock( & cco_fifo_lock);
-
- // search the message index in the fifo
- for(i=fifo[dest].start ; i>0 ; i--) if(fifo[dest].msg[i-1] == msg) break;
- // if we found the message
- if(i)
- {
- // first we release the buffer(s) of the removed message
- interf_release_buf(msg);
- // then we remove the message from the fifo
- memcpy( & fifo[dest].msg[i-1], & fifo[dest].msg[i], sizeof(fifo[dest].msg[0]) * (fifo[dest].start - i) );
- fifo[dest].start --;
- dbg_assert(fifo[dest].start < INTERF_NB_BUFFER);
- if(fifo[dest].current >= i) fifo[dest].current --;
- return_value = true;
- }
-
- // if necessary, release the CCO mutex
- if(dest == MSG_CCO) cyg_mutex_unlock( & cco_fifo_lock);
-
- return return_value;
-}
+ uint i;
+ bool return_value = false;
+
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ dbg_assert (dest <= MSG_CCO);
+
+ // if requested, take the CCO mutex
+ if (dest == MSG_CCO)
+cyg_mutex_lock ( &cco_fifo_lock);
+
+ // search the message index in the fifo
+ for (i=fifo[dest].start; i>0; i--)
+ if (fifo[dest].msg[i-1] == msg)
+ break;
+ // if we found the message
+ if (i)
+ {
+ // first we release the buffer(s) of the removed message
+ interf_release_buf (msg);
+ // then we remove the message from the fifo
+ memcpy ( &fifo[dest].msg[i-1], &fifo[dest].msg[i], sizeof(fifo[dest].msg[0]) * (fifo[dest].start - i) );
+ fifo[dest].start --;
+ dbg_assert(fifo[dest].start < INTERF_NB_BUFFER);
+ if(fifo[dest].current >= i) fifo[dest].current --;
+ return_value = true;
+ }
+ // if necessary, release the CCO mutex
+ if(dest == MSG_CCO)
+cyg_mutex_unlock( & cco_fifo_lock);
+ return return_value;
+}
-void
-interf_local_buf_release(msg_mme_t *msg)
+void
+interf_local_buf_release (msg_mme_t *msg)
{
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
- // lock the mutex
- cyg_mutex_lock( & local_ressource_lock);
+cyg_mutex_lock ( &local_ressource_lock);
- nb_local_buf_available ++;
+ nb_local_buf_available ++;
+ // wake up any waiting allocators
+ cyg_cond_signal ( &local_ressource_wait);
+
+cyg_mutex_unlock ( &local_ressource_lock);
- // wake up any waiting allocators
- cyg_cond_signal( & local_ressource_wait);
- // unlock the mutex
- cyg_mutex_unlock( & local_ressource_lock);
}
-//void
-//interf_released_buf(void)
-void
-interf_buf_to_release(void)
+void
+interf_buf_to_release (void)
{
- interf_buffer_t *buf;
- msg_mme_t *msg, *next_msg;
-#if DEBUG
- int i;
-#endif
-
- // as we have buffer to release in the mailbox
- while( (msg = cyg_mbox_tryget(buf_rel_mbox_handle)) != NULL )
- {
-#if DEBUG
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- // check that the message to release is not the last part
- // of a fragmented message (which would cause a severe
- // memory leak)
- for(i=0 ; i<INTERF_NB_BUFFER ; i++)
- {
- dbg_assert(pool[i].next_msg != msg);
- }
-#endif
- do
- {
- buf = PARENT_OF(interf_buffer_t, msg, msg);
- buf->size = 0;
- next_msg = buf->next_msg;
- buf->next_msg = NULL;
- interf_desc[buf->id].pf_add_buf(msg);
- } while(next_msg);
- }
+ interf_buffer_t *buf;
+ msg_mme_t *msg, *next_msg;
+ #if DEBUG
+ int i;
+ #endif
+
+ // as we have buffer to release in the mailbox
+ while ( (msg = cyg_mbox_tryget (buf_rel_mbox_handle)) != NULL )
+ {
+ #if DEBUG
+ dbg_assert( ! msg_check_wrong_mme_const_values(msg));
+ // check that the message to release is not the last part
+ // of a fragmented message (which would cause a severe
+ // memory leak)
+ for(i=0; i<INTERF_NB_BUFFER; i++)
+ {
+ dbg_assert(pool[i].next_msg != msg);
+ }
+ #endif
+ do
+ {
+ buf = PARENT_OF (interf_buffer_t, msg, msg);
+ buf->size = 0;
+ next_msg = buf->next_msg;
+ buf->next_msg = NULL;
+ interf_desc[buf->id].pf_add_buf (msg);
+ } while (next_msg);
+ }
}
-
/***************************************************************/
/***************************************************************/
/***************************************************************/
@@ -258,48 +257,42 @@ interf_buf_to_release(void)
/***************************************************************/
/***************************************************************/
-
E_ErrCode
-interf_init(void)
+interf_init (void)
{
-// cyg_resolution_t resolution;
unsigned int i, j, k;
-#if DEBUG
+ #if DEBUG
unsigned int nb_buf=0;
// check parameters
- for(i=0 ; i<COUNT(interf_desc) ; i++) nb_buf += interf_desc[i].nb_buf;
+ for(i=0; i<COUNT(interf_desc); i++) nb_buf += interf_desc[i].nb_buf;
if(nb_buf != INTERF_NB_BUFFER) return NbBufIncoherent;
if(interf_desc[INTERF_SAR].nb_buf < (INTERF_MAX_FRAG_PER_MSG * INTERF_MAX_FRAG_MSG_SIM) ) return NbBufIncoherent;
if(interf_desc[INTERF_SAR].nb_buf < CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE)
{
- printf("interf.h : Warning : InterfDesc[SAR].NbBuf should be greater than CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE\n");
+ printf("interf.h : Warning : InterfDesc[SAR].NbBuf should be greater than CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE\n");
}
if (sizeof(pool[0].msg) != SAR_MSDU_PAYLOAD_MAX_SIZE )
{
- printf("wrong mmentry size : %lu octets instead of %i\n", sizeof(pool[0].msg), SAR_MSDU_PAYLOAD_MAX_SIZE);
- printf(" osa : %lu\n", sizeof(pool[0].msg.osa));
- printf(" oda : %lu\n", sizeof(pool[0].msg.oda));
- printf(" v_lan_tag : %lu\n", sizeof(pool[0].msg.v_lan_tag));
- printf(" m_type : %lu\n", sizeof(pool[0].msg.m_type));
- printf(" mmv; : %lu\n", sizeof(pool[0].msg.mmv));
- printf(" mm_type; : %lu\n", sizeof(pool[0].msg.mm_type));
- printf(" fmi; : %lu\n", sizeof(pool[0].msg.fmi));
- printf(" mm_entry : %lu\n", sizeof(pool[0].msg.mm_entry));
+ printf("wrong mmentry size : %lu octets instead of %i\n", sizeof(pool[0].msg), SAR_MSDU_PAYLOAD_MAX_SIZE);
+ printf(" osa : %lu\n", sizeof(pool[0].msg.osa));
+ printf(" oda : %lu\n", sizeof(pool[0].msg.oda));
+ printf(" v_lan_tag : %lu\n", sizeof(pool[0].msg.v_lan_tag));
+ printf(" m_type : %lu\n", sizeof(pool[0].msg.m_type));
+ printf(" mmv; : %lu\n", sizeof(pool[0].msg.mmv));
+ printf(" mm_type; : %lu\n", sizeof(pool[0].msg.mm_type));
+ printf(" fmi; : %lu\n", sizeof(pool[0].msg.fmi));
+ printf(" mm_entry : %lu\n", sizeof(pool[0].msg.mm_entry));
}
-#endif
+ #endif
// calculate the frag MMI timeout delay
frag_MMI_time_out_delay = FragMMI_ReassemblyTimeOut_sec;
// convert it from s to ms
frag_MMI_time_out_delay *= 1000;
// and then convert it to system ticks
- frag_MMI_time_out_delay = interf_ms_to_cyg_tick(frag_MMI_time_out_delay);
-/* resolution = cyg_clock_get_resolution(cyg_real_time_clock());
- frag_MMI_time_out_delay *= resolution.divisor;
- frag_MMI_time_out_delay /= resolution.dividend;
-*/
+ frag_MMI_time_out_delay = interf_ms_to_cyg_tick (frag_MMI_time_out_delay);
// attribute buffer to their owner and use the loop to init msg const values
- bzero(pool, sizeof(pool));
+ bzero (pool, sizeof(pool));
for(i=0, j=0, k=0 ; i<COUNT(interf_desc) ; i++)
{
j += interf_desc[i].nb_buf;
@@ -318,17 +311,17 @@ interf_init(void)
// init of local ressources
nb_local_buf_available = 0;
cyg_mutex_init( & local_ressource_lock);
- cyg_cond_init( & local_ressource_wait, & local_ressource_lock);
+ cyg_cond_init( & local_ressource_wait, & local_ressource_lock);
// Init callback and transmit buffer's pool
for(i=0, j=0 , k=0 ; i<COUNT(interf_desc) ; i++)
{
if(interf_desc[i].pf_rel_buf != NULL) interf_desc[i].pf_rel_buf();
- if(interf_desc[i].pf_cb_rc != NULL) interf_desc[i].pf_cb_rc();
- k = j;
- j += interf_desc[i].nb_buf;
+ if(interf_desc[i].pf_cb_rc != NULL) interf_desc[i].pf_cb_rc();
+ k = j;
+ j += interf_desc[i].nb_buf;
if(interf_desc[i].pf_add_buf != NULL)
{
- for( ; k<j ; k++)
+ for(; k<j; k++)
{
interf_desc[i].pf_add_buf( & pool[k].msg);
}
@@ -342,222 +335,228 @@ interf_init(void)
return Success;
}
-void interf_receive(msg_mme_t *msg)
+void
+interf_receive (msg_mme_t *msg)
{
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
-
-#if DEBUG
- dbg_assert(cyg_mbox_tryput(incoming_mbox_handle, msg));
-#else
- cyg_mbox_put(incoming_mbox_handle, msg);
-#endif
- // set the flag for the station
- cyg_flag_setbits(&station_flag, STATION_FLAG_MSG_RCV);
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+
+ #if DEBUG
+ dbg_assert(cyg_mbox_tryput(incoming_mbox_handle, msg));
+ #else
+ cyg_mbox_put (incoming_mbox_handle, msg);
+ #endif
+ // set the flag for the station
+ cyg_flag_setbits (&station_flag, STATION_FLAG_MSG_RCV);
}
void
-interf_received(void)
+interf_received (void)
{
- msg_mme_t * msg;
- bool message_complete, msg_RSP_or_CNF;
- int msg_nb;
-
- // as we have msg in the mailbox
- while( (msg = cyg_mbox_tryget(incoming_mbox_handle)) != NULL )
- {
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- // TODO : vérifier que l'ODA est bien celle de la station
- // check if message is complete
- if(msg->fmi.nf_mi == 0) message_complete = true;
- else
- {
- msg = interf_received_frag(msg);
- if(msg != NULL) message_complete = true;
- else message_complete = false;
- }
- // if MME is not complete, then look for next message
- if( ! message_complete) continue;
- // check if it is a .CNF or .RSP type message
- msg_RSP_or_CNF = msg->mm_type & 0x1;
- // check if message is for CCO or STA and add it in corresponding fifo
- msg_nb = msg_get_number(msg);
- interf_msg_add(msg_list[msg_nb].msg_dest, msg);
- // TODO : set corresponding flags
- }
+ msg_mme_t * msg;
+ bool message_complete, msg_RSP_or_CNF;
+ int msg_nb;
+
+ // as we have msg in the mailbox
+ while ( (msg = cyg_mbox_tryget (incoming_mbox_handle)) != NULL )
+ {
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ // TODO : vérifier que l'ODA est bien celle de la station
+ // check if message is complete
+ if (msg->fmi.nf_mi == 0)
+ message_complete = true;
+ else
+ {
+ msg = interf_received_frag (msg);
+ if (msg != NULL)
+ message_complete = true;
+ else
+ message_complete = false;
+ }
+ // if MME is not complete, then look for next message
+ if ( !message_complete)
+ continue;
+ // check if it is a .CNF or .RSP type message
+ msg_RSP_or_CNF = msg->mm_type & 0x1;
+ // check if message is for CCO or STA and add it in corresponding fifo
+ msg_nb = msg_get_number (msg);
+ interf_msg_add (msg_list[msg_nb].msg_dest, msg);
+ // TODO : set corresponding flags
+ }
}
void
-interf_send(msg_mme_t *msg, uint msg_size, interf_id_t interf_id)
+interf_send (msg_mme_t *msg, uint msg_size, interf_id_t interf_id)
{
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- dbg_assert(msg_size <= SAR_MSDU_PAYLOAD_MAX_SIZE);
- dbg_assert(interf_id < COUNT(interf_desc));
-
- // check if padding is requested (and if yes, do so)
- if(msg_size < SAR_MSDU_PAYLOAD_MIN_SIZE) msg_size = SAR_MSDU_PAYLOAD_MIN_SIZE;
- // and then, send the message
- dbg_assert_print(interf_desc[interf_id].pf_send_buf, "interface non imlémentée\n");
- interf_desc[interf_id].pf_send_buf(msg);
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ dbg_assert (msg_size <= SAR_MSDU_PAYLOAD_MAX_SIZE);
+ dbg_assert (interf_id < COUNT (interf_desc));
+
+ // check if padding is requested (and if yes, do so)
+ if (msg_size < SAR_MSDU_PAYLOAD_MIN_SIZE)
+ msg_size = SAR_MSDU_PAYLOAD_MIN_SIZE;
+ // and then, send the message
+ dbg_assert_print (interf_desc[interf_id].pf_send_buf, "interface not implemented\n");
+ interf_desc[interf_id].pf_send_buf (msg);
}
msg_mme_t *
-interf_msg_get_last(msg_mme_dest_t dest)
+interf_msg_get_last (msg_mme_dest_t dest)
{
- msg_mme_t *return_value = NULL;
+ msg_mme_t *return_value = NULL;
- dbg_assert(dest < COUNT(fifo));
+ dbg_assert (dest < COUNT (fifo));
- fifo[dest].current = fifo[dest].start;
- if(fifo[dest].current != 0) return_value = fifo[dest].msg[fifo[dest].current - 1];
- return return_value;
+ fifo[dest].current = fifo[dest].start;
+ if (fifo[dest].current != 0)
+ return_value = fifo[dest].msg[fifo[dest].current - 1];
+ return return_value;
}
msg_mme_t *
-interf_msg_get_last_of_type(msg_mme_dest_t dest, mm_type_t mm_type)
+interf_msg_get_last_of_type (msg_mme_dest_t dest, mm_type_t mm_type)
{
- msg_mme_t *return_value = NULL;
-
- dbg_assert(dest < COUNT(fifo));
-
- fifo[dest].current = fifo[dest].start;
- while(fifo[dest].current != 0)
- {
- if(fifo[dest].msg[fifo[dest].current - 1]->mm_type == mm_type)
- {
- return_value = fifo[dest].msg[fifo[dest].current - 1];
- break;
- }
- fifo[dest].current --;
- }
- return return_value;
+ msg_mme_t *return_value = NULL;
+
+ dbg_assert (dest < COUNT (fifo));
+
+ fifo[dest].current = fifo[dest].start;
+ while (fifo[dest].current != 0)
+ {
+ if (fifo[dest].msg[fifo[dest].current - 1]->mm_type == mm_type)
+ {
+ return_value = fifo[dest].msg[fifo[dest].current - 1];
+ break;
+ }
+ fifo[dest].current --;
+ }
+ return return_value;
}
msg_mme_t *
-interf_msg_get_previous(msg_mme_dest_t dest)
+interf_msg_get_previous (msg_mme_dest_t dest)
{
- msg_mme_t *return_value = NULL;
-
- dbg_assert(dest < COUNT(fifo));
-
- if(fifo[dest].current > 1)
- {
- fifo[dest].current --;
- return_value = fifo[dest].msg[fifo[dest].current - 1];
- }
- return return_value;
+ msg_mme_t *return_value = NULL;
+
+ dbg_assert (dest < COUNT (fifo));
+
+ if (fifo[dest].current > 1)
+ {
+ fifo[dest].current --;
+ return_value = fifo[dest].msg[fifo[dest].current - 1];
+ }
+ return return_value;
}
msg_mme_t *
-interf_msg_get_previous_of_type(msg_mme_dest_t dest, mm_type_t mm_type)
+interf_msg_get_previous_of_type (msg_mme_dest_t dest, mm_type_t mm_type)
{
- msg_mme_t *return_value = NULL;
-
- dbg_assert(dest < COUNT(fifo));
-
- while(fifo[dest].current > 1)
- {
- fifo[dest].current --;
- if(fifo[dest].msg[fifo[dest].current - 1]->mm_type == mm_type)
- {
- return_value = fifo[dest].msg[fifo[dest].current - 1];
- break;
- }
- }
- return return_value;
-}
+ msg_mme_t *return_value = NULL;
+ dbg_assert (dest < COUNT (fifo));
+
+ while (fifo[dest].current > 1)
+ {
+ fifo[dest].current --;
+ if (fifo[dest].msg[fifo[dest].current - 1]->mm_type == mm_type)
+ {
+ return_value = fifo[dest].msg[fifo[dest].current - 1];
+ break;
+ }
+ }
+ return return_value;
+}
msg_mme_t *
-interf_msg_get_next_part(msg_mme_t *msg)
+interf_msg_get_next_part (msg_mme_t *msg)
{
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
-
- return PARENT_OF(interf_buffer_t, msg, msg)->next_msg;
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+
+ return PARENT_OF(interf_buffer_t, msg, msg)->next_msg;
}
-void
-interf_release_buf(msg_mme_t *msg)
+void
+interf_release_buf (msg_mme_t *msg)
{
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
-
-#if DEBUG
- dbg_assert(cyg_mbox_tryput(buf_rel_mbox_handle, msg));
-#else
- cyg_mbox_put(buf_rel_mbox_handle, msg);
-#endif
- // set the flag
- cyg_flag_setbits(&station_flag, STATION_FLAG_BUF_REL);
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+
+ #if DEBUG
+ dbg_assert(cyg_mbox_tryput(buf_rel_mbox_handle, msg));
+ #else
+ cyg_mbox_put (buf_rel_mbox_handle, msg);
+ #endif
+ // set the flag
+ cyg_flag_setbits (&station_flag, STATION_FLAG_BUF_REL);
}
-
msg_mme_t *
-interf_give_buf(void)
+interf_give_buf (void)
{
- msg_mme_t *msg;
- int i;
-
- // lock the mutex
- cyg_mutex_lock( & local_ressource_lock);
- // if there is no buffer available, wait for one
- while( nb_local_buf_available == 0 )
- cyg_cond_wait( & local_ressource_wait);
- // search for an available buffer
- dbg_assert(INTERF_CP == 0);
- for(i=0 ; i<interf_desc[INTERF_CP].nb_buf ; i++)
- {
- if(pool[i].size == 0) break;
- }
- dbg_assert(i != interf_desc[INTERF_CP].nb_buf);
- // lock the availble buffer and return it
- pool[i].size = 1;
- msg = & pool[i].msg;
- nb_local_buf_available --;
- // unlock the mutex
- cyg_mutex_unlock( & local_ressource_lock);
- // and return the buffer
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- return msg;
+ msg_mme_t *msg;
+ int i;
+
+cyg_mutex_lock ( &local_ressource_lock);
+ // if there is no buffer available, wait for one
+ while (nb_local_buf_available == 0)
+ cyg_cond_wait ( &local_ressource_wait);
+ // search for an available buffer
+ dbg_assert (INTERF_CP == 0);
+ for (i=0; i<interf_desc[INTERF_CP].nb_buf; i++)
+ {
+ if (pool[i].size == 0)
+ break;
+ }
+ dbg_assert (i != interf_desc[INTERF_CP].nb_buf);
+ // lock the availble buffer and return it
+ pool[i].size = 1;
+ msg = &pool[i].msg;
+ nb_local_buf_available --;
+cyg_mutex_unlock ( &local_ressource_lock);
+ // and return the buffer
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ return msg;
}
-void
-interf_msg_purge(void)
+void
+interf_msg_purge (void)
{
- int i, j;
- cyg_tick_count_t time_out_date;
- dbg_assert(frag_MMI_time_out_delay >= 1);
- // calculate the date before which messages has expired
- time_out_date = cyg_current_time();
- time_out_date -= frag_MMI_time_out_delay;
- // check if some messages has expired
- for(i=0 ; i<INTERF_MAX_FRAG_MSG_SIM ; i++)
- {
- if( (frag_msg[i].date_cyg_tick != 0)
- && (frag_msg[i].date_cyg_tick < time_out_date) )
- {
- // the message has expired, so remove it parts
- for(j=0 ; j<INTERF_MAX_FRAG_PER_MSG ; j++)
- {
- if(frag_msg[i].msg[j]) interf_release_buf(frag_msg[i].msg[j]);
- }
- // and reset it slot in the waiting file
- bzero( & frag_msg[i], sizeof(frag_msg[i]));
- }
- }
+ int i, j;
+ cyg_tick_count_t time_out_date;
+ dbg_assert (frag_MMI_time_out_delay >= 1);
+ // calculate the date before which messages has expired
+ time_out_date = cyg_current_time ();
+ if (time_out_date < frag_MMI_time_out_delay)
+ return;
+ time_out_date -= frag_MMI_time_out_delay;
+ // check if some messages has expired
+ for (i=0; i<INTERF_MAX_FRAG_MSG_SIM ; i++)
+ {
+ if ( (frag_msg[i].date_cyg_tick != 0)&& (frag_msg[i].date_cyg_tick
+ < time_out_date))
+ {
+ // the message has expired, so remove it parts
+ for (j=0; j<INTERF_MAX_FRAG_PER_MSG ; j++)
+ {
+ if (frag_msg[i].msg[j])
+ interf_release_buf (frag_msg[i].msg[j]);
+ }
+ // and reset it slot in the waiting file
+ bzero ( &frag_msg[i], sizeof(frag_msg[i]));
+ }
+ }
}
-
-cyg_tick_count_t
-interf_ms_to_cyg_tick(uint ms)
+cyg_tick_count_t
+interf_ms_to_cyg_tick (uint ms)
{
- cyg_resolution_t resolution;
- cyg_tick_count_t return_value;
-
- return_value = ms;
- // convert it from ms to ns
- return_value *= 1000000;
+ cyg_resolution_t resolution;
+ cyg_tick_count_t return_value;
+
+ return_value = ms;
+ // convert it from ms to ns
+ return_value *= 1000000;
// and then convert it to system ticks
- resolution = cyg_clock_get_resolution(cyg_real_time_clock());
- return_value *= resolution.divisor;
- return_value /= resolution.dividend;
- return return_value;
+ resolution = cyg_clock_get_resolution (cyg_real_time_clock ());
+ return_value *= resolution.divisor;
+ return_value /= resolution.dividend;
+ return return_value;
}
diff --git a/cp/interf/src/interf_sar_layer.c b/cp/interf/src/interf_sar_layer.c
index 8b40ea6cf7..ac4cb6d6b5 100644
--- a/cp/interf/src/interf_sar_layer.c
+++ b/cp/interf/src/interf_sar_layer.c
@@ -9,43 +9,34 @@
#include "common/std.h"
#include "cp/interf/inc/interf_sar_layer.h"
-
sar_context_t *interf_sar_context = NULL;
-
-void
-interf_sar_layer_init(void)
+void interf_sar_layer_init (void)
{
-// interf_sar_context = sar_initialize();
+ // interf_sar_context = sar_initialize();
}
-
-void
-interf_sar_layer_add_buf(msg_mme_t *msg)
+void interf_sar_layer_add_buf (msg_mme_t *msg)
{
- dbg_assert(interf_sar_context);
- dbg_assert(msg);
+ dbg_assert (interf_sar_context);
+ dbg_assert (msg);
}
-
-void
-interf_sar_layer_send_buf(msg_mme_t *msg)
+void interf_sar_layer_send_buf (msg_mme_t *msg)
{
- dbg_assert(interf_sar_context);
- dbg_assert(msg);
+ dbg_assert (interf_sar_context);
+ dbg_assert (msg);
}
-int
-interf_sar_layer_rel_buf(void)
+int interf_sar_layer_rel_buf (void)
{
- dbg_assert(interf_sar_context);
-
- return 0;
+ dbg_assert (interf_sar_context);
+
+ return 0;
}
-int
-interf_sar_layer_cb_rc(void)
+int interf_sar_layer_cb_rc (void)
{
- dbg_assert(interf_sar_context);
- return 0;
+ dbg_assert (interf_sar_context);
+ return 0;
}
diff --git a/cp/msg/Module b/cp/msg/Module
index 418e4f001a..3deceab545 100644
--- a/cp/msg/Module
+++ b/cp/msg/Module
@@ -1,2 +1,2 @@
-SOURCES := msg.c
+SOURCES := msg.c msg_cm.c msg_cc.c
diff --git a/cp/msg/inc/msg_cc.h b/cp/msg/inc/msg_cc.h
new file mode 100644
index 0000000000..d252d48a76
--- /dev/null
+++ b/cp/msg/inc/msg_cc.h
@@ -0,0 +1,20 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/msg/inc/msg_cc.h
+ * \brief MME messages of CC type
+ * \ingroup cp_msg
+ */
+
+#ifndef msg_cc__h__
+#define msg_cc__h__
+
+//#include "cp/msg/msg.h"
+
+
+#endif
diff --git a/cp/msg/inc/msg_cm.h b/cp/msg/inc/msg_cm.h
new file mode 100644
index 0000000000..5f25425693
--- /dev/null
+++ b/cp/msg/inc/msg_cm.h
@@ -0,0 +1,34 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/msg/inc/msg_cm.h
+ * \brief MME messages of CM type
+ * \ingroup cp_msg
+ */
+#ifndef MSG_CM_H_
+#define MSG_CM_H_
+
+#include "cp/cp_types.h"
+#include "cp/interf/inc/interf_types.h"
+#include "cp/msg/msg.h"
+
+
+typedef struct unassociated_sta_t // 11.5.1
+{
+ // TODO : set the real types
+ u8 nid[7];
+ u8 cco_capability;
+} __attribute__ ((packed)) unassociated_sta_t;
+
+
+void
+msg_cm_unassociated_sta_ind_send(interf_id_t interf_id, mac_adresse_t oda);
+
+
+
+#endif /*MSG_CM_H_*/
diff --git a/cp/msg/inc/msg_const.h b/cp/msg/inc/msg_const.h
new file mode 100644
index 0000000000..5cfb180946
--- /dev/null
+++ b/cp/msg/inc/msg_const.h
@@ -0,0 +1,200 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/msg/inc/msg_const.h
+ * \brief constants of msg module
+ * \ingroup cp_msg
+ */
+#ifndef MSG_CONST_H_
+#define MSG_CONST_H_
+
+#include "mac/sar/inc/sar_mf.h"
+#include "cp/cp_types.h"
+
+
+/*
+ * Homeplug AV constantes
+ */
+#define MSG_VLAN_TAG 0 // TBD
+#define MSG_MTYPE 0xE188 // 11.1
+#define MSG_MME_HEADER_SIZE 23
+/*
+ * Familles et numéros de message
+ */
+#define MSG_CC_START 0x0000
+#define MSG_CC_STOP 0x005B
+
+#define MSG_CP_START 0x2000
+#define MSG_CP_STOP 0x200B
+
+#define MSG_NN_START 0x4000
+#define MSG_NN_STOP 0x4013
+
+#define MSG_CM_START 0x6000
+#define MSG_CM_STOP 0x604F
+
+#define MSG_UNKNOW 0xFFFF
+
+typedef enum msg_mme_dest_t { MSG_STA, MSG_CCO } msg_mme_dest_t;
+
+/*
+ * mm type constants
+ * take care of the following :
+ * according to Intellon technical reference manual of Homeplug AV firmware p9,
+ * the two LSB value of messages should be :
+ * 0b00 for REQ
+ * 0b01 for CNF
+ * 0b10 for IND
+ * 0b11 for RSP
+ * this is very unclear in the Homeplug AV specification v1.0.10
+ */
+typedef enum mm_type_t
+{
+ CC_CCO_APPOINT_REQ = 0x0000,
+ CC_CCO_APPOINT_CNF = 0x0001,
+ CC_BACKUP_APPOINT_REQ = 0x0004,
+ CC_BACKUP_APPOINT_CNF = 0x0005,
+ CC_LINK_INFO_REQ = 0x0008,
+ CC_LINK_INFO_CNF = 0x0009,
+ CC_LINK_INFO_IND = 0x000A,
+ CC_LINK_INFO_RSP = 0x000B,
+ CC_HANDOVER_REQ = 0x000C,
+ CC_HANDOVER_CNF = 0x000D,
+ CC_HANDOVER_INFO_IND = 0x0010,
+ CC_HANDOVER_INFO_RSP = 0x0011,
+ CC_DISCOVER_LIST_REQ = 0x0014,
+ CC_DISCOVER_LIST_CNF = 0x0015,
+ CC_DISCOVER_LIST_IND = 0x0016,
+ CC_LINK_NEW_REQ = 0x0018,
+ CC_LINK_NEW_CNF = 0x0019,
+ CC_LINK_MOD_REQ = 0x001C,
+ CC_LINK_MOD_CNF = 0x001D,
+ CC_LINK_SQZ_REQ = 0x0020,
+ CC_LINK_SQZ_CNF = 0x0021,
+ CC_LINK_REL_REQ = 0x0024,
+ CC_LINK_REL_IND = 0x0025,
+ CC_DETECT_REPORT_REQ = 0x0028,
+ CC_DETECT_REPORT_CNF = 0x0029,
+ CC_WHO_RU_REQ = 0x002C,
+ CC_WHO_RU_CNF = 0x002D,
+ CC_ASSOC_REQ = 0x0030,
+ CC_ASSOC_CNF = 0x0031,
+ CC_LEAVE_REQ = 0x0034,
+ CC_LEAVE_CNF = 0x0035,
+ CC_LEAVE_IND = 0x0036,
+ CC_LEAVE_RSP = 0x0037,
+ CC_SET_TEI_MAP_REQ = 0x0038,
+ CC_SET_TEI_MAP_IND = 0x0039,
+ CC_RELAY_REQ = 0x003C,
+ CC_RELAY_IND = 0x003D,
+ CC_BEACON_RELIABILITY_REQ = 0x0040,
+ CC_BEACON_RELIABILITY_CNF = 0x0041,
+ CC_ALLOC_MOVE_REQ = 0x0044,
+ CC_ALLOC_MOVE_CNF = 0x0045,
+ CC_ACCESS_NEW_REQ = 0x0048,
+ CC_ACCESS_NEW_CNF = 0x0049,
+ CC_ACCESS_NEW_IND = 0x004A,
+ CC_ACCESS_NEW_RSP = 0x004B,
+ CC_ACCESS_REL_REQ = 0x004C,
+ CC_ACCESS_REL_CNF = 0x004D,
+ CC_ACCESS_REL_IND = 0x004E,
+ CC_ACCESS_REL_RSP = 0x004F,
+ CC_DCPPC_IND = 0x0052,
+ CC_DCPPC_RSP = 0x0053,
+ CC_HP1_DET_REQ = 0x0054,
+ CC_HP1_DET_CNF = 0x0055,
+ CC_BLE_UPDATE_IND = 0x0058,
+
+ CP_PROXY_APPOINT_REQ = 0x2000,
+ CP_PROXY_APPOINT_CNF = 0x2001,
+ PH_PROXY_APPOINT_IND = 0x2006,
+ CP_PROXY_WAKE_REQ = 0x2008,
+
+ NN_INL_REQ = 0x4000,
+ NN_INL_CNF = 0x4001,
+ NN_NEW_REQ = 0x4004,
+ NN_NEW_CNF = 0x4005,
+ NN_NEW_IND = 0x4006,
+ NN_ADD_ALLOC_REQ = 0x4008,
+ NN_ADD_ALLOC_CNF = 0x4009,
+ NN_ADD_ALLOC_IND = 0x400A,
+ NN_REL_ALLOC_REQ = 0x400C,
+ NN_REL_ALLOC_CNF = 0x400D,
+ NN_REL_NET_IND = 0x4013,
+
+ CM_UNASSOCIATED_STA_IND = 0x6003,
+ CM_ENCRYPTED_PAYLOAD_IND = 0x6006,
+ CM_ENCRYPTED_PAYLOAD_RSP = 0x6007,
+ CM_SET_KEY_REQ = 0x6008,
+ CM_SET_KEY_CNF = 0x6009,
+ CM_GET_KEY_REQ = 0x600C,
+ CM_GET_KEY_CNF = 0x600D,
+ CM_SC_JOIN_REQ = 0x6010,
+ CM_SC_JOIN_CNF = 0x6011,
+ CM_CHAN_EST_IND = 0x6016,
+ CM_TM_UPDATE_IND = 0x6020,
+ CM_AMP_MAP_REQ = 0x601C,
+ CM_AMP_MAP_CNF = 0x601D,
+ CM_BRG_INFO_REQ = 0x6020,
+ CM_BRG_INFO_CNF = 0x6021,
+ CM_CONN_NEW_REQ = 0x6024,
+ CM_CONN_NEW_CNF = 0x6025,
+ CM_CONN_REL_IND = 0x602A,
+ CM_CONN_REL_RSP = 0x602B,
+ CM_CONN_MOD_REQ = 0x602C,
+ CM_CONN_MOD_CNF = 0x602D,
+ CM_CONN_INFO_REQ = 0x6030,
+ CM_CONN_INFO_CNF = 0x6031,
+ CM_STA_CAP_REQ = 0x6034,
+ CM_STA_CAP_CNF = 0x6035,
+ CM_NW_INFO_REQ = 0x6038,
+ CM_NW_INFO_CNF = 0x6039,
+ CM_GET_BEACON_REQ = 0x603C,
+ CM_GET_BEACON_CNF = 0x603D,
+ CM_HFID_REQ = 0x6040,
+ CM_HFID_CNF = 0x6041,
+ CM_MME_ERROR_IND = 0x6046,
+ CM_NW_STATS_REQ = 0x6048,
+ CM_NW_STATS_CNF = 0x6049,
+ CM_LINK_STATS_REQ = 0x604C,
+ CM_LINK_STATS_CNF = 0x604D
+} __attribute__ ((packed)) mm_type_t;
+
+/*
+ * types of messages
+ */
+typedef struct msg_fmi_t // Table 11-178
+{
+ u8 nf_mi :4; // Number of fragments for message
+ u8 fn_mi :4; // fragment number
+ u8 fmsn; // fragmentation message sequence number
+} msg_fmi_t;
+
+typedef struct msg_mme_t // Table 11-178
+{
+ mac_adresse_t oda; // original destination adress
+ mac_adresse_t osa; // original source adress
+ u32 v_lan_tag; // ieee 802.1 tag (optional)
+ u16 m_type; // const = 0x88E1
+ u8 mmv; // management message version
+ mm_type_t mm_type; // management message type
+ msg_fmi_t fmi;
+ u8 mm_entry[SAR_MSDU_PAYLOAD_MAX_SIZE - MSG_MME_HEADER_SIZE];
+} __attribute__ ((packed)) msg_mme_t;
+
+typedef struct msg_list_mme_t
+{
+ u8 msg_mame[30]; // Message Name
+ msg_mme_dest_t msg_dest; // prefered destination (default if STA)
+ int (*msg_func) (msg_mme_t msg[]); // Function processing the message
+} msg_list_mme_t;
+
+
+
+
+#endif /*MSG_CONST_H_*/
diff --git a/cp/msg/msg.h b/cp/msg/msg.h
index 47c271adcd..f2ed56eb1e 100644
--- a/cp/msg/msg.h
+++ b/cp/msg/msg.h
@@ -14,105 +14,60 @@
#ifndef msg__h__
#define msg__h__
-
+#include "cp/interf/inc/interf_types.h"
+#include "cp/msg/inc/msg_const.h"
+#include "cp/msg/inc/msg_cc.h"
+#include "cp/msg/inc/msg_cm.h"
#include "cp/cp_types.h"
-#include "mac/sar/inc/sar_mf.h"
-/*
- * Homeplug AV constantes
- */
-#define MSG_VLAN_TAG 0 // TBD
-#define MSG_MTYPE 0xe188 // 11.1
-
-/*
- * Familles et numéros de message
- */
-#define MSG_CC_START 0x0000
-#define MSG_CC_STOP 0x005B
-
-#define MSG_CP_START 0x2000
-#define MSG_CP_STOP 0x200B
-
-#define MSG_NN_START 0x4000
-#define MSG_NN_STOP 0x4013
-
-#define MSG_CM_START 0x6000
-#define MSG_CM_STOP 0x604F
-
-#define MSG_UNKNOW 0xFFFF
-
-typedef enum msg_mme_dest_t {MSG_STA, MSG_CCO} msg_mme_dest_t;
-
-
-/*
- * types of messages
- */
-
-typedef struct msg_fmi_t // Table 11-178
-{
- u8 nf_mi:4; // Number of fragments for message
- u8 fn_mi:4; // fragment number
- u8 fmsn; // fragmentation message sequence number
-} msg_fmi_t;
-
-typedef struct msg_mme_t // Table 11-178
-{
- mac_adresse_t oda;
- mac_adresse_t osa;
- u32 v_lan_tag;
- u16 m_type;
- u8 mmv;
- mm_type_t mm_type;
- msg_fmi_t fmi;
- u8 mm_entry[SAR_MSDU_PAYLOAD_MAX_SIZE - 23]; // 23 = header size
-} __attribute__ ((packed)) msg_mme_t;
-
-typedef struct msg_list_mme_t
-{
- u8 msg_mame[30]; // Message Name
- msg_mme_dest_t msg_dest; // prefered destination (default if STA)
- int (*msg_func)(msg_mme_t msg[]); // Function processing the message
-} msg_list_mme_t;
-
+#include "cp/interf/interf.h"
/*
* Global variables
*/
extern msg_list_mme_t msg_list[];
-
/**
* \brief Give the message number in our local reference.
* \param Msg : pointer to the message
* \return the message number or UNKNOW_MSG
*/
u16
-msg_get_number(msg_mme_t *msg);
+msg_get_number (msg_mme_t *msg);
/**
* \brief
* \param Msg : pointer to the message
* \return NULL or ptr to the function
*/
-void *
-msg_dispatch(msg_mme_t *msg);
-
+void *
+msg_dispatch (msg_mme_t *msg);
/**
* \brief set the const values of mme (ie mtype)
* \param Msg : pointer to the message
* \return
*/
-void
-msg_set_mme_const_values(msg_mme_t *msg);
+void
+msg_set_mme_const_values (msg_mme_t *msg);
/**
* \brief check the const values of mme (ie mtype)
* \param Msg : pointer to the message
* \return true if ok
*/
-bool
-msg_check_wrong_mme_const_values(msg_mme_t *msg);
+bool
+msg_check_wrong_mme_const_values (msg_mme_t *msg);
+
+/**
+ * \brief add field common to all mme messages (OSA)
+ * and send it through the interface
+ * \param msg : pointer to the message
+ * \param msg_size : size of the message (including header)
+ * \return
+ */
+void
+msg_send(msg_mme_t *msg, uint msg_size, interf_id_t interf_id);
#endif
diff --git a/cp/msg/src/msg.c b/cp/msg/src/msg.c
index d706a36ed7..75f5c63924 100644
--- a/cp/msg/src/msg.c
+++ b/cp/msg/src/msg.c
@@ -14,89 +14,99 @@
#include "common/std.h"
#include "cp/msg/msg.h"
+msg_list_mme_t msg_list[] =
+ {
+ { "CC_CCO_APPOINT.REQ", MSG_STA, NULL },
+ { "CC_CCO_APPOINT.CNF", MSG_STA, NULL },
+ { "CC_CCO_APPOINT.", MSG_STA, NULL },
+ { "CC_CCO_APPOINT.", MSG_STA, NULL },
-msg_list_mme_t msg_list[] =
-{
- {"CC_CCO_APPOINT.REQ" , MSG_STA, NULL},
- {"CC_CCO_APPOINT.CNF" , MSG_STA, NULL},
- {"CC_CCO_APPOINT." , MSG_STA, NULL},
- {"CC_CCO_APPOINT." , MSG_STA, NULL},
-
- {"CC_BACKUP_APPOINT.REQ", MSG_STA, NULL},
- {"CC_BACKUP_APPOINT.CNF", MSG_CCO, NULL},
- {"CC_BACKUP_APPOINT." , MSG_STA, NULL},
- {"CC_BACKUP_APPOINT." , MSG_STA, NULL},
-
- {"CC_LINK_INFO.REQ" , MSG_CCO, NULL},
- {"CC_LINK_INFO.CNF" , MSG_STA, NULL},
- {"CC_LINK_INFO.IND" , MSG_STA, NULL}, // le msg est STA car le destinataire n'a pas encore changé
- {"CC_LINK_INFO.RSP" , MSG_CCO, NULL},
-
- {"CC_HANDOVER.REQ" , MSG_STA, NULL},
- {"CC_HANDOVER.CNF" , MSG_CCO, NULL},
- {"CC_HANDOVER." , MSG_STA, NULL},
- {"CC_HANDOVER." , MSG_STA, NULL},
-
- {"CC_HANDOVER_INFO." , MSG_STA, NULL},
- {"CC_HANDOVER_INFO." , MSG_STA, NULL},
- {"CC_HANDOVER_INFO.IND" , MSG_STA, NULL},
- {"CC_HANDOVER_INFO.RSP" , MSG_CCO, NULL}
-
-};
+ { "CC_BACKUP_APPOINT.REQ", MSG_STA, NULL },
+ { "CC_BACKUP_APPOINT.CNF", MSG_CCO, NULL },
+ { "CC_BACKUP_APPOINT.", MSG_STA, NULL },
+ { "CC_BACKUP_APPOINT.", MSG_STA, NULL },
+
+ { "CC_LINK_INFO.REQ", MSG_CCO, NULL },
+ { "CC_LINK_INFO.CNF", MSG_STA, NULL },
+ { "CC_LINK_INFO.IND", MSG_STA, NULL }, // le msg est STA car le destinataire n'a pas encore changé
+ { "CC_LINK_INFO.RSP", MSG_CCO, NULL },
+
+ { "CC_HANDOVER.REQ", MSG_STA, NULL },
+ { "CC_HANDOVER.CNF", MSG_CCO, NULL },
+ { "CC_HANDOVER.", MSG_STA, NULL },
+ { "CC_HANDOVER.", MSG_STA, NULL },
+
+ { "CC_HANDOVER_INFO.", MSG_STA, NULL },
+ { "CC_HANDOVER_INFO.", MSG_STA, NULL },
+ { "CC_HANDOVER_INFO.IND", MSG_STA, NULL },
+ { "CC_HANDOVER_INFO.RSP", MSG_CCO, NULL }
+ };
u16
-msg_get_number(msg_mme_t *msg)
+msg_get_number (msg_mme_t *msg)
{
- msg_mme_t * mme;
- u16 mme_num;
-
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
+ msg_mme_t * mme;
+ u16 mme_num;
+
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
mme = msg;
mme_num = mme->mm_type;
-
- if( mme->mm_type >= MSG_CM_START ) mme_num -= (MSG_CM_START - (MSG_NN_STOP + 1));
- if( mme->mm_type >= MSG_NN_START ) mme_num -= (MSG_NN_START - (MSG_CP_STOP + 1));
- if( mme->mm_type >= MSG_CP_START ) mme_num -= (MSG_CP_START - (MSG_CC_STOP + 1));
-
- if(mme_num >= COUNT(msg_list))
+
+ if (mme->mm_type >= MSG_CM_START ) mme_num -= (MSG_CM_START - (MSG_NN_STOP + 1));
+ if (mme->mm_type >= MSG_NN_START ) mme_num -= (MSG_NN_START - (MSG_CP_STOP + 1));
+ if (mme->mm_type >= MSG_CP_START ) mme_num -= (MSG_CP_START - (MSG_CC_STOP + 1));
+
+ if (mme_num >= COUNT (msg_list))
{
- dbg_assert(0);
+ dbg_assert (0);
return MSG_UNKNOW;
}
return mme_num;
}
-void *
-msg_dispatch(msg_mme_t *msg)
+void *
+msg_dispatch (msg_mme_t *msg)
{
- u16 mme_num;
-
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
+ u16 mme_num;
+
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
- mme_num = msg_get_number(msg);
- if( (mme_num == MSG_UNKNOW) || (msg_list[mme_num].msg_func == NULL) )
+ mme_num = msg_get_number (msg);
+ if ( (mme_num == MSG_UNKNOW) || (msg_list[mme_num].msg_func == NULL))
{
// unknown or not implemented message
return NULL;
}
- msg_list[mme_num].msg_func(msg);
+ msg_list[mme_num].msg_func (msg);
return msg_list[mme_num].msg_func;
}
-void
-msg_set_mme_const_values(msg_mme_t *msg)
+void
+msg_set_mme_const_values (msg_mme_t *msg)
{
- dbg_assert(msg);
+ dbg_assert (msg);
- msg->m_type = MSG_MTYPE; // if you know how to init a const value in a struct, tell me !
+ msg->m_type = MSG_MTYPE; // 11.1.4
+ msg->mmv = 0x01; // 11.1.5
}
-bool
-msg_check_wrong_mme_const_values(msg_mme_t *msg)
+bool
+msg_check_wrong_mme_const_values (msg_mme_t *msg)
{
- dbg_assert(msg);
+ dbg_assert (msg);
- return (msg->m_type != MSG_MTYPE);
+ return (msg->m_type != MSG_MTYPE);
}
+void
+msg_send(msg_mme_t *msg, uint msg_size, interf_id_t interf_id)
+{
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ dbg_assert(msg_size <= SAR_MSDU_PAYLOAD_MAX_SIZE);
+ dbg_assert(interf_id < INTERF_MAX);
+ // set the values common to all MME
+ // TODO set the ODA
+ // and then, send the message
+ interf_send (msg, msg_size, interf_id);
+}
diff --git a/cp/msg/src/msg_cc.c b/cp/msg/src/msg_cc.c
index e4829e950c..25535b2dc3 100644
--- a/cp/msg/src/msg_cc.c
+++ b/cp/msg/src/msg_cc.c
@@ -1,4 +1,3 @@
-
/* Cesar project {{{
*
* Copyright (C) 2007 Spidcom
@@ -15,9 +14,3 @@
#include "common/std.h"
#include "cp/msg/inc/msg_cc.h"
-
-
-int MSG_CC_CCO_APPOINT_REQ_Send(E_IntID IntID, u8 TEI, u8 ReqType, u8 MacAd[])
-{
- return 0;
-}
diff --git a/cp/msg/src/msg_cm.c b/cp/msg/src/msg_cm.c
new file mode 100644
index 0000000000..7e3aa303ad
--- /dev/null
+++ b/cp/msg/src/msg_cm.c
@@ -0,0 +1,48 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/msg/msg_cm.c
+ * \brief
+ * \ingroup cp_msg
+ */
+
+#include "common/std.h"
+#include "cp/msg/inc/msg_cm.h"
+
+
+void
+msg_cm_unassociated_sta_ind_send(interf_id_t interf_id, mac_adresse_t oda)
+{
+ // 11.5.1
+ msg_mme_t *msg;
+ unassociated_sta_t *unassociated_sta;
+
+ dbg_assert(interf_id < INTERF_MAX);
+
+ // ask for a buffer
+ msg = interf_give_buf ();
+ dbg_assert ( !msg_check_wrong_mme_const_values (msg));
+ // set the header values of msg
+ memcpy(msg->oda, oda, sizeof(mac_adresse_t));
+ // the OSA is set in the common part of interf_send
+ // vlan is optional and not used
+ // mtype is a constant already set
+ // mmv is a constant already set
+ msg->mm_type = CM_UNASSOCIATED_STA_IND;
+ // the message is not fragmented
+ msg->fmi.nf_mi = 0;
+ msg->fmi.fn_mi = 0;
+ msg->fmi.fmsn = 0;
+ // set the message values
+ unassociated_sta = (unassociated_sta_t *) & msg->mm_entry;
+ // TODO set the values...
+
+ // and finaly, send the message
+ STA_TRACE(" send cm_unassociated_sta\n");
+ msg_send(msg, sizeof(unassociated_sta_t) + MSG_MME_HEADER_SIZE, interf_id);
+}
diff --git a/cp/station/Makefile b/cp/station/Makefile
index d9278ba349..a5965225c3 100644
--- a/cp/station/Makefile
+++ b/cp/station/Makefile
@@ -3,7 +3,7 @@ BASE = ../../
ECOS = y
TARGET_PROGRAMS = station
-station_SOURCES = station.c
+station_SOURCES = station_fsm.c station_events.c
station_MODULES = lib cp/interf
include $(BASE)/common/make/top.mk
diff --git a/cp/station/Module b/cp/station/Module
index 4c122d337a..cde4fa5e6e 100644
--- a/cp/station/Module
+++ b/cp/station/Module
@@ -1,2 +1,2 @@
-SOURCES := station.c
+SOURCES := station_fsm.c station_events.c
diff --git a/cp/station/inc/station_events.h b/cp/station/inc/station_events.h
new file mode 100644
index 0000000000..81c54dfa0d
--- /dev/null
+++ b/cp/station/inc/station_events.h
@@ -0,0 +1,55 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/station/inc/station_events.h
+ * \brief
+ * \ingroup cp_sta
+ */
+#ifndef STATION_EVENTS_H_
+#define STATION_EVENTS_H_
+
+#include "cp/station/station.h"
+
+/**
+ * \brief launch the ustt timer
+ * \param
+ * \return
+ */
+void
+station_launch_ustt(void);
+
+/**
+ * \brief called when the ustt timer has expired
+ *
+ * \param
+ * \return
+ */
+void
+station_ustt_expires(void);
+
+/**
+ * \brief send periodically the unassoc_sta mme
+ *
+ * \param
+ * \return
+ */
+void
+station_send_cm_unassoc_sta_mme_periodicaly(void);
+
+/**
+ * \brief stop sending periodically the unassoc_sta mme
+ *
+ * \param
+ * \return
+ */
+void
+station_stop_cm_unassoc_sta_mme_periodicaly(void);
+
+
+
+#endif /*STATION_EVENTS_H_*/
diff --git a/cp/station/inc/station_types.h b/cp/station/inc/station_types.h
index 735618e74c..9081cc1b6c 100644
--- a/cp/station/inc/station_types.h
+++ b/cp/station/inc/station_types.h
@@ -14,23 +14,67 @@
#define STA_TYPES_H_
/*
+ * station module constantes
+ */
+ // the number of alarm that we can create
+#if DEBUG // we need 3 more alarms in debug for test purpose
+ #define ALARM_NB 6
+#else
+ #define ALARM_NB 3
+#endif
+
+/*
+ * Homeplug AV constantes
+ */
+#define MinCCoScanTime_ms 1000
+#define MaxCCoScanTime_ms 2000
+#define MinScanTime_ms 2000
+#define MaxScanTime_ms 4000
+#define USAI_ms 1000
+#define MaxDiscoverPeriod_ms 10000
+
+/*
* the event flags
*/
-#define STATION_FLAG_MSG_RCV 0x1 // the sta has received a mme
-#define STATION_FLAG_PERIODIC 0x2 // should send a cm_unassociated_sta message
- // or a beacon
-#define STATION_FLAG_BEACON_MISSED 0x4 // the last beacon was missed
-#define STATION_FLAG_BEACON_RECEIVED 0x8 // a beacon was received
-#define STATION_FLAG_BBT 0x10 // the timer bbt has expired
-#define STATION_FLAG_USTT 0x20 // the timer ustt has expired
-#define STATION_FLAG_TEI_LEASE 0x40 // the tei of the sta has expired
-#define STATION_FLAG_BUF_REL 0x80 // some buffer can be released
-// TBC
+typedef enum station_flag_t
+{
+ STATION_FLAG_MSG_RCV = 0x1, // the sta has received a mme
+ STATION_FLAG_PERIODIC_UNASSO = 0x2, // send a cm_unassociated_sta message
+ STATION_FLAG_PERIODIC_BEACON = 0x4, // send a periodic beacon
+ STATION_FLAG_BEACON_MISSED = 0x8, // the last beacon was missed
+ STATION_FLAG_BEACON_RECEIVED = 0x10, // a beacon was received
+ STATION_FLAG_BBT = 0x20, // the timer bbt has expired
+ STATION_FLAG_USTT = 0x40, // the timer ustt has expired
+ STATION_FLAG_TEI_LEASE = 0x80, // the tei of the sta has expired
+ STATION_FLAG_BUF_REL = 0x100 // some buffer can be released
+ // TBC
+} station_flag_t;
+
+
+typedef enum station_status_t
+{
+ POWER_ON,
+ UNASSO_STA,
+ UNASSO_CCO,
+ UNAUTHEN_STA,
+ AUTHEN_STA
+} station_status_t;
typedef struct station_event_t
{
- cyg_flag_value_t flag_value;
- void (*func)(void);
+ cyg_flag_value_t flag_value;
+ void (*func) (void);
} station_event_t;
+typedef struct alarm_def_t
+{
+ bool alarm_used;
+ cyg_alarm alarm;
+ cyg_handle_t counter;
+ cyg_handle_t real_time_clock_handle;
+ cyg_handle_t alarm_handle;
+ cyg_flag_t *cyg_flag;
+ station_flag_t station_flag;
+} alarm_def_t;
+
#endif /*STA_TYPES_H_*/
diff --git a/cp/station/src/station.c b/cp/station/src/station.c
deleted file mode 100644
index ef1471b9b6..0000000000
--- a/cp/station/src/station.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file cp/station/station.h
- * \brief
- * \ingroup cp_station
- */
-
-#include "common/std.h"
-#include "cp/station/station.h"
-
-
-/*
- * global variables of station module
- */
-cyg_flag_t station_flag;
-
-/*
- * locale variables
- */
-const station_event_t station_event[] =
- {
- {STATION_FLAG_MSG_RCV, interf_received},
- {STATION_FLAG_BUF_REL, interf_buf_to_release}
- };
-
-/*
- * functions of station module
- */
-
-
-void
-station_init(void)
-{
- // init the sta module
- cyg_flag_init(&station_flag);
-
- // init the others modules
- interf_init();
- // TODO init the others modules
-
- // wait 60 ms for some zero cross
- cyg_thread_delay(interf_ms_to_cyg_tick(60));
- // now that everything is initialised, do the AVLN discovery
-// station_power_on_net_disco();
-}
-
-void
-station_power_on_net_disco(void)
-{
- // TODO
- station_wait_event();
-}
-
-void
-station_wait_event(void)
-{
- cyg_flag_value_t flag_value;
- uint i;
-#if DEBUG
- uint tmp;
-#endif
-
- while(1)
- {
- // wait for a station event
- flag_value = cyg_flag_wait(&station_flag, 0xFFFFFFFF, CYG_FLAG_WAITMODE_OR);
- // process the event
- for(i=0 ; i<COUNT(station_event) ; i++)
- {
- if(flag_value & station_event[i].flag_value)
- {
- // we find an event, so we clear it
- cyg_flag_maskbits(&station_flag, station_event[i].flag_value);
- // and then we process it
- dbg_assert(station_event[i].func);
- station_event[i].func();
- }
- }
-#if DEBUG
- // check if some other event did not occur
- for(i=0, tmp=0 ; i<COUNT(station_event) ; i++)
- {
- tmp <<= 1;
- tmp |= 1;
- }
- dbg_assert(flag_value & tmp);
-#endif
- }
-}
diff --git a/cp/station/src/station_events.c b/cp/station/src/station_events.c
new file mode 100644
index 0000000000..24a4679839
--- /dev/null
+++ b/cp/station/src/station_events.c
@@ -0,0 +1,95 @@
+ /* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/station/src/station_events.c
+ * \brief the events generated in station module
+ * \ingroup cp_station
+ */
+
+#include "common/std.h"
+#include "cp/station/inc/station_events.h"
+
+
+void
+station_launch_ustt(void)
+{
+ uint ustt;
+ double tmp;
+
+ tmp = rand_r( & station_seed);
+ tmp /= RAND_MAX;
+ tmp *= USAI_ms;
+ ustt = (int) tmp;
+ //printf("ustt = %i \n", ustt);
+ dbg_assert(ustt < USAI_ms);
+ dbg_assert(ustt);
+ //printf("ustt timer = %i ms\n", ustt);
+ station_gen_timed_event(&station_flag, STATION_FLAG_USTT, ustt);
+ }
+
+
+void
+station_ustt_expires(void)
+{
+
+ // see Figure 7-76
+ bool avln_detected = true;
+
+ //STA_TRACE("ustt expires\n");
+ // check if some AVLN are detected
+ // TODO
+ if(avln_detected)
+ {
+ // send unassoc_sta_mme with a periodic time
+ if( ! unassoc_sta_mme_periodic_sending)
+ station_send_cm_unassoc_sta_mme_periodicaly();
+ }
+ else
+ {
+ // stop transmiting unassoc_sta_mme
+ if( unassoc_sta_mme_periodic_sending)
+ station_stop_cm_unassoc_sta_mme_periodicaly();
+ }
+ // check if we launch again the ustt timer Fig 7-76 or Fig 7-77
+ if( (station_status == POWER_ON) || (station_status == UNASSO_STA) )
+ {
+ station_launch_ustt();
+ }
+}
+
+void
+station_send_cm_unassoc_sta_mme_periodicaly(void)
+{
+ // see 7.2.1
+ static int offset_ms;
+ int next_event_date_ms;
+ double tmp;
+
+ // set the flag
+ unassoc_sta_mme_periodic_sending = true;
+ // calculate the next transmition time
+ tmp = rand_r( & station_seed);
+ tmp /= RAND_MAX;
+ tmp *= MaxDiscoverPeriod_ms;
+ next_event_date_ms = (int) tmp;
+ next_event_date_ms += offset_ms;
+ offset_ms = MaxDiscoverPeriod_ms - tmp;
+ dbg_assert(next_event_date_ms);
+ dbg_assert(next_event_date_ms < (2 * MaxDiscoverPeriod_ms));
+ station_gen_timed_event(&station_flag, STATION_FLAG_PERIODIC_UNASSO, next_event_date_ms);
+ // send the message
+ msg_cm_unassociated_sta_ind_send(INTERF_SAR, BROADCAST_MAC_AD);
+}
+
+void
+station_stop_cm_unassoc_sta_mme_periodicaly(void)
+{
+ // reset the flag
+ unassoc_sta_mme_periodic_sending = false;
+ station_stop_timed_event(&station_flag, STATION_FLAG_PERIODIC_UNASSO);
+}
diff --git a/cp/station/src/station_fsm.c b/cp/station/src/station_fsm.c
new file mode 100644
index 0000000000..0f9757c46e
--- /dev/null
+++ b/cp/station/src/station_fsm.c
@@ -0,0 +1,228 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/station/src/station_fsm.c
+ * \brief finite state machine and main loop of the thread station
+ * \ingroup cp_station
+ */
+
+#include "common/std.h"
+#include "cp/station/station.h"
+
+
+/*
+ * global variables of station module
+ */
+// this is for the STA events
+cyg_flag_t station_flag;
+// the station status (POWER_ON, UNASSOCIATED, etc)
+station_status_t station_status;
+// the seed used for random numbers
+uint station_seed = 894;
+// a flag, true when sending unassociated sta mme on a periodic way
+bool unassoc_sta_mme_periodic_sending;
+
+/*
+ * locale variables
+ */
+const station_event_t station_event[] =
+ {
+ { STATION_FLAG_MSG_RCV, interf_received },
+ { STATION_FLAG_BUF_REL, interf_buf_to_release },
+ { STATION_FLAG_USTT, station_ustt_expires},
+ { STATION_FLAG_PERIODIC_UNASSO, station_send_cm_unassoc_sta_mme_periodicaly }
+ };
+static alarm_def_t alarm_def[ALARM_NB];
+static cyg_mutex_t alarm_lock;
+
+/*
+ * functions of station module
+ */
+
+void
+station_init (void)
+{
+ uint i;
+
+ // TODO init station_seed
+ // init the station module
+ // init the event
+ cyg_flag_init (&station_flag);
+ // init the alarm
+ for(i=0 ; i<COUNT(alarm_def) ; i++)
+ alarm_def[i].alarm_used = false;
+ cyg_mutex_init( & alarm_lock);
+ unassoc_sta_mme_periodic_sending = false;
+
+ // init the others modules
+ interf_init ();
+ // TODO init the others modules
+
+ // wait 60 ms for some zero cross
+#if DEBUG == 0
+ cyg_thread_delay (interf_ms_to_cyg_tick (60));
+#endif
+ // now that everything is initialised, do the AVLN discovery
+ station_power_on_net_disco();
+}
+
+
+
+void
+station_power_on_net_disco (void)
+{
+ bool sta_was_cco = false;
+ uint min_bbt, max_bbt, bbt;
+ double tmp;
+
+ STA_TRACE("Station enter POWER_ON state\n");
+ station_status = POWER_ON;
+ // TODO check if before the previous reboot the sta was CCO
+ // if yes, set sta_was_cco to true
+ // calculate the BBT
+ if (sta_was_cco)
+ {
+ min_bbt = MinCCoScanTime_ms;
+ max_bbt = MaxCCoScanTime_ms;
+ }
+ else
+ {
+ min_bbt = MinScanTime_ms;
+ max_bbt = MaxScanTime_ms;
+ }
+ tmp = rand_r( & station_seed);
+ tmp /= RAND_MAX;
+ tmp *= max_bbt;
+ bbt = (int) tmp;
+ bbt += min_bbt;
+ dbg_assert( (bbt > MinCCoScanTime_ms) && (bbt < MaxScanTime_ms) );
+ // set the BBT timer
+ //printf("bbt = %i ms\n", bbt);
+ station_gen_timed_event(&station_flag, STATION_FLAG_BBT, bbt);
+ // calculate USTT timer
+ station_launch_ustt();
+
+ station_wait_event ();
+}
+
+void
+station_wait_event (void)
+{
+ cyg_flag_value_t flag_value, flag_mask;
+ uint i;
+
+ // create the flag mask
+ flag_mask = 0;
+ for(i=0 ; i<COUNT(station_event) ; i++)
+ {
+ flag_mask |= station_event[i].flag_value;
+ }
+ // the infinite loop of the thread
+#if DEBUG
+ printf(" station ready and waiting for event...\n");
+#endif
+ while (1)
+ {
+ // wait for a station event
+ flag_value = cyg_flag_wait (&station_flag, flag_mask, CYG_FLAG_WAITMODE_OR );
+ //printf("flag_value : %x\n", flag_value);
+ // process the event
+ for (i=0; i<COUNT (station_event) ; i++)
+ {
+ if (flag_value & station_event[i].flag_value)
+ {
+ // we find an event, so we clear it
+ cyg_flag_maskbits (&station_flag, ~station_event[i].flag_value);
+ // and then we process it
+ dbg_assert (station_event[i].func);
+ station_event[i].func ();
+ }
+ }
+ }
+}
+
+
+
+
+void
+station_gen_timed_event(cyg_flag_t *cyg_flag, station_flag_t station_flag, uint event_delay_ms)
+{
+ uint i;
+ cyg_tick_count_t trigger_time;
+
+ dbg_assert(cyg_flag);
+
+cyg_mutex_lock ( & alarm_lock);
+
+ // search for an available alarm
+ for(i=0 ; (i<COUNT(alarm_def)) && (alarm_def[i].alarm_used == true) ; i++);
+ dbg_assert(i<COUNT(alarm_def));
+ // get the handle to the real time clock counter
+ alarm_def[i].alarm_used = true;
+
+cyg_mutex_unlock ( & alarm_lock);
+
+ alarm_def[i].real_time_clock_handle = cyg_real_time_clock();
+ cyg_clock_to_counter(alarm_def[i].real_time_clock_handle, &alarm_def[i].counter);
+ // create the alarm
+ alarm_def[i].cyg_flag = cyg_flag;
+ alarm_def[i].station_flag = station_flag;
+ cyg_alarm_create ( alarm_def[i].counter,
+ station_alarm_handler,
+ i,
+ & alarm_def[i].alarm_handle,
+ & alarm_def[i].alarm
+ );
+ // initialize the alarm
+ trigger_time = interf_ms_to_cyg_tick(event_delay_ms) + cyg_current_time();
+ cyg_alarm_initialize(alarm_def[i].alarm_handle, trigger_time, 0);
+ //printf("create alarm %i at %i\n", i, (int) cyg_current_time());
+}
+
+void
+station_stop_timed_event(cyg_flag_t *cyg_flag, station_flag_t station_flag)
+{
+ uint i;
+
+cyg_mutex_lock ( & alarm_lock);
+
+ // search for the alarm to stop
+ for(i=0 ; i<COUNT(alarm_def) ; i++)
+ if( (alarm_def[i].cyg_flag == cyg_flag)
+ && (alarm_def[i].station_flag == station_flag) ) break;
+ if(i < COUNT(alarm_def))
+ {
+ cyg_alarm_disable(alarm_def[i].alarm_handle);
+ alarm_def[i].alarm_used = false;
+ cyg_flag_maskbits(cyg_flag, ~ station_flag);
+ //printf("delete alarm %i\n", i);
+ }
+
+cyg_mutex_unlock ( & alarm_lock);
+
+}
+
+void
+station_alarm_handler(cyg_handle_t alarm, cyg_addrword_t data)
+// warning : this function is called in DSR context
+{
+ dbg_assert(data < COUNT(alarm_def));
+ dbg_assert(alarm_def[data].cyg_flag);
+
+cyg_mutex_lock ( & alarm_lock);
+
+ // release the alarm
+ alarm_def[data].alarm_used = false;
+ // generate the event
+ cyg_flag_setbits (alarm_def[data].cyg_flag, alarm_def[data].station_flag);
+ //printf("got event at %i\n", (int) cyg_current_time());
+
+cyg_mutex_unlock ( & alarm_lock);
+
+}
+
diff --git a/cp/station/station.h b/cp/station/station.h
index 37b0ef96dd..f3013336cb 100644
--- a/cp/station/station.h
+++ b/cp/station/station.h
@@ -6,7 +6,7 @@
*
* }}} */
/**
- * \file cp/sta/sta.h
+ * \file cp/station/station.h
* \brief
* \ingroup cp_sta
*/
@@ -17,20 +17,36 @@
#include "cp/interf/interf.h"
#include "cp/station/inc/station_types.h"
+#include "cp/station/inc/station_events.h"
+#define STA_TRACE_ENABLE 1
+
+#if STA_TRACE_ENABLE
+ //#define STA_TRACE(p) printf("%6i : %s", cyg_current_time(), p)
+ #define STA_TRACE(p) printf(p)
+#else
+ #define STA_TRACE(p)
+#endif
+
/*
- * global variables of sta module
+ * some global variables
*/
+extern station_status_t station_status;
+extern uint station_seed;
+extern bool unassoc_sta_mme_periodic_sending;
+extern cyg_flag_t station_flag;
+
+
/**
* \brief Init station module
* This is the cp entry point.
* \param
* \return
*/
-void
-station_init(void);
+void
+station_init (void);
/**
* \brief Init station module
@@ -38,17 +54,49 @@ station_init(void);
* \param
* \return
*/
-void
-station_power_on_net_disco(void);
-
+void
+station_power_on_net_disco (void);
/**
* \brief wait for a station event
* \param
* \return
*/
-void
-station_wait_event(void);
+void
+station_wait_event (void);
+
+/**
+ * \brief create an alarm that will generate an event after
+ * the specified delay
+ * \param cyg_flag : the event handle
+ * \param station_flag : the event flag
+ * \param event_delay_ms : the amount of time to wait
+ * \return
+ */
+void
+station_gen_timed_event(cyg_flag_t *cyg_flag, station_flag_t station_flag, uint event_delay_ms);
+
+/**
+ * \brief will stop an alarm previously created with station_gen_timed_event
+ *
+ * \param cyg_flag : the event handle
+ * \param station_flag : the event flag
+ * \return
+ */
+void
+station_stop_timed_event(cyg_flag_t *cyg_flag, station_flag_t station_flag);
+
+
+/**
+ * \brief this function is called when the amount of time specified
+ * with station_wait_event() has elapsed.
+ * warning : this function is called in DSR context
+ *
+ * \param see ecos manual about alarm
+ * \return
+ */
+void
+station_alarm_handler(cyg_handle_t alarm, cyg_addrword_t data);
#endif /* CP_STATION_H_ */
diff --git a/cp/test/Makefile b/cp/test/Makefile
index 758d773f6e..2b67297f47 100644
--- a/cp/test/Makefile
+++ b/cp/test/Makefile
@@ -3,7 +3,7 @@ BASE = ../../
ECOS = y
TARGET_PROGRAMS = UnitTestCP
-UnitTestCP_SOURCES = test_interf.c test_cp.c test_msg.c
+UnitTestCP_SOURCES = test_interf.c test_cp.c test_msg.c test_station.c
UnitTestCP_MODULES = lib cp/interf cp/msg cp/station
include $(BASE)/common/make/top.mk
diff --git a/cp/test/inc/test_interf.h b/cp/test/inc/test_interf.h
index f602826c47..7ffdca8378 100644
--- a/cp/test/inc/test_interf.h
+++ b/cp/test/inc/test_interf.h
@@ -14,7 +14,6 @@
#ifndef interf__test__h
#define interf__test__h
-
#include <stdio.h>
#include <string.h>
@@ -22,10 +21,7 @@
#include "cp/interf/interf.h"
#include "cp/interf/inc/interf_private.h"
-
-void
-interf_test(void);
+void interf_test (void);
#endif
-
-
+
diff --git a/cp/test/inc/test_msg.h b/cp/test/inc/test_msg.h
index ac80b55acc..f4ce28aa22 100644
--- a/cp/test/inc/test_msg.h
+++ b/cp/test/inc/test_msg.h
@@ -14,19 +14,13 @@
#ifndef messages__test__h
#define messages__test__h
-
#include <stdio.h>
#include <string.h>
#include "cp/msg/msg.h"
#include "cp/cp_types.h"
-
-
-void
-msg_test(void);
-
-
+void msg_test (void);
#endif
-
+
diff --git a/cp/test/inc/test_secu.h b/cp/test/inc/test_secu.h
index 2a3bdaafd0..3e46cc7182 100644
--- a/cp/test/inc/test_secu.h
+++ b/cp/test/inc/test_secu.h
@@ -7,21 +7,18 @@
* }}} */
/**
* \file cp/test/test_secu.h
- * \brief Unit tests for module SECU.
+ * \brief Unit tests for module secu.
* \ingroup cp_test
*/
#ifndef secu__test__h
#define secu__test__h
-
#include <stdio.h>
#include <string.h>
#include "cp/secu/secu.h"
-
-void
-SECU_Test(void);
+void SECU_Test (void);
#endif
diff --git a/cp/test/inc/test_station.h b/cp/test/inc/test_station.h
new file mode 100644
index 0000000000..789fa54c58
--- /dev/null
+++ b/cp/test/inc/test_station.h
@@ -0,0 +1,22 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/test/test_station.h
+ * \brief Unit tests for module station.
+ * \ingroup cp_test
+ */
+#ifndef TEST_STATION_H_
+#define TEST_STATION_H_
+
+#include "cp/station/station.h"
+
+
+void station_test (void);
+
+
+#endif /*TEST_STATION_H_*/
diff --git a/cp/test/src/test_cp.c b/cp/test/src/test_cp.c
index 5c25544c06..f463238aec 100644
--- a/cp/test/src/test_cp.c
+++ b/cp/test/src/test_cp.c
@@ -16,48 +16,22 @@
#include <cyg/kernel/kapi.h>
#include "common/std.h"
-#include "cp/station/station.h"
//#include "cp/test/test_secu.h"
#include "cp/test/inc/test_msg.h"
#include "cp/test/inc/test_interf.h"
+#include "cp/test/inc/test_station.h"
-/*
- * sta thread constantes
- */
-#define STA_PRIORITY 30
-
-static unsigned char sta_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
-static cyg_handle_t sta_handle;
-static cyg_thread sta_thread;
-static void
-sta_entry(cyg_addrword_t data)
+int main (void)
{
- //station_init();
- station_wait_event();
-}
-
-
-int main(void)
-{
- char thread_name[] = "sta";
-
- station_init();
- // create a station thread
- cyg_thread_create( STA_PRIORITY,
- &sta_entry,
- 0,
- thread_name,
- sta_stack,
- sizeof(sta_stack),
- &sta_handle,
- &sta_thread
- );
-
-// SECU_Test();
- msg_test();
- interf_test();
- printf("test complete.\n");
- return 0;
+ // SECU_Test();
+ msg_test ();
+ interf_test ();
+ station_test ();
+
+ printf ("test complete.\n");
+ // and stop the ecos thread
+ HAL_PLATFORM_EXIT(0);
+ return 0;
}
diff --git a/cp/test/src/test_interf.c b/cp/test/src/test_interf.c
index 563412e09c..1ecd7fbc8b 100644
--- a/cp/test/src/test_interf.c
+++ b/cp/test/src/test_interf.c
@@ -17,105 +17,106 @@
/*
* Test de void interf_init(void);
*/
-int
-interf_init_test(void)
+int interf_init_test (void)
{
- return interf_init();
+ return interf_init ();
}
/*
* Test de interf_received_frag_test
*/
-int interf_received_frag_test(void)
+int interf_received_frag_test (void)
{
- interf_buffer_t buf_test[5];
- msg_mme_t *msg;
- int i;
- // init the buf
- bzero(buf_test, sizeof(buf_test));
- // Test add of a 5 fragments message
- for(i=0 ; i<5 ; i++)
- {
- msg = &buf_test[i].msg;
- msg_set_mme_const_values(msg);
- bzero(msg->osa, 6);
- msg->fmi.nf_mi = 4; // Number of fragments for message
- msg->fmi.fn_mi = i; // fragment number
- msg->fmi.fmsn = 32;
- if(i != msg->fmi.nf_mi)
- {
- if(interf_received_frag(msg) != NULL) return Failure;
- }
- else if(interf_received_frag(msg) == NULL) return Failure;
- }
- // check that BufTest structure is updated correctly
- for(i=0 ; i < 3 ; i++)
- {
- if(buf_test[i].next_msg != &buf_test[i+1].msg ) return Failure;
- }
- // Test filling the receiving struct
- interf_init();
- for(i=0 ; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
- {
- msg = &buf_test[i].msg;
- bzero(msg->osa, 6);
- msg->fmi.nf_mi = 4; // Number of fragments for message
- msg->fmi.fn_mi = i; // fragment number
- msg->fmi.fmsn = i;
- if(interf_received_frag(msg) != NULL) return Failure;
- }
- // and then test adding others fragments
- for(i=1 ; i < 5 ; i++)
- {
- msg = &buf_test[i].msg;
- bzero(msg->osa, 6);
- msg->fmi.nf_mi = 4; // Number of fragments for message
- msg->fmi.fn_mi = i; // fragment number
- msg->fmi.fmsn = 0;
- if(i != msg->fmi.nf_mi)
- {
- if(interf_received_frag(msg) != NULL) return Failure;
- }
- else if(interf_received_frag(msg) == NULL) return Failure;
- }
- return Success;
+ interf_buffer_t buf_test[5];
+ msg_mme_t *msg;
+ int i;
+
+ interf_init ();
+ // init the buf
+ bzero (buf_test, sizeof(buf_test));
+ // Test add of a 5 fragments message
+ for(i=0; i<5; i++)
+ {
+ msg = &buf_test[i].msg;
+ msg_set_mme_const_values(msg);
+ bzero(msg->osa, 6);
+ msg->fmi.nf_mi = 4; // Number of fragments for message
+ msg->fmi.fn_mi = i; // fragment number
+ msg->fmi.fmsn = 32;
+ if(i != msg->fmi.nf_mi)
+ {
+ if(interf_received_frag(msg) != NULL) return 1;
+ }
+ else if(interf_received_frag(msg) == NULL) return 2;
+ }
+ // check that BufTest structure is updated correctly
+ for(i=0; i < 3; i++)
+ {
+ if(buf_test[i].next_msg != &buf_test[i+1].msg ) return 3;
+ }
+ // Test filling the receiving struct
+ interf_init();
+ for(i=0 ; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
+ {
+ msg = &buf_test[i].msg;
+ bzero(msg->osa, 6);
+ msg->fmi.nf_mi = 4; // Number of fragments for message
+ msg->fmi.fn_mi = i; // fragment number
+ msg->fmi.fmsn = i;
+ if(interf_received_frag(msg) != NULL) return 4;
+ }
+ // and then test adding others fragments
+ for(i=1 ; i<5 ; i++)
+ {
+ msg = &buf_test[i].msg;
+ bzero(msg->osa, 6);
+ msg->fmi.nf_mi = 4; // Number of fragments for message
+ msg->fmi.fn_mi = i; // fragment number
+ msg->fmi.fmsn = 0;
+ if(i != msg->fmi.nf_mi)
+ {
+ if(interf_received_frag(msg) != NULL) return 5;
+ }
+ else if(interf_received_frag(msg) == NULL) return 6;
+ }
+ return Success;
}
/*
* Test de void interf_msg_add(msg_mme_dest_t mme_dest, msg_mme_t *msg)
*
*/
-int interf_msg_add_test(void)
+int interf_msg_add_test (void)
{
- msg_mme_dest_t dest = MSG_STA;
- msg_mme_t msg;
-
- msg_set_mme_const_values( & msg);
- interf_msg_add(dest, & msg);
-
- return Success;
+ msg_mme_dest_t dest = MSG_STA;
+ msg_mme_t msg;
+
+ msg_set_mme_const_values ( &msg);
+ interf_msg_add (dest, &msg);
+
+ return Success;
}
/*
* Test de void interf_send(msg_mme_t *msg)
*
*/
-int interf_send_test(void)
+int interf_send_test (void)
{
- msg_mme_t msg;
-
- msg_set_mme_const_values( & msg);
- interf_send( & msg, 80, INTERF_CP);
- return Success;
+ msg_mme_t msg;
+
+ msg_set_mme_const_values ( &msg);
+ interf_send ( &msg, 80, INTERF_CP);
+ return Success;
}
/*
* Test de void interf_received(void)
*
*/
-int interf_received_test(void)
+int interf_received_test (void)
{
- interf_received();
- return Success;
+ interf_received ();
+ return Success;
}
/*
@@ -123,38 +124,38 @@ int interf_received_test(void)
*/
#define NB_MSG_REMOVE_TEST 4
-int interf_msg_remove_test(void)
+int interf_msg_remove_test (void)
{
- msg_mme_t msg[NB_MSG_REMOVE_TEST];
- msg_mme_dest_t dest = MSG_STA;
- int i;
-
- // init the msg
- bzero(msg, sizeof(msg));
-
- // init all the interf module
- interf_init();
- // init messages
- for(i=0 ; i<NB_MSG_REMOVE_TEST ; i++)
- {
- msg_set_mme_const_values( & msg[i]);
- }
- // add messages in the fifo
- for(i=0 ; i<NB_MSG_REMOVE_TEST ; i++)
- {
- interf_msg_add(dest, & msg[i]);
- }
-
- // and then remove it with different order
- if( ! interf_msg_remove(dest, & msg[0]) ) return Failure;
- if( ! interf_msg_remove(dest, & msg[3]) ) return Failure;
- if( ! interf_msg_remove(dest, & msg[1]) ) return Failure;
- if( ! interf_msg_remove(dest, & msg[2]) ) return Failure;
- // remove messages from an empty fifo
- if( interf_msg_remove(dest, & msg[0]) ) return Failure;
- if( interf_msg_remove(dest, & msg[3]) ) return Failure;
-
- return Success;
+ msg_mme_t msg[NB_MSG_REMOVE_TEST];
+ msg_mme_dest_t dest = MSG_STA;
+ int i;
+
+ // init the msg
+ bzero (msg, sizeof(msg));
+
+ // init all the interf module
+ interf_init();
+ // init messages
+ for(i=0 ; i < NB_MSG_REMOVE_TEST ; i++)
+ {
+ msg_set_mme_const_values( & msg[i]);
+ }
+ // add messages in the fifo
+ for(i=0 ; i<NB_MSG_REMOVE_TEST ; i++)
+ {
+ interf_msg_add(dest, & msg[i]);
+ }
+
+ // and then remove it with different order
+ if( ! interf_msg_remove(dest, & msg[0]) ) return Failure;
+ if( ! interf_msg_remove(dest, & msg[3]) ) return Failure;
+ if( ! interf_msg_remove(dest, & msg[1]) ) return Failure;
+ if( ! interf_msg_remove(dest, & msg[2]) ) return Failure;
+ // remove messages from an empty fifo
+ if( interf_msg_remove(dest, & msg[0]) ) return Failure;
+ if( interf_msg_remove(dest, & msg[3]) ) return Failure;
+
+ return Success;
}
@@ -163,62 +164,61 @@ int interf_msg_remove_test(void)
* et des fonctions attachées
*/
#define MY_CONST_ 9 // doit etre inférieure a la taille d'une mailbox
-
-int interf_release_buf_test(void)
+int interf_release_buf_test (void)
{
- interf_buffer_t buf[MY_CONST_];
- msg_mme_t *msg[MY_CONST_];
- int i;
-
- // init all the interf module
- interf_init();
- bzero(&buf, sizeof(buf));
-
- // init the messages for test
- for(i=0 ; i<MY_CONST_ ; i++)
- {
- msg[i] = &buf[i].msg;
- bzero(msg[i]->osa, sizeof(msg[i]->osa));
- msg_set_mme_const_values(msg[i]);
- msg[i]->mm_type = 4; // cc_backup_appoint.req message,to STA
- }
-
- // empile les message dans la fifo
- for(i=0 ; i<MY_CONST_ ; i++)
- {
- interf_release_buf(msg[i]);
- }
- // et hop on vide !
- interf_buf_to_release();
-
- return Success;
+ interf_buffer_t buf[MY_CONST_];
+ msg_mme_t *msg[MY_CONST_];
+ int i;
+
+ // init all the interf module
+ interf_init ();
+ bzero (&buf, sizeof(buf));
+
+ // init the messages for test
+ for(i=0 ; i<MY_CONST_ ; i++)
+ {
+ msg[i] = &buf[i].msg;
+ bzero(msg[i]->osa, sizeof(msg[i]->osa));
+ msg_set_mme_const_values(msg[i]);
+ msg[i]->mm_type = 4; // cc_backup_appoint.req message,to STA
+ }
+
+ // empile les message dans la fifo
+ for(i=0 ; i<MY_CONST_ ; i++)
+ {
+ interf_release_buf(msg[i]);
+ }
+ // et hop on vide !
+ interf_buf_to_release();
+
+ return Success;
}
/*
* test de la fonction de purge
*/
-int interf_msg_purge_test(void)
+int interf_msg_purge_test (void)
{
- interf_buffer_t buf_test;
- msg_mme_t *msg;
-
- // init all the interf module
- interf_init();
- bzero(&buf_test, sizeof(buf_test));
-
- // create a fragment of message
- msg = &buf_test.msg;
- msg_set_mme_const_values(msg);
- bzero(msg->osa, 6);
- msg->fmi.nf_mi = 4; // Number of fragments for message
- msg->fmi.fn_mi = 1; // fragment number
- msg->fmi.fmsn = 32;
- // add this fragment in the fifo
- interf_receive(msg);
- interf_received();
- cyg_thread_delay(150);
- interf_msg_purge();
- return Success;
+ interf_buffer_t buf_test;
+ msg_mme_t *msg;
+
+ // init all the interf module
+ interf_init ();
+ bzero (&buf_test, sizeof(buf_test));
+
+ // create a fragment of message
+ msg = &buf_test.msg;
+ msg_set_mme_const_values(msg);
+ bzero(msg->osa, 6);
+ msg->fmi.nf_mi = 4; // Number of fragments for message
+ msg->fmi.fn_mi = 1; // fragment number
+ msg->fmi.fmsn = 32;
+ // add this fragment in the fifo
+ interf_receive(msg);
+ interf_received();
+ cyg_thread_delay(150);
+ interf_msg_purge();
+ return Success;
}
/*
@@ -227,149 +227,148 @@ int interf_msg_purge_test(void)
*/
#define NB_MSG_TEST 9
-int interf_module_test(void)
+int interf_module_test (void)
{
- interf_buffer_t buf[NB_MSG_TEST];
- msg_mme_t *msg[NB_MSG_TEST], *test;
- int i;
-
- for(i=0 ; i<NB_MSG_TEST ; i++)
- {
- msg[i] = &buf[i].msg;
- }
-
- // init all the interf module
- interf_init();
- bzero(&buf, sizeof(buf));
-
- // init the messages for test
- for(i=0 ; i<NB_MSG_TEST ; i++)
- {
- bzero(msg[i]->osa, sizeof(msg[i]->osa));
- msg_set_mme_const_values(msg[i]);
- msg[i]->mm_type = 4; // cc_backup_appoint.req message,to STA
- }
- // create a message of type 9
- msg[1]->mm_type = 9; // cc_link_info.cnf, to STA
-
- // create a 3 parts fragmented message
-
- msg[2]->mm_type = 9; // cc_link_info.cnf, to STA
- msg[2]->fmi.nf_mi = 2;
- msg[2]->fmi.fn_mi = 0;
- msg[2]->fmi.fmsn = 45;
-
- msg[4]->mm_type = 9; // cc_link_info.cnf, to STA
- msg[4]->fmi.nf_mi = 2;
- msg[4]->fmi.fn_mi = 1;
- msg[4]->fmi.fmsn = 45;
-
- msg[7]->mm_type = 9; // cc_link_info.cnf, to STA
- msg[7]->fmi.nf_mi = 2;
- msg[7]->fmi.fn_mi = 2;
- msg[7]->fmi.fmsn = 45;
-
- // receive the message at the STA
- for(i=0 ; i<NB_MSG_TEST ; i++)
- {
- interf_receive(msg[i]);
- }
-
- // simulate the sta event,
- interf_received();
-
- // the msg should now be in the STA fifo, so ask for it
- test = interf_msg_get_last(MSG_STA);
- // check that we have the same msg
- if(test != msg[8]) return Failure;
-
- // the previous msg should be the first part of frag msg
- test = interf_msg_get_previous(MSG_STA);
- if(test != msg[2]) return Failure;
-
- // then we should have the other complete msg
- test = interf_msg_get_previous(MSG_STA);
- if(test != msg[6]) return Failure;
- test = interf_msg_get_previous(MSG_STA);
- if(test != msg[5]) return Failure;
- test = interf_msg_get_previous(MSG_STA);
- if(test != msg[3]) return Failure;
- test = interf_msg_get_previous(MSG_STA);
- if(test != msg[1]) return Failure;
- test = interf_msg_get_previous(MSG_STA);
- if(test != msg[0]) return Failure;
-
- // and here, we are at the end of the fifo
- test = interf_msg_get_previous(MSG_STA);
- if(test != NULL) return Failure;
- // test it once again to discover an assert ...
- test = interf_msg_get_previous(MSG_STA);
- if(test != NULL) return Failure;
-
- // then we try to get a message from it type
- test = interf_msg_get_last_of_type(MSG_STA, 9);
- if(test != msg[2]) return Failure;
-
- // remove one before it, and ask again
- if( ! interf_msg_remove(MSG_STA, msg[3])) return Failure;
- test = interf_msg_get_last_of_type(MSG_STA, 9);
- if(test != msg[2]) return Failure;
-
- // and we ask for the others parts of the message
- test = interf_msg_get_next_part(test);
- if(test != msg[4]) return Failure;
-
- test = interf_msg_get_next_part(test);
- if(test != msg[7]) return Failure;
-
- // there is no more part
- test = interf_msg_get_next_part(test);
- if(test != NULL) return Failure;
-
- // then we try (again) to get a message from it type
- test = interf_msg_get_last_of_type(MSG_STA, 9);
- if(test != msg[2]) return Failure;
- // we ask for previous message of this type
- test = interf_msg_get_previous_of_type(MSG_STA, 9);
- if(test != msg[1]) return Failure;
-
-
- return Success;
-}
+ interf_buffer_t buf[NB_MSG_TEST];
+ msg_mme_t *msg[NB_MSG_TEST], *test;
+ int i;
+
+ for (i=0 ; i<NB_MSG_TEST ; i++)
+ {
+ msg[i] = &buf[i].msg;
+ }
+
+ // init all the interf module
+ interf_init ();
+ bzero (&buf, sizeof(buf));
+
+ // init the messages for test
+ for(i=0 ; i<NB_MSG_TEST ; i++)
+ {
+ bzero(msg[i]->osa, sizeof(msg[i]->osa));
+ msg_set_mme_const_values(msg[i]);
+ msg[i]->mm_type = 4; // cc_backup_appoint.req message,to STA
+ }
+ // create a message of type 9
+ msg[1]->mm_type = 9; // cc_link_info.cnf, to STA
+
+ // create a 3 parts fragmented message
+ msg[2]->mm_type = 9; // cc_link_info.cnf, to STA
+ msg[2]->fmi.nf_mi = 2;
+ msg[2]->fmi.fn_mi = 0;
+ msg[2]->fmi.fmsn = 45;
+ msg[4]->mm_type = 9; // cc_link_info.cnf, to STA
+ msg[4]->fmi.nf_mi = 2;
+ msg[4]->fmi.fn_mi = 1;
+ msg[4]->fmi.fmsn = 45;
+ msg[7]->mm_type = 9; // cc_link_info.cnf, to STA
+ msg[7]->fmi.nf_mi = 2;
+ msg[7]->fmi.fn_mi = 2;
+ msg[7]->fmi.fmsn = 45;
+
+ // receive the message at the STA
+ for(i=0 ; i<NB_MSG_TEST ; i++)
+ {
+ interf_receive(msg[i]);
+ }
+
+ // simulate the sta event,
+ interf_received();
+
+ // the msg should now be in the STA fifo, so ask for it
+ test = interf_msg_get_last(MSG_STA);
+ // check that we have the same msg
+ if(test != msg[8]) return Failure;
+
+ // the previous msg should be the first part of frag msg
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != msg[2]) return Failure;
+
+ // then we should have the other complete msg
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != msg[6]) return Failure;
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != msg[5]) return Failure;
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != msg[3]) return Failure;
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != msg[1]) return Failure;
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != msg[0]) return Failure;
+
+ // and here, we are at the end of the fifo
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != NULL) return Failure;
+ // test it once again to discover an assert ...
+ test = interf_msg_get_previous(MSG_STA);
+ if(test != NULL) return Failure;
+
+ // then we try to get a message from it type
+ test = interf_msg_get_last_of_type(MSG_STA, 9);
+ if(test != msg[2]) return Failure;
+
+ // remove one before it, and ask again
+ if( ! interf_msg_remove(MSG_STA, msg[3])) return Failure;
+ test = interf_msg_get_last_of_type(MSG_STA, 9);
+ if(test != msg[2]) return Failure;
+
+ // and we ask for the others parts of the message
+ test = interf_msg_get_next_part(test);
+ if(test != msg[4]) return Failure;
+
+ test = interf_msg_get_next_part(test);
+ if(test != msg[7]) return Failure;
+
+ // there is no more part
+ test = interf_msg_get_next_part(test);
+ if(test != NULL) return Failure;
+
+ // then we try (again) to get a message from it type
+ test = interf_msg_get_last_of_type(MSG_STA, 9);
+ if(test != msg[2]) return Failure;
+ // we ask for previous message of this type
+ test = interf_msg_get_previous_of_type(MSG_STA, 9);
+ if(test != msg[1]) return Failure;
+
+ return Success;
+}
struct interf_test_t
{
- int(*func)(void);
+ int(*func) (void);
char func_name[30];
};
-
-void interf_test(void)
+
+void interf_test (void)
{
+ bool verbose = false;
unsigned int i;
int res;
- struct interf_test_t my_test[]=
+ struct interf_test_t my_test[]=
+ {
+ { interf_init_test, "interf_init" },
+ { interf_received_frag_test, "interf_received_frag" },
+ { interf_msg_add_test, "interf_msg_add" },
+ { interf_msg_remove_test, "interf_msg_remove" },
+ { interf_send_test, "interf_send" },
+ { interf_received_test, "interf_received" },
+ { interf_release_buf_test, "interf_release_buf" },
+ { interf_msg_purge_test, "interf_msg_purge" },
+ { interf_module_test, "interf : module" }
+ };
+
+ printf ("test du module interf\n");
+ for (i=0; i<COUNT (my_test) ; i++)
{
- {interf_init_test, "interf_init"},
- {interf_received_frag_test, "interf_received_frag"},
- {interf_msg_add_test, "interf_msg_add"},
- {interf_msg_remove_test, "interf_msg_remove"},
- {interf_send_test, "interf_send"},
- {interf_received_test, "interf_received"},
- {interf_release_buf_test, "interf_release_buf"},
- {interf_msg_purge_test, "interf_msg_purge"},
- {interf_module_test, "interf : module"}
- };
-
- printf("test du module interf\n");
- for(i=0 ; i<COUNT(my_test) ; i++)
- {
- res = my_test[i].func();
- printf(" %-50s", my_test[i].func_name);
- if(res == Success) printf("OK\n");
- else printf("FAILED : %i\n", res);
+ res = my_test[i].func ();
+ if(verbose || (res != Success))
+ {
+ printf (" %-50s", my_test[i].func_name);
+ if (res == Success) printf ("OK\n");
+ else printf ("FAILED : %i\n", res);
+ }
}
-
}
diff --git a/cp/test/src/test_msg.c b/cp/test/src/test_msg.c
index ddc5fea167..b3a0205298 100644
--- a/cp/test/src/test_msg.c
+++ b/cp/test/src/test_msg.c
@@ -19,62 +19,65 @@
*/
typedef struct msg_dispatch_test_t
{
- msg_mme_t sample; // message à tester
- int ( * expected_func)(u8 msg[]); // numéro de message attendu
-} msg_dispatch_test_t;
-
-int msg_dispatch_test(void)
+ msg_mme_t sample; // message à tester
+ int ( * expected_func) (u8 msg[]); // numéro de message attendu
+} msg_dispatch_test_t;
+
+int msg_dispatch_test (void)
{
- /*
- unsigned int i;
- msg_dispatch_test_t sample[]=
- {
- {"ODAODAOSAOSAVLANMT1\x08\x00MFM", NULL}, // 0x08 CC_LINK_INFO.REQ
- {"ODAODAOSAOSAVLANMT1\x00\x60MFM", NULL} // 0x6000
- };
-
- for(i=0 ; i < COUNT(sample) ; i++)
- {
- if(msg_dispatch(& sample[i].sample) != sample[i].expected_func) return Failure;
- }
- */
+ /*
+ unsigned int i;
+ msg_dispatch_test_t sample[]=
+ {
+ {"ODAODAOSAOSAVLANMT1\x08\x00MFM", NULL}, // 0x08 CC_LINK_INFO.REQ
+ {"ODAODAOSAOSAVLANMT1\x00\x60MFM", NULL} // 0x6000
+ };
+
+ for(i=0 ; i < COUNT(sample) ; i++)
+ {
+ if(msg_dispatch(& sample[i].sample) != sample[i].expected_func) return Failure;
+ }
+ */
return Success;
}
/*
* test de void msg_xxx_mme_const_values
*/
-int msg_set_mme_const_values_test(void)
+int msg_set_mme_const_values_test (void)
{
- msg_mme_t msg;
- msg_set_mme_const_values(&msg);
- return msg_check_wrong_mme_const_values(& msg);
+ msg_mme_t msg;
+ msg_set_mme_const_values (&msg);
+ return msg_check_wrong_mme_const_values (&msg);
}
-
struct msg_test_t
{
- int(*func)(void);
+ int(*func) (void);
char func_name[30];
};
-void msg_test(void)
+void msg_test (void)
{
+ bool verbose = false;
unsigned int i;
int res;
- struct msg_test_t test[]=
- {
- {msg_dispatch_test, "msg_dispatch"},
- {msg_set_mme_const_values_test,"msg_xx_mme_const_values"}
- };
-
- printf("test du module MSG\n");
- for(i=0 ; i<COUNT(test) ; i++)
+ struct msg_test_t my_test[]=
+ {
+ { msg_dispatch_test, "msg_dispatch" },
+ { msg_set_mme_const_values_test, "msg_xx_mme_const_values" }
+ };
+
+ printf ("test du module MSG\n");
+ for (i=0 ; i<COUNT (my_test) ; i++)
{
- res = test[i].func();
- printf(" %-50s", test[i].func_name);
- if(res == Success) printf("OK\n");
- else printf("FAILED : %i\n", res);
+ res = my_test[i].func ();
+ if(verbose || (res != Success))
+ {
+ printf (" %-50s", my_test[i].func_name);
+ if (res == Success) printf ("OK\n");
+ else printf ("FAILED : %i\n", res);
+ }
}
}
diff --git a/cp/test/src/test_secu.c b/cp/test/src/test_secu.c
index 23a41f31b6..76eebb67df 100644
--- a/cp/test/src/test_secu.c
+++ b/cp/test/src/test_secu.c
@@ -15,77 +15,51 @@
#include "cp/test/test_secu.h"
/*
- * Déclaration des fonctions locales
- */
- int sha2_self_test(void);
- int sha2_self_test_wikipedia(void);
- int CheckPasswordValidity_test(void);
- int pbkdf1_test(void);
- int aes_self_test(void);
- int aes_avs_test(void);
- int secu_init_test(void);
- int secu_hash_test(void);
- int secu_gen_AES_key_test(void);
- int secu_gen_nonce_test(void);
- int secu_protocol_run_test(void);
-
-
-/*
* Test de la fonction sha2
*/
-
+
/*
* FIPS-180-2 test vectors
*/
//static const char sha2_test_str[3][57] =
static char sha2_test_str[3][57] =
-{
- { "abc" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
- { "" }
-};
+ {
+ { "abc" },
+ { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
+ { "" }
+ };
-static const unsigned char sha2_test_sum[6][32] =
-{
- /*
- * SHA-224 test vectors
- */
- { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
- 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
- 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
- 0xE3, 0x6C, 0x9D, 0xA7 },
- { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
- 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
- 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
- 0x52, 0x52, 0x25, 0x25 },
- { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8,
- 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
- 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
- 0x4E, 0xE7, 0xAD, 0x67 },
-
- /*
- * SHA-256 test vectors
- */
- { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
- 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
- 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
- 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
- { 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
- 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
- 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
- 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
- { 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
- 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
- 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
- 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
-};
+static const unsigned char sha2_test_sum[6][32] = {
+/*
+ * SHA-224 test vectors
+ */
+{ 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42, 0xA4, 0x77,
+ 0xBD, 0xA2, 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3,
+ 0xF7, 0xE3, 0x6C, 0x9D, 0xA7 }, { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27,
+ 0x76, 0xCC, 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50, 0xB0,
+ 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19, 0x52, 0x52, 0x25, 0x25 }, {
+ 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8, 0xBB, 0xB4, 0xC1,
+ 0xEA, 0x97, 0x61, 0x8A, 0x4B, 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48,
+ 0xB2, 0xEE, 0x4E, 0xE7, 0xAD, 0x67 },
+
+/*
+ * SHA-256 test vectors
+ */
+{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41, 0x41, 0x40, 0xDE,
+ 0x5D, 0xAE, 0x22, 0x23, 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A,
+ 0x9C, 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD }, { 0x24, 0x8D,
+ 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, 0xE5, 0xC0, 0x26, 0x93, 0x0C,
+ 0x3E, 0x60, 0x39, 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
+ 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }, { 0xCD, 0xC7, 0x6E,
+ 0x5C, 0x99, 0x14, 0xFB, 0x92, 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7,
+ 0x3E, 0x67, 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E, 0x04,
+ 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 } };
/*
* Checkup routine
*/
-int
-sha2_self_test(void)
+int sha2_self_test (void)
{
//int verbose = 0;
int i, j, k;
@@ -93,61 +67,65 @@ sha2_self_test(void)
unsigned char sha2sum[32];
sha2_context ctx;
- memset( buf, 'a', 1000 );
+ memset (buf, 'a', 1000);
- for( i = 0; i < 6; i++ )
+ for (i = 0; i < 6; i++)
{
j = i % 3;
k = i < 3;
- sha2_starts( &ctx, k );
- if( j < 2 ) sha2_update( &ctx, (unsigned char *)sha2_test_str[j], strlen( sha2_test_str[j] ) );
+ sha2_starts ( &ctx, k );
+ if (j < 2)
+ sha2_update ( &ctx, (unsigned char *)sha2_test_str[j],
+ strlen (sha2_test_str[j]) );
else
{
- for( j = 0; j < 1000; j++ ) sha2_update( &ctx, buf, 1000 );
+ for (j = 0; j < 1000; j++)
+ sha2_update ( &ctx, buf, 1000);
}
- sha2_finish( &ctx, sha2sum );
- if( memcmp( sha2sum, sha2_test_sum[i], 32 - k * 4 ) != 0 )
+ sha2_finish ( &ctx, sha2sum );
+ if (memcmp (sha2sum, sha2_test_sum[i], 32 - k * 4) != 0)
{
- return( 1 );
+ return ( 1 );
}
}
- return( 0 );
+ return ( 0 );
}
-
-int
-sha2_self_test_wikipedia(void)
+int sha2_self_test_wikipedia (void)
{
unsigned int i;
int j, errcount = 0;
unsigned char output[SHA256OutputSize];
- unsigned char samples[3][44] =
- {
- {"The quick brown fox jumps over the lazy dog"},
- {"The quick brown fox jumps over the lazy cog"},
- {""}
- };
- unsigned char samplesres[3][SHA256OutputSize] =
- {
- {0xd7, 0xa8, 0xfb, 0xb3, 0x07, 0xd7, 0x80, 0x94 , 0x69, 0xca, 0x9a, 0xbc, 0xb0, 0x08, 0x2e, 0x4f, 0x8d, 0x56, 0x51, 0xe4, 0x6d, 0x3c, 0xdb, 0x76, 0x2d, 0x02, 0xd0, 0xbf ,0x37, 0xc9, 0xe5, 0x92},
- {0xe4, 0xc4, 0xd8, 0xf3 , 0xbf, 0x76, 0xb6, 0x92 , 0xde, 0x79, 0x1a, 0x17 , 0x3e, 0x05, 0x32, 0x11 , 0x50, 0xf7, 0xa3, 0x45 , 0xb4, 0x64, 0x84, 0xfe, 0x42, 0x7f, 0x6a, 0xcc, 0x7e, 0xcc, 0x81, 0xbe},
- {0xe3, 0xb0, 0xc4, 0x42 , 0x98, 0xfc, 0x1c, 0x14 , 0x9a, 0xfb, 0xf4, 0xc8 , 0x99, 0x6f, 0xb9, 0x24 , 0x27, 0xae, 0x41, 0xe4 , 0x64, 0x9b, 0x93, 0x4c , 0xa4, 0x95, 0x99, 0x1b , 0x78, 0x52, 0xb8, 0x55}
- };
-
- for(i=0 ; i<COUNT(samples) ; i++)
+ unsigned char samples[3][44] = { {
+ "The quick brown fox jumps over the lazy dog" }, {
+ "The quick brown fox jumps over the lazy cog" }, { "" } };
+ unsigned char samplesres[3][SHA256OutputSize] = { { 0xd7, 0xa8, 0xfb,
+ 0xb3, 0x07, 0xd7, 0x80, 0x94, 0x69, 0xca, 0x9a, 0xbc, 0xb0, 0x08,
+ 0x2e, 0x4f, 0x8d, 0x56, 0x51, 0xe4, 0x6d, 0x3c, 0xdb, 0x76, 0x2d,
+ 0x02, 0xd0, 0xbf, 0x37, 0xc9, 0xe5, 0x92 }, { 0xe4, 0xc4, 0xd8,
+ 0xf3, 0xbf, 0x76, 0xb6, 0x92, 0xde, 0x79, 0x1a, 0x17, 0x3e, 0x05,
+ 0x32, 0x11, 0x50, 0xf7, 0xa3, 0x45, 0xb4, 0x64, 0x84, 0xfe, 0x42,
+ 0x7f, 0x6a, 0xcc, 0x7e, 0xcc, 0x81, 0xbe }, { 0xe3, 0xb0, 0xc4,
+ 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f,
+ 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4,
+ 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 } };
+
+ for (i=0; i<COUNT (samples) ; i++)
{
- if(i!=2) sha2(samples[i], 43, output, 0);
- else sha2(samples[i], 0, output, 0);
- for(j=0 ; j<32 ; j++)
+ if (i!=2)
+ sha2 (samples[i], 43, output, 0);
+ else
+ sha2 (samples[i], 0, output, 0);
+ for (j=0; j<32; j++)
{
- if(output[j] != samplesres[i][j]) errcount++;
+ if (output[j] != samplesres[i][j])
+ errcount++;
}
}
- return(errcount);
+ return (errcount);
}
-
/*
* Test de la fonction CheckPasswordValidity
*/
@@ -158,23 +136,25 @@ struct pwd_test_t
unsigned int ExpResult;
};
-int CheckPasswordValidity_test(void)
+int CheckPasswordValidity_test (void)
{
- struct T_PwdTest PwdTest[]=
+ struct T_PwdTest PwdTest[]=
{
- {0x32, "abcd efgh ijkl mnop", Failure}, // type de mot de passe incorrect
- {PWD_DPW, "abcd efgh ijkl m", Success}, // le plus petit mot de passe DPW
- {PWD_NPW, "abcd efg", Success}, // le plus petit mot de passe NPW
- {PWD_DPW, "abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd", Success}, // le plus grand mot de passe
- {PWD_DPW, "abcd efgh ijkl ", PWD_WrongSize}, // mot de passe DPW trop petit
- {PWD_NPW, "abcd ef", PWD_WrongSize}, // mot de passe NPW trop petit
- {PWD_DPW, "abcd efgh ijkl m\x1F", PWD_ForbidenChar}, // mot de passe avec caractère incorrect
- {PWD_DPW, "abcd efgh ijkl m\x80", PWD_ForbidenChar} // mot de passe avec caractère incorrect
+ { 0x32, "abcd efgh ijkl mnop", Failure }, // type de mot de passe incorrect
+ { PWD_DPW, "abcd efgh ijkl m", Success }, // le plus petit mot de passe DPW
+ { PWD_NPW, "abcd efg", Success }, // le plus petit mot de passe NPW
+ { PWD_DPW, "abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd", Success }, // le plus grand mot de passe
+ { PWD_DPW, "abcd efgh ijkl ", PWD_WrongSize }, // mot de passe DPW trop petit
+ { PWD_NPW, "abcd ef", PWD_WrongSize }, // mot de passe NPW trop petit
+ { PWD_DPW, "abcd efgh ijkl m\x1F", PWD_ForbidenChar }, // mot de passe avec caractère incorrect
+ { PWD_DPW, "abcd efgh ijkl m\x80", PWD_ForbidenChar } // mot de passe avec caractère incorrect
};
unsigned int i;
- for(i=0 ; i<COUNT(PwdTest) ; i++)
+ for (i=0 ; i<COUNT (PwdTest) ; i++)
{
- if(CheckPasswordValidity(PwdTest[i].PWDType, PwdTest[i].Password) != PwdTest[i].ExpResult) return Failure;
+ if (CheckPasswordValidity (PwdTest[i].PWDType, PwdTest[i].Password)
+ != PwdTest[i].ExpResult)
+ return Failure;
}
return Success;
}
@@ -190,26 +170,24 @@ struct T_pbkdf1Test
u8 ExpOutputKey[OutputKeySize];
};
-int pbkdf1_test(void)
+int pbkdf1_test (void)
{
unsigned int i;
unsigned char OutputKey[OutputKeySize];
- struct T_pbkdf1Test pbkdf1Test[]=
- {
- {
- "hello world how are you?",
- { 0x58, 0x56, 0x52, 0xf6, 0x9c, 0x04, 0xb5, 0x72},
- 999,
- {0x84, 0x33, 0x45, 0x96, 0xab, 0xe5, 0x1e, 0x60, 0x7e, 0x63, 0x8f, 0x4b, 0x2d, 0x8c, 0x51, 0x68}
- }, //
+ struct T_pbkdf1Test pbkdf1Test[]=
+ {
+ { "hello world how are you?",
+ { 0x58, 0x56, 0x52, 0xf6, 0x9c, 0x04, 0xb5, 0x72 },
+ 999,
+ { 0x84, 0x33, 0x45, 0x96, 0xab, 0xe5, 0x1e, 0x60, 0x7e, 0x63, 0x8f, 0x4b, 0x2d, 0x8c, 0x51, 0x68 }
+ } //
};
- for(i=0 ; i<COUNT(pbkdf1Test) ; i++)
+ for(i=0; i<COUNT(pbkdf1Test); i++)
{
pbkdf1(pbkdf1Test[i].Password, pbkdf1Test[i].Salt, pbkdf1Test[i].ItCount, OutputKey);
if(memcmp( OutputKey, pbkdf1Test[i].ExpOutputKey, OutputKeySize)) return Failure;
}
return Success;
-
}
/*
@@ -217,58 +195,52 @@ int pbkdf1_test(void)
*/
/*
- * AES-ECB test vectors (source: NIST, rijndael-vals.zip)
+ * AES-ECB test vectors (source: NIST, rijndael-vals.zip)
*/
/*
* Checkup routine
*/
-int aes_self_test(void)
+int aes_self_test (void)
{
//int verbose = 0;
int i, j, u, v;
aes_context ctx;
unsigned char buf[32];
- uint8 aes_enc_test[3][16] =
- {
- { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73,
- 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F },
- { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11,
- 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 },
- { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D,
- 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
- };
-
- uint8 aes_dec_test[3][16] =
- {
- { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
- 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 },
- { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2,
- 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 },
- { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D,
- 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
- };
-
- for( i = 0; i < 6; i++ )
+ uint8 aes_enc_test[3][16] = { { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D,
+ 0x73, 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, { 0xF3,
+ 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, 0x38, 0xF0, 0x41, 0x56,
+ 0x06, 0x31, 0xB1, 0x14 }, { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0,
+ 0xEE, 0x5D, 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } };
+
+ uint8 aes_dec_test[3][16] = { { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C,
+ 0x58, 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, { 0x48,
+ 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, 0x92, 0x29, 0x31, 0x9C,
+ 0x19, 0xF1, 0x5B, 0xA4 }, { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB,
+ 0x38, 0x2D, 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } };
+
+ for (i = 0; i < 6; i++)
{
u = i >> 1;
- v = i & 1;
+ v = i & 1;
- memset( buf, 0, 32 );
- aes_set_key( &ctx, buf, 128 + u * 64 );
- for( j = 0; j < 10000; j++ )
+ memset (buf, 0, 32);
+ aes_set_key ( &ctx, buf, 128 + u * 64);
+ for (j = 0; j < 10000; j++)
{
- if( v == 0 ) aes_encrypt( &ctx, buf, buf );
- if( v == 1 ) aes_decrypt( &ctx, buf, buf );
+ if (v == 0)
+ aes_encrypt ( &ctx, buf, buf );
+ if (v == 1)
+ aes_decrypt ( &ctx, buf, buf );
}
- if( ( v == 0 && memcmp( buf, aes_enc_test[u], 16 ) != 0 ) ||
- ( v == 1 && memcmp( buf, aes_dec_test[u], 16 ) != 0 ) )
+ if ( (v == 0&& memcmp (buf, aes_enc_test[u], 16) != 0) ||(v == 1
+ && memcmp (buf, aes_dec_test[u], 16) != 0))
{
- return( 1 );
+ return ( 1 );
}
}
- return( 0 );
+ return ( 0 );
}
/*
* test la fonction aes avec d'autres vecteurs de test fournis par le NIS
@@ -283,64 +255,70 @@ struct T_aes_test
unsigned char CypherText[AES_TEXT_SIZE];
};
-int aes_avs_test(void)
+int aes_avs_test (void)
{
aes_context ctx;
unsigned char AESOutput[AES_TEXT_SIZE];
unsigned char tmp[AES_TEXT_SIZE];
unsigned int i;
- int nbfailed = 0;
- struct T_aes_test aes_test[]=
- {
- { // élément de test http://www.faqs.org/rfcs/rfc3602.html case #1
- {0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b, 0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06},
- {0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41},
- {"Single block msg"},
- 16,
- {0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8, 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a}
- },
-
- { // élément de test http://www.faqs.org/rfcs/rfc3602.html case #4
- {0x56, 0xe4, 0x7a, 0x38, 0xc5, 0x59, 0x89, 0x74, 0xbc, 0x46, 0x90, 0x3d, 0xba, 0x29, 0x03, 0x49},
- {0x8c, 0xe8, 0x2e, 0xef, 0xbe, 0xa0, 0xda, 0x3c, 0x44, 0x69, 0x9e, 0xd7, 0xdb, 0x51, 0xb7, 0xd9},
- {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
- 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
- 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf},
- 64,
- {0xc3, 0x0e, 0x32, 0xff, 0xed, 0xc0, 0x77, 0x4e, 0x6a, 0xff, 0x6a, 0xf0, 0x86, 0x9f, 0x71, 0xaa,
- 0x0f, 0x3a, 0xf0, 0x7a, 0x9a, 0x31, 0xa9, 0xc6, 0x84, 0xdb, 0x20, 0x7e, 0xb0, 0xef, 0x8e, 0x4e,
- 0x35, 0x90, 0x7a, 0xa6, 0x32, 0xc3, 0xff, 0xdf, 0x86, 0x8b, 0xb7, 0xb2, 0x9d, 0x3d, 0x46, 0xad,
- 0x83, 0xce, 0x9f, 0x9a, 0x10, 0x2e, 0xe9, 0x9d, 0x49, 0xa5, 0x3e, 0x87, 0xf4, 0xc3, 0xda, 0x55}
- }
-
+ int nbfailed = 0;
+ struct T_aes_test aes_test[]= { { // élément de test http://www.faqs.org/rfcs/rfc3602.html case #1
+ { 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b, 0x51, 0x2e,
+ 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 }, { 0x3d, 0xaf, 0xba,
+ 0x42, 0x9d, 0x9e, 0xb4, 0x30, 0xb4, 0x22, 0xda, 0x80,
+ 0x2c, 0x9f, 0xac, 0x41 }, { "Single block msg" }, 16, {
+ 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8, 0x27,
+ 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a } },
+
+ { // élément de test http://www.faqs.org/rfcs/rfc3602.html case #4
+ { 0x56, 0xe4, 0x7a, 0x38, 0xc5, 0x59, 0x89, 0x74, 0xbc, 0x46,
+ 0x90, 0x3d, 0xba, 0x29, 0x03, 0x49 }, { 0x8c, 0xe8, 0x2e,
+ 0xef, 0xbe, 0xa0, 0xda, 0x3c, 0x44, 0x69, 0x9e, 0xd7,
+ 0xdb, 0x51, 0xb7, 0xd9 }, { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4,
+ 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad,
+ 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+ 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8,
+ 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
+ 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+ 0xdb, 0xdc, 0xdd, 0xde, 0xdf }, 64, { 0xc3, 0x0e, 0x32,
+ 0xff, 0xed, 0xc0, 0x77, 0x4e, 0x6a, 0xff, 0x6a, 0xf0,
+ 0x86, 0x9f, 0x71, 0xaa, 0x0f, 0x3a, 0xf0, 0x7a, 0x9a,
+ 0x31, 0xa9, 0xc6, 0x84, 0xdb, 0x20, 0x7e, 0xb0, 0xef,
+ 0x8e, 0x4e, 0x35, 0x90, 0x7a, 0xa6, 0x32, 0xc3, 0xff,
+ 0xdf, 0x86, 0x8b, 0xb7, 0xb2, 0x9d, 0x3d, 0x46, 0xad,
+ 0x83, 0xce, 0x9f, 0x9a, 0x10, 0x2e, 0xe9, 0x9d, 0x49,
+ 0xa5, 0x3e, 0x87, 0xf4, 0xc3, 0xda, 0x55 } }
+
};
// teste une valeur de clé incorrecte
- aes_set_key( &ctx, aes_test[0].Key, 1);
+ aes_set_key ( &ctx, aes_test[0].Key, 1);
// vérifie le fonctionnement de l'encryptage/décryptage AES
- aes_set_key( &ctx, aes_test[0].Key, AESKeySize*8);
- aes_encrypt( &ctx, aes_test[0].PlainText, AESOutput);
- aes_decrypt( &ctx, AESOutput, tmp);
- if(memcmp(tmp, aes_test[0].PlainText, aes_test[0].len) != 0)
+ aes_set_key ( &ctx, aes_test[0].Key, AESKeySize*8);
+ aes_encrypt ( &ctx, aes_test[0].PlainText, AESOutput);
+ aes_decrypt ( &ctx, AESOutput, tmp);
+ if (memcmp (tmp, aes_test[0].PlainText, aes_test[0].len) != 0)
{
nbfailed++;
}
// test du mode CBC
- for(i=0 ; i<COUNT(aes_test) ; i++)
+ for (i=0; i<COUNT (aes_test) ; i++)
{
- aes_set_key( &ctx, aes_test[i].Key, AESKeySize*8);
- aes_cbc_encrypt(&ctx, aes_test[i].IV, aes_test[i].PlainText, AESOutput, aes_test[i].len);
- if(memcmp(aes_test[i].CypherText, AESOutput, aes_test[i].len) != 0)
+ aes_set_key ( &ctx, aes_test[i].Key, AESKeySize*8);
+ aes_cbc_encrypt (&ctx, aes_test[i].IV, aes_test[i].PlainText,
+ AESOutput, aes_test[i].len);
+ if (memcmp (aes_test[i].CypherText, AESOutput, aes_test[i].len) != 0)
{
nbfailed++;
break;
}
-
- aes_set_key( &ctx, aes_test[i].Key, AESKeySize*8);
- aes_cbc_decrypt(&ctx, aes_test[i].IV, aes_test[i].CypherText, tmp, aes_test[i].len);
- if(memcmp(aes_test[i].PlainText, tmp, aes_test[i].len) != 0)
+
+ aes_set_key ( &ctx, aes_test[i].Key, AESKeySize*8);
+ aes_cbc_decrypt (&ctx, aes_test[i].IV, aes_test[i].CypherText, tmp,
+ aes_test[i].len);
+ if (memcmp (aes_test[i].PlainText, tmp, aes_test[i].len) != 0)
{
nbfailed++;
//break;
@@ -352,128 +330,141 @@ int aes_avs_test(void)
/*
* test de void SECU_Init(T_SEC *p_sec)
*/
-int
-SECU_Init_Test(void)
+int SECU_Init_Test (void)
{
T_SEC sec;
-
- SECU_Init(&sec);
-
+
+ SECU_Init (&sec);
+
return Success;
}
/*
* test de E_SecuErrCode SECU_Hash(E_PWDType PWDType, u8 in[], u8 out[])
*/
-int SECU_Hash_Test(void)
+int SECU_Hash_Test (void)
{
u8 out[AESKeySize];
u8 Pwd[] = "Hello world! what's up ?";
- return SECU_Hash(PWD_DPW, Pwd , out);
+ return SECU_Hash (PWD_DPW, Pwd , out);
}
/*
* test de E_SecuErrCode SECU_GenAESKey(u8 Key[])
*/
-int SECU_GenAESKey_Test(void)
+int SECU_GenAESKey_Test (void)
{
u8 key[AESKeySize];
E_ErrCode r;
unsigned int i;
- u8 ExpRes[] = {0x18, 0x72, 0xce, 0x0, 0x56, 0xcb, 0xf2, 0xdf, 0x33, 0x5a, 0x6, 0x9c, 0x6b, 0x41, 0x2d, 0x26 };
-
- r = SECU_GenAESKey(key);
- if(r != Success) return r;
- for(i=0 ; i<COUNT(ExpRes) ; i++) if(key[i] != ExpRes[i]) return Failure;
+ u8 ExpRes[] = { 0x18, 0x72, 0xce, 0x0, 0x56, 0xcb, 0xf2, 0xdf, 0x33,
+ 0x5a, 0x6, 0x9c, 0x6b, 0x41, 0x2d, 0x26 };
+
+ r = SECU_GenAESKey (key);
+ if (r != Success)
+ return r;
+ for (i=0; i<COUNT (ExpRes) ; i++)
+ if (key[i] != ExpRes[i])
+ return Failure;
return Success;
}
/*
* test de E_SecuErrCode SECU_GenNonce(T_SEC *p_sec)
*/
-int SECU_GenNonce_Test(void)
+int SECU_GenNonce_Test (void)
{
T_SEC sec;
- SECU_Init(&sec);
- SECU_GenNonce(&sec);
- if(sec.ProtocolRun.Nonce == 0xce7218) return Success; // résultat obtenu avec la clé par défaut de SECU_GenAESKey()
- else return Failure;
+ SECU_Init (&sec);
+ SECU_GenNonce (&sec);
+ if (sec.ProtocolRun.Nonce == 0xce7218)
+ return Success; // résultat obtenu avec la clé par défaut de SECU_GenAESKey()
+ else
+ return Failure;
}
-
+
/*
* test des protocol-run
*/
-int SECU_ProtocolRun_Test(void)
+int SECU_ProtocolRun_Test (void)
{
T_SEC STA_sec, CCO_sec;
T_ProtocolRun Msg;
E_PID PID = ProvStaWithNMKuUKE;
-
- SECU_Init(&STA_sec);
- SECU_Init(&CCO_sec);
-
+
+ SECU_Init (&STA_sec);
+ SECU_Init (&CCO_sec);
+
// le CCO démarre un nouveau protocol-run
- if(SECU_StartNewProtocolRun(&CCO_sec, PID) != Success) return Failure;
+ if (SECU_StartNewProtocolRun (&CCO_sec, PID) != Success)
+ return Failure;
// on vérifie que les paramètres sont initialisés correctement
- if(CCO_sec.ProtocolRun.PID != 0x3) return Failure;
+ if (CCO_sec.ProtocolRun.PID != 0x3)
+ return Failure;
//if(CCO_sec.ProtocolRun.PRN != 0xce7218) return Failure; // résultat obtenu avec la clé par défaut de SECU_GenAESKey()
// le CCO demande les paramètres du pr en cours
- if(SECU_GenProtocolRunParam(&CCO_sec, &Msg, false) != Success) return Failure;
+ if (SECU_GenProtocolRunParam (&CCO_sec, &Msg, false) != Success)
+ return Failure;
// la STA reçoit le premier message du pr
- if(SECU_CheckProtocolRunParam(&STA_sec, Msg) != Success) return Failure;
+ if (SECU_CheckProtocolRunParam (&STA_sec, Msg) != Success)
+ return Failure;
// la STA génère un nouveau message
- if(SECU_GenProtocolRunParam(&STA_sec, &Msg, false) != Success) return Failure;
+ if (SECU_GenProtocolRunParam (&STA_sec, &Msg, false) != Success)
+ return Failure;
// et le renvoie au CCO
- if(SECU_CheckProtocolRunParam(&CCO_sec, Msg) != Success) return Failure;
+ if (SECU_CheckProtocolRunParam (&CCO_sec, Msg) != Success)
+ return Failure;
// le CCO refait un message
- if(SECU_GenProtocolRunParam(&CCO_sec, &Msg, false) != Success) return Failure;
+ if (SECU_GenProtocolRunParam (&CCO_sec, &Msg, false) != Success)
+ return Failure;
// et le renvoie à la STA
- if(SECU_CheckProtocolRunParam(&STA_sec, Msg) != Success) return Failure;
+ if (SECU_CheckProtocolRunParam (&STA_sec, Msg) != Success)
+ return Failure;
// la STA génère le dernier message du protocol run
- if(SECU_GenProtocolRunParam(&STA_sec, &Msg, true) != Success) return Failure;
+ if (SECU_GenProtocolRunParam (&STA_sec, &Msg, true) != Success)
+ return Failure;
// et le renvoie au CCO
- if(SECU_CheckProtocolRunParam(&CCO_sec, Msg) != Success) return Failure;
+ if (SECU_CheckProtocolRunParam (&CCO_sec, Msg) != Success)
+ return Failure;
// le CCO ne peut plus renvoyer de messages
- if(SECU_GenProtocolRunParam(&CCO_sec, &Msg, false) != PRN_NotInitialised) return Failure;
-
+ if (SECU_GenProtocolRunParam (&CCO_sec, &Msg, false)
+ != PRN_NotInitialised)
+ return Failure;
+
return Success;
}
-
-
-
-
struct T_SecuTest
{
- int(*func)(void);
+ int(*func) (void);
char FuncName[30];
};
-void SECU_Test(void)
+void SECU_Test (void)
{
unsigned int i;
int res;
- struct T_SecuTest SecuTest[]=
- {
- {sha2_self_test, "sha2 (1)"},
- {sha2_self_test_wikipedia, "sha2 (2)"},
- {CheckPasswordValidity_test,"CheckPasswordValidity"},
- {pbkdf1_test, "pbkdf1"},
- {aes_self_test, "aes (1)"},
- {aes_avs_test, "aes (2)"},
- {SECU_Init_Test, "SECU_Init"},
- {SECU_Hash_Test, "SECU_Hash"},
- {SECU_GenAESKey_Test, "SECU_GenAESKey"},
- {SECU_GenNonce_Test, "SECU_GenNonce"},
- {SECU_ProtocolRun_Test, "SECU_ProtocolRun"}
- };
-
- printf("test du module SECU\n");
- for(i=0 ; i<COUNT(SecuTest) ; i++)
+ struct T_SecuTest SecuTest[]=
+ {
+ { sha2_self_test, "sha2 (1)" },
+ { sha2_self_test_wikipedia, "sha2 (2)" },
+ { CheckPasswordValidity_test, "CheckPasswordValidity" },
+ { pbkdf1_test, "pbkdf1" },
+ { aes_self_test, "aes (1)" },
+ { aes_avs_test, "aes (2)" },
+ { SECU_Init_Test, "SECU_Init" },
+ { SECU_Hash_Test, "SECU_Hash" },
+ { SECU_GenAESKey_Test, "SECU_GenAESKey" },
+ { SECU_GenNonce_Test, "SECU_GenNonce" },
+ { SECU_ProtocolRun_Test, "SECU_ProtocolRun" }
+ };
+
+ printf ("test du module SECU\n");
+ for (i=0; i<COUNT (SecuTest) ; i++)
{
- res = SecuTest[i].func();
- printf(" %-50s", SecuTest[i].FuncName);
- if(res == Success) printf("OK\n");
- else printf("FAILED : %i\n", res);
+ res = SecuTest[i].func ();
+ printf (" %-50s", SecuTest[i].FuncName);
+ if (res == Success) printf ("OK\n");
+ else printf ("FAILED : %i\n", res);
}
}
diff --git a/cp/test/src/test_station.c b/cp/test/src/test_station.c
new file mode 100644
index 0000000000..bd8b0bddc8
--- /dev/null
+++ b/cp/test/src/test_station.c
@@ -0,0 +1,125 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/test/test_station.c
+ * \brief unit tests for station module
+ * \ingroup cp_test
+ */
+
+#include "common/std.h"
+#include "cp/test/inc/test_station.h"
+
+
+#define STA_THREAD_PRIORITY 30
+
+
+static unsigned char station_thread_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+static cyg_handle_t station_thread_handle;
+static cyg_thread station_thread;
+
+
+/*
+ * void station_gen_timed_event(cyg_flag_t *cyg_flag, station_flag_t station_flag, uint event_delay_ms)
+ */
+int station_gen_timed_event_test(void)
+{
+ // we create a local event for the test
+ cyg_flag_t local_flag;
+ cyg_flag_value_t flag_value = 8, flag_return = 0;
+ cyg_tick_count_t cyg_tick_count, cur_time, event_wait_tick;
+ uint event_wait_ms = 200;
+
+ event_wait_tick = interf_ms_to_cyg_tick(event_wait_ms);
+ // init the local event
+ cyg_flag_init(&local_flag);
+ // generated the timed event
+ station_gen_timed_event(&local_flag, flag_value>>1, event_wait_ms/2);
+ station_gen_timed_event(&local_flag, flag_value, event_wait_ms);
+ station_gen_timed_event(&local_flag, flag_value<<1, event_wait_ms/2);
+ // and now wait for the event...
+ cur_time = cyg_current_time();
+ cyg_flag_timed_wait (&local_flag, flag_value, CYG_FLAG_WAITMODE_OR, event_wait_ms*2);
+ if(cyg_current_time() < (cur_time + event_wait_tick) ) return 1;
+ // test if we can delete an event
+ // delete the previous events
+ station_stop_timed_event(&local_flag, flag_value>>1);
+ station_stop_timed_event(&local_flag, flag_value);
+ station_stop_timed_event(&local_flag, flag_value<<1);
+ // generated another the timed event
+ station_gen_timed_event(&local_flag, flag_value, event_wait_ms);
+ // and another one which arrive later
+ station_gen_timed_event(&local_flag, flag_value>>1, 2*event_wait_ms);
+ // delete the first one
+ station_stop_timed_event(&local_flag, flag_value);
+ // wait for it...
+ cyg_tick_count = cyg_current_time();
+ cyg_tick_count += (event_wait_ms * 3);
+ //printf("wait at %i\n", (int)cyg_current_time());
+ flag_return = cyg_flag_timed_wait(&local_flag, 0xFFFFFFFF, CYG_FLAG_WAITMODE_OR, cyg_tick_count);
+ //printf("got event %i at %i\n", (int)flag_return, cyg_current_time());
+ // if we had an event, it's a failure
+ if(flag_return != (flag_value>>1)) return 2;
+
+ cyg_thread_delay (interf_ms_to_cyg_tick (10000));
+
+ return Success;
+}
+
+struct station_test_t
+{
+ int(*func) (void);
+ char func_name[30];
+};
+
+
+static void
+station_thread_launch(cyg_addrword_t data)
+{
+ station_init();
+}
+
+void station_test (void)
+{
+ bool verbose = true;
+ unsigned int i;
+ int res;
+ struct station_test_t my_test[]=
+ {
+ {station_gen_timed_event_test, "station_gen_timed_event"}
+ };
+
+ printf ("test du module station\n");
+ // for the test, we create a thread STA
+ cyg_thread_create(
+ STA_THREAD_PRIORITY,
+ &station_thread_launch,
+ 0,
+ "STA",
+ station_thread_stack,
+ sizeof(station_thread_stack),
+ &station_thread_handle,
+ &station_thread
+ );
+ cyg_thread_resume(station_thread_handle);
+ // wait for the thread to start and init
+ cyg_thread_delay(10);
+ // and now do the unit tests
+ for (i=0 ; i<COUNT (my_test) ; i++)
+ {
+ res = my_test[i].func ();
+ if(verbose || (res != Success))
+ {
+ printf (" %-50s", my_test[i].func_name);
+ if (res == Success) printf ("OK\n");
+ else printf ("FAILED : %i\n", res);
+ }
+ }
+ // end of the test, we destroy the STA thread
+ cyg_thread_kill(station_thread_handle);
+}
+