service: Send D-Bus reply for Manager.ConnectService when service is ready
[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 bus = dbus.SystemBus()
13
14 manager = dbus.Interface(bus.get_object('net.connman', "/"),
15                                         'net.connman.Manager')
16
17 def technology_enable_tethering(path, tech_type, ssid, psk):
18         tech = dbus.Interface(bus.get_object("net.connman", path),
19                                                 "net.connman.Technology")
20
21         properties = tech.GetProperties()
22
23         for key in properties.keys():
24                 if key in ["Type"]:
25                         if properties[key] == tech_type:
26                                 if len(ssid) > 0:
27                                         tech.SetProperty("TetheringIdentifier",
28                                                                 ssid)
29                                 if len(psk) > 0:
30                                         tech.SetProperty("TetheringPassphrase",
31                                                                 psk)
32                                 print "Enabling %s tethering" % tech_type
33                                 tech.SetProperty("Tethering", dbus.Boolean(1))
34
35                                 return tech_type
36                         else:
37                                 return None
38
39 properties = manager.GetProperties()
40
41 for key in properties.keys():
42         if key in ["Technologies"]:
43                 for path in properties[key]:
44                         if (len(sys.argv) == 4):
45                                 tech = technology_enable_tethering(path,
46                                         sys.argv[1], sys.argv[2], sys.argv[3])
47                         else:
48                                 tech = technology_enable_tethering(path,
49                                                         sys.argv[1], "", "")
50
51                         if tech != None:
52                                 break;
53
54 if tech == None:
55         print "Failed to enable %s tethering" % (sys.argv[1])