5
5
*/
6
6
7
7
/** @file
8
- * @brief OpenThread L2 stack public header
8
+ * @brief OpenThread stack public header
9
9
*/
10
10
11
11
#ifndef ZEPHYR_INCLUDE_NET_OPENTHREAD_H_
12
12
#define ZEPHYR_INCLUDE_NET_OPENTHREAD_H_
13
13
14
14
/**
15
- * @brief OpenThread Layer 2 abstraction layer
16
- * @defgroup openthread OpenThread L2 abstraction layer
15
+ * @brief OpenThread stack public header
16
+ * @defgroup openthread OpenThread stack
17
17
* @since 1.11
18
18
* @version 0.8.0
19
19
* @ingroup ieee802154
20
20
* @{
21
21
*/
22
22
23
23
#include <zephyr/kernel.h>
24
-
25
24
#include <zephyr/net/net_if.h>
25
+ #include <zephyr/kernel/thread.h>
26
26
27
27
#include <openthread/instance.h>
28
+ #include <openthread/message.h>
28
29
29
30
#ifdef __cplusplus
30
31
extern "C" {
@@ -44,8 +45,10 @@ struct pkt_list_elem {
44
45
* @brief OpenThread l2 private data.
45
46
*/
46
47
struct openthread_context {
47
- /** Pointer to OpenThread stack instance */
48
- otInstance * instance ;
48
+ /** @deprecated Pointer to OpenThread stack instance. This is deprecated and will be removed
49
+ * in a future release. This field must not be used anymore.
50
+ */
51
+ __deprecated otInstance * instance ;
49
52
50
53
/** Pointer to OpenThread network interface */
51
54
struct net_if * iface ;
@@ -62,25 +65,74 @@ struct openthread_context {
62
65
/** Array for storing net_pkt for OpenThread internal usage */
63
66
struct pkt_list_elem pkt_list [CONFIG_OPENTHREAD_PKT_LIST_SIZE ];
64
67
65
- /** A mutex to protect API calls from being preempted. */
66
- struct k_mutex api_lock ;
68
+ /** @deprecated A mutex to protect API calls from being preempted. This is deprecated and
69
+ * will be removed in a future release. This field must not be used anymore.
70
+ */
71
+ __deprecated struct k_mutex api_lock ;
67
72
68
- /** A work queue for all OpenThread activity */
69
- struct k_work_q work_q ;
73
+ /** @deprecated A work queue for all OpenThread activity. This is deprecated and will be
74
+ * removed in a future release. This field must not be used anymore.
75
+ */
76
+ __deprecated struct k_work_q work_q ;
70
77
71
- /** Work object for OpenThread internal usage */
72
- struct k_work api_work ;
78
+ /** @deprecated Work object for OpenThread internal usage. This is deprecated and will be
79
+ * removed in a future release. This field must not be used anymore.
80
+ */
81
+ __deprecated struct k_work api_work ;
73
82
74
- /** A list for state change callbacks */
83
+ /** @deprecated A list for state change callbacks. This is deprecated and will be removed in
84
+ * a future release.
85
+ */
75
86
sys_slist_t state_change_cbs ;
76
87
};
77
88
/**
78
89
* INTERNAL_HIDDEN @endcond
79
90
*/
80
91
92
+ /**
93
+ * @brief The common callback type for receiving IPv4 (translated by NAT64) and IPv6 datagrams.
94
+ *
95
+ * This callback is called when a datagram is received.
96
+ *
97
+ * @param message The message to receive.
98
+ * @param context The context to pass to the callback.
99
+ */
100
+ typedef void (* openthread_receive_cb )(otMessage * message , void * context );
101
+
81
102
/** OpenThread state change callback */
82
103
83
104
/**
105
+ * @brief OpenThread state change callback structure
106
+ *
107
+ * Used to register a callback in the callback list. As many
108
+ * callbacks as needed can be added as long as each of them
109
+ * are unique pointers of struct openthread_state_changed_cb.
110
+ *
111
+ * @note You may destroy the object only after it is unregistered from the callback list.
112
+ */
113
+ struct openthread_state_changed_callback {
114
+ /**
115
+ * @brief Callback for notifying configuration or state changes.
116
+ *
117
+ * @param otCallback OpenThread callback to register.
118
+ * See https://openthread.io/reference/group/api-instance#otstatechangedcallback for
119
+ * details.
120
+ */
121
+ otStateChangedCallback otCallback ;
122
+
123
+ /** User data if required */
124
+ void * user_data ;
125
+
126
+ /**
127
+ * Internally used field for list handling
128
+ * - user must not directly modify
129
+ */
130
+ sys_snode_t node ;
131
+ };
132
+
133
+ /**
134
+ * @deprecated use @ref openthread_state_changed_callback instead.
135
+ *
84
136
* @brief OpenThread state change callback structure
85
137
*
86
138
* Used to register a callback in the callback list. As many
@@ -111,23 +163,42 @@ struct openthread_state_changed_cb {
111
163
};
112
164
113
165
/**
166
+ * @brief Register callbacks that will be called when a certain configuration
167
+ * or state changes occur within OpenThread.
168
+ *
169
+ * @param cb Callback struct to register.
170
+ */
171
+ int openthread_state_changed_callback_register (struct openthread_state_changed_callback * cb );
172
+
173
+ /**
174
+ * @brief Unregister OpenThread configuration or state changed callbacks.
175
+ *
176
+ * @param cb Callback struct to unregister.
177
+ */
178
+ int openthread_state_changed_callback_unregister (struct openthread_state_changed_callback * cb );
179
+
180
+ /**
181
+ * @deprecated use @ref openthread_state_changed_callback_register instead.
182
+ *
114
183
* @brief Registers callbacks which will be called when certain configuration
115
184
* or state changes occur within OpenThread.
116
185
*
117
186
* @param ot_context the OpenThread context to register the callback with.
118
187
* @param cb callback struct to register.
119
188
*/
120
- int openthread_state_changed_cb_register (struct openthread_context * ot_context ,
121
- struct openthread_state_changed_cb * cb );
189
+ __deprecated int openthread_state_changed_cb_register (struct openthread_context * ot_context ,
190
+ struct openthread_state_changed_cb * cb );
122
191
123
192
/**
193
+ * @deprecated use @ref openthread_state_changed_callback_unregister instead.
194
+ *
124
195
* @brief Unregisters OpenThread configuration or state changed callbacks.
125
196
*
126
197
* @param ot_context the OpenThread context to unregister the callback from.
127
198
* @param cb callback struct to unregister.
128
199
*/
129
- int openthread_state_changed_cb_unregister (struct openthread_context * ot_context ,
130
- struct openthread_state_changed_cb * cb );
200
+ __deprecated int openthread_state_changed_cb_unregister (struct openthread_context * ot_context ,
201
+ struct openthread_state_changed_cb * cb );
131
202
132
203
/**
133
204
* @brief Get OpenThread thread identification.
@@ -151,6 +222,44 @@ struct openthread_context *openthread_get_default_context(void);
151
222
struct otInstance * openthread_get_default_instance (void );
152
223
153
224
/**
225
+ * @brief Initialize the OpenThread module.
226
+ *
227
+ * This function:
228
+ * - Initializes the OpenThread module.
229
+ * - Creates an OpenThread single instance.
230
+ * - Starts the shell.
231
+ * - Enables the UART and NCP HDLC for coprocessor purposes.
232
+ * - Initializes the NAT64 translator.
233
+ * - Creates a work queue for the OpenThread module.
234
+ *
235
+ * @note This function is automatically called by Zephyr's networking layer.
236
+ * If you want to initialize the OpenThread independently, call this function
237
+ * in your application init code.
238
+ *
239
+ * @retval 0 On success.
240
+ * @retval -EIO On failure.
241
+ */
242
+ int openthread_init (void );
243
+
244
+ /**
245
+ * @brief Run the OpenThread network.
246
+ *
247
+ * @details Prepares the OpenThread network and enables it.
248
+ * Depends on active settings: it uses the stored network configuration,
249
+ * starts the joining procedure or uses the default network configuration.
250
+ * Additionally, when the device is MTD, it sets the SED mode to properly
251
+ * attach the network.
252
+ */
253
+ int openthread_run (void );
254
+
255
+ /**
256
+ * @brief Disable the OpenThread network.
257
+ */
258
+ int openthread_stop (void );
259
+
260
+ /**
261
+ * @deprecated use @ref openthread_run instead.
262
+ *
154
263
* @brief Starts the OpenThread network.
155
264
*
156
265
* @details Depends on active settings: it uses stored network configuration,
@@ -159,9 +268,46 @@ struct otInstance *openthread_get_default_instance(void);
159
268
*
160
269
* @param ot_context
161
270
*/
162
- int openthread_start (struct openthread_context * ot_context );
271
+ __deprecated int openthread_start (struct openthread_context * ot_context );
163
272
164
273
/**
274
+ * @brief Set the additional callback for receiving packets.
275
+ *
276
+ * @details This callback is called once a packet is received and can be
277
+ * used to inject packets into the Zephyr networking stack.
278
+ * Setting this callback is optional.
279
+ *
280
+ * @param cb Callback to set.
281
+ * @param context Context to pass to the callback.
282
+ */
283
+ void openthread_set_receive_cb (openthread_receive_cb cb , void * context );
284
+
285
+ /**
286
+ * @brief Lock internal mutex before accessing OpenThread API.
287
+ *
288
+ * @details OpenThread API is not thread-safe. Therefore, before accessing any
289
+ * API function, you need to lock the internal mutex, to prevent the
290
+ * OpenThread thread from pre-empting the API call.
291
+ */
292
+ void openthread_mutex_lock (void );
293
+
294
+ /**
295
+ * @brief Try to lock internal mutex before accessing OpenThread API.
296
+ *
297
+ * @details This function behaves like openthread_mutex_lock(), provided that
298
+ * the internal mutex is unlocked. Otherwise, it returns a negative value without
299
+ * waiting.
300
+ */
301
+ int openthread_mutex_try_lock (void );
302
+
303
+ /**
304
+ * @brief Unlock internal mutex after accessing OpenThread API.
305
+ */
306
+ void openthread_mutex_unlock (void );
307
+
308
+ /**
309
+ * @deprecated use @ref openthread_mutex_lock.
310
+ *
165
311
* @brief Lock internal mutex before accessing OT API.
166
312
*
167
313
* @details OpenThread API is not thread-safe, therefore before accessing any
@@ -170,9 +316,11 @@ int openthread_start(struct openthread_context *ot_context);
170
316
*
171
317
* @param ot_context Context to lock.
172
318
*/
173
- void openthread_api_mutex_lock (struct openthread_context * ot_context );
319
+ __deprecated void openthread_api_mutex_lock (struct openthread_context * ot_context );
174
320
175
321
/**
322
+ * @deprecated use @ref openthread_mutex_try_lock instead.
323
+ *
176
324
* @brief Try to lock internal mutex before accessing OT API.
177
325
*
178
326
* @details This function behaves like openthread_api_mutex_lock() provided that
@@ -183,14 +331,16 @@ void openthread_api_mutex_lock(struct openthread_context *ot_context);
183
331
* @retval 0 On success.
184
332
* @retval <0 On failure.
185
333
*/
186
- int openthread_api_mutex_try_lock (struct openthread_context * ot_context );
334
+ __deprecated int openthread_api_mutex_try_lock (struct openthread_context * ot_context );
187
335
188
336
/**
337
+ * @deprecated use @ref openthread_mutex_unlock instead.
338
+ *
189
339
* @brief Unlock internal mutex after accessing OT API.
190
340
*
191
341
* @param ot_context Context to unlock.
192
342
*/
193
- void openthread_api_mutex_unlock (struct openthread_context * ot_context );
343
+ __deprecated void openthread_api_mutex_unlock (struct openthread_context * ot_context );
194
344
195
345
/** @cond INTERNAL_HIDDEN */
196
346
0 commit comments