oc_connectivity.h 4.77 KB
Newer Older
Kishen Maloor's avatar
Kishen Maloor committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
George Nash's avatar
George Nash committed
16 17 18
/**
  @file
*/
Kishen Maloor's avatar
Kishen Maloor committed
19 20
#ifndef OC_CONNECTIVITY_H
#define OC_CONNECTIVITY_H
Kishen Maloor's avatar
Kishen Maloor committed
21

22
#include "messaging/coap/conf.h"
23
#include "oc_config.h"
24
#include "oc_endpoint.h"
Kishen Maloor's avatar
Kishen Maloor committed
25
#include "oc_network_events.h"
26
#include "oc_session_events.h"
Kishen Maloor's avatar
Kishen Maloor committed
27 28 29
#include "port/oc_log.h"
#include "util/oc_process.h"
#include <stdint.h>
Kishen Maloor's avatar
Kishen Maloor committed
30

31
#ifdef __cplusplus
32
extern "C" {
33 34
#endif

35 36
#ifndef OC_DYNAMIC_ALLOCATION
#ifndef OC_MAX_APP_DATA_SIZE
37
#error "Set OC_MAX_APP_DATA_SIZE in oc_config.h"
38
#endif /* !OC_MAX_APP_DATA_SIZE */
39 40

#ifdef OC_BLOCK_WISE_SET_MTU
41
#define OC_BLOCK_WISE
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#if OC_BLOCK_WISE_SET_MTU < (COAP_MAX_HEADER_SIZE + 16)
#error "OC_BLOCK_WISE_SET_MTU must be >= (COAP_MAX_HEADER_SIZE + 2^4)"
#endif /* OC_BLOCK_WISE_SET_MTU is too small */
#define OC_MAX_BLOCK_SIZE (OC_BLOCK_WISE_SET_MTU - COAP_MAX_HEADER_SIZE)
#define OC_BLOCK_SIZE                                                          \
  (OC_MAX_BLOCK_SIZE < 32                                                      \
     ? 16                                                                      \
     : (OC_MAX_BLOCK_SIZE < 64                                                 \
          ? 32                                                                 \
          : (OC_MAX_BLOCK_SIZE < 128                                           \
               ? 64                                                            \
               : (OC_MAX_BLOCK_SIZE < 256                                      \
                    ? 128                                                      \
                    : (OC_MAX_BLOCK_SIZE < 512                                 \
                         ? 256                                                 \
                         : (OC_MAX_BLOCK_SIZE < 1024                           \
                              ? 512                                            \
                              : (OC_MAX_BLOCK_SIZE < 2048 ? 1024 : 2048)))))))
#else /* OC_BLOCK_WISE_SET_MTU */
61
#define OC_BLOCK_SIZE (OC_MAX_APP_DATA_SIZE)
62
#endif /* !OC_BLOCK_WISE_SET_MTU */
63

64
enum {
65
#ifdef OC_TCP // TODO: need to check about tls packet.
Jaehyun Cho's avatar
Jaehyun Cho committed
66 67
  OC_PDU_SIZE = (OC_MAX_APP_DATA_SIZE + COAP_MAX_HEADER_SIZE)
#else /* OC_TCP */
68
#ifdef OC_SECURITY
69
  OC_PDU_SIZE = (2 * OC_BLOCK_SIZE + COAP_MAX_HEADER_SIZE)
70 71 72
#else  /* OC_SECURITY */
  OC_PDU_SIZE = (OC_BLOCK_SIZE + COAP_MAX_HEADER_SIZE)
#endif /* !OC_SECURITY */
Jaehyun Cho's avatar
Jaehyun Cho committed
73
#endif /* !OC_TCP */
74
};
75
#else /* !OC_DYNAMIC_ALLOCATION */
76 77 78
#ifdef __cplusplus
}
#endif
79
#include "oc_buffer_settings.h"
80
#ifdef __cplusplus
81
extern "C" {
82
#endif
Jaehyun Cho's avatar
Jaehyun Cho committed
83 84 85
#ifdef OC_TCP
#define OC_PDU_SIZE (oc_get_max_app_data_size() + COAP_MAX_HEADER_SIZE)
#else /* OC_TCP */
86
#define OC_PDU_SIZE (oc_get_mtu_size())
Jaehyun Cho's avatar
Jaehyun Cho committed
87
#endif /* !OC_TCP */
88 89 90
#define OC_BLOCK_SIZE (oc_get_block_size())
#define OC_MAX_APP_DATA_SIZE (oc_get_max_app_data_size())
#endif /* OC_DYNAMIC_ALLOCATION */
91

92
struct oc_message_s
Kishen Maloor's avatar
Kishen Maloor committed
93
{
Kishen Maloor's avatar
Kishen Maloor committed
94
  struct oc_message_s *next;
95
  struct oc_memb *pool;
Kishen Maloor's avatar
Kishen Maloor committed
96 97
  oc_endpoint_t endpoint;
  size_t length;
Kishen Maloor's avatar
Kishen Maloor committed
98
  uint8_t ref_count;
99 100 101
#ifdef OC_DYNAMIC_ALLOCATION
  uint8_t *data;
#else  /* OC_DYNAMIC_ALLOCATION */
102
  uint8_t data[OC_PDU_SIZE];
103
#endif /* OC_DYNAMIC_ALLOCATION */
Kishen Maloor's avatar
Kishen Maloor committed
104 105 106
#ifdef OC_TCP
  size_t read_offset;
#endif /* OC_TCP */
107 108 109
#ifdef OC_SECURITY
  uint8_t encrypted;
#endif
110
};
Kishen Maloor's avatar
Kishen Maloor committed
111

112
int oc_send_buffer(oc_message_t *message);
Kishen Maloor's avatar
Kishen Maloor committed
113

George Nash's avatar
George Nash committed
114
int oc_connectivity_init(size_t device);
Kishen Maloor's avatar
Kishen Maloor committed
115

George Nash's avatar
George Nash committed
116
void oc_connectivity_shutdown(size_t device);
Kishen Maloor's avatar
Kishen Maloor committed
117

118
void oc_send_discovery_request(oc_message_t *message);
Kishen Maloor's avatar
Kishen Maloor committed
119

Kishen Maloor's avatar
Kishen Maloor committed
120 121
void oc_connectivity_end_session(oc_endpoint_t *endpoint);

Jaehong Jo's avatar
Jaehong Jo committed
122
#ifdef OC_DNS_LOOKUP
123 124 125 126 127
int oc_dns_lookup(const char *domain, oc_string_t *addr,
                  enum transport_flags flags);
#ifdef OC_DNS_CACHE
void oc_dns_clear_cache(void);
#endif /* OC_DNS_CACHE */
Jaehong Jo's avatar
Jaehong Jo committed
128 129
#endif /* OC_DNS_LOOKUP */

George Nash's avatar
George Nash committed
130
oc_endpoint_t *oc_connectivity_get_endpoints(size_t device);
131

132 133 134 135 136
void handle_network_interface_event_callback(oc_interface_event_t event);

void handle_session_event_callback(const oc_endpoint_t *endpoint,
                                   oc_session_state_t state);

Jaehyun Cho's avatar
Jaehyun Cho committed
137 138 139 140 141 142 143 144
#ifdef OC_TCP
/* TCP CSM states */
typedef enum { CSM_NONE, CSM_SENT, CSM_DONE, CSM_ERROR = 255 } tcp_csm_state_t;

tcp_csm_state_t oc_tcp_get_csm_state(oc_endpoint_t *endpoint);
int oc_tcp_update_csm_state(oc_endpoint_t *endpoint, tcp_csm_state_t csm);
#endif /* OC_TCP */

145 146 147 148
#ifdef __cplusplus
}
#endif

Kishen Maloor's avatar
Kishen Maloor committed
149
#endif /* OC_CONNECTIVITY_H */