Skip to content

Commit

Permalink
net: lib: nrf_cloud_coap: expose CoAP transport functions
Browse files Browse the repository at this point in the history
Expose transport functions so that external coap_client
instances can be used with nRF Cloud.
IRIS-8806

Signed-off-by: Justin Morton <[email protected]>
  • Loading branch information
jayteemo committed May 2, 2024
1 parent d92c02b commit 21d130e
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 200 deletions.
1 change: 1 addition & 0 deletions include/net/nrf_cloud_coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int nrf_cloud_coap_init(void);
* Negative values are device-side errors defined in errno.h.
* Positive values are cloud-side errors (CoAP result codes)
* defined in zephyr/net/coap.h.
* @retval -EACCES if @ref nrf_cloud_coap_init has not been called.
*/
int nrf_cloud_coap_connect(const char * const app_ver);

Expand Down
71 changes: 71 additions & 0 deletions subsys/net/lib/nrf_cloud/coap/include/nrf_cloud_coap_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,82 @@ enum coap_content_format {
};
#endif

struct nrf_cloud_coap_client {
struct coap_client cc;
bool initialized;
bool authenticated;
bool cid_saved;
};

#define NRF_CLOUD_COAP_PROXY_RSC "proxy"

/**
* @defgroup nrf_cloud_coap_transport nRF CoAP API
* @{
*/

/**@brief Initialize the provided nrf_cloud_coap_client.
*
* @param client Client to initialize.
*
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_init(struct nrf_cloud_coap_client *const client);

/**@brief Connect to the cloud.
*
* @param client Client to connect.
*
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_connect(struct nrf_cloud_coap_client *const client);

/**@brief Disconnect from the cloud.
*
* @param client Client to disconnect.
*
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_disconnect(struct nrf_cloud_coap_client *const client);

/**@brief Perform authentication with the cloud.
*
* @param client Client to authenticate.
*
* @retval -ENOTCONN Client is not connected.
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_authenticate(struct nrf_cloud_coap_client *const client);

/**@brief Pause the CoAP connection.
*
* @param client Client to pause.
*
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_pause(struct nrf_cloud_coap_client *const client);

/**@brief Resume a paused CoAP connection.
*
* @param client Client to resume.
*
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_resume(struct nrf_cloud_coap_client *const client);

/**@brief Get the CoAP options required to perform a proxy download.
*
* @param opt_accept Option to be populated with COAP_OPTION_ACCEPT details.
* @param opt_proxy_uri Option to be populated with COAP_OPTION_PROXY_URI details.
* @param host Download host.
* @param path Download file path.
*
* @return 0 if successful, otherwise a negative error code.
*/
int nrf_cloud_coap_transport_proxy_dl_opts_get(struct coap_client_option *const opt_accept,
struct coap_client_option *const opt_proxy_uri,
char const *const host, char const *const path);

/**@brief Check if device is connected and authorized to use nRF Cloud CoAP.
*
* A device is authorized if the JWT it POSTed to the /auth/jwt endpoint is valid
Expand Down
Loading

0 comments on commit 21d130e

Please sign in to comment.