Beispiel #1
0
def _handle_le_connection_complete(pkt):
    result = {}
    status, handle, role, peer_bdaddr_type = struct.unpack("<BHBB", pkt[0:5])
    device_address = utils.packed_bdaddr_to_string(pkt[5:11])
    interval, latency, supervision_timeout, master_clock_accuracy = \
        struct.unpack("<HHHB", pkt[11:])
    result["status"] = status
    result["handle"] = handle
    result["role"] = role
    result["peer_bluetooth_address_type"] = peer_bdaddr_type
    result["peer_device_address"] = device_address
    result["interval"] = interval
    result["latency"] = latency
    result["supervision_timeout"] = supervision_timeout
    result["master_clock_accuracy"] = master_clock_accuracy
    return result
Beispiel #2
0
def _handle_le_connection_complete(pkt):
    result = {}
    status, handle, role, peer_bdaddr_type = struct.unpack("<BHBB", pkt[0:5])
    device_address = utils.packed_bdaddr_to_string(pkt[5:11])
    interval, latency, supervision_timeout, master_clock_accuracy = \
        struct.unpack("<HHHB", pkt[11:])
    result["status"] = status
    result["handle"] = handle
    result["role"] = role
    result["peer_bluetooth_address_type"] = peer_bdaddr_type
    result["peer_device_address"] = device_address
    result["interval"] = interval
    result["latency"] = latency
    result["supervision_timeout"] = supervision_timeout
    result["master_clock_accuracy"] = master_clock_accuracy
    return result
Beispiel #3
0
def _handle_le_advertising_report(pkt):
    result = {}
    num_reports = struct.unpack("<B", pkt[0])[0]
    report_pkt_offset = 0
    result["number_of_advertising_reports"] = num_reports
    result["advertising_reports"] = []
    for i in range(0, num_reports):
        report = {}
        report_event_type = struct.unpack("<B", pkt[report_pkt_offset + 1])[0]
        report["report_type_id"] = report_event_type
        bdaddr_type = struct.unpack("<B", pkt[report_pkt_offset + 2])[0]
        report["peer_bluetooth_address_type"] = bdaddr_type
        device_addr = utils.packed_bdaddr_to_string(
            pkt[report_pkt_offset + 3:report_pkt_offset + 9])
        report["peer_bluetooth_address"] = device_addr
        report_data_length, = struct.unpack("<B", pkt[report_pkt_offset + 9])
        report["report_metadata_length"] = report_data_length
        if report_event_type == constants.LE_ADV_IND:
            report["report_type_string"] = "LE_ADV_IND"
        elif report_event_type == constants.LE_ADV_DIRECT_IND:
            report["report_type_string"] = "LE_ADV_DIRECT_IND"
        elif report_event_type == constants.LE_ADV_SCAN_IND:
            report["report_type_string"] = "LE_ADV_SCAN_IND"
        elif report_event_type == constants.LE_ADV_NONCONN_IND:
            report["report_type_string"] = "LE_ADV_NONCONN_IND"
        elif report_event_type == constants.LE_ADV_SCAN_RSP:
            report["report_type_string"] = "LE_ADV_SCAN_RSP"
            if report_data_length:
                local_name_len, = struct.unpack("<B",
                                                pkt[report_pkt_offset + 11])
                name = pkt[report_pkt_offset + 12:report_pkt_offset + 12 +
                           (local_name_len - 1)]
                report["peer_name"] = name
        else:
            report["report_type_string"] = "UNKNOWN"
        # Each report length is (2 (event type, bdaddr type) + 6 (the address)
        #    + 1 (data length field) + data length + 1 (rssi)) bytes long.
        report_pkt_offset = report_pkt_offset + 10 + report_data_length + 1
        rssi, = struct.unpack("<b", pkt[report_pkt_offset - 1])
        report["rssi"] = rssi
        result["advertising_reports"].append(report)
    return result
Beispiel #4
0
def _handle_le_advertising_report(pkt):
    result = {}
    num_reports = struct.unpack("<B", pkt[0])[0]
    report_pkt_offset = 0
    result["number_of_advertising_reports"] = num_reports
    result["advertising_reports"] = []
    for i in range(0, num_reports):
        report = {}
        report_event_type = struct.unpack("<B", pkt[report_pkt_offset + 1])[0]
        report["report_type_id"] = report_event_type
        bdaddr_type = struct.unpack("<B", pkt[report_pkt_offset + 2])[0]
        report["peer_bluetooth_address_type"] = bdaddr_type
        device_addr = utils.packed_bdaddr_to_string(
            pkt[report_pkt_offset + 3:report_pkt_offset + 9])
        report["peer_bluetooth_address"] = device_addr
        report_data_length, = struct.unpack("<B", pkt[report_pkt_offset + 9])
        report["report_metadata_length"] = report_data_length
        if report_event_type == constants.LE_ADV_IND:
            report["report_type_string"] = "LE_ADV_IND"
        elif report_event_type == constants.LE_ADV_DIRECT_IND:
            report["report_type_string"] = "LE_ADV_DIRECT_IND"
        elif report_event_type == constants.LE_ADV_SCAN_IND:
            report["report_type_string"] = "LE_ADV_SCAN_IND"
        elif report_event_type == constants.LE_ADV_NONCONN_IND:
            report["report_type_string"] = "LE_ADV_NONCONN_IND"
        elif report_event_type == constants.LE_ADV_SCAN_RSP:
            report["report_type_string"] = "LE_ADV_SCAN_RSP"
            local_name_len, = struct.unpack("<B", pkt[report_pkt_offset + 11])
            name = pkt[report_pkt_offset + 12:report_pkt_offset + 12 + (local_name_len - 1)]
            report["peer_name"] = name
        else:
            report["report_type_string"] = "UNKNOWN"
        # Each report length is (2 (event type, bdaddr type) + 6 (the address)
        #    + 1 (data length field) + data length + 1 (rssi)) bytes long.
        report_pkt_offset = report_pkt_offset +  10 + report_data_length + 1
        rssi, = struct.unpack("<b", pkt[report_pkt_offset - 1])
        report["rssi"] = rssi
        result["advertising_reports"].append(report)
    return result