int sst_cmd_func_test(char * func_type, char * tagt_type, unsigned int id , unsigned int *pid) { cmd_t *cmd ; int ret = -1 ; cmd= (sst_get_aw_storage())->cmd ; dprintk("sst_cmd_func_test: function [%s] ,target [%s]\n", func_type, tagt_type); mutex_lock(&com_mutex); do{ sst_memset(func_buf, 0 ,128 ); strncpy(func_buf, func_type, 64); strncpy(func_buf+64, tagt_type,64); /* Updata command */ spin_lock(&cmd->lock); sst_memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_FUNC_TEST; cmd->cmd_param[1] = id ; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY ; cmd->cmd_buf = (unsigned char *)func_buf ; cmd->cmd_buf_len =128 ; spin_unlock(&cmd->lock); /* Send the command */ ret = post_cmd_wait_resp( cmd ); if( ret != 0 ){ derr(" respone a fail flag 0x%x\n", ret); mutex_unlock(&com_mutex); return (- EINVAL ); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ derr(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->status != SST_STAS_CMD_RET ){ derr(" cmd status:0x%x error\n", cmd->status); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->resp_type !=SST_RESP_FUNC_TEST_DONE ){ derr(" error in Swd:response type = 0x%x \n", cmd->resp_type); mutex_unlock(&com_mutex); return (- EINVAL ); } if(pid) *pid = cmd->resp_ret[1]; }while( false ); mutex_unlock(&com_mutex); return (0); }
/* * Send the command to Swd after the read/write work done * * @param: type[in] request store object type * @param: id [in] store object id * @param: buf [in] buffer if read cmd work done * @param: len [out] actual buffer len * * @return: 0 if ok, otherwise fail. * */ int sst_cmd_work_done( unsigned int type, unsigned int id, char *buf, ssize_t len ) { cmd_t *cmd =(sst_get_aw_storage())->cmd ; int ret = -1 ; mutex_lock(&com_mutex); do{ /* Updata command */ spin_lock(&cmd->lock); sst_memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_WORK_DONE; cmd->cmd_param[0] = type ; cmd->cmd_param[1] = id ; cmd->cmd_buf = buf; cmd->cmd_buf_len = len ; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY ; spin_unlock(&cmd->lock); /* Send the command */ ret = post_cmd_wait_resp( cmd ); if( ret != 0 ){ derr(" respone a fail flag 0x%x\n", ret); mutex_unlock(&com_mutex); return (- EINVAL ); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ derr(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->status != SST_STAS_CMD_RET ){ derr(" cmd status:0x%x error\n", cmd->status); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->resp_type != SST_RESP_READ_DONE &&\ cmd->resp_type != SST_RESP_WRITE_DONE ){ derr(" error in Swd:response type = 0x%x \n", cmd->resp_type); mutex_unlock(&com_mutex); return (- EINVAL ); } }while( false ); mutex_unlock(&com_mutex); return (0); }
/* * Send init succeuss command to Swd * * @param: type[in] request store object type * @param: id [in] store object id * @param: buf [in] buffer if read cmd work done * @param: len [out] actual buffer len * * @return: 0 if ok, otherwise fail. * */ int sst_cmd_init_done(void) { cmd_t *cmd =(sst_get_aw_storage())->cmd ; int ret = -1 ; mutex_lock(&com_mutex); do{ /* Updata command */ spin_lock(&cmd->lock); sst_memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_INITIALIZED; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY ; spin_unlock(&cmd->lock); /* Send the command */ ret = post_cmd_wait_resp( cmd ); if( ret != 0 ){ derr(" respone a fail flag 0x%x\n", ret); mutex_unlock(&com_mutex); return (- EINVAL ); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ derr(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->status != SST_STAS_CMD_RET ){ derr(" cmd status:0x%x error\n", cmd->status); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->resp_type !=SST_RESP_INITED_DONE ){ derr(" error in Swd:response type = 0x%x \n", cmd->resp_type); mutex_unlock(&com_mutex); return (- EINVAL ); } }while( false ); mutex_unlock(&com_mutex); return (0); }
/* * update secure object data to SWd * * @param: type[in] request store object type * @param: id [in] store object id * @param: src [in] update store object buffer * @param: len [in] buffer len * * @return: 0 if ok, otherwise fail. * */ int sst_cmd_update_object( unsigned int type , unsigned int id , char *src, ssize_t len, char * name ) { cmd_t *cmd = (sst_get_aw_storage())->cmd ; int ret = -1 ; mutex_lock(&com_mutex); do{ /* Updata command */ spin_lock(&cmd->lock); sst_memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_UPDATE_REQ; cmd->cmd_param[0] = type ; cmd->cmd_param[1] = id ; cmd->cmd_buf = src ; cmd->cmd_buf_len = len ; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY; if(name != NULL && id == OEM_DATA ){ cmd->resp_buf = name ; cmd->resp_buf_len = strnlen(name,64) ; } spin_unlock(&cmd->lock); /* Send the command */ ret = post_cmd_wait_resp( cmd ); if( ret != 0 ){ derr(" command procedure error 0x%x\n", ret); mutex_unlock(&com_mutex); return (- EINVAL ); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ derr(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->status != SST_STAS_CMD_RET ){ derr(" cmd status:0x%x error\n", cmd->status); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->resp_type != SST_RESP_UPDATE_DONE ) { derr(" update error in Swd:\ len = 0x%x , response type =0x%x \n", cmd->resp_buf_len, cmd->resp_type); mutex_unlock(&com_mutex); return (- EFAULT ); } } while( false ) ; mutex_unlock(&com_mutex); return (0); }
/* * send binding request for OEM data * * @param: id [in] store object id * @param: src [in] request store object buffer * @param: len [in] buffer len * @param: dst [out] binding result buffer * * @return: 0 if ok, otherwise fail. * */ int sst_cmd_binding_store( unsigned int id , char *src, ssize_t len, char *dst, ssize_t dst_len , ssize_t *retLen ) { cmd_t *cmd = (sst_get_aw_storage())->cmd ; int ret = -1 ; mutex_lock(&com_mutex); do{ /* Updata command */ spin_lock(&cmd->lock); sst_memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_BIND_REQ; cmd->cmd_param[0] = OEM_DATA ; cmd->cmd_param[1] = id ; cmd->cmd_buf = src ; cmd->cmd_buf_len = len ; cmd->resp_buf = dst; cmd->resp_buf_len = dst_len; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY; spin_unlock(&cmd->lock); /* Send the command */ ret = post_cmd_wait_resp( cmd ); if( ret != 0 ){ derr(" command procedure error 0x%x\n", ret); mutex_unlock(&com_mutex); return (- EINVAL ); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ derr(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->status != SST_STAS_CMD_RET ){ derr(" cmd status:0x%x error\n", cmd->status); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->resp_type != SST_RESP_BIND_DONE ) { derr(" bind error in Swd:\ len = 0x%x , response type =0x%x \n", cmd->resp_buf_len, cmd->resp_type); mutex_unlock(&com_mutex); return (- EFAULT ); } *retLen = cmd->resp_ret[1]; } while( false ) ; mutex_unlock(&com_mutex); return (0); }
/* * Send the polling command to Swd * * @param: pret [out] SWd polling work type. * SST_RESP_READ/SST_RESP_WRITE/SST_RESP_DUMMY ... * @param: ptype [out] read or write work from SWd, OEM or USER data * @param: pid [out] read or write work from SWs, 0x01,0x02 ... * @param: buf [in] buffer if polling write cmd from SWd * @param: len [in] buffer len * @param: retLen [out] actual wirte buffer len * * @return: 0 if ok, otherwise fail. * */ int sst_cmd_polling_swd( unsigned int *pret, unsigned int *ptype, unsigned int *pid, char *buf, ssize_t len, ssize_t *retLen ) { cmd_t *cmd = (sst_get_aw_storage())->cmd ; int ret = -1 ; mutex_lock(&com_mutex); do{ /* Updata command */ spin_lock(&cmd->lock); sst_memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_POLLING; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY ; cmd->resp_buf = buf ; cmd->resp_buf_len = len ; spin_unlock(&cmd->lock); /* Send the command */ ret = post_cmd_wait_resp( cmd ); if( ret != 0 ){ derr(" respone a fail flag 0x%x\n", ret); mutex_unlock(&com_mutex); return (- EINVAL ); } /* Check the response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ derr(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->status != SST_STAS_CMD_RET ){ derr(" cmd status:0x%x error\n", cmd->status); mutex_unlock(&com_mutex); return (- EINVAL ); } if( cmd->resp_type != SST_RESP_DUMMY &&\ cmd->resp_type != SST_RESP_READ &&\ cmd->resp_type != SST_RESP_WRITE &&\ cmd->resp_type != SST_RESP_DELETE){ derr(" error in Swd:response type = 0x%x \n", cmd->resp_type); mutex_unlock(&com_mutex); return (- EINVAL ); } *pret = cmd->resp_type; *ptype = cmd->resp_ret[1]; *pid = cmd->resp_ret[2]; *retLen = cmd->resp_ret[3]; }while( false ); mutex_unlock(&com_mutex); return (0); }
static int sst_cmd_update_object( unsigned int type , unsigned int id , char *src, unsigned int len, char * name ) { cmd_t *cmd ; int ret = -1 ; unsigned char *name_buf ; cmd = malloc(sizeof(*cmd)); name_buf = malloc(strnlen(name, 64)); if(!cmd || !name_buf){ printf("sst_cmd_binding_store out of memory\n"); return -1 ; } memset(cmd, 0, sizeof(*cmd)); do{ memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_UPDATE_REQ; cmd->cmd_param[0] = type ; cmd->cmd_param[1] = id ; cmd->cmd_buf = (unsigned char *)src ; cmd->cmd_buf_len = len ; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY; if(name != NULL && type == OEM_DATA ){ memcpy(name_buf, name, strnlen(name,64)); cmd->resp_buf = (unsigned char *)name_buf ; cmd->resp_buf_len = strnlen(name,64) ; } /* Send the command */ ret = post_cmd_wait_resp(cmd ); if( ret != 0 ){ printf(" command procedure error 0x%x\n", ret); free(cmd); free(name_buf); return (- 1); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ printf(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); free(cmd); free(name_buf); return (- 1 ); } if( cmd->status != SST_STAS_CMD_RET ){ printf(" cmd status:0x%x error\n", cmd->status); free(cmd); free(name_buf); return (- 1 ); } if( cmd->resp_type != SST_RESP_UPDATE_DONE ) { printf(" update error in Swd:\ len = 0x%x , response type =0x%x \n", cmd->resp_buf_len, cmd->resp_type); free(cmd); free(name_buf); return (- 1); } } while( 0 ) ; free(cmd); free(name_buf); return 0; }
static int sst_cmd_binding_store( unsigned int id , char *src, unsigned int len, char *dst, unsigned int *retLen ) { cmd_t *cmd ; int ret = -1 ; cmd = malloc(sizeof(*cmd)); if(!cmd){ printf("sst_cmd_binding_store out of memory\n"); return -1 ; } memset(cmd, 0, sizeof(*cmd)); do{ /* Binding command */ memset(cmd, 0 ,sizeof(*cmd)) ; cmd->cmd_type = SST_CMD_BIND_REQ; cmd->cmd_param[0] = OEM_DATA ; cmd->cmd_param[1] = id ; cmd->cmd_buf = (unsigned char *)src ; cmd->cmd_buf_len = len ; cmd->resp_buf =(unsigned char *)dst; cmd->resp_buf_len = MAX_STORE_LEN; cmd->resp_ret[0] = -1 ; cmd->status = SST_STAS_CMD_RDY; /* Send the command */ ret = post_cmd_wait_resp(cmd ); if( ret != 0 ){ printf(" command procedure error 0x%x\n", ret); free(cmd); return (- 1); } /* Check response */ if( cmd->resp_ret[0] != SST_RESP_RET_SUCCESS ){ printf(" cmd response fail:0x%x error\n", cmd->resp_ret[0]); free(cmd); return (- 1 ); } if( cmd->status != SST_STAS_CMD_RET ){ printf(" cmd status:0x%x error\n", cmd->status); free(cmd); return (- 1 ); } if( cmd->resp_type != SST_RESP_BIND_DONE ) { printf(" bind error in Swd:\ len = 0x%x , response type =0x%x \n", cmd->resp_buf_len, cmd->resp_type); free(cmd); return (- 1); } *retLen = cmd->resp_ret[1]; } while( 0 ) ; free(cmd); return 0; }