aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc
diff options
context:
space:
mode:
authorChristophe Ricard <christophe.ricard@gmail.com>2015-02-03 13:48:07 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2015-02-04 03:14:09 -0500
commit15d4a8da0e440faf589a26346c8287e1ed0abe6c (patch)
treed6ddf14215118c72dff898f57b24535e68225878 /net/nfc
parent3ba5c8466b320c3fd5d5861b34aa8a31dd0cf6b3 (diff)
NFC: nci: Move logical connection structure allocation
conn_info is currently allocated only after nfcee_discovery_ntf which is not generic enough for logical connection other than NFCEE. The corresponding conn_info is now created in nci_core_conn_create_rsp(). 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/hci.c8
-rw-r--r--net/nfc/nci/ntf.c23
-rw-r--r--net/nfc/nci/rsp.c29
3 files changed, 34 insertions, 26 deletions
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index ecf253942606..ed54ec533836 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -615,12 +615,20 @@ static int nci_hci_dev_connect_gates(struct nci_dev *ndev,
615 615
616int nci_hci_dev_session_init(struct nci_dev *ndev) 616int nci_hci_dev_session_init(struct nci_dev *ndev)
617{ 617{
618 struct nci_conn_info *conn_info;
618 struct sk_buff *skb; 619 struct sk_buff *skb;
619 int r; 620 int r;
620 621
621 ndev->hci_dev->count_pipes = 0; 622 ndev->hci_dev->count_pipes = 0;
622 ndev->hci_dev->expected_pipes = 0; 623 ndev->hci_dev->expected_pipes = 0;
623 624
625 conn_info = ndev->hci_dev->conn_info;
626 if (!conn_info)
627 return -EPROTO;
628
629 conn_info->data_exchange_cb = nci_hci_data_received_cb;
630 conn_info->data_exchange_cb_context = ndev;
631
624 nci_hci_reset_pipes(ndev->hci_dev); 632 nci_hci_reset_pipes(ndev->hci_dev);
625 633
626 if (ndev->hci_dev->init_data.gates[0].gate != NCI_HCI_ADMIN_GATE) 634 if (ndev->hci_dev->init_data.gates[0].gate != NCI_HCI_ADMIN_GATE)
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index 6bbbf6fdacc0..3218071072ac 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -723,7 +723,6 @@ static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
723 struct sk_buff *skb) 723 struct sk_buff *skb)
724{ 724{
725 u8 status = NCI_STATUS_OK; 725 u8 status = NCI_STATUS_OK;
726 struct nci_conn_info *conn_info;
727 struct nci_nfcee_discover_ntf *nfcee_ntf = 726 struct nci_nfcee_discover_ntf *nfcee_ntf =
728 (struct nci_nfcee_discover_ntf *)skb->data; 727 (struct nci_nfcee_discover_ntf *)skb->data;
729 728
@@ -734,27 +733,9 @@ static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
734 * and only one, NFCEE_DISCOVER_NTF with a Protocol type of 733 * and only one, NFCEE_DISCOVER_NTF with a Protocol type of
735 * “HCI Access”, even if the HCI Network contains multiple NFCEEs. 734 * “HCI Access”, even if the HCI Network contains multiple NFCEEs.
736 */ 735 */
737 if (!ndev->hci_dev->conn_info) { 736 ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id;
738 conn_info = devm_kzalloc(&ndev->nfc_dev->dev, 737 ndev->cur_id = nfcee_ntf->nfcee_id;
739 sizeof(*conn_info), GFP_KERNEL);
740 if (!conn_info) {
741 status = NCI_STATUS_REJECTED;
742 goto exit;
743 }
744
745 conn_info->id = nfcee_ntf->nfcee_id;
746 conn_info->conn_id = NCI_INVALID_CONN_ID;
747
748 conn_info->data_exchange_cb = nci_hci_data_received_cb;
749 conn_info->data_exchange_cb_context = ndev;
750 738
751 INIT_LIST_HEAD(&conn_info->list);
752 list_add(&conn_info->list, &ndev->conn_info_list);
753
754 ndev->hci_dev->conn_info = conn_info;
755 }
756
757exit:
758 nci_req_complete(ndev, status); 739 nci_req_complete(ndev, status);
759} 740}
760 741
diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c
index b419fed77ea3..02486bc2ceea 100644
--- a/net/nfc/nci/rsp.c
+++ b/net/nfc/nci/rsp.c
@@ -233,16 +233,27 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev,
233 233
234 if (status == NCI_STATUS_OK) { 234 if (status == NCI_STATUS_OK) {
235 rsp = (struct nci_core_conn_create_rsp *)skb->data; 235 rsp = (struct nci_core_conn_create_rsp *)skb->data;
236 list_for_each_entry(conn_info, &ndev->conn_info_list, list) {
237 if (conn_info->id == ndev->cur_id)
238 break;
239 }
240 236
241 if (!conn_info || conn_info->id != ndev->cur_id) { 237 conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
238 sizeof(*conn_info), GFP_KERNEL);
239 if (!conn_info) {
242 status = NCI_STATUS_REJECTED; 240 status = NCI_STATUS_REJECTED;
243 goto exit; 241 goto exit;
244 } 242 }
245 243
244 conn_info->id = ndev->cur_id;
245 conn_info->conn_id = rsp->conn_id;
246
247 /* Note: data_exchange_cb and data_exchange_cb_context need to
248 * be specify out of nci_core_conn_create_rsp_packet
249 */
250
251 INIT_LIST_HEAD(&conn_info->list);
252 list_add(&conn_info->list, &ndev->conn_info_list);
253
254 if (ndev->cur_id == ndev->hci_dev->nfcee_id)
255 ndev->hci_dev->conn_info = conn_info;
256
246 conn_info->conn_id = rsp->conn_id; 257 conn_info->conn_id = rsp->conn_id;
247 conn_info->max_pkt_payload_len = rsp->max_ctrl_pkt_payload_len; 258 conn_info->max_pkt_payload_len = rsp->max_ctrl_pkt_payload_len;
248 atomic_set(&conn_info->credits_cnt, rsp->credits_cnt); 259 atomic_set(&conn_info->credits_cnt, rsp->credits_cnt);
@@ -255,9 +266,17 @@ exit:
255static void nci_core_conn_close_rsp_packet(struct nci_dev *ndev, 266static void nci_core_conn_close_rsp_packet(struct nci_dev *ndev,
256 struct sk_buff *skb) 267 struct sk_buff *skb)
257{ 268{
269 struct nci_conn_info *conn_info;
258 __u8 status = skb->data[0]; 270 __u8 status = skb->data[0];
259 271
260 pr_debug("status 0x%x\n", status); 272 pr_debug("status 0x%x\n", status);
273 if (status == NCI_STATUS_OK) {
274 conn_info = nci_get_conn_info_by_conn_id(ndev, ndev->cur_id);
275 if (conn_info) {
276 list_del(&conn_info->list);
277 devm_kfree(&ndev->nfc_dev->dev, conn_info);
278 }
279 }
261 nci_req_complete(ndev, status); 280 nci_req_complete(ndev, status);
262} 281}
263 282