0% found this document useful (0 votes)
228 views

Pax Response

The document provides code for initializing communication with a SAM or Mifare card using the NeptuneLiteAPI. It requests initialization information including app info, context, SAM slot and callback. It detects and initializes the SAM, performs authentication using APDU commands, and calls the callback returning the response code upon completion.

Uploaded by

bau nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
228 views

Pax Response

The document provides code for initializing communication with a SAM or Mifare card using the NeptuneLiteAPI. It requests initialization information including app info, context, SAM slot and callback. It detects and initializes the SAM, performs authentication using APDU commands, and calls the callback returning the response code upon completion.

Uploaded by

bau nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Hi Bau:

There is no avaliable demo for your reference.

For Mifare and SAM card,we have provided the NeptuneLiteAPI to operate the PICC/ICC
moudle.

// Initial + Set Config


public int Initialize(IDAL idal,
byte SAM_SLOT,
AppInfo appInfo,
InitializeCallback initializeCallback) {

/* _______________________________

Request Initialize information


1. App Information
2. App Context
3. SAM Slot
4. Initialize Callback
_______________________________ */

log_message = " ";


log_message += "Initialize";

// Setup Callback Info


this.initializeCallback = initializeCallback;

log_message += ",ACQ="+appInfo.getAcquirerID();
log_message += ",Loc="+appInfo.getLocationID();
log_message += ",AppVer="+appInfo.getSoftwareVersion();
log_message += ",SPID="+appInfo.getSPID();
log_message += ",TermID="+appInfo.getTerminalID();
log_message += ",SAM Slot="+SAM_SLOT;

// Pax Context
try {
paxContext = new PaxContext();
paxContext.setSAM_SLOT(SAM_SLOT);
paxContext.setIdal(idal);
paxContext.setIcc(ICC.getInstance(this.paxContext.getIdal()));
paxContext.setPiccType(EPiccType.INTERNAL);
paxContext.setPicc(Picc.getInstance(paxContext.getPiccType(),
paxContext.getIdal()));
paxContext.setSet(true);

if (paxContext.getIcc().detect(paxContext.getSAM_SLOT())) {
byte[] res = paxContext.getIcc().init(paxContext.getSAM_SLOT());

if (res == null) {
Log.e(TAG, "ICC Init Call No Response");
}

paxContext.getIcc().autoResp(paxContext.getSAM_SLOT(), true);

} else {
// SAM not detect
Log.d(TAG, "No SAM Detect");
// Set Error Callback (No SAM Detect)
responseInitialize.setRespCode(ErrorCode.NoSAMpresent);
responseInitialize.setRespMsg("No SAM Detect");
this.initializeCallback.call(responseInitialize);
return ErrorCode.NoSAMpresent;
}

} catch (Exception e) {
Log.d(TAG, "Exception : " + e.getMessage());
// Set Error Callback (SAM Paring Fail)
responseInitialize.setRespCode(ErrorCode.SAMpairingfailure);
responseInitialize.setRespMsg("Exception : " + e.getMessage());
this.initializeCallback.call(responseInitialize);
return ErrorCode.SAMpairingfailure;
}

// App Info
this.appInfo = appInfo;

// Perform Init

/* ----------------------
SAM Authentication */

/*APDU Object*/
IApdu apdu = Packer.getInstance().getApdu();
IApdu.IApduReq apduReq;
IApdu.IApduResp apduResp;

/*Error Code*/
int resp_code = 0;

/*Request Object*/
Request request = new Request();
request.setIs_first_packet(true);

/*Request First Session*/


Response response = bss.Init(request);
boolean is_finished = false;

Log.e(TAG, "Session 1st Response Result :: " + response.getResponse_code());

while (!is_finished) {

if (response.getResponse_code() == ERROR_NOERROR) {

byte cla = response.getDatas()[0];


byte ins = response.getDatas()[1];
byte p1 = response.getDatas()[2];
byte p2 = response.getDatas()[3];
byte lc = response.getDatas()[4];
byte le = response.getDatas()[5 + lc];

if (lc != 0) {

byte[] data = new byte[lc];


System.arraycopy(response.getDatas(), 5, data, 0, lc);
apduReq = apdu.createReq(cla, ins, p1, p2, data, le);
} else {

apduReq = apdu.createReq(cla, ins, p1, p2, new byte[0], le);


}

byte[] req = apduReq.pack();


byte[] isoRes;

/*Check Selector*/
if (response.getHw_selector() == SELECTOR_ICC) {

isoRes = paxContext.getIcc().isoCommand(paxContext.getSAM_SLOT(),
req);

} else {
// for init session is allowance for SAM (ICC) only.
// PICC not yet initialise at this state.
// Up-on programming condition for each devices.
Log.e(TAG, "SAM Authentication Failed !");
resp_code = ErrorCode.SAMpairingfailure;
break;
}

if (isoRes != null) {
apduResp = apdu.unpack(isoRes);
String isoStr = null;

/* try {
isoStr = "iso command response:" + " Data:" +
Hex.encode(apduResp.getData())
+ " Status:" + apduResp.getStatusString();
} catch (Exception e) {
e.printStackTrace();
}

Log.e(TAG, isoStr);*/

/*Request Next Session*/


try {

request.setIs_first_packet(false);
request.setSession_id(response.getSession_id());
request.setFunction_id(response.getFunction_id());
request.setHw_selector(response.getHw_selector());

request.setApdu_response_code(Hex.deocde(apduResp.getStatusString()));
request.setDatas(apduResp.getData());
request.setData_len(apduResp.getData().length);

} catch (Exception e) {
e.printStackTrace();
}

response = bss.Init(request);

if (response.isIs_last_packet()) {

is_finished = true;
if (response.getResponse_code() == ERROR_NOERROR) {
Log.e(TAG, "SAM OK");
resp_code = ERROR_NOERROR;

// Set Lib Info (lib version , device id)


libInfo.setLibVersion(LibVersion + "#" + bss.getVersion());
libInfo.setDeviceID(Hex.encode(response.getDatas()));

// Set Config
bss.SetConfig(conFinfo);

// Set Init Status


isInit = true;

} else {
Log.e(TAG, "SAM Failed");
Log.e(TAG, "Response Code :: " +
response.getResponse_code());
is_finished = true;
resp_code = ErrorCode.SAMpairingfailure;
}

} else {
//Log.e(TAG, "Session Next Response Code :: " +
response.getResponse_code());
//Log.e(TAG, "Session Next Response :: " +
Hex.encode(response.getDatas()));
}

} else {
// Invalid
is_finished = true;
Log.e(TAG, "SAM Authentication Failed !");
resp_code = ErrorCode.SAMpairingfailure;
}

} else {
// Invalid
is_finished = true;
Log.e(TAG, "SAM Authentication Failed !");
resp_code = ErrorCode.SAMpairingfailure;

log_message += ",Resp="+resp_code;
Util.createLogFile(bss,log_message,true);

// Success Call Back


responseInitialize.setRespCode(resp_code);
responseInitialize.setRespMsg("");
responseInitialize.setPaxContext(paxContext);

this.initializeCallback.call(responseInitialize);

return resp_code;
}
BR
Danny Duan Replied At 2020-06-24 14:47:06

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy