Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static void ble_operation_remove_by_mac(ble_operation_t **queue,

while (*cur)
{
if (!memcmp((*cur)->device->mac, mac, sizeof(mac_addr_t)))
if (ble_mac_equal((*cur)->device->mac, mac))
{
tmp = *cur;
*cur = (*cur)->next;
Expand Down
20 changes: 14 additions & 6 deletions main/ble_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ int atouuid(const char *str, ble_uuid_t uuid)
&uuid[5], &uuid[4], &uuid[3], &uuid[2], &uuid[1], &uuid[0]) != 16;
}

bool ble_uuid_equal(ble_uuid_t uuid1, ble_uuid_t uuid2){
return memcmp(uuid1, uuid2, sizeof(ble_uuid_t)) == 0;
}

bool ble_mac_equal(mac_addr_t mac1, mac_addr_t mac2){
return memcmp(mac1, mac2, sizeof(mac_addr_t)) == 0;
}

static service_desc_t *ble_get_sig_service(ble_uuid_t uuid)
{
service_desc_t *p;

for (p = services; p->name; p++)
{
if (memcmp(p->uuid, uuid, sizeof(ble_uuid_t)))
if (!ble_uuid_equal(p->uuid, uuid))
continue;

return p;
Expand All @@ -148,7 +156,7 @@ static characteristic_desc_t *ble_get_sig_characteristic(ble_uuid_t uuid)

for (p = characteristics; p->name; p++)
{
if (memcmp(p->uuid, uuid, sizeof(ble_uuid_t)))
if (!ble_uuid_equal(p->uuid, uuid))
continue;

return p;
Expand Down Expand Up @@ -707,7 +715,7 @@ ble_device_t *ble_device_find_by_mac(ble_device_t *list, mac_addr_t mac)

for (cur = list; cur; cur = cur->next)
{
if (!memcmp(cur->mac, mac, sizeof(mac_addr_t)))
if (ble_mac_equal(cur->mac, mac))
break;
}

Expand Down Expand Up @@ -739,7 +747,7 @@ void ble_device_remove_by_mac(ble_device_t **list, mac_addr_t mac)

for (cur = list; *cur; cur = &(*cur)->next)
{
if (!memcmp((*cur)->mac, mac, sizeof(mac_addr_t)))
if (ble_mac_equal((*cur)->mac, mac))
break;
}

Expand Down Expand Up @@ -828,7 +836,7 @@ ble_service_t *ble_device_service_find(ble_device_t *device, ble_uuid_t uuid)

for (cur = device->services; cur; cur = cur->next)
{
if (!memcmp(cur->uuid, uuid, sizeof(ble_uuid_t)))
if (ble_uuid_equal(cur->uuid, uuid))
break;
}

Expand Down Expand Up @@ -879,7 +887,7 @@ ble_characteristic_t *ble_device_characteristic_find_by_uuid(

for (cur = service->characteristics; cur; cur = cur->next)
{
if (!memcmp(cur->uuid, uuid, sizeof(ble_uuid_t)))
if (ble_uuid_equal(cur->uuid, uuid))
break;
}

Expand Down
3 changes: 3 additions & 0 deletions main/ble_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ ble_characteristic_t *ble_device_characteristic_find_by_handle(
void ble_device_characteristic_free(ble_characteristic_t *characteristic);
void ble_device_characteristics_free(ble_characteristic_t **list);

bool ble_uuid_equal(ble_uuid_t uuid1, ble_uuid_t uuid2);
bool ble_mac_equal(mac_addr_t mac1, mac_addr_t mac2);

int ble_device_info_get_by_conn_id_handle(ble_device_t *list, uint16_t conn_id,
uint16_t handle, ble_device_t **device, ble_service_t **service,
ble_characteristic_t **characteristic);
Expand Down