NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_hs_resolv_priv.h
1/*
2 * Copyright 2020 Espressif Systems (Shanghai) PTE LTD
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
27/*
28 * An entry in the resolving list.
29 */
30struct ble_hs_resolv_entry {
31 uint8_t rl_addr_type;
32 uint8_t rl_local_irk[16];
33 uint8_t rl_peer_irk[16];
34 uint8_t rl_identity_addr[BLE_DEV_ADDR_LEN];
35 uint8_t rl_pseudo_id[BLE_DEV_ADDR_LEN];
36 uint8_t rl_local_rpa[BLE_DEV_ADDR_LEN];
37 uint8_t rl_peer_rpa[BLE_DEV_ADDR_LEN];
38 uint8_t rl_isrpa;
39};
40
41#if MYNEWT_VAL(BLE_STORE_CONFIG_PERSIST)
42/* Persist peer records in NVS. XXX Need to handle this in `store` module */
43int ble_store_persist_peer_records(void);
44#endif
45
46struct ble_hs_peer_sec {
47 ble_addr_t peer_addr;
48 uint8_t irk[16];
49 uint8_t irk_present: 1;
50};
51/*
52 * BLE host peer device record, this helps in storing peer RPA before bond is
53 * created and IRKs are exchanged.
54 */
55struct ble_hs_dev_records {
56 bool rec_used;
57 uint8_t rand_addr_type;
58 uint8_t pseudo_addr[BLE_DEV_ADDR_LEN];
59 uint8_t rand_addr[BLE_DEV_ADDR_LEN];
60 uint8_t identity_addr[BLE_DEV_ADDR_LEN];
61 struct ble_hs_peer_sec peer_sec;
62};
63
64/* Add a device to the resolving list */
65int ble_hs_resolv_list_add(uint8_t *cmdbuf);
66int ble_hs_gen_own_private_rnd(void);
67uint8_t *ble_hs_get_rpa_local(void);
68
69/* Remove a device from the resolving list */
70int ble_hs_resolv_list_rmv(uint8_t, uint8_t *);
71/* Clear the resolving list and peer dev record */
72void ble_hs_resolv_list_clear_all(void);
73
74/* Address resolution enable command */
75void ble_hs_resolv_enable(bool);
76void ble_hs_resolv_nrpa_enable(void);
77void ble_hs_resolv_nrpa_disable(void);
78
79/* Finds 'addr' in resolving list. Doesnt check if address resolution enabled */
80struct ble_hs_resolv_entry *
81ble_hs_resolv_list_find(uint8_t *addr);
82
83/* Resolve a Resolvable Private Address and maintain mapping of RPA */
84struct ble_hs_resolv_entry *
85ble_hs_resolv_rpa_addr(uint8_t *addr, uint8_t addr_type);
86
87/* Returns true if host based RPA (privacy) is enabled */
88bool ble_host_rpa_enabled(void);
89
90/* Searches peer device records (RPA) and fetches matching RL, peer_address
91 * into input parameters if RL is found */
92void
93ble_rpa_replace_peer_params_with_rl(uint8_t *, uint8_t *, struct ble_hs_resolv_entry **);
94
95int ble_rpa_resolv_add_peer_rec(uint8_t *);
96
97struct ble_hs_dev_records *ble_rpa_get_peer_dev_records(void);
98int ble_rpa_get_num_peer_dev_records(void);
99void ble_rpa_set_num_peer_dev_records(int);
100int ble_rpa_remove_peer_dev_rec(struct ble_hs_dev_records *);
101struct ble_hs_dev_records *ble_rpa_find_peer_dev_rec(uint8_t *);
102
103/* Set the resolvable private address timeout */
104int ble_hs_resolv_set_rpa_tmo(uint16_t);
105
106/* Resolve a resolvable private address */
107int ble_hs_resolv_rpa(uint8_t *rpa, uint8_t *irk);
108
109/* Initialize resolv*/
110void ble_hs_resolv_init(void);
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif