From: Abhishek Chandra Date: Mon, 13 Nov 2017 12:18:45 +0000 (+0530) Subject: [bluetooth] bt_unit_test changes for IPSP Support in TizenNext X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_next;p=platform%2Fcore%2Fapi%2Fbluetooth.git [bluetooth] bt_unit_test changes for IPSP Support in TizenNext Following IPSP functions support has been added through this patch 1) IPSP intailize 2) IPSP deinitailize 3) IPSP connect 4) IPSP disconnect 5) Callbacks and Event handling for IPSP Change-Id: Ib1060c3c71307f358271d1272e6449fd22f81354 Signed-off-by: Abhishek Chandra --- diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index dd866f7..354de12 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -64,7 +64,7 @@ const char *custom_uuid = "fa87c0d0-afac-11de-8a39-0800200c9a66"; #define HTTP_STATUS_UUID "2ab8" #define HTTP_SECURITY_UUID "2abb" #define HTTP_STATUS_DESC_UUID "2902" - +#define IPSP_PORT 3344 static bt_unit_test_table_e current_tc_table; static char remote_addr[18] = "F6:FB:8F:D8:C8:7C"; static char ipsp_iface_name[17] = ""; @@ -9491,7 +9491,7 @@ int test_input_callback(void *data) char client_ipv6[100] = {0, }; char *addr = NULL; - printf("\n****** IPSP Application Server Started ******\n"); + TC_PRT("\n****** IPSP Application Server Started ******\n"); getifaddrs(&ifap); @@ -9500,6 +9500,7 @@ int test_input_callback(void *data) if (!memcmp(ifa->ifa_name, ipsp_iface_name, IFNAMSIZ)) { getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); + TC_PRT("[IPV6]Host : %s \n",host); addr = strchr(host, '%'); if (addr != NULL) { addr = g_strndup(host, (addr - host)); @@ -9511,49 +9512,65 @@ int test_input_callback(void *data) freeifaddrs(ifap); - bzero((char *) &serverAddr, sizeof(serverAddr)); - - serverAddr.sin6_flowinfo = 0; - serverAddr.sin6_family = AF_INET6; - serverAddr.sin6_addr = in6addr_any; - serverAddr.sin6_port = htons(3344); - serverAddr.sin6_scope_id = if_nametoindex(ipsp_iface_name); - inet_pton(AF_INET6, addr, &(serverAddr.sin6_addr.s6_addr)); - - g_free(addr); - - /* Create the IPSP APP server socket */ - serverSocket = socket(AF_INET6, SOCK_STREAM, 0); - if (serverSocket < 0) - TC_PRT("\nIPSP server Error : In socket creation !"); - else - TC_PRT("\nIPSP Server : Socket created.."); + if(addr != NULL) + { + bzero((char *) &serverAddr, sizeof(serverAddr)); + serverAddr.sin6_flowinfo = 0; + serverAddr.sin6_family = AF_INET6; + serverAddr.sin6_addr = in6addr_any; + serverAddr.sin6_port = htons(IPSP_PORT); + serverAddr.sin6_scope_id = if_nametoindex(ipsp_iface_name); + inet_pton(AF_INET6, addr, &(serverAddr.sin6_addr.s6_addr)); + g_free(addr); - /* Bind the address struct to the socket */ - if (bind(serverSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0) - TC_PRT("\nIPSP server Error : In socket binding !"); - else - TC_PRT("\nIPSP Server : Socket binding done.."); + /* Create the IPSP APP server socket */ + serverSocket = socket(AF_INET6, SOCK_STREAM, 0); + if (serverSocket < 0) { + TC_PRT("\nIPSP server Error : In socket creation !"); + break; + } + else + TC_PRT("\nIPSP Server : Socket created.."); - /* Listen on the socket, with 1 max connection requests queued */ - if (listen(serverSocket, 1) < 0) - TC_PRT("\nIPSP server Error : In socket listening !"); - else - TC_PRT("\nIPSP server : Socket listening, waiting for connection...\n"); - /* Accept call creates a new socket for the incoming connection */ - clilen = sizeof(clientAddr); - ipsp_server_sock = accept(serverSocket, (struct sockaddr *) &clientAddr, &clilen); - if (ipsp_server_sock < 0) - TC_PRT("\nIPSP server Error : While accepting incoming connection !"); + /* Bind the address struct to the socket */ + if (bind(serverSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0) { + TC_PRT("\nIPSP server Error : In socket binding !"); + close(serverSocket); + break; + } + else + TC_PRT("\nIPSP Server : Socket binding done.."); - inet_ntop(AF_INET6, &(clientAddr.sin6_addr), client_ipv6, 100); - TC_PRT("\n****** IPSP server : Incoming connection from client... %s successful, ready to send/receive IPV6 data ******", client_ipv6); + /* Listen on the socket, with 1 max connection requests queued */ + if (listen(serverSocket, 1) < 0) { + TC_PRT("\nIPSP server Error : In socket listening !"); + close(serverSocket); + break; + } + else + TC_PRT("\nIPSP server : Socket listening, waiting for connection...\n"); + + /* Accept call creates a new socket for the incoming connection */ + clilen = sizeof(clientAddr); + ipsp_server_sock = accept(serverSocket, (struct sockaddr *) &clientAddr, &clilen); + if (ipsp_server_sock < 0) { + TC_PRT("\nIPSP server Error : While accepting incoming connection !"); + close(serverSocket); + break; + } - close(serverSocket); + inet_ntop(AF_INET6, &(clientAddr.sin6_addr), client_ipv6, 100); + TC_PRT("\n****** IPSP server : Incoming connection from client... %s successful, ready to send/receive IPV6 data ******", client_ipv6); + close(serverSocket); + } + else + { + TC_PRT("Matching Address is Not Found , Wait till the Connected Event is recieved from STACK"); + } break; } case BT_UNIT_TEST_FUNCTION_IPSP_CONNECT_WITH_APP_SERVER_SOCKET: { @@ -9567,7 +9584,7 @@ int test_input_callback(void *data) } saddr = g_test_param.params[0]; - printf("\n****** IPSP Application Client Started ******\n"); + TC_PRT("\n****** IPSP Application Client Started ******\n"); /* Create the IPSP APP Client socket */ ipsp_client_sock = socket(AF_INET6, SOCK_STREAM, 0); @@ -9581,23 +9598,28 @@ int test_input_callback(void *data) if (server == NULL) TC_PRT("\nIPSP Client Error : No such host !"); + else { - memset((char *) &serverAddr, 0, sizeof(serverAddr)); - serverAddr.sin6_flowinfo = 0; - serverAddr.sin6_family = AF_INET6; - serverAddr.sin6_addr = in6addr_any; - serverAddr.sin6_port = htons(3344); - serverAddr.sin6_scope_id = if_nametoindex(ipsp_iface_name); + TC_PRT("\nIPSP Client GetHostbyName Success!"); + memset((char *) &serverAddr, 0, sizeof(serverAddr)); + serverAddr.sin6_flowinfo = 0; + serverAddr.sin6_family = AF_INET6; + serverAddr.sin6_addr = in6addr_any; + serverAddr.sin6_port = htons(IPSP_PORT); + serverAddr.sin6_scope_id = if_nametoindex(ipsp_iface_name); - memmove((char *) &serverAddr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length); + memmove((char *) &serverAddr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length); - /* Connect with IPSP APP Server socket */ - if (connect(ipsp_client_sock, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0) - TC_PRT("\nIPSP Client Error : %d while connecting with server !", errno); - else - TC_PRT("\n****** IPSP Client : Connection with : %s successful, ready to send/receive IPV6 data ******\n", saddr); + TC_PRT("\nIPSP Client Attempt To Connect to server %s!",serverAddr.sin6_addr.s6_addr); - __bt_free_test_param(&g_test_param); + /* Connect with IPSP APP Server socket */ + if (connect(ipsp_client_sock, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0) + TC_PRT("\nIPSP Client Error : %d while connecting with server !", errno); + else + TC_PRT("\n****** IPSP Client : Connection with : %s successful, ready to send/receive IPV6 data ******\n", saddr); + + __bt_free_test_param(&g_test_param); + } break; } case BT_UNIT_TEST_FUNCTION_IPSP_SEND_IPV6_APP_DATA: {