I'm trying to reproduce an ATT packet being sent to a Bluetooth LE device already connected to a phone.
Is this even possible?
I've figured out how the packet should look like, I'm just not able to wrap my head around GATT and how it translates to ATT in this specific case.
The wireshark dump looks like this:
localhost () remote () ATT 26 Sent Handle Value Notification, Handle: 0x0035 (Unknown)
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
0... .... = Authentication Signature: False
.0.. .... = Command: False
..01 1011 = Method: Handle Value Notification (0x1b)
Handle: 0x0035 (Unknown)
Value: 0a0b313233343536373839303132
I've already figured out that the actual application payload here starts after the handle 0x0035, with 0x0a 0x0b being some custom control characters and everything afterwards a number (123456789012), exactly as I expected it to be.
How do I translate the "handle" to the GATT protocol? Is this done in Android GATT via UUIDs? If I loop over all services on that device a get a bunch of services, loads of characteristics, descriptors and I'm lost.
Oh, what I forgot to mention: None of the services and characteristics I get seem to be related to the handle 0x0035.
Is "getInstanceId" supposed to return the handle that will be used? Writing to writable characteristics on that device lead to Wireshark showing the handle value corresponding to the getInstanceId.
first thing you have to know is that in Android you can't use the Handles direktly as a developer. You have to deal with the UUIDs. in Wireshark when you have a look at the ATT Protocoll you should be able to see the UUID of the service and the characteristic when opening the Handle drop down. With this Information you should be able to detect the UUids you need.
https://developer.android.com/guide/topics/connectivity/bluetooth-le shows you how to send a value to a notification. In general you can use Constants for example to ebanle notifications. I guess if your server requires specific bytes you should be able to send them the same way.
Well, after inspecting logs and docs a little more I came to the conclusion that the remote device (which should provide serivces) here is actually using a server on the local host and this is a value notification sent from the host to the remote.
Related
I'm developing an app for a custom peice of bluetooth hardware.
The spec for the device has a number of commands which can be sent to the device, via a specific Bluetooth Characteristic.
we are currently using this version of Flutter Blue; flutter_blue:^0.7.2
So far we have it discovering the device, connecting, and discovering the correct services and characteristics.
We also have it sending commands and receving the expected responses.
This works by listing on the correct chartacteristic like so;
await notify.setNotifyValue(true);
notify.value.listen((event) {
_handleEvent(event);
});
and then sending the commnads like so;
await recv.write(command, withoutResponse: true);
(where the command is a List representing the payload bytes).
The problem comes in where a response includes more than one packet.
In this case the inital packet is received but the following expected packets do not arrive.
On ios it's working slightly better in that the inital packet is 4 times the size of the Android response and includes the expected data, BUT if the data is too big it's not included.
I've attempted to modify the MTU but this dosen't seem to have any effect on the issue.
Any help would be greatly appeciated.
In this case the issue was totally releated to the MTU setting.
I was under the impression that if you requested to set it too high it would automatically go to it's highest possible value. But looks like that is not the case.
If you are seeing a similar issue try setting the MTU to 251
My problem is as follows:
I would like to make an application to list the sms conversation using C# and AT Command ... (not Android)
The Android/iOS smartphone will be connected by USB cable.
is it possible ?
any ways to help me
Provided the phone implements a serial USB interface that speaks AT commands (Communication Device Class (CDC) Abstract Control Model (ACM)), then yes this is possible.
The command to read SMS messages is AT+CMGR and it is standardized in the 3GPP specification 27.005. For reading1 SMS messages there no special handling other than the normal AT command response parsing (never use sleep/delay/etc).
The sms commands operates in one of two modes, Text mode (optional) or PDU mode (mandatory). Text mode is simpler but does not provide all the meta information that PDU mode does. Depending on the phone or what you want to display and parse you might be required to use PDU mode.
Parsing the hexadecimal binary response you get in PDU mode is very far from trivial, and you most certainly want to use a library for this rather than trying to write parse code yourself (at least when your experience is starting on not knowing about the relevant commands and not having read V.250, 27.007 and 27.005 before).
1For sending you must wait for `"\r\n> " before sending the payload, see the first part of this answer.
Purpose: Write "commands"(quoted because I haven't figure out the right command, I was told it's 0x0001, 0x0010, 0x01, 0x02, etc ) to CCCD handle on the BLE stack to enable notification/indication (from MCU to Android device)
Problem: Don't know the right API, don't know if there is an API, tried setCharacteristic(), did not work, at all.
What I have: I can discover the right char., I can send data from phone, I can bond (taken care not by me, but by the stack anyway) but I cannot send data FROM MCU to Android.
Help, please?
First use https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html#getDescriptor(java.util.UUID) with UUID.fromString("00002902-0000-1000-8000-00805F9B34FB") as argument to get the CCCD.
Use https://developer.android.com/reference/android/bluetooth/BluetoothGattDescriptor.html#setValue(byte[]) to set the value https://developer.android.com/reference/android/bluetooth/BluetoothGattDescriptor.html#ENABLE_NOTIFICATION_VALUE. Then call https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#writeDescriptor(android.bluetooth.BluetoothGattDescriptor) to send the value to the remote device.
Then you must also call https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean) in order to make Android's Bluetooth stack forward the notifications to your app.
I am currently developing an android app and i want to send data message with audio file attached to it. One of the arguments of the sendDataMessage() methods is "destination port".
I know its the port i want to send the message via, but I am not sure what to put there, is there a default port for sending data messages? I have looked for it but every example I have seen uses different port. However, whichever port I use, I get Null PDU exception.
I am using HTC for running and testing the app btw.
Default is 8091. Most devices don't support port filtering very well, though:
SmsManager.sendDataMessage(..., onSpecificPort , ...,.. ) Is not Filtering SMS On Port Basis
Your null PDU is probably not because of a port selection problem, though.
I am stuck at a place where my Android Phone(Samsung Galaxy) has to open 2(or more) connections to my PC(server) which is a paired device. For this purpose, I start SDP server on PC with UUID : 00001101-0000-1000-8000-00805F9B34FB and channel 2, after the first connection I unregister the SDP service on the PC and register it again on channel 3(and same UUID) and expect my android phone to 'connect' to it for establishing the second bluetooth connection. The second one fails.
The problem as I have figured out is that because of the pairing, the channel num and UUID of the device for the 'BluetoothSocket.connect' are serviced from cache and are not being updated, so my SDP change in channel num on the server side is not visible here as it still tries to connect to channel 2(old one).
A workaround of this problem(found after a lot of frustrating attempts) might be to change the android.server.BluetoothService.java file, by introducing
updateDeviceServiceChannelCache(addr) before returning in the getRemoteServiceChannel() and fetchRemoteUuids() so as to update the channel number at each func call.
The above solution may well be wrong, please pardon me for that. If it is correct please suggest any further changes and how to make this change permanent in eclipse, or in other case(wrong solution), the right way of doing this.
Note: I have android 2.3.5 and the requests from the device are actually from the browser that I forward to the PC. I want them on separate channels.
thanks.