All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manuel Reimer <mail+linux-bluetooth@m-reimer.de>
To: linux-bluetooth@vger.kernel.org
Subject: Bluetooth connection hangs after some retries (reset required/possible?)
Date: Fri, 4 Mar 2016 16:09:57 +0100	[thread overview]
Message-ID: <56D9A545.7070200@m-reimer.de> (raw)

Hello,

I'm still doing my first steps with bluetooth on Linux...

I'm trying to get HID reports of a bluetooth game controller (PS4 
gamepad). The relevant lines:

char dest[18] = "XX:XX:XX:XX:XX:XX";
int int_socket = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
struct sockaddr_l2 addr = { 0 };
addr.l2_family = AF_BLUETOOTH;
str2ba( dest, &addr.l2_bdaddr );
addr.l2_psm = htobs(L2CAP_PSM_HIDP_INTR);
connect(int_socket, (struct sockaddr *)&addr, sizeof(addr));
char buf[79] = { 0 };
int bytes_read;
bytes_read = recv(int_socket, buf, sizeof(buf), 0);
while(1) {
   if( bytes_read > 0 ) {
     printf("received [%s]\n", buf);
   }
}

Yes, I do proper initialization and yes, my "real code" has error handling.

If I run this code for the first time (currently I have the "hidp" 
module blacklisted to get sure I'm really the first user of the device), 
then everything works as expected. Initialization is done and lines are 
running through console.

Sometimes I'm able to Ctrl+C and restart *once* but it never is possible 
to do a third try. If I do so, then the "read" just hangs forever. This 
also happens if I disconnect the bluetooth device and reconnect it. I 
have to "systemctl restart bluetooth" in this case to get a new chance.

What is happening here? For me it seems like the bluetooth daemon 
"somehow" does some kind of "deadlocking". Maybe the controller keeps 
sending and noone takes the messages which causes the daemon to deadlock?

How to get around this? Is it actually possible to get this stable? Is 
there, for example, some command, I can send, so whatever hangs here is 
reset?

Thank you for every answer...

Best regards,

Manuel

             reply	other threads:[~2016-03-04 15:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 15:09 Manuel Reimer [this message]
2016-03-05 10:25 ` Bluetooth connection hangs after some retries (reset required/possible?) Manuel Reimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56D9A545.7070200@m-reimer.de \
    --to=mail+linux-bluetooth@m-reimer.de \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.