public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [Bluez-users] What's the best way to go about device detection?
@ 2004-05-17  5:35 Rob Raper
  2004-05-17 11:04 ` Marcel Holtmann
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Raper @ 2004-05-17  5:35 UTC (permalink / raw)
  To: bluez-users

Without involving any of my source code at alll, I can demonstrate one of my 
biggest problems.     I'll first create a connection to an existing 
bluetooth device.  It works fine.  I can get an RSSI value or link value.  
Then, I'lll try a non-existent device.   I get a connection timed out error 
fairly quickly.  Great, that's exactly what I want and what I expect.  What 
follows, however, is what is really causing me problems.  I can no longer 
connect to the valid bt device.   I just get errors for a long time.  I 
can't disconnect either.   How can I clear out the failed connection and 
move on without everything breaking down like this?

pluto62:~/bluez-utils-2.4/tools# hcitool cc 00:60:57:23:35:15
pluto62:~/bluez-utils-2.4/tools# hcitool rssi 00:60:57:23:35:15
RSSI return value: -1
pluto62:~/bluez-utils-2.4/tools# hcitool dc 00:60:57:23:35:15

So far so good...Now try an invalid address

pluto62:~/bluez-utils-2.4/tools# hcitool cc 00:60:57:23:35:14
Can't create connection: Connection timed out

As expected.

pluto62:~/bluez-utils-2.4/tools# hcitool dc 00:60:57:23:35:14
Disconnect failed: Input/output error

Why an input/output error?  It's on the con list, how do I get it off?

pluto62:~/bluez-utils-2.4/tools# hcitool cc 00:60:57:23:35:15
Can't create connection: Input/output error

Uh oh.. why can't I connect to the bt adapter that worked before?




>From: Marcel Holtmann <marcel@holtmann.org>
>To: Rob Raper <djrobx@hotmail.com>
>CC: BlueZ Mailing List <bluez-users@lists.sourceforge.net>
>Subject: Re: [Bluez-users] What's the best way to go about device 
>detection?
>Date: Sun, 16 May 2004 22:20:24 +0200
>
>Hi Rob,
>
> > Thanks for your reply.   I'll have a look into RSSI.   Is it
> > possible to use RSSI for detection, but then use RFCOMM to do the actual
> > communications?    Once "linked" to a server they don't ever need to 
>talk to
> > multiple servers at the same time.  It's just that other servers need to
> > determine signal strength in order to decide when to perform a hand off.
>
>this is what I said. The RSSI comes for free with an inquiry with RSSI
>command from the Bluetooth 1.2 specification. And while a connection is
>active you can retrieve it without any extra cost. Look at the hcitool
>info command and see how it finds the needed ACL handle of an existing
>connection.
>
>And btw check your devices that they really support inquiry while they
>maintain an open ACL connection.
>
> > Here's the block of code that I'm currently using to do a scan.  The old
> > version which worked better was simply a verison of the "hcitool scan"
> > routine modified to connect and check singal strength.
>
>Sorry, but I won't read that code. It is too much nested and actually
>code that needs more than 80 chars in a row is way too complex.
>
>Regards
>
>Marcel
>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: SourceForge.net Broadband
>Sign-up now for SourceForge Broadband and get the fastest
>6.0/768 connection for only $19.95/mo for the first 3 months!
>http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
>_______________________________________________
>Bluez-users mailing list
>Bluez-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/bluez-users

_________________________________________________________________
Watch LIVE baseball games on your computer with MLB.TV, included with MSN 
Premium! http://join.msn.click-url.com/go/onm00200439ave/direct/01/



-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users

^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <BAY14-F2518CB70kFir00064ba8@hotmail.com>]
* Re: [Bluez-users] What's the best way to go about device detection?
@ 2004-05-17 16:45 Rob Raper
  2004-05-17 17:05 ` Marcel Holtmann
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Raper @ 2004-05-17 16:45 UTC (permalink / raw)
  To: marcel; +Cc: bluez-users

I have two CSR based dongles (one D-Link DBt120 rev B3) and one Microsoft 
dongle from their wireless keyboard & mouse pack.   They both operate pretty 
much identically.   If I can obtain a 1.2 dongle that supports getting rssi 
on a scan it's probably a better solution anyway.   Your hardware support 
list shows all 1.1, however, do you know which dongles can support 1.2?

Also just FYI, the phones we're connecting to at the moment are Nokia 3650s.

The D-link that I do most of the testing on shows:

hci0:   Type: USB
        BD Address: 00:0F:3D:0B:FB:45 ACL MTU: 192:8  SCO MTU: 64:8
        UP RUNNING PSCAN ISCAN
        RX bytes:3686 acl:0 sco:0 events:273 errors:0
        TX bytes:2832 acl:0 sco:0 commands:205 errors:0
        Features: 0xff 0xff 0x0f 0x00 0x00 0x00 0x00 0x00
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy:
        Link mode: MASTER
        Name: 'Embt'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Ver: 1.1 (0x1) HCI Rev: 0x20d LMP Ver: 1.1 (0x1) LMP Subver: 
0x20d
        Manufacturer: Cambridge Silicon Radio (10)



>From: Marcel Holtmann <marcel@holtmann.org>
>To: Rob Raper <djrobx@hotmail.com>
>CC: BlueZ Mailing List <bluez-users@lists.sourceforge.net>
>Subject: Re: [Bluez-users] What's the best way to go about device 
>detection?
>Date: Mon, 17 May 2004 13:04:52 +0200
>
>Hi Rob,
>
> > Without involving any of my source code at alll, I can demonstrate one 
>of my
> > biggest problems.     I'll first create a connection to an existing
> > bluetooth device.  It works fine.  I can get an RSSI value or link 
>value.
> > Then, I'lll try a non-existent device.   I get a connection timed out 
>error
> > fairly quickly.  Great, that's exactly what I want and what I expect.  
>What
> > follows, however, is what is really causing me problems.  I can no 
>longer
> > connect to the valid bt device.   I just get errors for a long time.  I
> > can't disconnect either.   How can I clear out the failed connection and
> > move on without everything breaking down like this?
> >
> > pluto62:~/bluez-utils-2.4/tools# hcitool cc 00:60:57:23:35:15
> > pluto62:~/bluez-utils-2.4/tools# hcitool rssi 00:60:57:23:35:15
> > RSSI return value: -1
> > pluto62:~/bluez-utils-2.4/tools# hcitool dc 00:60:57:23:35:15
> >
> > So far so good...Now try an invalid address
> >
> > pluto62:~/bluez-utils-2.4/tools# hcitool cc 00:60:57:23:35:14
> > Can't create connection: Connection timed out
> >
> > As expected.
> >
> > pluto62:~/bluez-utils-2.4/tools# hcitool dc 00:60:57:23:35:14
> > Disconnect failed: Input/output error
> >
> > Why an input/output error?  It's on the con list, how do I get it off?
>
>if create_connection fails no ACL link is in the connection list and
>there is no need to disconnect it unless we have a bug in the Bluetooth
>core layer. However using the native HCI create_connection and
>disconnect functions is not a good idea and the timeout you see is not
>from the Bluetooth chip I think. If the create_connection process is
>still running you can't disconnect anything and in some cases you
>trouble the Bluetooth chip with such actions. Check with hcidump what is
>going on.
>
>What kind of Bluetooth modules are you using? Show us "hciconfig -a".
>
>Regards
>
>Marcel
>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: SourceForge.net Broadband
>Sign-up now for SourceForge Broadband and get the fastest
>6.0/768 connection for only $19.95/mo for the first 3 months!
>http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
>_______________________________________________
>Bluez-users mailing list
>Bluez-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/bluez-users

_________________________________________________________________
Express yourself with the new version of MSN Messenger! Download today - 
it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Bluez-users] What's the best way to go about device detection?
@ 2004-05-16 17:42 Rob Raper
  2004-05-16 20:20 ` Marcel Holtmann
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Raper @ 2004-05-16 17:42 UTC (permalink / raw)
  To: marcel; +Cc: bluez-users

Hi Marcel.  Thanks for your reply.   I'll have a look into RSSI.   Is it 
possible to use RSSI for detection, but then use RFCOMM to do the actual 
communications?    Once "linked" to a server they don't ever need to talk to 
multiple servers at the same time.  It's just that other servers need to 
determine signal strength in order to decide when to perform a hand off.

Here's the block of code that I'm currently using to do a scan.  The old 
version which worked better was simply a verison of the "hcitool scan" 
routine modified to connect and check singal strength.

the MobileOrbiterSocket class is my list of known BT devices that I could 
potentially connect to.

Thanks again for your help, it's much appreciated!


	int dev_id;
	dev_id = hci_devid(GetData()->Get_MAC_ADDR().c_str());
	if (dev_id < 0)
	{
		dev_id = hci_get_route(NULL);
		if (dev_id < 0)
		{
			m_pOCLogger->Write(LV_CRITICAL, "Can't get an ID for bluetooth dongle.");
			return;
		}
		else
		{
			m_pOCLogger->Write(LV_WARNING,"Bluetooth dongle %s not found, using 
hci0.", GetData()->Get_MAC_ADDR().c_str());
		}
	}

	int m_fdHCI = hci_open_dev(dev_id);
	if (m_fdHCI < 0)
	{
		m_pOCLogger->Write(LV_CRITICAL,"Device open failed");
		return;
	}
	OCSafetyFD sfhci(&m_fdHCI);
	m_DevInfo.dev_id = dev_id;
	if (ioctl(m_fdHCI, HCIGETDEVINFO, (void*) &m_DevInfo))
	{
		m_pOCLogger->Write(LV_CRITICAL,"Can't get info about device");
		return;
	}
	ba2str(&m_DevInfo.bdaddr, addr);
	m_pOCLogger->Write(LV_STATUS,"Attached to BT adapter: %s\t%s\n", 
m_DevInfo.name, addr);

	struct hci_filter nf;
	hci_filter_clear(&nf);
	hci_filter_all_ptypes(&nf);
	hci_filter_all_events(&nf);
	if (setsockopt(m_fdHCI, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)))
	{
		m_pOCLogger->Write(LV_CRITICAL,"Failed to set filter: %s\n", 
strerror(errno));
		return;
	}

	map<string, MobileOrbiterSocket *>::iterator iMos;
	unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr;
	evt_cmd_complete *cc;
	evt_cmd_status   *cs;
	evt_conn_complete *ecc;
	evt_disconn_complete *dcc;
	get_link_quality_rp *rp;
	hci_event_hdr *hdr;

	while(!m_bQuit)
	{
		struct timeval tv;
		int res;
		fd_set fds;
		tv.tv_sec = 1;
		tv.tv_usec = 0;
		for (;;) {
			FD_ZERO(&fds);
			FD_SET(m_fdHCI, &fds);
			res = select(m_fdHCI + 1, &fds, NULL, NULL, &tv);
			if (!res)
				break;
			if (res < 0) {
				if ((errno == EAGAIN) || (errno == EINTR))
					continue;
				break;
			}
			if (FD_ISSET(m_fdHCI, &fds))
			{
				while((res = read(m_fdHCI, buf, sizeof(buf))) < 0)
				{
					if ((errno == EAGAIN) || (errno == EINTR))
						continue;
				}
				printf("Read...\n");
				if (res < 0)
				{
					m_pOCLogger->Write(LV_STATUS, "Error reading from HCI handle");
				}
				else
				{
					hdr = (hci_event_hdr *)(buf + 1);
					ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
					res -= (1 + HCI_EVENT_HDR_SIZE);
					switch(hdr->evt) {
					case EVT_CMD_STATUS:
						cs = (evt_cmd_status *)ptr;
						switch(cs->opcode) {
						case SETUP_OPCODE:
							/* Setup */
							printf("Got %d bytes of setup status, status is %x!\n", res, 
cs->status);
							if (cs->status == 0x0c)  // Busy.
							{
								m_bIsSettingUp = false;
							}
							break;
						default:
							m_pOCLogger->Write(LV_CRITICAL, "Got status %02x on unknown opcode 
%d/%d, length %d\n", cs->status, cs->opcode, cs->ncmd, res);
						}
						break;
					case EVT_CONN_COMPLETE:
						m_bIsSettingUp = false;
						ecc = (evt_conn_complete *)ptr;
						ba2str(&ecc->bdaddr, addr);
						if (!ecc->status)
						{
							printf("Connected failed to '%s', status is %d\n", addr, 
ecc->status);
							break;
						}
						else
						{
							iMos = m_OrbiterSockets.find(addr);
							if (iMos != m_OrbiterSockets.end())
							{
								printf("Got connected to '%s'\n", addr);
								(*iMos).second->SetState(MOS_LINKED);
								(*iMos).second->m_ctNextEventTime = 
time(NULL)+MOS_T_CONNECT_STRENGTH_DELAY;
								(*iMos).second->m_Handle = ecc->handle;
							}
						}
						break;
					case EVT_DISCONN_COMPLETE:
						dcc = (evt_disconn_complete *)ptr;
						for(iMos = m_OrbiterSockets.begin(); iMos != m_OrbiterSockets.end(); 
++iMos)
						{
							if ((*iMos).second->m_Handle == dcc->handle)
							{
								switch((*iMos).second->GetState())
								{
									case MOS_CONNECTED:
										(*iMos).second->Disconnect();
										break;
									case MOS_LINKED:
										(*iMos).second->SetState(MOS_IDLE);
										(*iMos).second->m_ctNextEventTime = 
time(NULL)+MOS_T_TRYCONNECT_INTERVAL;
										break;
									default:
										printf("Notice (benign): Got disconnect for %s in state %d", 
(*iMos).first.c_str(), (*iMos).second->GetState());
										break;
								}
							}
						}
						break;
					case EVT_CMD_COMPLETE:
						cc = (evt_cmd_complete *)ptr;
						switch(cc->opcode) {
						case LQ_OPCODE:
							/* Link Quality Reply */
							rp = (get_link_quality_rp *)(ptr + EVT_CMD_COMPLETE_SIZE);
							for(iMos = m_OrbiterSockets.begin(); iMos != m_OrbiterSockets.end(); 
++iMos)
							{
								if ((*iMos).second->m_Handle == rp->handle)
								{
									switch((*iMos).second->GetState())
									{
										case MOS_LINKED_LINEQUALITY:
											if (!rp->status)
											{
												int diff = (*iMos).second->m_SignalStrength - rp->link_quality;
												if (diff < -15 || diff > 15)
												{
													printf("Detection event, link quality: %d", rp->link_quality);
													GetEvents()->Mobile_Orbiter_Detected(addr, 
StringUtils::itos(rp->link_quality).c_str());
													(*iMos).second->m_SignalStrength=rp->link_quality;
												}
											}
											else
											{
												m_pOCLogger->Write(LV_STATUS, "Notice (benign): Got status %d on 
link quality!", rp->status);
											}
											(*iMos).second->SetState(MOS_LINKED);
											(*iMos).second->m_ctNextEventTime = 
time(NULL)+MOS_T_SIGNALSTRENGTH_INTERVAL;
											break;
										case MOS_CONNECTED_LINEQUALITY:
											if (!rp->status)
											{
												(*iMos).second->m_SignalStrength=rp->link_quality;
											}
											else
											{
												m_pOCLogger->Write(LV_STATUS, "Notice (benign): Got status %d on 
link quality!", rp->status);
											}
											(*iMos).second->SetState(MOS_CONNECTED);
											break;
									}
								}
							}
							break;
						case SETUP_OPCODE:
							/* Setup */
							printf("Got %d bytes of setup complete!\n", res);
							break;
						default:
							m_pOCLogger->Write(LV_CRITICAL, "Got complete on unknown opcode 
%d/%d, length %d\n", cc->opcode, cc->ncmd, res);
						}
						break;
					case EVT_QOS_SETUP_COMPLETE:
						/* Ignore */
						break;
					default:
						printf("Got unknown event '%02x' with %d bytes\n", hdr->evt, res);
					}
				}
			}
		}








>From: Marcel Holtmann <marcel@holtmann.org>
>To: Rob Raper <djrobx@hotmail.com>
>CC: BlueZ Mailing List <bluez-users@lists.sourceforge.net>
>Subject: Re: [Bluez-users] What's the best way to go about device 
>detection?
>Date: Sun, 16 May 2004 14:23:59 +0200
>
>Hi Rob,
>
> > Sorry for the newbie questions or if I'm missing some obvious concepts, 
>but
> > I can't find any documentation for bluez, I've been primarily hacking
> > samples and learning by experimentation.  My RFCOMM implementation from 
>a
> > single server to a single phone works perfectly, my problem has to do 
>with
> > detection of a bluetooth device and signal strengths.
> >
> > I'm writing an application that involves having cell phones that
> > automatically attach to servers when they come into range; like a 
>'roaming'
> > application.    When the phone gets closer to another server (when going
> > from room to room), the previous server should detach from it and the 
>next
> > server will attach.  These servers are connected in their own way over
> > ethernet and coordinate the hand-off.
> >
> > So, the server needs to look for available phones and report their 
>signal
> > strengths, even if they're connected to another server.   When one
> > connection becomes significantly stronger, it will perform a coordinated
> > hand off (coordated by ethernet, not bluetooth).
>
>without knowing the source code it is hard to say, but actually I think
>this is a Bluetooth topology problem. Looks like that you are builing
>complex scatternets and the master/slave roles and the role switch are
>going to hit you badly.
>
>You should start using RSSI for signal strength, because link quality is
>a vendor specific value and differ from Bluetooth chip manufacturer to
>the other. The other big advantage with RSSI is that with Bluetooth 1.2
>you get it for free from an inquiry.
>
>Regards
>
>Marcel
>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: SourceForge.net Broadband
>Sign-up now for SourceForge Broadband and get the fastest
>6.0/768 connection for only $19.95/mo for the first 3 months!
>http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
>_______________________________________________
>Bluez-users mailing list
>Bluez-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/bluez-users

_________________________________________________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage! 
http://join.msn.click-url.com/go/onm00200362ave/direct/01/

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [Bluez-users] What's the best way to go about device detection?
@ 2004-05-15 17:36 Rob Raper
  2004-05-16 12:23 ` Marcel Holtmann
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Raper @ 2004-05-15 17:36 UTC (permalink / raw)
  To: bluez-users

Sorry for the newbie questions or if I'm missing some obvious concepts, but 
I can't find any documentation for bluez, I've been primarily hacking 
samples and learning by experimentation.  My RFCOMM implementation from a 
single server to a single phone works perfectly, my problem has to do with 
detection of a bluetooth device and signal strengths.

I'm writing an application that involves having cell phones that 
automatically attach to servers when they come into range; like a 'roaming' 
application.    When the phone gets closer to another server (when going 
from room to room), the previous server should detach from it and the next 
server will attach.  These servers are connected in their own way over 
ethernet and coordinate the hand-off.

So, the server needs to look for available phones and report their signal 
strengths, even if they're connected to another server.   When one 
connection becomes significantly stronger, it will perform a coordinated 
hand off (coordated by ethernet, not bluetooth).

My first stab was to take the hcitool sources and use a modified version 
"scan" function.   For each MAC it would then do a (hci_send_cmd) 
OCF_CREATE_CONN and just wait until  OCF_GET_LINK_QUALITY succeeded.    It 
worked fine on the one to many relationship (it would detect, then worked 
fine to connect to several phones.   But as soon we launched the app on 
another server, all hell broke loose.   The hci inquiry failed frequently, 
most of the time it couldn't even read the bluetooth name off the phone.  It 
seems I can't even really do a hcitool scan on multiple machines at the same 
time.

I don't really need to scan, I know the bluetooth addresses of the phones 
that could be in range.

I found sources to a utlity called btp (Bluetooth Presence) which is used 
with Digium's Asterisk PBX to detect the presence of your phone, which had 
much more detailed implementation of using hci_send_cmd and how to read its 
responses asynchronously by reading the bluetooth device descriptor, but I'm 
not going about something properly.    I iterate through my list trying to 
connect to phones.   When I send a connect to a phone that's nonexistent, 
about 5 second later, I stilll get a EVT_CONN_COMPLETE with the status of 0. 
   How do I know when the connection has failed?   Link level requests come 
back with Busy for phones that don't exist.    Is there a faster way to 
determine the non-presence of a phone so I can move onto the next one?  
Looking through btp's sources it looks like it looks at phones sequentially 
rather than issuing a bunch of connect requests all at the same time.   I 
guess I just don't have a good understanding of what things can and can't be 
done simultaneously over bluetooth.

If I ONLY try to connect to a phone that IS there, then my routine does go 
through and get its level and all is OK.   It's when the phone is not there 
that everything breaks down.  I can't even proceed onto the next phone 
correctly.

Any help is appreciated!

_________________________________________________________________
Check out the coupons and bargains on MSN Offers! http://youroffers.msn.com



-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-05-19 22:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-17  5:35 [Bluez-users] What's the best way to go about device detection? Rob Raper
2004-05-17 11:04 ` Marcel Holtmann
     [not found] <BAY14-F2518CB70kFir00064ba8@hotmail.com>
2004-05-19 22:44 ` Marcel Holtmann
  -- strict thread matches above, loose matches on Subject: below --
2004-05-17 16:45 Rob Raper
2004-05-17 17:05 ` Marcel Holtmann
2004-05-16 17:42 Rob Raper
2004-05-16 20:20 ` Marcel Holtmann
2004-05-15 17:36 Rob Raper
2004-05-16 12:23 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox