Skip to content

Instantly share code, notes, and snippets.

@LaloHao
Forked from aforemny/ofono + phonesim
Created August 2, 2021 10:32
Show Gist options
  • Save LaloHao/7d6b6148753c59c0e91ebcd4f20c9a4e to your computer and use it in GitHub Desktop.
Save LaloHao/7d6b6148753c59c0e91ebcd4f20c9a4e to your computer and use it in GitHub Desktop.

-- phonesim.nix (phonesim module)

{ config, pkgs, lib, ... }:

with lib;

let

  port = "12345";

in

{

  config = {
   systemd.services.phonesim = {
     description = "phonesim";
     after = [ "ofono.service" ];
     wantedBy = [ "multi-user.target" ];
     serviceConfig = {
       ExecStart = "${pkgs.ofono-phonesim}/bin/phonesim -p ${port} ${pkgs.ofono-phonesim}/share/phonesim/default.xml";
     };
   };

  # Could not get this to work. I used the scripts from the ofono source distribution, see blow.
  #systemd.services.phonesim-modem = {
  #  description = "phonesim-modem";
  #  after = [ "phonesim.service" ];
  #  wantedBy = [ "multi-user.target" ];
  #  serviceConfig = {
  #    ExecStart = "${pkgs.dbus}/bin/dbus-send --print-reply --system --dest=org.ofono /phonesim org.ofono.Modem.SetProperty string:'Powered' variant:boolean:'true'";
  #    ExecStop = "${pkgs.dbus}/bin/dbus-send --print-reply --system --dest=org.ofono /phonesim org.ofono.Modem.SetProperty string:'Powered' variant:boolean:'false'";
  #  };
  #};
  };

}

-- ofonod config

environment.etc."ofono/phonesim.conf".text = ''
  [phonesim]
  Driver=phonesim
  Address=127.0.0.1
  Port=12345
'';

-- enable-modem /phonesim (ofono/test/

#!/usr/bin/env python3

import dbus
import sys

bus = dbus.SystemBus()

if len(sys.argv) == 2:
        path = sys.argv[1]
else:
        manager = dbus.Interface(bus.get_object('org.ofono', '/'),
                        'org.ofono.Manager')
        modems = manager.GetModems()
        path = modems[0][0]

print("Connecting modem %s..." % path)
modem = dbus.Interface(bus.get_object('org.ofono', path),
                                                'org.ofono.Modem')

modem.SetProperty("Powered", dbus.Boolean(1), timeout = 120)

-- disable-modem /phonesim

#!/usr/bin/env python3

import dbus
import sys

bus = dbus.SystemBus()

if len(sys.argv) == 2:
        path = sys.argv[1]
else:
        manager = dbus.Interface(bus.get_object('org.ofono', '/'),
                        'org.ofono.Manager')
        modems = manager.GetModems()
        path = modems[0][0]

print("Disconnecting modem %s..." % path)
modem = dbus.Interface(bus.get_object('org.ofono', path),
                                                'org.ofono.Modem')

modem.SetProperty("Powered", dbus.Boolean(0), timeout = 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment