From 92227700ccdf0e712a01dd3d9731ef546ea73bae Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 24 Jan 2021 23:57:25 +0100 Subject: [PATCH] feat(mp-ble): Allow to set/get device name --- epicardium/ble/epic_ble_api.c | 12 ++++++++++++ epicardium/epicardium.h | 4 ++++ pycardium/modules/modbluetooth_card10.c | 8 ++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/epicardium/ble/epic_ble_api.c b/epicardium/ble/epic_ble_api.c index 910bc8ad7..b37ca2aa8 100644 --- a/epicardium/ble/epic_ble_api.c +++ b/epicardium/ble/epic_ble_api.c @@ -5,6 +5,7 @@ #include "api/interrupt-sender.h" #include "wsf_buf.h" +#include "svc_core.h" #include "FreeRTOS.h" #include "queue.h" @@ -90,3 +91,14 @@ void ble_epic_dm_api_event(dmEvt_t *dm_event) LOG_WARN("ble", "could not allocate dm event"); } } + +int epic_ble_set_device_name(const uint8_t *buf, uint16_t len) +{ + return epic_ble_atts_set_attr(GAP_DN_HDL, buf, len); +} + +int epic_ble_get_device_name(uint8_t **buf, uint16_t *len) +{ + uint8_t ret = AttsGetAttr(GAP_DN_HDL, len, buf); + return ret; +} diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 78c1de9f8..12f7b86fb 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -177,6 +177,8 @@ typedef _Bool bool; #define API_BLE_GET_ATT_WRITE 0x1BD #define API_BLE_FREE_ATT_WRITE 0x1BE #define API_BLE_ATTS_DYN_ADD_CHARACTERISTIC 0x1BF +#define API_BLE_SET_DEVICE_NAME 0x172 +#define API_BLE_GET_DEVICE_NAME 0x173 #define API_BLE_GET_ADDRESS 0x174 /* clang-format on */ @@ -2606,6 +2608,8 @@ API(API_BLE_ATTS_SET_BUFFER, int epic_ble_atts_set_buffer(uint16_t value_handle, API(API_BLE_FREE_EVENT, int epic_ble_free_event(struct epic_ble_event *e)); +API(API_BLE_SET_DEVICE_NAME, int epic_ble_set_device_name(const uint8_t *buf, uint16_t len)); +API(API_BLE_GET_DEVICE_NAME, int epic_ble_get_device_name(uint8_t **buf, uint16_t *len)); API(API_BLE_GET_ADDRESS, void epic_ble_get_address(uint8_t *addr)); #endif /* _EPICARDIUM_H */ diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c index cbebefcec..f64eab4cb 100644 --- a/pycardium/modules/modbluetooth_card10.c +++ b/pycardium/modules/modbluetooth_card10.c @@ -332,14 +332,14 @@ void mp_bluetooth_get_device_addr(uint8_t *addr) size_t mp_bluetooth_gap_get_device_name(const uint8_t **buf) { - raise(); - return 0; + uint16_t len; + epic_ble_get_device_name((uint8_t **)buf, &len); + return len; } int mp_bluetooth_gap_set_device_name(const uint8_t *buf, size_t len) { - raise(); - return 0; + return epic_ble_set_device_name(buf, len); } // Start advertisement. Will re-start advertisement when already enabled. -- GitLab