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
66
77
83{
85 const char *psk_id;
86 size_t psk_id_len;
87
89 const char *psk;
90 size_t psk_len;
91};
92
98{
99 // DER Common CA cert
100 const uint8_t *ca_cert;
102
104 const uint8_t *public_cert;
106
108 const uint8_t *private_key;
110
112 const uint8_t *secondary_ca_cert;
114};
115
127
133
139typedef void (*golioth_client_event_cb_fn)(struct golioth_client *client,
140 enum golioth_client_event event,
141 void *arg);
142
155typedef void (*golioth_get_cb_fn)(struct golioth_client *client,
156 const struct golioth_response *response,
157 const char *path,
158 const uint8_t *payload,
159 size_t payload_size,
160 void *arg);
161
175typedef void (*golioth_get_block_cb_fn)(struct golioth_client *client,
176 const struct golioth_response *response,
177 const char *path,
178 const uint8_t *payload,
179 size_t payload_size,
180 bool is_last,
181 void *arg);
182
195typedef void (*golioth_set_cb_fn)(struct golioth_client *client,
196 const struct golioth_response *response,
197 const char *path,
198 void *arg);
199
212struct golioth_client *golioth_client_create(const struct golioth_client_config *config);
213
222bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms);
223
233enum golioth_status golioth_client_start(struct golioth_client *client);
234
249enum golioth_status golioth_client_stop(struct golioth_client *client);
250
256void golioth_client_destroy(struct golioth_client *client);
257
264bool golioth_client_is_running(struct golioth_client *client);
265
275bool golioth_client_is_connected(struct golioth_client *client);
276
282void golioth_client_register_event_callback(struct golioth_client *client,
284 void *arg);
285
293uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client);
294
302
308golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client);
309
311
312#ifdef __cplusplus
313}
314#endif
golioth_status
void * golioth_sys_thread_t
Definition golioth_sys.h:82
golioth_auth_type
Authentication type.
Definition client.h:69
golioth_content_type
Golioth Content Type.
Definition client.h:45
bool golioth_client_is_connected(struct golioth_client *client)
void(* golioth_get_block_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, const uint8_t *payload, size_t payload_size, bool is_last, void *arg)
Definition client.h:175
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_get_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:155
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_set_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, void *arg)
Definition client.h:195
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_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:139
@ GOLIOTH_TLS_AUTH_TYPE_TAG
Authenticate with TLS credential tag (Zephyr specific)
Definition client.h:75
@ GOLIOTH_TLS_AUTH_TYPE_PKI
Authenticate with PKI certificates (CA cert, public client cert, private client key)
Definition client.h:73
@ GOLIOTH_TLS_AUTH_TYPE_PSK
Authenticate with pre-shared key (psk-id and psk)
Definition client.h:71
@ 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:130
struct golioth_credential credentials
Definition client.h:131
TLS Authentication Credential.
Definition client.h:118
enum golioth_auth_type auth_type
Definition client.h:119
struct golioth_pki_credential pki
Definition client.h:123
struct golioth_psk_credential psk
Definition client.h:122
const uint8_t * public_cert
DER Public client cert.
Definition client.h:104
const uint8_t * ca_cert
Definition client.h:100
const uint8_t * secondary_ca_cert
DER secondary Common CA cert.
Definition client.h:112
size_t secondary_ca_cert_len
Definition client.h:113
const uint8_t * private_key
DER Private client key.
Definition client.h:108
const char * psk
Pre-shared key, secret password.
Definition client.h:89
const char * psk_id
PSK Identifier (e.g. "devicename@projectname")
Definition client.h:85
Response status and CoAP class/code.
Definition client.h:53
enum golioth_status status
Definition client.h:60
uint8_t status_code
the 03 in 4.03
Definition client.h:64
uint8_t status_class
the 2 in 2.XX
Definition client.h:62