aboutsummaryrefslogtreecommitdiff
path: root/src/ble/profile/legacy.c
diff options
context:
space:
mode:
authorDien-Nhung Nguyen-Phu <kein@kienlab.com>2024-06-23 19:22:20 +0700
committerDien-Nhung Nguyen-Phu <kein@kienlab.com>2024-06-23 19:33:13 +0700
commit8274cab154f198447f12028e1686bbe2a6de6ebd (patch)
tree35c825b6551afad7688813d7de510111a67bf007 /src/ble/profile/legacy.c
parent2383bf65e5f3ee9bc58877905dd29eed2e194d19 (diff)
feat: add initial Bluetooth LE module
Diffstat (limited to 'src/ble/profile/legacy.c')
-rw-r--r--src/ble/profile/legacy.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/ble/profile/legacy.c b/src/ble/profile/legacy.c
new file mode 100644
index 0000000..fc775e5
--- /dev/null
+++ b/src/ble/profile/legacy.c
@@ -0,0 +1,51 @@
+#include "utils.h"
+
+static const uint16_t ServiceUUID = 0xFEE0;
+static const gattAttrType_t service = {2, (uint8_t *)&ServiceUUID};
+
+static const uint16_t RxCharUUID = 0xFEE1;
+static uint8 RxCharProps = GATT_PROP_WRITE;
+static uint8 RxCharVal[16];
+
+static gattAttribute_t attr_table[] = {
+ ATTR_DECLAR(primaryServiceUUID, 2, GATT_PERMIT_READ, &service),
+
+ CHAR_DECLAR(&RxCharProps),
+ CHAR_VAL_DECLAR(&RxCharUUID, 2, GATT_PERMIT_WRITE, RxCharVal),
+};
+
+static bStatus_t receive(uint8_t *val, uint16_t len)
+{
+ /* TODO: implement data receiving here*/
+}
+
+static bStatus_t write_handler(uint16 connHandle, gattAttribute_t *pAttr,
+ uint8 *pValue, uint16 len, uint16 offset, uint8 method)
+{
+ if(gattPermitAuthorWrite(pAttr->permissions)) {
+ return ATT_ERR_INSUFFICIENT_AUTHOR;
+ }
+
+ uint16_t uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
+ if(uuid == RxCharUUID) {
+ return receive(pValue, len);
+ }
+ return ATT_ERR_ATTR_NOT_FOUND;
+}
+
+gattServiceCBs_t service_handlers = {
+ NULL,
+ write_handler,
+ NULL
+};
+
+int legacy_registerService()
+{
+ uint8 status = SUCCESS;
+
+ status = GATTServApp_RegisterService(attr_table,
+ GATT_NUM_ATTRS(attr_table),
+ GATT_MAX_ENCRYPT_KEY_SIZE,
+ &service_handlers);
+ return (status);
+} \ No newline at end of file