@@ -233,6 +233,11 @@ static int _wh_Server_HandleCommRequest(whServerContext* server,
233233 /* Process the init action */
234234 server -> comm -> client_id = req .client_id ;
235235
236+ /* A fresh INIT after a prior CLOSE must put the channel back into
237+ * the connected state so the subsequent request loop accepts non-
238+ * COMM groups again. */
239+ wh_Server_SetConnected (server , WH_COMM_CONNECTED );
240+
236241 resp .client_id = server -> comm -> client_id ;
237242 resp .server_id = server -> comm -> server_id ;
238243
@@ -526,9 +531,8 @@ int wh_Server_HandleRequestMessage(whServerContext* server)
526531 /* Use the CommServer internal buffer to avoid copies */
527532 data = wh_CommServer_GetDataPtr (server -> comm );
528533
529- /* Are we connected with a valid data pointer? */
530- if ( (server -> connected == WH_COMM_DISCONNECTED ) ||
531- (data == NULL ) ) {
534+ /* Valid data pointer? */
535+ if (data == NULL ) {
532536 return WH_ERROR_NOTREADY ;
533537 }
534538
@@ -539,6 +543,15 @@ int wh_Server_HandleRequestMessage(whServerContext* server)
539543 group = WH_MESSAGE_GROUP (kind );
540544 action = WH_MESSAGE_ACTION (kind );
541545
546+ /* When disconnected, only allow COMM-group messages through so the
547+ * client can re-establish (INIT), interrogate (INFO/ECHO) or repeat
548+ * a CLOSE on the channel. Any other request is rejected with
549+ * NOTREADY until a fresh INIT brings the channel back up. */
550+ if (server -> connected == WH_COMM_DISCONNECTED &&
551+ group != WH_MESSAGE_GROUP_COMM ) {
552+ return WH_ERROR_NOTREADY ;
553+ }
554+
542555#ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION
543556 /* General authentication check for if user has permissions for the
544557 * group and action requested. When dealing with key ID's there should
0 commit comments