mirror of
https://github.com/google/bumble.git
synced 2026-05-06 03:38:01 +00:00
@@ -594,7 +594,10 @@ class SDP_PDU:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_bytes(cls, pdu: bytes) -> SDP_PDU:
|
def from_bytes(cls, pdu: bytes) -> SDP_PDU:
|
||||||
pdu_id, transaction_id, _parameters_length = struct.unpack_from('>BHH', pdu, 0)
|
pdu_id, transaction_id, parameters_length = struct.unpack_from('>BHH', pdu, 0)
|
||||||
|
|
||||||
|
if len(pdu) != 5 + parameters_length:
|
||||||
|
logger.warning("Expect %d bytes, got %d", 5 + parameters_length, len(pdu))
|
||||||
|
|
||||||
subclass = cls.subclasses.get(pdu_id)
|
subclass = cls.subclasses.get(pdu_id)
|
||||||
if not (subclass := cls.subclasses.get(pdu_id)):
|
if not (subclass := cls.subclasses.get(pdu_id)):
|
||||||
@@ -616,9 +619,11 @@ class SDP_PDU:
|
|||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
if self._payload is None:
|
if self._payload is None:
|
||||||
self._payload = struct.pack(
|
parameters = hci.HCI_Object.dict_to_bytes(self.__dict__, self.fields)
|
||||||
'>BHH', self.pdu_id, self.transaction_id, 0
|
self._payload = (
|
||||||
) + hci.HCI_Object.dict_to_bytes(self.__dict__, self.fields)
|
struct.pack('>BHH', self.pdu_id, self.transaction_id, len(parameters))
|
||||||
|
+ parameters
|
||||||
|
)
|
||||||
return self._payload
|
return self._payload
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -18,9 +18,11 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from bumble import sdp
|
||||||
from bumble.core import BT_L2CAP_PROTOCOL_ID, UUID
|
from bumble.core import BT_L2CAP_PROTOCOL_ID, UUID
|
||||||
from bumble.sdp import (
|
from bumble.sdp import (
|
||||||
SDP_BROWSE_GROUP_LIST_ATTRIBUTE_ID,
|
SDP_BROWSE_GROUP_LIST_ATTRIBUTE_ID,
|
||||||
@@ -206,6 +208,16 @@ def sdp_records(record_count=1):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
def test_pdu_parameter_length(caplog) -> None:
|
||||||
|
caplog.set_level(logging.WARNING)
|
||||||
|
pdu = sdp.SDP_ErrorResponse(
|
||||||
|
transaction_id=0, error_code=sdp.ErrorCode.INVALID_SDP_VERSION
|
||||||
|
)
|
||||||
|
assert sdp.SDP_PDU.from_bytes(bytes(pdu)) == pdu
|
||||||
|
assert not re.search("Expect \d+ bytes, got \d+", caplog.text)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_service_search():
|
async def test_service_search():
|
||||||
|
|||||||
Reference in New Issue
Block a user