Comments (5)
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.
@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
andreader#write
methods
Thanks, again. 👍
from nfc-pcsc.
@bdsomer could you give a full descripton and better summary. I'm facing similar issues here as well.
thanks.
from nfc-pcsc.
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):
-
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 isffffffffffff
, as far as I know) and the correct key type. -
Then don't forget to pass the third parameter – block size 16 (number) to the
reader.read
andreader.write
calls. -
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.
@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)
- Error when writing data. Receives an Invalid data length error. HOT 3
- Authentication failed for same blocks BUT is Working in others HOT 1
- P2P Feature
- Empty Data
- Multi RFID Reader
- was compiled against a different Node.js version using NODE_MODULE_VERSION 111. This version of Node.js requires NODE_MODULE_VERSION 110. HOT 3
- UnhandledPromiseRejectionWarning: WriteError: Write operation failed: Status code: 0x6300 HOT 3
- I don't understand that code HOT 1
- Module not found: Error: Can't resolve 'fs' HOT 2
- Unable to run the basic example HOT 2
- Add disposition parameter in disconnect method HOT 2
- MacOS installation issue using npm HOT 2
- Cannot access "events.EventEmitter" in client code HOT 4
- Context Aware Native Module, Electron Context Isolation and Node Integration Support
- Unsupported engine Please Help
- Emulate Tag NFC?
- Sveltekit build fails when running 'npm run build' but works on 'npm run dev' HOT 1
- It turned out to connect the library in CRA(React)? HOT 1
- Writes become slower each time
- Cannot process ISO 14443-4 tag because AID was not set
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nfc-pcsc.