diff options
author | Christophe Ricard <christophe.ricard@gmail.com> | 2016-04-30 03:12:51 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2016-05-03 19:43:21 -0400 |
commit | 9b8d1a4cf2aa819d606b4e423a6523fc0d4460a2 (patch) | |
tree | 5862df9d18bb3e54f90b6fb81a23ac68ea0107a8 /net/nfc | |
parent | de5ea8517c2ae40785fe5d0a2d02fc71bef1761b (diff) |
nfc: nci: Add an additional parameter to identify a connection id
According to NCI specification, destination type and destination
specific parameters shall uniquely identify a single destination
for the Logical Connection.
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net/nfc')
-rw-r--r-- | net/nfc/nci/core.c | 25 | ||||
-rw-r--r-- | net/nfc/nci/ntf.c | 2 | ||||
-rw-r--r-- | net/nfc/nci/rsp.c | 20 |
3 files changed, 36 insertions, 11 deletions
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index 0884f1444817..74f2d54df4fc 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c | |||
@@ -64,18 +64,26 @@ struct nci_conn_info *nci_get_conn_info_by_conn_id(struct nci_dev *ndev, | |||
64 | return NULL; | 64 | return NULL; |
65 | } | 65 | } |
66 | 66 | ||
67 | int nci_get_conn_info_by_id(struct nci_dev *ndev, u8 id) | 67 | int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type, |
68 | struct dest_spec_params *params) | ||
68 | { | 69 | { |
69 | struct nci_conn_info *conn_info; | 70 | struct nci_conn_info *conn_info; |
70 | 71 | ||
71 | list_for_each_entry(conn_info, &ndev->conn_info_list, list) { | 72 | list_for_each_entry(conn_info, &ndev->conn_info_list, list) { |
72 | if (conn_info->id == id) | 73 | if (conn_info->dest_type == dest_type) { |
73 | return conn_info->conn_id; | 74 | if (!params) |
75 | return conn_info->conn_id; | ||
76 | if (conn_info) { | ||
77 | if (params->id == conn_info->dest_params->id && | ||
78 | params->protocol == conn_info->dest_params->protocol) | ||
79 | return conn_info->conn_id; | ||
80 | } | ||
81 | } | ||
74 | } | 82 | } |
75 | 83 | ||
76 | return -EINVAL; | 84 | return -EINVAL; |
77 | } | 85 | } |
78 | EXPORT_SYMBOL(nci_get_conn_info_by_id); | 86 | EXPORT_SYMBOL(nci_get_conn_info_by_dest_type_params); |
79 | 87 | ||
80 | /* ---- NCI requests ---- */ | 88 | /* ---- NCI requests ---- */ |
81 | 89 | ||
@@ -623,12 +631,15 @@ int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type, | |||
623 | if (params) { | 631 | if (params) { |
624 | memcpy(cmd->params, params, params_len); | 632 | memcpy(cmd->params, params, params_len); |
625 | if (params->length > 0) | 633 | if (params->length > 0) |
626 | ndev->cur_id = params->value[DEST_SPEC_PARAMS_ID_INDEX]; | 634 | memcpy(&ndev->cur_params, |
635 | ¶ms->value[DEST_SPEC_PARAMS_ID_INDEX], | ||
636 | sizeof(struct dest_spec_params)); | ||
627 | else | 637 | else |
628 | ndev->cur_id = 0; | 638 | ndev->cur_params.id = 0; |
629 | } else { | 639 | } else { |
630 | ndev->cur_id = 0; | 640 | ndev->cur_params.id = 0; |
631 | } | 641 | } |
642 | ndev->cur_dest_type = destination_type; | ||
632 | 643 | ||
633 | r = __nci_request(ndev, nci_core_conn_create_req, (unsigned long)&data, | 644 | r = __nci_request(ndev, nci_core_conn_create_req, (unsigned long)&data, |
634 | msecs_to_jiffies(NCI_CMD_TIMEOUT)); | 645 | msecs_to_jiffies(NCI_CMD_TIMEOUT)); |
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c index 2ada2b39e355..1e8c1a12aaec 100644 --- a/net/nfc/nci/ntf.c +++ b/net/nfc/nci/ntf.c | |||
@@ -734,7 +734,7 @@ static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev, | |||
734 | * “HCI Access”, even if the HCI Network contains multiple NFCEEs. | 734 | * “HCI Access”, even if the HCI Network contains multiple NFCEEs. |
735 | */ | 735 | */ |
736 | ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id; | 736 | ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id; |
737 | ndev->cur_id = nfcee_ntf->nfcee_id; | 737 | ndev->cur_params.id = nfcee_ntf->nfcee_id; |
738 | 738 | ||
739 | nci_req_complete(ndev, status); | 739 | nci_req_complete(ndev, status); |
740 | } | 740 | } |
diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c index 69fe163b7350..e3bbf1937d0e 100644 --- a/net/nfc/nci/rsp.c +++ b/net/nfc/nci/rsp.c | |||
@@ -226,7 +226,7 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, | |||
226 | struct sk_buff *skb) | 226 | struct sk_buff *skb) |
227 | { | 227 | { |
228 | __u8 status = skb->data[0]; | 228 | __u8 status = skb->data[0]; |
229 | struct nci_conn_info *conn_info; | 229 | struct nci_conn_info *conn_info = NULL; |
230 | struct nci_core_conn_create_rsp *rsp; | 230 | struct nci_core_conn_create_rsp *rsp; |
231 | 231 | ||
232 | pr_debug("status 0x%x\n", status); | 232 | pr_debug("status 0x%x\n", status); |
@@ -241,7 +241,17 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, | |||
241 | goto exit; | 241 | goto exit; |
242 | } | 242 | } |
243 | 243 | ||
244 | conn_info->id = ndev->cur_id; | 244 | conn_info->dest_params = devm_kzalloc(&ndev->nfc_dev->dev, |
245 | sizeof(struct dest_spec_params), | ||
246 | GFP_KERNEL); | ||
247 | if (!conn_info->dest_params) { | ||
248 | status = NCI_STATUS_REJECTED; | ||
249 | goto free_conn_info; | ||
250 | } | ||
251 | |||
252 | conn_info->dest_type = ndev->cur_dest_type; | ||
253 | conn_info->dest_params->id = ndev->cur_params.id; | ||
254 | conn_info->dest_params->protocol = ndev->cur_params.protocol; | ||
245 | conn_info->conn_id = rsp->conn_id; | 255 | conn_info->conn_id = rsp->conn_id; |
246 | 256 | ||
247 | /* Note: data_exchange_cb and data_exchange_cb_context need to | 257 | /* Note: data_exchange_cb and data_exchange_cb_context need to |
@@ -251,7 +261,7 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, | |||
251 | INIT_LIST_HEAD(&conn_info->list); | 261 | INIT_LIST_HEAD(&conn_info->list); |
252 | list_add(&conn_info->list, &ndev->conn_info_list); | 262 | list_add(&conn_info->list, &ndev->conn_info_list); |
253 | 263 | ||
254 | if (ndev->cur_id == ndev->hci_dev->nfcee_id) | 264 | if (ndev->cur_params.id == ndev->hci_dev->nfcee_id) |
255 | ndev->hci_dev->conn_info = conn_info; | 265 | ndev->hci_dev->conn_info = conn_info; |
256 | 266 | ||
257 | conn_info->conn_id = rsp->conn_id; | 267 | conn_info->conn_id = rsp->conn_id; |
@@ -259,7 +269,11 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, | |||
259 | atomic_set(&conn_info->credits_cnt, rsp->credits_cnt); | 269 | atomic_set(&conn_info->credits_cnt, rsp->credits_cnt); |
260 | } | 270 | } |
261 | 271 | ||
272 | free_conn_info: | ||
273 | if (status == NCI_STATUS_REJECTED) | ||
274 | devm_kfree(&ndev->nfc_dev->dev, conn_info); | ||
262 | exit: | 275 | exit: |
276 | |||
263 | nci_req_complete(ndev, status); | 277 | nci_req_complete(ndev, status); |
264 | } | 278 | } |
265 | 279 | ||