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


Python _bluetooth.hci_open_dev方法代码示例

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


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

示例1: create_connection_cancel

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [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_open_dev [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_open_dev [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_open_dev [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_open_dev [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_open_dev [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_open_dev [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_open_dev [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_open_dev [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: adv_airdrop

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [as 别名]
def adv_airdrop():
    while True:
        dev_id = 0
        toggle_device(dev_id, True)
        header = (0x02, 0x01, 0x1a, 0x1b, 0xff, 0x4c, 0x00)
        data1 = (0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
        apple_id = (0x00, 0x00)
        phone = (0x00, 0x00)
        email = (0xb7, 0x9b)
        data2 = (0x00, 0x00, 0x00, 0x10, 0x02, 0x0b, 0x00)
        try:
            sock = bluez.hci_open_dev(dev_id)
        except:
            print("Cannot open bluetooth device %i" % dev_id)
            raise
        start_le_advertising(sock, adv_type=0x02, min_interval=500, max_interval=500,
                             data=(header + data1 + apple_id + phone + email + data2))
        time.sleep(10)
        stop_le_advertising(sock) 
开发者ID:hexway,项目名称:apple_bleee,代码行数:21,代码来源:ble_read_state.py

示例11: adv_airdrop

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [as 别名]
def adv_airdrop(self):

        while True:
            dev_id = self.dev_id
            toggle_device(dev_id, True)
            header = (0x02, 0x01, 0x1a, 0x1b, 0xff, 0x4c, 0x00)
            data1 = (0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
            apple_id = (0x00, 0x00)
            phone = (0x00, 0x00)
            email = (0xb7, 0x9b)
            data2 = (0x00, 0x00, 0x00, 0x10, 0x02, 0x0b, 0x00)
            try:
                sock = bluez.hci_open_dev(dev_id)
            except:
                print("Cannot open bluetooth device %i" % dev_id)
                raise
            start_le_advertising(sock, adv_type=0x02, min_interval=500, max_interval=500,
                                data=(header + data1 + apple_id + phone + email + data2))
            time.sleep(10)
            stop_le_advertising(sock) 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:22,代码来源:ble_utils.py

示例12: set_bt_name

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [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

示例13: inquiry_cancel

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [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

示例14: exit_periodic_inquiry_mode

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [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

示例15: disconnect

# 需要导入模块: from bluetooth import _bluetooth [as 别名]
# 或者: from bluetooth._bluetooth import hci_open_dev [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


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