Fix static analyzer issue
[platform/core/connectivity/wifi-direct-manager.git] / src / wifi-direct-iface.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /**
21  * This file implements wifi direct manager interface functions.
22  *
23  * @file        wifi-direct-iface.c
24  * @author      Nishant Chaprana (n.chaprana@samsung.com)
25  * @version     0.1
26  */
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include <wifi-direct.h>
32
33 #include "wifi-direct-dbus.h"
34 #include "wifi-direct-iface.h"
35 #include "wifi-direct-method.h"
36 #include "wifi-direct-ipc.h"
37 #include "wifi-direct-error.h"
38 #include "wifi-direct-log.h"
39 #include "wifi-direct-manager.h"
40 #include "wifi-direct-oem.h"
41 #include "wifi-direct-session.h"
42 #include "wifi-direct-util.h"
43 #include "wifi-direct-group.h"
44 #include "wifi-direct-state.h"
45 #include <vconf.h>
46 #include "wifi-direct-service.h"
47 #include "wifi-direct-asp.h"
48
49 typedef enum {
50         WFD_IFACE_MANAGE,
51         WFD_IFACE_GROUP,
52         WFD_IFACE_CONFIG,
53         WFD_IFACE_SERVICE,
54         WFD_IFACE_DISPLAY,
55         WFD_IFACE_ASP,
56         WFD_IFACE_MAX,
57 } iface_type_e;
58
59 typedef void (*method_handler)(GVariant *parameters, void *dest);
60
61 typedef struct {
62                 const char *method_str;
63                 method_handler handler;
64 } wfd_manager_iface_method_handler;
65
66 static wfd_manager_iface_method_handler wfd_manager_iface_manage[] = {
67                 {"Activate", activate_handler},
68                 {"AddClient", add_client_handler},
69                 {"Deactivate", deactivate_handler},
70                 {"StartDiscovery", start_discovery_handler},
71                 {"StopDiscovery", stop_discovery_handler},
72                 {"GetDiscoveredPeers", get_discovered_peer_handler},
73                 {"Connect", connect_handler},
74                 {"Disconnect", disconnect_handler},
75                 {"CancelConnection", cancel_connection_handler},
76                 {"AcceptConnection", accept_connection_handler},
77                 {"RejectConnection", reject_connection_handler},
78                 {"DisconnectAll", disconnect_all_handler},
79                 {"GetConnectedPeers", get_connected_peers_handler},
80                 {"GetConnectingPeer", get_connecting_peer_handler},
81                 {"IsDiscoverable", is_discoverable_handler},
82                 {"IsListeningOnly", is_listening_only_handler},
83                 {"GetPeerInfo", get_peer_info_handler},
84                 {"GetPeerVsie", get_peer_vsie_handler},
85                 {"GetState", get_state_handler},
86                 {NULL, NULL},
87 };
88
89 static wfd_manager_iface_method_handler wfd_manager_iface_group[] = {
90                 {"CreateGroup", create_group_handler},
91                 {"DestroyGroup", destroy_group_handler},
92                 {"IsGroupOwner", is_group_owner_handler},
93                 {"IsAutoGroup", is_auto_group_handler},
94                 {"ActivatePushButton", activate_pushbutton_handler},
95                 {"GetPersistentGroups", get_persistent_group_handler},
96                 {"RemovePersistentGroup", remove_persistent_group_handler},
97                 {"SetPassphrase", set_passphrase_handler},
98                 {"GetPassphrase", get_passphrase_handler},
99                 {"SetPersistentGroupEnabled", set_persistent_group_handler},
100                 {"IsPersistentGroupEnabled", is_persistent_group_enabled_handler},
101                 {"RemovePersistentDevice", remove_persistent_device_handler},
102                 {"RemoveAllPersistentDevice", remove_all_persistent_device_handler},
103                 {NULL, NULL},
104 };
105
106 static wfd_manager_iface_method_handler wfd_manager_iface_config[] = {
107                 {"GetDeviceName", get_device_name_handler},
108                 {"SetDeviceName", set_device_name_handler},
109                 {"SetWpsPin", set_wps_pin_handler},
110                 {"GetWpsPin", get_wps_pin_handler},
111                 {"GenerateWpsPin", generate_wps_pin_handler},
112                 {"GetSupportedWpsMode", get_supported_wps_mode_handler},
113                 {"GetReqWpsMode", get_req_wps_mode_handler},
114                 {"SetReqWpsMode", set_req_wps_mode_handler},
115                 {"GetLocalWpsMode", get_local_wps_mode_handler},
116                 {"GetIPAddress", get_ip_address_handler},
117                 {"GetMacAddress", get_mac_address_handler},
118                 {"GetGoIntent", get_go_intent_handler},
119                 {"SetGoIntent", set_go_intent_handler},
120                 {"SetGoIntentPerType", set_go_intent_per_type_handler},
121                 {"GetGoIntentPerType", get_go_intent_per_type_handler},
122                 {"GetMaxClient", get_max_client_handler},
123                 {"SetMaxClient", set_max_client_handler},
124                 {"SetAutoConnectionMode", set_autoconnection_mode_handler},
125                 {"IsAutoConnectionMode", is_autoconnection_mode_handler},
126                 {"GetOperatingChannel", get_operating_channel_handler},
127                 {"GetSupportedChannels", get_supported_channels_handler},
128                 {"SetAutoConnectionPeer", set_autoconnection_peer_handler},
129                 {"GetConnectingPeer", get_connecting_peer_handler},
130                 {"GetInterfaceName", get_interface_name_handler},
131                 {"GetSubnetMask", get_subnet_mask_handler},
132                 {"GetGateway", get_gateway_handler},
133                 {"GetSessionTimer", get_session_timer_handler},
134                 {"SetSessionTimer", set_session_timer_handler},
135                 {"SetAutoGroupRemoval", get_auto_group_removal_handler},
136                 {"GetPrimaryDevType", get_primary_dev_type_handler},
137                 {"GetSecondaryDevType", get_secondary_dev_type_handler},
138                 {"GetPeerRssi", get_peer_rssi_handler},
139                 {"AddVsie", add_vsie_handler},
140                 {"GetVsie", get_vsie_handler},
141                 {"RemoveVsie", remove_vsie_handler},
142                 {"GetWpsConfigMethod", get_wps_config_method_handler},
143                 {"SetWpsConfigMethod", set_wps_config_method_handler},
144                 {NULL, NULL},
145 };
146
147 static wfd_manager_iface_method_handler wfd_manager_iface_service[] = {
148                 {"StartDiscovery", srv_start_discovery_handler},
149                 {"StopDiscovery", srv_stop_discovery_handler},
150                 {"Register", srv_register_handler},
151                 {"Deregister", srv_deregister_handler},
152                 {NULL, NULL},
153 };
154
155 static wfd_manager_iface_method_handler wfd_manager_iface_display[] = {
156                 {"Init", display_init_handler},
157                 {"Deinit", display_deinit_handler},
158                 {"SetConfig", display_set_config_handler},
159                 {"SetAvailiability", display_set_avail_handler},
160                 {"GetConfig", display_get_config_handler},
161                 {"GetAvailiability", display_get_avail_handler},
162                 {"GetPeerType", display_get_peer_type_handler},
163                 {"GetPeerAvailability", display_get_peer_avail_handler},
164                 {"GetPeerHdcp",  display_get_peer_hdcp_handler},
165                 {"GetPeerPort",  display_get_peer_port_handler},
166                 {"GetPeerThroughput",  display_get_peer_throughput_handler},
167                 {NULL, NULL},
168 };
169
170 static wfd_manager_iface_method_handler wfd_manager_iface_asp[] = {
171                 {"AdvertiseService", advertise_service_handler},
172                 {"CancelAdvertiseService", cancel_advertise_service_handler},
173                 {"SeekService", seek_service_handler},
174                 {"CancelSeekService", cancel_seek_service_handler},
175                 {"ConnectSession", connect_sessoin_handler},
176                 {"ConfirmSession", confirm_sessoin_handler},
177                 {NULL, NULL},
178 };
179
180 static GHashTable *wfd_manager_iface_tbl[WFD_IFACE_MAX];
181
182 static int set_iface_hash(wfd_manager_iface_method_handler handler[], int idx)
183 {
184         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
185         GHashTable *new_hash_tbl;
186         int cnt;
187         int ret = -1;
188
189         new_hash_tbl = NULL;
190         new_hash_tbl =  g_hash_table_new(g_str_hash, g_str_equal);
191         if (!new_hash_tbl) {
192                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
193                 return ret;
194         }
195
196         cnt = 0;
197         while (handler[cnt].method_str != NULL) {
198                 g_hash_table_insert(new_hash_tbl,
199                                 (gpointer)handler[cnt].method_str,
200                                 (gpointer)handler[cnt].handler);
201                 cnt++;
202         }
203         wfd_manager_iface_tbl[idx] = new_hash_tbl;
204
205         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
206         return 0;
207 }
208
209 int wfd_manager_iface_init()
210 {
211         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
212         /*test manage iface */
213         int ret = -1;
214         int cnt;
215
216         for (cnt = 0; cnt < WFD_IFACE_MAX; cnt++)
217                 wfd_manager_iface_tbl[cnt] = NULL;
218
219
220         if (set_iface_hash(wfd_manager_iface_manage, WFD_IFACE_MANAGE) != 0) {
221                 wfd_manager_iface_deinit();
222                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
223                 return ret;
224         }
225
226         if (set_iface_hash(wfd_manager_iface_group, WFD_IFACE_GROUP) != 0) {
227                 wfd_manager_iface_deinit();
228                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
229                 return ret;
230         }
231
232         if (set_iface_hash(wfd_manager_iface_config, WFD_IFACE_CONFIG) != 0) {
233                 wfd_manager_iface_deinit();
234                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
235                 return ret;
236         }
237
238         if (set_iface_hash(wfd_manager_iface_service, WFD_IFACE_SERVICE) != 0) {
239                 wfd_manager_iface_deinit();
240                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
241                 return ret;
242         }
243
244         if (set_iface_hash(wfd_manager_iface_display, WFD_IFACE_DISPLAY) != 0) {
245                 wfd_manager_iface_deinit();
246                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
247                 return ret;
248         }
249
250         if (set_iface_hash(wfd_manager_iface_asp, WFD_IFACE_ASP) != 0) {
251                 wfd_manager_iface_deinit();
252                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
253                 return ret;
254         }
255
256         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
257         return 0;
258 }
259
260 void wfd_manager_iface_deinit()
261 {
262         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
263         int cnt;
264         for (cnt = 0; cnt < WFD_IFACE_MAX; cnt++) {
265                 if (wfd_manager_iface_tbl[cnt])
266                         g_hash_table_destroy(wfd_manager_iface_tbl[cnt]);
267                 wfd_manager_iface_tbl[cnt] = NULL;
268         }
269         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
270         return;
271 }
272 //LCOV_EXCL_START
273 void wfd_manager_iface_manage_handler(const char *method,
274                 GVariant *parameters,
275                 GDBusMethodInvocation *invocation)
276 {
277         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
278         method_handler handler;
279
280         handler = (method_handler)g_hash_table_lookup
281                         (wfd_manager_iface_tbl[WFD_IFACE_MANAGE], method);
282
283         if (handler)
284                 handler(parameters, invocation);
285         return;
286 }
287
288 void wfd_manager_iface_group_handler(const char *method,
289                 GVariant *parameters,
290                 GDBusMethodInvocation *invocation)
291 {
292         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
293         method_handler handler;
294
295         handler = (method_handler)g_hash_table_lookup
296                         (wfd_manager_iface_tbl[WFD_IFACE_GROUP], method);
297
298         if (handler)
299                 handler(parameters, invocation);
300         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
301         return;
302 }
303
304 void wfd_manager_iface_config_handler(const char *method,
305                 GVariant *parameters,
306                 GDBusMethodInvocation *invocation)
307 {
308         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
309         method_handler handler;
310
311         handler = (method_handler)g_hash_table_lookup
312                         (wfd_manager_iface_tbl[WFD_IFACE_CONFIG], method);
313         if (handler)
314                 handler(parameters, invocation);
315         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
316         return;
317 }
318
319 void wfd_manager_iface_service_handler(const char *method,
320                 GVariant *parameters,
321                 GDBusMethodInvocation *invocation)
322 {
323         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
324         method_handler handler;
325
326         handler = (method_handler)g_hash_table_lookup
327                         (wfd_manager_iface_tbl[WFD_IFACE_SERVICE], method);
328         if (handler)
329                 handler(parameters, invocation);
330         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
331         return;
332 }
333
334 void wfd_manager_iface_display_handler(const char *method,
335                 GVariant *parameters,
336                 GDBusMethodInvocation *invocation)
337 {
338         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
339         method_handler handler;
340
341         handler = (method_handler)g_hash_table_lookup
342                         (wfd_manager_iface_tbl[WFD_IFACE_DISPLAY], method);
343         if (handler)
344                 handler(parameters, invocation);
345         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
346         return;
347 }
348
349 void wfd_manager_iface_asp_handler(const char *method,
350                 GVariant *parameters,
351                 GDBusMethodInvocation *invocation)
352 {
353         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
354         method_handler handler;
355
356         handler = (method_handler)g_hash_table_lookup
357                         (wfd_manager_iface_tbl[WFD_IFACE_ASP], method);
358         if (handler)
359                 handler(parameters, invocation);
360         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
361         return;
362 }
363 //LCOV_EXCL_STOP