|
| 1 | +/**************************************************************************** |
| 2 | + * apps/examples/nimble_blecent/blecent.h |
| 3 | + * |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | + * contributor license agreements. See the NOTICE file distributed with |
| 6 | + * this work for additional information regarding copyright ownership. The |
| 7 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance with the |
| 9 | + * License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | + * License for the specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + ****************************************************************************/ |
| 20 | + |
| 21 | +#ifndef H_BLECENT_ |
| 22 | +#define H_BLECENT_ |
| 23 | + |
| 24 | +/**************************************************************************** |
| 25 | + * Included Files |
| 26 | + ****************************************************************************/ |
| 27 | + |
| 28 | +#include <stdio.h> |
| 29 | + |
| 30 | +#ifdef __cplusplus |
| 31 | +extern "C" |
| 32 | +{ |
| 33 | +#endif |
| 34 | + |
| 35 | +struct ble_hs_adv_fields; |
| 36 | +struct ble_gap_conn_desc; |
| 37 | +struct ble_hs_cfg; |
| 38 | +union ble_store_value; |
| 39 | +union ble_store_key; |
| 40 | + |
| 41 | +#define BLECENT_SVC_ALERT_UUID 0x1811 |
| 42 | +#define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 |
| 43 | +#define BLECENT_CHR_NEW_ALERT 0x2A46 |
| 44 | +#define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 |
| 45 | +#define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45 |
| 46 | +#define BLECENT_CHR_ALERT_NOT_CTRL_PT 0x2A44 |
| 47 | + |
| 48 | +/* Misc. */ |
| 49 | + |
| 50 | +void print_bytes(const uint8_t *bytes, int len); |
| 51 | +void print_mbuf(const struct os_mbuf *om); |
| 52 | +char *addr_str(const void *addr); |
| 53 | +void print_uuid(const ble_uuid_t *uuid); |
| 54 | +void print_conn_desc(const struct ble_gap_conn_desc *desc); |
| 55 | +void print_adv_fields(const struct ble_hs_adv_fields *fields); |
| 56 | + |
| 57 | +/* Peer. */ |
| 58 | + |
| 59 | +struct peer_dsc |
| 60 | +{ |
| 61 | + SLIST_ENTRY(peer_dsc) next; |
| 62 | + struct ble_gatt_dsc dsc; |
| 63 | +}; |
| 64 | +SLIST_HEAD(peer_dsc_list, peer_dsc); |
| 65 | + |
| 66 | +struct peer_chr |
| 67 | +{ |
| 68 | + SLIST_ENTRY(peer_chr) next; |
| 69 | + struct ble_gatt_chr chr; |
| 70 | + |
| 71 | + struct peer_dsc_list dscs; |
| 72 | +}; |
| 73 | +SLIST_HEAD(peer_chr_list, peer_chr); |
| 74 | + |
| 75 | +struct peer_svc |
| 76 | +{ |
| 77 | + SLIST_ENTRY(peer_svc) next; |
| 78 | + struct ble_gatt_svc svc; |
| 79 | + |
| 80 | + struct peer_chr_list chrs; |
| 81 | +}; |
| 82 | +SLIST_HEAD(peer_svc_list, peer_svc); |
| 83 | + |
| 84 | +struct peer; |
| 85 | +typedef void peer_disc_fn(const struct peer *peer, int status, void *arg); |
| 86 | + |
| 87 | +struct peer |
| 88 | +{ |
| 89 | + SLIST_ENTRY(peer) next; |
| 90 | + |
| 91 | + uint16_t conn_handle; |
| 92 | + |
| 93 | + /* List of discovered GATT services. */ |
| 94 | + |
| 95 | + struct peer_svc_list svcs; |
| 96 | + |
| 97 | + /* Keeps track of where we are in the service discovery process. */ |
| 98 | + |
| 99 | + uint16_t disc_prev_chr_val; |
| 100 | + struct peer_svc *cur_svc; |
| 101 | + |
| 102 | + /* Callback that gets executed when service discovery completes. */ |
| 103 | + |
| 104 | + peer_disc_fn *disc_cb; |
| 105 | + void *disc_cb_arg; |
| 106 | +}; |
| 107 | + |
| 108 | +int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb, |
| 109 | + void *disc_cb_arg); |
| 110 | +const struct peer_dsc * |
| 111 | +peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid, |
| 112 | + const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid); |
| 113 | +const struct peer_chr * |
| 114 | +peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid, |
| 115 | + const ble_uuid_t *chr_uuid); |
| 116 | +const struct peer_svc * |
| 117 | +peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid); |
| 118 | +int peer_delete(uint16_t conn_handle); |
| 119 | +int peer_add(uint16_t conn_handle); |
| 120 | +int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs); |
| 121 | + |
| 122 | +#ifdef __cplusplus |
| 123 | +} |
| 124 | +#endif |
| 125 | + |
| 126 | +#endif |
0 commit comments