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_SENT,
51  SIXP_TRANS_STATE_REQUEST_RECEIVED,
52  SIXP_TRANS_STATE_RESPONSE_SENT,
53  SIXP_TRANS_STATE_RESPONSE_RECEIVED,
54  SIXP_TRANS_STATE_CONFIRMATION_SENT,
55  SIXP_TRANS_STATE_CONFIRMATION_RECEIVED,
56  SIXP_TRANS_STATE_TERMINATING,
58 
59 /**
60  * \brief 6P Transaction Modes (for internal use)
61  */
62 typedef enum {
63  SIXP_TRANS_MODE_UNAVAILABLE = 0,
64  SIXP_TRANS_MODE_2_STEP,
65  SIXP_TRANS_MODE_3_STEP
67 
68 typedef struct sixp_trans sixp_trans_t;
69 
70 /**
71  * \brief Change the state of a specified transaction
72  * \param trans The pointer to a transaction
73  * \param new_state New state to move the transaction to
74  * \return 0 on success, -1 on failure
75  */
77  sixp_trans_state_t new_state);
78 
79 /**
80  * \brief Return the command associated with a specified transaction
81  * \param trans The pointer to a transaction
82  * \return Command identifier; SIXP_PKT_CMD_UNAVAILABLE on failure
83  */
85 
86 /**
87  * \brief Return the state of a specified transaction
88  * \param trans The pointer to a transaction
89  * \return a state of the transaction; SIXP_TRANS_STATE_UNAVAILABLE if the
90  * transaction is not found in the system.
91  */
93 
94 /**
95  * \brief Return the sequence number associated with a specified transaction
96  * \param trans The pointer of a transaction
97  * \return 0 or larger than 0 on success, -1 on failure
98  */
99 int16_t sixp_trans_get_seqno(sixp_trans_t *trans);
100 
101 /**
102  * \brief Return the mode, 2-step or 3-step, of a specified transaction
103  * \param trans The pointer to a transaction
104  * \return The mode of the transaction, SIXP_TRANS_MODE_UNAVAILABLE on failure
105  */
107 
108 /**
109  * \brief Invoke the output callback of a specified transaction
110  * \param trans The pointer to a transaction
111  * \param status An output result value
112  */
114  sixp_output_status_t status);
115 
116 /**
117  * \brief Set an output callback to a specified transaction
118  * \param trans The pointer to a transaction
119  * \param func The pointer to a callback function
120  * \param arg The pointer to an argument which will be passed to func
121  * \param arg_len The length of the argument
122  */
125  void *arg,
126  uint16_t arg_len);
127 
128 /**
129  * \brief Allocate a transaction
130  * \param pkt The pointer to a packet which triggers the allocation
131  * \param peer_addr The peer address which will be associated
132  * \return A pointer to an newly allocated transaction, NULL on failure
133  */
135  const linkaddr_t *peer_addr);
136 
137 /**
138  * \brief Find a transaction
139  * \param peer_addr The peer address
140  * \return The pointer to a transaction; NULL on failure
141  */
142 sixp_trans_t *sixp_trans_find(const linkaddr_t *peer_addr);
143 
144 /**
145  * \brief Initialize Memory and List for 6P transactions
146  * This function removes and frees existing transactions.
147  */
148 int sixp_trans_init(void);
149 
150 /*---------------------------------------------------------------------------*/
151 /** @} */
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:62
int sixp_trans_init(void)
Initialize Memory and List for 6P transactions This function removes and frees existing transactions...
Definition: sixp-trans.c:411
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:328
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:316
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:274
sixp_trans_t * sixp_trans_find(const linkaddr_t *peer_addr)
Find a transaction.
Definition: sixp-trans.c:384
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:73
sixp_trans_state_t sixp_trans_get_state(sixp_trans_t *trans)
Return the state of a specified transaction.
Definition: sixp-trans.c:284
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:294
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:341
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:206
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:305