Configuration of an LTE modem on the Raspberry Pi
-------------------------------------------------

[HUAWEI 4G Dongle E3372](https://consumer.huawei.com/za/routers/e3372/specs/) is an USB 2.0 device with a microSD card reader and a slot for a standard SIM Card

![Huawei-e3372-rpi-image](Huawei_e3372_rpi.jpg)

After plugging in the USB dongle check if Linux recognized it. E.g. `Huawei Technologies Co., Ltd. Modem/Networkcard`

`lsusb`
```
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 04d9:0007 Holtek Semiconductor, Inc. 
Bus 001 Device 005: ID 12d1:1506 Huawei Technologies Co., Ltd. Modem/Networkcard
Bus 001 Device 003: ID 2516:012f Cooler Master Co., Ltd. 
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
```
Check if the driver created the modem device. You should see the `/dev/cdc-wdm0`

`ls /dev/cdc*`
```
/dev/cdc-wdm0
```
Install `Network Manager`

`sudo apt install network-manager`
Check modems avalable to the network manager

`mmcli --list-modems`
```
    /org/freedesktop/ModemManager1/Modem/0 [huawei] E3372
```
Check status of the modem

`mmcli --modem=/org/freedesktop/ModemManager1/Modem/0`
```
  --------------------------------
  General  |            dbus path: /org/freedesktop/ModemManager1/Modem/0
           |            device id: 46c19d81068f7f5001140bf211de0b717b981698
  --------------------------------
  Hardware |         manufacturer: huawei
           |                model: E3372
           |             revision: 21.200.07.00.55
           |            supported: gsm-umts
           |              current: gsm-umts
           |         equipment id: 861821033381192
  --------------------------------
  System   |               device: /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.3
           |              drivers: option1, huawei_cdc_ncm
           |               plugin: Huawei
           |         primary port: ttyUSB1
           |                ports: ttyUSB0 (at), ttyUSB1 (at), cdc-wdm0 (at), wwan0 (net)
  --------------------------------
  Status   |       unlock retries: sim-pin (3), sim-pin2 (3), sim-puk (10), sim-puk2 (10)
           |                state: connected

           |          power state: on
           |          access tech: lte
           |       signal quality: 70% (recent)
  --------------------------------
  Modes    |            supported: allowed: 2g; preferred: none
           |                       allowed: 3g; preferred: none
           |                       allowed: 4g; preferred: none
           |                       allowed: 2g, 3g, 4g; preferred: none
           |              current: allowed: 2g, 3g, 4g; preferred: none
  --------------------------------
  IP       |            supported: ipv4
  --------------------------------
  3GPP     |                 imei: 861821033381192
           |          operator id: 23101
           |        operator name: Orange
           |         registration: home
  --------------------------------
  3GPP EPS | ue mode of operation: csps-2
  --------------------------------
  SIM      |            dbus path: /org/freedesktop/ModemManager1/SIM/0
  --------------------------------
  Bearer   |            dbus path: /org/freedesktop/ModemManager1/Bearer/0
```
Check the SIM card status

`mmcli --sim=/org/freedesktop/ModemManager1/SIM/0`
```
  ---------------------------
  General    |     dbus path: /org/freedesktop/ModemManager1/SIM/0
  ---------------------------
  Properties |          imsi: 231014462647671
             |         iccid: 8942101180024842166
             |   operator id: 23101
             | operator name: Orange
```
Create configuration for the modem. Set `con-name 'Orange-LTE'` to any name and `apn 'internet'` to the APN name of your mobile provider

`sudo nmcli connection add type gsm ifname '*' con-name 'Orange-LTE' apn 'internet' connection.autoconnect yes`

The configuration file is created with the con-name as filename and nmconnection as the suffix

`sudo cat /etc/NetworkManager/system-connections/Orange-LTE.nmconnection`
```
[connection]
id=Orange-LTE
uuid=8dc159fe-e0ed-4a56-9b7f-fb813e2c4753
type=gsm
permissions=

[gsm]
apn=internet
number=*99#

[ipv4]
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
```
Check status of the network device `wwan0`. It should have an IP address assigned by your mobile provider (e.g. 10.121.79.142)

`ip addr show wwan0`

```
4: wwan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 00:1e:10:1f:00:00 brd ff:ff:ff:ff:ff:ff
    inet 10.121.79.142/30 brd 10.121.79.143 scope global noprefixroute wwan0
       valid_lft forever preferred_lft forever
    inet 169.254.62.145/16 brd 169.254.255.255 scope global noprefixroute wwan0
       valid_lft forever preferred_lft forever
```
Check if the internet is reachable

`ping -I wwan0 www.google.com -c 5`
```
PING www.google.com (142.251.37.100) from 10.121.79.142 wwan0: 56(84) bytes of data.
64 bytes from prg03s13-in-f4.1e100.net (142.251.37.100): icmp_seq=1 ttl=117 time=23.5 ms
64 bytes from prg03s13-in-f4.1e100.net (142.251.37.100): icmp_seq=2 ttl=117 time=36.9 ms
64 bytes from prg03s13-in-f4.1e100.net (142.251.37.100): icmp_seq=3 ttl=117 time=32.7 ms
64 bytes from prg03s13-in-f4.1e100.net (142.251.37.100): icmp_seq=4 ttl=117 time=43.7 ms
64 bytes from prg03s13-in-f4.1e100.net (142.251.37.100): icmp_seq=5 ttl=117 time=29.7 ms

--- www.google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 11ms
rtt min/avg/max/mdev = 23.539/33.298/43.704/6.781 ms
```
