[bluetooth] bt_unit_test changes for IPSP Support in TizenNext 31/163631/3
authorAbhishek Chandra <abhishek.ch@samsung.com>
Tue, 12 Dec 2017 11:58:01 +0000 (17:28 +0530)
committerAbhishek Chandra <abhishek.ch@samsung.com>
Wed, 13 Dec 2017 06:45:06 +0000 (12:15 +0530)
 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: I5746265bb3eeec090054bfce75c577c7b2dc918e
Signed-off-by: Abhishek Chandra <abhishek.ch@samsung.com>
test/bt_unit_test.c

index 24130231a1e0c2701bc18284e5095031cc2bc94b..2da961a600b1e788fa317beda60c1ae32fa91f59 100644 (file)
@@ -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] = "";
@@ -9497,7 +9497,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);
 
@@ -9506,6 +9506,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));
@@ -9517,12 +9518,13 @@ int test_input_callback(void *data)
 
                        freeifaddrs(ifap);
 
+                       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(3344);
+                               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));
 
@@ -9530,36 +9532,49 @@ int test_input_callback(void *data)
 
                        /* Create the IPSP APP server socket */
                        serverSocket = socket(AF_INET6, SOCK_STREAM, 0);
-                       if (serverSocket < 0)
+                               if (serverSocket < 0) {
                                TC_PRT("\nIPSP server Error : In socket creation !");
+                                       break;
+                               }
                        else
                                TC_PRT("\nIPSP Server : Socket created..");
 
 
                        /* Bind the address struct to the socket */
-                       if (bind(serverSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0)
+                               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..");
 
 
                        /* Listen on the socket, with 1 max connection requests queued */
-                       if (listen(serverSocket, 1) < 0)
+                               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)
+                               if (ipsp_server_sock  < 0) {
                                TC_PRT("\nIPSP server Error : While accepting incoming connection !");
+                                       close(serverSocket);
+                                       break;
+                               }
 
                        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: {
@@ -9573,7 +9588,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);
@@ -9587,23 +9602,27 @@ 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);
+                               /* 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);
+                               __bt_free_test_param(&g_test_param);
+                       }
                        break;
                }
                case BT_UNIT_TEST_FUNCTION_IPSP_SEND_IPV6_APP_DATA: {