summaryrefslogtreecommitdiff
path: root/cleopatre/devkit
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit')
-rw-r--r--cleopatre/devkit/doc/cleopatre_managerd_specs.odtbin109329 -> 111056 bytes
-rw-r--r--cleopatre/devkit/doc/cleopatre_mme_specs.odtbin170256 -> 169662 bytes
-rw-r--r--cleopatre/devkit/doc/cleopatre_plcdrv_archi.odtbin139640 -> 146469 bytes
-rw-r--r--cleopatre/devkit/doc/cleopatre_spidapp_specs.odtbin0 -> 108074 bytes
-rw-r--r--cleopatre/devkit/plcd/inc/plcd.h124
-rw-r--r--cleopatre/devkit/plcd/src/event.c372
-rw-r--r--cleopatre/devkit/plcd/src/hpav.c523
-rw-r--r--cleopatre/devkit/plcd/src/plcd.c189
-rw-r--r--cleopatre/devkit/plcd/src/plcd_main.c299
-rw-r--r--cleopatre/devkit/plcd/src/plcd_process.c623
-rw-r--r--cleopatre/devkit/plcd/src/plcd_stack.c953
-rw-r--r--cleopatre/devkit/tests/libspid/ftests/spidlib_ftests.c2
-rw-r--r--cleopatre/devkit/tests/libspid/utests/Makefile1
-rw-r--r--cleopatre/devkit/tests/libspid/utests/inc/config_item_utests.h6
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/config_item_utests.c28
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c48
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/image_utests.c8
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/system_utests.c313
-rw-r--r--cleopatre/devkit/tests/utests_makerules6
19 files changed, 2319 insertions, 1176 deletions
diff --git a/cleopatre/devkit/doc/cleopatre_managerd_specs.odt b/cleopatre/devkit/doc/cleopatre_managerd_specs.odt
index 21fe8c6ebb..58e333bc29 100644
--- a/cleopatre/devkit/doc/cleopatre_managerd_specs.odt
+++ b/cleopatre/devkit/doc/cleopatre_managerd_specs.odt
Binary files differ
diff --git a/cleopatre/devkit/doc/cleopatre_mme_specs.odt b/cleopatre/devkit/doc/cleopatre_mme_specs.odt
index 7c4972e3d6..20779daffd 100644
--- a/cleopatre/devkit/doc/cleopatre_mme_specs.odt
+++ b/cleopatre/devkit/doc/cleopatre_mme_specs.odt
Binary files differ
diff --git a/cleopatre/devkit/doc/cleopatre_plcdrv_archi.odt b/cleopatre/devkit/doc/cleopatre_plcdrv_archi.odt
index 3f8eab66e3..31ff48c70f 100644
--- a/cleopatre/devkit/doc/cleopatre_plcdrv_archi.odt
+++ b/cleopatre/devkit/doc/cleopatre_plcdrv_archi.odt
Binary files differ
diff --git a/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt b/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt
new file mode 100644
index 0000000000..077529b219
--- /dev/null
+++ b/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt
Binary files differ
diff --git a/cleopatre/devkit/plcd/inc/plcd.h b/cleopatre/devkit/plcd/inc/plcd.h
index fbc4ffea3a..727919d177 100644
--- a/cleopatre/devkit/plcd/inc/plcd.h
+++ b/cleopatre/devkit/plcd/inc/plcd.h
@@ -19,8 +19,19 @@
#include <sys/socket.h>
#include <stdint.h>
#include <linux/netlink.h>
+
#include "nvram.h"
+#define PLCD_ASSERT(condition) \
+{ \
+ if (!(condition)) \
+ { \
+ syslog (LOG_ERR, "%s: %d: %s: Assertion '%s' failed.", \
+ __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(condition)); \
+ abort(); \
+ } \
+}
+
#define MME_TYPE_DRV_STA_SET_MAC_ADDR 0xb000
#define MME_TYPE_DRV_STA_SET_CCO_PREF 0xb004
#define MME_TYPE_DRV_STA_SET_WAS_CCO 0xb008
@@ -46,45 +57,77 @@
#define MME_RESULT_SUCCESS 0x00
-#define HFID_LEN 64
-#define EVENT_REFRESH_TIMEOUT_MS 1000
+#define PLCD_EVENT_REFRESH_TIMEOUT_MS 1000
+#define PLCD_INIT_RETRIES 10
-typedef enum {
+typedef enum
+{
MME_DRV_STATUS_ASSOC_UNASSOCIATED = 0,
- MME_DRV_STATUS_ASSOC_ASSOCIATED ,
+ MME_DRV_STATUS_ASSOC_ASSOCIATED,
MME_DRV_STATUS_ASSOC_AUTHENTICATED,
MME_DRV_STATUS_ASSOC_NB
} mme_drv_status_assoc_t;
-typedef enum {
+typedef enum
+{
MME_DRV_STATUS_CCO_STATION = 0,
- MME_DRV_STATUS_CCO_PROXY ,
+ MME_DRV_STATUS_CCO_PROXY,
MME_DRV_STATUS_CCO_MAIN,
MME_DRV_STATUS_CCO_NB
} mme_drv_status_cco_t;
-
-typedef enum {
+typedef enum
+{
MME_DRV_SC_ADD = 0,
MME_DRV_SC_JOIN,
MME_DRV_SC_NB
} mme_drv_sc_t;
-typedef enum {
+typedef enum
+{
MME_DRV_KEY_TYPE_NID = 0,
MME_DRV_KEY_TYPE_SL,
MME_DRV_KEY_TYPE_NB
} mme_drv_key_type_t;
-/** main context of pld daemon */
-typedef struct {
- /** path of hardware info file */
- char *hardware_info_path;
- /** path of HP AV info file */
+typedef enum
+{
+ MME_DRV_KEY_SL_SC = 0,
+ MME_DRV_KEY_SL_HS,
+ MME_DRV_KEY_SL_NB
+} mme_drv_key_sl_t;
+
+static char *mme_drv_status_assoc_table[] =
+{
+ LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED,
+ LIBSPID_HPAV_INFO_VALUE_STATUS_ASSOCIATED,
+ LIBSPID_HPAV_INFO_VALUE_STATUS_AUTHENTICATED,
+ NULL
+};
+
+static char *mme_drv_status_cco_table[] =
+{
+ LIBSPID_HPAV_INFO_VALUE_CCO_STATION,
+ LIBSPID_HPAV_INFO_VALUE_CCO_PROXY,
+ LIBSPID_HPAV_INFO_VALUE_CCO_MAIN,
+ NULL
+};
+
+static char *mme_drv_key_sl_table[] =
+{
+ LIBSPID_HPAV_CONF_VALUE_SL_SC,
+ LIBSPID_HPAV_CONF_VALUE_SL_HS,
+ NULL
+};
+
+/** main context of plc daemon */
+typedef struct
+{
+ /** full path of HPAV info file */
char *hpav_info_path;
- /** path of HP AV config file */
+ /** full path of HPAV config file */
char *hpav_conf_path;
- /** path of interna config file */
+ /** full path of internal config file */
char *internal_conf_path;
/** netlink socket descriptor for PLC driver comm */
int plc_sock;
@@ -92,16 +135,47 @@ typedef struct {
struct sockaddr_nl plcd_addr;
/** NVRAM structure */
spc300_nvram_t *nvram;
- /* PLC stack last status */
- struct {
- unsigned int is_assoc;
- unsigned int is_cco;
- unsigned int is_preferred_cco;
- unsigned int is_backup_cco;
- unsigned int is_sc;
- } status;
+ /** indicates if configuration files have to be saved in flash */
+ libspid_boolean_t is_save_conf_needed;
+ /** indicates if other processes have to be informed about files modifications */
+ libspid_boolean_t is_warn_needed;
+ /* hpav.conf last values */
+ struct
+ {
+ /* CCo preference */
+ libspid_boolean_t is_cco_preferred;
+ /* CCo status at boot */
+ libspid_boolean_t was_cco;
+ /* NMK value */
+ char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN];
+ /* NID value */
+ char nid_str[LIBSPID_HPAV_CONF_NID_STR_LEN];
+ /* SL value */
+ char sl_str[LIBSPID_HPAV_CONF_SL_STR_MAX_LEN];
+ /* user HFID value */
+ char user_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
+ /* AVLN HFID value */
+ char avln_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
+ } hpav_conf;
+ /* hpav.info last values */
+ struct
+ {
+ /* status value */
+ char status[LIBSPID_HPAV_INFO_STATUS_MAX_LEN];
+ /* CCo value */
+ char cco[LIBSPID_HPAV_INFO_CCO_MAX_LEN];
+ /* backup CCo value */
+ libspid_boolean_t is_backup_cco;
+ /* Simple Connect value */
+ libspid_boolean_t is_sc;
+ /* Simple Connect button value */
+ libspid_boolean_t is_sc_button;
+ } hpav_info;
} plcd_ctx_t;
-extern int hpav_send_single_value (const plcd_ctx_t *plcd_ctx, unsigned int mmtype, const void *value, unsigned int length);
+/* Global variable indicating if a SIGHUP signal occurred,
+ * has been caught in plcd signal handler,
+ * and has now to be processed. */
+extern libspid_boolean_t is_process_signal_needed;
#endif /* PLCD_H */
diff --git a/cleopatre/devkit/plcd/src/event.c b/cleopatre/devkit/plcd/src/event.c
deleted file mode 100644
index 20838589ec..0000000000
--- a/cleopatre/devkit/plcd/src/event.c
+++ /dev/null
@@ -1,372 +0,0 @@
-/* SPC300 bundle {{{
- *
- * Copyright (C) 2009 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file devkit/plcd/src/status.c
- * \brief status refresh for PLC daemon
- * \ingroup plcd
- *
- * After starting the PLC firmware, some events occurs reflecting the
- * new status of AV stack.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <syslog.h>
-#include <linux/if_ether.h>
-#include <errno.h>
-#include <assert.h>
-#include <arpa/inet.h>
-#include <sys/select.h>
-#include <sys/time.h>
-#include "libmme.h"
-#include "libspid.h"
-#include "plcd.h"
-
-char *assoc_table[] = {
- LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED,
- LIBSPID_HPAV_INFO_VALUE_STATUS_ASSOCIATED,
- LIBSPID_HPAV_INFO_VALUE_STATUS_AUTHENTICATED,
- NULL
-};
-
-char *cco_table[] = {
- LIBSPID_HPAV_INFO_VALUE_CCO_STATION,
- LIBSPID_HPAV_INFO_VALUE_CCO_PROXY,
- LIBSPID_HPAV_INFO_VALUE_CCO_MAIN,
- NULL
-};
-
-char *sl_table[] = {
- LIBSPID_HPAV_CONF_VALUE_SL_SC,
- LIBSPID_HPAV_CONF_VALUE_SL_HS,
- NULL
-};
-
-char *boolean_table[] = {
- "no",
- "yes",
-};
-
-static void binary_to_string (const unsigned char *binary, int binary_len, char *string)
-{
- int i;
- for(i = 0; i < binary_len; i++)
- {
- sprintf (string + i * 2, "%02x", binary[i]);
- }
-}
-
-int inform_manager (plcd_ctx_t *ctx)
-{
- assert (ctx != NULL);
- return 0;
-}
-
-int check_sc_start (plcd_ctx_t *ctx)
-{
- char buffer_sc_status[16], buffer_sc_button[16];
- char buffer[1024];
- unsigned char sc;
-
- assert (ctx != NULL);
-
- /* get SC button and SC status */
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, buffer_sc_button, sizeof(buffer_sc_button));
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC, buffer_sc_status, sizeof(buffer_sc_status));
- if(LIBSPID_GET_BOOLEAN (buffer_sc_button) && !LIBSPID_GET_BOOLEAN (buffer_sc_status))
- {
- /* start SC process */
- /* check authentication status to know which kind of SC to
- * send */
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, buffer, sizeof(buffer));
- if(!strcmp (buffer, assoc_table[MME_DRV_STATUS_ASSOC_UNASSOCIATED]))
- {
- /* send SC_JOIN because we are unassociated */
- sc = MME_DRV_SC_JOIN;
- }
- else
- {
- /* send SC_ADD because we are associated or authenticated */
- sc = MME_DRV_SC_ADD;
- }
-
- if(hpav_send_single_value (ctx, MME_TYPE_DRV_STA_SC, &sc, 1) >= 0)
- {
- libspid_config_write_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC, boolean_table [LIBSPID_TRUE]);
- syslog (LOG_INFO, "SC started");
- }
- else
- {
- /* error */
- syslog (LOG_WARNING, "failed to start SC (%s)", strerror (errno));
- return -1;
- }
- }
-
- return 0;
-}
-
-int refresh_status (plcd_ctx_t *ctx, mme_ctx_t *status_ctx, int *is_save_conf_needed, int *is_info_manager_needed)
-{
- unsigned int len;
- unsigned char assoc_new, cco_new, cco_preferred_new, cco_backup_new, sc_new;
- //unsigned char assoc_current, cco_new_current, cco_preferred_current, cco_backup_current, sc_current, was_cco_current;
- char buffer[256];
-
- assert (ctx != NULL);
- assert (status_ctx != NULL);
- assert ((MME_TYPE_DRV_STA_STATUS | MME_TYPE_IND) == status_ctx->mmtype);
- assert (is_save_conf_needed != NULL);
- assert (is_info_manager_needed != NULL);
-
- buffer[0] = '\0';
-
- /* check new association status */
- mme_pull (status_ctx, &assoc_new, sizeof(assoc_new), &len);
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, buffer, sizeof(buffer));
- if((assoc_new < MME_DRV_STATUS_ASSOC_NB) && strcmp (buffer, assoc_table[assoc_new]))
- {
- libspid_config_write_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, assoc_table [assoc_new]);
- *is_info_manager_needed = LIBSPID_TRUE;
- }
-
- /* set new cco status */
- mme_pull (status_ctx, &cco_new, sizeof(cco_new), &len);
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_CCO, buffer, sizeof(buffer));
- if((cco_new < MME_DRV_STATUS_CCO_NB) && strcmp (buffer, cco_table[cco_new]))
- {
- libspid_config_write_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_CCO, cco_table [cco_new]);
- *is_info_manager_needed = LIBSPID_TRUE;
- }
-
- /* check if WAS_CCO needs to be updated */
- libspid_config_read_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_WAS_CCO, buffer, sizeof(buffer));
- if((MME_DRV_STATUS_ASSOC_AUTHENTICATED == assoc_new)
- && (((MME_DRV_STATUS_CCO_MAIN == cco_new) && !LIBSPID_GET_BOOLEAN (buffer))
- || ((cco_new != MME_DRV_STATUS_CCO_MAIN) && LIBSPID_GET_BOOLEAN (buffer))))
- {
- /* WAS_CCO update needed */
- libspid_config_write_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_WAS_CCO, MME_DRV_STATUS_CCO_MAIN == cco_new ? boolean_table[LIBSPID_TRUE] : boolean_table[LIBSPID_FALSE]);
- *is_save_conf_needed = LIBSPID_TRUE;
- }
-
- /* check new cco preferred status with current one, and update
- then save it if they are different */
- mme_pull (status_ctx, &cco_preferred_new, sizeof(cco_preferred_new), &len);
- libspid_config_read_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, buffer, sizeof(buffer));
- if((cco_preferred_new <= LIBSPID_TRUE) && (cco_preferred_new != LIBSPID_GET_BOOLEAN (buffer)))
- {
- libspid_config_write_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, boolean_table[cco_preferred_new]);
- *is_save_conf_needed = LIBSPID_TRUE;
- }
-
- /* check cco backup status and update info file if changed */
- mme_pull (status_ctx, &cco_backup_new, sizeof(cco_backup_new), &len);
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, buffer, sizeof(buffer));
- if((cco_backup_new <= LIBSPID_TRUE) && (cco_backup_new != LIBSPID_GET_BOOLEAN (buffer)))
- {
- libspid_config_write_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, boolean_table [cco_backup_new]);
- *is_info_manager_needed = LIBSPID_TRUE;
- }
-
- /* check if SC has changed from yes ---> no */
- mme_pull (status_ctx, &sc_new, sizeof(sc_new), &len);
- libspid_config_read_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC, buffer, sizeof(buffer));
- if((sc_new <= LIBSPID_TRUE) && (sc_new != LIBSPID_GET_BOOLEAN (buffer)))
- {
- /* exit from SC state */
- libspid_config_write_item (ctx->hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC, boolean_table [sc_new]);
- *is_info_manager_needed = LIBSPID_TRUE;
- }
-
- syslog (LOG_INFO, "new status: assoc=%d cco=%d cco_pref=%d cco_backup=%d sc=%d", assoc_new, cco_new, cco_preferred_new, cco_backup_new, sc_new);
-
- return 0;
-}
-
-int refresh_hfid (plcd_ctx_t *ctx, mme_ctx_t *hfid_ctx, int *is_save_conf_needed)
-{
- char buffer[256], hfid[HFID_LEN];
- unsigned int len, is_avln = LIBSPID_FALSE;
- assert (ctx != NULL);
- assert (hfid_ctx != NULL);
- assert (((MME_TYPE_DRV_STA_SET_U_STA_HFID | MME_TYPE_IND) == hfid_ctx->mmtype)
- || ((MME_TYPE_DRV_STA_SET_AVLN_HFID | MME_TYPE_IND) == hfid_ctx->mmtype));
- assert (is_save_conf_needed != NULL);
-
- is_avln = ((MME_TYPE_DRV_STA_SET_AVLN_HFID | MME_TYPE_IND) == hfid_ctx->mmtype);
-
- /* get the HFID value from MME */
- mme_pull (hfid_ctx, hfid, HFID_LEN, &len);
- hfid[HFID_LEN - 1] = '\0';
-
- /* compare to current config value */
- libspid_config_read_item (ctx->hpav_conf_path, is_avln ? LIBSPID_HPAV_CONF_LABEL_AVLN_HFID : LIBSPID_HPAV_CONF_LABEL_USER_HFID, buffer, sizeof(buffer));
- if(strncmp (hfid, buffer, HFID_LEN))
- {
- libspid_config_write_item (ctx->hpav_conf_path, is_avln ? LIBSPID_HPAV_CONF_LABEL_AVLN_HFID : LIBSPID_HPAV_CONF_LABEL_USER_HFID, hfid);
- *is_save_conf_needed = LIBSPID_TRUE;
- }
-
- return 0;
-}
-
-int refresh_key (plcd_ctx_t *ctx, mme_ctx_t *key_ctx, int *is_save_conf_needed)
-{
- unsigned char nmk[16], nid[7], type, sl;
- char nmk_str[64], nid_str[32];
- unsigned int len;
-
- assert (ctx != NULL);
- assert (key_ctx != NULL);
- assert ((MME_TYPE_DRV_STA_SET_KEY | MME_TYPE_IND) == key_ctx->mmtype);
- assert (is_save_conf_needed != NULL);
-
- /* get the new NMK set it to hpav.conf */
- mme_pull (key_ctx, nmk, sizeof(nmk), &len);
- binary_to_string (nmk, sizeof(nmk), nmk_str);
- libspid_config_write_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str);
-
- /* get the message type: NID or SL */
- mme_pull (key_ctx, &type, 1, &len);
- if(type > 0x01)
- type = 0x01;
-
- /* get the NID */
- mme_pull (key_ctx, nid, sizeof(nid), &len);
-
- /* get the SL */
- mme_pull (key_ctx, &sl, sizeof(sl), &len);
-
- /* update config file according to given type */
- if(MME_DRV_KEY_TYPE_NID == type)
- {
- /* NID change */
- binary_to_string (nid, sizeof(nid), nid_str);
- libspid_config_write_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_NID, nid_str);
- }
- else
- {
- /* SL change */
- libspid_config_write_item (ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_SL, sl_table[type]);
- }
-
- *is_save_conf_needed = LIBSPID_TRUE;
-
- return 0;
-}
-
-int event_process (plcd_ctx_t *ctx)
-{
- struct msghdr msg;
- struct nlmsghdr *nlh;
- struct sockaddr_nl kernel_addr;
- struct iovec iov;
- MME_t *mme_hdr;
- fd_set readfds;
- struct timeval timeout;
- int result, msg_len;
- unsigned int result_len;
- mme_ctx_t mme_ctx;
- int is_save_conf_needed = LIBSPID_FALSE, is_info_manager_needed = LIBSPID_FALSE;
- unsigned char mme_buffer[ETH_DATA_LEN];
-
- assert (ctx != NULL);
- FD_ZERO (&readfds);
- FD_SET (ctx->plc_sock, &readfds);
- timeout.tv_sec = EVENT_REFRESH_TIMEOUT_MS / 1000;
- timeout.tv_usec = (EVENT_REFRESH_TIMEOUT_MS % 1000) * 1000;
-
- result = select (ctx->plc_sock + 1, &readfds, NULL, NULL, &timeout);
- if(result < 0)
- {
- /* look for interrupt */
- if(EINTR == errno)
- {
- /* process interrupt */
- }
- else
- {
- syslog (LOG_WARNING, "select failure (errno=%d)", errno);
- return (-1);
- }
- }
- else if (result > 0)
- {
- if (FD_ISSET (ctx->plc_sock, &readfds))
- {
- /* create message from PLC driver netlink */
- nlh=(struct nlmsghdr *)malloc(NLMSG_LENGTH(ETH_DATA_LEN));
- memset(nlh, 0, NLMSG_LENGTH(ETH_DATA_LEN));
- memset(&kernel_addr, 0, sizeof(kernel_addr));
- iov.iov_base = (void *)nlh;
- iov.iov_len = NLMSG_LENGTH(ETH_DATA_LEN);
- msg.msg_name = (void *)&kernel_addr;
- msg.msg_namelen = sizeof(kernel_addr);
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
-
- if((msg_len = recvmsg (ctx->plc_sock, &msg, 0)) < 0)
- {
- syslog (LOG_WARNING, "mme receive error (%d)", errno);
- free (nlh);
- return -1;
- }
- else if(msg_len > 0)
- {
- /* check MMTYPE */
- mme_hdr = (MME_t *)NLMSG_DATA (nlh);
- mme_init (&mme_ctx, mme_hdr->mmtype, mme_buffer, ETH_DATA_LEN);
- mme_put (&mme_ctx, (unsigned char *)NLMSG_DATA (nlh) + sizeof(MME_t), ETH_DATA_LEN - sizeof(MME_t), &result_len);
-
- switch(mme_hdr->mmtype)
- {
- case (MME_TYPE_DRV_STA_STATUS | MME_TYPE_IND):
- /* check DRV_STA_STATUS content and process new
- values */
- refresh_status (ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
- break;
- case (MME_TYPE_DRV_STA_SET_U_STA_HFID | MME_TYPE_IND):
- case (MME_TYPE_DRV_STA_SET_AVLN_HFID | MME_TYPE_IND):
- /* check DRV_STA_SET_*_HFID content and process
- new values */
- refresh_hfid (ctx, &mme_ctx, &is_save_conf_needed);
- break;
- case (MME_TYPE_DRV_STA_SET_KEY | MME_TYPE_IND):
- /* process set key update */
- refresh_key (ctx, &mme_ctx, &is_save_conf_needed);
- break;
- default:
- syslog (LOG_WARNING, "unexpected DRV MME received (%04x)", mme_hdr->mmtype);
- free (nlh);
- return -1;
- }
- }
- free (nlh);
- }
- }
- else {
- /* timeout */
- /* check if we need to start SC process */
- check_sc_start (ctx);
- }
-
- /*check if hpav.conf save is needed */
- if(is_save_conf_needed)
- {
- libspid_system_save_file (ctx->hpav_conf_path);
- }
- /* check if manager daemon needs to be informed */
- if(is_info_manager_needed)
- {
- inform_manager (ctx);
- }
-
- return 0;
-}
diff --git a/cleopatre/devkit/plcd/src/hpav.c b/cleopatre/devkit/plcd/src/hpav.c
deleted file mode 100644
index f54eb7cd59..0000000000
--- a/cleopatre/devkit/plcd/src/hpav.c
+++ /dev/null
@@ -1,523 +0,0 @@
-/* SPC300 project {{{
- *
- * Copyright (C) 2009 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file devkit/plcd/src/hpav.c
- * \brief communication with HP AV stack
- * \ingroup plcd
- *
- * All communication functions with the HP AV stack
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <syslog.h>
-#include <linux/if_ether.h>
-#include <errno.h>
-#include <assert.h>
-#include <arpa/inet.h> /* for htons() */
-#include "libmme.h"
-#include "libspid.h"
-#include "plcd.h"
-
-#ifdef __UTESTS__
- #include "hpav_utests.h"
-#endif
-
-static void log_packet (char *packet, int len)
-{
- int i;
- char trace_buffer[256];
-
- if(len <= 0)
- return;
-
- trace_buffer[0] = '\0';
- for (i = 0; i < len; i++)
- {
- if((packet[i] > 0x20) || (packet[i] < 0x7f))
- sprintf (trace_buffer + strlen (trace_buffer), "%c", packet[i]);
- else
- sprintf (trace_buffer + strlen (trace_buffer), "\\x%02x", packet[i]);
- if(i % 60 == 0)
- {
- syslog (LOG_INFO, trace_buffer);
- trace_buffer[0] = '\0';
- }
- }
- syslog (LOG_INFO, trace_buffer);
-}
-
-static int string_to_binary (const char* string, unsigned char *binary, unsigned int binary_length)
-{
- int i, count = 0;
- char hexa[3];
-
- assert (string != NULL);
- assert (binary != NULL);
-
- for(i = 0; i < binary_length; i++)
- {
- if(strlen (string) < i * 2)
- break;
- memcpy (hexa, string + (i * 2), 2);
- hexa[2] = '\0';
- binary[i] = strtoul (hexa, NULL, 16);
- count++;
- }
- return count;
-}
-
-int hpav_compute_dak (const char *dpw, unsigned char *dak)
-{
- assert (dpw);
- assert (dak);
- libspid_secu_pbkdf1 (dpw, strlen (dpw), LIBSPID_SECU_SALT_TYPE_DAK, LIBSPID_SECU_PBKDF1_ITERATION, dak, LIBSPID_SECU_OUTPUT_KEY_SIZE);
- return 0;
-}
-
-int hpav_send_mme (const plcd_ctx_t *plcd_ctx, mme_ctx_t *request_ctx, mme_ctx_t *confirm_ctx)
-{
- struct sockaddr_nl kernel_addr;
- struct nlmsghdr *nlh;
- int msg_payload_len;
- struct iovec iov;
- struct msghdr msg;
- MME_t *mme_hdr;
- fd_set readfds;
- struct timeval timeout;
- int result;
- unsigned int len;
-
- assert (NULL != plcd_ctx);
- assert (NULL != request_ctx);
- assert (NULL != confirm_ctx);
- assert (MME_STATUS_INIT != request_ctx->status);
- assert (MME_STATUS_INIT != confirm_ctx->status);
- assert (MME_TYPE_REQ == (request_ctx->mmtype & MME_TYPE_MASK));
-
- msg_payload_len = request_ctx->tail - request_ctx->head + sizeof(MME_t);
- assert (ETH_FRAME_LEN >= msg_payload_len);
- mme_get_free_space (confirm_ctx, &len);
- assert (ETH_DATA_LEN <= len);
-
- /* fill the netlink address to send msg */
- memset(&kernel_addr, 0, sizeof(kernel_addr));
- kernel_addr.nl_family = AF_NETLINK;
- kernel_addr.nl_pid = 0; /* For Linux Kernel */
- kernel_addr.nl_groups = 0; /* unicast */
-
- /* create the message */
- nlh=(struct nlmsghdr *)malloc(NLMSG_LENGTH(ETH_FRAME_LEN));
- memset(nlh, 0, NLMSG_LENGTH(ETH_FRAME_LEN));
-
- /* fill the netlink message header */
- nlh->nlmsg_len = NLMSG_LENGTH(ETH_FRAME_LEN);
- nlh->nlmsg_pid = getpid(); /* self pid */
- nlh->nlmsg_flags = 0;
-
- /* fill the MME header */
- mme_hdr = (MME_t *)NLMSG_DATA (nlh);
- memcpy (mme_hdr->mme_dest, plcd_ctx->nvram->plc_address, ETH_ALEN);
- memcpy (mme_hdr->mme_src, plcd_ctx->nvram->plc_address, ETH_ALEN);
- mme_hdr->mtype = htons (MME_TYPE);
- mme_hdr->mmv = MME_VERSION;
- mme_hdr->mmtype = request_ctx->mmtype;
-
- /* fill MME payload */
- memcpy ((unsigned char *)mme_hdr + sizeof(MME_t), request_ctx->buffer + request_ctx->head, request_ctx->tail - request_ctx->head);
-
- /* fill message info */
- memset(&msg, 0, sizeof(msg));
- msg.msg_name = (void *)&kernel_addr;
- msg.msg_namelen = sizeof(kernel_addr);
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- iov.iov_base = (void *)nlh;
- iov.iov_len = NLMSG_LENGTH(msg_payload_len);
-
- if(0 > sendmsg (plcd_ctx->plc_sock, &msg, 0))
- {
- syslog (LOG_WARNING, "sendmsg error (%d), type=%04x", errno, mme_hdr->mmtype);
- free (nlh);
- return -1;
- }
-
- /* prepare the recv message */
- memset(nlh, 0, NLMSG_LENGTH(ETH_FRAME_LEN));
- iov.iov_len = NLMSG_LENGTH(ETH_FRAME_LEN);
-
- /* wait for confirm message */
- timeout.tv_sec = MME_TOUT;
- timeout.tv_usec = 0;
- FD_ZERO(&readfds);
- FD_SET(plcd_ctx->plc_sock, &readfds);
-
- result = select (plcd_ctx->plc_sock + 1, &readfds, NULL, NULL, &timeout);
- if(0 > result)
- {
- /* recv error */
- syslog (LOG_WARNING, "select failed (%d)", errno);
- free (nlh);
- return -1;
- }
- else if(0 < result)
- {
- /* read received */
- if(0 >= recvmsg (plcd_ctx->plc_sock, &msg, 0))
- {
- syslog (LOG_WARNING, "mme confirm error (%d)", errno);
- free (nlh);
- return -1;
- }
- /* check MMTYPE */
- mme_hdr = (MME_t *)NLMSG_DATA (nlh);
-
- if(((request_ctx->mmtype & ~MME_TYPE_MASK) | MME_TYPE_CNF) != mme_hdr->mmtype)
- {
- syslog (LOG_WARNING, "bad msg received, type=%04x", mme_hdr->mmtype);
- free (nlh);
- return -1;
- }
-
- /* transfert to confirm ctx */
- mme_put (confirm_ctx, (unsigned char *)NLMSG_DATA (nlh) + sizeof(MME_t), ETH_DATA_LEN - sizeof(MME_t), &len);
- free (nlh);
- return 0;
- }
-
- /* timeout */
- syslog (LOG_WARNING, "read confirm timeout");
- free (nlh);
- return -1;
-}
-
-int hpav_send_single_value (const plcd_ctx_t *plcd_ctx, unsigned int mmtype, const void *value, unsigned int length)
-{
- unsigned char buffer[ETH_DATA_LEN];
- mme_ctx_t request_ctx, confirm_ctx;
- unsigned char result;
- unsigned int result_len;
-
- assert (NULL != plcd_ctx);
-
- /* init mme */
- mme_init (&request_ctx, mmtype | MME_TYPE_REQ, buffer, ETH_DATA_LEN);
- mme_init (&confirm_ctx, mmtype | MME_TYPE_CNF, buffer, ETH_DATA_LEN);
- if(value != NULL)
- {
- /* put value */
- mme_put (&request_ctx, value, length, &result_len);
- }
- if((0 <= hpav_send_mme (plcd_ctx, &request_ctx, &confirm_ctx))
- && (MME_SUCCESS == mme_pull (&confirm_ctx, &result, sizeof(result), &result_len))
- && (MME_RESULT_SUCCESS == result))
- {
- return 0;
- }
- else
- {
- return -1;
- }
-}
-
-int hpav_send_mac_address (const plcd_ctx_t *plcd_ctx, const unsigned char *mac_addr)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_MAC_ADDR, mac_addr, ETH_ALEN);
-}
-
-int hpav_send_cco_preferred (const plcd_ctx_t *plcd_ctx, const int is_cco_preferred)
-{
- unsigned char value = is_cco_preferred;
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_CCO_PREF, &value, 1);
-}
-
-int hpav_send_was_cco (const plcd_ctx_t *plcd_ctx, const int is_was_cco)
-{
- unsigned char value = is_was_cco;
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_WAS_CCO, &value, 1);
-}
-
-int hpav_send_key (const plcd_ctx_t *plcd_ctx, const unsigned char *nmk, const unsigned char *nid, const char *sl)
-{
- unsigned char value[16 + 9]; /* total message size = size of nmk + size of NID/SL */
- unsigned char *nid_sl = &value[16]; /* pointer to NID/SL part of message */
-
- assert (NULL != plcd_ctx);
- assert (NULL != nmk);
-
- /* put NMK */
- memcpy(value, nmk, 16);
-
- /* select value for NID or SL */
- memset (nid_sl, '\0', 9);
- if(sl != NULL)
- {
- /* put choose sl */
- nid_sl[0] = 0x01;
- if(!strcmp (sl, LIBSPID_HPAV_CONF_VALUE_SL_HS))
- nid_sl[8] = 0x01;
- }
- else
- {
- memcpy (nid_sl + 1, nid, 7);
- }
-
- return hpav_send_single_value( plcd_ctx, MME_TYPE_DRV_STA_SET_KEY, value, sizeof(value) );
-}
-
-int hpav_send_dak (const plcd_ctx_t *plcd_ctx, const unsigned char *dak)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_DAK, dak, LIBSPID_SECU_OUTPUT_KEY_SIZE);
-}
-
-int hpav_send_mfg_hfid (const plcd_ctx_t *plcd_ctx, const char *mfg_hfid)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_M_STA_HFID, mfg_hfid, 64);
-}
-
-int hpav_send_user_hfid (const plcd_ctx_t *plcd_ctx, const char *user_hfid)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_U_STA_HFID, user_hfid, 64);
-}
-
-int hpav_send_avln_hfid (const plcd_ctx_t *plcd_ctx, const char *avln_hfid)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_AVLN_HFID, avln_hfid, 64);
-}
-
-int hpav_send_tonemask (const plcd_ctx_t *plcd_ctx, const unsigned char *tonemask)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_SET_TONEMASK, tonemask, 192);
-}
-
-int hpav_send_internal (const plcd_ctx_t *plcd_ctx)
-{
- char key[LIBSPID_KEY_MAX_LEN + 1], key_previous[LIBSPID_KEY_MAX_LEN + 1];
- char *value[1], line_buffer[LIBSPID_LINE_MAX_LEN];
- char mme_buffer[MME_PAYLOAD_MAX_LEN];
- int elt_number, result;
-
- assert (plcd_ctx != NULL);
-
- mme_buffer[0] = '\0';
- *key = '\0';
-
- elt_number = 1;
- /* get 1st key value */
- if((result = libspid_config_read_line (
- plcd_ctx->internal_conf_path,
- "= \t",
- key,
- &elt_number,
- value,
- line_buffer,
- LIBSPID_LINE_MAX_LEN)
- ) != LIBSPID_SUCCESS)
- {
- if(result != LIBSPID_ERROR_SYSTEM)
- {
- /* internal libspid error */
- syslog (LOG_WARNING, "wrong config format");
- }
- return 0;
- }
-
- /* get all items */
- while(strlen (key) > 0)
- {
- /* save current key */
- strcpy (key_previous, key);
- elt_number = 1;
- /* get key value and next key */
- if((result = libspid_config_read_line (
- plcd_ctx->internal_conf_path,
- "= \t",
- key,
- &elt_number,
- value,
- line_buffer,
- LIBSPID_LINE_MAX_LEN)
- ) != LIBSPID_SUCCESS)
- {
- syslog (LOG_WARNING, "wrong config format: %s", key);
- return 0;
- }
- if(elt_number != 1)
- continue;
- /* check free space */
- if(strlen (mme_buffer) + strlen (key_previous)
- + 1 + strlen (value[0]) >= sizeof(mme_buffer))
- {
- /* not enough free space: send current MME */
- mme_buffer[strlen (mme_buffer) - 1] = '\0';
- if((result = hpav_send_single_value (
- plcd_ctx,
- MME_TYPE_DRV_STA_SET_CONFIG,
- mme_buffer,
- strlen (mme_buffer) + 1)
- ) < 0)
- {
- return result;
- }
- /* reset buffer content */
- mme_buffer[0] = '\0';
- }
- /* push label into buffer */
- strcat (mme_buffer, key_previous);
- strcat (mme_buffer, ":");
- /* push value into buffer */
- strcat (mme_buffer, value[0]);
- strcat (mme_buffer, " ");
- }
- /* replace last space by a NULL char */
- mme_buffer[strlen (mme_buffer) - 1] = '\0';
-
- /* send MME */
- return(hpav_send_single_value (
- plcd_ctx,
- MME_TYPE_DRV_STA_SET_CONFIG,
- mme_buffer,
- strlen (mme_buffer) + 1)
- );
-}
-
-int hpav_send_start (const plcd_ctx_t *plcd_ctx)
-{
- return hpav_send_single_value (plcd_ctx, MME_TYPE_DRV_STA_MAC_START, NULL, 0);
-}
-
-int hpav_init (plcd_ctx_t *plcd_ctx)
-{
- char buffer[1024];
- unsigned char nmk[LIBSPID_SECU_OUTPUT_KEY_SIZE];
- unsigned char nid[7];
- unsigned char dak[LIBSPID_SECU_OUTPUT_KEY_SIZE];
-
- assert (NULL != plcd_ctx);
- assert (NULL != plcd_ctx->nvram);
-
- /* send the MAC address to the AV stack */
- if(0 > hpav_send_mac_address (plcd_ctx, plcd_ctx->nvram->plc_address))
- {
- syslog (LOG_WARNING, "set mac address failed");
- return -1;
- }
-
- /* get the CCO_PREFERRED and send it to AV stack */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, buffer, sizeof(buffer));
- if( 0 > hpav_send_cco_preferred (plcd_ctx, LIBSPID_GET_BOOLEAN (buffer)))
- {
- syslog (LOG_WARNING, "set 'CCO preferred' failed");
- return -1;
- }
-
- /* get the WAS_CCO and send it to AV stack */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_WAS_CCO, buffer , sizeof(buffer));
- if( 0 > hpav_send_was_cco (plcd_ctx, LIBSPID_GET_BOOLEAN (buffer)))
- {
- syslog (LOG_WARNING, "set 'was CCO' failed");
- return -1;
- }
-
- /* get the NMK, and compute it if necessary */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_NMK, buffer , sizeof(buffer));
- if(!strcmp (buffer, LIBSPID_HPAV_CONF_VALUE_NONE))
- {
- syslog (LOG_WARNING, "No NMK found. Use plc application to generate it from NPW");
- return -1;
- }
- else
- {
- /* get NMK in binary format from string */
- string_to_binary (buffer, nmk, 16);
- }
-
- /* get the NID from hpav.conf */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_NID, buffer , sizeof(buffer));
- if(!strcmp (buffer, LIBSPID_HPAV_CONF_VALUE_NONE))
- {
- /* get SL */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_SL, buffer , sizeof(buffer));
- /* send NMK and SL */
- if(0 > hpav_send_key (plcd_ctx, nmk, NULL, buffer))
- {
- syslog (LOG_WARNING, "set key failed");
- return -1;
- }
- }
- else
- {
- /* get NID in binary format */
- string_to_binary (buffer, nid, 7);
- /* send NMK and NID */
- if(0 > hpav_send_key (plcd_ctx, nmk, nid, NULL))
- {
- syslog (LOG_WARNING, "set key failed");
- return -1;
- }
- }
-
- /* compute DAK from DPW */
- hpav_compute_dak (plcd_ctx->nvram->device_password, dak);
- /* send DAK */
- if(0 > hpav_send_dak (plcd_ctx, dak))
- {
- syslog (LOG_WARNING, "set DAK failed");
- return -1;
- }
-
- /* send manufacturer HFID */
- if(0 > hpav_send_mfg_hfid (plcd_ctx, plcd_ctx->nvram->product_name))
- {
- syslog (LOG_WARNING, "set mfg HFID failed");
- return -1;
- }
-
- /* get user HFID from hpav config file end send it */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_USER_HFID, buffer , sizeof(buffer));
- if(0 > hpav_send_user_hfid (plcd_ctx, buffer))
- {
- syslog (LOG_WARNING, "set user HFID failed");
- return -1;
- }
-
- /* get avln HFID from hpav config file end send it */
- libspid_config_read_item (plcd_ctx->hpav_conf_path, LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, buffer , sizeof(buffer));
- if(0 > hpav_send_avln_hfid (plcd_ctx, buffer))
- {
- syslog (LOG_WARNING, "set AVLN HFID failed");
- return -1;
- }
-
- /* send tonemask */
- if(0 > hpav_send_tonemask (plcd_ctx, plcd_ctx->nvram->tonemask))
- {
- syslog (LOG_WARNING, "set tonemask failed");
- return -1;
- }
-
- /* send internals config parameters */
- if(0 > hpav_send_internal (plcd_ctx))
- {
- syslog (LOG_WARNING, "set internal config failed");
- return -1;
- }
-
- /* start the AV stack */
- if(0 > hpav_send_start (plcd_ctx))
- {
- syslog (LOG_WARNING, "start MAC failed");
- return -1;
- }
-
- return 0;
-}
-
-
-
diff --git a/cleopatre/devkit/plcd/src/plcd.c b/cleopatre/devkit/plcd/src/plcd.c
deleted file mode 100644
index cac97ac516..0000000000
--- a/cleopatre/devkit/plcd/src/plcd.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* SPC300 bundle {{{
- *
- * Copyright (C) 2009 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file devkit/plcd/src/plcd.c
- * \brief PLC daemon for AV stack management
- * \ingroup plcd
- *
- * This PLC daemon is responsible for the initialization of
- * the AV stack : start, parameter sending, status watching.
- * It is also responsible for any configuration change from
- * the ethernet / plc side through MME messages.
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-#include <syslog.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <unistd.h> /* for getpid() */
-#include "libmme.h"
-#include "libspid.h"
-#include "plcd.h"
-
-#ifdef __UTESTS__
- #include "plcd_utests.h"
-#endif
-
-static spc300_nvram_t g_nvram;
-
-static void print_usage (const char *cmd)
-{
- fprintf (stderr, "Usage : %s " \
- "[ -h --hw_file hardware_info_file ]" \
- "[ -c --conf_file hpav_conf_file ]" \
- "[ -i --info_file hpav_info_file ]" \
- "[ -v --version show version number ]\n",
- cmd);
-}
-
-static void init_info_file (plcd_ctx_t *ctx)
-{
- FILE *fp;
-
- assert (ctx != NULL);
-
- if((fp = fopen (ctx->hpav_info_path, "w")) != NULL)
- {
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_STATUS, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED);
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_CCO, LIBSPID_HPAV_INFO_VALUE_CCO_STATION);
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, "no");
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_SC, "no");
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, "no");
- fclose (fp);
- }
-}
-
-int plcd_init (plcd_ctx_t *ctx)
-{
- assert(ctx != NULL);
- memset (ctx, '\0', sizeof(plcd_ctx_t));
- ctx->hardware_info_path = LIBSPID_HARDWARE_INFO_PATH;
- ctx->hpav_info_path = LIBSPID_HPAV_INFO_PATH;
- ctx->hpav_conf_path = LIBSPID_HPAV_CONF_PATH;
- ctx->internal_conf_path = LIBSPID_INTERNAL_CONF_PATH;
-
- init_info_file (ctx);
-
- /* open netlink socket */
- if(0 > (ctx->plc_sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_PLC_DRV)))
- {
- perror ("netlink socket open");
- return -1;
- }
- memset(&ctx->plcd_addr, 0, sizeof(ctx->plcd_addr));
- ctx->plcd_addr.nl_family = AF_NETLINK;
- ctx->plcd_addr.nl_pid = getpid(); /* self pid */
- ctx->plcd_addr.nl_groups = 0; /* not in mcast group */
- if (0 > bind(ctx->plc_sock, (struct sockaddr *)&ctx->plcd_addr, sizeof(ctx->plcd_addr)))
- {
- perror("netlink socket bind");
- return -1;
- }
-
- /* get NVRAM data */
- ctx->nvram = &g_nvram;
-#ifdef __UTESTS__
- if(LIBSPID_SUCCESS != utests_libspid_system_get_nvram (ctx->nvram))
-#else
- if(LIBSPID_SUCCESS != libspid_system_get_nvram (ctx->nvram))
-#endif
- {
- perror ("NVRAM content read");
- return -1;
- }
-
- return 0;
-}
-
-void plcd_uninit(plcd_ctx_t *ctx)
-{
- close(ctx->plc_sock);
-}
-
-#ifdef __UTESTS__
- int utests_main (int argc, char **argv)
-#else
- int main (int argc, char **argv)
-#endif
-{
- plcd_ctx_t ctx; /* main context */
- char buffer[1024];
- int c, opt_index = 0;
-
- struct option long_opts[] =
- { { "hw_file", required_argument, NULL, 'h' },
- { "conf_file", required_argument, NULL, 'c' },
- { "info_file", required_argument, NULL, 'i' },
- { "version", no_argument, NULL, 'v' }
- };
-
- /* show PLCD version */
- syslog (LOG_NOTICE, "PLC Daemon (%s) Running\n", VERSION);
-
- /* init context */
- if ( 0 != plcd_init (&ctx) )
- {
- exit(1);
- }
-
- /* open log process */
- openlog (argv[0], 0, LOG_DAEMON);
-
- /*process options */
- while((c = getopt_long_only (argc, argv,
- "h:c:i:v:",
- long_opts, &opt_index)) != -1)
- {
- switch(c)
- {
- case 'h': /* hardware info file */
- ctx.hardware_info_path = optarg;
- break;
- case 'c': /* HP AV config file */
- ctx.hpav_conf_path = optarg;
- break;
- case 'i': /* HP AV info file */
- ctx.hpav_info_path = optarg;
- break;
- case 'v': /* version number */
- fprintf (stdout, "%s\n", VERSION);
- return 0;
- default:
- print_usage (argv[0]);
- return 1;
- }
- }
-
- /* set the current PID to info file */
- sprintf (buffer, "%d", getpid ());
- if(LIBSPID_SUCCESS != libspid_config_write_item (ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_PLCD_PID, buffer))
- {
- syslog (LOG_WARNING, "write pid to %s failed", ctx.hpav_info_path);
- }
-
- /* initialize the AV stack and loopback until successful init */
- //while(0 > hpav_init (&ctx));
- if(hpav_init (&ctx) < 0)
- {
- syslog (LOG_WARNING, "plc init failed\n");
- return 1;
- }
-
- /* now get all events : DRV MMEs from plcdrv or config file
- changes (from managerd) */
- while (1)
- {
- event_process (&ctx);
- }
- //plcd_uninit(&ctx);
-
- return 0;
-}
diff --git a/cleopatre/devkit/plcd/src/plcd_main.c b/cleopatre/devkit/plcd/src/plcd_main.c
new file mode 100644
index 0000000000..38c8fba1f1
--- /dev/null
+++ b/cleopatre/devkit/plcd/src/plcd_main.c
@@ -0,0 +1,299 @@
+/* SPC300 bundle {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/plcd/src/plcd_main.c
+ * \brief PLC daemon for AV / EoC stack management
+ * \ingroup plcd
+ *
+ * This PLC daemon is responsible for the initialization of
+ * the AV / EoC stack: start, parameter sending, status watching.
+ * It is also responsible for any configuration change from
+ * the ethernet / plc sides through MME-s.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <syslog.h>
+#include <sys/types.h>
+#include <unistd.h> /* for getpid() */
+
+#include "libmme.h"
+#include "libspid.h"
+#include "plcd.h"
+
+#ifdef __UTESTS__
+# include "plcd_utests.h"
+#endif /* __UTESTS__ */
+
+
+static spc300_nvram_t g_nvram;
+libspid_boolean_t is_process_signal_needed = LIBSPID_FALSE;
+
+
+/******************************************************************************/
+/* DEBUG FUNCTION */
+/******************************************************************************/
+
+/**
+ * Print help for plcd usage.
+ *
+ * \param cmd command
+ */
+static void
+plcd_print_usage (const char *cmd)
+{
+ fprintf (stderr, "Usage : %s " \
+ "[ -c --conf_file hpav_conf_file ]" \
+ "[ -i --info_file hpav_info_file ]" \
+ "[ -v --version show version number ]\n",
+ cmd);
+}
+
+
+/******************************************************************************/
+/* SIGNAL HANDLER FOR THIS PROCESS */
+/******************************************************************************/
+
+/**
+ * Handle signals reception.
+ *
+ * \param signal_nb signal identifier
+ */
+void
+plcd_signal_handler (int signal_nb)
+{
+ /* check that we received a SIGHUP signal (other signals must be ignored) */
+ if (SIGHUP == signal_nb)
+ {
+ syslog (LOG_DEBUG, "signal handler: SIGHUP");
+ is_process_signal_needed = LIBSPID_TRUE;
+ }
+}
+
+
+/******************************************************************************/
+/* (UN)INITIALIZATION FUNCTIONS */
+/******************************************************************************/
+
+/**
+ * Initialize PLC daemon.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_init (plcd_ctx_t *ctx)
+{
+ char is_cco_preferred_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ char was_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+
+ PLCD_ASSERT (NULL != ctx);
+
+ is_process_signal_needed = LIBSPID_FALSE;
+ memset (ctx, 0, sizeof (plcd_ctx_t));
+ ctx->hpav_info_path = LIBSPID_HPAV_INFO_PATH;
+ ctx->hpav_conf_path = LIBSPID_HPAV_CONF_PATH;
+ ctx->internal_conf_path = LIBSPID_INTERNAL_CONF_PATH;
+
+ /* create an empty hpav.info file for writing default values */
+ if ((LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_STATUS, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED))
+ || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_CCO, LIBSPID_HPAV_INFO_VALUE_CCO_STATION))
+ || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, LIBSPID_VALUE_BOOLEAN_FALSE))
+ || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_SC, LIBSPID_VALUE_BOOLEAN_FALSE))
+ || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, LIBSPID_VALUE_BOOLEAN_FALSE)))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+
+ /* save these values into PLCD context */
+ strcpy (ctx->hpav_info.status, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED);
+ strcpy (ctx->hpav_info.cco, LIBSPID_HPAV_INFO_VALUE_CCO_STATION);
+ ctx->hpav_info.is_backup_cco = LIBSPID_FALSE;
+ ctx->hpav_info.is_sc = LIBSPID_FALSE;
+ ctx->hpav_info.is_sc_button = LIBSPID_FALSE;
+
+ /* open netlink socket */
+ if (0 > (ctx->plc_sock = socket (PF_NETLINK, SOCK_RAW, NETLINK_PLC_DRV)))
+ {
+ syslog (LOG_WARNING, "socket open failed");
+ return -1;
+ }
+ memset (&ctx->plcd_addr, 0, sizeof (ctx->plcd_addr));
+ ctx->plcd_addr.nl_family = AF_NETLINK;
+ ctx->plcd_addr.nl_pid = getpid(); /* self pid */
+ ctx->plcd_addr.nl_groups = 0; /* not in mcast group */
+ if (0 > bind (ctx->plc_sock, (struct sockaddr *) &ctx->plcd_addr,
+ sizeof (ctx->plcd_addr)))
+ {
+ syslog (LOG_WARNING, "socket bind failed");
+ return -1;
+ }
+
+ /* get NVRAM data */
+ ctx->nvram = &g_nvram;
+#ifdef __UTESTS__
+ if (LIBSPID_SUCCESS != utests_libspid_system_get_nvram (ctx->nvram))
+#else
+ if (LIBSPID_SUCCESS != libspid_system_get_nvram (ctx->nvram))
+#endif /* __UTESTS__ */
+ {
+ syslog (LOG_WARNING, "libspid system get nvram failed");
+ return -1;
+ }
+
+ /* read and save hpav.conf file contents */
+ if ((LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, is_cco_preferred_str,
+ LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO, was_cco_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NMK, ctx->hpav_conf.nmk_str,
+ LIBSPID_HPAV_CONF_NMK_STR_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NID, ctx->hpav_conf.nid_str,
+ LIBSPID_HPAV_CONF_NID_STR_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_SL, ctx->hpav_conf.sl_str,
+ LIBSPID_HPAV_CONF_SL_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID, ctx->hpav_conf.user_hfid,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, ctx->hpav_conf.avln_hfid,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN)))
+ {
+ syslog (LOG_WARNING, "libspid config read item failed");
+ return -1;
+ }
+ ctx->hpav_conf.is_cco_preferred = LIBSPID_GET_BOOLEAN (is_cco_preferred_str);
+ ctx->hpav_conf.was_cco = LIBSPID_GET_BOOLEAN (was_cco_str);
+
+ return 0;
+}
+
+/**
+ * Un-initialize PLC daemon.
+ *
+ * \param ctx plcd context
+ */
+void
+plcd_uninit (plcd_ctx_t *ctx)
+{
+ close (ctx->plc_sock);
+}
+
+
+/******************************************************************************/
+/* MAIN FUNCTION */
+/******************************************************************************/
+
+/**
+ * Program entry.
+ *
+ * \param argc number of program arguments
+ * \param argv table of (argc) program arguments
+ * \return EXIT_FAILURE on error, EXIT_SUCCESS otherwise
+ */
+int
+#ifdef __UTESTS__
+utests_main (int argc, char **argv)
+#else
+main (int argc, char **argv)
+#endif /* __UTESTS__ */
+{
+ int c = 0, opt_index = 0, init_nb = 0, init_ret = -1;
+
+ /* main context */
+ plcd_ctx_t ctx;
+
+ /* input program arguments */
+ struct option long_opts[] = {{"conf_file", required_argument, NULL, 'c'},
+ {"info_file", required_argument, NULL, 'i'},
+ {"version", no_argument, NULL, 'v'}};
+
+ /* init context */
+ if (0 > plcd_init (&ctx))
+ {
+ exit (EXIT_FAILURE);
+ }
+
+ /* show PLCD version */
+ syslog (LOG_NOTICE, "PLC Daemon (%s) Running\n", VERSION);
+
+ /* open log process */
+ openlog (argv[0], 0, LOG_DAEMON);
+
+ /* process options */
+ while (-1 != (c = getopt_long_only (argc, argv, "c:i:v:", long_opts,
+ &opt_index)))
+ {
+ switch(c)
+ {
+ case 'c':
+ /* HPAV config file */
+ ctx.hpav_conf_path = optarg;
+ break;
+ case 'i':
+ /* HPAV info file */
+ ctx.hpav_info_path = optarg;
+ break;
+ case 'v':
+ /* version number */
+ fprintf (stdout, "%s\n", VERSION);
+ exit (EXIT_SUCCESS);
+ default:
+ plcd_print_usage (argv[0]);
+ exit (EXIT_SUCCESS);
+ }
+ }
+
+ /* initialize the AV / EoC stack
+ * and loop (PLCD_INIT_RETRIES maximum) until successful init */
+ for (init_nb = 0; init_nb < PLCD_INIT_RETRIES; init_nb++)
+ {
+ if (0 == (init_ret = plcd_stack_init (&ctx)))
+ {
+ break;
+ }
+ }
+ if (0 != init_ret)
+ {
+ syslog (LOG_WARNING, "stack init failed\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* register to hpav.conf and hpav.info files update */
+ if ((LIBSPID_SUCCESS != libspid_system_file_update_register (getpid(),
+ LIBSPID_HPAV_CONF_PATH, plcd_signal_handler))
+ || (LIBSPID_SUCCESS != libspid_system_file_update_register (getpid(),
+ LIBSPID_HPAV_INFO_PATH, plcd_signal_handler)))
+ {
+ exit (EXIT_FAILURE);
+ }
+
+ /* now get all events from plcdrv (i.e. DRV MME-s) */
+ while (1)
+ {
+ if (0 > plcd_stack_event_dispatch (&ctx))
+ {
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ plcd_uninit (&ctx);
+ exit (EXIT_SUCCESS);
+}
diff --git a/cleopatre/devkit/plcd/src/plcd_process.c b/cleopatre/devkit/plcd/src/plcd_process.c
new file mode 100644
index 0000000000..88e3d576a0
--- /dev/null
+++ b/cleopatre/devkit/plcd/src/plcd_process.c
@@ -0,0 +1,623 @@
+/* SPC300 bundle {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/plcd/src/plcd_process.c
+ * \brief processing functions of PLC daemon
+ * \ingroup plcd
+ *
+ * After starting the PLC firmware,
+ * some events occur according to new status of AV / EoC stack,
+ * or user actions.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+#include <linux/if_ether.h>
+#include <errno.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+
+#include "libmme.h"
+#include "libspid.h"
+#include "plcd.h"
+
+
+/******************************************************************************/
+/* PROCESS EVENTS COMING FROM AV / EOC STACK VIA DRV MME */
+/******************************************************************************/
+
+/**
+ * Process reception of a DRV_STA_STATUS.IND MME from AV / EoC stack.
+ *
+ * \param ctx plcd context
+ * \param indication_ctx MME context of DRV_STA_STATUS.IND
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_event_status (plcd_ctx_t *ctx, mme_ctx_t *indication_ctx)
+{
+ unsigned int len = 0;
+ unsigned char rx_status = 0, rx_cco = 0, rx_is_cco_preferred = 0, \
+ rx_is_backup_cco = 0, rx_is_sc = 0;
+ char was_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != indication_ctx);
+ PLCD_ASSERT ((MME_TYPE_DRV_STA_STATUS | MME_TYPE_IND) == indication_ctx->mmtype);
+
+ /* check if status needs to be updated in hpav.info
+ * with received association status value */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_status, sizeof (rx_status),
+ &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (MME_DRV_STATUS_ASSOC_NB > rx_status);
+ if (strcmp (ctx->hpav_info.status, mme_drv_status_assoc_table[rx_status]))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_STATUS, mme_drv_status_assoc_table[rx_status]))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ strcpy (ctx->hpav_info.status, mme_drv_status_assoc_table[rx_status]);
+ ctx->is_warn_needed = LIBSPID_TRUE;
+ }
+
+ /* check if cco needs to be updated in hpav.info
+ * with received cco status value */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_cco, sizeof (rx_cco), &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (MME_DRV_STATUS_CCO_NB > rx_cco);
+ if (strcmp (ctx->hpav_info.cco, mme_drv_status_cco_table[rx_cco]))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_CCO, mme_drv_status_cco_table[rx_cco]))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ strcpy (ctx->hpav_info.cco, mme_drv_status_cco_table[rx_cco]);
+ ctx->is_warn_needed = LIBSPID_TRUE;
+ }
+
+ /* check if WAS_CCO needs to be updated in hpav.conf
+ * depending on received cco value */
+ if ((MME_DRV_STATUS_ASSOC_AUTHENTICATED == rx_status)
+ && (((MME_DRV_STATUS_CCO_MAIN == rx_cco) && !ctx->hpav_conf.was_cco)
+ || ((rx_cco != MME_DRV_STATUS_CCO_MAIN) && ctx->hpav_conf.was_cco)))
+ {
+ strcpy (was_cco_str, MME_DRV_STATUS_CCO_MAIN == rx_cco ? \
+ LIBSPID_VALUE_BOOLEAN_TRUE : LIBSPID_VALUE_BOOLEAN_FALSE);
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO, was_cco_str))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ ctx->hpav_conf.was_cco = LIBSPID_GET_BOOLEAN (was_cco_str);
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+
+ /* check if cco preferred needs to be updated in hpav.conf
+ * with received cco preferred value */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_is_cco_preferred,
+ sizeof (rx_is_cco_preferred), &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (LIBSPID_BOOLEAN_NB > rx_is_cco_preferred);
+ if (rx_is_cco_preferred != ctx->hpav_conf.is_cco_preferred)
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, LIBSPID_TRUE == rx_is_cco_preferred ? \
+ LIBSPID_VALUE_BOOLEAN_TRUE : LIBSPID_VALUE_BOOLEAN_FALSE))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ ctx->hpav_conf.is_cco_preferred = rx_is_cco_preferred;
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+
+ /* check if backup cco needs to be updated in hpav.info
+ * with received backup cco value */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_is_backup_cco,
+ sizeof (rx_is_backup_cco), &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (LIBSPID_BOOLEAN_NB > rx_is_backup_cco);
+ if (rx_is_backup_cco != ctx->hpav_info.is_backup_cco)
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, LIBSPID_TRUE == rx_is_backup_cco ? \
+ LIBSPID_VALUE_BOOLEAN_TRUE : LIBSPID_VALUE_BOOLEAN_FALSE))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ ctx->hpav_info.is_backup_cco = rx_is_backup_cco;
+ ctx->is_warn_needed = LIBSPID_TRUE;
+ }
+
+ /* check if SC has changed from "yes" to "no" in hpav.info */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_is_sc, sizeof (rx_is_sc),
+ &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (LIBSPID_BOOLEAN_NB > rx_is_sc);
+ if (rx_is_sc != ctx->hpav_info.is_sc)
+ {
+ /* exit from SC state */
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_SC, LIBSPID_TRUE == rx_is_sc ? \
+ LIBSPID_VALUE_BOOLEAN_TRUE : LIBSPID_VALUE_BOOLEAN_FALSE))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ ctx->hpav_info.is_sc = rx_is_sc;
+ ctx->is_warn_needed = LIBSPID_TRUE;
+ }
+
+ syslog (LOG_INFO, "stack event status: STATUS=%d CCO=%d BACKUP_CCO=%d SC=%d CCO_PREFERRED=%d WAS_CCO=%d",
+ rx_status, rx_cco, rx_is_backup_cco, rx_is_sc, rx_is_cco_preferred, ctx->hpav_conf.was_cco);
+
+ return 0;
+}
+
+/**
+ * Process reception of a DRV_STA_SET_U_STA_HFID.IND
+ * or DRV_STA_SET_AVLN_HFID.IND MME from AV / EoC stack.
+ *
+ * \param ctx plcd context
+ * \param indication_ctx MME context of DRV_STA_SET_xxx_HFID.IND
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_event_hfid (plcd_ctx_t *ctx, mme_ctx_t *indication_ctx)
+{
+ char rx_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN] = {0};
+ unsigned int len = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != indication_ctx);
+
+ /* get the HFID value from MME */
+ if (MME_SUCCESS != mme_pull (indication_ctx, rx_hfid,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN, &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+
+ /* compare to current config value */
+ if (((MME_TYPE_DRV_STA_SET_U_STA_HFID | MME_TYPE_IND) == \
+ indication_ctx->mmtype)
+ && (memcmp (rx_hfid, ctx->hpav_conf.user_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN)))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID, rx_hfid))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ memcpy (ctx->hpav_conf.user_hfid, rx_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN);
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+ else if (((MME_TYPE_DRV_STA_SET_AVLN_HFID | MME_TYPE_IND) == \
+ indication_ctx->mmtype)
+ && (memcmp (rx_hfid, ctx->hpav_conf.avln_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN)))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, rx_hfid))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ memcpy (ctx->hpav_conf.avln_hfid, rx_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN);
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+ else
+ {
+ syslog (LOG_WARNING, "stack event hfid: unexpected mmtype (%04x)", indication_ctx->mmtype);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * Process reception of a DRV_STA_SET_KEY.IND from AV / EoC stack.
+ *
+ * \param ctx plcd context
+ * \param indication_ctx MME context of DRV_STA_SET_KEY.IND
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_event_key (plcd_ctx_t *ctx, mme_ctx_t *indication_ctx)
+{
+ unsigned char rx_nmk[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0}, rx_type = 0, \
+ rx_nid[LIBSPID_HPAV_CONF_NID_BIN_LEN] = {0}, rx_sl = 0;
+ char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN] = {0}, \
+ nid_str[LIBSPID_HPAV_CONF_NID_STR_LEN] = {0}, \
+ sl_str[LIBSPID_HPAV_CONF_SL_STR_MAX_LEN] = {0};
+ unsigned int len = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != indication_ctx);
+ PLCD_ASSERT ((MME_TYPE_DRV_STA_SET_KEY | MME_TYPE_IND) == indication_ctx->mmtype);
+
+ /* get received NMK */
+ if (MME_SUCCESS != mme_pull (indication_ctx, rx_nmk,
+ LIBSPID_HPAV_CONF_NMK_BIN_LEN, &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+
+ /* get received Type: NID or SL */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_type, sizeof (rx_type), &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (MME_DRV_KEY_TYPE_NB > rx_type);
+
+ /* get received NID */
+ if (MME_SUCCESS != mme_pull (indication_ctx, rx_nid,
+ LIBSPID_HPAV_CONF_NID_BIN_LEN, &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+
+ /* get received SL */
+ if (MME_SUCCESS != mme_pull (indication_ctx, &rx_sl, sizeof (rx_sl), &len))
+ {
+ syslog (LOG_WARNING, "mme pull failed");
+ return -1;
+ }
+ PLCD_ASSERT (MME_DRV_KEY_SL_NB > rx_sl);
+
+ /* convert NMK, NID, SL to string */
+ if ((LIBSPID_SUCCESS != libspid_binary_to_hexstring (rx_nmk,
+ LIBSPID_HPAV_CONF_NMK_BIN_LEN, nmk_str))
+ || (LIBSPID_SUCCESS != libspid_binary_to_hexstring (rx_nid,
+ LIBSPID_HPAV_CONF_NID_BIN_LEN, nid_str)))
+ {
+ syslog (LOG_WARNING, "libspid binary to string failed");
+ return -1;
+ }
+ strcpy (sl_str, mme_drv_key_sl_table[rx_sl]);
+
+ /* update config file according to Type */
+ if (memcmp (nmk_str, ctx->hpav_conf.nmk_str, LIBSPID_HPAV_CONF_NMK_STR_LEN))
+ {
+ /* NMK change => set it in hpav.conf */
+ syslog (LOG_DEBUG, "stack event key: nmk update");
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str))
+ {
+ syslog (LOG_WARNING, "libspid config write failed");
+ return -1;
+ }
+
+ /* save NMK */
+ memcpy (ctx->hpav_conf.nmk_str, nmk_str, LIBSPID_HPAV_CONF_NMK_STR_LEN);
+
+ /* hpav.conf save is needed */
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+ if (MME_DRV_KEY_TYPE_NID == rx_type)
+ {
+ syslog (LOG_DEBUG, "stack event key: rx type is nid");
+ if (memcmp (nid_str, ctx->hpav_conf.nid_str, LIBSPID_HPAV_CONF_NID_STR_LEN))
+ {
+ /* NID change => set it in hpav.conf */
+ syslog (LOG_DEBUG, "stack event key: nid update");
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NID, nid_str))
+ {
+ syslog (LOG_WARNING, "libspid config write failed");
+ return -1;
+ }
+
+ /* save NID */
+ memcpy (ctx->hpav_conf.nid_str, nid_str, LIBSPID_HPAV_CONF_NID_STR_LEN);
+
+ /* hpav.conf save is needed */
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+ }
+ else
+ {
+ syslog (LOG_DEBUG, "stack event key: rx type is sl");
+ if (strcmp (sl_str, ctx->hpav_conf.sl_str))
+ {
+ /* SL change and NID reset to none => set them in hpav.conf */
+ syslog (LOG_DEBUG, "stack event key: sl update and nid reset");
+ if ((LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_SL, sl_str))
+ || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NID, LIBSPID_VALUE_NONE)))
+ {
+ syslog (LOG_WARNING, "libspid config write failed");
+ return -1;
+ }
+
+ /* save SL and NID */
+ strcpy (ctx->hpav_conf.sl_str, sl_str);
+ memcpy (ctx->hpav_conf.nid_str, nid_str, LIBSPID_HPAV_CONF_NID_STR_LEN);
+
+ /* hpav.conf save is needed */
+ ctx->is_save_conf_needed = LIBSPID_TRUE;
+ }
+ }
+
+ return 0;
+}
+
+
+/******************************************************************************/
+/* PROCESS EVENTS COMING FROM A USER ACTION */
+/******************************************************************************/
+
+/**
+ * Process a modification of NMK, NID or SL in hpav.conf file,
+ * following a user action such as NPW update via spidapp.
+ *
+ * \param ctx plcd context
+ * \param nmk_str the new NMK
+ * \param nid_str the new NID
+ * \param sl_str the new SL
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_handle_user_key (plcd_ctx_t *ctx, const char *nmk_str, const char *nid_str,
+ const char *sl_str)
+{
+ unsigned char tx_nmk[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0}, tx_type = 0, \
+ tx_nid[LIBSPID_HPAV_CONF_NID_BIN_LEN] = {0}, tx_sl = 0;
+ mme_ctx_t request_ctx, confirm_ctx, indication_ctx;
+ unsigned char result = 0;
+ unsigned int result_len = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != nmk_str);
+ PLCD_ASSERT (NULL != nid_str);
+ PLCD_ASSERT (NULL != sl_str);
+
+ if (0 > plcd_stack_set_key (ctx, nmk_str, nid_str, sl_str))
+ {
+ syslog (LOG_WARNING, "stack set key failed");
+ return -1;
+ }
+
+ /* save NMK, NID, SL */
+ memcpy (ctx->hpav_conf.nmk_str, nmk_str, LIBSPID_HPAV_CONF_NMK_STR_LEN);
+ memcpy (ctx->hpav_conf.nid_str, nid_str, LIBSPID_HPAV_CONF_NID_STR_LEN);
+ strcpy (ctx->hpav_conf.sl_str, sl_str);
+
+ return 0;
+}
+
+/**
+ * Process a modification of SC_BUTTON in hpav.info file,
+ * following a user action such as pressing the SC button.
+ *
+ * \param ctx plcd context
+ * \param status the new association status
+ * \param is_sc the new SC status
+ * \param is_sc_button the new SC button status
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_handle_user_sc (plcd_ctx_t *ctx, const char *status,
+ libspid_boolean_t is_sc, libspid_boolean_t is_sc_button)
+{
+ unsigned char sc = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != status);
+
+ /* check SC and SC button */
+ if ((LIBSPID_TRUE == is_sc_button) && (LIBSPID_FALSE == is_sc))
+ {
+ /* start SC process */
+ /* check authentication status to know which kind of SC to send */
+ if (!strcmp (status, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED))
+ {
+ /* send SC_JOIN because we are unassociated */
+ sc = MME_DRV_SC_JOIN;
+ }
+ else
+ {
+ /* send SC_ADD because we are associated or authenticated */
+ sc = MME_DRV_SC_ADD;
+ }
+
+ if (0 > plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SC, &sc, sizeof (unsigned char)))
+ {
+ syslog (LOG_WARNING, "send recv single value failed (errno = %s)",
+ strerror (errno));
+ return -1;
+ }
+
+ if (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_SC, LIBSPID_VALUE_BOOLEAN_TRUE))
+ {
+ syslog (LOG_WARNING, "libspid config write item failed");
+ return -1;
+ }
+ /* save this value into PLCD context */
+ ctx->hpav_info.is_sc = LIBSPID_TRUE;
+ ctx->is_warn_needed = LIBSPID_TRUE;
+ syslog (LOG_INFO, "handle user sc: sc started");
+ }
+
+ /* save status and SC button into PLCD context */
+ strcpy (ctx->hpav_info.status, status);
+ ctx->hpav_info.is_sc_button = is_sc_button;
+
+ return 0;
+}
+
+
+/******************************************************************************/
+/* HANDLE SIGNAL RECEIVED AFTER A FILE MODIFICATION */
+/******************************************************************************/
+
+/**
+ * This function is called after reception of a SIGHUP by PLCD signal handler.
+ * Check which information has changed in which file,
+ * and depending on this information, call the appropriate processing function.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_process_signal (plcd_ctx_t *ctx)
+{
+ /* hpav.conf */
+ char is_cco_preferred_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ char was_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN] = {0};
+ char nid_str[LIBSPID_HPAV_CONF_NID_STR_LEN] = {0};
+ char sl_str[LIBSPID_HPAV_CONF_SL_STR_MAX_LEN] = {0};
+ char user_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN] = {0};
+ char avln_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN] = {0};
+
+ /* hpav.info */
+ char status[LIBSPID_HPAV_INFO_STATUS_MAX_LEN];
+ char cco[LIBSPID_HPAV_INFO_CCO_MAX_LEN];
+ char is_backup_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ char is_sc_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ char is_sc_button_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+
+ PLCD_ASSERT (NULL != ctx);
+
+ /* read hpav.conf file contents */
+ if ((LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, is_cco_preferred_str,
+ LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO, was_cco_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str,
+ LIBSPID_HPAV_CONF_NMK_STR_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NID, nid_str,
+ LIBSPID_HPAV_CONF_NID_STR_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_SL, sl_str, LIBSPID_HPAV_CONF_SL_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID, user_hfid,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, avln_hfid,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN)))
+ {
+ syslog (LOG_WARNING, "libspid config read item failed");
+ return;
+ }
+
+ /* check which information has changed in which file */
+
+ if (LIBSPID_GET_BOOLEAN (is_cco_preferred_str) != ctx->hpav_conf.is_cco_preferred)
+ {
+ /* CCO_PREFERRED => send DRV_STA_SET_CCO_PREF? */
+ }
+
+ if (LIBSPID_GET_BOOLEAN (was_cco_str) != ctx->hpav_conf.was_cco)
+ {
+ /* WAS_CCO => send DRV_STA_SET_WAS_CCO? */
+ }
+
+ /* check NMK, NID, SL changes */
+ /* check if we need to update NMK/NID/SL */
+ if (memcmp (nmk_str, ctx->hpav_conf.nmk_str, LIBSPID_HPAV_CONF_NMK_STR_LEN)
+ || memcmp (nid_str, ctx->hpav_conf.nid_str, LIBSPID_HPAV_CONF_NID_STR_LEN)
+ || strcmp (sl_str, ctx->hpav_conf.sl_str))
+ {
+ if (0 > plcd_handle_user_key (ctx, nmk_str, nid_str, sl_str))
+ {
+ syslog (LOG_WARNING, "handle user key failed");
+ return -1;
+ }
+ }
+
+ if (memcmp (user_hfid, ctx->hpav_conf.user_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN))
+ {
+ /* USER_HFID => send DRV_STA_SET_U_STA_HFID? */
+ }
+
+ if (memcmp (user_hfid, ctx->hpav_conf.user_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN))
+ {
+ /* AVLN_HFID => send DRV_STA_SET_AVLN_HFID? */
+ }
+
+ /* read hpav.info file contents */
+ if ((LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_STATUS, status,
+ LIBSPID_HPAV_INFO_STATUS_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_CCO, cco,
+ LIBSPID_HPAV_INFO_CCO_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, is_backup_cco_str,
+ LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_SC, is_sc_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_info_path,
+ LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, is_sc_button_str, LIBSPID_BOOLEAN_STR_MAX_LEN)))
+ {
+ syslog (LOG_WARNING, "libspid config read item failed");
+ return;
+ }
+
+ if (strcmp (status, ctx->hpav_info.status)
+ || strcmp (cco, ctx->hpav_info.cco)
+ || (LIBSPID_GET_BOOLEAN (is_backup_cco_str) != ctx->hpav_info.is_backup_cco)
+ || (LIBSPID_GET_BOOLEAN (is_sc_str) != ctx->hpav_info.is_sc))
+ {
+ /* raise an error: cannot happen, this information is modified only by PLC daemon */
+ syslog (LOG_ERR, "hpav.info has been modified by a non-allowed application or user");
+ }
+
+ /* check if we need to start SC process */
+ if (LIBSPID_GET_BOOLEAN (is_sc_button_str) != ctx->hpav_info.is_sc_button)
+ {
+ /* can start “Simple Connect” procedure */
+ if (0 > plcd_handle_user_sc (ctx, status, LIBSPID_GET_BOOLEAN (is_sc_str),
+ LIBSPID_GET_BOOLEAN (is_sc_button_str)))
+ {
+ syslog (LOG_WARNING, "handle user sc failed");
+ return -1;
+ }
+ }
+}
diff --git a/cleopatre/devkit/plcd/src/plcd_stack.c b/cleopatre/devkit/plcd/src/plcd_stack.c
new file mode 100644
index 0000000000..99a333f93c
--- /dev/null
+++ b/cleopatre/devkit/plcd/src/plcd_stack.c
@@ -0,0 +1,953 @@
+/* SPC300 bundle {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/plcd/src/plcd_stack.c
+ * \brief communication with AV / EoC stack
+ * \ingroup plcd
+ *
+ * Initialization of the AV / EoC stack,
+ * and all communication functions with the AV / EoC stack.
+ *
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <syslog.h>
+#include <linux/if_ether.h>
+#include <errno.h>
+#include <arpa/inet.h> /* for htons() */
+
+#include "libmme.h"
+#include "libspid.h"
+#include "plcd.h"
+
+#ifdef __UTESTS__
+# include "hpav_utests.h"
+#endif
+
+
+/******************************************************************************/
+/* DEBUG FUNCTION */
+/******************************************************************************/
+
+/**
+ * Log packet contents.
+ *
+ * \param packet packet to log
+ * \param len length of packet to log
+ */
+static void
+plcd_log_packet (const char *packet, int len)
+{
+ int i = 0;
+ char trace_buffer[256] = {0};
+
+ PLCD_ASSERT (NULL != packet);
+
+ if (0 >= len)
+ {
+ return;
+ }
+
+ trace_buffer[0] = '\0';
+ for (i = 0; i < len; i++)
+ {
+ if ((0x20 < packet[i]) || (0x7f > packet[i]))
+ {
+ sprintf (trace_buffer + strlen (trace_buffer), "%c", packet[i]);
+ }
+ else
+ {
+ sprintf (trace_buffer + strlen (trace_buffer), "\\x%02x", packet[i]);
+ }
+ if (0 == i % 60)
+ {
+ syslog (LOG_INFO, trace_buffer);
+ trace_buffer[0] = '\0';
+ }
+ }
+ syslog (LOG_INFO, trace_buffer);
+}
+
+
+/******************************************************************************/
+/* DISPATCH EVENTS COMING FROM AV / EOC STACK VIA DRV MME */
+/******************************************************************************/
+
+/**
+ * Receive DRV MME-s from PLC driver,
+ * i.e. events coming from AV / EoC stack, and to dispatch them.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_event_dispatch (plcd_ctx_t *ctx)
+{
+ struct msghdr msg;
+ struct nlmsghdr *nlh = NULL;
+ struct sockaddr_nl kernel_addr;
+ struct iovec iov;
+ MME_t *mme_hdr = NULL;
+ fd_set readfds;
+ struct timeval timeout;
+ int result = 0, msg_len = 0;
+ unsigned int result_len = 0;
+ mme_ctx_t mme_ctx;
+ int is_save_conf_needed = LIBSPID_FALSE, is_info_manager_needed = LIBSPID_FALSE;
+ unsigned char mme_buffer[ETH_DATA_LEN] = {0};
+
+ PLCD_ASSERT (NULL != ctx);
+ FD_ZERO (&readfds);
+ FD_SET (ctx->plc_sock, &readfds);
+ timeout.tv_sec = PLCD_EVENT_REFRESH_TIMEOUT_MS / 1000;
+ timeout.tv_usec = (PLCD_EVENT_REFRESH_TIMEOUT_MS % 1000) * 1000;
+
+ /* select() on the netlink socket to poll received MME-s from PLC driver */
+ result = select (ctx->plc_sock + 1, &readfds, NULL, NULL, &timeout);
+ if (0 > result)
+ {
+ /* look for interrupt */
+ if (EINTR == errno)
+ {
+ /* reset errno */
+ errno = 0;
+ /* process interrupt */
+ }
+ else
+ {
+ syslog (LOG_WARNING, "select failed (errno = %d)", errno);
+ return -1;
+ }
+ }
+ else if (0 < result)
+ {
+ if (FD_ISSET (ctx->plc_sock, &readfds))
+ {
+ /* create message from PLC driver netlink */
+ nlh = (struct nlmsghdr *) malloc (NLMSG_LENGTH (ETH_DATA_LEN));
+ memset (nlh, 0, NLMSG_LENGTH(ETH_DATA_LEN));
+ memset (&kernel_addr, 0, sizeof (kernel_addr));
+ iov.iov_base = (void *) nlh;
+ iov.iov_len = NLMSG_LENGTH (ETH_DATA_LEN);
+ msg.msg_name = (void *) &kernel_addr;
+ msg.msg_namelen = sizeof (kernel_addr);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ if (0 > (msg_len = recvmsg (ctx->plc_sock, &msg, 0)))
+ {
+ syslog (LOG_WARNING, "recvmsg failed (errno = %d)", errno);
+ free (nlh);
+ return -1;
+ }
+ else if (msg_len > 0)
+ {
+ /* check MMTYPE */
+ mme_hdr = (MME_t *) NLMSG_DATA (nlh);
+ if ((MME_SUCCESS != mme_init (&mme_ctx, mme_hdr->mmtype, mme_buffer,
+ ETH_DATA_LEN))
+ || (MME_SUCCESS != mme_put (&mme_ctx,
+ (unsigned char *) NLMSG_DATA (nlh) + sizeof (MME_t),
+ ETH_DATA_LEN - sizeof (MME_t), &result_len)))
+ {
+ syslog (LOG_WARNING, "mme init / put failed");
+ free (nlh);
+ return -1;
+ }
+
+ /* then, depending on MMTYPE of the received MME,
+ * it calls different processing routines */
+ switch (mme_hdr->mmtype)
+ {
+ case (MME_TYPE_DRV_STA_STATUS | MME_TYPE_IND):
+ /* check DRV_STA_STATUS.IND contents and process new values */
+ if (0 > plcd_stack_event_status (ctx, &mme_ctx))
+ {
+ syslog (LOG_WARNING, "stack event status failed");
+ free (nlh);
+ return -1;
+ }
+ break;
+ case (MME_TYPE_DRV_STA_SET_U_STA_HFID | MME_TYPE_IND):
+ case (MME_TYPE_DRV_STA_SET_AVLN_HFID | MME_TYPE_IND):
+ /* check DRV_STA_SET_*_HFID.IND contents and process new values */
+ if (0 > plcd_stack_event_hfid (ctx, &mme_ctx))
+ {
+ syslog (LOG_WARNING, "stack event hfid failed");
+ free (nlh);
+ return -1;
+ }
+ break;
+ case (MME_TYPE_DRV_STA_SET_KEY | MME_TYPE_IND):
+ /* DRV_STA_SET_KEY.IND => process set key update */
+ if (0 > plcd_stack_event_key (ctx, &mme_ctx))
+ {
+ syslog (LOG_WARNING, "stack event key failed");
+ free (nlh);
+ return -1;
+ }
+ break;
+ default:
+ /* other received MME types generate an error */
+ syslog (LOG_WARNING, "stack event dispatch: unexpected mmtype (%04x)",
+ mme_hdr->mmtype);
+ free (nlh);
+ return -1;
+ }
+ }
+ free (nlh);
+ }
+ }
+ else
+ {
+ /* timeout */
+ }
+
+ if (is_process_signal_needed)
+ {
+ /* now handle all config / info files changes (from spidapp / managerd) */
+ plcd_process_signal (ctx);
+ is_process_signal_needed = LIBSPID_FALSE;
+ }
+
+ /* After processing, check if some other actions have to be performed.
+ * These actions can be:
+ * - save modified configuration files into flash;
+ * - inform other processes about files modifications. */
+
+ /* check if hpav.conf save is needed */
+ if (ctx->is_save_conf_needed)
+ {
+ if (LIBSPID_SUCCESS != libspid_system_save_file (ctx->hpav_conf_path))
+ {
+ syslog (LOG_WARNING, "libspid system save file failed");
+ return -1;
+ }
+ ctx->is_save_conf_needed = LIBSPID_FALSE;
+
+ /* moreover, inform other processes about hpav.conf modification */
+ if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(),
+ ctx->hpav_conf_path))
+ {
+ syslog (LOG_WARNING, "libspid system file update warn failed");
+ return -1;
+ }
+ }
+ /* check if manager daemon needs to be informed */
+ if (ctx->is_warn_needed)
+ {
+ if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(),
+ ctx->hpav_info_path))
+ {
+ syslog (LOG_WARNING, "libspid system file update warn failed");
+ return -1;
+ }
+ ctx->is_warn_needed = LIBSPID_FALSE;
+ }
+
+ return 0;
+}
+
+
+/******************************************************************************/
+/* GENERIC FUNCTIONS TO SEND AND RECEIVE DRV MME */
+/******************************************************************************/
+
+/**
+ * Transmit a DRV MME to PLC driver.
+ * Send the given MME and,
+ * depending on given confirmation and indication contexts,
+ * wait - or not (if they are NULL) - for corresponding .CNF / .IND DRV MME-s.
+ *
+ * \param ctx plcd context
+ * \param request_ctx mme context for .REQ
+ * \param confirm_ctx mme context for .CNF
+ * \param indication_ctx mme context for .IND
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_send_recv_drv_mme (const plcd_ctx_t *ctx, const mme_ctx_t *request_ctx,
+ mme_ctx_t *confirm_ctx, mme_ctx_t *indication_ctx)
+{
+ struct sockaddr_nl kernel_addr;
+ struct nlmsghdr *nlh = NULL;
+ int msg_payload_len = 0;
+ struct iovec iov;
+ struct msghdr msg;
+ MME_t *mme_hdr = NULL;
+ fd_set readfds;
+ struct timeval timeout;
+ int result = 0;
+ unsigned int cnf_len = 0, ind_len = 0;
+ int recv_mme = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != request_ctx);
+ PLCD_ASSERT (MME_STATUS_INIT != request_ctx->status);
+ PLCD_ASSERT (MME_TYPE_REQ == (request_ctx->mmtype & MME_TYPE_MASK));
+
+ /* if confirm ctx is not NULL, it means that we expect to receive a .CNF,
+ * after having sent the .REQ */
+ if (NULL != confirm_ctx)
+ {
+ PLCD_ASSERT (MME_STATUS_INIT != confirm_ctx->status);
+ mme_get_free_space (confirm_ctx, &cnf_len);
+ PLCD_ASSERT (ETH_DATA_LEN <= cnf_len);
+ recv_mme++;
+ }
+ /* if indication ctx is not NULL, it means that we expect to receive a .IND,
+ * after having sent the .REQ */
+ if (NULL != indication_ctx)
+ {
+ PLCD_ASSERT (MME_STATUS_INIT != indication_ctx->status);
+ mme_get_free_space (indication_ctx, &ind_len);
+ PLCD_ASSERT (ETH_DATA_LEN <= ind_len);
+ recv_mme++;
+ }
+
+ msg_payload_len = request_ctx->tail - request_ctx->head + sizeof (MME_t);
+ PLCD_ASSERT (ETH_FRAME_LEN >= msg_payload_len);
+
+ /* fill the netlink address to send msg */
+ memset (&kernel_addr, 0, sizeof (kernel_addr));
+ kernel_addr.nl_family = AF_NETLINK;
+ kernel_addr.nl_pid = 0; /* For Linux Kernel */
+ kernel_addr.nl_groups = 0; /* unicast */
+
+ /* create the message */
+ nlh = (struct nlmsghdr *) malloc (NLMSG_LENGTH(ETH_FRAME_LEN));
+ memset (nlh, 0, NLMSG_LENGTH (ETH_FRAME_LEN));
+
+ /* fill the netlink message header */
+ nlh->nlmsg_len = NLMSG_LENGTH (ETH_FRAME_LEN);
+ nlh->nlmsg_pid = getpid(); /* self pid */
+ nlh->nlmsg_flags = 0;
+
+ /* fill the MME header */
+ mme_hdr = (MME_t *) NLMSG_DATA (nlh);
+ memcpy (mme_hdr->mme_dest, ctx->nvram->plc_address, ETH_ALEN);
+ memcpy (mme_hdr->mme_src, ctx->nvram->plc_address, ETH_ALEN);
+ mme_hdr->mtype = htons (MME_TYPE);
+ mme_hdr->mmv = MME_VERSION;
+ mme_hdr->mmtype = request_ctx->mmtype;
+
+ /* fill MME payload */
+ memcpy ((unsigned char *) mme_hdr + sizeof (MME_t),
+ request_ctx->buffer + request_ctx->head,
+ request_ctx->tail - request_ctx->head);
+
+ /* fill message info */
+ memset (&msg, 0, sizeof (msg));
+ msg.msg_name = (void *) &kernel_addr;
+ msg.msg_namelen = sizeof (kernel_addr);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ iov.iov_base = (void *) nlh;
+ iov.iov_len = NLMSG_LENGTH (msg_payload_len);
+
+ if (0 > sendmsg (ctx->plc_sock, &msg, 0))
+ {
+ syslog (LOG_WARNING, "sendmsg failed (errno = %d): mmtype = %04x", errno,
+ mme_hdr->mmtype);
+ free (nlh);
+ return -1;
+ }
+
+ /* prepare the recv message */
+ memset (nlh, 0, NLMSG_LENGTH (ETH_FRAME_LEN));
+ iov.iov_len = NLMSG_LENGTH (ETH_FRAME_LEN);
+
+ /* wait for confirm/indication message(s) */
+ timeout.tv_sec = MME_TOUT;
+ timeout.tv_usec = 0;
+ FD_ZERO (&readfds);
+ FD_SET (ctx->plc_sock, &readfds);
+
+ while (recv_mme)
+ {
+ result = select (ctx->plc_sock + 1, &readfds, NULL, NULL, &timeout);
+ if (0 > result)
+ {
+ /* look for interrupt */
+ if (EINTR == errno)
+ {
+ /* reset errno */
+ errno = 0;
+ /* process interrupt */
+ }
+ else
+ {
+ /* recv error */
+ syslog (LOG_WARNING, "select failed (errno = %d)", errno);
+ free (nlh);
+ return -1;
+ }
+ }
+ else if (0 < result)
+ {
+ /* read received */
+ if (0 >= recvmsg (ctx->plc_sock, &msg, 0))
+ {
+ syslog (LOG_WARNING, "recvmsg failed (errno = %d)", errno);
+ free (nlh);
+ return -1;
+ }
+ /* check MMTYPE */
+ mme_hdr = (MME_t *) NLMSG_DATA (nlh);
+
+ if ((NULL != confirm_ctx)
+ && ((request_ctx->mmtype & ~MME_TYPE_MASK) | MME_TYPE_CNF) == \
+ mme_hdr->mmtype)
+ {
+ /* transfert to confirm ctx */
+ mme_put (confirm_ctx,
+ (unsigned char *) NLMSG_DATA (nlh) + sizeof (MME_t),
+ ETH_DATA_LEN - sizeof (MME_t),
+ &cnf_len);
+ recv_mme--;
+ }
+ else if ((NULL != indication_ctx)
+ && ((request_ctx->mmtype & ~MME_TYPE_MASK) | MME_TYPE_IND) == \
+ mme_hdr->mmtype)
+ {
+ /* transfert to indication ctx */
+ mme_put (indication_ctx,
+ (unsigned char *) NLMSG_DATA (nlh) + sizeof (MME_t),
+ ETH_DATA_LEN - sizeof (MME_t),
+ &ind_len);
+ recv_mme--;
+ }
+ else
+ {
+ syslog (LOG_WARNING, "send recv drv mme: unexpected mmtype (%04x)",
+ mme_hdr->mmtype);
+ free (nlh);
+ return -1;
+ }
+ }
+ else
+ {
+ /* timeout */
+ syslog (LOG_WARNING, "send recv drv mme: select timeout");
+ free (nlh);
+ return -1;
+ }
+ }
+
+ free (nlh);
+ return 0;
+}
+
+/**
+ * Send a DRV MME in which there is only one data field (maximum).
+ * If value is NULL, then MME data is empty.
+ * This helper function is used to send almost all initialization DRV MME-s.
+ *
+ * \param ctx plcd context
+ * \param mmtype mmtype of mme to send
+ * \param value mme data
+ * \param length length of mme data
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_send_recv_single_value (const plcd_ctx_t *ctx,
+ unsigned int mmtype,
+ const void *value,
+ unsigned int length)
+{
+ unsigned char buffer[ETH_DATA_LEN] = {0};
+ mme_ctx_t request_ctx, confirm_ctx;
+ unsigned char result = 0;
+ unsigned int result_len = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+
+ /* init mme */
+ mme_init (&request_ctx, mmtype | MME_TYPE_REQ, buffer, ETH_DATA_LEN);
+ mme_init (&confirm_ctx, mmtype | MME_TYPE_CNF, buffer, ETH_DATA_LEN);
+ if (NULL != value)
+ {
+ /* put value */
+ mme_put (&request_ctx, value, length, &result_len);
+ }
+ if ((0 > plcd_send_recv_drv_mme (ctx, &request_ctx, &confirm_ctx, NULL))
+ || (MME_SUCCESS != mme_pull (&confirm_ctx, &result, sizeof (result),
+ &result_len))
+ || (MME_RESULT_SUCCESS != result))
+ {
+ syslog (LOG_WARNING, "send recv drv mme / mme pull failed");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/******************************************************************************/
+/* SPECIFIC FUNCTIONS TO SEND AND RECEIVE DRV MME MANIPULATED DURING INIT */
+/******************************************************************************/
+
+/**
+ * Send DRV_STA_MAC_ADDR.REQ and receive DRV_STA_MAC_ADDR.CNF.
+ *
+ * \param ctx plcd context
+ * \param mac_addr data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_mac_address (const plcd_ctx_t *ctx, const unsigned char *mac_addr)
+{
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != mac_addr);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_MAC_ADDR,
+ mac_addr, ETH_ALEN);
+}
+
+/**
+ * Send DRV_STA_SET_CCO_PREF.REQ and receive DRV_STA_SET_CCO_PREF.CNF.
+ *
+ * \param ctx plcd context
+ * \param is_cco_preferred data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_cco_preferred (const plcd_ctx_t *ctx,
+ libspid_boolean_t is_cco_preferred)
+{
+ unsigned char value = (unsigned char) is_cco_preferred;
+
+ PLCD_ASSERT (NULL != ctx);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_CCO_PREF, &value,
+ sizeof (value));
+}
+
+/**
+ * Send DRV_STA_SET_WAS_CCO.REQ and receive DRV_STA_SET_WAS_CCO.CNF.
+ *
+ * \param ctx plcd context
+ * \param was_cco data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_was_cco (const plcd_ctx_t *ctx, libspid_boolean_t was_cco)
+{
+ unsigned char value = (unsigned char) was_cco;
+
+ PLCD_ASSERT (NULL != ctx);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_WAS_CCO, &value,
+ sizeof (value));
+}
+
+/**
+ * Send DRV_STA_SET_KEY.REQ and receive DRV_STA_SET_KEY.CNF.
+ *
+ * \param ctx plcd context
+ * \param nmk_str data to send in mme
+ * \param nid_str data to possibly send in mme (data contain nid xor sl)
+ * \param sl_str data to possibly send in mme (data contain nid xor sl)
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_key (const plcd_ctx_t *ctx, const char *nmk_str,
+ const char *nid_str, const char *sl_str)
+{
+ unsigned char buffer_req_cnf[ETH_DATA_LEN] = {0};
+ mme_ctx_t request_ctx, confirm_ctx;
+ unsigned char result = 0;
+ unsigned int result_len = 0;
+ unsigned char tx_type = 0, tx_nid[LIBSPID_HPAV_CONF_NID_BIN_LEN] = {0}, \
+ tx_sl = 0, tx_nmk[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0};
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != nmk_str);
+ PLCD_ASSERT (NULL != nid_str);
+ PLCD_ASSERT (NULL != sl_str);
+
+ /* init mme */
+ mme_init (&request_ctx, MME_TYPE_DRV_STA_SET_KEY | MME_TYPE_REQ,
+ buffer_req_cnf, ETH_DATA_LEN);
+ mme_init (&confirm_ctx, MME_TYPE_DRV_STA_SET_KEY | MME_TYPE_CNF,
+ buffer_req_cnf, ETH_DATA_LEN);
+
+ /* check NMK */
+ if (!strcmp (nmk_str, LIBSPID_VALUE_NONE))
+ {
+ syslog (LOG_WARNING, "stack set key: no nmk found \
+ => use spidapp to generate it from npw");
+ return -1;
+ }
+
+ /* convert NMK to binary */
+ if (LIBSPID_SUCCESS != libspid_hexstring_to_binary (nmk_str, tx_nmk,
+ LIBSPID_HPAV_CONF_NMK_BIN_LEN))
+ {
+ syslog (LOG_WARNING, "libspid string to binary failed");
+ return -1;
+ }
+
+ /* put NMK */
+ mme_put (&request_ctx, tx_nmk, LIBSPID_HPAV_CONF_NMK_BIN_LEN, &result_len);
+
+ /* check NID */
+ if (!strcmp (nid_str, LIBSPID_VALUE_NONE))
+ {
+ /* NID is none => send NMK and SL */
+ /* set Type to send: SL */
+ tx_type = MME_DRV_KEY_TYPE_SL;
+ syslog (LOG_DEBUG, "stack set key: tx type is sl");
+ /* set SL to send */
+ if (!strcmp (sl_str, LIBSPID_HPAV_CONF_VALUE_SL_SC))
+ {
+ tx_sl = MME_DRV_KEY_SL_SC;
+ }
+ else if (!strcmp (sl_str, LIBSPID_HPAV_CONF_VALUE_SL_HS))
+ {
+ tx_sl = MME_DRV_KEY_SL_HS;
+ }
+ else
+ {
+ syslog (LOG_WARNING, "stack set key: unexpected sl");
+ return -1;
+ }
+ }
+ else /* NID is not none => send NMK and NID */
+ {
+ /* convert NID to binary */
+ if (LIBSPID_SUCCESS != libspid_hexstring_to_binary (nid_str, tx_nid,
+ LIBSPID_HPAV_CONF_NID_BIN_LEN))
+ {
+ syslog (LOG_WARNING, "libspid string to binary failed");
+ return -1;
+ }
+ /* set Type to send: NID */
+ tx_type = MME_DRV_KEY_TYPE_NID;
+ syslog (LOG_DEBUG, "stack set key: tx type is nid");
+ }
+
+ /* put Type */
+ mme_put (&request_ctx, &tx_type, sizeof (tx_type), &result_len);
+ /* put NID */
+ mme_put (&request_ctx, tx_nid, LIBSPID_HPAV_CONF_NID_BIN_LEN, &result_len);
+ /* put SL */
+ mme_put (&request_ctx, &tx_sl, sizeof (tx_sl), &result_len);
+
+ if ((0 > plcd_send_recv_drv_mme (ctx, &request_ctx, &confirm_ctx, NULL))
+ || (MME_SUCCESS != mme_pull (&confirm_ctx, &result, sizeof (result),
+ &result_len))
+ || (MME_RESULT_SUCCESS != result))
+ {
+ syslog (LOG_WARNING, "send recv drv mme / mme pull failed");
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * Send DRV_STA_SET_DAK.REQ and receive DRV_STA_SET_DAK.CNF.
+ *
+ * \param ctx plcd context
+ * \param dpw device passwork used to generate device access key to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_dak (const plcd_ctx_t *ctx, const char *dpw)
+{
+ unsigned char dak[LIBSPID_SECU_OUTPUT_KEY_SIZE];
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != dpw);
+
+ /* firstly compute DAK from DPW */
+ if (LIBSPID_SUCCESS != libspid_secu_pbkdf1 (dpw, strlen (dpw),
+ LIBSPID_SECU_SALT_TYPE_DAK,
+ LIBSPID_SECU_PBKDF1_ITERATION, dak,
+ LIBSPID_SECU_OUTPUT_KEY_SIZE))
+ {
+ syslog (LOG_WARNING, "libspid secu pbkdf1 failed");
+ return -1;
+ }
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_DAK, dak,
+ LIBSPID_SECU_OUTPUT_KEY_SIZE);
+}
+
+/**
+ * Send DRV_STA_SET_M_STA_HFID.REQ and receive DRV_STA_SET_M_STA_HFID.CNF.
+ *
+ * \param ctx plcd context
+ * \param manu_hfid data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_manu_hfid (const plcd_ctx_t *ctx, const char *manu_hfid)
+{
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != manu_hfid);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_M_STA_HFID,
+ manu_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN);
+}
+
+/**
+ * Send DRV_STA_SET_U_STA_HFID.REQ and receive DRV_STA_SET_U_STA_HFID.CNF.
+ *
+ * \param ctx plcd context
+ * \param user_hfid data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_user_hfid (const plcd_ctx_t *ctx, const char *user_hfid)
+{
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != user_hfid);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_U_STA_HFID,
+ user_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN);
+}
+
+/**
+ * Send DRV_STA_SET_AVLN_HFID.REQ and receive DRV_STA_SET_AVLN_HFID.CNF.
+ *
+ * \param ctx plcd context
+ * \param avln_hfid data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_avln_hfid (const plcd_ctx_t *ctx, const char *avln_hfid)
+{
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != avln_hfid);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_AVLN_HFID,
+ avln_hfid, LIBSPID_HPAV_CONF_HFID_MAX_LEN);
+}
+
+/**
+ * Send DRV_STA_SET_TONEMASK.REQ and receive DRV_STA_SET_TONEMASK.CNF.
+ *
+ * \param ctx plcd context
+ * \param tonemask data to send in mme
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_tonemask (const plcd_ctx_t *ctx, const unsigned char *tonemask)
+{
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != tonemask);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_TONEMASK,
+ tonemask, 192);
+}
+
+/**
+ * Send DRV_STA_SET_CONFIG.REQ with contents of internal.conf file,
+ * and receive DRV_STA_SET_CONFIG.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_set_internal (const plcd_ctx_t *ctx)
+{
+ char key[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = {0}, \
+ key_previous[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = {0};
+ char *value[1] = {0}, line_buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
+ char mme_buffer[MME_PAYLOAD_MAX_LEN] = {0};
+ int elt_number = 0, result = 0;
+
+ PLCD_ASSERT (NULL != ctx);
+
+ /* firstly reads contents of internal.info file */
+ mme_buffer[0] = '\0';
+ *key = '\0';
+ elt_number = 1;
+
+ /* get 1st key value */
+ if (LIBSPID_SUCCESS != (result = libspid_config_read_line \
+ (ctx->internal_conf_path, "= \t", key, &elt_number, value, line_buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN)))
+ {
+ if (LIBSPID_ERROR_SYSTEM != result)
+ {
+ /* internal libspid error */
+ syslog (LOG_WARNING, "libspid config read line failed (wrong format)");
+ }
+ return 0;
+ }
+
+ /* get all items */
+ while (0 < strlen (key))
+ {
+ /* save current key */
+ strcpy (key_previous, key);
+ elt_number = 1;
+ /* get key value and next key */
+ if (LIBSPID_SUCCESS != (result = libspid_config_read_line \
+ (ctx->internal_conf_path, "= \t", key, &elt_number, value, line_buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN)))
+ {
+ syslog (LOG_WARNING, "libspid config read line failed: key = %s", key);
+ return 0;
+ }
+ if (1 != elt_number)
+ {
+ continue;
+ }
+ /* check free space */
+ if (strlen (mme_buffer) + strlen (key_previous) + 1 + strlen (value[0]) >= \
+ sizeof (mme_buffer))
+ {
+ /* not enough free space: send current MME */
+ mme_buffer[strlen (mme_buffer) - 1] = '\0';
+ if (0 > (result = plcd_send_recv_single_value (ctx,
+ MME_TYPE_DRV_STA_SET_CONFIG,
+ mme_buffer,
+ strlen (mme_buffer) + 1)))
+ {
+ return result;
+ }
+ /* reset buffer content */
+ mme_buffer[0] = '\0';
+ }
+ /* push label into buffer */
+ strcat (mme_buffer, key_previous);
+ strcat (mme_buffer, ":");
+ /* push value into buffer */
+ strcat (mme_buffer, value[0]);
+ strcat (mme_buffer, " ");
+ }
+ /* replace last space by a NULL char */
+ mme_buffer[strlen (mme_buffer) - 1] = '\0';
+
+ /* send MME */
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_SET_CONFIG,
+ mme_buffer, strlen (mme_buffer) + 1);
+}
+
+/**
+ * Send DRV_STA_MAC_START.REQ and receive DRV_STA_MAC_START.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_start (const plcd_ctx_t *ctx)
+{
+ PLCD_ASSERT (NULL != ctx);
+
+ return plcd_send_recv_single_value (ctx, MME_TYPE_DRV_STA_MAC_START, NULL, 0);
+}
+
+
+/******************************************************************************/
+/* FUNCTION TO SEND AND RECEIVE DRV MME NEEDED FOR AV / EOC STACK INIT */
+/******************************************************************************/
+
+/**
+ * Send all DRV MME-s for initialization process.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+plcd_stack_init (const plcd_ctx_t *ctx)
+{
+ char buffer[1024];
+ unsigned char nmk[LIBSPID_SECU_OUTPUT_KEY_SIZE];
+ unsigned char nid[LIBSPID_HPAV_CONF_NID_BIN_LEN];
+ unsigned char dak[LIBSPID_SECU_OUTPUT_KEY_SIZE];
+
+ PLCD_ASSERT (NULL != ctx);
+ PLCD_ASSERT (NULL != ctx->nvram);
+
+ /* send MAC address to AV / EoC stack */
+ if(0 > plcd_stack_set_mac_address (ctx, ctx->nvram->plc_address))
+ {
+ syslog (LOG_WARNING, "stack set mac address failed");
+ return -1;
+ }
+
+ /* send CCO_PREFERRED to AV / EoC stack */
+ if (0 > plcd_stack_set_cco_preferred (ctx, ctx->hpav_conf.is_cco_preferred))
+ {
+ syslog (LOG_WARNING, "stack set cco preferred failed");
+ return -1;
+ }
+
+ /* send WAS_CCO to AV / EoC stack */
+ if (0 > plcd_stack_set_was_cco (ctx, ctx->hpav_conf.was_cco))
+ {
+ syslog (LOG_WARNING, "stack set was cco failed");
+ return -1;
+ }
+
+ /* send NMK and (NID or SL) */
+ if (0 > plcd_stack_set_key (ctx, ctx->hpav_conf.nmk_str,
+ ctx->hpav_conf.nid_str,
+ ctx->hpav_conf.sl_str))
+ {
+ syslog (LOG_WARNING, "stack set key failed");
+ return -1;
+ }
+
+ /* send DAK */
+ if (0 > plcd_stack_set_dak (ctx, ctx->nvram->device_password))
+ {
+ syslog (LOG_WARNING, "stack set dak failed");
+ return -1;
+ }
+
+ /* send manufacturer HFID */
+ if (0 > plcd_stack_set_manu_hfid (ctx, ctx->nvram->product_name))
+ {
+ syslog (LOG_WARNING, "stack set manu hfid failed");
+ return -1;
+ }
+
+ /* send user HFID */
+ if (0 > plcd_stack_set_user_hfid (ctx, ctx->hpav_conf.user_hfid))
+ {
+ syslog (LOG_WARNING, "stack set user hfid failed");
+ return -1;
+ }
+
+ /* send AVLN HFID */
+ if (0 > plcd_stack_set_avln_hfid (ctx, ctx->hpav_conf.avln_hfid))
+ {
+ syslog (LOG_WARNING, "stack set avln hfid failed");
+ return -1;
+ }
+
+ /* send tonemask */
+ if (0 > plcd_stack_set_tonemask (ctx, ctx->nvram->tonemask))
+ {
+ syslog (LOG_WARNING, "stack set tonemask failed");
+ return -1;
+ }
+
+ /* send internal config parameters */
+ if (0 > plcd_stack_set_internal (ctx))
+ {
+ syslog (LOG_WARNING, "stack set internal failed");
+ return -1;
+ }
+
+ /* start AV / EoC stack */
+ if (0 > plcd_stack_start (ctx))
+ {
+ syslog (LOG_WARNING, "stack start failed");
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/cleopatre/devkit/tests/libspid/ftests/spidlib_ftests.c b/cleopatre/devkit/tests/libspid/ftests/spidlib_ftests.c
index 17038824b8..9ff0eb4d30 100644
--- a/cleopatre/devkit/tests/libspid/ftests/spidlib_ftests.c
+++ b/cleopatre/devkit/tests/libspid/ftests/spidlib_ftests.c
@@ -21,7 +21,7 @@ int main()
char value[BUFF_LEN];
int buffer_len;
const char* delimiters = "= \t";
- char key[LIBSPID_KEY_MAX_LEN];
+ char key[LIBSPID_CONFIG_KEY_MAX_LEN];
char *elt[ELT_NUMBER];
unsigned int elt_number = sizeof(elt)/sizeof(elt[0]);
char buffer[BUFF_LEN];
diff --git a/cleopatre/devkit/tests/libspid/utests/Makefile b/cleopatre/devkit/tests/libspid/utests/Makefile
index dd2d54d8ca..39314c3700 100644
--- a/cleopatre/devkit/tests/libspid/utests/Makefile
+++ b/cleopatre/devkit/tests/libspid/utests/Makefile
@@ -1,5 +1,6 @@
PRJ_BASE = ../../../../application/libspid
FILES = system network config_item config_line image
+OBJ_FILES = $(PRJ_OBJPATH)/config_line.o
LIBSPID_DIR=../../../../application/libspid
LINUX_DIR=../../../../linux-2.6.25.10-spc300
diff --git a/cleopatre/devkit/tests/libspid/utests/inc/config_item_utests.h b/cleopatre/devkit/tests/libspid/utests/inc/config_item_utests.h
index e08df1b978..501d65fe8b 100644
--- a/cleopatre/devkit/tests/libspid/utests/inc/config_item_utests.h
+++ b/cleopatre/devkit/tests/libspid/utests/inc/config_item_utests.h
@@ -23,11 +23,13 @@
/* none */
/* FUNCTION STUB */
/* true if character is a blank (space or tab). C99. */
-inline static int isblank(int c)
+#undef isblank
+/*
+static int isblank(int c)
{
return (c == ' ') || (c == '\t');
}
-
+*/
/* none */
/* PLCD FUNCTION DECLARATIONS */
diff --git a/cleopatre/devkit/tests/libspid/utests/src/config_item_utests.c b/cleopatre/devkit/tests/libspid/utests/src/config_item_utests.c
index d20c34ca6f..0b1efcf42b 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/config_item_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/config_item_utests.c
@@ -81,7 +81,7 @@ void teardown(void)
START_TEST (test_read_param)
{
int ret = 7;
- char buffer[LIBSPID_LINE_MAX_LEN] = {0};
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
char key[32] = "key";
char filename[128];
@@ -89,15 +89,15 @@ START_TEST (test_read_param)
sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(ITEM_CNF));
/* filename = NULL */
- ret = libspid_config_read_item( NULL, key, buffer, LIBSPID_LINE_MAX_LEN );
+ ret = libspid_config_read_item( NULL, key, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "filename = NULL");
/* key = NULL */
- ret = libspid_config_read_item( filename, NULL, buffer, LIBSPID_LINE_MAX_LEN );
+ ret = libspid_config_read_item( filename, NULL, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "key = NULL");
/* buffer = NULL */
- ret = libspid_config_read_item( filename, key, NULL, LIBSPID_LINE_MAX_LEN );
+ ret = libspid_config_read_item( filename, key, NULL, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "buffer = NULL");
/* buffer_len = 0 */
@@ -106,11 +106,11 @@ START_TEST (test_read_param)
/* file does not exist */
remove(CONFIG_FILE_DONT_EXIST);
- ret = libspid_config_read_item( CONFIG_FILE_DONT_EXIST, key, buffer, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_config_read_item( CONFIG_FILE_DONT_EXIST, key, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_unless( ret == LIBSPID_ERROR_SYSTEM, "file does not exist");
/* key not found */
- ret = libspid_config_read_item( filename, "nokey", buffer, LIBSPID_LINE_MAX_LEN );
+ ret = libspid_config_read_item( filename, "nokey", buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_NOT_FOUND, "key doesn't exist");
/* LIMIT USAGE */
@@ -119,7 +119,7 @@ START_TEST (test_read_param)
fail_unless( ret == LIBSPID_ERROR_NO_SPACE, "buf_len too small");
/* label is an empty string */
- ret = libspid_config_read_item( filename, "", buffer, LIBSPID_LINE_MAX_LEN );
+ ret = libspid_config_read_item( filename, "", buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_NOT_FOUND, "label is a empty string");
}
END_TEST
@@ -129,7 +129,7 @@ START_TEST (test_write_param)
int ret;
char key[128] = "key";
char filename[128];
- char buffer[LIBSPID_LINE_MAX_LEN] = {0};
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
system("cp " ITEM_CNF " " UTESTS_TMP_DIR);
sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(ITEM_CNF));
@@ -168,20 +168,20 @@ tc_param (void)
START_TEST (test_libspid_config_read_item)
{
int ret;
- char buffer[LIBSPID_LINE_MAX_LEN];
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
char filename[128];
system("cp " ITEM_CNF " " UTESTS_TMP_DIR);
sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(ITEM_CNF));
- ret = libspid_config_read_item (filename, "spidcom", buffer, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_config_read_item (filename, "spidcom", buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_item fail");
fail_if( strcmp(buffer, "malika") != 0, "libspid_config_read_item gets wrong value");
- ret = libspid_config_read_item (filename, "eth", buffer, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_config_read_item (filename, "eth", buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_item fail");
fail_if( strcmp(buffer, "11:aa:22:bb:33:cc") != 0, "libspid_config_read_item gets wrong value");
- ret = libspid_config_read_item (filename, "", buffer, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_config_read_item (filename, "", buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if( ret != LIBSPID_ERROR_NOT_FOUND, "libspid_config_read_item do not detect failure as expected");
}
END_TEST
@@ -189,7 +189,7 @@ END_TEST
START_TEST (test_libspid_config_write_item)
{
int ret;
- char line[LIBSPID_LINE_MAX_LEN];
+ char line[LIBSPID_CONFIG_LINE_MAX_LEN];
FILE *fp;
char filename[128];
char *p = NULL;
@@ -205,7 +205,7 @@ START_TEST (test_libspid_config_write_item)
fail_if(ret != LIBSPID_SUCCESS, " libspid_config_write_item fail");
fp = fopen(filename, "r");
- while ( fgets(line, LIBSPID_LINE_MAX_LEN, fp) != NULL )
+ while ( fgets(line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL )
{
p = strtok(line, " \t" LIBSPID_CONFIG_DELIMITER);
if (strstr(p, "eth"))
diff --git a/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c b/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c
index bf8058a4ab..aa8d72f19f 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c
@@ -85,7 +85,7 @@ START_TEST (test_read_param)
{
int ret = 7;
char delimiters[32] = " :";
- char buffer[LIBSPID_LINE_MAX_LEN] = {0};
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
char *elt[8];
unsigned int elt_nb = 2;
char key[32] = "key";
@@ -97,41 +97,41 @@ START_TEST (test_read_param)
/* filename = NULL */
ret = libspid_config_read_line( NULL, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "filename = NULL");
/* delimiters = NULL */
ret = libspid_config_read_line( filename, NULL, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "delimiters = NULL");
/* delimiters = "" */
strcpy(delimiters, "");
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "delimiters = empty string");
strcpy(delimiters, " :"); /* correct for next test */
/* key = NULL */
ret = libspid_config_read_line( filename, delimiters, NULL,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "key = NULL");
/* elt_nb > LIBSPID_ELT_MAX_NB */
- elt_nb = LIBSPID_ELT_MAX_NB + 1;
+ elt_nb = LIBSPID_CONFIG_ELT_MAX_NB + 1;
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "elt_nb = 0");
elt_nb = 2; /* correct for next test */
/* elt = NULL */
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, NULL, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, NULL, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "elt = NULL");
/* buffer = NULL */
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, NULL, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, NULL, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_PARAM, "buffer = NULL");
/* buffer_len = 0 */
@@ -142,12 +142,12 @@ START_TEST (test_read_param)
/* file does not exist */
remove(CONFIG_FILE_DONT_EXIST);
ret = libspid_config_read_line( CONFIG_FILE_DONT_EXIST, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN);
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_unless( ret == LIBSPID_ERROR_SYSTEM, "file does not exist");
/* key not found */
ret = libspid_config_read_line( filename, delimiters, "nokey",
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_unless( ret == LIBSPID_ERROR_NOT_FOUND, "key doesn't exist");
/* LIMIT USAGE */
@@ -162,7 +162,7 @@ START_TEST (test_read_param)
/* ask for no element */
strcpy(key, "key2");
elt_nb = 0;
- fail_unless(((libspid_config_read_line(filename, " ", key, &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN) >= 0)
+ fail_unless(((libspid_config_read_line(filename, " ", key, &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN) >= 0)
&& !strcmp(key, "key3")
&& (elt_nb == 0)),
"get 0 element");
@@ -170,7 +170,7 @@ START_TEST (test_read_param)
/* other delimiter */
strcpy(key, "key4");
elt_nb = 10;
- fail_unless(((libspid_config_read_line(filename, ":", key, &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN) >= 0)
+ fail_unless(((libspid_config_read_line(filename, ":", key, &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN) >= 0)
&& (elt_nb == 8)
&& !strcmp(elt[3], "elt54 elt")),
"other delimiter");
@@ -178,7 +178,7 @@ START_TEST (test_read_param)
/* 2 delimiters */
strcpy(key, "key4");
elt_nb = 10;
- fail_unless(((libspid_config_read_line(filename, " :", key, &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN) >= 0)
+ fail_unless(((libspid_config_read_line(filename, " :", key, &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN) >= 0)
&& !strcmp(key, "key5")
&& (elt_nb == 9)
&& !strcmp(elt[3], "elt54")
@@ -188,7 +188,7 @@ START_TEST (test_read_param)
/* long comment line */
strcpy(key, "key1");
elt_nb = 10;
- fail_unless(((libspid_config_read_line(filename, " ", key, &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN) >= 0)
+ fail_unless(((libspid_config_read_line(filename, " ", key, &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN) >= 0)
&& !strcmp(key, "key2")),
"long comment line");
@@ -228,7 +228,7 @@ START_TEST (test_write_param)
fail_unless( ret == LIBSPID_ERROR_PARAM, "key = NULL");
/* elt_nb > LIBSPID_ELT_MAX_NB */
- elt_nb = LIBSPID_ELT_MAX_NB + 1;
+ elt_nb = LIBSPID_CONFIG_ELT_MAX_NB + 1;
ret = libspid_config_write_line(filename, delimiter, key, elt_nb, elt);
fail_unless( ret == LIBSPID_ERROR_PARAM, "elt_nb = 0");
elt_nb = 2; /* correct for nex test */
@@ -317,7 +317,7 @@ START_TEST (test_libspid_config_read_line)
int ret;
char filename[128];
char delimiters[32] = " :";
- char buffer[LIBSPID_LINE_MAX_LEN] = {0};
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
char *elt[8];
unsigned int elt_nb;
char key[32];
@@ -327,7 +327,7 @@ START_TEST (test_libspid_config_read_line)
elt_nb = 8;
strcpy(key, "eth");
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
fail_if(elt_nb != 6);
@@ -339,7 +339,7 @@ START_TEST (test_libspid_config_read_line)
elt_nb = 8;
strcpy(key, "eth");
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
fail_if(elt_nb != 6);
@@ -352,14 +352,14 @@ START_TEST (test_libspid_config_read_line)
strcpy(key, "spidcom");
elt_nb = 8;
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_if(ret != LIBSPID_ERROR_NOT_FOUND, "libspid_config_read_line fail");
strcpy(delimiters, ", ");
strcpy(key, "mode");
elt_nb = 8;
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
fail_if(elt_nb != 4, "libspid_config_read_line gets wrong data");
fail_if( strcmp(elt[2], "something") != 0, "libspid_config_read_line gets wrong data");
@@ -369,7 +369,7 @@ START_TEST (test_libspid_config_read_line)
strcpy(delimiters, ", ");
elt_nb = 8;
ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
fail_if( strcmp(key, "mode") != 0, "libspid_config_read_line gets wrong first key");
}
@@ -384,7 +384,7 @@ START_TEST (test_libspid_config_write_line)
unsigned int elt_nb;
char key[32];
FILE *fp;
- char line[LIBSPID_LINE_MAX_LEN];
+ char line[LIBSPID_CONFIG_LINE_MAX_LEN];
char el0[32] = {0};
char el1[32] = {0};
char *p;
@@ -404,7 +404,7 @@ START_TEST (test_libspid_config_write_line)
perror("fopen())");
exit(EXIT_FAILURE);
}
- while ( fgets(line, LIBSPID_LINE_MAX_LEN, fp) != NULL )
+ while ( fgets(line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL )
{
p = strtok(line, ":");
if ( !strcmp(p, key) )
diff --git a/cleopatre/devkit/tests/libspid/utests/src/image_utests.c b/cleopatre/devkit/tests/libspid/utests/src/image_utests.c
index e06bb3007f..80e3a4c5e0 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/image_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/image_utests.c
@@ -298,7 +298,7 @@ START_TEST (test_libspid_image_select)
perror("fopen");
exit(EXIT_FAILURE);
}
- fread(&image_desc, sizeof(spidcom_image_desc_t), 1, fp);
+ fail_if (1 != fread (&image_desc, sizeof (spidcom_image_desc_t), 1, fp));
fclose(fp);
fail_if(image_desc.index != 1, "libspid_image_select gets wrong index");
fail_if( strcmp(image_desc.description, "SPiDCOM image") != 0, "libspid_image_select gets wrong description");
@@ -323,7 +323,7 @@ START_TEST (test_libspid_image_select)
perror("fopen");
exit(EXIT_FAILURE);
}
- fread(&image_desc, sizeof(spidcom_image_desc_t), 1, fp);
+ fail_if (1 != fread (&image_desc, sizeof (spidcom_image_desc_t), 1, fp));
fclose(fp);
fail_if(image_desc.index != 3, "libspid_image_select gets wrong index");
fail_if( strcmp(image_desc.description, "SPiDCOM image") != 0, "libspid_image_select gets wrong description");
@@ -337,7 +337,7 @@ START_TEST (test_libspid_image_select)
perror("fopen");
exit(EXIT_FAILURE);
}
- fread(&image_desc, sizeof(spidcom_image_desc_t), 1, fp);
+ fail_if (1 != fread (&image_desc, sizeof (spidcom_image_desc_t), 1, fp));
fclose(fp);
fail_if(image_desc.index != 4, "libspid_image_select gets wrong index");
fail_if( strcmp(image_desc.description, "SPiDCOM image") != 0, "libspid_image_select gets wrong description");
@@ -351,7 +351,7 @@ START_TEST (test_libspid_image_select)
perror("fopen");
exit(EXIT_FAILURE);
}
- fread(&image_desc, sizeof(spidcom_image_desc_t), 1, fp);
+ fail_if (1 != fread (&image_desc, sizeof (spidcom_image_desc_t), 1, fp));
fclose(fp);
fail_if(image_desc.index != 5, "libspid_image_select gets wrong index");
fail_if( strcmp(image_desc.description, "SPiDCOM image") != 0, "libspid_image_select gets wrong description");
diff --git a/cleopatre/devkit/tests/libspid/utests/src/system_utests.c b/cleopatre/devkit/tests/libspid/utests/src/system_utests.c
index 007cda1556..b0a7cd6a72 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/system_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/system_utests.c
@@ -44,7 +44,7 @@
#define MTD_TST "testfiles/mtd.tst"
/** local variables */
-
+volatile sig_atomic_t handler_called = 0;
/* fixtures - run before and after each unit test */
void setup(void)
@@ -116,6 +116,9 @@ void setup(void)
void teardown(void)
{
+ char command[512];
+ sprintf (command, "rm -f %s", LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
}
@@ -125,10 +128,10 @@ void teardown(void)
START_TEST (param_get_kernel_version)
{
int ret;
- char buffer[LIBSPID_LINE_MAX_LEN];
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
/* buffer is NULL */
- ret = libspid_system_get_kernel_version(NULL, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_system_get_kernel_version(NULL, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if(ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
/* buffer_len is zero */
@@ -158,10 +161,10 @@ END_TEST
START_TEST (param_get_meminfo)
{
int ret;
- char buffer[LIBSPID_LINE_MAX_LEN];
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
/* buffer is NULL */
- ret = libspid_system_get_meminfo(NULL, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_system_get_meminfo(NULL, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if(ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
/* buffer_len is zero */
@@ -195,13 +198,13 @@ tc_param (void)
START_TEST (test_libspid_system_get_kernel_version)
{
int ret;
- char buffer[LIBSPID_LINE_MAX_LEN];
- char test_string[LIBSPID_LINE_MAX_LEN];
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
+ char test_string[LIBSPID_CONFIG_LINE_MAX_LEN];
FILE *fp;
system("cp " VERSION_TST " " LIBSPID_SYSTEM_VERSION_PATH);
- ret = libspid_system_get_kernel_version(buffer, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_system_get_kernel_version(buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_kernel_version fail");
fp = fopen(LIBSPID_SYSTEM_VERSION_PATH, "r");
@@ -210,7 +213,7 @@ START_TEST (test_libspid_system_get_kernel_version)
perror("fopen(VERSION_TST, \"r\")");
exit(EXIT_FAILURE);
}
- fgets(test_string, LIBSPID_LINE_MAX_LEN, fp);
+ fail_if (NULL == fgets (test_string, LIBSPID_CONFIG_LINE_MAX_LEN, fp));
fail_if( strcmp(buffer, test_string) != 0, "libspid_system_get_kernel_version gets wrong data");
fclose(fp);
}
@@ -229,7 +232,7 @@ END_TEST
START_TEST (test_libspid_system_get_uptime)
{
int ret;
- char test_string[LIBSPID_LINE_MAX_LEN];
+ char test_string[LIBSPID_CONFIG_LINE_MAX_LEN];
FILE *fp;
unsigned int total_s;
unsigned int idle_s;
@@ -245,7 +248,7 @@ START_TEST (test_libspid_system_get_uptime)
exit(EXIT_FAILURE);
}
- fgets(test_string, LIBSPID_LINE_MAX_LEN, fp);
+ fail_if (NULL== fgets (test_string, LIBSPID_CONFIG_LINE_MAX_LEN, fp));
fclose(fp); /* flushes I/O buffer into the file */
fail_if(total_s != 11, "libspid_system_get_uptime gets wrong total_s");
fail_if(idle_s != 333, "libspid_system_get_uptime gets wrong idle_s");
@@ -255,14 +258,14 @@ END_TEST
START_TEST (test_libspid_system_get_meminfo)
{
int ret;
- char buffer[LIBSPID_LINE_MAX_LEN];
- char test_string[3*LIBSPID_LINE_MAX_LEN];
- char line[LIBSPID_LINE_MAX_LEN];
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
+ char test_string[3*LIBSPID_CONFIG_LINE_MAX_LEN];
+ char line[LIBSPID_CONFIG_LINE_MAX_LEN];
FILE *fp;
system("cp " MEMINFO_TST " " LIBSPID_SYSTEM_MEMINFO_PATH);
- ret = libspid_system_get_meminfo(buffer, LIBSPID_LINE_MAX_LEN);
+ ret = libspid_system_get_meminfo(buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_meminfo fail");
@@ -273,7 +276,7 @@ START_TEST (test_libspid_system_get_meminfo)
exit(EXIT_FAILURE);
}
- while ( fgets(line, LIBSPID_LINE_MAX_LEN, fp) != NULL )
+ while ( fgets(line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL )
{
strcat(test_string, line);
}
@@ -285,7 +288,7 @@ END_TEST
START_TEST (test_libspid_system_save)
{
int ret;
- char test_string[LIBSPID_LINE_MAX_LEN] = "test1\ntest2\n"; /* do not forget last '\n' */
+ char test_string[LIBSPID_CONFIG_LINE_MAX_LEN] = "test1\ntest2\n"; /* do not forget last '\n' */
FILE *fp;
char tst_file[128] = {0};
@@ -313,7 +316,7 @@ START_TEST (test_libspid_system_save)
fclose(fp); /* flushes I/O buffer into the file */
ret = libspid_system_save();
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_meminfo fail");
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_system_save fail");
/* test if files have been well copied */
sprintf(tst_file, "%s/test1", LIBSPID_SAVE_DIR_PATH);
@@ -337,7 +340,6 @@ START_TEST (test_libspid_system_save)
TRACE("%s\n",d->d_name);
}
#endif
-
}
END_TEST
@@ -466,6 +468,275 @@ START_TEST (test_libspid_system_get_date)
}
END_TEST
+void callback (int signal_nb)
+{
+ if (SIGHUP == signal_nb)
+ {
+ handler_called = 1;
+ }
+}
+
+START_TEST (test_libspid_system_file_update_register)
+{
+ pid_t rx_pid = 1;
+ char filename[LIBSPID_CONFIG_KEY_MAX_LEN + 1];
+ char filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 2];
+ libspid_boolean_t is_registered = LIBSPID_FALSE;
+ unsigned int elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
+ char *elt[LIBSPID_CONFIG_ELT_MAX_NB] = { NULL };
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
+ char key[LIBSPID_CONFIG_KEY_MAX_LEN];
+ memset (filename, 'f', LIBSPID_CONFIG_KEY_MAX_LEN);
+ filename[LIBSPID_CONFIG_KEY_MAX_LEN] = '\0';
+ memset (filename_too_long, 'l', LIBSPID_CONFIG_KEY_MAX_LEN + 1);
+ filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = '\0';
+ strcpy (key, filename);
+
+ /* Test wrong input parameters. */
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (0, filename,
+ callback));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (rx_pid, NULL,
+ callback));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (rx_pid,
+ filename_too_long, callback));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (rx_pid,
+ filename, NULL));
+
+ /* Test to register filename/rx_pid. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid, filename,
+ callback));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+
+ /* Check "signal.info" file contents.*/
+ fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (1 == elt_number);
+ fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "1"));
+
+ /* Test to register another rx_pid. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid + 1,
+ filename, callback));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid + 1,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+
+ /* Check "signal.info" file contents.*/
+ strcpy (key, filename);
+ elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
+ fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (2 == elt_number);
+ fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "1"));
+ fail_unless ((NULL != elt[1]) && !strcmp (elt[1], "2"));
+
+ /* Test when the given process has already registered to the given file update. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid, filename,
+ callback));
+
+ /* Check "signal.info" file contents.*/
+ strcpy (key, filename);
+ elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
+ fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (2 == elt_number);
+ fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "1"));
+ fail_unless ((NULL != elt[1]) && !strcmp (elt[1], "2"));
+}
+END_TEST
+
+START_TEST (test_libspid_system_file_update_unregister)
+{
+ pid_t rx_pid1 = 10;
+ pid_t rx_pid2 = 20;
+ pid_t rx_pid3 = 30;
+ const char filename[] = "filename";
+ char filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 2];
+ libspid_boolean_t is_registered = LIBSPID_FALSE;
+ unsigned int elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
+ char *elt[LIBSPID_CONFIG_ELT_MAX_NB] = { NULL };
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
+ char key[LIBSPID_CONFIG_KEY_MAX_LEN];
+ memset (filename_too_long, 'l', LIBSPID_CONFIG_KEY_MAX_LEN + 1);
+ filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = '\0';
+ strcpy (key, filename);
+
+ /* Test wrong input parameters. */
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_unregister (0,
+ filename));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_unregister (rx_pid1,
+ NULL));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_unregister (rx_pid1,
+ filename_too_long));
+
+ /* Test when no process is registered to the given file update. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid1, filename));
+
+ /* Test when the process is not registered to the given file update. */
+ /** rx_pid1 registration */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid1,
+ filename, callback));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid1,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+ /** end rx_pid1 registration */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid2, filename));
+
+ /* Check "signal.info" file contents.*/
+ fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (1 == elt_number);
+ fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "10"));
+
+ /* Test when several processes are registered to the given file update. */
+ /** rx_pid2 registration */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid2, filename,
+ callback));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid2,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+ /** end rx_pid2 registration */
+ /** rx_pid3 registration */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid3, filename,
+ callback));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid3,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+ /** end rx_pid3 registration */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid1, filename));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid1,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid3, filename));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid3,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+
+ /* Check "signal.info" file contents.*/
+ strcpy (key, filename);
+ elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
+ fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (1 == elt_number);
+ fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "20"));
+
+ /* Test when only one process is registered to the given file update. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid2, filename));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid2,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+}
+END_TEST
+
+START_TEST (test_libspid_system_file_update_is_registered)
+{
+ pid_t rx_pid = 3;
+ const char filename[] = "filename";
+ char filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 2];
+ libspid_boolean_t is_registered = LIBSPID_TRUE;
+ const char wrong_filename[] = "wrong_filename";
+ char command[512] = {0};
+ memset (filename_too_long, 'l', LIBSPID_CONFIG_KEY_MAX_LEN + 1);
+ filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = '\0';
+
+ /* Test wrong input parameters. */
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (0,
+ filename, &is_registered));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (rx_pid,
+ NULL, &is_registered));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (rx_pid,
+ filename_too_long, &is_registered));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (rx_pid,
+ filename, NULL));
+
+ /* Test when "signal.info" file does not exist. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+
+ /* Test when "signal.info" file exists but filename/rx_pid is not registered. */
+ sprintf (command, "touch %s", LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+ sprintf (command, "echo %s%s%d > %s", wrong_filename,
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 1, LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+ sprintf (command, "echo %s%s%d > %s", wrong_filename,
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid, LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+ sprintf (command, "echo %s%s%d > %s", filename,
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 1, LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_FALSE != is_registered);
+
+ /* Test when "signal.info" file exists and filename/rx_pid is registered. */
+ sprintf (command, "echo %s%s%d > %s", filename,
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid, LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+
+ /* Test when "signal.info" file exists and several rx_pid are registered on filename. */
+ sprintf (command, "echo %s%s%d%s%d > %s", filename,
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 2, LIBSPID_SIGNAL_INFO_DELIMITER,
+ rx_pid + 3, LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid + 3,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid + 2,
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+}
+END_TEST
+
+START_TEST (test_libspid_system_file_update_warn)
+{
+ pid_t tx_pid = 0;
+ const char filename[] = "filename";
+ char filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 2];
+ libspid_boolean_t is_registered = LIBSPID_FALSE;
+ memset (filename_too_long, 'l', LIBSPID_CONFIG_KEY_MAX_LEN + 1);
+ filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = '\0';
+
+ /* Test wrong input parameters. */
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_warn (-1, filename));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_warn (tx_pid, NULL));
+ fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_warn (tx_pid,
+ filename_too_long));
+
+ /* Test when no process is registered. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_warn (tx_pid, filename));
+ fail_if (0 != handler_called);
+
+ /* Test when my PID is registered. */
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (getpid(), filename,
+ callback));
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (getpid(),
+ filename, &is_registered));
+ fail_if (LIBSPID_TRUE != is_registered);
+ fail_if (LIBSPID_SUCCESS != libspid_system_file_update_warn (tx_pid, filename));
+ fail_if (!handler_called);
+}
+END_TEST
+
extern Suite* libspid_system_suite(void)
{
Suite *s = suite_create("LIBSPID_SYSTEM");
@@ -482,6 +753,10 @@ extern Suite* libspid_system_suite(void)
tcase_add_test(tc_core, test_libspid_system_factory);
tcase_add_test(tc_core, test_libspid_system_get_nvram);
tcase_add_test(tc_core, test_libspid_system_get_date);
+ tcase_add_test(tc_core, test_libspid_system_file_update_is_registered);
+ tcase_add_test(tc_core, test_libspid_system_file_update_register);
+ tcase_add_test(tc_core, test_libspid_system_file_update_unregister);
+ tcase_add_test(tc_core, test_libspid_system_file_update_warn);
suite_add_tcase(s, tc_core);
suite_add_tcase(s, tc_param());
diff --git a/cleopatre/devkit/tests/utests_makerules b/cleopatre/devkit/tests/utests_makerules
index 1a50ea43f6..59f962f727 100644
--- a/cleopatre/devkit/tests/utests_makerules
+++ b/cleopatre/devkit/tests/utests_makerules
@@ -1,5 +1,5 @@
#You need to precise : PRJ_BASE and FILES before calling this file
-#EXTRA_CFLAGS is optionnal
+#EXTRA_CFLAGS and OBJ_FILES are optionnal
TEST_NAME = utests
PRJ_SRCPATH = $(PRJ_BASE)/src
@@ -24,7 +24,7 @@ else
endif
CC=gcc
CPP=g++
-CFLAGS = -Wall -O -g -D__UTESTS__ -I$(PRJ_INCPATH) -I$(TEST_INCPATH) $(EXTRA_CFLAGS)
+CFLAGS = -Wall -g -D__UTESTS__ -I$(PRJ_INCPATH) -I$(TEST_INCPATH) $(EXTRA_CFLAGS)
LDFLAGS = $(EXTRA_LDFLAGS)
LIBS = -lcheck -lpthread $(EXTRA_LIBS)
@@ -45,7 +45,7 @@ preall:
.PHONY: all clean
.PRECIOUS: $(PRJ_OBJPATH)/%.o $(TEST_OBJPATH)/%.o
-$(OBJPATH)/%.elf: $(PRJ_OBJPATH)/%.o $(TEST_OBJPATH)/%_$(TEST_NAME).o
+$(OBJPATH)/%.elf: $(PRJ_OBJPATH)/%.o $(TEST_OBJPATH)/%_$(TEST_NAME).o $(OBJ_FILES)
$(LDCC) $(LDFLAGS) -o $@ $^ $(LIBS)