0

I'm trying to connect my Raspberry Pi 3B+ over BLE GATT Server using the Bluez5.6 library. I have successfully tested the BLE server application. Able to connect & communicate over the GATT services on the BLE client application over android.

I would like to apply the authentication pin while the connecting client application(Android App) to the BLE GATT server. I have tried to apply the different capabilities to the BLE agent.

like... DisplayOnly DisplayYesNo KeyboardOnly NoInputNoOutput KeyboardDisplay

Here is the source code for the main function.

def main():
    # global mainloop
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    bus = dbus.SystemBus()
    adapter = find_adapter(bus)
    if not adapter:
        logger.error('main : BLE adapter not found')
        return

    #discovery functionality
    bus.add_signal_receiver(dis_interfaces_added, dbus_interface = "org.freedesktop.DBus.ObjectManager", signal_name = "InterfacesAdded")
    bus.add_signal_receiver(dis_properties_changed, dbus_interface = "org.freedesktop.DBus.Properties", signal_name = "PropertiesChanged", arg0 = "org.bluez.Device1", path_keyword = "path")

    om = dbus.Interface(bus.get_object("org.bluez", "/"), "org.freedesktop.DBus.ObjectManager")
    objects = om.GetManagedObjects()
    for path, interfaces in objects.items():
        if "org.bluez.Device1" in interfaces:
            devices[path] = interfaces["org.bluez.Device1"]

    capability = "NoInputNoOutput"
    logger.info('main : capability : (%s)' % capability)

    agent_path = "/test/agent"
    agent = Agent(bus, agent_path)

    service_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter), GATT_MANAGER_IFACE)
    ad_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter), LE_ADVERTISING_MANAGER_IFACE)

    app = ConfigBluetoothServiceApplication(bus)
    adv = ConfigBluetoothServiceAdvertisement(bus, 0)

    mainloop = GLib.MainLoop()

    agent_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, "/org/bluez"), GATT_AGENT_IFACE)
    agent_manager.RegisterAgent(agent_path, capability)
    logger.info('main : main : Agent registered')
    agent_manager.RequestDefaultAgent(agent_path)

    service_manager.RegisterApplication(app.get_path(), {}, reply_handler=register_app_cb, error_handler=register_app_error_cb)
    ad_manager.RegisterAdvertisement(adv.get_path(), {}, reply_handler=register_ad_cb, error_handler=register_ad_error_cb)

    try:
        mainloop.run()
    except KeyboardInterrupt:
        adv.Release()
        mainloop.quit()


if __name__ == '__main__':
    main()

Will you please help me to know, What are the required configurations that have to be done to add the authentication for the BLE GATT Server?

2
  • What value do you have on the Flags property on your Characteristics?
    – ukBaz
    Mar 30 at 9:28
  • @ukBaz Thanks for your reply. I haven't set the Flags property for the characteristics. I have read the documentation & found that the Flags are used to authenticate & encrypt the data for the services & characteristics to do read-write functionality. But I am more interested in the authentication before connecting to the Bluetooth Gatt Service. i.e. while pairing & connecting with Gatt Server using the Gatt Client application, Can I used the authentication with the pin code for the Bluetooth Gatt Server?
    – shiv patil
    Apr 8 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.