Contiki-NG
Loading...
Searching...
No Matches
Packet buffer

The packetbuf module does Contiki'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.
int packetbuf_copyfrom (const void *from, uint16_t len)
 Copy from external data into the packetbuf.
int packetbuf_copyto (void *to)
 Copy the entire packetbuf to an external buffer.
int packetbuf_hdralloc (int size)
 Extend the header of the packetbuf, for outbound packets.
int packetbuf_hdrreduce (int size)
 Reduce the header in the packetbuf, for incoming packets.
void packetbuf_set_datalen (uint16_t len)
 Set the length of the data in the packetbuf.
void * packetbuf_dataptr (void)
 Get a pointer to the data in the packetbuf.
void * packetbuf_hdrptr (void)
 Get a pointer to the header in the packetbuf, for outbound packets.
uint16_t packetbuf_datalen (void)
 Get the length of the data in the packetbuf.
uint8_t packetbuf_hdrlen (void)
 Get the length of the header in the packetbuf.
uint16_t packetbuf_totlen (void)
 Get the total length of the header and data in the packetbuf.
uint16_t packetbuf_remaininglen (void)
 Get the total length of the remaining space in the packetbuf.
bool packetbuf_holds_broadcast (void)
 Checks whether the current packet is a broadcast.

Detailed Description

The packetbuf module does Contiki's buffer management.

Function Documentation

◆ packetbuf_clear()

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.

Definition at line 75 of file packetbuf.c.

Referenced by output(), packetbuf_copyfrom(), PROCESS_THREAD(), PROCESS_THREAD(), sixp_pkt_create(), and tsch_packet_create_eb().

◆ packetbuf_copyfrom()

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.

Definition at line 84 of file packetbuf.c.

References packetbuf_clear(), and PACKETBUF_SIZE.

◆ packetbuf_copyto()

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 96 of file packetbuf.c.

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

◆ packetbuf_datalen()

uint16_t packetbuf_datalen ( void )

Get the length of the data in the packetbuf.

Returns
Length of the data in the packetbuf

Definition at line 155 of file packetbuf.c.

Referenced by input(), packet_input(), packetbuf_totlen(), sixtop_input(), sixtop_output(), and tsch_packet_create_eb().

◆ packetbuf_dataptr()

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.

Definition at line 143 of file packetbuf.c.

References packetbuf_hdrlen().

Referenced by input(), output(), packet_input(), packetbuf_copyto(), PROCESS_THREAD(), PROCESS_THREAD(), sixp_pkt_create(), sixtop_input(), sixtop_output(), and tsch_packet_create_eb().

◆ packetbuf_hdralloc()

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 107 of file packetbuf.c.

References PACKETBUF_SIZE, and packetbuf_totlen().

Referenced by sixp_pkt_create(), sixtop_output(), and tsch_packet_create_eb().

◆ packetbuf_hdrlen()

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 161 of file packetbuf.c.

Referenced by packetbuf_dataptr(), packetbuf_totlen(), sixtop_input(), and tsch_packet_create_eb().

◆ packetbuf_hdrptr()

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 149 of file packetbuf.c.

Referenced by packetbuf_copyto(), sixp_pkt_create(), sixtop_output(), and tsch_packet_create_eb().

◆ packetbuf_hdrreduce()

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 124 of file packetbuf.c.

Referenced by sixtop_input().

◆ packetbuf_holds_broadcast()

bool packetbuf_holds_broadcast ( void )

Checks whether the current packet is a broadcast.

Return values
trueiff the current packet is a broadcast

Definition at line 229 of file packetbuf.c.

References addr, linkaddr_cmp(), and linkaddr_null.

◆ packetbuf_remaininglen()

uint16_t packetbuf_remaininglen ( void )

Get the total length of the remaining space in the packetbuf.

Returns
Length of the remaining space in the packetbuf

Definition at line 173 of file packetbuf.c.

References PACKETBUF_SIZE, and packetbuf_totlen().

Referenced by tsch_packet_create_eb().

◆ packetbuf_set_datalen()

void packetbuf_set_datalen ( uint16_t len)

Set the length of the data in the packetbuf.

Parameters
lenThe length of the data

Definition at line 136 of file packetbuf.c.

Referenced by output(), PROCESS_THREAD(), PROCESS_THREAD(), sixp_pkt_create(), sixtop_output(), and tsch_packet_create_eb().

◆ packetbuf_totlen()

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 167 of file packetbuf.c.

References packetbuf_datalen(), and packetbuf_hdrlen().

Referenced by packetbuf_hdralloc(), packetbuf_remaininglen(), sixp_pkt_create(), sixtop_output(), and tsch_packet_create_eb().