⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interrup.c

📁 虚拟网络驱动程序ndis for 数字电视 ip 数据接收
💻 C
📖 第 1 页 / 共 2 页
字号:
                    );

        if(++ii == Adapter->IPFilterPIDNum)
            break;
    }

	Adapter->TotalReceiveBytes.LowPart += 188;
	if(Adapter->TotalReceiveBytes.LowPart < 188)
		Adapter->TotalReceiveBytes.HighPart++;

    NdisDprReleaseSpinLock(&Adapter->MPEdecSpinLock);
}



void ToMPESection(IN PRTFAST_ADAPTER Adapter,IN MPE_DECODER *pMPEdec,IN PUCHAR TsBuf)// Tsbuf len = 188Bytes
{
    TSHEAD *pTsheader = (TSHEAD *)TsBuf;
    USHORT  wPID = pTsheader->PID1*256+pTsheader->PID2;
    MPE_SECTION_HEAD *pSecheader = NULL;
    PUCHAR  pSection, pPayload;
    SHORT   TmpLen0,TmpLen,DataLen;

    //if(pTsheader->sync != TS_SYNC_BYTE)
    //    return;
    //if(pMPEdec->wPID != wPID)
    //    return;

    //check TS continuous counter
    pMPEdec->bTsContinuous = TRUE;
    pMPEdec->CurTsCounter = pTsheader->continuity_counter;
    if(pMPEdec->TotalTsNum == 0)
        pMPEdec->LastTsCounter = pMPEdec->CurTsCounter;
    else
    {
        /*UCHAR iLost = pMPEdec->LastTsCounter+1;
        for( ; ; iLost++)
        {
            if( (0x0f&iLost) == pMPEdec->CurTsCounter)
                break;
            pMPEdec->LostTsNum++;
            pMPEdec->bTsContinuous = FALSE;
            pMPEdec->SectionSync = FALSE;

        }*/

		if(pMPEdec->CurTsCounter != ((pMPEdec->LastTsCounter + 1) & 0x0f))
		{
			UCHAR iLost;

/*			iLost = pMPEdec->CurTsCounter + 0x10;
			iLost -= pMPEdec->LastTsCounter + 1;
			iLost &= 0x0f;

			if(iLost > 0)
			{
	            pMPEdec->LostTsNum += iLost;
				Adapter->ulLostCounter += iLost; //add by aoguihua
		        pMPEdec->bTsContinuous = FALSE;
			    pMPEdec->SectionSync = FALSE;
			}  */

			if (pMPEdec->CurTsCounter > ((pMPEdec->LastTsCounter + 1) & 0x0f))
			{
				iLost = pMPEdec->CurTsCounter - ((pMPEdec->LastTsCounter + 1) & 0x0f);

				pMPEdec->LostTsNum += iLost;
				Adapter->ulLostCounter += iLost; //add by aoguihua
		        pMPEdec->bTsContinuous = FALSE;
			    pMPEdec->SectionSync = FALSE;
				//DbgPrint(("cur > last.\n"));
			}
			else if (pMPEdec->CurTsCounter < ((pMPEdec->LastTsCounter + 1) & 0x0f))
			{
				iLost = pMPEdec->CurTsCounter + 0x10 - ((pMPEdec->LastTsCounter + 1) & 0x0f);

				pMPEdec->LostTsNum += iLost;
				Adapter->ulLostCounter += iLost; //add by aoguihua
		        pMPEdec->bTsContinuous = FALSE;
			    pMPEdec->SectionSync = FALSE;
				//DbgPrint(("cur < last.\n"));
			}
		}

        pMPEdec->LastTsCounter = pMPEdec->CurTsCounter;
    }

    pMPEdec->TotalTsNum++;

    // skip adaptation_field
    TmpLen0 = 0;
    if((pTsheader->adaptation_field == 0x02) || 
		(pTsheader->adaptation_field == 0x03))
    {
        TmpLen0 = 1+TsBuf[sizeof(TSHEAD)];
        if(TmpLen0 >= 184)
		{
		//	DbgPrint(("exit 1.\n"));
            return;
		}
    }

    // decoder section
    TmpLen = sizeof(TSHEAD) + TmpLen0 + 
		pTsheader->start_indicator*(TsBuf[sizeof(TSHEAD)+TmpLen0]+1);
    if(TmpLen >= 188)
	{
	//	DbgPrint(("exit 2.\n"));
        return;
	}

    pPayload = TsBuf+sizeof(TSHEAD)+TmpLen0;
    pSection = TsBuf+TmpLen;

    if(pTsheader->start_indicator)
    {
        // pMPEdec->SectionDone = FALSE;
        if((pMPEdec->SectionSync)&&(pPayload[0] != 0))
        {
            DataLen = pPayload[0];
            if((pMPEdec->CurSectionLen+DataLen) > MPE_MAXSECTIONLEN)
            {
                //Adapter->IPStatistic[pMPEdec->IndexPID].lLostStatistic++;
                //Adapter->ulLostCounter++;

				ToMACPacket(Adapter,pMPEdec);
                pMPEdec->SectionSync = FALSE;
			//	DbgPrint(("to mac 1.\n"));
                //return;
            }

            pSection = pPayload+1;
            NdisMoveMemory(pMPEdec->SectionBuf+pMPEdec->CurSectionLen,pSection,DataLen);
            //memcpy(pMPEdec->SectionBuf+pMPEdec->CurSectionLen,pSection,DataLen);
            pMPEdec->CurSectionLen += DataLen;
            if(pMPEdec->TotalSectionLen == 0)
            {
                pSecheader = (MPE_SECTION_HEAD *)pMPEdec->SectionBuf;
                pMPEdec->TotalSectionLen = pSecheader->section_length1*256+pSecheader->section_length2;
            }

            if(pMPEdec->TotalSectionLen+3 <= pMPEdec->CurSectionLen)
			{
                ToMACPacket(Adapter,pMPEdec);
			}
			else
			{
				//DbgPrint(("to mac 2.\n"));
				ToMACPacket(Adapter,pMPEdec);
			}

            pSection = TsBuf+TmpLen;
        }

        DataLen = 188-TmpLen;
        while(DataLen>0)
        {
            if(pSection[0] != 0x3e)
            {
				if (pMPEdec->SectionSync)
					ToMACPacket(Adapter,pMPEdec);

                pMPEdec->SectionSync = FALSE;
				//DbgPrint(("%x.\n"),pSection[0]);
				//DbgPrint(("exit 3.\n"));
                return;
            } 

            pMPEdec->CurSectionLen = DataLen;
            NdisMoveMemory(pMPEdec->SectionBuf,pSection,DataLen);
            //memcpy(pMPEdec->SectionBuf,pSection,DataLen);
            pMPEdec->SectionSync = TRUE; 
            if( pMPEdec->CurSectionLen >= sizeof(MPE_SECTION_HEAD) )
            {
                pSecheader = (MPE_SECTION_HEAD *)pMPEdec->SectionBuf;
                pMPEdec->TotalSectionLen = pSecheader->section_length1*256+pSecheader->section_length2;
                if( pMPEdec->TotalSectionLen+3 <= pMPEdec->CurSectionLen )
                {
                    ToMACPacket(Adapter,pMPEdec);
                    DataLen -= pMPEdec->TotalSectionLen+3;
                    pSection += pMPEdec->TotalSectionLen+3;

					/*if (pSection[0]>0)
					{
						DataLen -= (pSection[0] + 1);
						pSection += (pSection[0] + 1);
					}*/
                }
                else
				{
					//DbgPrint(("exit 4.\n"));
                    return;
				}
            }
            else
            {
                //Adapter->IPStatistic[pMPEdec->IndexPID].lLostStatistic += 2;
                //Adapter->ulLostCounter += 2;

                pMPEdec->TotalSectionLen = 0;
			//	DbgPrint(("exit 5.\n"));
                return;
            }
        }
    }
    else if(pMPEdec->SectionSync)
    {
        DataLen = 188-TmpLen;
        if( (pMPEdec->CurSectionLen+DataLen) >MPE_MAXSECTIONLEN)
        {
            //Adapter->IPStatistic[pMPEdec->IndexPID].lLostStatistic += 2;
            //Adapter->ulLostCounter += 2;
		//	DbgPrint(("to mac 4.\n"));
			ToMACPacket(Adapter,pMPEdec);

            pMPEdec->SectionSync = FALSE;
            return;
        }

        NdisMoveMemory(pMPEdec->SectionBuf+pMPEdec->CurSectionLen,pSection,DataLen);
        //memcpy(pMPEdec->SectionBuf+pMPEdec->CurSectionLen,pSection,DataLen);
        pMPEdec->CurSectionLen += DataLen;
        if( pMPEdec->TotalSectionLen == 0 )
        {
            pSecheader = (MPE_SECTION_HEAD *)pMPEdec->SectionBuf;
            pMPEdec->TotalSectionLen = pSecheader->section_length1*256+pSecheader->section_length2;
        }
        if( pMPEdec->TotalSectionLen+3 <= pMPEdec->CurSectionLen )
		{
            ToMACPacket(Adapter,pMPEdec);
		}
    }
}


typedef unsigned char       BYTE;
typedef unsigned short      WORD;
typedef unsigned long       DWORD;


WORD IPchksum(WORD* pDATA,WORD len)
{
	DWORD sum;
	
	sum=0x00000000;
	while(len>1)
	{
		sum+=*pDATA++;
		len-=2;
	}
	
	if(len==1)
	        sum+=(*(BYTE*)pDATA);
	        
	sum=(sum>>16)+(sum&0x0000FFFF);
	sum+=(sum>>16);
	
	return ( (WORD)( (~sum)&0x0000FFFF) );	
	
}



void ToMACPacket(IN PRTFAST_ADAPTER Adapter, IN MPE_DECODER *pMPEdec)
{
    MPE_SECTION_HEAD *pSecheader = (MPE_SECTION_HEAD *)pMPEdec->SectionBuf;
    SHORT IPLen, SectionDataLen;
	WORD crc,continueCnt;
    PUCHAR pIPstart = pMPEdec->SectionBuf + sizeof(MPE_SECTION_HEAD);
	PUCHAR temp;
	WORD i,j;
    ULONG ulRecIP, IndicateLen, ulRecMAC;
    UCHAR bFilterPass = 0, DstMAC[RTFAST_LENGTH_OF_ADDRESS] = {0x01,0x00,0x5e,};
    int ii;

    IPLen = (pIPstart[2]<<8) + pIPstart[3];

    /*SectionDataLen = pMPEdec->CurSectionLen-sizeof(MPE_SECTION_HEAD)-4;
    if( IPLen > SectionDataLen )
    {
        //Adapter->IPStatistic[pMPEdec->IndexPID].lLostStatistic++;
        //Adapter->ulLostCounter++;
        return;
    }*/

	// destination
    pMPEdec->MACheader[0] = pSecheader->MAC_address1;
    pMPEdec->MACheader[1] = pSecheader->MAC_address2;
    pMPEdec->MACheader[2] = pSecheader->MAC_address3;
    pMPEdec->MACheader[3] = pSecheader->MAC_address4;
    pMPEdec->MACheader[4] = pSecheader->MAC_address5;
    pMPEdec->MACheader[5] = pSecheader->MAC_address6;
    NdisZeroMemory(pMPEdec->MACheader+6,6);// source
    //memset(pMPEdec->MACheader+6,0x00,6);// source
    pMPEdec->MACheader[12] = 0x08;  // MAC protocol
    pMPEdec->MACheader[13] = 0x00;

	//DbgPrint(("num=%d,last=%d.\n"),pSecheader->section_number,pSecheader->last_section_number);
    
    pMPEdec->SectionSync = FALSE;

    pMPEdec->IPbuf = pIPstart;
    pMPEdec->IPPacketLen = IPLen;
    Adapter->CurMPEdec = pMPEdec;

    if(Adapter->PacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST |
                                 NDIS_PACKET_TYPE_PROMISCUOUS))
    {
        bFilterPass = 1;
    }

    //statistics
    ulRecIP = ( (pIPstart[16]<<24)|(pIPstart[17]<<16)|(pIPstart[18]<<8)|(pIPstart[19]) );
	ulRecMAC = (pMPEdec->MACheader[0] << 16) | (pMPEdec->MACheader[1] << 8) | pMPEdec->MACheader[2];


    //if(((pIPstart[16]&0xF0) == 0xE0) || (ulRecMAC == 0x01005e))//Muticast
	if( (pIPstart[16]&0xF0)==0xE0 )//Muticast
    {

        /*if(!bFilterPass)
        {
            DstMAC[3] = 0x7F&pIPstart[17];
            DstMAC[4] = pIPstart[18];
            DstMAC[5] = pIPstart[19];
            for(ii = 0; ii<MAX_IP_FILTERPID_NUM; ii++)
			{
                if(!memcmp(Adapter->Addresses[ii],DstMAC,RTFAST_LENGTH_OF_ADDRESS))
                {
                    bFilterPass = 1;
                   break;
                }
			}
        }*/

		DbgPrint(("to multi.\n"));
       // if(bFilterPass)
            Adapter->llRxMulticastBytes += IPLen+RTFAST_HEADER_SIZE; 

    } 
    else if( ((pIPstart[16]&0x80) == 0x00)||((pIPstart[16]&0xC0) == 0x80)||((pIPstart[16]&0xE0) == 0xC0))//Unicast
    {
        //unicast filter
        BOOLEAN  bMACpass = FALSE, bIPpass = FALSE;

        if(Adapter->bMACorIPfiltr == FALSE)
        {
            if( (pMPEdec->MACheader[0] == Adapter->StationAddress[0]) &&
                (pMPEdec->MACheader[1] == Adapter->StationAddress[1]) &&
                (pMPEdec->MACheader[2] == Adapter->StationAddress[2]) &&
                (pMPEdec->MACheader[3] == Adapter->StationAddress[3]) &&
                (pMPEdec->MACheader[4] == Adapter->StationAddress[4]) &&
                (pMPEdec->MACheader[5] == Adapter->StationAddress[5]))
                bMACpass = TRUE;

			DbgPrint(("to 2.\n"));
        }
        else
        {
            if(ulRecIP == Adapter->UnicastIPFilter)
            {
                pMPEdec->MACheader[0] = Adapter->StationAddress[0];
                pMPEdec->MACheader[1] = Adapter->StationAddress[1];
                pMPEdec->MACheader[2] = Adapter->StationAddress[2];
                pMPEdec->MACheader[3] = Adapter->StationAddress[3];
                pMPEdec->MACheader[4] = Adapter->StationAddress[4];
                pMPEdec->MACheader[5] = Adapter->StationAddress[5];
                bIPpass = TRUE;
				DbgPrint(("to 3.\n"));
            }
        }

        if( !( bMACpass||bIPpass ) )
		{
			DbgPrint(("to 4.\n"));
            return;
		}

        Adapter->llRxUnicastBytes = IPLen+RTFAST_HEADER_SIZE;
        Adapter->ulRxUnicastIP = ulRecIP;

        bFilterPass = 1;

		DbgPrint(("to 5.\n"));
		pMPEdec->RxStatistic += IPLen+RTFAST_HEADER_SIZE;
    }  
    
   // if(!bFilterPass)
  //      return;

    // Modified by hanney on May 28th 2005
    //pMPEdec->RxStatistic += IPLen+RTFAST_HEADER_SIZE;
    Adapter->IPStatistic[pMPEdec->IndexPID].lRxStatistic += IPLen+RTFAST_HEADER_SIZE;
    Adapter->IPStatistic[pMPEdec->IndexPID].lRxFrameStatistic++;
    // ****
    Adapter->TotalTransmitBytes.LowPart += IPLen+RTFAST_HEADER_SIZE;
    if(Adapter->TotalTransmitBytes.LowPart < (ULONG)IPLen+RTFAST_HEADER_SIZE)
        Adapter->TotalTransmitBytes.HighPart++;

    Adapter->FramesRcvGood++;

    IndicateLen = ((UINT)IPLen+RTFAST_HEADER_SIZE) > (Adapter->MaxLookAhead + RTFAST_HEADER_SIZE) ?
            (Adapter->MaxLookAhead + RTFAST_HEADER_SIZE) :
            (IPLen+RTFAST_HEADER_SIZE);


    NdisMEthIndicateReceive(
            Adapter->MiniportAdapterHandle,
            (NDIS_HANDLE)Adapter,
            (PCHAR)(pMPEdec->MACheader),
            RTFAST_HEADER_SIZE,
            (PCHAR)pIPstart,
            IndicateLen,
            IPLen
            ); 
    Adapter->IndicateReceiveDone = TRUE;

//19970721
    //
    // Finally, indicate ReceiveComplete to all protocols which received packets
    //
    if(Adapter->IndicateReceiveDone)
    {
        NdisMEthIndicateReceiveComplete(Adapter->MiniportAdapterHandle);
        Adapter->IndicateReceiveDone = FALSE;
    }
//19970721

	Adapter->FramesXmitGood++;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -