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