Skip to contentSkip to conversation

keytable: load bpf protocol for unsupported protocols

PATCH New Sean Young 1 participant 2 messages May 26, 2019 Media (V4L/DVB)

lore
Share & tools
lore

Sean Young

author
#0 lore raw

PATCH 1/2 keytable: load bpf protocol for unsupported protocols

If there is no hardware decoder or kernel software decoder available for a protocol, attempt to load a bpf protocol for this.

This opens the door for building the kernel without IR decoders (non bpf ones) and just rely on bpf and hardware decoders. This requires the bpf decoders to be written though, this still needs to be done.

---
 utils/keytable/keytable.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
utils/keytable/keytable.c +28 -3
index 9384532b..daf82c0e 100644
@@ -326,6 +326,10 @@ static bool compare_parameters(struct toml_table_t *a, struct toml_table_t *b)
 	int64_t avalue, bvalue;
 	const char *name, *raw;
 
+	if (a == NULL || b == NULL) {
+		return true;
+	}
+
 	while ((name = toml_key_in(a, i++)) != NULL) {
 		raw = toml_raw_in(a, name);
 		if (!raw)
@@ -1110,6 +1114,26 @@ static struct sysfs_names *find_device(char *name)
 	return names;
 }
 
+static enum sysfs_protocols create_bpf_for_unsupported(enum sysfs_protocols protocols, enum sysfs_protocols supported)
+{
+	const struct protocol_map_entry *pme;
+	struct bpf_protocol *b;
+
+	for (pme = protocol_map; pme->name; pme++) {
+		if (!(protocols & pme->sysfs_protocol) ||
+		    (supported & pme->sysfs_protocol))
+			continue;
+
+		b = malloc(sizeof(*b));
+		b->name = strdup(pme->name);
+		add_bpf_protocol(b);
+
+		protocols &= ~pme->sysfs_protocol;
+	}
+
+	return protocols;
+}
+
 static enum sysfs_protocols v1_get_hw_protocols(char *name)
 {
 	FILE *fp;
@@ -1466,13 +1490,13 @@ static int set_proto(struct rc_device *rc_dev)
 {
 	int rc = 0;
 
-	rc_dev->current &= rc_dev->supported;
-
 	if (rc_dev->version == VERSION_2) {
 		rc = v2_set_protocols(rc_dev);
 		return rc;
 	}
 
+	rc_dev->current &= rc_dev->supported;
+
 	if (rc_dev->type == SOFTWARE_DECODER) {
 		const struct protocol_map_entry *pme;
 
@@ -2215,7 +2239,8 @@ int main(int argc, char *argv[])
 		if (rc_dev.lirc_name)
 			clear_bpf(rc_dev.lirc_name);
 
-		rc_dev.current = ch_proto;
+		rc_dev.current = create_bpf_for_unsupported(ch_proto, rc_dev.supported);
+
 		if (set_proto(&rc_dev))
 			fprintf(stderr, _("Couldn't change the IR protocols\n"));
 		else {
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 2/2 keytable: add xbox-dvd protocol to match kernel

Rename the bpf protocol to match. Now we can use the generated keymap for the XBox DVD remote.

---
 utils/common/ir-encode.c                      |  1 +
 utils/keytable/bpf_protocols/Makefile.am      |  2 +-
 .../bpf_protocols/{xbox.c => xbox-dvd.c}      |  2 +-
 utils/keytable/keytable.c                     |  4 ++-
 utils/keytable/rc_keymaps/xbox_dvd.toml       |  4 +--
 .../rc_keymaps_userspace/xbox_dvd.toml        | 31 -------------------
 6 files changed, 8 insertions(+), 36 deletions(-)
 rename utils/keytable/bpf_protocols/{xbox.c => xbox-dvd.c} (99%)
 delete mode 100644 utils/keytable/rc_keymaps_userspace/xbox_dvd.toml
utils/common/ir-encode.c +1 -0
index 4bd1b694..93c88501 100644
@@ -375,6 +375,7 @@ static const struct {
 	[RC_PROTO_RCMM12] = { "rc-mm-12", 0x0fff },
 	[RC_PROTO_RCMM24] = { "rc-mm-24", 0xffffff },
 	[RC_PROTO_RCMM32] = { "rc-mm-32", 0xffffffff },
+	[RC_PROTO_XBOX_DVD] = { "xbox-dvd", 0xfff },
 };
 
 static bool str_like(const char *a, const char *b)
utils/keytable/bpf_protocols/Makefile.am +1 -1
index 123b64ec..bca3bdec 100644
@@ -10,7 +10,7 @@ CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
 %.o: %.c bpf_helpers.h
 	$(CLANG) $(CLANG_SYS_INCLUDES) -D__linux__ -I$(top_srcdir)/include -target bpf -O2 -c $<
 
-PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o xbox.o imon_rsc.o
+PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o xbox-dvd.o imon_rsc.o
 
 all: $(PROTOCOLS)
 
utils/keytable/bpf_protocols/xbox-dvd.c renamed from utils/keytable/bpf_protocols/xbox.c +1 -1
similarity index 99%
rename from utils/keytable/bpf_protocols/xbox.c
rename to utils/keytable/bpf_protocols/xbox-dvd.c
index e48e0a79..91b7d02e 100644
@@ -51,7 +51,7 @@ static inline int eq_margin(unsigned d1, unsigned d2)
 	return ((d1 > (d2 - BPF_PARAM(margin))) && (d1 < (d2 + BPF_PARAM(margin))));
 }
 
-SEC("xbox")
+SEC("xbox-dvd")
 int bpf_decoder(unsigned int *sample)
 {
 	unsigned int key = 0;
utils/keytable/keytable.c +3 -1
index daf82c0e..bf5e2c6f 100644
@@ -128,6 +128,7 @@ enum sysfs_protocols {
 	SYSFS_CEC		= (1 << 13),
 	SYSFS_IMON		= (1 << 14),
 	SYSFS_RCMM		= (1 << 15),
+	SYSFS_XBOX_DVD		= (1 << 16),
 	SYSFS_INVALID		= 0,
 };
 
@@ -163,6 +164,7 @@ const struct protocol_map_entry protocol_map[] = {
 	{ "cec",	NULL,		SYSFS_CEC	},
 	{ "imon",	NULL,		SYSFS_IMON	},
 	{ "rc-mm",	NULL,		SYSFS_RCMM	},
+	{ "xbox-dvd",	NULL,		SYSFS_XBOX_DVD	},
 	{ NULL,		NULL,		SYSFS_INVALID	},
 };
 
@@ -1621,7 +1623,7 @@ static void print_scancodes(const struct lirc_scancode *scancodes, unsigned coun
 {
 	unsigned i;
 
-	for (i=0; i< count; i++) {
+	for (i = 0; i < count; i++) {
 		const char *p = protocol_name(scancodes[i].rc_proto);
 
 		printf(_("%llu.%06llu: "),
utils/keytable/rc_keymaps/xbox_dvd.toml +2 -2
index 77863542..16f7bdd5 100644
@@ -1,6 +1,6 @@
 [[protocols]]
-name = "XBox DVD"
-protocol = "xbox"
+name = "xbox_dvd"
+protocol = "xbox_dvd"
 [protocols.scancodes]
 0xa0b = "KEY_OK"
 0xaa6 = "KEY_UP"
utils/keytable/rc_keymaps_userspace/xbox_dvd.toml deleted +0 -31
deleted file mode 100644
index 77863542..00000000
@@ -1,31 +0,0 @@
-[[protocols]]
-name = "XBox DVD"
-protocol = "xbox"
-[protocols.scancodes]
-0xa0b = "KEY_OK"
-0xaa6 = "KEY_UP"
-0xaa7 = "KEY_DOWN"
-0xaa8 = "KEY_RIGHT"
-0xaa9 = "KEY_LEFT"
-0xac3 = "KEY_INFO"
-0xac6 = "KEY_9"
-0xac7 = "KEY_8"
-0xac8 = "KEY_7"
-0xac9 = "KEY_6"
-0xaca = "KEY_5"
-0xacb = "KEY_4"
-0xacc = "KEY_3"
-0xacd = "KEY_2"
-0xace = "KEY_1"
-0xacf = "KEY_0"
-0xad5 = "KEY_ANGLE"
-0xad8 = "KEY_BACK"
-0xadd = "KEY_PREVIOUSSONG"
-0xadf = "KEY_NEXTSONG"
-0xae0 = "KEY_STOP"
-0xae2 = "KEY_REWIND"
-0xae3 = "KEY_FASTFORWARD"
-0xae5 = "KEY_TITLE"
-0xae6 = "KEY_PAUSE"
-0xaea = "KEY_PLAY"
-0xaf7 = "KEY_MENU"
Signature · 1 line
2.20.1