Mobile broadband helper script for FreeBSD

Packages sudo, xterm, yad, and ppp packages are required.

Install first usb_modeswitch and usbutils packages

Code:
pkg install usb_modeswitch usbutils

The script with Finnish provider DNA and Huawei E220 dongle.

Code:
#!/bin/sh
#
# RJP 3.8.2025 ppp-gui for mobile broadband .. and maybe more too
# packages sudo, xterm, yad, and ppp packages are required
# 
# 
touch ~/.Xresources
echo ' ! Use a truetype font and size.
xterm*faceName: Monospace ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources
echo 'xterm*faceSize: 14 ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources
xrdb -merge ~/.Xresources


echo '
attach 100 {
        device-name "u3g[0-9]+";
        match "vendor" "0x12d1";
        match "product" "0x1003"; 
        action "/usr/sbin/ppp -ddial DNA";
};
' > /tmp/huawei-e220.conf

echo '
default:
 allow users *
 #set log Phase Chat Connect hdlc LCP IPCP IPV6CP CCP tun
 set log Phase Chat Connect 
DNA: 
 set device /dev/cuaU0.0 
 set timeout 0 
 set authname " "
 set authkey " "
 set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
        \"\" \
        AT OK-AT-OK \
        AT+CFUN=1 OK-AT-OK \
        AT+CMEE=2 OK-AT-OK \
        AT+CSQ OK \
        AT+CGDCONT=1,\\\"IP\\\",\\\"internet\\\" OK \
        AT+CGACT? OK-AT-OK \
        AT+CGATT? OK \
        AT+CGCLASS? OK \
        AT+COPS? OK \
        \\dATD*99# TIMEOUT 40 CONNECT"
 set crtscts on 
 disable vjcomp 
 disable acfcomp 
 disable deflate 
 disable deflate24 
 disable pred1 
 disable protocomp 
 disable mppe 
 disable ipv6cp 
 disable lqr 
 disable echo 
 nat enable yes 
 enable dns 
 resolv writable 
 set dns 8.8.8.8 ## google dns
 set ifaddr 10.1.0.2/0 10.1.0.1/0 255.255.255.255 0.0.0.0
 #add default HISADDR
 #  https://forums.freebsd.org/threads/pc-bsd-huawei-e1752-mobile-broadband-configure.24800/
' > /tmp/ppp.conf

echo '
 # /etc/ppp/ppp.linkup

 # These commands executed with uid of ppp invoker!
DNA:
 shell route delete default
 shell route add default -interface INTERFACE
' > /tmp/ppp.linkup

echo '
 # /etc/ppp/ppp.linkdown
 # These commands executed with uid of ppp invoker!
default:
 shell logger "LABEL down (up UPTIME): OCTETSIN received, OCTETSOUT sent"
DNA:
 shell route delete default
 shell route add default billion
' > /tmp/ppp.linkdown



echo '
Install first usb_modeswitch and usbutils packages

pkg install usb_modeswitch usbutils

Check u3g driver status

kldstat 

If not loaded, load u3g

kldload u3g

###################################################
### BASIC SETTINGS for Huawei E220 DNA FINLAND ####
###################################################
 #================================#
 ## /etc/devd/huawei-e220.conf

attach 100 {
        device-name "u3g[0-9]+";
        match "vendor" "0x12d1";
        match "product" "0x1003"; 
        action "/usr/sbin/ppp -ddial DNA";
};

 #================================#

 ## /etc/ppp/ppp.conf


default:
 allow users *
 #set log Phase Chat Connect hdlc LCP IPCP IPV6CP CCP tun
 set log Phase Chat Connect 
DNA: 
 set device /dev/cuaU0.0 
 set timeout 0 
 set authname " " # use your provider authname here
 set authkey " "  # use your provider autkey here
 set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
        \"\" \
        AT OK-AT-OK \
        AT+CFUN=1 OK-AT-OK \
        AT+CMEE=2 OK-AT-OK \
        AT+CSQ OK \
        AT+CGDCONT=1,\\\"IP\\\",\\\"internet\\\" OK \ # use your provider APN in stead of internet
        AT+CGACT? OK-AT-OK \
        AT+CGATT? OK \
        AT+CGCLASS? OK \
        AT+COPS? OK \
        \\dATD*99# TIMEOUT 40 CONNECT"
 set crtscts on 
 disable vjcomp 
 disable acfcomp 
 disable deflate 
 disable deflate24 
 disable pred1 
 disable protocomp 
 disable mppe 
 disable ipv6cp 
 disable lqr 
 disable echo 
 nat enable yes 
 enable dns 
 resolv writable 
 set dns 8.8.8.8 ## google dns
 set ifaddr 10.1.0.2/0 10.1.0.1/0 255.255.255.255 0.0.0.0
 #add default HISADDR
 #  https://forums.freebsd.org/threads/pc-bsd-huawei-e1752-mobile-broadband-configure.24800/

 #================================#
 # /etc/ppp/ppp.linkup

 # These commands executed with uid of ppp invoker!
DNA:
 shell route delete default
 shell route add default -interface INTERFACE

 #================================#

 # /etc/ppp/ppp.linkdown
 # These commands executed with uid of ppp invoker!
default:
 shell logger "LABEL down (up UPTIME): OCTETSIN received, OCTETSOUT sent"
DNA:
 shell route delete default
 shell route add default billion

 #================================#


' > /tmp/readme-ppp.txt


yad --form --columns=5 --rows=4 --center --width=1200 --title="PPP GUI" --text="PPP GUI" \
\
--field="README FIRST":fbtn "sh -c 'xdg-open /tmp/readme-ppp.txt ; exec sh' & " \
--field="Make Huawei e220 conf settings":fbtn "xterm -e sh -c 'sudo cp /tmp/huawei-e220.conf /etc/devd/huawei-e220.conf ; exec sh' & " \
--field="Make basic ppp.conf settings":fbtn "xterm -e sh -c 'sudo cp /etc/ppp/ppp.conf /etc/ppp/ppp.conf.bak && sudo cp /tmp/ppp.conf /etc/ppp/ppp.conf ; exec sh' & " \
--field="Look ppp.conf settings":fbtn "xterm -e sh -c 'sudo cat /etc/ppp/ppp.conf; exec sh' & " \
--field="Restore ppp.conf earlier settings":fbtn "xterm -e sh -c 'sudo cp /etc/ppp/ppp.conf.bak /etc/ppp/ppp.conf ; exec sh' & " \
--field="Edit ppp.conf file":fbtn "xterm -e sh -c 'sudo nano /etc/ppp/ppp.conf ; exec sh' & " \
--field="Make basic ppp.linkup settings":fbtn "xterm -e sh -c 'sudo cp /etc/ppp/ppp.linkup /etc/ppp/ppp.linkup.bak && sudo cp /tmp/ppp.linkup /etc/ppp/ppp.linkup ; exec sh' & " \
--field="Edit ppp.linkup file":fbtn "xterm -e sh -c 'sudo nano /etc/ppp/ppp.linkup ; exec sh' & " \
--field="Make basic ppp.down settings":fbtn "xterm -e sh -c 'sudo cp /etc/ppp/ppp.linkdown /etc/ppp/ppp.linkdown.bak && sudo cp /tmp/ppp.linkdown /etc/ppp/ppp.linkdown ; exec sh' & " \
--field="Edit ppp.linkdown file":fbtn "xterm -e sh -c 'sudo nano /etc/ppp/ppp.linkdown ; exec sh' & " \
--field="See Mobile dmesg":fbtn "xterm  -e sh -c 'sudo dmesg | grep Mobile ; exec sh' & " \
--field="See ugen1.2 dump_device_desc":fbtn "xterm  -e sh -c 'sudo usbconfig -d ugen1.2 dump_device_desc ; exec sh' & " \
--field="Load mobile broadband driver":fbtn "xterm  -e sh -c 'sudo kldload u3g ; exec sh' & " \
--field="Connect mobile network":fbtn "xterm -e sh -c 'sudo ppp -ddial DNA ; exec sh' & " \
--field="Disconnect mobile network":fbtn "xterm -e sh -c 'sudo killall ppp ; exec sh' & " \
--field="Test connection":fbtn "sh -c 'xterm -hold -e ping -c 3 google.com ; exec sh' & " \
--button=Exit:1

cd /tmp && rm huawei-e220.conf ppp.conf ppp.linkup ppp.linkdown readme-ppp.txt

 
Back
Top