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