Skip to content

Commit 118278f

Browse files
cricard13Samuel Ortiz
authored andcommitted
NFC: hci: Add pipes table to reference them with a tuple {gate, host}
In order to keep host source information on specific hci event (such as evt_connectivity or evt_transaction) and because 2 pipes can be connected to the same gate, it is necessary to add a table referencing every pipe with a {gate, host} tuple. Signed-off-by: Christophe Ricard <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]>
1 parent fda7a49 commit 118278f

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

include/net/nfc/hci.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ struct nfc_hci_ops {
6363
};
6464

6565
/* Pipes */
66-
#define NFC_HCI_INVALID_PIPE 0x80
6766
#define NFC_HCI_DO_NOT_CREATE_PIPE 0x81
67+
#define NFC_HCI_INVALID_PIPE 0x80
68+
#define NFC_HCI_INVALID_GATE 0xFF
69+
#define NFC_HCI_INVALID_HOST 0x80
6870
#define NFC_HCI_LINK_MGMT_PIPE 0x00
6971
#define NFC_HCI_ADMIN_PIPE 0x01
7072

@@ -73,7 +75,13 @@ struct nfc_hci_gate {
7375
u8 pipe;
7476
};
7577

78+
struct nfc_hci_pipe {
79+
u8 gate;
80+
u8 dest_host;
81+
};
82+
7683
#define NFC_HCI_MAX_CUSTOM_GATES 50
84+
#define NFC_HCI_MAX_PIPES 127
7785
struct nfc_hci_init_data {
7886
u8 gate_count;
7987
struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES];
@@ -125,6 +133,7 @@ struct nfc_hci_dev {
125133
void *clientdata;
126134

127135
u8 gate2pipe[NFC_HCI_MAX_GATES];
136+
struct nfc_hci_pipe pipes[NFC_HCI_MAX_PIPES];
128137

129138
u8 sw_romlib;
130139
u8 sw_patch;
@@ -167,6 +176,8 @@ void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev);
167176
void nfc_hci_driver_failure(struct nfc_hci_dev *hdev, int err);
168177

169178
int nfc_hci_result_to_errno(u8 result);
179+
void nfc_hci_reset_pipes(struct nfc_hci_dev *dev);
180+
void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host);
170181

171182
/* Host IDs */
172183
#define NFC_HCI_HOST_CONTROLLER_ID 0x00

net/nfc/hci/command.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev)
331331
if (r < 0)
332332
return r;
333333

334-
memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
334+
nfc_hci_reset_pipes(hdev);
335335

336336
return 0;
337337
}
@@ -345,7 +345,7 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
345345

346346
pr_debug("\n");
347347

348-
if (hdev->gate2pipe[dest_gate] == NFC_HCI_DO_NOT_CREATE_PIPE)
348+
if (pipe == NFC_HCI_DO_NOT_CREATE_PIPE)
349349
return 0;
350350

351351
if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE)
@@ -380,6 +380,8 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
380380
return r;
381381
}
382382

383+
hdev->pipes[pipe].gate = dest_gate;
384+
hdev->pipes[pipe].dest_host = dest_host;
383385
hdev->gate2pipe[dest_gate] = pipe;
384386

385387
return 0;

net/nfc/hci/core.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ int nfc_hci_result_to_errno(u8 result)
4646
}
4747
EXPORT_SYMBOL(nfc_hci_result_to_errno);
4848

49+
void nfc_hci_reset_pipes(struct nfc_hci_dev *hdev)
50+
{
51+
int i = 0;
52+
53+
for (i = 0; i < NFC_HCI_MAX_PIPES; i++) {
54+
hdev->pipes[i].gate = NFC_HCI_INVALID_GATE;
55+
hdev->pipes[i].dest_host = NFC_HCI_INVALID_HOST;
56+
}
57+
memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
58+
}
59+
EXPORT_SYMBOL(nfc_hci_reset_pipes);
60+
61+
void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host)
62+
{
63+
int i = 0;
64+
65+
for (i = 0; i < NFC_HCI_MAX_PIPES; i++) {
66+
if (hdev->pipes[i].dest_host != host)
67+
continue;
68+
69+
hdev->pipes[i].gate = NFC_HCI_INVALID_GATE;
70+
hdev->pipes[i].dest_host = NFC_HCI_INVALID_HOST;
71+
}
72+
}
73+
EXPORT_SYMBOL(nfc_hci_reset_pipes_per_host);
74+
4975
static void nfc_hci_msg_tx_work(struct work_struct *work)
5076
{
5177
struct nfc_hci_dev *hdev = container_of(work, struct nfc_hci_dev,
@@ -168,7 +194,7 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
168194
struct sk_buff *skb)
169195
{
170196
int r = 0;
171-
u8 gate = nfc_hci_pipe2gate(hdev, pipe);
197+
u8 gate = hdev->pipes[pipe].gate;
172198
u8 local_gate, new_pipe;
173199
u8 gate_opened = 0x00;
174200

@@ -330,9 +356,9 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
330356
struct sk_buff *skb)
331357
{
332358
int r = 0;
333-
u8 gate = nfc_hci_pipe2gate(hdev, pipe);
359+
u8 gate = hdev->pipes[pipe].gate;
334360

335-
if (gate == 0xff) {
361+
if (gate == NFC_HCI_INVALID_GATE) {
336362
pr_err("Discarded event %x to unopened pipe %x\n", event, pipe);
337363
goto exit;
338364
}
@@ -573,7 +599,7 @@ static int hci_dev_down(struct nfc_dev *nfc_dev)
573599
if (hdev->ops->close)
574600
hdev->ops->close(hdev);
575601

576-
memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
602+
nfc_hci_reset_pipes(hdev);
577603

578604
return 0;
579605
}
@@ -932,7 +958,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
932958

933959
nfc_set_drvdata(hdev->ndev, hdev);
934960

935-
memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
961+
nfc_hci_reset_pipes(hdev);
936962

937963
hdev->quirks = quirks;
938964

0 commit comments

Comments
 (0)