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 /* for nullradio, allow unlimited packet size */
100 #define nullradio_driver_max_payload_len ((unsigned short)-1)
101 #endif /* NETSTACK_CONF_RADIO */
102 
103 /* Framer selection. The framer is used by the MAC implementation
104  to build and parse frames. */
105 #ifdef NETSTACK_CONF_FRAMER
106 #define NETSTACK_FRAMER NETSTACK_CONF_FRAMER
107 #else /* NETSTACK_CONF_FRAMER */
108 #define NETSTACK_FRAMER framer_802154
109 #endif /* NETSTACK_CONF_FRAMER */
110 
111 /* Maximal packet length. Each radio driver should define this.
112  When Contiki-NG is compiled for a specific platform (radio), that value is used. */
113 #define NETSTACK_RADIO_MAX_PAYLOAD_LEN_XX(radio) radio##_max_payload_len
114 #define NETSTACK_RADIO_MAX_PAYLOAD_LEN_X(radio) NETSTACK_RADIO_MAX_PAYLOAD_LEN_XX(radio)
115 #define NETSTACK_RADIO_MAX_PAYLOAD_LEN NETSTACK_RADIO_MAX_PAYLOAD_LEN_X(NETSTACK_RADIO)
116 
117 #include "net/mac/mac.h"
118 #include "net/mac/framer/framer.h"
119 #include "dev/radio.h"
120 #include "net/linkaddr.h"
121 
122 /**
123  * The structure of a network driver in Contiki.
124  */
126  char *name;
127 
128  /** Initialize the network driver */
129  void (*init)(void);
130 
131  /** Callback for getting notified of incoming packet in packetbuf. */
132  void (*input)(void);
133 
134  /** Output funtion, sends from uipbuf. */
135  uint8_t (*output)(const linkaddr_t *localdest);
136 };
137 
138 extern const struct routing_driver NETSTACK_ROUTING;
139 extern const struct network_driver NETSTACK_NETWORK;
140 extern const struct mac_driver NETSTACK_MAC;
141 extern const struct radio_driver NETSTACK_RADIO;
142 extern const struct framer NETSTACK_FRAMER;
143 
144 void netstack_init(void);
145 
146 /* Netstack ip_packet_processor - for implementing packet filters, firewalls,
147  debuggin info, etc */
148 
149 enum netstack_ip_action {
150  NETSTACK_IP_PROCESS = 0, /* Default behaviour - nothing else */
151  NETSTACK_IP_DROP = 1, /* Drop this packet before processing/sending anymore */
152 };
153 
154 enum netstack_ip_callback_type {
155  NETSTACK_IP_INPUT = 0,
156  NETSTACK_IP_OUTPUT = 1,
157 };
158 
159 struct netstack_ip_packet_processor {
160  struct netstack_ip_packet_processor *next;
161  enum netstack_ip_action (*process_input)(void);
162  enum netstack_ip_action (*process_output)(const linkaddr_t * localdest);
163 };
164 
165 /* This function is intended for the IP stack to call whenever input/output
166  callback needs to be called */
167 enum netstack_ip_action netstack_process_ip_callback(uint8_t type, const linkaddr_t *localdest);
168 
169 void netstack_ip_packet_processor_add(struct netstack_ip_packet_processor *p);
170 void netstack_ip_packet_processor_remove(struct netstack_ip_packet_processor *p);
171 
172 /* Netstack sniffer - this will soon be deprecated... */
173 
174 struct netstack_sniffer {
175  struct netstack_sniffer *next;
176  void (*input_callback)(void);
177  void (*output_callback)(int mac_status);
178 };
179 
180 #define NETSTACK_SNIFFER(name, input_callback, output_callback) \
181  static struct netstack_sniffer name = { NULL, input_callback, output_callback }
182 
183 void netstack_sniffer_add(struct netstack_sniffer *s);
184 void netstack_sniffer_remove(struct netstack_sniffer *s);
185 
186 #endif /* NETSTACK_H */
The structure of a MAC protocol driver in Contiki.
Definition: mac.h:62
Header file for the radio API
Header file for the link-layer address representation
The structure of a device driver for a radio in Contiki.
Definition: radio.h:264
The structure of a network driver in Contiki.
Definition: netstack.h:125
void(* init)(void)
Initialize the network driver.
Definition: netstack.h:129
void(* input)(void)
Callback for getting notified of incoming packet in packetbuf.
Definition: netstack.h:132
A MAC framer is responsible for constructing and parsing the header in MAC frames...
The structure of a routing protocol driver.
Definition: routing.h:60
uint8_t(* output)(const linkaddr_t *localdest)
Output funtion, sends from uipbuf.
Definition: netstack.h:135
MAC driver header file