Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v4 03/10] adaptername: Retrieve config name from adapter
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>

Retrieve saved config name using adapter_get_config_name() instead
of reading it from storage file.
---
 plugins/adaptername.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index f58fb0f..46dbbe8 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -198,7 +198,8 @@ static void set_pretty_name(struct btd_adapter *adapter,
 static int adaptername_probe(struct btd_adapter *adapter)
 {
 	int current_id;
-	char name[MAX_NAME_LENGTH + 1];
+	char *name;
+	char str[MAX_NAME_LENGTH + 1];
 	char *pretty_hostname;
 
 	pretty_hostname = read_pretty_host_name();
@@ -211,8 +212,10 @@ static int adaptername_probe(struct btd_adapter *adapter)
 	adapter_set_allow_name_changes(adapter, TRUE);
 	current_id = adapter_get_dev_id(adapter);
 
-	if (read_local_name(adapter_get_address(adapter), name) < 0)
-		expand_name(name, MAX_NAME_LENGTH, main_opts.name, current_id);
+	if (adapter_get_config_name(adapter, &name) < 0) {
+		expand_name(str, MAX_NAME_LENGTH, main_opts.name, current_id);
+		name = str;
+	}
 
 	DBG("Setting name '%s' for device 'hci%d'", name, current_id);
 	adapter_set_name(adapter, name);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v4 02/10] adapter: Read name in storage at init
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   34 ++++++++++++++++++++++++++++++++++
 src/adapter.h |    1 +
 2 files changed, 35 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index ad8ee06..8b9af28 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -115,6 +115,10 @@ struct service_auth {
 	struct agent *agent;		/* NULL for queued auths */
 };
 
+struct btd_adapter_config {
+	char *name;
+};
+
 struct btd_adapter {
 	uint16_t dev_id;
 	gboolean up;
@@ -155,6 +159,8 @@ struct btd_adapter {
 	gboolean pairable;		/* pairable state */
 	gboolean initialized;
 
+	struct btd_adapter_config config;
+
 	gboolean off_requested;		/* DEVDOWN ioctl was called */
 
 	gint ref;
@@ -780,11 +786,24 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
 		adapter->name = g_strdup(maxname);
 	}
 
+	g_free(adapter->config.name);
+	adapter->config.name = g_strdup(maxname);
+
 	write_local_name(&adapter->bdaddr, maxname);
 
 	return 0;
 }
 
+int adapter_get_config_name(struct btd_adapter *adapter, char **name)
+{
+	if (adapter->config.name == NULL)
+		return -EINVAL;
+
+	*name = adapter->config.name;
+
+	return 0;
+}
+
 static void set_name(struct btd_adapter *adapter, const char *name,
 						GDBusPendingPropertySet id)
 {
@@ -2665,6 +2684,18 @@ void btd_adapter_unref(struct btd_adapter *adapter)
 	g_free(path);
 }
 
+static void load_config(struct btd_adapter *adapter)
+{
+	char name[MAX_NAME_LENGTH + 1];
+
+	/* Get name */
+	if (read_local_name(&adapter->bdaddr, name) < 0)
+		adapter->config.name = NULL;
+	else
+		adapter->config.name = g_strdup(name);
+
+}
+
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
 {
 	adapter->up = up;
@@ -2684,6 +2715,7 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
 	if (main_opts.gatt_enabled)
 		btd_adapter_gatt_server_start(adapter);
 
+	load_config(adapter);
 	load_drivers(adapter);
 	btd_profile_foreach(probe_profile, adapter);
 	clear_blocked(adapter);
@@ -2752,6 +2784,8 @@ void adapter_remove(struct btd_adapter *adapter)
 	/* Return adapter to down state if it was not up on init */
 	if (!adapter->already_up && adapter->up)
 		mgmt_set_powered(adapter->dev_id, FALSE);
+
+	g_free(adapter->config.name);
 }
 
 uint16_t adapter_get_dev_id(struct btd_adapter *adapter)
diff --git a/src/adapter.h b/src/adapter.h
index b5bff10..b575c1b 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -133,6 +133,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
 void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
+int adapter_get_config_name(struct btd_adapter *adapter, char **name);
 int adapter_set_name(struct btd_adapter *adapter, const char *name);
 void adapter_name_changed(struct btd_adapter *adapter, const char *name);
 void adapter_service_insert(struct btd_adapter *adapter, void *rec);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v4 01/10] doc: Add settings storage documentation
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>

---
 doc/settings-storage.txt |  102 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 doc/settings-storage.txt

diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
new file mode 100644
index 0000000..0a3f90e
--- /dev/null
+++ b/doc/settings-storage.txt
@@ -0,0 +1,102 @@
+Information related to local adapters and remote devices are stored in storage
+directory (default: /var/lib/bluetooth).
+Files are in ini-file format.
+
+There is one directory per adapter, named by its bluetooth address, which
+contains:
+ - a settings file for the local adapter
+ - an attribute_db file containing attributes of supported LE services
+ - names file containing names of all devices already seen
+ - one directory per remote device, named by remote device address, which
+   contains:
+    - a settings file
+    - a key file accessible only by root
+    - an attribute_db file containing attributes of remote LE services
+
+So the directory structure should be:
+    /var/lib/bluetooth/<adapter address>/
+        ./settings
+        ./attribute_db
+        ./names
+        ./<remote device address>/
+            ./settings
+            ./keys
+            ./attribute_db
+        ./<remote device address>/
+            ./settings
+            ./keys
+            ./attribute_db
+        ...
+
+Adapter directory files
+=======================
+
+Settings file contains 1 [General] group with adapter info:
+  [General]
+  Name=
+  Class=0x000000
+  Pairable=<true|false>
+  PairableTimeout=0
+  DiscoverableTimeout=0
+  Mode=<off|connectable|discoverable>
+  OnMode=<connectable|discoverable>
+
+The attribute_db file is a list of handles (group name) with UUID and Value as
+keys, for example:
+  [0x0001]
+  UUID=00002800-0000-1000-8000-00805f9b34fb
+  Value=0018
+
+  [0x0004]
+  UUID=00002803-0000-1000-8000-00805f9b34fb
+  Value=020600002A
+
+  [0x0006]
+  UUID=00002a00-0000-1000-8000-00805f9b34fb
+  Value=4578616D706C6520446576696365
+
+Names file contains 1 [Names] group with device address as key:
+  [Names]
+  <nn:nn:nn:nn:nn:nn>=device name a
+  <mm:mm:mm:mm:mm:mm>=device name b
+
+Device directory files
+======================
+
+Remote device settings file will include a [General] group with device infos
+and a [DeviceID] group with related infos:
+  [General]
+  Alias=
+  Class=0x000000
+  Manufacturer=0
+  LmpVersion=
+  LmpSubversion=
+  Features=0000000000000000
+  SupportedTechnologies=<BR/EDR|LE>;<BR/EDR|LE>
+  AddressType=<static|public>
+  LastSeen=yyyy-mm-dd hh:mm:ss GMT
+  LastUsed=yyyy-mm-dd hh:mm:ss GMT
+  Trusted=<true|false>
+  Profiles=<128 bits UUID of profile 1>;<128 bits UUID of profile 2>;...
+
+  [DeviceID]
+  Assigner=0
+  Vendor=0
+  Product=0
+  Version=0
+
+Keys file includes informations related to link key or long term link key:
+  [LinkKey]
+  Key=
+  Type=0
+  PINLength=0
+
+  [LongTermKey]
+  Key=
+  Authenticated=<true|false>
+  EncSize=0
+  EDiv=0
+  Rand=0
+
+The attribute_db file is a list of handles (group name) with UUID and Value as
+keys (cf. attribute_db in adapter directory).
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v4 00/10] Move adapter config file to ini-file format
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
  To: linux-bluetooth

Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/settings
in ini-file format for BlueZ 5.
If this file does not exist, we try to convert legacy config file to it.

Access to variables during run-time is performed in adapter structure which is populated by loading saved configuration during initialization.

First 6 patches remove access to config file from run-time.
Last patch move to ini-file format style (load, save and convert).

Frédéric Danis (10):
  doc: Add settings storage documentation
  adapter: Read name in storage at init
  adaptername: Retrieve config name from adapter
  adapter: Read device class in storage at init
  adapter: Move pairable read to load_config()
  adapter: Read pairable timeout in storage at init
  adapter: Read discoverable timeout in storage at init
  adapter: Read mode in storage at init
  adapter: Move saved config to ini-file format
  TODO: Add entry to remove storage convertion function

 TODO                     |    6 +
 doc/settings-storage.txt |  102 ++++++++++++++
 plugins/adaptername.c    |    9 +-
 src/adapter.c            |  330 +++++++++++++++++++++++++++++++++++-----------
 src/adapter.h            |    1 +
 5 files changed, 370 insertions(+), 78 deletions(-)
 create mode 100644 doc/settings-storage.txt

-- 
1.7.9.5


^ permalink raw reply

* [PATCH] systemd: prevent duplicate logging messages in journal
From: Marti Raudsepp @ 2012-10-10 15:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marti Raudsepp

By default, both stdout and syslog messages go to the systemd journal,
which results in duplicate messages being logged.
---
 src/bluetooth.service.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/bluetooth.service.in b/src/bluetooth.service.in
index 2a576a3..a8442a9 100644
--- a/src/bluetooth.service.in
+++ b/src/bluetooth.service.in
@@ -5,6 +5,7 @@ Description=Bluetooth service
 Type=dbus
 BusName=org.bluez
 ExecStart=@prefix@/sbin/bluetoothd -n
+StandardOutput=null
 
 [Install]
 WantedBy=bluetooth.target
-- 
1.7.12.2


^ permalink raw reply related

* Re: [PATCH] Bluetooth: btmrv: Use %*ph specifier instead of print_hex_dump_bytes
From: Marcel Holtmann @ 2012-10-10 15:28 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth, bzhao
In-Reply-To: <1349880093-23728-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> Use standard print specifier and remove print_hex_dump_bytes call.
> Makes output more sensible:
> 
> ...
> [18809.401218] 00000000: 0b 00 00 fe 5b fc 01 f2 00 00 00    ....[......
> ...
> 
> would be changed to
> 
> ...
> [18809.401218] Bluetooth: hex: 0b 00 00 fe 5b fc 01 f2 00 00 00
> ...
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  drivers/bluetooth/btmrvl_sdio.c |    6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply

* Re: [PATCHv1 0/6] Handle AMP_LINK
From: Marcel Holtmann @ 2012-10-10 15:28 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> Add code for handling High Speed link
> 
> Changes:
> 	* v1: Fixes according to Marcel's review
> 	* RFCv1: Initial release
> 
> Andrei Emeltchenko (6):
>   Bluetooth: Allow to set flush timeout
>   Bluetooth: AMP: Handle AMP_LINK timeout
>   Bluetooth: AMP: Add handle to hci_chan structure
>   Bluetooth: AMP: Handle number of compl blocks for AMP_LINK
>   Bluetooth: AMP: Handle AMP_LINK connection
>   Bluetooth: AMP: Hanlde AMP_LINK case in conn_put

patches look fine to me.

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply

* Re: Agenda for Linux Wireless (802.11/Bluetooth/NFC) Mini-Summit 2012 (Barcelona!)
From: John W. Linville @ 2012-10-10 15:18 UTC (permalink / raw)
  To: Michal Kazior
  Cc: Johannes Berg, linux-wireless@vger.kernel.org,
	linux-bluetooth@vger.kernel.org, alexander.smirnov@siemens.com
In-Reply-To: <507561C8.7080601@tieto.com>

On Wed, Oct 10, 2012 at 01:53:44PM +0200, Michal Kazior wrote:
> On 22/08/12 22:41, John W. Linville wrote:
> >On Wed, Aug 22, 2012 at 10:39:35PM +0200, Johannes Berg wrote:
> >>On Wed, 2012-08-22 at 16:19 -0400, John W. Linville wrote:
> >>
> >>>With that said, there are still a number of slots available for
> >>>presentations or discussion topics.  This is especially true for the
> >>>802.11 group...  Please step-up with some suggested topics!
> >>
> >>Anyone want to carefully review & present Michal's and my work on
> >>multi-channel in mac80211? :-)
> >
> >I would _really_ like to see this.  Anyone (smarter than me) that is
> >willing to do this for the group?
> >
> >John
> >
> 
> Hi,
> 
> I'd like to do it. I'll update the wiki and put myself in a free
> timeslot if that's okay.
> 
> 
> -- Pozdrawiam / Best regards, Michal Kazior.

That sounds great to me!

Thanks,

John

-- 
John W. Linville		Someday the world will need a hero, and you
linville@tuxdriver.com			might be all we have.  Be ready.

^ permalink raw reply

* Re: [PATCH 1/2] Pass confirm name as bool value
From: Johan Hedberg @ 2012-10-10 15:00 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1349875198-28913-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Wed, Oct 10, 2012, Szymon Janc wrote:
> confirm_name is a boolean value and can be pass as such instead of
> uint8_t.
> 
> ---
>  src/adapter.c |    2 +-
>  src/adapter.h |    3 ++-
>  src/event.c   |    2 +-
>  src/event.h   |    2 +-
>  src/mgmt.c    |    2 +-
>  5 files changed, 6 insertions(+), 5 deletions(-)

Both patches have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH] Bluetooth: btmrv: Use %*ph specifier instead of print_hex_dump_bytes
From: Andrei Emeltchenko @ 2012-10-10 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: bzhao

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Use standard print specifier and remove print_hex_dump_bytes call.
Makes output more sensible:

...
[18809.401218] 00000000: 0b 00 00 fe 5b fc 01 f2 00 00 00    ....[......
...

would be changed to

...
[18809.401218] Bluetooth: hex: 0b 00 00 fe 5b fc 01 f2 00 00 00
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 drivers/bluetooth/btmrvl_sdio.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 90b3a75..49494ae 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -597,8 +597,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 
 	default:
 		BT_ERR("Unknown packet type:%d", type);
-		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, payload,
-				     blksz * num_blocks);
+		BT_ERR("hex: %*ph", blksz * num_blocks, payload);
 
 		kfree_skb(skb);
 		skb = NULL;
@@ -857,8 +856,7 @@ static int btmrvl_sdio_host_to_card(struct btmrvl_private *priv,
 		if (ret < 0) {
 			i++;
 			BT_ERR("i=%d writesb failed: %d", i, ret);
-			print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
-						payload, nb);
+			BT_ERR("hex: %*ph", nb, payload);
 			ret = -EIO;
 			if (i > MAX_WRITE_IOMEM_RETRY)
 				goto exit;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 6/6] Bluetooth: AMP: Hanlde AMP_LINK case in conn_put
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Handle AMP link when setting up disconnect timeout.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/hci_core.h |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d5ed054..9fe8e2d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -605,7 +605,10 @@ static inline void hci_conn_put(struct hci_conn *conn)
 
 	if (atomic_dec_and_test(&conn->refcnt)) {
 		unsigned long timeo;
-		if (conn->type == ACL_LINK || conn->type == LE_LINK) {
+
+		switch (conn->type) {
+		case ACL_LINK:
+		case LE_LINK:
 			del_timer(&conn->idle_timer);
 			if (conn->state == BT_CONNECTED) {
 				timeo = conn->disc_timeout;
@@ -614,12 +617,20 @@ static inline void hci_conn_put(struct hci_conn *conn)
 			} else {
 				timeo = msecs_to_jiffies(10);
 			}
-		} else {
+			break;
+
+		case AMP_LINK:
+			timeo = conn->disc_timeout;
+			break;
+
+		default:
 			timeo = msecs_to_jiffies(10);
+			break;
 		}
+
 		cancel_delayed_work(&conn->disc_work);
 		queue_delayed_work(conn->hdev->workqueue,
-					&conn->disc_work, timeo);
+				   &conn->disc_work, timeo);
 	}
 }
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 5/6] Bluetooth: AMP: Handle AMP_LINK connection
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

AMP_LINK represents physical link between AMP controllers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/hci_core.h |   13 +++++++++++++
 net/bluetooth/hci_core.c         |   22 +++++++++++++++++++---
 net/bluetooth/hci_event.c        |    1 +
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index b697ef3..d5ed054 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -73,6 +73,7 @@ struct discovery_state {
 struct hci_conn_hash {
 	struct list_head list;
 	unsigned int     acl_num;
+	unsigned int     amp_num;
 	unsigned int     sco_num;
 	unsigned int     le_num;
 };
@@ -449,6 +450,9 @@ static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
 	case ACL_LINK:
 		h->acl_num++;
 		break;
+	case AMP_LINK:
+		h->amp_num++;
+		break;
 	case LE_LINK:
 		h->le_num++;
 		break;
@@ -470,6 +474,9 @@ static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
 	case ACL_LINK:
 		h->acl_num--;
 		break;
+	case AMP_LINK:
+		h->amp_num--;
+		break;
 	case LE_LINK:
 		h->le_num--;
 		break;
@@ -486,6 +493,8 @@ static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
 	switch (type) {
 	case ACL_LINK:
 		return h->acl_num;
+	case AMP_LINK:
+		return h->amp_num;
 	case LE_LINK:
 		return h->le_num;
 	case SCO_LINK:
@@ -801,6 +810,10 @@ static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
 		sco_disconn_cfm(conn, reason);
 		break;
 
+	/* L2CAP would be handled for BREDR chan */
+	case AMP_LINK:
+		break;
+
 	default:
 		BT_ERR("unknown link type %d", conn->type);
 		break;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index bd26cb5..2e72c41 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2379,6 +2379,9 @@ static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
 	case ACL_LINK:
 		cnt = hdev->acl_cnt;
 		break;
+	case AMP_LINK:
+		cnt = hdev->block_cnt;
+		break;
 	case SCO_LINK:
 	case ESCO_LINK:
 		cnt = hdev->sco_cnt;
@@ -2508,11 +2511,19 @@ static void hci_sched_acl_blk(struct hci_dev *hdev)
 	struct hci_chan *chan;
 	struct sk_buff *skb;
 	int quote;
+	u8 type;
 
 	__check_timeout(hdev, cnt);
 
+	BT_DBG("%s", hdev->name);
+
+	if (hdev->dev_type == HCI_AMP)
+		type = AMP_LINK;
+	else
+		type = ACL_LINK;
+
 	while (hdev->block_cnt > 0 &&
-	       (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) {
+	       (chan = hci_chan_sent(hdev, type, &quote))) {
 		u32 priority = (skb_peek(&chan->data_q))->priority;
 		while (quote > 0 && (skb = skb_peek(&chan->data_q))) {
 			int blocks;
@@ -2545,14 +2556,19 @@ static void hci_sched_acl_blk(struct hci_dev *hdev)
 	}
 
 	if (cnt != hdev->block_cnt)
-		hci_prio_recalculate(hdev, ACL_LINK);
+		hci_prio_recalculate(hdev, type);
 }
 
 static void hci_sched_acl(struct hci_dev *hdev)
 {
 	BT_DBG("%s", hdev->name);
 
-	if (!hci_conn_num(hdev, ACL_LINK))
+	/* No ACL link over BR/EDR controller */
+	if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_BREDR)
+		return;
+
+	/* No AMP link over AMP controller */
+	if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP)
 		return;
 
 	switch (hdev->flow_ctl_mode) {
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 5c0b6c1..0383635 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2733,6 +2733,7 @@ static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
 
 		switch (conn->type) {
 		case ACL_LINK:
+		case AMP_LINK:
 			hdev->block_cnt += block_count;
 			if (hdev->block_cnt > hdev->num_blocks)
 				hdev->block_cnt = hdev->num_blocks;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 4/6] Bluetooth: AMP: Handle number of compl blocks for AMP_LINK
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Add handling blocks count for AMP link.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/hci_event.c |   25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 82e478a..5c0b6c1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2677,6 +2677,27 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	queue_work(hdev->workqueue, &hdev->tx_work);
 }
 
+static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev,
+						 __u16 handle)
+{
+	struct hci_chan *chan;
+
+	switch (hdev->dev_type) {
+	case HCI_BREDR:
+		return hci_conn_hash_lookup_handle(hdev, handle);
+	case HCI_AMP:
+		chan = hci_chan_lookup_handle(hdev, handle);
+		if (chan)
+			return chan->conn;
+		break;
+	default:
+		BT_ERR("%s unknown dev_type %d", hdev->name, hdev->dev_type);
+		break;
+	}
+
+	return NULL;
+}
+
 static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
@@ -2698,13 +2719,13 @@ static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
 
 	for (i = 0; i < ev->num_hndl; i++) {
 		struct hci_comp_blocks_info *info = &ev->handles[i];
-		struct hci_conn *conn;
+		struct hci_conn *conn = NULL;
 		__u16  handle, block_count;
 
 		handle = __le16_to_cpu(info->handle);
 		block_count = __le16_to_cpu(info->blocks);
 
-		conn = hci_conn_hash_lookup_handle(hdev, handle);
+		conn = __hci_conn_lookup_handle(hdev, handle);
 		if (!conn)
 			continue;
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 3/6] Bluetooth: AMP: Add handle to hci_chan structure
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

hci_chan will be identified by handle used in logical link creation
process. This handle is used in AMP ACL-U packet handle field.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/hci_core.h |    3 ++-
 net/bluetooth/hci_conn.c         |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index dfa108c..b697ef3 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -350,7 +350,7 @@ struct hci_conn {
 
 struct hci_chan {
 	struct list_head list;
-
+	__u16 handle;
 	struct hci_conn *conn;
 	struct sk_buff_head data_q;
 	unsigned int	sent;
@@ -567,6 +567,7 @@ void hci_conn_check_pending(struct hci_dev *hdev);
 struct hci_chan *hci_chan_create(struct hci_conn *conn);
 void hci_chan_del(struct hci_chan *chan);
 void hci_chan_list_flush(struct hci_conn *conn);
+struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
 
 struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
 			     __u8 dst_type, __u8 sec_level, __u8 auth_type);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 6487579..fe64621 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -989,3 +989,35 @@ void hci_chan_list_flush(struct hci_conn *conn)
 	list_for_each_entry_safe(chan, n, &conn->chan_list, list)
 		hci_chan_del(chan);
 }
+
+static struct hci_chan *__hci_chan_lookup_handle(struct hci_conn *hcon,
+						 __u16 handle)
+{
+	struct hci_chan *hchan;
+
+	list_for_each_entry(hchan, &hcon->chan_list, list) {
+		if (hchan->handle == handle)
+			return hchan;
+	}
+
+	return NULL;
+}
+
+struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
+{
+	struct hci_conn_hash *h = &hdev->conn_hash;
+	struct hci_conn *hcon;
+	struct hci_chan *hchan = NULL;
+
+	rcu_read_lock();
+
+	list_for_each_entry_rcu(hcon, &h->list, list) {
+		hchan = __hci_chan_lookup_handle(hcon, handle);
+		if (hchan)
+			break;
+	}
+
+	rcu_read_unlock();
+
+	return hchan;
+}
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 2/6] Bluetooth: AMP: Handle AMP_LINK timeout
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

When AMP_LINK timeouts execute HCI_OP_DISCONN_PHY_LINK as analog to
HCI_OP_DISCONNECT for ACL_LINK.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/hci_core.h |    2 ++
 net/bluetooth/hci_conn.c         |   32 +++++++++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 90ae4f0..dfa108c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -285,6 +285,8 @@ struct hci_dev {
 	int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
 };
 
+#define HCI_PHY_HANDLE(handle)	(handle & 0xff)
+
 struct hci_conn {
 	struct list_head list;
 
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 53202f6..6487579 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -130,6 +130,20 @@ void hci_acl_disconn(struct hci_conn *conn, __u8 reason)
 	hci_send_cmd(conn->hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp);
 }
 
+static void hci_amp_disconn(struct hci_conn *conn, __u8 reason)
+{
+	struct hci_cp_disconn_phy_link cp;
+
+	BT_DBG("hcon %p", conn);
+
+	conn->state = BT_DISCONN;
+
+	cp.phy_handle = HCI_PHY_HANDLE(conn->handle);
+	cp.reason = reason;
+	hci_send_cmd(conn->hdev, HCI_OP_DISCONN_PHY_LINK,
+		     sizeof(cp), &cp);
+}
+
 static void hci_add_sco(struct hci_conn *conn, __u16 handle)
 {
 	struct hci_dev *hdev = conn->hdev;
@@ -230,11 +244,24 @@ void hci_sco_setup(struct hci_conn *conn, __u8 status)
 	}
 }
 
+static void hci_conn_disconnect(struct hci_conn *conn)
+{
+	__u8 reason = hci_proto_disconn_ind(conn);
+
+	switch (conn->type) {
+	case ACL_LINK:
+		hci_acl_disconn(conn, reason);
+		break;
+	case AMP_LINK:
+		hci_amp_disconn(conn, reason);
+		break;
+	}
+}
+
 static void hci_conn_timeout(struct work_struct *work)
 {
 	struct hci_conn *conn = container_of(work, struct hci_conn,
 					     disc_work.work);
-	__u8 reason;
 
 	BT_DBG("hcon %p state %s", conn, state_to_string(conn->state));
 
@@ -253,8 +280,7 @@ static void hci_conn_timeout(struct work_struct *work)
 		break;
 	case BT_CONFIG:
 	case BT_CONNECTED:
-		reason = hci_proto_disconn_ind(conn);
-		hci_acl_disconn(conn, reason);
+		hci_conn_disconnect(conn);
 		break;
 	default:
 		conn->state = BT_CLOSED;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 1/6] Bluetooth: Allow to set flush timeout
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349879912-23633-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>


Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_sock.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index af467ce..ed2dfc9 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -529,6 +529,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
 		chan->fcs  = opts.fcs;
 		chan->max_tx = opts.max_tx;
 		chan->tx_win = opts.txwin_size;
+		chan->flush_to = opts.flush_to;
 		break;
 
 	case L2CAP_LM:
-- 
1.7.9.5


^ permalink raw reply related

* [PATCHv1 0/6] Handle AMP_LINK
From: Andrei Emeltchenko @ 2012-10-10 14:38 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349707932-10006-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Add code for handling High Speed link

Changes:
	* v1: Fixes according to Marcel's review
	* RFCv1: Initial release

Andrei Emeltchenko (6):
  Bluetooth: Allow to set flush timeout
  Bluetooth: AMP: Handle AMP_LINK timeout
  Bluetooth: AMP: Add handle to hci_chan structure
  Bluetooth: AMP: Handle number of compl blocks for AMP_LINK
  Bluetooth: AMP: Handle AMP_LINK connection
  Bluetooth: AMP: Hanlde AMP_LINK case in conn_put

 include/net/bluetooth/hci_core.h |   35 ++++++++++++++++++---
 net/bluetooth/hci_conn.c         |   64 ++++++++++++++++++++++++++++++++++++--
 net/bluetooth/hci_core.c         |   22 +++++++++++--
 net/bluetooth/hci_event.c        |   26 ++++++++++++++--
 net/bluetooth/l2cap_sock.c       |    1 +
 5 files changed, 136 insertions(+), 12 deletions(-)

-- 
1.7.9.5


^ permalink raw reply

* [PATCH v3 10/10] TODO: Add entry to remove storage convertion function
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

---
 TODO |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/TODO b/TODO
index 384d428..c6787cc 100644
--- a/TODO
+++ b/TODO
@@ -30,6 +30,12 @@ General
   Priority: Low
   Complexity: C1
 
+- Function in src/adapter.c to convert old storage files to new ini-file format
+  should be removed 6-8 months after first BlueZ 5 release.
+
+  Priority: Low
+  Complexity: C1
+
 BlueZ 5
 =======
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 09/10] adapter: Move saved config to ini-file format
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

Read and write config file in ini-file format.
If the file can not be loaded, try to convert legacy configuration.
---
 src/adapter.c |  206 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 174 insertions(+), 32 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 85c5da9..6b4197c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <sys/ioctl.h>
+#include <sys/file.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -84,6 +85,8 @@
 
 #define OFF_TIMER 3
 
+#define SETTINGS_PATH STORAGEDIR "/%s/settings"
+
 static GSList *adapter_drivers = NULL;
 
 enum session_req_type {
@@ -224,6 +227,54 @@ static uint8_t get_mode(const char *mode)
 		return MODE_UNKNOWN;
 }
 
+static void write_config(struct btd_adapter *adapter)
+{
+	GKeyFile *key_file;
+	char filename[PATH_MAX + 1];
+	char address[18];
+	char *str;
+	gsize length = 0;
+
+	key_file = g_key_file_new();
+
+	g_key_file_set_string(key_file, "General", "Name",
+				adapter->config.name);
+
+	str = g_strdup_printf("0x%2.2x%2.2x%2.2x", adapter->config.class[2],
+				adapter->config.class[1],
+				adapter->config.class[0]);
+	g_key_file_set_string(key_file, "General", "Class", str);
+	g_free(str);
+
+	g_key_file_set_boolean(key_file, "General", "Pairable",
+				adapter->pairable);
+
+	if (adapter->pairable_timeout != main_opts.pairto)
+		g_key_file_set_integer(key_file, "General", "PairableTimeout",
+					adapter->pairable_timeout);
+
+	if (adapter->discov_timeout != main_opts.discovto)
+		g_key_file_set_integer(key_file, "General",
+					"DiscoverableTimeout",
+					adapter->discov_timeout);
+
+	g_key_file_set_string(key_file, "General", "Mode",
+				mode2str(adapter->config.mode));
+	g_key_file_set_string(key_file, "General", "OnMode",
+				mode2str(adapter->config.on_mode));
+
+	ba2str(&adapter->bdaddr, address);
+	snprintf(filename, PATH_MAX, SETTINGS_PATH, address);
+
+	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+	str = g_key_file_to_data(key_file, &length, NULL);
+	g_file_set_contents(filename, str, length, NULL);
+	g_free(str);
+
+	g_key_file_free(key_file);
+}
+
 static struct session_req *session_ref(struct session_req *req)
 {
 	req->refcount++;
@@ -293,7 +344,6 @@ static struct session_req *find_session_by_msg(GSList *list, const DBusMessage *
 static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 {
 	int err;
-	const char *modestr;
 
 	if (adapter->pending_mode != NULL)
 		return -EALREADY;
@@ -329,10 +379,9 @@ done:
 	if (new_mode != MODE_OFF)
 		adapter->config.on_mode = new_mode;
 
-	modestr = mode2str(new_mode);
-	write_device_mode(&adapter->bdaddr, modestr);
+	write_config(adapter);
 
-	DBG("%s", modestr);
+	DBG("%s", mode2str(new_mode));
 
 	return 0;
 }
@@ -475,7 +524,7 @@ void btd_adapter_pairable_changed(struct btd_adapter *adapter,
 {
 	adapter->pairable = pairable;
 
-	write_device_pairable(&adapter->bdaddr, pairable);
+	write_config(adapter);
 
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
 					ADAPTER_INTERFACE, "Pairable");
@@ -692,7 +741,7 @@ static void set_discoverable_timeout(struct btd_adapter *adapter,
 
 	adapter->discov_timeout = timeout;
 
-	write_discoverable_timeout(&adapter->bdaddr, timeout);
+	write_config(adapter);
 
 	g_dbus_emit_property_changed(conn, adapter->path, ADAPTER_INTERFACE,
 						"DiscoverableTimeout");
@@ -712,7 +761,7 @@ static void set_pairable_timeout(struct btd_adapter *adapter,
 
 	adapter->pairable_timeout = timeout;
 
-	write_pairable_timeout(&adapter->bdaddr, timeout);
+	write_config(adapter);
 
 	g_dbus_emit_property_changed(conn, adapter->path, ADAPTER_INTERFACE,
 							"PairableTimeout");
@@ -732,7 +781,7 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)
 	adapter->config.class[1] = new_class[1];
 	adapter->config.class[2] = new_class[2];
 
-	write_local_class(&adapter->bdaddr, new_class);
+	write_config(adapter);
 
 	adapter->dev_class = class;
 
@@ -792,7 +841,7 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
 	g_free(adapter->config.name);
 	adapter->config.name = g_strdup(maxname);
 
-	write_local_name(&adapter->bdaddr, maxname);
+	write_config(adapter);
 
 	return 0;
 }
@@ -2479,17 +2528,15 @@ static void set_mode_complete(struct btd_adapter *adapter)
 {
 	DBusConnection *conn = btd_get_dbus_connection();
 	struct session_req *pending;
-	const char *modestr;
 	int err;
 
 	adapter->config.mode = adapter->mode;
 	if (adapter->mode != MODE_OFF)
 		adapter->config.on_mode = adapter->mode;
 
-	modestr = mode2str(adapter->mode);
-	write_device_mode(&adapter->bdaddr, modestr);
+	write_config(adapter);
 
-	DBG("%s", modestr);
+	DBG("%s", mode2str(adapter->mode));
 
 	if (adapter->mode == MODE_OFF) {
 		g_slist_free_full(adapter->mode_sessions, session_free);
@@ -2656,56 +2703,151 @@ void btd_adapter_unref(struct btd_adapter *adapter)
 	g_free(path);
 }
 
-static void load_config(struct btd_adapter *adapter)
+static void convert_config(struct btd_adapter *adapter, const char *filename,
+				GKeyFile *key_file)
 {
-	char name[MAX_NAME_LENGTH + 1];
 	char address[18];
-	char mode[14];
+	char str[MAX_NAME_LENGTH + 1];
+	char config_path[PATH_MAX + 1];
+	char *converted;
+	uint8_t class[3];
+	gboolean flag;
 	int timeout;
+	char *data;
+	gsize length = 0;
+
+	ba2str(&adapter->bdaddr, address);
+	snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address);
+
+	converted = textfile_get(config_path, "converted");
+	if (converted) {
+		if (strcmp(converted, "yes") == 0) {
+			DBG("Legacy config file already converted");
+			return;
+		}
+
+		g_free(converted);
+	}
+
+	if (read_local_name(&adapter->bdaddr, str) == 0)
+		g_key_file_set_string(key_file, "General", "Name", str);
+
+	if (read_local_class(&adapter->bdaddr, class) == 0) {
+		sprintf(str, "0x%2.2x%2.2x%2.2x", class[2], class[1], class[0]);
+		g_key_file_set_string(key_file, "General", "Class", str);
+	}
+
+	if (read_device_pairable(&adapter->bdaddr, &flag) == 0)
+		g_key_file_set_boolean(key_file, "General", "Pairable", flag);
+
+	if (read_pairable_timeout(address, &timeout) == 0)
+		g_key_file_set_integer(key_file, "General",
+						"PairableTimeout", timeout);
+
+	if (read_discoverable_timeout(address, &timeout) == 0)
+		g_key_file_set_integer(key_file, "General",
+						"DiscoverableTimeout", timeout);
+
+	if (read_device_mode(address, str, sizeof(str)) == 0)
+		g_key_file_set_string(key_file, "General", "Mode", str);
+
+	if (read_on_mode(address, str, sizeof(str)) == 0)
+		g_key_file_set_string(key_file, "General", "OnMode", str);
+
+	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+	data = g_key_file_to_data(key_file, &length, NULL);
+	g_file_set_contents(filename, data, length, NULL);
+	g_free(data);
+
+	textfile_put(config_path, "converted", "yes");
+}
+
+static void load_config(struct btd_adapter *adapter)
+{
+	GKeyFile *key_file;
+	char filename[PATH_MAX + 1];
+	char address[18];
+	char *str;
+	GError *gerr = NULL;
 
 	ba2str(&adapter->bdaddr, address);
 
+	key_file = g_key_file_new();
+
+	snprintf(filename, PATH_MAX, SETTINGS_PATH, address);
+
+	if (!g_key_file_load_from_file(key_file, filename, 0, NULL))
+		convert_config(adapter, filename, key_file);
+
 	/* Get name */
-	if (read_local_name(&adapter->bdaddr, name) < 0)
-		adapter->config.name = NULL;
-	else
-		adapter->config.name = g_strdup(name);
+	adapter->config.name = g_key_file_get_string(key_file, "General",
+								"Name", NULL);
 
 	/* Get class */
-	if (read_local_class(&adapter->bdaddr, adapter->config.class) < 0) {
+	str = g_key_file_get_string(key_file, "General", "Class", NULL);
+	if (str) {
+		char tmp[3];
+		int i;
+		uint8_t *class = adapter->config.class;
+
+		memset(tmp, 0, sizeof(tmp));
+		for (i = 0; i < 3; i++) {
+			memcpy(tmp, str + (i * 2) + 2, 2);
+			class[2 - i] = (uint8_t) strtol(tmp, NULL, 16);
+		}
+	} else {
 		uint32_t class = htobl(main_opts.class);
 		memcpy(adapter->config.class, &class, 3);
 	}
+	g_free(str);
 
 	/* Get pairable mode */
-	if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
+	adapter->pairable = g_key_file_get_boolean(key_file, "General",
+							"Pairable", &gerr);
+	if (gerr) {
 		adapter->pairable = TRUE;
+		g_error_free(gerr);
+		gerr = NULL;
+	}
 
 	/* Get pairable timeout */
-	if (read_pairable_timeout(address, &timeout) < 0)
+	adapter->pairable_timeout = g_key_file_get_integer(key_file, "General",
+						"PairableTimeout", &gerr);
+	if (gerr) {
 		adapter->pairable_timeout = main_opts.pairto;
-	else
-		adapter->pairable_timeout = timeout;
+		g_error_free(gerr);
+		gerr = NULL;
+	}
 
 	/* Get discoverable timeout */
-	if (read_discoverable_timeout(address, &timeout) < 0)
+	adapter->discov_timeout = g_key_file_get_integer(key_file, "General",
+						"DiscoverableTimeout", &gerr);
+	if (gerr) {
 		adapter->discov_timeout = main_opts.discovto;
-	else
-		adapter->discov_timeout = timeout;
+		g_error_free(gerr);
+		gerr = NULL;
+	}
 
 	/* Get mode */
+	str = g_key_file_get_string(key_file, "General", "Mode", NULL);
 	if (main_opts.remember_powered == FALSE)
 		adapter->config.mode = main_opts.mode;
-	else if (read_device_mode(address, mode, sizeof(mode)) == 0)
-		adapter->config.mode = get_mode(mode);
+	else if (str)
+		adapter->config.mode = get_mode(str);
 	else
 		adapter->config.mode = main_opts.mode;
+	g_free(str);
 
 	/* Get on mode */
-	if (read_on_mode(address, mode, sizeof(mode)) == 0)
-		adapter->config.on_mode = get_mode(mode);
+	str = g_key_file_get_string(key_file, "General", "OnMode", NULL);
+	if (str)
+		adapter->config.on_mode = get_mode(str);
 	else
 		adapter->config.on_mode = MODE_CONNECTABLE;
+	g_free(str);
+
+	g_key_file_free(key_file);
 }
 
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 08/10] adapter: Read mode in storage at init
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   61 ++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 27 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 40df4a1..85c5da9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -118,6 +118,8 @@ struct service_auth {
 struct btd_adapter_config {
 	char *name;
 	uint8_t class[3];
+	uint8_t mode;
+	uint8_t on_mode;
 };
 
 struct btd_adapter {
@@ -210,7 +212,7 @@ static const char *mode2str(uint8_t mode)
 	}
 }
 
-static uint8_t get_mode(const bdaddr_t *bdaddr, const char *mode)
+static uint8_t get_mode(const char *mode)
 {
 	if (strcasecmp("off", mode) == 0)
 		return MODE_OFF;
@@ -218,15 +220,7 @@ static uint8_t get_mode(const bdaddr_t *bdaddr, const char *mode)
 		return MODE_CONNECTABLE;
 	else if (strcasecmp("discoverable", mode) == 0)
 		return MODE_DISCOVERABLE;
-	else if (strcasecmp("on", mode) == 0) {
-		char onmode[14], srcaddr[18];
-
-		ba2str(bdaddr, srcaddr);
-		if (read_on_mode(srcaddr, onmode, sizeof(onmode)) < 0)
-			return MODE_CONNECTABLE;
-
-		return get_mode(bdaddr, onmode);
-	} else
+	else
 		return MODE_UNKNOWN;
 }
 
@@ -331,6 +325,10 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		return err;
 
 done:
+	adapter->config.mode = new_mode;
+	if (new_mode != MODE_OFF)
+		adapter->config.on_mode = new_mode;
+
 	modestr = mode2str(new_mode);
 	write_device_mode(&adapter->bdaddr, modestr);
 
@@ -390,7 +388,7 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
 	int err;
 
 	if (powered) {
-		mode = get_mode(&adapter->bdaddr, "on");
+		mode = adapter->config.on_mode;
 		return set_discoverable(adapter, mode == MODE_DISCOVERABLE,
 									id);
 	}
@@ -1403,7 +1401,7 @@ static DBusMessage *request_session(DBusConnection *conn,
 	if (!adapter->mode_sessions)
 		adapter->global_mode = adapter->mode;
 
-	new_mode = get_mode(&adapter->bdaddr, "on");
+	new_mode = adapter->config.on_mode;
 
 	req = find_session(adapter->mode_sessions, sender);
 	if (req) {
@@ -2312,21 +2310,15 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
 						uint16_t *discoverable_timeout,
 						gboolean *pairable)
 {
-	char str[14], address[18];
+	char address[18];
 
 	ba2str(&adapter->bdaddr, address);
 
-	if (mode) {
-		if (main_opts.remember_powered == FALSE)
-			*mode = main_opts.mode;
-		else if (read_device_mode(address, str, sizeof(str)) == 0)
-			*mode = get_mode(&adapter->bdaddr, str);
-		else
-			*mode = main_opts.mode;
-	}
+	if (mode)
+		*mode = adapter->config.mode;
 
 	if (on_mode)
-		*on_mode = get_mode(&adapter->bdaddr, "on");
+		*on_mode = adapter->config.on_mode;
 
 	if (discoverable_timeout)
 		*discoverable_timeout = adapter->discov_timeout;
@@ -2490,6 +2482,10 @@ static void set_mode_complete(struct btd_adapter *adapter)
 	const char *modestr;
 	int err;
 
+	adapter->config.mode = adapter->mode;
+	if (adapter->mode != MODE_OFF)
+		adapter->config.on_mode = adapter->mode;
+
 	modestr = mode2str(adapter->mode);
 	write_device_mode(&adapter->bdaddr, modestr);
 
@@ -2664,6 +2660,7 @@ static void load_config(struct btd_adapter *adapter)
 {
 	char name[MAX_NAME_LENGTH + 1];
 	char address[18];
+	char mode[14];
 	int timeout;
 
 	ba2str(&adapter->bdaddr, address);
@@ -2695,6 +2692,20 @@ static void load_config(struct btd_adapter *adapter)
 		adapter->discov_timeout = main_opts.discovto;
 	else
 		adapter->discov_timeout = timeout;
+
+	/* Get mode */
+	if (main_opts.remember_powered == FALSE)
+		adapter->config.mode = main_opts.mode;
+	else if (read_device_mode(address, mode, sizeof(mode)) == 0)
+		adapter->config.mode = get_mode(mode);
+	else
+		adapter->config.mode = main_opts.mode;
+
+	/* Get on mode */
+	if (read_on_mode(address, mode, sizeof(mode)) == 0)
+		adapter->config.on_mode = get_mode(mode);
+	else
+		adapter->config.on_mode = MODE_CONNECTABLE;
 }
 
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
@@ -3601,17 +3612,13 @@ gboolean adapter_powering_down(struct btd_adapter *adapter)
 
 int btd_adapter_restore_powered(struct btd_adapter *adapter)
 {
-	char mode[14], address[18];
-
 	if (!main_opts.remember_powered)
 		return -EINVAL;
 
 	if (adapter->up)
 		return 0;
 
-	ba2str(&adapter->bdaddr, address);
-	if (read_device_mode(address, mode, sizeof(mode)) == 0 &&
-						g_str_equal(mode, "off"))
+	if (adapter->config.mode == MODE_OFF)
 		return 0;
 
 	return mgmt_set_powered(adapter->dev_id, TRUE);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 07/10] adapter: Read discoverable timeout in storage at init
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index b869d81..40df4a1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2268,16 +2268,6 @@ static void load_connections(struct btd_adapter *adapter)
 	g_slist_free_full(conns, g_free);
 }
 
-static int get_discoverable_timeout(const char *src)
-{
-	int timeout;
-
-	if (read_discoverable_timeout(src, &timeout) == 0)
-		return timeout;
-
-	return main_opts.discovto;
-}
-
 static void set_auto_connect(gpointer data, gpointer user_data)
 {
 	struct btd_device *device = data;
@@ -2339,7 +2329,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
 		*on_mode = get_mode(&adapter->bdaddr, "on");
 
 	if (discoverable_timeout)
-		*discoverable_timeout = get_discoverable_timeout(address);
+		*discoverable_timeout = adapter->discov_timeout;
 
 	if (pairable)
 		*pairable = adapter->pairable;
@@ -2421,7 +2411,6 @@ void btd_adapter_start(struct btd_adapter *adapter)
 	adapter->dev_class = 0;
 	adapter->off_requested = FALSE;
 	adapter->up = TRUE;
-	adapter->discov_timeout = get_discoverable_timeout(address);
 	adapter->off_timer = 0;
 
 	if (adapter->scan_mode & SCAN_INQUIRY)
@@ -2700,6 +2689,12 @@ static void load_config(struct btd_adapter *adapter)
 		adapter->pairable_timeout = main_opts.pairto;
 	else
 		adapter->pairable_timeout = timeout;
+
+	/* Get discoverable timeout */
+	if (read_discoverable_timeout(address, &timeout) < 0)
+		adapter->discov_timeout = main_opts.discovto;
+	else
+		adapter->discov_timeout = timeout;
 }
 
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 06/10] adapter: Read pairable timeout in storage at init
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 357b717..b869d81 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2278,16 +2278,6 @@ static int get_discoverable_timeout(const char *src)
 	return main_opts.discovto;
 }
 
-static int get_pairable_timeout(const char *src)
-{
-	int timeout;
-
-	if (read_pairable_timeout(src, &timeout) == 0)
-		return timeout;
-
-	return main_opts.pairto;
-}
-
 static void set_auto_connect(gpointer data, gpointer user_data)
 {
 	struct btd_device *device = data;
@@ -2432,7 +2422,6 @@ void btd_adapter_start(struct btd_adapter *adapter)
 	adapter->off_requested = FALSE;
 	adapter->up = TRUE;
 	adapter->discov_timeout = get_discoverable_timeout(address);
-	adapter->pairable_timeout = get_pairable_timeout(address);
 	adapter->off_timer = 0;
 
 	if (adapter->scan_mode & SCAN_INQUIRY)
@@ -2685,6 +2674,10 @@ void btd_adapter_unref(struct btd_adapter *adapter)
 static void load_config(struct btd_adapter *adapter)
 {
 	char name[MAX_NAME_LENGTH + 1];
+	char address[18];
+	int timeout;
+
+	ba2str(&adapter->bdaddr, address);
 
 	/* Get name */
 	if (read_local_name(&adapter->bdaddr, name) < 0)
@@ -2701,6 +2694,12 @@ static void load_config(struct btd_adapter *adapter)
 	/* Get pairable mode */
 	if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
 		adapter->pairable = TRUE;
+
+	/* Get pairable timeout */
+	if (read_pairable_timeout(address, &timeout) < 0)
+		adapter->pairable_timeout = main_opts.pairto;
+	else
+		adapter->pairable_timeout = timeout;
 }
 
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 05/10] adapter: Move pairable read to load_config()
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 93dc0fb..357b717 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2697,6 +2697,10 @@ static void load_config(struct btd_adapter *adapter)
 		uint32_t class = htobl(main_opts.class);
 		memcpy(adapter->config.class, &class, 3);
 	}
+
+	/* Get pairable mode */
+	if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
+		adapter->pairable = TRUE;
 }
 
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
@@ -2724,10 +2728,6 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
 	clear_blocked(adapter);
 	load_devices(adapter);
 
-	/* Set pairable mode */
-	if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
-		adapter->pairable = TRUE;
-
 	/* retrieve the active connections: address the scenario where
 	 * the are active connections before the daemon've started */
 	load_connections(adapter);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 04/10] adapter: Read device class in storage at init
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8b9af28..93dc0fb 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -117,6 +117,7 @@ struct service_auth {
 
 struct btd_adapter_config {
 	char *name;
+	uint8_t class[3];
 };
 
 struct btd_adapter {
@@ -729,6 +730,10 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)
 	if (class == adapter->dev_class)
 		return;
 
+	adapter->config.class[0] = new_class[0];
+	adapter->config.class[1] = new_class[1];
+	adapter->config.class[2] = new_class[2];
+
 	write_local_class(&adapter->bdaddr, new_class);
 
 	adapter->dev_class = class;
@@ -2353,15 +2358,8 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
 void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
 								uint8_t *minor)
 {
-	uint8_t cls[3];
-
-	if (read_local_class(&adapter->bdaddr, cls) < 0) {
-		uint32_t class = htobl(main_opts.class);
-		memcpy(cls, &class, 3);
-	}
-
-	*major = cls[1];
-	*minor = cls[0];
+	*major = adapter->config.class[1];
+	*minor = adapter->config.class[0];
 }
 
 uint32_t btd_adapter_get_class(struct btd_adapter *adapter)
@@ -2694,6 +2692,11 @@ static void load_config(struct btd_adapter *adapter)
 	else
 		adapter->config.name = g_strdup(name);
 
+	/* Get class */
+	if (read_local_class(&adapter->bdaddr, adapter->config.class) < 0) {
+		uint32_t class = htobl(main_opts.class);
+		memcpy(adapter->config.class, &class, 3);
+	}
 }
 
 gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 03/10] adaptername: Retrieve config name from adapter
From: Frédéric Danis @ 2012-10-10 14:10 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1349878219-14359-1-git-send-email-frederic.danis@linux.intel.com>

Retrieve saved config name using adapter_get_config_name() instead
of reading it from storage file.
---
 plugins/adaptername.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index f58fb0f..46dbbe8 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -198,7 +198,8 @@ static void set_pretty_name(struct btd_adapter *adapter,
 static int adaptername_probe(struct btd_adapter *adapter)
 {
 	int current_id;
-	char name[MAX_NAME_LENGTH + 1];
+	char *name;
+	char str[MAX_NAME_LENGTH + 1];
 	char *pretty_hostname;
 
 	pretty_hostname = read_pretty_host_name();
@@ -211,8 +212,10 @@ static int adaptername_probe(struct btd_adapter *adapter)
 	adapter_set_allow_name_changes(adapter, TRUE);
 	current_id = adapter_get_dev_id(adapter);
 
-	if (read_local_name(adapter_get_address(adapter), name) < 0)
-		expand_name(name, MAX_NAME_LENGTH, main_opts.name, current_id);
+	if (adapter_get_config_name(adapter, &name) < 0) {
+		expand_name(str, MAX_NAME_LENGTH, main_opts.name, current_id);
+		name = str;
+	}
 
 	DBG("Setting name '%s' for device 'hci%d'", name, current_id);
 	adapter_set_name(adapter, name);
-- 
1.7.9.5


^ permalink raw reply related


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