summaryrefslogtreecommitdiff
path: root/extmod/modbluetooth.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2021-01-22 17:30:25 +1100
committerDamien George <damien@micropython.org>2021-01-22 18:15:12 +1100
commitaa136b4d78c7f81e63bde20ae17ab69bbbf456db (patch)
treea58ffd937bebd1d830db637152ca9e72f9c1c7fd /extmod/modbluetooth.c
parent49dd9ba1a5e50c400a3cfd604dd884bf9fea628c (diff)
extmod/modbluetooth: Add ble.hci_cmd(ogf, ocf, req, resp) function.
This allows sending arbitrary HCI commands and getting the response. The return value of the function is the status of the command. This is intended for debugging and not to be a part of the public API, and must be enabled via mpconfigboard.h. It's currently only implemented for NimBLE bindings. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'extmod/modbluetooth.c')
-rw-r--r--extmod/modbluetooth.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c
index caaf872e7..8870a21c4 100644
--- a/extmod/modbluetooth.c
+++ b/extmod/modbluetooth.c
@@ -884,6 +884,23 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_recvinto_obj, 4,
#endif // MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS
+#if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD
+
+STATIC mp_obj_t bluetooth_ble_hci_cmd(size_t n_args, const mp_obj_t *args) {
+ mp_int_t ogf = mp_obj_get_int(args[1]);
+ mp_int_t ocf = mp_obj_get_int(args[2]);
+ mp_buffer_info_t bufinfo_request = {0};
+ mp_buffer_info_t bufinfo_response = {0};
+ mp_get_buffer_raise(args[3], &bufinfo_request, MP_BUFFER_READ);
+ mp_get_buffer_raise(args[4], &bufinfo_response, MP_BUFFER_WRITE);
+ uint8_t status = 0;
+ bluetooth_handle_errno(mp_bluetooth_hci_cmd(ogf, ocf, bufinfo_request.buf, bufinfo_request.len, bufinfo_response.buf, bufinfo_response.len, &status));
+ return MP_OBJ_NEW_SMALL_INT(status);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_hci_cmd_obj, 5, 5, bluetooth_ble_hci_cmd);
+
+#endif // MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD
+
// ----------------------------------------------------------------------------
// Bluetooth object: Definition
// ----------------------------------------------------------------------------
@@ -927,6 +944,9 @@ STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_l2cap_send), MP_ROM_PTR(&bluetooth_ble_l2cap_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_l2cap_recvinto), MP_ROM_PTR(&bluetooth_ble_l2cap_recvinto_obj) },
#endif
+ #if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD
+ { MP_ROM_QSTR(MP_QSTR_hci_cmd), MP_ROM_PTR(&bluetooth_ble_hci_cmd_obj) },
+ #endif
};
STATIC MP_DEFINE_CONST_DICT(bluetooth_ble_locals_dict, bluetooth_ble_locals_dict_table);