I have to do a search in ADN file on SIM card in my STK applet to find someone.
However, if I have to scan the whole number of records in ADN file (even it's a blank record), it will be very slow and I don't know how to get the number of contacts in the ADN file from STK applet.
If anyone of you knows how to get the number of contacts, please share with me and thank you very much in advance.
As the phone has the contact memory usage information (i.e. 34/250), I don't know how the phone get this information and is there any solution that allow STK Applet to get this information from the phone?
Phone select the file and in response to it SIM send the response, for which mobile again run a command which is known as Get Response, In this get response SIM send the details of that file. Now in case of ADN which is a record file command will contains file size and record length so Total records will be Size/Record length.
You can read about these command in more details in 3GPP 11.11
Now regarding searching the data in STK applet is not very time consuming, STK applets are very fast and 250 records are not too much, so in a loop just read record and check for 21 bytes if it is FF then record is empty. Structure of ADM records is:-
1 to X Alpha Identifier O X bytes
X+1 Length of BCD number/SSC contents M 1 byte
X+2 TON and NPI M 1 byte
X+3 to X+12 Dialling Number/SSC String M 10 bytes
X+13 Capability/Configuration Identifier M 1 byte
X+14 Extension1 Record Identifier M 1 byte
In your case length is 34 so first 20 bytes contains the name(here we call it Alpha ID) then number starts. Well I am asking to check 21th byte because it could be a case when user saved a number without any name. So don't check first byte.