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: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2013-05-10 11:57:06 +02:00
parent 0b456c418a
commit 0a946301c2
5 changed files with 66 additions and 4 deletions

View File

@ -59,9 +59,10 @@ struct nfc_hci_ops {
struct nfc_target *target);
int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
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 (*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 */

View File

@ -68,9 +68,12 @@ struct nfc_ops {
void *cb_context);
int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
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);
/* 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

View File

@ -126,6 +126,13 @@ int nfc_dev_up(struct nfc_dev *dev)
if (!rc)
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:
device_unlock(&dev->dev);
return rc;

View File

@ -692,6 +692,36 @@ static int hci_check_presence(struct nfc_dev *nfc_dev,
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)
{
mutex_lock(&hdev->msg_tx_mutex);
@ -802,6 +832,9 @@ static struct nfc_ops hci_nfc_ops = {
.tm_send = hci_tm_send,
.check_presence = hci_check_presence,
.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,

View File

@ -636,6 +636,21 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
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 = {
.dev_up = nci_dev_up,
.dev_down = nci_dev_down,
@ -646,6 +661,9 @@ static struct nfc_ops nci_nfc_ops = {
.activate_target = nci_activate_target,
.deactivate_target = nci_deactivate_target,
.im_transceive = nci_transceive,
.enable_se = nci_enable_se,
.disable_se = nci_disable_se,
.discover_se = nci_discover_se,
};
/* ---- Interface to NCI drivers ---- */