int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate, u8 pipe) { bool pipe_created = false; int r; pr_debug("\n"); if (hdev->gate2pipe[dest_gate] == NFC_HCI_DO_NOT_CREATE_PIPE) return 0; if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE) return -EADDRINUSE; if (pipe != NFC_HCI_INVALID_PIPE) goto open_pipe; switch (dest_gate) { case NFC_HCI_LINK_MGMT_GATE: pipe = NFC_HCI_LINK_MGMT_PIPE; break; case NFC_HCI_ADMIN_GATE: pipe = NFC_HCI_ADMIN_PIPE; break; default: pipe = nfc_hci_create_pipe(hdev, dest_host, dest_gate, &r); if (pipe == NFC_HCI_INVALID_PIPE) return r; pipe_created = true; break; } open_pipe: r = nfc_hci_open_pipe(hdev, pipe); if (r < 0) { if (pipe_created) if (nfc_hci_delete_pipe(hdev, pipe) < 0) { /* TODO: Cannot clean by deleting pipe... * -> inconsistent state */ } return r; } hdev->gate2pipe[dest_gate] = pipe; return 0; }
int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate) { int r; u8 pipe = hdev->gate2pipe[gate]; pr_debug("\n"); if (pipe == NFC_HCI_INVALID_PIPE) return -EADDRNOTAVAIL; r = nfc_hci_close_pipe(hdev, pipe); if (r < 0) return r; if (pipe != NFC_HCI_LINK_MGMT_PIPE && pipe != NFC_HCI_ADMIN_PIPE) { r = nfc_hci_delete_pipe(hdev, pipe); if (r < 0) return r; } hdev->gate2pipe[gate] = NFC_HCI_INVALID_PIPE; return 0; }