From patchwork Thu Oct 26 09:30:25 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: 10027909 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 6B83F6032C for ; Thu, 26 Oct 2017 09:30:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6023B28D80 for ; Thu, 26 Oct 2017 09:30:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5486C28D8C; Thu, 26 Oct 2017 09:30:48 +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 57DC228D8D for ; Thu, 26 Oct 2017 09:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752043AbdJZJak (ORCPT ); Thu, 26 Oct 2017 05:30:40 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:52362 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751961AbdJZJag (ORCPT ); Thu, 26 Oct 2017 05:30:36 -0400 Received: by mail-lf0-f65.google.com with SMTP id b190so2967385lfg.9; Thu, 26 Oct 2017 02:30:35 -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=qBJf7CvmZvX8SCEiqQZEmn7QzcQmPFB6aK1DuIXte5LHQc4Wq7ro1JsQDuq4usUIDs 0g5H+IJvDjC2AmsVQZGeZkKLroTXio1GCnU0xHQ8uLl2SHzugu9nGJtiJk+Lro5KeQ2F MGX8+R5InA2cANVGP2SkG+O3mGPNy+V3cfW8Huntnd2NNnk0f1QrhrSZ6dITfMohgjKr +R9s9/kPiCTMvFrWpLkGyuOfEcdVROOHC/+LlYS474y/NneKHlaFxfZ8JxB14hS+lM3F u6Laa+p7+W3gghv5ONzp8Acnafe3MeDAXrgrSVHkmp+aolqGIOQn/G+KHrqRx4On6tuR Tb2w== 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=rr3s6+pnX2Nuuhi9CmPAOuYWKVXS2RHoKNZl4/+0pVur/d/J0+Zj/iWtWHgxzE4xFv Ww/eprd5pmMZdlPUhgOpAIgmhLkaBXDqPZIfLtcV570PCtRpPArlhpD0wm6rEl5BMl1n 00rauIIVEFKLA5i/97B2yCKBbC50D7vyfGCTBx4kTtQrnd2cG1upbx6QDdwcXGulK+lX unrTu7PNapifcETa8ggn+3t1/YRB/hLhH//4VaB7xx/xgBd2zsSf2N3KnGM6W36ZcRK6 Jbmn9AEYLYegxDYUEAuxGwygZP69i9KmTGqgBOS+PCimiMqF0N8LAnSbLTSbP5O//v5a Yt/w== X-Gm-Message-State: AMCzsaVqlt5X9bFWZ9jBymRSTXLAFpXqUstI1/4wr715M89PKA03/EdR 7ZfmrlHfwTpPE2XTaMUdpbmWxSiz X-Google-Smtp-Source: ABhQp+QsFc4map110YhfqDyTAqQz9F6wtBeph0WNzRutNo52/opyF4Ty814qX4kTAMXgRyjS+nzo6w== X-Received: by 10.25.16.42 with SMTP id f42mr7664006lfi.172.1509010234484; Thu, 26 Oct 2017 02:30:34 -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 p28sm1322691lje.13.2017.10.26.02.30.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Oct 2017 02:30:33 -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: [PATCH v2 6/7] ipsp: Connect to IPSP PSM Date: Thu, 26 Oct 2017 12:30:25 +0300 Message-Id: <20171026093026.27952-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171026093026.27952-1-luiz.dentz@gmail.com> References: <20171026093026.27952-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;