Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / test / test-network
1 #!/usr/bin/python
2
3 from __future__ import absolute_import, print_function, unicode_literals
4
5 from optparse import OptionParser, make_option
6 import sys
7 import time
8 import dbus
9 import bluezutils
10
11 bus = dbus.SystemBus()
12
13 manager = dbus.Interface(bus.get_object("org.bluez", "/"),
14                                                 "org.bluez.Manager")
15
16 option_list = [
17                 make_option("-i", "--device", action="store",
18                                 type="string", dest="dev_id"),
19                 ]
20 parser = OptionParser(option_list=option_list)
21
22 (options, args) = parser.parse_args()
23
24 if (len(args) < 1):
25         print("Usage: %s <address> [service]" % (sys.argv[0]))
26         sys.exit(1)
27
28 # Fix-up in case of "connect" invocation that other scripts use
29 if args[0] == "connect":
30         del args[:1]
31
32 if (len(args) < 2):
33         service = "panu"
34 else:
35         service = args[1]
36
37 device = bluezutils.find_device(args[0], options.dev_id)
38
39 network = dbus.Interface(bus.get_object("org.bluez", device.object_path),
40                                                 "org.bluez.Network1")
41
42 iface = network.Connect(service)
43
44 print("Connected to %s service %s, interface %s" % (args[0], service, iface))
45
46 print("Press CTRL-C to disconnect")
47
48 try:
49         time.sleep(1000)
50         print("Terminating connection")
51 except:
52         pass
53
54 network.Disconnect()