Exemplo n.º 1
0
char SBBTA252::getChecksum(int bit, char *cmd, int cmdLength)
{
  char ret;
  int dec = 0;
  int i = 1;
  
  while (i < cmdLength-3)
  {
    dec += hex2dec(&cmd[i]);
    i += 2;
  }
  dec = dec % 256;
  
  if (bit == 1)
  {
    ret = dec2hex(dec / 16);
  }
  else if (bit == 2)
  {
    ret = dec2hex(dec % 16);
  }
  else
  {
    ROS_WARN("Checksum bit %d is out of range.", bit);
    ret = -1;
  }
  
  // Return the checksum bit
  return ret;
} // end getChecksum()
Exemplo n.º 2
0
void SBBTA252::sendChangeAddressCommand(int thruster, int new_address)
{
  // Declare variables
  char cmd[10];
  Serial::buf_send = cmd;

  if (new_address < 1 || new_address > 255)
  {
    ROS_WARN("New address %d is not in the range from 1-255", new_address);
    return;
  }

  // Send command
  if (Serial::fd > 0)
  {
    cmd[0] = SBBTA252_SC;
    cmd[1] = getAddress(1, thruster);
    cmd[2] = getAddress(2, thruster);
    cmd[3] = '0'; // Command specific char
    cmd[4] = 'B'; // Command specific char
    cmd[5] = dec2hex(new_address / 16);
    cmd[6] = dec2hex(new_address % 16);
    cmd[7] = getChecksum(1, cmd, 10);
    cmd[8] = getChecksum(2, cmd, 10);
    cmd[9] = SBBTA252_EC;
    Serial::length_send = 10;
    send();
    usleep(SBBTA252_SERIAL_DELAY);
    
    ROS_DEBUG("Changing address from %d to %d.", thruster, new_address);
  }
} // end SendChangeAddressCommand()
Exemplo n.º 3
0
char SBBTA252::getAddress(int bit, int thruster)
{
  char ret;
  
  // Check validity of thruster address
  if (thruster < 0 || thruster > 255)
  {
    ROS_WARN("Thruster address %d is out of range.", thruster);
    return -1;
  }
  
  if (bit == 1)
  {
    ret = dec2hex(thruster / 16);
  }
  else if (bit == 2)
  {
    ret = dec2hex(thruster % 16);
  }
  else
  {
    ROS_WARN("Address bit %d is out of range.", bit);
    ret = -1;
  }
  
  // Return the address bit
  return ret;
} // end getAddress()
Exemplo n.º 4
0
bool SBBTA252::parseStatus()
{
  // Declare variables.
  char *msg = Serial::buf_recv;
  char address[2];
  int rpm, // ranges from -4500 to 4500
      current, // Amps * 10
      motor_temp,
      controller_temp,
      voltage,
      water_detect,
      status,
      faults;

  address[0]      = msg[1];
  address[1]      = msg[2];
  rpm             = getDecimal(msg, 3, 8);
  current         = getDecimal(msg, 10, 12);
  motor_temp      = getDecimal(msg, 14, 16);
  controller_temp = getDecimal(msg, 18, 20);
  voltage         = getDecimal(msg, 22, 24);
  water_detect    = getDecimal(msg, 26, 28);
  status          = getDecimal(msg, 30, 32);
  faults          = getDecimal(msg, 34, 36);

  // check for what status and fault messages are here:
  char checksum[2];

  int cs = hex2dec(address) + rpm + current + motor_temp + controller_temp + voltage + water_detect + status + faults;

  cs = cs % 256;  
  checksum[0] = dec2hex(cs / 16);
  checksum[1] = dec2hex(cs % 16);

  if (checksum[0] != msg[38] || checksum[1] != msg[39])
  {
    ROS_ERROR("We received a bad status message. Checksums didn't match.");
    return false;
  }
  else
  {
    /*
    ROS_ERROR("msg=%s.", msg);
    ROS_ERROR("rpm = %d.", rpm);
    ROS_ERROR("current = %d.", current);
    ROS_ERROR("motor_temp = %d.", motor_temp);
    ROS_ERROR("controller_temp = %d.", controller_temp);
    ROS_ERROR("voltage = %d.", voltage);
    ROS_ERROR("water_detect = %d.", water_detect);
    ROS_ERROR("status = %d.", status);
    ROS_ERROR("faults = %d.", faults);
    */
  
    return true;
  }
} // end parseStatus()
// function request_card
static int KSAPI request_card(ks_reader_dev_t *dev,char* phyid,KS_CARD_TYPE t) {
    int ret;
    unsigned long snr;
    uint8 ucCardPhyID[8];

    if(!g_dev_hd) {
        ret=open_device(dev);
        if(ret)
            return ret;
    }
    if(!g_dev_hd) {
        return KS_PORT_NOTOPEN;
    }

    ret= RWD.rf_card(g_dev_hd, 0, &snr);
    if(ret) {
        GetErrMsgByErrCode(ret,gErrMsg);
        TRACE_ERR("检测卡错误, "<<gErrMsg);
        return KS_REQUESTCARD;
    }

    g_lastCardType = KS_MFCARD;

    dev->cardtype = g_lastCardType;
    set_4byte_int(ucCardPhyID,snr);
    dec2hex(ucCardPhyID,4,phyid);
    phyid[8]=0;

    DEBUG("request_card:[%s]",phyid );

    return 0;
}
Exemplo n.º 6
0
void wr_Current(void)
{
    if(rd[SN_Color] == RedColor)
    {
        CurrentMaxim = 0x04D9;
    }
    else if(rd[SN_Color] == BlueColor)
    {
        CurrentMaxim = 0x0953;
    }

    CurrentMinum = 0x0011;
    CurrentTuneValue = dec2hex(rd[9], rd[10]);

    if((CurrentTuneValue < CurrentMaxim) && (CurrentTuneValue > CurrentMinum) )
    {
        Response(Error);
    }
    else
    {
        Response(Error_wr_Current);
    }

    Flag_Order = true;
}
Exemplo n.º 7
0
void command1()
{
	int p = hex2dec(inst[pos+1]) * 16 + hex2dec(inst[pos+2]);
	inst[p] = dec2hex(A);
	pos += 3;
	if (pos >= 0xf0)
		pos -= 0xf0;
}
Exemplo n.º 8
0
Arquivo: 10473.cpp Projeto: fkrafi/UVa
int main(){
	freopen("10473.txt", "r", stdin);
	while(gets(s)){
		if(s[0]=='-')break;
		if(s[0]=='0' && s[1]=='x')hex2dec();
		else dec2hex();
	}
	return 0;
}
Exemplo n.º 9
0
int main() {
    long v;

    while (std::cin >> v) {
        std::cout << dec2hex(v) << std::endl;
    }

    return 0;
}
Exemplo n.º 10
0
int __stdcall encrypt_work_key_asc(char src_text[17], char des_text[17])
{
	unsigned char text[9] = "";
	unsigned char mtext[9] = "";
	hex2dec(src_text, text, 8);
	encrypt_work_key(text, mtext);
	dec2hex(mtext, 8, des_text);
	
	return 0;
}
Exemplo n.º 11
0
// obs³u¿ pakiet
void announce_handle_packet(unsigned char* data, unsigned int len) {
    // wype³nij pakiet (nazwa urz¹dzenia, adres MAC, sygnaturka)
    len = 0;

    // skonfigurowana nazwa urz¹dzenia
    config_t* config_get();
    
    strcpy(config_ram.name, (char*)data+len);
    len += strlen((char*)data);

    // ³amanie wiersza
    memcpy_P(PSTR("\r\n"), data+len, 2);
    len += 2;

    // adres MAC (w formacie "human-readable")
    unsigned char *mac = nic_get_mac();
    for (unsigned char i=0; i<6; i++) {
        data[len++] = dec2hex(mac[i] >> 4);
        data[len++] = dec2hex(mac[i] & 0x0f);

        if (i<5)
            data[len++] = '-';
    }

    // ³amanie wiersza
    memcpy_P(PSTR("\r\n"), data+len, 2);
    len += 2;
    
    // sygnaturka
    strcpy_P(RS2ETH_SIGNATURE, (char*)data+len);
    len += strlen_P(RS2ETH_SIGNATURE);

    rs_dump(data, len);

    // utwórz "po³¹czenie" UDP (odpowiedŸ)
    struct uip_udp_conn* conn;
    conn = uip_udp_new(&uip_udp_conn->ripaddr, uip_udp_conn->rport);

    if (!conn) {
        return;
    }

    // wyœlij z portu konfiguracyjnego
    uip_udp_bind(conn, HTONS(ANNOUNCE_PORT));

    // wyœlij
    uip_udp_send(len + 10);

    // czekaj na wys³anie
    nic_wait_for_send();

    // zamknij po³¹czenia UDP (przychodz¹cy broadcast i wychodz¹cy unicast)
    uip_udp_remove(conn);
    uip_udp_remove(uip_udp_conn);
}
Exemplo n.º 12
0
char SBBTA252::getSpeed(int bit, int speed)
{
  char ret;
  
  // Check validity of thruster address
  if (speed < -100 || speed > 100)
  {
    ROS_WARN("Speed %d is out of range.", speed);
    return -1;
  }
  
  int dec;
  if (speed == 0)
  {
    dec = 128;
  }
  else if (speed > 0)
  {
    dec = speed + 130;
  }
  else if (speed < 0)
  {
    dec = speed + 125;
  }
  
  if (bit == 1)
  {
    ret = dec2hex(dec / 16);
  }
  else if (bit == 2)
  {
    ret = dec2hex(dec % 16);
  }
  else
  {
    ROS_WARN("Address bit %d is out of range.", bit);
    ret = -1;
  }
  
  // Return the address bit
  return ret;
} // end getSpeed()
//用PSAM卡计算DF03下的修改文件的MAC
int ks_zjvcc_cardtype::CalcSafeMac4Sam(const char *szCmdbuf,char *szMac) {
    int ret;
    unsigned char uRandom[8]= {0};
    char szRandom[17] = {0};
    ret = this->GetRandomNum8(uRandom);
    if(ret)
        return ret;
    dec2hex(uRandom,8,szRandom);
    strcpy(this->m_szRandomNum,szRandom);
    return m_PSAMCardType->CalcSafeMac4Sam(this,szCmdbuf,szMac);
}
Exemplo n.º 14
0
static char * hex_print(unsigned char * s)
{
	char * g = kmalloc(strlen(s)*3 + 1, GFP_ATOMIC);
	int i;

	if(!g) {
	       if (net_ratelimit()) 
			printk(KERN_ERR "layer7: out of memory in hex_print, bailing.\n");
	       return NULL;
	}

	for(i = 0; i < strlen(s); i++) {
		g[i*3    ] = dec2hex(s[i]/16);
		g[i*3 + 1] = dec2hex(s[i]%16);
		g[i*3 + 2] = ' ';
	}
	g[i*3] = '\0';

	return g;
}
Exemplo n.º 15
0
void vscp_server_GUID2String( uint8_t *pGUID, char *pbuf )
{
    int i;
    char wrkbuf[ 2 ];
    
    pbuf[ 0 ] = 0x00;    // Empty string
    for ( i=0; i<16; i++ ) {
        dec2hex( pGUID[ 15-i ], wrkbuf, 2 );
        strcat( pbuf, wrkbuf );
        if ( i != 15 ) strcat( pbuf, ":" );
    }
}
Exemplo n.º 16
0
void vscp_server_Data2String( uint8_t *pData, uint16_t size, char *pbuf )
{
    int i;
    char wrkbuf[ 2 ];
    
    pbuf[ 0 ] = 0x00;    // Empty string
    for ( i=0; i<size; i++ ) {
        dec2hex( pData[ 15-i ], wrkbuf, 2 );
        strcat( pbuf, wrkbuf );
        if ( i != 15 ) strcat( pbuf, ":" );
    }
}
// 握奇外部认证使用8字节随机数
int ks_zjvcc_cardtype::GetRandomNum8(byte *uRandomNum) {
    byte ucResp[256]= {0};
    byte ucRespLen = 0;

    int nRet = Adpu((BYTE*)"\x00\x84\x00\x00\x08",5, ucResp, ucRespLen);
    if(nRet)
        return nRet;

    memcpy(uRandomNum,ucResp,8);
    memset(m_szRandomNum,0,sizeof m_szRandomNum);
    dec2hex(uRandomNum,8,this->m_szRandomNum);
    return 0;
}
Exemplo n.º 18
0
int main(int argc, char *argv[])
{
  if (argc < 2) {
    printf("Usage: %s <number>\n", argv[0]);
    return 1;
  }
  int a = atoi(argv[1]);
  printf("DEC: %d\n", a);
  printf("HEX: ");
  dec2hex(a);
  printf("BIN: ");
  dec2bin(a);
  printf("OCT: ");
  dec2radix(a, 8);
  printf("26: ");
  dec2radix(a, 26);

  return 0;
}
int ks_zjvcc_cardtype::ExtAuth(const char *cardphyid,int keyidx) {
    string sCmd;
    unsigned char ucRespData[512]= {0};
    unsigned char ucRandom[9]= {0};
    char sRandomHex[17]= {0};
    char encrypt_random[24] = {0};
    int nRet;

    nRet=SelectADF();
    if(nRet)
        return nRet;
    nRet=GetRandomNum8(ucRandom); // 握奇外部认证使用8字节随机数
    if(nRet)
        return nRet;

    ks_cpu_cmd_t cmd;
    memset(&cmd,0,sizeof(cmd));
    cmd.recv_buf=ucRespData;

    dec2hex(ucRandom,8,sRandomHex);
    nRet = CalcExtAuthEncrypt4Sam(cardphyid,keyidx,sRandomHex,encrypt_random);
    if(nRet) {
        return nRet;
    }
    sCmd = "008200"+ltohex(keyidx)+"08";
    sCmd += encrypt_random;

    cmd.cmd_type=1;
    cmd.send_buf=(byte*)sCmd.c_str();
    cmd.send_len=sCmd.size();
    nRet=m_Reader->cpucard_cmd(m_ReaderPara,&cmd,m_defaultCardType);
    if(nRet) {
        if(cmd.cmd_retcode) {
            SET_ERR(GetErrMsgByErrCode(cmd.cmd_retcode,NULL));
            return cmd.cmd_retcode;
        } else {
            SET_ERR(m_Reader->GetErrMsg(NULL));
            return nRet;
        }
    }
    return 0;
}
Exemplo n.º 20
0
int _stdcall SMT_Login_With_UserKey(int sector, unsigned char *Buffer, int PaDSelect)
{
	// 0代表keyA, 1代表keyB
	memcpy(g_login_key, Buffer, sizeof(g_login_key) - 1);
	g_mode = PaDSelect;

	char KeyA[13] = "";
	dec2hex(Buffer, 6, KeyA);
	::MessageBox(NULL, KeyA, "密钥", MB_OK);

	itoa(sector, KeyA, 10);
	::MessageBox(NULL, KeyA, "扇区", MB_OK);

	itoa(PaDSelect, KeyA, 10);
	::MessageBox(NULL, KeyA, "模式", MB_OK);
	//	int  ret;
	/*
	
	ret = Rf_StoreKey(PaDSelect, sector, Buffer);
	if (ret != 1)
    {
		
		itoa(ret, KeyA, 10);
		MessageBox(NULL, "1", NULL, MB_OK);
		MessageBox(NULL, KeyA, NULL, MB_OK);
		
		return ret;
    }


	ret = Rf_LoadKey(PaDSelect, sector, sector);
	if (ret != 1)
	{		
		itoa(ret, KeyA, 10);
		MessageBox(NULL, "2", NULL, MB_OK);
		MessageBox(NULL, KeyA, NULL, MB_OK);
		
		return ret;
	}
	*/
	return 0;
}
Exemplo n.º 21
0
// function write_block
static int KSAPI write_block(ks_reader_dev_t *dev,ks_card_info_t *card,int block_no,const uint8 *block) {
    int ret;
    int blk;
    int sector;
    char blockBuf[33] = {0};

    sector = block_no/4;
    blk = block_no - (sector*4);
    // TODO : 根据卡类型判断,只能处理32个扇区之前的
    if(block_no >= 32*4 || block_no <= 0)
        return KS_BLOCK_OVERFLOW;
    if(!g_dev_hd)
        return KS_PORT_NOTOPEN;
    dec2hex(block, 16, blockBuf);
    ret = MIFS_WRITE(g_dev_hd, sector, blk, (char*)blockBuf, gErrMsg);
    //ret = dc_write(g_dev_hd,block_no,(uint8*)block);
    if(ret)
        return KS_WRITECARD;
    return 0;
}
Exemplo n.º 22
0
static int packege_search_data(ST_PACK *in_pack,char *send_data){
	int ret;
	ext_elect_search_req_t* elect_search_req_t;
	elect_search_req_t=(ext_elect_search_req_t*)send_data;
	
	unsigned char buf[68]="";
	unsigned char soutmd5[16]="";
	char outmd5[32]="";
	
	T_t_pif_card	tCard;	
	memset(&tCard,0,sizeof(tCard));
	

	memcpy(elect_search_req_t->prix,"1",1);	
	memcpy(elect_search_req_t->length,"0103",4);	
	memcpy(elect_search_req_t->type,"0006",4);
	memset(elect_search_req_t->bitery,'0',sizeof(elect_search_req_t->bitery));	
	sprintf(elect_search_req_t->room,"%-20s",in_pack->saddr);
	ret=DB_t_pif_card_read_by_card_id(in_pack->lvol0, &tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			ret=E_CARDNO_NOT_EXIST;
		else
			ret=E_DB_CARD_R;
		return ret;
	}
	sprintf(elect_search_req_t->cutid,"%-22d",tCard.cosumer_id);//客户号
	memcpy(elect_search_req_t->relate,"1",1);//对应关系
	memcpy(elect_search_req_t->clientid,"0001",4);
	memset(outmd5,'0',32);

	memcpy(buf,elect_search_req_t->type,67);	
	writelog(LOG_ERR,"buf data=[%s]",buf);
	CalcMD5(buf,67,soutmd5);
	dec2hex(soutmd5,16,outmd5);
	writelog(LOG_ERR,"outmd5 data=[%s]",outmd5);
	sprintf(elect_search_req_t->signcheck,"%s",outmd5);	
	
	return 0;
}
Exemplo n.º 23
0
// function login_card
static int KSAPI login_card(ks_reader_dev_t *dev,ks_card_info_t *card,int sect_no,
                            KS_MF_KEYTYPE keytype,const uint8 *key) {
    //return -1;
    int ret;
    uint8 mode;
    //UCHAR mafireS50Key[32][6] = {0};
    //unsigned char debugstr[20] = {0};
    //int debugLen = 0;
    //dec2hex(key, 6, debugstr);
    //hex2dec("04736CBF7FB3", 12, debugstr, debugLen);

    if(keytype == MF_KEYA) {
        mode = 0;
    } else {
        mode = 1;
    }
    if(!g_dev_hd)
        return KS_PORT_NOTOPEN;

    //ret = dc_load_key(g_dev_hd,mode,sect_no,(uint8*)key);
    //memcpy(&mafireS50Key[mode*16+sect_no][0],key,6);

    //if(ret)
    //{
    //	GetErrMsgByErrCode(ret,gErrMsg);
    //	return KS_LOGINCARD;
    //}
    //ret = dc_authentication(g_dev_hd,mode,sect_no);
    //char cErrMsg[300];
    char sectorkey[13] = {0};
    int keyLen = 0;
    dec2hex(key, 6, sectorkey);
    ret = MIFS_AUTH(g_dev_hd,sect_no ,mode, sectorkey,gErrMsg);

    if(ret) {
        GetErrMsgByErrCode(ret,gErrMsg);
        return KS_LOGINCARD;
    }
    return 0;
}
Exemplo n.º 24
0
void itob(int n, char s[], int b)
{
  switch (b) {
    case 2:
      dec2bin(n,s);
      printf("%s\n",s);
      break;
    case 8:
      dec2oct(n,s);
      reverse(s);
      printf("%s\n",s);
      break;
    case 10:
      printf("%d\n",n);
      break;
    case 16:
      dec2hex(n,s);
      reverse(s);
      printf("%s\n",s);
      break;
    default:
      break;
  }
}
Exemplo n.º 25
0
// function cpucard_cmd
static int KSAPI cpucard_cmd(ks_reader_dev_t *dev,ks_cpu_cmd_t *cmd,KS_CARD_TYPE t) {
    int ret = -1;
    uint8 sw1,sw2;
    char szCmd[256];
    char ats[200] = {0};
    ks_cpu_cmd_t innerCmd;
    cmd->cmd_retcode=0;
    assert(dev != NULL);
    if(!g_dev_hd) {
        strcpy(gErrMsg,"读卡器端口未打开");
        strcpy(cmd->cmd_retmsg,gErrMsg);
        return KS_PORT_NOTOPEN;
    }

    int recvlen;
    if(t == KS_CPUCARD || t == KS_FIXCARD) {
        // 非接触式
        if(dev->cpuport == CARDSLOT_RF) {
            if(cmd->cmd_type == 0) {
                //1
                //char sendBuf[512] = {0};
                unsigned char cmpBuf[100] = {0};
                int cmpLen = 0;
                char recvBuf[512] = {0};
                int recvLen = 0;
                unsigned char* RevTemp = NULL;
                hex2dec("0084000004", 10, cmpBuf, cmpLen);
                if ( !memcmp(cmpBuf, cmd->send_buf, cmpLen) ) {
                    ret = CPUCARD_APDU(g_dev_hd,"0084000004", recvBuf, gErrMsg);
                } else {
                    //dec2hex(cmd->send_buf, cmd->send_len, sendBuf);
                    ret = CPUCARD_APDU(g_dev_hd, (char*)cmd->send_buf, recvBuf, gErrMsg);
                }
                recvLen = strlen(recvBuf);
                RevTemp = cmd->recv_buf;
                hex2dec((char*)recvBuf, recvLen, cmd->recv_buf, (int&)cmd->recv_len);
                cmd->recv_buf = RevTemp;
            } else {
                //2
                unsigned char ucCmd[512];
                int  iCmdLen=0;
                unsigned char* RevTemp = NULL;
                //hex2dec((char*)cmd->send_buf,cmd->send_len,ucCmd,iCmdLen);
                if ( !strncmp("00B09500", (char*)cmd->send_buf, 8) ) {
                    strcat((char*)cmd->send_buf, "14");
                }
                ret = CPUCARD_APDU(g_dev_hd,(char*)cmd->send_buf , (char*)ucCmd, gErrMsg);
                iCmdLen = strlen((char*)ucCmd);
                memcpy(cmd->recv_buf,ucCmd,cmd->recv_len);
                RevTemp = cmd->recv_buf;
                hex2dec((char*)ucCmd, iCmdLen, cmd->recv_buf, (int&)cmd->recv_len);
                cmd->recv_buf = RevTemp;
            }
        } else {
            //GET_DECARD_SLOT(dev,dev->cpuport);
            if(cmd->cmd_type == 0) {
                //3
                char recvBuf[512] = {0};
                int recvLen = 0;
                unsigned char* RevTemp = NULL;
                ret = SAMCAR1_APDU(g_dev_hd, (char*)cmd->send_buf, (char*)recvBuf, gErrMsg);
                recvLen = strlen(recvBuf);
                RevTemp = cmd->recv_buf;
                hex2dec((char*)recvBuf, recvLen, cmd->recv_buf, (int&)cmd->recv_len);
                cmd->recv_buf = RevTemp;
            } else {
                //4
                //unsigned char ucCmd[512];
                //int  iCmdLen=0;
                char recvBuf[512] = {0};
                int recvLen = 0;
                unsigned char* RevTemp = NULL;
                //hex2dec((char*)cmd->send_buf,cmd->send_len,ucCmd,iCmdLen);
                ret = SAMCAR1_APDU(g_dev_hd, (char*)cmd->send_buf, (char*)recvBuf, gErrMsg);
                recvLen = strlen(recvBuf);
                RevTemp = cmd->recv_buf;
                hex2dec((char*)recvBuf, recvLen, cmd->recv_buf, (int&)cmd->recv_len);
                cmd->recv_buf = RevTemp;
            }
        }
    } else if(t == KS_SIMCARD) {
#if 0
        unsigned char ucCmd[512];
        int  iCmdLen=0;
        ucCmd[0] = 0xA2;
        ucCmd[1] = 0x33;
        if(cmd->cmd_type == 0) {
            memcpy(ucCmd+2,cmd->send_buf,cmd->send_len);
            iCmdLen = cmd->send_len + 2;
            ret = send_rfsim_cmd(ucCmd,iCmdLen,cmd->recv_buf,(unsigned char*)&recvlen);
            cmd->recv_len=recvlen;
        } else {
            hex2dec((char*)cmd->send_buf,cmd->send_len,ucCmd+2,iCmdLen);
            iCmdLen += 2;
            ret = send_rfsim_cmd(ucCmd,iCmdLen,cmd->recv_buf,(unsigned char*)&recvlen);
            cmd->recv_len=recvlen;
        }
#else
        char ucCmd[512] = {0};
        char reCmd[512] = {0};
        int  iCmdLen=0;
        int revLen = 0;
        if ( !strncmp( (char*)cmd->send_buf, "805E000207", 10) ) {
            strcat((char*)cmd->send_buf, "08");
            cmd->send_len+=2;
        }

        if ( !strncmp( (char*)cmd->send_buf, "807400021A", 10) ) {
            strcat((char*)cmd->send_buf, "14");
            cmd->send_len+=2;
        }

        if ( !strncmp( (char*)cmd->send_buf, "807C010212", 10) ) {
            strcat((char*)cmd->send_buf, "2B");
            cmd->send_len+=2;
        }


        if ( !strncmp( (char*)cmd->send_buf, "8476000012", 10) ) {
            strcat((char*)cmd->send_buf, "04");
            cmd->send_len+=2;
        }
        if (cmd->cmd_type == 0) {
            unsigned char* RevTemp = NULL;
            RevTemp = cmd->recv_buf;
            dec2hex(cmd->send_buf, cmd->send_len, ucCmd);
            ret = RFSIMCARD_APDU(g_dev_hd, ucCmd,reCmd, gErrMsg);
            hex2dec(reCmd, strlen(reCmd), cmd->recv_buf, (int&)cmd->recv_len);
            cmd->recv_buf = RevTemp;
        } else {
            unsigned char* RevTemp = NULL;
            RevTemp = cmd->recv_buf;
            if ( !strncmp("00B09500", (char*)cmd->send_buf, 8) ) {
                strcat((char*)cmd->send_buf, "14");
            }
            ret = RFSIMCARD_APDU(g_dev_hd, (char*)cmd->send_buf,reCmd, gErrMsg);
            hex2dec(reCmd, strlen(reCmd), cmd->recv_buf, (int&)cmd->recv_len);
            cmd->recv_buf = RevTemp;
        }
#endif
    } else {
        // 接触式
#if 0	//end del by chen 2012-01-16
        if(dev->cpuport == CARDSLOT_RF) {
            return KS_CMDERROR;
        } else {
#endif	//end del by chen 2012-01-16
            //GET_DECARD_SLOT(dev,dev->cpuport);

            if(cmd->cmd_type == 0) {
                //5
                unsigned char cmpBuf1[100] = {0};
                unsigned char cmpBuf2[100] = {0};
                unsigned char cmpBuf3[100] = {0};
                int cmpLen1 = 0;
                int cmpLen2 = 0;
                int cmpLen3 = 0;
                char recvBuf[512] = {0};
                int recvLen = 0;
                char sendBuf[200] = {0};
                char sendLen = 0;
                unsigned char* RevTemp = NULL;
#if 1
                hex2dec("80FA020020", 10, cmpBuf1, cmpLen1);
                if ( !(memcmp(cmpBuf1, cmd->send_buf, cmpLen1)) ) {

                    dec2hex(cmd->send_buf, 37, sendBuf);
                }
                ret = SAMCAR1_APDU(g_dev_hd,sendBuf , recvBuf, gErrMsg);
                //g_flag = 1;
#else
                hex2dec("80FA0200205F3131313131313131000000000000000000000000001EE6B790201508141000", strlen("80FA0200205F3131313131313131000000000000000000000000001EE6B790201508141000"), cmpBuf1, cmpLen1);
                hex2dec("80FA02002020110814000020001111110007D00013880A12D6870000000000000000000000", strlen("80FA02002020110814000020001111110007D00013880A12D6870000000000000000000000"), cmpBuf2, cmpLen2);
                hex2dec("80FA02002000D5C5C8FD350000000000000000000000000000000000000000000000000000", strlen("80FA02002000D5C5C8FD350000000000000000000000000000000000000000000000000000"), cmpBuf3, cmpLen3);
                if ( !memcmp(cmpBuf1, cmd->send_buf, cmpLen1) ) {
                    ret = CPUCARD_APDU(g_dev_hd, "80FA0200205F3131313131313131000000000000000000000000001EE6B790201508141000", recvBuf, gErrMsg);
                } else if ( !memcmp(cmpBuf2, cmd->send_buf, cmpLen2) ) {
                    ret = CPUCARD_APDU(g_dev_hd, "80FA02002020110814000020001111110007D00013880A12D6870000000000000000000000", recvBuf, gErrMsg);
                } else if ( !memcmp(cmpBuf3, cmd->send_buf, cmpLen3) ) {
                    ret = CPUCARD_APDU(g_dev_hd, recvBuf, "80FA02002000D5C5C8FD350000000000000000000000000000000000000000000000000000", gErrMsg);
                } else {
                    //dec2hex(cmd->send_buf, cmd->send_len, sendBuf);
                    ret = CPUCARD_APDU(g_dev_hd, recvBuf, (char*)cmd->send_buf, gErrMsg);
                }
#endif
                recvLen = strlen(recvBuf);
                RevTemp = cmd->recv_buf;
                hex2dec((char*)recvBuf, recvLen, cmd->recv_buf, (int&)cmd->recv_len);
                cmd->recv_buf = RevTemp;
            } else {
                //6
                //unsigned char ucCmd[512];
                //int  iCmdLen=0;
                char recvBuf[512] = {0};
                int recvLen = 0;
                unsigned char* RevTemp = NULL;
                //hex2dec((char*)cmd->send_buf,cmd->send_len,ucCmd,iCmdLen);
                if ( !strncmp((char*)cmd->send_buf, "801A040110", 10) ) {
                    strncpy((char*)cmd->send_buf , "801A440110", 10);
                }
                ret = SAMCAR1_APDU(g_dev_hd, (char*)cmd->send_buf, (char*)recvBuf, gErrMsg);
                recvLen = strlen(recvBuf);
                RevTemp = cmd->recv_buf;
                hex2dec((char*)recvBuf, recvLen, cmd->recv_buf, (int&)cmd->recv_len);
                cmd->recv_buf = RevTemp;
            }
            //}//del by chen 2012-01-16
        }
        if(ret) {
            cmd->cmd_retcode = 0;
            TRACE_ERR("执行指令错误,type["<<t<<"]");
            GetErrMsgByErrCode(ret,gErrMsg);
            strcpy(cmd->cmd_retmsg,gErrMsg);
            return KS_CMDERROR;
        }
        //if(cmd->recv_len < 2)
        //{
        //	cmd->cmd_retcode = 0;
        //	strcpy(cmd->cmd_retmsg,"读卡器读返回数据错误");
        //	cmd->cmd_retcode = 2;
        //	return KS_CMDERROR;
        //}
        sw1 = cmd->recv_buf[cmd->recv_len-2];
        sw2 = cmd->recv_buf[cmd->recv_len-1];
        if(sw1 != 0x90 && sw1 != 0x61) {
            ret = sw1;
            ret = ret*256 + sw2;
            cmd->cmd_retcode = ret;
            TRACE_ERR("执行指令返回状态错误,sw["<<std::hex<<(int)sw1<<" "<<(int)sw2<<"]");
            return cmd->cmd_retcode;
        }
        if(sw1 == 0x61 && sw2 != 0x00) {
            // 61XX ,调用 00C0 取后续数据
            TRACE_ERR("自动获取后续数据");
            memset(&innerCmd,0,sizeof innerCmd);
            innerCmd.send_len = sprintf(szCmd,"00C00000%02X",sw2);
            innerCmd.send_buf = (unsigned char*)szCmd;
            innerCmd.recv_buf = cmd->recv_buf;
            innerCmd.cmd_type = 1; // 16 hex
            ret = cpucard_cmd(dev,&innerCmd,t);
            if(ret==0) {
                cmd->recv_len = innerCmd.recv_len;
            }
            cmd->cmd_retcode = innerCmd.cmd_retcode;
            return ret;
        }
        return 0;
    }

    int KSAPI config_card(ks_reader_dev_t *dev,KS_CPUCARD_TYPE t) {
        return -1;
#if 0
        if(!g_dev_hd)
            return KS_PORT_NOTOPEN;
        if(t == CPUCARD_A)
            return dc_config_card(g_dev_hd,'A');
        else
            return dc_config_card(g_dev_hd,'B');
#endif
    }
    int KSAPI card_type() {
        return g_lastCardType;
    }
    void KSAPI set_logger(void *para) {
        KS_Log_Tracer::instance((KS_Log_Tracer*)para);
    }
Exemplo n.º 26
0
int makepaysenddata(payelect &Tdata,kst_ald_pay &pay)
{
   char log[1024]="[gateway_receive]支付请求:";
  char strlog[1024]="";
  char str[1024]="";
  char mdstr[1024]="";
  int offset;
  unsigned  char  inmd5[105]="";
  unsigned char soutmd5[32]="";
  char signature[33]="";
  kst_ald_pay *ald_pay=&pay;
  payelect *query=&Tdata;
  memset(query,0,sizeof(query));
  strncpy(query->discern,"1",1);
  strncpy(str,query->discern,sizeof(query->discern)); 
  strcat(strlog,str);
  strncpy(query->length,"0142",4);
  strncpy(str,query->length,sizeof(query->length)); 
  strcat(strlog,str);
  strncpy(query->type,"0002",4);
  strncpy(str,query->type,sizeof(query->type)); 
  strcat(strlog,str);
  strncpy(query->bitmap,"0000000000000000",16);
  strncpy(str,query->bitmap,sizeof(query->bitmap));
  strcat(strlog,str);
  strncpy(query->roomname,ald_pay->payaccount,sizeof(query->roomname));
  strncpy(str,query->roomname,sizeof(query->roomname));
  strcat(strlog,str);
  strncpy(query->account,ald_pay->account,sizeof(query->account)); 
  strncpy(str,query->account,sizeof(query->account));
  strcat(strlog,str);
  strncpy(query->money,ald_pay->payamt,sizeof(query->money));
  strncpy(str,query->money,sizeof(query->money));
  strcat(strlog,str);
  strncpy(query->datetime,ald_pay->datetime,sizeof(query->datetime));
  strncpy(str,query->datetime,sizeof(query->datetime));
  strcat(strlog,str);  
  strncpy(query->tracenum,ald_pay->rfn,sizeof(ald_pay->rfn)); 
  strncpy(str,query->tracenum,sizeof(query->tracenum));
  strcat(strlog,str);
  strncpy(query->retnum,"    ",4);
  strncpy(str,query->retnum,sizeof(query->retnum));
   strcat(strlog,str); 
  strncpy(query->station,ald_pay->trcd,sizeof(query->station));
  strncpy(str,query->station,sizeof(query->station));
  strcat(strlog,str);
  offset=0;
  memcpy(mdstr,query->type,4);
  offset+=4;
  memcpy(mdstr+offset,query->bitmap,16);
  offset+=16;
  memcpy(mdstr+offset,query->roomname,20);
   offset+=20;
  memcpy(mdstr+offset,query->account,22);
   offset+=22;
  memcpy(mdstr+offset,query->money,7);
   offset+=7;
  memcpy(mdstr+offset,query->datetime,10);
   offset+=10;
  memcpy(mdstr+offset,query->tracenum,18);
   offset+=18;
  memcpy(mdstr+offset,query->retnum,4);
   offset+=4;
  memcpy(mdstr+offset,query->station,4);
   offset+=4;
  memcpy(inmd5,mdstr,105);
  memset(query->signature,0,sizeof(query->signature));
  CalcMD5(inmd5,sizeof(inmd5),soutmd5);
  dec2hex(soutmd5,16,signature);
  memcpy(query->signature,signature,32);
  strncpy(str,query->signature,sizeof(query->signature));
  strcat(strlog,str); 				  
  strcat(log,strlog);
  WriteLog(log);
  
  return 0;
}
Exemplo n.º 27
0
static int packege_elec_request(ST_PACK *in_pack,int flag,char *send_data){
	int ret;
	ext_elect_req_t* elect_req_t;
	elect_req_t=(ext_elect_req_t*)send_data;
	double money=0;			//充值金额
	char serialno[10]="";
	char sysdate[11]="";
	char systime[9]="";
	char sysdatetime[20]="";
	unsigned char buf[106]="";
	unsigned char soutmd5[16]="";
	char outmd5[32]="";
	T_t_pif_card	tCard;
	memset(&tCard,0,sizeof(tCard));
	if(flag==1){//房间查询不加密
		memcpy(elect_req_t->prix,"0",1);
	}else{
		memcpy(elect_req_t->prix,"1",1);
	}
	
	memcpy(elect_req_t->length,"0141",4);	
	
	if(flag==1){
		memcpy(elect_req_t->type,"0001",4);
		
	}else if(flag==2){
		memcpy(elect_req_t->type,"0002",4);
	}

	memset(elect_req_t->bitery,'0',sizeof(elect_req_t->bitery));
	sprintf(elect_req_t->room,"%-20s",in_pack->saddr);
	ret=DB_t_pif_card_read_by_card_id(in_pack->lvol0, &tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			ret=E_CARDNO_NOT_EXIST;
		else
			ret=E_DB_CARD_R;
		return ret;
	}
	sprintf(elect_req_t->cutid,"%-22d",tCard.cosumer_id);	
	money = in_pack->damt1;
	int i_money=D2I(D4U5(money*100,0));
	sprintf(elect_req_t->money,"%07d",i_money);
	ret=get_datetime_from_db(sysdate,systime);
	if(ret)
	{
		writelog(LOG_ERR,"get_datetime_from_db error,error code=[%d]",ret);
		getsysdate(sysdate);
		getsystime(systime);
	}
	strcpy(sysdatetime,sysdate+4);
	strcat(sysdatetime,systime);
	memcpy(elect_req_t->datetime,sysdatetime,10);
	memcpy(elect_req_t->tracenum,sysdate,8);
	sprintf(serialno,"%010d",in_pack->lvol6);
	memcpy(elect_req_t->tracenum+8,serialno,10);
	memcpy(elect_req_t->retnum,"0000",4);
	memcpy(elect_req_t->clientid,"0001",4);
	memset(outmd5,'0',32);
	if(flag==1){
		sprintf(elect_req_t->signcheck,"%s",outmd5);
	}else if(flag==2){
		memcpy(buf,elect_req_t->type,105);	
		writelog(LOG_ERR,"buf data=[%s]",buf);
		CalcMD5(buf,105,soutmd5);
		dec2hex(soutmd5,16,outmd5);
		writelog(LOG_ERR,"outmd5 data=[%s]",outmd5);
		sprintf(elect_req_t->signcheck,"%s",outmd5);
	}	
	
	
	return 0;
	
}
Exemplo n.º 28
0
/***********************************************************************
		module		:	[WIFI]
		function		:	[发送数据]
  		return		:	[无]
		comment	:	[全局普通函数]
		machine		:	[EH-0818]
		language	:	[CHN]
 		keyword		:	[WIFI]
		date			:	[11/07/27]
 		author		:	[chen-zhengkai]
************************************************************************/
void sendRecords()
{
	char retStr[20] = {0};
	char temp[20] = {0};
	int templen = 0;
	//unsigned char data_buffer[1000] = {0};	//要传送的数据
	unsigned char aBuffer[200] = {0};	
	unsigned char rb8583[50] = {0};
	unsigned char send_buf[200] = {0};	//每次上传数据数组
	int send_len = 0;
	//unsigned char* pdBuffer = NULL;		//每次上传数据指针
	USER_INFO* pinfo = NULL;
	char infotemp[10] = {0};
	unsigned long	db_cnt = 0;					//数据库记录数
	unsigned short	send_cnt = 0;				//上传次数
	char* pTemp = NULL;
	char	rec_flag = 0;
	
	strcpy(retStr, "数据上传成功");
	db_cnt = DB_count_records(0);	//返回数据库已记录的条数(包括已删除)
	if (!db_cnt) {
		strcpy(retStr, "数据库无记录");
	}
	else {
		DispStr_CE(0,6,"连接上传中",DISP_CENTER|DISP_CLRSCR);
		DispStr_CE(0,8,"请耐心等待",DISP_CENTER);
		DispStr_CE(0,10,"按F1退出...",DISP_CENTER);

	//	for (send_cnt = 0; send_cnt < db_cnt; send_cnt++) {
			pinfo = (USER_INFO*)DB_jump_to_record(ATTENDANCE_INDEX, send_cnt, &rec_flag);
			if (rec_flag) {	//记录被删除
	//			continue;
			}
			dec2hex(pinfo->phyNo, 4, infotemp);
			memcpy(rb8583, infotemp,  8);		//物理卡号
			memcpy(rb8583+8, pinfo->time, 16);	//考勤时间
			atd_pack(aBuffer, rb8583, 24);
			hex2dec(aBuffer, 58, (unsigned char*)send_buf, &send_len);
			//send_len = 58;
#if 0
			if (NaNo_OK !=  CWiFi_Write(g_pHandle[0], send_buf,  send_len+1) ){	//注:长度必须多一字符
				strcpy(retStr, "数据上传失败");
				break;
			}
#else
			char tempBuf[300] = {0};
			//memcpy(tempBuf, "008A600031000008000038000001C00010000001090931201104084444444444444444444431323334353630303031393930323130333131343030313030303139390072A00000000386980701202020202020203030303030303030303030303030303030303030303030303030303030304646303130303030303130312020202020203030303030303030", sizeof("008A600031000008000038000001C00010000001090931201104084444444444444444444431323334353630303031393930323130333131343030313030303139390072A00000000386980701202020202020203030303030303030303030303030303030303030303030303030303030304646303130303030303130312020202020203030303030303030"));
			memcpy(tempBuf, "ABCDEFGHIJK", 11);
			int m = strlen(tempBuf);
			//hex2dec(tempBuf, strlen(tempBuf), (unsigned char*)send_buf,  &m);
			if (NaNo_OK !=  CWiFi_Write(g_pHandle[0], tempBuf,  11+1) ){	//注:长度必须多一字符
				strcpy(retStr, "数据上传失败");
		//		break;
			}
#endif
			if( KEY_F1 == KEY_Read()) {
				strcpy(retStr, "数据上传中断");
			//	break;
			}
			Sys_Delay_MS(100);	//延时100毫秒
	//	}
	}
	DispStr_CE(0,6,retStr,DISP_CENTER|DISP_CLRSCR);
	DispStr_CE(0,8,"按任意键返回",DISP_CENTER);
	delay_and_wait_key( 3, EXIT_KEY_ALL, 0 );
}
Exemplo n.º 29
0
int main(int argc, char **argv) {
    FILE *in;
    dec2hex(stdin);
}
Exemplo n.º 30
0
// function request_card 
static int KSAPI request_card(ks_reader_dev_t *dev,char* phyid,KS_CARD_TYPE t)
{
	int ret,i;
	unsigned long snr;
	unsigned short tagtype;
	unsigned char size,sw1,sw2;
	uint8 ucCardPhyID[8];
	uint8 rData[256];
	uint8 cmd[256];
	int len,rlen,retries;
	//g_lastCardType = 0;
	gErrMsg[0]=0;
	if(!g_dev_hd)
	{
		ret=open_device(dev);
		if(ret)
			return ret;
	}
	if(!g_dev_hd)
	{
		return KS_PORT_NOTOPEN;
	}
	/*
	if(KS_SIMCARD ==  t )
	{
		if(KS_SIMCARD == g_lastCardType || 0 == g_lastCardType)
		{
			// ÉÏ´ÎÑ°¿¨ÊÇÊÖ»ú¿¨£¬²»ÓÃreset
		}
		if(dev->cpuport == CARDSLOT_RF)
		{
			len = 5;
			retries = 10;
			while(--retries > 0)
			{
				memset(rData,0,sizeof(rData));
				memcpy(cmd,"\x90\xB0\x04\x00\x00",5);
				if(do_send_recv_pos_cmd(cmd,5,rData,rlen,300))
				{
					if(rData[0] == 0x9C && rData[1] == 0x02)
					{
						// read success
						break;
					}
					else if(rData[0] == 0x9C && rData[1] == 0x03)
					{

						Sleep(100); // 100ms
					}
				}
			}
			if(retries == 0)
			{
				TRACE_ERR("¼ì²âRFUIM¿¨³¬Ê±");
				return KS_REQUESTCARD;
			}
			if((rData[2] & 0xF0) != 0x10) // 2.4 G ¿¨
			{
				TRACE_ERR("¼ì²âRFUIM״̬´íÎó,code["<<(int)rData[2]<<"]");
				return KS_REQUESTCARD;
			}
			memcpy(ucCardPhyID,rData+3,8); // physical id
			dec2hex(ucCardPhyID,8,phyid);
			phyid[16]=0;
			dev->cardtype = KS_SIMCARD;
			g_lastCardType = dev->cardtype;
			return 0;
		}
		else
		{
			TRACE_ERR("·¢ËÍÊÖ»ú¿¨Ñ°¿¨Ö¸Áî,²ÎÊý´íÎó");
			return KS_REQUESTCARD;
		}
	}
	else if(KS_MFCARD ==t || KS_CPUCARD == t || KS_FIXCARD == t)
	{
		len = 5;
		retries = 3;
		if(KS_SIMCARD == g_lastCardType || 0 == g_lastCardType)
		{
			// ÉÏ´ÎÑ°¿¨ÊÇÊÖ»ú¿¨£¬²»ÓÃreset
		}
		else
		{
			reset(dev,300);
		}
		while(--retries > 0)
		{
			memcpy(cmd,"\x90\xB0\x04\x52\x00",5);
			memset(rData,0,sizeof(rData));
			if(do_send_recv_pos_cmd(cmd,5,rData,rlen,300))
			{
				if(rData[0] == 0x9C && rData[1] == 0x02)
				{
					// read success
				}
				else if(rData[0] == 0x9C && rData[1] == 0x03)
				{
					Sleep(100); 
					continue;
				}
			}
			else
			{
				TRACE_ERR("¼ì²âIC¶Á¿¨Æ÷ÎÞÓ¦´ð");
				return KS_REQUESTCARD;
			}

			if(rData[2] != 0x45)
			{
				TRACE_ERR("¼ì²âIC״̬´íÎócode["<<(int)rData[2]<<"]");
				return KS_REQUESTCARD;
			}
			if(memcmp(rData+7,"\x04\x00",2) == 0
				|| memcmp(rData+7,"\x02\x00",2) == 0)
			{
				// m1 ¿¨
				if(rData[9] != 0x08)
				{
					// 7+1 ¿¨
					dev->cardtype = KS_FIXCARD;
				}
				else
				{
					dev->cardtype = KS_MFCARD;
				}
				break;
			}
			else if(memcmp(rData+7,"\x08\x00",2) == 0)
			{
				// CPU ¿¨
				dev->cardtype = KS_CPUCARD;
			}
			else 
			{
				TRACE_ERR("¼ì²âIC¿¨Ê±£¬ÎÞ·¨Ê¶±ð¿¨ÀàÐÍ");
				return KS_REQUESTCARD;
			}
		}
		if(retries == 0)
		{
			TRACE_ERR("¼ì²âIC¿¨³¬Ê±");
			return KS_REQUESTCARD;
		}
		// read success
		for(i = 0;i < 4; ++i)
			ucCardPhyID[3-i] = rData[3+i]; // physical id

		if(dev->cardtype == KS_FIXCARD || dev->cardtype == KS_CPUCARD)
		{
			// CPU ¿¨reset
			if(t == KS_CPUCARD || t == KS_FIXCARD)
			{
				len = 5;
				memcpy(cmd,"\x40\x50\x00\x00\x00",len);
				if(do_send_recv_cpu_cmd(cmd,len,rData,rlen,300))
				{
					TRACE_ERR("¼ì²âIC¿¨ÎªCPU¿¨£¬CPU¿¨¸´Î»´íÎó");
					return KS_REQUESTCARD;
				}
			}
		}		
		dec2hex(ucCardPhyID,4,phyid);
		phyid[8] = 0;
		g_lastCardType = dev->cardtype;
		return 0;
	}
	*/
	if(g_lastCardType != 0 ) //&& g_lastCardType != KS_SIMCARD && g_lastCardType != KS_MFCARD)
	{
		reset(dev,300);
	}
	len = 5;
	retries = 3;
	while(--retries > 0)
	{
		memcpy(cmd,"\x90\xB0\x04\x52\x00",5);
		memset(rData,0,sizeof(rData));
		if(do_send_recv_pos_cmd(cmd,5,rData,rlen,300))
		{
			if(rData[0] == 0x9C && rData[1] == 0x02)
			{
				// read success
			}
			else if(rData[0] == 0x9C && rData[1] == 0x03)
			{
				Sleep(100); 
				continue;
			}
		}
		else
		{
			TRACE_ERR("¼ì²âIC¶Á¿¨Æ÷ÎÞÓ¦´ð");
			return KS_REQUESTCARD;
		}
		// Èç¹ûÊÇÊÖ»ú¿¨
		if(rData[2] != 0x45)
		{
			// SIMCARD
			memcpy(ucCardPhyID,rData+3,8); // physical id
			dec2hex(ucCardPhyID,8,phyid);
			phyid[16]=0;
			dev->cardtype = KS_SIMCARD;
			g_lastCardType = dev->cardtype;
			return 0;
		}
		else
		{
			if(memcmp(rData+7,"\x04\x00",2) == 0
				|| memcmp(rData+7,"\x02\x00",2) == 0)
			{
				// m1 ¿¨
				if(rData[9] == 0x08)
				{
					// mifare one
					dev->cardtype = KS_MFCARD;
				}
				else if(rData[9] == 0x18)
				{
					// mifare one
					//if(memcmp(rData+7,"\x02\x00",2) == 0)  S70
					dev->cardtype = KS_MFCARD;
				}
				else if(rData[9] != 0x28)
				{
					// 7+1 ¿¨
					dev->cardtype = KS_FIXCARD;
				}
				else
				{
					dev->cardtype = KS_CPUCARD;
				}
			}
			else if(memcmp(rData+7,"\x08\x00",2) == 0)
			{
				// CPU ¿¨
				dev->cardtype = KS_CPUCARD;
			}
			else 
			{
				TRACE_ERR("¼ì²âIC¿¨Ê±£¬ÎÞ·¨Ê¶±ð¿¨ÀàÐÍ");
				return KS_REQUESTCARD;
			}
			// read success
			for(i = 0;i < 4; ++i)
				ucCardPhyID[3-i] = rData[3+i]; // physical id
			dec2hex(ucCardPhyID,4,phyid);
			phyid[8] = 0;
			g_lastCardType = dev->cardtype;
			return 0;
		}
	}
	if(retries == 0)
	{
		TRACE_ERR("¼ì²âIC¿¨³¬Ê±");
		return KS_REQUESTCARD;
	}
	
	
	TRACE_ERR("´«Èë²ÎÊýÓÐÎó");
	return KS_REQUESTCARD;
}