Reworked the Rime/Chameleon interface so that packets now always hit Rime before Chameleon. Chameleon is now only called by Rime. This makes packet sniffing easier, and allows for sniffing packets after their header has been processed by Chameleon, thereby making per-packet power profiling much easier to implement

This commit is contained in:
adamdunkels 2010-02-23 18:29:53 +00:00
parent d8cce42d28
commit b746b7fc06
4 changed files with 35 additions and 38 deletions

View File

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rime.h,v 1.25 2010/02/18 21:48:39 adamdunkels Exp $
* $Id: rime.h,v 1.26 2010/02/23 18:29:53 adamdunkels Exp $
*/
/**
@ -89,24 +89,7 @@ int rime_init(void);
*/
void rime_input(void);
/**
* \brief Rime calls this function to send out a packet
*
* This function must be implemented by the driver running
* below Rime. It is called by anonymous broadcast (abc) to
* send out a packet. The packet is consecutive in the
* packetbuf. A pointer to the first byte of the packet is
* obtained from the packetbuf_hdrptr() function. The length
* of the packet to send is obtained with the packetbuf_totlen()
* function.
*
* The driver, which typically is a MAC protocol, may
* queue the packet by using the queuebuf functions.
*/
void rime_driver_send(void);
void rime_set_output(void (*output_function)(void));
void rime_output(void);
int rime_output(struct channel *c);
extern const struct mac_driver *rime_mac;

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: chameleon.c,v 1.8 2010/02/18 21:48:39 adamdunkels Exp $
* $Id: chameleon.c,v 1.9 2010/02/23 18:29:53 adamdunkels Exp $
*/
/**
@ -101,10 +101,10 @@ printhdr(uint8_t *hdr, int len)
}
#endif /* DEBUG */
/*---------------------------------------------------------------------------*/
void
chameleon_input(void)
struct channel *
chameleon_parse(void)
{
struct channel *c;
struct channel *c = NULL;
PRINTF("%d.%d: chameleon_input\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
#if DEBUG
@ -117,16 +117,16 @@ chameleon_input(void)
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channelno);
packetbuf_set_attr(PACKETBUF_ATTR_CHANNEL, c->channelno);
abc_input(c);
} else {
PRINTF("%d.%d: chameleon_input channel not found for incoming packet\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
}
}
return c;
}
/*---------------------------------------------------------------------------*/
int
chameleon_output(struct channel *c)
chameleon_create(struct channel *c)
{
int ret;
@ -141,7 +141,6 @@ chameleon_output(struct channel *c)
printhdr(packetbuf_hdrptr(), packetbuf_hdrlen());
#endif /* DEBUG */
if(ret) {
rime_output();
return 1;
}
}

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: chameleon.h,v 1.2 2009/03/12 21:58:20 adamdunkels Exp $
* $Id: chameleon.h,v 1.3 2010/02/23 18:29:53 adamdunkels Exp $
*/
/**
@ -56,7 +56,7 @@ struct chameleon_module {
void chameleon_init(const struct chameleon_module *header_processing_module);
int chameleon_hdrsize(const struct packetbuf_attrlist attrlist[]);
void chameleon_input(void);
int chameleon_output(struct channel *c);
struct channel *chameleon_parse(void);
int chameleon_create(struct channel *c);
#endif /* __CHAMELEON_H__ */

View File

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rime.c,v 1.25 2010/02/18 21:48:39 adamdunkels Exp $
* $Id: rime.c,v 1.26 2010/02/23 18:29:53 adamdunkels Exp $
*/
/**
@ -79,7 +79,7 @@ const struct mac_driver *rime_mac;
#ifdef RIME_CONF_POLITE_ANNOUNCEMENT_MAX_TIME
#define POLITE_ANNOUNCEMENT_MAX_TIME RIME_CONF_POLITE_ANNOUNCEMENT_MAX_TIME
#else /* RIME_CONF_POLITE_ANNOUNCEMENT_MAX_TIME */
#define POLITE_ANNOUNCEMENT_MAX_TIME CLOCK_SECOND * 64
#define POLITE_ANNOUNCEMENT_MAX_TIME CLOCK_SECOND * 128
#endif /* RIME_CONF_POLITE_ANNOUNCEMENT_MAX_TIME */
@ -102,14 +102,20 @@ static void
input(void)
{
struct rime_sniffer *s;
struct channel *c;
RIMESTATS_ADD(rx);
c = chameleon_parse();
for(s = list_head(sniffers); s != NULL; s = s->next) {
if(s->input_callback != NULL) {
s->input_callback();
}
}
RIMESTATS_ADD(rx);
chameleon_input();
if(c != NULL) {
abc_input(c);
}
}
/*---------------------------------------------------------------------------*/
static void
@ -139,6 +145,9 @@ init(void)
static void
packet_sent(void *ptr, int status, int num_tx)
{
struct channel *c = ptr;
switch(status) {
case MAC_TX_COLLISION:
PRINTF("rime: collision after %d tx\n", num_tx);
@ -152,7 +161,7 @@ packet_sent(void *ptr, int status, int num_tx)
default:
PRINTF("rime: error %d after %d tx\n", status, num_tx);
}
if(status == MAC_TX_OK) {
struct rime_sniffer *s;
/* Call sniffers, but only if the packet was sent. */
@ -162,15 +171,21 @@ packet_sent(void *ptr, int status, int num_tx)
}
}
}
abc_sent(c, status, num_tx);
}
/*---------------------------------------------------------------------------*/
void
rime_output(void)
int
rime_output(struct channel *c)
{
RIMESTATS_ADD(tx);
packetbuf_compact();
if(chameleon_create(c)) {
packetbuf_compact();
NETSTACK_MAC.send(packet_sent, NULL);
NETSTACK_MAC.send(packet_sent, c);
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
const struct mac_driver rime_driver = {