Bluez moves agent registration from a per device interface to a per adapter interface. Update dun_gw modem emulator to reflect this change. --- plugins/dun_gw.c | 119 ++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 67 deletions(-)
diff --git a/plugins/dun_gw.c b/plugins/dun_gw.c index 75b62eb..5cc839e 100644 --- a/plugins/dun_gw.c +++ b/plugins/dun_gw.c @@ -35,77 +35,65 @@ #include "bluetooth.h" -#define DUN_GW_CHANNEL 1 +#define AGENT_PATH "/dun_gw" +#define VERSION_1_0 0x0100 + +#ifndef DBUS_TYPE_UNIX_FD +#define DBUS_TYPE_UNIX_FD -1 +#endif -static struct server *server; static guint modemwatch_id; static GList *modems; -static const gchar *dun_record = -"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" -"<record>\n" -" <attribute id=\"0x0001\">\n" -" <sequence>\n" -" <uuid value=\"0x1103\"/>\n" -" </sequence>\n" -" </attribute>\n" -"\n" -" <attribute id=\"0x0004\">\n" -" <sequence>\n" -" <sequence>\n" -" <uuid value=\"0x0100\"/>\n" -" </sequence>\n" -" <sequence>\n" -" <uuid value=\"0x0003\"/>\n" -" <uint8 value=\"1\" name=\"channel\"/>\n" -" </sequence>\n" -" </sequence>\n" -" </attribute>\n" -"\n" -" <attribute id=\"0x0009\">\n" -" <sequence>\n" -" <sequence>\n" -" <uuid value=\"0x1103\"/>\n" -" <uint16 value=\"0x0100\" name=\"version\"/>\n" -" </sequence>\n" -" </sequence>\n" -" </attribute>\n" -"\n" -" <attribute id=\"0x0100\">\n" -" <text value=\"Dial-up Networking\" name=\"name\"/>\n" -" </attribute>\n" -"</record>\n"; - -static void dun_gw_connect_cb(GIOChannel *io, GError *err, gpointer user_data) +static DBusMessage *dun_gw_agent_new_connection(DBusConnection *conn, + DBusMessage *msg, void *data) { - struct ofono_emulator *em = user_data; - struct ofono_modem *modem; int fd; + const char *device; + guint16 version = 0; + struct ofono_emulator *em; + struct ofono_modem *modem; - DBG(""); + fd = bluetooth_parse_newconnection_message(msg, &device, &version, NULL, + NULL); + if (fd < 0) + return __ofono_error_invalid_args(msg); - if (err) { - DBG("%s", err->message); - g_io_channel_shutdown(io, TRUE, NULL); - return; - } + DBG("New connection for %s (version 0x%04X)", device, version); /* Pick the first powered modem */ modem = modems->data; + if (modem == NULL) + return __ofono_error_failed(msg); + DBG("Picked modem %p for emulator", modem); em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_DUN); - if (em == NULL) { - g_io_channel_shutdown(io, TRUE, NULL); - return; - } - - fd = g_io_channel_unix_get_fd(io); - g_io_channel_set_close_on_unref(io, FALSE); + if (em == NULL) + return __ofono_error_failed(msg); ofono_emulator_register(em, fd); + + return dbus_message_new_method_return(msg); +} + +static DBusMessage *dun_gw_agent_release(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBG(""); + + return dbus_message_new_method_return(msg); } +static const GDBusMethodTable agent_methods[] = { + { GDBUS_ASYNC_METHOD("NewConnection", + GDBUS_ARGS({ "fd", "h" }, + { "property", "a{sv}" }), + NULL, dun_gw_agent_new_connection) }, + { GDBUS_METHOD("Release", NULL, NULL, dun_gw_agent_release) }, + { } +}; + static void gprs_watch(struct ofono_atom *atom, enum ofono_atom_watch_condition cond, void *data) @@ -115,17 +103,16 @@ static void gprs_watch(struct ofono_atom *atom, if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) { modems = g_list_append(modems, modem); - if (modems->next == NULL) - server = bluetooth_register_server(DUN_GW_CHANNEL, - dun_record, - dun_gw_connect_cb, - NULL); + if (modems->next != NULL) + return; + + bluetooth_register_telephony_agent(AGENT_PATH, DUN_GW_UUID, + VERSION_1_0, 0, + agent_methods, NULL, NULL); } else { modems = g_list_remove(modems, modem); - if (modems == NULL && server != NULL) { - bluetooth_unregister_server(server); - server = NULL; - } + if (modems == NULL) + bluetooth_unregister_telephony_agent(AGENT_PATH); } } @@ -149,6 +136,9 @@ static int dun_gw_init(void) { DBG(""); + if (DBUS_TYPE_UNIX_FD < 0) + return -EBADF; + modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL); __ofono_modem_foreach(call_modemwatch, NULL); @@ -160,11 +150,6 @@ static void dun_gw_exit(void) { __ofono_modemwatch_remove(modemwatch_id); g_list_free(modems); - - if (server) { - bluetooth_unregister_server(server); - server = NULL; - } } OFONO_PLUGIN_DEFINE(dun_gw, "Dial-up Networking Profile Plugins", VERSION, -- 1.7.9.5 _______________________________________________ ofono mailing list ofono@ofono.org http://lists.ofono.org/listinfo/ofono