Added a function that gets called when we see SLIP input. This function can be used to determine if a node is a SLIP gateway or not.

This commit is contained in:
adamdunkels 2008-02-24 21:00:53 +00:00
parent 8906441004
commit af48b648ee
2 changed files with 48 additions and 32 deletions

View File

@ -29,7 +29,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: slip.c,v 1.6 2008/02/03 20:43:35 adamdunkels Exp $
* @(#)$Id: slip.c,v 1.7 2008/02/24 21:00:53 adamdunkels Exp $
*/
@ -86,7 +86,13 @@ static u16_t begin, end;
static u8_t rxbuf[RX_BUFSIZE];
static u16_t pkt_end; /* SLIP_END tracker. */
static void (* input_callback)(void) = NULL;
/*---------------------------------------------------------------------------*/
void
slip_set_input_callback(void (*c)(void))
{
input_callback = c;
}
/*---------------------------------------------------------------------------*/
u8_t
slip_send(void)
@ -116,7 +122,7 @@ slip_send(void)
return UIP_FW_OK;
}
/*---------------------------------------------------------------------------*/
u8_t
slip_write(const void *_ptr, int len)
{
@ -141,7 +147,6 @@ slip_write(const void *_ptr, int len)
return len;
}
/*---------------------------------------------------------------------------*/
static void
rxbuf_init(void)
@ -191,12 +196,14 @@ slip_poll_handler(u8_t *outbuf, u16_t blen)
len = 0;
} else {
unsigned i;
for(i = begin; i < RX_BUFSIZE; i++)
for(i = begin; i < RX_BUFSIZE; i++) {
*outbuf++ = rxbuf[i];
for(i = 0; i < pkt_end; i++)
}
for(i = 0; i < pkt_end; i++) {
*outbuf++ = rxbuf[i];
}
}
}
/* Remove data from buffer together with the copied packet. */
begin = pkt_end;
@ -232,6 +239,9 @@ PROCESS_THREAD(slip_process, ev, data)
char buf[8];
memcpy(&buf[0], "=IPA", 4);
memcpy(&buf[4], &uip_hostaddr, 4);
if(input_callback) {
input_callback();
}
slip_write(buf, 8);
} else if(uip_len > 0
&& uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])

View File

@ -29,7 +29,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: slip.h,v 1.4 2007/02/02 13:26:48 bg- Exp $
* @(#)$Id: slip.h,v 1.5 2008/02/24 21:00:53 adamdunkels Exp $
*/
#ifndef __SLIP_H__
@ -71,6 +71,12 @@ extern u8_t slip_active;
/* Statistics. */
extern u16_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.
*/
void slip_set_input_callback(void (*callback)(void));
/*
* These machine dependent functions and an interrupt service routine
* must be provided externally (slip_arch.c).