Skip to content

Instantly share code, notes, and snippets.

@kamituel
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamituel/264ee1683c5a3f805be0 to your computer and use it in GitHub Desktop.
Save kamituel/264ee1683c5a3f805be0 to your computer and use it in GitHub Desktop.
SE API usage example
var openSession = function(readers) {
var seReader = readers.filter(function(reader) {
return reader.type === 'uicc';
})[0];
if (!seReader) {
return Promise.reject('No suitable SE found');
}
return seReader.openSession();
};
var openChannel = function(session) {
var testAIDBuffer = ['0', '1', '2'];
var mastercardAID = new Uint8Array(testAIDBuffer);
return session.openLogicalChannel(mastercardAID);
};
var sendFirstAPDU = function(channel) {
var apdu = new SECommand('A', 'B', 'C', 'D');
return channel.transmit(apdu);
};
var sendSecondAPDU = function(response) {
// Do sth wit the response
var apdu = new SECommand('1', '2', '3', '4');
return response.channel.transmit(apdu);
};
var updateUI = function() {
console.log('All okay');
};
var showError = function(error) {
console.error(error);
};
var cleanup = function(response) {
return response.channel.reader.closeAll();
};
var sedom = window.navigator.mozSEManager;
var pRdrs = sedom.getSEReaders();
pRdrs.then(openSession)
.then(openChannel)
.then(sendFirstAPDU)
.then(sendSecondAPDU)
.then(cleanup)
.then(updateUI)
.catch(showError);
@kamituel
Copy link
Author

Note: The response from the openLogicalChannel (so SELECT an applet) might contain some data useful to the Gaia app.

The Open Mobile API has this data available.

@kamituel
Copy link
Author

How do we handle the 9Fxx (more data to be fetched) when openinng the logical channel, or for any other APDU send during .transmit()? Do we fetch this data in the SIM API impl, or do we leave it out for the Gaia app to do itself?

It might be implemeted by Gaia app, by OS, or on the RIL chipset level.

@kamituel
Copy link
Author

How to support developers with testing this API on the phone or the emulator? (emulator support? card reader connected to the PC via USB, and acting as a SE for an emulator)

@kamituel
Copy link
Author

Security around field enter/leave events - do we want to constrain this somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment