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_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_connected = NULL;
28 const char *e_connman_prop_connections = NULL;
29 const char *e_connman_prop_default = NULL;
30 const char *e_connman_prop_interface = 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_powered = 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_scan_interval = NULL;
50 const char *e_connman_prop_scanning = NULL;
51 const char *e_connman_prop_state = NULL;
52 const char *e_connman_prop_strength = NULL;
53 const char *e_connman_prop_frequency = NULL;
54 const char *e_connman_prop_type = NULL;
55 const char *e_connman_prop_wifi_mode = NULL;
56 const char *e_connman_prop_wifi_passphrase = NULL;
57 const char *e_connman_prop_wifi_security = NULL;
58 const char *e_connman_prop_wifi_ssid = NULL;
59 const char *e_connman_prop_wifi_channel = NULL;
60 const char *e_connman_prop_wifi_eap = NULL;
61 const char *e_connman_prop_error = NULL;
62 const char *e_connman_prop_mode = NULL;
63 const char *e_connman_prop_security = NULL;
64 const char *e_connman_prop_passphrase = NULL;
65 const char *e_connman_prop_passphrase_required = NULL;
66 const char *e_connman_prop_favorite = NULL;
67 const char *e_connman_prop_immutable = NULL;
68 const char *e_connman_prop_auto_connect = NULL;
69 const char *e_connman_prop_setup_required = NULL;
70 const char *e_connman_prop_apn = NULL;
71 const char *e_connman_prop_mcc = NULL;
72 const char *e_connman_prop_mnc = NULL;
73 const char *e_connman_prop_roaming = NULL;
74 const char *e_connman_prop_technology_default = NULL;
75 const char *e_connman_prop_technologies_available = NULL;
76 const char *e_connman_prop_technologies_enabled = NULL;
77 const char *e_connman_prop_technologies_connected = NULL;
79 int _e_dbus_connman_log_dom = -1;
82 e_connman_system_bus_name_get(void)
84 return unique_name ? unique_name : bus_name;
87 /***********************************************************************
89 ***********************************************************************/
92 * Synchronize elements with server.
94 * This will call Manager.GetProperties() on server, retrieve properties
95 * and some element paths and then request their properties.
97 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
98 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
100 * This will not remove stale elements.
102 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
105 e_connman_manager_sync_elements(void)
107 E_Connman_Element *manager;
112 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
114 e_connman_element_properties_sync(manager);
118 DBG("sync_manager: %s (%s)", unique_name, bus_name);
124 _e_connman_system_name_owner_exit(void)
126 e_connman_manager_clear_elements();
127 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
134 _e_connman_system_name_owner_enter(const char *uid)
136 DBG("enter connman at %s (old was %s)", uid, unique_name);
137 if (unique_name && strcmp(unique_name, uid) == 0)
139 DBG("same unique_name for connman, ignore.");
144 _e_connman_system_name_owner_exit();
146 unique_name = strdup(uid);
148 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
149 e_connman_manager_sync_elements();
153 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
156 const char *name, *from, *to;
158 dbus_error_init(&err);
159 if (!dbus_message_get_args(msg, &err,
160 DBUS_TYPE_STRING, &name,
161 DBUS_TYPE_STRING, &from,
162 DBUS_TYPE_STRING, &to,
165 ERR("could not get NameOwnerChanged arguments: %s: %s",
166 err.name, err.message);
167 dbus_error_free(&err);
171 if (strcmp(name, bus_name) != 0)
174 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
176 if (from[0] == '\0' && to[0] != '\0')
178 _e_connman_system_name_owner_enter(to);
180 else if (from[0] != '\0' && to[0] == '\0')
182 DBG("exit connman at %s", from);
183 if (strcmp(unique_name, from) != 0)
184 DBG("%s was not the known name %s, ignored.", from, unique_name);
186 _e_connman_system_name_owner_exit();
190 DBG("unknow change from %s to %s", from, to);
195 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
201 pending_get_name_owner = NULL;
203 if (!_dbus_callback_check_and_init(msg, &itr, err))
206 t = dbus_message_iter_get_arg_type(&itr);
207 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
210 dbus_message_iter_get_basic(&itr, &uid);
213 ERR("no name owner!");
217 _e_connman_system_name_owner_enter(uid);
222 * Initialize E Connection Manager (E_Connman) system.
224 * This will connect and watch org.moblin.connman.Manager and Element
225 * events and translate to Ecore main loop events, also provide a
226 * proxy for method invocation on server.
228 * Interesting events are:
229 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
230 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
231 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
232 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
233 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
236 * Manager IN/OUT events do not provide any event information, just
237 * tells you that system is usable or not. After manager is out, all
238 * elements will be removed, so after this event do not use the system anymore.
240 * Element events will give you an element object. After DEL event callback
241 * returns, that element will not be valid anymore.
244 e_connman_system_init(E_DBus_Connection *edbus_conn)
251 _e_dbus_connman_log_dom = eina_log_domain_register
252 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
254 if(_e_dbus_connman_log_dom < 0)
257 ("impossible to create a log domain for edbus_connman module");
261 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
262 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
264 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
265 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
267 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
268 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
270 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
271 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
273 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
274 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
276 if (!e_connman_iface_manager)
277 e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager");
279 if (!e_connman_iface_profile)
280 e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile");
282 if (!e_connman_iface_service)
283 e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service");
285 if (!e_connman_iface_connection)
286 e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection");
288 if (!e_connman_iface_technology)
289 e_connman_iface_technology = eina_stringshare_add("org.moblin.connman.Technology");
291 if (!e_connman_prop_available)
292 e_connman_prop_available = eina_stringshare_add("Available");
294 if (!e_connman_prop_connected)
295 e_connman_prop_connected = eina_stringshare_add("Connected");
297 if (!e_connman_prop_connections)
298 e_connman_prop_connections = eina_stringshare_add("Connections");
300 if (!e_connman_prop_default)
301 e_connman_prop_default = eina_stringshare_add("Default");
303 if (!e_connman_prop_interface)
304 e_connman_prop_interface = eina_stringshare_add("Interface");
306 if (!e_connman_prop_ipv4)
307 e_connman_prop_ipv4 = eina_stringshare_add("IPv4");
309 if (!e_connman_prop_ipv4_configuration)
310 e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration");
312 if (!e_connman_prop_ethernet)
313 e_connman_prop_ethernet = eina_stringshare_add("Ethernet");
315 if (!e_connman_prop_method)
316 e_connman_prop_method = eina_stringshare_add("Method");
318 if (!e_connman_prop_address)
319 e_connman_prop_address = eina_stringshare_add("Address");
321 if (!e_connman_prop_gateway)
322 e_connman_prop_gateway = eina_stringshare_add("Gateway");
324 if (!e_connman_prop_netmask)
325 e_connman_prop_netmask = eina_stringshare_add("Netmask");
327 if (!e_connman_prop_mtu)
328 e_connman_prop_mtu = eina_stringshare_add("MTU");
330 if (!e_connman_prop_name)
331 e_connman_prop_name = eina_stringshare_add("Name");
333 if (!e_connman_prop_offline_mode)
334 e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode");
336 if (!e_connman_prop_policy)
337 e_connman_prop_policy = eina_stringshare_add("Policy");
339 if (!e_connman_prop_powered)
340 e_connman_prop_powered = eina_stringshare_add("Powered");
342 if (!e_connman_prop_priority)
343 e_connman_prop_priority = eina_stringshare_add("Priority");
345 if (!e_connman_prop_profiles)
346 e_connman_prop_profiles = eina_stringshare_add("Profiles");
348 if (!e_connman_prop_profile_active)
349 e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
351 if (!e_connman_prop_services)
352 e_connman_prop_services = eina_stringshare_add("Services");
354 if (!e_connman_prop_technologies)
355 e_connman_prop_technologies = eina_stringshare_add("Technologies");
357 if (!e_connman_prop_remember)
358 e_connman_prop_remember = eina_stringshare_add("Remember");
360 if (!e_connman_prop_scan_interval)
361 e_connman_prop_scan_interval = eina_stringshare_add("ScanInterval");
363 if (!e_connman_prop_scanning)
364 e_connman_prop_scanning = eina_stringshare_add("Scanning");
366 if (!e_connman_prop_state)
367 e_connman_prop_state = eina_stringshare_add("State");
369 if (!e_connman_prop_strength)
370 e_connman_prop_strength = eina_stringshare_add("Strength");
372 if (!e_connman_prop_frequency)
373 e_connman_prop_frequency = eina_stringshare_add("Frequency");
375 if (!e_connman_prop_type)
376 e_connman_prop_type = eina_stringshare_add("Type");
378 if (!e_connman_prop_wifi_mode)
379 e_connman_prop_wifi_mode = eina_stringshare_add("WiFi.Mode");
381 if (!e_connman_prop_wifi_passphrase)
382 e_connman_prop_wifi_passphrase = eina_stringshare_add("WiFi.Passphrase");
384 if (!e_connman_prop_wifi_security)
385 e_connman_prop_wifi_security = eina_stringshare_add("WiFi.Security");
387 if (!e_connman_prop_wifi_ssid)
388 e_connman_prop_wifi_ssid = eina_stringshare_add("WiFi.SSID");
390 if (!e_connman_prop_wifi_channel)
391 e_connman_prop_wifi_channel = eina_stringshare_add("WiFi.Channel");
393 if (!e_connman_prop_wifi_eap)
394 e_connman_prop_wifi_eap = eina_stringshare_add("WiFi.EAP");
396 if (!e_connman_prop_error)
397 e_connman_prop_error = eina_stringshare_add("Error");
399 if (!e_connman_prop_mode)
400 e_connman_prop_mode = eina_stringshare_add("Mode");
402 if (!e_connman_prop_security)
403 e_connman_prop_security = eina_stringshare_add("Security");
405 if (!e_connman_prop_passphrase)
406 e_connman_prop_passphrase = eina_stringshare_add("Passphrase");
408 if (!e_connman_prop_passphrase_required)
409 e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired");
411 if (!e_connman_prop_favorite)
412 e_connman_prop_favorite = eina_stringshare_add("Favorite");
414 if (!e_connman_prop_immutable)
415 e_connman_prop_immutable = eina_stringshare_add("Immutable");
417 if (!e_connman_prop_auto_connect)
418 e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect");
420 if (!e_connman_prop_setup_required)
421 e_connman_prop_setup_required = eina_stringshare_add("SetupRequired");
423 if (!e_connman_prop_apn)
424 e_connman_prop_apn = eina_stringshare_add("APN");
426 if (!e_connman_prop_mcc)
427 e_connman_prop_mcc = eina_stringshare_add("MCC");
429 if (!e_connman_prop_mnc)
430 e_connman_prop_mnc = eina_stringshare_add("MNC");
432 if (!e_connman_prop_roaming)
433 e_connman_prop_roaming = eina_stringshare_add("Roaming");
435 if (!e_connman_prop_technology_default)
436 e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology");
438 if (!e_connman_prop_technologies_available)
439 e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies");
441 if (!e_connman_prop_technologies_enabled)
442 e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies");
444 if (!e_connman_prop_technologies_connected)
445 e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies");
447 e_connman_conn = edbus_conn;
448 cb_name_owner_changed = e_dbus_signal_handler_add
449 (e_connman_conn, E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, "NameOwnerChanged",
450 _e_connman_system_name_owner_changed, NULL);
452 if (pending_get_name_owner)
453 dbus_pending_call_cancel(pending_get_name_owner);
455 pending_get_name_owner = e_dbus_get_name_owner
456 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
458 e_connman_elements_init();
464 _stringshare_del(const char **str)
469 eina_stringshare_del(*str);
474 * Shutdown connman system.
476 * When count drops to 0 resources will be released and no calls should be
480 e_connman_system_shutdown(void)
484 ERR("connman system already shut down.");
492 _stringshare_del(&e_connman_iface_manager);
493 _stringshare_del(&e_connman_iface_profile);
494 _stringshare_del(&e_connman_iface_service);
495 _stringshare_del(&e_connman_iface_connection);
496 _stringshare_del(&e_connman_iface_technology);
498 _stringshare_del(&e_connman_prop_available);
499 _stringshare_del(&e_connman_prop_connected);
500 _stringshare_del(&e_connman_prop_connections);
501 _stringshare_del(&e_connman_prop_default);
502 _stringshare_del(&e_connman_prop_interface);
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_powered);
515 _stringshare_del(&e_connman_prop_priority);
516 _stringshare_del(&e_connman_prop_profiles);
517 _stringshare_del(&e_connman_prop_profile_active);
518 _stringshare_del(&e_connman_prop_services);
519 _stringshare_del(&e_connman_prop_technologies);
520 _stringshare_del(&e_connman_prop_remember);
521 _stringshare_del(&e_connman_prop_scan_interval);
522 _stringshare_del(&e_connman_prop_scanning);
523 _stringshare_del(&e_connman_prop_state);
524 _stringshare_del(&e_connman_prop_strength);
525 _stringshare_del(&e_connman_prop_frequency);
526 _stringshare_del(&e_connman_prop_type);
527 _stringshare_del(&e_connman_prop_wifi_mode);
528 _stringshare_del(&e_connman_prop_wifi_passphrase);
529 _stringshare_del(&e_connman_prop_wifi_security);
530 _stringshare_del(&e_connman_prop_wifi_ssid);
531 _stringshare_del(&e_connman_prop_wifi_channel);
532 _stringshare_del(&e_connman_prop_wifi_eap);
533 _stringshare_del(&e_connman_prop_error);
534 _stringshare_del(&e_connman_prop_mode);
535 _stringshare_del(&e_connman_prop_security);
536 _stringshare_del(&e_connman_prop_passphrase);
537 _stringshare_del(&e_connman_prop_passphrase_required);
538 _stringshare_del(&e_connman_prop_favorite);
539 _stringshare_del(&e_connman_prop_immutable);
540 _stringshare_del(&e_connman_prop_auto_connect);
541 _stringshare_del(&e_connman_prop_setup_required);
542 _stringshare_del(&e_connman_prop_apn);
543 _stringshare_del(&e_connman_prop_mcc);
544 _stringshare_del(&e_connman_prop_mnc);
545 _stringshare_del(&e_connman_prop_roaming);
546 _stringshare_del(&e_connman_prop_technology_default);
547 _stringshare_del(&e_connman_prop_technologies_available);
548 _stringshare_del(&e_connman_prop_technologies_enabled);
549 _stringshare_del(&e_connman_prop_technologies_connected);
551 if (pending_get_name_owner)
553 dbus_pending_call_cancel(pending_get_name_owner);
554 pending_get_name_owner = NULL;
557 if (cb_name_owner_changed)
559 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
560 cb_name_owner_changed = NULL;
564 _e_connman_system_name_owner_exit();
566 e_connman_elements_shutdown();
567 eina_log_domain_unregister(_e_dbus_connman_log_dom);
568 e_connman_conn = NULL;