anjay
Loading...
Searching...
No Matches
sim_bootstrap.h File Reference
#include <avsystem/commons/avs_stream.h>
#include <avsystem/commons/avs_stream_md5.h>
#include <anjay/bootstrapper.h>

Go to the source code of this file.

Typedefs

typedef int anjay_sim_bootstrap_perform_command_cb_t(void *arg, const void *cmd, size_t cmd_length, void *out_buf, size_t out_buf_size, size_t *out_response_size)
 

Functions

avs_stream_t * anjay_sim_bootstrap_stream_create (anjay_sim_bootstrap_perform_command_cb_t *perform_command_cb, void *perform_command_cb_arg)
 
static avs_error_t anjay_sim_bootstrap_perform (anjay_t *anjay, anjay_sim_bootstrap_perform_command_cb_t *perform_command_cb, void *perform_command_cb_arg)
 
avs_error_t anjay_sim_bootstrap_calculate_md5 (avs_stream_t *stream, uint8_t(*md5)[AVS_COMMONS_MD5_LENGTH])
 

Typedef Documentation

◆ anjay_sim_bootstrap_perform_command_cb_t

typedef int anjay_sim_bootstrap_perform_command_cb_t(void *arg, const void *cmd, size_t cmd_length, void *out_buf, size_t out_buf_size, size_t *out_response_size)

A callback that shall execute a command on the SIM card.

A common way to implement through a cellular modem is to hexlify the cmd parameter and pass it otherwise as-is to the standard AT+CSIM=xx,"..." AT command. The response string from the +CSIM: xx,"..." response would then be unhexlified and also passed otherwise as-is.

Parameters
argOpaque user context argument; the value passed as perform_command_cb_arg to anjay_sim_bootstrap_stream_create or anjay_sim_bootstrap_perform will be passed as-is.
cmdPointer to binary command data. Contains CLA, INS, P1, P2 and optionally Lc, Data and Le bytes according to the APD structure specification as defined in ETSI TS 102 221.
cmd_lengthNumber of bytes at the cmd pointer which are valid and actually form the command.
out_bufPointer to a buffer in which the response (including optional data bytes as well as SW1 and SW2) shall be stored.
out_buf_sizeSize of the buffer pointed to by out_buf (number of bytes that can be safely accessed by the function).
out_response_sizePointer to a variable that, on successful return from this function, will be filled with the number of bytes in out_buf (never more than out_buf_size) that actually form the response from the SIM card.
Returns
0 on success, or a nonzero value in case of error.

Function Documentation

◆ anjay_sim_bootstrap_calculate_md5()

avs_error_t anjay_sim_bootstrap_calculate_md5 ( avs_stream_t *  stream,
uint8_t(*)  md5[AVS_COMMONS_MD5_LENGTH] 
)

Calulates MD5 hash value of a Bootstrap Information stored in an avs_stream_t object previously created with anjay_sim_bootstrap_stream_create().

Parameters
streamStream to opeate on. avs_stream_reset() is called on it on function exit.
md5Pointer to an array of AVS_COMMONS_MD5_LENGTH size that will be filled with MD5 hash value
Returns
AVS_OK in case of success, or an error code.

◆ anjay_sim_bootstrap_perform()

static avs_error_t anjay_sim_bootstrap_perform ( anjay_t anjay,
anjay_sim_bootstrap_perform_command_cb_t perform_command_cb,
void *  perform_command_cb_arg 
)
inlinestatic

Reads LwM2M Bootstrap Information from the SIM card, as described in Appendix G of the LwM2M Core TS, and initializes the Anjay data model according to the data contained inside.

If such bootstrap information is not present on the SIM card, or on any other error, the data model will be left unchanged.

For details on the internals of this process, see LwM2M Core TS 1.2.1, Appendix G https://www.openmobilealliance.org/release/LightweightM2M/V1_2_1-20221209-A/HTML-Version/OMA-TS-LightweightM2M_Core-V1_2_1-20221209-A.html#15-0-Appendix-G-Storage-of-LwM2M-Bootstrap-Information-on-the-Smartcard-Normative.

This is a convenience function that calls anjay_sim_bootstrap_stream_create and anjay_bootstrapper underneath.

Parameters
anjayAnjay object to operate on.
perform_command_cbCallback function to use for performing raw commands on the smartcard.
perform_command_cb_argOpaque argument that will be passed to perform_command_cb .
Returns
AVS_OK in case of success, or an error code.

◆ anjay_sim_bootstrap_stream_create()

avs_stream_t * anjay_sim_bootstrap_stream_create ( anjay_sim_bootstrap_perform_command_cb_t perform_command_cb,
void *  perform_command_cb_arg 
)

Creates an input stream object that reads the LwM2M bootstrap information file (EF LwM2M_Bootstrap) from the SIM card.

The stream object will be allocated on the heap and can be freed using avs_stream_cleanup().

Parameters
perform_command_cbCallback function to use for performing raw commands on the smartcard.
perform_command_cb_argOpaque argument that will be passed to perform_command_cb .
Returns
The newly created stream object, or NULL in case of error.