Corrected @file tags and restored 'Files' section.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caprotocolmessage_singlethread.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 function for handling protocol messages.
25  */
26
27 #ifndef __CA_PROTOCOL_MESSAGE_SINGLETHREAD_H_
28 #define __CA_PROTOCOL_MESSAGE_SINGLETHREAD_H_
29
30 #include "cacommon.h"
31 #include "config.h"
32 #include "coap.h"
33 #include "debug.h"
34
35 #define htons(x) ( ((x)<< 8 & 0xFF00) | ((x)>> 8 & 0x00FF) )
36 #define ntohs(x) htons(x)
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42
43 typedef uint32_t code_t;
44
45 /**
46  * @brief   generates pdu structure from the given information.
47  * @param   uri               [IN]    uri information of the pdu
48  * @param   code              [IN]    code of the pdu packet
49  * @param   info              [IN]    pdu information such as request code ,response code and payload
50  * @return  coap_pdu_t     created pdu
51  */
52 coap_pdu_t *CAGeneratePdu(const char *uri, uint32_t code, const CAInfo_t info);
53
54 /**
55  * function for generating
56  */
57
58 /**
59  * @brief   extracts request information from received pdu.
60  * @param   pdu              [IN]    received pdu
61  * @param   outReqInfo       [OUT]   request info structure made from received pdu
62  * @param   outUri           [OUT]   uri received in the received pdu
63  * @param   buflen           [IN]    Buffer Length for outUri parameter
64  * @return  NONE
65  */
66 void CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo,
67                              char *outUri, uint32_t bufLen);
68
69 /**
70  * @brief   extracts response information from received pdu.
71  * @param   pdu              [IN]    received pdu
72  * @param   outResInfo       [OUT]   response info structure made from received pdu
73  * @param   outUri           [OUT]   uri received in the received pdu
74  * @param   buflen           [IN]    Buffer Length for outUri parameter
75  * @return  NONE
76  */
77 void CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
78                               char *outUri, uint32_t bufLen);
79
80 /**
81  * @brief   creates pdu from the request information
82  * @param   code         [IN]    request or response code
83  * @param   options      [OUT]   options for the request and response
84  * @param   info         [IN]    information to create pdu
85  * @param   payload      [IN]    payload for the request or response consumed
86  * @return  coap_pdu_t
87  */
88 coap_pdu_t *CAGeneratePduImpl(const code_t code, coap_list_t *options,
89                               const CAInfo_t info, const char *payload);
90
91 /**
92  * @brief   parse the URI and creates the options
93  * @param   uriInfo      [IN]   uri information
94  * @param   options      [OUT]  options information
95  * @return  None
96  */
97 void CAParseURI(const char *uriInfo, coap_list_t **options);
98
99 /**
100  * @brief   create option list from header information in the info
101  * @param   code         [IN]   uri information
102  * @param   info         [IN]   options information
103  * @param   optlist      [OUT]  options information
104  * @return  None
105  */
106 void CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **optlist);
107
108 /**
109  * @brief   creates option node from key length and data
110  *          need to replace queue head if new node has to be added before the existing queue head
111  * @param   key          [IN]    key for the that needs to be sent
112  * @param   length       [IN]    length of the data that needs to be sent
113  * @param   data         [IN]    data that needs to be sent
114  * @return  created list
115  */
116 coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length,
117                                    const uint8_t *data);
118
119 /**
120  * @brief   order the inserted options
121  * @param   a            [IN]    option 1 for insertion
122  * @param   b            [IN]    option 2 for insertion
123  * @return  0 or 1
124  */
125 int CAOrderOpts(void *a, void *b);
126
127 /**
128  * @brief   number of options count
129  * @param   opt_iter     [IN]   option iteration for count
130  * @return number of options
131  */
132 uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter);
133
134 /**
135  * @brief   gets option data
136  * @param   data             [IN]    data that is received
137  * @param   length           [IN]    length of the data
138  * @param   option           [OUT]   result of the operation
139  * @param   buflen           [IN]    buffer length of the result
140  * @return  option count
141  */
142 uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen);
143
144 /**
145  * @brief   extracts request information from received pdu.
146  * @param   pdu              [IN]     received pdu
147  * @param   outCode          [OUT]    code of the received pdu
148  * @param   outInfo          [OUT]    request info structure made from received pdu
149  * @param   outUri           [OUT]    uri received in the received pdu
150  * @param   buflen           [IN]     Buffer Length for outUri parameter
151  * @return  None
152  */
153 void CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo,
154                       char *outUri, uint32_t bufLen);
155
156 /**
157  * @brief   create pdu fromn received data
158  * @param   data         [IN]   received data
159  * @param   length       [IN]   length of the data received
160  * @param   outCode      [OUT]  code received
161  * @return  None
162  */
163 coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode);
164
165 /**
166  * @brief  generates the token
167  * @param   token        [OUT]   generated token
168  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
169  */
170
171 CAResult_t CAGenerateTokenInternal(CAToken_t *token);
172
173 /**
174  * @brief  destroys the token
175  * @param   token        [IN]   generated token
176  * @return  none
177  */
178 void CADestroyTokenInternal(CAToken_t token);
179
180 /**
181  * @brief   destroy the ca info structure
182  * @param   info         [IN]   info structure created from received packet
183  * @return  none
184  */
185 void CADestroyInfo(CAInfo_t *info);
186
187 /**
188  * @brief   gets message type from PDU binary data
189  * @param   pdu        [IN]    pdu data
190  * @param   size       [IN]    size of pdu data
191  * @return  message type
192  */
193 CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size);
194
195 /**
196  * @brief   gets message ID PDU binary data
197  * @param   pdu        [IN]    pdu data
198  * @param   size       [IN]    size of pdu data
199  * @return  message ID
200  */
201 uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size);
202
203 #ifdef __cplusplus
204 } /* extern "C" */
205 #endif
206
207 #endif //#ifndef __CA_PROTOCOL_MESSAGE_SINGLETHREAD_H_
208