Lines Matching +full:ctrl +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0-only
17 void amp_ctrl_get(struct amp_ctrl *ctrl) in amp_ctrl_get() argument
19 BT_DBG("ctrl %p orig refcnt %d", ctrl, in amp_ctrl_get()
20 kref_read(&ctrl->kref)); in amp_ctrl_get()
22 kref_get(&ctrl->kref); in amp_ctrl_get()
27 struct amp_ctrl *ctrl = container_of(kref, struct amp_ctrl, kref); in amp_ctrl_destroy() local
29 BT_DBG("ctrl %p", ctrl); in amp_ctrl_destroy()
31 kfree(ctrl->assoc); in amp_ctrl_destroy()
32 kfree(ctrl); in amp_ctrl_destroy()
35 int amp_ctrl_put(struct amp_ctrl *ctrl) in amp_ctrl_put() argument
37 BT_DBG("ctrl %p orig refcnt %d", ctrl, in amp_ctrl_put()
38 kref_read(&ctrl->kref)); in amp_ctrl_put()
40 return kref_put(&ctrl->kref, &_ctrl_destroy); in amp_ctrl_put()
45 struct amp_ctrl *ctrl; in amp_ctrl_add() local
47 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in amp_ctrl_add()
48 if (!ctrl) in amp_ctrl_add()
51 kref_init(&ctrl->kref); in amp_ctrl_add()
52 ctrl->id = id; in amp_ctrl_add()
54 mutex_lock(&mgr->amp_ctrls_lock); in amp_ctrl_add()
55 list_add(&ctrl->list, &mgr->amp_ctrls); in amp_ctrl_add()
56 mutex_unlock(&mgr->amp_ctrls_lock); in amp_ctrl_add()
58 BT_DBG("mgr %p ctrl %p", mgr, ctrl); in amp_ctrl_add()
60 return ctrl; in amp_ctrl_add()
65 struct amp_ctrl *ctrl, *n; in amp_ctrl_list_flush() local
69 mutex_lock(&mgr->amp_ctrls_lock); in amp_ctrl_list_flush()
70 list_for_each_entry_safe(ctrl, n, &mgr->amp_ctrls, list) { in amp_ctrl_list_flush()
71 list_del(&ctrl->list); in amp_ctrl_list_flush()
72 amp_ctrl_put(ctrl); in amp_ctrl_list_flush()
74 mutex_unlock(&mgr->amp_ctrls_lock); in amp_ctrl_list_flush()
79 struct amp_ctrl *ctrl; in amp_ctrl_lookup() local
83 mutex_lock(&mgr->amp_ctrls_lock); in amp_ctrl_lookup()
84 list_for_each_entry(ctrl, &mgr->amp_ctrls, list) { in amp_ctrl_lookup()
85 if (ctrl->id == id) { in amp_ctrl_lookup()
86 amp_ctrl_get(ctrl); in amp_ctrl_lookup()
87 mutex_unlock(&mgr->amp_ctrls_lock); in amp_ctrl_lookup()
88 return ctrl; in amp_ctrl_lookup()
91 mutex_unlock(&mgr->amp_ctrls_lock); in amp_ctrl_lookup()
99 if (++mgr->handle == 0) in __next_handle()
100 mgr->handle = 1; in __next_handle()
102 return mgr->handle; in __next_handle()
108 bdaddr_t *dst = &mgr->l2cap_conn->hcon->dst; in phylink_add()
118 hcon->state = BT_CONNECT; in phylink_add()
119 hcon->attempt++; in phylink_add()
120 hcon->handle = __next_handle(mgr); in phylink_add()
121 hcon->remote_id = remote_id; in phylink_add()
122 hcon->amp_mgr = amp_mgr_get(mgr); in phylink_add()
135 return -EINVAL; in hmac_sha256()
152 ret = -ENOMEM; in hmac_sha256()
156 shash->tfm = tfm; in hmac_sha256()
167 int phylink_gen_key(struct hci_conn *conn, u8 *data, u8 *len, u8 *type) in phylink_gen_key() argument
169 struct hci_dev *hdev = conn->hdev; in phylink_gen_key()
176 return -EACCES; in phylink_gen_key()
178 BT_DBG("conn %p key_type %d", conn, conn->key_type); in phylink_gen_key()
181 if (conn->key_type < 3) { in phylink_gen_key()
182 bt_dev_err(hdev, "legacy key type %u", conn->key_type); in phylink_gen_key()
183 return -EACCES; in phylink_gen_key()
186 *type = conn->key_type; in phylink_gen_key()
187 *len = HCI_AMP_LINK_KEY_SIZE; in phylink_gen_key()
189 key = hci_find_link_key(hdev, &conn->dst); in phylink_gen_key()
191 BT_DBG("No Link key for conn %p dst %pMR", conn, &conn->dst); in phylink_gen_key()
192 return -EACCES; in phylink_gen_key()
196 memcpy(&keybuf[0], key->val, HCI_LINK_KEY_SIZE); in phylink_gen_key()
197 memcpy(&keybuf[HCI_LINK_KEY_SIZE], key->val, HCI_LINK_KEY_SIZE); in phylink_gen_key()
206 if (conn->key_type == HCI_LK_DEBUG_COMBINATION) { in phylink_gen_key()
219 struct hci_rp_read_local_amp_assoc *rp = (void *)skb->data; in read_local_amp_assoc_complete()
220 struct amp_assoc *assoc = &hdev->loc_assoc; in read_local_amp_assoc_complete()
223 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); in read_local_amp_assoc_complete()
225 if (rp->status) in read_local_amp_assoc_complete()
228 frag_len = skb->len - sizeof(*rp); in read_local_amp_assoc_complete()
229 rem_len = __le16_to_cpu(rp->rem_len); in read_local_amp_assoc_complete()
234 memcpy(assoc->data + assoc->offset, rp->frag, frag_len); in read_local_amp_assoc_complete()
235 assoc->offset += frag_len; in read_local_amp_assoc_complete()
238 amp_read_loc_assoc_frag(hdev, rp->phy_handle); in read_local_amp_assoc_complete()
243 memcpy(assoc->data + assoc->offset, rp->frag, rem_len); in read_local_amp_assoc_complete()
244 assoc->len = assoc->offset + rem_len; in read_local_amp_assoc_complete()
245 assoc->offset = 0; in read_local_amp_assoc_complete()
249 a2mp_send_getampassoc_rsp(hdev, rp->status); in read_local_amp_assoc_complete()
250 a2mp_send_create_phy_link_req(hdev, rp->status); in read_local_amp_assoc_complete()
256 struct amp_assoc *loc_assoc = &hdev->loc_assoc; in amp_read_loc_assoc_frag()
260 BT_DBG("%s handle %u", hdev->name, phy_handle); in amp_read_loc_assoc_frag()
263 cp.max_len = cpu_to_le16(hdev->amp_assoc_size); in amp_read_loc_assoc_frag()
264 cp.len_so_far = cpu_to_le16(loc_assoc->offset); in amp_read_loc_assoc_frag()
279 memset(&hdev->loc_assoc, 0, sizeof(struct amp_assoc)); in amp_read_loc_assoc()
282 cp.max_len = cpu_to_le16(hdev->amp_assoc_size); in amp_read_loc_assoc()
284 set_bit(READ_LOC_AMP_ASSOC, &mgr->state); in amp_read_loc_assoc()
296 struct amp_mgr *mgr = hcon->amp_mgr; in amp_read_loc_assoc_final_data()
303 cp.phy_handle = hcon->handle; in amp_read_loc_assoc_final_data()
305 cp.max_len = cpu_to_le16(hdev->amp_assoc_size); in amp_read_loc_assoc_final_data()
307 set_bit(READ_LOC_AMP_ASSOC_FINAL, &mgr->state); in amp_read_loc_assoc_final_data()
320 struct hci_rp_write_remote_amp_assoc *rp = (void *)skb->data; in write_remote_amp_assoc_complete()
323 hdev->name, rp->status, rp->phy_handle); in write_remote_amp_assoc_complete()
325 if (rp->status) in write_remote_amp_assoc_complete()
328 amp_write_rem_assoc_continue(hdev, rp->phy_handle); in write_remote_amp_assoc_complete()
336 struct amp_mgr *mgr = hcon->amp_mgr; in amp_write_rem_assoc_frag()
337 struct amp_ctrl *ctrl; in amp_write_rem_assoc_frag() local
339 u16 frag_len, len; in amp_write_rem_assoc_frag() local
341 ctrl = amp_ctrl_lookup(mgr, hcon->remote_id); in amp_write_rem_assoc_frag()
342 if (!ctrl) in amp_write_rem_assoc_frag()
345 if (!ctrl->assoc_rem_len) { in amp_write_rem_assoc_frag()
347 ctrl->assoc_rem_len = ctrl->assoc_len; in amp_write_rem_assoc_frag()
348 ctrl->assoc_len_so_far = 0; in amp_write_rem_assoc_frag()
350 amp_ctrl_put(ctrl); in amp_write_rem_assoc_frag()
354 frag_len = min_t(u16, 248, ctrl->assoc_rem_len); in amp_write_rem_assoc_frag()
355 len = frag_len + sizeof(*cp); in amp_write_rem_assoc_frag()
357 cp = kzalloc(len, GFP_KERNEL); in amp_write_rem_assoc_frag()
359 amp_ctrl_put(ctrl); in amp_write_rem_assoc_frag()
363 BT_DBG("hcon %p ctrl %p frag_len %u assoc_len %u rem_len %u", in amp_write_rem_assoc_frag()
364 hcon, ctrl, frag_len, ctrl->assoc_len, ctrl->assoc_rem_len); in amp_write_rem_assoc_frag()
366 cp->phy_handle = hcon->handle; in amp_write_rem_assoc_frag()
367 cp->len_so_far = cpu_to_le16(ctrl->assoc_len_so_far); in amp_write_rem_assoc_frag()
368 cp->rem_len = cpu_to_le16(ctrl->assoc_rem_len); in amp_write_rem_assoc_frag()
369 memcpy(cp->frag, ctrl->assoc, frag_len); in amp_write_rem_assoc_frag()
371 ctrl->assoc_len_so_far += frag_len; in amp_write_rem_assoc_frag()
372 ctrl->assoc_rem_len -= frag_len; in amp_write_rem_assoc_frag()
374 amp_ctrl_put(ctrl); in amp_write_rem_assoc_frag()
377 hci_req_add(&req, HCI_OP_WRITE_REMOTE_AMP_ASSOC, len, cp); in amp_write_rem_assoc_frag()
389 BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle); in amp_write_rem_assoc_continue()
404 BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle); in amp_write_remote_assoc()
410 BT_DBG("%s phy handle 0x%2.2x hcon %p", hdev->name, handle, hcon); in amp_write_remote_assoc()
420 BT_DBG("%s status 0x%2.2x", hdev->name, status); in create_phylink_complete()
431 hcon = hci_conn_hash_lookup_handle(hdev, cp->phy_handle); in create_phylink_complete()
435 amp_write_remote_assoc(hdev, cp->phy_handle); in create_phylink_complete()
447 cp.phy_handle = hcon->handle; in amp_create_phylink()
449 BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon, in amp_create_phylink()
450 hcon->handle); in amp_create_phylink()
452 if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len, in amp_create_phylink()
468 BT_DBG("%s status 0x%2.2x", hdev->name, status); in accept_phylink_complete()
477 amp_write_remote_assoc(hdev, cp->phy_handle); in accept_phylink_complete()
486 cp.phy_handle = hcon->handle; in amp_accept_phylink()
488 BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon, in amp_accept_phylink()
489 hcon->handle); in amp_accept_phylink()
491 if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len, in amp_accept_phylink()
504 struct hci_dev *bredr_hdev = hci_dev_hold(bredr_hcon->hdev); in amp_physical_cfm()
505 struct amp_mgr *mgr = hs_hcon->amp_mgr; in amp_physical_cfm()
510 if (!bredr_hdev || !mgr || !mgr->bredr_chan) in amp_physical_cfm()
513 bredr_chan = mgr->bredr_chan; in amp_physical_cfm()
517 set_bit(FLAG_EFS_ENABLE, &bredr_chan->flags); in amp_physical_cfm()
518 bredr_chan->remote_amp_id = hs_hcon->remote_id; in amp_physical_cfm()
519 bredr_chan->local_amp_id = hs_hcon->hdev->id; in amp_physical_cfm()
520 bredr_chan->hs_hcon = hs_hcon; in amp_physical_cfm()
521 bredr_chan->conn->mtu = hs_hcon->hdev->block_mtu; in amp_physical_cfm()
532 struct hci_conn *hs_hcon = chan->hs_hcon; in amp_create_logical_link()
537 &chan->conn->hcon->dst); in amp_create_logical_link()
542 hdev = hci_dev_hold(chan->hs_hcon->hdev); in amp_create_logical_link()
546 cp.phy_handle = hs_hcon->handle; in amp_create_logical_link()
548 cp.tx_flow_spec.id = chan->local_id; in amp_create_logical_link()
549 cp.tx_flow_spec.stype = chan->local_stype; in amp_create_logical_link()
550 cp.tx_flow_spec.msdu = cpu_to_le16(chan->local_msdu); in amp_create_logical_link()
551 cp.tx_flow_spec.sdu_itime = cpu_to_le32(chan->local_sdu_itime); in amp_create_logical_link()
552 cp.tx_flow_spec.acc_lat = cpu_to_le32(chan->local_acc_lat); in amp_create_logical_link()
553 cp.tx_flow_spec.flush_to = cpu_to_le32(chan->local_flush_to); in amp_create_logical_link()
555 cp.rx_flow_spec.id = chan->remote_id; in amp_create_logical_link()
556 cp.rx_flow_spec.stype = chan->remote_stype; in amp_create_logical_link()
557 cp.rx_flow_spec.msdu = cpu_to_le16(chan->remote_msdu); in amp_create_logical_link()
558 cp.rx_flow_spec.sdu_itime = cpu_to_le32(chan->remote_sdu_itime); in amp_create_logical_link()
559 cp.rx_flow_spec.acc_lat = cpu_to_le32(chan->remote_acc_lat); in amp_create_logical_link()
560 cp.rx_flow_spec.flush_to = cpu_to_le32(chan->remote_flush_to); in amp_create_logical_link()
562 if (hs_hcon->out) in amp_create_logical_link()
574 struct hci_conn *hcon = hchan->conn; in amp_disconnect_logical_link()
577 if (hcon->state != BT_CONNECTED) { in amp_disconnect_logical_link()
582 cp.log_handle = cpu_to_le16(hchan->handle); in amp_disconnect_logical_link()
583 hci_send_cmd(hcon->hdev, HCI_OP_DISCONN_LOGICAL_LINK, sizeof(cp), &cp); in amp_disconnect_logical_link()