Initializing Mobile Hotspot using bluetooth C# - c#

I need to create a service that starts a mobile hotspot using bluetooth. I've found the code to create a hotspot service, but this creates a hotspot with the Ethernet adapter.
I've read the documentation and can't find anything to specify bluetooth like in the settings UI.
This is the code to initialize the hotspot with the Ethernet adapter.
var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
var tetheringManager = Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager.CreateFromConnectionProfile(connectionProfile);
The problem with this is that the network is shared through WiFi, and not Bluetooth.
Here are my current connections:
My OS were unfortiunately installed in Norwegian, but the display should look familiar in English.

GetConnectionProfiles returns a IReadOnlyList of ConnectionProfile. You can then try to select a specific profile from the list to operate on, instead of using the default one you have in your snippet.

Related

C# Get name of Wifi Direct Device Connected and OS family

I'm using code similar to what is specified at WifiDirectSample to connect devices over Wifi Direct using legacy mode.
Connection/Disconnection works fine. However I want to show the name of the device being connected i.e. MyComputer or SamsungS20, something like that and detect if the device being connected is either of Windows or android or iOS type.
So far I have somehow managed to get the name of the device using the machine name as below
var EndpointPairs = wfdDevice.GetConnectionEndpointPairs();
EndpointPair connectionEndPointPair = EndpointPairs[0];
HostName remoteHostName = connectionEndPointPair.RemoteHostName;
IPHostEntry iPHostEntry = Dns.GetHostEntry(remoteHostName.ToString());
string machineName = iPHostEntry.HostName;
Which gives name of the device in case of Windows something like MyComputer.local and incase of android somthing like SamsungS20.mshome.net !?
is there some method/API or anything which can acomplish this?
Edit:
The application being developed of WinUI App.

Defining GattCharacteristic as a Server

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.

Determine private resolvable Bluetooth LE address

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? (OS Level, Serial Code etc)

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.

WiFi Direct in Windows 10 says "UnsupportedHardware" althought it should be supported

I'll try to keep it short. I've been running in Windows 10 (10130) Microsoft's WiFi Direct Services example available on GitHub , the C# one in Visual Studio 2015 RC. Now, in their Build conference they said you can run in CMD a command to know if your WiFi adapter is compatible with WiFi Direct
netsh wlan show wirelesscap
Which gives me a big YES, your wireless adapter is compatible.
Wi-Fi Direct Device : Supported
Wi-Fi Direct GO : Supported
Wi-Fi Direct Client : Supported
But when I run the mentioned sample, everything goes OK until the WiFiDirectServiceWrapper.OnAdvertisementStatusChanged(. . .) is triggered, almost inmediatly after creating the advertiser. While running the sample with the profiler attached I get this:
private void OnAdvertisementStatusChanged(WiFiDrectServiceAdvertiser sender, object args)
--
sender | {Windows.Devices.WiFiDirect.Services.WiFiDirectServiceAdvertiser}
AdvertisementStatus: Aborted
AutoAcceptSession: true
CustomServiceStatusCode: 0
DeferredSessionInfo: null
PreferGroupOwnerMode: true
PreferredConfigurationMethods : _native, can't see_
ServiceError: UnsupportedHardware
ServiceInfo: null
ServiceName: "myservice"
ServiceNamePrefixes: {System.__comObject}
ServiceStatus: Available
I really don't know how I'm supposed to depurate this, as I can't find where this Event is raised (the only references to that method are
this.advertiser.AdversitementStatusChanged += OnAdvertisementStatusChanged
this.advertiser.AdversitementStatusChanged -= OnAdvertisementStatusChanged
^ those), and I can't see the WifiDirectServiceAdvertiser implementation.
My WiFi Card is a Qualcomm Atheros AR9485, and I'm using the latest drivers available through Windows Update. In the device manager I get two Wi-Fi Direct Virtual adapters:
Microsoft Wi-Fi Direct Virtual Adapter
Microsoft Wi-Fi Direct Virtual Adapter #2
The second one is disabled sometimes (the UnsupportedHardware event is the same, enabled or disabled). For all of them I've disabled the "Allow the PC to shut down this device to save energy" option.
I've tried to compile the code to x86 and x64, but I get the same result at the same point. I've tried another two generic wireless thumbs (those USB WiFi adapters) which Windows says yes, they're compatible too with no luck.
I know Windows 10 is not final, but any help is appreciated.
It seems that the WiFiDirect capabilities are not the only ones you need to look at if the thing you want to do is advertise a service (which is actually the "new in Windows 10 thing" concerning Direct).
The command you must execute is exactly the same as before:
netsh wlan show wirelesscap
but if you want to advertise a service, the relevant capabilities are the following:
P2P Device Discovery : Supported
P2P Service Name Discovery : Supported
P2P Service Info Discovery : Supported
P2P Background Discovery : Supported
What WiFiDirect does in Windows since 8 and 8.1 is advertising the whole computer, but since 10, WiFiDirectServices advertises one or more services running simultaneously in your machine.
Lets say you are the developer of com.boardgames. If you want to host a board games competition somewhere without a WiFi hard AP, that could be the prefix of the name of all your services, so each client connects only to the one they want: for example, com.boardgames.solitaire or com.boardgames.chess instead of connecting to your machine.
Sadly, none of the computers nor WiFi antennas I've tried are compatible with P2P discoveries.

Categories