All of lore.kernel.org
 help / color / mirror / Atom feed
* Serial Port connection with DBus API
@ 2017-04-07 13:47 Barry Byford
  2017-04-07 21:56 ` Barry Byford
  0 siblings, 1 reply; 10+ messages in thread
From: Barry Byford @ 2017-04-07 13:47 UTC (permalink / raw)
  To: Bluez mailing list

Hello,

I am trying to create a serial port server that can be connected to by
an already existing Android app.

The app is trying connect on channel 1. I am taking the
test/test-profile example as my starting point.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile?h=5.43

My code is far from finished but I thought it would be enough to
accept the connection (or at least print that a new connection attempt
had happened.) However I am getting an access denied error and I'm
concerned that I'm going down the wrong route on this and it might be
simpler than I am making it.

Error message
$ python3 BTspp.py
Traceback (most recent call last):
  File "BTclassic.py", line 54, in <module>
    dbus.publish('org.bluez.Profile1', Profile('x', 'y'))
  File "/usr/local/lib/python3.5/dist-packages/pydbus/publication.py",
line 42, in publish
    return Publication(self, bus_name, *objects)
  File "/usr/local/lib/python3.5/dist-packages/pydbus/publication.py",
line 35, in __init__
    self._at_exit(bus.request_name(bus_name,
allow_replacement=allow_replacement, replace=replace).__exit__)
  File "/usr/local/lib/python3.5/dist-packages/pydbus/request_name.py",
line 29, in request_name
    return NameOwner(self, name, allow_replacement, replace)
  File "/usr/local/lib/python3.5/dist-packages/pydbus/request_name.py",
line 8, in __init__
    res = bus.dbus.RequestName(name, flags)
  File "/usr/local/lib/python3.5/dist-packages/pydbus/proxy_method.py",
line 75, in __call__
    0, timeout_to_glib(timeout), None).unpack()
GLib.Error: g-dbus-error-quark:
GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Connection
":1.47" is not allowed to own the service "org.bluez.Profile1" due to
security policies in the configuration file (9

Python code so far:

from pydbus import SystemBus
from gi.repository import GLib

loop = GLib.MainLoop()

dbus = SystemBus()


class Profile(object):
    """
      <node>
        <interface name='org.bluez.Profile1'>
          <method name='Release'>
          </method>
          <method name='Cancel'>
          </method>
          <method name='NewConnection'>
            <arg type='o' name='path' direction='in'/>
            <arg type='h' name='fd' direction='in'/>
            <arg type='a{sv}' name='properties' direction='in'/>
          </method>
          <method name='RequestDisconnection'>
            <arg type='o' name='path' direction='in'/>
          </method>
        </interface>
      </node>
    """
    def __init__(self, x, y):
        pass

    def Release(self):
        pass

    def Cancel(self):
        pass

    def NewConnection(self, path, fd, properties):
        print('New connection', path, fd, properties)

    def RequestDisconnection(self, path):
        pass

if __name__ == '__main__':
    profile_mngr = dbus.get('org.bluez', '/org/bluez')
    uuid = "00001101-0000-1000-8000-00805f9b34fb"
    opts = {
            "AutoConnect": GLib.Variant('b', True),
            'Channel': GLib.Variant('i', 1),
            'Service': GLib.Variant('s', uuid),
            'Name': GLib.Variant('s', 'Serial Port')
        }

    # my_profile = Profile(dbus, '/org/bluez/example')
    dbus.publish('org.bluez.Profile1', Profile('x', 'y'))
    profile_mngr.RegisterProfile('/foo/bar/profile', uuid, opts)

    loop.run()


Is there a simpler way of doing this?

Thanks,
Barry

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-04-26 22:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-07 13:47 Serial Port connection with DBus API Barry Byford
2017-04-07 21:56 ` Barry Byford
2017-04-08  7:18   ` Johan Hedberg
2017-04-08  7:57     ` Barry Byford
2017-04-21 20:54     ` Barry Byford
2017-04-22  5:26       ` Johan Hedberg
2017-04-22 20:46         ` Barry Byford
2017-04-25 21:48           ` Barry Byford
2017-04-26 19:07             ` Johan Hedberg
2017-04-26 22:47               ` Barry Byford

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.