[cecd-devel] [PATCH 2/6] [cecd] check and handle libcec_decode_message return values
Status: Beta
Brought to you by:
pbatard
|
From: Florian F. <f.f...@gm...> - 2011-12-30 14:11:46
|
In case we do not recognize the opcode, or the parameters supplied
are invalid it is mandatory to reply with a <Feature Abort> message
with the proper [Abort Reason].
---
cecd/cecd.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/cecd/cecd.c b/cecd/cecd.c
index 48e62b0..acc9859 100644
--- a/cecd/cecd.c
+++ b/cecd/cecd.c
@@ -891,7 +891,10 @@ 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)
+ buffer[1] = CEC_OP_ABORT;
+
if (len <= 1) {
// Ignore ACK, etc.
continue;
@@ -967,7 +970,17 @@ int main(int argc, char** argv)
if ((buffer[0] & 0x0f) == 0x0f)
break;
buffer[1] = CEC_OP_FEATURE_ABORT;
- buffer[2] = CEC_ABORT_REFUSED;
+ switch (r) {
+ case LIBCEC_ERROR_NOT_SUPPORTED:
+ buffer[2] = CEC_ABORT_UNRECOGNIZED;
+ break;
+ case LIBCEC_ERROR_INVALID_PARAM:
+ buffer[2] = CEC_ABORT_INVALID_OPERAND;
+ break;
+ default:
+ buffer[2] = CEC_ABORT_REFUSED;
+ break;
+ }
len = 3;
break;
@@ -982,6 +995,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
|