mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-12-04 17:44:44 +08:00
67dab2d2ae
The method is now deprecated and thus the replacement utility library should be used in the test scripts.
88 lines
2.1 KiB
Python
Executable File
88 lines
2.1 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
import gobject
|
|
|
|
import dbus.mainloop.glib
|
|
import bluezutils
|
|
|
|
def create_device_reply(device):
|
|
print("Pairing succeed!")
|
|
mainloop.quit()
|
|
|
|
def create_device_error(error):
|
|
print("Pairing failed.")
|
|
mainloop.quit()
|
|
|
|
if __name__ == '__main__':
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
mainloop = gobject.MainLoop()
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
managed_objects = bluezutils.get_managed_objects()
|
|
adapter0 = bluezutils.find_adapter_in_objects(managed_objects, "hci0")
|
|
adapter1 = bluezutils.find_adapter_in_objects(managed_objects, "hci1")
|
|
|
|
adapter0_path = adapter0.object_path
|
|
adapter1_path = adapter1.object_path
|
|
|
|
adapter0_address = managed_objects[adapter0_path][
|
|
bluezutils.ADAPTER_INTERFACE]["Address"]
|
|
adapter1_address = managed_objects[adapter1_path][
|
|
bluezutils.ADAPTER_INTERFACE]["Address"]
|
|
|
|
print("Adapters:")
|
|
print(" hci0: " + adapter0_address)
|
|
print(" hci1: " + adapter1_address)
|
|
print()
|
|
|
|
print("Removing any existing bond...")
|
|
|
|
try:
|
|
dev = bluezutils.find_device_in_objects(managed_objects,
|
|
adapter1_address,
|
|
adapter0_address)
|
|
adapter0.RemoveDevice(dev.object_path)
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
dev = bluezutils.find_device_in_objects(managed_objects,
|
|
adapter0_address,
|
|
adapter1_address)
|
|
adapter1.RemoveDevice(dev.object_path)
|
|
except:
|
|
pass
|
|
|
|
print("Done.")
|
|
print()
|
|
print("Reading local Out of Band data...")
|
|
|
|
oob_adapter0 = dbus.Interface(bus.get_object("org.bluez",
|
|
adapter0_path), "org.bluez.OutOfBand")
|
|
oob_adapter1 = dbus.Interface(bus.get_object("org.bluez",
|
|
adapter1_path), "org.bluez.OutOfBand")
|
|
|
|
oob0 = oob_adapter0.ReadLocalData()
|
|
oob1 = oob_adapter1.ReadLocalData()
|
|
|
|
print("Done.")
|
|
print()
|
|
print("Exchanging Out of Band data...")
|
|
|
|
oob_adapter0.AddRemoteData(adapter1_address, oob1)
|
|
oob_adapter1.AddRemoteData(adapter0_address, oob0)
|
|
|
|
print("Done.")
|
|
print()
|
|
print("Starting to pair.")
|
|
adapter1.CreatePairedDevice(adapter0_address, "/test/agent_oob",
|
|
"DisplayYesNo",
|
|
reply_handler=create_device_reply,
|
|
error_handler=create_device_error)
|
|
|
|
mainloop.run()
|