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:
parent
cde2aa99ba
commit
96d4581f0b
10 changed files with 27 additions and 14 deletions
|
@ -246,7 +246,7 @@ static int nfcsim_activate_target(struct nfc_dev *nfc_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nfcsim_deactivate_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);
|
struct nfcsim *dev = nfc_get_drvdata(nfc_dev);
|
||||||
|
|
||||||
|
|
|
@ -2263,7 +2263,7 @@ static int pn533_activate_target(struct nfc_dev *nfc_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pn533_deactivate_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 pn533 *dev = nfc_get_drvdata(nfc_dev);
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
|
|
|
@ -68,7 +68,7 @@ struct nfc_ops {
|
||||||
int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
|
int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
|
||||||
u32 protocol);
|
u32 protocol);
|
||||||
void (*deactivate_target)(struct nfc_dev *dev,
|
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,
|
int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
|
||||||
struct sk_buff *skb, data_exchange_cb_t cb,
|
struct sk_buff *skb, data_exchange_cb_t cb,
|
||||||
void *cb_context);
|
void *cb_context);
|
||||||
|
|
|
@ -449,7 +449,7 @@ error:
|
||||||
* @dev: The nfc device that found the target
|
* @dev: The nfc device that found the target
|
||||||
* @target_idx: index of the target that must be deactivated
|
* @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;
|
int rc = 0;
|
||||||
|
|
||||||
|
@ -476,7 +476,7 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
|
||||||
if (dev->ops->check_presence)
|
if (dev->ops->check_presence)
|
||||||
del_timer_sync(&dev->check_pres_timer);
|
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;
|
dev->active_target = NULL;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
|
@ -631,7 +631,8 @@ static int digital_activate_target(struct nfc_dev *nfc_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void digital_deactivate_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);
|
struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
|
||||||
|
|
||||||
|
|
|
@ -678,7 +678,8 @@ static int hci_activate_target(struct nfc_dev *nfc_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hci_deactivate_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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -835,9 +835,11 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nci_deactivate_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);
|
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
|
||||||
|
u8 nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE;
|
||||||
|
|
||||||
pr_debug("entry\n");
|
pr_debug("entry\n");
|
||||||
|
|
||||||
|
@ -848,9 +850,14 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
|
||||||
|
|
||||||
ndev->target_active_prot = 0;
|
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) {
|
if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
|
||||||
nci_request(ndev, nci_rf_deactivate_req,
|
nci_request(ndev, nci_rf_deactivate_req, nci_mode,
|
||||||
NCI_DEACTIVATE_TYPE_IDLE_MODE,
|
|
||||||
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
|
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");
|
pr_debug("entry\n");
|
||||||
|
|
||||||
if (nfc_dev->rf_mode == NFC_RF_INITIATOR) {
|
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 {
|
} else {
|
||||||
if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE ||
|
if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE ||
|
||||||
atomic_read(&ndev->state) == NCI_DISCOVERY) {
|
atomic_read(&ndev->state) == NCI_DISCOVERY) {
|
||||||
|
|
|
@ -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]);
|
target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
|
||||||
protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
|
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);
|
rc = nfc_activate_target(dev, target_idx, protocol);
|
||||||
|
|
||||||
nfc_put_device(dev);
|
nfc_put_device(dev);
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include <net/nfc/nfc.h>
|
#include <net/nfc/nfc.h>
|
||||||
#include <net/sock.h>
|
#include <net/sock.h>
|
||||||
|
|
||||||
|
#define NFC_TARGET_MODE_IDLE 0
|
||||||
|
#define NFC_TARGET_MODE_SLEEP 1
|
||||||
|
|
||||||
struct nfc_protocol {
|
struct nfc_protocol {
|
||||||
int id;
|
int id;
|
||||||
struct proto *proto;
|
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_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,
|
int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
|
||||||
data_exchange_cb_t cb, void *cb_context);
|
data_exchange_cb_t cb, void *cb_context);
|
||||||
|
|
|
@ -321,7 +321,8 @@ static void rawsock_destruct(struct sock *sk)
|
||||||
|
|
||||||
if (sk->sk_state == TCP_ESTABLISHED) {
|
if (sk->sk_state == TCP_ESTABLISHED) {
|
||||||
nfc_deactivate_target(nfc_rawsock(sk)->dev,
|
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);
|
nfc_put_device(nfc_rawsock(sk)->dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue