2c8258199ca44682bd97d87244c13b2af2c404ce
[platform/upstream/iotivity.git] / csdk / occoap / include / occoap.h
1 //******************************************************************
2 ///
3 // Copyright 2014 Intel Mobile Communications GmbH 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 #ifndef OCCOAP_H_
22 #define OCCOAP_H_
23
24 //-----------------------------------------------------------------------------
25 // Includes
26 //-----------------------------------------------------------------------------
27 #include "ocstack.h"
28 #include "occoaptoken.h"
29 #include "ocstackinternal.h"
30 #include "occoaphelper.h"
31 #include <stdint.h>
32
33 //-----------------------------------------------------------------------------
34 // Function Prototypes
35 //-----------------------------------------------------------------------------
36
37 uint32_t GetTime(float afterSeconds);
38
39 /**
40  * Initialize the CoAP client or server with the its IPv4 address and CoAP port
41  *
42  * @param ipAddr
43  *     IP Address of host device
44  * @param port
45  *     Port of host device
46  * @param mode
47  *     Host device is client, server, or client-server
48  *
49  * @return
50  *   0   - success
51  *   TBD - TBD error
52  */
53 OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode);
54
55 /**
56  * Discover OC resources
57  *
58  * @param method          - method to perform on the resource
59  * @param qos             - CON or NON requests
60  * @param token           - pointer to the token data structure
61  * @param Uri             - URI of the resource to interact with
62  * @param payload         - CoAP PDU payload
63  * @param options         - The address of an array containing the vendor specific
64  *                          header options to be sent with the request
65  * @param numOptions      - The number of header options to be included
66  * @return
67  *   0   - success
68  *   TBD - TBD error
69  */
70 OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * token,
71         const char *Uri, const char *payload, OCHeaderOption * options, uint8_t numOptions);
72
73
74 /**
75  * Stop the CoAP client or server processing
76  *
77  * @return 0 - success, else - TBD error
78  */
79 OCStackResult OCStopCoAP();
80
81 /**
82  * Called in main loop of CoAP client or server.  Allows low-level CoAP processing of
83  * send, receive, timeout, discovery, callbacks, etc.
84  *
85  * @return 0 - success, else - TBD error
86  */
87 OCStackResult OCProcessCoAP();
88
89 /**
90  * This method is called to generate a token of MAX_TOKEN_LENGTH.
91  * This token is used to co-relate client requests with server responses.
92  *
93  */
94 void OCGenerateCoAPToken(OCCoAPToken * token);
95
96 /**
97  * Initiate sending of CoAP messages. Example: server uses it to send observe messages
98  *
99  * @return 0 - success, else - TBD error
100  */
101 OCStackResult OCSendCoAPNotification (unsigned char * uri, OCDevAddr *dstAddr,
102         OCQualityOfService qos, OCCoAPToken * token,
103         unsigned char *payload, OCResource *resPtr, uint32_t maxAge);
104
105 #endif /* OCCOAP_H_ */