1 /** @file
2  * @brief Offloaded network device iface API
3  *
4  * This is not to be included by the application.
5  */
6 
7 /*
8  * Copyright (c) 2022 Nordic Semiconductor ASA
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef ZEPHYR_INCLUDE_OFFLOADED_NETDEV_H_
14 #define ZEPHYR_INCLUDE_OFFLOADED_NETDEV_H_
15 
16 #include <zephyr/kernel.h>
17 #include <zephyr/types.h>
18 #include <stdbool.h>
19 #include <zephyr/net/net_if.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @brief Offloaded Net Devices
27  * @defgroup offloaded_netdev Offloaded Net Devices
28  * @ingroup networking
29  * @{
30  */
31 
32 /** Types of offloaded netdev L2 */
33 enum offloaded_net_if_types {
34 	/** Unknown, device hasn't register a type */
35 	L2_OFFLOADED_NET_IF_TYPE_UNKNOWN,
36 
37 	/** Ethernet devices */
38 	L2_OFFLOADED_NET_IF_TYPE_ETHERNET,
39 
40 	/** Modem */
41 	L2_OFFLOADED_NET_IF_TYPE_MODEM,
42 
43 	/** IEEE 802.11 Wi-Fi */
44 	L2_OFFLOADED_NET_IF_TYPE_WIFI,
45 };
46 
47 /**
48  * @brief Extended net_if_api for offloaded ifaces/network devices, allowing handling of
49  *	  admin up/down state changes
50  */
51 struct offloaded_if_api {
52 	/**
53 	 * The net_if_api must be placed in first position in this
54 	 * struct so that we are compatible with network interface API.
55 	 */
56 	struct net_if_api iface_api;
57 
58 	/** Enable or disable the device (in response to admin state change) */
59 	int (*enable)(const struct net_if *iface, bool state);
60 
61 	/* Types of offloaded net device */
62 	enum offloaded_net_if_types (*get_type)(void);
63 };
64 
65 /* Ensure offloaded_if_api is compatible with net_if_api */
66 BUILD_ASSERT(offsetof(struct offloaded_if_api, iface_api) == 0);
67 
68 /**
69  * @brief Check if the offloaded network interface supports Wi-Fi.
70  *
71  * @param iface Pointer to network interface
72  *
73  * @return True if interface supports Wi-Fi, False otherwise.
74  */
net_off_is_wifi_offloaded(struct net_if * iface)75 static inline bool net_off_is_wifi_offloaded(struct net_if *iface)
76 {
77 	const struct offloaded_if_api *api = (const struct offloaded_if_api *)
78 		net_if_get_device(iface)->api;
79 
80 	return api->get_type && api->get_type() == L2_OFFLOADED_NET_IF_TYPE_WIFI;
81 }
82 
83 /**
84  * @}
85  */
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* ZEPHYR_INCLUDE_OFFLOADED_NETDEV_H_ */
92