Skip to content

Bluetooth HCI Command Packet AttributeError #4741

@sacca97

Description

@sacca97

Brief description

When building an HCI Command Packet, trying to access the opcode raises AttributeError.
This causes, among other things, the BluetoothUserSocket send_command to crash.
However, the issue is not present when the packets are received and automatically parsed. Which makes me question if that is the correct way of building the packet.

Scapy version

2.6.1

Python version

3.13

Operating system

Linux 6.14.4

Additional environment information

No response

How to reproduce

(assuming cmd is any valid HCI_Cmd_X),

pkt = HCI_Hdr() / HCI_Command_Hdr() / cmd
print(pkt.opcode)

Actual result

  File "/home/x/Projects/y/z/hci.py", line 18, in send_cmd
    print(pkt.opcode)
          ^^^^^^^^^^
  File "/home/x/Projects/y/.z/lib64/python3.13/site-packages/scapy/packet.py", line 482, in __getattr__
    return self.payload.__getattr__(attr)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/x/Projects/y/.z/lib64/python3.13/site-packages/scapy/packet.py", line 482, in __getattr__
    return self.payload.__getattr__(attr)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/x/Projects/y/.z/lib64/python3.13/site-packages/scapy/packet.py", line 482, in __getattr__
    return self.payload.__getattr__(attr)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/x/Projects/y/.z/lib64/python3.13/site-packages/scapy/packet.py", line 480, in __getattr__
    fld, v = self.getfield_and_val(attr)
             ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/x/Projects/y/.z/lib64/python3.13/site-packages/scapy/packet.py", line 1886, in getfield_and_val
    raise AttributeError(attr)
AttributeError: opcode

Expected result

To print the actual opcode.

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions