xref: /aosp_15_r20/external/openthread/include/openthread/ncp.h (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1*cfb92d14SAndroid Build Coastguard Worker /*
2*cfb92d14SAndroid Build Coastguard Worker  *  Copyright (c) 2016, The OpenThread Authors.
3*cfb92d14SAndroid Build Coastguard Worker  *  All rights reserved.
4*cfb92d14SAndroid Build Coastguard Worker  *
5*cfb92d14SAndroid Build Coastguard Worker  *  Redistribution and use in source and binary forms, with or without
6*cfb92d14SAndroid Build Coastguard Worker  *  modification, are permitted provided that the following conditions are met:
7*cfb92d14SAndroid Build Coastguard Worker  *  1. Redistributions of source code must retain the above copyright
8*cfb92d14SAndroid Build Coastguard Worker  *     notice, this list of conditions and the following disclaimer.
9*cfb92d14SAndroid Build Coastguard Worker  *  2. Redistributions in binary form must reproduce the above copyright
10*cfb92d14SAndroid Build Coastguard Worker  *     notice, this list of conditions and the following disclaimer in the
11*cfb92d14SAndroid Build Coastguard Worker  *     documentation and/or other materials provided with the distribution.
12*cfb92d14SAndroid Build Coastguard Worker  *  3. Neither the name of the copyright holder nor the
13*cfb92d14SAndroid Build Coastguard Worker  *     names of its contributors may be used to endorse or promote products
14*cfb92d14SAndroid Build Coastguard Worker  *     derived from this software without specific prior written permission.
15*cfb92d14SAndroid Build Coastguard Worker  *
16*cfb92d14SAndroid Build Coastguard Worker  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*cfb92d14SAndroid Build Coastguard Worker  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cfb92d14SAndroid Build Coastguard Worker  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cfb92d14SAndroid Build Coastguard Worker  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20*cfb92d14SAndroid Build Coastguard Worker  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*cfb92d14SAndroid Build Coastguard Worker  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*cfb92d14SAndroid Build Coastguard Worker  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*cfb92d14SAndroid Build Coastguard Worker  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*cfb92d14SAndroid Build Coastguard Worker  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*cfb92d14SAndroid Build Coastguard Worker  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*cfb92d14SAndroid Build Coastguard Worker  *  POSSIBILITY OF SUCH DAMAGE.
27*cfb92d14SAndroid Build Coastguard Worker  */
28*cfb92d14SAndroid Build Coastguard Worker 
29*cfb92d14SAndroid Build Coastguard Worker /**
30*cfb92d14SAndroid Build Coastguard Worker  * @file
31*cfb92d14SAndroid Build Coastguard Worker  * @brief
32*cfb92d14SAndroid Build Coastguard Worker  *  This file defines the top-level functions for the OpenThread NCP module.
33*cfb92d14SAndroid Build Coastguard Worker  */
34*cfb92d14SAndroid Build Coastguard Worker 
35*cfb92d14SAndroid Build Coastguard Worker #ifndef OPENTHREAD_NCP_H_
36*cfb92d14SAndroid Build Coastguard Worker #define OPENTHREAD_NCP_H_
37*cfb92d14SAndroid Build Coastguard Worker 
38*cfb92d14SAndroid Build Coastguard Worker #include <stdarg.h>
39*cfb92d14SAndroid Build Coastguard Worker 
40*cfb92d14SAndroid Build Coastguard Worker #include <openthread/platform/logging.h>
41*cfb92d14SAndroid Build Coastguard Worker #include <openthread/platform/radio.h>
42*cfb92d14SAndroid Build Coastguard Worker 
43*cfb92d14SAndroid Build Coastguard Worker #ifdef __cplusplus
44*cfb92d14SAndroid Build Coastguard Worker extern "C" {
45*cfb92d14SAndroid Build Coastguard Worker #endif
46*cfb92d14SAndroid Build Coastguard Worker 
47*cfb92d14SAndroid Build Coastguard Worker /**
48*cfb92d14SAndroid Build Coastguard Worker  * @addtogroup api-ncp
49*cfb92d14SAndroid Build Coastguard Worker  *
50*cfb92d14SAndroid Build Coastguard Worker  * @brief
51*cfb92d14SAndroid Build Coastguard Worker  *   This module includes functions that control the Thread stack's execution.
52*cfb92d14SAndroid Build Coastguard Worker  *
53*cfb92d14SAndroid Build Coastguard Worker  * @{
54*cfb92d14SAndroid Build Coastguard Worker  *
55*cfb92d14SAndroid Build Coastguard Worker  */
56*cfb92d14SAndroid Build Coastguard Worker 
57*cfb92d14SAndroid Build Coastguard Worker /**
58*cfb92d14SAndroid Build Coastguard Worker  * Pointer is called to send HDLC encoded NCP data.
59*cfb92d14SAndroid Build Coastguard Worker  *
60*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aBuf        A pointer to a buffer with an output.
61*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aBufLength  A length of the output data stored in the buffer.
62*cfb92d14SAndroid Build Coastguard Worker  *
63*cfb92d14SAndroid Build Coastguard Worker  * @returns                Number of bytes processed by the callback.
64*cfb92d14SAndroid Build Coastguard Worker  *
65*cfb92d14SAndroid Build Coastguard Worker  */
66*cfb92d14SAndroid Build Coastguard Worker typedef int (*otNcpHdlcSendCallback)(const uint8_t *aBuf, uint16_t aBufLength);
67*cfb92d14SAndroid Build Coastguard Worker 
68*cfb92d14SAndroid Build Coastguard Worker /**
69*cfb92d14SAndroid Build Coastguard Worker  * Is called after NCP send finished.
70*cfb92d14SAndroid Build Coastguard Worker  *
71*cfb92d14SAndroid Build Coastguard Worker  */
72*cfb92d14SAndroid Build Coastguard Worker void otNcpHdlcSendDone(void);
73*cfb92d14SAndroid Build Coastguard Worker 
74*cfb92d14SAndroid Build Coastguard Worker /**
75*cfb92d14SAndroid Build Coastguard Worker  * Is called after HDLC encoded NCP data received.
76*cfb92d14SAndroid Build Coastguard Worker  *
77*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aBuf        A pointer to a buffer.
78*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aBufLength  The length of the data stored in the buffer.
79*cfb92d14SAndroid Build Coastguard Worker  *
80*cfb92d14SAndroid Build Coastguard Worker  */
81*cfb92d14SAndroid Build Coastguard Worker void otNcpHdlcReceive(const uint8_t *aBuf, uint16_t aBufLength);
82*cfb92d14SAndroid Build Coastguard Worker 
83*cfb92d14SAndroid Build Coastguard Worker /**
84*cfb92d14SAndroid Build Coastguard Worker  * Initialize the NCP based on HDLC framing.
85*cfb92d14SAndroid Build Coastguard Worker  *
86*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aInstance        The OpenThread instance structure.
87*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aSendCallback    The function pointer used to send NCP data.
88*cfb92d14SAndroid Build Coastguard Worker  *
89*cfb92d14SAndroid Build Coastguard Worker  */
90*cfb92d14SAndroid Build Coastguard Worker void otNcpHdlcInit(otInstance *aInstance, otNcpHdlcSendCallback aSendCallback);
91*cfb92d14SAndroid Build Coastguard Worker 
92*cfb92d14SAndroid Build Coastguard Worker /**
93*cfb92d14SAndroid Build Coastguard Worker  * Initialize the NCP based on HDLC framing.
94*cfb92d14SAndroid Build Coastguard Worker  *
95*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aInstances       The OpenThread instance pointers array.
96*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aCount           Number of elements in the array.
97*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aSendCallback    The function pointer used to send NCP data.
98*cfb92d14SAndroid Build Coastguard Worker  *
99*cfb92d14SAndroid Build Coastguard Worker  */
100*cfb92d14SAndroid Build Coastguard Worker void otNcpHdlcInitMulti(otInstance **aInstance, uint8_t aCount, otNcpHdlcSendCallback aSendCallback);
101*cfb92d14SAndroid Build Coastguard Worker 
102*cfb92d14SAndroid Build Coastguard Worker /**
103*cfb92d14SAndroid Build Coastguard Worker  * Initialize the NCP based on SPI framing.
104*cfb92d14SAndroid Build Coastguard Worker  *
105*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aInstance  The OpenThread instance structure.
106*cfb92d14SAndroid Build Coastguard Worker  *
107*cfb92d14SAndroid Build Coastguard Worker  */
108*cfb92d14SAndroid Build Coastguard Worker void otNcpSpiInit(otInstance *aInstance);
109*cfb92d14SAndroid Build Coastguard Worker 
110*cfb92d14SAndroid Build Coastguard Worker /**
111*cfb92d14SAndroid Build Coastguard Worker  * @brief Send data to the host via a specific stream.
112*cfb92d14SAndroid Build Coastguard Worker  *
113*cfb92d14SAndroid Build Coastguard Worker  * Attempts to send the given data to the host
114*cfb92d14SAndroid Build Coastguard Worker  * using the given aStreamId. This is useful for reporting
115*cfb92d14SAndroid Build Coastguard Worker  * error messages, implementing debug/diagnostic consoles,
116*cfb92d14SAndroid Build Coastguard Worker  * and potentially other types of datastreams.
117*cfb92d14SAndroid Build Coastguard Worker  *
118*cfb92d14SAndroid Build Coastguard Worker  * The write either is accepted in its entirety or rejected.
119*cfb92d14SAndroid Build Coastguard Worker  * Partial writes are not attempted.
120*cfb92d14SAndroid Build Coastguard Worker  *
121*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aStreamId  A numeric identifier for the stream to write to.
122*cfb92d14SAndroid Build Coastguard Worker  *                        If set to '0', will default to the debug stream.
123*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aDataPtr   A pointer to the data to send on the stream.
124*cfb92d14SAndroid Build Coastguard Worker  *                        If aDataLen is non-zero, this param MUST NOT be NULL.
125*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aDataLen   The number of bytes of data from aDataPtr to send.
126*cfb92d14SAndroid Build Coastguard Worker  *
127*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_NONE         The data was queued for delivery to the host.
128*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_BUSY         There are not enough resources to complete this
129*cfb92d14SAndroid Build Coastguard Worker  *                               request. This is usually a temporary condition.
130*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_INVALID_ARGS The given aStreamId was invalid.
131*cfb92d14SAndroid Build Coastguard Worker  */
132*cfb92d14SAndroid Build Coastguard Worker otError otNcpStreamWrite(int aStreamId, const uint8_t *aDataPtr, int aDataLen);
133*cfb92d14SAndroid Build Coastguard Worker 
134*cfb92d14SAndroid Build Coastguard Worker /**
135*cfb92d14SAndroid Build Coastguard Worker  * Writes OpenThread Log using `otNcpStreamWrite`.
136*cfb92d14SAndroid Build Coastguard Worker  *
137*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aLogLevel   The log level.
138*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aLogRegion  The log region.
139*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aFormat     A pointer to the format string.
140*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aArgs       va_list matching aFormat.
141*cfb92d14SAndroid Build Coastguard Worker  */
142*cfb92d14SAndroid Build Coastguard Worker void otNcpPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs);
143*cfb92d14SAndroid Build Coastguard Worker 
144*cfb92d14SAndroid Build Coastguard Worker //-----------------------------------------------------------------------------------------
145*cfb92d14SAndroid Build Coastguard Worker // Peek/Poke memory access control delegates
146*cfb92d14SAndroid Build Coastguard Worker 
147*cfb92d14SAndroid Build Coastguard Worker /**
148*cfb92d14SAndroid Build Coastguard Worker  * Defines delegate (function pointer) type to control behavior of peek/poke operation.
149*cfb92d14SAndroid Build Coastguard Worker  *
150*cfb92d14SAndroid Build Coastguard Worker  * This delegate function is called to decide whether to allow peek or poke of a specific memory region. It is used
151*cfb92d14SAndroid Build Coastguard Worker  * if NCP support for peek/poke commands is enabled.
152*cfb92d14SAndroid Build Coastguard Worker  *
153*cfb92d14SAndroid Build Coastguard Worker  * @param[in] aAddress    Start address of memory region.
154*cfb92d14SAndroid Build Coastguard Worker  * @param[in] aCount      Number of bytes to peek or poke.
155*cfb92d14SAndroid Build Coastguard Worker  *
156*cfb92d14SAndroid Build Coastguard Worker  * @returns  TRUE to allow peek/poke of the given memory region, FALSE otherwise.
157*cfb92d14SAndroid Build Coastguard Worker  *
158*cfb92d14SAndroid Build Coastguard Worker  */
159*cfb92d14SAndroid Build Coastguard Worker typedef bool (*otNcpDelegateAllowPeekPoke)(uint32_t aAddress, uint16_t aCount);
160*cfb92d14SAndroid Build Coastguard Worker 
161*cfb92d14SAndroid Build Coastguard Worker /**
162*cfb92d14SAndroid Build Coastguard Worker  * Registers peek/poke delegate functions with NCP module.
163*cfb92d14SAndroid Build Coastguard Worker  *
164*cfb92d14SAndroid Build Coastguard Worker  * The delegate functions are called by NCP module to decide whether to allow peek or poke of a specific memory region.
165*cfb92d14SAndroid Build Coastguard Worker  * If the delegate pointer is set to NULL, it allows peek/poke operation for any address.
166*cfb92d14SAndroid Build Coastguard Worker  *
167*cfb92d14SAndroid Build Coastguard Worker  * @param[in] aAllowPeekDelegate      Delegate function pointer for peek operation.
168*cfb92d14SAndroid Build Coastguard Worker  * @param[in] aAllowPokeDelegate      Delegate function pointer for poke operation.
169*cfb92d14SAndroid Build Coastguard Worker  *
170*cfb92d14SAndroid Build Coastguard Worker  */
171*cfb92d14SAndroid Build Coastguard Worker void otNcpRegisterPeekPokeDelegates(otNcpDelegateAllowPeekPoke aAllowPeekDelegate,
172*cfb92d14SAndroid Build Coastguard Worker                                     otNcpDelegateAllowPeekPoke aAllowPokeDelegate);
173*cfb92d14SAndroid Build Coastguard Worker 
174*cfb92d14SAndroid Build Coastguard Worker /**
175*cfb92d14SAndroid Build Coastguard Worker  * @}
176*cfb92d14SAndroid Build Coastguard Worker  *
177*cfb92d14SAndroid Build Coastguard Worker  */
178*cfb92d14SAndroid Build Coastguard Worker 
179*cfb92d14SAndroid Build Coastguard Worker #ifdef __cplusplus
180*cfb92d14SAndroid Build Coastguard Worker } // extern "C"
181*cfb92d14SAndroid Build Coastguard Worker #endif
182*cfb92d14SAndroid Build Coastguard Worker 
183*cfb92d14SAndroid Build Coastguard Worker #endif // OPENTHREAD_NCP_H_
184