mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-25 05:04:18 +08:00
Add test/test-oob for testing Out Of Band pairing
This test utilizes D-Bus Out Of Band API so bluetoothd must be compiled with dbusoob plugin.
This commit is contained in:
parent
4e02012afe
commit
f6a34aa79b
@ -205,8 +205,8 @@ EXTRA_DIST += test/apitest test/sap-client test/hsplay test/hsmicro \
|
||||
test/test-telephony test/test-network test/simple-agent \
|
||||
test/simple-service test/simple-endpoint test/test-audio \
|
||||
test/test-input test/test-attrib test/test-sap-server \
|
||||
test/service-record.dtd test/service-did.xml test/service-spp.xml \
|
||||
test/service-opp.xml test/service-ftp.xml
|
||||
test/test-oob test/service-record.dtd test/service-did.xml \
|
||||
test/service-spp.xml test/service-opp.xml test/service-ftp.xml
|
||||
|
||||
|
||||
if HIDD
|
||||
|
80
test/test-oob
Executable file
80
test/test-oob
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import gobject
|
||||
|
||||
import dbus.mainloop.glib
|
||||
|
||||
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()
|
||||
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
|
||||
"org.bluez.Manager")
|
||||
|
||||
adapter0_path = manager.FindAdapter("hci0")
|
||||
adapter1_path = manager.FindAdapter("hci1")
|
||||
|
||||
adapter0 = dbus.Interface(bus.get_object("org.bluez", adapter0_path),
|
||||
"org.bluez.Adapter")
|
||||
adapter1 = dbus.Interface(bus.get_object("org.bluez", adapter1_path),
|
||||
"org.bluez.Adapter")
|
||||
|
||||
adapter0_address = adapter0.GetProperties()["Address"]
|
||||
adapter1_address = adapter1.GetProperties()["Address"]
|
||||
print "Adapters:"
|
||||
print " hci0: " + adapter0_address
|
||||
print " hci1: " + adapter1_address
|
||||
print
|
||||
|
||||
print "Removing any existing bond..."
|
||||
|
||||
try:
|
||||
device = adapter0.FindDevice(adapter1_address)
|
||||
adapter0.RemoveDevice(device)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
device = adapter1.FindDevice(adapter0_address)
|
||||
adapter1.RemoveDevice(device)
|
||||
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[0], oob1[1])
|
||||
oob_adapter1.AddRemoteData(adapter0_address, oob0[0], oob0[1])
|
||||
|
||||
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()
|
Loading…
Reference in New Issue
Block a user