Giter Club home page Giter Club logo

Comments (5)

pokusew avatar pokusew commented on September 2, 2024 2

Hi @bdsomer,

it is certainly not a bug (hopefully). 😄

Firstly, what card you you use? (Mifare Classic?)

In case, that you use Mifare Classic, you need to authenticate every block, that you want to access (write to). That you do with the following:

await reader.authenticate(4, KEY_TYPE_A, 'ffffffffffff');

Note: reader.loadAuthenticationKey is internal API, you don't need to use it. It is called automatically and in highly efficient manner, when you call reader.authenticate.

Further, if you use Mifare Classic, you need to pass the third parameter (blockSize) to reader.write. Mifare Classic cards have block size 16. So you can write data like this:

await reader.write(4, data, 16);

Please also be ware of the memory organization (structure) of Mifare Classic card – see my comment explaining it.
You should to be cautious, when writing more than 16 bytes of data with single reader.write call. For example if you want to write 64 bytes of data starting in block number 4 using block size 16 (needed for Mifare Classic) and you call reader.write(4, data, 16), under the hood it will result in four commands (reader.write(4, data1, 16), reader.write(5, data2, 16), reader.write(6, data3, 16), reader.write(7, data4, 16)) (e.g. 64 / 16 = 4). The problem is the memory organization of Mifare Classic card. Last block in each sector is "sector trailer" (in this case 7) which contains access conditions for the other 3 data blocks (for 4, 5, 6) in the sector.

Finally, take a look at the main example, where everything is explained in comments (note that you need to uncomment some code to make it work with Mifare Classic). Just read the comments I you will be okay. 🙂

That should be all. Please let me know if it solves your problems.

Hope it helps.

from nfc-pcsc.

bdsomer avatar bdsomer commented on September 2, 2024

@pokusew Awesome, thanks! This solved my problem.

To fix, I followed your steps:

  • Remove await reader.loadAuthenticationKey(0, 'ffffffffffff')
  • Pass the third parameter to the reader#read and reader#write methods

Thanks, again. 👍

from nfc-pcsc.

Philip-Nunoo avatar Philip-Nunoo commented on September 2, 2024

@bdsomer could you give a full descripton and better summary. I'm facing similar issues here as well.

thanks.

from nfc-pcsc.

pokusew avatar pokusew commented on September 2, 2024

Hi @Philip-Nunoo,

firstly, I suppose you use Mifare Classic card, right?

I think that everything is summed up in my previous comment #25 (comment). There is a link to the example, where everything is explained with comments and code (you need to uncomment some code for Mifare Classic as there is described) 🙂

Just a small recapitulation – how to read/write data on Mifare Classic card (just for your convenience, but be sure to read my previous comment, links and example):

  1. You need to authenticate every block, you want to access (read or write), using reader.authenticate as shown here (remove Promise.all if you don't need to authenticate more blocks). Ensure, that you use the correct key (default is ffffffffffff , as far as I know) and the correct key type.

  2. Then don't forget to pass the third parameter – block size 16 (number) to the reader.read and reader.write calls.

  3. Lastly be aware of the memory organization (structure) of Mifare Classic card. See my previous comment.

Hope it helps. 🙂


PS Don't forget to star ⭐️ my library, if you find it useful. 😃 Thanks.

from nfc-pcsc.

Philip-Nunoo avatar Philip-Nunoo commented on September 2, 2024

@pokusew nice. Was able to figure it out and thanks for the prompt reply as well.

I'd sure ⭐ it ayt.

from nfc-pcsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.