[cecd-devel] [PATCH 2/6 v2] [cecd] check and handle libcec_decode_message return values
Status: Beta
Brought to you by:
pbatard
|
From: Florian F. <f.f...@gm...> - 2012-01-03 13:08:38
|
In case we do not recognize the opcode, it is mandatory to reply with
a <Feature Abort> message with the proper [Abort Reason]. If the error
returned is INVALID_PARAM, which corresponds to an invalid payload length
or number of operands, do not reply per specification.
---
Changes since v1:
- added check to verify length is big enough to access opcode byte
- removed reply in case of invalid payload lenght as said by specification
- store opcode for insertion in CEC_OP_FEATURE_ABORT reply
cecd/cecd.c | 25 +++++++++++++++++++++----
1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/cecd/cecd.c b/cecd/cecd.c
index 48e62b0..f96347b 100644
--- a/cecd/cecd.c
+++ b/cecd/cecd.c
@@ -603,7 +603,7 @@ int main(int argc, char** argv)
uint16_t physical_address = 0xFFFF;
// TODO: check for seq_data overflow
uint16_t seq_data[CEC_MAX_COMMAND_SIZE], seq_len, ucp_unprocessed[CEC_MAX_COMMAND_SIZE], cec_unprocessed[CEC_MAX_COMMAND_SIZE];
- uint8_t i, byte, buffer[CEC_MAX_COMMAND_SIZE];
+ uint8_t i, byte, buffer[CEC_MAX_COMMAND_SIZE], opcode = 0;
uint8_t ucp_unprocessed_len = 0, ucp_processed_len, cec_unprocessed_len = 0, cec_processed_len;
char *target_device, *device_name, *str = NULL, *saveptr = NULL, **key, *val;
@@ -891,7 +891,12 @@ int main(int argc, char** argv)
cecd_log("could not read message (error %d)\n", len);
continue;
}
- libcec_decode_message(buffer, len);
+ r = libcec_decode_message(buffer, len);
+ if (r != LIBCEC_SUCCESS && len >= 2) {
+ opcode = buffer[1];
+ buffer[1] = CEC_OP_ABORT;
+ }
+
if (len <= 1) {
// Ignore ACK, etc.
continue;
@@ -967,8 +972,19 @@ int main(int argc, char** argv)
if ((buffer[0] & 0x0f) == 0x0f)
break;
buffer[1] = CEC_OP_FEATURE_ABORT;
- buffer[2] = CEC_ABORT_REFUSED;
- len = 3;
+ buffer[2] = opcode;
+ switch (r) {
+ case LIBCEC_ERROR_NOT_SUPPORTED:
+ buffer[3] = CEC_ABORT_UNRECOGNIZED;
+ break;
+ case LIBCEC_ERROR_INVALID_PARAM:
+ len = 0;
+ break;
+ default:
+ buffer[3] = CEC_ABORT_REFUSED;
+ break;
+ }
+ len = 4;
break;
default:
@@ -982,6 +998,7 @@ int main(int argc, char** argv)
len = 0;
break;
}
+
if (len) {
if (libcec_write_message(handle, buffer, len)) {
cecd_log("could not send message\n");
--
1.7.5.4
|