aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Young <sean@mess.org>2016-11-29 14:12:40 +0000
committerGregor Jasny <gjasny@googlemail.com>2017-01-16 20:56:31 +0100
commit63ad731274b6dc8d5c77d9ada6d2e4b1dcaa7a71 (patch)
tree6221a5ddbdb8143bc46796ef793a226963fc0a50
parentf5b50505ce6174028d147c6a7f34add3c085c1ff (diff)
ir-ctl: improve scancode validation
Ensure rc6 mce is that just that and that nec32 is not necx or nec. Signed-off-by: Sean Young <sean@mess.org>
-rw-r--r--utils/ir-ctl/ir-ctl.c4
-rw-r--r--utils/ir-ctl/ir-encode.c18
-rw-r--r--utils/ir-ctl/ir-encode.h1
3 files changed, 21 insertions, 2 deletions
diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index 768daad0..53ff8cab 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -242,7 +242,7 @@ static struct file *read_file(const char *fname)
return NULL;
}
- if (scancode & ~protocol_scancode_mask(proto)) {
+ if (!protocol_scancode_valid(proto, scancode)) {
fprintf(stderr, _("error: %s:%d: invalid scancode '%s' for protocol '%s'\n"), fname, lineno, scancodestr, protocol_name(proto));
return NULL;
}
@@ -354,7 +354,7 @@ static struct file *read_scancode(const char *name)
return NULL;
}
- if (scancode & ~protocol_scancode_mask(proto)) {
+ if (!protocol_scancode_valid(proto, scancode)) {
fprintf(stderr, _("error: invalid scancode '%s' for protocol '%s'\n"), p + 1, protocol_name(proto));
return NULL;
}
diff --git a/utils/ir-ctl/ir-encode.c b/utils/ir-ctl/ir-encode.c
index 0c1d0d59..9256087f 100644
--- a/utils/ir-ctl/ir-encode.c
+++ b/utils/ir-ctl/ir-encode.c
@@ -416,6 +416,24 @@ unsigned protocol_scancode_mask(enum rc_proto proto)
return encoders[proto].scancode_mask;
}
+bool protocol_scancode_valid(enum rc_proto p, unsigned s)
+{
+ if (s & ~encoders[p].scancode_mask)
+ return false;
+
+ if (p == RC_PROTO_NECX) {
+ return (((s >> 16) ^ ~(s >> 8)) & 0xff) != 0;
+ } else if (p == RC_PROTO_NEC32) {
+ return (((s >> 24) ^ ~(s >> 16)) & 0xff) != 0;
+ } else if (p == RC_PROTO_RC6_MCE) {
+ return (s & 0xffff0000) == 0x800f0000;
+ } else if (p == RC_PROTO_RC6_6A_32) {
+ return (s & 0xffff0000) != 0x800f0000;
+ }
+
+ return true;
+}
+
unsigned protocol_encode(enum rc_proto proto, unsigned scancode, unsigned *buf)
{
return encoders[proto].encode(proto, scancode, buf);
diff --git a/utils/ir-ctl/ir-encode.h b/utils/ir-ctl/ir-encode.h
index b2542ec0..4a51f1c0 100644
--- a/utils/ir-ctl/ir-encode.h
+++ b/utils/ir-ctl/ir-encode.h
@@ -28,6 +28,7 @@ enum rc_proto {
bool protocol_match(const char *name, enum rc_proto *proto);
unsigned protocol_carrier(enum rc_proto proto);
unsigned protocol_max_size(enum rc_proto proto);
+bool protocol_scancode_valid(enum rc_proto proto, unsigned scancode);
unsigned protocol_scancode_mask(enum rc_proto proto);
unsigned protocol_encode(enum rc_proto proto, unsigned scancode, unsigned *buf);
const char *protocol_name(enum rc_proto proto);

Privacy Policy