Java Question Adding new functionalities and tags decoding to NFC library

Bratt

Member
Licensed User
Longtime User
I'll upload the source code later after I clean up some mess.

For now I have a new version with limited NfcV functions. A demo is attached to show how to use the NfcV functions. Only read no write for now.

I've tested a ISO 15693 tag(ICODE SLI/NXP SL2 ICS2001). It works fine.



Hello i need to develop an application that can read/write to the first block in an ISO 15693 tag.
I have tested reading with the NFCV reader example and that works fine.
Unfortunately i don't have enough skills to develop write functionality in the library.
Do you have any plans to add write functionality in the near future?

Thank you.
 

Chelu

Member
Licensed User
Longtime User
Chelu,
The function you want is card simulation as opposed to reader which is a quite new function. I believe Android 4.4 supports the function.

The current lib can not meet your requirement.
Thanks jjcc.
 

jjcc

Member
Licensed User
Longtime User
Hello i need to develop an application that can read/write to the first block in an ISO 15693 tag.
I have tested reading with the NFCV reader example and that works fine.
Unfortunately i don't have enough skills to develop write functionality in the library.
Do you have any plans to add write functionality in the near future?

Thank you.
Will write that function as well as lock function later.
 

vidiot

New Member
Licensed User
Longtime User
Thank you, I see NFC library 1.23 -- did it include write functionality?
 

maldrovandi

Member
Licensed User
Longtime User
Please do not post duplicate questions.

Hello Erel.
I have a question to ask: the link below is an example of how to read a block of paper and write Mifare Ultralight a selected block. These features would need much if they were implemented in B4A, but I read that most people, for years, have been required and you do not have them implemented. Can I ask if there is a reason for this? Perhaps there is a hidden problem in using writing in B4A?

http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html
 

jjcc

Member
Licensed User
Longtime User
Hello Erel.
I have a question to ask: the link below is an example of how to read a block of paper and write Mifare Ultralight a selected block. These features would need much if they were implemented in B4A, but I read that most people, for years, have been required and you do not have them implemented. Can I ask if there is a reason for this? Perhaps there is a hidden problem in using writing in B4A?

http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html
The source code is there in github. You can add the functions if you can not wait. I can add the functions but you need to wait for a while. MifareUltra is simpler than Mifare Classic and IsoV type.
 

maldrovandi

Member
Licensed User
Longtime User
The source code is there in github. You can add the functions if you can not wait. I can add the functions but you need to wait for a while. MifareUltra is simpler than Mifare Classic and IsoV type.

Would you be able to integrate Erel's libraries, in order to write on Mifare Ultralight? All this would be a really good thing ....
 

JohnShepherd

New Member
Licensed User
Longtime User
The attachments are the new version of NFC library and a sample application. I added some extra java code to the library by Sherlok and Erel.

Here's how to use the lib:
1.initialize a "MiFare" object.
2.Call ReadSector() method with 3 parameters: SectorIndex, KeyData, KeyType
3.If succeeded, retrieve the data block by block with method GetBlockData()

B4X:
Sub Read()
   Dim key(16) As Byte
   Dim block_data() As Byte
   Dim bc As ByteConverter
  
   Dim i As Int
   For i  = 0 To 15
      key(i) = 255 '0xff
   Next

   'btnClear
   Dim mfc As MiFare
   Log("Check if the card is MF classic")
    If NFC.IsMifareClassic(Activity.GetStartingIntent) Then
      Dim StrData As String
      mfc.Initialize(Activity.GetStartingIntent)
      If True = mfc.ReadSector(0,key,0) Then' Read sector 0, key, type 0(as keyA)     
         Log("Read sector done")
         For i = 0 To 2 'read 3 blocks of data
            block_data = mfc.GetBlockData(i)
            StrData =  bc.HexFromBytes(block_data)
            Log( "data:" & StrData)
            If i = 0 Then
               Label1.Text = StrData
            Else If i = 1 Then
               Label2.Text = StrData
            Else If i = 2 Then
               Label3.Text = StrData
            End If
         Next
      End If
   End If
End Sub

In manifest editor, I added "android.nfc.action.NDEF_DISCOVERED" and "android.nfc.action.TAG_DISCOVERED" intent filter. Actually "android.nfc.action.TECH_DISCOVERED" is better than NDEF_DISCOVERED but it needs some code like:
B4X:
  <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
          android:resource="@xml/filter_nfc" />

I don't know how to put the "filter_nfc.xml" under "res/xml" directory. Maybe Erel knows.

Good luck

There seems to be a problem with the key length, mifare keys are only 6 bytes long.
If I set a 6 byte key, it seems to ignore me and only authenticates with the default keys.
Can you amend this, or do you have the source code so I can fix it ?
 

jjcc

Member
Licensed User
Longtime User
There seems to be a problem with the key length, mifare keys are only 6 bytes long.
If I set a 6 byte key, it seems to ignore me and only authenticates with the default keys.
Can you amend this, or do you have the source code so I can fix it ?
you are right. Here's the fix
 

Attachments

  • NFC1.24.zip
    19.8 KB · Views: 797

joschi

Member
Licensed User
Longtime User
hi!
I have downloaded the V1.24 from the LIB. I would like to test it with the postet example nfcvreader. But when I start the Project file I get an error "Missing libraries: encryption". in the Forum I don't found this lib. Where get I the lib?

Thanks!!!
 

Lexman

New Member
Licensed User
Longtime User
you are right. Here's the fix
Hi jjcc,
Many thanks for your earlier update of NFC lib.
As you may already know there is a "problem" to read the UID from Mifare 1K etc. with newer phones. (Samsung S4, S5, Nexus 7 (2013)) http://www.rfid-blog.com/?p=2247
because they have Broadcom NFC chip installed. Could you please update the NFC lib so it becomes possible to read ONLY UID from Mifare tags ? . Do not have any other needs to read/write to tag memory. There is some apps on Google Play that can read Mifare UID via Broadcom NFC chip - so it is possible... - I hope you can find some "work around" to solve this issue.
Checkout app "NFC taginfo"

Best Regards !
 

Lexman

New Member
Licensed User
Longtime User
Hi jjcc,
Many thanks for your earlier update of NFC lib.
As you may already know there is a "problem" to read the UID from Mifare 1K etc. with newer phones. (Samsung S4, S5, Nexus 7 (2013)) http://www.rfid-blog.com/?p=2247
because they have Broadcom NFC chip installed. Could you please update the NFC lib so it becomes possible to read ONLY UID from Mifare tags ? . Do not have any other needs to read/write to tag memory. There is some apps on Google Play that can read Mifare UID via Broadcom NFC chip - so it is possible... - I hope you can find some "work around" to solve this issue.
Checkout app "NFC taginfo"

Best Regards !

Hello again. I solved this problem myself and updated the NFC lib so I can now read the UID from Mifare Classic and Mifare Ultralite tags on the Nexus 7 (2013) with Broacom NFC chip.

Cheers
 

aeropic

Active Member
Licensed User
Longtime User
Here's NFC1.25. It added functions for accessing Ultralight/NTag203 tags. Along with an sample B4A code showing how to use the ReadPage function.
Hi JJCC,

I'm just trying NFC1.25 anf the ultralightreader on my galaxy S3 and I get some trouble with it:

1- at compile time : AndroidManifest.xml:36: error: Error: No resource found that matches the given name (at 'resource' with value '@xml/tech_filter').

2 if I cancel the ressource in the manifest, I get this error
B4X:
Convert byte code - optimized dex.      Error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: class name (BADoclet$Property) does not match path (BADoclet/BADoclet$Property.class)
    at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:520)
    at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
    at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
    at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
    at com.android.dx.command.dexer.Main.processClass(Main.java:665)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
    at com.android.dx.command.dexer.Main.access$600(Main.java:78)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:596)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)
...while parsing BADoclet/BADoclet$Property.class
1 error; aborting
    Optimized dexer failed. Switching to Standard dexer.

What am I doing wrong ?
 

jjcc

Member
Licensed User
Longtime User
Hi JJCC,

I'm just trying NFC1.25 anf the ultralightreader on my galaxy S3 and I get some trouble with it:

1- at compile time : AndroidManifest.xml:36: error: Error: No resource found that matches the given name (at 'resource' with value '@xml/tech_filter').

2 if I cancel the ressource in the manifest, I get this error
B4X:
Convert byte code - optimized dex.      Error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: class name (BADoclet$Property) does not match path (BADoclet/BADoclet$Property.class)
    at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:520)
    at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
    at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
    at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
    at com.android.dx.command.dexer.Main.processClass(Main.java:665)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
    at com.android.dx.command.dexer.Main.access$600(Main.java:78)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:596)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)
...while parsing BADoclet/BADoclet$Property.class
1 error; aborting
    Optimized dexer failed. Switching to Standard dexer.

What am I doing wrong ?
For this specific app, I believe you need to put a file "tech_filter.xml" into the directory "$yourworkingdir/Objects/res/xml" and make it read only. Here's a sample file, you can copy it to your directory.
 

Attachments

  • tech_filter.xml
    161 bytes · Views: 725
Top