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_address = NULL;
38 const char *e_connman_prop_ipv4_method = NULL;
39 const char *e_connman_prop_address = NULL;
40 const char *e_connman_prop_name = NULL;
41 const char *e_connman_prop_network = NULL;
42 const char *e_connman_prop_networks = NULL;
43 const char *e_connman_prop_offline_mode = NULL;
44 const char *e_connman_prop_policy = NULL;
45 const char *e_connman_prop_powered = NULL;
46 const char *e_connman_prop_priority = NULL;
47 const char *e_connman_prop_profiles = NULL;
48 const char *e_connman_prop_profile_active = NULL;
49 const char *e_connman_prop_services = NULL;
50 const char *e_connman_prop_remember = NULL;
51 const char *e_connman_prop_scan_interval = NULL;
52 const char *e_connman_prop_scanning = NULL;
53 const char *e_connman_prop_state = NULL;
54 const char *e_connman_prop_strength = NULL;
55 const char *e_connman_prop_frequency = NULL;
56 const char *e_connman_prop_type = NULL;
57 const char *e_connman_prop_wifi_mode = NULL;
58 const char *e_connman_prop_wifi_passphrase = NULL;
59 const char *e_connman_prop_wifi_security = NULL;
60 const char *e_connman_prop_wifi_ssid = NULL;
61 const char *e_connman_prop_wifi_channel = NULL;
62 const char *e_connman_prop_wifi_eap = NULL;
63 const char *e_connman_prop_error = NULL;
64 const char *e_connman_prop_mode = NULL;
65 const char *e_connman_prop_security = NULL;
66 const char *e_connman_prop_passphrase = NULL;
67 const char *e_connman_prop_passphrase_required = NULL;
68 const char *e_connman_prop_favorite = NULL;
69 const char *e_connman_prop_immutable = NULL;
70 const char *e_connman_prop_auto_connect = NULL;
71 const char *e_connman_prop_setup_required = NULL;
72 const char *e_connman_prop_apn = NULL;
73 const char *e_connman_prop_mcc = NULL;
74 const char *e_connman_prop_mnc = NULL;
75 const char *e_connman_prop_roaming = NULL;
76 const char *e_connman_prop_technology_default = NULL;
77 const char *e_connman_prop_technologies_available = NULL;
78 const char *e_connman_prop_technologies_enabled= NULL;
79 const char *e_connman_prop_technologies_connected = NULL;
82 int _e_dbus_connman_log_dom = -1;
85 e_connman_system_bus_name_get(void)
87 return unique_name ? unique_name : bus_name;
91 /***********************************************************************
93 ***********************************************************************/
96 * Synchronize elements with server.
98 * This will call Manager.GetProperties() on server, retrieve properties
99 * and some element paths and then request their properties.
101 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
102 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
104 * This will not remove stale elements.
106 * @return 1 on success, 0 otherwise.
109 e_connman_manager_sync_elements(void)
111 E_Connman_Element *manager;
115 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
117 e_connman_element_properties_sync(manager);
121 DBG("sync_manager: %s (%s)", unique_name, bus_name);
127 _e_connman_system_name_owner_exit(void)
129 e_connman_manager_clear_elements();
130 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
137 _e_connman_system_name_owner_enter(const char *uid)
139 DBG("enter connman at %s (old was %s)", uid, unique_name);
140 if (unique_name && strcmp(unique_name, uid) == 0)
142 DBG("same unique_name for connman, ignore.");
147 _e_connman_system_name_owner_exit();
149 unique_name = strdup(uid);
151 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
152 e_connman_manager_sync_elements();
156 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
159 const char *name, *from, *to;
161 dbus_error_init(&err);
162 if (!dbus_message_get_args(msg, &err,
163 DBUS_TYPE_STRING, &name,
164 DBUS_TYPE_STRING, &from,
165 DBUS_TYPE_STRING, &to,
168 ERR("could not get NameOwnerChanged arguments: %s: %s",
169 err.name, err.message);
170 dbus_error_free(&err);
174 if (strcmp(name, bus_name) != 0)
177 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
179 if (from[0] == '\0' && to[0] != '\0')
180 _e_connman_system_name_owner_enter(to);
181 else if (from[0] != '\0' && to[0] == '\0')
183 DBG("exit connman at %s", from);
184 if (strcmp(unique_name, from) != 0)
185 DBG("%s was not the known name %s, ignored.", from, unique_name);
187 _e_connman_system_name_owner_exit();
190 DBG("unknow change from %s to %s", from, to);
194 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
200 pending_get_name_owner = NULL;
202 if (!_dbus_callback_check_and_init(msg, &itr, err))
205 t = dbus_message_iter_get_arg_type(&itr);
206 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
209 dbus_message_iter_get_basic(&itr, &uid);
212 ERR("no name owner!");
216 _e_connman_system_name_owner_enter(uid);
221 * Initialize E Connection Manager (E_Connman) system.
223 * This will connect and watch org.moblin.connman.Manager and Element
224 * events and translate to Ecore main loop events, also provide a
225 * proxy for method invocation on server.
227 * Interesting events are:
228 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
229 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
230 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
231 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
232 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
235 * Manager IN/OUT events do not provide any event information, just
236 * tells you that system is usable or not. After manager is out, all
237 * elements will be removed, so after this event do not use the system anymore.
239 * Element events will give you an element object. After DEL event callback
240 * returns, that element will not be valid anymore.
243 e_connman_system_init(E_DBus_Connection *edbus_conn)
250 _e_dbus_connman_log_dom = eina_log_domain_register
251 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
253 if(_e_dbus_connman_log_dom < 0)
256 ("impossible to create a log domain for edbus_connman module");
260 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
261 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
262 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
263 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
264 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
265 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
266 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
267 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
268 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
269 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
271 if (e_connman_iface_manager == NULL)
272 e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager");
273 if (e_connman_iface_network == NULL)
274 e_connman_iface_network = eina_stringshare_add("org.moblin.connman.Network");
275 if (e_connman_iface_profile == NULL)
276 e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile");
277 if (e_connman_iface_service == NULL)
278 e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service");
279 if (e_connman_iface_device == NULL)
280 e_connman_iface_device = eina_stringshare_add("org.moblin.connman.Device");
281 if (e_connman_iface_connection == NULL)
282 e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection");
284 if (e_connman_prop_available == NULL)
285 e_connman_prop_available = eina_stringshare_add("Available");
286 if (e_connman_prop_connected == NULL)
287 e_connman_prop_connected = eina_stringshare_add("Connected");
288 if (e_connman_prop_connections == NULL)
289 e_connman_prop_connections = eina_stringshare_add("Connections");
290 if (e_connman_prop_default == NULL)
291 e_connman_prop_default = eina_stringshare_add("Default");
292 if (e_connman_prop_device == NULL)
293 e_connman_prop_device = eina_stringshare_add("Device");
294 if (e_connman_prop_devices == NULL)
295 e_connman_prop_devices = eina_stringshare_add("Devices");
296 if (e_connman_prop_interface == NULL)
297 e_connman_prop_interface = eina_stringshare_add("Interface");
298 if (e_connman_prop_ipv4_address == NULL)
299 e_connman_prop_ipv4_address = eina_stringshare_add("IPv4.Address");
300 if (e_connman_prop_ipv4_method == NULL)
301 e_connman_prop_ipv4_method = eina_stringshare_add("IPv4.Method");
302 if (e_connman_prop_address == NULL)
303 e_connman_prop_address = eina_stringshare_add("Address");
304 if (e_connman_prop_name == NULL)
305 e_connman_prop_name = eina_stringshare_add("Name");
306 if (e_connman_prop_network == NULL)
307 e_connman_prop_network = eina_stringshare_add("Network");
308 if (e_connman_prop_networks == NULL)
309 e_connman_prop_networks = eina_stringshare_add("Networks");
310 if (e_connman_prop_offline_mode == NULL)
311 e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode");
312 if (e_connman_prop_policy == NULL)
313 e_connman_prop_policy = eina_stringshare_add("Policy");
314 if (e_connman_prop_powered == NULL)
315 e_connman_prop_powered = eina_stringshare_add("Powered");
316 if (e_connman_prop_priority == NULL)
317 e_connman_prop_priority = eina_stringshare_add("Priority");
318 if (e_connman_prop_profiles == NULL)
319 e_connman_prop_profiles = eina_stringshare_add("Profiles");
320 if (e_connman_prop_profile_active == NULL)
321 e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
322 if (e_connman_prop_services == NULL)
323 e_connman_prop_services = eina_stringshare_add("Services");
324 if (e_connman_prop_remember == NULL)
325 e_connman_prop_remember = eina_stringshare_add("Remember");
326 if (e_connman_prop_scan_interval == NULL)
327 e_connman_prop_scan_interval = eina_stringshare_add("ScanInterval");
328 if (e_connman_prop_scanning == NULL)
329 e_connman_prop_scanning = eina_stringshare_add("Scanning");
330 if (e_connman_prop_state == NULL)
331 e_connman_prop_state = eina_stringshare_add("State");
332 if (e_connman_prop_strength == NULL)
333 e_connman_prop_strength = eina_stringshare_add("Strength");
334 if (e_connman_prop_frequency == NULL)
335 e_connman_prop_frequency = eina_stringshare_add("Frequency");
336 if (e_connman_prop_type == NULL)
337 e_connman_prop_type = eina_stringshare_add("Type");
338 if (e_connman_prop_wifi_mode == NULL)
339 e_connman_prop_wifi_mode = eina_stringshare_add("WiFi.Mode");
340 if (e_connman_prop_wifi_passphrase == NULL)
341 e_connman_prop_wifi_passphrase = eina_stringshare_add("WiFi.Passphrase");
342 if (e_connman_prop_wifi_security == NULL)
343 e_connman_prop_wifi_security = eina_stringshare_add("WiFi.Security");
344 if (e_connman_prop_wifi_ssid == NULL)
345 e_connman_prop_wifi_ssid = eina_stringshare_add("WiFi.SSID");
346 if (e_connman_prop_wifi_channel == NULL)
347 e_connman_prop_wifi_channel = eina_stringshare_add("WiFi.Channel");
348 if (e_connman_prop_wifi_eap == NULL)
349 e_connman_prop_wifi_eap = eina_stringshare_add("WiFi.EAP");
350 if (e_connman_prop_error == NULL)
351 e_connman_prop_error = eina_stringshare_add("Error");
352 if (e_connman_prop_mode == NULL)
353 e_connman_prop_mode = eina_stringshare_add("Mode");
354 if (e_connman_prop_security == NULL)
355 e_connman_prop_security = eina_stringshare_add("Security");
356 if (e_connman_prop_passphrase == NULL)
357 e_connman_prop_passphrase = eina_stringshare_add("Passphrase");
358 if (e_connman_prop_passphrase_required == NULL)
359 e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired");
360 if (e_connman_prop_favorite == NULL)
361 e_connman_prop_favorite = eina_stringshare_add("Favorite");
362 if (e_connman_prop_immutable == NULL)
363 e_connman_prop_immutable = eina_stringshare_add("Immutable");
364 if (e_connman_prop_auto_connect == NULL)
365 e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect");
366 if (e_connman_prop_setup_required == NULL)
367 e_connman_prop_setup_required = eina_stringshare_add("SetupRequired");
368 if (e_connman_prop_apn == NULL)
369 e_connman_prop_apn = eina_stringshare_add("APN");
370 if (e_connman_prop_mcc == NULL)
371 e_connman_prop_mcc = eina_stringshare_add("MCC");
372 if (e_connman_prop_mnc == NULL)
373 e_connman_prop_mnc = eina_stringshare_add("MCN");
374 if (e_connman_prop_roaming == NULL)
375 e_connman_prop_roaming = eina_stringshare_add("Roaming");
376 if (e_connman_prop_technology_default == NULL)
377 e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology");
378 if (e_connman_prop_technologies_available == NULL)
379 e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies");
380 if (e_connman_prop_technologies_enabled == NULL)
381 e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies");
382 if (e_connman_prop_technologies_connected == NULL)
383 e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies");
385 e_connman_conn = edbus_conn;
386 cb_name_owner_changed = e_dbus_signal_handler_add
387 (e_connman_conn, fdo_bus_name, fdo_path, fdo_interface, "NameOwnerChanged",
388 _e_connman_system_name_owner_changed, NULL);
390 if (pending_get_name_owner)
391 dbus_pending_call_cancel(pending_get_name_owner);
393 pending_get_name_owner = e_dbus_get_name_owner
394 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
396 e_connman_elements_init();
402 _stringshare_del(const char **str)
406 eina_stringshare_del(*str);
411 * Shutdown connman system.
413 * When count drops to 0 resources will be released and no calls should be
417 e_connman_system_shutdown(void)
421 ERR("connman system already shut down.");
428 _stringshare_del(&e_connman_iface_manager);
429 _stringshare_del(&e_connman_iface_network);
430 _stringshare_del(&e_connman_iface_profile);
431 _stringshare_del(&e_connman_iface_service);
432 _stringshare_del(&e_connman_iface_device);
433 _stringshare_del(&e_connman_iface_connection);
435 _stringshare_del(&e_connman_prop_available);
436 _stringshare_del(&e_connman_prop_connected);
437 _stringshare_del(&e_connman_prop_connections);
438 _stringshare_del(&e_connman_prop_default);
439 _stringshare_del(&e_connman_prop_device);
440 _stringshare_del(&e_connman_prop_devices);
441 _stringshare_del(&e_connman_prop_interface);
442 _stringshare_del(&e_connman_prop_ipv4_address);
443 _stringshare_del(&e_connman_prop_ipv4_method);
444 _stringshare_del(&e_connman_prop_address);
445 _stringshare_del(&e_connman_prop_name);
446 _stringshare_del(&e_connman_prop_network);
447 _stringshare_del(&e_connman_prop_networks);
448 _stringshare_del(&e_connman_prop_offline_mode);
449 _stringshare_del(&e_connman_prop_policy);
450 _stringshare_del(&e_connman_prop_powered);
451 _stringshare_del(&e_connman_prop_priority);
452 _stringshare_del(&e_connman_prop_profiles);
453 _stringshare_del(&e_connman_prop_profile_active);
454 _stringshare_del(&e_connman_prop_services);
455 _stringshare_del(&e_connman_prop_remember);
456 _stringshare_del(&e_connman_prop_scan_interval);
457 _stringshare_del(&e_connman_prop_scanning);
458 _stringshare_del(&e_connman_prop_state);
459 _stringshare_del(&e_connman_prop_strength);
460 _stringshare_del(&e_connman_prop_frequency);
461 _stringshare_del(&e_connman_prop_type);
462 _stringshare_del(&e_connman_prop_wifi_mode);
463 _stringshare_del(&e_connman_prop_wifi_passphrase);
464 _stringshare_del(&e_connman_prop_wifi_security);
465 _stringshare_del(&e_connman_prop_wifi_ssid);
466 _stringshare_del(&e_connman_prop_wifi_channel);
467 _stringshare_del(&e_connman_prop_wifi_eap);
468 _stringshare_del(&e_connman_prop_error);
469 _stringshare_del(&e_connman_prop_mode);
470 _stringshare_del(&e_connman_prop_security);
471 _stringshare_del(&e_connman_prop_passphrase);
472 _stringshare_del(&e_connman_prop_passphrase_required);
473 _stringshare_del(&e_connman_prop_favorite);
474 _stringshare_del(&e_connman_prop_immutable);
475 _stringshare_del(&e_connman_prop_auto_connect);
476 _stringshare_del(&e_connman_prop_setup_required);
477 _stringshare_del(&e_connman_prop_apn);
478 _stringshare_del(&e_connman_prop_mcc);
479 _stringshare_del(&e_connman_prop_mnc);
480 _stringshare_del(&e_connman_prop_roaming);
481 _stringshare_del(&e_connman_prop_technology_default);
482 _stringshare_del(&e_connman_prop_technologies_available);
483 _stringshare_del(&e_connman_prop_technologies_enabled);
484 _stringshare_del(&e_connman_prop_technologies_connected);
486 if (pending_get_name_owner)
488 dbus_pending_call_cancel(pending_get_name_owner);
489 pending_get_name_owner = NULL;
492 if (cb_name_owner_changed)
494 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
495 cb_name_owner_changed = NULL;
499 _e_connman_system_name_owner_exit();
501 e_connman_elements_shutdown();
502 eina_log_domain_unregister(_e_dbus_connman_log_dom);
503 e_connman_conn = NULL;