Skip to content

Commit

Permalink
NFC: Extend and fix the internal secure element API
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Samuel Ortiz committed Jun 14, 2013
1 parent 0b456c4 commit 0a94630
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/net/nfc/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 5 additions & 2 deletions include/net/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions net/nfc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions net/nfc/hci/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions net/nfc/nci/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 ---- */
Expand Down

0 comments on commit 0a94630

Please sign in to comment.