当前位置: 首页>>代码示例>>Python>>正文


Python _bluetooth.HCI_FILTER属性代码示例

本文整理汇总了Python中bluetooth._bluetooth.HCI_FILTER属性的典型用法代码示例。如果您正苦于以下问题:Python _bluetooth.HCI_FILTER属性的具体用法?Python _bluetooth.HCI_FILTER怎么用?Python _bluetooth.HCI_FILTER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在bluetooth._bluetooth的用法示例。


在下文中一共展示了_bluetooth.HCI_FILTER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_connection_cancel

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def create_connection_cancel(self, cmd_params:dict) -> dict:
        '''
        cmd_params -- {
            'BD_ADDR': str
        }
        '''
        dd = hci_open_dev(self.devid)

        bin_cmd_params = bytes.fromhex(cmd_params['BD_ADDR'].replace(':', '')[::-1])

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_LINK_CTL, OCF_CREATE_CONN_CANCEL))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_LINK_CTL, OCF_CREATE_CONN_CANCEL, bin_cmd_params)
        
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+7)[3:]
        num_hci_cmd_pkts, cmd_opcode, status, \
            bdaddr = struct.unpack('<BHB6s', event_params)

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:27,代码来源:hci.py

示例2: reset

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def reset(self) -> dict:
        dd = hci_open_dev(self.devid)

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_RESET))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_RESET)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }
    
        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:22,代码来源:hci.py

示例3: write_scan_enable

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def write_scan_enable(self, cmd_params={'Scan_Enable': 0x00}) -> dict:
        dd = hci_open_dev(self.devid)

        bin_cmd_params = cmd_params['Scan_Enable'].to_bytes(1, 'little')

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE, bin_cmd_params)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:25,代码来源:hci.py

示例4: write_inquiry_mode

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def write_inquiry_mode(self, cmd_params={'Inquiry_Mode': 0x00}) -> dict:
        dd = hci_open_dev(self.devid)

        bin_cmd_params = cmd_params['Inquiry_Mode'].to_bytes(1, 'little')

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE, bin_cmd_params)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }
        
        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:25,代码来源:hci.py

示例5: read_page_timeout

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def read_page_timeout(self) -> dict:
        dd = hci_open_dev(self.devid)

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_READ_PAGE_TIMEOUT))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_READ_PAGE_TIMEOUT)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+3)[3:]
        num_hci_cmd_pkts, cmd_opcode, status, page_timeout = struct.unpack('<BHBH', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status,
            'Page_Timeout': page_timeout
        }

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:24,代码来源:hci.py

示例6: write_page_timeout

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def write_page_timeout(self, cmd_params={'Page_Timeout': 0x2000}) -> dict:
        dd = hci_open_dev(self.devid)

        bin_cmd_params = cmd_params['Page_Timeout'].to_bytes(2, 'little')

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_PAGE_TIMEOUT))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_TIMEOUT, bin_cmd_params)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+3)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:25,代码来源:hci.py

示例7: write_authentication_enable

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def write_authentication_enable(self, cmd_params={'Authentication_Enable': 0x00}) -> dict:
        dd = hci_open_dev(self.devid)

        bin_cmd_params = cmd_params['Authentication_Enable'].to_bytes(1, 'little')

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE, bin_cmd_params)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+3)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:25,代码来源:hci.py

示例8: read_class_of_device

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def read_class_of_device(self) -> dict:
        dd = hci_open_dev(self.devid)

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_HOST_CTL, OCF_READ_CLASS_OF_DEV))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_HOST_CTL, OCF_READ_CLASS_OF_DEV)

        event_params = dd.recv(3+HCI_MAX_EVENT_SIZE)[3:]
        num_hci_cmd_pkts, cmd_opcode, status, cod = struct.unpack('<BHB3s', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status,
            'Class_Of_Device': cod[::-1]
        }

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:25,代码来源:hci.py

示例9: le_set_advertising_enable

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def le_set_advertising_enable(self, cmd_params={'Advertising_Enable': 0x00}) -> dict:
        dd = hci_open_dev(self.devid)

        bin_cmd_params = cmd_params['Advertising_Enable'].to_bytes(1, 'little')

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_LE_CTL, OCF_LE_SET_ADVERTISING_ENABLE))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_LE_CTL, OCF_LE_SET_ADVERTISING_ENABLE, bin_cmd_params)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }
        
        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:25,代码来源:hci.py

示例10: set_bt_name

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def set_bt_name(payload, src_hci, src, dst):
    # Create raw HCI sock to set our BT name
    raw_sock = bt.hci_open_dev(bt.hci_devid(src_hci))
    flt = bt.hci_filter_new()
    bt.hci_filter_all_ptypes(flt)
    bt.hci_filter_all_events(flt)
    raw_sock.setsockopt(bt.SOL_HCI, bt.HCI_FILTER, flt)

    # Send raw HCI command to our controller to change the BT name (first 3 bytes are padding for alignment)
    raw_sock.sendall(binascii.unhexlify('01130cf8cccccc') + payload.ljust(MAX_BT_NAME, b'\x00'))
    raw_sock.close()
    #time.sleep(1)
    time.sleep(0.1)

    # Connect to BNEP to "refresh" the name (does auth)
    bnep = bluetooth.BluetoothSocket(bluetooth.L2CAP)
    bnep.bind((src, 0))
    bnep.connect((dst, BNEP_PSM))
    bnep.close()

    # Close ACL connection
    os.system('hcitool dc %s' % (dst,))
    #time.sleep(1) 
开发者ID:ArmisSecurity,项目名称:blueborne,代码行数:25,代码来源:doit.py

示例11: read_local_bdaddr

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def read_local_bdaddr(hci_sock):
    old_filter = hci_sock.getsockopt( _bt.SOL_HCI, _bt.HCI_FILTER, 14)
    flt = _bt.hci_filter_new()
    opcode = _bt.cmd_opcode_pack(_bt.OGF_INFO_PARAM, 
            _bt.OCF_READ_BD_ADDR)
    _bt.hci_filter_set_ptype(flt, _bt.HCI_EVENT_PKT)
    _bt.hci_filter_set_event(flt, _bt.EVT_CMD_COMPLETE);
    _bt.hci_filter_set_opcode(flt, opcode)
    hci_sock.setsockopt( _bt.SOL_HCI, _bt.HCI_FILTER, flt )

    _bt.hci_send_cmd(hci_sock, _bt.OGF_INFO_PARAM, _bt.OCF_READ_BD_ADDR )

    pkt = hci_sock.recv(255)

    status,raw_bdaddr = struct.unpack("xxxxxxB6s", pkt)
    assert status == 0

    t = [ "%X" % ord(b) for b in raw_bdaddr ]
    t.reverse()
    bdaddr = ":".join(t)

    # restore old filter
    hci_sock.setsockopt( _bt.SOL_HCI, _bt.HCI_FILTER, old_filter )
    return bdaddr 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:read-local-bdaddr.py

示例12: inquiry_cancel

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def inquiry_cancel(self) -> dict:
        '''
        Return -- {
            'Num_HCI_Command_Packets': int,
            'Command_Opcode': int,
            'Status': int
        }
        '''
        dd = hci_open_dev(self.devid)

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY_CANCEL))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_LINK_CTL, OCF_INQUIRY_CANCEL)
        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }
    
        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:30,代码来源:hci.py

示例13: exit_periodic_inquiry_mode

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def exit_periodic_inquiry_mode(self) -> dict:
        '''
        Return -- {
            'Num_HCI_Command_Packets': int,
            'Command_Opcode': int,
            'Status': int
        }
        '''
        dd = hci_open_dev(self.devid)

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_CMD_COMPLETE)
        hci_filter_set_opcode(
            flt, cmd_opcode_pack(OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY))
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY)

        event_params = dd.recv(3+EVT_CMD_COMPLETE_SIZE+1)[3:]
        num_hci_cmd_pkts, cmd_opcode, status = struct.unpack('<BHB', event_params)
        event_params = {
            'Num_HCI_Command_Packets': num_hci_cmd_pkts,
            'Command_Opcode': cmd_opcode,
            'Status': status
        }
        
        hci_close_dev(dd.fileno())
        return status 
开发者ID:fO-000,项目名称:bluescan,代码行数:31,代码来源:hci.py

示例14: disconnect

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def disconnect(self, cmd_params:dict) -> dict:
        '''
        cmd_params -- {
            'Connection_Handle': int, 2 bytes,
            'Reason': int, 1 bytes
        }
        '''
        dd = hci_open_dev(self.devid)
        
        flt = hci_filter_new()
        hci_filter_clear(flt)
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_DISCONN_COMPLETE)
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        bin_cmd_params = cmd_params['Connection_Handle'].to_bytes(2, 'little') + \
            cmd_params['Reason'].to_bytes(1, 'little')

        hci_send_cmd(dd, OGF_LINK_CTL, OCF_DISCONNECT, bin_cmd_params)

        # Receive and exclude HCI packet type (1 B)
        event_params = dd.recv(3+EVT_DISCONN_COMPLETE_SIZE)[3:] 
        status, conn_handle, reason, = struct.unpack(
            '<BHB', event_params)

        event_params = {
            'Status': status,
            'Connection_Handle': conn_handle,
            'Reason': reason
        }

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:35,代码来源:hci.py

示例15: read_remote_extended_features

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import HCI_FILTER [as 别名]
def read_remote_extended_features(self, cmd_params:dict) -> dict:
        '''
        cmd_params -- {
                          'Connection_Handle': 0x0000 to 0x0EFF,
                          'Page_Number': int
                      }
        '''
        dd = hci_open_dev(self.devid)

        bin_cmd_params = cmd_params[
            'Connection_Handle'].to_bytes(2, 'little') + \
            cmd_params['Page_Number'].to_bytes(1, 'little')

        flt = hci_filter_new()
        hci_filter_set_ptype(flt, HCI_EVENT_PKT)
        hci_filter_set_event(flt, EVT_READ_REMOTE_EXT_FEATURES_COMPLETE)
        dd.setsockopt(SOL_HCI, HCI_FILTER, flt)

        hci_send_cmd(dd, OGF_LINK_CTL, OCF_READ_REMOTE_EXT_FEATURES, 
            bin_cmd_params)

        while True:
            event_params = dd.recv(3 + \
                EVT_READ_REMOTE_EXT_FEATURES_COMPLETE_SIZE)[3:]
            status, conn_handle, page_num, max_page_num, ext_lmp_features = \
                struct.unpack('<BHBB8s', event_params)
            event_params = {
                'Status': status,
                'Connection_Handle': conn_handle,
                'Page_Number': page_num,
                'Maximum_Page_Number': max_page_num,
                'Extended_LMP_Features': ext_lmp_features
            }

            if event_params['Connection_Handle'] == cmd_params['Connection_Handle'] and \
                event_params['Page_Number'] == cmd_params['Page_Number']:
                break

        hci_close_dev(dd.fileno())
        return event_params 
开发者ID:fO-000,项目名称:bluescan,代码行数:42,代码来源:hci.py


注:本文中的bluetooth._bluetooth.HCI_FILTER属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。