예제 #1
0
파일: le_scan.py 프로젝트: fO-000/bluescan
    def scan_ll_feature(self, paddr, patype, timeout: int=10):
        """LL feature scanning

        paddr   - Peer addresss for scanning LL features.
        patype  - Peer address type, public or random.
        timeout - sec
        """
        spinner = Halo(text="Scanning", spinner={'interval': 200,
                                                 'frames': ['', '.', '.'*2, '.'*3]},
                       placement='right')
        hci = HCI(self.hci)
        logger.info('Scanning LE LL Features of %s, using %s\n'%(blue(paddr), blue(self.hci)))
        
        spinner.start()

        try:
            event_params = hci.le_create_connection(paddr, patype, timeout=timeout)
            logger.debug(event_params)
        except RuntimeError as e:
            logger.error(str(e))
            return
        except TimeoutError as e:
            logger.info("Timeout")
            # logger.error("TimeoutError {}".format(e))
            return

        event_params = hci.le_read_remote_features(event_params['Connection_Handle'])
        spinner.stop()
        logger.debug(event_params)
        print(blue('LE LL Features:'))
        pp_le_features(event_params['LE_Features'])

        event_params = hci.disconnect(event_params['Connection_Handle'], ControllerErrorCodes.REMOTE_USER_TERM_CONN)
        logger.debug(event_params)
        return
예제 #2
0
    def scan_ll_feature(self, paddr, patype):
        """LL feature scanning

        paddr  - Peer addresss for scanning LL features.
        patype - Peer address type, public or random.
        """
        hci = HCI(self.hci)
        logger.info('Scanning LE LL Features of %s, using %s\n' %
                    (blue(paddr), blue(self.hci)))

        try:
            event_params = hci.le_create_connection(
                HCI_Cmd_LE_Create_Connection(paddr=bytes.fromhex(
                    paddr.replace(':', ''))[::-1],
                                             patype=patype))
            logger.debug(event_params)
        except RuntimeError as e:
            logger.error(e)
            return

        event_params = hci.le_read_remote_features(
            HCI_Cmd_LE_Read_Remote_Features(
                handle=event_params['Connection_Handle']))
        logger.debug(event_params)
        print(blue('LE LL Features:'))
        pp_le_features(event_params['LE_Features'])

        event_params = hci.disconnect({
            'Connection_Handle':
            event_params['Connection_Handle'],
            'Reason':
            ERR_REMOTE_USER_TERMINATED_CONNECTION
        })
        logger.debug(event_params)
        return
예제 #3
0
파일: le_scan.py 프로젝트: fO-000/bluescan
    def detect_pairing_feature(self, paddr, patype, timeout:int=10):
        """
        """
        # TODO Mac OS 会弹窗,需要解决。
        hci = HCI(self.hci)
        logger.info("Detecting SMP pairing feature of %s, using %s\n"%(blue(paddr), blue(self.hci)))

        pairing_req = SM_Hdr(sm_command=btsmp.CmdCode.PAIRING_REQUEST) / \
            SM_Pairing_Request(iocap="NoInputNoOutput", oob='Not Present', 
                authentication=(0b00 << AUTHREQ_RFU_POS) | (0 << CT2_POS) | \
                    (0 << KEYPRESS_POS) | (1 << SC_POS) | (0 << MITM_POS) | \
                    (BONDING << BONDING_FLAGS_POS), max_key_size=16,
                initiator_key_distribution=(0b0000 << INIT_RESP_KEY_DIST_RFU_POS) \
                    | (1 << LINKKEY_POS) | (1 << SIGNKEY_POS) | (1 << IDKEY_POS) \
                    | (1 << ENCKEY_POS),
                responder_key_distribution=(0b0000 << INIT_RESP_KEY_DIST_RFU_POS) \
                    | (1 << LINKKEY_POS) | (1 << SIGNKEY_POS) | (1 << IDKEY_POS) \
                    | (1 << ENCKEY_POS))

        event_params = None
        
        spinner = Halo(text="Scanning", spinner={'interval': 200,
                                                 'frames': ['', '.', '.'*2, '.'*3]},
                       placement='right')
        hci = HCI(self.hci)
        logger.info('Scanning LE LL Features of %s, using %s\n'%(blue(paddr), blue(self.hci)))
        
        spinner.start()
        
        try:
            event_params = hci.le_create_connection(paddr, patype, timeout=timeout)
            logger.debug(event_params)

            result = btsmp.send_pairing_request(event_params['Connection_Handle'], pairing_req, self.hci)
            logger.debug("detect_pairing_feature(), result: {}".format(result))

            rsp = btsmp.recv_pairing_response(timeout, self.hci)
            logger.debug("detect_pairing_feature(), rsp: {}".format(rsp))
            
            spinner.stop()

            pp_smp_pkt(rsp)
        except RuntimeError as e:
            logger.error(str(e))
        except TimeoutError as e:
            output = subprocess.check_output(' '.join(['hciconfig', self.hci, 'reset']), 
                stderr=STDOUT, timeout=60, shell=True)
            event_params = None
            logger.info("Timeout")
            # logger.error("detect_pairing_feature(), TimeoutError {}".format(e))

        if event_params != None:
            hci.disconnect(event_params['Connection_Handle'],
                           ControllerErrorCodes.UNSUPPORTED_REMOTE_FEATURE)

        return
예제 #4
0
    def detect_pairing_feature(self, paddr, patype, timeout: int = 10):
        """ """
        hci = HCI(self.hci)
        logger.info("Detecting SMP pairing feature of %s, using %s\n" %
                    (blue(paddr), blue(self.hci)))

        pairing_req = SM_Hdr(sm_command=btsmp.CmdCode.PAIRING_REQUEST) / \
            SM_Pairing_Request(iocap="NoInputNoOutput", oob='Not Present',
                authentication=(0b00 << AUTHREQ_RFU_POS) | (0 << CT2_POS) | \
                    (0 << KEYPRESS_POS) | (1 << SC_POS) | (0 << MITM_POS) | \
                    (BONDING << BONDING_FLAGS_POS), max_key_size=16,
                initiator_key_distribution=(0b0000 << INIT_RESP_KEY_DIST_RFU_POS) \
                    | (1 << LINKKEY_POS) | (1 << SIGNKEY_POS) | (1 << IDKEY_POS) \
                    | (1 << ENCKEY_POS),
                responder_key_distribution=(0b0000 << INIT_RESP_KEY_DIST_RFU_POS) \
                    | (1 << LINKKEY_POS) | (1 << SIGNKEY_POS) | (1 << IDKEY_POS) \
                    | (1 << ENCKEY_POS))

        event_params = None
        try:
            event_params = hci.le_create_connection(
                HCI_Cmd_LE_Create_Connection(paddr=bytes.fromhex(
                    paddr.replace(':', ''))[::-1],
                                             patype=patype), timeout)
            logger.debug(event_params)

            result = btsmp.send_pairing_request(
                event_params['Connection_Handle'], pairing_req, self.hci)
            logger.debug("detect_pairing_feature(), result: {}".format(result))

            rsp = btsmp.recv_pairing_response(timeout, self.hci)
            logger.debug("detect_pairing_feature(), rsp: {}".format(rsp))

            pp_smp_pkt(rsp)
        except RuntimeError as e:
            logger.error(e)
        except TimeoutError as e:
            output = subprocess.check_output(' '.join(
                ['hciconfig', self.hci, 'reset']),
                                             stderr=STDOUT,
                                             timeout=60,
                                             shell=True)
            event_params = None
            logger.info("Timeout")
            # logger.error("detect_pairing_feature(), TimeoutError {}".format(e))

        if event_params != None:
            hci.disconnect({
                'Connection_Handle':
                event_params['Connection_Handle'],
                'Reason':
                0x1A
            })

        return