KNX IoT
KNX IoT Point API stack implementation
oc_endpoint.h
Go to the documentation of this file.
1 /*
2 // Copyright (c) 2017, 2020 Intel Corporation
3 // Copyright (c) 2023 Cascoda Ltd
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 */
22 #ifndef OC_ENDPOINT_H
23 #define OC_ENDPOINT_H
24 
25 #include "oc_helpers.h"
26 #include "oc_uuid.h"
27 
28 #include "messaging/coap/oscore_constants.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
38 typedef struct
39 {
40  uint16_t port;
41  uint8_t address[16];
42  uint8_t scope;
44 
49 typedef struct
50 {
51  uint16_t port;
52  uint8_t address[4];
54 
60  DISCOVERY = 1 << 0,
61  SECURED = 1 << 1,
62  IPV4 = 1 << 2,
63  IPV6 = 1 << 3,
64  TCP = 1 << 4,
65  OSCORE = 1 << 5,
66  MULTICAST = 1 << 6,
67  ACCEPTED = 1 << 7,
68  OSCORE_DECRYPTED = 1 << 8,
69  OSCORE_ENCRYPTED = 1 << 9,
70 };
71 
72 #define SERIAL_NUM_SIZE (12)
77 typedef struct oc_endpoint_t
78 {
79  struct oc_endpoint_t *next;
80  size_t device;
81  enum transport_flags flags;
82  // oc_string_t
83  // oscore_id; /**< OSCORE context (binary), e.g. binary serial number*/
86  size_t oscore_id_len;
87  union dev_addr {
88  oc_ipv6_addr_t ipv6;
89  oc_ipv4_addr_t ipv4;
90  } addr, addr_local;
92  uint8_t priority;
93  uint32_t group_address;
97  int32_t
101  uint8_t request_piv[OSCORE_PIV_LEN];
102  uint8_t request_piv_len;
103  uint8_t kid_len;
104  uint8_t kid[OSCORE_CTXID_LEN];
105  uint8_t kid_ctx_len;
106  uint8_t kid_ctx[OSCORE_IDCTX_LEN];
107  // bool rx_msg_is_response;
109 
110 #define oc_make_ipv4_endpoint(__name__, __flags__, __port__, ...) \
111  oc_endpoint_t __name__ = { .flags = __flags__, \
112  .addr.ipv4 = { .port = __port__, \
113  .address = { __VA_ARGS__ } } }
114 #define oc_make_ipv6_endpoint(__name__, __flags__, __port__, ...) \
115  oc_endpoint_t __name__ = { .flags = __flags__, \
116  .device = 0, \
117  .group_address = 0, \
118  .addr.ipv6 = { .port = __port__, \
119  .address = { __VA_ARGS__ } } }
120 
127 
134 
144  char *oscore_str_id);
145 
155 int oc_endpoint_set_oscore_id(oc_endpoint_t *endpoint, char *oscore_id,
156  int oscore_id_len);
157 
164 void oc_endpoint_set_auth_at_index(oc_endpoint_t *endpoint, int32_t index);
165 
174 int oc_endpoint_to_string(oc_endpoint_t *endpoint, oc_string_t *endpoint_str);
175 
184 int oc_string_to_endpoint(oc_string_t *endpoint_str, oc_endpoint_t *endpoint,
185  oc_string_t *uri);
186 
194 int oc_endpoint_string_parse_path(oc_string_t *endpoint_str, oc_string_t *path);
195 
203 
211 int oc_endpoint_compare(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2);
212 
221  const oc_endpoint_t *ep2);
222 
229 void oc_endpoint_set_local_address(oc_endpoint_t *ep, int interface_index);
230 
238 
246 
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif /* OC_ENDPOINT_H */
#define SERIAL_NUM_SIZE
binary: 6 bytes: in hex: 12 bytes
Definition: oc_endpoint.h:72
struct oc_endpoint_t oc_endpoint_t
the endpoint information
void oc_endpoint_set_auth_at_index(oc_endpoint_t *endpoint, int32_t index)
set auth at index for the endpoint, e.g.
int oc_endpoint_compare(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2)
compare endpoint
int oc_endpoint_set_oscore_id(oc_endpoint_t *endpoint, char *oscore_id, int oscore_id_len)
set the OSCORE identifier (SID)
void oc_endpoint_list_copy(oc_endpoint_t **dst, oc_endpoint_t *src)
copy list of endpoint
int oc_endpoint_string_parse_path(oc_string_t *endpoint_str, oc_string_t *path)
parse endpoint
void oc_endpoint_print(oc_endpoint_t *ep)
print the (first) endpoint to std out
int oc_string_to_endpoint(oc_string_t *endpoint_str, oc_endpoint_t *endpoint, oc_string_t *uri)
string to endpoint
oc_endpoint_t * oc_new_endpoint(void)
create new endpoint
int oc_endpoint_set_oscore_id_from_str(oc_endpoint_t *endpoint, char *oscore_str_id)
set the OSCORE identifier (SID)
transport_flags
transport flags (bit map) these flags are used to determine what to do on communication level
Definition: oc_endpoint.h:59
@ DISCOVERY
used for discovery
Definition: oc_endpoint.h:60
@ SECURED
secure communication
Definition: oc_endpoint.h:61
@ MULTICAST
multicast enabled
Definition: oc_endpoint.h:66
@ ACCEPTED
accepted
Definition: oc_endpoint.h:67
@ OSCORE_DECRYPTED
OSCORE decrypted message.
Definition: oc_endpoint.h:68
@ OSCORE_ENCRYPTED
OSCORE encrypted message.
Definition: oc_endpoint.h:69
@ TCP
tcp communication
Definition: oc_endpoint.h:64
@ OSCORE
OSCORE communication.
Definition: oc_endpoint.h:65
@ IPV4
ipv4 communication
Definition: oc_endpoint.h:62
@ IPV6
ipv6 communication
Definition: oc_endpoint.h:63
void oc_endpoint_copy(oc_endpoint_t *dst, oc_endpoint_t *src)
copy endpoint
int oc_endpoint_compare_address(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2)
compare address of the endpoint
int oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint)
is endpoint (ipv6) link local
int oc_endpoint_to_string(oc_endpoint_t *endpoint, oc_string_t *endpoint_str)
convert the endpoint to a human readable string (e.g.
void oc_free_endpoint(oc_endpoint_t *endpoint)
free endpoint
void oc_endpoint_set_local_address(oc_endpoint_t *ep, int interface_index)
set interface index on the endpoint
generic helpers
uuid implementationGenerate and work with UUIDs as specified in RFC 4122.
the endpoint information
Definition: oc_endpoint.h:78
uint8_t priority
priority
Definition: oc_endpoint.h:92
char oscore_id[SERIAL_NUM_SIZE+1]
OSCORE context (binary), e.g.
Definition: oc_endpoint.h:84
uint8_t request_piv[OSCORE_PIV_LEN]
OSCORE partial iv.
Definition: oc_endpoint.h:101
int32_t auth_at_index
auth at index +1 [1-max_indexes], 0 == error.
Definition: oc_endpoint.h:98
enum transport_flags flags
the transport flags
Definition: oc_endpoint.h:81
size_t device
device index
Definition: oc_endpoint.h:80
struct oc_endpoint_t * next
pointer to the next structure
Definition: oc_endpoint.h:79
uint8_t request_piv_len
OSCORE partial iv length.
Definition: oc_endpoint.h:102
int interface_index
interface index
Definition: oc_endpoint.h:91
uint32_t group_address
group address, being used to find back the OSCORE credential to be used for encryption for s-mode mes...
Definition: oc_endpoint.h:93
ipv4 data structure
Definition: oc_endpoint.h:50
uint16_t port
port
Definition: oc_endpoint.h:51
ipv6 data structure
Definition: oc_endpoint.h:39
uint16_t port
port number
Definition: oc_endpoint.h:40
uint8_t scope
scope of the address (multicast)
Definition: oc_endpoint.h:42