24 #include "oc_config.h"
28 #include "util/oc_etimer.h"
29 #if defined _MSC_VER && !defined __INTEL_COMPILER
30 #define oc_ri_internal_expand(...) __VA_ARGS__
31 #define oc_ri_internal_expand_call(fn, ...) \
32 oc_ri_internal_expand_call2(fn, (__VA_ARGS__))
33 #define oc_ri_internal_expand_call2(fn, args) fn args
36 #if defined _MSC_VER && !defined __INTEL_COMPILER
37 #define oc_ri_create_const_resource_internal( \
38 next_resource, resource_name, device_index, name, uri, dpt, iface_mask, \
39 content_format, properties, get_cb, put_cb, post_cb, delete_cb, ctx, \
40 observe_period, instance, ...) \
41 oc_resource_data_t resource_name##_data; \
42 const oc_resource_t resource_name = { \
43 (oc_resource_t *)&next_resource, \
45 oc_string_create_const(name), \
46 oc_string_create_const(uri), \
47 oc_ri_internal_expand_call(oc_string_array_create_const, __VA_ARGS__), \
48 oc_string_create_const(dpt), \
61 &resource_name##_data, \
64 #define oc_ri_create_const_resource_internal( \
65 next_resource, resource_name, device_index, name, uri, dpt, iface_mask, \
66 content_format, properties, get_cb, put_cb, post_cb, delete_cb, ctx, \
67 observe_period, instance, ...) \
68 oc_resource_data_t resource_name##_data; \
69 const oc_resource_t resource_name = { \
70 (oc_resource_t *)&next_resource, \
72 oc_string_create_const(name), \
73 oc_string_create_const(uri), \
74 oc_string_array_create_const(__VA_ARGS__), \
75 oc_string_create_const(dpt), \
88 &resource_name##_data, \
92 #if defined _MSC_VER && !defined __INTEL_COMPILER
93 #define oc_ri_create_const_resource_linked(next_resource, ...) \
94 extern const oc_resource_t next_resource; \
95 oc_ri_internal_expand_call(oc_ri_create_const_resource_internal, \
96 next_resource, __VA_ARGS__)
98 #define oc_ri_create_const_resource_linked(next_resource, ...) \
99 extern const oc_resource_t next_resource; \
100 oc_ri_create_const_resource_internal(next_resource, __VA_ARGS__)
103 #if defined _MSC_VER && !defined __INTEL_COMPILER
104 #define oc_ri_create_const_resource_final(resource_name, ...) \
105 oc_resource_dummy_t resource_block_end##resource_name = { NULL, -1 }; \
106 oc_ri_internal_expand_call(oc_ri_create_const_resource_internal, \
107 resource_block_end##resource_name, resource_name, \
110 #define oc_ri_create_const_resource_final(resource_name, ...) \
111 oc_resource_dummy_t resource_block_end##resource_name = { NULL, -1 }; \
113 oc_ri_create_const_resource_internal(resource_block_end##resource_name, \
114 resource_name, __VA_ARGS__)
173 __NUM_OC_STATUS_CODES__,
216 APPLICATION_PKCS7_CO =
279 #define OC_MAX_IF_MASKS 14
316 oc_string_array_t interface_array);
361 #ifdef OC_PUBLISHER_TABLE
403 #define OC_NUM_CORE_RESOURCES_PER_DEVICE (1 + WELLKNOWNCORE)
472 typedef struct oc_resource_data_t
474 uint8_t num_observers;
475 } oc_resource_data_t;
505 typedef struct oc_resource_dummy_s
509 } oc_resource_dummy_t;
511 typedef struct oc_link_s oc_link_t;
531 struct oc_etimer
timer;
556 oc_trigger_t event_callback,
557 oc_clock_time_t ticks);
566 #define oc_ri_add_timed_event_callback_seconds(cb_data, event_callback, \
569 oc_ri_add_timed_event_callback_ticks(cb_data, event_callback, \
570 (oc_clock_time_t)(seconds) * \
571 (oc_clock_time_t)OC_CLOCK_SECOND); \
581 oc_trigger_t event_callback);
700 char **key,
size_t *key_len,
char **value,
701 size_t *value_len,
size_t n);
736 size_t *key_len,
size_t n);
end point implementation, e.g.
request and response payload handling in cbor
int oc_ri_get_query_nth_key_value(const char *query, size_t query_len, char **key, size_t *key_len, char **value, size_t *value_len, size_t n)
retrieve the query value at the nth position
void oc_ri_add_timed_event_callback_ticks(void *cb_data, oc_trigger_t event_callback, oc_clock_time_t ticks)
add timed event callback
oc_status_t
CoAP status codes.
@ OC_STATUS_NOT_IMPLEMENTED
Not Implemented 5.01.
@ OC_STATUS_REQUEST_ENTITY_TOO_LARGE
Request Entity Too Large 4.13.
@ OC_STATUS_BAD_REQUEST
Bad Request 4.00.
@ OC_IGNORE
Ignore: do not respond to request.
@ OC_STATUS_INTERNAL_SERVER_ERROR
Internal Server Error 5.00.
@ OC_STATUS_NOT_FOUND
Not Found 4.04.
@ OC_STATUS_GATEWAY_TIMEOUT
Gateway Timeout 5.04.
@ OC_STATUS_NOT_ACCEPTABLE
Not Acceptable 4.06.
@ OC_STATUS_DELETED
Deleted 2.02.
@ OC_STATUS_CREATED
Created 2.01.
@ OC_STATUS_METHOD_NOT_ALLOWED
Method Not Allowed 4.05.
@ OC_STATUS_PROXYING_NOT_SUPPORTED
Proxying not supported 5.05.
@ OC_STATUS_NOT_MODIFIED
Not Modified (VALID 2.03)
@ OC_STATUS_CHANGED
Changed 2.04.
@ OC_STATUS_BAD_OPTION
Bad Option 4.02.
@ OC_STATUS_UNAUTHORIZED
Unauthorized 4.01.
@ OC_STATUS_UNSUPPORTED_MEDIA_TYPE
Unsupported Media Type 4.15.
@ OC_PING_TIMEOUT
Ping Time out.
@ OC_STATUS_BAD_GATEWAY
Bad Gateway 5.02.
@ OC_STATUS_SERVICE_UNAVAILABLE
Service Unavailable 5.03.
@ OC_STATUS_FORBIDDEN
Forbidden 4.03.
const oc_resource_t * oc_ri_get_app_resources(void)
retrieve list of resources
bool oc_ri_delete_resource(const oc_resource_t *resource)
remove the resource from the list of application resources
bool oc_check_accept_header(oc_request_t *request, oc_content_format_t accept)
checks if the accept header is correct note that if the accept header is not there,...
int oc_ri_query_exists(const char *query, size_t query_len, const char *key)
checks if key exist in query
const char * get_interface_string(oc_interface_mask_t mask)
Get the interface string object Note: should be called with a single interface as mask only.
int oc_get_interface_in_mask_in_string_array(oc_interface_mask_t iface_mask, int nr_entries, oc_string_array_t interface_array)
sets all interfaces in the mask in the string array
struct oc_response_buffer_s oc_response_buffer_t
response buffer type
bool oc_ri_add_resource(oc_resource_t *resource)
add resource to the system
void oc_ri_free_resource_properties(oc_resource_t *resource)
free the properties of the resource
const char * get_method_name(oc_method_t method)
Get the method name object.
oc_resource_data_t * oc_ri_alloc_resource_data(void)
allocate a resource structure
struct oc_request_handler_s oc_request_handler_t
request handler type
void oc_ri_remove_timed_event_callback(void *cb_data, oc_trigger_t event_callback)
remove the timed event callback
oc_event_callback_retval_t
callback return values
@ OC_EVENT_DONE
callback done, e.g.
@ OC_EVENT_CONTINUE
callbacks continue
bool oc_ri_new_request_from_request(oc_request_t *new_request, oc_request_t *request, oc_response_buffer_t *response_buffer, oc_response_t *response_obj)
create a new request from the old request is used internally only for redirection of:
oc_interface_mask_t oc_ri_get_interface_mask(char *iface, size_t if_len)
retrieve the interface mask from the interface name
oc_resource_t * oc_ri_alloc_resource(void)
allocate a resource structure
const oc_resource_t * oc_ri_resource_next(const oc_resource_t *resource)
get the next resource
int oc_ri_get_query_value(const char *query, size_t query_len, const char *key, char **value)
retrieve the value of the query parameter "key"
oc_content_format_t
payload content formats
@ APPLICATION_VND_OMA_LWM2M_JSON
application/vnd.oma.lwm2m+json
@ APPLICATION_SOAP_FASTINFOSET
application
@ APPLICATION_RDF_XML
application - not used
@ APPLICATION_CRATTRS
application/csrattrs
@ APPLICATION_PKCS7_CMC_RESPONSE
application/pkcs7-mime; smime-type=CMC-Response
@ APPLICATION_FASTINFOSET
application
@ APPLICATION_OCTET_STREAM
application/octet-stream
@ APPLICATION_SENSML_CBOR
application/sensml+cbor
@ APPLICATION_VND_OMA_LWM2M_CBOR
application/vnd.oma.lwm2m+cbor
@ AUDIO_RAW
audio/raw - not used
@ APPLICATION_PKCS7_SGK
application/pkcs7-mime; smime-type=server-generated-key
@ APPLICATION_PKIX_CERT
application/pkix-cert
@ IMAGE_PNG
image/png - not used
@ APPLICATION_PKCS8
application/pkcs8
@ APPLICATION_SENML_CBOR
application/senml+cbor
@ APPLICATION_OSCORE
application/oscore
@ APPLICATION_ATOM_XML
application - not used
@ IMAGE_GIF
image/gif - not used
@ APPLICATION_CBOR
application/cbor
@ APPLICATION_VND_OCF_CBOR
application/vnd.ocf+cbor
@ APPLICATION_SENSML_EXI
application/sensml-exi
@ APPLICATION_SENML_EXI
application/senml-exi
@ APPLICATION_PKCS7_CMC_REQUEST
application/pkcs7-mime; smime-type=CMC-Request
@ APPLICATION_X_OBIX_BINARY
application - not used
@ CONTENT_NONE
no content format
@ APPLICATION_LINK_FORMAT
application/link-format
@ APPLICATION_SENSML_JSON
application/sensml+json
@ APPLICATION_VND_OMA_LWM2M_TLV
application/vnd.oma.lwm2m+tlv
@ APPLICATION_SENML_JSON
application/senml+json
@ IMAGE_TIFF
image/tiff - not used
@ APPLICATION_PKCS10
application/pkcs10
@ APPLICATION_JSON
application/json
@ APPLICATION_SOAP_XML
application/soap - not used
@ IMAGE_JPEG
image/jpeg - not used
@ APPLICATION_XMPP_XML
application - not used
@ VIDEO_RAW
video/raw - not used
@ APPLICATION_EXI
application/exi
@ APPLICATION_XML
application/xml
void oc_ri_init(void)
initialize the resource implementation handler
struct oc_event_callback_s oc_event_callback_t
event callback
int oc_status_code(oc_status_t key)
convert the (internal) status code to coap status as integer
oc_interface_mask_t
interface masks security access scopes defined as interfaces note that scope = 1 is not used.
@ OC_IF_M
if.m (manufacturer) (16384)
@ OC_IF_NONE
no interface defined
oc_core_resource_t
core resource numbers
@ OC_A_LSM
load state machine
@ OC_DEV_IID
KNX installation ID.
@ OC_KNX_SWU_PKGV
sw package version
@ OC_DEV_HOSTNAME
Device host name for DNS resolution.
@ OC_KNX_A_SEN
a/sen resource
@ OC_KNX_SWU_PROTOCOL
software update protocol
@ OC_KNX_AUTH_O_OSNDELAY
oscore osn delay
@ OC_KNX_SWU_MAXDEFER
swu max defer
@ OC_DEV_FWV
Firmware version.
@ OC_KNX
.well-known / knx
@ OC_KNX_SWU
swu top level
@ OC_KNX_K
k (renamed) .knx resource
@ OC_KNX_SWU_PKGBYTES
sw package bytes
@ OC_KNX_SUB
delete all device subscriptions
@ OC_KNX_SWU_PKGCMD
sw package command
@ OC_KNX_LASTUPDATE
sw last update
@ OC_KNX_SWU_RESULT
sw result
@ OC_DEV_HWV
Hardware version.
@ OC_DEV_SA
/dev/sa subnet address
@ OC_KNX_SWU_METHOD
sw method
@ OC_APP_X
application ID entry
@ OC_DEV_SN
Device serial number.
@ OC_DEV_DA
/dev/da device address
@ OC_DEV_HWT
The hardware type is a manufacture specific id for a device type (MaC uses this id for compatibility ...
@ OC_DEV_PORT
/dev/port the coap port number
@ OC_DEV_FID
/dev/fid the fabric ID
@ OC_KNX_AUTH_O
auth/o oscore functional block properties list
@ OC_APP
application ID (list)
@ OC_DEV_MODEL
Device model.
@ OC_KNX_IA
.well-known / knx / ia
@ OC_DEV_MID
/dev/mid the manufacturer ID
@ OC_KNX_SWU_STATE
sw state
@ OC_DEV_MPORT
/dev/mport the multicast port number
@ OC_KNX_SWU_PKGNAMES
sw package names
@ OC_KNX_AUTH_O_REPLWDO
oscore replay window
@ OC_KNX_SWU_PKGQURL
sw query url
@ OC_KNX_AUTH
auth list all sub resources
@ OC_KNX_SWU_UPDATE
sw update
@ OC_DEV_PM
Programming Mode.
@ OC_KNX_OSN
.well-known / knx / osn
@ OC_KNX_AUTH_AT
auth/at resource listing auth/at/X
@ OC_KNX_AUTH_AT_X
auth/at/X resources
@ WELLKNOWNCORE
well-known/core resource
@ OC_KNX_FINGERPRINT
FINGERPRINT value of loaded contents.
struct oc_separate_response_s oc_separate_response_t
separate response type
oc_resource_properties_t
resource properties (bit mask)
@ OC_SECURE_MCAST
secure multi cast (OSCORE)
@ OC_UNDISCOVERABLE
parameter
@ OC_OBSERVABLE
observable
@ OC_DISCOVERABLE
datapoint
@ OC_PERIODIC
periodical update
bool oc_ri_add_resource_block(const oc_resource_t *resource)
add resource block to the system
struct oc_request_t oc_request_t
request information structure
void oc_print_interface(oc_interface_mask_t iface_mask)
prints all interfaces in the mask to stdout
bool oc_ri_delete_resource_block(const oc_resource_t *resource)
remove the resource block from the list of application resources
int oc_total_interface_in_mask(oc_interface_mask_t iface_mask)
total interfaces in the interface mask Note calculates the if.g.s.a only 1
struct oc_properties_cb_t oc_properties_cb_t
properties callback structure
void(* oc_request_callback_t)(oc_request_t *, oc_interface_mask_t, void *)
request callback
void(* oc_get_properties_cb_t)(oc_resource_t *, oc_interface_mask_t, void *)
get properties callback
bool(* oc_set_properties_cb_t)(oc_resource_t *, oc_rep_t *, void *)
set properties callback
bool oc_ri_is_app_resource_valid(const oc_resource_t *resource)
checks if the resource is valid
int oc_ri_query_nth_key_exists(const char *query, size_t query_len, char **key, size_t *key_len, size_t n)
check if the nth key exists
const oc_resource_t * oc_ri_get_app_resource_by_uri(const char *uri, size_t uri_len, size_t device)
retrieve the resource by uri and device index
struct oc_response_t oc_response_t
response type
void oc_ri_shutdown(void)
shut down the resource implementation handler
uuid implementationGenerate and work with UUIDs as specified in RFC 4122.
struct oc_event_callback_s * next
next callback
void * data
data for the callback
oc_trigger_t callback
callback to be invoked
struct oc_etimer timer
timer
properties callback structure
parsed entry of a cbor object This represents a link list of response values one can iterate over the...
request information structure
size_t uri_path_len
path length
size_t query_len
query length
oc_endpoint_t * origin
origin of the request
oc_response_t * response
pointer to the response
oc_content_format_t content_format
content format (of the payload in the request)
const char * uri_path
path (as string)
oc_content_format_t accept
accept header, e.g the format to be returned on the request
const uint8_t * _payload
payload of the request
const char * query
query (as string)
size_t _payload_len
payload size
oc_rep_t * request_payload
request payload structure
const oc_resource_t * resource
resource structure
struct oc_resource_s * next
next resource
oc_string_t name
name of the resource (e.g.
oc_content_format_t content_type
the content format that the resource supports, e.g.
oc_request_handler_t post_handler
callback for POST
const bool is_const
Whether the associated resource data is readonly.
uint8_t fb_instance
function block instance, default = 0
oc_interface_mask_t interfaces
supported interfaces
oc_resource_properties_t properties
properties (as bit mask)
oc_properties_cb_t set_properties
callback for set properties
oc_request_handler_t delete_handler
callback for DELETE
oc_request_handler_t get_handler
callback for GET
size_t device
device index
oc_properties_cb_t get_properties
callback for get properties
oc_string_t dpt
dpt of the resource
uint16_t observe_period_seconds
observe period in seconds
oc_string_t uri
uri of the resource
oc_string_array_t types
"rt" types of the resource
oc_request_handler_t put_handler
callback for PUT
oc_resource_data_t * runtime_data
Runtime modifiable data.
oc_separate_response_t * separate_response
separate response
oc_response_buffer_t * response_buffer
response buffer