Returning NMBS_ERROR_INVALID_UNIT_ID in case of invalid unit ID in response

This commit is contained in:
Valerio De Benedetto 2022-06-26 11:08:16 +02:00
parent 30c7ce3854
commit 037de71d9b
2 changed files with 4 additions and 2 deletions

View File

@ -338,6 +338,7 @@ static nmbs_error recv_req_header(nmbs_t* nmbs, bool* first_byte_received) {
static nmbs_error recv_res_header(nmbs_t* nmbs) {
uint16_t req_transaction_id = nmbs->msg.transaction_id;
uint8_t req_unit_id = nmbs->msg.unit_id;
uint8_t req_fc = nmbs->msg.fc;
nmbs_error err = recv_msg_header(nmbs, NULL);
@ -349,8 +350,8 @@ static nmbs_error recv_res_header(nmbs_t* nmbs) {
return NMBS_ERROR_INVALID_RESPONSE;
}
if (nmbs->msg.ignored)
return NMBS_ERROR_INVALID_RESPONSE;
if (nmbs->msg.unit_id != req_unit_id)
return NMBS_ERROR_INVALID_UNIT_ID;
if (nmbs->msg.fc != req_fc) {
if (nmbs->msg.fc - 0x80 == req_fc) {

View File

@ -54,6 +54,7 @@ extern "C" {
*/
typedef enum nmbs_error {
// Library errors
NMBS_ERROR_INVALID_UNIT_ID = -7, /**< Received invalid unit ID in response from server */
NMBS_ERROR_INVALID_TCP_MBAP = -6, /**< Received invalid TCP MBAP */
NMBS_ERROR_CRC = -5, /**< Received invalid CRC */
NMBS_ERROR_TRANSPORT = -4, /**< Transport error */