Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1376737pxy; Sun, 1 Aug 2021 23:14:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf/A621zFKC/2V2pKwUN/J9AmUQ6RT8OPK0+ImzIORNvrPvZMUCKKgTgfVFdiUWfSH1nai X-Received: by 2002:a05:6638:4115:: with SMTP id ay21mr13325782jab.13.1627884886054; Sun, 01 Aug 2021 23:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627884886; cv=none; d=google.com; s=arc-20160816; b=wzPrRBJy50zH9Emaq3+q3T7XnvmLKhv8phI7/KOxvlht8Rg6H0pEige01SkkeL8xnU Z7yJXexEMGsjfyrf70ayXWszZKsYSXGQmw7PezR5HMVnAh2K6azCmHqpYuvdPPcbMqxW 6Lu0CA5LUx+Yl/zw5CfchBTq358RdVKQ8UIC1nD0/Lv5XX1SMFKkxOhaOO7umVXAD7OO efD/HTZIgY92O5tVERU88SRPdqjjNdDXtdc8stwtQltHmQJo2i4J5QgA+wnAu6oCo/uF 88SM7LSYtFLJFWpo0J2Oc48ysBXLVP0pkQDQwPDsiMd98ZEeeFbzIRVEEGo1vmcGMLpv D17g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=F7VJqV3BeiJu665vbWvjgil8eUCIQvMKzwljw5TIy8g=; b=X+PCMrEUNA3N4wkcYN3vbkk2mti6vc+A2fm9cO3jHJURbPfU21Y++YiMJ/uYAcLK+s 8bV7nzNVLZjOi7ojPPYuO5FLmyZ85fmyTFng8NNQLGVWgtCAwKArWo3Ah3Jd1UUiexm3 pLuSfpmQBz6gz6PsGxD6qJWnVdYJyvbYq7hVnc5nP+eR610pfHboXFOwg+vX1vhpCVVQ 1JnDyrmwHV6mIgqX1SHAqzgbPOBIcQIW9Qc82jT6z0xL7+FwsknnUUa3RS7/CtPF3OMM KsXSo+/8dOE+FVhpaSwGC6r0d+eTnLvI4LicKP3ljFCJiCKtt5HhHrMXooIErFf3oQqT dgEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uGc82zsX; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si12223326jad.82.2021.08.01.23.14.14; Sun, 01 Aug 2021 23:14:46 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=uGc82zsX; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232063AbhHBGNS (ORCPT + 99 others); Mon, 2 Aug 2021 02:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbhHBGNQ (ORCPT ); Mon, 2 Aug 2021 02:13:16 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34BDC06175F for ; Sun, 1 Aug 2021 23:13:07 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id x12-20020a05620a14acb02903b8f9d28c19so12177399qkj.23 for ; Sun, 01 Aug 2021 23:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=F7VJqV3BeiJu665vbWvjgil8eUCIQvMKzwljw5TIy8g=; b=uGc82zsXPPEEKkj+VR67JZA6I3HM8MGm5bjV+ebmcIMTypGWrLqZdXWB6u97RqFki2 7+X1UFWriyRMZaQLbdZdQ161HyvrqcjM5T01n1xj6USfuSYceyaJR7FrxewzcyE3RZSt IzIHvXqAAq30QAzE6z0ERFKwuQlLf5F6DZ3KocMfhyZ0OGQODa+i8LhtHg0zZGEc1lfg ecBj3I+yNgpTi4E9vLabMLcvKaVxoFnjEmncZRL4I18zu9DH9+MQEaYilSZmBXqT7MQq hUe4V4NndavjwRSg7JTnU4sa0Y+S+B/1L83c7eh1FHENZbr4CP+1jxlNEWB1R7uO4U3x gfUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=F7VJqV3BeiJu665vbWvjgil8eUCIQvMKzwljw5TIy8g=; b=dmu5UBPLJK6a8gAeOdqcom1KO639YlFjw6UZLJcOnXvRo/l+JWlLIuBRDwnGtnitI1 X60ty4oO0ca+c20/qa+z96IhXRPG7GotdOqRbXhnWkF8/u8YaFVKN8AfarftWDeJjJIX SX5vKxJDqWYH15QmXbTBehJfK0Cv7y9XIWFc43wr8glL9J8uSqtqO+cOVZ8jBbDbL4os 9TaX9H3SnYbmrt9+YQJCPPBZk/b4NhD8Sw8A2y6yqs+uF8xf6ozFzXkvXYZP/f+weSyd KrFDiIPVkspE7shm5+n/6bLHo+oq8c/bWqjZoPImdr83rSAk9QQ6JTTQF1Rpe/FGVIQ6 QgEg== X-Gm-Message-State: AOAM530s72W83c9EyqY9/STF3p68462SjTG9rPqpeUnU7fyFW8b95pRp Xx/ilMzA1VZbTi3oaT1vJGLaPPTZ/5jEAoGhopPe10Boa+tfWSf5TM1UzUut0FKpUW7hS/qC6Hs yY8713Z2QTcl2rpNhrhSQv9EXrfOz399frVne+MtcWy7TfZCx0uEWpVsxcDFb9RDw7g/r1XdXK4 eCL0s8rsiU+tg= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:9f82:5515:89:f2cb]) (user=howardchung job=sendgmr) by 2002:a05:6214:dce:: with SMTP id 14mr9060709qvt.34.1627884786950; Sun, 01 Aug 2021 23:13:06 -0700 (PDT) Date: Mon, 2 Aug 2021 14:12:40 +0800 In-Reply-To: <20210802061250.170975-1-howardchung@google.com> Message-Id: <20210802141140.Bluez.v7.3.If0cf6e1feb9e9cc8106793bcaea60202852d7095@changeid> Mime-Version: 1.0 References: <20210802061250.170975-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v7 03/13] mcap: add adapter authorization From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Yun-Hao Chung Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung Currently mcap is the only profile that doesn't request adatper authorization. This patch adds a argument when creating the mcap instance to set authorize method. The reason why we don't use btd_request_authorization directly like all other profiles is because tools/mcaptest includes the profile/health/mcap.h. If we add dependency to adapter.h in mcap.h, it will make mcaptest depend on adapter and be not able to build independently. --- (no changes since v1) android/health.c | 2 +- profiles/health/hdp.c | 1 + profiles/health/mcap.c | 38 ++++++++++++++++++++++++++++++++++++-- profiles/health/mcap.h | 9 +++++++++ tools/mcaptest.c | 2 +- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/android/health.c b/android/health.c index 9a29964b1be2..de50db98e988 100644 --- a/android/health.c +++ b/android/health.c @@ -2008,7 +2008,7 @@ bool bt_health_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) mcl_connected, mcl_reconnected, mcl_disconnected, mcl_uncached, NULL, /* CSP is not used right now */ - NULL, &err); + NULL, NULL, &err); if (!mcap) { error("health: MCAP instance creation failed %s", err->message); g_error_free(err); diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c index 6bc41946fef3..efa8955efaea 100644 --- a/profiles/health/hdp.c +++ b/profiles/health/hdp.c @@ -1347,6 +1347,7 @@ static gboolean update_adapter(struct hdp_adapter *hdp_adapter) mcl_connected, mcl_reconnected, mcl_disconnected, mcl_uncached, NULL, /* CSP is not used by now */ + btd_request_authorization, hdp_adapter, &err); if (hdp_adapter->mi == NULL) { error("Error creating the MCAP instance: %s", err->message); diff --git a/profiles/health/mcap.c b/profiles/health/mcap.c index be13af37a0b8..a7eaba51693a 100644 --- a/profiles/health/mcap.c +++ b/profiles/health/mcap.c @@ -14,6 +14,7 @@ #endif #define _GNU_SOURCE +#include #include #include #include @@ -23,6 +24,7 @@ #include #include "lib/bluetooth.h" +#include "lib/uuid.h" #include "bluetooth/l2cap.h" #include "btio/btio.h" #include "src/log.h" @@ -1980,7 +1982,6 @@ static void set_mcl_conf(GIOChannel *chan, struct mcap_mcl *mcl) mcl->state = MCL_CONNECTED; mcl->role = MCL_ACCEPTOR; mcl->req = MCL_AVAILABLE; - mcl->cc = g_io_channel_ref(chan); mcl->ctrl |= MCAP_CTRL_STD_OP; mcap_sync_init(mcl); @@ -2005,19 +2006,38 @@ static void set_mcl_conf(GIOChannel *chan, struct mcap_mcl *mcl) mcl->mi->mcl_connected_cb(mcl, mcl->mi->user_data); } +static void auth_callback(DBusError *derr, void *user_data) +{ + struct mcap_mcl *mcl = user_data; + + if (derr) { + error("Access denied: %s", derr->message); + goto reject; + } + + set_mcl_conf(mcl->cc, mcl); + return; + +reject: + g_io_channel_shutdown(mcl->cc, TRUE, NULL); + g_io_channel_unref(mcl->cc); +} + static void connect_mcl_event_cb(GIOChannel *chan, GError *gerr, gpointer user_data) { struct mcap_instance *mi = user_data; struct mcap_mcl *mcl; - bdaddr_t dst; + bdaddr_t src, dst; char address[18], srcstr[18]; GError *err = NULL; + guint ret; if (gerr) return; bt_io_get(chan, &err, + BT_IO_OPT_SOURCE_BDADDR, &src, BT_IO_OPT_DEST_BDADDR, &dst, BT_IO_OPT_DEST, address, BT_IO_OPT_INVALID); @@ -2044,6 +2064,18 @@ static void connect_mcl_event_cb(GIOChannel *chan, GError *gerr, mcl->next_mdl = (rand() % MCAP_MDLID_FINAL) + 1; } + mcl->cc = g_io_channel_ref(chan); + if (mi->authorize_cb) { + ret = mi->authorize_cb(&src, &dst, HDP_UUID, auth_callback, + mcl); + if (ret != 0) + return; + + error("HDP: authorization for device %s failed", address); + g_io_channel_unref(mcl->cc); + goto drop; + } + set_mcl_conf(chan, mcl); return; @@ -2060,6 +2092,7 @@ struct mcap_instance *mcap_create_instance(const bdaddr_t *src, mcap_mcl_event_cb mcl_disconnected, mcap_mcl_event_cb mcl_uncached, mcap_info_ind_event_cb mcl_sync_info_ind, + mcap_authorize_cb authorize_cb, gpointer user_data, GError **gerr) { @@ -2089,6 +2122,7 @@ struct mcap_instance *mcap_create_instance(const bdaddr_t *src, mi->mcl_disconnected_cb = mcl_disconnected; mi->mcl_uncached_cb = mcl_uncached; mi->mcl_sync_infoind_cb = mcl_sync_info_ind; + mi->authorize_cb = authorize_cb; mi->user_data = user_data; mi->csp_enabled = FALSE; diff --git a/profiles/health/mcap.h b/profiles/health/mcap.h index 5a94c8b63bea..48b7d7846c57 100644 --- a/profiles/health/mcap.h +++ b/profiles/health/mcap.h @@ -9,6 +9,8 @@ * */ +#include + #define MCAP_VERSION 0x0100 /* current version 01.00 */ /* bytes to get MCAP Supported Procedures */ @@ -249,6 +251,11 @@ typedef void (* mcap_sync_set_cb) (struct mcap_mcl *mcl, GError *err, gpointer data); +typedef void mcap_auth_cb(DBusError *derr, void *user_data); +typedef guint (* mcap_authorize_cb) (const bdaddr_t *src, const bdaddr_t *dst, + const char *uuid, mcap_auth_cb cb, + void *user_data); + struct mcap_mdl_cb { mcap_mdl_event_cb mdl_connected; /* Remote device has created a MDL */ mcap_mdl_event_cb mdl_closed; /* Remote device has closed a MDL */ @@ -271,6 +278,7 @@ struct mcap_instance { mcap_mcl_event_cb mcl_disconnected_cb; /* MCL disconnected */ mcap_mcl_event_cb mcl_uncached_cb; /* MCL has been removed from MCAP cache */ mcap_info_ind_event_cb mcl_sync_infoind_cb; /* (CSP Master) Received info indication */ + mcap_authorize_cb authorize_cb; /* Method to request authorization */ gpointer user_data; /* Data to be provided in callbacks */ int ref; /* Reference counter */ @@ -404,6 +412,7 @@ struct mcap_instance *mcap_create_instance(const bdaddr_t *src, mcap_mcl_event_cb mcl_disconnected, mcap_mcl_event_cb mcl_uncached, mcap_info_ind_event_cb mcl_sync_info_ind, + mcap_authorize_cb authorize_cb, gpointer user_data, GError **gerr); void mcap_release_instance(struct mcap_instance *mi); diff --git a/tools/mcaptest.c b/tools/mcaptest.c index dcef0b908ac8..63ee22149a40 100644 --- a/tools/mcaptest.c +++ b/tools/mcaptest.c @@ -434,7 +434,7 @@ int main(int argc, char *argv[]) mcl_connected, mcl_reconnected, mcl_disconnected, mcl_uncached, NULL, /* CSP is not used right now */ - NULL, &err); + NULL, NULL, &err); if (!mcap) { printf("MCAP instance creation failed %s\n", err->message); -- 2.32.0.554.ge1b32706d8-goog