summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Houston <stephen@localhost.localdomain>2017-11-21 10:49:22 -0600
committerStephen Houston <stephen@localhost.localdomain>2017-11-21 10:49:22 -0600
commit62f2b9b9d940b3595e0c2409af3eafe6d9049ced (patch)
treeb726f84c96bf2be5fb7cac94e8a02fa092f929f3
parent503d8c4092d86e2380d326aa2f0123609805c28a (diff)
Wireless: Fix popups, Add networkmanager support (Highly experimental and does not work well)
-rw-r--r--meson.build10
-rw-r--r--src/networkmanager.c1738
-rw-r--r--src/wireless.c235
-rw-r--r--src/wireless.h8
4 files changed, 1949 insertions, 42 deletions
diff --git a/meson.build b/meson.build
index a12c621..b612130 100644
--- a/meson.build
+++ b/meson.build
@@ -16,7 +16,9 @@ dir_lib = join_paths(dir_prefix, get_option('libdir'))
16pkgconfig = import('pkgconfig') 16pkgconfig = import('pkgconfig')
17cc = meson.get_compiler('c') 17cc = meson.get_compiler('c')
18 18
19release = 'ver-0.22' 19dep_e = dependency('enlightenment')
20release = dep_e.get_pkgconfig_variable('release')
21
20host_os = host_machine.system() 22host_os = host_machine.system()
21if host_os == 'linux' 23if host_os == 'linux'
22 if cc.has_header_symbol('features.h', '__UCLIBC__') 24 if cc.has_header_symbol('features.h', '__UCLIBC__')
@@ -31,12 +33,11 @@ endif
31module_arch = '@0@-@1@-@2@'.format(host_os, host_machine.cpu_family(), release) 33module_arch = '@0@-@1@-@2@'.format(host_os, host_machine.cpu_family(), release)
32edje_cmd = find_program('edje_cc') 34edje_cmd = find_program('edje_cc')
33 35
34dep_e = dependency('enlightenment')
35deps = [ 36deps = [
36 dep_e, 37 dep_e,
37 dependency('elementary'), 38 dependency('elementary'),
38] 39]
39dir_gadgets = join_paths([dir_lib, 'enlightenment/gadgets', dep_e.get_pkgconfig_variable('release')]) 40dir_gadgets = join_paths([dir_lib, 'enlightenment/gadgets', module_arch])
40 41
41config_h = configuration_data() 42config_h = configuration_data()
42config_h.set('_GNU_SOURCE', '1') 43config_h.set('_GNU_SOURCE', '1')
@@ -57,7 +58,8 @@ config_h.set_quoted('THEMEDIR', join_paths([dir_gadgets, 'wireless']))
57build_files = [ 58build_files = [
58 'src/wireless.h', 59 'src/wireless.h',
59 'src/wireless.c', 60 'src/wireless.c',
60 'src/connman.c' 61 'src/connman.c',
62 'src/networkmanager.c'
61] 63]
62 64
63inc = include_directories('.', '../../') 65inc = include_directories('.', '../../')
diff --git a/src/networkmanager.c b/src/networkmanager.c
new file mode 100644
index 0000000..ce2252e
--- /dev/null
+++ b/src/networkmanager.c
@@ -0,0 +1,1738 @@
1#include "wireless.h"
2
3#define NETWORKMANAGER_BUS_NAME "org.freedesktop.NetworkManager"
4#define NETWORKMANAGER_BUS_PATH "/org/freedesktop/NetworkManager"
5#define NETWORKMANAGER_BUS_INTERFACE NETWORKMANAGER_BUS_NAME
6
7#define NETWORKMANAGER_SERVICE_TYPE_ITER(i) \
8 for ((i) = 0; (i) < NETWORKMANAGER_SERVICE_TYPE_LAST; (i)++)
9
10#define MILLI_PER_SEC 1000
11#define NETWORKMANAGER_CONNECTION_TIMEOUT 60 * MILLI_PER_SEC
12
13#undef DBG
14#undef INF
15#undef WRN
16#undef ERR
17#undef CRI
18
19#define DBG(...) EINA_LOG_DOM_DBG(_networkmanager_log_dom, __VA_ARGS__)
20#define INF(...) EINA_LOG_DOM_INFO(_networkmanager_log_dom, __VA_ARGS__)
21#define WRN(...) EINA_LOG_DOM_WARN(_networkmanager_log_dom, __VA_ARGS__)
22#define ERR(...) EINA_LOG_DOM_ERR(_networkmanager_log_dom, __VA_ARGS__)
23#define CRI(...) EINA_LOG_DOM_CRIT(_networkmanager_log_dom, __VA_ARGS__)
24
25typedef enum
26{
27 NETWORKMANAGER_STATE_NONE = -1, /* All unknown states */
28 NETWORKMANAGER_STATE_OFFLINE,
29 NETWORKMANAGER_STATE_IDLE,
30 NETWORKMANAGER_STATE_ASSOCIATION,
31 NETWORKMANAGER_STATE_CONFIGURATION,
32 NETWORKMANAGER_STATE_READY,
33 NETWORKMANAGER_STATE_ONLINE,
34 NETWORKMANAGER_STATE_DISCONNECT,
35 NETWORKMANAGER_STATE_FAILURE
36} NetworkManager_State;
37
38typedef enum
39{
40 NETWORKMANAGER_SERVICE_TYPE_NONE = -1, /* All non-supported types */
41 NETWORKMANAGER_SERVICE_TYPE_ETHERNET = 0,
42 NETWORKMANAGER_SERVICE_TYPE_WIFI = 1,
43 NETWORKMANAGER_SERVICE_TYPE_BLUETOOTH = 2,
44 NETWORKMANAGER_SERVICE_TYPE_CELLULAR = 3,
45 NETWORKMANAGER_SERVICE_TYPE_LAST = 4
46} NetworkManager_Service_Type;
47
48typedef struct
49{
50 EINA_INLIST;
51 Eldbus_Proxy *proxy;
52 Eldbus_Proxy *device_proxy;
53
54 /* Private */
55 struct
56 {
57 Eldbus_Pending *connect;
58 void *data;
59 } pending;
60 Eldbus_Signal_Handler *handler;
61
62 /* Properties */
63 const char *path;
64 const char *name;
65 const char *conn_ssid;
66 Wireless_Network_Security security;
67 NetworkManager_State state;
68 NetworkManager_State device_state;
69 NetworkManager_Service_Type type;
70 uint8_t strength;
71 Eina_Bool access_point;
72 Eina_Bool is_active_connection;
73
74 /* Connection */
75 Wireless_Network *wn;
76 unsigned int method;
77 const char *address;
78 const char *gateway;
79 union
80 {
81 struct
82 {
83 const char *netmask;
84 } v4;
85 struct
86 {
87 const char *prefixlength;
88 Wireless_Network_IPv6_Privacy privacy;
89 } v6;
90 } ip;
91
92 Eina_Array *domain_servers;
93 Eina_Array *name_servers;
94 Eina_Array *time_servers;
95
96 /* Proxy */
97 unsigned int proxy_type;
98 const char *proxy_url;
99 Eina_Array *proxy_servers;
100 Eina_Array *proxy_excludes;
101 Eina_Bool ipv6 : 1;
102 Eina_Bool favorite: 1;
103} NetworkManager_Service;
104
105typedef struct NetworkManager_Technology
106{
107 NetworkManager_Service_Type type;
108 NetworkManager_Service *service;
109 Eldbus_Proxy *proxy;
110 Eldbus_Signal_Handler *handler;
111 Eina_Bool powered : 1;
112 Eina_Bool connected : 1;
113 int state;
114} NetworkManager_Technology;
115
116typedef enum
117{
118 NETWORKMANAGER_FIELD_STATE_MANDATORY,
119 NETWORKMANAGER_FIELD_STATE_OPTIONAL,
120 NETWORKMANAGER_FIELD_STATE_ALTERNATE,
121 NETWORKMANAGER_FIELD_STATE_INFO,
122} NetworkManager_Field_State;
123
124typedef struct NetworkManager_Field
125{
126 const char *name;
127
128 NetworkManager_Field_State requirement;
129 const char *type;
130 const char *value;
131} NetworkManager_Field;
132
133static int _networkmanager_log_dom = -1;
134
135static Eina_Inlist *networkmanager_services_list[NETWORKMANAGER_SERVICE_TYPE_LAST];
136static NetworkManager_Service *networkmanager_current_service[NETWORKMANAGER_SERVICE_TYPE_LAST];
137static Wireless_Connection *networkmanager_current_connection[NETWORKMANAGER_SERVICE_TYPE_LAST];
138static NetworkManager_Technology networkmanager_technology[NETWORKMANAGER_SERVICE_TYPE_LAST];
139
140static Eldbus_Pending *pending_getproperties_manager;
141static Eldbus_Pending *pending_getdevices;
142static Eldbus_Pending *pending_getactive;
143static Eldbus_Proxy *proxy_manager;
144static Eina_List *pending_technologies;
145static Eina_List *sig_handlers;
146static const char *active_connection;
147Eldbus_Connection *dbus_conn;
148
149//static NetworkManager_Service *_networkmanager_service_find_path(const char *path);
150static void _networkmanager_services_free();
151
152static void
153_eldbus_proxy_del(Eldbus_Proxy *proxy)
154{
155 Eldbus_Object *obj;
156
157 obj = eldbus_proxy_object_get(proxy);
158 eldbus_proxy_unref(proxy);
159 eldbus_object_unref(obj);
160}
161
162static inline Eina_Bool
163_networkmanager_service_is_connected(const NetworkManager_Service *ns)
164{
165 return (ns->is_active_connection) && (ns->state >= NETWORKMANAGER_STATE_ASSOCIATION) && (ns->state <= NETWORKMANAGER_STATE_ONLINE);
166}
167
168void
169networkmanager_technology_enabled_set(Wireless_Service_Type type EINA_UNUSED, Eina_Bool state EINA_UNUSED)
170{
171}
172
173void
174networkmanager_service_edit(const char *path EINA_UNUSED, Wireless_Connection *wc EINA_UNUSED)
175{
176}
177
178void
179networkmanager_service_edit_proxy(const char *path EINA_UNUSED, Wireless_Connection *wc EINA_UNUSED)
180{
181}
182
183void
184networkmanager_service_edit_domains(const char *path EINA_UNUSED, Wireless_Connection *wc EINA_UNUSED)
185{
186}
187
188void
189networkmanager_service_edit_nameservers(const char *path EINA_UNUSED, Wireless_Connection *wc EINA_UNUSED)
190{
191}
192
193void
194networkmanager_service_edit_timeservers(const char *path EINA_UNUSED, Wireless_Connection *wc EINA_UNUSED)
195{
196}
197
198void
199networkmanager_service_remove(const char *path EINA_UNUSED)
200{
201}
202
203void
204networkmanager_airplane_mode_set(Eina_Bool set EINA_UNUSED)
205{
206}
207
208/*static NetworkManager_Service *
209_networkmanager_service_find_path(const char *path)
210{
211 NetworkManager_Service *ns, *nss = NULL;
212 int i;
213
214 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
215 {
216 EINA_INLIST_FOREACH(networkmanager_services_list[i], ns)
217 {
218 if (eina_streq(ns->path, path))
219 {
220 nss = ns;
221 break;
222 }
223 }
224 }
225 return nss;
226}*/
227
228static NetworkManager_Service *
229_networkmanager_service_find_wn(Wireless_Network *wn)
230{
231 NetworkManager_Service *ns, *nss = NULL;
232 int i;
233
234 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
235 {
236 EINA_INLIST_FOREACH(networkmanager_services_list[i], ns)
237 {
238 if (ns->wn)
239 {
240 if (eina_streq(ns->path, wn->path))
241 {
242 nss = ns;
243 break;
244 }
245 }
246 }
247 }
248 return nss;
249}
250
251static void
252_networkmanager_service_connect_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
253{
254 Eldbus_Message_Iter *it;
255 NetworkManager_Service *ns = data;
256 const char *name, *text, *conn_path;
257
258 it = eldbus_message_iter_get(msg);
259 if (eldbus_message_error_get(msg, &name, &text))
260 {
261 ERR("Could not connect %s: %s", name, text);
262 return;
263 }
264 if (!eldbus_message_iter_arguments_get(it, "o", &conn_path))
265 {
266 ERR("Could not get new connection path");
267 return;
268 }
269 ns->pending.connect = NULL;
270}
271
272static Eina_Bool
273_networkmanager_service_connect(Wireless_Network *wn)
274{
275 NetworkManager_Service *ns;
276
277 ns = _networkmanager_service_find_wn(wn);
278 if (!ns)
279 {
280 ERR("Could not find matching service for this connection request %p", wn);
281 return EINA_FALSE;
282 }
283 if (!ns->pending.connect)
284 {
285 Eldbus_Pending *pend;
286 const char *device_path;
287
288 device_path = eldbus_object_path_get(eldbus_proxy_object_get(ns->device_proxy));
289 if (ns->type == NETWORKMANAGER_SERVICE_TYPE_WIFI)
290 {
291 if (ns->access_point)
292 {
293 pend = eldbus_proxy_call(proxy_manager, "ActivateConnection",
294 _networkmanager_service_connect_cb, ns,
295 NETWORKMANAGER_CONNECTION_TIMEOUT, "ooo",
296 "/", device_path, "/");
297 }
298 else
299 {
300 pend = eldbus_proxy_call(proxy_manager, "ActivateConnection",
301 _networkmanager_service_connect_cb, ns,
302 NETWORKMANAGER_CONNECTION_TIMEOUT, "ooo",
303 ns->path, device_path, "/");
304 }
305 }
306 else
307 {
308 pend = eldbus_proxy_call(proxy_manager, "ActivateConnection",
309 _networkmanager_service_connect_cb, ns,
310 NETWORKMANAGER_CONNECTION_TIMEOUT, "",
311 ns->path, device_path, "/");
312 }
313 ns->pending.connect = pend;
314 }
315 return !!ns->pending.connect;
316}
317
318static Wireless_Network_State
319_networkmanager_wifi_state_convert(NetworkManager_State state)
320{
321 Wireless_Network_State wifi_state;
322 switch (state)
323 {
324 case NETWORKMANAGER_STATE_ASSOCIATION:
325 case NETWORKMANAGER_STATE_CONFIGURATION:
326 wifi_state = WIRELESS_NETWORK_STATE_CONFIGURING;
327 break;
328 case NETWORKMANAGER_STATE_READY:
329 wifi_state = WIRELESS_NETWORK_STATE_CONNECTED;
330 break;
331 case NETWORKMANAGER_STATE_ONLINE:
332 wifi_state = WIRELESS_NETWORK_STATE_ONLINE;
333 break;
334 case NETWORKMANAGER_STATE_FAILURE:
335 wifi_state = WIRELESS_NETWORK_STATE_FAILURE;
336 break;
337 case NETWORKMANAGER_STATE_NONE:
338 case NETWORKMANAGER_STATE_OFFLINE:
339 case NETWORKMANAGER_STATE_IDLE:
340 case NETWORKMANAGER_STATE_DISCONNECT:
341 default:
342 wifi_state = WIRELESS_NETWORK_STATE_NONE;
343 }
344 return wifi_state;
345}
346
347static void
348_networkmanager_service_convert(NetworkManager_Service *ns)
349{
350 Wireless_Network *wn;
351
352 wn = calloc(1, sizeof(Wireless_Network));
353 wn->path = ns->path;
354 wn->name = ns->name;
355 wn->security = ns->security;
356 wn->state = _networkmanager_wifi_state_convert(ns->state);
357 wn->type = ns->type;
358 wn->strength = ns->strength;
359 wn->connect_cb = _networkmanager_service_connect;
360 ns->wn = wn;
361}
362
363static void
364_networkmanager_update_current_network(NetworkManager_Service *ns, NetworkManager_Service_Type type)
365{
366 if (networkmanager_current_service[type] != ns)
367 {
368 free(networkmanager_current_connection[type]);
369 networkmanager_current_connection[type] = NULL;
370 if (ns)
371 networkmanager_current_connection[type] = calloc(1, sizeof(Wireless_Connection));
372 }
373 networkmanager_current_service[type] = ns;
374 if (ns)
375 memcpy(&networkmanager_current_connection[type]->wn, &ns->wn, sizeof(Wireless_Connection));
376 else
377 networkmanager_current_connection[type] = NULL;
378 wireless_wifi_current_networks_set(networkmanager_current_connection);
379}
380
381static void
382_networkmanager_update_networks(NetworkManager_Service_Type type)
383{
384 Eina_Array *arr;
385 NetworkManager_Service *ns;
386 NetworkManager_Service *services[NETWORKMANAGER_SERVICE_TYPE_LAST] = {NULL};
387
388 arr = eina_array_new(eina_inlist_count(networkmanager_services_list[type]));
389 EINA_INLIST_FOREACH(networkmanager_services_list[type], ns)
390 {
391 if (ns->wn) free(ns->wn);
392 _networkmanager_service_convert(ns);
393 eina_array_push(arr, ns->wn);
394 if (networkmanager_current_service[type] && _networkmanager_service_is_connected(ns))
395 services[type] = ns;
396 }
397 memcpy(&networkmanager_current_service, services, NETWORKMANAGER_SERVICE_TYPE_LAST * sizeof(void*));
398 arr = wireless_networks_set(arr);
399 _networkmanager_update_current_network(networkmanager_current_service[type], type);
400 eina_array_free(arr);
401}
402
403static void
404_networkmanager_update_technologies(void)
405{
406 Eina_Bool avail[NETWORKMANAGER_SERVICE_TYPE_LAST];
407 int i;
408
409 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
410 avail[i] = networkmanager_technology[i].type > -1;
411 wireless_service_type_available_set(avail);
412}
413
414static void
415_networkmanager_update_enabled_technologies(void)
416{
417 Eina_Bool enabled[NETWORKMANAGER_SERVICE_TYPE_LAST];
418 int i;
419
420 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
421 enabled[i] = networkmanager_technology[i].powered;
422 wireless_service_type_enabled_set(enabled);
423}
424
425static void
426_networkmanager_service_parse_stringarray(Eldbus_Message_Iter *value, Eina_Array **arr)
427{
428 Eldbus_Message_Iter *itr_array;
429 const char *s;
430
431 if (!eldbus_message_iter_arguments_get(value, "as", &itr_array))
432 {
433 ERR("Could not parse dbus string array %p", value);
434 return;
435 }
436 if (*arr)
437 {
438 while (eina_array_count(*arr))
439 eina_stringshare_del(eina_array_pop(*arr));
440 }
441 else
442 *arr = eina_array_new(1);
443 while (eldbus_message_iter_get_and_next(itr_array, 's', &s))
444 eina_array_push(*arr, eina_stringshare_add(s));
445}
446
447static void
448_networkmanager_manager_getsetting_prop_wireless(void *data, const void *msg, Eldbus_Message_Iter *it)
449{
450 const char *setting = msg;
451 NetworkManager_Service *ns = data;
452
453 if (eina_streq(setting, "ssid"))
454 {
455 Eldbus_Message_Iter *array;
456 unsigned char value;
457 char ssid[33];
458 int i = 0;
459
460 memset (&ssid, '\0', sizeof (ssid));
461 if (!eldbus_message_iter_arguments_get(it, "ay", &array))
462 {
463 ERR("Could not get technology ap ssid %p", msg);
464 return;
465 }
466 while (eldbus_message_iter_get_and_next(array, 'y', &value))
467 {
468 ssid[i] = value;
469 ++i;
470 if (i > 32)
471 {
472 i = 32;
473 break;
474 }
475 }
476 ssid[i] = '\0';
477 if (i)
478 eina_stringshare_replace(&ns->conn_ssid, ssid);
479 }
480}
481
482static void
483_networkmanager_manager_getsetting_prop_proxy(void *data, const void *msg, Eldbus_Message_Iter *it)
484{
485 const char *setting = msg;
486 NetworkManager_Service *ns = data;
487
488 if (eina_streq(setting, "method"))
489 {
490 int method;
491 if (!eldbus_message_iter_arguments_get(it, "u", &method))
492 {
493 ERR("Could not get technology proxy method %p", msg);
494 return;
495 }
496 if (method == 0)
497 ns->proxy_type = WIRELESS_PROXY_TYPE_MANUAL;
498 else
499 ns->proxy_type = WIRELESS_PROXY_TYPE_AUTO;
500 DBG("New proxy type: %d", method);
501 }
502 if (eina_streq(setting, "pac-url"))
503 {
504 const char *url;
505 if (!eldbus_message_iter_arguments_get(it, "s", &url))
506 {
507 ERR("Could not get technology proxy url %p", msg);
508 return;
509 }
510 eina_stringshare_replace(&ns->proxy_url, url);
511 DBG("New proxy url: %s", url);
512 }
513}
514
515static void
516_networkmanager_manager_getsetting_prop_ipv6(void *data, const void *msg, Eldbus_Message_Iter *it)
517{
518 const char *setting = msg;
519 NetworkManager_Service *ns = data;
520
521 if (eina_streq(setting, "method"))
522 {
523 const char *method;
524 if (!eldbus_message_iter_arguments_get(it, "s", &method))
525 {
526 ERR("Could not get technology ipv6 method %p", msg);
527 return;
528 }
529 ns->method = WIRELESS_NETWORK_IPV6_METHOD_OFF;
530 if (eina_streq(method, "auto"))
531 ns->method = WIRELESS_NETWORK_IPV6_METHOD_AUTO;
532 else if (eina_streq(method, "manual"))
533 ns->method = WIRELESS_NETWORK_IPV6_METHOD_MANUAL;
534 else if (eina_streq(method, "6to4"))
535 ns->method = WIRELESS_NETWORK_IPV6_METHOD_6TO4;
536 else if (eina_streq(method, "link-local"))
537 ns->method = WIRELESS_NETWORK_IPV6_METHOD_FIXED;
538 else if (eina_streq(method, "shared"))
539 ns->method = WIRELESS_NETWORK_IPV6_METHOD_FIXED;
540 DBG("New method: %s", method);
541 }
542 else if (eina_streq(setting, "gateway"))
543 {
544 const char *gateway;
545 if (!eldbus_message_iter_arguments_get(it, "s", &gateway))
546 {
547 ERR("Could not get technology ipv6 gateway %p", msg);
548 return;
549 }
550 eina_stringshare_replace(&ns->gateway, gateway);
551 DBG("New gateway: %s", gateway);
552 }
553 else if (eina_streq(setting, "ip6-privacy"))
554 {
555 int privacy;
556 if (!eldbus_message_iter_arguments_get(it, "u", &privacy))
557 {
558 ERR("Could not get technology ipv6 privacy %p", msg);
559 return;
560 }
561 ns->ip.v6.privacy = WIRELESS_NETWORK_IPV6_PRIVACY_DISABLED;
562 if (privacy == -1 || privacy == 0)
563 ns->ip.v6.privacy = WIRELESS_NETWORK_IPV6_PRIVACY_DISABLED;
564 else if (privacy == 1)
565 ns->ip.v6.privacy = WIRELESS_NETWORK_IPV6_PRIVACY_ENABLED;
566 else if (privacy == 2)
567 ns->ip.v6.privacy = WIRELESS_NETWORK_IPV6_PRIVACY_PREFERRED;
568 DBG("New privacy: %d", privacy);
569 }
570 else if (eina_streq(setting, "address-data"))
571 {
572 const char *name, *address;
573 size_t prefix;
574 char buf[4096];
575 Eldbus_Message_Iter *array, *array2, *array3, *variant;
576 if (!eldbus_message_iter_arguments_get(it, "aa{sv}", &array))
577 {
578 ERR("Could not get technology ipv6 address %p", msg);
579 return;
580 }
581 if (!eldbus_message_iter_arguments_get(array, "a{sv}", &array2))
582 {
583 DBG("No IPv6 address %p", msg);
584 return;
585 }
586 while (eldbus_message_iter_get_and_next(array2, 'e', &array3))
587 {
588 if (!eldbus_message_iter_arguments_get(array3, "sv", &name, &variant))
589 {
590 ERR("Could not get technology ipv6 address %p", msg);
591 return;
592 }
593 if (eina_streq(name, "address"))
594 {
595 if (!eldbus_message_iter_arguments_get(variant, "s", &address))
596 {
597 ERR("Could not get technology ipv6 address %p", msg);
598 return;
599 }
600 if (strlen(address) >= 5)
601 eina_stringshare_replace(&ns->address, address);
602 DBG("New address: %s", address);
603 }
604 else if (eina_streq(name, "prefix"))
605 {
606 if (!eldbus_message_iter_arguments_get(variant, "u", &prefix))
607 {
608 ERR("Could not get technology ipv6 address %p", msg);
609 return;
610 }
611 memset (&buf, '\0', sizeof (buf));
612 snprintf(buf, sizeof(buf), "%ld", prefix);
613 eina_stringshare_replace(&ns->ip.v6.prefixlength, buf);
614 DBG("New prefix length: %s", buf);
615 }
616 }
617 }
618 else if (eina_streq(setting, "dns"))
619 _networkmanager_service_parse_stringarray(it, &ns->name_servers);
620 else if (eina_streq(setting, "dns-search"))
621 _networkmanager_service_parse_stringarray(it, &ns->domain_servers);
622}
623
624static void
625_networkmanager_manager_getsetting_prop_ipv4(void *data, const void *msg, Eldbus_Message_Iter *it)
626{
627 const char *setting = msg;
628 NetworkManager_Service *ns = data;
629
630 if (eina_streq(setting, "method"))
631 {
632 const char *method;
633 if (!eldbus_message_iter_arguments_get(it, "s", &method))
634 {
635 ERR("Could not get technology ipv4 method %p", msg);
636 return;
637 }
638 ns->method = WIRELESS_NETWORK_IPV4_METHOD_OFF;
639 if (eina_streq(method, "disabled"))
640 ns->method = WIRELESS_NETWORK_IPV4_METHOD_OFF;
641 else if (eina_streq(method, "auto"))
642 ns->method = WIRELESS_NETWORK_IPV4_METHOD_DHCP;
643 else if (eina_streq(method, "manual"))
644 ns->method = WIRELESS_NETWORK_IPV4_METHOD_MANUAL;
645 else if (eina_streq(method, "link-local"))
646 ns->method = WIRELESS_NETWORK_IPV4_METHOD_FIXED;
647 else if (eina_streq(method, "shared"))
648 ns->method = WIRELESS_NETWORK_IPV4_METHOD_FIXED;
649 DBG("New method: %s", method);
650 }
651 if (eina_streq(setting, "gateway"))
652 {
653 const char *gateway;
654 if (!eldbus_message_iter_arguments_get(it, "s", &gateway))
655 {
656 ERR("Could not get technology ipv4 gateway %p", msg);
657 return;
658 }
659 eina_stringshare_replace(&ns->gateway, gateway);
660 DBG("New gateway: %s", gateway);
661 }
662 if (eina_streq(setting, "address-data"))
663 {
664 const char *name, *address;
665 size_t prefix = 0;
666 char buf[4096];
667 struct in_addr tmp_addr;
668 Eldbus_Message_Iter *array, *array2, *array3, *variant;
669 if (!eldbus_message_iter_arguments_get(it, "aa{sv}", &array))
670 {
671 ERR("Could not get technology ipv4 address %p", msg);
672 return;
673 }
674 if (!eldbus_message_iter_arguments_get(array, "a{sv}", &array2))
675 {
676 DBG("No IPv4 address %p", msg);
677 return;
678 }
679 while (eldbus_message_iter_get_and_next(array2, 'e', &array3))
680 {
681 if (!eldbus_message_iter_arguments_get(array3, "sv", &name, &variant))
682 {
683 ERR("Could not get technology ipv4 address %p", msg);
684 return;
685 }
686 if (eina_streq(name, "address"))
687 {
688 if (!eldbus_message_iter_arguments_get(variant, "s", &address))
689 {
690 ERR("Could not get technology ipv4 address %p", msg);
691 return;
692 }
693 if (strlen(address) >= 5)
694 eina_stringshare_replace(&ns->address, address);
695 DBG("New address: %s", address);
696 }
697 if (eina_streq(name, "prefix"))
698 {
699 if (!eldbus_message_iter_arguments_get(variant, "u", &prefix))
700 {
701 ERR("Could not get technology ipv4 address %p", msg);
702 return;
703 }
704 memset (&buf, '\0', sizeof (buf));
705 tmp_addr.s_addr = prefix ? htonl(~((1 << (32 - prefix)) - 1)) : 0;
706 inet_ntop(AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN);
707 eina_stringshare_replace(&ns->ip.v4.netmask, buf);
708 DBG("New netmask: %s", buf);
709 }
710 }
711 }
712 else if (eina_streq(setting, "dns"))
713 _networkmanager_service_parse_stringarray(it, &ns->name_servers);
714 else if (eina_streq(setting, "dns-search"))
715 _networkmanager_service_parse_stringarray(it, &ns->domain_servers);
716}
717
718static void
719_networkmanager_manager_getsetting_prop_connection(void *data, const void *msg, Eldbus_Message_Iter *it)
720{
721 const char *name, *setting = msg;
722 NetworkManager_Service *ns = data;
723
724 if (eina_streq(setting, "id"))
725 {
726 if (!eldbus_message_iter_arguments_get(it, "s", &name))
727 {
728 ERR("Could not get technology name %p", msg);
729 return;
730 }
731 eina_stringshare_replace(&ns->name, name);
732 DBG("New name: %s", name);
733 }
734}
735
736static void
737_networkmanager_manager_getap(void *data, const void *msg, Eldbus_Message_Iter *it)
738{
739 const char *setting = msg;
740 NetworkManager_Service *ns = data;
741
742 if (eina_streq(setting, "Ssid"))
743 {
744 Eldbus_Message_Iter *array;
745 unsigned char value;
746 char ssid[33];
747 int i = 0;
748
749 memset (&ssid, '\0', sizeof (ssid));
750 if (!eldbus_message_iter_arguments_get(it, "ay", &array))
751 {
752 ERR("Could not get technology ap ssid %p", msg);
753 return;
754 }
755 while (eldbus_message_iter_get_and_next(array, 'y', &value))
756 {
757 ssid[i] = value;
758 ++i;
759 if (i > 32)
760 {
761 i = 32;
762 break;
763 }
764 }
765 ssid[i] = '\0';
766 if (i)
767 eina_stringshare_replace(&ns->name, ssid);
768 }
769 else if (eina_streq(setting, "Strength"))
770 {
771 int value;
772
773 if (!eldbus_message_iter_arguments_get(it, "y", &value))
774 {
775 ERR("Could not get technology ap strength %p", msg);
776 return;
777 }
778 ns->strength = value;
779 }
780 else if (eina_streq(setting, "WpaFlags"))
781 {
782 int value;
783
784 if (!eldbus_message_iter_arguments_get(it, "u", &value))
785 {
786 ERR("Could not get technology ap security %p", msg);
787 return;
788 }
789 if (value & 0x00000000)
790 {
791 ns->security = WIRELESS_NETWORK_SECURITY_NONE;
792 }
793 else if ((value & 0x00000001) || (value & 0x00000002) ||
794 (value & 0x00000008) || (value & 0x00000010))
795 {
796 ns->security = WIRELESS_NETWORK_SECURITY_WEP;
797 }
798 else if (value & 0x00000100)
799 {
800 ns->security = WIRELESS_NETWORK_SECURITY_PSK;
801 }
802 else if (value & 0x00000200)
803 {
804 ns->security = WIRELESS_NETWORK_SECURITY_IEEE8021X;
805 }
806 }
807}
808
809static void
810_networkmanager_manager_getsetting(void *data, const void *msg, Eldbus_Message_Iter *it)
811{
812 const char *setting = msg;
813
814 if (eina_streq(setting, "connection"))
815 {
816 eldbus_message_iter_dict_iterate(it, "sv",
817 _networkmanager_manager_getsetting_prop_connection, data);
818 }
819 else if (eina_streq(setting, "ipv4"))
820 {
821 eldbus_message_iter_dict_iterate(it, "sv",
822 _networkmanager_manager_getsetting_prop_ipv4, data);
823 }
824 else if (eina_streq(setting, "ipv6"))
825 {
826 eldbus_message_iter_dict_iterate(it, "sv",
827 _networkmanager_manager_getsetting_prop_ipv6, data);
828 }
829 else if (eina_streq(setting, "proxy"))
830 {
831 eldbus_message_iter_dict_iterate(it, "sv",
832 _networkmanager_manager_getsetting_prop_proxy, data);
833 }
834 else if (eina_streq(setting, "802-11-wireless"))
835 {
836 eldbus_message_iter_dict_iterate(it, "sv",
837 _networkmanager_manager_getsetting_prop_wireless, data);
838 }
839}
840
841static void
842_networkmanager_service_free_common(NetworkManager_Service *ns)
843{
844 if (!ns) return;
845
846 if (ns->pending.connect)
847 {
848 eldbus_pending_cancel(ns->pending.connect);
849 free(ns->pending.data);
850 }
851 eina_stringshare_del(ns->address);
852 eina_stringshare_del(ns->gateway);
853 if (ns->ipv6)
854 {
855 eina_stringshare_del(ns->ip.v6.prefixlength);
856 }
857 else
858 {
859 eina_stringshare_del(ns->ip.v4.netmask);
860 }
861 eina_stringshare_del(ns->proxy_url);
862 if (ns->domain_servers)
863 array_clear(ns->domain_servers);
864 if (ns->name_servers)
865 array_clear(ns->name_servers);
866 if (ns->time_servers)
867 array_clear(ns->time_servers);
868 if (ns->proxy_servers)
869 array_clear(ns->proxy_servers);
870 if (ns->proxy_excludes)
871 array_clear(ns->proxy_excludes);
872 eina_stringshare_del(ns->name);
873 eina_stringshare_del(ns->path);
874 if (ns->handler)
875 eldbus_signal_handler_del(ns->handler);
876 if (ns->wn)
877 free(ns->wn);
878 DBG("service free %p || proxy %p", ns, ns->proxy);
879 if (ns->proxy)
880 _eldbus_proxy_del(ns->proxy);
881}
882
883static void
884_networkmanager_service_free_nolist(NetworkManager_Service *ns)
885{
886 if (!ns) return;
887
888 _networkmanager_service_free_common(ns);
889 free(ns);
890 ns = NULL;
891}
892
893static void
894_networkmanager_service_free(NetworkManager_Service *ns)
895{
896 if (!ns) return;
897
898 _networkmanager_service_free_common(ns);
899 networkmanager_services_list[ns->type] = eina_inlist_remove(networkmanager_services_list[ns->type],
900 EINA_INLIST_GET(ns));
901 free(ns);
902 ns = NULL;
903}
904
905static void
906_networkmanager_service_ap_property(void *data, const Eldbus_Message *msg)
907{
908 NetworkManager_Service *ns = data;
909 Eldbus_Message_Iter *var;
910
911 if (!eldbus_message_arguments_get(msg, "a{sv}", &var))
912 {
913 ERR("Could not parse property update %p", msg);
914 return;
915 }
916 eldbus_message_iter_dict_iterate(var, "sv", _networkmanager_manager_getap, ns);
917 if (_networkmanager_service_is_connected(ns))
918 _networkmanager_update_current_network(ns, ns->type);
919}
920
921static void
922_networkmanager_service_property(void *data, const Eldbus_Message *msg)
923{
924 NetworkManager_Service *ns = data;
925 Eldbus_Message_Iter *var;
926
927 if (!eldbus_message_arguments_get(msg, "a{sv}", &var))
928 {
929 ERR("Could not parse property update %p", msg);
930 return;
931 }
932 eldbus_message_iter_dict_iterate(var, "sv", _networkmanager_manager_getsetting, ns);
933 if (_networkmanager_service_is_connected(ns))
934 _networkmanager_update_current_network(ns, ns->type);
935}
936
937static void
938_networkmanager_service_state(void *data, int state)
939{
940 NetworkManager_Service *ns = data;
941 int i;
942
943 if (state <= 0)
944 ns->device_state = NETWORKMANAGER_STATE_NONE; /* All unknown states */
945 else if (state > 0 && state <= 20)
946 ns->device_state = NETWORKMANAGER_STATE_OFFLINE;
947 else if (state == 30)
948 ns->device_state = NETWORKMANAGER_STATE_IDLE;
949 else if (state == 40)
950 ns->device_state = NETWORKMANAGER_STATE_ASSOCIATION;
951 else if (state == 50)
952 ns->device_state = NETWORKMANAGER_STATE_CONFIGURATION;
953 else if (state > 50 && state < 100)
954 ns->device_state = NETWORKMANAGER_STATE_READY;
955 else if (state == 100)
956 ns->device_state = NETWORKMANAGER_STATE_ONLINE;
957 else if (state == 110)
958 ns->device_state = NETWORKMANAGER_STATE_DISCONNECT;
959 else if (state == 120)
960 ns->device_state = NETWORKMANAGER_STATE_FAILURE;
961 else
962 ns->device_state = NETWORKMANAGER_STATE_NONE;
963 if (ns->is_active_connection)
964 ns->state = ns->device_state;
965 else
966 ns->state = NETWORKMANAGER_STATE_IDLE;
967
968 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
969 {
970 if (i != ns->type)
971 _networkmanager_update_networks(i);
972 }
973 if (_networkmanager_service_is_connected(ns))
974 _networkmanager_update_current_network(ns, ns->type);
975}
976
977static NetworkManager_Service *
978_networkmanager_service_ap_new(int type, const char *path, Eldbus_Message_Iter *props)
979{
980 NetworkManager_Service *ns, *nss;
981 Eldbus_Object *obj;
982
983 ns = calloc(1, sizeof(NetworkManager_Service));
984 ns->path = eina_stringshare_add(path);
985 ns->type = type;
986 ns->address = NULL;
987 ns->access_point = EINA_TRUE;
988 ns->is_active_connection = EINA_FALSE;
989 ns->state = NETWORKMANAGER_STATE_IDLE;
990 ns->device_state = NETWORKMANAGER_STATE_IDLE;
991
992 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
993 ns->proxy = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".AccessPoint");
994 ns->handler = eldbus_proxy_signal_handler_add(ns->proxy, "PropertiesChanged",
995 _networkmanager_service_ap_property, ns);
996 eldbus_message_iter_dict_iterate(props, "sv", _networkmanager_manager_getap, ns);
997 if (ns->type == -1)
998 {
999 ERR("Service added of invalid type");
1000 _networkmanager_service_free_nolist(ns);
1001 return NULL;
1002 }
1003 if (!ns->name)
1004 {
1005 DBG("Invalid service name");
1006 _networkmanager_service_free_nolist(ns);
1007 return NULL;
1008 }
1009 EINA_INLIST_FOREACH(networkmanager_services_list[ns->type], nss)
1010 {
1011 if (nss->access_point)
1012 {
1013 if (!nss->name) continue;
1014 if (eina_streq(ns->name, nss->name))
1015 {
1016 DBG("Matched APs");
1017 if (nss->strength > ns->strength)
1018 {
1019 _networkmanager_service_free_nolist(ns);
1020 return NULL;
1021 }
1022 else
1023 {
1024 _networkmanager_service_free(nss);
1025 break;
1026 }
1027 }
1028 }
1029 else
1030 {
1031 if (!nss->conn_ssid) continue;
1032 if (eina_streq(ns->name, nss->conn_ssid))
1033 {
1034 if (nss->strength < ns->strength)
1035 {
1036 nss->strength = ns->strength;
1037 nss->security = ns->security;
1038 if (nss->wn)
1039 free(nss->wn);
1040 _networkmanager_service_convert(nss);
1041 }
1042 _networkmanager_service_free_nolist(ns);
1043 return NULL;
1044 }
1045 }
1046 }
1047 networkmanager_services_list[ns->type] = eina_inlist_append(networkmanager_services_list[ns->type],
1048 EINA_INLIST_GET(ns));
1049 DBG("Added service: %p %s || proxy %p", ns, path, ns->proxy);
1050 return ns;
1051}
1052
1053static NetworkManager_Service *
1054_networkmanager_service_new(int type, int state, const char *path, Eldbus_Message_Iter *props)
1055{
1056 NetworkManager_Service *ns, *nss;
1057 Eldbus_Object *obj;
1058
1059 ns = calloc(1, sizeof(NetworkManager_Service));
1060 ns->path = eina_stringshare_add(path);
1061 ns->type = type;
1062 ns->access_point = EINA_FALSE;
1063 ns->is_active_connection = EINA_FALSE;
1064 ns->address = NULL;
1065 if (active_connection && path)
1066 {
1067 if (eina_streq(ns->path, active_connection))
1068 {
1069 ns->is_active_connection = EINA_TRUE;
1070 }
1071 }
1072 _networkmanager_service_state(ns, state);
1073
1074 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
1075 ns->proxy = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Settings.Connection");
1076 ns->handler = eldbus_proxy_signal_handler_add(ns->proxy, "PropertiesChanged",
1077 _networkmanager_service_property, ns);
1078 eldbus_message_iter_dict_iterate(props, "sa{sv}", _networkmanager_manager_getsetting, ns);
1079 if (ns->type == -1)
1080 {
1081 ERR("Service added of invalid type");
1082 _networkmanager_service_free_nolist(ns);
1083 return NULL;
1084 }
1085 if (!ns->name)
1086 {
1087 ERR("Invalid service name");
1088 _networkmanager_service_free_nolist(ns);
1089 return NULL;
1090 }
1091 EINA_INLIST_FOREACH(networkmanager_services_list[ns->type], nss)
1092 {
1093 if (!ns->conn_ssid) continue;
1094 if (nss->access_point)
1095 {
1096 if (!nss->name) continue;
1097 if (eina_streq(ns->conn_ssid, nss->name))
1098 {
1099 DBG("Matched Service To AP");
1100 if (ns->strength < nss->strength)
1101 {
1102 ns->strength = nss->strength;
1103 ns->security = nss->security;
1104 }
1105 _networkmanager_service_free(nss);
1106 }
1107 }
1108 }
1109 networkmanager_services_list[ns->type] = eina_inlist_append(networkmanager_services_list[ns->type],
1110 EINA_INLIST_GET(ns));
1111 DBG("Added service: %p %s || proxy %p", ns, path, ns->proxy);
1112 return ns;
1113}
1114
1115static void
1116_networkmanager_manager_getaps(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
1117{
1118 const char *name, *text, *path;
1119 Eldbus_Message_Iter *it, *array;
1120 NetworkManager_Technology *nt = data;
1121 NetworkManager_Service *ns;
1122
1123 pending_technologies = eina_list_remove(pending_technologies, pending);
1124
1125 it = eldbus_message_iter_get(msg);
1126 if (eldbus_message_error_get(msg, &name, &text))
1127 {
1128 ERR("Could not get technology aps %s: %s", name, text);
1129 return;
1130 }
1131 if (!eldbus_message_iter_arguments_get(it, "a{sv}", &array))
1132 {
1133 ERR("Could not get technology aps %p", msg);
1134 return;
1135 }
1136 path = eldbus_pending_path_get(pending);
1137 ns = _networkmanager_service_ap_new(nt->type, path, array);
1138 if (ns) ns->device_proxy = nt->proxy;
1139 _networkmanager_update_networks(nt->type);
1140}
1141
1142static void
1143_networkmanager_manager_getservices(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
1144{
1145 const char *name, *text, *path;
1146 Eldbus_Message_Iter *it, *array;
1147 NetworkManager_Technology *nt = data;
1148 NetworkManager_Service *ns;
1149
1150 pending_technologies = eina_list_remove(pending_technologies, pending);
1151
1152 it = eldbus_message_iter_get(msg);
1153 if (eldbus_message_error_get(msg, &name, &text))
1154 {
1155 ERR("Could not get technology services %s: %s", name, text);
1156 return;
1157 }
1158 if (!eldbus_message_iter_arguments_get(it, "a{sv}", &array))
1159 {
1160 ERR("Could not get technology services %p", msg);
1161 return;
1162 }
1163 path = eldbus_pending_path_get(pending);
1164 ns = _networkmanager_service_new(nt->type, nt->state, path, array);
1165 if (ns) ns->device_proxy = nt->proxy;
1166 _networkmanager_update_networks(nt->type);
1167}
1168
1169static void
1170_networkmanager_manager_gettechnologies_prop_aps(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
1171{
1172 const char *name, *text, *path;
1173 Eldbus_Message_Iter *it, *array;
1174 Eldbus_Object *obj;
1175 Eldbus_Proxy *proxy;
1176 Eldbus_Pending *pend;
1177 NetworkManager_Technology *nt = data;
1178
1179 pending_technologies = eina_list_remove(pending_technologies, pending);
1180
1181 it = eldbus_message_iter_get(msg);
1182 if (eldbus_message_error_get(msg, &name, &text))
1183 {
1184 ERR("Could not get technology aps %s: %s", name, text);
1185 return;
1186 }
1187 if (!eldbus_message_iter_arguments_get(it, "ao", &array))
1188 {
1189 ERR("Could not get technology aps %p", msg);
1190 return;
1191 }
1192 while (eldbus_message_iter_get_and_next(array, 'o', &path))
1193 {
1194 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
1195 proxy = eldbus_proxy_get(obj,
1196 NETWORKMANAGER_BUS_INTERFACE ".AccessPoint");
1197 pend = eldbus_proxy_property_get_all(proxy,
1198 _networkmanager_manager_getaps, nt);
1199 pending_technologies = eina_list_append(pending_technologies, pend);
1200 }
1201}
1202
1203static void
1204_networkmanager_manager_gettechnologies_prop_services(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
1205{
1206 const char *name, *text, *path;
1207 Eldbus_Message_Iter *it, *variant, *array;
1208 Eldbus_Object *obj;
1209 Eldbus_Proxy *proxy;
1210 Eldbus_Pending *pend;
1211 NetworkManager_Technology *nt = data;
1212
1213 pending_technologies = eina_list_remove(pending_technologies, pending);
1214
1215 it = eldbus_message_iter_get(msg);
1216 if (eldbus_message_error_get(msg, &name, &text))
1217 {
1218 ERR("Could not get technology services %s: %s", name, text);
1219 return;
1220 }
1221 if (!eldbus_message_iter_arguments_get(it, "v", &variant))
1222 {
1223 ERR("Could not get technology services %p", msg);
1224 return;
1225 }
1226 if (!eldbus_message_iter_arguments_get(variant, "ao", &array))
1227 {
1228 ERR("Could not get technology services %p", msg);
1229 return;
1230 }
1231 while (eldbus_message_iter_get_and_next(array, 'o', &path))
1232 {
1233 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
1234 proxy = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Settings.Connection");
1235 pend = eldbus_proxy_call(proxy, "GetSettings",
1236 _networkmanager_manager_getservices, nt, -1, "");
1237 pending_technologies = eina_list_append(pending_technologies, pend);
1238 }
1239}
1240
1241static void
1242_networkmanager_manager_gettechnologies_prop_state(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
1243{
1244 const char *name, *text;
1245 Eldbus_Message_Iter *it, *variant;
1246 NetworkManager_Technology *nt = data;
1247 NetworkManager_Service *ns;
1248 int state;
1249
1250 pending_technologies = eina_list_remove(pending_technologies, pending);
1251 it = eldbus_message_iter_get(msg);
1252 if (eldbus_message_error_get(msg, &name, &text))
1253 {
1254 ERR("Could not get technology state %s: %s", name, text);
1255 return;
1256 }
1257 if (!eldbus_message_iter_arguments_get(it, "v", &variant))
1258 {
1259 ERR("Could not get technology state %p", msg);
1260 return;
1261 }
1262 if (!eldbus_message_iter_arguments_get(variant, "u", &state))
1263 {
1264 ERR("Could not get technology state %p", msg);
1265 return;
1266 }
1267 nt->state = state;
1268 if (state < 30)
1269 nt->powered = EINA_FALSE;
1270 else
1271 nt->powered = EINA_TRUE;
1272 if (state == 100)
1273 nt->connected = EINA_TRUE;
1274 else
1275 nt->connected = EINA_FALSE;
1276 _networkmanager_update_technologies();
1277 _networkmanager_update_enabled_technologies();
1278 EINA_INLIST_FOREACH(networkmanager_services_list[nt->type], ns)
1279 _networkmanager_service_state(ns, state);
1280}
1281
1282static void
1283_networkmanager_manager_technology_event_property(void *data, const Eldbus_Message *msg)
1284{
1285 NetworkManager_Technology *nt = data;
1286 NetworkManager_Service *ns;
1287 Eldbus_Message_Iter *it;
1288 int state;
1289
1290 if (pending_getproperties_manager) return;
1291 it = eldbus_message_iter_get(msg);
1292 if (!eldbus_message_iter_arguments_get(it, "u", &state))
1293 {
1294 ERR("Error getting technology state");
1295 return;
1296 }
1297 nt->state = state;
1298 if (state < 30)
1299 nt->powered = EINA_FALSE;
1300 else
1301 nt->powered = EINA_TRUE;
1302 if (state == 100)
1303 nt->connected = EINA_TRUE;
1304 else
1305 nt->connected = EINA_FALSE;
1306 _networkmanager_update_technologies();
1307 _networkmanager_update_enabled_technologies();
1308 EINA_INLIST_FOREACH(networkmanager_services_list[nt->type], ns)
1309 _networkmanager_service_state(ns, state);
1310}
1311
1312static void
1313_networkmanager_manager_gettechnologies(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
1314{
1315 const char *name, *text;
1316 int type;
1317 Eldbus_Proxy *prox = data, *proxy;
1318 Eldbus_Pending *pend = data;
1319 Eldbus_Message_Iter *it, *variant;
1320 NetworkManager_Technology *nt = NULL;
1321
1322 pending_technologies = eina_list_remove(pending_technologies, pending);
1323 it = eldbus_message_iter_get(msg);
1324 if (eldbus_message_error_get(msg, &name, &text))
1325 {
1326 ERR("Could not get technology %s: %s", name, text);
1327 return;
1328 }
1329 if (!eldbus_message_iter_arguments_get(it, "v", &variant))
1330 {
1331 ERR("Could not parse message %p", msg);
1332 return;
1333 }
1334 if (!eldbus_message_iter_arguments_get(variant, "u", &type))
1335 {
1336 ERR("Could not get technology type %p", msg);
1337 return;
1338 }
1339 if (type == 1)
1340 {
1341 DBG("Found Ethernet Technology\n");
1342 nt = &networkmanager_technology[0];
1343 nt->type = NETWORKMANAGER_SERVICE_TYPE_ETHERNET;
1344 }
1345 else if (type == 2)
1346 {
1347 DBG("Found Wireless Technology\n");
1348 nt = &networkmanager_technology[1];
1349 nt->type = NETWORKMANAGER_SERVICE_TYPE_WIFI;
1350 }
1351 else if (type == 5)
1352 {
1353 DBG("Found Bluetooth Technology\n");
1354 nt = &networkmanager_technology[2];
1355 nt->type = NETWORKMANAGER_SERVICE_TYPE_BLUETOOTH;
1356 }
1357 else if (type == 8)
1358 {
1359 DBG("Found Cellular Technology\n");
1360 nt = &networkmanager_technology[3];
1361 nt->type = NETWORKMANAGER_SERVICE_TYPE_CELLULAR;
1362 }
1363 if (!nt)
1364 {
1365 DBG("No handler for technology: %u", type);
1366 return;
1367 }
1368 nt->proxy = prox;
1369
1370 nt->handler = eldbus_proxy_signal_handler_add(nt->proxy, "StateChanged",
1371 _networkmanager_manager_technology_event_property, nt);
1372
1373 pend = eldbus_proxy_property_get(nt->proxy, "State",
1374 _networkmanager_manager_gettechnologies_prop_state, nt);
1375 pending_technologies = eina_list_append(pending_technologies, pend);
1376 pend = eldbus_proxy_property_get(nt->proxy, "AvailableConnections",
1377 _networkmanager_manager_gettechnologies_prop_services, nt);
1378 pending_technologies = eina_list_append(pending_technologies, pend);
1379 if (nt->type == NETWORKMANAGER_SERVICE_TYPE_WIFI)
1380 {
1381 proxy = eldbus_proxy_get(eldbus_proxy_object_get(nt->proxy),
1382 NETWORKMANAGER_BUS_INTERFACE ".Device.Wireless");
1383 pend = eldbus_proxy_call(proxy, "GetAllAccessPoints",
1384 _networkmanager_manager_gettechnologies_prop_aps, nt, -1, "");
1385 pending_technologies = eina_list_append(pending_technologies, pend);
1386 }
1387}
1388
1389static void
1390_networkmanager_manager_getactive_conn(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending)
1391{
1392 const char *name, *text, *conn_path;
1393 Eldbus_Message_Iter *it, *variant;
1394 NetworkManager_Service *ns;
1395 int i;
1396
1397 pending_technologies = eina_list_remove(pending_technologies, pending);
1398 it = eldbus_message_iter_get(msg);
1399 if (eldbus_message_error_get(msg, &name, &text))
1400 {
1401 ERR("Could not get connection_path %s: %s", name, text);
1402 return;
1403 }
1404 if (!eldbus_message_iter_arguments_get(it, "v", &variant))
1405 {
1406 ERR("Could not parse message %p", msg);
1407 return;
1408 }
1409 if (!eldbus_message_iter_arguments_get(variant, "o", &conn_path))
1410 {
1411 ERR("Could not get connection path %p", msg);
1412 return;
1413 }
1414 eina_stringshare_replace(&active_connection, conn_path);
1415 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1416 {
1417 EINA_INLIST_FOREACH(networkmanager_services_list[i], ns)
1418 {
1419 if (ns->access_point) continue;
1420 ns->is_active_connection = EINA_FALSE;
1421 ns->state = NETWORKMANAGER_STATE_IDLE;
1422 if (!ns->path) continue;
1423 if (eina_streq(ns->path, conn_path))
1424 {
1425 ns->is_active_connection = EINA_TRUE;
1426 _networkmanager_service_state(ns, networkmanager_technology[i].state);
1427 }
1428 }
1429 }
1430}
1431
1432static void
1433_networkmanager_manager_getactive(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
1434{
1435 Eldbus_Object *obj;
1436 Eldbus_Proxy *prox;
1437 Eldbus_Pending *pend;
1438 Eldbus_Message_Iter *variant;
1439 const char *name, *text, *conn_path;
1440 int i;
1441 NetworkManager_Service *ns;
1442
1443 pending_getactive = NULL;
1444 if (eldbus_message_error_get(msg, &name, &text))
1445 {
1446 ERR("Could not get active connection. %s: %s", name, text);
1447 return;
1448 }
1449 if (!eldbus_message_arguments_get(msg, "v", &variant))
1450 {
1451 ERR("Error getting connection path");
1452 return;
1453 }
1454 if (!eldbus_message_iter_arguments_get(variant, "o", &conn_path))
1455 {
1456 ERR("Error getting connection path");
1457 return;
1458 }
1459 if (eina_streq(conn_path, "/"))
1460 {
1461 DBG("No active connection present");
1462 eina_stringshare_replace(&active_connection, conn_path);
1463 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1464 {
1465 _networkmanager_update_networks(i);
1466 EINA_INLIST_FOREACH(networkmanager_services_list[i], ns)
1467 {
1468 if (ns->access_point) continue;
1469 if (ns->is_active_connection)
1470 {
1471 ns->is_active_connection = EINA_FALSE;
1472 ns->state = NETWORKMANAGER_STATE_IDLE;
1473 _networkmanager_update_current_network(ns, ns->type);
1474 }
1475 }
1476 _networkmanager_update_networks(i);
1477 }
1478 return;
1479 }
1480 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, conn_path);
1481 prox = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Connection.Active");
1482 pend = eldbus_proxy_property_get(prox, "Connection",
1483 _networkmanager_manager_getactive_conn, NULL);
1484 pending_technologies = eina_list_append(pending_technologies, pend);
1485}
1486
1487static void
1488_networkmanager_manager_getdevices(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
1489{
1490 Eldbus_Message_Iter *array;
1491 const char *name, *text, *path;
1492
1493 pending_getdevices = NULL;
1494 if (eldbus_message_error_get(msg, &name, &text))
1495 {
1496 ERR("Could not get technologies. %s: %s", name, text);
1497 return;
1498 }
1499 if (!eldbus_message_arguments_get(msg, "ao", &array))
1500 {
1501 ERR("Error getting array");
1502 return;
1503 }
1504 while (eldbus_message_iter_get_and_next(array, 'o', &path))
1505 {
1506 Eldbus_Object *obj;
1507 Eldbus_Pending *pend;
1508 Eldbus_Proxy *prox;
1509 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
1510 prox = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Device");
1511 pend = eldbus_proxy_property_get(prox, "DeviceType",
1512 _networkmanager_manager_gettechnologies, prox);
1513 pending_technologies = eina_list_append(pending_technologies, pend);
1514 }
1515}
1516
1517
1518static void
1519_networkmanager_manager_getstate(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
1520{
1521 const char *name, *text;
1522 int state;
1523
1524 pending_getproperties_manager = NULL;
1525 if (eldbus_message_error_get(msg, &name, &text))
1526 {
1527 ERR("Could not get properties. %s: %s", name, text);
1528 }
1529 else if (!eldbus_message_arguments_get(msg, "u", &state))
1530 {
1531 ERR("Could not parse message %p", msg);
1532 }
1533 else
1534 {
1535 DBG("New state: %d\n", state);
1536 //_networkmanager_update_state(str_to_state(state));
1537 //if (state == 10)
1538 //{
1539 //Eina_Bool offline;
1540 //_networkmanager_update_airplane_mode(offline);
1541 //}
1542 }
1543}
1544
1545static void
1546_networkmanager_manager_update_prop(void *data EINA_UNUSED, const void *msg, Eldbus_Message_Iter *it)
1547{
1548 const char *setting = msg;
1549
1550 if (eina_streq(setting, "State"))
1551 {
1552 int state;
1553 if (!eldbus_message_iter_arguments_get(it, "u", &state))
1554 {
1555 ERR("Error getting technology state");
1556 return;
1557 }
1558 DBG("New state: %d\n", state);
1559 //_networkmanager_update_state(str_to_state(state));
1560 //if (state == 10)
1561 //{
1562 //Eina_Bool offline;
1563 //_networkmanager_update_airplane_mode(offline);
1564 //}
1565 }
1566 else if (eina_streq(setting, "PrimaryConnection"))
1567 {
1568 Eldbus_Object *obj;
1569 Eldbus_Pending *pend;
1570 Eldbus_Proxy *prox;
1571 const char *conn_path;
1572 int i;
1573 NetworkManager_Service *ns;
1574
1575 if (!eldbus_message_iter_arguments_get(it, "o", &conn_path))
1576 {
1577 ERR("Error getting connection path");
1578 return;
1579 }
1580 if (eina_streq(conn_path, "/"))
1581 {
1582 DBG("No active connection present");
1583 eina_stringshare_replace(&active_connection, conn_path);
1584 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1585 {
1586 EINA_INLIST_FOREACH(networkmanager_services_list[i], ns)
1587 {
1588 if (ns->access_point) continue;
1589 if (ns->is_active_connection)
1590 {
1591 ns->is_active_connection = EINA_FALSE;
1592 ns->state = NETWORKMANAGER_STATE_IDLE;
1593 }
1594 }
1595 _networkmanager_update_networks(i);
1596 }
1597 return;
1598 }
1599 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, conn_path);
1600 prox = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Connection.Active");
1601 pend = eldbus_proxy_property_get(prox, "Connection",
1602 _networkmanager_manager_getactive_conn, NULL);
1603 pending_technologies = eina_list_append(pending_technologies, pend);
1604 }
1605}
1606
1607static void
1608_networkmanager_manager_event_property(void *data EINA_UNUSED, const Eldbus_Message *msg)
1609{
1610 Eldbus_Message_Iter *var;
1611
1612 if (pending_getproperties_manager) return;
1613 if (!eldbus_message_arguments_get(msg, "a{sv}", &var))
1614 {
1615 ERR("Could not parse property update %p", msg);
1616 return;
1617 }
1618 eldbus_message_iter_dict_iterate(var, "sv", _networkmanager_manager_update_prop, NULL);
1619}
1620
1621static void
1622_networkmanager_services_free(void)
1623{
1624 int i;
1625 NetworkManager_Service *ns;
1626
1627 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1628 {
1629 EINA_INLIST_FOREACH(networkmanager_services_list[i], ns)
1630 _networkmanager_service_free(ns);
1631 }
1632}
1633
1634static void
1635_networkmanager_start(void)
1636{
1637 Eldbus_Object *obj;
1638 int i;
1639
1640 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1641 {
1642 networkmanager_technology[i].type = -1;
1643 networkmanager_technology[i].handler = NULL;
1644 networkmanager_technology[i].proxy = NULL;
1645 }
1646
1647 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, NETWORKMANAGER_BUS_PATH);
1648 proxy_manager = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE);
1649
1650 pending_getproperties_manager =
1651 eldbus_proxy_call(proxy_manager, "state", _networkmanager_manager_getstate,
1652 NULL, -1, "");
1653 pending_getdevices =
1654 eldbus_proxy_call(proxy_manager, "GetDevices", _networkmanager_manager_getdevices,
1655 NULL, -1, "");
1656 pending_getactive =
1657 eldbus_proxy_property_get(proxy_manager, "PrimaryConnection",
1658 _networkmanager_manager_getactive, NULL);
1659
1660 sig_handlers = eina_list_append(sig_handlers,
1661 eldbus_proxy_signal_handler_add(proxy_manager, "PropertiesChanged",
1662 _networkmanager_manager_event_property, NULL));
1663}
1664
1665static void
1666_networkmanager_end(void)
1667{
1668 Eldbus_Pending *pend;
1669 int i;
1670
1671 if (!proxy_manager) return;
1672
1673 EINA_LIST_FREE(pending_technologies, pend)
1674 {
1675 eldbus_pending_cancel(pend);
1676 pend = NULL;
1677 }
1678 _networkmanager_services_free();
1679 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1680 {
1681 if (networkmanager_technology[i].handler)
1682 eldbus_signal_handler_del(networkmanager_technology[i].handler);
1683 if (networkmanager_technology[i].proxy)
1684 _eldbus_proxy_del(networkmanager_technology[i].proxy);
1685 networkmanager_technology[i].proxy = NULL;
1686 }
1687 if (sig_handlers)
1688 eina_list_free(sig_handlers);
1689 eina_stringshare_del(active_connection);
1690 if (pending_getactive)
1691 eldbus_pending_cancel(pending_getactive);
1692 pending_getactive = NULL;
1693 if (pending_getdevices)
1694 eldbus_pending_cancel(pending_getdevices);
1695 pending_getdevices = NULL;
1696 if (pending_getproperties_manager)
1697 eldbus_pending_cancel(pending_getproperties_manager);
1698 pending_getproperties_manager = NULL;
1699
1700 _eldbus_proxy_del(proxy_manager);
1701 proxy_manager = NULL;
1702}
1703
1704static void
1705_networkmanager_name_owner_changed(void *data EINA_UNUSED, const char *bus EINA_UNUSED, const char *from EINA_UNUSED, const char *to)
1706{
1707 if (to[0])
1708 _networkmanager_start();
1709 else
1710 _networkmanager_end();
1711}
1712
1713void
1714networkmanager_init(void)
1715{
1716 if (_networkmanager_log_dom > -1) return;
1717 eldbus_name_owner_changed_callback_add(dbus_conn, NETWORKMANAGER_BUS_NAME,
1718 _networkmanager_name_owner_changed, NULL, EINA_TRUE);
1719 _networkmanager_log_dom = eina_log_domain_register("wireless.networkmanager", EINA_COLOR_ORANGE);
1720}
1721
1722void
1723networkmanager_shutdown(void)
1724{
1725 int i;
1726
1727 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
1728 {
1729 free(networkmanager_current_connection[i]);
1730 networkmanager_current_connection[i] = NULL;
1731 networkmanager_current_service[i] = NULL;
1732 }
1733 _networkmanager_end();
1734 eldbus_name_owner_changed_callback_del(dbus_conn, NETWORKMANAGER_BUS_NAME,
1735 _networkmanager_name_owner_changed, NULL);
1736 eina_log_domain_unregister(_networkmanager_log_dom);
1737 _networkmanager_log_dom = -1;
1738}
diff --git a/src/wireless.c b/src/wireless.c
index 2607ea9..740d187 100644
--- a/src/wireless.c
+++ b/src/wireless.c
@@ -1,9 +1,5 @@
1#include "wireless.h" 1#include "wireless.h"
2 2
3
4/* FIXME */
5void connman_technology_enabled_set(Wireless_Service_Type type, Eina_Bool state);
6
7static const char *wireless_theme_groups[] = 3static const char *wireless_theme_groups[] =
8{ 4{
9 [WIRELESS_SERVICE_TYPE_ETHERNET] = "wireless/ethernet", 5 [WIRELESS_SERVICE_TYPE_ETHERNET] = "wireless/ethernet",
@@ -43,8 +39,8 @@ typedef struct Instance
43 Evas_Object *win; 39 Evas_Object *win;
44 Evas_Object *box; 40 Evas_Object *box;
45 Evas_Object *icon[WIRELESS_SERVICE_TYPE_LAST]; 41 Evas_Object *icon[WIRELESS_SERVICE_TYPE_LAST];
46
47 Eina_Bool popup; 42 Eina_Bool popup;
43 Wireless_Connection_Type connection;
48 44
49 struct 45 struct
50 { 46 {
@@ -66,6 +62,24 @@ typedef struct Wireless_Auth_Popup
66 62
67void connman_init(void); 63void connman_init(void);
68void connman_shutdown(void); 64void connman_shutdown(void);
65void connman_technology_enabled_set(Wireless_Service_Type type, Eina_Bool state);
66void connman_service_remove(const char *path);
67void connman_service_edit(const char *path, Wireless_Connection *wc);
68void connman_service_edit_proxy(const char *path, Wireless_Connection *wc);
69void connman_service_edit_domains(const char *path, Wireless_Connection *wc);
70void connman_service_edit_nameservers(const char *path, Wireless_Connection *wc);
71void connman_service_edit_timeservers(const char *path, Wireless_Connection *wc);
72
73void networkmanager_init(void);
74void networkmanager_shutdown(void);
75void networkmanager_technology_enabled_set(Wireless_Service_Type type, Eina_Bool state);
76void networkmanager_service_remove(const char *path);
77void networkmanager_service_edit(const char *path, Wireless_Connection *wc);
78void networkmanager_service_edit_proxy(const char *path, Wireless_Connection *wc);
79void networkmanager_service_edit_domains(const char *path, Wireless_Connection *wc);
80void networkmanager_service_edit_nameservers(const char *path, Wireless_Connection *wc);
81void networkmanager_service_edit_timeservers(const char *path, Wireless_Connection *wc);
82
69Eldbus_Connection *dbus_conn; 83Eldbus_Connection *dbus_conn;
70Wireless_Config *wireless_config; 84Wireless_Config *wireless_config;
71 85
@@ -93,6 +107,7 @@ static struct
93 Eina_Stringshare *proxy_excludes; 107 Eina_Stringshare *proxy_excludes;
94 Eina_Hash *items; 108 Eina_Hash *items;
95 Eina_List *entries; 109 Eina_List *entries;
110 Wireless_Connection_Type connection;
96 Wireless_Service_Type type; 111 Wireless_Service_Type type;
97} wireless_popup; 112} wireless_popup;
98 113
@@ -112,6 +127,150 @@ static int _wireless_gadget_log_dom = -1;
112static void _wireless_gadget_refresh(); 127static void _wireless_gadget_refresh();
113 128
114static void 129static void
130_connection_init(void)
131{
132 switch (inst->connection)
133 {
134 case WIRELESS_CONNECTION_TYPE_CONNMAN:
135 connman_init();
136 break;
137 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
138 networkmanager_init();
139 break;
140 default:
141 connman_init();
142 }
143}
144
145static void
146_connection_shutdown(void)
147{
148 switch (inst->connection)
149 {
150 case WIRELESS_CONNECTION_TYPE_CONNMAN:
151 connman_shutdown();
152 break;
153 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
154 networkmanager_shutdown();
155 break;
156 default:
157 connman_shutdown();
158 }
159}
160
161static void
162_connection_technology_enabled_set(Wireless_Service_Type type, Eina_Bool state)
163{
164 switch (inst->connection)
165 {
166 case WIRELESS_CONNECTION_TYPE_CONNMAN:
167 connman_technology_enabled_set(type, state);
168 break;
169 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
170 networkmanager_technology_enabled_set(type, state);
171 break;
172 default:
173 connman_technology_enabled_set(type, state);
174 }
175}
176
177static void
178_connection_service_remove(const char *path)
179{
180 switch (inst->connection)
181 {
182 case WIRELESS_CONNECTION_TYPE_CONNMAN:
183 connman_service_remove(path);
184 break;
185 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
186 networkmanager_service_remove(path);
187 break;
188 default:
189 connman_service_remove(path);
190 }
191}
192
193static void
194_connection_service_edit(const char *path, Wireless_Connection *wc)
195{
196 switch (inst->connection)
197 {
198 case WIRELESS_CONNECTION_TYPE_CONNMAN:
199 connman_service_edit(path, wc);
200 break;
201 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
202 networkmanager_service_edit(path, wc);
203 break;
204 default:
205 connman_service_edit(path, wc);
206 }
207}
208
209static void
210_connection_service_edit_proxy(const char *path, Wireless_Connection *wc)
211{
212 switch (inst->connection)
213 {
214 case WIRELESS_CONNECTION_TYPE_CONNMAN:
215 connman_service_edit_proxy(path, wc);
216 break;
217 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
218 networkmanager_service_edit_proxy(path, wc);
219 break;
220 default:
221 connman_service_edit_proxy(path, wc);
222 }
223}
224
225static void
226_connection_service_edit_domains(const char *path, Wireless_Connection *wc)
227{
228 switch (inst->connection)
229 {
230 case WIRELESS_CONNECTION_TYPE_CONNMAN:
231 connman_service_edit_domains(path, wc);
232 break;
233 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
234 networkmanager_service_edit_domains(path, wc);
235 break;
236 default:
237 connman_service_edit_domains(path, wc);
238 }
239}
240
241static void
242_connection_service_edit_nameservers(const char *path, Wireless_Connection *wc)
243{
244 switch (inst->connection)
245 {
246 case WIRELESS_CONNECTION_TYPE_CONNMAN:
247 connman_service_edit_nameservers(path, wc);
248 break;
249 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
250 networkmanager_service_edit_nameservers(path, wc);
251 break;
252 default:
253 connman_service_edit_nameservers(path, wc);
254 }
255}
256
257static void
258_connection_service_edit_timeservers(const char *path, Wireless_Connection *wc)
259{
260 switch (inst->connection)
261 {
262 case WIRELESS_CONNECTION_TYPE_CONNMAN:
263 connman_service_edit_timeservers(path, wc);
264 break;
265 case WIRELESS_CONNECTION_TYPE_NETWORKMANAGER:
266 networkmanager_service_edit_timeservers(path, wc);
267 break;
268 default:
269 connman_service_edit_timeservers(path, wc);
270 }
271}
272
273static void
115_wifi_icon_signal(Evas_Object *icon, int state, int strength) 274_wifi_icon_signal(Evas_Object *icon, int state, int strength)
116{ 275{
117 Edje_Message_Int_Set *msg; 276 Edje_Message_Int_Set *msg;
@@ -168,7 +327,7 @@ _wifi_icon_init(Evas_Object *icon, Wireless_Network *wn, int type)
168static void 327static void
169_wireless_popup_toggle(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) 328_wireless_popup_toggle(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
170{ 329{
171 connman_technology_enabled_set(wireless_popup.type, elm_check_state_get(obj)); 330 _connection_technology_enabled_set(wireless_popup.type, elm_check_state_get(obj));
172} 331}
173 332
174static void 333static void
@@ -407,12 +566,6 @@ _wireless_edit_send()
407{ 566{
408 Eina_Bool basic = EINA_FALSE, proxy = EINA_FALSE; 567 Eina_Bool basic = EINA_FALSE, proxy = EINA_FALSE;
409 568
410 void connman_service_edit(const char *path, Wireless_Connection *wc);
411 void connman_service_edit_proxy(const char *path, Wireless_Connection *wc);
412 void connman_service_edit_domains(const char *path, Wireless_Connection *wc);
413 void connman_service_edit_nameservers(const char *path, Wireless_Connection *wc);
414 void connman_service_edit_timeservers(const char *path, Wireless_Connection *wc);
415
416 if (wireless_edit[0]->method == wireless_edit[1]->method) 569 if (wireless_edit[0]->method == wireless_edit[1]->method)
417 { 570 {
418 if (wireless_edit[1]->ipv6) 571 if (wireless_edit[1]->ipv6)
@@ -447,7 +600,7 @@ _wireless_edit_send()
447 basic = EINA_TRUE; 600 basic = EINA_TRUE;
448 601
449 if (basic) 602 if (basic)
450 connman_service_edit(wireless_edit[1]->wn->path, wireless_edit[1]); 603 _connection_service_edit(wireless_edit[1]->wn->path, wireless_edit[1]);
451 604
452 if (wireless_edit[1]->proxy_type == WIRELESS_PROXY_TYPE_MANUAL) 605 if (wireless_edit[1]->proxy_type == WIRELESS_PROXY_TYPE_MANUAL)
453 { 606 {
@@ -480,7 +633,7 @@ _wireless_edit_send()
480 else 633 else
481 proxy = EINA_TRUE; 634 proxy = EINA_TRUE;
482 if (proxy) 635 if (proxy)
483 connman_service_edit_proxy(wireless_edit[1]->wn->path, wireless_edit[1]); 636 _connection_service_edit_proxy(wireless_edit[1]->wn->path, wireless_edit[1]);
484 637
485 array_clear(wireless_edit[1]->domain_servers); 638 array_clear(wireless_edit[1]->domain_servers);
486 if (wireless_popup.domain_servers) 639 if (wireless_popup.domain_servers)
@@ -493,11 +646,11 @@ _wireless_edit_send()
493 wireless_edit[1]->name_servers = string_to_array(wireless_popup.name_servers); 646 wireless_edit[1]->name_servers = string_to_array(wireless_popup.name_servers);
494 647
495 if (_wireless_array_notequal(wireless_edit[0]->domain_servers, wireless_edit[1]->domain_servers)) 648 if (_wireless_array_notequal(wireless_edit[0]->domain_servers, wireless_edit[1]->domain_servers))
496 connman_service_edit_domains(wireless_edit[1]->wn->path, wireless_edit[1]); 649 _connection_service_edit_domains(wireless_edit[1]->wn->path, wireless_edit[1]);
497 if (_wireless_array_notequal(wireless_edit[0]->name_servers, wireless_edit[1]->name_servers)) 650 if (_wireless_array_notequal(wireless_edit[0]->name_servers, wireless_edit[1]->name_servers))
498 connman_service_edit_nameservers(wireless_edit[1]->wn->path, wireless_edit[1]); 651 _connection_service_edit_nameservers(wireless_edit[1]->wn->path, wireless_edit[1]);
499 if (_wireless_array_notequal(wireless_edit[0]->time_servers, wireless_edit[1]->time_servers)) 652 if (_wireless_array_notequal(wireless_edit[0]->time_servers, wireless_edit[1]->time_servers))
500 connman_service_edit_timeservers(wireless_edit[1]->wn->path, wireless_edit[1]); 653 _connection_service_edit_timeservers(wireless_edit[1]->wn->path, wireless_edit[1]);
501} 654}
502 655
503static void 656static void
@@ -510,8 +663,7 @@ _wireless_edit_send_button()
510static void 663static void
511_wireless_edit_remove() 664_wireless_edit_remove()
512{ 665{
513 void connman_service_remove(const char *path); 666 _connection_service_remove(wireless_edit[1]->wn->path);
514 connman_service_remove(wireless_edit[1]->wn->path);
515 evas_object_del(wireless_edit_popup); 667 evas_object_del(wireless_edit_popup);
516} 668}
517 669
@@ -1023,7 +1175,7 @@ _wireless_gadget_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Ob
1023 for (type = 0; type < WIRELESS_SERVICE_TYPE_LAST; type++) 1175 for (type = 0; type < WIRELESS_SERVICE_TYPE_LAST; type++)
1024 if (obj == inst->icon[type]) 1176 if (obj == inst->icon[type])
1025 break; 1177 break;
1026 if (ev->button == 2) connman_technology_enabled_set(type, !wireless_type_enabled[type]); 1178 if (ev->button == 2) _connection_technology_enabled_set(type, !wireless_type_enabled[type]);
1027 if (ev->button == 3) 1179 if (ev->button == 3)
1028 { 1180 {
1029 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 1181 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
@@ -1043,18 +1195,18 @@ _wireless_gadget_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Ob
1043 ctx = elm_win_add(inst->win, "win", ELM_WIN_POPUP_MENU); 1195 ctx = elm_win_add(inst->win, "win", ELM_WIN_POPUP_MENU);
1044 evas_object_size_hint_weight_set(ctx, .2, .33); 1196 evas_object_size_hint_weight_set(ctx, .2, .33);
1045 1197
1046 tb = elm_table_add(ctx); 1198 tb = elm_box_add(ctx);
1047 evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 1199 evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1048 evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); 1200 evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
1049 1201
1050 wireless_popup.content = list = elm_list_add(ctx); 1202 wireless_popup.content = list = elm_list_add(ctx);
1051 elm_list_mode_set(list, ELM_LIST_EXPAND); 1203 elm_list_mode_set(list, ELM_LIST_COMPRESS);
1052 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 1204 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1053 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); 1205 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1054 _wireless_popup_list_populate(); 1206 _wireless_popup_list_populate();
1055 elm_list_go(list); 1207 elm_list_go(list);
1056 evas_object_show(list); 1208 evas_object_show(list);
1057 elm_table_pack(tb, list, 0, 0, 2, 1); 1209 elm_box_pack_end(tb, list);
1058 toggle = elm_check_add(ctx); 1210 toggle = elm_check_add(ctx);
1059 evas_object_show(toggle); 1211 evas_object_show(toggle);
1060 elm_object_style_set(toggle, "toggle"); 1212 elm_object_style_set(toggle, "toggle");
@@ -1063,7 +1215,7 @@ _wireless_gadget_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Ob
1063 elm_object_part_text_set(toggle, "off", _("Off")); 1215 elm_object_part_text_set(toggle, "off", _("Off"));
1064 elm_check_state_set(toggle, wireless_type_enabled[type]); 1216 elm_check_state_set(toggle, wireless_type_enabled[type]);
1065 evas_object_smart_callback_add(toggle, "changed", _wireless_popup_toggle, inst); 1217 evas_object_smart_callback_add(toggle, "changed", _wireless_popup_toggle, inst);
1066 elm_table_pack(tb, toggle, 0, 1, 2, 1); 1218 elm_box_pack_end(tb, toggle);
1067 wireless_popup.popup = ctx; 1219 wireless_popup.popup = ctx;
1068 1220
1069 //Currently not used due to e internals 1221 //Currently not used due to e internals
@@ -1090,7 +1242,7 @@ _wireless_gadget_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Ob
1090} 1242}
1091 1243
1092static Evas_Object * 1244static Evas_Object *
1093_wireless_tooltip_row(Evas_Object *tb, const char *label, const char *value, int row) 1245_wireless_tooltip_row(Evas_Object *tb, const char *label, const char *value)
1094{ 1246{
1095 Evas_Object *lbl; 1247 Evas_Object *lbl;
1096 1248
@@ -1098,13 +1250,13 @@ _wireless_tooltip_row(Evas_Object *tb, const char *label, const char *value, int
1098 evas_object_show(lbl); 1250 evas_object_show(lbl);
1099 evas_object_size_hint_align_set(lbl, 0, 0.5); 1251 evas_object_size_hint_align_set(lbl, 0, 0.5);
1100 elm_object_text_set(lbl, label); 1252 elm_object_text_set(lbl, label);
1101 elm_table_pack(tb, lbl, 0, row, 1, 1); 1253 elm_box_pack_end(tb, lbl);
1102 1254
1103 lbl = elm_label_add(tb); 1255 lbl = elm_label_add(tb);
1104 evas_object_show(lbl); 1256 evas_object_show(lbl);
1105 evas_object_size_hint_align_set(lbl, 0, 0.5); 1257 evas_object_size_hint_align_set(lbl, 0, 0.5);
1106 elm_object_text_set(lbl, value); 1258 elm_object_text_set(lbl, value);
1107 elm_table_pack(tb, lbl, 1, row, 1, 1); 1259 elm_box_pack_end(tb, lbl);
1108 return lbl; 1260 return lbl;
1109} 1261}
1110 1262
@@ -1128,30 +1280,30 @@ static Evas_Object *
1128_wireless_tooltip(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *tooltip) 1280_wireless_tooltip(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *tooltip)
1129{ 1281{
1130 Evas_Object *tb; 1282 Evas_Object *tb;
1131 int row = 0;
1132 char buf[1024]; 1283 char buf[1024];
1133 int type = WIRELESS_SERVICE_TYPE_WIFI; 1284 int type = WIRELESS_SERVICE_TYPE_WIFI;
1134 1285
1135 if (!wireless_current[type]) 1286 if (!wireless_current[type])
1136 { 1287 {
1137 if (!wireless_type_available[type])//connman not found 1288 if (!wireless_type_available[type])//connection not found
1138 { 1289 {
1139 inst->tooltip.error = elm_label_add(tooltip); 1290 inst->tooltip.error = elm_label_add(tooltip);
1140 elm_object_text_set(inst->tooltip.error, _("Error: Connman not detected!")); 1291 elm_object_text_set(inst->tooltip.error, _("Error: No backend detected!"));
1141 evas_object_event_callback_add(inst->tooltip.error, EVAS_CALLBACK_DEL, _wireless_tooltip_del, inst); 1292 evas_object_event_callback_add(inst->tooltip.error, EVAS_CALLBACK_DEL, _wireless_tooltip_del, inst);
1142 return inst->tooltip.error; 1293 return inst->tooltip.error;
1143 } 1294 }
1144 return NULL; 1295 return NULL;
1145 } 1296 }
1146 tb = elm_table_add(tooltip); 1297 tb = elm_box_add(tooltip);
1147 elm_table_padding_set(tb, 5, 1); 1298 evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1299 evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
1148 1300
1149 _wireless_tooltip_row(tb, _("Name:"), wireless_current[type]->wn->name, row++); 1301 _wireless_tooltip_row(tb, _("Name:"), wireless_current[type]->wn->name);
1150 inst->tooltip.method = _wireless_tooltip_row(tb, _("Method:"), _wireless_tooltip_method_name(), row++); 1302 inst->tooltip.method = _wireless_tooltip_row(tb, _("Method:"), _wireless_tooltip_method_name());
1151 1303
1152 inst->tooltip.address = _wireless_tooltip_row(tb, _("Address:"), wireless_current[type]->address, row++); 1304 inst->tooltip.address = _wireless_tooltip_row(tb, _("Address:"), wireless_current[type]->address);
1153 snprintf(buf, sizeof(buf), "%u%%", wireless_current[type]->wn->strength); 1305 snprintf(buf, sizeof(buf), "%u%%", wireless_current[type]->wn->strength);
1154 inst->tooltip.signal = _wireless_tooltip_row(tb, _("Signal:"), buf, row++); 1306 inst->tooltip.signal = _wireless_tooltip_row(tb, _("Signal:"), buf);
1155 1307
1156 evas_object_event_callback_add(tb, EVAS_CALLBACK_DEL, _wireless_tooltip_del, inst); 1308 evas_object_event_callback_add(tb, EVAS_CALLBACK_DEL, _wireless_tooltip_del, inst);
1157 return tb; 1309 return tb;
@@ -1169,7 +1321,7 @@ wireless_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_
1169 free(inst); 1321 free(inst);
1170 free(wireless_config); 1322 free(wireless_config);
1171 1323
1172 connman_shutdown(); 1324 _connection_shutdown();
1173 eldbus_connection_unref(dbus_conn); 1325 eldbus_connection_unref(dbus_conn);
1174 eina_log_domain_unregister(_wireless_gadget_log_dom); 1326 eina_log_domain_unregister(_wireless_gadget_log_dom);
1175 _wireless_gadget_log_dom = -1; 1327 _wireless_gadget_log_dom = -1;
@@ -1189,9 +1341,11 @@ _wireless_gadget_icon_add(int type)
1189 elm_layout_file_set(g, elm_theme_group_path_find(NULL, wireless_theme_groups[type]), 1341 elm_layout_file_set(g, elm_theme_group_path_find(NULL, wireless_theme_groups[type]),
1190 wireless_theme_groups[type]); 1342 wireless_theme_groups[type]);
1191 elm_object_tooltip_content_cb_set(g, _wireless_tooltip, inst, NULL); 1343 elm_object_tooltip_content_cb_set(g, _wireless_tooltip, inst, NULL);
1344 //elm_object_tooltip_window_mode_set(g, EINA_TRUE);
1192 evas_object_event_callback_add(g, EVAS_CALLBACK_MOUSE_DOWN, _wireless_gadget_mouse_down, inst); 1345 evas_object_event_callback_add(g, EVAS_CALLBACK_MOUSE_DOWN, _wireless_gadget_mouse_down, inst);
1193 } 1346 }
1194 DBG("Updating icon for %d", type); 1347 DBG("Updating icon for %d", type);
1348 if (wireless_current[type] && wireless_current[type]->wn)
1195 _wifi_icon_init(inst->icon[type], wireless_current[type] ? wireless_current[type]->wn : NULL, type); 1349 _wifi_icon_init(inst->icon[type], wireless_current[type] ? wireless_current[type]->wn : NULL, type);
1196 evas_object_hide(inst->icon[type]); 1350 evas_object_hide(inst->icon[type]);
1197} 1351}
@@ -1279,16 +1433,20 @@ main(int argc, char *argv[])
1279 elm_init(argc, (char **)argv); 1433 elm_init(argc, (char **)argv);
1280 elm_theme_extension_add(NULL, THEMEDIR "/wireless.edj"); 1434 elm_theme_extension_add(NULL, THEMEDIR "/wireless.edj");
1281 _wireless_gadget_log_dom = eina_log_domain_register("wireless", EINA_COLOR_CYAN); 1435 _wireless_gadget_log_dom = eina_log_domain_register("wireless", EINA_COLOR_CYAN);
1436
1282 dbus_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM); 1437 dbus_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
1283 connman_init();
1284 1438
1285 wireless_config = calloc(1, sizeof(Wireless_Config)); 1439 wireless_config = calloc(1, sizeof(Wireless_Config));
1286 inst = calloc(1, sizeof(Instance)); 1440 inst = calloc(1, sizeof(Instance));
1287 snprintf(id, sizeof(id), "%s", getenv("E_GADGET_ID")); 1441 snprintf(id, sizeof(id), "%s", getenv("E_GADGET_ID"));
1288 inst->id = atoi(id); 1442 inst->id = atoi(id);
1443// inst->connection = WIRELESS_CONNECTION_TYPE_NETWORKMANAGER;
1444 inst->connection = WIRELESS_CONNECTION_TYPE_CONNMAN;
1289 inst->orient = E_GADGET_SITE_ORIENT_NONE; 1445 inst->orient = E_GADGET_SITE_ORIENT_NONE;
1290 wireless_popup.type = inst->tooltip.type = -1; 1446 wireless_popup.type = inst->tooltip.type = -1;
1291 1447
1448 _connection_init();
1449
1292 inst->win = elm_win_add(NULL, "wireless", ELM_WIN_BASIC); 1450 inst->win = elm_win_add(NULL, "wireless", ELM_WIN_BASIC);
1293 evas_object_size_hint_min_set(inst->win, 100, 100); 1451 evas_object_size_hint_min_set(inst->win, 100, 100);
1294 evas_object_size_hint_aspect_set(inst->win, EVAS_ASPECT_CONTROL_BOTH, 1, 1); 1452 evas_object_size_hint_aspect_set(inst->win, EVAS_ASPECT_CONTROL_BOTH, 1, 1);
@@ -1670,3 +1828,4 @@ wireless_authenticate_external(Wireless_Network *wn, const char *url)
1670 evas_object_show(ctx); 1828 evas_object_show(ctx);
1671 auth_popup = 1; 1829 auth_popup = 1;
1672} 1830}
1831
diff --git a/src/wireless.h b/src/wireless.h
index d81d3c5..6bef66c 100644
--- a/src/wireless.h
+++ b/src/wireless.h
@@ -4,6 +4,7 @@
4#include <Elementary.h> 4#include <Elementary.h>
5#include <e_gadget_types.h> 5#include <e_gadget_types.h>
6#include "config.h" 6#include "config.h"
7#include <arpa/inet.h>
7 8
8#define _(str) (str) 9#define _(str) (str)
9#define d_(str, dom) (str) 10#define d_(str, dom) (str)
@@ -14,6 +15,13 @@
14 15
15typedef enum 16typedef enum
16{ 17{
18 WIRELESS_CONNECTION_TYPE_NONE = -1,
19 WIRELESS_CONNECTION_TYPE_CONNMAN,
20 WIRELESS_CONNECTION_TYPE_NETWORKMANAGER,
21} Wireless_Connection_Type;
22
23typedef enum
24{
17 WIRELESS_SERVICE_TYPE_NONE = -1, 25 WIRELESS_SERVICE_TYPE_NONE = -1,
18 WIRELESS_SERVICE_TYPE_ETHERNET, 26 WIRELESS_SERVICE_TYPE_ETHERNET,
19 WIRELESS_SERVICE_TYPE_WIFI, 27 WIRELESS_SERVICE_TYPE_WIFI,