BlueZ BLE GATT write request (0x12) instead of (0x16) - bluetooth-lowenergy

I am trying to reverse engineer a BLE device for research. The BLE device does not require pairing.
One of the commands that are written that I can see in wireshark is write to a specific handle. When I try to do the same using the Gatttool write request:
sudo gatttool -i hci0 -b 54:6C:0E:21:F5:99 --char-write-req -a 0x0030
-n 110100701301000110010030721000d68c054688df413aa89fb3cfab3d6457172000053958839fa147ac53c129eafc524829bc9ed7655fe96c9f641745c4e07cf044
It uses a 0x16 prepare write request instead and there seems to be some error as well. Below is an image of both captures, the left side is the GAtttool request and the right side is the request done by the phone.

The communication to the right has earlier negotiated a larger MTU. That's why it can send the whole value in one request.

Related

socat to log serial port data

I want to log and display a stream of data arriving at a serial port in hex with timestamps and all non printable characters (particularly any XON XOFF characters). don't need to transmit anything on the Tx port, it is not connected.
Been trying to use stty to set port parameters and socat to log but having trouble.
using /dev/null socat just exits without any doing any thing, using -u and /dev/null as second address doesn't show or log anything, using a PTY as second address works for a while but then hangs - I guess the PTY fills up and block with nothing reading it.
Thanks for any help.

How to monitor simple bi-directional TCP socket traffic (Telnet) in the middle of two endpoints?

I'm debugging an IOT protocol between two essentially black boxes on my local network talking over a telnet connection. On either end, I can specify the IP address and port. I'd like to observe / record the data exchanged between the client and server.
I'm thinking a proxy running on my Mac laptop might work. I've done some research and experimentation with nc (BSD netcat). I can only figure out a working one-way pipe, and thus the protocol exchange does not happen between A and B.
Telnet TCP server (A) <===============> TCP Client (B)
Telnet TCP server (A) <===\ /==> TCP Client (B)
\ /
\ /
Proxy/Intercept (C) *
Using a feature in the server device (A), I can have two telnet connections active. Using this, I've been able to see the server's (A) responses to whatever Client (B) is commanding, but I cannot see the Client (B) commands. ~80% of the responses are a code meaning invalid command received, but a few are reasonable responses for what this thing should be doing. I can also note that that data rate is only about 4 Bytes / second, so I'd be happy to just watch this exchange live in a terminal.
To clarify: I can power-cycle the client (B), and it will re-establish a socket connection to the IP address and port of my choosing, so I'm not really thinking about a sniffing / Wireshark type solution.
I guess I'm hoping for a relatively straightforward solution run in the shell using existing standard tools. I suppose a small program could be written in Python or something to do this, but I hope that's overkill.

Sending data to MyMqttHub through AT Commands

I've been coding a AT client using ESP32 S2 as a host and Nimbelink's Skywire Nano (nrf9160) as a LTE Modem controlled by Serial AT Commands, the LTE module is responsive and is working well. The LTE modem has an internal TCP Stack, which we have used to send data to dweet.io through a HTTP POST with success, but we haven't been successful in doing the same sending data to a private MQTT server.
The LTE module uses a method called Socket Dials, these are AT commands that facilitate sending data to the web, it basically consist in these three commands:
AT#SOCKET to activate the socket
AT#TCPCONN to connect to an URL
Example:
at#xtcpconn=3,"node02.myqtthub.com",1883
AT#TCPSEND which opens a > promt in which you enter whatever you are going to send
I'm not a communication protocols expert, so it has been a bit difficult finding the correct way to send the string since I haven't found similar examples using TCP sockets. I have tried sending mosquitto_pub strings withouy success and nimbelink only has an example using HTTP, I hope some one can help me with this or at least send me in the right direction.
at#xsocket=3,1,1
#XSOCKET: 3,6
OK
at#xtcpconn=3,"node02.myqtthub.com",1883
#XTCPCONN: 1
OK
at#xtcpsend=3
mosquitto_pub -h node02.myqtthub.com -i hub -u user -P 'password' -t topic -m "hello world"#XTCPSEND: 104
OK
SOCK: 3,HUP
Edit: added the LTE log of the attempt

generating network traffic with iperf without a server

I need to exercise some hardware by sending a network traffic with it. While it is doing it I will probing some of the lines with an oscilloscope. Need to verify signaling. The problem is that I won't be able to connect to any server during the test. Many reasons for that, one of each is that hardware isn't complete yet.
Does anyone know if there is a away to generate network traffic with iperf without using a server? All I need is to just send some data, don't need to know if it was received. If there isn't can someone point me to a tool that can do that.
iperf UDP will do it you just need to make sure there is an arp entry for the destination (enter it manually) or use a multicast destination which doesn't require ARP, e.g. iperf -u -c 239.1.1.1 -b 10M

Multiple programs on a machine should receive the network traffic arriving on one port

I have UDP network traffic arriving on my machine (OSC traffic from an iPad, to be exact) and I want two programs to be able to receive that traffic. The problem is that I can't bind to the same network port with two programs at once and I can't send to multiple ports with the iOS app I'm using. How can I solve this problem?
You can use the power of the command line for this. The following snippet uses socat (probably needs to be installed beforehand) and tee (should be preinstalled on any OS X or Linux).
socat -u UDP4-RECVFROM:8123,fork - | tee >(socat -u - UDP4-SENDTO:localhost:8223) | socat -u - UDP4-SENDTO:localhost:8323
Explanation: socat listens for traffic on UDP port 8123, pipes it to tee, which pipes it to two other instances of socat forwarding it to ports 8223 and 8323 on localhost respectively. With your two programs you need to listen to those ports on localhost.
While the answer with using socat is elegant it is not clear for me, what you are trying to do:
both programs should receive all parts of the traffic and they will only receive and not reply. This can be done with the proposed socat way
both program should receive all parts of the traffic and there reply will be mixed together (how?)
each of the programs should only receive parts of the traffic, e.g. the one which the other did not get. This should be possible if both of your programs use SO_REUSEADDR, SO_REUSEPORT. Replies will then be mixed together.
or do you actually want to communicate with each of the programs seperatly - then you would have to use either multiple sockets in the iOS app (which you don't want to do) or built your own protocol which does multiplexing, e.g. each message is prefixed with there target app and on the target machine a demultiplexer application will receive all packets and forward them to the appropriate application and wrap the replies back in the multiplexing protocol.
In summary: please describe the problem your are trying to solve, not only one small technical detail of it.
The problem is that I can't bind to the same network port with two programs at once
Yes you can. Just set SO_REUSEADDR and maybe SO_REUSEPORT on both of them before you bind.

Resources