MC7455: Use GPS at same time as ModemManager

I have been using this udev rule for a while, allowing gpsd to control the GPS while MM is handling the rest:

# Sierra GPS interfaces - use gpsd instead of MM
#  note on udev matching: it seems all ATTRS matches must be found at the same
#  level, so we must use ENV{ID_VENDOR_ID} to be able to match against bInterfaceNumber
SUBSYSTEM=="tty",ACTION=="add",ENV{ID_VENDOR_ID}=="1199",ATTRS{bInterfaceNumber}=="02",SYMLINK="gps%n",ENV{ID_MM_PORT_IGNORE}="1",RUN+="/usr/sbin/gpsdctl add $devnode"
SUBSYSTEM=="tty",ACTION=="remove",ENV{ID_VENDOR_ID}=="1199",ATTRS{bInterfaceNumber}=="02",RUN+="/usr/sbin/gpsdctl remove $devnode"

These rules abuse the fact that Sierra Wireless use static USB interface numbers, so you know that USB interface #2 is GPS regardless of the ttyUSBx device number. So it works even if you have more than one Sierra modem connected, or other ttyUSBx devices.

For completeness: I also have a gpsd device hook to support automatic start/stop of the NMEA with the default modem settings. The VID/PID extraction is a bit hackish and can most likely be done better, but this Works For Me™:

bjorn@miraculix:~$ cat /etc/gpsd/device-hook 
#!/bin/sh
# $Id: device-hook,v 1.3 2017/12/23 12:42:49 bjorn Exp $
#
# gpsd will not poll a device before it is opened, at which time this script is called
# This means that we can unconditionally add the GPS without wasting any power,  It
# will be activated when the first client connects to gpsd, and this script is called
#
# gpsd will also deactivate the port after some inactivity period

# figure out the parent usb device
USBDEV=`ls -l "$1" |sed -ne 's!^c......... [0-9]* [^ ]* [^ ]* \([0-9]*\), \([0-9]*\) .*!/sys/dev/char/\1:\2/device/../..!p'`

# silently ignore any non-USB ports
if [ ! -r "$USBDEV/idVendor" ] || [ ! -r "$USBDEV/idProduct" ]; then
  exit 0
fi 

VID=`cat "$USBDEV/idVendor"`
PID=`cat "$USBDEV/idProduct"`

case "$2" in
  ACTIVATE)
    CMD=START
    ;;
  *)
    CMD=STOP
    ;;
esac

case "$VID:$PID" in
  "1199:9071" |\
  "1199:9079" |\
  "1199:9091" )
    echo \$GPS_$CMD >"$1"
    ;;
  *)
    ;;
esac

exit 0

Note that you obviously will have to modify the list of supported VID:PIDs if you use something else than MC7455/Lenovo EM7455/EM7565

1 Like