From 24b17e58b14c06d507fe5aebc6ed4cd576de8288 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 02:24:47 +0000 Subject: [PATCH 1/9] Remove dead code and obsolete comments --- os/dev/slip.c | 68 ++------------------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) diff --git a/os/dev/slip.c b/os/dev/slip.c index b27dca332..42a34be7b 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -38,8 +38,6 @@ #include "contiki.h" #include "net/ipv6/uip.h" -#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) - #include "dev/slip.h" #define SLIP_END 0300 @@ -92,9 +90,6 @@ slip_set_input_callback(void (*c)(void)) input_callback = c; } /*---------------------------------------------------------------------------*/ -/* slip_send: forward (IPv4) packets with {UIP_FW_NETIF(..., slip_send)} - * was used in slip-bridge.c - */ uint8_t slip_send(void) { @@ -153,56 +148,9 @@ rxbuf_init(void) state = STATE_OK; } /*---------------------------------------------------------------------------*/ -/* Upper half does the polling. */ static uint16_t slip_poll_handler(uint8_t *outbuf, uint16_t blen) { -#ifdef SLIP_CONF_MICROSOFT_CHAT - /* This is a hack and won't work across buffer edge! */ - if(rxbuf[begin] == 'C') { - int i; - if(begin < next_free && (next_free - begin) >= 6 - && memcmp(&rxbuf[begin], "CLIENT", 6) == 0) { - state = STATE_TWOPACKETS; /* Interrupts do nothing. */ - memset(&rxbuf[begin], 0x0, 6); - - rxbuf_init(); - - for(i = 0; i < 13; i++) { - slip_arch_writeb("CLIENTSERVER\300"[i]); - } - return 0; - } - } -#endif /* SLIP_CONF_MICROSOFT_CHAT */ - -#ifdef SLIP_CONF_ANSWER_MAC_REQUEST - else if(rxbuf[begin] == '?') { - /* Used by tapslip6 to request mac for auto configure */ - int i, j; - char* hexchar = "0123456789abcdef"; - if(begin < next_free && (next_free - begin) >= 2 - && rxbuf[begin + 1] == 'M') { - state = STATE_TWOPACKETS; /* Interrupts do nothing. */ - rxbuf[begin] = 0; - rxbuf[begin + 1] = 0; - - rxbuf_init(); - - linkaddr_t addr = get_mac_addr(); - /* this is just a test so far... just to see if it works */ - slip_arch_writeb('!'); - slip_arch_writeb('M'); - for(j = 0; j < 8; j++) { - slip_arch_writeb(hexchar[addr.u8[j] >> 4]); - slip_arch_writeb(hexchar[addr.u8[j] & 15]); - } - slip_arch_writeb(SLIP_END); - return 0; - } - } -#endif /* SLIP_CONF_ANSWER_MAC_REQUEST */ - /* * Interrupt can not change begin but may change pkt_end. * If pkt_end != begin it will not change again. @@ -338,11 +286,7 @@ PROCESS_THREAD(slip_process, ev, data) if(input_callback) { input_callback(); } -#ifdef SLIP_CONF_TCPIP_INPUT - SLIP_CONF_TCPIP_INPUT(); -#else tcpip_input(); -#endif } } @@ -389,22 +333,14 @@ slip_input_byte(unsigned char c) } rxbuf[cur_end] = c; -#ifdef SLIP_CONF_MICROSOFT_CHAT - /* There could be a separate poll routine for this. */ - if(c == 'T' && rxbuf[begin] == 'C') { - process_poll(&slip_process); - return 1; - } -#endif /* SLIP_CONF_MICROSOFT_CHAT */ - if(c == SLIP_END) { /* * We have a new packet, possibly of zero length. * * There may already be one packet buffered. */ - if(cur_end != pkt_end) { /* Non zero length. */ - if(begin == pkt_end) { /* None buffered. */ + if(cur_end != pkt_end) { /* Non zero length. */ + if(begin == pkt_end) { /* None buffered. */ pkt_end = cur_end; } else { SLIP_STATISTICS(slip_twopackets++); From 4522b5b9425ef2742d3018f1cdf83defc8dd6415 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 02:26:31 +0000 Subject: [PATCH 2/9] Tidy-up file structure and code style --- os/dev/slip.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/os/dev/slip.c b/os/dev/slip.c index 42a34be7b..6385a6e5e 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -26,46 +26,42 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * */ - - -#include -#include - +/*---------------------------------------------------------------------------*/ #include "contiki.h" - #include "net/ipv6/uip.h" #include "dev/slip.h" +#include +#include +/*---------------------------------------------------------------------------*/ #define SLIP_END 0300 #define SLIP_ESC 0333 #define SLIP_ESC_END 0334 #define SLIP_ESC_ESC 0335 - +/*---------------------------------------------------------------------------*/ PROCESS(slip_process, "SLIP driver"); uint8_t slip_active; +/*---------------------------------------------------------------------------*/ #if 1 #define SLIP_STATISTICS(statement) #else uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; #define SLIP_STATISTICS(statement) statement #endif - +/*---------------------------------------------------------------------------*/ /* Must be at least one byte larger than UIP_BUFSIZE! */ #define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16) - +/*---------------------------------------------------------------------------*/ enum { - STATE_TWOPACKETS = 0, /* We have 2 packets and drop incoming data. */ + STATE_TWOPACKETS = 0, /* We have 2 packets and drop incoming data. */ STATE_OK = 1, STATE_ESC = 2, STATE_RUBBISH = 3, }; - +/*---------------------------------------------------------------------------*/ /* * Variables begin and end manage the buffer space in a cyclic * fashion. The first used byte is at begin and end is one byte past @@ -76,13 +72,12 @@ enum { * [pkt_end, end). If more bytes arrive in state STATE_TWOPACKETS * they are discarded. */ - static uint8_t state = STATE_TWOPACKETS; static uint16_t begin, next_free; static uint8_t rxbuf[RX_BUFSIZE]; -static uint16_t pkt_end; /* SLIP_END tracker. */ +static uint16_t pkt_end; /* SLIP_END tracker. */ -static void (* input_callback)(void) = NULL; +static void (*input_callback)(void) = NULL; /*---------------------------------------------------------------------------*/ void slip_set_input_callback(void (*c)(void)) @@ -169,7 +164,7 @@ slip_poll_handler(uint8_t *outbuf, uint16_t blen) len = 0; break; } - if (esc) { + if(esc) { if(rxbuf[i] == SLIP_ESC_ESC) { outbuf[len] = SLIP_ESC; len++; @@ -193,7 +188,7 @@ slip_poll_handler(uint8_t *outbuf, uint16_t blen) len = 0; break; } - if (esc) { + if(esc) { if(rxbuf[i] == SLIP_ESC_ESC) { outbuf[len] = SLIP_ESC; len++; @@ -214,7 +209,7 @@ slip_poll_handler(uint8_t *outbuf, uint16_t blen) len = 0; break; } - if (esc) { + if(esc) { if(rxbuf[i] == SLIP_ESC_ESC) { outbuf[len] = SLIP_ESC; len++; @@ -280,7 +275,7 @@ PROCESS_THREAD(slip_process, ev, data) /* Move packet from rxbuf to buffer provided by uIP. */ uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN], - UIP_BUFSIZE - UIP_LLH_LEN); + UIP_BUFSIZE - UIP_LLH_LEN); if(uip_len > 0) { if(input_callback) { @@ -308,7 +303,7 @@ slip_input_byte(unsigned char c) if(c != SLIP_ESC_END && c != SLIP_ESC_ESC) { state = STATE_RUBBISH; SLIP_STATISTICS(slip_rubbish++); - next_free = pkt_end; /* remove rubbish */ + next_free = pkt_end; /* remove rubbish */ return 0; } state = STATE_OK; From 7fd76dc23ec4a90dd273ccb44342d4fc52fe4189 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 02:26:42 +0000 Subject: [PATCH 3/9] Change variables to static --- os/dev/slip.c | 7 +++---- os/dev/slip.h | 6 ------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/os/dev/slip.c b/os/dev/slip.c index 6385a6e5e..17404bf1b 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -41,14 +41,13 @@ #define SLIP_ESC_ESC 0335 /*---------------------------------------------------------------------------*/ PROCESS(slip_process, "SLIP driver"); - -uint8_t slip_active; - +/*---------------------------------------------------------------------------*/ +static uint8_t slip_active; /*---------------------------------------------------------------------------*/ #if 1 #define SLIP_STATISTICS(statement) #else -uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; +static uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; #define SLIP_STATISTICS(statement) statement #endif /*---------------------------------------------------------------------------*/ diff --git a/os/dev/slip.h b/os/dev/slip.h index 759de1a46..75ae58fd8 100644 --- a/os/dev/slip.h +++ b/os/dev/slip.h @@ -64,12 +64,6 @@ int slip_input_byte(unsigned char c); uint8_t slip_write(const void *ptr, int len); -/* Did we receive any bytes lately? */ -extern uint8_t slip_active; - -/* Statistics. */ -extern uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; - /** * Set a function to be called when there is activity on the SLIP * interface; used for detecting if a node is a gateway node. From 8f2fa80401c2becc7ffd7fbbec438ed609ffae18 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 02:29:11 +0000 Subject: [PATCH 4/9] Make SLIP stats properly configurable --- os/dev/slip.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/os/dev/slip.c b/os/dev/slip.c index 17404bf1b..4b7021d89 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -44,11 +44,11 @@ PROCESS(slip_process, "SLIP driver"); /*---------------------------------------------------------------------------*/ static uint8_t slip_active; /*---------------------------------------------------------------------------*/ -#if 1 -#define SLIP_STATISTICS(statement) -#else +#if SLIP_CONF_WITH_STATS static uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; #define SLIP_STATISTICS(statement) statement +#else +#define SLIP_STATISTICS(statement) #endif /*---------------------------------------------------------------------------*/ /* Must be at least one byte larger than UIP_BUFSIZE! */ From 38df9fdfb24aa7ac1c7e71c63a2147525b16d80e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 02:45:00 +0000 Subject: [PATCH 5/9] Change slip_write return type and use it where possible --- examples/slip-radio/project-conf.h | 2 +- examples/slip-radio/slip-net.c | 23 +---------------------- examples/slip-radio/slip-radio.c | 8 -------- os/dev/slip.c | 5 ++--- os/dev/slip.h | 2 +- 5 files changed, 5 insertions(+), 35 deletions(-) diff --git a/examples/slip-radio/project-conf.h b/examples/slip-radio/project-conf.h index 89e135a42..2f05bec5e 100644 --- a/examples/slip-radio/project-conf.h +++ b/examples/slip-radio/project-conf.h @@ -37,7 +37,7 @@ /*---------------------------------------------------------------------------*/ #define UIP_CONF_ROUTER 0 -#define CMD_CONF_OUTPUT slip_radio_cmd_output +#define CMD_CONF_OUTPUT slip_write /* Default CMD handlers if the target did not specify them */ #ifndef CMD_CONF_HANDLERS diff --git a/examples/slip-radio/slip-net.c b/examples/slip-radio/slip-net.c index 1a787c85c..e1efbf4cf 100644 --- a/examples/slip-radio/slip-net.c +++ b/examples/slip-radio/slip-net.c @@ -49,27 +49,6 @@ slipnet_init(void) { } /*---------------------------------------------------------------------------*/ -void -slip_send_packet(const uint8_t *ptr, int len) -{ - uint16_t i; - uint8_t c; - - slip_arch_writeb(SLIP_END); - for(i = 0; i < len; ++i) { - c = *ptr++; - if(c == SLIP_END) { - slip_arch_writeb(SLIP_ESC); - c = SLIP_ESC_END; - } else if(c == SLIP_ESC) { - slip_arch_writeb(SLIP_ESC); - c = SLIP_ESC_ESC; - } - slip_arch_writeb(c); - } - slip_arch_writeb(SLIP_END); -} -/*---------------------------------------------------------------------------*/ static void slipnet_input(void) { @@ -94,7 +73,7 @@ slipnet_input(void) } LOG_DBG_("\n"); - slip_send_packet(uip_buf, uip_len); + slip_write(uip_buf, uip_len); } /*---------------------------------------------------------------------------*/ static uint8_t diff --git a/examples/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index 720bc9694..53a0324bc 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -56,8 +56,6 @@ extern const struct slip_radio_sensors SLIP_RADIO_CONF_SENSORS; #endif -void slip_send_packet(const uint8_t *ptr, int len); - /* max 16 packets at the same time??? */ uint8_t packet_ids[16]; int packet_pos; @@ -187,12 +185,6 @@ slip_radio_cmd_handler(const uint8_t *data, int len) return 0; } /*---------------------------------------------------------------------------*/ -void -slip_radio_cmd_output(const uint8_t *data, int data_len) -{ - slip_send_packet(data, data_len); -} -/*---------------------------------------------------------------------------*/ static void slip_input_callback(void) { diff --git a/os/dev/slip.c b/os/dev/slip.c index 4b7021d89..076685d58 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -110,7 +110,7 @@ slip_send(void) return UIP_FW_OK; } /*---------------------------------------------------------------------------*/ -uint8_t +void slip_write(const void *_ptr, int len) { const uint8_t *ptr = _ptr; @@ -130,9 +130,8 @@ slip_write(const void *_ptr, int len) } slip_arch_writeb(c); } - slip_arch_writeb(SLIP_END); - return len; + slip_arch_writeb(SLIP_END); } /*---------------------------------------------------------------------------*/ static void diff --git a/os/dev/slip.h b/os/dev/slip.h index 75ae58fd8..1a9fb68ce 100644 --- a/os/dev/slip.h +++ b/os/dev/slip.h @@ -62,7 +62,7 @@ uint8_t slip_send(void); */ int slip_input_byte(unsigned char c); -uint8_t slip_write(const void *ptr, int len); +void slip_write(const void *ptr, int len); /** * Set a function to be called when there is activity on the SLIP From 3e93e216466e91f95c687e1aad1eaeaeeffe84cf Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 16:13:48 +0000 Subject: [PATCH 6/9] Change return type of slip_send to void The return value was not checked anywhere in the code --- os/dev/slip.c | 2 +- os/dev/slip.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/os/dev/slip.c b/os/dev/slip.c index 076685d58..db2e26ee4 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -84,7 +84,7 @@ slip_set_input_callback(void (*c)(void)) input_callback = c; } /*---------------------------------------------------------------------------*/ -uint8_t +void slip_send(void) { uint16_t i; diff --git a/os/dev/slip.h b/os/dev/slip.h index 1a9fb68ce..d4450d533 100644 --- a/os/dev/slip.h +++ b/os/dev/slip.h @@ -41,7 +41,7 @@ PROCESS_NAME(slip_process); /** * Send an IP packet from the uIP buffer with SLIP. */ -uint8_t slip_send(void); +void slip_send(void); /** * Input a SLIP byte. From f9e17a6c7682b70c1896f642e4ce47d06794cc28 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 16:14:02 +0000 Subject: [PATCH 7/9] Document slip_write --- os/dev/slip.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/os/dev/slip.h b/os/dev/slip.h index d4450d533..bb0ca3baf 100644 --- a/os/dev/slip.h +++ b/os/dev/slip.h @@ -62,6 +62,9 @@ void slip_send(void); */ int slip_input_byte(unsigned char c); +/** + * Send using SLIP len bytes starting from the location pointed to by ptr + */ void slip_write(const void *ptr, int len); /** From 1ba2eac5cbbe2d753817d5a98f86ad6e5567bc68 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 16:14:38 +0000 Subject: [PATCH 8/9] Use slip_write to slip_send --- os/dev/slip.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/os/dev/slip.c b/os/dev/slip.c index db2e26ee4..3cfe9ea07 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -87,27 +87,7 @@ slip_set_input_callback(void (*c)(void)) void slip_send(void) { - uint16_t i; - uint8_t *ptr; - uint8_t c; - - slip_arch_writeb(SLIP_END); - - ptr = &uip_buf[UIP_LLH_LEN]; - for(i = 0; i < uip_len; ++i) { - c = *ptr++; - if(c == SLIP_END) { - slip_arch_writeb(SLIP_ESC); - c = SLIP_ESC_END; - } else if(c == SLIP_ESC) { - slip_arch_writeb(SLIP_ESC); - c = SLIP_ESC_ESC; - } - slip_arch_writeb(c); - } - slip_arch_writeb(SLIP_END); - - return UIP_FW_OK; + slip_write(&uip_buf[UIP_LLH_LEN], uip_len); } /*---------------------------------------------------------------------------*/ void From 065bad280d02fcc3aa386ca5bcd14a2594deb0e0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 17:03:41 +0000 Subject: [PATCH 9/9] Adjust return types of JN516x-specific slip implementation --- arch/platform/jn516x/lib/slip.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/platform/jn516x/lib/slip.c b/arch/platform/jn516x/lib/slip.c index 8e66c5f66..a5ce4c16d 100644 --- a/arch/platform/jn516x/lib/slip.c +++ b/arch/platform/jn516x/lib/slip.c @@ -167,7 +167,7 @@ slip_write_char(uint8_t c) slip_arch_writeb(c); } /*---------------------------------------------------------------------------*/ -uint8_t +void slip_write(const void *_ptr, int len) { const uint8_t *ptr = _ptr; @@ -181,14 +181,12 @@ slip_write(const void *_ptr, int len) slip_write_char(c); } slip_arch_writeb(SLIP_END); - - return len; } /*---------------------------------------------------------------------------*/ /* slip_send: forward (IPv4) packets with {UIP_FW_NETIF(..., slip_send)} * was used in slip-bridge.c */ -uint8_t +void slip_send(void) { uint16_t i; @@ -203,8 +201,6 @@ slip_send(void) slip_write_char(c); } slip_arch_writeb(SLIP_END); - - return UIP_FW_OK; } /*---------------------------------------------------------------------------*/ static void