Revert "SIG-1358 #resolve"
diff --git a/lib/Makefile b/lib/Makefile
index fe61376..6533590 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -34,10 +34,6 @@
wfa_sock.o: wfa_sock.c ../inc/wfa_sock.h ../inc/wfa_types.h
-wfa_serial.o: wfa_serial.c ../inc/wfa_serial.h ../inc/wfa_nw_al.h ../inc/wfa_types.h
-
-wfa_nw_al.o: wfa_nw_al.c ../inc/wfa_nw_al.h ../inc/wfa_types.h
-
wfa_thr.o: wfa_thr.c ../inc/wfa_tg.h
wfa_wmmps.o: wfa_wmmps.c ../inc/wfa_wmmps.h
diff --git a/lib/wfa_ca_resp.c b/lib/wfa_ca_resp.c
index b5c6bd1..542a22f 100644
--- a/lib/wfa_ca_resp.c
+++ b/lib/wfa_ca_resp.c
@@ -153,7 +153,7 @@
sprintf(gRespStr, "status,ERROR,Command Not Defined\r\n");
/* make sure if getting send error, will close the socket */
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
done = 0;
@@ -185,7 +185,7 @@
default:
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -214,7 +214,7 @@
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -252,7 +252,7 @@
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -275,7 +275,7 @@
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done ;
}
@@ -300,7 +300,7 @@
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -324,7 +324,7 @@
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -403,7 +403,7 @@
strncat(gRespStr, "\r\n", 4);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -476,8 +476,8 @@
}
strncat(gRespStr, "\r\n", 4);
}
-
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
printf("gRespStr = %s", gRespStr);
return done;
}
@@ -504,7 +504,7 @@
sprintf(gRespStr, "status,INVALID\r\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
return done;
@@ -536,7 +536,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -568,7 +568,7 @@
printf("unknown status\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -598,7 +598,7 @@
sprintf(gRespStr, "status,COMPLETE,mac,00:00:00:00:00:00\r\n");
printf("unknown status\n");
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -632,7 +632,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -661,7 +661,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -698,7 +698,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -730,7 +730,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -776,7 +776,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -807,7 +807,7 @@
break;
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -842,7 +842,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -870,7 +870,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -898,7 +898,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -926,7 +926,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -954,7 +954,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -981,7 +981,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1022,7 +1022,7 @@
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1054,7 +1054,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1083,7 +1083,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
@@ -1128,7 +1128,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1157,7 +1157,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
@@ -1209,7 +1209,8 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
-// wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+
return done;
}
@@ -1238,7 +1239,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1271,7 +1272,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1352,7 +1353,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1383,7 +1384,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1412,7 +1413,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
@@ -1586,7 +1587,7 @@
DPRINT_INFO(WFA_OUT, " %s\n", gRespStr);
}
- // wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
+ wfaCtrlSend(gCaSockfd, (BYTE *)gRespStr, strlen(gRespStr));
return done;
}
diff --git a/lib/wfa_nw_al.c b/lib/wfa_nw_al.c
deleted file mode 100644
index 39e929e..0000000
--- a/lib/wfa_nw_al.c
+++ /dev/null
@@ -1,542 +0,0 @@
-/****************************************************************************
-*
-* Copyright (c) 2015 Wi-Fi Alliance
-*
-* Permission to use, copy, modify, and/or distribute this software for any
-* purpose with or without fee is hereby granted, provided that the above
-* copyright notice and this permission notice appear in all copies.
-*
-* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
-* USE OR PERFORMANCE OF THIS SOFTWARE.
-*
-*****************************************************************************/
-
-/**
-* File: wfa_nw_al.c
-* library functions for network layer abstraction,
-*
-* They are common library to open, close and send receive over any defined interface
-* so above layer will be modular
-*
-* Revision History:
-*
-*
-*/
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "wfa_debug.h"
-#include "wfa_nw_al.h"
-#include "wfa_serial.h"
-#include "wfa_sock.h"
-
-
-
-
-/* Set the read time out for read function*/
-#define READ_TIME_OUT_SEC 30
-#define READ_TIME_OUT_U_SEC 0
-
-
-/**
-* @brief This function will create and oipen the interface, like tcp /udp or serial.
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char * ifaceName interface name, eth0, /dev/ttyS0, ...
-* @param int typeOfConn type of connection like TCP / serial
-* @param int servFlag true: it a server connection, false: client connection
-* this relavent with ethernet connection.
-*
-*
-**/
-
-int wfaOpenInterFace(t_ifaceHandle *handle, char * ifaceName, int typeOfConn, int servFlag )
-{
-#ifdef DEBUG_FUNC
- printf("%s \n",__func__);
-#endif
- if( (handle == NULL) || (ifaceName == NULL))
- {
- return WFA_ERROR;
- }
- FD_ZERO(&handle->fds);
- handle->timeout.tv_sec = READ_TIME_OUT_SEC;
- handle->timeout.tv_usec = READ_TIME_OUT_U_SEC;
- switch(typeOfConn)
- {
- case CONN_TYPE_TCP:
- { /* operation related to tcp*/
- handle->ifaceType = CONN_TYPE_TCP;
- if(strlen(ifaceName) > (sizeof(handle->if_attr.ipConn.device) - 1))
- return WFA_ERROR;
- /*expecting not more than 31 char + 1 null */
- strncpy(handle->if_attr.ipConn.device, ifaceName, 31);
- if(servFlag)
- {
- handle->if_attr.ipConn.clientSockfd = -1;
- /*set up the server but need to call "wfaInterFacePeerConn"
- to listen for the client connection*/
- handle->if_attr.ipConn.sockfd =
- wfaCreateTCPServSock(handle->if_attr.ipConn.device,
- handle->if_attr.ipConn.port);
- if(handle->if_attr.ipConn.sockfd == -1)
- {
- return WFA_ERROR;
- }
- handle->if_attr.ipConn.srvFlag = 1;
- }
- else
- { /*tcp client connect*/
- if(handle->if_attr.ipConn.sockfd == -1)
- {
- if ((handle->if_attr.ipConn.sockfd = socket(PF_INET,
- SOCK_STREAM, IPPROTO_TCP)) < 0)
- {
- DPRINT_ERR(WFA_ERR, "socket() failed: %i", errno);
- return WFA_ERROR;
- }
- handle->if_attr.ipConn.srvFlag = 0; /* client socket*/
- }
- }
- break;
- }
- case CONN_TYPE_UDP:
- { /* operation related to udp*/
- handle->ifaceType = CONN_TYPE_UDP;
- if(servFlag)
- {
- if(strlen(ifaceName) > (sizeof(handle->if_attr.ipConn.device) - 1))
- return WFA_ERROR;
- /*expecting not more than 31 char + 1 null */
- strncpy(handle->if_attr.ipConn.device, ifaceName, 31);
-
- handle->if_attr.ipConn.sockfd =
- wfaCreateUDPSock(handle->if_attr.ipConn.srcIpaddr,
- handle->if_attr.ipConn.port);
- if(handle->if_attr.ipConn.sockfd == -1)
- {
- return WFA_ERROR;
- }
- handle->if_attr.ipConn.srvFlag = 1;
- }
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* operation related to serial*/
- printf("trying to open serial port %s \n",ifaceName);
- handle->ifaceType = CONN_TYPE_SERIAL;
- if(strlen(ifaceName) > (sizeof(handle->if_attr.serial.device) - 1))
- return WFA_ERROR;
- /*expecting not more than 31 char + 1 null */
- strncpy(handle->if_attr.ipConn.device, ifaceName, 31);
- wfaOpenSerial(handle, handle->if_attr.serial.device,
- handle->if_attr.serial.baudrate);
- break;
- }
- }
- return WFA_SUCCESS;
-}
-
-
-/**
-* @brief
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char *destIpAddr
-* @param int dstPort
-* @param int dstBuad
-* @param int typeOfConn
-*
-*
-**/
-int wfaInterFacePeerInfoSet(t_ifaceHandle *handle, char *destIpAddr, int dstPort, int dstBuad, int typeOfConn )
-{
-#ifdef DEBUG_FUNC
- printf("%s \n",__func__);
-#endif
-
- if(handle == NULL) {
- return WFA_ERROR;
- }
- if(typeOfConn != handle->ifaceType) {
- DPRINT_ERR(WFA_ERR, "type of connection difference \n");
- return WFA_ERROR;
- }
- switch(typeOfConn) {
- case CONN_TYPE_TCP:
- { /* operation related to tcp*/
- if(destIpAddr == NULL)
- return WFA_ERROR;
- memset(&handle->if_attr.ipConn.to, 0, sizeof(handle->if_attr.ipConn.to));
- handle->if_attr.ipConn.to.sin_family = AF_INET;
- handle->if_attr.ipConn.to.sin_addr.s_addr = inet_addr(destIpAddr);
- handle->if_attr.ipConn.to.sin_port = htons(dstPort);
- break;
- }
- case CONN_TYPE_UDP:
- { /* operation related to udp*/
- if(destIpAddr == NULL)
- return WFA_ERROR;
- memset(&handle->if_attr.ipConn.to, 0, sizeof(handle->if_attr.ipConn.to));
- handle->if_attr.ipConn.to.sin_family = AF_INET;
- handle->if_attr.ipConn.to.sin_addr.s_addr = inet_addr(destIpAddr);
- handle->if_attr.ipConn.to.sin_port = htons(dstPort);
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* operation related to serial*/
- /* for this connection there is nothing like peer connection*/
- if(handle->if_attr.serial.baudrate != dstBuad)
- {
- printf("there is mismatch in dst buad\n");
- // DPRINT_ERR(WFA_ERR, "diffrebce in baud rate: local :%d remote: %d\n",
- // handle->if_attr.serial.baudrate, dstBuad);
- // return WFA_ERROR;
- }
- break;
- }
- }
- return WFA_SUCCESS;
-}
-
-
-/**
-* @brief
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char *destIpAddr
-* @param int dstPort
-* @param int dstBuad
-* @param int typeOfConn
-*
-*
-**/
-int wfaInterFacePeerConn(t_ifaceHandle *handle )
-{
- int typeOfConn;
- int retStatus =0;
-#ifdef DEBUG_FUNC
- printf("%s \n",__func__);
-#endif
-
- if( (handle == NULL) ) {
- return WFA_ERROR;
- }
- typeOfConn = handle->ifaceType;
- switch(typeOfConn) {
- case CONN_TYPE_TCP:
- { /* operation related to tcp*/
- if(handle->if_attr.ipConn.srvFlag) {
- /* wait for client connection, just start listen */
- /* accept the connection*/
- if (handle->if_attr.ipConn.clientSockfd == -1) {
- handle->if_attr.ipConn.clientSockfd =
- wfaAcceptTCPConn( handle->if_attr.ipConn.sockfd);
- printf("clent sock %d\n",handle->if_attr.ipConn.clientSockfd);
- }
- else {
- printf("clent sock %d\n",handle->if_attr.ipConn.clientSockfd);
- }
- }
- else {
- if(handle->if_attr.ipConn.sockfd != -1) {
- retStatus = wCONNECT(handle->if_attr.ipConn.sockfd,
- (struct sockaddr *)&handle->if_attr.ipConn.to,
- sizeof(handle->if_attr.ipConn.to));
- if(retStatus < 0)
- printf("Connection error %d\n", errno);
- }
- }
- break;
- }
- case CONN_TYPE_UDP:
- { /* operation related to udp*/
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* operation related to serial*/
- /* for this connection there is nothing like peer connection*/
- break;
- }
- }
- return retStatus;
-}
-
-
-/**
-* @brief
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char *destIpAddr
-* @param int dstPort
-* @param int dstBuad
-* @param int typeOfConn
-*
-*
-**/
-
-int wfaInterFacePeerConnClose(t_ifaceHandle *handle )
-{
- int typeOfConn;
-
-#ifdef DEBUG_FUNC
- printf("%s \n",__func__);
-#endif
-
- if( (handle == NULL) ) {
- return WFA_ERROR;
- }
- typeOfConn = handle->ifaceType;
- switch(typeOfConn) {
- case CONN_TYPE_TCP:
- { /* operation related to tcp*/
- if(handle->if_attr.ipConn.srvFlag) {
- /* close the connection*/
- if(handle->if_attr.ipConn.clientSockfd != -1)
- {
- shutdown(handle->if_attr.ipConn.clientSockfd, SHUT_WR);
- close(handle->if_attr.ipConn.clientSockfd);
- handle->if_attr.ipConn.clientSockfd = -1;
- }
- }
- else {
- if(handle->if_attr.ipConn.sockfd != -1)
- {
- shutdown(handle->if_attr.ipConn.sockfd, SHUT_WR);
- close(handle->if_attr.ipConn.sockfd);
- handle->if_attr.ipConn.sockfd = -1;
- }
- }
- break;
- }
- case CONN_TYPE_UDP:
- { /* operation related to udp*/
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* operation related to serial*/
- /* disconnect the uart*/
- wfaInterFaceClose(handle);
- break;
- }
- }
- return WFA_SUCCESS;
-}
-
-
-
-/**
-* @brief
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char *destIpAddr
-* @param int dstPort
-* @param int dstBuad
-* @param int typeOfConn
-*
-*
-**/
-int wfaInterFaceClose(t_ifaceHandle *handle )
-{
-#ifdef DEBUG_FUNC
- printf("%s \n",__func__);
-#endif
-
- if( (handle == NULL) ) {
- return WFA_ERROR;
- }
-
- switch(handle->ifaceType) {
- case CONN_TYPE_TCP:
- { /* operation related to tcp*/
- if(handle->if_attr.ipConn.srvFlag)
- {
- /* check for the client socket */
- if(handle->if_attr.ipConn.clientSockfd != -1)
- {
- shutdown(handle->if_attr.ipConn.clientSockfd, SHUT_WR);
- close(handle->if_attr.ipConn.clientSockfd);
- handle->if_attr.ipConn.clientSockfd = -1;
- }
- }
- shutdown(handle->if_attr.ipConn.clientSockfd, SHUT_RDWR);
- close(handle->if_attr.ipConn.sockfd);
- handle->if_attr.ipConn.sockfd = -1;
- break;
- }
- case CONN_TYPE_UDP:
- { /* operation related to udp*/
- wCLOSE(handle->if_attr.ipConn.sockfd);
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* operation related to serial*/
- /* for this connection there is nothing like peer connection*/
- wfaCloseSerial(handle);
- break;
- }
- }
- return WFA_SUCCESS;
-}
-
-/**
-* @brief
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char *destIpAddr
-* @param int dstPort
-* @param int dstBuad
-* @param int typeOfConn
-*
-*
-**/
-int wfaInterFaceDataSend(t_ifaceHandle *handle, char *buffer, int bufferLen )
-{
- int bytesSent = 0;
-//#ifdef DEBUG_FUNC
- printf("%s -> to send %d \n",__func__, bufferLen);
-//#endif
-
- if( (handle == NULL) || (buffer == NULL) || (bufferLen <= 0)) {
- return WFA_ERROR;
- }
- switch(handle->ifaceType) {
- case CONN_TYPE_TCP:
- { /* tcp send */
- if(handle->if_attr.ipConn.srvFlag){
- bytesSent = wSEND(handle->if_attr.ipConn.clientSockfd, buffer, bufferLen, 0);
- if(bytesSent == -1) {
- DPRINT_ERR(WFA_ERR, "Error sending tcp packet\n");
- }
- }
- else {
- bytesSent = wSEND(handle->if_attr.ipConn.sockfd, buffer, bufferLen, 0);
- if(bytesSent == -1) {
- DPRINT_ERR(WFA_ERR, "Error sending tcp packet\n");
- }
- }
- printf("able to sent %d \n", bytesSent );
- return bytesSent;
- break;
- }
- case CONN_TYPE_UDP:
- { /* udp sendto*/
- bytesSent = wSENDTO(handle->if_attr.ipConn.sockfd, buffer, bufferLen, 0,
- (struct sockaddr *)&handle->if_attr.ipConn.to, sizeof(handle->if_attr.ipConn.to));
- return bytesSent;
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* serial wrtie to the fd*/
- wfaSerialSend(handle, buffer, bufferLen);
- break;
- }
- }
- return WFA_SUCCESS;
-}
-
-
-/**
-* @brief
-*
-* @param t_ifaceHandle *handle pointer to handle.
-* @param char *destIpAddr
-* @param int dstPort
-* @param int dstBuad
-* @param int typeOfConn
-*
-*
-**/
-int wfaInterFaceDataRecv(t_ifaceHandle *handle, char *buffer, int bufferLen, int *recvLen )
-{
- int bytesRecvd = 0;
- int retStatus = WFA_SUCCESS;
- int ret = 0;
-
-#ifdef DEBUG_FUNC
- printf("%s \n",__func__);
-#endif
- if( (handle == NULL) || (buffer == NULL) || (bufferLen <= 0))
- {
- printf("handle or buffer error \n");
- return WFA_ERROR;
- }
- switch(handle->ifaceType)
- {
- case CONN_TYPE_TCP:
- { /* tcp send */
- FD_ZERO(&handle->fds);
- if(handle->if_attr.ipConn.srvFlag)
- {
- FD_SET(handle->if_attr.ipConn.clientSockfd, &handle->fds);
- ret = select(handle->if_attr.ipConn.clientSockfd+1, &handle->fds, NULL, NULL, &handle->timeout);
- printf("after select ret %d\n",ret);
- if ( ret > 0)
- {
- bytesRecvd = wRECV(handle->if_attr.ipConn.clientSockfd,
- buffer, bufferLen, 0);
- }
- else
- {
- bytesRecvd = -1;
- printf("timeout on receive\n");
- }
- if(bytesRecvd == -1)
- {
- DPRINT_ERR(WFA_ERR, "Error in receiving tcp packet\n");
- *recvLen = 0;
- retStatus = WFA_ERROR;
- }
- }
- else {
- FD_SET(handle->if_attr.ipConn.sockfd, &handle->fds);
- if (select(handle->if_attr.ipConn.sockfd+1, &handle->fds, NULL, NULL, &handle->timeout) > 0)
- {
- bytesRecvd = wRECV(handle->if_attr.ipConn.sockfd, buffer, bufferLen, 0);
- }
- else
- {
- bytesRecvd = -1;
- printf("timeout on receive\n");
- }
- if(bytesRecvd == -1)
- {
- DPRINT_ERR(WFA_ERR, "Error in receiving tcp packet\n");
- *recvLen = 0;
- retStatus = WFA_ERROR;
- }
- }
- printf("byte recv %d \n",bytesRecvd);
- *recvLen = bytesRecvd;
- break;
- }
- case CONN_TYPE_UDP:
- { /* udp recvfrom*/
- *recvLen = wRECVFROM(handle->if_attr.ipConn.sockfd,buffer,
- bufferLen, 0, NULL, NULL);
- return WFA_SUCCESS;
- break;
- }
- case CONN_TYPE_SERIAL:
- { /* serial wrtie to the fd*/
- /*need to do little more*/
- retStatus = wfaSerialRecv(handle, buffer, bufferLen, recvLen);
- if(WFA_SUCCESS != retStatus)
- printf("serial recev error \n");
- break;
- }
- }
- return retStatus;
-}
-
diff --git a/lib/wfa_serial.c b/lib/wfa_serial.c
deleted file mode 100644
index e6295a1..0000000
--- a/lib/wfa_serial.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/****************************************************************************
-*
-* Copyright (c) 2015 Wi-Fi Alliance
-*
-* Permission to use, copy, modify, and/or distribute this software for any
-* purpose with or without fee is hereby granted, provided that the above
-* copyright notice and this permission notice appear in all copies.
-*
-* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
-* USE OR PERFORMANCE OF THIS SOFTWARE.
-*
-*****************************************************************************/
-
-/*
- * File: wfa_serial.c
- * library functions for serial port,
- * They are common library to open, close and send receive over serial port.
- *
- * Revision History:
- *
- *
- */
-
-
-
-//#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-#include <termios.h>
-#include <stdio.h>
-
-#include "wfa_types.h"
-#include "wfa_serial.h"
-#include "wfa_debug.h"
-
-/************ For Debug enable below *************************/
-
-#define DEBUG_SERIAL
-#ifdef DEBUG_SERIAL
-extern unsigned short wfa_defined_debug;
-#endif
-
-
-int wfa_getBaudeRate(int baudrate)
-{
- switch (baudrate){
- case 0:
- return -1;
- case 2400:
- return B2400;
- case 4800:
- return B4800;
- case 9600:
- return B9600;
- case 19200:
- return B19200;
- case 38400:
- return B38400;
- case 57600:
- return B57600;
- case 115200:
- return B115200;
- case 230400:
- return B230400;
- case 460800:
- return B460800;
- case 921600:
- return B921600;
- case 1000000:
- return B1000000;
- case 1152000:
- return B1152000;
- case 1500000:
- return B1500000;
- case 2000000:
- return B2000000;
- case 2500000:
- return B2500000;
- case 3000000:
- return B3000000;
- case 3500000:
- return B3500000;
- case 4000000:
- return B4000000;
- default:
- printf("baud not in list, default 115200");
- return B115200;
- }
-}
-
-/**
-* @brief Open serial port for communicaiton
-*
-*
-*
-* @param t_ifaceHandle *handle, handle of the structure
-* @param char *device device name, port to be used
-* @param int baudRate buadrate for the port
-*
-*
-* @return WFA_SUCCESS, WFA_ERROR.
-*/
-
-
-
-int wfaOpenSerial(t_ifaceHandle *handle, char *device, int baudRate)
-{
- int fd= -1;
- int baud;
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"%s \n",__func__);
-#endif
- if((handle == NULL) || (device == NULL))
- return WFA_ERROR; //ERROR_NULL_POINTER;
-
- fd = open(device, O_RDWR | O_NOCTTY );
- if (fd <0) {
- DPRINT_INFO(WFA_ERR,"Not able to open serial port\n");
- perror(device);
- exit(1);
- }
-
- handle->if_attr.serial.fd = fd;
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"baud rate %d \n",baudRate);
-#endif
- if(( baud = wfa_getBaudeRate( baudRate)) == -1)
- return WFA_ERROR;
-
- /* save current port settings */
- if (tcgetattr(fd,&(handle->if_attr.serial.oldtio)) != 0)
- {
- DPRINT_INFO(WFA_ERR,"error %d from tcgetattr", errno);
- return WFA_ERROR;
- }
-
- bzero(&(handle->if_attr.serial.newtio),sizeof(handle->if_attr.serial.newtio));
- /* Set the buad rate for the serial port */
-
- handle->if_attr.serial.newtio.c_cflag |= baud;
- handle->if_attr.serial.newtio.c_cflag |= (CLOCAL | CREAD);
- handle->if_attr.serial.newtio.c_cflag |= CRTSCTS;
- /*No parity 8N1 */
- handle->if_attr.serial.newtio.c_cflag |= CS8;
-
- /* setting flow control*/
- /* shut off xon/xoff ctrl */
- handle->if_attr.serial.newtio.c_iflag &= ~(IXON | IXOFF | IXANY);
- handle->if_attr.serial.newtio.c_oflag = 0; /*&= ~OPOST;*/
-
- /* no signaling chars, no echo, */
- handle->if_attr.serial.newtio.c_cc[VTIME] = 5; /* inter-character timer */
- handle->if_attr.serial.newtio.c_cc[VMIN] = 250; /* blocking read until 250 chars received */
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"handle->if_attr.serial.newtio.c_cflag =%x\n",handle->if_attr.serial.newtio.c_cflag );
-#endif
- /* clean the port*/
- tcflush(fd, TCIFLUSH);
- if(tcsetattr(fd, TCSANOW, &(handle->if_attr.serial.newtio)) != 0)
- {
- DPRINT_INFO(WFA_ERR,"error %d from tcsetattr", errno);
- return WFA_ERROR;
- }
- return WFA_SUCCESS;
-}
-
-
-
-/**
-* @brief Close serial port for communicaiton
-*
-*
-* @param t_ifaceHandle *handle, handle of the structure
-*
-* @return WFA_SUCCESS, WFA_ERROR.
-*/
-
-int wfaCloseSerial(t_ifaceHandle *handle)
-{
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"%s \n",__func__);
-#endif
- if((handle == NULL) )
- return WFA_ERROR;
-
- if (handle->if_attr.serial.fd <0) {
- return -1;
- }
- /*restore back old settings*/
- tcsetattr(handle->if_attr.serial.fd ,TCSANOW,&handle->if_attr.serial.oldtio);
- close(handle->if_attr.serial.fd );
-
- handle->if_attr.serial.fd = -1;
- return WFA_SUCCESS;
-}
-
-
-/**
-* @brief Send data over serial port
-*
-*
-* @param t_ifaceHandle *handle, handle of the structure
-* @param char *buffer buffer to be sent
-* @param int bufferLen length of the buffer to be sent
-*
-* @return WFA_SUCCESS, WFA_ERROR.
-*/
-
-int wfaSerialSend(t_ifaceHandle *handle, char *buffer, int bufferLen)
-{
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"%s \n",__func__);
-#endif
- if((handle == NULL) || (buffer == NULL))
- return WFA_ERROR; //ERROR_NULL_POINTER;
-
- if (handle->if_attr.serial.fd<0) {
- return -1;
- }
-
- /*send the buffer serial port*/
- write(handle->if_attr.serial.fd, buffer, bufferLen);
- /* 100 micro sec per char in case of 115200 baud*/
- usleep((bufferLen + 25) *200);
- return WFA_SUCCESS;
-}
-
-
-/**
-* @brief Receive data over serial port
-*
-*
-*
-* @param t_ifaceHandle *handle, handle of the structure
-* @param char *buffer buffer for recv data
-* @param int bufferLen size of the receive data buffer
-*
-* @return WFA_SUCCESS, WFA_ERROR.
-*/
-
-int wfaSerialRecv(t_ifaceHandle *handle, char *buffer, int bufferLen, int *recevLen)
-{
- int numByte = 0;
- int byteLeft = 0;
- int bytes;
- unsigned int delayUs = 0;
-
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"%s \n",__func__);
-#endif
-
- if(handle == NULL || buffer == NULL )
- {
- DPRINT_INFO(WFA_ERR,"handle or buffer error \n");
- return WFA_ERROR;
- }
-
- if (handle->if_attr.serial.fd<0) {
- DPRINT_INFO(WFA_ERR,"Serial fd error\n");
- return -1;
- }
- /* calculating delay to receive some byte, 200
- based on baud rate but at least 1000 usec*/
- delayUs = (10000000 * 200) / handle->if_attr.serial.baudrate + 1000;
-
-
- /*send the buffer serial port*/
- byteLeft = bufferLen;
- FD_ZERO(&handle->fds);
- FD_SET(handle->if_attr.serial.fd, &handle->fds);
- if (select(handle->if_attr.serial.fd+1, &handle->fds, NULL, NULL, &handle->timeout) > 0)
- {
- numByte = read(handle->if_attr.serial.fd, buffer, bufferLen);
- }
- else
- {
- numByte = -1;
- DPRINT_INFO(WFA_ERR,"Timeout on serial read\n");
- }
- if(numByte < 0) {
- DPRINT_INFO(WFA_ERR,"serial read fail\n");
- *recevLen = numByte;
- return WFA_ERROR;
- }
- if(byteLeft >= numByte)
- byteLeft -= numByte;
- else
- byteLeft = 0;
-
- while(byteLeft) {
- wUSLEEP(delayUs);
- ioctl(handle->if_attr.serial.fd, FIONREAD, &bytes);
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"Bytes Availble %d \n",bytes);
-#endif
- if(!bytes ) /* proceed if data still in buffer */
- break;
- numByte = read(handle->if_attr.serial.fd, &buffer[numByte], byteLeft);
- if(byteLeft >= numByte)
- byteLeft -= numByte;
- else
- byteLeft = 0;
- }
-
- *recevLen = bufferLen - byteLeft;
-#ifdef DEBUG_SERIAL
- DPRINT_INFO(WFA_OUT,"Data receive %d \n",*recevLen);
-#endif
- return WFA_SUCCESS;
-}
-
-
diff --git a/lib/wfa_sock.c b/lib/wfa_sock.c
index 0068ef8..0ac8af6 100644
--- a/lib/wfa_sock.c
+++ b/lib/wfa_sock.c
@@ -54,7 +54,7 @@
* intput: port -- TCP socket port to listen
* return: socket id;
*/
-int wfaCreateTCPServSock(char *devIface, unsigned short port)
+int wfaCreateTCPServSock(unsigned short port)
{
int sock; /* socket to create */
struct sockaddr_in servAddr; /* Local address */
@@ -64,17 +64,12 @@
if ((sock = wSOCKET(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
DPRINT_ERR(WFA_ERR, "createTCPServSock socket() failed");
- return WFA_ERROR;
+ return WFA_FAILURE;
}
/* Construct local address structure */
wMEMSET(&servAddr, 0, sizeof(servAddr));
-// wfaGetifAddr(gnetIf, &servAddr);
- if (wfaGetifAddr(devIface, &servAddr)== WFA_FAILURE) {
- DPRINT_ERR(WFA_ERR, "Unable to find interface %s\n",devIface);
- wCLOSE(sock);
- return WFA_ERROR;
- }
+ wfaGetifAddr(gnetIf, &servAddr);
servAddr.sin_family = AF_INET; /* Internet address family */
servAddr.sin_port = htons(port); /* Local port */
@@ -83,14 +78,14 @@
if (wBIND(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
{
DPRINT_ERR(WFA_ERR, "bind() failed");
- return WFA_ERROR;
+ return WFA_FAILURE;
}
/* Mark the socket so it will listen for incoming connections */
if (wLISTEN(sock, MAXPENDING) < 0)
{
DPRINT_ERR(WFA_ERR, "listen() failed");
- return WFA_ERROR;
+ return WFA_FAILURE;
}
return sock;
@@ -157,18 +152,6 @@
return mysock;
}
-int wfaConnectTCPPeer(int mysock, char *daddr, int dport)
-{
- struct sockaddr_in peerAddr;
-#if 0
- wMEMSET(&peerAddr, 0, sizeof(peerAddr));
- peerAddr.sin_family = AF_INET;
- inet_aton(daddr, &peerAddr.sin_addr);
- peerAddr.sin_port = htons(dport);
-#endif
- wCONNECT(mysock, (struct sockaddr *)&peerAddr, sizeof(peerAddr));
- return mysock;
-}
/*
* acceptTCPConn(): handle and accept any incoming socket connection request.
* input: serSock -- the socket id to listen
@@ -360,7 +343,7 @@
wCLOSE(fd);
- return WFA_SUCCESS;
+ return WFA_FAILURE;
}
/*