|
34 | 34 | #include "../../../nimble/host/src/ble_sm_priv.h" |
35 | 35 |
|
36 | 36 | #include "btp/btp.h" |
| 37 | +#include "btp/bttester.h" |
37 | 38 |
|
38 | 39 | #include <errno.h> |
39 | 40 |
|
@@ -89,6 +90,43 @@ static const struct ble_gap_conn_params dflt_conn_params = { |
89 | 90 | .max_ce_len = 0x0300, |
90 | 91 | }; |
91 | 92 |
|
| 93 | +/* Important: Remember to update this if new events are introduced */ |
| 94 | +#define BTP_GAP_EV_MAX GAP_EV_SUBRATE_CHANGE |
| 95 | + |
| 96 | +#define GAP_SUPPORTED_EVENTS_LEN BTP_EVENT_BITMAP_LEN(BTP_GAP_EV_MAX) |
| 97 | + |
| 98 | +static uint8_t gap_supported_events[GAP_SUPPORTED_EVENTS_LEN]; |
| 99 | + |
| 100 | +static void |
| 101 | +gap_init_supported_events(void) |
| 102 | +{ |
| 103 | + memset(gap_supported_events, 0, sizeof(gap_supported_events)); |
| 104 | + |
| 105 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_NEW_SETTINGS)); |
| 106 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_DEVICE_FOUND)); |
| 107 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_DEVICE_CONNECTED)); |
| 108 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_DEVICE_DISCONNECTED)); |
| 109 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_PASSKEY_DISPLAY)); |
| 110 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_PASSKEY_ENTRY_REQ)); |
| 111 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_PASSKEY_CONFIRM_REQ)); |
| 112 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_IDENTITY_RESOLVED)); |
| 113 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_CONN_PARAM_UPDATE)); |
| 114 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_SEC_LEVEL_CHANGED)); |
| 115 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_BOND_LOST)); |
| 116 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_SEC_PAIRING_FAILED)); |
| 117 | +#if MYNEWT_VAL(BLE_PERIODIC_ADV) |
| 118 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_SYNC_ESTABLISHED)); |
| 119 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_SYNC_LOST)); |
| 120 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_REPORT)); |
| 121 | +#endif |
| 122 | +#if MYNEWT_VAL(BLE_PERIODIC_ADV_SYNC_TRANSFER) |
| 123 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_TRANSFER_RECEIVED)); |
| 124 | +#endif |
| 125 | +#if MYNEWT_VAL(BLE_CONN_SUBRATING) |
| 126 | + tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_SUBRATE_CHANGE)); |
| 127 | +#endif |
| 128 | +} |
| 129 | + |
92 | 130 | static int |
93 | 131 | gap_conn_find_by_addr(const ble_addr_t *dev_addr, |
94 | 132 | struct ble_gap_conn_desc *out_desc) |
@@ -134,6 +172,17 @@ supported_commands(const void *cmd, uint16_t cmd_len, |
134 | 172 | return BTP_STATUS_SUCCESS; |
135 | 173 | } |
136 | 174 |
|
| 175 | +static uint8_t |
| 176 | +supported_events(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) |
| 177 | +{ |
| 178 | + struct btp_gap_read_supported_events_rp *rp = rsp; |
| 179 | + |
| 180 | + *rsp_len = tester_supported_events(BTP_SERVICE_ID_GAP, rp->data); |
| 181 | + *rsp_len += sizeof(*rp); |
| 182 | + |
| 183 | + return BTP_STATUS_SUCCESS; |
| 184 | +} |
| 185 | + |
137 | 186 | static uint8_t |
138 | 187 | controller_index_list(const void *cmd, uint16_t cmd_len, |
139 | 188 | void *rsp, uint16_t *rsp_len) |
@@ -2277,6 +2326,12 @@ static const struct btp_handler handlers[] = { |
2277 | 2326 | .expect_len = 0, |
2278 | 2327 | .func = supported_commands, |
2279 | 2328 | }, |
| 2329 | + { |
| 2330 | + .opcode = BTP_GAP_READ_SUPPORTED_EVENTS, |
| 2331 | + .index = BTP_INDEX_NONE, |
| 2332 | + .expect_len = 0, |
| 2333 | + .func = supported_events, |
| 2334 | + }, |
2280 | 2335 | { |
2281 | 2336 | .opcode = BTP_GAP_READ_CONTROLLER_INDEX_LIST, |
2282 | 2337 | .index = BTP_INDEX_NONE, |
@@ -2483,9 +2538,12 @@ tester_init_gap(void) |
2483 | 2538 | assert(adv_buf); |
2484 | 2539 |
|
2485 | 2540 | tester_init_gap_cb(); |
| 2541 | + gap_init_supported_events(); |
2486 | 2542 |
|
2487 | 2543 | tester_register_command_handlers(BTP_SERVICE_ID_GAP, handlers, |
2488 | 2544 | ARRAY_SIZE(handlers)); |
| 2545 | + tester_register_supported_events(BTP_SERVICE_ID_GAP, gap_supported_events, |
| 2546 | + sizeof(gap_supported_events)); |
2489 | 2547 |
|
2490 | 2548 | return BTP_STATUS_SUCCESS; |
2491 | 2549 | } |
|
0 commit comments