private static byte [ ] cEmiToTP1 ( final byte [ ] frame ) { // set frame type to std/ext final int stdMaxApdu = 15 ; final int cEmiPrefix = 10 ; final boolean std = frame . length <= cEmiPrefix + stdMaxApdu ; final byte [ ] tp1 ; if ( std ) { tp1 = new byte [ frame . length - 2 ] ; int i = 0 ; // set upper 6 bits of ctrl1 field, ensure not repeated std frame tp1 [ i ++ ] = ( byte ) ( ( frame [ 2 ] & 0xfc ) | StdFrameFormat | RepeatFlag ) ; // src tp1 [ i ++ ] = frame [ 4 ] ; tp1 [ i ++ ] = frame [ 5 ] ; // dst tp1 [ i ++ ] = frame [ 6 ] ; tp1 [ i ++ ] = frame [ 7 ] ; // address type, npci, length final int len = frame [ 8 ] ; tp1 [ i ++ ] = ( byte ) ( ( frame [ 3 ] & 0xf0 ) | len ) ; // tpci tp1 [ i ++ ] = frame [ 9 ] ; // apdu for ( int k = 0 ; k < len ; k ++ ) tp1 [ i ++ ] = frame [ 10 + k ] ; } else { // total length = frame length - 1 byte mc + 1 byte checksum tp1 = new byte [ frame . length ] ; for ( int i = 1 ; i < frame . length ; i ++ ) tp1 [ i - 1 ] = frame [ i ] ; // ensure not repeated ext frame tp1 [ 0 ] |= ( byte ) ( frame [ 0 ] | ExtFrameFormat | RepeatFlag ) ; } // last byte is checksum tp1 [ tp1 . length - 1 ] = ( byte ) checksum ( tp1 ) ; return tp1 ; }
returns a TP1 std or ext frame