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#pragma once
7
8#include <stdbool.h>
9#include <stdint.h>
10#include <stdlib.h>
12#include "golioth_sys.h"
13
26
28struct golioth_client;
29
38
45
61
72
78{
80 const char *psk_id;
81 size_t psk_id_len;
82
84 const char *psk;
85 size_t psk_len;
86};
87
93{
94 // DER Common CA cert
95 const uint8_t *ca_cert;
97
99 const uint8_t *public_cert;
101
103 const uint8_t *private_key;
105};
106
118
124
130typedef void (*golioth_client_event_cb_fn)(struct golioth_client *client,
131 enum golioth_client_event event,
132 void *arg);
133
146typedef void (*golioth_get_cb_fn)(struct golioth_client *client,
147 const struct golioth_response *response,
148 const char *path,
149 const uint8_t *payload,
150 size_t payload_size,
151 void *arg);
152typedef void (*golioth_get_block_cb_fn)(struct golioth_client *client,
153 const struct golioth_response *response,
154 const char *path,
155 const uint8_t *payload,
156 size_t payload_size,
157 bool is_last,
158 void *arg);
159
171typedef void (*golioth_set_cb_fn)(struct golioth_client *client,
172 const struct golioth_response *response,
173 const char *path,
174 void *arg);
175
188struct golioth_client *golioth_client_create(const struct golioth_client_config *config);
189
198bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms);
199
209enum golioth_status golioth_client_start(struct golioth_client *client);
210
225enum golioth_status golioth_client_stop(struct golioth_client *client);
226
232void golioth_client_destroy(struct golioth_client *client);
233
240bool golioth_client_is_running(struct golioth_client *client);
241
251bool golioth_client_is_connected(struct golioth_client *client);
252
258void golioth_client_register_event_callback(struct golioth_client *client,
260 void *arg);
261
269uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client);
270
278
284golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client);
285
golioth_status
void * golioth_sys_thread_t
Definition golioth_sys.h:64
golioth_auth_type
Authentication type.
Definition client.h:64
golioth_content_type
Golioth Content Type.
Definition client.h:41
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:152
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:146
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:32
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:171
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:130
@ GOLIOTH_TLS_AUTH_TYPE_TAG
Authenticate with TLS credential tag (Zephyr specific)
Definition client.h:70
@ GOLIOTH_TLS_AUTH_TYPE_PKI
Authenticate with PKI certificates (CA cert, public client cert, private client key)
Definition client.h:68
@ GOLIOTH_TLS_AUTH_TYPE_PSK
Authenticate with pre-shared key (psk-id and psk)
Definition client.h:66
@ GOLIOTH_CONTENT_TYPE_JSON
Definition client.h:42
@ GOLIOTH_CONTENT_TYPE_CBOR
Definition client.h:43
@ GOLIOTH_CLIENT_EVENT_CONNECTED
Client was previously not connected, and is now connected.
Definition client.h:34
@ GOLIOTH_CLIENT_EVENT_DISCONNECTED
Client was previously connected, and is now disconnected.
Definition client.h:36
Golioth client configuration, passed into golioth_client_create.
Definition client.h:121
struct golioth_credential credentials
Definition client.h:122
TLS Authentication Credential.
Definition client.h:109
enum golioth_auth_type auth_type
Definition client.h:110
struct golioth_pki_credential pki
Definition client.h:114
struct golioth_psk_credential psk
Definition client.h:113
const uint8_t * public_cert
DER Public client cert.
Definition client.h:99
const uint8_t * ca_cert
Definition client.h:95
const uint8_t * private_key
DER Private client key.
Definition client.h:103
const char * psk
Pre-shared key, secret password.
Definition client.h:84
const char * psk_id
PSK Identifier (e.g. "devicename@projectname")
Definition client.h:80
Response status and CoAP class/code.
Definition client.h:48
enum golioth_status status
Definition client.h:55
uint8_t status_code
the 03 in 4.03
Definition client.h:59
uint8_t status_class
the 2 in 2.XX
Definition client.h:57