Fix Side effect from "Fix Coverity issues"
[platform/core/api/multi-device-group.git] / test / mdg-manager.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/time.h>
22 #include <unistd.h>
23 #include <glib.h>
24 #include <gio/gio.h>
25
26 #include "menu.h"
27 #include "common.h"
28
29 mdg_h handle = NULL;
30
31 GList *found_group_list;
32 GList *found_device_list;
33 GList *found_invited_device_list;
34 GList *found_channel_list;
35
36 static char groupid[MENU_DATA_SIZE + 1] = "mygroup";
37 static char request_groupid[MENU_DATA_SIZE + 1] = "subgroup";
38 static char timeout[MENU_DATA_SIZE + 1] = "2";
39 static char group_idx[MENU_DATA_SIZE + 1] = "1";
40 static char device_idx[MENU_DATA_SIZE + 1] = "1";
41 static char channel_idx[MENU_DATA_SIZE + 1] = "1";
42 static char pin[MENU_DATA_SIZE + 1] = "12341234";
43 static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
44 static char channel_id[MENU_DATA_SIZE + 1] = "Channel1";
45
46 static int run_group_find(MManager *mm, struct menu_data *menu);
47 static int run_devices_find(MManager *mm, struct menu_data *menu);
48
49 static const char* __device_type_to_string(mdg_device_type_e type)
50 {
51         switch (type) {
52         /* CHECK: List all enum values here */
53         case MDG_DEVICE_TYPE_LOCAL:
54                 return "Local";
55         case MDG_DEVICE_TYPE_REMOTE:
56                 return "Remote";
57         default:
58                 return "Unknown";
59         }
60 }
61
62 static void _destroy_mdg_device_info(gpointer data)
63 {
64         mdg_device_info_destroy((mdg_device_h)data);
65 }
66
67 void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
68                                                         int len, int ret, void *user_data)
69 {
70         msg("_request_result_cb is called command %s Requester id %s", cmd,
71                                 device_id);
72
73         if (cmd == NULL) {
74                 msgp("cmd is null [%s(0x%X)]", mdg_error_to_string(ret), ret);
75                 return;
76         }
77
78         if (strncmp("COMP_REQ_CREATE_GROUP", cmd, strlen(cmd)) == 0) {
79                 msgp("[CMD] Request Create Group [%s(0x%X)]", mdg_error_to_string(ret), ret);
80                 if (ret == MDG_ERROR_NONE && arg != NULL) {
81                         msgb("Created Group name is %s", arg);
82                         run_group_find(NULL, NULL);
83                         run_devices_find(NULL, NULL);
84                 }
85         } else if (strncmp("COMP_REQ_INVITE_DEVICE", cmd, strlen(cmd)) == 0) {
86                 msgp("[CMD] Request Invite [%s(0x%X)]", mdg_error_to_string(ret), ret);
87                 if (ret == MDG_ERROR_NONE && arg != NULL)
88                         msgb("Invited Device ID is %s", arg);
89         } else if (strncmp("COMP_REQ_EJECT_DEVICE", cmd, strlen(cmd)) == 0) {
90                 msgp("[CMD] Request Eject [%s(0x%X)]", mdg_error_to_string(ret), ret);
91                 if (ret == MDG_ERROR_NONE && arg != NULL)
92                         msgb("Ejected Device ID is %s", arg);
93         } else if (strncmp("COMP_REQ_DELETE_GROUP", cmd, strlen(cmd)) == 0) {
94                 msgp("[CMD] Request Delete Group [%s(0x%X)]", mdg_error_to_string(ret), ret);
95                 if (ret == MDG_ERROR_NONE && arg != NULL)
96                         msgb("Deleted Group name is %s", arg);
97         } else if (strncmp("COMP_REQ_SEND_DATA", cmd, strlen(cmd)) == 0) {
98                 msgp("Received data [%zd] %s", strlen((char *)arg), arg);
99         } else {
100                 msgp("[Recv][%zd] %s", strlen((char *) arg), arg);
101         }
102 }
103
104 void _device_eject_result_cb(int result, void *user_data)
105 {
106         msgb("\rEject Device Complete [%s]", mdg_error_to_string(result));
107 }
108
109 static int run_device_eject(MManager *mm, struct menu_data *menu)
110 {
111         int ret;
112         int idx = 1;
113         mdg_group_h group = NULL;
114         mdg_device_h device = NULL;
115
116         msg("Eject Device");
117
118         if (strlen(group_idx)) {
119                 idx = (unsigned short)strtol(group_idx, NULL, 10);
120                 if (0 >= idx) {
121                         msgp("Invalid index. set to 1");
122                         idx = 1;
123                 }
124         }
125
126         if (found_group_list) {
127                 group = g_list_nth_data(found_group_list, idx - 1);
128                 if (NULL == group) {
129                         msgr("Failed to g_hash_table_find");
130                         return RET_FAILURE;
131                 }
132         }
133
134         if (strlen(device_idx)) {
135                 idx = (unsigned short)strtol(device_idx, NULL, 10);
136                 if (0 >= idx) {
137                         msgp("Invalid index. set to 1");
138                         idx = 1;
139                 }
140         }
141
142         if (NULL == found_invited_device_list) {
143                 msgr("Find device first");
144                 return RET_FAILURE;
145         }
146
147         device = g_list_nth_data(found_invited_device_list, idx - 1);
148         if (NULL == device) {
149                 msgr("Failed to g_hash_table_find");
150                 return RET_FAILURE;
151         }
152
153         ret = mdg_group_eject_device(handle, group, device, _device_eject_result_cb, NULL);
154         if (MDG_ERROR_NONE != ret) {
155                 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
156                 return RET_FAILURE;
157         }
158         msg(" - mdg_group_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
159
160         return RET_SUCCESS;
161 }
162
163 bool __group_foreach_cb(mdg_device_h device, void *user_data)
164 {
165         char *device_id;
166
167         mdg_device_info_get_device_id(device, &device_id);
168         msgb("\rDevice is [%s]", device_id);
169
170         found_invited_device_list = g_list_append(found_invited_device_list, device);
171
172         g_free(device_id);
173
174         return true;
175 }
176
177 static int run_group_foreach_device(MManager *mm, struct menu_data *menu)
178 {
179         int ret;
180         int idx = 1;
181         mdg_group_h group = NULL;
182
183         msg("Foreach Device");
184
185         if (strlen(group_idx)) {
186                 idx = (unsigned short)strtol(group_idx, NULL, 10);
187                 if (0 >= idx) {
188                         msgp("Invalid index. set to 1");
189                         idx = 1;
190                 }
191         }
192
193         if (found_group_list) {
194                 group = g_list_nth_data(found_group_list, idx - 1);
195                 if (NULL == group) {
196                         msgr("Failed to g_hash_table_find");
197                         return RET_FAILURE;
198                 }
199         }
200
201         if (found_invited_device_list) {
202                 g_list_free_full(found_device_list, _destroy_mdg_device_info);
203                 found_invited_device_list = NULL;
204         }
205
206         ret = mdg_group_foreach_device(handle, group, __group_foreach_cb, NULL);
207         if (MDG_ERROR_NONE != ret) {
208                 msgr("Failed to foreach device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
209                 return RET_FAILURE;
210         }
211         msg(" - mdg_group_foreach_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
212
213         return RET_SUCCESS;
214 }
215
216 void _device_invite_result_cb(int result, mdg_device_h device, void *user_data)
217 {
218         bool is_invited;
219         mdg_device_info_is_invited(device, &is_invited);
220         msgb("\rInvite Device Finished [%s]", mdg_error_to_string(result));
221         msgb("\rThe device invited is : %d", is_invited);
222 }
223
224 static int run_device_invite(MManager *mm, struct menu_data *menu)
225 {
226         int ret;
227         int idx = 1;
228         mdg_group_h group = NULL;
229         mdg_device_h device = NULL;
230
231         msg("Invite Device");
232
233         if (strlen(group_idx)) {
234                 idx = (unsigned short)strtol(group_idx, NULL, 10);
235                 if (0 >= idx) {
236                         msgp("Invalid index. set to 1");
237                         idx = 1;
238                 }
239         }
240
241         if (found_group_list) {
242                 group = g_list_nth_data(found_group_list, idx - 1);
243                 if (NULL == group) {
244                         msgr("Failed to g_hash_table_find");
245                         return RET_FAILURE;
246                 }
247         }
248
249         if (strlen(device_idx)) {
250                 idx = (unsigned short)strtol(device_idx, NULL, 10);
251                 if (0 >= idx) {
252                         msgp("Invalid index. set to 1");
253                         idx = 1;
254                 }
255         }
256
257         if (NULL == found_device_list) {
258                 msgr("Find device first");
259                 return RET_FAILURE;
260         }
261
262         device = g_list_nth_data(found_device_list, idx - 1);
263         if (NULL == device) {
264                 msgr("Failed to g_hash_table_find");
265                 return RET_FAILURE;
266         }
267
268         ret = mdg_group_invite_device(handle, group, device, pin, _device_invite_result_cb, NULL);
269         if (MDG_ERROR_NONE != ret) {
270                 msgr("Failed to device invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
271                 return RET_FAILURE;
272         }
273         msg(" - mdg_group_invite_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
274
275         return RET_SUCCESS;
276 }
277
278
279 static int run_devices_show(MManager *mm, struct menu_data *menu)
280 {
281         mdg_device_h device;
282
283         int i;
284         GList *iter = NULL;
285
286         /* Get a first item */
287         i = 0;
288         iter = g_list_first(found_device_list);
289         while (NULL != iter) {
290                 device = iter->data;
291                 if (!device) {
292                         msgr("device is null");
293                         break;
294                 }
295
296                 char *model_name;
297                 char *device_id;
298                 mdg_device_info_get_model_name(device, &model_name);
299                 mdg_device_info_get_device_id(device, &device_id);
300
301                 msgp("[%d] Model : %s, Device ID : %s", i+1, model_name, device_id);
302
303                 mdg_device_h cloned_device;
304                 char *cloned_model_name;
305                 char *cloned_device_id;
306
307                 mdg_device_info_clone(&cloned_device, device);
308                 mdg_device_info_get_model_name(cloned_device, &cloned_model_name);
309                 mdg_device_info_get_device_id(cloned_device, &cloned_device_id);
310
311                 msgp("*Cloned* [%d] Model : %s, Device ID : %s", i+1, cloned_model_name, cloned_device_id);
312
313                 if (model_name)
314                         free(model_name);
315
316                 if (device_id)
317                         free(device_id);
318
319                 if (cloned_model_name)
320                         free(cloned_model_name);
321
322                 if (cloned_device_id)
323                         free(cloned_device_id);
324
325                 mdg_device_info_destroy(cloned_device);
326
327                 /* Next item */
328                 iter = g_list_next(iter);
329                 i++;
330         }
331
332         return RET_SUCCESS;
333 }
334
335 static int run_invited_devices_show(MManager *mm, struct menu_data *menu)
336 {
337         mdg_device_h device;
338
339         int i;
340         GList *iter = NULL;
341
342         /* Get a first item */
343         i = 0;
344         iter = g_list_first(found_invited_device_list);
345         while (NULL != iter) {
346                 device = iter->data;
347                 if (!device) {
348                         msgr("device is null");
349                         break;
350                 }
351
352                 char *model_name;
353                 char *device_id;
354
355                 mdg_device_info_get_device_id(device, &device_id);
356                 mdg_device_info_get_model_name(device, &model_name);
357
358                 msgp("[%d] Device : %s, Model : %s", i+1, device_id, model_name);
359
360                 if (model_name)
361                         free(model_name);
362
363                 if (device_id)
364                         free(device_id);
365
366                 /* Next item */
367                 iter = g_list_next(iter);
368                 i++;
369         }
370
371         return RET_SUCCESS;
372 }
373
374 typedef struct _channel_t {
375         char *device_id; /**< User callback to be called */
376         char *channel_id; /**< User data pointer */
377 } channel_t;
378
379 static int run_channels_show(MManager *mm, struct menu_data *menu)
380 {
381         channel_t *channel;
382
383         int i;
384         GList *iter = NULL;
385
386         /* Get a first item */
387         i = 0;
388         iter = g_list_first(found_channel_list);
389         while (NULL != iter) {
390                 channel = iter->data;
391                 if (!channel) {
392                         msgr("channel is null");
393                         break;
394                 }
395
396                 msgp("[%d] device id : %s, channel id : %s,", i+1, channel->device_id, channel->channel_id);
397
398                 /* Next item */
399                 iter = g_list_next(iter);
400                 i++;
401         }
402
403         return RET_SUCCESS;
404 }
405
406 #if 0
407 static int run_group_get_members(MManager *mm, struct menu_data *menu)
408 {
409         int ret;
410         int idx;
411         int count;
412         mdg_group_h group = NULL;
413         mdg_device_h **devices = NULL;
414
415         msg("Get Group Members");
416
417         if (strlen(group_idx)) {
418                 idx = (unsigned short)strtol(group_idx, NULL, 10);
419                 if (0 >= idx) {
420                         msgp("Invalid index. set to 1");
421                         idx = 1;
422                 }
423         }
424
425         if (found_group_list) {
426                 group = g_list_nth_data(found_group_list, idx - 1);
427                 if (NULL == group) {
428                         msgr("Failed to g_hash_table_find");
429                         return RET_FAILURE;
430                 }
431         }
432
433         ret = mdg_group_get_member_devices(group, devices, &count);
434         if (MDG_ERROR_NONE != ret) {
435                 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
436                 return RET_FAILURE;
437         }
438         msg(" - mdg_group_get_member_devices() ret: [0x%X] [%s]", ret,
439                 mdg_error_to_string(ret));
440
441         for (int i = 0; i < count; i++) {
442
443                 char *device_id = NULL;
444                 char *ip = NULL;
445                 mdg_device_type_e device_type;
446
447                 mdg_device_info_get_device_id(devices[i], &device_id);
448                 mdg_device_info_get_ip(devices[i], &ip);
449                 mdg_device_info_get_device_type(devices[i], &device_type);
450
451                 msgp("device_id : %s, name : %s, type : %s", device_id, ip,
452                         __device_type_to_string(device_type));
453
454                 if (device_id)
455                         free(device_id);
456                 if (ip)
457                         free(ip);
458         }
459
460         return RET_SUCCESS;
461 }
462 #endif
463
464 static int run_group_delete(MManager *mm, struct menu_data *menu)
465 {
466         int ret;
467         int idx = 1;
468         mdg_group_h group = NULL;
469
470         msg("Delete Group");
471
472         if (strlen(group_idx)) {
473                 idx = (unsigned short)strtol(group_idx, NULL, 10);
474                 if (0 >= idx) {
475                         msgp("Invalid index. set to 1");
476                         idx = 1;
477                 }
478         }
479
480         if (found_group_list) {
481                 group = g_list_nth_data(found_group_list, idx - 1);
482                 if (NULL == group) {
483                         msgr("Failed to g_hash_table_find");
484                         return RET_FAILURE;
485                 }
486         }
487
488         ret = mdg_group_delete(handle, group);
489         if (MDG_ERROR_NONE != ret) {
490                 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
491                 return RET_FAILURE;
492         }
493         msg(" - mdg_group_delete() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
494
495         return RET_SUCCESS;
496 }
497
498 void _device_finish_cb(int result, void *user_data)
499 {
500         msgb("\rFind Device Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
501 }
502
503 bool _device_found_cb(mdg_device_h device, void *user_data)
504 {
505         char *device_id = NULL;
506         char *model_name = NULL;
507         mdg_device_type_e device_type;
508         GList *iter = NULL;
509         gboolean is_exist = FALSE;
510
511         mdg_device_info_get_device_id(device, &device_id);
512         mdg_device_info_get_model_name(device, &model_name);
513         mdg_device_info_get_type(device, &device_type);
514
515         iter = found_device_list;
516         while (iter != NULL) {
517                 mdg_device_h temp = (mdg_device_h)iter->data;
518                 char *temp_device_id;
519
520                 mdg_device_info_get_device_id(temp, &temp_device_id);
521
522                 if (g_strcmp0(device_id, temp_device_id) == 0) {
523                         is_exist = TRUE;
524                         free(temp_device_id);
525                         mdg_device_info_destroy(device);
526                         break;
527                 }
528
529                 free(temp_device_id);
530                 iter = g_list_next(iter);
531         }
532
533         if (is_exist == FALSE) {
534                 mdg_device_h cloned_device;
535                 mdg_device_info_clone(&cloned_device, device);
536                 found_device_list = g_list_append(found_device_list, cloned_device);
537                 msgp("\r[ID] %s [Type] %s [Name] %s", device_id,
538                         __device_type_to_string(device_type), model_name);
539         }
540
541         if (device_id)
542                 free(device_id);
543         if (model_name)
544                 free(model_name);
545
546         return TRUE;
547 }
548
549 static int run_devices_find(MManager *mm, struct menu_data *menu)
550 {
551         int ret;
552         int duration = 0;
553         msg("Find Devices");
554
555         if (strlen(timeout))
556                 duration = (unsigned short)strtol(timeout, NULL, 10);
557
558         ret = mdg_device_find(handle, duration, false, _device_found_cb, _device_finish_cb, NULL);
559         if (MDG_ERROR_NONE != ret) {
560                 msgr("Failed to Find Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret);
561                 return RET_FAILURE;
562         }
563         msg(" - mdg_device_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
564
565         if (found_device_list) {
566                 g_list_free_full(found_device_list, _destroy_mdg_device_info);
567                 found_device_list = NULL;
568         }
569
570         return RET_SUCCESS;
571 }
572
573 void __invited_event_cb(mdg_group_h group, void *user_data)
574 {
575         char *device_id;
576         char *name;
577
578         mdg_group_info_get_device_id(group, &device_id);
579         mdg_group_info_get_name(group, &name);
580
581         msgb("device is invited by [%s], Group Name [%s]", device_id, name);
582
583         g_free(device_id);
584         g_free(name);
585 }
586
587 void __ejected_event_cb(mdg_group_h group, void *user_data)
588 {
589         char *device_id;
590         char *name;
591
592         mdg_group_info_get_device_id(group, &device_id);
593         mdg_group_info_get_name(group, &name);
594
595         msgb("device is ejected by [%s], Group Name [%s]", device_id, name);
596
597         g_free(device_id);
598         g_free(name);
599 }
600
601 int run_device_show_local_device(MManager *mm, struct menu_data *menu)
602 {
603         int ret = 0;
604         mdg_device_h device = NULL;
605
606         msg("Get Local Device");
607
608         ret = mdg_device_get_local_device(handle, &device);
609         if (MDG_ERROR_NONE != ret) {
610                 msgr("Failed to Get My Device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
611                 return RET_FAILURE;
612         }
613         msg(" - mdg_device_info_get_local_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
614
615         if (ret == 0) {
616                 char *device_id = NULL;
617                 char *model_name;
618                 char *device_name;
619                 char *platform_ver;
620                 char *vendor_id;
621                 char *profile;
622                 bool is_invited;
623                 mdg_device_type_e type;
624
625                 mdg_device_info_get_device_id(device, &device_id);
626                 mdg_device_info_get_model_name(device, &model_name);
627                 mdg_device_info_get_device_name(device, &device_name);
628                 mdg_device_info_get_platform_ver(device, &platform_ver);
629                 mdg_device_info_get_vendor_id(device, &vendor_id);
630                 mdg_device_info_get_profile(device, &profile);
631                 mdg_device_info_is_invited(device, &is_invited);
632                 mdg_device_info_get_type(device, &type);
633
634                 msgb("\n[ID] %s", device_id);
635                 msgb("[Model Name] %s", model_name);
636                 msgb("[Device Name] %s", device_name);
637                 msgb("[Platform Ver.] %s", platform_ver);
638                 msgb("[Vendor ID] %s", vendor_id);
639                 msgb("[Profile] %s", profile);
640                 msgb("[Is Invited] %d", is_invited);
641                 msgb("[Type] %s\n", __device_type_to_string(type));
642
643                 if (model_name)
644                         free(model_name);
645                 if (device_id)
646                         free(device_id);
647                 if (device_name)
648                         free(device_name);
649                 if (platform_ver)
650                         free(platform_ver);
651                 if (vendor_id)
652                         free(vendor_id);
653                 if (profile)
654                         free(profile);
655
656                 mdg_device_info_destroy(device);
657                 device = NULL;
658         }
659
660         mdg_set_invited_event_cb(handle, __invited_event_cb, NULL);
661         mdg_set_ejected_event_cb(handle, __ejected_event_cb, NULL);
662
663         return RET_SUCCESS;
664 }
665
666 static int run_group_show(MManager *mm, struct menu_data *menu)
667 {
668         mdg_group_h group;
669
670         int i;
671         GList *iter = NULL;
672
673         /* Get a first item */
674         i = 0;
675         iter = g_list_first(found_group_list);
676         while (NULL != iter) {
677                 group = iter->data;
678                 if (!group) {
679                         msgr("groups is null");
680                         break;
681                 }
682
683                 char *device_id;
684                 char *name;
685                 mdg_group_type_e type;
686
687                 mdg_group_info_get_device_id(group, &device_id);
688                 mdg_group_info_get_name(group, &name);
689                 mdg_group_info_get_type(group, &type);
690
691                 msgp("[%d] type: %s, name: %s", i+1, mdg_group_type_to_string(type), name);
692                 msgp("     device_id: %s\n", device_id);
693
694                 mdg_group_h cloned_group;
695                 char *cloned_device_id;
696                 char *cloned_name;
697                 mdg_group_type_e cloned_type;
698
699                 mdg_group_info_clone(&cloned_group, group);
700                 mdg_group_info_get_device_id(cloned_group, &cloned_device_id);
701                 mdg_group_info_get_name(cloned_group, &cloned_name);
702                 mdg_group_info_get_type(cloned_group, &cloned_type);
703
704                 msgp("*Cloned* [%d] type: %s, name: %s", i+1, mdg_group_type_to_string(cloned_type), cloned_name);
705                 msgp("     device_id: %s\n", cloned_device_id);
706
707                 if (device_id)
708                         free(device_id);
709                 if (name)
710                         free(name);
711
712                 if (cloned_device_id)
713                         free(cloned_device_id);
714                 if (cloned_name)
715                         free(cloned_name);
716
717                 mdg_group_info_destroy(cloned_group);
718
719                 /* Next item */
720                 iter = g_list_next(iter);
721                 i++;
722         }
723
724         return RET_SUCCESS;
725 }
726
727 static void _destroy_mdg_group_info(gpointer data)
728 {
729         mdg_group_info_destroy((mdg_group_h)data);
730 }
731
732 bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data)
733 {
734         char *group_name;
735         mdg_group_h cloned_group;
736
737         mdg_group_info_get_name(group, &group_name);
738
739         if (type == MDG_GROUP_TYPE_LOCAL)
740                 msgp("\rfound group type : MINE, name : %s", group_name);
741         else
742                 msgp("\rfound group type : REMOTE, name : %s", group_name);
743
744         mdg_group_info_clone(&cloned_group, group);
745
746         found_group_list = g_list_append(found_group_list, cloned_group);
747
748         if (group_name != NULL)
749                 free(group_name);
750
751         return TRUE;
752 }
753
754 void _group_finish_cb(int result, void *user_data)
755 {
756         msgb("\rFind Group Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
757 }
758
759 static int run_group_find(MManager *mm, struct menu_data *menu)
760 {
761         int ret;
762         int duration = 0;
763         msg("Find Group");
764
765         if (strlen(timeout))
766                 duration = (unsigned short)strtol(timeout, NULL, 10);
767
768         if (found_group_list) {
769                 g_list_free_full(found_group_list, _destroy_mdg_group_info);
770                 found_group_list = NULL;
771         }
772
773         ret = mdg_group_find(handle, duration, _group_found_cb, _group_finish_cb, NULL);
774         if (MDG_ERROR_NONE != ret) {
775                 msgr("Failed to Find Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
776                 return RET_FAILURE;
777         }
778         msg(" - mdg_group_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
779
780         return RET_SUCCESS;
781 }
782
783 static int run_group_create(MManager *mm, struct menu_data *menu)
784 {
785         int ret;
786         msg("Create Group");
787
788         ret = mdg_group_create(handle, groupid);
789         if (MDG_ERROR_NONE != ret) {
790                 msgr("Failed to Create Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
791                 return RET_FAILURE;
792         }
793         msg(" - mdg_group_create() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
794         msgb("Create Group Successfully");
795
796         return RET_SUCCESS;
797 }
798
799 void _send_data_finish2_cb(int result, mdg_device_h device, char *channel_id, int msg_id,
800         unsigned char *data, int len, void *user_data)
801 {
802         msgb("\rmsg id = %d, data = %s, len = %d", msg_id, data, len);
803         msgb("\rSend Data once more Finished = %d", result);
804 }
805
806 void _send_data_finish_cb(int result, mdg_device_h device, char *channel_id, int msg_id,
807         unsigned char *data, int len, void *user_data)
808 {
809         int msg_id2;
810
811         msgb("\rmsg id = %d, channel ID data = %s, len = %d", msg_id, data, len);
812         msgb("\rSend Data Finished = %d", result);
813
814         msgb("\rSend Data Once more");
815         mdg_device_send_data(handle, device, channel_id, (unsigned char *)"Welcome",
816                                                  7, _send_data_finish2_cb, NULL, &msg_id2);
817
818         msgp("The message ID is %d", msg_id2);
819 }
820
821 static int __send_data(int devidx, int chaidx)
822 {
823         int ret = 0;
824         char *deviceid = NULL;
825         mdg_device_h device = NULL;
826         channel_t *channel = NULL;
827
828         if (!found_invited_device_list || !found_channel_list) {
829                         msgr("Find local device first");
830                         return RET_FAILURE;
831         }
832
833         if (found_invited_device_list) {
834                 device = g_list_nth_data(found_invited_device_list, devidx - 1);
835                 if (NULL == device) {
836                         msgr("Find local device first");
837                         return RET_FAILURE;
838                 }
839         }
840
841         if (found_channel_list) {
842                 channel = g_list_nth_data(found_channel_list, chaidx - 1);
843                 if (NULL == channel) {
844                         msgr("Find local device first");
845                         return RET_FAILURE;
846                 }
847         }
848
849         if (NULL == device) {
850                 msgr("device is NULL");
851                 return RET_FAILURE;
852         }
853
854         if (NULL == channel) {
855                 msgr("channel is NULL");
856                 return RET_FAILURE;
857         }
858
859         mdg_device_info_get_device_id(device, &deviceid);
860         msgp("Sent to [ID] %s [CHANNEL ID] %s", deviceid, channel->channel_id);
861         if (deviceid) {
862                 free(deviceid);
863                 deviceid = NULL;
864         }
865
866         int msg_id;
867         ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message,
868                                         strlen(message), _send_data_finish_cb, NULL, &msg_id);
869         if (MDG_ERROR_NONE != ret)
870                 msgr("Failed to Send Data: [ID] %s", deviceid);
871
872         msgp("The message ID is %d", msg_id);
873
874         return ret;
875 }
876
877 static int run_send_data(MManager *mm, struct menu_data *menu)
878 {
879         int devidx = 0;
880         int chaidx = 0;
881         int count = g_list_length(found_invited_device_list);
882
883         if (0 >= count) {
884                 msgr("No Device");
885                 return RET_SUCCESS;
886         }
887
888         if (strlen(device_idx)) {
889                 devidx = (unsigned short)strtol(device_idx, NULL, 10);
890                 if (0 >= devidx) {
891                         msgp("Invalid index. set to 1");
892                         devidx = 1;
893                 }
894         }
895         if (strlen(channel_idx)) {
896                 chaidx = (unsigned short)strtol(channel_idx, NULL, 10);
897                 if (0 >= chaidx) {
898                         msgp("Invalid index. set to 1");
899                         chaidx = 1;
900                 }
901         }
902         return __send_data(devidx, chaidx);
903 }
904
905 void _invited_device_finish_cb(int result, void *user_data)
906 {
907         msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result,
908                 mdg_error_to_string(result));
909 }
910
911 bool _invited_device_found_cb(mdg_device_h device, void *user_data)
912 {
913         char *device_id = NULL;
914         mdg_device_type_e device_type;
915         mdg_device_h cloned_device;
916
917         mdg_device_info_get_device_id(device, &device_id);
918         mdg_device_info_get_type(device, &device_type);
919
920         msgp("\r[ID] %s [Type] %s", device_id, __device_type_to_string(device_type));
921
922         if (device_id)
923                 free(device_id);
924
925         mdg_device_info_clone(&cloned_device, device);
926
927         found_invited_device_list = g_list_append(found_invited_device_list, cloned_device);
928
929         return TRUE;
930 }
931
932 static int run_devices_find_invited_device(MManager *mm, struct menu_data *menu)
933 {
934         int ret;
935         int duration = 0;
936         msg("Find My Owned Devices");
937
938         if (strlen(timeout))
939                 duration = (unsigned short)strtol(timeout, NULL, 10);
940
941         ret = mdg_device_find(handle, duration, true, _invited_device_found_cb,
942                 _invited_device_finish_cb, NULL);
943         if (MDG_ERROR_NONE != ret) {
944                 msgr("Failed to Find My Owned Devices: [%s(0x%X)]",
945                         mdg_error_to_string(ret), ret);
946                 return RET_FAILURE;
947         }
948
949         msg(" - mdg_device_find_invited_device() ret: [0x%X] [%s]",
950                 ret, mdg_error_to_string(ret));
951
952         if (found_invited_device_list) {
953                 g_list_free_full(found_invited_device_list, _destroy_mdg_device_info);
954                 found_invited_device_list = NULL;
955         }
956
957         return RET_SUCCESS;
958 }
959
960 static int run_request_create_group(MManager *mm, struct menu_data *menu)
961 {
962         int ret = 0;
963         int dev_count = 0;
964         mdg_device_h device = NULL;
965
966         msg("Request create group");
967
968         dev_count = g_list_length(found_invited_device_list);
969
970         if (0 >= dev_count) {
971                 msgr("No Device");
972                 return RET_SUCCESS;
973         }
974
975         int dev_idx = 1;
976         if (strlen(device_idx)) {
977                 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
978                 if (0 >= dev_idx) {
979                         msgp("Invalid index. set to 1");
980                         dev_idx = 1;
981                 }
982         }
983
984         if (found_invited_device_list) {
985                 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
986                 if (NULL == device) {
987                         msgr("Failed to g_hash_table_find");
988                         return RET_FAILURE;
989                 }
990         }
991
992         ret = mdg_request_create_group(handle, device, request_groupid,
993                 receive_request_result, NULL);
994         if (MDG_ERROR_NONE != ret) {
995                 msgr("Failed to Request Create Group: [%s(0x%X)]",
996                         mdg_error_to_string(ret), ret);
997                 return RET_FAILURE;
998         }
999
1000         msg(" - mdg_request_create_group() ret: [0x%X] [%s]",
1001                 ret, mdg_error_to_string(ret));
1002
1003         return RET_SUCCESS;
1004 }
1005
1006 static int run_request_invite(MManager *mm, struct menu_data *menu)
1007 {
1008         int ret = 0;
1009         int grp_count = 0;
1010         int dev_count = 0;
1011         mdg_device_h device = NULL;
1012         mdg_group_h group = NULL;
1013
1014         dev_count = g_list_length(found_invited_device_list);
1015         grp_count = g_list_length(found_group_list);
1016
1017         if (0 >= dev_count || 0 >= grp_count) {
1018                 msgr("No Device");
1019                 return RET_SUCCESS;
1020         }
1021
1022         int grp_idx = 1;
1023         if (strlen(group_idx)) {
1024                 grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
1025                 if (0 >= grp_idx) {
1026                         msgp("Invalid index. set to 1");
1027                         grp_idx = 1;
1028                 }
1029         }
1030
1031         if (found_group_list) {
1032                 group = g_list_nth_data(found_group_list, grp_idx - 1);
1033                 if (NULL == group) {
1034                         msgr("Failed to g_hash_table_find");
1035                         return RET_FAILURE;
1036                 }
1037         }
1038
1039         int dev_idx = 1;
1040         if (strlen(device_idx)) {
1041                 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1042                 if (0 >= dev_idx) {
1043                         msgp("Invalid index. set to 1");
1044                         dev_idx = 1;
1045                 }
1046         }
1047
1048         if (found_invited_device_list) {
1049                 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1050                 if (NULL == device) {
1051                         msgr("Failed to g_hash_table_find");
1052                         return RET_FAILURE;
1053                 }
1054         }
1055
1056         ret = mdg_request_invite_device(handle, group, device, pin,
1057                 receive_request_result, NULL);
1058         if (MDG_ERROR_NONE != ret) {
1059                 msgr("Failed to Request Invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1060                 return RET_FAILURE;
1061         }
1062
1063         msg(" - mdg_request_invite_device() ret: [0x%X] [%s]",
1064                 ret, mdg_error_to_string(ret));
1065
1066         return RET_SUCCESS;
1067 }
1068
1069 static int run_request_eject(MManager *mm, struct menu_data *menu)
1070 {
1071         int ret = 0;
1072         int grp_count = 0;
1073         int dev_count = 0;
1074         mdg_device_h device = NULL;
1075         mdg_group_h group = NULL;
1076
1077         dev_count = g_list_length(found_invited_device_list);
1078         grp_count = g_list_length(found_group_list);
1079
1080         if (0 >= dev_count || 0 >= grp_count) {
1081                 msgr("No Device");
1082                 return RET_SUCCESS;
1083         }
1084
1085         int grp_idx = 1;
1086         if (group_idx != NULL && strlen(group_idx)) {
1087                 grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
1088                 if (0 >= grp_idx) {
1089                         msgp("Invalid index. set to 1");
1090                         grp_idx = 1;
1091                 }
1092         }
1093
1094         if (found_group_list) {
1095                 group = g_list_nth_data(found_group_list, grp_idx - 1);
1096                 if (NULL == group) {
1097                         msgr("Failed to g_hash_table_find");
1098                         return RET_FAILURE;
1099                 }
1100         }
1101
1102         int dev_idx = 1;
1103         if (device_idx != NULL && strlen(device_idx)) {
1104                 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1105                 if (0 >= dev_idx) {
1106                         msgp("Invalid index. set to 1");
1107                         dev_idx = 1;
1108                 }
1109         }
1110
1111         if (found_invited_device_list) {
1112                 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1113                 if (NULL == device) {
1114                         msgr("Failed to g_hash_table_find");
1115                         return RET_FAILURE;
1116                 }
1117         }
1118
1119         ret = mdg_request_eject_device(handle, group, device, receive_request_result,
1120                 NULL);
1121         if (MDG_ERROR_NONE != ret) {
1122                 msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1123                 return RET_FAILURE;
1124         }
1125
1126         msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1127
1128         return RET_SUCCESS;
1129 }
1130
1131 void __req_channel_list_finish_cb(char *device_id, char *channel_id, void *user_data)
1132 {
1133         msgp("\rDevice ID : [%s], Channel ID : [%s]", device_id, channel_id);
1134
1135         channel_t *channel = g_new0(channel_t, 1);
1136         channel->device_id = g_strdup(device_id);
1137         channel->channel_id = g_strdup(channel_id);
1138
1139         found_channel_list = g_list_append(found_channel_list, channel);
1140
1141         return;
1142 }
1143
1144 static int run_request_channel_list(MManager *mm, struct menu_data *menu)
1145 {
1146         int ret = 0;
1147         int dev_count = 0;
1148         mdg_device_h device = NULL;
1149
1150         dev_count = g_list_length(found_invited_device_list);
1151
1152         if (0 >= dev_count) {
1153                 msgr("No Device");
1154                 return RET_SUCCESS;
1155         }
1156
1157         int dev_idx = 1;
1158         if (strlen(device_idx)) {
1159                 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1160                 if (0 >= dev_idx) {
1161                         msgp("Invalid index. set to 1");
1162                         dev_idx = 1;
1163                 }
1164         }
1165
1166         if (found_invited_device_list) {
1167                 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1168                 if (NULL == device) {
1169                         msgr("Failed to g_hash_table_find");
1170                         return RET_FAILURE;
1171                 }
1172         }
1173
1174         ret = mdg_request_channel_list(handle, device, __req_channel_list_finish_cb, NULL);
1175         if (MDG_ERROR_NONE != ret) {
1176                 msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1177                 return RET_FAILURE;
1178         }
1179
1180         msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1181
1182         return RET_SUCCESS;
1183 }
1184
1185 void __channel_cb(int result, char *device_id, char *channel_id, int msg_id,
1186         unsigned char *arg, int len, void *user_data)
1187 {
1188         msgb("[%s] channel callback is called by [%s]'s send message", channel_id, device_id);
1189         msgb("The msg_id is %d, arg : %s, len : %d", msg_id, arg, len);
1190         msgb("result is %d", result);
1191
1192         mdg_device_send_response(handle, device_id, channel_id, msg_id, (unsigned char *)"Ya, Hi", 6);
1193 }
1194
1195
1196 void __channel_opened_cb(int result, mdg_channel_h channel, void *user_data)
1197 {
1198         msgb("result is %d", result);
1199         if (result == MDG_ERROR_NONE)
1200                 msgb("channel opened callback is called. server socket is created");
1201         else
1202                 msgb("channel opened callback is called. but server socket is not created");
1203
1204         unsigned char buf[256] = "SENDSEND";
1205         mdg_channel_write(channel, buf, 256);
1206         //write and recv using mdg_channel_write / mdg_channel_recv
1207 }
1208
1209 static int run_regist_channel(MManager *mm, struct menu_data *menu)
1210 {
1211         int ret = 0;
1212
1213         ret = mdg_device_regist_channel(handle, channel_id, __channel_cb, NULL);
1214         msg(" - mdg_device_regist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1215
1216         ret = mdg_set_channel_opened_callback(handle, channel_id, __channel_opened_cb, NULL);
1217         msg(" - mdg_set_channel_opened_callback() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1218
1219         return RET_SUCCESS;
1220 }
1221
1222 static int run_unregist_channel(MManager *mm, struct menu_data *menu)
1223 {
1224         int ret = 0;
1225
1226         ret = mdg_device_unregist_channel(handle, channel_id);
1227
1228         msg(" - mdg_unregist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1229
1230         return RET_SUCCESS;
1231 }
1232
1233 static int run_set_preconfigured_pin(MManager *mm, struct menu_data *menu)
1234 {
1235         int ret = 0;
1236
1237         ret = mdg_set_preconfigured_pin(handle, pin);
1238
1239         msg(" - mdg_set_preconfigured_pin() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1240
1241         return RET_SUCCESS;
1242 }
1243
1244 void _mdg_channel_client_opened_cb(int result, mdg_channel_h channel, void *user_data)
1245 {
1246         msgp("Client Opened result : %d", result);
1247
1248         unsigned char *buf;
1249         buf = (unsigned char *)malloc(1024);
1250         if (NULL == buf) {
1251                 msgp("memory allocation error");
1252                 return;
1253         }
1254         int len;
1255         mdg_channel_read(channel, &buf, &len);
1256
1257         msgp("Get Data : %s, %d", buf, len);
1258         free(buf);
1259         buf = NULL;
1260 }
1261
1262 static int __request_open_channel(int devidx, int chaidx)
1263 {
1264         int ret = 0;
1265         char *deviceid = NULL;
1266         mdg_device_h device = NULL;
1267         channel_t *channel = NULL;
1268
1269         if (!found_invited_device_list || !found_channel_list) {
1270                         msgr("Find local device first");
1271                         return RET_FAILURE;
1272         }
1273
1274         if (found_invited_device_list) {
1275                 device = g_list_nth_data(found_invited_device_list, devidx - 1);
1276                 if (NULL == device) {
1277                         msgr("Find local device first");
1278                         return RET_FAILURE;
1279                 }
1280         }
1281
1282         if (found_channel_list) {
1283                 channel = g_list_nth_data(found_channel_list, chaidx - 1);
1284                 if (NULL == channel) {
1285                         msgr("Find local device first");
1286                         return RET_FAILURE;
1287                 }
1288         }
1289
1290         if (NULL == device) {
1291                 msgr("device is NULL");
1292                 return RET_FAILURE;
1293         }
1294
1295         if (NULL == channel) {
1296                 msgr("channel is NULL");
1297                 return RET_FAILURE;
1298         }
1299
1300         mdg_device_info_get_device_id(device, &deviceid);
1301         msgp("Open channel between [ID] %s [CHANNEL ID] %s", deviceid, channel->channel_id);
1302         if (deviceid) {
1303                 free(deviceid);
1304                 deviceid = NULL;
1305         }
1306
1307         ret = mdg_request_channel_open(handle, device, channel->channel_id,
1308                 _mdg_channel_client_opened_cb, NULL);
1309         if (MDG_ERROR_NONE != ret)
1310                 msgr("Failed to Send Data: [ID] %s", deviceid);
1311
1312         return ret;
1313 }
1314
1315 static int run_request_open_channel(MManager *mm, struct menu_data *menu)
1316 {
1317         int devidx = 0;
1318         int chaidx = 0;
1319         int count = g_list_length(found_invited_device_list);
1320
1321         if (0 >= count) {
1322                 msgr("No Device");
1323                 return RET_SUCCESS;
1324         }
1325
1326         if (strlen(device_idx)) {
1327                 devidx = (unsigned short)strtol(device_idx, NULL, 10);
1328                 if (0 >= devidx) {
1329                         msgp("Invalid index. set to 1");
1330                         devidx = 1;
1331                 }
1332         }
1333         if (strlen(channel_idx)) {
1334                 chaidx = (unsigned short)strtol(channel_idx, NULL, 10);
1335                 if (0 >= chaidx) {
1336                         msgp("Invalid index. set to 1");
1337                         chaidx = 1;
1338                 }
1339         }
1340         return __request_open_channel(devidx, chaidx);
1341 }
1342
1343 static struct menu_data menu_group_create[] = {
1344         { "0", "Group Name", NULL, NULL, groupid },
1345         { "1", "Run", NULL, run_group_create, NULL },
1346         { NULL, NULL, },
1347 };
1348
1349 static struct menu_data menu_group_find[] = {
1350         { "0", "Timeout", NULL, NULL, timeout },
1351         { "1", "Run", NULL, run_group_find, NULL },
1352         { NULL, NULL, },
1353 };
1354
1355 static struct menu_data menu_group_delete[] = {
1356         { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1357         { "1", "Index", NULL, NULL, group_idx },
1358         { "2", "Run", NULL, run_group_delete, NULL },
1359         { NULL, NULL, },
1360 };
1361
1362 static struct menu_data menu_devices_find[] = {
1363         { "0", "Timeout", NULL, NULL, timeout },
1364         { "1", "Run", NULL, run_devices_find, NULL },
1365         { NULL, NULL, },
1366 };
1367
1368 static struct menu_data menu_group_invite_device[] = {
1369         { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1370         { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
1371         { "2", "Group Index", NULL, NULL, group_idx },
1372         { "3", "Device Index", NULL, NULL, device_idx },
1373         { "4", "PIN", NULL, NULL, pin },
1374         { "5", "Run", NULL, run_device_invite, NULL },
1375         { NULL, NULL, },
1376 };
1377
1378 static struct menu_data menu_group_eject_device[] = {
1379         { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1380         { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1381         { "2", "Group Index", NULL, NULL, group_idx },
1382         { "3", "Device Index", NULL, NULL, device_idx },
1383         { "4", "Run", NULL, run_device_eject, NULL },
1384         { NULL, NULL, },
1385 };
1386
1387 static struct menu_data menu_group_foreach_device[] = {
1388         { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1389         { "1", "Group Index", NULL, NULL, group_idx },
1390         { "2", "Run", NULL, run_group_foreach_device, NULL },
1391         { NULL, NULL, },
1392 };
1393
1394 static struct menu_data menu_send_data[] = {
1395         { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1396         { "1", "Show Channel List", NULL, run_channels_show, NULL },
1397         { "2", "Message", NULL, NULL, message },
1398         { "3", "Device Index", NULL, NULL, device_idx },
1399         { "4", "Channel Index", NULL, NULL, channel_idx },
1400         { "5", "Send", NULL, run_send_data, NULL },
1401         { NULL, NULL, },
1402 };
1403
1404 static struct menu_data menu_devices_find_invited_device[] = {
1405         { "0", "Timeout", NULL, NULL, timeout },
1406         { "1", "Run", NULL, run_devices_find_invited_device, NULL },
1407         { NULL, NULL, },
1408 };
1409
1410 static struct menu_data menu_request_create_group[] = {
1411         { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1412         { "1", "Device Index", NULL, NULL, device_idx },
1413         { "2", "Request Group Name", NULL, NULL, request_groupid },
1414         { "3", "Run", NULL, run_request_create_group, NULL },
1415         { NULL, NULL, },
1416 };
1417
1418 static struct menu_data menu_request_invite[] = {
1419         { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1420         { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1421         { "2", "Group Index", NULL, NULL, group_idx },
1422         { "3", "Device Index", NULL, NULL, device_idx },
1423         { "4", "PIN", NULL, NULL, pin },
1424         { "5", "Run", NULL, run_request_invite, NULL },
1425         { NULL, NULL, },
1426 };
1427
1428 static struct menu_data menu_request_eject[] = {
1429         { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1430         { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1431         { "2", "Group Index", NULL, NULL, group_idx },
1432         { "3", "Device Index", NULL, NULL, device_idx },
1433         { "4", "Run", NULL, run_request_eject, NULL },
1434         { NULL, NULL, },
1435 };
1436
1437 static struct menu_data menu_request_channel_list[] = {
1438         { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1439         { "1", "Device Index", NULL, NULL, device_idx },
1440         { "2", "Run", NULL, run_request_channel_list, NULL },
1441         { NULL, NULL, },
1442 };
1443
1444 static struct menu_data menu_regist_channel[] = {
1445         { "0", "Channel ID", NULL, NULL, channel_id },
1446         { "1", "Run", NULL, run_regist_channel, NULL },
1447         { NULL, NULL, },
1448 };
1449
1450 static struct menu_data menu_unregist_channel[] = {
1451         { "0", "Channel ID", NULL, NULL, channel_id },
1452         { "1", "Run", NULL, run_unregist_channel, NULL },
1453         { NULL, NULL, },
1454 };
1455
1456 static struct menu_data menu_set_preconfigured_pin[] = {
1457         { "0", "PIN", NULL, NULL, pin },
1458         { "1", "Run", NULL, run_set_preconfigured_pin, NULL },
1459         { NULL, NULL, },
1460 };
1461
1462 static struct menu_data menu_request_open_channel[] = {
1463         { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1464         { "1", "Show Channel List", NULL, run_channels_show, NULL },
1465         { "2", "Device Index", NULL, NULL, device_idx },
1466         { "3", "Channel Index", NULL, NULL, channel_idx },
1467         { "4", "Run", NULL, run_request_open_channel, NULL },
1468         { NULL, NULL, },
1469 };
1470
1471 struct menu_data menu_mdg_manager[] = {
1472         { "1", "Show Local Device", NULL, run_device_show_local_device, NULL }, // O
1473         { "2", "Create Group", menu_group_create, NULL, NULL }, // 0
1474         { "3", "Find Group(s)", menu_group_find, NULL, NULL }, // 0
1475         { "4", "Show Group(s)", NULL, run_group_show, NULL }, // 0
1476         { "5", "Delete Group", menu_group_delete, NULL, NULL }, // 0
1477         { "6", "Find Device(s)", menu_devices_find, NULL, NULL }, // 0
1478         { "7", "Show Device(s)", NULL, run_devices_show, NULL }, // 0
1479         { "8", "Invite Device", menu_group_invite_device, NULL, NULL }, // 0
1480         { "9", "Eject Device", menu_group_eject_device, NULL, NULL }, // 0
1481         { "10", "Foreach Device", menu_group_foreach_device, NULL, NULL },
1482         { "11", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0
1483         { "12", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0
1484         { "13", "Request Create Group", menu_request_create_group, NULL, NULL }, // 0
1485         { "14", "Request Invite", menu_request_invite, NULL, NULL }, // 0
1486         { "15", "Request Eject", menu_request_eject, NULL, NULL }, // 0
1487         { "16", "Request Channel List", menu_request_channel_list, NULL, NULL }, // 0
1488         { "17", "Regist Channel", menu_regist_channel, NULL, NULL },
1489         { "18", "Unregist Channel", menu_unregist_channel, NULL, NULL },
1490         { "19", "Send Message", menu_send_data, NULL, NULL }, // 0
1491         { "20", "Set Preconfigured PIN", menu_set_preconfigured_pin, NULL, NULL }, // 0
1492         { "21", "Request Open Channel", menu_request_open_channel, NULL, NULL }, // 0
1493 };