Commit 3c09e92f authored by David S. Miller's avatar David S. Miller

Merge tag 'nfc-next-3.20-2' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/nfc-next

NFC: 3.20 second pull request

This is the second NFC pull request for 3.20.

It brings:

- NCI NFCEE (NFC Execution Environment, typically an embedded or
  external secure element) discovery and enabling/disabling support.
  In order to communicate with an NFCEE, we also added NCI's logical
  connections support to the NCI stack.

- HCI over NCI protocol support. Some secure elements only understand
  HCI and thus we need to send them HCI frames when they're part of
  an NCI chipset.

- NFC_EVT_TRANSACTION userspace API addition. Whenever an application
  running on a secure element needs to notify its host counterpart,
  we send an NFC_EVENT_SE_TRANSACTION event to userspace through the
  NFC netlink socket.

- Secure element and HCI transaction event support for the st21nfcb
  chipset.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 020219a6 fa00e8fe
......@@ -301,6 +301,8 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
u8 event, struct sk_buff *skb)
{
int r = 0;
struct device *dev = &hdev->ndev->dev;
struct nfc_evt_transaction *transaction;
pr_debug("connectivity gate event: %x\n", event);
......@@ -308,6 +310,25 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
case ST21NFCA_EVT_CONNECTIVITY:
break;
case ST21NFCA_EVT_TRANSACTION:
if (skb->len < NFC_MIN_AID_LENGTH + 2 &&
skb->data[0] != NFC_EVT_TRANSACTION_AID_TAG)
return -EPROTO;
transaction = (struct nfc_evt_transaction *)devm_kzalloc(dev,
skb->len - 2, GFP_KERNEL);
transaction->aid_len = skb->data[1];
memcpy(transaction->aid, &skb->data[2], skb->data[1]);
if (skb->data[transaction->aid_len + 2] !=
NFC_EVT_TRANSACTION_PARAMS_TAG)
return -EPROTO;
transaction->params_len = skb->data[transaction->aid_len + 3];
memcpy(transaction->params, skb->data +
transaction->aid_len + 4, transaction->params_len);
r = nfc_se_transaction(hdev->ndev, host, transaction);
break;
default:
return 1;
......
......@@ -2,7 +2,7 @@
# Makefile for ST21NFCB NCI based NFC driver
#
st21nfcb_nci-objs = ndlc.o st21nfcb.o
st21nfcb_nci-objs = ndlc.o st21nfcb.o st21nfcb_se.o
obj-$(CONFIG_NFC_ST21NFCB) += st21nfcb_nci.o
st21nfcb_i2c-objs = i2c.o
......
......@@ -22,6 +22,7 @@
#include <net/nfc/nci_core.h>
#include "st21nfcb.h"
#include "st21nfcb_se.h"
#define DRIVER_DESC "NCI NFC driver for ST21NFCB"
......@@ -78,6 +79,13 @@ static struct nci_ops st21nfcb_nci_ops = {
.close = st21nfcb_nci_close,
.send = st21nfcb_nci_send,
.get_rfprotocol = st21nfcb_nci_get_rfprotocol,
.discover_se = st21nfcb_nci_discover_se,
.enable_se = st21nfcb_nci_enable_se,
.disable_se = st21nfcb_nci_disable_se,
.se_io = st21nfcb_nci_se_io,
.hci_load_session = st21nfcb_hci_load_session,
.hci_event_received = st21nfcb_hci_event_received,
.hci_cmd_received = st21nfcb_hci_cmd_received,
};
int st21nfcb_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
......@@ -114,9 +122,10 @@ int st21nfcb_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
if (r) {
pr_err("Cannot register nfc device to nci core\n");
nci_free_device(ndlc->ndev);
return r;
}
return r;
return st21nfcb_se_init(ndlc->ndev);
}
EXPORT_SYMBOL_GPL(st21nfcb_nci_probe);
......
......@@ -19,6 +19,7 @@
#ifndef __LOCAL_ST21NFCB_H_
#define __LOCAL_ST21NFCB_H_
#include "st21nfcb_se.h"
#include "ndlc.h"
/* Define private flags: */
......@@ -27,6 +28,7 @@
struct st21nfcb_nci_info {
struct llt_ndlc *ndlc;
unsigned long flags;
struct st21nfcb_se_info se_info;
};
void st21nfcb_nci_remove(struct nci_dev *ndev);
......
This diff is collapsed.
/*
* NCI based Driver for STMicroelectronics NFC Chip
*
* Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LOCAL_ST21NFCB_SE_H_
#define __LOCAL_ST21NFCB_SE_H_
/*
* ref ISO7816-3 chap 8.1. the initial character TS is followed by a
* sequence of at most 32 characters.
*/
#define ST21NFCB_ESE_MAX_LENGTH 33
#define ST21NFCB_HCI_HOST_ID_ESE 0xc0
struct st21nfcb_se_info {
u8 atr[ST21NFCB_ESE_MAX_LENGTH];
struct completion req_completion;
struct timer_list bwi_timer;
int wt_timeout; /* in msecs */
bool bwi_active;
struct timer_list se_active_timer;
bool se_active;
bool xch_error;
se_io_cb_t cb;
void *cb_context;
};
int st21nfcb_se_init(struct nci_dev *ndev);
void st21nfcb_se_deinit(struct nci_dev *ndev);
int st21nfcb_nci_discover_se(struct nci_dev *ndev);
int st21nfcb_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
int st21nfcb_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
int st21nfcb_nci_se_io(struct nci_dev *ndev, u32 se_idx,
u8 *apdu, size_t apdu_length,
se_io_cb_t cb, void *cb_context);
int st21nfcb_hci_load_session(struct nci_dev *ndev);
void st21nfcb_hci_event_received(struct nci_dev *ndev, u8 pipe,
u8 event, struct sk_buff *skb);
void st21nfcb_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
struct sk_buff *skb);
#endif /* __LOCAL_ST21NFCB_NCI_H_ */
......@@ -62,6 +62,25 @@
#define NCI_STATUS_NFCEE_PROTOCOL_ERROR 0xc2
#define NCI_STATUS_NFCEE_TIMEOUT_ERROR 0xc3
/* NFCEE Interface/Protocols */
#define NCI_NFCEE_INTERFACE_APDU 0x00
#define NCI_NFCEE_INTERFACE_HCI_ACCESS 0x01
#define NCI_NFCEE_INTERFACE_TYPE3_CMD_SET 0x02
#define NCI_NFCEE_INTERFACE_TRANSPARENT 0x03
/* Destination type */
#define NCI_DESTINATION_NFCC_LOOPBACK 0x01
#define NCI_DESTINATION_REMOTE_NFC_ENDPOINT 0x02
#define NCI_DESTINATION_NFCEE 0x03
/* Destination-specific parameters type */
#define NCI_DESTINATION_SPECIFIC_PARAM_RF_TYPE 0x00
#define NCI_DESTINATION_SPECIFIC_PARAM_NFCEE_TYPE 0x01
/* NFCEE Discovery Action */
#define NCI_NFCEE_DISCOVERY_ACTION_DISABLE 0x00
#define NCI_NFCEE_DISCOVERY_ACTION_ENABLE 0x01
/* NCI RF Technology and Mode */
#define NCI_NFC_A_PASSIVE_POLL_MODE 0x00
#define NCI_NFC_B_PASSIVE_POLL_MODE 0x01
......@@ -224,6 +243,28 @@ 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)
#define DEST_SPEC_PARAMS_ID_INDEX 0
#define DEST_SPEC_PARAMS_PROTOCOL_INDEX 1
struct dest_spec_params {
__u8 id;
__u8 protocol;
} __packed;
struct core_conn_create_dest_spec_params {
__u8 type;
__u8 length;
__u8 value[0];
} __packed;
struct nci_core_conn_create_cmd {
__u8 destination_type;
__u8 number_destination_params;
struct core_conn_create_dest_spec_params params[0];
} __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;
......@@ -260,6 +301,19 @@ struct nci_rf_deactivate_cmd {
__u8 type;
} __packed;
#define NCI_OP_NFCEE_DISCOVER_CMD nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x00)
struct nci_nfcee_discover_cmd {
__u8 discovery_action;
} __packed;
#define NCI_OP_NFCEE_MODE_SET_CMD nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x01)
#define NCI_NFCEE_DISABLE 0x00
#define NCI_NFCEE_ENABLE 0x01
struct nci_nfcee_mode_set_cmd {
__u8 nfcee_id;
__u8 nfcee_mode;
} __packed;
/* ----------------------- */
/* ---- NCI Responses ---- */
/* ----------------------- */
......@@ -295,6 +349,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_cnt;
__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)
......@@ -303,6 +367,13 @@ struct nci_core_set_config_rsp {
#define NCI_OP_RF_DEACTIVATE_RSP nci_opcode_pack(NCI_GID_RF_MGMT, 0x06)
#define NCI_OP_NFCEE_DISCOVER_RSP nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x00)
struct nci_nfcee_discover_rsp {
__u8 status;
__u8 num_nfcee;
} __packed;
#define NCI_OP_NFCEE_MODE_SET_RSP nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x01)
/* --------------------------- */
/* ---- NCI Notifications ---- */
/* --------------------------- */
......@@ -430,4 +501,30 @@ struct nci_rf_deactivate_ntf {
__u8 reason;
} __packed;
#define NCI_OP_RF_NFCEE_ACTION_NTF nci_opcode_pack(NCI_GID_RF_MGMT, 0x09)
struct nci_rf_nfcee_action_ntf {
__u8 nfcee_id;
__u8 trigger;
__u8 supported_data_length;
__u8 supported_data[0];
} __packed;
#define NCI_OP_NFCEE_DISCOVER_NTF nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x00)
struct nci_nfcee_supported_protocol {
__u8 num_protocol;
__u8 supported_protocol[0];
} __packed;
struct nci_nfcee_information_tlv {
__u8 num_tlv;
__u8 information_tlv[0];
} __packed;
struct nci_nfcee_discover_ntf {
__u8 nfcee_id;
__u8 nfcee_status;
struct nci_nfcee_supported_protocol supported_protocols;
struct nci_nfcee_information_tlv information_tlv;
} __packed;
#endif /* __NCI_H */
......@@ -78,15 +78,107 @@ struct nci_ops {
int (*se_io)(struct nci_dev *ndev, u32 se_idx,
u8 *apdu, size_t apdu_length,
se_io_cb_t cb, void *cb_context);
int (*hci_load_session)(struct nci_dev *ndev);
void (*hci_event_received)(struct nci_dev *ndev, u8 pipe, u8 event,
struct sk_buff *skb);
void (*hci_cmd_received)(struct nci_dev *ndev, u8 pipe, u8 cmd,
struct sk_buff *skb);
};
#define NCI_MAX_SUPPORTED_RF_INTERFACES 4
#define NCI_MAX_DISCOVERED_TARGETS 10
#define NCI_MAX_NUM_NFCEE 255
#define NCI_MAX_CONN_ID 7
struct nci_conn_info {
struct list_head list;
__u8 id; /* can be an RF Discovery ID or an NFCEE ID */
__u8 conn_id;
__u8 max_pkt_payload_len;
atomic_t credits_cnt;
__u8 initial_num_credits;
data_exchange_cb_t data_exchange_cb;
void *data_exchange_cb_context;
struct sk_buff *rx_skb;
};
#define NCI_INVALID_CONN_ID 0x80
#define NCI_HCI_ANY_OPEN_PIPE 0x03
/* Gates */
#define NCI_HCI_ADMIN_GATE 0x00
#define NCI_HCI_LINK_MGMT_GATE 0x06
/* Pipes */
#define NCI_HCI_LINK_MGMT_PIPE 0x00
#define NCI_HCI_ADMIN_PIPE 0x01
/* Generic responses */
#define NCI_HCI_ANY_OK 0x00
#define NCI_HCI_ANY_E_NOT_CONNECTED 0x01
#define NCI_HCI_ANY_E_CMD_PAR_UNKNOWN 0x02
#define NCI_HCI_ANY_E_NOK 0x03
#define NCI_HCI_ANY_E_PIPES_FULL 0x04
#define NCI_HCI_ANY_E_REG_PAR_UNKNOWN 0x05
#define NCI_HCI_ANY_E_PIPE_NOT_OPENED 0x06
#define NCI_HCI_ANY_E_CMD_NOT_SUPPORTED 0x07
#define NCI_HCI_ANY_E_INHIBITED 0x08
#define NCI_HCI_ANY_E_TIMEOUT 0x09
#define NCI_HCI_ANY_E_REG_ACCESS_DENIED 0x0a
#define NCI_HCI_ANY_E_PIPE_ACCESS_DENIED 0x0b
#define NCI_HCI_DO_NOT_OPEN_PIPE 0x81
#define NCI_HCI_INVALID_PIPE 0x80
#define NCI_HCI_INVALID_GATE 0xFF
#define NCI_HCI_INVALID_HOST 0x80
#define NCI_HCI_MAX_CUSTOM_GATES 50
#define NCI_HCI_MAX_PIPES 127
struct nci_hci_gate {
u8 gate;
u8 pipe;
u8 dest_host;
} __packed;
struct nci_hci_pipe {
u8 gate;
u8 host;
} __packed;
struct nci_hci_init_data {
u8 gate_count;
struct nci_hci_gate gates[NCI_HCI_MAX_CUSTOM_GATES];
char session_id[9];
};
#define NCI_HCI_MAX_GATES 256
struct nci_hci_dev {
u8 nfcee_id;
struct nci_dev *ndev;
struct nci_conn_info *conn_info;
struct nci_hci_init_data init_data;
struct nci_hci_pipe pipes[NCI_HCI_MAX_PIPES];
u8 gate2pipe[NCI_HCI_MAX_GATES];
int expected_pipes;
int count_pipes;
struct sk_buff_head rx_hcp_frags;
struct work_struct msg_rx_work;
struct sk_buff_head msg_rx_queue;
};
/* NCI Core structures */
struct nci_dev {
struct nfc_dev *nfc_dev;
struct nci_ops *ops;
struct nci_hci_dev *hci_dev;
int tx_headroom;
int tx_tailroom;
......@@ -95,7 +187,10 @@ struct nci_dev {
unsigned long flags;
atomic_t cmd_cnt;
atomic_t credits_cnt;
__u8 cur_conn_id;
struct list_head conn_info_list;
struct nci_conn_info *rf_conn_info;
struct timer_list cmd_timer;
struct timer_list data_timer;
......@@ -141,13 +236,10 @@ struct nci_dev {
__u8 manufact_id;
__u32 manufact_specific_info;
/* received during NCI_OP_RF_INTF_ACTIVATED_NTF */
__u8 max_data_pkt_payload_size;
__u8 initial_num_credits;
/* Save RF Discovery ID or NFCEE ID under conn_create */
__u8 cur_id;
/* stored during nci_data_exchange */
data_exchange_cb_t data_exchange_cb;
void *data_exchange_cb_context;
struct sk_buff *rx_data_reassembly;
/* stored during intf_activated_ntf */
......@@ -163,9 +255,36 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
void nci_free_device(struct nci_dev *ndev);
int nci_register_device(struct nci_dev *ndev);
void nci_unregister_device(struct nci_dev *ndev);
int nci_request(struct nci_dev *ndev,
void (*req)(struct nci_dev *ndev,
unsigned long opt),
unsigned long opt, __u32 timeout);
int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
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, u8 destination_type,
u8 number_destination_params,
size_t params_len,
struct core_conn_create_dest_spec_params *params);
int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id);
struct nci_hci_dev *nci_hci_allocate(struct nci_dev *ndev);
int nci_hci_send_event(struct nci_dev *ndev, u8 gate, u8 event,
const u8 *param, size_t param_len);
int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate,
u8 cmd, const u8 *param, size_t param_len,
struct sk_buff **skb);
int nci_hci_open_pipe(struct nci_dev *ndev, u8 pipe);
int nci_hci_connect_gate(struct nci_dev *ndev, u8 dest_host,
u8 dest_gate, u8 pipe);
int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
const u8 *param, size_t param_len);
int nci_hci_get_param(struct nci_dev *ndev, u8 gate, u8 idx,
struct sk_buff **skb);
int nci_hci_dev_session_init(struct nci_dev *ndev);
static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
unsigned int len,
gfp_t how)
......@@ -200,7 +319,9 @@ void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb);
int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload);
int nci_send_data(struct nci_dev *ndev, __u8 conn_id, struct sk_buff *skb);
void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
int err);
__u8 conn_id, int err);
void nci_hci_data_received_cb(void *context, struct sk_buff *skb, int err);
void nci_clear_target_list(struct nci_dev *ndev);
/* ----- NCI requests ----- */
......@@ -209,6 +330,8 @@ void nci_clear_target_list(struct nci_dev *ndev);
#define NCI_REQ_CANCELED 2
void nci_req_complete(struct nci_dev *ndev, int result);
struct nci_conn_info *nci_get_conn_info_by_conn_id(struct nci_dev *ndev,
int conn_id);
/* ----- NCI status code ----- */
int nci_to_errno(__u8 code);
......
......@@ -135,6 +135,31 @@ struct nfc_se {
u16 state;
};
/**
* nfc_evt_transaction - A struct for NFC secure element event transaction.
*
* @aid: The application identifier triggering the event
*
* @aid_len: The application identifier length [5:16]
*
* @params: The application parameters transmitted during the transaction
*
* @params_len: The applications parameters length [0:255]
*
*/
#define NFC_MIN_AID_LENGTH 5
#define NFC_MAX_AID_LENGTH 16
#define NFC_MAX_PARAMS_LENGTH 255
#define NFC_EVT_TRANSACTION_AID_TAG 0x81
#define NFC_EVT_TRANSACTION_PARAMS_TAG 0x82
struct nfc_evt_transaction {
u32 aid_len;
u8 aid[NFC_MAX_AID_LENGTH];
u8 params_len;
u8 params[NFC_MAX_PARAMS_LENGTH];
} __packed;
struct nfc_genl_data {
u32 poll_req_portid;
struct mutex genl_data_mutex;
......@@ -262,6 +287,8 @@ int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb);
void nfc_driver_failure(struct nfc_dev *dev, int err);
int nfc_se_transaction(struct nfc_dev *dev, u8 se_idx,
struct nfc_evt_transaction *evt_transaction);
int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type);
int nfc_remove_se(struct nfc_dev *dev, u32 se_idx);
struct nfc_se *nfc_find_se(struct nfc_dev *dev, u32 se_idx);
......
......@@ -183,6 +183,7 @@ enum nfc_attrs {
NFC_ATTR_SE_APDU,
NFC_ATTR_TARGET_ISO15693_DSFID,
NFC_ATTR_TARGET_ISO15693_UID,
NFC_ATTR_SE_PARAMS,
/* private: internal use only */
__NFC_ATTR_AFTER_LAST
};
......
......@@ -932,6 +932,27 @@ int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
}
EXPORT_SYMBOL(nfc_remove_se);
int nfc_se_transaction(struct nfc_dev *dev, u8 se_idx,
struct nfc_evt_transaction *evt_transaction)
{
int rc;
pr_debug("transaction: %x\n", se_idx);
device_lock(&dev->dev);
if (!evt_transaction) {
rc = -EPROTO;
goto out;
}
rc = nfc_genl_se_transaction(dev, se_idx, evt_transaction);
out:
device_unlock(&dev->dev);
return rc;
}
EXPORT_SYMBOL(nfc_se_transaction);
static void nfc_release(struct device *d)
{
struct nfc_dev *dev = to_nfc_dev(d);
......
......@@ -4,6 +4,6 @@
obj-$(CONFIG_NFC_NCI) += nci.o
nci-objs := core.o data.o lib.o ntf.o rsp.o
nci-objs := core.o data.o lib.o ntf.o rsp.o hci.o
nci-$(CONFIG_NFC_NCI_SPI) += spi.o
......@@ -41,10 +41,28 @@
#include <net/nfc/nci_core.h>
#include <linux/nfc.h>
struct core_conn_create_data {
int length;
struct nci_core_conn_create_cmd *cmd;
};
static void nci_cmd_work(struct work_struct *work);
static void nci_rx_work(struct work_struct *work);
static void nci_tx_work(struct work_struct *work);
struct nci_conn_info *nci_get_conn_info_by_conn_id(struct nci_dev *ndev,
int conn_id)
{
struct nci_conn_info *conn_info;
list_for_each_entry(conn_info, &ndev->conn_info_list, list) {
if (conn_info->conn_id == conn_id)
return conn_info;
}
return NULL;
}
/* ---- NCI requests ---- */
void nci_req_complete(struct nci_dev *ndev, int result)
......@@ -109,10 +127,10 @@ static int __nci_request(struct nci_dev *ndev,
return rc;
}
static inline int nci_request(struct nci_dev *ndev,
void (*req)(struct nci_dev *ndev,
unsigned long opt),
unsigned long opt, __u32 timeout)
inline int nci_request(struct nci_dev *ndev,
void (*req)(struct nci_dev *ndev,
unsigned long opt),
unsigned long opt, __u32 timeout)
{
int rc;
......@@ -456,6 +474,95 @@ int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, __u8 *val)
}
EXPORT_SYMBOL(nci_set_config);
static void nci_nfcee_discover_req(struct nci_dev *ndev, unsigned long opt)
{
struct nci_nfcee_discover_cmd cmd;
__u8 action = opt;
cmd.discovery_action = action;
nci_send_cmd(ndev, NCI_OP_NFCEE_DISCOVER_CMD, 1, &cmd);
}
int nci_nfcee_discover(struct nci_dev *ndev, u8 action)
{
return nci_request(ndev, nci_nfcee_discover_req, action,
msecs_to_jiffies(NCI_CMD_TIMEOUT));
}
EXPORT_SYMBOL(nci_nfcee_discover);
static void nci_nfcee_mode_set_req(struct nci_dev *ndev, unsigned long opt)
{
struct nci_nfcee_mode_set_cmd *cmd =
(struct nci_nfcee_mode_set_cmd *)opt;
nci_send_cmd(ndev, NCI_OP_NFCEE_MODE_SET_CMD,
sizeof(struct nci_nfcee_mode_set_cmd), cmd);
}
int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode)
{
struct nci_nfcee_mode_set_cmd cmd;
cmd.nfcee_id = nfcee_id;
cmd.nfcee_mode = nfcee_mode;
return nci_request(ndev, nci_nfcee_mode_set_req, (unsigned long)&cmd,
msecs_to_jiffies(NCI_CMD_TIMEOUT));
}
EXPORT_SYMBOL(nci_nfcee_mode_set);
static void nci_core_conn_create_req(struct nci_dev *ndev, unsigned long opt)
{
struct core_conn_create_data *data =
(struct core_conn_create_data *)opt;
nci_send_cmd(ndev, NCI_OP_CORE_CONN_CREATE_CMD, data->length, data->cmd);
}
int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
u8 number_destination_params,
size_t params_len,
struct core_conn_create_dest_spec_params *params)
{
int r;
struct nci_core_conn_create_cmd *cmd;
struct core_conn_create_data data;
data.length = params_len + sizeof(struct nci_core_conn_create_cmd);
cmd = kzalloc(data.length, GFP_KERNEL);
if (!cmd)
return -ENOMEM;
cmd->destination_type = destination_type;
cmd->number_destination_params = number_destination_params;
memcpy(cmd->params, params, params_len);
data.cmd = cmd;
ndev->cur_id = params->value[DEST_SPEC_PARAMS_ID_INDEX];
r = __nci_request(ndev, nci_core_conn_create_req,
(unsigned long)&data,
msecs_to_jiffies(NCI_CMD_TIMEOUT));
kfree(cmd);
return r;
}
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);
......@@ -712,6 +819,11 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
{
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
int rc;
struct nci_conn_info *conn_info;
conn_info = ndev->rf_conn_info;
if (!conn_info)
return -EPROTO;
pr_debug("target_idx %d, len %d\n", target->idx, skb->len);
......@@ -724,8 +836,8 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
return -EBUSY;
/* store cb and context to be used on receiving data */
ndev->data_exchange_cb = cb;
ndev->data_exchange_cb_context = cb_context;
conn_info->data_exchange_cb = cb;
conn_info->data_exchange_cb_context = cb_context;
rc = nci_send_data(ndev, NCI_STATIC_RF_CONN_ID, skb);
if (rc)
......@@ -768,10 +880,16 @@ static int nci_disable_se(struct nfc_dev *nfc_dev, u32 se_idx)
static int nci_discover_se(struct nfc_dev *nfc_dev)
{
int r;
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
if (ndev->ops->discover_se)
if (ndev->ops->discover_se) {
r = nci_nfcee_discover(ndev, NCI_NFCEE_DISCOVERY_ACTION_ENABLE);
if (r != NCI_STATUS_OK)
return -EPROTO;
return ndev->ops->discover_se(ndev);
}
return 0;
}
......@@ -807,7 +925,6 @@ static struct nfc_ops nci_nfc_ops = {
};
/* ---- Interface to NCI drivers ---- */
/**
* nci_allocate_device - allocate a new nci device
*
......@@ -842,13 +959,20 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
tx_headroom + NCI_DATA_HDR_SIZE,
tx_tailroom);
if (!ndev->nfc_dev)
goto free_exit;
goto free_nci;
ndev->hci_dev = nci_hci_allocate(ndev);
if (!ndev->hci_dev)
goto free_nfc;
nfc_set_drvdata(ndev->nfc_dev, ndev);
return ndev;
free_exit:
free_nfc:
kfree(ndev->nfc_dev);
free_nci:
kfree(ndev);
return NULL;
}
......@@ -913,6 +1037,7 @@ int nci_register_device(struct nci_dev *ndev)
(unsigned long) ndev);
mutex_init(&ndev->req_lock);
INIT_LIST_HEAD(&ndev->conn_info_list);
rc = nfc_register_device(ndev->nfc_dev);
if (rc)
......@@ -938,12 +1063,19 @@ EXPORT_SYMBOL(nci_register_device);
*/
void nci_unregister_device(struct nci_dev *ndev)
{
struct nci_conn_info *conn_info, *n;
nci_close_device(ndev);
destroy_workqueue(ndev->cmd_wq);
destroy_workqueue(ndev->rx_wq);
destroy_workqueue(ndev->tx_wq);
list_for_each_entry_safe(conn_info, n, &ndev->conn_info_list, list) {
list_del(&conn_info->list);
/* conn_info is allocated with devm_kzalloc */
}
nfc_unregister_device(ndev->nfc_dev);
}
EXPORT_SYMBOL(nci_unregister_device);
......@@ -1027,20 +1159,25 @@ int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload)
static void nci_tx_work(struct work_struct *work)
{
struct nci_dev *ndev = container_of(work, struct nci_dev, tx_work);
struct nci_conn_info *conn_info;
struct sk_buff *skb;
pr_debug("credits_cnt %d\n", atomic_read(&ndev->credits_cnt));
conn_info = nci_get_conn_info_by_conn_id(ndev, ndev->cur_conn_id);
if (!conn_info)
return;
pr_debug("credits_cnt %d\n", atomic_read(&conn_info->credits_cnt));
/* Send queued tx data */
while (atomic_read(&ndev->credits_cnt)) {
while (atomic_read(&conn_info->credits_cnt)) {
skb = skb_dequeue(&ndev->tx_q);
if (!skb)
return;
/* Check if data flow control is used */
if (atomic_read(&ndev->credits_cnt) !=
if (atomic_read(&conn_info->credits_cnt) !=
NCI_DATA_FLOW_CONTROL_NOT_USED)
atomic_dec(&ndev->credits_cnt);
atomic_dec(&conn_info->credits_cnt);
pr_debug("NCI TX: MT=data, PBF=%d, conn_id=%d, plen=%d\n",
nci_pbf(skb->data),
......@@ -1092,7 +1229,9 @@ static void nci_rx_work(struct work_struct *work)
if (test_bit(NCI_DATA_EXCHANGE_TO, &ndev->flags)) {
/* complete the data exchange transaction, if exists */
if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
nci_data_exchange_complete(ndev, NULL, -ETIMEDOUT);
nci_data_exchange_complete(ndev, NULL,
ndev->cur_conn_id,
-ETIMEDOUT);
clear_bit(NCI_DATA_EXCHANGE_TO, &ndev->flags);
}
......
......@@ -36,10 +36,20 @@
/* Complete data exchange transaction and forward skb to nfc core */
void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
int err)
__u8 conn_id, int err)
{
data_exchange_cb_t cb = ndev->data_exchange_cb;
void *cb_context = ndev->data_exchange_cb_context;
struct nci_conn_info *conn_info;
data_exchange_cb_t cb;
void *cb_context;
conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id);
if (!conn_info) {
kfree_skb(skb);
goto exit;
}
cb = conn_info->data_exchange_cb;
cb_context = conn_info->data_exchange_cb_context;
pr_debug("len %d, err %d\n", skb ? skb->len : 0, err);
......@@ -48,9 +58,6 @@ void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
clear_bit(NCI_DATA_EXCHANGE_TO, &ndev->flags);
if (cb) {
ndev->data_exchange_cb = NULL;
ndev->data_exchange_cb_context = NULL;
/* forward skb to nfc core */
cb(cb_context, skb, err);
} else if (skb) {
......@@ -60,6 +67,7 @@ void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
kfree_skb(skb);
}
exit:
clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
}
......@@ -85,6 +93,7 @@ static inline void nci_push_data_hdr(struct nci_dev *ndev,
static int nci_queue_tx_data_frags(struct nci_dev *ndev,
__u8 conn_id,
struct sk_buff *skb) {
struct nci_conn_info *conn_info;
int total_len = skb->len;
unsigned char *data = skb->data;
unsigned long flags;
......@@ -95,11 +104,17 @@ static int nci_queue_tx_data_frags(struct nci_dev *ndev,
pr_debug("conn_id 0x%x, total_len %d\n", conn_id, total_len);
conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id);
if (!conn_info) {
rc = -EPROTO;
goto free_exit;
}
__skb_queue_head_init(&frags_q);
while (total_len) {
frag_len =
min_t(int, total_len, ndev->max_data_pkt_payload_size);
min_t(int, total_len, conn_info->max_pkt_payload_len);
skb_frag = nci_skb_alloc(ndev,
(NCI_DATA_HDR_SIZE + frag_len),
......@@ -151,12 +166,19 @@ static int nci_queue_tx_data_frags(struct nci_dev *ndev,
/* Send NCI data */
int nci_send_data(struct nci_dev *ndev, __u8 conn_id, struct sk_buff *skb)
{
struct nci_conn_info *conn_info;
int rc = 0;
pr_debug("conn_id 0x%x, plen %d\n", conn_id, skb->len);
conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id);
if (!conn_info) {
rc = -EPROTO;
goto free_exit;
}
/* check if the packet need to be fragmented */
if (skb->len <= ndev->max_data_pkt_payload_size) {
if (skb->len <= conn_info->max_pkt_payload_len) {
/* no need to fragment packet */
nci_push_data_hdr(ndev, conn_id, skb, NCI_PBF_LAST);
......@@ -170,6 +192,7 @@ int nci_send_data(struct nci_dev *ndev, __u8 conn_id, struct sk_buff *skb)
}
}
ndev->cur_conn_id = conn_id;
queue_work(ndev->tx_wq, &ndev->tx_work);
goto exit;
......@@ -185,7 +208,7 @@ int nci_send_data(struct nci_dev *ndev, __u8 conn_id, struct sk_buff *skb)
static void nci_add_rx_data_frag(struct nci_dev *ndev,
struct sk_buff *skb,
__u8 pbf, __u8 status)
__u8 pbf, __u8 conn_id, __u8 status)
{
int reassembly_len;
int err = 0;
......@@ -229,16 +252,13 @@ static void nci_add_rx_data_frag(struct nci_dev *ndev,
}
exit:
if (ndev->nfc_dev->rf_mode == NFC_RF_INITIATOR) {
nci_data_exchange_complete(ndev, skb, err);
} else if (ndev->nfc_dev->rf_mode == NFC_RF_TARGET) {
if (ndev->nfc_dev->rf_mode == NFC_RF_TARGET) {
/* Data received in Target mode, forward to nfc core */
err = nfc_tm_data_received(ndev->nfc_dev, skb);
if (err)
pr_err("unable to handle received data\n");
} else {
pr_err("rf mode unknown\n");
kfree_skb(skb);
nci_data_exchange_complete(ndev, skb, conn_id, err);
}
}
......@@ -247,6 +267,8 @@ void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb)
{
__u8 pbf = nci_pbf(skb->data);
__u8 status = 0;
__u8 conn_id = nci_conn_id(skb->data);
struct nci_conn_info *conn_info;
pr_debug("len %d\n", skb->len);
......@@ -255,6 +277,10 @@ void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb)
nci_conn_id(skb->data),
nci_plen(skb->data));
conn_info = nci_get_conn_info_by_conn_id(ndev, nci_conn_id(skb->data));
if (!conn_info)
return;
/* strip the nci data header */
skb_pull(skb, NCI_DATA_HDR_SIZE);
......@@ -268,5 +294,5 @@ void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb)
skb_trim(skb, (skb->len - 1));
}
nci_add_rx_data_frag(ndev, skb, pbf, nci_to_errno(status));
nci_add_rx_data_frag(ndev, skb, pbf, conn_id, nci_to_errno(status));
}
This diff is collapsed.
......@@ -43,6 +43,7 @@ static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
struct nci_core_conn_credit_ntf *ntf = (void *) skb->data;
struct nci_conn_info *conn_info;
int i;
pr_debug("num_entries %d\n", ntf->num_entries);
......@@ -59,11 +60,13 @@ static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
i, ntf->conn_entries[i].conn_id,
ntf->conn_entries[i].credits);
if (ntf->conn_entries[i].conn_id == NCI_STATIC_RF_CONN_ID) {
/* found static rf connection */
atomic_add(ntf->conn_entries[i].credits,
&ndev->credits_cnt);
}
conn_info = nci_get_conn_info_by_conn_id(ndev,
ntf->conn_entries[i].conn_id);
if (!conn_info)
return;
atomic_add(ntf->conn_entries[i].credits,
&conn_info->credits_cnt);
}
/* trigger the next tx */
......@@ -96,7 +99,7 @@ static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev,
/* complete the data exchange transaction, if exists */
if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
nci_data_exchange_complete(ndev, NULL, -EIO);
nci_data_exchange_complete(ndev, NULL, ntf->conn_id, -EIO);
}
static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev,
......@@ -513,6 +516,7 @@ static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
struct nci_conn_info *conn_info;
struct nci_rf_intf_activated_ntf ntf;
__u8 *data = skb->data;
int err = NCI_STATUS_OK;
......@@ -537,6 +541,13 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
pr_debug("rf_tech_specific_params_len %d\n",
ntf.rf_tech_specific_params_len);
/* If this contains a value of 0x00 (NFCEE Direct RF
* Interface) then all following parameters SHALL contain a
* value of 0 and SHALL be ignored.
*/
if (ntf.rf_interface == NCI_RF_INTERFACE_NFCEE_DIRECT)
goto listen;
if (ntf.rf_tech_specific_params_len > 0) {
switch (ntf.activation_rf_tech_and_mode) {
case NCI_NFC_A_PASSIVE_POLL_MODE:
......@@ -614,11 +625,16 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
exit:
if (err == NCI_STATUS_OK) {
ndev->max_data_pkt_payload_size = ntf.max_data_pkt_payload_size;
ndev->initial_num_credits = ntf.initial_num_credits;
conn_info = ndev->rf_conn_info;
if (!conn_info)
return;
conn_info->max_pkt_payload_len = ntf.max_data_pkt_payload_size;
conn_info->initial_num_credits = ntf.initial_num_credits;
/* set the available credits to initial value */
atomic_set(&ndev->credits_cnt, ndev->initial_num_credits);
atomic_set(&conn_info->credits_cnt,
conn_info->initial_num_credits);
/* store general bytes to be reported later in dep_link_up */
if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) {
......@@ -643,6 +659,7 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
nci_req_complete(ndev, err);
}
} else {
listen:
/* Listen mode */
atomic_set(&ndev->state, NCI_LISTEN_ACTIVE);
if (err == NCI_STATUS_OK &&
......@@ -661,10 +678,15 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
struct nci_conn_info *conn_info;
struct nci_rf_deactivate_ntf *ntf = (void *) skb->data;
pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
conn_info = ndev->rf_conn_info;
if (!conn_info)
return;
/* drop tx data queue */
skb_queue_purge(&ndev->tx_q);
......@@ -676,7 +698,8 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
/* complete the data exchange transaction, if exists */
if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
nci_data_exchange_complete(ndev, NULL, -EIO);
nci_data_exchange_complete(ndev, NULL, NCI_STATIC_RF_CONN_ID,
-EIO);
switch (ntf->type) {
case NCI_DEACTIVATE_TYPE_IDLE_MODE:
......@@ -696,6 +719,32 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
nci_req_complete(ndev, NCI_STATUS_OK);
}
static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
u8 status = NCI_STATUS_OK;
struct nci_nfcee_discover_ntf *nfcee_ntf =
(struct nci_nfcee_discover_ntf *)skb->data;
pr_debug("\n");
/* NFCForum NCI 9.2.1 HCI Network Specific Handling
* If the NFCC supports the HCI Network, it SHALL return one,
* and only one, NFCEE_DISCOVER_NTF with a Protocol type of
* “HCI Access”, even if the HCI Network contains multiple NFCEEs.
*/
ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id;
ndev->cur_id = nfcee_ntf->nfcee_id;
nci_req_complete(ndev, status);
}
static void nci_nfcee_action_ntf_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
pr_debug("\n");
}
void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
{
__u16 ntf_opcode = nci_opcode(skb->data);
......@@ -734,6 +783,14 @@ void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
nci_rf_deactivate_ntf_packet(ndev, skb);
break;
case NCI_OP_NFCEE_DISCOVER_NTF:
nci_nfcee_discover_ntf_packet(ndev, skb);
break;
case NCI_OP_RF_NFCEE_ACTION_NTF:
nci_nfcee_action_ntf_packet(ndev, skb);
break;
default:
pr_err("unknown ntf opcode 0x%x\n", ntf_opcode);
break;
......
......@@ -140,13 +140,31 @@ static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev,
static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
{
struct nci_conn_info *conn_info;
__u8 status = skb->data[0];
pr_debug("status 0x%x\n", status);
if (status == NCI_STATUS_OK)
if (status == NCI_STATUS_OK) {
atomic_set(&ndev->state, NCI_DISCOVERY);
conn_info = ndev->rf_conn_info;
if (!conn_info) {
conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
sizeof(struct nci_conn_info),
GFP_KERNEL);
if (!conn_info) {
status = NCI_STATUS_REJECTED;
goto exit;
}
conn_info->conn_id = NCI_STATIC_RF_CONN_ID;
INIT_LIST_HEAD(&conn_info->list);
list_add(&conn_info->list, &ndev->conn_info_list);
ndev->rf_conn_info = conn_info;
}
}
exit:
nci_req_complete(ndev, status);
}
......@@ -178,6 +196,90 @@ static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
}
}
static void nci_nfcee_discover_rsp_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
struct nci_nfcee_discover_rsp *discover_rsp;
if (skb->len != 2) {
nci_req_complete(ndev, NCI_STATUS_NFCEE_PROTOCOL_ERROR);
return;
}
discover_rsp = (struct nci_nfcee_discover_rsp *)skb->data;
if (discover_rsp->status != NCI_STATUS_OK ||
discover_rsp->num_nfcee == 0)
nci_req_complete(ndev, discover_rsp->status);
}
static void nci_nfcee_mode_set_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);
}
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;
conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
sizeof(*conn_info), GFP_KERNEL);
if (!conn_info) {
status = NCI_STATUS_REJECTED;
goto exit;
}
conn_info->id = ndev->cur_id;
conn_info->conn_id = rsp->conn_id;
/* Note: data_exchange_cb and data_exchange_cb_context need to
* be specify out of nci_core_conn_create_rsp_packet
*/
INIT_LIST_HEAD(&conn_info->list);
list_add(&conn_info->list, &ndev->conn_info_list);
if (ndev->cur_id == ndev->hci_dev->nfcee_id)
ndev->hci_dev->conn_info = conn_info;
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_cnt);
}
exit:
nci_req_complete(ndev, status);
}
static void nci_core_conn_close_rsp_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
struct nci_conn_info *conn_info;
__u8 status = skb->data[0];
pr_debug("status 0x%x\n", status);
if (status == NCI_STATUS_OK) {
conn_info = nci_get_conn_info_by_conn_id(ndev, ndev->cur_id);
if (conn_info) {
list_del(&conn_info->list);
devm_kfree(&ndev->nfc_dev->dev, conn_info);
}
}
nci_req_complete(ndev, status);
}
void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
{
__u16 rsp_opcode = nci_opcode(skb->data);
......@@ -207,6 +309,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;
......@@ -223,6 +333,14 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
nci_rf_deactivate_rsp_packet(ndev, skb);
break;
case NCI_OP_NFCEE_DISCOVER_RSP:
nci_nfcee_discover_rsp_packet(ndev, skb);
break;
case NCI_OP_NFCEE_MODE_SET_RSP:
nci_nfcee_mode_set_rsp_packet(ndev, skb);
break;
default:
pr_err("unknown rsp opcode 0x%x\n", rsp_opcode);
break;
......
......@@ -497,6 +497,53 @@ int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
return -EMSGSIZE;
}
int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx,
struct nfc_evt_transaction *evt_transaction)
{
struct nfc_se *se;
struct sk_buff *msg;
void *hdr;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
NFC_EVENT_SE_TRANSACTION);
if (!hdr)
goto free_msg;
se = nfc_find_se(dev, se_idx);
if (!se)
goto free_msg;
if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type) ||
nla_put(msg, NFC_ATTR_SE_AID, evt_transaction->aid_len,
evt_transaction->aid) ||
nla_put(msg, NFC_ATTR_SE_PARAMS, evt_transaction->params_len,
evt_transaction->params))
goto nla_put_failure;
/* evt_transaction is no more used */
devm_kfree(&dev->dev, evt_transaction);
genlmsg_end(msg, hdr);
genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
nla_put_failure:
genlmsg_cancel(msg, hdr);
free_msg:
/* evt_transaction is no more used */
devm_kfree(&dev->dev, evt_transaction);
nlmsg_free(msg);
return -EMSGSIZE;
}
static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
u32 portid, u32 seq,
struct netlink_callback *cb,
......
......@@ -100,6 +100,8 @@ int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list);
int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type);
int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx);
int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx,
struct nfc_evt_transaction *evt_transaction);
struct nfc_dev *nfc_get_device(unsigned int idx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment