framer-nullmac.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "net/mac/framer-nullmac.h"
00041 #include "net/packetbuf.h"
00042
00043 #define DEBUG 0
00044
00045 #if DEBUG
00046 #include <stdio.h>
00047 #define PRINTF(...) printf(__VA_ARGS__)
00048 #define PRINTADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7])
00049 #else
00050 #define PRINTF(...)
00051 #define PRINTADDR(addr)
00052 #endif
00053
00054 struct nullmac_hdr {
00055 rimeaddr_t receiver;
00056 rimeaddr_t sender;
00057 };
00058
00059
00060 static int
00061 create(void)
00062 {
00063 struct nullmac_hdr *hdr;
00064
00065 if(packetbuf_hdralloc(sizeof(struct nullmac_hdr))) {
00066 hdr = packetbuf_hdrptr();
00067 rimeaddr_copy(&(hdr->sender), &rimeaddr_node_addr);
00068 rimeaddr_copy(&(hdr->receiver), packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
00069 return sizeof(struct nullmac_hdr);
00070 }
00071 PRINTF("PNULLMAC-UT: too large header: %u\n", len);
00072 return 0;
00073 }
00074
00075 static int
00076 parse(void)
00077 {
00078 struct nullmac_hdr *hdr;
00079 hdr = packetbuf_dataptr();
00080 if(packetbuf_hdrreduce(sizeof(struct nullmac_hdr))) {
00081 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &(hdr->sender));
00082 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &(hdr->receiver));
00083
00084 PRINTF("PNULLMAC-IN: ");
00085 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
00086 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
00087 PRINTF("%u (%u)\n", packetbuf_datalen(), len);
00088
00089 return sizeof(struct nullmac_hdr);
00090 }
00091 return 0;
00092 }
00093
00094 const struct framer framer_nullmac = {
00095 create, parse
00096 };