1 /***************************************************************************/ /**
2  * @file  sl_net_basic_profiles.c
3  *******************************************************************************
4  * # License
5  * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
6  *******************************************************************************
7  *
8  * SPDX-License-Identifier: Zlib
9  *
10  * The licensor of this software is Silicon Laboratories Inc.
11  *
12  * This software is provided 'as-is', without any express or implied
13  * warranty. In no event will the authors be held liable for any damages
14  * arising from the use of this software.
15  *
16  * Permission is granted to anyone to use this software for any purpose,
17  * including commercial applications, and to alter it and redistribute it
18  * freely, subject to the following restrictions:
19  *
20  * 1. The origin of this software must not be misrepresented; you must not
21  *    claim that you wrote the original software. If you use this software
22  *    in a product, an acknowledgment in the product documentation would be
23  *    appreciated but is not required.
24  * 2. Altered source versions must be plainly marked as such, and must not be
25  *    misrepresented as being the original software.
26  * 3. This notice may not be removed or altered from any source distribution.
27  *
28  ******************************************************************************/
29 
30 #include "sl_net.h"
31 #include "sl_net_ip_types.h"
32 #include "sl_net_wifi_types.h"
33 #include "sl_net_default_values.h"
34 #include <string.h>
35 
36 #define MAX_WIFI_CLIENT_PROFILES 2
37 #define MAX_WIFI_AP_PROFILES     2
38 
39 static sl_net_wifi_client_profile_t wifi_client_profiles[MAX_WIFI_CLIENT_PROFILES] = { 0 };
40 static sl_net_wifi_ap_profile_t wifi_ap_profiles[MAX_WIFI_AP_PROFILES]             = { 0 };
41 
sl_net_set_profile(sl_net_interface_t interface,sl_net_profile_id_t profile_id,const sl_net_profile_t * profile)42 sl_status_t sl_net_set_profile(sl_net_interface_t interface,
43                                sl_net_profile_id_t profile_id,
44                                const sl_net_profile_t *profile)
45 {
46 
47   switch (interface) {
48 #ifdef SL_WIFI_COMPONENT_INCLUDED
49     case SL_NET_WIFI_CLIENT_INTERFACE:
50       if (profile_id >= MAX_WIFI_CLIENT_PROFILES) {
51         return SL_STATUS_INVALID_INDEX;
52       }
53       memcpy(&wifi_client_profiles[profile_id],
54              (const sl_net_wifi_client_profile_t *)profile,
55              sizeof(sl_net_wifi_client_profile_t));
56       return SL_STATUS_OK;
57 
58     case SL_NET_WIFI_AP_INTERFACE:
59       if (profile_id >= MAX_WIFI_AP_PROFILES) {
60         return SL_STATUS_INVALID_INDEX;
61       }
62       memcpy(&wifi_ap_profiles[profile_id],
63              (const sl_net_wifi_ap_profile_t *)profile,
64              sizeof(sl_net_wifi_ap_profile_t));
65       return SL_STATUS_OK;
66 #endif
67     default:
68       return SL_STATUS_NOT_SUPPORTED;
69   }
70 }
71 
sl_net_get_profile(sl_net_interface_t interface,sl_net_profile_id_t profile_id,sl_net_profile_t * profile)72 sl_status_t sl_net_get_profile(sl_net_interface_t interface, sl_net_profile_id_t profile_id, sl_net_profile_t *profile)
73 {
74 
75   SL_WIFI_ARGS_CHECK_NULL_POINTER(profile);
76 
77   switch (interface) {
78 #ifdef SL_WIFI_COMPONENT_INCLUDED
79     case SL_NET_WIFI_CLIENT_INTERFACE:
80       if (profile_id >= MAX_WIFI_CLIENT_PROFILES) {
81         return SL_STATUS_INVALID_INDEX;
82       }
83       memcpy(profile, &wifi_client_profiles[profile_id], sizeof(sl_net_wifi_client_profile_t));
84       return SL_STATUS_OK;
85 
86     case SL_NET_WIFI_AP_INTERFACE:
87       if (profile_id >= MAX_WIFI_AP_PROFILES) {
88         return SL_STATUS_INVALID_INDEX;
89       }
90       memcpy(profile, &wifi_ap_profiles[profile_id], sizeof(sl_net_wifi_ap_profile_t));
91       return SL_STATUS_OK;
92 #endif
93 
94     default:
95       return SL_STATUS_NOT_SUPPORTED;
96   }
97 }
98 
sl_net_delete_profile(sl_net_interface_t interface,sl_net_profile_id_t profile_id)99 sl_status_t sl_net_delete_profile(sl_net_interface_t interface, sl_net_profile_id_t profile_id)
100 {
101 
102   switch (interface) {
103 #ifdef SL_WIFI_COMPONENT_INCLUDED
104     case SL_NET_WIFI_CLIENT_INTERFACE:
105       if (profile_id >= MAX_WIFI_CLIENT_PROFILES) {
106         return SL_STATUS_INVALID_INDEX;
107       }
108       memset(&wifi_client_profiles[profile_id], 0, sizeof(sl_net_wifi_client_profile_t));
109       return SL_STATUS_OK;
110 
111     case SL_NET_WIFI_AP_INTERFACE:
112       if (profile_id >= MAX_WIFI_AP_PROFILES) {
113         return SL_STATUS_INVALID_INDEX;
114       }
115       memset(&wifi_ap_profiles[profile_id], 0, sizeof(sl_net_wifi_ap_profile_t));
116       return SL_STATUS_OK;
117 #endif
118 
119     default:
120       return SL_STATUS_NOT_SUPPORTED;
121   }
122 }
123