0
votes

I am having difficulty figuring out how to convert my bluetooth command (from Gatttool) to Bluez c code.

Can you help me translate the following Gatttool command (bluetooth request) to c?

[CON][MY_MAC_ADDRESS][LE]> char-write-req 0x00c0 0100

So my handle is 0x00c0 and my data is 0100 (on). I don't know which hci_request structure properties I need to fill (except for the handle).

... I've successfully connected to the device (LE connection)
struct hci_request rq = {0};
rq.ogf = ??; // should the handle go here?
rq.ocf = ??; // should the data go here
rq.cparam = ??;
rq.clen = ??;
rq.rparam = ??;
rq.rlen = ??;
rq.event = ??; // what would the event be?

hci_send_req(dd, &rq, 1000);
1

1 Answers

0
votes

Why don't yo use the standard bluez gatt command i.e.

void WriteValue(array{byte} value, dict options) 

but combine the HCI command yourself?

However if you really want to combine the HCI command(which means you skip the GATT/ATT/L2CAP level), the format is "HCI ACL Data Packets" defined as "HCI_ACLDATA_PKT" at hci.h at BlueZ: Handle:The Connection Handle of your ACL. Packet_Boundary_Flag:00/01/10 or 11 depends your L2cap package type. Broadcast_Flag: basically is 0x00 i.e. No broadcast Data_Total_Length: length of your package. then the package need include the L2CAP PDU length and channel ID(should be 0x0004 as ATT protocol),then append the ATT pdu type,opcode(write command) att handle and data.