6

Im new to UICC and Secure Elements and I tried to do a simple android application using this tutorial (http://code.google.com/p/seek-for- android/wiki/UsingSmartCardAPI) to connect the Secure Elements. When I run the application it throw an java.lang.SecurityException: Connection refused !!!. PLease help. Thanks

code

public void onCreate(Bundle savedInstanceState) { 
          final String LOG_TAG = "HelloSmartcard";     
          super.onCreate(savedInstanceState);     
          LinearLayout layout = new LinearLayout(this); 
          layout.setLayoutParams(new LayoutParams( 
                  LayoutParams.WRAP_CONTENT, 
                  LayoutParams.WRAP_CONTENT)); 

          Button button = new Button(this); 
          button.setLayoutParams(new LayoutParams( 
                  LayoutParams.WRAP_CONTENT, 
                  LayoutParams.WRAP_CONTENT));     
          button.setText("Click Me"); 
          button.setOnClickListener(new OnClickListener() { 
            public void onClick(View v) { 
                try { 
                      Log.d(LOG_TAG, "Retrieve available readers..."); 
                      Reader[] readers = seService.getReaders(); 
                      if (readers.length < 1) 
                         return;     
                      Log.d(LOG_TAG, "Create Session from the first reader..."); 
                      Session session = readers[0].openSession();     
                      Log.d(LOG_TAG, 
                      "Create logical channel within the session..."); 
                      Channel channel = session.openLogicalChannel(new 
byte[] { 
                      (byte) 0xD2, 0x76, 0x00, 0x01, 0x18, 0x00, 0x02, 
                      (byte) 0xFF, 0x49, 0x50, 0x25, (byte) 0x89, 
                      (byte) 0xC0, 0x01, (byte) 0x9B, 0x01 });     
                      //Log.d(LOG_TAG, "Send HelloWorld APDU command"); 
                      byte[] respApdu = channel.transmit(new byte[] { 
                      (byte) 0x90, 0x10, 0x00, 0x00, 0x00 });     
                      channel.close();     
                      // Parse response APDU and show text but remove SW1 SW2 first 
                      byte[] helloStr = new byte[respApdu.length - 2]; 
                      System.arraycopy(respApdu, 0, helloStr, 0, 
respApdu.length - 2); 
                      Toast.makeText(MainActivity.this, new 
String(helloStr),   Toast.LENGTH_LONG).show(); 
                   } catch (Exception e) { 
                      Log.e(LOG_TAG, "Error occured:", e); 
                      return; 
                   } 
            } 
          }); 

          layout.addView(button); 
          setContentView(layout); 
          try { 
                Log.i(LOG_TAG, "creating SEService object"); 
                seService = new SEService(this, this); 
              } catch (SecurityException e) { 
                Log.e(LOG_TAG, "Binding not allowed, uses-permission org.simalliance.openmobileapi.SMARTCARD?"); 
              } catch (Exception e) { 
                Log.e(LOG_TAG, "Exception: " + e.getMessage()); 
              } 

    } 

logcat

05-22 08:11:49.669: E/HelloSmartcard(6691): Error occured:
05-22 08:11:49.669: E/HelloSmartcard(6691): java.lang.SecurityException: Connection refused !!!
05-22 08:11:49.669: E/HelloSmartcard(6691):     at org.simalliance.openmobileapi.SEService.checkForException(SEService.java:611)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at org.simalliance.openmobileapi.SEService.openLogicalChannel(SEService.java:479)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:143)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at com.gieseckedevrient.android.hellosmartcard.MainActivity$1.onClick(MainActivity.java:50)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at android.view.View.performClick(View.java:2485)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at android.view.View$PerformClick.run(View.java:9080)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at android.os.Handler.handleCallback(Handler.java:587)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at android.os.Looper.loop(Looper.java:130)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at android.app.ActivityThread.main(ActivityThread.java:3768)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at java.lang.reflect.Method.invokeNative(Native Method)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at java.lang.reflect.Method.invoke(Method.java:507)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
05-22 08:11:49.669: E/HelloSmartcard(6691):     at dalvik.system.NativeStart.main(Native Method)

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gieseckedevrient.android.hellosmartcard"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD"/>
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <uses-library android:name="org.simalliance.openmobileapi" android:required="false" />
    </application>

</manifest>
chinna_82
  • 6,353
  • 17
  • 79
  • 134

1 Answers1

4

//Define the permission in the AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD"/>
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
  • i have the smartcard permision already. Why i need internet.? – chinna_82 May 22 '12 at 08:27
  • ya you dont need that. if you are not requesting to webservice. – Padma Kumar May 22 '12 at 08:29
  • no...i dont have access to webservice.. do u have any other way for me to connect to UICC sim...? – chinna_82 May 22 '12 at 08:33
  • 1
    @chinna_82 he Android system runs on the application processor, thus has limited or no access to the SIM card. Communication with the SIM card is provided by the baseband processor over AT commands (e.g. AT+CPIN, AT+CRSM) defined by 3GPP 27.007 specification or through an proprietary IPC interface. – Padma Kumar May 22 '12 at 08:35
  • I am facing same issues. And also give permission, but still problem is there. Do you have solution... @PadmaKumar – Krunal Indrodiya Apr 25 '16 at 05:30