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 |
Functions | |
const linkaddr_t * | packetbuf_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 |
Referenced by packetbuf_addr(), packetbuf_set_addr(), and queuebuf_addr().
#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 |
The size of the packetbuf header, in bytes.
Referenced by packetbuf_clear(), packetbuf_clear_hdr(), packetbuf_compact(), packetbuf_copyto(), packetbuf_copyto_hdr(), packetbuf_dataptr(), packetbuf_hdrlen(), and packetbuf_is_reference().
#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 | ( | ... | ) |
Referenced by packetbuf_copyto(), packetbuf_copyto_hdr(), and packetbuf_set_datalen().
typedef uint16_t packetbuf_attr_t |
anonymous enum |
const linkaddr_t * packetbuf_addr | ( | uint8_t | type | ) |
References packetbuf_addr::addr, PACKETBUF_ADDR_FIRST, and packetbuf_addrs.
Referenced by create(), dao_input(), dio_input(), input(), input_packet(), mac_sequence_is_duplicate(), mac_sequence_register_seqno(), packet_input(), parse(), send_one_packet(), send_packet(), and uip_ds6_link_neighbor_callback().
packetbuf_attr_t packetbuf_attr | ( | uint8_t | type | ) |
References packetbuf_attrs, and packetbuf_attr::val.
Referenced by compower_accumulate_attrs(), compower_attrconv(), create(), input(), input_packet(), mac_sequence_is_duplicate(), mac_sequence_register_seqno(), packet_input(), and send_packet().
void packetbuf_attr_clear | ( | void | ) |
References addr, i, linkaddr_copy(), linkaddr_null, packetbuf_addrs, packetbuf_attrs, PACKETBUF_NUM_ADDRS, PACKETBUF_NUM_ATTRS, and packetbuf_attr::val.
Referenced by packetbuf_clear().
void packetbuf_attr_copyfrom | ( | struct packetbuf_attr * | attrs, |
struct packetbuf_addr * | addrs | ||
) |
References packetbuf_addrs, and packetbuf_attrs.
Referenced by copy_packet(), and queuebuf_to_packetbuf().
void packetbuf_attr_copyto | ( | struct packetbuf_attr * | attrs, |
struct packetbuf_addr * | addrs | ||
) |
References packetbuf_addrs, and packetbuf_attrs.
Referenced by copy_packet(), if(), and queuebuf_update_attr_from_packetbuf().
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.
from | A pointer to the data from which to copy |
len | The size of the data to copy |
The | number 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.
to | A pointer to the buffer to which the data is to be copied |
The | number 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.
to | A pointer to the buffer to which the data is to be copied |
The | number 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.
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.
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.
size | The number of bytes the header should be extended |
Non-zero | if 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.
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.
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.
size | The number of bytes the header should be reduced |
Non-zero | if 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.
Non-zero | if 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.
ptr | A pointer to the external data |
len | The 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.
A | pointer 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 | ||
) |
References linkaddr_copy(), PACKETBUF_ADDR_FIRST, and packetbuf_addrs.
Referenced by output(), parse(), send_one_packet(), and send_packet().
int packetbuf_set_attr | ( | uint8_t | type, |
const packetbuf_attr_t | val | ||
) |
References packetbuf_attrs, and packetbuf_attr::val.
Referenced by compower_attrconv(), create(), output(), parse(), qsend_list(), rf212_read(), rf233_read(), send_one_packet(), send_packet(), set_packet_attrs(), and uip_over_mesh_send().
void packetbuf_set_datalen | ( | uint16_t | len | ) |
Set the length of the data in the packetbuf.
len | The 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.
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().
|
static |
|
static |
Referenced by packetbuf_clear(), packetbuf_compact(), packetbuf_copyto(), packetbuf_dataptr(), and packetbuf_hdrreduce().
|
static |
|
static |
struct packetbuf_addr packetbuf_addrs[PACKETBUF_NUM_ADDRS] |
Referenced by packetbuf_addr(), packetbuf_attr_clear(), packetbuf_attr_copyfrom(), packetbuf_attr_copyto(), and packetbuf_set_addr().
|
static |
struct packetbuf_attr packetbuf_attrs[PACKETBUF_NUM_ATTRS] |
Referenced by packetbuf_attr(), packetbuf_attr_clear(), packetbuf_attr_copyfrom(), packetbuf_attr_copyto(), and packetbuf_set_attr().
|
static |