Loading...
Searching...
No Matches
ad.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018,2019 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
27#ifndef NET_BLUETIL_AD_H
28#define NET_BLUETIL_AD_H
29
30#include <stdint.h>
31#include <stddef.h>
32#include <string.h>
33
34#include "net/ble.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
43#define BLUETIL_AD_INIT(b,p,s) { .buf = b, .pos = p, .size = s }
44
48#define BLUETIL_AD_FLAGS_DEFAULT (BLE_GAP_DISCOVERABLE | \
49 BLE_GAP_FLAG_BREDR_NOTSUP)
50
54enum {
58};
59
63typedef struct {
64 uint8_t *data;
65 size_t len;
67
71typedef struct {
72 uint8_t *buf;
73 size_t pos;
74 size_t size;
76
85void bluetil_ad_init(bluetil_ad_t *ad, void *buf, size_t pos, size_t size);
86
98 uint8_t type, bluetil_ad_data_t *data);
99
111int bluetil_ad_find_and_cmp(const bluetil_ad_t *ad, uint8_t type,
112 const void *val, size_t val_len);
113
130int bluetil_ad_find_str(const bluetil_ad_t *ad, uint8_t type,
131 char *str, size_t str_len);
132
144int bluetil_ad_add(bluetil_ad_t *ad, uint8_t type,
145 const void *data, size_t data_len);
146
156static inline int bluetil_ad_add_flags(bluetil_ad_t *ad, uint8_t flags)
157{
158 return bluetil_ad_add(ad, BLE_GAP_AD_FLAGS, &flags, 1);
159}
160
173static inline int bluetil_ad_add_name(bluetil_ad_t *ad, const char *name)
174{
175 return bluetil_ad_add(ad, BLE_GAP_AD_NAME, name, strlen(name));
176}
177
195 void *buf, size_t buf_len,
196 uint8_t flags)
197{
198 bluetil_ad_init(ad, buf, 0, buf_len);
199 return bluetil_ad_add_flags(ad, flags);
200}
201
202/* add more convenience functions on demand... */
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* NET_BLUETIL_AD_H */
int bluetil_ad_find(const bluetil_ad_t *ad, uint8_t type, bluetil_ad_data_t *data)
Find a specific field in the given advertising data.
static int bluetil_ad_add_flags(bluetil_ad_t *ad, uint8_t flags)
Convenience function to add the "flags" field.
Definition ad.h:156
int bluetil_ad_find_and_cmp(const bluetil_ad_t *ad, uint8_t type, const void *val, size_t val_len)
Find a specific field and compare its value against the given data.
int bluetil_ad_find_str(const bluetil_ad_t *ad, uint8_t type, char *str, size_t str_len)
Find the given field and copy its payload into a string.
int bluetil_ad_add(bluetil_ad_t *ad, uint8_t type, const void *data, size_t data_len)
Add a new field to the given advertising data.
void bluetil_ad_init(bluetil_ad_t *ad, void *buf, size_t pos, size_t size)
Initialize the given advertising data descriptor.
static int bluetil_ad_add_name(bluetil_ad_t *ad, const char *name)
Convenience function to add the "full name" field.
Definition ad.h:173
static int bluetil_ad_init_with_flags(bluetil_ad_t *ad, void *buf, size_t buf_len, uint8_t flags)
Convenience function for initializing the advertising data descriptor and directly adding the flags f...
Definition ad.h:194
@ BLUETIL_AD_NOTFOUND
entry not found
Definition ad.h:56
@ BLUETIL_AD_NOMEM
insufficient memory to write field
Definition ad.h:57
@ BLUETIL_AD_OK
everything went as expected
Definition ad.h:55
Struct used for returning the contents of a selected field.
Definition ad.h:63
uint8_t * data
pointer a field's payload
Definition ad.h:64
size_t len
length of the payload
Definition ad.h:65
Descriptor for a buffer containing advertising data.
Definition ad.h:71
size_t pos
current write position in the buffer
Definition ad.h:73
size_t size
overall length of the buffer
Definition ad.h:74
uint8_t * buf
buffer containing the advertising data
Definition ad.h:72
General BLE values as defined by the BT standard.