'wipi'에 해당되는 글 1건

  1. 2010.07.16 [wipi 2.0] - smart card i/o 하자

wipi 2.0 표준 api 를 보면 IODevice 라는 넘이 존재한다. 이넘을 사용해서 smart card(usim) 에 read/write 할 수 있다.

connect
- IODevice 클래스를 사용해서 chip에 connect 하고 ATR 값을 읽어온다.
/**
     * Connect 하면 ATR 값을 Chip에서 읽을 수 있다.
     *
     * @throws IOException
     */
    public static void connect() throws IOException {       
        byte bAtr[] = Util.byteSet(50, (byte)0x20);
       
        if(iod == null) {
            try {
                iod = new IODevice("1ChipCard", 0, bAtr);
            } catch (IOException e) {
                close();
                System.out.println("[OpCard Connect Exception] - " + e);   
                throw e;
            } catch (Exception e) {
                close();
                System.out.println("[OpCard Connect Exception] - " + e);   
                throw new IOException("Conect Error!");
            }
            atr = Util.byteArr2HexaStr(Util.byteTrim(bAtr));   
        }       
       
        System.out.println("[Debug] - OpCard Connect Success!"); 
        System.out.println("[Debug] ATR - " + atr); 
    }       

apdu send
- chip에 apdu 명령을 보낸다.
/**
     *
     * @param cmd (cls, ins, p1, p2, lc , data, le)
     * @return
     * @throws IOException
     */
    public static String send(byte[] cmd) throws IOException {       
        String szBuf = null;
        int ret = 0;
        byte buf[] = new byte[255];
       
        if(iod != null) {
            try {
                iod.write(cmd);
                ret = iod.read(buf);                       
            } catch (IOException e) {
                close();
                System.out.println("[OpCard send Exception] - " + e);   
                throw e;
            } catch (Exception e) {
                close();
                System.out.println("[OpCard send Exception] - " + e);   
                throw new IOException("Send Error!");
            }
        }
       
        szBuf = Util.toString(buf, 0, ret);  // byte -> Hex String 변환
        System.out.println("[Debug] ret - " + ret); 
        System.out.println("[Debug] buf - " + szBuf); 
       
        return szBuf.trim();
    }

close
- connection 종료
public static void close() {       
       
        if (iod != null) {
            try {
                iod.close();
                iod = null;
            } catch (IOException e) {
                iod = null;
                System.out.println("[OpCard Close Exception] - " + e);   
            } catch (Exception e) {
                iod = null;
                System.out.println("[OpCard close Exception] - " + e);   
            }
        }    
        System.out.println("[Debug] - OpCard Close Success!"); 
    }

흠... 위 코드는 SKT wipi 폰에서 테스트 됨.
KT는 뭐.. 공개하면 안될듯 ㅋ


'java > smart card' 카테고리의 다른 글

[smart card] - smartcardio 사용하기(2)  (3) 2010.06.29
[smart card] - smartcardio 사용하기(1)  (0) 2010.06.29
Posted by 짱가쟁이
이전버튼 1 이전버튼