Contiki-NG
nullframer.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 */
30
31/**
32 * \file
33 * MAC framer that does nothing...
34 * \author
35 * Niclas Finne <nfi@sics.se>
36 * Joakim Eriksson <joakime@sics.se>
37 */
39#include "net/packetbuf.h"
40
41#ifdef NULLFRAMER_CONF_PARSE_802154
42#define NULLFRAMER_PARSE_802154 NULLFRAMER_CONF_PARSE_802154
43#else
44/* defaults to parsing of the 802154 header as that is used for Slip-Radio */
45#define NULLFRAMER_PARSE_802154 1
46#endif
47
48/*---------------------------------------------------------------------------*/
49static int
50is_broadcast_addr(uint8_t mode, const uint8_t *addr)
51{
52 int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
53 while(i-- > 0) {
54 if(addr[i] != 0xff) {
55 return 0;
56 }
57 }
58 return 1;
59}
60/*---------------------------------------------------------------------------*/
61static int
62hdr_length(void)
63{
64 /* never adds any header */
65 return 0;
66}
67/*---------------------------------------------------------------------------*/
68static int
69create(void)
70{
71 /* nothing extra... */
72 return 0;
73}
74/*---------------------------------------------------------------------------*/
75static int
76parse(void)
77{
78#if NULLFRAMER_PARSE_802154
79 frame802154_t frame;
80 int len;
81 len = packetbuf_datalen();
82 if(frame802154_parse(packetbuf_dataptr(), len, &frame)) {
83 if(frame.fcf.dest_addr_mode) {
84 if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
85 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
86 }
87 }
88 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
89 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
90 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, frame.fcf.ack_required);
91 return 0;
92 }
93#endif
94 return 0;
95}
96/*---------------------------------------------------------------------------*/
97const struct framer no_framer = {
98 hdr_length,
99 create,
100 parse
101};
A MAC framer is responsible for constructing and parsing the header in MAC frames.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
Definition: frame802154.c:500
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
Definition: packetbuf.c:143
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
Definition: packetbuf.c:155
Header file for the Packet buffer (packetbuf) management.
uint8_t ack_required
1 bit.
Definition: frame802154.h:157
uint8_t dest_addr_mode
2 bit.
Definition: frame802154.h:162
Parameters used by the frame802154_create() function.
Definition: frame802154.h:199
uint8_t seq
Sequence number.
Definition: frame802154.h:206
uint8_t dest_addr[8]
Destination address.
Definition: frame802154.h:203
uint8_t src_addr[8]
Source address.
Definition: frame802154.h:204
frame802154_fcf_t fcf
Frame control field
Definition: frame802154.h:205
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107