0

I have an issue using bluetoothctl and the gatt menu. I want to write in a specific device handle, but when I'm doing this nothing is returned. I have a second handle with some fields to check if an error occurred with what I wrote.

My data is a public key that I retrieve in hex format that I convert with python into bytes format. I want to send a JSON as message so I convert my message withjson.dumps(message).encode()

When I have these data, I'm using the python PKCS1_OAEP to encrypt my message and retrieve my cyphertext.

The purpose is to send my cyphertext by air via the Linux BLE with bluetoothctl. However as I said before, when I use the bluetoothctl menu gatt and select the attributes where I want to write, nothing is returned even an error message but I know that an error occurred thanks to the second handle.

It's not my entire cyphertext but That's what it looks like \xbfm\xcd\xea\x15\xd1\x87\x90f]\xc9\x7f\x18M. I don't know if the "write" functionality from menu gatt support cyphertext.

I know that the basics formats is like write "0x.. 0x.." but I can't use it.

Do you have any ideas ? Thanks you !

Noyha
  • 3
  • 2
  • The way your question is currently written it is not clear what the problem is that you are having. Are you trying to use `bluetoothctl` from inside a python script? – ukBaz Jan 28 '23 at 06:46
  • You're right indeed. I use Bluetoothctl with a python script with pexpect. But the problem is about what kind of data can you write to a specific attributes in bluetoothctl menu gatt. Python is used to encrypt a Json message. This encrypted message have a specific format. I don't know if the write command from menu gatt can take my encrypted message because of the format for the reason explained on my previous message. Every time I get an error when I try to send my encrypted message via the write command. – Noyha Jan 29 '23 at 20:30
  • What error do you get? With GATT it doesn't understand what you are sending, just that it is bytes. So your data in the question would be `'0xbf 0x6d 0xcd 0xea 0x15 0xd1 0x87 0x90 0x66 0x5d 0xc9 0x7f 0x18 0x4d'`. This could be created with `" ".join([f"{x:#x}" for x in data])`. From a Python script it is more usual to use the BlueZ D-Bus API as documented at https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc. There is an example at: https://stackoverflow.com/a/63751113/7721752. There can be a limit of 20ish characters. Is that the error you get? – ukBaz Jan 29 '23 at 21:40
  • Does sending the information work if you do it manually in `bluetoothctl`? If you have `sudo btmon` running in a separate terminal, are there any errors reported? – ukBaz Jan 30 '23 at 06:27
  • Thanks for answering me. I resolved my problem on my side this morning. There was an extra blank space in what I sent so it couldn't work ! However, the data sent was exactly what you wrote. Thanks for the answers ! – Noyha Jan 30 '23 at 22:32

0 Answers0