1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #ifndef OCCOAPHELPER_H_
23 #define OCCOAPHELPER_H_
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
33 #include "occoaptoken.h"
34 #include "ocstackinternal.h"
36 // Convert OCStack code to CoAP code
37 uint8_t OCToCoAPResponseCode(OCStackResult result);
39 // Convert CoAP code to OCStack code
40 OCStackResult CoAPToOCResponseCode(uint8_t coapCode);
42 // Internal function to generate a coap pdu based on passed parameters
44 GenerateCoAPPdu(uint8_t msgType, uint8_t code, unsigned short id,
45 size_t tokenLength, uint8_t * token, unsigned char * payloadJSON,
46 coap_list_t *options);
48 // Call back function used by libcoap to order option in coap pdu
49 int OrderOptions(void *a, void *b);
51 // Internal function to create an option node for coap pdu
53 CreateNewOptionNode(unsigned short key, unsigned int length,
56 // Internal function to create OCRequest struct at the server from a received coap pdu
57 OCStackResult FormOCRequest(const coap_queue_t * rcvdRequest,
58 OCRequest * * requestLoc, unsigned char * uriBuf,
59 unsigned char * queryBuf);
61 // Internal function to create OCEntityHandlerRequest at the server from a received coap pdu
62 OCStackResult FormOCEntityHandlerRequest(const coap_queue_t * rcvdRequest,
63 OCEntityHandlerRequest * * entityHandlerRequestLoc,
64 unsigned char * bufRes, unsigned char * query);
66 // Internal function to retrieve a Token from received coap pdu
67 OCStackResult RetrieveOCCoAPToken(const coap_queue_t * rcvdRequest,
68 OCCoAPToken * * rcvdTokenLoc);
70 // Internal function to create OCResponse struct at the client from a received coap pdu
71 OCStackResult FormOCResponse(const coap_queue_t * rcvdResponse,
72 OCResponse * * responseLoc);
74 // Internal function to create OCClientResponse struct at the client from a received coap pdu
75 OCStackResult FormOCClientResponse(const coap_queue_t * rcvdResponse,
76 OCClientResponse * * clientResponseLoc);
78 #endif /* OCCOAPHELPER_H_ */