mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-29 15:14:31 +08:00
android/hog: Add support to auto discover primary if not set
This adds support to auto discover primary service stopping once HoG UUID is found.
This commit is contained in:
parent
48b4dfbccf
commit
1f27eabeca
104
android/hog.c
104
android/hog.c
@ -674,7 +674,9 @@ struct bt_hog *bt_hog_new(const char *name, uint16_t vendor, uint16_t product,
|
||||
hog->vendor = vendor;
|
||||
hog->product = product;
|
||||
hog->version = version;
|
||||
hog->primary = g_memdup(primary, sizeof(*primary));
|
||||
|
||||
if (primary)
|
||||
hog->primary = g_memdup(primary, sizeof(*hog->primary));
|
||||
|
||||
return bt_hog_ref(hog);
|
||||
}
|
||||
@ -700,6 +702,98 @@ void bt_hog_unref(struct bt_hog *hog)
|
||||
hog_free(hog);
|
||||
}
|
||||
|
||||
static void find_included_cb(uint8_t status, GSList *services, void *user_data)
|
||||
{
|
||||
struct bt_hog *hog = user_data;
|
||||
struct gatt_included *include;
|
||||
GSList *l;
|
||||
|
||||
DBG("");
|
||||
|
||||
if (hog->primary)
|
||||
return;
|
||||
|
||||
if (status) {
|
||||
const char *str = att_ecode2str(status);
|
||||
DBG("Find included failed: %s", str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!services) {
|
||||
DBG("No included service found");
|
||||
return;
|
||||
}
|
||||
|
||||
for (l = services; l; l = l->next) {
|
||||
include = l->data;
|
||||
|
||||
if (strcmp(include->uuid, HOG_UUID) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
for (l = services; l; l = l->next) {
|
||||
include = l->data;
|
||||
|
||||
gatt_find_included(hog->attrib, include->range.start,
|
||||
include->range.end, find_included_cb, hog);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
hog->primary = g_new0(struct gatt_primary, 1);
|
||||
memcpy(hog->primary->uuid, include->uuid, sizeof(include->uuid));
|
||||
memcpy(&hog->primary->range, &include->range, sizeof(include->range));
|
||||
|
||||
gatt_discover_char(hog->attrib, hog->primary->range.start,
|
||||
hog->primary->range.end, NULL,
|
||||
char_discovered_cb, hog);
|
||||
}
|
||||
|
||||
static void primary_cb(uint8_t status, GSList *services, void *user_data)
|
||||
{
|
||||
struct bt_hog *hog = user_data;
|
||||
struct gatt_primary *primary;
|
||||
GSList *l;
|
||||
|
||||
DBG("");
|
||||
|
||||
if (status) {
|
||||
const char *str = att_ecode2str(status);
|
||||
DBG("Discover primary failed: %s", str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!services) {
|
||||
DBG("No primary service found");
|
||||
return;
|
||||
}
|
||||
|
||||
for (l = services; l; l = l->next) {
|
||||
primary = l->data;
|
||||
|
||||
if (strcmp(primary->uuid, HOG_UUID) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
for (l = services; l; l = l->next) {
|
||||
primary = l->data;
|
||||
|
||||
gatt_find_included(hog->attrib, primary->range.start,
|
||||
primary->range.end, find_included_cb,
|
||||
hog);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
hog->primary = g_memdup(primary, sizeof(*primary));
|
||||
|
||||
gatt_discover_char(hog->attrib, hog->primary->range.start,
|
||||
hog->primary->range.end, NULL,
|
||||
char_discovered_cb, hog);
|
||||
}
|
||||
|
||||
bool bt_hog_attach(struct bt_hog *hog, void *gatt)
|
||||
{
|
||||
struct gatt_primary *primary = hog->primary;
|
||||
@ -710,6 +804,11 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)
|
||||
|
||||
hog->attrib = g_attrib_ref(gatt);
|
||||
|
||||
if (!primary) {
|
||||
gatt_discover_primary(hog->attrib, NULL, primary_cb, hog);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hog->reports == NULL) {
|
||||
gatt_discover_char(hog->attrib, primary->range.start,
|
||||
primary->range.end, NULL,
|
||||
@ -733,6 +832,9 @@ void bt_hog_detach(struct bt_hog *hog)
|
||||
{
|
||||
GSList *l;
|
||||
|
||||
if (!hog->attrib)
|
||||
return;
|
||||
|
||||
for (l = hog->reports; l; l = l->next) {
|
||||
struct report *r = l->data;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user