NFC: netlink: Add mode parameter to deactivate_target functions
authorChristophe Ricard <christophe.ricard@gmail.com>
Sun, 25 Oct 2015 21:54:43 +0000 (22:54 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 27 Oct 2015 02:55:12 +0000 (03:55 +0100)
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>
drivers/nfc/nfcsim.c
drivers/nfc/pn533.c
include/net/nfc/nfc.h
net/nfc/core.c
net/nfc/digital_core.c
net/nfc/hci/core.c
net/nfc/nci/core.c
net/nfc/netlink.c
net/nfc/nfc.h
net/nfc/rawsock.c

index 93111fa8d2829735ec1ddea6c09c6da86bbb9459..26ac9e5fa1ab256277e543548484268c033243fc 100644 (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);
 
index a03e4eb5fe2978c24d10899d249ddc2373968db6..bb3d5ea9869c63e061761edd1d460dc41a36a01f 100644 (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;
index 30afc9a6718c01d7ef22ab6758a8a7c4a8019acf..dcfcfc9c00bf56a4cf1681333e56bb21c14b23d9 100644 (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);
index cff3f1614ad4557ff178804acb55bacbad328149..1fe3d3b362c0cdce72d8317488e8b1fc4d58ea1d 100644 (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:
index 009bcf317101003e4095fda37ed1b6b7e31565e1..23c2a118ac9f98c3cfd11c871a9126664f54838e 100644 (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);
 
index 6e061da2258a8bd32f80f585aaaf7e951180b7d3..2b0f0ac498d2c02c92a62d8e749a103f5b1849c1 100644 (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)
 {
 }
 
index 75bda34fd8e4f7f952ce2ea50d9208e373165111..ecf420d43a6dfed60f09bbfcbbb8798c245bafba 100644 (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) {
index f04053295ff122fdf588a749ab2202b712331c42..f58c1fba10268b9c1336d205ff294e906dd04791 100644 (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);
index 5c93e8412a2639f3d1c77cf7ee5e15a95991a858..c20b784ad72069ae599bec30d8896ac693a8bda9 100644 (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);
index e9a91488fe3d388d90f24b3a2e645bbf71cdb60a..e386e6c90b179f9494d25f412133a6c42fc29e4c 100644 (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);
        }