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 DBusPendingCall *pending_get_name_owner_old = NULL;
8 static unsigned int init_count = 0;
9 static char *unique_name = NULL;
11 static const char bus_name[] = "net.connman";
12 static const char bus_name_old[] = "org.moblin.connman";
14 E_DBus_Connection *e_connman_conn = NULL;
16 EAPI int E_CONNMAN_EVENT_MANAGER_IN = 0;
17 EAPI int E_CONNMAN_EVENT_MANAGER_OUT = 0;
18 EAPI int E_CONNMAN_EVENT_ELEMENT_ADD = 0;
19 EAPI int E_CONNMAN_EVENT_ELEMENT_DEL = 0;
20 EAPI int E_CONNMAN_EVENT_ELEMENT_UPDATED = 0;
22 const char *e_connman_iface_manager = NULL;
23 const char *e_connman_iface_profile = NULL;
24 const char *e_connman_iface_service = NULL;
25 const char *e_connman_iface_connection = NULL;
26 const char *e_connman_iface_technology = NULL;
28 const char *e_connman_prop_ipv4 = NULL;
29 const char *e_connman_prop_ipv4_configuration = NULL;
30 const char *e_connman_prop_ethernet = NULL;
31 const char *e_connman_prop_interface = NULL;
32 const char *e_connman_prop_speed = NULL;
33 const char *e_connman_prop_duplex = NULL;
34 const char *e_connman_prop_method = NULL;
35 const char *e_connman_prop_address = NULL;
36 const char *e_connman_prop_gateway = NULL;
37 const char *e_connman_prop_netmask = NULL;
38 const char *e_connman_prop_mtu = NULL;
39 const char *e_connman_prop_name = NULL;
40 const char *e_connman_prop_offline_mode = NULL;
41 const char *e_connman_prop_profiles = NULL;
42 const char *e_connman_prop_profile_active = NULL;
43 const char *e_connman_prop_services = NULL;
44 const char *e_connman_prop_technologies = NULL;
45 const char *e_connman_prop_state = NULL;
46 const char *e_connman_prop_strength = NULL;
47 const char *e_connman_prop_type = NULL;
48 const char *e_connman_prop_error = NULL;
49 const char *e_connman_prop_security = NULL;
50 const char *e_connman_prop_passphrase = NULL;
51 const char *e_connman_prop_passphrase_required = NULL;
52 const char *e_connman_prop_login_required = NULL;
53 const char *e_connman_prop_favorite = NULL;
54 const char *e_connman_prop_immutable = NULL;
55 const char *e_connman_prop_auto_connect = NULL;
56 const char *e_connman_prop_roaming = NULL;
57 const char *e_connman_prop_technology_default = NULL;
58 const char *e_connman_prop_technologies_available = NULL;
59 const char *e_connman_prop_technologies_enabled = NULL;
60 const char *e_connman_prop_technologies_connected = NULL;
61 const char *e_connman_prop_nameservers = NULL;
62 const char *e_connman_prop_nameservers_configuration = NULL;
63 const char *e_connman_prop_domains = NULL;
64 const char *e_connman_prop_domains_configuration = NULL;
65 const char *e_connman_prop_proxy = NULL;
66 const char *e_connman_prop_proxy_configuration = NULL;
67 const char *e_connman_prop_url = NULL;
68 const char *e_connman_prop_servers = NULL;
69 const char *e_connman_prop_excludes = NULL;
71 int _e_dbus_connman_log_dom = -1;
74 e_connman_system_bus_name_get(void)
76 return unique_name ? unique_name : bus_name;
79 /***********************************************************************
81 ***********************************************************************/
84 * Synchronize elements with server.
86 * This will call Manager.GetProperties() on server, retrieve properties
87 * and some element paths and then request their properties.
89 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
90 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
92 * This will not remove stale elements.
94 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
97 e_connman_manager_sync_elements(void)
99 E_Connman_Element *manager;
104 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
106 e_connman_element_properties_sync(manager);
110 DBG("sync_manager: %s (%s)", unique_name, bus_name);
116 _e_connman_system_name_owner_exit(void)
118 e_connman_manager_clear_elements();
119 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
126 _e_connman_system_name_owner_enter(const char *uid)
128 DBG("enter connman at %s (old was %s)", uid, unique_name);
129 if (unique_name && strcmp(unique_name, uid) == 0)
131 DBG("same unique_name for connman, ignore.");
136 _e_connman_system_name_owner_exit();
138 unique_name = strdup(uid);
140 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
141 e_connman_manager_sync_elements();
145 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
148 const char *name, *from, *to;
150 dbus_error_init(&err);
151 if (!dbus_message_get_args(msg, &err,
152 DBUS_TYPE_STRING, &name,
153 DBUS_TYPE_STRING, &from,
154 DBUS_TYPE_STRING, &to,
157 ERR("could not get NameOwnerChanged arguments: %s: %s",
158 err.name, err.message);
159 dbus_error_free(&err);
163 if (strcmp(name, bus_name) != 0)
166 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
168 if (from[0] == '\0' && to[0] != '\0')
170 _e_connman_system_name_owner_enter(to);
172 else if (from[0] != '\0' && to[0] == '\0')
174 DBG("exit connman at %s", from);
175 if (strcmp(unique_name, from) != 0)
176 DBG("%s was not the known name %s, ignored.", from, unique_name);
178 _e_connman_system_name_owner_exit();
182 DBG("unknow change from %s to %s", from, to);
187 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
193 pending_get_name_owner = NULL;
195 if (!_dbus_callback_check_and_init(msg, &itr, err))
198 t = dbus_message_iter_get_arg_type(&itr);
199 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
202 dbus_message_iter_get_basic(&itr, &uid);
205 ERR("no name owner!");
209 if (!e_connman_iface_manager)
210 e_connman_iface_manager = eina_stringshare_add("net.connman.Manager");
212 if (!e_connman_iface_profile)
213 e_connman_iface_profile = eina_stringshare_add("net.connman.Profile");
215 if (!e_connman_iface_service)
216 e_connman_iface_service = eina_stringshare_add("net.connman.Service");
218 if (!e_connman_iface_connection)
219 e_connman_iface_connection = eina_stringshare_add("net.connman.Connection");
221 if (!e_connman_iface_technology)
222 e_connman_iface_technology = eina_stringshare_add("net.connman.Technology");
224 _e_connman_system_name_owner_enter(uid);
229 _e_connman_get_name_owner_old(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
235 pending_get_name_owner_old = NULL;
237 if (!_dbus_callback_check_and_init(msg, &itr, err))
240 t = dbus_message_iter_get_arg_type(&itr);
241 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
244 dbus_message_iter_get_basic(&itr, &uid);
247 ERR("no name owner!");
251 if (!e_connman_iface_manager)
252 e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager");
254 if (!e_connman_iface_profile)
255 e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile");
257 if (!e_connman_iface_service)
258 e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service");
260 if (!e_connman_iface_connection)
261 e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection");
263 if (!e_connman_iface_technology)
264 e_connman_iface_technology = eina_stringshare_add("org.moblin.connman.Technology");
266 _e_connman_system_name_owner_enter(uid);
271 * Initialize E Connection Manager (E_Connman) system.
273 * This will connect and watch net.connman.Manager and Element
274 * events and translate to Ecore main loop events, also provide a
275 * proxy for method invocation on server.
277 * Interesting events are:
278 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
279 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
280 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
281 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
282 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
285 * Manager IN/OUT events do not provide any event information, just
286 * tells you that system is usable or not. After manager is out, all
287 * elements will be removed, so after this event do not use the system anymore.
289 * Element events will give you an element object. After DEL event callback
290 * returns, that element will not be valid anymore.
293 e_connman_system_init(E_DBus_Connection *edbus_conn)
300 _e_dbus_connman_log_dom = eina_log_domain_register
301 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
303 if (_e_dbus_connman_log_dom < 0)
306 ("impossible to create a log domain for edbus_connman module");
310 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
311 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
313 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
314 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
316 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
317 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
319 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
320 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
322 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
323 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
325 #define ADD_STRINGSHARE(name, s) \
327 name = eina_stringshare_add(s)
329 ADD_STRINGSHARE(e_connman_iface_manager, "net.connman.Manager");
330 ADD_STRINGSHARE(e_connman_iface_profile, "net.connman.Profile");
331 ADD_STRINGSHARE(e_connman_iface_service, "net.connman.Service");
332 ADD_STRINGSHARE(e_connman_iface_connection, "net.connman.Connection");
333 ADD_STRINGSHARE(e_connman_iface_technology, "net.connman.Technology");
335 ADD_STRINGSHARE(e_connman_prop_ipv4, "IPv4");
336 ADD_STRINGSHARE(e_connman_prop_ipv4_configuration, "IPv4.Configuration");
337 ADD_STRINGSHARE(e_connman_prop_ethernet, "Ethernet");
338 ADD_STRINGSHARE(e_connman_prop_interface, "Interface");
339 ADD_STRINGSHARE(e_connman_prop_speed, "Speed");
340 ADD_STRINGSHARE(e_connman_prop_duplex, "Duplex");
341 ADD_STRINGSHARE(e_connman_prop_method, "Method");
342 ADD_STRINGSHARE(e_connman_prop_address, "Address");
343 ADD_STRINGSHARE(e_connman_prop_gateway, "Gateway");
344 ADD_STRINGSHARE(e_connman_prop_netmask, "Netmask");
345 ADD_STRINGSHARE(e_connman_prop_mtu, "MTU");
346 ADD_STRINGSHARE(e_connman_prop_name, "Name");
347 ADD_STRINGSHARE(e_connman_prop_offline_mode, "OfflineMode");
348 ADD_STRINGSHARE(e_connman_prop_profiles, "Profiles");
349 ADD_STRINGSHARE(e_connman_prop_profile_active, "ActiveProfile");
350 ADD_STRINGSHARE(e_connman_prop_services, "Services");
351 ADD_STRINGSHARE(e_connman_prop_technologies, "Technologies");
352 ADD_STRINGSHARE(e_connman_prop_state, "State");
353 ADD_STRINGSHARE(e_connman_prop_strength, "Strength");
354 ADD_STRINGSHARE(e_connman_prop_type, "Type");
355 ADD_STRINGSHARE(e_connman_prop_error, "Error");
356 ADD_STRINGSHARE(e_connman_prop_security, "Security");
357 ADD_STRINGSHARE(e_connman_prop_passphrase, "Passphrase");
358 ADD_STRINGSHARE(e_connman_prop_passphrase_required, "PassphraseRequired");
359 ADD_STRINGSHARE(e_connman_prop_login_required, "LoginRequired");
360 ADD_STRINGSHARE(e_connman_prop_favorite, "Favorite");
361 ADD_STRINGSHARE(e_connman_prop_immutable, "Immutable");
362 ADD_STRINGSHARE(e_connman_prop_auto_connect, "AutoConnect");
363 ADD_STRINGSHARE(e_connman_prop_roaming, "Roaming");
364 ADD_STRINGSHARE(e_connman_prop_technology_default, "DefaultTechnology");
365 ADD_STRINGSHARE(e_connman_prop_technologies_available,
366 "AvailableTechnologies");
367 ADD_STRINGSHARE(e_connman_prop_technologies_enabled, "EnabledTechnologies");
368 ADD_STRINGSHARE(e_connman_prop_technologies_connected,
369 "ConnectedTechnologies");
370 ADD_STRINGSHARE(e_connman_prop_nameservers, "Nameservers");
371 ADD_STRINGSHARE(e_connman_prop_nameservers_configuration,
372 "Nameservers.Configuration");
373 ADD_STRINGSHARE(e_connman_prop_domains, "Domains");
374 ADD_STRINGSHARE(e_connman_prop_domains_configuration,
375 "Domains.Configuration");
376 ADD_STRINGSHARE(e_connman_prop_proxy, "Proxy");
377 ADD_STRINGSHARE(e_connman_prop_proxy_configuration, "Proxy.Configuration");
378 ADD_STRINGSHARE(e_connman_prop_url, "URL");
379 ADD_STRINGSHARE(e_connman_prop_servers, "Servers");
380 ADD_STRINGSHARE(e_connman_prop_excludes, "Excludes");
382 #undef ADD_STRINGSHARE
384 e_connman_conn = edbus_conn;
385 cb_name_owner_changed = e_dbus_signal_handler_add
386 (e_connman_conn, E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, "NameOwnerChanged",
387 _e_connman_system_name_owner_changed, NULL);
389 if (pending_get_name_owner)
390 dbus_pending_call_cancel(pending_get_name_owner);
392 pending_get_name_owner = e_dbus_get_name_owner
393 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
395 if (pending_get_name_owner_old)
396 dbus_pending_call_cancel(pending_get_name_owner_old);
398 pending_get_name_owner_old = e_dbus_get_name_owner
399 (e_connman_conn, bus_name_old, _e_connman_get_name_owner_old, NULL);
401 e_connman_elements_init();
407 _stringshare_del(const char **str)
412 eina_stringshare_del(*str);
417 * Shutdown connman system.
419 * When count drops to 0 resources will be released and no calls should be
423 e_connman_system_shutdown(void)
427 ERR("connman system already shut down.");
435 _stringshare_del(&e_connman_iface_manager);
436 _stringshare_del(&e_connman_iface_profile);
437 _stringshare_del(&e_connman_iface_service);
438 _stringshare_del(&e_connman_iface_connection);
439 _stringshare_del(&e_connman_iface_technology);
441 _stringshare_del(&e_connman_prop_ipv4);
442 _stringshare_del(&e_connman_prop_ipv4_configuration);
443 _stringshare_del(&e_connman_prop_ethernet);
444 _stringshare_del(&e_connman_prop_interface);
445 _stringshare_del(&e_connman_prop_speed);
446 _stringshare_del(&e_connman_prop_duplex);
447 _stringshare_del(&e_connman_prop_method);
448 _stringshare_del(&e_connman_prop_address);
449 _stringshare_del(&e_connman_prop_gateway);
450 _stringshare_del(&e_connman_prop_netmask);
451 _stringshare_del(&e_connman_prop_mtu);
452 _stringshare_del(&e_connman_prop_name);
453 _stringshare_del(&e_connman_prop_offline_mode);
454 _stringshare_del(&e_connman_prop_profiles);
455 _stringshare_del(&e_connman_prop_profile_active);
456 _stringshare_del(&e_connman_prop_services);
457 _stringshare_del(&e_connman_prop_technologies);
458 _stringshare_del(&e_connman_prop_state);
459 _stringshare_del(&e_connman_prop_strength);
460 _stringshare_del(&e_connman_prop_type);
461 _stringshare_del(&e_connman_prop_error);
462 _stringshare_del(&e_connman_prop_security);
463 _stringshare_del(&e_connman_prop_passphrase);
464 _stringshare_del(&e_connman_prop_passphrase_required);
465 _stringshare_del(&e_connman_prop_login_required);
466 _stringshare_del(&e_connman_prop_favorite);
467 _stringshare_del(&e_connman_prop_immutable);
468 _stringshare_del(&e_connman_prop_auto_connect);
469 _stringshare_del(&e_connman_prop_roaming);
470 _stringshare_del(&e_connman_prop_technology_default);
471 _stringshare_del(&e_connman_prop_technologies_available);
472 _stringshare_del(&e_connman_prop_technologies_enabled);
473 _stringshare_del(&e_connman_prop_technologies_connected);
474 _stringshare_del(&e_connman_prop_nameservers);
475 _stringshare_del(&e_connman_prop_nameservers_configuration);
476 _stringshare_del(&e_connman_prop_domains);
477 _stringshare_del(&e_connman_prop_domains_configuration);
478 _stringshare_del(&e_connman_prop_proxy);
479 _stringshare_del(&e_connman_prop_proxy_configuration);
480 _stringshare_del(&e_connman_prop_url);
481 _stringshare_del(&e_connman_prop_servers);
482 _stringshare_del(&e_connman_prop_excludes);
484 if (pending_get_name_owner)
486 dbus_pending_call_cancel(pending_get_name_owner);
487 pending_get_name_owner = NULL;
490 if (cb_name_owner_changed)
492 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
493 cb_name_owner_changed = NULL;
497 _e_connman_system_name_owner_exit();
499 e_connman_elements_shutdown();
500 eina_log_domain_unregister(_e_dbus_connman_log_dom);
501 e_connman_conn = NULL;