Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Rime buffer management

The packetbuf module does Rime's buffer management.

Data Structures

struct  packetbuf_addr
 
struct  packetbuf_attr
 
struct  packetbuf_attrlist
 

Files

file  packetbuf.c
 
    Rime buffer (packetbuf) management

 
file  packetbuf.h
 
    Header file for the Rime buffer (packetbuf) management

 

Macros

#define _DEBUG_   0
 
#define DEBUG_LEVEL   0
 
#define PACKETBUF_ADDR_FIRST   PACKETBUF_ADDR_SENDER
 
#define PACKETBUF_ADDRSIZE   (sizeof(linkaddr_t) * PACKETBUF_ATTR_BYTE)
 
#define PACKETBUF_ATTR_BIT   1
 
#define PACKETBUF_ATTR_BYTE   8
 
#define PACKETBUF_ATTR_LAST   { PACKETBUF_ATTR_NONE, 0 }
 
#define PACKETBUF_ATTR_PACKET_TYPE_ACK   1
 
#define PACKETBUF_ATTR_PACKET_TYPE_DATA   0
 
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM   2
 
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END   3
 
#define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP   4
 
#define PACKETBUF_ATTRIBUTES(...)   { __VA_ARGS__ PACKETBUF_ATTR_LAST }
 
#define PACKETBUF_HDR_SIZE   48
 The size of the packetbuf header, in bytes. More...
 
#define PACKETBUF_IS_ADDR(type)   ((type) >= PACKETBUF_ADDR_FIRST)
 
#define PACKETBUF_NUM_ADDRS   4
 
#define PACKETBUF_NUM_ATTRS   (PACKETBUF_ATTR_MAX - PACKETBUF_NUM_ADDRS)
 
#define PACKETBUF_SIZE   128
 The size of the packetbuf, in bytes. More...
 
#define PRINTF(...)
 

Typedefs

typedef uint16_t packetbuf_attr_t
 

Enumerations

enum  {
  PACKETBUF_ATTR_NONE,
  PACKETBUF_ATTR_CHANNEL,
  PACKETBUF_ATTR_NETWORK_ID,
  PACKETBUF_ATTR_LINK_QUALITY,
  PACKETBUF_ATTR_RSSI,
  PACKETBUF_ATTR_TIMESTAMP,
  PACKETBUF_ATTR_RADIO_TXPOWER,
  PACKETBUF_ATTR_LISTEN_TIME,
  PACKETBUF_ATTR_TRANSMIT_TIME,
  PACKETBUF_ATTR_MAC_TRANSMISSIONS,
  PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS,
  PACKETBUF_ATTR_MAC_SEQNO,
  PACKETBUF_ATTR_MAC_ACK,
  PACKETBUF_ATTR_MAC_PIGGYBACK_LEN,
  PACKETBUF_ATTR_MAC_FRAMETYPE,
  PACKETBUF_ATTR_NET_ID,
  PACKETBUF_ATTR_RELIABLE,
  PACKETBUF_ATTR_PACKET_ID,
  PACKETBUF_ATTR_PACKET_TYPE,
  PACKETBUF_ATTR_REXMIT,
  PACKETBUF_ATTR_MAX_REXMIT,
  PACKETBUF_ATTR_NUM_REXMIT,
  PACKETBUF_ATTR_PENDING,
  PACKETBUF_ATTR_HOPS,
  PACKETBUF_ATTR_TTL,
  PACKETBUF_ATTR_EPACKET_ID,
  PACKETBUF_ATTR_EPACKET_TYPE,
  PACKETBUF_ATTR_ERELIABLE,
  PACKETBUF_ADDR_SENDER,
  PACKETBUF_ADDR_RECEIVER,
  PACKETBUF_ADDR_ESENDER,
  PACKETBUF_ADDR_ERECEIVER,
  PACKETBUF_ATTR_MAX
}
 

Functions

const linkaddr_tpacketbuf_addr (uint8_t type)
 
packetbuf_attr_t packetbuf_attr (uint8_t type)
 
void packetbuf_attr_clear (void)
 
void packetbuf_attr_copyfrom (struct packetbuf_attr *attrs, struct packetbuf_addr *addrs)
 
void packetbuf_attr_copyto (struct packetbuf_attr *attrs, struct packetbuf_addr *addrs)
 
void packetbuf_clear (void)
 Clear and reset the packetbuf. More...
 
void packetbuf_clear_hdr (void)
 Clear and reset the header of the packetbuf. More...
 
void packetbuf_compact (void)
 Compact the packetbuf. More...
 
int packetbuf_copyfrom (const void *from, uint16_t len)
 Copy from external data into the packetbuf. More...
 
int packetbuf_copyto (void *to)
 Copy the entire packetbuf to an external buffer. More...
 
int packetbuf_copyto_hdr (uint8_t *to)
 Copy the header portion of the packetbuf to an external buffer. More...
 
uint16_t packetbuf_datalen (void)
 Get the length of the data in the packetbuf. More...
 
void * packetbuf_dataptr (void)
 Get a pointer to the data in the packetbuf. More...
 
void packetbuf_hdr_remove (int size)
 
int packetbuf_hdralloc (int size)
 Extend the header of the packetbuf, for outbound packets. More...
 
uint8_t packetbuf_hdrlen (void)
 Get the length of the header in the packetbuf, for outbound packets. More...
 
void * packetbuf_hdrptr (void)
 Get a pointer to the header in the packetbuf, for outbound packets. More...
 
int packetbuf_hdrreduce (int size)
 Reduce the header in the packetbuf, for incoming packets. More...
 
int packetbuf_is_reference (void)
 Check if the packetbuf references external data. More...
 
void packetbuf_reference (void *ptr, uint16_t len)
 Point the packetbuf to external data. More...
 
void * packetbuf_reference_ptr (void)
 Get a pointer to external data referenced by the packetbuf. More...
 
int packetbuf_set_addr (uint8_t type, const linkaddr_t *addr)
 
int packetbuf_set_attr (uint8_t type, const packetbuf_attr_t val)
 
void packetbuf_set_datalen (uint16_t len)
 Set the length of the data in the packetbuf. More...
 
uint16_t packetbuf_totlen (void)
 Get the total length of the header and data in the packetbuf. More...
 

Variables

static uint16_t buflen
 
static uint16_t bufptr
 
static uint8_t hdrptr
 
static uint8_t * packetbuf = (uint8_t *)packetbuf_aligned
 
struct packetbuf_addr packetbuf_addrs [PACKETBUF_NUM_ADDRS]
 
static uint16_t packetbuf_aligned [(PACKETBUF_SIZE+PACKETBUF_HDR_SIZE)/2+1]
 
struct packetbuf_attr packetbuf_attrs [PACKETBUF_NUM_ATTRS]
 
static uint8_t * packetbufptr
 

#define _DEBUG_   0
#define DEBUG_LEVEL   0
#define PACKETBUF_ADDR_FIRST   PACKETBUF_ADDR_SENDER
#define PACKETBUF_ADDRSIZE   (sizeof(linkaddr_t) * PACKETBUF_ATTR_BYTE)
#define PACKETBUF_ATTR_BIT   1
#define PACKETBUF_ATTR_BYTE   8
#define PACKETBUF_ATTR_LAST   { PACKETBUF_ATTR_NONE, 0 }
#define PACKETBUF_ATTR_PACKET_TYPE_ACK   1

Referenced by send_packet().

#define PACKETBUF_ATTR_PACKET_TYPE_DATA   0
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM   2

Referenced by output().

#define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END   3

Referenced by output().

#define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP   4
#define PACKETBUF_ATTRIBUTES (   ...)    { __VA_ARGS__ PACKETBUF_ATTR_LAST }
#define PACKETBUF_HDR_SIZE   48
#define PACKETBUF_IS_ADDR (   type)    ((type) >= PACKETBUF_ADDR_FIRST)
#define PACKETBUF_NUM_ADDRS   4

Referenced by packetbuf_attr_clear().

#define PACKETBUF_NUM_ATTRS   (PACKETBUF_ATTR_MAX - PACKETBUF_NUM_ADDRS)

Referenced by packetbuf_attr_clear().

#define PACKETBUF_SIZE   128

The size of the packetbuf, in bytes.

Referenced by packetbuf_copyfrom(), packetbuf_copyto(), packetbuf_hdralloc(), and PROCESS_THREAD().

#define PRINTF (   ...)

typedef uint16_t packetbuf_attr_t

anonymous enum
Enumerator
PACKETBUF_ATTR_NONE 
PACKETBUF_ATTR_CHANNEL 
PACKETBUF_ATTR_NETWORK_ID 
PACKETBUF_ATTR_LINK_QUALITY 
PACKETBUF_ATTR_RSSI 
PACKETBUF_ATTR_TIMESTAMP 
PACKETBUF_ATTR_RADIO_TXPOWER 
PACKETBUF_ATTR_LISTEN_TIME 
PACKETBUF_ATTR_TRANSMIT_TIME 
PACKETBUF_ATTR_MAC_TRANSMISSIONS 
PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS 
PACKETBUF_ATTR_MAC_SEQNO 
PACKETBUF_ATTR_MAC_ACK 
PACKETBUF_ATTR_MAC_PIGGYBACK_LEN 
PACKETBUF_ATTR_MAC_FRAMETYPE 
PACKETBUF_ATTR_NET_ID 
PACKETBUF_ATTR_RELIABLE 
PACKETBUF_ATTR_PACKET_ID 
PACKETBUF_ATTR_PACKET_TYPE 
PACKETBUF_ATTR_REXMIT 
PACKETBUF_ATTR_MAX_REXMIT 
PACKETBUF_ATTR_NUM_REXMIT 
PACKETBUF_ATTR_PENDING 
PACKETBUF_ATTR_HOPS 
PACKETBUF_ATTR_TTL 
PACKETBUF_ATTR_EPACKET_ID 
PACKETBUF_ATTR_EPACKET_TYPE 
PACKETBUF_ATTR_ERELIABLE 
PACKETBUF_ADDR_SENDER 
PACKETBUF_ADDR_RECEIVER 
PACKETBUF_ADDR_ESENDER 
PACKETBUF_ADDR_ERECEIVER 
PACKETBUF_ATTR_MAX 

void packetbuf_attr_copyfrom ( struct packetbuf_attr attrs,
struct packetbuf_addr addrs 
)
void packetbuf_attr_copyto ( struct packetbuf_attr attrs,
struct packetbuf_addr addrs 
)
void packetbuf_clear ( void  )

Clear and reset the packetbuf.

This function clears the packetbuf and resets all internal state pointers (header size, header pointer, external data pointer). It is used before preparing a packet in the packetbuf.

References buflen, bufptr, hdrptr, packetbuf, packetbuf_attr_clear(), PACKETBUF_HDR_SIZE, and packetbufptr.

Referenced by netstack_aes_decrypt(), netstack_aes_encrypt(), output(), packetbuf_copyfrom(), packetbuf_reference(), PROCESS_THREAD(), and queuebuf_to_packetbuf().

void packetbuf_clear_hdr ( void  )

Clear and reset the header of the packetbuf.

This function clears the header of the packetbuf and resets all the internal state pointers pertaining to the header (header size, header pointer, but not external data pointer). It is used before after sending a packet in the packetbuf, to be able to reuse the packet buffer for a later retransmission.

References hdrptr, and PACKETBUF_HDR_SIZE.

void packetbuf_compact ( void  )

Compact the packetbuf.

This function compacts the packetbuf by copying the data portion of the packetbuf so that becomes consecutive to the header. It also copies external data that has previously been referenced with packetbuf_reference() into the packetbuf.

This function is called by the Rime code before a packet is to be sent by a device driver. This assures that the entire packet is consecutive in memory.

References bufptr, i, len, packetbuf, packetbuf_datalen(), PACKETBUF_HDR_SIZE, packetbuf_is_reference(), and packetbuf_reference_ptr().

Referenced by netstack_aes_encrypt(), and send_packet().

int packetbuf_copyfrom ( const void *  from,
uint16_t  len 
)

Copy from external data into the packetbuf.

Parameters
fromA pointer to the data from which to copy
lenThe size of the data to copy
Return values
Thenumber of bytes that was copied into the packetbuf
        This function copies data from a pointer into the
        packetbuf. If the data that is to be copied is larger
        than the packetbuf, only the data that fits in the
        packetbuf is copied. The number of bytes that could be
        copied into the rimbuf is returned.

References buflen, len, packetbuf_clear(), PACKETBUF_SIZE, and packetbufptr.

Referenced by copy_packet(), queuebuf_to_packetbuf(), uip_over_mesh_make_announced_gateway(), and uip_over_mesh_send().

int packetbuf_copyto ( void *  to)

Copy the entire packetbuf to an external buffer.

Parameters
toA pointer to the buffer to which the data is to be copied
Return values
Thenumber of bytes that was copied to the external buffer
        This function copies the packetbuf to an external
        buffer. Both the data portion and the header portion of
        the packetbuf is copied. If the packetbuf referenced
        external data (referenced with packetbuf_reference()) the
        external data is copied.

        The external buffer to which the packetbuf is to be
        copied must be able to accomodate at least
        (PACKETBUF_SIZE + PACKETBUF_HDR_SIZE) bytes. The number of
        bytes that was copied to the external buffer is
        returned.

References buffer, buflen, bufptr, hdrptr, i, packetbuf, PACKETBUF_HDR_SIZE, PACKETBUF_SIZE, packetbufptr, and PRINTF.

Referenced by if(), and recv_data().

int packetbuf_copyto_hdr ( uint8_t *  to)

Copy the header portion of the packetbuf to an external buffer.

Parameters
toA pointer to the buffer to which the data is to be copied
Return values
Thenumber of bytes that was copied to the external buffer
        This function copies the header portion of the packetbuf
        to an external buffer.

        The external buffer to which the packetbuf is to be
        copied must be able to accomodate at least
        PACKETBUF_HDR_SIZE bytes. The number of bytes that was
        copied to the external buffer is returned.

References hdrptr, i, packetbuf, PACKETBUF_HDR_SIZE, and PRINTF.

Referenced by if().

uint16_t packetbuf_datalen ( void  )

Get the length of the data in the packetbuf.

Returns
Length of the data in the packetbuf
        For outbound packets, the packetbuf consists of two
        parts: header and data. This function is used to get
        the length of the data in the packetbuf. The data is
        stored in the packetbuf and accessed via the
        packetbuf_dataptr() function.

        For incoming packets, both the packet header and the
        packet data is stored in the data portion of the
        packetbuf. This function is then used to get the total
        length of the packet - both header and data.

References buflen.

Referenced by create(), if(), input(), input_packet(), packet_input(), packetbuf_compact(), packetbuf_totlen(), parse(), send_packet(), uncompress_hdr_hc06(), and uncompress_hdr_hc1().

void * packetbuf_dataptr ( void  )

Get a pointer to the data in the packetbuf.

Returns
Pointer to the packetbuf data
        This function is used to get a pointer to the data in
        the packetbuf. The data is either stored in the packetbuf,
        or referenced to an external location.

        For outbound packets, the packetbuf consists of two
        parts: header and data. The header is accessed with the
        packetbuf_hdrptr() function.

        For incoming packets, both the packet header and the
        packet data is stored in the data portion of the
        packetbuf. Thus this function is used to get a pointer to
        the header for incoming packets.

References bufptr, packetbuf, and PACKETBUF_HDR_SIZE.

Referenced by create(), gateway_announce_recv(), input(), input_packet(), netstack_aes_decrypt(), netstack_aes_verify(), output(), packet_input(), parse(), PROCESS_THREAD(), and send_packet().

void packetbuf_hdr_remove ( int  size)

References hdrptr.

Referenced by send_packet().

int packetbuf_hdralloc ( int  size)

Extend the header of the packetbuf, for outbound packets.

Parameters
sizeThe number of bytes the header should be extended
Return values
Non-zeroif the header could be extended, zero otherwise
        This function is used to allocate extra space in the
        header portion in the packetbuf, when preparing outbound
        packets for transmission. If the function is unable to
        allocate sufficient header space, the function returns
        zero and does not allocate anything.

References hdrptr, PACKETBUF_SIZE, and packetbuf_totlen().

Referenced by create(), queuebuf_to_packetbuf(), and send_packet().

uint8_t packetbuf_hdrlen ( void  )

Get the length of the header in the packetbuf, for outbound packets.

Returns
Length of the header in the packetbuf
        For outbound packets, the packetbuf consists of two
        parts: header and data. This function is used to get
        the length of the header in the packetbuf. The header is
        stored in the packetbuf and accessed via the
        packetbuf_hdrptr() function.

References hdrptr, and PACKETBUF_HDR_SIZE.

Referenced by packetbuf_totlen().

void * packetbuf_hdrptr ( void  )

Get a pointer to the header in the packetbuf, for outbound packets.

Returns
Pointer to the packetbuf header
        For outbound packets, the packetbuf consists of two
        parts: header and data. This function is used to get a
        pointer to the header in the packetbuf. The header is
        stored in the packetbuf.

References hdrptr, and packetbuf.

Referenced by create(), netstack_aes_encrypt(), queuebuf_to_packetbuf(), send_one_packet(), and send_packet().

int packetbuf_hdrreduce ( int  size)

Reduce the header in the packetbuf, for incoming packets.

Parameters
sizeThe number of bytes the header should be reduced
Return values
Non-zeroif the header could be reduced, zero otherwise
        This function is used to remove the first part of the
        header in the packetbuf, when processing incoming
        packets. If the function is unable to remove the
        requested amount of header space, the function returns
        zero and does not allocate anything.

References buflen, and bufptr.

Referenced by input_packet(), and parse().

int packetbuf_is_reference ( void  )

Check if the packetbuf references external data.

Return values
Non-zeroif the packetbuf references external data, zero otherwise.
        For outbound packets, the packetbuf consists of two
        parts: header and data. This function is used to check
        if the packetbuf points to external data that has
        previously been referenced with packetbuf_reference().

References packetbuf, PACKETBUF_HDR_SIZE, and packetbufptr.

Referenced by packetbuf_compact().

void packetbuf_reference ( void *  ptr,
uint16_t  len 
)

Point the packetbuf to external data.

Parameters
ptrA pointer to the external data
lenThe length of the external data
        For outbound packets, the packetbuf consists of two
        parts: header and data. This function is used to make
        the packetbuf point to external data. The function also
        specifies the length of the external data that the
        packetbuf references.

References buflen, len, packetbuf_clear(), packetbufptr, and ptr.

void * packetbuf_reference_ptr ( void  )

Get a pointer to external data referenced by the packetbuf.

Return values
Apointer to the external data
        For outbound packets, the packetbuf consists of two
        parts: header and data. The data may point to external
        data that has previously been referenced with
        packetbuf_reference(). This function is used to get a
        pointer to the external data.

References packetbufptr.

Referenced by if(), and packetbuf_compact().

int packetbuf_set_addr ( uint8_t  type,
const linkaddr_t addr 
)
void packetbuf_set_datalen ( uint16_t  len)

Set the length of the data in the packetbuf.

Parameters
lenThe length of the data
        For outbound packets, the packetbuf consists of two
        parts: header and data. This function is used to set
        the length of the data in the packetbuf.

References buflen, len, and PRINTF.

Referenced by input_packet(), output(), and PROCESS_THREAD().

uint16_t packetbuf_totlen ( void  )

Get the total length of the header and data in the packetbuf.

Returns
Length of data and header in the packetbuf

References packetbuf_datalen(), and packetbuf_hdrlen().

Referenced by create(), input_packet(), netstack_aes_decrypt(), netstack_aes_encrypt(), netstack_aes_verify(), packetbuf_hdralloc(), send_data(), send_one_packet(), and send_packet().

uint16_t packetbuf_aligned[(PACKETBUF_SIZE+PACKETBUF_HDR_SIZE)/2+1]
static