47 #include "contiki-net.h"
51 struct packetbuf_attr packetbuf_attrs[PACKETBUF_NUM_ATTRS];
52 struct packetbuf_addr packetbuf_addrs[PACKETBUF_NUM_ADDRS];
55 static uint16_t buflen, bufptr;
56 static uint8_t hdrptr;
63 static uint8_t *packetbuf = (uint8_t *)packetbuf_aligned;
65 static uint8_t *packetbufptr;
70 #define PRINTF(...) printf(__VA_ARGS__)
83 packetbuf_attr_clear();
99 memcpy(packetbufptr, from, l);
112 }
else if(bufptr > 0) {
115 packetbuf[i] = packetbuf[bufptr + i];
128 PRINTF(
"packetbuf_write_hdr: header:\n");
130 PRINTF(
"0x%02x, ", packetbuf[i]);
146 char *bufferptr = buffer;
150 bufferptr += sprintf(bufferptr,
"0x%02x, ", packetbuf[i]);
152 PRINTF(
"packetbuf_write: header: %s\n", buffer);
155 for(i = bufptr; i < buflen + bufptr; ++i) {
156 bufferptr += sprintf(bufferptr,
"0x%02x, ", packetbufptr[i]);
158 PRINTF(
"packetbuf_write: data: %s\n", buffer);
182 packetbuf_hdr_remove(
int size)
202 PRINTF(
"packetbuf_set_len: len %d\n", len);
215 return (
void *)(&packetbuf[hdrptr]);
266 packetbuf_attr_clear(
void)
269 for(i = 0; i < PACKETBUF_NUM_ATTRS; ++i) {
270 packetbuf_attrs[i].val = 0;
272 for(i = 0; i < PACKETBUF_NUM_ADDRS; ++i) {
278 packetbuf_attr_copyto(
struct packetbuf_attr *attrs,
279 struct packetbuf_addr *addrs)
281 memcpy(attrs, packetbuf_attrs,
sizeof(packetbuf_attrs));
282 memcpy(addrs, packetbuf_addrs,
sizeof(packetbuf_addrs));
286 packetbuf_attr_copyfrom(
struct packetbuf_attr *attrs,
287 struct packetbuf_addr *addrs)
289 memcpy(packetbuf_attrs, attrs,
sizeof(packetbuf_attrs));
290 memcpy(packetbuf_addrs, addrs,
sizeof(packetbuf_addrs));
293 #if !PACKETBUF_CONF_ATTRS_INLINE
295 packetbuf_set_attr(uint8_t type,
const packetbuf_attr_t val)
298 packetbuf_attrs[type].val = val;
303 packetbuf_attr(uint8_t type)
305 return packetbuf_attrs[type].val;
309 packetbuf_set_addr(uint8_t type,
const linkaddr_t *addr)
312 linkaddr_copy(&packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].addr, addr);
317 packetbuf_addr(uint8_t type)
319 return &packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].addr;
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
int packetbuf_copyfrom(const void *from, uint16_t len)
Copy from external data into the packetbuf.
const linkaddr_t linkaddr_null
The null Rime address.
Header file for the Rime buffer (packetbuf) management
uint8_t packetbuf_hdrlen(void)
Get the length of the header in the packetbuf.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
Header file for the Rime stack
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
void * packetbuf_reference_ptr(void)
Get a pointer to external data referenced by the packetbuf.
#define PACKETBUF_HDR_SIZE
The size of the packetbuf header, in bytes.
int packetbuf_copyto(void *to)
Copy the entire packetbuf to an external buffer.
void packetbuf_compact(void)
Compact the packetbuf.
void packetbuf_clear_hdr(void)
Clear and reset the header of the packetbuf.
int packetbuf_copyto_hdr(uint8_t *to)
Copy the header portion of the packetbuf to an external buffer.
void packetbuf_clear(void)
Clear and reset the packetbuf.
void packetbuf_reference(void *ptr, uint16_t len)
Point the packetbuf to external data.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int packetbuf_is_reference(void)
Check if the packetbuf references external data.
int packetbuf_hdrreduce(int size)
Reduce the header in the packetbuf, for incoming packets.