[PATCH 03/18] eir: Store class in struct eir_data as uint32_t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This simplify code as class is stored on storage as uint32_t and
had to be converted to it in few places.

---
 src/adapter.c |   11 ++++-------
 src/eir.c     |    3 ++-
 src/eir.h     |    2 +-
 src/event.c   |   11 +++--------
 src/event.h   |    2 +-
 src/mgmt.c    |    2 +-
 6 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 06ba78c..d34e966 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2929,7 +2929,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	struct eir_data eir_data;
 	char *alias, *name;
 	gboolean legacy, name_known;
-	uint32_t dev_class;
 	int err;
 	GSList *l;
 
@@ -2940,10 +2939,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 		return;
 	}
 
-	dev_class = eir_data.dev_class[0] | (eir_data.dev_class[1] << 8) |
-						(eir_data.dev_class[2] << 16);
-	if (dev_class != 0)
-		write_remote_class(&adapter->bdaddr, bdaddr, dev_class);
+	if (eir_data.class != 0)
+		write_remote_class(&adapter->bdaddr, bdaddr, eir_data.class);
 
 	if (eir_data.appearance != 0)
 		write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
@@ -2999,8 +2996,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	alias = read_stored_data(&adapter->bdaddr, bdaddr, bdaddr_type,
 								"aliases");
 
-	dev = found_device_new(bdaddr, bdaddr_type, name, alias, dev_class,
-						legacy, eir_data.flags);
+	dev = found_device_new(bdaddr, bdaddr_type, name, alias,
+				eir_data.class, legacy, eir_data.flags);
 	free(name);
 	free(alias);
 
diff --git a/src/eir.c b/src/eir.c
index c29be40..4b054ea 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -166,7 +166,8 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
 		case EIR_CLASS_OF_DEV:
 			if (data_len < 3)
 				break;
-			memcpy(eir->dev_class, data, 3);
+			eir->class = data[0] | (data[1] << 8) |
+							(data[2] << 16);
 			break;
 
 		case EIR_GAP_APPEARANCE:
diff --git a/src/eir.h b/src/eir.h
index e6e870a..3a52563 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -47,7 +47,7 @@ struct eir_data {
 	GSList *services;
 	int flags;
 	char *name;
-	uint8_t dev_class[3];
+	uint32_t class;
 	uint16_t appearance;
 	gboolean name_complete;
 	uint8_t *hash;
diff --git a/src/event.c b/src/event.c
index 3b85961..670b79a 100644
--- a/src/event.c
+++ b/src/event.c
@@ -453,7 +453,7 @@ int btd_event_ltk_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
 }
 
 void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
-						char *name, uint8_t *dev_class)
+						char *name, uint32_t class)
 {
 	struct btd_adapter *adapter;
 	struct btd_device *device;
@@ -463,13 +463,8 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_typ
 
 	update_lastused(local, peer, bdaddr_type);
 
-	if (dev_class != NULL) {
-		uint32_t class = dev_class[0] | (dev_class[1] << 8) |
-							(dev_class[2] << 16);
-
-		if (class != 0)
-			write_remote_class(local, peer, class);
-	}
+	if (class != 0)
+		write_remote_class(local, peer, class);
 
 	device_set_addr_type(device, bdaddr_type);
 
diff --git a/src/event.h b/src/event.h
index 7031cc9..6d001dd 100644
--- a/src/event.h
+++ b/src/event.h
@@ -30,7 +30,7 @@ void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean lega
 void btd_event_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
 void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name);
 void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
-					char *name, uint8_t *dev_class);
+						char *name, uint32_t class);
 void btd_event_conn_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
 void btd_event_disconn_complete(bdaddr_t *local, bdaddr_t *peer);
 void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
diff --git a/src/mgmt.c b/src/mgmt.c
index 3f83fdf..ee4cbbe 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -503,7 +503,7 @@ static void mgmt_device_connected(int sk, uint16_t index, void *buf, size_t len)
 	btd_event_conn_complete(&info->bdaddr, &ev->addr.bdaddr,
 						ev->addr.type,
 						eir_data.name,
-						eir_data.dev_class);
+						eir_data.class);
 
 	eir_data_free(&eir_data);
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux