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 ******************************************************************/
27 #ifndef __CA_RETRANSMISSION_H_
28 #define __CA_RETRANSMISSION_H_
32 #include "uthreadpool.h"
34 #include "uarraylist.h"
37 /** CA_ETHERNET, CA_WIFI, CA_EDR, CA_LE **/
38 #define DEFAULT_RETRANSMISSION_TYPE (CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE)
40 /** default ACK time is 2 sec.(CoAP) **/
41 #define DEFAULT_ACK_TIMEOUT_SEC 2
43 /** default max retransmission trying count is 4.(CoAP) **/
44 #define DEFAULT_MAX_RETRANSMIT 4
46 /** check period is 1 sec. **/
47 #define RETRANSMISSION_CHECK_PERIOD_SEC 1
49 /** retransmission data send method type**/
50 typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
53 /** retransmission timeout callback type**/
54 typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size);
58 /** retransmission support connectivity type **/
59 CAConnectivityType_t supportType;
60 /** retransmission trying count **/
63 } CARetransmissionConfig_t;
67 /** Thread pool of the thread started **/
68 u_thread_pool_t threadPool;
69 /** mutex for synchrnoization **/
71 /** conditional mutex for synchrnoization **/
73 /** send method for retransmission data **/
74 CADataSendMethod_t dataSendMethod;
75 /** callback function for retransmit timeout **/
76 CATimeoutCallback_t timeoutCallback;
77 /** retransmission configure data **/
78 CARetransmissionConfig_t config;
79 /** Variable to inform the thread to stop **/
81 /** array list on which the thread is operating. **/
82 u_arraylist_t *dataList;
91 * @brief Initializes the retransmission context
92 * @param context [IN] context for retransmission
93 * @param handle [IN] thread pool handle
94 * @param retransmissionSendMethod [IN] function to be called for retransmission
95 * @param timeoutCallback [IN] callback for retransmit timeout
96 * @param config [IN] configuration for retransmission.
97 * if NULL is coming, it will set default values.
98 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
100 CAResult_t CARetransmissionInitialize(CARetransmission_t *context, u_thread_pool_t handle,
101 CADataSendMethod_t retransmissionSendMethod,
102 CATimeoutCallback_t timeoutCallback,
103 CARetransmissionConfig_t* config);
106 * @brief Starting the retransmission context
107 * @param context [IN] context for retransmission
108 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
110 CAResult_t CARetransmissionStart(CARetransmission_t *context);
113 * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up and
114 * process the retransmission data.
115 * @param context [IN] context for retransmission
116 * @param endpoint [IN] endpoint information
117 * @param pdu [IN] sent pdu binary data
118 * @param size [IN] sent pdu binary data size
119 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
121 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
122 const CARemoteEndpoint_t* endpoint,const void* pdu,
126 * @brief Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
127 * the specified CON data will remove on retransmission list.
128 * @param context [IN] context for retransmission
129 * @param endpoint [IN] endpoint information
130 * @param pdu [IN] received pdu binary data
131 * @param size [IN] received pdu binary data size
132 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
134 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
135 const CARemoteEndpoint_t *endpoint, const void *pdu,
139 * @brief Stopping the retransmission context
140 * @param context [IN] context for retransmission
141 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
143 CAResult_t CARetransmissionStop(CARetransmission_t *context);
146 * @brief Terminating the retransmission context
147 * @param context [IN] context for retransmission
148 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
150 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
156 #endif // __CA_RETRANSMISSION_H_