From 5dfd75d8f8fbb8c5b98e2785639ad1c8a884e8ff Mon Sep 17 00:00:00 2001 From: j3tm0t0 Date: Wed, 15 Jun 2016 00:47:03 +0900 Subject: [PATCH] change to use udev for FS01BU --- scripts/connect_air.sh | 100 ++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/scripts/connect_air.sh b/scripts/connect_air.sh index f054ddb..829082b 100644 --- a/scripts/connect_air.sh +++ b/scripts/connect_air.sh @@ -1,44 +1,32 @@ #!/bin/bash init_fs01bu() { - usb_modeswitch -t < /sys/bus/usb-serial/drivers/option1/new_id + if (lsusb | grep 1c9e:6801 > /dev/null && [ -e /dev/ttyUSB2 ]) + then + return 0 + else + echo ERROR: modem is not configured or initialized properly. + echo Please re-attach modem or reboot. + return 1 + fi } - init_ak020() { if (lsusb | grep 15eb:7d0e > /dev/null && [ -e /dev/ttyUSB0 ]) then - echo AT+CFUN=1 > /dev/ttyUSB0 - sleep 1 + echo AT+CFUN=1 > /dev/ttyUSB0 # This mddem needs to be initialzed with this comamnd. + sleep 2 return 0 + else + echo ERROR: modem is not configured or initialized properly. + echo Please re-attach modem or reboot. + return 1 fi - echo -n "Configuring modem ... " - cat << EOF > /etc/udev/rules.d/40-ak-020.rules -ACTION=="add", ATTRS{idVendor}=="15eb", ATTRS{idProduct}=="a403", RUN+="/usr/sbin/usb_modeswitch --std-eject --default-vendor 0x15eb --default-product 0xa403 --target-product 0x15eb --target-product 0x7d0e" -ACTION=="add", ATTRS{idVendor}=="15eb", ATTRS{idProduct}=="7d0e", RUN+="/sbin/modprobe usbserial vendor=0x15eb product=0x7d0e" -EOF - udevadm control --reload - echo done. - echo Please re-attach modem or reboot. - exit 1 } dialup() { - cat > /etc/wvdial.conf << EOF + cat > /etc/wvdial.conf << EOF [Dialer Defaults] Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 @@ -60,34 +48,64 @@ Carrier Check = no Auto DNS = 1 Check Def Route = 1 EOF - grep replacedefaultroute /etc/ppp/peers/wvdial &> /dev/null || echo replacedefaultroute >> /etc/ppp/peers/wvdial - echo waiting for modem device - for i in {1..30} - do - [ -e $1 ] && break - echo -n . - sleep 1 - done - [ $i = 30 ] && ( echo modem not found ; exit 1 ) - while [ 1 ] ; do wvdial ; sleep 60 ; done + grep replacedefaultroute /etc/ppp/peers/wvdial &> /dev/null || echo replacedefaultroute >> /etc/ppp/peers/wvdial + echo waiting for modem device + for i in {1..30} + do + [ -e $1 ] && break + echo -n . + sleep 1 + done + [ $i = 30 ] && ( echo modem not found ; exit 1 ) + while [ 1 ] ; do wvdial ; sleep 60 ; done } +# check UID if [ $UID != 0 ] then echo please execute as root or use sudo command. exit 1 fi +# check required package wvdial +if type wvdial &> /dev/null +then + : +else + echo ERROR: wvdial is missing. + echo Please install it with \"apt-get install -y wvdial\" command. + exit 1 +fi + +# check udev rule file +if [ ! -f /etc/udev/rules.d/40-usb-modems.rules ] +then + echo -n "Adding udev modem configuration ... " + cat << EOF > /etc/udev/rules.d/40-usb-modems.rules +# Fujisoft FS01BU +ACTION=="add", ATTRS{idVendor}=="1c9e", ATTRS{idProduct}=="98ff", RUN+="/usr/sbin/usb_modeswitch --std-eject --default-vendor 0x1c9e --default-product 0x98ff --target-vendor 0x1c9e --target-product 0x6801 -M 55534243123456780000000080000606f50402527000000000000000000000" +ACTION=="add", ATTRS{idVendor}=="1c9e", ATTRS{idProduct}=="6801", RUN+="/sbin/modprobe usbserial vendor=0x1c9e product=0x6801" +ACTION=="add", ATTRS{idVendor}=="1c9e", ATTRS{idProduct}=="6801", RUN+="echo 1c9e 6801 > /sys/bus/usb-serial/drivers/option1/new_id" + +# Abit AK-020 +ACTION=="add", ATTRS{idVendor}=="15eb", ATTRS{idProduct}=="a403", RUN+="/usr/sbin/usb_modeswitch --std-eject --default-vendor 0x15eb --default-product 0xa403 --target-product 0x15eb --target-product 0x7d0e" +ACTION=="add", ATTRS{idVendor}=="15eb", ATTRS{idProduct}=="7d0e", RUN+="/sbin/modprobe usbserial vendor=0x15eb product=0x7d0e" +EOF + udevadm control --reload + echo done. + echo Please re-attach modem or reboot. + exit 1 +fi + +# main if (lsusb | grep 1c9e: > /dev/null) then echo Found FS01BU - init_fs01bu 1c9e 98ff 1c9e 6801 && \ - dialup /dev/ttyUSB2 soracom.io sora sora + init_fs01bu && dialup /dev/ttyUSB2 soracom.io sora sora elif (lsusb | grep 15eb: > /dev/null) then echo Found AK-020 - init_ak020 && \ - dialup /dev/ttyUSB0 soracom.io sora sora + init_ak020 && dialup /dev/ttyUSB0 soracom.io sora sora else echo No supported modem found. Please wait for a while and re-execute script. exit 1