diff --git a/tools/obex-server-tool.c b/tools/obex-server-tool.c
index a25dfb9..d7ffe50 100644
--- a/tools/obex-server-tool.c
+++ b/tools/obex-server-tool.c
#include <sys/un.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <gobex/gobex.h>
+#include <btio/btio.h>
#include "glib-helper.h"
static gboolean option_packet = FALSE;
static gboolean option_bluetooth = FALSE;
+static int option_channel = -1;
static void sig_term(int sig)
{
&option_bluetooth, "Use a UNIX socket" },
{ "bluetooth", 'b', 0, G_OPTION_ARG_NONE,
&option_bluetooth, "Use Bluetooth" },
+ { "channel", 'c', 0, G_OPTION_ARG_INT,
+ &option_channel, "Transport channel", "CHANNEL" },
{ "packet", 'p', 0, G_OPTION_ARG_NONE,
&option_packet, "Packet based transport" },
{ "stream", 's', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
return TRUE;
}
+static void bluetooth_accept(GIOChannel *io, GError *err, gpointer data)
+{
+ GObex *obex;
+ GObexTransportType transport;
+
+ g_print("Accepted new client connection on bluetooth socket\n");
+
+ g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_close_on_unref(io, TRUE);
+
+ if (option_packet)
+ transport = G_OBEX_TRANSPORT_PACKET;
+ else
+ transport = G_OBEX_TRANSPORT_STREAM;
+
+ obex = g_obex_new(io, transport, -1, -1);
+ g_obex_set_disconnect_function(obex, disconn_func, NULL);
+ g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put, NULL);
+ g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, NULL);
+ g_obex_add_request_function(obex, G_OBEX_OP_CONNECT, handle_connect,
+ NULL);
+ clients = g_slist_append(clients, obex);
+}
+
+static gboolean bluetooth_watch(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+ if (cond & G_IO_NVAL)
+ return FALSE;
+
+ g_io_channel_shutdown(chan, TRUE, NULL);
+ return FALSE;
+}
+
+static guint bluetooth_listen(void)
+{
+ GIOChannel *io;
+ guint id;
+ GError *err = NULL;
+ BtIOType type;
+ BtIOOption option;
+
+ if (option_channel == -1) {
+ g_printerr("Bluetooth channel not set\n");
+ return 0;
+ }
+
+ if (option_packet || option_channel > 31) {
+ type = BT_IO_L2CAP;
+ option = BT_IO_OPT_PSM;
+ } else {
+ type = BT_IO_RFCOMM;
+ option = BT_IO_OPT_CHANNEL;
+ }
+
+ io = bt_io_listen(type, bluetooth_accept, NULL, NULL, NULL, &err,
+ option, option_channel,
+ BT_IO_OPT_INVALID);
+ if (io == NULL) {
+ g_printerr("%s\n", err->message);
+ g_error_free(err);
+ return 0;
+ }
+
+ g_print("Bluetooth socket created\n");
+
+ id = g_io_add_watch(io, G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ bluetooth_watch, NULL);
+
+ g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_close_on_unref(io, TRUE);
+ g_io_channel_unref(io);
+
+ return id;
+}
+
static guint unix_listen(void)
{
GIOChannel *io;
exit(EXIT_FAILURE);
}
- server_id = unix_listen();
+ if (option_bluetooth)
+ server_id = bluetooth_listen();
+ else
+ server_id = unix_listen();
+
if (server_id == 0)
exit(EXIT_FAILURE);