1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 * @file caretransmission.h
23 * @brief This file contains common function for retransmission messages.
26 #ifndef CA_RETRANSMISSION_H_
27 #define CA_RETRANSMISSION_H_
31 #include "cathreadpool.h"
33 #include "uarraylist.h"
36 /** CA_IPV4, CA_EDR, CA_LE **/
37 #define DEFAULT_RETRANSMISSION_TYPE (CA_IPV4 | CA_EDR | CA_LE)
39 /** default ACK time is 2 sec.(CoAP) **/
40 #define DEFAULT_ACK_TIMEOUT_SEC 2
42 /** default max retransmission trying count is 4.(CoAP) **/
43 #define DEFAULT_MAX_RETRANSMIT 4
45 /** check period is 1 sec. **/
46 #define RETRANSMISSION_CHECK_PERIOD_SEC 1
48 /** retransmission data send method type**/
49 typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
52 /** retransmission timeout callback type**/
53 typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
58 /** retransmission support transport type **/
59 CATransportType_t supportType;
61 /** retransmission trying count **/
64 } CARetransmissionConfig_t;
68 /** Thread pool of the thread started **/
69 ca_thread_pool_t threadPool;
71 /** mutex for synchronization **/
74 /** conditional mutex for synchronization **/
77 /** send method for retransmission data **/
78 CADataSendMethod_t dataSendMethod;
80 /** callback function for retransmit timeout **/
81 CATimeoutCallback_t timeoutCallback;
83 /** retransmission configure data **/
84 CARetransmissionConfig_t config;
86 /** Variable to inform the thread to stop **/
89 /** array list on which the thread is operating. **/
90 u_arraylist_t *dataList;
100 * @brief Initializes the retransmission context
101 * @param context [IN] context for retransmission
102 * @param handle [IN] thread pool handle
103 * @param retransmissionSendMethod [IN] function to be called for retransmission
104 * @param timeoutCallback [IN] callback for retransmit timeout
105 * @param config [IN] configuration for retransmission.
106 * if NULL is coming, it will set default values.
107 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
109 CAResult_t CARetransmissionInitialize(CARetransmission_t *context, ca_thread_pool_t handle,
110 CADataSendMethod_t retransmissionSendMethod,
111 CATimeoutCallback_t timeoutCallback,
112 CARetransmissionConfig_t* config);
115 * @brief Starting the retransmission context
116 * @param context [IN] context for retransmission
117 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
119 CAResult_t CARetransmissionStart(CARetransmission_t *context);
122 * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up and
123 * process the retransmission data
124 * @param context [IN] context for retransmission
125 * @param endpoint [IN] endpoint information
126 * @param pdu [IN] sent pdu binary data
127 * @param size [IN] sent pdu binary data size
128 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
130 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
131 const CARemoteEndpoint_t* endpoint, const void* pdu,
135 * @brief Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
136 * the specified CON data will remove on retransmission list.
137 * @param context [IN] context for retransmission
138 * @param endpoint [IN] endpoint information
139 * @param pdu [IN] received pdu binary data
140 * @param size [IN] received pdu binary data size
141 * @param retransmissionPdu [OUT] pdu data of the request for reset and ack
142 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
144 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
145 const CARemoteEndpoint_t *endpoint, const void *pdu,
146 uint32_t size, void **retransmissionPdu);
149 * @brief Stopping the retransmission context
150 * @param context [IN] context for retransmission
151 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
153 CAResult_t CARetransmissionStop(CARetransmission_t *context);
156 * @brief Terminating the retransmission context
157 * @param context [IN] context for retransmission
158 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
160 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
166 #endif /* CA_RETRANSMISSION_H_ */