Add device control 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
77         if (!g_wifi_funcs->sta_start)
78                 return -ENOTSUP;
79
80         return g_wifi_funcs->sta_start(ifname);
81 }
82
83 EXPORT
84 int hal_wifi_p2p_start(const char *ifname)
85 {
86         if (!g_wifi_funcs)
87                 return -ENOTSUP;
88
89         if (!g_wifi_funcs->p2p_start)
90                 return -ENOTSUP;
91
92         return g_wifi_funcs->p2p_start(ifname);
93 }
94
95 EXPORT
96 int hal_wifi_softap_start(const char *ifname)
97 {
98         if (!g_wifi_funcs)
99                 return -ENOTSUP;
100
101         if (!g_wifi_funcs->softap_start)
102                 return -ENOTSUP;
103
104         return g_wifi_funcs->softap_start(ifname);
105 }
106
107 EXPORT
108 int hal_wifi_stop(const char *ifname)
109 {
110         if (!g_wifi_funcs)
111                 return -ENOTSUP;
112
113         if (!g_wifi_funcs->stop)
114                 return -ENOTSUP;
115
116         return g_wifi_funcs->stop(ifname);
117 }
118
119 EXPORT
120 int hal_wifi_get_mac(const char *ifname, char **mac)
121 {
122         if (!g_wifi_funcs)
123                 return -ENOTSUP;
124
125         if (!g_wifi_funcs->get_mac)
126                 return -ENOTSUP;
127
128         return g_wifi_funcs->get_mac(ifname, mac);
129 }
130
131 EXPORT
132 int hal_wifi_device_control(const char *command, int argc, char *argv[])
133 {
134         if (!g_wifi_funcs)
135                 return -ENOTSUP;
136
137         if (!g_wifi_funcs->device_control)
138                 return -ENOTSUP;
139
140         return g_wifi_funcs->device_control(command, argc, argv);
141 }