void UT_CSRTPCryptoHandlerSRTCP::UT_CountSenderPacketIndexL2L(  )
 	{
 	//Index Rekey Check when does not need Re-Key
 	// just a dummy packet index
    //iCryptoHandlerSRTCP->iReplayPktIndex = 5;
    iCryptoHandlerSRTCP->iSRTCPIndexEStripped= 0x7FFFFFFE;
    HBufC8* rtcpPacket =HBufC8::NewLC(KRTCPPacketIndexUpperLimit().Length());
	*rtcpPacket=KRTCPPacketIndexUpperLimit;
    Hex(*rtcpPacket);
    TInt len= KRTCPPacketIndexUpperLimit().Length();
	rtcpPacket->Des().SetLength(len/2);
    iCryptoHandlerSRTCP->InitializePlainPacketL(*rtcpPacket);
    iCryptoHandlerSRTCP->CountSenderPacketIndexL();
    //normal situation
    //7FFFFFFE -is the index we sent
    EUNIT_ASSERT(iCryptoHandlerSRTCP->iSRTCPIndex==0xFFFFFFFF);
    EUNIT_ASSERT(iReKeyCalled== ETrue);
	CleanupStack::PopAndDestroy(rtcpPacket);
 	} 	
TEMPLATE_InterruptHandler
void TEMPLATED_InterruptHandler::handleInstructionAbort()
{
	kout << "Instruction Abort \n";
	auto esr=RegESR_EL1::read();
	RegELR_EL1::read().dump();
	RegSCTLR_EL1::read().dump();
	RegSPSR_EL1::read().dump();
	esr.dump();
	int   farNotValid = getBits(esr.ISS,10,10);
	if(!farNotValid)
	{
		kout << "FAR = " << Hex(RegFAR_EL1::read().faultAddr) << "\n";
	}else{
		kout << "FAR not valid\n";
	}
	kout << "not processing it\n";
	asm_wfi_loop();
}
void UT_CSRTPCryptoHandlerSRTCP::UT_AuthenticateL2L( ) 
 	{
 	//false cases when auth tage is not equal 
 	HBufC8* encSrtcpPacket =HBufC8::NewLC(KSRTCPPacketWrongAuthTag().Length());
	*encSrtcpPacket=KSRTCPPacketWrongAuthTag;
    Hex(*encSrtcpPacket);
    TInt len= KSRTCPPacketWrongAuthTag().Length();
	encSrtcpPacket->Des().SetLength(len/2);
 	iCryptoHandlerSRTCP->InitializeEncryptedPacketL(*encSrtcpPacket);
 	iCryptoHandlerSRTCP->ReceiverPacketIndexL();
    iCryptoHandlerSRTCP->CheckMasterKeyIdentifierL();
    iCryptoHandlerSRTCP->DeriveSessionKeysL();
	
	// do the authentication (integrity check)
    RTP_EUNIT_ASSERT_SPECIFIC_LEAVE(iCryptoHandlerSRTCP->AuthenticateL(), 
    													KErrNotFound);
 	CleanupStack::PopAndDestroy(encSrtcpPacket);     
 	
 	
 	}
void UT_CSRTPCryptoHandlerSRTCP::UT_DeriveSessionKeysL_OneL()
	{
	HBufC8* encSrtcpPacket =HBufC8::NewLC(KSRTCPPacket().Length());
	*encSrtcpPacket=KSRTCPPacket;
    Hex(*encSrtcpPacket);
    TInt len= KSRTCPPacket().Length();
	encSrtcpPacket->Des().SetLength(len/2);
	
    iCryptoHandlerSRTCP->InitializeEncryptedPacketL(*encSrtcpPacket);
    iCryptoHandlerSRTCP->ReceiverPacketIndexL();
    iCryptoHandlerSRTCP->DeriveSessionKeysL();

    EUNIT_ASSERT( iCryptoHandlerSRTCP->iSessionEncrKey->Compare(
                                    *iRFC3711_SessionEncrKey128bits) == 0);
    EUNIT_ASSERT( iCryptoHandlerSRTCP->iSessionSaltKey->Compare(
                                    *iRFC3711_SessionSaltKey128bits) == 0);
    EUNIT_ASSERT( iCryptoHandlerSRTCP->iSessionAuthKey->Compare(
                                    *iRFC3711_SessionAuthKey128bits) == 0);
    CleanupStack::PopAndDestroy(encSrtcpPacket);  	
	}
Ejemplo n.º 5
0
// -------------------------------------------------------
// fill
// -------------------------------------------------------
void HexGrid::fill() {
	assert(_items != 0);
	for (int r = 0; r < _rMax; r++) {
		int q_offset = r >> 1;
		for (int q = -q_offset; q < _qMax - q_offset; q++) {
			GridItem item;
			item.hex = Hex(q, r);
			item.position = hex_math::hex_to_pixel(_layout, item.hex);
			item.state = 0;
			item.bomb = false;
			item.adjacentBombs = 0;
			item.wiggle = false;
			item.timer = 0.0f;
			item.scale = v2(1, 1);
			//item.rotating = false;
			int idx = (q + q_offset) + r * _qMax;
			_items[idx] = item;
		}
	}
	_hover = -1;
}
 void UT_CSRTPCryptoHandlerSRTCP::UT_ReplayProtectionL4L( )  
 	{
 	//Set stored PktIndx number to bigger than the one in the sequence number
    //and outside the Replay window
    iCryptoHandlerSRTCP->iReplayPktIndex= KTestSeqNr65536;
    HBufC8* encSrtcpPacket1 =HBufC8::NewLC(KSRTCPPacket1().Length());
	*encSrtcpPacket1=KSRTCPPacket1;
    Hex(*encSrtcpPacket1);
    TInt len= KSRTCPPacket1().Length();
	encSrtcpPacket1->Des().SetLength(len/2);
        
    iCryptoHandlerSRTCP->InitializeEncryptedPacketL(*encSrtcpPacket1);
 	iCryptoHandlerSRTCP->ReceiverPacketIndexL();
             
    
    // do the replay protection 
    EUNIT_ASSERT_SPECIFIC_LEAVE( 
    	iCryptoHandlerSRTCP->ReplayProtectionL(), KErrArgument );
    
   	CleanupStack::PopAndDestroy(encSrtcpPacket1); 
 	}
Ejemplo n.º 7
0
void BucketTest::testBucketGeneration()
{
    BucketIdFactory factory;
    DocumentId doc1("doc:ns:spec");
    DocumentId doc2("doc:ns2:spec");
    DocumentId doc3("doc:ns:spec2");
    DocumentId userDoc1("userdoc:ns:18:spec");
    DocumentId userDoc2("userdoc:ns2:18:spec2");
    DocumentId userDoc3("userdoc:ns:19:spec");
    DocumentId groupDoc1("groupdoc:ns:yahoo.com:spec");
    DocumentId groupDoc2("groupdoc:ns2:yahoo.com:spec2");
    DocumentId groupDoc3("groupdoc:ns:yahoo:spec");
    DocumentId orderDoc1("orderdoc(31,19):ns:13:1268182861:foo");
    DocumentId orderDoc2("orderdoc(31,19):ns:13:1205110861:foo");
    DocumentId orderDoc3("orderdoc(31,19):ns:13:1205715661:foo");
    DocumentId orderDoc4("orderdoc(4,0):ns:13:2:foo");
    DocumentId orderDoc5("orderdoc(4,0):ns:13:4:foo");
    DocumentId orderDoc6("orderdoc(4,0):ns:13:11:foo");

    BucketId docBucket1(factory.getBucketId(doc1));
    BucketId docBucket2(factory.getBucketId(doc2));
    BucketId docBucket3(factory.getBucketId(doc3));
    BucketId userDocBucket1(factory.getBucketId(userDoc1));
    BucketId userDocBucket2(factory.getBucketId(userDoc2));
    BucketId userDocBucket3(factory.getBucketId(userDoc3));
    BucketId groupDocBucket1(factory.getBucketId(groupDoc1));
    BucketId groupDocBucket2(factory.getBucketId(groupDoc2));
    BucketId groupDocBucket3(factory.getBucketId(groupDoc3));
    BucketId orderDocBucket1(factory.getBucketId(orderDoc1));
    BucketId orderDocBucket2(factory.getBucketId(orderDoc2));
    BucketId orderDocBucket3(factory.getBucketId(orderDoc3));
    BucketId orderDocBucket4(factory.getBucketId(orderDoc4));
    BucketId orderDocBucket5(factory.getBucketId(orderDoc5));
    BucketId orderDocBucket6(factory.getBucketId(orderDoc6));

    CPPUNIT_ASSERT_EQUAL(Hex(0xe99703f200000012ull), Hex(userDocBucket1.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xebfa518a00000012ull), Hex(userDocBucket2.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xeac1850800000013ull), Hex(userDocBucket3.getRawId()));

    CPPUNIT_ASSERT_EQUAL(Hex(0xeae764e90000000dull), Hex(orderDocBucket1.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xeacb85f10000000dull), Hex(orderDocBucket2.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xea68ddf10000000dull), Hex(orderDocBucket3.getRawId()));

    CPPUNIT_ASSERT_EQUAL(Hex(0xe87526540000000dull), Hex(orderDocBucket4.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xea59f8f20000000dull), Hex(orderDocBucket5.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xe9eb703d0000000dull), Hex(orderDocBucket6.getRawId()));

    userDocBucket1.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000012ull), Hex(userDocBucket1.getId()));
    userDocBucket2.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000012ull), Hex(userDocBucket2.getId()));
    userDocBucket3.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000013ull), Hex(userDocBucket3.getId()));

    CPPUNIT_ASSERT_EQUAL(Hex(0xe90ce4b09a1acd50ull), Hex(groupDocBucket1.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xe9cedaa49a1acd50ull), Hex(groupDocBucket2.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xe8cdb18bafe81f24ull), Hex(groupDocBucket3.getRawId()));

    groupDocBucket1.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x400000000000cd50ull), Hex(groupDocBucket1.getId()));
    groupDocBucket2.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x400000000000cd50ull), Hex(groupDocBucket2.getId()));
    groupDocBucket3.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000001f24ull), Hex(groupDocBucket3.getId()));

    CPPUNIT_ASSERT_EQUAL(Hex(0xe980c9abd5fd8d11ull), Hex(docBucket1.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xeafe870c5f9c37b9ull), Hex(docBucket2.getRawId()));
    CPPUNIT_ASSERT_EQUAL(Hex(0xeaebe9473ecbcd69ull), Hex(docBucket3.getRawId()));

    docBucket1.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000008d11ull), Hex(docBucket1.getId()));
    docBucket2.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x40000000000037b9ull), Hex(docBucket2.getId()));
    docBucket3.setUsedBits(16);
    CPPUNIT_ASSERT_EQUAL(Hex(0x400000000000cd69ull), Hex(docBucket3.getId()));
}
Vector4::Vector4(char* hex){
	Hex(hex);
}
void UT_CSRTPCryptoHandlerSRTCP::SetupL(  )
    {
  	iDecryptedPayload = HBufC8::NewL(KDecryptedPayload().Length());
	*iDecryptedPayload = KDecryptedPayload;
	Hex(*iDecryptedPayload);

    iRFC3711_SessionEncrKey128bits = HBufC8::NewL(KRFC3711_SessionEncrKey128bits().Length());
	*iRFC3711_SessionEncrKey128bits = KRFC3711_SessionEncrKey128bits;
	Hex(*iRFC3711_SessionEncrKey128bits);

    iRFC3711_SessionSaltKey128bits = HBufC8::NewL(KRFC3711_SessionSaltKey128bits().Length());
	*iRFC3711_SessionSaltKey128bits = KRFC3711_SessionSaltKey128bits;
	Hex(*iRFC3711_SessionSaltKey128bits);

    iRFC3711_SessionAuthKey128bits = HBufC8::NewL(KRFC3711_SessionAuthKey128bits().Length());
	*iRFC3711_SessionAuthKey128bits = KRFC3711_SessionAuthKey128bits;
	Hex(*iRFC3711_SessionAuthKey128bits);
	
    
	iTestPayload160Bits = HBufC8::NewL(KTestPayload160Bits().Length());
	*iTestPayload160Bits = KTestPayload160Bits;	
	Hex(*iTestPayload160Bits);	
    
	iTestMKI128Bits = HBufC8::NewL(KTestMKI128Bits().Length());
	*iTestMKI128Bits = KTestMKI128Bits;	
	Hex(*iTestMKI128Bits);	

	iTestAuthTag80Bits = HBufC8::NewL(KTestAuthTag80Bits().Length());
	*iTestAuthTag80Bits = KTestAuthTag80Bits;	
	Hex(*iTestAuthTag80Bits);	
		
		
   HBufC8* masterKey = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
    CleanupStack::PushL( masterKey );
    *masterKey = KRFC3711_TestMasterKey128bits;
	
    
    
    HBufC8* masterSalt =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
    CleanupStack::PushL( masterSalt);
	*masterSalt = KRFC3711_TestMasterSalt112bits;
	
	
	HBufC8* mki =HBufC8::NewL(KTestMKI128Bits().Length());
    CleanupStack::PushL( mki);
	*mki = KTestMKI128Bits;
	Hex(*mki);
	
	iMasterKey = CSRTPMasterKey::NewL( *masterKey, *mki );
    iMasterSalt = CSRTPMasterSalt::NewL( *masterSalt );
    
    
    TSrtpCryptoParams params;
    iContext = CSRTPCryptoContext::NewL(iMasterKey, iMasterSalt, params );
    CleanupStack::PopAndDestroy( mki );
    CleanupStack::PopAndDestroy( masterSalt );
    CleanupStack::PopAndDestroy( masterKey ); 
    iDestination.Input(_L("127.0.0.1"));

    iSRTPSession = CSRTPSession::NewL( iDestination, iContext, *this ); 
    iStreamIn = CSRTPStreamIn::NewL(*iSRTPSession, 0xDEADBEEF);
  
    iCryptoHandlerSRTCP=  iStreamIn->iHandlerRTCP;   
    iReKeyCalled = EFalse; 
    } 
Ejemplo n.º 10
0
/*-------------------------------------------------------------------------------

    Class: Util

    Method: Hex

    Description: Prints hex dump of data to output.
    
    Parameters: const unsigned char* aData : in : Pointer to data to be output
	                                              as hex dump
                const int aLength          : in : The lenght of data

    Return Values: None

    Errors/Exceptions: None

-------------------------------------------------------------------------------*/
void Util::Hex(const unsigned char* aData, const int aLength)
{
	Hex((void *)aData, aLength);
}
Ejemplo n.º 11
0
/*-------------------------------------------------------------------------------

    Class: Util

    Method: Hex

    Description: Prints hex dump of char table to output.
    
    Parameters: const char aData[] : in : Data to be output as hex dump

    Return Values: None

    Errors/Exceptions: None

-------------------------------------------------------------------------------*/
void Util::Hex(const char aData[])
{
	string s(aData);
	Hex(s);
}
Ejemplo n.º 12
0
TEST(UtilitiesTest, testHMAC01) {
    //This test case is an official one from an RFC.
    uint8_t key[64];
    convertFromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", key, 20);
    uint8_t data[64];
    convertFromHex("4869205468657265", data, 8);

    uint8_t digest[32];

    HMAC_SHA256_Buf(key, 20, data, 8, digest);

    EXPECT_EQ(std::string("b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"), std::string(Hex(digest, 32)));
}
Ejemplo n.º 13
0
void GPIO::selectAltFunction(uint32_t pin, ALT alt)
{
	kout << INFO << "GPIO select pin "<< pin << " to ALT " << Hex(alt) << "\n";
	selectAltFunctionNoLog(pin, alt);
}
void UT_CSrtpAuthentication_RCC::SetupL(  )
    {

    iAuthenticator = CSrtpAuthentication_RCC::NewL();    

    iRFC2202_Test1_Key_160bits = HBufC8::NewL(KRFC2202_Test1_Key_160bits().Length());
    iRFC2202_Test1_Data_16bits = HBufC8::NewL(KRFC2202_Test1_Data_16bits().Length());
    iRFC2202_Test1_Tag_80bits = HBufC8::NewL(KRFC2202_Test1_Tag_80bits().Length());
    iRFC2202_Test1_Tag_32bits = HBufC8::NewL(KRFC2202_Test1_Tag_32bits().Length());

    iRFC2202_Test2_Key         = HBufC8::NewL(KRFC2202_Test2_Key().Length());
    iRFC2202_Test2_Data_28bits = HBufC8::NewL(KRFC2202_Test2_Data_28bits().Length());
    iRFC2202_Test2_Tag_80bits = HBufC8::NewL(KRFC2202_Test2_Tag_80bits().Length());
    iRFC2202_Test2_Tag_32bits = HBufC8::NewL(KRFC2202_Test2_Tag_32bits().Length());

    iRFC2202_Test3_Key_160bits = HBufC8::NewL(KRFC2202_Test3_Key_160bits().Length());
    iRFC2202_Test3_Data_400bits = HBufC8::NewL(KRFC2202_Test3_Data_400bits().Length());
    iRFC2202_Test3_Tag_80bits = HBufC8::NewL(KRFC2202_Test3_Tag_80bits().Length());
    iRFC2202_Test3_Tag_32bits = HBufC8::NewL(KRFC2202_Test3_Tag_32bits().Length());

    iRFC2202_Test4_Key_200bits = HBufC8::NewL(KRFC2202_Test4_Key_200bits().Length());
    iRFC2202_Test4_Data_400bits = HBufC8::NewL(KRFC2202_Test4_Data_400bits().Length());
    iRFC2202_Test4_Tag_80bits = HBufC8::NewL(KRFC2202_Test4_Tag_80bits().Length());
    iRFC2202_Test4_Tag_32bits = HBufC8::NewL(KRFC2202_Test4_Tag_32bits().Length());

    iRFC2202_Test5_Key_160bits = HBufC8::NewL(KRFC2202_Test5_Key_160bits().Length());
    iRFC2202_Test5_Data        = HBufC8::NewL(KRFC2202_Test5_Data().Length());
    iRFC2202_Test5_Tag_80bits = HBufC8::NewL(KRFC2202_Test5_Tag_80bits().Length());
    iRFC2202_Test5_Tag_32bits = HBufC8::NewL(KRFC2202_Test5_Tag_32bits().Length());

    iRFC2202_Test6_Key_640bits = HBufC8::NewL(KRFC2202_Test6_Key_640bits().Length());
    iRFC2202_Test6_Data_54bits = HBufC8::NewL(KRFC2202_Test6_Data_54bits().Length());
    iRFC2202_Test6_Tag_80bits = HBufC8::NewL(KRFC2202_Test6_Tag_80bits().Length());
    iRFC2202_Test6_Tag_32bits = HBufC8::NewL(KRFC2202_Test6_Tag_32bits().Length());

    iRFC2202_Test7_Key_640bits = HBufC8::NewL(KRFC2202_Test7_Key_640bits().Length());
    iRFC2202_Test7_Data_73bits = HBufC8::NewL(KRFC2202_Test7_Data_73bits().Length());
    iRFC2202_Test7_Tag_80bits = HBufC8::NewL(KRFC2202_Test7_Tag_80bits().Length());
    iRFC2202_Test7_Tag_32bits = HBufC8::NewL(KRFC2202_Test7_Tag_32bits().Length());
    iTest8_Key_160bits= HBufC8::NewL(KTest8_Key_160bits().Length());
    iTest8_Data_168bits= HBufC8::NewL(KTest8_Data_168bits().Length());
    iTest8_Data2_32bits= HBufC8::NewL(KTest8_Data2_32bits().Length());
    iTest8_Tag_80bits= HBufC8::NewL(KTest8_Tag_80bits().Length());

	*iRFC2202_Test1_Key_160bits = KRFC2202_Test1_Key_160bits;
	*iRFC2202_Test1_Data_16bits = KRFC2202_Test1_Data_16bits;
	*iRFC2202_Test1_Tag_80bits  = KRFC2202_Test1_Tag_80bits;
	*iRFC2202_Test1_Tag_32bits  = KRFC2202_Test1_Tag_32bits;

	*iRFC2202_Test2_Key         = KRFC2202_Test2_Key;
	*iRFC2202_Test2_Data_28bits = KRFC2202_Test2_Data_28bits;
	*iRFC2202_Test2_Tag_80bits  = KRFC2202_Test2_Tag_80bits;
	*iRFC2202_Test2_Tag_32bits  = KRFC2202_Test2_Tag_32bits;

	*iRFC2202_Test3_Key_160bits = KRFC2202_Test3_Key_160bits;
	*iRFC2202_Test3_Data_400bits = KRFC2202_Test3_Data_400bits;
	*iRFC2202_Test3_Tag_80bits  = KRFC2202_Test3_Tag_80bits;
	*iRFC2202_Test3_Tag_32bits  = KRFC2202_Test3_Tag_32bits;

    *iRFC2202_Test4_Key_200bits = KRFC2202_Test4_Key_200bits;
    *iRFC2202_Test4_Data_400bits = KRFC2202_Test4_Data_400bits;
    *iRFC2202_Test4_Tag_80bits  = KRFC2202_Test4_Tag_80bits;
    *iRFC2202_Test4_Tag_32bits  = KRFC2202_Test4_Tag_32bits;

    *iRFC2202_Test5_Key_160bits = KRFC2202_Test5_Key_160bits;
    *iRFC2202_Test5_Data        = KRFC2202_Test5_Data;
    *iRFC2202_Test5_Tag_80bits  = KRFC2202_Test5_Tag_80bits;
    *iRFC2202_Test5_Tag_32bits  = KRFC2202_Test5_Tag_32bits;

	*iRFC2202_Test6_Key_640bits = KRFC2202_Test6_Key_640bits;
	*iRFC2202_Test6_Data_54bits = KRFC2202_Test6_Data_54bits;
	*iRFC2202_Test6_Tag_80bits  = KRFC2202_Test6_Tag_80bits;
	*iRFC2202_Test6_Tag_32bits  = KRFC2202_Test6_Tag_32bits;

	*iRFC2202_Test7_Key_640bits = KRFC2202_Test7_Key_640bits;
	*iRFC2202_Test7_Data_73bits = KRFC2202_Test7_Data_73bits;
	*iRFC2202_Test7_Tag_80bits  = KRFC2202_Test7_Tag_80bits;
	*iRFC2202_Test7_Tag_32bits = KRFC2202_Test7_Tag_32bits;
	*iTest8_Key_160bits= KTest8_Key_160bits;
    *iTest8_Data_168bits= KTest8_Data_168bits;
    *iTest8_Data2_32bits= KTest8_Data2_32bits;
    *iTest8_Tag_80bits= KTest8_Tag_80bits;

	Hex(*iRFC2202_Test1_Key_160bits);
//	Hex(*iRFC2202_Test1_Data_16bits);
	Hex(*iRFC2202_Test1_Tag_80bits);
	Hex(*iRFC2202_Test1_Tag_32bits);

//	Hex(*iRFC2202_Test2_Key);
//	Hex(*iRFC2202_Test2_Data_28bits);
	Hex(*iRFC2202_Test2_Tag_80bits);
	Hex(*iRFC2202_Test2_Tag_32bits);
	iRFC2202_Test2_Tag_32bits->Des().SetLength(32/8);

	Hex(*iRFC2202_Test3_Key_160bits);
	Hex(*iRFC2202_Test3_Data_400bits);
	Hex(*iRFC2202_Test3_Tag_80bits);
	Hex(*iRFC2202_Test3_Tag_32bits);

	Hex(*iRFC2202_Test4_Key_200bits);
	Hex(*iRFC2202_Test4_Data_400bits);
	Hex(*iRFC2202_Test4_Tag_80bits);
	Hex(*iRFC2202_Test4_Tag_32bits);

	Hex(*iRFC2202_Test5_Key_160bits);
//	Hex(*iRFC2202_Test5_Data);
	Hex(*iRFC2202_Test5_Tag_80bits);
	Hex(*iRFC2202_Test5_Tag_32bits);

	Hex(*iRFC2202_Test6_Key_640bits);
//	Hex(*iRFC2202_Test6_Data_54bits);
	Hex(*iRFC2202_Test6_Tag_80bits);
	Hex(*iRFC2202_Test6_Tag_32bits);

	Hex(*iRFC2202_Test7_Key_640bits);
//	Hex(*iRFC2202_Test7_Data_73bits);
	Hex(*iRFC2202_Test7_Tag_80bits);
	Hex(*iRFC2202_Test7_Tag_32bits);
	
	Hex(*iTest8_Key_160bits);
	Hex(*iTest8_Data_168bits);
	
	Hex(*iTest8_Data2_32bits);

	Hex(*iTest8_Tag_80bits);
	iTest8_Tag_80bits->Des().SetLength(10);
    } 
 void UT_CSRTPCryptoHandlerSRTCP::UT_ReplayProtectionL3L( )   
 	{
 	//Set stored PktIndx number to bigger than the on in the sequence number
    //but inside the Replay window and it has been seen
     	
 	HBufC8* encSrtcpPacket1 =HBufC8::NewLC(KSRTCPPacket1().Length());
	*encSrtcpPacket1=KSRTCPPacket1;
    Hex(*encSrtcpPacket1);
    TInt len= KSRTCPPacket1().Length();
	encSrtcpPacket1->Des().SetLength(len/2);
	

    // do the authentication (integrity check)
    iCryptoHandlerSRTCP->InitializeEncryptedPacketL(*encSrtcpPacket1);
 	iCryptoHandlerSRTCP->ReceiverPacketIndexL();
 	iCryptoHandlerSRTCP->CheckMasterKeyIdentifierL();
             
    // derive session keys..
    iCryptoHandlerSRTCP->DeriveSessionKeysL();
    // do the replay protection 
    iCryptoHandlerSRTCP->ReplayProtectionL();
    
    iCryptoHandlerSRTCP->AuthenticateL();
    iCryptoHandlerSRTCP->AddReplayIndex();
    //EUNIT_ASSERT(iCryptoHandlerSRTP->iPktIndex == KTestSeqNr17); 
   	CleanupStack::PopAndDestroy(encSrtcpPacket1);  
    
    //Create the packet again so can check the Replay protection
            
	HBufC8* encSrtcpPacket2 =HBufC8::NewLC(KSRTCPPacket2().Length());
	*encSrtcpPacket2=KSRTCPPacket2;
    Hex(*encSrtcpPacket2);
    TInt len2= KSRTCPPacket2().Length();
	encSrtcpPacket2->Des().SetLength(len2/2);
    
    
        
    iCryptoHandlerSRTCP->InitializeEncryptedPacketL(*encSrtcpPacket2);
 
    iCryptoHandlerSRTCP->ReceiverPacketIndexL();
     
    iCryptoHandlerSRTCP->ReplayProtectionL();
    
    iCryptoHandlerSRTCP->AddReplayIndex(); 
    
   	CleanupStack::PopAndDestroy(encSrtcpPacket2);  	

	HBufC8* encSrtcpPacket3 =HBufC8::NewLC(KSRTCPPacket1().Length());
	*encSrtcpPacket3=KSRTCPPacket1;
    Hex(*encSrtcpPacket3);
    len= KSRTCPPacket1().Length();
	encSrtcpPacket1->Des().SetLength(len/2);
	

    // do the authentication (integrity check)
    iCryptoHandlerSRTCP->InitializeEncryptedPacketL(*encSrtcpPacket3);
 	iCryptoHandlerSRTCP->ReceiverPacketIndexL();
             
    // do the replay protection 
    EUNIT_ASSERT_SPECIFIC_LEAVE( iCryptoHandlerSRTCP->ReplayProtectionL(),
     KErrArgument );
    
   	CleanupStack::PopAndDestroy(encSrtcpPacket3);  
       	
     	}
Ejemplo n.º 16
0
void BucketTest::testReverseBucket()
{
    {
        BucketId id(0x3000000000000012ull);
        CPPUNIT_ASSERT_EQUAL(Hex(0x480000000000000cull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }

    {
        BucketId id(0x4000000000000012ull);
        CPPUNIT_ASSERT_EQUAL(Hex(0x4800000000000010ull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }

    {
        BucketId id(0x600000000000ffffull);
        CPPUNIT_ASSERT_EQUAL(Hex(0xffff000000000018ull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }

    {
        BucketId id(0x540000000001ffffull);
        CPPUNIT_ASSERT_EQUAL(Hex(0xffff800000000015ull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }

    {
        BucketId id(0xa80000000003ffffull);
        CPPUNIT_ASSERT_EQUAL(Hex(0xffffc0000000002aull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }

    {
        BucketId id(0xbc0000000007ffffull);
        CPPUNIT_ASSERT_EQUAL(Hex(0xffffe0000000002full), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }
    {
        BucketId id(0xcc0000000002ffffull);
        CPPUNIT_ASSERT_EQUAL(Hex(0xffff400000000033ull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }
    {
        BucketId id(0xebffffffffffffffull);
        CPPUNIT_ASSERT_EQUAL(Hex(0xfffffffffffffffaull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }
    {
        BucketId id(0xeaaaaaaaaaaaaaaaull);
        CPPUNIT_ASSERT_EQUAL(Hex(0x555555555555557aull), Hex(id.toKey()));
        CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
    }
}
int enableMMU()
{
	// provided by linker script, must be placed in RAM, because they need to be writeable, typical setting is : L0Table spans 4KB,L1Table spans the successive 4KB,and L0Table must start at a 4KB boundary.
	extern RegDescriptor4KBL0 L0Table[];
	extern RegDescriptor4KBL1 L1Table[];
	// must be at EL1
	auto curEl = RegCurrentEL::read();
	if(curEl.EL != 1)
	{
		kout << FATAL << " Not at EL1 \n";
		return 1;
	}
	// set SPSel to 1
	RegSPSel spsel{0};
	spsel.SP = 1;
	spsel.write();

	// set exception vector of EL1
	extern char ExceptionVectorEL1[];
	RegVBAR_EL1 vbar;
	vbar.Addr = reinterpret_cast<uint64_t>(ExceptionVectorEL1);
	vbar.write();

	// determine PARange
	auto aa64 = RegID_AA64MMFR0_EL1::read();
	aa64.dump();
	if(aa64.TGran4 != 0b0000)
	{
		kout << FATAL << "4KB granule is not supported\n";
		return 1;
	}

	int paBitsMap[]=   {32,  36,  40,  42,  44,  48,  52};
	int indexBitsMap[]={2,   6,   1,   3,   5,   9,   INT32_MAX};
//	int levelsMap[]=   {3,   3,   4,   4,   4,   4,   INT32_MAX};
	int initLevelMap[]={1,   1,   0,   0,   0,   0,   INT32_MAX};
//	int tnszMap[]=     {32,  28,  24,  22,  20,  16,  INT32_MAX};
	if(aa64.PARange >= arrsizeof(paBitsMap))
	{
		kout << FATAL << "PARange not supported\n";
		return 1;
	}
	int effPARange = aa64.PARange;
	if(paBitsMap[effPARange] == 52 )
	{
		kout << INFO << "PARange is 52, we need to reduce it to 48\n";
		--effPARange;
	}

	if(initLevelMap[effPARange] != 0)
	{
		kout << FATAL << "Initial level not at 0,which this program designed for specifically.";
		return 1;
	}


	auto tcr = RegTCR_EL1::read();
	// disable address tag
	tcr.TBI0 = tcr.TBI1 = 0;
	// set output address size,same with PARange
	tcr.IPS = effPARange & 0b0111;// reserve lower 3 bits
	// set input address size, TxSZ is the most significant bits
	tcr.T0SZ = tcr.T1SZ = 64 - paBitsMap[effPARange];
	tcr.A1 = 0; //ASID is in ttbr0
	tcr.TG0 = 0b00;//TTBR0 4KB
	tcr.TG1 = 0b10;//TTBR1 4KB
	tcr.SH0 = tcr.SH1 = 0b10;//outer shareable
	tcr.IRGN0 = tcr.IRGN1 = 0b01;//inner cacheable
	tcr.ORGN0 = tcr.ORGN1 =0b01;// outer cacheable
	tcr.EPD0 = tcr.EPD1 = 0; // not disable page walk on TLB miss

	tcr.write();

	// memory attribute
	// peri: DevicenGnRnE,Execute Never,Not Shared,(auto)noncacheable,privileged
	// flash and others:Normal,Read/Write,Shared,Cacheable
	//   ram: + unprivileged
	//   flash: + privileged
	//    peri: +privileged
	// mair--> 0:device, 0x00, 1:normal, 0xff  2:normal,non-cacheable,0x44
	RegMAIR_EL1 mair{0};
	mair.Attr0 = 0x00; // Device-nGnRnE
	mair.Attr1 = 0xff; //Normal
	mair.Attr3 = 0x44; // Normal,Non-Cacheable
//	mair.Attr3 = ; //Normal, read only
	mair.write();



	// initial level resolves (9-extra) bits
	// every following level resolves 9 bits, the lower 12 bits are flatten mapped
//	int levelsNeeded = (paBitsMap[effPARange] - 12)/9;

	// make sure that this section is placed at the lowest 4KB, so that it can be successfully flatten mapped.That is, mainEnd <= 4KB
	// because we just use L1 as block descriptor,so it allows more that 12 bits of flatten mapping, i.e. at least 12+9 = 21 bits

	extern char mainEnd[];
	if( (reinterpret_cast<size_t>(mainEnd) >> 30) >= 1) // >1GB, overflows
	{
		kout << FATAL << "end of main overflows, meaning that it may not be flatten mapped.\n";
		return 1;
	}

	// There is alignment requirement of translation table address
	// translation table's lower 12 bits must be 0


	// we have simplified the condition, by promising that L0Index=L1Index=0, L1 is a block descriptor, whose output address is 0
	// use the preallocated memory in the RAM.
	RegDescriptor4KBL0 & descrL0 = L0Table[0];
	descrL0.IsTable = 1;
	descrL0.Valid = 1;
	descrL0.RES0 = 0;
	descrL0.NSTable = 0;// non-secure, res0,also ignored.TODO test if 1 is working
	descrL0.NextLevelTableAddr = ( reinterpret_cast<uint64_t>(L1Table) & upperMaskBits(64-12)) >> 12;
	descrL0.APTable = 0b00; // no effect on permissions
	descrL0.PXNTable = 0;//no effect
	descrL0.XNTable = 0 ;// no effect
	descrL0.Ignored_0=0;
	descrL0.Ignored_1=0;


	// map RAM
//	RegDescriptor4KBL0 & descrRAML0 = L0Table[0];
//	descrL0.IsTable = 1;
//	descrL0.Valid = 1;
//	descrL0.RES0 = 0;
//	descrL0.NextLevelTableAddr = (L1Table >> 12);

	// map peri.



	// starts at next level
	// not all are read-only, the PERIPHABSE is writeable
	RegDescriptor4KBL1 & descrL1= L1Table[0];
	descrL1.S0.IsTable=0;
	descrL1.S0.NS=1;
	descrL1.S0.OutputAddr = (0 >> 30); //VA[29:0] = OA[29:0]
	descrL1.S0.AF = 1; // if AF=0, the first access will generate a fault
	descrL1.S0.AttrIndex = 1;// normal memory
	descrL1.S0.Valid = 1;
	descrL1.S0.PXN = 0;
	descrL1.S0.UXN = 0;
	descrL1.S0.Contiguous = 1;
	descrL1.S0.nG = 0; // apply to all ASID
	// no AP[0], AP[2]=0:read-write 1:read-only  AP[1]= can be access from EL0
//	descrL1.S0.AP = 0b01; // read-write, also from EL0
	descrL1.S0.AP = 0b00;
	descrL1.S0.NS = 1; // non-secure
	descrL1.S0.SH = 0b10; //outer-shareable
	descrL1.S0.Ignored = 0;
	descrL1.S0.RES0_0=0;
	descrL1.S0.RES0_1=0;
	descrL1.S0.Reserved=0;

	// RAM starts from 1GB
	L1Table[1] = L1Table[0]; // all the same, except the following changes
	L1Table[1].S0.AP = 0b00;
	L1Table[1].S0.OutputAddr = (0x40000000 >> 30);

	// currently, TTBR0 is flatten mapped
	RegTTBR0_EL1 ttbr0 {0};

	// original : TTBR[47:12], modified: TTBR[47:12-extraBits]
	//  that is, originally, ttbr.BADDR's lower 11bits are 0,now its number reduces by extraBits
	int extraBits = 9 - indexBitsMap[effPARange]; // extraBits
	(void)extraBits;
//	ttbr0.BADDR = reinterpret_cast<uint64_t>(L0Table) & upperMaskBits(63 - (12-extraBits)+1) >> 1;// keep bits[63:(12-extraBits)]
//	ttbr0.BADDR = 0x400; // level 3 fault
//	ttbr0.BADDR = 0x40; // level 3
//	ttbr0.BADDR = 0x4; // level 2 fault
	ttbr0.BADDR = reinterpret_cast<uint64_t>(L0Table)>>1;
	ttbr0.ASID = 0;
	ttbr0.CnP = 0;

//	uint64_t & lttbr0 = *reinterpret_cast<uint64_t*>(&ttbr0);
//	lttbr0 = reinterpret_cast<uint64_t>(L0Table);

	RegTTBR1_EL1 ttbr1 {0};
	ttbr1.BADDR = ttbr0.BADDR;
	ttbr1.ASID = 0;
	ttbr1.CnP = 0;

	ttbr0.write();
	ttbr1.write();
	asm_isb();// seen by following instructions


	// dump information
	kout << "L0Table = " << Hex(reinterpret_cast<uint64_t>(L0Table)) << "\n";
	kout << "L1Table = " << Hex(reinterpret_cast<uint64_t>(L1Table)) << "\n";
	ttbr0.updateRead();
	ttbr0.dump();
	ttbr1.updateRead();
	ttbr1.dump();

	tcr.updateRead();
	tcr.dump();

	L0Table[0].dump();
	L1Table[0].dump();
	RegSCTLR_EL1::read().dump();


	if(RegID_AA64MMFR1_EL1::read().PAN == 0)
	{
		kout << INFO << "PAN not supported\n";
	}else{
		// this may fail,because architechure does not support armv8.1-PAN
		RegPAN::read().dump();
	}

	// test it, not working before enabling MMU
	// Stage1, EL1,as if read from that address
//	__asm__ __volatile__("at S1E1R,%0 \n\t"::"r"(mainEnd));
//	RegPAR_EL1::read().dump();

	// SMPEN
//	__asm__("MRS X0, S3_1_C15_C2_1 \n\t"
//			"ORR X0, X0, #(0x1 << 6) \n\t" // The SMP bit.
//			"MSR S3_1_C15_C2_1, X0 \n\t"
//			);

	// enable it
	auto sctl = RegSCTLR_EL1::read();
	sctl.EE = 0;//little endian
	sctl.E0E = 0;
	sctl.WXN = 0; // no effect,XNs normal
	sctl.I = 1;
	sctl.SA = 0;
	sctl.SA0 = 0;
	sctl.C = 1;
	sctl.A = 0;
	sctl.M = 1;
	sctl.write();
//	__asm__("DSB SY \n\t");
	asm_isb();
	sctl.updateRead();
	sctl.dump();

	kout << INFO << "Successfully set TTBR0\n";
	// change vbar to ttbr1
	vbar.Addr |= upperMaskBits(tcr.T1SZ);
	vbar.write();


	RegPC pc{0};
	extern char afterMMUSet[];
	kout << INFO << "afterMMUSet = ";
	kout << Hex(reinterpret_cast<uint64_t>(afterMMUSet))<<"\n";
	kout << INFO << "mainEnd = " ;
	kout << Hex(reinterpret_cast<uint64_t>(mainEnd))<<"\n";

	// set the upper tcr.T1SZ bits to 1,so TTBR1 is used
	pc.PC = reinterpret_cast<uint64_t>(afterMMUSet) | upperMaskBits(tcr.T1SZ);
	pc.write(); // just jump to the next instruction, but TTBR0 is changed to TTBR1

	// 设置栈值为高端地址
	__asm__ __volatile__(
			"mov x0,sp \n\t"
			"orr x0,x0,%0 \n\t"
			"mov sp,x0 \n\t"
			"orr x29,x29, %0 \n\t"::"r"(upperMaskBits(tcr.T1SZ)):"sp","x0");

	// define a local symbol:afterMMUSet
	ASM_DEFINE_LOCAL_SYM(afterMMUSet);//if local,3b38, wrong value
	kout << INFO << "Successfully enabled MMU\n";
	kout << INFO << "end enableMMU.\n";


	ASM_DEFINE_LOCAL_SYM(mainEnd);

	return 0;
}
Ejemplo n.º 18
0
static bool FmtH2B( char *src, uint width, char PGM *dst, int len, PTYPE typ ) {
//==============================================================================

    char        ch1;
    byte        ch2;
    bool        valid;
    char        *stop;

#if defined( _M_IX86 ) || defined( __AXP__ ) || defined( __PPC__ )
#else
    typ = typ;
#endif
    pgm_memset( dst, 0, len );
    if( width >= 2 * len ) {
        len *= 2;
        src += width - len;
    } else {
        len = width;
    }
    stop = src + len;
    ch1 = '0';
    if( ( len & 1 ) == 0 ) {
        ch1 = *src;
        src++;
    }
    ch2 = *src;
    src++;
#if defined( _M_IX86 ) || defined( __AXP__ ) || defined( __PPC__ )
    if( typ != PT_CHAR ) {
        ++len;
        len &= ~1;
        len /= 2;
        dst += len - 1;
    }
#endif
    for(;;) {
        valid = false;
        if( !isxdigit( ch1 ) ) {
            if( ch1 != ' ' ) break;
            ch1 = '0';
        }
        if( !isxdigit( ch2 ) ) {
            if( ch2 != ' ' ) break;
            ch2 = '0';
        }
        valid = true;
        *dst = ( Hex( ch1 ) << 4 ) + Hex( ch2 );
#if defined( _M_IX86 ) || defined( __AXP__ ) || defined( __PPC__ )
        if( typ == PT_CHAR ) {
            ++dst;
        } else {
            --dst;
        }
#else
        dst++;
#endif
        if( src == stop ) break;
        ch1 = *src;
        src++;
        ch2 = *src;
        src++;
    }
    return( valid );
}
Ejemplo n.º 19
0
v3 HexGrid::convert(int q, int r) const {
	Hex hex = Hex(q, r);
	v2 position = hex_math::hex_to_pixel(_layout, hex);
	return v3(position.x, 0.0f, position.y);
}
int main()
{
	VirtioDriver vio(VIRTIO_0_BASE);
	vio.init();

	kout << "Magic value is " << Hex(vio.reg32<VirtioDriver::V2_MagicValue>()) << "\n";
	kout << "Version = " << vio.reg32<VirtioDriver::V2_Version>() << "\n";
	kout << "VendorID = " << Hex(vio.reg32<VirtioDriver::V2_VendorID>()) << "\n";
	kout << "DeviceID = " << Hex(vio.reg32<VirtioDriver::V2_DeviceID>()) << "\n";
	kout << "HostFeatures = " << Hex(vio.reg32<VirtioDriver::V1_HostFeatures>()) << "\n";
	kout << "GuestPageSize = " << Hex(vio.reg32<VirtioDriver::V1_GuestPageSize>()) << "\n";
	kout << "DeviceStatus = " << Hex(vio.reg32<VirtioDriver::V1_Status>()) << "\n";
	kout << "QueueNumMax = " << vio.reg32<VirtioDriver::V1_QueueNumMax>() << "\n";


	auto blkConf = vio.regcopy<VirtioBlockConfig,VirtioDriver::V1_Config>();
	blkConf.dump();

//	return 0;

	// 至少包含2个对齐的PAGE
	char queueBuffer[VirtioDriver::PAGE_SIZE_4KB*3];
	// 对齐处的地址
	uint64_t pageAddr = alignAhead(reinterpret_cast<uint64_t>(queueBuffer),VirtioDriver::PAGE_SIZE_4KB);

	// legacy需要3个,[0]=8byte,3fields, [1]=data,[2]=1byte status
	size_t descrNum = 4;
	uint16_t startDescrIndex=1;
	constexpr size_t readBytes =
//			3
			// 512*3-1  // invalid
			512*3 // 必须是512的n倍
			;
	// qsize
	// mem_size
	//
	VirtioQueueLayout vq(reinterpret_cast<void*>(pageAddr),descrNum,VirtioDriver::USED_RING_ALIGNMENT);

	auto memSize = vq.memSize();
	kout << "virtqueue memSize = " << memSize << "\n";
	// 应当清0
	std::memset(vq.queueBase(), 0, memSize);

	// reqeust
	size_t blkNum = 1;
	size_t reqBufSize = VirtioBlockRequestRef::memSize(blkNum);
	if(reqBufSize >= readBytes + 512)
	{
		kout << FATAL << "req size overflows\n";
		return 1;
	}

	// 至少包含readBytes个
	char reqBuf[readBytes+512];

	VirtioBlockRequestRef vreq(reqBuf,blkNum,VirtioBlockRequestRef::REQ_IN,0);
	const char * invalidStr = "if you see this, then it is invalid\n";
	std::memcpy(vreq.data(),invalidStr,std::strlen(invalidStr));


	VirtioQueueDescriptor * descs[3];
	vq.allocateDescriptros(descs, 3);
	vq.chainDescriptors(descs, 3);
//	descs[0]

	// DW = DeviceWriteOnly,DR = DeviceReadOnly
	// [0]=header,DR,[1]=status,DW[2]=empty buffer,DW
	// or
	// [0] = header + status + empty buffer, DW
	// 前一个用于legacy模式
	auto descTable = vq.descTable();
	new (&descTable[startDescrIndex]) VirtioQueueDescriptor(reinterpret_cast<uint64_t>(vreq.base()),16,bitOnes<VirtioQueueDescriptor::VIRTQ_DESC_F_NEXT>(),startDescrIndex+1);
	new (&descTable[startDescrIndex+1]) VirtioQueueDescriptor(descTable[startDescrIndex+1].addr() + 16,readBytes,bitOnes<VirtioQueueDescriptor::VIRTQ_DESC_F_NEXT,VirtioQueueDescriptor::VIRTQ_DESC_F_WRITE>(),startDescrIndex+2);
	new (&descTable[startDescrIndex+2]) VirtioQueueDescriptor(descTable[startDescrIndex+2].addr() + readBytes,1,bitOnes<VirtioQueueDescriptor::VIRTQ_DESC_F_WRITE>(),0);

	// 注意, old_idx和new_idx之间的差值就是本次请求的数目
	auto & avRef = vq.availRing();
	avRef.idx(1); //
	avRef.ring()[0]=startDescrIndex;// header
//	avRef.ring()[1]=startDescrIndex + 1;
	/*
	下面这些寄存器只写
	case VIRTIO_MMIO_DEVICE_FEATURES_SEL:
    case VIRTIO_MMIO_DRIVER_FEATURES:
    case VIRTIO_MMIO_DRIVER_FEATURES_SEL:
    case VIRTIO_MMIO_GUEST_PAGE_SIZE:
    case VIRTIO_MMIO_QUEUE_SEL:
    case VIRTIO_MMIO_QUEUE_NUM:
    case VIRTIO_MMIO_QUEUE_ALIGN:
    case VIRTIO_MMIO_QUEUE_NOTIFY:
    case VIRTIO_MMIO_INTERRUPT_ACK:

	// 下面这些寄存器只读
    case VIRTIO_MMIO_MAGIC_VALUE:
    case VIRTIO_MMIO_VERSION:
    case VIRTIO_MMIO_DEVICE_ID:
    case VIRTIO_MMIO_VENDOR_ID:
    case VIRTIO_MMIO_DEVICE_FEATURES:
    case VIRTIO_MMIO_QUEUE_NUM_MAX:
    case VIRTIO_MMIO_INTERRUPT_STATUS:

	 */
/*
 *
		The virtual queue is configured as follows:
		1. Select the queue writing its index (first queue is 0) to QueueSel.
		2. Check if the queue is not already in use: read QueuePFN, expecting a returned value of zero (0x0).
		3. Read maximum queue size (number of elements) from QueueNumMax. If the returned value is zero
		(0x0) the queue is not available.
		4. Allocate and zero the queue pages in contiguous virtual memory, aligning the Used Ring to an optimal boundary (usually page size). The driver should choose a queue size smaller than or equal to
		QueueNumMax.
		5. Notify the device about the queue size by writing the size to QueueNum.
		6. Notify the device about the used alignment by writing its value in bytes to QueueAlign.
		7. Write the physical number of the first page of the queue to the QueuePFN register.
 *
 *
 */
	vio.reg32<VirtioDriver::V1_QueueSel>() = 0; // set current
	vio.reg32<VirtioDriver::V1_QueueNum>()=descrNum; // set current queue size
	vio.reg32<VirtioDriver::V1_QueuePFN>() = pageAddr / VirtioDriver::PAGE_SIZE_4KB; // 设置PFN

	// notify index 0 completed
	vio.reg32<VirtioDriver::V1_QueueNotify>()=0; // which queue?

	// wait to complete
	delayCPU(1000*1000);

	kout << "=====read data is \n";
	kout.print(reinterpret_cast<const char*>(vreq.data()),readBytes);
	kout << "\n=================\n";

	/*

	 Historically, many drivers ignored the len value, as a result, many devices set len incorrectly. Thus, when
using the legacy interface, it is generally a good idea to ignore the len value in used ring entries if possible.
Specific known issues are listed per device type.

 	 对于block device,
 	 When using the legacy interface, transitional drivers SHOULD ignore the len value in used ring entries.
Note: Historically, some devices put the total descriptor length, or the total length of device-writable buffers
there, even when only the status byte was actually written.
	也就是说,legacy 模式下的len应当忽略
	在实践中,len返回的总是readBytes + 1,因此应当忽略。

	 */
	// 读取usedRing
	// 同样,old_idx和new_idx之间的差值也体现了本次完成的数目
	auto &usedRingRef = vq.usedRing();
	kout << "used ring idx = " << usedRingRef.idx() << "\n";
	kout << "ring[0]{id,len} = " << usedRingRef.ring()[0]._id  << "," << usedRingRef.ring()[0]._len<< "\n";
//	kout << "ring[1]{id,len} = " << usedRingRef.ring()[1]._id  << "," << usedRingRef.ring()[1]._len<< "\n";

	return 0;
}
Ejemplo n.º 21
0
Archivo: ogg.c Proyecto: Erikhht/TCPMP
static bool_t OGMHeader(ogg* p, oggstream* s, const char* Data, int Length )
{
	int i;
	if (Length<40 || (*Data & PACKET_TYPE_BITS) != PACKET_TYPE_HEADER)
		return 0;

	if (strncmp(Data+1, "Direct Show Samples embedded in Ogg", 35) == 0)
	{
		// old header

		if (INT32LE(*(int32_t*)(Data+96)) == 0x05589F80)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_VIDEO;
			s->Stream.Format.Format.Video.Width = INT32LE(*(int32_t*)(Data+176));
			s->Stream.Format.Format.Video.Height = INT32LE(*(int32_t*)(Data+180));
			s->Stream.Format.Format.Video.Pixel.FourCC = INT32LE(*(int32_t*)(Data+68));
			s->Stream.Format.Format.Video.Pixel.BitCount = INT16LE(*(int16_t*)(Data+182));

			i = INT16LE(*(int16_t*)(Data+136));	// extrasize
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+142,s->Stream.Format.ExtraLength);

			s->MediaRateDen = INT64LE(*(int32_t*)(Data+164))*TICKSPERSEC;
			s->MediaRateNum = 10000000;
			s->DefaultLen = 1;

			FrameRate(&s->Stream.Format.PacketRate,s->MediaRateNum,s->MediaRateDen/TICKSPERSEC);
			return 1;
		}

		if (INT32LE(*(int32_t*)(Data+96)) == 0x05589F81)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_AUDIO;
			s->Stream.Format.Format.Audio.Format = INT16LE(*(int16_t*)(Data+124));
			s->Stream.Format.Format.Audio.Channels = INT16LE(*(int16_t*)(Data+126));
			s->Stream.Format.Format.Audio.BlockAlign = INT16LE(*(int16_t*)(Data+136));
			s->Stream.Format.Format.Audio.Bits = INT16LE(*(int16_t*)(Data+138));
			s->Stream.Format.Format.Audio.SampleRate = INT32LE(*(int32_t*)(Data+128));
			s->Stream.Format.ByteRate = INT32LE(*(int32_t*)(p+132));

			i = INT16LE(*(int16_t*)(Data+136));	// extrasize
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+142,s->Stream.Format.ExtraLength);

			s->MediaRateDen = TICKSPERSEC;
			s->MediaRateNum = INT32LE(*(int32_t*)(Data+128));
			s->DefaultLen = 1;
			return 1;
		}
	}
	else
	if (Length >= sizeof(ogm_header)+1)
	{
		ogm_header Head;
		memcpy(&Head,Data+1,sizeof(Head));

		// new header
		if (strncmp(Head.streamtype, MT_Video, strlen(MT_Video)) == 0)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_VIDEO;
			s->Stream.Format.Format.Video.Width = INT32LE(Head.format.video.width);
			s->Stream.Format.Format.Video.Height = INT32LE(Head.format.video.height);
			s->Stream.Format.Format.Video.Pixel.FourCC = INT32LE(*(int32_t*)Head.subtype);
			s->Stream.Format.Format.Video.Pixel.BitCount = INT16LE(Head.bits_per_sample);

			s->MediaRateDen = INT64LE(Head.time_unit)*TICKSPERSEC;
			s->MediaRateNum = INT64LE(Head.samples_per_unit) * 10000000;
			s->DefaultLen = INT32LE(Head.default_len);

			FrameRate(&s->Stream.Format.PacketRate,s->MediaRateNum,s->MediaRateDen/TICKSPERSEC);
			i = Length - (sizeof(ogm_header)+1);
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+1+sizeof(ogm_header),s->Stream.Format.ExtraLength);
			return 1;
		}
		
		if (strncmp(Head.streamtype, MT_Audio, strlen(MT_Audio)) == 0)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_AUDIO;
			s->Stream.Format.Format.Audio.Format = 0;
			for (i=0;i<4;++i)
				if (Head.subtype[i])
					s->Stream.Format.Format.Audio.Format = s->Stream.Format.Format.Audio.Format*16+Hex(Head.subtype[i]);
			s->Stream.Format.Format.Audio.Channels = INT16LE(Head.format.audio.channels);
			s->Stream.Format.Format.Audio.Bits = INT16LE(Head.bits_per_sample);
			s->Stream.Format.Format.Audio.BlockAlign = INT16LE(Head.format.audio.blockalign);
			s->Stream.Format.ByteRate = INT32LE(Head.format.audio.avgbytespersec);
			s->Stream.Format.Format.Audio.SampleRate = (int)INT64LE(Head.samples_per_unit);

			s->MediaRateDen = INT64LE(Head.time_unit)*TICKSPERSEC;
			s->MediaRateNum = INT64LE(Head.samples_per_unit) * 10000000;
			s->DefaultLen = INT32LE(Head.default_len);

			i = Length - (sizeof(ogm_header)+1);
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+1+sizeof(ogm_header),s->Stream.Format.ExtraLength);
			return 1;
		}

		if (strncmp(Data+1, MT_Text,  strlen(MT_Text)) == 0)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_SUBTITLE;
			s->Stream.Format.Format.Subtitle.FourCC = SUBTITLE_OEM; //???

			s->MediaRateDen = INT64LE(Head.time_unit)*TICKSPERSEC;
			s->MediaRateNum = INT64LE(Head.samples_per_unit) * 10000000;
			s->DefaultLen = INT32LE(Head.default_len);

			i = Length - (sizeof(ogm_header)+1);
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+1+sizeof(ogm_header),s->Stream.Format.ExtraLength);
			return 1;
		}
	}

	return 0;
}
Ejemplo n.º 22
0
void Pdb::Sync0(Thread& ctx, Frame *single_frame)
{
	if(!single_frame) {
		stop = false;
	
		framelist.Clear();
		frame.Clear();
		current_frame = NULL;
	}

	STACKFRAME64 stackFrame = {0};
	
	stackFrame.AddrPC.Mode = stackFrame.AddrFrame.Mode = stackFrame.AddrStack.Mode = AddrModeFlat;
	DWORD machineType = IMAGE_FILE_MACHINE_I386;
	void *c;
#ifdef CPU_64
	if(win64) {
		machineType = IMAGE_FILE_MACHINE_AMD64;
		stackFrame.AddrPC.Offset = ctx.context64.Rip;
		stackFrame.AddrFrame.Offset = ctx.context64.Rbp;
		stackFrame.AddrStack.Offset = ctx.context64.Rsp;
		c = &ctx.context64;
	}
	else
#endif
	{
		machineType = IMAGE_FILE_MACHINE_I386;
		stackFrame.AddrPC.Offset = ctx.context32.Eip;
		stackFrame.AddrFrame.Offset = ctx.context32.Ebp;
		stackFrame.AddrStack.Offset = ctx.context32.Esp;
		c = &ctx.context32;
	}

	DWORD64 lastFrame = 0; // Prevent loops with optimised stackframes
	int fc = -1;
	while(::StackWalk64(machineType, hProcess, ctx.hThread, &stackFrame, c,
	      0, ::SymFunctionTableAccess64, ::SymGetModuleBase64, 0)) {
	    if(stackFrame.AddrPC.Offset == 0 || lastFrame >= stackFrame.AddrFrame.Offset) {
			LLOG("Invalid stack frame");
			break;
	    }
		lastFrame = stackFrame.AddrFrame.Offset;
		LLOG("PC: " << Hex(stackFrame.AddrPC.Offset));
		Frame& f = single_frame ? *single_frame : frame.Add();
		f.pc = stackFrame.AddrPC.Offset;
		f.frame = stackFrame.AddrFrame.Offset;
		f.stack = stackFrame.AddrStack.Offset;
		f.fn = GetFnInfo(f.pc);
		String r;
		if(IsNull(f.fn.name)) {
			if(single_frame)
				return;
			r = Hex(f.pc);
			for(int i = 0; i < module.GetCount(); i++) {
				const ModuleInfo& m = module[i];
				if(f.pc >= m.base && f.pc < m.base + m.size) {
					r << " (" << GetFileName(m.path) << ")";
					break;
				}
			}
		}
		else {
			GetLocals(f, ctx, f.param, f.local);
			if(single_frame)
				return;
			r = f.fn.name;
			r << '(';
			for(int i = 0; i < f.param.GetCount(); i++) {
				if(i)
					r << ", ";
				r << f.param.GetKey(i) << "=" << Visualise(f.param[i]).GetString();
			}
			r << ')';
			if(fc < 0)
				fc = frame.GetCount() - 1;
		}
		framelist.Add(frame.GetCount() - 1, r);
	}
	framelist <<= max(fc, 0);
}
Ejemplo n.º 23
0
/*-------------------------------------------------------------------------------

    Class: Util

    Method: Hex

    Description: Prints hex dump of string to output.
    
    Parameters: const string& aMsg : in : Data to be output as hex dump

    Return Values: None

    Errors/Exceptions: None

-------------------------------------------------------------------------------*/
void Util::Hex(const string& aMsg)
{
	Hex((const unsigned char *)aMsg.c_str(), aMsg.length());
}
Ejemplo n.º 24
0
Archivo: Map.cpp Proyecto: mwhiter/hex
	Tile* HexMap::getTile(int q, int r, int s) const {
		return getTile(Hex(q, r, s));
	}
Ejemplo n.º 25
0
/*-------------------------------------------------------------------------------

    Class: Util

    Method: Hex

    Description: Prints hex dump of data to output.
    
    Parameters: void *aData       : in : Pointer to data to be output as hex dump
                const int aLength : in : The lenght of data

    Return Values: None

    Errors/Exceptions: None

-------------------------------------------------------------------------------*/
void Util::Hex(void *aData, const int aLength)
{
	Hex(aData, aLength, NULL);
}
Ejemplo n.º 26
0
/** When selecting a single PID from the demux, we get PES out (not TS).
 *
 * For audio purposes, we must demux that and get ES (which is what an MP2
 * file is).
 */
unsigned int AudioStream::Read(void *buffer, size_t len, size_t *pread)
{
#if 0 /* Uncomment this to see what the raw stream is like */
    ssize_t res = ::read(m_fd, buffer, len);
    if (res < 0)
        return errno;
    *pread = res;
    return 0;
#endif

    if (m_eslen == 0)
    {
        do {
            if (!m_started)
            {
                // Look for PES packet signature

                do {
                    if (m_fill < BUFFER)
                    {
                        ssize_t rc = ::read(m_fd, m_buffer + m_fill,
                                            BUFFER - m_fill);
                        if (rc < 0)
                        {
                            if (errno != EWOULDBLOCK)
                                TRACE << "Read error in AudioStream "
                                      << errno << "\n";
//			    else
//				LOG(TV) << "EWOULDBLOCK (starting)\n";

                            return errno;
                        }

                        if (rc == 0)
                        {
                            TRACE << "EOF in AudioStream\n";
                            *pread = 0;
                            return 0;
                        }

//			LOG(TV) << "Read " << rc << " bytes in AudioStream\n";

                        m_fill += (unsigned)rc;
                    }

                    const unsigned char *prefix = (const unsigned char*)
                                                  memchr(m_buffer, '\0', m_fill - 4);
                    if (prefix)
                    {
                        if (prefix[1] == 0 && prefix[2] == 1)// && prefix[3] == 0xC0)
                        {
                            TRACE << "Found PES sync (" << prefix[3] << ")\n";
                            m_fill -= (unsigned)(prefix - m_buffer);
                            memmove(m_buffer, prefix, (unsigned int)m_fill);
                            m_started = true;
                        }
                        else
                        {
                            // Fake sync
                            m_fill -= (unsigned)(prefix + 1 - m_buffer);
                            memmove(m_buffer, prefix + 1, (unsigned int)m_fill);
                        }
                    }
                    else
                    {
                        // No sync at all
                        m_fill = 0;
                    }
                } while (!m_started);
            }

            // PES packet signature is at start of buffer
            while (m_fill < 32)
            {
                ssize_t rc = ::read(m_fd, m_buffer + m_fill, BUFFER - m_fill);
                if (rc < 0)
                {
                    if (errno != EWOULDBLOCK)
                        TRACE << "Read error in AudioStream " << errno << "\n";
//		    else
//			LOG(TV) << "EWOULDBLOCK (running)\n";

                    if (errno != EOVERFLOW)
                        return errno;
                }
                else if (rc == 0)
                {
                    TRACE << "EOF in AudioStream\n";
                    *pread = 0;
                    return 0;
                }
                else
                {
//		TRACE << "Read " << rc << " bytes in AudioStream\n";
                    m_fill += (unsigned)rc;
                }
            }

//	    TRACE << "m_fill now " << m_fill << "\n";

            if (m_pes_packet_remaining == 0)
            {
                if (m_buffer[0] != 0 || m_buffer[1] != 0 || m_buffer[2] != 1)
                {
                    TRACE << "Lost PES sync\n" << util::Hex(m_buffer, 32);
                    m_started = false;
                }
            }
        } while (!m_started);

        if (m_pes_packet_remaining == 0)
        {
            // Start of packet
//	    unsigned int streamid = m_buffer[3];
            unsigned int packlen = m_buffer[4]*256 + m_buffer[5] + 6;
            unsigned int peshlen = m_buffer[8] + 9;
//	    TRACE << "id=" << streamid << " packlen=" << packlen << " peshlen=" << peshlen << "\n" << Hex(m_buffer, 16);
            if (peshlen > 32) // Sanity check
            {
                TRACE << "Clipping oversize header!\n";
                peshlen = 32;
            }

            m_esdata = m_buffer + peshlen;
            m_eslen = m_fill - peshlen;
            m_pes_packet_remaining = packlen - peshlen;
            if (m_eslen > m_pes_packet_remaining)
                m_eslen = m_pes_packet_remaining;
        }
        else
        {
            m_esdata = m_buffer;
            m_eslen = m_fill;
            if (m_eslen > m_pes_packet_remaining)
                m_eslen = m_pes_packet_remaining;
        }

        assert(m_pes_packet_remaining >= m_eslen);

        m_pes_packet_remaining -= m_eslen;
    }

    if (len > m_eslen)
        len = m_eslen;

//    LOG(TV) << "Returning " << len << "\n";

    memcpy(buffer, m_esdata, len);
    m_esdata += len;
    m_eslen -= (unsigned)len;

    if (m_eslen == 0)
    {
        m_fill -= (unsigned)(m_esdata - m_buffer);
//	TRACE << "Shuffling " << m_fill << "\n";
        memmove(m_buffer, m_esdata, m_fill);
    }

    *pread = len;
    return 0;

#if 0
    TRACE << "In read, eslen=" << m_eslen << " ppr=" << m_pes_packet_remaining
          << "\n";
    if (!m_eslen)
    {
        unsigned int prefill = 0;

        do {
            int rc = ::read(m_fd, m_buffer + prefill, TS_PACKET - prefill);
            if (rc < 0)
            {
                TRACE << "Read error in AudioStream " << errno << "\n";
                return errno;
            }

            if (rc == 0)
            {
                TRACE << "EOF in AudioStream\n";
                *pread = 0;
                return 0;
            }

            TRACE << "Read " << rc << " bytes in AudioStream\n";

            if (m_buffer[0] != 0x47)
            {
                TRACE << "Bogus start-of-packet\n" << Hex(m_buffer, TS_PACKET);
                unsigned char *byte47 = (unsigned char*)memchr(m_buffer, 0x47,
                                        TS_PACKET);
                if (byte47)
                {
                    prefill = TS_PACKET - (byte47 - m_buffer);
                    TRACE << "0x47 found at " << (byte47-m_buffer)
                          << " prefill is " << prefill << "\n";
                    memmove(m_buffer, byte47, prefill);
                }
                continue;
            }

            if (!m_started && ((m_buffer[1] & 0x40) != 0))
                m_started = true;

            prefill = 0;

        } while (!m_started);

        bool adaptation = (m_buffer[3] & 0x20) != 0;

        const unsigned char *pesdata;
        unsigned int peslen;

        if (adaptation)
        {
            unsigned int alen = m_buffer[4];
            pesdata = m_buffer + 5 + alen;
            peslen = TS_PACKET - alen - 5;
        }
        else
        {
            pesdata = m_buffer + 5;
            peslen = TS_PACKET - 4;
        }

        if (m_pes_packet_remaining == 0)
        {
            // Start of packet
            unsigned int packlen = pesdata[4]*256 + pesdata[5] + 6;
            unsigned int peshlen = pesdata[8];
            TRACE << "packlen=" << packlen << " peshlen=" << peshlen << "\n";
            m_esdata = pesdata + peshlen + 9;
            m_eslen = peslen - peshlen - 9;
            m_pes_packet_remaining = packlen - peshlen - 9;
        }
        else
        {
            m_esdata = pesdata;
            m_eslen = peslen;
            if (m_eslen > m_pes_packet_remaining)
                m_eslen = m_pes_packet_remaining;
        }

        m_pes_packet_remaining -= m_eslen;
    }

    if (len > m_eslen)
        len = m_eslen;

    memcpy(buffer, m_esdata, len);
    m_esdata += len;
    m_eslen -= len;
    *pread = len;
    return 0;
#endif
}