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
189typedef void (*golioth_get_block_cb_fn)(struct golioth_client *client,
190 enum golioth_status status,
191 const struct golioth_coap_rsp_code *coap_rsp_code,
192 const char *path,
193 const uint8_t *payload,
194 size_t payload_size,
195 bool is_last,
196 void *arg);
197
218typedef void (*golioth_set_cb_fn)(struct golioth_client *client,
219 enum golioth_status status,
220 const struct golioth_coap_rsp_code *coap_rsp_code,
221 const char *path,
222 void *arg);
223
236struct golioth_client *golioth_client_create(const struct golioth_client_config *config);
237
246bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms);
247
257enum golioth_status golioth_client_start(struct golioth_client *client);
258
273enum golioth_status golioth_client_stop(struct golioth_client *client);
274
280void golioth_client_destroy(struct golioth_client *client);
281
288bool golioth_client_is_running(struct golioth_client *client);
289
299bool golioth_client_is_connected(struct golioth_client *client);
300
306void golioth_client_register_event_callback(struct golioth_client *client,
308 void *arg);
309
317uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client);
318
326
332golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client);
333
335
336#ifdef __cplusplus
337}
338#endif
golioth_status
void * golioth_sys_thread_t
Definition golioth_sys.h:82
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:218
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_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:189
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