Fixed reading error code from write response.
authorFlorian Pose <fp@igh-essen.com>
Fri, 05 Mar 2010 16:30:51 +0100
changeset 1840 06fcb795525b
parent 1839 7f36c38e2518
child 1841 4d465f8bf246
Fixed reading error code from write response.
master/fsm_soe.c
--- a/master/fsm_soe.c	Fri Mar 05 16:15:49 2010 +0100
+++ b/master/fsm_soe.c	Fri Mar 05 16:30:51 2010 +0100
@@ -597,20 +597,21 @@
 
 	error_flag = (EC_READ_U8(data) >> 4) & 1;
 	if (error_flag) {
-		req->error_code = EC_READ_U16(data + rec_size - 2);
-		EC_ERR("Received error response: 0x%04x.\n",
-				req->error_code);
-        fsm->state = ec_fsm_soe_error;
+		if (rec_size < EC_SOE_WRITE_RESPONSE_SIZE + 2) {
+			EC_ERR("Received corrupted error response - error flag set,"
+					" but received size is %zu.\n", rec_size);
+		} else {
+			req->error_code = EC_READ_U16(data + EC_SOE_WRITE_RESPONSE_SIZE);
+			EC_ERR("Received error response: 0x%04x.\n",
+					req->error_code);
+		}
+		ec_print_data(data, rec_size);
+		fsm->state = ec_fsm_soe_error;
         return;
 	} else {
 		req->error_code = 0x0000;
 	}
 
-	if (master->debug_level) {
-		EC_DBG("IDN data:\n");
-		ec_print_data(req->data, req->data_size);
-	}
-
     fsm->state = ec_fsm_soe_end; // success
 }