Skip to content

Commit

Permalink
bluetooth: tester: Add explicit functions for event and response
Browse files Browse the repository at this point in the history
This make is easier to verify if proper use of BTP is maintained.
tester_rsp and tester_rsp_full will be removed eventually when
BTP is fully async.
  • Loading branch information
KKopyscinski authored and sjanc committed Jul 26, 2023
1 parent e88212a commit 6871cec
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 136 deletions.
4 changes: 3 additions & 1 deletion apps/bttester/src/btp/bttester.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ tester_init(void);
void
tester_rsp(uint8_t service, uint8_t opcode, uint8_t status);
void
tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len);
tester_rsp_full(uint8_t service, uint8_t opcode, const void *rsp, size_t len);
void
tester_event(uint8_t service, uint8_t opcode, const void *data, size_t len);

struct btp_handler {
uint8_t opcode;
Expand Down
61 changes: 29 additions & 32 deletions apps/bttester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ device_found(ble_addr_t *addr, int8_t rssi, uint8_t evtype,
* current one
*/
if (adv_buf->om_len) {
tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND,
adv_buf->om_data, adv_buf->om_len);
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND,
adv_buf->om_data, adv_buf->om_len);
}

store_adv(addr, rssi, data, len);
Expand All @@ -688,8 +688,8 @@ device_found(ble_addr_t *addr, int8_t rssi, uint8_t evtype,
return;
}
done:
tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND,
adv_buf->om_data, adv_buf->om_len);
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND,
adv_buf->om_data, adv_buf->om_len);
}

static int
Expand Down Expand Up @@ -786,9 +786,8 @@ device_connected_ev_send(struct os_event *ev)
return;
}

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED,
(uint8_t *) &connected_ev,
sizeof(connected_ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED,
(uint8_t *) &connected_ev, sizeof(connected_ev));

periph_privacy(desc);
}
Expand Down Expand Up @@ -826,9 +825,9 @@ le_connected(uint16_t conn_handle, int status)
os_time_ms_to_ticks32(
CONNECTED_EV_DELAY_MS(desc.conn_itvl)));
#else
tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED,
(uint8_t *) &connected_ev,
sizeof(connected_ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED,
(uint8_t *) &connected_ev,
sizeof(connected_ev));
#endif
}

Expand Down Expand Up @@ -869,8 +868,8 @@ le_disconnected(struct ble_gap_conn_desc *conn, int reason)

memcpy(&ev.address, addr, sizeof(ev.address));

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand Down Expand Up @@ -924,8 +923,8 @@ auth_passkey_display(uint16_t conn_handle, unsigned int passkey)
memcpy(&ev.address, addr, sizeof(ev.address));
ev.passkey = htole32(pk.passkey);

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand All @@ -947,8 +946,8 @@ auth_passkey_entry(uint16_t conn_handle)

memcpy(&ev.address, addr, sizeof(ev.address));

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand All @@ -971,8 +970,8 @@ auth_passkey_numcmp(uint16_t conn_handle, unsigned int passkey)
memcpy(&ev.address, addr, sizeof(ev.address));
ev.passkey = htole32(passkey);

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand Down Expand Up @@ -1051,8 +1050,8 @@ le_identity_resolved(uint16_t conn_handle)
memcpy(&ev.identity_address, &desc.peer_id_addr,
sizeof(ev.identity_address));

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand All @@ -1076,8 +1075,8 @@ le_pairing_failed(uint16_t conn_handle, int reason)

ev.reason = reason;

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_PAIRING_FAILED,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_PAIRING_FAILED,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand All @@ -1093,8 +1092,8 @@ le_conn_param_update(struct ble_gap_conn_desc *desc)
ev.conn_latency = desc->conn_latency;
ev.supervision_timeout = desc->supervision_timeout;

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_CONN_PARAM_UPDATE,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_CONN_PARAM_UPDATE,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand All @@ -1121,8 +1120,8 @@ le_encryption_changed(struct ble_gap_conn_desc *desc)
}
}

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_LEVEL_CHANGED,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_LEVEL_CHANGED,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand All @@ -1136,10 +1135,8 @@ bond_lost(uint16_t conn_handle)
assert(rc == 0);

memcpy(&ev.address, &desc.peer_id_addr, sizeof(ev.address));
tester_send(BTP_SERVICE_ID_GAP,
BTP_GAP_EV_BOND_LOST,
(uint8_t *) &ev,
sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST,
(uint8_t *) &ev, sizeof(ev));
}

static void
Expand Down Expand Up @@ -1212,8 +1209,8 @@ adv_complete(void)
current_settings &= ~BIT(BTP_GAP_SETTINGS_ADVERTISING);
ev.current_settings = htole32(current_settings);

tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_NEW_SETTINGS,
(uint8_t *) &ev, sizeof(ev));
tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_NEW_SETTINGS,
(uint8_t *) &ev, sizeof(ev));
}

static int
Expand Down
47 changes: 24 additions & 23 deletions apps/bttester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ attr_value_changed_ev(uint16_t handle, struct os_mbuf *data)
ev->data_length = htole16(os_mbuf_len(data));
os_mbuf_appendfrom(buf, data, 0, os_mbuf_len(data));

tester_send_buf(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED,
CONTROLLER_INDEX, buf);
tester_event(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED,
buf->om_data, buf->om_len);
}

static int
Expand Down Expand Up @@ -683,8 +683,8 @@ read_cb(uint16_t conn_handle,

if (error->status != 0 && error->status != BLE_HS_EDONE) {
rp->att_response = (uint8_t) BLE_HS_ATT_ERR(error->status);
tester_send(BTP_SERVICE_ID_GATT, btp_opcode, gatt_buf.buf, gatt_buf
.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode,
gatt_buf.buf, gatt_buf.len);
read_destroy();
return 0;
}
Expand All @@ -697,8 +697,8 @@ read_cb(uint16_t conn_handle,
}

rp->data_length += attr->om->om_len;
tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
gatt_buf.buf, gatt_buf.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode,
gatt_buf.buf, gatt_buf.len);
read_destroy();

return 0;
Expand Down Expand Up @@ -748,15 +748,15 @@ read_long_cb(uint16_t conn_handle,

if (error->status != 0 && error->status != BLE_HS_EDONE) {
rp->att_response = (uint8_t) BLE_HS_ATT_ERR(error->status);
tester_send(BTP_SERVICE_ID_GATT, btp_opcode, gatt_buf.buf, gatt_buf
.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode,
gatt_buf.buf, gatt_buf.len);
read_destroy();
return 0;
}

if (error->status == BLE_HS_EDONE) {
tester_send(BTP_SERVICE_ID_GATT, btp_opcode, gatt_buf.buf, gatt_buf
.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode,
gatt_buf.buf, gatt_buf.len);
read_destroy();
return 0;
}
Expand Down Expand Up @@ -882,8 +882,8 @@ write_rsp(uint16_t conn_handle, const struct ble_gatt_error *error,

SYS_LOG_DBG("");

tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
&err, sizeof(err));
tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode,
&err, sizeof(err));
return 0;
}

Expand Down Expand Up @@ -969,8 +969,8 @@ reliable_write_rsp(uint16_t conn_handle,

SYS_LOG_DBG("Reliable write status %d", err);

tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_RELIABLE_WRITE,
&err, sizeof(err));
tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_RELIABLE_WRITE,
&err, sizeof(err));
return 0;
}

Expand Down Expand Up @@ -1081,7 +1081,8 @@ disc_prim_uuid_cb(uint16_t conn_handle,
}

if (error->status == BLE_HS_EDONE) {
tester_send(BTP_SERVICE_ID_GATT, opcode, gatt_buf.buf, gatt_buf.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, opcode,
gatt_buf.buf, gatt_buf.len);
discover_destroy();
return 0;
}
Expand Down Expand Up @@ -1136,8 +1137,8 @@ disc_all_desc_cb(uint16_t conn_handle,
}

if (error->status == BLE_HS_EDONE) {
tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, gatt_buf
.buf, gatt_buf.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC,
gatt_buf.buf, gatt_buf.len);
discover_destroy();
return 0;
}
Expand Down Expand Up @@ -1253,8 +1254,8 @@ find_included_cb(uint16_t conn_handle,
}

if (error->status == BLE_HS_EDONE) {
tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, gatt_buf
.buf, gatt_buf.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED,
gatt_buf.buf, gatt_buf.len);
discover_destroy();
return 0;
}
Expand Down Expand Up @@ -1310,8 +1311,8 @@ disc_chrc_cb(uint16_t conn_handle,
}

if (error->status == BLE_HS_EDONE) {
tester_send(BTP_SERVICE_ID_GATT, btp_opcode, gatt_buf.buf, gatt_buf
.len);
tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode,
gatt_buf.buf, gatt_buf.len);
discover_destroy();
return 0;
}
Expand Down Expand Up @@ -2046,8 +2047,8 @@ tester_gatt_notify_rx_ev(uint16_t conn_handle, uint16_t attr_handle,
ev->data_length = htole16(os_mbuf_len(om));
os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));

tester_send_buf(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION,
CONTROLLER_INDEX, buf);
tester_event(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION,
buf->om_data, buf->om_len);

fail:
os_mbuf_free_chain(buf);
Expand Down
Loading

0 comments on commit 6871cec

Please sign in to comment.