Contiki-NG
Loading...
Searching...
No Matches
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 */
40#include "net/packetbuf.h"
41
42#ifdef NULLFRAMER_CONF_PARSE_802154
43#define NULLFRAMER_PARSE_802154 NULLFRAMER_CONF_PARSE_802154
44#else
45/* defaults to parsing of the 802154 header as that is used for Slip-Radio */
46#define NULLFRAMER_PARSE_802154 1
47#endif
48
49/*---------------------------------------------------------------------------*/
50#if NULLFRAMER_PARSE_802154
51static int
52is_broadcast_addr(uint8_t mode, const uint8_t *addr)
53{
54 int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
55 while(i-- > 0) {
56 if(addr[i] != 0xff) {
57 return 0;
58 }
59 }
60 return 1;
61}
62#endif /* NULLFRAMER_PARSE_802154 */
63/*---------------------------------------------------------------------------*/
64static int
65hdr_length(void)
66{
67 /* never adds any header */
68 return 0;
69}
70/*---------------------------------------------------------------------------*/
71static int
72create(void)
73{
74 /* nothing extra... */
75 return 0;
76}
77/*---------------------------------------------------------------------------*/
78static int
79parse(void)
80{
81#if NULLFRAMER_PARSE_802154
82 frame802154_t frame;
83 int len;
84 len = packetbuf_datalen();
85 if(frame802154_parse(packetbuf_dataptr(), len, &frame)) {
86 if(frame.fcf.dest_addr_mode) {
87 if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
88 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
89 }
90 }
91 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
92 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
93 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, frame.fcf.ack_required);
94 }
95#endif
96 return 0;
97}
98/*---------------------------------------------------------------------------*/
99const struct framer no_framer = {
100 hdr_length,
101 create,
102 parse
103};
802.15.4 frame creation and parsing functions
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.
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.
uint8_t dest_addr_mode
2 bit.
Parameters used by the frame802154_create() function.
uint8_t seq
Sequence number.
uint8_t dest_addr[8]
Destination address.
uint8_t src_addr[8]
Source address.
frame802154_fcf_t fcf
Frame control field
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition uip-nd6.c:107