Пример #1
0
void OpOR::Execute()
{
    auto reg = Environment::get().GetReg();
    auto cu = Environment::get().GetCU();

    const uint16_t ddata = cu->GetOperandData(0);
    const uint16_t sdata = cu->GetOperandData(1);
    const uint16_t result = ddata | sdata;

    reg->SetFlag(Flag::Overflow, 0);
    reg->SetFlag(Flag::Carry, 0);
    reg->CheckZero(result);
    reg->CheckSign(result);
    reg->CheckParity(result);

    cu->SetOperandData(0, result);
}
Пример #2
0
void OpADC::Execute()
{
    auto reg = Environment::get().GetReg();
    auto cu = Environment::get().GetCU();

    const uint16_t ddata = cu->GetOperandData(0);
    const uint16_t sdata = cu->GetOperandData(1);
    const uint16_t result = ddata + sdata + reg->GetFlag(Flag::Carry);

    reg->SetFlag(Flag::Overflow, static_cast<uint32_t> (ddata + sdata) != result);
    reg->CheckCarry(ddata);
    reg->CheckZero(result);
    reg->CheckSign(result);
    reg->CheckAuxiliaryCarry(ddata, result);
    reg->CheckParity(result);

    cu->SetOperandData(0, result);
}
Пример #3
0
int CommOpen(const char *device_name, 
                         unsigned long speed,
                         unsigned data_bits,
                         char parity,
                         unsigned stop_bits)
{
    struct termios tio;
    int i = -1, fd = -1;

    Trapdoor();

    if (!CheckParity(parity) || !CheckBaudRate(speed) || !CheckStopBits(stop_bits))
        return -1;

    /* open port */
    fd = open(device_name, O_RDWR|O_NOCTTY|O_NONBLOCK);
    if (fd < 0) 
    {
#if defined(_DEBUG_SERIAL_)
        CsDebug(1, (1, "CommOpen: open failed"));
#endif
        return -1;
    }

#if defined(_DEBUG_SERIAL_)
    CsDebug(1, (1, "CommOpen: opened %s (fd:%d)", device_name, fd));
#endif

    /* find a handle */
    for (i = 0; i < MAX_PORTS; i++)
    {
        if (HANDLE(i).fd == -1)
            break;
    }

    if (i == MAX_PORTS)
        return -1;

    HANDLE(i).fd = fd;
    
    /* don't wory about these for now */
    //HANDLE(i).baud       = GetBaudRate(speed);
    //HANDLE(i).parity     = GetParity(parity);
    //HANDLE(i).stop_bits  = GetStopBits(stop_bits);
    //HANDLE(i).data_bits  = GetWordLen(data_bits);

    /* setup baudrate and other communication port configuration */
    //newtio.c_cflag = HANDLE(i).baud       |
    //                 HANDLE(i).parity     |
    //                 HANDLE(i).stop_bits  |
    //                 HANDLE(i).data_bits  |
    //                 CLOCAL|CREAD|PARENB;
    /* setup baudrate and other communication port configuration */

    /* get current attributes */
    tcgetattr(fd, &tio);

    /* set input/ouput baud rate */
    cfsetispeed(&tio, GetBaudRate(speed));
    cfsetospeed(&tio, GetBaudRate(speed));

    /* reset current databits, parity and stopbits settings */
    tio.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB);
    /* set new settings */
    tio.c_cflag |= (GetWordLen(data_bits) | GetParity(parity) | GetStopBits(stop_bits) | CREAD | CLOCAL);

    tio.c_iflag     = 0;
    tio.c_oflag     = 0;
    tio.c_lflag     = 0;
    tio.c_cc[VMIN]  = 1;
    tio.c_cc[VTIME] = 0;

    /* write out the attributes */
    tcsetattr(fd, TCSAFLUSH, &tio);

    CsDebug(1, (1, "CommOpen: opened handle %d(%d)", i, fd));

    return i;
}
Пример #4
0
int	GetAuthKeyInfoFromFile_V1(char *KeyFileBuff, B2B_AUTH_INFO_T *AuthInfo)
{
    int ret = NO_ERROR;

    char    DeviceInfoBinSizeBuff[B2B_DEVINFOBIN_SIZE+1];
    char    AgencyIDSizeBuff[B2B_DEVINFOBIN_SIZE+1];
    char    SolutionIDSizeBuff[B2B_DEVINFOBIN_SIZE+1];

    memset(DeviceInfoBinSizeBuff, 0, B2B_DEVINFOBIN_SIZE+1);
    memset(AgencyIDSizeBuff, 0, B2B_DEVINFOBIN_SIZE+1);
    memset(SolutionIDSizeBuff, 0, B2B_DEVINFOBIN_SIZE+1);

    //printf("KeyFile(%s)\n", KeyFileBuff);
    if((ret = CheckCheckSum(KeyFileBuff)) != NO_ERROR)	{
        //printf("ret(%d)\n", ret);
        return	ret;
    }

    sprintf(AuthInfo->EncriptKeyBuff, "%s", KeyFileBuff);

    //	AgencyID
    memcpy(AuthInfo->AgencyIDBuff, AuthInfo->EncriptKeyBuff+B2B_AGENCYID_POSITION_V1, B2B_AGENCYID_ENCSIZE_V1);
    //printf("AgencyIDBUFF(%s)\n", AuthInfo->AgencyIDBuff);

    //	SolutionID
    memcpy(AuthInfo->SolutionIDBuff, AuthInfo->EncriptKeyBuff+B2B_SOLUTION_POSITION_V1, B2B_SOLUTION_ENCSIZE_V1);
    //printf("SolutionIDBUFF(%s)\n", AuthInfo->SolutionIDBuff);

    //	AgencyIDLength
    memcpy(AgencyIDSizeBuff, AuthInfo->EncriptKeyBuff+B2B_AGENCYSIZE_POSITION_V1, B2B_AGENCYSIZE_ENCSIZE_V1);
    //printf("AgencyIDSizeBUFF(%s)\n", AgencyIDSizeBuff);

    //	SolutionIDLength
    memcpy(SolutionIDSizeBuff, AuthInfo->EncriptKeyBuff+B2B_SOLUTIONSIZE_POSITION_V1, B2B_SOLUTIONSIZE_ENCSIZE_V1);
    //printf("SoltionIDSizeBUFF(%s)\n", SolutionIDSizeBuff);

    //	AgencyID Parity
    memcpy(AuthInfo->AgencyIDParityBuff, AuthInfo->EncriptKeyBuff+B2B_AGENCYPARITY_POSITION_V1, B2B_AGENCYSOLUTION_PARITY_ENCSIZE_V1);
    //printf("AgencyIDParityBUFF(%s)\n", AuthInfo->AgencyIDParityBuff);

    //	Solution Parity
    memcpy(AuthInfo->SolutionIDParityBuff, AuthInfo->EncriptKeyBuff+B2B_SOLUTIONPARITY_POSITION_V1, B2B_AGENCYSOLUTION_PARITY_ENCSIZE_V1);
    //printf("SolutionIDParityBUFF(%s)\n", AuthInfo->SolutionIDParityBuff);

    //	Authentication Time
    memcpy(AuthInfo->AuthTimeBuff, AuthInfo->EncriptKeyBuff+B2B_AUTHTIME_POSITION_V1, B2B_AUTHTIME_ENCSIZE_V1);
    //printf("AuthTimeBUFF(%s)\n", AuthInfo->AuthTimeBuff);

    //	ExpireDateTime
    memcpy(AuthInfo->ExpireDateBuff, AuthInfo->EncriptKeyBuff+B2B_EXPIREDATE_POSITION_V1, B2B_EXPIREDATE_ENCSIZE_V1);
    //printf("ExpireDateBUFF(%s)\n", AuthInfo->ExpireDateBuff);

    //	ProductID
    memcpy(AuthInfo->ProductID, AuthInfo->EncriptKeyBuff+B2B_PRODUCTID_POSITION_V1, B2B_PRODUCTID_ENCSIZE_V1);
    //printf("ProductIDBUFF(%s)\n", AuthInfo->ProductID);

    //	Random
    memcpy(AuthInfo->RandomBuff, AuthInfo->EncriptKeyBuff+B2B_RANDOM_POSITION_V1, B2B_RANDOM_ENCSIZE_V1);
    //printf("RandomBUFF(%s)\n", AuthInfo->RandomBuff);

    //	Parity
    memcpy(AuthInfo->ParityBuff, AuthInfo->EncriptKeyBuff+B2B_DATETIMEPARITY_POSITION_V1, B2B_DATETIMEPARITY_ENCSIZE_V1);
    //printf("ParityBUFF(%s)\n", AuthInfo->ParityBuff);

    //	Version
    memcpy(&(AuthInfo->Version), AuthInfo->EncriptKeyBuff+B2B_VERSION_POSITION_V1, B2B_VERSION_ENCSIZE_V1);
    //printf("VersionBUFF(%c)\n", AuthInfo->Version);

    //	DeviceInfoSize
    memcpy(DeviceInfoBinSizeBuff, AuthInfo->EncriptKeyBuff+B2B_DEVICEINFOSIZE_POSITION_V1, B2B_DEVICEINFOSIZE_ENCSIZE_V1);
    //printf("DeviceBinSizeBUFF(%s)\n", DeviceInfoBinSizeBuff);
    AuthInfo->DeviceInfoSize = atoi(DeviceInfoBinSizeBuff);

    //	DeviceInfo.bin
    if((AuthInfo->DeviceInfo = (char *) malloc( AuthInfo->DeviceInfoSize+1)) == NULL)	{
        return	ERROR_EXCEPTION_MEMORY;
    }
    memcpy(AuthInfo->DeviceInfo, AuthInfo->EncriptKeyBuff+B2B_DEVICEINFO_POSITION_V1, AuthInfo->DeviceInfoSize);
    //printf("DeviceInfoBUFF(%s)\n", AuthInfo->DeviceInfo);

    if((ret = GetExpireDateInfo(AuthInfo->ExpireDateBuff, &(AuthInfo->ExpireDate))) != NO_ERROR)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        return	ret;
    }

    if((ret = CheckAuthTime(AuthInfo->AuthTimeBuff, AuthInfo->ExpireDate)) != NO_ERROR)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        return	ret;
    }

    if((ret = GetRandomNumber(AuthInfo->RandomBuff, &(AuthInfo->RandomNumber))) != NO_ERROR)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        return	ret;
    }

    if((ret = CheckParity(AuthInfo->ParityBuff, AuthInfo->AuthTimeBuff, AuthInfo->ExpireDateBuff, AuthInfo->ProductID, AuthInfo->RandomNumber)) != NO_ERROR)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        return	ret;
    }

    //	Version Check
    if(AuthInfo->Version != B2B_AUTHENTICATION_VERSION_V1)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        return	ret;
    }

    AuthInfo->AgencyIDLength = atoi(AgencyIDSizeBuff);
    AuthInfo->SolutionIDLength = atoi(SolutionIDSizeBuff);
    if((ret = GetAgencyNSolutionID_V1(AuthInfo->AgencyIDBuff, AuthInfo->AgencyID, AuthInfo->AgencyIDParityBuff, AuthInfo->AgencyIDLength)) != NO_ERROR)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        return	ERROR_UNABLE_CREATEKEYFILE;
    }


    if((ret = GetAgencyNSolutionID_V1(AuthInfo->SolutionIDBuff, AuthInfo->SolutionID, AuthInfo->SolutionIDParityBuff, AuthInfo->SolutionIDLength)) != NO_ERROR)	{
        //printf("ret(%d)(_%d_)\n", ret, __LINE__);
        //return ERROR_UNABLE_CREATEKEYFILE;	// 에러리턴 주석처리 - 20120801, kih
    }

    return	NO_ERROR;
}