Bluetooth socket bind() returns WSAENETDOWN

Hello there,
      This is the first time I'm probramming for bluetooth.
I installed a USB bluetooth device and the software comes with it works great, detecting other devices and communicates.

I'm trying to run my application in server mode (using WSASetService).
But it fails at bind() with WSANETDOWN. Any idea how to troubleshoot this ??

 DWORD lastError = ::WSAGetLastError();
     printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));

 memset(&sbth, 0, sizeof(sbth));
 sbth.addressFamily = AF_BTH;
 sbth.btAddr = 0;
 sbth.port = BT_PORT_ANY;

 if (bind(s, (const sockaddr*)&sbth, sizeof(SOCKADDR_BTH)) == SOCKET_ERROR) {  // <<------ here is the problem
     lastError = ::WSAGetLastError(); // always WSANETDOWN
     printf("Failed to bind bluetooth socket! %s\n", GetLastErrorMessage(lastError));
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Does your USB installed as Microsoft Bluetooth Stack ?!
Or others, such as Widcomm stack?

What is the stack? : Bluetooth is written standard by BluetoothSIG. Different companies, orgnaization and individuals have their own API's of Bluetooth by implementing the lower-part of software of Bluetooth acoording to the written standard. To program a Bluetooth application, you have to use the Bluetooth Stack that dongle are installed to. Usually, USB-Dongles can be configured to work in any stack.
So, using Bluetooth lib of Microsoft means your device is installed to use Microsoft BT Stack

How to know?
Simpliest way is to use run this application (comes with XP SP2)
Choose next, send file, then click on browse,
If the search took less than a second or two, it's not installed on microsoft BT stack! try to update driver and let microsoft windows choose the driver.
if it took more than 10 seconds , it's MS BT Stack and the problem because of other problem!

mxjijoAuthor Commented:

   I must have updated the posting earlier.
I found the problem myself. It was caused by the software came with it.,
I don't have time to invesigate what is wrong with it, but once I uninstalled
the software and  let XP auto detect the h/w my program started working.
I tried reporting the problem to the manufacturer but they never responded.

thanks for spending time on it
Well, Why you are tring to REPORT the problem? There is no problem!
I mean, your are using a dongle comes with stack different than Microsoft and it's working!
But miscrosoft API's works ONLY for devices/dongles installed with Microsoft stack!
So, It's like you try to use Windows API's on Linux!
I hope you understand my point! and don't bother the manufacture :)

mxjijoAuthor Commented:


As you can see my code above, I am not using any non-standard API's.
FYI,  when a manufacturer install a network interface, no matter what their
h/w is, it is their resposibility to make it compatible with standard socket API's.
If what you're saying is correct, why should any network card OEM's release their own drivers ?? :)

Try to understand me please:)

Bluetooth is a standard, written in a PDF file (more than 1500 pages).
Bluetooth has layers: Hardware layer (dongles and so), Low-Level software layer, High-Level software layer(profiles)
The manufacture of the dongle implement the Hardware layer. Microsoft (for windows) and Widcomm(for windows) and FreeBT(for windows ) and dozens of other companies implemented the LowLevel layer of the Bluetooth and part of the HighLevel (some profiles).

When you insert a dongle into your XP, and choose Widcomm as the Low-Level layer(e.g. installation CD), you don't call Microsoft Bluetooth Layer! Since it cannot find any associated dongle!
Other side: Widcomm DOESN'T use sockets when dealing with dongles! So when you try to Assign a Socket, you got nothing!

The above code is not Standard Bluetooth API's, It's Microsoft Bluetooth API's that uses sockets!

For more information, try to look for the keywords: Bluetooth Stack .

Have fun..


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Wireless Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.