User:TravMurav/Dual-Sim QMI draft

From postmarketOS Wiki
Note The msm-modem-uim-selection package was added to the pmOS and is installed by default on platforms where it is known to be required
Note This page is an early draft that needs to be rewritten and placed somewhere in QMI/Dual-SIM. This page might be confusing in it's current state

Some dual-sim devices may have a problem where the modem will not select your SIM automatically. When it happens you may need to manually select an application that will handle authentification on your SIM.

This guide happens to work in general but sometimes vendor (like Motorolla on harpia) may change modem firmware and you will need another solution

(Examples provided for wileyfox-crackling)


Preparation

We don't need custom libqmi anymore, but this instruction is saved for reference

Get working libqmi (at the time of writing libqmi from Alpine crashes with segfault on attempt of communicating with modem):

(This is done with pmbootstrap on your local machine)

cd ~/.local/var/pmbootstrap/cache_git/pmaports/temp
mkdir libqmi
cd libqmi
wget https://gist.githubusercontent.com/Minecrell/eddea99e7c7b17c2a723d8ea657d56ea/raw/cf7a7e1467c062fce459a94ec9d479bb8a22712c/APKBUILD
pmbootstrap build libqmi --arch aarch64

You need to install all the necessary components on the device: (Assuming that you have local repo and Internet connection configured)

(This is done on your device)

sudo apk add libqmi

Make sure you have libqmi, qmi-utils and ofono-scripts installed. Also make sure you have selected proper kernel variant (with -modem) and enabled nonfree-firmware during pmbootstrap init.

Making dual-sim QMI modem work

Boot device with working SIM inserted.

Make sure oFono services are stopped:

$ sudo rc-service ofono stop
 * Stopping oFono ...
$ sudo rc-service ofono-auto-enable stop
 * Stopping ofono-auto-enable ...

Check that your modem is working and detected SIM in slot:

Note If you have a newer modem that is only accessible through QRTR, you will have to replace /dev/modem with qrtr://<node> where <node> can be found using qrtr-lookup (install qrtr package).
$ sudo qmicli -d /dev/modem --uim-get-card-status
[/dev/modem] Successfully got card status
Provisioning applications:
        Primary GW:   session doesn't exist
        Primary 1X:   session doesn't exist
        Secondary GW: session doesn't exist
        Secondary 1X: session doesn't exist
Slot [1]:
        Card state: 'present'
        UPIN state: 'not-initialized'
                UPIN retries: '0'
                UPUK retries: '0'
        Application [1]:
                Application type:  'usim (2)'
                Application state: 'detected'
                Application ID:
                        [ YOUR AID FOR THIS SIM ]
                Personalization state: 'unknown'
                UPIN replaces PIN1: 'no'
                PIN1 state: 'not-initialized'
                        PIN1 retries: '0'
                        PUK1 retries: '0'
                PIN2 state: 'not-initialized'
                        PIN2 retries: '0'
                        PUK2 retries: '0'
Slot [2]:
        Card state: 'error: no-atr-received (3)
        UPIN state: 'not-initialized'
                UPIN retries: '0'
                UPUK retries: '0'

Note that neither of four provisioning applications is present: On harpia it wasn't the case, application was already selected but modem didn't go online anyway.

You also can see list of your slots and state of cards in them. You may have more than one application though, for now we only need USIM one.


If you have an application selected already, please check if you have

$ sudo qmicli -d /dev/modem --dms-uim-get-state
[/dev/modem] UIM state retrieved:
	State: 'not-present'

This shows a (suspected) bug in firmware where it reports the wrong state if the application was selected too early (Some kind of race condition in the modem). You need to clear selected application by doing this:

$ sudo qmicli -d /dev/modem --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning'

Now you can try to select an application on your SIM:

In the following command you may need to change slot that you are using and you should replace $YOUR_AID with Application ID that you got from previous command. (note that applications have different IDs)

$ sudo qmicli -d /dev/modem --uim-change-provisioning-session="slot=1,activate=yes,session-type=primary-gw-provisioning,aid=$YOUR_AID"
[/dev/modem] Successfully changed provisioning session


Error like this may mean that either you did something wrong or that you need a different approach. (The message in qmicli for this error is wrong and only means that modem didn't like something)

error: could not power off SIM: QMI protocol error (3): 'Internal'


If the command would succeed you will have application sellected:

$ sudo qmicli -d /dev/modem --uim-get-card-status
[/dev/modem] Successfully got card status
Provisioning applications:
        Primary GW:   slot '1', application '1'
        Primary 1X:   session doesn't exist
        Secondary GW: session doesn't exist
        Secondary 1X: session doesn't exist
Slot [1]:
        Card state: 'present'
        UPIN state: 'not-initialized'
                UPIN retries: '0'
                UPUK retries: '0'
        Application [1]:
                Application type:  'usim (2)'
                Application state: 'ready'
                Application ID:
                        [ AID ]
                Personalization state: 'ready'
                UPIN replaces PIN1: 'no'
                PIN1 state: 'disabled'
                        PIN1 retries: '3'
                        PUK1 retries: '10'
                PIN2 state: 'enabled-not-verified'
                        PIN2 retries: '2'
                        PUK2 retries: '10'
Slot [2]:
        Card state: 'error: no-atr-received (3)
        UPIN state: 'not-initialized'
                UPIN retries: '0'
                UPUK retries: '0'


Only thing left is to start ofono and connect to the network:

Icon TODO: Unlocking SIM with PIN? /usr/lib/ofono/test/enter-pin ...
$ sudo rc-service ofono start
 * Starting oFono ...
$ sudo rc-service ofono-auto-enable start
 * Starting ofono-auto-enable ...
Note enable-modem and online-modem are probably not needed with ofono-auto-enable
$ cd /usr/lib/ofono/test/
$ ./enable-modem
Connecting modem /gobi_0...

$ ./list-modems
[ /gobi_0 ]
    Online = 0
    Powered = 1
    Lockdown = 0
    Emergency = 0
    Manufacturer = QUALCOMM INCORPORATED
    Model = 0
    Revision = MPSS.DPM.2.0.2.c1.4-00015-M8936FAAAANUZM-1  1  [Apr 29 2015 05:00:00]
    Serial = XXXXXXXXXXXXXXX
    SystemPath = /sys/devices/platform/soc/4080000.hexagon/remoteproc/remoteproc0/remoteproc0:smd-edge/remoteproc0:smd-edge.rpmsg_chrdev.0.0/rpmsg/rpmsg_ctrl1/rpmsg0
    Interfaces = org.ofono.SmartMessaging org.ofono.PushNotification org.ofono.MessageManager org.ofono.LongTermEvolution org.ofono.RadioSettings org.ofono.MessageWaiting org.ofono.AllowedAccessPoints org.ofono.SimManager org.ofono.VoiceCallManager
    Features = sms rat sim
    Type = hardware
    [ org.ofono.SmartMessaging ]
    [ org.ofono.PushNotification ]
    [ org.ofono.MessageManager ]
        ServiceCenterAddress = +XXXXXXXXXXX
        UseDeliveryReports = 0
        Bearer = cs-preferred
        Alphabet = default
    [ org.ofono.LongTermEvolution ]
        DefaultAccessPointName =
        Protocol = ip
        AuthenticationMethod = none
        Username =
        Password =
    [ org.ofono.RadioSettings ]
        TechnologyPreference = any
        AvailableTechnologies = gsm umts lte
    [ org.ofono.MessageWaiting ]
        VoicemailWaiting = 0
        VoicemailMessageCount = 0
        VoicemailMailboxNumber =
    [ org.ofono.AllowedAccessPoints ]
    [ org.ofono.SimManager ]
        Present = 1
        CardIdentifier = XXXXXXXXXXXXXXXXXXXX
        SubscriberIdentity = XXXXXXXXXXXXXXX
        FixedDialing = 0
        BarredDialing = 0
        MobileCountryCode = XXX
        MobileNetworkCode = XX
        SubscriberNumbers = +XXXXXXXXXXX
        LockedPins =
        PinRequired = none
        Retries = [pin = 3] [pin2 = 2] [puk = 10] [puk2 = 10]
        CardSlotCount = 1
        ActiveCardSlot = 1
    [ org.ofono.VoiceCallManager ]
        EmergencyNumbers = 911 112

$ ./online-modem
Setting modem /gobi_0 online...

Now you can send an SMS!

Using ofono test scripts:

$ cd /usr/lib/ofono/test/
$ ./send-sms "+XXXXXXXXXXX" "Hello from pmOS!" 0
Send message using modem /gobi_0 ...
/gobi_0/message_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Or you can try to make a call!

$ cd /usr/lib/ofono/test/
$ ./dial-number "number"
Using modem /gobi_0
/gobi_0/voicecall01
$ ./hangup-active 
[ /gobi_0/voicecall01 ] active

Or using qt5-qttools:

$ qdbus-qt5 --system org.ofono /gobi_0 org.ofono.VoiceCallManager.Dial "number" ""
...
$ qdbus-qt5 --system org.ofono /gobi_0 org.ofono.VoiceCallManager.HangupAll

Automating this process

Install the package with apk add msm-modem-uim-selection

At some point I wrote a hacky script that does all of that automatically as a system service. If this guide works for you, you could try installing it from this page Ideally it should be replaced with something less fragile but at least it works as PoC.

Notes:

"valid" session-type values are[1]:

session-type Description
primary-gw-provisioning Primary GSM/WCDMA provisioning.
primary-1x-provisioning Primary CDMA1x provisioning.
secondary-gw-provisioning Secondary GSM/WCDMA provisioning.
secondary-1x-provisioning Secondary CDMA1x provisioning.
nonprovisioning-slot-1 Nonprovisioning on slot 1.
nonprovisioning-slot-2 Nonprovisioning on slot 2.
type-card-slot-1 Card on slot 1.
type-card-slot-2 Card on slot 2.
logical-channel-slot-1 Logical channel on slot 1.
logical-channel-slot-2 Logical channel on slot 2.

References