All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH obexd 1/6] gobex: fix not handling unkown transport type
@ 2011-08-26  9:49 Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 2/6] gobex: fix setting final bit on PUT requests Luiz Augusto von Dentz
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-26  9:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 gobex/gobex.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/gobex/gobex.c b/gobex/gobex.c
index ff35830..7c2fbcc 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -884,6 +884,9 @@ GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
 		obex->read = read_packet;
 		obex->write = write_packet;
 		break;
+	default:
+		g_obex_unref(obex);
+		return NULL;
 	}
 
 	g_io_channel_set_encoding(io, NULL, NULL);
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH obexd 2/6] gobex: fix setting final bit on PUT requests
  2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
@ 2011-08-26  9:49 ` Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 3/6] gobex: Add random put request test Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-26  9:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Final bit should not be set when creating new request packets for PUT
since it may be not be the end of the body.
---
 gobex/gobex-transfer.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index fad641b..386ba9a 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -170,9 +170,11 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
 		return;
 	}
 
-	req = g_obex_packet_new(transfer->opcode, TRUE, G_OBEX_HDR_INVALID);
+	final = transfer->opcode == G_OBEX_OP_PUT ? FALSE : TRUE;
 
-	if (transfer->opcode == G_OBEX_OP_PUT)
+	req = g_obex_packet_new(transfer->opcode, final, G_OBEX_HDR_INVALID);
+
+	if (!final)
 		g_obex_packet_add_body(req, put_get_data, transfer);
 
 	transfer->req_id = g_obex_send_req(obex, req, -1, transfer_response,
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH obexd 3/6] gobex: Add random put request test
  2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 2/6] gobex: fix setting final bit on PUT requests Luiz Augusto von Dentz
@ 2011-08-26  9:49 ` Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 4/6] gobex: Add Bluetooth support for test-client Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-26  9:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 unit/test-gobex-transfer.c |  102 ++++++++++++++++++++++++++++++++++++++------
 unit/util.h                |    4 +-
 2 files changed, 90 insertions(+), 16 deletions(-)

diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index aeea846..a246418 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -22,16 +22,19 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdint.h>
+#include <fcntl.h>
 
 #include <gobex/gobex.h>
 
 #include "util.h"
 
 #define FINAL_BIT 0x80
+#define RANDOM_PACKETS 4
 
 static guint8 put_req_first[] = { G_OBEX_OP_PUT, 0x00, 0x30,
 	G_OBEX_HDR_TYPE, 0x00, 0x0b,
@@ -81,6 +84,28 @@ static gboolean resume_obex(gpointer user_data)
 	return FALSE;
 }
 
+static gssize provide_random(void *buf, gsize len, gpointer user_data)
+{
+	struct test_data *d = user_data;
+	int fd;
+	gssize ret;
+
+	if (d->count == RANDOM_PACKETS - 1)
+		return 0;
+
+	fd = open("/dev/urandom", O_RDONLY | O_NOCTTY, 0);
+	if (fd < 0) {
+		g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+				"open(/dev/urandom): %s", strerror(errno));
+		g_main_loop_quit(d->mainloop);
+		return -1;
+	}
+
+	ret = read(fd, buf, len);
+	close(fd);
+	return ret;
+}
+
 static gssize provide_eagain(void *buf, gsize len, gpointer user_data)
 {
 	struct test_data *d = user_data;
@@ -328,19 +353,25 @@ static void handle_get(GObex *obex, GObexPacket *req, gpointer user_data)
 		g_main_loop_quit(d->mainloop);
 }
 
-static void test_get_rsp(void)
+static void test_put_req_random(void)
 {
 	GIOChannel *io;
 	GIOCondition cond;
 	guint io_id, timer_id;
 	GObex *obex;
 	struct test_data d = { 0, NULL, {
-				{ get_rsp_first, sizeof(get_rsp_first) },
-				{ get_rsp_last, sizeof(get_rsp_last) } }, {
-				{ get_req_last, sizeof(get_req_last) },
-				{ NULL, 0 } } };
+				{ NULL, 0 },
+				{ NULL, 0 },
+				{ NULL, 0 },
+				{ put_req_last, sizeof(put_req_last) } }, {
+				{ put_rsp_first, sizeof(put_rsp_first) },
+				{ put_rsp_first, sizeof(put_rsp_first) },
+				{ put_rsp_first, sizeof(put_rsp_first) },
+				{ put_rsp_last, sizeof(put_rsp_last) } } };
 
 	create_endpoints(&obex, &io, SOCK_STREAM);
+	d.obex = obex;
+	d.provide_delay = 200;
 
 	cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
 	io_id = g_io_add_watch(io, cond, test_io_cb, &d);
@@ -349,15 +380,15 @@ static void test_get_rsp(void)
 
 	timer_id = g_timeout_add_seconds(1, test_timeout, &d);
 
-	g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, &d);
-
-	g_io_channel_write_chars(io, (char *) get_req_first,
-					sizeof(get_req_first), NULL, &d.err);
+	g_obex_put_req(obex, provide_random, transfer_complete, &d, &d.err,
+					G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
+					G_OBEX_HDR_NAME, "random.bin",
+					G_OBEX_HDR_INVALID);
 	g_assert_no_error(d.err);
 
 	g_main_loop_run(d.mainloop);
 
-	g_assert_cmpuint(d.count, ==, 1);
+	g_assert_cmpuint(d.count, ==, RANDOM_PACKETS);
 
 	g_main_loop_unref(d.mainloop);
 
@@ -369,7 +400,7 @@ static void test_get_rsp(void)
 	g_assert_no_error(d.err);
 }
 
-static void test_put_req_delay(void)
+static void test_put_req_eagain(void)
 {
 	GIOChannel *io;
 	GIOCondition cond;
@@ -392,7 +423,7 @@ static void test_put_req_delay(void)
 
 	timer_id = g_timeout_add_seconds(1, test_timeout, &d);
 
-	g_obex_put_req(obex, provide_data, transfer_complete, &d, &d.err,
+	g_obex_put_req(obex, provide_eagain, transfer_complete, &d, &d.err,
 					G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
 					G_OBEX_HDR_NAME, "file.txt",
 					G_OBEX_HDR_INVALID);
@@ -412,7 +443,48 @@ static void test_put_req_delay(void)
 	g_assert_no_error(d.err);
 }
 
-static void test_put_req_eagain(void)
+static void test_get_rsp(void)
+{
+	GIOChannel *io;
+	GIOCondition cond;
+	guint io_id, timer_id;
+	GObex *obex;
+	struct test_data d = { 0, NULL, {
+				{ get_rsp_first, sizeof(get_rsp_first) },
+				{ get_rsp_last, sizeof(get_rsp_last) } }, {
+				{ get_req_last, sizeof(get_req_last) },
+				{ NULL, 0 } } };
+
+	create_endpoints(&obex, &io, SOCK_STREAM);
+
+	cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
+	io_id = g_io_add_watch(io, cond, test_io_cb, &d);
+
+	d.mainloop = g_main_loop_new(NULL, FALSE);
+
+	timer_id = g_timeout_add_seconds(1, test_timeout, &d);
+
+	g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, &d);
+
+	g_io_channel_write_chars(io, (char *) get_req_first,
+					sizeof(get_req_first), NULL, &d.err);
+	g_assert_no_error(d.err);
+
+	g_main_loop_run(d.mainloop);
+
+	g_assert_cmpuint(d.count, ==, 1);
+
+	g_main_loop_unref(d.mainloop);
+
+	g_source_remove(timer_id);
+	g_io_channel_unref(io);
+	g_source_remove(io_id);
+	g_obex_unref(obex);
+
+	g_assert_no_error(d.err);
+}
+
+static void test_put_req_delay(void)
 {
 	GIOChannel *io;
 	GIOCondition cond;
@@ -435,7 +507,7 @@ static void test_put_req_eagain(void)
 
 	timer_id = g_timeout_add_seconds(1, test_timeout, &d);
 
-	g_obex_put_req(obex, provide_eagain, transfer_complete, &d, &d.err,
+	g_obex_put_req(obex, provide_data, transfer_complete, &d, &d.err,
 					G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
 					G_OBEX_HDR_NAME, "file.txt",
 					G_OBEX_HDR_INVALID);
@@ -558,6 +630,8 @@ int main(int argc, char *argv[])
 	g_test_add_func("/gobex/test_put_req_eagain", test_put_req_eagain);
 	g_test_add_func("/gobex/test_put_req_eagain", test_get_rsp_eagain);
 
+	g_test_add_func("/gobex/test_put_req_random", test_put_req_random);
+
 	g_test_run();
 
 	return 0;
diff --git a/unit/util.h b/unit/util.h
index 1878051..4a7fc43 100644
--- a/unit/util.h
+++ b/unit/util.h
@@ -34,8 +34,8 @@ struct test_buf {
 struct test_data {
 	guint count;
 	GError *err;
-	struct test_buf recv[3];
-	struct test_buf send[3];
+	struct test_buf recv[4];
+	struct test_buf send[4];
 	guint provide_delay;
 	GObex *obex;
 	GMainLoop *mainloop;
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH obexd 4/6] gobex: Add Bluetooth support for test-client
  2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 2/6] gobex: fix setting final bit on PUT requests Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 3/6] gobex: Add random put request test Luiz Augusto von Dentz
@ 2011-08-26  9:49 ` Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 5/6] gobex: Add Bluetooth support for test-server Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-26  9:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 tools/test-client.c |  216 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 155 insertions(+), 61 deletions(-)

diff --git a/tools/test-client.c b/tools/test-client.c
index ec6d1c2..d967f02 100644
--- a/tools/test-client.c
+++ b/tools/test-client.c
@@ -33,12 +33,16 @@
 #include <readline/history.h>
 
 #include <gobex/gobex.h>
+#include <btio/btio.h>
 
 static GMainLoop *main_loop = NULL;
 static GObex *obex = NULL;
 
 static gboolean option_packet = FALSE;
 static gboolean option_bluetooth = FALSE;
+static char *option_source = NULL;
+static char *option_dest = NULL;
+static int option_channel = -1;
 
 static void sig_term(int sig)
 {
@@ -51,6 +55,14 @@ static GOptionEntry options[] = {
 			&option_bluetooth, "Use a UNIX socket" },
 	{ "bluetooth", 'b', 0, G_OPTION_ARG_NONE,
 			&option_bluetooth, "Use Bluetooth" },
+	{ "source", 's', 0, G_OPTION_ARG_STRING,
+			&option_source, "Bluetooth adapter address",
+			"00:..." },
+	{ "destination", 'd', 0, G_OPTION_ARG_STRING,
+			&option_dest, "Remote bluetooth address",
+			"00:..." },
+	{ "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,
@@ -58,48 +70,6 @@ static GOptionEntry options[] = {
 	{ NULL },
 };
 
-static void disconn_func(GObex *obex, GError *err, gpointer user_data)
-{
-	g_printerr("Disconnected: %s\n", err ? err->message : "(no error)");
-	g_main_loop_quit(main_loop);
-}
-
-static GIOChannel *unix_connect(void)
-{
-	GIOChannel *io;
-	struct sockaddr_un addr = {
-		AF_UNIX, "\0/gobex/server"
-	};
-	int sk, err, sock_type;
-
-	if (option_packet)
-		sock_type = SOCK_SEQPACKET;
-	else
-		sock_type = SOCK_STREAM;
-
-	sk = socket(PF_LOCAL, sock_type, 0);
-	if (sk < 0) {
-		err = errno;
-		g_printerr("Can't create unix socket: %s (%d)\n",
-						strerror(err), err);
-		return NULL;
-	}
-
-	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		err = errno;
-		g_printerr("connect: %s (%d)\n", strerror(err), err);
-		return NULL;
-	}
-
-	io = g_io_channel_unix_new(sk);
-	g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
-	g_io_channel_set_close_on_unref(io, TRUE);
-
-	g_print("Unix socket created: %d\n", sk);
-
-	return io;
-}
-
 static void conn_complete(GObex *obex, GError *err, GObexPacket *rsp,
 							gpointer user_data)
 {
@@ -293,13 +263,145 @@ static gboolean prompt_read(GIOChannel *chan, GIOCondition cond,
 	return TRUE;
 }
 
+static void disconn_func(GObex *obex, GError *err, gpointer user_data)
+{
+	g_printerr("Disconnected: %s\n", err ? err->message : "(no error)");
+	g_main_loop_quit(main_loop);
+}
+
+static void transport_connect(GIOChannel *io, GObexTransportType transport,
+				gssize rx_mtu, gssize tx_mtu)
+{
+	GIOChannel *input;
+	GIOCondition events;
+
+	g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+	g_io_channel_set_close_on_unref(io, TRUE);
+
+	obex = g_obex_new(io, transport, rx_mtu, tx_mtu);
+	g_obex_set_disconnect_function(obex, disconn_func, NULL);
+
+	input = g_io_channel_unix_new(STDIN_FILENO);
+	g_io_channel_set_close_on_unref(input, TRUE);
+	events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
+	g_io_add_watch(input, events, prompt_read, NULL);
+	g_io_channel_unref(input);
+	rl_callback_handler_install("client> ", parse_line);
+}
+
+static GIOChannel *unix_connect(GObexTransportType transport)
+{
+	GIOChannel *io;
+	struct sockaddr_un addr = {
+		AF_UNIX, "\0/gobex/server"
+	};
+	int sk, err, sock_type;
+
+	if (option_packet)
+		sock_type = SOCK_SEQPACKET;
+	else
+		sock_type = SOCK_STREAM;
+
+	sk = socket(PF_LOCAL, sock_type, 0);
+	if (sk < 0) {
+		err = errno;
+		g_printerr("Can't create unix socket: %s (%d)\n",
+						strerror(err), err);
+		return NULL;
+	}
+
+	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		err = errno;
+		g_printerr("connect: %s (%d)\n", strerror(err), err);
+		return NULL;
+	}
+
+	io = g_io_channel_unix_new(sk);
+
+	g_print("Unix socket created: %d\n", sk);
+
+	transport_connect(io, transport, -1, -1);
+
+	return io;
+}
+
+static void conn_callback(GIOChannel *io, GError *err, gpointer user_data)
+{
+	GObexTransportType transport = GPOINTER_TO_UINT(user_data);
+	guint16 imtu = 4096, omtu = 32767;
+
+	if (err != NULL) {
+		g_printerr("%s\n", err->message);
+		return;
+	}
+
+	if (transport == G_OBEX_TRANSPORT_PACKET) {
+		GError *err = NULL;
+
+		if (!bt_io_get(io, BT_IO_L2CAP, &err,
+					BT_IO_OPT_OMTU, &omtu,
+					BT_IO_OPT_IMTU, &imtu,
+					BT_IO_OPT_INVALID)) {
+			g_printerr("%s\n", err->message);
+			g_clear_error(&err);
+			exit(EXIT_FAILURE);
+		} else
+			g_print("imtu=%u, omtu=%u\n", imtu, omtu);
+	}
+
+	g_print("Bluetooth socket connected\n");
+
+	transport_connect(io, transport, imtu, omtu);
+}
+
+static GIOChannel *bluetooth_connect(GObexTransportType transport)
+{
+	GIOChannel *io;
+	GError *err = NULL;
+	BtIOType type;
+	BtIOOption option;
+
+	if (option_dest == NULL || option_channel < 0)
+		return NULL;
+
+	if (transport == G_OBEX_TRANSPORT_PACKET || option_channel > 31) {
+		type = BT_IO_L2CAP;
+		option = BT_IO_OPT_PSM;
+	} else {
+		type = BT_IO_RFCOMM;
+		option = BT_IO_OPT_CHANNEL;
+	}
+
+	if (option_source)
+		io = bt_io_connect(type, conn_callback, GUINT_TO_POINTER(transport),
+				NULL, &err,
+				BT_IO_OPT_SOURCE, option_source,
+				BT_IO_OPT_DEST, option_dest,
+				option, option_channel,
+				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+				BT_IO_OPT_INVALID);
+	else
+		io = bt_io_connect(type, conn_callback, GUINT_TO_POINTER(transport),
+				NULL, &err,
+				BT_IO_OPT_DEST, option_dest,
+				option, option_channel,
+				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+				BT_IO_OPT_INVALID);
+
+	if (io != NULL)
+		return io;
+
+	g_printerr("%s\n", err->message);
+	g_error_free(err);
+	return NULL;
+}
+
 int main(int argc, char *argv[])
 {
 	GOptionContext *context;
 	GError *err = NULL;
 	struct sigaction sa;
 	GIOChannel *io;
-	GIOCondition events;
 	GObexTransportType transport;
 
 	context = g_option_context_new(NULL);
@@ -312,7 +414,16 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	io = unix_connect();
+	if (option_packet)
+		transport = G_OBEX_TRANSPORT_PACKET;
+	else
+		transport = G_OBEX_TRANSPORT_STREAM;
+
+	if (option_bluetooth)
+		io = bluetooth_connect(transport);
+	else
+		io = unix_connect(transport);
+
 	if (io == NULL)
 		exit(EXIT_FAILURE);
 
@@ -323,23 +434,6 @@ int main(int argc, char *argv[])
 
 	main_loop = g_main_loop_new(NULL, FALSE);
 
-	if (option_packet)
-		transport = G_OBEX_TRANSPORT_PACKET;
-	else
-		transport = G_OBEX_TRANSPORT_STREAM;
-
-	obex = g_obex_new(io, transport, -1, -1);
-	g_io_channel_unref(io);
-
-	g_obex_set_disconnect_function(obex, disconn_func, NULL);
-
-	io = g_io_channel_unix_new(STDIN_FILENO);
-	g_io_channel_set_close_on_unref(io, TRUE);
-	events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-	g_io_add_watch(io, events, prompt_read, NULL);
-	g_io_channel_unref(io);
-	rl_callback_handler_install("client> ", parse_line);
-
 	g_main_loop_run(main_loop);
 
 	rl_callback_handler_remove();
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH obexd 5/6] gobex: Add Bluetooth support for test-server
  2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2011-08-26  9:49 ` [PATCH obexd 4/6] gobex: Add Bluetooth support for test-client Luiz Augusto von Dentz
@ 2011-08-26  9:49 ` Luiz Augusto von Dentz
  2011-08-26  9:49 ` [PATCH obexd 6/6] gobex: add root support to test-server Luiz Augusto von Dentz
  2011-08-29 10:43 ` [PATCH obexd 1/6] gobex: fix not handling unkown transport type Johan Hedberg
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-26  9:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 tools/test-server.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 85 insertions(+), 1 deletions(-)

diff --git a/tools/test-server.c b/tools/test-server.c
index a25dfb9..d7ffe50 100644
--- a/tools/test-server.c
+++ b/tools/test-server.c
@@ -29,10 +29,12 @@
 #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"
 
@@ -42,6 +44,7 @@ static GSList *clients = NULL;
 
 static gboolean option_packet = FALSE;
 static gboolean option_bluetooth = FALSE;
+static int option_channel = -1;
 
 static void sig_term(int sig)
 {
@@ -54,6 +57,8 @@ static GOptionEntry options[] = {
 			&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,
@@ -265,6 +270,81 @@ static gboolean unix_accept(GIOChannel *chan, GIOCondition cond, gpointer data)
 	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;
@@ -331,7 +411,11 @@ int main(int argc, char *argv[])
 		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);
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH obexd 6/6] gobex: add root support to test-server
  2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2011-08-26  9:49 ` [PATCH obexd 5/6] gobex: Add Bluetooth support for test-server Luiz Augusto von Dentz
@ 2011-08-26  9:49 ` Luiz Augusto von Dentz
  2011-08-29 10:43 ` [PATCH obexd 1/6] gobex: fix not handling unkown transport type Johan Hedberg
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-26  9:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 tools/test-server.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/tools/test-server.c b/tools/test-server.c
index d7ffe50..728e2ad 100644
--- a/tools/test-server.c
+++ b/tools/test-server.c
@@ -45,6 +45,7 @@ static GSList *clients = NULL;
 static gboolean option_packet = FALSE;
 static gboolean option_bluetooth = FALSE;
 static int option_channel = -1;
+static char *option_root = NULL;
 
 static void sig_term(int sig)
 {
@@ -63,6 +64,8 @@ static GOptionEntry options[] = {
 			&option_packet, "Packet based transport" },
 	{ "stream", 's', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
 			&option_packet, "Stream based transport" },
+	{ "root", 'r', 0, G_OPTION_ARG_STRING,
+			&option_root, "Root dir", "/..." },
 	{ NULL },
 };
 
@@ -411,6 +414,11 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	if (option_root && chdir(option_root) > 0) {
+		perror("chdir:");
+		exit(EXIT_FAILURE);
+	}
+
 	if (option_bluetooth)
 		server_id = bluetooth_listen();
 	else
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH obexd 1/6] gobex: fix not handling unkown transport type
  2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2011-08-26  9:49 ` [PATCH obexd 6/6] gobex: add root support to test-server Luiz Augusto von Dentz
@ 2011-08-29 10:43 ` Johan Hedberg
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2011-08-29 10:43 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

On Fri, Aug 26, 2011, Luiz Augusto von Dentz wrote:
> ---
>  gobex/gobex.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

All six patches have been applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-29 10:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26  9:49 [PATCH obexd 1/6] gobex: fix not handling unkown transport type Luiz Augusto von Dentz
2011-08-26  9:49 ` [PATCH obexd 2/6] gobex: fix setting final bit on PUT requests Luiz Augusto von Dentz
2011-08-26  9:49 ` [PATCH obexd 3/6] gobex: Add random put request test Luiz Augusto von Dentz
2011-08-26  9:49 ` [PATCH obexd 4/6] gobex: Add Bluetooth support for test-client Luiz Augusto von Dentz
2011-08-26  9:49 ` [PATCH obexd 5/6] gobex: Add Bluetooth support for test-server Luiz Augusto von Dentz
2011-08-26  9:49 ` [PATCH obexd 6/6] gobex: add root support to test-server Luiz Augusto von Dentz
2011-08-29 10:43 ` [PATCH obexd 1/6] gobex: fix not handling unkown transport type Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.