explore-nfc-board-driver icon indicating copy to clipboard operation
explore-nfc-board-driver copied to clipboard

Variable bLength goes to 0 after macro invocation

Open eugch opened this issue 10 years ago • 4 comments

Thanks for your code. I have a question regarding the variable bLength

I notice that after invoking below in line 284, variable bLength will be reset to 0. In this program it was supposed to hold the value of 7 for the length of the Ultralight UID.

PH_CHECK_SUCCESS_FCT(status, phalMful_Read(alMful, p, bBufferReader));

My initial intention was to reuse this variable to print the UID to a file. I had to reassign this variable as early as possible to another variable as a temporary workaround but was still curious why is that happening.

Have you encountered this? Thanks.

eugch avatar Sep 24 '14 13:09 eugch

Hi, The UID of the card is printed out during the loop on line 250. The content of the card is printed on line 284. There is 2 loops here, the first one, to loop over the different pages (addresses 04 to 0F on the card chip), and the nested one, to print each byte (4 bytes per page).

Let me know if that helps (by the way I fixed the terrible indenting).

robinmonjo avatar Sep 24 '14 19:09 robinmonjo

Hi Robin, Thanks for responding. I understand that reading the UID and the user content are specified in two different loops. But I'm actually referring to something else.

My observation is that variable bLength which I expect to be 7 should not change throughout the program since it is only assigned once by the function phpalI14443p3a_ActivateCard at line 240.

If I do a printf of bLength at every line preceding line 284, it would show 7 until after line 284 where it will somewhat be set to 0. Since this variable is not used after line284, hence it would not be obvious that the value held by bLength has changed.

Let me know if I'm not getting across to you. :) Thanks.

eugch avatar Sep 25 '14 12:09 eugch

Ok, indeed, the only line where bLength may change is the line 240 apparently. However the function call, line 240, use a reference to bLength, so it might give this reference to an underlying structure that might change it afterward. Are you sure line 240 is called only once, and that you are not in the second iteration of the loop line 238 ?

I can't test it right know, I don't have a R-Pi nor the Eplore-NFC card in my possession. Might spend some time working on this later this year (wanted to use libuv + a better API and why not add support for other NFC cards)

robinmonjo avatar Sep 25 '14 21:09 robinmonjo

I believe the while loop that begins at line 238 and ends at line 299 should only invoke

phpalI14443p3a_ActivateCard(I14443p3a, NULL, 0x00, bUid, &bLength, bSak, &bMoreCardsAvailable);

once for every card that it detects. It also has to complete write/read operations before terminating the loop.

In any case, I have a temporary workaround which works for now, but I was just curious why would a variable have its value silently changed through the program. We can discuss more on this when you are actively working on this.

Anyways, your code has been very helpful as a starting point for some of the NXP NFC readlib work that I am exploring, in fact it is the only one besides the actual polling program from NXP. Hope to keep in touch and trade notes with you in the future.

eugch avatar Sep 26 '14 00:09 eugch