June 24, 2003

80 00 1A 00 0F D7

My dabbling with Bluetooth continues. Using WSASetService it's pretty easy to get your device to advertise a standard Bluetooth service on one of its sockets. Simply create your socket with the Bluetooth address family, bind and listen as normal and then call WSASetService to start advertising a service on this socket to other devices within range. Now call accept and wait...

I chose the File Transfer Service as my hello world service. Get one of your other devices to discover your services and the new service should appear. Connect and your accept will return a connected socket. Issue a recv and you get the bytes that form the title to this piece. That's the start of an OBEX Connect packet...


Share this entry: Email it! | bookmark it! | digg it! | reddit!

Posted by Len at June 24, 2003 05:42 AM | Comments (163) | Categories : Geek Speak
Comments

Hi Hi... I am now working on Bluetooth programming on winsock also... But I find that I always fail in WSASetService, can you send me your program for teaching me? Thanks a lot for your kind help. Yours, KK

Posted by: KK at July 11, 2003 10:49 AM

Rough and ready code, but it worked for me.

WORD wVersionRequested = 0x202;
WSADATA m_data;

if (0 == ::WSAStartup(wVersionRequested, &m_data))
{
SOCKET s = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

const DWORD lastError = ::GetLastError();

if (s == INVALID_SOCKET)
{
printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));
exit(1);
}

WSAPROTOCOL_INFO protocolInfo;

int protocolInfoSize = sizeof(protocolInfo);

if (0 != getsockopt(s, SOL_SOCKET, SO_PROTOCOL_INFO, (char*)&protocolInfo, &protocolInfoSize))
{
exit(1);
}

SOCKADDR_BTH address;

address.addressFamily = AF_BTH;
address.btAddr = 0;
address.serviceClassId = GUID_NULL;
address.port = BT_PORT_ANY;

sockaddr *pAddr = (sockaddr*)&address;

if (0 != bind(s, pAddr, sizeof(SOCKADDR_BTH)))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

int size = sizeof(SOCKADDR_BTH);

if (0 != getsockname(s, pAddr, &size))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

if (0 != listen(s, 10))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

WSAQUERYSET service;

memset(&service, 0, sizeof(service));

service.dwSize = sizeof(service);

service.lpszServiceInstanceName = "My Service";
service.lpszComment = "My comment";

GUID serviceID = OBEXFileTransferServiceClass_UUID;

service.lpServiceClassId = &serviceID;

service.dwNumberOfCsAddrs = 1;
service.dwNameSpace = NS_BTH;

CSADDR_INFO csAddr;

memset(&csAddr, 0, sizeof(csAddr));

csAddr.LocalAddr.iSockaddrLength = sizeof(SOCKADDR_BTH);
csAddr.LocalAddr.lpSockaddr = pAddr;

csAddr.iSocketType = SOCK_STREAM;
csAddr.iProtocol = BTHPROTO_RFCOMM;

service.lpcsaBuffer = &csAddr;

if (0 != WSASetService(&service, RNRSERVICE_REGISTER, 0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

SOCKET s1 = accept(s, 0, 0);

unsigned char buffer[2000];

memset(buffer, 0, sizeof(buffer));

int r = recv(s1,(char*)buffer, sizeof(buffer), 0);

Posted by: Len at July 21, 2003 09:29 PM

Interesting how the socket function works for you.

I get a 10047 (Protocol not supported by address family error) when I use the socket command.

Posted by: Will at September 7, 2003 10:18 PM

You need windows XP SP 1 and native support for your bluetooth device for this stuff to work.

Posted by: Len at September 8, 2003 12:10 AM

I have XP SP1.

Posted by: Will at September 9, 2003 05:32 PM

Will, see the comments on the Bluetooth Sockets entry. In summary:

"As far as I know it will only work if XP recognises your bluetooth device and doesnt need additional drivers. I have a TDK dongle that needs its own drivers and doesnt integrate with XP's wireless link control panel applet and that doesnt work with the code above. I have built in bluetooth on the Sony Vaio and that integrates with XP's control panel applet and works with the code above. "

Posted by: Len at September 9, 2003 05:53 PM

Thanks, that actually helps alot!

I used the Windows Catalog.

http://www.microsoft.com/windows/catalog/default.aspx?subID=22&xslt=search&qu=bluetooth&scope=0

Posted by: Will at September 9, 2003 09:54 PM

Cool.

Posted by: Len at September 9, 2003 10:23 PM

what did you find in the windows catalog?
the link does not work for me.
did you find a list of winxp-natively supported bluetooth-hardware there?

Posted by: slomoman at October 3, 2003 11:44 AM

Hi,
I am trying to send a file from PC to nokia3650.I am getting Invalid_socket error when I create a socket using..
SOCKET s = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
I have windows xp with service pack1,I am using VC++.My bluetooth adapter is D-Link(DBT-120). What else do I need?.

Posted by: swarna at October 8, 2003 06:15 AM

You need a bluetooth stack/driver that supports Windows XP SP1's bluetooth integration.

Posted by: Len at October 8, 2003 08:39 AM

Where Can I get it or download it?.

Posted by: swarna at October 8, 2003 10:26 PM

I think you need to speak to the supplier of your hardware.

Posted by: Len at October 8, 2003 11:06 PM

ok..I'll. Thank you very much.

Posted by: swarna at October 8, 2003 11:45 PM

I have downloaded the latest driver for windows XP from Dlink site. It didn't help. My laptop could identify the cell phone but not able to exchage messages programmatically. I am planning to test with some other BT adapter . Can anyone suggest me a good one?.
Thanks,
Swarna

Posted by: swarna at October 10, 2003 05:38 PM

If you take a look in the Windows XP driver you find a list of bluetooth hardware, natively supported by XP:

[ALPS.NT.5.1]
ALPS Integrated Bluetooth Device= BthUsbDriverInstallXP, USB\Vid_044e&Pid_3005
Alps Bluetooth USB Adapter= BthUsbDriverInstallXP, USB\Vid_044e&Pid_3006

[BrainBoxes.NT.5.1]
Brain Boxes USB Bluetooth Adapter BL-554= BthUsbDriverInstallXP, USB\Vid_05d1&Pid_0003

[Cambridge.NT.5.1]
Cambridge Silicon Radio Ltd. Bluetooth Adapter=BthUsbDriverInstallXP, USB\Vid_0a12&Pid_0001

[FIC.NT.5.1]
FIC Bluetooth Wireless Adapter= BthUsbDriverInstallXP, USB\Vid_05b1&Pid_1389

[GVC.NT.5.1]
GVC Bluetooth Wireless Adapter= BthUsbDriverInstallXP, USB\Vid_0525&Pid_a220

[IBM.NT.5.1]
Bluetooth UltraPort Module from IBM= BthUsbDriverInstallXP, USB\Vid_04BF&Pid_0317
IBM Integrated Bluetooth= BthUsbDriverInstallXP, USB\Vid_04BF&Pid_0318
IBM Integrated Bluetooth II= BthUsbDriverInstallXP, USB\Vid_1668&Pid_0441

[Microsoft.NT.5.1]
Microsoft Wireless Transceiver for Bluetooth= BthUsbDriverInstallXP, USB\Vid_045e&Pid_007e

[SiliconWave.NT.5.1]
Silicon Wave Bluetooth Wireless Adapter= BthUsbDriverInstallXP, USB\Vid_0c10&Pid_0000

[Sony.NT.5.1]
USB Bluetooth Device= BthUsbDriverInstallXP, USB\Vid_044E&Pid_3002
USB Bluetooth Device= BthUsbDriverInstallXP, USB\Vid_044E&Pid_3003
Sony Bluetooth USB Adapter= BthUsbDriverInstallXP, USB\Vid_044E&Pid_3004

[TDK.NT.5.1]
TDK Bluetooth USB Adapter= BthUsbDriverInstallXP, USB\Vid_04BF&Pid_0319

[Toshiba.NT.5.1]
TOSHIBA Integrated Bluetooth= BthUsbDriverInstallXP, USB\Vid_0930&Pid_0502&Rev_1350
TOSHIBA Integrated Bluetooth 2= BthUsbDriverInstallXP, USB\Vid_0930&Pid_0505

I've got it running with the BL-554 from brainboxes. But i had to adapt the USB Adress previously....

Posted by: daniel at November 19, 2003 08:33 AM

Just found this:

http://www.tdksystems.com/support/faqs2/index.html?http://www.metafaq.com/faq/tdksys/bluetooth

It seems that you can purchase the windows xp bluetooth stack for the TDK USB device. I've no idea why it's something you have to purchase rather than them just making it available as a download.... Does anyone know if the stack is available elsewhere as a download rather than a purchase? (more interested in getting it faster than saving money...)

Posted by: Len at November 19, 2003 01:23 PM

I didnt notice that the url I posted in the last comment was some useless framebased crap. This is what you need to get the drivers from TDK.

http://www.tdkshop.com/products.aspx?catid=5

Posted by: Len at November 21, 2003 06:18 AM

Purchased and installed the TDK drivers and they work fine.

Posted by: Len at November 26, 2003 06:26 PM

Note that only the USB Bluetooth devices shipped with the Microsoft logo (Designed for XP) will actually work under Windows XP SP1 Bluetooth drivers.
To check, the TDK Systems USB vendor ID (VID) is 0x4BF and the product ID (PID) for TDK Systems USB products which work with the Microsoft drivers are 0x319.
I hope this may help.

Posted by: Sinclair at December 3, 2003 05:12 PM

Hi, Len, what's the best way to connect to a device that does not have a standard service/profile? Can we just get its radio address and then connect to it using "connect" socket function? Also, in this situation, are we writing a client application instead of server application? For bluetooth client application, it appears that we need to use both bind and connect functions, am I right?

Thanks.

Posted by: Rockie at December 16, 2003 03:14 AM

Rockie,

To be honest, I dont know. I've only just got to a point where I had two machines which supported the bluetooth winsock stuff and I havent had a chance to play with them together yet.

I would imagine that you can just use sockets like you'd expect to for other transports...

Posted by: Len at December 18, 2003 10:00 AM

Hi,

I get a compilation error, "Ws2bth.h: No such file or directory" when I compile the sample code in Microsoft Visual studio .Net ( vc7) 2002.
I searched under vc7\PlatformSDK\include but I could not find this file. I compiled in WinXP Sp1.

Do I need any patches or anything? How do I get this file.

Thanks in advance

Posted by: Uma at January 6, 2004 10:13 PM

I have the Feb 2003 platform sdk installed and Ws2bth.h is in the D:\Program Files\Microsoft SDK\include directory.

Posted by: Len at January 6, 2004 10:35 PM

Hi Len, do you have the code for the client which corresponds to the example above or did you not get that far? It Would be great if you could make that available.

Phil

Posted by: Phil Worgan at January 20, 2004 03:35 PM

Phil

No, not at the moment.

Posted by: Len at January 25, 2004 01:15 PM

Hi! All,

I was reading this Bluetooth stuff, very impressive, and like it in C++ and specially on Microsoft Platform.

I have a query, is it possible to use that code in C#? if so then any hint to start with?

Take Care,

Mudassir
San Jose, CA

Posted by: Mohammed Mudassir at February 29, 2004 10:03 AM

Mudassir

I don't think you can get down to the low level winsock code in C# directly. You'd have to use pInvoke or whatever. The approach I'd take is to take care of the messy stuff in C++ and either wrap that in COM and use COM interop to get at it from C# or wrap it in managed C++ and access it directly...

Posted by: Len at February 29, 2004 01:11 PM

Thanks,

Seems to me i have to make my hand dirty in C++ , never used that lingo before.

Oh one more query, I have Platform SDK, and Windows 2000 Server can we develop this Bluetooh Server kind of thing on 2000 Platform? Because as I read the artilce of , it clearly indicate that you must have XP? Any idea if its okay to use this on 2000 Server , using some other mean

Thanks again,

Mudassir,

San Jose, CA

Posted by: Mohammed Mudassir at February 29, 2004 05:47 PM

Only XP supports winsock bluetooth access, as far as I know.

Posted by: Len at February 29, 2004 06:51 PM

Hi! Len,

Just installed the XP & SP1 on my old PIII and with VS.NET after having an awesome weekend on Santa Cruz.

Any idea which DLL i have to call using PInvoke to get access to the Bluetooth Socket? WinSock2? or Win32?

ciao

Mudassir

San Jose, CA


Posted by: Mohammed Mudassir at March 25, 2004 05:23 AM

I'd guess at ws2_32.dll

Posted by: Len at March 25, 2004 08:16 AM

Hi Len! i'm developing a bluetooth project and i have a problem. I need to comunicate a Pocket Pc 2003 with a server to exchange some files. The problem is that, in the server software (that i'm developing with Visual Studio.NET 2003) i can't open a socket connection. It compiles correctly and executes normal, but when it opens a socket connection it breaks. I don't know what happends.
Do you know what can be happening or what i'm doing wrong? Another question is, can i comunicate 30 Pocket PC's with the server? (Not simultaniusly). How?

Thanks for the response!

Posted by: Javi at May 18, 2004 12:08 PM

This is the code i'm using:

WORD wVersion=0x202;
WSADATA m_data;

if(0==::WSAStartup(wVersion,&m_data))
{
SOCKET s=socket(AF_BTH,SOCK_STREAM,BTHPROTO_RFCOMM);
if(s==INVALID_SOCKET)
{
MessageBox((CString)"No se ha podido crear el socket de Conexión",(CString)"Socket Error",MB_OK|MB_ICONERROR);
}
else
{
SOCKADDR_BTH name;
memset(&name,0,sizeof(name));
name.addressFamily=AF_BTH;
name.btAddr=0;
name.serviceClassId=GUID_NULL;
name.port=0;
sockaddr *pAddr=(sockaddr*)&name;
if(0!=bind(s,pAddr,sizeof(SOCKADDR_BTH)))
{
MessageBox((CString)"Bind Error",(CString)"Socket Error",MB_OK|MB_ICONERROR);
closesocket(s);
exit(1);
}
listen(s,SOMAXCONN);

for(; ;)
{
SOCKADDR_BTH sab2;
int ilen=sizeof(sab2);

SOCKET s2=accept(s,(SOCKADDR*)&sab2,&ilen);

if(s2==INVALID_SOCKET)
{
MessageBox((CString)"No se ha podido crear el socket de Recepción",(CString)"Socket Error",MB_OK|MB_ICONERROR);
}
else
{
MessageBox((CString)"OK");
}
}
closesocket(s);
}
}

Posted by: Javi at May 18, 2004 12:20 PM

Javi, it would help if you told me how it breaks... Have you read all the comments on the bluetooth articles here? Are you SURE you have a device that is supported natively by the Windows XP SP1 Bluetooth support? Does my sample code here run OK?

Posted by: Len at May 18, 2004 08:48 PM

Hello again!

Now i know that the error i get is this one:

WSAEAFNOSUPPORT (10047)
Translation: Address family not supported by protocol family.
Description: An address that is incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket (Wsapiref_2qr6.asp) call or if an address of the wrong family is used for a socket, for example, in sendto (Wsapiref_4sqa.asp).

Anyone knows how to resolve or debug it?

thanks in advance!

Posted by: Javi at May 18, 2004 09:03 PM

Javi,

Take a look at the sample code here: http://www.lenholgate.com/archives/000102.html this code works if you have the right hardware.

Len

Posted by: Len at May 18, 2004 11:21 PM

Hi Len!

Thanks in advance for all your help!

When I execute your code i get the following error:
"Error on init the application. Can't find irprops.cpl"

Do you or Someone knows what happends here?

Posted by: Javi at May 21, 2004 10:19 AM

irprops.cpl is part of the Windows XP SP1 Bluetooth support. If you dont have compatible hardware and you dont have it working natively with windows xp then this code wont work.

Posted by: at May 21, 2004 10:29 AM

Hi everybody!

I'm developing a bluetooth compatible application and i found the same errors like yours.
But it's difficult to me to understand why need windows XP native recognizing of our dongle Bluetooth device.

Someone can explain me why? I search in all MSDN and i haven't found any page where says that developers only can program with native bluetooth devices. Has it an explanation?

thanks in advance!!

Posted by: Synth2 at May 21, 2004 10:59 AM

If your device has native Windows XP SP 1 support then it has the correct drivers to work with Winsock. If it doesn't, then you need to contact the manufacturer of your device and find out who supplies the SDK for the drivers.

Posted by: Len Holgate at May 21, 2004 12:45 PM

Hi Len!

I have installed Windows XP SP1 and now it recognizes my Bluetooth device natively (an Conceptronic CBT100u with CSR radio xip) as CSR Bluetooth Device, but yet i get the 10047 Error when i try to create a socket.

Am I forgetting something?

P.D.

I also instaled Q323183_WXP_SP2_X86_ESN that makes possible the recognition of my device.

thanks in advance.

Posted by: Synth2 at May 25, 2004 10:39 AM

Are you running MY sample code and getting this error?

Posted by: Len at May 25, 2004 10:54 AM

Hi Len

Yes.I'm doing a copy-paste from the web to the Visual Studio.Net Project. It compiles but breaks when has to create the socket and return Error code 10047. I have 2 different Bluetooth devices and it breaks with all them.

Posted by: Synth2 at May 25, 2004 11:28 AM

Strange. Sorry but all I can say is that 'it works for me'. Read all the comments on all of the bluetooth postings; perhaps someone has had similar problems?

Posted by: Len at May 25, 2004 11:37 AM

I want to ask you something.

When you say "Native recognition" you mean that, when you insert the USB dongle at first time, windows ask you for drivers, at this moment it's not necessary for me to insert any cd or indicate to windows any path to locate those drivers. Windows automatically searches for the drivers and find one who is " CSR USB Bluetooth Device" and finish the installation.
The device runs correctly.

it's that what you understands for "Native Recognition"? or is any other thing?

Posted by: Synth2 at May 25, 2004 11:43 AM

Possibly. What you MUST have (as far as I know) is a control panel applet named "Wireless Link" which has a "Bluetooth" tab for configuring your hardware. You shouldn't need to have ANY other drivers loaded and if you've previously loaded drivers you should remove them. If you dont have the control panel applet then the winsock code doesnt work.

Posted by: Len at May 25, 2004 11:51 AM

Ok

I haven't this control panel applet.
All i have is a Bluetooth option at the Control Panel (the default Windows XP control Panel in My Pc). Nothing like Wireless Link.

What this means? That i haven't installed correctly Windows XP SP1?

Posted by: Synth2 at May 25, 2004 11:57 AM

I've no idea. Have you uninstalled all the drivers that came with your device?

Posted by: Len at May 25, 2004 12:10 PM

Yes. I've sended a mail to Conceptronic (the manufacturer) and tell me that my device was compatible with Windows XP SP2 but this pack is still in a Beta version. They tell me that all the disponible drivers are in the web and i've donwloaded and installed all them.

Posted by: at May 25, 2004 12:30 PM

Hi Len!

Where can i find all the services that we can offer to a device? (I mean like in your code is OBEXFileTransferServiceClass_UUID)

Thanks in advance!


Posted by: Synth2 at May 26, 2004 11:06 AM

In one of the headers, why not do a search for OBEXFileTransferServiceClass_UUID in files of type *.h in the platform sdk include directory...

Posted by: Len Holgate at May 26, 2004 11:14 AM

Hi Len!

First of all Thank you for all your help.
Without your help i'm lost!!

I have a new question. In the client device what function do you use to find the service of the client? WSALookupServiceBegin?

Posted by: Synth2 at May 27, 2004 08:42 AM

Sorry i forget to ask yoy how do you search (in the bluetooth device) for others devices?

Posted by: Synth2 at May 27, 2004 08:55 AM

Sorry Len!

I re-write my tow questions:

1) In the client device, what function do you use to find the server service (in your code sample OBEXFileTransferServiceClass_UUID). You uses WSALookupServiceBegin?

2) How doy you search (in the bluetooth device) for other devices arround?

Thanks!

Posted by: Synth2 at May 27, 2004 09:04 AM

One of the samples oh here does that.

Go look up WSALookupServiceBegin and Bluetooth on MSDN.

Posted by: Len Holgate at May 27, 2004 10:01 AM

Sorry

where can i find this sample?
I search in MSDN i can't find it
Thanks and excusme for my ignorance.

Posted by: Synth2 at May 27, 2004 10:10 AM

This sample does device and service discovery:
http://www.lenholgate.com/archives/000102.html

and typing "MSDN WSALookupServiceBegin Bluetooth" (without the quotes into Google gives the correct MSDN page as the second item listed...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bluetooth/bluetooth/bluetooth_and_wsalookupservicebegin_for_device_inquiry.asp

Posted by: Len Holgate at May 27, 2004 10:29 AM

Hi!

I have a problem with the WSALookupServiceBegin function. I get Error 10022 when i use this function. Here is the code i'm using.
this code is the one i used in my Pocket Pc (not in a PC). I want to contact my Pocket Pc and my Pc via Bluetooth with sockets.

WSADATA data;

if(WSAStartup(0x202,&data)==0)
{
//Se ha iniciado correctamente la libreria ws2.dll//

WSAQUERYSET Query1;
LPHANDLE Handle1=NULL;

Query1.dwSize=sizeof(WSAQUERYSET);
Query1.dwNameSpace=NS_BTH;

if(WSALookupServiceBegin(&Query1,LUP_RETURN_NAME|LUP_RETURN_ADDR,Handle1)==0)
{
//Se ha iniciado correctamente la busqueda de dispositivos//
DWORD ret;
LPDWORD tam;

do
{
tam=(unsigned long *)sizeof(Query1);
ret=WSALookupServiceNext(Handle1,NULL,tam,&Query1);
MessageBox((CString)Query1.lpszServiceInstanceName);

}while(ret!=WSA_E_NO_MORE);

}
else
{
//Error en la inicialización de la busqueda de dispositivos//
CString a;
a.Format(_T("Error en la inicialización de la búqueda de dispositivos. Error %d"),GetLastError());
MessageBox(a,(CString)"WSALookupServiceBegin Error",MB_OK|MB_ICONERROR);
}
}
else
{
//No se ha podido iniciar la libreria ws2.dll//

MessageBox((CString)"No se ha podido iniciar la libreria ws2.dll",(CString)"WS2.dll no Iniciada",MB_OK|MB_ICONERROR);
}

WSACleanup();


/////

Anyone knows where is or can be the problem?

thanks in advance!

Posted by: Synth2 at May 28, 2004 09:52 AM

Posting the same comment on two entries isn't a good thing and probably wont result in more helpful responses...

Posted by: Len Holgate at May 28, 2004 11:24 AM

Where can I find the q323183_wxp_sp2_x86_esn.exe, I have the q323183_wxp_sp2_x86_enu.exe but by OS language (Win XP Spanish) it don't work.

Posted by: John at June 20, 2004 07:52 PM

Hi there,

As I have read 'Synth2' was trying to use the conceptronic wireless CBT100U with XP+SP1+Q323183.

I have read all the comments posted I now I see clearly that my XP+SP1+Q323183 doesn't recognize my CBT100U.

I'm afraid XP+SP2 is probably the solution to recognition of my CBTU, but I have to resolve my
problem with XP+SP1+Q323183.

Synth2, Have you get some positive results with your problem ?

Have you found the way to recognize the CBTU with your XP ?

Thanks Len&Synth2

Jorge

PD. John, the q323183_wxp_sp2_x86_esn.exe is provided directly by microsoft support.

Posted by: jorlopez at July 1, 2004 09:18 AM

i just bought used wireless transceiver for bluetooth (microsoft) i could not find any drivers even at the microsoft com. where can i find em. if possiple e-mail me please.

Posted by: George at July 4, 2004 11:45 AM

While I was searching for a problem with my pocket pc bluetooth connection, I stumbled on this list an found there wero more people with such a problem.
Allthough it didn't solve my problems, you can find a microsoft sample in the following dir (if you have installed the pocket pc 2003 sdk) :
\Windows CE Tools\wce420\POCKET PC 2003\Samples\Win32\Bluetooth\btsearch

Posted by: MArnix at July 15, 2004 10:48 AM


Hi,

Does anyone know where I can download a Bluetooth stack compatible with the Windows 2000/Visual C++ environment.

A free stack is much appreciated...

Regards


Posted by: Dinesh at July 24, 2004 10:50 AM

Dear

This is to inquire that how can one downlaod the latest driver for ALPS BLUETOOTH DEVICE with the following Properties:

Name: Alps Bluettoth Device
Type: USB
Maufacturer: Cambridge Silicon Radio
Firmware Revision: Version 332
Device Address: 00:0D:10:01:1A:8C
HCI Version: Bluetooth HCI 1.1
HCI Revision:014C
LMP Vesrion: Bluettoth LMP 1.1
LMP Sub Version: 014C

I have just upgarded my previous Windows XP Prof Version to the Windows Xp Prof Version with Service Pack 2 which is not recognising the Bluetooth Audio(upgarded 3-4 times due to Windows Update prob- issue in discussion with MS , prob when reinstalled this time)and hence the need for the Latest Driver which is Windows XP Recognised.

I shall be very gretaful for the early favor.

Thanks and Regards

Rohan Sharma

Posted by: Rohan Sharma at March 1, 2005 04:30 AM

I have a MICROSOFT WIRELESS TRANCEIVER FOR BLUETOOTH but there is no device driver for it on my system. So i cant even use it. Information on how to install and use it will be highly appreciated. Presently am running WINDOWS XP on my pc.

Posted by: Dare at April 5, 2005 12:07 PM

Hi Len and everyone else,

I've written an app using C# for my PDA which looks for a Bluetooth SPP service running on devices in the same vicinity. When it finds one, it connects and sends a string of data to the service. Without Len's code it would have taken me a long time to figure out how to do this.

I'm now at the stage where I want to send a string of data from the Bluetooth SPP server back to the PDA application.

The problem is, when I issue the send() function using the socket handle used for the recv() function I get Winsock error 10053 - connection aborted.

Does anyone know why this is happening and how to correct it so that the data I want send, gets sent correctly?

Many thanks,

Rich

Posted by: Richard Telford at April 20, 2005 03:09 PM

The problem was - I was accept()ing the socket connection within a do{}while loop. I was trying to recv() data outside of this loop .. but scope was forced within. I just took the accept() outside the loop and hey presto!

My problems now are much, much worse =) yay!

Posted by: Richard Telford at April 22, 2005 05:38 PM

Hi Len,

I'm currently trying to send files to a mobile phone without authentication and without additionnal soft on the phone. Is it possible using winsock, like shown in your sample code ?
Creating a socket with OBEXFileTransferServiceClass advertised as a service is enough to connect to a mobile phone and send files or there is something else to do ?
And are there alternatives to winsock ?

Regards.

Posted by: JPH at April 27, 2005 10:24 AM

When I run your example I am able to discover all the BT devices however when I get to the point


SOCKET s1= accept(s, 0, 0);
unsigned char buffer[2000];

in your code it seems to hang waiting... how can I communicate with a PDA to the BT router?

Posted by: kmoore at May 1, 2005 07:16 AM

Hi Len,
I need to pair with a cellular without authentication (no passkey), and then to find the virtual com number of the dial up networking service installed when the mobile is paired.
Is it possible ?
Thanks

Posted by: JPH at May 11, 2005 10:56 PM

Funny you should ask that. I'm doing exactly that for a client at present. The discovery and pairing is easy enough (though it would be nice if the MS API gave you a bit more control of some aspects) but the virtual com port stuff is hard due to the fact that the MS bluetooth stack doesnt expose the virtual com port API and so although you can do it using the control panel applet you cant do it programatically. What you CAN do though is connect to the serial service using the bluetooth winsock support and read/write via the sockets interface.

Posted by: Len at May 11, 2005 11:01 PM

Hi, all 8)))

Could anybody explain what version of Win I need to develop a Bluetooth app using OBEX file transfer???
hanks for help 8))

Posted by: AzuManga at May 15, 2005 10:06 AM

You need XP with SP1 or later and you need hardware that is supported by the Windows XP Bluetooth stack.

Posted by: Len at May 15, 2005 10:23 AM

But on the msdn.com said that OBEX is supported only by Win CE.NEt 4.0 or later. Is it wrong?

Posted by: AzuManga at May 15, 2005 10:27 AM

Ah, I see what you mean. No, that's not wrong. If you want to use the MS implemntation of OBEX then you need to use CE. If you use XP SP1 you would need to supply your own OBEX parser etc.

Posted by: Len at May 15, 2005 10:38 AM

And are there any functions in windows XP SP1 which can transfer file using sockets? Or I must cut file into pieces during sending and use

send(SOCKET *aSocket,......)

Thanks for help 8)

Posted by: AzuManga at May 15, 2005 10:47 AM

If you have control over both ends of the bluetooth connection then you can send the file any way that you want. For example you could create a sockets connection and use the TransmitFile() API to send it and custom code at the other end to recv it. If you need to deal with a standard device at the other end then obviously you'd need to conform to what it expects the protocol to be... Take a look at our Bluetooth server demo at http://www.lenholgate.com/archives/000263.html which demonstrates OBEX File transfer and can communicate with anything that understands the OBEX file transfer protocol - such as pda's etc.

Posted by: Len at May 15, 2005 11:24 AM

Can I program Btooth with winsock if i haven't MS Plaform SDK??

Posted by: AzuManga at May 15, 2005 02:26 PM

No. But the platform SDK is a free download so that doesn't usually pose a problem.

Posted by: Len at May 15, 2005 02:33 PM

Hi Len,
I've found a way to get the virtual com port of the DUN service installed for a cellular phone (I get it from the registry). But the problem is that the mobile must not only be authenticated but the services (DUN, serial port...) must be also installed, something the BluetoothAuthenticateDevice() function does not do.
So I don't know if there is a way to enable those services in order to use them... Have you find anything about that ?

Another question, does serial port service over socket works easily or it had to be implemented at a low level like the OBEX packets ?

Many Thanks for your help

Posted by: JPH at May 16, 2005 06:52 PM

No idea re the enabling of services.

The serial port over socket just works, you just get a byte stream and the stuff you push into the socket appears to come out of the serial port that the service is bound to.

Posted by: Len at May 16, 2005 08:25 PM

I need to send AT commands over the Dial Up Networking service and get the reply. I really don't see how to do the serial connection over sockets.
Have to initialize service to DialupNetworkingServiceClass_UUID, and then send directly the commands ? Can you show me an example ?
Thanks

Posted by: JPH at May 17, 2005 02:35 PM

I don't have time to produce example code for free for you right now. Drop me an email if you'd like us to quote you for the work.

Posted by: Len at May 17, 2005 04:07 PM

Hi Len,
After some work, I finally succeded in connecting to the DUN service using sockets. But it seems that authentication is necessary...
Thanks anyway

Posted by: JPH at May 17, 2005 04:55 PM

You can authenticate programatically

Posted by: Len at May 17, 2005 05:34 PM

Hi,

I could execute the server code. I have problem with the client code. I am not able to use the connect function properly in the client, especially while specifying the address of the server bluetooth . Can anyone help me in this task as to how to get and specify the bluetooth address?

Posted by: shyam at May 20, 2005 05:11 AM

Hi everybody,

I'm doing a placement. The aim is to do bluejacking that is to say I have to send messages from my laptoop to mobile phones. So I've wrote a code to be able this communication.
In first I have discover different Bluetooth devices thanks to functions BluetoothFindFirstRadio, BluetoothFindFirstDevice and BluetoothFindNextDevice.

My code uses Windows socket.
Actually, I think mobile phones have already a program using socket to communicate via Bluetooth. So I think I just have to use connect() and send() functions.
I send you the code I've wrote. Thanks for your answer.

case IDM_SEND:
iResult = WSAStartup(wVersionRequested, &wsaData);

//SOCKADDR_BTH address;
ZeroMemory(&address,sizeof(address));

address.addressFamily = AF_BTH;
address.btAddr = deviceInfo.Address.ullLong;//Address find using BluetoothFindFirstDevice or BluetoothFindNextDevice
//address.serviceClassId = GUID_NULL;
address.port = BT_PORT_ANY;

s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

if(s == INVALID_SOCKET)
{
WSACleanup();
printf("%s\n", GetLastErrorMessage(GetLastError()));
break;
}

if (0 != connect(s, (SOCKADDR*)&address, sizeof(SOCKADDR_BTH)))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
closesocket(s);
break;
}

//unsigned char sbuffer[50] = "You've been jacked";

send(s,(char*)sbuffer, strlen((char*)sbuffer), 0);

closesocket(s);

WSACleanup();

break;

Posted by: Thomas at May 26, 2005 10:29 AM

Thomas: I do bluetooth connections as well, but I use SOCKADDR_BTH structure in this way:

SOCKADDR_BTH bthSockAddr;

bthSockAddr.addressFamily=AF_BTH;
bthSockAddr.btAddr=bthAddr;//target address
bthSockAddr.port=0;
bthSockAddr.serviceClassId=SerialPortServiceClass_UUID;//the service you want to use

and everithing works rigth.

What is the problem with your code??

Apart from this, I have the folllowing problem;

When using BluetoothAuthenticateDevice function I get error 1008, which means:An attempt was made to reference a token that does not exist.
This is the code I am using:

BLUETOOTH_DEVICE_INFO pbtdi;
memset(&pbtdi, 0, sizeof(pbtdi));
pbtdi.dwSize=sizeof(BLUETOOTH_DEVICE_INFO);
pbtdi.Address.ullLong=bthAddr;

if(ERROR_SUCCESS != ::BluetoothGetDeviceInfo(m_hLocalRadio,&pbtdi))
{
CString strError;
strError.Format("GetDeviceInfo failed:%d %s\n",GetLastError(),GetLastErrorMessage(GetLastError()));

AfxMessageBox(strError);
}

if(pbtdi.fConnected==FALSE||pbtdi.fAuthenticated==FALSE||pbtdi.fRemembered==FALSE )
{
HWND hwndParent=NULL;//could change
PWCHAR pszPasskey=pin;//the pin number
ULONG ulPasskeyLength=sizeof(BLUETOOTH_MAX_PASSKEY_SIZE);

if(ERROR_SUCCESS != ::BluetoothAuthenticateDevice(hwndParent,m_hLocalRadio,&pbtdi,pszPasskey,ulPasskeyLength))
{
CString strError;
strError.Format("Authentication failed:%d %s\n",GetLastError(),GetLastErrorMessage(GetLastError()));
AfxMessageBox(strError);
}
}

Anyone any clue about what is going on??

Posted by: asier at May 31, 2005 12:17 PM

Passkey length should be the length of the pass key that you supply... ie strlen(pszPassKey). I've had no trouble authenticating devices, but I don't have the code to hand right now.

Posted by: Len at May 31, 2005 01:38 PM

Thanks for the answer. I'll try the way you say. Anyway, the above code worked properly in a bluetooth connection between two PCs (I managed to perform the authentication).
I am using CAsynSocket MFC(Microsoft Foundation Class). I create a raw bluetooth socket, with socket() API, and then I attach it to a CAsyncSocket class object.
The problem started trying to authenticate a "Cashira" bluecore. Apparently, that bluecore should respond to the authentication query, but inestead of that, I get error 1008.The problem could be in the bluecore, but using MIcrosoft's bluetooth staff(send, receive, add new device etc.)I can authenticate the device.
Well, if I manage to solve the problem I'll report with the results I obtain

Posted by: asier at June 1, 2005 02:58 PM

Problem solved.
The thing is that I needed to do a pairing with the remote device before every connection.At first time everithing was ok (first time=the device wasn't neither authenticated nor remembered).But,after disconnecting, when I tryed to do another connection, the error appeared(error 1008).It seems that if the device you wanto to pair to, is among the devices already discovered by your computer (go to the bluetooth icon of control panel,double click, and there you got the devices that your computer "knows"), that error occurs.I have no idea why is that.
So, when I close the connection, now I call to BluetoothRemoveDevice, that removes the device from the devices "known" by the computer, and next time I perform a connection, I am able to do the pairing without any problem.

Posted by: asier at June 1, 2005 04:41 PM

Thanks for your answers

Posted by: Thomas at June 2, 2005 09:20 AM

Hello,
I have always the same problem : the connection doesn't work.
For more details, I'm going to explain you my programm.
It's a Windows API developped under VS.NET.
My software offers 5 functions.
- Find First Radio (case IDM_START)
- Find First Device (case IDM_FIRSTDEVICE)
- Find Next Device (case IDM_NEXTDEVICE)
- Send a message, this is the server (case IDM_RECEIVE)
- Receive a message (case IDM_SEND)


case IDM_START:
// Free the space for FRP and use that for Finding First Radio
ZeroMemory (&btFRP, sizeof(btFRP));
btFRP.dwSize = sizeof(BLUETOOTH_FIND_RADIO_PARAMS);
// &hRadio is the handle for BT device, Returned value is dunno.
hbtRadioFind = BluetoothFindFirstRadio ( &btFRP, &hRadio );

GetLastErrorMessage(GetLastError());
//If hbtRadioFind is NULL, ERROR
if (hbtRadioFind == NULL) {
GetLastErrorMessage(GetLastError());
InvalidateRect(hWnd, &rt, true); //Reinitialize Window
break;
}

// Succeed in getting bluetooth handle.
// Check if the Bluetooth handle is connectable.
if(BluetoothIsConnectable(hRadio)){
GetLastErrorMessage(GetLastError());
}else{
GetLastErrorMessage(GetLastError());
PostQuitMessage(0);
}

// Enable the Incoming Connections.
if(!BluetoothEnableIncomingConnections(hRadio, TRUE)){
GetLastErrorMessage(GetLastError());
PostQuitMessage(0);
}

// Get the Radio Information.
ZeroMemory (&btRadioInfo, sizeof(btRadioInfo));
btRadioInfo.dwSize = sizeof(BLUETOOTH_RADIO_INFO);
err = BluetoothGetRadioInfo (hRadio, &btRadioInfo);
if (err != ERROR_SUCCESS) {
GetLastErrorMessage(GetLastError());
InvalidateRect(hWnd, &rt, true);
break;
}
//Function to post information about the Radio (MAC address, Name...)
PostRadioInfo(btRadioInfo,rt,hWnd);

ZeroMemory (&hNF, sizeof(hNF));
hNF.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
hNF.dbch_devicetype = DBT_DEVTYP_HANDLE; // Set the device type to be the devive handle type.
hNF.dbch_handle = hRadio; // Set the dbch_handle member to the device handle obtained from the CreateFile function.
//hNF.dbch_eventguid = GUID_BLUETOOTH_RADIO_IN_RANGE;

// Register the Device Notification, so there is a message to pass back if event happens.
hNotify = RegisterDeviceNotification (hWnd, &hNF, DEVICE_NOTIFY_WINDOW_HANDLE);
if (!hNotify) {
GetLastErrorMessage(GetLastError());
break;
}

UnregisterDeviceNotification(hNotify);
break;


case IDM_FIRSTDEVICE:
ZeroMemory(&deviceSearchParams, sizeof(deviceSearchParams));
deviceSearchParams.dwSize=sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);

deviceSearchParams.hRadio=NULL;//hRadio;
deviceSearchParams.fReturnAuthenticated = true;
//deviceSearchParams.fReturnRemembered = true;
deviceSearchParams.fReturnUnknown = true;
deviceSearchParams.fReturnConnected = true;
deviceSearchParams.fIssueInquiry = true;
deviceSearchParams.cTimeoutMultiplier = 5;

ZeroMemory(&deviceInfo,sizeof(deviceInfo));
deviceInfo.dwSize=sizeof(BLUETOOTH_DEVICE_INFO);

hDeviceFind=BluetoothFindFirstDevice(&deviceSearchParams,&deviceInfo);

if(hDeviceFind==NULL){
GetLastErrorMessage(GetLastError());
InvalidateRect(hWnd,&rt,true);
break;
}

err2=BluetoothGetDeviceInfo(hRadio,&deviceInfo);
if(err2!=ERROR_SUCCESS){
GetLastErrorMessage(GetLastError());
InvalidateRect(hWnd,&rt,true);
break;
}

PostDeviceInfo(deviceInfo,rt,hWnd);
ZeroMemory (&hNF, sizeof(hNF));
hNF.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
hNF.dbch_devicetype = DBT_DEVTYP_HANDLE; // Set the device type to be the devive handle type.
hNF.dbch_handle = hRadio; // Set the dbch_handle member to the device handle obtained from the CreateFile function.

hNotify = RegisterDeviceNotification (hWnd, &hNF, DEVICE_NOTIFY_WINDOW_HANDLE);
if (!hNotify) {
GetLastErrorMessage(GetLastError());
break;
}

//Procedure to select the bluetooth device.
ZeroMemory (&btSDP, sizeof(BLUETOOTH_SELECT_DEVICE_PARAMS));
btSDP.dwSize = sizeof(BLUETOOTH_SELECT_DEVICE_PARAMS);
btSDP.cNumOfClasses = 1; // 0 to search all devices.
btSDP.hwndParent = hWnd;
/*if(BluetoothSelectDevices(&btSDP)){
// if success.
strcpy(errmsg, "Bluetooth Selected Successful");
BluetoothDisplayDeviceProperties(hWnd,&deviceInfo);
BluetoothSelectDevicesFree(&btSDP);
}else{
GetLastErrorMessage(GetLastError());
}*/


//BluetoothFindDeviceClose(hDeviceFind);
UnregisterDeviceNotification(hNotify);

break;

case IDM_NEXTDEVICE:
i++;
//ZeroMemory(&deviceInfo,sizeof(deviceInfo));
//deviceInfo.dwSize=sizeof(BLUETOOTH_DEVICE_INFO);

nextDevice=BluetoothFindNextDevice(hDeviceFind,&deviceInfo);

if(nextDevice==false){
GetLastErrorMessage(GetLastError());
InvalidateRect(hWnd,&rt,true);
break;
}

err2=BluetoothGetDeviceInfo(hRadio,&deviceInfo);

if(err2!=ERROR_SUCCESS){
GetLastErrorMessage(GetLastError());
InvalidateRect(hWnd,&rt,true);
break;
}

PostDeviceInfo(deviceInfo,rt,hWnd);

ZeroMemory (&hNF, sizeof(hNF));
hNF.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
hNF.dbch_devicetype = DBT_DEVTYP_HANDLE; // Set the device type to be the devive handle type.
hNF.dbch_handle = hRadio; // Set the dbch_handle member to the device handle obtained from the CreateFile function.
//hNF.dbch_eventguid = GUID_BLUETOOTH_RADIO_IN_RANGE;

hNotify = RegisterDeviceNotification (hWnd, &hNF, DEVICE_NOTIFY_WINDOW_HANDLE);
if (!hNotify) {
GetLastErrorMessage(GetLastError());
break;
}

//Procedure to select the bluetooth device.
ZeroMemory (&btSDP, sizeof(BLUETOOTH_SELECT_DEVICE_PARAMS));
btSDP.dwSize = sizeof(BLUETOOTH_SELECT_DEVICE_PARAMS);
btSDP.cNumOfClasses = 0; // 0 to search all devices.

/*if(BluetoothSelectDevices(&btSDP)){
// if success.
strcpy(errmsg, "Bluetooth Selected Successful");
//wprintf(L"Bluetooth Selected Successful");
BluetoothDisplayDeviceProperties(hWnd,&deviceInfo);
BluetoothSelectDevicesFree(&btSDP);
}else{
GetLastErrorMessage(GetLastError());
}*/


//BluetoothFindDeviceClose(hDeviceFind);
UnregisterDeviceNotification(hNotify);

break;

case IDM_RECEIVE:

//Initialize Winsock
iResult = WSAStartup(wVersionRequested, &wsaData);

if (iResult!=0)
{
// if failed, do something
break;
}

//Create a socket
//SOCKET ConnectSocket;
ConnectSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

if (ConnectSocket == INVALID_SOCKET)
{
WSACleanup();
//GetLastErrorMessage(GetLastError());
OutputString ("Error in creating socket.", 'a');
InvalidateRect(hWnd, &rt, true);
break;
}

//WSAPROTOCOL_INFO protocolInfo;

protocolInfoSize = sizeof(protocolInfo);

if (0 != getsockopt(ConnectSocket, SOL_SOCKET, SO_PROTOCOL_INFO, (char*)&protocolInfo, &protocolInfoSize))
{
WSACleanup();
//printf("%s\n", GetLastErrorMessage(GetLastError()));
break;
}
//SOCKADDR_BTH address;

address.addressFamily = AF_BTH;
address.btAddr = deviceInfo.Address.ullLong;
address.serviceClassId = GUID_NULL;
address.port = BT_PORT_ANY;

pAddr = (sockaddr*)&address;

if (0 != bind(ConnectSocket, pAddr, sizeof(SOCKADDR_BTH)))
{
WSACleanup();
//Add Error Message
printf("%s\n", GetLastErrorMessage(GetLastError()));
break;
}

size = sizeof(SOCKADDR_BTH);

if (0 != getsockname(ConnectSocket, pAddr, &size))
{
WSACleanup();
//Add Error Message
printf("%s\n", GetLastErrorMessage(GetLastError()));
break;
}

if (0 != listen(ConnectSocket, 10))
{
WSACleanup();
//Add Error Message
printf("%s\n", GetLastErrorMessage(GetLastError()));
break;
}

//WSAQUERYSET service;
ZeroMemory(&service, sizeof(service));

service.dwSize = sizeof(service);

service.lpszServiceInstanceName = "My Service";
service.lpszComment = "My comment";

serviceID = OBEXFileTransferServiceClass_UUID;

service.lpServiceClassId = &serviceID;

service.dwNumberOfCsAddrs = 1;
service.dwNameSpace = NS_BTH;

//CSADDR_INFO csAddr;

ZeroMemory(&csAddr, sizeof(csAddr));

csAddr.LocalAddr.iSockaddrLength = sizeof(SOCKADDR_BTH);
csAddr.LocalAddr.lpSockaddr = pAddr;//Specifie the address to join

csAddr.iSocketType = SOCK_STREAM;
csAddr.iProtocol = BTHPROTO_RFCOMM;

service.lpcsaBuffer = &csAddr;

if (0 != WSASetService(&service, RNRSERVICE_REGISTER, 0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

s = accept(ConnectSocket, 0, 0);//Just accept communication from the client definied by pAddr

//unsigned char buffer[50] = "You've been jacked";

recv(s,(char*)rbuffer, sizeof(rbuffer), 0);

//send(ConnectSocket,(char*)sbuffer, strlen((char*)sbuffer), 0);
//WSAsendto(ConnectSocket,(char*)buffer, strlen((char*)buffer), 0,pAddr,sizeof(pAddr));//We specifie the client's address

sprintf (szOut, "Message received : %S\n",rbuffer);
OutputString (szOut, 'a');
InvalidateRect(hWnd, &rt, true);

WSACleanup();

closesocket(s);
closesocket(ConnectSocket);

break;

case IDM_SEND:

iResult = WSAStartup(wVersionRequested, &wsaData);

//SOCKADDR_BTH address;
ZeroMemory(&address,sizeof(address));

address.addressFamily = AF_BTH;
address.btAddr = 0x000272B004A3;//deviceInfo.Address.ullLong;
address.serviceClassId = SerialPortServiceClass_UUID;//OBEXObjectPushServiceClass;////GUID_NULL;
address.port = 0;//BT_PORT_ANY;

s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

if(s == INVALID_SOCKET)
{
WSACleanup();
printf("%s\n", GetLastErrorMessage(GetLastError()));
break;
}


/* if (0 != connect(s, 0,0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
closesocket(s);
break;
}*/

if (0 != connect(s, (SOCKADDR*)&address, sizeof(SOCKADDR_BTH)))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
closesocket(s);
break;
}


send(s,(char*)sbuffer, strlen((char*)sbuffer), 0);

closesocket(s);

WSACleanup();

break;


When I try to establish a connexion it doesn't work, the Error Message is : "The address isn't available in this context".

Thanks a lot by advance for your help. Send me a message on my email box, if you need my solution.

Posted by: Thomas at June 3, 2005 02:21 PM

Hi...

I have been trying to open the Bluetooth serial port and read from it. The code I have written works perfectly fine on the IBM desktop with iOGEAR dongle. But when I run the same code on the IBM Thinkpad R50p, it cannot open the port. However, the same configuration works fine in the Hyperterminal.(I can see the data!)

It even worked for USB->Serial port, neither works on the Thinkpad. Could someone please let me know if its the hardware :-(

After scrapping all, the part for opening the port:
#include
#include // file I/O
#include // file I/O
#include "windows.h"

using namespace std;

void main()
{
HANDLE portHandle_;

portHandle_ = CreateFile("Com40", // Specify port device
GENERIC_READ | GENERIC_WRITE, // Specify mode that open device.
0, // the devide isn't shared.
NULL, // the object gets a default security.
OPEN_EXISTING, // Specify which action to take on file.
0, // default.
NULL); // default.

if ( portHandle_ == INVALID_HANDLE_VALUE)
{
cout system("pause");
exit(0);
}

cout system("pause");

}

Thanks in advance...

Posted by: TrinitY at June 4, 2005 08:09 AM

To those of you that feel the need to post large amounts of code that 'doesn't work' in the hope that someone will fix it for you. Please dont. I certainly don't have time to look at your code and work out what you're doing wrong and, from the lack of corresponding 'here's the fix' comments, it seems that nobody else has the time either.

Do please continue to post questions and problems but I don't think that posting huge chunks of broken code really works.

Posted by: Len at June 4, 2005 10:39 AM

Thomas:
in "case IDM_SEND:"
Try casting the adress, i.e. address.btAddr = (BTH_ADDR)0x000272B004A3;

Besides, in "case IDM_FIRSTDEVICE:", if you don't query for devices and their services, the FindFirstDevice function, should not be able to return any DeviceInfo(neither sould be the FindNextDevice).

Asier

Posted by: asier at June 6, 2005 07:10 PM

Many thanks to you Len for the great examples. You might be the only place indexed by Google that has working bluetooth code involving obex. It's ironic that even though I work for Bluetooth SIG, I still need to go find samples like yours to see how stuff is supposed to work.

thanks

Posted by: austin at June 15, 2005 04:02 PM

A great forum on bluetooth programming for windows indeed. I have a problem for which you guys might give a solution, I am trying to send text/image files using OBEX File Transfer protocol to mobile devices.

Problem is we like to do this without Passkey. We tried using setting SO_BTH_AUTHENTICATE and SO_BTH_ENCRYPT options OFF in vain. Can anyone help?

I know we can send passkey through BluetoothAuthenticateDevice function, but then the mobile user would also have to enter the passkey.

Using Windows File Transfer / Send a File wizard, you can turn passkey authentication OFF, that means there is a way that this should work.

Posted by: Shahbaz at July 18, 2005 01:00 PM

If you bind the mobile phone to the computer, you only would need to enter the passkey only first time.
Anyway, using connect() (and the serial port profile), I managed to connect to my mobile phone (Nokia 6600) without using passkeys (just do the connection, no file or data trnasmision.)
I have managed to do data transmissions without passkeys between two computers, just using sockets (client socket in one computer, server socket in the other one, again with Serial Port profile).

Posted by: asier at July 26, 2005 06:01 PM

Hi Len,

I am trying to develop a client (Pocket PC 2003)/server (Windows XP SP2) application via the WinSock support for Bluetooth. I am stuck with the connect call, which always fails and the WSAGetLastError call reports WSAEINVAL. I went through this page and could not find a similar the same topic.

The Pocket PCs are the latest HP iPAQ and Dell Axim. They have built-in Bluetooth support. The USB Bluetooth adapter I am using on the XP is the D-Link DBT-120. Here is what I did.

On the server side (XP), the socket is created, bound, and started listening. Then the server advertises the service with my own class ID(NGW_TERM_SVC_ID) generated from the Windows utility GUIDGEN.exe. Finally, it starts to accept connection requests. Everything seems OK.

On the client side, the socket is created via the call:

SOCKET Socket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

The address is specified as:

SOCKADDR_BTH BthAddr = {0};
BthAddr.addressFamily = AF_BTH;
BthAddr.btAddr = Addr; // CE 51 5F 3D 0F 00 00 00
BthAddr.serviceClassId = NGW_TERM_SVC_ID;

Finally, the client tries to connect:

connect(Socket, &BthAddr , sizeof(BthAddr));

The call always fails with the error condition WSAEINVAL.

I want to know what I did wrong or what steps I missed? The MSDN document seems to be incomplete and inconsistent. I am stuck and really frustrated. Please give me some help! Thanks a lot!

Posted by: Xiaoan Lu at July 26, 2005 10:07 PM

Regarding "no passkey":
Windows XP SP2 BT Stack can not connect to a SPP slave service on a device which does not use authentication.
I can setup the device with "no passkey", but once I try to connect to the device by opening the COM port, the BT stack wants to exchange passkeys. But the device definitely does not support authentication. It has been disabled (SPP slave application from Casira Bluetooth development kit, with removed authentication).
It seems that I am not the only one having such a problem (e.g. http://www.experts-exchange.com/Programming/Wireless_Programming/Bluetooth/Q_21499516.html sounds similar).
Is this behavior a bug of the MS stack? With the WIDCOMM stack I can disable authentication and SPP connections will work without passkey exchange.
How about doing this programatically? Does the MS stack still insist on passkey exchange when using the Winsock API?

In fact I am looking for an easy solution to search for devices, connect using SPP, doing a file download by opening the associated COM port, closing the BT connection and searching for more devices again... Some kind of BT API for scripting would be nice.

Posted by: Guido at August 8, 2005 02:33 PM

Xiaoan Lu:

WSAINVAL means that you might have called Accept()on a socket that wasn´t listening.It can also mean that one of the parameters of the sockaddr structure has an invalid value (are you sure that NGW_TERM_SVC_ID profile is known on the client side?).Besides that, I got that error also trying to comunicate to a Casira BlueCore without using any passkey (I mean, not doing autentifications, or pairings at all).The Casira wanted to do the pairing with me (I was the master,the Casira the slave, and I was using a TDK dongle on a PC, with MSicrosoft's bluetooth stack).So I needed to do the pairing with the Casira, before trying to do the connection using connect().So I used BluetoothAuthenticateDevice, and everithing was solved.Maybe you have the same problem.

Guido:

I have done Bluetooth connections between PC's using MS's bluetooth stack, without changing any passskey. Just creating a socket, defining the sockaaddr structure and then using connect, everything worked fine.
Doing connectionds with the Casira can be a little bit triky.Actually I connect to the Casira but changing passwords.


I have the following problem:

The Casira BlueCore listens for incoming connections. First it wants to do the pairing, and if everithing goes fine, it accepts the connection.In the pairing process, it gets something called LinkKey, which identifies incoming device(the PC in this case).Once it has the link key, there is no need to call BluetoothAuthenticateDevice().But if the Casira connects with another device, it losts that link key, so next time I want to connect with the Casira, I need to do the pairing again, calling again to BluetoothAuthenticateDevice, and here comes the problem:

If you do BLuetoothAuthenticateDevice() again on a device that you authenticated before(I mean, that device appears on the Bluetooth Configuration pane the you can find on Control Panel) , the following error occurs:1008,an attempt was made to reference a token that does not exist.Is that a bug?Anyone found the same problem??

Posted by: asier at August 12, 2005 06:55 PM

I found the solution! Was simple, probably we all are deliberating because there is no ample information freely available about this.

All I had to do to perform File Transfers to mobile devices without Pass-Keys is to use OBEXObjectPushServiceClass_UUID service instead of OBEXFileTransferServiceClass_UUID. Thats all, no change in any other functions!

Hope this helps anyone who is looking for info like us.

Posted by: Shahbaz at August 19, 2005 08:06 AM

That's great news. Thanks for sharing!

Posted by: Len at August 19, 2005 08:38 AM

Hello Xiaoan Lu,

I've had the same problem wiht the connect function. Change the extended compiler settings Data aligment from quad word to Byte !! Then it will works!

Posted by: Wojtek at September 16, 2005 03:47 PM

I write the server to receive file via OBEX and i problem. when i find on gsm telephon computer with Bluetooth telephon find it at secont repeat, and i use fsquirt an chosse receive file telephon find at first. What take on paramiters who destroy this error

Posted by: krzys at October 4, 2005 12:37 PM

I'm sorry, I don't understand.

Posted by: Len at October 4, 2005 12:45 PM

We are looking for a way of pairing a CE.NET PDA Bluetooth connection with some Bluetooth peripheral.

This will eventually be use to record some information in agricultural application. The device are most likely to be in the shorterm a barcode reader with Bluetooth connection and some GPS/Bluetooth.

We want a way to simplify the pairing process to the end user instead of using the pairing process built in the PDA.

We want to programmatically initiate and control the Bluetooth pairing process on the PDA to the Bluetooth peripheral within a C program.


Ben

Posted by: Ben at October 13, 2005 01:35 PM

Hi Len,
Thanks for this. You deserve a medal!

Just wondered why your code sample doesn't call 'closesocket' anywhere? Also, it looks like the brace matching

if (0 == ::WSAStartup(wVersionRequested, &m_data))
{
...

is missing. Has something fallen off the end or am I missing something?

Thanks again,
Fran

Posted by: Fran at October 31, 2005 03:44 PM

Fran

I don't think it's a complete sample (I can't remember), I think it was just to get to the point where SetService worked.

See this one: http://www.lenholgate.com/archives/000102.html for something a little more complete.

Posted by: Len at October 31, 2005 03:59 PM

Hi nice code, helped me a lot.
i'm trying to write an c++ application wich receives data from j2me client applikation on a 6600.

If i start the server app on die pc die client on the mobile is able to find the service, to connect and to send.

the server waits at the accept, he accepts the connection but buffer is empty.

i did tcp/ip socket connections between java and c++ before and it worket fine.
i am sending and receive data like i did it in my tcp/ip app. but with bt it doesn't work. accepts the connection but receives nothing. has anybody a idea where the problem could be?
here is my code:

send in j2me like this:
con =(StreamConnection)Connector.open(serverConnectionString); //got the server connection string from service discovery
OutputStream os = null;
os = con.openOutputStream();
String str = new String("Test");
os.write(str.getBytes());
System.out.println("sent");

works fine with a small j2me server applikation

but in c++ on my pc it receives no data:

printf("before ");
SOCKET s1 = accept(s, NULL, NULL);
printf("accepted");
if(s1 == INVALID_SOCKET){
printf("error");
}
char message[256] ="";
int r = recv(s1, message, sizeof(message), 0);
printf("Text: %s", message);

-so fine, just get "before accepted Text: before accepted Text: before accepted Text: befor accepted

but no messages! has anybody an idiea where the problem could be? has it something to do, with the way i receive or send? or could der be something wrong with my socket connection?

thx
IlB

Posted by: Andreas at November 25, 2005 01:26 AM

What does recv return? If the message contains any null bytes then the printf will stop at the first...

Posted by: Len at November 25, 2005 09:09 AM

thanks for your answer.

it returns nothing, it isnt changed by the recv method. i always receive 0 bytes.

is it possible to get a connection although something is wrong with the socket or service settings, and so its not possible to receive data?
The socket is valid, becaus if i enter an invalid socket i recieve -1.

anybody any idea where i could search for the problem?

Posted by: Andreas at November 26, 2005 09:49 AM

Kenneth Johnson (www.beadwithmebylori.com), of the Public Health Agency of Canada, Ottawa (www.online-paid-surveys.com), Ontario ((Guorge)), examined the association between breast cancer risk and passive and active smoking in an analysis of 19 published studies

Posted by: Guorge at December 10, 2005 04:35 AM

hello.
I haD done all of this things even posted some article also on different forum that how to communicate with your bluetooth Device and your Window Xp.now i am getting one Problem. Everything works Proper but in case when data is too long like 100 kb or more then 100 kb after receving 50 kb or 20 kb not a fixed amount of data i am getting error that some software installed in your host machine has abort the connection.can anyone face this type of Problem. if yes let me know how to resolve this

Thankyou.

Posted by: Rupesh Shukla at March 28, 2006 09:25 AM

Hi!
I have a windows XP with service Pack2. It shows the microsoft bt control panel application. Bt hardware is recognized properly. It can even serarch and find nearby bt devices.
So the MS bt stack seems to be properly installed.
Nevertheless opening a socket with AF_BTH causes error 10047 (WSAEAFNOSUPPORT).
Did anybody see something similar?
Any idea?
Any hint will be highly appreciated.
Thanks, Manuel

Posted by: Manuel Abrecht at May 31, 2006 01:08 PM

Your bluetooth hardware is turned ON when you run the code?

Posted by: Len at June 2, 2006 01:02 PM

i wanted to know how does one implement OBEX protocol for file transfer, when one is using the sockets interface for bluetooth programming?

and also, how does one transfer messages to and from the mobile phone? Are AT commands to be used for the same?

Thanking in anticipation.

Posted by: Denil Shah at July 27, 2006 04:29 PM

Visit www.officefield.com

Posted by: Kamal Faridi at January 25, 2007 10:48 AM

Hello Everyone

I need some help........I am very new to all this...I am working on Bluetooth device discovery provided by Len.I have a XP SP2 system and a Broadcomm supported dongle.The code was compiled but when I tried to run it I got an error like:Failed to get the Bluetooth Socket!An adress incompatible with the protocol was used.

Can someone help me how to resolve this?Its really very urgent.

Thanks
Ramya.

Posted by: at January 25, 2007 07:21 PM

Hi,
Thanks for the code it really helped me to get started with the bluetooth project.
I have a problem though: the program get stuck on accept(s1,0,0) and I´m forced to stop it. Any ideas?

Posted by: Marius at April 3, 2007 08:29 AM

Accept will not return until you connect a device to the file tranfer service running on your machine.

Posted by: Len at April 3, 2007 10:17 PM

Hi, how can I replace Windows xp's OBEX Object Push Service with my own? Question is: Can I disable defaul Win XP service?
Thanks!!!

Posted by: Stanko Culaja at April 5, 2007 09:05 PM

You could try looking at the services list and stopping likely candidates... The Bluetooth Support Service perhaps?

Posted by: Len at April 6, 2007 10:42 AM

ok, I will try. Thanks ;)

Posted by: Stanko Culaja at April 6, 2007 05:14 PM

And one more question...
I am creating one bth service server.
Wenn I put value -50 to be the port value to my server, the server is successful started. This is ok, or what???

p.s. I have stoped Bth Win Service with
"net stop "Bluetooth Support Service"" and then I wanted to connect to my phone, with no success :(
My app can only find local bth radio and can't find any remote bth devices.

Posted by: Stanko Culaja at April 6, 2007 05:28 PM

I guess it's all or nothing then, it's unlikely that you can replace just the object push service... Can't you just create you own and give it your own name and advertise it as well as the standard one? It's been a while since I played with this stuff but I thought I managed to do that on my VAIO...
Why do you think that -50 is a good value?

Posted by: Len at April 6, 2007 05:37 PM

I want to build the application that can recive files from phone. Because of that, I want to replace the standard OBEX Object Push or OBEX File Transfer Service. Is there any way to do this.
value -50 is only test value, and server was successful started with this value. This is surprising.

Thanks

Posted by: Stanko Culaja at April 6, 2007 05:50 PM

A listening bluetooth socket should be bound to the bluetooth wildcard address; the port should be set to BT_PORT_ANY.

From what I remember you can advertise multiple instances of the same service from one machine; can you see your service from your phone? You may not NEED to disable the standard object push service. Do you have another bluetooth device other than your phone that you can use to test the service? Whilst your phone may not display multiple services of the same type a PDA probably will (my iPaq does) and this would at least let you test to see if you are actually correctly advertising the service from your machine....

Have you tried the Bluetooth server demo http://www.lenholgate.com/archives/000263.html ? This advertises many services and, as far as I remember, always worked fine alongside the existing XP services... If this runs and your phone cant see its services but can see the standard XP services then I expect you will need to somehow disable the XP services....

Posted by: Len at April 6, 2007 06:02 PM

This bth server demo is working, when I try to send file from phone(n-gage - Symbian 6). But when I turn off this server, I can't send file from phone. I think that WinXP default server is turned off. Now I can't start that server :) I tried to restart PC and to net stop net start service but is useless.
Can you put sorce code of this bth server demo. I want to see witch service name, comment, GUID you had puted in this app.
Thanks!

Posted by: Stanko Culaja at April 6, 2007 07:02 PM

Sorry, I can license you the code if you'd like, email me for prices, but the code isn't free.

The demo server exposes the following bluetooth services:

servers.AddServer(factory.NewServer(
OBEXFileTransferServiceClass_UUID,
_T("JetByte File Transfer"),
_T("OBEX File Transfer")));

servers.AddServer(factory.NewServer(
SerialPortServiceClass_UUID,
_T("JetByte Serial Port 1"),
_T("Serial Port 1")));

servers.AddServer(factory.NewServer(
SerialPortServiceClass_UUID,
_T("JetByte Serial Port 2"),
_T("Serial Port 2")));

servers.AddServer(factory.NewServer(
DialupNetworkingServiceClass_UUID,
_T("JetByte Dial Up Networking"),
_T("Dial Up Networking")));

servers.AddServer(factory.NewServer(
LANAccessUsingPPPServiceClass_UUID,
_T("JetByte LAN Access"),
_T("LAN Access using PPP")));

servers.AddServer(factory.NewServer(
OBEXObjectPushServiceClass_UUID,
_T("JetByte OBEX Object Push"),
_T("OBEX Object Push")));

Posted by: Len at April 6, 2007 07:10 PM

Thanks for the UUIDs :D
I'm making my own wraper around WinXpBthApi.
Now I only need to study OBEX protocol.
again, thank you ;)

Posted by: Stanko Culaja at April 6, 2007 11:30 PM

I have successful started OBEX Object Push Service. When I try to accept connection, the trhead is blocked. OK, that is normal, but when I want to connect from my mobile phone, the thread is still blocked :(
From my phone I get "Sending File Error" Error. When I stop my server, and then try to send file from phone, I get: "Unable to connect" error. That means that my phone can see the server, but I can't accept a connection, no error, no succes, app is still waiting at accept func.
Do you know about this?
Thanks!

Posted by: Stanko Culaja at April 7, 2007 03:32 PM

And why are you using the getsockopt function?
I can' see reason to call this func().

Posted by: Stanko Culaja at April 7, 2007 03:37 PM

Without seeing your code (and no, I dont have time to look at your code for free!) it's hard to say what you're doing wrong. Have you used the various bits of code available on this site to test with? You should be able to use one of the samples that I know to work and have it get at least to the point where the accept completes...

Posted by: Len at April 7, 2007 03:38 PM

getsockopt() was probably called just to take a look at the protocol info structure in the debugger.

Posted by: Len at April 7, 2007 03:40 PM

Thanks for the answers!
I'll try to find some other samples on this site.

Posted by: Stanko Culaja at April 7, 2007 03:44 PM

I have found the bug. BT_PORT_ANY was the bug. When I put a number, then all is OK. BT_PORT_ANY has value -1.
I think that phone can find the service( because, he don't know in that stage the number of port), but he can't connect to server because the port number is -1.
Now( when the port number is positive(1-30)), all is working ideally.
Thanks!

Posted by: Stanko Culaja at April 7, 2007 04:06 PM

I don't think that's really the fix that you want... You specify BT_PORT_ANY because you dont know what ports might be available and you don't care which one the sockets layer binds to. You then bind the wildcard address and it gives you a port that is guarenteed to be available... You then copy that address into the CSADDR_INFO that you provide when you register your service and, well, everything works. The fix you have at the moment wont allow you to run multiple copies of the service and will also fail if something else happens to be using that port.

Posted by: Len at April 7, 2007 04:29 PM

Hmm,
There is no alternative, because BT_PORT_ANY is not working. Maybe, i can try another version of Winsock. I am now using 2,0 version(WSAStartup(MAKEWORD(2,0)...).

Posted by: Stanko Culaja at April 7, 2007 04:35 PM

Well, since it "works for me" (tm) I guess there's probably a bug in your code. How are you registering the service? I assume you've read this: http://msdn2.microsoft.com/en-us/library/aa362920.aspx and I assume that you're using the address that your listening socket is ACTUALLY bound to (and not the address that you pass in to the bind call) that is, you bind to wildcard, listen and then use the result of a call to getsockname() on your listening socket as the address used when you register your service?

Posted by: Len at April 7, 2007 04:46 PM

That was the main problem :)
I have skiped the getsockname() function :(
Now, all is ok.
Thank you for answering all my questions.
I hope that this discussion will be usefuly for other visitors.

Posted by: Stanko Culaja at April 7, 2007 06:36 PM

Glad you fixed your problem and good luck with your project.

Posted by: Len at April 7, 2007 06:53 PM

Hi, I'm back with one question ;)
What is the optimal size of one obex packet( with body data).
I'm using 1kb size. This is OK, or will I use smaller packet?
Thanks...

Posted by: Stanko Culaja at April 23, 2007 05:47 PM

I've no idea.

Posted by: Len at April 25, 2007 03:37 PM

Helo, I developing some application for connecting pda and bluetooth printer. Application is quite simple, it need just to connect with printer(for now) using pairing. I have name, pass key and (MAC) address of BT printer.
OS is windows CE 5.0.
This is code:
CString error;

WORD wVersionRequested = 0x202;
WSADATA m_data;


if (0 == WSAStartup(wVersionRequested, &m_data))
{
SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

if (s == INVALID_SOCKET) {
error.Format(_T("Socket creation failed, error %d"), WSAGetLastError ());
AfxMessageBox (error);
return;
}

SOCKADDR_BTH sab;
memset (&sab, 0, sizeof(sab));

if (0 != bind (s, (SOCKADDR *) &sab, sizeof(sab))) {
error.Format(_T("Socket bind, error %d"), WSAGetLastError ());
AfxMessageBox (error);
closesocket (s);
return;
}

listen (s, 5);
for ( ; ; ) {

SOCKADDR_BTH sab2;
sab2.addressFamily = AF_BTH;
sab2.btAddr = b; //b is a BT_ADDR variable
sab2.serviceClassId = GUID_NULL;
sab2.port = 4;

int ilen = sizeof(sab2);
sockaddr *pAddr = (sockaddr*)&sab2;
SOCKET s2 = accept (s, pAddr, &ilen);
if (s2 == INVALID_SOCKET) {
error.Format(_T("Socket bind, error %d"), WSAGetLastError ());
AfxMessageBox (error);
break;
}
error.Format(_T("Connection came from %04x%08x to channel %d"),GET_NAP(sab2.btAddr), GET_SAP(sab2.btAddr), sab2.port);
AfxMessageBox (error);
}

closesocket (s);
}

But I get a 10047 (Protocol not supported by address family error) when I use the socket command.
How can I do pairing?

Thanks...

Posted by: Sloba at July 4, 2007 09:41 AM

I don't think CE supports bluetooth over winsock, I think there is a special API for bluetooth. Never done anything with bluetooth on CE. Sorry I can't be more help.

Posted by: Len at July 4, 2007 04:39 PM

@Len
Thanx for replay.
I manage to find SDK for my bluetooth (it's Atinav), and than I use his special API for bluetooth.

thanx for help.

Posted by: Sloba at July 10, 2007 07:31 AM

Hey Len and the whole community,
thanks for your great informations about developing with Microsoft's bluetooth stack (with winsock).
I'm new to bluetooth and sockets but your tutorial and comments gave me a nice entry.

I am developing an application (Windows XP SP2, Visual Studio 2005) which shall recognize any wireless(bluetooth) input devices (of the same type) which offer a specific HID-Service and establish a connection with it.

With BlueSoleil I can connect, so I am able to access this HID-Device in the system, but on my own I am not able to bind this service in the system.

With your tutorial I am able to discover all bluetooth devices and I can list the services.
Unfortunately I don't know how to install that HID nor how to read/write to/from it.

Du you have any idea how to solve that problem? Is there any tutorial or code-example?

Thanks a lot!

Hope my english is not that bad, greetings from germany!

Christian

Posted by: Christian at July 23, 2007 09:31 PM

Christian,

I'm sorry, I've no idea.

And your English is just fine :)

Posted by: Len at July 24, 2007 01:24 PM

I have setup a virtual com port on xp service pack two then I enumerate the serial ports to detect what it was. I thought I was done, No! When I try to open the serial port it comes up with a dialog that says enter the passkey! Doh, that defeats the whole purpose of what I'm trying to do ( pair programatically ).

Not only that, but I can't pair with it because my device doesn't use a passkey!!! Wow they sure made this stuff way harder than it needs to be.

This is quite urgent for me and I have spent almost two weeks getting it going in c#. Please email me if anyone knows how to get around this last problem!!!!.

Posted by: R.J at November 1, 2007 10:28 PM

Hey Len and the whole community,
I have the same problem like Stanko Culaja mentioned before.I advertise the OBEXObjectPush service in the same way like you did(include using the getsockname function),no errors,but no phone could find and connect my PC.
I am really puzzled,is there anything else i have to do or my socket version isn't right?(wVersionRequested = 0x202)
Any suggestion will be appreciated and thanks in advance!


Posted by: ukyocxl at March 10, 2008 09:06 AM

Have you tried running the example server that's available here http://www.lenholgate.com/archives/000263.html? If so, does this work?

Posted by: Len at March 16, 2008 05:22 PM

i am trying to ave the bluetooth address in registry but i dont know how to do that, firstly is there anyway to typecast the address into string or anyother format when i use int the value of the address changes. Help me out on this please.

Maria

Posted by: at July 6, 2008 09:09 PM

Hi len, it's been a long time without studying in bluetooth, cause i still have no idea about it. But it's still puzzling and attracting me!
I've tried Bluetooth server demo and it works fine, my iPaq can send file and Bluetooth server demo can receive and stream them into the JetByteTools.log. But my iPaq couldn't find OBEXObjectPush service,and just find the other five service including OBEXFileTransferService, so which service does work in file transfer OBEXObjectPush or OBEXFileTransferService?
And i've also tried you test project named blue. I found that you register OBEXFileTransferService.It will accept when my iPaq send a file. But strangely i just replace OBEXFileTransferServiceClass_UUID with OBEXObjectPushServiceClass_UUID, the socket will block at accept.
But i found another interesting phenomena, when i use Nokia N73 to send a file to your blue project, the socket will accept both OBEXFileTransferServiceClass_UUID and OBEXObjectPushServiceClass_UUID!
Sometimes i thought that's a bug!
Do you know why? I wish to see your reply.
And thanks for your time!

Posted by: ukyocxl at July 29, 2008 10:26 AM

I expect each device you have looks for different types of services. The iPaq probably never attempts to connect to the object push service; which is why the accept never completes.

Posted by: Len at July 29, 2008 10:34 AM

Hi Len, you're completely right!
I made a mistake. At the beginning i succeed in sending a file from PC to iPaq by object push service, so i thought iPaq also use that service when send a file. But iPaq use file transfer service. As you say that why the accept never completes!
After that, i test several devices, such as Nokia N73, Nokia 6270 and SonyEricsson phone. They all use object push service when sending a file! Does that mean most of mobile device using object push service when they send and receive files? Do you know anything about that?
Thank you for you help!

Posted by: ukyocxl at August 4, 2008 02:49 AM

I expect it will depend on the device as to what services it supports. So the best way to support more devices is to support more services... Object push and file transfer are similar, so why not support both?

Posted by: Len at August 4, 2008 08:16 AM

hmm...file transfer seems a little bit more complicated, it use more headers.
Anyway thank you very much and i'll have a try.

Posted by: ukyocxl at August 5, 2008 12:17 PM

Hi, Len, I'm glad to tell you my App can support two services now! Thanks to your help and your BluetoothServer demo.
But now I found another strange question. Before mobile devices sending file to my App, they will find devices around them first, then choose device and send file. Question comes, some devices(iPaq, N73) can find my PC directly, and some devices(Nokia 6270, SonyEricsson) can't find. First, i thought there are something wrong with my App, but I try your BluetoothServer demo, the same question occurs.
Unfortunately when i use Microsoft Bluetooth(with a bluetooth logo at right-bottom task bar, oh i guess you know it), and choose receive option, then those devices can find my PC right now! How strange!
Do you know anything about it?

Posted by: ukyocxl at August 15, 2008 09:17 AM

Is it because you have paired the devices that work and you havent done so for the devices that don't work?

Posted by: Len at September 1, 2008 09:17 AM
Post a comment









Remember personal info?




Enter this code in the box below to prove that you're not some kind of automated spam robot...