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->remote_id = remote_id; in phylink_add()
121 hcon->amp_mgr = amp_mgr_get(mgr); in phylink_add()
134 return -EINVAL; in hmac_sha256()
151 ret = -ENOMEM; in hmac_sha256()
155 shash->tfm = tfm; in hmac_sha256()
166 int phylink_gen_key(struct hci_conn *conn, u8 *data, u8 *len, u8 *type) in phylink_gen_key() argument
168 struct hci_dev *hdev = conn->hdev; in phylink_gen_key()
175 return -EACCES; in phylink_gen_key()
177 BT_DBG("conn %p key_type %d", conn, conn->key_type); in phylink_gen_key()
180 if (conn->key_type < 3) { in phylink_gen_key()
181 bt_dev_err(hdev, "legacy key type %u", conn->key_type); in phylink_gen_key()
182 return -EACCES; in phylink_gen_key()
185 *type = conn->key_type; in phylink_gen_key()
186 *len = HCI_AMP_LINK_KEY_SIZE; in phylink_gen_key()
188 key = hci_find_link_key(hdev, &conn->dst); in phylink_gen_key()
190 BT_DBG("No Link key for conn %p dst %pMR", conn, &conn->dst); in phylink_gen_key()
191 return -EACCES; in phylink_gen_key()
195 memcpy(&keybuf[0], key->val, HCI_LINK_KEY_SIZE); in phylink_gen_key()
196 memcpy(&keybuf[HCI_LINK_KEY_SIZE], key->val, HCI_LINK_KEY_SIZE); in phylink_gen_key()
205 if (conn->key_type == HCI_LK_DEBUG_COMBINATION) { in phylink_gen_key()
218 struct hci_rp_read_local_amp_assoc *rp = (void *)skb->data; in read_local_amp_assoc_complete()
219 struct amp_assoc *assoc = &hdev->loc_assoc; in read_local_amp_assoc_complete()
222 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); in read_local_amp_assoc_complete()
224 if (rp->status) in read_local_amp_assoc_complete()
227 frag_len = skb->len - sizeof(*rp); in read_local_amp_assoc_complete()
228 rem_len = __le16_to_cpu(rp->rem_len); in read_local_amp_assoc_complete()
233 memcpy(assoc->data + assoc->offset, rp->frag, frag_len); in read_local_amp_assoc_complete()
234 assoc->offset += frag_len; in read_local_amp_assoc_complete()
237 amp_read_loc_assoc_frag(hdev, rp->phy_handle); in read_local_amp_assoc_complete()
242 memcpy(assoc->data + assoc->offset, rp->frag, rem_len); in read_local_amp_assoc_complete()
243 assoc->len = assoc->offset + rem_len; in read_local_amp_assoc_complete()
244 assoc->offset = 0; in read_local_amp_assoc_complete()
248 a2mp_send_getampassoc_rsp(hdev, rp->status); in read_local_amp_assoc_complete()
249 a2mp_send_create_phy_link_req(hdev, rp->status); in read_local_amp_assoc_complete()
255 struct amp_assoc *loc_assoc = &hdev->loc_assoc; in amp_read_loc_assoc_frag()
259 BT_DBG("%s handle %u", hdev->name, phy_handle); in amp_read_loc_assoc_frag()
262 cp.max_len = cpu_to_le16(hdev->amp_assoc_size); in amp_read_loc_assoc_frag()
263 cp.len_so_far = cpu_to_le16(loc_assoc->offset); in amp_read_loc_assoc_frag()
278 memset(&hdev->loc_assoc, 0, sizeof(struct amp_assoc)); in amp_read_loc_assoc()
281 cp.max_len = cpu_to_le16(hdev->amp_assoc_size); in amp_read_loc_assoc()
283 set_bit(READ_LOC_AMP_ASSOC, &mgr->state); in amp_read_loc_assoc()
295 struct amp_mgr *mgr = hcon->amp_mgr; in amp_read_loc_assoc_final_data()
302 cp.phy_handle = hcon->handle; in amp_read_loc_assoc_final_data()
304 cp.max_len = cpu_to_le16(hdev->amp_assoc_size); in amp_read_loc_assoc_final_data()
306 set_bit(READ_LOC_AMP_ASSOC_FINAL, &mgr->state); in amp_read_loc_assoc_final_data()
319 struct hci_rp_write_remote_amp_assoc *rp = (void *)skb->data; in write_remote_amp_assoc_complete()
322 hdev->name, rp->status, rp->phy_handle); in write_remote_amp_assoc_complete()
324 if (rp->status) in write_remote_amp_assoc_complete()
327 amp_write_rem_assoc_continue(hdev, rp->phy_handle); in write_remote_amp_assoc_complete()
335 struct amp_mgr *mgr = hcon->amp_mgr; in amp_write_rem_assoc_frag()
336 struct amp_ctrl *ctrl; in amp_write_rem_assoc_frag() local
338 u16 frag_len, len; in amp_write_rem_assoc_frag() local
340 ctrl = amp_ctrl_lookup(mgr, hcon->remote_id); in amp_write_rem_assoc_frag()
341 if (!ctrl) in amp_write_rem_assoc_frag()
344 if (!ctrl->assoc_rem_len) { in amp_write_rem_assoc_frag()
346 ctrl->assoc_rem_len = ctrl->assoc_len; in amp_write_rem_assoc_frag()
347 ctrl->assoc_len_so_far = 0; in amp_write_rem_assoc_frag()
349 amp_ctrl_put(ctrl); in amp_write_rem_assoc_frag()
353 frag_len = min_t(u16, 248, ctrl->assoc_rem_len); in amp_write_rem_assoc_frag()
354 len = frag_len + sizeof(*cp); in amp_write_rem_assoc_frag()
356 cp = kzalloc(len, GFP_KERNEL); in amp_write_rem_assoc_frag()
358 amp_ctrl_put(ctrl); in amp_write_rem_assoc_frag()
362 BT_DBG("hcon %p ctrl %p frag_len %u assoc_len %u rem_len %u", in amp_write_rem_assoc_frag()
363 hcon, ctrl, frag_len, ctrl->assoc_len, ctrl->assoc_rem_len); in amp_write_rem_assoc_frag()
365 cp->phy_handle = hcon->handle; in amp_write_rem_assoc_frag()
366 cp->len_so_far = cpu_to_le16(ctrl->assoc_len_so_far); in amp_write_rem_assoc_frag()
367 cp->rem_len = cpu_to_le16(ctrl->assoc_rem_len); in amp_write_rem_assoc_frag()
368 memcpy(cp->frag, ctrl->assoc, frag_len); in amp_write_rem_assoc_frag()
370 ctrl->assoc_len_so_far += frag_len; in amp_write_rem_assoc_frag()
371 ctrl->assoc_rem_len -= frag_len; in amp_write_rem_assoc_frag()
373 amp_ctrl_put(ctrl); in amp_write_rem_assoc_frag()
376 hci_req_add(&req, HCI_OP_WRITE_REMOTE_AMP_ASSOC, len, cp); in amp_write_rem_assoc_frag()
388 BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle); in amp_write_rem_assoc_continue()
403 BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle); in amp_write_remote_assoc()
409 BT_DBG("%s phy handle 0x%2.2x hcon %p", hdev->name, handle, hcon); in amp_write_remote_assoc()
419 BT_DBG("%s status 0x%2.2x", hdev->name, status); in create_phylink_complete()
430 hcon = hci_conn_hash_lookup_handle(hdev, cp->phy_handle); in create_phylink_complete()
434 amp_write_remote_assoc(hdev, cp->phy_handle); in create_phylink_complete()
446 cp.phy_handle = hcon->handle; in amp_create_phylink()
448 BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon, in amp_create_phylink()
449 hcon->handle); in amp_create_phylink()
451 if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len, in amp_create_phylink()
467 BT_DBG("%s status 0x%2.2x", hdev->name, status); in accept_phylink_complete()
476 amp_write_remote_assoc(hdev, cp->phy_handle); in accept_phylink_complete()
485 cp.phy_handle = hcon->handle; in amp_accept_phylink()
487 BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon, in amp_accept_phylink()
488 hcon->handle); in amp_accept_phylink()
490 if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len, in amp_accept_phylink()
503 struct hci_dev *bredr_hdev = hci_dev_hold(bredr_hcon->hdev); in amp_physical_cfm()
504 struct amp_mgr *mgr = hs_hcon->amp_mgr; in amp_physical_cfm()
509 if (!bredr_hdev || !mgr || !mgr->bredr_chan) in amp_physical_cfm()
512 bredr_chan = mgr->bredr_chan; in amp_physical_cfm()
516 set_bit(FLAG_EFS_ENABLE, &bredr_chan->flags); in amp_physical_cfm()
517 bredr_chan->remote_amp_id = hs_hcon->remote_id; in amp_physical_cfm()
518 bredr_chan->local_amp_id = hs_hcon->hdev->id; in amp_physical_cfm()
519 bredr_chan->hs_hcon = hs_hcon; in amp_physical_cfm()
520 bredr_chan->conn->mtu = hs_hcon->hdev->block_mtu; in amp_physical_cfm()
531 struct hci_conn *hs_hcon = chan->hs_hcon; in amp_create_logical_link()
536 &chan->conn->hcon->dst); in amp_create_logical_link()
541 hdev = hci_dev_hold(chan->hs_hcon->hdev); in amp_create_logical_link()
545 cp.phy_handle = hs_hcon->handle; in amp_create_logical_link()
547 cp.tx_flow_spec.id = chan->local_id; in amp_create_logical_link()
548 cp.tx_flow_spec.stype = chan->local_stype; in amp_create_logical_link()
549 cp.tx_flow_spec.msdu = cpu_to_le16(chan->local_msdu); in amp_create_logical_link()
550 cp.tx_flow_spec.sdu_itime = cpu_to_le32(chan->local_sdu_itime); in amp_create_logical_link()
551 cp.tx_flow_spec.acc_lat = cpu_to_le32(chan->local_acc_lat); in amp_create_logical_link()
552 cp.tx_flow_spec.flush_to = cpu_to_le32(chan->local_flush_to); in amp_create_logical_link()
554 cp.rx_flow_spec.id = chan->remote_id; in amp_create_logical_link()
555 cp.rx_flow_spec.stype = chan->remote_stype; in amp_create_logical_link()
556 cp.rx_flow_spec.msdu = cpu_to_le16(chan->remote_msdu); in amp_create_logical_link()
557 cp.rx_flow_spec.sdu_itime = cpu_to_le32(chan->remote_sdu_itime); in amp_create_logical_link()
558 cp.rx_flow_spec.acc_lat = cpu_to_le32(chan->remote_acc_lat); in amp_create_logical_link()
559 cp.rx_flow_spec.flush_to = cpu_to_le32(chan->remote_flush_to); in amp_create_logical_link()
561 if (hs_hcon->out) in amp_create_logical_link()
573 struct hci_conn *hcon = hchan->conn; in amp_disconnect_logical_link()
576 if (hcon->state != BT_CONNECTED) { in amp_disconnect_logical_link()
581 cp.log_handle = cpu_to_le16(hchan->handle); in amp_disconnect_logical_link()
582 hci_send_cmd(hcon->hdev, HCI_OP_DISCONN_LOGICAL_LINK, sizeof(cp), &cp); in amp_disconnect_logical_link()