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,10 +196,12 @@ 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];
}
}
}
@ -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

@ -1,35 +1,35 @@
/* -*- C -*- */
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* 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 SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* 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.
*
* @(#)$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__
@ -59,7 +59,7 @@ u8_t slip_send(void);
*
* \param c The data that is to be passed to the SLIP driver
*
* \return Non-zero if the CPU should be powered up, zero otherwise.
* \return Non-zero if the CPU should be powered up, zero otherwise.
*/
int slip_input_byte(unsigned char c);
@ -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).