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