summaryrefslogtreecommitdiff
path: root/cleopatre/application/managerd
diff options
context:
space:
mode:
authorCeline Buret2010-10-08 10:52:36 +0200
committerCeline Buret2010-10-18 11:52:04 +0200
commit97fdecd4cfed7fee984ea604b0915b850e9cca1a (patch)
tree0d14e330afb84a4f5d278de41b33b44124acff4a /cleopatre/application/managerd
parent27df5a48a8ad62d3cfdb994aea82ed2e86f13efb (diff)
cleo/app/mgrd: implement attachment led and led1&2, closes #1951
To drive LED-s: - add SIGHUP registration and signal handler in managerd, - add hpav.info structure in managerd context to keep previous values, - add processing dispatch in managerd depending on hpav.info modifications, - create new files in managerd dedicated to led management, - implement led events processing, - implement SIGALRM signal handler for led flashing, - remove led management from simple_connect, - update managerd specs. Code relative to LED1&2 is dedicated to spk300 only.
Diffstat (limited to 'cleopatre/application/managerd')
-rw-r--r--cleopatre/application/managerd/inc/led.h103
-rw-r--r--cleopatre/application/managerd/inc/managerd.h16
-rw-r--r--cleopatre/application/managerd/inc/simple_connect.h1
-rw-r--r--cleopatre/application/managerd/inc/vs_mme.h1
-rw-r--r--cleopatre/application/managerd/src/led.c392
-rw-r--r--cleopatre/application/managerd/src/managerd.c151
-rw-r--r--cleopatre/application/managerd/src/simple_connect.c14
7 files changed, 660 insertions, 18 deletions
diff --git a/cleopatre/application/managerd/inc/led.h b/cleopatre/application/managerd/inc/led.h
new file mode 100644
index 0000000000..ba28b09125
--- /dev/null
+++ b/cleopatre/application/managerd/inc/led.h
@@ -0,0 +1,103 @@
+/*
+ * cleopatre/application/managerd/inc/led.h
+ *
+ * (C) Copyright 2010 SPiDCOM Technologies
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#ifndef LED_H
+#define LED_H
+
+#include "../../linux/autoconf.h"
+
+struct managerd_ctx;
+
+/** LED GPIO numbers */
+#define LED_ATTACHMENT_GPIO_NUM 3
+#if (defined CONFIG_MACH_SPK300G || defined CONFIG_MACH_SPK300)
+# define LED1_GPIO_NUM 13
+# define LED2_GPIO_NUM 12
+#endif
+
+/** Blinking timers */
+#define LED_FAST_TIMER_US 100000
+#define LED_LOW_TIMER_US 500000
+
+/**
+ * Handle SIGALRM reception.
+ *
+ * \param signal_nb signal identifier
+ */
+void
+led_signal_handler (int signal_nb);
+
+/**
+ * When timer expires, this function is called to invert current value of LED,
+ * in order to make it blink.
+ */
+void
+led_flashing (void);
+
+/**
+ * LED attachment event.
+ *
+ * \param ctx managerd context
+ * \param status current status value from hpav.info
+ * \param is_sc current Simple Connect value from hpav.info
+ * \return error code
+ */
+int
+led_attachment_event (struct managerd_ctx *ctx, const char *status,
+ libspid_boolean_t is_sc);
+
+/**
+ * LED1 event.
+ *
+ * \param ctx managerd context
+ * \param cco current CCo value from hpav.info
+ * \return error code
+ */
+int
+led1_event (struct managerd_ctx *ctx, const char *cco);
+
+/**
+ * LED2 event.
+ *
+ * \param ctx managerd context
+ * \param is_backup_cco current backup CCo value from hpav.info
+ * \return error code
+ */
+int
+led2_event (struct managerd_ctx *ctx, libspid_boolean_t is_backup_cco);
+
+/**
+ * Initialize LED-s: set GPIO direction and value.
+ *
+ * \param ctx managerd context
+ * \return error code
+ */
+int
+led_init (struct managerd_ctx *ctx);
+
+/**
+ * Uninitialize LED-s: reset GPIO value.
+ *
+ * \param ctx managerd context
+ */
+void
+led_uninit (struct managerd_ctx *ctx);
+
+#endif /* LED_H */
diff --git a/cleopatre/application/managerd/inc/managerd.h b/cleopatre/application/managerd/inc/managerd.h
index 324dba7453..381779e68b 100644
--- a/cleopatre/application/managerd/inc/managerd.h
+++ b/cleopatre/application/managerd/inc/managerd.h
@@ -28,6 +28,8 @@
#include <linux/netlink.h>
#include "../../linux/gpio.h"
+#include "libspid.h"
+
/** Define packet max length */
#define MAX_PKT_LEN 1524
@@ -46,6 +48,20 @@ struct managerd_ctx {
union gpio_info sc_it;
union gpio_info led_gpio;
int is_sc_available;
+ /* 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;
};
#endif /* MANAGERD_H */
diff --git a/cleopatre/application/managerd/inc/simple_connect.h b/cleopatre/application/managerd/inc/simple_connect.h
index c291eeb0d9..8a06c4283b 100644
--- a/cleopatre/application/managerd/inc/simple_connect.h
+++ b/cleopatre/application/managerd/inc/simple_connect.h
@@ -25,7 +25,6 @@
/** GPIO number for SC button and it associated LED */
#define SC_BUT_GPIO_NUM 1
-#define SC_LED_GPIO_NUM 2
/** name of the gpio device */
#define GPIO_DEVICE_NAME "/dev/gpio"
diff --git a/cleopatre/application/managerd/inc/vs_mme.h b/cleopatre/application/managerd/inc/vs_mme.h
index 1f0170320f..709a8e4928 100644
--- a/cleopatre/application/managerd/inc/vs_mme.h
+++ b/cleopatre/application/managerd/inc/vs_mme.h
@@ -22,7 +22,6 @@
#define VS_MME_H
#include "libmme.h"
-#include "libspid.h"
#include "managerd.h"
#include "bridge.h"
diff --git a/cleopatre/application/managerd/src/led.c b/cleopatre/application/managerd/src/led.c
new file mode 100644
index 0000000000..189ed87e6a
--- /dev/null
+++ b/cleopatre/application/managerd/src/led.c
@@ -0,0 +1,392 @@
+/*
+ * cleopatre/application/managerd/src/led.c
+ *
+ * (C) Copyright 2010 SPiDCOM Technologies
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <syslog.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "nvram.h"
+#include "../../linux/gpio.h"
+
+#include "managerd.h"
+#include "led.h"
+
+/* Global variable for "/dev/gpio" file descriptor
+ * needed during SIGALRM signal handling */
+int gpio_fd = -1;
+
+/**
+ * Handle SIGALRM reception.
+ *
+ * \param signal_nb signal identifier
+ */
+void
+led_signal_handler (int signal_nb)
+{
+ /* check that we received a SIGALRM signal (other signals must be ignored) */
+ if (SIGALRM == signal_nb)
+ {
+ led_flashing ();
+ }
+}
+
+/**
+ * When timer expires, this function is called to invert current value of LED,
+ * in order to make it blink.
+ */
+void
+led_flashing (void)
+{
+ union gpio_info led_gpio;
+
+ /* Set GPIO number */
+ led_gpio.gpioval.num = LED_ATTACHMENT_GPIO_NUM;
+
+ /* Get GPIO value */
+ if (0 > (ioctl (gpio_fd, GPIOIOC_GETVALUE, (unsigned long *) &led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl GETVALUE for LED GPIO (%s)",
+ strerror (errno));
+ }
+
+ /* Invert GPIO value */
+ if (led_gpio.gpioval.val)
+ led_gpio.gpioval.val = 0;
+ else
+ led_gpio.gpioval.val = 1;
+
+ /* Set GPIO value */
+ if (0 > (ioctl (gpio_fd, GPIOIOC_SETVALUE, (unsigned long *) &led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED GPIO (%s)",
+ strerror (errno));
+ }
+}
+
+/**
+ * LED attachment event.
+ *
+ * \param ctx managerd context
+ * \return error code
+ */
+int
+led_attachment_event (struct managerd_ctx *ctx, const char *status,
+ libspid_boolean_t is_sc)
+{
+ struct itimerval itv;
+ /* Set default timer interval */
+ itv.it_interval.tv_sec = 0;
+ itv.it_interval.tv_usec = 0;
+ /* Set default current value */
+ itv.it_value.tv_sec = 0;
+ itv.it_value.tv_usec = 0;
+
+ /* Check arguments */
+ assert (NULL != ctx);
+ assert (NULL != status);
+
+ /* Set GPIO number */
+ ctx->led_gpio.gpioval.num = LED_ATTACHMENT_GPIO_NUM;
+
+ if ((LIBSPID_TRUE == ctx->hpav_info.is_sc) && (LIBSPID_FALSE == is_sc)
+ && strcmp (LIBSPID_HPAV_INFO_VALUE_STATUS_AUTHENTICATED, status))
+ {
+ /* SC has failed: modem is not authenticated after a SC procedure
+ * Fast flashing of the LED: one flash every 100ms
+ * Start timer */
+ syslog (LOG_DEBUG, "led_attachment_event: fast flashing");
+ itv.it_interval.tv_usec = LED_FAST_TIMER_US;
+ itv.it_value.tv_usec = LED_FAST_TIMER_US;
+ if (0 > setitimer (ITIMER_REAL, &itv, &itv))
+ {
+ syslog (LOG_WARNING, "setitimer failed (%s)", strerror (errno));
+ }
+ }
+ else if (((LIBSPID_FALSE == is_sc)
+ && !strcmp(LIBSPID_HPAV_INFO_VALUE_STATUS_ASSOCIATED, status))
+ || (LIBSPID_TRUE == is_sc))
+ {
+ /* Associated (or associating): standard attachment procedure,
+ * or SC is on-going
+ * Low flashing of the LED: one flash every 500ms
+ * Start timer */
+ syslog (LOG_DEBUG, "led_attachment_event: low flashing");
+ itv.it_interval.tv_usec = LED_LOW_TIMER_US;
+ itv.it_value.tv_usec = LED_LOW_TIMER_US;
+ if (0 > setitimer (ITIMER_REAL, &itv, &itv))
+ {
+ syslog (LOG_WARNING, "setitimer failed (%s)", strerror (errno));
+ }
+ }
+ else if (!strcmp (LIBSPID_HPAV_INFO_VALUE_STATUS_AUTHENTICATED, status))
+ {
+ /* Authenticated: modem is attached to an AVLN
+ * Stop timer and set GPIO value */
+ syslog (LOG_DEBUG, "led_attachment_event: set 1");
+ if (0 > setitimer (ITIMER_REAL, &itv, &itv))
+ {
+ syslog (LOG_WARNING, "setitimer failed (%s)", strerror (errno));
+ }
+ ctx->led_gpio.gpioval.val = 1;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED GPIO (%s)",
+ strerror (errno));
+ }
+ }
+ else if ((LIBSPID_FALSE == is_sc)
+ && !strcmp (LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED, status))
+ {
+ /* Unassociated: modem is on,
+ * but standard attachment procedure has not started (or has failed)
+ * Stop timer and reset GPIO value */
+ syslog (LOG_DEBUG, "led_attachment_event: set 0");
+ if (0 > setitimer (ITIMER_REAL, &itv, &itv))
+ {
+ syslog (LOG_WARNING, "setitimer failed (%s)", strerror (errno));
+ }
+ ctx->led_gpio.gpioval.val = 0;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED GPIO (%s)",
+ strerror (errno));
+ }
+ }
+ else
+ {
+ syslog (LOG_WARNING, "led_attachment_event: unknown state");
+ }
+
+ return 0;
+}
+
+/**
+ * LED1 event.
+ *
+ * \param ctx managerd context
+ * \param cco current CCo value from hpav.info
+ * \return error code
+ */
+int
+led1_event (struct managerd_ctx *ctx, const char *cco)
+{
+ /* Check arguments */
+ assert (NULL != ctx);
+ assert (NULL != cco);
+
+#if (defined CONFIG_MACH_SPK300G || defined CONFIG_MACH_SPK300)
+ /* Set GPIO number */
+ ctx->led_gpio.gpioval.num = LED1_GPIO_NUM;
+
+ if (!strcmp (LIBSPID_HPAV_INFO_VALUE_CCO_STATION, cco)
+ || !strcmp (LIBSPID_HPAV_INFO_VALUE_CCO_PROXY, cco))
+ {
+ /* Simple station or proxy CCo
+ * Reset GPIO value */
+ syslog (LOG_DEBUG, "led1_event: set 0");
+ ctx->led_gpio.gpioval.val = 0;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED1 GPIO (%s)",
+ strerror (errno));
+ }
+ }
+ else if (!strcmp (LIBSPID_HPAV_INFO_VALUE_CCO_MAIN, cco))
+ {
+ /* Main CCo: modem took control of the AVLN
+ * Set GPIO value */
+ syslog (LOG_DEBUG, "led1_event: set 1");
+ ctx->led_gpio.gpioval.val = 1;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED1 GPIO (%s)",
+ strerror (errno));
+ }
+ }
+ else
+ {
+ syslog (LOG_WARNING, "led1_event: unknown state");
+ }
+#else
+ syslog (LOG_DEBUG, "led1_event: no led1");
+#endif
+
+ return 0;
+}
+
+/**
+ * LED2 event.
+ *
+ * \param ctx managerd context
+ * \param is_backup_cco current backup CCo value from hpav.info
+ * \return error code
+ */
+int
+led2_event (struct managerd_ctx *ctx, libspid_boolean_t is_backup_cco)
+{
+ /* Check arguments */
+ assert (NULL != ctx);
+
+#if (defined CONFIG_MACH_SPK300G || defined CONFIG_MACH_SPK300)
+ /* Set GPIO number */
+ ctx->led_gpio.gpioval.num = LED2_GPIO_NUM;
+
+ if (LIBSPID_FALSE == is_backup_cco)
+ {
+ /* Not a backup CCo
+ * Reset GPIO value */
+ syslog (LOG_DEBUG, "led2_event: set 0");
+ ctx->led_gpio.gpioval.val = 0;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED2 GPIO (%s)",
+ strerror (errno));
+ }
+ }
+ else if (LIBSPID_TRUE == is_backup_cco)
+ {
+ /* Backup CCo
+ * Set GPIO value */
+ syslog (LOG_DEBUG, "led2_event: set 1");
+ ctx->led_gpio.gpioval.val = 1;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED2 GPIO (%s)",
+ strerror (errno));
+ }
+ }
+ else
+ {
+ syslog (LOG_WARNING, "led2_event: unknown state");
+ }
+#else
+ syslog (LOG_DEBUG, "led2_event: no led2");
+#endif
+
+ return 0;
+}
+
+/**
+ * Set GPIO direction.
+ *
+ * \param ctx managerd context
+ * \return error code
+ */
+int
+led_init (struct managerd_ctx *ctx)
+{
+ /* Check arguments */
+ assert (NULL != ctx);
+ assert (0 <= ctx->gpio_fd);
+
+ /* Set GPIO direction */
+ ctx->led_gpio.gpiodir.num = LED_ATTACHMENT_GPIO_NUM;
+ ctx->led_gpio.gpiodir.dir = SPC300_GPIO_DIRECTION_OUTPUT;
+ ctx->led_gpio.gpiodir.val = 0;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETDIRECTION,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETDIRECTION for LED GPIO (%s)",
+ strerror (errno));
+ }
+
+#if (defined CONFIG_MACH_SPK300G || defined CONFIG_MACH_SPK300)
+ /* Set GPIO direction of LED1&2 */
+ ctx->led_gpio.gpiodir.num = LED1_GPIO_NUM;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETDIRECTION,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETDIRECTION for LED1 GPIO (%s)",
+ strerror (errno));
+ }
+ ctx->led_gpio.gpiodir.num = LED2_GPIO_NUM;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETDIRECTION,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETDIRECTION for LED2 GPIO (%s)",
+ strerror (errno));
+ }
+#endif
+
+ /* Register the SIGALRM signal handler for LED flashing */
+ if (SIG_ERR == signal (SIGALRM, led_signal_handler))
+ {
+ syslog (LOG_WARNING, "cannot register led signal handler");
+ return -1;
+ }
+
+ /* Set global variable */
+ gpio_fd = ctx->gpio_fd;
+
+ return 0;
+}
+
+/**
+ * Reset GPIO value.
+ *
+ * \param ctx managerd context
+ */
+void
+led_uninit (struct managerd_ctx *ctx)
+{
+ /* Check argument */
+ assert (ctx != NULL);
+
+ /* Reset GPIO value */
+ ctx->led_gpio.gpioval.num = LED_ATTACHMENT_GPIO_NUM;
+ ctx->led_gpio.gpioval.val = 0;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED GPIO (%s)",
+ strerror (errno));
+ }
+
+#if (defined CONFIG_MACH_SPK300G || defined CONFIG_MACH_SPK300)
+ /* Reset GPIO value of LED1&2 */
+ ctx->led_gpio.gpioval.num = LED1_GPIO_NUM;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED1 GPIO (%s)",
+ strerror (errno));
+ }
+ ctx->led_gpio.gpioval.num = LED2_GPIO_NUM;
+ if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETVALUE,
+ (unsigned long *) &ctx->led_gpio)))
+ {
+ syslog (LOG_WARNING, "cannot call ioctl SETVALUE for LED2 GPIO (%s)",
+ strerror (errno));
+ }
+#endif
+}
diff --git a/cleopatre/application/managerd/src/managerd.c b/cleopatre/application/managerd/src/managerd.c
index 42bb6dfd78..28035c7012 100644
--- a/cleopatre/application/managerd/src/managerd.c
+++ b/cleopatre/application/managerd/src/managerd.c
@@ -29,8 +29,115 @@
#include "bridge.h"
#include "mme_nl.h"
#include "simple_connect.h"
+#include "led.h"
#include "managerd.h"
+
+/* Global variable indicating if a SIGHUP signal occurred,
+ * has been caught in managerd signal handler,
+ * and has now to be processed. */
+libspid_boolean_t is_process_signal_needed;
+
+
+/**
+ * Handle SIGHUP reception.
+ *
+ * \param signal_nb signal identifier
+ */
+void
+managerd_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;
+ }
+}
+
+/**
+ * This function is called after reception of a SIGHUP by managerd signal handler.
+ * Check which information has changed in hpav.info file,
+ * and depending on this information, call the appropriate processing function.
+ *
+ * \param ctx managerd context
+ * \return -1 on error, 0 otherwise
+ */
+int
+managerd_process_signal (struct managerd_ctx *ctx)
+{
+ /* 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};
+
+ assert (NULL != ctx);
+
+ /* read hpav.info file contents */
+ if ((LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
+ LIBSPID_HPAV_INFO_LABEL_STATUS, status,
+ LIBSPID_HPAV_INFO_STATUS_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
+ LIBSPID_HPAV_INFO_LABEL_CCO, cco,
+ LIBSPID_HPAV_INFO_CCO_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
+ LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, is_backup_cco_str,
+ LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
+ LIBSPID_HPAV_INFO_LABEL_SC, is_sc_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
+ || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_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 -1;
+ }
+
+ if (strcmp (status, ctx->hpav_info.status)
+ || (LIBSPID_GET_BOOLEAN (is_sc_str) != ctx->hpav_info.is_sc))
+ {
+ /* attachment */
+ if (0 > led_attachment_event (ctx, status,
+ LIBSPID_GET_BOOLEAN (is_sc_str)))
+ {
+ syslog (LOG_WARNING, "led attachment event failed");
+ return -1;
+ }
+
+ /* save values in managerd context */
+ strcpy (ctx->hpav_info.status, status);
+ ctx->hpav_info.is_sc = LIBSPID_GET_BOOLEAN (is_sc_str);
+ }
+ if (strcmp (cco, ctx->hpav_info.cco))
+ {
+ /* LED1 */
+ if (0 > led1_event (ctx, cco))
+ {
+ syslog (LOG_WARNING, "led1 event failed");
+ return -1;
+ }
+
+ /* save value in managerd context */
+ strcpy (ctx->hpav_info.cco, cco);
+ }
+ if (LIBSPID_GET_BOOLEAN (is_backup_cco_str) != ctx->hpav_info.is_backup_cco)
+ {
+ /* LED2 */
+ if (0 > led2_event (ctx, LIBSPID_GET_BOOLEAN (is_backup_cco_str)))
+ {
+ syslog (LOG_WARNING, "led2 event failed");
+ return -1;
+ }
+
+ /* save value in managerd context */
+ ctx->hpav_info.is_backup_cco = LIBSPID_GET_BOOLEAN (is_backup_cco_str);
+ }
+
+ return 0;
+}
+
/**
* Daemon core process.
* Wait frame on BR and MME netlink, processing it before
@@ -143,6 +250,13 @@ static int managerd_process(struct managerd_ctx *ctx)
else
continue;
}
+
+ if (is_process_signal_needed)
+ {
+ /* now handle all info file changes (from plcd) */
+ managerd_process_signal (ctx);
+ is_process_signal_needed = LIBSPID_FALSE;
+ }
}
//Freeing buffer
@@ -158,6 +272,11 @@ static int managerd_process(struct managerd_ctx *ctx)
*/
static int managerd_init(struct managerd_ctx *ctx)
{
+ /* hpav.info */
+ 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};
+
//Check arguments
assert(ctx != NULL);
@@ -172,10 +291,33 @@ static int managerd_init(struct managerd_ctx *ctx)
if(0 > mme_nl_init(ctx))
return -1;
- //Initialize simple connect part
+ //Initialize simple connect part (open "/dev/gpio")
if(0 > simple_connect_init(ctx))
return -1;
+ /* Initialize led part (need "/dev/gpio") */
+ if (0 > led_init (ctx))
+ return -1;
+
+ /* Set default values of hpav.info file into managerd 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;
+
+ /* Initialize to true to set LED-s status
+ * according to current hpav.info contents. */
+ is_process_signal_needed = LIBSPID_TRUE;
+
+ /* Register to hpav.info file update */
+ if (LIBSPID_SUCCESS != libspid_system_file_update_register (getpid(),
+ LIBSPID_HPAV_INFO_PATH, managerd_signal_handler))
+ {
+ syslog (LOG_WARNING, "libspid system file update register failed");
+ return -1;
+ }
+
return 0;
}
@@ -195,7 +337,10 @@ static void managerd_uninit(struct managerd_ctx *ctx)
//Uninitialize mme part
mme_nl_uninit(ctx);
- //Uninitialize simple connect part
+ /* Uninitialize led part (need "/dev/gpio") */
+ led_uninit (ctx);
+
+ //Uninitialize simple connect part (close "/dev/gpio")
simple_connect_uninit(ctx);
}
@@ -221,6 +366,8 @@ int main(int argc, char **argv)
return -1;
}
+ syslog (LOG_NOTICE, "Manager Daemon Running");
+
// send reset info (VS_MME_RESET.IND)
vs_mme_reset_ind (&ctx);
diff --git a/cleopatre/application/managerd/src/simple_connect.c b/cleopatre/application/managerd/src/simple_connect.c
index e5f5a0edc8..b04edf91b3 100644
--- a/cleopatre/application/managerd/src/simple_connect.c
+++ b/cleopatre/application/managerd/src/simple_connect.c
@@ -30,7 +30,6 @@
#include "nvram.h"
#include "../../linux/gpio.h"
-#include "libspid.h"
#include "simple_connect.h"
/**
@@ -81,11 +80,6 @@ simple_connect_init (struct managerd_ctx *ctx)
ctx->sc_it.gpioit.enable = 1;
ctx->sc_it.gpioit.mask = (1 << SC_BUT_GPIO_NUM);
- /* Set GPIO info for SC LED */
- ctx->led_gpio.gpiodir.num = SC_LED_GPIO_NUM;
- ctx->led_gpio.gpiodir.dir = SPC300_GPIO_DIRECTION_OUTPUT;
- ctx->led_gpio.gpiodir.val = 0;
-
/* Open GPIO device */
if (0 > (ctx->gpio_fd = open (GPIO_DEVICE_NAME, O_RDWR)))
{
@@ -104,13 +98,6 @@ simple_connect_init (struct managerd_ctx *ctx)
ctx->is_sc_available = 1;
}
- /* Set gpio direction for LED */
- if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETDIRECTION,
- (unsigned long*)&ctx->led_gpio)))
- {
- syslog (LOG_WARNING, "cannot call ioctl for LED gpio (%s)", strerror (errno));
- }
-
/* Set GPIO interrupt for SC button */
if (0 > ioctl (ctx->gpio_fd, GPIOIOC_SETIT,
(unsigned long *) &ctx->sc_it))
@@ -146,4 +133,3 @@ simple_connect_uninit (struct managerd_ctx *ctx)
/* Close GPIO device */
close (ctx->gpio_fd);
}
-