mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-16 08:44:38 +08:00
android: Load Identity Resolving Keys
Load IRKs from file.
This commit is contained in:
parent
62cc5889fe
commit
93af47ef15
@ -2167,6 +2167,33 @@ static void load_ltks(GSList *ltks)
|
||||
g_free(cp);
|
||||
}
|
||||
|
||||
static void load_irks(GSList *irks)
|
||||
{
|
||||
struct mgmt_cp_load_irks *cp;
|
||||
struct mgmt_irk_info *irk;
|
||||
size_t irk_count, cp_size;
|
||||
GSList *l;
|
||||
|
||||
irk_count = g_slist_length(irks);
|
||||
|
||||
DBG("irks %zu", irk_count);
|
||||
|
||||
cp_size = sizeof(*cp) + (irk_count * sizeof(*irk));
|
||||
|
||||
cp = g_malloc0(cp_size);
|
||||
|
||||
cp->irk_count = htobs(irk_count);
|
||||
|
||||
for (l = irks, irk = cp->irks; l != NULL; l = g_slist_next(l), irk++)
|
||||
memcpy(irk, irks->data, sizeof(*irk));
|
||||
|
||||
if (mgmt_send(mgmt_if, MGMT_OP_LOAD_IRKS, adapter.index, cp_size, cp,
|
||||
NULL, NULL, NULL) == 0)
|
||||
error("Failed to load IRKs");
|
||||
|
||||
g_free(cp);
|
||||
}
|
||||
|
||||
static uint8_t get_adapter_uuids(void)
|
||||
{
|
||||
struct hal_ev_adapter_props_changed *ev;
|
||||
@ -2638,6 +2665,32 @@ failed:
|
||||
return info;
|
||||
}
|
||||
|
||||
static struct mgmt_irk_info *get_irk_info(GKeyFile *key_file, const char *peer)
|
||||
{
|
||||
struct mgmt_irk_info *info = NULL;
|
||||
unsigned int i;
|
||||
char *str;
|
||||
|
||||
str = g_key_file_get_string(key_file, peer, "IdentityResolvingKey",
|
||||
NULL);
|
||||
if (!str || strlen(str) != 32)
|
||||
goto failed;
|
||||
|
||||
info = g_new0(struct mgmt_irk_info, 1);
|
||||
|
||||
str2ba(peer, &info->addr.bdaddr);
|
||||
|
||||
info->addr.type = g_key_file_get_integer(key_file, peer, "Type", NULL);
|
||||
|
||||
for (i = 0; i < sizeof(info->val); i++)
|
||||
sscanf(str + (i * 2), "%02hhX", &info->val[i]);
|
||||
|
||||
failed:
|
||||
g_free(str);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static time_t device_timestamp(const struct device *dev)
|
||||
{
|
||||
if (dev->bredr && dev->le) {
|
||||
@ -2695,6 +2748,7 @@ static void load_devices_info(bt_bluetooth_ready cb)
|
||||
unsigned int i;
|
||||
GSList *keys = NULL;
|
||||
GSList *ltks = NULL;
|
||||
GSList *irks = NULL;
|
||||
|
||||
key_file = g_key_file_new();
|
||||
|
||||
@ -2705,10 +2759,12 @@ static void load_devices_info(bt_bluetooth_ready cb)
|
||||
for (i = 0; i < len; i++) {
|
||||
struct mgmt_link_key_info *key_info;
|
||||
struct mgmt_ltk_info *ltk_info;
|
||||
struct mgmt_irk_info *irk_info;
|
||||
struct mgmt_ltk_info *slave_ltk_info;
|
||||
struct device *dev;
|
||||
|
||||
key_info = get_key_info(key_file, devs[i]);
|
||||
irk_info = get_irk_info(key_file, devs[i]);
|
||||
ltk_info = get_ltk_info(key_file, devs[i], true);
|
||||
slave_ltk_info = get_ltk_info(key_file, devs[i], false);
|
||||
|
||||
@ -2721,6 +2777,9 @@ static void load_devices_info(bt_bluetooth_ready cb)
|
||||
if (key_info)
|
||||
keys = g_slist_prepend(keys, key_info);
|
||||
|
||||
if (irk_info)
|
||||
irks = g_slist_prepend(irks, irk_info);
|
||||
|
||||
if (ltk_info)
|
||||
ltks = g_slist_prepend(ltks, ltk_info);
|
||||
|
||||
@ -2735,6 +2794,9 @@ static void load_devices_info(bt_bluetooth_ready cb)
|
||||
load_ltks(ltks);
|
||||
g_slist_free_full(ltks, g_free);
|
||||
|
||||
load_irks(irks);
|
||||
g_slist_free_full(irks, g_free);
|
||||
|
||||
load_link_keys(keys, cb);
|
||||
g_slist_free_full(keys, g_free);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user