mirror of
https://github.com/D-Modem/gui.git
synced 2026-11-28 14:19:58 -08:00
Support the MultiTech MT9234MU: find it on Linux, page ATI11
- libdmodemctl: a command's response in pages (ATI11 on the Agere modems, the MultiTech MT9234 among them) stops at "Press any key". The session now sends a space at that prompt, for 8 pages at most, and keeps the prompt out of the response. So the Call Stats page gets the full report instead of a timeout. Text typed in the terminal is left to the user. A test covers it. - Linux: usbmodem.c finds an MT9234MU or MT9234ZBA-USB in sysfs. The line settings show its ttyUSB with a "Use" button, or say that it needs mts_mt9234mu.fw (or the ti_usb_3410_5052 driver). Its port opens with RTS/CTS (the modem's &K3). - docs/design.md: hardware modems on each system, the firmware file and the country setting (AT%T19). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRTNWiwCE3duMg28226
This commit is contained in:
9 files changed
+312
-4
No files matched your search
@@ -5,6 +5,7 @@ add_executable(dmodem-gui
|
||||
src/window.c
|
||||
src/modem.c
|
||||
src/config.c
|
||||
src/usbmodem.c
|
||||
src/settings.c
|
||||
src/stats.c
|
||||
src/voice.c
|
||||
|
||||
@@ -102,6 +102,23 @@ gboolean config_sip_ready(const Config *c);
|
||||
/* the line settings dialog */
|
||||
void prefs_show(App *a);
|
||||
|
||||
/* usbmodem.c: a MultiTech MT9234MU (or MT9234ZBA-USB) on USB, from
|
||||
sysfs */
|
||||
typedef struct UsbModem {
|
||||
char *name; /* "MultiTech MT9234MU" */
|
||||
char *tty; /* "/dev/ttyUSB0", or NULL if it has none */
|
||||
gboolean no_firmware; /* in the boot ROM: no firmware loaded */
|
||||
} UsbModem;
|
||||
/* the first one plugged in, or NULL */
|
||||
UsbModem *usbmodem_find(void);
|
||||
/* what it is and where, or what it needs, for the user */
|
||||
char *usbmodem_describe(const UsbModem *m);
|
||||
/* whether Linux has its firmware file (mts_mt9234mu.fw) */
|
||||
gboolean usbmodem_firmware_present(void);
|
||||
/* whether tty path is such a modem's */
|
||||
gboolean usbmodem_is(const char *path);
|
||||
void usbmodem_free(UsbModem *m);
|
||||
|
||||
/* modem.c */
|
||||
void modem_start(App *a);
|
||||
void modem_stop(App *a);
|
||||
|
||||
+34
-1
@@ -305,6 +305,37 @@ static AdwPreferencesGroup *group(AdwPreferencesPage *page, const char *title,
|
||||
return ADW_PREFERENCES_GROUP(g);
|
||||
}
|
||||
|
||||
static void use_found(GtkButton *b, gpointer data)
|
||||
{
|
||||
Prefs *p = data;
|
||||
gtk_editable_set_text(GTK_EDITABLE(p->device),
|
||||
g_object_get_data(G_OBJECT(b), "tty"));
|
||||
}
|
||||
|
||||
/* a MultiTech MT9234MU plugged in: a row that says where it is (with a
|
||||
button that puts it in Device), or what it needs */
|
||||
static void device_found(Prefs *p)
|
||||
{
|
||||
UsbModem *m = usbmodem_find();
|
||||
if (!m)
|
||||
return;
|
||||
char *d = usbmodem_describe(m);
|
||||
GtkWidget *r = adw_action_row_new();
|
||||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(r), "Found");
|
||||
adw_action_row_set_subtitle(ADW_ACTION_ROW(r), d);
|
||||
if (m->tty) {
|
||||
GtkWidget *b = gtk_button_new_with_label("Use");
|
||||
gtk_widget_set_valign(b, GTK_ALIGN_CENTER);
|
||||
g_object_set_data_full(G_OBJECT(b), "tty", g_strdup(m->tty),
|
||||
g_free);
|
||||
g_signal_connect(b, "clicked", G_CALLBACK(use_found), p);
|
||||
adw_action_row_add_suffix(ADW_ACTION_ROW(r), b);
|
||||
}
|
||||
adw_preferences_group_add(p->device_g, r);
|
||||
g_free(d);
|
||||
usbmodem_free(m);
|
||||
}
|
||||
|
||||
static char *text_of(AdwEntryRow *r)
|
||||
{
|
||||
return g_strstrip(g_strdup(gtk_editable_get_text(GTK_EDITABLE(r))));
|
||||
@@ -388,8 +419,10 @@ void prefs_show(App *a)
|
||||
p->alsa = entry(p->alsa_g, "ALSA device", c->alsa);
|
||||
p->device_g = group(page, "A modem that already runs",
|
||||
"dmodemd started as a service, or any modem's "
|
||||
"serial port.");
|
||||
"serial port (a MultiTech MT9234MU is "
|
||||
"/dev/ttyUSB0).");
|
||||
p->device = entry(p->device_g, "Device", c->device);
|
||||
device_found(p);
|
||||
|
||||
AdwPreferencesGroup *adv = group(page, "Advanced", NULL);
|
||||
p->init = entry(adv, "Commands when the modem opens", c->init);
|
||||
|
||||
@@ -157,6 +157,10 @@ static gboolean open_dte(App *a, const char *path)
|
||||
cfsetispeed(&t, B115200);
|
||||
cfsetospeed(&t, B115200);
|
||||
t.c_cflag |= CLOCAL | CREAD;
|
||||
/* (a MultiTech MT9234MU: RTS/CTS, its &K3, so that the
|
||||
modem's buffer does not overflow in a fast call) */
|
||||
if (usbmodem_is(path))
|
||||
t.c_cflag |= CRTSCTS;
|
||||
tcsetattr(fd, TCSANOW, &t);
|
||||
}
|
||||
a->fd = fd;
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* usbmodem.c - hardware modems on USB that the "device" line can open:
|
||||
* the MultiTech MT9234MU and MT9234ZBA-USB, found in sysfs
|
||||
*
|
||||
* These modems have a TI TUSB3410 USB UART. Linux's ti_usb_3410_5052
|
||||
* driver downloads its firmware (mts_mt9234mu.fw) into the chip; then
|
||||
* the modem is a ttyUSB. Without the firmware file the modem stays in
|
||||
* the chip's boot ROM (one configuration) and has no tty.
|
||||
*/
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "app.h"
|
||||
|
||||
/* MultiTech's vendor ID and the products with a TUSB3410 */
|
||||
static const struct {
|
||||
const char *product, *name;
|
||||
} models[] = {
|
||||
{ "f114", "MultiTech MT9234MU" },
|
||||
{ "f115", "MultiTech MT9234ZBA-USB" },
|
||||
{ "0319", "MultiTech MT9234ZBA-USB" },
|
||||
};
|
||||
|
||||
/* the firmware file's places that Linux looks in */
|
||||
static const char *const firmware[] = {
|
||||
"/lib/firmware/updates/mts_mt9234mu.fw",
|
||||
"/lib/firmware/mts_mt9234mu.fw",
|
||||
"/usr/lib/firmware/updates/mts_mt9234mu.fw",
|
||||
"/usr/lib/firmware/mts_mt9234mu.fw",
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the trimmed text of sysfs file dir/name, or NULL */
|
||||
static char *attr(const char *dir, const char *name)
|
||||
{
|
||||
char *path = g_build_filename(dir, name, NULL);
|
||||
char *t = NULL;
|
||||
if (g_file_get_contents(path, &t, NULL, NULL))
|
||||
g_strstrip(t);
|
||||
g_free(path);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* the first ttyUSB under USB device dir's interfaces, as /dev/ttyUSBn,
|
||||
or NULL */
|
||||
static char *tty_of(const char *dir)
|
||||
{
|
||||
char *found = NULL;
|
||||
GDir *d = g_dir_open(dir, 0, NULL);
|
||||
if (!d)
|
||||
return NULL;
|
||||
const char *e;
|
||||
while (!found && (e = g_dir_read_name(d))) {
|
||||
/* (its interfaces: "1-2:2.0") */
|
||||
if (!strchr(e, ':'))
|
||||
continue;
|
||||
char *itf = g_build_filename(dir, e, NULL);
|
||||
GDir *i = g_dir_open(itf, 0, NULL);
|
||||
const char *t;
|
||||
while (i && !found && (t = g_dir_read_name(i)))
|
||||
if (g_str_has_prefix(t, "ttyUSB"))
|
||||
found = g_strconcat("/dev/", t, NULL);
|
||||
if (i)
|
||||
g_dir_close(i);
|
||||
g_free(itf);
|
||||
}
|
||||
g_dir_close(d);
|
||||
return found;
|
||||
}
|
||||
|
||||
gboolean usbmodem_firmware_present(void)
|
||||
{
|
||||
for (int i = 0; firmware[i]; i++)
|
||||
if (g_file_test(firmware[i], G_FILE_TEST_EXISTS))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UsbModem *usbmodem_find(void)
|
||||
{
|
||||
const char *root = "/sys/bus/usb/devices";
|
||||
GDir *d = g_dir_open(root, 0, NULL);
|
||||
if (!d)
|
||||
return NULL;
|
||||
UsbModem *m = NULL;
|
||||
const char *e;
|
||||
while (!m && (e = g_dir_read_name(d))) {
|
||||
char *dir = g_build_filename(root, e, NULL);
|
||||
char *vid = attr(dir, "idVendor");
|
||||
char *pid = vid ? attr(dir, "idProduct") : NULL;
|
||||
for (size_t k = 0; pid && !m &&
|
||||
k < sizeof(models) / sizeof(models[0]); k++) {
|
||||
if (g_ascii_strcasecmp(vid, "06e0") ||
|
||||
g_ascii_strcasecmp(pid, models[k].product))
|
||||
continue;
|
||||
m = g_new0(UsbModem, 1);
|
||||
m->name = g_strdup(models[k].name);
|
||||
m->tty = tty_of(dir);
|
||||
char *nc = attr(dir, "bNumConfigurations");
|
||||
/* (one configuration: the boot ROM's) */
|
||||
m->no_firmware = !m->tty && nc && !strcmp(nc, "1");
|
||||
g_free(nc);
|
||||
}
|
||||
g_free(vid);
|
||||
g_free(pid);
|
||||
g_free(dir);
|
||||
}
|
||||
g_dir_close(d);
|
||||
return m;
|
||||
}
|
||||
|
||||
char *usbmodem_describe(const UsbModem *m)
|
||||
{
|
||||
if (m->tty)
|
||||
return g_strdup_printf("%s at %s", m->name, m->tty);
|
||||
if (m->no_firmware && !usbmodem_firmware_present())
|
||||
return g_strdup_printf("%s, with no firmware: put "
|
||||
"mts_mt9234mu.fw in /lib/firmware, "
|
||||
"then connect the modem again", m->name);
|
||||
if (m->no_firmware)
|
||||
return g_strdup_printf("%s, with no firmware: load the "
|
||||
"ti_usb_3410_5052 driver, then connect "
|
||||
"the modem again", m->name);
|
||||
return g_strdup_printf("%s, with no serial port: load the "
|
||||
"ti_usb_3410_5052 driver", m->name);
|
||||
}
|
||||
|
||||
gboolean usbmodem_is(const char *path)
|
||||
{
|
||||
UsbModem *m = usbmodem_find();
|
||||
gboolean is = m && m->tty && path && !strcmp(m->tty, path);
|
||||
usbmodem_free(m);
|
||||
return is;
|
||||
}
|
||||
|
||||
void usbmodem_free(UsbModem *m)
|
||||
{
|
||||
if (!m)
|
||||
return;
|
||||
g_free(m->name);
|
||||
g_free(m->tty);
|
||||
g_free(m);
|
||||
}
|
||||
Reference in new issue
Block a user