[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1860
  • Last Modified:

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



 SOCKET s = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
 DWORD lastError = ::WSAGetLastError();
 if (s == INVALID_SOCKET)
 {
     printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));
     exit(1);
 }


 SOCKADDR_BTH sbth;
 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));
     exit(1);
 }
0
mxjijo
Asked:
mxjijo
  • 3
  • 2
1 Solution
 
nehayaCommented:
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)
c:\WINDOWS\system32\fsquirt.exe
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!

Regards,
Nehaya
0
 
mxjijoAuthor Commented:

nehaya,
   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
~j
0
 
nehayaCommented:
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 :)

Regards,
Nehaya
0
 
mxjijoAuthor Commented:

wow!

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 ?? :)


0
 
nehayaCommented:
:)
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..

Regards,
Nehaya
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now