Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
conn_mgr_connectivity_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_CONN_MGR_CONNECTIVITY_IMPL_H_
14#define ZEPHYR_INCLUDE_CONN_MGR_CONNECTIVITY_IMPL_H_
15
16#include <zephyr/device.h>
17#include <zephyr/net/net_if.h>
19#include <zephyr/net/net_mgmt.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
35/* Forward declaration */
37
53 int (*connect)(struct conn_mgr_conn_binding *const binding);
54
64 int (*disconnect)(struct conn_mgr_conn_binding *const binding);
65
76 void (*init)(struct conn_mgr_conn_binding *const binding);
77
96 int (*set_opt)(struct conn_mgr_conn_binding *const binding,
97 int optname, const void *optval, size_t optlen);
98
114 int (*get_opt)(struct conn_mgr_conn_binding *const binding,
115 int optname, void *optval, size_t *optlen);
116};
117
119#define CONN_MGR_CONN_IMPL_GET_NAME(conn_id) __conn_mgr_conn_##conn_id
120#define CONN_MGR_CONN_IMPL_GET_CTX_TYPE(conn_id) conn_id##_CTX_TYPE
132
139#define CONN_MGR_CONN_DEFINE(conn_id, conn_api) \
140 const struct conn_mgr_conn_impl CONN_MGR_CONN_IMPL_GET_NAME(conn_id) = { \
141 .api = conn_api, \
142 };
143
147#define CONN_MGR_CONN_DECLARE_PUBLIC(conn_id) \
148 extern const struct conn_mgr_conn_impl CONN_MGR_CONN_IMPL_GET_NAME(conn_id)
149
151#define CONN_MGR_CONN_BINDING_GET_NAME(dev_id, sfx) __conn_mgr_bndg_##dev_id##_##sfx
152#define CONN_MGR_CONN_BINDING_GET_DATA(dev_id, sfx) __conn_mgr_bndg_data_##dev_id##_##sfx
153#define CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, sfx) __conn_mgr_bndg_mutex_##dev_id##_##sfx
164 struct net_if *iface;
165
168
170 void *ctx;
171
184
197
201 /* Internal-use mutex for protecting access to the binding and API functions. */
202 struct k_mutex *mutex;
204};
205
213#define CONN_MGR_BIND_CONN_INST(dev_id, inst, conn_id) \
214 K_MUTEX_DEFINE(CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, inst)); \
215 static CONN_MGR_CONN_IMPL_GET_CTX_TYPE(conn_id) \
216 CONN_MGR_CONN_BINDING_GET_DATA(dev_id, inst); \
217 static STRUCT_SECTION_ITERABLE(conn_mgr_conn_binding, \
218 CONN_MGR_CONN_BINDING_GET_NAME(dev_id, inst)) = { \
219 .iface = NET_IF_GET(dev_id, inst), \
220 .impl = &(CONN_MGR_CONN_IMPL_GET_NAME(conn_id)), \
221 .ctx = &(CONN_MGR_CONN_BINDING_GET_DATA(dev_id, inst)), \
222 .mutex = &(CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, inst)) \
223 };
224
231#define CONN_MGR_BIND_CONN(dev_id, conn_id) \
232 CONN_MGR_BIND_CONN_INST(dev_id, 0, conn_id)
233
246{
248 if (iface == binding->iface) {
249 if (binding->impl->api) {
250 return binding;
251 }
252 return NULL;
253 }
254 }
255 return NULL;
256}
257
270static inline void conn_mgr_binding_lock(struct conn_mgr_conn_binding *binding)
271{
272 (void)k_mutex_lock(binding->mutex, K_FOREVER);
273}
274
286static inline void conn_mgr_binding_unlock(struct conn_mgr_conn_binding *binding)
287{
288 (void)k_mutex_unlock(binding->mutex);
289}
290
302static inline void conn_mgr_binding_set_flag(struct conn_mgr_conn_binding *binding,
303 enum conn_mgr_if_flag flag, bool value)
304{
305 conn_mgr_binding_lock(binding);
306
307 binding->flags &= ~BIT(flag);
308 if (value) {
309 binding->flags |= BIT(flag);
310 }
311
313}
314
326static inline bool conn_mgr_binding_get_flag(struct conn_mgr_conn_binding *binding,
327 enum conn_mgr_if_flag flag)
328{
329 bool value = false;
330
331 conn_mgr_binding_lock(binding);
332
333 value = !!(binding->flags & BIT(flag));
334
336
337 return value;
338}
339
344#ifdef __cplusplus
345}
346#endif
347
348#endif /* ZEPHYR_INCLUDE_CONN_MGR_CONNECTIVITY_IMPL_H_ */
API for controlling generic network association routines on network devices that support it.
#define K_FOREVER
Generate infinite timeout delay.
Definition kernel.h:1440
static bool conn_mgr_binding_get_flag(struct conn_mgr_conn_binding *binding, enum conn_mgr_if_flag flag)
Check the value of the specified connectivity flag for the provided binding.
Definition conn_mgr_connectivity_impl.h:326
static void conn_mgr_binding_lock(struct conn_mgr_conn_binding *binding)
Lock the passed-in binding, making it safe to access.
Definition conn_mgr_connectivity_impl.h:270
static void conn_mgr_binding_set_flag(struct conn_mgr_conn_binding *binding, enum conn_mgr_if_flag flag, bool value)
Set the value of the specified connectivity flag for the provided binding.
Definition conn_mgr_connectivity_impl.h:302
static struct conn_mgr_conn_binding * conn_mgr_if_get_binding(struct net_if *iface)
Retrieves the conn_mgr binding struct for a provided iface if it exists.
Definition conn_mgr_connectivity_impl.h:245
static void conn_mgr_binding_unlock(struct conn_mgr_conn_binding *binding)
Unlocks the passed-in binding.
Definition conn_mgr_connectivity_impl.h:286
conn_mgr_if_flag
Per-iface connectivity flags.
Definition conn_mgr_connectivity.h:67
#define STRUCT_SECTION_FOREACH(struct_type, iterator)
Iterate over a specified iterable section.
Definition iterable_sections.h:270
int k_mutex_unlock(struct k_mutex *mutex)
Unlock a mutex.
int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
Lock a mutex.
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
Public API for network interface.
Network Management API public header.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Connectivity Manager Connectivity API structure.
Definition conn_mgr_connectivity_impl.h:43
int(* get_opt)(struct conn_mgr_conn_binding *const binding, int optname, void *optval, size_t *optlen)
Implementation callback for conn_mgr_if_get_opt.
Definition conn_mgr_connectivity_impl.h:114
int(* set_opt)(struct conn_mgr_conn_binding *const binding, int optname, const void *optval, size_t optlen)
Implementation callback for conn_mgr_if_set_opt.
Definition conn_mgr_connectivity_impl.h:96
int(* connect)(struct conn_mgr_conn_binding *const binding)
When called, the connectivity implementation should start attempting to establish connectivity (assoc...
Definition conn_mgr_connectivity_impl.h:53
void(* init)(struct conn_mgr_conn_binding *const binding)
Called once for each iface that has been bound to a connectivity implementation using this API.
Definition conn_mgr_connectivity_impl.h:76
int(* disconnect)(struct conn_mgr_conn_binding *const binding)
When called, the connectivity implementation should disconnect (disassociate), or stop any in-progres...
Definition conn_mgr_connectivity_impl.h:64
Connectivity Manager network interface binding structure.
Definition conn_mgr_connectivity_impl.h:162
const struct conn_mgr_conn_impl * impl
The connectivity implementation the network device is bound to.
Definition conn_mgr_connectivity_impl.h:167
struct net_if * iface
The network interface the connectivity implementation is bound to.
Definition conn_mgr_connectivity_impl.h:164
int timeout
Timeout (seconds)
Definition conn_mgr_connectivity_impl.h:196
uint32_t flags
Connectivity flags.
Definition conn_mgr_connectivity_impl.h:183
void * ctx
Pointer to private, per-iface connectivity context.
Definition conn_mgr_connectivity_impl.h:170
Connectivity Implementation struct.
Definition conn_mgr_connectivity_impl.h:128
struct conn_mgr_conn_api * api
The connectivity API used by the implementation.
Definition conn_mgr_connectivity_impl.h:130
Mutex Structure.
Definition kernel.h:2994
Network Interface structure.
Definition net_if.h:680