Welcome to mirror list, hosted at ThFree Co, Russian Federation.

openthread_api_wb.c « openthread_api « core « openthread « thread « STM32_WPAN « ST « Middlewares - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec64232c01edbb0e5e0558c683969c1f7aa9b7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
  ******************************************************************************
  * @file    openthread_api_wb.c
  * @author  MCD Application Team
  * @brief   Contains STM32WB specificities requested to control the OpenThread
  *          interface.
  ******************************************************************************
  * @attention
 *
 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under Ultimate Liberty license
 * SLA0044, the "License"; You may not use this file except in compliance with
 * the License. You may obtain a copy of the License at:
 *                             www.st.com/SLA0044
 *
 ******************************************************************************
 */


/* Includes ------------------------------------------------------------------*/
#include "stm32wbxx_hal.h"
#include "tl_thread_hci.h"

/* Include definition of compilation flags requested for OpenThread configuration */
#include OPENTHREAD_CONFIG_FILE

#include "tl.h"
#include "openthread_api_wb.h"
#include "dbg_trace.h"
#include "shci.h"

/* INSTANCE */
otStateChangedCallback otStateChangedCb = NULL;

/* IP6 */
otIp6SlaacIidCreate aIidCreateCb = NULL;
otIp6ReceiveCallback otIp6ReceiveCb = NULL;

/* LINK */
otHandleActiveScanResult otHandleActiveScanResultCb = NULL;
otHandleEnergyScanResult otHandleEnergyScanResultCb = NULL;
otLinkPcapCallback otLinkPcapCb = NULL;

/* THREAD */
otReceiveDiagnosticGetCallback otReceiveDiagnosticGetCb = NULL;

#if OPENTHREAD_FTD
/* THREAD_FTD */
otThreadChildTableCallback otThreadChildTableCallbackCb = NULL;
#endif

/* COMMISSIONER */
otCommissionerEnergyReportCallback otCommissionerEnergyReportCb = NULL;
otCommissionerPanIdConflictCallback otCommissionerPanIdConflictCb = NULL;

/* DNS */
otDnsResponseHandler otDnsResponseHandlerCb = NULL;

/* ICMP6 */
otIcmp6ReceiveCallback otIcmp6ReceiveCb = NULL;

/* JOINER */
otJoinerCallback otJoinerCb = NULL;

/* LINK_RAW */
otLinkRawReceiveDone otLinkRawReceiveDoneCb = NULL;
otLinkRawTransmitDone otLinkRawTransmitDoneCb = NULL;
otLinkRawEnergyScanDone otLinkRawEnergyScanDoneCb = NULL;

/* UDP */
otUdpReceive otUdpReceiveCb = NULL;

/* COAP */
typedef void (*CoapRequestHandlerCallback)(otCoapHeader *aHeader, otMessage *aMessage,
                                     const otMessageInfo *aMessageInfo);
typedef void (*CoapResponseHandlerCallback)(otCoapHeader *aHeader, otMessage *aMessage,
                                      const otMessageInfo *aMessageInfo, otError aResult);

CoapRequestHandlerCallback coapRequestHandlerCb = NULL;
CoapResponseHandlerCallback coapResponseHandlerCb = NULL;

#if OPENTHREAD_ENABLE_JAM_DETECTION
/* JAM_DETECTION */
otJamDetectionCallback otJamDetectionCallbackCb = NULL;
#endif


/**
  * @brief  This function is used to manage all the callbacks used by the
  *         OpenThread interface. These callbacks are used for example to
  *         notify the application as soon as the state of a device has been
  *         modified.
  *
  *         Important Note: This function must be called each time a message
  *         is sent from the M0 to the M4.
  *
  * @param  None
  * @retval None
  */

HAL_StatusTypeDef OpenThread_CallBack_Processing(void)
{
    HAL_StatusTypeDef status = HAL_OK;

    /* Get pointer on received event buffer from M0 */
    Thread_OT_Cmd_Request_t* p_notification = THREAD_Get_NotificationPayloadBuffer();

    switch(p_notification->ID)
    {
    case MSG_M0TOM4_NOTIFY_STATE_CHANGE:
        if (otStateChangedCb != NULL)
        {
            otStateChangedCb((uint32_t) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_COAP_REQUEST_HANDLER:
        coapRequestHandlerCb = (CoapRequestHandlerCallback) p_notification->Data[0];

        if (coapRequestHandlerCb != NULL)
        {
            coapRequestHandlerCb( (otCoapHeader *) p_notification->Data[1],
                    (otMessage *) p_notification->Data[2],
                    (otMessageInfo *) p_notification->Data[3]);
        }
        break;
    case MSG_M0TOM4_COAP_RESPONSE_HANDLER:
        coapResponseHandlerCb = (CoapResponseHandlerCallback) p_notification->Data[0];
        if (coapResponseHandlerCb != NULL)
        {
            coapResponseHandlerCb( (otCoapHeader *) p_notification->Data[1],
                    (otMessage *) p_notification->Data[2],
                    (otMessageInfo *) p_notification->Data[3],
                    (otError) p_notification->Data[4]);
        }
        break;
    case MSG_M0TOM4_NOTIFY_STACK_RESET:
        /* Store Thread NVM data in Flash*/
        SHCI_C2_FLASH_StoreData(THREAD_IP);
        /* Perform an NVIC Reset in order to reinitalize the device */
        HAL_NVIC_SystemReset();
        break;
    case MSG_M0TOM4_IP6_RECEIVE:
        if (otIp6ReceiveCb != NULL)
        {
            otIp6ReceiveCb((otMessage*) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_IP6_SLAAC_IID_CREATE:
        if (aIidCreateCb != NULL)
        {
            /* Not passing otInstance as first parameter, because created on M0, passing NULL instead */
            aIidCreateCb(NULL, (otNetifAddress*) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_HANDLE_ACTIVE_SCAN_RESULT:
        if (otHandleActiveScanResultCb != NULL)
        {
            otHandleActiveScanResultCb((otActiveScanResult*) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_HANDLE_ENERGY_SCAN_RESULT:
        if (otHandleEnergyScanResultCb != NULL)
        {
            otHandleEnergyScanResultCb((otEnergyScanResult*) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_HANDLE_LINK_PCAP:
        if (otLinkPcapCb != NULL)
        {
            otLinkPcapCb((otRadioFrame*) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_RECEIVE_DIAGNOSTIC_GET_CALLBACK:
        if (otReceiveDiagnosticGetCb != NULL)
        {
            otReceiveDiagnosticGetCb((otMessage*) p_notification->Data[0],
                    (otMessageInfo*) p_notification->Data[1],
                    (void*) p_notification->Data[2]);
        }
        break;
#if OPENTHREAD_FTD
    case MSG_M0TOM4_THREAD_FTD_CHILD_TABLE_CALLBACK:
        if (otThreadChildTableCallbackCb != NULL)
        {
            otThreadChildTableCallbackCb((otThreadChildTableEvent) p_notification->Data[0],
                    (const otChildInfo *) p_notification->Data[1]);
        }
        break;
#endif
    case MSG_M0TOM4_COMMISSIONER_ENERGY_REPORT_CALLBACK:
        if (otCommissionerEnergyReportCb != NULL)
        {
            otCommissionerEnergyReportCb((uint32_t) p_notification->Data[0],
                    (uint8_t*) p_notification->Data[1],
                    (uint8_t) p_notification->Data[2],
                    (void*) p_notification->Data[3]);
        }
        break;
    case MSG_M0TOM4_DNS_RESPONSE_HANDLER:
        if (otDnsResponseHandlerCb != NULL)
        {
            otDnsResponseHandlerCb((void*) p_notification->Data[0],
                    (char*) p_notification->Data[1],
                    (otIp6Address*) p_notification->Data[2],
                    (uint32_t) p_notification->Data[3],
                    (otError) p_notification->Data[4]);
        }
        break;
    case MSG_M0TOM4_ICMP6_RECEIVE_CALLBACK:
        if (otIcmp6ReceiveCb != NULL)
        {
            otIcmp6ReceiveCb((void*) p_notification->Data[0],
                    (otMessage*) p_notification->Data[1],
                    (otMessageInfo*) p_notification->Data[2],
                    (otIcmp6Header*) p_notification->Data[3]);
        }
        break;
    case MSG_M0TOM4_JOINER_CALLBACK:
        if (otJoinerCb != NULL)
        {
            otJoinerCb((otError) p_notification->Data[0],
                    (void*) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_LINK_RAW_RECEIVE_DONE:
        if (otLinkRawReceiveDoneCb != NULL)
        {
            otLinkRawReceiveDoneCb((otInstance*) p_notification->Data[0],
                    (otRadioFrame*) p_notification->Data[1],
                    (otError) p_notification->Data[2]);
        }
        break;
    case MSG_M0TOM4_LINK_RAW_TRANSMIT_DONE:
        if (otLinkRawTransmitDoneCb != NULL)
        {
            otLinkRawTransmitDoneCb((otInstance*) p_notification->Data[0],
                    (otRadioFrame*) p_notification->Data[1],
                    (otRadioFrame*) p_notification->Data[2],
                    (otError) p_notification->Data[3]);
        }
        break;
    case MSG_M0TOM4_LINK_RAW_ENERGY_SCAN_DONE:
        if (otLinkRawEnergyScanDoneCb != NULL)
        {
            otLinkRawEnergyScanDoneCb((otInstance*) p_notification->Data[0],
                    (int8_t) p_notification->Data[1]);
        }
        break;
    case MSG_M0TOM4_UDP_RECEIVE:
        if (otUdpReceiveCb != NULL)
        {
            otUdpReceiveCb((void*) p_notification->Data[0],
                    (otMessage*) p_notification->Data[1],
                    (otMessageInfo*) p_notification->Data[2]);
        }
        break;
#if OPENTHREAD_ENABLE_JAM_DETECTION
    case MSG_M0TOM4_JAM_DETECTION_CALLBACK:
        if (otJamDetectionCallbackCb != NULL)
        {
            otJamDetectionCallbackCb((bool) p_notification->Data[0],
                    (void *) p_notification->Data[1]);
        }
        break;
#endif
    default:
        status = HAL_ERROR;
        break;
    }

    TL_THREAD_SendAck();
    return status;

}