Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 4/5] core: Remove mode session code
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Mode session no longer are needed since RequestSession is gone
---
 src/adapter.c | 210 +++++-----------------------------------------------------
 1 file changed, 15 insertions(+), 195 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 2d81f66..b15c8b7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -89,8 +89,6 @@ static const char *base_path = "/org/bluez";
 static GSList *adapter_drivers = NULL;
 
 enum session_req_type {
-	SESSION_TYPE_MODE_GLOBAL = 0,
-	SESSION_TYPE_MODE_SESSION,
 	SESSION_TYPE_DISC_INTERLEAVED,
 	SESSION_TYPE_DISC_LE_SCAN
 };
@@ -99,10 +97,8 @@ struct session_req {
 	struct btd_adapter	*adapter;
 	enum session_req_type	type;
 	DBusMessage		*msg;		/* Unreplied message ref */
-	GDBusPendingPropertySet prop_id;	/* Pending Properties.Set() */
 	char			*owner;		/* Bus name of the owner */
 	guint			id;		/* Listener id */
-	uint8_t			mode;		/* Requested mode */
 	int			refcount;	/* Session refcount */
 	gboolean		got_reply;	/* Agent reply received */
 };
@@ -135,16 +131,12 @@ struct btd_adapter {
 	uint32_t discov_timeout;	/* discoverable time(sec) */
 	guint pairable_timeout_id;	/* pairable timeout id */
 	uint32_t pairable_timeout;	/* pairable time(sec) */
-	uint8_t mode;			/* off, connectable, discoverable,
-					 * limited */
-	uint8_t global_mode;		/* last valid global mode */
 	struct session_req *pending_mode;
 	guint auth_idle_id;		/* Pending authorization dequeue */
 	GQueue *auths;			/* Ongoing and pending auths */
 	GSList *connections;		/* Connected devices */
 	GSList *devices;		/* Devices structure pointers */
 	guint	remove_temp;		/* Remove devices timer */
-	GSList *mode_sessions;		/* Request Mode sessions */
 	GSList *disc_sessions;		/* Discovery sessions */
 	struct session_req *scanning_session;
 	GSList *connect_list;		/* Devices to connect when found */
@@ -181,20 +173,6 @@ int btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major,
 	return mgmt_set_dev_class(adapter->dev_id, major, minor);
 }
 
-static const char *mode2str(uint8_t mode)
-{
-	switch(mode) {
-	case MODE_OFF:
-		return "off";
-	case MODE_CONNECTABLE:
-		return "connectable";
-	case MODE_DISCOVERABLE:
-		return "discoverable";
-	default:
-		return "unknown";
-	}
-}
-
 static uint8_t get_mode(const char *mode)
 {
 	if (strcasecmp("off", mode) == 0)
@@ -288,16 +266,15 @@ static struct session_req *session_ref(struct session_req *req)
 }
 
 static struct session_req *create_session(struct btd_adapter *adapter,
-					DBusMessage *msg, uint8_t mode,
-					enum session_req_type type,
-					GDBusWatchFunction cb)
+						DBusMessage *msg,
+						enum session_req_type type,
+						GDBusWatchFunction cb)
 {
 	const char *sender;
 	struct session_req *req;
 
 	req = g_new0(struct session_req, 1);
 	req->adapter = adapter;
-	req->mode = mode;
 	req->type = type;
 
 	if (msg == NULL)
@@ -313,56 +290,11 @@ static struct session_req *create_session(struct btd_adapter *adapter,
 	req->id = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
 							sender, cb, req, NULL);
 
-	info("%s session %p with %s activated",
-		req->mode ? "Mode" : "Discovery", req, sender);
+	info("session %p with %s activated", req, sender);
 
 	return session_ref(req);
 }
 
-static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
-{
-	int err;
-
-	if (adapter->pending_mode != NULL)
-		return -EALREADY;
-
-	if (!adapter->powered && new_mode != MODE_OFF) {
-		err = mgmt_set_powered(adapter->dev_id, TRUE);
-		if (err < 0)
-			return err;
-
-		goto done;
-	}
-
-	if (adapter->powered && new_mode == MODE_OFF) {
-		err = mgmt_set_powered(adapter->dev_id, FALSE);
-		if (err < 0)
-			return err;
-
-		adapter->off_requested = TRUE;
-
-		goto done;
-	}
-
-	if (new_mode == adapter->mode)
-		return 0;
-
-	if (new_mode == MODE_CONNECTABLE)
-		err = mgmt_set_discoverable(adapter->dev_id, FALSE, 0);
-	else
-		err = mgmt_set_discoverable(adapter->dev_id, TRUE,
-						adapter->discov_timeout);
-	if (err < 0)
-		return err;
-
-done:
-	store_adapter_info(adapter);
-
-	DBG("%s", mode2str(new_mode));
-
-	return 0;
-}
-
 static void set_discoverable(struct btd_adapter *adapter,
 			gboolean discoverable, GDBusPendingPropertySet id)
 {
@@ -386,6 +318,8 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
 
 	if (powered == FALSE)
 		adapter->off_requested = TRUE;
+
+	g_dbus_pending_property_success(id);
 }
 
 static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
@@ -453,23 +387,6 @@ static struct session_req *find_session(GSList *list, const char *sender)
 	return NULL;
 }
 
-static uint8_t get_needed_mode(struct btd_adapter *adapter, uint8_t mode)
-{
-	GSList *l;
-
-	if (adapter->global_mode > mode)
-		mode = adapter->global_mode;
-
-	for (l = adapter->mode_sessions; l; l = l->next) {
-		struct session_req *req = l->data;
-
-		if (req->mode > mode)
-			mode = req->mode;
-	}
-
-	return mode;
-}
-
 static void send_devices_found(struct btd_adapter *adapter)
 {
 	struct discovery *discovery = adapter->discovery;
@@ -565,38 +482,16 @@ static void session_remove(struct session_req *req)
 {
 	struct btd_adapter *adapter = req->adapter;
 
-	/* Ignore global requests */
-	if (req->type == SESSION_TYPE_MODE_GLOBAL)
-		return;
-
-	DBG("%s session %p with %s deactivated",
-		req->mode ? "Mode" : "Discovery", req, req->owner);
-
-	if (req->mode) {
-		uint8_t mode;
+	DBG("session %p with %s deactivated", req, req->owner);
 
-		adapter->mode_sessions = g_slist_remove(adapter->mode_sessions,
-							req);
+	adapter->disc_sessions = g_slist_remove(adapter->disc_sessions, req);
 
-		mode = get_needed_mode(adapter, adapter->global_mode);
-
-		if (mode == adapter->mode)
-			return;
-
-		DBG("Switching to '%s' mode", mode2str(mode));
-
-		set_mode(adapter, mode);
-	} else {
-		adapter->disc_sessions = g_slist_remove(adapter->disc_sessions,
-							req);
-
-		if (adapter->disc_sessions)
-			return;
+	if (adapter->disc_sessions)
+		return;
 
-		DBG("Stopping discovery");
+	DBG("Stopping discovery");
 
-		stop_discovery(adapter);
-	}
+	stop_discovery(adapter);
 }
 
 static void session_free(void *data)
@@ -1000,7 +895,7 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
 		return btd_error_failed(msg, strerror(-err));
 
 done:
-	req = create_session(adapter, msg, 0, SESSION_TYPE_DISC_INTERLEAVED,
+	req = create_session(adapter, msg, SESSION_TYPE_DISC_INTERLEAVED,
 							session_owner_exit);
 
 	adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
@@ -1701,8 +1596,7 @@ void adapter_connect_list_add(struct btd_adapter *adapter,
 	if (adapter->disc_sessions == NULL)
 		adapter->discov_id = g_idle_add(discovery_cb, adapter);
 
-	req = create_session(adapter, NULL, 0, SESSION_TYPE_DISC_LE_SCAN,
-									NULL);
+	req = create_session(adapter, NULL, SESSION_TYPE_DISC_LE_SCAN, NULL);
 	adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
 	adapter->scanning_session = req;
 }
@@ -1738,8 +1632,7 @@ void btd_adapter_start(struct btd_adapter *adapter)
 					adapter->disc_sessions != NULL)
 		return;
 
-	req = create_session(adapter, NULL, 0, SESSION_TYPE_DISC_LE_SCAN,
-									NULL);
+	req = create_session(adapter, NULL, SESSION_TYPE_DISC_LE_SCAN, NULL);
 	adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
 	adapter->scanning_session = req;
 
@@ -1792,57 +1685,6 @@ static void unload_drivers(struct btd_adapter *adapter)
 	adapter->profiles = NULL;
 }
 
-static void set_mode_complete(struct btd_adapter *adapter)
-{
-	DBusConnection *conn = btd_get_dbus_connection();
-	struct session_req *pending;
-	int err;
-
-	DBG("%s", mode2str(adapter->mode));
-
-	if (adapter->mode == MODE_OFF) {
-		g_slist_free_full(adapter->mode_sessions, session_free);
-		adapter->mode_sessions = NULL;
-	}
-
-	if (adapter->pending_mode == NULL)
-		return;
-
-	pending = adapter->pending_mode;
-	adapter->pending_mode = NULL;
-
-	err = (pending->mode != adapter->mode) ? -EINVAL : 0;
-
-	if (pending->type == SESSION_TYPE_MODE_GLOBAL) {
-		if (err < 0)
-			g_dbus_pending_property_error(pending->prop_id,
-						ERROR_INTERFACE ".Failed",
-						strerror(-err));
-		else {
-			adapter->global_mode = adapter->mode;
-			g_dbus_pending_property_success(pending->prop_id);
-		}
-	} else if (pending->msg != NULL) {
-		DBusMessage *msg = pending->msg;
-		DBusMessage *reply;
-
-		if (err < 0)
-			reply = btd_error_failed(msg, strerror(-err));
-		else
-			reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-
-		g_dbus_send_message(conn, reply);
-	}
-
-	if (err != 0)
-		error("unable to set mode: %s", mode2str(pending->mode));
-
-	if (adapter->mode != MODE_DISCOVERABLE || adapter->discov_timeout == 0)
-		store_adapter_info(adapter);
-
-	session_unref(pending);
-}
-
 int btd_adapter_stop(struct btd_adapter *adapter)
 {
 	DBusConnection *conn = btd_get_dbus_connection();
@@ -1878,7 +1720,6 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 	adapter->discoverable = FALSE;
 	adapter->connectable = false;
 
-	adapter->mode = MODE_OFF;
 	adapter->off_requested = FALSE;
 
 	if (emit_discoverable)
@@ -1897,8 +1738,6 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 
 	info("Adapter %s has been disabled", adapter->path);
 
-	set_mode_complete(adapter);
-
 	return 0;
 }
 
@@ -2710,8 +2549,6 @@ static void load_config(struct btd_adapter *adapter)
 		gerr = NULL;
 	}
 
-	adapter->mode = MODE_OFF;
-
 	mgmt_set_connectable(adapter->dev_id, TRUE);
 	mgmt_set_discoverable(adapter->dev_id, adapter->discoverable,
 				adapter->discov_timeout);
@@ -3089,17 +2926,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	}
 }
 
-static uint8_t create_mode(bool connectable, bool discoverable)
-{
-	if (connectable && discoverable)
-		return MODE_DISCOVERABLE;
-
-	if (connectable && !discoverable)
-		return MODE_CONNECTABLE;
-
-	return MODE_OFF;
-}
-
 void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 							bool discoverable)
 {
@@ -3118,7 +2944,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 
 	adapter->connectable = connectable;
 	adapter->discoverable = discoverable;
-	adapter->mode = create_mode(connectable, discoverable);
 
 	if (emit_pairable)
 		g_dbus_emit_property_changed(btd_get_dbus_connection(),
@@ -3126,8 +2951,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
 					ADAPTER_INTERFACE, "Discoverable");
-
-	set_mode_complete(adapter);
 }
 
 struct agent *adapter_get_agent(struct btd_adapter *adapter)
@@ -3385,9 +3208,6 @@ int btd_adapter_restore_powered(struct btd_adapter *adapter)
 	if (adapter->powered)
 		return 0;
 
-	if (adapter->mode == MODE_OFF)
-		return 0;
-
 	return mgmt_set_powered(adapter->dev_id, TRUE);
 }
 
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 3/5] core: Simplify set_powered to not use set_mode
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/src/adapter.c b/src/adapter.c
index ce4e44e..2d81f66 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -373,28 +373,19 @@ static void set_discoverable(struct btd_adapter *adapter,
 static void set_powered(struct btd_adapter *adapter, gboolean powered,
 						GDBusPendingPropertySet id)
 {
-	uint8_t mode;
 	int err;
 
-	if (powered)
-		return set_discoverable(adapter, adapter->discoverable, id);
-
-	mode = MODE_OFF;
-
-	if (mode == adapter->mode) {
-		adapter->global_mode = mode;
+	if (adapter->powered == powered)
 		return g_dbus_pending_property_success(id);
-	}
 
-	err = set_mode(adapter, mode);
+	err = mgmt_set_powered(adapter->dev_id, powered);
 	if (err < 0)
 		return g_dbus_pending_property_error(id,
 						ERROR_INTERFACE ".Failed",
-						strerror(-err));
+						strerror(err));
 
-	adapter->pending_mode = create_session(adapter, NULL, mode,
-					SESSION_TYPE_MODE_GLOBAL, NULL);
-	adapter->pending_mode->prop_id = id;
+	if (powered == FALSE)
+		adapter->off_requested = TRUE;
 }
 
 static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 2/5] core: Fix set_discoverable to not attempt to power on the adapter
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Discoverable flag is completely independent flag for the kernel so we
can reflect this in the D-Bus API.
---
 src/adapter.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 375bff4..ce4e44e 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -366,25 +366,8 @@ done:
 static void set_discoverable(struct btd_adapter *adapter,
 			gboolean discoverable, GDBusPendingPropertySet id)
 {
-	uint8_t mode;
-	int err;
-
-	mode = discoverable ? MODE_DISCOVERABLE : MODE_CONNECTABLE;
-
-	if (mode == adapter->mode) {
-		adapter->global_mode = mode;
-		return g_dbus_pending_property_success(id);
-	}
-
-	err = set_mode(adapter, mode);
-	if (err < 0)
-		return g_dbus_pending_property_error(id,
-						ERROR_INTERFACE ".Failed",
-						strerror(-err));
-
-	adapter->pending_mode = create_session(adapter, NULL, mode,
-					SESSION_TYPE_MODE_GLOBAL, NULL);
-	adapter->pending_mode->prop_id = id;
+	mgmt_set_discoverable(adapter->dev_id, discoverable, 0);
+	g_dbus_pending_property_success(id);
 }
 
 static void set_powered(struct btd_adapter *adapter, gboolean powered,
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 1/5] core: Fix set_pairable to not attempt to power on the adapter
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Pairable flag is completely independent flag for the kernel so we can
reflect this in the D-Bus API.
---
 src/adapter.c | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 96a23e9..375bff4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -417,29 +417,9 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
 static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
 				bool reply, GDBusPendingPropertySet id)
 {
-	int err;
-
-	if (!adapter->connectable)
-		return g_dbus_pending_property_error(id,
-						ERROR_INTERFACE ".NotReady",
-						"Resource Not Ready");
-
 	if (pairable == adapter->pairable)
 		goto done;
 
-	if (!adapter->discoverable)
-		goto store;
-
-	err = set_mode(adapter, MODE_DISCOVERABLE);
-	if (err < 0) {
-		if (reply)
-			g_dbus_pending_property_error(id,
-						ERROR_INTERFACE ".Failed",
-						strerror(-err));
-		return;
-	}
-
-store:
 	mgmt_set_pairable(adapter->dev_id, pairable);
 
 done:
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH 13/13] TODO: Mark convert storage to ini-file item as done
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 TODO |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/TODO b/TODO
index 5a70e40..f0e494f 100644
--- a/TODO
+++ b/TODO
@@ -60,11 +60,10 @@ BlueZ 5
 Priority/Complexity omitted as all items are required before 5.0 is
 released.
 
-- [pending] Convert storage to user per-remote device directories and
-  ini-file format
-
 Completed items:
 
+- Convert storage to user per-remote device directories and ini-file format
+
 - Don't install libbluetooth by default (put it behind a configure switch)
 
 - Switch plugins to standard D-Bus properties interface
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 12/13] bluetoothd: Remove storage info from man page
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/bluetoothd.8.in |   50 --------------------------------------------------
 1 file changed, 50 deletions(-)

diff --git a/src/bluetoothd.8.in b/src/bluetoothd.8.in
index a7ae77b..a89f02c 100644
--- a/src/bluetoothd.8.in
+++ b/src/bluetoothd.8.in
@@ -37,55 +37,5 @@ Use specific MTU size for SDP server.
 .I @CONFIGDIR@/main.conf
 Default location of the global configuration file.
 
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/linkkeys
-Default location for link keys of paired devices. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fInnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\fP Link key.
-
-\fIn\fP Link type integer.
-
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/names
-Default location for the device name cache. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fIname\fP Remote device name, terminated with newline.
-
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/features
-Default location for the features cache. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fInnnnnnnnnnnnnnnn\fP Remote device LMP features coded as an 8 byte bitfield.
-
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/manufacturers
-Default location for the manufacturers cache. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fIn\fP Remote device manufacturer integer.
-
-\fIn\fP Remote device LMP version integer.
-
-\fIn\fP Remote device LMP sub-version integer.
-
 .SH "AUTHOR"
 This manual page was written by Marcel Holtmann, Philipp Matthias Hahn and Fredrik Noring.
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 11/13] adapter: Fix invalid read in conversions
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

==8664== Invalid read of size 1
==8664==    at 0x45B214: convert_entry (adapter.c:2325)
==8664==    by 0x456A44: textfile_foreach (textfile.c:464)
==8664==    by 0x45A823: convert_file (adapter.c:2387)
==8664==    by 0x45ABDE: convert_device_storage (adapter.c:2869)
==8664==    by 0x45F6CE: adapter_init (adapter.c:3043)
==8664==    by 0x4594D9: btd_manager_register_adapter (manager.c:176)
==8664==    by 0x46DB3E: mgmt_event.part.38 (mgmt.c:1206)
==8664==    by 0x4E79D52: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
==8664==    by 0x4E7A09F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
==8664==    by 0x4E7A499: g_main_loop_run (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
==8664==    by 0x409D53: main (main.c:513)
==8664==  Address 0x60b99c1 is not stack'd, malloc'd or (recently) free'd
==8664==
---
 src/adapter.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index dd1b0b1..ab86b83 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2204,7 +2204,7 @@ static void convert_entry(char *key, char *value, void *user_data)
 	char *data;
 	gsize length = 0;
 
-	if (key[17] == '#') {
+	if (strchr(key, '#')) {
 		key[17] = '\0';
 		type = key[18] - '0';
 	}
@@ -2446,7 +2446,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data)
 	char *data;
 	gsize length = 0;
 
-	if (key[17] == '#') {
+	if (strchr(key, '#')) {
 		key[17] = '\0';
 		device_type = key[18] - '0';
 	}
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 10/13] adapter: Remove support of pincodes storage file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

This is no more supported in new storage.
---
 src/adapter.c |    3 +--
 src/storage.c |   20 --------------------
 src/storage.h |    1 -
 3 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 581c528..dd1b0b1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3594,8 +3594,7 @@ ssize_t btd_adapter_get_pin(struct btd_adapter *adapter, struct btd_device *dev,
 			return ret;
 	}
 
-	return read_pin_code(&adapter->bdaddr, device_get_address(dev),
-								pin_buf);
+	return -1;
 }
 
 int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,
diff --git a/src/storage.c b/src/storage.c
index 35049f1..375974a 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -144,26 +144,6 @@ int read_local_name(const bdaddr_t *bdaddr, char *name)
 	return 0;
 }
 
-ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
-{
-	char filename[PATH_MAX + 1], addr[18], *str;
-	ssize_t len;
-
-	create_filename(filename, PATH_MAX, local, "pincodes");
-
-	ba2str(peer, addr);
-	str = textfile_get(filename, addr);
-	if (!str)
-		return -ENOENT;
-
-	strncpy(pin, str, 16);
-	len = strlen(pin);
-
-	free(str);
-
-	return len;
-}
-
 sdp_record_t *record_from_string(const gchar *str)
 {
 	sdp_record_t *rec;
diff --git a/src/storage.h b/src/storage.h
index 9a9c82f..8d171b0 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -27,7 +27,6 @@ int read_discoverable_timeout(const char *src, int *timeout);
 int read_pairable_timeout(const char *src, int *timeout);
 int read_on_mode(const char *src, char *mode, int length);
 int read_local_name(const bdaddr_t *bdaddr, char *name);
-ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
 sdp_record_t *record_from_string(const gchar *str);
 sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
 int read_device_pairable(const bdaddr_t *local, gboolean *mode);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 09/13] proximity: Use new storage architecture
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 profiles/proximity/monitor.c |   72 ++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index d9ed3ff..0be0ae4 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -83,51 +83,52 @@ struct monitor {
 	guint attioid;
 };
 
-static inline int create_filename(char *buf, size_t size,
-				const bdaddr_t *bdaddr, const char *name)
+static void write_proximity_config(struct btd_device *device, const char *alert,
+					const char *level)
 {
-	char addr[18];
+	char *filename;
+	GKeyFile *key_file;
+	char *data;
+	gsize length = 0;
 
-	ba2str(bdaddr, addr);
+	filename = btd_device_get_storage_path(device, "proximity");
 
-	return create_name(buf, size, STORAGEDIR, addr, name);
-}
-
-static int write_proximity_config(const bdaddr_t *sba, const bdaddr_t *dba,
-					const char *alert, const char *level)
-{
-	char filename[PATH_MAX + 1], addr[18], key[38];
-
-	create_filename(filename, PATH_MAX, sba, "proximity");
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+	if (level)
+		g_key_file_set_string(key_file, alert, "Level", level);
+	else
+		g_key_file_remove_group(key_file, alert, NULL);
 
-	ba2str(dba, addr);
-
-	snprintf(key, sizeof(key), "%17s#%s", addr, alert);
+	data = g_key_file_to_data(key_file, &length, NULL);
+	if (length > 0) {
+		create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+		g_file_set_contents(filename, data, length, NULL);
+	}
 
-	return textfile_put(filename, key, level);
+	g_free(data);
+	g_free(filename);
+	g_key_file_free(key_file);
 }
 
-static char *read_proximity_config(const bdaddr_t *sba, const bdaddr_t *dba,
-							const char *alert)
+static char *read_proximity_config(struct btd_device *device, const char *alert)
 {
-	char filename[PATH_MAX + 1], addr[18], key[38];
-	char *str, *strnew;
+	char *filename;
+	GKeyFile *key_file;
+	char *str;
 
-	create_filename(filename, PATH_MAX, sba, "proximity");
+	filename = btd_device_get_storage_path(device, "proximity");
 
-	ba2str(dba, addr);
-	snprintf(key, sizeof(key), "%17s#%s", addr, alert);
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
-	str = textfile_caseget(filename, key);
-	if (str == NULL)
-		return NULL;
+	str = g_key_file_get_string(key_file, alert, "Level", NULL);
 
-	strnew = g_strdup(str);
-	free(str);
+	g_free(filename);
+	g_key_file_free(key_file);
 
-	return strnew;
+	return str;
 }
 
 static uint8_t str2level(const char *level)
@@ -417,7 +418,6 @@ static void property_set_link_loss_level(const GDBusPropertyTable *property,
 		DBusMessageIter *iter, GDBusPendingPropertySet id, void *data)
 {
 	struct monitor *monitor = data;
-	struct btd_device *device = monitor->device;
 	const char *level;
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
@@ -438,9 +438,7 @@ static void property_set_link_loss_level(const GDBusPropertyTable *property,
 	g_free(monitor->linklosslevel);
 	monitor->linklosslevel = g_strdup(level);
 
-	write_proximity_config(adapter_get_address(device_get_adapter(device)),
-					device_get_address(device),
-					"LinkLossAlertLevel", level);
+	write_proximity_config(monitor->device, "LinkLossAlertLevel", level);
 
 	if (monitor->attrib)
 		write_alert_level(monitor);
@@ -601,9 +599,7 @@ int monitor_register(struct btd_device *device,
 	struct monitor *monitor;
 	char *level;
 
-	level = read_proximity_config(
-			adapter_get_address(device_get_adapter(device)),
-			device_get_address(device), "LinkLossAlertLevel");
+	level = read_proximity_config(device, "LinkLossAlertLevel");
 
 	monitor = g_new0(struct monitor, 1);
 	monitor->device = btd_device_ref(device);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 08/13] adapter: Convert proximity file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

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

diff --git a/src/adapter.c b/src/adapter.c
index 1417a85..581c528 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2614,6 +2614,54 @@ static void convert_gatt_entry(char *key, char *value, void *user_data)
 	g_key_file_free(key_file);
 }
 
+static void convert_proximity_entry(char *key, char *value, void *user_data)
+{
+	char *src_addr = user_data;
+	char *alert;
+	char filename[PATH_MAX + 1];
+	GKeyFile *key_file;
+	struct stat st;
+	int err;
+	char *data;
+	gsize length = 0;
+
+	if (!strchr(key, '#'))
+		return;
+
+	key[17] = '\0';
+	alert = &key[18];
+
+	if (bachk(key) != 0)
+		return;
+
+	/* Check if the device directory has been created as records should
+	 * only be converted for known devices */
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, key);
+	filename[PATH_MAX] = '\0';
+
+	err = stat(filename, &st);
+	if (err || !S_ISDIR(st.st_mode))
+		return;
+
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/proximity", src_addr,
+									key);
+	filename[PATH_MAX] = '\0';
+
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+	g_key_file_set_string(key_file, alert, "Level", value);
+
+	data = g_key_file_to_data(key_file, &length, NULL);
+	if (length > 0) {
+		create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+		g_file_set_contents(filename, data, length, NULL);
+	}
+
+	g_free(data);
+	g_key_file_free(key_file);
+}
+
 static void convert_device_storage(struct btd_adapter *adapter)
 {
 	char filename[PATH_MAX + 1];
@@ -2713,6 +2761,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
 		textfile_put(filename, "converted", "yes");
 	}
 	free(str);
+
+	/* Convert proximity */
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/proximity", address);
+	filename[PATH_MAX] = '\0';
+
+	str = textfile_get(filename, "converted");
+	if (str && strcmp(str, "yes") == 0) {
+		DBG("Legacy %s file already converted", filename);
+	} else {
+		textfile_foreach(filename, convert_proximity_entry, address);
+		textfile_put(filename, "converted", "yes");
+	}
+	free(str);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 07/13] gatt: Use new storage architecture
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 profiles/gatt/gas.c |   80 +++++++++++++++++++++++----------------------------
 1 file changed, 36 insertions(+), 44 deletions(-)

diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index 2c1dc83..c9353f6 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -77,60 +77,58 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
 	return (gas->device == device ? 0 : -1);
 }
 
-static inline int create_filename(char *buf, size_t size,
-				const bdaddr_t *bdaddr, const char *name)
-{
-	char addr[18];
-
-	ba2str(bdaddr, addr);
-
-	return create_name(buf, size, STORAGEDIR, addr, name);
-}
-
-static int write_ctp_handle(const bdaddr_t *sba, const bdaddr_t *dba,
-					uint8_t bdaddr_type, uint16_t uuid,
+static void write_ctp_handle(struct btd_device *device, uint16_t uuid,
 					uint16_t handle)
 {
-	char filename[PATH_MAX + 1], addr[18], key[27], value[7];
+	char *filename, group[6], value[7];
+	GKeyFile *key_file;
+	char *data;
+	gsize length = 0;
 
-	create_filename(filename, PATH_MAX, sba, "gatt");
+	filename = btd_device_get_storage_path(device, "gatt");
 
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
-	ba2str(dba, addr);
+	snprintf(group, sizeof(group), "%hu", uuid);
+	snprintf(value, sizeof(value), "0x%4.4X", handle);
+	g_key_file_set_string(key_file, group, "Value", value);
 
-	snprintf(key, sizeof(key), "%17s#%hhu#0x%4.4x", addr, bdaddr_type,
-									uuid);
-	snprintf(value, sizeof(value), "0x%4.4x", handle);
+	data = g_key_file_to_data(key_file, &length, NULL);
+	if (length > 0) {
+		create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+		g_file_set_contents(filename, data, length, NULL);
+	}
 
-	return textfile_put(filename, key, value);
+	g_free(data);
+	g_free(filename);
+	g_key_file_free(key_file);
 }
 
-static int read_ctp_handle(const bdaddr_t *sba, const bdaddr_t *dba,
-					uint8_t bdaddr_type, uint16_t uuid,
+static int read_ctp_handle(struct btd_device *device, uint16_t uuid,
 					uint16_t *value)
 {
-	char filename[PATH_MAX + 1], addr[18], key[27];
+	char *filename, group[6];
+	GKeyFile *key_file;
 	char *str;
+	int err = 0;
 
-	create_filename(filename, PATH_MAX, sba, "gatt");
+	filename = btd_device_get_storage_path(device, "gatt");
 
-	ba2str(dba, addr);
-	snprintf(key, sizeof(key), "%17s#%hhu#0x%04x", addr, bdaddr_type,
-									uuid);
+	snprintf(group, sizeof(group), "%hu", uuid);
 
-	str = textfile_get(filename, key);
-	if (str == NULL)
-		return -errno;
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
-	if (sscanf(str, "%hx", value) != 1) {
-		free(str);
-		return -ENOENT;
-	}
+	str = g_key_file_get_string(key_file, group, "Value", NULL);
+	if (str == NULL || sscanf(str, "%hx", value) != 1)
+		err = -ENOENT;
 
-	free(str);
+	g_free(str);
+	g_free(filename);
+	g_key_file_free(key_file);
 
-	return 0;
+	return err;
 }
 
 static void gap_appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
@@ -214,10 +212,7 @@ static void ccc_written_cb(guint8 status, const guint8 *pdu, guint16 plen,
 						gas->changed_handle,
 						indication_cb, gas, NULL);
 
-	write_ctp_handle(adapter_get_address(device_get_adapter(gas->device)),
-					device_get_address(gas->device),
-					device_get_addr_type(gas->device),
-					GATT_CHARAC_SERVICE_CHANGED,
+	write_ctp_handle(gas->device, GATT_CHARAC_SERVICE_CHANGED,
 					gas->changed_handle);
 }
 
@@ -391,10 +386,7 @@ int gas_register(struct btd_device *device, struct att_range *gap,
 						attio_connected_cb,
 						attio_disconnected_cb, gas);
 
-	read_ctp_handle(adapter_get_address(device_get_adapter(gas->device)),
-					device_get_address(gas->device),
-					device_get_addr_type(gas->device),
-					GATT_CHARAC_SERVICE_CHANGED,
+	read_ctp_handle(gas->device, GATT_CHARAC_SERVICE_CHANGED,
 					&gas->changed_handle);
 
 	return 0;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 06/13] adapter: Convert gatt file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 26950b7..1417a85 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2564,6 +2564,56 @@ static void convert_ccc_entry(char *key, char *value, void *user_data)
 	g_key_file_free(key_file);
 }
 
+static void convert_gatt_entry(char *key, char *value, void *user_data)
+{
+	char *src_addr = user_data;
+	char dst_addr[18];
+	char type = BDADDR_BREDR;
+	int handle, ret;
+	char filename[PATH_MAX + 1];
+	GKeyFile *key_file;
+	struct stat st;
+	int err;
+	char group[6];
+	char *data;
+	gsize length = 0;
+
+	ret = sscanf(key, "%17s#%hhu#%04X", dst_addr, &type, &handle);
+	if (ret < 3)
+		return;
+
+	if (bachk(dst_addr) != 0)
+		return;
+
+	/* Check if the device directory has been created as records should
+	 * only be converted for known devices */
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, dst_addr);
+	filename[PATH_MAX] = '\0';
+
+	err = stat(filename, &st);
+	if (err || !S_ISDIR(st.st_mode))
+		return;
+
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/gatt", src_addr,
+								dst_addr);
+	filename[PATH_MAX] = '\0';
+
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+	sprintf(group, "%hu", handle);
+	g_key_file_set_string(key_file, group, "Value", value);
+
+	data = g_key_file_to_data(key_file, &length, NULL);
+	if (length > 0) {
+		create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+		g_file_set_contents(filename, data, length, NULL);
+	}
+
+	g_free(data);
+	g_key_file_free(key_file);
+}
+
 static void convert_device_storage(struct btd_adapter *adapter)
 {
 	char filename[PATH_MAX + 1];
@@ -2650,6 +2700,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
 
 	/* Convert appearances */
 	convert_file("appearances", address, convert_appearances_entry, FALSE);
+
+	/* Convert gatt */
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/gatt", address);
+	filename[PATH_MAX] = '\0';
+
+	str = textfile_get(filename, "converted");
+	if (str && strcmp(str, "yes") == 0) {
+		DBG("Legacy %s file already converted", filename);
+	} else {
+		textfile_foreach(filename, convert_gatt_entry, address);
+		textfile_put(filename, "converted", "yes");
+	}
+	free(str);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 05/13] device: Load appearance from storage
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

Update adapter_update_found_devices() to store appearance in device.

Remove no more used functions in storage.[ch].
---
 src/adapter.c |    7 +++----
 src/device.c  |   37 +++++++++++++++++++++++--------------
 src/storage.c |   41 -----------------------------------------
 src/storage.h |    4 ----
 4 files changed, 26 insertions(+), 63 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index c95e341..26950b7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3074,10 +3074,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 		return;
 	}
 
-	if (eir_data.appearance != 0)
-		write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
-							eir_data.appearance);
-
 	if (eir_data.name != NULL && eir_data.name_complete)
 		adapter_store_cached_name(&adapter->bdaddr, bdaddr,
 								eir_data.name);
@@ -3101,6 +3097,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	device_set_legacy(dev, legacy);
 	device_set_rssi(dev, rssi);
 
+	if (eir_data.appearance != 0)
+		device_set_appearance(dev, eir_data.appearance);
+
 	if (eir_data.name)
 		device_set_name(dev, eir_data.name);
 
diff --git a/src/device.c b/src/device.c
index 30d5eb9..047c26a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -149,6 +149,7 @@ struct btd_device {
 	uint16_t	vendor;
 	uint16_t	product;
 	uint16_t	version;
+	uint16_t	appearance;
 	struct btd_adapter	*adapter;
 	GSList		*uuids;
 	GSList		*primaries;		/* List of primary services */
@@ -241,6 +242,13 @@ static gboolean store_device_info_cb(gpointer user_data)
 		g_key_file_remove_key(key_file, "General", "Class", NULL);
 	}
 
+	if (device->appearance) {
+		sprintf(class, "0x%4.4x", device->appearance);
+		g_key_file_set_string(key_file, "General", "Appearance", class);
+	} else {
+		g_key_file_remove_key(key_file, "General", "Appearance", NULL);
+	}
+
 	switch (device->bdaddr_type) {
 	case BDADDR_BREDR:
 		g_key_file_set_string(key_file, "General",
@@ -564,10 +572,10 @@ static gboolean get_appearance(const GDBusPropertyTable *property, void *data,
 	if (dev_property_exists_class(property, data))
 		return FALSE;
 
-	if (read_remote_appearance(adapter_get_address(device->adapter),
-					&device->bdaddr, device->bdaddr_type,
-					appearance) == 0)
+	if (device->appearance) {
+		*appearance = device->appearance;
 		return TRUE;
+	}
 
 	return FALSE;
 }
@@ -1745,6 +1753,13 @@ static void load_info(struct btd_device *device, const gchar *local,
 		g_free(str);
 	}
 
+	/* Load appearance */
+	str = g_key_file_get_string(key_file, "General", "Appearance", NULL);
+	if (str) {
+		device->appearance = strtol(str, NULL, 16);
+		g_free(str);
+	}
+
 	/* Load device technology */
 	techno = g_key_file_get_string_list(key_file, "General",
 					"SupportedTechnologies", NULL, NULL);
@@ -4093,17 +4108,11 @@ void btd_device_unref(struct btd_device *device)
 
 int device_get_appearance(struct btd_device *device, uint16_t *value)
 {
-	uint16_t app;
-	int err;
-
-	err = read_remote_appearance(adapter_get_address(device->adapter),
-					&device->bdaddr, device->bdaddr_type,
-					&app);
-	if (err < 0)
-		return err;
+	if (device->appearance == 0)
+		return -1;
 
 	if (value)
-		*value = app;
+		*value = device->appearance;
 
 	return 0;
 }
@@ -4119,8 +4128,8 @@ void device_set_appearance(struct btd_device *device, uint16_t value)
 		g_dbus_emit_property_changed(btd_get_dbus_connection(),
 				device->path, DEVICE_INTERFACE, "Icon");
 
-	write_remote_appearance(adapter_get_address(device->adapter),
-				&device->bdaddr, device->bdaddr_type, value);
+	device->appearance = value;
+	store_device_info(device);
 }
 
 static gboolean notify_attios(gpointer user_data)
diff --git a/src/storage.c b/src/storage.c
index 38e5897..35049f1 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -144,47 +144,6 @@ int read_local_name(const bdaddr_t *bdaddr, char *name)
 	return 0;
 }
 
-int read_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
-				uint8_t bdaddr_type, uint16_t *appearance)
-{
-	char filename[PATH_MAX + 1], key[20], *str;
-
-	create_filename(filename, PATH_MAX, local, "appearances");
-
-	ba2str(peer, key);
-	sprintf(&key[17], "#%hhu", bdaddr_type);
-
-	str = textfile_get(filename, key);
-	if (!str)
-		return -ENOENT;
-
-	if (sscanf(str, "%hx", appearance) != 1) {
-		free(str);
-		return -ENOENT;
-	}
-
-	free(str);
-
-	return 0;
-}
-
-int write_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
-				uint8_t bdaddr_type, uint16_t appearance)
-{
-	char filename[PATH_MAX + 1], key[20], str[7];
-
-	create_filename(filename, PATH_MAX, local, "appearances");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(peer, key);
-	sprintf(&key[17], "#%hhu", bdaddr_type);
-
-	sprintf(str, "0x%4.4x", appearance);
-
-	return textfile_put(filename, key, str);
-}
-
 ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
 {
 	char filename[PATH_MAX + 1], addr[18], *str;
diff --git a/src/storage.h b/src/storage.h
index cc7f930..9a9c82f 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -27,10 +27,6 @@ int read_discoverable_timeout(const char *src, int *timeout);
 int read_pairable_timeout(const char *src, int *timeout);
 int read_on_mode(const char *src, char *mode, int length);
 int read_local_name(const bdaddr_t *bdaddr, char *name);
-int write_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
-				uint8_t bdaddr_type, uint16_t appearance);
-int read_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
-				uint8_t bdaddr_type, uint16_t *appearance);
 ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
 sdp_record_t *record_from_string(const gchar *str);
 sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 04/13] adapter: Convert appearances file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

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

diff --git a/src/adapter.c b/src/adapter.c
index 1279145..c95e341 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2190,6 +2190,11 @@ static void convert_profiles_entry(GKeyFile *key_file, void *value)
 	g_key_file_set_string(key_file, "General", "Services", value);
 }
 
+static void convert_appearances_entry(GKeyFile *key_file, void *value)
+{
+	g_key_file_set_string(key_file, "General", "Appearance", value);
+}
+
 static void convert_entry(char *key, char *value, void *user_data)
 {
 	struct device_converter *converter = user_data;
@@ -2642,6 +2647,9 @@ static void convert_device_storage(struct btd_adapter *adapter)
 		textfile_put(filename, "converted", "yes");
 	}
 	free(str);
+
+	/* Convert appearances */
+	convert_file("appearances", address, convert_appearances_entry, FALSE);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 03/13] doc: Add device appearance in settings-storage doc
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 doc/settings-storage.txt |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index 037e14f..bc60709 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -165,6 +165,9 @@ Long term key) related to a remote device.
   Class			String		Device class in hexadecimal,
 					i.e. 0x000000
 
+  Appearance		String		Device appearance in hexadecimal,
+					i.e. 0x0000
+
   SupportedTechnologies	List of		List of technologies supported by
 			strings		device, separated by ";"
 					Technologies can be BR/EDR or LE
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 02/13] alert: Use ccc file from device storage
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

---
 profiles/alert/server.c |   69 +++++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/profiles/alert/server.c b/profiles/alert/server.c
index 3f7b37e..3736a0b 100644
--- a/profiles/alert/server.c
+++ b/profiles/alert/server.c
@@ -322,29 +322,41 @@ static void watcher_disconnect(DBusConnection *conn, void *user_data)
 	g_slist_foreach(alert_adapters, update_supported_categories, NULL);
 }
 
-static struct btd_device *get_notifiable_device(struct btd_adapter *adapter,
-						char *key, char *value,
-						uint16_t ccc)
+static gboolean is_notifiable_device(struct btd_device *device, uint16_t ccc)
 {
-	struct btd_device *device;
-	char addr[18];
-	uint16_t hnd, val;
-	uint8_t bdaddr_type;
+	char *filename;
+	GKeyFile *key_file;
+	char handle[6];
+	char *str;
+	uint16_t val;
+	gboolean result;
+
+	sprintf(handle, "%hu", ccc);
 
-	sscanf(key, "%17s#%hhu#%04hX", addr, &bdaddr_type, &hnd);
+	filename = btd_device_get_storage_path(device, "ccc");
 
-	if (hnd != ccc)
-		return NULL;
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
-	val = strtol(value, NULL, 16);
-	if (!(val & 0x0001))
-		return NULL;
+	str = g_key_file_get_string(key_file, handle, "Value", NULL);
+	if (!str) {
+		result = FALSE;
+		goto end;
+	}
+
+	val = strtol(str, NULL, 16);
+	if (!(val & 0x0001)) {
+		result = FALSE;
+		goto end;
+	}
 
-	device = adapter_find_device(adapter, addr);
-	if (device == NULL)
-		return NULL;
+	result = TRUE;
+end:
+	g_free(str);
+	g_free(filename);
+	g_key_file_free(key_file);
 
-	return btd_device_ref(device);
+	return result;
 }
 
 static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
@@ -392,40 +404,27 @@ end:
 	g_free(cb);
 }
 
-static void filter_devices_notify(char *key, char *value, void *user_data)
+static void filter_devices_notify(struct btd_device *device, void *user_data)
 {
 	struct notify_data *notify_data = user_data;
 	struct alert_adapter *al_adapter = notify_data->al_adapter;
 	enum notify_type type = notify_data->type;
-	struct btd_device *device;
 	struct notify_callback *cb;
 
-	device = get_notifiable_device(al_adapter->adapter, key, value,
-						al_adapter->hnd_ccc[type]);
-	if (device == NULL)
+	if (!is_notifiable_device(device, al_adapter->hnd_ccc[type]))
 		return;
 
 	cb = g_new0(struct notify_callback, 1);
 	cb->notify_data = notify_data;
-	cb->device = device;
+	cb->device = btd_device_ref(device);
 	cb->id = btd_device_add_attio_callback(device,
 						attio_connected_cb, NULL, cb);
 }
 
-static void create_filename(char *filename, struct btd_adapter *adapter)
-{
-	char srcaddr[18];
-
-	ba2str(adapter_get_address(adapter), srcaddr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "ccc");
-}
-
 static void notify_devices(struct alert_adapter *al_adapter,
 			enum notify_type type, uint8_t *value, size_t len)
 {
 	struct notify_data *notify_data;
-	char filename[PATH_MAX + 1];
 
 	notify_data = g_new0(struct notify_data, 1);
 	notify_data->al_adapter = al_adapter;
@@ -433,8 +432,8 @@ static void notify_devices(struct alert_adapter *al_adapter,
 	notify_data->value = g_memdup(value, len);
 	notify_data->len = len;
 
-	create_filename(filename, al_adapter->adapter);
-	textfile_foreach(filename, filter_devices_notify, notify_data);
+	btd_adapter_for_each_device(al_adapter->adapter, filter_devices_notify,
+					notify_data);
 }
 
 static void pasp_notification(enum notify_type type)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 01/13] adapter: Add btd_adapter_for_each_device()
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
  To: linux-bluetooth

---
 src/adapter.c |    7 +++++++
 src/adapter.h |    4 ++++
 2 files changed, 11 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 96a23e9..1279145 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3635,3 +3635,10 @@ void adapter_read_local_oob_data_complete(struct btd_adapter *adapter,
 	g_free(adapter->oob_handler);
 	adapter->oob_handler = NULL;
 }
+
+void btd_adapter_for_each_device(struct btd_adapter *adapter,
+			void (*cb)(struct btd_device *device, void *data),
+			void *data)
+{
+	g_slist_foreach(adapter->devices, (GFunc) cb, data);
+}
diff --git a/src/adapter.h b/src/adapter.h
index bde76b2..a192a71 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -231,3 +231,7 @@ void btd_adapter_set_oob_handler(struct btd_adapter *adapter,
 gboolean btd_adapter_check_oob_handler(struct btd_adapter *adapter);
 void adapter_store_cached_name(const bdaddr_t *local, const bdaddr_t *peer,
 							const char *name);
+
+void btd_adapter_for_each_device(struct btd_adapter *adapter,
+			void (*cb)(struct btd_device *device, void *data),
+			void *data);
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH 01/11] adapter: Rename btd_adapter *up members to *powered
From: Johan Hedberg @ 2012-12-17 15:00 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Mon, Dec 17, 2012, Szymon Janc wrote:
> This better describes those members purpose.
> ---
>  src/adapter.c | 36 ++++++++++++++++++------------------
>  src/adapter.h |  2 +-
>  2 files changed, 19 insertions(+), 19 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH 11/11] adapter: Remove not used btd_adapter_get_mode
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

This function is not used anymore and adapter mode is now internal to
btd_adapter.
---
 src/adapter.c | 11 +++++------
 src/adapter.h |  7 -------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 035a4ca..96a23e9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -77,6 +77,11 @@
 #define EIR_SIM_HOST                0x10 /* Simultaneous LE and BR/EDR to Same
 					    Device Capable (Host) */
 
+#define MODE_OFF		0x00
+#define MODE_CONNECTABLE	0x01
+#define MODE_DISCOVERABLE	0x02
+#define MODE_UNKNOWN		0xff
+
 #define REMOVE_TEMP_TIMEOUT (3 * 60)
 #define PENDING_FOUND_MAX 5
 
@@ -1692,12 +1697,6 @@ static void load_connections(struct btd_adapter *adapter)
 	g_slist_free_full(conns, g_free);
 }
 
-void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode)
-{
-	if (mode)
-		*mode = adapter->mode;
-}
-
 bool btd_adapter_get_pairable(struct btd_adapter *adapter)
 {
 	return adapter->pairable;
diff --git a/src/adapter.h b/src/adapter.h
index 44ba56a..bde76b2 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -32,11 +32,6 @@
 
 #define ADAPTER_INTERFACE	"org.bluez.Adapter1"
 
-#define MODE_OFF		0x00
-#define MODE_CONNECTABLE	0x01
-#define MODE_DISCOVERABLE	0x02
-#define MODE_UNKNOWN		0xff
-
 #define MAX_NAME_LENGTH		248
 
 /* Invalid SSP passkey value used to indicate negative replies */
@@ -80,8 +75,6 @@ void btd_adapter_start(struct btd_adapter *adapter);
 
 int btd_adapter_stop(struct btd_adapter *adapter);
 
-void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode);
-
 bool btd_adapter_get_pairable(struct btd_adapter *adapter);
 
 void btd_adapter_get_major_minor(struct btd_adapter *adapter, uint8_t *major,
-- 
1.8.0


^ permalink raw reply related

* [PATCH 10/11] mgmt: Remove not needed power state change in read_info_complete
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Initial power state is no longer set up by bluetoothd.
---
 src/mgmt.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/mgmt.c b/src/mgmt.c
index 3c7e014..7e3f670 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -1160,7 +1160,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	struct controller_info *info;
 	struct btd_adapter *adapter;
 	const char *name;
-	uint8_t mode, major, minor;
+	uint8_t major, minor;
 	char addr[18];
 
 	if (len < sizeof(*rp)) {
@@ -1213,18 +1213,9 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	btd_adapter_get_major_minor(adapter, &major, &minor);
 	mgmt_set_dev_class(index, major, minor);
 
-	btd_adapter_get_mode(adapter, &mode);
-	if (mode == MODE_OFF && mgmt_powered(info->current_settings)) {
-		mgmt_set_powered(index, FALSE);
-		return;
-	}
-
-	if (mode != MODE_OFF) {
-		if (mgmt_powered(info->current_settings)) {
-			get_connections(sk, index);
-			btd_adapter_start(adapter);
-		} else
-			mgmt_set_powered(index, TRUE);
+	if (mgmt_powered(info->current_settings)) {
+		get_connections(sk, index);
+		btd_adapter_start(adapter);
 	}
 
 	btd_adapter_unref(adapter);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 09/11] core: Remove mode option form main_opts
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Config option is removed so this is no longer needed.
---
 src/adapter.c | 9 ++-------
 src/hcid.h    | 2 --
 src/main.c    | 1 -
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e97e9bb..035a4ca 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2746,12 +2746,7 @@ static void load_config(struct btd_adapter *adapter)
 
 	/* Get discoverable mode */
 	adapter->discoverable = g_key_file_get_boolean(key_file, "General",
-							"Discoverable", &gerr);
-	if (gerr) {
-		adapter->discoverable = (main_opts.mode == MODE_DISCOVERABLE);
-		g_error_free(gerr);
-		gerr = NULL;
-	}
+							"Discoverable", NULL);
 
 	/* Get discoverable timeout */
 	adapter->discov_timeout = g_key_file_get_integer(key_file, "General",
@@ -2762,7 +2757,7 @@ static void load_config(struct btd_adapter *adapter)
 		gerr = NULL;
 	}
 
-	adapter->mode = main_opts.mode;
+	adapter->mode = MODE_OFF;
 
 	mgmt_set_connectable(adapter->dev_id, TRUE);
 	mgmt_set_discoverable(adapter->dev_id, adapter->discoverable,
diff --git a/src/hcid.h b/src/hcid.h
index 1c3af7d..aa563dc 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -38,8 +38,6 @@ struct main_opts {
 	gboolean	name_resolv;
 	gboolean	debug_keys;
 
-	uint8_t		mode;
-
 	uint16_t	did_source;
 	uint16_t	did_vendor;
 	uint16_t	did_product;
diff --git a/src/main.c b/src/main.c
index 290a0eb..59a0ad9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -230,7 +230,6 @@ static void init_defaults(void)
 {
 	/* Default HCId settings */
 	memset(&main_opts, 0, sizeof(main_opts));
-	main_opts.mode	= MODE_OFF;
 	main_opts.name	= g_strdup("BlueZ");
 	main_opts.discovto	= DEFAULT_DISCOVERABLE_TIMEOUT;
 	main_opts.autoto = DEFAULT_AUTO_CONNECT_TIMEOUT;
-- 
1.8.0


^ permalink raw reply related

* [PATCH 08/11] adapter: Remove scan_mode member
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

This is not needed anymore as boolean flags can be used instead.
---
 src/adapter.c | 68 +++++++++++++++--------------------------------------------
 1 file changed, 17 insertions(+), 51 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 2af0d4f..e97e9bb 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -130,8 +130,6 @@ struct btd_adapter {
 	uint32_t discov_timeout;	/* discoverable time(sec) */
 	guint pairable_timeout_id;	/* pairable timeout id */
 	uint32_t pairable_timeout;	/* pairable time(sec) */
-	uint8_t scan_mode;		/* scan mode: SCAN_DISABLED, SCAN_PAGE,
-					 * SCAN_INQUIRY */
 	uint8_t mode;			/* off, connectable, discoverable,
 					 * limited */
 	uint8_t global_mode;		/* last valid global mode */
@@ -1778,16 +1776,6 @@ void btd_adapter_start(struct btd_adapter *adapter)
 	adapter->off_requested = FALSE;
 	adapter->powered = TRUE;
 
-	if (adapter->scan_mode & SCAN_INQUIRY) {
-		adapter->mode = MODE_DISCOVERABLE;
-		adapter->discoverable = TRUE;
-	} else {
-		adapter->mode = MODE_CONNECTABLE;
-		adapter->discoverable = FALSE;
-	}
-
-	adapter->connectable = true;
-
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
 						ADAPTER_INTERFACE, "Powered");
 
@@ -1934,7 +1922,7 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 	if (adapter->connectable && adapter->pairable == TRUE)
 		emit_pairable = true;
 
-	adapter->scan_mode = SCAN_DISABLED;
+	adapter->discoverable = FALSE;
 	adapter->connectable = false;
 
 	adapter->mode = MODE_OFF;
@@ -3155,56 +3143,34 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 
 static uint8_t create_mode(bool connectable, bool discoverable)
 {
-	uint8_t mode = 0;
-
-	if (connectable)
-		mode |= SCAN_PAGE;
+	if (connectable && discoverable)
+		return MODE_DISCOVERABLE;
 
-	if (discoverable)
-		mode |= SCAN_INQUIRY;
+	if (connectable && !discoverable)
+		return MODE_CONNECTABLE;
 
-	return mode;
+	return MODE_OFF;
 }
 
 void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 							bool discoverable)
 {
-	bool emit_pairable = false;
-	uint8_t scan_mode;
-
-	scan_mode = create_mode(connectable, discoverable);
+	bool emit_pairable;
 
-	DBG("old 0x%02x new 0x%02x", adapter->scan_mode, scan_mode);
+	DBG("connectable %u (old %u) discoverable %u (old %u)",
+					connectable, adapter->connectable,
+					discoverable, adapter->discoverable);
 
-	if (adapter->scan_mode == scan_mode)
+	if (connectable == adapter->connectable &&
+			discoverable == adapter->discoverable)
 		return;
 
-	switch (scan_mode) {
-	case SCAN_DISABLED:
-		adapter->mode = MODE_OFF;
-		adapter->connectable = false;
-		adapter->discoverable = FALSE;
-		break;
-	case SCAN_PAGE:
-		adapter->mode = MODE_CONNECTABLE;
-		adapter->discoverable = FALSE;
-		adapter->connectable = true;
-		break;
-	case (SCAN_PAGE | SCAN_INQUIRY):
-		adapter->mode = MODE_DISCOVERABLE;
-		adapter->discoverable = TRUE;
-		adapter->connectable = true;
-		break;
-	default:
-		/* ignore, reserved */
-		return;
-	}
-
-	/* If page scanning gets toggled emit the Pairable property */
-	if ((adapter->scan_mode & SCAN_PAGE) != (scan_mode & SCAN_PAGE))
-		emit_pairable = true;
+	/* If connectable gets toggled emit the Pairable property */
+	emit_pairable = adapter->connectable != connectable;
 
-	adapter->scan_mode = scan_mode;
+	adapter->connectable = connectable;
+	adapter->discoverable = discoverable;
+	adapter->mode = create_mode(connectable, discoverable);
 
 	if (emit_pairable)
 		g_dbus_emit_property_changed(btd_get_dbus_connection(),
-- 
1.8.0


^ permalink raw reply related

* [PATCH 07/11] adapter: Use discoverable memeber instead of scan_mode
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Where possible use discoverable memeber instead of checking scan_mode
against SCAN_INQUIRY flag.
---
 src/adapter.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 473c9cf..2af0d4f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -424,7 +424,7 @@ static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
 	if (pairable == adapter->pairable)
 		goto done;
 
-	if (!(adapter->scan_mode & SCAN_INQUIRY))
+	if (!adapter->discoverable)
 		goto store;
 
 	err = set_mode(adapter, MODE_DISCOVERABLE);
@@ -687,7 +687,7 @@ static void set_discoverable_timeout(struct btd_adapter *adapter,
 	if (adapter->discov_timeout == timeout && timeout == 0)
 		return g_dbus_pending_property_success(id);
 
-	if (adapter->scan_mode & SCAN_INQUIRY)
+	if (adapter->discoverable)
 		mgmt_set_discoverable(adapter->dev_id, TRUE, timeout);
 
 	adapter->discov_timeout = timeout;
@@ -1163,7 +1163,7 @@ static gboolean adapter_property_get_discoverable(
 	struct btd_adapter *adapter = data;
 	dbus_bool_t value;
 
-	value = adapter->scan_mode & SCAN_INQUIRY ? TRUE : FALSE;
+	value = adapter->discoverable ? TRUE : FALSE;
 	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
 
 	return TRUE;
@@ -1928,7 +1928,7 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 		adapter_remove_connection(adapter, device);
 	}
 
-	if (adapter->scan_mode == (SCAN_PAGE | SCAN_INQUIRY))
+	if (adapter->discoverable)
 		emit_discoverable = true;
 
 	if (adapter->connectable && adapter->pairable == TRUE)
@@ -3183,6 +3183,7 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 	case SCAN_DISABLED:
 		adapter->mode = MODE_OFF;
 		adapter->connectable = false;
+		adapter->discoverable = FALSE;
 		break;
 	case SCAN_PAGE:
 		adapter->mode = MODE_CONNECTABLE;
-- 
1.8.0


^ permalink raw reply related

* [PATCH 06/11] adapter: Add connectable member to btd_adapter
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

This will be used to track if adapter is in connectable state.
---
 src/adapter.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 915d897..473c9cf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -153,6 +153,7 @@ struct btd_adapter {
 	guint auto_timeout_id;		/* Automatic connections timeout */
 	sdp_list_t *services;		/* Services associated to adapter */
 
+	bool connectable;		/* connectable state */
 	gboolean discoverable;		/* discoverable state */
 	gboolean pairable;		/* pairable state */
 	gboolean initialized;
@@ -415,7 +416,7 @@ static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
 {
 	int err;
 
-	if (adapter->scan_mode == SCAN_DISABLED)
+	if (!adapter->connectable)
 		return g_dbus_pending_property_error(id,
 						ERROR_INTERFACE ".NotReady",
 						"Resource Not Ready");
@@ -1785,6 +1786,8 @@ void btd_adapter_start(struct btd_adapter *adapter)
 		adapter->discoverable = FALSE;
 	}
 
+	adapter->connectable = true;
+
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
 						ADAPTER_INTERFACE, "Powered");
 
@@ -1928,10 +1931,12 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 	if (adapter->scan_mode == (SCAN_PAGE | SCAN_INQUIRY))
 		emit_discoverable = true;
 
-	if ((adapter->scan_mode & SCAN_PAGE) && adapter->pairable == TRUE)
+	if (adapter->connectable && adapter->pairable == TRUE)
 		emit_pairable = true;
 
 	adapter->scan_mode = SCAN_DISABLED;
+	adapter->connectable = false;
+
 	adapter->mode = MODE_OFF;
 	adapter->off_requested = FALSE;
 
@@ -3177,14 +3182,17 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 	switch (scan_mode) {
 	case SCAN_DISABLED:
 		adapter->mode = MODE_OFF;
+		adapter->connectable = false;
 		break;
 	case SCAN_PAGE:
 		adapter->mode = MODE_CONNECTABLE;
 		adapter->discoverable = FALSE;
+		adapter->connectable = true;
 		break;
 	case (SCAN_PAGE | SCAN_INQUIRY):
 		adapter->mode = MODE_DISCOVERABLE;
 		adapter->discoverable = TRUE;
+		adapter->connectable = true;
 		break;
 	default:
 		/* ignore, reserved */
-- 
1.8.0


^ permalink raw reply related

* [PATCH 05/11] adapter: Remove not used parameter from btd_adapter_get_mode
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

discoverable_timeout is not used outside of adapter code.
---
 src/adapter.c | 6 +-----
 src/adapter.h | 3 +--
 src/mgmt.c    | 6 ++----
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8f1c229..915d897 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1693,14 +1693,10 @@ static void load_connections(struct btd_adapter *adapter)
 	g_slist_free_full(conns, g_free);
 }
 
-void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
-						uint16_t *discoverable_timeout)
+void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode)
 {
 	if (mode)
 		*mode = adapter->mode;
-
-	if (discoverable_timeout)
-		*discoverable_timeout = adapter->discov_timeout;
 }
 
 bool btd_adapter_get_pairable(struct btd_adapter *adapter)
diff --git a/src/adapter.h b/src/adapter.h
index 125657a..44ba56a 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -80,8 +80,7 @@ void btd_adapter_start(struct btd_adapter *adapter);
 
 int btd_adapter_stop(struct btd_adapter *adapter);
 
-void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
-						uint16_t *discoverable_timeout);
+void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode);
 
 bool btd_adapter_get_pairable(struct btd_adapter *adapter);
 
diff --git a/src/mgmt.c b/src/mgmt.c
index feca194..3c7e014 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -332,12 +332,10 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 {
 	struct controller_info *info;
 	gboolean pairable;
-	uint16_t index, discoverable_timeout;
+	uint16_t index;
 
 	DBG("new settings %x", settings);
 
-	btd_adapter_get_mode(adapter, NULL, &discoverable_timeout);
-
 	index = adapter_get_dev_id(adapter);
 
 	info = &controllers[index];
@@ -1215,7 +1213,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	btd_adapter_get_major_minor(adapter, &major, &minor);
 	mgmt_set_dev_class(index, major, minor);
 
-	btd_adapter_get_mode(adapter, &mode, NULL);
+	btd_adapter_get_mode(adapter, &mode);
 	if (mode == MODE_OFF && mgmt_powered(info->current_settings)) {
 		mgmt_set_powered(index, FALSE);
 		return;
-- 
1.8.0


^ 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