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