diff --git a/xwords4/linux/linuxbt.c b/xwords4/linux/linuxbt.c index e9214a30f..28eab8471 100644 --- a/xwords4/linux/linuxbt.c +++ b/xwords4/linux/linuxbt.c @@ -74,6 +74,37 @@ btConnectSocket( LinBtStuff* btStuff, const CommsAddrRec* addrP ) XP_LOGF( "%s: connect->%s", __FUNCTION__, strerror(errno) ); } } +} /* btConnectSocket */ + +static void +btWaitConnection( CommonGlobals* globals ) +{ + struct sockaddr_l2 saddr; + struct sockaddr_l2 inaddr; + int listener, sock; + socklen_t slen; + + listener = socket( AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP ); + + XP_MEMSET( &saddr, 0, sizeof(saddr) ); + saddr.l2_family = AF_BLUETOOTH; + saddr.l2_bdaddr = *BDADDR_ANY; + saddr.l2_psm = htobs( XW_PSM ); + + bind( listener, (struct sockaddr *)&saddr, sizeof(saddr) ); + + listen( listener, 3 ); /* eventually can accept up to 3 -- piconet */ + + // accept one connection + XP_LOGF( "%s: blocking on accept", __FUNCTION__ ); + slen = sizeof( inaddr ); + sock = accept( listener, (struct sockaddr *)&inaddr, &slen ); + XP_LOGF( "%s: accept returned", __FUNCTION__ ); + + close( listener ); + + (*globals->socketChanged)( globals->socketChangedClosure, + -1, sock ); } void @@ -88,6 +119,10 @@ linux_bt_open( CommonGlobals* globals, XP_Bool amMaster ) globals->u.bt.btStuff = btStuff; } + + if ( amMaster ) { + btWaitConnection( globals ); + } } void diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 52e883bbe..8d5767ce4 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -897,9 +897,13 @@ main( int argc, char** argv ) } } else if ( conType == COMMS_CONN_BT ) { bdaddr_t ba; - XP_Bool success = XP_FALSE; + XP_Bool success; XP_ASSERT( btaddr ); - if ( btaddr[1] == ':' ) { + if ( isServer ) { + success = XP_TRUE; + /* any format is ok */ + } else if ( btaddr[1] == ':' ) { + success = XP_FALSE; if ( btaddr[0] == 'n' ) { if ( !nameToBtAddr( btaddr+2, &ba ) ) { fprintf( stderr, "fatal error: unable to find device %s\n",