using pyserial

March 7, 2016 1 comment
import sys
import glob
import serial
import time


def serial_ports():
    if sys.platform.startswith('win'):
        ports = ['COM%s' % (i + 1) for i in range(256)]
    elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
        # this excludes your current terminal "/dev/tty"
        ports = glob.glob('/dev/tty[A-Za-z]*')
    elif sys.platform.startswith('darwin'):
        ports = glob.glob('/dev/tty.*')
    else:
        raise EnvironmentError('Unsupported platform')

    result = []
    for port in ports:
        try:
            s = serial.Serial(port)
            s.close()
            result.append(port)
        except (OSError, serial.SerialException):
            pass
    return result


def process(p):
    ser = serial.Serial(port=p,
                        baudrate=9600,
                        parity=serial.PARITY_EVEN,
                        stopbits=serial.STOPBITS_TWO,
                        bytesize=serial.EIGHTBITS)

    for i in range(100):
        ser.write('A')
        time.sleep(0.1);

        out = ''
        while ser.inWaiting() > 0:
            out += ser.read(1)

        if out != '':
            print ">>" + out

    ser.close()


if __name__ == '__main__':
    port = (serial_ports())[0]
    process(port)
Categories: code, Uncategorized

USIM command and file

August 24, 2015 Leave a comment

ATR | atr
Reset | reset
Format | A6F0000000 | reset
Virginize | A601000001FF | reset

USIM
SELECT FILE | print “00 A4 00 04 02 3F00”
STATUS | print “80 F2 00 00 00”
READ BINARY | print “00 B0 00 00 00”
UPDATE BINARY | print “00 D6 00 00 00”
READ RECORD | print “00 B2 00 00 00”
UPDATE RECORD | print “00 DC 00 00 00”
SEARCH RECORD | print “00 A2 00 00 00”
INCREASE | print “80 32 00 00 00”
RETRIEVE DATA | print “80 CB 00 00 00”
SET DATA | print “80 DB 00 00 00”
VERIFY | print “00 20 00 00 00”
CHANGE PIN | print “00 24 00 00 00”
DISABLE PIN | print “00 26 00 00 00”
ENABLE PIN | print “00 28 00 00 00”
UNBLOCK PIN | print “00 2C 00 00 00”
DEACTIVATE FILE | print “00 04 00 00 00”
ACTIVATE FILE | print “00 44 00 00 00”
AUTHENTICATE | print “00 88 00 00 00”
GET CHALLENGE | print “00 84 00 00 00”
TERMINAL CAPABILITY | print “80 AA 00 00 00”
TERMINAL PROFILE | print “80 10 00 00 00”
ENVELOPE | print “80 C2 00 00 00”
FETCH | print “80 12 00 00 00”
TERMINAL RESPONSE | print “80 14 00 00 00”
MANAGE CHANNEL | print “00 70 00 00 00”
MANAGE SECURE CHANNEL | print “00 73 00 00 00”
TRANSACT DATA | print “00 75 00 00 00”
GET RESPONSE | print “00 C0 00 00 00”

EF DF
MF | print “3F00”
DFGSM | print “7F20”
DFTELECOM | print “7F10”
EFDIR | print “2F00”
EFPL | print “2F05”
EFARR | print “2F06”
EFICCID | print “2FE2”
EFARR | print “6F06”
EFADN | print “6F3A”
EFFDN | print “6F3B”
EFSMS | print “6F3C”
EFECCP | print “6F4F”
EFMSISDN | print “6F40”
EFSMSP | print “6F42”
EFSMSS | print “6F43”
EFLND | print “6F44”
EFSMSR | print “6F47”
EFSDN | print “6F49”
EFEXT1 | print “6F4A”
EFEXT2 | print “6F4B”
EFEXT3 | print “6F4C”
EFBDN | print “6F4D”
EFEXT4 | print “6F4E”
EFSUME | print “6F54”
EFICE_DN | print “6FE0”
EFICE_FF | print “6FE1”
DFGRAPHICS | print “5F50”
EFIMG | print “4F20”
EFIIDFn | print “4FXX”
DFPHONEBOOK | print “5F3A”
EFPBR | print “4F30”
EFIAP | print “4FXX”
EFADN | print “4FXX”
EFEXT1 | print “4FXX”
EFPBC | print “4FXX”
EFGRP | print “4FXX”
EFAAS | print “4FXX”
EFGAS | print “4FXX”
EFANR | print “4FXX”
EFSNE | print “4FXX”
EFCCP1 | print “4FXX”
EFUID | print “4FXX”
EFPSC | print “4F22”
EFCC | print “4F23”
EFPUID | print “4F24”
EFEMAIL | print “4FXX”
DFMULTIMEDIA | print “5F3B”
EFMML | print “4F47”
EFMMDF | print “4F48”
EFPseudo | print “4F41”
EFUPLMNWLAN | print “4F42”
EF0PLMNWLAN | print “4F43”
EFUSSIDL | print “4F44”
EFOSSIDL | print “4F45”
EFWRI | print “4F46”
EFHWSIDL | print “4F47”
EFWEHPLMNPI | print “4F48”
EFWHPI | print “4F49”
EFWLRPLMN | print “4F4A”
DFPHONEBOOK | print “5F3A”
DFGSM-ACCESS | print “5F3B”
DFMExE | print “5F3C”
DFSoLSA | print “5F70”
DFWLAN | print “5F40”
EFORPK | print “4F41”
EFSAI | print “4F30”
EFSLL | print “4F31”
EFMExE-ST | print “4F40”
EFARPK | print “4F42”
EFTPRK | print “4F43”
EFTKCDF | print “4FXX”
EFKc | print “4F20”
EFKcGPRS | print “4F52”
EFCPBCCH | print “4F63”
EFinvSCAN | print “4F64”
EFUID | print “4FXX”
EFPSC | print “4F22”
EFCC | print “4F23”
EFPUID | print “4F24”
EFPBR | print “4F30”
EFCCP1 | print “4FXX”
EFIAP | print “4FXX”
EFADN | print “4FXX”
EFEXT1 | print “4FXX”
EFPBC | print “4FXX”
EFGRP | print “4FXX”
EFAAS | print “4FXX”
EFGAS | print “4FXX”
EFANR | print “4FXX”
EFSNE | print “4FXX”
EFEMAIL | print “4FXX”
EFLI | print “6F05”
EFARR | print “6F06”
EFIMSI | print “6F07”
EFKeys | print “6F08”
EFKeysPS | print “6F09”
EFDCK | print “6F2C”
EFHPPLMN | print “6F31”
EFCNL | print “6F32”
EFACMmax | print “6F37”
EFUST | print “6F38”
EFACM | print “6F39”
EFFDN | print “6F3B”
EFSMS | print “6F3C”
EFGID1 | print “6F3E”
EFGID2 | print “6F3F”
EFMSISDN | print “6F40”
EFPUCT | print “6F41”
EFSMSP | print “6F42”
EFSMSS | print “6F43”
EFCBMI | print “6F45”
EFSPN | print “6F46”
EFSMSR | print “6F47”
EFCBMID | print “6F48”
EFSDN | print “6F49”
EFEXT2 | print “6F4B”
EFEXT3 | print “6F4C”
EFBDN | print “6F4D”
EFEXT5 | print “6F4E”
EFCBMIR | print “6F50”
EFEXT4 | print “6F55”
EFEST | print “6F56”
EFACL | print “6F57”
EFCMI | print “6F58”
EFSTART-HFN | print “6F5B”
EFTHRESHOLD | print “6F5C”
EFPLMNwAcT | print “6F60”
EFOPLMNwAcT | print “6F61”
EFHPLMNwAcT | print “6F62”
EFEHPLMN | print “6FD9”
EFPSLOCI | print “6F73”
EFACC | print “6F78”
EFFPLMN | print “6F7B”
EFLOCI | print “6F7E”
EFICI | print “6F80”
EFOCI | print “6F81”
EFICT | print “6F82”
EFOCT | print “6F83”
EFAD | print “6FAD”
EFeMLPP | print “6FB5”
EFAAeM | print “6FB6”
EFECC | print “6FB7”
EFHiddenkey | print “6FC3”
EFNETPAR | print “6FC4”
EFPNN | print “6FC5”
EFOPL | print “6FC6”
EFMBDN | print “6FC7”
EFEXT6 | print “6FC8”
EFMBI | print “6FC9”
EFMWIS | print “6FCA”
EFCFIS | print “6FCB”
EFEXT7 | print “6FCC”
EFSPDI | print “6FCD”
EFMMSN | print “6FCE”
EFEXT8 | print “6FCF”
EFMMSICP | print “6FD0”
EFMMSUP | print “6FD1”
EFMMSUCP | print “6FD2”
EFNIA | print “6FD3”
EFCCP2 | print “6F4F”
EFVGCS | print “6FB1”
EFVGCSS | print “6FB2”
EFVBS | print “6FB3”
EFVBSS | print “6FB4”
EFVGCSCA | print “6FD4”
EFVBSCA | print “6FD5”
EFGBAP | print “6FD6”
EFMSK | print “6FD7”
EFMUK | print “6FD8”
EFGBANL | print “6FDA”
EFEHPLMNPI | print “6FDB”
EFLRPLMNSI | print “6FDC”
EFNAFKCA | print “6FDD”
EFSPNI | print “6FDE”
EFPNNI | print “6FDF”
EFNCP-IP | print “6FE2”
EFEPSLOCI | print “6FE3”
EFEPSNSC | print “6FE4”
DFHNB | print “5F50”
EFACSGL | print “4F81”
EFCSGI | print “4F82”
EFHNBN | print “4F83”
ADF | print “7FAA”

Clear | clear

Categories: Uncategorized

List Of SW1 SW2 in Smart Card

August 13, 2015 Leave a comment

6E00/E/Class not supported.
61–I/    /Response bytes still available
61XX/I/Command successfully executed; ‘XX’ bytes of data are available and can be requested using GET RESPONSE.
62–/W/State of non-volatile memory unchanged
6200/W/    No information given (NV-Ram not changed)
6201/W/    NV-Ram not changed 1.
6281/W/    Part of returned data may be corrupted
6282/W/    End of file/record reached before reading Le bytes
6283/W/    Selected file invalidated
6284/W/    Selected file is not valid. FCI not formated according to ISO
6285/W/    No Purse Engine enslaved for R3bc
62A2/W/    Wrong R-MAC
62A4/W/    Card locked (during reset( ))
62CX//    Counter with value x (command dependent)
62F1/W/    Wrong C-MAC
62F3/W/    Internal reset
62F5/W/    Default agent locked
62F7/W/    Cardholder locked
62F8/W/    Basement is current agent
62F9/W/    CALC Key Set not unblocked
62FX/W/    –
62XX//    RFU
63–/W/State of non-volatile memory changed
6300/W/    No information given (NV-Ram changed)
6381/W/    File filled up by the last write. Loading/updating is not allowed.
6382/W/    Card key not supported.
6383/W/    Reader key not supported.
6384/W/    Plaintext transmission not supported.
6385/W/    Secured transmission not supported.
6386/W/    Volatile memory is not available.
6387/W/    Non-volatile memory is not available.
6388/W/    Key number not valid.
6389/W/    Key length is not correct.
63C0/W/    Verify fail, no try left.
63C1/W/    Verify fail, 1 try left.
63C2/W/    Verify fail, 2 tries left.
63C3/W/    Verify fail, 3 tries left.
63CX//    The counter has reached the value �x� (0 = x = 15) (command dependent).
63FX/W/    –
63XX//    RFU
64–/E/State of non-volatile memory unchanged
6400/E/No information given (NV-Ram not changed)
6401/E/Command timeout.
64XX/E/    RFU
65–/E/State of non-volatile memory changed
6500/E/No information given
6501/E/Write error. Memory failure. There have been problems in writing or reading the EEPROM. Other hardware problems may also bring this error.
6581/E/Memory failure
65FX/E/-
65XX/E/    RFU
66–/S/
6669/S/Incorrect Encryption/Decryption Padding
66XX/S/    –
67–/E/
6700/E/Wrong length
67XX/E/    length incorrect (procedure)(ISO 7816-3)
68–/E/Functions in CLA not supported
6800/E/No information given (The request function is not supported by the card)
6881/E/Logical channel not supported
6882/E/Secure messaging not supported
6883/E/Last command of the chain expected
6884/E/Command chaining not supported
68FX/E/-
68XX/E/    RFU
69–/E/Command not allowed
6900/E/No information given (Command not allowed)
6981/E/Command incompatible with file structure
6982/E/Security condition not satisfied.
6983/E/Authentication method blocked
6984/E/Referenced data reversibly blocked (invalidated)
6985/E/Conditions of use not satisfied
6986/E/Command not allowed (no current EF)
6987/E/Expected secure messaging (SM) object missing
6988/E/Incorrect secure messaging (SM) data object
6996/E/Data must be updated again
69F0/E/Permission Denied
69F1/E/Permission Denied – Missing Privilege
69FX/E/-
69XX/E/    RFU
6A–/E/Wrong parameter(s) P1-P2
6A00/E/No information given (Bytes P1 and/or P2 are incorrect)
6A80/E/The parameters in the data field are incorrect.
6A81/E/Function not supported
6A82/E/File not found
6A83/E/Record not found
6A84/E/There is insufficient memory space in record or file
6A85/E/Lc inconsistent with TLV structure
6A86/E/Incorrect P1 or P2 parameter.
6A87/E/Lc inconsistent with P1-P2
6A88/E/Referenced data not found
6A89/E/File already exists
6A8A/E/DF name already exists.
6AF0/E/Wrong parameter value
6AFX/E/-
6AXX/E/    RFU
6B–/E/
6B00/E/Wrong parameter(s) P1-P2
6BXX/E/    Reference incorrect (procedure byte), (ISO 7816-3)
6C–/E/Wrong length Le
6C00/E/Incorrect P3 length.
6CXX/E/    Bad length value in Le; ‘xx’ is the correct exact Le
6D–/E/
6D00/E/Instruction code not supported or invalid
6DXX/E/    Instruction code not programmed or invalid (procedure byte), (ISO 7816-3)
6E–/E/
6E00/E/Class not supported
6EXX/E/    Instruction class not supported (procedure byte), (ISO 7816-3)
6F–/E/Internal exception
6F00/E/Command aborted – more exact diagnosis not possible (e.g., operating system error).
6FFF/E/Card dead (overuse, �)
6FXX/E/    No precise diagnosis (procedure byte), (ISO 7816-3)
9— /    /
9000/I/Command successfully executed (OK).
9004/W/    PIN not succesfully verified, 3 or more PIN tries left
9008/ /Key/file not found
9080/W/    Unblock Try Counter has reached zero
9101/ /States.activity, States.lock Status or States.lockable has wrong value
9102/ /Transaction number reached its limit
920x/I/Writing to EEPROM successful after ‘x’ attempts.
9210/E/Insufficient memory. No more storage available.
9240/E/Writing to EEPROM not successful.
9301/ /Integrity error
9302/ /Candidate S2 invalid
9400/E/No EF selected.
9401/ /Candidate currency code does not match purse currency
9402/ /Candidate amount too high
9402/E/Address range exceeded.
9403/ /Candidate amount too low
9404/E/FID not found, record not found or comparison pattern not found.
9405/ /Problems in the data field
9407/ /Bad currency : purse engine has no slot with R3bc currency
9408/ /R3bc currency not supported in purse engine
9408/E/Selected file type does not match command.
9580/ /Bad sequence
9681/ /Slave not found
9700/ /PIN blocked and Unblock Try Counter is 1 or 2
9702/ /Main keys are blocked
9704/ /PIN not succesfully verified, 3 or more PIN tries left
9784/ /Base key
9785/ /Limit exceeded – C-MAC key
9786/ /SM error – Limit exceeded – R-MAC key
9787/ /Limit exceeded – sequence counter
9788/ /Limit exceeded – R-MAC length
9789/ /Service not available
9802/E/No PIN defined.
9804/E/Access conditions not satisfied, authentication failed.
9835/E/ASK RANDOM or GIVE RANDOM not executed.
9840/E/PIN verification not successful.
9850/E/INCREASE or DECREASE could not be executed because a limit has been reached.
9900/ /1 PIN try left
9904/ /PIN not succesfully verified, 1 PIN try left
9985/ /Wrong status – Cardholder lock
9986/E/Missing privilege
9987/ /PIN is not installed
9988/ /Wrong status – R-MAC state
9A00/ /2 PIN try left
9A04/ /PIN not succesfully verified, 2 PIN try left
9A71/ /Wrong parameter value – Double agent AID
9A72/ /Wrong parameter value – Double agent Type
9D05/E/Incorrect certificate type
9D07/E/Incorrect session data size
9D08/E/Incorrect DIR file record size
9D09/E/Incorrect FCI record size
9D0A/E/Incorrect code size
9D10/E/Insufficient memory to load application
9D11/E/Invalid AID
9D12/E/Duplicate AID
9D13/E/Application previously loaded
9D14/E/Application history list full
9D15/E/Application not open
9D17/E/Invalid offset
9D18/E/Application already loaded
9D19/E/Invalid certificate
9D1A/E/Invalid signature
9D1B/E/Invalid KTU
9D1D/E/    MSM controls not set
9D1E/E/Application signature does not exist
9D1F/E/KTU does not exist
9D20/E/Application not loaded
9D21/E/Invalid Open command data length
9D30/E/Check data parameter is incorrect (invalid start address)
9D31/E/Check data parameter is incorrect (invalid length)
9D32/E/Check data parameter is incorrect (illegal memory check area)
9D40/E/Invalid MSM Controls ciphertext
9D41/E/MSM controls already set
9D42/E/Set MSM Controls data length less than 2 bytes
9D43/E/Invalid MSM Controls data length
9D44/E/Excess MSM Controls ciphertext
9D45/E/Verification of MSM Controls data failed
9D50/E/Invalid MCD Issuer production ID
9D51/E/Invalid MCD Issuer ID
9D52/E/Invalid set MSM controls data date
9D53/E/Invalid MCD number
9D54/E/Reserved field error
9D55/E/Reserved field error
9D56/E/Reserved field error
9D57/E/Reserved field error
9D60/E/MAC verification failed
9D61/E/Maximum number of unblocks reached
9D62/E/Card was not blocked
9D63/E/Crypto functions not available
9D64/E/No application loaded
9E00/ /PIN not installed
9E04/ /PIN not succesfully verified, PIN not installed
9F00/ /PIN blocked and Unblock Try Counter is 3
9F04/ /PIN not succesfully verified, PIN blocked and Unblock Try Counter is 3
9FXX/ /Command successfully executed; ‘xx’ bytes of data are available and can be requested using GET RESPONSE.
9XXX/ /Application related status, (ISO 7816-3)

Categories: smartcard

array besar di c

May 5, 2013 Leave a comment

waktu itu mau coba alokasikan array di c, ukuran 500an kali 35000an.

langsung crash, hehehe. coba pake cara lain

bikin array of pointer dulu, terus masing2 baru deh dialokasikan pakai malloc.

ini contoh programnya.

 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
int width=600, height=40000;
int* foo[width];
int i;
for(i=0;i<width;i++) {
foo[i]=malloc(sizeof(int)*height);
}

foo[width-1][height-1]=5;
printf(“%d\n”, foo[width-1][height-1]);

for(i=0;i<width;i++) {
free(foo[i]);
}

printf(“end\n”);
}

Categories: Uncategorized

Tutorial+pembuktian+rumus+luas+lingkaran

February 14, 2011 Leave a comment

video_player_embed_code_text

Categories: Uncategorized

Test Page

February 14, 2011 Leave a comment

Test description

Categories: Uncategorized

Running external command from java

October 22, 2009 Leave a comment
import java.io.*;

public class ExternalCommand
{
public static void main(String args[]) throws Exception
{
String line;
OutputStream stdin = null;
InputStream stderr = null;
InputStream stdout = null;

// launch EXE and grab stdin/stdout and stderr
Process process = Runtime.getRuntime ().exec ("bc");
stdin = process.getOutputStream ();
stderr = process.getErrorStream ();
stdout = process.getInputStream ();

// "write" the parms into stdin
line = "13*3" + "\n";
stdin.write(line.getBytes() );
stdin.flush();

stdin.close();

// clean up if any output in stdout
BufferedReader brCleanUp =
new BufferedReader (new InputStreamReader (stdout));
while ((line = brCleanUp.readLine ()) != null) {
System.out.println ("[Stdout] " + line);
}
brCleanUp.close();

// clean up if any output in stderr
brCleanUp =
new BufferedReader (new InputStreamReader (stderr));
while ((line = brCleanUp.readLine ()) != null) {
System.out.println ("[Stderr] " + line);
}
brCleanUp.close();

}
}

ref: http://www.rgagnon.com/javadetails/java-0014.html

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.