struct bt_conn *bt_conn_add_br(const bt_addr_t *peer) { struct bt_conn *conn = conn_new(); if (!conn) { return NULL; } bt_addr_copy(&conn->br.dst, peer); conn->type = BT_CONN_TYPE_BR; return conn; }
struct bt_keys *bt_keys_find_irk(const bt_addr_le_t *addr) { int i; BT_DBG("%s", bt_addr_le_str(addr)); if (!bt_addr_le_is_rpa(addr)) { return NULL; } for (i = 0; i < ARRAY_SIZE(key_pool); i++) { if (!(key_pool[i].keys & BT_KEYS_IRK)) { continue; } if (!bt_addr_cmp((bt_addr_t *)addr->val, &key_pool[i].irk.rpa)) { BT_DBG("cached RPA %s for %s", bt_addr_str(&key_pool[i].irk.rpa), bt_addr_le_str(&key_pool[i].addr)); return &key_pool[i]; } } for (i = 0; i < ARRAY_SIZE(key_pool); i++) { if (!(key_pool[i].keys & BT_KEYS_IRK)) { continue; } if (bt_smp_irk_matches(key_pool[i].irk.val, (bt_addr_t *)addr->val)) { BT_DBG("RPA %s matches %s", bt_addr_str(&key_pool[i].irk.rpa), bt_addr_le_str(&key_pool[i].addr)); bt_addr_copy(&key_pool[i].irk.rpa, (bt_addr_t *)addr->val); return &key_pool[i]; } } BT_DBG("No IRK for %s", bt_addr_le_str(addr)); return NULL; }
static int ssp_confirm_reply(struct bt_conn *conn) { struct bt_hci_cp_user_confirm_reply *cp; struct net_buf *buf; BT_DBG(""); buf = bt_hci_cmd_create(BT_HCI_OP_USER_CONFIRM_REPLY, sizeof(*cp)); if (!buf) { return -ENOBUFS; } cp = net_buf_add(buf, sizeof(*cp)); bt_addr_copy(&cp->bdaddr, &conn->br.dst); return bt_hci_cmd_send_sync(BT_HCI_OP_USER_CONFIRM_REPLY, buf, NULL); }
static int pin_code_neg_reply(const bt_addr_t *bdaddr) { struct bt_hci_cp_pin_code_neg_reply *cp; struct net_buf *buf; BT_DBG(""); buf = bt_hci_cmd_create(BT_HCI_OP_PIN_CODE_NEG_REPLY, sizeof(*cp)); if (!buf) { return -ENOBUFS; } cp = net_buf_add(buf, sizeof(*cp)); bt_addr_copy(&cp->bdaddr, bdaddr); return bt_hci_cmd_send_sync(BT_HCI_OP_PIN_CODE_NEG_REPLY, buf, NULL); }
static int ssp_passkey_reply(struct bt_conn *conn, unsigned int passkey) { struct bt_hci_cp_user_passkey_reply *cp; struct net_buf *buf; BT_DBG(""); buf = bt_hci_cmd_create(BT_HCI_OP_USER_PASSKEY_REPLY, sizeof(*cp)); if (!buf) { return -ENOBUFS; } cp = net_buf_add(buf, sizeof(*cp)); bt_addr_copy(&cp->bdaddr, &conn->br.dst); cp->passkey = sys_cpu_to_le32(passkey); return bt_hci_cmd_send_sync(BT_HCI_OP_USER_PASSKEY_REPLY, buf, NULL); }
static int pin_code_reply(struct bt_conn *conn, const char *pin, uint8_t len) { struct bt_hci_cp_pin_code_reply *cp; struct net_buf *buf; BT_DBG(""); buf = bt_hci_cmd_create(BT_HCI_OP_PIN_CODE_REPLY, sizeof(*cp)); if (!buf) { return -ENOBUFS; } cp = net_buf_add(buf, sizeof(*cp)); bt_addr_copy(&cp->bdaddr, &conn->br.dst); cp->pin_len = len; strncpy(cp->pin_code, pin, sizeof(cp->pin_code)); return bt_hci_cmd_send_sync(BT_HCI_OP_PIN_CODE_REPLY, buf, NULL); }
static struct bt_keys *bt_keys_get_addr_br(const bt_addr_t *addr) { struct bt_keys *keys; int i; BT_DBG("%s", bt_addr_str(addr)); for (i = 0; i < ARRAY_SIZE(key_pool); i++) { keys = &key_pool[i]; /* * When both LE and BR/EDR keys are for the same device, * the bt_addr_le_t is the public address, i.e. the same * as the BR/EDR address. */ if (keys->addr.type == BT_ADDR_LE_PUBLIC && !bt_addr_cmp((const bt_addr_t *)keys->addr.val, addr)) { return keys; } /* * BT_ADDR_LE_ANY has the same type of as BT_ADDR_LE_PUBLIC * value. No need to make redudant comparision against * BT_ADDR_LE_PUBLIC. */ if (!bt_addr_le_cmp(&keys->addr, BT_ADDR_LE_ANY)) { bt_addr_copy((bt_addr_t *)keys->addr.val, addr); BT_DBG("created %p for %s", keys, bt_addr_str(addr)); return keys; } } BT_DBG("unable to create keys for %s", bt_addr_str(addr)); return NULL; }