Contiki-NG
sixp-trans.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 sixtop
32  * @{
33  */
34 /**
35  * \file
36  * Transaction Management APIs for 6top Protocol (6P)
37  * \author
38  * Yasuyuki Tanaka <yasuyuki.tanaka@inf.ethz.ch>
39  */
40 
41 #include "sixp.h"
42 #include "sixp-pkt.h"
43 
44 /**
45  * \brief 6P Transaction States (for internal use)
46  */
47 typedef enum {
48  SIXP_TRANS_STATE_UNAVAILABLE = 0,
49  SIXP_TRANS_STATE_INIT,
50  SIXP_TRANS_STATE_REQUEST_SENDING,
51  SIXP_TRANS_STATE_REQUEST_SENT,
52  SIXP_TRANS_STATE_REQUEST_RECEIVED,
53  SIXP_TRANS_STATE_RESPONSE_SENDING,
54  SIXP_TRANS_STATE_RESPONSE_SENT,
55  SIXP_TRANS_STATE_RESPONSE_RECEIVED,
56  SIXP_TRANS_STATE_CONFIRMATION_SENDING,
57  SIXP_TRANS_STATE_CONFIRMATION_SENT,
58  SIXP_TRANS_STATE_CONFIRMATION_RECEIVED,
59  SIXP_TRANS_STATE_TERMINATING,
60  SIXP_TRANS_STATE_WAIT_FREE,
62 
63 /**
64  * \brief 6P Transaction Modes (for internal use)
65  */
66 typedef enum {
67  SIXP_TRANS_MODE_UNAVAILABLE = 0,
68  SIXP_TRANS_MODE_2_STEP,
69  SIXP_TRANS_MODE_3_STEP
71 
72 typedef struct sixp_trans sixp_trans_t;
73 
74 /**
75  * \brief Change the state of a specified transaction
76  * \param trans The pointer to a transaction
77  * \param new_state New state to move the transaction to
78  * \return 0 on success, -1 on failure
79  */
81  sixp_trans_state_t new_state);
82 
83 /**
84  * \brief Return the scheduling function associated with a specified transaction
85  * \param trans The pointer to a transaction
86  * \return Pointer to a scheduling function (sixp_sf_t)
87  */
89 
90 /**
91  * \brief Return the command associated with a specified transaction
92  * \param trans The pointer to a transaction
93  * \return Command identifier; SIXP_PKT_CMD_UNAVAILABLE on failure
94  */
96 
97 /**
98  * \brief Return the state of a specified transaction
99  * \param trans The pointer to a transaction
100  * \return a state of the transaction; SIXP_TRANS_STATE_UNAVAILABLE if the
101  * transaction is not found in the system.
102  */
104 
105 /**
106  * \brief Return the sequence number associated with a specified transaction
107  * \param trans The pointer of a transaction
108  * \return 0 or larger than 0 on success, -1 on failure
109  */
110 int16_t sixp_trans_get_seqno(sixp_trans_t *trans);
111 
112 /**
113  * \brief Return the mode, 2-step or 3-step, of a specified transaction
114  * \param trans The pointer to a transaction
115  * \return The mode of the transaction, SIXP_TRANS_MODE_UNAVAILABLE on failure
116  */
118 
119 /**
120  * \brief Return the peer addr of a specified transaction
121  * \param trans The pointer to a transaction
122  * \return The pointer to the peer addr
123  */
124 const linkaddr_t *sixp_trans_get_peer_addr(sixp_trans_t *trans);
125 
126 /**
127  * \brief Invoke the output callback of a specified transaction
128  * \param trans The pointer to a transaction
129  * \param status An output result value
130  */
132  sixp_output_status_t status);
133 
134 /**
135  * \brief Set an output callback to a specified transaction
136  * \param trans The pointer to a transaction
137  * \param func The pointer to a callback function
138  * \param arg The pointer to an argument which will be passed to func
139  * \param arg_len The length of the argument
140  */
143  void *arg,
144  uint16_t arg_len);
145 
146 /**
147  * \brief Allocate a transaction
148  * \param pkt The pointer to a packet which triggers the allocation
149  * \param peer_addr The peer address which will be associated
150  * \return A pointer to an newly allocated transaction, NULL on failure
151  */
153  const linkaddr_t *peer_addr);
154 
155 /**
156  * \brief Helper function to terminate a transaction
157  * \param trans The pointer to a transaction to terminate
158  */
160 
161 /**
162  * \brief Helper function to abort a transaction immediately
163  * \param trans The pointer to a transaction to terminate
164  */
165 void sixp_trans_abort(sixp_trans_t *trans);
166 
167 /**
168  * \brief Free a transaction
169  * \param trans The pointer to a transaction to be freed
170  * \note This function is for internal use only, which is NOT expected
171  * to be called by a scheduling function, for instance.
172  */
173 void sixp_trans_free(sixp_trans_t *trans);
174 
175 /**
176  * \brief Find a transaction
177  * \param peer_addr The peer address
178  * \return The pointer to a transaction; NULL on failure
179  */
180 sixp_trans_t *sixp_trans_find(const linkaddr_t *peer_addr);
181 
182 /**
183  * \brief Initialize Memory and List for 6P transactions
184  * This function removes and frees existing transactions.
185  */
186 int sixp_trans_init(void);
187 
188 /*---------------------------------------------------------------------------*/
189 /** @} */
sixp_pkt_cmd_t
6P Command Identifiers
Definition: sixp-pkt.h:72
sixp_trans_mode_t
6P Transaction Modes (for internal use)
Definition: sixp-trans.h:66
int sixp_trans_init(void)
Initialize Memory and List for 6P transactions This function removes and frees existing transactions...
Definition: sixp-trans.c:489
/brief Scheduling Function Driver
Definition: sixtop.h:104
void sixp_trans_set_callback(sixp_trans_t *trans, sixp_sent_callback_t func, void *arg, uint16_t arg_len)
Set an output callback to a specified transaction.
Definition: sixp-trans.c:375
void sixp_trans_abort(sixp_trans_t *trans)
Helper function to abort a transaction immediately.
Definition: sixp-trans.c:469
6top Protocol (6P) APIs
void sixp_trans_invoke_callback(sixp_trans_t *trans, sixp_output_status_t status)
Invoke the output callback of a specified transaction.
Definition: sixp-trans.c:363
struct sixp_trans sixp_trans_t
6P Transaction Data Structure (for internal use)
sixp_pkt_cmd_t sixp_trans_get_cmd(sixp_trans_t *trans)
Return the command associated with a specified transaction.
Definition: sixp-trans.c:310
sixp_trans_t * sixp_trans_find(const linkaddr_t *peer_addr)
Find a transaction.
Definition: sixp-trans.c:431
void(* sixp_sent_callback_t)(void *arg, uint16_t arg_len, const linkaddr_t *dest_addr, sixp_output_status_t status)
6P Packet Sent Handler
Definition: sixp.h:74
sixp_trans_state_t sixp_trans_get_state(sixp_trans_t *trans)
Return the state of a specified transaction.
Definition: sixp-trans.c:320
const sixtop_sf_t * sixp_trans_get_sf(sixp_trans_t *trans)
Return the scheduling function associated with a specified transaction.
Definition: sixp-trans.c:299
const linkaddr_t * sixp_trans_get_peer_addr(sixp_trans_t *trans)
Return the peer addr of a specified transaction.
Definition: sixp-trans.c:352
6top IE Structure
Definition: sixp-pkt.h:121
6top Protocol (6P) Packet Manipulation APIs
sixp_trans_state_t
6P Transaction States (for internal use)
Definition: sixp-trans.h:47
int16_t sixp_trans_get_seqno(sixp_trans_t *trans)
Return the sequence number associated with a specified transaction.
Definition: sixp-trans.c:330
void sixp_trans_terminate(sixp_trans_t *trans)
Helper function to terminate a transaction.
Definition: sixp-trans.c:458
void sixp_trans_free(sixp_trans_t *trans)
Free a transaction.
Definition: sixp-trans.c:166
sixp_output_status_t
6P Send Status, which represents sixp_output() result.
Definition: sixp.h:65
sixp_trans_t * sixp_trans_alloc(const sixp_pkt_t *pkt, const linkaddr_t *peer_addr)
Allocate a transaction.
Definition: sixp-trans.c:388
int sixp_trans_transit_state(sixp_trans_t *trans, sixp_trans_state_t new_state)
Change the state of a specified transaction.
Definition: sixp-trans.c:224
sixp_trans_mode_t sixp_trans_get_mode(sixp_trans_t *trans)
Return the mode, 2-step or 3-step, of a specified transaction.
Definition: sixp-trans.c:341