WXK
2025-05-22 035ecb85c3513be2b6ab5c515db082cb7fee8f97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
#ifndef PEER_H
#define PEER_H
 
#include "host/ble_hs.h"
 
/** Peer. */
struct peer_dsc {
    SLIST_ENTRY(peer_dsc) next;
    struct ble_gatt_dsc dsc;
};
SLIST_HEAD(peer_dsc_list, peer_dsc);
 
struct peer_chr {
    SLIST_ENTRY(peer_chr) next;
    struct ble_gatt_chr chr;
 
    struct peer_dsc_list dscs;
};
SLIST_HEAD(peer_chr_list, peer_chr);
 
struct peer_svc {
    SLIST_ENTRY(peer_svc) next;
    struct ble_gatt_svc svc;
 
    struct peer_chr_list chrs;
};
SLIST_HEAD(peer_svc_list, peer_svc);
 
struct peer;
typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);
 
struct peer {
    SLIST_ENTRY(peer) next;
 
    uint16_t conn_handle;
 
    /** List of discovered GATT services. */
    struct peer_svc_list svcs;
 
    /** Keeps track of where we are in the service discovery process. */
    uint16_t disc_prev_chr_val;
    struct peer_svc *cur_svc;
 
    /** Callback that gets executed when service discovery completes. */
    peer_disc_fn *disc_cb;
    void *disc_cb_arg;
};
 
 
int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
 
int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb, void *disc_cb_arg);
 
const struct peer_dsc *peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
                                          const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
const struct peer_chr *peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
                                          const ble_uuid_t *chr_uuid);
const struct peer_svc *peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
 
int peer_delete(uint16_t conn_handle);
int peer_add(uint16_t conn_handle);
 
 
#endif