1 /* USER CODE BEGIN Header */
2 /**
3   ******************************************************************************
4   * @file    dtm_preprocess_events.c
5   * @author  GPM WBL Application Team
6   * @brief   File containing hooks for network processor mode.
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2024 STMicroelectronics.
11   * All rights reserved.
12   *
13   * This software is licensed under terms that can be found in the LICENSE file
14   * in the root directory of this software component.
15   * If no LICENSE file comes with this software, it is provided AS-IS.
16   *
17   ******************************************************************************
18   */
19 /* USER CODE END Header */
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include "dtm_preprocess_events.h"
23 #include "ble.h"
24 
25 int hci_disconnection_complete_event_process(uint8_t *buffer_in);
26 int aci_hal_adv_scan_resp_data_update_event_process(uint8_t *buffer_in);
27 int aci_hal_pawr_data_free_event_process(uint8_t *buffer_in);
28 int aci_l2cap_cos_disconnection_complete_event_process(uint8_t *buffer_in);
29 int aci_l2cap_cos_connection_event_process(uint8_t *buffer_in);
30 int aci_l2cap_cos_sdu_data_rx_event_process(uint8_t *buffer_in);
31 int aci_gatt_srv_attribute_modified_event_process(uint8_t *buffer_in);
32 int aci_gatt_clt_notification_event_process(uint8_t *buffer_in);
33 int aci_gatt_clt_proc_complete_event_process(uint8_t *buffer_in);
34 int aci_gatt_tx_pool_available_event_process(uint8_t *buffer_in);
35 int aci_gatt_srv_read_event_process(uint8_t *buffer_in);
36 int aci_gatt_srv_write_event_process(uint8_t *buffer_in);
37 int aci_att_srv_prepare_write_req_event_process(uint8_t *buffer_in);
38 
39 const hci_events_table_type hci_events_table[] = {
40 #if (BLESTACK_CONTROLLER_ONLY == 0)
41   {HCI_DISCONNECTION_COMPLETE_EVT_CODE, hci_disconnection_complete_event_process},
42 #endif /* (BLESTACK_CONTROLLER_ONLY == 0) */
43   {0,NULL},
44 };
45 const hci_le_meta_events_table_type hci_le_meta_events_table[] = {
46   {0,NULL},
47 };
48 const hci_vendor_specific_events_table_type hci_vendor_specific_events_table[] = {
49   {ACI_HAL_ADV_SCAN_RESP_DATA_UPDATE_VSEVT_CODE, aci_hal_adv_scan_resp_data_update_event_process},
50 #if (CFG_BLE_CONTROLLER_PERIODIC_ADV_WR_ENABLED == 1)
51   {ACI_HAL_PAWR_DATA_FREE_VSEVT_CODE, aci_hal_pawr_data_free_event_process},
52 #endif /* (CFG_BLE_CONTROLLER_PERIODIC_ADV_WR_ENABLED == 1) */
53 #if (BLESTACK_CONTROLLER_ONLY == 0)
54 #if (CFG_BLE_L2CAP_COS_ENABLED == 1)
55   {ACI_L2CAP_COS_DISCONNECTION_COMPLETE_VSEVT_CODE, aci_l2cap_cos_disconnection_complete_event_process},
56   {ACI_L2CAP_COS_SDU_DATA_RX_VSEVT_CODE, aci_l2cap_cos_sdu_data_rx_event_process},
57 #endif /* (CFG_BLE_L2CAP_COS_ENABLED == 1) */
58 #if (CFG_BLE_CONNECTION_ENABLED == 1)
59   {ACI_GATT_SRV_ATTRIBUTE_MODIFIED_VSEVT_CODE, aci_gatt_srv_attribute_modified_event_process},
60   {ACI_GATT_CLT_NOTIFICATION_VSEVT_CODE, aci_gatt_clt_notification_event_process},
61   {ACI_GATT_CLT_PROC_COMPLETE_VSEVT_CODE, aci_gatt_clt_proc_complete_event_process},
62   {ACI_GATT_TX_POOL_AVAILABLE_VSEVT_CODE, aci_gatt_tx_pool_available_event_process},
63   {ACI_GATT_SRV_READ_VSEVT_CODE, aci_gatt_srv_read_event_process},
64   {ACI_GATT_SRV_WRITE_VSEVT_CODE, aci_gatt_srv_write_event_process},
65   {ACI_ATT_SRV_PREPARE_WRITE_REQ_VSEVT_CODE, aci_att_srv_prepare_write_req_event_process},
66 #endif /* (CFG_BLE_CONNECTION_ENABLED == 1) */
67 #endif /* (BLESTACK_CONTROLLER_ONLY == 0) */
68   {0,NULL},
69 };
70 
hci_disconnection_complete_event_process(uint8_t * buffer_in)71 int hci_disconnection_complete_event_process(uint8_t *buffer_in)
72 {
73   tBleStatus ret;
74   /* Input params */
75   hci_disconnection_complete_event_rp0 *evt = (hci_disconnection_complete_event_rp0 *)buffer_in;
76 
77   ret = hci_disconnection_complete_event_preprocess(evt->Status,
78                                                     evt->Connection_Handle,
79                                                     evt->Reason);
80 
81   return ret;
82 }
83 
aci_hal_adv_scan_resp_data_update_event_process(uint8_t * buffer_in)84 int aci_hal_adv_scan_resp_data_update_event_process(uint8_t *buffer_in)
85 {
86   int ret;
87   /* Input params */
88   aci_hal_adv_scan_resp_data_update_event_rp0 *evt = (aci_hal_adv_scan_resp_data_update_event_rp0 *)buffer_in;
89 
90   ret = aci_hal_adv_scan_resp_data_update_event_preprocess(evt->Old_Pointer, evt->New_Pointer);
91 
92   return ret;
93 }
94 
95 #if (CFG_BLE_CONTROLLER_PERIODIC_ADV_WR_ENABLED == 1)
96 
aci_hal_pawr_data_free_event_process(uint8_t * buffer_in)97 int aci_hal_pawr_data_free_event_process(uint8_t *buffer_in)
98 {
99   int ret = 0;
100 
101   /* Input params */
102   aci_hal_pawr_data_free_event_rp0 *evt = (aci_hal_pawr_data_free_event_rp0 *)buffer_in;
103   ret = aci_hal_pawr_data_free_event_preprocess(evt->Buffer, evt->Type);
104 
105   return ret;
106 }
107 
108 #endif /* (CFG_BLE_CONTROLLER_PERIODIC_ADV_WR_ENABLED == 1) */
109 
110 #if (BLESTACK_CONTROLLER_ONLY == 0)
111 #if (CFG_BLE_L2CAP_COS_ENABLED == 1)
112 
aci_l2cap_cos_disconnection_complete_event_process(uint8_t * buffer_in)113 int aci_l2cap_cos_disconnection_complete_event_process(uint8_t *buffer_in)
114 {
115   int ret;
116   /* Input params */
117   aci_l2cap_cos_disconnection_complete_event_rp0 *evt = (aci_l2cap_cos_disconnection_complete_event_rp0 *)buffer_in;
118   ret = aci_l2cap_cos_disconnection_complete_event_preprocess(evt->Connection_Handle,
119                                                           evt->CID);
120 
121   return ret;
122 }
123 
aci_l2cap_cos_sdu_data_rx_event_process(uint8_t * buffer_in)124 int aci_l2cap_cos_sdu_data_rx_event_process(uint8_t *buffer_in)
125 {
126   int ret;
127 
128   aci_l2cap_cos_sdu_data_rx_event_rp0 *evt = (aci_l2cap_cos_sdu_data_rx_event_rp0 *)buffer_in;
129 
130   ret = aci_l2cap_cos_sdu_data_rx_event_preprocess(evt->Connection_Handle,
131                                                    evt->CID,
132                                                    evt->RX_Credit_Balance,
133                                                    evt->SDU_Length);
134 
135   return ret;
136 }
137 
138 #endif /* (CFG_BLE_L2CAP_COS_ENABLED == 1) */
139 
140 #if (CFG_BLE_CONNECTION_ENABLED == 1)
141 
aci_gatt_tx_pool_available_event_process(uint8_t * buffer_in)142 int aci_gatt_tx_pool_available_event_process(uint8_t *buffer_in)
143 {
144   int ret;
145 
146   aci_gatt_tx_pool_available_event_rp0 *evt = (aci_gatt_tx_pool_available_event_rp0 *)buffer_in;
147   ret = aci_gatt_tx_pool_available_event_preprocess(evt->Connection_Handle,
148                                                     evt->Available_Buffers);
149 
150   return ret;
151 }
152 
aci_gatt_srv_attribute_modified_event_process(uint8_t * buffer_in)153 int aci_gatt_srv_attribute_modified_event_process(uint8_t *buffer_in)
154 {
155   int ret;
156 
157   aci_gatt_srv_attribute_modified_event_rp0 *evt = (aci_gatt_srv_attribute_modified_event_rp0 *)buffer_in;
158   ret = aci_gatt_srv_attribute_modified_event_preprocess(evt->Connection_Handle,
159                                                          evt->CID,
160                                                          evt->Attr_Handle,
161                                                          evt->Attr_Data_Length,
162                                                          evt->Attr_Data);
163 
164   return ret;
165 }
166 
aci_gatt_clt_notification_event_process(uint8_t * buffer_in)167 int aci_gatt_clt_notification_event_process(uint8_t *buffer_in)
168 {
169   int ret;
170   /* Input params */
171   aci_gatt_clt_notification_event_rp0 *evt = (aci_gatt_clt_notification_event_rp0 *)buffer_in;
172   ret = aci_gatt_clt_notification_event_preprocess(evt->Connection_Handle,
173                                                    evt->CID,
174                                                    evt->Attribute_Handle,
175                                                    evt->Attribute_Value_Length,
176                                                    evt->Attribute_Value);
177 
178   return ret;
179 }
180 
aci_gatt_clt_proc_complete_event_process(uint8_t * buffer_in)181 int aci_gatt_clt_proc_complete_event_process(uint8_t *buffer_in)
182 {
183   tBleStatus ret;
184   /* Input params */
185   aci_gatt_clt_proc_complete_event_rp0 *evt = (aci_gatt_clt_proc_complete_event_rp0 *)buffer_in;
186   ret = aci_gatt_clt_proc_complete_event_preprocess(evt->Connection_Handle,
187                                                     evt->CID,
188                                                     evt->Error_Code);
189 
190   return ret;
191 }
192 
aci_gatt_srv_read_event_process(uint8_t * buffer_in)193 int aci_gatt_srv_read_event_process(uint8_t *buffer_in)
194 {
195   int ret;
196 
197   aci_gatt_srv_read_event_rp0 *evt = (aci_gatt_srv_read_event_rp0 *)buffer_in;
198   ret = aci_gatt_srv_read_event_preprocess(evt->Connection_Handle, evt->CID, evt->Attribute_Handle, evt->Data_Offset);
199 
200   return ret;
201 }
202 
aci_gatt_srv_write_event_process(uint8_t * buffer_in)203 int aci_gatt_srv_write_event_process(uint8_t *buffer_in)
204 {
205   int ret;
206 
207   aci_gatt_srv_write_event_rp0 *evt = (aci_gatt_srv_write_event_rp0 *)buffer_in;
208   ret = aci_gatt_srv_write_event_preprocess(evt->Connection_Handle, evt->CID, evt->Resp_Needed,
209                                             evt->Attribute_Handle, evt->Data_Length, evt->Data);
210 
211   return ret;
212 }
213 
aci_att_srv_prepare_write_req_event_process(uint8_t * buffer_in)214 int aci_att_srv_prepare_write_req_event_process(uint8_t *buffer_in)
215 {
216   int ret = 0;
217 
218   /* Input params */
219   aci_att_srv_prepare_write_req_event_rp0 *evt = (aci_att_srv_prepare_write_req_event_rp0 *)buffer_in;
220   ret = aci_att_srv_prepare_write_req_event_preprocess(evt->Connection_Handle, evt->CID, evt->Attribute_Handle,
221                                                        evt->Data_Offset, evt->Data_Length, evt->Data);
222   return ret;
223 }
224 
225 #endif /* (CFG_BLE_CONNECTION_ENABLED == 1) */
226 
227 #endif /* (BLESTACK_CONTROLLER_ONLY == 0) */
228