Zephyr API Documentation 4.4.99
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
12
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
34
35/* Forward declaration */
37
59
69 int (*connect)(struct conn_mgr_conn_binding *const binding);
70
78 int (*disconnect)(struct conn_mgr_conn_binding *const binding);
79
90 void (*init)(struct conn_mgr_conn_binding *const binding);
91
110 int (*set_opt)(struct conn_mgr_conn_binding *const binding,
111 int optname, const void *optval, size_t optlen);
112
128 int (*get_opt)(struct conn_mgr_conn_binding *const binding,
129 int optname, void *optval, size_t *optlen);
130};
131
133#define CONN_MGR_CONN_IMPL_GET_NAME(conn_id) __conn_mgr_conn_##conn_id
134#define CONN_MGR_CONN_IMPL_GET_CTX_TYPE(conn_id) conn_id##_CTX_TYPE
136
146
153#define CONN_MGR_CONN_DEFINE(conn_id, conn_api) \
154 const struct conn_mgr_conn_impl CONN_MGR_CONN_IMPL_GET_NAME(conn_id) = { \
155 .api = conn_api, \
156 };
157
161#define CONN_MGR_CONN_DECLARE_PUBLIC(conn_id) \
162 extern const struct conn_mgr_conn_impl CONN_MGR_CONN_IMPL_GET_NAME(conn_id)
163
165#define CONN_MGR_CONN_BINDING_GET_NAME(dev_id, sfx) __conn_mgr_bndg_##dev_id##_##sfx
166#define CONN_MGR_CONN_BINDING_GET_DATA(dev_id, sfx) __conn_mgr_bndg_data_##dev_id##_##sfx
167#define CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, sfx) __conn_mgr_bndg_mutex_##dev_id##_##sfx
169
178 struct net_if *iface;
179
182
184 void *ctx;
185
190
198
211
221
223
225 /* Internal-use work item for tracking interface idle timeouts */
226 struct k_work_delayable idle_worker;
227
228 /* Internal-use mutex for protecting access to the binding and API functions. */
229 struct k_mutex *mutex;
231};
232
240#define CONN_MGR_BIND_CONN_INST(dev_id, inst, conn_id) \
241 K_MUTEX_DEFINE(CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, inst)); \
242 static CONN_MGR_CONN_IMPL_GET_CTX_TYPE(conn_id) \
243 CONN_MGR_CONN_BINDING_GET_DATA(dev_id, inst); \
244 static STRUCT_SECTION_ITERABLE(conn_mgr_conn_binding, \
245 CONN_MGR_CONN_BINDING_GET_NAME(dev_id, inst)) = { \
246 .iface = NET_IF_GET(dev_id, inst), \
247 .impl = &(CONN_MGR_CONN_IMPL_GET_NAME(conn_id)), \
248 .ctx = &(CONN_MGR_CONN_BINDING_GET_DATA(dev_id, inst)), \
249 .mutex = &(CONN_MGR_CONN_BINDING_GET_MUTEX(dev_id, inst)) \
250 };
251
258#define CONN_MGR_BIND_CONN(dev_id, conn_id) \
259 CONN_MGR_BIND_CONN_INST(dev_id, 0, conn_id)
260
273{
275 if (iface == binding->iface) {
276 if (binding->impl->api) {
277 return binding;
278 }
279 return NULL;
280 }
281 }
282 return NULL;
283}
284
297static inline void conn_mgr_binding_lock(struct conn_mgr_conn_binding *binding)
298{
299 (void)k_mutex_lock(binding->mutex, K_FOREVER);
300}
301
313static inline void conn_mgr_binding_unlock(struct conn_mgr_conn_binding *binding)
314{
315 (void)k_mutex_unlock(binding->mutex);
316}
317
329static inline void conn_mgr_binding_set_flag(struct conn_mgr_conn_binding *binding,
330 enum conn_mgr_if_flag flag, bool value)
331{
332 conn_mgr_binding_lock(binding);
333
334 binding->flags &= ~BIT(flag);
335 if (value) {
336 binding->flags |= BIT(flag);
337 }
338
340}
341
353static inline bool conn_mgr_binding_get_flag(struct conn_mgr_conn_binding *binding,
354 enum conn_mgr_if_flag flag)
355{
356 bool value = false;
357
358 conn_mgr_binding_lock(binding);
359
360 value = !!(binding->flags & BIT(flag));
361
363
364 return value;
365}
366
370
371#ifdef __cplusplus
372}
373#endif
374
375#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:1664
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:353
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:297
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:329
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:272
static void conn_mgr_binding_unlock(struct conn_mgr_conn_binding *binding)
Unlocks the passed-in binding.
Definition conn_mgr_connectivity_impl.h:313
conn_mgr_if_flag
Per-iface connectivity flags.
Definition conn_mgr_connectivity.h:92
#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
#define NULL
Definition iar_missing_defs.h:20
Public API for network interface.
Network Management API public header.
#define bool
Definition stdbool.h:13
__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:128
bool(* has_connection_config)(struct conn_mgr_conn_binding *const binding)
When called, the connectivity implementation should return whether it has the configuration needed to...
Definition conn_mgr_connectivity_impl.h:58
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:110
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:69
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:90
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:78
Connectivity Manager network interface binding structure.
Definition conn_mgr_connectivity_impl.h:176
const struct conn_mgr_conn_impl * impl
The connectivity implementation the network device is bound to.
Definition conn_mgr_connectivity_impl.h:181
int idle_timeout
Usage timeout (seconds).
Definition conn_mgr_connectivity_impl.h:220
struct net_if * iface
The network interface the connectivity implementation is bound to.
Definition conn_mgr_connectivity_impl.h:178
int timeout
Timeout (seconds).
Definition conn_mgr_connectivity_impl.h:210
uint32_t flags
Connectivity flags.
Definition conn_mgr_connectivity_impl.h:197
void * ctx
Pointer to private, per-iface connectivity context.
Definition conn_mgr_connectivity_impl.h:184
Connectivity Implementation struct.
Definition conn_mgr_connectivity_impl.h:142
struct conn_mgr_conn_api * api
The connectivity API used by the implementation.
Definition conn_mgr_connectivity_impl.h:144
Kernel mutex structure.
Definition kernel.h:3437
A structure used to submit work after a delay.
Definition kernel.h:4603
Network Interface structure.
Definition net_if.h:731