]> git.karo-electronics.de Git - linux-beck.git/commitdiff
NFC: pn533: Add some polling entropy
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 3 Jul 2013 13:14:17 +0000 (15:14 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 13 Aug 2013 22:35:19 +0000 (00:35 +0200)
By not always starting the polling loop from the same modulation, we
avoid entering infinite loops where devices exporting 2 targets (on 2
different modulations) get the same target activated over and over.
If this target is not readable (e.g. a wallet emulating a tag), we will
stay in an error loop for ever.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/pn533.c

index 9f3868b0170b3b36ecdd6aa87d467cb0b3c7ee99..5df730be88a388ba28f705fde82fdce04b1ff88e 100644 (file)
@@ -1913,6 +1913,7 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev,
                            u32 im_protocols, u32 tm_protocols)
 {
        struct pn533 *dev = nfc_get_drvdata(nfc_dev);
+       u8 rand_mod;
 
        nfc_dev_dbg(&dev->interface->dev,
                    "%s: im protocols 0x%x tm protocols 0x%x",
@@ -1936,11 +1937,15 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev,
                        tm_protocols = 0;
        }
 
-       dev->poll_mod_curr = 0;
        pn533_poll_create_mod_list(dev, im_protocols, tm_protocols);
        dev->poll_protocols = im_protocols;
        dev->listen_protocols = tm_protocols;
 
+       /* Do not always start polling from the same modulation */
+       get_random_bytes(&rand_mod, sizeof(rand_mod));
+       rand_mod %= dev->poll_mod_count;
+       dev->poll_mod_curr = rand_mod;
+
        return pn533_send_poll_frame(dev);
 }