aboutsummaryrefslogtreecommitdiff
path: root/extmod/modbluetooth.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-05-08 13:54:10 +1000
committerDamien George <damien.p.george@gmail.com>2020-05-11 21:30:41 +1000
commit3b6c9119eb3593d9a3af8474d7186541f08d849e (patch)
treeec6fe93a8d9657398d80eca6ff5ac1e257477847 /extmod/modbluetooth.c
parentf385b7bfa86aa4657d4a28971a63b8681e1403e2 (diff)
extmod/modbluetooth: Add support for changing the GAP device name.
This commit allows the user to set/get the GAP device name used by service 0x1800, characteristic 0x2a00. The usage is: BLE.config(gap_name="myname") print(BLE.config("gap_name")) As part of this change the compile-time setting MICROPY_PY_BLUETOOTH_DEFAULT_NAME is renamed to MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME to emphasise its link to GAP and this new "gap_name" config value. And the default value of this for the NimBLE bindings is changed from "PYBD" to "MPY NIMBLE" to be more generic.
Diffstat (limited to 'extmod/modbluetooth.c')
-rw-r--r--extmod/modbluetooth.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c
index 7a3d1ac12..7e6abb549 100644
--- a/extmod/modbluetooth.c
+++ b/extmod/modbluetooth.c
@@ -295,6 +295,11 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
}
switch (mp_obj_str_get_qstr(args[1])) {
+ case MP_QSTR_gap_name: {
+ const uint8_t *buf;
+ size_t len = mp_bluetooth_gap_get_device_name(&buf);
+ return mp_obj_new_bytes(buf, len);
+ }
case MP_QSTR_mac: {
uint8_t addr[6];
mp_bluetooth_get_device_addr(addr);
@@ -315,6 +320,13 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) {
mp_map_elem_t *e = &kwargs->table[i];
switch (mp_obj_str_get_qstr(e->key)) {
+ case MP_QSTR_gap_name: {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(e->value, &bufinfo, MP_BUFFER_READ);
+ int ret = mp_bluetooth_gap_set_device_name(bufinfo.buf, bufinfo.len);
+ bluetooth_handle_errno(ret);
+ break;
+ }
case MP_QSTR_rxbuf: {
// Determine new buffer sizes
mp_int_t ringbuf_alloc = mp_obj_get_int(e->value);