NFC Secure Element

by Gruntz Dominik » Tue, 07 Dec 2010 19:42:37 GMT


Sponsored Links
 Hi everyone,

Do I see it right, that the Android 2.3 NFC API does not provide functionality 
to access a secure element? A secure element is a smartcard connected to the 
NFC controller, i.e. a secure storage in the device, either embedded in the 
mobile phone, on the SIM card or on a SD card.

With JavaME access to the secure element was provided with JSR177 which 
supported the communication with smart card applications usind APDU commands. I 
have not seen comparable functionality in package android.nfc.

Thanks for any hints
Dominik

-- 



Re: NFC Secure Element

by nemik » Mon, 20 Dec 2010 09:27:05 GMT


 Dominik,

Yea, that's right. All it does currently is read; at least via the
Java API. If you look at the kernel source though, a bunch of ifdefs
which allow for emulation were all disabled. So full compliance with
the NFC standard will have to wait for a future kernel release.




-- 


Sponsored Links


Re: NFC Secure Element

by nemik » Sun, 09 Jan 2011 03:40:25 GMT


 I was able to enable a secure element the other day by messing around
with this external/libnfc-nxp library. I enabled SMX (SmartMX) in the
config headers, and upon booting and monitoring `adb logcat` during
boot I saw 1 secure elements (a SmartMX one) had been enabled. I was
then able to change the mode in NfcService.java to card emulation
mode.

The Nexus S is now emulating a MiFare Classic 4k card. However, I am
not able to read sectors from the card directly. I've been trying to
use the micmd tool to do that but things act pretty strangely. For
example, I tried to read block 0 and micmd tells me "Could not read
the data block! Tag halted, reconnecting..." but what's even stranger
is that at that point, 'adb logcat' shuts itself off. As if that read
command somehow interfered with USB or logging?
However trying `a` commands to authenticate in micmd always works for
some reason and it'll even pretent to write and persist data to
blocks; but of course that data never actually gets persisted to the
emulated card. Maybe this is a bug in micmd?

Does anyone know if the Nexus S hardware (or its PN544 NFC chipset)
even contains a hardware secure element like SmartMX? I tried also
enabling UICC but that didn't seem to work at all and NFC service
wouldn't even start in that case. Plus my SIM card is MANY years old
and not sure it'd even work...

Either way, I used libnfc.org's `nfc-mfclassic` tool to dump out the
contents of that emulated 4k card. It is here:  http://pastebin.com/zKZ2ELcw 

Seems to be entirely blank which is why I'm wondering if these aren't
some default values it would spit out anyway even if no SmartMX module
existed?

If anyone has any more insights into this, I'd be very happy to hear
them.

-Nemanja





-- 



Re: Re: NFC Secure Element

by Ajith Kamath » Mon, 10 Jan 2011 13:31:30 GMT


 i Nemik

* I have small doubt with current implementation. Is SmartMX a Secure
Element ?If so can you give me examples?
* I have checked libnfc-nxp , enabling P2P parameter was at phnfcconfig.h.
what needs to be done to enable Secure element?
what are MifarePlus, Desfire, Topaz . Is it a Card type or Secure Element?


* Also where is the general read-write methods for entry of Secure element.
All I can see is phLibNfc_SE.c is methods for getting list of secured
element, selecting secure element, deselecting.
* But method for exchange of data is not present. Can you tell me where can
I find this?

* In libnfc-nxp There are files like phFriNfc_NdefMap.c,
phFriNfc_MifareULMap.c, phFriNfc_TopazMap.c, phFriNfc_TopazDynamicMap.c,
phFriNfc_DesfireMap.c, phFriNfc_FelicaMap.c.
Can you tell me what these files are used for. The current comments in the
file do not provide sufficient information

* I am trying to use Wired Mode, Hence phHciNfc_WI.c will be used to
communicate between Controller and Secure element right?

Please advice.

Regards,
Ajith



Hi

On Sun, Jan 9, 2011 at 1:00 AM, nemik <ne...@nemik.net> wrote:


--



Re: NFC Secure Element

by nemik » Mon, 10 Jan 2011 14:14:15 GMT


 jith,

According to
http://discussion.forum.nokia.com/forum/showthread.php?199442-6212-device-how-to-work-with-the-secure-element
the CN072 is a secure element in the Smart MX family. I'm not sure the
same one is in the Nexus S, but I presume the one in there is at least
very similar.

Here is the info on it:
http://www.nxp.com/acrobat_download2/other/identification/SFS107710.pdf

I'm still trying to figure out how to get access to it as well, for
reading or writing. I doubt there are any specific commands for it
though, it just takes regular commands over ISO14443 just like other
MiFare cards.

On Jan 9, 11:31pm, Ajith Kamath <sjce.aj...@gmail.com> wrote:

--



Re: Re: NFC Secure Element

by Ajith Kamath » Mon, 10 Jan 2011 15:51:54 GMT


 i Nemik

I'm running over the libnfc code.
I can see these 4 files to be prominent for communication with SE

phHciNfc_CE_A.c
phHciNfc_CE_B.c

I am thinking the above two might be used for R/W into SE from App
Processor.
And the below two is used for communication between NFC Controller and SE.

phHciNfc_SWP.c
phHciNfc_WI.c

Please go through these files and let me know if I'm in right path.

Regards,
Ajith




On Mon, Jan 10, 2011 at 11:44 AM, nemik <ne...@nemik.net> wrote:


--



Re: NFC Secure Element

by gusdgg » Fri, 14 Jan 2011 21:21:40 GMT


 i Nemik,

Please, could you tell me how do you enable the SMX in the nexus s
configuration and change the mode in the Nfcservice? So far, I can
read and write tags,

Regards
gusdgg

On 10 ene, 04:51, Ajith Kamath <sjce.aj...@gmail.com> wrote:

--



Re: NFC Secure Element

by gusdgg » Fri, 14 Jan 2011 21:21:42 GMT


 Could you tell me how do you enabled SMX (SmartMX) and set the
cardemulation mode? So far, I was able to read and write tags with the
Nexus S.

Thanks

.gusdgg






-- 



Re: NFC Secure Element

by Dominik » Tue, 18 Jan 2011 08:11:19 GMT


 According to the NXP documentation of PN544, three SE variants are
supported:
- SIM Card (via UICC)
- Embedded (SmartMX security chip)
- SD Card

Do you know which version is intended to be used by the Nexus S
device?

The above messages describe attempts to enable SmartMX. As soon as
access to this SE is possible:
Which keys do you use to access the SE? Such keys should be private
and not generally be known.

I am at a loss.

- Dominik

-- 



Re: NFC Secure Element

by Ajith Kamath » Tue, 18 Jan 2011 11:11:50 GMT


 I still dont have nexus s but there is a high probability that its Embedded

Yes Keys are private and most likely needs to be provided by Service
Provider. The same thing has been mentioned in nokia forum
But I am not sure  how this will be done for nexus S.(may be there are ties
with Service Provider)

If anyone can explain OTA agent and its communication with TSM, it would be
very helpful. Since this too is not clear (w.r.t android)

Regards,
Ajith







-- 



Re: NFC Secure Element

by Ajith Kamath » Thu, 20 Jan 2011 11:29:50 GMT


 Hi Dominik

Can you explain how what did you use to access Secure element?
Which methods , which file?

Because permission may depend on how you are accessing it.

Regards,
Ajith






-- 



Re: NFC Secure Element

by nemik » Fri, 21 Jan 2011 05:01:16 GMT


 Sorry for not replying in a while, been very busy with projects at
work.

I posted my diff's to enable the Nexus S to emulate an NFC tag. The
links are below:
 http://nemik.net/code/android-nfc/Nfc-app.diff for 
 http://android.git.kernel.org/?p=platform/packages/apps/Nfc.git ;a=summary
and
 http://nemik.net/code/android-nfc/libnfc-nxp.diff for 
 http://android.git.kernel.org/?p=platform/external/libnfc-nxp.git ;a=summary

These are just based on the on the open source, plain vanilla Android
Gingerbread codebase. If you patch it with the diffs above, you can
build the OS, upload the images to the phone's bootloader (make sure
to unlock the bootloader first) and then see it for yourself.

It is pretty badly broken and this is just to prove that it can kinda
work, I hacked it up pretty hard.

Also, I added a lot of LOGD()'s in the NFC app's JNI so I could see
what was going on when trying things out on the phone so I could read
it when doing an 'adb logcat' on the computer with the phone attached
over USB.

Have fun!





-- 



Re: NFC Secure Element

by mtk » Tue, 25 Jan 2011 02:50:55 GMT


 Thanks Nemik for posting the patch, I was trying to get the emulation
working without much luck so far, I see you have flipped some
additional flags than what I had, so I'll trying those.
Btw I was able to set the SE to wired mode by calling
phLibNfc_SE_SetMode(seID,phLibNfc_SE_ActModeWired,
nfc_jni_se_set_mode_callback,(void *)nat);
so now the SE gets detected as a local tag and I can open a tag
connection to same - I tried a few APDUs, but getting error codes 6a
82 (not found), 69 85 etc back.. I'll post if I'm able to make any
progress.







-- 



Re: NFC Secure Element

by gusdgg » Tue, 25 Jan 2011 02:58:58 GMT


 Nemik,

Thanks for posting the diff's and great work! I'll patch the codebase
and see what happen. In the meantime and coming back to your question
about the Nexus S hardware containing a secure element like SmartMX,
did you get the secure element list with the method
getSecureElementList() in the patched version? I called this method
(via reflection, no patched yet) but it gets the error message
"WRITE_SECURE_SETTINGS permission required"

As you may know, there are an excelent nexus s teardown (http://
www.ifixit.com/Teardown/Nexus-S-Teardown/4365/1) from iFixit. You'll
see there, in the step 7 - 2nd picture, the NXP PN544 NFC chip closely
located to the UICC slot, but as far I can see there isn't any SmartMx
chip in that picture, nor in the others.

Regards,
gusdgg

-- 



Re: NFC Secure Element

by nemik » Fri, 28 Jan 2011 13:25:55 GMT


 mtk, very cool! So when you did that call directly (somewhere in init
of the jni code?) you got it to detect? How are you sending APDU
commands? Also, if I understand wired mode correctly, the tag is not
emulated externally to other readers; it's only available internally
using the NFC API?

gusdgg, yes, I saw the secure elements using the
getSecureElementList() and just doing logging with those and observing
them using `adb logcat`. I think that is in one of the diffs I posted.
It worked OK for me and I wasn't seeing any permission errors. Though
I never even bothered to do it via reflection on the stock firmware
since I figured it would just deny it. Your findings clearly confirm
that.
As for the SmartMX chip, maybe you're right. But I suppose it could
also be built into the PN544 chip itself. I have no idea, I wasn't
able to find any datasheets that talk about it and have no details on
the NXP chips Samsung's been sourcing for the Nexus S.




-- 



Other Threads

1. Json paser showing array length as 0.. pls help

hi guys this the class where i m parsing the values

package com.example;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.util.Log;

public class JSONhelper {

        private final String baseURL = "http://ajax.googleapis.com/ajax/
services/search/local?v=1.0&sll=48.8565,2.3509&q=restaurant";


        JSONArray resultsJsonArray;
        JSONObject placesJsonObject;
        ArrayList<PlaceInformation> resultArrayList = new
ArrayList<PlaceInformation>();



        public JSONhelper(Context context) {

        }

        public void getJson() {
                HttpGet httpGet = getHttpUriRequest();
                HttpClient httpClient = getHttpClient();
                HttpResponse httpResponse = getHttpResponse(httpGet, 
httpClient);
                JSONObject jsonObject = getJSONObject(httpResponse);

                // initialiseArrayLists(jsonObject);
                getResultsArrayList(jsonObject);
                // Log.v(TAG, "ArrayList initialized=" + flag);
        }



        public void getResultsArrayList(JSONObject jsonObject) {
                try {
                        resultsJsonArray = jsonObject.getJSONArray("resuslt");
                        for (int i = 0; i < resultsJsonArray.length(); i++) {
                                placesJsonObject = 
resultsJsonArray.getJSONObject(i);
                                getPlaceInformation(placesJsonObject);
                        }
                } catch (Exception e) {
                        // TODO: handle exception
                }
        }

        private void getPlaceInformation(JSONObject placesJsonObject2)
                        throws JSONException {
                PlaceInformation placeinfo = new PlaceInformation();
                placeinfo.lat = placesJsonObject2.getString("lat");
                placeinfo.lng = placesJsonObject2.getString("lng");
                placeinfo.title = placesJsonObject2.getString("title");
                placeinfo.city = placesJsonObject2.getString("city");
                placeinfo.country = placesJsonObject2.getString("country");
                placeinfo.streetAddress =
placesJsonObject2.getString("streetAddress");

                placeinfo.addressLines1 = placesJsonObject2
                                .getJSONArray("addressLines").getString(0);
                placeinfo.addressLines2 = placesJsonObject2
                                .getJSONArray("addressLines").getString(1);

                placeinfo.phoneNumbers =
placesJsonObject2.getJSONArray("phoneNumbers")
                                .getJSONObject(0).getString("phoneNumbers");

                resultArrayList.add(placeinfo);

        }



        private HttpGet getHttpUriRequest() {
                HttpGet get = null;
                Log.v("111", "tt" + get);

                String URL = baseURL;// getURL(("since"));
                try {
                        get = new HttpGet(URL);
                        Log.v("111", "tt" + get);
                        Log.v("111", "tt" + URL);
                } catch (IllegalArgumentException e) {
                        // Log.v(TAG, "IllegalArgumentException");
                        e.printStackTrace();
                }
                return get;
        }

        private HttpClient getHttpClient() {
                HttpClient httpClient = new DefaultHttpClient();
                Log.v("222", "ccc" + httpClient);
                return httpClient;
        }

        private HttpResponse getHttpResponse(HttpGet get, HttpClient
httpClient) {
                HttpResponse httpResponse = null;
                try {
                        Log.v("getHttpResponse====", "httpClient" + httpClient);
                        Log.v("getHttpResponse====", "get" + get);
                        httpResponse = httpClient.execute(get);
                        Log.v("333", "rrr" + httpResponse);

                } catch (ClientProtocolException e) {

                        e.printStackTrace();
                } catch (IOException e) {
                        // Log.v(TAG, "IOException");
                        e.printStackTrace();
                }
                return httpResponse;

        }

        JSONObject getJSONObject(HttpResponse httpResponse) {

                String jsonString = null;
                JSONObject responseDataJsonObject = null;
                if (httpResponse.getStatusLine().toString().equals("HTTP/1.1 200
OK"))

                {
                        try {
                                jsonString = 
EntityUtils.toString(httpResponse.getEntity());
                                Log.v("sdfvsd", "*********" + 
jsonString.toString());
                                responseDataJsonObject = new 
JSONObject(jsonString);

                        } catch (ParseException e) {
                                // Log.v(TAG, "ParseException");
                                e.printStackTrace();
                        } catch (IOException e) {
                                // Log.v(TAG, "IOException");
                                e.printStackTrace();
                        } catch (JSONException e) {
                                // Log.v(TAG, "JSONException");
                                e.printStackTrace();
                        }
                }
                return responseDataJsonObject;
        }

}


*********************
later in next class i m

package com.example;


import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;


public class First extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                JSONhelper jsoNhelper=new JSONhelper(getApplicationContext());
                jsoNhelper.getJson();
                ArrayList<PlaceInformation> a=jsoNhelper.resultArrayList;
                Log.v("First", " arrayList length="+ a.size());

        }

}


here i m not getting the list of array...means the out put....
pls comment and solve my issues

-- 

2. Android Patent issue

All,

I have just started my career in Android world and finding more
interesting. Just wanted to know does this patent issue will impact to
android development?

-- 

3. What does "Battery Use" tell and how is it implemented?

4. Geofence application in android

5. framework to integrate a new voice recognition engine.

6. Android Email Client Omits Email Headers

7. Problems porting Android OS onto a new platform