Skip to content

Commit

Permalink
chore: update README.md with installation instructions and add QMI AP…
Browse files Browse the repository at this point in the history
…DU driver
  • Loading branch information
damonto committed Jul 24, 2024
1 parent 61698f7 commit c6ef874
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,46 @@ Once done, you can run the program with root privileges:
sudo ./telegram-sms -bot-token=YourTelegramToken --admin-id=YourTelegramChatID
```

### QMI Driver
### QMI

Since the new version of "libqmi" has not been released, if you want to use the qmi driver, you should compile "libqmi" yourself.
To use the QMI driver, ensure you have the following dependencies:

> https://modemmanager.org/docs/libqmi/building/building-meson/
1. **libqmi** >= 1.35.5
2. **lpac** >= 2.0.3

Since the new version of `libqmi` has not been officially released and `lpac` doesn't provide a binary with the built-in QMI driver, you will need to compile `libqmi` and `lpac` manually.

For detailed build instructions, refer to [libqmi's official documentation](https://modemmanager.org/docs/libqmi/building/building-meson/).

#### 1. Compile and Install `libqmi`

If you already have `libqmi` version **1.35.5** or later installed, you can skip this step.

```bash
# Arch Linux (dependencis)
# pacman -S meson ninja bash-completion gobject-introspection help2man
# sudo pacman -S --needed meson ninja pkg-config bash-completion gobject-introspection help2man (Arch Linux)
# sudo apt-get install -y meson ninja-build pkg-config bash-completion gobject-introspection help2man (Ubuntu/Debian)
git clone https://gitlab.freedesktop.org/mobile-broadband/libqmi.git
cd libqmi
meson setup build --prefix=/usr
ninja -C build
ninja -C build install
sudo ninja -C build install
```

#### 2. Compile `lpac`

```bash
# sudo pacman -S --needed cmake make pkg-config libcurl-gnutls (Arch Linux)
# sudo apt-get install -y cmake make pkg-config libcurl4-gnutls-dev (Ubuntu/Debian)
git clone https://github.com/estkme-group/lpac.git
cd lpac
cmake -B build -DLPAC_WITH_APDU_QMI=on -DLPAC_WITH_APDU_PCSC=off -S .
make -j$(nproc) -C build
```

Once you have compiled and installed `libqmi` and `lpac`, you can run the program with the following command:

```bash
sudo ./telegram-sms -bot-token=YourTelegramToken --admin-id=YourTelegramChatID --apdu-driver=qmi --dir=/path/to/lpac --dont-download
```

If you wish to run the program in the background, you can utilize the `systemctl` command. Here is an example of how to achieve this:
Expand Down
1 change: 1 addition & 0 deletions internal/app/handler/ussd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (h *USSDHandler) handleExecuteCommand(c telebot.Context) error {
timout := time.After(120 * time.Second)
<-timout
h.modem.CancelUSSDSession()
h.stateManager.Done(c)
}()
h.state.Next(StateUSSDRespondCommand)
return c.Send(fmt.Sprintf("%s\n%s\nIf you want to respond to this USSD command, please send me the response.", c.Text(), response))
Expand Down
15 changes: 5 additions & 10 deletions internal/pkg/modem/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,24 @@ type Manager struct {
reboot chan struct{}
}

var managerInstance *Manager
var instance *Manager

func NewManager() (*Manager, error) {
mmgr, err := modemmanager.NewModemManager()
if err != nil {
return nil, err
}

if err := mmgr.ScanDevices(); err != nil {
return nil, err
}

managerInstance = &Manager{
instance = &Manager{
mmgr: mmgr,
modems: make(map[string]*Modem),
reboot: make(chan struct{}, 1),
}
go managerInstance.watch()
return managerInstance, nil
go instance.watch()
return instance, nil
}

func GetManager() *Manager {
return managerInstance
return instance
}

func (m *Manager) watch() error {
Expand Down
9 changes: 9 additions & 0 deletions internal/pkg/modem/ussd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func (m *Modem) RespondUSSDCommand(response string) (string, error) {
if err != nil {
return "", err
}
state, err := ussd.GetState()
if err != nil {
return "", err
}
if state == modemmanager.MmModem3gppUssdSessionStateActive || state == modemmanager.MmModem3gppUssdSessionStateIdle {
if err := ussd.Cancel(); err != nil {
return "", err
}
}
reply, err := ussd.Respond(response)
if err != nil {
return "", err
Expand Down

0 comments on commit c6ef874

Please sign in to comment.