Release tizen_2.0_beta
[framework/connectivity/connman.git] / test / simple-agent
index 7e1ce8b..d3bb315 100755 (executable)
@@ -8,51 +8,144 @@ import dbus.mainloop.glib
 import sys
 
 class Canceled(dbus.DBusException):
-       _dbus_error_name = "org.moblin.connman.Error.Canceled"
+       _dbus_error_name = "net.connman.Error.Canceled"
 
 class Agent(dbus.service.Object):
-       passphrase = ""
+       identity = None
+       passphrase = None
+       wpspin = None
+       username = None
+       password = None
 
-       @dbus.service.method("org.moblin.connman.Agent",
+       @dbus.service.method("net.connman.Agent",
                                        in_signature='', out_signature='')
        def Release(self):
                print("Release")
                mainloop.quit()
 
-       @dbus.service.method("org.moblin.connman.Agent",
+       def input_passphrase(self):
+               response = {}
+
+               if not self.identity and not self.passphrase and not self.wpspin:
+                       args = raw_input('Answer: ')
+
+                       for arg in args.split():
+                               if arg.startswith("Identity="):
+                                       identity = arg.replace("Identity=", "", 1)
+                                       response["Identity"] = identity
+                               if arg.startswith("Passphrase="):
+                                       passphrase = arg.replace("Passphrase=", "", 1)
+                                       response["Passphrase"] = passphrase
+                               if arg.startswith("WPS="):
+                                       wpspin = arg.replace("WPS=", "", 1)
+                                       response["WPS"] = wpspin
+                                       break
+               else:
+                       if self.identity:
+                               response["Identity"] = self.identity
+                       if self.passphrase:
+                               response["Passphrase"] = self.passphrase
+                       if self.wpspin:
+                               response["WPS"] = self.wpspin
+
+               return response
+
+       def input_username(self):
+               response = {}
+
+               if not self.username and not self.password:
+                       args = raw_input('Answer: ')
+
+                       for arg in args.split():
+                               if arg.startswith("Username="):
+                                       username = arg.replace("Username=", "", 1)
+                                       response["Username"] = username
+                               if arg.startswith("Password="):
+                                       password = arg.replace("Password=", "", 1)
+                                       response["Password"] = password
+               else:
+                       if self.username:
+                               response["Username"] = self.username
+                       if self.password:
+                               response["Password"] = self.password
+
+               return response
+
+       @dbus.service.method("net.connman.Agent",
                                        in_signature='oa{sv}',
                                        out_signature='a{sv}')
        def RequestInput(self, path, fields):
                print "RequestInput (%s,%s)" % (path, fields)
 
-               response = {}
-               response["Passphrase"] = self.passphrase
+               response = None
+
+               if fields.has_key("Passphrase"):
+                       response = self.input_passphrase()
+               elif fields.has_key("Username"):
+                       response = self.input_username()
+               else:
+                       print "No method to answer the input request"
 
                print "returning (%s)" % (response)
 
                return response
 
-       @dbus.service.method("org.moblin.connman.Agent",
+       @dbus.service.method("net.connman.Agent",
+                                       in_signature='os',
+                                       out_signature='')
+       def ReportError(self, path, error):
+               print "ReportError %s, %s" % (path, error)
+               retry = raw_input("Retry service (yes/no): ")
+               if (retry == "yes"):
+                       class Retry(dbus.DBusException):
+                               _dbus_error_name = "net.connman.Agent.Error.Retry"
+
+                       raise Retry("retry service")
+               else:
+                       return
+
+
+       @dbus.service.method("net.connman.Agent",
                                        in_signature='', out_signature='')
        def Cancel(self):
                print "Cancel"
 
-
+def print_usage():
+       print "Usage:"
+       print "For EAP/WPA input:"
+       print "%s Identity=<identity> Passphrase=<passphrase> WPS=<wpspin>" % (sys.argv[0])
+       print "For WISPr login input:"
+       print "%s Username=<username> Password=<password>" % (sys.argv[0])
+       print "Help: %s help" % (sys.argv[0])
+       sys.exit(1)
 
 if __name__ == '__main__':
-       if len(sys.argv) < 2:
-               print "Usage: %s <passphrase>" % (sys.argv[0])
-               sys.exit(1)
+       if len(sys.argv) == 2 and sys.argv[1] == "help":
+               print_usage()
 
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
        bus = dbus.SystemBus()
-       manager = dbus.Interface(bus.get_object('org.moblin.connman', "/"),
-                                       'org.moblin.connman.Manager')
+       manager = dbus.Interface(bus.get_object('net.connman', "/"),
+                                       'net.connman.Manager')
 
        path = "/test/agent"
        object = Agent(bus, path)
-       object.passphrase = sys.argv[1]
+
+       if len(sys.argv) >= 2:
+               for arg in sys.argv[1:]:
+                       if arg.startswith("Identity="):
+                               object.identity = arg.replace("Identity=", "", 1)
+                       elif arg.startswith("Passphrase="):
+                               object.passphrase = arg.replace("Passphrase=", "", 1)
+                       elif arg.startswith("WPS="):
+                               object.wpspin = arg.replace("WPS=", "", 1)
+                       elif arg.startswith("Username="):
+                               object.username = arg.replace("Username=", "", 1)
+                       elif arg.startswith("Password="):
+                               object.password = arg.replace("Password=", "", 1)
+                       else:
+                               print_usage()
 
        manager.RegisterAgent(path)