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