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