From patchwork Fri Oct 20 10:22:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 10019479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5571B602CB for ; Fri, 20 Oct 2017 10:22:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45A57285F1 for ; Fri, 20 Oct 2017 10:22:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A99528EE0; Fri, 20 Oct 2017 10:22:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEF89285F1 for ; Fri, 20 Oct 2017 10:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752936AbdJTKWs (ORCPT ); Fri, 20 Oct 2017 06:22:48 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:48665 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752874AbdJTKWr (ORCPT ); Fri, 20 Oct 2017 06:22:47 -0400 Received: by mail-lf0-f68.google.com with SMTP id a69so12663245lfe.5; Fri, 20 Oct 2017 03:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jz8YDlAZ7g9Rz5uWYjEQbJKYea1PfJ1YmrM7RKaPuOc=; b=FIWUSA5h4Uwkx463GXyi0p/4t71sZS9XzTEo2W5NwOrf+7v8cpv71IJcIwlxTKm3tW kPU5+D3OKxhjcRJg8BNyIc60gV7bew6U/5egRrD0L8jpd4JrjD3HVXz1PLB0NmzY6C+J N1v+WTlZwdKgCHI5relGgWw58SaXJFskjhQiknmCGV2oRS2yws1i6kbOXA1jWNm+Yw2M SSmQlbNpqXHhpBUP+iqxp9uU5RHx2uXG/aZ9KwKuonumD73tltM8pN46uxvfqZ72Uig4 bQ5tvSx5xJ+/MaUGSrp7KLVKpcytdyI1qCPljigEgZrrcSZOKg4+0d+ew2whFJVEPNRJ BR6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Jz8YDlAZ7g9Rz5uWYjEQbJKYea1PfJ1YmrM7RKaPuOc=; b=N4o2WQPkH9cP1ahGgyN7GFlSpPFKyIARa548b4xFgoL5Sr8YQ70b3QyBy9uHolgn36 7JWmapOXzkU/JtMLB+Rl9HdbTWIrI7OBeHEoSQjLuXAMXochd4zHhbviAlTtNKsWARwM VlGyYb6i/oJoVzBp8IX9cpYWSHAn9KGHSZ/f8F5E78XG3gmHZIU4xyvB1wKn90mxQRQg iVd7Lbkz7xRe6Q8O1/TKVdJ1teT1reeXJH1MRjN9hWmEV3EN403BWm/VuvXX/LLM8VjO gH6QGXfg10FAUkeYlOJ6eNpmhSIre2cQDkTIEn9q4ZZhLoXR61nrrnwUyAETiSWhs5fd q2ZA== X-Gm-Message-State: AMCzsaVx90Rr+ACiLjcMNEAqgGrBGaUPEbbYk7OLYBA/ZYk8MxYTDT1L VVF9OnuSeS55G0jbW4TA4NnCEt5B X-Google-Smtp-Source: ABhQp+TIxJ9U22twg01n9WyJNyBuTxvNiEXcre8ZN1Arng/9+ArRtinVsS7n0Cix9jXkIYyYDR2BeQ== X-Received: by 10.25.145.80 with SMTP id y16mr1623665lfj.102.1508494965396; Fri, 20 Oct 2017 03:22:45 -0700 (PDT) Received: from vudentzs-t460s.pp.htv.fi (89-27-7-11.bb.dnainternet.fi. [89.27.7.11]) by smtp.gmail.com with ESMTPSA id z71sm168510lje.26.2017.10.20.03.22.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 03:22:44 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Cc: patrik.flykt@linux.intel.com, linux-wpan@vger.kernel.org Subject: [RFC 6/7] ipsp: Connect to IPSP PSM Date: Fri, 20 Oct 2017 13:22:35 +0300 Message-Id: <20171020102236.17499-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020102236.17499-1-luiz.dentz@gmail.com> References: <20171020102236.17499-1-luiz.dentz@gmail.com> Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Luiz Augusto von Dentz In case the remote device has IPSP service connect attempt to the IPSP L2CAP PSM. --- profiles/network/ipsp.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/profiles/network/ipsp.c b/profiles/network/ipsp.c index 2645b0598..28683f4b6 100644 --- a/profiles/network/ipsp.c +++ b/profiles/network/ipsp.c @@ -34,6 +34,7 @@ #include "lib/sdp.h" #include "lib/uuid.h" +#include "btio/btio.h" #include "src/shared/util.h" #include "src/shared/att.h" #include "src/shared/queue.h" @@ -47,6 +48,28 @@ #include "src/log.h" #define IPSP_UUID16 0x1820 +#define IPSP_PSM 0x0023 +#define IPSP_MTU 1280 + +struct ipsp_session { + GIOChannel *io; + unsigned int id; +}; + +static void ipsp_cleanup(struct btd_service *service) +{ + struct ipsp_session *session = btd_service_get_user_data(service); + + if (!session) + return; + + btd_service_set_user_data(service, NULL); + + if (session->id > 0) + g_source_remove(session->id); + + g_io_channel_unref(session->io); +} static int ipsp_probe(struct btd_service *service) { @@ -64,6 +87,49 @@ static void ipsp_remove(struct btd_service *service) const char *path = device_get_path(device); DBG("path %s", path); + + ipsp_cleanup(service); +} + +static gboolean ipsp_session(GIOChannel *chan, GIOCondition cond, + gpointer data) +{ + struct btd_service *service = data; + + if (cond & G_IO_NVAL) + return FALSE; + + if (cond & (G_IO_HUP | G_IO_ERR)) { + DBG("IPSP session disconnected"); + ipsp_cleanup(service); + return FALSE; + } + + return TRUE; +} + +static void ipsp_connect(GIOChannel *io, GError *err, gpointer user_data) +{ + struct btd_service *service = user_data; + struct ipsp_session *session = btd_service_get_user_data(service); + + if (err) { + DBG("%s", err->message); + + ipsp_cleanup(service); + + btd_service_connecting_complete(service, -EIO); + return; + } + + session->id = g_io_add_watch(io, + G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, + (GIOFunc) ipsp_session, service); + + g_io_channel_unref(session->io); + session->io = NULL; + + btd_service_connecting_complete(service, 0); } static void foreach_ipsp_service(struct gatt_db_attribute *attr, @@ -77,12 +143,13 @@ static void foreach_ipsp_service(struct gatt_db_attribute *attr, static int ipsp_accept(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); + struct btd_adapter *adapter = device_get_adapter(device); struct gatt_db *db = btd_device_get_gatt_db(device); - const char *path = device_get_path(device); bool found = false; bt_uuid_t ipsp_uuid; + struct ipsp_session *session; - DBG("path %s", path); + DBG("path %s", device_get_path(device)); /* Handle the IPSP services */ bt_uuid16_create(&ipsp_uuid, IPSP_UUID16); @@ -92,7 +159,33 @@ static int ipsp_accept(struct btd_service *service) return -EINVAL; } - btd_service_connecting_complete(service, 0); + session = g_new0(struct ipsp_session, 1); + if (!session) { + error("Unable to allocate IPSP session"); + return -ENOMEM; + } + + /* Connect L2CAP channel */ + session->io = bt_io_connect(ipsp_connect, service, NULL, NULL, + BT_IO_OPT_SOURCE_BDADDR, + btd_adapter_get_address(adapter), + BT_IO_OPT_SOURCE_TYPE, + btd_adapter_get_address_type(adapter), + BT_IO_OPT_DEST_BDADDR, + device_get_address(device), + BT_IO_OPT_DEST_TYPE, + btd_device_get_bdaddr_type(device), + BT_IO_OPT_PSM, IPSP_PSM, + BT_IO_OPT_IMTU, IPSP_MTU, + BT_IO_OPT_INVALID); + if (!session->io) { + error("Unable create IPSP connection"); + g_free(session); + return -EIO; + } + + /* Attach session to the service */ + btd_service_set_user_data(service, session); return 0; } @@ -104,6 +197,8 @@ static int ipsp_disconnect(struct btd_service *service) DBG("path %s", path); + ipsp_cleanup(service); + btd_service_disconnecting_complete(service, 0); return 0;