Closed jonarrien closed 1 year ago
I would need to review the Linux kernel documentation and source code to shed light on this answer. But it should be similar to creating an L2CAP socket, just the that socket options and maybe address binding would be different, but the kernel should have this functionality built-in.
Here is an example to get you started https://github.com/pauloborges/bluez/blob/master/tools/rfcomm.c#L502
Thanks @colemancda, that link has been incredibly helpful.
I've been able to create RFCOMMSocket using sockaddr_rc, set socket options, connect device using SOCK_STREAM and send some data successfully. :)
Just some question raised during the implementation, because I was not able to connect until pairing it first using bluetoothctl
with the following commands:
[bluetoothctl] pair XX:XX:XX:XX:XX:XX
[bluetoothctl] trust XX:XX:XX:XX:XX:XX
There is a 6 digit code that needs to be confirmed when pairing the device and I was expecting to see them when scanning for a device and invoking connect
function. With IOBluetooth
on macOS it happens when establishing RFCOMM connection as far as I can remember.
If device is paired and trusted via bluetoothctl, the app perfectly establishes a connection and send data. Even with a non-privileged user, which didn't expect, but is very nice.
Is there any function to pair and trust the device from code like bluetoothctl does? or should it happen when invoking connect
? Not sure what I'm missing.
On the other hand, I think OptionSet could be a good fit for RFCOMMSocket.Options and for L2CAPSocket.Options. I may give it a try. Swift OptionSet
Hi,
I see rfcomm is defined in BluetoothProtocols but not aware if RFCOMM sockets can be established currently. Seems the project is more focused on BLE implementation and would like to know if you consider implementing a RFCOMMSocket or similar class.
In case you foresee implementing it or accept contributions, could you describe briefly what steps should be followed for the implementation? Also thinking about BluetoothDarwin library and using IOBluetoothRFCOMMChannel there, but sharing similar architecture.
I've used IOBluetooth framework before, but still a newbie when it comes to Bluez. I'm interested in opening a serial port with bluetooth classic accessories.
Any light you can through on this matter would be really appreciated.