Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1821207pxb; Fri, 6 Nov 2020 23:09:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYu3fRckNzrqGLuQ/czJfFz1QSmR8MKcyOz4uxYyXBzOfXtUKWbVcd0bH6TbzHeT3GEz91 X-Received: by 2002:aa7:c44d:: with SMTP id n13mr6044863edr.138.1604732940951; Fri, 06 Nov 2020 23:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604732940; cv=none; d=google.com; s=arc-20160816; b=AmJF7YPHg5zb5TWUxCyJU83EKEMPiw3APYsmNe3iWuHDOoY5mMKGzzMbpxGey+8sbt EiQmsOSy54DMXtMsStOAxwv8WGsfHTQjWHr3P/e+qmpGJnVzyXJWQJWXSeNanyuh/0/Z HuymWpSc/7GOXa3NevLdrUb46apHmYCLU8C5fLAxtZo9sQecLEord3IHfErj8Qqg+s1G pZPRWoUvCXjffs4pUjapEr0Y6SZqmzOLLpnJX7Wm8bRB4mFYLf141KosioQC+2uDLFIx BrZBOyzmcGIREUSlrZFhEtYLAyxJ0+yUu7MkgVA1JEWPJDSvznsOZuhcJQfkRjT05l8V /aWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=+q88F2O6PkLdRUj/vAZC6aFVgh7di/sUipqRDnXaT7Y=; b=G6BPdVbQp3Ec14FnxgNpLxCUbkgIF9M+ykt1GP8L/RRZc6CVIXo3D5F4iUzbmt0HGB KdZky/rLlfycuMsaJ/V8fnH5ONi7Um1FBWmwf5RlUHKbCxaxRgvn+3QkjRfQu51OQEMI E4IKAmlICyebbkxrRFq12kdbUvr4bd9jdPAlapAvQmCnbhVrWwwg4LpmAJbsIAN7Thcl UsI53MAgFjkWiyegS9s6ZnhgO5lclKJYpAySvxO7c0Clk0yUqEeRQLn5cLPJPNCyNbK1 pn0zafSSSYzOc6LxVp5lrwn7oYw7MdnzMwNfW2MPmhXjc8MkB7EgTjFiktPzX9O/+ZEl 82OA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn11si2579900ejc.638.2020.11.06.23.08.36; Fri, 06 Nov 2020 23:09:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727830AbgKGHDe (ORCPT + 99 others); Sat, 7 Nov 2020 02:03:34 -0500 Received: from mga17.intel.com ([192.55.52.151]:45630 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727824AbgKGHDe (ORCPT ); Sat, 7 Nov 2020 02:03:34 -0500 IronPort-SDR: urSmjum1t11zBYO6G8DDxlA/T0m63eQL3XFgrhGHb49NGu393dayJ8eIx60P+ldzrdrna8fkU9 cE5YmeAaU49Q== X-IronPort-AV: E=McAfee;i="6000,8403,9797"; a="149485521" X-IronPort-AV: E=Sophos;i="5.77,458,1596524400"; d="scan'208";a="149485521" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2020 23:03:34 -0800 IronPort-SDR: hLDyrWlfXEYFE5gd6ksV2Etb/m7RwOjRWG8O8o6iCuloA6JEEjS7B6GlaY3c2wYn0Ob/kEF0qF DMTVwRy58aNA== X-IronPort-AV: E=Sophos;i="5.77,458,1596524400"; d="scan'208";a="359032059" Received: from ralassax-mobl.amr.corp.intel.com (HELO ingas-nuc1.intel.com) ([10.209.101.141]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2020 23:03:33 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: luiz.von.dentz@intel.com, Inga Stotland Subject: [RFC PATCH BlueZ 10/10] tools/rfcomm-tester: Convert to use ELL library Date: Fri, 6 Nov 2020 23:03:12 -0800 Message-Id: <20201107070312.8561-11-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201107070312.8561-1-inga.stotland@intel.com> References: <20201107070312.8561-1-inga.stotland@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This reworks the source code to use ELL primitives and removes dependecies on GLib. --- Makefile.tools | 4 +- tools/rfcomm-tester.c | 92 ++++++++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index e65547c3f..2f86c839c 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -122,12 +122,12 @@ tools_l2cap_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-ell.la $(ell_ldadd) tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c monitor/bt.h \ - emulator/hciemu.h emulator/hciemu.c \ + emulator/hciemu.h emulator/hciemu-ell.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_rfcomm_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-ell.la $(ell_ldadd) tools_bnep_tester_SOURCES = tools/bnep-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu-ell.c \ diff --git a/tools/rfcomm-tester.c b/tools/rfcomm-tester.c index 9bae5b9d5..516dd3f82 100644 --- a/tools/rfcomm-tester.c +++ b/tools/rfcomm-tester.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include "lib/bluetooth.h" #include "lib/rfcomm.h" @@ -35,9 +35,9 @@ struct test_data { struct mgmt *mgmt; uint16_t mgmt_index; struct hciemu *hciemu; + struct l_io *io; enum hciemu_type hciemu_type; const void *test_data; - unsigned int io_id; uint16_t conn_handle; }; @@ -192,9 +192,9 @@ static void test_post_teardown(const void *test_data) { struct test_data *data = tester_get_data(); - if (data->io_id > 0) { - g_source_remove(data->io_id); - data->io_id = 0; + if (data->io) { + l_io_destroy(data->io); + data->io = NULL; } hciemu_unref(data->hciemu); @@ -395,8 +395,7 @@ static int connect_rfcomm_sock(int sk, const bdaddr_t *bdaddr, uint8_t channel) return 0; } -static gboolean client_received_data(GIOChannel *io, GIOCondition cond, - gpointer user_data) +static bool client_received_data(struct l_io *io, void *user_data) { struct test_data *data = tester_get_data(); const struct rfcomm_client_data *cli = data->test_data; @@ -404,7 +403,7 @@ static gboolean client_received_data(GIOChannel *io, GIOCondition cond, ssize_t ret; char buf[248]; - sk = g_io_channel_unix_get_fd(io); + sk = l_io_get_fd(io); ret = read(sk, buf, cli->data_len); if (cli->data_len != ret) { @@ -420,19 +419,38 @@ static gboolean client_received_data(GIOChannel *io, GIOCondition cond, return false; } -static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond, - gpointer user_data) +static void rc_disconnect_cb(struct l_io *io, void *user_data) { struct test_data *data = tester_get_data(); const struct rfcomm_client_data *cli = data->test_data; socklen_t len = sizeof(int); int sk, err, sk_err; - tester_print("Connected"); + tester_print("Disconnected"); + + sk = l_io_get_fd(io); + + if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0) + err = -errno; + else + err = -sk_err; + + if (cli->expected_connect_err && err == cli->expected_connect_err) + tester_test_passed(); + else + tester_test_failed(); +} - data->io_id = 0; +static bool rc_connect_cb(struct l_io *io, void *user_data) +{ + struct test_data *data = tester_get_data(); + const struct rfcomm_client_data *cli = data->test_data; + socklen_t len = sizeof(int); + int sk, err, sk_err; + + tester_print("Connected"); - sk = g_io_channel_unix_get_fd(io); + sk = l_io_get_fd(io); if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0) err = -errno; @@ -458,7 +476,7 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond, return false; } else if (cli->read_data) { - g_io_add_watch(io, G_IO_IN, client_received_data, NULL); + l_io_set_read_handler(io, client_received_data, NULL, NULL); bthost_send_rfcomm_data(hciemu_client_get_host(data->hciemu), data->conn_handle, cli->client_channel, @@ -535,7 +553,6 @@ static void test_connect(const void *test_data) struct bthost *bthost = hciemu_client_get_host(data->hciemu); const struct rfcomm_client_data *cli = data->test_data; const uint8_t *client_addr, *master_addr; - GIOChannel *io; int sk; bthost_add_l2cap_server(bthost, 0x0003, NULL, NULL, NULL); @@ -554,18 +571,19 @@ static void test_connect(const void *test_data) return; } - io = g_io_channel_unix_new(sk); - g_io_channel_set_close_on_unref(io, TRUE); - - data->io_id = g_io_add_watch(io, G_IO_OUT, rc_connect_cb, NULL); + data->io = l_io_new(sk); + l_io_set_close_on_destroy(data->io, true); + l_io_set_disconnect_handler(data->io, rc_disconnect_cb, NULL, NULL); - g_io_channel_unref(io); + if (!l_io_set_write_handler(data->io, rc_connect_cb, NULL, NULL)) { + tester_test_failed(); + return; + } tester_print("Connect in progress %d", sk); } -static gboolean server_received_data(GIOChannel *io, GIOCondition cond, - gpointer user_data) +static bool server_received_data(struct l_io *io, void *user_data) { struct test_data *data = tester_get_data(); const struct rfcomm_server_data *srv = data->test_data; @@ -573,7 +591,7 @@ static gboolean server_received_data(GIOChannel *io, GIOCondition cond, ssize_t ret; int sk; - sk = g_io_channel_unix_get_fd(io); + sk = l_io_get_fd(io); ret = read(sk, buf, srv->data_len); if (ret != srv->data_len) { @@ -589,16 +607,14 @@ static gboolean server_received_data(GIOChannel *io, GIOCondition cond, return false; } -static gboolean rfcomm_listen_cb(GIOChannel *io, GIOCondition cond, - gpointer user_data) +static bool rfcomm_listen_cb(struct l_io *io, void *user_data) { struct test_data *data = tester_get_data(); const struct rfcomm_server_data *srv = data->test_data; int sk, new_sk; - data->io_id = 0; - sk = g_io_channel_unix_get_fd(io); + sk = l_io_get_fd(io); new_sk = accept(sk, NULL, NULL); if (new_sk < 0) { @@ -616,15 +632,12 @@ static gboolean rfcomm_listen_cb(GIOChannel *io, GIOCondition cond, close(new_sk); return false; } else if (srv->read_data) { - GIOChannel *new_io; - - new_io = g_io_channel_unix_new(new_sk); - g_io_channel_set_close_on_unref(new_io, TRUE); + struct l_io *new_io; - data->io_id = g_io_add_watch(new_io, G_IO_IN, - server_received_data, NULL); + new_io = l_io_new(new_sk); + l_io_set_close_on_destroy(new_io, true); + l_io_set_read_handler(new_io, server_received_data, NULL, NULL); - g_io_channel_unref(new_io); return false; } @@ -677,7 +690,6 @@ static void test_server(const void *test_data) const struct rfcomm_server_data *srv = data->test_data; const uint8_t *master_addr; struct bthost *bthost; - GIOChannel *io; int sk; master_addr = hciemu_get_master_bdaddr(data->hciemu); @@ -696,11 +708,10 @@ static void test_server(const void *test_data) return; } - io = g_io_channel_unix_new(sk); - g_io_channel_set_close_on_unref(io, TRUE); + data->io = l_io_new(sk); + l_io_set_close_on_destroy(data->io, true); - data->io_id = g_io_add_watch(io, G_IO_IN, rfcomm_listen_cb, NULL); - g_io_channel_unref(io); + l_io_set_read_handler(data->io, rfcomm_listen_cb, NULL, NULL); tester_print("Listening for connections"); @@ -713,12 +724,11 @@ static void test_server(const void *test_data) #define test_rfcomm(name, data, setup, func) \ do { \ struct test_data *user; \ - user = malloc(sizeof(struct test_data)); \ + user = l_new(struct test_data, 1); \ if (!user) \ break; \ user->hciemu_type = HCIEMU_TYPE_BREDR; \ user->test_data = data; \ - user->io_id = 0; \ tester_add_full(name, data, \ test_pre_setup, setup, func, NULL, \ test_post_teardown, 2, user, test_data_free); \ -- 2.26.2