diff --git a/include/coap3/coap_session.h b/include/coap3/coap_session.h index 19d300fa..a4cc3d84 100644 --- a/include/coap3/coap_session.h +++ b/include/coap3/coap_session.h @@ -198,6 +198,15 @@ coap_proto_t coap_session_get_proto(const coap_session_t *session); */ coap_session_type_t coap_session_get_type(const coap_session_t *session); +/** + * Check if the session is using OSCORE. + * + * @param session The CoAP session. + * + * @return @c 1 if the session is using OSCORE, @c 0 otherwise. + */ +int coap_session_is_oscore(const coap_session_t *session); + /** * Get the session state * diff --git a/libcoap-3.map b/libcoap-3.map index fc08738b..d6792008 100644 --- a/libcoap-3.map +++ b/libcoap-3.map @@ -299,6 +299,7 @@ global: coap_session_get_tls; coap_session_get_type; coap_session_init_token; + coap_session_is_oscore; coap_session_max_pdu_size; coap_session_new_token; coap_session_reference; diff --git a/libcoap-3.sym b/libcoap-3.sym index a33eab23..941ba0b3 100644 --- a/libcoap-3.sym +++ b/libcoap-3.sym @@ -297,6 +297,7 @@ coap_session_get_state coap_session_get_tls coap_session_get_type coap_session_init_token +coap_session_is_oscore coap_session_max_pdu_size coap_session_new_token coap_session_reference diff --git a/man/Makefile.am b/man/Makefile.am index 6571f17a..a47ea940 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -232,6 +232,7 @@ install-man: install-man3 install-man5 install-man7 @echo ".so man3/coap_session.3" > coap_session_get_state.3 @echo ".so man3/coap_session.3" > coap_session_get_tls.3 @echo ".so man3/coap_session.3" > coap_session_get_type.3 + @echo ".so man3/coap_session.3" > coap_session_is_oscore.3 @echo ".so man3/coap_string.3" > coap_delete_bin_const.3 @echo ".so man3/coap_string.3" > coap_make_str_const.3 @echo ".so man3/coap_string.3" > coap_string_equal.3 diff --git a/man/coap_session.txt.in b/man/coap_session.txt.in index 9d940a7f..6de38165 100644 --- a/man/coap_session.txt.in +++ b/man/coap_session.txt.in @@ -26,6 +26,7 @@ coap_session_get_proto, coap_session_get_state, coap_session_get_tls, coap_session_get_type, +coap_session_is_oscore, coap_session_get_psk_hint, coap_session_get_psk_key, coap_endpoint_set_app_data, @@ -71,6 +72,8 @@ coap_tls_library_t *tls_lib);* *coap_session_type_t coap_session_get_type(const coap_session_t *_session_);* +*int coap_session_is_oscore(const coap_session_t *_session_);* + *const coap_bin_const_t *coap_session_get_psk_hint( const coap_session_t *_session_);* @@ -249,6 +252,9 @@ COAP_SESSION_TYPE_HELLO /* Negotiating a (D)TLS session */ The *coap_session_get_type*() function is used to get the session type from the _session_. +The *coap_session_is_oscore*() function returns whether the _session_ is +using OSCORE. Returns 1 if the session is using OSCORE, 0 otherwise. + The *coap_session_get_psk_hint*() function is used to get the current server _session_'s pre-shared-key identity hint. @@ -289,6 +295,8 @@ error. *coap_session_get_type*() returns the current session's type or 0 on error. +*coap_session_is_oscore*() returns 1 if the session is using OSCORE, 0 otherwise. + *coap_session_get_psk_hint*() returns the current server session's pre-shared-key identity hint, or NULL if not defined. diff --git a/src/coap_session.c b/src/coap_session.c index 34b9a1e5..56283e89 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -2338,6 +2338,16 @@ coap_session_get_type(const coap_session_t *session) { return 0; } +int +coap_session_is_oscore(const coap_session_t *session) { +#if COAP_OSCORE_SUPPORT + return (session && session->oscore_encryption != 0) ? 1 : 0; +#else + (void)session; + return 0; +#endif +} + COAP_API int coap_session_set_type_client(coap_session_t *session) { int ret;