I'm trying to write simple app, which sends short text message to cellphones in bluetooth adapter range.
My first try is sending files: I can send file from PC to cellphone, but i must enter PIN on cellphone, and on PC.
I would rather to send text messages (something like push message) - is it possible to send it without paring devices?
If isn't possible to send push messages, maybe I can send simple file without requesting PIN ?
I use 32feet library.
Sample code (used to send files to selected device)
static int BTSendFile(string adres, string FileName)
{
Uri uri = new Uri("obex://" + adres + '/' + Path.GetFileName(FileName));
ObexWebRequest req = new ObexWebRequest(uri);
req.ReadFile(FileName);
ObexWebResponse rsp = (ObexWebResponse)req.GetResponse();
return (int)rsp.StatusCode;
}
A quick answer would be; NO, you will ALWAYS need some kind of pairing.
But if you take a look at the different kinds of pairing out there, you would see that BT 2.1 supports Secure Simple Pairing (SSP) with the Just Works-mode. This allows you to pair devices (almost) without any user interaction. From Wikipedia:
Just works: As implied by the name, this method just works. No user interaction is required; however, a device may prompt the user to confirm the pairing process. This method is typically used by headsets with very limited IO capabilities, and is more secure than the fixed PIN mechanism which is typically used for legacy pairing by this set of limited devices. This method provides no man in the middle protection.
However, since "This method is typically used by headsets with very limited IO capabilities", it would probably not apply to the cellphones you are talking about, but I thought you should know :)
According to the offical Bluetooth Message Access Profile, i.e. the specific Bluetooth profile that deals with accessing SMS/MMS systems on phones via a remote device:
'The MCE device shall use the services of the MSE device only after successfully creating a secure connection. This includes exchanging of security initialization messages, creation of link keys, and enabling encryption'
From: https://developer.bluetooth.org/TechnologyOverview/Pages/MAP.aspx
There is also a link to the full spec there if you are interested.
This certtainly suggests that secure pairing is required, which I'd assume to involve the passkey. My experience is that once a device has been paired a connection can be made without repeating the pairing as long as that pairing is remembered by the devices (i.e. I've paired a device once and not had to do it again). As to simpler, non-keyed pairing mentioned by khellang above, I've not seen anything about this - if it is purely for devices like headsets then the security requirements may be lower due to their not likely wanting write access to a device?
Related
I want to fill my variable "selectedCharacteristic" with
GattCharacteristic selectedCharacteristic
selectedCharacteristic = Constants.ResultCharacteristicUuid;
Unfortunately, this doesn't work. It won't convert.
The ResultCharacteristicUuid is from the Microsoft UWP BLE Example.
https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/BluetoothLE/cs/Constants.cs
My program, which has not much to do with the microsoft example (besides the constants.cs),
opens up a BLE Service on start, along with the Result-Characteristic. It acts as an BLE server, nothing more.
So when my BLE Server started, there should be a simple solution to get the device infos and everything GattCharacteristic needs, or not?
The goal is to write to the characteristic as the server, not as a client.
What do I need to get the ResultCharacteristic-Uuid into selectedCharacteristic ?
The UUID should be defined by yourself when you are creating your own service, characteristic. Based on the document- Bluetooth GATT server, you could generate your custom UUID from Visual Studio through Tools -> CreateGuid (use option 5 to get it in the "xxxxxxxx-xxxx-...xxxx" format). This uuid can now be used to declare new local services, characteristics or descriptors.
Im currently working on a Mobile application which connects to a Ble peripheral and reads data from it. In order to test if the connection is working. I have written a small C# application that utilizes the RaspberryPi4 bluetooth via DBus with BlueZ.
Everything works except that when connecting to iOS a pairing request is issued by the raspberry, eventhough I do not have any encrypted characteristics.
I have read on the Apple forum that this is because bluetoothd is automaticly trying to read the battery level of the phone. But sadly even after the fix suggested there I get the pairing requests.
Does anyone have an idea how I could fix this?
Thanks in advance
I believe disabling this bluez config option in /etc/bluetooth/main.conf would prevent the pi from trying to read characteristics from the iOS device, if that is the issue:
# Do reverse service discovery for previously unknown devices that connect to
# us. For BR/EDR this option is really only needed for qualification since the
# BITE tester doesn't like us doing reverse SDP for some test cases, for LE
# this disables the GATT client functionally so it can be used in system which
# can only operate as peripheral.
# Defaults to 'true'.
#ReverseServiceDiscovery = true
Check the connection min and max intervals, they shall be compliant with the iOS guidelines: https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf (page 180 - 40.6 Connection Parameters).
You can tune them like this:
echo "30" > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
echo "45" > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
The default values worked for me: [24,40]
I have written an application that uses the UWP classes to offer a GATT-Server (i. e. my laptop functions as a BLE peripheral).
I can successfully advertise, connect, and use it, but there's one thing I cannot figure out: how can I find out the current private resolvable address that the central is seeing?
My bluetooth adapter appears to have the internal address 9C:B6:D0:XX:YY:ZZ. I can find and confirm that address in various ways:
BluetoothAdapter.GetDefaultAsync().AsTask().Result.BluetoothAddress.ToString("X12") returns "9CB6D0XXYYZZ" as result in the direct window of Visual Studio.
If I add a breakpoint in any read request handler, then GattReadRequestedEventArgs.Session.DeviceId.Id is "BluetoothLE#BluetoothLE9c:b6:d0:xx:yy:zz-gg:hh:ii:jj:kk:ll".
Device Manager > Bluetooth > {Device Name} > Properties > Advanced shows 9c:b6:d0:xx:yy:zz.
I'm using the "nRF Connect" app for Android to connect to my artificial peripheral and operate on its BLE services and characteristics, and it works great. However, the address that nRF Connect shows is a different one, for example "5F:69:8A:DD:C9:ED". It also changes every time I restart the GATT-Server.
I suppose this is a private resolvable address, used to hide the actual adapter's address for privacy reasons. But I cannot seem to find a way to determine that address from the code in the GATT server. All I know is that it is neither the BluetoothAdapter.BluetoothAddress, nor part of the GattReadRequestedEventArgs.Session.DeviceId.Id, because both contain only the internal address that never changes, and the gg:hh:ii:jj:kk:ll part mentioned above is yet another address (but not the one nRF Connect shows).
Determine private resolvable Bluetooth LE address
For API Address and the Private Rotating Address. The API returns a Static Address and the advertisement contains the private Rotating Address.
There is no way in UWP to get the private rotating address and this is by design.
What device information can I access from the Hololens at run time using MRTK?
Can MRTK determine a unique identifier for each Hololens device that runs my program? Ideally this would be a serial code, but any other unique identifier from the device would be useful.
I am trying to determine ways to track how many unique devices are running my program, as well as how often they run it.
I am aware that using a managed device might be one way to do this, but I am curious if there is any way to get such information without needing to set up ID Management.
You can use the instance of the EasClientDeviceInformation to get device information from the local device. The property Id provides the identifier of the local device. you can use the following code:
using Windows.Security.ExchangeActiveSyncProvisioning;
. . .
EasClientDeviceInformation deviceInfo = new EasClientDeviceInformation();
var deviceIdentifier = deviceInfo.Id;
In addition, you can retrieve more device information through other properties of the instance, a specific sample is provided here: Client Device Information sample.
I was reading that question (How to create a simple proxy in C#?) that is near of my wishes.
I simply want develop a c# app that, by example, monitors Firefox, IE, etc and logs all navigated pages. Depending of the visited page, I want to block the site (like a parental filter).
Code snippets/samples are good, but if you can just tell me some direction of that classes to use I will be grateful. :-)
I’ll answer appropriate for a parent: ala "Parental Controls"
You can start out with a proxy server when the kids are less than about 10 years old. After that, they will figure out how to get around the proxy (or run their own client applications that bypass the proxy). In the early teen years, you can use raw sockets.
Type this program into Visual Studio (C#).
class Program
{
static void Main(string[] args)
{
try
{
byte[] input = BitConverter.GetBytes(1);
byte[] buffer = new byte[4096];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
s.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.91"), 0));
s.IOControl(IOControlCode.ReceiveAll, input, null);
int bytes = 0;
do
{
bytes = s.Receive(buffer);
if (bytes > 0)
{
Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytes));
}
} while (bytes > 0);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
Note that this is just a “snippet”, lacking appropriate design and error checking. [Please do not use 'as-is' - you did request just a head start] Change the IP address to your machine. Run the program AS Administrator (use “runas” on the command line, or right-click “Run as Administrator”). Only administrators can create and use raw sockets on modern versions of windows. Sit back and watch the show.
All network traffic is delivered to your code (displayed on the screen, which will not look nice, with this program).
Your next step is to create some protocol filters. Learn about the various internet application protocols (assuming you don't already know), modify the program to examine the packets. Look for HTTP protocol, and save the appropriate data (like GET requests).
I personally have setup filters for AIM (AOL Instant Messenger), HTTP, MSN messenger (Windows Live Messenger), POP, and SMTP. Today, HTTP gets just about everything since the kids prefer the facebook wall to AIM nowadays.
As the kids reach their early-to-mid teenage years, you will want to back-off on the monitoring. Some say this is to enable the kids to “grow up”, but the real reason is that “you don’t wanna know”. I backed off to just collecting URLs of get requests, and username/passwords (for emergency situations) that are in clear text (pop, basic auth, etc.).
I don't know what happens in late teen years; I cannot image things getting much worse, but I am told that "I have not seen anything yet".
Like someone earlier said, this only works when run on the target machine (I run a copy on all of the machines in the house). Otherwise, for simple monitoring check your router - mine has some nice logging features.
My final comment is that this application should be written in C/C++ against the Win32 API directly, and installed as a service running with administrative rights on the machine. I don't think this type of code is appropriate for managed c#. You can attach a UI in C# for monitoring and control. You have to engineer the code so as to have zero noticeable effect on the system.
Your approach will depend on whether or not you are installing this application on the same box you are using to browse or on a separate proxy server.
If you are doing this on a separate server it will be easier to accomplish this in C# / managed code, as you will be simply writing a C# proxy server that client pc's will have point to. System.Net.Sockets namespace TcpListener and TcpClient will be your friend.
If, however, you are installing this on the same machine then take a look WinPcap and and SharpPCap and perhaps Fiddler for some ideas.
Hope that helps.