New Post: CSR Harmony stack
Commented Unassigned: BluetoothListener problem with unknown GUID [35112]
I'm hoping someone out there can help me.
I have a windows mobile 6 application that connects to a device via Bluetooth.
Everything is working fine. I can send commands to it and receive data.
That said I am using a service Guid for the BluetoothListener of:
BluetoothService.RFCommProtocol mainly because it works. The problem is the Bluetooth device I'm working with is a sealed unit with no programmable interface and thus I can't set the Guid on it.
I know this is a constant that Alan says will result is a random channel number, but it works.
I tried using a created Guid and the device received and sent nothing.
My problem is that the device comes with a key-fob which can be used to send a command to it.
I'm then expected on the mobile to receive that data it then sends.
The previous version of the application uses CFSerial.dll and thus used a Comm Port for its Bluetooth connection and this was able receive the data triggered by the key-fob. I suspect this has something to do with the Comm Port method being bound to a specific channel or service of some kind, but I'm guessing wildly.
On the application the user is given the choice whether to use the mobile or the keyfob to trigger the data. If they choose the mobile I'm fine, I have it working, but if they choose the keyfob I create a bluetoothlistener (using the Guid above) but it never gets any data.
Does anyone know if I can use Bluetooth SDP to get the channel number and then do something with that to listen for data?
Any help or pointers in the right direction would be very very helpful.
Comments: ** Comment from web user: alanjmcf **
On the first issue. Use the SDP lookup functions in the library to find what services are advertised by the two devices. Use SdpBrowser and do a "All Services (over L2CAP)" scan against each.
That will show the SDP records unless one is just using a fixed port... If that's the case then there are only tens of RFCOMM port numbers so one time do a loop until you find the one (or more) that connect and hard code that in your program.
On the second question. Is that being run on WM6 or desktop Windows? I would think that if the connect fails then the socket is not connected so there's no point in using it regardless of error code. What's the Socket Error Code? 10056? It could be that the error code is being re-purposed for some other Bluetooth error condition. The error numbers for the MSFT stack on desktop Windows are summarised at https://32feet.codeplex.com/wikipage?title=Errors but that one's not really defined well. http://msdn.microsoft.com/en-us/library/aa362901.aspx
New Comment on "BluetoothWin32Authentication"
New Comment on "BluetoothWin32Authentication"
New Comment on "BluetoothWin32Authentication"
Updated Wiki: BluetoothWin32Authentication
BluetoothWin32Authentication
The class is used to respond to requests for authentication for Bluetooth devices.It is supported only on the Microsoft stack on desktop Windows (MSFT+Win32 in my jargon). It should be possible to implement on BlueSoleil for instance, but I never managed to find the way to get their API to work -- it may need use of a message loop, similar to some stuff in Widcomm.
This class is generally used in a mode where a user supplied callback will be called when any device requires authentication. This is the mode that needs to be used for Bluetooth 2.1 Simple Secure Pairing (SSP). The callback will specify what type of pairing is required e.g. Legacy for tradional PIN pairing, or NumericComparison/JustWorks for v2.1 devices, and the user code in the callback method should response respectively, e.g by setting e.Pin or e.Confirm etc, see the full table of how to respond below. Also see the example code below.
(For traditional pairing (with a PIN code), it can also be used in a mode where an instance can be created specifying both the one device that is being connected to and the PIN string to use it will respond to that single device; it is used by BluetoothClient that way to support its Pin property.)
To confirm the pairing the callback method should do the following:
AuthenticationMethod etc | Action |
---|---|
Legacy | Then the pairing is using old-style PIN support, so the Pin property should be set |
NumericComparison | Then the Confirm propery needs to be set, but…… |
• If NumericComparisonandJustWorksNumericComparison | • Then the user should be asked to confirm the pairing with a simple Yes/No. |
• If NumericComparison, and notJustWorksNumericComparison | • Then the user should be shown the NumberOrPasskey value and asked to confirm that the values displayed on both devices match. |
OutOfBand | ConfirmOob should be called -- this is untested |
→ | It seems that Passkey is "please input the passkey as displayed on the other device", and PasskeyNotification is "here's the passkey to type on the remote device, confirm that" |
PasskeyNotification | Then the user need to be shown the NumberOrPasskey value which needs to be typed on the remote device, and the Confirm propery needs to be set |
Passkey | Presumably set ResponseNumberOrPasskey as well as Confirm -- this is untested |
There are other properties on the BluetoothWin32AuthentionEventArgs for instance CallbackWithResult and PreviousNativeErrorCode. The reference documentation for this class is at http://docs.32feet.net/html/T_InTheHand_Net_Bluetooth_BluetoothWin32Authentication.htm
If you simply want to allow the pairing to go ahead when to SSP devices are connecting then handling the callback and setting e.Confirm=True will be enough -- but that is a little insecure...
If you want to initiate this pairing process then call BluetoothSecurity.PairRequest passing a null password.
Examples
If one wants to respond to PIN requests for one device with a known PIN then use the simple form which is initialized with an address and PIN.BluetoothWin32Authentication authenticator = new BluetoothWin32Authentication(remoteEP.Address, m_pin); // when the peer is expected to require pairing, perhaps do some work. authenticator.Dispose();
Using pairer AsNew BluetoothWin32Authentication(AddressOf HandlerWithSsp ) ' or AddressOf Win32AuthCallbackHandler Console.WriteLine("Hit Return to stop authenticating") Console.ReadLine() EndUsing ... Sub Win32AuthCallbackHandler(ByVal sender AsObject, ByVal e As InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs) ' Note we assume here that 'Legacy' pairing is being used,' and thus we only set the Pin property!Dim address AsString = e.Device.DeviceAddress.ToString() Console.WriteLine("Received an authentication request from address " + address) '' compare the first 8 hex numbers, this is just a special case because in the' used scenario the model of the devices can be identified by the first 8 hex' numbers, the last 4 numbers being the device specific part.If address.Substring(0, 8).Equals("0099880D") OrElse _ address.Substring(0, 8).Equals("0099880E") Then' send authentication response e.Pin = "5276"ElseIf (address.Substring(0, 8).Equals("00997788")) Then' send authentication response e.Pin = "ásdfghjkl"EndIfEndSub
' untested!Sub HandlerWithSsp(ByVal sender AsObject, ByVal e As InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs) If e.AuthenticationMethod = BluetoothAuthenticationMethod.Legacy Then' Call the old method above Win32AuthCallbackHandler(sender, e) ElseIf e.JustWorksNumericComparison = TrueThenDim rslt As DialogResult = MessageBox.Show("Allow device with address "& e.Device.DeviceAddress.ToString() & " to pair?") If rslt = DialogResult.Yes Then e.Confirm = TrueEndIfElseIf e.AuthenticationMethod = BluetoothAuthenticationMethod.NumericComparison ThenDim rslt As DialogResult = MessageBox.Show("Device with address "& e.Device.DeviceAddress.ToString() & " is wanting to pair."& _ " Confirm that it is displaying this six-digit number on screen: "& e.NumberOrPasskeyAsString) If rslt = DialogResult.Yes Then e.Confirm = TrueEndIfElseIf e.AuthenticationMethod = BluetoothAuthenticationMethod.Passkey ThenDim line AsString = MyInputBox.Show("Device with address "& e.Device.DeviceAddress.ToString & " is wanting to pair."& _ " Please enter the six digit number that it is displaying on screen.") If line IsNotNothingThenDim pk AsInteger = Integer.Parse(line) If pk >= 0 AndAlso pk < 1000000 Then e.ResponseNumberOrPasskey = pk e.Confirm = TrueEndIfEndIfElse' TODOEndIfEndSub
Secure Simple Pairing schemes
The pairing method used follows this pattern:if (either is pre-v2.1) then Legacy else if (Out-Of-Band channel) then OutOfBand else if (neither have "Man-in-the-Middle Protection Required") then (i.e. both have "Man-in-the-Middle Protection _Not_ Required") Just-Works else Depending on the two devices' "IO Capabilities", either NumericComparison or Passkey. Passkey is used when one device has KeyboardOnly -- and the peer device _isn't_ NoInputNoOutput.
TODO Add SSP forms descriptions.
Changes
As of February 2011 the callback mode supports Secure Simple Pairing on Windows 7 (and Vista SP2 etc). Various new properties have been added to the BluetoothWin32AuthentionEventArgs class: AuthenticationMethod, NumberOrPasskeyAsString, NumberOrPasskey, Confirm, JustWorksNumericComparison, ResponseNumberOrPasskey, etc. The AuthenticationMethod enum can have values: Legacy, OutOfBand, NumericComparison, Passkey, and PasskeyNotification.Testing
I've managed to test: NumericComparison, and PasskeyNotification, as well as Legacy of course. When I first started testing I didn't have another Windows 7 box available with the MSFT stack so I tested with remote devices running BlueSoleil and Linux. (Note I have not managed to get authentication working with 32feet.NET on the BlueSoleil stack.) See the comments for one of our users who has: "tested SSP/NC between 2 Windows 7 PCs, a Windows 7 PC and an iPhone and a Windows 7 PC and a device we manufacture."I have also tested the peer advertising each of the IO-Capabilities (using Linux BlueZ and its CreatePairedDevice API), and thus tested PasskeyNotification (when the peer advertised: 'KeyboardOnly').
I don't think it'll be possible to exercise the other methods: Passkey because that would need Windows to advertise KeyboardOnly and I can't find a way to do that. It also appears that Windows 7 might only have support for three I've tested, as MSDN for BluetoothSendAuthenticationResponseEx says: "Only the BLUETOOTH_AUTHENTICATION_METHOD_LEGACY, BLUETOOTH_AUTHENTICATION_METHOD_NUMERIC_COMPAIRISON and BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY response types are valid." -- presumably there are two typos there: spelling "COMPAIRISON" and missing "..._NOTIFICATION" in the last.
New Post: Windows Embedded CE 7; Microsoft Socket; Client Connection
when i try to open a BT-Client on a Windows CE7 Device the creation of the client failed with the exception "32feet.NET does not support the Bluetooth stack on this device." When i look at the Radios theres only one radio on the device with the MS-Stack. Which should be supported according to the documentation.
The creation of the Socket failed with the MS-Error 10044 and 10047.
Has anyone has an idea to fix this?
New Post: how to circumvent Windows "A bluetooth device is trying to connect"
using (BluetoothClient client = new BluetoothClient())
{
var address = new BluetoothAddress(0xecfe7e11c3af);
BluetoothEndPoint endPoint = new BluetoothEndPoint(address, BluetoothService.SerialPort);
client.Connect(endPoint);
var stream = client.GetStream();
System.Threading.Thread.Sleep(10000);
}
Whenever I hit the Connect line, windows pops up a bubble notification that "A bluetooth device is trying to connect -- click to allow this". If I click the notification, windows then brings up a wizard that ends up installing virtual COM ports on my system. Is there any way to disable this functionality through the 32feet library? I want the user experience completely contained within my application, and I do not want 2 COM ports installed each time I connect to a different device.The client bluetooth chip is Bluetooth 4.0. I've previously connected to Bluetooth 2.0 modules where Windows did not interrupt the connection process.
New Post: Windows Embedded CE 7; Microsoft Socket; Client Connection
New Post: Windows Embedded CE 7; Microsoft Socket; Client Connection
New Post: how to circumvent Windows "A bluetooth device is trying to connect"
New Post: Windows Embedded CE 7; Microsoft Socket; Client Connection
New Comment on "Testing if a device is in range"
New Comment on "General Bluetooth Data Connections"
New Comment on "Supported Hardware and Software"
New Post: How to set sniffer mode on usb bluetooth?
I'm using HCI sniffer tools on Linux, hcidump.
It is possible to achieve the same result using 32feel.net?
New Post: How to set sniffer mode on usb bluetooth?
Apparently Message Analyzer on Windows 8 can sniff Bluetooth http://msdn.microsoft.com/en-us/library/jj659262.aspx
New Post: How to listen to stream and read after x bytes?
I am working on bluetooth for the first time, and I'm finding I have trouble with speed when I am reading an answer from the device after I send a question. I send a question and I expect 276 bytes to be sent back to me. At the moment I just use Read(buffer, 0, 276).
But the stream seem to take a while to fill, and I have to input a Thread.sleep(100), and since I might have to do this 65 000 times, it takes waaaaaay too long. How should I do this to make it effective??
I appreciate your help a lot!!
Best regards,
Elin
New Post: How to listen to stream and read after x bytes?
Try that and see how it helps the 'speed'/promptness too.
New Post: How to listen to stream and read after x bytes?
Now trying to change it from ask-return-ask-return-ask-return to ask-return until stopped, I think this will improve it combined with the reading of smaller chunks for bytes.
But I've run into another question that might be able to ask while I'm at it?
I use a BluetooothClient and connect via that. Is there any way to set baud rate then??