NFC: netlink: Add mode parameter to deactivate_target functions

In order to manage in a better way the nci poll mode state machine,
add mode parameter to deactivate_target functions.
This way we can manage different target state.
mode parameter make sense only in nci core.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Christophe Ricard 2015-10-25 22:54:43 +01:00 committed by Samuel Ortiz
parent cde2aa99ba
commit 96d4581f0b
10 changed files with 27 additions and 14 deletions

View File

@ -246,7 +246,7 @@ static int nfcsim_activate_target(struct nfc_dev *nfc_dev,
}
static void nfcsim_deactivate_target(struct nfc_dev *nfc_dev,
struct nfc_target *target)
struct nfc_target *target, u8 mode)
{
struct nfcsim *dev = nfc_get_drvdata(nfc_dev);

View File

@ -2263,7 +2263,7 @@ static int pn533_activate_target(struct nfc_dev *nfc_dev,
}
static void pn533_deactivate_target(struct nfc_dev *nfc_dev,
struct nfc_target *target)
struct nfc_target *target, u8 mode)
{
struct pn533 *dev = nfc_get_drvdata(nfc_dev);
struct sk_buff *skb;

View File

@ -68,7 +68,7 @@ struct nfc_ops {
int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
u32 protocol);
void (*deactivate_target)(struct nfc_dev *dev,
struct nfc_target *target);
struct nfc_target *target, u8 mode);
int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
struct sk_buff *skb, data_exchange_cb_t cb,
void *cb_context);

View File

@ -449,7 +449,7 @@ error:
* @dev: The nfc device that found the target
* @target_idx: index of the target that must be deactivated
*/
int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode)
{
int rc = 0;
@ -476,7 +476,7 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
if (dev->ops->check_presence)
del_timer_sync(&dev->check_pres_timer);
dev->ops->deactivate_target(dev, dev->active_target);
dev->ops->deactivate_target(dev, dev->active_target, mode);
dev->active_target = NULL;
error:

View File

@ -631,7 +631,8 @@ static int digital_activate_target(struct nfc_dev *nfc_dev,
}
static void digital_deactivate_target(struct nfc_dev *nfc_dev,
struct nfc_target *target)
struct nfc_target *target,
u8 mode)
{
struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);

View File

@ -678,7 +678,8 @@ static int hci_activate_target(struct nfc_dev *nfc_dev,
}
static void hci_deactivate_target(struct nfc_dev *nfc_dev,
struct nfc_target *target)
struct nfc_target *target,
u8 mode)
{
}

View File

@ -835,9 +835,11 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
}
static void nci_deactivate_target(struct nfc_dev *nfc_dev,
struct nfc_target *target)
struct nfc_target *target,
__u8 mode)
{
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
u8 nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE;
pr_debug("entry\n");
@ -848,9 +850,14 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
ndev->target_active_prot = 0;
switch (mode) {
case NFC_TARGET_MODE_SLEEP:
nci_mode = NCI_DEACTIVATE_TYPE_SLEEP_MODE;
break;
}
if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
nci_request(ndev, nci_rf_deactivate_req,
NCI_DEACTIVATE_TYPE_IDLE_MODE,
nci_request(ndev, nci_rf_deactivate_req, nci_mode,
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
}
}
@ -884,7 +891,7 @@ static int nci_dep_link_down(struct nfc_dev *nfc_dev)
pr_debug("entry\n");
if (nfc_dev->rf_mode == NFC_RF_INITIATOR) {
nci_deactivate_target(nfc_dev, NULL);
nci_deactivate_target(nfc_dev, NULL, NCI_DEACTIVATE_TYPE_IDLE_MODE);
} else {
if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE ||
atomic_read(&ndev->state) == NCI_DISCOVERY) {

View File

@ -885,7 +885,7 @@ static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
nfc_deactivate_target(dev, target_idx);
nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
rc = nfc_activate_target(dev, target_idx, protocol);
nfc_put_device(dev);

View File

@ -25,6 +25,9 @@
#include <net/nfc/nfc.h>
#include <net/sock.h>
#define NFC_TARGET_MODE_IDLE 0
#define NFC_TARGET_MODE_SLEEP 1
struct nfc_protocol {
int id;
struct proto *proto;
@ -147,7 +150,7 @@ int nfc_dep_link_down(struct nfc_dev *dev);
int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol);
int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx);
int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode);
int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
data_exchange_cb_t cb, void *cb_context);

View File

@ -321,7 +321,8 @@ static void rawsock_destruct(struct sock *sk)
if (sk->sk_state == TCP_ESTABLISHED) {
nfc_deactivate_target(nfc_rawsock(sk)->dev,
nfc_rawsock(sk)->target_idx);
nfc_rawsock(sk)->target_idx,
NFC_TARGET_MODE_IDLE);
nfc_put_device(nfc_rawsock(sk)->dev);
}