51 #ifdef CHAMELEON_CONF_WITH_MAC_LINK_ADDRESSES
52 #define CHAMELEON_WITH_MAC_LINK_ADDRESSES CHAMELEON_CONF_WITH_MAC_LINK_ADDRESSES
54 #define CHAMELEON_WITH_MAC_LINK_ADDRESSES 0
60 #define PRINTF(...) printf(__VA_ARGS__)
70 static struct channel *
73 const struct packetbuf_attrlist *a;
74 int byteptr, bitptr, len;
83 PRINTF(
"chameleon-raw: too short packet\n");
86 c = channel_lookup((hdr->channel[1] << 8) + hdr->channel[0]);
88 PRINTF(
"chameleon-raw: input: channel %u not found\n",
89 (hdr->channel[1] << 8) + hdr->channel[0]);
95 PRINTF(
"chameleon-raw: too short packet\n");
99 for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
100 #if CHAMELEON_WITH_MAC_LINK_ADDRESSES
101 if(a->type == PACKETBUF_ADDR_SENDER ||
102 a->type == PACKETBUF_ADDR_RECEIVER) {
107 PRINTF(
"%d.%d: unpack_header type %s, len %d\n",
109 packetbuf_attr_strings[a->type], a->len);
110 len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
111 if(PACKETBUF_IS_ADDR(a->type)) {
112 const rimeaddr_t addr;
113 memcpy((uint8_t *)&addr, &hdrptr[byteptr], len / 8);
114 PRINTF(
"%d.%d: unpack_header type %s, addr %d.%d\n",
116 packetbuf_attr_strings[a->type],
117 addr.u8[0], addr.u8[1]);
118 packetbuf_set_addr(a->type, &addr);
120 packetbuf_attr_t val = 0;
121 memcpy((uint8_t *)&val, &hdrptr[byteptr], len / 8);
123 packetbuf_set_attr(a->type, val);
124 PRINTF(
"%d.%d: unpack_header type %s, val %d\n",
126 packetbuf_attr_strings[a->type],
135 output(
struct channel *c)
137 const struct packetbuf_attrlist *a;
145 PRINTF(
"chameleon-raw: insufficient space for headers\n");
149 hdr->channel[0] = c->channelno & 0xff;
150 hdr->channel[1] = (c->channelno >> 8) & 0xff;
154 for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
155 #if CHAMELEON_WITH_MAC_LINK_ADDRESSES
156 if(a->type == PACKETBUF_ADDR_SENDER ||
157 a->type == PACKETBUF_ADDR_RECEIVER) {
159 PRINTF(
"%d.%d: pack_header leaving sender/receiver to link layer\n");
163 PRINTF(
"%d.%d: pack_header type %s, len %d\n",
165 packetbuf_attr_strings[a->type], a->len);
166 len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
167 if(PACKETBUF_IS_ADDR(a->type)) {
168 const rimeaddr_t *rimeaddr;
170 rimeaddr = packetbuf_addr(a->type);
171 hdrptr[byteptr] = rimeaddr->u8[0];
172 hdrptr[byteptr + 1] = rimeaddr->u8[1];
174 PRINTF(
"%d.%d: address %d.%d\n",
176 ((uint8_t *)packetbuf_addr(a->type))[0],
177 ((uint8_t *)packetbuf_addr(a->type))[1]);
179 packetbuf_attr_t val;
180 val = packetbuf_attr(a->type);
181 memcpy(&hdrptr[byteptr], &val, len / 8);
182 PRINTF(
"%d.%d: value %d\n",
193 hdrsize(
const struct packetbuf_attrlist *a)
201 for(; a->type != PACKETBUF_ATTR_NONE; ++a) {
206 #if CHAMELEON_WITH_MAC_LINK_ADDRESSES
207 if(a->type == PACKETBUF_ADDR_SENDER ||
208 a->type == PACKETBUF_ADDR_RECEIVER) {