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