From 0b882cd516d5fa63472ce137b17e015e3a459f1c Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Sun, 17 Mar 2013 10:49:11 +0100 Subject: [PATCH 1/4] Telnetd improvement: allow specifying a maximum silence time and kill the connection after that time. This is to avoid the telnet connection getting stuck forever if the connecting host reboots. --- apps/telnetd/telnetd.c | 22 +++++++++++++++++----- apps/telnetd/telnetd.h | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/telnetd/telnetd.c b/apps/telnetd/telnetd.c index e0967e6c2..95786442b 100644 --- a/apps/telnetd/telnetd.c +++ b/apps/telnetd/telnetd.c @@ -72,8 +72,8 @@ struct telnetd_state { #define STATE_WONT 3 #define STATE_DO 4 #define STATE_DONT 5 - #define STATE_CLOSE 6 + struct timer silence_timer; }; static struct telnetd_state s; @@ -101,6 +101,8 @@ static struct telnetd_buf buf; static uint8_t connected; +#define MAX_SILENCE_TIME (CLOCK_SECOND * 30) + #define MIN(a, b) ((a) < (b)? (a): (b)) /*---------------------------------------------------------------------------*/ static void @@ -357,6 +359,7 @@ telnetd_appcall(void *ts) s.state = STATE_NORMAL; connected = 1; shell_start(); + timer_set(&s.silence_timer, MAX_SILENCE_TIME); ts = (char *)0; } else { uip_send(telnetd_reject_text, strlen(telnetd_reject_text)); @@ -378,9 +381,11 @@ telnetd_appcall(void *ts) connected = 0; } if(uip_acked()) { + timer_set(&s.silence_timer, MAX_SILENCE_TIME); acked(); } if(uip_newdata()) { + timer_set(&s.silence_timer, MAX_SILENCE_TIME); newdata(); } if(uip_rexmit() || @@ -389,15 +394,22 @@ telnetd_appcall(void *ts) uip_connected() || uip_poll()) { senddata(); + if(s.numsent > 0) { + timer_set(&s.silence_timer, MAX_SILENCE_TIME); + } } - } else { if(uip_poll()) { - if(ts == (char *)10) { + if(timer_expired(&s.silence_timer)) { uip_close(); - } else { - tcp_markconn(uip_conn, (char *)ts + 1); + tcp_markconn(uip_conn, NULL); } } } } /*---------------------------------------------------------------------------*/ +void +telnetd_init(void) +{ + process_start(&telnetd_process, NULL); +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/telnetd/telnetd.h b/apps/telnetd/telnetd.h index 3c9d6c015..9db26ebec 100644 --- a/apps/telnetd/telnetd.h +++ b/apps/telnetd/telnetd.h @@ -38,6 +38,8 @@ PROCESS_NAME(telnetd_process); +void telnetd_init(void); + void telnetd_gui_eventhandler(process_event_t ev, process_data_t data); void telnetd_appcall(void *data); void telnetd_gui_init(void); From c9de0e49be2bc38484a16281f3778db0c44b553d Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Sun, 17 Mar 2013 23:34:05 +0100 Subject: [PATCH 2/4] Added a number of default options for ContikiMAC, and allow them to be overridden with contiki-conf.h configuration options --- core/net/mac/contikimac.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/core/net/mac/contikimac.c b/core/net/mac/contikimac.c index 7027c5685..b4cfde02d 100644 --- a/core/net/mac/contikimac.c +++ b/core/net/mac/contikimac.c @@ -55,9 +55,11 @@ #include /* TX/RX cycles are synchronized with neighbor wake periods */ -#ifndef WITH_PHASE_OPTIMIZATION +#ifdef CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION +#define WITH_PHASE_OPTIMIZATION CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION +#else /* CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION */ #define WITH_PHASE_OPTIMIZATION 1 -#endif +#endif /* CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION */ /* Two byte header added to allow recovery of padded short packets */ /* Wireshark will not understand such packets at present */ #ifdef CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER @@ -117,7 +119,7 @@ struct hdr { /* Are we currently receiving a burst? */ static int we_are_receiving_burst = 0; -/* BURST_RECV_TIME is the maximum time a receiver waits for the +/* INTER_PACKET_DEADLINE is the maximum time a receiver waits for the next packet of a burst when FRAME_PENDING is set. */ #define INTER_PACKET_DEADLINE CLOCK_SECOND / 32 @@ -125,15 +127,27 @@ static int we_are_receiving_burst = 0; consists of two or more CCA checks. CCA_COUNT_MAX is the number of CCAs to be done for each periodic channel check. The default is two.*/ +#ifdef CONTIKIMAC_CONF_CCA_COUNT_MAX +#define CCA_COUNT_MAX (CONTIKIMAC_CONF_CCA_COUNT_MAX) +#else #define CCA_COUNT_MAX 2 +#endif /* Before starting a transmission, Contikimac checks the availability of the channel with CCA_COUNT_MAX_TX consecutive CCAs */ +#ifdef CONTIKIMAC_CONF_CCA_COUNT_MAX_TX +#define CCA_COUNT_MAX_TX (CONTIKIMAC_CONF_CCA_COUNT_MAX_TX) +#else #define CCA_COUNT_MAX_TX 6 +#endif /* CCA_CHECK_TIME is the time it takes to perform a CCA check. */ /* Note this may be zero. AVRs have 7612 ticks/sec, but block until cca is done */ +#ifdef CONTIKIMAC_CONF_CCA_CHECK_TIME +#define CCA_CHECK_TIME (CONTIKIMAC_CONF_CCA_CHECK_TIME) +#else #define CCA_CHECK_TIME RTIMER_ARCH_SECOND / 8192 +#endif /* CCA_SLEEP_TIME is the time between two successive CCA checks. */ /* Add 1 when rtimer ticks are coarse */ @@ -177,12 +191,20 @@ static int we_are_receiving_burst = 0; #define GUARD_TIME 10 * CHECK_TIME + CHECK_TIME_TX /* INTER_PACKET_INTERVAL is the interval between two successive packet transmissions */ +#ifdef CONTIKIMAC_CONF_INTER_PACKET_INTERVAL +#define INTER_PACKET_INTERVAL CONTIKIMAC_CONF_INTER_PACKET_INTERVAL +#else #define INTER_PACKET_INTERVAL RTIMER_ARCH_SECOND / 5000 +#endif /* AFTER_ACK_DETECTECT_WAIT_TIME is the time to wait after a potential ACK packet has been detected until we can read it out from the radio. */ +#ifdef CONTIKIMAC_CONF_AFTER_ACK_DETECTECT_WAIT_TIME +#define AFTER_ACK_DETECTECT_WAIT_TIME CONTIKIMAC_CONF_AFTER_ACK_DETECTECT_WAIT_TIME +#else #define AFTER_ACK_DETECTECT_WAIT_TIME RTIMER_ARCH_SECOND / 1500 +#endif /* MAX_PHASE_STROBE_TIME is the time that we transmit repeated packets to a neighbor for which we have a phase lock. */ From ee64780cb64faee3d39d98bee18428860978e226 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Sun, 17 Mar 2013 23:52:14 +0100 Subject: [PATCH 3/4] Allow proactive probing interval to be configured --- core/net/rime/collect.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/net/rime/collect.c b/core/net/rime/collect.c index 6f16b4b4d..d225e1574 100644 --- a/core/net/rime/collect.c +++ b/core/net/rime/collect.c @@ -157,7 +157,11 @@ MEMB(send_queue_memb, struct packetqueue_item, MAX_SENDING_QUEUE); queue, the system periodically sends a dummy packet to potential parents, i.e., neighbors with a lower rtmetric than we have but for which we do not yet have a link quality estimate. */ +#ifdef COLLECT_CONF_PROACTIVE_PROBING_INTERVAL +#define PROACTIVE_PROBING_INTERVAL (random_rand() % (2 * COLLECT_CONF_PROACTIVE_PROBING_INTERVAL)) +#else /* COLLECT_CONF_PROACTIVE_PROBING_INTERVAL */ #define PROACTIVE_PROBING_INTERVAL (random_rand() % CLOCK_SECOND * 60) +#endif /* COLLECT_CONF_PROACTIVE_PROBING_INTERVAL */ #define PROACTIVE_PROBING_REXMITS 15 /* The ANNOUNCEMENT_SCAN_TIME defines for how long the Collect From 03ce7c65cf7f686b60fb3fc226bc3b6a4045796e Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Sun, 17 Mar 2013 23:24:03 +0100 Subject: [PATCH 4/4] Allow platform makefiles to specify APPS to be used, by defining a PLATFORMAPPS variable. --- Makefile.include | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile.include b/Makefile.include index 3abdbb493..f80757b5b 100644 --- a/Makefile.include +++ b/Makefile.include @@ -89,10 +89,11 @@ PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFI ### Include application makefiles ifdef APPS - APPDIRS += ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \ - ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \ - $(APPS)} - APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDIRS), $(DIR)/Makefile.$(APP)}}} + APPDS = ${wildcard ${foreach DIR, $(APPDIRS), ${addprefix $(DIR)/, $(APPS)}}} \ + ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \ + ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \ + $(APPS)} + APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDS), $(DIR)/Makefile.$(APP)}}} -include $(APPINCLUDES) APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)} DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)} @@ -116,6 +117,20 @@ else include $(target_makefile) endif +ifdef PLATFORMAPPS + PLATFORMAPPDS = ${wildcard ${foreach DIR, $(APPDIRS), ${addprefix $(DIR)/, $(PLATFORMAPPS)}}} \ + ${wildcard ${addprefix $(CONTIKI)/apps/, $(PLATFORMAPPS)} \ + ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(PLATFORMAPPS)} \ + $(PLATFORMAPPS)} + PLATFORMAPPINCLUDES = ${foreach APP, $(PLATFORMAPPS), \ + ${wildcard ${foreach DIR, $(PLATFORMAPPDS), $(DIR)/Makefile.$(APP)}}} + -include $(PLATFORMAPPINCLUDES) + PLATFORMAPP_SOURCES = ${foreach APP, $(PLATFORMAPPS), $($(APP)_src)} + CONTIKI_SOURCEFILES += $(PLATFORMAPP_SOURCES) + APPDS += $(PLATFORMAPPDS) +endif + + ### Forward comma-separated list of arbitrary defines to the compiler COMMA := , @@ -129,7 +144,7 @@ CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \ $(CONTIKI_CPU_DIRS)} SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \ - $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDIRS) ${dir $(target_makefile)} + $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDS) ${dir $(target_makefile)} vpath %.c $(SOURCEDIRS) vpath %.S $(SOURCEDIRS)