KNX IoT
KNX IoT Point API stack implementation
oc_core_res.h
Go to the documentation of this file.
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 // Copyright (c) 2021 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 */
21 #ifndef OC_CORE_RES_H
22 #define OC_CORE_RES_H
23 
24 #include "oc_ri.h"
25 #include "oc_programming_mode.h"
26 #include "oc_knx.h"
27 #include <stdint.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
38 #define OC_CORE_EXTERN_CONST_RESOURCE(resource_name) \
39  extern const oc_resource_t core_resource_##resource_name;
45 #define OC_CORE_RESOURCE_NAME(name) core_resource_##name
46 
51 #if defined _MSC_VER && !defined __INTEL_COMPILER
52 #define OC_CORE_CREATE_CONST_RESOURCE_INTERNAL( \
53  resource_name, next_resource, device_index, uri, iface_mask, content_format, \
54  properties, get_cb, put_cb, post_cb, delete_cb, dpt, num_resource_types, \
55  ...) \
56  _Pragma("warning(disable:4090)"); \
57  oc_ri_internal_expand_call( \
58  oc_ri_create_const_resource_internal, core_resource_##next_resource, \
59  core_resource_##resource_name, device_index, NULL, uri, dpt, iface_mask, \
60  content_format, properties, get_cb, put_cb, post_cb, delete_cb, NULL, 0, \
61  0, num_resource_types, __VA_ARGS__) _Pragma("warning(default:4090)")
62 #else
63 #define OC_CORE_CREATE_CONST_RESOURCE_INTERNAL( \
64  resource_name, next_resource, device_index, uri, iface_mask, content_format, \
65  properties, get_cb, put_cb, post_cb, delete_cb, dpt, num_resource_types, \
66  ...) \
67  _Pragma("GCC diagnostic push"); \
68  _Pragma("GCC diagnostic ignored \"-Wdiscarded-array-qualifiers\""); \
69  oc_ri_create_const_resource_internal( \
70  core_resource_##next_resource, core_resource_##resource_name, \
71  device_index, NULL, uri, dpt, iface_mask, content_format, properties, \
72  get_cb, put_cb, post_cb, delete_cb, NULL, 0, 0, num_resource_types, \
73  __VA_ARGS__); \
74  _Pragma("GCC diagnostic pop")
75 #endif
84 #if defined _MSC_VER && !defined __INTEL_COMPILER
85 #define OC_CORE_CREATE_CONST_RESOURCE_LINKED(resource_name, next_resource, \
86  ...) \
87  extern const oc_resource_t core_resource_##next_resource; \
88  oc_ri_internal_expand_call(OC_CORE_CREATE_CONST_RESOURCE_INTERNAL, \
89  resource_name, next_resource, __VA_ARGS__)
90 #else
91 #define OC_CORE_CREATE_CONST_RESOURCE_LINKED(resource_name, next_resource, \
92  ...) \
93  extern const oc_resource_t core_resource_##next_resource; \
94  OC_CORE_CREATE_CONST_RESOURCE_INTERNAL(resource_name, next_resource, \
95  __VA_ARGS__)
96 #endif
97 
105 #if defined _MSC_VER && !defined __INTEL_COMPILER
106 #define OC_CORE_CREATE_CONST_RESOURCE_FINAL(resource_name, ...) \
107  oc_resource_dummy_t core_resource_##resource_name##_final = { NULL, -1 }; \
108  oc_ri_internal_expand_call(OC_CORE_CREATE_CONST_RESOURCE_INTERNAL, \
109  resource_name, resource_name##_final, \
110  __VA_ARGS__)
111 #else
112 #define OC_CORE_CREATE_CONST_RESOURCE_FINAL(resource_name, ...) \
113  oc_resource_dummy_t core_resource_##resource_name##_final = { NULL, -1 }; \
114  OC_CORE_CREATE_CONST_RESOURCE_INTERNAL(resource_name, resource_name##_final, \
115  __VA_ARGS__)
116 #endif
117 
122 typedef void (*oc_core_init_platform_cb_t)(void *data);
123 
128 typedef void (*oc_core_add_device_cb_t)(void *data);
129 
134 typedef struct oc_platform_info_t
135 {
136  oc_string_t mfg_name;
138  void *data;
140 
145 typedef struct oc_knx_version_info_t
146 {
147  int major;
148  int minor;
149  int patch;
151 
157 typedef struct oc_device_info_t
158 {
159  oc_string_t serialnumber;
163  oc_string_t hwt;
164  oc_string_t model;
165  oc_string_t hostname;
166  uint32_t mid;
167  uint64_t fid;
168  uint32_t ia;
169  uint64_t iid;
170  uint32_t port;
171  uint32_t mport;
172  bool pm;
175  void *data;
177 
182 void oc_core_init(void);
183 
188 void oc_core_shutdown(void);
189 
200  void *data);
201 
213 oc_device_info_t *oc_core_add_device(const char *name, const char *version,
214  const char *base,
215  const char *serial_number,
216  oc_core_add_device_cb_t add_device_cb,
217  void *data);
218 
228 int oc_core_set_device_fwv(size_t device_index, int major, int minor,
229  int patch);
230 
240 int oc_core_set_device_hwv(size_t device_index, int major, int minor,
241  int patch);
251 int oc_core_set_device_ap(size_t device_index, int major, int minor, int patch);
252 
260 int oc_core_set_device_mid(size_t device_index, uint32_t mid);
261 
269 int oc_core_set_device_ia(size_t device_index, uint32_t ia);
270 
279 int oc_core_set_mid(size_t device_index, int32_t mid);
280 
288 int oc_core_set_and_store_device_ia(size_t device_index, uint32_t ia);
289 
299 int oc_core_set_device_hwt(size_t device_index, const char *hardware_type);
300 
308 int oc_core_set_device_pm(size_t device_index, bool pm);
309 
317 int oc_core_set_device_model(size_t device_index, const char *model);
318 
326 int oc_core_set_device_hostname(size_t device_index, const char *host_name);
327 
335 int oc_core_set_device_iid(size_t device_index, uint64_t iid);
336 
344 int oc_core_set_and_store_device_iid(size_t device_index, uint64_t iid);
345 
353 int oc_core_set_device_fid(size_t device_index, uint64_t fid);
354 
361 uint64_t oc_core_get_device_iid(size_t device_index);
362 
369 
377 
384 
391 void oc_core_encode_interfaces_mask(CborEncoder *parent,
392  oc_interface_mask_t iface_mask);
393 
401 const oc_resource_t *oc_core_get_resource_by_index(int type, size_t device);
402 
411  size_t device);
412 
418 void oc_check_uri(const char *uri);
419 
440 void oc_core_populate_resource(int core_resource, size_t device_index,
441  const char *uri, oc_interface_mask_t iface_mask,
442  oc_content_format_t content_format,
443  int properties, oc_request_callback_t get_cb,
444  oc_request_callback_t put_cb,
445  oc_request_callback_t post_cb,
446  oc_request_callback_t delete_cb,
447  int num_resource_types, ...);
448 
456 void oc_core_bind_dpt_resource(int core_resource, size_t device_index,
457  const char *dpt);
458 
467  oc_request_t *request);
468 
480  oc_request_t *request);
481 
493  oc_request_t *request);
494 
504  int truncated);
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 #endif /* OC_CORE_RES_H */
int oc_core_set_device_fwv(size_t device_index, int major, int minor, int patch)
set the firmware version
int oc_core_set_device_hwt(size_t device_index, const char *hardware_type)
sets the hardware type (string) input string should not be larger than 6, note that if the input is l...
struct oc_knx_version_info_t oc_knx_version_info_t
version information e.g.
int oc_core_set_device_model(size_t device_index, const char *model)
sets the model (string)
oc_platform_info_t * oc_core_init_platform(const char *mfg_name, oc_core_init_platform_cb_t init_cb, void *data)
initialize the platform
int oc_core_set_device_mid(size_t device_index, uint32_t mid)
sets the manufacturer id
int oc_core_set_device_fid(size_t device_index, uint64_t fid)
sets the fabric identifier (fid)
int oc_core_set_device_hwv(size_t device_index, int major, int minor, int patch)
sets the hardware version number
oc_device_info_t * oc_core_add_device(const char *name, const char *version, const char *base, const char *serial_number, oc_core_add_device_cb_t add_device_cb, void *data)
Add device to the platform.
uint64_t oc_core_get_device_iid(size_t device_index)
sets the installation identifier (iid) (unsigned int)
int oc_filter_resource_by_urn(const oc_resource_t *resource, oc_request_t *request)
remove "urn:knx" from response when already provided in query
bool oc_filter_resource_by_if(const oc_resource_t *resource, oc_request_t *request)
filter if the query parameters of the request contains the resource (determined by resource type "if"...
void oc_core_shutdown(void)
shutdown the core functionality
void oc_core_bind_dpt_resource(int core_resource, size_t device_index, const char *dpt)
bind dpt to a core resource
int oc_frame_interfaces_mask_in_response(oc_interface_mask_t iface_mask, int truncated)
frame the interface mask in the response, as string in the uri example: full tag if= ":if....
void(* oc_core_init_platform_cb_t)(void *data)
callback for initializing the platform
Definition: oc_core_res.h:122
const oc_resource_t * oc_core_get_resource_by_uri(const char *uri, size_t device)
retrieve the resource by uri
bool oc_filter_resource_by_rt(const oc_resource_t *resource, oc_request_t *request)
filter if the query parameters of the request contains the resource (determined by resource type "rt"...
const oc_resource_t * oc_core_get_resource_by_index(int type, size_t device)
retrieve the resource by type (e.g.
struct oc_platform_info_t oc_platform_info_t
platform information
int oc_core_set_device_iid(size_t device_index, uint64_t iid)
sets the installation identifier (iid) (unsigned int)
int oc_core_set_device_ap(size_t device_index, int major, int minor, int patch)
sets the application version number
int oc_core_set_and_store_device_ia(size_t device_index, uint32_t ia)
sets and stores the internal address
size_t oc_core_get_num_devices(void)
retrieve the amount of devices
void oc_check_uri(const char *uri)
Ensure that the given URI starts with a forward slash.
int oc_core_set_device_pm(size_t device_index, bool pm)
sets the programming mode (boolean)
void(* oc_core_add_device_cb_t)(void *data)
callback for adding a device
Definition: oc_core_res.h:128
int oc_core_set_device_ia(size_t device_index, uint32_t ia)
sets the internal address
int oc_core_set_device_hostname(size_t device_index, const char *host_name)
sets the host name (string)
int oc_core_set_and_store_device_iid(size_t device_index, uint64_t iid)
sets the installation identifier (iid) and store it
oc_device_info_t * oc_core_get_device_info(size_t device)
retrieve the device info from the device index
int oc_core_set_mid(size_t device_index, int32_t mid)
sets the manufacturer id
oc_platform_info_t * oc_core_get_platform_info(void)
retrieve the platform information
struct oc_device_info_t oc_device_info_t
device information
void oc_core_init(void)
initialize the core functionality
void oc_core_encode_interfaces_mask(CborEncoder *parent, oc_interface_mask_t iface_mask)
encode the interfaces with the cbor (payload) encoder
void oc_core_populate_resource(int core_resource, size_t device_index, const char *uri, oc_interface_mask_t iface_mask, oc_content_format_t content_format, int properties, oc_request_callback_t get_cb, oc_request_callback_t put_cb, oc_request_callback_t post_cb, oc_request_callback_t delete_cb, int num_resource_types,...)
populate core resource mainly used for creation of core resources
implementation of /.well-known/knx and /k resources
enum oc_lsm_state oc_lsm_state_t
LSM state machine values.
programming mode code
resource internals
oc_content_format_t
payload content formats
Definition: oc_ri.h:184
oc_interface_mask_t
interface masks security access scopes defined as interfaces note that scope = 1 is not used.
Definition: oc_ri.h:261
void(* oc_request_callback_t)(oc_request_t *, oc_interface_mask_t, void *)
request callback
Definition: oc_ri.h:433
device information
Definition: oc_core_res.h:158
oc_knx_version_info_t fwv
fwv firmware version
Definition: oc_core_res.h:161
oc_lsm_state_t lsm_s
knx lsm states
Definition: oc_core_res.h:173
oc_string_t hwt
knx hardware type, should not be larger than 6 chars
Definition: oc_core_res.h:163
uint32_t ia
knx ia Device individual address
Definition: oc_core_res.h:168
oc_string_t hostname
knx host name
Definition: oc_core_res.h:165
oc_knx_version_info_t ap
fwv application version
Definition: oc_core_res.h:162
oc_knx_version_info_t hwv
knx hardware version
Definition: oc_core_res.h:160
void * data
user data
Definition: oc_core_res.h:175
uint64_t fid
knx fabric id
Definition: oc_core_res.h:167
uint32_t port
coap port number
Definition: oc_core_res.h:170
oc_string_t model
knx model
Definition: oc_core_res.h:164
oc_core_add_device_cb_t add_device_cb
callback when device is changed
Definition: oc_core_res.h:174
oc_string_t serialnumber
knx serial number
Definition: oc_core_res.h:159
uint32_t mid
knx manufactorer ID
Definition: oc_core_res.h:166
uint64_t iid
knx iid (installation id)
Definition: oc_core_res.h:169
bool pm
knx programming mode
Definition: oc_core_res.h:172
uint32_t mport
multicast port number
Definition: oc_core_res.h:171
version information e.g.
Definition: oc_core_res.h:146
int patch
patch version number
Definition: oc_core_res.h:149
int major
major version number
Definition: oc_core_res.h:147
int minor
minor version number
Definition: oc_core_res.h:148
platform information
Definition: oc_core_res.h:135
oc_string_t mfg_name
manufacturer name
Definition: oc_core_res.h:136
oc_core_init_platform_cb_t init_platform_cb
callback function
Definition: oc_core_res.h:137
void * data
user data for the callback function
Definition: oc_core_res.h:138
request information structure
Definition: oc_ri.h:412
resource structure
Definition: oc_ri.h:482