50 #ifdef CHAMELEON_CONF_WITH_MAC_LINK_ADDRESSES
51 #define CHAMELEON_WITH_MAC_LINK_ADDRESSES CHAMELEON_CONF_WITH_MAC_LINK_ADDRESSES
53 #define CHAMELEON_WITH_MAC_LINK_ADDRESSES 0
59 #define PRINTF(...) printf(__VA_ARGS__)
69 static struct channel *
72 const struct packetbuf_attrlist *a;
73 int byteptr, bitptr, len;
82 PRINTF(
"chameleon-raw: too short packet\n");
85 c = channel_lookup((hdr->channel[1] << 8) + hdr->channel[0]);
87 PRINTF(
"chameleon-raw: input: channel %u not found\n",
88 (hdr->channel[1] << 8) + hdr->channel[0]);
94 PRINTF(
"chameleon-raw: too short packet\n");
98 for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
99 #if CHAMELEON_WITH_MAC_LINK_ADDRESSES
100 if(a->type == PACKETBUF_ADDR_SENDER ||
101 a->type == PACKETBUF_ADDR_RECEIVER) {
106 PRINTF(
"%d.%d: unpack_header type %d, len %d\n",
109 len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
110 if(PACKETBUF_IS_ADDR(a->type)) {
111 const linkaddr_t addr;
112 memcpy((uint8_t *)&addr, &hdrptr[byteptr], len / 8);
113 PRINTF(
"%d.%d: unpack_header type %d, addr %d.%d\n",
115 a->type, addr.u8[0], addr.u8[1]);
116 packetbuf_set_addr(a->type, &addr);
118 packetbuf_attr_t val = 0;
119 memcpy((uint8_t *)&val, &hdrptr[byteptr], len / 8);
121 packetbuf_set_attr(a->type, val);
122 PRINTF(
"%d.%d: unpack_header type %d, val %d\n",
132 output(
struct channel *c)
134 const struct packetbuf_attrlist *a;
142 PRINTF(
"chameleon-raw: insufficient space for headers\n");
146 hdr->channel[0] = c->channelno & 0xff;
147 hdr->channel[1] = (c->channelno >> 8) & 0xff;
151 for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
152 #if CHAMELEON_WITH_MAC_LINK_ADDRESSES
153 if(a->type == PACKETBUF_ADDR_SENDER ||
154 a->type == PACKETBUF_ADDR_RECEIVER) {
156 PRINTF(
"%d.%d: pack_header leaving sender/receiver to link layer\n");
160 PRINTF(
"%d.%d: pack_header type %d, len %d\n",
163 len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
164 if(PACKETBUF_IS_ADDR(a->type)) {
165 const linkaddr_t *linkaddr;
167 linkaddr = packetbuf_addr(a->type);
168 hdrptr[byteptr] = linkaddr->u8[0];
169 hdrptr[byteptr + 1] = linkaddr->u8[1];
171 PRINTF(
"%d.%d: address %d.%d\n",
173 ((uint8_t *)packetbuf_addr(a->type))[0],
174 ((uint8_t *)packetbuf_addr(a->type))[1]);
176 packetbuf_attr_t val;
177 val = packetbuf_attr(a->type);
178 memcpy(&hdrptr[byteptr], &val, len / 8);
179 PRINTF(
"%d.%d: value %d\n",
190 hdrsize(
const struct packetbuf_attrlist *a)
198 for(; a->type != PACKETBUF_ATTR_NONE; ++a) {
201 #if CHAMELEON_WITH_MAC_LINK_ADDRESSES
202 if(a->type == PACKETBUF_ADDR_SENDER ||
203 a->type == PACKETBUF_ADDR_RECEIVER) {
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
Header file for Chameleon, Rime's header processing module
#define CC_CONST_FUNCTION
Configure if the C compiler have problems with const function pointers.
#define NULL
The null pointer.
Header file for the Rime stack
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int packetbuf_hdrreduce(int size)
Reduce the header in the packetbuf, for incoming packets.