diff options
| author | Anson Bridges <bridges.anson@gmail.com> | 2026-02-17 11:37:50 -0800 |
|---|---|---|
| committer | Anson Bridges <bridges.anson@gmail.com> | 2026-02-17 11:37:50 -0800 |
| commit | fb1611c0ca99d9e609057c46507be2af8389bb7b (patch) | |
| tree | 646ac568fdad1e6cf9e1f5767295b183bc5c5441 /firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src | |
| parent | 6e952fe110c2a48204c8cb0a836309ab97e5979a (diff) | |
Diffstat (limited to 'firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src')
3 files changed, 679 insertions, 0 deletions
diff --git a/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/common_blesvc.h b/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/common_blesvc.h new file mode 100644 index 0000000..2cf1552 --- /dev/null +++ b/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/common_blesvc.h @@ -0,0 +1,54 @@ + +/** + ****************************************************************************** + * @file common_blesvc.h + * @author MCD Application Team + * @brief Header for ble modules + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __COMMON_BLESVC_H +#define __COMMON_BLESVC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "ble_common.h" +#include "ble.h" +#include "dbg_trace.h" + + + +/* Exported types ------------------------------------------------------------*/ +typedef enum +{ + COMSVC_Notification = ( 1 << 0 ), + COMSVC_Indication = ( 1 << 1 ), +} COMSVC_ClientCharConfMask_t; + +/* Exported constants --------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ + + +#ifdef __cplusplus +} +#endif + +#endif /*__COMMON_BLESVC_H */ + + diff --git a/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/p2p_stm.c b/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/p2p_stm.c new file mode 100644 index 0000000..15ec975 --- /dev/null +++ b/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/p2p_stm.c @@ -0,0 +1,295 @@ +/** + ****************************************************************************** + * @file p2p_stm.c + * @author MCD Application Team + * @brief Peer to Peer Service (Custom STM) + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "common_blesvc.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef struct{ + uint16_t PeerToPeerSvcHdle; /**< Service handle */ + uint16_t P2PWriteClientToServerCharHdle; /**< Characteristic handle */ + uint16_t P2PNotifyServerToClientCharHdle; /**< Characteristic handle */ +#if(BLE_CFG_OTA_REBOOT_CHAR != 0) + uint16_t RebootReqCharHdle; /**< Characteristic handle */ +#endif +}PeerToPeerContext_t; + +/* Private defines -----------------------------------------------------------*/ +#define UUID_128_SUPPORTED 1 + +#if (UUID_128_SUPPORTED == 1) +#define BM_UUID_LENGTH UUID_TYPE_128 +#else +#define BM_UUID_LENGTH UUID_TYPE_16 +#endif + +#define BM_REQ_CHAR_SIZE (3) + + +/* Private macros ------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ +/** + * Reboot Characteristic UUID + * 0000fe11-8e22-4541-9d4c-21edae82ed19 + */ +#if(BLE_CFG_OTA_REBOOT_CHAR != 0) +#if (UUID_128_SUPPORTED == 1) +static const uint8_t BM_REQ_CHAR_UUID[16] = {0x19, 0xed, 0x82, 0xae, + 0xed, 0x21, 0x4c, 0x9d, + 0x41, 0x45, 0x22, 0x8e, + 0x11, 0xFE, 0x00, 0x00}; +#else +static const uint8_t BM_REQ_CHAR_UUID[2] = {0x11, 0xFE}; +#endif +#endif + +/** + * START of Section BLE_DRIVER_CONTEXT + */ +PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static PeerToPeerContext_t aPeerToPeerContext; + +/** + * END of Section BLE_DRIVER_CONTEXT + */ +/* Private function prototypes -----------------------------------------------*/ +static SVCCTL_EvtAckStatus_t PeerToPeer_Event_Handler(void *Event); + + +/* Functions Definition ------------------------------------------------------*/ +/* Private functions ----------------------------------------------------------*/ + +#define COPY_UUID_128(uuid_struct, uuid_15, uuid_14, uuid_13, uuid_12, uuid_11, uuid_10, uuid_9, uuid_8, uuid_7, uuid_6, uuid_5, uuid_4, uuid_3, uuid_2, uuid_1, uuid_0) \ +do {\ + uuid_struct[0] = uuid_0; uuid_struct[1] = uuid_1; uuid_struct[2] = uuid_2; uuid_struct[3] = uuid_3; \ + uuid_struct[4] = uuid_4; uuid_struct[5] = uuid_5; uuid_struct[6] = uuid_6; uuid_struct[7] = uuid_7; \ + uuid_struct[8] = uuid_8; uuid_struct[9] = uuid_9; uuid_struct[10] = uuid_10; uuid_struct[11] = uuid_11; \ + uuid_struct[12] = uuid_12; uuid_struct[13] = uuid_13; uuid_struct[14] = uuid_14; uuid_struct[15] = uuid_15; \ +}while(0) + +/* Hardware Characteristics Service */ +/* + The following 128bits UUIDs have been generated from the random UUID + generator: + D973F2E0-B19E-11E2-9E96-0800200C9A66: Service 128bits UUID + D973F2E1-B19E-11E2-9E96-0800200C9A66: Characteristic_1 128bits UUID + D973F2E2-B19E-11E2-9E96-0800200C9A66: Characteristic_2 128bits UUID + */ +#define COPY_P2P_SERVICE_UUID(uuid_struct) COPY_UUID_128(uuid_struct,0x00,0x00,0xfe,0x40,0xcc,0x7a,0x48,0x2a,0x98,0x4a,0x7f,0x2e,0xd5,0xb3,0xe5,0x8f) +#define COPY_P2P_WRITE_CHAR_UUID(uuid_struct) COPY_UUID_128(uuid_struct,0x00,0x00,0xfe,0x41,0x8e,0x22,0x45,0x41,0x9d,0x4c,0x21,0xed,0xae,0x82,0xed,0x19) +#define COPY_P2P_NOTIFY_UUID(uuid_struct) COPY_UUID_128(uuid_struct,0x00,0x00,0xfe,0x42,0x8e,0x22,0x45,0x41,0x9d,0x4c,0x21,0xed,0xae,0x82,0xed,0x19) + + + +/** + * @brief Event handler + * @param Event: Address of the buffer holding the Event + * @retval Ack: Return whether the Event has been managed or not + */ +static SVCCTL_EvtAckStatus_t PeerToPeer_Event_Handler(void *Event) +{ + SVCCTL_EvtAckStatus_t return_value; + hci_event_pckt *event_pckt; + evt_blecore_aci *blecore_evt; + aci_gatt_attribute_modified_event_rp0 * attribute_modified; + P2PS_STM_App_Notification_evt_t Notification; + + return_value = SVCCTL_EvtNotAck; + event_pckt = (hci_event_pckt *)(((hci_uart_pckt*)Event)->data); + + switch(event_pckt->evt) + { + case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE: + { + blecore_evt = (evt_blecore_aci*)event_pckt->data; + switch(blecore_evt->ecode) + { + case ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE: + { + attribute_modified = (aci_gatt_attribute_modified_event_rp0*)blecore_evt->data; + if(attribute_modified->Attr_Handle == (aPeerToPeerContext.P2PNotifyServerToClientCharHdle + 2)) + { + /** + * Descriptor handle + */ + return_value = SVCCTL_EvtAckFlowEnable; + /** + * Notify to application + */ + if(attribute_modified->Attr_Data[0] & COMSVC_Notification) + { + Notification.P2P_Evt_Opcode = P2PS_STM__NOTIFY_ENABLED_EVT; + P2PS_STM_App_Notification(&Notification); + } + else + { + Notification.P2P_Evt_Opcode = P2PS_STM_NOTIFY_DISABLED_EVT; + P2PS_STM_App_Notification(&Notification); + } + } + + else if(attribute_modified->Attr_Handle == (aPeerToPeerContext.P2PWriteClientToServerCharHdle + 1)) + { + BLE_DBG_P2P_STM_MSG("-- GATT : LED CONFIGURATION RECEIVED\n"); + Notification.P2P_Evt_Opcode = P2PS_STM_WRITE_EVT; + Notification.DataTransfered.Length=attribute_modified->Attr_Data_Length; + Notification.DataTransfered.pPayload=attribute_modified->Attr_Data; + P2PS_STM_App_Notification(&Notification); + } +#if(BLE_CFG_OTA_REBOOT_CHAR != 0) + else if(attribute_modified->Attr_Handle == (aPeerToPeerContext.RebootReqCharHdle + 1)) + { + BLE_DBG_P2P_STM_MSG("-- GATT : REBOOT REQUEST RECEIVED\n"); + Notification.P2P_Evt_Opcode = P2PS_STM_BOOT_REQUEST_EVT; + Notification.DataTransfered.Length=attribute_modified->Attr_Data_Length; + Notification.DataTransfered.pPayload=attribute_modified->Attr_Data; + P2PS_STM_App_Notification(&Notification); + } +#endif + } + break; + + default: + break; + } + } + break; /* HCI_HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE_SPECIFIC */ + + default: + break; + } + + return(return_value); +}/* end SVCCTL_EvtAckStatus_t */ + + +/* Public functions ----------------------------------------------------------*/ + +/** + * @brief Service initialization + * @param None + * @retval None + */ +void P2PS_STM_Init(void) +{ + + Char_UUID_t uuid16; + + /** + * Register the event handler to the BLE controller + */ + SVCCTL_RegisterSvcHandler(PeerToPeer_Event_Handler); + + /** + * Peer To Peer Service + * + * Max_Attribute_Records = 2*no_of_char + 1 + * service_max_attribute_record = 1 for Peer To Peer service + + * 2 for P2P Write characteristic + + * 2 for P2P Notify characteristic + + * 1 for client char configuration descriptor + + * + */ + COPY_P2P_SERVICE_UUID(uuid16.Char_UUID_128); + aci_gatt_add_service(UUID_TYPE_128, + (Service_UUID_t *) &uuid16, + PRIMARY_SERVICE, +#if (BLE_CFG_OTA_REBOOT_CHAR != 0) + 2+ +#endif + 6, + &(aPeerToPeerContext.PeerToPeerSvcHdle)); + + /** + * Add LED Characteristic + */ + COPY_P2P_WRITE_CHAR_UUID(uuid16.Char_UUID_128); + aci_gatt_add_char(aPeerToPeerContext.PeerToPeerSvcHdle, + UUID_TYPE_128, &uuid16, + 2, + CHAR_PROP_WRITE_WITHOUT_RESP|CHAR_PROP_READ, + ATTR_PERMISSION_NONE, + GATT_NOTIFY_ATTRIBUTE_WRITE, /* gattEvtMask */ + 10, /* encryKeySize */ + 1, /* isVariable */ + &(aPeerToPeerContext.P2PWriteClientToServerCharHdle)); + + /** + * Add Button Characteristic + */ + COPY_P2P_NOTIFY_UUID(uuid16.Char_UUID_128); + aci_gatt_add_char(aPeerToPeerContext.PeerToPeerSvcHdle, + UUID_TYPE_128, &uuid16, + 2, + CHAR_PROP_NOTIFY, + ATTR_PERMISSION_NONE, + GATT_NOTIFY_ATTRIBUTE_WRITE, /* gattEvtMask */ + 10, /* encryKeySize */ + 1, /* isVariable: 1 */ + &(aPeerToPeerContext.P2PNotifyServerToClientCharHdle)); + +#if(BLE_CFG_OTA_REBOOT_CHAR != 0) + /** + * Add Boot Request Characteristic + */ + aci_gatt_add_char(aPeerToPeerContext.PeerToPeerSvcHdle, + BM_UUID_LENGTH, + (Char_UUID_t *)BM_REQ_CHAR_UUID, + BM_REQ_CHAR_SIZE, + CHAR_PROP_WRITE_WITHOUT_RESP, + ATTR_PERMISSION_NONE, + GATT_NOTIFY_ATTRIBUTE_WRITE, + 10, + 0, + &(aPeerToPeerContext.RebootReqCharHdle)); +#endif + + + return; +} + +/** + * @brief Characteristic update + * @param UUID: UUID of the characteristic + * @param Service_Instance: Instance of the service to which the characteristic belongs + * + */ +tBleStatus P2PS_STM_App_Update_Char(uint16_t UUID, uint8_t *pPayload) +{ + tBleStatus result = BLE_STATUS_INVALID_PARAMS; + switch(UUID) + { + case P2P_NOTIFY_CHAR_UUID: + + result = aci_gatt_update_char_value(aPeerToPeerContext.PeerToPeerSvcHdle, + aPeerToPeerContext.P2PNotifyServerToClientCharHdle, + 0, /* charValOffset */ + 2, /* charValueLen */ + (uint8_t *) pPayload); + + break; + + default: + break; + } + + return result; +}/* end P2PS_STM_Init() */ + + diff --git a/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/svc_ctl.c b/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/svc_ctl.c new file mode 100644 index 0000000..bde8a37 --- /dev/null +++ b/firmware/memory_chip_gone/Middlewares/ST/STM32_WPAN/ble/svc/Src/svc_ctl.c @@ -0,0 +1,330 @@ +/** + ****************************************************************************** + * @file svc_ctl.c + * @author MCD Application Team + * @brief BLE Controller + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "common_blesvc.h" +#include "cmsis_compiler.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef struct +{ +#if (BLE_CFG_SVC_MAX_NBR_CB > 0) +SVC_CTL_p_EvtHandler_t SVCCTL__SvcHandlerTab[BLE_CFG_SVC_MAX_NBR_CB]; +#endif +uint8_t NbreOfRegisteredHandler; +} SVCCTL_EvtHandler_t; + +typedef struct +{ +#if (BLE_CFG_CLT_MAX_NBR_CB > 0) +SVC_CTL_p_EvtHandler_t SVCCTL_CltHandlerTable[BLE_CFG_CLT_MAX_NBR_CB]; +#endif +uint8_t NbreOfRegisteredHandler; +} SVCCTL_CltHandler_t; + +/* Private defines -----------------------------------------------------------*/ +#define SVCCTL_EGID_EVT_MASK 0xFF00 +#define SVCCTL_GATT_EVT_TYPE 0x0C00 +#define SVCCTL_GAP_DEVICE_NAME_LENGTH 7 + +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/** + * START of Section BLE_DRIVER_CONTEXT + */ + +PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") SVCCTL_EvtHandler_t SVCCTL_EvtHandler; +PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") SVCCTL_CltHandler_t SVCCTL_CltHandler; + +/** + * END of Section BLE_DRIVER_CONTEXT + */ + +/* Private functions ----------------------------------------------------------*/ +/* Weak functions ----------------------------------------------------------*/ +void BVOPUS_STM_Init(void); + +__WEAK void BAS_Init( void ) +{ + return; +} + +__WEAK void BLS_Init( void ) +{ + return; +} +__WEAK void CRS_STM_Init( void ) +{ + return; +} +__WEAK void DIS_Init( void ) +{ + return; +} +__WEAK void EDS_STM_Init( void ) +{ + return; +} +__WEAK void HIDS_Init( void ) +{ + return; +} +__WEAK void HRS_Init( void ) +{ + return; +} +__WEAK void HTS_Init( void ) +{ + return; +} +__WEAK void IAS_Init( void ) +{ + return; +} +__WEAK void LLS_Init( void ) +{ + return; +} +__WEAK void TPS_Init( void ) +{ + return; +} +__WEAK void MOTENV_STM_Init( void ) +{ + return; +} +__WEAK void P2PS_STM_Init( void ) +{ + return; +} +__WEAK void ZDD_STM_Init( void ) +{ + return; +} +__WEAK void OTAS_STM_Init( void ) +{ + return; +} +__WEAK void MESH_Init( void ) +{ + return; +} +__WEAK void BVOPUS_STM_Init( void ) +{ + return; +} +__WEAK void SVCCTL_InitCustomSvc( void ) +{ + return; +} + +/* Functions Definition ------------------------------------------------------*/ + +void SVCCTL_Init( void ) +{ + + /** + * Initialize the number of registered Handler + */ + SVCCTL_EvtHandler.NbreOfRegisteredHandler = 0; + SVCCTL_CltHandler.NbreOfRegisteredHandler = 0; + + /** + * Add and Initialize requested services + */ + SVCCTL_SvcInit(); + + return; +} + +__WEAK void SVCCTL_SvcInit(void) +{ + BAS_Init(); + + BLS_Init(); + + CRS_STM_Init(); + + DIS_Init(); + + EDS_STM_Init(); + + HIDS_Init(); + + HRS_Init(); + + HTS_Init(); + + IAS_Init(); + + LLS_Init(); + + TPS_Init(); + + MOTENV_STM_Init(); + + P2PS_STM_Init(); + + ZDD_STM_Init(); + + OTAS_STM_Init(); + + BVOPUS_STM_Init(); + + MESH_Init(); + + SVCCTL_InitCustomSvc(); + + return; +} + +/** + * @brief BLE Controller initialization + * @param None + * @retval None + */ +void SVCCTL_RegisterSvcHandler( SVC_CTL_p_EvtHandler_t pfBLE_SVC_Service_Event_Handler ) +{ +#if (BLE_CFG_SVC_MAX_NBR_CB > 0) + SVCCTL_EvtHandler.SVCCTL__SvcHandlerTab[SVCCTL_EvtHandler.NbreOfRegisteredHandler] = pfBLE_SVC_Service_Event_Handler; + SVCCTL_EvtHandler.NbreOfRegisteredHandler++; +#else + (void)(pfBLE_SVC_Service_Event_Handler); +#endif + + return; +} + +/** + * @brief BLE Controller initialization + * @param None + * @retval None + */ +void SVCCTL_RegisterCltHandler( SVC_CTL_p_EvtHandler_t pfBLE_SVC_Client_Event_Handler ) +{ +#if (BLE_CFG_CLT_MAX_NBR_CB > 0) + SVCCTL_CltHandler.SVCCTL_CltHandlerTable[SVCCTL_CltHandler.NbreOfRegisteredHandler] = pfBLE_SVC_Client_Event_Handler; + SVCCTL_CltHandler.NbreOfRegisteredHandler++; +#else + (void)(pfBLE_SVC_Client_Event_Handler); +#endif + + return; +} + +__WEAK SVCCTL_UserEvtFlowStatus_t SVCCTL_UserEvtRx( void *pckt ) +{ + hci_event_pckt *event_pckt; + evt_blecore_aci *blecore_evt; + SVCCTL_EvtAckStatus_t event_notification_status; + SVCCTL_UserEvtFlowStatus_t return_status; + uint8_t index; + + event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data; + event_notification_status = SVCCTL_EvtNotAck; + + switch (event_pckt->evt) + { + case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE: + { + blecore_evt = (evt_blecore_aci*) event_pckt->data; + + switch ((blecore_evt->ecode) & SVCCTL_EGID_EVT_MASK) + { + case SVCCTL_GATT_EVT_TYPE: +#if (BLE_CFG_SVC_MAX_NBR_CB > 0) + /* For Service event handler */ + for (index = 0; index < SVCCTL_EvtHandler.NbreOfRegisteredHandler; index++) + { + event_notification_status = SVCCTL_EvtHandler.SVCCTL__SvcHandlerTab[index](pckt); + /** + * When a GATT event has been acknowledged by a Service, there is no need to call the other registered handlers + * a GATT event is relevant for only one Service + */ + if (event_notification_status != SVCCTL_EvtNotAck) + { + /** + * The event has been managed. The Event processing should be stopped + */ + break; + } + } +#endif +#if (BLE_CFG_CLT_MAX_NBR_CB > 0) + /* For Client event handler */ + event_notification_status = SVCCTL_EvtNotAck; + for(index = 0; index <SVCCTL_CltHandler.NbreOfRegisteredHandler; index++) + { + event_notification_status = SVCCTL_CltHandler.SVCCTL_CltHandlerTable[index](pckt); + /** + * When a GATT event has been acknowledged by a Client, there is no need to call the other registered handlers + * a GATT event is relevant for only one Client + */ + if (event_notification_status != SVCCTL_EvtNotAck) + { + /** + * The event has been managed. The Event processing should be stopped + */ + break; + } + } +#endif + break; + + default: + break; + } + } + break; /* HCI_HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE_SPECIFIC */ + + default: + break; + } + + /** + * When no registered handlers (either Service or Client) has acknowledged the GATT event, it is reported to the application + * a GAP event is always reported to the application. + */ + switch (event_notification_status) + { + case SVCCTL_EvtNotAck: + /** + * The event has NOT been managed. + * It shall be passed to the application for processing + */ + return_status = SVCCTL_App_Notification(pckt); + break; + + case SVCCTL_EvtAckFlowEnable: + return_status = SVCCTL_UserEvtFlowEnable; + break; + + case SVCCTL_EvtAckFlowDisable: + return_status = SVCCTL_UserEvtFlowDisable; + break; + + default: + return_status = SVCCTL_UserEvtFlowEnable; + break; + } + + return (return_status); +} + + |
