2012-09-25 20:11:48 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
|
|
|
from gi.repository import GObject
|
|
|
|
|
2012-09-28 03:14:29 +08:00
|
|
|
import os
|
2012-09-25 20:11:48 +08:00
|
|
|
import sys
|
|
|
|
import dbus
|
|
|
|
import dbus.service
|
|
|
|
import dbus.mainloop.glib
|
|
|
|
from optparse import OptionParser, make_option
|
|
|
|
|
2012-11-13 16:25:03 +08:00
|
|
|
hfp_record = """
|
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
|
|
|
|
<record>
|
|
|
|
<attribute id="0x0000">
|
|
|
|
<uint32 value="0x00010002" />
|
|
|
|
</attribute>
|
|
|
|
<attribute id="0x0001">
|
|
|
|
<sequence>
|
|
|
|
<uuid value="0x111e" />
|
|
|
|
<uuid value="0x1203" />
|
|
|
|
</sequence>
|
|
|
|
</attribute>
|
|
|
|
<attribute id="0x0004">
|
|
|
|
<sequence>
|
|
|
|
<sequence>
|
|
|
|
<uuid value="0x0100" />
|
|
|
|
</sequence>
|
|
|
|
<sequence>
|
|
|
|
<uuid value="0x0003" />
|
|
|
|
<uint8 value="0x07" />
|
|
|
|
</sequence>
|
|
|
|
</sequence>
|
|
|
|
</attribute>
|
|
|
|
<attribute id="0x0005">
|
|
|
|
<sequence>
|
|
|
|
<uuid value="0x1002" />
|
|
|
|
</sequence>
|
|
|
|
</attribute>
|
|
|
|
<attribute id="0x0009">
|
|
|
|
<sequence>
|
|
|
|
<sequence>
|
|
|
|
<uuid value="0x111e" />
|
|
|
|
<uint16 value="0x0105" />
|
|
|
|
</sequence>
|
|
|
|
</sequence>
|
|
|
|
</attribute>
|
|
|
|
<attribute id="0x0100">
|
|
|
|
<text value="Handsfree" />
|
|
|
|
</attribute>
|
|
|
|
<attribute id="0x0311">
|
|
|
|
<uint16 value="0x0031" />
|
|
|
|
</attribute>
|
|
|
|
</record>
|
|
|
|
"""
|
|
|
|
|
2012-09-25 20:11:48 +08:00
|
|
|
class Profile(dbus.service.Object):
|
2012-11-10 03:25:22 +08:00
|
|
|
@dbus.service.method("org.bluez.Profile1",
|
2012-09-25 20:11:48 +08:00
|
|
|
in_signature="", out_signature="")
|
|
|
|
def Release(self):
|
|
|
|
print("Release")
|
|
|
|
mainloop.quit()
|
|
|
|
|
2012-11-10 03:25:22 +08:00
|
|
|
@dbus.service.method("org.bluez.Profile1",
|
2012-09-26 19:46:27 +08:00
|
|
|
in_signature="", out_signature="")
|
|
|
|
def Cancel(self):
|
|
|
|
print("Cancel")
|
|
|
|
|
2012-11-10 03:25:22 +08:00
|
|
|
@dbus.service.method("org.bluez.Profile1",
|
2012-11-09 18:29:33 +08:00
|
|
|
in_signature="oha{sv}", out_signature="")
|
|
|
|
def NewConnection(self, path, fd, properties):
|
2012-09-28 03:14:29 +08:00
|
|
|
fd = fd.take()
|
2012-09-26 19:46:27 +08:00
|
|
|
print("NewConnection(%s, %d)" % (path, fd))
|
2012-11-13 16:24:58 +08:00
|
|
|
for key in properties.keys():
|
2012-11-13 16:48:06 +08:00
|
|
|
if key == "Version" or key == "Features":
|
|
|
|
print(" %s = 0x%04x" % (key, properties[key]))
|
|
|
|
else:
|
|
|
|
print(" %s = %s" % (key, properties[key]))
|
2012-11-13 16:24:58 +08:00
|
|
|
|
2012-09-28 03:14:29 +08:00
|
|
|
os.close(fd)
|
2012-09-26 19:46:27 +08:00
|
|
|
|
2012-09-25 20:11:48 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
2012-11-10 03:25:22 +08:00
|
|
|
manager = dbus.Interface(bus.get_object("org.bluez",
|
|
|
|
"/org/bluez"), "org.bluez.ProfileManager1")
|
2012-09-25 20:11:48 +08:00
|
|
|
|
|
|
|
option_list = [
|
|
|
|
make_option("-u", "--uuid", action="store",
|
2012-09-26 19:46:27 +08:00
|
|
|
type="string", dest="uuid",
|
|
|
|
default="spp"),
|
2012-09-25 20:11:48 +08:00
|
|
|
make_option("-p", "--path", action="store",
|
2012-09-26 19:46:27 +08:00
|
|
|
type="string", dest="path",
|
|
|
|
default="/foo/bar/profile"),
|
|
|
|
make_option("-n", "--name", action="store",
|
|
|
|
type="string", dest="name",
|
|
|
|
default="Test Profile"),
|
|
|
|
make_option("-s", "--server",
|
|
|
|
action="store_const",
|
|
|
|
const="server", dest="role"),
|
|
|
|
make_option("-c", "--client",
|
|
|
|
action="store_const",
|
|
|
|
const="client", dest="role"),
|
|
|
|
make_option("-a", "--auto-connect",
|
|
|
|
action="store_true",
|
|
|
|
dest="auto_connect", default=False),
|
2012-09-26 20:12:45 +08:00
|
|
|
make_option("-P", "--PSM", action="store",
|
|
|
|
type="int", dest="psm"),
|
|
|
|
make_option("-C", "--channel", action="store",
|
2012-11-13 16:25:03 +08:00
|
|
|
type="int", dest="channel"),
|
|
|
|
make_option("-r", "--record", action="store",
|
|
|
|
type="string", dest="record",
|
|
|
|
default=None),
|
2012-09-25 20:11:48 +08:00
|
|
|
]
|
2012-09-26 19:46:27 +08:00
|
|
|
|
2012-09-25 20:11:48 +08:00
|
|
|
parser = OptionParser(option_list=option_list)
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
profile = Profile(bus, options.path)
|
|
|
|
|
|
|
|
mainloop = GObject.MainLoop()
|
|
|
|
|
2012-11-13 16:25:03 +08:00
|
|
|
if options.uuid == "hfp":
|
|
|
|
options.channel = 7
|
|
|
|
options.record = hfp_record
|
|
|
|
options.name = "HFP HandsFree"
|
|
|
|
|
2012-09-26 19:46:27 +08:00
|
|
|
opts = {
|
|
|
|
"Name" : options.name,
|
|
|
|
"AutoConnect" : options.auto_connect,
|
2012-09-26 00:17:00 +08:00
|
|
|
}
|
2012-09-25 20:11:48 +08:00
|
|
|
|
2012-09-26 19:46:27 +08:00
|
|
|
if (options.role):
|
|
|
|
opts["Role"] = options.role
|
|
|
|
|
2012-09-26 20:12:45 +08:00
|
|
|
if (options.psm):
|
|
|
|
opts["PSM"] = dbus.UInt16(options.psm)
|
|
|
|
|
|
|
|
if (options.channel):
|
|
|
|
opts["Channel"] = dbus.UInt16(options.channel)
|
|
|
|
|
2012-11-13 16:25:03 +08:00
|
|
|
if (options.record):
|
|
|
|
opts["ServiceRecord"] = options.record
|
|
|
|
|
2012-09-25 20:11:48 +08:00
|
|
|
manager.RegisterProfile(options.path, options.uuid, opts)
|
|
|
|
|
|
|
|
mainloop.run()
|