Contiki 3.x
Macros | Functions
Rime buffer management

The packetbuf module does Rime's buffer management. More...

Macros

#define PACKETBUF_SIZE   128
 The size of the packetbuf, in bytes.
 

Functions

void packetbuf_clear (void)
 Clear and reset the packetbuf. More...
 
int packetbuf_copyfrom (const void *from, uint16_t len)
 Copy from external data into the packetbuf. More...
 
void packetbuf_compact (void)
 Compact the packetbuf. More...
 
int packetbuf_copyto (void *to)
 Copy the entire packetbuf to an external buffer. More...
 
int packetbuf_hdralloc (int size)
 Extend the header of the packetbuf, for outbound packets. More...
 
int packetbuf_hdrreduce (int size)
 Reduce the header in the packetbuf, for incoming packets. More...
 
void packetbuf_set_datalen (uint16_t len)
 Set 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_hdrptr (void)
 Get a pointer to the header in the packetbuf, for outbound packets. More...
 
uint16_t packetbuf_datalen (void)
 Get the length of the data in the packetbuf. More...
 
uint8_t packetbuf_hdrlen (void)
 Get the length of the header in the packetbuf. More...
 
uint16_t packetbuf_totlen (void)
 Get the total length of the header and data in the packetbuf. More...
 
int packetbuf_holds_broadcast (void)
 Checks whether the current packet is a broadcast. More...
 

Detailed Description

The packetbuf module does Rime's buffer management.

Function Documentation

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.

Examples:
example-collect.c.

Definition at line 76 of file packetbuf.c.

Referenced by main(), output(), packetbuf_copyfrom(), and PROCESS_THREAD().

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.

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.

Definition at line 97 of file packetbuf.c.

References packetbuf_hdrlen().

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.
Examples:
example-broadcast.c, example-mesh.c, example-multihop.c, example-runicast.c, example-trickle.c, and example-unicast.c.

Definition at line 85 of file packetbuf.c.

References packetbuf_clear(), and PACKETBUF_SIZE.

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.

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

Definition at line 111 of file packetbuf.c.

References packetbuf_dataptr(), packetbuf_hdrptr(), and PACKETBUF_SIZE.

uint16_t packetbuf_datalen ( void  )

Get the length of the data in the packetbuf.

Returns
Length of the data in the packetbuf
Examples:
example-collect.c, and example-mesh.c.

Definition at line 170 of file packetbuf.c.

Referenced by create_frame(), input(), packetbuf_totlen(), send_packet(), send_to_peer(), sicslowmac_dataRequest(), and uncompress_hdr_iphc().

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.
Examples:
example-broadcast.c, example-collect.c, example-mesh.c, example-multihop.c, and example-trickle.c.

Definition at line 158 of file packetbuf.c.

References packetbuf_hdrlen().

Referenced by create_frame(), input(), main(), output(), packetbuf_copyto(), PROCESS_THREAD(), retransmit_current_packet(), send_packet(), send_queued_packet(), send_to_peer(), and sicslowmac_dataRequest().

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.

Definition at line 122 of file packetbuf.c.

References PACKETBUF_SIZE, and packetbuf_totlen().

Referenced by create_frame(), and send_packet().

uint8_t packetbuf_hdrlen ( void  )

Get the length of the header in the packetbuf.

Returns
Length of the header in the packetbuf

Definition at line 176 of file packetbuf.c.

Referenced by packetbuf_compact(), packetbuf_dataptr(), and packetbuf_totlen().

void * packetbuf_hdrptr ( void  )

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

Returns
Pointer to the packetbuf header

Definition at line 164 of file packetbuf.c.

Referenced by create_frame(), main(), packetbuf_copyto(), 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.

Definition at line 139 of file packetbuf.c.

int packetbuf_holds_broadcast ( void  )

Checks whether the current packet is a broadcast.

Return values
0iff current packet is not a broadcast

Definition at line 242 of file packetbuf.c.

References addr, linkaddr_cmp(), and linkaddr_null.

Referenced by create_frame(), mac_LowpanToEthernet(), send_packet(), and sicslowmac_dataRequest().

void packetbuf_set_datalen ( uint16_t  len)

Set the length of the data in the packetbuf.

Parameters
lenThe length of the data
Examples:
example-collect.c.

Definition at line 151 of file packetbuf.c.

Referenced by main(), 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

Definition at line 182 of file packetbuf.c.

References packetbuf_datalen(), and packetbuf_hdrlen().

Referenced by create_frame(), packetbuf_hdralloc(), and send_packet().