xref: /btstack/port/stm32-wb55xx-nucleo-freertos/Middlewares/STM32_WPAN/ble/core/auto/ble_hal_aci.c (revision 0561b2d8d5dba972c7daa57d5e677f7a1327edfd)
1 /******************************************************************************
2  * @file    ble_hal_aci.c
3  * @author  MCD Application Team
4  * @date    23 May 2019
5  * @brief   Source file for ble api STM32WB (hal_aci)
6  *          Auto-generated file: do not edit!
7  ******************************************************************************
8  * @attention
9  *
10  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
11  * All rights reserved.</center></h2>
12  *
13  * This software component is licensed by ST under Ultimate Liberty license
14  * SLA0044, the "License"; You may not use this file except in compliance with
15  * the License. You may obtain a copy of the License at:
16  *                             www.st.com/SLA0044
17  *
18  ******************************************************************************
19  */
20 
21 #include "ble_hal_aci.h"
22 
aci_hal_get_fw_build_number(uint16_t * Build_Number)23 tBleStatus aci_hal_get_fw_build_number(uint16_t *Build_Number)
24 {
25   struct hci_request rq;
26   aci_hal_get_fw_build_number_rp0 resp;
27   Osal_MemSet(&resp, 0, sizeof(resp));
28   Osal_MemSet(&rq, 0, sizeof(rq));
29   rq.ogf = 0x3f;
30   rq.ocf = 0x000;
31   rq.rparam = &resp;
32   rq.rlen = sizeof(resp);
33   if (hci_send_req(&rq, FALSE) < 0)
34     return BLE_STATUS_TIMEOUT;
35   if (resp.Status)
36   {
37     return resp.Status;
38   }
39   *Build_Number = btoh(resp.Build_Number, 2);
40   return BLE_STATUS_SUCCESS;
41 }
42 
aci_hal_write_config_data(uint8_t Offset,uint8_t Length,uint8_t Value[])43 tBleStatus aci_hal_write_config_data(uint8_t Offset,
44                                      uint8_t Length,
45                                      uint8_t Value[])
46 {
47   struct hci_request rq;
48   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
49   aci_hal_write_config_data_cp0 *cp0 = (aci_hal_write_config_data_cp0*)(cmd_buffer);
50   tBleStatus status = 0;
51   int index_input = 0;
52   cp0->Offset = htob(Offset, 1);
53   index_input += 1;
54   cp0->Length = htob(Length, 1);
55   index_input += 1;
56   Osal_MemCpy((void *) &cp0->Value, (const void *) Value, Length);
57   index_input += Length;
58   Osal_MemSet(&rq, 0, sizeof(rq));
59   rq.ogf = 0x3f;
60   rq.ocf = 0x00c;
61   rq.cparam = cmd_buffer;
62   rq.clen = index_input;
63   rq.rparam = &status;
64   rq.rlen = 1;
65   if (hci_send_req(&rq, FALSE) < 0)
66     return BLE_STATUS_TIMEOUT;
67   if (status)
68   {
69     return status;
70   }
71   return BLE_STATUS_SUCCESS;
72 }
73 
aci_hal_read_config_data(uint8_t Offset,uint8_t * Data_Length,uint8_t Data[])74 tBleStatus aci_hal_read_config_data(uint8_t Offset,
75                                     uint8_t *Data_Length,
76                                     uint8_t Data[])
77 {
78   struct hci_request rq;
79   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
80   aci_hal_read_config_data_cp0 *cp0 = (aci_hal_read_config_data_cp0*)(cmd_buffer);
81   aci_hal_read_config_data_rp0 resp;
82   Osal_MemSet(&resp, 0, sizeof(resp));
83   int index_input = 0;
84   cp0->Offset = htob(Offset, 1);
85   index_input += 1;
86   Osal_MemSet(&rq, 0, sizeof(rq));
87   rq.ogf = 0x3f;
88   rq.ocf = 0x00d;
89   rq.cparam = cmd_buffer;
90   rq.clen = index_input;
91   rq.rparam = &resp;
92   rq.rlen = sizeof(resp);
93   if (hci_send_req(&rq, FALSE) < 0)
94     return BLE_STATUS_TIMEOUT;
95   if (resp.Status)
96   {
97     return resp.Status;
98   }
99   *Data_Length = btoh(resp.Data_Length, 1);
100   Osal_MemCpy((void *) Data, (const void *) resp.Data, *Data_Length);
101   return BLE_STATUS_SUCCESS;
102 }
103 
aci_hal_set_tx_power_level(uint8_t En_High_Power,uint8_t PA_Level)104 tBleStatus aci_hal_set_tx_power_level(uint8_t En_High_Power,
105                                       uint8_t PA_Level)
106 {
107   struct hci_request rq;
108   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
109   aci_hal_set_tx_power_level_cp0 *cp0 = (aci_hal_set_tx_power_level_cp0*)(cmd_buffer);
110   tBleStatus status = 0;
111   int index_input = 0;
112   cp0->En_High_Power = htob(En_High_Power, 1);
113   index_input += 1;
114   cp0->PA_Level = htob(PA_Level, 1);
115   index_input += 1;
116   Osal_MemSet(&rq, 0, sizeof(rq));
117   rq.ogf = 0x3f;
118   rq.ocf = 0x00f;
119   rq.cparam = cmd_buffer;
120   rq.clen = index_input;
121   rq.rparam = &status;
122   rq.rlen = 1;
123   if (hci_send_req(&rq, FALSE) < 0)
124     return BLE_STATUS_TIMEOUT;
125   if (status)
126   {
127     return status;
128   }
129   return BLE_STATUS_SUCCESS;
130 }
131 
aci_hal_le_tx_test_packet_number(uint32_t * Number_Of_Packets)132 tBleStatus aci_hal_le_tx_test_packet_number(uint32_t *Number_Of_Packets)
133 {
134   struct hci_request rq;
135   aci_hal_le_tx_test_packet_number_rp0 resp;
136   Osal_MemSet(&resp, 0, sizeof(resp));
137   Osal_MemSet(&rq, 0, sizeof(rq));
138   rq.ogf = 0x3f;
139   rq.ocf = 0x014;
140   rq.rparam = &resp;
141   rq.rlen = sizeof(resp);
142   if (hci_send_req(&rq, FALSE) < 0)
143     return BLE_STATUS_TIMEOUT;
144   if (resp.Status)
145   {
146     return resp.Status;
147   }
148   *Number_Of_Packets = btoh(resp.Number_Of_Packets, 4);
149   return BLE_STATUS_SUCCESS;
150 }
151 
aci_hal_tone_start(uint8_t RF_Channel,uint8_t Freq_offset)152 tBleStatus aci_hal_tone_start(uint8_t RF_Channel,
153                               uint8_t Freq_offset)
154 {
155   struct hci_request rq;
156   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
157   aci_hal_tone_start_cp0 *cp0 = (aci_hal_tone_start_cp0*)(cmd_buffer);
158   tBleStatus status = 0;
159   int index_input = 0;
160   cp0->RF_Channel = htob(RF_Channel, 1);
161   index_input += 1;
162   cp0->Freq_offset = htob(Freq_offset, 1);
163   index_input += 1;
164   Osal_MemSet(&rq, 0, sizeof(rq));
165   rq.ogf = 0x3f;
166   rq.ocf = 0x015;
167   rq.cparam = cmd_buffer;
168   rq.clen = index_input;
169   rq.rparam = &status;
170   rq.rlen = 1;
171   if (hci_send_req(&rq, FALSE) < 0)
172     return BLE_STATUS_TIMEOUT;
173   if (status)
174   {
175     return status;
176   }
177   return BLE_STATUS_SUCCESS;
178 }
179 
aci_hal_tone_stop(void)180 tBleStatus aci_hal_tone_stop(void)
181 {
182   struct hci_request rq;
183   tBleStatus status = 0;
184   Osal_MemSet(&rq, 0, sizeof(rq));
185   rq.ogf = 0x3f;
186   rq.ocf = 0x016;
187   rq.rparam = &status;
188   rq.rlen = 1;
189   if (hci_send_req(&rq, FALSE) < 0)
190     return BLE_STATUS_TIMEOUT;
191   if (status)
192   {
193     return status;
194   }
195   return BLE_STATUS_SUCCESS;
196 }
197 
aci_hal_get_link_status(uint8_t Link_Status[8],uint16_t Link_Connection_Handle[16/2])198 tBleStatus aci_hal_get_link_status(uint8_t Link_Status[8],
199                                    uint16_t Link_Connection_Handle[16 / 2])
200 {
201   struct hci_request rq;
202   aci_hal_get_link_status_rp0 resp;
203   Osal_MemSet(&resp, 0, sizeof(resp));
204   Osal_MemSet(&rq, 0, sizeof(rq));
205   rq.ogf = 0x3f;
206   rq.ocf = 0x017;
207   rq.rparam = &resp;
208   rq.rlen = sizeof(resp);
209   if (hci_send_req(&rq, FALSE) < 0)
210     return BLE_STATUS_TIMEOUT;
211   if (resp.Status)
212   {
213     return resp.Status;
214   }
215   Osal_MemCpy((void *) Link_Status, (const void *) resp.Link_Status, 8);
216   Osal_MemCpy((void *) Link_Connection_Handle, (const void *) resp.Link_Connection_Handle, 16);
217   return BLE_STATUS_SUCCESS;
218 }
219 
aci_hal_set_radio_activity_mask(uint16_t Radio_Activity_Mask)220 tBleStatus aci_hal_set_radio_activity_mask(uint16_t Radio_Activity_Mask)
221 {
222   struct hci_request rq;
223   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
224   aci_hal_set_radio_activity_mask_cp0 *cp0 = (aci_hal_set_radio_activity_mask_cp0*)(cmd_buffer);
225   tBleStatus status = 0;
226   int index_input = 0;
227   cp0->Radio_Activity_Mask = htob(Radio_Activity_Mask, 2);
228   index_input += 2;
229   Osal_MemSet(&rq, 0, sizeof(rq));
230   rq.ogf = 0x3f;
231   rq.ocf = 0x018;
232   rq.cparam = cmd_buffer;
233   rq.clen = index_input;
234   rq.rparam = &status;
235   rq.rlen = 1;
236   if (hci_send_req(&rq, FALSE) < 0)
237     return BLE_STATUS_TIMEOUT;
238   if (status)
239   {
240     return status;
241   }
242   return BLE_STATUS_SUCCESS;
243 }
244 
aci_hal_get_anchor_period(uint32_t * Anchor_Period,uint32_t * Max_Free_Slot)245 tBleStatus aci_hal_get_anchor_period(uint32_t *Anchor_Period,
246                                      uint32_t *Max_Free_Slot)
247 {
248   struct hci_request rq;
249   aci_hal_get_anchor_period_rp0 resp;
250   Osal_MemSet(&resp, 0, sizeof(resp));
251   Osal_MemSet(&rq, 0, sizeof(rq));
252   rq.ogf = 0x3f;
253   rq.ocf = 0x019;
254   rq.rparam = &resp;
255   rq.rlen = sizeof(resp);
256   if (hci_send_req(&rq, FALSE) < 0)
257     return BLE_STATUS_TIMEOUT;
258   if (resp.Status)
259   {
260     return resp.Status;
261   }
262   *Anchor_Period = btoh(resp.Anchor_Period, 4);
263   *Max_Free_Slot = btoh(resp.Max_Free_Slot, 4);
264   return BLE_STATUS_SUCCESS;
265 }
266 
aci_hal_set_event_mask(uint32_t Event_Mask)267 tBleStatus aci_hal_set_event_mask(uint32_t Event_Mask)
268 {
269   struct hci_request rq;
270   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
271   aci_hal_set_event_mask_cp0 *cp0 = (aci_hal_set_event_mask_cp0*)(cmd_buffer);
272   tBleStatus status = 0;
273   int index_input = 0;
274   cp0->Event_Mask = htob(Event_Mask, 4);
275   index_input += 4;
276   Osal_MemSet(&rq, 0, sizeof(rq));
277   rq.ogf = 0x3f;
278   rq.ocf = 0x01a;
279   rq.cparam = cmd_buffer;
280   rq.clen = index_input;
281   rq.rparam = &status;
282   rq.rlen = 1;
283   if (hci_send_req(&rq, FALSE) < 0)
284     return BLE_STATUS_TIMEOUT;
285   if (status)
286   {
287     return status;
288   }
289   return BLE_STATUS_SUCCESS;
290 }
291 
aci_hal_set_smp_eng_config(uint32_t SMP_Config)292 tBleStatus aci_hal_set_smp_eng_config(uint32_t SMP_Config)
293 {
294   struct hci_request rq;
295   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
296   aci_hal_set_smp_eng_config_cp0 *cp0 = (aci_hal_set_smp_eng_config_cp0*)(cmd_buffer);
297   tBleStatus status = 0;
298   int index_input = 0;
299   cp0->SMP_Config = htob(SMP_Config, 4);
300   index_input += 4;
301   Osal_MemSet(&rq, 0, sizeof(rq));
302   rq.ogf = 0x3f;
303   rq.ocf = 0x01b;
304   rq.cparam = cmd_buffer;
305   rq.clen = index_input;
306   rq.rparam = &status;
307   rq.rlen = 1;
308   if (hci_send_req(&rq, FALSE) < 0)
309     return BLE_STATUS_TIMEOUT;
310   if (status)
311   {
312     return status;
313   }
314   return BLE_STATUS_SUCCESS;
315 }
316 
aci_hal_get_pm_debug_info(uint8_t * Allocated_For_TX,uint8_t * Allocated_For_RX,uint8_t * Allocated_MBlocks)317 tBleStatus aci_hal_get_pm_debug_info(uint8_t *Allocated_For_TX,
318                                      uint8_t *Allocated_For_RX,
319                                      uint8_t *Allocated_MBlocks)
320 {
321   struct hci_request rq;
322   aci_hal_get_pm_debug_info_rp0 resp;
323   Osal_MemSet(&resp, 0, sizeof(resp));
324   Osal_MemSet(&rq, 0, sizeof(rq));
325   rq.ogf = 0x3f;
326   rq.ocf = 0x01c;
327   rq.rparam = &resp;
328   rq.rlen = sizeof(resp);
329   if (hci_send_req(&rq, FALSE) < 0)
330     return BLE_STATUS_TIMEOUT;
331   if (resp.Status)
332   {
333     return resp.Status;
334   }
335   *Allocated_For_TX = btoh(resp.Allocated_For_TX, 1);
336   *Allocated_For_RX = btoh(resp.Allocated_For_RX, 1);
337   *Allocated_MBlocks = btoh(resp.Allocated_MBlocks, 1);
338   return BLE_STATUS_SUCCESS;
339 }
340 
aci_hal_read_radio_reg(uint8_t Register_Address,uint8_t * reg_val)341 tBleStatus aci_hal_read_radio_reg(uint8_t Register_Address,
342                                   uint8_t *reg_val)
343 {
344   struct hci_request rq;
345   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
346   aci_hal_read_radio_reg_cp0 *cp0 = (aci_hal_read_radio_reg_cp0*)(cmd_buffer);
347   aci_hal_read_radio_reg_rp0 resp;
348   Osal_MemSet(&resp, 0, sizeof(resp));
349   int index_input = 0;
350   cp0->Register_Address = htob(Register_Address, 1);
351   index_input += 1;
352   Osal_MemSet(&rq, 0, sizeof(rq));
353   rq.ogf = 0x3f;
354   rq.ocf = 0x030;
355   rq.cparam = cmd_buffer;
356   rq.clen = index_input;
357   rq.rparam = &resp;
358   rq.rlen = sizeof(resp);
359   if (hci_send_req(&rq, FALSE) < 0)
360     return BLE_STATUS_TIMEOUT;
361   if (resp.Status)
362   {
363     return resp.Status;
364   }
365   *reg_val = btoh(resp.reg_val, 1);
366   return BLE_STATUS_SUCCESS;
367 }
368 
aci_hal_write_radio_reg(uint8_t Register_Address,uint8_t Register_Value)369 tBleStatus aci_hal_write_radio_reg(uint8_t Register_Address,
370                                    uint8_t Register_Value)
371 {
372   struct hci_request rq;
373   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
374   aci_hal_write_radio_reg_cp0 *cp0 = (aci_hal_write_radio_reg_cp0*)(cmd_buffer);
375   tBleStatus status = 0;
376   int index_input = 0;
377   cp0->Register_Address = htob(Register_Address, 1);
378   index_input += 1;
379   cp0->Register_Value = htob(Register_Value, 1);
380   index_input += 1;
381   Osal_MemSet(&rq, 0, sizeof(rq));
382   rq.ogf = 0x3f;
383   rq.ocf = 0x031;
384   rq.cparam = cmd_buffer;
385   rq.clen = index_input;
386   rq.rparam = &status;
387   rq.rlen = 1;
388   if (hci_send_req(&rq, FALSE) < 0)
389     return BLE_STATUS_TIMEOUT;
390   if (status)
391   {
392     return status;
393   }
394   return BLE_STATUS_SUCCESS;
395 }
396 
aci_hal_read_raw_rssi(uint8_t Value[3])397 tBleStatus aci_hal_read_raw_rssi(uint8_t Value[3])
398 {
399   struct hci_request rq;
400   aci_hal_read_raw_rssi_rp0 resp;
401   Osal_MemSet(&resp, 0, sizeof(resp));
402   Osal_MemSet(&rq, 0, sizeof(rq));
403   rq.ogf = 0x3f;
404   rq.ocf = 0x032;
405   rq.rparam = &resp;
406   rq.rlen = sizeof(resp);
407   if (hci_send_req(&rq, FALSE) < 0)
408     return BLE_STATUS_TIMEOUT;
409   if (resp.Status)
410   {
411     return resp.Status;
412   }
413   Osal_MemCpy((void *) Value, (const void *) resp.Value, 3);
414   return BLE_STATUS_SUCCESS;
415 }
416 
aci_hal_rx_start(uint8_t RF_Channel)417 tBleStatus aci_hal_rx_start(uint8_t RF_Channel)
418 {
419   struct hci_request rq;
420   uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
421   aci_hal_rx_start_cp0 *cp0 = (aci_hal_rx_start_cp0*)(cmd_buffer);
422   tBleStatus status = 0;
423   int index_input = 0;
424   cp0->RF_Channel = htob(RF_Channel, 1);
425   index_input += 1;
426   Osal_MemSet(&rq, 0, sizeof(rq));
427   rq.ogf = 0x3f;
428   rq.ocf = 0x033;
429   rq.cparam = cmd_buffer;
430   rq.clen = index_input;
431   rq.rparam = &status;
432   rq.rlen = 1;
433   if (hci_send_req(&rq, FALSE) < 0)
434     return BLE_STATUS_TIMEOUT;
435   if (status)
436   {
437     return status;
438   }
439   return BLE_STATUS_SUCCESS;
440 }
441 
aci_hal_rx_stop(void)442 tBleStatus aci_hal_rx_stop(void)
443 {
444   struct hci_request rq;
445   tBleStatus status = 0;
446   Osal_MemSet(&rq, 0, sizeof(rq));
447   rq.ogf = 0x3f;
448   rq.ocf = 0x034;
449   rq.rparam = &status;
450   rq.rlen = 1;
451   if (hci_send_req(&rq, FALSE) < 0)
452     return BLE_STATUS_TIMEOUT;
453   if (status)
454   {
455     return status;
456   }
457   return BLE_STATUS_SUCCESS;
458 }
459 
aci_hal_stack_reset(void)460 tBleStatus aci_hal_stack_reset(void)
461 {
462   struct hci_request rq;
463   tBleStatus status = 0;
464   Osal_MemSet(&rq, 0, sizeof(rq));
465   rq.ogf = 0x3f;
466   rq.ocf = 0x03b;
467   rq.rparam = &status;
468   rq.rlen = 1;
469   if (hci_send_req(&rq, FALSE) < 0)
470     return BLE_STATUS_TIMEOUT;
471   if (status)
472   {
473     return status;
474   }
475   return BLE_STATUS_SUCCESS;
476 }
477 
478