Zephyr Project API 3.7.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
33/* Forward declaration */
35
51 int (*connect)(struct conn_mgr_conn_binding *const binding);
52
62 int (*disconnect)(struct conn_mgr_conn_binding *const binding);
63
74 void (*init)(struct conn_mgr_conn_binding *const binding);
75
94 int (*set_opt)(struct conn_mgr_conn_binding *const binding,
95 int optname, const void *optval, size_t optlen);
96
112 int (*get_opt)(struct conn_mgr_conn_binding *const binding,
113 int optname, void *optval, size_t *optlen);
114};
115
117#define CONN_MGR_CONN_IMPL_GET_NAME(conn_id) __conn_mgr_conn_##conn_id
118#define CONN_MGR_CONN_IMPL_GET_CTX_TYPE(conn_id) conn_id##_CTX_TYPE
130
137#define CONN_MGR_CONN_DEFINE(conn_id, conn_api) \
138 const struct conn_mgr_conn_impl CONN_MGR_CONN_IMPL_GET_NAME(conn_id) = { \
139 .api = conn_api, \
140 };
141
145#define CONN_MGR_CONN_DECLARE_PUBLIC(conn_id) \
146 extern const struct conn_mgr_conn_impl CONN_MGR_CONN_IMPL_GET_NAME(conn_id)
147
149#define CONN_MGR_CONN_BINDING_GET_NAME(dev_id, sfx) __conn_mgr_bndg_##dev_id##_##sfx
150#define CONN_MGR_CONN_BINDING_GET_DATA(dev_id, sfx) __conn_mgr_bndg_data_##dev_id##_##sfx
151#define CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, sfx) __conn_mgr_bndg_mutex_##dev_id##_##sfx
162 struct net_if *iface;
163
166
168 void *ctx;
169
182
195
199 /* Internal-use mutex for protecting access to the binding and API functions. */
200 struct k_mutex *mutex;
202};
203
211#define CONN_MGR_BIND_CONN_INST(dev_id, inst, conn_id) \
212 K_MUTEX_DEFINE(CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, inst)); \
213 static CONN_MGR_CONN_IMPL_GET_CTX_TYPE(conn_id) \
214 CONN_MGR_CONN_BINDING_GET_DATA(dev_id, inst); \
215 static STRUCT_SECTION_ITERABLE(conn_mgr_conn_binding, \
216 CONN_MGR_CONN_BINDING_GET_NAME(dev_id, inst)) = { \
217 .iface = NET_IF_GET(dev_id, inst), \
218 .impl = &(CONN_MGR_CONN_IMPL_GET_NAME(conn_id)), \
219 .ctx = &(CONN_MGR_CONN_BINDING_GET_DATA(dev_id, inst)), \
220 .mutex = &(CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, inst)) \
221 };
222
229#define CONN_MGR_BIND_CONN(dev_id, conn_id) \
230 CONN_MGR_BIND_CONN_INST(dev_id, 0, conn_id)
231
244{
246 if (iface == binding->iface) {
247 if (binding->impl->api) {
248 return binding;
249 }
250 return NULL;
251 }
252 }
253 return NULL;
254}
255
268static inline void conn_mgr_binding_lock(struct conn_mgr_conn_binding *binding)
269{
270 (void)k_mutex_lock(binding->mutex, K_FOREVER);
271}
272
284static inline void conn_mgr_binding_unlock(struct conn_mgr_conn_binding *binding)
285{
286 (void)k_mutex_unlock(binding->mutex);
287}
288
300static inline void conn_mgr_binding_set_flag(struct conn_mgr_conn_binding *binding,
301 enum conn_mgr_if_flag flag, bool value)
302{
303 conn_mgr_binding_lock(binding);
304
305 binding->flags &= ~BIT(flag);
306 if (value) {
307 binding->flags |= BIT(flag);
308 }
309
311}
312
324static inline bool conn_mgr_binding_get_flag(struct conn_mgr_conn_binding *binding,
326{
327 bool value = false;
328
329 conn_mgr_binding_lock(binding);
330
331 value = !!(binding->flags & BIT(flag));
332
334
335 return value;
336}
337
342#ifdef __cplusplus
343}
344#endif
345
346#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:1363
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:324
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:268
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:300
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:243
static void conn_mgr_binding_unlock(struct conn_mgr_conn_binding *binding)
Unlocks the passed-in binding.
Definition conn_mgr_connectivity_impl.h:284
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
struct k_mutex mutex
Definition kobject.c:1318
Public API for network interface.
Network Management API public header.
static ZTEST_DMEM int flag
Definition main.c:26
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Connectivity Manager Connectivity API structure.
Definition conn_mgr_connectivity_impl.h:41
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:112
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:94
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:51
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:74
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:62
Connectivity Manager network interface binding structure.
Definition conn_mgr_connectivity_impl.h:160
const struct conn_mgr_conn_impl * impl
The connectivity implementation the network device is bound to.
Definition conn_mgr_connectivity_impl.h:165
struct net_if * iface
The network interface the connectivity implementation is bound to.
Definition conn_mgr_connectivity_impl.h:162
int timeout
Timeout (seconds)
Definition conn_mgr_connectivity_impl.h:194
uint32_t flags
Connectivity flags.
Definition conn_mgr_connectivity_impl.h:181
void * ctx
Pointer to private, per-iface connectivity context.
Definition conn_mgr_connectivity_impl.h:168
Connectivity Implementation struct.
Definition conn_mgr_connectivity_impl.h:126
struct conn_mgr_conn_api * api
The connectivity API used by the implementation.
Definition conn_mgr_connectivity_impl.h:128
Mutex Structure.
Definition kernel.h:2917
Network Interface structure.
Definition net_if.h:678