diff --git a/win_ca/win_ca.sln b/win_ca/win_ca.sln index a5e130c..e241bed 100644 --- a/win_ca/win_ca.sln +++ b/win_ca/win_ca.sln @@ -9,8 +9,8 @@ Global Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A0D02A3A-4CD6-48EB-835D-E8612F4F53C1}.Debug|Win32.ActiveCfg = Debug|Win32 - {A0D02A3A-4CD6-48EB-835D-E8612F4F53C1}.Debug|Win32.Build.0 = Debug|Win32 + {A0D02A3A-4CD6-48EB-835D-E8612F4F53C1}.Debug|Win32.ActiveCfg = Release|Win32 + {A0D02A3A-4CD6-48EB-835D-E8612F4F53C1}.Debug|Win32.Build.0 = Release|Win32 {A0D02A3A-4CD6-48EB-835D-E8612F4F53C1}.Release|Win32.ActiveCfg = Release|Win32 {A0D02A3A-4CD6-48EB-835D-E8612F4F53C1}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection diff --git a/win_ca/win_ca/wfa_ca.c b/win_ca/win_ca/wfa_ca.c index f43db78..493cf7d 100644 --- a/win_ca/win_ca/wfa_ca.c +++ b/win_ca/win_ca/wfa_ca.c @@ -30,7 +30,7 @@ extern dutCommandRespFuncPtr wfaCmdRespProcFuncTbl[]; extern typeNameStr_t nameStr[]; /* -* the output format can be redefined for file output. +* The output format can be redefined for file output. */ int main(int argc, char *argv[]) { @@ -61,6 +61,10 @@ int main(int argc, char *argv[]) int iOptVal = 0; int iOptLen = sizeof (int); + WFA_OUT = stdout; + WFA_ERR = stderr; + WFA_WNG = stdout; + DPRINT_INFOL(WFA_OUT, "%c[%d;%d;%dm", 0x1B, 1,32,40); if(argc < 3) { @@ -68,7 +72,8 @@ int main(int argc, char *argv[]) exit(1); } - myport = atoi(argv[2]); + myport = atoi(argv[2]); + if(argc > 3) { if(argc < 5) @@ -95,10 +100,11 @@ int main(int argc, char *argv[]) logfile = fopen(argv[5],"a"); if(logfile != NULL) { - fd = _fileno(logfile); + WFA_OUT = WFA_ERR = WFA_WNG = logfile; + //fd = _fileno(logfile); DPRINT_INFO(WFA_OUT,"redirecting the output to %s\n",argv[5]); - _dup2(fd,1); - _dup2(fd,2); + //_dup2(fd,1); + //_dup2(fd,2); } else { diff --git a/win_dut/win_dut/wfa_dut.c b/win_dut/win_dut/wfa_dut.c index bb9d637..9ea2c57 100644 --- a/win_dut/win_dut/wfa_dut.c +++ b/win_dut/win_dut/wfa_dut.c @@ -85,12 +85,18 @@ DWORD WINAPI wfa_recv_thread(void *thr_param) { while (n!=-1) { - n = wfaRecvFile(wfaTGWMMData.btSockfd, wfaTGWMMData.gtgRecv, (char *)recvBuf); + n = wfaRecvFile(wfaTGWMMData.btSockfd, wfaTGWMMData.gtgRecv, (char *)recvBuf, sizeof(recvBuf)); if(wfaTGWMMData.gtgTransac != 0 && n != -1) /* for transaction DT3, need to send a response back */ { char respBuf[WFA_BUFF_4K]; int respLen = 0; + int iResult; + u_long iMode = 1; + iResult = ioctlsocket(wfaTGWMMData.btSockfd, FIONBIO, &iMode); + if (iResult != NO_ERROR) + DPRINT_ERR(WFA_ERR, "ioctlsocket failed with error: %ld\n", iResult); + if(wfaSendShortFile(wfaTGWMMData.btSockfd, wfaTGWMMData.gtgTransac, (BYTE *) recvBuf, n, (BYTE *) respBuf, &respLen) == WFA_SUCCESS) { if(wfaCtrlSend(wfaDutAgentData.gxcSockfd, (BYTE *)respBuf, respLen)!=respLen) @@ -144,12 +150,19 @@ struct timeval *wfaSetTimer(int secs, int usecs, struct timeval *tv) */ void init_prog_global() { + int i = 0; wfa_defined_debug = WFA_DEBUG_ERR | WFA_DEBUG_WARNING | WFA_DEBUG_INFO; wfaDutAgentCAPIData.geSupplicant = 1; wfaDutAgentData.gagtSockfd = -1; wfaDutAgentData.gxcSockfd = -1; + wfaDutAgentData.isExit = 1; strcpy(wfaDutAgentData.WFA_CLI_CMD_DIR, "C:\\WFA\\CLIs\\Intel"); + for (i = 0; i < WFA_MAX_WMM_STREAMS; i++) + { + wfaTGWMMData.svrSock[i] = -1; + } + #ifdef WFA_WMM_WPA2 wfaTGWMMData.btSockfd = -1; #endif @@ -164,12 +177,160 @@ void init_prog_global() #endif } +/** + * Housekeeping system resources including sockets +*/ +void wfaDutAgentCleanup() +{ + int i = 0; + + if(wfaTGWMMData.btSockfd != -1) + { + closesocket(wfaTGWMMData.btSockfd); + wfaTGWMMData.btSockfd = -1; + } + + if(wfaTGWMMData.txSockfd != -1) + { + closesocket(wfaTGWMMData.txSockfd); + wfaTGWMMData.txSockfd = -1; + } + + for (i = 0; i < WFA_MAX_WMM_STREAMS; i++) + { + if (wfaTGWMMData.svrSock[i] != -1) + { + closesocket(wfaTGWMMData.svrSock[i]); + wfaTGWMMData.svrSock[i] = -1; + } + } + + for(i = 0; i < WFA_MAX_TRAFFIC_STREAMS; i++) + { + if(wfaTGWMMData.tgSockfds[i] > 0) + { + DPRINT_INFOL(WFA_OUT, "Closing a socket which should have been closed earlier\n"); + closesocket(wfaTGWMMData.tgSockfds[i]); + wfaTGWMMData.tgSockfds[i] = -1; + } + } + + if(wfaDutAgentData.gagtSockfd != -1) + { + closesocket(wfaDutAgentData.gagtSockfd); + wfaDutAgentData.gagtSockfd = -1; + } + + if(wfaDutAgentData.gxcSockfd != -1) + { + closesocket(wfaDutAgentData.gxcSockfd); + wfaDutAgentData.gxcSockfd = -1; + } + + /* just reset the flags for the command */ + wfaTGWMMData.gtgRecv = 0; + wfaTGWMMData.gtgSend = 0; + wfaTGWMMData.gtgTransac = 0; + +#ifdef WFA_WMM_PS_EXT + wfaTGWMMPSData.gtgWmmPS = 0; + + if(wfaTGWMMPSData.psSockfd != -1) + { + closesocket(wfaTGWMMPSData.psSockfd); + wfaTGWMMPSData.psSockfd = -1; + } + + memset(&wfaTGWMMPSData.wmmps_info, 0, sizeof(wfaWmmPS_t)); + wfaSetDUTPwrMgmt(PS_OFF); +#endif + +} + +/** + * Console event handler +*/ +BOOL wfaDutAgtConsoleCtrlHandler(DWORD ConEvent) +{ + switch (ConEvent) + { + case CTRL_C_EVENT: + DPRINT_INFOL(WFA_OUT, "Ctrl-C event\n"); + goto CLEANUP; + case CTRL_CLOSE_EVENT: + DPRINT_INFOL(WFA_OUT, "Ctrl-Close event\n"); + goto CLEANUP; + case CTRL_BREAK_EVENT: + DPRINT_INFOL(WFA_OUT, "Ctrl-Break event\n"); + goto CLEANUP; + case CTRL_LOGOFF_EVENT: + DPRINT_INFOL(WFA_OUT, "Ctrl-LogOff event\n"); + goto CLEANUP; + case CTRL_SHUTDOWN_EVENT: + DPRINT_INFOL(WFA_OUT, "Ctrl-ShutDown event\n"); + goto CLEANUP; + default: + return FALSE; + } + +CLEANUP: + wfaDutAgentCleanup(); + wfaDutAgentData.isExit = 0; + Sleep(500); + ExitProcess(0); + return TRUE; +} + +/** + * Check WM_QUIT message to exit the application +*/ +DWORD WINAPI win_msg_check() +{ + MSG Msg; + + if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) + { + if (Msg.message == WM_QUIT) + { + DPRINT_INFOL(WFA_OUT, "WM_QUIT\n"); + wfaDutAgentCleanup(); + wfaDutAgentData.isExit = 0; + ExitProcess(0); + } + else + { + DPRINT_INFOL(WFA_OUT, "Message:%s\n", Msg.message); + } + } + + return (DWORD) 0; +} + +BOOL IsWow64Bit() +{ + BOOL bIsWow64 = FALSE; + + LPFN_ISWOW64PROCESS fnWow64Proc; + + fnWow64Proc = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); + + if (NULL != fnWow64Proc) + { + if (!fnWow64Proc(GetCurrentProcess(), &bIsWow64)) + { + DPRINT_INFOL(WFA_OUT, "Unable to determine WoW64\n"); + } + } + + return bIsWow64; +} + /** * Main function of windows DUT agent */ int main(int argc, char **argv) { - int nfds, maxfdn1 = -1, nbytes = 0, cmdLen = 0, isExit = 1; + int nfds, maxfdn1 = -1, nbytes = 0, cmdLen = 0; int respLen; int ret = 0; WORD locPortNo = 0; /* local control port number */ @@ -183,6 +344,11 @@ int main(int argc, char **argv) SECURITY_ATTRIBUTES sa; DWORD dwFlags; BYTE *trafficBuf=NULL; + int iResult; + u_long iMode = 1; + TCHAR sys_path[512]; + int path_len; + FILE* dut_log_file; #ifdef WFA_WMM_WPA2 struct timeval lstime; @@ -194,6 +360,10 @@ int main(int argc, char **argv) DWORD thr_id; #endif /* #ifdef WFA_WMM_WPA2 */ + WFA_OUT = stdout; + WFA_ERR = stderr; + WFA_WNG = stdout; + if (argc < 3) /* Test for correct number of arguments */ { DPRINT_ERR(WFA_ERR, "Usage: %s \n", argv[0]); @@ -202,22 +372,38 @@ int main(int argc, char **argv) if(argc > 3) { - sa.nLength = sizeof (SECURITY_ATTRIBUTES); + sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; dwFlags = FILE_ATTRIBUTE_NORMAL; - hStdOut = CreateFile ((LPCWSTR) argv[3], + /*hStdOut = CreateFile((LPCWSTR) argv[3], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, dwFlags, NULL); - - SetStdHandle(STD_OUTPUT_HANDLE,hStdOut); - SetStdHandle(STD_ERROR_HANDLE,hStdOut); - freopen(argv[3],"a",stdout); - DPRINT_INFOL(WFA_OUT, "Redirected output to %s\n",argv[3]); + if(hStdOut != INVALID_HANDLE_VALUE) + { + int fd = _open_osfhandle((intptr_t)hStdOut, _O_APPEND); + if(fd != -1) + { + dut_log_file = _fdopen(fd, "a+"); + } + }*/ + + dut_log_file = fopen(argv[3], "a"); + + WFA_OUT = WFA_ERR = WFA_WNG = dut_log_file; + //WFA_ERR = dut_log_file; + //WFA_WNG = dut_log_file; + //SetStdHandle(STD_OUTPUT_HANDLE,hStdOut); + //SetStdHandle(STD_ERROR_HANDLE,hStdOut); + //freopen(argv[3],"a",stdout); + DPRINT_INFOL(WFA_OUT, "Redirected output to %s\n",argv[3]); + + //wfaTGWMMData.throttle_rate = atoi(argv[4]); + //wfaTGWMMData.sleep_time = atoi(argv[5]); } strncpy(wfaDutAgentData.gnetIf, argv[1], 50); @@ -236,6 +422,12 @@ int main(int argc, char **argv) rand_gen_sid(); #endif + if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)wfaDutAgtConsoleCtrlHandler, TRUE) == FALSE) + { + DPRINT_INFOL(WFA_OUT, "Failed to install handler\r\n"); + return 1; + } + #ifdef WFA_WMM_WPA2 /* raise itself priority class first */ wfaTGWMMData.adj_latency = wfa_estimate_timer_latency() + 2000; /* four more mini */ @@ -256,10 +448,17 @@ int main(int argc, char **argv) /* initial some external pointers */ wfa_set_envs(); - if (FALSE == Wow64EnableWow64FsRedirection(FALSE)) +#ifndef WOW64_REDIRECT + path_len = GetSystemWow64Directory(sys_path, 512); + + if (path_len > 0 && IsWow64Bit()) { - DPRINT_INFOL(WFA_OUT, "Disable WoW64 failed\n"); + if (FALSE == Wow64EnableWow64FsRedirection(FALSE)) + { + DPRINT_INFOL(WFA_OUT, "Disable WoW64 failed\n"); + } } +#endif #ifdef WFA_WMM_WPA2 /* create a receive thread */ @@ -298,7 +497,7 @@ int main(int argc, char **argv) maxfdn1 = wfaDutAgentData.gagtSockfd + 1; - while (isExit) + while (wfaDutAgentData.isExit) { /* set socket file descriptors. For baseline, there are only * three sockets required. They are an agent main socket, @@ -334,6 +533,8 @@ int main(int argc, char **argv) /* Put a sleep so that the thread gets the mutex then main thread gets it */ Sleep(1); + win_msg_check(); + if ((nfds = select(maxfdn1, &sockSet, NULL, NULL, tovalp)) < 0) { if (errno == EINTR) @@ -373,6 +574,10 @@ int main(int argc, char **argv) int2BuffBigEndian((int)lstime.tv_sec, &((tgHeader_t *)trafficBuf)->hdr[12]); int2BuffBigEndian((int)lstime.tv_usec, &((tgHeader_t *)trafficBuf)->hdr[16]); + iResult = ioctlsocket(wfaTGWMMData.btSockfd, FIONBIO, &iMode); + if (iResult != NO_ERROR) + DPRINT_ERR(WFA_ERR, "ioctlsocket failed with error: %ld\n", iResult); + if(wfaSendShortFile(wfaTGWMMData.btSockfd, wfaTGWMMData.gtgTransac, trafficBuf, 0, respBuf, &respLen) == WFA_SUCCESS) { if(wfaCtrlSend(wfaDutAgentData.gxcSockfd, respBuf, respLen) != respLen) @@ -389,10 +594,10 @@ int main(int argc, char **argv) { /* Incoming connection request */ wfaDutAgentData.gxcSockfd = wfaAcceptTCPConn(wfaDutAgentData.gagtSockfd); - if(wfaDutAgentData.gxcSockfd == -1) + if(wfaDutAgentData.gxcSockfd == WFA_FAILURE) { DPRINT_ERR(WFA_ERR, "Failed to open control link socket\n"); - WFA_EXIT(1); + goto END; } } /* Control Link port event*/ @@ -408,8 +613,6 @@ int main(int argc, char **argv) } else { - /* Clean the tray for any in Active icons */ - RefreshTaskbarNotificationArea(); DPRINT_INFOL(WFA_OUT, "\nThe command Received after socket: %s\n",xcCmdBuf+4); memset(parmsVal,'\0',MAX_PARMS_BUFF); /* command received */ @@ -442,6 +645,7 @@ int main(int argc, char **argv) DPRINT_INFOL(WFA_OUT, "Not supported command\n"); } DPRINT_INFOL(WFA_OUT, "Completed control command\n"); + #ifdef WFA_WMM_WPA2 /* for traffic_agent_send command, the wfaSentStatsResp() in wfa_thr.c will send the final status to the ca */ if(xcCmdTag == WFA_TRAFFIC_AGENT_SEND_RESP_TLV) @@ -493,6 +697,7 @@ int main(int argc, char **argv) #endif /* WFA_WMM_WPA2 */ } /* end of while (isExit) */ +END: free(trafficBuf); free(toutvalp); free(respBuf); diff --git a/win_dut/win_dut/wfa_dut.h b/win_dut/win_dut/wfa_dut.h index 9ec1f8a..7cba131 100644 --- a/win_dut/win_dut/wfa_dut.h +++ b/win_dut/win_dut/wfa_dut.h @@ -27,6 +27,7 @@ struct wfa_dutagt_data int gagtSockfd; int gxcSockfd; int vend; + volatile int isExit; char gCmdStr[WFA_CMD_STR_SZ]; char intfname[64]; char WFA_CLI_CMD_DIR[64]; @@ -58,8 +59,11 @@ struct wfa_tg_wmm_data int slotCnt; int mainSendThread; int usedThread; - int runLoop; + volatile int runLoop; int gtimeOut; + int svrSock[WFA_MAX_WMM_STREAMS]; + int throttle_rate; + int sleep_time; }; struct wfa_tg_voice_data @@ -102,10 +106,11 @@ struct wfa_tg_wmmps_data int msgsize; }; - struct wfa_dutagt_data wfaDutAgentData; struct wfa_dutagt_capi_data wfaDutAgentCAPIData; +typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); + #if defined(WFA_WMM_WPA2) || defined(WFA_WMM_PS) || defined(WFA_WMM_AC) struct wfa_tg_wmm_data wfaTGWMMData; #endif diff --git a/win_inc/wfa_ca_resp.h b/win_inc/wfa_ca_resp.h index 4e7059a..2c6d673 100644 --- a/win_inc/wfa_ca_resp.h +++ b/win_inc/wfa_ca_resp.h @@ -36,6 +36,8 @@ int wfaTrafficAgentRecvStopResp(BYTE *cmdBuf); int wfaTrafficAgentResetResp(BYTE *cmdBuf); int wfaTrafficAgentPingStartResp(BYTE *cmdBuf); int wfaTrafficAgentPingStopResp(BYTE *cmdBuf); +int wfaTrafficAgentVersionResp(BYTE *cmdBuf); + int wfaStaGetMacAddressResp(BYTE *cmdBuf); int wfaStaGetBSSIDResp(BYTE *cmdBuf); int wfaStaSetEncryptionResp(BYTE *cmdBuf); diff --git a/win_inc/wfa_cmds.h b/win_inc/wfa_cmds.h index 6b39370..b777859 100644 --- a/win_inc/wfa_cmds.h +++ b/win_inc/wfa_cmds.h @@ -383,6 +383,7 @@ enum { eDEF_WMMPS = 8, eDEF_HS20 = 9, eDEF_WMMAC = 10, + eDEF_60G = 11 }; typedef struct ca_sta_reset_default @@ -487,7 +488,7 @@ typedef struct wmm_tspec unsigned int PHYrate;//The minimum PHY Rate float sba;//The Surplus Bandwidth Allownce unsigned short medium_time;//The medium time -}wmmtspec_t; +} wmmtspec_t; typedef struct wmmac_addts { diff --git a/win_inc/wfa_debug.h b/win_inc/wfa_debug.h index e7d0913..45ef50b 100644 --- a/win_inc/wfa_debug.h +++ b/win_inc/wfa_debug.h @@ -20,9 +20,9 @@ #ifndef _WFA_DEBUG_H #define _WFA_DEBUG_H -#define WFA_ERR stderr /* error: can be redefined to a log file */ -#define WFA_OUT stdout /* info: can be redefined to a log file */ -#define WFA_WNG stdout /* warning: can be redefined to a log file */ +//#define WFA_ERR stderr /* error: can be redefined to a log file */ +//#define WFA_OUT stdout /* info: can be redefined to a log file */ +//#define WFA_WNG stdout /* warning: can be redefined to a log file */ #define WFA_DEBUG_DEFAULT 0x0001 #define WFA_DEBUG_ERR 0x0001 @@ -32,6 +32,9 @@ #define WFA_DEBUG 1 unsigned short wfa_defined_debug; +FILE* WFA_OUT; +FILE* WFA_ERR; +FILE* WFA_WNG; #define DPRINT_ERR fprintf(WFA_ERR, "ERROR: File %s, Line %ld: ", \ __FILE__, (long)__LINE__); \ diff --git a/win_inc/wfa_main.h b/win_inc/wfa_main.h index a7e9916..0a3ee81 100644 --- a/win_inc/wfa_main.h +++ b/win_inc/wfa_main.h @@ -30,6 +30,13 @@ #include #include #include +#include +#include +#include +#include +#include +//#include +//#include #include "iphdr.h" #include diff --git a/win_inc/wfa_miscs.h b/win_inc/wfa_miscs.h index c0a625a..84bef80 100644 --- a/win_inc/wfa_miscs.h +++ b/win_inc/wfa_miscs.h @@ -26,5 +26,7 @@ extern int wfa_itime_diff(struct timeval *t1, struct timeval *t2); char * strtok_r(char *string, const char *sepset, char **lasts); int strncasecmp(const char *s1, const char *s2, size_t n); int strcasecmp(const char *s1, const char *s2); +char *ltrim(char *s); +char *rtrim(char *s); #endif diff --git a/win_inc/wfa_rsp.h b/win_inc/wfa_rsp.h index 118d63a..bce443f 100644 --- a/win_inc/wfa_rsp.h +++ b/win_inc/wfa_rsp.h @@ -41,6 +41,7 @@ typedef struct ca_sta_get_stats_resp { int status; int txFrames; + int txActFrames; int rxFrames; int txMulticast; int rxMulticast; @@ -116,7 +117,6 @@ typedef struct dut_cmd_response caP2pStaGetPskResp_t pskInfo; #endif - int connected; } cmdru; }dutCmdResponse_t; diff --git a/win_inc/wfa_sock.h b/win_inc/wfa_sock.h index 839182d..0100d24 100644 --- a/win_inc/wfa_sock.h +++ b/win_inc/wfa_sock.h @@ -24,6 +24,12 @@ #define MAX_ETH_PAYLOAD_LEN 1450 #define MAX_LEGACY_PAYLOAD_LEN 1000 +#define MAX_SOCKOPT_RECVBUF_LEN 128*1024 +#define MAX_SOCKOPT_SNDBUF_LEN 128*1024 + +#define SOCK_TYPE_UDP 0 +#define SOCK_TYPE_TCP 1 + struct sockfds { int *agtfd; /* dut agent main socket fd */ @@ -33,17 +39,28 @@ struct sockfds int *psfd; /* wmm-ps socket id */ }; +extern int wfaCreateTCPServSockImpl(char *serverIpAddr, unsigned short port); extern int wfaCreateTCPServSock(unsigned short sport); extern int wfaCreateUDPSock(char *sipaddr, unsigned short sport); +extern int wfaCreateSock(int sockType, char *ipaddr, unsigned short port); + extern int wfaAcceptTCPConn(int servSock); + +extern int wfaConnectToPeer(int sockType, int mysock, char *daddr, int dport); extern int wfaConnectUDPPeer(int sock, char *dipaddr, int dport); + extern void wfaSetSockFiDesc(fd_set *sockset, int *, struct sockfds *); + extern int wfaCtrlSend(SOCKET sock, unsigned char *buf, int bufLen); extern int wfaCtrlRecv(int sock, unsigned char *buf, int bufLen); extern int wfaTrafficSendTo(int sock, char *buf, int bufLen, struct sockaddr *to); -extern int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from); +extern int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from, int bufLen); + extern int wfaSetSockMcastRecvOpt(int, char*); extern int wfaSetSockMcastSendOpt(int); extern int wfaSetProcPriority(int); +int wfaCreateTCPCliSock(); +int wfaConnectTCPPeer(int mysock, char *daddr, int dport); + #endif /* _WFA_SOCK_H */ diff --git a/win_inc/wfa_tg.h b/win_inc/wfa_tg.h index e892949..be34b20 100644 --- a/win_inc/wfa_tg.h +++ b/win_inc/wfa_tg.h @@ -61,6 +61,7 @@ #define KW_USERPRIORITY 17 #define KW_MAXCNT 18 #define KW_HTI 19 +#define KW_TRANSPROTOTYPE 20 /* Profile Types */ #define PROF_FILE_TX 1 @@ -162,6 +163,7 @@ typedef struct _tg_profile int startdelay; int maxcnt; int hti; /* High Throughput Injection */ + int transProtoType; /* 0 is udp and 1 is tcp */ tgTC_t tgTC[5]; } tgProfile_t; @@ -174,6 +176,7 @@ typedef struct _tg_stats int outOfSequenceFrames; int lostPkts; /* voice over wi-fi */ unsigned long jitter; /* voice over wi-fi */ + unsigned int txActFrames; } tgStats_t; typedef struct _e2e_stats @@ -252,7 +255,7 @@ typedef struct _tg_thr_data extern int wfaTGConfig(int len, BYTE *buf, int *respLen, BYTE *respBuf); extern int wfaSendLongFile(int fromSockfd, int streamId, BYTE *respBuf, int *respLen); -extern int wfaRecvFile(int mySockfi, int profId, char *buf); +extern int wfaRecvFile(int mySockfi, int profId, char *buf, int bufLen); extern int wfaTGRecvStart(int len, BYTE *parms, int *respLen, BYTE *respBuf); extern int wfaTGRecvStop(int len, BYTE *parms, int *respLen, BYTE *respBuf); extern int wfaTGSendStart(int len, BYTE *parms, int *respLen, BYTE *respBuf); @@ -262,6 +265,8 @@ extern int wfaFlushSockQueue(int profId); extern int wfaTGSendPing(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf); extern int wfaTGStopPing(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf); extern int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf); +extern int agtCmdProcGetTGVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf); + /* open tc flow with specific AC class */ extern int wfaOpenTrafficControlFlow(SOCKET sockfd, int tgClass, tgProfile_t *pTGProfile, tgTC_t *pTC); extern int wfaCloseTrafficControlFlow(tgTC_t *pTC); diff --git a/win_inc/wfa_tlv.h b/win_inc/wfa_tlv.h index b385505..29059e2 100644 --- a/win_inc/wfa_tlv.h +++ b/win_inc/wfa_tlv.h @@ -140,7 +140,8 @@ typedef struct _wfatlvHdr #define WFA_STA_REASSOCIATE_TLV (WFA_STA_DISCONNECT_TLV +0x01) /* 268 */ #define WFA_STA_SET_PWRSAVE_TLV (WFA_STA_REASSOCIATE_TLV + 0x01) /* 269 WMMPS */ #define WFA_STA_SET_POWER_SAVE_TLV (WFA_STA_SET_PWRSAVE_TLV + 0x01) /* 270 legacy PS*/ -#define WFA_STA_CLI_CMD_TLV (WFA_STA_SET_POWER_SAVE_TLV + 0x01) /* 271 */ +#define WFA_TRAFFIC_AGENT_VERSION_TLV (WFA_STA_SET_POWER_SAVE_TLV + 0x01) +#define WFA_STA_CLI_CMD_TLV (WFA_TRAFFIC_AGENT_VERSION_TLV + 0x01) /* 271 */ #ifdef WFA_P2P #define WFA_STA_GET_P2P_DEV_ADDRESS_TLV (WFA_STA_CLI_CMD_TLV + 0x01) /* 270 */ @@ -156,7 +157,6 @@ typedef struct _wfatlvHdr #define WFA_STA_WPS_READ_PIN_TLV (WFA_STA_SET_WPS_PBC_TLV + 0x01) /* 280 */ #define WFA_STA_WPS_ENTER_PIN_TLV (WFA_STA_WPS_READ_PIN_TLV + 0x01) /* 281 */ #define WFA_STA_GET_PSK_TLV (WFA_STA_WPS_ENTER_PIN_TLV + 0x01) /* 282 */ - #define WFA_STA_NEW_COMMANDS_END (WFA_STA_GET_PSK_TLV + 0x01) #else #define WFA_STA_NEW_COMMANDS_END (WFA_STA_CLI_CMD_TLV + 0x01) @@ -178,7 +178,8 @@ typedef struct _wfatlvHdr #define WFA_STA_REASSOCIATE_RESP_TLV (WFA_STA_DISCONNECT_RESP_TLV + 0x01) /* 524 */ #define WFA_STA_SET_PWRSAVE_RESP_TLV (WFA_STA_REASSOCIATE_RESP_TLV + 0x01) /* 525 */ #define WFA_STA_SET_POWER_SAVE_RESP_TLV (WFA_STA_SET_PWRSAVE_RESP_TLV + 0x01) /* 526, legacy PS */ -#define WFA_STA_CLI_CMD_RESP_TLV (WFA_STA_SET_POWER_SAVE_RESP_TLV + 0x01) /* 527 */ +#define WFA_TRAFFIC_AGENT_VERSION_RESP_TLV (WFA_STA_SET_POWER_SAVE_RESP_TLV + 0x01) +#define WFA_STA_CLI_CMD_RESP_TLV (WFA_TRAFFIC_AGENT_VERSION_RESP_TLV + 0x01) /* 528 */ #ifdef WFA_P2P #define WFA_STA_GET_P2P_DEV_ADDRESS_RESP_TLV (WFA_STA_CLI_CMD_RESP_TLV + 0x01) /* 525 */ diff --git a/win_inc/wfa_ver.h b/win_inc/wfa_ver.h index d0590e4..0d793cb 100644 --- a/win_inc/wfa_ver.h +++ b/win_inc/wfa_ver.h @@ -19,6 +19,8 @@ #ifndef _WFA_VER_H #define _WFA_VER_H -#define WFA_SYSTEM_VER "WIN7_WIN8_DUT-v9.0.0" +#define WFA_SYSTEM_VER "WIN7_WIN8_DUT-WTSv9.2.0" + +#define WFA_TG_VER "WIN7_WIN8-TG-WTSv9.2.0" #endif \ No newline at end of file diff --git a/win_inc/wfa_wmmps.h b/win_inc/wfa_wmmps.h index ffedc23..c0a700a 100644 --- a/win_inc/wfa_wmmps.h +++ b/win_inc/wfa_wmmps.h @@ -163,7 +163,7 @@ typedef struct wfa_wmmps pthread_t thr; pthread_cond_t thr_flag_cond; pthread_mutex_t thr_flag_mutex; -}wfaWmmPS_t; +} wfaWmmPS_t; /* WMMPS used sending dirction routines implemented in wfa_thr.c start with Cap W */ int WfaStaSndHello(char,int,int *state); diff --git a/win_lib/wfa_ca_resp.c b/win_lib/wfa_ca_resp.c index 3a0d007..88409bd 100644 --- a/win_lib/wfa_ca_resp.c +++ b/win_lib/wfa_ca_resp.c @@ -82,9 +82,10 @@ dutCommandRespFuncPtr wfaCmdRespProcFuncTbl[(WFA_STA_RESPONSE_END - WFA_STA_COMM wfaStaReAssociationResp, wfaStaSetPwrSaveResp, /* 60 */ wfaStaSetPowerSaveResp, /* 61 legacy power save */ + wfaTrafficAgentVersionResp, wfaStaCliCmdResp, -#ifdef WFA_P2P +#ifdef WFA_P2P wfaStaGetP2pDevAddressResp, wfaStaSetP2pResp, wfaStaP2pConnectResp, @@ -101,7 +102,7 @@ dutCommandRespFuncPtr wfaCmdRespProcFuncTbl[(WFA_STA_RESPONSE_END - WFA_STA_COMM wfaStaWpsEnterPinResp, wfaStaGetPskResp, #endif - + }; int caCmdNotDefinedYet(BYTE *cmdBuf) @@ -385,6 +386,13 @@ int wfaTrafficAgentSendResp(BYTE *cmdBuf) strncat(wfaCAAgetData.gRespStr, copyBuf, sizeof(copyBuf)-1); } + strncat(wfaCAAgetData.gRespStr, ",txActFrames,", 13); + for(i=0; ilen; int numStreams = len/sizeof(dutCmdResponse_t); - //DPRINT_INFO(WFA_OUT, "Entering wfaTrafficAgentRecvStopResp ...\n"); - dutCmdResponse_t statResp[WFA_MAX_TRAFFIC_STREAMS]; DPRINT_INFO(WFA_OUT, "Entering wfaTrafficAgentRecvStopResp ...\n"); @@ -497,6 +504,13 @@ int wfaTrafficAgentRecvStopResp(BYTE *cmdBuf) strncat(wfaCAAgetData.gRespStr, copyBuf, sizeof(copyBuf)-1); } + strncat(wfaCAAgetData.gRespStr, ",txActFrames,", 13); + for(i=0; istatus) + { + case STATUS_RUNNING: + DPRINT_INFO(WFA_OUT, "wfaTrafficAgentPingStart running ...\n"); + done = 1; + break; + + case STATUS_COMPLETE: + sprintf(wfaCAAgetData.gRespStr, "status,COMPLETE,version,%s\r\n", stpResp->cmdru.version); + break; + + default: + sprintf(wfaCAAgetData.gRespStr, "status,INVALID\r\n"); + } + + DPRINT_INFO(WFA_OUT, " %s\n", wfaCAAgetData.gRespStr); + wfaCtrlSend(wfaCAAgetData.gCaSockfd, (BYTE *)wfaCAAgetData.gRespStr, strlen(wfaCAAgetData.gRespStr)); + + return done; +} + int wfaStaGetMacAddressResp(BYTE *cmdBuf) { int done=0; @@ -932,9 +973,13 @@ int wfaStaGetStatsResp(BYTE *cmdBuf) break; case STATUS_COMPLETE: - sprintf(wfaCAAgetData.gRespStr, "status,COMPLETE,txFrames,%i,rxFrames,%i,txMulticast,%i,rxMulticast,%i,fcsErrors,%i,txRetries,%i\r\n", - stats->txFrames, stats->rxFrames, stats->txMulticast, stats->rxMulticast, stats->fcsErrors, stats->txRetries); - break; + sprintf(wfaCAAgetData.gRespStr, "status,COMPLETE,txActFrames,%i,txFrames,%i,rxFrames,%i,txMulticast,%i,rxMulticast,%i,fcsErrors,%i,txRetries,%i\r\n", + stats->txActFrames, stats->txFrames, stats->rxFrames, stats->txMulticast, stats->rxMulticast, stats->fcsErrors, stats->txRetries); + + //sprintf(wfaCAAgetData.gRespStr, "status,COMPLETE,txFrames,%i,rxFrames,%i,txMulticast,%i,rxMulticast,%i,fcsErrors,%i,txRetries,%i\r\n", + // stats->txFrames, stats->rxFrames, stats->txMulticast, stats->rxMulticast, stats->fcsErrors, stats->txRetries); + + break; case STATUS_ERROR: sprintf(wfaCAAgetData.gRespStr, "status,ERROR\r\n"); diff --git a/win_lib/wfa_cmdproc.c b/win_lib/wfa_cmdproc.c index f141f2f..b94d41c 100644 --- a/win_lib/wfa_cmdproc.c +++ b/win_lib/wfa_cmdproc.c @@ -43,6 +43,7 @@ typeNameStr_t keywordStr[] = { KW_USERPRIORITY, "userpriority", NULL}, { KW_MAXCNT, "maxcnt", NULL}, { KW_HTI, "hti", NULL}, + { KW_TRANSPROTOTYPE, "transProtoType", NULL}, }; /* profile type string table */ @@ -76,7 +77,6 @@ int cmdProcNotDefinedYet(char *pcmdStr, char *buf, int *len) } - /* * xcCmdProcGetVersion(): process the command get_version string from TM * to convert it into a internal format @@ -109,7 +109,7 @@ int xcCmdProcAgentConfig(char *pcmdStr, BYTE *aBuf, int *aLen) int userPrio = 0; wfaTLV *hdr = (wfaTLV *)aBuf; - tgProfile_t tgpf = {0, 0, "", -1, "", -1, 0, 0, 0, TG_WMM_AC_BE, 0}; + tgProfile_t tgpf = {0, 0, "", -1, "", -1, 0, 0, 0, TG_WMM_AC_BE, 0, 0, -1, 0}; tgProfile_t *pf = &tgpf; DPRINT_INFO(WFA_OUT, "start xcCmdProcAgentConfig ...\n"); @@ -118,6 +118,7 @@ int xcCmdProcAgentConfig(char *pcmdStr, BYTE *aBuf, int *aLen) if(aBuf == NULL) return WFA_FAILURE; + pcmdStr = rtrim(pcmdStr); while((str = strtok_r(NULL, ",", (char **)&pcmdStr)) != NULL) { for(i = 0; itrafficClass = TG_WMM_AC_BE2; - + pf->trafficClass = TG_WMM_AC_BE2; } else { @@ -400,8 +400,7 @@ int xcCmdProcAgentConfig(char *pcmdStr, BYTE *aBuf, int *aLen) kwcnt++; str = NULL; break; - - //------------------------------------------------ + case KW_HTI: str = strtok_r(NULL, ",", (char **)&pcmdStr); @@ -422,7 +421,20 @@ int xcCmdProcAgentConfig(char *pcmdStr, BYTE *aBuf, int *aLen) kwcnt++; str = NULL; break; - //----------------------------------------------- + + case KW_TRANSPROTOTYPE: + str = strtok_r(NULL, ",", (char **)&pcmdStr); + + if(strcasecmp(str, "1") == 0) + { + pf->transProtoType = 1; + } + else + { + pf->transProtoType = 0; + } + DPRINT_INFO(WFA_OUT, "transProtoType %s\r\n", str); + break; default: ; @@ -650,6 +662,31 @@ int xcCmdProcAgentRecvStop(char *pcmdStr, BYTE *aBuf, int *aLen) return WFA_SUCCESS; } +/* +* xcCmdProcAgentVersion(): Process and send the Control command +* "traffic_agent_version" +* input - pcmdStr parameter string pointer +* return - WFA_SUCCESS or WFA_FAILURE; +*/ +int xcCmdProcAgentVersion(char *pcmdStr, BYTE *aBuf, int *aLen) +{ + wfaTLV *hdr = (wfaTLV *)aBuf; + + DPRINT_INFO(WFA_OUT, "Entering xcCmdProcAgentRecvStop ...\n"); + + if(aBuf == NULL) + return WFA_FAILURE; + + memset(aBuf, 0, *aLen); + + hdr->tag = WFA_TRAFFIC_AGENT_VERSION_TLV; + hdr->len = 0; /* multiple 4s if more streams */ + + *aLen = 4; + + return WFA_SUCCESS; +} + /* * xcCmdProcAgentSendPing(): Process and send the Control command * "traffic_agent_send_ping" diff --git a/win_lib/wfa_cmdtbl.c b/win_lib/wfa_cmdtbl.c index 8d8312c..32f3e0f 100644 --- a/win_lib/wfa_cmdtbl.c +++ b/win_lib/wfa_cmdtbl.c @@ -86,9 +86,10 @@ xcCommandFuncPtr gWfaCmdFuncTbl[WFA_STA_COMMANDS_END+(WFA_STA_NEW_COMMANDS_END - wfaStaResetDefault, /* WFA_STA_RESET_DEFAULT_TLV (43)*/ wfaStaDisconnect, /* WFA_STA_DISCONNECT_TLV (44)*/ wfaStaReassociate, /* WFA_STA_REASSOCIATE_TLV (45)*/ - wfaStaSetPwrSave, /* WFA_STA_SET_PWRSAVE_TLV (60)*/ - wfaStaSetPowerSave, /* WFA_STA_SET_POWER_SAVE_TLV legacy (61)*/ - wfaStaCliCommand, /* WFA_STA_CLI_CMD_TLV (46)*/ + wfaStaSetPwrSave, /* WFA_STA_SET_PWRSAVE_TLV (46)*/ + wfaStaSetPowerSave, /* WFA_STA_SET_POWER_SAVE_TLV legacy (47)*/ + agtCmdProcGetTGVersion, /* (48)*/ + wfaStaCliCommand, /* WFA_STA_CLI_CMD_TLV (49)*/ #ifdef WFA_P2P wfaStaGetP2pDevAddress, /* (47)*/ diff --git a/win_lib/wfa_cs.c b/win_lib/wfa_cs.c index dfa4a36..8d54326 100644 --- a/win_lib/wfa_cs.c +++ b/win_lib/wfa_cs.c @@ -26,7 +26,7 @@ #ifdef WFA_WMM_AC_EXT extern int wfaTGSetPrio(int sockfd, int tgClass); #endif - +extern char e2eResults[]; #define FW(x,y) FindWindowEx(x, NULL, y, L"") char *wtsPath = "C:\\WFA"; @@ -58,6 +58,23 @@ int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf) return WFA_SUCCESS; } +int agtCmdProcGetTGVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf) +{ + dutCmdResponse_t *getverResp = &wfaDutAgentData.gGenericResp; + + DPRINT_INFOL(WFA_OUT, "Entering agtCmdProcGetTGVersion ...\n"); + + getverResp->status = STATUS_COMPLETE; + strncpy(getverResp->cmdru.version, WFA_TG_VER, WFA_VERSION_LEN-1); + + wfaEncodeTLV(WFA_TRAFFIC_AGENT_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); + + DPRINT_INFOL(WFA_OUT, "Completing ...\n"); + + return WFA_SUCCESS; +} + /** Force the station wireless I/F to re/associate with the AP * @param len not used. * @param caCmdBuf A buffer containing the command passed from control agent. @@ -537,15 +554,15 @@ int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBu verifyIpResp->status = STATUS_COMPLETE; verifyIpResp->cmdru.connected = 0; - btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT); + if ((wfaTGWMMData.btSockfd = wfaCreateSock(SOCK_TYPE_UDP, "127.0.0.1", WFA_UDP_ECHO_PORT)) == WFA_FAILURE) + { + zlog_info(zc, "Error creating socket ...\r\n"); + verifyIpResp->status = STATUS_ERROR; + wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; - if(btSockfd == -1) - { - verifyIpResp->status = STATUS_ERROR; - wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf); - *respLen = WFA_TLV_HDR_LEN + 4; - return WFA_FAILURE; - } + return WFA_FAILURE; + } toAddr.sin_family = AF_INET; toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr); @@ -553,7 +570,7 @@ int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBu while(done) { - wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr); + wfaTrafficSendTo(wfaTGWMMData.btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr); cnt++; fds[0].fd = btSockfd; @@ -3045,6 +3062,8 @@ void _setProg(char *progname) wfaDutAgentCAPIData.progSet = eDEF_VHT; else if(strcmp(progname, "11n") ==0) wfaDutAgentCAPIData.progSet = eDEF_11N; + else if(strcmp(progname, "60G") ==0) // fix: add it for 60GHz + wfaDutAgentCAPIData.progSet = eDEF_60G; else wfaDutAgentCAPIData.progSet = 0; } @@ -3231,6 +3250,17 @@ int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) caStaCliCmdResp_t infoResp; + int regValInd = 0; + + HKEY hKey = NULL; + LONG lErrorCode; + HANDLE hEvent = NULL; + DWORD TimeoutVal = 30000; + DWORD dwWaitResult; + + DWORD dwFilter = REG_NOTIFY_CHANGE_LAST_SET; + int size1 = 0; + DPRINT_INFOL(WFA_OUT, "\nEntry wfaStaCliCommand... \n"); DPRINT_INFOL(WFA_OUT, "\nThe command Received: %s\n",caCmdBuf); @@ -3304,9 +3334,7 @@ int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) } DPRINT_INFOL(WFA_OUT, "CMDSTR =========== %s ==================\n", CmdStr); - // try - Sleep(3000); - + CmdReturnFlag =0; // check the return process @@ -3339,30 +3367,70 @@ int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) } fclose(wfaCliFd); } + else + { + infoResp.status = STATUS_ERROR; + DPRINT_INFOL(WFA_OUT, "Cannot open the file %s\n", clfile); + goto END; + } st = 1; wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); + /* should excused with CmdReturnFlag setting, but in fact it is NOT, why, bug? benz */ + lErrorCode = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Environment"), 0, KEY_NOTIFY, &hKey); + if (lErrorCode != ERROR_SUCCESS) + { + DPRINT_INFOL(WFA_OUT, "Error in RegOpenKeyEx (%d).\r\n", lErrorCode); + goto CLEANUP; + } + + hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hEvent == NULL) + { + DPRINT_INFOL(WFA_OUT, "Error in CreateEvent (%d).\r\n", GetLastError()); + goto CLEANUP; + } + + lErrorCode = RegNotifyChangeKeyValue(hKey, FALSE, dwFilter, hEvent, TRUE); + if (lErrorCode != ERROR_SUCCESS) + { + DPRINT_INFOL(WFA_OUT, "Error in RegNotifyChangeKeyValue (%d).\r\n", lErrorCode); + goto CLEANUP; + } + + DPRINT_INFOL(WFA_OUT, "Waiting for a change in the specified key...\r\n"); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & echo CLI: %s & %s", wfaDutAgentData.WFA_CLI_CMD_DIR, CmdStr, CmdStr); ret = system(wfaDutAgentData.gCmdStr); + dwWaitResult = WaitForSingleObject(hEvent, TimeoutVal); + if (dwWaitResult == WAIT_OBJECT_0) + { + DPRINT_INFOL(WFA_OUT, "Change has occurred.\r\n"); + } + else if (dwWaitResult == WAIT_TIMEOUT) + { + DPRINT_INFOL(WFA_OUT, "Wait registry key timeout.\r\n"); + } + else + { + DPRINT_INFOL(WFA_OUT, "Error in WaitForSingleObject (%d).\r\n", GetLastError()); + infoResp.status = STATUS_ERROR; + goto CLEANUP; + } + DPRINT_INFOL(WFA_OUT, "\nRUN-> %s system call retVale=%i\n", wfaDutAgentData.gCmdStr, ret); - Sleep(2000); - - memset(&retstr[0],'\0',32); - while(retstr[0] =='\0' && ckcnt > 0) - { - wfaGetEnvVal("WFA_CLI_STATUS",&retstr[0],sizeof(retstr)); - ckcnt--; - Sleep(2000); - } + memset(&retstr[0],'\0',32); + wfaGetEnvVal("WFA_CLI_STATUS",&retstr[0],sizeof(retstr)); DPRINT_INFOL(WFA_OUT, "\nCLI CmdStr %s retrived WFA_CLI_STATUS=%s\n", CmdStr, retstr); if(strlen(retstr) > 0) st = atoi(retstr); + DPRINT_INFOL(WFA_OUT, "CLI status %d\n",st); infoResp.resFlag=CmdReturnFlag; switch(st) @@ -3373,8 +3441,43 @@ int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) { memset(&retstr[0],'\0',32); DPRINT_INFOL(WFA_OUT, "cli status beforoe %s**** len%d**** \n", retstr,strlen(retstr)); + lErrorCode = RegNotifyChangeKeyValue(hKey, FALSE, dwFilter, hEvent, TRUE); + if (lErrorCode != ERROR_SUCCESS) + { + DPRINT_INFOL(WFA_OUT, "Error in RegNotifyChangeKeyValue (%d).\r\n", lErrorCode); + goto CLEANUP; + } + dwWaitResult = WaitForSingleObject(hEvent, TimeoutVal); + if (dwWaitResult == WAIT_OBJECT_0) + { + DPRINT_INFOL(WFA_OUT, "Change has occurred.\r\n"); + } + else if (dwWaitResult == WAIT_TIMEOUT) + { + DPRINT_INFOL(WFA_OUT, "Wait registry key timeout.\r\n"); + } + else + { + DPRINT_INFOL(WFA_OUT, "Error in WaitForSingleObject (%d).\r\n", GetLastError()); + goto CLEANUP; + } + // Close the key. + if (hKey != NULL && RegCloseKey(hKey) != ERROR_SUCCESS) + { + DPRINT_INFOL(WFA_OUT, "Error in RegCloseKey (%d).\r\n", GetLastError()); + } + + // Close the handle. + if (hEvent != NULL && !CloseHandle(hEvent)) + { + DPRINT_INFOL(WFA_OUT, "Error in CloseHandle (%d).\r\n", GetLastError()); + } + wfaGetEnvVal("WFA_CLI_RETURN",&retstr[0],sizeof(retstr)); - DPRINT_INFOL(WFA_OUT, "cli status %s**** len%d**** \n", retstr,strlen(retstr)); + if (retstr != NULL) + { + DPRINT_INFOL(WFA_OUT, "cli status %s**** len%d**** \n", retstr,strlen(retstr)); + } memset(&infoResp.result[0],'\0',WFA_CLI_CMD_RESP_LEN); if(retstr != NULL) { @@ -3382,7 +3485,11 @@ int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) DPRINT_INFOL(WFA_OUT, "Return CLI result to CA: %s****\n", &infoResp.result[0]); } else + { strcpy(&infoResp.result[0], "ENV_VAR_NOT_DEFINED"); + } + + goto END; } break; @@ -3396,6 +3503,20 @@ int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) break; } +CLEANUP: + // Close the key. + if (hKey != NULL && RegCloseKey(hKey) != ERROR_SUCCESS) + { + DPRINT_INFOL(WFA_OUT, "Error in RegCloseKey (%d).\r\n", GetLastError()); + } + + // Close the handle. + if (hEvent != NULL && !CloseHandle(hEvent)) + { + DPRINT_INFOL(WFA_OUT, "Error in CloseHandle (%d).\r\n", GetLastError()); + } + +END: wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); @@ -3479,7 +3600,7 @@ int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_get_p2p_dev_address /interface %s", WFA_CLI_CMD_DIR, intf); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_get_p2p_dev_address /interface %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3562,7 +3683,7 @@ int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_set_p2p /interface %s %s", WFA_CLI_CMD_DIR, intf, cmd); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_set_p2p /interface %s %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf, cmd); st = wfaExecuteCLI(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3612,7 +3733,7 @@ int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_connect /interface %s /p2pdevid %s", WFA_CLI_CMD_DIR, intf,getStaP2pConnect->devId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_connect /interface %s /p2pdevid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pConnect->devId); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3674,7 +3795,7 @@ int wfaStaP2pJoin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_join /interface %s /p2pdevid %s /ssid %s", WFA_CLI_CMD_DIR, intf,getStaP2pJoin->devId,getStaP2pJoin->ssid); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_join /interface %s /p2pdevid %s /ssid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pJoin->devId,getStaP2pJoin->ssid); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3726,7 +3847,7 @@ int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *resp wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_start_group_formation /interface %s /p2pdevid %s /intent_val %d", WFA_CLI_CMD_DIR, intf,getStaP2pStartGrpForm->devId,getStaP2pStartGrpForm->intent_val); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_start_group_formation /interface %s /p2pdevid %s /intent_val %d", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pStartGrpForm->devId,getStaP2pStartGrpForm->intent_val); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3787,7 +3908,7 @@ int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_dissolve /interface %s /groupid %s", WFA_CLI_CMD_DIR, intf,getStap2pDissolve->grpId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_p2p_dissolve /interface %s /groupid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStap2pDissolve->grpId); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3836,9 +3957,9 @@ int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_RETURN"); if(getStaP2pInvReq->grpId_flag == 1) - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_send_p2p_invitation_req /interface %s /p2pdevid %s /groupid %s", WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId,getStaP2pInvReq->grpId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_send_p2p_invitation_req /interface %s /p2pdevid %s /groupid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId,getStaP2pInvReq->grpId); else - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_send_p2p_invitation_req /interface %s /p2pdevid %s", WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_send_p2p_invitation_req /interface %s /p2pdevid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3891,9 +4012,9 @@ int wfaStaAcceptP2pReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_RETURN"); if(getStaP2pInvReq->grpId_flag == 1) - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_accept_p2p_invitation_req /interface %s /p2pdevid %s /groupid %s", WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId,getStaP2pInvReq->grpId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_accept_p2p_invitation_req /interface %s /p2pdevid %s /groupid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId,getStaP2pInvReq->grpId); else - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_accept_p2p_invitation_req /interface %s /p2pdevid %s", WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_accept_p2p_invitation_req /interface %s /p2pdevid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pInvReq->devId); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3943,7 +4064,7 @@ int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_send_p2p_provision_dis_req /interface %s /configmethod %s /p2pdevid %s", WFA_CLI_CMD_DIR, intf,getStaP2pProvDisReq->confMethod,getStaP2pProvDisReq->devId); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_send_p2p_provision_dis_req /interface %s /configmethod %s /p2pdevid %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaP2pProvDisReq->confMethod,getStaP2pProvDisReq->devId); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -3992,7 +4113,7 @@ int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_set_wps_pbc /interface %s", WFA_CLI_CMD_DIR, intf); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_set_wps_pbc /interface %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -4041,7 +4162,7 @@ int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_wps_read_pin /interface %s", WFA_CLI_CMD_DIR, intf); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_wps_read_pin /interface %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -4101,7 +4222,7 @@ int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_wps_enter_pin /interface %s /pin ", WFA_CLI_CMD_DIR, intf,getStaWpsEnterPin->wpsPin); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_wps_enter_pin /interface %s /pin ", wfaDutAgentData.WFA_CLI_CMD_DIR, intf,getStaWpsEnterPin->wpsPin); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); @@ -4151,7 +4272,7 @@ int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) wfaClearEnvVal("WFA_CLI_STATUS"); wfaClearEnvVal("WFA_CLI_RETURN"); - sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_get_psk /interface %s", WFA_CLI_CMD_DIR, intf); + sprintf(wfaDutAgentData.gCmdStr, "cd %s & sta_get_psk /interface %s", wfaDutAgentData.WFA_CLI_CMD_DIR, intf); system(wfaDutAgentData.gCmdStr); DPRINT_INFOL(WFA_OUT, "CLI Command %s\n", wfaDutAgentData.gCmdStr); diff --git a/win_lib/wfa_miscs.c b/win_lib/wfa_miscs.c index 6b9e933..ab23a10 100644 --- a/win_lib/wfa_miscs.c +++ b/win_lib/wfa_miscs.c @@ -21,9 +21,9 @@ * @brief File containing the miscellaneous utility rountines */ -#include "wfa_debug.h" +//#include "wfa_debug.h" #include "wfa_main.h" -#include "wfa_types.h" +//#include "wfa_types.h" #include /* For prototype of "_ftime()" */ @@ -219,7 +219,7 @@ int bigEndianBuff2Int(char *buff) */ void printProfile(tgProfile_t *pf) { - DPRINT_INFO(WFA_OUT, "profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n", pf->profile, pf->direction, pf->dipaddr, pf->dport, pf->sipaddr, pf->sport, pf->rate, pf->duration, pf->pksize); + DPRINT_INFO(WFA_OUT, "profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i transProtoType %i hti %i\r\n", pf->profile, pf->direction, pf->dipaddr, pf->dport, pf->sipaddr, pf->sport, pf->rate, pf->duration, pf->pksize, pf->transProtoType, pf->hti); } /** @@ -359,3 +359,25 @@ int strcasecmp(const char *s1, const char *s2) return toupper((unsigned char)*s1) - toupper((unsigned char)*s2); } + +/** + * Left trim of space + * @param s The string to be left trimmed +*/ +char *ltrim(char *s) +{ + while(isspace(*s)) s++; + return s; +} + +/** + * Right trim of space + * @param s The string to be right trimmed +*/ +char *rtrim(char *s) +{ + char* back = s + strlen(s); + while(isspace(*--back)); + *(back+1) = '\0'; + return s; +} \ No newline at end of file diff --git a/win_lib/wfa_sock.c b/win_lib/wfa_sock.c index 79e8d90..95ecf55 100644 --- a/win_lib/wfa_sock.c +++ b/win_lib/wfa_sock.c @@ -32,16 +32,16 @@ */ int wfaCreateTCPServSock(unsigned short port) { - int sock; /* socket to create */ + int sock; /* socket to create */ struct sockaddr_in servAddr; /* Local address */ const int on = 1; WSADATA wsaData; BOOL bOpt = TRUE; - int wsaret=WSAStartup(0x101,&wsaData); + int wsaret = WSAStartup(0x101,&wsaData); - if(wsaret!=0) + if(wsaret != 0) { - DPRINT_ERR(WFA_ERR, "createTCPServSock socket() failed"); + DPRINT_ERR(WFA_ERR, "socket init failed"); return WFA_FAILURE; } /* Create socket for incoming connections */ @@ -72,9 +72,110 @@ int wfaCreateTCPServSock(unsigned short port) return sock; } +/** + * Create a TCP socket + * @param serverIpAddr TCP Local ip address to bind. + * @param port TCP port to receive and send packet. + * @return socket id. +*/ +int wfaCreateTCPServSockImpl(char *serverIpAddr, unsigned short port) +{ + int sock; /* socket to create */ + struct sockaddr_in servAddr; /* Local address */ + const int on = 1; + WSADATA wsaData; + BOOL bOpt = TRUE; + + int wsaret = WSAStartup(0x101,&wsaData); + if(wsaret != 0) + { + DPRINT_ERR(WFA_ERR, "socket init failed"); + return WFA_FAILURE; + } + + /* Create socket for incoming connections */ + if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + DPRINT_ERR(WFA_ERR, "createTCPServSock socket() failed"); + return WFA_FAILURE; + } + + setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char*)&bOpt,sizeof(BOOL)); + + /* Construct local address structure */ + memset(&servAddr, 0, sizeof(servAddr)); + + servAddr.sin_family = AF_INET; /* Internet address family */ + //servAddr.sin_addr.s_addr = inet_addr(serverIpAddr); /* Any incoming interface */ + servAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ + servAddr.sin_port = htons(port); /* Local port */ + + /* Bind to the local address */ + if (bind(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + DPRINT_ERR(WFA_ERR, "bind() failed"); + return WFA_FAILURE; + } + + /* Mark the socket so it will listen for incoming connections */ + if (listen(sock, MAXPENDING) < 0) + { + DPRINT_ERR(WFA_ERR, "listen() failed"); + return WFA_FAILURE; + } + + return sock; +} + +/** + * Create a TCP client or UDP socket + * @param sockType TCP or UDP. + * @param ipaddr local UDP ip address to bind. + * @param port UDP port to receive and send packet. + * @return socket id. +*/ +int wfaCreateSock(int sockType, char *ipaddr, unsigned short port) +{ + // tcp + if (sockType == SOCK_TYPE_TCP) + { + return wfaCreateTCPCliSock(); + } + // udp or default + else + { + return wfaCreateUDPSock(ipaddr, port); + } +} + +/** + * Create a TCP client socket + * return socket id + */ +int wfaCreateTCPCliSock() +{ + WSADATA wsaData; + int s, c=0; + + if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) + { + DPRINT_ERR(WFA_ERR, "socket init failed"); + return WFA_FAILURE; + } + + s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); + if (s < 0) + { + DPRINT_ERR(WFA_ERR, "createTCPServSock socket() failed"); + return WFA_FAILURE; + } + + return s; +} + /** * Create a UDP socket - * @param ipaddr TCP Local ip address for test traffic. + * @param ipaddr Local UDP ip address to bind. * @param port UDP port to receive and send packet. * @return socket id. */ @@ -98,6 +199,7 @@ int wfaCreateUDPSock(char *ipaddr, unsigned short port) DPRINT_ERR(WFA_ERR, "createUDPSock socket() failed with error %d for port %d",errsv,port); return WFA_FAILURE; } + servAddr.sin_family = AF_INET; servAddr.sin_addr.s_addr = htonl(INADDR_ANY); servAddr.sin_port = htons(port); @@ -138,6 +240,54 @@ int wfaSetSockMcastRecvOpt(int sockfd, char *mcastgroup) return so; } +/** + * Called to connect to remote host through subroutine. + * @param sockType TCP or UDP. + * @param mysock Local socket handle. + * @param dport Destination port. + * @return Socket number if succeed, otherwise 1. +*/ +int wfaConnectToPeer(int sockType, int mysock, char *daddr, int dport) +{ + // tcp + if (sockType == SOCK_TYPE_TCP) + { + return wfaConnectTCPPeer(mysock, daddr, dport); + } + // udp or default + else + { + return wfaConnectUDPPeer(mysock, daddr, dport); + } +} + +/** + * Called to connect to remote host through TCP. + * @param mysock Local socket handle. + * @param daddr Destination IP address. + * @param dport Destination port. + * @return Connection status. +*/ +int wfaConnectTCPPeer(int mysock, char *daddr, int dport) +{ + struct sockaddr_in peerAddr; + int c; + + memset((char*)&peerAddr, 0, sizeof(peerAddr)); + peerAddr.sin_family = PF_INET; + peerAddr.sin_addr.s_addr = inet_addr (daddr); + peerAddr.sin_port = htons (dport); + + c = connect(mysock, (struct sockaddr*)&peerAddr, sizeof(peerAddr)); + if (c < 0) + { + DPRINT_ERR(WFA_ERR, "wfaConnectTCPPeer connect() failed: %d\r\n", WSAGetLastError()); + return WFA_FAILURE; + } + + return c; +} + /** * Called to set up a virtual connection to the receiver * @param mysock Local socket number. @@ -172,11 +322,10 @@ int wfaAcceptTCPConn(int servSock) clntLen = sizeof(clntAddr); /* Wait for a client to connect */ - if ((clntSock = accept(servSock, (struct sockaddr *) &clntAddr, - (int *)&clntLen)) < 0) + if ((clntSock = accept(servSock, (struct sockaddr *) &clntAddr, (int *)&clntLen)) < 0) { - DPRINT_ERR(WFA_ERR, "accept() failed"); - exit(1); + DPRINT_ERR(WFA_ERR, "accept() failed\n"); + return WFA_FAILURE; } /* clntSock is connected to a client! */ @@ -202,7 +351,6 @@ void wfaSetSockFiDesc(fd_set *fdset, int *maxfdn1, struct sockfds *fds) *maxfdn1 = max(*maxfdn1-1, *fds->cafd) + 1; } - #ifdef WFA_WMM_PS /* if the power save socket port valid */ if(*fds->psfd > 0) @@ -286,12 +434,11 @@ int wfaTrafficSendTo(int sock, char *buf, int bufLen, struct sockaddr *to) * @param from The address of sender of the data. * @return The number of bytes received. */ -int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from) +int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from, int bufLen) { int bytesRecvd =0; int addrLen=sizeof(struct sockaddr); - int NonBlock=0; /* 0 is blocking */ if (ioctlsocket(sock, FIONBIO, (u_long *)&NonBlock) == SOCKET_ERROR) { @@ -304,7 +451,7 @@ int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from) DPRINT_ERR(WFA_ERR, "Uninitialized buffer\n"); return WFA_ERROR; } - bytesRecvd = recv(sock, buf, MAX_RCV_BUF_LEN, 0); + bytesRecvd = recv(sock, buf, bufLen, 0); return bytesRecvd; } diff --git a/win_lib/wfa_tg.c b/win_lib/wfa_tg.c index a887941..e8cdb69 100644 --- a/win_lib/wfa_tg.c +++ b/win_lib/wfa_tg.c @@ -30,7 +30,7 @@ extern int gettimeofday(struct timeval *tv, void *tz); #ifdef WFA_WMM_WPA2 extern int wfaTrafficSendTo(int, char *, int, struct sockaddr *); -extern int wfaTrafficRecv(int, char *, struct sockaddr *); +extern int wfaTrafficRecv(int, char *, struct sockaddr *, int); extern DWORD WINAPI wfa_wpa2_sleep_thread(void *thr_param); #endif @@ -107,22 +107,37 @@ int wfaTGSendPing(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) myStream->id = streamid; /* the id start from 1 */ myStream->tblidx = wfaTGWMMData.slotCnt-1; - wfaTGWMMData.btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT); - if((wfaTGWMMData.btSockfd = wfaConnectUDPPeer(wfaTGWMMData.btSockfd, staPing->dipaddr, WFA_UDP_ECHO_PORT)) > 0) - { - wfaTGWMMData.gtgTransac = streamid; - wfaTGWMMData.gtgSend = streamid; + if ((wfaTGWMMData.btSockfd = wfaCreateSock(myStream->profile.transProtoType, "127.0.0.1", WFA_UDP_ECHO_PORT)) == WFA_FAILURE) + { + spresp->status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_SEND_PING_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)spresp, respBuf); + *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); - /* - * the framerate here is used to derive the timeout - * value for waiting transaction echo responses. - */ - wfaTGWMMData.gtimeOut = MINISECONDS/staPing->frameRate; /* in msec */ + return WFA_FAILURE; + } - /* set to longest time */ - if(staPing->duration == 0) - staPing->duration = 3600; - } + if((wfaTGWMMData.btSockfd = wfaConnectToPeer(myStream->profile.transProtoType, wfaTGWMMData.btSockfd, staPing->dipaddr, WFA_UDP_ECHO_PORT)) == WFA_FAILURE) + { + spresp->status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_SEND_PING_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)spresp, respBuf); + *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); + + return WFA_FAILURE; + } + + wfaTGWMMData.gtgTransac = streamid; + wfaTGWMMData.gtgSend = streamid; + + /* + * the framerate here is used to derive the timeout + * value for waiting transaction echo responses. + */ + wfaTGWMMData.gtimeOut = (int) (MINISECONDS/staPing->frameRate); /* in msec */ + + /* set to longest time */ + if(staPing->duration == 0) + staPing->duration = 3600; + #else DPRINT_INFOL(WFA_WNG, "Doesn't support UDP Echo\n"); #endif @@ -405,10 +420,10 @@ int wfaTGRecvStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) case PROF_MCAST: status = STATUS_COMPLETE; thisSockfd = wfaTGWMMData.btSockfd = wfaCreateUDPSock(theProfile->dipaddr, theProfile->dport); - if(wfaTGWMMData.btSockfd >= 0) + if(wfaTGWMMData.btSockfd >=0 ) { wfaTGWMMData.gtgRecv = streamid; - DPRINT_INFOL(WFA_OUT, "wfaTGRecvStart wfaCreateUDPSock for MCAST btSockfd=%\n", wfaTGWMMData.btSockfd); + DPRINT_INFOL(WFA_OUT, "wfaTGRecvStart wfaCreateUDPSock for MCAST btSockfd=%d addr=%s:%d\n", wfaTGWMMData.btSockfd,theProfile->dipaddr, theProfile->dport); } else { @@ -439,18 +454,18 @@ int wfaTGRecvStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) wfaTGWMMData.gtgTransac = streamid; wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag = streamid; - DPRINT_INFOL(WFA_OUT, "PROF_TRANSC usedThread %i\n", wfaTGWMMData.usedThread); + DPRINT_INFOL(WFA_OUT, "PROF_TRANSC wfaTGWMMData.usedThread %i\n", wfaTGWMMData.usedThread); DPRINT_INFOL(WFA_OUT, "\r\nFired thread %d\n",wfaTGWMMData.usedThread); DPRINT_INFOL(WFA_OUT, "\r\nThread %d flag is %d\n",wfaTGWMMData.usedThread,wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag); ret = ReleaseMutex(wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag_mutex); if ( ret == 0) { Sleep(100); - DPRINT_INFOL(WFA_OUT, "PROF_TRANSC usedThread %i streamId is %d, call release mutex ret = %d flag_mutex=%d errCd=%d \n", + DPRINT_INFOL(WFA_OUT, "PROF_TRANSC wfaTGWMMData.usedThread %i streamId is %d, call release mutex ret = %d flag_mutex=%d errCd=%d \n", wfaTGWMMData.usedThread, wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag, ret, wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag_mutex, GetLastError()); ret = ReleaseMutex(wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag_mutex); } - DPRINT_INFOL(WFA_OUT, "PROF_TRANSC usedThread %i flag-streamId is %d, release mutex ret = %d flag_mutex=%d \n", + DPRINT_INFOL(WFA_OUT, "PROF_TRANSC wfaTGWMMData.usedThread %i flag-streamId is %d, release mutex ret = %d flag_mutex=%d \n", wfaTGWMMData.usedThread, wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag, ret, wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag_mutex); wfaTGWMMData.usedThread++; @@ -463,7 +478,7 @@ int wfaTGRecvStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) */ wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag = streamid; - DPRINT_INFOL(WFA_OUT, "PROF_FILE_TX or PROF_IPTV, usedThread %i ; Fired thread %d flag is %d\n", + DPRINT_INFOL(WFA_OUT, "PROF_FILE_TX or PROF_IPTV, wfaTGWMMData.usedThread %i ; Fired thread %d flag is %d\n", wfaTGWMMData.usedThread,wfaTGWMMData.usedThread,wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag); ReleaseMutex(wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag_mutex); @@ -627,6 +642,7 @@ int wfaTGRecvStop(int len, BYTE *parms, int *respLen, BYTE *respBuf) } break; + case PROF_UAPSD: #ifdef WFA_WMM_PS DPRINT_INFOL(WFA_OUT, "entering tgRecvStop PROF_UAPSD\n"); @@ -744,39 +760,43 @@ int wfaTGSendStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) } else - { - wfaTGWMMData.btSockfd = wfaCreateUDPSock(theProfile->sipaddr, theProfile->sport); - if((wfaTGWMMData.btSockfd=wfaConnectUDPPeer(wfaTGWMMData.btSockfd, theProfile->dipaddr, theProfile->dport)) > 0) - { - wfaTGWMMData.gtgSend = streamid; - } - else - { - staSendResp.status = STATUS_ERROR; - wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); - *respLen = WFA_TLV_HDR_LEN + 4; - - return WFA_FAILURE; - } + { + if ((wfaTGWMMData.btSockfd = wfaCreateSock(theProfile->transProtoType, theProfile->sipaddr, theProfile->sport)) == WFA_FAILURE) + { + staSendResp.status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; + + return WFA_FAILURE; + } + + if((wfaTGWMMData.btSockfd = wfaConnectToPeer(theProfile->transProtoType, wfaTGWMMData.btSockfd, theProfile->dipaddr, theProfile->dport)) == WFA_FAILURE) + { + staSendResp.status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; + + return WFA_FAILURE; + } + + wfaTGWMMData.gtgSend = streamid; } break; - case PROF_MCAST: - wfaTGWMMData.btSockfd = wfaCreateUDPSock(theProfile->sipaddr, theProfile->sport); - if(wfaTGWMMData.btSockfd) - { - wfaTGWMMData.gtgSend = streamid; - } - else + case PROF_MCAST: + if ((wfaTGWMMData.btSockfd = wfaCreateSock(SOCK_TYPE_UDP, theProfile->sipaddr, theProfile->sport)) == WFA_FAILURE) { - staSendResp.status = STATUS_ERROR; + DPRINT_INFOL(WFA_OUT, "socket creation failed\r\n"); + staSendResp.status = STATUS_ERROR; - wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); - *respLen = WFA_TLV_HDR_LEN + 4; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; - return WFA_FAILURE; + return WFA_FAILURE; } + wfaTGWMMData.gtgSend = streamid; + so = wfaSetSockMcastSendOpt(wfaTGWMMData.btSockfd); if (so < 0) { @@ -801,7 +821,7 @@ int wfaTGSendStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag = streamid; wfaTGWMMData.mainSendThread = wfaTGWMMData.usedThread; - DPRINT_INFOL(WFA_OUT, "usedThread %i\n", wfaTGWMMData.usedThread); + DPRINT_INFOL(WFA_OUT, "wfaTGWMMData.usedThread %i\n", wfaTGWMMData.usedThread); DPRINT_INFOL(WFA_OUT, "\r\nFired thread %d\n", wfaTGWMMData.usedThread); DPRINT_INFOL(WFA_OUT, "\r\nThread %d flag is %d\n", wfaTGWMMData.usedThread, wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag); ReleaseMutex(wfaTGWMMData.wmm_thr[wfaTGWMMData.usedThread].thr_flag_mutex); @@ -813,29 +833,35 @@ int wfaTGSendStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) case PROF_TRANSC: #ifdef WFA_WMM_WPA2 - wfaTGWMMData.btSockfd = wfaCreateUDPSock(theProfile->sipaddr, theProfile->sport); - if((wfaTGWMMData.btSockfd = wfaConnectUDPPeer(wfaTGWMMData.btSockfd, theProfile->dipaddr, theProfile->dport)) > 0) - { - wfaTGWMMData.gtgTransac = streamid; - wfaTGWMMData.gtgSend = streamid; - - /* - * the framerate here is used to derive the timeout - * value for waiting transaction echo responses. - */ - wfaTGWMMData.gtimeOut = MINISECONDS/theProfile->rate; /* in msec */ - } - else - { - staSendResp.status = STATUS_ERROR; - wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); - *respLen = WFA_TLV_HDR_LEN + 4; + if ((wfaTGWMMData.btSockfd = wfaCreateSock(theProfile->transProtoType, theProfile->sipaddr, theProfile->sport)) == WFA_FAILURE) + { + staSendResp.status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; + + return WFA_FAILURE; + } + + if((wfaTGWMMData.btSockfd = wfaConnectToPeer(theProfile->transProtoType, wfaTGWMMData.btSockfd, theProfile->dipaddr, theProfile->dport)) == WFA_FAILURE) + { + staSendResp.status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; + + return WFA_FAILURE; + } + + wfaTGWMMData.gtgTransac = streamid; + wfaTGWMMData.gtgSend = streamid; - return WFA_SUCCESS; - } + /* + * the framerate here is used to derive the timeout + * value for waiting transaction echo responses. + */ + wfaTGWMMData.gtimeOut = MINISECONDS/theProfile->rate; /* in msec */ /* set duration for the test */ - DPRINT_INFOL(WFA_OUT, "\r\n TRANSFIX -Setting timer for %d ms\n",(theProfile->duration)*1000); + DPRINT_INFOL(WFA_OUT, "TRANSFIX -Setting timer for %d ms\n",(theProfile->duration)*1000); timer_dur = (theProfile->duration)*1000; CreateThread(NULL, 0, wfa_wpa2_sleep_thread, (PVOID)&timer_dur, 0,&thr_id); #endif @@ -844,26 +870,38 @@ int wfaTGSendStart(int len, BYTE *parms, int *respLen, BYTE *respBuf) case PROF_START_SYNC: #ifdef WFA_WMM_WPA2 DPRINT_INFOL(WFA_OUT, "profile port %i\n", theProfile->sport); - wfaTGWMMData.btSockfd = wfaCreateUDPSock(theProfile->sipaddr, theProfile->sport); - if((wfaTGWMMData.btSockfd = wfaConnectUDPPeer(wfaTGWMMData.btSockfd, theProfile->dipaddr, theProfile->dport)) > 0) - { - wfaTGWMMData.gtgTransac = streamid; - wfaTGWMMData.gtgSend = streamid; + if ((wfaTGWMMData.btSockfd = wfaCreateSock(theProfile->transProtoType, theProfile->sipaddr, theProfile->sport)) == WFA_FAILURE) + { + DPRINT_INFOL(WFA_OUT, "socket creation error"); + staSendResp.status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; + + return WFA_FAILURE; + } + if((wfaTGWMMData.btSockfd = wfaConnectToPeer(theProfile->transProtoType, wfaTGWMMData.btSockfd, theProfile->dipaddr, theProfile->dport)) == WFA_FAILURE) + { + DPRINT_INFOL(WFA_OUT, "connection failed\r\n"); + staSendResp.status = STATUS_ERROR; + wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf); + *respLen = WFA_TLV_HDR_LEN + 4; + + return WFA_FAILURE; + } + + wfaTGWMMData.gtgTransac = streamid; + wfaTGWMMData.gtgSend = streamid; #ifdef WFA_VOICE_EXT - if(theProfile->profile == PROF_START_SYNC) - wfaTGVoiceData.gtgStartSync = streamid; + if(theProfile->profile == PROF_START_SYNC) + wfaTGVoiceData.gtgStartSync = streamid; #endif - /* - * the framerate here is used to derive the timeout - * value for waiting transaction echo responses. - */ - wfaTGWMMData.gtimeOut = MINISECONDS/theProfile->rate; /* in msec */ - } - else - { - DPRINT_INFOL(WFA_OUT, "connection failed\n"); - } + /* + * the framerate here is used to derive the timeout + * value for waiting transaction echo responses. + */ + wfaTGWMMData.gtimeOut = MINISECONDS/theProfile->rate; /* in msec */ + /* set duration for the test */ DPRINT_INFOL(WFA_OUT, "\r\n SYNCFIX -Setting timer for %d ms\n",(theProfile->duration)*1000); @@ -927,6 +965,15 @@ int wfaTGReset(int len, BYTE *parms, int *respLen, BYTE *respBuf) wfaTGWMMData.txSockfd = -1; } + for (i = 0; i < WFA_MAX_WMM_STREAMS; i++) + { + if (wfaTGWMMData.svrSock[i] != -1) + { + CLOSE(wfaTGWMMData.svrSock[i]); + wfaTGWMMData.svrSock[i] = -1; + } + } + for(i=0;i 0) @@ -1014,7 +1061,7 @@ void tmout_stop_send(int num) wfaTGWMMData.runLoop = 0; /* - * once usedThread is reset, WMM tests using multithread is ended + * once wfaTGWMMData.usedThread is reset, WMM tests using multithread is ended * the threads will be reused for the next test. */ wfaTGWMMData.usedThread = 0; @@ -1178,6 +1225,7 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) struct timeval before, after,after1,af; int difftime = 0,x; int counter = 0; + struct timeval stime; int throttled_est_cost; int act_sleep_time; gettimeofday(&af,0); @@ -1194,13 +1242,12 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) if(theProf == NULL) { - //return FALSE; return WFA_FAILURE; } if(theProf->rate == 0) { - DPRINT_INFOL(WFA_OUT, "Input parameters control - Rate %i and progset %i and hti %i\n", theProf->duration, wfaDutAgentCAPIData.progSet, theProf->hti); + //DPRINT_INFOL(WFA_OUT, "Input parameters control - Rate %i and progset %i and hti %i\n", theProf->duration, wfaDutAgentCAPIData.progSet, theProf->hti); if(wfaDutAgentCAPIData.progSet == eDEF_VHT) // only for VHT or other high through programs { if(theProf->hti == WFA_ON) @@ -1212,9 +1259,16 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) } else { - packLen = MAX_LEGACY_PAYLOAD_LEN; + if (theProf->pksize <= 0) + { + packLen = MAX_LEGACY_PAYLOAD_LEN; + } + else + { + packLen = theProf->pksize; + } } - DPRINT_INFOL(WFA_OUT, "Input parameters control - Rate %i and progset %i and PacketLength %i\n", theProf->duration,wfaDutAgentCAPIData.progSet,packLen); + DPRINT_INFOL(WFA_OUT, "Input parameters control - duration %i and progset %i and PacketLength %i\n", theProf->duration,wfaDutAgentCAPIData.progSet,packLen); } else { @@ -1246,11 +1300,14 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) { /* experiment for VHT */ sleepTime = 50; + //sleepTime = wfaTGWMMData.sleep_time; if(becnt != 0) throttledRate = 700/20; else throttledRate = 800/20; - + + //throttledRate = wfaTGWMMData.throttle_rate; + throttledRate = 800/20; becnt++; DPRINT_INFOL(WFA_OUT, "running with HTI and rate 0\n"); @@ -1276,13 +1333,17 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) while(wfaTGWMMData.runLoop) { - if(packLen == 1001) - x=1; + /*if(packLen == 1001) + x=1;*/ counter++; /* fill in the counter */ int2BuffBigEndian(counter, &((tgHeader_t *)packBuf)->hdr[8]); + /*if(theProf->transProtoType == SOCK_TYPE_UDP && counter%throttledRate == 0) + { + Sleep(1); + }*/ /* * the following code is only used to slow down * over fast traffic flooding the buffer and cause @@ -1290,49 +1351,64 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) * some limitations, purely for experiment purpose. * each implementation needs some fine tune to it. */ - if(counter ==1) - { - gettimeofday(&before, NULL); - - before.tv_usec += sleepTime; - if(before.tv_usec > 1000000) - { - before.tv_usec -= 1000000; - before.tv_sec +=1; - } - } - - if(throttledRate != 0) - { - if(counter%throttledRate == 0) - { - gettimeofday(&after, NULL); - difftime = wfa_itime_diff(&after, &before); - - if(difftime > wfaTGWMMData.adj_latency) - { - // too much time left, go sleep - //DPRINT_INFOL(WFA_OUT"\r\n Sleeping for %d time", (difftime-adj_latency)/1000); - Sleep((difftime-wfaTGWMMData.adj_latency)/10000); - - gettimeofday(&after1, NULL); - difftime = wfa_itime_diff(&after1, &before); - } - - // burn the rest to absort latency - if(difftime >0) - buzz_time(difftime); - - before.tv_usec += sleepTime; - if(before.tv_usec > 1000000) - { - before.tv_usec -= 1000000; - before.tv_sec +=1; - } - } - } // otherwise, it floods + //In 60GHz, the throttle control has to be skipped since Intel device won't work properly without non-blocking socket + if (theProf->transProtoType == SOCK_TYPE_UDP) + { + if(counter ==1) + { + gettimeofday(&before, NULL); + + before.tv_usec += sleepTime; + if(before.tv_usec > 1000000) + { + before.tv_usec -= 1000000; + before.tv_sec +=1; + } + } + + if(throttledRate != 0) + { + if(counter%throttledRate == 0) + { + gettimeofday(&after, NULL); + difftime = wfa_itime_diff(&after, &before); + + if(difftime > wfaTGWMMData.adj_latency) + { + // too much time left, go sleep + //DPRINT_INFOL(WFA_OUT, "\r\n Sleeping for %d time", (difftime-wfaTGWMMData.adj_latency)/1000); + Sleep((difftime-wfaTGWMMData.adj_latency)/10000); + + gettimeofday(&after1, NULL); + difftime = wfa_itime_diff(&after1, &before); + } + + // burn the rest to absort latency + if(difftime >0) + { + //DPRINT_INFOL(WFA_OUT, "\r\n diff time %d ", difftime); + buzz_time(difftime); + } + + before.tv_usec += sleepTime; + if(before.tv_usec > 1000000) + { + before.tv_usec -= 1000000; + before.tv_sec +=1; + } + } + } // otherwise, it floods + } // end of if (theProf->transProtoType == SOCK_TYPE_UDP) + + /* + * Fill the timestamp to the header. + */ + gettimeofday(&stime, NULL); + int2BuffBigEndian(stime.tv_sec, &((tgHeader_t *)packBuf)->hdr[12]); + int2BuffBigEndian(stime.tv_usec, &((tgHeader_t *)packBuf)->hdr[16]); bytesSent = wfaTrafficSendTo(mySockfd, packBuf, packLen, (struct sockaddr *)&toAddr); + myStream->stats.txActFrames++; if(bytesSent != -1) { myStream->stats.txPayloadBytes += bytesSent; @@ -1364,6 +1440,11 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) DPRINT_ERR(WFA_ERR, "WSAStartup not yet called\n"); break; + case WSAEWOULDBLOCK: + ////DPRINT_ERR(WFA_ERR, "WSAStartup not yet called\n"); + ////Sleep(1); /* hold for 1 ms */ + break; + default: DPRINT_ERR(WFA_ERR, "Packet sent error %d\n",errsv); Sleep(20); @@ -1391,7 +1472,10 @@ int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen) /* return statistics */ sendResp.status = STATUS_COMPLETE; sendResp.streamId = myStream->id; + + DPRINT_INFOL(WFA_OUT, "Sent actutal frames are %d\r\n",myStream->stats.txActFrames); DPRINT_INFOL(WFA_OUT, "\r\n Sent frames are %d\n",myStream->stats.txFrames); + memcpy(&sendResp.cmdru.stats, &myStream->stats, sizeof(tgStats_t)); wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, sizeof(dutCmdResponse_t), @@ -1469,11 +1553,13 @@ int wfaSendShortFile(int mySockfd, int streamid, BYTE *sendBuf, int pksize, BYTE toAddr.sin_port = htons(theProf->dport); } - int2BuffBigEndian(myStream->stats.txFrames, &((tgHeader_t *)packBuf)->hdr[8]); - + int2BuffBigEndian(myStream->stats.txActFrames, &((tgHeader_t *)packBuf)->hdr[8]); + if(mySockfd != -1) bytesSent = wfaTrafficSendTo(mySockfd, (char *)packBuf, packLen, (struct sockaddr *)&toAddr); + myStream->stats.txActFrames++; + if(bytesSent != -1) { myStream->stats.txFrames++; @@ -1517,7 +1603,7 @@ int wfaSendShortFile(int mySockfd, int streamid, BYTE *sendBuf, int pksize, BYTE * @param recvBuf The buffer allocated to hold received packets. * @return The number of bytes received. */ -int wfaRecvFile(int mySockfd, int streamid, char *recvBuf) +int wfaRecvFile(int mySockfd, int streamid, char *recvBuf, int bufLen) { /* how many packets are received */ char *packBuf = recvBuf; @@ -1537,8 +1623,6 @@ int wfaRecvFile(int mySockfd, int streamid, char *recvBuf) return WFA_ERROR; } - memset(packBuf, 0, MAX_RCV_BUF_LEN); - memset(&fromAddr, 0, sizeof(fromAddr)); fromAddr.sin_family = AF_INET; fromAddr.sin_addr.s_addr = inet_addr(theProf->dipaddr); @@ -1560,7 +1644,7 @@ int wfaRecvFile(int mySockfd, int streamid, char *recvBuf) return WFA_ERROR; } /* it is always to receive at least one packet, in case more in the queue, just pick them up */ - bytesRecvd = wfaTrafficRecv(mySockfd, packBuf, (struct sockaddr *)&fromAddr); + bytesRecvd = wfaTrafficRecv(mySockfd, packBuf, (struct sockaddr *)&fromAddr, bufLen); if(!wfaTGWMMData.gtgTransac) { @@ -1618,7 +1702,7 @@ int wfaRecvFile(int mySockfd, int streamid, char *recvBuf) } } #endif - bytesRecvd = wfaTrafficRecv(mySockfd, packBuf, (struct sockaddr *)&fromAddr); + bytesRecvd = wfaTrafficRecv(mySockfd, packBuf, (struct sockaddr *)&fromAddr, bufLen); if (bytesRecvd == 0) SwitchToThread(); @@ -1672,7 +1756,7 @@ int wfaSendBitrateData(int mySockfd, int streamId, BYTE *pRespBuf, int *pRespLen int counter = 0, i; /* frame data sending count */ unsigned long difftime; dutCmdResponse_t sendResp; - struct timeval before, after; + struct timeval before, after, stime; DPRINT_INFOL(WFA_OUT, "wfaSendBitrateData entering\n"); @@ -1724,6 +1808,9 @@ int wfaSendBitrateData(int mySockfd, int streamId, BYTE *pRespBuf, int *pRespLen goto errcleanup; } memset(packBuf, 0, packLen + 4); + /* fill in the header */ + strncpy(packBuf, "1345678", sizeof(tgHeader_t)); + /* initialize the destination address */ memset(&toAddr, 0, sizeof(toAddr)); toAddr.sin_family = AF_INET; @@ -1747,7 +1834,15 @@ int wfaSendBitrateData(int mySockfd, int streamId, BYTE *pRespBuf, int *pRespLen iSleep++; /* fill in the counter */ int2BuffBigEndian(counter, &((tgHeader_t *)packBuf)->hdr[8]); + /* + * Fill the timestamp to the header. + */ + gettimeofday(&stime, NULL); + int2BuffBigEndian(stime.tv_sec, &((tgHeader_t *)packBuf)->hdr[12]); + int2BuffBigEndian(stime.tv_usec, &((tgHeader_t *)packBuf)->hdr[16]); + bytesSent = wfaTrafficSendTo(mySockfd, packBuf, packLen, (struct sockaddr *)&toAddr); + myStream->stats.txActFrames++; if(bytesSent != -1) { myStream->stats.txPayloadBytes += bytesSent; @@ -1839,8 +1934,8 @@ int wfaSendBitrateData(int mySockfd, int streamId, BYTE *pRespBuf, int *pRespLen *pRespLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); extraTimeSpendOnSending = extraTimeSpendOnSending/1000; - DPRINT_INFOL(WFA_OUT, "*** wfg_tg.cpp wfaSendBitrateData Count=%i txFrames=%i totalByteSent=%i sleepTotal=%llu milSec extraTimeSpendOnSending=%llu nOverTimeCount=%d nOverSend=%i rate=%d nDuration=%d ***\n", - counter, (myStream->stats.txFrames),(unsigned int) (myStream->stats.txPayloadBytes), sleepTotal,extraTimeSpendOnSending, nOverTimeCount, nOverSend, theProf->rate , nDuration); + DPRINT_INFOL(WFA_OUT, "*** wfg_tg.cpp wfaSendBitrateData Count=%i txActFrames=%i txFrames=%i totalByteSent=%i sleepTotal=%llu milSec extraTimeSpendOnSending=%llu nOverTimeCount=%d nOverSend=%i rate=%d nDuration=%d ***\n", + counter,(myStream->stats.txActFrames), (myStream->stats.txFrames),(unsigned int) (myStream->stats.txPayloadBytes), sleepTotal,extraTimeSpendOnSending, nOverTimeCount, nOverSend, theProf->rate , nDuration); wfaSleepMilsec(1000); return ret; diff --git a/win_lib/wfa_thr.c b/win_lib/wfa_thr.c index f371cf7..0b2f9c6 100644 --- a/win_lib/wfa_thr.c +++ b/win_lib/wfa_thr.c @@ -19,7 +19,7 @@ /***************************************************************************** Copyright (c) Microsoft All rights reserved. -Licensed under the Microsoft Limited Public License (the “License”); you may not +Licensed under the Microsoft Limited Public License (the $(D@<(Bicense?; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://msdn.microsoft.com/en-us/cc300389. @@ -61,625 +61,691 @@ extern int gettimeofday(struct timeval *tv, void *tz); extern tgStream_t *findStreamProfile(int id); extern void tmout_stop_send(int); -/* -* Function: ResolveAddress -* -* Description: -* This routine resolves the specified address and returns a list of addrinfo -* structure containing SOCKADDR structures representing the resolved addresses. -* Note that if 'addr' is non-NULL, then getaddrinfo will resolve it whether -* it is a string listeral address or a hostname. -*/ -struct addrinfo *ResolveAddress(char *addr, char *port, int af, int type, int proto) -{ - struct addrinfo hints, - *res = NULL; - int rc; - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = ((addr) ? 0 : AI_PASSIVE); - hints.ai_family = af; - hints.ai_socktype = type; - hints.ai_protocol = proto; - - DPRINT_INFOL(WFA_OUT, "receiving port %s\n", port); - rc = getaddrinfo(addr, port, &hints, &res); - if (rc != 0) - { - DPRINT_ERR(WFA_ERR, "Invalid address %s\n", addr); - return NULL; - } - - return res; -} - -/* -* Routine: -* DeleteFlow -* Description: -* Deletes the flow and its member variables -* Arguments: -* [in] pFlow - -* ptr to the existing Flow struct. -*/ -BOOL DeleteFlow (IN PTC_GEN_FLOW *pFlow) -{ - if(pFlow == NULL || *pFlow == NULL) - { - return TRUE; - } - - free(*pFlow); - *pFlow = NULL; - - return TRUE; -} - -/* -* Routine: -* CreateFlow -* Description: -* The function returns a tc flow in ppTcFlowObj on success -* Arguments: -* [in,out] ppTcFlowObj - -* double ptr to Flow struct in which the function returns the flow. -* [in] DSCPValue - -* dscp value for the flow -* [in] OnePValue - -* 802.1p value for the flow -* [in] ThrottleRate - -* throttle rate for the flow -* Return: -* TRUE if file creating is successful -* FALSE if creating file failed. -*/ -BOOL CreateFlow( IN OUT PTC_GEN_FLOW *_ppTcFlowObj, - IN USHORT DSCPValue, - IN USHORT OnePValue, - IN ULONG ThrottleRate) -{ - BOOL status = FALSE; - ULONG TokenRate = QOS_NOT_SPECIFIED; - ULONG TokenBucketSize = QOS_NOT_SPECIFIED; - ULONG PeakBandwidth = QOS_NOT_SPECIFIED; - ULONG Latency = QOS_NOT_SPECIFIED; - ULONG DelayVariation = QOS_NOT_SPECIFIED; - SERVICETYPE ServiceType = SERVICETYPE_BESTEFFORT; - ULONG MaxSduSize = QOS_NOT_SPECIFIED; - ULONG MinimumPolicedSize = QOS_NOT_SPECIFIED; - - PVOID pCurrentObject; - PTC_GEN_FLOW _pTcFlowObj = NULL; - - int Length = 0; - - // Calculate the memory size required for the optional TC objects - Length += (OnePValue == NOT_SPECIFIED ? 0 : sizeof(QOS_TRAFFIC_CLASS)) + - (DSCPValue == NOT_SPECIFIED ? 0 : sizeof(QOS_DS_CLASS)); - - // Print the Flow parameters - if(ThrottleRate == QOS_NOT_SPECIFIED) - { - } - else - { - ServiceType = SERVICETYPE_GUARANTEED; - } - - TokenRate = TokenBucketSize = ThrottleRate; - // Allocate the flow descriptor - _pTcFlowObj = (PTC_GEN_FLOW)malloc(FIELD_OFFSET(TC_GEN_FLOW, TcObjects) + Length); - if (!_pTcFlowObj) - { - DPRINT_ERR(WFA_ERR, "CreateFlow::Flow Allocation Failed\n"); - goto Exit; - } - - _pTcFlowObj->SendingFlowspec.TokenRate = TokenRate; - _pTcFlowObj->SendingFlowspec.TokenBucketSize = TokenBucketSize; - _pTcFlowObj->SendingFlowspec.PeakBandwidth = PeakBandwidth; - _pTcFlowObj->SendingFlowspec.Latency = Latency; - _pTcFlowObj->SendingFlowspec.DelayVariation = DelayVariation; - _pTcFlowObj->SendingFlowspec.ServiceType = ServiceType; - _pTcFlowObj->SendingFlowspec.MaxSduSize = MaxSduSize; - _pTcFlowObj->SendingFlowspec.MinimumPolicedSize = MinimumPolicedSize; - - memcpy(&(_pTcFlowObj->ReceivingFlowspec), &(_pTcFlowObj->SendingFlowspec), sizeof(_pTcFlowObj->ReceivingFlowspec)); - - _pTcFlowObj->TcObjectsLength = Length; - // Add any requested objects - pCurrentObject = (PVOID)_pTcFlowObj->TcObjects; - - if(OnePValue != NOT_SPECIFIED) - { - QOS_TRAFFIC_CLASS *pTClassObject = (QOS_TRAFFIC_CLASS*)pCurrentObject; - pTClassObject->ObjectHdr.ObjectType = QOS_OBJECT_TRAFFIC_CLASS; - pTClassObject->ObjectHdr.ObjectLength = sizeof(QOS_TRAFFIC_CLASS); - pTClassObject->TrafficClass = OnePValue; //802.1p tag to be used - - pCurrentObject = (PVOID)(pTClassObject + 1); - } - - if(DSCPValue != NOT_SPECIFIED) - { - QOS_DS_CLASS *pDSClassObject = (QOS_DS_CLASS*)pCurrentObject; - pDSClassObject->ObjectHdr.ObjectType = QOS_OBJECT_DS_CLASS; - pDSClassObject->ObjectHdr.ObjectLength = sizeof(QOS_DS_CLASS); - pDSClassObject->DSField = (DSCPValue << 3); //Services Type - } - - DeleteFlow(_ppTcFlowObj); - *_ppTcFlowObj = _pTcFlowObj; - - status = TRUE; - -Exit: - if(!status) - { - DPRINT_INFOL(WFA_OUT, "Flow Creation Failed\n"); - DeleteFlow(&_pTcFlowObj); - } - else - { - DPRINT_INFOL(WFA_OUT, "Flow Creation Succeeded\n"); - } - - return status; -} -/* -* Routine: -* DeleteFilter -* -* Description: -* Deletes the filter and its member variables -*/ -BOOL DeleteFilter(PTC_GEN_FILTER *ppFilter) -{ - PTC_GEN_FILTER pFilter; - - if (ppFilter == NULL || *ppFilter == NULL) - { - return TRUE; - } - - pFilter = (*ppFilter); - - if (pFilter->Pattern) - { - free(pFilter->Pattern); - } - - if (pFilter->Mask) - { - free(pFilter->Mask); - } -#ifndef WFA_TC_BACK2VHT - free(pFilter); /* fixed memory leak here */ -#endif - *ppFilter = NULL; - - return TRUE; -} - -/* -* Routine: -* CreateFilter -* Description: -* The function returns a tc filter in ppFilter on success -* Arguments: -* [in, out] ppFilter - -* double ptr to Filter struct in which the function returns the filter -* [in] Address - -* destination address of the outgoing packets of interest. -* [in] Port - -* destination port of the outgoing packets of interest. -* [in] ProtocolId - -* protocol of the outgoing packets of interest. -* Return: -* TRUE if filter creating successes. -* FALSE if failed. -*/ -BOOL CreateFilter( IN OUT PTC_GEN_FILTER *ppFilter, - IN SOCKADDR_STORAGE Address, - IN USHORT Port, - IN UCHAR ProtocolId) -{ - BOOL status = FALSE; - USHORT AddressFamily = Address.ss_family; - PTC_GEN_FILTER pFilter = NULL; - PIP_PATTERN pPattern = NULL; - PIP_PATTERN pMask = NULL; - - if(AddressFamily != AF_INET) - { - DPRINT_INFOL(WFA_OUT, "Address family is not AF_INET"); - goto Exit; - } - pFilter = (PTC_GEN_FILTER)malloc(sizeof(TC_GEN_FILTER)); - if(!pFilter) - { - DPRINT_INFOL(WFA_OUT, "Error, No memory for filter\n"); - goto Exit; - } - ZeroMemory(pFilter, sizeof(TC_GEN_FILTER)); - pPattern = (PIP_PATTERN)malloc(sizeof(IP_PATTERN)); - pMask = (PIP_PATTERN)malloc(sizeof(IP_PATTERN)); - - if(!pPattern || !pMask) - { - DPRINT_INFOL(WFA_OUT, "pPattern or pMask is null"); - goto Exit; - } - - memset(pPattern, 0, sizeof(IP_PATTERN)); - - pPattern->DstAddr = ((SOCKADDR_IN *)&Address)->sin_addr.s_addr; - pPattern->tcDstPort = htons(Port); - pPattern->ProtocolId = ProtocolId; - - memset(pMask, (ULONG)-1, sizeof(IP_PATTERN)); - - pMask->SrcAddr = 0; - pMask->tcSrcPort = 0; - - if(pPattern->tcDstPort == 0) - { - pMask->tcDstPort = 0; - } - - if(pPattern->ProtocolId == 0) - { - pMask->ProtocolId = 0; - } - - if(pPattern->DstAddr == 0) - { - pMask->DstAddr = 0; - } - - pFilter->AddressType = NDIS_PROTOCOL_ID_TCP_IP; - pFilter->PatternSize = sizeof(IP_PATTERN); - pFilter->Pattern = pPattern; - pFilter->Mask = pMask; - DeleteFilter(ppFilter); - *ppFilter = pFilter; - - status = TRUE; - -Exit: - if(!status) - { - DPRINT_INFOL(WFA_OUT, "Filter Creation Failed\n"); - DeleteFilter(&pFilter); - } - else - { - DPRINT_INFOL(WFA_OUT, "Filter Creation Succeeded\n"); - } - - return status; -} - -/* -* Routine: -* ClNotifyHandler -* Description: -* Empty notification handler. -* The ClNotifyHandler function is used by traffic control to notify the client of various -* traffic control$(Dx7(Bspecific events, including the deletion of flows, changes in filter parameters, -* or the closing of an interface. -* Arguments: -* [in] ClRegCtx - -* Client registration context, provided to traffic control by the client with the client's call -* to the TcRegisterClient function. -* [in] ClIfcCtx - -* Client interface context, provided to traffic control by the client with the client's call to -* the TcOpenInterface function. Note that during a TC_NOTIFY_IFC_UP event, ClIfcCtx is not -* available and will be set to NULL. -* [in] Event - -* Describes the notification event. See the Remarks section for a list of notification events. -* [in] SubCode - -* Handle used to further qualify a notification event. -* [in] BufSize - -* Size of the buffer included with the notification event, in bytes. -* [in] Buffer - -* Buffer containing the detailed event information associated with Event and SubCode. -* Return: -* None -*/ -void ClNotifyHandler( IN HANDLE ClRegCtx, - IN HANDLE ClIfcCtx, - IN ULONG Event, - IN HANDLE SubCode, - IN ULONG BufSize, - IN PVOID Buffer) -{ - UNREFERENCED_PARAMETER(ClRegCtx); - UNREFERENCED_PARAMETER(ClIfcCtx); - DPRINT_INFOL(WFA_OUT, "Traffict Control Flow::Unexpected notification: Event=%d, SubCode=%p, BufSize=%d, Buffer=%p", - (int)Event, (void *)SubCode, (int)BufSize, Buffer); -} - -/* -* Routine: -* ClearIfcList -* Description: -* Clears the IfcList and its member variables -* Arguments: -* [in] pIfcList - -* The interface list. -* Return: -* TRUE if successes or FALSE if fails. -*/ -BOOL ClearIfcList( IN PIFC_LIST pIfcList) -{ - ULONG i; - - if(!pIfcList) - { - return TRUE; - } - - if(pIfcList->pIfcInfo) - { - PIFC_INFO pCurrentIfcInfo = pIfcList->pIfcInfo; - - for(i = 0; i < pIfcList->IfcCount; i ++) - { - if(pCurrentIfcInfo->hFilter) - { - TcDeleteFilter(pCurrentIfcInfo->hFilter); - } - if(pCurrentIfcInfo->hFlow) - { - TcDeleteFlow(pCurrentIfcInfo->hFlow); - } - if(pCurrentIfcInfo->hIfc) - { - TcCloseInterface(pCurrentIfcInfo->hIfc); - } - - pCurrentIfcInfo++; - } - - free(pIfcList->pIfcInfo); - } - - ZeroMemory(pIfcList, sizeof(IFC_LIST)); - - return TRUE; -} - -/* -* Routine: -* MakeIfcList -* Description: -* The function enumerates all TC enabled interfaces. -* opens each TC enabled interface and stores each ifc handle in IFC_LIST struct -* pointed to by pIfcList. -* Arguments: -* [in] hClient - -* Handle returned by TcRegisterClient -* [in] pIfcList - -* ptr to IfcList structure which will be populated by the function -* Return: -* TRUE if successes or FALSE if fails. -*/ -BOOL - MakeIfcList( IN HANDLE hClient, - IN PIFC_LIST pIfcList) -{ - BOOL status = FALSE; - ULONG err = ERROR_INVALID_PARAMETER; - - ULONG BufferSize = 512, ActualBufferSize, RemainingBufferSize = 0; - PTC_IFC_DESCRIPTOR pIfcBuffer = NULL, pCurrentIfc = NULL; - PIFC_INFO pIfcInfo = NULL, pCurrentIfcInfo = NULL; - ULONG nIfcs = 0; - - // Enumerate the TC enabled interfaces - while(TRUE) - { - ActualBufferSize = BufferSize; - pIfcBuffer = (PTC_IFC_DESCRIPTOR)malloc(ActualBufferSize); - if(pIfcBuffer == NULL) - { - DPRINT_ERR(WFA_ERR, "Error MakeIfcList malloc failed\n"); - break; - } - - err = TcEnumerateInterfaces(hClient, &ActualBufferSize, pIfcBuffer); - if(err == ERROR_INSUFFICIENT_BUFFER) - { - DPRINT_ERR(WFA_ERR, "Error MakeIfcList TcEnumerateInterfaces failed, inc size continue to try\n"); - free(pIfcBuffer); - BufferSize *= 2; - } - else - { - break; - } - } - - if(err != NO_ERROR) - { - DPRINT_ERR(WFA_ERR, "Error MakeIfcList TcEnumerateInterfaces while loop errCd=%d\n", err); - goto Exit; - } - // Count the number of interfaces - pCurrentIfc = pIfcBuffer; - RemainingBufferSize = ActualBufferSize; - while(RemainingBufferSize) - { - nIfcs ++; - - RemainingBufferSize -= pCurrentIfc->Length; - pCurrentIfc = (PTC_IFC_DESCRIPTOR)(((PBYTE)pCurrentIfc) + pCurrentIfc->Length); - } - - if(nIfcs == 0) - { - DPRINT_ERR(WFA_ERR, "Error MakeIfcList nIfcs == 0\n"); - goto Exit; - } - // Allocate memory for the size(IFC_INFO) X nIfcs - pIfcInfo = (PIFC_INFO)malloc(sizeof(IFC_INFO) * nIfcs); - if(!pIfcInfo) - { - DPRINT_ERR(WFA_ERR, "Error MakeIfcList malloc pIfcInfo is NULL \n"); - goto Exit; - } - - ZeroMemory(pIfcInfo, sizeof(IFC_INFO) * nIfcs); - - ClearIfcList(pIfcList); - pIfcList->IfcCount = nIfcs; - pIfcList->pIfcInfo = pIfcInfo; - // Open Each interface and store the ifc handle in ifcList - pCurrentIfc = pIfcBuffer; - pCurrentIfcInfo = pIfcInfo; - - RemainingBufferSize = ActualBufferSize; - while(RemainingBufferSize) - { - HANDLE hIfc; - - err = TcOpenInterfaceW(pCurrentIfc->pInterfaceName, - hClient, - 0, - &hIfc); - - if(err != NO_ERROR) - { - DPRINT_ERR(WFA_ERR, "MakeIfcList TcOpenInterface Failed %d\n", err); - break; - } - - pCurrentIfcInfo->hIfc = hIfc; - - RemainingBufferSize -= pCurrentIfc->Length; - pCurrentIfc = (PTC_IFC_DESCRIPTOR)(((PBYTE)pCurrentIfc) + pCurrentIfc->Length); - pCurrentIfcInfo ++; - } - - if(err != NO_ERROR) - { - goto Exit; - } - - status = TRUE; - -Exit: - if(!status) - { - ClearIfcList(pIfcList); - } - if(pIfcBuffer) - { - free(pIfcBuffer); - } - - return status; -} - -/* -* Routine: -* AddTcFlows -* Description: -* Add Tc Flow in pTcFlow to each interface in IfcList. -* Arguments: -* [in] IfcList - -* The interface list. -* [in] pTcFlow - -* The TC flow to add. -* Return: -* TRUE if successes. Otherwise return FALSE. -*/ -BOOL AddTcFlows( IN IFC_LIST IfcList, - IN PTC_GEN_FLOW pTcFlow) -{ - UINT i; - ULONG err; - BOOL status = FALSE; - PIFC_INFO pCurrentIfcInfo = IfcList.pIfcInfo; - - // For each interface in the list, add a TC flow - for(i = 0; i < IfcList.IfcCount; i++) - { - HANDLE hFlow; - - err = TcAddFlow(pCurrentIfcInfo->hIfc, - 0, 0, pTcFlow, &hFlow); - if(err != NO_ERROR) - { - DPRINT_ERR(WFA_ERR, "AddTcFlows, TcAddFlow Failed %d\n", err); - goto Exit; - } - - pCurrentIfcInfo->hFlow = hFlow; - pCurrentIfcInfo++; - } - - status = TRUE; - -Exit: - - return status; -} - -/* -* Routine: -* AddTcFilters -* Description: -* Add Tc Filter in pTcFilter to each interface in IfcList -* Arguments: -* [in] IfcList - -* The interface list. -* [in] pTcFilter - -* The filter to apply. -* Return: -* TRUE if successes. Otherwise return FALSE. -*/ -BOOL AddTcFilters( IN IFC_LIST IfcList, - IN PTC_GEN_FILTER pTcFilter) -{ - UINT i; - ULONG err; - BOOL status = FALSE; - PIFC_INFO pCurrentIfcInfo = IfcList.pIfcInfo; - // For each interface in the list, add TC filter on the corresponding TcFlow - for(i = 0; i < IfcList.IfcCount; i++) - { - HANDLE hFilter; - - err = TcAddFilter(pCurrentIfcInfo->hFlow, pTcFilter, &hFilter); - if(err != NO_ERROR) - { - DPRINT_ERR(WFA_ERR, "AddTcFilters, TcAddFilter Failed %d\n", err); - goto Exit; - } - - pCurrentIfcInfo->hFilter = hFilter; - pCurrentIfcInfo++; - } - - status = TRUE; - -Exit: - - return status; +// +// Function: ResolveAddress +// +// Description: +// This routine resolves the specified address and returns a list of addrinfo +// structure containing SOCKADDR structures representing the resolved addresses. +// Note that if 'addr' is non-NULL, then getaddrinfo will resolve it whether +// it is a string listeral address or a hostname. +// +struct addrinfo *ResolveAddress(char *addr, char *port, int af, int type, int proto) +{ + struct addrinfo hints, + *res = NULL; + int rc; + + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = ((addr) ? 0 : AI_PASSIVE); + hints.ai_family = af; + hints.ai_socktype = type; + hints.ai_protocol = proto; + + ////DPRINT_INFOL(WFA_OUT, "receiving port %s\n", port); + //zlog_info(zc, "receiving port %s\r\n", port); + rc = getaddrinfo(addr, port, &hints, &res); + if (rc != 0) + { + ////DPRINT_ERR(WFA_ERR, "Invalid address %s\n", addr); + //zlog_error(zc, "Invalid address %s\r\n", addr); + return NULL; + } + + return res; +} + + +// +// Routine: +// DeleteFlow +// Description: +// Deletes the flow and its member variables +// Arguments: +// [in] pFlow - +// ptr to the existing Flow struct. +// +//****************************************************************************** +BOOL DeleteFlow (IN PTC_GEN_FLOW *pFlow) +{ + if(pFlow == NULL || *pFlow == NULL) + { + return TRUE; + } + + free(*pFlow); + *pFlow = NULL; + + return TRUE; +} + +// +// Routine: +// CreateFlow +// Description: +// The function returns a tc flow in ppTcFlowObj on success +// Arguments: +// [in,out] ppTcFlowObj - +// double ptr to Flow struct in which the function returns the flow. +// [in] DSCPValue - +// dscp value for the flow +// [in] OnePValue - +// 802.1p value for the flow +// [in] ThrottleRate - +// throttle rate for the flow +// Return: +// TRUE if file creating is successful +// FALSE if creating file failed. +// +//****************************************************************************** +BOOL CreateFlow( IN OUT PTC_GEN_FLOW *_ppTcFlowObj, + IN USHORT DSCPValue, + IN USHORT OnePValue, + IN ULONG ThrottleRate) +{ + BOOL status = FALSE; + // + // Flow Parameters + // + ULONG TokenRate = QOS_NOT_SPECIFIED; + ULONG TokenBucketSize = QOS_NOT_SPECIFIED; + ULONG PeakBandwidth = QOS_NOT_SPECIFIED; + ULONG Latency = QOS_NOT_SPECIFIED; + ULONG DelayVariation = QOS_NOT_SPECIFIED; + SERVICETYPE ServiceType = SERVICETYPE_BESTEFFORT; + ULONG MaxSduSize = QOS_NOT_SPECIFIED; + ULONG MinimumPolicedSize = QOS_NOT_SPECIFIED; + + PVOID pCurrentObject; + PTC_GEN_FLOW _pTcFlowObj = NULL; + + int Length = 0; + + // + // Calculate the memory size required for the optional TC objects + // + Length += (OnePValue == NOT_SPECIFIED ? 0 : sizeof(QOS_TRAFFIC_CLASS)) + + (DSCPValue == NOT_SPECIFIED ? 0 : sizeof(QOS_DS_CLASS)); + + // + // Print the Flow parameters + // + if(ThrottleRate == QOS_NOT_SPECIFIED) + { + // DPRINT_INFO(WFA_OUT, "\tThrottleRate: *\n"); + // DPRINT_INFO(WFA_OUT, "\tServiceType: Best effort\n"); + } + else + { + ServiceType = SERVICETYPE_GUARANTEED; + } + + TokenRate = TokenBucketSize = ThrottleRate; + + // + // Allocate the flow descriptor + // + _pTcFlowObj = (PTC_GEN_FLOW)malloc(FIELD_OFFSET(TC_GEN_FLOW, TcObjects) + Length); + if (!_pTcFlowObj) + { + ////DPRINT_ERR(WFA_ERR, "Flow Allocation Failed\n"); + //zlog_error(zc, "Flow Allocation Failed\r\n"); + goto Exit; + } + + _pTcFlowObj->SendingFlowspec.TokenRate = TokenRate; + _pTcFlowObj->SendingFlowspec.TokenBucketSize = TokenBucketSize; + _pTcFlowObj->SendingFlowspec.PeakBandwidth = PeakBandwidth; + _pTcFlowObj->SendingFlowspec.Latency = Latency; + _pTcFlowObj->SendingFlowspec.DelayVariation = DelayVariation; + _pTcFlowObj->SendingFlowspec.ServiceType = ServiceType; + _pTcFlowObj->SendingFlowspec.MaxSduSize = MaxSduSize; + _pTcFlowObj->SendingFlowspec.MinimumPolicedSize = MinimumPolicedSize; + + memcpy(&(_pTcFlowObj->ReceivingFlowspec), &(_pTcFlowObj->SendingFlowspec), sizeof(_pTcFlowObj->ReceivingFlowspec)); + + _pTcFlowObj->TcObjectsLength = Length; + + // + // Add any requested objects + // + pCurrentObject = (PVOID)_pTcFlowObj->TcObjects; + + if(OnePValue != NOT_SPECIFIED) + { + QOS_TRAFFIC_CLASS *pTClassObject = (QOS_TRAFFIC_CLASS*)pCurrentObject; + pTClassObject->ObjectHdr.ObjectType = QOS_OBJECT_TRAFFIC_CLASS; + pTClassObject->ObjectHdr.ObjectLength = sizeof(QOS_TRAFFIC_CLASS); + pTClassObject->TrafficClass = OnePValue; //802.1p tag to be used + + pCurrentObject = (PVOID)(pTClassObject + 1); + } + + if(DSCPValue != NOT_SPECIFIED) + { + QOS_DS_CLASS *pDSClassObject = (QOS_DS_CLASS*)pCurrentObject; + pDSClassObject->ObjectHdr.ObjectType = QOS_OBJECT_DS_CLASS; + pDSClassObject->ObjectHdr.ObjectLength = sizeof(QOS_DS_CLASS); + ////pDSClassObject->DSField = (DSCPValue << 3); //Services Type + pDSClassObject->DSField = DSCPValue; + } + + DeleteFlow(_ppTcFlowObj); + *_ppTcFlowObj = _pTcFlowObj; + + status = TRUE; + +Exit: + if(!status) + { + ////DPRINT_INFO(WFA_OUT, "Flow Creation Failed\n"); + //zlog_info(zc, "Flow Creation Failed\n"); + DeleteFlow(&_pTcFlowObj); + } + else + { + ////DPRINT_INFO(WFA_OUT, "Flow Creation Succeeded\n"); + //zlog_info(zc, "Flow Creation Succeeded\r\n"); + } + + return status; +} + +//****************************************************************************** +// Routine: +// DeleteFilter +// +// Description: +// Deletes the filter and its member variables +// +//****************************************************************************** +BOOL DeleteFilter(PTC_GEN_FILTER *ppFilter) +{ + PTC_GEN_FILTER pFilter; + + if (ppFilter == NULL || *ppFilter == NULL) + { + return TRUE; + } + + pFilter = (*ppFilter); + + if (pFilter->Pattern) + { + free(pFilter->Pattern); + } + + if (pFilter->Mask) + { + free(pFilter->Mask); + } + + *ppFilter = NULL; + + return TRUE; +} + +// +// Routine: +// CreateFilter +// Description: +// The function returns a tc filter in ppFilter on success +// Arguments: +// [in, out] ppFilter - +// double ptr to Filter struct in which the function returns the filter +// [in] Address - +// destination address of the outgoing packets of interest. +// [in] Port - +// destination port of the outgoing packets of interest. +// [in] ProtocolId - +// protocol of the outgoing packets of interest. +// Return: +// TRUE if filter creating successes. +// FALSE if failed. +// +BOOL CreateFilter( IN OUT PTC_GEN_FILTER *ppFilter, + IN SOCKADDR_STORAGE Address, + IN USHORT Port, + IN UCHAR ProtocolId) +{ + BOOL status = FALSE; + USHORT AddressFamily = Address.ss_family; + PTC_GEN_FILTER pFilter = NULL; + PIP_PATTERN pPattern = NULL; + PIP_PATTERN pMask = NULL; + + if(AddressFamily != AF_INET) + { + ////DPRINT_INFO(WFA_OUT, "Address family is not AF_INET"); + //zlog_info(zc, "Address family is not AF_INET\r\n"); + goto Exit; + } + + // + // Allocate memory for the filter + // + pFilter = (PTC_GEN_FILTER)malloc(sizeof(TC_GEN_FILTER)); + if(!pFilter) + { + ////DPRINT_INFO(WFA_OUT, "Error, No memory for filter\n"); + //zlog_info(zc, "Error, No memory for filter\r\n"); + goto Exit; + } + ZeroMemory(pFilter, sizeof(TC_GEN_FILTER)); + + // + // Allocate memory for the pattern and mask + // + pPattern = (PIP_PATTERN)malloc(sizeof(IP_PATTERN)); + pMask = (PIP_PATTERN)malloc(sizeof(IP_PATTERN)); + + if(!pPattern || !pMask) + { + ////DPRINT_INFO(WFA_OUT, "pPattern or pMask is null"); + //zlog_info(zc, "pPattern or pMask is null\r\n"); + goto Exit; + } + + memset(pPattern, 0, sizeof(IP_PATTERN)); + + pPattern->DstAddr = ((SOCKADDR_IN *)&Address)->sin_addr.s_addr; + pPattern->tcDstPort = htons(Port); + pPattern->ProtocolId = ProtocolId; + + memset(pMask, (ULONG)-1, sizeof(IP_PATTERN)); + // + // Set the source address and port to wildcard + // 0 -> wildcard, 0xFF-> exact match + // + pMask->SrcAddr = 0; + pMask->tcSrcPort = 0; + + // + // If the user specified 0 for dest port, dest address or protocol + // set the appropriate mask as wildcard + // 0 -> wildcard, 0xFF-> exact match + // + + if(pPattern->tcDstPort == 0) + { + pMask->tcDstPort = 0; + } + + if(pPattern->ProtocolId == 0) + { + pMask->ProtocolId = 0; + } + + if(pPattern->DstAddr == 0) + { + pMask->DstAddr = 0; + } + + pFilter->AddressType = NDIS_PROTOCOL_ID_TCP_IP; + pFilter->PatternSize = sizeof(IP_PATTERN); + pFilter->Pattern = pPattern; + pFilter->Mask = pMask; + + // + // Delete any previous instances of the Filter + // + DeleteFilter(ppFilter); + *ppFilter = pFilter; + + status = TRUE; + +Exit: + if(!status) + { + ////DPRINT_INFO(WFA_OUT, "Filter Creation Failed\n"); + //zlog_info(zc, "Filter Creation Failed\r\n"); + DeleteFilter(&pFilter); + } + else + { + ////DPRINT_INFO(WFA_OUT, "Filter Creation Succeeded\n"); + //zlog_info(zc, "Filter Creation Succeeded\r\n"); + } + + return status; +} + +// +// Routine: +// ClNotifyHandler +// Description: +// Empty notification handler. +// The ClNotifyHandler function is used by traffic control to notify the client of various +// traffic control$(Dx7(Bspecific events, including the deletion of flows, changes in filter parameters, +// or the closing of an interface. +// Arguments: +// [in] ClRegCtx - +// Client registration context, provided to traffic control by the client with the client's call +// to the TcRegisterClient function. +// [in] ClIfcCtx - +// Client interface context, provided to traffic control by the client with the client's call to +// the TcOpenInterface function. Note that during a TC_NOTIFY_IFC_UP event, ClIfcCtx is not +// available and will be set to NULL. +// [in] Event - +// Describes the notification event. See the Remarks section for a list of notification events. +// [in] SubCode - +// Handle used to further qualify a notification event. +// [in] BufSize - +// Size of the buffer included with the notification event, in bytes. +// [in] Buffer - +// Buffer containing the detailed event information associated with Event and SubCode. +// Return: +// None +// +void ClNotifyHandler( IN HANDLE ClRegCtx, + IN HANDLE ClIfcCtx, + IN ULONG Event, + IN HANDLE SubCode, + IN ULONG BufSize, + IN PVOID Buffer) +{ + UNREFERENCED_PARAMETER(ClRegCtx); + UNREFERENCED_PARAMETER(ClIfcCtx); + // + // Notification was unexpected + // + ////DPRINT_INFO(WFA_OUT, "Unexpected notification: Event=%d, SubCode=%p, BufSize=%d, Buffer=%p", + //// (int)Event, (void *)SubCode, (int)BufSize, Buffer); + //zlog_info(zc, "Unexpected notification: Event=%d, SubCode=%p, BufSize=%d, Buffer=%p\r\n", (int)Event, (void *)SubCode, (int)BufSize, Buffer); +} + +// +// Routine: +// ClearIfcList +// Description: +// Clears the IfcList and its member variables +// Arguments: +// [in] pIfcList - +// The interface list. +// Return: +// TRUE if successes or FALSE if fails. +// +BOOL ClearIfcList( IN PIFC_LIST pIfcList) +{ + ULONG i; + + if(!pIfcList) + { + return TRUE; + } + + if(pIfcList->pIfcInfo) + { + // + // Delete filter, flow and interface + // + PIFC_INFO pCurrentIfcInfo = pIfcList->pIfcInfo; + + for(i = 0; i < pIfcList->IfcCount; i ++) + { + if(pCurrentIfcInfo->hFilter) + { + TcDeleteFilter(pCurrentIfcInfo->hFilter); + } + if(pCurrentIfcInfo->hFlow) + { + TcDeleteFlow(pCurrentIfcInfo->hFlow); + } + if(pCurrentIfcInfo->hIfc) + { + TcCloseInterface(pCurrentIfcInfo->hIfc); + } + + pCurrentIfcInfo++; + } + + free(pIfcList->pIfcInfo); + } + + ZeroMemory(pIfcList, sizeof(IFC_LIST)); + + return TRUE; +} + + +// +// Routine: +// MakeIfcList +// Description: +// The function enumerates all TC enabled interfaces. +// opens each TC enabled interface and stores each ifc handle in IFC_LIST struct +// pointed to by pIfcList. +// Arguments: +// [in] hClient - +// Handle returned by TcRegisterClient +// [in] pIfcList - +// ptr to IfcList structure which will be populated by the function +// Return: +// TRUE if successes or FALSE if fails. +// +BOOL +MakeIfcList( IN HANDLE hClient, + IN PIFC_LIST pIfcList) +{ + BOOL status = FALSE; + ULONG err = ERROR_INVALID_PARAMETER; + + ULONG BufferSize = 1, ActualBufferSize, RemainingBufferSize = 0; + PTC_IFC_DESCRIPTOR pIfcBuffer = NULL, pCurrentIfc; + PIFC_INFO pIfcInfo = NULL, pCurrentIfcInfo; + ULONG nIfcs = 0; + + // + // Enumerate the TC enabled interfaces + // + while(TRUE) + { + ActualBufferSize = BufferSize; + pIfcBuffer = (PTC_IFC_DESCRIPTOR)malloc(ActualBufferSize); + if(pIfcBuffer == NULL) + { + break; + } + + err = TcEnumerateInterfaces(hClient, &ActualBufferSize, pIfcBuffer); + if(err == ERROR_INSUFFICIENT_BUFFER) + { + free(pIfcBuffer); + BufferSize *= 2; + } + else + { + break; + } + } + + if(err != NO_ERROR) + { + goto Exit; + } + + // + // Count the number of interfaces + // + + pCurrentIfc = pIfcBuffer; + RemainingBufferSize = ActualBufferSize; + while(RemainingBufferSize) + { + nIfcs ++; + + RemainingBufferSize -= pCurrentIfc->Length; + pCurrentIfc = (PTC_IFC_DESCRIPTOR)(((PBYTE)pCurrentIfc) + pCurrentIfc->Length); + } + + if(nIfcs == 0) + { + goto Exit; + } + + // + // Allocate memory for the size(IFC_INFO) X nIfcs + // + pIfcInfo = (PIFC_INFO)malloc(sizeof(IFC_INFO) * nIfcs); + if(!pIfcInfo) + { + goto Exit; + } + + ZeroMemory(pIfcInfo, sizeof(IFC_INFO) * nIfcs); + + ClearIfcList(pIfcList); + pIfcList->IfcCount = nIfcs; + pIfcList->pIfcInfo = pIfcInfo; + + // + // Open Each interface and store the ifc handle in ifcList + // + pCurrentIfc = pIfcBuffer; + pCurrentIfcInfo = pIfcInfo; + + RemainingBufferSize = ActualBufferSize; + while(RemainingBufferSize) + { + HANDLE hIfc; + + err = TcOpenInterfaceW(pCurrentIfc->pInterfaceName, + hClient, + 0, + &hIfc); + + if(err != NO_ERROR) + { + ////DPRINT_ERR(WFA_ERR, "TcOpenInterface Failed %d\n", err); + //zlog_info(zc, "TcOpenInterface Failed %d\r\n", err); + break; + } + + pCurrentIfcInfo->hIfc = hIfc; + + RemainingBufferSize -= pCurrentIfc->Length; + pCurrentIfc = (PTC_IFC_DESCRIPTOR)(((PBYTE)pCurrentIfc) + pCurrentIfc->Length); + pCurrentIfcInfo ++; + } + + if(err != NO_ERROR) + { + goto Exit; + } + + status = TRUE; + +Exit: + if(!status) + { + ClearIfcList(pIfcList); + } + + // + // Cleanup the IfcBuffer + // + if(pIfcBuffer) + { + free(pIfcBuffer); + } + + return status; +} + +// +// Routine: +// AddTcFlows +// Description: +// Add Tc Flow in pTcFlow to each interface in IfcList. +// Arguments: +// [in] IfcList - +// The interface list. +// [in] pTcFlow - +// The TC flow to add. +// Return: +// TRUE if successes. Otherwise return FALSE. +// +BOOL AddTcFlows( IN IFC_LIST IfcList, + IN PTC_GEN_FLOW pTcFlow) +{ + UINT i; + ULONG err; + BOOL status = FALSE; + PIFC_INFO pCurrentIfcInfo = IfcList.pIfcInfo; + + // + // For each interface in the list, add a TC flow + // + for(i = 0; i < IfcList.IfcCount; i++) + { + HANDLE hFlow; + + err = TcAddFlow(pCurrentIfcInfo->hIfc, 0, 0, pTcFlow, &hFlow); + if(err != NO_ERROR) + { + ////DPRINT_ERR(WFA_ERR, "TcAddFlow Failed %d\n", err); + //zlog_error(zc, "TcAddFlow Failed %d\r\n", err); + goto Exit; + } + + pCurrentIfcInfo->hFlow = hFlow; + pCurrentIfcInfo++; + } + + status = TRUE; + +Exit: + return status; +} + +// +// Routine: +// AddTcFilters +// Description: +// Add Tc Filter in pTcFilter to each interface in IfcList +// Arguments: +// [in] IfcList - +// The interface list. +// [in] pTcFilter - +// The filter to apply. +// Return: +// TRUE if successes. Otherwise return FALSE. +// +BOOL AddTcFilters( IN IFC_LIST IfcList, + IN PTC_GEN_FILTER pTcFilter) +{ + UINT i; + ULONG err; + BOOL status = FALSE; + PIFC_INFO pCurrentIfcInfo = IfcList.pIfcInfo; + + // + // For each interface in the list, add TC filter on the corresponding TcFlow + // + for(i = 0; i < IfcList.IfcCount; i++) + { + HANDLE hFilter; + + err = TcAddFilter(pCurrentIfcInfo->hFlow, pTcFilter, &hFilter); + if(err != NO_ERROR) + { + ////DPRINT_ERR(WFA_ERR, "TcAddFilter Failed %d\n", err); + //zlog_error(zc, "TcAddFilter Failed %d\r\n", err); + goto Exit; + } + + pCurrentIfcInfo->hFilter = hFilter; + pCurrentIfcInfo++; + } + + status = TRUE; + +Exit: + return status; } -int CleanTos_Win7 (IN PIFC_LIST pIfcList,PTC_GEN_FILTER *ppFilter,IN PTC_GEN_FLOW *pFlow) -{ - ClearIfcList(pIfcList); - DeleteFilter(ppFilter); - DeleteFlow(pFlow); - return 0; -} - /* NOTE, to run this version of code, win_dut have to run under administrator mode * wfaTGSetPrio_Win7(): This depends on the network interface card. * So you might want to remap according to the driver @@ -724,14 +790,17 @@ int wfaTGSetPrio(int sockfd, int tgClass, int streamid) ret = wfaACClassToQos(tgClass, &qos, &(tosval), &threadPri); - if (pTGProfile->tgTC[0].Qos == qos) + if (pTGProfile->tgTC[0].pTcFilter != NULL && pTGProfile->tgTC[0].Qos == qos) + //if (pTGProfile->tgTC[0].Qos == qos) { DPRINT_INFOL(WFA_OUT,"wfaTGSetPrio, same QoS do nothing QoS=0x%x\n", qos); } else { - wfaCloseTrafficControlFlow(&(pTGProfile->tgTC[0])); - Sleep(50); + //wfaCloseTrafficControlFlow(&(pTGProfile->tgTC[0])); + //Sleep(50); + pTGProfile->tgTC[0].Qos = qos; + pTGProfile->tgTC[0].tosVal = tosval; ret = wfaOpenTrafficControlFlow(sockfd, tgClass, pTGProfile, &(pTGProfile->tgTC[0])); if (ret == WFA_SUCCESS) @@ -778,12 +847,14 @@ void wfaSentStatsResp(int sock, BYTE *buf) sendStatsResp->streamId = allStreams->id; memcpy(&sendStatsResp->cmdru.stats, &allStreams->stats, sizeof(tgStats_t)); - DPRINT_INFOL(WFA_OUT, "id=%i rxFrames=%i txFrames=%i rxPayLoadBytes=%i txPayloadBytes=%i lastPktSN=%i\n", allStreams->id, + /*DPRINT_INFOL(WFA_OUT, "id=%i rxFrames=%i txFrames=%i rxPayLoadBytes=%i txPayloadBytes=%i lastPktSN=%i\n", allStreams->id, allStreams->stats.rxFrames, allStreams->stats.txFrames, allStreams->stats.rxPayloadBytes, allStreams->stats.txPayloadBytes, - allStreams->lastPktSN); + allStreams->lastPktSN); */ + + DPRINT_INFOL(WFA_OUT, "id=%i rxFrames=%i txActFrames=%i txFrames=%i rxPayLoadBytes=%llu txPayloadBytes=%llu lastPktSN=%i\r\n", allStreams->id,allStreams->stats.rxFrames,allStreams->stats.txActFrames,allStreams->stats.txFrames,allStreams->stats.rxPayloadBytes,allStreams->stats.txPayloadBytes,allStreams->lastPktSN); sendStatsResp++; total++; @@ -1071,7 +1142,7 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) tgWMM_t *my_wmm = &wfaTGWMMData.wmm_thr[myId]; tgStream_t *myStream = NULL; int myStreamId; - int mySock, status, respLen =WFA_BUFF_4K ; + int mySock, status, respLen; tgProfile_t *myProfile; BYTE respBuf[WFA_BUFF_4K]; int resendcnt = 0; @@ -1079,7 +1150,9 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) int timer_dur; int iOptVal; int iOptLen = sizeof(int); - + int bufActualSize = 0; + ULONG iResult = 0L; + u_long iMode = 1; while(1) { @@ -1096,7 +1169,6 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) my_wmm->thr_flag = 0; DPRINT_INFOL(WFA_OUT, "wfa_wmm_thread::lock met %d ...\n",myId); - /* use the flag as a stream id to file the profile */ myStream = findStreamProfile(myStreamId); myProfile = &myStream->profile; @@ -1117,26 +1189,49 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) { case DIRECT_SEND: DPRINT_INFOL(WFA_OUT, "creating send socket with port %d ...\n",myProfile->sport); - mySock = wfaCreateUDPSock(myProfile->sipaddr, myProfile->sport); - if(mySock < 0) + if ((mySock = wfaCreateSock(myProfile->transProtoType, myProfile->sipaddr, myProfile->sport)) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't creat socket\n"); + continue; + } + + DPRINT_INFOL(WFA_OUT, "Current transProtoProfile is %i and connecting to %s and port %i\n", myProfile->transProtoType, myProfile->dipaddr, myProfile->dport); + + if (wfaConnectToPeer(myProfile->transProtoType, mySock, myProfile->dipaddr, myProfile->dport) == WFA_FAILURE) + { + DPRINT_INFOL(WFA_OUT, "can't connect to %s and port %i\n", myProfile->dipaddr, myProfile->dport); + continue; + } + + //if (myProfile->transProtoType == SOCK_TYPE_TCP) { - DPRINT_ERR(WFA_ERR, "can't creat socket\n"); - break; + iResult = ioctlsocket(mySock, FIONBIO, &iMode); + DPRINT_INFOL(WFA_OUT, "ioctlsocket result: %d\n", iResult); + if (iResult != NO_ERROR) + DPRINT_INFOL(WFA_OUT, "ioctlsocket failed with error: %ld\n", iResult); } - wfaConnectUDPPeer(mySock, myProfile->dipaddr, myProfile->dport); - /* * Set packet/socket priority TOS field */ DPRINT_INFOL(WFA_OUT, "To Set QoS Traffic Class=%i\n", myProfile->trafficClass); wfaTGSetPrio(mySock, myProfile->trafficClass,myStreamId); + //wfaTGSetPrio_Win7(mySock, myProfile->trafficClass, myProfile); /* if delay is too long, it must be something wrong */ if(myProfile->startdelay > 0 && myProfile->startdelay<100) { Sleep(1000 * myProfile->startdelay); } + //memset(respBuf, 0, WFA_BUFF_4K); // benz added + + /* + * set timer fire up + */ + DPRINT_INFOL(WFA_OUT, "Thread %d Setting timer for %d ms\n",myId,1000*myProfile->duration); + timer_dur = 1000*(myProfile->duration + 1); /* add one missing second */ + CreateThread(NULL, 0, wfa_wmm_sleep_thread, (PVOID)&timer_dur, 0, &thr_id); + if (getsockopt(mySock, SOL_SOCKET, SO_SNDBUF, (char*)&iOptVal, &iOptLen) != SOCKET_ERROR) { DPRINT_INFOL(WFA_OUT, "SO_SNDBUF Value: %ld\n", iOptVal); @@ -1145,7 +1240,7 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) { DPRINT_INFOL(WFA_OUT, "Error to get Default SO_RECVBUF= %ld \n", iOptVal); } - iOptVal = iOptVal*40; /* one mbyte buffer size */ + iOptVal = 128 * 1024;//iOptVal*40; /* one mbyte buffer size or 128 * 1024? */ if ( setsockopt(mySock, SOL_SOCKET, SO_SNDBUF, (char*)&iOptVal, iOptLen) != SOCKET_ERROR) { @@ -1158,18 +1253,11 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) if (getsockopt(mySock, SOL_SOCKET, SO_SNDBUF, (char*)&iOptVal, &iOptLen) != SOCKET_ERROR) { DPRINT_INFOL(WFA_OUT, "get resetted SO_SNDBUF Value: %ld\n", iOptVal); - } - memset(respBuf, 0, WFA_BUFF_4K); // benz added + } - /* - * set timer fire up - */ - DPRINT_INFOL(WFA_OUT, "\r\n Thread %d Setting timer for %d ms\n",myId,1000*myProfile->duration); - timer_dur = 1000*(myProfile->duration + 1); /* add one missing second */ - CreateThread(NULL, 0, wfa_wmm_sleep_thread, (PVOID)&timer_dur, 0, &thr_id); /* ----------detect some fixed bit rate cases on Sending ---------------- */ - if ( (myProfile->rate != 0 ) /* WFA_SEND_FIX_BITRATE_MAX_FRAME_RATE)*/ && + if ((myProfile->rate != 0 ) /* WFA_SEND_FIX_BITRATE_MAX_FRAME_RATE)*/ && (myProfile->pksize * myProfile->rate * 8 < WFA_SEND_FIX_BITRATE_MAX)) { wfaSendBitrateData(mySock, myStreamId, respBuf, &respLen); @@ -1178,7 +1266,10 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) { wfaSendLongFile(mySock, myStreamId, respBuf, &respLen); } - DPRINT_INFOL(WFA_OUT, "\r\n Closing socket for thread %d sockId=%i",myId, mySock); + + wfaCloseTrafficControlFlow(&(myProfile->tgTC[0])); + + DPRINT_INFOL(WFA_OUT, "Closing socket for thread %d sockId=%i\n",myId, mySock); closesocket(mySock); Sleep(1000); @@ -1187,9 +1278,8 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) */ if(myId == wfaTGWMMData.mainSendThread) { - wfaSentStatsResp(wfaDutAgentData.gxcSockfd, respBuf); - - Sleep(3000); + wfaSentStatsResp(wfaDutAgentData.gxcSockfd, respBuf); + Sleep(3000); DPRINT_INFOL(WFA_OUT, "finish resendsn %i", resendcnt); } @@ -1200,21 +1290,57 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) if(myProfile->profile == PROF_IPTV || myProfile->profile == PROF_FILE_TX || myProfile->profile == PROF_MCAST) { int nbytes = 0; - char recvBuf[MAX_RCV_BUF_LEN+1]; /* 32*1024 + 1 = 32K */ + char *recvBuf; int iOptVal;//, iOptLen; int iOptLen = sizeof(int); #ifdef WFA_VOICE_EXT struct timeval currtime; FILE *e2eoutp = NULL; - char e2eResults[124]; + char e2eResults[256]; int le2eCnt = 0; tgE2EStats_t *e2esp = NULL; int totalE2Cnt = 6000; #endif + if (myProfile->transProtoType == SOCK_TYPE_TCP) + { + if ((wfaTGWMMData.svrSock[myStream->tblidx] = wfaCreateTCPServSockImpl(myProfile->dipaddr, myProfile->dport)) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't create server socket to %s and port %i\r\n", myProfile->dipaddr, myProfile->dport); + continue; + } + } + else + { + if ((mySock = wfaCreateSock(myProfile->transProtoType, myProfile->sipaddr, myProfile->sport)) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't create socket at %s and port %i\r\n", myProfile->dipaddr, myProfile->dport); + continue; + } + } + + if (myProfile->transProtoType == SOCK_TYPE_TCP) + { + DPRINT_INFOL(WFA_OUT, "Before accepting connection\r\n"); + if ((mySock = wfaAcceptTCPConn(wfaTGWMMData.svrSock[myStream->tblidx])) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't accept the connection\r\n"); + closesocket(wfaTGWMMData.svrSock[myStream->tblidx]); + continue; + } + DPRINT_INFOL(WFA_OUT, "After accepting connection\r\n"); + } + else + { + if (wfaConnectToPeer(myProfile->transProtoType, mySock, myProfile->dipaddr, myProfile->dport) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't connect to %s and port %i\r\n", myProfile->dipaddr, myProfile->dport); + closesocket(mySock); + continue; + } + } - mySock = wfaCreateUDPSock(myProfile->sipaddr, myProfile->sport); - wfaTGWMMData.tgSockfds[myStream->tblidx] = mySock; + wfaTGWMMData.tgSockfds[myStream->tblidx] = mySock; #ifdef WFA_VOICE_EXT if(myProfile->profile == PROF_IPTV) @@ -1254,9 +1380,35 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) DPRINT_ERR(WFA_OUT, "after setting SO_RECVBUF, getsockopt failed with error %d\n", WSAGetLastError()); } - for (;;) + if (myProfile->pksize <= 0) + { + DPRINT_INFOL(WFA_OUT, "Receiver zero packet size detected\r\n"); + if(myProfile->rate == 0 && wfaDutAgentCAPIData.progSet == eDEF_VHT && myProfile->hti == WFA_OFF) + { + bufActualSize = MAX_ETH_PAYLOAD_LEN; + DPRINT_INFOL(WFA_OUT, "use default ethernet payload size\r\n"); + } + else + { + // the sender can send any size of packet, using the configurable receiving buffer size makes it able to + // adjust the receving buffer size + bufActualSize = MAX_UDP_LEN; + DPRINT_INFOL(WFA_OUT, "use maximum buffer size\r\n"); + } + recvBuf = (char*)malloc((bufActualSize + 1) * sizeof(char)); + } + else + { + recvBuf = (char*)malloc((myProfile->pksize + 1) * sizeof(char)); + bufActualSize = myProfile->pksize; + } + + DPRINT_INFOL(WFA_OUT, "The packet size in profile is %d\r\n", bufActualSize); + + for (;;) { - nbytes = wfaRecvFile(mySock, myStreamId, (char *)recvBuf); + memset(recvBuf, 0, bufActualSize + 1); + nbytes = wfaRecvFile(mySock, myStreamId, (char *)recvBuf, bufActualSize); if (nbytes==0) { DPRINT_ERR(WFA_OUT, "The connection has been gracefully closed, the return value is zero"); @@ -1270,6 +1422,8 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) } } /* for */ + free(recvBuf); + my_wmm->thr_flag = 0; #ifdef WFA_VOICE_EXT @@ -1305,13 +1459,42 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) int sendCount=0, rcvCount=0; DPRINT_INFOL(WFA_OUT, "RCV:PROF_TRANSC::Packet receiving and then send back\n"); - mySock = wfaCreateUDPSock(myProfile->sipaddr, myProfile->sport); - if(mySock < 0) - { - my_wmm->thr_flag = 0; - DPRINT_INFO(WFA_OUT, "PROF_TRANSC::Packet receiving and then send back; ERR on wfaCreateUDPSock \n"); - continue; - } + if (myProfile->transProtoType == SOCK_TYPE_TCP) + { + if ((mySock = wfaCreateTCPServSockImpl(myProfile->dipaddr, myProfile->dport)) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't create server socket to %s and port %i\r\n", myProfile->dipaddr, myProfile->dport); + continue; + } + } + else + { + if ((mySock = wfaCreateSock(myProfile->transProtoType, myProfile->sipaddr, myProfile->sport)) == WFA_FAILURE) + { + my_wmm->thr_flag = 0; + DPRINT_ERR(WFA_ERR, "PROF_TRANSC::Packet receiving and then send back; ERR on wfaCreateUDPSock \n"); + continue; + } + } + + if (myProfile->transProtoType == SOCK_TYPE_TCP) + { + if (wfaAcceptTCPConn(mySock) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't accept the connection\r\n"); + closesocket(mySock); + continue; + } + } + else + { + if (wfaConnectToPeer(myProfile->transProtoType, mySock, myProfile->dipaddr, myProfile->dport) == WFA_FAILURE) + { + DPRINT_ERR(WFA_ERR, "can't connect to %s and port %i\r\n", myProfile->dipaddr, myProfile->dport); + closesocket(mySock); + continue; + } + } wfaTGWMMData.tgSockfds[myStream->tblidx] = mySock; wfaTGWMMData.gtgTransac = myStreamId; @@ -1346,22 +1529,22 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) { int i = 0; - nbytes = wfaRecvFile(mySock, wfaTGWMMData.gtgTransac, (char *)recvBuf); + nbytes = wfaRecvFile(mySock, wfaTGWMMData.gtgTransac, (char *)recvBuf, sizeof(recvBuf)); if(nbytes <= 0) { Sleep(3); i++; - if ( i< 10) + if (i < 10) continue; else { - DPRINT_INFO(WFA_OUT, "RCV:PROF_TRANSC::ERR on wfaRecvFile, try 20 times failed\n"); + DPRINT_INFO(WFA_OUT, "RCV:PROF_TRANSC::ERR on wfaRecvFile, try 10 times failed\n"); break; } } else - { - sendCount++; + { + rcvCount++; } } else @@ -1379,7 +1562,7 @@ DWORD WINAPI wfa_wmm_thread(void *thr_param) } else { - rcvCount++; + sendCount++; } } /* while(gtgTransac != 0) */ DPRINT_INFOL(WFA_OUT, "wfa_wmm_thread::RCV;PROF_TRANSC::while loop done sendCount=%d rcvCount=%d\n",sendCount, rcvCount); diff --git a/win_lib/wfa_typestr.c b/win_lib/wfa_typestr.c index 982f043..b4a85b5 100644 --- a/win_lib/wfa_typestr.c +++ b/win_lib/wfa_typestr.c @@ -26,6 +26,8 @@ extern int xcCmdProcAgentSend(char *, BYTE *, int *); extern int xcCmdProcAgentRecvStart(char *, BYTE *, int *); extern int xcCmdProcAgentRecvStop(char *, BYTE *, int *); extern int xcCmdProcAgentReset(char *, BYTE *, int *); +extern int xcCmdProcAgentVersion(char *, BYTE *, int *); + extern int xcCmdProcStaGetIpConfig(char *, BYTE *, int *); extern int xcCmdProcStaSetIpConfig(char *, BYTE *, int *); extern int xcCmdProcStaGetMacAddress(char *pcmdStr, BYTE *, int *); @@ -136,6 +138,7 @@ typeNameStr_t nameStr[] = {WFA_STA_REASSOCIATE_TLV, "sta_reassoc", xcCmdProcStaReAssociate}, {WFA_STA_SET_PWRSAVE_TLV, "sta_set_pwrsave", xcCmdProcStaSetPwrSave}, {WFA_STA_SET_POWER_SAVE_TLV, "sta_set_power_save", xcCmdProcStaSetPowerSave}, /* legacy power save */ + {WFA_TRAFFIC_AGENT_VERSION_TLV, "traffic_agent_version", xcCmdProcAgentVersion}, {WFA_STA_CLI_CMD_TLV, "wfa_cli_cmd", xcCmdProcStaCliCommand}, #ifdef WFA_P2P @@ -153,6 +156,5 @@ typeNameStr_t nameStr[] = {WFA_STA_WPS_ENTER_PIN_TLV, "sta_wps_enter_pin", xcCmdProcStaWpsEnterPin}, {WFA_STA_GET_PSK_TLV, "sta_get_psk", xcCmdProcStaGetPsk}, #endif - {-1, "", NULL}, }; diff --git a/win_lib/wfa_wmm_tc.c b/win_lib/wfa_wmm_tc.c index 8bca8c3..ef08188 100644 --- a/win_lib/wfa_wmm_tc.c +++ b/win_lib/wfa_wmm_tc.c @@ -61,24 +61,46 @@ int wfaACClassToQos(int tgClass, int *pQos, int *pTosVal, int *pThreadPriority) { DPRINT_ERR(WFA_ERR, "wfaACClassToQos pass in err param or NULL pt tgClass=%d pQos=0x%x pTosVal=0x%x pThreadPriority=0x%x\n",tgClass, pQos, pTosVal, pThreadPriority); return WFA_FAILURE; - } + } + + switch(tgClass) { case TG_WMM_AC_BK: /*Change this value to the ported device*/ - Qos = 1; - DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS Background tag: 0x%x\n", TOS_BK); + Qos = 0x08; + //Qos = 1; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS BK/UP1 tag: 0x%x\n", TOS_BK); tosVal = TOS_BK; threadPriority = THREAD_PRIORITY_BELOW_NORMAL; break; + case TG_WMM_AC_BK2: + case TG_WMM_AC_UP2: + /*Change this value to the ported device*/ + Qos = 0x10; + //Qos = 2; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS BK/UP2 tag: 0x%x\n", TOS_LE); + tosVal = TOS_LE; + threadPriority = THREAD_PRIORITY_BELOW_NORMAL; + break; + case TG_WMM_AC_VI: - Qos = 4; - DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS Video tag: 0x%x\n",TOS_VI); + case TG_WMM_AC_UP5: + Qos = 0x28; + //Qos = 5; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS VI/UP5 tag: 0x%x\n",TOS_VI); tosVal = TOS_VI; threadPriority = THREAD_PRIORITY_ABOVE_NORMAL; break; + /*case TG_WMM_AC_UP5: + Qos = 0x28; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS UP5 tag: 0x%x\n",TOS_VI); + tosVal = TOS_VI; + threadPriority = THREAD_PRIORITY_ABOVE_NORMAL; + break;*/ + case TG_WMM_AC_UAPSD: tosVal = 0x88; threadPriority = THREAD_PRIORITY_BELOW_NORMAL; @@ -86,23 +108,76 @@ int wfaACClassToQos(int tgClass, int *pQos, int *pTosVal, int *pThreadPriority) case TG_WMM_AC_VO: /*Change this value to the ported device*/ - Qos = 6; - DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS Voice Tag: 0x%x\n",TOS_VO7 ); - tosVal=TOS_VO7; + Qos = 0x30; + //Qos = 6; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS VO/UP6 Tag: 0x%x\n",TOS_VO); + tosVal = TOS_VO; threadPriority = THREAD_PRIORITY_HIGHEST; break; + /*case TG_WMM_AC_UP7: + Qos = 0x38; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS UP7 Tag: 0x%x\n", TOS_VO7); + tosVal = TOS_VO7; + threadPriority = THREAD_PRIORITY_HIGHEST; + break;*/ + case TG_WMM_AC_BE: - Qos = 0; - DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS BE tag: 0x%x\n", TOS_BE); + Qos = 0x00; + //Qos = 0; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS BE/UP0 tag: 0x%x\n", TOS_BE); tosVal = TOS_BE; threadPriority = THREAD_PRIORITY_NORMAL; break; + /*case TG_WMM_AC_UP3: + Qos = 0x18; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS UP3 tag: 0x%x\n", TOS_BE); + tosVal = TOS_EE; + threadPriority = THREAD_PRIORITY_NORMAL; + break;*/ + + /*case TG_WMM_AC_BK2: + Qos = 0x10; + //Qos = 2; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS BE2 tag: 0x%x\n", TOS_LE); + tosVal = TOS_LE; + threadPriority = THREAD_PRIORITY_BELOW_NORMAL; + break;*/ + + case TG_WMM_AC_VI2: + /* Change this value to the ported device */ + Qos = 0x20; + //Qos = 4; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS VI/UP4 tag: 0x%x\n", TOS_VI4); + tosVal = TOS_VI4; + threadPriority = THREAD_PRIORITY_NORMAL; + break; + + case TG_WMM_AC_VO2: + case TG_WMM_AC_UP7: + Qos = 0x38; + //Qos = 7; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS VO/UP7 tag: 0x%x\n", TOS_VO7); + /*Change this value to the ported device*/ + tosVal = TOS_VO7; + threadPriority = THREAD_PRIORITY_ABOVE_NORMAL; + break; + + case TG_WMM_AC_BE2: + case TG_WMM_AC_UP3: + Qos = 0x18; + //Qos = 3; + DPRINT_INFOL(WFA_OUT, "wfaACClassToQos: Setting QoS BE/UP3 tag: 0x%x\n", TOS_EE); + tosVal = TOS_EE; + threadPriority = THREAD_PRIORITY_NORMAL; + break; + default: DPRINT_WARNING(WFA_WNG, "wfaACClassToQos: ERR Unknown AC class value 0x%x\n", tgClass); tosVal = TOS_BE; - Qos = 0; + Qos = 0x00; + //Qos = 0; threadPriority = threadPriority = THREAD_PRIORITY_BELOW_NORMAL; } *pQos = Qos; @@ -121,10 +196,17 @@ int wfaOpenTrafficControlFlow(SOCKET sockfd, int tgClass, tgProfile_t *pTGProfil int ret = WFA_SUCCESS; int Qos=0, tosVal=0, threadPriority=0; char *stport=NULL; + ULONG err; SOCKADDR_STORAGE Address = { 0 }; struct addrinfo *dest = NULL; + TCI_CLIENT_FUNC_LIST ClientHandlerList; + HANDLE hClient = TC_INVALID_HANDLE; + IFC_LIST IfcList = {0}; + PTC_GEN_FLOW pTcFlow = NULL; + PTC_GEN_FILTER pTcFilter = NULL; + if ( pTC == NULL) { DPRINT_ERR(WFA_ERR, "wfaOpenTrafficControlFlow, ERR pTC is NULL\n"); @@ -135,8 +217,10 @@ int wfaOpenTrafficControlFlow(SOCKET sockfd, int tgClass, tgProfile_t *pTGProfil DPRINT_ERR(WFA_ERR, "wfaOpenTrafficControlFlow, ERR pTGProfile is NULL\n"); return WFA_FAILURE; } - ret = wfaACClassToQos(tgClass, &(pTC->Qos), &(pTC->tosVal), &threadPriority); - if(!CreateFlow(&(pTC->pTcFlow), pTC->Qos, NOT_SPECIFIED, QOS_NOT_SPECIFIED)) + + ////ret = wfaACClassToQos(tgClass, &(pTC->Qos), &(pTC->tosVal), &threadPriority); + if(!CreateFlow(&pTcFlow, pTC->Qos, NOT_SPECIFIED, QOS_NOT_SPECIFIED)) + //if(!CreateFlow(&(pTC->pTcFlow), pTC->Qos, NOT_SPECIFIED, QOS_NOT_SPECIFIED)) { ret = WFA_FAILURE; DPRINT_ERR(WFA_ERR, "wfaOpenTrafficControlFlow:TC flow creation - FAILED\n"); @@ -149,7 +233,6 @@ int wfaOpenTrafficControlFlow(SOCKET sockfd, int tgClass, tgProfile_t *pTGProfil // Resolve the destination address dest = ResolveAddress( pTGProfile->dipaddr, stport, AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if(dest == NULL) { DPRINT_INFOL(WFA_OUT, "ERR wfaOpenTrafficControlFlow:ResolveAddress FAILED"); @@ -162,21 +245,25 @@ int wfaOpenTrafficControlFlow(SOCKET sockfd, int tgClass, tgProfile_t *pTGProfil DPRINT_INFOL(WFA_OUT, "wfaOpenTrafficControlFlow creating a filter start for QoS %i\n", (pTC->Qos)); // Create the TC Filter with the parameters - if (!CreateFilter(&(pTC->pTcFilter), Address, pTGProfile->dport, IPPROTO_UDP)) + if (!CreateFilter(&pTcFilter, Address, pTGProfile->dport, IPPROTO_UDP)) + //if (!CreateFilter(&(pTC->pTcFilter), Address, pTGProfile->dport, IPPROTO_UDP)) { ret = WFA_FAILURE; DPRINT_ERR(WFA_ERR, "wfaOpenTrafficControlFlow:CreateFilter - FAILED\n"); goto CLEANUP; } // Register TC client - memset(&(pTC->ClientHandlerList), 0, sizeof(pTC->ClientHandlerList)); - pTC->ClientHandlerList.ClNotifyHandler = (TCI_NOTIFY_HANDLER)ClNotifyHandler; - ret = TcRegisterClient(CURRENT_TCI_VERSION, 0, &(pTC->ClientHandlerList), &(pTC->hClient)); - if(ret != NO_ERROR) + //memset(&(pTC->ClientHandlerList), 0, sizeof(pTC->ClientHandlerList)); + //pTC->ClientHandlerList.ClNotifyHandler = (TCI_NOTIFY_HANDLER)ClNotifyHandler; + //ret = TcRegisterClient(CURRENT_TCI_VERSION, 0, &(pTC->ClientHandlerList), &(pTC->hClient)); + memset(&ClientHandlerList, 0, sizeof(ClientHandlerList)); + ClientHandlerList.ClNotifyHandler = (TCI_NOTIFY_HANDLER)ClNotifyHandler; + err = TcRegisterClient(CURRENT_TCI_VERSION, 0, &ClientHandlerList, &hClient); + if(err != NO_ERROR) { DPRINT_ERR(WFA_OUT, "wfaOpenTrafficControlFlow TcRegisterClient Failed %d\n", ret); - if(ret == ERROR_OPEN_FAILED) + if(err == ERROR_OPEN_FAILED) { DPRINT_ERR(WFA_OUT, "Please make sure you are running with admin credentials\n"); } @@ -184,45 +271,57 @@ int wfaOpenTrafficControlFlow(SOCKET sockfd, int tgClass, tgProfile_t *pTGProfil goto CLEANUP; } // Enumerate All TC enabled Interfaces and store the information in IfcList - if(!MakeIfcList(pTC->hClient, &(pTC->IfcList))) + //if(!MakeIfcList(pTC->hClient, &(pTC->IfcList))) + if(!MakeIfcList(hClient, &IfcList)) { DPRINT_ERR(WFA_ERR, "wfaOpenTrafficControlFlow::MakeIfcList falied, make sure QoS Packet Scheduler is active for this interface\n"); ret = WFA_FAILURE; goto CLEANUP; } // Add pTcFlow on all the Ifcs in the IfcList - if(!AddTcFlows(pTC->IfcList, pTC->pTcFlow)) + if(!AddTcFlows(IfcList, pTcFlow)) + //if(!AddTcFlows(pTC->IfcList, pTC->pTcFlow)) { DPRINT_ERR(WFA_ERR, "wfaOpenTrafficControlFlow::AddTcFlows FAILED\n"); ret = WFA_FAILURE; goto CLEANUP; } // Add pTcFilter to all the corresponding TcFlows on all the Ifcs in the IfcList - if (!AddTcFilters(pTC->IfcList, pTC->pTcFilter)) + if (!AddTcFilters(IfcList, pTcFilter)) + //if (!AddTcFilters(pTC->IfcList, pTC->pTcFilter)) { DPRINT_INFOL(WFA_OUT, "ERR wfaOpenTrafficControlFlow::AddTcFilters\n"); ret = WFA_FAILURE; goto CLEANUP; } - if(setsockopt ( sockfd, IPPROTO_IP, IP_TOS, (char *)&(pTC->tosVal), sizeof(pTC->tosVal)) < 0) - { - DPRINT_INFOL(WFA_OUT,"ERR wfaTGSetPrio, setsockopt failed to set tosVal=0x%x\n", pTC->tosVal); - goto CLEANUP; - } - else - { - DPRINT_INFOL(WFA_OUT,"wfaTGSetPrio call wfaOpenTrafficControlFlow +++, TOS set OK tosVal=0x%x sockFd=%d\n", pTC->tosVal, sockfd); - } + +//#ifndef QOS_SUPPORT +// if(setsockopt (sockfd, IPPROTO_IP, IP_TOS, (char *)&(pTC->tosVal), sizeof(pTC->tosVal)) < 0) +// { +// DPRINT_INFOL(WFA_OUT,"ERR wfaTGSetPrio, setsockopt failed to set tosVal=0x%x\n", pTC->tosVal); +// goto CLEANUP; +// } +// else +// { +// DPRINT_INFOL(WFA_OUT,"wfaTGSetPrio call wfaOpenTrafficControlFlow +++, TOS set OK tosVal=0x%x sockFd=%d\n", pTC->tosVal, sockfd); +// } +//#endif pTC->trafficClass = tgClass; CLEANUP: - if ( ret != WFA_SUCCESS ) + //if (ret != WFA_SUCCESS) { - wfaCloseTrafficControlFlow(pTC); + pTC->hClient = hClient; + //pTC->ClientHandlerList = ClientHandlerList; + pTC->IfcList = IfcList; + pTC->pTcFilter = pTcFilter; + pTC->pTcFlow = pTcFlow; + //wfaCloseTrafficControlFlow(pTC); } return ret; }/* wfaOpenTrafficControlFlow */ + int wfaCloseTrafficControlFlow(tgTC_t *pTC) { if ( pTC == NULL) @@ -236,14 +335,17 @@ int wfaCloseTrafficControlFlow(tgTC_t *pTC) DeleteFlow(&(pTC->pTcFlow)); TcDeregisterClient(pTC->hClient);// must call to unreg - memset(&(pTC->ClientHandlerList), 0, sizeof(pTC->ClientHandlerList)); + //memset(&(pTC->ClientHandlerList), 0, sizeof(pTC->ClientHandlerList)); - ZeroMemory(&(pTC->IfcList), sizeof(IFC_LIST)); + //ZeroMemory(&(pTC->IfcList), sizeof(IFC_LIST)); pTC->pTcFilter = NULL; pTC->pTcFlow = NULL; pTC->Qos = -1; pTC->tosVal = -1; pTC->trafficClass = 0; + //pTC->hClient = TC_INVALID_HANDLE; + //pTC->IfcList = {0}; + DPRINT_INFOL(WFA_OUT, " wfaCloseTrafficControlFlow::---\n"); return WFA_SUCCESS; }/* wfaCloseTrafficControlFlow */