Golioth Firmware SDK
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Golioth, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef __cplusplus
8extern "C"
9{
10#endif
11
12#pragma once
13
14#include <stdbool.h>
15#include <stdint.h>
16#include <stdlib.h>
18#include "golioth_sys.h"
19
30
32struct golioth_client;
33
42
50
53{
56 uint8_t code_class;
58 uint8_t code_detail;
59};
60
71
77{
79 const char *psk_id;
80 size_t psk_id_len;
81
83 const char *psk;
84 size_t psk_len;
85};
86
92{
93 // DER Common CA cert
94 const uint8_t *ca_cert;
96
98 const uint8_t *public_cert;
100
102 const uint8_t *private_key;
104
106 const uint8_t *secondary_ca_cert;
108};
109
121
127
133typedef void (*golioth_client_event_cb_fn)(struct golioth_client *client,
134 enum golioth_client_event event,
135 void *arg);
136
158typedef void (*golioth_get_cb_fn)(struct golioth_client *client,
159 enum golioth_status status,
160 const struct golioth_coap_rsp_code *coap_rsp_code,
161 const char *path,
162 const uint8_t *payload,
163 size_t payload_size,
164 void *arg);
165
174typedef void (*golioth_set_block_cb_fn)(struct golioth_client *client,
175 enum golioth_status status,
176 const struct golioth_coap_rsp_code *coap_rsp_code,
177 const char *path,
178 size_t block_size,
179 void *arg);
180
204typedef void (*golioth_get_block_cb_fn)(struct golioth_client *client,
205 enum golioth_status status,
206 const struct golioth_coap_rsp_code *coap_rsp_code,
207 const char *path,
208 const uint8_t *payload,
209 size_t payload_size,
210 bool is_last,
211 void *arg);
212
233typedef void (*golioth_set_cb_fn)(struct golioth_client *client,
234 enum golioth_status status,
235 const struct golioth_coap_rsp_code *coap_rsp_code,
236 const char *path,
237 void *arg);
238
260typedef void (*golioth_post_cb_fn)(struct golioth_client *client,
261 enum golioth_status status,
262 const struct golioth_coap_rsp_code *coap_rsp_code,
263 const char *path,
264 const uint8_t *payload,
265 size_t payload_size,
266 void *arg);
267
280struct golioth_client *golioth_client_create(const struct golioth_client_config *config);
281
290bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms);
291
301enum golioth_status golioth_client_start(struct golioth_client *client);
302
317enum golioth_status golioth_client_stop(struct golioth_client *client);
318
324void golioth_client_destroy(struct golioth_client *client);
325
332bool golioth_client_is_running(struct golioth_client *client);
333
343bool golioth_client_is_connected(struct golioth_client *client);
344
350void golioth_client_register_event_callback(struct golioth_client *client,
352 void *arg);
353
361uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client);
362
370
376golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client);
377
379
380#ifdef __cplusplus
381}
382#endif
golioth_status
void * golioth_sys_thread_t
Definition golioth_sys.h:82
void(* golioth_set_block_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, size_t block_size, void *arg)
Definition client.h:174
void(* golioth_get_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:158
golioth_auth_type
Authentication type.
Definition client.h:63
void(* golioth_set_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, void *arg)
Definition client.h:233
golioth_content_type
Golioth Content Type.
Definition client.h:45
bool golioth_client_is_connected(struct golioth_client *client)
enum golioth_status golioth_client_start(struct golioth_client *client)
bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms)
void(* golioth_post_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:260
void golioth_client_register_event_callback(struct golioth_client *client, golioth_client_event_cb_fn callback, void *arg)
bool golioth_client_is_running(struct golioth_client *client)
uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client)
golioth_client_event
Golioth client events.
Definition client.h:36
enum golioth_status golioth_client_stop(struct golioth_client *client)
void golioth_client_destroy(struct golioth_client *client)
struct golioth_client * golioth_client_create(const struct golioth_client_config *config)
golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client)
void(* golioth_get_block_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, const uint8_t *payload, size_t payload_size, bool is_last, void *arg)
Definition client.h:204
void golioth_client_set_packet_loss_percent(uint8_t percent)
void(* golioth_client_event_cb_fn)(struct golioth_client *client, enum golioth_client_event event, void *arg)
Definition client.h:133
@ GOLIOTH_TLS_AUTH_TYPE_TAG
Authenticate with TLS credential tag (Zephyr specific)
Definition client.h:69
@ GOLIOTH_TLS_AUTH_TYPE_PKI
Authenticate with PKI certificates (CA cert, public client cert, private client key)
Definition client.h:67
@ GOLIOTH_TLS_AUTH_TYPE_PSK
Authenticate with pre-shared key (psk-id and psk)
Definition client.h:65
@ GOLIOTH_CONTENT_TYPE_JSON
Definition client.h:46
@ GOLIOTH_CONTENT_TYPE_CBOR
Definition client.h:47
@ GOLIOTH_CONTENT_TYPE_OCTET_STREAM
Definition client.h:48
@ GOLIOTH_CLIENT_EVENT_CONNECTED
Client was previously not connected, and is now connected.
Definition client.h:38
@ GOLIOTH_CLIENT_EVENT_DISCONNECTED
Client was previously connected, and is now disconnected.
Definition client.h:40
Golioth client configuration, passed into golioth_client_create.
Definition client.h:124
struct golioth_credential credentials
Definition client.h:125
CoAP response code returned by server.
Definition client.h:53
uint8_t code_detail
the 03 in 4.03
Definition client.h:58
TLS Authentication Credential.
Definition client.h:112
enum golioth_auth_type auth_type
Definition client.h:113
struct golioth_pki_credential pki
Definition client.h:117
struct golioth_psk_credential psk
Definition client.h:116
const uint8_t * public_cert
DER Public client cert.
Definition client.h:98
const uint8_t * ca_cert
Definition client.h:94
const uint8_t * secondary_ca_cert
DER secondary Common CA cert.
Definition client.h:106
size_t secondary_ca_cert_len
Definition client.h:107
const uint8_t * private_key
DER Private client key.
Definition client.h:102
const char * psk
Pre-shared key, secret password.
Definition client.h:83
const char * psk_id
PSK Identifier (e.g. "devicename@projectname")
Definition client.h:79