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