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_available = NULL;
29 const char *e_connman_prop_connections = NULL;
30 const char *e_connman_prop_default = NULL;
31 const char *e_connman_prop_ipv4 = NULL;
32 const char *e_connman_prop_ipv4_configuration = NULL;
33 const char *e_connman_prop_ethernet = 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_policy = NULL;
42 const char *e_connman_prop_priority = NULL;
43 const char *e_connman_prop_profiles = NULL;
44 const char *e_connman_prop_profile_active = NULL;
45 const char *e_connman_prop_services = NULL;
46 const char *e_connman_prop_technologies = NULL;
47 const char *e_connman_prop_remember = NULL;
48 const char *e_connman_prop_state = NULL;
49 const char *e_connman_prop_strength = NULL;
50 const char *e_connman_prop_type = NULL;
51 const char *e_connman_prop_error = NULL;
52 const char *e_connman_prop_mode = 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_favorite = NULL;
57 const char *e_connman_prop_immutable = NULL;
58 const char *e_connman_prop_auto_connect = NULL;
59 const char *e_connman_prop_setup_required = NULL;
60 const char *e_connman_prop_apn = NULL;
61 const char *e_connman_prop_mcc = NULL;
62 const char *e_connman_prop_mnc = NULL;
63 const char *e_connman_prop_roaming = NULL;
64 const char *e_connman_prop_technology_default = NULL;
65 const char *e_connman_prop_technologies_available = NULL;
66 const char *e_connman_prop_technologies_enabled = NULL;
67 const char *e_connman_prop_technologies_connected = NULL;
69 int _e_dbus_connman_log_dom = -1;
72 e_connman_system_bus_name_get(void)
74 return unique_name ? unique_name : bus_name;
77 /***********************************************************************
79 ***********************************************************************/
82 * Synchronize elements with server.
84 * This will call Manager.GetProperties() on server, retrieve properties
85 * and some element paths and then request their properties.
87 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
88 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
90 * This will not remove stale elements.
92 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
95 e_connman_manager_sync_elements(void)
97 E_Connman_Element *manager;
102 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
104 e_connman_element_properties_sync(manager);
108 DBG("sync_manager: %s (%s)", unique_name, bus_name);
114 _e_connman_system_name_owner_exit(void)
116 e_connman_manager_clear_elements();
117 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
124 _e_connman_system_name_owner_enter(const char *uid)
126 DBG("enter connman at %s (old was %s)", uid, unique_name);
127 if (unique_name && strcmp(unique_name, uid) == 0)
129 DBG("same unique_name for connman, ignore.");
134 _e_connman_system_name_owner_exit();
136 unique_name = strdup(uid);
138 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
139 e_connman_manager_sync_elements();
143 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
146 const char *name, *from, *to;
148 dbus_error_init(&err);
149 if (!dbus_message_get_args(msg, &err,
150 DBUS_TYPE_STRING, &name,
151 DBUS_TYPE_STRING, &from,
152 DBUS_TYPE_STRING, &to,
155 ERR("could not get NameOwnerChanged arguments: %s: %s",
156 err.name, err.message);
157 dbus_error_free(&err);
161 if (strcmp(name, bus_name) != 0)
164 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
166 if (from[0] == '\0' && to[0] != '\0')
168 _e_connman_system_name_owner_enter(to);
170 else if (from[0] != '\0' && to[0] == '\0')
172 DBG("exit connman at %s", from);
173 if (strcmp(unique_name, from) != 0)
174 DBG("%s was not the known name %s, ignored.", from, unique_name);
176 _e_connman_system_name_owner_exit();
180 DBG("unknow change from %s to %s", from, to);
185 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
191 pending_get_name_owner = NULL;
193 if (!_dbus_callback_check_and_init(msg, &itr, err))
196 t = dbus_message_iter_get_arg_type(&itr);
197 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
200 dbus_message_iter_get_basic(&itr, &uid);
203 ERR("no name owner!");
207 if (!e_connman_iface_manager)
208 e_connman_iface_manager = eina_stringshare_add("net.connman.Manager");
210 if (!e_connman_iface_profile)
211 e_connman_iface_profile = eina_stringshare_add("net.connman.Profile");
213 if (!e_connman_iface_service)
214 e_connman_iface_service = eina_stringshare_add("net.connman.Service");
216 if (!e_connman_iface_connection)
217 e_connman_iface_connection = eina_stringshare_add("net.connman.Connection");
219 if (!e_connman_iface_technology)
220 e_connman_iface_technology = eina_stringshare_add("net.connman.Technology");
222 _e_connman_system_name_owner_enter(uid);
227 _e_connman_get_name_owner_old(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
233 pending_get_name_owner_old = NULL;
235 if (!_dbus_callback_check_and_init(msg, &itr, err))
238 t = dbus_message_iter_get_arg_type(&itr);
239 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
242 dbus_message_iter_get_basic(&itr, &uid);
245 ERR("no name owner!");
249 if (!e_connman_iface_manager)
250 e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager");
252 if (!e_connman_iface_profile)
253 e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile");
255 if (!e_connman_iface_service)
256 e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service");
258 if (!e_connman_iface_connection)
259 e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection");
261 if (!e_connman_iface_technology)
262 e_connman_iface_technology = eina_stringshare_add("org.moblin.connman.Technology");
264 _e_connman_system_name_owner_enter(uid);
269 * Initialize E Connection Manager (E_Connman) system.
271 * This will connect and watch net.connman.Manager and Element
272 * events and translate to Ecore main loop events, also provide a
273 * proxy for method invocation on server.
275 * Interesting events are:
276 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
277 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
278 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
279 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
280 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
283 * Manager IN/OUT events do not provide any event information, just
284 * tells you that system is usable or not. After manager is out, all
285 * elements will be removed, so after this event do not use the system anymore.
287 * Element events will give you an element object. After DEL event callback
288 * returns, that element will not be valid anymore.
291 e_connman_system_init(E_DBus_Connection *edbus_conn)
298 _e_dbus_connman_log_dom = eina_log_domain_register
299 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
301 if (_e_dbus_connman_log_dom < 0)
304 ("impossible to create a log domain for edbus_connman module");
308 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
309 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
311 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
312 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
314 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
315 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
317 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
318 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
320 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
321 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
323 if (!e_connman_prop_available)
324 e_connman_prop_available = eina_stringshare_add("Available");
326 if (!e_connman_prop_connections)
327 e_connman_prop_connections = eina_stringshare_add("Connections");
329 if (!e_connman_prop_default)
330 e_connman_prop_default = eina_stringshare_add("Default");
332 if (!e_connman_prop_ipv4)
333 e_connman_prop_ipv4 = eina_stringshare_add("IPv4");
335 if (!e_connman_prop_ipv4_configuration)
336 e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration");
338 if (!e_connman_prop_ethernet)
339 e_connman_prop_ethernet = eina_stringshare_add("Ethernet");
341 if (!e_connman_prop_method)
342 e_connman_prop_method = eina_stringshare_add("Method");
344 if (!e_connman_prop_address)
345 e_connman_prop_address = eina_stringshare_add("Address");
347 if (!e_connman_prop_gateway)
348 e_connman_prop_gateway = eina_stringshare_add("Gateway");
350 if (!e_connman_prop_netmask)
351 e_connman_prop_netmask = eina_stringshare_add("Netmask");
353 if (!e_connman_prop_mtu)
354 e_connman_prop_mtu = eina_stringshare_add("MTU");
356 if (!e_connman_prop_name)
357 e_connman_prop_name = eina_stringshare_add("Name");
359 if (!e_connman_prop_offline_mode)
360 e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode");
362 if (!e_connman_prop_policy)
363 e_connman_prop_policy = eina_stringshare_add("Policy");
365 if (!e_connman_prop_priority)
366 e_connman_prop_priority = eina_stringshare_add("Priority");
368 if (!e_connman_prop_profiles)
369 e_connman_prop_profiles = eina_stringshare_add("Profiles");
371 if (!e_connman_prop_profile_active)
372 e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
374 if (!e_connman_prop_services)
375 e_connman_prop_services = eina_stringshare_add("Services");
377 if (!e_connman_prop_technologies)
378 e_connman_prop_technologies = eina_stringshare_add("Technologies");
380 if (!e_connman_prop_remember)
381 e_connman_prop_remember = eina_stringshare_add("Remember");
383 if (!e_connman_prop_state)
384 e_connman_prop_state = eina_stringshare_add("State");
386 if (!e_connman_prop_strength)
387 e_connman_prop_strength = eina_stringshare_add("Strength");
389 if (!e_connman_prop_type)
390 e_connman_prop_type = eina_stringshare_add("Type");
392 if (!e_connman_prop_error)
393 e_connman_prop_error = eina_stringshare_add("Error");
395 if (!e_connman_prop_mode)
396 e_connman_prop_mode = eina_stringshare_add("Mode");
398 if (!e_connman_prop_security)
399 e_connman_prop_security = eina_stringshare_add("Security");
401 if (!e_connman_prop_passphrase)
402 e_connman_prop_passphrase = eina_stringshare_add("Passphrase");
404 if (!e_connman_prop_passphrase_required)
405 e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired");
407 if (!e_connman_prop_favorite)
408 e_connman_prop_favorite = eina_stringshare_add("Favorite");
410 if (!e_connman_prop_immutable)
411 e_connman_prop_immutable = eina_stringshare_add("Immutable");
413 if (!e_connman_prop_auto_connect)
414 e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect");
416 if (!e_connman_prop_setup_required)
417 e_connman_prop_setup_required = eina_stringshare_add("SetupRequired");
419 if (!e_connman_prop_apn)
420 e_connman_prop_apn = eina_stringshare_add("APN");
422 if (!e_connman_prop_mcc)
423 e_connman_prop_mcc = eina_stringshare_add("MCC");
425 if (!e_connman_prop_mnc)
426 e_connman_prop_mnc = eina_stringshare_add("MNC");
428 if (!e_connman_prop_roaming)
429 e_connman_prop_roaming = eina_stringshare_add("Roaming");
431 if (!e_connman_prop_technology_default)
432 e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology");
434 if (!e_connman_prop_technologies_available)
435 e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies");
437 if (!e_connman_prop_technologies_enabled)
438 e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies");
440 if (!e_connman_prop_technologies_connected)
441 e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies");
443 e_connman_conn = edbus_conn;
444 cb_name_owner_changed = e_dbus_signal_handler_add
445 (e_connman_conn, E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, "NameOwnerChanged",
446 _e_connman_system_name_owner_changed, NULL);
448 if (pending_get_name_owner)
449 dbus_pending_call_cancel(pending_get_name_owner);
451 pending_get_name_owner = e_dbus_get_name_owner
452 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
454 if (pending_get_name_owner_old)
455 dbus_pending_call_cancel(pending_get_name_owner_old);
457 pending_get_name_owner_old = e_dbus_get_name_owner
458 (e_connman_conn, bus_name_old, _e_connman_get_name_owner_old, NULL);
460 e_connman_elements_init();
466 _stringshare_del(const char **str)
471 eina_stringshare_del(*str);
476 * Shutdown connman system.
478 * When count drops to 0 resources will be released and no calls should be
482 e_connman_system_shutdown(void)
486 ERR("connman system already shut down.");
494 _stringshare_del(&e_connman_iface_manager);
495 _stringshare_del(&e_connman_iface_profile);
496 _stringshare_del(&e_connman_iface_service);
497 _stringshare_del(&e_connman_iface_connection);
498 _stringshare_del(&e_connman_iface_technology);
500 _stringshare_del(&e_connman_prop_available);
501 _stringshare_del(&e_connman_prop_connections);
502 _stringshare_del(&e_connman_prop_default);
503 _stringshare_del(&e_connman_prop_ipv4);
504 _stringshare_del(&e_connman_prop_ipv4_configuration);
505 _stringshare_del(&e_connman_prop_ethernet);
506 _stringshare_del(&e_connman_prop_method);
507 _stringshare_del(&e_connman_prop_address);
508 _stringshare_del(&e_connman_prop_gateway);
509 _stringshare_del(&e_connman_prop_netmask);
510 _stringshare_del(&e_connman_prop_mtu);
511 _stringshare_del(&e_connman_prop_name);
512 _stringshare_del(&e_connman_prop_offline_mode);
513 _stringshare_del(&e_connman_prop_policy);
514 _stringshare_del(&e_connman_prop_priority);
515 _stringshare_del(&e_connman_prop_profiles);
516 _stringshare_del(&e_connman_prop_profile_active);
517 _stringshare_del(&e_connman_prop_services);
518 _stringshare_del(&e_connman_prop_technologies);
519 _stringshare_del(&e_connman_prop_remember);
520 _stringshare_del(&e_connman_prop_state);
521 _stringshare_del(&e_connman_prop_strength);
522 _stringshare_del(&e_connman_prop_type);
523 _stringshare_del(&e_connman_prop_error);
524 _stringshare_del(&e_connman_prop_mode);
525 _stringshare_del(&e_connman_prop_security);
526 _stringshare_del(&e_connman_prop_passphrase);
527 _stringshare_del(&e_connman_prop_passphrase_required);
528 _stringshare_del(&e_connman_prop_favorite);
529 _stringshare_del(&e_connman_prop_immutable);
530 _stringshare_del(&e_connman_prop_auto_connect);
531 _stringshare_del(&e_connman_prop_setup_required);
532 _stringshare_del(&e_connman_prop_apn);
533 _stringshare_del(&e_connman_prop_mcc);
534 _stringshare_del(&e_connman_prop_mnc);
535 _stringshare_del(&e_connman_prop_roaming);
536 _stringshare_del(&e_connman_prop_technology_default);
537 _stringshare_del(&e_connman_prop_technologies_available);
538 _stringshare_del(&e_connman_prop_technologies_enabled);
539 _stringshare_del(&e_connman_prop_technologies_connected);
541 if (pending_get_name_owner)
543 dbus_pending_call_cancel(pending_get_name_owner);
544 pending_get_name_owner = NULL;
547 if (cb_name_owner_changed)
549 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
550 cb_name_owner_changed = NULL;
554 _e_connman_system_name_owner_exit();
556 e_connman_elements_shutdown();
557 eina_log_domain_unregister(_e_dbus_connman_log_dom);
558 e_connman_conn = NULL;