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