NFC: nci: Support logical connections management
authorChristophe Ricard <christophe.ricard@gmail.com>
Sun, 1 Feb 2015 21:26:12 +0000 (22:26 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 2 Feb 2015 20:50:39 +0000 (21:50 +0100)
In order to communicate with an NFCEE, we need to open a logical
connection to it, by sending the NCI_OP_CORE_CONN_CREATE_CMD
command to the NFCC. It's left up to the drivers to decide when
to close an already opened logical connection.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
include/net/nfc/nci.h
include/net/nfc/nci_core.h
net/nfc/nci/core.c
net/nfc/nci/rsp.c

index 230f227bb319602e51acfaf9cfd0fe29a6b11d57..deac78b9a53c956ce8e0417e4b950d8a2be773ed 100644 (file)
@@ -243,6 +243,26 @@ struct nci_core_set_config_cmd {
        struct  set_config_param param; /* support 1 param per cmd is enough */
 } __packed;
 
+#define NCI_OP_CORE_CONN_CREATE_CMD    nci_opcode_pack(NCI_GID_CORE, 0x04)
+struct dest_spec_params {
+       __u8    id;
+       __u8    protocol;
+} __packed;
+
+struct core_conn_create_dest_spec_params {
+       __u8    type;
+       __u8    length;
+       struct dest_spec_params value;
+} __packed;
+
+struct nci_core_conn_create_cmd {
+       __u8    destination_type;
+       __u8    number_destination_params;
+       struct core_conn_create_dest_spec_params params;
+} __packed;
+
+#define NCI_OP_CORE_CONN_CLOSE_CMD     nci_opcode_pack(NCI_GID_CORE, 0x05)
+
 #define NCI_OP_RF_DISCOVER_MAP_CMD     nci_opcode_pack(NCI_GID_RF_MGMT, 0x00)
 struct disc_map_config {
        __u8    rf_protocol;
@@ -327,6 +347,16 @@ struct nci_core_set_config_rsp {
        __u8    params_id[0];   /* variable size array */
 } __packed;
 
+#define NCI_OP_CORE_CONN_CREATE_RSP    nci_opcode_pack(NCI_GID_CORE, 0x04)
+struct nci_core_conn_create_rsp {
+       __u8    status;
+       __u8    max_ctrl_pkt_payload_len;
+       __u8    credits;
+       __u8    conn_id;
+} __packed;
+
+#define NCI_OP_CORE_CONN_CLOSE_RSP     nci_opcode_pack(NCI_GID_CORE, 0x05)
+
 #define NCI_OP_RF_DISCOVER_MAP_RSP     nci_opcode_pack(NCI_GID_RF_MGMT, 0x00)
 
 #define NCI_OP_RF_DISCOVER_RSP         nci_opcode_pack(NCI_GID_RF_MGMT, 0x03)
index 6cf6ee2b696d43cc8b450290003d919c0340673c..8ba3e38e4167a445b747d0e6d17dbb548845ed70 100644 (file)
@@ -186,6 +186,9 @@ int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, __u8 *val);
 
 int nci_nfcee_discover(struct nci_dev *ndev, u8 action);
 int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode);
+int nci_core_conn_create(struct nci_dev *ndev,
+                        struct core_conn_create_dest_spec_params *params);
+int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id);
 
 static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
                                            unsigned int len,
index e5fb8c8eed9469b6dbd5ae4bffcd7e8206ce53b5..2a96ed68c7bbf231747f544b8e693fc18cd44a35 100644 (file)
@@ -507,6 +507,44 @@ int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode)
 }
 EXPORT_SYMBOL(nci_nfcee_mode_set);
 
+static void nci_core_conn_create_req(struct nci_dev *ndev, unsigned long opt)
+{
+       struct nci_core_conn_create_cmd cmd;
+       struct core_conn_create_dest_spec_params *params =
+                               (struct core_conn_create_dest_spec_params *)opt;
+
+       cmd.destination_type = NCI_DESTINATION_NFCEE;
+       cmd.number_destination_params = 1;
+       memcpy(&cmd.params.type, params,
+              sizeof(struct core_conn_create_dest_spec_params));
+       nci_send_cmd(ndev, NCI_OP_CORE_CONN_CREATE_CMD,
+                    sizeof(struct nci_core_conn_create_cmd), &cmd);
+}
+
+int nci_core_conn_create(struct nci_dev *ndev,
+                        struct core_conn_create_dest_spec_params *params)
+{
+       ndev->cur_id = params->value.id;
+       return nci_request(ndev, nci_core_conn_create_req,
+                       (unsigned long)params,
+                       msecs_to_jiffies(NCI_CMD_TIMEOUT));
+}
+EXPORT_SYMBOL(nci_core_conn_create);
+
+static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
+{
+       __u8 conn_id = opt;
+
+       nci_send_cmd(ndev, NCI_OP_CORE_CONN_CLOSE_CMD, 1, &conn_id);
+}
+
+int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
+{
+       return nci_request(ndev, nci_core_conn_close_req, conn_id,
+                               msecs_to_jiffies(NCI_CMD_TIMEOUT));
+}
+EXPORT_SYMBOL(nci_core_conn_close);
+
 static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
index 0a3e98240dd644821d6799251137c0ae50b12b76..31ccf7d05e824c7a3fc574c4580730cdf0f12e67 100644 (file)
@@ -222,6 +222,45 @@ static void nci_nfcee_mode_set_rsp_packet(struct nci_dev *ndev,
        nci_req_complete(ndev, status);
 }
 
+static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev,
+                                           struct sk_buff *skb)
+{
+       __u8 status = skb->data[0];
+       struct nci_conn_info *conn_info;
+       struct nci_core_conn_create_rsp *rsp;
+
+       pr_debug("status 0x%x\n", status);
+
+       if (status == NCI_STATUS_OK) {
+               rsp = (struct nci_core_conn_create_rsp *)skb->data;
+               list_for_each_entry(conn_info, &ndev->conn_info_list, list) {
+                       if (conn_info->id == ndev->cur_id)
+                               break;
+               }
+
+               if (!conn_info || conn_info->id != ndev->cur_id) {
+                       status = NCI_STATUS_REJECTED;
+                       goto exit;
+               }
+
+               conn_info->conn_id = rsp->conn_id;
+               conn_info->max_pkt_payload_len = rsp->max_ctrl_pkt_payload_len;
+               atomic_set(&conn_info->credits_cnt, rsp->credits);
+       }
+
+exit:
+       nci_req_complete(ndev, status);
+}
+
+static void nci_core_conn_close_rsp_packet(struct nci_dev *ndev,
+                                          struct sk_buff *skb)
+{
+       __u8 status = skb->data[0];
+
+       pr_debug("status 0x%x\n", status);
+       nci_req_complete(ndev, status);
+}
+
 void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
 {
        __u16 rsp_opcode = nci_opcode(skb->data);
@@ -251,6 +290,14 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
                nci_core_set_config_rsp_packet(ndev, skb);
                break;
 
+       case NCI_OP_CORE_CONN_CREATE_RSP:
+               nci_core_conn_create_rsp_packet(ndev, skb);
+               break;
+
+       case NCI_OP_CORE_CONN_CLOSE_RSP:
+               nci_core_conn_close_rsp_packet(ndev, skb);
+               break;
+
        case NCI_OP_RF_DISCOVER_MAP_RSP:
                nci_rf_disc_map_rsp_packet(ndev, skb);
                break;
This page took 0.030631 seconds and 5 git commands to generate.