[PATCHv2 27/27] android/hog: Replace definitions of characteristic uuids with bt_uuids

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

 



Instead of using simply define and then convert the uuid values to
bt_uuid everytime the char_discovered_cb is called, it's better to
define these bt_uuids directly.
---
 android/hog.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/android/hog.c b/android/hog.c
index ad047f0..a456b0c 100644
--- a/android/hog.c
+++ b/android/hog.c
@@ -52,12 +52,6 @@
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 
-#define HOG_INFO_UUID		0x2A4A
-#define HOG_REPORT_MAP_UUID	0x2A4B
-#define HOG_REPORT_UUID		0x2A4D
-#define HOG_PROTO_MODE_UUID	0x2A4E
-#define HOG_CONTROL_POINT_UUID	0x2A4C
-
 #define HOG_REPORT_TYPE_INPUT	1
 #define HOG_REPORT_TYPE_OUTPUT	2
 #define HOG_REPORT_TYPE_FEATURE	3
@@ -67,6 +61,17 @@
 
 static bdaddr_t	adapter_addr;
 
+static const bt_uuid_t info_uuid = { .type = BT_UUID16,
+					.value.u16 = 0x2A4A };
+static const bt_uuid_t report_map_uuid = { .type = BT_UUID16,
+					.value.u16 = 0x2A4B };
+static const bt_uuid_t control_point_uuid = { .type = BT_UUID16,
+					.value.u16 = 0x2A4C };
+static const bt_uuid_t report_uuid = { .type = BT_UUID16,
+					.value.u16 = 0x2A4D };
+static const bt_uuid_t protocol_mode_uuid = { .type = BT_UUID16,
+					.value.u16 = 0x2A4E };
+
 struct bt_hog {
 	int			ref_count;
 	uint16_t		service_handle;
@@ -318,7 +323,6 @@ static void external_report_reference_cb(bool success, uint8_t status,
 					void *user_data)
 {
 	struct bt_hog *hog = user_data;
-	uint16_t uuid16;
 	bt_uuid_t uuid;
 	struct queue *chrs;
 
@@ -333,12 +337,12 @@ static void external_report_reference_cb(bool success, uint8_t status,
 		return;
 	}
 
-	uuid16 = get_le16(value);
-	DBG("External report reference read, external report characteristic "
-						"UUID: 0x%04x", uuid16);
+	DBG("External report characteristic UUID: 0x%04x", get_le16(value));
+
+	bt_uuid16_create(&uuid, get_le16(value));
 
 	/* Do not discover if is not a Report */
-	if (uuid16 != HOG_REPORT_UUID)
+	if (bt_uuid_cmp(&uuid, &report_uuid))
 		return;
 
 	chrs = queue_new();
@@ -347,7 +351,6 @@ static void external_report_reference_cb(bool success, uint8_t status,
 		return;
 	}
 
-	bt_uuid16_create(&uuid, uuid16);
 	gatt_db_read_by_type(hog->db, 0x0001, 0xffff, uuid, chrs);
 
 	if (queue_isempty(chrs))
@@ -836,18 +839,11 @@ static void char_discovered_cb(struct gatt_db_attribute *attrib,
 								void *user_data)
 {
 	struct bt_hog *hog = user_data;
-	bt_uuid_t report_uuid, report_map_uuid, proto_mode_uuid, ctrlpt_uuid;
-	bt_uuid_t info_uuid, uuid;
+	bt_uuid_t uuid;
 	struct report *report;
 	uint16_t value_handle;
 	uint8_t properties;
 
-	bt_uuid16_create(&report_uuid, HOG_REPORT_UUID);
-	bt_uuid16_create(&report_map_uuid, HOG_REPORT_MAP_UUID);
-	bt_uuid16_create(&info_uuid, HOG_INFO_UUID);
-	bt_uuid16_create(&proto_mode_uuid, HOG_PROTO_MODE_UUID);
-	bt_uuid16_create(&ctrlpt_uuid, HOG_CONTROL_POINT_UUID);
-
 	gatt_db_attribute_get_char_data(attrib, NULL, &value_handle,
 							&properties, &uuid);
 
@@ -865,11 +861,11 @@ static void char_discovered_cb(struct gatt_db_attribute *attrib,
 	} else if (!bt_uuid_cmp(&uuid, &info_uuid)) {
 		bt_gatt_client_read_value(hog->client, value_handle,
 						info_read_cb, hog, NULL);
-	} else if (!bt_uuid_cmp(&uuid, &proto_mode_uuid)) {
+	} else if (!bt_uuid_cmp(&uuid, &protocol_mode_uuid)) {
 		hog->proto_mode_handle = value_handle;
 		bt_gatt_client_read_value(hog->client, value_handle,
 						proto_mode_read_cb, hog, NULL);
-	} else if (!bt_uuid_cmp(&uuid, &ctrlpt_uuid)) {
+	} else if (!bt_uuid_cmp(&uuid, &control_point_uuid)) {
 		hog->ctrlpt_handle = value_handle;
 	}
 }
-- 
1.9.1

--
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