My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Functions
secure_api.h File Reference
#include <sw_types.h>
#include <otz_common.h>
#include <task.h>

Go to the source code of this file.

Classes

struct  otz_secure_encode_cmd
 Encode command structure. More...
 
struct  otz_secure_encode_ctx
 Encode context. More...
 

Functions

int open_session_from_ns (void *param)
 Dispatcher command function to handle the Open session request from non-secure world. More...
 
int close_session_from_ns (void *param)
 Dispatcher command function to handle the Close session request from non-secure world. More...
 
int sa_create_entry_point (int svc_id, sa_config_t *psa_config)
 Invokes the init function of the service task. More...
 
int sa_destroy_entry_point (int svc_id, void *data, int elf_flag)
 Invokes the exit function of the service task. More...
 
int sa_open_session (sa_config_t *psa_config, void *session_context)
 Open Session. More...
 
int sa_close_session (void *session_context)
 Close Session. More...
 
void get_api_context (int *svc_id, int *task_id, int *cmd_id, int *cmd_type)
 Helper function to return the service id, session id and command id from the smc command parameter. More...
 
int decode_data (void *data, struct otzc_encode_meta *meta_data, int *type, int *offset, int *pos, int *mapped, void **out_data, int *out_len)
 Helper function to decode the data which got passed from non-secure world. More...
 
int update_response_len (struct otzc_encode_meta *meta_data, int pos, int len)
 Helper function to update the response length. More...
 
int open_session_from_secure (int svc_id, int *session_id)
 Open session request from secure application task. More...
 
int close_session_from_secure (int svc_id, int session_id)
 Close session request which is got initiated from secure task. More...
 
int ipc_connect (int svc_id, int *session_id)
 Establish session between two tasks. More...
 
int ipc_disconnect (int svc_id, int session_id)
 Disconnect the previously established session between two tasks. More...
 
int ipc_send (int src_svc_id, int src_context, int svc_id, int session_id, int cmd_id, struct otz_secure_encode_ctx *enc_ctx, struct otzc_encode_meta *meta_data)
 Send the data between two tasks. More...
 
int otz_encode_data (struct otz_secure_encode_cmd *enc, struct otzc_encode_meta **pmeta_data, struct otz_secure_encode_ctx **penc_context, int encode_type)
 Helper function to encode the data which originate from secure application. More...
 
int decode_ipi_out_data (void *data, struct otzc_encode_meta *meta_data, int *type, int *offset, int *pos, void **out_data, int *out_len)
 Helper function to decode the response data for IPI. More...
 
void otz_release_data (struct otz_secure_encode_ctx *enc_context, struct otzc_encode_meta *meta_data)
 Release the encoded data. More...
 
int ipc_api (int src_svc_id, int src_session_id, int target_svc_id, int target_cmd_id, void *req_buf, int req_buf_len, void *res_buf, int res_buf_len, int *ret_res_buf_len)
 Helper function to send the data between two tasks for single request and single response buffer. More...
 
void ipc_test_crypto (int src_svc_id, int src_session_id)
 : Test IPC command for crypto operation More...
 
void ipc_test_echo (int src_svc_id, int src_session_id)
 Test IPC command for echo operation. More...
 
void handle_task_return (int task_id, sw_tls *tls)
 Helper function to handle the task return. More...
 
void otz_ipi (struct otz_smc_cmd *smc_cmd)
 Invoke IPI. More...
 
void otz_ipi_return (struct otz_smc_cmd *smc_cmd, int ret_val)
 Return for IPI. More...
 

Function Documentation

int close_session_from_ns ( void *  param)

Dispatcher command function to handle the Close session request from non-secure world.

This function invokes the close session API and its get called from dispatcher task.

Parameters
parampointer to struct otz_smc_cmd
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int close_session_from_secure ( int  svc_id,
int  session_id 
)

Close session request which is got initiated from secure task.

This function invokes the close session API and its get called from secure application task. This is to close the request from secure application, either for IPI or secure to non-secure world communication.

Parameters
svc_idService ID
session_idSession ID
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int decode_data ( void *  data,
struct otzc_encode_meta meta_data,
int *  type,
int *  offset,
int *  pos,
int *  mapped,
void **  out_data,
int *  out_len 
)

Helper function to decode the data which got passed from non-secure world.

This helper function decodes the data which got encoded from non-secure application.

Parameters
dataEncoded data
meta_dataMeta data helps to identify the encoded data
typeData type of the decoded data as output parameter
offsetCurrent offset as input parameter and Next offset as output parameter
posCurrent position as input parameter and Next position as output parameter
mappedDecoded data is shared memory or not as output parameter
out_dataDecoded data as output parameter
out_lenDecoded data length as output parameter
Returns
otz_return_t: OTZ_OK - Decoded data successfully
OTZ_* - An implementation-defined error code for any other error.
This helper function decodes the data which got encoded from non-secure or secure application.
Parameters
dataEncoded data
meta_dataMeta data helps to identify the encoded data
typeData type of the decoded data as output parameter
offsetCurrent offset as input parameter and Next offset as output parameter
posCurrent position as input parameter and Next position as output parameter
mappedDecoded data is shared memory or not as output parameter
out_dataDecoded data as output parameter
out_lenDecoded data length as output parameter
Returns
otz_return_t: OTZ_OK - Decoded data successfully
OTZ_* - An implementation-defined error code for any other error.
int decode_ipi_out_data ( void *  data,
struct otzc_encode_meta meta_data,
int *  type,
int *  offset,
int *  pos,
void **  out_data,
int *  out_len 
)

Helper function to decode the response data for IPI.

This helper function decodes the data which got returned from target secure application.

Parameters
dataEncoded data
meta_dataMeta data helps to identify the encoded data
typeData type of the decoded data as output parameter
offsetCurrent offset as input parameter and Next offset as output parameter
posCurrent position as input parameter and Next position as output parameter
out_dataDecoded data as output parameter
out_lenDecoded data length as output parameter
Returns
otz_return_t: OTZ_OK - Decoded data successfully
OTZ_* - An implementation-defined error code for any other error.
void get_api_context ( int *  svc_id,
int *  task_id,
int *  cmd_id,
int *  cmd_type 
)

Helper function to return the service id, session id and command id from the smc command parameter.

Parameters
svc_idservice identifier as output parameter
task_idsession context as output parameter
cmd_idcommand identifier as output parameter
cmd_typecommand type as output parameter
void handle_task_return ( int  task_id,
sw_tls tls 
)

Helper function to handle the task return.

This function helps to handle the return functionality of task. This function puts the task in to wait or suspend state based on the return value and also helps to set the return value of secure call or IPC call.

Parameters
task_idTask ID
tlsTask local storage
int ipc_api ( int  src_svc_id,
int  src_session_id,
int  target_svc_id,
int  target_cmd_id,
void *  req_buf,
int  req_buf_len,
void *  res_buf,
int  res_buf_len,
int *  ret_res_buf_len 
)

Helper function to send the data between two tasks for single request and single response buffer.

This function helps to send the data between two task of single request and single response. This takes care of session establishment, encoding, sending and decoding of data.

Parameters
src_svc_idSource service ID
src_session_idSource session ID
target_svc_idTarget service ID
target_cmd_idTarget command ID
req_bufRequest buffer
req_buf_lenRequest buffer length
res_bufResponse buffer
res_buf_lenResponse buffer length
ret_res_buf_lenReturn response buffer length
Returns
otz_return_t: OTZ_OK - API success
OTZ_* - An implementation-defined error code for any other error.
int ipc_connect ( int  svc_id,
int *  session_id 
)

Establish session between two tasks.

This function used in IPC functionality to establish session between two tasks.

Parameters
svc_idTarget service ID
session_idSession ID as output parameter
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int ipc_disconnect ( int  svc_id,
int  session_id 
)

Disconnect the previously established session between two tasks.

This function used in IPC functionality to close the session which got established between two tasks.

Parameters
svc_idTarget service ID
session_idSession ID need to be closed
Returns
otz_return_t: OTZ_OK - Session closed successfully
OTZ_* - An implementation-defined error code for any other error.
int ipc_send ( int  src_svc_id,
int  src_context,
int  svc_id,
int  session_id,
int  cmd_id,
struct otz_secure_encode_ctx enc_ctx,
struct otzc_encode_meta meta_data 
)

Send the data between two tasks.

This function used to send the data between two tasks. We need to call this function after the session establishment.

Parameters
src_svc_idSource service ID
src_contextSource session ID
svc_idTarget service ID
session_idTarget session ID
cmd_idTarget command ID
enc_ctxEncode context
meta_dataMeta data
Returns
otz_return_t: OTZ_OK - Data sent successfully
OTZ_* - An implementation-defined error code for any other error.
void ipc_test_crypto ( int  src_svc_id,
int  src_session_id 
)

: Test IPC command for crypto operation

This function helps to test the IPC functionality by invoking crypto operation.

Parameters
src_svc_idSource service ID
src_session_idSource session ID
void ipc_test_echo ( int  src_svc_id,
int  src_session_id 
)

Test IPC command for echo operation.

This function helps to test IPC command of echo service.

Parameters
src_svc_idSource service ID
src_session_idSource session ID
int open_session_from_ns ( void *  param)

Dispatcher command function to handle the Open session request from non-secure world.

This function invokes the open session API and its get called from dispatcher task.

Parameters
parampointer to struct otz_smc_cmd
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int open_session_from_secure ( int  svc_id,
int *  session_id 
)

Open session request from secure application task.

This function invokes the open session API and its get called from secure application task. This is to initiate the request from secure application, either for IPI or secure to non-secure world communication.

Parameters
svc_idService ID
session_idPointer to session ID as an output parameter
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int otz_encode_data ( struct otz_secure_encode_cmd enc,
struct otzc_encode_meta **  pmeta_data,
struct otz_secure_encode_ctx **  penc_context,
int  encode_type 
)

Helper function to encode the data which originate from secure application.

This function encodes the data into a encoder stream and this function gets called from secure application. This will be used for IPI or secure to non-secure communication.

Parameters
encEncode command structure
pmeta_dataMeta data which get populated based on the encoding
penc_contextEncoder context which contains the encoded stream for request and response buffer and its details.
encode_typeEncoding data type - UINT32 or Shared memory
Returns
otz_return_t: OTZ_OK - Encoded data successfully
OTZ_* - An implementation-defined error code for any other error.
void otz_ipi ( struct otz_smc_cmd smc_cmd)

Invoke IPI.

This function formulate the parameters for IPI and suspend the current task and invoke the SWI command for IPI notification

Parameters
smc_cmdPointer to command structure
void otz_ipi_return ( struct otz_smc_cmd smc_cmd,
int  ret_val 
)

Return for IPI.

This function sets the IPI return value in the originated task. Reschedules the originated task.

Parameters
smc_cmdCommand parameter which got passed in IPI
ret_valReturn value of the target task result.
void otz_release_data ( struct otz_secure_encode_ctx enc_context,
struct otzc_encode_meta meta_data 
)

Release the encoded data.

This function releases the resources which got allocated in encoding function.

Parameters
enc_contextEncode context
meta_dataMeta data which got populated in encoding
int sa_close_session ( void *  session_context)

Close Session.

This function close the session which got established between secure and non-secure application. This function destroys the corresponding service task.

Parameters
session_contextSession ID
Returns
otz_return_t: OTZ_OK - Session closed successfully
OTZ_* - An implementation-defined error code for any other error.
int sa_create_entry_point ( int  svc_id,
sa_config_t psa_config 
)

Invokes the init function of the service task.

This function invokes the init function of the corresponding service task

Parameters
svc_idService identifier of the task
psa_configConfiguration details for the task
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int sa_destroy_entry_point ( int  svc_id,
void *  data,
int  elf_flag 
)

Invokes the exit function of the service task.

This function invokes the exit function of the corresponding service task

Parameters
svc_id: service identifier of the task
data: private data which need to be freed
elf_flag: to free the mapped secure memory
Returns
otz_return_t: OTZ_OK - Session closed successfully
OTZ_* - An implementation-defined error code for any other error.
int sa_open_session ( sa_config_t psa_config,
void *  session_context 
)

Open Session.

This function establish the session between secure and non-secure application. This function creates the task correspond to the service ID.

Parameters
psa_configPointer to task init configuration structure.
session_contextSession ID as output parameter.
Returns
otz_return_t: OTZ_OK - Session established successfully
OTZ_* - An implementation-defined error code for any other error.
int update_response_len ( struct otzc_encode_meta meta_data,
int  pos,
int  len 
)

Helper function to update the response length.

Parameters
meta_dataMeta data helps to identify the encoded data
posCurrent position
lennew response length
Returns
otz_return_t: OTZ_OK - Updated responsed length successfully
OTZ_* - An implementation-defined error code for any other error.