Contiki-NG
Loading...
Searching...
No Matches
netstack.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 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 * This file is part of the Contiki operating system.
30 */
31
32/**
33 * \file
34 * Include file for the Contiki low-layer network stack (NETSTACK)
35 * \author
36 * Adam Dunkels <adam@sics.se>
37 */
38
39#ifndef NETSTACK_H
40#define NETSTACK_H
41
42#include "contiki.h"
43
44/* Routing protocol configuration. The Routing protocol is configured through the Makefile,
45 via the flag MAKE_ROUTING */
46#ifdef NETSTACK_CONF_ROUTING
47#define NETSTACK_ROUTING NETSTACK_CONF_ROUTING
48#else /* NETSTACK_CONF_ROUTING */
49#if ROUTING_CONF_RPL_LITE
50#define NETSTACK_ROUTING rpl_lite_driver
51#elif ROUTING_CONF_RPL_CLASSIC
52#define NETSTACK_ROUTING rpl_classic_driver
53#elif ROUTING_CONF_NULLROUTING
54#define NETSTACK_ROUTING nullrouting_driver
55#else
56#error Unknown ROUTING configuration
57#endif
58#endif /* NETSTACK_CONF_ROUTING */
59
60/* Network layer configuration. The NET layer is configured through the Makefile,
61 via the flag MAKE_NET */
62#ifdef NETSTACK_CONF_NETWORK
63#define NETSTACK_NETWORK NETSTACK_CONF_NETWORK
64#else /* NETSTACK_CONF_NETWORK */
65#if NETSTACK_CONF_WITH_IPV6
66#define NETSTACK_NETWORK sicslowpan_driver
67#elif NETSTACK_CONF_WITH_NULLNET
68#define NETSTACK_NETWORK nullnet_driver
69#else
70#error Unknown NET configuration
71#endif
72#endif /* NETSTACK_CONF_NETWORK */
73
74/* MAC layer configuration. The MAC layer is configured through the Makefile,
75 via the flag MAKE_MAC */
76#ifdef NETSTACK_CONF_MAC
77#define NETSTACK_MAC NETSTACK_CONF_MAC
78#else /* NETSTACK_CONF_MAC */
79#if MAC_CONF_WITH_NULLMAC
80#define NETSTACK_MAC nullmac_driver
81#elif MAC_CONF_WITH_CSMA
82#define NETSTACK_MAC csma_driver
83#elif MAC_CONF_WITH_TSCH
84#define NETSTACK_MAC tschmac_driver
85#elif MAC_CONF_WITH_BLE
86#define NETSTACK_MAC ble_l2cap_driver
87#else
88#error Unknown MAC configuration
89#endif
90#endif /* NETSTACK_CONF_MAC */
91
92/* Radio driver configuration. Most often set by the platform. */
93#ifdef NETSTACK_CONF_RADIO
94#define NETSTACK_RADIO NETSTACK_CONF_RADIO
95#else /* NETSTACK_CONF_RADIO */
96#define NETSTACK_RADIO nullradio_driver
97#endif /* NETSTACK_CONF_RADIO */
98
99/* Framer selection. The framer is used by the MAC implementation
100 to build and parse frames. */
101#ifdef NETSTACK_CONF_FRAMER
102#define NETSTACK_FRAMER NETSTACK_CONF_FRAMER
103#else /* NETSTACK_CONF_FRAMER */
104#define NETSTACK_FRAMER framer_802154
105#endif /* NETSTACK_CONF_FRAMER */
106
107#include "net/mac/mac.h"
109#include "dev/radio.h"
110#include "net/linkaddr.h"
111
112/**
113 * The structure of a network driver in Contiki.
114 */
116 char *name;
117
118 /** Initialize the network driver */
119 void (*init)(void);
120
121 /** Callback for getting notified of incoming packet in packetbuf. */
122 void (*input)(void);
123
124 /** Output funtion, sends from uipbuf. */
125 uint8_t (*output)(const linkaddr_t *localdest);
126};
127
128extern const struct routing_driver NETSTACK_ROUTING;
129extern const struct network_driver NETSTACK_NETWORK;
130extern const struct mac_driver NETSTACK_MAC;
131extern const struct radio_driver NETSTACK_RADIO;
132extern const struct framer NETSTACK_FRAMER;
133
134/* Netstack ip_packet_processor - for implementing packet filters, firewalls,
135 debuggin info, etc */
136
137enum netstack_ip_action {
138 NETSTACK_IP_PROCESS = 0, /* Default behaviour - nothing else */
139 NETSTACK_IP_DROP = 1, /* Drop this packet before processing/sending anymore */
140};
141
142enum netstack_ip_callback_type {
143 NETSTACK_IP_INPUT = 0,
144 NETSTACK_IP_OUTPUT = 1,
145};
146
147struct netstack_ip_packet_processor {
148 struct netstack_ip_packet_processor *next;
149 enum netstack_ip_action (*process_input)(void);
150 enum netstack_ip_action (*process_output)(const linkaddr_t * localdest);
151};
152
153/* This function is intended for the IP stack to call whenever input/output
154 callback needs to be called */
155enum netstack_ip_action netstack_process_ip_callback(uint8_t type, const linkaddr_t *localdest);
156
157void netstack_ip_packet_processor_add(struct netstack_ip_packet_processor *p);
158void netstack_ip_packet_processor_remove(struct netstack_ip_packet_processor *p);
159
160/* Netstack sniffer - this will soon be deprecated... */
161
162struct netstack_sniffer {
163 struct netstack_sniffer *next;
164 void (*input_callback)(void);
165 void (*output_callback)(int mac_status);
166};
167
168#define NETSTACK_SNIFFER(name, input_callback, output_callback) \
169 static struct netstack_sniffer name = { NULL, input_callback, output_callback }
170
171void netstack_sniffer_add(struct netstack_sniffer *s);
172void netstack_sniffer_remove(struct netstack_sniffer *s);
173
174#endif /* NETSTACK_H */
A MAC framer is responsible for constructing and parsing the header in MAC frames.
Header file for the link-layer address representation.
MAC driver header file.
Header file for the radio API.
The structure of a MAC protocol driver in Contiki.
Definition mac.h:68
The structure of a network driver in Contiki.
Definition netstack.h:115
void(* input)(void)
Callback for getting notified of incoming packet in packetbuf.
Definition netstack.h:122
uint8_t(* output)(const linkaddr_t *localdest)
Output funtion, sends from uipbuf.
Definition netstack.h:125
void(* init)(void)
Initialize the network driver.
Definition netstack.h:119
The structure of a Contiki-NG radio device driver.
Definition radio.h:534
The structure of a routing protocol driver.
Definition routing.h:60