Commit 0a946301 authored by Samuel Ortiz's avatar Samuel Ortiz

NFC: Extend and fix the internal secure element API

Secure elements need to be discovered after enabling the NFC controller.
This is typically done by the NCI core and the HCI drivers (HCI does not
specify how to discover SEs, it is left to the specific drivers).
Also, the SE enable/disable API explicitely takes a SE index as its
argument.
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 0b456c41
...@@ -59,9 +59,10 @@ struct nfc_hci_ops { ...@@ -59,9 +59,10 @@ struct nfc_hci_ops {
struct nfc_target *target); struct nfc_target *target);
int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event, int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
struct sk_buff *skb); struct sk_buff *skb);
int (*enable_se)(struct nfc_dev *dev, u32 secure_element);
int (*disable_se)(struct nfc_dev *dev, u32 secure_element);
int (*fw_upload)(struct nfc_hci_dev *hdev, const char *firmware_name); int (*fw_upload)(struct nfc_hci_dev *hdev, const char *firmware_name);
int (*discover_se)(struct nfc_hci_dev *dev);
int (*enable_se)(struct nfc_hci_dev *dev, u32 se_idx);
int (*disable_se)(struct nfc_hci_dev *dev, u32 se_idx);
}; };
/* Pipes */ /* Pipes */
......
...@@ -68,9 +68,12 @@ struct nfc_ops { ...@@ -68,9 +68,12 @@ struct nfc_ops {
void *cb_context); void *cb_context);
int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb); int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target); int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target);
int (*enable_se)(struct nfc_dev *dev, u32 secure_element);
int (*disable_se)(struct nfc_dev *dev, u32 secure_element);
int (*fw_upload)(struct nfc_dev *dev, const char *firmware_name); int (*fw_upload)(struct nfc_dev *dev, const char *firmware_name);
/* Secure Element API */
int (*discover_se)(struct nfc_dev *dev);
int (*enable_se)(struct nfc_dev *dev, u32 se_idx);
int (*disable_se)(struct nfc_dev *dev, u32 se_idx);
}; };
#define NFC_TARGET_IDX_ANY -1 #define NFC_TARGET_IDX_ANY -1
......
...@@ -126,6 +126,13 @@ int nfc_dev_up(struct nfc_dev *dev) ...@@ -126,6 +126,13 @@ int nfc_dev_up(struct nfc_dev *dev)
if (!rc) if (!rc)
dev->dev_up = true; dev->dev_up = true;
/* We have to enable the device before discovering SEs */
if (dev->ops->discover_se) {
rc = dev->ops->discover_se(dev);
if (!rc)
pr_warn("SE discovery failed\n");
}
error: error:
device_unlock(&dev->dev); device_unlock(&dev->dev);
return rc; return rc;
......
...@@ -692,6 +692,36 @@ static int hci_check_presence(struct nfc_dev *nfc_dev, ...@@ -692,6 +692,36 @@ static int hci_check_presence(struct nfc_dev *nfc_dev,
return hdev->ops->check_presence(hdev, target); return hdev->ops->check_presence(hdev, target);
} }
static int hci_discover_se(struct nfc_dev *nfc_dev)
{
struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
if (hdev->ops->discover_se)
return hdev->ops->discover_se(hdev);
return 0;
}
static int hci_enable_se(struct nfc_dev *nfc_dev, u32 se_idx)
{
struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
if (hdev->ops->enable_se)
return hdev->ops->enable_se(hdev, se_idx);
return 0;
}
static int hci_disable_se(struct nfc_dev *nfc_dev, u32 se_idx)
{
struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
if (hdev->ops->disable_se)
return hdev->ops->enable_se(hdev, se_idx);
return 0;
}
static void nfc_hci_failure(struct nfc_hci_dev *hdev, int err) static void nfc_hci_failure(struct nfc_hci_dev *hdev, int err)
{ {
mutex_lock(&hdev->msg_tx_mutex); mutex_lock(&hdev->msg_tx_mutex);
...@@ -802,6 +832,9 @@ static struct nfc_ops hci_nfc_ops = { ...@@ -802,6 +832,9 @@ static struct nfc_ops hci_nfc_ops = {
.tm_send = hci_tm_send, .tm_send = hci_tm_send,
.check_presence = hci_check_presence, .check_presence = hci_check_presence,
.fw_upload = hci_fw_upload, .fw_upload = hci_fw_upload,
.discover_se = hci_discover_se,
.enable_se = hci_enable_se,
.disable_se = hci_disable_se,
}; };
struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops, struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
......
...@@ -636,6 +636,21 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target, ...@@ -636,6 +636,21 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
return rc; return rc;
} }
static int nci_enable_se(struct nfc_dev *nfc_dev, u32 se_idx)
{
return 0;
}
static int nci_disable_se(struct nfc_dev *nfc_dev, u32 se_idx)
{
return 0;
}
static int nci_discover_se(struct nfc_dev *nfc_dev)
{
return 0;
}
static struct nfc_ops nci_nfc_ops = { static struct nfc_ops nci_nfc_ops = {
.dev_up = nci_dev_up, .dev_up = nci_dev_up,
.dev_down = nci_dev_down, .dev_down = nci_dev_down,
...@@ -646,6 +661,9 @@ static struct nfc_ops nci_nfc_ops = { ...@@ -646,6 +661,9 @@ static struct nfc_ops nci_nfc_ops = {
.activate_target = nci_activate_target, .activate_target = nci_activate_target,
.deactivate_target = nci_deactivate_target, .deactivate_target = nci_deactivate_target,
.im_transceive = nci_transceive, .im_transceive = nci_transceive,
.enable_se = nci_enable_se,
.disable_se = nci_disable_se,
.discover_se = nci_discover_se,
}; };
/* ---- Interface to NCI drivers ---- */ /* ---- Interface to NCI drivers ---- */
......
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