KNX IoT
KNX IoT Point API stack implementation
oc_connectivity.h
Go to the documentation of this file.
1 /*
2 // Copyright (c) 2016, 2018, 2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
20 #ifndef OC_CONNECTIVITY_H
21 #define OC_CONNECTIVITY_H
22 
23 #include "messaging/coap/conf.h"
24 #include "oc_config.h"
25 #include "oc_endpoint.h"
26 #include "oc_network_events.h"
27 #include "oc_session_events.h"
28 #include "port/oc_log.h"
29 #include "util/oc_process.h"
30 #include <stdint.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #ifndef OC_DYNAMIC_ALLOCATION
37 #ifndef OC_MAX_APP_DATA_SIZE
38 #error "Set OC_MAX_APP_DATA_SIZE in oc_config.h"
39 #endif /* !OC_MAX_APP_DATA_SIZE */
40 
41 #ifdef OC_BLOCK_WISE_SET_MTU
42 #define OC_BLOCK_WISE
43 #if OC_BLOCK_WISE_SET_MTU < (COAP_MAX_HEADER_SIZE + 16)
44 #error "OC_BLOCK_WISE_SET_MTU must be >= (COAP_MAX_HEADER_SIZE + 2^4)"
45 #endif /* OC_BLOCK_WISE_SET_MTU is too small */
46 #define OC_MAX_BLOCK_SIZE (OC_BLOCK_WISE_SET_MTU - COAP_MAX_HEADER_SIZE)
47 #define OC_BLOCK_SIZE \
48  (OC_MAX_BLOCK_SIZE < 32 \
49  ? 16 \
50  : (OC_MAX_BLOCK_SIZE < 64 \
51  ? 32 \
52  : (OC_MAX_BLOCK_SIZE < 128 \
53  ? 64 \
54  : (OC_MAX_BLOCK_SIZE < 256 \
55  ? 128 \
56  : (OC_MAX_BLOCK_SIZE < 512 \
57  ? 256 \
58  : (OC_MAX_BLOCK_SIZE < 1024 \
59  ? 512 \
60  : (OC_MAX_BLOCK_SIZE < 2048 ? 1024 : 2048)))))))
61 #else /* OC_BLOCK_WISE_SET_MTU */
62 #define OC_BLOCK_SIZE (OC_MAX_APP_DATA_SIZE)
63 #endif /* !OC_BLOCK_WISE_SET_MTU */
64 
65 enum {
66 #ifdef OC_TCP // TODO: need to check about tls packet.
67 #ifdef OC_OSCORE
68  OC_PDU_SIZE = (OC_MAX_APP_DATA_SIZE + 2 * COAP_MAX_HEADER_SIZE)
69 #else /* OC_OSCORE */
70  OC_PDU_SIZE = (OC_MAX_APP_DATA_SIZE + COAP_MAX_HEADER_SIZE)
71 #endif /* !OC_OSCORE */
72 #else /* OC_TCP */
73 #ifdef OC_SECURITY
74 #ifdef OC_OSCORE
75  OC_PDU_SIZE = (OC_BLOCK_SIZE + 2 * COAP_MAX_HEADER_SIZE)
76 #else /* OC_OSCORE */
77  OC_PDU_SIZE = (OC_BLOCK_SIZE + COAP_MAX_HEADER_SIZE)
78 #endif /* !OC_OSCORE */
79 #else /* OC_SECURITY */
80  OC_PDU_SIZE = (OC_BLOCK_SIZE + COAP_MAX_HEADER_SIZE)
81 #endif /* !OC_SECURITY */
82 #endif /* !OC_TCP */
83 };
84 #else /* !OC_DYNAMIC_ALLOCATION */
85 #ifdef __cplusplus
86 }
87 #endif
88 #include "oc_buffer_settings.h"
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 #ifdef OC_TCP
93 #ifdef OC_OSCORE
94 #define OC_PDU_SIZE (oc_get_max_app_data_size() + 2 * COAP_MAX_HEADER_SIZE)
95 #else /* OC_OSCORE */
96 #define OC_PDU_SIZE (oc_get_max_app_data_size() + COAP_MAX_HEADER_SIZE)
97 #endif /* !OC_OSCORE */
98 #else /* OC_TCP */
99 #define OC_PDU_SIZE (oc_get_mtu_size())
100 #endif /* !OC_TCP */
101 #define OC_BLOCK_SIZE (oc_get_block_size())
102 #define OC_MAX_APP_DATA_SIZE (oc_get_max_app_data_size())
103 #endif /* OC_DYNAMIC_ALLOCATION */
104 
105 struct oc_message_s
106 {
107  struct oc_message_s *next;
108  struct oc_memb *pool;
109  oc_endpoint_t endpoint;
110  oc_ipv6_addr_t mcast_dest;
111  size_t length;
112  uint8_t ref_count;
113 #ifdef OC_DYNAMIC_ALLOCATION
114 #ifdef OC_INOUT_BUFFER_SIZE
115  uint8_t data[OC_INOUT_BUFFER_SIZE];
116 #else /* OC_INOUT_BUFFER_SIZE */
117  uint8_t *data;
118 #endif /* !OC_INOUT_BUFFER_SIZE */
119 #else /* OC_DYNAMIC_ALLOCATION */
120  uint8_t data[OC_PDU_SIZE];
121 #endif /* OC_DYNAMIC_ALLOCATION */
122 #ifdef OC_TCP
123  size_t read_offset;
124 #endif /* OC_TCP */
125  uint8_t encrypted;
126  void (*soft_ref_cb)(struct oc_message_s *);
127 };
128 
135 int oc_send_buffer(oc_message_t *message);
136 
144 oc_message_t *oc_get_incoming_message_with_ptr(uint8_t *data);
145 
153 int oc_connectivity_set_port(uint32_t port);
154 
161 int oc_connectivity_init(size_t device);
162 
168 void oc_connectivity_shutdown(size_t device);
169 
175 void oc_send_discovery_request(oc_message_t *message);
176 
183 
184 #ifdef OC_DNS_LOOKUP
193 int oc_dns_lookup(const char *domain, oc_string_t *addr,
194  enum transport_flags flags);
195 #ifdef OC_DNS_CACHE
200 void oc_dns_clear_cache(void);
201 #endif /* OC_DNS_CACHE */
202 #endif /* OC_DNS_LOOKUP */
203 
211 
218 
226  oc_session_state_t state);
227 
236 
245 
246 #ifdef OC_TCP
251 typedef enum {
255  CSM_ERROR = 255
257 
265 
274 #endif /* OC_TCP */
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif /* OC_CONNECTIVITY_H */
CoAP message buffer setting implementation.
oc_endpoint_t * oc_connectivity_get_endpoints(size_t device)
retrieve list of endpoints for the device
int oc_connectivity_set_port(uint32_t port)
set the default (unicast) CoAp port to another value
void oc_connectivity_unsubscribe_mcast_ipv6(oc_endpoint_t *address)
unsubscribe to a multicast address
int oc_send_buffer(oc_message_t *message)
send buffer
tcp_csm_state_t oc_tcp_get_csm_state(oc_endpoint_t *endpoint)
retrieve the cms state
void oc_connectivity_end_session(oc_endpoint_t *endpoint)
end session for the specific endpoint
tcp_csm_state_t
The CSM states.
@ CSM_NONE
None.
@ CSM_SENT
Send.
@ CSM_DONE
Done.
@ CSM_ERROR
Error.
void oc_connectivity_shutdown(size_t device)
shut down the connectivity for device at device index
void handle_session_event_callback(const oc_endpoint_t *endpoint, oc_session_state_t state)
the session callback
int oc_connectivity_init(size_t device)
initialize the connectivity (e.g.
int oc_tcp_update_csm_state(oc_endpoint_t *endpoint, tcp_csm_state_t csm)
update the csm state on the tcp connection
void handle_network_interface_event_callback(oc_interface_event_t event)
the callback function for an network change
oc_message_t * oc_get_incoming_message_with_ptr(uint8_t *data)
get buffer of a received message
void oc_send_discovery_request(oc_message_t *message)
send discovery request
void oc_connectivity_subscribe_mcast_ipv6(oc_endpoint_t *address)
Subscribe to a multicast address.
int oc_dns_lookup(const char *domain, oc_string_t *addr, enum transport_flags flags)
DNS look up.
end point implementation, e.g.
transport_flags
transport flags (bit map) these flags are used to determine what to do on communication level
Definition: oc_endpoint.h:59
platform abstraction of logging
network events (network interfaces going up/down)
oc_interface_event_t
network events
session events
oc_session_state_t
session states
the endpoint information
Definition: oc_endpoint.h:78
ipv6 data structure
Definition: oc_endpoint.h:39