1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 * @file caprotocolmessage.h
22 * @brief This file contains common function for handling protocol messages.
25 #ifndef __CA_PROTOCOL_MESSAGE_H_
26 #define __CA_PROTOCOL_MESSAGE_H_
38 typedef uint32_t code_t;
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
47 coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t info);
50 * function for generating
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)
60 uint32_t CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo,
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)
70 uint32_t CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
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
80 coap_pdu_t* CACreatePDUforRequest(const code_t code, coap_list_t *options,
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
92 coap_pdu_t *CACreatePDUforRequestWithPayload(const code_t code, coap_list_t *optlist,
93 const char* payload, const CAInfo_t info);
96 * @brief parse the URI and creates the options
97 * @param uriInfo [IN] uri information
98 * @param options [IN] options information
101 void CAParseURI(const char *uriInfo, coap_list_t **options);
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
110 void CAParseHeadOption(const uint32_t code, const CAInfo_t info, coap_list_t **optlist);
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
119 coap_list_t *CACreateNewOptionNode(const uint16_t key, const uint32_t length,
120 const uint8_t *data);
123 * @brief order the inserted options
124 * @param a [IN] option 1 for insertion
125 * @param b [IN] option 2 for insertion
128 int CAOrderOpts(void *a, void *b);
131 * @brief number of options count
132 * @param opt_iter [IN] option iteration for count
133 * @return number of options
135 uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter);
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
146 uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *result, uint32_t buflen,
147 uint32_t encode_always);
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
157 void CAGetRequestPDUInfo(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo,
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
167 coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode);
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)
175 CAResult_t CAGenerateTokenInternal(CAToken_t *token);
178 * @brief destroys the token
179 * @param token [IN] generated token
182 void CADestroyTokenInternal(CAToken_t token);
185 * @brief destroy the ca info structure
186 * @param info [IN] info structure created from received packet
189 void CADeinitialize(CAInfo_t *info);
195 #endif //#ifndef __CA_PROTOCOL_MESSAGE_H_