Skip to content

Commit a1d00bf

Browse files
committed
Return exception response for READ EXCEPTION STATUS (0x07)
The server was silently dropping requests with function code 0x07, returning -1 with errno ENOPROTOOPT and sending nothing back to the client. This violates the Modbus specification which requires a response for every valid request. Now returns ILLEGAL_FUNCTION exception, which is the correct response for an unimplemented function code. Closes #813
1 parent e5cee8b commit a1d00bf

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/modbus.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,11 +1086,12 @@ int modbus_reply(modbus_t *ctx,
10861086
rsp[byte_count_pos] = rsp_length - byte_count_pos - 1;
10871087
} break;
10881088
case MODBUS_FC_READ_EXCEPTION_STATUS:
1089-
if (ctx->debug) {
1090-
fprintf(stderr, "FIXME Not implemented\n");
1091-
}
1092-
errno = ENOPROTOOPT;
1093-
return -1;
1089+
rsp_length = response_exception(ctx,
1090+
&sft,
1091+
MODBUS_EXCEPTION_ILLEGAL_FUNCTION,
1092+
rsp,
1093+
TRUE,
1094+
"Unsupported function: READ EXCEPTION STATUS (0x07)\n");
10941095
break;
10951096
case MODBUS_FC_MASK_WRITE_REGISTER: {
10961097
int mapping_address = address - mb_mapping->start_registers;

0 commit comments

Comments
 (0)