kernel-device: add get_interface_number() method

We already have methods to query for interface specific attributes
like class/subclass/protocol, so add a new one for the interface
number, and make sure we use ATTRS{bInterfaceNumber} to load it
always, instead of assuming the ID_USB_INTERFACE_NUM property is set.
This commit is contained in:
Aleksander Morgado
2021-02-07 11:53:13 +01:00
parent cc07d21410
commit 1b35d74c15
8 changed files with 42 additions and 19 deletions

View File

@@ -63,7 +63,7 @@ get_usb_interface_config_index (MMPort *data,
guint usb_iface_num;
guint i;
usb_iface_num = mm_kernel_device_get_property_as_int_hex (mm_port_peek_kernel_device (data), "ID_USB_INTERFACE_NUM");
usb_iface_num = (guint) mm_kernel_device_get_interface_number (mm_port_peek_kernel_device (data));
for (i = 0; i < G_N_ELEMENTS (usb_interface_configs); i++) {
if (usb_interface_configs[i].usb_iface_num == usb_iface_num)

View File

@@ -56,7 +56,7 @@ MM_PLUGIN_DEFINE_MINOR_VERSION
typedef struct {
MMPortProbe *probe;
guint first_usbif;
gint first_usbif;
guint timeout_id;
gboolean custom_init_run;
} FirstInterfaceContext;
@@ -178,22 +178,22 @@ try_next_usbif (MMPortProbe *probe,
{
FirstInterfaceContext *fi_ctx;
GList *l;
guint closest;
gint closest;
fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT);
g_assert (fi_ctx != NULL);
/* Look for the next closest one among the list of interfaces in the device,
* and enable that one as being first */
closest = G_MAXUINT;
closest = G_MAXINT;
for (l = mm_device_peek_port_probe_list (device); l; l = g_list_next (l)) {
MMPortProbe *iter = MM_PORT_PROBE (l->data);
/* Only expect ttys for next probing attempt */
if (g_str_equal (mm_port_probe_get_port_subsys (iter), "tty")) {
guint usbif;
gint usbif;
usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (iter), "ID_USB_INTERFACE_NUM");
usbif = mm_kernel_device_get_interface_number (mm_port_probe_peek_port (iter));
if (usbif == fi_ctx->first_usbif) {
/* This is the one we just probed, which wasn't yet removed, so just skip it */
} else if (usbif > fi_ctx->first_usbif &&
@@ -203,7 +203,7 @@ try_next_usbif (MMPortProbe *probe,
}
}
if (closest == G_MAXUINT) {
if (closest == G_MAXINT) {
/* No more ttys to try! Just return something */
closest = 0;
mm_obj_dbg (probe, "no more ports to run initial probing");
@@ -359,9 +359,7 @@ huawei_custom_init (MMPortProbe *probe,
g_task_set_task_data (task, ctx, (GDestroyNotify)huawei_custom_init_context_free);
/* Custom init only to be run in the first interface */
if (mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe),
"ID_USB_INTERFACE_NUM") != fi_ctx->first_usbif) {
if (mm_kernel_device_get_interface_number (mm_port_probe_peek_port (probe)) != fi_ctx->first_usbif) {
if (fi_ctx->custom_init_run)
/* If custom init was run already, we can consider this as successfully run */
g_task_return_boolean (task, TRUE);
@@ -391,8 +389,8 @@ static gint
probe_cmp_by_usbif (MMPortProbe *a,
MMPortProbe *b)
{
return ((gint) mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (a), "ID_USB_INTERFACE_NUM") -
(gint) mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (b), "ID_USB_INTERFACE_NUM"));
return (mm_kernel_device_get_interface_number (mm_port_probe_peek_port (a)) -
mm_kernel_device_get_interface_number (mm_port_probe_peek_port (b)));
}
static guint

View File

@@ -56,7 +56,7 @@ grab_port (MMPlugin *self,
{
MMPortSerialAtFlag pflags = MM_PORT_SERIAL_AT_FLAG_NONE;
MMKernelDevice *port;
guint usbif;
gint usbif;
/* The Option plugin cannot do anything with non-AT ports */
if (!mm_port_probe_is_at (probe)) {
@@ -73,7 +73,7 @@ grab_port (MMPlugin *self,
* the modem/data port, per mail with Option engineers. Only this port
* will emit responses to dialing commands.
*/
usbif = mm_kernel_device_get_property_as_int_hex (port, "ID_USB_INTERFACE_NUM");
usbif = mm_kernel_device_get_interface_number (port);
if (usbif == 0)
pflags = MM_PORT_SERIAL_AT_FLAG_PRIMARY | MM_PORT_SERIAL_AT_FLAG_PPP;

View File

@@ -59,7 +59,7 @@ telit_grab_port (MMPlugin *self,
if (g_object_get_data (G_OBJECT (device), TAG_GETPORTCFG_SUPPORTED) != NULL) {
guint usbif;
usbif = mm_kernel_device_get_property_as_int_hex (port, "ID_USB_INTERFACE_NUM");
usbif = (guint) mm_kernel_device_get_interface_number (port);
if (usbif == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_TELIT_MODEM_PORT))) {
mm_obj_dbg (self, "AT port '%s/%s' flagged as primary",
mm_port_probe_get_port_subsys (probe),
@@ -257,9 +257,7 @@ telit_custom_init_step (GTask *task)
* is always linked to an AT port
*/
port = mm_port_probe_peek_port (probe);
if (!ctx->getportcfg_done &&
g_strcmp0 (mm_kernel_device_get_property (port, "ID_USB_INTERFACE_NUM"), "00") == 0) {
if (!ctx->getportcfg_done && mm_kernel_device_get_interface_number (port) == 0) {
if (ctx->getportcfg_retries == 0)
goto out;
ctx->getportcfg_retries--;

View File

@@ -550,6 +550,12 @@ kernel_device_get_sysfs_path (MMKernelDevice *self)
return MM_KERNEL_DEVICE_GENERIC (self)->priv->sysfs_path;
}
static gint
kernel_device_get_interface_number (MMKernelDevice *self)
{
return (gint) MM_KERNEL_DEVICE_GENERIC (self)->priv->interface_number;
}
static gint
kernel_device_get_interface_class (MMKernelDevice *self)
{
@@ -1172,6 +1178,7 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass)
kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem;
kernel_device_class->get_physdev_manufacturer = kernel_device_get_physdev_manufacturer;
kernel_device_class->get_physdev_product = kernel_device_get_physdev_product;
kernel_device_class->get_interface_number = kernel_device_get_interface_number;
kernel_device_class->get_interface_class = kernel_device_get_interface_class;
kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass;
kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol;

View File

@@ -402,6 +402,15 @@ kernel_device_get_physdev_product (MMKernelDevice *_self)
return (self->priv->physdev ? g_udev_device_get_sysfs_attr (self->priv->physdev, "product") : NULL);
}
static gint
kernel_device_get_interface_number (MMKernelDevice *_self)
{
MMKernelDeviceUdev *self;
self = MM_KERNEL_DEVICE_UDEV (_self);
return (self->priv->interface ? (gint) udev_device_get_sysfs_attr_as_hex (self->priv->interface, "bInterfaceNumber") : -1);
}
static gint
kernel_device_get_interface_class (MMKernelDevice *_self)
{
@@ -743,6 +752,7 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem;
kernel_device_class->get_physdev_manufacturer = kernel_device_get_physdev_manufacturer;
kernel_device_class->get_physdev_product = kernel_device_get_physdev_product;
kernel_device_class->get_interface_number = kernel_device_get_interface_number;
kernel_device_class->get_interface_class = kernel_device_get_interface_class;
kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass;
kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol;

View File

@@ -125,6 +125,14 @@ mm_kernel_device_get_physdev_product (MMKernelDevice *self)
NULL);
}
gint
mm_kernel_device_get_interface_number (MMKernelDevice *self)
{
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_interface_number ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_interface_number (self) :
-1);
}
gint
mm_kernel_device_get_interface_class (MMKernelDevice *self)
{

View File

@@ -41,6 +41,7 @@ struct _MMKernelDeviceClass {
const gchar * (* get_driver) (MMKernelDevice *self);
const gchar * (* get_sysfs_path) (MMKernelDevice *self);
gint (* get_interface_number) (MMKernelDevice *self);
gint (* get_interface_class) (MMKernelDevice *self);
gint (* get_interface_subclass) (MMKernelDevice *self);
gint (* get_interface_protocol) (MMKernelDevice *self);
@@ -74,6 +75,7 @@ const gchar *mm_kernel_device_get_name (MMKernelDevice *self);
const gchar *mm_kernel_device_get_driver (MMKernelDevice *self);
const gchar *mm_kernel_device_get_sysfs_path (MMKernelDevice *self);
gint mm_kernel_device_get_interface_number (MMKernelDevice *self);
gint mm_kernel_device_get_interface_class (MMKernelDevice *self);
gint mm_kernel_device_get_interface_subclass (MMKernelDevice *self);
gint mm_kernel_device_get_interface_protocol (MMKernelDevice *self);