summaryrefslogtreecommitdiff
path: root/extmod/modbluetooth.h
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-11-24 23:04:58 +1100
committerDamien George <damien@micropython.org>2020-12-02 14:37:55 +1100
commit60830bcba46dd649e396b605708274a2208c398d (patch)
tree3c12aeb7b65d029bada56078e50ead286972d8e3 /extmod/modbluetooth.h
parent89553997b8496aca96b46274c81fa6413d58f6bd (diff)
extmod/modbluetooth: Allow user-specified reason in read request IRQ.
Instead of returning None/bool from the IRQ, return None/int (where a zero value means success). This mirrors how the L2CAP_ACCEPT return value works. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'extmod/modbluetooth.h')
-rw-r--r--extmod/modbluetooth.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/extmod/modbluetooth.h b/extmod/modbluetooth.h
index 0d4296626..9856d4a68 100644
--- a/extmod/modbluetooth.h
+++ b/extmod/modbluetooth.h
@@ -94,6 +94,14 @@
#define MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_AUTHENTICATED (0x2000)
#define MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_AUTHORIZED (0x4000)
+// Return values from _IRQ_GATTS_READ_REQUEST.
+#define MP_BLUETOOTH_GATTS_NO_ERROR (0x00)
+#define MP_BLUETOOTH_GATTS_ERROR_READ_NOT_PERMITTED (0x02)
+#define MP_BLUETOOTH_GATTS_ERROR_WRITE_NOT_PERMITTED (0x03)
+#define MP_BLUETOOTH_GATTS_ERROR_INSUFFICIENT_AUTHENTICATION (0x05)
+#define MP_BLUETOOTH_GATTS_ERROR_INSUFFICIENT_AUTHORIZATION (0x08)
+#define MP_BLUETOOTH_GATTS_ERROR_INSUFFICIENT_ENCRYPTION (0x0f)
+
// For mp_bluetooth_gattc_write, the mode parameter
#define MP_BLUETOOTH_WRITE_MODE_NO_RESPONSE (0)
#define MP_BLUETOOTH_WRITE_MODE_WITH_RESPONSE (1)
@@ -185,6 +193,13 @@ _FLAG_READ_AUTHORIZED = const(0x0800)
_FLAG_WRITE_ENCRYPTED = const(0x1000)
_FLAG_WRITE_AUTHENTICATED = const(0x2000)
_FLAG_WRITE_AUTHORIZED = const(0x4000)
+
+_GATTS_NO_ERROR = const(0x00)
+_GATTS_ERROR_READ_NOT_PERMITTED = const(0x02)
+_GATTS_ERROR_WRITE_NOT_PERMITTED = const(0x03)
+_GATTS_ERROR_INSUFFICIENT_AUTHENTICATION = const(0x05)
+_GATTS_ERROR_INSUFFICIENT_AUTHORIZATION = const(0x08)
+_GATTS_ERROR_INSUFFICIENT_ENCRYPTION = const(0x0f)
*/
// bluetooth.UUID type.
@@ -324,8 +339,9 @@ void mp_bluetooth_gatts_on_write(uint16_t conn_handle, uint16_t value_handle);
// Call this when an acknowledgment is received for an indication.
void mp_bluetooth_gatts_on_indicate_complete(uint16_t conn_handle, uint16_t value_handle, uint8_t status);
-// Call this when a characteristic is read from. Return false to deny the read.
-bool mp_bluetooth_gatts_on_read_request(uint16_t conn_handle, uint16_t value_handle);
+// Call this when a characteristic is read from (giving the handler a chance to update the stored value).
+// Return 0 to allow the read, otherwise a non-zero rejection reason (see MP_BLUETOOTH_GATTS_ERROR_*).
+mp_int_t mp_bluetooth_gatts_on_read_request(uint16_t conn_handle, uint16_t value_handle);
// Call this when an MTU exchange completes.
void mp_bluetooth_gatts_on_mtu_exchanged(uint16_t conn_handle, uint16_t value);