wifi: Add support for autoscan request
[framework/connectivity/connman.git] / test / enable-tethering
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) >= 2 and 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         sys.exit(1)
12
13 bus = dbus.SystemBus()
14
15 manager = dbus.Interface(bus.get_object('net.connman', "/"),
16                                         'net.connman.Manager')
17
18 def technology_enable_tethering(path, tech_type, ssid, psk):
19         tech = dbus.Interface(bus.get_object("net.connman", path),
20                                                 "net.connman.Technology")
21
22         properties = tech.GetProperties()
23
24         for key in properties.keys():
25                 if key in ["Type"]:
26                         if properties[key] == tech_type:
27                                 if len(ssid) > 0:
28                                         tech.SetProperty("TetheringIdentifier",
29                                                                 ssid)
30                                 if len(psk) > 0:
31                                         tech.SetProperty("TetheringPassphrase",
32                                                                 psk)
33                                 print "Enabling %s tethering" % tech_type
34                                 tech.SetProperty("Tethering", dbus.Boolean(1))
35
36                                 return tech_type
37                         else:
38                                 return None
39
40 technologies = manager.GetTechnologies()
41 tech = None
42
43 for path,_ in technologies:
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, sys.argv[1], "", "")
49
50         if tech != None:
51                 break;
52
53 if tech == None:
54         print "Failed to enable %s tethering" % (sys.argv[1])