1 #include "e_connman_private.h"
5 static E_DBus_Signal_Handler *cb_name_owner_changed = NULL;
6 static DBusPendingCall *pending_get_name_owner = NULL;
7 static unsigned int init_count = 0;
8 static char *unique_name = NULL;
10 static const char bus_name[] = "net.connman";
12 E_DBus_Connection *e_connman_conn = NULL;
14 EAPI int E_CONNMAN_EVENT_MANAGER_IN = 0;
15 EAPI int E_CONNMAN_EVENT_MANAGER_OUT = 0;
16 EAPI int E_CONNMAN_EVENT_ELEMENT_ADD = 0;
17 EAPI int E_CONNMAN_EVENT_ELEMENT_DEL = 0;
18 EAPI int E_CONNMAN_EVENT_ELEMENT_UPDATED = 0;
20 const char *e_connman_iface_manager = NULL;
21 const char *e_connman_iface_profile = NULL;
22 const char *e_connman_iface_service = NULL;
23 const char *e_connman_iface_connection = NULL;
24 const char *e_connman_iface_technology = NULL;
26 const char *e_connman_prop_available = NULL;
27 const char *e_connman_prop_connections = NULL;
28 const char *e_connman_prop_default = NULL;
29 const char *e_connman_prop_ipv4 = NULL;
30 const char *e_connman_prop_ipv4_configuration = NULL;
31 const char *e_connman_prop_ethernet = NULL;
32 const char *e_connman_prop_interface = NULL;
33 const char *e_connman_prop_speed = NULL;
34 const char *e_connman_prop_duplex = NULL;
35 const char *e_connman_prop_method = NULL;
36 const char *e_connman_prop_address = NULL;
37 const char *e_connman_prop_gateway = NULL;
38 const char *e_connman_prop_netmask = NULL;
39 const char *e_connman_prop_mtu = NULL;
40 const char *e_connman_prop_name = NULL;
41 const char *e_connman_prop_offline_mode = NULL;
42 const char *e_connman_prop_policy = NULL;
43 const char *e_connman_prop_priority = NULL;
44 const char *e_connman_prop_profiles = NULL;
45 const char *e_connman_prop_profile_active = NULL;
46 const char *e_connman_prop_services = NULL;
47 const char *e_connman_prop_technologies = NULL;
48 const char *e_connman_prop_remember = NULL;
49 const char *e_connman_prop_state = NULL;
50 const char *e_connman_prop_strength = NULL;
51 const char *e_connman_prop_type = NULL;
52 const char *e_connman_prop_error = NULL;
53 const char *e_connman_prop_security = NULL;
54 const char *e_connman_prop_passphrase = NULL;
55 const char *e_connman_prop_passphrase_required = NULL;
56 const char *e_connman_prop_login_required = NULL;
57 const char *e_connman_prop_favorite = NULL;
58 const char *e_connman_prop_immutable = NULL;
59 const char *e_connman_prop_auto_connect = NULL;
60 const char *e_connman_prop_roaming = NULL;
61 const char *e_connman_prop_technology_default = NULL;
62 const char *e_connman_prop_technologies_available = NULL;
63 const char *e_connman_prop_technologies_enabled = NULL;
64 const char *e_connman_prop_technologies_connected = NULL;
65 const char *e_connman_prop_nameservers = NULL;
66 const char *e_connman_prop_nameservers_configuration = NULL;
67 const char *e_connman_prop_domains = NULL;
68 const char *e_connman_prop_domains_configuration = NULL;
69 const char *e_connman_prop_proxy = NULL;
70 const char *e_connman_prop_proxy_configuration = NULL;
71 const char *e_connman_prop_url = NULL;
72 const char *e_connman_prop_servers = NULL;
73 const char *e_connman_prop_excludes = NULL;
75 int _e_dbus_connman_log_dom = -1;
78 e_connman_system_bus_name_get(void)
80 return unique_name ? unique_name : bus_name;
83 /***********************************************************************
85 ***********************************************************************/
88 * Synchronize elements with server.
90 * This will call Manager.GetProperties() on server, retrieve properties
91 * and some element paths and then request their properties.
93 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
94 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
96 * This will not remove stale elements.
98 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
101 e_connman_manager_sync_elements(void)
103 E_Connman_Element *manager;
108 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
110 e_connman_element_properties_sync(manager);
114 DBG("sync_manager: %s (%s)", unique_name, bus_name);
120 _e_connman_system_name_owner_exit(void)
122 e_connman_manager_clear_elements();
123 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
130 _e_connman_system_name_owner_enter(const char *uid)
132 DBG("enter connman at %s (old was %s)", uid, unique_name);
133 if (unique_name && strcmp(unique_name, uid) == 0)
135 DBG("same unique_name for connman, ignore.");
140 _e_connman_system_name_owner_exit();
142 unique_name = strdup(uid);
144 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
145 e_connman_manager_sync_elements();
149 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
152 const char *name, *from, *to;
154 dbus_error_init(&err);
155 if (!dbus_message_get_args(msg, &err,
156 DBUS_TYPE_STRING, &name,
157 DBUS_TYPE_STRING, &from,
158 DBUS_TYPE_STRING, &to,
161 ERR("could not get NameOwnerChanged arguments: %s: %s",
162 err.name, err.message);
163 dbus_error_free(&err);
167 if (strcmp(name, bus_name) != 0)
170 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
172 if (from[0] == '\0' && to[0] != '\0')
174 _e_connman_system_name_owner_enter(to);
176 else if (from[0] != '\0' && to[0] == '\0')
178 DBG("exit connman at %s", from);
179 if (strcmp(unique_name, from) != 0)
180 DBG("%s was not the known name %s, ignored.", from, unique_name);
182 _e_connman_system_name_owner_exit();
186 DBG("unknow change from %s to %s", from, to);
191 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
197 pending_get_name_owner = NULL;
199 if (!_dbus_callback_check_and_init(msg, &itr, err))
202 t = dbus_message_iter_get_arg_type(&itr);
203 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
206 dbus_message_iter_get_basic(&itr, &uid);
209 ERR("no name owner!");
213 _e_connman_system_name_owner_enter(uid);
218 * Initialize E Connection Manager (E_Connman) system.
220 * This will connect and watch net.connman.Manager and Element
221 * events and translate to Ecore main loop events, also provide a
222 * proxy for method invocation on server.
224 * Interesting events are:
225 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
226 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
227 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
228 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
229 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
232 * Manager IN/OUT events do not provide any event information, just
233 * tells you that system is usable or not. After manager is out, all
234 * elements will be removed, so after this event do not use the system anymore.
236 * Element events will give you an element object. After DEL event callback
237 * returns, that element will not be valid anymore.
240 e_connman_system_init(E_DBus_Connection *edbus_conn)
247 _e_dbus_connman_log_dom = eina_log_domain_register
248 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
250 if (_e_dbus_connman_log_dom < 0)
253 ("impossible to create a log domain for edbus_connman module");
257 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
258 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
260 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
261 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
263 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
264 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
266 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
267 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
269 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
270 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
272 #define ADD_STRINGSHARE(name, s) \
274 name = eina_stringshare_add(s)
276 ADD_STRINGSHARE(e_connman_iface_manager, "net.connman.Manager");
277 ADD_STRINGSHARE(e_connman_iface_profile, "net.connman.Profile");
278 ADD_STRINGSHARE(e_connman_iface_service, "net.connman.Service");
279 ADD_STRINGSHARE(e_connman_iface_connection, "net.connman.Connection");
280 ADD_STRINGSHARE(e_connman_iface_technology, "net.connman.Technology");
281 ADD_STRINGSHARE(e_connman_prop_available, "Available");
282 ADD_STRINGSHARE(e_connman_prop_connections, "Connections");
283 ADD_STRINGSHARE(e_connman_prop_default, "Default");
284 ADD_STRINGSHARE(e_connman_prop_ipv4, "IPv4");
285 ADD_STRINGSHARE(e_connman_prop_ipv4_configuration, "IPv4.Configuration");
286 ADD_STRINGSHARE(e_connman_prop_ethernet, "Ethernet");
287 ADD_STRINGSHARE(e_connman_prop_interface, "Interface");
288 ADD_STRINGSHARE(e_connman_prop_speed, "Speed");
289 ADD_STRINGSHARE(e_connman_prop_duplex, "Duplex");
290 ADD_STRINGSHARE(e_connman_prop_method, "Method");
291 ADD_STRINGSHARE(e_connman_prop_address, "Address");
292 ADD_STRINGSHARE(e_connman_prop_gateway, "Gateway");
293 ADD_STRINGSHARE(e_connman_prop_netmask, "Netmask");
294 ADD_STRINGSHARE(e_connman_prop_mtu, "MTU");
295 ADD_STRINGSHARE(e_connman_prop_name, "Name");
296 ADD_STRINGSHARE(e_connman_prop_offline_mode, "OfflineMode");
297 ADD_STRINGSHARE(e_connman_prop_policy, "Policy");
298 ADD_STRINGSHARE(e_connman_prop_priority, "Priority");
299 ADD_STRINGSHARE(e_connman_prop_profiles, "Profiles");
300 ADD_STRINGSHARE(e_connman_prop_profile_active, "ActiveProfile");
301 ADD_STRINGSHARE(e_connman_prop_services, "Services");
302 ADD_STRINGSHARE(e_connman_prop_technologies, "Technologies");
303 ADD_STRINGSHARE(e_connman_prop_remember, "Remember");
304 ADD_STRINGSHARE(e_connman_prop_state, "State");
305 ADD_STRINGSHARE(e_connman_prop_strength, "Strength");
306 ADD_STRINGSHARE(e_connman_prop_type, "Type");
307 ADD_STRINGSHARE(e_connman_prop_error, "Error");
308 ADD_STRINGSHARE(e_connman_prop_security, "Security");
309 ADD_STRINGSHARE(e_connman_prop_passphrase, "Passphrase");
310 ADD_STRINGSHARE(e_connman_prop_passphrase_required, "PassphraseRequired");
311 ADD_STRINGSHARE(e_connman_prop_login_required, "LoginRequired");
312 ADD_STRINGSHARE(e_connman_prop_favorite, "Favorite");
313 ADD_STRINGSHARE(e_connman_prop_immutable, "Immutable");
314 ADD_STRINGSHARE(e_connman_prop_auto_connect, "AutoConnect");
315 ADD_STRINGSHARE(e_connman_prop_roaming, "Roaming");
316 ADD_STRINGSHARE(e_connman_prop_technology_default, "DefaultTechnology");
317 ADD_STRINGSHARE(e_connman_prop_technologies_available,
318 "AvailableTechnologies");
319 ADD_STRINGSHARE(e_connman_prop_technologies_enabled, "EnabledTechnologies");
320 ADD_STRINGSHARE(e_connman_prop_technologies_connected,
321 "ConnectedTechnologies");
322 ADD_STRINGSHARE(e_connman_prop_nameservers, "Nameservers");
323 ADD_STRINGSHARE(e_connman_prop_nameservers_configuration,
324 "Nameservers.Configuration");
325 ADD_STRINGSHARE(e_connman_prop_domains, "Domains");
326 ADD_STRINGSHARE(e_connman_prop_domains_configuration,
327 "Domains.Configuration");
328 ADD_STRINGSHARE(e_connman_prop_proxy, "Proxy");
329 ADD_STRINGSHARE(e_connman_prop_proxy_configuration, "Proxy.Configuration");
330 ADD_STRINGSHARE(e_connman_prop_url, "URL");
331 ADD_STRINGSHARE(e_connman_prop_servers, "Servers");
332 ADD_STRINGSHARE(e_connman_prop_excludes, "Excludes");
334 #undef ADD_STRINGSHARE
336 e_connman_conn = edbus_conn;
337 cb_name_owner_changed = e_dbus_signal_handler_add
338 (e_connman_conn, E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, "NameOwnerChanged",
339 _e_connman_system_name_owner_changed, NULL);
341 if (pending_get_name_owner)
342 dbus_pending_call_cancel(pending_get_name_owner);
344 pending_get_name_owner = e_dbus_get_name_owner
345 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
347 e_connman_elements_init();
353 _stringshare_del(const char **str)
358 eina_stringshare_del(*str);
363 * Shutdown connman system.
365 * When count drops to 0 resources will be released and no calls should be
369 e_connman_system_shutdown(void)
373 ERR("connman system already shut down.");
381 _stringshare_del(&e_connman_iface_manager);
382 _stringshare_del(&e_connman_iface_profile);
383 _stringshare_del(&e_connman_iface_service);
384 _stringshare_del(&e_connman_iface_connection);
385 _stringshare_del(&e_connman_iface_technology);
387 _stringshare_del(&e_connman_prop_available);
388 _stringshare_del(&e_connman_prop_connections);
389 _stringshare_del(&e_connman_prop_default);
390 _stringshare_del(&e_connman_prop_ipv4);
391 _stringshare_del(&e_connman_prop_ipv4_configuration);
392 _stringshare_del(&e_connman_prop_ethernet);
393 _stringshare_del(&e_connman_prop_interface);
394 _stringshare_del(&e_connman_prop_speed);
395 _stringshare_del(&e_connman_prop_duplex);
396 _stringshare_del(&e_connman_prop_method);
397 _stringshare_del(&e_connman_prop_address);
398 _stringshare_del(&e_connman_prop_gateway);
399 _stringshare_del(&e_connman_prop_netmask);
400 _stringshare_del(&e_connman_prop_mtu);
401 _stringshare_del(&e_connman_prop_name);
402 _stringshare_del(&e_connman_prop_offline_mode);
403 _stringshare_del(&e_connman_prop_policy);
404 _stringshare_del(&e_connman_prop_priority);
405 _stringshare_del(&e_connman_prop_profiles);
406 _stringshare_del(&e_connman_prop_profile_active);
407 _stringshare_del(&e_connman_prop_services);
408 _stringshare_del(&e_connman_prop_technologies);
409 _stringshare_del(&e_connman_prop_remember);
410 _stringshare_del(&e_connman_prop_state);
411 _stringshare_del(&e_connman_prop_strength);
412 _stringshare_del(&e_connman_prop_type);
413 _stringshare_del(&e_connman_prop_error);
414 _stringshare_del(&e_connman_prop_security);
415 _stringshare_del(&e_connman_prop_passphrase);
416 _stringshare_del(&e_connman_prop_passphrase_required);
417 _stringshare_del(&e_connman_prop_login_required);
418 _stringshare_del(&e_connman_prop_favorite);
419 _stringshare_del(&e_connman_prop_immutable);
420 _stringshare_del(&e_connman_prop_auto_connect);
421 _stringshare_del(&e_connman_prop_roaming);
422 _stringshare_del(&e_connman_prop_technology_default);
423 _stringshare_del(&e_connman_prop_technologies_available);
424 _stringshare_del(&e_connman_prop_technologies_enabled);
425 _stringshare_del(&e_connman_prop_technologies_connected);
426 _stringshare_del(&e_connman_prop_nameservers);
427 _stringshare_del(&e_connman_prop_nameservers_configuration);
428 _stringshare_del(&e_connman_prop_domains);
429 _stringshare_del(&e_connman_prop_domains_configuration);
430 _stringshare_del(&e_connman_prop_proxy);
431 _stringshare_del(&e_connman_prop_proxy_configuration);
432 _stringshare_del(&e_connman_prop_url);
433 _stringshare_del(&e_connman_prop_servers);
434 _stringshare_del(&e_connman_prop_excludes);
436 if (pending_get_name_owner)
438 dbus_pending_call_cancel(pending_get_name_owner);
439 pending_get_name_owner = NULL;
442 if (cb_name_owner_changed)
444 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
445 cb_name_owner_changed = NULL;
449 _e_connman_system_name_owner_exit();
451 e_connman_elements_shutdown();
452 eina_log_domain_unregister(_e_dbus_connman_log_dom);
453 e_connman_conn = NULL;