linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: neil.benn@ziath.com
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: Registering a profile
Date: Tue, 2 Oct 2018 15:47:38 +0300	[thread overview]
Message-ID: <CABBYNZ+x2jzBRVNuLp-BpOAbdMk+xayrR61edPs2pEJ22cRFhw@mail.gmail.com> (raw)
In-Reply-To: <CADckva_Xsa4euhy27qHQSQas2aoMKnK0pSvWndjoxLq2gohdTg@mail.gmail.com>

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

  reply	other threads:[~2018-10-02 12:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABBYNZ+x2jzBRVNuLp-BpOAbdMk+xayrR61edPs2pEJ22cRFhw@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=neil.benn@ziath.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).