Basic data read process
Repeat the basic read data process for each file that Eseye delivers to the AnyNet Secure SIM. For more information, see Available files and sizes.
Use the following process actions:
Read file header using the block read function
If ((HeaderLength != 0) and (HeaderLength != 0xFFFF) and (HeaderChecksum != 0) and (HeaderChecksum != 0xFFFFFFFF)) then
{
// FILE ready to read
Read file data in chunks() // using calls to block read function()
Verify checksum ()
File Format Conversion () // convert DER to PEM as required
}
else
{
// FILE not found – random back-off and try again
}Read block function
We recommend that you implement a single function to request a block read of file data from the AnyNet Secure SIM.
For a description of the parameters, see AT+CRSM – reading files from the SIM.
Use AT+CRSM to achieve a block read, with the following format:
where data is unused and therefore empty.
This command returns:
where "" is an ASCII hex string that you must return to binary form.
Example
To read the Thing Name file header into a buffer called returned_data, call the read block function as follows:
Thing Name fileid: 28640
Offset: 0
readlength: 6 bytes
where "4D4150" is the string for "MAP".
The first character in the data is the upper nibble of the first data byte. The second character is the lower nibble of the first data byte. You must convert each nibble into its hexadecimal data byte value.
Converting the returned data into binary
You must convert the "RETURNEDDATA" ASCII hexadecimal string into binary.
Example
The following example processes the returned string, reading two ASCII characters and converting them to binary. The resultant byte value is stored at the location defined by output_data:
Reading the file header
The following example uses the read block function to read the Thing Name header, returning 6 bytes from offset 0. 6 bytes is the header size.
Call the read block function with the following parameters:
Thing Name fileid: 28640
offset: 0
readlength: 6 bytes
If you use the suggested read block functionality, then the returned data is in binary format, not the ASCII hex returned by the modem.
After the response data is received, you can extract the file header length (2 bytes) and checksum (4 bytes). For more information, see File format.
Both values are big-endian. You may need to reverse the byte order.
If datalength is not equal to 0 and 0xFFFF, and the checksum is not equal to 0 and 0xFFFFFFFF, you can read the rest of the file.
Reading the file in chunks
After reading the file header, you can read the data content, starting at offset 6. Read up to 255 bytes at a time.
Check the modem command manual, as shorter length limits per read may apply.
Example
The following example reads the Root CA file, of length 1239 bytes.
For a file with a data record of 927 bytes, this code results in the following call sequence:
which in turn will issue the following AT commands:
File verification
After all the data bytes are read from the AnyNet Secure SIM, you must verify them. Perform a CRC32 calculation for the data and compare it to the checksum in the header. If the sum matches, the file read is complete. Otherwise randomly backoff to wait until the file update completes, and then try again.
For more information, see CRC-32 code example.
File format conversion
The following files are transferred in Binary DER-encoded / ASN.1 BER-encoded format:
Root CA fileid: 28641
Public signed certificate fileid: 28642
Private key fileid: 28643
You may need to convert these into PEM or base64 format for use with the SSL/TLS client. Use base64 to encode the data and add header and footer lines.
Example
For the Public signed certificate file:
Last updated
Was this helpful?