Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp595219pxk; Fri, 11 Sep 2020 15:31:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymxG0U9MbWPlHOJiXXLz6xWGtlFZdjBoDbvmY9SqK0m8a+uh+yfM1vEMwcaA5b7ghDXMSP X-Received: by 2002:a17:906:914b:: with SMTP id y11mr4159553ejw.145.1599863500596; Fri, 11 Sep 2020 15:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599863500; cv=none; d=google.com; s=arc-20160816; b=JO1ZC5fi4d/OC4Zh/ZhfoDwTyF9zqhkdDqU1sh1gwjeJRx8S05JaOwFcVCjcMRPltd qTjiiq8TkBbI0YvTo9Ufxl2ktdCf+xSqW4dftzMBuFAnqLVUt7NG/mJE6nHsRRGWGUtf 55cnIyUFcyMvulq2m/uPSbUXGYJsKtwp57qnwgJkRSTra0I/vJPyXZyjVmMC11w7WHjy toCnk5GCWlYf4Tr8yp826EIfPQ+d9ObOSvByg47u6XxSr/CESuJaxw3TlIRiQUb38AbD EoKKR+v3QWSufke+J+SNbStP9HAwLv+p9UJNGIaYLGWDpyb0mF6+QZf0wfFscnwTyE0A FXdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WaLvyDrpSOjFqABkikbrubyIQ9gGcpKW8XM7vdEOdKA=; b=ULMoimhX9Lec0yfoRjj9dZiwgmojnb8ESd0wLIA+6P4RewZ8wv02TPd5CypA3UbUAI dmKRPfd1LTexAxdCcp0L6hLS80TCmt31v6xsaG5iu8x1q9TitSModPHbVnhb/+9Q9QCq E/PDp4jRlaNnYS1CcbR9WhI0wyMNzzbqngpt17YDIhtug2O326x8e0e3K8IBceygIzBt LZLo4PwKz/rCEKK6jOnp26TEnJeU2LUpj1EfiRpZrFv5Qq3qr5LjS1fToplsAVQRBsTt BkKgJXFG/OcjX/EaDcVLj8rRZ/LXTbRr6B/U7eK8yiuwOfKrhtWfe28qR8FSwayC8vAP Dbxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ybrt8GDp; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id re18si2090481ejb.684.2020.09.11.15.30.59; Fri, 11 Sep 2020 15:31:40 -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=@chromium.org header.s=google header.b=Ybrt8GDp; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725835AbgIKWax (ORCPT + 99 others); Fri, 11 Sep 2020 18:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725855AbgIKWas (ORCPT ); Fri, 11 Sep 2020 18:30:48 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30CD5C061757 for ; Fri, 11 Sep 2020 15:30:47 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id m5so7537842pgj.9 for ; Fri, 11 Sep 2020 15:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WaLvyDrpSOjFqABkikbrubyIQ9gGcpKW8XM7vdEOdKA=; b=Ybrt8GDp4U0Ref+E7puBcHWfPDeqZwmnDzBVdD7Dl8dM4XCcdjemh+UcuyJ+GCBIeN VvfI56mOhtYfsip2ICar2nX41HBqhyjAy9YYZq+KHS0C20b3RjnHBK4UgqDYPE3UujpY zOthAQCPCBOpf8Okk9WkZ3HNUFV7O4GpwwJJ4= 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:mime-version:content-transfer-encoding; bh=WaLvyDrpSOjFqABkikbrubyIQ9gGcpKW8XM7vdEOdKA=; b=P3yRDpl/rs8FCF2QGvlolt6ePE/WaS4rCGQgBRD+u3VlsDAm8qpRn7+fso3q+fi66n wEx31A3sVadKOOW8QkYizpuExMIV54ey8ArKnZ+i1OY/N8jKIlJX65GxZfnsbNL7/qd9 XQ0fctpzdJ8AL8YkojXxR04EOBkZznebJIzjgxDeRkjNv9MlykVFkYI/l7LEDVV2BAXE PE8M3POc2C0SQX3UnBP8bhYB3hKn2hpDaQaCId1UxuBs2OZfc8faKL6cAcquHM1lWqGA JSWZePQnaDlxid6gw3svVcdy6KSJ4Iw49dJ+cvld3TxU+Rg89D+4ipgXZUEpqfit95IU iW1w== X-Gm-Message-State: AOAM5323O8noDa3r8+9ds9KpQccgRjTLh4LgHYPZ6v363YE5+JPo5ZfQ r4zPThhs/GY33Fetv50N5uzHxA== X-Received: by 2002:a63:464c:: with SMTP id v12mr3182389pgk.130.1599863446753; Fri, 11 Sep 2020 15:30:46 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id m14sm3123742pfo.202.2020.09.11.15.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 15:30:46 -0700 (PDT) From: Abhishek Pandit-Subedi To: luiz.dentz@gmail.com, marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Abhishek Pandit-Subedi Subject: [Bluez PATCH v4 2/4] adapter: Handle controller resume and notify drivers Date: Fri, 11 Sep 2020 15:30:35 -0700 Message-Id: <20200911153010.Bluez.v4.2.Ic6aa9c03323b5ef0265e5b5b36986af05d9ecd26@changeid> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200911223037.4127188-1-abhishekpandit@chromium.org> References: <20200911223037.4127188-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Register for controller resume notification and notify the adapter drivers when it occurs. Also adds the resume event kernel feature to make sure the kernel supports this event. --- Changes in v4: None Changes in v3: None Changes in v2: None src/adapter.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/adapter.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index e700a78d5..d77d83d11 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -8771,6 +8771,33 @@ static void connected_callback(uint16_t index, uint16_t length, eir_data_free(&eir_data); } +static void controller_resume_notify(struct btd_adapter *adapter) +{ + GSList *l; + + for (l = adapter->drivers; l; l = g_slist_next(l)) { + struct btd_adapter_driver *driver = l->data; + if (driver->resume) + driver->resume(adapter); + } +} + +static void controller_resume_callback(uint16_t index, uint16_t length, + const void *param, void *user_data) +{ + const struct mgmt_ev_controller_resume *ev = param; + struct btd_adapter *adapter = user_data; + + if (length < sizeof(*ev)) { + btd_error(adapter->dev_id, "Too small device resume event"); + return; + } + + info("Controller resume with wake event 0x%x", ev->wake_reason); + + controller_resume_notify(adapter); +} + static void device_blocked_callback(uint16_t index, uint16_t length, const void *param, void *user_data) { @@ -9394,6 +9421,11 @@ static void read_info_complete(uint8_t status, uint16_t length, user_passkey_notify_callback, adapter, NULL); + mgmt_register(adapter->mgmt, MGMT_EV_CONTROLLER_RESUME, + adapter->dev_id, + controller_resume_callback, + adapter, NULL); + set_dev_class(adapter); set_name(adapter, btd_adapter_get_name(adapter)); @@ -9604,6 +9636,17 @@ static void read_commands_complete(uint8_t status, uint16_t length, break; } } + + for (i = 0; i < num_events; i++) { + uint16_t ev = get_le16(rp->opcodes + num_commands + i); + + switch(ev) { + case MGMT_EV_CONTROLLER_RESUME: + DBG("kernel supports suspend/resume events"); + kernel_features |= KERNEL_HAS_RESUME_EVT; + break; + } + } } static void read_version_complete(uint8_t status, uint16_t length, diff --git a/src/adapter.h b/src/adapter.h index b0ed4915f..fae2e9d3d 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -113,6 +113,7 @@ struct btd_adapter_driver { const char *name; int (*probe) (struct btd_adapter *adapter); void (*remove) (struct btd_adapter *adapter); + void (*resume) (struct btd_adapter *adapter); }; typedef void (*service_auth_cb) (DBusError *derr, void *user_data); @@ -239,6 +240,7 @@ enum kernel_features { KERNEL_BLOCKED_KEYS_SUPPORTED = 1 << 1, KERNEL_SET_SYSTEM_CONFIG = 1 << 2, KERNEL_EXP_FEATURES = 1 << 3, + KERNEL_HAS_RESUME_EVT = 1 << 4, }; bool has_kernel_features(uint32_t feature); -- 2.28.0.618.gf4bc123cb7-goog