Merge "Implementation of connectivity abstraction feature Release v0.5" into connecti...
[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  * @file caprotocolmessage.h
22  * @brief This file contains common function for handling protocol messages.
23  */
24
25 #ifndef __CA_PROTOCOL_MESSAGE_H_
26 #define __CA_PROTOCOL_MESSAGE_H_
27
28 #include "cacommon.h"
29 #include "config.h"
30 #include "coap.h"
31 #include "debug.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 typedef uint32_t code_t;
39
40 /**
41  * @brief   generates pdu structure from the given information.
42  * @param   uri              [IN]    uri information of the pdu
43  * @param   code              [IN]    cod of the pdu packet
44  * @param   info              [IN]    pdu information such as request code ,response code and payload
45  * @return  coap_pdu_t     created pdu
46  */
47 coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t info);
48
49 /**
50  * function for generating
51  */
52
53 /**
54  * @brief   extracts request information from received pdu.
55  * @param   pdu              [IN]    received pdu
56  * @param   outReqInfo     [OUT]    request info structure made from received pdu
57  * @param   outUri           [OUT]    uri received in the received pdu
58  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
59  */
60 uint32_t CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, 
61                                         char *outUri);
62
63 /**
64  * @brief   extracts response information from received pdu.
65  * @param   pdu              [IN]    received pdu
66  * @param   outResInfo     [OUT]    request info structure made from received pdu
67  * @param   outUri           [OUT]    uri received in the received pdu
68  * @return  0 or 1 ( CAResult_t error codes in cacommon.h)
69  */
70 uint32_t CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
71         char *outUri);
72
73 /**
74  * @brief   creates pdu from the request information
75  * @param   code              [IN]    request or response code
76  * @param   options              [IN]    options for the request and response
77  * @param   outUri           [IN]    information to create pdu
78  * @return  coap_pdu_t
79  */
80 coap_pdu_t* CACreatePDUforRequest(const code_t code, coap_list_t *options, 
81                                         const CAInfo_t info);
82
83 /**
84  * @brief   creates pdu from the request information and paylod
85  * @param   code              [IN]    request or response code alloted
86  * @param   options              [IN]    options for the request and response backpacked
87  * @param   payload       [IN]    payload for the request or response consumed
88  * @param   outUri           [IN]    information to create pdu
89  * @return  coap_pdu_t
90  */
91
92 coap_pdu_t *CACreatePDUforRequestWithPayload(const code_t code, coap_list_t *optlist,
93         const char* payload, const CAInfo_t info);
94
95 /**
96  * @brief   parse the URI and creates the options
97  * @param   uriInfo              [IN]   uri information
98  * @param   options              [IN]   options information
99  * @return  None
100  */
101 void CAParseURI(const char *uriInfo, coap_list_t **options);
102
103 /**
104  * @brief   create option list from header information in the info
105  * @param   code              [IN]   uri information
106  * @param   info              [IN]   options information
107  * @param   optlist              [IN]   options information
108  * @return  None
109  */
110 void CAParseHeadOption(const uint32_t code, const CAInfo_t info, coap_list_t **optlist);
111
112 /**
113  * @brief   creates option node from key lenght and data
114  * @param   key              [IN]    key for the that needs to be sent
115  * @param   length              [IN]    length of the data that needs to be sent
116  * @param   data              [IN]    data that needs to be sent
117  * @return  created list
118  */
119 coap_list_t *CACreateNewOptionNode(const uint16_t key, const uint32_t length, 
120                                             const uint8_t *data);
121
122 /**
123  * @brief   order the inserted options
124  * @param   a              [IN]    option 1 for insertion
125  * @param   b              [IN]    option 2 for insertion
126  * @return  0 or 1
127  */
128 int CAOrderOpts(void *a, void *b);
129
130 /**
131  * @brief   number of options count
132  * @param   opt_iter              [IN]   option iteration for count
133  * @return number of options
134  */
135 uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter);
136
137 /**
138  * @brief   gets option data
139  * @param   data              [IN]    data that is received
140  * @param   length              [IN]    length of the data
141  * @param   result              [IN]    result of the operation
142  * @param   buflen              [IN]    buffer length of the result
143  * @param   encode_always              [IN]    encoded data
144  * @return  0 or 1
145  */
146 uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *result, uint32_t buflen,
147         uint32_t encode_always);
148
149 /**
150  * @brief   extracts request information from received pdu.
151  * @param   pdu              [IN]  received pdu
152  * @param   outCode    [OUT]    code of the received pdu
153  * @param   outInfo      [OUT]    request info structure made from received pdu
154  * @param   outUri          [OUT]    uri received in the received pdu
155  * @return  None
156  */
157 void CAGetRequestPDUInfo(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo, 
158                         char *outUri);
159
160 /**
161  * @brief   create pdu fromn received data
162  * @param   data              [IN]   received data
163  * @param   length              [IN]   length of the data received
164  * @param   outCode       [IN]   code received
165  * @return  None
166  */
167 coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode);
168
169 /**
170  * @brief  generates the token
171  * @param   token              [OUT]   generated token
172  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
173  */
174
175 CAResult_t CAGenerateTokenInternal(CAToken_t *token);
176
177 /**
178  * @brief  destroys the token
179  * @param   token              [IN]   generated token
180  * @return  none
181  */
182 void CADestroyTokenInternal(CAToken_t token);
183
184 /**
185  * @brief   destroy the ca info structure
186  * @param   info              [IN]   info structure  created from received  packet
187  * @return  none
188  */
189 void CADeinitialize(CAInfo_t *info);
190
191 #ifdef __cplusplus
192 } /* extern "C" */
193 #endif
194
195 #endif //#ifndef __CA_PROTOCOL_MESSAGE_H_