amp.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright (c) 2011,2012 Intel Corp.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License version 2 and
  5. only version 2 as published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. */
  11. #include <net/bluetooth/bluetooth.h>
  12. #include <net/bluetooth/hci.h>
  13. #include <net/bluetooth/hci_core.h>
  14. #include <net/bluetooth/a2mp.h>
  15. #include <net/bluetooth/amp.h>
  16. /* Physical Link interface */
  17. static u8 __next_handle(struct amp_mgr *mgr)
  18. {
  19. if (++mgr->handle == 0)
  20. mgr->handle = 1;
  21. return mgr->handle;
  22. }
  23. struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr,
  24. u8 remote_id)
  25. {
  26. bdaddr_t *dst = mgr->l2cap_conn->dst;
  27. struct hci_conn *hcon;
  28. hcon = hci_conn_add(hdev, AMP_LINK, dst);
  29. if (!hcon)
  30. return NULL;
  31. hcon->state = BT_CONNECT;
  32. hcon->out = true;
  33. hcon->attempt++;
  34. hcon->handle = __next_handle(mgr);
  35. hcon->remote_id = remote_id;
  36. hcon->amp_mgr = mgr;
  37. return hcon;
  38. }
  39. void amp_read_loc_assoc_frag(struct hci_dev *hdev, u8 phy_handle)
  40. {
  41. struct hci_cp_read_local_amp_assoc cp;
  42. struct amp_assoc *loc_assoc = &hdev->loc_assoc;
  43. BT_DBG("%s handle %d", hdev->name, phy_handle);
  44. cp.phy_handle = phy_handle;
  45. cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
  46. cp.len_so_far = cpu_to_le16(loc_assoc->offset);
  47. hci_send_cmd(hdev, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
  48. }
  49. void amp_read_loc_assoc(struct hci_dev *hdev, struct amp_mgr *mgr)
  50. {
  51. struct hci_cp_read_local_amp_assoc cp;
  52. memset(&hdev->loc_assoc, 0, sizeof(struct amp_assoc));
  53. memset(&cp, 0, sizeof(cp));
  54. cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
  55. mgr->state = READ_LOC_AMP_ASSOC;
  56. hci_send_cmd(hdev, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
  57. }