Contiki-NG
sixtop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Yasuyuki Tanaka
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 copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /**
31  * \addtogroup link-layer
32  * @{
33  */
34 /**
35  * \defgroup sixtop 6TiSCH Operation Sublayer (6top)
36  * @{
37  */
38 /**
39  * \file
40  * 6TiSCH Operation Sublayer (6top) APIs
41  * \author
42  * Yasuyuki Tanaka <yasuyuki.tanaka@inf.ethz.ch>
43  */
44 
45 #ifndef _SIXTOP_H_
46 #define _SIXTOP_H_
47 
48 #include "net/mac/mac.h"
49 #include "net/linkaddr.h"
50 
51 #include "sixp-pkt.h"
52 
53 #define SIXTOP_SUBIE_ID 0xc9
54 
55 /**
56  * \brief Input Handler of Scheduling Function
57  * \param type 6P Message Type of an input packet
58  * \param code Code, 6P Command Identifier or Return Code, of an input packet
59  * \param body Body, "Other Fields", of an input packet
60  * \param body_len The length of body
61  * \param body src_addr Source address of an input packet
62  */
63 typedef void (* sixtop_sf_input)(sixp_pkt_type_t type,
64  sixp_pkt_code_t code,
65  const uint8_t *body,
66  uint16_t body_len,
67  const linkaddr_t *src_addr);
68 
69 /**
70  * \brief Timeout Handler of Scheduling Function
71  * \param cmd 6P Command (Identifier) in process under the transaction
72  * \param peer_addr The peer address of the transaction
73  */
74 typedef void (* sixtop_sf_timeout)(sixp_pkt_cmd_t cmd,
75  const linkaddr_t *peer_addr);
76 
77 /**
78  * \brief 6P internal error code, which SF is informed of through its
79  * sixtop_sf_error handler
80  */
81 typedef enum {
82  SIXP_ERROR_SCHEDULE_INCONSISTENCY,
83  SIXP_ERROR_TX_AFTER_TRANSACTION_TERMINATION,
84  SIXP_ERROR_INVALID_TRANS_STATE_TRANSITION,
85  SIXP_ERROR_UNDEFINED
86 } sixp_error_t;
87 
88 /**
89  * \brief Error Handler of Scheduling Function
90  * \param err Error occurred in a 6P transaction
91  * \param cmd Command of the 6P transaction
92  * \param seqno SeqNum of the 6P transaction
93  * \param peer_addr MAC address of the 6P transaction
94  * \details The error handler is called when an error occurs in 6P
95  */
96 typedef void (* sixtop_sf_error)(sixp_error_t err,
97  sixp_pkt_cmd_t cmd,
98  uint8_t seqno,
99  const linkaddr_t *peer_addr);
100 
101 /**
102  * /brief Scheduling Function Driver
103  */
104 typedef struct {
105  uint8_t sfid; /**< SFID */
106  clock_time_t timeout_interval; /**< Timeout Value */
107  void (*init)(void); /**< Init Function */
108  sixtop_sf_input input; /**< Input Handler */
109  sixtop_sf_timeout timeout; /**< Transaction Timeout Handler */
110  sixtop_sf_error error; /**< Internal Error Handler */
111 } sixtop_sf_t;
112 /**
113  * \var sixtop_sf_t::sfid
114  * managed: 0x00-0xfe
115  * unmanaged: 0xf0-0xfe
116  * reserved: 0xff
117  */
118 
119 
120 /**
121  * \brief Add a Scheduling Function (SF) to 6top Sublayer
122  * \param sf The pointer to a Scheduling Function Driver
123  * \return 0 on success, -1 on failure
124  *
125  * If there is a SF whose SF is identical to one of a SF specified to this API,
126  * the addition will fail and -1 will be returned. If there is no room to
127  * another SF, -1 will be returned as well. You can specify how many SFs can be
128  * added with SIXTOP_CONF_MAX_SCHEDULING_FUNCTIONS.
129  */
130 int sixtop_add_sf(const sixtop_sf_t *sf);
131 
132 /**
133  * \brief Find a SF which has been added by SFID
134  * \param sfid Scheduling Function Identifier of a SF
135  * \return The pointer to a SF driver having the specified SFID on success, NULL
136  * on failure (not found)
137  */
138 const sixtop_sf_t *sixtop_find_sf(uint8_t sfid);
139 
140 /**
141  * \brief Output a 6P packet which is supposestored in packetbuf
142  * \param dest_addr Destination address of the outgoing packet
143  * \param callback MAC callback function to get a TX result
144  * \param arg The pointer to an argument which is returned with the MAC callback
145  * \return 0 on success, -1 on failure
146  */
147 int sixtop_output(const linkaddr_t *dest_addr,
148  mac_callback_t callback, void *arg);
149 
150 /**
151  * \brief Input a packet stored in packetbuf
152  */
153 void sixtop_input(void);
154 
155 /**
156  * \brief Initialize 6top module
157  * This initialization function removes all the SFs which has been installed
158  * into the 6top sub-layer. In addition, it invokes sixp_init().
159  */
160 void sixtop_init(void);
161 
162 /**
163  * \brief Initialize installed SFs which has been added in the system
164  * This function is supposed to be invoked every time the node gets associated.
165  */
166 void sixtop_init_sf(void);
167 
168 #endif /* !_SIXTOP_H_ */
169 /** @} */
170 /** @} */
void(* sixtop_sf_input)(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t *body, uint16_t body_len, const linkaddr_t *src_addr)
Input Handler of Scheduling Function.
Definition: sixtop.h:63
sixp_pkt_cmd_t
6P Command Identifiers
Definition: sixp-pkt.h:72
sixp_pkt_type_t
6P Message Types
Definition: sixp-pkt.h:62
/brief Scheduling Function Driver
Definition: sixtop.h:104
void sixtop_init_sf(void)
Initialize installed SFs which has been added in the system This function is supposed to be invoked e...
Definition: sixtop.c:275
sixp_error_t
6P internal error code, which SF is informed of through its sixtop_sf_error handler ...
Definition: sixtop.h:81
Header file for the link-layer address representation
void(* sixtop_sf_timeout)(sixp_pkt_cmd_t cmd, const linkaddr_t *peer_addr)
Timeout Handler of Scheduling Function.
Definition: sixtop.h:74
const sixtop_sf_t * sixtop_find_sf(uint8_t sfid)
Find a SF which has been added by SFID.
Definition: sixtop.c:110
void(* sixtop_sf_error)(sixp_error_t err, sixp_pkt_cmd_t cmd, uint8_t seqno, const linkaddr_t *peer_addr)
Error Handler of Scheduling Function.
Definition: sixtop.h:96
void sixtop_init(void)
Initialize 6top module This initialization function removes all the SFs which has been installed into...
Definition: sixtop.c:261
void sixtop_input(void)
Input a packet stored in packetbuf.
Definition: sixtop.c:204
uint8_t sfid
SFID.
Definition: sixtop.h:105
sixtop_sf_input input
Input Handler.
Definition: sixtop.h:108
6P Codes integrating Command IDs and Return Codes
Definition: sixp-pkt.h:103
int sixtop_add_sf(const sixtop_sf_t *sf)
Add a Scheduling Function (SF) to 6top Sublayer.
Definition: sixtop.c:74
sixtop_sf_error error
Internal Error Handler.
Definition: sixtop.h:110
6top Protocol (6P) Packet Manipulation APIs
sixtop_sf_timeout timeout
Transaction Timeout Handler.
Definition: sixtop.h:109
int sixtop_output(const linkaddr_t *dest_addr, mac_callback_t callback, void *arg)
Output a 6P packet which is supposestored in packetbuf.
Definition: sixtop.c:125
MAC driver header file
clock_time_t timeout_interval
Timeout Value.
Definition: sixtop.h:106