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[] = "org.moblin.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_network = NULL;
22 const char *e_connman_iface_profile = NULL;
23 const char *e_connman_iface_service = NULL;
24 const char *e_connman_iface_device = 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_connected = NULL;
30 const char *e_connman_prop_connections = NULL;
31 const char *e_connman_prop_default = NULL;
32 const char *e_connman_prop_device = NULL;
33 const char *e_connman_prop_devices = NULL;
34 const char *e_connman_prop_interface = NULL;
35 const char *e_connman_prop_ipv4 = NULL;
36 const char *e_connman_prop_ipv4_configuration = NULL;
37 const char *e_connman_prop_ethernet = NULL;
38 const char *e_connman_prop_method = NULL;
39 const char *e_connman_prop_address = NULL;
40 const char *e_connman_prop_gateway = NULL;
41 const char *e_connman_prop_netmask = NULL;
42 const char *e_connman_prop_mtu = NULL;
43 const char *e_connman_prop_name = NULL;
44 const char *e_connman_prop_network = NULL;
45 const char *e_connman_prop_networks = NULL;
46 const char *e_connman_prop_offline_mode = NULL;
47 const char *e_connman_prop_policy = NULL;
48 const char *e_connman_prop_powered = NULL;
49 const char *e_connman_prop_priority = NULL;
50 const char *e_connman_prop_profiles = NULL;
51 const char *e_connman_prop_profile_active = NULL;
52 const char *e_connman_prop_services = NULL;
53 const char *e_connman_prop_technologies = NULL;
54 const char *e_connman_prop_remember = NULL;
55 const char *e_connman_prop_scan_interval = NULL;
56 const char *e_connman_prop_scanning = NULL;
57 const char *e_connman_prop_state = NULL;
58 const char *e_connman_prop_strength = NULL;
59 const char *e_connman_prop_frequency = NULL;
60 const char *e_connman_prop_type = NULL;
61 const char *e_connman_prop_wifi_mode = NULL;
62 const char *e_connman_prop_wifi_passphrase = NULL;
63 const char *e_connman_prop_wifi_security = NULL;
64 const char *e_connman_prop_wifi_ssid = NULL;
65 const char *e_connman_prop_wifi_channel = NULL;
66 const char *e_connman_prop_wifi_eap = NULL;
67 const char *e_connman_prop_error = NULL;
68 const char *e_connman_prop_mode = NULL;
69 const char *e_connman_prop_security = NULL;
70 const char *e_connman_prop_passphrase = NULL;
71 const char *e_connman_prop_passphrase_required = NULL;
72 const char *e_connman_prop_favorite = NULL;
73 const char *e_connman_prop_immutable = NULL;
74 const char *e_connman_prop_auto_connect = NULL;
75 const char *e_connman_prop_setup_required = NULL;
76 const char *e_connman_prop_apn = NULL;
77 const char *e_connman_prop_mcc = NULL;
78 const char *e_connman_prop_mnc = NULL;
79 const char *e_connman_prop_roaming = NULL;
80 const char *e_connman_prop_technology_default = NULL;
81 const char *e_connman_prop_technologies_available = NULL;
82 const char *e_connman_prop_technologies_enabled = NULL;
83 const char *e_connman_prop_technologies_connected = NULL;
85 int _e_dbus_connman_log_dom = -1;
88 e_connman_system_bus_name_get(void)
90 return unique_name ? unique_name : bus_name;
93 /***********************************************************************
95 ***********************************************************************/
98 * Synchronize elements with server.
100 * This will call Manager.GetProperties() on server, retrieve properties
101 * and some element paths and then request their properties.
103 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
104 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
106 * This will not remove stale elements.
108 * @return 1 on success, 0 otherwise.
111 e_connman_manager_sync_elements(void)
113 E_Connman_Element *manager;
118 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
120 e_connman_element_properties_sync(manager);
124 DBG("sync_manager: %s (%s)", unique_name, bus_name);
130 _e_connman_system_name_owner_exit(void)
132 e_connman_manager_clear_elements();
133 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
140 _e_connman_system_name_owner_enter(const char *uid)
142 DBG("enter connman at %s (old was %s)", uid, unique_name);
143 if (unique_name && strcmp(unique_name, uid) == 0)
145 DBG("same unique_name for connman, ignore.");
150 _e_connman_system_name_owner_exit();
152 unique_name = strdup(uid);
154 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
155 e_connman_manager_sync_elements();
159 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
162 const char *name, *from, *to;
164 dbus_error_init(&err);
165 if (!dbus_message_get_args(msg, &err,
166 DBUS_TYPE_STRING, &name,
167 DBUS_TYPE_STRING, &from,
168 DBUS_TYPE_STRING, &to,
171 ERR("could not get NameOwnerChanged arguments: %s: %s",
172 err.name, err.message);
173 dbus_error_free(&err);
177 if (strcmp(name, bus_name) != 0)
180 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
182 if (from[0] == '\0' && to[0] != '\0')
184 _e_connman_system_name_owner_enter(to);
186 else if (from[0] != '\0' && to[0] == '\0')
188 DBG("exit connman at %s", from);
189 if (strcmp(unique_name, from) != 0)
190 DBG("%s was not the known name %s, ignored.", from, unique_name);
192 _e_connman_system_name_owner_exit();
196 DBG("unknow change from %s to %s", from, to);
201 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
207 pending_get_name_owner = NULL;
209 if (!_dbus_callback_check_and_init(msg, &itr, err))
212 t = dbus_message_iter_get_arg_type(&itr);
213 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
216 dbus_message_iter_get_basic(&itr, &uid);
219 ERR("no name owner!");
223 _e_connman_system_name_owner_enter(uid);
228 * Initialize E Connection Manager (E_Connman) system.
230 * This will connect and watch org.moblin.connman.Manager and Element
231 * events and translate to Ecore main loop events, also provide a
232 * proxy for method invocation on server.
234 * Interesting events are:
235 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
236 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
237 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
238 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
239 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
242 * Manager IN/OUT events do not provide any event information, just
243 * tells you that system is usable or not. After manager is out, all
244 * elements will be removed, so after this event do not use the system anymore.
246 * Element events will give you an element object. After DEL event callback
247 * returns, that element will not be valid anymore.
250 e_connman_system_init(E_DBus_Connection *edbus_conn)
257 _e_dbus_connman_log_dom = eina_log_domain_register
258 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
260 if(_e_dbus_connman_log_dom < 0)
263 ("impossible to create a log domain for edbus_connman module");
267 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
268 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
270 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
271 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
273 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
274 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
276 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
277 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
279 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
280 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
282 if (!e_connman_iface_manager)
283 e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager");
285 if (!e_connman_iface_network)
286 e_connman_iface_network = eina_stringshare_add("org.moblin.connman.Network");
288 if (!e_connman_iface_profile)
289 e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile");
291 if (!e_connman_iface_service)
292 e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service");
294 if (!e_connman_iface_device)
295 e_connman_iface_device = eina_stringshare_add("org.moblin.connman.Device");
297 if (!e_connman_iface_connection)
298 e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection");
300 if (!e_connman_iface_technology)
301 e_connman_iface_technology = eina_stringshare_add("org.moblin.connman.Technology");
303 if (!e_connman_prop_available)
304 e_connman_prop_available = eina_stringshare_add("Available");
306 if (!e_connman_prop_connected)
307 e_connman_prop_connected = eina_stringshare_add("Connected");
309 if (!e_connman_prop_connections)
310 e_connman_prop_connections = eina_stringshare_add("Connections");
312 if (!e_connman_prop_default)
313 e_connman_prop_default = eina_stringshare_add("Default");
315 if (!e_connman_prop_device)
316 e_connman_prop_device = eina_stringshare_add("Device");
318 if (!e_connman_prop_devices)
319 e_connman_prop_devices = eina_stringshare_add("Devices");
321 if (!e_connman_prop_interface)
322 e_connman_prop_interface = eina_stringshare_add("Interface");
324 if (!e_connman_prop_ipv4)
325 e_connman_prop_ipv4 = eina_stringshare_add("IPv4");
327 if (!e_connman_prop_ipv4_configuration)
328 e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration");
330 if (!e_connman_prop_ethernet)
331 e_connman_prop_ethernet = eina_stringshare_add("Ethernet");
333 if (!e_connman_prop_method)
334 e_connman_prop_method = eina_stringshare_add("Method");
336 if (!e_connman_prop_address)
337 e_connman_prop_address = eina_stringshare_add("Address");
339 if (!e_connman_prop_gateway)
340 e_connman_prop_gateway = eina_stringshare_add("Gateway");
342 if (!e_connman_prop_netmask)
343 e_connman_prop_netmask = eina_stringshare_add("Netmask");
345 if (!e_connman_prop_mtu)
346 e_connman_prop_mtu = eina_stringshare_add("MTU");
348 if (!e_connman_prop_name)
349 e_connman_prop_name = eina_stringshare_add("Name");
351 if (!e_connman_prop_network)
352 e_connman_prop_network = eina_stringshare_add("Network");
354 if (!e_connman_prop_networks)
355 e_connman_prop_networks = eina_stringshare_add("Networks");
357 if (!e_connman_prop_offline_mode)
358 e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode");
360 if (!e_connman_prop_policy)
361 e_connman_prop_policy = eina_stringshare_add("Policy");
363 if (!e_connman_prop_powered)
364 e_connman_prop_powered = eina_stringshare_add("Powered");
366 if (!e_connman_prop_priority)
367 e_connman_prop_priority = eina_stringshare_add("Priority");
369 if (!e_connman_prop_profiles)
370 e_connman_prop_profiles = eina_stringshare_add("Profiles");
372 if (!e_connman_prop_profile_active)
373 e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
375 if (!e_connman_prop_services)
376 e_connman_prop_services = eina_stringshare_add("Services");
378 if (!e_connman_prop_technologies)
379 e_connman_prop_technologies = eina_stringshare_add("Technologies");
381 if (!e_connman_prop_remember)
382 e_connman_prop_remember = eina_stringshare_add("Remember");
384 if (!e_connman_prop_scan_interval)
385 e_connman_prop_scan_interval = eina_stringshare_add("ScanInterval");
387 if (!e_connman_prop_scanning)
388 e_connman_prop_scanning = eina_stringshare_add("Scanning");
390 if (!e_connman_prop_state)
391 e_connman_prop_state = eina_stringshare_add("State");
393 if (!e_connman_prop_strength)
394 e_connman_prop_strength = eina_stringshare_add("Strength");
396 if (!e_connman_prop_frequency)
397 e_connman_prop_frequency = eina_stringshare_add("Frequency");
399 if (!e_connman_prop_type)
400 e_connman_prop_type = eina_stringshare_add("Type");
402 if (!e_connman_prop_wifi_mode)
403 e_connman_prop_wifi_mode = eina_stringshare_add("WiFi.Mode");
405 if (!e_connman_prop_wifi_passphrase)
406 e_connman_prop_wifi_passphrase = eina_stringshare_add("WiFi.Passphrase");
408 if (!e_connman_prop_wifi_security)
409 e_connman_prop_wifi_security = eina_stringshare_add("WiFi.Security");
411 if (!e_connman_prop_wifi_ssid)
412 e_connman_prop_wifi_ssid = eina_stringshare_add("WiFi.SSID");
414 if (!e_connman_prop_wifi_channel)
415 e_connman_prop_wifi_channel = eina_stringshare_add("WiFi.Channel");
417 if (!e_connman_prop_wifi_eap)
418 e_connman_prop_wifi_eap = eina_stringshare_add("WiFi.EAP");
420 if (!e_connman_prop_error)
421 e_connman_prop_error = eina_stringshare_add("Error");
423 if (!e_connman_prop_mode)
424 e_connman_prop_mode = eina_stringshare_add("Mode");
426 if (!e_connman_prop_security)
427 e_connman_prop_security = eina_stringshare_add("Security");
429 if (!e_connman_prop_passphrase)
430 e_connman_prop_passphrase = eina_stringshare_add("Passphrase");
432 if (!e_connman_prop_passphrase_required)
433 e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired");
435 if (!e_connman_prop_favorite)
436 e_connman_prop_favorite = eina_stringshare_add("Favorite");
438 if (!e_connman_prop_immutable)
439 e_connman_prop_immutable = eina_stringshare_add("Immutable");
441 if (!e_connman_prop_auto_connect)
442 e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect");
444 if (!e_connman_prop_setup_required)
445 e_connman_prop_setup_required = eina_stringshare_add("SetupRequired");
447 if (!e_connman_prop_apn)
448 e_connman_prop_apn = eina_stringshare_add("APN");
450 if (!e_connman_prop_mcc)
451 e_connman_prop_mcc = eina_stringshare_add("MCC");
453 if (!e_connman_prop_mnc)
454 e_connman_prop_mnc = eina_stringshare_add("MCN");
456 if (!e_connman_prop_roaming)
457 e_connman_prop_roaming = eina_stringshare_add("Roaming");
459 if (!e_connman_prop_technology_default)
460 e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology");
462 if (!e_connman_prop_technologies_available)
463 e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies");
465 if (!e_connman_prop_technologies_enabled)
466 e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies");
468 if (!e_connman_prop_technologies_connected)
469 e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies");
471 e_connman_conn = edbus_conn;
472 cb_name_owner_changed = e_dbus_signal_handler_add
473 (e_connman_conn, E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, "NameOwnerChanged",
474 _e_connman_system_name_owner_changed, NULL);
476 if (pending_get_name_owner)
477 dbus_pending_call_cancel(pending_get_name_owner);
479 pending_get_name_owner = e_dbus_get_name_owner
480 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
482 e_connman_elements_init();
488 _stringshare_del(const char **str)
493 eina_stringshare_del(*str);
498 * Shutdown connman system.
500 * When count drops to 0 resources will be released and no calls should be
504 e_connman_system_shutdown(void)
508 ERR("connman system already shut down.");
516 _stringshare_del(&e_connman_iface_manager);
517 _stringshare_del(&e_connman_iface_network);
518 _stringshare_del(&e_connman_iface_profile);
519 _stringshare_del(&e_connman_iface_service);
520 _stringshare_del(&e_connman_iface_device);
521 _stringshare_del(&e_connman_iface_connection);
522 _stringshare_del(&e_connman_iface_technology);
524 _stringshare_del(&e_connman_prop_available);
525 _stringshare_del(&e_connman_prop_connected);
526 _stringshare_del(&e_connman_prop_connections);
527 _stringshare_del(&e_connman_prop_default);
528 _stringshare_del(&e_connman_prop_device);
529 _stringshare_del(&e_connman_prop_devices);
530 _stringshare_del(&e_connman_prop_interface);
531 _stringshare_del(&e_connman_prop_ipv4);
532 _stringshare_del(&e_connman_prop_ipv4_configuration);
533 _stringshare_del(&e_connman_prop_ethernet);
534 _stringshare_del(&e_connman_prop_method);
535 _stringshare_del(&e_connman_prop_address);
536 _stringshare_del(&e_connman_prop_gateway);
537 _stringshare_del(&e_connman_prop_netmask);
538 _stringshare_del(&e_connman_prop_mtu);
539 _stringshare_del(&e_connman_prop_name);
540 _stringshare_del(&e_connman_prop_network);
541 _stringshare_del(&e_connman_prop_networks);
542 _stringshare_del(&e_connman_prop_offline_mode);
543 _stringshare_del(&e_connman_prop_policy);
544 _stringshare_del(&e_connman_prop_powered);
545 _stringshare_del(&e_connman_prop_priority);
546 _stringshare_del(&e_connman_prop_profiles);
547 _stringshare_del(&e_connman_prop_profile_active);
548 _stringshare_del(&e_connman_prop_services);
549 _stringshare_del(&e_connman_prop_technologies);
550 _stringshare_del(&e_connman_prop_remember);
551 _stringshare_del(&e_connman_prop_scan_interval);
552 _stringshare_del(&e_connman_prop_scanning);
553 _stringshare_del(&e_connman_prop_state);
554 _stringshare_del(&e_connman_prop_strength);
555 _stringshare_del(&e_connman_prop_frequency);
556 _stringshare_del(&e_connman_prop_type);
557 _stringshare_del(&e_connman_prop_wifi_mode);
558 _stringshare_del(&e_connman_prop_wifi_passphrase);
559 _stringshare_del(&e_connman_prop_wifi_security);
560 _stringshare_del(&e_connman_prop_wifi_ssid);
561 _stringshare_del(&e_connman_prop_wifi_channel);
562 _stringshare_del(&e_connman_prop_wifi_eap);
563 _stringshare_del(&e_connman_prop_error);
564 _stringshare_del(&e_connman_prop_mode);
565 _stringshare_del(&e_connman_prop_security);
566 _stringshare_del(&e_connman_prop_passphrase);
567 _stringshare_del(&e_connman_prop_passphrase_required);
568 _stringshare_del(&e_connman_prop_favorite);
569 _stringshare_del(&e_connman_prop_immutable);
570 _stringshare_del(&e_connman_prop_auto_connect);
571 _stringshare_del(&e_connman_prop_setup_required);
572 _stringshare_del(&e_connman_prop_apn);
573 _stringshare_del(&e_connman_prop_mcc);
574 _stringshare_del(&e_connman_prop_mnc);
575 _stringshare_del(&e_connman_prop_roaming);
576 _stringshare_del(&e_connman_prop_technology_default);
577 _stringshare_del(&e_connman_prop_technologies_available);
578 _stringshare_del(&e_connman_prop_technologies_enabled);
579 _stringshare_del(&e_connman_prop_technologies_connected);
581 if (pending_get_name_owner)
583 dbus_pending_call_cancel(pending_get_name_owner);
584 pending_get_name_owner = NULL;
587 if (cb_name_owner_changed)
589 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
590 cb_name_owner_changed = NULL;
594 _e_connman_system_name_owner_exit();
596 e_connman_elements_shutdown();
597 eina_log_domain_unregister(_e_dbus_connman_log_dom);
598 e_connman_conn = NULL;