#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <syslog.h>
#include <signal.h>
+#include <getopt.h>
#include <sys/stat.h>
#include <gdbus.h>
g_main_loop_quit(main_loop);
}
+static void usage(void)
+{
+ printf("Connection Manager version %s\n\n", VERSION);
+
+ printf("Usage:\n"
+ "\tconnmand [options]\n"
+ "\n");
+
+ printf("Options:\n"
+ "\t-c, --compat Enable Network Manager compatibility\n"
+ "\t-n, --nodaemon Don't fork daemon to background\n"
+ "\t-h, --help Display help\n"
+ "\n");
+}
+
+static struct option options[] = {
+ { "nodaemon", 0, 0, 'n' },
+ { "compat", 0, 0, 'c' },
+ { "help", 0, 0, 'h' },
+ { }
+};
+
int main(int argc, char *argv[])
{
DBusConnection *conn;
struct sigaction sa;
+ int log_option = LOG_NDELAY | LOG_PID;
+ int opt, detach = 1, compat = 0;
+
+ while ((opt = getopt_long(argc, argv, "+nch", options, NULL)) != EOF) {
+ switch(opt) {
+ case 'n':
+ detach = 0;
+ break;
+ case 'c':
+ compat = 1;
+ break;
+ case 'h':
+ default:
+ usage();
+ exit(0);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ optind = 0;
+
+ if (detach) {
+ if (daemon(0, 0)) {
+ perror("Can't start daemon");
+ exit(1);
+ }
+ } else
+ log_option |= LOG_PERROR;
+
+ openlog("connmand", log_option, LOG_DAEMON);
mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
exit(1);
}
- __connman_manager_init(conn);
+ if (compat) {
+ if (g_dbus_request_name(conn, NM_SERVICE) == FALSE)
+ compat = 0;
+ }
+
+ __connman_manager_init(conn, compat);
__connman_plugin_init();
rmdir(STATEDIR);
+ closelog();
+
return 0;
}
{ },
};
+static DBusMessage *activate_device(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char *path;
+
+ DBG("conn %p", conn);
+
+ dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ DBG("device %s", path);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+static DBusMessage *set_wireless(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ dbus_bool_t enabled;
+
+ DBG("conn %p", conn);
+
+ dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &enabled,
+ DBUS_TYPE_INVALID);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+static DBusMessage *get_wireless(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ dbus_bool_t enabled = TRUE;
+
+ DBG("conn %p", conn);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &enabled,
+ DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+static DBusMessage *do_sleep(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ DBG("conn %p", conn);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+static DBusMessage *do_wake(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ DBG("conn %p", conn);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+enum {
+ NM_STATE_UNKNOWN = 0,
+ NM_STATE_ASLEEP,
+ NM_STATE_CONNECTING,
+ NM_STATE_CONNECTED,
+ NM_STATE_DISCONNECTED
+};
+
+static DBusMessage *get_state(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ dbus_uint32_t state = NM_STATE_DISCONNECTED;
+
+ DBG("conn %p", conn);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
+ DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+static GDBusMethodTable nm_methods[] = {
+ { "getDevices", "", "ao", list_interfaces },
+ { "setActiveDevice", "o", "", activate_device },
+ { "setWirelessEnabled", "b", "", set_wireless },
+ { "getWirelessEnabled", "", "b", get_wireless },
+ { "sleep", "", "", do_sleep },
+ { "wake", "", "", do_wake },
+ { "state", "", "u", get_state },
+ { },
+};
+
static DBusConnection *connection = NULL;
+static int nm_compat = 0;
-int __connman_manager_init(DBusConnection *conn)
+int __connman_manager_init(DBusConnection *conn, int compat)
{
DBG("conn %p", conn);
manager_methods,
manager_signals, NULL);
+ if (compat) {
+ g_dbus_register_object(connection, NM_PATH, NULL, NULL);
+
+ g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
+ nm_methods, NULL, NULL);
+
+ nm_compat = 1;
+ }
+
return 0;
}
{
DBG("conn %p", connection);
+ if (nm_compat) {
+ g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
+
+ g_dbus_unregister_object(connection, NM_PATH);
+ }
+
g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE);