Modem

There are two different userspace services in postmarketOS that can manage the modem:
* oFono: Integrated in Phosh, Glacier and similar Mer-related projects like AsteroidOS or UBports-related projects like Lomiri
* ModemManager: Integrated in Phosh, Sxmo and Plasma Mobile (KDE switched from oFono to MM from about 21.10 release) 
Some modems might be only supported in oFono, while others are only supported in ModemManager. But usually either can be used (but not at the same time).
== oFono ==
oFono can be controlled using the Python oFono test scripts from the command line:
 $ sudo apk add ofono-scripts
 $ /usr/lib/ofono/test/enable-modem
 $ /usr/lib/ofono/test/online-modem
 $ /usr/lib/ofono/test/list-modems
Check if the SIM card shows up. If you have a dual SIM Qualcomm device (e.g. Wileyfox Swift), follow this guide.
Unlock the SIM card:
 $ /usr/lib/ofono/test/enter-pin pin <pin>
Eventually, your SIM card should show up as registering in /usr/lib/ofono/test/list-modems.
ofonoctl is also very useful test tool:
 $ sudo apk add ofonoctl
 $ ofonoctl list
=== SMS ===
Use the send-sms and receive-sms test scripts (from ofono-scripts package).
 $ /usr/lib/ofono/test/send-sms "COUNTRYCODENUMBER" "Test SMS from oFono" 0
 Send message using modem /gobi_0 ...
 /gobi_0/message_9914F33A7C53DD6F080B38755E7D64FD59EA8F8F
== ModemManager ==
ModemManager is integrated into the UI of Phosh and Plasma Mobile. Alternatively it can be controlled using mmcli from the command line:
 # List modems
 $ sudo mmcli -m 0
 # Enter pin
 $ sudo mmcli --sim 0 --pin <pin>
Signal strength information can be viewed by using the following commands:
 # Set the interval
 $ mmcli -m any --signal-setup=120
 # Get the information
 $ mmcli -m any --signal-get
=== SMS ===
How to test SMS functionality with ModemManager:
$ sudo mmcli -m 0 --messaging-create-sms="number='+xxxxxxxxxx',text='Hello from MM'"
Successfully created new SMS: /org/freedesktop/ModemManager1/SMS/0
$ sudo mmcli -m 0 -s /org/freedesktop/ModemManager1/SMS/0 --send
successfully sent the SMS
=== Mobile Data ===
To set up mobile data in command line with ModemManager:
* Make sure ModemManager is started (sudo rc-service modemmanager start).
* If your SIM is locked, make sure to enter PIN (see above).
* Look up your modem device name wwan0qmi0 / cdc-wdm0 / rpmsg0 in output of nmcli d .
lg-hammerhead [~]$ nmcli d
DEVICE TYPE STATE CONNECTION 
wlan0 wifi connected Lexx Wi-Fi 
wwan0qmi0 gsm disconnected -- 
p2p-dev-wlan0 wifi-p2p disconnected -- 
dummy0 dummy unmanaged -- 
usb0 ethernet unmanaged -- 
lo loopback unmanaged --
* Create network connection for modem:
# Change "gsm" and "wwan0qmi0" with your TYPE and DEVICE below respectively.
$ sudo nmcli con add con-name "modem" type "gsm" ifname "wwan0qmi0" gsm.auto-config "TRUE"
# If auto-config doesn't work, adjust this command ("internet.mts.ru" & "mts") with your Internet Service Provider's apn settings.
$ sudo nmcli con add con-name "modem" type "gsm" ifname "wwan0qmi0" apn "internet.mts.ru" user "mts" password "mts"
# You should then get:
Connection 'modem' (xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) successfully added.
NetworkManager will then connect mobile network automatically when it's available.
To connect manually use sudo nmcli c up "modem".
* Check if an IP address is assigned to wwan0/rmnet0/etc with ip addr .
* Check if modem is the gateway with ip route (expect default via 10... dev wwan0/rmnet0/etc ...)
* Ping something (e.g. ping 8.8.8.8).
See https://gist.github.com/Minecrell/4cc2bfb9fcae18e294386b0a213907d1 [dead link] for oFono instructions.
== Qualcomm Modems ==
On most Qualcomm SoCs the modem is a separate processor which lives next to the main CPU where Linux is running on. It needs to be given firmware by the host processor to start.
The procedure for getting the modem to work is generally the following:
* Package and install the Firmware of your modem into the file system, generally the mba.* and modem.* files.
* Install the package msm-modem-downstream or msm-modem-rpmsg (for most older SoCs on mainline, see below), depending on the kernel you are using (and reboot to activate the udev rules and services).
* Install ofono and start it using rc-service ofono start
* You should see signs of your firmware being loaded in the dmesg.
* You can use the ofono test scripts (packaged in ofono-scripts or ofonoctl to see if the Linux recognized your modem and if it works correctly.
* On some platforms you may need to manually install msm-modem-uim-selection, see Dual-Sim QMI page for some details.
Note: On newer SoCs (e.g. SDM845 or MSM8953), the modem seems to be available only through QRTR, and not through rpmsg channels as on older Qualcomm SoCs. You can see this if qrtr-lookup also lists modem services such as User Identity Module service. In that case, you can query the modem through libqmi 1.26.0+ like qmicli -d qrtr://<node> --uim-get-card-status (get <node> from the qrtr-lookup output). Currently, the QRTR transport does not seem to be supported in modem services like oFono or ModemManager yet. At least for ModemManager there seem to be ongoing efforts to make it work, though. See SDM845 Modem for details and example output. Ofono QRTR/QMI support is WIP, ofono version >= 2.4.
== Troubleshooting ==
=== When switching UI (or debugging modem) ===
Ofono and ModemManager cannot run at the same time. If you switch UI from Mer- or UBPorts-related projects to Phosh or Plasma Mobile (or vice versa), you might have to make sure that only the correct userspace service is running.
Check if ofono service is running: rc-status | grep ofono
Start ofono service (not persistent): sudo service ofono start 
=== Getting ModemManager logs ===
1. Open /etc/init.d/modemmanager with your favorite text editor with root permissions
2. Enable debug mode by changing the command_args line to command_args="${modemmanager_opts} --debug --log-level=DEBUG"
3. Output the logs to /var/log/modemmanager.err by adding error_log="/var/log/modemmanager" to the same file.
4. Save and restart ModemManager with rc-service modemmanager restart
5. The logs will now be available at /var/log/modemmmanager.err. Note that they contain sensitive information such as your phone number(s), IMEI, etc.! Scrub them when uploading these logs to the Web!
Also note that the logs may take up a lot of space if you leave them running for a long time.
Example of /etc/init.d/modemmanager
 #!/sbin/openrc-run
 
 supervisor=supervise-daemon
 command=/usr/sbin/ModemManager
 command_args="${modemmanager_opts} --debug --log-level=DEBUG"
 error_log="/var/log/modemmanager.err"
 
 description="ModemManager Daemon"
 
 depend() {
 need dbus
 }
=== Getting eg25-manager logs ===
This only applies to the PinePhone.
1. Open /etc/init.d/eg25-manager with your favorite text editor with root permissions
2. Output the logs to /var/log/eg25-manager.err by adding error_log="/var/log/e25-manager" to the same file.
4. Save and restart eg25-manager with rc-service eg25-manager restart
5. The logs will now be available at /var/log/eg25-manager.err.
Example of /etc/init.d/eg25-manager
 #!/sbin/openrc-run
 
 supervisor=supervise-daemon
 command=/usr/bin/eg25-manager
 error_log="/var/log/eg25-manager.err"
 
 description="EG25 Manager Daemon"
=== usbmon logs ===
The Linux kernel allows you to capture QMI and AT commands over USB using usbmon and can be read using Wireshark.
See this page to use it: Create usbmon capture
== Relevant issues ==
* N900: integrate ofono
* Let's get the cellular modem working! (presenting various stacks, general discussion)
* Get qualcomm modems working (at the end of the thread scintill wrote a few wrappers and made SMS on a QC modem work with a downstream kernel without userspace blobs!)
* i9195/Qualcomm modem support (scintill's work integrated)
* xiaomi-santoni: gets modem to work on the device
== Reverse engineering userspace daemons ==
Android ROMs contain several userspace daemons which interact with the modem such as rmtfs, IMS daemons, etc.
strace is your friend on an Android userdebug image (example: LineageOS) where you can use root.
Sometimes SELinux will make it hard to insert your strace command in boot services, you can disable it by booting
the boot.img using adb boot with a Linux kernel cmdline that disables SELinux: androidboot.selinux=permissive.
You can get the complete cmdline you have to pass by checking the cmdline when you have a LineageOS image booted where you append the SELinux permissive mode argument.
Example:
 fastboot boot boot.img --cmdline "androidboot.selinux=permissive androidboot.hardware=qcom androidboot.console=ttyMSM0 printk.devkmsg=on androidboot.configfs=true loop.max_part=7 msm_rtb.filter=0x237 ehci-hcd.park=3 service_locator.enable=1 androidboot.memcg=1 cgroup.memory=nokmem androidboot.usbcontroller=a600000.dwc3 swiotlb=2048 androidboot.boot_devices=soc/1d84000.ufshc buildvariant=userdebug"
== Relevant pages ==
* QMI
* Samsung Modem
== See also ==
* Maemo Leste Call/Phone support
* KDE Developer Documentation: Plasma Mobile Telephony Stack: https://develop.kde.org/docs/packaging/plasma-mobile/telephony/
* APN Settings: These settings will work even if you don't have a pinephone https://wiki.pine64.org/wiki/PinePhone_APN_Settings
Category:Guide