Contiki 2.5
framer-nullmac.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $Id: framer-nullmac.c,v 1.2 2010/06/14 19:19:16 adamdunkels Exp $
30  */
31 
32 /**
33  * \file
34  * MAC framer for nullmac
35  * \author
36  * Niclas Finne <nfi@sics.se>
37  * Joakim Eriksson <joakime@sics.se>
38  */
39 
40 #include "net/mac/framer-nullmac.h"
41 #include "net/packetbuf.h"
42 
43 #define DEBUG 0
44 
45 #if DEBUG
46 #include <stdio.h>
47 #define PRINTF(...) printf(__VA_ARGS__)
48 #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])
49 #else
50 #define PRINTF(...)
51 #define PRINTADDR(addr)
52 #endif
53 
54 struct nullmac_hdr {
55  rimeaddr_t receiver;
56  rimeaddr_t sender;
57 };
58 
59 /*---------------------------------------------------------------------------*/
60 static int
61 create(void)
62 {
63  struct nullmac_hdr *hdr;
64 
65  if(packetbuf_hdralloc(sizeof(struct nullmac_hdr))) {
66  hdr = packetbuf_hdrptr();
67  rimeaddr_copy(&(hdr->sender), &rimeaddr_node_addr);
68  rimeaddr_copy(&(hdr->receiver), packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
69  return sizeof(struct nullmac_hdr);
70  }
71  PRINTF("PNULLMAC-UT: too large header: %u\n", len);
72  return 0;
73 }
74 /*---------------------------------------------------------------------------*/
75 static int
76 parse(void)
77 {
78  struct nullmac_hdr *hdr;
79  hdr = packetbuf_dataptr();
80  if(packetbuf_hdrreduce(sizeof(struct nullmac_hdr))) {
81  packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &(hdr->sender));
82  packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &(hdr->receiver));
83 
84  PRINTF("PNULLMAC-IN: ");
85  PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
86  PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
87  PRINTF("%u (%u)\n", packetbuf_datalen(), len);
88 
89  return sizeof(struct nullmac_hdr);
90  }
91  return 0;
92 }
93 /*---------------------------------------------------------------------------*/
94 static int
95 set_pan_id(uint16_t pan_id)
96 {
97  return 0;
98 }
99 /*---------------------------------------------------------------------------*/
100 const struct framer framer_nullmac = {
101  create, parse, set_pan_id
102 };