1 /*!
2  * \file      LmPackage.h
3  *
4  * \brief     Defines the packages API
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2018 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  */
21 #ifndef __LMH_PACKAGE_H__
22 #define __LMH_PACKAGE_H__
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include <stdint.h>
29 #include <stdbool.h>
30 #include "LmHandlerTypes.h"
31 
32 /*!
33  * Maximum number of packages
34  */
35 #define PKG_MAX_NUMBER                              4
36 
37 typedef struct LmhPackage_s
38 {
39     uint8_t Port;
40     /*
41      *=========================================================================
42      * Below callbacks must be initialized in package variable declaration
43      *=========================================================================
44      */
45 
46     /*!
47      * Initializes the package with provided parameters
48      *
49      * \param [IN] params            Pointer to the package parameters
50      * \param [IN] dataBuffer        Pointer to main application buffer
51      * \param [IN] dataBufferMaxSize Main application buffer maximum size
52      */
53     void ( *Init )( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize );
54     /*!
55      * Returns the current package initialization status.
56      *
57      * \retval status Package initialization status
58      *                [true: Initialized, false: Not initialized]
59      */
60     bool ( *IsInitialized )( void );
61     /*!
62      * Returns if a package transmission is pending or not.
63      *
64      * \retval status Package transmission status
65      *                [true: pending, false: Not pending]
66      */
67     bool ( *IsTxPending )( void );
68     /*!
69      * Processes the internal package events.
70      */
71     void ( *Process )( void );
72     /*!
73      * Processes the MCSP Confirm
74      *
75      * \param [IN] mcpsConfirm MCPS confirmation primitive data
76      */
77     void ( *OnMcpsConfirmProcess )( McpsConfirm_t *mcpsConfirm );
78     /*!
79      * Processes the MCPS Indication
80      *
81      * \param [IN] mcpsIndication     MCPS indication primitive data
82      */
83     void ( *OnMcpsIndicationProcess )( McpsIndication_t *mcpsIndication );
84     /*!
85      * Processes the MLME Confirm
86      *
87      * \param [IN] mlmeConfirm MLME confirmation primitive data
88      */
89     void ( *OnMlmeConfirmProcess )( MlmeConfirm_t *mlmeConfirm );
90     /*!
91      * Processes the MLME Indication
92      *
93      * \param [IN] mlmeIndication     MLME indication primitive data
94      */
95     void ( *OnMlmeIndicationProcess )( MlmeIndication_t *mlmeIndication );
96 
97     /*
98      *=========================================================================
99      * Below callbacks must be initialized in LmHandler initialization with
100      * provideded LmHandlerSend and OnMacRequest functions
101      *=========================================================================
102      */
103 
104     /*!
105      * Notifies the upper layer that a MCPS request has been made to the MAC layer
106      *
107      * \param   [IN] status      - Request returned status
108      * \param   [IN] mcpsRequest - Performed MCPS-Request. Refer to \ref McpsReq_t.
109      * \param   [IN] nextTxDelay - Time to wait until another TX is possible.
110      */
111     void ( *OnMacMcpsRequest )( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxDelay );
112     /*!
113      * Notifies the upper layer that a MLME request has been made to the MAC layer
114      *
115      * \param   [IN] status      - Request returned status
116      * \param   [IN] mlmeRequest - Performed MLME-Request. Refer to \ref MlmeReq_t.
117      * \param   [IN] nextTxDelay - Time to wait until another TX is possible.
118      */
119     void ( *OnMacMlmeRequest )( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxDelay );
120     /*!
121     * Join a LoRa Network in classA
122     *
123     * \Note if the device is ABP, this is a pass through function
124     *
125     * \param [IN] isOtaa Indicates which activation mode must be used
126     */
127     void ( *OnJoinRequest )( bool isOtaa );
128     /*!
129     * Requests network server time update
130     *
131     * \retval status Returns \ref LORAMAC_HANDLER_SET if joined else \ref LORAMAC_HANDLER_RESET
132     */
133     LmHandlerErrorStatus_t ( *OnDeviceTimeRequest )( void );
134 #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 )
135     /*!
136      * Notifies the upper layer that the system time has been updated.
137      *
138      * \param [in] isSynchronized Indicates if the system time is synchronized in the range +/-1 second
139      * \param [in] timeCorrection Received time correction value
140      */
141     void ( *OnSysTimeUpdate )( bool isSynchronized, int32_t timeCorrection );
142 #else
143     /*!
144      * Notifies the upper layer that the system time has been updated.
145      */
146     void ( *OnSysTimeUpdate )( void );
147 #endif
148 }LmhPackage_t;
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif // __LMH_PACKAGE_H__
155