test: Handle new tethering properties
[framework/connectivity/connman.git] / test / enable-tethering
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) < 4 and sys.argv[1] == "wifi"):
7         print "Usage: %s wifi [SSID] [passphrase]" % (sys.argv[0])
8         sys.exit(1)
9 elif (len(sys.argv) < 2):
10         print "Usage: %s type" % (sys.argv[0])
11
12 print "Enabling %s tethering" % (sys.argv[1])
13
14 bus = dbus.SystemBus()
15
16 manager = dbus.Interface(bus.get_object('net.connman', "/"),
17                                         'net.connman.Manager')
18
19 def technology_enable_tethering(path, tech_type, ssid, psk):
20         tech = dbus.Interface(bus.get_object("net.connman", path),
21                                                 "net.connman.Technology")
22
23         properties = tech.GetProperties()
24
25         for key in properties.keys():
26                 if key in ["Type"]:
27                         if properties[key] == tech_type:
28                                 if len(ssid) > 0:
29                                         tech.SetProperty("TetheringIdentifier",
30                                                                 ssid)
31                                 if len(psk) > 0:
32                                         tech.SetProperty("TetheringPassphrase",
33                                                                 psk)
34                                 tech.SetProperty("Tethering", dbus.Boolean(1))
35
36 properties = manager.GetProperties()
37
38 for key in properties.keys():
39         if key in ["Technologies"]:
40                 for path in properties[key]:
41                         if (len(sys.argv) == 4):
42                                 technology_enable_tethering(path, sys.argv[1],
43                                                 sys.argv[2], sys.argv[3])
44                         else:
45                                 technology_enable_tethering(path, sys.argv[1],
46                                                                         "", "")