Пример #1
0
 def from_c(cls, event):
     passkey_display = event.evt.gap_evt.params.passkey_display
     passkey = "".join(chr(c) for c in util.uint8_array_to_list(passkey_display.passkey, 6))
     match_request = bool(passkey_display.match_request)
     return cls(conn_handle=event.evt.gap_evt.conn_handle,
                passkey=passkey,
                match_request=match_request)
Пример #2
0
    def from_c(cls, adv_report_evt):
        ad_list = util.uint8_array_to_list(adv_report_evt.data,
                                           adv_report_evt.dlen)
        ble_adv_data = cls()
        ble_adv_data.raw_bytes = bytes(ad_list)
        index = 0
        while index < len(ad_list):
            ad_len = ad_list[index]
            # If the length field is zero, skip it (probably padded zeros at the end of the payload)
            if ad_len == 0:
                index += 1
                continue
            try:
                ad_type = ad_list[index + 1]
                offset = index + 2
                key = BLEAdvData.Types(ad_type)
                ble_adv_data.records[key] = ad_list[offset:offset + ad_len - 1]
            except ValueError:
                logger.error(
                    'Invalid advertising data type: 0x{:02X}'.format(ad_type))
                pass
            except IndexError:
                logger.error('Invalid advertising data: {}'.format(ad_list))
                return ble_adv_data
            index += (ad_len + 1)

        return ble_adv_data
Пример #3
0
 def from_c(cls, event):
     hvx_evt = event.evt.gattc_evt.params.hvx
     return cls(conn_handle=event.evt.gattc_evt.conn_handle,
                status=BLEGattStatusCode(event.evt.gattc_evt.gatt_status),
                error_handle=event.evt.gattc_evt.error_handle,
                attr_handle=hvx_evt.handle,
                hvx_type=BLEGattHVXType(hvx_evt.type),
                data=util.uint8_array_to_list(hvx_evt.data, hvx_evt.len))
Пример #4
0
 def from_c(cls, event):
     read_rsp = event.evt.gattc_evt.params.read_rsp
     return cls(conn_handle=event.evt.gattc_evt.conn_handle,
                status=BLEGattStatusCode(event.evt.gattc_evt.gatt_status),
                error_handle=event.evt.gattc_evt.error_handle,
                attr_handle=read_rsp.handle,
                offset=read_rsp.offset,
                data=util.uint8_array_to_list(read_rsp.data, read_rsp.len))
Пример #5
0
    def from_auth_request(cls, conn_handle, write_event):
        attr_handle = write_event.handle
        uuid = BLEUUID.from_c(write_event.uuid)
        write_operand = BLEGattsWriteOperation(write_event.op)
        auth_required = bool(write_event.auth_required)
        offset = write_event.offset
        data = util.uint8_array_to_list(write_event.data, write_event.len)

        return cls(conn_handle, attr_handle, uuid, write_operand, auth_required, offset, data)
Пример #6
0
 def from_c(cls, event):
     write_rsp_evt = event.evt.gattc_evt.params.write_rsp
     return cls(conn_handle=event.evt.gattc_evt.conn_handle,
                status=BLEGattStatusCode(event.evt.gattc_evt.gatt_status),
                error_handle=event.evt.gattc_evt.error_handle,
                attr_handle=write_rsp_evt.handle,
                write_op=BLEGattWriteOperation(write_rsp_evt.write_op),
                offset=write_rsp_evt.offset,
                data=util.uint8_array_to_list(write_rsp_evt.data, write_rsp_evt.len))
Пример #7
0
    def from_c(cls, adv_report_evt):
        ad_list = util.uint8_array_to_list(adv_report_evt.data,
                                           adv_report_evt.dlen)
        ble_adv_data = cls()
        index = 0
        while index < len(ad_list):
            ad_len = ad_list[index]
            try:
                ad_type = ad_list[index + 1]
                offset = index + 2
                key = BLEAdvData.Types(ad_type)
                ble_adv_data.records[key] = ad_list[offset:offset + ad_len - 1]
            except ValueError:
                logger.error(
                    'Invalid advertising data type: 0x{:02X}'.format(ad_type))
                pass
            except IndexError:
                logger.error('Invalid advertising data: {}'.format(ad_list))
                return ble_adv_data
            index += (ad_len + 1)

        return ble_adv_data
Пример #8
0
 def from_c(cls, params):
     offset = params.offset
     value = bytearray(util.uint8_array_to_list(params.p_value, params.len))
     return cls(value, offset)
Пример #9
0
 def from_c(cls, gattc_write_params):
     return cls(write_op=BLEGattWriteOperation(gattc_write_params.write_op),
                flags=gattc_write_params.flags,
                handle=gattc_write_params.handle,
                data=util.uint8_array_to_list(gattc_write_params.p_value,
                                              gattc_write_params.len))
Пример #10
0
 def from_c(cls, key):
     key_data = bytearray(util.uint8_array_to_list(key.csrk,
                                                   cls.KEY_LENGTH))
     return cls(key_data)
Пример #11
0
 def from_c(cls, id_key):
     irk = bytearray(
         util.uint8_array_to_list(id_key.id_info.irk, cls.KEY_LENGTH))
     addr = BLEGapAddr.from_c(id_key.id_addr_info)
     return cls(irk, addr)
Пример #12
0
 def from_c(cls, info):
     ltk = bytearray(util.uint8_array_to_list(info.ltk, cls.KEY_LENGTH))
     lesc = info.lesc
     auth = info.auth
     return cls(ltk, lesc, auth)
Пример #13
0
 def from_c(cls, master_id):
     rand = bytearray(util.uint8_array_to_list(master_id.rand,
                                               cls.RAND_LEN))
     ediv = master_id.ediv
     return cls(ediv, rand)
Пример #14
0
 def from_c(cls, addr):
     addr_list = util.uint8_array_to_list(addr.addr,
                                          driver.BLE_GAP_ADDR_LEN)
     addr_list.reverse()
     return cls(addr_type=BLEGapAddrTypes(addr.addr_type), addr=addr_list)
Пример #15
0
 def from_uuid128(cls, uuid128):
     uuid = util.uint8_array_to_list(uuid128.uuid, 16)
     return cls.from_array(uuid)