10 #include <glib-object.h>
15 #define RESET_COLOR "\e[m"
16 #define MAKE_RED "\e[31m"
17 #define MAKE_GREEN "\e[32m"
19 #define __FUNC_ENTER__ printf("%s() entering...\n", __func__)
20 #define __FUNC_EXIT__ printf("%s() leaving...\n", __func__)
22 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
23 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
25 #define MAX_ADVERTISE 255
27 #define MAX_SESSION 255
29 static const char *print_error(int err_type)
34 case ASP_ERROR_NOT_PERMITTED:
35 return "NOT_PERMITTED";
36 case ASP_ERROR_OUT_OF_MEMORY:
37 return "OUT_OF_MEMORY";
38 case ASP_ERROR_PERMISSION_DENIED:
39 return "PERMISSION_DENIED";
40 case ASP_ERROR_RESOURCE_BUSY:
41 return "RESOURCE_BUSY";
42 case ASP_ERROR_INVALID_PARAMETER:
43 return "INVALID_PARAMETER";
44 case ASP_ERROR_CONNECTION_TIME_OUT:
45 return "CONNECTION_TIME_OUT";
46 case ASP_ERROR_NOT_SUPPORTED:
47 return "NOT_SUPPORTED";
48 case ASP_ERROR_NOT_INITIALIZED:
49 return "NOT_INITIALIZED";
50 case ASP_ERROR_ALREADY_INITIALIZED:
51 return "ALREADY_INITIALIZED";
52 case ASP_ERROR_COMMUNICATION_FAILED:
53 return "COMMUNICATION_FAILED";
54 case ASP_ERROR_OPERATION_FAILED:
55 return "ASP_ERROR_OPERATION_FAILED";
56 case ASP_ERROR_IN_PROGRESS:
58 case ASP_ERROR_SERVICE_NOT_FOUND:
59 return "SERVICE_NOT_FOUND";
60 case ASP_ERROR_SESSION_NOT_FOUND:
61 return "SESSION_NOT_FOUND";
62 case ASP_ERROR_NETWORK_ROLE_REJECTED:
63 return "NETWORK_ROLE_REJECTED";
69 static const char* print_advert_status_reason(asp_advert_status_reason_e reason)
72 case ASP_ADVERT_STATUS_REASON_SUCCESS:
73 return "ASP_ADVERT_STATUS_REASON_SUCCESS";
74 case ASP_ADVERT_STATUS_REASON_SERVICE_DUPLICATED:
75 return "ASP_ADVERT_STATUS_REASON_SERVICE_DUPLICATED";
76 case ASP_ADVERT_STATUS_REASON_OTHER_FAILURE:
77 return "ASP_ADVERT_STATUS_REASON_OTHER_FAILURE";
83 static const char* print_p2p_role_scheme(asp_advert_p2p_role_scheme_e role)
86 case ASP_ADVERT_P2P_ROLE_SCHEME_ANY:
87 return "ASP_ADVERT_P2P_ROLE_SCHEME_ANY";
88 case ASP_ADVERT_P2P_ROLE_SCHEME_GO:
89 return "ASP_ADVERT_P2P_ROLE_SCHEME_GO";
90 case ASP_ADVERT_P2P_ROLE_SCHEME_GC:
91 return "ASP_ADVERT_P2P_ROLE_SCHEME_GC";
97 static const char* print_session_connect_status(int status)
100 case ASP_CONNECT_STATUS_NETWORK_ROLE_REJECTED:
101 return "ASP_CONNECT_STATUS_NETWORK_ROLE_REJECTED";
102 case ASP_CONNECT_STATUS_CONNECTION_LIMIT_REACHED:
103 return "ASP_CONNECT_STATUS_CONNECTION_LIMIT_REACHED";
104 case ASP_CONNECT_STATUS_REQUEST_SENT:
105 return "ASP_CONNECT_STATUS_REQUEST_SENT";
106 case ASP_CONNECT_STATUS_REQUEST_RECEIVED:
107 return "ASP_CONNECT_STATUS_REQUEST_RECEIVED";
108 case ASP_CONNECT_STATUS_REQUEST_DEFERRED:
109 return "ASP_CONNECT_STATUS_REQUEST_DEFERRED";
110 case ASP_CONNECT_STATUS_REQUEST_ACCEPTED:
111 return "ASP_CONNECT_STATUS_REQUEST_ACCEPTED";
112 case ASP_CONNECT_STATUS_REQUEST_FAILED:
113 return "ASP_CONNECT_STATUS_REQUEST_FAILED";
114 case ASP_CONNECT_STATUS_GROUP_FORMATION_STARTED:
115 return "ASP_CONNECT_STATUS_GROUP_FORMATION_STARTED";
116 case ASP_CONNECT_STATUS_GROUP_FORMATION_COMPLETED:
117 return "ASP_CONNECT_STATUS_GROUP_FORMATION_COMPLETED";
118 case ASP_CONNECT_STATUS_GROUP_FORMATION_FAILED:
119 return "ASP_CONNECT_STATUS_GROUP_FORMATION_FAILED";
125 static const char* print_session_state(int session_state)
127 switch (session_state) {
128 case ASP_SESSION_STATE_ERROR:
129 return "ASP_SESSION_STATE_ERROR";
130 case ASP_SESSION_STATE_CLOSED:
131 return "ASP_SESSION_STATE_CLOSED";
132 case ASP_SESSION_STATE_INITIATED:
133 return "ASP_SESSION_STATE_INITIATED";
134 case ASP_SESSION_STATE_REQUESTED:
135 return "ASP_SESSION_STATE_REQUESTED";
136 case ASP_SESSION_STATE_OPEN:
137 return "ASP_SESSION_STATE_OPEN";
143 static const char* print_session_close_state(int state)
146 case ASP_SESSION_CLOSE_OK:
147 return "ASP_SESSION_CLOSE_OK";
148 case ASP_SESSION_CLOSE_DISASSOCIATED:
149 return "ASP_SESSION_CLOSE_DISASSOCIATED";
150 case ASP_SESSION_CLOSE_LOCAL_CLOSE:
151 return "ASP_SESSION_CLOSE_LOCAL_CLOSE";
152 case ASP_SESSION_CLOSE_REMOTE_CLOSE:
153 return "ASP_SESSION_CLOSE_REMOTE_CLOSE";
154 case ASP_SESSION_CLOSE_SYSTEM_FAILURE:
155 return "ASP_SESSION_CLOSE_SYSTEM_FAILURE";
156 case ASP_SESSION_CLOSE_NO_RESPONSE:
157 return "ASP_SESSION_CLOSE_NO_RESPONSE";
163 static const char* print_port_status(int status)
166 case ASP_PORT_STATUS_LOCAL_PORT_ALLOWED:
167 return "ASP_PORT_STATUS_LOCAL_PORT_ALLOWED";
168 case ASP_PORT_STATUS_LOCAL_PORT_BLOCKED:
169 return "ASP_PORT_STATUS_LOCAL_PORT_BLOCKED";
170 case ASP_PORT_STATUS_FAILURE:
171 return "ASP_PORT_STATUS_FAILURE";
172 case ASP_PORT_STATUS_REMOTE_PORT_ALLOWED:
173 return "ASP_PORT_STATUS_REMOTE_PORT_ALLOWED";
180 static const char* print_service_status(int status)
183 case ASP_SERVICE_STATUS_NOT_ADVERTISED:
184 return "ASP_SERVICE_STATUS_NOT_ADVERTISED";
185 case ASP_SERVICE_STATUS_ADVERTISED:
186 return "ASP_SERVICE_STATUS_ADVERTISED";
200 CMD_SEEK_SET_SEARCH_RESULT_CB,
201 CMD_SEEK_UNSET_SEARCH_RESULT_CB,
202 CMD_ADVERT_SET_STATUS_CHANGED_CB,
203 CMD_ADVERT_UNSET_STATUS_CHANGED_CB,
204 CMD_SESSION_SET_REQUEST_CB,
205 CMD_SESSION_UNSET_REQUST_CB,
206 CMD_SESSION_SET_CONFIG_REQUEST_CB,
207 CMD_SESSION_UNSET_CONFIG_REQUEST_CB,
208 CMD_SESSION_SET_CONNECT_STATUS_CB,
209 CMD_SESSION_UNSET_CONNECT_STATUS_CB,
210 CMD_SESSION_SET_STATUS_CB,
211 CMD_SESSION_UNSET_STATUS_CB,
212 CMD_SESSION_SET_PORT_STATUS_CB,
213 CMD_SESSION_UNSET_PORT_STATUS_CB,
218 CMD_ADVERT_SET_SERVICE_TYPE,
219 CMD_ADVERT_SET_AUTO_ACCEPT,
222 CMD_ADVERT_REMOVE_INFO,
223 CMD_ADVERT_SET_STATUS,
224 CMD_ADVERT_SET_DISCOVERY_TECH,
225 CMD_ADVERT_SET_PREF_CONN,
226 CMD_ADVERT_SET_P2P_ROLE,
227 CMD_ADVERT_GET_P2P_ROLE,
228 CMD_ADVERT_SET_P2P_CONFIG,
229 CMD_ADVERT_GET_P2P_CONFIG,
230 CMD_ADVERT_SET_P2P_RSP,
240 CMD_SEEK_REMOVE_INFO,
241 CMD_SEEK_SET_DISCOVERY_TECH,
242 CMD_SEEK_SET_PREF_CONN,
253 CMD_SESSION_SET_INFO,
254 CMD_SESSION_GET_INFO,
256 CMD_SESSION_SET_P2P_ROLE_SCHEME,
257 CMD_SESSION_GET_P2P_ROLE_SCHEME,
259 CMD_SESSION_SET_P2P_CONFIG_METHOD,
260 CMD_SESSION_GET_P2P_CONFIG_METHOD,
262 CMD_SESSION_GET_CLOSE_STATUS,
266 CMD_SESSION_GET_HANDLE,
267 CMD_SESSION_SET_STATE_READY,
269 CMD_SESSION_BIND_PORT,
270 CMD_SESSION_RELEASE_PORT,
280 menu_str_s g_menu_str[] = {
281 { CMD_QUIT, "CMD_QUIT" },
282 { CMD_FULL_MENU, "CMD_FULL_MENU" },
283 { CMD_INITIALIZE, "CMD_INITIALIZE" },
284 { CMD_DEINITIALIZE, "CMD_DEINITIALIZE" },
286 {CMD_SEEK_SET_SEARCH_RESULT_CB, "CMD_SEEK_SET_SEARCH_RESULT_CB"},
287 {CMD_SEEK_UNSET_SEARCH_RESULT_CB, "CMD_SEEK_UNSET_SEARCH_RESULT_CB"},
288 {CMD_ADVERT_SET_STATUS_CHANGED_CB, "CMD_ADVERT_SET_STATUS_CHANGED_CB"},
289 {CMD_ADVERT_UNSET_STATUS_CHANGED_CB, "CMD_ADVERT_UNSET_STATUS_CHANGED_CB"},
290 {CMD_SESSION_SET_REQUEST_CB, "CMD_SESSION_SET_REQUEST_CB"},
291 {CMD_SESSION_UNSET_REQUST_CB, "CMD_SESSION_UNSET_REQUST_CB"},
292 {CMD_SESSION_SET_CONFIG_REQUEST_CB, "CMD_SESSION_SET_CONFIG_REQUEST_CB"},
293 {CMD_SESSION_UNSET_CONFIG_REQUEST_CB, "CMD_SESSION_UNSET_CONFIG_REQUEST_CB"},
294 {CMD_SESSION_SET_CONNECT_STATUS_CB, "CMD_SESSION_SET_CONNECT_STATUS_CB"},
295 {CMD_SESSION_UNSET_CONNECT_STATUS_CB, "CMD_SESSION_UNSET_CONNECT_STATUS_CB"},
296 {CMD_SESSION_SET_STATUS_CB, "CMD_SESSION_SET_STATUS_CB"},
297 {CMD_SESSION_UNSET_STATUS_CB, "CMD_SESSION_UNSET_STATUS_CB"},
298 {CMD_SESSION_SET_PORT_STATUS_CB, "CMD_SESSION_SET_PORT_STATUS_CB"},
299 {CMD_SESSION_UNSET_PORT_STATUS_CB, "CMD_SESSION_UNSET_PORT_STATUS_CB"},
301 {CMD_ADVERT_CREATE, "CMD_ADVERT_CREATE"},
302 {CMD_ADVERT_DESTROY, "CMD_ADVERT_DESTROY"},
304 {CMD_ADVERT_SET_SERVICE_TYPE, "CMD_ADVERT_SET_SERVICE_TYPE"},
305 {CMD_ADVERT_SET_AUTO_ACCEPT, "CMD_ADVERT_SET_AUTO_ACCEPT"},
306 {CMD_ADVERT_ADD_INFO, "CMD_ADVERT_ADD_INFO"},
307 {CMD_ADVERT_GET_INFO, "CMD_ADVERT_GET_INFO"},
308 {CMD_ADVERT_REMOVE_INFO, "CMD_ADVERT_REMOVE_INFO"},
309 {CMD_ADVERT_SET_STATUS, "CMD_ADVERT_SET_STATUS"},
310 {CMD_ADVERT_SET_DISCOVERY_TECH, "CMD_ADVERT_SET_DISCOVERY_TECH"},
311 {CMD_ADVERT_SET_PREF_CONN, "CMD_ADVERT_SET_PREF_CONN"},
312 {CMD_ADVERT_SET_P2P_ROLE, "CMD_ADVERT_SET_P2P_ROLE"},
313 {CMD_ADVERT_GET_P2P_ROLE, "CMD_ADVERT_GET_P2P_ROLE"},
314 {CMD_ADVERT_SET_P2P_CONFIG, "CMD_ADVERT_SET_P2P_CONFIG"},
315 {CMD_ADVERT_GET_P2P_CONFIG, "CMD_ADVERT_GET_P2P_CONFIG"},
316 {CMD_ADVERT_SET_P2P_RSP, "CMD_ADVERT_SET_P2P_RSP"},
318 {CMD_ADVERT_START, "CMD_ADVERT_START"},
319 {CMD_ADVERT_STOP, "CMD_ADVERT_STOP"},
320 {CMD_ADVERT_CHANGE, "CMD_ADVERT_CHANGE"},
322 {CMD_SEEK_CREATE, "CMD_SEEK_CREATE"},
323 {CMD_SEEK_DESTROY, "CMD_SEEK_DESTROY"},
325 {CMD_SEEK_ADD_INFO, "CMD_SEEK_ADD_INFO"},
326 {CMD_SEEK_REMOVE_INFO, "CMD_SEEK_REMOVE_INFO"},
327 {CMD_SEEK_SET_DISCOVERY_TECH, "CMD_SEEK_SET_DISCOVERY_TECH"},
328 {CMD_SEEK_SET_PREF_CONN, "CMD_SEEK_SET_PREF_CONN"},
330 {CMD_SEEK_START, "CMD_SEEK_START"},
331 {CMD_SEEK_STOP, "CMD_SEEK_STOP"},
333 {CMD_SESSION_CREATE, "CMD_SESSION_CREATE"},
334 {CMD_SESSION_DESTROY, "CMD_SESSION_DESTROY"},
336 {CMD_SESSION_GET_MAC, "CMD_SESSION_GET_MAC"},
337 {CMD_SESSION_GET_ID, "CMD_SESSION_GET_ID"},
339 {CMD_SESSION_SET_INFO, "CMD_SESSION_SET_INFO"},
340 {CMD_SESSION_GET_INFO, "CMD_SESSION_GET_INFO"},
342 {CMD_SESSION_SET_P2P_ROLE_SCHEME, "CMD_SESSION_SET_P2P_ROLE_SCHEME"},
343 {CMD_SESSION_GET_P2P_ROLE_SCHEME, "CMD_SESSION_GET_P2P_ROLE_SCHEME"},
345 {CMD_SESSION_SET_P2P_CONFIG_METHOD, "CMD_SESSION_SET_P2P_CONFIG_METHOD"},
346 {CMD_SESSION_GET_P2P_CONFIG_METHOD, "CMD_SESSION_GET_P2P_CONFIG_METHOD"},
348 {CMD_SESSION_GET_CLOSE_STATUS, "CMD_SESSION_GET_CLOSE_STATUS"},
350 {CMD_SESSION_CONNECT, "CMD_SESSION_CONNECT"},
351 {CMD_SESSOIN_CONFIRM, "CMD_SESSOIN_CONFIRM"},
352 {CMD_SESSION_GET_HANDLE, "CMD_SESSION_GET_HANDLE"},
353 {CMD_SESSION_SET_STATE_READY, "CMD_SESSION_SET_STATE_READY"},
354 {CMD_SESSION_CLOSE, "CMD_SESSION_CLOSE"},
355 {CMD_SESSION_BIND_PORT, "CMD_SESSION_BIND_PORT"},
356 {CMD_SESSION_RELEASE_PORT, "CMD_SESSION_RELEASE_PORT"},
361 GMainLoop* main_loop;
364 struct appdata* g_test_appdata;
366 static asp_advert_service_h local_advert = NULL;
367 static asp_seek_service_h local_seek = NULL;
368 static asp_session_h local_session = NULL;
370 struct appdata* get_appdata()
372 return g_test_appdata;
375 void set_appdata(struct appdata* p)
380 static inline void prt_help(const char *cmd)
382 printf("%s -t [dest ID]\n", cmd);
383 printf(" -u [my ID]\n");
384 printf(" -p [passwd]\n");
385 printf(" -a [alias]\n");
388 static int get_param(int argc, char **argv, struct appdata *ad)
390 printf("Parsing argument...\n");
392 while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1) {
393 printf("Parsing argument...:%c\n", opt);
402 printf("Argument: \n");
409 printf("Call Test Program\n");
410 printf(" %d: quit\n", CMD_QUIT);
411 printf(" %d: Full menu\n", CMD_FULL_MENU);
414 char* cmd_transform(char*str)
418 static char static_buffer[255];
429 /* replance "_" to space */
430 for (i = 0, j = 4; i < len; i++, j++) {
432 if (str[j] >= 'A' && str[j] <= 'Z')
433 static_buffer[i] = str[j] + 'a' - 'A';
434 else if (str[j] == '_')
435 static_buffer[i] = ' ';
437 static_buffer[i] = str[j];
439 static_buffer[j] = '\0';
441 return static_buffer;
447 printf("Call Test Program\n");
449 for (i = 0; g_menu_str[i].cmd != -1; i++) {
452 if (i == 2 || i == 4 || i == 6 || i == 12 || i == 17 ||
453 i == 20 || i == 24 || i == 26 || i == 28 || i == 36)
455 printf(" %02d: %-32s ", g_menu_str[i].cmd,
456 cmd_transform(g_menu_str[i].menu_str));
457 if (i == 2 || i == 4 || i == 6 || i == 12 || i == 17 ||
458 i == 20 || i == 24 || i == 26 || i == 28 || i == 36)
465 int is_digit(const char* str)
473 if (strlen(str) == 0)
477 for (i = 0; i < len; i++) {
478 if (str[i] < '0' || str[i] > '9')
485 void seek_search_result_cb(int error_code,
486 asp_seek_service_h seek_service,
487 const char *service_mac,
489 asp_wps_type_e config_method,
490 const char *instance_name,
491 const char *service_info,
493 unsigned char status,
499 void advert_status_changed_cb(asp_advert_service_h adv_service,
500 asp_service_status_e status,
501 asp_advert_status_reason_e reason,
507 void session_request_cb(int error_code,
508 asp_advert_service_h adv_service,
509 asp_session_h session,
510 const char *device_name,
513 bool get_network_config_pin,
514 const char *network_config_pin,
520 void session_config_request_cb(int error_code,
521 asp_session_h session,
523 const char *config_pin,
529 void session_connect_status_cb(int error_code,
530 asp_session_h session,
531 asp_connect_status_e status,
532 const char *deferred_resp,
539 void session_status_cb(int error_code,
540 asp_session_h session,
541 asp_session_state_e state,
542 const char *additional_info,
548 void session_port_status_cb(int error_code,
549 asp_session_h session,
550 const char *ip_address,
553 asp_port_status_e status,
559 int init_asp_client(struct appdata *ad)
564 ret = asp_initialize();
565 printf("asp_initialize() result=[%d]\n", ret);
567 ret = asp_seek_set_search_result_cb(seek_search_result_cb, (void*)ad);
568 printf("asp_seek_set_search_result_cb result=[%d]\n", ret);
570 ret = asp_advert_set_status_changed_cb(advert_status_changed_cb, (void*)ad);
571 printf("asp_advert_set_status_changed_cb result=[%d]\n", ret);
573 ret = asp_session_set_request_cb(session_request_cb, (void*)ad);
574 printf("asp_session_set_request_cb result=[%d]\n", ret);
576 ret = asp_session_set_config_request_cb(session_config_request_cb, (void*)ad);
577 printf("asp_session_set_config_request_cb result=[%d]\n", ret);
579 ret = asp_session_set_connect_status_cb(session_connect_status_cb, (void*)ad);
580 printf("asp_session_set_connect_status_cb result=[%d]\n", ret);
582 ret = asp_session_set_status_cb(session_status_cb, (void*)ad);
583 printf("asp_session_set_status_cb result=[%d]\n", ret);
585 ret = asp_session_set_port_status_cb(session_port_status_cb, (void*)ad);
586 printf("asp_session_set_port_status_cb result=[%d]\n", ret);
592 void test_full_menu()
601 struct appdata *ad = get_appdata(ad);
604 g_main_loop_quit(ad->main_loop);
611 struct appdata *ad = get_appdata(ad);
614 ret = init_asp_client(ad);
615 printf("init_asp_client() result=[%d]\n", ret);
624 ret = asp_deinitialize();
625 printf("asp_deinitialize() result=[%d]\n", ret);
628 void test_asp_seek_set_search_result_cb()
630 struct appdata *ad = get_appdata(ad);
633 ret = asp_seek_set_search_result_cb(seek_search_result_cb, ad);
634 printf("asp_seek_set_search_result_cb() result=[%d]\n", ret);
639 void test_asp_seek_unset_search_result_cb()
643 ret = asp_seek_unset_search_result_cb();
644 printf("asp_seek_unset_search_result_cb() result=[%d]\n", ret);
649 void test_asp_advert_set_status_changed_cb()
651 struct appdata *ad = get_appdata(ad);
654 ret = asp_advert_set_status_changed_cb(advert_status_changed_cb, ad);
655 printf("asp_advert_unset_status_changed_cb() result=[%d]\n", ret);
660 void test_asp_advert_unset_status_changed_cb()
664 ret = asp_advert_unset_status_changed_cb();
665 printf("asp_advert_unset_status_changed_cb() result=[%d]\n", ret);
670 void test_asp_session_set_request_cb()
672 struct appdata *ad = get_appdata(ad);
675 ret = asp_session_set_request_cb(session_request_cb, ad);
676 printf("asp_session_set_request_cb() result=[%d]\n", ret);
681 void test_asp_session_unset_request_cb()
685 ret = asp_session_unset_request_cb();
686 printf("asp_session_unset_request_cb() result=[%d]\n", ret);
691 void test_asp_session_set_config_request_cb()
693 struct appdata *ad = get_appdata(ad);
696 ret = asp_session_set_config_request_cb(session_config_request_cb, ad);
697 printf("asp_session_set_config_request_cb() result=[%d]\n", ret);
702 void test_asp_session_unset_config_request_cb()
706 ret = asp_session_unset_config_request_cb();
707 printf("asp_session_unset_config_request_cb() result=[%d]\n", ret);
712 void test_asp_session_set_connect_status_cb()
714 struct appdata *ad = get_appdata(ad);
717 ret = asp_session_set_connect_status_cb(session_connect_status_cb, ad);
718 printf("asp_session_set_connect_status_cb() result=[%d]\n", ret);
723 void test_asp_session_unset_connect_status_cb()
727 ret = asp_session_unset_connect_status_cb();
728 printf("asp_session_unset_connect_status_cb() result=[%d]\n", ret);
733 void test_asp_session_set_status_cb()
735 struct appdata *ad = get_appdata(ad);
738 ret = asp_session_set_status_cb(session_status_cb, ad);
739 printf("asp_session_set_status_cb() result=[%d]\n", ret);
744 void test_asp_session_unset_status_cb()
748 ret = asp_session_unset_status_cb();
749 printf("asp_session_unset_status_cb() result=[%d]\n", ret);
754 void test_asp_session_set_port_status_cb()
756 struct appdata *ad = get_appdata(ad);
759 ret = asp_session_set_port_status_cb(session_port_status_cb, ad);
760 printf("asp_session_set_port_status_cb() result=[%d]\n", ret);
765 void test_asp_session_unset_port_status_cb()
769 ret = asp_session_unset_connect_status_cb();
770 printf("asp_session_unset_connect_status_cb() result=[%d]\n", ret);
775 void test_asp_advert_create()
777 char instance_name[64] = {0, };
780 printf("Input instance :\n");
781 if (scanf(" %64[^\n]s", instance_name) < 0)
784 if (strlen(instance_name) <= 0) {
785 printf("invalid instance_name !!\n");
789 printf("instance_name: [%s]\n", instance_name);
790 ret = asp_advert_create(instance_name, &local_advert);
791 if (ret == ASP_ERROR_NONE) {
792 printf(MAKE_GREEN"asp_advert_create"RESET_COLOR"\n");
793 printf("local_advert [%p]\n", local_advert);
795 printf(MAKE_RED"asp_advert_create : %s ", print_error(ret));
796 printf(RESET_COLOR"\n");
802 void test_asp_advert_destroy()
806 ret = asp_advert_destroy(local_advert);
807 if (ret == ASP_ERROR_NONE) {
808 printf(MAKE_GREEN"asp_advert_destroy"RESET_COLOR"\n");
811 printf(MAKE_RED"asp_advert_destroy : %s ", print_error(ret));
812 printf(RESET_COLOR"\n");
818 void test_asp_advert_set_service_type()
820 char service_type[256] = {0, };
823 printf("Input advertise_type :\n");
824 if (scanf(" %256[^\n]s", service_type) < 0)
827 if (strlen(service_type) <= 0) {
828 printf("invalid advertise_type !!\n");
832 printf("service_type: [%s]\n", service_type);
833 ret = asp_advert_set_service_type(local_advert, service_type);
834 if (ret == ASP_ERROR_NONE) {
835 printf(MAKE_GREEN"asp_advert_set_service_type"RESET_COLOR"\n");;
837 printf(MAKE_RED"asp_advert_set_service_type : %s ", print_error(ret));
838 printf(RESET_COLOR"\n");
844 void test_asp_advert_set_auto_accept()
849 printf("Enter ASP service auto accept : \n");
850 if (scanf("%d", &auto_accept) < 0)
853 ret = asp_advert_set_auto_accept(local_advert, auto_accept);
854 if (ret == ASP_ERROR_NONE) {
855 printf(MAKE_GREEN"asp_advert_set_auto_accept"RESET_COLOR"\n");
857 printf(MAKE_RED"asp_advert_set_auto_accept : %s ", print_error(ret));
858 printf(RESET_COLOR"\n");
864 void test_asp_advert_add_info()
866 char key[256] = {0, };
867 char value[256] = {0, };
870 printf("Enter ASP service information key :\n");
871 if (scanf(" %256[^\n]s", key) < 0)
873 printf("Enter ASP service information value :\n");
874 if (scanf(" %256[^\n]s", value) < 0)
877 ret = asp_advert_add_info(local_advert, key, value);
878 if (ret == ASP_ERROR_NONE) {
879 printf(MAKE_GREEN"asp_advert_add_info"RESET_COLOR"\n");
881 printf(MAKE_RED"asp_advert_add_info : %s ", print_error(ret));
882 printf(RESET_COLOR"\n");
888 void test_asp_advert_get_info()
891 char key[256] = {0, };
895 printf("Enter ASP service information key :\n");
896 if (scanf(" %256[^\n]s", key) < 0)
899 ret = asp_advert_get_info(local_advert, key,
901 if (ret == ASP_ERROR_NONE) {
903 printf(MAKE_GREEN"value [%s]"RESET_COLOR"\n", value);
904 printf(MAKE_GREEN"asp_advert_get_info"RESET_COLOR"\n");
906 printf(MAKE_RED"asp_advert_get_info : %s ", print_error(ret));
907 printf(RESET_COLOR"\n");
913 void test_asp_advert_remove_info()
915 char key[256] = {0, };
918 printf("Enter ASP service information key :\n");
919 if (scanf(" %256[^\n]s", key) < 0)
922 ret = asp_advert_remove_info(local_advert, key);
923 if (ret == ASP_ERROR_NONE) {
924 printf(MAKE_GREEN"asp_advert_remove_info"RESET_COLOR"\n");
926 printf(MAKE_RED"asp_advert_remove_info : %s ", print_error(ret));
927 printf(RESET_COLOR"\n");
933 void test_asp_advert_set_status()
935 unsigned char status = 0;
938 printf("Enter ASP service status : \n");
939 printf("1 = available to use\n");
940 printf("0 = not available to use\n");
941 if (scanf("%hhu", &status) < 0)
944 ret = asp_advert_set_status(local_advert, status);
945 if (ret == ASP_ERROR_NONE) {
946 printf(MAKE_GREEN"asp_advert_set_status"RESET_COLOR"\n");
948 printf(MAKE_RED"asp_advert_set_status : %s ", print_error(ret));
949 printf(RESET_COLOR"\n");
955 void test_asp_advert_set_discovery_tech()
960 printf("Enter ASP advertising tech : \n");
961 printf("Please enter logical OR value of below techs\n");
962 printf("ASP_DISCOVERY_TECH_P2P = 0x01\n");
963 printf("ASP_DISCOVERY_TECH_BLE = 0x02\n");
964 printf("ASP_DISCOVERY_TECH_NFC = 0x04\n");
965 printf("ASP_DISCOVERY_TECH_INFRA = 0x08\n");
966 printf("ASP_DISCOVERY_TECH_NAN = 0x10\n");
967 if (scanf("%d", &tech) < 0)
970 ret = asp_advert_set_discovery_tech(local_advert, tech);
971 if (ret == ASP_ERROR_NONE) {
972 printf(MAKE_GREEN"asp_advert_set_discovery_tech"RESET_COLOR"\n");
974 printf(MAKE_RED"asp_advert_set_discovery_tech : %s ", print_error(ret));
975 printf(RESET_COLOR"\n");
981 void test_asp_advert_set_preferred_connection()
983 unsigned char pref = 0;
986 printf("Enter ASP advertising preferred connection : \n");
987 if (scanf("%hhu", &pref) < 0)
990 ret = asp_advert_set_preferred_connection(local_advert, pref);
991 if (ret == ASP_ERROR_NONE) {
992 printf(MAKE_GREEN"asp_advert_set_preferred_connection"RESET_COLOR"\n");
994 printf(MAKE_RED"asp_advert_set_preferred_connection : %s ", print_error(ret));
995 printf(RESET_COLOR"\n");
1001 void test_asp_advert_set_p2p_role_scheme()
1003 unsigned char role = 0;
1006 printf("Enter ASP p2p service role : ");
1007 printf("0 = Don't care\n");
1008 printf("1 = The receiving interface shall be the GO\n");
1009 if (scanf("%hhu", &role) < 0)
1012 ret = asp_advert_set_p2p_role_scheme(local_advert, role);
1013 if (ret == ASP_ERROR_NONE) {
1014 printf(MAKE_GREEN"asp_advert_set_p2p_role_scheme"RESET_COLOR"\n");
1016 printf(MAKE_RED"asp_advert_set_p2p_role_scheme : %s ", print_error(ret));
1017 printf(RESET_COLOR"\n");
1023 void test_asp_advert_get_p2p_role_scheme()
1025 asp_advert_p2p_role_scheme_e role = 0;
1029 ret = asp_advert_get_p2p_role_scheme(local_advert, &role);
1030 if (ret == ASP_ERROR_NONE) {
1031 printf(MAKE_GREEN"asp_advert_get_p2p_role_scheme"RESET_COLOR"\n");
1032 printf(MAKE_GREEN"role [%d]"RESET_COLOR"\n", (int)role);
1034 printf(MAKE_RED"asp_advert_get_p2p_role_scheme : %s ", print_error(ret));
1035 printf(RESET_COLOR"\n");
1041 void test_asp_advert_set_p2p_config_method()
1043 unsigned int config_method = 0;
1046 printf("Enter ASP service p2p config method : \n");
1047 printf("1 = P2Ps default configuration or WSC PIN\n");
1048 printf("2 = WSC PIN method both display and keypad\n");
1049 printf("3 = WSC PIN method only display\n");
1050 printf("4 = WSC PIN method only keypad\n");
1051 if (scanf(" %d", &config_method) < 0)
1054 ret = asp_advert_set_p2p_config_method(local_advert, config_method);
1055 if (ret == ASP_ERROR_NONE) {
1056 printf(MAKE_GREEN"asp_advert_set_p2p_config_method"RESET_COLOR"\n");
1058 printf(MAKE_RED"asp_advert_set_p2p_config_method : %s ", print_error(ret));
1059 printf(RESET_COLOR"\n");
1065 void test_asp_advert_get_p2p_config_method()
1067 unsigned int config_method = 0;
1070 ret = asp_advert_get_p2p_config_method(local_advert, &config_method);
1071 if (ret == ASP_ERROR_NONE) {
1072 printf(MAKE_GREEN"asp_advert_get_p2p_config_method [%u] "RESET_COLOR"\n", config_method);
1074 printf(MAKE_RED"asp_advert_get_p2p_config_method : %s ", print_error(ret));
1075 printf(RESET_COLOR"\n");
1081 void test_asp_advert_set_p2p_response()
1083 char service_rsp[256] = {0, };
1086 printf("Input service_rsp :\n");
1087 if (scanf(" %256[^\n]s", service_rsp) < 0)
1090 if (strlen(service_rsp) <= 0)
1093 printf("service_info: [%s]\n", service_rsp);
1094 ret = asp_advert_set_p2p_response(local_advert, service_rsp, strlen(service_rsp));
1095 if (ret == ASP_ERROR_NONE) {
1096 printf(MAKE_GREEN"asp_advert_set_p2p_response"RESET_COLOR"\n");
1098 printf(MAKE_RED"asp_advert_set_p2p_response : %s ", print_error(ret));
1099 printf(RESET_COLOR"\n");
1105 void test_asp_advert_start_advertising()
1109 ret = asp_advert_start_advertising(local_advert);
1110 if (ret == ASP_ERROR_NONE) {
1111 printf(MAKE_GREEN"asp_advert_start_advertising"RESET_COLOR"\n");
1113 printf(MAKE_RED"asp_advert_start_advertising : %s ", print_error(ret));
1114 printf(RESET_COLOR"\n");
1120 void test_asp_advert_stop_advertising()
1124 ret = asp_advert_stop_advertising(local_advert);
1125 if (ret == ASP_ERROR_NONE) {
1126 printf(MAKE_GREEN"asp_advert_start_advertising"RESET_COLOR"\n");
1128 printf(MAKE_RED"asp_advert_start_advertising : %s ", print_error(ret));
1129 printf(RESET_COLOR"\n");
1135 void test_asp_advert_change_service_status()
1137 unsigned char status = 0;
1140 ret = asp_advert_change_service_status(local_advert, status);
1141 if (ret == ASP_ERROR_NONE) {
1142 printf(MAKE_GREEN"asp_advert_change_service_status"RESET_COLOR"\n");
1144 printf(MAKE_RED"asp_advert_change_service_status : %s ", print_error(ret));
1145 printf(RESET_COLOR"\n");
1151 void test_asp_seek_create()
1153 char service_type[64] = {0, };
1156 printf("Input service_type :\n");
1157 if (scanf(" %64[^\n]s", service_type) < 0)
1160 if (strlen(service_type) <= 0)
1163 printf("service_type: [%s]\n", service_type);
1164 ret = asp_seek_create(service_type, &local_seek);
1165 if (ret == ASP_ERROR_NONE) {
1166 printf(MAKE_GREEN"asp_seek_create"RESET_COLOR"\n");
1167 printf("seek handle [%p]\n", local_seek);
1169 printf(MAKE_RED"asp_seek_create : %s ", print_error(ret));
1170 printf(RESET_COLOR"\n");
1176 void test_asp_seek_destroy()
1180 ret = asp_seek_destroy(local_seek);
1181 if (ret == ASP_ERROR_NONE) {
1182 printf(MAKE_GREEN"asp_seek_destroy"RESET_COLOR"\n");
1184 printf(MAKE_RED"asp_seek_destroy : %s ", print_error(ret));
1185 printf(RESET_COLOR"\n");
1191 void test_asp_seek_add_info()
1193 char key[256] = {0, };
1196 printf("Enter ASP service information key :\n");
1197 if (scanf(" %256[^\n]s", key) < 0)
1200 ret = asp_seek_add_info(local_seek, key);
1201 if (ret == ASP_ERROR_NONE) {
1202 printf(MAKE_GREEN"asp_seek_add_info"RESET_COLOR"\n");
1204 printf(MAKE_RED"asp_seek_add_info : %s ", print_error(ret));
1205 printf(RESET_COLOR"\n");
1211 void test_asp_seek_remove_info()
1213 char key[256] = {0, };
1216 printf("Enter ASP service information key :\n");
1217 if (scanf(" %256[^\n]s", key) < 0)
1220 ret= asp_seek_remove_info(local_seek, key);
1221 if (ret == ASP_ERROR_NONE) {
1222 printf(MAKE_GREEN"asp_seek_remove_info"RESET_COLOR"\n");
1224 printf(MAKE_RED"asp_seek_remove_info : %s ", print_error(ret));
1225 printf(RESET_COLOR"\n");
1231 void test_asp_seek_set_discovery_tech()
1236 printf("Enter ASP seeking tech : \n");
1237 printf("Please enter logical OR value of below techs\n");
1238 printf("ASP_DISCOVERY_TECH_P2P = 0x01\n");
1239 printf("ASP_DISCOVERY_TECH_BLE = 0x02\n");
1240 printf("ASP_DISCOVERY_TECH_NFC = 0x04\n");
1241 printf("ASP_DISCOVERY_TECH_INFRA = 0x08\n");
1242 printf("ASP_DISCOVERY_TECH_NAN = 0x10\n");
1243 if (scanf("%d", &tech) < 0)
1246 ret = asp_seek_set_discovery_tech(local_seek, tech);
1247 if (ret == ASP_ERROR_NONE) {
1248 printf(MAKE_GREEN"asp_seek_set_discovery_tech"RESET_COLOR"\n");
1250 printf(MAKE_RED"asp_seek_set_discovery_tech : %s ", print_error(ret));
1251 printf(RESET_COLOR"\n");
1257 void test_asp_seek_set_preferred_connection()
1259 unsigned char pref = 0;
1262 printf("Enter ASP seeking preferred connection : \n");
1263 if (scanf("%hhu", &pref) < 0)
1266 ret = asp_seek_set_preferred_connection(local_seek, pref);
1267 if (ret == ASP_ERROR_NONE) {
1268 printf(MAKE_GREEN"asp_seek_set_preferred_connection"RESET_COLOR"\n");
1270 printf(MAKE_RED"asp_seek_set_preferred_connection : %s ", print_error(ret));
1271 printf(RESET_COLOR"\n");
1277 void test_asp_seek_start()
1281 ret = asp_seek_start(local_seek);
1282 if (ret == ASP_ERROR_NONE) {
1283 printf(MAKE_GREEN"asp_seek_start"RESET_COLOR"\n");
1285 printf(MAKE_RED"asp_seek_start : %s ", print_error(ret));
1286 printf(RESET_COLOR"\n");
1292 void test_asp_seek_stop()
1296 ret = asp_seek_stop(local_seek);
1297 if (ret == ASP_ERROR_NONE) {
1298 printf(MAKE_GREEN"asp_seek_stop"RESET_COLOR"\n");
1300 printf(MAKE_RED"asp_seek_stop : %s ", print_error(ret));
1301 printf(RESET_COLOR"\n");
1307 void test_asp_session_create()
1311 char *mac_addr = NULL;
1312 unsigned int adv_id = 0;
1314 printf("\nEnter advertise id: ");
1315 if (scanf("%u", &adv_id) < 1)
1318 printf("\nEnter target address: ");
1319 if (scanf("%18ms", &mac_addr) < 1)
1322 ret = asp_session_create(mac_addr, adv_id, &local_session);
1323 if (ret == ASP_ERROR_NONE) {
1324 printf(MAKE_GREEN"asp_session_create"RESET_COLOR"\n");
1325 printf("session id [%p]", local_session);
1327 printf(MAKE_RED"asp_session_create : %s ", print_error(ret));
1328 printf(RESET_COLOR"\n");
1334 void test_asp_session_destroy()
1338 ret = asp_session_destroy(local_session);
1339 if (ret == ASP_ERROR_NONE) {
1340 printf(MAKE_GREEN"asp_session_destroy"RESET_COLOR"\n");
1342 printf(MAKE_RED"asp_session_destroy : %s ", print_error(ret));
1343 printf(RESET_COLOR"\n");
1349 void test_asp_session_get_mac()
1351 char *session_mac = NULL;
1354 ret = asp_session_get_mac(local_session, &session_mac);
1355 if (ret == ASP_ERROR_NONE) {
1356 printf(MAKE_GREEN"asp_session_get_mac"RESET_COLOR"\n");
1357 printf("session_mac [%s]", session_mac);
1359 printf(MAKE_RED"asp_session_get_mac : %s ", print_error(ret));
1360 printf(RESET_COLOR"\n");
1366 void test_asp_session_get_id()
1368 unsigned int session_id = 0;
1371 ret = asp_session_get_id(local_session, &session_id);
1372 if (ret == ASP_ERROR_NONE) {
1373 printf(MAKE_GREEN"asp_session_get_id"RESET_COLOR"\n");
1374 printf("session_info [%u]", session_id);
1376 printf(MAKE_RED"asp_session_get_id : %s ", print_error(ret));
1377 printf(RESET_COLOR"\n");
1383 void test_asp_session_set_info()
1385 char *session_info = NULL;
1388 printf("\nEnter session_info: ");
1389 if (scanf("%128ms", &session_info) < 1)
1392 ret = asp_session_set_info(local_session, session_info);
1393 g_free(session_info);
1394 if (ret == ASP_ERROR_NONE) {
1395 printf(MAKE_GREEN"asp_session_set_info"RESET_COLOR"\n");
1397 printf(MAKE_RED"asp_session_set_info : %s ", print_error(ret));
1398 printf(RESET_COLOR"\n");
1404 void test_asp_session_get_info()
1406 char *session_info = NULL;
1409 ret = asp_session_get_info(local_session, &session_info);
1410 if (ret == ASP_ERROR_NONE) {
1411 printf(MAKE_GREEN"asp_session_get_info"RESET_COLOR"\n");
1412 printf("session_info [%s]", session_info);
1414 printf(MAKE_RED"asp_session_get_info : %s ", print_error(ret));
1415 printf(RESET_COLOR"\n");
1421 void test_asp_session_set_p2p_role_scheme()
1423 int role = ASP_ADVERT_P2P_ROLE_SCHEME_ANY;
1426 printf("\nEnter network role: ");
1427 printf("\n0 = Don't care");
1428 printf("\n1 = shall be the GO\n");
1429 if (scanf("%d", &role) < 1)
1432 ret = asp_session_set_p2p_role_scheme(local_session,
1433 (asp_advert_p2p_role_scheme_e)role);
1434 if (ret == ASP_ERROR_NONE) {
1435 printf(MAKE_GREEN"asp_session_set_p2p_role_scheme"RESET_COLOR"\n");
1437 printf(MAKE_RED"asp_session_set_p2p_role_scheme : %s ", print_error(ret));
1438 printf(RESET_COLOR"\n");
1444 void test_asp_session_get_p2p_role_scheme()
1446 asp_advert_p2p_role_scheme_e role;
1449 ret = asp_session_get_p2p_role_scheme(local_session, &role);
1450 if (ret == ASP_ERROR_NONE) {
1451 printf(MAKE_GREEN"asp_session_get_p2p_role_scheme"RESET_COLOR"\n");
1452 printf("network role [%u]", role);
1454 printf(MAKE_RED"asp_session_get_p2p_role_scheme : %s ", print_error(ret));
1455 printf(RESET_COLOR"\n");
1461 void test_asp_session_set_p2p_config_method()
1463 int config_method = ASP_WPS_TYPE_NONE;
1466 printf("\nEnter network config: ");
1467 printf("\n1 = P2Ps default configuration or WSC PIN\n");
1468 printf("\n2 = WSC PIN method only\n");
1469 if (scanf("%d", &config_method) < 1)
1472 ret = asp_session_set_p2p_config_method(local_session,
1473 (asp_wps_type_e)config_method);
1474 if (ret == ASP_ERROR_NONE) {
1475 printf(MAKE_GREEN"asp_session_set_p2p_config_method"RESET_COLOR"\n");
1477 printf(MAKE_RED"asp_session_set_p2p_config_method : %s ", print_error(ret));
1478 printf(RESET_COLOR"\n");
1484 void test_asp_session_get_p2p_config_method()
1486 asp_wps_type_e config_method = 0;
1489 ret = asp_session_get_p2p_config_method(local_session, &config_method);
1490 if (ret == ASP_ERROR_NONE) {
1491 printf(MAKE_GREEN"asp_session_get_p2p_config_method"RESET_COLOR"\n");
1492 printf("network config [%d]", config_method);
1494 printf(MAKE_RED"asp_session_get_p2p_config_method : %s ", print_error(ret));
1495 printf(RESET_COLOR"\n");
1501 void test_asp_session_get_close_status()
1506 ret = asp_session_get_close_status(local_session, &status);
1507 if (ret == ASP_ERROR_NONE) {
1508 printf(MAKE_GREEN"asp_session_get_close_status"RESET_COLOR"\n");
1509 printf("close status [%d]", status);
1511 printf(MAKE_RED"asp_session_get_close_status : %s ", print_error(ret));
1512 printf(RESET_COLOR"\n");
1518 void test_asp_session_connect()
1522 ret = asp_session_connect(local_session);
1523 if (ret == ASP_ERROR_NONE) {
1524 printf(MAKE_GREEN"asp_session_connect"RESET_COLOR"\n");
1526 printf(MAKE_RED"asp_session_connect : %s ", print_error(ret));
1527 printf(RESET_COLOR"\n");
1532 void test_asp_session_confirm()
1537 printf("\nEnter confirm : ");
1538 if (scanf("%d", &confirmed) < 1)
1541 ret = asp_session_confirm(local_session, confirmed, NULL);
1542 if (ret == ASP_ERROR_NONE) {
1543 printf(MAKE_GREEN"asp_session_confirm"RESET_COLOR"\n");
1545 printf(MAKE_RED"asp_session_confirm : %s ", print_error(ret));
1546 printf(RESET_COLOR"\n");
1552 void test_asp_session_get_handle()
1554 char *mac_addr = NULL;
1555 unsigned int session_id = 0;
1559 printf("\nEnter target address: ");
1560 if (scanf("%17ms", &mac_addr) < 1)
1563 printf("\nEnter session id: ");
1564 if (scanf("%u", &session_id) < 1)
1567 ret = asp_session_get_handle(mac_addr, session_id, &local_session);
1568 if (ret == ASP_ERROR_NONE) {
1569 printf(MAKE_GREEN"asp_session_get_handle"RESET_COLOR"\n");
1571 printf(MAKE_RED"asp_session_get_handle : %s ", print_error(ret));
1572 printf(RESET_COLOR"\n");
1578 void test_asp_session_set_state_ready()
1582 ret = asp_session_set_state_ready(local_session);
1583 if (ret == ASP_ERROR_NONE) {
1584 printf(MAKE_GREEN"asp_session_set_state_ready"RESET_COLOR"\n");
1585 local_session = NULL;
1587 printf(MAKE_RED"asp_session_set_state_ready : %s ", print_error(ret));
1588 printf(RESET_COLOR"\n");
1594 void test_asp_session_close()
1598 ret = asp_session_close(local_session);
1599 if (ret == ASP_ERROR_NONE) {
1600 printf(MAKE_GREEN"asp_session_close"RESET_COLOR"\n");
1601 local_session = NULL;
1603 printf(MAKE_RED"asp_session_close : %s ", print_error(ret));
1604 printf(RESET_COLOR"\n");
1610 void test_asp_session_bind_port()
1614 char *ip_address = NULL;
1618 printf("\nEnter IP address: ");
1619 if (scanf("%17ms", &ip_address) < 1)
1622 printf("\nEnter port: ");
1623 if (scanf("%i", &port) < 1)
1626 printf("\nEnter proto: ");
1627 if (scanf("%i", &proto) < 1)
1630 ret = asp_session_bind_port(local_session, ip_address, port, proto);
1631 if (ret == ASP_ERROR_NONE) {
1632 printf(MAKE_GREEN"asp_session_bind_port"RESET_COLOR"\n");
1634 printf(MAKE_RED"asp_session_bind_port : %s ", print_error(ret));
1635 printf(RESET_COLOR"\n");
1641 void test_asp_session_release_port()
1645 char *ip_address = NULL;
1649 printf("\nEnter IP address: ");
1650 if (scanf("%17ms", &ip_address) < 1)
1653 printf("\nEnter port: ");
1654 if (scanf("%i", &port) < 1)
1657 printf("\nEnter proto: ");
1658 if (scanf("%i", &proto) < 1)
1661 ret = asp_session_release_port(local_session, ip_address, port, proto);
1662 if (ret == ASP_ERROR_NONE) {
1663 printf(MAKE_GREEN"asp_session_release_port"RESET_COLOR"\n");
1665 printf(MAKE_RED"asp_session_release_port : %s ", print_error(ret));
1666 printf(RESET_COLOR"\n");
1672 typedef void (*test_func)(void);
1679 menu_func_s g_menu_func[] = {
1680 {CMD_QUIT, test_quit },
1681 {CMD_FULL_MENU, test_full_menu},
1682 {CMD_INITIALIZE, test_init },
1683 {CMD_DEINITIALIZE, test_deinit},
1685 {CMD_SEEK_SET_SEARCH_RESULT_CB, test_asp_seek_set_search_result_cb},
1686 {CMD_SEEK_UNSET_SEARCH_RESULT_CB, test_asp_seek_unset_search_result_cb},
1687 {CMD_ADVERT_SET_STATUS_CHANGED_CB, test_asp_advert_set_status_changed_cb},
1688 {CMD_ADVERT_UNSET_STATUS_CHANGED_CB, test_asp_advert_unset_status_changed_cb},
1689 {CMD_SESSION_SET_REQUEST_CB, test_asp_session_set_request_cb},
1690 {CMD_SESSION_UNSET_REQUST_CB, test_asp_session_unset_request_cb},
1691 {CMD_SESSION_SET_CONFIG_REQUEST_CB, test_asp_session_set_config_request_cb},
1692 {CMD_SESSION_UNSET_CONFIG_REQUEST_CB, test_asp_session_unset_config_request_cb},
1693 {CMD_SESSION_SET_CONNECT_STATUS_CB, test_asp_session_set_connect_status_cb},
1694 {CMD_SESSION_UNSET_CONNECT_STATUS_CB, test_asp_session_unset_connect_status_cb},
1695 {CMD_SESSION_SET_STATUS_CB, test_asp_session_set_status_cb},
1696 {CMD_SESSION_UNSET_STATUS_CB, test_asp_session_unset_status_cb},
1697 {CMD_SESSION_SET_PORT_STATUS_CB, test_asp_session_set_port_status_cb},
1698 {CMD_SESSION_UNSET_PORT_STATUS_CB, test_asp_session_unset_port_status_cb},
1700 {CMD_ADVERT_CREATE, test_asp_advert_create},
1701 {CMD_ADVERT_DESTROY, test_asp_advert_destroy},
1703 {CMD_ADVERT_SET_SERVICE_TYPE, test_asp_advert_set_service_type},
1704 {CMD_ADVERT_SET_AUTO_ACCEPT, test_asp_advert_set_auto_accept},
1705 {CMD_ADVERT_ADD_INFO, test_asp_advert_add_info},
1706 {CMD_ADVERT_GET_INFO, test_asp_advert_get_info},
1707 {CMD_ADVERT_REMOVE_INFO, test_asp_advert_remove_info},
1708 {CMD_ADVERT_SET_STATUS, test_asp_advert_set_status},
1709 {CMD_ADVERT_SET_DISCOVERY_TECH, test_asp_advert_set_discovery_tech},
1710 {CMD_ADVERT_SET_PREF_CONN, test_asp_advert_set_preferred_connection},
1711 {CMD_ADVERT_SET_P2P_ROLE, test_asp_advert_set_p2p_role_scheme},
1712 {CMD_ADVERT_GET_P2P_ROLE, test_asp_advert_get_p2p_role_scheme},
1713 {CMD_ADVERT_SET_P2P_CONFIG, test_asp_advert_set_p2p_config_method},
1714 {CMD_ADVERT_GET_P2P_CONFIG, test_asp_advert_get_p2p_config_method},
1715 {CMD_ADVERT_SET_P2P_RSP, test_asp_advert_set_p2p_response},
1717 {CMD_ADVERT_START, test_asp_advert_start_advertising},
1718 {CMD_ADVERT_STOP, test_asp_advert_stop_advertising},
1719 {CMD_ADVERT_CHANGE, test_asp_advert_change_service_status},
1721 {CMD_SEEK_CREATE, test_asp_seek_create},
1722 {CMD_SEEK_DESTROY, test_asp_seek_destroy},
1724 {CMD_SEEK_ADD_INFO, test_asp_seek_add_info},
1725 {CMD_SEEK_REMOVE_INFO, test_asp_seek_remove_info},
1726 {CMD_SEEK_SET_DISCOVERY_TECH, test_asp_seek_set_discovery_tech},
1727 {CMD_SEEK_SET_PREF_CONN, test_asp_seek_set_preferred_connection},
1729 {CMD_SEEK_START, test_asp_seek_start},
1730 {CMD_SEEK_STOP, test_asp_seek_stop},
1732 {CMD_SESSION_CREATE, test_asp_session_create},
1733 {CMD_SESSION_DESTROY, test_asp_session_destroy},
1735 {CMD_SESSION_GET_MAC, test_asp_session_get_mac},
1736 {CMD_SESSION_GET_ID, test_asp_session_get_id},
1738 {CMD_SESSION_SET_INFO, test_asp_session_set_info},
1739 {CMD_SESSION_GET_INFO, test_asp_session_get_info},
1741 {CMD_SESSION_SET_P2P_ROLE_SCHEME, test_asp_session_set_p2p_role_scheme},
1742 {CMD_SESSION_GET_P2P_ROLE_SCHEME, test_asp_session_get_p2p_role_scheme},
1744 {CMD_SESSION_SET_P2P_CONFIG_METHOD, test_asp_session_set_p2p_config_method},
1745 {CMD_SESSION_GET_P2P_CONFIG_METHOD, test_asp_session_get_p2p_config_method},
1747 {CMD_SESSION_GET_CLOSE_STATUS, test_asp_session_get_close_status},
1749 {CMD_SESSION_CONNECT, test_asp_session_connect},
1750 {CMD_SESSOIN_CONFIRM, test_asp_session_confirm},
1751 {CMD_SESSION_GET_HANDLE, test_asp_session_get_handle},
1752 {CMD_SESSION_SET_STATE_READY, test_asp_session_set_state_ready},
1753 {CMD_SESSION_CLOSE, test_asp_session_close},
1754 {CMD_SESSION_BIND_PORT, test_asp_session_bind_port},
1755 {CMD_SESSION_RELEASE_PORT, test_asp_session_release_port},
1759 void process_input(const char *input, gpointer user_data)
1763 cmd = strtol(input, NULL, 0);
1764 if (is_digit(input) < 0 || strlen(input) == 0 || errno == ERANGE || errno
1768 printf("cmd=[%d]\n", cmd);
1769 g_menu_func[cmd].func();
1772 static gboolean test_terminal_read_std_input(GIOChannel * source,
1773 GIOCondition condition, gpointer user_data)
1777 static char buf[1024];
1781 n = read(fd, buf, 1024);
1783 buf[n - 1] = '\0'; /* remove new line... */
1785 printf("Error: read() from stdin returns 0.\n");
1787 printf("input: read, err\n");
1791 process_input(buf, user_data);
1796 int main(int argc, char **argv)
1798 GMainLoop *main_loop;
1800 struct appdata *ad = NULL;
1802 #if !GLIB_CHECK_VERSION(2, 36, 0)
1806 main_loop = g_main_loop_new(NULL, FALSE);
1808 ad = (struct appdata*)malloc(sizeof(struct appdata));
1811 ad->main_loop = main_loop;
1813 int r = get_param(argc, argv, ad);
1818 int std_input_fd = 0;
1819 GIOChannel *gio2 = g_io_channel_unix_new(std_input_fd);
1820 g_io_add_watch(gio2, G_IO_IN, (GIOFunc) test_terminal_read_std_input, ad);
1821 g_io_channel_unref(gio2);
1825 g_main_loop_run(main_loop);