Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 239
Registered: ‎07-26-2010
My Device: Z10
My Carrier: Telkomsel

SIM card applet reading problem

[ Edited ]

For testing purpose, I have a custom made SIM card, which only has an applet in it, and nothing else.

This is the code to test it:

public class APDUScreen extends MainScreen {

	private TextField tf;
	private ButtonField bf;
	
	public APDUScreen(){
		setTitle(":: APDU Test ::");
		
		tf = new TextField(FOCUSABLE);
		bf = new ButtonField("Test", FOCUSABLE | ButtonField.CONSUME_CLICK | FIELD_HCENTER);
		bf.setChangeListener(listener);
		
		add(tf);
		add(new SeparatorField());
		add(bf);
		
	}
	
	FieldChangeListener listener = new FieldChangeListener() {
		
		public void fieldChanged(Field field, int context) {
			if (field == bf){
				APDUConnection connection = null;
				
				try {
					connection = (APDUConnection)  Connector.open("apdu:0;target=43.73.6C.54.72.61.69.6E.69.6E.67.41.70.70");
					byte[] responseATR = connection.getATR();
					
					tf.setText(new String(responseATR));
				}
				catch (IOException ioe){
					tf.setText(ioe.getMessage());
				}
				finally {
					if (connection != null)
						try {
							connection.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
				}
			}
			
		}
	};
}

 When I ran it (debugging on device), the debugger popped up and I found this:

[407.906] Unable to get MCC/MNC number
[407.921] GemaltoAAccessControllScheme::doWork() done (static method)

 

What would probably be the cause of the error?

Developer
Posts: 239
Registered: ‎07-26-2010
My Device: Z10
My Carrier: Telkomsel

Re: SIM card applet reading problem

[ Edited ]

OK, it turned out that I used the wrong card. Now I'm using the correct card.

This is how I load the applet, using smart card reader.

fileloader.PNG

 

Now let's try to load the applet on phone:

APDUConnection connection = null

try {
	connection = (APDUConnection) Connector.open("apdu:0;target=43.73.6C.54.72.61.69.6E.69.6E.67.41.70.70");
	byte[] responseATR = connection.getATR();
	tf.setText(new String(responseATR));
}
catch (IOException ioe){
	tf.setText(ioe.getMessage());
}

 

I get this:

Unable to open; No free channels

 

FYI, System.getProperty("microedition.smartcardslots") gives me: OC

 

Developer
Posts: 239
Registered: ‎07-26-2010
My Device: Z10
My Carrier: Telkomsel

Re: SIM card applet reading problem

Just found this:

In the case when there are no logical channels available or the card does not support logical channels, the card will return an error. An IOException will be thrown and no connection object will be returned to the J2ME application.

 

I guess that's the cause, but what exactly do logical channels mean?

Highlighted
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: SIM card applet reading problem

For a description of logical channels, see section 5.1.1.2 of the ISO7816-4 specification.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim