Mobile USB 3G internet

Hello. How to set up an Internet connection through an USB cable using a 3G phone or modem? It is easy to set up on Linux with NetworkManager. I think the connection uses PPP. But if that's the case, then how to configure it correctly on FreeBSD, without for example making costly mistakes like getting huge phone bills? I think the Handbook's PPP section only concerns old-fashioned dial-up modem connections.
I think the Handbook's PPP section only concerns old-fashioned dial-up modem connections.
Some 3G/4G phones operate as a traditional "modem" and you need to "dial" a specific number (usually *99#) to enable the internet connection. It basically works just like an old fashioned dialup.
I use Sierra modems and the MC7355 is supported well. It is an miniPCIe module. There is a newer MC7455 not yet supported. Older MC7700 is supported too. All of these are LTE capable modules.

For connection you would use either PPP or i use /net/mpd5 which is harder to get your modem script right but it handles reconnections well.

Some people are using Mifi hotspots with a UBS tethering cable. In this case you only need to setup ue0 connection with dhcp.

The pfSense forum has alot of feedback on working devices.

This guys blog is still relevant. Nothing has changed.

Here are my mpd config files.

Huawei has some supported models too.
here my basic notes about Android phone USB tethering in FreeBSD 10.3-RELEASE

Check the u3g driver and load it
- check u3g driver: kldstat
- if it's not there do kldload u3g (add to /boot/loader.conf: u3g_load="YES")

If I remember correctly FreeBSD 11 recognize the phone without need to manually load the u3g driver.

Connect the phone with the USB cable
set Data Enabled ON
set USB Tethering ON

ifconfig to locate the new network interface,
in my system is ue0

Like root: dhclient ue0

- To connect at boot time in /etc/rc.conf add: dhclient ue0

- Avoid DHCP (dhclient) to change DNS entry in /etc/resolv.conf
Create /etc/dhclient-enter-hooks with this code: add_new_resolv_conf() { return 0 }

- Noted some differences in web pages, optimized for mobiles,
and in the ISP firewall (transparent proxy) setup:
in case of FreeBSD update problems use the ISP proxy server.
Connect with 3G UBS modem Huawei E160 and E173 in FreeBSD 10.3-RELEASE.
ISP: - Kenya

- check if u3g driver is loaded: kldstat
- if is not there do kldload u3g (add to /boot/loader.conf: u3g_load="YES")
If I remember correctly FreeBSD 11 recognize the modem without need to manually load u3g driver.

- create a /etc/ppp/ppp.conf file with this code:

 set device /dev/cuaU0.0
 set timeout 0
        \"\" \
        AT OK-AT-OK \
        AT+CPIN="" OK-AT-OK \
        ATH OK-AT-OK \
        ATE1 OK-AT-OK \
        AT+CGDCONT=1,\\\"IP\\\",\\\"\\\" OK \
        \\dATD*99# TIMEOUT 40 CONNECT"
 set authname "SAF"
 set authkey "WEB"
 set ifaddr
 add default HISADDR

That's all: Huawei 3G modems use HiLink, a system by Huawei. There is no need to be initialized by usb_modeswitch.
Ref.: #15328 (NCM Protocol support) - OpenWrt

Connect and disconnect
like root do
- to connect: /usr/sbin/ppp -ddial saf
- to disconnect: killall -9 ppp

Check new network interfaces with: ifconfig
when ifconfig show the inet you are connected: inet '' --> netmask 0xffffffff

To start modem at boot (without root password) add in /etc/rc.conf
ppp_enable="YES" ppp_mode="ddial" ppp_profile="saf"

About ppp.conf
/dev/cuaU0.0 device number can be different, list: ls -l /dev/cuaU* setup
AT+CPIN="" is the card PIN or live blank if PIN authentication is disabled (can be different)
dial number: *99#
AT+CPIN="" is the card PIN or live blank if PIN authentication is disabled
dial number: *99#
Live blank APN_USER=
(set authname "")
Live blank APN_PASS=
(set authkey "")

- Do not use options: more options more difficult to connect
- ppp warning are not so important (Warning: Add! route failed: ff02::: ...)
- Create and read the ppp log file: /var/log/ppp.log

About the hardware
- Huawei 3G USB modems have different chip and setup (set device /dev/cuaU0.1).
- Some USB ports don't have enough power for the modem.
- Sometime the connection can fail only because the modem is not in a good position.
- Different Operative Systems manage the same hardware in different ways.

FreeBSD Docs: Handbook Chapter 26. PPP
FAQ FreeBSD: Chapter 14. PPP
man ppp
I'm using an old "dumbphone". A Linux distro can successfully connect to the Internet with my phone, so I've tapped the USB communication with Wireshark and tried to figure out how to connect on FreeBSD. I think I managed to get the AT commands right so it will dial ok, but then it fails to setup the PPP LCP phase correctly. Well, I might check out those configurations KBob posted some time.
Hello again.

I've found out that the problem somehow appears to be in the USB connection, /dev/cuaU0. Looks like the connection somehow freezes easily. If I use the USB device directly using set device /dev/cuaU0, it freezes almost instantly. In the term terminal, after writing just one or a few characters, it stops echoing my input. If I use dial, the chat script fails quite early because of a timeout.

If I use socat and a local TCP port instead, it usually freezes at the ATD command if using dial, and somewhere in the IPCP phase if connecting manually using term. The socat command is socat -v tcp-listen:[I]port[/I],fork open:/dev/cuaU0,rawer.

Finally, I tried to attach the phone to a Linux computer and access that using TCP. Now I finally managed to make it work!

My conclusion is that FreeBSD appears to have some kind of a problem in talking to the phone. Is it a bug, or maybe some weird 'feature' that can be tuned or configured to work correctly?
Now I finally succeeded in making it work on my FreeBSD computer without the help of Linux. It appears that the success or failure depends on the stty parameters of the serial device, /dev/cuaU0.

Normally if ppp tries to talk with my phone directly with the option set device /dev/cuaU0, the connection stops working quite immediately when the first data is written to the serial device. For example, if I open the term terminal in ppp and start to write commands such as at, only the first character echoes back to the terminal and I get no further data out of the device, even if I press enter and write more commands. It just gets stuck.

If I use the socat method with open:/dev/cuaU0,rawer and TCP tunneling in ppp, the initialization goes further until at around the atd*99# position, it gets stuck.

Then I tried cu on the /dev/cuaU0 device. For example, using cu -l /dev/cuaU0 to test writing commands manually, or using socat tunneling with system:'cu -l /dev/cuaU0' instead of using the open parameter. Now the initialization completes and I can see packets being sent out, but no packets are received. I know cu considers ~ as an escape character and doesn't support disabling it, which is undesirable for this application.

I compared the outputs of stty -a -f /dev/cuaU0 when the device was open in either ppp, socat, or cu, and also the output of stty -a -F /dev/ttyACM0 on Linux.

And I finally came up with a somewhat hacky solution which works:
1. Plug in the phone
2. Start ppp and write the following commands:
set device /dev/cuaU0
enable dns
set ifaddr 0 0
add default HISADDR
3. Now run stty -f /dev/cuaU0 raw.
4. Back in the ppp terminal, write your AT commands. For example:
5. Done!