pythonbluetoothscapyrfcomm

How to send BluetoothRFCommSocket with Scapy?


I set up a BluetoothRFCommSocket with this code:

    from scapy.layers.bluetooth import *
    from scapy.all import *
    bt = BluetoothRFCommSocket('68:A0:3E:CC:24:06',2)

And the error is:

    Traceback (most recent call last):
      File "test.py", line 3, in <module>
        bt = BluetoothRFCommSocket('68:A0:3E:CC:24:06',2)
      File "/usr/local/lib/python2.7/dist-packages/scapy-2.4.3rc1.dev120-py2.7.egg/scapy/layers/bluetooth.py", line 1229, in __init__
        s.connect((bt_address, port))
      File "/usr/lib/python2.7/socket.py", line 228, in meth
        return getattr(self._sock,name)(*args)
    socket.error: [Errno 22] Invalid argument

What is the correct way to set up BluetoothRFCommSocket and send it?


Solution

  • I also get this error.

    From scapy source code:

    class BluetoothRFCommSocket(BluetoothL2CAPSocket):
    """read/write packets on a connected RFCOMM socket"""
    
    def __init__(self, bt_address, port=0):
        s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW,
                          socket.BTPROTO_RFCOMM)
        s.connect((bt_address, port))
        self.ins = self.outs = s
    

    Scapy uses SOCK_RAW to create the socket, but it seems like RFCOMM does not support this.(I have also tried to use c_types and libc, but the error still occured)

    Replace SOCK_RAW with SOCK_STREAM will eliminate the error.This is the way PyBluez use.

    (L2CAP support SOCK_RAW)