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. How to properly use Model classes in Android

Hi,

When traying to do a good design for an Android app, I ussually face a
problem when trying to get some balance between clarity and efficiency,
maybe is a silly situation but for example, let's take a simple shopping
list app:

I can have a really readable model based on two classes: FoodItem and
ShoppingList, where FoodItem represents each item that can be in the
shopping list containing its fields (name, description, price, etc...) and
the ShoppingList item just keeps a list of FoodItems objects and some extra
fields (i.e: totalPrice, etc...).

Ok, now I'm putting an ActivityList for showing and managing my shopping
list with a custom layout for showing FoodItem's data. The simplest way I've
found to load list is using a SimpleListAdapter, which needs to receive a
Map containing the fields of the FoodItem I want to show in the list,
then... what's the best option? Having a method like "toMap" in my FoodItem
class and, consequently another similar method "toMapsList" in my
ShoppingList class to translate my list of objects to a list of Maps? or is
there any other option?

This doesn't seem to be a good solution from the point of view of
efficiency. It seems it would be better to take off from the model and work
just with Maps the whole way.

I don't know if there's a proper way to keep a clean model in an Android app
withouth having to do things like convertir objects to Maps.

Any good solution?

Thanks! :)

-- 

2. Built-in camera problem deleting files

Hi all!

I'm using  the built-in camera in my app to take a picture and to save
it in a database. So, from my activity, I launch the camera, take a
picture and go back to the activity (thanks to "onActivityResult"
method). Here, I store the picture in the database and I delete it
from the phone. Seems to be working properly: the picture is being
deleted from the sdcard but if you go to the gallery app that comes
with the device, the picture is being displayed but as a "wrong file",
so you can see that there is/was a picture there but you can't open it
or even see the preview.  But I can delete it from the gallery app
manually (selecting them and then deleting). How can i do this
programatically?


Thanks a lot! I really need help with this

-- 

3. VideoView setBackgroundColor is foregroundcolor ?

4. all_apps_3d error when screen rotation

5. audio recorder

6. gtablet apps

7. Subclassing TextView in a widget - HELP!!!!!