2010-08-18 10:35:55

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 0/5] Fast connectable mode for HFP (update)

Hi,

The following patches are implementation of fast connectable mode for HFP.
Such mode means significantly shorter page scan interval and interlaced
page scan type. As a result, HFP connection typically is created much faster.
The fast connectable mode can be activated by incomming call indicator and
deactivated by answer or reject call indicator. Such speeds up connectability
of a headset when there is an incomming call. Retransmisions in eSCO are
possiblle to be paused for in-band ring tone when the mode is enabled during
given above period of time. eSCO is not affected during call since page scan
settings are returned to their default values immidiately after call is
accepted (or rejected).

Use of the mode can be enabled by changing FastConnectable in audio.conf
configuration file. It is disabled by default. Also, it doesn't affect and
doesn't change any other interfaces.

Br,
Dmitriy




2010-08-18 11:15:16

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 0/5] Fast connectable mode for HFP (update)

Hi Dmitry,

On Wed, Aug 18, 2010, Dmitriy Paliy wrote:
> The following patches are implementation of fast connectable mode for HFP.
> Such mode means significantly shorter page scan interval and interlaced
> page scan type. As a result, HFP connection typically is created much faster.
> The fast connectable mode can be activated by incomming call indicator and
> deactivated by answer or reject call indicator. Such speeds up connectability
> of a headset when there is an incomming call. Retransmisions in eSCO are
> possiblle to be paused for in-band ring tone when the mode is enabled during
> given above period of time. eSCO is not affected during call since page scan
> settings are returned to their default values immidiately after call is
> accepted (or rejected).
>
> Use of the mode can be enabled by changing FastConnectable in audio.conf
> configuration file. It is disabled by default. Also, it doesn't affect and
> doesn't change any other interfaces.

Thanks for the patches. They've all been pushed upstream.

One thing that still needs discussing/consideration is the safeguard for
setting the correct mode if bluetoothd crashed while we were in the fast
connectable mode. Right now your patches take care of this in the audio
plugin but in the future if other users of this new core daemon API come
up the proper intialization should (imho) be inside the core daemon. We
already do this for things like periodic inquiry where bluetoothd always
sends the HCI_Exit_Periodic_Inquiry_Mode command when it starts up (in
case bluetoothd previously crashed while discovering devices).

Johan

2010-08-18 10:35:59

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 4/5] Add set fast connectable to audio manager

Set fast connectable added to audio manager interface. Enables
fast connectable mode for all audio adapters or sets respective
values to default when disabled. It does not interfere with any
other audio manager's interfaces, modes, or states.
---
audio/manager.c | 14 ++++++++++++++
audio/manager.h | 4 ++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/audio/manager.c b/audio/manager.c
index 6dd0f87..3db5987 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -1290,3 +1290,17 @@ gboolean manager_allow_headset_connection(struct audio_device *device)

return TRUE;
}
+
+void manager_set_fast_connectable(gboolean enable)
+{
+ GSList *l;
+
+ for (l = adapters; l != NULL; l = l->next) {
+ struct audio_adapter *adapter = l->data;
+
+ if (btd_adapter_set_fast_connectable(adapter->btd_adapter,
+ enable))
+ error("Changing fast connectable for hci%d failed",
+ adapter_get_dev_id(adapter->btd_adapter));
+ }
+}
diff --git a/audio/manager.h b/audio/manager.h
index 8e1abf4..90fe6f0 100644
--- a/audio/manager.h
+++ b/audio/manager.h
@@ -48,3 +48,7 @@ struct audio_device *manager_get_device(const bdaddr_t *src,
gboolean create);

gboolean manager_allow_headset_connection(struct audio_device *device);
+
+/* TRUE to enable fast connectable and FALSE to disable fast connectable for all
+ * audio adapters. */
+void manager_set_fast_connectable(gboolean enable);
--
1.7.0.4


2010-08-18 10:35:58

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 3/5] Add set fast connectable to adapter

Set fast connectable added to adapter interface. Enables or disables
faster page scanning. It does not interfere with any other adapter's
interfaces.
---
src/adapter.c | 12 ++++++++++++
src/adapter.h | 6 ++++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 4ad4165..b023c01 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3454,3 +3454,15 @@ void btd_adapter_unregister_powered_callback(struct btd_adapter *adapter,
adapter->powered_callbacks =
g_slist_remove(adapter->powered_callbacks, cb);
}
+
+int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,
+ gboolean enable)
+{
+ if (!adapter_ops)
+ return -EINVAL;
+
+ if (!adapter->up)
+ return -EINVAL;
+
+ return adapter_ops->set_fast_connectable(adapter->dev_id, enable);
+}
diff --git a/src/adapter.h b/src/adapter.h
index 657e035..5352731 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -196,3 +196,9 @@ void btd_adapter_register_powered_callback(struct btd_adapter *adapter,
btd_adapter_powered_cb cb);
void btd_adapter_unregister_powered_callback(struct btd_adapter *adapter,
btd_adapter_powered_cb cb);
+
+/* If TRUE, enables fast connectabe, i.e. reduces page scan interval and changes
+ * type. If FALSE, disables fast connectable, i.e. sets page scan interval and
+ * type to default values. Valid for both connectable and discoverable modes. */
+int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,
+ gboolean enable);
--
1.7.0.4


2010-08-18 10:36:00

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 5/5] Add fast connectable support to HFP

Audio.conf is updated to support fast connectable mode. Set
FastConnectable to true to enable and to false to disable. Headset
initialization and call indicators are updated respectively. It is
disabled by default.
---
audio/audio.conf | 7 +++++++
audio/headset.c | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/audio/audio.conf b/audio/audio.conf
index a64fb66..302e046 100644
--- a/audio/audio.conf
+++ b/audio/audio.conf
@@ -32,6 +32,13 @@ HFP=true
# Maximum number of connected HSP/HFP devices per adapter. Defaults to 1
MaxConnected=1

+# Set to true to enable use of fast connectable mode (faster page scanning)
+# for HFP when incomming call starts. Default settings are restored after
+# call is answered or rejected. Page scan interval is much shorter and page
+# scan type changed to interlaced. Such allows faster connection initiated
+# by a headset.
+FastConnectable=false
+
# Just an example of potential config options for the other interfaces
#[A2DP]
#SBCSources=1
diff --git a/audio/headset.c b/audio/headset.c
index 99d4c7a..cdb3370 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -95,6 +95,7 @@ static struct {
};

static gboolean sco_hci = TRUE;
+static gboolean fast_connectable = FALSE;

static GSList *active_devices = NULL;

@@ -2262,6 +2263,19 @@ uint32_t headset_config_init(GKeyFile *config)
g_free(str);
}

+ /* Init fast connectable option */
+ str = g_key_file_get_string(config, "Headset", "FastConnectable",
+ &err);
+ if (err) {
+ DBG("audio.conf: %s", err->message);
+ g_clear_error(&err);
+ } else {
+ fast_connectable = strcmp(str, "true") == 0;
+ if (fast_connectable)
+ manager_set_fast_connectable(FALSE);
+ g_free(str);
+ }
+
return ag.features;
}

@@ -2743,6 +2757,9 @@ int telephony_incoming_call_ind(const char *number, int type)
struct headset *hs;
struct headset_slc *slc;

+ if (fast_connectable)
+ manager_set_fast_connectable(TRUE);
+
if (!active_devices)
return -ENODEV;

@@ -2782,6 +2799,9 @@ int telephony_calling_stopped_ind(void)
{
struct audio_device *dev;

+ if (fast_connectable)
+ manager_set_fast_connectable(FALSE);
+
if (ag.ring_timer) {
g_source_remove(ag.ring_timer);
ag.ring_timer = 0;
--
1.7.0.4


2010-08-18 10:35:56

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 1/5] Add STANDARD and INTERLACED page scan definitions

Added standard and interlaced page scan type definitions. Used for
both read and write page scan type HCI commands.
---
lib/hci.h | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/hci.h b/lib/hci.h
index f31918d..0369ee2 100644
--- a/lib/hci.h
+++ b/lib/hci.h
@@ -992,6 +992,8 @@ typedef struct {
#define OCF_READ_PAGE_SCAN_TYPE 0x0046

#define OCF_WRITE_PAGE_SCAN_TYPE 0x0047
+ #define PAGE_SCAN_TYPE_STANDARD 0x00
+ #define PAGE_SCAN_TYPE_INTERLACED 0x01

#define OCF_READ_AFH_MODE 0x0048
typedef struct {
--
1.7.0.4


2010-08-18 10:35:57

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 2/5] Add fast connectable to hciops

Fast connectable switches between two sets of parameters to enable
or disable fast page scan mode. Page scan interval and page scan
type are changed to speed up connectabily when needed. When
disabled it sets default values. List of btd_adapter_ops is updated
respectively.
---
plugins/hciops.c | 33 +++++++++++++++++++++++++++++++++
src/adapter.h | 1 +
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 9c97c5a..f1e9f69 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -716,6 +716,38 @@ static int hciops_cancel_resolve_name(int index, bdaddr_t *bdaddr)
return err;
}

+static int hciops_fast_connectable(int index, gboolean enable)
+{
+ int dd, err = 0;
+ write_page_activity_cp cp;
+ uint8_t type;
+
+ if (enable) {
+ type = PAGE_SCAN_TYPE_INTERLACED;
+ cp.interval = 0x0024; /* 22.5 msec page scan interval */
+ } else {
+ type = PAGE_SCAN_TYPE_STANDARD; /* default */
+ cp.interval = 0x0800; /* default 1.28 sec page scan */
+ }
+
+ cp.window = 0x0012; /* default 11.25 msec page scan window */
+
+ dd = hci_open_dev(index);
+ if (dd < 0)
+ return -EIO;
+
+ if (hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_ACTIVITY,
+ WRITE_PAGE_ACTIVITY_CP_SIZE, &cp) < 0)
+ err = -errno;
+ else if (hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_SCAN_TYPE,
+ 1, &type) < 0)
+ err = -errno;
+
+ hci_close_dev(dd);
+
+ return err;
+}
+
static struct btd_adapter_ops hci_ops = {
.setup = hciops_setup,
.cleanup = hciops_cleanup,
@@ -732,6 +764,7 @@ static struct btd_adapter_ops hci_ops = {
.set_name = hciops_set_name,
.read_name = hciops_read_name,
.set_class = hciops_set_class,
+ .set_fast_connectable = hciops_fast_connectable,
};

static int hciops_init(void)
diff --git a/src/adapter.h b/src/adapter.h
index 58853ac..657e035 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -183,6 +183,7 @@ struct btd_adapter_ops {
int (*set_name) (int index, const char *name);
int (*read_name) (int index);
int (*set_class) (int index, uint32_t class);
+ int (*set_fast_connectable) (int index, gboolean enable);
};

int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
--
1.7.0.4


2010-08-17 14:43:10

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 4/5] Add set fast connectable to audio manager

Hi Dmitriy,

On Tue, Aug 17, 2010, Dmitriy Paliy wrote:
> + if ( btd_adapter_set_fast_connectable(adapter->btd_adapter,
> + enable) )
> + error("Changing fast connectable for hci%d failed",
> + adapter_get_dev_id(adapter->btd_adapter) );
> + }

Same coding style issues I already mentioned for the other patch: no
braces for one-line if-statements and no space after ( or before ).

Johan

2010-08-17 14:41:32

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 2/5] Add fast connectable to hciops

Hi Dmitry,

On Tue, Aug 17, 2010, Dmitriy Paliy wrote:
> + if ( hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_ACTIVITY,
> + WRITE_PAGE_ACTIVITY_CP_SIZE, &cp) < 0 ) {
> + err = -errno;
> + } else if ( hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_SCAN_TYPE,
> + 1, &type) < 0 ) {
> + err = -errno;
> + }

A few coding style issues: no braces for one-line if-statements and
remove the spaces after ( and before ) should be removed.

Johan