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 ******************************************************************/
24 * This file contains common function for handling protocol messages.
27 #ifndef __CA_PROTOCOL_MESSAGE_H_
28 #define __CA_PROTOCOL_MESSAGE_H_
40 typedef uint32_t code_t;
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
49 coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t info);
52 * function for generating
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
63 void CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, char *outUri,
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
74 void CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo, char *outUri,
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
85 coap_pdu_t *CAGeneratePduImpl(const code_t code, coap_list_t *options, const CAInfo_t info,
89 * @brief parse the URI and creates the options
90 * @param uriInfo [IN] uri information
91 * @param options [OUT] options information
94 void CAParseURI(const char *uriInfo, coap_list_t **options);
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
103 void CAParseHeadOption(const uint32_t code, const CAInfo_t info, coap_list_t **optlist);
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
112 coap_list_t *CACreateNewOptionNode(const uint16_t key, const uint32_t length, const uint8_t *data);
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
121 int CAOrderOpts(void *a, void *b);
124 * @brief number of options count
125 * @param opt_iter [IN] option iteration for count
126 * @return number of options
128 uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter);
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
138 uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen);
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
149 void CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo, char *outUri,
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
159 coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode);
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)
167 CAResult_t CAGenerateTokenInternal(CAToken_t *token);
170 * @brief destroys the token
171 * @param token [IN] generated token
174 void CADestroyTokenInternal(CAToken_t token);
177 * @brief destroy the ca info structure
178 * @param info [IN] info structure created from received packet
181 void CADestroyInfo(CAInfo_t *info);
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
189 CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size);
192 * @brief gets message ID PDU binary data
193 * @param pdu [IN] pdu data
194 * @param size [IN] size of pdu data
197 uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size);
203 #endif //#ifndef __CA_PROTOCOL_MESSAGE_H_