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 ******************************************************************/
21 * @file caretransmission.h
24 #ifndef __CA_RETRANSMISSION_H_
25 #define __CA_RETRANSMISSION_H_
29 #include "uthreadpool.h"
31 #include "uarraylist.h"
34 /** CA_ETHERNET, CA_WIFI, CA_EDR, CA_LE **/
35 #define DEFAULT_RETRANSMISSION_TYPE (CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE)
37 /** default ACK time is 2 sec.(CoAP) **/
38 #define DEFAULT_ACK_TIMEOUT_SEC 2
40 /** default max retransmission trying count is 4.(CoAP) **/
41 #define DEFAULT_MAX_RETRANSMIT 4
43 /** check period is 1 sec. **/
44 #define RETRANSMISSION_CHECK_PERIOD_SEC 1
46 /** retransmission data send method type**/
47 typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
50 /** retransmission timeout callback type**/
51 typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size);
55 /** retransmission support connectivity type **/
56 CAConnectivityType_t supportType;
57 /** retransmission trying count **/
60 } CARetransmissionConfig_t;
64 /** Thread pool of the thread started **/
65 u_thread_pool_t threadPool;
66 /** mutex for synchrnoization **/
68 /** conditional mutex for synchrnoization **/
70 /** send method for retransmission data **/
71 CADataSendMethod_t dataSendMethod;
72 /** callback function for retransmit timeout **/
73 CATimeoutCallback_t timeoutCallback;
74 /** retransmission configure data **/
75 CARetransmissionConfig_t config;
76 /** Variable to inform the thread to stop **/
78 /** array list on which the thread is operating. **/
79 u_arraylist_t *dataList;
88 * @brief Initializes the retransmission context
89 * @param context [IN] context for retransmission
90 * @param handle [IN] thread pool handle
91 * @param retransmissionSendMethod [IN] function to be called for retransmission
92 * @param timeoutCallback [IN] callback for retransmit timeout
93 * @param config [IN] configuration for retransmission.
94 * if NULL is coming, it will set default values.
95 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
97 CAResult_t CARetransmissionInitialize(CARetransmission_t *context, u_thread_pool_t handle,
98 CADataSendMethod_t retransmissionSendMethod,
99 CATimeoutCallback_t timeoutCallback,
100 CARetransmissionConfig_t* config);
103 * @brief Starting the retransmission context
104 * @param context [IN] context for retransmission
105 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
107 CAResult_t CARetransmissionStart(CARetransmission_t *context);
110 * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up and
111 * process the retransmission data.
112 * @param context [IN] context for retransmission
113 * @param endpoint [IN] endpoint information
114 * @param pdu [IN] sent pdu binary data
115 * @param size [IN] sent pdu binary data size
116 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
118 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
119 const CARemoteEndpoint_t* endpoint,const void* pdu,
123 * @brief Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
124 * the specified CON data will remove on retransmission list.
125 * @param context [IN] context for retransmission
126 * @param endpoint [IN] endpoint information
127 * @param pdu [IN] received pdu binary data
128 * @param size [IN] received pdu binary data size
129 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
131 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
132 const CARemoteEndpoint_t *endpoint, const void *pdu,
136 * @brief Stopping the retransmission context
137 * @param context [IN] context for retransmission
138 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
140 CAResult_t CARetransmissionStop(CARetransmission_t *context);
143 * @brief Terminating the retransmission context
144 * @param context [IN] context for retransmission
145 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
147 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
153 #endif // __CA_RETRANSMISSION_H_