From 0c7d36bbf1df00830c139c3f3feb32be09c7d1a2 Mon Sep 17 00:00:00 2001 From: kubodera_yuichi Date: Thu, 7 Jan 2010 02:16:39 +0000 Subject: [PATCH] =?UTF-8?q?=E8=B5=B7=E5=8B=95=E6=99=82=E3=81=AE=E5=BE=A9?= =?UTF-8?q?=E6=97=A7=E5=87=A6=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@149 ff987cc8-cf2f-4642-8568-d52cce064691 --- cr_hsm_code.c | 107 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 26 deletions(-) diff --git a/cr_hsm_code.c b/cr_hsm_code.c index abefa29..1773b79 100644 --- a/cr_hsm_code.c +++ b/cr_hsm_code.c @@ -316,9 +316,10 @@ int hsm_reset_module( void ) return ret_code; } - // failed state からの復旧要求 - cmd.cmd = Cmd_RetryFailedModule; - cmd.args.retryfailedmodule.module = HSM_MODULE_ID; + // モジュールの状態確認 + cmd.cmd = Cmd_NewEnquiry; + cmd.args.newenquiry.module = HSM_MODULE_ID; + cmd.args.newenquiry.version = EnqVer_Six; ret_code = NFastApp_Transact( connection, NULL, &cmd, &reply, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { @@ -332,30 +333,84 @@ int hsm_reset_module( void ) return ret_code; } - NFastApp_Free_Command( handle, NULL, NULL, &cmd ); - NFastApp_Free_Reply( handle, NULL, NULL, &reply ); - - memset( &cmd, 0, sizeof( cmd ) ); - memset( &reply, 0, sizeof( reply ) ); - - // モジュールのリセット - cmd.cmd = Cmd_ClearUnit; - cmd.args.clearunit.module = HSM_MODULE_ID; - ret_code = NFastApp_Transact( connection, NULL, &cmd, &reply, NULL ); - if ( ret_code != CR_GENID_SUCCESS ) + // モジュールが failed state でないなら以下は必要ないので即終了 + if ( reply.reply.newenquiry.flags & Cmd_NewEnquiry_Reply_flags_Failed ) { - SetErrorInfo( __FUNCTION__, __LINE__ ); - return ret_code; - } - ret_code = reply.status; - if ( ret_code != CR_GENID_SUCCESS ) - { - SetErrorInfo( __FUNCTION__, __LINE__ ); - return ret_code; - } - - NFastApp_Free_Command( handle, NULL, NULL, &cmd ); - NFastApp_Free_Reply( handle, NULL, NULL, &reply ); + NFastApp_Free_Command( handle, NULL, NULL, &cmd ); + NFastApp_Free_Reply( handle, NULL, NULL, &reply ); + + memset( &cmd, 0, sizeof( cmd ) ); + memset( &reply, 0, sizeof( reply ) ); + + // failed state からの復旧要求 + // 必ず Status_OK を返してくるので信用できない + cmd.cmd = Cmd_RetryFailedModule; + cmd.args.retryfailedmodule.module = HSM_MODULE_ID; + ret_code = NFastApp_Transact( connection, NULL, &cmd, &reply, NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + ret_code = reply.status; + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + + NFastApp_Free_Command( handle, NULL, NULL, &cmd ); + NFastApp_Free_Reply( handle, NULL, NULL, &reply ); + + memset( &cmd, 0, sizeof( cmd ) ); + memset( &reply, 0, sizeof( reply ) ); + + // モジュールのリセット + cmd.cmd = Cmd_ClearUnit; + cmd.args.clearunit.module = HSM_MODULE_ID; + ret_code = NFastApp_Transact( connection, NULL, &cmd, &reply, NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + ret_code = reply.status; + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + + NFastApp_Free_Command( handle, NULL, NULL, &cmd ); + NFastApp_Free_Reply( handle, NULL, NULL, &reply ); + + memset( &cmd, 0, sizeof( cmd ) ); + memset( &reply, 0, sizeof( reply ) ); + + // モジュールの状態を再度確認 + cmd.cmd = Cmd_NewEnquiry; + cmd.args.newenquiry.module = HSM_MODULE_ID; + cmd.args.newenquiry.version = EnqVer_Six; + ret_code = NFastApp_Transact( connection, NULL, &cmd, &reply, NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + ret_code = reply.status; + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + + // 復旧しないようなら終了するしかない + if ( reply.reply.newenquiry.flags & Cmd_NewEnquiry_Reply_flags_Failed ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return Status_HardwareFailed; + } + } // 復旧処理 // 切断 ret_code = NFastApp_Disconnect( hsmConnection, NULL );