linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Registering a profile
@ 2018-09-28 22:38 Neil Benn
  2018-10-01 22:29 ` Neil Benn
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Benn @ 2018-09-28 22:38 UTC (permalink / raw)
  To: linux-bluetooth

Hello,

  I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
the device using the following call:
---
    #configure the bluetooth hardware device
    def init_bt_device(self):

        print("Configuring for name " + BTKbDevice.MY_DEV_NAME)

        #set the device class to a barcode scanner and set the name
        os.system("hciconfig hcio class 0x002560")
        os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)

        #make the device discoverable
        os.system("hciconfig hcio piscan")

  Then after that I attempt to setup the profile using the following code:
---
    #set up a bluez profile to advertise device capabilities from a
loaded service record
    def init_bluez_profile(self):

        print("Configuring Bluez Profile")

        #setup profile options
        service_record=self.read_sdp_service_record()

        opts = {
            "ServiceRecord":service_record,
            "Role":"server",
            "RequireAuthentication":False,
            "RequireAuthorization":False,
            "Name":BTKbDevice.MY_DEV_NAME,
            "AutoConnect":True
        }

        #retrieve a proxy for the bluez profile interface
        bus = dbus.SystemBus()
        self.manager =
dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
"org.bluez.ProfileManager1")
        self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
        self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
BTKbDevice.UUID, opts)
        print("Profile registered ")
---
  The sdp record is available from https://textuploader.com/dv8xt.
The profile in question is basically the same as the one defined in
the test-profile as shown below:
---
class BTKbBluezProfile(dbus.service.Object):
    fd = -1

    @dbus.service.method("org.bluez.Profile1",
                                    in_signature="", out_signature="")
    def Release(self):
            print("Release")
            mainloop.quit()

    @dbus.service.method("org.bluez.Profile1",
                                    in_signature="", out_signature="")
    def Cancel(self):
            print("Cancel")

    @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
out_signature="")
    def NewConnection(self, path, fd, properties):
            self.fd = fd.take()
            print("NewConnection(%s, %d)" % (path, self.fd))
            for key in properties.keys():
                    print ('key ' + key + ' value ' + properties[key])
                    if key == "Version" or key == "Features":
                            print("  %s = 0x%04x" % (key, properties[key]))
                    else:
                            print("  %s = %s" % (key, properties[key]))

    @dbus.service.method("org.bluez.Profile1", in_signature="o",
out_signature="")
    def RequestDisconnection(self, path):
            print("RequestDisconnection(%s)" % (path))

            if (self.fd > 0):
                    os.close(self.fd)
                    self.fd = -1

    def __init__(self, bus, path):
            dbus.service.Object.__init__(self, bus, path)
---
  However it seems like the profile is not being registered, or least
the methods in the profile are not being called.  I'm sorry to ask
such a basic question but can someone please point me in the right
direction as to why the profile is either not being registered or the
callbacks on the profile are not being called.

  Thank you very much for reading this far and any and all help is
most appreciated!

Cheers,

Neil

-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

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

* Re: Registering a profile
  2018-09-28 22:38 Registering a profile Neil Benn
@ 2018-10-01 22:29 ` Neil Benn
  2018-10-02  8:37   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Benn @ 2018-10-01 22:29 UTC (permalink / raw)
  To: linux-bluetooth

Hello,

  I've been running a dbus-monitor and I can't see the interface being
called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
I've tried listening to that interface and also on the path with
dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
IF anyone has any advance I'd be very grateful and there is 100 rep
points up on Stack Overflow for any advice too!

  Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!

Cheers,

Neil
On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
>
> Hello,
>
>   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> the device using the following call:
> ---
>     #configure the bluetooth hardware device
>     def init_bt_device(self):
>
>         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
>
>         #set the device class to a barcode scanner and set the name
>         os.system("hciconfig hcio class 0x002560")
>         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
>
>         #make the device discoverable
>         os.system("hciconfig hcio piscan")
>
>   Then after that I attempt to setup the profile using the following code:
> ---
>     #set up a bluez profile to advertise device capabilities from a
> loaded service record
>     def init_bluez_profile(self):
>
>         print("Configuring Bluez Profile")
>
>         #setup profile options
>         service_record=self.read_sdp_service_record()
>
>         opts = {
>             "ServiceRecord":service_record,
>             "Role":"server",
>             "RequireAuthentication":False,
>             "RequireAuthorization":False,
>             "Name":BTKbDevice.MY_DEV_NAME,
>             "AutoConnect":True
>         }
>
>         #retrieve a proxy for the bluez profile interface
>         bus = dbus.SystemBus()
>         self.manager =
> dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> "org.bluez.ProfileManager1")
>         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
>         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> BTKbDevice.UUID, opts)
>         print("Profile registered ")
> ---
>   The sdp record is available from https://textuploader.com/dv8xt.
> The profile in question is basically the same as the one defined in
> the test-profile as shown below:
> ---
> class BTKbBluezProfile(dbus.service.Object):
>     fd = -1
>
>     @dbus.service.method("org.bluez.Profile1",
>                                     in_signature="", out_signature="")
>     def Release(self):
>             print("Release")
>             mainloop.quit()
>
>     @dbus.service.method("org.bluez.Profile1",
>                                     in_signature="", out_signature="")
>     def Cancel(self):
>             print("Cancel")
>
>     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> out_signature="")
>     def NewConnection(self, path, fd, properties):
>             self.fd = fd.take()
>             print("NewConnection(%s, %d)" % (path, self.fd))
>             for key in properties.keys():
>                     print ('key ' + key + ' value ' + properties[key])
>                     if key == "Version" or key == "Features":
>                             print("  %s = 0x%04x" % (key, properties[key]))
>                     else:
>                             print("  %s = %s" % (key, properties[key]))
>
>     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> out_signature="")
>     def RequestDisconnection(self, path):
>             print("RequestDisconnection(%s)" % (path))
>
>             if (self.fd > 0):
>                     os.close(self.fd)
>                     self.fd = -1
>
>     def __init__(self, bus, path):
>             dbus.service.Object.__init__(self, bus, path)
> ---
>   However it seems like the profile is not being registered, or least
> the methods in the profile are not being called.  I'm sorry to ask
> such a basic question but can someone please point me in the right
> direction as to why the profile is either not being registered or the
> callbacks on the profile are not being called.
>
>   Thank you very much for reading this far and any and all help is
> most appreciated!
>
> Cheers,
>
> Neil
>
> --
>
> Neil Benn MSc
> Ziath Ltd
> Phone: +44 (0) 1223 855021
> http://www.ziath.com
>
> Please consider the environment before printing this email.



-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

* Re: Registering a profile
  2018-10-01 22:29 ` Neil Benn
@ 2018-10-02  8:37   ` Luiz Augusto von Dentz
  2018-10-02 10:39     ` Neil Benn
  0 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02  8:37 UTC (permalink / raw)
  To: neil.benn; +Cc: linux-bluetooth

Hi Neil,
On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
>
> Hello,
>
>   I've been running a dbus-monitor and I can't see the interface being
> called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> I've tried listening to that interface and also on the path with
> dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> IF anyone has any advance I'd be very grateful and there is 100 rep
> points up on Stack Overflow for any advice too!
>
>   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
>
> Cheers,
>
> Neil
> On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > the device using the following call:
> > ---
> >     #configure the bluetooth hardware device
> >     def init_bt_device(self):
> >
> >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> >
> >         #set the device class to a barcode scanner and set the name
> >         os.system("hciconfig hcio class 0x002560")
> >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> >
> >         #make the device discoverable
> >         os.system("hciconfig hcio piscan")
> >

You shouldn't be using hciconfig, instead do the following:

The class is automatically set by bluetoothd based on the
services/profiles registered and the setting in the main.conf:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9

For the name use D-Bus property Alias:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216

To make the adapter discoverable use D-Bus property Discoverable:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252



> >   Then after that I attempt to setup the profile using the following code:
> > ---
> >     #set up a bluez profile to advertise device capabilities from a
> > loaded service record
> >     def init_bluez_profile(self):
> >
> >         print("Configuring Bluez Profile")
> >
> >         #setup profile options
> >         service_record=self.read_sdp_service_record()
> >
> >         opts = {
> >             "ServiceRecord":service_record,
> >             "Role":"server",
> >             "RequireAuthentication":False,
> >             "RequireAuthorization":False,
> >             "Name":BTKbDevice.MY_DEV_NAME,
> >             "AutoConnect":True
> >         }
> >
> >         #retrieve a proxy for the bluez profile interface
> >         bus = dbus.SystemBus()
> >         self.manager =
> > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > "org.bluez.ProfileManager1")
> >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > BTKbDevice.UUID, opts)
> >         print("Profile registered ")
> > ---
> >   The sdp record is available from https://textuploader.com/dv8xt.
> > The profile in question is basically the same as the one defined in
> > the test-profile as shown below:
> > ---
> > class BTKbBluezProfile(dbus.service.Object):
> >     fd = -1
> >
> >     @dbus.service.method("org.bluez.Profile1",
> >                                     in_signature="", out_signature="")
> >     def Release(self):
> >             print("Release")
> >             mainloop.quit()
> >
> >     @dbus.service.method("org.bluez.Profile1",
> >                                     in_signature="", out_signature="")
> >     def Cancel(self):
> >             print("Cancel")
> >
> >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > out_signature="")
> >     def NewConnection(self, path, fd, properties):
> >             self.fd = fd.take()
> >             print("NewConnection(%s, %d)" % (path, self.fd))
> >             for key in properties.keys():
> >                     print ('key ' + key + ' value ' + properties[key])
> >                     if key == "Version" or key == "Features":
> >                             print("  %s = 0x%04x" % (key, properties[key]))
> >                     else:
> >                             print("  %s = %s" % (key, properties[key]))
> >
> >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > out_signature="")
> >     def RequestDisconnection(self, path):
> >             print("RequestDisconnection(%s)" % (path))
> >
> >             if (self.fd > 0):
> >                     os.close(self.fd)
> >                     self.fd = -1
> >
> >     def __init__(self, bus, path):
> >             dbus.service.Object.__init__(self, bus, path)
> > ---
> >   However it seems like the profile is not being registered, or least
> > the methods in the profile are not being called.  I'm sorry to ask
> > such a basic question but can someone please point me in the right
> > direction as to why the profile is either not being registered or the
> > callbacks on the profile are not being called.

They would be called only when there is a connection to the profile,
did you actually connect? If this is something like a serial port the
remote should lookup the SDP record and connect to the channel listed
there.

> >   Thank you very much for reading this far and any and all help is
> > most appreciated!
> >
> > Cheers,
> >
> > Neil
> >
> > --
> >
> > Neil Benn MSc
> > Ziath Ltd
> > Phone: +44 (0) 1223 855021
> > http://www.ziath.com
> >
> > Please consider the environment before printing this email.
>
>
>
> --
>
> Neil Benn MSc
> Ziath Ltd
> Phone: +44 (0) 1223 855021
> http://www.ziath.com
>
> Please consider the environment before printing this email.
>
> Follow us on Facebook, Twitter or LinkedIn
>
> IMPORTANT NOTICE: This message, including any attached documents, is
> intended only for the use of the individual or entity to which it is
> addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law. If the
> reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify Ziath
> Ltd immediately by email at info@ziath.com. Thank you.



--
Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-02  8:37   ` Luiz Augusto von Dentz
@ 2018-10-02 10:39     ` Neil Benn
  2018-10-02 11:27       ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Benn @ 2018-10-02 10:39 UTC (permalink / raw)
  To: luiz.dentz; +Cc: linux-bluetooth

Hello,

  Thanks for that; I'll change the config file for this and for the
name can that be in the main.conf file?  The same for the
discoverable; set the timeout to zero - there is no security needed
for this device at all.  Can this all be done with the conf file?

  On the connection; yes it connects.  This is a HID device connecting
via L2CAP with the interrupt on 19 and the control on 17 and the
windows PC correctly connects to the device, queries the service
record, identifies it as a HID and connects on both the control and
interrupt psm ports but none of the dbus methods are being called.  At
the moment I am using the pybluez library with the BluetoothSocket and
calling listen and accept which is a bit 'manual'.  To detect a
disconnect I'm calling hcitool con and parsing the response - which is
again a bit manual.  Please see below for my current 'hack':

---
    #listen for incoming client connections
    #ideally this would be handled by the Bluez 5 profile
    #but that didn't seem to work
    def listen(self):

        print("Waiting for connections")
        self.scontrol=BluetoothSocket(L2CAP)
        self.sinterrupt=BluetoothSocket(L2CAP)

        self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
        self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
        #Start listening on the server sockets
        self.scontrol.listen(1) # Limit of 1 connection
        self.sinterrupt.listen(1)

        self.ccontrol,cinfo = self.scontrol.accept()
        self.controlClientMac = cinfo[0]
        self.controlClientPsm = cinfo[1]
        print ('control is ' + self.controlClientMac + " " +
str(self.controlClientPsm))

        self.cinterrupt, cinfo = self.sinterrupt.accept()
        self.interruptClientMac = cinfo[0]
        self.interruptClientPsm = cinfo[1]
        print ('interrupt is ' + self.interruptClientMac + " " +
str(self.interruptClientPsm))

        thread.start_new_thread(self.check_connection, ())

    def check_connection(self):
        halt = False
        while not halt:
            stdoutdata = subprocess.check_output(["hcitool", "con"])

            if self.controlClientMac in stdoutdata.split():
                time.sleep(0.1)
            else:
                print('got disconnection')
                self.scontrol.shutdown(2);
                self.sinterrupt.shutdown(2)
                halt = True
        thread.start_new_thread(self.listen, ())

  Obviously this is a very clumsy way of doing it and calling back on
the profile is the correct way to do it, I just can't work out why the
profile is not being called.  I'm trying to spy on the dbus comms to
see if anything is being sent but I can't see any bluez profile
messages being sent at all.  Thanks for your response and any advice
is greatly appreciated.

Cheers,

Neil
On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Neil,
> On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   I've been running a dbus-monitor and I can't see the interface being
> > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > I've tried listening to that interface and also on the path with
> > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > IF anyone has any advance I'd be very grateful and there is 100 rep
> > points up on Stack Overflow for any advice too!
> >
> >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> >
> > Cheers,
> >
> > Neil
> > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > the device using the following call:
> > > ---
> > >     #configure the bluetooth hardware device
> > >     def init_bt_device(self):
> > >
> > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > >
> > >         #set the device class to a barcode scanner and set the name
> > >         os.system("hciconfig hcio class 0x002560")
> > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > >
> > >         #make the device discoverable
> > >         os.system("hciconfig hcio piscan")
> > >
>
> You shouldn't be using hciconfig, instead do the following:
>
> The class is automatically set by bluetoothd based on the
> services/profiles registered and the setting in the main.conf:
>
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
>
> For the name use D-Bus property Alias:
>
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
>
> To make the adapter discoverable use D-Bus property Discoverable:
>
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
>
>
>
> > >   Then after that I attempt to setup the profile using the following code:
> > > ---
> > >     #set up a bluez profile to advertise device capabilities from a
> > > loaded service record
> > >     def init_bluez_profile(self):
> > >
> > >         print("Configuring Bluez Profile")
> > >
> > >         #setup profile options
> > >         service_record=self.read_sdp_service_record()
> > >
> > >         opts = {
> > >             "ServiceRecord":service_record,
> > >             "Role":"server",
> > >             "RequireAuthentication":False,
> > >             "RequireAuthorization":False,
> > >             "Name":BTKbDevice.MY_DEV_NAME,
> > >             "AutoConnect":True
> > >         }
> > >
> > >         #retrieve a proxy for the bluez profile interface
> > >         bus = dbus.SystemBus()
> > >         self.manager =
> > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > "org.bluez.ProfileManager1")
> > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > BTKbDevice.UUID, opts)
> > >         print("Profile registered ")
> > > ---
> > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > The profile in question is basically the same as the one defined in
> > > the test-profile as shown below:
> > > ---
> > > class BTKbBluezProfile(dbus.service.Object):
> > >     fd = -1
> > >
> > >     @dbus.service.method("org.bluez.Profile1",
> > >                                     in_signature="", out_signature="")
> > >     def Release(self):
> > >             print("Release")
> > >             mainloop.quit()
> > >
> > >     @dbus.service.method("org.bluez.Profile1",
> > >                                     in_signature="", out_signature="")
> > >     def Cancel(self):
> > >             print("Cancel")
> > >
> > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > out_signature="")
> > >     def NewConnection(self, path, fd, properties):
> > >             self.fd = fd.take()
> > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > >             for key in properties.keys():
> > >                     print ('key ' + key + ' value ' + properties[key])
> > >                     if key == "Version" or key == "Features":
> > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > >                     else:
> > >                             print("  %s = %s" % (key, properties[key]))
> > >
> > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > out_signature="")
> > >     def RequestDisconnection(self, path):
> > >             print("RequestDisconnection(%s)" % (path))
> > >
> > >             if (self.fd > 0):
> > >                     os.close(self.fd)
> > >                     self.fd = -1
> > >
> > >     def __init__(self, bus, path):
> > >             dbus.service.Object.__init__(self, bus, path)
> > > ---
> > >   However it seems like the profile is not being registered, or least
> > > the methods in the profile are not being called.  I'm sorry to ask
> > > such a basic question but can someone please point me in the right
> > > direction as to why the profile is either not being registered or the
> > > callbacks on the profile are not being called.
>
> They would be called only when there is a connection to the profile,
> did you actually connect? If this is something like a serial port the
> remote should lookup the SDP record and connect to the channel listed
> there.
>
> > >   Thank you very much for reading this far and any and all help is
> > > most appreciated!
> > >
> > > Cheers,
> > >
> > > Neil
> > >
> > > --
> > >
> > > Neil Benn MSc
> > > Ziath Ltd
> > > Phone: +44 (0) 1223 855021
> > > http://www.ziath.com
> > >
> > > Please consider the environment before printing this email.
> >
> >
> >
> > --
> >
> > Neil Benn MSc
> > Ziath Ltd
> > Phone: +44 (0) 1223 855021
> > http://www.ziath.com
> >
> > Please consider the environment before printing this email.
> >
> > Follow us on Facebook, Twitter or LinkedIn
> >
> > IMPORTANT NOTICE: This message, including any attached documents, is
> > intended only for the use of the individual or entity to which it is
> > addressed, and may contain information that is privileged,
> > confidential and exempt from disclosure under applicable law. If the
> > reader of this message is not the intended recipient, or the employee
> > or agent responsible for delivering the message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly prohibited.
> > If you have received this communication in error, please notify Ziath
> > Ltd immediately by email at info@ziath.com. Thank you.
>
>
>
> --
> Luiz Augusto von Dentz



-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

* Re: Registering a profile
  2018-10-02 10:39     ` Neil Benn
@ 2018-10-02 11:27       ` Luiz Augusto von Dentz
  2018-10-02 12:28         ` Neil Benn
  0 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02 11:27 UTC (permalink / raw)
  To: neil.benn; +Cc: linux-bluetooth

Hi Neil,
On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
>
> Hello,
>
>   Thanks for that; I'll change the config file for this and for the
> name can that be in the main.conf file?  The same for the
> discoverable; set the timeout to zero - there is no security needed
> for this device at all.  Can this all be done with the conf file?
>
>   On the connection; yes it connects.  This is a HID device connecting
> via L2CAP with the interrupt on 19 and the control on 17 and the
> windows PC correctly connects to the device, queries the service
> record, identifies it as a HID and connects on both the control and
> interrupt psm ports but none of the dbus methods are being called.  At
> the moment I am using the pybluez library with the BluetoothSocket and
> calling listen and accept which is a bit 'manual'.  To detect a
> disconnect I'm calling hcitool con and parsing the response - which is
> again a bit manual.  Please see below for my current 'hack':

I don't think that will work since the input plugin is already
listening in those PSM, in fact I don't think RegisterProfile would
parse the values from the record since you don't seem to be using the
PSM:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54

Btw, why would you want to replace the HID profile? Is that not working?

> ---
>     #listen for incoming client connections
>     #ideally this would be handled by the Bluez 5 profile
>     #but that didn't seem to work
>     def listen(self):
>
>         print("Waiting for connections")
>         self.scontrol=BluetoothSocket(L2CAP)
>         self.sinterrupt=BluetoothSocket(L2CAP)
>
>         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
>         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
>         #Start listening on the server sockets
>         self.scontrol.listen(1) # Limit of 1 connection
>         self.sinterrupt.listen(1)
>
>         self.ccontrol,cinfo = self.scontrol.accept()
>         self.controlClientMac = cinfo[0]
>         self.controlClientPsm = cinfo[1]
>         print ('control is ' + self.controlClientMac + " " +
> str(self.controlClientPsm))
>
>         self.cinterrupt, cinfo = self.sinterrupt.accept()
>         self.interruptClientMac = cinfo[0]
>         self.interruptClientPsm = cinfo[1]
>         print ('interrupt is ' + self.interruptClientMac + " " +
> str(self.interruptClientPsm))
>
>         thread.start_new_thread(self.check_connection, ())
>
>     def check_connection(self):
>         halt = False
>         while not halt:
>             stdoutdata = subprocess.check_output(["hcitool", "con"])
>
>             if self.controlClientMac in stdoutdata.split():
>                 time.sleep(0.1)
>             else:
>                 print('got disconnection')
>                 self.scontrol.shutdown(2);
>                 self.sinterrupt.shutdown(2)
>                 halt = True
>         thread.start_new_thread(self.listen, ())
>
>   Obviously this is a very clumsy way of doing it and calling back on
> the profile is the correct way to do it, I just can't work out why the
> profile is not being called.  I'm trying to spy on the dbus comms to
> see if anything is being sent but I can't see any bluez profile
> messages being sent at all.  Thanks for your response and any advice
> is greatly appreciated.
>
> Cheers,
>
> Neil
> On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > Hi Neil,
> > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   I've been running a dbus-monitor and I can't see the interface being
> > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > I've tried listening to that interface and also on the path with
> > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > points up on Stack Overflow for any advice too!
> > >
> > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > >
> > > Cheers,
> > >
> > > Neil
> > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > the device using the following call:
> > > > ---
> > > >     #configure the bluetooth hardware device
> > > >     def init_bt_device(self):
> > > >
> > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > >
> > > >         #set the device class to a barcode scanner and set the name
> > > >         os.system("hciconfig hcio class 0x002560")
> > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > >
> > > >         #make the device discoverable
> > > >         os.system("hciconfig hcio piscan")
> > > >
> >
> > You shouldn't be using hciconfig, instead do the following:
> >
> > The class is automatically set by bluetoothd based on the
> > services/profiles registered and the setting in the main.conf:
> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> >
> > For the name use D-Bus property Alias:
> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> >
> > To make the adapter discoverable use D-Bus property Discoverable:
> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> >
> >
> >
> > > >   Then after that I attempt to setup the profile using the following code:
> > > > ---
> > > >     #set up a bluez profile to advertise device capabilities from a
> > > > loaded service record
> > > >     def init_bluez_profile(self):
> > > >
> > > >         print("Configuring Bluez Profile")
> > > >
> > > >         #setup profile options
> > > >         service_record=self.read_sdp_service_record()
> > > >
> > > >         opts = {
> > > >             "ServiceRecord":service_record,
> > > >             "Role":"server",
> > > >             "RequireAuthentication":False,
> > > >             "RequireAuthorization":False,
> > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > >             "AutoConnect":True
> > > >         }
> > > >
> > > >         #retrieve a proxy for the bluez profile interface
> > > >         bus = dbus.SystemBus()
> > > >         self.manager =
> > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > "org.bluez.ProfileManager1")
> > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > BTKbDevice.UUID, opts)
> > > >         print("Profile registered ")
> > > > ---
> > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > The profile in question is basically the same as the one defined in
> > > > the test-profile as shown below:
> > > > ---
> > > > class BTKbBluezProfile(dbus.service.Object):
> > > >     fd = -1
> > > >
> > > >     @dbus.service.method("org.bluez.Profile1",
> > > >                                     in_signature="", out_signature="")
> > > >     def Release(self):
> > > >             print("Release")
> > > >             mainloop.quit()
> > > >
> > > >     @dbus.service.method("org.bluez.Profile1",
> > > >                                     in_signature="", out_signature="")
> > > >     def Cancel(self):
> > > >             print("Cancel")
> > > >
> > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > out_signature="")
> > > >     def NewConnection(self, path, fd, properties):
> > > >             self.fd = fd.take()
> > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > >             for key in properties.keys():
> > > >                     print ('key ' + key + ' value ' + properties[key])
> > > >                     if key == "Version" or key == "Features":
> > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > >                     else:
> > > >                             print("  %s = %s" % (key, properties[key]))
> > > >
> > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > out_signature="")
> > > >     def RequestDisconnection(self, path):
> > > >             print("RequestDisconnection(%s)" % (path))
> > > >
> > > >             if (self.fd > 0):
> > > >                     os.close(self.fd)
> > > >                     self.fd = -1
> > > >
> > > >     def __init__(self, bus, path):
> > > >             dbus.service.Object.__init__(self, bus, path)
> > > > ---
> > > >   However it seems like the profile is not being registered, or least
> > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > such a basic question but can someone please point me in the right
> > > > direction as to why the profile is either not being registered or the
> > > > callbacks on the profile are not being called.
> >
> > They would be called only when there is a connection to the profile,
> > did you actually connect? If this is something like a serial port the
> > remote should lookup the SDP record and connect to the channel listed
> > there.
> >
> > > >   Thank you very much for reading this far and any and all help is
> > > > most appreciated!
> > > >
> > > > Cheers,
> > > >
> > > > Neil
> > > >
> > > > --
> > > >
> > > > Neil Benn MSc
> > > > Ziath Ltd
> > > > Phone: +44 (0) 1223 855021
> > > > http://www.ziath.com
> > > >
> > > > Please consider the environment before printing this email.
> > >
> > >
> > >
> > > --
> > >
> > > Neil Benn MSc
> > > Ziath Ltd
> > > Phone: +44 (0) 1223 855021
> > > http://www.ziath.com
> > >
> > > Please consider the environment before printing this email.
> > >
> > > Follow us on Facebook, Twitter or LinkedIn
> > >
> > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > intended only for the use of the individual or entity to which it is
> > > addressed, and may contain information that is privileged,
> > > confidential and exempt from disclosure under applicable law. If the
> > > reader of this message is not the intended recipient, or the employee
> > > or agent responsible for delivering the message to the intended
> > > recipient, you are hereby notified that any dissemination,
> > > distribution or copying of this communication is strictly prohibited.
> > > If you have received this communication in error, please notify Ziath
> > > Ltd immediately by email at info@ziath.com. Thank you.
> >
> >
> >
> > --
> > Luiz Augusto von Dentz
>
>
>
> --
>
> Neil Benn MSc
> Ziath Ltd
> Phone: +44 (0) 1223 855021
> http://www.ziath.com
>
> Please consider the environment before printing this email.
>
> Follow us on Facebook, Twitter or LinkedIn
>
> IMPORTANT NOTICE: This message, including any attached documents, is
> intended only for the use of the individual or entity to which it is
> addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law. If the
> reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify Ziath
> Ltd immediately by email at info@ziath.com. Thank you.



-- 
Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-02 11:27       ` Luiz Augusto von Dentz
@ 2018-10-02 12:28         ` Neil Benn
  2018-10-02 12:47           ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Benn @ 2018-10-02 12:28 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello,

  Thanks for that please see inline below:


On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
>
> Hi Neil,
> On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   Thanks for that; I'll change the config file for this and for the
> > name can that be in the main.conf file?  The same for the
> > discoverable; set the timeout to zero - there is no security needed
> > for this device at all.  Can this all be done with the conf file?
> >
> >   On the connection; yes it connects.  This is a HID device connecting
> > via L2CAP with the interrupt on 19 and the control on 17 and the
> > windows PC correctly connects to the device, queries the service
> > record, identifies it as a HID and connects on both the control and
> > interrupt psm ports but none of the dbus methods are being called.  At
> > the moment I am using the pybluez library with the BluetoothSocket and
> > calling listen and accept which is a bit 'manual'.  To detect a
> > disconnect I'm calling hcitool con and parsing the response - which is
> > again a bit manual.  Please see below for my current 'hack':
>
> I don't think that will work since the input plugin is already
> listening in those PSM,

It does connect and work but it doesn't register the profile.  If I
don't register the profile the default name in the config is used
>
> in fact I don't think RegisterProfile would
> parse the values from the record since you don't seem to be using the
> PSM:
>
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54


The PSM is defined in the service record
>
>
>
> Btw, why would you want to replace the HID profile? Is that not working?

I'm using an sdp profile provided in some sample code I found, is
there a default one that is supported?  Is that default one selected
when I pick my uuid?

  If so then I think it has been overcomplicated by this sdp profile?
How do I use the default in-built profile - is it just the uuid?
On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Neil,
> On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   Thanks for that; I'll change the config file for this and for the
> > name can that be in the main.conf file?  The same for the
> > discoverable; set the timeout to zero - there is no security needed
> > for this device at all.  Can this all be done with the conf file?
> >
> >   On the connection; yes it connects.  This is a HID device connecting
> > via L2CAP with the interrupt on 19 and the control on 17 and the
> > windows PC correctly connects to the device, queries the service
> > record, identifies it as a HID and connects on both the control and
> > interrupt psm ports but none of the dbus methods are being called.  At
> > the moment I am using the pybluez library with the BluetoothSocket and
> > calling listen and accept which is a bit 'manual'.  To detect a
> > disconnect I'm calling hcitool con and parsing the response - which is
> > again a bit manual.  Please see below for my current 'hack':
>
> I don't think that will work since the input plugin is already
> listening in those PSM, in fact I don't think RegisterProfile would
> parse the values from the record since you don't seem to be using the
> PSM:
>
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
>
> Btw, why would you want to replace the HID profile? Is that not working?
>
> > ---
> >     #listen for incoming client connections
> >     #ideally this would be handled by the Bluez 5 profile
> >     #but that didn't seem to work
> >     def listen(self):
> >
> >         print("Waiting for connections")
> >         self.scontrol=BluetoothSocket(L2CAP)
> >         self.sinterrupt=BluetoothSocket(L2CAP)
> >
> >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> >         #Start listening on the server sockets
> >         self.scontrol.listen(1) # Limit of 1 connection
> >         self.sinterrupt.listen(1)
> >
> >         self.ccontrol,cinfo = self.scontrol.accept()
> >         self.controlClientMac = cinfo[0]
> >         self.controlClientPsm = cinfo[1]
> >         print ('control is ' + self.controlClientMac + " " +
> > str(self.controlClientPsm))
> >
> >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> >         self.interruptClientMac = cinfo[0]
> >         self.interruptClientPsm = cinfo[1]
> >         print ('interrupt is ' + self.interruptClientMac + " " +
> > str(self.interruptClientPsm))
> >
> >         thread.start_new_thread(self.check_connection, ())
> >
> >     def check_connection(self):
> >         halt = False
> >         while not halt:
> >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> >
> >             if self.controlClientMac in stdoutdata.split():
> >                 time.sleep(0.1)
> >             else:
> >                 print('got disconnection')
> >                 self.scontrol.shutdown(2);
> >                 self.sinterrupt.shutdown(2)
> >                 halt = True
> >         thread.start_new_thread(self.listen, ())
> >
> >   Obviously this is a very clumsy way of doing it and calling back on
> > the profile is the correct way to do it, I just can't work out why the
> > profile is not being called.  I'm trying to spy on the dbus comms to
> > see if anything is being sent but I can't see any bluez profile
> > messages being sent at all.  Thanks for your response and any advice
> > is greatly appreciated.
> >
> > Cheers,
> >
> > Neil
> > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Neil,
> > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > I've tried listening to that interface and also on the path with
> > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > points up on Stack Overflow for any advice too!
> > > >
> > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > >
> > > > Cheers,
> > > >
> > > > Neil
> > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > the device using the following call:
> > > > > ---
> > > > >     #configure the bluetooth hardware device
> > > > >     def init_bt_device(self):
> > > > >
> > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > >
> > > > >         #set the device class to a barcode scanner and set the name
> > > > >         os.system("hciconfig hcio class 0x002560")
> > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > >
> > > > >         #make the device discoverable
> > > > >         os.system("hciconfig hcio piscan")
> > > > >
> > >
> > > You shouldn't be using hciconfig, instead do the following:
> > >
> > > The class is automatically set by bluetoothd based on the
> > > services/profiles registered and the setting in the main.conf:
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > >
> > > For the name use D-Bus property Alias:
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > >
> > > To make the adapter discoverable use D-Bus property Discoverable:
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > >
> > >
> > >
> > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > ---
> > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > loaded service record
> > > > >     def init_bluez_profile(self):
> > > > >
> > > > >         print("Configuring Bluez Profile")
> > > > >
> > > > >         #setup profile options
> > > > >         service_record=self.read_sdp_service_record()
> > > > >
> > > > >         opts = {
> > > > >             "ServiceRecord":service_record,
> > > > >             "Role":"server",
> > > > >             "RequireAuthentication":False,
> > > > >             "RequireAuthorization":False,
> > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > >             "AutoConnect":True
> > > > >         }
> > > > >
> > > > >         #retrieve a proxy for the bluez profile interface
> > > > >         bus = dbus.SystemBus()
> > > > >         self.manager =
> > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > "org.bluez.ProfileManager1")
> > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > BTKbDevice.UUID, opts)
> > > > >         print("Profile registered ")
> > > > > ---
> > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > The profile in question is basically the same as the one defined in
> > > > > the test-profile as shown below:
> > > > > ---
> > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > >     fd = -1
> > > > >
> > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > >                                     in_signature="", out_signature="")
> > > > >     def Release(self):
> > > > >             print("Release")
> > > > >             mainloop.quit()
> > > > >
> > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > >                                     in_signature="", out_signature="")
> > > > >     def Cancel(self):
> > > > >             print("Cancel")
> > > > >
> > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > out_signature="")
> > > > >     def NewConnection(self, path, fd, properties):
> > > > >             self.fd = fd.take()
> > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > >             for key in properties.keys():
> > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > >                     if key == "Version" or key == "Features":
> > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > >                     else:
> > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > >
> > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > out_signature="")
> > > > >     def RequestDisconnection(self, path):
> > > > >             print("RequestDisconnection(%s)" % (path))
> > > > >
> > > > >             if (self.fd > 0):
> > > > >                     os.close(self.fd)
> > > > >                     self.fd = -1
> > > > >
> > > > >     def __init__(self, bus, path):
> > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > ---
> > > > >   However it seems like the profile is not being registered, or least
> > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > such a basic question but can someone please point me in the right
> > > > > direction as to why the profile is either not being registered or the
> > > > > callbacks on the profile are not being called.
> > >
> > > They would be called only when there is a connection to the profile,
> > > did you actually connect? If this is something like a serial port the
> > > remote should lookup the SDP record and connect to the channel listed
> > > there.
> > >
> > > > >   Thank you very much for reading this far and any and all help is
> > > > > most appreciated!
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Neil
> > > > >
> > > > > --
> > > > >
> > > > > Neil Benn MSc
> > > > > Ziath Ltd
> > > > > Phone: +44 (0) 1223 855021
> > > > > http://www.ziath.com
> > > > >
> > > > > Please consider the environment before printing this email.
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Neil Benn MSc
> > > > Ziath Ltd
> > > > Phone: +44 (0) 1223 855021
> > > > http://www.ziath.com
> > > >
> > > > Please consider the environment before printing this email.
> > > >
> > > > Follow us on Facebook, Twitter or LinkedIn
> > > >
> > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > intended only for the use of the individual or entity to which it is
> > > > addressed, and may contain information that is privileged,
> > > > confidential and exempt from disclosure under applicable law. If the
> > > > reader of this message is not the intended recipient, or the employee
> > > > or agent responsible for delivering the message to the intended
> > > > recipient, you are hereby notified that any dissemination,
> > > > distribution or copying of this communication is strictly prohibited.
> > > > If you have received this communication in error, please notify Ziath
> > > > Ltd immediately by email at info@ziath.com. Thank you.
> > >
> > >
> > >
> > > --
> > > Luiz Augusto von Dentz
> >
> >
> >
> > --
> >
> > Neil Benn MSc
> > Ziath Ltd
> > Phone: +44 (0) 1223 855021
> > http://www.ziath.com
> >
> > Please consider the environment before printing this email.
> >
> > Follow us on Facebook, Twitter or LinkedIn
> >
> > IMPORTANT NOTICE: This message, including any attached documents, is
> > intended only for the use of the individual or entity to which it is
> > addressed, and may contain information that is privileged,
> > confidential and exempt from disclosure under applicable law. If the
> > reader of this message is not the intended recipient, or the employee
> > or agent responsible for delivering the message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly prohibited.
> > If you have received this communication in error, please notify Ziath
> > Ltd immediately by email at info@ziath.com. Thank you.
>
>
>
> --
> Luiz Augusto von Dentz



-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

* Re: Registering a profile
  2018-10-02 12:28         ` Neil Benn
@ 2018-10-02 12:47           ` Luiz Augusto von Dentz
  2018-10-02 14:57             ` Barry Byford
  0 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02 12:47 UTC (permalink / raw)
  To: neil.benn; +Cc: linux-bluetooth

Hi Neil,
On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
>
> Hello,
>
>   Thanks for that please see inline below:
>
>
> On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> >
> > Hi Neil,
> > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   Thanks for that; I'll change the config file for this and for the
> > > name can that be in the main.conf file?  The same for the
> > > discoverable; set the timeout to zero - there is no security needed
> > > for this device at all.  Can this all be done with the conf file?
> > >
> > >   On the connection; yes it connects.  This is a HID device connecting
> > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > windows PC correctly connects to the device, queries the service
> > > record, identifies it as a HID and connects on both the control and
> > > interrupt psm ports but none of the dbus methods are being called.  At
> > > the moment I am using the pybluez library with the BluetoothSocket and
> > > calling listen and accept which is a bit 'manual'.  To detect a
> > > disconnect I'm calling hcitool con and parsing the response - which is
> > > again a bit manual.  Please see below for my current 'hack':
> >
> > I don't think that will work since the input plugin is already
> > listening in those PSM,
>
> It does connect and work but it doesn't register the profile.  If I
> don't register the profile the default name in the config is used
> >
> > in fact I don't think RegisterProfile would
> > parse the values from the record since you don't seem to be using the
> > PSM:
> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
>
>
> The PSM is defined in the service record
> >
> >
> >
> > Btw, why would you want to replace the HID profile? Is that not working?
>
> I'm using an sdp profile provided in some sample code I found, is
> there a default one that is supported?  Is that default one selected
> when I pick my uuid?

You are not suppose to use existing UUIDs that the daemon already
registers, the fact that you are able to register it without cause a
problem might be a bug and we should probably check if the UUID is
already registered and fail if it does.

The HID profile is implementation is under profiles/input/, it
actually hooks with kernel HID drivers.

If you just want to test it you should probably have a look at
test-profile in python:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile

>   If so then I think it has been overcomplicated by this sdp profile?
> How do I use the default in-built profile - is it just the uuid?
> On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > Hi Neil,
> > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   Thanks for that; I'll change the config file for this and for the
> > > name can that be in the main.conf file?  The same for the
> > > discoverable; set the timeout to zero - there is no security needed
> > > for this device at all.  Can this all be done with the conf file?
> > >
> > >   On the connection; yes it connects.  This is a HID device connecting
> > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > windows PC correctly connects to the device, queries the service
> > > record, identifies it as a HID and connects on both the control and
> > > interrupt psm ports but none of the dbus methods are being called.  At
> > > the moment I am using the pybluez library with the BluetoothSocket and
> > > calling listen and accept which is a bit 'manual'.  To detect a
> > > disconnect I'm calling hcitool con and parsing the response - which is
> > > again a bit manual.  Please see below for my current 'hack':
> >
> > I don't think that will work since the input plugin is already
> > listening in those PSM, in fact I don't think RegisterProfile would
> > parse the values from the record since you don't seem to be using the
> > PSM:
> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> >
> > Btw, why would you want to replace the HID profile? Is that not working?
> >
> > > ---
> > >     #listen for incoming client connections
> > >     #ideally this would be handled by the Bluez 5 profile
> > >     #but that didn't seem to work
> > >     def listen(self):
> > >
> > >         print("Waiting for connections")
> > >         self.scontrol=BluetoothSocket(L2CAP)
> > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > >
> > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > >         #Start listening on the server sockets
> > >         self.scontrol.listen(1) # Limit of 1 connection
> > >         self.sinterrupt.listen(1)
> > >
> > >         self.ccontrol,cinfo = self.scontrol.accept()
> > >         self.controlClientMac = cinfo[0]
> > >         self.controlClientPsm = cinfo[1]
> > >         print ('control is ' + self.controlClientMac + " " +
> > > str(self.controlClientPsm))
> > >
> > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > >         self.interruptClientMac = cinfo[0]
> > >         self.interruptClientPsm = cinfo[1]
> > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > str(self.interruptClientPsm))
> > >
> > >         thread.start_new_thread(self.check_connection, ())
> > >
> > >     def check_connection(self):
> > >         halt = False
> > >         while not halt:
> > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > >
> > >             if self.controlClientMac in stdoutdata.split():
> > >                 time.sleep(0.1)
> > >             else:
> > >                 print('got disconnection')
> > >                 self.scontrol.shutdown(2);
> > >                 self.sinterrupt.shutdown(2)
> > >                 halt = True
> > >         thread.start_new_thread(self.listen, ())
> > >
> > >   Obviously this is a very clumsy way of doing it and calling back on
> > > the profile is the correct way to do it, I just can't work out why the
> > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > see if anything is being sent but I can't see any bluez profile
> > > messages being sent at all.  Thanks for your response and any advice
> > > is greatly appreciated.
> > >
> > > Cheers,
> > >
> > > Neil
> > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Neil,
> > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > I've tried listening to that interface and also on the path with
> > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > points up on Stack Overflow for any advice too!
> > > > >
> > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Neil
> > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > >
> > > > > > Hello,
> > > > > >
> > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > the device using the following call:
> > > > > > ---
> > > > > >     #configure the bluetooth hardware device
> > > > > >     def init_bt_device(self):
> > > > > >
> > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > >
> > > > > >         #set the device class to a barcode scanner and set the name
> > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > >
> > > > > >         #make the device discoverable
> > > > > >         os.system("hciconfig hcio piscan")
> > > > > >
> > > >
> > > > You shouldn't be using hciconfig, instead do the following:
> > > >
> > > > The class is automatically set by bluetoothd based on the
> > > > services/profiles registered and the setting in the main.conf:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > >
> > > > For the name use D-Bus property Alias:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > >
> > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > >
> > > >
> > > >
> > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > ---
> > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > loaded service record
> > > > > >     def init_bluez_profile(self):
> > > > > >
> > > > > >         print("Configuring Bluez Profile")
> > > > > >
> > > > > >         #setup profile options
> > > > > >         service_record=self.read_sdp_service_record()
> > > > > >
> > > > > >         opts = {
> > > > > >             "ServiceRecord":service_record,
> > > > > >             "Role":"server",
> > > > > >             "RequireAuthentication":False,
> > > > > >             "RequireAuthorization":False,
> > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > >             "AutoConnect":True
> > > > > >         }
> > > > > >
> > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > >         bus = dbus.SystemBus()
> > > > > >         self.manager =
> > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > "org.bluez.ProfileManager1")
> > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > BTKbDevice.UUID, opts)
> > > > > >         print("Profile registered ")
> > > > > > ---
> > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > The profile in question is basically the same as the one defined in
> > > > > > the test-profile as shown below:
> > > > > > ---
> > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > >     fd = -1
> > > > > >
> > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > >                                     in_signature="", out_signature="")
> > > > > >     def Release(self):
> > > > > >             print("Release")
> > > > > >             mainloop.quit()
> > > > > >
> > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > >                                     in_signature="", out_signature="")
> > > > > >     def Cancel(self):
> > > > > >             print("Cancel")
> > > > > >
> > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > out_signature="")
> > > > > >     def NewConnection(self, path, fd, properties):
> > > > > >             self.fd = fd.take()
> > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > >             for key in properties.keys():
> > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > >                     if key == "Version" or key == "Features":
> > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > >                     else:
> > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > >
> > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > out_signature="")
> > > > > >     def RequestDisconnection(self, path):
> > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > >
> > > > > >             if (self.fd > 0):
> > > > > >                     os.close(self.fd)
> > > > > >                     self.fd = -1
> > > > > >
> > > > > >     def __init__(self, bus, path):
> > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > ---
> > > > > >   However it seems like the profile is not being registered, or least
> > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > such a basic question but can someone please point me in the right
> > > > > > direction as to why the profile is either not being registered or the
> > > > > > callbacks on the profile are not being called.
> > > >
> > > > They would be called only when there is a connection to the profile,
> > > > did you actually connect? If this is something like a serial port the
> > > > remote should lookup the SDP record and connect to the channel listed
> > > > there.
> > > >
> > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > most appreciated!
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > Neil
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Neil Benn MSc
> > > > > > Ziath Ltd
> > > > > > Phone: +44 (0) 1223 855021
> > > > > > http://www.ziath.com
> > > > > >
> > > > > > Please consider the environment before printing this email.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Neil Benn MSc
> > > > > Ziath Ltd
> > > > > Phone: +44 (0) 1223 855021
> > > > > http://www.ziath.com
> > > > >
> > > > > Please consider the environment before printing this email.
> > > > >
> > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > >
> > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > intended only for the use of the individual or entity to which it is
> > > > > addressed, and may contain information that is privileged,
> > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > reader of this message is not the intended recipient, or the employee
> > > > > or agent responsible for delivering the message to the intended
> > > > > recipient, you are hereby notified that any dissemination,
> > > > > distribution or copying of this communication is strictly prohibited.
> > > > > If you have received this communication in error, please notify Ziath
> > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > >
> > > >
> > > >
> > > > --
> > > > Luiz Augusto von Dentz
> > >
> > >
> > >
> > > --
> > >
> > > Neil Benn MSc
> > > Ziath Ltd
> > > Phone: +44 (0) 1223 855021
> > > http://www.ziath.com
> > >
> > > Please consider the environment before printing this email.
> > >
> > > Follow us on Facebook, Twitter or LinkedIn
> > >
> > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > intended only for the use of the individual or entity to which it is
> > > addressed, and may contain information that is privileged,
> > > confidential and exempt from disclosure under applicable law. If the
> > > reader of this message is not the intended recipient, or the employee
> > > or agent responsible for delivering the message to the intended
> > > recipient, you are hereby notified that any dissemination,
> > > distribution or copying of this communication is strictly prohibited.
> > > If you have received this communication in error, please notify Ziath
> > > Ltd immediately by email at info@ziath.com. Thank you.
> >
> >
> >
> > --
> > Luiz Augusto von Dentz
>
>
>
> --
>
> Neil Benn MSc
> Ziath Ltd
> Phone: +44 (0) 1223 855021
> http://www.ziath.com
>
> Please consider the environment before printing this email.
>
> Follow us on Facebook, Twitter or LinkedIn
>
> IMPORTANT NOTICE: This message, including any attached documents, is
> intended only for the use of the individual or entity to which it is
> addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law. If the
> reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify Ziath
> Ltd immediately by email at info@ziath.com. Thank you.



-- 
Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-02 12:47           ` Luiz Augusto von Dentz
@ 2018-10-02 14:57             ` Barry Byford
  2018-10-02 18:31               ` Neil Benn
  2018-10-03 10:35               ` Luiz Augusto von Dentz
  0 siblings, 2 replies; 15+ messages in thread
From: Barry Byford @ 2018-10-02 14:57 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: neil.benn, Bluez mailing list

Hi Luiz,

On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Neil,
> On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   Thanks for that please see inline below:
> >
> >
> > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Neil,
> > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > >   Thanks for that; I'll change the config file for this and for the
> > > > name can that be in the main.conf file?  The same for the
> > > > discoverable; set the timeout to zero - there is no security needed
> > > > for this device at all.  Can this all be done with the conf file?
> > > >
> > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > windows PC correctly connects to the device, queries the service
> > > > record, identifies it as a HID and connects on both the control and
> > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > again a bit manual.  Please see below for my current 'hack':
> > >
> > > I don't think that will work since the input plugin is already
> > > listening in those PSM,
> >
> > It does connect and work but it doesn't register the profile.  If I
> > don't register the profile the default name in the config is used
> > >
> > > in fact I don't think RegisterProfile would
> > > parse the values from the record since you don't seem to be using the
> > > PSM:
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> >
> >
> > The PSM is defined in the service record
> > >
> > >
> > >
> > > Btw, why would you want to replace the HID profile? Is that not working?
> >
> > I'm using an sdp profile provided in some sample code I found, is
> > there a default one that is supported?  Is that default one selected
> > when I pick my uuid?
>
> You are not suppose to use existing UUIDs that the daemon already
> registers, the fact that you are able to register it without cause a
> problem might be a bug and we should probably check if the UUID is
> already registered and fail if it does.
>
> The HID profile is implementation is under profiles/input/, it
> actually hooks with kernel HID drivers.
>
> If you just want to test it you should probably have a look at
> test-profile in python:

Do you have any example invocations of test-profile for common profiles?

It can be difficult to know where the issue is if you are not
confident with what settings should work.

>
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
>
> >   If so then I think it has been overcomplicated by this sdp profile?
> > How do I use the default in-built profile - is it just the uuid?
> > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Neil,
> > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > >   Thanks for that; I'll change the config file for this and for the
> > > > name can that be in the main.conf file?  The same for the
> > > > discoverable; set the timeout to zero - there is no security needed
> > > > for this device at all.  Can this all be done with the conf file?
> > > >
> > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > windows PC correctly connects to the device, queries the service
> > > > record, identifies it as a HID and connects on both the control and
> > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > again a bit manual.  Please see below for my current 'hack':
> > >
> > > I don't think that will work since the input plugin is already
> > > listening in those PSM, in fact I don't think RegisterProfile would
> > > parse the values from the record since you don't seem to be using the
> > > PSM:
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > >
> > > Btw, why would you want to replace the HID profile? Is that not working?
> > >
> > > > ---
> > > >     #listen for incoming client connections
> > > >     #ideally this would be handled by the Bluez 5 profile
> > > >     #but that didn't seem to work
> > > >     def listen(self):
> > > >
> > > >         print("Waiting for connections")
> > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > >
> > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > >         #Start listening on the server sockets
> > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > >         self.sinterrupt.listen(1)
> > > >
> > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > >         self.controlClientMac = cinfo[0]
> > > >         self.controlClientPsm = cinfo[1]
> > > >         print ('control is ' + self.controlClientMac + " " +
> > > > str(self.controlClientPsm))
> > > >
> > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > >         self.interruptClientMac = cinfo[0]
> > > >         self.interruptClientPsm = cinfo[1]
> > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > str(self.interruptClientPsm))
> > > >
> > > >         thread.start_new_thread(self.check_connection, ())
> > > >
> > > >     def check_connection(self):
> > > >         halt = False
> > > >         while not halt:
> > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > >
> > > >             if self.controlClientMac in stdoutdata.split():
> > > >                 time.sleep(0.1)
> > > >             else:
> > > >                 print('got disconnection')
> > > >                 self.scontrol.shutdown(2);
> > > >                 self.sinterrupt.shutdown(2)
> > > >                 halt = True
> > > >         thread.start_new_thread(self.listen, ())
> > > >
> > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > the profile is the correct way to do it, I just can't work out why the
> > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > see if anything is being sent but I can't see any bluez profile
> > > > messages being sent at all.  Thanks for your response and any advice
> > > > is greatly appreciated.
> > > >
> > > > Cheers,
> > > >
> > > > Neil
> > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > <luiz.dentz@gmail.com> wrote:
> > > > >
> > > > > Hi Neil,
> > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > >
> > > > > > Hello,
> > > > > >
> > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > I've tried listening to that interface and also on the path with
> > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > points up on Stack Overflow for any advice too!
> > > > > >
> > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > Neil
> > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > the device using the following call:
> > > > > > > ---
> > > > > > >     #configure the bluetooth hardware device
> > > > > > >     def init_bt_device(self):
> > > > > > >
> > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > >
> > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > >
> > > > > > >         #make the device discoverable
> > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > >
> > > > >
> > > > > You shouldn't be using hciconfig, instead do the following:
> > > > >
> > > > > The class is automatically set by bluetoothd based on the
> > > > > services/profiles registered and the setting in the main.conf:
> > > > >
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > >
> > > > > For the name use D-Bus property Alias:
> > > > >
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > >
> > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > >
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > >
> > > > >
> > > > >
> > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > ---
> > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > loaded service record
> > > > > > >     def init_bluez_profile(self):
> > > > > > >
> > > > > > >         print("Configuring Bluez Profile")
> > > > > > >
> > > > > > >         #setup profile options
> > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > >
> > > > > > >         opts = {
> > > > > > >             "ServiceRecord":service_record,
> > > > > > >             "Role":"server",
> > > > > > >             "RequireAuthentication":False,
> > > > > > >             "RequireAuthorization":False,
> > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > >             "AutoConnect":True
> > > > > > >         }
> > > > > > >
> > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > >         bus = dbus.SystemBus()
> > > > > > >         self.manager =
> > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > "org.bluez.ProfileManager1")
> > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > BTKbDevice.UUID, opts)
> > > > > > >         print("Profile registered ")
> > > > > > > ---
> > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > the test-profile as shown below:
> > > > > > > ---
> > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > >     fd = -1
> > > > > > >
> > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > >                                     in_signature="", out_signature="")
> > > > > > >     def Release(self):
> > > > > > >             print("Release")
> > > > > > >             mainloop.quit()
> > > > > > >
> > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > >                                     in_signature="", out_signature="")
> > > > > > >     def Cancel(self):
> > > > > > >             print("Cancel")
> > > > > > >
> > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > out_signature="")
> > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > >             self.fd = fd.take()
> > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > >             for key in properties.keys():
> > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > >                     if key == "Version" or key == "Features":
> > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > >                     else:
> > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > >
> > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > out_signature="")
> > > > > > >     def RequestDisconnection(self, path):
> > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > >
> > > > > > >             if (self.fd > 0):
> > > > > > >                     os.close(self.fd)
> > > > > > >                     self.fd = -1
> > > > > > >
> > > > > > >     def __init__(self, bus, path):
> > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > ---
> > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > such a basic question but can someone please point me in the right
> > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > callbacks on the profile are not being called.
> > > > >
> > > > > They would be called only when there is a connection to the profile,
> > > > > did you actually connect? If this is something like a serial port the
> > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > there.
> > > > >
> > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > most appreciated!
> > > > > > >
> > > > > > > Cheers,
> > > > > > >
> > > > > > > Neil
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Neil Benn MSc
> > > > > > > Ziath Ltd
> > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > http://www.ziath.com
> > > > > > >
> > > > > > > Please consider the environment before printing this email.
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Neil Benn MSc
> > > > > > Ziath Ltd
> > > > > > Phone: +44 (0) 1223 855021
> > > > > > http://www.ziath.com
> > > > > >
> > > > > > Please consider the environment before printing this email.
> > > > > >
> > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > >
> > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > intended only for the use of the individual or entity to which it is
> > > > > > addressed, and may contain information that is privileged,
> > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > or agent responsible for delivering the message to the intended
> > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > If you have received this communication in error, please notify Ziath
> > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Luiz Augusto von Dentz
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Neil Benn MSc
> > > > Ziath Ltd
> > > > Phone: +44 (0) 1223 855021
> > > > http://www.ziath.com
> > > >
> > > > Please consider the environment before printing this email.
> > > >
> > > > Follow us on Facebook, Twitter or LinkedIn
> > > >
> > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > intended only for the use of the individual or entity to which it is
> > > > addressed, and may contain information that is privileged,
> > > > confidential and exempt from disclosure under applicable law. If the
> > > > reader of this message is not the intended recipient, or the employee
> > > > or agent responsible for delivering the message to the intended
> > > > recipient, you are hereby notified that any dissemination,
> > > > distribution or copying of this communication is strictly prohibited.
> > > > If you have received this communication in error, please notify Ziath
> > > > Ltd immediately by email at info@ziath.com. Thank you.
> > >
> > >
> > >
> > > --
> > > Luiz Augusto von Dentz
> >
> >
> >
> > --
> >
> > Neil Benn MSc
> > Ziath Ltd
> > Phone: +44 (0) 1223 855021
> > http://www.ziath.com
> >
> > Please consider the environment before printing this email.
> >
> > Follow us on Facebook, Twitter or LinkedIn
> >
> > IMPORTANT NOTICE: This message, including any attached documents, is
> > intended only for the use of the individual or entity to which it is
> > addressed, and may contain information that is privileged,
> > confidential and exempt from disclosure under applicable law. If the
> > reader of this message is not the intended recipient, or the employee
> > or agent responsible for delivering the message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly prohibited.
> > If you have received this communication in error, please notify Ziath
> > Ltd immediately by email at info@ziath.com. Thank you.
>
>
>
> --
> Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-02 14:57             ` Barry Byford
@ 2018-10-02 18:31               ` Neil Benn
  2018-10-03 10:35               ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 15+ messages in thread
From: Neil Benn @ 2018-10-02 18:31 UTC (permalink / raw)
  To: 31baz66; +Cc: Luiz Augusto von Dentz, linux-bluetooth

Hello,

  Thanks for all the advice; sorry I didn't get back earlier - been
stuck on other jobs covering for people off sick.  I've not got the
main.conf of:

Name = DataPaqWalk
Class = 0x002650
DiscoverableTimeout = 0
PairableTimeout = 0
AutoConnectTimeout = 60
ReconnectAttempts=7
ReconnectIntervals=1,2,4,8,16,32,64
AutoEnable=true

  When I bring up bluetoothd in debug I can see that the name is now
picked up from the conf file:

bluetoothd[579]: src/adapter.c:btd_adapter_new() Major class: 6
bluetoothd[579]: src/adapter.c:btd_adapter_new() Minor class: 20
...
bluetoothd[579]: src/adapter.c:local_name_changed_callback() Name: DataPaqWalk
bluetoothd[579]: src/adapter.c:local_name_changed_callback() Short name:
bluetoothd[579]: src/adapter.c:local_name_changed_callback() Current
alias: DataPaqWalk

  The code is now _much_ simpler:

---
class BTKbDevice():

    #define some constants
    P_CTRL =17  #Service port - must match port configured in SDP record
    P_INTR =19  #Interrrupt port - must match port configured in SDP record
    PROFILE_DBUS_PATH="/bluez/yaptb/btkb_profile" #dbus path of  the
bluez profile we will create
    UUID="00001124-0000-1000-8000-00805f9b34fb"


    def __init__(self):

        print("Setting up BT device")
        self.init_bluez_profile()


    #set up a bluez profile to advertise device capabilities from a
loaded service record
    def init_bluez_profile(self):
        bus = dbus.SystemBus()

        print ("setting adapter to discoverable")
        self.adapter =
dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
"org.bluez.Adapter1")
        self.adapter.Discoverable =True

        print("Configuring Bluez Profile")

        opts = {
            "Role":"server",
            "AutoConnect":True
        }

        self.manager =
dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
"org.bluez.ProfileManager1")
        self.profile = BTKbBluezProfile(bus,
BTKbDevice.PROFILE_DBUS_PATH)#BTKbDevice.PROFILE_DBUS_PATH)
        self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
BTKbDevice.UUID, opts)
        print("Profile registered ")

class BTKbBluezProfile(dbus.service.Object):
    fd = -1

    @dbus.service.method("org.bluez.Profile1",
                                    in_signature="", out_signature="")
    def Release(self):
            print("Release")
            mainloop.quit()

    @dbus.service.method("org.bluez.Profile1",
                                    in_signature="", out_signature="")
    def Cancel(self):
            print("Cancel")

    @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
out_signature="")
    def NewConnection(self, path, fd, properties):
            self.fd = fd.take()
            print("NewConnection(%s, %d)" % (path, self.fd))
            for key in properties.keys():
                    print ('key ' + key + ' value ' + properties[key])
                    if key == "Version" or key == "Features":
                            print("  %s = 0x%04x" % (key, properties[key]))
                    else:
                            print("  %s = %s" % (key, properties[key]))



    @dbus.service.method("org.bluez.Profile1", in_signature="o",
out_signature="")
    def RequestDisconnection(self, path):
            print("RequestDisconnection(%s)" % (path))

            if (self.fd > 0):
                    os.close(self.fd)
                    self.fd = -1

    def __init__(self, bus, path):
            dbus.service.Object.__init__(self, bus, path)
---

  There is a bit more code but this is the main part and it executes
and I can see activity on the bluetoothd log:

bluetoothd[579]: src/profile.c:register_profile() sender :1.11
bluetoothd[579]: src/profile.c:create_ext() Created
":1.11/bluez/yaptb/btkb_profile/00001124-0000-1000-8000-00805f9b34fb"
bluetoothd[579]: src/profile.c:ext_adapter_probe()
":1.11/bluez/yaptb/btkb_profile/00001124-0000-1000-8000-00805f9b34fb"
probed
bluetoothd[579]: src/adapter.c:adapter_service_add() /org/bluez/hci0
bluetoothd[579]: src/sdpd-service.c:add_record_to_server() Adding
record with handle 0x10003
bluetoothd[579]: src/sdpd-service.c:add_record_to_server() Record
pattern UUID 00000100-0000-1000-8000-00805f9
bluetoothd[579]: src/sdpd-service.c:add_record_to_server() Record
pattern UUID 00001002-0000-1000-8000-00805f9
bluetoothd[579]: src/sdpd-service.c:add_record_to_server() Record
pattern UUID 00001124-0000-1000-8000-00805f9
bluetoothd[579]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
bluetoothd[579]: src/adapter.c:add_uuid() sending add uuid command for index 0

  However but when I attempt to connect from the Windows PC it cannot
find the Raspberry Pi0W so it is no longer discoverable - I'm missing
something here; do you have any idea what it is?  Note that when I've
got this done I'm going to write it up and publish it so that should
help others after me.

  Thanks for your advice.

Cheers,

Neil
On Tue, 2 Oct 2018 at 15:57, Barry Byford <31baz66@gmail.com> wrote:
>
> Hi Luiz,
>
> On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > Hi Neil,
> > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   Thanks for that please see inline below:
> > >
> > >
> > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Neil,
> > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > name can that be in the main.conf file?  The same for the
> > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > for this device at all.  Can this all be done with the conf file?
> > > > >
> > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > windows PC correctly connects to the device, queries the service
> > > > > record, identifies it as a HID and connects on both the control and
> > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > again a bit manual.  Please see below for my current 'hack':
> > > >
> > > > I don't think that will work since the input plugin is already
> > > > listening in those PSM,
> > >
> > > It does connect and work but it doesn't register the profile.  If I
> > > don't register the profile the default name in the config is used
> > > >
> > > > in fact I don't think RegisterProfile would
> > > > parse the values from the record since you don't seem to be using the
> > > > PSM:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > >
> > >
> > > The PSM is defined in the service record
> > > >
> > > >
> > > >
> > > > Btw, why would you want to replace the HID profile? Is that not working?
> > >
> > > I'm using an sdp profile provided in some sample code I found, is
> > > there a default one that is supported?  Is that default one selected
> > > when I pick my uuid?
> >
> > You are not suppose to use existing UUIDs that the daemon already
> > registers, the fact that you are able to register it without cause a
> > problem might be a bug and we should probably check if the UUID is
> > already registered and fail if it does.
> >
> > The HID profile is implementation is under profiles/input/, it
> > actually hooks with kernel HID drivers.
> >
> > If you just want to test it you should probably have a look at
> > test-profile in python:
>
> Do you have any example invocations of test-profile for common profiles?
>
> It can be difficult to know where the issue is if you are not
> confident with what settings should work.
>
> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> >
> > >   If so then I think it has been overcomplicated by this sdp profile?
> > > How do I use the default in-built profile - is it just the uuid?
> > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Neil,
> > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > name can that be in the main.conf file?  The same for the
> > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > for this device at all.  Can this all be done with the conf file?
> > > > >
> > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > windows PC correctly connects to the device, queries the service
> > > > > record, identifies it as a HID and connects on both the control and
> > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > again a bit manual.  Please see below for my current 'hack':
> > > >
> > > > I don't think that will work since the input plugin is already
> > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > parse the values from the record since you don't seem to be using the
> > > > PSM:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > >
> > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > >
> > > > > ---
> > > > >     #listen for incoming client connections
> > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > >     #but that didn't seem to work
> > > > >     def listen(self):
> > > > >
> > > > >         print("Waiting for connections")
> > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > >
> > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > >         #Start listening on the server sockets
> > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > >         self.sinterrupt.listen(1)
> > > > >
> > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > >         self.controlClientMac = cinfo[0]
> > > > >         self.controlClientPsm = cinfo[1]
> > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > str(self.controlClientPsm))
> > > > >
> > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > >         self.interruptClientMac = cinfo[0]
> > > > >         self.interruptClientPsm = cinfo[1]
> > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > str(self.interruptClientPsm))
> > > > >
> > > > >         thread.start_new_thread(self.check_connection, ())
> > > > >
> > > > >     def check_connection(self):
> > > > >         halt = False
> > > > >         while not halt:
> > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > >
> > > > >             if self.controlClientMac in stdoutdata.split():
> > > > >                 time.sleep(0.1)
> > > > >             else:
> > > > >                 print('got disconnection')
> > > > >                 self.scontrol.shutdown(2);
> > > > >                 self.sinterrupt.shutdown(2)
> > > > >                 halt = True
> > > > >         thread.start_new_thread(self.listen, ())
> > > > >
> > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > see if anything is being sent but I can't see any bluez profile
> > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > is greatly appreciated.
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Neil
> > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > <luiz.dentz@gmail.com> wrote:
> > > > > >
> > > > > > Hi Neil,
> > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > points up on Stack Overflow for any advice too!
> > > > > > >
> > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > >
> > > > > > > Cheers,
> > > > > > >
> > > > > > > Neil
> > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > the device using the following call:
> > > > > > > > ---
> > > > > > > >     #configure the bluetooth hardware device
> > > > > > > >     def init_bt_device(self):
> > > > > > > >
> > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > >
> > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > >
> > > > > > > >         #make the device discoverable
> > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > >
> > > > > >
> > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > >
> > > > > > The class is automatically set by bluetoothd based on the
> > > > > > services/profiles registered and the setting in the main.conf:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > >
> > > > > > For the name use D-Bus property Alias:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > >
> > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > >
> > > > > >
> > > > > >
> > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > ---
> > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > loaded service record
> > > > > > > >     def init_bluez_profile(self):
> > > > > > > >
> > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > >
> > > > > > > >         #setup profile options
> > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > >
> > > > > > > >         opts = {
> > > > > > > >             "ServiceRecord":service_record,
> > > > > > > >             "Role":"server",
> > > > > > > >             "RequireAuthentication":False,
> > > > > > > >             "RequireAuthorization":False,
> > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > >             "AutoConnect":True
> > > > > > > >         }
> > > > > > > >
> > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > >         bus = dbus.SystemBus()
> > > > > > > >         self.manager =
> > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > >         print("Profile registered ")
> > > > > > > > ---
> > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > the test-profile as shown below:
> > > > > > > > ---
> > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > >     fd = -1
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > >     def Release(self):
> > > > > > > >             print("Release")
> > > > > > > >             mainloop.quit()
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > >     def Cancel(self):
> > > > > > > >             print("Cancel")
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > out_signature="")
> > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > >             self.fd = fd.take()
> > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > >             for key in properties.keys():
> > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > >                     else:
> > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > out_signature="")
> > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > >
> > > > > > > >             if (self.fd > 0):
> > > > > > > >                     os.close(self.fd)
> > > > > > > >                     self.fd = -1
> > > > > > > >
> > > > > > > >     def __init__(self, bus, path):
> > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > ---
> > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > callbacks on the profile are not being called.
> > > > > >
> > > > > > They would be called only when there is a connection to the profile,
> > > > > > did you actually connect? If this is something like a serial port the
> > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > there.
> > > > > >
> > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > most appreciated!
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > >
> > > > > > > > Neil
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > Neil Benn MSc
> > > > > > > > Ziath Ltd
> > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > http://www.ziath.com
> > > > > > > >
> > > > > > > > Please consider the environment before printing this email.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Neil Benn MSc
> > > > > > > Ziath Ltd
> > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > http://www.ziath.com
> > > > > > >
> > > > > > > Please consider the environment before printing this email.
> > > > > > >
> > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > >
> > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > addressed, and may contain information that is privileged,
> > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Luiz Augusto von Dentz
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Neil Benn MSc
> > > > > Ziath Ltd
> > > > > Phone: +44 (0) 1223 855021
> > > > > http://www.ziath.com
> > > > >
> > > > > Please consider the environment before printing this email.
> > > > >
> > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > >
> > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > intended only for the use of the individual or entity to which it is
> > > > > addressed, and may contain information that is privileged,
> > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > reader of this message is not the intended recipient, or the employee
> > > > > or agent responsible for delivering the message to the intended
> > > > > recipient, you are hereby notified that any dissemination,
> > > > > distribution or copying of this communication is strictly prohibited.
> > > > > If you have received this communication in error, please notify Ziath
> > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > >
> > > >
> > > >
> > > > --
> > > > Luiz Augusto von Dentz
> > >
> > >
> > >
> > > --
> > >
> > > Neil Benn MSc
> > > Ziath Ltd
> > > Phone: +44 (0) 1223 855021
> > > http://www.ziath.com
> > >
> > > Please consider the environment before printing this email.
> > >
> > > Follow us on Facebook, Twitter or LinkedIn
> > >
> > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > intended only for the use of the individual or entity to which it is
> > > addressed, and may contain information that is privileged,
> > > confidential and exempt from disclosure under applicable law. If the
> > > reader of this message is not the intended recipient, or the employee
> > > or agent responsible for delivering the message to the intended
> > > recipient, you are hereby notified that any dissemination,
> > > distribution or copying of this communication is strictly prohibited.
> > > If you have received this communication in error, please notify Ziath
> > > Ltd immediately by email at info@ziath.com. Thank you.
> >
> >
> >
> > --
> > Luiz Augusto von Dentz



-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

* Re: Registering a profile
  2018-10-02 14:57             ` Barry Byford
  2018-10-02 18:31               ` Neil Benn
@ 2018-10-03 10:35               ` Luiz Augusto von Dentz
  2018-10-03 13:49                 ` Neil Benn
  1 sibling, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-03 10:35 UTC (permalink / raw)
  To: Barry Byford; +Cc: neil.benn, linux-bluetooth

Hi Barry,
On Tue, Oct 2, 2018 at 5:57 PM Barry Byford <31baz66@gmail.com> wrote:
>
> Hi Luiz,
>
> On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > Hi Neil,
> > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   Thanks for that please see inline below:
> > >
> > >
> > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Neil,
> > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > name can that be in the main.conf file?  The same for the
> > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > for this device at all.  Can this all be done with the conf file?
> > > > >
> > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > windows PC correctly connects to the device, queries the service
> > > > > record, identifies it as a HID and connects on both the control and
> > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > again a bit manual.  Please see below for my current 'hack':
> > > >
> > > > I don't think that will work since the input plugin is already
> > > > listening in those PSM,
> > >
> > > It does connect and work but it doesn't register the profile.  If I
> > > don't register the profile the default name in the config is used
> > > >
> > > > in fact I don't think RegisterProfile would
> > > > parse the values from the record since you don't seem to be using the
> > > > PSM:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > >
> > >
> > > The PSM is defined in the service record
> > > >
> > > >
> > > >
> > > > Btw, why would you want to replace the HID profile? Is that not working?
> > >
> > > I'm using an sdp profile provided in some sample code I found, is
> > > there a default one that is supported?  Is that default one selected
> > > when I pick my uuid?
> >
> > You are not suppose to use existing UUIDs that the daemon already
> > registers, the fact that you are able to register it without cause a
> > problem might be a bug and we should probably check if the UUID is
> > already registered and fail if it does.
> >
> > The HID profile is implementation is under profiles/input/, it
> > actually hooks with kernel HID drivers.
> >
> > If you just want to test it you should probably have a look at
> > test-profile in python:
>
> Do you have any example invocations of test-profile for common profiles?

test-profile is just a sample, but yes we do have many instances of
common profiles using RegisterProfile:

OBEX Daemon:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/bluetooth.c#n256

Ofono (HFP):
https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/bluez5.c#n104

PulseAudio (HSP):
https://gitlab.freedesktop.org/pulseaudio/pulseaudio/blob/master/src/modules/bluetooth/backend-native.c#L332

> It can be difficult to know where the issue is if you are not
> confident with what settings should work.

Well test-profile is not exactly a library just a convenient sample on
how to use the interface, it was used mostly for testing SPP which is
quite common way to register external profiles. HID is probably a no
go due to reason already stated.

> >
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> >
> > >   If so then I think it has been overcomplicated by this sdp profile?
> > > How do I use the default in-built profile - is it just the uuid?
> > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Neil,
> > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > name can that be in the main.conf file?  The same for the
> > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > for this device at all.  Can this all be done with the conf file?
> > > > >
> > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > windows PC correctly connects to the device, queries the service
> > > > > record, identifies it as a HID and connects on both the control and
> > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > again a bit manual.  Please see below for my current 'hack':
> > > >
> > > > I don't think that will work since the input plugin is already
> > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > parse the values from the record since you don't seem to be using the
> > > > PSM:
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > >
> > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > >
> > > > > ---
> > > > >     #listen for incoming client connections
> > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > >     #but that didn't seem to work
> > > > >     def listen(self):
> > > > >
> > > > >         print("Waiting for connections")
> > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > >
> > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > >         #Start listening on the server sockets
> > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > >         self.sinterrupt.listen(1)
> > > > >
> > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > >         self.controlClientMac = cinfo[0]
> > > > >         self.controlClientPsm = cinfo[1]
> > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > str(self.controlClientPsm))
> > > > >
> > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > >         self.interruptClientMac = cinfo[0]
> > > > >         self.interruptClientPsm = cinfo[1]
> > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > str(self.interruptClientPsm))
> > > > >
> > > > >         thread.start_new_thread(self.check_connection, ())
> > > > >
> > > > >     def check_connection(self):
> > > > >         halt = False
> > > > >         while not halt:
> > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > >
> > > > >             if self.controlClientMac in stdoutdata.split():
> > > > >                 time.sleep(0.1)
> > > > >             else:
> > > > >                 print('got disconnection')
> > > > >                 self.scontrol.shutdown(2);
> > > > >                 self.sinterrupt.shutdown(2)
> > > > >                 halt = True
> > > > >         thread.start_new_thread(self.listen, ())
> > > > >
> > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > see if anything is being sent but I can't see any bluez profile
> > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > is greatly appreciated.
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Neil
> > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > <luiz.dentz@gmail.com> wrote:
> > > > > >
> > > > > > Hi Neil,
> > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > points up on Stack Overflow for any advice too!
> > > > > > >
> > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > >
> > > > > > > Cheers,
> > > > > > >
> > > > > > > Neil
> > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > the device using the following call:
> > > > > > > > ---
> > > > > > > >     #configure the bluetooth hardware device
> > > > > > > >     def init_bt_device(self):
> > > > > > > >
> > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > >
> > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > >
> > > > > > > >         #make the device discoverable
> > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > >
> > > > > >
> > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > >
> > > > > > The class is automatically set by bluetoothd based on the
> > > > > > services/profiles registered and the setting in the main.conf:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > >
> > > > > > For the name use D-Bus property Alias:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > >
> > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > >
> > > > > >
> > > > > >
> > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > ---
> > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > loaded service record
> > > > > > > >     def init_bluez_profile(self):
> > > > > > > >
> > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > >
> > > > > > > >         #setup profile options
> > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > >
> > > > > > > >         opts = {
> > > > > > > >             "ServiceRecord":service_record,
> > > > > > > >             "Role":"server",
> > > > > > > >             "RequireAuthentication":False,
> > > > > > > >             "RequireAuthorization":False,
> > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > >             "AutoConnect":True
> > > > > > > >         }
> > > > > > > >
> > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > >         bus = dbus.SystemBus()
> > > > > > > >         self.manager =
> > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > >         print("Profile registered ")
> > > > > > > > ---
> > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > the test-profile as shown below:
> > > > > > > > ---
> > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > >     fd = -1
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > >     def Release(self):
> > > > > > > >             print("Release")
> > > > > > > >             mainloop.quit()
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > >     def Cancel(self):
> > > > > > > >             print("Cancel")
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > out_signature="")
> > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > >             self.fd = fd.take()
> > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > >             for key in properties.keys():
> > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > >                     else:
> > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > >
> > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > out_signature="")
> > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > >
> > > > > > > >             if (self.fd > 0):
> > > > > > > >                     os.close(self.fd)
> > > > > > > >                     self.fd = -1
> > > > > > > >
> > > > > > > >     def __init__(self, bus, path):
> > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > ---
> > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > callbacks on the profile are not being called.
> > > > > >
> > > > > > They would be called only when there is a connection to the profile,
> > > > > > did you actually connect? If this is something like a serial port the
> > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > there.
> > > > > >
> > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > most appreciated!
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > >
> > > > > > > > Neil
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > Neil Benn MSc
> > > > > > > > Ziath Ltd
> > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > http://www.ziath.com
> > > > > > > >
> > > > > > > > Please consider the environment before printing this email.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Neil Benn MSc
> > > > > > > Ziath Ltd
> > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > http://www.ziath.com
> > > > > > >
> > > > > > > Please consider the environment before printing this email.
> > > > > > >
> > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > >
> > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > addressed, and may contain information that is privileged,
> > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Luiz Augusto von Dentz
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Neil Benn MSc
> > > > > Ziath Ltd
> > > > > Phone: +44 (0) 1223 855021
> > > > > http://www.ziath.com
> > > > >
> > > > > Please consider the environment before printing this email.
> > > > >
> > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > >
> > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > intended only for the use of the individual or entity to which it is
> > > > > addressed, and may contain information that is privileged,
> > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > reader of this message is not the intended recipient, or the employee
> > > > > or agent responsible for delivering the message to the intended
> > > > > recipient, you are hereby notified that any dissemination,
> > > > > distribution or copying of this communication is strictly prohibited.
> > > > > If you have received this communication in error, please notify Ziath
> > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > >
> > > >
> > > >
> > > > --
> > > > Luiz Augusto von Dentz
> > >
> > >
> > >
> > > --
> > >
> > > Neil Benn MSc
> > > Ziath Ltd
> > > Phone: +44 (0) 1223 855021
> > > http://www.ziath.com
> > >
> > > Please consider the environment before printing this email.
> > >
> > > Follow us on Facebook, Twitter or LinkedIn
> > >
> > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > intended only for the use of the individual or entity to which it is
> > > addressed, and may contain information that is privileged,
> > > confidential and exempt from disclosure under applicable law. If the
> > > reader of this message is not the intended recipient, or the employee
> > > or agent responsible for delivering the message to the intended
> > > recipient, you are hereby notified that any dissemination,
> > > distribution or copying of this communication is strictly prohibited.
> > > If you have received this communication in error, please notify Ziath
> > > Ltd immediately by email at info@ziath.com. Thank you.
> >
> >
> >
> > --
> > Luiz Augusto von Dentz



-- 
Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-03 10:35               ` Luiz Augusto von Dentz
@ 2018-10-03 13:49                 ` Neil Benn
  2018-10-03 14:03                   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Benn @ 2018-10-03 13:49 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Barry Byford, linux-bluetooth

Hello,

  Thanks; I followed Barry's example on making the device discoverable
via bluetoothd and that can now be found so the profile is registered
without needing the sdp_record.  However the profile isn't getting
callbacks still except in one case where I kill the bluetoothd process
and the release method on the profile is called which is strange.

  Looking at the output from dbus when a connection happens; we have
the following:

signal time=1538574206.428425 sender=:1.0 -> destination=(null
destination) serial=314 path=/org/freedesktop/systemd1;
interface=org.freedesktop.systemd1.Manager; member=UnitNew
   string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
   object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
signal time=1538574206.431862 sender=:1.0 -> destination=(null
destination) serial=315 path=/org/freedesktop/systemd1;
interface=org.freedesktop.systemd1.Manager; member=UnitNew
   string "sys-subsystem-bluetooth-devices-hci0:11.device"
   object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
signal time=1538574206.463318 sender=:1.22 -> destination=(null
destination) serial=17 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.bluez.Device1"
   array [
      dict entry(
         string "Connected"
         variant             boolean true
      )
   ]
   array [
   ]
signal time=1538574210.618465 sender=:1.22 -> destination=(null
destination) serial=18 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.bluez.Device1"
   array [
      dict entry(
         string "Connected"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1538574210.629705 sender=:1.0 -> destination=(null
destination) serial=316
path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.systemd1.Device"
   array [
      dict entry(
         string "SysFSPath"
         variant             string
"/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
      )
   ]
   array [
   ]
signal time=1538574210.640715 sender=:1.0 -> destination=(null
destination) serial=317
path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.systemd1.Unit"
   array [
      dict entry(
         string "ActiveState"
         variant             string "inactive"
      )
      dict entry(
         string "SubState"
         variant             string "dead"
      )
      dict entry(
         string "StateChangeTimestamp"
         variant             uint64 1538574210626509
      )
      dict entry(
         string "StateChangeTimestampMonotonic"
         variant             uint64 2940864110
      )
      dict entry(
         string "InactiveExitTimestamp"
         variant             uint64 1538574206426852
      )
      dict entry(
         string "InactiveExitTimestampMonotonic"
         variant             uint64 2936664452
      )
      dict entry(
         string "ActiveEnterTimestamp"
         variant             uint64 1538574206426852
      )
      dict entry(
         string "ActiveEnterTimestampMonotonic"
         variant             uint64 2936664452
      )
      dict entry(
         string "ActiveExitTimestamp"
         variant             uint64 1538574210626509
      )
      dict entry(
         string "ActiveExitTimestampMonotonic"
         variant             uint64 2940864110
      )
      dict entry(
         string "InactiveEnterTimestamp"
         variant             uint64 1538574210626509
      )
      dict entry(
         string "InactiveEnterTimestampMonotonic"
         variant             uint64 2940864110
      )
      dict entry(
         string "Job"
         variant             struct {
               uint32 0
               object path "/"
            }
      )
      dict entry(
         string "ConditionResult"
         variant             boolean false
      )
      dict entry(
         string "AssertResult"
         variant             boolean false
      )
      dict entry(
         string "ConditionTimestamp"
         variant             uint64 0
      )
      dict entry(
         string "ConditionTimestampMonotonic"
         variant             uint64 0
      )
      dict entry(
         string "AssertTimestamp"
         variant             uint64 0
      )
      dict entry(
         string "AssertTimestampMonotonic"
         variant             uint64 0
      )
   ]
   array [
   ]
signal time=1538574210.668073 sender=:1.0 -> destination=(null
destination) serial=318 path=/org/freedesktop/systemd1;
interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
   string "sys-subsystem-bluetooth-devices-hci0:11.device"
   object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
signal time=1538574210.670654 sender=:1.0 -> destination=(null
destination) serial=319
path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.systemd1.Device"
   array [
      dict entry(
         string "SysFSPath"
         variant             string
"/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
      )
   ]
   array [
   ]
signal time=1538574210.677890 sender=:1.0 -> destination=(null
destination) serial=320
path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.systemd1.Unit"
   array [
      dict entry(
         string "ActiveState"
         variant             string "inactive"
      )
      dict entry(
         string "SubState"
         variant             string "dead"
      )
      dict entry(
         string "StateChangeTimestamp"
         variant             uint64 1538574210626572
      )
      dict entry(
         string "StateChangeTimestampMonotonic"
         variant             uint64 2940864171
      )
      dict entry(
         string "InactiveExitTimestamp"
         variant             uint64 1538574206426942
      )
      dict entry(
         string "InactiveExitTimestampMonotonic"
         variant             uint64 2936664542
      )
      dict entry(
         string "ActiveEnterTimestamp"
         variant             uint64 1538574206426942
      )
      dict entry(
         string "ActiveEnterTimestampMonotonic"
         variant             uint64 2936664542
      )
      dict entry(
         string "ActiveExitTimestamp"
         variant             uint64 1538574210626572
      )
      dict entry(
         string "ActiveExitTimestampMonotonic"
         variant             uint64 2940864171
      )
      dict entry(
         string "InactiveEnterTimestamp"
         variant             uint64 1538574210626572
      )
      dict entry(
         string "InactiveEnterTimestampMonotonic"
         variant             uint64 2940864171
      )
      dict entry(
         string "Job"
         variant             struct {
               uint32 0
               object path "/"
            }
      )
      dict entry(
         string "ConditionResult"
         variant             boolean false
      )
      dict entry(
         string "AssertResult"
         variant             boolean false
      )
      dict entry(
         string "ConditionTimestamp"
         variant             uint64 0
      )
      dict entry(
         string "ConditionTimestampMonotonic"
         variant             uint64 0
      )
      dict entry(
         string "AssertTimestamp"
         variant             uint64 0
      )
      dict entry(
         string "AssertTimestampMonotonic"
         variant             uint64 0
      )
   ]
   array [
   ]
signal time=1538574210.699336 sender=:1.0 -> destination=(null
destination) serial=321 path=/org/freedesktop/systemd1;
interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
   string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
   object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"

  So there are events being fired just not the ones that connect to my
registered profile.  In addition I've tried to register the profile
and listen for connections on the device PSM of 17 and 19 which HID
uses but nothing happens there either - though I'm not sure this is
the best way to communicate as it feels 'wrong' tbh.

  Thanks again - I'm still basically not getting any events fired on
the profile except for Release which isn't really that useful as it
only notifies me if the bluetooth stack goes down!

  Any ideas?

Cheers,

Neil
On Wed, 3 Oct 2018 at 11:35, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Barry,
> On Tue, Oct 2, 2018 at 5:57 PM Barry Byford <31baz66@gmail.com> wrote:
> >
> > Hi Luiz,
> >
> > On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Neil,
> > > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > >   Thanks for that please see inline below:
> > > >
> > > >
> > > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > > >
> > > > > Hi Neil,
> > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > >
> > > > > > Hello,
> > > > > >
> > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > name can that be in the main.conf file?  The same for the
> > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > >
> > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > windows PC correctly connects to the device, queries the service
> > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > >
> > > > > I don't think that will work since the input plugin is already
> > > > > listening in those PSM,
> > > >
> > > > It does connect and work but it doesn't register the profile.  If I
> > > > don't register the profile the default name in the config is used
> > > > >
> > > > > in fact I don't think RegisterProfile would
> > > > > parse the values from the record since you don't seem to be using the
> > > > > PSM:
> > > > >
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > >
> > > >
> > > > The PSM is defined in the service record
> > > > >
> > > > >
> > > > >
> > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > >
> > > > I'm using an sdp profile provided in some sample code I found, is
> > > > there a default one that is supported?  Is that default one selected
> > > > when I pick my uuid?
> > >
> > > You are not suppose to use existing UUIDs that the daemon already
> > > registers, the fact that you are able to register it without cause a
> > > problem might be a bug and we should probably check if the UUID is
> > > already registered and fail if it does.
> > >
> > > The HID profile is implementation is under profiles/input/, it
> > > actually hooks with kernel HID drivers.
> > >
> > > If you just want to test it you should probably have a look at
> > > test-profile in python:
> >
> > Do you have any example invocations of test-profile for common profiles?
>
> test-profile is just a sample, but yes we do have many instances of
> common profiles using RegisterProfile:
>
> OBEX Daemon:
> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/bluetooth.c#n256
>
> Ofono (HFP):
> https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/bluez5.c#n104
>
> PulseAudio (HSP):
> https://gitlab.freedesktop.org/pulseaudio/pulseaudio/blob/master/src/modules/bluetooth/backend-native.c#L332
>
> > It can be difficult to know where the issue is if you are not
> > confident with what settings should work.
>
> Well test-profile is not exactly a library just a convenient sample on
> how to use the interface, it was used mostly for testing SPP which is
> quite common way to register external profiles. HID is probably a no
> go due to reason already stated.
>
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> > >
> > > >   If so then I think it has been overcomplicated by this sdp profile?
> > > > How do I use the default in-built profile - is it just the uuid?
> > > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > > <luiz.dentz@gmail.com> wrote:
> > > > >
> > > > > Hi Neil,
> > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > >
> > > > > > Hello,
> > > > > >
> > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > name can that be in the main.conf file?  The same for the
> > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > >
> > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > windows PC correctly connects to the device, queries the service
> > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > >
> > > > > I don't think that will work since the input plugin is already
> > > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > > parse the values from the record since you don't seem to be using the
> > > > > PSM:
> > > > >
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > >
> > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > >
> > > > > > ---
> > > > > >     #listen for incoming client connections
> > > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > > >     #but that didn't seem to work
> > > > > >     def listen(self):
> > > > > >
> > > > > >         print("Waiting for connections")
> > > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > > >
> > > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > > >         #Start listening on the server sockets
> > > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > > >         self.sinterrupt.listen(1)
> > > > > >
> > > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > > >         self.controlClientMac = cinfo[0]
> > > > > >         self.controlClientPsm = cinfo[1]
> > > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > > str(self.controlClientPsm))
> > > > > >
> > > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > > >         self.interruptClientMac = cinfo[0]
> > > > > >         self.interruptClientPsm = cinfo[1]
> > > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > > str(self.interruptClientPsm))
> > > > > >
> > > > > >         thread.start_new_thread(self.check_connection, ())
> > > > > >
> > > > > >     def check_connection(self):
> > > > > >         halt = False
> > > > > >         while not halt:
> > > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > > >
> > > > > >             if self.controlClientMac in stdoutdata.split():
> > > > > >                 time.sleep(0.1)
> > > > > >             else:
> > > > > >                 print('got disconnection')
> > > > > >                 self.scontrol.shutdown(2);
> > > > > >                 self.sinterrupt.shutdown(2)
> > > > > >                 halt = True
> > > > > >         thread.start_new_thread(self.listen, ())
> > > > > >
> > > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > > see if anything is being sent but I can't see any bluez profile
> > > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > > is greatly appreciated.
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > Neil
> > > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > >
> > > > > > > Hi Neil,
> > > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > > points up on Stack Overflow for any advice too!
> > > > > > > >
> > > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > >
> > > > > > > > Neil
> > > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > >
> > > > > > > > > Hello,
> > > > > > > > >
> > > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > > the device using the following call:
> > > > > > > > > ---
> > > > > > > > >     #configure the bluetooth hardware device
> > > > > > > > >     def init_bt_device(self):
> > > > > > > > >
> > > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > >
> > > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > >
> > > > > > > > >         #make the device discoverable
> > > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > > >
> > > > > > >
> > > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > > >
> > > > > > > The class is automatically set by bluetoothd based on the
> > > > > > > services/profiles registered and the setting in the main.conf:
> > > > > > >
> > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > > >
> > > > > > > For the name use D-Bus property Alias:
> > > > > > >
> > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > > >
> > > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > > >
> > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > > ---
> > > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > > loaded service record
> > > > > > > > >     def init_bluez_profile(self):
> > > > > > > > >
> > > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > > >
> > > > > > > > >         #setup profile options
> > > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > > >
> > > > > > > > >         opts = {
> > > > > > > > >             "ServiceRecord":service_record,
> > > > > > > > >             "Role":"server",
> > > > > > > > >             "RequireAuthentication":False,
> > > > > > > > >             "RequireAuthorization":False,
> > > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > > >             "AutoConnect":True
> > > > > > > > >         }
> > > > > > > > >
> > > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > > >         bus = dbus.SystemBus()
> > > > > > > > >         self.manager =
> > > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > > >         print("Profile registered ")
> > > > > > > > > ---
> > > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > > the test-profile as shown below:
> > > > > > > > > ---
> > > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > > >     fd = -1
> > > > > > > > >
> > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > >     def Release(self):
> > > > > > > > >             print("Release")
> > > > > > > > >             mainloop.quit()
> > > > > > > > >
> > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > >     def Cancel(self):
> > > > > > > > >             print("Cancel")
> > > > > > > > >
> > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > > out_signature="")
> > > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > > >             self.fd = fd.take()
> > > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > > >             for key in properties.keys():
> > > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > > >                     else:
> > > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > > >
> > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > > out_signature="")
> > > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > > >
> > > > > > > > >             if (self.fd > 0):
> > > > > > > > >                     os.close(self.fd)
> > > > > > > > >                     self.fd = -1
> > > > > > > > >
> > > > > > > > >     def __init__(self, bus, path):
> > > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > > ---
> > > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > > callbacks on the profile are not being called.
> > > > > > >
> > > > > > > They would be called only when there is a connection to the profile,
> > > > > > > did you actually connect? If this is something like a serial port the
> > > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > > there.
> > > > > > >
> > > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > > most appreciated!
> > > > > > > > >
> > > > > > > > > Cheers,
> > > > > > > > >
> > > > > > > > > Neil
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > > Neil Benn MSc
> > > > > > > > > Ziath Ltd
> > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > http://www.ziath.com
> > > > > > > > >
> > > > > > > > > Please consider the environment before printing this email.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > Neil Benn MSc
> > > > > > > > Ziath Ltd
> > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > http://www.ziath.com
> > > > > > > >
> > > > > > > > Please consider the environment before printing this email.
> > > > > > > >
> > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > >
> > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Luiz Augusto von Dentz
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Neil Benn MSc
> > > > > > Ziath Ltd
> > > > > > Phone: +44 (0) 1223 855021
> > > > > > http://www.ziath.com
> > > > > >
> > > > > > Please consider the environment before printing this email.
> > > > > >
> > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > >
> > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > intended only for the use of the individual or entity to which it is
> > > > > > addressed, and may contain information that is privileged,
> > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > or agent responsible for delivering the message to the intended
> > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > If you have received this communication in error, please notify Ziath
> > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Luiz Augusto von Dentz
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Neil Benn MSc
> > > > Ziath Ltd
> > > > Phone: +44 (0) 1223 855021
> > > > http://www.ziath.com
> > > >
> > > > Please consider the environment before printing this email.
> > > >
> > > > Follow us on Facebook, Twitter or LinkedIn
> > > >
> > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > intended only for the use of the individual or entity to which it is
> > > > addressed, and may contain information that is privileged,
> > > > confidential and exempt from disclosure under applicable law. If the
> > > > reader of this message is not the intended recipient, or the employee
> > > > or agent responsible for delivering the message to the intended
> > > > recipient, you are hereby notified that any dissemination,
> > > > distribution or copying of this communication is strictly prohibited.
> > > > If you have received this communication in error, please notify Ziath
> > > > Ltd immediately by email at info@ziath.com. Thank you.
> > >
> > >
> > >
> > > --
> > > Luiz Augusto von Dentz
>
>
>
> --
> Luiz Augusto von Dentz



--

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

* Re: Registering a profile
  2018-10-03 13:49                 ` Neil Benn
@ 2018-10-03 14:03                   ` Luiz Augusto von Dentz
  2018-10-03 15:28                     ` Neil Benn
  0 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-03 14:03 UTC (permalink / raw)
  To: neil.benn; +Cc: Barry Byford, linux-bluetooth

Hi Neil,
On Wed, Oct 3, 2018 at 4:49 PM Neil Benn <neil.benn@ziath.com> wrote:
>
> Hello,
>
>   Thanks; I followed Barry's example on making the device discoverable
> via bluetoothd and that can now be found so the profile is registered
> without needing the sdp_record.  However the profile isn't getting
> callbacks still except in one case where I kill the bluetoothd process
> and the release method on the profile is called which is strange.
>
>   Looking at the output from dbus when a connection happens; we have
> the following:
>
> signal time=1538574206.428425 sender=:1.0 -> destination=(null
> destination) serial=314 path=/org/freedesktop/systemd1;
> interface=org.freedesktop.systemd1.Manager; member=UnitNew
>    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
>    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> signal time=1538574206.431862 sender=:1.0 -> destination=(null
> destination) serial=315 path=/org/freedesktop/systemd1;
> interface=org.freedesktop.systemd1.Manager; member=UnitNew
>    string "sys-subsystem-bluetooth-devices-hci0:11.device"
>    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> signal time=1538574206.463318 sender=:1.22 -> destination=(null
> destination) serial=17 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
>    string "org.bluez.Device1"
>    array [
>       dict entry(
>          string "Connected"
>          variant             boolean true
>       )
>    ]
>    array [
>    ]
> signal time=1538574210.618465 sender=:1.22 -> destination=(null
> destination) serial=18 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
>    string "org.bluez.Device1"
>    array [
>       dict entry(
>          string "Connected"
>          variant             boolean false
>       )
>    ]
>    array [
>    ]
> signal time=1538574210.629705 sender=:1.0 -> destination=(null
> destination) serial=316
> path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
>    string "org.freedesktop.systemd1.Device"
>    array [
>       dict entry(
>          string "SysFSPath"
>          variant             string
> "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
>       )
>    ]
>    array [
>    ]
> signal time=1538574210.640715 sender=:1.0 -> destination=(null
> destination) serial=317
> path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
>    string "org.freedesktop.systemd1.Unit"
>    array [
>       dict entry(
>          string "ActiveState"
>          variant             string "inactive"
>       )
>       dict entry(
>          string "SubState"
>          variant             string "dead"
>       )
>       dict entry(
>          string "StateChangeTimestamp"
>          variant             uint64 1538574210626509
>       )
>       dict entry(
>          string "StateChangeTimestampMonotonic"
>          variant             uint64 2940864110
>       )
>       dict entry(
>          string "InactiveExitTimestamp"
>          variant             uint64 1538574206426852
>       )
>       dict entry(
>          string "InactiveExitTimestampMonotonic"
>          variant             uint64 2936664452
>       )
>       dict entry(
>          string "ActiveEnterTimestamp"
>          variant             uint64 1538574206426852
>       )
>       dict entry(
>          string "ActiveEnterTimestampMonotonic"
>          variant             uint64 2936664452
>       )
>       dict entry(
>          string "ActiveExitTimestamp"
>          variant             uint64 1538574210626509
>       )
>       dict entry(
>          string "ActiveExitTimestampMonotonic"
>          variant             uint64 2940864110
>       )
>       dict entry(
>          string "InactiveEnterTimestamp"
>          variant             uint64 1538574210626509
>       )
>       dict entry(
>          string "InactiveEnterTimestampMonotonic"
>          variant             uint64 2940864110
>       )
>       dict entry(
>          string "Job"
>          variant             struct {
>                uint32 0
>                object path "/"
>             }
>       )
>       dict entry(
>          string "ConditionResult"
>          variant             boolean false
>       )
>       dict entry(
>          string "AssertResult"
>          variant             boolean false
>       )
>       dict entry(
>          string "ConditionTimestamp"
>          variant             uint64 0
>       )
>       dict entry(
>          string "ConditionTimestampMonotonic"
>          variant             uint64 0
>       )
>       dict entry(
>          string "AssertTimestamp"
>          variant             uint64 0
>       )
>       dict entry(
>          string "AssertTimestampMonotonic"
>          variant             uint64 0
>       )
>    ]
>    array [
>    ]
> signal time=1538574210.668073 sender=:1.0 -> destination=(null
> destination) serial=318 path=/org/freedesktop/systemd1;
> interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
>    string "sys-subsystem-bluetooth-devices-hci0:11.device"
>    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> signal time=1538574210.670654 sender=:1.0 -> destination=(null
> destination) serial=319
> path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
>    string "org.freedesktop.systemd1.Device"
>    array [
>       dict entry(
>          string "SysFSPath"
>          variant             string
> "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
>       )
>    ]
>    array [
>    ]
> signal time=1538574210.677890 sender=:1.0 -> destination=(null
> destination) serial=320
> path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
>    string "org.freedesktop.systemd1.Unit"
>    array [
>       dict entry(
>          string "ActiveState"
>          variant             string "inactive"
>       )
>       dict entry(
>          string "SubState"
>          variant             string "dead"
>       )
>       dict entry(
>          string "StateChangeTimestamp"
>          variant             uint64 1538574210626572
>       )
>       dict entry(
>          string "StateChangeTimestampMonotonic"
>          variant             uint64 2940864171
>       )
>       dict entry(
>          string "InactiveExitTimestamp"
>          variant             uint64 1538574206426942
>       )
>       dict entry(
>          string "InactiveExitTimestampMonotonic"
>          variant             uint64 2936664542
>       )
>       dict entry(
>          string "ActiveEnterTimestamp"
>          variant             uint64 1538574206426942
>       )
>       dict entry(
>          string "ActiveEnterTimestampMonotonic"
>          variant             uint64 2936664542
>       )
>       dict entry(
>          string "ActiveExitTimestamp"
>          variant             uint64 1538574210626572
>       )
>       dict entry(
>          string "ActiveExitTimestampMonotonic"
>          variant             uint64 2940864171
>       )
>       dict entry(
>          string "InactiveEnterTimestamp"
>          variant             uint64 1538574210626572
>       )
>       dict entry(
>          string "InactiveEnterTimestampMonotonic"
>          variant             uint64 2940864171
>       )
>       dict entry(
>          string "Job"
>          variant             struct {
>                uint32 0
>                object path "/"
>             }
>       )
>       dict entry(
>          string "ConditionResult"
>          variant             boolean false
>       )
>       dict entry(
>          string "AssertResult"
>          variant             boolean false
>       )
>       dict entry(
>          string "ConditionTimestamp"
>          variant             uint64 0
>       )
>       dict entry(
>          string "ConditionTimestampMonotonic"
>          variant             uint64 0
>       )
>       dict entry(
>          string "AssertTimestamp"
>          variant             uint64 0
>       )
>       dict entry(
>          string "AssertTimestampMonotonic"
>          variant             uint64 0
>       )
>    ]
>    array [
>    ]
> signal time=1538574210.699336 sender=:1.0 -> destination=(null
> destination) serial=321 path=/org/freedesktop/systemd1;
> interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
>    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
>    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
>
>   So there are events being fired just not the ones that connect to my
> registered profile.  In addition I've tried to register the profile
> and listen for connections on the device PSM of 17 and 19 which HID
> uses but nothing happens there either - though I'm not sure this is
> the best way to communicate as it feels 'wrong' tbh.

Have you read my responses? It _wont_ work for these PSMs, those are
already taken by the daemon except if you are not loading the input
plugin. Can't you try with something simpler like SPP, which is what
this interface is for?

>   Thanks again - I'm still basically not getting any events fired on
> the profile except for Release which isn't really that useful as it
> only notifies me if the bluetooth stack goes down!
>
>   Any ideas?
>
> Cheers,
>
> Neil
> On Wed, 3 Oct 2018 at 11:35, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > Hi Barry,
> > On Tue, Oct 2, 2018 at 5:57 PM Barry Byford <31baz66@gmail.com> wrote:
> > >
> > > Hi Luiz,
> > >
> > > On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> > > <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Neil,
> > > > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > >   Thanks for that please see inline below:
> > > > >
> > > > >
> > > > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > > > >
> > > > > > Hi Neil,
> > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > >
> > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > >
> > > > > > I don't think that will work since the input plugin is already
> > > > > > listening in those PSM,
> > > > >
> > > > > It does connect and work but it doesn't register the profile.  If I
> > > > > don't register the profile the default name in the config is used
> > > > > >
> > > > > > in fact I don't think RegisterProfile would
> > > > > > parse the values from the record since you don't seem to be using the
> > > > > > PSM:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > >
> > > > >
> > > > > The PSM is defined in the service record
> > > > > >
> > > > > >
> > > > > >
> > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > >
> > > > > I'm using an sdp profile provided in some sample code I found, is
> > > > > there a default one that is supported?  Is that default one selected
> > > > > when I pick my uuid?
> > > >
> > > > You are not suppose to use existing UUIDs that the daemon already
> > > > registers, the fact that you are able to register it without cause a
> > > > problem might be a bug and we should probably check if the UUID is
> > > > already registered and fail if it does.
> > > >
> > > > The HID profile is implementation is under profiles/input/, it
> > > > actually hooks with kernel HID drivers.
> > > >
> > > > If you just want to test it you should probably have a look at
> > > > test-profile in python:
> > >
> > > Do you have any example invocations of test-profile for common profiles?
> >
> > test-profile is just a sample, but yes we do have many instances of
> > common profiles using RegisterProfile:
> >
> > OBEX Daemon:
> > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/bluetooth.c#n256
> >
> > Ofono (HFP):
> > https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/bluez5.c#n104
> >
> > PulseAudio (HSP):
> > https://gitlab.freedesktop.org/pulseaudio/pulseaudio/blob/master/src/modules/bluetooth/backend-native.c#L332
> >
> > > It can be difficult to know where the issue is if you are not
> > > confident with what settings should work.
> >
> > Well test-profile is not exactly a library just a convenient sample on
> > how to use the interface, it was used mostly for testing SPP which is
> > quite common way to register external profiles. HID is probably a no
> > go due to reason already stated.
> >
> > > >
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> > > >
> > > > >   If so then I think it has been overcomplicated by this sdp profile?
> > > > > How do I use the default in-built profile - is it just the uuid?
> > > > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > > > <luiz.dentz@gmail.com> wrote:
> > > > > >
> > > > > > Hi Neil,
> > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > >
> > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > >
> > > > > > I don't think that will work since the input plugin is already
> > > > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > > > parse the values from the record since you don't seem to be using the
> > > > > > PSM:
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > >
> > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > >
> > > > > > > ---
> > > > > > >     #listen for incoming client connections
> > > > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > > > >     #but that didn't seem to work
> > > > > > >     def listen(self):
> > > > > > >
> > > > > > >         print("Waiting for connections")
> > > > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > > > >
> > > > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > > > >         #Start listening on the server sockets
> > > > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > > > >         self.sinterrupt.listen(1)
> > > > > > >
> > > > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > > > >         self.controlClientMac = cinfo[0]
> > > > > > >         self.controlClientPsm = cinfo[1]
> > > > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > > > str(self.controlClientPsm))
> > > > > > >
> > > > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > > > >         self.interruptClientMac = cinfo[0]
> > > > > > >         self.interruptClientPsm = cinfo[1]
> > > > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > > > str(self.interruptClientPsm))
> > > > > > >
> > > > > > >         thread.start_new_thread(self.check_connection, ())
> > > > > > >
> > > > > > >     def check_connection(self):
> > > > > > >         halt = False
> > > > > > >         while not halt:
> > > > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > > > >
> > > > > > >             if self.controlClientMac in stdoutdata.split():
> > > > > > >                 time.sleep(0.1)
> > > > > > >             else:
> > > > > > >                 print('got disconnection')
> > > > > > >                 self.scontrol.shutdown(2);
> > > > > > >                 self.sinterrupt.shutdown(2)
> > > > > > >                 halt = True
> > > > > > >         thread.start_new_thread(self.listen, ())
> > > > > > >
> > > > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > > > see if anything is being sent but I can't see any bluez profile
> > > > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > > > is greatly appreciated.
> > > > > > >
> > > > > > > Cheers,
> > > > > > >
> > > > > > > Neil
> > > > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > > >
> > > > > > > > Hi Neil,
> > > > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > >
> > > > > > > > > Hello,
> > > > > > > > >
> > > > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > > > points up on Stack Overflow for any advice too!
> > > > > > > > >
> > > > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > > > >
> > > > > > > > > Cheers,
> > > > > > > > >
> > > > > > > > > Neil
> > > > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > >
> > > > > > > > > > Hello,
> > > > > > > > > >
> > > > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > > > the device using the following call:
> > > > > > > > > > ---
> > > > > > > > > >     #configure the bluetooth hardware device
> > > > > > > > > >     def init_bt_device(self):
> > > > > > > > > >
> > > > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > >
> > > > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > >
> > > > > > > > > >         #make the device discoverable
> > > > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > > > >
> > > > > > > >
> > > > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > > > >
> > > > > > > > The class is automatically set by bluetoothd based on the
> > > > > > > > services/profiles registered and the setting in the main.conf:
> > > > > > > >
> > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > > > >
> > > > > > > > For the name use D-Bus property Alias:
> > > > > > > >
> > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > > > >
> > > > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > > > >
> > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > > > ---
> > > > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > > > loaded service record
> > > > > > > > > >     def init_bluez_profile(self):
> > > > > > > > > >
> > > > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > > > >
> > > > > > > > > >         #setup profile options
> > > > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > > > >
> > > > > > > > > >         opts = {
> > > > > > > > > >             "ServiceRecord":service_record,
> > > > > > > > > >             "Role":"server",
> > > > > > > > > >             "RequireAuthentication":False,
> > > > > > > > > >             "RequireAuthorization":False,
> > > > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > > > >             "AutoConnect":True
> > > > > > > > > >         }
> > > > > > > > > >
> > > > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > > > >         bus = dbus.SystemBus()
> > > > > > > > > >         self.manager =
> > > > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > > > >         print("Profile registered ")
> > > > > > > > > > ---
> > > > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > > > the test-profile as shown below:
> > > > > > > > > > ---
> > > > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > > > >     fd = -1
> > > > > > > > > >
> > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > >     def Release(self):
> > > > > > > > > >             print("Release")
> > > > > > > > > >             mainloop.quit()
> > > > > > > > > >
> > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > >     def Cancel(self):
> > > > > > > > > >             print("Cancel")
> > > > > > > > > >
> > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > > > out_signature="")
> > > > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > > > >             self.fd = fd.take()
> > > > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > > > >             for key in properties.keys():
> > > > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > > > >                     else:
> > > > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > > > >
> > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > > > out_signature="")
> > > > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > > > >
> > > > > > > > > >             if (self.fd > 0):
> > > > > > > > > >                     os.close(self.fd)
> > > > > > > > > >                     self.fd = -1
> > > > > > > > > >
> > > > > > > > > >     def __init__(self, bus, path):
> > > > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > > > ---
> > > > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > > > callbacks on the profile are not being called.
> > > > > > > >
> > > > > > > > They would be called only when there is a connection to the profile,
> > > > > > > > did you actually connect? If this is something like a serial port the
> > > > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > > > there.
> > > > > > > >
> > > > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > > > most appreciated!
> > > > > > > > > >
> > > > > > > > > > Cheers,
> > > > > > > > > >
> > > > > > > > > > Neil
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > >
> > > > > > > > > > Neil Benn MSc
> > > > > > > > > > Ziath Ltd
> > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > http://www.ziath.com
> > > > > > > > > >
> > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > > Neil Benn MSc
> > > > > > > > > Ziath Ltd
> > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > http://www.ziath.com
> > > > > > > > >
> > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > >
> > > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > > >
> > > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Luiz Augusto von Dentz
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Neil Benn MSc
> > > > > > > Ziath Ltd
> > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > http://www.ziath.com
> > > > > > >
> > > > > > > Please consider the environment before printing this email.
> > > > > > >
> > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > >
> > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > addressed, and may contain information that is privileged,
> > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Luiz Augusto von Dentz
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Neil Benn MSc
> > > > > Ziath Ltd
> > > > > Phone: +44 (0) 1223 855021
> > > > > http://www.ziath.com
> > > > >
> > > > > Please consider the environment before printing this email.
> > > > >
> > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > >
> > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > intended only for the use of the individual or entity to which it is
> > > > > addressed, and may contain information that is privileged,
> > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > reader of this message is not the intended recipient, or the employee
> > > > > or agent responsible for delivering the message to the intended
> > > > > recipient, you are hereby notified that any dissemination,
> > > > > distribution or copying of this communication is strictly prohibited.
> > > > > If you have received this communication in error, please notify Ziath
> > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > >
> > > >
> > > >
> > > > --
> > > > Luiz Augusto von Dentz
> >
> >
> >
> > --
> > Luiz Augusto von Dentz
>
>
>
> --
>
> Neil Benn MSc
> Ziath Ltd
> Phone: +44 (0) 1223 855021
> http://www.ziath.com
>
> Please consider the environment before printing this email.
>
> Follow us on Facebook, Twitter or LinkedIn
>
> IMPORTANT NOTICE: This message, including any attached documents, is
> intended only for the use of the individual or entity to which it is
> addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law. If the
> reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify Ziath
> Ltd immediately by email at info@ziath.com. Thank you.



-- 
Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-03 14:03                   ` Luiz Augusto von Dentz
@ 2018-10-03 15:28                     ` Neil Benn
  2018-10-03 18:08                       ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Benn @ 2018-10-03 15:28 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Barry Byford, linux-bluetooth

Hello,

  I understand that which is why I didn't prusue it.  My guess is that
the old code basically wasn't registering the profile so I guess that
the PSMs were not taken and it explains why I could directly connect
to the sockets via pyBluez - the issue here is that this was 'hacky'
and there was no way I could rebind to a paired device after losing
connection.

  I tried with SPP with the following main.conf:

Name = DataPaqWalk
DiscoverableTimeout = 0
PairableTimeout = 0
ReconnectAttempts=7
ReconnectIntervals=1,2,4,8,16,32,64
AutoEnable=true

  The code is now:

---
#!/usr/bin/python
#
# YAPTB Bluetooth keyboard emulator DBUS Service
#
# Adapted from
# www.linuxuser.co.uk/tutorials/emulate-bluetooth-keyboard-with-the-raspberry-pi
#
#

#from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function

import os
import sys
import uuid
import dbus
import dbus.service
import dbus.mainloop.glib
import time
import bluetooth
import thread
import subprocess
import traceback
from bluetooth import *

from dbus.mainloop.glib import DBusGMainLoop

try:
  from gi.repository import GObject
except ImportError:
  import gobject as GObject

#
#define a bluez 5 profile object for our keyboard
#
class BTKbBluezProfile(dbus.service.Object):
    fd = -1

    @dbus.service.method("org.bluez.Profile1",
                                    in_signature="", out_signature="")
    def Release(self):
        print("Release")
        mainloop.quit()

    @dbus.service.method("org.bluez.Profile1",
                                    in_signature="", out_signature="")
    def Cancel(self):
        print("Cancel")

    @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
out_signature="")
    def NewConnection(self, path, fd, properties):
        print ('NewConnection')
        self.fd = fd.take()
        print("NewConnection(%s, %d)" % (path, self.fd))
        for key in properties.keys():
                print ('key ' + key + ' value ' + properties[key])
                if key == "Version" or key == "Features":
                        print("  %s = 0x%04x" % (key, properties[key]))
                else:
                        print("  %s = %s" % (key, properties[key]))



    @dbus.service.method("org.bluez.Profile1", in_signature="o",
out_signature="")
    def RequestDisconnection(self, path):
            print("RequestDisconnection(%s)" % (path))

            if (self.fd > 0):
                    os.close(self.fd)
                    self.fd = -1

    def __init__(self, bus, path):
            dbus.service.Object.__init__(self, bus, path)


#
#create a bluetooth device to emulate a HID keyboard,
# advertize a SDP record using our bluez profile class
#
class BTKbDevice():

    #define some constants
    P_CTRL =17  #Service port - must match port configured in SDP record
    P_INTR =19  #Interrrupt port - must match port configured in SDP record
    PROFILE_DBUS_PATH="/bluez/yaptb/btkb_profile" #dbus path of  the
bluez profile we will create
    UUID='00001101-0000-1000-8000-00805f9b34fb'
    #UUID="00001124-0000-1000-8000-00805f9b34fb"


    def __init__(self):

        print("Setting up BT device")
        self.init_bluez_profile()


    #set up a bluez profile to advertise device capabilities from a
loaded service record
    def init_bluez_profile(self):

        bus = dbus.SystemBus()

        print ("setting adapter to discoverable")
        self.adapter =
dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
"org.bluez.Adapter1")
        self.adapter.Discoverable = True

        print("Configuring Bluez Profile")

        opts = {
            "Role":"server"
        }

        self.manager =
dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
"org.bluez.ProfileManager1")
        self.profile = BTKbBluezProfile(bus,
BTKbDevice.PROFILE_DBUS_PATH)#BTKbDevice.PROFILE_DBUS_PATH)
        self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
BTKbDevice.UUID, opts)
        print("Profile registered ")

    #send a string to the bluetooth host machine
    def send_string(self,message):
         self.cinterrupt.send(message)


#define a dbus service that emulates a bluetooth keyboard
#this will enable different clients to connect to and use
#the service
class BTKbService(dbus.service.Object):

    def __init__(self):

        print("Setting up service")
        bus = dbus.SystemBus()
        #set up as a dbus service
        bus_name=dbus.service.BusName("org.yaptb.btkbservice",bus)
        dbus.service.Object.__init__(self,bus_name,"/org/yaptb/btkbservice")
        self.device= BTKbDevice();


    @dbus.service.method('org.yaptb.btkbservice', in_signature='yay')
    def send_keys(self,modifier_byte,keys):
        cmd_str=""
        cmd_str+=chr(0xA1)
        cmd_str+=chr(0x01)
        cmd_str+=chr(modifier_byte)
        cmd_str+=chr(0x00)

        count=0
        for key_code in keys:
            if(count<6):
                cmd_str+=chr(key_code)
            count+=1

        self.device.send_string(cmd_str);



#main routine
if __name__ == "__main__":
    mainloop = GObject.MainLoop()
    # we an only run as root
    if not os.geteuid() == 0:
       sys.exit("Only root can run this script")

    DBusGMainLoop(set_as_default=True)
    myservice = BTKbService();
    mainloop.run()
---

  This does the same as for an HID; no events are fired on the dbus;
bluetoothd gives:

bluetoothd[651]: src/adapter.c:connected_callback() hci0 device
C8:FF:28:79:05:D4 connected eir_len 5
bluetoothd[651]: src/adapter.c:new_link_key_callback() hci0 new key
for C8:FF:28:79:05:D4 type 4 pin_len 0 store_hint 1
bluetoothd[651]: src/device.c:device_set_bonded()
bluetoothd[651]: src/device.c:device_bonding_complete() bonding (nil)
status 0x00
bluetoothd[651]: src/adapter.c:resume_discovery()
bluetoothd[651]: src/adapter.c:dev_disconnected() Device
C8:FF:28:79:05:D4 disconnected, reason 3
bluetoothd[651]: src/adapter.c:adapter_remove_connection()
bluetoothd[651]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr
C8:FF:28:79:05:D4 type 0 status 0xe
bluetoothd[651]: src/device.c:device_bonding_complete() bonding (nil)
status 0x0e
bluetoothd[651]: src/device.c:device_bonding_failed() status 14
bluetoothd[651]: src/adapter.c:resume_discovery()

  The device itself connects and disconnects after a second or so:

[bluetooth]# discoverable on
Changing discoverable on succeeded
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller B8:27:EB:14:FB:B1 Powered: yes
[CHG] Device C8:FF:28:79:05:D4 Connected: yes
[CHG] Device C8:FF:28:79:05:D4 Connected: no
[bluetooth]#

  So I'm getting the same thing.  In the longer run I'll need HID
because I'm making a HID device; maybe as you say I can disable the
input plugin and connect the PSM but I'll still need to capture the
connected/disconnected events.  Sorry to keep posting; your help is
very much appreciated - as I said; I will return the code back when it
is working.  Any ideas?

  Thanks.

Cheers,

Neil
On Wed, 3 Oct 2018 at 15:04, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Neil,
> On Wed, Oct 3, 2018 at 4:49 PM Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   Thanks; I followed Barry's example on making the device discoverable
> > via bluetoothd and that can now be found so the profile is registered
> > without needing the sdp_record.  However the profile isn't getting
> > callbacks still except in one case where I kill the bluetoothd process
> > and the release method on the profile is called which is strange.
> >
> >   Looking at the output from dbus when a connection happens; we have
> > the following:
> >
> > signal time=1538574206.428425 sender=:1.0 -> destination=(null
> > destination) serial=314 path=/org/freedesktop/systemd1;
> > interface=org.freedesktop.systemd1.Manager; member=UnitNew
> >    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
> >    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> > signal time=1538574206.431862 sender=:1.0 -> destination=(null
> > destination) serial=315 path=/org/freedesktop/systemd1;
> > interface=org.freedesktop.systemd1.Manager; member=UnitNew
> >    string "sys-subsystem-bluetooth-devices-hci0:11.device"
> >    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> > signal time=1538574206.463318 sender=:1.22 -> destination=(null
> > destination) serial=17 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> >    string "org.bluez.Device1"
> >    array [
> >       dict entry(
> >          string "Connected"
> >          variant             boolean true
> >       )
> >    ]
> >    array [
> >    ]
> > signal time=1538574210.618465 sender=:1.22 -> destination=(null
> > destination) serial=18 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> >    string "org.bluez.Device1"
> >    array [
> >       dict entry(
> >          string "Connected"
> >          variant             boolean false
> >       )
> >    ]
> >    array [
> >    ]
> > signal time=1538574210.629705 sender=:1.0 -> destination=(null
> > destination) serial=316
> > path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> >    string "org.freedesktop.systemd1.Device"
> >    array [
> >       dict entry(
> >          string "SysFSPath"
> >          variant             string
> > "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
> >       )
> >    ]
> >    array [
> >    ]
> > signal time=1538574210.640715 sender=:1.0 -> destination=(null
> > destination) serial=317
> > path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> >    string "org.freedesktop.systemd1.Unit"
> >    array [
> >       dict entry(
> >          string "ActiveState"
> >          variant             string "inactive"
> >       )
> >       dict entry(
> >          string "SubState"
> >          variant             string "dead"
> >       )
> >       dict entry(
> >          string "StateChangeTimestamp"
> >          variant             uint64 1538574210626509
> >       )
> >       dict entry(
> >          string "StateChangeTimestampMonotonic"
> >          variant             uint64 2940864110
> >       )
> >       dict entry(
> >          string "InactiveExitTimestamp"
> >          variant             uint64 1538574206426852
> >       )
> >       dict entry(
> >          string "InactiveExitTimestampMonotonic"
> >          variant             uint64 2936664452
> >       )
> >       dict entry(
> >          string "ActiveEnterTimestamp"
> >          variant             uint64 1538574206426852
> >       )
> >       dict entry(
> >          string "ActiveEnterTimestampMonotonic"
> >          variant             uint64 2936664452
> >       )
> >       dict entry(
> >          string "ActiveExitTimestamp"
> >          variant             uint64 1538574210626509
> >       )
> >       dict entry(
> >          string "ActiveExitTimestampMonotonic"
> >          variant             uint64 2940864110
> >       )
> >       dict entry(
> >          string "InactiveEnterTimestamp"
> >          variant             uint64 1538574210626509
> >       )
> >       dict entry(
> >          string "InactiveEnterTimestampMonotonic"
> >          variant             uint64 2940864110
> >       )
> >       dict entry(
> >          string "Job"
> >          variant             struct {
> >                uint32 0
> >                object path "/"
> >             }
> >       )
> >       dict entry(
> >          string "ConditionResult"
> >          variant             boolean false
> >       )
> >       dict entry(
> >          string "AssertResult"
> >          variant             boolean false
> >       )
> >       dict entry(
> >          string "ConditionTimestamp"
> >          variant             uint64 0
> >       )
> >       dict entry(
> >          string "ConditionTimestampMonotonic"
> >          variant             uint64 0
> >       )
> >       dict entry(
> >          string "AssertTimestamp"
> >          variant             uint64 0
> >       )
> >       dict entry(
> >          string "AssertTimestampMonotonic"
> >          variant             uint64 0
> >       )
> >    ]
> >    array [
> >    ]
> > signal time=1538574210.668073 sender=:1.0 -> destination=(null
> > destination) serial=318 path=/org/freedesktop/systemd1;
> > interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
> >    string "sys-subsystem-bluetooth-devices-hci0:11.device"
> >    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> > signal time=1538574210.670654 sender=:1.0 -> destination=(null
> > destination) serial=319
> > path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> >    string "org.freedesktop.systemd1.Device"
> >    array [
> >       dict entry(
> >          string "SysFSPath"
> >          variant             string
> > "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
> >       )
> >    ]
> >    array [
> >    ]
> > signal time=1538574210.677890 sender=:1.0 -> destination=(null
> > destination) serial=320
> > path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> >    string "org.freedesktop.systemd1.Unit"
> >    array [
> >       dict entry(
> >          string "ActiveState"
> >          variant             string "inactive"
> >       )
> >       dict entry(
> >          string "SubState"
> >          variant             string "dead"
> >       )
> >       dict entry(
> >          string "StateChangeTimestamp"
> >          variant             uint64 1538574210626572
> >       )
> >       dict entry(
> >          string "StateChangeTimestampMonotonic"
> >          variant             uint64 2940864171
> >       )
> >       dict entry(
> >          string "InactiveExitTimestamp"
> >          variant             uint64 1538574206426942
> >       )
> >       dict entry(
> >          string "InactiveExitTimestampMonotonic"
> >          variant             uint64 2936664542
> >       )
> >       dict entry(
> >          string "ActiveEnterTimestamp"
> >          variant             uint64 1538574206426942
> >       )
> >       dict entry(
> >          string "ActiveEnterTimestampMonotonic"
> >          variant             uint64 2936664542
> >       )
> >       dict entry(
> >          string "ActiveExitTimestamp"
> >          variant             uint64 1538574210626572
> >       )
> >       dict entry(
> >          string "ActiveExitTimestampMonotonic"
> >          variant             uint64 2940864171
> >       )
> >       dict entry(
> >          string "InactiveEnterTimestamp"
> >          variant             uint64 1538574210626572
> >       )
> >       dict entry(
> >          string "InactiveEnterTimestampMonotonic"
> >          variant             uint64 2940864171
> >       )
> >       dict entry(
> >          string "Job"
> >          variant             struct {
> >                uint32 0
> >                object path "/"
> >             }
> >       )
> >       dict entry(
> >          string "ConditionResult"
> >          variant             boolean false
> >       )
> >       dict entry(
> >          string "AssertResult"
> >          variant             boolean false
> >       )
> >       dict entry(
> >          string "ConditionTimestamp"
> >          variant             uint64 0
> >       )
> >       dict entry(
> >          string "ConditionTimestampMonotonic"
> >          variant             uint64 0
> >       )
> >       dict entry(
> >          string "AssertTimestamp"
> >          variant             uint64 0
> >       )
> >       dict entry(
> >          string "AssertTimestampMonotonic"
> >          variant             uint64 0
> >       )
> >    ]
> >    array [
> >    ]
> > signal time=1538574210.699336 sender=:1.0 -> destination=(null
> > destination) serial=321 path=/org/freedesktop/systemd1;
> > interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
> >    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
> >    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> >
> >   So there are events being fired just not the ones that connect to my
> > registered profile.  In addition I've tried to register the profile
> > and listen for connections on the device PSM of 17 and 19 which HID
> > uses but nothing happens there either - though I'm not sure this is
> > the best way to communicate as it feels 'wrong' tbh.
>
> Have you read my responses? It _wont_ work for these PSMs, those are
> already taken by the daemon except if you are not loading the input
> plugin. Can't you try with something simpler like SPP, which is what
> this interface is for?
>
> >   Thanks again - I'm still basically not getting any events fired on
> > the profile except for Release which isn't really that useful as it
> > only notifies me if the bluetooth stack goes down!
> >
> >   Any ideas?
> >
> > Cheers,
> >
> > Neil
> > On Wed, 3 Oct 2018 at 11:35, Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Barry,
> > > On Tue, Oct 2, 2018 at 5:57 PM Barry Byford <31baz66@gmail.com> wrote:
> > > >
> > > > Hi Luiz,
> > > >
> > > > On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> > > > <luiz.dentz@gmail.com> wrote:
> > > > >
> > > > > Hi Neil,
> > > > > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > >
> > > > > > Hello,
> > > > > >
> > > > > >   Thanks for that please see inline below:
> > > > > >
> > > > > >
> > > > > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > > > > >
> > > > > > > Hi Neil,
> > > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > > >
> > > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > > >
> > > > > > > I don't think that will work since the input plugin is already
> > > > > > > listening in those PSM,
> > > > > >
> > > > > > It does connect and work but it doesn't register the profile.  If I
> > > > > > don't register the profile the default name in the config is used
> > > > > > >
> > > > > > > in fact I don't think RegisterProfile would
> > > > > > > parse the values from the record since you don't seem to be using the
> > > > > > > PSM:
> > > > > > >
> > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > >
> > > > > >
> > > > > > The PSM is defined in the service record
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > >
> > > > > > I'm using an sdp profile provided in some sample code I found, is
> > > > > > there a default one that is supported?  Is that default one selected
> > > > > > when I pick my uuid?
> > > > >
> > > > > You are not suppose to use existing UUIDs that the daemon already
> > > > > registers, the fact that you are able to register it without cause a
> > > > > problem might be a bug and we should probably check if the UUID is
> > > > > already registered and fail if it does.
> > > > >
> > > > > The HID profile is implementation is under profiles/input/, it
> > > > > actually hooks with kernel HID drivers.
> > > > >
> > > > > If you just want to test it you should probably have a look at
> > > > > test-profile in python:
> > > >
> > > > Do you have any example invocations of test-profile for common profiles?
> > >
> > > test-profile is just a sample, but yes we do have many instances of
> > > common profiles using RegisterProfile:
> > >
> > > OBEX Daemon:
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/bluetooth.c#n256
> > >
> > > Ofono (HFP):
> > > https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/bluez5.c#n104
> > >
> > > PulseAudio (HSP):
> > > https://gitlab.freedesktop.org/pulseaudio/pulseaudio/blob/master/src/modules/bluetooth/backend-native.c#L332
> > >
> > > > It can be difficult to know where the issue is if you are not
> > > > confident with what settings should work.
> > >
> > > Well test-profile is not exactly a library just a convenient sample on
> > > how to use the interface, it was used mostly for testing SPP which is
> > > quite common way to register external profiles. HID is probably a no
> > > go due to reason already stated.
> > >
> > > > >
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> > > > >
> > > > > >   If so then I think it has been overcomplicated by this sdp profile?
> > > > > > How do I use the default in-built profile - is it just the uuid?
> > > > > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > >
> > > > > > > Hi Neil,
> > > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > > >
> > > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > > >
> > > > > > > I don't think that will work since the input plugin is already
> > > > > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > > > > parse the values from the record since you don't seem to be using the
> > > > > > > PSM:
> > > > > > >
> > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > > >
> > > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > > >
> > > > > > > > ---
> > > > > > > >     #listen for incoming client connections
> > > > > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > > > > >     #but that didn't seem to work
> > > > > > > >     def listen(self):
> > > > > > > >
> > > > > > > >         print("Waiting for connections")
> > > > > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > > > > >
> > > > > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > > > > >         #Start listening on the server sockets
> > > > > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > > > > >         self.sinterrupt.listen(1)
> > > > > > > >
> > > > > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > > > > >         self.controlClientMac = cinfo[0]
> > > > > > > >         self.controlClientPsm = cinfo[1]
> > > > > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > > > > str(self.controlClientPsm))
> > > > > > > >
> > > > > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > > > > >         self.interruptClientMac = cinfo[0]
> > > > > > > >         self.interruptClientPsm = cinfo[1]
> > > > > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > > > > str(self.interruptClientPsm))
> > > > > > > >
> > > > > > > >         thread.start_new_thread(self.check_connection, ())
> > > > > > > >
> > > > > > > >     def check_connection(self):
> > > > > > > >         halt = False
> > > > > > > >         while not halt:
> > > > > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > > > > >
> > > > > > > >             if self.controlClientMac in stdoutdata.split():
> > > > > > > >                 time.sleep(0.1)
> > > > > > > >             else:
> > > > > > > >                 print('got disconnection')
> > > > > > > >                 self.scontrol.shutdown(2);
> > > > > > > >                 self.sinterrupt.shutdown(2)
> > > > > > > >                 halt = True
> > > > > > > >         thread.start_new_thread(self.listen, ())
> > > > > > > >
> > > > > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > > > > see if anything is being sent but I can't see any bluez profile
> > > > > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > > > > is greatly appreciated.
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > >
> > > > > > > > Neil
> > > > > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > > > >
> > > > > > > > > Hi Neil,
> > > > > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > >
> > > > > > > > > > Hello,
> > > > > > > > > >
> > > > > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > > > > points up on Stack Overflow for any advice too!
> > > > > > > > > >
> > > > > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > > > > >
> > > > > > > > > > Cheers,
> > > > > > > > > >
> > > > > > > > > > Neil
> > > > > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hello,
> > > > > > > > > > >
> > > > > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > > > > the device using the following call:
> > > > > > > > > > > ---
> > > > > > > > > > >     #configure the bluetooth hardware device
> > > > > > > > > > >     def init_bt_device(self):
> > > > > > > > > > >
> > > > > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > > >
> > > > > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > > >
> > > > > > > > > > >         #make the device discoverable
> > > > > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > > > > >
> > > > > > > > >
> > > > > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > > > > >
> > > > > > > > > The class is automatically set by bluetoothd based on the
> > > > > > > > > services/profiles registered and the setting in the main.conf:
> > > > > > > > >
> > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > > > > >
> > > > > > > > > For the name use D-Bus property Alias:
> > > > > > > > >
> > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > > > > >
> > > > > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > > > > >
> > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > > > > ---
> > > > > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > > > > loaded service record
> > > > > > > > > > >     def init_bluez_profile(self):
> > > > > > > > > > >
> > > > > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > > > > >
> > > > > > > > > > >         #setup profile options
> > > > > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > > > > >
> > > > > > > > > > >         opts = {
> > > > > > > > > > >             "ServiceRecord":service_record,
> > > > > > > > > > >             "Role":"server",
> > > > > > > > > > >             "RequireAuthentication":False,
> > > > > > > > > > >             "RequireAuthorization":False,
> > > > > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > > > > >             "AutoConnect":True
> > > > > > > > > > >         }
> > > > > > > > > > >
> > > > > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > > > > >         bus = dbus.SystemBus()
> > > > > > > > > > >         self.manager =
> > > > > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > > > > >         print("Profile registered ")
> > > > > > > > > > > ---
> > > > > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > > > > the test-profile as shown below:
> > > > > > > > > > > ---
> > > > > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > > > > >     fd = -1
> > > > > > > > > > >
> > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > > >     def Release(self):
> > > > > > > > > > >             print("Release")
> > > > > > > > > > >             mainloop.quit()
> > > > > > > > > > >
> > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > > >     def Cancel(self):
> > > > > > > > > > >             print("Cancel")
> > > > > > > > > > >
> > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > > > > out_signature="")
> > > > > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > > > > >             self.fd = fd.take()
> > > > > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > > > > >             for key in properties.keys():
> > > > > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > > > > >                     else:
> > > > > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > > > > >
> > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > > > > out_signature="")
> > > > > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > > > > >
> > > > > > > > > > >             if (self.fd > 0):
> > > > > > > > > > >                     os.close(self.fd)
> > > > > > > > > > >                     self.fd = -1
> > > > > > > > > > >
> > > > > > > > > > >     def __init__(self, bus, path):
> > > > > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > > > > ---
> > > > > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > > > > callbacks on the profile are not being called.
> > > > > > > > >
> > > > > > > > > They would be called only when there is a connection to the profile,
> > > > > > > > > did you actually connect? If this is something like a serial port the
> > > > > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > > > > there.
> > > > > > > > >
> > > > > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > > > > most appreciated!
> > > > > > > > > > >
> > > > > > > > > > > Cheers,
> > > > > > > > > > >
> > > > > > > > > > > Neil
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > >
> > > > > > > > > > > Neil Benn MSc
> > > > > > > > > > > Ziath Ltd
> > > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > > http://www.ziath.com
> > > > > > > > > > >
> > > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > >
> > > > > > > > > > Neil Benn MSc
> > > > > > > > > > Ziath Ltd
> > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > http://www.ziath.com
> > > > > > > > > >
> > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > >
> > > > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > > > >
> > > > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Luiz Augusto von Dentz
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > Neil Benn MSc
> > > > > > > > Ziath Ltd
> > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > http://www.ziath.com
> > > > > > > >
> > > > > > > > Please consider the environment before printing this email.
> > > > > > > >
> > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > >
> > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Luiz Augusto von Dentz
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Neil Benn MSc
> > > > > > Ziath Ltd
> > > > > > Phone: +44 (0) 1223 855021
> > > > > > http://www.ziath.com
> > > > > >
> > > > > > Please consider the environment before printing this email.
> > > > > >
> > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > >
> > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > intended only for the use of the individual or entity to which it is
> > > > > > addressed, and may contain information that is privileged,
> > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > or agent responsible for delivering the message to the intended
> > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > If you have received this communication in error, please notify Ziath
> > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Luiz Augusto von Dentz
> > >
> > >
> > >
> > > --
> > > Luiz Augusto von Dentz
> >
> >
> >
> > --
> >
> > Neil Benn MSc
> > Ziath Ltd
> > Phone: +44 (0) 1223 855021
> > http://www.ziath.com
> >
> > Please consider the environment before printing this email.
> >
> > Follow us on Facebook, Twitter or LinkedIn
> >
> > IMPORTANT NOTICE: This message, including any attached documents, is
> > intended only for the use of the individual or entity to which it is
> > addressed, and may contain information that is privileged,
> > confidential and exempt from disclosure under applicable law. If the
> > reader of this message is not the intended recipient, or the employee
> > or agent responsible for delivering the message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly prohibited.
> > If you have received this communication in error, please notify Ziath
> > Ltd immediately by email at info@ziath.com. Thank you.
>
>
>
> --
> Luiz Augusto von Dentz



-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

* Re: Registering a profile
  2018-10-03 15:28                     ` Neil Benn
@ 2018-10-03 18:08                       ` Luiz Augusto von Dentz
  2018-10-03 18:45                         ` Neil Benn
  0 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-03 18:08 UTC (permalink / raw)
  To: neil.benn; +Cc: Barry Byford, linux-bluetooth

Hi Neil,

On Wed, Oct 3, 2018 at 6:28 PM Neil Benn <neil.benn@ziath.com> wrote:
>
> Hello,
>
>   I understand that which is why I didn't prusue it.  My guess is that
> the old code basically wasn't registering the profile so I guess that
> the PSMs were not taken and it explains why I could directly connect
> to the sockets via pyBluez - the issue here is that this was 'hacky'
> and there was no way I could rebind to a paired device after losing
> connection.
>
>   I tried with SPP with the following main.conf:
>
> Name = DataPaqWalk
> DiscoverableTimeout = 0
> PairableTimeout = 0
> ReconnectAttempts=7
> ReconnectIntervals=1,2,4,8,16,32,64
> AutoEnable=true
>
>   The code is now:
>
> ---
> #!/usr/bin/python
> #
> # YAPTB Bluetooth keyboard emulator DBUS Service
> #
> # Adapted from
> # www.linuxuser.co.uk/tutorials/emulate-bluetooth-keyboard-with-the-raspberry-pi
> #
> #
>
> #from __future__ import absolute_import, print_function, unicode_literals
> from __future__ import absolute_import, print_function
>
> import os
> import sys
> import uuid
> import dbus
> import dbus.service
> import dbus.mainloop.glib
> import time
> import bluetooth
> import thread
> import subprocess
> import traceback
> from bluetooth import *
>
> from dbus.mainloop.glib import DBusGMainLoop
>
> try:
>   from gi.repository import GObject
> except ImportError:
>   import gobject as GObject
>
> #
> #define a bluez 5 profile object for our keyboard
> #
> class BTKbBluezProfile(dbus.service.Object):
>     fd = -1
>
>     @dbus.service.method("org.bluez.Profile1",
>                                     in_signature="", out_signature="")
>     def Release(self):
>         print("Release")
>         mainloop.quit()
>
>     @dbus.service.method("org.bluez.Profile1",
>                                     in_signature="", out_signature="")
>     def Cancel(self):
>         print("Cancel")
>
>     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> out_signature="")
>     def NewConnection(self, path, fd, properties):
>         print ('NewConnection')
>         self.fd = fd.take()
>         print("NewConnection(%s, %d)" % (path, self.fd))
>         for key in properties.keys():
>                 print ('key ' + key + ' value ' + properties[key])
>                 if key == "Version" or key == "Features":
>                         print("  %s = 0x%04x" % (key, properties[key]))
>                 else:
>                         print("  %s = %s" % (key, properties[key]))
>
>
>
>     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> out_signature="")
>     def RequestDisconnection(self, path):
>             print("RequestDisconnection(%s)" % (path))
>
>             if (self.fd > 0):
>                     os.close(self.fd)
>                     self.fd = -1
>
>     def __init__(self, bus, path):
>             dbus.service.Object.__init__(self, bus, path)
>
>
> #
> #create a bluetooth device to emulate a HID keyboard,
> # advertize a SDP record using our bluez profile class
> #
> class BTKbDevice():
>
>     #define some constants
>     P_CTRL =17  #Service port - must match port configured in SDP record
>     P_INTR =19  #Interrrupt port - must match port configured in SDP record
>     PROFILE_DBUS_PATH="/bluez/yaptb/btkb_profile" #dbus path of  the
> bluez profile we will create
>     UUID='00001101-0000-1000-8000-00805f9b34fb'
>     #UUID="00001124-0000-1000-8000-00805f9b34fb"
>
>
>     def __init__(self):
>
>         print("Setting up BT device")
>         self.init_bluez_profile()
>
>
>     #set up a bluez profile to advertise device capabilities from a
> loaded service record
>     def init_bluez_profile(self):
>
>         bus = dbus.SystemBus()
>
>         print ("setting adapter to discoverable")
>         self.adapter =
> dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> "org.bluez.Adapter1")
>         self.adapter.Discoverable = True
>
>         print("Configuring Bluez Profile")
>
>         opts = {
>             "Role":"server"
>         }

No PSM/Channel, how do you expect the remote device to connect to you?

>         self.manager =
> dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> "org.bluez.ProfileManager1")
>         self.profile = BTKbBluezProfile(bus,
> BTKbDevice.PROFILE_DBUS_PATH)#BTKbDevice.PROFILE_DBUS_PATH)
>         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> BTKbDevice.UUID, opts)
>         print("Profile registered ")
>
>     #send a string to the bluetooth host machine
>     def send_string(self,message):
>          self.cinterrupt.send(message)
>
>
> #define a dbus service that emulates a bluetooth keyboard
> #this will enable different clients to connect to and use
> #the service
> class BTKbService(dbus.service.Object):
>
>     def __init__(self):
>
>         print("Setting up service")
>         bus = dbus.SystemBus()
>         #set up as a dbus service
>         bus_name=dbus.service.BusName("org.yaptb.btkbservice",bus)
>         dbus.service.Object.__init__(self,bus_name,"/org/yaptb/btkbservice")
>         self.device= BTKbDevice();
>
>
>     @dbus.service.method('org.yaptb.btkbservice', in_signature='yay')
>     def send_keys(self,modifier_byte,keys):
>         cmd_str=""
>         cmd_str+=chr(0xA1)
>         cmd_str+=chr(0x01)
>         cmd_str+=chr(modifier_byte)
>         cmd_str+=chr(0x00)
>
>         count=0
>         for key_code in keys:
>             if(count<6):
>                 cmd_str+=chr(key_code)
>             count+=1
>
>         self.device.send_string(cmd_str);
>
>
>
> #main routine
> if __name__ == "__main__":
>     mainloop = GObject.MainLoop()
>     # we an only run as root
>     if not os.geteuid() == 0:
>        sys.exit("Only root can run this script")
>
>     DBusGMainLoop(set_as_default=True)
>     myservice = BTKbService();
>     mainloop.run()
> ---
>
>   This does the same as for an HID; no events are fired on the dbus;
> bluetoothd gives:
>
> bluetoothd[651]: src/adapter.c:connected_callback() hci0 device
> C8:FF:28:79:05:D4 connected eir_len 5
> bluetoothd[651]: src/adapter.c:new_link_key_callback() hci0 new key
> for C8:FF:28:79:05:D4 type 4 pin_len 0 store_hint 1
> bluetoothd[651]: src/device.c:device_set_bonded()
> bluetoothd[651]: src/device.c:device_bonding_complete() bonding (nil)
> status 0x00
> bluetoothd[651]: src/adapter.c:resume_discovery()
> bluetoothd[651]: src/adapter.c:dev_disconnected() Device
> C8:FF:28:79:05:D4 disconnected, reason 3
> bluetoothd[651]: src/adapter.c:adapter_remove_connection()
> bluetoothd[651]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr
> C8:FF:28:79:05:D4 type 0 status 0xe
> bluetoothd[651]: src/device.c:device_bonding_complete() bonding (nil)
> status 0x0e
> bluetoothd[651]: src/device.c:device_bonding_failed() status 14
> bluetoothd[651]: src/adapter.c:resume_discovery()
>
>   The device itself connects and disconnects after a second or so:
>
> [bluetooth]# discoverable on
> Changing discoverable on succeeded
> [bluetooth]# power on
> Changing power on succeeded
> [CHG] Controller B8:27:EB:14:FB:B1 Powered: yes
> [CHG] Device C8:FF:28:79:05:D4 Connected: yes
> [CHG] Device C8:FF:28:79:05:D4 Connected: no
> [bluetooth]#
>
>   So I'm getting the same thing.  In the longer run I'll need HID
> because I'm making a HID device; maybe as you say I can disable the
> input plugin and connect the PSM but I'll still need to capture the
> connected/disconnected events.  Sorry to keep posting; your help is
> very much appreciated - as I said; I will return the code back when it
> is working.  Any ideas?

ACL link does not mean it is connected to your profile, since you
don't register any all your profile does is expose a SDP record which
by itself don't allow any connections. I had at least 3 examples on
how profiles are using the interface, had you look at that? The only
difference is that they are in C but the usage is pretty similar, note
though that you need a conterpart that do lookup for the SDP record
and connect to the PSM/Channel. Also no need to keep pasting the same
code over and over, it is quite clear it is not working, what you
should be looking for is HCI trace of what the remote is trying to do
when connecting, usually it start by doing a SDP search for the UUIDs
it want to connect followed by L2CAP/RFCOMM connection.

>   Thanks.
>
> Cheers,
>
> Neil
> On Wed, 3 Oct 2018 at 15:04, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > Hi Neil,
> > On Wed, Oct 3, 2018 at 4:49 PM Neil Benn <neil.benn@ziath.com> wrote:
> > >
> > > Hello,
> > >
> > >   Thanks; I followed Barry's example on making the device discoverable
> > > via bluetoothd and that can now be found so the profile is registered
> > > without needing the sdp_record.  However the profile isn't getting
> > > callbacks still except in one case where I kill the bluetoothd process
> > > and the release method on the profile is called which is strange.
> > >
> > >   Looking at the output from dbus when a connection happens; we have
> > > the following:
> > >
> > > signal time=1538574206.428425 sender=:1.0 -> destination=(null
> > > destination) serial=314 path=/org/freedesktop/systemd1;
> > > interface=org.freedesktop.systemd1.Manager; member=UnitNew
> > >    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
> > >    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> > > signal time=1538574206.431862 sender=:1.0 -> destination=(null
> > > destination) serial=315 path=/org/freedesktop/systemd1;
> > > interface=org.freedesktop.systemd1.Manager; member=UnitNew
> > >    string "sys-subsystem-bluetooth-devices-hci0:11.device"
> > >    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> > > signal time=1538574206.463318 sender=:1.22 -> destination=(null
> > > destination) serial=17 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > >    string "org.bluez.Device1"
> > >    array [
> > >       dict entry(
> > >          string "Connected"
> > >          variant             boolean true
> > >       )
> > >    ]
> > >    array [
> > >    ]
> > > signal time=1538574210.618465 sender=:1.22 -> destination=(null
> > > destination) serial=18 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > >    string "org.bluez.Device1"
> > >    array [
> > >       dict entry(
> > >          string "Connected"
> > >          variant             boolean false
> > >       )
> > >    ]
> > >    array [
> > >    ]
> > > signal time=1538574210.629705 sender=:1.0 -> destination=(null
> > > destination) serial=316
> > > path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > >    string "org.freedesktop.systemd1.Device"
> > >    array [
> > >       dict entry(
> > >          string "SysFSPath"
> > >          variant             string
> > > "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
> > >       )
> > >    ]
> > >    array [
> > >    ]
> > > signal time=1538574210.640715 sender=:1.0 -> destination=(null
> > > destination) serial=317
> > > path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > >    string "org.freedesktop.systemd1.Unit"
> > >    array [
> > >       dict entry(
> > >          string "ActiveState"
> > >          variant             string "inactive"
> > >       )
> > >       dict entry(
> > >          string "SubState"
> > >          variant             string "dead"
> > >       )
> > >       dict entry(
> > >          string "StateChangeTimestamp"
> > >          variant             uint64 1538574210626509
> > >       )
> > >       dict entry(
> > >          string "StateChangeTimestampMonotonic"
> > >          variant             uint64 2940864110
> > >       )
> > >       dict entry(
> > >          string "InactiveExitTimestamp"
> > >          variant             uint64 1538574206426852
> > >       )
> > >       dict entry(
> > >          string "InactiveExitTimestampMonotonic"
> > >          variant             uint64 2936664452
> > >       )
> > >       dict entry(
> > >          string "ActiveEnterTimestamp"
> > >          variant             uint64 1538574206426852
> > >       )
> > >       dict entry(
> > >          string "ActiveEnterTimestampMonotonic"
> > >          variant             uint64 2936664452
> > >       )
> > >       dict entry(
> > >          string "ActiveExitTimestamp"
> > >          variant             uint64 1538574210626509
> > >       )
> > >       dict entry(
> > >          string "ActiveExitTimestampMonotonic"
> > >          variant             uint64 2940864110
> > >       )
> > >       dict entry(
> > >          string "InactiveEnterTimestamp"
> > >          variant             uint64 1538574210626509
> > >       )
> > >       dict entry(
> > >          string "InactiveEnterTimestampMonotonic"
> > >          variant             uint64 2940864110
> > >       )
> > >       dict entry(
> > >          string "Job"
> > >          variant             struct {
> > >                uint32 0
> > >                object path "/"
> > >             }
> > >       )
> > >       dict entry(
> > >          string "ConditionResult"
> > >          variant             boolean false
> > >       )
> > >       dict entry(
> > >          string "AssertResult"
> > >          variant             boolean false
> > >       )
> > >       dict entry(
> > >          string "ConditionTimestamp"
> > >          variant             uint64 0
> > >       )
> > >       dict entry(
> > >          string "ConditionTimestampMonotonic"
> > >          variant             uint64 0
> > >       )
> > >       dict entry(
> > >          string "AssertTimestamp"
> > >          variant             uint64 0
> > >       )
> > >       dict entry(
> > >          string "AssertTimestampMonotonic"
> > >          variant             uint64 0
> > >       )
> > >    ]
> > >    array [
> > >    ]
> > > signal time=1538574210.668073 sender=:1.0 -> destination=(null
> > > destination) serial=318 path=/org/freedesktop/systemd1;
> > > interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
> > >    string "sys-subsystem-bluetooth-devices-hci0:11.device"
> > >    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> > > signal time=1538574210.670654 sender=:1.0 -> destination=(null
> > > destination) serial=319
> > > path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > >    string "org.freedesktop.systemd1.Device"
> > >    array [
> > >       dict entry(
> > >          string "SysFSPath"
> > >          variant             string
> > > "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
> > >       )
> > >    ]
> > >    array [
> > >    ]
> > > signal time=1538574210.677890 sender=:1.0 -> destination=(null
> > > destination) serial=320
> > > path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > >    string "org.freedesktop.systemd1.Unit"
> > >    array [
> > >       dict entry(
> > >          string "ActiveState"
> > >          variant             string "inactive"
> > >       )
> > >       dict entry(
> > >          string "SubState"
> > >          variant             string "dead"
> > >       )
> > >       dict entry(
> > >          string "StateChangeTimestamp"
> > >          variant             uint64 1538574210626572
> > >       )
> > >       dict entry(
> > >          string "StateChangeTimestampMonotonic"
> > >          variant             uint64 2940864171
> > >       )
> > >       dict entry(
> > >          string "InactiveExitTimestamp"
> > >          variant             uint64 1538574206426942
> > >       )
> > >       dict entry(
> > >          string "InactiveExitTimestampMonotonic"
> > >          variant             uint64 2936664542
> > >       )
> > >       dict entry(
> > >          string "ActiveEnterTimestamp"
> > >          variant             uint64 1538574206426942
> > >       )
> > >       dict entry(
> > >          string "ActiveEnterTimestampMonotonic"
> > >          variant             uint64 2936664542
> > >       )
> > >       dict entry(
> > >          string "ActiveExitTimestamp"
> > >          variant             uint64 1538574210626572
> > >       )
> > >       dict entry(
> > >          string "ActiveExitTimestampMonotonic"
> > >          variant             uint64 2940864171
> > >       )
> > >       dict entry(
> > >          string "InactiveEnterTimestamp"
> > >          variant             uint64 1538574210626572
> > >       )
> > >       dict entry(
> > >          string "InactiveEnterTimestampMonotonic"
> > >          variant             uint64 2940864171
> > >       )
> > >       dict entry(
> > >          string "Job"
> > >          variant             struct {
> > >                uint32 0
> > >                object path "/"
> > >             }
> > >       )
> > >       dict entry(
> > >          string "ConditionResult"
> > >          variant             boolean false
> > >       )
> > >       dict entry(
> > >          string "AssertResult"
> > >          variant             boolean false
> > >       )
> > >       dict entry(
> > >          string "ConditionTimestamp"
> > >          variant             uint64 0
> > >       )
> > >       dict entry(
> > >          string "ConditionTimestampMonotonic"
> > >          variant             uint64 0
> > >       )
> > >       dict entry(
> > >          string "AssertTimestamp"
> > >          variant             uint64 0
> > >       )
> > >       dict entry(
> > >          string "AssertTimestampMonotonic"
> > >          variant             uint64 0
> > >       )
> > >    ]
> > >    array [
> > >    ]
> > > signal time=1538574210.699336 sender=:1.0 -> destination=(null
> > > destination) serial=321 path=/org/freedesktop/systemd1;
> > > interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
> > >    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
> > >    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> > >
> > >   So there are events being fired just not the ones that connect to my
> > > registered profile.  In addition I've tried to register the profile
> > > and listen for connections on the device PSM of 17 and 19 which HID
> > > uses but nothing happens there either - though I'm not sure this is
> > > the best way to communicate as it feels 'wrong' tbh.
> >
> > Have you read my responses? It _wont_ work for these PSMs, those are
> > already taken by the daemon except if you are not loading the input
> > plugin. Can't you try with something simpler like SPP, which is what
> > this interface is for?
> >
> > >   Thanks again - I'm still basically not getting any events fired on
> > > the profile except for Release which isn't really that useful as it
> > > only notifies me if the bluetooth stack goes down!
> > >
> > >   Any ideas?
> > >
> > > Cheers,
> > >
> > > Neil
> > > On Wed, 3 Oct 2018 at 11:35, Luiz Augusto von Dentz
> > > <luiz.dentz@gmail.com> wrote:
> > > >
> > > > Hi Barry,
> > > > On Tue, Oct 2, 2018 at 5:57 PM Barry Byford <31baz66@gmail.com> wrote:
> > > > >
> > > > > Hi Luiz,
> > > > >
> > > > > On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> > > > > <luiz.dentz@gmail.com> wrote:
> > > > > >
> > > > > > Hi Neil,
> > > > > > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > >   Thanks for that please see inline below:
> > > > > > >
> > > > > > >
> > > > > > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > > > > > >
> > > > > > > > Hi Neil,
> > > > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > >
> > > > > > > > > Hello,
> > > > > > > > >
> > > > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > > > >
> > > > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > > > >
> > > > > > > > I don't think that will work since the input plugin is already
> > > > > > > > listening in those PSM,
> > > > > > >
> > > > > > > It does connect and work but it doesn't register the profile.  If I
> > > > > > > don't register the profile the default name in the config is used
> > > > > > > >
> > > > > > > > in fact I don't think RegisterProfile would
> > > > > > > > parse the values from the record since you don't seem to be using the
> > > > > > > > PSM:
> > > > > > > >
> > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > > >
> > > > > > >
> > > > > > > The PSM is defined in the service record
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > > >
> > > > > > > I'm using an sdp profile provided in some sample code I found, is
> > > > > > > there a default one that is supported?  Is that default one selected
> > > > > > > when I pick my uuid?
> > > > > >
> > > > > > You are not suppose to use existing UUIDs that the daemon already
> > > > > > registers, the fact that you are able to register it without cause a
> > > > > > problem might be a bug and we should probably check if the UUID is
> > > > > > already registered and fail if it does.
> > > > > >
> > > > > > The HID profile is implementation is under profiles/input/, it
> > > > > > actually hooks with kernel HID drivers.
> > > > > >
> > > > > > If you just want to test it you should probably have a look at
> > > > > > test-profile in python:
> > > > >
> > > > > Do you have any example invocations of test-profile for common profiles?
> > > >
> > > > test-profile is just a sample, but yes we do have many instances of
> > > > common profiles using RegisterProfile:
> > > >
> > > > OBEX Daemon:
> > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/bluetooth.c#n256
> > > >
> > > > Ofono (HFP):
> > > > https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/bluez5.c#n104
> > > >
> > > > PulseAudio (HSP):
> > > > https://gitlab.freedesktop.org/pulseaudio/pulseaudio/blob/master/src/modules/bluetooth/backend-native.c#L332
> > > >
> > > > > It can be difficult to know where the issue is if you are not
> > > > > confident with what settings should work.
> > > >
> > > > Well test-profile is not exactly a library just a convenient sample on
> > > > how to use the interface, it was used mostly for testing SPP which is
> > > > quite common way to register external profiles. HID is probably a no
> > > > go due to reason already stated.
> > > >
> > > > > >
> > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> > > > > >
> > > > > > >   If so then I think it has been overcomplicated by this sdp profile?
> > > > > > > How do I use the default in-built profile - is it just the uuid?
> > > > > > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > > >
> > > > > > > > Hi Neil,
> > > > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > >
> > > > > > > > > Hello,
> > > > > > > > >
> > > > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > > > >
> > > > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > > > >
> > > > > > > > I don't think that will work since the input plugin is already
> > > > > > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > > > > > parse the values from the record since you don't seem to be using the
> > > > > > > > PSM:
> > > > > > > >
> > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > > > >
> > > > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > > > >
> > > > > > > > > ---
> > > > > > > > >     #listen for incoming client connections
> > > > > > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > > > > > >     #but that didn't seem to work
> > > > > > > > >     def listen(self):
> > > > > > > > >
> > > > > > > > >         print("Waiting for connections")
> > > > > > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > > > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > > > > > >
> > > > > > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > > > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > > > > > >         #Start listening on the server sockets
> > > > > > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > > > > > >         self.sinterrupt.listen(1)
> > > > > > > > >
> > > > > > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > > > > > >         self.controlClientMac = cinfo[0]
> > > > > > > > >         self.controlClientPsm = cinfo[1]
> > > > > > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > > > > > str(self.controlClientPsm))
> > > > > > > > >
> > > > > > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > > > > > >         self.interruptClientMac = cinfo[0]
> > > > > > > > >         self.interruptClientPsm = cinfo[1]
> > > > > > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > > > > > str(self.interruptClientPsm))
> > > > > > > > >
> > > > > > > > >         thread.start_new_thread(self.check_connection, ())
> > > > > > > > >
> > > > > > > > >     def check_connection(self):
> > > > > > > > >         halt = False
> > > > > > > > >         while not halt:
> > > > > > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > > > > > >
> > > > > > > > >             if self.controlClientMac in stdoutdata.split():
> > > > > > > > >                 time.sleep(0.1)
> > > > > > > > >             else:
> > > > > > > > >                 print('got disconnection')
> > > > > > > > >                 self.scontrol.shutdown(2);
> > > > > > > > >                 self.sinterrupt.shutdown(2)
> > > > > > > > >                 halt = True
> > > > > > > > >         thread.start_new_thread(self.listen, ())
> > > > > > > > >
> > > > > > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > > > > > see if anything is being sent but I can't see any bluez profile
> > > > > > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > > > > > is greatly appreciated.
> > > > > > > > >
> > > > > > > > > Cheers,
> > > > > > > > >
> > > > > > > > > Neil
> > > > > > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Neil,
> > > > > > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hello,
> > > > > > > > > > >
> > > > > > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > > > > > points up on Stack Overflow for any advice too!
> > > > > > > > > > >
> > > > > > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > > > > > >
> > > > > > > > > > > Cheers,
> > > > > > > > > > >
> > > > > > > > > > > Neil
> > > > > > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hello,
> > > > > > > > > > > >
> > > > > > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > > > > > the device using the following call:
> > > > > > > > > > > > ---
> > > > > > > > > > > >     #configure the bluetooth hardware device
> > > > > > > > > > > >     def init_bt_device(self):
> > > > > > > > > > > >
> > > > > > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > > > >
> > > > > > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > > > >
> > > > > > > > > > > >         #make the device discoverable
> > > > > > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > > > > > >
> > > > > > > > > > The class is automatically set by bluetoothd based on the
> > > > > > > > > > services/profiles registered and the setting in the main.conf:
> > > > > > > > > >
> > > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > > > > > >
> > > > > > > > > > For the name use D-Bus property Alias:
> > > > > > > > > >
> > > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > > > > > >
> > > > > > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > > > > > >
> > > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > > > > > ---
> > > > > > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > > > > > loaded service record
> > > > > > > > > > > >     def init_bluez_profile(self):
> > > > > > > > > > > >
> > > > > > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > > > > > >
> > > > > > > > > > > >         #setup profile options
> > > > > > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > > > > > >
> > > > > > > > > > > >         opts = {
> > > > > > > > > > > >             "ServiceRecord":service_record,
> > > > > > > > > > > >             "Role":"server",
> > > > > > > > > > > >             "RequireAuthentication":False,
> > > > > > > > > > > >             "RequireAuthorization":False,
> > > > > > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > > > > > >             "AutoConnect":True
> > > > > > > > > > > >         }
> > > > > > > > > > > >
> > > > > > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > > > > > >         bus = dbus.SystemBus()
> > > > > > > > > > > >         self.manager =
> > > > > > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > > > > > >         print("Profile registered ")
> > > > > > > > > > > > ---
> > > > > > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > > > > > the test-profile as shown below:
> > > > > > > > > > > > ---
> > > > > > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > > > > > >     fd = -1
> > > > > > > > > > > >
> > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > > > >     def Release(self):
> > > > > > > > > > > >             print("Release")
> > > > > > > > > > > >             mainloop.quit()
> > > > > > > > > > > >
> > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > > > >     def Cancel(self):
> > > > > > > > > > > >             print("Cancel")
> > > > > > > > > > > >
> > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > > > > > out_signature="")
> > > > > > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > > > > > >             self.fd = fd.take()
> > > > > > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > > > > > >             for key in properties.keys():
> > > > > > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > > > > > >                     else:
> > > > > > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > > > > > >
> > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > > > > > out_signature="")
> > > > > > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > > > > > >
> > > > > > > > > > > >             if (self.fd > 0):
> > > > > > > > > > > >                     os.close(self.fd)
> > > > > > > > > > > >                     self.fd = -1
> > > > > > > > > > > >
> > > > > > > > > > > >     def __init__(self, bus, path):
> > > > > > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > > > > > ---
> > > > > > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > > > > > callbacks on the profile are not being called.
> > > > > > > > > >
> > > > > > > > > > They would be called only when there is a connection to the profile,
> > > > > > > > > > did you actually connect? If this is something like a serial port the
> > > > > > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > > > > > there.
> > > > > > > > > >
> > > > > > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > > > > > most appreciated!
> > > > > > > > > > > >
> > > > > > > > > > > > Cheers,
> > > > > > > > > > > >
> > > > > > > > > > > > Neil
> > > > > > > > > > > >
> > > > > > > > > > > > --
> > > > > > > > > > > >
> > > > > > > > > > > > Neil Benn MSc
> > > > > > > > > > > > Ziath Ltd
> > > > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > > > http://www.ziath.com
> > > > > > > > > > > >
> > > > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > >
> > > > > > > > > > > Neil Benn MSc
> > > > > > > > > > > Ziath Ltd
> > > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > > http://www.ziath.com
> > > > > > > > > > >
> > > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > > >
> > > > > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > > > > >
> > > > > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Luiz Augusto von Dentz
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > > Neil Benn MSc
> > > > > > > > > Ziath Ltd
> > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > http://www.ziath.com
> > > > > > > > >
> > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > >
> > > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > > >
> > > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Luiz Augusto von Dentz
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Neil Benn MSc
> > > > > > > Ziath Ltd
> > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > http://www.ziath.com
> > > > > > >
> > > > > > > Please consider the environment before printing this email.
> > > > > > >
> > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > >
> > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > addressed, and may contain information that is privileged,
> > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Luiz Augusto von Dentz
> > > >
> > > >
> > > >
> > > > --
> > > > Luiz Augusto von Dentz
> > >
> > >
> > >
> > > --
> > >
> > > Neil Benn MSc
> > > Ziath Ltd
> > > Phone: +44 (0) 1223 855021
> > > http://www.ziath.com
> > >
> > > Please consider the environment before printing this email.
> > >
> > > Follow us on Facebook, Twitter or LinkedIn
> > >
> > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > intended only for the use of the individual or entity to which it is
> > > addressed, and may contain information that is privileged,
> > > confidential and exempt from disclosure under applicable law. If the
> > > reader of this message is not the intended recipient, or the employee
> > > or agent responsible for delivering the message to the intended
> > > recipient, you are hereby notified that any dissemination,
> > > distribution or copying of this communication is strictly prohibited.
> > > If you have received this communication in error, please notify Ziath
> > > Ltd immediately by email at info@ziath.com. Thank you.
> >
> >
> >
> > --
> > Luiz Augusto von Dentz
>
>
>
> --
>
> Neil Benn MSc
> Ziath Ltd
> Phone: +44 (0) 1223 855021
> http://www.ziath.com
>
> Please consider the environment before printing this email.
>
> Follow us on Facebook, Twitter or LinkedIn
>
> IMPORTANT NOTICE: This message, including any attached documents, is
> intended only for the use of the individual or entity to which it is
> addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law. If the
> reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify Ziath
> Ltd immediately by email at info@ziath.com. Thank you.



-- 
Luiz Augusto von Dentz

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

* Re: Registering a profile
  2018-10-03 18:08                       ` Luiz Augusto von Dentz
@ 2018-10-03 18:45                         ` Neil Benn
  0 siblings, 0 replies; 15+ messages in thread
From: Neil Benn @ 2018-10-03 18:45 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Barry Byford, linux-bluetooth

Hello,

  Thanks; apologies for the code - I was just trying to be explicit;
other linux forums I've used before in the past have said that if I
don't post the code they won't respond; I agree it is verbose!  On the
code you posted; I've studied it and to be honest - I can't see any
difference between the code you've pasted and what the Python code is
doing.  The issue is that the C examples are quite different and this
is what I've understood from the examples:

- the OBEX one is registering a service record which goes back to
where I first had a problem plus it is OBEX but the concept of
listening for the bluetooth to come up and down is something I can
make use of later
- the ofono seems to make a simple registration (again similar to the
python code) though the device_send_message is something interesting
that I was going to come back to later
- the pulseaudio one again sends a path and uuid followed by options
but there is nothing I can see there that affects me.
- the hfp example at
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-hfp
is very useful as it gives guidance as to how to use the
filedescriptor returned on newconnection but this goes counter to the
send_device method on ofono which; if I am reading it correctly; seems
a better way to send a message

  What is interesting in the C examples is that the calls are all
async; maybe the python dbus library is not returning the calls
correctly.  Reading these examples is good and it really helps me
understand items for the future.

  Right now the counterpart connecting to my device is a windows PC;
I'm going to switch to a linux PC on the other side so I can get
logging and try again - I'll also put the interrupt channel in to the
connection and if that does not work then the control channel.  I
thought that this was defined in the profile as it was in the
sdp_record so I didn't add it in.

  Thanks.

Cheers,

Neil
On Wed, 3 Oct 2018 at 19:08, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Neil,
>
> On Wed, Oct 3, 2018 at 6:28 PM Neil Benn <neil.benn@ziath.com> wrote:
> >
> > Hello,
> >
> >   I understand that which is why I didn't prusue it.  My guess is that
> > the old code basically wasn't registering the profile so I guess that
> > the PSMs were not taken and it explains why I could directly connect
> > to the sockets via pyBluez - the issue here is that this was 'hacky'
> > and there was no way I could rebind to a paired device after losing
> > connection.
> >
> >   I tried with SPP with the following main.conf:
> >
> > Name = DataPaqWalk
> > DiscoverableTimeout = 0
> > PairableTimeout = 0
> > ReconnectAttempts=7
> > ReconnectIntervals=1,2,4,8,16,32,64
> > AutoEnable=true
> >
> >   The code is now:
> >
> > ---
> > #!/usr/bin/python
> > #
> > # YAPTB Bluetooth keyboard emulator DBUS Service
> > #
> > # Adapted from
> > # www.linuxuser.co.uk/tutorials/emulate-bluetooth-keyboard-with-the-raspberry-pi
> > #
> > #
> >
> > #from __future__ import absolute_import, print_function, unicode_literals
> > from __future__ import absolute_import, print_function
> >
> > import os
> > import sys
> > import uuid
> > import dbus
> > import dbus.service
> > import dbus.mainloop.glib
> > import time
> > import bluetooth
> > import thread
> > import subprocess
> > import traceback
> > from bluetooth import *
> >
> > from dbus.mainloop.glib import DBusGMainLoop
> >
> > try:
> >   from gi.repository import GObject
> > except ImportError:
> >   import gobject as GObject
> >
> > #
> > #define a bluez 5 profile object for our keyboard
> > #
> > class BTKbBluezProfile(dbus.service.Object):
> >     fd = -1
> >
> >     @dbus.service.method("org.bluez.Profile1",
> >                                     in_signature="", out_signature="")
> >     def Release(self):
> >         print("Release")
> >         mainloop.quit()
> >
> >     @dbus.service.method("org.bluez.Profile1",
> >                                     in_signature="", out_signature="")
> >     def Cancel(self):
> >         print("Cancel")
> >
> >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > out_signature="")
> >     def NewConnection(self, path, fd, properties):
> >         print ('NewConnection')
> >         self.fd = fd.take()
> >         print("NewConnection(%s, %d)" % (path, self.fd))
> >         for key in properties.keys():
> >                 print ('key ' + key + ' value ' + properties[key])
> >                 if key == "Version" or key == "Features":
> >                         print("  %s = 0x%04x" % (key, properties[key]))
> >                 else:
> >                         print("  %s = %s" % (key, properties[key]))
> >
> >
> >
> >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > out_signature="")
> >     def RequestDisconnection(self, path):
> >             print("RequestDisconnection(%s)" % (path))
> >
> >             if (self.fd > 0):
> >                     os.close(self.fd)
> >                     self.fd = -1
> >
> >     def __init__(self, bus, path):
> >             dbus.service.Object.__init__(self, bus, path)
> >
> >
> > #
> > #create a bluetooth device to emulate a HID keyboard,
> > # advertize a SDP record using our bluez profile class
> > #
> > class BTKbDevice():
> >
> >     #define some constants
> >     P_CTRL =17  #Service port - must match port configured in SDP record
> >     P_INTR =19  #Interrrupt port - must match port configured in SDP record
> >     PROFILE_DBUS_PATH="/bluez/yaptb/btkb_profile" #dbus path of  the
> > bluez profile we will create
> >     UUID='00001101-0000-1000-8000-00805f9b34fb'
> >     #UUID="00001124-0000-1000-8000-00805f9b34fb"
> >
> >
> >     def __init__(self):
> >
> >         print("Setting up BT device")
> >         self.init_bluez_profile()
> >
> >
> >     #set up a bluez profile to advertise device capabilities from a
> > loaded service record
> >     def init_bluez_profile(self):
> >
> >         bus = dbus.SystemBus()
> >
> >         print ("setting adapter to discoverable")
> >         self.adapter =
> > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > "org.bluez.Adapter1")
> >         self.adapter.Discoverable = True
> >
> >         print("Configuring Bluez Profile")
> >
> >         opts = {
> >             "Role":"server"
> >         }
>
> No PSM/Channel, how do you expect the remote device to connect to you?
>
> >         self.manager =
> > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > "org.bluez.ProfileManager1")
> >         self.profile = BTKbBluezProfile(bus,
> > BTKbDevice.PROFILE_DBUS_PATH)#BTKbDevice.PROFILE_DBUS_PATH)
> >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > BTKbDevice.UUID, opts)
> >         print("Profile registered ")
> >
> >     #send a string to the bluetooth host machine
> >     def send_string(self,message):
> >          self.cinterrupt.send(message)
> >
> >
> > #define a dbus service that emulates a bluetooth keyboard
> > #this will enable different clients to connect to and use
> > #the service
> > class BTKbService(dbus.service.Object):
> >
> >     def __init__(self):
> >
> >         print("Setting up service")
> >         bus = dbus.SystemBus()
> >         #set up as a dbus service
> >         bus_name=dbus.service.BusName("org.yaptb.btkbservice",bus)
> >         dbus.service.Object.__init__(self,bus_name,"/org/yaptb/btkbservice")
> >         self.device= BTKbDevice();
> >
> >
> >     @dbus.service.method('org.yaptb.btkbservice', in_signature='yay')
> >     def send_keys(self,modifier_byte,keys):
> >         cmd_str=""
> >         cmd_str+=chr(0xA1)
> >         cmd_str+=chr(0x01)
> >         cmd_str+=chr(modifier_byte)
> >         cmd_str+=chr(0x00)
> >
> >         count=0
> >         for key_code in keys:
> >             if(count<6):
> >                 cmd_str+=chr(key_code)
> >             count+=1
> >
> >         self.device.send_string(cmd_str);
> >
> >
> >
> > #main routine
> > if __name__ == "__main__":
> >     mainloop = GObject.MainLoop()
> >     # we an only run as root
> >     if not os.geteuid() == 0:
> >        sys.exit("Only root can run this script")
> >
> >     DBusGMainLoop(set_as_default=True)
> >     myservice = BTKbService();
> >     mainloop.run()
> > ---
> >
> >   This does the same as for an HID; no events are fired on the dbus;
> > bluetoothd gives:
> >
> > bluetoothd[651]: src/adapter.c:connected_callback() hci0 device
> > C8:FF:28:79:05:D4 connected eir_len 5
> > bluetoothd[651]: src/adapter.c:new_link_key_callback() hci0 new key
> > for C8:FF:28:79:05:D4 type 4 pin_len 0 store_hint 1
> > bluetoothd[651]: src/device.c:device_set_bonded()
> > bluetoothd[651]: src/device.c:device_bonding_complete() bonding (nil)
> > status 0x00
> > bluetoothd[651]: src/adapter.c:resume_discovery()
> > bluetoothd[651]: src/adapter.c:dev_disconnected() Device
> > C8:FF:28:79:05:D4 disconnected, reason 3
> > bluetoothd[651]: src/adapter.c:adapter_remove_connection()
> > bluetoothd[651]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr
> > C8:FF:28:79:05:D4 type 0 status 0xe
> > bluetoothd[651]: src/device.c:device_bonding_complete() bonding (nil)
> > status 0x0e
> > bluetoothd[651]: src/device.c:device_bonding_failed() status 14
> > bluetoothd[651]: src/adapter.c:resume_discovery()
> >
> >   The device itself connects and disconnects after a second or so:
> >
> > [bluetooth]# discoverable on
> > Changing discoverable on succeeded
> > [bluetooth]# power on
> > Changing power on succeeded
> > [CHG] Controller B8:27:EB:14:FB:B1 Powered: yes
> > [CHG] Device C8:FF:28:79:05:D4 Connected: yes
> > [CHG] Device C8:FF:28:79:05:D4 Connected: no
> > [bluetooth]#
> >
> >   So I'm getting the same thing.  In the longer run I'll need HID
> > because I'm making a HID device; maybe as you say I can disable the
> > input plugin and connect the PSM but I'll still need to capture the
> > connected/disconnected events.  Sorry to keep posting; your help is
> > very much appreciated - as I said; I will return the code back when it
> > is working.  Any ideas?
>
> ACL link does not mean it is connected to your profile, since you
> don't register any all your profile does is expose a SDP record which
> by itself don't allow any connections. I had at least 3 examples on
> how profiles are using the interface, had you look at that? The only
> difference is that they are in C but the usage is pretty similar, note
> though that you need a conterpart that do lookup for the SDP record
> and connect to the PSM/Channel. Also no need to keep pasting the same
> code over and over, it is quite clear it is not working, what you
> should be looking for is HCI trace of what the remote is trying to do
> when connecting, usually it start by doing a SDP search for the UUIDs
> it want to connect followed by L2CAP/RFCOMM connection.
>
> >   Thanks.
> >
> > Cheers,
> >
> > Neil
> > On Wed, 3 Oct 2018 at 15:04, Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Neil,
> > > On Wed, Oct 3, 2018 at 4:49 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > >   Thanks; I followed Barry's example on making the device discoverable
> > > > via bluetoothd and that can now be found so the profile is registered
> > > > without needing the sdp_record.  However the profile isn't getting
> > > > callbacks still except in one case where I kill the bluetoothd process
> > > > and the release method on the profile is called which is strange.
> > > >
> > > >   Looking at the output from dbus when a connection happens; we have
> > > > the following:
> > > >
> > > > signal time=1538574206.428425 sender=:1.0 -> destination=(null
> > > > destination) serial=314 path=/org/freedesktop/systemd1;
> > > > interface=org.freedesktop.systemd1.Manager; member=UnitNew
> > > >    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
> > > >    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> > > > signal time=1538574206.431862 sender=:1.0 -> destination=(null
> > > > destination) serial=315 path=/org/freedesktop/systemd1;
> > > > interface=org.freedesktop.systemd1.Manager; member=UnitNew
> > > >    string "sys-subsystem-bluetooth-devices-hci0:11.device"
> > > >    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> > > > signal time=1538574206.463318 sender=:1.22 -> destination=(null
> > > > destination) serial=17 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> > > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > > >    string "org.bluez.Device1"
> > > >    array [
> > > >       dict entry(
> > > >          string "Connected"
> > > >          variant             boolean true
> > > >       )
> > > >    ]
> > > >    array [
> > > >    ]
> > > > signal time=1538574210.618465 sender=:1.22 -> destination=(null
> > > > destination) serial=18 path=/org/bluez/hci0/dev_C8_FF_28_79_05_D4;
> > > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > > >    string "org.bluez.Device1"
> > > >    array [
> > > >       dict entry(
> > > >          string "Connected"
> > > >          variant             boolean false
> > > >       )
> > > >    ]
> > > >    array [
> > > >    ]
> > > > signal time=1538574210.629705 sender=:1.0 -> destination=(null
> > > > destination) serial=316
> > > > path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> > > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > > >    string "org.freedesktop.systemd1.Device"
> > > >    array [
> > > >       dict entry(
> > > >          string "SysFSPath"
> > > >          variant             string
> > > > "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
> > > >       )
> > > >    ]
> > > >    array [
> > > >    ]
> > > > signal time=1538574210.640715 sender=:1.0 -> destination=(null
> > > > destination) serial=317
> > > > path=/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice;
> > > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > > >    string "org.freedesktop.systemd1.Unit"
> > > >    array [
> > > >       dict entry(
> > > >          string "ActiveState"
> > > >          variant             string "inactive"
> > > >       )
> > > >       dict entry(
> > > >          string "SubState"
> > > >          variant             string "dead"
> > > >       )
> > > >       dict entry(
> > > >          string "StateChangeTimestamp"
> > > >          variant             uint64 1538574210626509
> > > >       )
> > > >       dict entry(
> > > >          string "StateChangeTimestampMonotonic"
> > > >          variant             uint64 2940864110
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveExitTimestamp"
> > > >          variant             uint64 1538574206426852
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveExitTimestampMonotonic"
> > > >          variant             uint64 2936664452
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveEnterTimestamp"
> > > >          variant             uint64 1538574206426852
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveEnterTimestampMonotonic"
> > > >          variant             uint64 2936664452
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveExitTimestamp"
> > > >          variant             uint64 1538574210626509
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveExitTimestampMonotonic"
> > > >          variant             uint64 2940864110
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveEnterTimestamp"
> > > >          variant             uint64 1538574210626509
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveEnterTimestampMonotonic"
> > > >          variant             uint64 2940864110
> > > >       )
> > > >       dict entry(
> > > >          string "Job"
> > > >          variant             struct {
> > > >                uint32 0
> > > >                object path "/"
> > > >             }
> > > >       )
> > > >       dict entry(
> > > >          string "ConditionResult"
> > > >          variant             boolean false
> > > >       )
> > > >       dict entry(
> > > >          string "AssertResult"
> > > >          variant             boolean false
> > > >       )
> > > >       dict entry(
> > > >          string "ConditionTimestamp"
> > > >          variant             uint64 0
> > > >       )
> > > >       dict entry(
> > > >          string "ConditionTimestampMonotonic"
> > > >          variant             uint64 0
> > > >       )
> > > >       dict entry(
> > > >          string "AssertTimestamp"
> > > >          variant             uint64 0
> > > >       )
> > > >       dict entry(
> > > >          string "AssertTimestampMonotonic"
> > > >          variant             uint64 0
> > > >       )
> > > >    ]
> > > >    array [
> > > >    ]
> > > > signal time=1538574210.668073 sender=:1.0 -> destination=(null
> > > > destination) serial=318 path=/org/freedesktop/systemd1;
> > > > interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
> > > >    string "sys-subsystem-bluetooth-devices-hci0:11.device"
> > > >    object path "/org/freedesktop/systemd1/unit/sys_2dsubsystem_2dbluetooth_2ddevices_2dhci0_3a11_2edevice"
> > > > signal time=1538574210.670654 sender=:1.0 -> destination=(null
> > > > destination) serial=319
> > > > path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> > > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > > >    string "org.freedesktop.systemd1.Device"
> > > >    array [
> > > >       dict entry(
> > > >          string "SysFSPath"
> > > >          variant             string
> > > > "/sys/devices/platform/soc/20201000.serial/tty/ttyAMA0/hci0/hci0:11"
> > > >       )
> > > >    ]
> > > >    array [
> > > >    ]
> > > > signal time=1538574210.677890 sender=:1.0 -> destination=(null
> > > > destination) serial=320
> > > > path=/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice;
> > > > interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
> > > >    string "org.freedesktop.systemd1.Unit"
> > > >    array [
> > > >       dict entry(
> > > >          string "ActiveState"
> > > >          variant             string "inactive"
> > > >       )
> > > >       dict entry(
> > > >          string "SubState"
> > > >          variant             string "dead"
> > > >       )
> > > >       dict entry(
> > > >          string "StateChangeTimestamp"
> > > >          variant             uint64 1538574210626572
> > > >       )
> > > >       dict entry(
> > > >          string "StateChangeTimestampMonotonic"
> > > >          variant             uint64 2940864171
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveExitTimestamp"
> > > >          variant             uint64 1538574206426942
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveExitTimestampMonotonic"
> > > >          variant             uint64 2936664542
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveEnterTimestamp"
> > > >          variant             uint64 1538574206426942
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveEnterTimestampMonotonic"
> > > >          variant             uint64 2936664542
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveExitTimestamp"
> > > >          variant             uint64 1538574210626572
> > > >       )
> > > >       dict entry(
> > > >          string "ActiveExitTimestampMonotonic"
> > > >          variant             uint64 2940864171
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveEnterTimestamp"
> > > >          variant             uint64 1538574210626572
> > > >       )
> > > >       dict entry(
> > > >          string "InactiveEnterTimestampMonotonic"
> > > >          variant             uint64 2940864171
> > > >       )
> > > >       dict entry(
> > > >          string "Job"
> > > >          variant             struct {
> > > >                uint32 0
> > > >                object path "/"
> > > >             }
> > > >       )
> > > >       dict entry(
> > > >          string "ConditionResult"
> > > >          variant             boolean false
> > > >       )
> > > >       dict entry(
> > > >          string "AssertResult"
> > > >          variant             boolean false
> > > >       )
> > > >       dict entry(
> > > >          string "ConditionTimestamp"
> > > >          variant             uint64 0
> > > >       )
> > > >       dict entry(
> > > >          string "ConditionTimestampMonotonic"
> > > >          variant             uint64 0
> > > >       )
> > > >       dict entry(
> > > >          string "AssertTimestamp"
> > > >          variant             uint64 0
> > > >       )
> > > >       dict entry(
> > > >          string "AssertTimestampMonotonic"
> > > >          variant             uint64 0
> > > >       )
> > > >    ]
> > > >    array [
> > > >    ]
> > > > signal time=1538574210.699336 sender=:1.0 -> destination=(null
> > > > destination) serial=321 path=/org/freedesktop/systemd1;
> > > > interface=org.freedesktop.systemd1.Manager; member=UnitRemoved
> > > >    string "sys-devices-platform-soc-20201000.serial-tty-ttyAMA0-hci0-hci0:11.device"
> > > >    object path "/org/freedesktop/systemd1/unit/sys_2ddevices_2dplatform_2dsoc_2d20201000_2eserial_2dtty_2dttyAMA0_2dhci0_2dhci0_3a11_2edevice"
> > > >
> > > >   So there are events being fired just not the ones that connect to my
> > > > registered profile.  In addition I've tried to register the profile
> > > > and listen for connections on the device PSM of 17 and 19 which HID
> > > > uses but nothing happens there either - though I'm not sure this is
> > > > the best way to communicate as it feels 'wrong' tbh.
> > >
> > > Have you read my responses? It _wont_ work for these PSMs, those are
> > > already taken by the daemon except if you are not loading the input
> > > plugin. Can't you try with something simpler like SPP, which is what
> > > this interface is for?
> > >
> > > >   Thanks again - I'm still basically not getting any events fired on
> > > > the profile except for Release which isn't really that useful as it
> > > > only notifies me if the bluetooth stack goes down!
> > > >
> > > >   Any ideas?
> > > >
> > > > Cheers,
> > > >
> > > > Neil
> > > > On Wed, 3 Oct 2018 at 11:35, Luiz Augusto von Dentz
> > > > <luiz.dentz@gmail.com> wrote:
> > > > >
> > > > > Hi Barry,
> > > > > On Tue, Oct 2, 2018 at 5:57 PM Barry Byford <31baz66@gmail.com> wrote:
> > > > > >
> > > > > > Hi Luiz,
> > > > > >
> > > > > > On Tue, 2 Oct 2018 at 13:48, Luiz Augusto von Dentz
> > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > >
> > > > > > > Hi Neil,
> > > > > > > On Tue, Oct 2, 2018 at 3:29 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > >   Thanks for that please see inline below:
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, 2 Oct 2018, 12:28 Luiz Augusto von Dentz, <luiz.dentz@gmail.com> wrote:
> > > > > > > > >
> > > > > > > > > Hi Neil,
> > > > > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > >
> > > > > > > > > > Hello,
> > > > > > > > > >
> > > > > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > > > > >
> > > > > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > > > > >
> > > > > > > > > I don't think that will work since the input plugin is already
> > > > > > > > > listening in those PSM,
> > > > > > > >
> > > > > > > > It does connect and work but it doesn't register the profile.  If I
> > > > > > > > don't register the profile the default name in the config is used
> > > > > > > > >
> > > > > > > > > in fact I don't think RegisterProfile would
> > > > > > > > > parse the values from the record since you don't seem to be using the
> > > > > > > > > PSM:
> > > > > > > > >
> > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > > > >
> > > > > > > >
> > > > > > > > The PSM is defined in the service record
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > > > >
> > > > > > > > I'm using an sdp profile provided in some sample code I found, is
> > > > > > > > there a default one that is supported?  Is that default one selected
> > > > > > > > when I pick my uuid?
> > > > > > >
> > > > > > > You are not suppose to use existing UUIDs that the daemon already
> > > > > > > registers, the fact that you are able to register it without cause a
> > > > > > > problem might be a bug and we should probably check if the UUID is
> > > > > > > already registered and fail if it does.
> > > > > > >
> > > > > > > The HID profile is implementation is under profiles/input/, it
> > > > > > > actually hooks with kernel HID drivers.
> > > > > > >
> > > > > > > If you just want to test it you should probably have a look at
> > > > > > > test-profile in python:
> > > > > >
> > > > > > Do you have any example invocations of test-profile for common profiles?
> > > > >
> > > > > test-profile is just a sample, but yes we do have many instances of
> > > > > common profiles using RegisterProfile:
> > > > >
> > > > > OBEX Daemon:
> > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/bluetooth.c#n256
> > > > >
> > > > > Ofono (HFP):
> > > > > https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/bluez5.c#n104
> > > > >
> > > > > PulseAudio (HSP):
> > > > > https://gitlab.freedesktop.org/pulseaudio/pulseaudio/blob/master/src/modules/bluetooth/backend-native.c#L332
> > > > >
> > > > > > It can be difficult to know where the issue is if you are not
> > > > > > confident with what settings should work.
> > > > >
> > > > > Well test-profile is not exactly a library just a convenient sample on
> > > > > how to use the interface, it was used mostly for testing SPP which is
> > > > > quite common way to register external profiles. HID is probably a no
> > > > > go due to reason already stated.
> > > > >
> > > > > > >
> > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
> > > > > > >
> > > > > > > >   If so then I think it has been overcomplicated by this sdp profile?
> > > > > > > > How do I use the default in-built profile - is it just the uuid?
> > > > > > > > On Tue, 2 Oct 2018 at 12:28, Luiz Augusto von Dentz
> > > > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > > > >
> > > > > > > > > Hi Neil,
> > > > > > > > > On Tue, Oct 2, 2018 at 1:39 PM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > >
> > > > > > > > > > Hello,
> > > > > > > > > >
> > > > > > > > > >   Thanks for that; I'll change the config file for this and for the
> > > > > > > > > > name can that be in the main.conf file?  The same for the
> > > > > > > > > > discoverable; set the timeout to zero - there is no security needed
> > > > > > > > > > for this device at all.  Can this all be done with the conf file?
> > > > > > > > > >
> > > > > > > > > >   On the connection; yes it connects.  This is a HID device connecting
> > > > > > > > > > via L2CAP with the interrupt on 19 and the control on 17 and the
> > > > > > > > > > windows PC correctly connects to the device, queries the service
> > > > > > > > > > record, identifies it as a HID and connects on both the control and
> > > > > > > > > > interrupt psm ports but none of the dbus methods are being called.  At
> > > > > > > > > > the moment I am using the pybluez library with the BluetoothSocket and
> > > > > > > > > > calling listen and accept which is a bit 'manual'.  To detect a
> > > > > > > > > > disconnect I'm calling hcitool con and parsing the response - which is
> > > > > > > > > > again a bit manual.  Please see below for my current 'hack':
> > > > > > > > >
> > > > > > > > > I don't think that will work since the input plugin is already
> > > > > > > > > listening in those PSM, in fact I don't think RegisterProfile would
> > > > > > > > > parse the values from the record since you don't seem to be using the
> > > > > > > > > PSM:
> > > > > > > > >
> > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/profile-api.txt#n54
> > > > > > > > >
> > > > > > > > > Btw, why would you want to replace the HID profile? Is that not working?
> > > > > > > > >
> > > > > > > > > > ---
> > > > > > > > > >     #listen for incoming client connections
> > > > > > > > > >     #ideally this would be handled by the Bluez 5 profile
> > > > > > > > > >     #but that didn't seem to work
> > > > > > > > > >     def listen(self):
> > > > > > > > > >
> > > > > > > > > >         print("Waiting for connections")
> > > > > > > > > >         self.scontrol=BluetoothSocket(L2CAP)
> > > > > > > > > >         self.sinterrupt=BluetoothSocket(L2CAP)
> > > > > > > > > >
> > > > > > > > > >         self.scontrol.bind((self.MY_ADDRESS,self.P_CTRL))
> > > > > > > > > >         self.sinterrupt.bind((self.MY_ADDRESS,self.P_INTR ))
> > > > > > > > > >         #Start listening on the server sockets
> > > > > > > > > >         self.scontrol.listen(1) # Limit of 1 connection
> > > > > > > > > >         self.sinterrupt.listen(1)
> > > > > > > > > >
> > > > > > > > > >         self.ccontrol,cinfo = self.scontrol.accept()
> > > > > > > > > >         self.controlClientMac = cinfo[0]
> > > > > > > > > >         self.controlClientPsm = cinfo[1]
> > > > > > > > > >         print ('control is ' + self.controlClientMac + " " +
> > > > > > > > > > str(self.controlClientPsm))
> > > > > > > > > >
> > > > > > > > > >         self.cinterrupt, cinfo = self.sinterrupt.accept()
> > > > > > > > > >         self.interruptClientMac = cinfo[0]
> > > > > > > > > >         self.interruptClientPsm = cinfo[1]
> > > > > > > > > >         print ('interrupt is ' + self.interruptClientMac + " " +
> > > > > > > > > > str(self.interruptClientPsm))
> > > > > > > > > >
> > > > > > > > > >         thread.start_new_thread(self.check_connection, ())
> > > > > > > > > >
> > > > > > > > > >     def check_connection(self):
> > > > > > > > > >         halt = False
> > > > > > > > > >         while not halt:
> > > > > > > > > >             stdoutdata = subprocess.check_output(["hcitool", "con"])
> > > > > > > > > >
> > > > > > > > > >             if self.controlClientMac in stdoutdata.split():
> > > > > > > > > >                 time.sleep(0.1)
> > > > > > > > > >             else:
> > > > > > > > > >                 print('got disconnection')
> > > > > > > > > >                 self.scontrol.shutdown(2);
> > > > > > > > > >                 self.sinterrupt.shutdown(2)
> > > > > > > > > >                 halt = True
> > > > > > > > > >         thread.start_new_thread(self.listen, ())
> > > > > > > > > >
> > > > > > > > > >   Obviously this is a very clumsy way of doing it and calling back on
> > > > > > > > > > the profile is the correct way to do it, I just can't work out why the
> > > > > > > > > > profile is not being called.  I'm trying to spy on the dbus comms to
> > > > > > > > > > see if anything is being sent but I can't see any bluez profile
> > > > > > > > > > messages being sent at all.  Thanks for your response and any advice
> > > > > > > > > > is greatly appreciated.
> > > > > > > > > >
> > > > > > > > > > Cheers,
> > > > > > > > > >
> > > > > > > > > > Neil
> > > > > > > > > > On Tue, 2 Oct 2018 at 09:37, Luiz Augusto von Dentz
> > > > > > > > > > <luiz.dentz@gmail.com> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Neil,
> > > > > > > > > > > On Tue, Oct 2, 2018 at 1:32 AM Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hello,
> > > > > > > > > > > >
> > > > > > > > > > > >   I've been running a dbus-monitor and I can't see the interface being
> > > > > > > > > > > > called of 'org.bluez.Profile1' - I can see 'org.bluez.Device1' and
> > > > > > > > > > > > I've tried listening to that interface and also on the path with
> > > > > > > > > > > > dev_<ADAPTER-MAC> but I'm clearly doing something fundamentally wrong.
> > > > > > > > > > > > IF anyone has any advance I'd be very grateful and there is 100 rep
> > > > > > > > > > > > points up on Stack Overflow for any advice too!
> > > > > > > > > > > >
> > > > > > > > > > > >   Thanks; it's late here and I'll not be home till gone 1am so I'll be off now!
> > > > > > > > > > > >
> > > > > > > > > > > > Cheers,
> > > > > > > > > > > >
> > > > > > > > > > > > Neil
> > > > > > > > > > > > On Fri, 28 Sep 2018 at 23:38, Neil Benn <neil.benn@ziath.com> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hello,
> > > > > > > > > > > > >
> > > > > > > > > > > > >   I'm trying to setup a RPi0 operating a Bluetooth device; I've setup
> > > > > > > > > > > > > the device using the following call:
> > > > > > > > > > > > > ---
> > > > > > > > > > > > >     #configure the bluetooth hardware device
> > > > > > > > > > > > >     def init_bt_device(self):
> > > > > > > > > > > > >
> > > > > > > > > > > > >         print("Configuring for name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > > > > >
> > > > > > > > > > > > >         #set the device class to a barcode scanner and set the name
> > > > > > > > > > > > >         os.system("hciconfig hcio class 0x002560")
> > > > > > > > > > > > >         os.system("hciconfig hcio name " + BTKbDevice.MY_DEV_NAME)
> > > > > > > > > > > > >
> > > > > > > > > > > > >         #make the device discoverable
> > > > > > > > > > > > >         os.system("hciconfig hcio piscan")
> > > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > You shouldn't be using hciconfig, instead do the following:
> > > > > > > > > > >
> > > > > > > > > > > The class is automatically set by bluetoothd based on the
> > > > > > > > > > > services/profiles registered and the setting in the main.conf:
> > > > > > > > > > >
> > > > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n9
> > > > > > > > > > >
> > > > > > > > > > > For the name use D-Bus property Alias:
> > > > > > > > > > >
> > > > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n216
> > > > > > > > > > >
> > > > > > > > > > > To make the adapter discoverable use D-Bus property Discoverable:
> > > > > > > > > > >
> > > > > > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n252
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > > >   Then after that I attempt to setup the profile using the following code:
> > > > > > > > > > > > > ---
> > > > > > > > > > > > >     #set up a bluez profile to advertise device capabilities from a
> > > > > > > > > > > > > loaded service record
> > > > > > > > > > > > >     def init_bluez_profile(self):
> > > > > > > > > > > > >
> > > > > > > > > > > > >         print("Configuring Bluez Profile")
> > > > > > > > > > > > >
> > > > > > > > > > > > >         #setup profile options
> > > > > > > > > > > > >         service_record=self.read_sdp_service_record()
> > > > > > > > > > > > >
> > > > > > > > > > > > >         opts = {
> > > > > > > > > > > > >             "ServiceRecord":service_record,
> > > > > > > > > > > > >             "Role":"server",
> > > > > > > > > > > > >             "RequireAuthentication":False,
> > > > > > > > > > > > >             "RequireAuthorization":False,
> > > > > > > > > > > > >             "Name":BTKbDevice.MY_DEV_NAME,
> > > > > > > > > > > > >             "AutoConnect":True
> > > > > > > > > > > > >         }
> > > > > > > > > > > > >
> > > > > > > > > > > > >         #retrieve a proxy for the bluez profile interface
> > > > > > > > > > > > >         bus = dbus.SystemBus()
> > > > > > > > > > > > >         self.manager =
> > > > > > > > > > > > > dbus.Interface(bus.get_object("org.bluez","/org/bluez"),
> > > > > > > > > > > > > "org.bluez.ProfileManager1")
> > > > > > > > > > > > >         self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
> > > > > > > > > > > > >         self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH,
> > > > > > > > > > > > > BTKbDevice.UUID, opts)
> > > > > > > > > > > > >         print("Profile registered ")
> > > > > > > > > > > > > ---
> > > > > > > > > > > > >   The sdp record is available from https://textuploader.com/dv8xt.
> > > > > > > > > > > > > The profile in question is basically the same as the one defined in
> > > > > > > > > > > > > the test-profile as shown below:
> > > > > > > > > > > > > ---
> > > > > > > > > > > > > class BTKbBluezProfile(dbus.service.Object):
> > > > > > > > > > > > >     fd = -1
> > > > > > > > > > > > >
> > > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > > > > >     def Release(self):
> > > > > > > > > > > > >             print("Release")
> > > > > > > > > > > > >             mainloop.quit()
> > > > > > > > > > > > >
> > > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1",
> > > > > > > > > > > > >                                     in_signature="", out_signature="")
> > > > > > > > > > > > >     def Cancel(self):
> > > > > > > > > > > > >             print("Cancel")
> > > > > > > > > > > > >
> > > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}",
> > > > > > > > > > > > > out_signature="")
> > > > > > > > > > > > >     def NewConnection(self, path, fd, properties):
> > > > > > > > > > > > >             self.fd = fd.take()
> > > > > > > > > > > > >             print("NewConnection(%s, %d)" % (path, self.fd))
> > > > > > > > > > > > >             for key in properties.keys():
> > > > > > > > > > > > >                     print ('key ' + key + ' value ' + properties[key])
> > > > > > > > > > > > >                     if key == "Version" or key == "Features":
> > > > > > > > > > > > >                             print("  %s = 0x%04x" % (key, properties[key]))
> > > > > > > > > > > > >                     else:
> > > > > > > > > > > > >                             print("  %s = %s" % (key, properties[key]))
> > > > > > > > > > > > >
> > > > > > > > > > > > >     @dbus.service.method("org.bluez.Profile1", in_signature="o",
> > > > > > > > > > > > > out_signature="")
> > > > > > > > > > > > >     def RequestDisconnection(self, path):
> > > > > > > > > > > > >             print("RequestDisconnection(%s)" % (path))
> > > > > > > > > > > > >
> > > > > > > > > > > > >             if (self.fd > 0):
> > > > > > > > > > > > >                     os.close(self.fd)
> > > > > > > > > > > > >                     self.fd = -1
> > > > > > > > > > > > >
> > > > > > > > > > > > >     def __init__(self, bus, path):
> > > > > > > > > > > > >             dbus.service.Object.__init__(self, bus, path)
> > > > > > > > > > > > > ---
> > > > > > > > > > > > >   However it seems like the profile is not being registered, or least
> > > > > > > > > > > > > the methods in the profile are not being called.  I'm sorry to ask
> > > > > > > > > > > > > such a basic question but can someone please point me in the right
> > > > > > > > > > > > > direction as to why the profile is either not being registered or the
> > > > > > > > > > > > > callbacks on the profile are not being called.
> > > > > > > > > > >
> > > > > > > > > > > They would be called only when there is a connection to the profile,
> > > > > > > > > > > did you actually connect? If this is something like a serial port the
> > > > > > > > > > > remote should lookup the SDP record and connect to the channel listed
> > > > > > > > > > > there.
> > > > > > > > > > >
> > > > > > > > > > > > >   Thank you very much for reading this far and any and all help is
> > > > > > > > > > > > > most appreciated!
> > > > > > > > > > > > >
> > > > > > > > > > > > > Cheers,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Neil
> > > > > > > > > > > > >
> > > > > > > > > > > > > --
> > > > > > > > > > > > >
> > > > > > > > > > > > > Neil Benn MSc
> > > > > > > > > > > > > Ziath Ltd
> > > > > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > > > > http://www.ziath.com
> > > > > > > > > > > > >
> > > > > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > --
> > > > > > > > > > > >
> > > > > > > > > > > > Neil Benn MSc
> > > > > > > > > > > > Ziath Ltd
> > > > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > > > http://www.ziath.com
> > > > > > > > > > > >
> > > > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > > > >
> > > > > > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > > > > > >
> > > > > > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > Luiz Augusto von Dentz
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > >
> > > > > > > > > > Neil Benn MSc
> > > > > > > > > > Ziath Ltd
> > > > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > > > http://www.ziath.com
> > > > > > > > > >
> > > > > > > > > > Please consider the environment before printing this email.
> > > > > > > > > >
> > > > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > > > >
> > > > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Luiz Augusto von Dentz
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > Neil Benn MSc
> > > > > > > > Ziath Ltd
> > > > > > > > Phone: +44 (0) 1223 855021
> > > > > > > > http://www.ziath.com
> > > > > > > >
> > > > > > > > Please consider the environment before printing this email.
> > > > > > > >
> > > > > > > > Follow us on Facebook, Twitter or LinkedIn
> > > > > > > >
> > > > > > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > > > > > intended only for the use of the individual or entity to which it is
> > > > > > > > addressed, and may contain information that is privileged,
> > > > > > > > confidential and exempt from disclosure under applicable law. If the
> > > > > > > > reader of this message is not the intended recipient, or the employee
> > > > > > > > or agent responsible for delivering the message to the intended
> > > > > > > > recipient, you are hereby notified that any dissemination,
> > > > > > > > distribution or copying of this communication is strictly prohibited.
> > > > > > > > If you have received this communication in error, please notify Ziath
> > > > > > > > Ltd immediately by email at info@ziath.com. Thank you.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Luiz Augusto von Dentz
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Luiz Augusto von Dentz
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Neil Benn MSc
> > > > Ziath Ltd
> > > > Phone: +44 (0) 1223 855021
> > > > http://www.ziath.com
> > > >
> > > > Please consider the environment before printing this email.
> > > >
> > > > Follow us on Facebook, Twitter or LinkedIn
> > > >
> > > > IMPORTANT NOTICE: This message, including any attached documents, is
> > > > intended only for the use of the individual or entity to which it is
> > > > addressed, and may contain information that is privileged,
> > > > confidential and exempt from disclosure under applicable law. If the
> > > > reader of this message is not the intended recipient, or the employee
> > > > or agent responsible for delivering the message to the intended
> > > > recipient, you are hereby notified that any dissemination,
> > > > distribution or copying of this communication is strictly prohibited.
> > > > If you have received this communication in error, please notify Ziath
> > > > Ltd immediately by email at info@ziath.com. Thank you.
> > >
> > >
> > >
> > > --
> > > Luiz Augusto von Dentz
> >
> >
> >
> > --
> >
> > Neil Benn MSc
> > Ziath Ltd
> > Phone: +44 (0) 1223 855021
> > http://www.ziath.com
> >
> > Please consider the environment before printing this email.
> >
> > Follow us on Facebook, Twitter or LinkedIn
> >
> > IMPORTANT NOTICE: This message, including any attached documents, is
> > intended only for the use of the individual or entity to which it is
> > addressed, and may contain information that is privileged,
> > confidential and exempt from disclosure under applicable law. If the
> > reader of this message is not the intended recipient, or the employee
> > or agent responsible for delivering the message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly prohibited.
> > If you have received this communication in error, please notify Ziath
> > Ltd immediately by email at info@ziath.com. Thank you.
>
>
>
> --
> Luiz Augusto von Dentz



-- 

Neil Benn MSc
Ziath Ltd
Phone: +44 (0) 1223 855021
http://www.ziath.com

Please consider the environment before printing this email.

Follow us on Facebook, Twitter or LinkedIn

IMPORTANT NOTICE: This message, including any attached documents, is
intended only for the use of the individual or entity to which it is
addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this message is not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify Ziath
Ltd immediately by email at info@ziath.com. Thank you.

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

end of thread, other threads:[~2018-10-03 18:45 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-28 22:38 Registering a profile Neil Benn
2018-10-01 22:29 ` Neil Benn
2018-10-02  8:37   ` Luiz Augusto von Dentz
2018-10-02 10:39     ` Neil Benn
2018-10-02 11:27       ` Luiz Augusto von Dentz
2018-10-02 12:28         ` Neil Benn
2018-10-02 12:47           ` Luiz Augusto von Dentz
2018-10-02 14:57             ` Barry Byford
2018-10-02 18:31               ` Neil Benn
2018-10-03 10:35               ` Luiz Augusto von Dentz
2018-10-03 13:49                 ` Neil Benn
2018-10-03 14:03                   ` Luiz Augusto von Dentz
2018-10-03 15:28                     ` Neil Benn
2018-10-03 18:08                       ` Luiz Augusto von Dentz
2018-10-03 18:45                         ` Neil Benn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).