Make linux client work as host. Currently accepts only one connection

and blocks in accept.  Need threads and a piconet.
This commit is contained in:
ehouse 2006-08-29 13:20:09 +00:00
parent 209da1b042
commit f3eb95b891
2 changed files with 41 additions and 2 deletions

View file

@ -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

View file

@ -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",