Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC v4 00/12] LE auto connection and connection parameters
From: Andre Guedes @ 2013-12-06 22:05 UTC (permalink / raw)
  To: linux-bluetooth

Hi all,

This v4 is the same patch set from v3 but rebased on top of current
bluetooth-next tree.

Below follows v3 cover letter:

The main changes from the previous version are:
  * Debugfs interface to add auto connect address instead of new mgmt
    commands.
  * We always stop LE scanning in favor of connection establishment even if
    the controller supports scanning and connection at the same time.
  * Background scanning is now controlled in one single place (hci_update_
    background_scan function).
  * RCU was replaced by hdev->lock to protect hdev->le_conn_params list. After
    all the changes since the original version of this patch set, I realized
    we always operate on hdev->le_conn_params with hdev->lock held so there is
    no point in use RCU to protect this list.

In order to test the LE auto connection mechanism please follow the
instructions below.

To add a new auto connection address we write on le_auto_conn file following
the format <address> <address type> <auto_connect>.

The <address type> values are:
  * 0 for public address
  * 1 for random address

The <auto_connect> values are (for more details see struct hci_conn_params):
  * 0 for disabled
  * 1 for always
  * 2 for link loss

So for instance, if you want the kernel autonomously establishes connections
with device AA:BB:CC:DD:EE:FF (public address) every time the device enters in
connectable mode (starts advertising), you should run the command:
$ echo "AA:BB:CC:DD:EE:FF 0 1" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn

To get the list of connection parameters configured in kernel, read the
le_auto_conn file:
$ cat /sys/kernel/debug/bluetooth/hci0/le_auto_conn

Finally, to clear the connection parameters list, write an empty string:
$ echo "" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn

BR,

Andre


Andre Guedes (12):
  Bluetooth: Save connection interval parameters in hci_conn
  Bluetooth: Group list_head fields from strcut hci_dev together
  Bluetooth: Introduce connection parameters list
  Bluetooth: Use connection parameters if any
  Bluetooth: Stop scanning on LE connection
  Bluetooth: Introduce hdev->pend_le_conn list
  Bluetooth: Introduce LE auto connection infrastructure
  Bluetooth: Re-enable background scan in case of error
  Bluetooth: Temporarily stop background scanning on discovery
  Bluetooth: Auto connection and power on
  Bleutooth: Add support for auto connect options
  Bluetooth: Add le_auto_conn file on debugfs

 include/net/bluetooth/hci_core.h |  43 +++++-
 net/bluetooth/hci_conn.c         |  39 ++++-
 net/bluetooth/hci_core.c         | 318 +++++++++++++++++++++++++++++++++++++++
 net/bluetooth/hci_event.c        |  60 ++++++++
 net/bluetooth/mgmt.c             |  25 ++-
 5 files changed, 473 insertions(+), 12 deletions(-)

-- 
1.8.4.2


^ permalink raw reply

* Re: SM: is BlueZ the Master/Initiator or Slave/Responder?
From: Scott James Remnant @ 2013-12-06 19:47 UTC (permalink / raw)
  To: Vinicius Costa Gomes
  Cc: linux-bluetooth@vger.kernel.org, Holtmann, Marcel, Johan Hedberg,
	Brian Gix
In-Reply-To: <20131128165916.GA21429@molly.amr.corp.intel.com>

Great, sounds like I came to the right conclusion myself - after
reading the spec and examining the test case, we couldn't find a
reason to set this bit unless BlueZ can also behave as the Slave,
which is not only something we didn't expect it to do, but also not
something we had claimed in the PICS.

I filed a TSE with the SIG on 11/25 and it looks like they agree too,
and that this test should only be used when a IUT specifies that it
supports both the Master and Slave role, so looks like the TSE will be
approved along with the matching TCW.

Scott

On Thu, Nov 28, 2013 at 8:59 AM, Vinicius Costa Gomes <vcgomes@gmail.com> wrote:
> Hi Scott,
>
> On 13:17 Mon 25 Nov, Scott James Remnant wrote:
>> We are able to pass all qualification tests with BlueZ as the Master except one:
>>
>>   TP/KDU/BV-06-C - Master Key Distribution - Encryption Key bit
>>
>> This test requires that BlueZ initiates pairing with the
>> SMP_DIST_ENC_KEY bit set in the init_key_dist member of struct
>> smp_cmd_pairing - however this member is always initialized to zero
>> and never changed.
>
> This test is in theory correct, but it doesn't test anything that does make
> sense at this point. Let me try to explain, setting the Encryption Key bit in
> the initiator key distribution field in the Pairing Request means that the
> Initiator wants to send its Encryption Key to the Responder.
>
> This is only useful in cases that both devices expect the roles to be reversed
> in future connections (The Master of this connection would become the Slave in
> future connections). And IIRC we weren't able to test this role reversal and
> it even offends the current GAP spec for Dual mode devices.
>
>>
>> This seems to have changed at some point in the past, 2b64d153 added
>> MITM mechanism and changed the init_key_dist member initialization
>> from dist_keys to 0
>>
>>
>> So two questions:
>>
>>  1) should BlueZ be able to behave as Master? It passes the majority
>> of the tests except this one.
>
> BlueZ should be able to bahave as Master, if not, it is a bug.
>
>>
>>  2) given the above, is this a bug that init_key_dist is 0 or is it a
>> test plan error that it requires this?
>
> I think it is a bit of both, for the current situation the Master distributing
> its keys doesn't make much sense and we should be able to change this value to
> be able to test the key distribution parts.
>
> What I suggest is adding a debugfs entry to change the value of init_key_dist
> for Pairing Requests, and keep the default being 0.
>
> (disclaimer: I am follwing development from the sidelines for some time, so
> feel free to correct me.)
>
>>
>> Scott
>> --
>> Scott James Remnant | Chrome OS Systems | keybuk@google.com | Google
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
> Cheers,
> --
> Vinicius



-- 
Scott James Remnant | Chrome OS Systems | keybuk@google.com | Google

^ permalink raw reply

* Re: [PATCH RFC] tty_ldisc: add more limits to the @write_wakeup
From: Peter Hurley @ 2013-12-06 16:18 UTC (permalink / raw)
  To: Huang Shijie; +Cc: gregkh, linux-serial, marcel, linux-bluetooth
In-Reply-To: <52A1A84B.80409@freescale.com>

On 12/06/2013 05:34 AM, Huang Shijie wrote:
> 于 2013年11月13日 15:30, Huang Shijie 写道:
>> In the uart_handle_cts_change(), uart_write_wakeup() is called after
>> we call @uart_port->ops->start_tx().
>>
>> The Documentation/serial/driver tells us:
>> -----------------------------------------------
>>    start_tx(port)
>> 	Start transmitting characters.
>>
>> 	Locking: port->lock taken.
>> 	Interrupts: locally disabled.
>> -----------------------------------------------
>>
>> So when the uart_write_wakeup() is called, the port->lock is taken by
>> the upper. See the following callstack:
>>
>> 	|_ uart_write_wakeup
>> 	   |_ tty_wakeup
>> 	      |_ ld->ops->write_wakeup
>>
>> With the port->lock held, we call the @write_wakeup. Some implemetation of
>> the @write_wakeup does not notice that the port->lock is held, and it still
>> tries to send data with uart_write() which will try to grab the prot->lock.
>> A dead lock occurs, see the following log caught in the Bluetooth by uart:
>>
>> --------------------------------------------------------------------
>> BUG: spinlock lockup suspected on CPU#0, swapper/0/0
>>   lock: 0xdc3f4410, .magic: dead4ead, .owner: swapper/0/0, .owner_cpu: 0
>> CPU: 0 PID: 0 Comm: swapper/0 Tainted: G        W    3.10.17-16839-ge4a1bef #1320
>> [<80014cbc>] (unwind_backtrace+0x0/0x138) from [<8001251c>] (show_stack+0x10/0x14)
>> [<8001251c>] (show_stack+0x10/0x14) from [<802816ac>] (do_raw_spin_lock+0x108/0x184)
>> [<802816ac>] (do_raw_spin_lock+0x108/0x184) from [<806a22b0>] (_raw_spin_lock_irqsave+0x54/0x60)
>> [<806a22b0>] (_raw_spin_lock_irqsave+0x54/0x60) from [<802f5754>] (uart_write+0x38/0xe0)
>> [<802f5754>] (uart_write+0x38/0xe0) from [<80455270>] (hci_uart_tx_wakeup+0xa4/0x168)
>> [<80455270>] (hci_uart_tx_wakeup+0xa4/0x168) from [<802dab18>] (tty_wakeup+0x50/0x5c)
>> [<802dab18>] (tty_wakeup+0x50/0x5c) from [<802f81a4>] (imx_rtsint+0x50/0x80)
>> [<802f81a4>] (imx_rtsint+0x50/0x80) from [<802f88f4>] (imx_int+0x158/0x17c)
>> [<802f88f4>] (imx_int+0x158/0x17c) from [<8007abe0>] (handle_irq_event_percpu+0x50/0x194)
>> [<8007abe0>] (handle_irq_event_percpu+0x50/0x194) from [<8007ad60>] (handle_irq_event+0x3c/0x5c)
>> --------------------------------------------------------------------
>>
>> This patch adds more limits to the @write_wakeup, the one who wants to
>> implemet the @write_wakeup should follow the limits which avoid the deadlock.
>>
>> Signed-off-by: Huang Shijie <b32955@freescale.com>
>> ---
>>   include/linux/tty_ldisc.h |    5 ++++-
>>   1 files changed, 4 insertions(+), 1 deletions(-)
>>
>> diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
>> index f15c898..539ccc5 100644
>> --- a/include/linux/tty_ldisc.h
>> +++ b/include/linux/tty_ldisc.h
>> @@ -91,7 +91,10 @@
>>    *	This function is called by the low-level tty driver to signal
>>    *	that line discpline should try to send more characters to the
>>    *	low-level driver for transmission.  If the line discpline does
>> - *	not have any more data to send, it can just return.
>> + *	not have any more data to send, it can just return. If the line
>> + *	discipline does have some data to send, please arise a tasklet
>> + *	or workqueue to do the real data transfer. Do not send data in
>> + *	this hook, it may leads to a deadlock.
>>    *
>>    * int (*hangup)(struct tty_struct *)
>>    *
> just a ping.
>
> In actually, this is a BUG in the tty code or BT code.

hci_uart_tx_wakeup() should perform the actual tx in a work item.

Regards,
Peter Hurley

^ permalink raw reply

* [PATCHv2] android: Fix delayed adapter turn off
From: Jakub Tyszkowski @ 2013-12-06 15:30 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>

We shouldn't care about pending actions being completed as we want to
turn BT off. This fixes Android UI controlls being locked when BT off
action waits in queue for to long.

---
 android/bluetooth.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 6174b1f..e5d8b7a 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1290,17 +1290,24 @@ static void set_mode_complete(uint8_t status, uint16_t length,
 	new_settings_callback(adapter.index, length, param, NULL);
 }
 
-static bool set_mode(uint16_t opcode, uint8_t mode)
+static bool set_mode(uint16_t opcode, uint8_t mode, bool unqueued)
 {
 	struct mgmt_mode cp;
+	unsigned int mgmt_result;
 
 	memset(&cp, 0, sizeof(cp));
 	cp.val = mode;
 
 	DBG("opcode=0x%x mode=0x%x", opcode, mode);
 
-	if (mgmt_send(mgmt_if, opcode, adapter.index, sizeof(cp), &cp,
-					set_mode_complete, NULL, NULL) > 0)
+	if (unqueued)
+		mgmt_result = mgmt_reply(mgmt_if, opcode, adapter.index,
+				sizeof(cp), &cp, set_mode_complete, NULL, NULL);
+	else
+		mgmt_result = mgmt_send(mgmt_if, opcode, adapter.index,
+				sizeof(cp), &cp, set_mode_complete, NULL, NULL);
+
+	if (mgmt_result > 0)
 		return true;
 
 	error("Failed to set mode");
@@ -1462,10 +1469,10 @@ static void read_info_complete(uint8_t status, uint16_t length,
 	missing_settings = adapter.current_settings ^ supported_settings;
 
 	if (missing_settings & MGMT_SETTING_SSP)
-		set_mode(MGMT_OP_SET_SSP, 0x01);
+		set_mode(MGMT_OP_SET_SSP, 0x01, false);
 
 	if (missing_settings & MGMT_SETTING_PAIRABLE)
-		set_mode(MGMT_OP_SET_PAIRABLE, 0x01);
+		set_mode(MGMT_OP_SET_PAIRABLE, 0x01, false);
 
 	return;
 
@@ -1926,7 +1933,8 @@ static uint8_t set_scan_mode(const void *buf, uint16_t len)
 	}
 
 	if (cur_conn != conn) {
-		if (!set_mode(MGMT_OP_SET_CONNECTABLE, conn ? 0x01 : 0x00))
+		if (!set_mode(MGMT_OP_SET_CONNECTABLE, conn ? 0x01 : 0x00,
+									false))
 			return HAL_STATUS_FAILED;
 	}
 
@@ -2234,7 +2242,7 @@ static void handle_enable_cmd(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	if (!set_mode(MGMT_OP_SET_POWERED, 0x01)) {
+	if (!set_mode(MGMT_OP_SET_POWERED, 0x01, false)) {
 		status = HAL_STATUS_FAILED;
 		goto failed;
 	}
@@ -2253,7 +2261,11 @@ static void handle_disable_cmd(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
+	/*
+	 * Prioritize BT turn off as not doing it in time makes Android
+	 * unstable and locks Bluetooth UI controlls.
+	 */
+	if (!set_mode(MGMT_OP_SET_POWERED, 0x00, true)) {
 		status = HAL_STATUS_FAILED;
 		goto failed;
 	}
-- 
1.8.5


^ permalink raw reply related

* Re: [PATCH RFC] tty_ldisc: add more limits to the @write_wakeup
From: Huang Shijie @ 2013-12-06 10:34 UTC (permalink / raw)
  To: Huang Shijie; +Cc: gregkh, linux-serial, marcel, linux-bluetooth
In-Reply-To: <1384327803-5925-1-git-send-email-b32955@freescale.com>

=D3=DA 2013=C4=EA11=D4=C213=C8=D5 15:30, Huang Shijie =D0=B4=B5=C0:
> In the uart_handle_cts_change(), uart_write_wakeup() is called after
> we call @uart_port->ops->start_tx().
>
> The Documentation/serial/driver tells us:
> -----------------------------------------------
>   start_tx(port)
> 	Start transmitting characters.
>
> 	Locking: port->lock taken.
> 	Interrupts: locally disabled.
> -----------------------------------------------
>
> So when the uart_write_wakeup() is called, the port->lock is taken by
> the upper. See the following callstack:
>
> 	|_ uart_write_wakeup
> 	   |_ tty_wakeup
> 	      |_ ld->ops->write_wakeup
>
> With the port->lock held, we call the @write_wakeup. Some implemetation=
 of
> the @write_wakeup does not notice that the port->lock is held, and it s=
till
> tries to send data with uart_write() which will try to grab the prot->l=
ock.
> A dead lock occurs, see the following log caught in the Bluetooth by ua=
rt:
>
> --------------------------------------------------------------------
> BUG: spinlock lockup suspected on CPU#0, swapper/0/0
>  lock: 0xdc3f4410, .magic: dead4ead, .owner: swapper/0/0, .owner_cpu: 0
> CPU: 0 PID: 0 Comm: swapper/0 Tainted: G        W    3.10.17-16839-ge4a=
1bef #1320
> [<80014cbc>] (unwind_backtrace+0x0/0x138) from [<8001251c>] (show_stack=
+0x10/0x14)
> [<8001251c>] (show_stack+0x10/0x14) from [<802816ac>] (do_raw_spin_lock=
+0x108/0x184)
> [<802816ac>] (do_raw_spin_lock+0x108/0x184) from [<806a22b0>] (_raw_spi=
n_lock_irqsave+0x54/0x60)
> [<806a22b0>] (_raw_spin_lock_irqsave+0x54/0x60) from [<802f5754>] (uart=
_write+0x38/0xe0)
> [<802f5754>] (uart_write+0x38/0xe0) from [<80455270>] (hci_uart_tx_wake=
up+0xa4/0x168)
> [<80455270>] (hci_uart_tx_wakeup+0xa4/0x168) from [<802dab18>] (tty_wak=
eup+0x50/0x5c)
> [<802dab18>] (tty_wakeup+0x50/0x5c) from [<802f81a4>] (imx_rtsint+0x50/=
0x80)
> [<802f81a4>] (imx_rtsint+0x50/0x80) from [<802f88f4>] (imx_int+0x158/0x=
17c)
> [<802f88f4>] (imx_int+0x158/0x17c) from [<8007abe0>] (handle_irq_event_=
percpu+0x50/0x194)
> [<8007abe0>] (handle_irq_event_percpu+0x50/0x194) from [<8007ad60>] (ha=
ndle_irq_event+0x3c/0x5c)
> --------------------------------------------------------------------
>
> This patch adds more limits to the @write_wakeup, the one who wants to
> implemet the @write_wakeup should follow the limits which avoid the dea=
dlock.
>
> Signed-off-by: Huang Shijie <b32955@freescale.com>
> ---
>  include/linux/tty_ldisc.h |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
> index f15c898..539ccc5 100644
> --- a/include/linux/tty_ldisc.h
> +++ b/include/linux/tty_ldisc.h
> @@ -91,7 +91,10 @@
>   *	This function is called by the low-level tty driver to signal
>   *	that line discpline should try to send more characters to the
>   *	low-level driver for transmission.  If the line discpline does
> - *	not have any more data to send, it can just return.
> + *	not have any more data to send, it can just return. If the line
> + *	discipline does have some data to send, please arise a tasklet
> + *	or workqueue to do the real data transfer. Do not send data in
> + *	this hook, it may leads to a deadlock.
>   *
>   * int (*hangup)(struct tty_struct *)
>   *
just a ping.

In actually, this is a BUG in the tty code or BT code.

thanks
Huang Shijie

^ permalink raw reply

* Re: [PATCH v2 1/2] Bluetooth: Use min_t for calculating chan->imtu
From: Johan Hedberg @ 2013-12-06  5:55 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1386306533-32239-1-git-send-email-johan.hedberg@gmail.com>

Hi,

On Fri, Dec 06, 2013, johan.hedberg@gmail.com wrote:
> Since there's a nice convenient helper for calculating the minimum of
> two values, let's use that one.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  net/bluetooth/l2cap_core.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)

Too early in the morning for me - sending a v3 with a proper subject
(with mps instead of imtu in it).

Johan

^ permalink raw reply

* [PATCH v3 2/2] Bluetooth: Fix valid LE PSM check
From: johan.hedberg @ 2013-12-06  5:54 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1386309293-4708-1-git-send-email-johan.hedberg@gmail.com>

From: Johan Hedberg <johan.hedberg@intel.com>

The range of valid LE PSMs is 0x0001-0x00ff so the check should be for
"less than or equal to" instead of "less than".

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 35feb9d6c322..ae0054ccee5b 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1851,7 +1851,7 @@ static bool is_valid_psm(u16 psm, u8 dst_type)
 		return false;
 
 	if (bdaddr_type_is_le(dst_type))
-		return (psm < 0x00ff);
+		return (psm <= 0x00ff);
 
 	/* PSM must be odd and lsb of upper byte must be 0 */
 	return ((psm & 0x0101) == 0x0001);
-- 
1.8.4.2


^ permalink raw reply related

* [PATCH v3 1/2] Bluetooth: Use min_t for calculating chan->mps
From: johan.hedberg @ 2013-12-06  5:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

Since there's a nice convenient helper for calculating the minimum of
two values, let's use that one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6e6f308af036..35feb9d6c322 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -505,11 +505,7 @@ static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
 	chan->sdu_len = 0;
 	chan->tx_credits = 0;
 	chan->rx_credits = le_max_credits;
-
-	if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
-		chan->mps = chan->imtu;
-	else
-		chan->mps = L2CAP_LE_DEFAULT_MPS;
+	chan->mps = min_t(u16, chan->imtu, L2CAP_LE_DEFAULT_MPS);
 
 	skb_queue_head_init(&chan->tx_q);
 }
-- 
1.8.4.2


^ permalink raw reply related

* [PATCH v3 1/2] Bluetooth: Use min_t for calculating chan->mps
From: johan.hedberg @ 2013-12-06  5:53 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

Since there's a nice convenient helper for calculating the minimum of
two values, let's use that one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6e6f308af036..35feb9d6c322 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -505,11 +505,7 @@ static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
 	chan->sdu_len = 0;
 	chan->tx_credits = 0;
 	chan->rx_credits = le_max_credits;
-
-	if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
-		chan->mps = chan->imtu;
-	else
-		chan->mps = L2CAP_LE_DEFAULT_MPS;
+	chan->mps = min_t(u16, chan->imtu, L2CAP_LE_DEFAULT_MPS);
 
 	skb_queue_head_init(&chan->tx_q);
 }
-- 
1.8.4.2


^ permalink raw reply related

* Re: [PATCH v2 2/2] Bluetooth: Fix valid LE PSM check
From: Marcel Holtmann @ 2013-12-06  5:52 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1386306533-32239-2-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

> The range of valid LE PSMs is 0x0001-0x00ff so the check should be for
> "less than or equal to" instead of "less than".
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply

* Re: [PATCH v2 1/2] Bluetooth: Use min_t for calculating chan->imtu
From: Marcel Holtmann @ 2013-12-06  5:51 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1386306533-32239-1-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

> Since there's a nice convenient helper for calculating the minimum of
> two values, let's use that one.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply

* [PATCH v2 2/2] Bluetooth: Fix valid LE PSM check
From: johan.hedberg @ 2013-12-06  5:08 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1386306533-32239-1-git-send-email-johan.hedberg@gmail.com>

From: Johan Hedberg <johan.hedberg@intel.com>

The range of valid LE PSMs is 0x0001-0x00ff so the check should be for
"less than or equal to" instead of "less than".

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 35feb9d6c322..ae0054ccee5b 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1851,7 +1851,7 @@ static bool is_valid_psm(u16 psm, u8 dst_type)
 		return false;
 
 	if (bdaddr_type_is_le(dst_type))
-		return (psm < 0x00ff);
+		return (psm <= 0x00ff);
 
 	/* PSM must be odd and lsb of upper byte must be 0 */
 	return ((psm & 0x0101) == 0x0001);
-- 
1.8.4.2


^ permalink raw reply related

* [PATCH v2 1/2] Bluetooth: Use min_t for calculating chan->imtu
From: johan.hedberg @ 2013-12-06  5:08 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

Since there's a nice convenient helper for calculating the minimum of
two values, let's use that one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6e6f308af036..35feb9d6c322 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -505,11 +505,7 @@ static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
 	chan->sdu_len = 0;
 	chan->tx_credits = 0;
 	chan->rx_credits = le_max_credits;
-
-	if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
-		chan->mps = chan->imtu;
-	else
-		chan->mps = L2CAP_LE_DEFAULT_MPS;
+	chan->mps = min_t(u16, chan->imtu, L2CAP_LE_DEFAULT_MPS);
 
 	skb_queue_head_init(&chan->tx_q);
 }
-- 
1.8.4.2


^ permalink raw reply related

* Re: [PATCH 1/2] Bluetooth: Use min_t for calculating chan->imtu
From: Johan Hedberg @ 2013-12-06  5:07 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1386306115-30686-1-git-send-email-johan.hedberg@gmail.com>

Hi,

On Fri, Dec 06, 2013, johan.hedberg@gmail.com wrote:
> Since there's a nice convenient helper for calculating the minimum of
> two values, let's use that one.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  net/bluetooth/l2cap_core.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 6e6f308af036..8f42cae96dc3 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -505,11 +505,7 @@ static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
>  	chan->sdu_len = 0;
>  	chan->tx_credits = 0;
>  	chan->rx_credits = le_max_credits;
> -
> -	if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
> -		chan->mps = chan->imtu;
> -	else
> -		chan->mps = L2CAP_LE_DEFAULT_MPS;
> +	chan->imtu = min_t(u16, chan->imtu, L2CAP_LE_DEFAULT_MPS);

Ignore this one. It should obviously be assigning to chan->mps and not
chan->imtu.

Johan

^ permalink raw reply

* Re: [PATCH v2 30/32] Bluetooth: Fix validating LE PSM values
From: Johan Hedberg @ 2013-12-06  5:05 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: BlueZ development
In-Reply-To: <CAJdJm_Pvc97a8i3vcO4NO0sDJFzUyJ3JOkGuwOyYL8Bi8RjE5A@mail.gmail.com>

Hi Lizardo,

On Thu, Dec 05, 2013, Anderson Lizardo wrote:
> On Thu, Dec 5, 2013 at 9:11 AM,  <johan.hedberg@gmail.com> wrote:
> > +static bool is_valid_psm(u16 psm, u8 dst_type)
> > +{
> > +       if (!psm)
> > +               return false;
> > +
> > +       if (bdaddr_type_is_le(dst_type))
> > +               return (psm < 0x00ff);
> 
> Shouldn't be "psm <= 0x00ff" here?

Yes, it should. I just sent two fix-up patches based on your feedback.
Thanks.

Johan

^ permalink raw reply

* [PATCH 2/2] Bluetooth: Fix valid LE PSM check
From: johan.hedberg @ 2013-12-06  5:01 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1386306115-30686-1-git-send-email-johan.hedberg@gmail.com>

From: Johan Hedberg <johan.hedberg@intel.com>

The range of valid LE PSMs is 0x0001-0x00ff so the check should be for
"less than or equal to" instead of "less than".

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 8f42cae96dc3..23c57b4cdbcb 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1851,7 +1851,7 @@ static bool is_valid_psm(u16 psm, u8 dst_type)
 		return false;
 
 	if (bdaddr_type_is_le(dst_type))
-		return (psm < 0x00ff);
+		return (psm <= 0x00ff);
 
 	/* PSM must be odd and lsb of upper byte must be 0 */
 	return ((psm & 0x0101) == 0x0001);
-- 
1.8.4.2


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Use min_t for calculating chan->imtu
From: johan.hedberg @ 2013-12-06  5:01 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

Since there's a nice convenient helper for calculating the minimum of
two values, let's use that one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6e6f308af036..8f42cae96dc3 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -505,11 +505,7 @@ static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
 	chan->sdu_len = 0;
 	chan->tx_credits = 0;
 	chan->rx_credits = le_max_credits;
-
-	if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
-		chan->mps = chan->imtu;
-	else
-		chan->mps = L2CAP_LE_DEFAULT_MPS;
+	chan->imtu = min_t(u16, chan->imtu, L2CAP_LE_DEFAULT_MPS);
 
 	skb_queue_head_init(&chan->tx_q);
 }
-- 
1.8.4.2


^ permalink raw reply related

* Re: [RFC v3 00/12] LE auto connection and connection parameters
From: Marcel Holtmann @ 2013-12-06  4:40 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CACJA=fWLf7wAmgooAkmbH3e2R+AE9dbfutvbjTewkp+5bJkmeQ@mail.gmail.com>

Hi Andre,

> Ping.
> 
>> The main changes from the previous version are:
>>  * Debugfs interface to add auto connect address instead of new mgmt
>>    commands.
>>  * We always stop LE scanning in favor of connection establishment even if
>>    the controller supports scanning and connection at the same time.
>>  * Background scanning is now controlled in one single place (hci_update_
>>    background_scan function).
>>  * RCU was replaced by hdev->lock to protect hdev->le_conn_params list. After
>>    all the changes since the original version of this patch set, I realized
>>    we always operate on hdev->le_conn_params with hdev->lock held so there is
>>    no point in use RCU to protect this list.

can you send a re-based v4 against the latest bluetooth-next tree please.

Regards

Marcel


^ permalink raw reply

* Re: [PATCH v2 30/32] Bluetooth: Fix validating LE PSM values
From: Anderson Lizardo @ 2013-12-06  0:02 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: BlueZ development
In-Reply-To: <1386249090-10236-31-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

On Thu, Dec 5, 2013 at 9:11 AM,  <johan.hedberg@gmail.com> wrote:
> +static bool is_valid_psm(u16 psm, u8 dst_type)
> +{
> +       if (!psm)
> +               return false;
> +
> +       if (bdaddr_type_is_le(dst_type))
> +               return (psm < 0x00ff);

Shouldn't be "psm <= 0x00ff" here?

> +
> +       /* PSM must be odd and lsb of upper byte must be 0 */
> +       return ((psm & 0x0101) == 0x0001);
> +}
> +
>  int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
>                        bdaddr_t *dst, u8 dst_type)
>  {

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [PATCH v2 00/32] Bluetooth: LE CoC support
From: Marcel Holtmann @ 2013-12-05 15:06 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

> Here's v2 of the patches with all comments taken into account.
> Additionally I've fixed the permissions of the debugfs files, fixed the
> credits calculation for max_credits == 1, and added a cleanup patch at
> the end of the set for simplifying l2cap_chan initialization for LE CoC.
> 
> I've also updated user space l2test now to support the new BT_SNDMTU and
> BT_RCVMTU socket options, i.e. the LE CoC functionality can now be
> tested using upstream l2test.
> 
> Johan
> 
> ----------------------------------------------------------------
> Johan Hedberg (32):
>      Bluetooth: Remove unnecessary braces from one-line if-statement
>      Bluetooth: Add module parameter to enable LE CoC support
>      Bluetooth: Update l2cap_global_chan_by_psm() to take a link type
>      Bluetooth: Allow l2cap_chan_check_security() to be used for LE links.
>      Bluetooth: Pass command length to LE signaling channel handlers
>      Bluetooth: Move LE L2CAP initiator procedure to its own function
>      Bluetooth: Add definitions for LE connection oriented channels
>      Bluetooth: Add initial code for LE L2CAP Connect Request
>      Bluetooth: Add smp_sufficient_security helper function
>      Bluetooth: Refactor L2CAP connect rejection to its own function
>      Bluetooth: Add basic LE L2CAP connect request receiving support
>      Bluetooth: Fix L2CAP channel closing for LE connections
>      Bluetooth: Add L2CAP Disconnect suppport for LE
>      Bluetooth: Make l2cap_le_sig_cmd logic consistent
>      Bluetooth: Add LE L2CAP flow control mode
>      Bluetooth: Track LE L2CAP credits in l2cap_chan
>      Bluetooth: Limit L2CAP_OPTIONS socket option usage with LE
>      Bluetooth: Add new BT_SNDMTU and BT_RCVMTU socket options
>      Bluetooth: Implement returning of LE L2CAP credits
>      Bluetooth: Add LE flow control discipline
>      Bluetooth: Reject LE CoC commands when the feature is not enabled
>      Bluetooth: Introduce L2CAP channel callback for suspending
>      Bluetooth: Add LE L2CAP segmentation support for outgoing data
>      Bluetooth: Implement LE L2CAP reassembly
>      Bluetooth: Fix LE L2CAP Connect Request handling together with SMP
>      Bluetooth: Fix suspending the L2CAP socket if we start with 0 credits
>      Bluetooth: Limit LE MPS to the MTU value
>      Bluetooth: Fix clearing of chan->omtu for LE CoC channels
>      Bluetooth: Fix CID ranges for LE CoC CID allocations
>      Bluetooth: Fix validating LE PSM values
>      Bluetooth: Add debugfs controls for LE CoC MPS and Credits
>      Bluetooth: Simplify l2cap_chan initialization for LE CoC
> 
> include/net/bluetooth/bluetooth.h |   3 +
> include/net/bluetooth/l2cap.h     |  45 +++
> net/bluetooth/l2cap_core.c        | 720 ++++++++++++++++++++++++++++++++++---
> net/bluetooth/l2cap_sock.c        | 157 +++++++-
> net/bluetooth/smp.c               |  16 +-
> net/bluetooth/smp.h               |   1 +
> 6 files changed, 873 insertions(+), 69 deletions(-)

all patches (including minor fixups) have been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply

* Re: [PATCH v2 1/6] android: Add android-tester
From: Luiz Augusto von Dentz @ 2013-12-05 15:00 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth@vger.kernel.org, Marcin Kraglak
In-Reply-To: <1385631770-3858-2-git-send-email-grzegorz.kolodziejczyk@tieto.com>

Hi Grzegorz,

On Thu, Nov 28, 2013 at 11:42 AM, Grzegorz Kolodziejczyk
<grzegorz.kolodziejczyk@tieto.com> wrote:
> From: Marcin Kraglak <marcin.kraglak@tieto.com>
>
> This commit add android-tester.c to tree and Makefile.am.
> This will contain set of unit tests for testing android daemon.
> ---
>  android/Makefile.am      |  4 ++++
>  android/android-tester.c | 21 +++++++++++++++++++++
>  2 files changed, 25 insertions(+)
>  create mode 100644 android/android-tester.c
>
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 94d231f..9390422 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -82,6 +82,10 @@ android_haltest_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android \
>
>  android_haltest_LDFLAGS = -pthread
>
> +noinst_PROGRAMS += android/android-tester
> +
> +android_android_tester_SOURCES = android/android-tester.c
> +
>  endif

You should probably add it to .gitignore as well. Also is this suppose
to be run in the host only or do we want to run in Android as well?

-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCHv2 1/4] android/socket: Cleanup sockets on unregister
From: Luiz Augusto von Dentz @ 2013-12-05 14:51 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1386085873-21715-2-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Tue, Dec 3, 2013 at 5:51 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> This cleans up rfsock structures closing all sockets and making general cleanup
> for servers and for connections. This will be called form socket unregister.
> ---
>  android/socket.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/android/socket.c b/android/socket.c
> index c9eca44..9020874 100644
> --- a/android/socket.c
> +++ b/android/socket.c
> @@ -93,8 +93,10 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
>         return rfsock;
>  }
>
> -static void cleanup_rfsock(struct rfcomm_sock *rfsock)
> +static void cleanup_rfsock(gpointer data)
>  {
> +       struct rfcomm_sock *rfsock = data;
> +
>         DBG("rfsock: %p fd %d real_sock %d chan %u",
>                 rfsock, rfsock->fd, rfsock->real_sock, rfsock->channel);
>
> @@ -936,5 +938,8 @@ void bt_socket_unregister(void)
>  {
>         DBG("");
>
> +       g_list_free_full(connections, cleanup_rfsock);
> +       g_list_free_full(servers, cleanup_rfsock);
> +
>         ipc_unregister(HAL_SERVICE_ID_SOCK);
>  }
> --
> 1.8.3.2

This one is now applied, please rebase make the changes we discussed
for the last 3.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH] all: Use G_SOURCE_REMOVE/G_SOURCE_CONTINUE macros
From: Johan Hedberg @ 2013-12-05 14:00 UTC (permalink / raw)
  To: Bastien Nocera, linux-bluetooth
In-Reply-To: <20131205133527.GA10825@x220.p-661hnu-f1>

Hi,

On Thu, Dec 05, 2013, Johan Hedberg wrote:
> On Wed, Nov 20, 2013, Bastien Nocera wrote:
> > 
> > Instead of TRUE/FALSE. This makes the source more readable.
> > ---
> >  attrib/gattrib.c                     |  2 +-
> >  attrib/gatttool.c                    |  2 +-
> >  configure.ac                         |  8 ++++++++
> >  gdbus/mainloop.c                     |  6 +++---
> >  gdbus/object.c                       |  2 +-
> >  gdbus/watch.c                        |  2 +-
> >  gobex/gobex.c                        |  4 ++--
> >  obexd/client/session.c               |  4 ++--
> >  obexd/client/transfer.c              |  6 +++---
> >  obexd/plugins/messages-dummy.c       |  2 +-
> >  obexd/plugins/messages-tracker.c     |  2 +-
> >  obexd/plugins/phonebook-dummy.c      |  6 +++---
> >  plugins/policy.c                     |  6 +++---
> >  profiles/audio/a2dp.c                | 16 ++++++++--------
> >  profiles/audio/avctp.c               | 12 ++++++------
> >  profiles/audio/avdtp.c               | 14 +++++++-------
> >  profiles/audio/avrcp.c               |  2 +-
> >  profiles/audio/player.c              |  4 ++--
> >  profiles/cyclingspeed/cyclingspeed.c |  2 +-
> >  profiles/health/hdp.c                |  4 ++--
> >  profiles/health/mcap.c               |  2 +-
> >  profiles/health/mcap_sync.c          | 18 +++++++++---------
> >  profiles/input/device.c              | 10 +++++-----
> >  profiles/network/connection.c        |  2 +-
> >  profiles/proximity/monitor.c         |  4 ++--
> >  profiles/sap/server.c                |  4 ++--
> >  src/adapter.c                        | 20 ++++++++++----------
> >  src/device.c                         | 16 ++++++++--------
> >  src/main.c                           |  4 ++--
> >  src/sdp-client.c                     |  2 +-
> >  src/shared/hciemu.c                  |  2 +-
> >  src/shared/tester.c                  | 18 +++++++++---------
> >  tools/btiotest.c                     |  6 +++---
> >  unit/test-gdbus-client.c             |  4 ++--
> >  unit/test-gobex-transfer.c           |  2 +-
> >  unit/test-gobex.c                    |  4 ++--
> >  unit/test-sdp.c                      |  2 +-
> >  37 files changed, 117 insertions(+), 109 deletions(-)
> 
> Applied. Thanks.

Correction, I had to take this back out because of the gdbus changes
which should at least be independent.

Johan

^ permalink raw reply

* [PATCH 2/2] android/audio: Add audio-hal initial skeleton
From: Lukasz Rymanowski @ 2013-12-05 13:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Lukasz Rymanowski
In-Reply-To: <1386251995-12188-1-git-send-email-lukasz.rymanowski@tieto.com>

This patch adds audio module for A2DP.
Also adds empty callbacks for stream_out, stream_in and hw_device
methods.
---
 android/Android.mk  |  23 +++
 android/Makefile.am |  10 ++
 android/hal-audio.c | 436 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 469 insertions(+)
 create mode 100644 android/hal-audio.c

diff --git a/android/Android.mk b/android/Android.mk
index 549613c..ebc3219 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -203,3 +203,26 @@ LOCAL_MODULE_TAGS := eng
 LOCAL_MODULE := btmon
 
 include $(BUILD_EXECUTABLE)
+
+#
+# A2DP audio
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := hal-audio.c
+
+LOCAL_C_INCLUDES = \
+	$(call include-path-for, system-core) \
+	$(call include-path-for, libhardware) \
+
+LOCAL_SHARED_LIBRARIES := \
+	libcutils \
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS) \
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := audio.a2dp.default
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/android/Makefile.am b/android/Makefile.am
index df04762..9349a61 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -83,6 +83,16 @@ android_haltest_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android \
 
 android_haltest_LDFLAGS = -pthread
 
+noinst_LTLIBRARIES += android/libaudio-internal.la
+
+android_libaudio_internal_la_SOURCES = android/hal-audio.c \
+					android/hardware/audio.h \
+					android/hardware/audio_effect.h \
+					android/hardware/hardware.h \
+					android/system/audio.h
+
+android_libaudio_internal_la_CPPFLAGS = -I$(srcdir)/android
+
 endif
 
 EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
diff --git a/android/hal-audio.c b/android/hal-audio.c
new file mode 100644
index 0000000..e98f317
--- /dev/null
+++ b/android/hal-audio.c
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <hardware/audio.h>
+#include <hardware/hardware.h>
+
+#include "hal-log.h"
+
+static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
+								size_t bytes)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static uint32_t out_get_sample_rate(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static size_t out_get_buffer_size(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static uint32_t out_get_channels(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static audio_format_t out_get_format(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_set_format(struct audio_stream *stream, audio_format_t format)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_standby(struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_dump(const struct audio_stream *stream, int fd)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static char *out_get_parameters(const struct audio_stream *stream,
+							const char *keys)
+{
+	DBG("");
+	return strdup("");
+}
+
+static uint32_t out_get_latency(const struct audio_stream_out *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_set_volume(struct audio_stream_out *stream, float left,
+								float right)
+{
+	DBG("");
+	/* volume controlled in audioflinger mixer (digital) */
+	return -ENOSYS;
+}
+
+static int out_get_render_position(const struct audio_stream_out *stream,
+							uint32_t *dsp_frames)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_add_audio_effect(const struct audio_stream *stream,
+							effect_handle_t effect)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int out_remove_audio_effect(const struct audio_stream *stream,
+							effect_handle_t effect)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static uint32_t in_get_sample_rate(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static size_t in_get_buffer_size(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static uint32_t in_get_channels(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static audio_format_t in_get_format(const struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_set_format(struct audio_stream *stream, audio_format_t format)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_standby(struct audio_stream *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_dump(const struct audio_stream *stream, int fd)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static char *in_get_parameters(const struct audio_stream *stream,
+							const char *keys)
+{
+	DBG("");
+	return strdup("");
+}
+
+static int in_set_gain(struct audio_stream_in *stream, float gain)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
+								size_t bytes)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_add_audio_effect(const struct audio_stream *stream,
+							effect_handle_t effect)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int in_remove_audio_effect(const struct audio_stream *stream,
+							effect_handle_t effect)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_open_output_stream(struct audio_hw_device *dev,
+					audio_io_handle_t handle,
+					audio_devices_t devices,
+					audio_output_flags_t flags,
+					struct audio_config *config,
+					struct audio_stream_out **stream_out)
+
+{
+	struct audio_stream_out *out;
+
+	out = calloc(1, sizeof(struct audio_stream_out));
+	if (!out)
+		return -ENOMEM;
+
+	DBG("");
+
+	out->common.get_sample_rate = out_get_sample_rate;
+	out->common.set_sample_rate = out_set_sample_rate;
+	out->common.get_buffer_size = out_get_buffer_size;
+	out->common.get_channels = out_get_channels;
+	out->common.get_format = out_get_format;
+	out->common.set_format = out_set_format;
+	out->common.standby = out_standby;
+	out->common.dump = out_dump;
+	out->common.set_parameters = out_set_parameters;
+	out->common.get_parameters = out_get_parameters;
+	out->common.add_audio_effect = out_add_audio_effect;
+	out->common.remove_audio_effect = out_remove_audio_effect;
+	out->get_latency = out_get_latency;
+	out->set_volume = out_set_volume;
+	out->write = out_write;
+	out->get_render_position = out_get_render_position;
+
+	*stream_out = out;
+
+	return 0;
+}
+
+static void adev_close_output_stream(struct audio_hw_device *dev,
+					struct audio_stream_out *stream)
+{
+	DBG("");
+}
+
+static int adev_set_parameters(struct audio_hw_device *dev,
+							const char *kvpairs)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static char *adev_get_parameters(const struct audio_hw_device *dev,
+							const char *keys)
+{
+	DBG("");
+	return strdup("");
+}
+
+static int adev_init_check(const struct audio_hw_device *dev)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_set_mode(struct audio_hw_device *dev, int mode)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
+					const struct audio_config *config)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_open_input_stream(struct audio_hw_device *dev,
+						audio_io_handle_t handle,
+						audio_devices_t devices,
+						struct audio_config *config,
+					  struct audio_stream_in **stream_in)
+{
+	struct audio_stream_in *in;
+
+	DBG("");
+
+	in = calloc(1, sizeof(struct audio_stream_in));
+	if (!in)
+		return -ENOMEM;
+
+	in->common.get_sample_rate = in_get_sample_rate;
+	in->common.set_sample_rate = in_set_sample_rate;
+	in->common.get_buffer_size = in_get_buffer_size;
+	in->common.get_channels = in_get_channels;
+	in->common.get_format = in_get_format;
+	in->common.set_format = in_set_format;
+	in->common.standby = in_standby;
+	in->common.dump = in_dump;
+	in->common.set_parameters = in_set_parameters;
+	in->common.get_parameters = in_get_parameters;
+	in->common.add_audio_effect = in_add_audio_effect;
+	in->common.remove_audio_effect = in_remove_audio_effect;
+	in->set_gain = in_set_gain;
+	in->read = in_read;
+	in->get_input_frames_lost = in_get_input_frames_lost;
+
+	*stream_in = in;
+
+	return 0;
+}
+
+static void adev_close_input_stream(struct audio_hw_device *dev,
+					struct audio_stream_in *stream_in)
+{
+	DBG("");
+	free(stream_in);
+}
+
+static int adev_dump(const audio_hw_device_t *device, int fd)
+{
+	DBG("");
+	return -ENOSYS;
+}
+
+static int adev_close(hw_device_t *device)
+{
+	DBG("");
+	free(device);
+	return 0;
+}
+
+static int adev_open(const hw_module_t *module, const char *name,
+							hw_device_t **device)
+{
+	struct audio_hw_device *adev;
+
+	DBG("");
+
+	if (strcmp(name, AUDIO_HARDWARE_INTERFACE)) {
+		error("interface %s not matching [%s]", name,
+						AUDIO_HARDWARE_INTERFACE);
+		return -EINVAL;
+	}
+
+	adev = calloc(1, sizeof(struct audio_hw_device));
+	if (!adev)
+		return -ENOMEM;
+
+	adev->common.version = AUDIO_DEVICE_API_VERSION_CURRENT;
+	adev->common.module = (struct hw_module_t *) module;
+	adev->common.close = adev_close;
+
+	adev->init_check = adev_init_check;
+	adev->set_voice_volume = adev_set_voice_volume;
+	adev->set_master_volume = adev_set_master_volume;
+	adev->set_mode = adev_set_mode;
+	adev->set_mic_mute = adev_set_mic_mute;
+	adev->get_mic_mute = adev_get_mic_mute;
+	adev->set_parameters = adev_set_parameters;
+	adev->get_parameters = adev_get_parameters;
+	adev->get_input_buffer_size = adev_get_input_buffer_size;
+	adev->open_output_stream = adev_open_output_stream;
+	adev->close_output_stream = adev_close_output_stream;
+	adev->open_input_stream = adev_open_input_stream;
+	adev->close_input_stream = adev_close_input_stream;
+	adev->dump = adev_dump;
+
+	*device = &adev->common;
+
+	return 0;
+}
+
+static struct hw_module_methods_t hal_module_methods = {
+	.open = adev_open,
+};
+
+struct audio_module HAL_MODULE_INFO_SYM = {
+	.common = {
+	.tag = HARDWARE_MODULE_TAG,
+	.version_major = 1,
+	.version_minor = 0,
+	.id = AUDIO_HARDWARE_MODULE_ID,
+	.name = "A2DP Bluez HW HAL",
+	.author = "Intel Corporation",
+	.methods = &hal_module_methods,
+	},
+};
-- 
1.8.4


^ permalink raw reply related

* Re: [PATCHv2 2/4] android/socket Use 64K buffer for socket handling
From: Andrei Emeltchenko @ 2013-12-05 13:48 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CABBYNZLzirtMJresKRYi9D-rJ8d0sJEXXDoP4X8ep=sUJv+ozQ@mail.gmail.com>

Hi Luiz,

On Thu, Dec 05, 2013 at 02:43:10PM +0200, Luiz Augusto von Dentz wrote:
> Hi Andrei,
> 
> On Tue, Dec 3, 2013 at 5:51 PM, Andrei Emeltchenko
> <Andrei.Emeltchenko.news@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > Make SOCKET_BUFFER define and use 0xFFFE instead of 1K.
> > The value 0XFFFE is what Android sends in OBEX Connect packet in
> > Maximum Packet Length field. Though OBEX specify meximum packet
> > length as 64K - 1 which is 0xFFFF.
> > ---
> >  android/socket.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/android/socket.c b/android/socket.c
> > index 9020874..9ff9019 100644
> > --- a/android/socket.c
> > +++ b/android/socket.c
> > @@ -52,6 +52,8 @@
> >
> >  #define SVC_HINT_OBEX 0x10
> >
> > +#define SOCKET_BUFFER 0xFFFE
> > +
> >  static bdaddr_t adapter_addr;
> >
> >  /* Simple list of RFCOMM server sockets */
> > @@ -487,7 +489,7 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
> >                                                                 gpointer data)
> >  {
> >         struct rfcomm_sock *rfsock = data;
> > -       unsigned char buf[1024];
> > +       unsigned char buf[SOCKET_BUFFER];
> >         int len, sent;
> >
> >         if (cond & G_IO_HUP) {
> > @@ -526,7 +528,7 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
> >                                                                 gpointer data)
> >  {
> >         struct rfcomm_sock *rfsock = data;
> > -       unsigned char buf[1024];
> > +       unsigned char buf[SOCKET_BUFFER];
> >         int len, sent;
> >
> >         if (cond & G_IO_HUP) {
> > --
> > 1.8.3.2
> 
> We need to be a bit more generic here, the socket HAL is not
> restricted to OBEX only, also it doesn't seems you are adjusting the
> buffer level of the sockets, 

it is in the following patch

> the buffer itself is just to copy between
> the sockets so we have to follow how much the sockets can
> transmit/receive not the other way around.

the idea is to copy data to socket buffers and then sleep.

> So it seems to me that we should either set the maximum MTU size we
> could use with RFCOMM (UINT16_MAX?) or read the MTU once connected
> (not sure if makes sense since it is SOCK_STREAM) and then allocate
> the same amount as buffer in a field in struct rfcomm_sock, also this
> needs then to be set back to socketpair with
> setsocketopt(SO_RCVBUF/SO_SNDBUF) so we minimize context switches and
> wakeups.

This can actually make more switches since RFCOMM packet size is
relatively small (990 bytes in my case). Maximum RFCOMM L2CAP MTU is 1013.

This is what we had before.

Best regards 
Andrei Emeltchenko 


^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox