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 */
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/*---------------------------------------------------------------------------*/
49#if NULLFRAMER_PARSE_802154
50static int
51is_broadcast_addr(uint8_t mode, const uint8_t *addr)
52{
53 int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
54 while(i-- > 0) {
55 if(addr[i] != 0xff) {
56 return 0;
57 }
58 }
59 return 1;
60}
61#endif /* NULLFRAMER_PARSE_802154 */
62/*---------------------------------------------------------------------------*/
63static int
64hdr_length(void)
65{
66 /* never adds any header */
67 return 0;
68}
69/*---------------------------------------------------------------------------*/
70static int
71create(void)
72{
73 /* nothing extra... */
74 return 0;
75}
76/*---------------------------------------------------------------------------*/
77static int
78parse(void)
79{
80#if NULLFRAMER_PARSE_802154
81 frame802154_t frame;
82 int len;
83 len = packetbuf_datalen();
84 if(frame802154_parse(packetbuf_dataptr(), len, &frame)) {
85 if(frame.fcf.dest_addr_mode) {
86 if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
87 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
88 }
89 }
90 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
91 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
92 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, frame.fcf.ack_required);
93 }
94#endif
95 return 0;
96}
97/*---------------------------------------------------------------------------*/
98const struct framer no_framer = {
99 hdr_length,
100 create,
101 parse
102};
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