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