Exemplo n.º 1
0
 MifarePlusKey::MifarePlusKey(const std::string& str, size_t keySize)
     : Key()
 {
     InitKey(keySize);
     clear();
     fromString(str);
 }
Exemplo n.º 2
0
bool cCamCryptNagra::MakeSessionKey(unsigned char *out, const unsigned char *camdata)
{
  if(!hasMod) return false;
  if(LOG(L_SC_PROC)) {
    unsigned char bb[64];
    camMod.Put(bb,sizeof(bb));
    LDUMP(L_SC_PROC,bb,sizeof(bb),"Sessionkey negotiation CAMMOD:");
    }
  //decrypt $2A data here and prepare $2B reply
  if(rsa.RSA(out,camdata,64,camExp,camMod)!=64) return false;
  LDUMP(L_SC_PROC,out,64,"CMD 2A/26 after RSA:");

  unsigned char key[16], sess[16];
  InitKey(key,signature,cardid);
  LDUMP(L_SC_PROC,key,16,"first IDEA key: ");
  Signature(sess,key,out,32);
  memcpy(key,sess,8);
  memcpy(key+8,sess,8);
  LDUMP(L_SC_PROC,key,16,"second IDEA key:");
  Signature(sess+8,key,out,32);
  LDUMP(L_SC_PROC,sess,16,"SESSION KEY:    ");
  idea.SetDecKey(sess,&sessKey);

  if(rsa.RSA(out,out,64,camExp,camMod)!=64) return false;
  LDUMP(L_SC_PROC,out,64,"CMD 2B/27 data:");
  return true;
}
Exemplo n.º 3
0
//初期化
HRESULT DirectInput::Init()
{


	//DirectInputオブジェクトの作成
	//hresultにはFAILED/SUCCEEDED等で真偽を確かめるのに使うもの
	HRESULT hresult = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&pDInput, NULL);
	if (FAILED(hresult))
	{
		return hresult;
	}

	//キーボード初期化処理
	hresult = InitKey();
	if (FAILED(hresult))
	{
		return hresult;
	}

	//マウス初期化
	hresult = InitMouse();
	if (FAILED(hresult))
	{
		return hresult;
	}

	return S_OK;
	
}
Exemplo n.º 4
0
logical sAction :: DBInitialize ( )
{

  InitKey("extern_id","Action");

  return(NO);
}
Exemplo n.º 5
0
bool cCamCryptNagra::DecryptDT08(const unsigned char *dt08, unsigned int irdid, cBN *irdmod, bool fakeid)
{
  if(LOG(L_SC_PROC)) {
    unsigned char bb[64];
    irdmod->Put(bb,sizeof(bb));
    LDUMP(L_SC_PROC,bb,sizeof(bb),"DT08 decrypt IRDID: %08x IRDMOD:",irdid);
    }
  unsigned char buff[72];
  if(rsa.RSA(buff,dt08+1,64,camExp,*irdmod)!=64) return false;
  memcpy(buff+64,dt08+1+64,8);
  buff[63]|=dt08[0]&0x80;
  LDUMP(L_SC_PROC,buff,72,"DT08 after RSA");

  unsigned char key[16];
  InitKey(key,boxkey,irdid);
  LDUMP(L_SC_PROC,key,16,"DT08 IDEA key");
  IdeaKS dks;
  idea.SetDecKey(key,&dks);
  idea.Decrypt(buff,72,&dks,0);
  LDUMP(L_SC_PROC,buff,72,"DT08 after IDEA");

  memcpy(signature,buff,8);
  LDUMP(L_SC_PROC,signature,8,"signature");
  BYTE4_BE(buff  ,0);
  BYTE4_BE(buff+4,fakeid?0xFFFFFFFF:cardid);
  Signature(buff,key,buff,72);
  LDUMP(L_SC_PROC,buff,8,"check sig");
  if(memcmp(signature,buff,8)) {
    PRINTF(L_SC_PROC,"DT08 signature failed");
    return false;
    }
  BN_bin2bn(buff+8,64,camMod);
  hasMod=true;
  return true;
}
Exemplo n.º 6
0
void CScript::InitBase()
{
	ADDTOCALLSTACK("CScript::InitBase");
	m_iLineNum		= 0;
	m_fSectionHead	= false;
	m_lSectionData	= 0;
	InitKey();
}
Exemplo n.º 7
0
int main( int argc, char *argv[] )
{
    InitKey();


    //PLAYING
    //byte_t attack[28] = { 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
    //    'a','a','d','m','i','n','a','t','r','u','e','\0' };
    char attack[1] = {'\0'};
    
    size_t mida;
    byte_t *eData = CreateInfoString( attack, &mida );
    printf("mida:%lu\n",mida);
    printf("dimCorr:%d\n",!(mida%16));


    byte_t *temp = malloc(mida);
    
    int i;

    for( i = 0; i < 16; i++ ) {
            temp[i] = eData[i];
    }

    for( i = 1; i < ( mida/16 - 1 ) ; i++ ) {
        int j;
        for( j = 0; j < 16; j++ ) {
            temp[16*i+j] = 0;
        }

    }

    for( i = 0; i < 16; i++ ) {
            temp[ i + (mida-16) ] = eData[i];
    }


    int err = ErrorFound( temp, mida );
    printf("Error found:%d\n",err);

    byte_t ivf[16];

    for( i = 0; i < 16; i++ ) ivf[i] = temp[i]^temp[ i + (mida-16) ];

    if( !memcmp( IV, ivf, 16 ) ) {
        printf("IV was the key\n");
        for( i = 0; i < 16; i++ ) printf("%02X",ivf[i]);
        printf("\n");
    } else {
        printf("IV was not the key or smth else has gone wrong\n");
    }


    return 0;
}
Exemplo n.º 8
0
/****************************************************************************
* 程序入口函数
****************************************************************************/
void main(void)
{
    InitLed();		      //设置LED1相应的IO口
    InitKey();            //设置S1相应的IO口
    
    while(1)
    {
        if (KeyScan())    //按键按下则改变LED状态
            LED1 = ~LED1;       
    }
}
Exemplo n.º 9
0
static INLINE
IMG_HANDLE FindHandle(PVRSRV_HANDLE_BASE *psBase,
		      IMG_VOID *pvData,
		      PVRSRV_HANDLE_TYPE eType,
		      IMG_HANDLE hParent)
{
	HAND_KEY aKey;

	PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);

	InitKey(aKey, psBase, pvData, eType, hParent);

	return (IMG_HANDLE) HASH_Retrieve_Extended(psBase->psHashTab, aKey);
}
Exemplo n.º 10
0
int main( int argc, char *argv[] )
{
    int rlines;
    char **in = ReadFile( "./input/is2c4.txt", 1, &rlines );
    byte_t *dec;
    int st = B64StringToBytes( &dec, in[0] );
    free(in[0]);
    free(in);

    InitKey();

    byte_t *result = BreakECBFixedKey( dec, st );

    printf("DECRYPTED STRING:\n%s\n",result);
    return 0;
}
Exemplo n.º 11
0
    MifarePlusKey::MifarePlusKey(const void* buf, size_t buflen, size_t keySize)
        : Key()
    {
        InitKey(keySize);
        clear();

        if (buf != NULL)
        {
            if (buflen >= d_keySize)
            {
                memcpy(d_key, buf, d_keySize);
                d_isEmpty = false;
            }
        }
        getLength();
    }
void ClientKey(mpz_t KPri[3])
{
    mpz_t LKey[6];
    InitKey(LKey);

    for(int i = 0; i < 3; i++)
    {
        mpz_init(KPri[i]);
    }

    getPriKey(KPri, LKey);

    for(int i = 0; i < 6; i++)
    {
        mpz_clear(LKey[i]);
    }
}
Exemplo n.º 13
0
int zkd_main (int scorelimit, int timelimit, const char* ciphertext)
{
    LoadStringMessage(ciphertext);

    srand(time(0));

    /*setup directories*/

    StopSolve();

    memset(&siSolveInfo,0,sizeof(SOLVEINFO));
    siSolveInfo.ioc_weight=siSolveInfo.ent_weight=siSolveInfo.chi_weight=5;
    siSolveInfo.dioc_weight=0;
    siSolveInfo.max_tabu=300;
    siSolveInfo.swaps=5;
    siSolveInfo.max_tol=40;
    siSolveInfo.disp_all=DispAll;
    siSolveInfo.disp_info=DispInfo;

    sprintf(siSolveInfo.log_name,"/%s","log.txt");
    siSolveInfo.optima_tabu=&tabu_list;
    SetInfo(&siSolveInfo);
    Reset();
	
	siSolveInfo.time_limit = timelimit;
	siSolveInfo.score_limit = scorelimit;
	siSolveInfo.iteration_limit = -1;

    //language
    iLang=0;
    SetLanguage();


    //sovle parameters
    message.SetBlockSize(1);

    //SetSolveTypeFeatures();

    InitKey();

    Solve();
    
    return siSolveInfo.best_score;
}
Exemplo n.º 14
0
nsresult
Classifier::Open(nsIFile& aCacheDirectory)
{
  nsresult rv;

  mCryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Ensure the safebrowsing directory exists.
  rv = aCacheDirectory.Clone(getter_AddRefs(mStoreDirectory));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = mStoreDirectory->AppendNative(NS_LITERAL_CSTRING("safebrowsing"));
  NS_ENSURE_SUCCESS(rv, rv);

  bool storeExists;
  rv = mStoreDirectory->Exists(&storeExists);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!storeExists) {
    rv = mStoreDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755);
    NS_ENSURE_SUCCESS(rv, rv);
  } else {
    bool storeIsDir;
    rv = mStoreDirectory->IsDirectory(&storeIsDir);
    NS_ENSURE_SUCCESS(rv, rv);
    if (!storeIsDir)
      return NS_ERROR_FILE_DESTINATION_NOT_DIR;
  }

  rv = InitKey();
  if (NS_FAILED(rv)) {
    // Without a usable key the database is useless
    Reset();
    return NS_ERROR_FAILURE;
  }

  mTableFreshness.Init();
  // XXX: Disk IO potentially on the main thread during startup
  RegenActiveTables();

  return NS_OK;
}
Exemplo n.º 15
0
void main(void)
{
	uchar Key_Value;  //读出的键值		
	InitLed();
	InitKey();
	while(1)
	{
		P0 = 0xf0;//亮P0 = 0xff闪
                 //P1 = 0xff;			
		if(P0 != 0xf0)
		{
			Delay_1ms(15);	//按键消抖
			if(P0 != 0xf0)
			{
				Key_Value = Keyscan();		
			}
		}	         
		P1 = table[Key_Value % 16];		//显示低位键值		
		Delay_1ms(5);
	}
}
Exemplo n.º 16
0
static PVRSRV_ERROR FreeHandleDataWrapper(IMG_HANDLE hHandle, IMG_VOID *pvData)
{
	PVRSRV_HANDLE_BASE *psBase = (PVRSRV_HANDLE_BASE *)pvData;
	HANDLE_DATA *psHandleData = IMG_NULL;
	PVRSRV_ERROR eError;

	if (psBase == IMG_NULL)
	{
		PVR_DPF((PVR_DBG_ERROR, "FreeHandleDataWrapper: Handle base missing"));
		return PVRSRV_ERROR_INVALID_PARAMS;
	}

	eError = GetHandleData(psBase, 
			       &psHandleData, 
			       hHandle, 
			       PVRSRV_HANDLE_TYPE_NONE);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "FreeHandleDataWrapper: Couldn't get handle data for handle"));
		return eError;
	}

	if (!TEST_ALLOC_FLAG(psHandleData, PVRSRV_HANDLE_ALLOC_FLAG_MULTI))
	{
		HAND_KEY aKey;
		IMG_HANDLE hRemovedHandle;

		InitKey(aKey, psBase, psHandleData->pvData, psHandleData->eType, ParentIfPrivate(psHandleData));

		hRemovedHandle = (IMG_HANDLE)HASH_Remove_Extended(psBase->psHashTab, aKey);

		PVR_ASSERT(hRemovedHandle != IMG_NULL);
		PVR_ASSERT(hRemovedHandle == psHandleData->hHandle);
		PVR_UNREFERENCED_PARAMETER(hRemovedHandle);
	}

	OSFreeMem(psHandleData);

	return PVRSRV_OK;
}
Exemplo n.º 17
0
int32_t main(void)
{
#ifdef DEBUG_PRINT
    /* Initialize UART printf function (printf via UART0) */
    Uart_Io_Init();
#endif
     
#ifdef DEBUG_PRINT
    printf("******************************************************************************************\n\r");
    printf("*        QPRC Revolution Counter example with ZIN trigger mode     *\n\r");
    printf("******************************************************************************************\n\n\r");

    printf("Connect RTO00_0 with AIN0_0, and ZIN0_0 with P14\n\r");
    printf("If active edge of ZIN is detected, PC count clears to 0 and RC count adds by 1 \n\n\r");
#endif
 
    InitWfg();
    InitOcu();
    InitFrt();
    InitKey();
    InitZinTrig();
    InitQprc();
    
    /*Start FRT operation */
    Mft_Frt_Start(&USER_FRT, USER_FRT_CH);

    /*Start OCU operation */
    Mft_Ocu_EnableOperation(&USER_OCU, USER_OCU_CH0);
    Mft_Ocu_EnableOperation(&USER_OCU, USER_OCU_CH1);

    while(1)
    {
        if (0 != m_u8PcMatchFlag)
        {
        #ifdef DEBUG_PRINT
            printf("The count of Position Counter matchs with compare value!\n");      
        #endif          
            m_u8PcMatchFlag = 0;
        }

        if (0 != m_u8PcOfFlag)
        {
        #ifdef DEBUG_PRINT
            printf("The count of Position Counter overflows!\n");      
        #endif   
            m_u8PcOfFlag = 0;
        }

        if (0 != m_u8PcUfFlag)
        {
        #ifdef DEBUG_PRINT
            printf("The count of Position Counter underflows!\n");      
        #endif    
            m_u8PcUfFlag = 0;
        }

        if (0 != m_u8RcMatchFlag)
        {
        #ifdef DEBUG_PRINT
            printf("The count of Revolution Counter matchs!\n");      
        #endif  
            m_u8RcMatchFlag = 0;
        }

        if (FALSE == GetKey())
        {
            ZinTrigGen();
        }
    }
}
Exemplo n.º 18
0
/*!
******************************************************************************

 @Function	AllocHandle

 @Description	Allocate a new handle

 @Input		phHandle - location for new handle
		pvData - pointer to resource to be associated with the handle
		eType - the type of resource
		hParent - parent handle or IMG_NULL

 @Output	phHandle - points to new handle

 @Return	Error code or PVRSRV_OK

******************************************************************************/
static PVRSRV_ERROR AllocHandle(PVRSRV_HANDLE_BASE *psBase,
				IMG_HANDLE *phHandle,
				IMG_VOID *pvData,
				PVRSRV_HANDLE_TYPE eType,
				PVRSRV_HANDLE_ALLOC_FLAG eFlag,
				IMG_HANDLE hParent)
{
	HANDLE_DATA *psNewHandleData;
	IMG_HANDLE hHandle;
	PVRSRV_ERROR eError;

	/* PVRSRV_HANDLE_TYPE_NONE is reserved for internal use */
	PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);
	PVR_ASSERT(psBase != IMG_NULL && psBase->psHashTab != IMG_NULL);
	PVR_ASSERT(gpsHandleFuncs);

	if (!TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_MULTI))
	{
		/* Handle must not already exist */
		PVR_ASSERT(FindHandle(psBase, pvData, eType, hParent) == IMG_NULL);
	}

	psNewHandleData = OSAllocZMem(sizeof(*psNewHandleData));
	if (psNewHandleData == IMG_NULL)
	{
		PVR_DPF((PVR_DBG_ERROR, "AllocHandle: Couldn't allocate handle data"));
		return PVRSRV_ERROR_OUT_OF_MEMORY;
	}

	eError = gpsHandleFuncs->pfnAcquireHandle(psBase->psImplBase, &hHandle, psNewHandleData);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "AllocHandle: Failed to acquire a handle"));
		goto ErrorFreeHandleData;
	}

	/*
	 * If a data pointer can be associated with multiple handles, we
	 * don't put the handle in the hash table, as the data pointer
	 * may not map to a unique handle
	 */
	if (!TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_MULTI))
	{
		HAND_KEY aKey;

		/* Initialise hash key */
		InitKey(aKey, psBase, pvData, eType, hParent);

		/* Put the new handle in the hash table */
		if (!HASH_Insert_Extended(psBase->psHashTab, aKey, (IMG_UINTPTR_T)hHandle))
		{
			PVR_DPF((PVR_DBG_ERROR, "AllocHandle: Couldn't add handle to hash table"));
			eError = PVRSRV_ERROR_UNABLE_TO_ADD_HANDLE;
			goto ErrorReleaseHandle;
		}
	}

	psNewHandleData->hHandle = hHandle;
	psNewHandleData->eType = eType;
	psNewHandleData->eFlag = eFlag;
	psNewHandleData->pvData = pvData;
	psNewHandleData->ui32Refs = 1;

	InitParentList(psNewHandleData);
#if defined(DEBUG)
	PVR_ASSERT(NoChildren(psNewHandleData));
#endif

	InitChildEntry(psNewHandleData);
#if defined(DEBUG)
	PVR_ASSERT(NoParent(psNewHandleData));
#endif

	/* Return the new handle to the client */
	*phHandle = psNewHandleData->hHandle;

	return PVRSRV_OK;

ErrorReleaseHandle:
	(IMG_VOID)gpsHandleFuncs->pfnReleaseHandle(psBase->psImplBase, hHandle, IMG_NULL);

ErrorFreeHandleData:
	OSFreeMem(psNewHandleData);

	return eError;
}
Exemplo n.º 19
0
/*!
******************************************************************************

 @Function	FreeHandle

 @Description	Free a handle data structure.

 @Input		psBase - Pointer to handle base structure
		hHandle - Handle to be freed
		eType - Type of the handle to be freed
		ppvData - Location for data associated with the freed handle

 @Output 		ppvData - Points to data that was associated with the freed handle

 @Return	PVRSRV_OK or PVRSRV_ERROR

******************************************************************************/
static PVRSRV_ERROR FreeHandle(PVRSRV_HANDLE_BASE *psBase,
			       IMG_HANDLE hHandle,
			       PVRSRV_HANDLE_TYPE eType,
			       IMG_VOID **ppvData)
{
	HANDLE_DATA *psHandleData = IMG_NULL;
	HANDLE_DATA *psReleasedHandleData;
	PVRSRV_ERROR eError;

	eError = GetHandleData(psBase, &psHandleData, hHandle, eType);
	if (eError != PVRSRV_OK)
	{
		return eError;
	}

	PVR_ASSERT(psHandleData->ui32Refs>0);

	psHandleData->ui32Refs--;
	if (psHandleData->ui32Refs > 0)
	{
		/* Reference count still positive, only possible for shared handles */
		PVR_ASSERT(TEST_ALLOC_FLAG(psHandleData, PVRSRV_HANDLE_ALLOC_FLAG_SHARED));
		return PVRSRV_OK;
	}
	/* else reference count zero, time to clean up */

	if (!TEST_ALLOC_FLAG(psHandleData, PVRSRV_HANDLE_ALLOC_FLAG_MULTI))
	{
		HAND_KEY aKey;
		IMG_HANDLE hRemovedHandle;

		InitKey(aKey, psBase, psHandleData->pvData, psHandleData->eType, ParentIfPrivate(psHandleData));

		hRemovedHandle = (IMG_HANDLE)HASH_Remove_Extended(psBase->psHashTab, aKey);

		PVR_ASSERT(hRemovedHandle != IMG_NULL);
		PVR_ASSERT(hRemovedHandle == psHandleData->hHandle);
		PVR_UNREFERENCED_PARAMETER(hRemovedHandle);
	}

	eError = UnlinkFromParent(psBase, psHandleData);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,
			 "FreeHandle: Error whilst unlinking from parent handle (%s)", 
			 PVRSRVGetErrorStringKM(eError)));
		return eError;
	}

	/* Free children */
	eError = IterateOverChildren(psBase, psHandleData, FreeHandleWrapper);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,
			 "FreeHandle: Error whilst freeing subhandles (%s)",
			 PVRSRVGetErrorStringKM(eError)));
		return eError;
	}

	eError = gpsHandleFuncs->pfnReleaseHandle(psBase->psImplBase, psHandleData->hHandle, (IMG_VOID **)&psReleasedHandleData);
	if (eError == PVRSRV_OK)
	{
		PVR_ASSERT(psReleasedHandleData == psHandleData);
	}

	if (ppvData)
	{
		*ppvData = psHandleData->pvData;
	}

	OSFreeMem(psHandleData);

	return eError;
}
Exemplo n.º 20
0
int zkd_main_file(int argc, char** argv)
{
	if (argc != 2 && argc != 4)
	{
		printf("Usage:\n");
		printf("%s filename [(-t | -s | -i) n]\n", argv[0]);
		printf("-t n limits runtime to n seconds\n");
		printf("-s n limits solution score to n\n");
		printf("-i n limits solution to n iterations\n");
		printf("If no limit options are given, solver will run for 2 minutes\n");
	}
	LoadMessage(argv[1], 0);
	
	srand(time(0));
	
	/*setup directories*/
	
	StopSolve();
	
	memset(&siSolveInfo,0,sizeof(SOLVEINFO));
	siSolveInfo.ioc_weight=siSolveInfo.ent_weight=siSolveInfo.chi_weight=5;
	siSolveInfo.dioc_weight=0;
	siSolveInfo.max_tabu=300;
	siSolveInfo.swaps=5;
	siSolveInfo.max_tol=40;
	siSolveInfo.disp_all=DispAll;
	siSolveInfo.disp_info=DispInfo;
	
	sprintf(siSolveInfo.log_name,"/%s","log.txt");
	siSolveInfo.optima_tabu=&tabu_list;
	SetInfo(&siSolveInfo);
	Reset();
	
	if (argc == 4)
	{
		if (!strcmp(argv[2], "-t"))
		{
			siSolveInfo.time_limit = atoi(argv[3]);
			siSolveInfo.iteration_limit = -1;
			siSolveInfo.score_limit = -1;
		}
		else if (!strcmp(argv[2], "-s"))
		{
			siSolveInfo.score_limit = atoi(argv[3]);
			siSolveInfo.iteration_limit = -1;
			siSolveInfo.time_limit = -1;
		}
		else if (!strcmp(argv[2], "-i"))
		{
			siSolveInfo.iteration_limit = atoi(argv[3]);
			siSolveInfo.time_limit = -1;
			siSolveInfo.score_limit = -1;
		}
	}
	else if (argc == 2)
	{
		siSolveInfo.time_limit = 120;
		siSolveInfo.iteration_limit = -1;
		siSolveInfo.score_limit = -1;
	}
	
	//language
	iLang=0;
	SetLanguage();
	
	
	//sovle parameters
	message.SetBlockSize(1);
	
	//SetSolveTypeFeatures();
	
	InitKey();
	
	Solve();
	
	return siSolveInfo.best_score;
}
Exemplo n.º 21
0
//int main(void) __attribute__((noreturn)); // Main never returns so don't waste stack space on it.
int main(void)
{
  Uint16 TempInt;


  // Set up the I/O lines

  DDRA = PortDirA;
  DDRB = PortDirB;
  SD_PowerOn();
  DDRC = PortDirC;
  DDRD = PortDirD;

  PINA = PortPullUpA;
  PINB = PortPullUpB;
  PINC = PortPullUpC;
  PIND = PortPullUpD;

  //set the channel is the keyboard.
  //mp3 init finish ,after reset the slave board have volume;
  SetBit(SelAPort, Sel0A);
  SetBit(SelAPort, Sel1A);
  SetBit(SelBPort, Sel0B);
  SetBit(SelBPort, Sel1B);
  SetBit(SelCPort, Sel0C);
  SetBit(SelCPort, Sel1C);
  LastError = 0;            // Indicate no errors yet

  // Init the peripherals

  Timer_Init();                               // Set up timers
  UART_Init();
  InitKey();
  BCMessageInit(BCAMP3Contoller);

  wdt_enable(WDTO_8S);//wdt 8s
  // Set up key vars

  UART_Rx(CmdRxBuf, 1);
  Track         = 1;
  IdleTime      = 0;
  FlashPhase    = 0;
  Volume        = 0;
  PreMuteVolume = 0;
  Ramp          = NoRamp;
  LastKey       = 0;
  for(Bay = LeftBay; Bay <= NoBay; Bay++) {
    BayProduct[Bay] = UnknownProduct;
    BaySource[Bay]  = 0xff;
  }
  Bay           = LeftBay;
  SlaveMode     = false;
  SlaveModePara = 0;
  sei();      // Enable global interrupts

  // Print product build banner

  wdt_reset();
  UART_TxStr("\r\n======================================\r\n031-517-202 ");
  UART_TxChar('0' + SWVerMajor);
  UART_TxChar('.');
  UART_TxChar('0' + SWVerMinor);
  UART_TxChar('.');
  UART_TxChar('0' + SWVerFix);
  UART_TxChar(' ');
  UART_TxStr(__TIME__);
  UART_TxChar(' ');
  UART_TxStr(__DATE__);
  UART_TxStr("\r\n======================================\r\n");

  // For reset the slave board maybe volume very high so have noise
  // so first set volume is 0

  wdt_reset();
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCALeftBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCACenterBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCARightBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg

  // Test the LEDs while bays boot up

  DelayMS(100);                     // Allow some time for keypad to boot up
  UART_TxStr("Testing LEDs\r\n");
  for (TempInt = 1; TempInt <= 2; TempInt++){
    for (Key = 1; Key <= MaxKey; Key++) {
      if(!SetLamp(Key)){
        SlaveMode = true;
        break;
      }
      DelayMS(250);
      wdt_reset();//feed the watchdog
    }
    if(SlaveMode)
      break;
  }

  // Show version number

  if(!SlaveMode){
    SetLamps(0);
    DelayMS(1000);
    SetLamps(LeftLEDs | SWVerMajor);
    DelayMS(2000);
    wdt_reset();
    SetLamps(RightLEDs | SWVerMinor);
    DelayMS(2000);
    wdt_reset();
    SetLamps(LeftLEDs | RightLEDs | SWVerFix);
    DelayMS(2000);
    wdt_reset();
  }

  // Load EEPROM settings

  SetLamp(1);
  LoadEEPROMSetting();
  UART_TxStr("Settings:\r\n");
  PrintSettings();


  //wait for tablet ready wait 60 seconds
  if(SlaveMode)
  {
    UART_TxStr("Wait for tablet ready\r\n");
    for(TempInt = 0; TempInt < 6000; TempInt++)
    {
      DelayMS(10);
      CheckForBoardMsg();
      wdt_reset();
    }
  }
  // Prepare MP3 decoder for work

  wdt_reset();       // Feed the watchdog
  DelayMS(500);
  SetLamp(4);
  Timer_Clear();
  for (TempInt = 1; TempInt <= 5; TempInt++) {
    if (MP3_Init())
      break;          // If init ok exit loop
    wdt_reset();      // Feed the watchdog
    DelayMS(250);     // Wait before trying again
  }
  MP3_Volume(250);
  UART_TxStr("MP3 init time = ");
  UART_TxNum(Timer_Read(), 1);
  UART_TxStr("mS\r\n");

  // Find the last track on the card
  wdt_reset();
  SetLamp(3);
  for (Tracks = 1; Tracks <= 99; Tracks++) {
    if (!MP3_OpenFile(Tracks))
      break;
  }
  Tracks--;

  SetBassTreble();  // Set the audio curve


  // Determine what is connected

  wdt_reset();
  SetLamp(2);
  SearchDevices();

  if(!SlaveMode)
  {
    ConfigDevices();    // Configure connected devices

    SetIdleState();
    MP3_Track(1);
    if (!InputPresent[MP3In])       // If no MP3 player display error
      ShowError(ErrorNoMP3, false);
  }

  UART_TxStr("Start up complete\r\n");

  //
  // Enter the main loop
  //

  Timer_Clear();
  SlaveModeTimerClear();
  for( ; ; ) {              // Run forever
    if (SlaveMode) {        // In slave mode only handle slave mode messages
      CheckForBoardMsg();
      if(SlaveModeTimerRead() > 5000)
      {
        UART_TxNum(SlaveModeTimerRead(),5);
        UART_TxStr("\r\nMore than 5 seconds change to normal mode\r\n");
        SlaveMode = false;//return to Normal mode
        SearchDevices();
        Volume = 99; //if Volume == IdleVolume the not need send the volume so need give the diffent IdleVolume value
        Bay = RightBay;
        SetIdleState();
        SetMux(Input,LeftBay);
        SetMux(Input,CenterBay);
        SetMux(Input,RightBay);
      }
      wdt_reset();  // Update the watchdog
    } else {                //  Not in slave mode so feed the MP3 engine

      if (MP3Ready && !MP3_Process())
        MainLoop(0);        // Tell the main loop we have stopped playback

      //  Call the main loop if it is due

      if (Timer_Read() >= LoopPeriod) {     // Run the main loop at 10Hz
        Timer_Clear();
        MainLoop(1);        // Tell the main loop we are still playing a track
      }
    }
  }
  return 0;
}
Exemplo n.º 22
0
 MifarePlusKey::MifarePlusKey(size_t keySize)
     : Key()
 {
     InitKey(keySize);
     clear();
 }
Exemplo n.º 23
0
bool CScript::ReadKeyParse() // Read line from script
{
	ADDTOCALLSTACK("CScript::ReadKeyParse");
	EXC_TRY("ReadKeyParse");
	EXC_SET("read");
	if ( !ReadKey(true) )
	{
		EXC_SET("init");
		InitKey();
		return false;	// end of section.
	}

	ASSERT(m_pszKey);
	GETNONWHITESPACE( m_pszKey );
	EXC_SET("parse");
	Str_Parse( m_pszKey, &m_pszArg );

	//if ( !m_pszArg[0] || m_pszArg[1] != '=' || !strchr( ".*+-/%|&!^", m_pszArg[0] ) )
	if ( !m_pszArg[0] || ( m_pszArg[1] != '=' && m_pszArg[1] != '+' && m_pszArg[1] != '-' ) || !strchr( ".*+-/%|&!^", m_pszArg[0] ) )
		return true;

	static LPCTSTR const sm_szEvalTypes[] =
	{
		"eval",
		"floatval"
	};

	EXC_SET("parse");
	LPCTSTR	pszArgs	= m_pszArg;
	pszArgs += 2;
	GETNONWHITESPACE( pszArgs );
	TemporaryString buf;

	int iKeyIndex = (strnicmp(m_pszKey, "float.", 6) == 0) ? 1 : 0;

	if ( m_pszArg[0] == '.' )
	{
		if ( *pszArgs == '"' )
		{
			TCHAR *	pQuote	= const_cast<TCHAR*>(strchr( pszArgs+1, '"' ));
			if ( pQuote )
			{
				pszArgs++;
				*pQuote	= '\0';
			}
		}
		sprintf(buf, "<%s>%s", m_pszKey, pszArgs);
	}
	else if ( m_pszArg[0] == m_pszArg[1] && m_pszArg[1] == '+' )
	{
		if ( m_pszArg[2] != '\0' )
			return true;
		sprintf(buf, "<eval (<%s> +1)>", m_pszKey);
	}
	else if ( m_pszArg[0] == m_pszArg[1] && m_pszArg[1] == '-' )
	{
		if ( m_pszArg[2] != '\0' )
			return true;
		sprintf(buf, "<eval (<%s> -1)>", m_pszKey);
	}
	else
	{
		sprintf(buf, "<%s (<%s> %c (%s))>", sm_szEvalTypes[iKeyIndex], m_pszKey, *m_pszArg, pszArgs);
	}
	strcpy(m_pszArg, buf);

	return true;
	EXC_CATCH;
	return false;
}