Esempio n. 1
0
int IStateHandshake::OnHandshake_Signature (const IPacket &packet)
{
    uint8_t signature[KEY_LENGTH] = { 0 };

    for (int i=0; i < KEY_LENGTH; ++i)
        signature[i] = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    /// Simple check to see if the handshake is good
    if(memcmp(m_srv_signature,signature,KEY_LENGTH))
    {
#if defined DEBUG
        syslog(LOG_DEBUG,"clt::IStateHandshake::OnHandshake_Signature - Invalid Server Signature.");
        syslog(LOG_DEBUG,"Server Key = %i %i, Client Key = %i %i",m_srv_signature[0],m_srv_signature[1],
            signature[0],signature[1]);
#endif
        return MSG_ERROR_ARG;
    }

    Func_X_2(m_base_key, m_S, 0x3);

    boost::shared_ptr<SROAuth> auth =
            boost::shared_static_cast<SROAuth,Authentication>(m_connection->getAuthentication());

    auth->setKey(m_base_key,KEY_LENGTH);

    SendID();

    return MSG_SUCCESS;
}
Esempio n. 2
0
int IStateHandshake::OnHandshake_Clean (const IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    SendID();

    return MSG_SUCCESS;
}
BST_ERR_ENUM_UINT8 BST_APP_CEmailIMAP::HandleWelcomResp( BST_VOID )
{
    BST_ERR_ENUM_UINT8      enErrMsg;
    if ( 0 == BST_OS_MEMCMP( m_pcServerResponse1, "OK", 2 ) )
    {
        enErrMsg            = SendID();
        if ( BST_NO_ERROR_MSG == enErrMsg )
        {
            m_lServerState  = BST_EMAIL_CONNECTED;
        }
        return enErrMsg;
    }
    else
    {
        return BST_ERR_UNREACHABLE;
    }
}
Esempio n. 4
0
void main()
{
	unsigned char c;

	Init_Device();

	CheckSRAMs();

	LED=0;
	adc_select=3;
	ADC0ConfigEven=ADC0ConfigOdd=0;		// adc0 gain and channel selection for every even sample and every odd sample
	ADC1ConfigEven=ADC1ConfigOdd=0;
	DAC0_mode=0;
	handshake=1;
	dac_increment=1;
	dac_amplitude=255;
	dac_offset=0;
	fifo_size=128;	// default number of samples in a block

	RTS=0;

	while (1)
	{
		while (SInOut()!='@');
		c=SInOut();
		if (c=='I')
		{
			SendID();
		}
		else if (c=='x')	// switch reference voltage and resistors
		{
			c=SInOut();
			SW0 = !(c&1);	// 1: 10k resistor connected to input, 0: input floating
			SW1 = !(c&2);
			SW2 = !(c&4);
			SW3 = !(c&8);
			PULL = !(c&16);	// 1: pull up to Vref, 0: pull down to GND
		}
		else if (c=='t')	// set trigger polarity
		{
			c=SInOut();
			TRIGINV = c&1;
		}
		else if (c=='b')	// set fifo block size (number of samples in a block
		{
			fifo_size=SInOut();
		}
		else if (c=='c')	// configure continuous sampling mode
		{
			ADC0ConfigEven=SInOut();
			ADC1ConfigEven=SInOut();
			ADC0ConfigOdd=SInOut();
			ADC1ConfigOdd=SInOut();
		}
		else if (c=='S') // start sampling, ESC exits
		{
			ContSampling();
		}
		else if (c=='s') // start sampling, ESC exits
		{
			unsigned long n;

			n = SInOut();
			n = (n << 8)+SInOut();
			n = (n << 8)+SInOut();
			SetSamplingFreq(n);
			n = SInOut();
			n = (n << 8)+SInOut();
			HiSpeedSampling(n);
//			SamplingToSRAM(SInOut());
		}
		else if (c=='A') // select ADCs
		{
			adc_select = SInOut() & 3;
		}
		else if (c=='1') // set range, current, channel
		{
			c=SInOut();
			SetPGA0(c);
		}
		else if (c=='2') // set range, current, channel
		{
			c=SInOut();
			SetPGA1(c);
		}
		else if (c=='M') // measure channels
		{
			c=SInOut();
			if (c<1) c=1;
			Convert(c); // make a single conversion and send data to PC
			SOut(adc1data >> 8);	// channel 0 or 1
			SOut(adc1data);
			SOut(adc0data >> 8);	// channel 2 or 3
			SOut(adc0data);
		}
		else if (c=='f') // set freq
Esempio n. 5
0
int IStateHandshake::OnHandshake_Security (const IPacket &packet)
{
    boost::shared_ptr<SROAuth> auth =
            boost::shared_static_cast<SROAuth,Authentication>(m_connection->getAuthentication());

    uint8_t mode = auth->getMode();

    if (mode & SECURITY_ENCRYPTION)
    {
        uint8_t public_key[KEY_LENGTH];

        for (int i = 0; i < KEY_LENGTH; ++i)
            public_key[i] = packet.Read<uint8_t>();

        auth->setKey(public_key,KEY_LENGTH);
    }

    if (mode & SECURITY_CRC)
    {
        uint32_t count = packet.Read<uint32_t>();

        uint32_t crc = packet.Read<uint32_t>();

        auth->initializeCount(count);

        auth->initializeCRC(crc);
    }

    if (mode & SECURITY_DH)
    {
        for (int i = 0; i < KEY_LENGTH; ++i)
            m_base_key[i] = packet.Read<uint8_t>();

        uint32_t G = packet.Read<uint32_t>();

        uint32_t P = packet.Read<uint32_t>();

        uint32_t A = packet.Read<uint32_t>();

        if (!packet.EndOfStream())
            return MSG_ERROR_SIZE;

        uint32_t b = rand();

        uint8_t keyByte = 0;
        uint32_t B = ModExp(P,b,G);
        m_S = ModExp(P,b,A);

        uint8_t priv_key[KEY_LENGTH] = { 0 };
        memcpy(priv_key,&A,sizeof(A));
        memcpy(priv_key+4,&B,sizeof(B));

        keyByte = LOBYTE(LOWORD(m_S)) & 0x03;
        Func_X_2(priv_key, m_S, keyByte);

        auth->setKey(priv_key,KEY_LENGTH);

        /// Generate the private blowfish data
        uint8_t signature[KEY_LENGTH] = { 0 };
        memcpy(signature,&B,sizeof(B));
        memcpy(signature+4,&A,sizeof(A));

        keyByte = LOBYTE(LOWORD(B)) & 0x07;
        Func_X_2(signature, m_S, keyByte);

        auth->encrypt(signature,signature,KEY_LENGTH);

        OPacket pkt;
        clt_pkt::Signature(&pkt,B,signature,KEY_LENGTH);
        m_connection->send(&pkt);

        memcpy(m_srv_signature,&A,sizeof(A));
        memcpy(m_srv_signature+4,&B,sizeof(B));

        keyByte = LOBYTE(LOWORD(A)) & 0x07;
        Func_X_2(m_srv_signature,m_S, keyByte);

        auth->encrypt(m_srv_signature,m_srv_signature,KEY_LENGTH);
    }

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (!(mode & SECURITY_DH))
        SendID();

    return MSG_SUCCESS;
}
Esempio n. 6
0
void main()
{
	unsigned char c;

	Init_Device();

	CheckSRAMs();

	adc_select=3;
	ADCConfigEven=ADCConfigOdd=0;		// adc0 gain and channel selection for every even sample and every odd sample
	DAC0_mode=0;
	handshake=1;
	dac_increment=1;
	dac_amplitude=255;
	dac_offset=0;
	fifo_size=128;	// default number of samples in a block

//fifo_size=4;	// default number of samples in a block
//SetSamplingFreq(100);

	for(c=0; c<3; c++)	// flash the power LED three times to indicate booting
	{
		LED=0;	Delay_ms(200);
		LED=1;	Delay_ms(200);
	}
	LED=0;


	RTS=0;




	while (1)
	{
		while (SInOut()!='@');
		c=SInOut();
		if (c=='I')
		{
			SendID();
		}
		else if (c=='x')	// switch reference voltage and resistors
		{
		}
		else if (c=='t')	// set trigger polarity
		{
		}
		else if (c=='b')	// set fifo block size (number of samples in a block
		{
			fifo_size=SInOut();
		}
		else if (c=='c')	// configure continuous sampling mode
		{
			c=SInOut();
			ADCConfigEven = ((c & 1) << 4) | ((c & 2) << 2);
			c=SInOut();
			ADCConfigEven =  ((c & 1) << 5) | ((c & 2) << 5);
			c=SInOut();
			ADCConfigOdd = ((c & 1) << 4) | ((c & 2) << 2);
			c=SInOut();
			ADCConfigOdd =  ((c & 1) << 5) | ((c & 2) << 5);
		}
		else if (c=='S') // start sampling, ESC exits
		{
			ContSampling();
		}
		else if (c=='s') // start sampling, ESC exits
		{
			unsigned long n;

			n = SInOut();
			n = (n << 8)+SInOut();
			n = (n << 8)+SInOut();
			SetSamplingFreq(n);
			n = SInOut();
			n = (n << 8)+SInOut();
			HiSpeedSampling(n);
		}
		else if (c=='A') // select ADCs
		{
			adc_select = SInOut() & 3;
		}
		else if (c=='1') // set channel
		{
			c=SInOut();
			MUX1A0 = c & 1;
			MUX1A1 = c & 2;
		}
		else if (c=='2') // setchannel
		{
			c=SInOut();
			MUX2A0 = c & 1;
			MUX2A1 = c & 2;
		}
		else if (c=='M') // measure channels
		{
			c=SInOut();
			if (c<1) c=1;
			Convert(c); // make a single conversion and send data to PC
			SOut(adc1data >> 8);	// channel 0 or 1
			SOut(adc1data);
			SOut(adc0data >> 8);	// channel 2 or 3
			SOut(adc0data);
		}
		else if (c=='f') // set freq