profile name_set
[framework/uifw/edbus.git] / src / bin / e_dbus_connman_test.c
1 #include "E_Connman.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <errno.h>
6
7 static void
8 _elements_print(E_Connman_Element **elements, int count)
9 {
10    int i;
11    for (i = 0; i < count; i++)
12      {
13         printf("--- element %d:\n", i);
14         e_connman_element_print(stdout, elements[i]);
15      }
16    free(elements);
17    printf("END: all elements count = %d\n", count);
18 }
19
20 static int
21 _on_element_add(void *data, int type, void *info)
22 {
23    E_Connman_Element *element = info;
24    printf(">>> %s\n", element->path);
25    return 1;
26 }
27
28 static int
29 _on_element_del(void *data, int type, void *info)
30 {
31    E_Connman_Element *element = info;
32    printf("<<< %s\n", element->path);
33    return 1;
34 }
35
36 static int
37 _on_element_updated(void *data, int type, void *info)
38 {
39    E_Connman_Element *element = info;
40    printf("!!! %s\n", element->path);
41    e_connman_element_print(stderr, element);
42    return 1;
43 }
44
45 static int
46 _on_cmd_quit(char *cmd, char *args)
47 {
48    fputs("Bye!\n", stderr);
49    ecore_main_loop_quit();
50    return 0;
51 }
52
53 static int
54 _on_cmd_sync(char *cmd, char *args)
55 {
56    e_connman_manager_sync_elements();
57    return 1;
58 }
59
60 static char *
61 _tok(char *p)
62 {
63    p = strchr(p, ' ');
64    if (!p)
65      return NULL;
66
67    *p = '\0';
68    p++;
69    while (isspace(*p))
70      p++;
71    if (*p == '\0')
72      return NULL;
73
74    return p;
75 }
76
77 static int
78 _on_cmd_get_all(char *cmd, char *args)
79 {
80    E_Connman_Element **elements;
81    char *type;
82    unsigned int count;
83    bool ret;
84
85    if (!args)
86      type = NULL;
87    else
88      type = args;
89
90    if (type)
91      ret = e_connman_elements_get_all_type(type, &count, &elements);
92    else
93      ret = e_connman_elements_get_all(&count, &elements);
94
95    if (!ret)
96      fputs("ERROR: could not get elements\n", stderr);
97    else
98      {
99         printf("BEG: all elements type=%s count = %d\n", type, count);
100         _elements_print(elements, count);
101      }
102
103    return 1;
104 }
105
106 static E_Connman_Element *
107 _element_from_args(char *args, char **next_args)
108 {
109    E_Connman_Element *element;
110
111    if (!args)
112      {
113         fputs("ERROR: missing element path\n", stderr);
114         *next_args = NULL;
115         return NULL;
116      }
117
118    *next_args = _tok(args);
119    element = e_connman_element_get(args);
120    if (!element)
121      fprintf(stderr, "ERROR: no element called \"%s\".\n", args);
122
123    return element;
124 }
125
126 static int
127 _on_cmd_print(char *cmd, char *args)
128 {
129    char *next_args;
130    E_Connman_Element *element = _element_from_args(args, &next_args);
131    if (element)
132      e_connman_element_print(stdout, element);
133    return 1;
134 }
135
136 static int
137 _on_cmd_get_properties(char *cmd, char *args)
138 {
139    char *next_args;
140    E_Connman_Element *element = _element_from_args(args, &next_args);
141    if (element)
142      e_connman_element_properties_sync(element);
143    return 1;
144 }
145
146 static int
147 _on_cmd_property_set(char *cmd, char *args)
148 {
149    char *next_args, *name, *p;
150    E_Connman_Element *element = _element_from_args(args, &next_args);
151    void *value;
152    long vlong;
153    unsigned short vu16;
154    unsigned int vu32;
155    int type;
156
157    if (!element)
158      return 1;
159
160    if (!next_args)
161      {
162         fputs("ERROR: missing parameters name, type and value.\n", stderr);
163         return 1;
164      }
165
166    name = next_args;
167    p = _tok(name);
168    if (!p)
169      {
170         fputs("ERROR: missing parameters type and value.\n", stderr);
171         return 1;
172      }
173
174    next_args = _tok(p);
175    if (!next_args)
176      {
177         fputs("ERROR: missing parameter value.\n", stderr);
178         return 1;
179      }
180
181    type = p[0];
182    switch (type)
183      {
184       case DBUS_TYPE_BOOLEAN:
185          vlong = !!atol(next_args);
186          value = (void *)vlong;
187          fprintf(stderr, "DBG: boolean is: %ld\n", vlong);
188          break;
189       case DBUS_TYPE_UINT16:
190          vu16 = strtol(next_args, &p, 0);
191          if (p == next_args)
192            {
193               fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
194               return 1;
195            }
196          value = &vu16;
197          fprintf(stderr, "DBG: u16 is: %hu\n", vu16);
198          break;
199       case DBUS_TYPE_UINT32:
200          vu32 = strtol(next_args, &p, 0);
201          if (p == next_args)
202            {
203               fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
204               return 1;
205            }
206          value = &vu32;
207          fprintf(stderr, "DBG: u16 is: %u\n", vu32);
208          break;
209       case DBUS_TYPE_STRING:
210       case DBUS_TYPE_OBJECT_PATH:
211          p = next_args + strlen(next_args);
212          if (p > next_args)
213            p--;
214          while (p > next_args && isspace(*p))
215            p--;
216          if (p <= next_args)
217            {
218               fprintf(stderr, "ERROR: invalid string \"%s\".\n", next_args);
219            }
220          p[1] = '\0';
221          value = next_args;
222          fprintf(stderr, "DBG: string is: \"%s\"\n", next_args);
223          break;
224       default:
225          fprintf(stderr, "ERROR: don't know how to parse type '%c' (%d)\n",
226                  type, type);
227          return 1;
228      }
229
230    fprintf(stderr, "set_property %s [%p] %s %c %p...\n",
231            args, element, name, type, value);
232    if (!e_connman_element_property_set(element, name, type, value))
233      {
234         fputs("ERROR: error setting property.\n", stderr);
235         return 1;
236      }
237    return 1;
238 }
239
240
241 /* Manager Commands */
242
243 static int
244 _on_cmd_manager_get(char *cmd, char *args)
245 {
246    E_Connman_Element *element;
247    element = e_connman_manager_get();
248    e_connman_element_print(stderr, element);
249    return 1;
250 }
251
252 static int
253 _on_cmd_manager_get_profiles(char *cmd, char *args)
254 {
255    unsigned int count;
256    E_Connman_Element **profiles;
257
258    if (!e_connman_manager_profiles_get(&count, &profiles))
259      {
260         fputs("ERROR: can't get profiles\n", stderr);
261         return 1;
262      }
263    printf("BEG: all manager profiles elements count = %d\n", count);
264    _elements_print(profiles, count);
265    return 1;
266 }
267
268 static int
269 _on_cmd_manager_get_devices(char *cmd, char *args)
270 {
271    unsigned int count;
272    E_Connman_Element **devices;
273
274    if (!e_connman_manager_devices_get(&count, &devices))
275      {
276         fputs("ERROR: can't get devices\n", stderr);
277         return 1;
278      }
279    printf("BEG: all manager devices elements count = %d\n", count);
280    _elements_print(devices, count);
281    return 1;
282 }
283
284 static int
285 _on_cmd_manager_get_services(char *cmd, char *args)
286 {
287    unsigned int count;
288    E_Connman_Element **services;
289
290    if (!e_connman_manager_services_get(&count, &services))
291      {
292         fputs("ERROR: can't get services\n", stderr);
293         return 1;
294      }
295    printf("BEG: all manager services elements count = %d\n", count);
296    _elements_print(services, count);
297    return 1;
298 }
299
300 static int
301 _on_cmd_manager_register_agent(char *cmd, char *args)
302 {
303    char *path;
304
305    if (!args)
306      {
307         fputs("ERROR: missing the object path\n", stderr);
308         return 1;
309      }
310
311    path = args;
312    if (e_connman_manager_agent_register(path, NULL, NULL))
313      printf(":::Registering agent %s...\n", path);
314    else
315      fprintf(stderr, "ERROR: can't register agent %s\n", path);
316
317    return 1;
318 }
319
320 static int
321 _on_cmd_manager_unregister_agent(char *cmd, char *args)
322 {
323    char *path;
324
325    if (!args)
326      {
327         fputs("ERROR: missing the object path\n", stderr);
328         return 1;
329      }
330
331    path = args;
332    if (e_connman_manager_agent_unregister(path, NULL, NULL))
333      printf(":::Unregistering agent %s...\n", path);
334    else
335      fprintf(stderr, "ERROR: can't unregister agent %s\n", path);
336
337    return 1;
338 }
339
340 static int
341 _on_cmd_manager_get_state(char *cmd, char *args)
342 {
343    const char *state;
344    if (e_connman_manager_state_get(&state))
345      printf(":::Manager state = \"%s\"\n", state);
346    else
347      fputs("ERROR: can't get manager state\n", stderr);
348    return 1;
349 }
350
351 static int
352 _on_cmd_manager_get_offline_mode(char *cmd, char *args)
353 {
354    bool offline;
355    if (e_connman_manager_offline_mode_get(&offline))
356      printf(":::Manager Offline Mode = %hhu\n", offline);
357    else
358      fputs("ERROR: can't get manager offline mode\n", stderr);
359    return 1;
360 }
361
362 static int
363 _on_cmd_manager_set_offline_mode(char *cmd, char *args)
364 {
365    bool offline;
366    if (!args)
367      {
368         fputs("ERROR: missing the offline mode value\n", stderr);
369         return 1;
370      }
371    _tok(args);
372    offline = !!atol(args);
373    if (e_connman_manager_offline_mode_set(offline, NULL, NULL))
374      printf(":::Manager Offline Mode set to %hhu\n", offline);
375    else
376      fputs("ERROR: can't set manager offline mode\n", stderr);
377    return 1;
378 }
379
380 /* Device Commands */
381 static int
382 _on_cmd_device_propose_scan(char *cmd, char *args)
383 {
384    char *path;
385    E_Connman_Element *e;
386
387    if (!args)
388      {
389         fputs("ERROR: missing the device path\n", stderr);
390         return 1;
391      }
392    _tok(args);
393    path = args;
394
395    e = e_connman_device_get(path);
396    if (e_connman_device_propose_scan(e, NULL, NULL))
397      printf(":::Proposing scan %s...\n", path);
398    else
399      fputs("ERROR: can't propose scan\n", stderr);
400    return 1;
401 }
402
403 static int
404 _on_cmd_device_get_address(char *cmd, char *args)
405 {
406    const char *address, *path;
407    E_Connman_Element *e;
408
409    if (!args)
410      {
411         fputs("ERROR: missing the device path\n", stderr);
412         return 1;
413      }
414    _tok(args);
415    path = args;
416
417    e = e_connman_device_get(path);
418    if (e_connman_device_address_get(e, &address))
419      printf(":::Device %s Address = \"%s\"\n", path, address);
420    else
421      fputs("ERROR: can't get device address\n", stderr);
422    return 1;
423 }
424
425 static int
426 _on_cmd_device_get_name(char *cmd, char *args)
427 {
428    const char *name, *path;
429    E_Connman_Element *e;
430
431    if (!args)
432      {
433         fputs("ERROR: missing the device path\n", stderr);
434         return 1;
435      }
436    _tok(args);
437    path = args;
438
439    e = e_connman_device_get(path);
440    if (e_connman_device_name_get(e, &name))
441      printf(":::Device %s Name = \"%s\"\n", path, name);
442    else
443      fputs("ERROR: can't get device name\n", stderr);
444    return 1;
445 }
446
447 static int
448 _on_cmd_device_get_type(char *cmd, char *args)
449 {
450    const char *type, *path;
451    E_Connman_Element *e;
452
453    if (!args)
454      {
455         fputs("ERROR: missing the device path\n", stderr);
456         return 1;
457      }
458    _tok(args);
459    path = args;
460
461    e = e_connman_device_get(path);
462    if (e_connman_device_type_get(e, &type))
463      printf(":::Device %s Type = \"%s\"\n", path, type);
464    else
465      fputs("ERROR: can't get device type\n", stderr);
466    return 1;
467 }
468
469 static int
470 _on_cmd_device_get_interface(char *cmd, char *args)
471 {
472    const char *interface, *path;
473    E_Connman_Element *e;
474
475    if (!args)
476      {
477         fputs("ERROR: missing the device path\n", stderr);
478         return 1;
479      }
480    _tok(args);
481    path = args;
482
483    e = e_connman_device_get(path);
484    if (e_connman_device_interface_get(e, &interface))
485      printf(":::Device %s Interface = \"%s\"\n", path, interface);
486    else
487      fputs("ERROR: can't get device interface\n", stderr);
488    return 1;
489 }
490
491 static int
492 _on_cmd_device_get_powered(char *cmd, char *args)
493 {
494    char *path;
495    bool powered;
496    E_Connman_Element *e;
497
498    if (!args)
499      {
500         fputs("ERROR: missing the device path\n", stderr);
501         return 1;
502      }
503    _tok(args);
504    path = args;
505
506    e = e_connman_device_get(path);
507    if (e_connman_device_powered_get(e, &powered))
508      printf(":::Device %s Powered = %hhu\n", path, powered);
509    else
510      fputs("ERROR: can't get device powered\n", stderr);
511    return 1;
512 }
513
514 static int
515 _on_cmd_device_set_powered(char *cmd, char *args)
516 {
517    char *device_path, *next_args;
518    bool powered;
519    E_Connman_Element *e;
520
521    if (!args)
522      {
523         fputs("ERROR: missing the device path\n", stderr);
524         return 1;
525      }
526    device_path = args;
527    next_args = _tok(args);
528    if (!next_args)
529      {
530         fputs("ERROR: missing the powered value\n", stderr);
531         return 1;
532      }
533    powered = !!atol(next_args);
534
535    e = e_connman_device_get(device_path);
536    if (e_connman_device_powered_set(e, powered, NULL, NULL))
537      printf(":::Device %s powered set to %hhu\n", device_path, powered);
538    else
539      fputs("ERROR: can't set device powered\n", stderr);
540    return 1;
541 }
542
543 static int
544 _on_cmd_device_get_scan_interval(char *cmd, char *args)
545 {
546    char *path;
547    unsigned short scan_interval;
548    E_Connman_Element *e;
549
550    if (!args)
551      {
552         fputs("ERROR: missing the device path\n", stderr);
553         return 1;
554      }
555    _tok(args);
556    path = args;
557
558    e = e_connman_device_get(path);
559    if (e_connman_device_scan_interval_get(e, &scan_interval))
560      printf(":::Device %s ScanInterval = %hu\n", path, scan_interval);
561    else
562      fputs("ERROR: can't get device scan interval\n", stderr);
563    return 1;
564 }
565
566 static int
567 _on_cmd_device_set_scan_interval(char *cmd, char *args)
568 {
569    char *device_path, *next_args, *p;
570    unsigned short scan_interval;
571    E_Connman_Element *e;
572
573    if (!args)
574      {
575         fputs("ERROR: missing the device path\n", stderr);
576         return 1;
577      }
578    device_path = args;
579    next_args = _tok(args);
580    if (!next_args)
581      {
582         fputs("ERROR: missing the scan interval value\n", stderr);
583         return 1;
584      }
585    scan_interval = strtol(next_args, &p, 0);
586    if (p == next_args)
587      {
588         fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
589         return 1;
590      }
591
592    e = e_connman_device_get(device_path);
593    if (e_connman_device_scan_interval_set(e, scan_interval, NULL, NULL))
594      printf(":::Device %s scan interval set to %hu\n", device_path, scan_interval);
595    else
596      fputs("ERROR: can't set device scan interval\n", stderr);
597    return 1;
598 }
599
600 static int
601 _on_cmd_device_get_scanning(char *cmd, char *args)
602 {
603    char *path;
604    bool scanning;
605    E_Connman_Element *e;
606
607    if (!args)
608      {
609         fputs("ERROR: missing the device path\n", stderr);
610         return 1;
611      }
612    _tok(args);
613    path = args;
614
615    e = e_connman_device_get(path);
616    if (e_connman_device_scanning_get(e, &scanning))
617      printf(":::Device %s Scanning = %hhu\n", path, scanning);
618    else
619      fputs("ERROR: can't get device scanning\n", stderr);
620    return 1;
621 }
622
623 static int
624 _on_cmd_device_get_networks(char *cmd, char *args)
625 {
626    E_Connman_Element **networks;
627    unsigned int count;
628    char *path;
629    E_Connman_Element *e;
630
631    if (!args)
632      {
633         fputs("ERROR: missing the device path\n", stderr);
634         return 1;
635      }
636    _tok(args);
637    path = args;
638
639    e = e_connman_device_get(path);
640    if (!e_connman_device_networks_get(e, &count, &networks))
641      {
642         fputs("ERROR: can't get networks\n", stderr);
643         return 1;
644      }
645
646    printf("BEG: all device network elements count = %d\n", count);
647    _elements_print(networks, count);
648    return 1;
649 }
650
651 /* Profile Commands */
652
653 static int
654 _on_cmd_profile_get_name(char *cmd, char *args)
655 {
656    const char *name, *path;
657    E_Connman_Element *e;
658
659    if (!args)
660      {
661         fputs("ERROR: missing the profile path\n", stderr);
662         return 1;
663      }
664    _tok(args);
665    path = args;
666
667    e = e_connman_profile_get(path);
668    if (e_connman_profile_name_get(e, &name))
669      printf(":::Profile %s Name = \"%s\"\n", path, name);
670    else
671      fputs("ERROR: can't get profile name\n", stderr);
672    return 1;
673 }
674
675 static int
676 _on_cmd_profile_set_name(char *cmd, char *args)
677 {
678    char *path, *next_args;
679    E_Connman_Element *e;
680
681    if (!args)
682      {
683         fputs("ERROR: missing the profile path\n", stderr);
684         return 1;
685      }
686    path = args;
687    next_args = _tok(args);
688    if (!next_args)
689      {
690         fputs("ERROR: missing the offline mode value\n", stderr);
691         return 1;
692      }
693    _tok(next_args);
694
695    e = e_connman_profile_get(path);
696    if (e_connman_profile_name_set(e, next_args, NULL, NULL))
697      printf(":::Profile %s Name set to %hhu\n", path, next_args);
698    else
699      fputs("ERROR: can't set profile name\n", stderr);
700    return 1;
701 }
702
703 static int
704 _on_cmd_profile_get_offline_mode(char *cmd, char *args)
705 {
706    char *path;
707    bool offline;
708    E_Connman_Element *e;
709
710    if (!args)
711      {
712         fputs("ERROR: missing the profile path\n", stderr);
713         return 1;
714      }
715    _tok(args);
716    path = args;
717
718    e = e_connman_profile_get(path);
719    if (e_connman_profile_offline_mode_get(e, &offline))
720      printf(":::Profile  %s Offline Mode = %hhu\n", path, offline);
721    else
722      fputs("ERROR: can't get profile offline mode\n", stderr);
723    return 1;
724 }
725
726 static int
727 _on_cmd_profile_set_offline_mode(char *cmd, char *args)
728 {
729    char *path, *next_args;
730    bool offline;
731    E_Connman_Element *e;
732
733    if (!args)
734      {
735         fputs("ERROR: missing the profile path\n", stderr);
736         return 1;
737      }
738    path = args;
739    next_args = _tok(args);
740    if (!next_args)
741      {
742         fputs("ERROR: missing the offline mode value\n", stderr);
743         return 1;
744      }
745    _tok(next_args);
746    offline = !!atol(next_args);
747
748    e = e_connman_profile_get(path);
749    if (e_connman_profile_offline_mode_set(e, offline, NULL, NULL))
750      printf(":::Profile %s Offline Mode set to %hhu\n", path, offline);
751    else
752      fputs("ERROR: can't set profile offline mode\n", stderr);
753    return 1;
754 }
755
756 static int
757 _on_cmd_profile_get_services(char *cmd, char *args)
758 {
759    E_Connman_Element **services;
760    E_Connman_Element *e;
761    unsigned int count;
762    char *path;
763
764    if (!args)
765      {
766         fputs("ERROR: missing the profile path\n", stderr);
767         return 1;
768      }
769    _tok(args);
770    path = args;
771
772    e = e_connman_profile_get(path);
773    if (!e_connman_profile_services_get(e, &count, &services))
774      {
775         fputs("ERROR: can't get services\n", stderr);
776         return 1;
777      }
778    printf("BEG: all profile services count = %d\n", count);
779    _elements_print(services, count);
780    return 1;
781 }
782
783
784 /* Network Commands */
785
786 static int
787 _on_cmd_network_get_address(char *cmd, char *args)
788 {
789    const char *address, *path;
790    E_Connman_Element *e;
791
792    if (!args)
793      {
794         fputs("ERROR: missing the network path\n", stderr);
795         return 1;
796      }
797    _tok(args);
798    path = args;
799
800    e = e_connman_network_get(path);
801    if (e_connman_network_address_get(e, &address))
802      printf(":::Network %s Address = \"%s\"\n", path, address);
803    else
804      fputs("ERROR: can't get network address\n", stderr);
805    return 1;
806 }
807
808 static int
809 _on_cmd_network_get_name(char *cmd, char *args)
810 {
811    const char *name, *path;
812    E_Connman_Element *e;
813
814    if (!args)
815      {
816         fputs("ERROR: missing the network path\n", stderr);
817         return 1;
818      }
819    _tok(args);
820    path = args;
821
822    e = e_connman_network_get(path);
823    if (e_connman_network_name_get(e, &name))
824      printf(":::Network %s Name = \"%s\"\n", path, name);
825    else
826      fputs("ERROR: can't get network name\n", stderr);
827    return 1;
828 }
829
830 static int
831 _on_cmd_network_get_connected(char *cmd, char *args)
832 {
833    char *path;
834    bool connected;
835    E_Connman_Element *e;
836
837    if (!args)
838      {
839         fputs("ERROR: missing the network path\n", stderr);
840         return 1;
841      }
842    _tok(args);
843    path = args;
844
845    e = e_connman_network_get(path);
846    if (e_connman_network_connected_get(e, &connected))
847      printf(":::Network %s Connected = %hhu\n", path, connected);
848    else
849      fputs("ERROR: can't get network connected\n", stderr);
850    return 1;
851 }
852
853 static int
854 _on_cmd_network_get_strength(char *cmd, char *args)
855 {
856    char *path;
857    unsigned char strength;
858    E_Connman_Element *e;
859
860    if (!args)
861      {
862         fputs("ERROR: missing the network path\n", stderr);
863         return 1;
864      }
865    _tok(args);
866    path = args;
867
868    e = e_connman_network_get(path);
869    if (e_connman_network_strength_get(e, &strength))
870      printf(":::Network %s Strength = %#02hhx (%d)\n", path, strength, strength);
871    else
872      fputs("ERROR: can't get network strength\n", stderr);
873    return 1;
874 }
875
876 static int
877 _on_cmd_network_get_frequency(char *cmd, char *args)
878 {
879    char *path;
880    unsigned short frequency;
881    E_Connman_Element *e;
882
883    if (!args)
884      {
885         fputs("ERROR: missing the network path\n", stderr);
886         return 1;
887      }
888    _tok(args);
889    path = args;
890
891    e = e_connman_network_get(path);
892    if (e_connman_network_frequency_get(e, &frequency))
893      printf(":::Network %s Frequency = %#04hx (%d)\n", path, frequency, frequency);
894    else
895      fputs("ERROR: can't get network frequency\n", stderr);
896    return 1;
897 }
898
899 static int
900 _on_cmd_network_get_device(char *cmd, char *args)
901 {
902    E_Connman_Element *e, *device;
903    char *path;
904
905    if (!args)
906      {
907         fputs("ERROR: missing the network path\n", stderr);
908         return 1;
909      }
910    _tok(args);
911    path = args;
912
913    e = e_connman_network_get(path);
914    if (!e_connman_network_device_get(e, &device))
915      fputs("ERROR: can't get network device\n", stderr);
916    else
917      e_connman_element_print(stderr, device);
918    return 1;
919 }
920
921 static int
922 _on_cmd_network_get_wifi_ssid(char *cmd, char *args)
923 {
924    unsigned char *bytes;
925    char *path;
926    unsigned int i, count;
927    E_Connman_Element *e;
928
929    if (!args)
930      {
931         fputs("ERROR: missing the network path\n", stderr);
932         return 1;
933      }
934    _tok(args);
935    path = args;
936
937    e = e_connman_network_get(path);
938    if (e_connman_network_wifi_ssid_get(e, &count, &bytes))
939      {
940         printf(":::Network %s Wifi SSID = ", path);
941         for (i = 0; i < count; i++)
942           printf("%#02hhx (\"%c\"), ", bytes[i], bytes[i]);
943         printf("\n");
944      }
945    else
946      fputs("ERROR: can't get network wifi ssid\n", stderr);
947    return 1;
948 }
949
950 static int
951 _on_cmd_network_get_wifi_mode(char *cmd, char *args)
952 {
953    const char *wifi_mode, *path;
954    E_Connman_Element *e;
955
956    if (!args)
957      {
958         fputs("ERROR: missing the network path\n", stderr);
959         return 1;
960      }
961    _tok(args);
962    path = args;
963
964    e = e_connman_network_get(path);
965    if (e_connman_network_wifi_mode_get(e, &wifi_mode))
966      printf(":::Network %s Wifi Mode = \"%s\"\n", path, wifi_mode);
967    else
968      fputs("ERROR: can't get network wifi mode\n", stderr);
969    return 1;
970 }
971
972 static int
973 _on_cmd_network_get_wifi_security(char *cmd, char *args)
974 {
975    const char *wifi_security, *path;
976    E_Connman_Element *e;
977
978    if (!args)
979      {
980         fputs("ERROR: missing the network path\n", stderr);
981         return 1;
982      }
983    _tok(args);
984    path = args;
985
986    e = e_connman_network_get(path);
987    if (e_connman_network_wifi_security_get(e, &wifi_security))
988      printf(":::Network %s Wifi Security = \"%s\"\n", path, wifi_security);
989    else
990      fputs("ERROR: can't get network wifi security\n", stderr);
991    return 1;
992 }
993
994 static int
995 _on_cmd_network_get_wifi_passphrase(char *cmd, char *args)
996 {
997    const char *wifi_passphrase, *path;
998    E_Connman_Element *e;
999
1000    if (!args)
1001      {
1002         fputs("ERROR: missing the network path\n", stderr);
1003         return 1;
1004      }
1005    _tok(args);
1006    path = args;
1007
1008    e = e_connman_network_get(path);
1009    if (e_connman_network_wifi_passphrase_get(e, &wifi_passphrase))
1010      printf(":::Network %s Wifi Passphrase = \"%s\"\n", path, wifi_passphrase);
1011    else
1012      fputs("ERROR: can't get network wifi passphrase\n", stderr);
1013    return 1;
1014 }
1015
1016 static int
1017 _on_cmd_network_get_wifi_channel(char *cmd, char *args)
1018 {
1019    char *path;
1020    E_Connman_Element *e;
1021    unsigned short wifi_channel;
1022
1023    if (!args)
1024      {
1025         fputs("ERROR: missing the network path\n", stderr);
1026         return 1;
1027      }
1028    _tok(args);
1029    path = args;
1030
1031    e = e_connman_network_get(path);
1032    if (e_connman_network_wifi_channel_get(e, &wifi_channel))
1033      printf(":::Network %s Wifi Channel = %#02hx (%d)\n", path, wifi_channel, wifi_channel);
1034    else
1035      fputs("ERROR: can't get network wifi channel\n", stderr);
1036    return 1;
1037 }
1038
1039 static int
1040 _on_cmd_network_get_wifi_eap(char *cmd, char *args)
1041 {
1042    const char *wifi_eap, *path;
1043    E_Connman_Element *e;
1044
1045    if (!args)
1046      {
1047         fputs("ERROR: missing the network path\n", stderr);
1048         return 1;
1049      }
1050    _tok(args);
1051    path = args;
1052
1053    e = e_connman_network_get(path);
1054    if (e_connman_network_wifi_eap_get(e, &wifi_eap))
1055      printf(":::Network %s Wifi EAP = \"%s\"\n", path, wifi_eap);
1056    else
1057      fputs("ERROR: can't get network wifi eap\n", stderr);
1058    return 1;
1059 }
1060
1061 /* Services Commands */
1062 static int
1063 _on_cmd_service_connect(char *cmd, char *args)
1064 {
1065    char *path;
1066    E_Connman_Element *e;
1067
1068    if (!args)
1069      {
1070         fputs("ERROR: missing the service path\n", stderr);
1071         return 1;
1072      }
1073    _tok(args);
1074    path = args;
1075
1076    e = e_connman_service_get(path);
1077    if (e_connman_service_connect(e, NULL, NULL))
1078      printf(":::Connecting to Service %s...\n", path);
1079    else
1080      fputs("ERROR: can't connect to service\n", stderr);
1081    return 1;
1082 }
1083
1084 static int
1085 _on_cmd_service_disconnect(char *cmd, char *args)
1086 {
1087    char *path;
1088    E_Connman_Element *e;
1089
1090    if (!args)
1091      {
1092         fputs("ERROR: missing the service path\n", stderr);
1093         return 1;
1094      }
1095    _tok(args);
1096    path = args;
1097
1098    e = e_connman_service_get(path);
1099    if (e_connman_service_disconnect(e, NULL, NULL))
1100      printf(":::Disconnecting Service %s...\n", path);
1101    else
1102      fputs("ERROR: can't disconnect service\n", stderr);
1103    return 1;
1104 }
1105
1106 static int
1107 _on_cmd_service_remove(char *cmd, char *args)
1108 {
1109    char *path;
1110    E_Connman_Element *e;
1111
1112    if (!args)
1113      {
1114         fputs("ERROR: missing the service path\n", stderr);
1115         return 1;
1116      }
1117    _tok(args);
1118    path = args;
1119
1120    e = e_connman_service_get(path);
1121    if (e_connman_service_remove(e, NULL, NULL))
1122      printf(":::Removing Service %s...\n", path);
1123    else
1124      fputs("ERROR: can't remove service\n", stderr);
1125    return 1;
1126 }
1127
1128 static int
1129 _on_cmd_service_move_before(char *cmd, char *args)
1130 {
1131    char *path, *service_path;
1132    E_Connman_Element *e;
1133
1134    if (!args)
1135      {
1136         fputs("ERROR: missing the service path\n", stderr);
1137         return 1;
1138      }
1139    service_path = args;
1140    path = _tok(args);
1141
1142    if (!path)
1143      {
1144         fputs("ERROR: missing the object service\n", stderr);
1145         return 1;
1146      }
1147    _tok(path);
1148
1149    e = e_connman_service_get(service_path);
1150    if (e_connman_service_move_before(e, path, NULL, NULL))
1151      printf(":::Moving before %s...\n", path);
1152    else
1153      fputs("ERROR: can't move before\n", stderr);
1154    return 1;
1155 }
1156
1157 static int
1158 _on_cmd_service_move_after(char *cmd, char *args)
1159 {
1160    char *path, *service_path;
1161    E_Connman_Element *e;
1162
1163    if (!args)
1164      {
1165         fputs("ERROR: missing the service path\n", stderr);
1166         return 1;
1167      }
1168    service_path = args;
1169    path = _tok(args);
1170
1171    if (!path)
1172      {
1173         fputs("ERROR: missing the object service\n", stderr);
1174         return 1;
1175      }
1176    _tok(path);
1177
1178    e = e_connman_service_get(service_path);
1179    if (e_connman_service_move_after(e, path, NULL, NULL))
1180      printf(":::Moving after %s...\n", path);
1181    else
1182      fputs("ERROR: can't move after\n", stderr);
1183    return 1;
1184 }
1185
1186 static int
1187 _on_cmd_service_get_state(char *cmd, char *args)
1188 {
1189    const char *state, *path;
1190    E_Connman_Element *e;
1191
1192    if (!args)
1193      {
1194         fputs("ERROR: missing the service path\n", stderr);
1195         return 1;
1196      }
1197    _tok(args);
1198    path = args;
1199
1200    e = e_connman_service_get(path);
1201    if (e_connman_service_state_get(e, &state))
1202      printf(":::Service %s State = \"%s\"\n", path, state);
1203    else
1204      fputs("ERROR: can't get service state\n", stderr);
1205    return 1;
1206 }
1207
1208 static int
1209 _on_cmd_service_get_error(char *cmd, char *args)
1210 {
1211    const char *error, *path;
1212    E_Connman_Element *e;
1213
1214    if (!args)
1215      {
1216         fputs("ERROR: missing the service path\n", stderr);
1217         return 1;
1218      }
1219    _tok(args);
1220    path = args;
1221
1222    e = e_connman_service_get(path);
1223    if (e_connman_service_error_get(e, &error))
1224      printf(":::Service %s Error = \"%s\"\n", path, error);
1225    else
1226      fputs("ERROR: can't get service error\n", stderr);
1227    return 1;
1228 }
1229
1230 static int
1231 _on_cmd_service_get_name(char *cmd, char *args)
1232 {
1233    const char *name, *path;
1234    E_Connman_Element *e;
1235
1236    if (!args)
1237      {
1238         fputs("ERROR: missing the service path\n", stderr);
1239         return 1;
1240      }
1241    _tok(args);
1242    path = args;
1243
1244    e = e_connman_service_get(path);
1245    if (e_connman_service_name_get(e, &name))
1246      printf(":::Service %s Name = \"%s\"\n", path, name);
1247    else
1248      fputs("ERROR: can't get service name\n", stderr);
1249    return 1;
1250 }
1251
1252 static int
1253 _on_cmd_service_get_type(char *cmd, char *args)
1254 {
1255    const char *type, *path;
1256    E_Connman_Element *e;
1257
1258    if (!args)
1259      {
1260         fputs("ERROR: missing the service path\n", stderr);
1261         return 1;
1262      }
1263    _tok(args);
1264    path = args;
1265
1266    e = e_connman_service_get(path);
1267    if (e_connman_service_type_get(e, &type))
1268      printf(":::Service %s Type = \"%s\"\n", path, type);
1269    else
1270      fputs("ERROR: can't get service type\n", stderr);
1271    return 1;
1272 }
1273
1274 static int
1275 _on_cmd_service_get_mode(char *cmd, char *args)
1276 {
1277    const char *mode, *path;
1278    E_Connman_Element *e;
1279
1280    if (!args)
1281      {
1282         fputs("ERROR: missing the service path\n", stderr);
1283         return 1;
1284      }
1285    _tok(args);
1286    path = args;
1287
1288    e = e_connman_service_get(path);
1289    if (e_connman_service_mode_get(e, &mode))
1290      printf(":::Service %s Mode = \"%s\"\n", path, mode);
1291    else
1292      fputs("ERROR: can't get service mode\n", stderr);
1293    return 1;
1294 }
1295
1296 static int
1297 _on_cmd_service_get_security(char *cmd, char *args)
1298 {
1299    const char *security, *path;
1300    E_Connman_Element *e;
1301
1302    if (!args)
1303      {
1304         fputs("ERROR: missing the service path\n", stderr);
1305         return 1;
1306      }
1307    _tok(args);
1308    path = args;
1309
1310    e = e_connman_service_get(path);
1311    if (e_connman_service_security_get(e, &security))
1312      printf(":::Service %s Security = \"%s\"\n", path, security);
1313    else
1314      fputs("ERROR: can't get service security\n", stderr);
1315    return 1;
1316 }
1317
1318 static int
1319 _on_cmd_service_get_passphrase(char *cmd, char *args)
1320 {
1321    const char *passphrase, *path;
1322    E_Connman_Element *e;
1323
1324    if (!args)
1325      {
1326         fputs("ERROR: missing the service path\n", stderr);
1327         return 1;
1328      }
1329    _tok(args);
1330    path = args;
1331
1332    e = e_connman_service_get(path);
1333    if (e_connman_service_passphrase_get(e, &passphrase))
1334      printf(":::Service %s Passphrase = \"%s\"\n", path, passphrase);
1335    else
1336      fputs("ERROR: can't get service passphrase\n", stderr);
1337    return 1;
1338 }
1339
1340 static int
1341 _on_cmd_service_set_passphrase(char *cmd, char *args)
1342 {
1343    char *passphrase, *path;
1344    E_Connman_Element *e;
1345
1346    if (!args)
1347      {
1348         fputs("ERROR: missing the service path\n", stderr);
1349         return 1;
1350      }
1351    path = args;
1352    passphrase = _tok(args);
1353
1354    if (!passphrase)
1355      {
1356         fputs("ERROR: missing the passphrase value\n", stderr);
1357         return 1;
1358      }
1359    _tok(passphrase);
1360
1361    e = e_connman_service_get(path);
1362    if (e_connman_service_passphrase_set(e, passphrase, NULL, NULL))
1363      printf(":::Service %s passphrase set to \"%s\"\n", path, passphrase);
1364    else
1365      fputs("ERROR: can't set service passphrase\n", stderr);
1366    return 1;
1367 }
1368
1369 static int
1370 _on_cmd_service_get_passphrase_required(char *cmd, char *args)
1371 {
1372    const char *path;
1373    bool passphrase;
1374    E_Connman_Element *e;
1375
1376    if (!args)
1377      {
1378         fputs("ERROR: missing the service path\n", stderr);
1379         return 1;
1380      }
1381    _tok(args);
1382    path = args;
1383
1384    e = e_connman_service_get(path);
1385    if (e_connman_service_passphrase_required_get(e, &passphrase))
1386      printf(":::Service %s Passphrase Required = %hhu\n", path, passphrase);
1387    else
1388      fputs("ERROR: can't get service passphrase required\n", stderr);
1389    return 1;
1390 }
1391
1392 static int
1393 _on_cmd_service_get_strength(char *cmd, char *args)
1394 {
1395    const char *path;
1396    unsigned char strength;
1397    E_Connman_Element *e;
1398
1399    if (!args)
1400      {
1401         fputs("ERROR: missing the service path\n", stderr);
1402         return 1;
1403      }
1404    _tok(args);
1405    path = args;
1406
1407    e = e_connman_service_get(path);
1408    if (e_connman_service_strength_get(e, &strength))
1409      printf(":::Service %s Strength = %#02hhx (%d)\n", path, strength, strength);
1410    else
1411      fputs("ERROR: can't get service strength\n", stderr);
1412    return 1;
1413 }
1414
1415 static int
1416 _on_cmd_service_get_favorite(char *cmd, char *args)
1417 {
1418    const char *path;
1419    bool favorite;
1420    E_Connman_Element *e;
1421
1422    if (!args)
1423      {
1424         fputs("ERROR: missing the service path\n", stderr);
1425         return 1;
1426      }
1427    _tok(args);
1428    path = args;
1429
1430    e = e_connman_service_get(path);
1431    if (e_connman_service_favorite_get(e, &favorite))
1432      printf(":::Service %s Favorite = %hhu\n", path, favorite);
1433    else
1434      fputs("ERROR: can't get service favorite\n", stderr);
1435    return 1;
1436 }
1437
1438 static int
1439 _on_cmd_service_get_immutable(char *cmd, char *args)
1440 {
1441    const char *path;
1442    bool immutable;
1443    E_Connman_Element *e;
1444
1445    if (!args)
1446      {
1447         fputs("ERROR: missing the service path\n", stderr);
1448         return 1;
1449      }
1450    _tok(args);
1451    path = args;
1452
1453    e = e_connman_service_get(path);
1454    if (e_connman_service_immutable_get(e, &immutable))
1455      printf(":::Service %s Immutable = %hhu\n", path, immutable);
1456    else
1457      fputs("ERROR: can't get service immutable\n", stderr);
1458    return 1;
1459 }
1460
1461 static int
1462 _on_cmd_service_get_auto_connect(char *cmd, char *args)
1463 {
1464    const char *path;
1465    bool auto_connect;
1466    E_Connman_Element *e;
1467
1468    if (!args)
1469      {
1470         fputs("ERROR: missing the service path\n", stderr);
1471         return 1;
1472      }
1473    _tok(args);
1474    path = args;
1475
1476    e = e_connman_service_get(path);
1477    if (e_connman_service_auto_connect_get(e, &auto_connect))
1478      printf(":::Service %s Auto Connect = %hhu\n", path, auto_connect);
1479    else
1480      fputs("ERROR: can't get service auto connect\n", stderr);
1481    return 1;
1482 }
1483
1484 static int
1485 _on_cmd_service_set_auto_connect(char *cmd, char *args)
1486 {
1487    char *path, *next_args;
1488    bool auto_connect;
1489    E_Connman_Element *e;
1490
1491    if (!args)
1492      {
1493         fputs("ERROR: missing the service path\n", stderr);
1494         return 1;
1495      }
1496    path = args;
1497    next_args = _tok(args);
1498
1499    if (!next_args)
1500      {
1501         fputs("ERROR: missing the auto connect value\n", stderr);
1502         return 1;
1503      }
1504    _tok(next_args);
1505    auto_connect = !!atol(next_args);
1506
1507    e = e_connman_service_get(path);
1508    if (e_connman_service_auto_connect_set(e, auto_connect, NULL, NULL))
1509      printf(":::Service %s auto connect set to %d\n", path, auto_connect);
1510    else
1511      fputs("ERROR: can't set service auto connect\n", stderr);
1512    return 1;
1513 }
1514
1515 static int
1516 _on_cmd_service_get_setup_required(char *cmd, char *args)
1517 {
1518    const char *path;
1519    bool setup_required;
1520    E_Connman_Element *e;
1521
1522    if (!args)
1523      {
1524         fputs("ERROR: missing the service path\n", stderr);
1525         return 1;
1526      }
1527    _tok(args);
1528    path = args;
1529
1530    e = e_connman_service_get(path);
1531    if (e_connman_service_setup_required_get(e, &setup_required))
1532      printf(":::Service %s Setup Required = %hhu\n", path, setup_required);
1533    else
1534      fputs("ERROR: can't get service setup required\n", stderr);
1535    return 1;
1536 }
1537
1538 static int
1539 _on_cmd_service_get_apn(char *cmd, char *args)
1540 {
1541    const char *apn, *path;
1542    E_Connman_Element *e;
1543
1544    if (!args)
1545      {
1546         fputs("ERROR: missing the service path\n", stderr);
1547         return 1;
1548      }
1549    _tok(args);
1550    path = args;
1551
1552    e = e_connman_service_get(path);
1553    if (e_connman_service_apn_get(e, &apn))
1554      printf(":::Service %s APN = \"%s\"\n", path, apn);
1555    else
1556      fputs("ERROR: can't get service APN\n", stderr);
1557    return 1;
1558 }
1559
1560 static int
1561 _on_cmd_service_set_apn(char *cmd, char *args)
1562 {
1563    char *apn, *path;
1564    E_Connman_Element *e;
1565
1566    if (!args)
1567      {
1568         fputs("ERROR: missing the service path\n", stderr);
1569         return 1;
1570      }
1571    path = args;
1572    apn = _tok(args);
1573
1574    if (!apn)
1575      {
1576         fputs("ERROR: missing the apn value\n", stderr);
1577         return 1;
1578      }
1579    _tok(apn);
1580
1581    e = e_connman_service_get(path);
1582    if (e_connman_service_apn_set(e, apn, NULL, NULL))
1583      printf(":::Service %s APN set to \"%s\"\n", path, apn);
1584    else
1585      fputs("ERROR: can't set service APN\n", stderr);
1586    return 1;
1587 }
1588
1589 static int
1590 _on_cmd_service_get_mcc(char *cmd, char *args)
1591 {
1592    const char *mcc, *path;
1593    E_Connman_Element *e;
1594
1595    if (!args)
1596      {
1597         fputs("ERROR: missing the service path\n", stderr);
1598         return 1;
1599      }
1600    _tok(args);
1601    path = args;
1602
1603    e = e_connman_service_get(path);
1604    if (e_connman_service_mcc_get(e, &mcc))
1605      printf(":::Service %s MCC = \"%s\"\n", path, mcc);
1606    else
1607      fputs("ERROR: can't get service MCC\n", stderr);
1608    return 1;
1609 }
1610
1611 static int
1612 _on_cmd_service_get_mnc(char *cmd, char *args)
1613 {
1614    const char *mnc, *path;
1615    E_Connman_Element *e;
1616
1617    if (!args)
1618      {
1619         fputs("ERROR: missing the service path\n", stderr);
1620         return 1;
1621      }
1622    _tok(args);
1623    path = args;
1624
1625    e = e_connman_service_get(path);
1626    if (e_connman_service_mnc_get(e, &mnc))
1627      printf(":::Service %s MNC = \"%s\"\n", path, mnc);
1628    else
1629      fputs("ERROR: can't get service MNC\n", stderr);
1630    return 1;
1631 }
1632
1633 static int
1634 _on_cmd_service_get_roaming(char *cmd, char *args)
1635 {
1636    const char *path;
1637    bool roaming;
1638    E_Connman_Element *e;
1639
1640    if (!args)
1641      {
1642         fputs("ERROR: missing the service path\n", stderr);
1643         return 1;
1644      }
1645    _tok(args);
1646    path = args;
1647
1648    e = e_connman_service_get(path);
1649    if (e_connman_service_roaming_get(e, &roaming))
1650      printf(":::Service %s Roaming = %hhu\n", path, roaming);
1651    else
1652      fputs("ERROR: can't get service roaming\n", stderr);
1653    return 1;
1654 }
1655
1656 static int
1657 _on_cmd_service_get_ipv4_method(char *cmd, char *args)
1658 {
1659    const char *ipv4_method, *path;
1660    E_Connman_Element *e;
1661
1662    if (!args)
1663      {
1664         fputs("ERROR: missing the service path\n", stderr);
1665         return 1;
1666      }
1667    _tok(args);
1668    path = args;
1669
1670    e = e_connman_service_get(path);
1671    if (e_connman_service_ipv4_method_get(e, &ipv4_method))
1672      printf(":::Service %s ipv4 method = \"%s\"\n", path, ipv4_method);
1673    else
1674      fputs("ERROR: can't get service ipv4 method\n", stderr);
1675    return 1;
1676 }
1677
1678 static int
1679 _on_cmd_service_get_ipv4_address(char *cmd, char *args)
1680 {
1681    const char *ipv4_address, *path;
1682    E_Connman_Element *e;
1683
1684    if (!args)
1685      {
1686         fputs("ERROR: missing the service path\n", stderr);
1687         return 1;
1688      }
1689    _tok(args);
1690    path = args;
1691
1692    e = e_connman_service_get(path);
1693    if (e_connman_service_ipv4_address_get(e, &ipv4_address))
1694      printf(":::Service %s ipv4 address = \"%s\"\n", path, ipv4_address);
1695    else
1696      fputs("ERROR: can't get service ipv4 address\n", stderr);
1697    return 1;
1698 }
1699
1700
1701 static int
1702 _on_input(void *data, Ecore_Fd_Handler *fd_handler)
1703 {
1704    char buf[256];
1705    char *cmd, *args;
1706    const struct {
1707       const char *cmd;
1708       int (*cb)(char *cmd, char *args);
1709    } *itr, maps[] = {
1710      {"quit", _on_cmd_quit},
1711      {"sync", _on_cmd_sync},
1712      {"get_all", _on_cmd_get_all},
1713      {"print", _on_cmd_print},
1714      {"get_properties", _on_cmd_get_properties},
1715      {"set_property", _on_cmd_property_set},
1716      {"manager_get", _on_cmd_manager_get},
1717      {"manager_get_profiles", _on_cmd_manager_get_profiles},
1718      {"manager_get_devices", _on_cmd_manager_get_devices},
1719      {"manager_get_services", _on_cmd_manager_get_services},
1720      {"manager_register_agent", _on_cmd_manager_register_agent},
1721      {"manager_unregister_agent", _on_cmd_manager_unregister_agent},
1722      {"manager_get_state", _on_cmd_manager_get_state},
1723      {"manager_get_offline_mode", _on_cmd_manager_get_offline_mode},
1724      {"manager_set_offline_mode", _on_cmd_manager_set_offline_mode},
1725      {"device_propose_scan", _on_cmd_device_propose_scan},
1726      {"device_get_address", _on_cmd_device_get_address},
1727      {"device_get_name", _on_cmd_device_get_name},
1728      {"device_get_type", _on_cmd_device_get_type},
1729      {"device_get_interface", _on_cmd_device_get_interface},
1730      {"device_get_powered", _on_cmd_device_get_powered},
1731      {"device_set_powered", _on_cmd_device_set_powered},
1732      {"device_get_scan_interval", _on_cmd_device_get_scan_interval},
1733      {"device_set_scan_interval", _on_cmd_device_set_scan_interval},
1734      {"device_get_scanning", _on_cmd_device_get_scanning},
1735      {"device_get_networks", _on_cmd_device_get_networks},
1736      {"profile_get_name", _on_cmd_profile_get_name},
1737      {"profile_set_name", _on_cmd_profile_set_name},
1738      {"profile_get_offline_mode", _on_cmd_profile_get_offline_mode},
1739      {"profile_set_offline_mode", _on_cmd_profile_set_offline_mode},
1740      {"profile_get_services", _on_cmd_profile_get_services},
1741      {"network_get_address", _on_cmd_network_get_address},
1742      {"network_get_name", _on_cmd_network_get_name},
1743      {"network_get_connected", _on_cmd_network_get_connected},
1744      {"network_get_strength", _on_cmd_network_get_strength},
1745      {"network_get_frequency", _on_cmd_network_get_frequency},
1746      {"network_get_device", _on_cmd_network_get_device},
1747      {"network_get_wifi_ssid", _on_cmd_network_get_wifi_ssid},
1748      {"network_get_wifi_mode", _on_cmd_network_get_wifi_mode},
1749      {"network_get_wifi_security", _on_cmd_network_get_wifi_security},
1750      {"network_get_wifi_passphrase", _on_cmd_network_get_wifi_passphrase},
1751      {"network_get_wifi_channel", _on_cmd_network_get_wifi_channel},
1752      {"network_get_wifi_eap", _on_cmd_network_get_wifi_eap},
1753      {"service_connect", _on_cmd_service_connect},
1754      {"service_disconnect", _on_cmd_service_disconnect},
1755      {"service_remove", _on_cmd_service_remove},
1756      {"service_move_before", _on_cmd_service_move_before},
1757      {"service_move_after", _on_cmd_service_move_after},
1758      {"service_get_state", _on_cmd_service_get_state},
1759      {"service_get_error", _on_cmd_service_get_error},
1760      {"service_get_name", _on_cmd_service_get_name},
1761      {"service_get_type", _on_cmd_service_get_type},
1762      {"service_get_mode", _on_cmd_service_get_mode},
1763      {"service_get_security", _on_cmd_service_get_security},
1764      {"service_get_passphrase", _on_cmd_service_get_passphrase},
1765      {"service_set_passphrase", _on_cmd_service_set_passphrase},
1766      {"service_get_passphrase_required", _on_cmd_service_get_passphrase_required},
1767      {"service_get_strength", _on_cmd_service_get_strength},
1768      {"service_get_favorite", _on_cmd_service_get_favorite},
1769      {"service_get_immutable", _on_cmd_service_get_immutable},
1770      {"service_get_auto_connect", _on_cmd_service_get_auto_connect},
1771      {"service_set_auto_connect", _on_cmd_service_set_auto_connect},
1772      {"service_get_setup_required", _on_cmd_service_get_setup_required},
1773      {"service_get_apn", _on_cmd_service_get_apn},
1774      {"service_set_apn", _on_cmd_service_set_apn},
1775      {"service_get_mcc", _on_cmd_service_get_mcc},
1776      {"service_get_mnc", _on_cmd_service_get_mnc},
1777      {"service_get_roaming", _on_cmd_service_get_roaming},
1778      {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method},
1779      {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address},
1780      {NULL, NULL}
1781    };
1782
1783
1784    if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
1785      {
1786         fputs("ERROR: reading from stdin, exit\n", stderr);
1787         return 0;
1788      }
1789
1790    if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1791      {
1792         fputs("ERROR: nothing to read?\n", stderr);
1793         return 0;
1794      }
1795
1796    if (!fgets(buf, sizeof(buf), stdin))
1797      {
1798         fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno));
1799         ecore_main_loop_quit();
1800         return 0;
1801      }
1802
1803    cmd = buf;
1804    while (isspace(*cmd))
1805      cmd++;
1806
1807    args = strchr(cmd, ' ');
1808    if (args)
1809      {
1810         char *p;
1811
1812         *args = '\0';
1813         args++;
1814
1815         while (isspace(*args))
1816           args++;
1817
1818         p = args + strlen(args) - 1;
1819         if (*p == '\n')
1820           *p = '\0';
1821      }
1822    else
1823      {
1824         char *p;
1825
1826         p = cmd + strlen(cmd) - 1;
1827         if (*p == '\n')
1828           *p = '\0';
1829      }
1830
1831    if (strcmp(cmd, "help") == 0)
1832      {
1833         if (args)
1834           {
1835              printf("Commands with '%s' in the name:\n", args);
1836              for (itr = maps; itr->cmd != NULL; itr++)
1837                if (strstr(itr->cmd, args))
1838                  printf("\t%s\n", itr->cmd);
1839           }
1840         else
1841           {
1842              fputs("Commands:\n", stdout);
1843              for (itr = maps; itr->cmd != NULL; itr++)
1844                printf("\t%s\n", itr->cmd);
1845           }
1846         fputc('\n', stdout);
1847         return 1;
1848      }
1849
1850    for (itr = maps; itr->cmd != NULL; itr++)
1851      if (strcmp(itr->cmd, cmd) == 0)
1852        return itr->cb(cmd, args);
1853
1854    printf("unknown command \"%s\", args=%s\n", cmd, args);
1855    return 1;
1856 }
1857
1858 int
1859 main(int argc, char *argv[])
1860 {
1861    E_DBus_Connection *c;
1862
1863    ecore_init();
1864    e_dbus_init();
1865    eina_init();
1866
1867    c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
1868    if (!c) {
1869       printf("ERROR: can't connect to system session\n");
1870       return -1;
1871    }
1872
1873    e_connman_system_init(c);
1874    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
1875    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
1876    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
1877                            _on_element_updated, NULL);
1878
1879    ecore_main_fd_handler_add
1880      (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL);
1881
1882    ecore_main_loop_begin();
1883
1884    e_connman_system_shutdown();
1885
1886    e_dbus_connection_close(c);
1887    eina_shutdown();
1888    e_dbus_shutdown();
1889    ecore_shutdown();
1890
1891    fputs("DBG: clean exit.\n", stderr);
1892
1893    return 0;
1894 }