From dd5d921b794e376579403c983a40c5038b142b31 Mon Sep 17 00:00:00 2001 From: Javier Moragon Date: Fri, 5 Jun 2026 11:12:49 +0200 Subject: [PATCH] socketcand: add < list > command to query available interfaces --- doc/protocol.md | 9 +++++++++ src/state_nobus.c | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/protocol.md b/doc/protocol.md index 62b651d..78602fb 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -11,6 +11,15 @@ After connecting to the socket the client is greeted with '< hi >'. The open com where canbus may be at maximum 16 characters long. If the client is allowed to access the bus the server will respond with '< ok >'. Otherwise an error is returned and the connection is terminated. After a bus was opened the mode is switched to BCM mode. The Mode NO_BUS is the only mode where bittimings or other bus configuration settings may be done. +#### List available buses #### +The list command can be used to query the CAN buses the daemon provides access to. The server answers with a single line containing all available bus names. + + < list > + +The response has the following format, e.g. + + < interfaces can0 can1 > + #### Configure the bittiming #### The protocol enables the client to change the bittiming of a given bus as provided by set link. Automatic bitrate configuration by the kernel is not supported because it is not guaranteed that the corresponding option was enabled during compile time (e.g. in Ubuntu 10.10 it is not). This way it it also easier to implement the function in a microcontroller based adapter. diff --git a/src/state_nobus.c b/src/state_nobus.c index 70a12d5..1f9e5f8 100644 --- a/src/state_nobus.c +++ b/src/state_nobus.c @@ -39,7 +39,19 @@ void state_nobus(void) return; } - if (!strncmp("< open ", buf, 7)) { + if (!strncmp("< list >", buf, 8)) { + size_t len; + + strcpy(buf, "< interfaces"); + len = strlen(buf); + for (i = 0; i < interface_count; i++) { + len += snprintf(buf + len, MAXLEN - len, " %s", interface_names[i]); + } + snprintf(buf + len, MAXLEN - len, " >"); + send(client_socket, buf, strlen(buf), 0); + tcp_quickack(client_socket); + return; + } else if (!strncmp("< open ", buf, 7)) { sscanf(buf, "< open %s>", bus_name); /* check if access to this bus is allowed */