Exemple #1
0
void CMsregPacketHeader::ReadDataFromFile(CFile& cfFile, DWORD& dwChecksum)
{
	// Read inherited data.
	CMsregPacket::ReadDataFromFile(cfFile, dwChecksum);

	// Read customer ID.
	m_csCustomerId = ReadString(cfFile, dwChecksum);

	// Read packet count.
	DWORD dwPackets = ReadDword(cfFile, dwChecksum);

	// Read packets.
	DeleteAllPackets();
	for (DWORD i = 0; i < dwPackets; i++)
	{
		AddPacket(ReadPacket(cfFile));
	}
}
Exemple #2
0
static unsigned DoAccess( void )
{
    unsigned    left;
    unsigned    len;
    unsigned    i;
    unsigned    piece;

    _DBG_EnterFunc( "DoAccess()" );
    _DBG_Writeln( "StartPacket" );
    StartPacket();
    if( Out_Mx_Num == 0 ) {
        /* Tell the server we're not expecting anything back */
        *(access_req *)In_Mx_Ptr[0].ptr |= 0x80;
    }
    for( i = 0; i < In_Mx_Num; ++i ) {
        _DBG_Writeln( "AddPacket" );
        AddPacket( In_Mx_Ptr[i].len, In_Mx_Ptr[i].ptr );
    }
    *(access_req *)In_Mx_Ptr[0].ptr &= ~0x80;
    _DBG_Writeln( "PutPacket" );
    PutPacket();
    if( Out_Mx_Num != 0 ) {
        _DBG_Writeln( "GetPacket" );
        len = GetPacket();
        left = len;
        for( i = 0; i < Out_Mx_Num && left > 0; ++i ) {
            if( left > Out_Mx_Ptr[i].len ) {
                piece = Out_Mx_Ptr[i].len;
            } else {
                piece = left;
            }
            _DBG_Writeln( "RemovePacket" );
            RemovePacket( piece, Out_Mx_Ptr[i].ptr );
            left -= piece;
        }
    } else {
        len = 0;
        left = 0;
    }
    _DBG_ExitFunc( "DoAccess()" );
    return( len - left );
}
Exemple #3
0
static trap_elen DoAccess( void )
{
    trap_elen  left;
    trap_elen  len;
    trap_elen  i;
    trap_elen  piece;

    _DBG_EnterFunc( "DoAccess()" );
    _DBG_Writeln( "StartPacket" );
    StartPacket();
    if( Out_Mx_Num == 0 ) {
        /* Tell the server we're not expecting anything back */
        TRP_REQUEST( In_Mx_Ptr ) |= 0x80;
    }
    for( i = 0; i < In_Mx_Num; ++i ) {
        _DBG_Writeln( "AddPacket" );
        AddPacket( In_Mx_Ptr[i].ptr, In_Mx_Ptr[i].len );
    }
    TRP_REQUEST( In_Mx_Ptr ) &= ~0x80;
    _DBG_Writeln( "PutPacket" );
    PutPacket();
    if( Out_Mx_Num != 0 ) {
        _DBG_Writeln( "GetPacket" );
        len = GetPacket();
        left = len;
        for( i = 0; i < Out_Mx_Num && left > 0; ++i ) {
            if( left > Out_Mx_Ptr[i].len ) {
                piece = Out_Mx_Ptr[i].len;
            } else {
                piece = left;
            }
            _DBG_Writeln( "RemovePacket" );
            RemovePacket( Out_Mx_Ptr[i].ptr, piece );
            left -= piece;
        }
    } else {
        len = 0;
        left = 0;
    }
    _DBG_ExitFunc( "DoAccess()" );
    return( len - left );
}
Startup::~Startup() {
    AddPacket(0);
    SendTo(GetCurrentProcess()->GetName());
}
Exemple #5
0
void CRecordingBuffer::Update()
{
	SRecording_FrameData packet;
	packet.frametime = gEnv->pTimer->GetFrameStartTime().GetSeconds();
	AddPacket(packet);
}
Exemple #6
0
void Optimise_Plc(PLC *plc)
{
	TAG *btag=NULL; // Base Tag for optimized Packet
	PACKET *packet=NULL;
	int bfindex=0,findex=0,bfunc=0,func=0;
	int MaxRealPacketSize=50;
	int MaxEltByPacket=MaxRealPacketSize;

	TrieChListe(&(plc->Tags),&compare_plc);
	LISTE *tags=&(plc->Tags);
	LISTE *packets=&(plc->Packets);
	Log(LOG_DEBUG,"Optimise Plc: %s (%d Tags)\n",plc->PlcName,tags->Count);
	ELEMENT *elt=GetFirst(tags);
	while (elt!=NULL)
	{
		if (btag==NULL)
		{
			btag=elt->Data;
			bfindex=_MBGetC_F_Index(btag->Address);
			//bfunc=_MBGetC_F_Index(btag->Address);
			bfunc=FTable[bfindex].Read_Function;
			elt=GetNext(tags,elt);
			continue;
		} else
		{
			TAG *tag=elt->Data;
			findex=_MBGetC_F_Index(btag->Address);
			//func=_MBGetC_F_Index(tag->Address);
			func=FTable[findex].Read_Function;
			if ((bfunc==func)&&(_MBGetAddress(btag->Address)+MaxEltByPacket>=_MBGetAddress(tag->Address)))
			{
				if (packet==NULL) // create a new packet
				{
					packet=malloc(sizeof(PACKET));
					if (packet!=NULL) // new packet
					{
						AddChListe(packets,packet);
						memset(packet,0,sizeof(PACKET));
						AddPacket(packet,btag); // base tag
						memcpy(packet->BaseAddress,btag->Address,sizeof(packet->BaseAddress));
						RemoveChListe(tags,btag);
					} else Log(LOG_CRIT,"Optimise_Plc : Unable to allocate memory: %s\n",strerror(errno));
				};
				if (packet!=NULL) // add to actual packet
				{
					AddPacket(packet,tag);
					tag->Index=_MBGetAddress(tag->Address)-_MBGetAddress(btag->Address);//-1;
					elt=GetNext(tags,elt);
					RemoveChListe(tags,tag);
					packet->NumElt=_MBGetAddress(tag->Address)-_MBGetAddress(btag->Address)+_MBGetDataSize(FTable[findex].DataType);
					continue;
				}
			} else
			{
				btag=NULL; // if not, there is no possibility of optimization
				packet=NULL;
				continue;
			}
			elt=GetNext(tags,elt);
		}
	}
}
Exemple #7
0
RTPPacket* FECDecoder::Recover()
{
	BYTE aux[8];
	QWORD lostMask = 0;

	//Check we have media pacekts
	if (!medias.size())
		//Exit
		return NULL;
	//Get First packet
	RTPPacket* first = medias.begin()->second;
	//Get the SSRC
	DWORD ssrc = first->GetSSRC();
	//Get first media packet
	DWORD minSeq = first->GetExtSeqNum();
	//Iterator on seq
	DWORD lastSeq = minSeq;

	//Set to 0
	memset(aux,0,8);
	//Create writter
	BitWritter w(aux,8);
	//vector of lost pacekt seq
	std::vector<DWORD> losts;

	//For each media packet
	for (RTPOrderedPackets::iterator it=medias.begin();it!=medias.end();++it)
	{
		//Get seq
		DWORD cur = it->first;
		//Insert lost
		for (DWORD i=lastSeq+1;i<cur;++i)
		{
			//set mask bit to not present
			w.Put(1,0);
			//Add to the vecotr
			losts.push_back(i);
		}
		//Set last seq
		lastSeq = cur;
		//set mask bit to present
		w.Put(1,1);
	}

	//End it
	w.Flush();

	//Get mask
	lostMask = get8(aux,0);

	//Check we have lost pacekts
	if (!losts.size())
		//Exit
		return NULL;

	//For each lost packet
	for(std::vector<DWORD>::iterator it=losts.begin();it!=losts.end();++it)
	{
		//Get lost packet sequence
		DWORD seq = *it;

		//Search FEC packets associated this media packet
		for (FECOrderedData::iterator it2 = codes.begin();it2!=codes.end();++it2)
		{
			//Get FEC packet
			FECData *fec = it2->second;

			//Check if it is associated with this media pacekt in level 0
			if (!fec->IsProtectedAtLevel0(seq))
				//Next
				continue;

			//Get the seq difference between fec data and the media
			// fec seq has to be <= media seq it fec data protect media data)
			DWORD diff = seq-fec->GetBaseExtSeq();
			//Shit mask of the lost packets to check the present ones from the base seq
			QWORD mediaMask = lostMask << (fec->GetBaseExtSeq()-minSeq);
			//Remove lost packet bit from the fec mask
			QWORD fecMask = fec->GetLevel0Mask() & ~(((QWORD)1)<<(64-diff-1));

			//Compare needed pacekts with actual pacekts, to check if we have all of them except the missing
			if ((fecMask & mediaMask) == fecMask)
			{
				//Rocovered media data
				BYTE	recovered[MTU+SRTP_MAX_TRAILER_LEN] ZEROALIGNEDTO32;
				//Get attributes
				bool  p  = fec->GetRecoveryP();
				bool  x  = fec->GetRecoveryX();
				BYTE  cc = fec->GetRecoveryCC();
				bool  m  = fec->GetRecoveryM();
				BYTE  pt = fec->GetRecoveryType();
				DWORD ts = fec->GetRecoveryTimestamp();
				WORD  l  = fec->GetRecoveryLength();
				//Get protection length
				DWORD level0Size = fec->GetLevel0Size();
				//Ensure there is enought size
				if (level0Size>MTU)
				{
					//Error
					Error("-FEC level 0 data size too big [%d]\n",level0Size);
					//Skip this one
					continue;
				}
				//Copy data
				memcpy(recovered,fec->GetLevel0Data(),level0Size);
				//Set value in temp buffer
				set8(aux,0,fecMask);
				//Get bit reader
				BitReader r(aux,8);
				//Read all media packet
				while(r.Left())
				{
					//If the media packet is used to reconstrud the packet
					if (r.Get(1))
					{
						//Get media packet
						RTPPacket* media = medias[fec->GetBaseExtSeq()+r.GetPos()-1];
						//Calculate receovered attributes
						p  ^= media->GetP();
						x  ^= media->GetX();
						cc ^= media->GetCC();
						m  ^= media->GetMark();
						pt ^= media->GetType();
						ts ^= media->GetTimestamp();
						l  ^= media->GetMediaLength();
						//Get data
						BYTE *payload = media->GetMediaData();
						//Calculate the xor
						for (int i=0;i<fmin(media->GetMediaLength(),level0Size);++i)
							//XOR
							recovered[i] ^= payload[i];
					}
				}
				//Create new video packet
				RTPPacket* packet = new RTPPacket(MediaFrame::Video,pt);
				//Set values
				packet->SetP(p);
				packet->SetX(x);
				packet->SetMark(m);
				packet->SetTimestamp(ts);
				//Set sequence number
				packet->SetSeqNum(seq);
				//Set seq cycles
				packet->SetSeqCycles(fec->GetBaseSeqCylcles());
				//Set ssrc
				packet->SetSSRC(ssrc);
				//Set payload and recovered length
				if (!packet->SetPayloadWithExtensionData(recovered,l))
				{
					//Delete packet
					delete(packet);
					//Error
					Error("-FEC payload of recovered packet to big [%u]\n",(unsigned int)l);
					//Skip
					continue;
				}

				Debug("-recovered packet len:%u ts:%u pts:%u seq:%d\n",l,ts,packet->GetTimestamp() ,packet->GetSeqNum());

				//Append the packet to the media packet list
				if (AddPacket(packet))
					//Return it if contained media
					return packet;
				else
					//Discard and continue
					delete(packet);
			}
		}
	}
	//Nothing found
	return NULL;
}
Exemple #8
0
unsigned ReqProg_load( void )
{
    char                buffer[160];
    char                *src;
    char                *dst;
    char                *name;
    char                *endparm;
    char                *err;
    tiny_ret_t          rc;
    prog_load_ret       *ret;
    unsigned_16         len;

    SaveVectors( OrigVectors );
    _DBG_EnterFunc( "AccLoadProg()" );
    ret = GetOutPtr( 0 );
    src = name = GetInPtr( sizeof( prog_load_req ) );
    rc = FindFilePath( src, buffer, DosXExtList );
    endparm = LinkParm;
    while( *endparm++ != '\0' ) {}      // skip program name
    strcpy( endparm, buffer );
    err = RemoteLink( LinkParm, 0 );
    if( err != NULL ) {
        _DBG_Writeln( "Can't RemoteLink" );
        TinyWrite( TINY_ERR, err, strlen( err ) );
        LoadError = err;
        ret->err = 1;
        len = 0;
    } else {
        if( TINY_OK( rc ) ) {
            while( *src++ != '\0' ) {}
            len = GetTotalSize() - ( src - name ) - sizeof( prog_load_req );
            dst = (char *)buffer;
            while( *dst++ != '\0' ) {};
            memcpy( dst, src, len );
            dst += len;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( sizeof( prog_load_req ), In_Mx_Ptr[0].ptr );
            _DBG_Writeln( "AddPacket" );
            AddPacket( dst - buffer, buffer );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            len = GetPacket();
            _DBG_Writeln( "RemovePacket" );
            RemovePacket( sizeof( *ret ), ret );
        } else {
            len = DoAccess();
        }
        _DBG_Writeln( "Linked --" );
        if( ret->err != 0 ) {
            get_err_text_req    erracc;
            prog_kill_req       killacc;
            int                 msg_len;

            _DBG_Writeln( "loadret->errcode != 0" );
            if( LoadError == NULL ) {
                _DBG_Writeln( "making a REQ_GET_ERR_TEXT request" );
                erracc.req = REQ_GET_ERR_TEXT;
                erracc.err = ret->err;
                _DBG_Writeln( "StartPacket" );
                StartPacket();
                _DBG_Writeln( "AddPacket" );
                AddPacket( sizeof( erracc ), &erracc );
                _DBG_Writeln( "PutPacket" );
                PutPacket();
                _DBG_Writeln( "GetPacket" );
                msg_len = GetPacket();
                _DBG_Writeln( "RemovePacket" );
                RemovePacket( msg_len, FailMsg );
                _DBG_Write( "FailMsg :  " );
                _DBG_NoTabWriteln( FailMsg );
                LoadError = FailMsg;
            }

            _DBG_Writeln( "making a REQ_PROG_KILL request" );
            killacc.req = REQ_PROG_KILL;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( sizeof( killacc ), &killacc );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            GetPacket();
            //RemovePacket( msg_len, &erracc );
            RemoteUnLink();

            TaskLoaded = FALSE;
        }
    }
    if( ret->err == 0 ) {
        _DBG_Writeln( "loadret->error_code == 0" );
        TaskLoaded = TRUE;
    }
    SaveVectors( LoadVectors );
    SaveVectors( CurrVectors );
    _DBG_ExitFunc( "AccLoadProg()" );
    return( len );
}
Exemple #9
0
trap_retval ReqProg_load( void )
{
    char                buffer[160];
    char                *src;
    char                *dst;
    char                *name;
    char                *endparm;
    const char          *err;
    tiny_ret_t          rc;
    prog_load_ret       *ret;
    trap_elen           len;

    SaveVectors( OrigVectors );
    _DBG_EnterFunc( "AccLoadProg()" );
    ret = GetOutPtr( 0 );
    src = name = GetInPtr( sizeof( prog_load_req ) );
    rc = FindProgFile( src, buffer, DosExtList );
    endparm = LinkParms;
    while( *endparm++ != '\0' ) {}      // skip trap parameters
    strcpy( endparm, buffer );          // add command line
    // result is as follow
    // "trap parameters string"+"\0"+"command line string"+"\0"
    err = RemoteLink( LinkParms, false );
    if( err != NULL ) {
        _DBG_Writeln( "Can't RemoteLink" );
        TinyWrite( TINY_ERR, err, strlen( err ) );
        LoadError = err;
        ret->err = 1;
        len = 0;
    } else {
        if( TINY_OK( rc ) ) {
            while( *src++ != '\0' ) {}
            len = GetTotalSize() - ( src - name ) - sizeof( prog_load_req );
            dst = (char *)buffer;
            while( *dst++ != '\0' ) {};
            memcpy( dst, src, len );
            dst += len;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( In_Mx_Ptr[0].ptr, sizeof( prog_load_req ) );
            _DBG_Writeln( "AddPacket" );
            AddPacket( buffer, dst - buffer );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            len = GetPacket();
            _DBG_Writeln( "RemovePacket" );
            RemovePacket( ret, sizeof( *ret ) );
        } else {
            len = DoAccess();
        }
        _DBG_Writeln( "Linked --" );
        if( ret->err != 0 ) {
            get_err_text_req    erracc;
            prog_kill_req       killacc;
            trap_elen           msg_len;

            _DBG_Writeln( "loadret->errcode != 0" );
            if( LoadError == NULL ) {
                _DBG_Writeln( "making a REQ_GET_ERR_TEXT request" );
                erracc.req = REQ_GET_ERR_TEXT;
                erracc.err = ret->err;
                _DBG_Writeln( "StartPacket" );
                StartPacket();
                _DBG_Writeln( "AddPacket" );
                AddPacket( &erracc, sizeof( erracc ) );
                _DBG_Writeln( "PutPacket" );
                PutPacket();
                _DBG_Writeln( "GetPacket" );
                msg_len = GetPacket();
                _DBG_Writeln( "RemovePacket" );
                RemovePacket( FailMsg, msg_len );
                _DBG_Write( "FailMsg :  " );
                _DBG_NoTabWriteln( FailMsg );
                LoadError = FailMsg;
            }

            _DBG_Writeln( "making a REQ_PROG_KILL request" );
            killacc.req = REQ_PROG_KILL;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( &killacc, sizeof( killacc ) );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            GetPacket();
            //RemovePacket( &erracc, msg_len );
            RemoteUnLink();

            TaskLoaded = false;
        }
    }
    if( ret->err == 0 ) {
        _DBG_Writeln( "loadret->error_code == 0" );
        TaskLoaded = true;
    }
    SaveVectors( LoadVectors );
    SaveVectors( CurrVectors );
    _DBG_ExitFunc( "AccLoadProg()" );
    return( len );
}
Exemple #10
0
//*****************************************************************************
void PACKET_STREAM::AddPacket(PACKET_HANDLER* Packet, void* Buffer)
{
    AddPacket(Packet->GetId(), Packet->GetSize(), Buffer);    
}