1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BTSHELL_PRIV_ 21 #define H_BTSHELL_PRIV_ 22 23 #include <inttypes.h> 24 #include "nimble/ble.h" 25 #include "nimble/nimble_opt.h" 26 #include "modlog/modlog.h" 27 28 #include "host/ble_gatt.h" 29 #include "host/ble_gap.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 struct ble_gap_white_entry; 36 struct ble_hs_adv_fields; 37 struct ble_gap_upd_params; 38 struct ble_gap_conn_params; 39 struct hci_adv_params; 40 struct ble_l2cap_sig_update_req; 41 struct ble_l2cap_sig_update_params; 42 union ble_store_value; 43 union ble_store_key; 44 struct ble_gap_adv_params; 45 struct ble_gap_conn_desc; 46 struct ble_gap_disc_params; 47 48 struct btshell_dsc { 49 SLIST_ENTRY(btshell_dsc) next; 50 struct ble_gatt_dsc dsc; 51 }; 52 SLIST_HEAD(btshell_dsc_list, btshell_dsc); 53 54 struct btshell_chr { 55 SLIST_ENTRY(btshell_chr) next; 56 struct ble_gatt_chr chr; 57 58 struct btshell_dsc_list dscs; 59 }; 60 SLIST_HEAD(btshell_chr_list, btshell_chr); 61 62 struct btshell_svc { 63 SLIST_ENTRY(btshell_svc) next; 64 struct ble_gatt_svc svc; 65 struct btshell_chr_list chrs; 66 }; 67 68 SLIST_HEAD(btshell_svc_list, btshell_svc); 69 70 struct btshell_l2cap_coc { 71 SLIST_ENTRY(btshell_l2cap_coc) next; 72 struct ble_l2cap_chan *chan; 73 }; 74 75 SLIST_HEAD(btshell_l2cap_coc_list, btshell_l2cap_coc); 76 77 struct btshell_conn { 78 uint16_t handle; 79 struct btshell_svc_list svcs; 80 struct btshell_l2cap_coc_list coc_list; 81 }; 82 83 struct btshell_scan_opts { 84 uint16_t limit; 85 uint8_t ignore_legacy:1; 86 }; 87 88 extern struct btshell_conn btshell_conns[MYNEWT_VAL(BLE_MAX_CONNECTIONS)]; 89 extern int btshell_num_conns; 90 91 int btshell_exchange_mtu(uint16_t conn_handle); 92 int btshell_disc_svcs(uint16_t conn_handle); 93 int btshell_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid); 94 int btshell_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle, 95 uint16_t end_handle); 96 int btshell_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle, 97 uint16_t end_handle, const ble_uuid_t *uuid); 98 int btshell_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle, 99 uint16_t end_handle); 100 int btshell_disc_full(uint16_t conn_handle); 101 int btshell_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle, 102 uint16_t end_handle); 103 int btshell_read(uint16_t conn_handle, uint16_t attr_handle); 104 int btshell_read_long(uint16_t conn_handle, uint16_t attr_handle, 105 uint16_t offset); 106 int btshell_read_by_uuid(uint16_t conn_handle, uint16_t start_handle, 107 uint16_t end_handle, const ble_uuid_t *uuid); 108 int btshell_read_mult(uint16_t conn_handle, uint16_t *attr_handles, 109 int num_attr_handles); 110 int btshell_write(uint16_t conn_handle, uint16_t attr_handle, 111 struct os_mbuf *om); 112 int btshell_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, 113 struct os_mbuf *om); 114 int btshell_write_long(uint16_t conn_handle, uint16_t attr_handle, 115 uint16_t offset, struct os_mbuf *om); 116 int btshell_write_reliable(uint16_t conn_handle, 117 struct ble_gatt_attr *attrs, int num_attrs); 118 #if MYNEWT_VAL(BLE_EXT_ADV) 119 int btshell_ext_adv_configure(uint8_t instance, 120 const struct ble_gap_ext_adv_params *params, 121 int8_t *selected_tx_power); 122 int btshell_ext_adv_start(uint8_t instance, int duration, 123 int max_events, bool restart); 124 int btshell_ext_adv_stop(uint8_t instance); 125 #endif 126 int btshell_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr, 127 int32_t duration_ms, 128 const struct ble_gap_adv_params *params, 129 bool restart); 130 int btshell_adv_stop(void); 131 int btshell_conn_initiate(uint8_t own_addr_type, const ble_addr_t *peer_addr, 132 int32_t duration_ms, 133 struct ble_gap_conn_params *params); 134 int btshell_ext_conn_initiate(uint8_t own_addr_type, 135 const ble_addr_t *peer_addr, 136 int32_t duration_ms, 137 struct ble_gap_conn_params *phy_1m_params, 138 struct ble_gap_conn_params *phy_2m_params, 139 struct ble_gap_conn_params *phy_coded_params); 140 int btshell_conn_cancel(void); 141 int btshell_term_conn(uint16_t conn_handle, uint8_t reason); 142 int btshell_wl_set(ble_addr_t *addrs, int addrs_count); 143 int btshell_scan(uint8_t own_addr_type, int32_t duration_ms, 144 const struct ble_gap_disc_params *disc_params, void *cb_args); 145 int btshell_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period, 146 uint8_t filter_duplicates, uint8_t filter_policy, 147 uint8_t limited, 148 const struct ble_gap_ext_disc_params *uncoded_params, 149 const struct ble_gap_ext_disc_params *coded_params, 150 void *cb_args); 151 int btshell_scan_cancel(void); 152 int btshell_update_conn(uint16_t conn_handle, 153 struct ble_gap_upd_params *params); 154 void btshell_notify(uint16_t attr_handle); 155 int btshell_datalen(uint16_t conn_handle, uint16_t tx_octets, 156 uint16_t tx_time); 157 int btshell_l2cap_update(uint16_t conn_handle, 158 struct ble_l2cap_sig_update_params *params); 159 int btshell_sec_start(uint16_t conn_handle); 160 int btshell_sec_pair(uint16_t conn_handle); 161 int btshell_sec_unpair(ble_addr_t *peer_addr); 162 int btshell_sec_restart(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv, 163 uint64_t rand_val, int auth); 164 int btshell_tx_start(uint16_t handle, uint16_t len, uint16_t rate, 165 uint16_t num); 166 int btshell_rssi(uint16_t conn_handle, int8_t *out_rssi); 167 int btshell_l2cap_create_srv(uint16_t psm, int accept_response); 168 int btshell_l2cap_connect(uint16_t conn, uint16_t psm); 169 int btshell_l2cap_disconnect(uint16_t conn, uint16_t idx); 170 int btshell_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes); 171 172 /** GATT server. */ 173 #define GATT_SVR_SVC_ALERT_UUID 0x1811 174 #define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 175 #define GATT_SVR_CHR_NEW_ALERT 0x2A46 176 #define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 177 #define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45 178 #define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44 179 180 void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg); 181 int gatt_svr_init(void); 182 void gatt_svr_print_svcs(void); 183 184 /** Misc. */ 185 void print_bytes(const uint8_t *bytes, int len); 186 void print_mbuf(const struct os_mbuf *om); 187 void print_addr(const void *addr); 188 void print_uuid(const ble_uuid_t *uuid); 189 int svc_is_empty(const struct btshell_svc *svc); 190 uint16_t chr_end_handle(const struct btshell_svc *svc, 191 const struct btshell_chr *chr); 192 int chr_is_empty(const struct btshell_svc *svc, const struct btshell_chr *chr); 193 void print_conn_desc(const struct ble_gap_conn_desc *desc); 194 void print_svc(struct btshell_svc *svc); 195 196 #ifdef __cplusplus 197 } 198 #endif 199 200 #endif 201