1 /***************************************************************************/ /**
2  * @file
3  * @brief Networking constants
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2022 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 #pragma once
31 
32 #include <stdint.h>
33 #include <limits.h>
34 #include "sl_wifi_constants.h"
35 
36 /// Network Interface Type mask
37 #define NETWORK_INTERFACE_TYPE_MASK 0xFFF8
38 
39 /// Interface Type Selection
40 #define SL_NET_INTERFACE_TYPE(x) (x & NETWORK_INTERFACE_TYPE_MASK)
41 
42 /** \addtogroup SL_NET_CONSTANTS Constants
43  * @{ */
44 
45 // Enumeration of network interfaces.
46 // @note Only Wi-Fi client and Wi-Fi access point interfaces currently supported.
47 /**
48  * @enum sl_net_interface_t
49  * @brief Enumeration of network interfaces.
50  *
51  * @details
52  * This enumeration defines the various network interfaces supported by the system. Currently, only `SL_NET_WIFI_CLIENT_INTERFACE` and `SL_NET_WIFI_AP_INTERFACE` are supported.
53  */
54 typedef enum {
55   SL_NET_WIFI_CLIENT_INTERFACE = (1 << 3), ///< Wi-Fi Client Interface
56   SL_NET_WIFI_AP_INTERFACE     = (2 << 3), ///< Wi-Fi Access Point Interface
57   SL_NET_ETHERNET_INTERFACE    = (3 << 3), ///< Ethernet Interface (not currently supported)
58   SL_NET_THREAD_INTERFACE      = (4 << 3), ///< Thread Interface (not currently supported)
59   SL_NET_BLUETOOTH_INTERFACE   = (5 << 3), ///< Bluetooth Interface (not currently supported)
60   SL_NET_ZWAVE_INTERFACE       = (6 << 3), ///< Z-Wave Interface (not currently supported)
61 } sl_net_interface_t;
62 /** @} */
63 
64 /// WiFi Client Interface
65 #define SL_NET_WIFI_CLIENT_INTERFACE (1 << 3)
66 
67 /// WiFi Access Point Interface
68 #define SL_NET_WIFI_AP_INTERFACE (2 << 3)
69 
70 /// Ethernet Interface
71 #define SL_NET_ETHERNET_INTERFACE (3 << 3)
72 
73 /// Thread Interface
74 #define SL_NET_THREAD_INTERFACE (4 << 3)
75 
76 /// Bluetooth Interface
77 #define SL_NET_BLUETOOTH_INTERFACE (5 << 3)
78 
79 /// Zwave Interface
80 #define SL_NET_ZWAVE_INTERFACE (6 << 3)
81 
82 /** \addtogroup SL_NET_CONSTANTS Constants
83  * @{ */
84 /**
85  * @enum sl_net_dns_resolution_ip_type_t
86  * @brief Enumeration of DNS resolution IP types.
87  *
88  * @details
89  * This enumeration defines the types of IP addresses that can be resolved by DNS. It includes both IPv4 and IPv6 address types.
90  */
91 typedef enum {
92   SL_NET_DNS_TYPE_IPV4, ///< IPV4 DNS Address resolution.
93   SL_NET_DNS_TYPE_IPV6  ///< IPV6 DNS Address resolution.
94 } sl_net_dns_resolution_ip_type_t;
95 
96 /**
97  * @enum sl_net_event_t
98  * @brief Enumeration of SL-Net Events.
99  *
100  * @details
101  * This enumeration defines the various network events that can be handled by the system. Each event type corresponds to a specific network-related occurrence.
102  */
103 typedef enum {
104   SL_NET_PING_RESPONSE_EVENT,     ///< Event triggered when a ping response is received.
105   SL_NET_DNS_RESOLVE_EVENT,       ///< Event triggered when a DNS address resolution occurs.
106   SL_NET_OTA_FW_UPDATE_EVENT,     ///< Event triggered when an OTA firmware update is completed.
107   SL_NET_DHCP_NOTIFICATION_EVENT, ///< Event triggered when a DHCP notification is received.
108   SL_NET_IP_ADDRESS_CHANGE_EVENT, ///< Event triggered when there is a DHCP IP address change.
109   SL_NET_EVENT_COUNT              ///< Represents the maximum count of events. Used internally by the SDK.
110 } sl_net_event_t;
111 
112 /**
113  * @enum sl_net_profile_id_t
114  * @brief Enumeration of SL Network profile IDs.
115  *
116  * @details
117  * This enumeration defines the various profile IDs that can be used in the SL Network. Each profile ID corresponds to a specific network profile.
118  *
119  * @note
120  * Ethernet, Thread, and Z-Wave profiles are defined but not currently supported.
121  */
122 typedef enum {
123   SL_NET_PROFILE_ID_0  = 0,  ///< Profile Id 0
124   SL_NET_PROFILE_ID_1  = 1,  ///< Profile Id 1
125   SL_NET_PROFILE_ID_2  = 2,  ///< Profile Id 2
126   SL_NET_PROFILE_ID_3  = 3,  ///< Profile Id 3
127   SL_NET_PROFILE_ID_4  = 4,  ///< Profile Id 4
128   SL_NET_PROFILE_ID_5  = 5,  ///< Profile Id 5
129   SL_NET_PROFILE_ID_6  = 6,  ///< Profile Id 6
130   SL_NET_PROFILE_ID_7  = 7,  ///< Profile Id 7
131   SL_NET_PROFILE_ID_8  = 8,  ///< Profile Id 8
132   SL_NET_PROFILE_ID_9  = 9,  ///< Profile Id 9
133   SL_NET_PROFILE_ID_10 = 10, ///< Profile Id 10
134 
135   SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID = SL_NET_PROFILE_ID_0, ///< Wi-Fi Client Default Profile.
136   SL_NET_DEFAULT_WIFI_AP_PROFILE_ID     = SL_NET_PROFILE_ID_0, ///< Wi-Fi Access Point Default Profile.
137   SL_NET_DEFAULT_ETHERNET_PROFILE_ID    = SL_NET_PROFILE_ID_0, ///< Ethernet Default Profile (not currently supported).
138   SL_NET_DEFAULT_THREAD_PROFILE_ID      = SL_NET_PROFILE_ID_0, ///< Thread Default Profile  (not currently supported).
139   SL_NET_DEFAULT_ZWAVE_PROFILE_ID       = SL_NET_PROFILE_ID_0, ///< Zwave Default Profile  (not currently supported).
140 } sl_net_profile_id_t;
141 
142 /**
143  * @enum sl_net_credential_type_t
144  * @brief Enumeration of network credential types.
145  *
146  * @details
147  * This enumeration defines the various types of network credentials that can be used for authentication and security purposes.
148  */
149 typedef enum {
150   SL_NET_INVALID_CREDENTIAL_TYPE, ///< Invalid Credential Type.
151   SL_NET_WIFI_PSK,                ///< Wi-Fi PSk Credential.
152   SL_NET_WIFI_PMK,                ///< Wi-Fi PMK Credential.
153   SL_NET_WIFI_WEP,                ///< Wi-Fi WEP Credential.
154   SL_NET_CERTIFICATE,             ///< TLS Client Certificate.
155   SL_NET_PUBLIC_KEY,              ///< TLS Certificate Public key.
156   SL_NET_PRIVATE_KEY,             ///< TLS Certificate Private key.
157   SL_NET_PACK_FILE,               ///< EAP Fast Pack File.
158   SL_NET_SIGNING_CERTIFICATE,     ///< TLS CA Certificate.
159   SL_NET_HTTP_CLIENT_CREDENTIAL,  ///< HTTP Client Credential.
160   SL_NET_EAP_CLIENT_CREDENTIAL,   ///< Wi-Fi EAP Credential.
161   SL_NET_MQTT_CLIENT_CREDENTIAL   ///< MQTT Client Credential.
162 } sl_net_credential_type_t;
163 
164 /**
165  * @typedef sl_net_certificate_id_t
166  * @brief Unique identifier for a certificate in the certificate store.
167  *
168  * @details
169  * This defines a unique identifier for the certificates stored in the certificate store. It is used as a reference and to manage certificates within the system.
170  */
171 typedef uint32_t sl_net_certificate_id_t;
172 
173 /**
174  * @enum sl_net_credential_id_t
175  * @brief Enumeration of network credential identifiers.
176  *
177  * @details
178  * This enumeration defines the various identifiers for network credentials used within the system. Each identifier corresponds to a specific type of credential.
179  *
180  * @note
181  *  - In case of @ref sl_net_credential_type_t of @ref SL_NET_CERTIFICATE, @ref SL_NET_PUBLIC_KEY, @ref SL_NET_PRIVATE_KEY, @ref SL_NET_SIGNING_CERTIFICATE, @ref SL_NET_PACK_FILE, the user can ONLY set @ref SL_NET_WIFI_EAP_CLIENT_CREDENTIAL_ID, @ref SL_NET_WIFI_EAP_SERVER_CREDENTIAL_ID, @ref SL_NET_TLS_CLIENT_CREDENTIAL_START, or @ref SL_NET_TLS_SERVER_CREDENTIAL_START at a time for Si91x devices.
182  */
183 typedef enum {
184   SL_NET_INVALID_CREDENTIAL_ID             = 0, ///< Invalid Credential Id.
185   SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID = 1, ///< Wi-Fi Client Credential Id.
186   ///< @note In case of `Basic Network Configuration Manager`, by default `default_wifi_client_credential` from `sl_net_default_values.h` is used. User can choose to override this by setting the credential using @ref sl_net_set_credential.
187   SL_NET_DEFAULT_WIFI_AP_CREDENTIAL_ID = 2, ///< Wi-Fi Access Point Credential Id.
188   ///< @note In case of `Basic Network Configuration Manager`, by default `default_wifi_ap_credential` from `sl_net_default_values.h` is used. User can choose to override this by setting the credential using @ref sl_net_set_credential.
189   SL_NET_WIFI_EAP_CLIENT_CREDENTIAL_ID = 3,        ///< Wi-Fi EAP Client Credential Id.
190   SL_NET_WIFI_EAP_SERVER_CREDENTIAL_ID = 4,        ///< Wi-Fi EAP Server Credential Id.
191   SL_NET_USER_CREDENTIAL_ID            = 5,        ///< User Credential Id.
192   SL_NET_TLS_CLIENT_CREDENTIAL_START   = (1 << 8), ///< TLS Client Credential Id.
193   SL_NET_TLS_SERVER_CREDENTIAL_START   = (2 << 8), ///< TLS Server Credential Id.
194   SL_NET_MQTT_SERVER_CREDENTIAL_START  = (3 << 8), ///< MQTT Server Credential Id.
195   SL_NET_MQTT_CLIENT_CREDENTIAL_START  = (4 << 8), ///< MQTT Client Credential Id.
196   SL_NET_HTTP_SERVER_CREDENTIAL_START  = (5 << 8), ///< HTTP Server Credential Id.
197   SL_NET_HTTP_CLIENT_CREDENTIAL_START  = (6 << 8), ///< HTTP Client Credential Id.
198 } sl_net_credential_id_t;
199 
200 /**
201  * @def SL_NET_CREDENTIAL_GROUP_MASK
202  * @brief Mask for extracting the credential group from a credential ID.
203  *
204  * @details
205  * This mask is used to extract the group portion of a credential ID. It helps in identifying the group to which a credential belongs.
206  *
207  * The credential group can be one of the value from @ref sl_net_credential_id_t.
208  */
209 #define SL_NET_CREDENTIAL_GROUP_MASK 0xFF00
210 
211 /**
212  * @def SL_NET_TLS_CLIENT_CREDENTIAL_ID(x)
213  * @brief Macro to generate a TLS Client Credential ID.
214  *
215  * @details
216  * This macro generates a unique TLS Client Credential ID by adding an offset to the base TLS Client Credential ID.
217  *
218  * x Offset to be added to the base TLS Client Credential ID.
219  *
220  * @note
221  *   - In case of @ref sl_net_credential_type_t of @ref SL_NET_CERTIFICATE, @ref SL_NET_PUBLIC_KEY, @ref SL_NET_PRIVATE_KEY, @ref SL_NET_SIGNING_CERTIFICATE, @ref SL_NET_PACK_FILE, the valid values for x are 0 to 2 for Si91x devices.
222  *   - In case of other types in @ref sl_net_credential_type_t, the valid values for x is only 0.
223  */
224 #define SL_NET_TLS_CLIENT_CREDENTIAL_ID(x) (SL_NET_TLS_CLIENT_CREDENTIAL_START + x)
225 
226 /**
227  * @def SL_NET_TLS_SERVER_CREDENTIAL_ID(x)
228  * @brief Macro to generate a TLS Server Credential ID.
229  *
230  * @details
231  * This macro generates a unique TLS Server Credential ID by adding an offset to the base TLS Server Credential ID.
232  *
233  * x Offset to be added to the base TLS Server Credential ID.
234  *
235  * @note
236  *   - In case of @ref sl_net_credential_type_t of @ref SL_NET_CERTIFICATE, @ref SL_NET_PUBLIC_KEY, @ref SL_NET_PRIVATE_KEY, @ref SL_NET_SIGNING_CERTIFICATE, @ref SL_NET_PACK_FILE, the valid values for x are 0 to 2 for Si91x devices.
237  *   - In case of other types in @ref sl_net_credential_type_t, the valid values for x is only 0.
238  */
239 #define SL_NET_TLS_SERVER_CREDENTIAL_ID(x) (SL_NET_TLS_SERVER_CREDENTIAL_START + x)
240 
241 /**
242  * @def SL_NET_MQTT_SERVER_CREDENTIAL_ID(x)
243  * @brief Macro to generate an MQTT Server Credential ID.
244  *
245  * @details
246  * This macro generates a unique MQTT Server Credential ID by adding an offset to the base MQTT Server Credential ID.
247  *
248  * x Offset to be added to the base MQTT Server Credential ID.
249  *
250  * @note
251  * The valid values for x is only 0.
252  */
253 #define SL_NET_MQTT_SERVER_CREDENTIAL_ID(x) (SL_NET_MQTT_SERVER_CREDENTIAL_START + x)
254 
255 /**
256  * @def SL_NET_MQTT_CLIENT_CREDENTIAL_ID(x)
257  * @brief Macro to generate an MQTT Client Credential ID.
258  *
259  * @details
260  * This macro generates a unique MQTT Client Credential ID by adding an offset to the base MQTT Client Credential ID.
261  *
262  * x Offset to be added to the base MQTT Client Credential ID.
263  *
264  * @note
265  * The valid values for x is only 0.
266  */
267 #define SL_NET_MQTT_CLIENT_CREDENTIAL_ID(x) (SL_NET_MQTT_CLIENT_CREDENTIAL_START + x)
268 
269 /**
270  * @def SL_NET_HTTP_SERVER_CREDENTIAL_ID(x)
271  * @brief Macro to generate an HTTP Server Credential ID.
272  *
273  * @details
274  * This macro generates a unique HTTP Server Credential ID by adding an offset to the base HTTP Server Credential ID.
275  *
276  * x Offset to be added to the base HTTP Server Credential ID.
277  *
278  * @note
279  * The valid values for x is only 0.
280  */
281 #define SL_NET_HTTP_SERVER_CREDENTIAL_ID(x) (SL_NET_HTTP_SERVER_CREDENTIAL_START + x)
282 
283 /**
284  * @def SL_NET_HTTP_CLIENT_CREDENTIAL_ID(x)
285  * @brief Macro to generate an HTTP Client Credential ID.
286  *
287  * @details
288  * This macro generates a unique HTTP Client Credential ID by adding an offset to the base HTTP Client Credential ID.
289  *
290  * x Offset to be added to the base HTTP Client Credential ID.
291  *
292  * @note
293  * The valid values for x is only 0.
294  */
295 #define SL_NET_HTTP_CLIENT_CREDENTIAL_ID(x) (SL_NET_HTTP_CLIENT_CREDENTIAL_START + x)
296 /** @} */
297