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";
11 static const char fdo_bus_name[] = "org.freedesktop.DBus";
12 static const char fdo_interface[] = "org.freedesktop.DBus";
13 static const char fdo_path[] = "/org/freedesktop/DBus";
15 E_DBus_Connection *e_connman_conn = NULL;
17 EAPI int E_CONNMAN_EVENT_MANAGER_IN = 0;
18 EAPI int E_CONNMAN_EVENT_MANAGER_OUT = 0;
19 EAPI int E_CONNMAN_EVENT_ELEMENT_ADD = 0;
20 EAPI int E_CONNMAN_EVENT_ELEMENT_DEL = 0;
21 EAPI int E_CONNMAN_EVENT_ELEMENT_UPDATED = 0;
23 const char *e_connman_iface_manager = NULL;
24 const char *e_connman_iface_network = NULL;
25 const char *e_connman_iface_profile = NULL;
26 const char *e_connman_iface_service = NULL;
27 const char *e_connman_iface_device = NULL;
28 const char *e_connman_iface_connection = NULL;
30 const char *e_connman_prop_available = NULL;
31 const char *e_connman_prop_connected = NULL;
32 const char *e_connman_prop_connections = NULL;
33 const char *e_connman_prop_default = NULL;
34 const char *e_connman_prop_device = NULL;
35 const char *e_connman_prop_devices = NULL;
36 const char *e_connman_prop_interface = NULL;
37 const char *e_connman_prop_ipv4 = NULL;
38 const char *e_connman_prop_ipv4_configuration = NULL;
39 const char *e_connman_prop_ethernet = NULL;
40 const char *e_connman_prop_method = NULL;
41 const char *e_connman_prop_address = NULL;
42 const char *e_connman_prop_gateway = NULL;
43 const char *e_connman_prop_netmask = NULL;
44 const char *e_connman_prop_mtu = NULL;
45 const char *e_connman_prop_name = NULL;
46 const char *e_connman_prop_network = NULL;
47 const char *e_connman_prop_networks = NULL;
48 const char *e_connman_prop_offline_mode = NULL;
49 const char *e_connman_prop_policy = NULL;
50 const char *e_connman_prop_powered = NULL;
51 const char *e_connman_prop_priority = NULL;
52 const char *e_connman_prop_profiles = NULL;
53 const char *e_connman_prop_profile_active = NULL;
54 const char *e_connman_prop_services = NULL;
55 const char *e_connman_prop_remember = NULL;
56 const char *e_connman_prop_scan_interval = NULL;
57 const char *e_connman_prop_scanning = NULL;
58 const char *e_connman_prop_state = NULL;
59 const char *e_connman_prop_strength = NULL;
60 const char *e_connman_prop_frequency = NULL;
61 const char *e_connman_prop_type = NULL;
62 const char *e_connman_prop_wifi_mode = NULL;
63 const char *e_connman_prop_wifi_passphrase = NULL;
64 const char *e_connman_prop_wifi_security = NULL;
65 const char *e_connman_prop_wifi_ssid = NULL;
66 const char *e_connman_prop_wifi_channel = NULL;
67 const char *e_connman_prop_wifi_eap = NULL;
68 const char *e_connman_prop_error = NULL;
69 const char *e_connman_prop_mode = NULL;
70 const char *e_connman_prop_security = NULL;
71 const char *e_connman_prop_passphrase = NULL;
72 const char *e_connman_prop_passphrase_required = NULL;
73 const char *e_connman_prop_favorite = NULL;
74 const char *e_connman_prop_immutable = NULL;
75 const char *e_connman_prop_auto_connect = NULL;
76 const char *e_connman_prop_setup_required = NULL;
77 const char *e_connman_prop_apn = NULL;
78 const char *e_connman_prop_mcc = NULL;
79 const char *e_connman_prop_mnc = NULL;
80 const char *e_connman_prop_roaming = NULL;
81 const char *e_connman_prop_technology_default = NULL;
82 const char *e_connman_prop_technologies_available = NULL;
83 const char *e_connman_prop_technologies_enabled= NULL;
84 const char *e_connman_prop_technologies_connected = NULL;
87 int _e_dbus_connman_log_dom = -1;
90 e_connman_system_bus_name_get(void)
92 return unique_name ? unique_name : bus_name;
96 /***********************************************************************
98 ***********************************************************************/
101 * Synchronize elements with server.
103 * This will call Manager.GetProperties() on server, retrieve properties
104 * and some element paths and then request their properties.
106 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
107 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
109 * This will not remove stale elements.
111 * @return 1 on success, 0 otherwise.
114 e_connman_manager_sync_elements(void)
116 E_Connman_Element *manager;
120 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
122 e_connman_element_properties_sync(manager);
126 DBG("sync_manager: %s (%s)", unique_name, bus_name);
132 _e_connman_system_name_owner_exit(void)
134 e_connman_manager_clear_elements();
135 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
142 _e_connman_system_name_owner_enter(const char *uid)
144 DBG("enter connman at %s (old was %s)", uid, unique_name);
145 if (unique_name && strcmp(unique_name, uid) == 0)
147 DBG("same unique_name for connman, ignore.");
152 _e_connman_system_name_owner_exit();
154 unique_name = strdup(uid);
156 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
157 e_connman_manager_sync_elements();
161 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
164 const char *name, *from, *to;
166 dbus_error_init(&err);
167 if (!dbus_message_get_args(msg, &err,
168 DBUS_TYPE_STRING, &name,
169 DBUS_TYPE_STRING, &from,
170 DBUS_TYPE_STRING, &to,
173 ERR("could not get NameOwnerChanged arguments: %s: %s",
174 err.name, err.message);
175 dbus_error_free(&err);
179 if (strcmp(name, bus_name) != 0)
182 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
184 if (from[0] == '\0' && to[0] != '\0')
185 _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();
195 DBG("unknow change from %s to %s", from, to);
199 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
205 pending_get_name_owner = NULL;
207 if (!_dbus_callback_check_and_init(msg, &itr, err))
210 t = dbus_message_iter_get_arg_type(&itr);
211 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
214 dbus_message_iter_get_basic(&itr, &uid);
217 ERR("no name owner!");
221 _e_connman_system_name_owner_enter(uid);
226 * Initialize E Connection Manager (E_Connman) system.
228 * This will connect and watch org.moblin.connman.Manager and Element
229 * events and translate to Ecore main loop events, also provide a
230 * proxy for method invocation on server.
232 * Interesting events are:
233 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
234 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
235 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
236 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
237 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
240 * Manager IN/OUT events do not provide any event information, just
241 * tells you that system is usable or not. After manager is out, all
242 * elements will be removed, so after this event do not use the system anymore.
244 * Element events will give you an element object. After DEL event callback
245 * returns, that element will not be valid anymore.
248 e_connman_system_init(E_DBus_Connection *edbus_conn)
255 _e_dbus_connman_log_dom = eina_log_domain_register
256 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
258 if(_e_dbus_connman_log_dom < 0)
261 ("impossible to create a log domain for edbus_connman module");
265 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
266 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
267 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
268 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
269 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
270 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
271 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
272 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 == NULL)
277 e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager");
278 if (e_connman_iface_network == NULL)
279 e_connman_iface_network = eina_stringshare_add("org.moblin.connman.Network");
280 if (e_connman_iface_profile == NULL)
281 e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile");
282 if (e_connman_iface_service == NULL)
283 e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service");
284 if (e_connman_iface_device == NULL)
285 e_connman_iface_device = eina_stringshare_add("org.moblin.connman.Device");
286 if (e_connman_iface_connection == NULL)
287 e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection");
289 if (e_connman_prop_available == NULL)
290 e_connman_prop_available = eina_stringshare_add("Available");
291 if (e_connman_prop_connected == NULL)
292 e_connman_prop_connected = eina_stringshare_add("Connected");
293 if (e_connman_prop_connections == NULL)
294 e_connman_prop_connections = eina_stringshare_add("Connections");
295 if (e_connman_prop_default == NULL)
296 e_connman_prop_default = eina_stringshare_add("Default");
297 if (e_connman_prop_device == NULL)
298 e_connman_prop_device = eina_stringshare_add("Device");
299 if (e_connman_prop_devices == NULL)
300 e_connman_prop_devices = eina_stringshare_add("Devices");
301 if (e_connman_prop_interface == NULL)
302 e_connman_prop_interface = eina_stringshare_add("Interface");
303 if (e_connman_prop_ipv4 == NULL)
304 e_connman_prop_ipv4 = eina_stringshare_add("IPv4");
305 if (e_connman_prop_ipv4_configuration == NULL)
306 e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration");
307 if (e_connman_prop_ethernet == NULL)
308 e_connman_prop_ethernet = eina_stringshare_add("Ethernet");
309 if (e_connman_prop_method == NULL)
310 e_connman_prop_method = eina_stringshare_add("Method");
311 if (e_connman_prop_address == NULL)
312 e_connman_prop_address = eina_stringshare_add("Address");
313 if (e_connman_prop_gateway == NULL)
314 e_connman_prop_gateway = eina_stringshare_add("Gateway");
315 if (e_connman_prop_netmask == NULL)
316 e_connman_prop_netmask = eina_stringshare_add("Netmask");
317 if (e_connman_prop_mtu == NULL)
318 e_connman_prop_mtu = eina_stringshare_add("MTU");
319 if (e_connman_prop_name == NULL)
320 e_connman_prop_name = eina_stringshare_add("Name");
321 if (e_connman_prop_network == NULL)
322 e_connman_prop_network = eina_stringshare_add("Network");
323 if (e_connman_prop_networks == NULL)
324 e_connman_prop_networks = eina_stringshare_add("Networks");
325 if (e_connman_prop_offline_mode == NULL)
326 e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode");
327 if (e_connman_prop_policy == NULL)
328 e_connman_prop_policy = eina_stringshare_add("Policy");
329 if (e_connman_prop_powered == NULL)
330 e_connman_prop_powered = eina_stringshare_add("Powered");
331 if (e_connman_prop_priority == NULL)
332 e_connman_prop_priority = eina_stringshare_add("Priority");
333 if (e_connman_prop_profiles == NULL)
334 e_connman_prop_profiles = eina_stringshare_add("Profiles");
335 if (e_connman_prop_profile_active == NULL)
336 e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
337 if (e_connman_prop_services == NULL)
338 e_connman_prop_services = eina_stringshare_add("Services");
339 if (e_connman_prop_remember == NULL)
340 e_connman_prop_remember = eina_stringshare_add("Remember");
341 if (e_connman_prop_scan_interval == NULL)
342 e_connman_prop_scan_interval = eina_stringshare_add("ScanInterval");
343 if (e_connman_prop_scanning == NULL)
344 e_connman_prop_scanning = eina_stringshare_add("Scanning");
345 if (e_connman_prop_state == NULL)
346 e_connman_prop_state = eina_stringshare_add("State");
347 if (e_connman_prop_strength == NULL)
348 e_connman_prop_strength = eina_stringshare_add("Strength");
349 if (e_connman_prop_frequency == NULL)
350 e_connman_prop_frequency = eina_stringshare_add("Frequency");
351 if (e_connman_prop_type == NULL)
352 e_connman_prop_type = eina_stringshare_add("Type");
353 if (e_connman_prop_wifi_mode == NULL)
354 e_connman_prop_wifi_mode = eina_stringshare_add("WiFi.Mode");
355 if (e_connman_prop_wifi_passphrase == NULL)
356 e_connman_prop_wifi_passphrase = eina_stringshare_add("WiFi.Passphrase");
357 if (e_connman_prop_wifi_security == NULL)
358 e_connman_prop_wifi_security = eina_stringshare_add("WiFi.Security");
359 if (e_connman_prop_wifi_ssid == NULL)
360 e_connman_prop_wifi_ssid = eina_stringshare_add("WiFi.SSID");
361 if (e_connman_prop_wifi_channel == NULL)
362 e_connman_prop_wifi_channel = eina_stringshare_add("WiFi.Channel");
363 if (e_connman_prop_wifi_eap == NULL)
364 e_connman_prop_wifi_eap = eina_stringshare_add("WiFi.EAP");
365 if (e_connman_prop_error == NULL)
366 e_connman_prop_error = eina_stringshare_add("Error");
367 if (e_connman_prop_mode == NULL)
368 e_connman_prop_mode = eina_stringshare_add("Mode");
369 if (e_connman_prop_security == NULL)
370 e_connman_prop_security = eina_stringshare_add("Security");
371 if (e_connman_prop_passphrase == NULL)
372 e_connman_prop_passphrase = eina_stringshare_add("Passphrase");
373 if (e_connman_prop_passphrase_required == NULL)
374 e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired");
375 if (e_connman_prop_favorite == NULL)
376 e_connman_prop_favorite = eina_stringshare_add("Favorite");
377 if (e_connman_prop_immutable == NULL)
378 e_connman_prop_immutable = eina_stringshare_add("Immutable");
379 if (e_connman_prop_auto_connect == NULL)
380 e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect");
381 if (e_connman_prop_setup_required == NULL)
382 e_connman_prop_setup_required = eina_stringshare_add("SetupRequired");
383 if (e_connman_prop_apn == NULL)
384 e_connman_prop_apn = eina_stringshare_add("APN");
385 if (e_connman_prop_mcc == NULL)
386 e_connman_prop_mcc = eina_stringshare_add("MCC");
387 if (e_connman_prop_mnc == NULL)
388 e_connman_prop_mnc = eina_stringshare_add("MCN");
389 if (e_connman_prop_roaming == NULL)
390 e_connman_prop_roaming = eina_stringshare_add("Roaming");
391 if (e_connman_prop_technology_default == NULL)
392 e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology");
393 if (e_connman_prop_technologies_available == NULL)
394 e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies");
395 if (e_connman_prop_technologies_enabled == NULL)
396 e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies");
397 if (e_connman_prop_technologies_connected == NULL)
398 e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies");
400 e_connman_conn = edbus_conn;
401 cb_name_owner_changed = e_dbus_signal_handler_add
402 (e_connman_conn, fdo_bus_name, fdo_path, fdo_interface, "NameOwnerChanged",
403 _e_connman_system_name_owner_changed, NULL);
405 if (pending_get_name_owner)
406 dbus_pending_call_cancel(pending_get_name_owner);
408 pending_get_name_owner = e_dbus_get_name_owner
409 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
411 e_connman_elements_init();
417 _stringshare_del(const char **str)
421 eina_stringshare_del(*str);
426 * Shutdown connman system.
428 * When count drops to 0 resources will be released and no calls should be
432 e_connman_system_shutdown(void)
436 ERR("connman system already shut down.");
443 _stringshare_del(&e_connman_iface_manager);
444 _stringshare_del(&e_connman_iface_network);
445 _stringshare_del(&e_connman_iface_profile);
446 _stringshare_del(&e_connman_iface_service);
447 _stringshare_del(&e_connman_iface_device);
448 _stringshare_del(&e_connman_iface_connection);
450 _stringshare_del(&e_connman_prop_available);
451 _stringshare_del(&e_connman_prop_connected);
452 _stringshare_del(&e_connman_prop_connections);
453 _stringshare_del(&e_connman_prop_default);
454 _stringshare_del(&e_connman_prop_device);
455 _stringshare_del(&e_connman_prop_devices);
456 _stringshare_del(&e_connman_prop_interface);
457 _stringshare_del(&e_connman_prop_ipv4);
458 _stringshare_del(&e_connman_prop_ipv4_configuration);
459 _stringshare_del(&e_connman_prop_ethernet);
460 _stringshare_del(&e_connman_prop_method);
461 _stringshare_del(&e_connman_prop_address);
462 _stringshare_del(&e_connman_prop_gateway);
463 _stringshare_del(&e_connman_prop_netmask);
464 _stringshare_del(&e_connman_prop_mtu);
465 _stringshare_del(&e_connman_prop_name);
466 _stringshare_del(&e_connman_prop_network);
467 _stringshare_del(&e_connman_prop_networks);
468 _stringshare_del(&e_connman_prop_offline_mode);
469 _stringshare_del(&e_connman_prop_policy);
470 _stringshare_del(&e_connman_prop_powered);
471 _stringshare_del(&e_connman_prop_priority);
472 _stringshare_del(&e_connman_prop_profiles);
473 _stringshare_del(&e_connman_prop_profile_active);
474 _stringshare_del(&e_connman_prop_services);
475 _stringshare_del(&e_connman_prop_remember);
476 _stringshare_del(&e_connman_prop_scan_interval);
477 _stringshare_del(&e_connman_prop_scanning);
478 _stringshare_del(&e_connman_prop_state);
479 _stringshare_del(&e_connman_prop_strength);
480 _stringshare_del(&e_connman_prop_frequency);
481 _stringshare_del(&e_connman_prop_type);
482 _stringshare_del(&e_connman_prop_wifi_mode);
483 _stringshare_del(&e_connman_prop_wifi_passphrase);
484 _stringshare_del(&e_connman_prop_wifi_security);
485 _stringshare_del(&e_connman_prop_wifi_ssid);
486 _stringshare_del(&e_connman_prop_wifi_channel);
487 _stringshare_del(&e_connman_prop_wifi_eap);
488 _stringshare_del(&e_connman_prop_error);
489 _stringshare_del(&e_connman_prop_mode);
490 _stringshare_del(&e_connman_prop_security);
491 _stringshare_del(&e_connman_prop_passphrase);
492 _stringshare_del(&e_connman_prop_passphrase_required);
493 _stringshare_del(&e_connman_prop_favorite);
494 _stringshare_del(&e_connman_prop_immutable);
495 _stringshare_del(&e_connman_prop_auto_connect);
496 _stringshare_del(&e_connman_prop_setup_required);
497 _stringshare_del(&e_connman_prop_apn);
498 _stringshare_del(&e_connman_prop_mcc);
499 _stringshare_del(&e_connman_prop_mnc);
500 _stringshare_del(&e_connman_prop_roaming);
501 _stringshare_del(&e_connman_prop_technology_default);
502 _stringshare_del(&e_connman_prop_technologies_available);
503 _stringshare_del(&e_connman_prop_technologies_enabled);
504 _stringshare_del(&e_connman_prop_technologies_connected);
506 if (pending_get_name_owner)
508 dbus_pending_call_cancel(pending_get_name_owner);
509 pending_get_name_owner = NULL;
512 if (cb_name_owner_changed)
514 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
515 cb_name_owner_changed = NULL;
519 _e_connman_system_name_owner_exit();
521 e_connman_elements_shutdown();
522 eina_log_domain_unregister(_e_dbus_connman_log_dom);
523 e_connman_conn = NULL;