1WindowsµdllļУ·һ1ƫbuffer[1]Ϊͷڰ׿£ƫͳһϵͳHidD_SetFeatureԼHidD_GetFeatureн޸ġ
2.ҪεַΪ£Ϊint[1]


ɹܣ
USB
	A ϵ APDU
	B ϵ APDU 
	CPU ϵ APDU
	
	
	
	
	public int SSSE_ReadPeopleInfo( 
			byte[]  KH,       
			byte[]  SHBZHM,      
			byte[]  XM,    
			byte[]  XMKZ, 
			byte[]  XB,
			byte[]  MZ,
			byte[]  CSRQ, 
			byte[]  FKRQ,   
			byte[]  KYXQ,  
			byte[]  ERR 
			){
		String strERR=null;
		int re=0;
		int i=0;
		byte[] Response_APDU=new byte[255];
		byte[] sATR=new byte[30];
		byte[] atr = new byte[18];
		int len_ATR=0;
		
		len_ATR = ICC_Reader_pre_PowerOn(SLOT_USER, sATR);
		if(len_ATR<0)
		{
			strERR="籣ϵʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -1;
		}
		
	
		for(i=len_ATR - 8; i<len_ATR; i++ )
		{
			atr[i-len_ATR+8] = sATR[i]; //ȡATR
		}
	
		
		String cmd = "";
		cmd = "00A404000F7378312E73682EC9E7BBE1B1A3D5CF";
		re=ICC_Reader_Application(SLOT_USER,20,HexString2Bytes(cmd),Response_APDU);
		if(re<0)
		{
			/*if(sATR[len_ATR-2] == (byte)0x73 && sATR[len_ATR-1] == (byte)0x68)
			{
				re= ICC_Reader_pre_PowerOn(SLOT_USER, sATR); //ϺҪϵ
				if(re<0)
				{
					strERR="籣ϵʧ";
					System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
					return -1;
				}
			}*/
			return -15;
		}
		
		cmd="00A4000002EF05";
		re=ICC_Reader_Application(SLOT_USER,7,HexString2Bytes(cmd),Response_APDU);
		if(re<0 )//|| Response_APDU[re-2] != (byte)0x90
		{
			cmd="00A4020002EF05";
			re=ICC_Reader_Application(SLOT_USER,7,HexString2Bytes(cmd),Response_APDU);
			if(re<0 )//|| Response_APDU[re-2] != (byte)0x90
			{
				strERR="ѡ05ʧ";
				System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
				return -5;
			}
		}
		
		cmd="00B2010012";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
		{
			strERR="ʶʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -1;
		}
		
		byte[] tempc = new byte[10];
		System.arraycopy(Response_APDU, 2, tempc, 0, 3);
		String scsdm = arrayByteToString(tempc, 3);

	/*	re = ICC_Reader_pre_PowerOn(PSAM_USER,Response_APDU);
		if(re<0)
		{
			strERR= "籣רPSAM";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -105;
		}
		re = ExterAuthen(scsdm.getBytes(), atr);
		if(re != 0)
			return -106;
		*/
		
		cmd="00B2050006";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 )//
		{
			strERR="ʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		//	return -3;
		}
		tlvRespToOutput(CN_style,re,Response_APDU,FKRQ);
		
		
		cmd="00B2060006";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
		{
			strERR="ʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		//	return -1;
		}
		tlvRespToOutput(CN_style,re,Response_APDU,KYXQ);/**/
		
		
		cmd="00B207000B";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 || Response_APDU[re-2] != (byte)0x90)
		{
			strERR="ʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -6;
		}
		tlvRespToOutput(AN_style,re,Response_APDU,KH);
		
		//EF06
		cmd="00A4000002EF06";
		re=ICC_Reader_Application(SLOT_USER,7,HexString2Bytes(cmd),Response_APDU);
		if(re<0 || Response_APDU[re-2] != (byte)0x90)
		{
			cmd="00A4020002EF06";
			re=ICC_Reader_Application(SLOT_USER,7,HexString2Bytes(cmd),Response_APDU);
			if(re<0 || Response_APDU[re-2] != (byte)0x90)
			{
				strERR="ѡ06ʧ";
				System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
				return -2;
			}
		}
		
		cmd="00B2090020";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 || Response_APDU[re-2] != (byte)0x90)
		{
			strERR="ʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -3;
		}
		tlvRespToOutput(AN_style,re,Response_APDU,XM);
		
		cmd="00B2080014";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 || Response_APDU[re-2] != (byte)0x90)
		{
			strERR="֤ʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -4;
		}
		tlvRespToOutput(AN_style,re,Response_APDU,SHBZHM);
		
		cmd="00B20A0003";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		if(re<0 )
		{
			strERR="Աʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -8;
		}
		tlvRespToOutput(AN_style,re,Response_APDU,XB);
		
		cmd="00B20B0003";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		
		byte[] mzdm = new byte[3];
		tlvRespToOutput(CN_style,re,Response_APDU,MZ);	
		
		cmd="00B20D0006";
		re=ICC_Reader_Application(SLOT_USER,5,HexString2Bytes(cmd),Response_APDU);
		
		tlvRespToOutput(CN_style,re,Response_APDU,CSRQ);
		
		return 0;
	}

	
	
	
	
		/*ϵ*/
public int powernOnHealthCard(){
	
	int reval;
	reval = PICC_Reader_SetTypeA();
	if (reval != IFD_OK) {
		return -1;
	}
	reval = PICC_Reader_Request();
	if (reval != IFD_OK) {
		return -2;
	}
	reval = PICC_Reader_anticoll(RecvBuffer);
	if (reval !=  IFD_OK) {
		return -3;
	}
	reval = PICC_Reader_Select((byte) 0x41);
	if (reval !=  IFD_OK) {
		return -4;
	}
	RecvLength[0] = PICC_Reader_PowerOnTypeA(RecvBuffer);
	if (RecvLength[0] <= 0) {
		return -5;
	} else {
		//cardNo
		System.arraycopy(RecvBuffer, 5, cardNo, 0, 8);
		
		String  strERR="";
		int re=0;
		byte[] Response_APDU=new byte[512];
		String cmd="00A4000002DDF1";
		re=PICC_Reader_Application(7,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		Log.d(TAG, "ѡDDF1ʧ");
		return -1;
	}
	cmd="00A4000002EF05";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
{
	strERR="ѡSSSE-EF05ʧ";
	Log.d(TAG, "ѡDDEF05ʧ");
	return -2;
}
//Ӧóд
	cmd="00b2390005";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡӦóдʧ";
		Log.d(TAG, "ȡдʧ");
		return -12;
	}

	byte[] YYCSDM = new byte[50];
	tlvRespToOutput(CN_style,re,Response_APDU,YYCSDM);
	Arrays.fill(cityCode,(byte) 0x30);
	System.arraycopy(YYCSDM, 0, cityCode, 0, 2);

		
	return 1;
	}
}	
	
	
	public int readIssuerAgency(	byte[]  KLB,      
												byte[]  GFBB,    
												byte[]  FKJGDM,   
												byte[]  FKJGZS,   
												byte[]  FKJGMC,   
												byte[]  FKRQ,     
												byte[]  KH,       
												byte[]  AQM,      
												byte[]  XPXLH,    
												byte[]  YYCSDM,   
												byte[]  ERR ){


//		byte[]  KLB= new byte[4];    //
//		byte[]  GFBB= new byte[16];   //淶汾
//		byte[]  FKJGDM= new byte[64]; //ʼ
//		byte[]  FKJGZS= new byte[360]; //֤
//		byte[]  FKJGMC= new byte[64]; //ʼ
//		byte[]  FKRQ= new byte[8];   //
//		byte[]  KH= new byte[18];      //
//		byte[]  AQM= new byte[3];      //ȫ
//		byte[]  XPXLH= new byte[10];      //оƬк
//		byte[]  YYCSDM= new byte[6];      //Ӧóд
//		byte[]  ERR = new byte[64];       //Ϣ
		//	byte[]  KYXQ= new byte[8];    //Ч
		String  strERR="";
		int re=0;
//		re = HdosUsbDevice.ICC_Reader_pre_PowerOn(slotNo, RecvBuffer);
//		if (re<=0) {
//			showString("ϵʧ");
//			return;
//		}
//		re=powernOnHealthCard();
//		if(re<0) 
//			{
//			strERR="ϵʧ";
//			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
//			return -99;
//			}
		byte[] Response_APDU=new byte[512];
			String cmd="00A4000002DDF1";
			re=PICC_Reader_Application(7,HexString2Bytes(cmd),Response_APDU);
			if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
		{
			strERR="ѡSSSEʧ";
			System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
			return -1;
		}
		cmd="00A4000002EF05";
		re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ѡSSSE-EF05ʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -2;
	}
	//
	cmd="00B2010003";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -3;
	}
	tlvRespToOutput(AN_style,re,Response_APDU,KLB);
	
	//淶汾
	cmd="00B2020006";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡĹ淶汾ʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -4;
	}
	tlvRespToOutput(AN_style,re,Response_APDU,GFBB);
	
	//
	//AN_style
	cmd="00B2030020";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -5;
	}
	tlvRespToOutput(AN_style,re,Response_APDU,FKJGMC);
	//
	//CN_style
	cmd="00B204000D";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -6;
	}
	byte[] tempFKJGDM=new byte[1024];
	tlvRespToOutput(CN_style,re,Response_APDU,tempFKJGDM);
	for(int i=0;i<1024;i++){
	if(tempFKJGDM[i]==(byte)0x46) break;
	FKJGDM[i]=tempFKJGDM[i];
}
	//֤
	//CN_style
	cmd="00b20500B6";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡ֤ʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -7;
	}
//	showResultAfterUnpack(Response_APDU, re);	
	tlvRespToOutput(CN_style,re,Response_APDU,FKJGZS);
	
	//ʱ
	cmd="00b2060006";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -8;
	}
	tlvRespToOutput(CN_style,re,Response_APDU,FKRQ);
	
	//
	cmd="00b2080014";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -9;
	}
	tlvRespToOutput(AN_style,re,Response_APDU,KH);
	
	//ȫ
	cmd="00b2090005";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡȫʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -10;
	}
	tlvRespToOutput(AN_style,re,Response_APDU,AQM);
	
	// оƬк
	cmd="00b20A000C";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡоƬкʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -11;
	}
	tlvRespToOutput(AN_style,re,Response_APDU,XPXLH);
	
	// Ӧóд
	cmd="00b2390005";
	re=PICC_Reader_Application(cmd.length()/2,HexString2Bytes(cmd),Response_APDU);
	if(re<0 ||  Response_APDU[re-2]!=(byte)0x90)
	{
		strERR="ȡӦóдʧ";
		System.arraycopy(strERR.getBytes(), 0, ERR, 0, strERR.getBytes().length);
		return -12;
	}

	tlvRespToOutput(CN_style,re,Response_APDU,YYCSDM);
	Arrays.fill(cityCode,(byte) 0x30);
	System.arraycopy(YYCSDM, 0, cityCode, 0, 2);
//	for(int i=0;i<8;i++)
//	Log.i(TAG, "temp= "+Integer.toHexString(cityCode[i]&0xff));
	
	return 1;
	}
	
	/*PSAMУ*/
	public int verificationPSAM(String password){
		

		byte[] Response_APDU=new byte[512];
			//	String commandString = etCommand.getText().toString();
		String commandString="00200000";
		String passWordLenth=byteToString(password.length()/2);
		int Lenth_of_Command_APDU=commandString.length() / 2+password.length()/2+1;
		byte[] apdu = new byte[Lenth_of_Command_APDU+1];
		
				if (commandString.length() != 0) {
					apdu = HexString2Bytes(commandString+passWordLenth+password);
				}
				RecvLength[0]=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu,Response_APDU);
	//	showResultAfterUnpack(Response_APDU, RecvLength[0]);	

				
				
				if(Response_APDU[0]!=(byte)0x90){
					if(Response_APDU[0]==(byte)0x63) return Response_APDU[1];	
					else return -1;
				}
				
				
		/*ļѡ*/
		String cmd1="00A4000002";
		String cmd2="DF01";
		Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
		byte[] apdu1 = new byte[Lenth_of_Command_APDU];
		if (cmd1.length() != 0) {
			apdu1 = HexString2Bytes(cmd1+cmd2);
		}
		RecvLength[0]=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
		if(Response_APDU[0]!=(byte)0x61) return -2;
		
		return 1;
	
		
	}
	
	
	public int  readPersonalInformation(		byte[] chsXM,
																byte[] chsXB,
																byte[] chsMZ,
																byte[] chsCSRQ,
																byte[] chsSFZH
														  ){
		
		int re=0;
//		byte[] chsXM= new byte[30+1];              //
//		byte[] chsXB= new byte[2+1];               //Ա
//		byte[] chsMZ= new byte[2+1];               //
//		byte[] chsCSRQ= new byte[8+1];             //ڣYYYYMMDDʽ
//		byte[] chsSFZH= new byte[18+1];             //֤
		byte[] Response_APDU=new byte[512];
		re=SelectFile(0 , "DDF1" ,null,"EF06");
		if(re<0) return re;
		re=AuthIRK(0);//֤û IRK
		if(re<0) 
		{
			Log.d(TAG, "֤û IRK");
			return re;
		}
		String cmd="00b2010400";
		Arrays.fill(Response_APDU, (byte) 0x00);
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			Log.d(TAG, "00b2010400");
			return -1;
		}

//		Arrays.fill(chsXM, (byte) 0x00);
		tlvRespToOutput(AN_style,  re,Response_APDU ,chsXM );
		System.out.println("re=    "+re);
		for(int y=0;y<20;y++){
			 System.out.println("chsXM["+y+"]= "+Integer.toHexString(chsXM[y]&0xff));
			
		}
		
		cmd="00b2020400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		tlvRespToOutput(CN_style,  re,Response_APDU ,chsXB);	
		
		cmd="00b2030400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		tlvRespToOutput(CN_style,  re,Response_APDU ,chsMZ);	
		
		cmd="00b2040400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		tlvRespToOutput(CN_style,  re,Response_APDU ,chsCSRQ);	
		
		cmd="00b2050400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		tlvRespToOutput(AN_style,  re,Response_APDU ,chsSFZH);	
		
		
		return 0;
	}
	
	
	public int  readAddressInformation(		byte[] chsDZLB1,
																byte[] chsDZ1,
																byte[] chsDZLB2,
																byte[] chsDZ2
	  ){
		int re=0;
		
		
		
		byte[] Response_APDU=new byte[512];
		re=SelectFile(0 , "DDF1" ,"DF01","EF05");
		if(re<0) return re;
		re=AuthIRK(1);//֤û IRK
		if(re<0) return re;
		
		
		String cmd="00b2010400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		tlvRespToOutput(CN_style,  re,Response_APDU ,chsDZLB1 );
		chsDZLB1[1]=0x00;
		cmd="00b2020400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		int flag=find0x00(Response_APDU,re);
		if(flag>0) re=flag+2;
		tlvRespToOutput(AN_style,  re,Response_APDU ,chsDZ1);	
		cmd="00b2030400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		tlvRespToOutput(CN_style,  re,Response_APDU ,chsDZLB2);	
		chsDZLB2[1]=0x00;
		cmd="00b2040400";
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			return -1;
		}
		flag=find0x00(Response_APDU,re);
		if(flag>0) re=flag+2;
		tlvRespToOutput(AN_style,  re,Response_APDU ,chsDZ2);	
		
		return 0;
	}
	public int find0x00(byte[] temp,int re){
		for(int i=0;i<re;i++)
		{
			if(temp[i]==0x00) return i;
			
		}
		return 0;
	}
	
	//֤û IRK 
	//KeyID : RK_DDF1/RK_DF01/RK_DF02
	//û  д
	public int AuthIRK(int KeyID){
		Log.d(TAG, "ʼ֤RK..");
		int re ;
		byte[] Response_APDU=new byte[512];
		byte[] vRand=new byte[8];
		String cmd="0084000008";
		//ȡû
		//RecvLength[0]=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
		re=PICC_Reader_Application(cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			Log.d(TAG, "ûȡʧ");
			return -1;
		}
		System.arraycopy(Response_APDU, 0, vRand, 0, 8);
			switch(KeyID) {
			case RK_DDF1:
				cmd= "80DE473118";
				break;
			case RK_DF01:
				cmd= "80DE473218";
				break;
			case RK_DF02:
				cmd= "80DE473318";
				break;
			case RK_DF03:
				cmd= "80DE473418";
				break;
			}	
			
			byte[] apdu1 = new byte[64];
			byte[] apduKey= new byte[5];
			apduKey = HexString2Bytes(cmd);
			System.arraycopy(apduKey, 0, apdu1, 0, 5);
			System.arraycopy(cardNo, 0, apdu1, 5, 8);
			System.arraycopy(cityCode, 0, apdu1, 13, 8);
			System.arraycopy(vRand, 0, apdu1, 21, 8);
			re=ICC_Reader_Application(slotNo,29,apdu1,Response_APDU);
			if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
				Log.d(TAG, "ɢԿʧ1");
				return -1;
			}
						
			cmd="80FA00001011223344556677880000000000000000";
			re=ICC_Reader_Application(slotNo,cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
			if((Response_APDU[0]!=(byte)0x61) && (Response_APDU[1]!=(byte)0x10)){
				Log.d(TAG, "macʧ");
				return -1;
			}
			
			cmd="00C0000010";
			re=ICC_Reader_Application(slotNo,cmd.length() / 2,HexString2Bytes(cmd),Response_APDU);
			if((Response_APDU[re-2]!=(byte)0x90) && (Response_APDU[re-1]!=(byte)0x00)){
				return -1;
			}	
		byte[] temp=new byte[8];
		System.arraycopy(Response_APDU, 8, temp, 0, 8);
		for(int t=0;t<8;t++){	
			temp[t]=(byte) (temp[t]^Response_APDU[t]);
		}
		
		if (KeyID == RK_DDF1)
			cmd= "0082000411";
		else
			cmd= "0082008411";
		String cmdTemp="112233445566778801";
		apduKey = HexString2Bytes(cmd);
		System.arraycopy(apduKey, 0, apdu1, 0, 5);
		System.arraycopy(temp, 0, apdu1, 5, 8);
		System.arraycopy(HexString2Bytes(cmdTemp), 0, apdu1, 13, 9);
		re=PICC_Reader_Application(22,apdu1,Response_APDU);
		
//		for(int i=0;i<re;i++)
//			Log.i(TAG, "Resp "+Integer.toHexString(Response_APDU[i]&0xff));
		if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
			Log.d(TAG, "֤RKʧ");
			return -1;
		}
		Log.d(TAG, "֤RK");
		return 1;
	}
	public	int SelectFile(int cardType,String DFID, String ADFID, String EFID){
		
		//ѡDFĿ¼
		int Lenth_of_Command_APDU=0;
		byte[] Response_APDU=new byte[512];
		int re=0;
		if ((DFID != null) && (DFID.length() != 0))
		{

			/*ļѡ*/
			String cmd1="00A4000002";
			String cmd2=DFID;
			if(cardType==0){
					Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
					//RecvLength[0]=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
					re=PICC_Reader_Application(Lenth_of_Command_APDU,HexString2Bytes(cmd1+cmd2),Response_APDU);
//					for(int i=0;i<re;i++)
//					Log.i(TAG, "temp= "+Integer.toHexString(Response_APDU[i]&0xff));
				}
			else{
				Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
				byte[] apdu1 = new byte[Lenth_of_Command_APDU];
				if (cmd1.length() != 0) {
					apdu1 = HexString2Bytes(cmd1+cmd2);
				}
					re=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
				}
			
			if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
//				Log.i(TAG, "temp   Response_APDU[re-2]= "+Integer.toHexString(Response_APDU[re-2]&0xff));
//				Log.i(TAG, "temp1   Response_APDU[re-2]= "+Integer.toHexString(Response_APDU[re-1]&0xff));
				return -1;
			}
		}
		
		
		if ((ADFID != null) && (ADFID.length() != 0))
		{
			
			//ѡAFĿ¼
			String cmd1="00A4000002";
			String cmd2=ADFID;
			if(cardType==0){
				Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
				//RecvLength[0]=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
				re=PICC_Reader_Application(Lenth_of_Command_APDU,HexString2Bytes(cmd1+cmd2),Response_APDU);
//				for(int i=0;i<re;i++)
//					Log.i(TAG, "temp1 = "+Integer.toHexString(Response_APDU[i]&0xff));	
			}
			else{
				Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
				byte[] apdu1 = new byte[Lenth_of_Command_APDU];
				if (cmd1.length() != 0) {
					apdu1 = HexString2Bytes(cmd1+cmd2);
				}
				re=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
			}
			
			if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
//				Log.i(TAG, "temp1 Response_APDU[re-2]= "+Integer.toHexString(Response_APDU[re-2]&0xff));
//				Log.i(TAG, "temp2 Response_APDU[re-1]= "+Integer.toHexString(Response_APDU[re-1]&0xff));
				return -1;
			}
		}
		
		if ((EFID != null) && (EFID.length() != 0))
		{
			
			//ѡEFĿ¼
			String cmd1="00A4000002";
			String cmd2=EFID;
			if(cardType==0){
				Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
				//RecvLength[0]=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
				re=PICC_Reader_Application(Lenth_of_Command_APDU,HexString2Bytes(cmd1+cmd2),Response_APDU);
//				for(int i=0;i<re;i++)
//					Log.i(TAG, "temp2= "+Integer.toHexString(Response_APDU[i]&0xff));
				}
			else{
				Lenth_of_Command_APDU=cmd1.length() / 2+cmd2.length()/2;
				byte[] apdu1 = new byte[Lenth_of_Command_APDU];
				if (cmd1.length() != 0) {
					apdu1 = HexString2Bytes(cmd1+cmd2);
				}
				re=ICC_Reader_Application(slotNo,Lenth_of_Command_APDU,apdu1,Response_APDU);
			}
			
			if(re<0 ||  Response_APDU[re-2]!=(byte)0x90){
//				Log.i(TAG, "temp2 re-2 = "+Integer.toHexString(Response_APDU[re-2]&0xff));
//				Log.i(TAG, "temp1 re-2 = "+Integer.toHexString(Response_APDU[re-1]&0xff));
				return -1;
			}
		}
		
		
		return 1;
	}
	
	
	