Skip to content

Instantly share code, notes, and snippets.

@ndunks
Last active March 2, 2021 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndunks/d15f725f87b96eb2ac5f30ea91db3824 to your computer and use it in GitHub Desktop.
Save ndunks/d15f725f87b96eb2ac5f30ea91db3824 to your computer and use it in GitHub Desktop.
Gammu SMS Daemon usb_modeswitch helper with Cyborg Mobile Broadband E488 4G LTE USB Stick (Telkomsel Flash)
#!/sbin/openrc-run
# Gammu SMS Daemon usb_modeswitch helper with Cyborg Mobile Broadband E488 4G LTE USB Stick (Telkomsel Flash)
retry="60"
pidfile="/var/run/$RC_SVCNAME.pid"
command="/usr/bin/gammu-smsd"
command_args="-d -p /var/run/$RC_SVCNAME.pid -c /etc/gammurc"
#command_background=true
#procname="gammu-smsd"
depend() {
need root localmount
}
# Init modem with usb_modeswitch
start_pre() {
local USB
local USB_SERIAL
local USB_TTY
ebegin "Starting $RC_SVCNAME (Device $VENDOR_ID).."
for f in /sys/bus/usb/devices/*/idVendor; do
if grep -q "^$VENDOR_ID" "$f"; then
USB=${f%/idVendor}
break
fi
done
if [ -z "$USB" ]; then
eend 1 "Device not found"
return 1
fi
case `cat $USB/idProduct` in
$PRODUCT_ID_INIT)
if [ "$1" = "self" ]; then
eend 1 "Failed to Initialize device."
return 1
fi
echo -n "Initialize the device.. " >&2
usb_modeswitch -v $VENDOR_ID -p $PRODUCT_ID_INIT -K > /dev/null
echo "OK" >&2
sleep 2
start_pre self
;;
$PRODUCT_ID_READY)
if [ ! -d /sys/module/usbserial ]; then modprobe usbserial; fi
echo $VENDOR_ID $PRODUCT_ID_READY > /sys/module/usbserial/drivers/usb-serial\:generic/new_id
sleep 0.5
for f in $USB/*\:*/uevent; do
USB_SERIAL=${f%/uevent}
if grep -q '^DRIVER=usbserial' $f &&
[ `cat $USB_SERIAL/bInterfaceNumber` = "$INTERFACE_NUMBER" ] &&
[ -d $USB_SERIAL/ttyUSB* ]
then
USB_TTY=`find "$USB_SERIAL" -maxdepth 1 -name 'ttyUSB*'`
USB_TTY="/dev/${USB_TTY##*/}"
break
#cat $f
fi
done
if [ -z $USB_TTY ] || [ ! -e $USB_TTY ]; then
eend 1 "Device not exist $USB_TTY"
return 1;
fi
;;
*)
eend 1 "Device not found"
return 1
esac
ln -sf $USB_TTY /dev/modem-cyborg
eend 0 "Ready"
}
VENDOR_ID=05c6
PRODUCT_ID_INIT=92fe
PRODUCT_ID_READY=9201
INTERFACE_NUMBER=01 # ttyUSB1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment