^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) Copyright (c) 2011,2012 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <net/bluetooth/hci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "hci_request.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "a2mp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "amp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Remote AMP Controllers interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) void amp_ctrl_get(struct amp_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) BT_DBG("ctrl %p orig refcnt %d", ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) kref_read(&ctrl->kref));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) kref_get(&ctrl->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static void amp_ctrl_destroy(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct amp_ctrl *ctrl = container_of(kref, struct amp_ctrl, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) BT_DBG("ctrl %p", ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) kfree(ctrl->assoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) kfree(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int amp_ctrl_put(struct amp_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) BT_DBG("ctrl %p orig refcnt %d", ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) kref_read(&ctrl->kref));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return kref_put(&ctrl->kref, &_ctrl_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr, u8 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct amp_ctrl *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (!ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) kref_init(&ctrl->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ctrl->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) mutex_lock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) list_add(&ctrl->list, &mgr->amp_ctrls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mutex_unlock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) BT_DBG("mgr %p ctrl %p", mgr, ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) void amp_ctrl_list_flush(struct amp_mgr *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct amp_ctrl *ctrl, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) BT_DBG("mgr %p", mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) mutex_lock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) list_for_each_entry_safe(ctrl, n, &mgr->amp_ctrls, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) list_del(&ctrl->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) amp_ctrl_put(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) mutex_unlock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct amp_ctrl *amp_ctrl_lookup(struct amp_mgr *mgr, u8 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct amp_ctrl *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) BT_DBG("mgr %p id %d", mgr, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) mutex_lock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) list_for_each_entry(ctrl, &mgr->amp_ctrls, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (ctrl->id == id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) amp_ctrl_get(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) mutex_unlock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) mutex_unlock(&mgr->amp_ctrls_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Physical Link interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static u8 __next_handle(struct amp_mgr *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (++mgr->handle == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) mgr->handle = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return mgr->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u8 remote_id, bool out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bdaddr_t *dst = &mgr->l2cap_conn->hcon->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct hci_conn *hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) u8 role = out ? HCI_ROLE_MASTER : HCI_ROLE_SLAVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) hcon = hci_conn_add(hdev, AMP_LINK, dst, role);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) BT_DBG("hcon %p dst %pMR", hcon, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) hcon->state = BT_CONNECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) hcon->attempt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) hcon->handle = __next_handle(mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) hcon->remote_id = remote_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) hcon->amp_mgr = amp_mgr_get(mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* AMP crypto key generation interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct crypto_shash *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct shash_desc *shash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (!ksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) tfm = crypto_alloc_shash("hmac(sha256)", 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) BT_DBG("crypto_alloc_ahash failed: err %ld", PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ret = crypto_shash_setkey(tfm, key, ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) BT_DBG("crypto_ahash_setkey failed: err %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!shash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) shash->tfm = tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ret = crypto_shash_digest(shash, plaintext, psize, output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) kfree(shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) crypto_free_shash(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int phylink_gen_key(struct hci_conn *conn, u8 *data, u8 *len, u8 *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct hci_dev *hdev = conn->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct link_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u8 keybuf[HCI_AMP_LINK_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u8 gamp_key[HCI_AMP_LINK_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (!hci_conn_check_link_mode(conn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) BT_DBG("conn %p key_type %d", conn, conn->key_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Legacy key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (conn->key_type < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) bt_dev_err(hdev, "legacy key type %d", conn->key_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *type = conn->key_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *len = HCI_AMP_LINK_KEY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) key = hci_find_link_key(hdev, &conn->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) BT_DBG("No Link key for conn %p dst %pMR", conn, &conn->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* BR/EDR Link Key concatenated together with itself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) memcpy(&keybuf[0], key->val, HCI_LINK_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) memcpy(&keybuf[HCI_LINK_KEY_SIZE], key->val, HCI_LINK_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Derive Generic AMP Link Key (gamp) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) err = hmac_sha256(keybuf, HCI_AMP_LINK_KEY_SIZE, "gamp", 4, gamp_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) bt_dev_err(hdev, "could not derive Generic AMP Key: err %d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (conn->key_type == HCI_LK_DEBUG_COMBINATION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) BT_DBG("Use Generic AMP Key (gamp)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) memcpy(data, gamp_key, HCI_AMP_LINK_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Derive Dedicated AMP Link Key: "802b" is 802.11 PAL keyID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return hmac_sha256(gamp_key, HCI_AMP_LINK_KEY_SIZE, "802b", 4, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void read_local_amp_assoc_complete(struct hci_dev *hdev, u8 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) u16 opcode, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct hci_rp_read_local_amp_assoc *rp = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct amp_assoc *assoc = &hdev->loc_assoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) size_t rem_len, frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (rp->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto send_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) frag_len = skb->len - sizeof(*rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) rem_len = __le16_to_cpu(rp->rem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (rem_len > frag_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) BT_DBG("frag_len %zu rem_len %zu", frag_len, rem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) memcpy(assoc->data + assoc->offset, rp->frag, frag_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) assoc->offset += frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Read other fragments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) amp_read_loc_assoc_frag(hdev, rp->phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) memcpy(assoc->data + assoc->offset, rp->frag, rem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) assoc->len = assoc->offset + rem_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) assoc->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) send_rsp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Send A2MP Rsp when all fragments are received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) a2mp_send_getampassoc_rsp(hdev, rp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) a2mp_send_create_phy_link_req(hdev, rp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void amp_read_loc_assoc_frag(struct hci_dev *hdev, u8 phy_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct hci_cp_read_local_amp_assoc cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct amp_assoc *loc_assoc = &hdev->loc_assoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct hci_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) BT_DBG("%s handle %d", hdev->name, phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) cp.phy_handle = phy_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) cp.len_so_far = cpu_to_le16(loc_assoc->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) hci_req_init(&req, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) hci_req_add(&req, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) err = hci_req_run_skb(&req, read_local_amp_assoc_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) a2mp_send_getampassoc_rsp(hdev, A2MP_STATUS_INVALID_CTRL_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) void amp_read_loc_assoc(struct hci_dev *hdev, struct amp_mgr *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct hci_cp_read_local_amp_assoc cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct hci_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) memset(&hdev->loc_assoc, 0, sizeof(struct amp_assoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) memset(&cp, 0, sizeof(cp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) set_bit(READ_LOC_AMP_ASSOC, &mgr->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) hci_req_init(&req, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) hci_req_add(&req, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) err = hci_req_run_skb(&req, read_local_amp_assoc_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) a2mp_send_getampassoc_rsp(hdev, A2MP_STATUS_INVALID_CTRL_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) void amp_read_loc_assoc_final_data(struct hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct hci_conn *hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct hci_cp_read_local_amp_assoc cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct amp_mgr *mgr = hcon->amp_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct hci_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (!mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) cp.phy_handle = hcon->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) cp.len_so_far = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) set_bit(READ_LOC_AMP_ASSOC_FINAL, &mgr->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* Read Local AMP Assoc final link information data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) hci_req_init(&req, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) hci_req_add(&req, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) err = hci_req_run_skb(&req, read_local_amp_assoc_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) a2mp_send_getampassoc_rsp(hdev, A2MP_STATUS_INVALID_CTRL_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static void write_remote_amp_assoc_complete(struct hci_dev *hdev, u8 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) u16 opcode, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct hci_rp_write_remote_amp_assoc *rp = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) BT_DBG("%s status 0x%2.2x phy_handle 0x%2.2x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) hdev->name, rp->status, rp->phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (rp->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) amp_write_rem_assoc_continue(hdev, rp->phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Write AMP Assoc data fragments, returns true with last fragment written*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static bool amp_write_rem_assoc_frag(struct hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct hci_conn *hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct hci_cp_write_remote_amp_assoc *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct amp_mgr *mgr = hcon->amp_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct amp_ctrl *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct hci_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) u16 frag_len, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ctrl = amp_ctrl_lookup(mgr, hcon->remote_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (!ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (!ctrl->assoc_rem_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) BT_DBG("all fragments are written");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ctrl->assoc_rem_len = ctrl->assoc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ctrl->assoc_len_so_far = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) amp_ctrl_put(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) frag_len = min_t(u16, 248, ctrl->assoc_rem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) len = frag_len + sizeof(*cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) cp = kzalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (!cp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) amp_ctrl_put(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) BT_DBG("hcon %p ctrl %p frag_len %u assoc_len %u rem_len %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) hcon, ctrl, frag_len, ctrl->assoc_len, ctrl->assoc_rem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) cp->phy_handle = hcon->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) cp->len_so_far = cpu_to_le16(ctrl->assoc_len_so_far);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) cp->rem_len = cpu_to_le16(ctrl->assoc_rem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) memcpy(cp->frag, ctrl->assoc, frag_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ctrl->assoc_len_so_far += frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ctrl->assoc_rem_len -= frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) amp_ctrl_put(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) hci_req_init(&req, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) hci_req_add(&req, HCI_OP_WRITE_REMOTE_AMP_ASSOC, len, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) hci_req_run_skb(&req, write_remote_amp_assoc_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) kfree(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) void amp_write_rem_assoc_continue(struct hci_dev *hdev, u8 handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct hci_conn *hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) hcon = hci_conn_hash_lookup_handle(hdev, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (!hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* Send A2MP create phylink rsp when all fragments are written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (amp_write_rem_assoc_frag(hdev, hcon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) a2mp_send_create_phy_link_rsp(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) void amp_write_remote_assoc(struct hci_dev *hdev, u8 handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct hci_conn *hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) hcon = hci_conn_hash_lookup_handle(hdev, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (!hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) BT_DBG("%s phy handle 0x%2.2x hcon %p", hdev->name, handle, hcon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) amp_write_rem_assoc_frag(hdev, hcon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static void create_phylink_complete(struct hci_dev *hdev, u8 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) u16 opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct hci_cp_create_phy_link *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) BT_DBG("%s status 0x%2.2x", hdev->name, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_PHY_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) hci_dev_lock(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct hci_conn *hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) hcon = hci_conn_hash_lookup_handle(hdev, cp->phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) hci_conn_del(hcon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) amp_write_remote_assoc(hdev, cp->phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) hci_dev_unlock(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) void amp_create_phylink(struct hci_dev *hdev, struct amp_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct hci_conn *hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct hci_cp_create_phy_link cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) struct hci_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) cp.phy_handle = hcon->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) hcon->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) &cp.key_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) BT_DBG("Cannot create link key");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) hci_req_init(&req, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) hci_req_add(&req, HCI_OP_CREATE_PHY_LINK, sizeof(cp), &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) hci_req_run(&req, create_phylink_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static void accept_phylink_complete(struct hci_dev *hdev, u8 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) u16 opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct hci_cp_accept_phy_link *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) BT_DBG("%s status 0x%2.2x", hdev->name, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) cp = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_PHY_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (!cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) amp_write_remote_assoc(hdev, cp->phy_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) void amp_accept_phylink(struct hci_dev *hdev, struct amp_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct hci_conn *hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct hci_cp_accept_phy_link cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct hci_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) cp.phy_handle = hcon->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) hcon->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) &cp.key_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) BT_DBG("Cannot create link key");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) hci_req_init(&req, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) hci_req_add(&req, HCI_OP_ACCEPT_PHY_LINK, sizeof(cp), &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) hci_req_run(&req, accept_phylink_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) void amp_physical_cfm(struct hci_conn *bredr_hcon, struct hci_conn *hs_hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct hci_dev *bredr_hdev = hci_dev_hold(bredr_hcon->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct amp_mgr *mgr = hs_hcon->amp_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct l2cap_chan *bredr_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) BT_DBG("bredr_hcon %p hs_hcon %p mgr %p", bredr_hcon, hs_hcon, mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (!bredr_hdev || !mgr || !mgr->bredr_chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) bredr_chan = mgr->bredr_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) l2cap_chan_lock(bredr_chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) set_bit(FLAG_EFS_ENABLE, &bredr_chan->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) bredr_chan->remote_amp_id = hs_hcon->remote_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) bredr_chan->local_amp_id = hs_hcon->hdev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) bredr_chan->hs_hcon = hs_hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) bredr_chan->conn->mtu = hs_hcon->hdev->block_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) __l2cap_physical_cfm(bredr_chan, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) l2cap_chan_unlock(bredr_chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) hci_dev_put(bredr_hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) void amp_create_logical_link(struct l2cap_chan *chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct hci_conn *hs_hcon = chan->hs_hcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct hci_cp_create_accept_logical_link cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) BT_DBG("chan %p hs_hcon %p dst %pMR", chan, hs_hcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) &chan->conn->hcon->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!hs_hcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) hdev = hci_dev_hold(chan->hs_hcon->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (!hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) cp.phy_handle = hs_hcon->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) cp.tx_flow_spec.id = chan->local_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) cp.tx_flow_spec.stype = chan->local_stype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) cp.tx_flow_spec.msdu = cpu_to_le16(chan->local_msdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) cp.tx_flow_spec.sdu_itime = cpu_to_le32(chan->local_sdu_itime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) cp.tx_flow_spec.acc_lat = cpu_to_le32(chan->local_acc_lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) cp.tx_flow_spec.flush_to = cpu_to_le32(chan->local_flush_to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) cp.rx_flow_spec.id = chan->remote_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) cp.rx_flow_spec.stype = chan->remote_stype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) cp.rx_flow_spec.msdu = cpu_to_le16(chan->remote_msdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) cp.rx_flow_spec.sdu_itime = cpu_to_le32(chan->remote_sdu_itime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) cp.rx_flow_spec.acc_lat = cpu_to_le32(chan->remote_acc_lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) cp.rx_flow_spec.flush_to = cpu_to_le32(chan->remote_flush_to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (hs_hcon->out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) hci_send_cmd(hdev, HCI_OP_CREATE_LOGICAL_LINK, sizeof(cp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) hci_send_cmd(hdev, HCI_OP_ACCEPT_LOGICAL_LINK, sizeof(cp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) hci_dev_put(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) void amp_disconnect_logical_link(struct hci_chan *hchan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct hci_conn *hcon = hchan->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) struct hci_cp_disconn_logical_link cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (hcon->state != BT_CONNECTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) BT_DBG("hchan %p not connected", hchan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) cp.log_handle = cpu_to_le16(hchan->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) hci_send_cmd(hcon->hdev, HCI_OP_DISCONN_LOGICAL_LINK, sizeof(cp), &cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) void amp_destroy_logical_link(struct hci_chan *hchan, u8 reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) BT_DBG("hchan %p", hchan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) hci_chan_del(hchan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }