| 80fba06 by Marcel Holtmann at 2008-03-14 |
1 |
#!/usr/bin/python |
|
2 |
|
|
3 |
import gobject |
|
4 |
|
| b6ed588 by Marcel Holtmann at 2008-06-08 |
5 |
import sys |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
6 |
import dbus |
|
7 |
import dbus.service |
|
8 |
import dbus.mainloop.glib |
|
9 |
|
| 31d673a by Marcel Holtmann at 2008-06-09 |
10 |
class Rejected(dbus.DBusException): |
| 3ed6db0 by Marcel Holtmann at 2008-06-09 |
11 |
_dbus_error_name = "org.bluez.Error.Rejected" |
|
12 |
|
| 80fba06 by Marcel Holtmann at 2008-03-14 |
13 |
class Agent(dbus.service.Object): |
| caab6d5 by Johan Hedberg at 2008-06-12 |
14 |
exit_on_release = True |
|
15 |
|
|
16 |
def set_exit_on_release(self, exit_on_release): |
|
17 |
self.exit_on_release = exit_on_release |
|
18 |
|
| 80fba06 by Marcel Holtmann at 2008-03-14 |
19 |
@dbus.service.method("org.bluez.Agent", |
| b727329 by Marcel Holtmann at 2008-03-15 |
20 |
in_signature="", out_signature="") |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
21 |
def Release(self): |
| b727329 by Marcel Holtmann at 2008-03-15 |
22 |
print "Release" |
| caab6d5 by Johan Hedberg at 2008-06-12 |
23 |
if self.exit_on_release: |
|
24 |
mainloop.quit() |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
25 |
|
|
26 |
@dbus.service.method("org.bluez.Agent", |
| 61a6576 by Claudio Takahasi at 2008-04-10 |
27 |
in_signature="os", out_signature="") |
|
28 |
def Authorize(self, device, uuid): |
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
29 |
print "Authorize (%s, %s)" % (device, uuid) |
| 61a6576 by Claudio Takahasi at 2008-04-10 |
30 |
|
|
31 |
@dbus.service.method("org.bluez.Agent", |
| b727329 by Marcel Holtmann at 2008-03-15 |
32 |
in_signature="o", out_signature="s") |
| 1658d5b by Marcel Holtmann at 2008-05-30 |
33 |
def RequestPinCode(self, device): |
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
34 |
print "RequestPinCode (%s)" % (device) |
| 8078346 by Johan Hedberg at 2008-06-11 |
35 |
return raw_input("Enter PIN Code: ") |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
36 |
|
|
37 |
@dbus.service.method("org.bluez.Agent", |
| b1235c9 by Marcel Holtmann at 2008-06-03 |
38 |
in_signature="o", out_signature="u") |
| 12f8733 by Marcel Holtmann at 2008-06-04 |
39 |
def RequestPasskey(self, device): |
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
40 |
print "RequestPasskey (%s)" % (device) |
| 4aa07a5 by Johan Hedberg at 2008-06-09 |
41 |
passkey = raw_input("Enter passkey: ") |
|
42 |
return dbus.UInt32(passkey) |
| b1235c9 by Marcel Holtmann at 2008-06-03 |
43 |
|
|
44 |
@dbus.service.method("org.bluez.Agent", |
|
45 |
in_signature="ou", out_signature="") |
| 12f8733 by Marcel Holtmann at 2008-06-04 |
46 |
def DisplayPasskey(self, device, passkey): |
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
47 |
print "DisplayPasskey (%s, %d)" % (device, passkey) |
| b1235c9 by Marcel Holtmann at 2008-06-03 |
48 |
|
|
49 |
@dbus.service.method("org.bluez.Agent", |
|
50 |
in_signature="ou", out_signature="") |
| 12f8733 by Marcel Holtmann at 2008-06-04 |
51 |
def RequestConfirmation(self, device, passkey): |
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
52 |
print "RequestConfirmation (%s, %d)" % (device, passkey) |
| 3ed6db0 by Marcel Holtmann at 2008-06-09 |
53 |
confirm = raw_input("Confirm passkey (yes/no): ") |
|
54 |
if (confirm == "yes"): |
|
55 |
return |
|
56 |
raise Rejected("Passkey doesn't match") |
| b1235c9 by Marcel Holtmann at 2008-06-03 |
57 |
|
|
58 |
@dbus.service.method("org.bluez.Agent", |
| b727329 by Marcel Holtmann at 2008-03-15 |
59 |
in_signature="s", out_signature="") |
| 19d46a3 by Marcel Holtmann at 2008-03-14 |
60 |
def ConfirmModeChange(self, mode): |
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
61 |
print "ConfirmModeChange (%s)" % (mode) |
| 19d46a3 by Marcel Holtmann at 2008-03-14 |
62 |
|
|
63 |
@dbus.service.method("org.bluez.Agent", |
| b727329 by Marcel Holtmann at 2008-03-15 |
64 |
in_signature="", out_signature="") |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
65 |
def Cancel(self): |
| b727329 by Marcel Holtmann at 2008-03-15 |
66 |
print "Cancel" |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
67 |
|
| 24e72e9 by Johan Hedberg at 2008-06-11 |
68 |
def create_device_reply(device): |
|
69 |
print "New device (%s)" % (device) |
| caab6d5 by Johan Hedberg at 2008-06-12 |
70 |
mainloop.quit() |
| 24e72e9 by Johan Hedberg at 2008-06-11 |
71 |
|
|
72 |
def create_device_error(error): |
|
73 |
print "Creating device failed: %s" % (error) |
| caab6d5 by Johan Hedberg at 2008-06-12 |
74 |
mainloop.quit() |
| 3f756f2 by Johan Hedberg at 2008-06-04 |
75 |
|
| 80fba06 by Marcel Holtmann at 2008-03-14 |
76 |
if __name__ == '__main__': |
|
77 |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
|
78 |
|
|
79 |
bus = dbus.SystemBus() |
| b727329 by Marcel Holtmann at 2008-03-15 |
80 |
manager = dbus.Interface(bus.get_object("org.bluez", "/"), |
|
81 |
"org.bluez.Manager") |
|
82 |
|
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
83 |
if len(sys.argv) > 1: |
|
84 |
path = manager.FindAdapter(sys.argv[1]) |
|
85 |
else: |
|
86 |
path = manager.DefaultAdapter() |
|
87 |
|
| b727329 by Marcel Holtmann at 2008-03-15 |
88 |
adapter = dbus.Interface(bus.get_object("org.bluez", path), |
|
89 |
"org.bluez.Adapter") |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
90 |
|
| b727329 by Marcel Holtmann at 2008-03-15 |
91 |
path = "/test/agent" |
| caab6d5 by Johan Hedberg at 2008-06-12 |
92 |
agent = Agent(bus, path) |
| 80fba06 by Marcel Holtmann at 2008-03-14 |
93 |
|
| 9dc4cfc by Marcel Holtmann at 2008-06-08 |
94 |
mainloop = gobject.MainLoop() |
|
95 |
|
|
96 |
if len(sys.argv) > 2: |
|
97 |
if len(sys.argv) > 3: |
|
98 |
device = adapter.FindDevice(sys.argv[2]) |
|
99 |
adapter.RemoveDevice(device) |
|
100 |
|
| caab6d5 by Johan Hedberg at 2008-06-12 |
101 |
agent.set_exit_on_release(False) |
| 8078346 by Johan Hedberg at 2008-06-11 |
102 |
adapter.CreatePairedDevice(sys.argv[2], path, "DisplayYesNo", |
| 3f756f2 by Johan Hedberg at 2008-06-04 |
103 |
reply_handler=create_device_reply, |
| 24e72e9 by Johan Hedberg at 2008-06-11 |
104 |
error_handler=create_device_error) |
| a15d02a by Marcel Holtmann at 2008-06-09 |
105 |
else: |
| 8078346 by Johan Hedberg at 2008-06-11 |
106 |
adapter.RegisterAgent(path, "DisplayYesNo") |
| a15d02a by Marcel Holtmann at 2008-06-09 |
107 |
print "Agent registered" |
| 3f756f2 by Johan Hedberg at 2008-06-04 |
108 |
|
| 80fba06 by Marcel Holtmann at 2008-03-14 |
109 |
mainloop.run() |
|
110 |
|
|
111 |
#adapter.UnregisterAgent(path) |
| b727329 by Marcel Holtmann at 2008-03-15 |
112 |
#print "Agent unregistered" |