2 * Network Configuration Module
4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file implements wifi direct manager interface functions.
23 * @file wifi-direct-iface.c
24 * @author Nishant Chaprana (n.chaprana@samsung.com)
31 #include <wifi-direct.h>
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"
46 #include "wifi-direct-service.h"
47 #include "wifi-direct-asp.h"
59 typedef void (*method_handler)(GVariant *parameters, void *dest);
62 const char *method_str;
63 method_handler handler;
64 } wfd_manager_iface_method_handler;
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},
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},
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},
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},
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},
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},
180 static GHashTable *wfd_manager_iface_tbl[WFD_IFACE_MAX];
182 static int set_iface_hash(wfd_manager_iface_method_handler handler[], int idx)
184 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
185 GHashTable *new_hash_tbl;
190 new_hash_tbl = g_hash_table_new(g_str_hash, g_str_equal);
192 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
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);
203 wfd_manager_iface_tbl[idx] = new_hash_tbl;
205 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
209 int wfd_manager_iface_init()
211 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
212 /*test manage iface */
216 for (cnt = 0; cnt < WFD_IFACE_MAX; cnt++)
217 wfd_manager_iface_tbl[cnt] = NULL;
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
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
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
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
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
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
256 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
260 void wfd_manager_iface_deinit()
262 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
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;
269 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
273 void wfd_manager_iface_manage_handler(const char *method,
274 GVariant *parameters,
275 GDBusMethodInvocation *invocation)
277 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
278 method_handler handler;
280 handler = (method_handler)g_hash_table_lookup
281 (wfd_manager_iface_tbl[WFD_IFACE_MANAGE], method);
284 handler(parameters, invocation);
288 void wfd_manager_iface_group_handler(const char *method,
289 GVariant *parameters,
290 GDBusMethodInvocation *invocation)
292 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
293 method_handler handler;
295 handler = (method_handler)g_hash_table_lookup
296 (wfd_manager_iface_tbl[WFD_IFACE_GROUP], method);
299 handler(parameters, invocation);
300 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
304 void wfd_manager_iface_config_handler(const char *method,
305 GVariant *parameters,
306 GDBusMethodInvocation *invocation)
308 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
309 method_handler handler;
311 handler = (method_handler)g_hash_table_lookup
312 (wfd_manager_iface_tbl[WFD_IFACE_CONFIG], method);
314 handler(parameters, invocation);
315 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
319 void wfd_manager_iface_service_handler(const char *method,
320 GVariant *parameters,
321 GDBusMethodInvocation *invocation)
323 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
324 method_handler handler;
326 handler = (method_handler)g_hash_table_lookup
327 (wfd_manager_iface_tbl[WFD_IFACE_SERVICE], method);
329 handler(parameters, invocation);
330 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
334 void wfd_manager_iface_display_handler(const char *method,
335 GVariant *parameters,
336 GDBusMethodInvocation *invocation)
338 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
339 method_handler handler;
341 handler = (method_handler)g_hash_table_lookup
342 (wfd_manager_iface_tbl[WFD_IFACE_DISPLAY], method);
344 handler(parameters, invocation);
345 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
349 void wfd_manager_iface_asp_handler(const char *method,
350 GVariant *parameters,
351 GDBusMethodInvocation *invocation)
353 __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
354 method_handler handler;
356 handler = (method_handler)g_hash_table_lookup
357 (wfd_manager_iface_tbl[WFD_IFACE_ASP], method);
359 handler(parameters, invocation);
360 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE