Enable NFC for Linux and pcscd on Dell E7470 (and others) with ControlVault2
Jacek Kowalski
2019-08-02 13e11418aa91a22af77dac257c5f7c54575366b7
Use SUPPORTED_DEVICES to match proper device

This is to support different vendor and device IDs.
2 files modified
32 ■■■■ changed files
README.md 2 ●●● patch | view | raw | blame | history
bcm20795.py 30 ●●●● patch | view | raw | blame | history
README.md
@@ -14,7 +14,7 @@
1. Clone the repository.
1. Install python3 and python3-usb.
1. Run: `./bcm20795.py on`
1. Run: `./bcm20795.py on` (use `sudo` if necessary).
1. Run `pcsc_scan` or whatever you prefer.
1. Enjoy!
bcm20795.py
@@ -14,8 +14,9 @@
import usb.core
import usb.util
VENDOR_ID = 0x0A5C
DEVICE_ID = 0x5834
SUPPORTED_DEVICES = [
    {'idVendor': 0x0A5C, 'idProduct': 0x5834},
]
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@@ -72,14 +73,29 @@
            if data[1] == 0x61:
                packet = self.recv_packet()
    
    @staticmethod
    def _dev_match(template, candidate):
        for prop, value in template.items():
            if prop not in candidate.__dict__ or candidate.__dict__[prop] != value:
                return False
        return True
    @classmethod
    def find(cls, vendor_id, product_id):
    def _dev_matcher(cls, dev):
        for device in SUPPORTED_DEVICES:
            if cls._dev_match(device, dev):
                return True
        return False
    @classmethod
    def find(cls):
        logger = logging.getLogger(__name__)
        logger.info('Looking for device {:04X}:{:04X}...'.format(vendor_id, product_id))
        logger.info('Looking for BCM device...')
        
        device = usb.core.find(idVendor=vendor_id, idProduct=product_id)
        device = usb.core.find(custom_match=cls._dev_matcher)
        if device is None:
            raise Exception('Cannot find device {:04X}:{:04X}'.format(vendor_id, product_id))
            raise Exception('Cannot find BCM device - check list of supported devices')
        logger.info('Found {:04X}:{:04X}'.format(device.idVendor, device.idProduct))
        
        logger.debug('Enumerating interfaces...')
        configuration = device.get_active_configuration()
@@ -159,7 +175,7 @@
        print('Usage: {} [on|off]'.format(sys.argv[0]))
        sys.exit(2)
    
    communicator = BcmCommunicator.find(VENDOR_ID, DEVICE_ID)
    communicator = BcmCommunicator.find()
    if sys.argv[1] == 'on':
        logger.info('Turning NFC on...')
        turn_on(communicator)