Reputation: 510
I have a JavaCard and can call JCSystem.getAvailableMemory(MEMORY_TYPE_PERSISTENT) and return that from my applet, but I want an exact value if its over 32767 bytes.
Upvotes: 1
Views: 1307
Reputation: 4047
Javacard with GP 2.2 + ETSI support
If your card supports Global Platform 2.2 and ETSI, you can use GET DATA command.
GP card spec 2.2 section 11.3 states that
Tag ‘FF21’: Extended Card Resources Information available for Card Content Management, as defined in ETSI TS 102 226.
And in ETSI 102.226 section 8.2.1.7.2:
After the successful execution of the command, the GET DATA response data field shall be coded as defined in GlobalPlatform [4]. The value of the TLV coded data object referred to in reference control parameters P1 and P2 of the command message is:
Length Description Value
1 Number of installed application tag '81'
1 Number of installed application length X
X Number of installed application
1 Free non volatile memory tag '82'
1 Free non volatile memory length Y
Y Free non volatile memory
1 Free volatile memory tag '83'
1 Free volatile memory length Z
Z Free volatile memory
The response of this command is not restricted to short
value because it is using TLV format, which means you can check free memory that is more than 32767 bytes
Upvotes: 3
Reputation: 21
In general there is no possibility to get the exact amount of free memory from the card using the standard Java Card API. Because most Java Cards don't even have integer support, the maximum value you can get from the APIs method is 32767 (upper bound of signed short).
If you're lucky, there might be some proprietary API method from the card/OS manufacturer. I've seen some proprietary APIs from NXP JCOP cards but none of them is capable of getting the amount of free memory if it exceeds the upper bound of a signed short.
Upvotes: 1