Exemplo n.º 1
0
    def scan(self, remote_bd_addr:str):
        hci = HCI(self.iface)
        event_params = hci.create_connection({
            'BD_ADDR': remote_bd_addr,
            'Packet_Type': 0xcc18,
            'Page_Scan_Repetition_Mode': 0x02,
            'Reserved': 0x00,
            'Clock_Offset': 0x0000,
            'Allow_Role_Switch': 0x01
        })

        if event_params['Status'] != 0:
            print(ERROR, 'Failed to create ACL connection')
            sys.exit(1)

        event_params = hci.read_remote_version_information(cmd_params={
            'Connection_Handle': event_params['Connection_Handle']
        })

        if event_params['Status'] != 0:
            print(ERROR, 'Failed to read remote version')
            sys.exit(1)

        print(blue('Version'))
        print('    Version:')
        print(' '*8+lm_vers[event_params['Version']], '(LMP)')
        print(' '*8+ll_vers[event_params['Version']], '(LL)')
        print('    Manufacturer name:', event_params['Manufacturer_Name'])
        print('    Subversion:', event_params['Subversion'], '\n')

        event_params = hci.read_remote_supported_features({
            'Connection_Handle': event_params['Connection_Handle']
        })
        if event_params['Status'] != 0:
            print(ERROR, 'Failed to read remote supported features')
        else:
            print(blue('LMP features'))
            pp_lmp_features(event_params['LMP_Features'])
            print()

        if not True if (event_params['LMP_Features'][7] >> 7) & 0x01 else False:
            sys.exit(1)

        print(blue('Extended LMP features'))
        event_params = hci.read_remote_extended_features({
            'Connection_Handle': event_params['Connection_Handle'],
            'Page_Number': 0x00
        })
        if event_params['Status'] != 0:
            print(ERROR, 'Failed to read remote extented features')
        else:
            pp_ext_lmp_features(event_params['Extended_LMP_Features'], 0)
            for i in range(1, event_params['Maximum_Page_Number']+1):
                event_params = hci.read_remote_extended_features({
                    'Connection_Handle': event_params['Connection_Handle'],
                    'Page_Number': i})
                if event_params['Status'] != 0:
                    print(ERROR, 'Failed to read remote extented features, page', i)
                else:
                    pp_ext_lmp_features(event_params['Extended_LMP_Features'], i)
Exemplo n.º 2
0
    def scan_lmp_feature(self, paddr):
        hci = HCI(self.iface)
        conn_complete_evt = hci.create_connection(
            paddr, page_scan_repetition_mode=0x02)

        if conn_complete_evt.status != 0:
            logger.error('Failed to create ACL connection')
            sys.exit(1)

        event_params = hci.read_remote_version_information(
            cmd_params={'Connection_Handle': conn_complete_evt.conn_handle})

        if event_params['Status'] != 0:
            logger.error('Failed to read remote version')
            sys.exit(1)

        print(blue('Version'))
        print('    Version:')
        print(' ' * 8 + lmp_vers[event_params['Version']], '(LMP)')
        print(' ' * 8 + ll_vers[event_params['Version']], '(LL)')
        print('    Manufacturer name:',
              green(company_identfiers[event_params['Manufacturer_Name']]))
        print('    Subversion:', event_params['Subversion'], '\n')

        complete_evt = hci.read_remote_supported_features(
            event_params['Connection_Handle'])
        if complete_evt.status != ControllerErrorCodes.SUCCESS:
            logger.error('Failed to read remote supported features')
        else:
            print(blue('LMP features'))
            pp_lmp_features(complete_evt.lmp_features)
            print()

        if not True if (complete_evt.lmp_features[7] >> 7) & 0x01 else False:
            sys.exit(1)

        print(blue('Extended LMP features'))
        complete_evt = hci.read_remote_extended_features(
            event_params['Connection_Handle'], 0x00)
        if complete_evt.status != ControllerErrorCodes.SUCCESS:
            logger.error('Failed to read remote extented features')
        else:
            pp_ext_lmp_features(complete_evt.ext_lmp_features, 0)
            for i in range(1, complete_evt.max_page_num + 1):
                complete_evt = hci.read_remote_extended_features(
                    event_params['Connection_Handle'], i)
                if complete_evt.status != ControllerErrorCodes.SUCCESS:
                    logger.error(
                        'Failed to read remote extented features, page {}'.
                        format(i))
                else:
                    pp_ext_lmp_features(complete_evt.ext_lmp_features, i)