@@ -181,17 +181,26 @@ static int _getCryptoResponse(uint8_t* respBuf, uint16_t type,
181181
182182 return header -> rc ;
183183}
184- static int _wait_response_with_crypttimeout (whClientContext * ctx ,
185- uint16_t * out_group , uint16_t * out_action ,
186- uint16_t * out_size , void * data )
184+ static int _SendRecieveWithTimeout (whClientContext * ctx ,
185+ uint16_t * group , uint16_t * action , uint16_t req_len ,
186+ uint16_t * res_len , void * data )
187187{
188+
188189 int ret = WH_ERROR_OK ;
190+
191+ ret = wh_Client_SendRequest (ctx , * group , * action , req_len , data );
192+ #if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
193+ if (ret == WH_ERROR_OK ) {
194+ ret = wh_Client_TimeoutStart (ctx );
195+ }
196+ #endif
197+
189198 do {
190- ret = wh_Client_RecvResponse (ctx , out_group , out_action , out_size , data );
199+ ret = wh_Client_RecvResponse (ctx , group , action , res_len , data );
191200#if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
192201 if (ret == WH_ERROR_NOTREADY ) {
193202 /* Check for crypto timeout */
194- int chk = wh_Client_CheckTimeout (ctx );
203+ int chk = wh_Client_TimeoutCheck (ctx );
195204 if (chk == WH_ERROR_TIMEOUT ) {
196205 return WH_ERROR_TIMEOUT ;
197206 } else if (chk < 0 && chk != WH_ERROR_OK ) {
@@ -251,17 +260,11 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
251260 (unsigned int )size );
252261 WH_DEBUG_CLIENT_VERBOSE ("RNG: req:%p\n" , req );
253262
254- /* Send request and get response */
255- ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
256- #if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
257- if (ret == WH_ERROR_OK ) {
258- ret = wh_Client_InitCryptTimeout (ctx );
259- }
260- #endif
263+ /* Send request and get response with Timeout */
261264 if (ret == 0 ) {
262265 do {
263- ret = _wait_response_with_crypttimeout (ctx , & group , & action , & res_len ,
264- dataPtr );
266+ ret = _SendRecieveWithTimeout (ctx , & group , & action ,
267+ req_len , & res_len , dataPtr );
265268 } while (ret == WH_ERROR_NOTREADY );
266269 }
267270 if (ret == WH_ERROR_OK ) {
@@ -435,20 +438,15 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
435438 WH_DEBUG_VERBOSE_HEXDUMP ("[client] iv: \n" , req_iv , iv_len );
436439 WH_DEBUG_VERBOSE_HEXDUMP ("[client] tmp: \n" , req_tmp , AES_BLOCK_SIZE );
437440 WH_DEBUG_VERBOSE_HEXDUMP ("[client] req packet: \n" , (uint8_t * )req , req_len );
438- ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
439- #if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
440- if (ret == WH_ERROR_OK ) {
441- ret = wh_Client_InitCryptTimeout (ctx );
442- }
443- #endif
444- /* read response */
441+
442+ /* Send and get response with Timeout */
445443 if (ret == WH_ERROR_OK ) {
446444 /* Response packet */
447445 uint16_t res_len = 0 ;
448446 do {
449447 ret =
450- _wait_response_with_crypttimeout (ctx , & group , & action ,
451- & res_len , dataPtr );
448+ _SendRecieveWithTimeout (ctx , & group , & action ,
449+ req_len , & res_len , dataPtr );
452450 } while (ret == WH_ERROR_NOTREADY );
453451
454452 if (ret == WH_ERROR_OK ) {
@@ -554,20 +552,15 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
554552 WH_DEBUG_VERBOSE_HEXDUMP ("[client] key: \n" , req_key , key_len );
555553 WH_DEBUG_VERBOSE_HEXDUMP ("[client] iv: \n" , req_iv , iv_len );
556554 WH_DEBUG_VERBOSE_HEXDUMP ("[client] req packet: \n" , (uint8_t * )req , req_len );
557- ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
558- #if defined(WOLFHSM_CFG_ENABLE_CWOLFHSM_CFG_CLIENT_TIMEOUTLIENT_TIMEOUT )
559- if (ret == WH_ERROR_OK ) {
560- ret = wh_Client_InitCryptTimeout (ctx );
561- }
562- #endif
563- /* read response */
555+
556+ /* Send and get response with Timeout */
564557 if (ret == WH_ERROR_OK ) {
565558 /* Response packet */
566559 uint16_t res_len = 0 ;
567560 do {
568561 ret =
569- _wait_response_with_crypttimeout (ctx , & group , & action ,
570- & res_len , dataPtr );
562+ _SendRecieveWithTimeout (ctx , & group , & action ,
563+ req_len , & res_len , dataPtr );
571564 } while (ret == WH_ERROR_NOTREADY );
572565
573566 if (ret == WH_ERROR_OK ) {
@@ -670,20 +663,14 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
670663 WH_DEBUG_VERBOSE_HEXDUMP ("[client] key: \n" , req_key , key_len );
671664 WH_DEBUG_VERBOSE_HEXDUMP ("[client] iv: \n" , req_iv , iv_len );
672665 WH_DEBUG_VERBOSE_HEXDUMP ("[client] req packet: \n" , (uint8_t * )req , req_len );
673- ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
674- #if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
675- if (ret == WH_ERROR_OK ) {
676- ret = wh_Client_InitCryptTimeout (ctx );
677- }
678- #endif
679- /* read response */
666+ /* Send and get response with Timeout */
680667 if (ret == WH_ERROR_OK ) {
681668 /* Response packet */
682669 uint16_t res_len = 0 ;
683670 do {
684671 ret =
685- _wait_response_with_crypttimeout (ctx , & group , & action ,
686- & res_len , dataPtr );
672+ _SendRecieveWithTimeout (ctx , & group , & action ,
673+ req_len , & res_len , dataPtr );
687674 } while (ret == WH_ERROR_NOTREADY );
688675
689676 if (ret == WH_ERROR_OK ) {
@@ -799,19 +786,13 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
799786
800787 WH_DEBUG_VERBOSE_HEXDUMP ("[client] AESGCM req packet: \n" , dataPtr , req_len );
801788
802- /* Send request and receive response */
803- ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
804- #if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
805- if (ret == WH_ERROR_OK ) {
806- ret = wh_Client_InitCryptTimeout (ctx );
807- }
808- #endif
789+ /* Send and get response with Timeout */
809790 if (ret == 0 ) {
810791 uint16_t res_len = 0 ;
811792 do {
812793 ret =
813- _wait_response_with_crypttimeout (ctx , & group , & action ,
814- & res_len , dataPtr );
794+ _SendRecieveWithTimeout (ctx , & group , & action ,
795+ req_len , & res_len , dataPtr );
815796 } while (ret == WH_ERROR_NOTREADY );
816797
817798 if (ret == WH_ERROR_OK ) {
@@ -1004,20 +985,13 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
1004985 /* Send request and receive response */
1005986 reqLen = sizeof (whMessageCrypto_GenericRequestHeader ) + sizeof (* req );
1006987 WH_DEBUG_VERBOSE_HEXDUMP ("[client] AESGCM DMA req packet: \n" , dataPtr , reqLen );
1007- if (ret == WH_ERROR_OK ) {
1008- ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
1009- }
1010- #if defined(WOLFHSM_CFG_CLIENT_TIMEOUT )
1011- if (ret == WH_ERROR_OK ) {
1012- ret = wh_Client_InitCryptTimeout (ctx );
1013- }
1014- #endif
988+ /* Send and get response with Timeout */
1015989 if (ret == 0 ) {
1016990 uint16_t resLen = 0 ;
1017991 do {
1018992 ret =
1019- _wait_response_with_crypttimeout (ctx , & group , & action ,
1020- & resLen , dataPtr );
993+ _SendRecieveWithTimeout (ctx , & group , & action ,
994+ reqLen , & resLen , dataPtr );
1021995 } while (ret == WH_ERROR_NOTREADY );
1022996
1023997 if (ret == WH_ERROR_OK ) {
0 commit comments