summaryrefslogtreecommitdiff
path: root/cleopatre
diff options
context:
space:
mode:
authorJulien Lacour2013-10-22 17:25:01 +0200
committerJulien Lacour2013-11-05 16:58:01 +0100
commit17927a5ba56ec1810b3de1b4ed03483fe2b39c1d (patch)
tree17cd52224d2274f66a66ece639f98e45b0272e10 /cleopatre
parente6d9075179d7768248cd6bd35e28990aad391982 (diff)
cleo/app/managerd: manage simple connect push button duration, refs #4257
Diffstat (limited to 'cleopatre')
-rw-r--r--cleopatre/application/managerd/inc/gpio_event.h9
-rw-r--r--cleopatre/application/managerd/src/managerd.c80
2 files changed, 82 insertions, 7 deletions
diff --git a/cleopatre/application/managerd/inc/gpio_event.h b/cleopatre/application/managerd/inc/gpio_event.h
index 280be84f0f..32f36fed1f 100644
--- a/cleopatre/application/managerd/inc/gpio_event.h
+++ b/cleopatre/application/managerd/inc/gpio_event.h
@@ -28,7 +28,14 @@ struct managerd_ctx;
#define SC_BUT_DEBOUNCE 1
/** Simple connect status */
#define SC_BUT_RELEASED 1
-#define SC_BUT_PUSHED (!SC_BUT_RELEASED)
+#define SC_BUT_PRESSED (!SC_BUT_RELEASED)
+/** Timing for Simple connect button features
+ * expressed in WAIT_TOUT count defined in bridge.h
+ * Minimal pressure time is following defines - WAIT_TOUT
+ */
+#define SC_BUT_PRESSED_TIME__RANDOM_KEY 10
+#define SC_BUT_PRESSED_TIME__SC_PROCESS 2
+
/** LED GPIO numbers */
#if !defined (CONFIG_HAVE_POWER_LED)
diff --git a/cleopatre/application/managerd/src/managerd.c b/cleopatre/application/managerd/src/managerd.c
index c5390de9fe..6149ee32b8 100644
--- a/cleopatre/application/managerd/src/managerd.c
+++ b/cleopatre/application/managerd/src/managerd.c
@@ -156,9 +156,11 @@ static int managerd_process(struct managerd_ctx *ctx)
uint8_t *buffer;
int result = 0;
int len;
+ int sc_timer;
//Check arguments
assert(ctx != NULL);
+ sc_timer = 0;
//Allocate buffer for bridge part
buffer = (uint8_t*)malloc(MAX_PKT_LEN);
@@ -196,6 +198,28 @@ static int managerd_process(struct managerd_ctx *ctx)
/* reset errno */
errno = 0;
/* process interrupt */
+ /** When timer throws a SIGALRM, code is handled here.
+ * After an end of simple connect process that failed,
+ * led is blinking fast, timer throws SIGALRM fast.
+ * So, no more timeout happens.
+ * Hence, code is unable to count pressure on simple connect button
+ * by timeout counter 'sc_timer'.
+ * To restart management of simple connect like in initial
+ * conditions, led blinking can be stopped when button is pressed
+ * and if simple connect process is finished:
+ */
+ if (simple_connect_button_status_get(ctx) == SC_BUT_PRESSED
+ && !ctx->hpav_info.is_sc)
+ {
+ if (0 > led_attachment_event (
+ ctx,
+ LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED,
+ LIBSPID_FALSE))
+ {
+ syslog (LOG_WARNING, "led attachment event failed");
+ return -1;
+ }
+ }
}
else
{
@@ -205,7 +229,21 @@ static int managerd_process(struct managerd_ctx *ctx)
}
else if (0 == result)
{
- /* No reception coming */
+ /** No reception coming:
+ * Use select timeout to count the duration
+ * during simple connect button is pressed
+ */
+ if (simple_connect_button_status_get (ctx) == SC_BUT_RELEASED)
+ {
+ sc_timer = 0;
+ }
+ else
+ {
+ if (sc_timer == 0)
+ // Initialise a new random generator.
+ managerd_random_seed ();
+ sc_timer ++;
+ }
}
else if (FD_ISSET (ctx->sock_br, &readfds)
|| FD_ISSET (ctx->sock_lo, &readfds))
@@ -248,11 +286,41 @@ static int managerd_process(struct managerd_ctx *ctx)
}
else if (FD_ISSET (ctx->gpio_fd, &exceptfds))
{
- /* Manage simple connect */
- if (0 > simple_connect_event (ctx))
- break;
- else
- continue;
+ /* Manage simple connect button */
+ if (sc_timer >= SC_BUT_PRESSED_TIME__RANDOM_KEY)
+ {
+ int ret = 0;
+ unsigned char npw[LIBSPID_HPAV_CONF_NPW_MIN_LEN] = {0};
+ managerd_random_npw_generate (npw);
+ ret = libspid_secu_nmk_update (npw);
+ /* save hpav.conf and inform plc daemon */
+ if (ret == LIBSPID_SUCCESS)
+ {
+ ret = libspid_system_save_file (LIBSPID_HPAV_CONF_PATH);
+ }
+ if (ret == LIBSPID_SUCCESS)
+ {
+ ret = libspid_system_file_update_warn (
+ getpid(), LIBSPID_HPAV_CONF_PATH);
+ }
+ if (ret != LIBSPID_SUCCESS)
+ {
+ syslog (LOG_ERR,
+ "RANDOM KEY GENERATION: \
+ libspid system or secu error\n");
+ return -1;
+ }
+ syslog (LOG_NOTICE, "SC: NMK updated randomly\n");
+ }
+ else if (sc_timer >= SC_BUT_PRESSED_TIME__SC_PROCESS)
+ {
+ sc_timer = 0;
+ if (0 > simple_connect_event (ctx))
+ break;
+ else
+ continue;
+ }
+ sc_timer = 0;
}
if (is_process_signal_needed)