Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / cafragmentation.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  *
24  * This file contains common utility functions to manage the CA msg
25  * fragmentation and reassemebly.
26  */
27
28 #ifndef CA_FRAGMENTATION_H_
29 #define CA_FRAGMENTATION_H_
30
31 #include "cacommon.h"
32 #include "logger.h"
33
34 /**
35  * @var MAX_DATA_LENGTH_SUPPORTED
36  * @brief From the adapter level, this is the maximum data length is supported
37  *        for the data transmission.
38  */
39 #define MAX_DATA_LENGTH_SUPPORTED 4095
40
41 /**
42  * @var NUMBER_OF_BITS_TO_IDENTIFY_DATA
43  * @brief The number of bits allocated to represent data length in header.
44  */
45 #define NUMBER_OF_BITS_TO_IDENTIFY_DATA 12
46
47 /**
48  * @var NUMBER_OF_BITS_IN_CA_HEADER
49  * @brief The length of the header in bits.
50  */
51 #define NUMBER_OF_BITS_IN_CA_HEADER 15
52
53 /**
54  * @var CA_HEADER_LENGTH
55  * @brief The length of the header in bytes.
56  */
57 #define CA_HEADER_LENGTH 2
58
59 /**
60  * @var CA_SUPPORTED_BLE_MTU_SIZE
61  * @brief The MTU supported for BLE adapter
62  */
63 #define CA_SUPPORTED_BLE_MTU_SIZE  20
64
65 #ifdef __TIZEN__
66 /**
67  * @var PLATFORM_IDENTIFIER_BIT
68  * @brief Reserved bit to differentiating the platform. Currently not in use.
69  */
70 #define PLATFORM_IDENTIFIER_BIT 1
71
72 /**
73  * @var CA_SUPPORTED_EDR_MTU_SIZE
74  * @brief The MTU supported from Tizen platform for EDR adapter.
75  */
76 #define CA_SUPPORTED_EDR_MTU_SIZE  512
77
78 #elif __ANDROID__
79 /**
80  * @var PLATFORM_IDENTIFIER_BIT
81  * @brief Reserved bit to differentiating the platform. Currently not in use.
82  */
83 #define PLATFORM_IDENTIFIER_BIT 0
84
85 /**
86  * @var CA_SUPPORTED_EDR_MTU_SIZE
87  * @brief The MTU supported from Android platform for EDR adapter.
88  */
89 #define CA_SUPPORTED_EDR_MTU_SIZE  200
90
91 #elif __ARDUINO__
92 /**
93  * @var PLATFORM_IDENTIFIER_BIT
94  * @brief Reserved bit to differentiating the platform. Currently not in use.
95  */
96 #define PLATFORM_IDENTIFIER_BIT 0
97
98 /**
99  * @var CA_SUPPORTED_EDR_MTU_SIZE
100  * @brief The MTU supported from Arduino platform for EDR adapter.
101  */
102 #define CA_SUPPORTED_EDR_MTU_SIZE  200
103
104 #else //Other Platforms
105 /**
106  * @var PLATFORM_IDENTIFIER_BIT
107  * @brief Reserved bit to differentiating the platform. Currently not in use.
108  */
109 #define PLATFORM_IDENTIFIER_BIT 0
110
111 /**
112  * @var CA_SUPPORTED_EDR_MTU_SIZE
113  * @brief The MTU supported for EDR adapter
114  */
115 #define CA_SUPPORTED_EDR_MTU_SIZE  200
116
117 #endif
118
119 /**
120  * @var HEADER_VERSION
121  * @brief Current Header version.
122  */
123 #define HEADER_VERSION 1
124
125 #ifdef __cplusplus
126 extern "C"
127 {
128 #endif
129
130 /*****************************************************************
131  * @file The CA Header format
132  * @brief CA Header will be defined by 2 bytes of Header.
133  * First two bits : Header version(Currently Its not being used)
134  * Third bit and fourth bit: Reserved bits for future use.
135  * 5th to 16th bit : 12 bits to provide the length of the data.
136  *****************************************************************/
137
138 /**
139 * @fn CAGenerateHeader
140 * @brief This function is used to generate the CA specific header to
141 *        maintain the fragmentation logic. The header structure
142 *        explained above will be formed and returned to the caller.
143 *
144 * @param[in,out] header Pointer to the octet array that will contain
145 *                       the generated header.
146 * @param[in]     length The total length of the data.  The length will
147 *                       be embedded in bits 5-16 of the header,
148 *                       meaning the maximum overall length of the
149 *                       data to be fragmented can be no more than 4096
150 *                       (2^12).
151 *
152 * @return @c CA_STATUS_OK on success. One of the @c CA_STATUS_FAILED or
153 *         other error values on error.
154 * @retval @c CA_STATUS_OK             Successful
155 * @retval @c CA_STATUS_INVALID_PARAM  Invalid input arguments
156 * @retval @c CA_STATUS_FAILED         Operation failed
157 */
158 CAResult_t CAGenerateHeader(char *header, uint32_t length);
159
160 /**
161 * @fn CAParseHeader
162 * @brief This function is used to parse the header in the receiver
163 *        end. This function will provide the information of the total
164 *        length of the data which has been fragmented.
165 *
166 * @param[in] header Pointer to the octet array data which contains the
167 *                   header information.  Note that pointer should
168 *                   point to two bytes of data header which needs to
169 *                   be parsed.
170 *
171 * @return Overall length of the data to be reassembled, or 0 on
172 *         failure.
173 */
174 uint32_t CAParseHeader(const char *header);
175
176 #ifdef __cplusplus
177 } /* extern "C" */
178 #endif
179
180 #endif  /* CA_FRAGMENTATION_H_ */
181