Add mac address and interface name support
[platform/hal/api/wifi.git] / src / hal-api-wifi.c
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdint.h>
19 #include <dlfcn.h>
20 #include <dlog.h>
21
22 #include <hal/hal-common.h>
23
24 #include "../include/hal-wifi.h"
25 #include "../include/hal-wifi-interface.h"
26 #include "common.h"
27
28 #ifndef EXPORT
29 #define EXPORT __attribute__ ((visibility("default")))
30 #endif
31
32 #define ARRAY_SIZE(name)        (sizeof(name)/sizeof(name[0]))
33
34 static hal_backend_wifi_funcs *g_wifi_funcs = NULL;
35
36 EXPORT
37 int hal_wifi_get_backend(void)
38 {
39         int ret;
40
41         if (g_wifi_funcs)
42                 return 0;
43
44         ret = hal_common_get_backend(HAL_MODULE_WIFI, (void **)&g_wifi_funcs);
45         if (ret < 0) {
46                 _E("Failed to get backend\n");
47                 return -EINVAL;
48         }
49
50         return 0;
51 }
52
53 EXPORT
54 int hal_wifi_put_backend(void)
55 {
56         int ret;
57
58         if (!g_wifi_funcs)
59                 return -EINVAL;
60
61         ret = hal_common_put_backend(HAL_MODULE_WIFI, (void *)g_wifi_funcs);
62         if (ret < 0) {
63                 _E("Failed to put backend\n");
64                 return -EINVAL;
65         }
66         g_wifi_funcs = NULL;
67
68         return 0;
69 }
70
71 EXPORT
72 int hal_wifi_sta_start(const char *ifname)
73 {
74         if (!g_wifi_funcs)
75                 return -ENOTSUP;
76         return g_wifi_funcs->sta_start(ifname);
77 }
78
79 EXPORT
80 int hal_wifi_p2p_start(const char *ifname)
81 {
82         if (!g_wifi_funcs)
83                 return -ENOTSUP;
84         return g_wifi_funcs->p2p_start(ifname);
85 }
86
87 EXPORT
88 int hal_wifi_softap_start(const char *ifname)
89 {
90         if (!g_wifi_funcs)
91                 return -ENOTSUP;
92         return g_wifi_funcs->softap_start(ifname);
93 }
94
95 EXPORT
96 int hal_wifi_stop(const char *ifname)
97 {
98         if (!g_wifi_funcs)
99                 return -ENOTSUP;
100         return g_wifi_funcs->stop(ifname);
101 }
102
103 EXPORT
104 int hal_wifi_get_mac(const char *ifname, char **mac)
105 {
106         if (!g_wifi_funcs)
107                 return -ENOTSUP;
108         return g_wifi_funcs->get_mac(ifname, mac);
109 }