Hi,
I am interested in using a pair of NRF52840 USB dongles to communicate on the L2CAP layer. I have flashed the dongles with the Zephyr's hci_usb samples, and have been able to connect the dongles with bluetoothctl. Now, I want to do the same using the socket functionality to use the L2CAP communication layer, however, I am receiving strerror EOPNOTSUPP (95): "Operation not supported", when using client-side connect() from sys/socket.h. I'm afraid I'm doing something conceptually wrong, but I also get the exact same error when trying hci_inquiry() from bluetooth/l2cap.h
Code example:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/socket.h> #include <bluetooth/bluetooth.h> #include <bluetooth/l2cap.h> #include <errno.h> extern int errno ; int main(void) { struct sockaddr_l2 addr = { 0 }; int s, status; char *message = "hello!"; char dest[18] = "ED:67:8A:54:94:40"; // allocate a socket s = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); // set the connection parameters (who to connect to) addr.l2_family = PF_BLUETOOTH; addr.l2_psm = htobs(0x1001); str2ba( dest, &addr.l2_bdaddr ); // connect to server status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); // send a message if( status == 0 ) { status = write(s, "hello!", 6); } int errnum = errno; if( status < 0 ) perror("uh oh"); if( status < 0 ) fprintf(stderr, "Error number: %d\n", errno); close(s); }
Some more info:
1) This isn't likely because I don't have a server-side listening since I get the same error with a different example using hci_inquiry() for scanning nearby devices.
2) The code reports "No route to host" (113) when unplugging the dongle.
3) Tried this code with NRF52_PCA10040 with hci_uart sample running.
4) Tried manually changing the default 00:00:00:00:00:00 address to something else.
5) Socket gets allocated properly
Hope you can help!