Home | History | Annotate | Download | only in 4X
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
      5 **| All rights reserved.                                                  |**
      6 **|                                                                       |**
      7 **| Redistribution and use in source and binary forms, with or without    |**
      8 **| modification, are permitted provided that the following conditions    |**
      9 **| are met:                                                              |**
     10 **|                                                                       |**
     11 **|  * Redistributions of source code must retain the above copyright     |**
     12 **|    notice, this list of conditions and the following disclaimer.      |**
     13 **|  * Redistributions in binary form must reproduce the above copyright  |**
     14 **|    notice, this list of conditions and the following disclaimer in    |**
     15 **|    the documentation and/or other materials provided with the         |**
     16 **|    distribution.                                                      |**
     17 **|  * Neither the name Texas Instruments nor the names of its            |**
     18 **|    contributors may be used to endorse or promote products derived    |**
     19 **|    from this software without specific prior written permission.      |**
     20 **|                                                                       |**
     21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     32 **|                                                                       |**
     33 **+-----------------------------------------------------------------------+**
     34 ****************************************************************************/
     35 
     36 /***************************************************************************/
     37 /*                                                                         */
     38 /*   MODULE:	ackEmulDb.c                                                */
     39 /*   PURPOSE:	Ack emulation database                                     */
     40 /*                                                                         */
     41 /***************************************************************************/
     42 #include "osApi.h"
     43 #include "802_11Defs.h"
     44 #include "ackEmulDb.h"
     45 #include "report.h"
     46 #include "utils.h"
     47 
     48 
     49 static void wdrv_aeFindFreeActiveIndex(ackEmulDB_t*	ackEmulDB,UINT8 *freeIndex);
     50 
     51 static void wdrv_aeWTargetDbInit(ackEmulDB_t*	ackEmulDB);
     52 static void wdrv_aeWSourceDbInit(ackEmulDB_t*	ackEmulDB);
     53 static void wdrv_aeWSourceDbResetstation(ackEmulDB_t*	ackEmulDB,int stationIndex);
     54 
     55 /*
     56 ULONG rt_osTimerGetTick(void)
     57 {
     58 	ULONG sysuptime;
     59 
     60 #if (TIWLN_MAJOR_VERSION >= 5)
     61 	NdisGetSystemUpTime(&sysuptime);
     62 #else
     63 	LARGE_INTEGER systime;
     64 
     65 	NdisGetCurrentSystemTime(&systime);
     66 	sysuptime = (((UINT32)systime.LowPart >> 10) | ((UINT32)systime.HighPart << 22))/10;
     67 #endif
     68 
     69 	return sysuptime;
     70 }
     71 
     72 */
     73 ackEmulDB_t* ackEmulDb_create(TI_HANDLE hOs)
     74 {
     75 	ackEmulDB_t*	ackEmulDB;
     76 
     77 	if( hOs  == NULL )
     78 	{
     79 	    WLAN_OS_REPORT(("FATAL ERROR: ackEmulDb_create(): OS handle Error - Aborting\n"));
     80 		return NULL;
     81 	}
     82 
     83 	/* alocate concatenator block */
     84 	ackEmulDB = os_memoryAlloc(hOs, (sizeof(ackEmulDB_t)));
     85 
     86 	if ( (!ackEmulDB) )
     87 	{
     88 		utils_nullMemoryFree(hOs, ackEmulDB, sizeof(ackEmulDB_t));
     89 	    WLAN_OS_REPORT(("FATAL ERROR: ackEmulDb_create(): Error Creating ackEmulDB module- Aborting\n"));
     90 		return(NULL);
     91 	}
     92 
     93 	/* reset control module control block */
     94 	os_memoryZero(hOs, ackEmulDB, (sizeof(ackEmulDB_t)));
     95 
     96 	ackEmulDB->hOs = hOs;
     97 
     98 	return(ackEmulDB);
     99 
    100 
    101 }
    102 
    103 TI_STATUS ackEmulDb_config(ackEmulDB_t*	ackEmulDB,
    104 						   TI_HANDLE	hOs,
    105 						   TI_HANDLE	hReport)
    106 {
    107 	/* check parameters validity */
    108 	if( (ackEmulDB == NULL) || (hOs == NULL) || (hReport == NULL) )
    109 	{
    110 	    WLAN_OS_REPORT(("FATAL ERROR: ackEmulDb_config(): Parameters Error - Aborting\n"));
    111 		return NOK;
    112 	}
    113 
    114 	/* set objects handles */
    115 	ackEmulDB->hOs = hOs;
    116 	ackEmulDB->hReport = hReport;
    117 
    118 	wdrv_aeDbInit(ackEmulDB);
    119 
    120 	WLAN_REPORT_INIT(ackEmulDB->hReport, ACK_EMUL_MODULE_LOG,
    121 		(".....ackEmulDB configured successfully\n"));
    122 
    123 	return OK;
    124 
    125 }
    126 
    127 TI_STATUS ackEmulDb_destroy(ackEmulDB_t*	ackEmulDB)
    128 {
    129 	/* free control module controll block */
    130 	os_memoryFree(ackEmulDB->hOs, ackEmulDB, sizeof(ackEmulDB_t));
    131 
    132 	return OK;
    133 
    134 
    135 }
    136 
    137 /****************************************************************************
    138  *                      wdrv_aeDbInit()
    139  ****************************************************************************
    140  * DESCRIPTION:	Initialize the WTarget and WSource database
    141  *
    142  * INPUTS:	None
    143  *
    144  * OUTPUT:	None
    145  *
    146  * RETURNS:	None
    147  ****************************************************************************/
    148 
    149 void wdrv_aeDbInit(ackEmulDB_t*	ackEmulDB)
    150 {
    151    wdrv_aeWTargetDbInit(ackEmulDB);
    152    wdrv_aeWSourceDbInit(ackEmulDB);
    153 }
    154 
    155 
    156 /****************************************************************************
    157  *                      wdrv_aeWTargetDbInit()
    158  ****************************************************************************
    159  * DESCRIPTION:	Initialize the WTarget database
    160  *
    161  * INPUTS:	None
    162  *
    163  * OUTPUT:	None
    164  *
    165  * RETURNS:	None
    166  ****************************************************************************/
    167 
    168 static void wdrv_aeWTargetDbInit(ackEmulDB_t*	ackEmulDB)
    169 {
    170 	int index;
    171 	for(index=0 ; index< MAX_ACIVE_SESSION+MAX_STANDBY_SESSION; index++)
    172 		wdrv_aeWTargetDbResetTuple(ackEmulDB,index);
    173 	for(index=0 ; index< MAX_ACIVE_SESSION; index++)
    174 	{
    175 		ackEmulDB->activeIndexTable[index].status = INDEX_FREE;
    176 		ackEmulDB->activeIndexTable[index].monitorIndex = 0xff;
    177 	}
    178 	ackEmulDB->sessionsTableManager.currentActiveState =0;
    179 	ackEmulDB->sessionsTableManager.currentStandbyState =0;
    180 }
    181 
    182 /****************************************************************************
    183  *                      wdrv_aeWTargetDbAddSession()
    184  ****************************************************************************
    185  * DESCRIPTION:	ADD new session to WTarget database
    186  *
    187  * INPUTS:	pktBuf - Pointer to packet IP header
    188  *          stationIndex - The station index of the packet source
    189  *
    190  * OUTPUT:	None
    191  *
    192  * RETURNS:	Session index if added, otherwise 0xff
    193  ****************************************************************************/
    194 
    195 
    196 int wdrv_aeWTargetDbAddSession(ackEmulDB_t*	ackEmulDB,UINT8 *pktBuf)
    197 {
    198    int index;
    199    int freeIndex = 0xff;
    200    UINT32 currentTimeTick;
    201    UINT32 oldestTimeTick;
    202    UINT8  oldestTimeIndex;
    203 
    204    /* find free index */
    205    for(index=0 ; index< MAX_ACIVE_SESSION+MAX_STANDBY_SESSION; index++)
    206    {
    207       if(ackEmulDB->wdrv_aeWTargetTable[index].sPorts	== 0)
    208       {
    209          freeIndex = index;
    210          break;
    211       }
    212    }
    213    if (freeIndex == 0xff)
    214    {
    215       /* find old session to delete */
    216       currentTimeTick = oldestTimeTick = os_timeStampUs(ackEmulDB->hOs);
    217       oldestTimeIndex = 0xff;
    218       for(index=0 ; index< MAX_ACIVE_SESSION+MAX_STANDBY_SESSION; index++)
    219       {
    220          if(ackEmulDB->wdrv_aeWTargetTable[index].timeStamp	< oldestTimeTick)
    221          {
    222             oldestTimeTick = ackEmulDB->wdrv_aeWTargetTable[index].timeStamp;
    223             oldestTimeIndex = index;
    224          }
    225       }
    226 
    227       if((WTARGET_TERMINATE_TIME_OUT) < (currentTimeTick - oldestTimeTick))
    228       {
    229          wdrv_aeWTargetDbResetTuple(ackEmulDB, oldestTimeIndex);
    230          freeIndex = oldestTimeIndex;
    231       }
    232 
    233    }
    234 
    235    if (freeIndex != 0xff)
    236    {
    237       /* Add new session */
    238 
    239       int ipHeaderLen = ((*(unsigned char*)pktBuf  & 0x0f) * 4);
    240       ackEmulDB->wdrv_aeWTargetTable[freeIndex].sPorts = wlan_ntohs(*(UINT16*)(pktBuf +ipHeaderLen));
    241       ackEmulDB->wdrv_aeWTargetTable[freeIndex].dPorts = wlan_ntohs(*(UINT16*)(pktBuf +ipHeaderLen+DEST_PORT_FIELD));
    242       ackEmulDB->wdrv_aeWTargetTable[freeIndex].srcIPAddr = wlan_ntohl(*(unsigned long*)(pktBuf+IP_SRC_ADDRESS_FIELD));
    243       ackEmulDB->wdrv_aeWTargetTable[freeIndex].destIPAddr = wlan_ntohl(*(unsigned long*)(pktBuf+IP_DEST_ADDRESS_FIELD));
    244       ackEmulDB->wdrv_aeWTargetTable[freeIndex].segmentSize				=0;
    245       ackEmulDB->wdrv_aeWTargetTable[freeIndex].sequenceNumber = wlan_ntohl(*(unsigned long*)(pktBuf+ipHeaderLen+TCP_SEQUENCE_NUMBER_FIELD));
    246       ackEmulDB->wdrv_aeWTargetTable[freeIndex].ackNumber					=0;
    247       ackEmulDB->wdrv_aeWTargetTable[freeIndex].timeStamp					=os_timeStampUs(ackEmulDB->hOs);
    248       ackEmulDB->wdrv_aeWTargetTable[freeIndex].ackCounter				   =0;
    249       ackEmulDB->wdrv_aeWTargetTable[freeIndex].ackTemplate.ipHeaderLen			=0;
    250       ackEmulDB->wdrv_aeWTargetTable[freeIndex].ackTemplate.tcpHeaderLen			=0;
    251       ackEmulDB->wdrv_aeWTargetTable[freeIndex].monitorState				= AE_STANDBY;
    252       ackEmulDB->wdrv_aeWTargetTable[freeIndex].equalSegmentSizeCounter	=0;
    253       ackEmulDB->wdrv_aeWTargetTable[freeIndex].yTagFlag					=FALSE;
    254 		ackEmulDB->wdrv_aeWTargetTable[freeIndex].activeIndex				= 0xff;
    255         ackEmulDB->sessionsTableManager.currentStandbyState ++;
    256    }
    257    return freeIndex;
    258 }
    259 
    260 
    261 /****************************************************************************
    262  *                      wdrv_aeWTargetDbFindDataSession()
    263  ****************************************************************************
    264  * DESCRIPTION:	Find existing session index for data packet at
    265  *                WTarget database.
    266  *
    267  * INPUTS:	pktBuf - Pointer to packet IP header
    268  *          stationIndex - The station index of the packet source
    269  *
    270  * OUTPUT:	monitorState - The monitor state
    271  *
    272  * RETURNS:	Ok if exist  otherwise  NOK
    273  ****************************************************************************/
    274 
    275 
    276 int wdrv_aeWTargetDbFindDataSession(ackEmulDB_t*	ackEmulDB, UINT8 *pktBuf,UINT8 *sessionIndex, UINT8 *monitorState)
    277 {
    278    int index;
    279    int ipHeaderLen;
    280 
    281    ipHeaderLen = ((*(unsigned char*)pktBuf  & 0x0f) * 4);
    282    *monitorState = AE_INACTIVE;
    283 
    284 	for(index=0 ; index< MAX_ACIVE_SESSION+MAX_STANDBY_SESSION; index++)
    285 	{
    286 		if (ackEmulDB->wdrv_aeWTargetTable[index].sPorts		== wlan_ntohs(*(UINT16*)(pktBuf +ipHeaderLen)) &&
    287           ackEmulDB->wdrv_aeWTargetTable[index].dPorts		== wlan_ntohs(*(UINT16*)(pktBuf +ipHeaderLen + DEST_PORT_FIELD)) &&
    288 	        ackEmulDB->wdrv_aeWTargetTable[index].srcIPAddr	== wlan_ntohl(*(unsigned long*)(pktBuf+IP_SRC_ADDRESS_FIELD)) &&
    289 	        ackEmulDB->wdrv_aeWTargetTable[index].destIPAddr	== wlan_ntohl(*(unsigned long*)(pktBuf+IP_DEST_ADDRESS_FIELD)))
    290 		{
    291 			*sessionIndex = index;
    292          *monitorState = ackEmulDB->wdrv_aeWTargetTable[index].monitorState;
    293 
    294          return OK;
    295       }
    296    }
    297    return NOK;
    298 
    299 }
    300 
    301 /****************************************************************************
    302  *                      wdrv_aeWTargetDbFindDataSession()
    303  ****************************************************************************
    304  * DESCRIPTION:	Find existing session index for Ack packet at
    305  *                WTarget database.
    306  *
    307  * INPUTS:	pktBuf - Pointer to packet IP header
    308  *          stationIndex - The station index of the packet source
    309  *
    310  * OUTPUT:	monitorState - The monitor state
    311  *
    312  * RETURNS:		Ok if exist  otherwise  NOK
    313  ****************************************************************************/
    314 int wdrv_aeWTargetDbFindAckSession(ackEmulDB_t*	ackEmulDB, UINT8 *pktBuf,UINT8 *sessionIndex, UINT8 *monitorState)
    315 {
    316    int index;
    317    int ipHeaderLen;
    318 
    319    ipHeaderLen = ((*(unsigned char*)pktBuf  & 0x0f) * 4);
    320    *monitorState = AE_INACTIVE;
    321 
    322 	for(index=0 ; index< MAX_ACIVE_SESSION+MAX_STANDBY_SESSION; index++)
    323 	{
    324 
    325       if (ackEmulDB->wdrv_aeWTargetTable[index].sPorts		== wlan_ntohs(*(UINT16*)(pktBuf +ipHeaderLen + DEST_PORT_FIELD)) &&
    326           ackEmulDB->wdrv_aeWTargetTable[index].dPorts		== wlan_ntohs(*(UINT16*)(pktBuf +ipHeaderLen )) &&
    327 	        ackEmulDB->wdrv_aeWTargetTable[index].srcIPAddr	== wlan_ntohl(*(unsigned long*)(pktBuf+IP_DEST_ADDRESS_FIELD)) &&
    328 	        ackEmulDB->wdrv_aeWTargetTable[index].destIPAddr	== wlan_ntohl(*(unsigned long*)(pktBuf+IP_SRC_ADDRESS_FIELD)))
    329 		{
    330 			*sessionIndex = index;
    331          *monitorState = ackEmulDB->wdrv_aeWTargetTable[index].monitorState;
    332 
    333          return OK;
    334       }
    335    }
    336    return NOK;
    337 
    338 }
    339 
    340 
    341 /****************************************************************************
    342  *                      wdrv_aeWTargetDbResetTuple()
    343  ****************************************************************************
    344  * DESCRIPTION:	reset tuple at WTarget database
    345  *
    346  * INPUTS:	index - the tuple index
    347  *
    348  * OUTPUT:	None
    349  *
    350  * RETURNS:	None
    351  ****************************************************************************/
    352 
    353 void wdrv_aeWTargetDbResetTuple(ackEmulDB_t*	ackEmulDB, int index)
    354 {
    355    UINT8 freeActiveIndex = ackEmulDB->wdrv_aeWTargetTable[index].activeIndex;
    356 	if (ackEmulDB->wdrv_aeWTargetTable[index].monitorState == AE_ACTIVE)
    357 	{
    358 		ackEmulDB->sessionsTableManager.currentActiveState --;
    359 	}
    360 	else
    361 	{
    362 		ackEmulDB->sessionsTableManager.currentStandbyState --;
    363 	}
    364 
    365    ackEmulDB->wdrv_aeWTargetTable[index].sPorts						=0;
    366    ackEmulDB->wdrv_aeWTargetTable[index].dPorts						=0;
    367    ackEmulDB->wdrv_aeWTargetTable[index].srcIPAddr					=0;
    368    ackEmulDB->wdrv_aeWTargetTable[index].destIPAddr				=0;
    369    ackEmulDB->wdrv_aeWTargetTable[index].segmentSize				=0;
    370    ackEmulDB->wdrv_aeWTargetTable[index].sequenceNumber			=0;
    371    ackEmulDB->wdrv_aeWTargetTable[index].ackNumber					=0;
    372    ackEmulDB->wdrv_aeWTargetTable[index].timeStamp					=0;
    373    ackEmulDB->wdrv_aeWTargetTable[index].ackCounter				=0;
    374    ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.ipHeaderLen			=0;
    375    ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.tcpHeaderLen			=0;
    376    ackEmulDB->wdrv_aeWTargetTable[index].monitorState				=AE_INACTIVE;
    377    ackEmulDB->wdrv_aeWTargetTable[index].equalSegmentSizeCounter	=0;
    378    ackEmulDB->wdrv_aeWTargetTable[index].yTagFlag					=FALSE;
    379 	ackEmulDB->wdrv_aeWTargetTable[index].activeIndex		= 0xff;
    380    if(freeActiveIndex != 0xff)
    381 
    382    {
    383       ackEmulDB->activeIndexTable[freeActiveIndex].status = INDEX_FREE;
    384       ackEmulDB->activeIndexTable[freeActiveIndex].monitorIndex = 0xff;
    385 
    386 
    387    }
    388 }
    389 
    390 
    391 /****************************************************************************
    392  *                      wdrv_aeWTargetDbPrint()
    393  ****************************************************************************
    394  * DESCRIPTION:	Print the WTarget database
    395  *
    396  * INPUTS:	None
    397  *
    398  * OUTPUT:	None
    399  *
    400  * RETURNS:	None
    401  ****************************************************************************/
    402 void wdrv_aeWTargetDbPrint(ackEmulDB_t*	ackEmulDB)
    403 {
    404 	int index;
    405    unsigned char* sipByte;
    406 	 unsigned char* 	dipByte;
    407 
    408    WLAN_OS_REPORT(("\n current Active State = %d\n", ackEmulDB->sessionsTableManager.currentActiveState));
    409    WLAN_OS_REPORT((" current Standby State = %d\n", ackEmulDB->sessionsTableManager.currentStandbyState));
    410    WLAN_OS_REPORT((" --------------------------\n"));
    411 
    412    WLAN_OS_REPORT(("|  |   SOURCE IP   |   DEST  IP    |SPORT|DPORT|St|Seg Size |AI|AC\n"));
    413    WLAN_OS_REPORT(("|------------------------------------------------------------------------| \n"));
    414    for(index=0 ; index< MAX_ACIVE_SESSION+MAX_STANDBY_SESSION; index++)
    415    {
    416 	   sipByte = (unsigned char*) &ackEmulDB->wdrv_aeWTargetTable[index].srcIPAddr;
    417 	   dipByte = (unsigned char*) &ackEmulDB->wdrv_aeWTargetTable[index].destIPAddr;
    418 
    419 	   WLAN_OS_REPORT(("|%02.2u|%03.3u.%03.3u.%03.3u.%03.3u|%03.3u.%03.3u.%03.3u.%03.3u|%05u|%05u|%02x|%09lu|%02x|%x|\n",
    420 		   index,
    421 		   sipByte[3],sipByte[2],sipByte[1],sipByte[0],
    422 		   dipByte[3],dipByte[2],dipByte[1],dipByte[0],
    423 		   ackEmulDB->wdrv_aeWTargetTable[index].sPorts,
    424 		   ackEmulDB->wdrv_aeWTargetTable[index].dPorts,
    425 		   (UINT8)ackEmulDB->wdrv_aeWTargetTable[index].monitorState,
    426 		   ackEmulDB->wdrv_aeWTargetTable[index].segmentSize,
    427          (UINT8)ackEmulDB->wdrv_aeWTargetTable[index].activeIndex,
    428          (UINT8)ackEmulDB->wdrv_aeWTargetTable[index].ackCounter));
    429 
    430    }
    431 }
    432 
    433 
    434 
    435 /****************************************************************************
    436  *                      wdrv_aeWTargetDbSetSessionSequenceNumber()
    437  ****************************************************************************
    438  * DESCRIPTION:	Set the Sequence Number fild at WTarget data base
    439  *
    440  * INPUTS:	index          - session index
    441  *          sequenceNumber - Tcp sequence number
    442  *
    443  * OUTPUT:	None
    444  *
    445  * RETURNS:	None
    446  ****************************************************************************/
    447 
    448 void wdrv_aeWTargetDbSetSessionSequenceNumber(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 sequenceNumber)
    449 {
    450    ackEmulDB->wdrv_aeWTargetTable[index].sequenceNumber = sequenceNumber;
    451 }
    452 
    453 /****************************************************************************
    454  *                      wdrv_aeWTargetDbGetSessionSequenceNumber()
    455  ****************************************************************************
    456  * DESCRIPTION:	Get the Sequence Number fild from WTarget data base
    457  *
    458  * INPUTS:	index          - session index
    459  *
    460  * OUTPUT:	*sequenceNumber - Tcp sequence number
    461  *
    462  * RETURNS:	None
    463  ****************************************************************************/
    464 void wdrv_aeWTargetDbGetSessionSequenceNumber(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 *sequenceNumber)
    465 {
    466       *sequenceNumber = ackEmulDB->wdrv_aeWTargetTable[index].sequenceNumber;
    467 
    468 }
    469 
    470 
    471 /****************************************************************************
    472  *                      wdrv_aeWTargetDbSetSessionSegmentSize()
    473  ****************************************************************************
    474  * DESCRIPTION:	Set the Segmen tSize fild at WTarget data base
    475  *
    476  * INPUTS:	index          - session index
    477  *          segmentSize - Tcp segment size
    478  *
    479  * OUTPUT:	None
    480  *
    481  * RETURNS:	None
    482  ****************************************************************************/
    483 void wdrv_aeWTargetDbSetSessionSegmentSize(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 segmentSize)
    484 {
    485    ackEmulDB->wdrv_aeWTargetTable[index].segmentSize = segmentSize;
    486 
    487 }
    488 
    489 /****************************************************************************
    490  *                      wdrv_aeWTargetDbGetSessionSegmentSize()
    491  ****************************************************************************
    492  * DESCRIPTION:	Get the SegmentSize fild from WTarget data base
    493  *
    494  * INPUTS:	index          - session index
    495  *
    496  * OUTPUT:	*segmentSize - Tcp sequence number
    497  *
    498  * RETURNS:	None
    499  ****************************************************************************/
    500 void wdrv_aeWTargetDbGetSessionSegmentSize(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 *segmentSize)
    501 {
    502       *segmentSize = ackEmulDB->wdrv_aeWTargetTable[index].segmentSize;
    503 
    504 }
    505 /****************************************************************************
    506  *               wdrv_aeWTargetDbSetSessionEqualSegmentSizeCounter()
    507  ****************************************************************************
    508  * DESCRIPTION:	Set the number of sequential packet
    509  *                with the same Segment Size.
    510  * INPUTS:	index                    - session index
    511  *          equalSegmentSizeCounter - the number of sequential packet
    512  *                                    with the same Segment Size
    513  *
    514  * OUTPUT:	None
    515  *
    516  * RETURNS:	None
    517  ****************************************************************************/
    518 void wdrv_aeWTargetDbSetSessionEqualSegmentSizeCounter(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT8 equalSegmentSizeCounter)
    519 {
    520 	ackEmulDB->wdrv_aeWTargetTable[index].equalSegmentSizeCounter = equalSegmentSizeCounter;
    521 }
    522 
    523 /****************************************************************************
    524  *              wdrv_aeWTargetDbGetIncrSessionEqualSegmentSizeCounter()
    525  ****************************************************************************
    526  * DESCRIPTION:	Increase and return  the number of sequential packet
    527  *                with the same Segment Size.
    528  *
    529  * INPUTS:	index          - session index
    530  *
    531  * OUTPUT:	*equalSegmentSizeCounter - the number of sequential packet
    532  *          with the same Segment Size
    533  *
    534  * RETURNS:	None
    535  ****************************************************************************/
    536 void wdrv_aeWTargetDbGetIncrSessionEqualSegmentSizeCounter(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT8 *equalSegmentSizeCounter)
    537 {
    538 	*equalSegmentSizeCounter = (ackEmulDB->wdrv_aeWTargetTable[index].equalSegmentSizeCounter ++);
    539 }
    540 
    541 
    542 /****************************************************************************
    543  *                   wdrv_aeWTargetDbSetActiveState()
    544  ****************************************************************************
    545  * DESCRIPTION:	Find free active index and update the WTarget DB with
    546  *                this index
    547  *
    548  * INPUTS:	index          - monitor session index
    549  *
    550  * OUTPUT:	*activeIndex - the active index
    551  *
    552  * RETURNS:	Ok if change state to active, otherwise NOK
    553  ****************************************************************************/
    554 int wdrv_aeWTargetDbSetActiveState(ackEmulDB_t*	ackEmulDB, UINT8 index , UINT8 *activeIndex)
    555 {
    556    UINT8 monitorState = AE_ACTIVE ;
    557    UINT8 freeIndex ,aIndex;
    558 
    559    wdrv_aeFindFreeActiveIndex(ackEmulDB, &freeIndex);
    560 
    561    if(freeIndex == 0xff)
    562    {
    563       /* We don't have free active index we try find old active session to delete */
    564       UINT32 currentTimeTick;
    565       UINT32 oldestTimeTick;
    566       UINT8  oldestTimeIndex;
    567       currentTimeTick = oldestTimeTick = os_timeStampUs(ackEmulDB->hOs);
    568       oldestTimeIndex = 0xff;
    569       for(aIndex=0 ; aIndex< MAX_ACIVE_SESSION; aIndex++)
    570       {
    571          if(ackEmulDB->wdrv_aeWTargetTable[ackEmulDB->activeIndexTable[aIndex].monitorIndex].timeStamp	<
    572             oldestTimeTick)
    573          {
    574             oldestTimeTick = ackEmulDB->wdrv_aeWTargetTable[ackEmulDB->activeIndexTable[aIndex].monitorIndex].timeStamp;
    575             oldestTimeIndex = aIndex;
    576          }
    577       }
    578 
    579       if((WTARGET_TERMINATE_TIME_OUT) < (currentTimeTick - oldestTimeTick))
    580       {
    581          wdrv_aeWTargetDbResetTuple(ackEmulDB, ackEmulDB->activeIndexTable[oldestTimeIndex].monitorIndex);
    582          freeIndex = oldestTimeIndex;
    583       }
    584 
    585    }
    586 
    587 
    588    if (freeIndex == 0xff)
    589    {
    590       *activeIndex = 0xff;
    591       return NOK;
    592    }
    593 
    594    /* we have new active index */
    595    ackEmulDB->activeIndexTable[freeIndex].status = INDEX_BUSY;
    596    ackEmulDB->activeIndexTable[freeIndex].monitorIndex = index;
    597    ackEmulDB->wdrv_aeWTargetTable[index].activeIndex = freeIndex;
    598    *activeIndex = freeIndex;
    599 
    600    ackEmulDB->sessionsTableManager.currentActiveState ++;
    601    ackEmulDB->sessionsTableManager.currentStandbyState --;
    602 
    603    /* set the monitor session state to ACTIVE */
    604    wdrv_aeWTargetDbSetSessionMonitorState(ackEmulDB, index, monitorState);
    605    return OK;
    606 }
    607 
    608 /****************************************************************************
    609  *                   wdrv_aeWTargetDbSetSessionMonitorState()
    610  ****************************************************************************
    611  * DESCRIPTION:	Set the state of monitor session.
    612  *
    613  * INPUTS:	index       - session index
    614  *
    615  *
    616  * OUTPUT:	monitorState - the new monitor state
    617  *
    618  * RETURNS:	None
    619  ****************************************************************************/
    620 
    621 void wdrv_aeWTargetDbSetSessionMonitorState(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT8 monitorState)
    622 {
    623       ackEmulDB->wdrv_aeWTargetTable[index].monitorState = monitorState;
    624 }
    625 
    626 
    627 /****************************************************************************
    628  *                   wdrv_aeWTargetDbGetSessionAckNumber()
    629  ****************************************************************************
    630  * DESCRIPTION:	Get the monitor session ack number
    631  *
    632  * INPUTS:	index          - monitor session index
    633  *
    634  * OUTPUT:	*ackNumber - The ack number
    635  *
    636  * RETURNS:None
    637  ****************************************************************************/
    638 void wdrv_aeWTargetDbGetSessionAckNumber(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 *ackNumber)
    639 {
    640       *ackNumber = ackEmulDB->wdrv_aeWTargetTable[index].ackNumber;
    641 }
    642 
    643 /****************************************************************************
    644  *                   wdrv_aeWTargetDbSetSessionAckNumber()
    645  ****************************************************************************
    646  * DESCRIPTION:	Set the monitor session ack number
    647  *
    648  * INPUTS:	index          - monitor session index
    649  *        	ackNumber - The ack number
    650  *
    651  * OUTPUT:	ackNumber - The ack number
    652  *
    653  * RETURNS:None
    654  ****************************************************************************/
    655 void wdrv_aeWTargetDbSetSessionAckNumber(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 ackNumber)
    656 {
    657       ackEmulDB->wdrv_aeWTargetTable[index].ackNumber = ackNumber;
    658 }
    659 
    660 
    661 /****************************************************************************
    662  *                   wdrv_aeWTargetDbGetSessionAckCounter()
    663  ****************************************************************************
    664  * DESCRIPTION:	Get the monitor session ack counter
    665  *
    666  * INPUTS:	index          - monitor session index
    667  *
    668  * OUTPUT:	*ackCounter - The ack counter
    669  *
    670  * RETURNS:None
    671  ****************************************************************************/
    672 void wdrv_aeWTargetDbGetSessionAckCounter(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 *ackCounter)
    673 {
    674       *ackCounter = ackEmulDB->wdrv_aeWTargetTable[index].ackCounter;
    675 }
    676 
    677 /****************************************************************************
    678  *                   wdrv_aeWTargetDbSetSessionAckCounter()
    679  ****************************************************************************
    680  * DESCRIPTION:	Set the monitor session ack counter
    681  *
    682  * INPUTS:	index          - monitor session index
    683  *          ackCounter     - The ack counter
    684  *
    685  * OUTPUT:	None
    686  *
    687  * RETURNS:None
    688  ****************************************************************************/
    689 void wdrv_aeWTargetDbSetSessionAckCounter(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 ackCounter)
    690 {
    691       ackEmulDB->wdrv_aeWTargetTable[index].ackCounter = ackCounter;
    692 }
    693 
    694 /****************************************************************************
    695  *                   wdrv_aeWTargetDbGetSessionActiveIndex()
    696  ****************************************************************************
    697  * DESCRIPTION:	Get the monitor session active index
    698  *
    699  * INPUTS:	index          - monitor session index
    700  *
    701  * OUTPUT:	*activeIndex - The session active index
    702  *
    703  * RETURNS:None
    704  ****************************************************************************/
    705 void wdrv_aeWTargetDbGetSessionActiveIndex(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT8 *activeIndex)
    706 {
    707       *activeIndex = ackEmulDB->wdrv_aeWTargetTable[index].activeIndex;
    708 
    709 }
    710 
    711 /****************************************************************************
    712  *                   wdrv_aeWTargetDbGetLastWackInfo()
    713  ****************************************************************************
    714  * DESCRIPTION:	Get the last wack info for this monitor session.
    715  *
    716  * INPUTS:	index          - monitor session index
    717  *
    718  * OUTPUT:	*lastWackInfo -  the last wack info
    719  *
    720  * RETURNS:None
    721  ****************************************************************************/
    722 void wdrv_aeWTargetDbGetSessionTimeStamp(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 *timeStamp)
    723 {
    724       *timeStamp = ackEmulDB->wdrv_aeWTargetTable[index].timeStamp;
    725 
    726 }
    727 
    728 /****************************************************************************
    729  *                   wdrv_aeWTargetDbSetSessionTimeStamp()
    730  ****************************************************************************
    731  * DESCRIPTION:	Set the time stamp for this monitor session.
    732  *
    733  * INPUTS:	index          - monitor session index
    734  *          timeStamp -  the time stamp info
    735  *
    736  * OUTPUT:	None
    737  *
    738  * RETURNS:None
    739  ****************************************************************************/
    740 void wdrv_aeWTargetDbSetSessionTimeStamp(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 timeStamp)
    741 {
    742       ackEmulDB->wdrv_aeWTargetTable[index].timeStamp= timeStamp;
    743 }
    744 
    745 /****************************************************************************
    746  *                   wdrv_aeFindFreeActiveIndex()
    747  ****************************************************************************
    748  * DESCRIPTION:	find if there is free index for active session.
    749  *
    750  * INPUTS:	None.
    751  *
    752  * OUTPUT:	*freeIndex -  index of free tuple in table activeIndexTable
    753  *
    754  * RETURNS:None
    755  ****************************************************************************/
    756 static void wdrv_aeFindFreeActiveIndex(ackEmulDB_t*	ackEmulDB, UINT8 *freeIndex)
    757 {
    758 	UINT8 index;
    759 	*freeIndex = 0xff;
    760 	for(index=0 ; index< MAX_ACIVE_SESSION; index++)
    761 	{
    762 		if(ackEmulDB->activeIndexTable[index].status == INDEX_FREE)
    763 		{
    764 			*freeIndex = index;
    765 			return;
    766 		}
    767 	}
    768 }
    769 
    770 
    771 /****************************************************************************
    772  *                   wdrv_aeWTargetDbSaveAckTemplate()
    773  ****************************************************************************
    774  * DESCRIPTION:	save the Tcp ack template for the WTarget side.
    775  *
    776  * INPUTS:	index          - monitor session index.
    777  *          *pIpHeader     - Pointer to packet IP header
    778  *
    779  *
    780  * OUTPUT:	None
    781  *
    782  * RETURNS:None
    783  ****************************************************************************/
    784 void wdrv_aeWTargetDbSaveAckTemplate(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT8 *pIpHeader)
    785 {
    786 
    787    UINT8 ipHeaderLen;
    788    UINT8 tcpHeaderLen;
    789 
    790    ipHeaderLen = ((*(unsigned char*)pIpHeader  & 0x0f) * 4);
    791    tcpHeaderLen = ((((*(unsigned char*)(pIpHeader + ipHeaderLen+TCP_OFFSET_FIELD))& 0xf0)>>4) * 4);
    792    os_memoryCopy(NULL, ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.data, pIpHeader, ipHeaderLen+tcpHeaderLen);
    793    ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.ipHeaderLen = ipHeaderLen;
    794    ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.tcpHeaderLen = tcpHeaderLen;
    795 }
    796 
    797 
    798 
    799 
    800 /****************************************************************************
    801  *                   wdrv_aeWTargetDbUpdateAckTemplate()
    802  ****************************************************************************
    803  * DESCRIPTION:	Update the Tcp ack template for the WTarget side.
    804  *
    805  * INPUTS:	index          - monitor session index.
    806  *          sequenceNumber - New sequence number
    807  *
    808  * OUTPUT:	None
    809  *
    810  * RETURNS:None
    811  ****************************************************************************/
    812 void wdrv_aeWTargetDbUpdateAckTemplate(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT32 sequenceNumber)
    813 {
    814    UINT8 *pSequenceNumber;
    815    /* Update Template Sequence Number */
    816    pSequenceNumber = ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.data +
    817         ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.tcpHeaderLen +TCP_SEQUENCE_NUMBER_FIELD;
    818    *(unsigned long*)(pSequenceNumber) = wlan_ntohl(sequenceNumber);
    819 }
    820 
    821 
    822 
    823 /****************************************************************************
    824  *                   wdrv_aeWTargetDbCmpAckTemplate()
    825  ****************************************************************************
    826  * DESCRIPTION:	comper the current tcp ack with ack template.
    827  *
    828  * INPUTS:	index          - monitor session index.
    829  *          *pIpHeader     - Pointer to packet IP header
    830  *
    831  * OUTPUT:	None
    832  *
    833  * RETURNS:None
    834  ****************************************************************************/
    835 int wdrv_aeWTargetDbCmpAckTemplate(ackEmulDB_t*	ackEmulDB, UINT8 index, UINT8 *pIpHeader)
    836 {
    837    UINT8 ipHeaderLen;
    838    UINT8 *pTcpHeader;
    839    UINT8 *pIpHeaderTemplate;
    840    UINT8 *pTcpHeaderTemplate;
    841    UINT8 ipHeaderTemplateLen;
    842 
    843    ipHeaderLen = ((*(unsigned char*)pIpHeader  & 0x0f) * 4);
    844    pIpHeaderTemplate = ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.data;
    845    ipHeaderTemplateLen = ackEmulDB->wdrv_aeWTargetTable[index].ackTemplate.ipHeaderLen;
    846 
    847    /* Comprer IP field: Version ,Header Length, Precedence, TOS , Unused, Total Length */
    848    if((*(UINT32*)(pIpHeaderTemplate))!=(*(UINT32*)pIpHeader))
    849    {
    850       WLAN_OS_REPORT(("\nCompare field: Version,Header Length, Precedence, TOS, Total Length fail \n"));
    851       return NOK;
    852    }
    853 
    854    /* Comprer IP field:Fragmentation Flags, Fragment Offset, TTL */
    855    if((*(UINT32*)(pIpHeaderTemplate+IP_IDENTIFIER_FIELD+2))!=
    856       (*(UINT32*)(pIpHeader+IP_IDENTIFIER_FIELD+2)))
    857    {
    858    		WLAN_REPORT_WARNING(ackEmulDB->hReport, ACK_EMUL_MODULE_LOG,
    859 			("Compare IP field:Fragmentation Flags, Fragment Offset, TTL fail \n"));
    860       return NOK;
    861    }
    862 
    863    pTcpHeader = pIpHeader + ipHeaderLen;
    864    pTcpHeaderTemplate = pIpHeaderTemplate + ipHeaderTemplateLen;
    865 
    866 
    867       /* Comprer TCP field: Offset, Reserved, Code, Window */
    868       if((*(UINT32*)(pTcpHeaderTemplate+TCP_ACK_NUMBER_FIELD+4))!=
    869       (*(UINT32*)(pTcpHeader+TCP_ACK_NUMBER_FIELD+4)))
    870    {
    871   		WLAN_REPORT_WARNING(ackEmulDB->hReport, ACK_EMUL_MODULE_LOG,
    872 			("Compare TCP field: Offset, Reserved, Code, Window fail\n"));
    873       return NOK;
    874    }
    875       /* Comprer TCP field: Urgent */
    876 
    877    if((*(UINT16*)(pTcpHeaderTemplate+TCP_CHECKSUM_FIELD+2))!=
    878       (*(UINT16*)(pTcpHeader+TCP_CHECKSUM_FIELD+2)))
    879    {
    880    		WLAN_REPORT_WARNING(ackEmulDB->hReport, ACK_EMUL_MODULE_LOG,
    881 			("Compare TCP field: Urgent fail\n\n"));
    882       return NOK;
    883    }
    884 
    885 
    886       /* Comprer TCP field: Sequence Number */
    887    if((*(UINT32*)(pTcpHeaderTemplate+TCP_SEQUENCE_NUMBER_FIELD))!=
    888       (*(UINT32*)(pTcpHeader+TCP_SEQUENCE_NUMBER_FIELD)))
    889    {
    890        WLAN_REPORT_WARNING(ackEmulDB->hReport, ACK_EMUL_MODULE_LOG,
    891 			("Comprare TCP field: Sequence Number fail\n\n"));
    892 	/* add Ytag */
    893       return NOK;
    894    }
    895 
    896 
    897    return OK;
    898 
    899 }
    900 
    901 
    902 /****************************************************************************
    903  *                         wdrv_aeDbGetXTagStatus()
    904  ****************************************************************************
    905  * DESCRIPTION:	Get the Xtag status of the source station for this
    906  *                session index.
    907  *
    908  * INPUTS:	sessionIndex  - monitor session index
    909  *
    910  * OUTPUT:	*status -  Xtag status
    911  *
    912  * RETURNS:None
    913  ****************************************************************************/
    914 void wdrv_aeDbGetXTagStatus(ackEmulDB_t*	ackEmulDB, UINT8 sessionIndex, UINT8 *status)
    915 {
    916       UINT16 stationIndex = ackEmulDB->wdrv_aeWTargetTable[sessionIndex].sourceStationIndex;
    917       if(stationIndex != 0xff)
    918          *status = ackEmulDB->ackEmulationXTagTable[stationIndex];
    919 }
    920 
    921 /****************************************************************************
    922  *                         wdrv_aeDbSetXTagStatus()
    923  ****************************************************************************
    924  * DESCRIPTION:	Set the Xtag status of the source station for this
    925  *                session index.
    926  *
    927  * INPUTS:	sessionIndex  - monitor session index
    928  *
    929  * OUTPUT:	status -  Xtag status
    930  *
    931  * RETURNS:None
    932  ****************************************************************************/
    933 void wdrv_aeDbSetXTagStatus(ackEmulDB_t*	ackEmulDB, UINT8 sessionIndex, UINT8 status)
    934 {
    935       UINT16 stationIndex = ackEmulDB->wdrv_aeWTargetTable[sessionIndex].sourceStationIndex;
    936       if(stationIndex != 0xff)
    937          ackEmulDB->ackEmulationXTagTable[stationIndex] = status;
    938 }
    939 
    940 
    941 
    942 
    943 
    944 
    945 
    946 /******************************* WSource Data base *************************************/
    947 
    948 /****************************************************************************
    949  *                      wdrv_aeWSourceDbInit()
    950  ****************************************************************************
    951  * DESCRIPTION:	Initialize the WSource database
    952  *
    953  * INPUTS:	None
    954  *
    955  * OUTPUT:	None
    956  *
    957  * RETURNS:	None
    958  ****************************************************************************/
    959 static void wdrv_aeWSourceDbInit(ackEmulDB_t*	ackEmulDB)
    960 {
    961 	int stationIndex;
    962 	for (stationIndex =0;stationIndex < MAX_AE_STATIONS;stationIndex++)
    963 		wdrv_aeWSourceDbResetstation(ackEmulDB, stationIndex);
    964 }
    965 
    966 /****************************************************************************
    967  *                      wdrv_aeWSourceDbResetstation()
    968  ****************************************************************************
    969  * DESCRIPTION:	Reset all the WSource tuple for specific station.
    970  *
    971  * INPUTS:	stationIndex - index of station to reset
    972  *
    973  * OUTPUT:	None
    974  *
    975  * RETURNS:	None
    976  ****************************************************************************/
    977 static void wdrv_aeWSourceDbResetstation(ackEmulDB_t*	ackEmulDB, int stationIndex)
    978 {
    979 	int activeIndex;
    980 	for (activeIndex =0;activeIndex < MAX_ACIVE_SESSION;activeIndex++)
    981 	{
    982 		ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].segmentSize=0;
    983       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackNumber =0;
    984       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackCounter =0;
    985       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].timeStamp =0;
    986       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackReorderProblem = REORDER_PROBLEM_OFF;
    987 		ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.ipHeaderLen =0;
    988 		ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.tcpHeaderLen =0;
    989 	}
    990 }
    991 
    992 /****************************************************************************
    993  *                      wdrv_aeWSourceDbResetSession()
    994  ****************************************************************************
    995  * DESCRIPTION:	Reset specific WSource session tuple for specific station.
    996  *
    997  * INPUTS:	stationIndex - index of station to reset
    998  *          activeIndex  - the index of the WSource tcp session
    999  *
   1000  * OUTPUT:	None
   1001  *
   1002  * RETURNS:	None
   1003  ****************************************************************************/
   1004 void wdrv_aeWSourceDbResetSession(ackEmulDB_t*	ackEmulDB, int stationIndex,int activeIndex)
   1005 {
   1006    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].segmentSize=0;
   1007    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackNumber =0;
   1008    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackCounter =0;
   1009    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].timeStamp =0;
   1010    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackReorderProblem = REORDER_PROBLEM_OFF;
   1011    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.ipHeaderLen =0;
   1012    ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.tcpHeaderLen =0;
   1013 }
   1014 
   1015 /****************************************************************************
   1016  *                   wdrv_aeWSourceSaveAckTemplate()
   1017  ****************************************************************************
   1018  * DESCRIPTION:	save the Tcp ack template for the WSource side.
   1019  *
   1020  * INPUTS:	stationIndex          -  station index.
   1021  *          activeIndex           -  session index
   1022  *          *dataBuf              -  Packet data
   1023  *          dataLen               -  data len
   1024  *          segmentSize           - segment Size
   1025  *
   1026  *
   1027  * OUTPUT:	None
   1028  *
   1029  * RETURNS:None
   1030  ****************************************************************************/
   1031 void wdrv_aeWSourceSaveAckTemplate(ackEmulDB_t*	ackEmulDB, UINT8 stationIndex,UINT8 activeIndex,
   1032 								   UINT8* pDot11Header, UINT8 *pWlanSnapHeader, UINT8 *pIpHeader
   1033 								   ,UINT16 dataLen,UINT16 segmentSize)
   1034 {
   1035 	UINT8 *pTcpHeader;
   1036 	UINT8 *pTemplateData;
   1037 	UINT8 ipHeaderLen;
   1038 	UINT8 tcpHeaderLen;
   1039 	UINT32 ackNumber;
   1040 
   1041 
   1042 	WLAN_OS_REPORT(("wdrv_aeWSourceSaveAckTemplate datalen = %d\n",dataLen));
   1043 
   1044     wdrv_aeWSourceDbSetSessionTimeStamp(ackEmulDB, stationIndex,activeIndex,os_timeStampUs(ackEmulDB->hOs));
   1045 
   1046 
   1047 	ipHeaderLen = ((*(unsigned char*)pIpHeader  & 0x0f) * 4);
   1048 	pTcpHeader = pIpHeader + ipHeaderLen;
   1049 	tcpHeaderLen = ((((*(unsigned char*)(pTcpHeader+TCP_OFFSET_FIELD))& 0xf0)>>4) * 4);
   1050 	pTemplateData = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.data;
   1051 
   1052 	os_memoryCopy(ackEmulDB->hOs, pTemplateData,pDot11Header, WLAN_HDR_LEN);
   1053 	os_memoryCopy(ackEmulDB->hOs, pTemplateData+WLAN_HDR_LEN,pWlanSnapHeader, WLAN_SNAP_HDR_LEN);
   1054 	WLAN_OS_REPORT((" osMoveMemory 2 \n"));
   1055 
   1056 	/* osMoveMemory(pTemplateData+WLAN_HDR_LEN+WLAN_SNAP_HDR_LEN,pIpHeader, dataLen-WLAN_HDR_LEN-WLAN_SNAP_HDR_LEN);*/
   1057 	os_memoryCopy(ackEmulDB->hOs, pTemplateData+WLAN_HDR_LEN+WLAN_SNAP_HDR_LEN,pIpHeader, dataLen);
   1058 	ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.ipHeaderLen = ipHeaderLen;
   1059 	ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.tcpHeaderLen = tcpHeaderLen;
   1060 
   1061 	ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].segmentSize = segmentSize;
   1062 
   1063 	ackNumber = wlan_ntohl(*(unsigned long*)(pIpHeader+ipHeaderLen+TCP_ACK_NUMBER_FIELD));
   1064 	ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackNumber = ackNumber;
   1065 	ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackCounter =	ackNumber/(segmentSize*2);
   1066 	ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackReorderProblem = REORDER_PROBLEM_OFF;
   1067 
   1068 	/* reset the Ip & TCP Checksum */
   1069 	*(UINT16*)(pTemplateData+WLAN_HDR_LEN+WLAN_SNAP_HDR_LEN+IP_CHECKSUM_FIELD) = 0x0000;
   1070 	*(UINT16*)(pTemplateData+WLAN_HDR_LEN+WLAN_SNAP_HDR_LEN+ipHeaderLen+TCP_CHECKSUM_FIELD) = 0x0000;
   1071 
   1072 }
   1073 
   1074 
   1075 /****************************************************************************
   1076  *                   wdrv_aeWSourceDbGetSessionAckCounter()
   1077  ****************************************************************************
   1078  * DESCRIPTION:	Get the ackCounter fild from WSource data base.
   1079  *
   1080  * INPUTS:	stationIndex          -  station index.
   1081  *          activeIndex           -  session index
   1082  *
   1083  * OUTPUT:	*ackCounter -         -  the Ack Counter
   1084  *
   1085  * RETURNS:None
   1086  ****************************************************************************/
   1087 void wdrv_aeWSourceDbGetSessionAckCounter(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 *ackCounter)
   1088 {
   1089       *ackCounter = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackCounter;
   1090 }
   1091 
   1092 /****************************************************************************
   1093  *                   wdrv_aeWSourceDbGetSessionAckCounter()
   1094  ****************************************************************************
   1095  * DESCRIPTION:	Set the ackCounter fild at WSource data base.
   1096  *
   1097  * INPUTS:	stationIndex          -  station index.
   1098  *          activeIndex           -  session index
   1099  *          ackCounter -         -  the Ack Counter
   1100  *
   1101  * OUTPUT:	None
   1102  *
   1103  * RETURNS:None
   1104  ****************************************************************************/
   1105 void wdrv_aeWSourceDbSetSessionAckCounter(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 ackCounter)
   1106 {
   1107       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackCounter= ackCounter;
   1108 }
   1109 
   1110 /****************************************************************************
   1111  *                   wdrv_aeWSourceDbGetSessionAckNumber()
   1112  ****************************************************************************
   1113  * DESCRIPTION:	Get the AckNumber fild from WSource data base.
   1114  *
   1115  * INPUTS:	stationIndex          -  station index.
   1116  *          activeIndex           -  session index
   1117  *
   1118  * OUTPUT:	*ackNumber -         -  the ack number
   1119  *
   1120  * RETURNS:None
   1121  ****************************************************************************/
   1122 void wdrv_aeWSourceDbGetSessionAckNumber(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 *ackNumber)
   1123 {
   1124       *ackNumber = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackNumber;
   1125 }
   1126 
   1127 /****************************************************************************
   1128  *                   wdrv_aeWSourceDbSetSessionAckNumber()
   1129  ****************************************************************************
   1130  * DESCRIPTION:	Set the ackNumber fild at WSource data base.
   1131  *
   1132  * INPUTS:	stationIndex          -  station index.
   1133  *          activeIndex           -  session index
   1134  *          ackNumber -           -  the ack number
   1135  *
   1136  * OUTPUT:	None
   1137  *
   1138  * RETURNS:None
   1139  ****************************************************************************/
   1140 void wdrv_aeWSourceDbSetSessionAckNumber(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 ackNumber)
   1141 {
   1142       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackNumber= ackNumber;
   1143 }
   1144 
   1145 /****************************************************************************
   1146  *                   wdrv_aeWSourceDbGetSessionSegmentSize()
   1147  ****************************************************************************
   1148  * DESCRIPTION:	Get the SegmentSize fild from WSource data base.
   1149  *
   1150  * INPUTS:	stationIndex          -  station index.
   1151  *          activeIndex           -  session index
   1152  *
   1153  * OUTPUT:	*segmentSize -         -  the ack segment size
   1154  *
   1155  * RETURNS:None
   1156  ****************************************************************************/
   1157 void wdrv_aeWSourceDbGetSessionSegmentSize(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 *segmentSize)
   1158 {
   1159       *segmentSize = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].segmentSize;
   1160 }
   1161 
   1162 /****************************************************************************
   1163  *                   wdrv_aeWSourceDbSetSessionSegmentSize()
   1164  ****************************************************************************
   1165  * DESCRIPTION:	Set the segmentSize fild at WSource data base.
   1166  *
   1167  * INPUTS:	stationIndex          -  station index.
   1168  *          activeIndex           -  session index
   1169  *          segmentSize -         -  the segment size
   1170  *
   1171  * OUTPUT:	None
   1172  *
   1173  * RETURNS:None
   1174  ****************************************************************************/
   1175 void wdrv_aeWSourceDbSetSessionSegmentSize(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 segmentSize)
   1176 {
   1177       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].segmentSize= segmentSize;
   1178 }
   1179 
   1180 
   1181 /****************************************************************************
   1182  *                   wdrv_aeWSourceDbGetSessionTimeStamp()
   1183  ****************************************************************************
   1184  * DESCRIPTION:	Get the timeStamp fild from WSource data base.
   1185  *
   1186  * INPUTS:	stationIndex          -  station index.
   1187  *          activeIndex           -  session index
   1188  *
   1189  * OUTPUT:	*timeStamp -         -  the time stamp
   1190  *
   1191  * RETURNS:None
   1192  ****************************************************************************/
   1193 void wdrv_aeWSourceDbGetSessionTimeStamp(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 *timeStamp)
   1194 {
   1195       *timeStamp = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].timeStamp;
   1196 }
   1197 
   1198 /****************************************************************************
   1199  *                   wdrv_aeWSourceDbSetSessionTimeStamp()
   1200  ****************************************************************************
   1201  * DESCRIPTION:	Set the timeStamp fild at WSource data base.
   1202  *
   1203  * INPUTS:	stationIndex          -  station index.
   1204  *          activeIndex           -  session index
   1205  *          timeStamp -         -  the time stamp
   1206  *
   1207  * OUTPUT:	None
   1208  *
   1209  * RETURNS:None
   1210  ****************************************************************************/
   1211 void wdrv_aeWSourceDbSetSessionTimeStamp(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 timeStamp)
   1212 {
   1213       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].timeStamp= timeStamp;
   1214 }
   1215 
   1216 /****************************************************************************
   1217  *                   wdrv_aeWSourceDbGetSessionAckReorderProblem()
   1218  ****************************************************************************
   1219  * DESCRIPTION:	Get the ack reorder problem fild from WSource data base.
   1220  *
   1221  * INPUTS:	stationIndex          -  station index.
   1222  *          activeIndex           -  session index
   1223  *
   1224  * OUTPUT:	*ackReorderProblem    -  the ack reorder problem
   1225  *
   1226  * RETURNS:None
   1227  ****************************************************************************/
   1228 void wdrv_aeWSourceDbGetSessionAckReorderProblem(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 *ackReorderProblem)
   1229 {
   1230       *ackReorderProblem = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackReorderProblem;
   1231 }
   1232 
   1233 /****************************************************************************
   1234  *                   wdrv_aeWSourceDbSetSessionAckReorderProblem()
   1235  ****************************************************************************
   1236  * DESCRIPTION:	Set the timeStamp fild at WSource data base.
   1237  *
   1238  * INPUTS:	stationIndex          -  station index.
   1239  *          activeIndex           -  session index
   1240  *          ackReorderProblem     -  the ack reorder problem
   1241  *
   1242  * OUTPUT:	None
   1243  *
   1244  * RETURNS:None
   1245  ****************************************************************************/
   1246 void wdrv_aeWSourceDbSetSessionAckReorderProblem(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex, UINT32 ackReorderProblem)
   1247 {
   1248       ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackReorderProblem= ackReorderProblem;
   1249 }
   1250 
   1251 /****************************************************************************
   1252  *                   wdrv_aeWSourceDbGetAckTemplate()
   1253  ****************************************************************************
   1254  * DESCRIPTION:	Get the ack reorder problem fild from WSource data base.
   1255  *
   1256  * INPUTS:	stationIndex          -  station index.
   1257  *          activeIndex           -  session index
   1258  *
   1259  * OUTPUT:	**pTeplate            -  pointer to the ack template buffer.
   1260  *          *ipHeaderLen          -  IP header length of Ack template.
   1261  *          tcpHeaderLen          -  TCP header length of Ack template.
   1262  *
   1263  * RETURNS:None
   1264  ****************************************************************************/
   1265 void wdrv_aeWSourceDbGetAckTemplate(ackEmulDB_t*	ackEmulDB, UINT16 stationIndex, UINT8 activeIndex,UINT8 **pTeplate,
   1266 													 UINT8 *ipHeaderLen, UINT8 *tcpHeaderLen)
   1267 {
   1268       *ipHeaderLen   = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.ipHeaderLen;
   1269       *tcpHeaderLen  = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.tcpHeaderLen;
   1270       *pTeplate      = ackEmulDB->wdrv_aeWSourceTable[stationIndex][activeIndex].ackTemplate.data;
   1271 }
   1272 
   1273 
   1274 /****************************************************************************
   1275  *                   wdrv_aeWSourceDbUpdateTemplate()
   1276  ****************************************************************************
   1277  * DESCRIPTION:	.Fide  and updte the WSource monitor session
   1278  *
   1279  * INPUTS:	*pktBuf               -  receive tcp Ack buffer.
   1280  *          stationIndex          -  station index
   1281  *
   1282  * OUTPUT:	*sessionIndex         -  The session index of the received ack
   1283  *
   1284  * RETURNS:None
   1285  ****************************************************************************/
   1286 void wdrv_aeWSourceDbUpdateTemplate(ackEmulDB_t*	ackEmulDB, UINT8 *pktBuf,UINT8 stationIndex,UINT8 *sessionIndex)
   1287 {
   1288    int index;
   1289    int ipHeaderLen;
   1290    UINT8 *pTmpIpHeader;
   1291    int tmpIpHeaderLen;
   1292    UINT32 ackNumber;
   1293    UINT32 prevAckNumber;
   1294    UINT32 segmentSize;
   1295    UINT32 reorderProblemStatus;
   1296    *sessionIndex =0xff;
   1297 
   1298    ipHeaderLen = ((*(unsigned char*)pktBuf  & 0x0f) * 4);
   1299    /* Find WSource session */
   1300    for(index=0 ; index< MAX_ACIVE_SESSION; index++)
   1301 	{
   1302       pTmpIpHeader = (ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackTemplate.data)+ WLAN_HDR_LEN+WLAN_SNAP_HDR_LEN;
   1303       tmpIpHeaderLen = ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackTemplate.ipHeaderLen;
   1304       if (	*(UINT16*)(pTmpIpHeader +tmpIpHeaderLen + DEST_PORT_FIELD)== *(UINT16*)(pktBuf +ipHeaderLen + DEST_PORT_FIELD) &&
   1305             *(UINT16*)(pTmpIpHeader +tmpIpHeaderLen )	== *(UINT16*)(pktBuf +ipHeaderLen ) &&
   1306 	         *(unsigned long*)(pTmpIpHeader+IP_DEST_ADDRESS_FIELD) 	== *(unsigned long*)(pktBuf+IP_DEST_ADDRESS_FIELD) &&
   1307             *(unsigned long*)(pTmpIpHeader+IP_SRC_ADDRESS_FIELD)	== *(unsigned long*)(pktBuf+IP_SRC_ADDRESS_FIELD))
   1308       {
   1309          /* Update ackNumber , ackCounter and reorder problem flag */
   1310          ackNumber = wlan_ntohl(*(unsigned long*)(pktBuf+ipHeaderLen+TCP_ACK_NUMBER_FIELD));
   1311          segmentSize = ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].segmentSize;
   1312 			prevAckNumber = ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackNumber;
   1313 
   1314 
   1315          if((prevAckNumber % (segmentSize*2))>(ackNumber % (segmentSize*2)))
   1316          {
   1317             reorderProblemStatus = ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackReorderProblem;
   1318 
   1319             switch(reorderProblemStatus)
   1320             {
   1321             case REORDER_PROBLEM_OFF:
   1322                ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackReorderProblem = REORDER_PROBLEM_ON;
   1323                break;
   1324             case REORDER_PROBLEM_ON:
   1325                ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackReorderProblem = REORDER_PROBLEM_PRE;
   1326                break;
   1327             case REORDER_PROBLEM_PRE:
   1328             default:
   1329                break;
   1330             }
   1331          }
   1332 
   1333          ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackNumber = ackNumber;
   1334          ackEmulDB->wdrv_aeWSourceTable[stationIndex][index].ackCounter =	ackNumber/(segmentSize*2);
   1335           *(unsigned long*)(pTmpIpHeader+tmpIpHeaderLen+TCP_SEQUENCE_NUMBER_FIELD) =
   1336           *(unsigned long*)(pktBuf+ipHeaderLen+TCP_SEQUENCE_NUMBER_FIELD);
   1337 
   1338          *sessionIndex = index;
   1339          WLAN_OS_REPORT(("\nindex =  = %d ackNumber %X , indentifier %d\n", *sessionIndex,ackNumber,
   1340             *(UINT16*)(pktBuf+IP_IDENTIFIER_FIELD)));
   1341 
   1342 
   1343          return ;
   1344       }
   1345    }
   1346    return ;
   1347 
   1348 }
   1349