Add first version of script for applying GPRS settings
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 23 Nov 2009 23:50:06 +0000 (00:50 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 23 Nov 2009 23:50:06 +0000 (00:50 +0100)
Makefile.am
test/process-context-settings [new file with mode: 0755]

index d5e5311..4b0d7e8 100644 (file)
@@ -241,7 +241,8 @@ test_files = test/test-manager test/test-modem test/test-voicecall \
                test/list-operators test/dial-number test/hangup-all \
                test/receive-sms test/send-sms \
                test/list-contexts test/create-context \
-               test/activate-context test/deactivate-context
+               test/activate-context test/deactivate-context \
+               test/process-context-settings
 
 conf_files = src/ofono.conf plugins/modem.conf
 
diff --git a/test/process-context-settings b/test/process-context-settings
new file mode 100755 (executable)
index 0000000..c984240
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+import os
+import dbus
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('org.ofono', '/'),
+                                               'org.ofono.Manager')
+
+properties = manager.GetProperties()
+
+for path in properties["Modems"]:
+       modem = dbus.Interface(bus.get_object('org.ofono', path),
+                                                       'org.ofono.Modem')
+
+       properties = modem.GetProperties()
+
+       if "org.ofono.DataConnectionManager" not in properties["Interfaces"]:
+               continue
+
+       connmgr = dbus.Interface(bus.get_object('org.ofono', path),
+                                       'org.ofono.DataConnectionManager')
+
+       properties = connmgr.GetProperties()
+
+       for path in properties["PrimaryContexts"]:
+               context = dbus.Interface(bus.get_object('org.ofono', path),
+                                       'org.ofono.PrimaryDataContext')
+
+               properties = context.GetProperties()
+
+               if properties["Active"] == dbus.Boolean(0):
+                       continue
+
+               print "Configuring %s" % (path)
+
+               settings = properties["Settings"]
+
+               interface = settings["Interface"]
+               address = settings["Address"]
+               gateway = settings["Gateway"]
+
+               if settings["Method"] == "dhcp":
+                       print "    Run DHCP on interface %s" % (interface)
+               else:
+                       print "    IP address is %s" % (address)
+                       print "    Gateway is %s" % (gateway)
+
+                       cmd = "ifconfig " + interface + " " + address
+                       cmd += " netmask 255.255.255.255"
+                       os.system(cmd);
+
+                       for i in settings["DomainNameServers"]:
+                               print "    Nameserver is %s" % (i)
+
+                               cmd = "route add -host " + i
+                               cmd +=" dev " + interface
+                               os.system(cmd);
+               print