17

I am trying to prevent modem manager from running when I plug my cell phone into a USB port.

I have tried to add a custom rule with udev, but my custom rules seem ignored. I created a file /etc/udev/rules.d/99-mm-usb-device-blacklist.rules which contains

# LG Phone
ATTRS{idVendor}=="1004", ENV{ID_MM_DEVICE_IGNORE}="1"

And yet when I plug in the phone and check dmesg, this is what I get:

[ 1809.761940] usb 3-1: new high-speed USB device number 11 using xhci_hcd
[ 1809.778662] usb 3-1: New USB device found, idVendor=1004, idProduct=61fc
[ 1809.778670] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1809.778674] usb 3-1: Product: B Project USB Device
[ 1809.778677] usb 3-1: Manufacturer: LG Electronics. Inc
[ 1809.778680] usb 3-1: SerialNumber: XXXXXXXXXXXXXXXXX
[ 1809.779501] cdc_acm 3-1:1.0: This device cannot do calls on its own. It is not a modem.
[ 1809.779584] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[ 1809.780899] cdc_ether 3-1:1.3 usb0: register 'cdc_ether' at usb-0000:00:14.0-1, CDC Ethernet Device, 6e:34:73:4f:68:4c
[ 1809.781454] scsi8 : usb-storage 3-1:1.5
[ 1809.807331] IPv6: ADDRCONF(NETDEV_UP): usb0: link is not ready
[ 1809.816566] IPv6: ADDRCONF(NETDEV_UP): usb0: link is not ready
[ 1809.816759] IPv6: ADDRCONF(NETDEV_UP): usb0: link is not ready

I have also tried editing /lib/udev/rules.dev/77-mm-usb-device-blacklist.rules but this did not work either. What am I missing? What would be a helpful step in debugging this?

Update: Running udevadm info --export-db shows the udev rule is being updated. The relevant output is:

P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.7
N: bus/usb/002/012
E: BUSNUM=002
E: DEVNAME=/dev/bus/usb/002/012
E: DEVNUM=012
E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.7
E: DEVTYPE=usb_device
E: DRIVER=usb
E: ID_BUS=usb
E: ID_MM_DEVICE_IGNORE=1
E: ID_MODEL=B_Project_USB_Device
E: ID_MODEL_ENC=B\x20Project\x20USB\x20Device
E: ID_MODEL_ID=61fc
E: ID_REVISION=0216
E: ID_SERIAL=LG_Electronics._Inc_B_Project_USB_Device_XXXXXXXXXXXXX
E: ID_SERIAL_SHORT=XXXXXXXXXXXX
E: ID_USB_INTERFACES=:020201:0a0000:ffffff:020600:080650:
E: ID_VENDOR=LG_Electronics._Inc
E: ID_VENDOR_ENC=LG\x20Electronics.\x20Inc
E: ID_VENDOR_ID=1004
E: MAJOR=189
E: MINOR=139
E: PRODUCT=1004/61fc/216
E: SUBSYSTEM=usb
E: TYPE=239/2/1
E: UDEV_LOG=7
E: USEC_INITIALIZED=5987581808

So modem manager should be ignoring the device. And yet my computer keeps trying to initialize a network connect through my phone whenever I plug it to the USB port. Is there another program that udev is launching?

2
  • 1
    Did you run ModemManager --debug to check what it was doing with the device in question? I'm also slightly surprised to not see ID_MM_CANDIDATE=1 in that entry -- perhaps this is a separate codepath scanning devices in ModemManager which doesn't respect that attribute?
    – kiko
    Nov 17, 2018 at 19:24
  • @kiko, I have the same issue as the question author. ID_MM_CANDIDATE does not appear in the USB device output, but there is a separate entry in the database output for the TTY device, and this has both ID_MM_CANDIDATE=1 and ID_MM_DEVICE_IGNORE=1. Modem Manager debug logs show that it is indeed probing the device. Feb 19, 2019 at 9:23

4 Answers 4

7

While there may be a way to do this with udev, I found a much simpler working solution at this AskUbuntu question.

To summarize, you can tell Network Manager not to manage certain devices by adding a line to its .conf file.

First, find your cell phone's mac address. Run dmesg from the terminal after you plug it in; one of the print outs should have the mac. The line for me was:

[ 4691.112016] cdc_ether 3-1:1.3 usb0: register 'cdc_ether' at usb-0000:00:14.0-1, CDC Ethernet Device, de:1a:28:c7:db:e6

Next, open /etc/NetworkManager/NetworkManager.conf with super user privledges, and add a your phone's mac as an unmanaged device. This is my NetworkManager.conf; I added the last two lines.

[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false

[keyfile]
unmanaged-devices=mac:de:1a:28:c7:db:e6
7

Modem Manager can be configured to use different filter policies, and the udev tags such as ID_MM_DEVICE_IGNORE have no effect under the strict filter policy.

You can determine which policy Modem Manager is using on your system by viewing its status:

> sudo systemctl status ModemManager
● ModemManager.service - Modem Manager
   Loaded: loaded (/lib/systemd/system/ModemManager.service...
   Active: active (running) since ...
   ...
   CGroup: /system.slice/ModemManager.service
           └─644 /usr/sbin/ModemManager --filter-policy=strict

This also shows that the relevant service file is /lib/systemd/system/ModemManager.service. We can edit this file in different ways to disable probing of a particular device.

To use a different policy which will refer to the udev blacklist rules we can change the command in the service:

ExecStart=/usr/sbin/ModemManager --filter-policy=default

Options are default (just use the blacklist rules) or paranoid (like strict but also use the blacklist rules). The documentation mentions this is not recommended as support for blacklist rules may be obsoleted in the future.

Another option is to filter a class of devices using one of several TTY-specific environment variables. This can be achieved by appending a line to the [Service] section of the service file. For example, to prohibit probing of ACM TTY devices:

[Service]
...
Environment="MM_FILTER_RULE_TTY_ACM_INTERFACE=0"

After changing the service file, reload the systemctl configuration and restart ModemManager:

sudo systemctl daemon-reload
sudo systemctl restart ModemManager

For debugging purposes it may be useful to watch modem manager logs when connecting your device. To enable debug logging, run:

sudo mmcli -G DEBUG;

To watch the filter log messages, run:

journalctl -f | grep "ModemManager.*\[filter\]"

Now when you connect your device you should see lines like:

# Device allowed with strict filter policy
[filter] (tty/...): port allowed:... 

# Device filtered with default filter policy and udev tags
[filter] (tty/...): port filtered: device is blacklisted

# Device filtered with strict filter policy and environment variables
[filter] (tty/...) port filtered: forbidden

To return ModemManager logging to its prior state, run:

sudo mmcli -G ERR
2
1

This is solution help me for ModemManager 1.10.0 (Ubuntu 18.04)
ModemManager -V

You can learn more: Common udev tags

Create a file /etc/udev/rules.d/49-stm32.rules and add this:

# 0483:5740 - STM32 in USB Serial Mode (CN5)
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_TTY_BLACKLIST}="1"
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{MTP_NO_PROBE}="1"
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_PORT_IGNORE}="1"
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_TTY_MANUAL_SCAN_ONLY}="1"

After save file and run:
sudo udevadm control --reload-rules

and (maybe it's not necessary):
sudo systemctl restart ModemManager.service

After reconnecting the USB device (physically pull out and pull in it into the USB port) and enjoy.

0

(just for sake of science, since you have already solved your issue...)

udev reads/executes its rules in the alphabetical order[1].
This could mean that your settings should be overwritten be NetworkManager, that's your rule is useless.

If you rename your rule from 99- to 99999- does this change help you?


[1] https://unix.stackexchange.com/questions/204979/why-do-the-rules-in-udev-rules-d-have-numbers-in-front-of-them

1
  • I had this problem 5 years ago, and no longer have any of the hardware which I experienced the issue with. I seem to recall messing with the filenames, but can't recall the exact circumstances.
    – superdesk
    Feb 26, 2019 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .