Пример #1
0
 def hci_send(self, cmd):
     """ send HCI Command via acquired socket BUT DON'T block waiting for an answer """
     packet = bt.HCI_Hdr() / bt.HCI_Command_Hdr() / cmd
     self.logger.debug(
         "Packet to be send out with 'hci_send':\n###[ Structure ]###\n  {}\n{}"
         .format(packet.summary(), packet.show2(dump=True)))
     return self.socket.send(packet)
Пример #2
0
    def connect(self, hwaddr):
        p = (
            bluetooth.HCI_Hdr()
            / bluetooth.HCI_Command_Hdr(opcode=0x200d)
            / bluetooth.HCI_Cmd_LE_Create_Connection(
                interval=96,
                window=48,
                filter=0,
                patype=1,
                paddr=hwaddr,
                atype=1,
                min_interval=24,
                max_interval=40,
                latency=0,
                timeout=500,
                min_ce=0,
                max_ce=0,
            )
        )
        self._send(p)
        while True:
            p = self.socket.recv()
            if self.debug:
                hexdump(p)

            if p.type == 4:
                if p.code == 0x3e and p.event == 1 and p.status == 0:
                    if self.debug:
                        print(f"Connected with handle {p.handle}")
                    self.connection_handle = p.handle
                    return
Пример #3
0
 def disconnect(self):
     p = (
         bluetooth.HCI_Hdr()
         / bluetooth.HCI_Command_Hdr(opcode=0x0406)
         / bluetooth.HCI_Cmd_Disconnect(handle=self.connection_handle)
     )
     self._send(p)
     while True:
         p = self.socket.recv()
         if p.type == 4:
             if p.code == 0x5:
                 return
Пример #4
0
 def read_attribute(self, gatt_handle):
     p = (
         bluetooth.HCI_Hdr(type=2)
         / bluetooth.HCI_ACL_Hdr(handle=self.connection_handle)
         / bluetooth.L2CAP_Hdr(cid=4)
         / bluetooth.ATT_Hdr()
         / bluetooth.ATT_Read_Request(gatt_handle=gatt_handle)
     )
     self._send(p)
     while True:
         p = self.socket.recv()
         if p.type == 2 and p.opcode == 0xb:
             return p.value
Пример #5
0
 def l2cap_send(self, cmd, handle, request_id):
     """ send non-blocking L2CAP command with specified handle and id """
     return self.socket.send(bt.HCI_Hdr() / bt.HCI_ACL_Hdr(handle=handle) /
                             bt.L2CAP_Hdr() /
                             bt.L2CAP_CmdHdr(id=request_id) / cmd)
Пример #6
0
 def hci_send_command(self, cmd):
     """ send HCI Command via acquired socket and block waiting for an answer """
     return self.socket.send_command(bt.HCI_Hdr() / bt.HCI_Command_Hdr() /
                                     cmd)