Base Code merged to SPIN 2.4
[platform/upstream/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] [hidden]" % (sys.argv[0])
8         print "Example:"
9         print "Create the open system access point:"
10         print "%s wifi abcd \"\"" % (sys.argv[0])
11         print "Create the security access point:"
12         print "%s wifi abcd 123456789" % (sys.argv[0])
13         print "Create the hidden access point:"
14         print "%s wifi abcd 123456789 hidden" % (sys.argv[0])
15         print "Create the open and hidden access point:"
16         print "%s wifi abcd \"\" hidden" % (sys.argv[0])
17         sys.exit(1)
18 elif (len(sys.argv) < 2):
19         print "Usage: %s type" % (sys.argv[0])
20         sys.exit(1)
21
22 bus = dbus.SystemBus()
23
24 manager = dbus.Interface(bus.get_object('net.connman', "/"),
25                                         'net.connman.Manager')
26
27 def technology_enable_tethering(path, tech_type, ssid, psk, hidden):
28         tech = dbus.Interface(bus.get_object("net.connman", path),
29                                                 "net.connman.Technology")
30
31         properties = tech.GetProperties()
32
33         for key in properties.keys():
34                 if key in ["Type"]:
35                         if properties[key] == tech_type:
36                                 if len(ssid) > 0:
37                                         tech.SetProperty("TetheringIdentifier",
38                                                                 ssid)
39                                         tech.SetProperty("TetheringPassphrase",
40                                                                 psk)
41                                 if tech_type == "wifi":
42                                         if len(hidden) > 0:
43                                                 if hidden == "hidden":
44                                                         tech.SetProperty("Hidden",dbus.Boolean(1))
45                                                 else:
46                                                         tech.SetProperty("Hidden",dbus.Boolean(0))
47                                         else:
48                                                 tech.SetProperty("Hidden",dbus.Boolean(0))
49
50                                 print "Enabling %s tethering" % tech_type
51                                 tech.SetProperty("Tethering", dbus.Boolean(1))
52
53                                 return tech_type
54                         else:
55                                 return None
56
57 technologies = manager.GetTechnologies()
58 tech = None
59
60 for path,_ in technologies:
61         if (len(sys.argv) == 5):
62                 tech = technology_enable_tethering(path,
63                                         sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
64         elif (len(sys.argv) == 4):
65                 tech = technology_enable_tethering(path,
66                                         sys.argv[1], sys.argv[2], sys.argv[3], "")
67         else:
68                 tech = technology_enable_tethering(path, sys.argv[1], "", "", "")
69
70         if tech != None:
71                 break;
72
73 if tech == None:
74         print "Failed to enable %s tethering" % (sys.argv[1])