mirror of
https://gitee.com/Vancouver2017/luban-lite.git
synced 2025-12-29 01:06:56 +00:00
v1.2.1
This commit is contained in:
40
packages/third-party/nimble/apps/btshell/pkg.yml
vendored
Normal file
40
packages/third-party/nimble/apps/btshell/pkg.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
pkg.name: apps/btshell
|
||||
pkg.type: app
|
||||
pkg.description: Shell application exposing the nimble GAP and GATT.
|
||||
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
|
||||
pkg.homepage: "http://mynewt.apache.org/"
|
||||
pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- "@apache-mynewt-core/kernel/os"
|
||||
- "@apache-mynewt-core/sys/log"
|
||||
- "@apache-mynewt-core/sys/log/modlog"
|
||||
- "@apache-mynewt-core/sys/stats"
|
||||
- "@apache-mynewt-core/sys/console"
|
||||
- "@apache-mynewt-core/sys/shell"
|
||||
- "@apache-mynewt-core/util/parse_arg"
|
||||
- nimble/host
|
||||
- nimble/host/services/gap
|
||||
- nimble/host/services/gatt
|
||||
- nimble/host/store/config
|
||||
- nimble/host/util
|
||||
|
||||
pkg.deps.BTSHELL_ANS:
|
||||
- nimble/host/services/ans
|
||||
3159
packages/third-party/nimble/apps/btshell/src/btshell.c
vendored
Normal file
3159
packages/third-party/nimble/apps/btshell/src/btshell.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
258
packages/third-party/nimble/apps/btshell/src/btshell.h
vendored
Normal file
258
packages/third-party/nimble/apps/btshell/src/btshell.h
vendored
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef H_BTSHELL_PRIV_
|
||||
#define H_BTSHELL_PRIV_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "os/mynewt.h"
|
||||
#include "nimble/ble.h"
|
||||
#include "nimble/nimble_opt.h"
|
||||
#include "modlog/modlog.h"
|
||||
|
||||
#include "host/ble_gatt.h"
|
||||
#include "host/ble_gap.h"
|
||||
#if (MYNEWT_VAL(BLE_ISO_BROADCAST_SOURCE))
|
||||
#include "audio/ble_audio_broadcast_source.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct ble_gap_white_entry;
|
||||
struct ble_hs_adv_fields;
|
||||
struct ble_gap_upd_params;
|
||||
struct ble_gap_conn_params;
|
||||
struct hci_adv_params;
|
||||
struct ble_l2cap_sig_update_req;
|
||||
struct ble_l2cap_sig_update_params;
|
||||
union ble_store_value;
|
||||
union ble_store_key;
|
||||
struct ble_gap_adv_params;
|
||||
struct ble_gap_conn_desc;
|
||||
struct ble_gap_disc_params;
|
||||
|
||||
struct btshell_dsc {
|
||||
SLIST_ENTRY(btshell_dsc) next;
|
||||
struct ble_gatt_dsc dsc;
|
||||
};
|
||||
SLIST_HEAD(btshell_dsc_list, btshell_dsc);
|
||||
|
||||
struct btshell_chr {
|
||||
SLIST_ENTRY(btshell_chr) next;
|
||||
struct ble_gatt_chr chr;
|
||||
|
||||
struct btshell_dsc_list dscs;
|
||||
};
|
||||
SLIST_HEAD(btshell_chr_list, btshell_chr);
|
||||
|
||||
struct btshell_svc {
|
||||
SLIST_ENTRY(btshell_svc) next;
|
||||
struct ble_gatt_svc svc;
|
||||
struct btshell_chr_list chrs;
|
||||
bool discovered;
|
||||
};
|
||||
|
||||
SLIST_HEAD(btshell_svc_list, btshell_svc);
|
||||
|
||||
struct btshell_l2cap_coc {
|
||||
SLIST_ENTRY(btshell_l2cap_coc) next;
|
||||
struct ble_l2cap_chan *chan;
|
||||
bool stalled;
|
||||
};
|
||||
|
||||
SLIST_HEAD(btshell_l2cap_coc_list, btshell_l2cap_coc);
|
||||
|
||||
struct btshell_conn {
|
||||
uint16_t handle;
|
||||
struct btshell_svc_list svcs;
|
||||
struct btshell_l2cap_coc_list coc_list;
|
||||
};
|
||||
|
||||
#define NAME_FILTER_LEN_MAX 20
|
||||
|
||||
struct btshell_scan_opts {
|
||||
uint16_t limit;
|
||||
uint8_t ignore_legacy : 1;
|
||||
uint8_t periodic_only : 1;
|
||||
uint8_t silent : 1;
|
||||
uint8_t name_filter_len;
|
||||
char name_filter[NAME_FILTER_LEN_MAX];
|
||||
};
|
||||
|
||||
extern struct btshell_conn btshell_conns[MYNEWT_VAL(BLE_MAX_CONNECTIONS)];
|
||||
extern int btshell_num_conns;
|
||||
|
||||
int btshell_exchange_mtu(uint16_t conn_handle);
|
||||
int btshell_disc_svcs(uint16_t conn_handle);
|
||||
int btshell_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid);
|
||||
int btshell_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle);
|
||||
int btshell_disc_all_chrs_in_svc(uint16_t conn_handle, struct btshell_svc *svc);
|
||||
int btshell_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle, const ble_uuid_t *uuid);
|
||||
int btshell_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle);
|
||||
int btshell_disc_full(uint16_t conn_handle);
|
||||
int btshell_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle);
|
||||
int btshell_read(uint16_t conn_handle, uint16_t attr_handle);
|
||||
int btshell_read_long(uint16_t conn_handle, uint16_t attr_handle,
|
||||
uint16_t offset);
|
||||
int btshell_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle, const ble_uuid_t *uuid);
|
||||
int btshell_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
|
||||
int num_attr_handles, bool variable);
|
||||
int btshell_write(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct os_mbuf *om);
|
||||
int btshell_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct os_mbuf *om);
|
||||
int btshell_write_long(uint16_t conn_handle, uint16_t attr_handle,
|
||||
uint16_t offset, struct os_mbuf *om);
|
||||
int btshell_write_reliable(uint16_t conn_handle,
|
||||
struct ble_gatt_attr *attrs, int num_attrs);
|
||||
#if MYNEWT_VAL(BLE_GATT_NOTIFY_MULTIPLE)
|
||||
int btshell_enqueue_notif(uint16_t handle, uint16_t len, uint8_t *value);
|
||||
int btshell_send_pending_notif(uint16_t conn_handle);
|
||||
int btshell_clear_pending_notif(void);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
int btshell_ext_adv_configure(uint8_t instance,
|
||||
const struct ble_gap_ext_adv_params *params,
|
||||
int8_t *selected_tx_power);
|
||||
int btshell_ext_adv_start(uint8_t instance, int duration,
|
||||
int max_events, bool restart);
|
||||
int btshell_ext_adv_stop(uint8_t instance);
|
||||
#endif
|
||||
int btshell_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr,
|
||||
int32_t duration_ms,
|
||||
const struct ble_gap_adv_params *params,
|
||||
bool restart);
|
||||
int btshell_adv_stop(void);
|
||||
int btshell_conn_initiate(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms,
|
||||
struct ble_gap_conn_params *params);
|
||||
int btshell_ext_conn_initiate(uint8_t own_addr_type,
|
||||
const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms,
|
||||
struct ble_gap_conn_params *phy_1m_params,
|
||||
struct ble_gap_conn_params *phy_2m_params,
|
||||
struct ble_gap_conn_params *phy_coded_params);
|
||||
int btshell_conn_cancel(void);
|
||||
int btshell_term_conn(uint16_t conn_handle, uint8_t reason);
|
||||
int btshell_wl_set(ble_addr_t *addrs, int addrs_count);
|
||||
int btshell_scan(uint8_t own_addr_type, int32_t duration_ms,
|
||||
const struct ble_gap_disc_params *disc_params, void *cb_args);
|
||||
int btshell_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period,
|
||||
uint8_t filter_duplicates, uint8_t filter_policy,
|
||||
uint8_t limited,
|
||||
const struct ble_gap_ext_disc_params *uncoded_params,
|
||||
const struct ble_gap_ext_disc_params *coded_params,
|
||||
void *cb_args);
|
||||
int btshell_scan_cancel(void);
|
||||
int btshell_update_conn(uint16_t conn_handle,
|
||||
struct ble_gap_upd_params *params);
|
||||
void btshell_notify(uint16_t attr_handle);
|
||||
int btshell_datalen(uint16_t conn_handle, uint16_t tx_octets,
|
||||
uint16_t tx_time);
|
||||
int btshell_l2cap_update(uint16_t conn_handle,
|
||||
struct ble_l2cap_sig_update_params *params);
|
||||
int btshell_sec_start(uint16_t conn_handle);
|
||||
int btshell_sec_pair(uint16_t conn_handle);
|
||||
int btshell_sec_unpair(ble_addr_t *peer_addr);
|
||||
int btshell_sec_restart(uint16_t conn_handle, uint8_t key_size,
|
||||
uint8_t *ltk, uint16_t ediv,
|
||||
uint64_t rand_val, int auth);
|
||||
int btshell_tx_start(uint16_t conn_handle, uint16_t len, uint16_t rate,
|
||||
uint16_t num);
|
||||
void btshell_tx_stop(void);
|
||||
int btshell_rssi(uint16_t conn_handle, int8_t *out_rssi);
|
||||
int btshell_l2cap_create_srv(uint16_t psm, uint16_t mtu, int accept_response);
|
||||
int btshell_l2cap_connect(uint16_t conn, uint16_t psm, uint16_t mtu, uint8_t num);
|
||||
int btshell_l2cap_disconnect(uint16_t conn, uint16_t idx);
|
||||
int btshell_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes);
|
||||
int btshell_l2cap_reconfig(uint16_t conn_handle, uint16_t mtu,
|
||||
uint8_t num, uint8_t idxs[]);
|
||||
|
||||
#if (MYNEWT_VAL(BLE_ISO_BROADCAST_SOURCE))
|
||||
int btshell_broadcast_base_add(uint8_t adv_instance, uint32_t presentation_delay);
|
||||
int btshell_broadcast_big_sub_add(uint8_t adv_instance,
|
||||
uint8_t codec_fmt,
|
||||
uint16_t company_id,
|
||||
uint16_t vendor_spec,
|
||||
uint8_t *metadata,
|
||||
unsigned int metadata_len,
|
||||
uint8_t *codec_spec_cfg,
|
||||
unsigned int codec_spec_cfg_len);
|
||||
int btshell_broadcast_bis_add(uint8_t adv_instance,
|
||||
uint8_t *codec_spec_cfg,
|
||||
unsigned int codec_spec_cfg_len);
|
||||
int btshell_broadcast_create(uint8_t adv_instance,
|
||||
struct ble_gap_ext_adv_params *ext_params,
|
||||
struct ble_gap_periodic_adv_params
|
||||
*per_params,
|
||||
const char *name,
|
||||
struct ble_iso_big_params big_params,
|
||||
uint8_t *extra_data,
|
||||
unsigned int extra_data_len);
|
||||
int btshell_broadcast_destroy(uint8_t adv_instance);
|
||||
int btshell_broadcast_update(uint8_t adv_instance,
|
||||
const char *name,
|
||||
uint8_t *extra_data,
|
||||
unsigned int extra_data_len);
|
||||
int btshell_broadcast_start(uint8_t adv_instance);
|
||||
int btshell_broadcast_stop(uint8_t adv_instance);
|
||||
#endif
|
||||
|
||||
void btshell_leaudio_init(void);
|
||||
|
||||
int btshell_gap_event(struct ble_gap_event *event, void *arg);
|
||||
void btshell_sync_stats(uint16_t handle);
|
||||
uint8_t btshell_get_default_own_addr_type(void);
|
||||
/** GATT server. */
|
||||
#define GATT_SVR_SVC_ALERT_UUID 0x1811
|
||||
#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
|
||||
#define GATT_SVR_CHR_NEW_ALERT 0x2A46
|
||||
#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
|
||||
#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45
|
||||
#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44
|
||||
|
||||
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
|
||||
int gatt_svr_init(void);
|
||||
void gatt_svr_print_svcs(void);
|
||||
|
||||
/** Misc. */
|
||||
void print_bytes(const uint8_t *bytes, int len);
|
||||
void print_mbuf(const struct os_mbuf *om);
|
||||
void print_addr(const void *addr);
|
||||
void print_uuid(const ble_uuid_t *uuid);
|
||||
int svc_is_empty(const struct btshell_svc *svc);
|
||||
uint16_t chr_end_handle(const struct btshell_svc *svc,
|
||||
const struct btshell_chr *chr);
|
||||
int chr_is_empty(const struct btshell_svc *svc, const struct btshell_chr *chr);
|
||||
void print_conn_desc(const struct ble_gap_conn_desc *desc);
|
||||
void print_svc(struct btshell_svc *svc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
5065
packages/third-party/nimble/apps/btshell/src/cmd.c
vendored
Normal file
5065
packages/third-party/nimble/apps/btshell/src/cmd.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
42
packages/third-party/nimble/apps/btshell/src/cmd.h
vendored
Normal file
42
packages/third-party/nimble/apps/btshell/src/cmd.h
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef CMD_H
|
||||
#define CMD_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "host/ble_uuid.h"
|
||||
#include <parse_arg/parse_arg.h>
|
||||
|
||||
int parse_eddystone_url(char *full_url, uint8_t *out_scheme, char *out_body,
|
||||
uint8_t *out_body_len, uint8_t *out_suffix);
|
||||
|
||||
int cmd_parse_conn_start_end(uint16_t *out_conn, uint16_t *out_start,
|
||||
uint16_t *out_end);
|
||||
|
||||
int parse_dev_addr(const char *prefix, const struct parse_arg_kv_pair *addr_types,
|
||||
ble_addr_t *addr);
|
||||
|
||||
int cmd_parse_addr(const char *prefix, ble_addr_t *addr);
|
||||
|
||||
const char *cmd_addr_type_str(uint8_t type);
|
||||
|
||||
void cmd_init(void);
|
||||
|
||||
#endif
|
||||
666
packages/third-party/nimble/apps/btshell/src/cmd_gatt.c
vendored
Normal file
666
packages/third-party/nimble/apps/btshell/src/cmd_gatt.c
vendored
Normal file
@@ -0,0 +1,666 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "bsp/bsp.h"
|
||||
#include "host/ble_hs_mbuf.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
#include "console/console.h"
|
||||
#include "btshell.h"
|
||||
#include "cmd.h"
|
||||
#include "cmd_gatt.h"
|
||||
|
||||
#define CMD_BUF_SZ 256
|
||||
static bssnz_t uint8_t cmd_buf[CMD_BUF_SZ];
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-discover *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_discover_characteristic(int argc, char **argv)
|
||||
{
|
||||
uint16_t start_handle;
|
||||
uint16_t conn_handle;
|
||||
uint16_t end_handle;
|
||||
ble_uuid_any_t uuid;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cmd_parse_conn_start_end(&conn_handle, &start_handle, &end_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn start end' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = parse_arg_ble_uuid("uuid", &uuid);
|
||||
if (rc == 0) {
|
||||
rc = btshell_disc_chrs_by_uuid(conn_handle, start_handle, end_handle,
|
||||
&uuid.u);
|
||||
} else if (rc == ENOENT) {
|
||||
rc = btshell_disc_all_chrs(conn_handle, start_handle, end_handle);
|
||||
} else {
|
||||
console_printf("invalid 'uuid' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
if (rc != 0) {
|
||||
console_printf("error discovering characteristics; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_discover_descriptor(int argc, char **argv)
|
||||
{
|
||||
uint16_t start_handle;
|
||||
uint16_t conn_handle;
|
||||
uint16_t end_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cmd_parse_conn_start_end(&conn_handle, &start_handle, &end_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn start end' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = btshell_disc_all_dscs(conn_handle, start_handle, end_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("error discovering descriptors; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_discover_service(int argc, char **argv)
|
||||
{
|
||||
ble_uuid_any_t uuid;
|
||||
int conn_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = parse_arg_ble_uuid("uuid", &uuid);
|
||||
if (rc == 0) {
|
||||
rc = btshell_disc_svc_by_uuid(conn_handle, &uuid.u);
|
||||
} else if (rc == ENOENT) {
|
||||
rc = btshell_disc_svcs(conn_handle);
|
||||
} else {
|
||||
console_printf("invalid 'uuid' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
console_printf("error discovering services; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_discover_full(int argc, char **argv)
|
||||
{
|
||||
int conn_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = btshell_disc_full(conn_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("error discovering all; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-exchange-mtu *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_exchange_mtu(int argc, char **argv)
|
||||
{
|
||||
uint16_t conn_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = btshell_exchange_mtu(conn_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("error exchanging mtu; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-notify *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_notify(int argc, char **argv)
|
||||
{
|
||||
uint16_t attr_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
attr_handle = parse_arg_uint16("attr", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'attr' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
btshell_notify(attr_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-read *
|
||||
*****************************************************************************/
|
||||
|
||||
#define CMD_READ_MAX_ATTRS 8
|
||||
|
||||
int
|
||||
cmd_gatt_read(int argc, char **argv)
|
||||
{
|
||||
static uint16_t attr_handles[CMD_READ_MAX_ATTRS];
|
||||
uint16_t conn_handle;
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
uint16_t offset;
|
||||
ble_uuid_any_t uuid;
|
||||
uint8_t num_attr_handles;
|
||||
int is_uuid;
|
||||
int is_long;
|
||||
bool is_var;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
is_long = parse_arg_long("long", &rc);
|
||||
if (rc == ENOENT) {
|
||||
is_long = 0;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'long' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
is_var = parse_arg_bool_dflt("variable", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'variable' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
for (num_attr_handles = 0;
|
||||
num_attr_handles < CMD_READ_MAX_ATTRS;
|
||||
num_attr_handles++) {
|
||||
|
||||
attr_handles[num_attr_handles] = parse_arg_uint16("attr", &rc);
|
||||
if (rc == ENOENT) {
|
||||
break;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'attr' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
rc = parse_arg_ble_uuid("uuid", &uuid);
|
||||
if (rc == ENOENT) {
|
||||
is_uuid = 0;
|
||||
} else if (rc == 0) {
|
||||
is_uuid = 1;
|
||||
} else {
|
||||
console_printf("invalid 'uuid' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
start = parse_arg_uint16("start", &rc);
|
||||
if (rc == ENOENT) {
|
||||
start = 0;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'start' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
end = parse_arg_uint16("end", &rc);
|
||||
if (rc == ENOENT) {
|
||||
end = 0;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'end' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
offset = parse_arg_uint16("offset", &rc);
|
||||
if (rc == ENOENT) {
|
||||
offset = 0;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'offset' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (num_attr_handles == 1) {
|
||||
if (is_long) {
|
||||
rc = btshell_read_long(conn_handle, attr_handles[0], offset);
|
||||
} else {
|
||||
rc = btshell_read(conn_handle, attr_handles[0]);
|
||||
}
|
||||
} else if (num_attr_handles > 1) {
|
||||
rc = btshell_read_mult(conn_handle, attr_handles, num_attr_handles, is_var);
|
||||
} else if (is_uuid) {
|
||||
if (start == 0 || end == 0) {
|
||||
rc = EINVAL;
|
||||
} else {
|
||||
rc = btshell_read_by_uuid(conn_handle, start, end, &uuid.u);
|
||||
}
|
||||
} else {
|
||||
rc = EINVAL;
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
console_printf("error reading characteristic; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-service-changed *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_service_changed(int argc, char **argv)
|
||||
{
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
start = parse_arg_uint16("start", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'start' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
end = parse_arg_uint16("end", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'end' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
ble_svc_gatt_changed(start, end);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-service-visibility *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_service_visibility(int argc, char **argv)
|
||||
{
|
||||
uint16_t handle;
|
||||
bool vis;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
handle = parse_arg_uint16("handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
vis = parse_arg_bool("visibility", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'visibility' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
ble_gatts_svc_set_visibility(handle, vis);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-find-included-services *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_find_included_services(int argc, char **argv)
|
||||
{
|
||||
uint16_t start_handle;
|
||||
uint16_t conn_handle;
|
||||
uint16_t end_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cmd_parse_conn_start_end(&conn_handle, &start_handle, &end_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn start end' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = btshell_find_inc_svcs(conn_handle, start_handle, end_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("error finding included services; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-show *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_show(int argc, char **argv)
|
||||
{
|
||||
struct btshell_conn *conn;
|
||||
struct btshell_svc *svc;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < btshell_num_conns; i++) {
|
||||
conn = btshell_conns + i;
|
||||
|
||||
console_printf("CONNECTION: handle=%d\n", conn->handle);
|
||||
|
||||
SLIST_FOREACH(svc, &conn->svcs, next) {
|
||||
print_svc(svc);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_show_local(int argc, char **argv)
|
||||
{
|
||||
gatt_svr_print_svcs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $gatt-write *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_gatt_write(int argc, char **argv)
|
||||
{
|
||||
struct ble_gatt_attr attrs[MYNEWT_VAL(BLE_GATT_WRITE_MAX_ATTRS)] = { { 0 } };
|
||||
uint16_t attr_handle;
|
||||
uint16_t conn_handle;
|
||||
uint16_t offset;
|
||||
int total_attr_len;
|
||||
int num_attrs;
|
||||
unsigned int attr_len;
|
||||
int is_long;
|
||||
int no_rsp;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
no_rsp = parse_arg_bool_dflt("no_rsp", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'no_rsp' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
is_long = parse_arg_bool_dflt("long", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'long' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
total_attr_len = 0;
|
||||
num_attrs = 0;
|
||||
while (1) {
|
||||
attr_handle = parse_arg_uint16("attr", &rc);
|
||||
if (rc == ENOENT) {
|
||||
break;
|
||||
} else if (rc != 0) {
|
||||
rc = -rc;
|
||||
console_printf("invalid 'attr' parameter\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
rc = parse_arg_byte_stream("value", sizeof cmd_buf - total_attr_len,
|
||||
cmd_buf + total_attr_len, &attr_len);
|
||||
if (rc == ENOENT) {
|
||||
break;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'value' parameter\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
offset = parse_arg_uint16("offset", &rc);
|
||||
if (rc == ENOENT) {
|
||||
offset = 0;
|
||||
} else if (rc != 0) {
|
||||
console_printf("invalid 'offset' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (num_attrs >= sizeof attrs / sizeof attrs[0]) {
|
||||
rc = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
attrs[num_attrs].handle = attr_handle;
|
||||
attrs[num_attrs].offset = offset;
|
||||
attrs[num_attrs].om = ble_hs_mbuf_from_flat(cmd_buf + total_attr_len,
|
||||
attr_len);
|
||||
if (attrs[num_attrs].om == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
total_attr_len += attr_len;
|
||||
num_attrs++;
|
||||
}
|
||||
|
||||
if (no_rsp) {
|
||||
if (num_attrs != 1) {
|
||||
rc = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
rc = btshell_write_no_rsp(conn_handle, attrs[0].handle, attrs[0].om);
|
||||
attrs[0].om = NULL;
|
||||
} else if (is_long) {
|
||||
if (num_attrs != 1) {
|
||||
rc = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
rc = btshell_write_long(conn_handle, attrs[0].handle,
|
||||
attrs[0].offset, attrs[0].om);
|
||||
attrs[0].om = NULL;
|
||||
} else if (num_attrs > 1) {
|
||||
rc = btshell_write_reliable(conn_handle, attrs, num_attrs);
|
||||
} else if (num_attrs == 1) {
|
||||
rc = btshell_write(conn_handle, attrs[0].handle, attrs[0].om);
|
||||
attrs[0].om = NULL;
|
||||
} else {
|
||||
rc = -EINVAL;
|
||||
}
|
||||
|
||||
done:
|
||||
for (i = 0; i < sizeof attrs / sizeof attrs[0]; i++) {
|
||||
os_mbuf_free_chain(attrs[i].om);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
console_printf("error writing characteristic; rc=%d\n", rc);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_enqueue_notif(int argc, char **argv)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_GATT_NOTIFY_MULTIPLE)
|
||||
int rc;
|
||||
uint16_t handle;
|
||||
unsigned int len;
|
||||
uint8_t value[BLE_ATT_ATTR_MAX_LEN];
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
handle = parse_arg_uint16("handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
rc = parse_arg_byte_stream("value", BLE_ATT_ATTR_MAX_LEN, value, &len);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'value' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
return btshell_enqueue_notif(handle, len, value);
|
||||
} else {
|
||||
return btshell_enqueue_notif(handle, 0, NULL);
|
||||
}
|
||||
#else
|
||||
console_printf("To enable this features set BLE_GATT_NOTIFY_MULTIPLE\n");
|
||||
return ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_send_pending_notif(int argc, char **argv)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_GATT_NOTIFY_MULTIPLE)
|
||||
uint16_t conn_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return btshell_send_pending_notif(conn_handle);
|
||||
#else
|
||||
console_printf("To enable this features set BLE_GATT_NOTIFY_MULTIPLE\n");
|
||||
return ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
cmd_gatt_clear_pending_notif(int argc, char **argv)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_GATT_NOTIFY_MULTIPLE)
|
||||
return btshell_clear_pending_notif();
|
||||
#else
|
||||
console_printf("To enable this features set BLE_GATT_NOTIFY_MULTIPLE\n");
|
||||
return ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
42
packages/third-party/nimble/apps/btshell/src/cmd_gatt.h
vendored
Normal file
42
packages/third-party/nimble/apps/btshell/src/cmd_gatt.h
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef CMD_GATT_H
|
||||
#define CMD_GATT_H
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
int cmd_gatt_discover_characteristic(int argc, char **argv);
|
||||
int cmd_gatt_discover_descriptor(int argc, char **argv);
|
||||
int cmd_gatt_discover_service(int argc, char **argv);
|
||||
int cmd_gatt_discover_full(int argc, char **argv);
|
||||
int cmd_gatt_find_included_services(int argc, char **argv);
|
||||
int cmd_gatt_exchange_mtu(int argc, char **argv);
|
||||
int cmd_gatt_notify(int argc, char **argv);
|
||||
int cmd_gatt_read(int argc, char **argv);
|
||||
int cmd_gatt_service_changed(int argc, char **argv);
|
||||
int cmd_gatt_service_visibility(int argc, char **argv);
|
||||
int cmd_gatt_show(int argc, char **argv);
|
||||
int cmd_gatt_show_local(int argc, char **argv);
|
||||
int cmd_gatt_write(int argc, char **argv);
|
||||
int cmd_gatt_enqueue_notif(int argc, char **argv);
|
||||
int cmd_gatt_send_pending_notif(int argc, char **argv);
|
||||
int cmd_gatt_clear_pending_notif(int argc, char **argv);
|
||||
|
||||
#endif
|
||||
562
packages/third-party/nimble/apps/btshell/src/cmd_iso.c
vendored
Normal file
562
packages/third-party/nimble/apps/btshell/src/cmd_iso.c
vendored
Normal file
@@ -0,0 +1,562 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_iso.h"
|
||||
|
||||
#include "cmd_iso.h"
|
||||
|
||||
#include "console/console.h"
|
||||
#include "shell/shell.h"
|
||||
|
||||
#if (MYNEWT_VAL(BLE_ISO))
|
||||
static struct iso_rx_stats {
|
||||
uint16_t conn_handle;
|
||||
bool ts_valid;
|
||||
uint32_t ts;
|
||||
uint16_t seq_num;
|
||||
uint64_t total_cnt;
|
||||
uint64_t valid_cnt;
|
||||
uint64_t error_cnt;
|
||||
uint64_t lost_cnt;
|
||||
} rx_stats_pool[MYNEWT_VAL(BLE_ISO_MAX_BISES)] = {
|
||||
[0 ... MYNEWT_VAL(BLE_ISO_MAX_BISES) - 1] = {
|
||||
.conn_handle = BLE_HS_CONN_HANDLE_NONE
|
||||
}
|
||||
};
|
||||
|
||||
static struct iso_rx_stats *
|
||||
iso_rx_stats_lookup_conn_handle(uint16_t conn_handle)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(rx_stats_pool); i++) {
|
||||
if (rx_stats_pool[i].conn_handle == conn_handle) {
|
||||
return &rx_stats_pool[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct iso_rx_stats *
|
||||
iso_rx_stats_get_or_new(uint16_t conn_handle)
|
||||
{
|
||||
struct iso_rx_stats *rx_stats;
|
||||
|
||||
rx_stats = iso_rx_stats_lookup_conn_handle(conn_handle);
|
||||
if (rx_stats == NULL) {
|
||||
rx_stats = iso_rx_stats_lookup_conn_handle(BLE_HS_CONN_HANDLE_NONE);
|
||||
if (rx_stats == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
rx_stats->conn_handle = conn_handle;
|
||||
|
||||
return rx_stats;
|
||||
}
|
||||
|
||||
static void
|
||||
iso_rx_stats_reset(void)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(rx_stats_pool); i++) {
|
||||
memset(&rx_stats_pool[i], 0, sizeof(rx_stats_pool[i]));
|
||||
rx_stats_pool[i].conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
iso_rx_stats_update(uint16_t conn_handle, const struct ble_iso_rx_data_info *info, void *arg)
|
||||
{
|
||||
struct iso_rx_stats *stats = arg;
|
||||
|
||||
if (!stats) {
|
||||
return;
|
||||
}
|
||||
|
||||
stats->ts_valid = info->ts_valid;
|
||||
if (stats->ts_valid) {
|
||||
stats->ts = info->ts;
|
||||
}
|
||||
|
||||
stats->seq_num = info->seq_num;
|
||||
|
||||
if (info->status == BLE_ISO_DATA_STATUS_VALID) {
|
||||
stats->valid_cnt++;
|
||||
} else if (info->status == BLE_ISO_DATA_STATUS_ERROR) {
|
||||
stats->error_cnt++;
|
||||
} else if (info->status == BLE_ISO_DATA_STATUS_LOST) {
|
||||
stats->lost_cnt++;
|
||||
}
|
||||
|
||||
stats->total_cnt++;
|
||||
|
||||
if ((stats->total_cnt % 100) == 0) {
|
||||
console_printf("conn_handle=0x%04x, seq_num=%d, num_rx=%lld, "
|
||||
"(valid=%lld, error=%lld, lost=%lld) ",
|
||||
stats->conn_handle, stats->seq_num,
|
||||
stats->total_cnt, stats->valid_cnt,
|
||||
stats->error_cnt, stats->lost_cnt);
|
||||
|
||||
if (stats->ts_valid) {
|
||||
console_printf("ts=10%" PRIu32, stats->ts);
|
||||
}
|
||||
|
||||
console_printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_iso_big_desc(const struct ble_iso_big_desc *desc)
|
||||
{
|
||||
console_printf(" big_handle=0x%02x, big_sync_delay=%" PRIu32 ","
|
||||
" transport_latency=%" PRIu32 ", nse=%u, bn=%u, pto=%u,"
|
||||
" irc=%u, max_pdu=%u, iso_interval=%u num_bis=%u",
|
||||
desc->big_handle, desc->big_sync_delay,
|
||||
desc->transport_latency_big, desc->nse, desc->bn, desc->pto,
|
||||
desc->irc, desc->max_pdu, desc->iso_interval, desc->num_bis);
|
||||
|
||||
if (desc->num_bis > 0) {
|
||||
console_printf(" conn_handles=");
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < desc->num_bis; i++) {
|
||||
console_printf("0x%04x,", desc->conn_handle[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ble_iso_event_handler(struct ble_iso_event *event, void *arg)
|
||||
{
|
||||
switch (event->type) {
|
||||
case BLE_ISO_EVENT_BIG_CREATE_COMPLETE:
|
||||
console_printf("BIG Create Completed status: %u",
|
||||
event->big_created.status);
|
||||
|
||||
if (event->big_created.status == 0) {
|
||||
print_iso_big_desc(&event->big_created.desc);
|
||||
console_printf(" phy=0x%02x", event->big_created.phy);
|
||||
}
|
||||
|
||||
console_printf("\n");
|
||||
break;
|
||||
|
||||
case BLE_ISO_EVENT_BIG_SYNC_ESTABLISHED:
|
||||
console_printf("BIG Sync Established status: %u",
|
||||
event->big_sync_established.status);
|
||||
|
||||
if (event->big_sync_established.status == 0) {
|
||||
print_iso_big_desc(&event->big_sync_established.desc);
|
||||
}
|
||||
|
||||
console_printf("\n");
|
||||
break;
|
||||
|
||||
case BLE_ISO_EVENT_BIG_SYNC_TERMINATED:
|
||||
console_printf("BIG Sync Terminated handle=0x%02x reason: %u\n",
|
||||
event->big_terminated.big_handle,
|
||||
event->big_terminated.reason);
|
||||
iso_rx_stats_reset();
|
||||
break;
|
||||
|
||||
case BLE_ISO_EVENT_ISO_RX:
|
||||
iso_rx_stats_update(event->iso_rx.conn_handle, event->iso_rx.info, arg);
|
||||
os_mbuf_free_chain(event->iso_rx.om);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(SHELL_CMD_HELP)
|
||||
static const struct shell_param cmd_iso_big_create_params[] = {
|
||||
{"adv_handle", "PA advertising handle, usage: =<UINT8>"},
|
||||
{"bis_cnt", "BIS count, usage: =<UINT8>"},
|
||||
{"sdu_interval", "SDU interval, usage: =<UINT32>"},
|
||||
{"max_sdu", "Maximum SDU size, usage: =<UINT16>"},
|
||||
{"max_latency", "Maximum transport latency, usage: =<UINT16>"},
|
||||
{"rtn", "Retransmission number, usage: =<UINT8>"},
|
||||
{"phy", "PHY, usage: =<UINT8>"},
|
||||
{"packing", "Packing, usage: =<UINT8>, default: 1"},
|
||||
{"framing", "Framing, usage: =<UINT8>, default: 0"},
|
||||
{"broadcast_code", "Broadcast Code, usage: =[string], default: NULL"},
|
||||
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
const struct shell_cmd_help cmd_iso_big_create_help = {
|
||||
.summary = "Create BIG",
|
||||
.usage = NULL,
|
||||
.params = cmd_iso_big_create_params,
|
||||
};
|
||||
#endif /* SHELL_CMD_HELP */
|
||||
|
||||
int
|
||||
cmd_iso_big_create(int argc, char **argv)
|
||||
{
|
||||
struct ble_iso_create_big_params params = { 0 };
|
||||
struct ble_iso_big_params big_params = { 0 };
|
||||
uint8_t big_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.adv_handle = parse_arg_uint8("adv_handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'adv_handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.cb = ble_iso_event_handler;
|
||||
|
||||
params.bis_cnt = parse_arg_uint8("bis_cnt", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'bis_cnt' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.sdu_interval = parse_arg_uint32_bounds("sdu_interval",
|
||||
0x0000FF, 0x0FFFFF,
|
||||
&rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'sdu_interval' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.max_sdu = parse_arg_uint16_bounds("max_sdu", 0x0001, 0x0FFF,
|
||||
&rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'max_sdu' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.max_transport_latency = parse_arg_uint16_bounds("max_latency",
|
||||
0x0005, 0x0FA0,
|
||||
&rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'max_latency' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.rtn = parse_arg_uint8_bounds("rtn", 0x00, 0x1E, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'rtn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.phy = parse_arg_uint8_bounds("phy", 0, 2, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'phy' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.packing = parse_arg_uint8_bounds_dflt("packing", 0, 1, 1, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'packing' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.framing = parse_arg_uint8_bounds_dflt("framing", 0, 1, 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'framing' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_params.broadcast_code = parse_arg_extract("broadcast_code");
|
||||
big_params.encryption = big_params.broadcast_code ? 1 : 0;
|
||||
|
||||
rc = ble_iso_create_big(¶ms, &big_params, &big_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("BIG create failed (%d)\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
console_printf("New big_handle %u created\n", big_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(SHELL_CMD_HELP)
|
||||
static const struct shell_param cmd_iso_big_terminate_params[] = {
|
||||
{"big_handle", "BIG handle, usage: =<UINT8>"},
|
||||
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
const struct shell_cmd_help cmd_iso_big_terminate_help = {
|
||||
.summary = "Terminate BIG",
|
||||
.usage = NULL,
|
||||
.params = cmd_iso_big_terminate_params,
|
||||
};
|
||||
#endif /* SHELL_CMD_HELP */
|
||||
|
||||
int
|
||||
cmd_iso_big_terminate(int argc, char **argv)
|
||||
{
|
||||
uint8_t big_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_handle = parse_arg_uint8("big_handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'big_handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_iso_terminate_big(big_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("BIG terminate failed (%d)\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(SHELL_CMD_HELP)
|
||||
static const struct shell_param cmd_iso_big_sync_create_params[] = {
|
||||
{"sync_handle", "PA sync handle, usage: =<UINT16>"},
|
||||
{"broadcast_code", "Broadcast Code, usage: =[string], default: NULL"},
|
||||
{"mse", "Maximum Subevents to receive data, usage: =<UINT8>"},
|
||||
{"sync_timeout", "BIG sync timeout, usage: =<UINT8>"},
|
||||
{"idxs", "BIS indexes, usage: =XX,YY,..."},
|
||||
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
const struct shell_cmd_help cmd_iso_big_sync_create_help = {
|
||||
.summary = "Synchronize to BIG",
|
||||
.usage = NULL,
|
||||
.params = cmd_iso_big_sync_create_params,
|
||||
};
|
||||
#endif /* SHELL_CMD_HELP */
|
||||
|
||||
int
|
||||
cmd_iso_big_sync_create(int argc, char **argv)
|
||||
{
|
||||
struct ble_iso_bis_params bis_params[MYNEWT_VAL(BLE_ISO_MAX_BISES)];
|
||||
struct ble_iso_big_sync_create_params params = { 0 };
|
||||
uint8_t bis_idxs[MYNEWT_VAL(BLE_ISO_MAX_BISES)];
|
||||
uint8_t big_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.sync_handle = parse_arg_uint16("sync_handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'sync_handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.broadcast_code = parse_arg_extract("broadcast_code");
|
||||
|
||||
params.mse = parse_arg_uint8_dflt("mse", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'mse' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.sync_timeout = parse_arg_uint16("sync_timeout", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'sync_timeout' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = parse_arg_byte_stream_custom("idxs", ",", ARRAY_SIZE(bis_idxs),
|
||||
bis_idxs, 0,
|
||||
(unsigned int *)¶ms.bis_cnt);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'idxs' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < params.bis_cnt; i++) {
|
||||
bis_params[i].bis_index = bis_idxs[i];
|
||||
}
|
||||
|
||||
params.bis_params = bis_params;
|
||||
params.cb = ble_iso_event_handler;
|
||||
|
||||
rc = ble_iso_big_sync_create(¶ms, &big_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("BIG Sync create failed (%d)\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
console_printf("New big_handle %u created\n", big_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(SHELL_CMD_HELP)
|
||||
static const struct shell_param cmd_iso_big_sync_terminate_params[] = {
|
||||
{"big_handle", "BIG handle, usage: =<UINT8>"},
|
||||
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
const struct shell_cmd_help cmd_iso_big_sync_terminate_help = {
|
||||
.summary = "Terminate BIG sync",
|
||||
.usage = NULL,
|
||||
.params = cmd_iso_big_sync_terminate_params,
|
||||
};
|
||||
#endif /* SHELL_CMD_HELP */
|
||||
|
||||
int
|
||||
cmd_iso_big_sync_terminate(int argc, char **argv)
|
||||
{
|
||||
uint8_t big_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
big_handle = parse_arg_uint8("big_handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'big_handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_iso_big_sync_terminate(big_handle);
|
||||
if (rc != 0) {
|
||||
console_printf("BIG Sync terminate failed (%d)\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct parse_arg_kv_pair cmd_iso_data_dir[] = {
|
||||
{ "tx", BLE_ISO_DATA_DIR_TX },
|
||||
{ "rx", BLE_ISO_DATA_DIR_RX },
|
||||
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
#if MYNEWT_VAL(SHELL_CMD_HELP)
|
||||
static const struct shell_param cmd_iso_data_path_setup_params[] = {
|
||||
{"conn_handle", "Connection handle, usage: =<UINT16>"},
|
||||
{"dir", "Data path direction, usage: =[tx|rx]"},
|
||||
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
const struct shell_cmd_help cmd_iso_data_path_setup_help = {
|
||||
.summary = "Setup ISO Data Path",
|
||||
.usage = NULL,
|
||||
.params = cmd_iso_data_path_setup_params,
|
||||
};
|
||||
#endif /* SHELL_CMD_HELP */
|
||||
|
||||
int
|
||||
cmd_iso_data_path_setup(int argc, char **argv)
|
||||
{
|
||||
struct ble_iso_data_path_setup_params params = { 0 };
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.conn_handle = parse_arg_uint16("conn_handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn_handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.data_path_dir = parse_arg_kv("dir", cmd_iso_data_dir, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'dir' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* For now, the Data Path ID is set to HCI by default */
|
||||
params.cb = ble_iso_event_handler;
|
||||
params.cb_arg = iso_rx_stats_get_or_new(params.conn_handle);
|
||||
|
||||
rc = ble_iso_data_path_setup(¶ms);
|
||||
if (rc != 0) {
|
||||
console_printf("ISO Data Path setup failed (%d)\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(SHELL_CMD_HELP)
|
||||
static const struct shell_param cmd_iso_data_path_remove_params[] = {
|
||||
{"conn_handle", "Connection handle, usage: =<UINT16>"},
|
||||
{"dir", "Data path direction, usage: =[tx|rx]"},
|
||||
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
const struct shell_cmd_help cmd_iso_data_path_remove_help = {
|
||||
.summary = "Remove ISO Data Path",
|
||||
.usage = NULL,
|
||||
.params = cmd_iso_data_path_remove_params,
|
||||
};
|
||||
#endif /* SHELL_CMD_HELP */
|
||||
|
||||
int
|
||||
cmd_iso_data_path_remove(int argc, char **argv)
|
||||
{
|
||||
struct ble_iso_data_path_remove_params params = { 0 };
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.conn_handle = parse_arg_uint16("conn_handle", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn_handle' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.data_path_dir = parse_arg_kv("dir", cmd_iso_data_dir, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'dir' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_iso_data_path_remove(¶ms);
|
||||
if (rc != 0) {
|
||||
console_printf("ISO Data Path remove failed (%d)\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* BLE_ISO */
|
||||
39
packages/third-party/nimble/apps/btshell/src/cmd_iso.h
vendored
Normal file
39
packages/third-party/nimble/apps/btshell/src/cmd_iso.h
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef H_CMD_ISO_
|
||||
#define H_CMD_ISO_
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
extern const struct shell_cmd_help cmd_iso_big_create_help;
|
||||
extern const struct shell_cmd_help cmd_iso_big_terminate_help;
|
||||
extern const struct shell_cmd_help cmd_iso_big_sync_create_help;
|
||||
extern const struct shell_cmd_help cmd_iso_big_sync_terminate_help;
|
||||
extern const struct shell_cmd_help cmd_iso_data_path_setup_help;
|
||||
extern const struct shell_cmd_help cmd_iso_data_path_remove_help;
|
||||
|
||||
int cmd_iso_big_create(int argc, char **argv);
|
||||
int cmd_iso_big_terminate(int argc, char **argv);
|
||||
int cmd_iso_big_sync_create(int argc, char **argv);
|
||||
int cmd_iso_big_sync_terminate(int argc, char **argv);
|
||||
int cmd_iso_data_path_setup(int argc, char **argv);
|
||||
int cmd_iso_data_path_remove(int argc, char **argv);
|
||||
|
||||
#endif /* H_CMD_ISO_ */
|
||||
325
packages/third-party/nimble/apps/btshell/src/cmd_l2cap.c
vendored
Normal file
325
packages/third-party/nimble/apps/btshell/src/cmd_l2cap.c
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "host/ble_l2cap.h"
|
||||
#include "console/console.h"
|
||||
#include "btshell.h"
|
||||
#include "cmd.h"
|
||||
#include "cmd_l2cap.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* $l2cap-update *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_l2cap_update(int argc, char **argv)
|
||||
{
|
||||
struct ble_l2cap_sig_update_params params;
|
||||
uint16_t conn_handle;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn_handle = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.itvl_min = parse_arg_uint16_dflt("interval_min",
|
||||
BLE_GAP_INITIAL_CONN_ITVL_MIN,
|
||||
&rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'interval_min' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.itvl_max = parse_arg_uint16_dflt("interval_max",
|
||||
BLE_GAP_INITIAL_CONN_ITVL_MAX,
|
||||
&rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'interval_max' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.slave_latency = parse_arg_uint16_dflt("latency", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'latency' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
params.timeout_multiplier = parse_arg_uint16_dflt("timeout", 0x0100, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'timeout' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = btshell_l2cap_update(conn_handle, ¶ms);
|
||||
if (rc != 0) {
|
||||
console_printf("error txing l2cap update; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $l2cap-create-server *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_l2cap_create_server(int argc, char **argv)
|
||||
{
|
||||
uint16_t psm = 0;
|
||||
uint16_t mtu;
|
||||
int error;
|
||||
int accept_response = 0;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
psm = parse_arg_uint16("psm", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'psm' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
error = parse_arg_uint32_dflt("error", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'error' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
mtu = parse_arg_uint16_dflt("mtu", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'mtu' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
switch (error) {
|
||||
case 1:
|
||||
accept_response = BLE_HS_EAUTHEN;
|
||||
break;
|
||||
case 2:
|
||||
accept_response = BLE_HS_EAUTHOR;
|
||||
break;
|
||||
case 3:
|
||||
accept_response = BLE_HS_EENCRYPT_KEY_SZ;
|
||||
break;
|
||||
}
|
||||
|
||||
rc = btshell_l2cap_create_srv(psm, mtu, accept_response);
|
||||
if (rc) {
|
||||
console_printf("Server create error: 0x%02x\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
console_printf("Server created successfully\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $l2cap-connect *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_l2cap_connect(int argc, char **argv)
|
||||
{
|
||||
uint16_t conn = 0;
|
||||
uint16_t psm = 0;
|
||||
uint16_t mtu;
|
||||
uint8_t num;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
psm = parse_arg_uint16("psm", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'psm' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
mtu = parse_arg_uint16_dflt("mtu", 0, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'mtu' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
num = parse_arg_uint8_dflt("num", 1, &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'num' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return btshell_l2cap_connect(conn, psm, mtu, num);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $l2cap-disconnect *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_l2cap_disconnect(int argc, char **argv)
|
||||
{
|
||||
uint16_t conn;
|
||||
uint16_t idx;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
idx = parse_arg_uint16("idx", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'idx' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return btshell_l2cap_disconnect(conn, idx);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $l2cap-send *
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
cmd_l2cap_send(int argc, char **argv)
|
||||
{
|
||||
uint16_t conn;
|
||||
uint16_t idx;
|
||||
uint16_t bytes;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
idx = parse_arg_uint16("idx", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'idx' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
bytes = parse_arg_uint16("bytes", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'bytes' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return btshell_l2cap_send(conn, idx, bytes);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_l2cap_show_coc(int argc, char **argv)
|
||||
{
|
||||
struct btshell_conn *conn = NULL;
|
||||
struct btshell_l2cap_coc *coc;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < btshell_num_conns; i++) {
|
||||
conn = btshell_conns + i;
|
||||
|
||||
if (SLIST_EMPTY(&conn->coc_list)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console_printf("conn_handle: 0x%04x\n", conn->handle);
|
||||
j = 0;
|
||||
SLIST_FOREACH(coc, &conn->coc_list, next) {
|
||||
console_printf(" idx: %i, chan pointer = %p\n", j++, coc->chan);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_l2cap_reconfig(int argc, char **argv)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_L2CAP_ENHANCED_COC)
|
||||
uint16_t conn;
|
||||
uint16_t mtu;
|
||||
uint8_t idxs[5];
|
||||
unsigned int num;
|
||||
int rc;
|
||||
|
||||
rc = parse_arg_init(argc - 1, argv + 1);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn = parse_arg_uint16("conn", &rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'conn' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
mtu = parse_arg_uint16_dflt("mtu", 0,&rc);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'mtu' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = parse_arg_byte_stream_custom("idxs", ",", 5, idxs, 0, &num);
|
||||
if (rc != 0) {
|
||||
console_printf("invalid 'idxs' parameter\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return btshell_l2cap_reconfig(conn, mtu, num, idxs);
|
||||
#else
|
||||
console_printf("To enable this features set BLE_L2CAP_ENHANCED_COC\n");
|
||||
return ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
33
packages/third-party/nimble/apps/btshell/src/cmd_l2cap.h
vendored
Normal file
33
packages/third-party/nimble/apps/btshell/src/cmd_l2cap.h
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef CMD_L2CAP_H
|
||||
#define CMD_L2CAP_H
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
int cmd_l2cap_update(int argc, char **argv);
|
||||
int cmd_l2cap_create_server(int argc, char **argv);
|
||||
int cmd_l2cap_connect(int argc, char **argv);
|
||||
int cmd_l2cap_disconnect(int argc, char **argv);
|
||||
int cmd_l2cap_send(int argc, char **argv);
|
||||
int cmd_l2cap_show_coc(int argc, char **argv);
|
||||
int cmd_l2cap_reconfig(int argc, char **argv);
|
||||
|
||||
#endif
|
||||
1088
packages/third-party/nimble/apps/btshell/src/cmd_leaudio.c
vendored
Normal file
1088
packages/third-party/nimble/apps/btshell/src/cmd_leaudio.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
66
packages/third-party/nimble/apps/btshell/src/cmd_leaudio.h
vendored
Normal file
66
packages/third-party/nimble/apps/btshell/src/cmd_leaudio.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef H_CMD_LEAUDIO_
|
||||
#define H_CMD_LEAUDIO_
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
#define CMD_ADV_DATA_CODEC_SPEC_CFG_MAX_SZ (9)
|
||||
/**
|
||||
* Maximum Metadata size is maximum adv size minus minimum size of other
|
||||
* fields in BASE advertising
|
||||
*/
|
||||
#define CMD_ADV_DATA_METADATA_MAX_SZ (MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) - 27)
|
||||
/**
|
||||
* Maximum size of extra data included in BASE advertising. Assumes minimum
|
||||
* size of other fields.
|
||||
*/
|
||||
#define CMD_ADV_DATA_EXTRA_MAX_SZ (MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) - 27)
|
||||
|
||||
int cmd_leaudio_base_add(int argc, char **argv);
|
||||
int cmd_leaudio_big_sub_add(int argc, char **argv);
|
||||
int cmd_leaudio_bis_add(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_create(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_destroy(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_update(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_start(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_stop(int argc, char **argv);
|
||||
|
||||
extern const struct shell_cmd_help cmd_leaudio_broadcast_sink_start_help;
|
||||
extern const struct shell_cmd_help cmd_leaudio_broadcast_sink_stop_help;
|
||||
extern const struct shell_cmd_help cmd_leaudio_broadcast_sink_metadata_update_help;
|
||||
|
||||
int cmd_leaudio_broadcast_sink_start(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_sink_stop(int argc, char **argv);
|
||||
int cmd_leaudio_broadcast_sink_metadata_update(int argc, char **argv);
|
||||
|
||||
extern const struct shell_cmd_help cmd_leaudio_scan_delegator_receive_state_add_help;
|
||||
extern const struct shell_cmd_help cmd_leaudio_scan_delegator_receive_state_remove_help;
|
||||
extern const struct shell_cmd_help cmd_leaudio_scan_delegator_receive_state_set_help;
|
||||
extern const struct shell_cmd_help cmd_leaudio_scan_delegator_receive_state_get_help;
|
||||
extern const struct shell_cmd_help cmd_leaudio_scan_delegator_receive_state_show_help;
|
||||
|
||||
int cmd_leaudio_scan_delegator_receive_state_add(int argc, char **argv);
|
||||
int cmd_leaudio_scan_delegator_receive_state_remove(int argc, char **argv);
|
||||
int cmd_leaudio_scan_delegator_receive_state_set(int argc, char **argv);
|
||||
int cmd_leaudio_scan_delegator_receive_state_get(int argc, char **argv);
|
||||
int cmd_leaudio_scan_delegator_receive_state_show(int argc, char **argv);
|
||||
|
||||
#endif /* H_CMD_LEAUDIO_ */
|
||||
646
packages/third-party/nimble/apps/btshell/src/gatt_svr.c
vendored
Normal file
646
packages/third-party/nimble/apps/btshell/src/gatt_svr.c
vendored
Normal file
@@ -0,0 +1,646 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "bsp/bsp.h"
|
||||
#include "console/console.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_uuid.h"
|
||||
#include "host/ble_gatt.h"
|
||||
#include "btshell.h"
|
||||
|
||||
/* 0000xxxx-8c26-476f-89a7-a108033a69c7 */
|
||||
#define PTS_UUID_DECLARE(uuid16) \
|
||||
((const ble_uuid_t *) (&(ble_uuid128_t) BLE_UUID128_INIT( \
|
||||
0xc7, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89, \
|
||||
0x6f, 0x47, 0x26, 0x8c, uuid16, uuid16 >> 8, 0x00, 0x00 \
|
||||
)))
|
||||
|
||||
#define PTS_SVC 0x0001
|
||||
#define PTS_CHR_READ 0x0002
|
||||
#define PTS_CHR_WRITE 0x0003
|
||||
#define PTS_CHR_RELIABLE_WRITE 0x0004
|
||||
#define PTS_CHR_WRITE_NO_RSP 0x0005
|
||||
#define PTS_CHR_READ_WRITE 0x0006
|
||||
#define PTS_CHR_READ_WRITE_ENC 0x0007
|
||||
#define PTS_CHR_READ_WRITE_AUTHEN 0x0008
|
||||
#define PTS_DSC_READ 0x0009
|
||||
#define PTS_DSC_WRITE 0x000a
|
||||
#define PTS_DSC_READ_WRITE 0x000b
|
||||
#define PTS_DSC_READ_WRITE_ENC 0x000c
|
||||
#define PTS_DSC_READ_WRITE_AUTHEN 0x000d
|
||||
|
||||
#define PTS_LONG_SVC 0x0011
|
||||
#define PTS_LONG_CHR_READ 0x0012
|
||||
#define PTS_LONG_CHR_WRITE 0x0013
|
||||
#define PTS_LONG_CHR_RELIABLE_WRITE 0x0014
|
||||
#define PTS_LONG_CHR_READ_WRITE 0x0015
|
||||
#define PTS_LONG_CHR_READ_WRITE_ALT 0x0016
|
||||
#define PTS_LONG_CHR_READ_WRITE_ENC 0x0017
|
||||
#define PTS_LONG_CHR_READ_WRITE_AUTHEN 0x0018
|
||||
#define PTS_LONG_DSC_READ 0x0019
|
||||
#define PTS_LONG_DSC_WRITE 0x001a
|
||||
#define PTS_LONG_DSC_READ_WRITE 0x001b
|
||||
#define PTS_LONG_DSC_READ_WRITE_ENC 0x001c
|
||||
#define PTS_LONG_DSC_READ_WRITE_AUTHEN 0x001d
|
||||
|
||||
#define PTS_INC_SVC 0x001e
|
||||
#define PTS_CHR_READ_WRITE_ALT 0x001f
|
||||
|
||||
/**
|
||||
* The vendor specific security test service consists of two characteristics:
|
||||
* o random-number-generator: generates a random 32-bit number each time
|
||||
* it is read. This characteristic can only be read over an encrypted
|
||||
* connection.
|
||||
* o static-value: a single-byte characteristic that can always be read,
|
||||
* but can only be written over an encrypted connection.
|
||||
*/
|
||||
|
||||
/* 59462f12-9543-9999-12c8-58b459a2712d */
|
||||
static const ble_uuid128_t gatt_svr_svc_sec_test_uuid =
|
||||
BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
|
||||
0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
|
||||
|
||||
/* 5c3a659e-897e-45e1-b016-007107c96df6 */
|
||||
static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid =
|
||||
BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
|
||||
0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
|
||||
|
||||
/* 5c3a659e-897e-45e1-b016-007107c96df7 */
|
||||
static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid =
|
||||
BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
|
||||
0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
|
||||
|
||||
/* 5c3a659e-897e-45e1-b016-007107c96df8 */
|
||||
static const ble_uuid128_t gatt_svr_chr_sec_test_static_auth_uuid =
|
||||
BLE_UUID128_INIT(0xf8, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
|
||||
0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
|
||||
|
||||
static uint8_t gatt_svr_sec_test_static_val;
|
||||
|
||||
static uint8_t gatt_svr_pts_static_val;
|
||||
static uint8_t gatt_svr_pts_static_long_val[30];
|
||||
static uint8_t gatt_svr_pts_static_long_val_alt[30];
|
||||
|
||||
static int
|
||||
gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt,
|
||||
void *arg);
|
||||
|
||||
static int
|
||||
gatt_svr_access_test(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt,
|
||||
void *arg);
|
||||
|
||||
static int
|
||||
gatt_svr_long_access_test(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt,
|
||||
void *arg);
|
||||
|
||||
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
||||
{
|
||||
/*** Service: PTS test. */
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
.uuid = PTS_UUID_DECLARE(PTS_SVC),
|
||||
.characteristics = (struct ble_gatt_chr_def[]) { {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_RELIABLE_WRITE),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_RELIABLE_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE_NO_RSP),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE_NO_RSP,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ENC),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC |
|
||||
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
|
||||
.min_key_size = 16,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHEN),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN |
|
||||
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_AUTHEN,
|
||||
|
||||
.descriptors = (struct ble_gatt_dsc_def[]){ {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_DSC_READ),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.att_flags = BLE_ATT_F_READ,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_DSC_WRITE),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.att_flags = BLE_ATT_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_ENC),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC |
|
||||
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC,
|
||||
.min_key_size = 16,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_AUTHEN),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_AUTHEN |
|
||||
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_AUTHEN,
|
||||
}, {
|
||||
0, /* No more descriptors in this characteristic. */
|
||||
} }
|
||||
}, {
|
||||
0, /* No more characteristics in this service. */
|
||||
} },
|
||||
},
|
||||
|
||||
{
|
||||
/*** Service: PTS long test. */
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_SVC),
|
||||
.characteristics = (struct ble_gatt_chr_def[]) { {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_WRITE),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_RELIABLE_WRITE),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_RELIABLE_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ALT),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ENC),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC |
|
||||
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
|
||||
.min_key_size = 16,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_AUTHEN),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN |
|
||||
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_AUTHEN,
|
||||
|
||||
.descriptors = (struct ble_gatt_dsc_def[]){ {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.att_flags = BLE_ATT_F_READ,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_WRITE),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.att_flags = BLE_ATT_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE_ENC),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC |
|
||||
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC,
|
||||
.min_key_size = 16,
|
||||
}, {
|
||||
.uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE_AUTHEN),
|
||||
.access_cb = gatt_svr_long_access_test,
|
||||
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_AUTHEN |
|
||||
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_AUTHEN,
|
||||
}, {
|
||||
0, /* No more descriptors in this characteristic. */
|
||||
} }
|
||||
}, {
|
||||
0, /* No more characteristics in this service. */
|
||||
} },
|
||||
},
|
||||
|
||||
{
|
||||
/*** Service: Security test. */
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
.uuid = &gatt_svr_svc_sec_test_uuid.u,
|
||||
.characteristics = (struct ble_gatt_chr_def[]) { {
|
||||
/*** Characteristic: Random number generator. */
|
||||
.uuid = &gatt_svr_chr_sec_test_rand_uuid.u,
|
||||
.access_cb = gatt_svr_chr_access_sec_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
|
||||
}, {
|
||||
/*** Characteristic: Static value. */
|
||||
.uuid = &gatt_svr_chr_sec_test_static_uuid.u,
|
||||
.access_cb = gatt_svr_chr_access_sec_test,
|
||||
.flags = BLE_GATT_CHR_F_READ |
|
||||
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
|
||||
}, {
|
||||
/*** Characteristic: Static value. */
|
||||
.uuid = &gatt_svr_chr_sec_test_static_auth_uuid.u,
|
||||
.access_cb = gatt_svr_chr_access_sec_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN,
|
||||
}, {
|
||||
0, /* No more characteristics in this service. */
|
||||
} },
|
||||
},
|
||||
|
||||
{
|
||||
0, /* No more services. */
|
||||
},
|
||||
};
|
||||
|
||||
static const struct ble_gatt_svc_def *inc_svcs[] = {
|
||||
&gatt_svr_svcs[0],
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct ble_gatt_svc_def gatt_svr_inc_svcs[] = {
|
||||
{
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
.uuid = PTS_UUID_DECLARE(PTS_INC_SVC),
|
||||
.includes = inc_svcs,
|
||||
.characteristics = (struct ble_gatt_chr_def[]) {{
|
||||
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ALT),
|
||||
.access_cb = gatt_svr_access_test,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
||||
}, {
|
||||
0, /* No more characteristics */
|
||||
}, },
|
||||
},
|
||||
|
||||
{
|
||||
0, /* No more services. */
|
||||
},
|
||||
};
|
||||
|
||||
static int
|
||||
gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
|
||||
void *dst, uint16_t *len)
|
||||
{
|
||||
uint16_t om_len;
|
||||
int rc;
|
||||
|
||||
om_len = OS_MBUF_PKTLEN(om);
|
||||
if (om_len < min_len || om_len > max_len) {
|
||||
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
|
||||
}
|
||||
|
||||
rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
|
||||
if (rc != 0) {
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt,
|
||||
void *arg)
|
||||
{
|
||||
const ble_uuid_t *uuid;
|
||||
int rand_num;
|
||||
int rc;
|
||||
|
||||
uuid = ctxt->chr->uuid;
|
||||
|
||||
/* Determine which characteristic is being accessed by examining its
|
||||
* 128-bit UUID.
|
||||
*/
|
||||
|
||||
if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) {
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
|
||||
|
||||
/* Respond with a 32-bit random number. */
|
||||
rand_num = rand();
|
||||
rc = os_mbuf_append(ctxt->om, &rand_num, sizeof rand_num);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0 ||
|
||||
ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_auth_uuid.u) == 0) {
|
||||
switch (ctxt->op) {
|
||||
case BLE_GATT_ACCESS_OP_READ_CHR:
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val,
|
||||
sizeof gatt_svr_sec_test_static_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
|
||||
case BLE_GATT_ACCESS_OP_WRITE_CHR:
|
||||
rc = gatt_svr_chr_write(ctxt->om,
|
||||
sizeof gatt_svr_sec_test_static_val,
|
||||
sizeof gatt_svr_sec_test_static_val,
|
||||
&gatt_svr_sec_test_static_val, NULL);
|
||||
return rc;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unknown characteristic; the nimble stack should not have called this
|
||||
* function.
|
||||
*/
|
||||
assert(0);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
/* This method is used for PTS testing only, to extract 16 bit value
|
||||
* from 128 bit vendor specific UUID.
|
||||
*/
|
||||
static uint16_t
|
||||
extract_uuid16_from_pts_uuid128(const ble_uuid_t *uuid)
|
||||
{
|
||||
const uint8_t *u8ptr;
|
||||
uint16_t uuid16;
|
||||
|
||||
u8ptr = BLE_UUID128(uuid)->value;
|
||||
uuid16 = u8ptr[12];
|
||||
uuid16 |= (uint16_t)u8ptr[13] << 8;
|
||||
return uuid16;
|
||||
}
|
||||
|
||||
static int
|
||||
gatt_svr_access_test(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt,
|
||||
void *arg)
|
||||
{
|
||||
uint16_t uuid16;
|
||||
int rc;
|
||||
|
||||
uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
|
||||
assert(uuid16 != 0);
|
||||
|
||||
switch (uuid16) {
|
||||
case PTS_CHR_READ:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
|
||||
sizeof gatt_svr_pts_static_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
|
||||
case PTS_CHR_WRITE:
|
||||
case PTS_CHR_RELIABLE_WRITE:
|
||||
case PTS_CHR_WRITE_NO_RSP:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_val,
|
||||
&gatt_svr_pts_static_val, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
|
||||
sizeof gatt_svr_pts_static_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
case PTS_CHR_READ_WRITE:
|
||||
case PTS_CHR_READ_WRITE_ENC:
|
||||
case PTS_CHR_READ_WRITE_AUTHEN:
|
||||
case PTS_CHR_READ_WRITE_ALT:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_val,
|
||||
&gatt_svr_pts_static_val, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
|
||||
sizeof gatt_svr_pts_static_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
case PTS_DSC_READ:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC);
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
|
||||
sizeof gatt_svr_pts_static_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
|
||||
case PTS_DSC_WRITE:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC);
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_val,
|
||||
&gatt_svr_pts_static_val, NULL);
|
||||
return rc;
|
||||
|
||||
case PTS_DSC_READ_WRITE:
|
||||
case PTS_DSC_READ_WRITE_ENC:
|
||||
case PTS_DSC_READ_WRITE_AUTHEN:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_val,
|
||||
&gatt_svr_pts_static_val, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
|
||||
sizeof gatt_svr_pts_static_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
static int
|
||||
gatt_svr_long_access_test(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt,
|
||||
void *arg)
|
||||
{
|
||||
uint16_t uuid16;
|
||||
int rc;
|
||||
|
||||
uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
|
||||
assert(uuid16 != 0);
|
||||
|
||||
switch (uuid16) {
|
||||
case PTS_LONG_CHR_READ:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
|
||||
sizeof gatt_svr_pts_static_long_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
|
||||
case PTS_LONG_CHR_WRITE:
|
||||
case PTS_LONG_CHR_RELIABLE_WRITE:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR);
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_long_val,
|
||||
&gatt_svr_pts_static_long_val, NULL);
|
||||
return rc;
|
||||
|
||||
case PTS_LONG_CHR_READ_WRITE:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_long_val,
|
||||
&gatt_svr_pts_static_long_val, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
|
||||
sizeof gatt_svr_pts_static_long_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
case PTS_LONG_CHR_READ_WRITE_ALT:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_long_val_alt,
|
||||
&gatt_svr_pts_static_long_val_alt, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val_alt,
|
||||
sizeof gatt_svr_pts_static_long_val_alt);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
case PTS_LONG_CHR_READ_WRITE_ENC:
|
||||
case PTS_LONG_CHR_READ_WRITE_AUTHEN:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_long_val,
|
||||
&gatt_svr_pts_static_long_val, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
|
||||
sizeof gatt_svr_pts_static_long_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
case PTS_LONG_DSC_READ:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC);
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
|
||||
sizeof gatt_svr_pts_static_long_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
|
||||
case PTS_LONG_DSC_WRITE:
|
||||
assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC);
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_long_val,
|
||||
&gatt_svr_pts_static_long_val, NULL);
|
||||
return rc;
|
||||
|
||||
case PTS_LONG_DSC_READ_WRITE:
|
||||
case PTS_LONG_DSC_READ_WRITE_ENC:
|
||||
case PTS_LONG_DSC_READ_WRITE_AUTHEN:
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
|
||||
rc = gatt_svr_chr_write(ctxt->om,0,
|
||||
sizeof gatt_svr_pts_static_long_val,
|
||||
&gatt_svr_pts_static_long_val, NULL);
|
||||
return rc;
|
||||
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
|
||||
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
|
||||
sizeof gatt_svr_pts_static_long_val);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
||||
{
|
||||
char buf[BLE_UUID_STR_LEN];
|
||||
|
||||
switch (ctxt->op) {
|
||||
case BLE_GATT_REGISTER_OP_SVC:
|
||||
MODLOG_DFLT(DEBUG, "registered service %s with handle=%d\n",
|
||||
ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
|
||||
ctxt->svc.handle);
|
||||
break;
|
||||
|
||||
case BLE_GATT_REGISTER_OP_CHR:
|
||||
MODLOG_DFLT(DEBUG, "registering characteristic %s with "
|
||||
"def_handle=%d val_handle=%d\n",
|
||||
ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
|
||||
ctxt->chr.def_handle,
|
||||
ctxt->chr.val_handle);
|
||||
break;
|
||||
|
||||
case BLE_GATT_REGISTER_OP_DSC:
|
||||
MODLOG_DFLT(DEBUG, "registering descriptor %s with handle=%d\n",
|
||||
ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
|
||||
ctxt->dsc.handle);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gatt_svr_print_svcs(void)
|
||||
{
|
||||
ble_gatts_show_local();
|
||||
}
|
||||
|
||||
int
|
||||
gatt_svr_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_gatts_count_cfg(gatt_svr_svcs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_gatts_add_svcs(gatt_svr_svcs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_gatts_count_cfg(gatt_svr_inc_svcs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_gatts_add_svcs(gatt_svr_inc_svcs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
3159
packages/third-party/nimble/apps/btshell/src/main.c
vendored
Normal file
3159
packages/third-party/nimble/apps/btshell/src/main.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
163
packages/third-party/nimble/apps/btshell/src/misc.c
vendored
Normal file
163
packages/third-party/nimble/apps/btshell/src/misc.c
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include "console/console.h"
|
||||
#include "host/ble_uuid.h"
|
||||
#include "host/ble_gap.h"
|
||||
|
||||
#include "btshell.h"
|
||||
|
||||
/**
|
||||
* Utility function to log an array of bytes.
|
||||
*/
|
||||
void
|
||||
print_bytes(const uint8_t *bytes, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
console_printf("%s0x%02x", i != 0 ? ":" : "", bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_mbuf(const struct os_mbuf *om)
|
||||
{
|
||||
int colon;
|
||||
|
||||
colon = 0;
|
||||
while (om != NULL) {
|
||||
if (colon) {
|
||||
console_printf(":");
|
||||
} else {
|
||||
colon = 1;
|
||||
}
|
||||
print_bytes(om->om_data, om->om_len);
|
||||
om = SLIST_NEXT(om, om_next);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_addr(const void *addr)
|
||||
{
|
||||
const uint8_t *u8p;
|
||||
|
||||
u8p = addr;
|
||||
console_printf("%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
|
||||
}
|
||||
|
||||
void
|
||||
print_uuid(const ble_uuid_t *uuid)
|
||||
{
|
||||
char buf[BLE_UUID_STR_LEN];
|
||||
|
||||
ble_uuid_to_str(uuid, buf);
|
||||
|
||||
console_printf("%s", buf);
|
||||
}
|
||||
|
||||
int
|
||||
svc_is_empty(const struct btshell_svc *svc)
|
||||
{
|
||||
return svc->svc.end_handle <= svc->svc.start_handle;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
chr_end_handle(const struct btshell_svc *svc, const struct btshell_chr *chr)
|
||||
{
|
||||
const struct btshell_chr *next_chr;
|
||||
|
||||
next_chr = SLIST_NEXT(chr, next);
|
||||
if (next_chr != NULL) {
|
||||
return next_chr->chr.def_handle - 1;
|
||||
} else {
|
||||
return svc->svc.end_handle;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
chr_is_empty(const struct btshell_svc *svc, const struct btshell_chr *chr)
|
||||
{
|
||||
return chr_end_handle(svc, chr) <= chr->chr.val_handle;
|
||||
}
|
||||
|
||||
void
|
||||
print_conn_desc(const struct ble_gap_conn_desc *desc)
|
||||
{
|
||||
console_printf("handle=%d our_ota_addr_type=%d our_ota_addr=",
|
||||
desc->conn_handle, desc->our_ota_addr.type);
|
||||
print_addr(desc->our_ota_addr.val);
|
||||
console_printf(" our_id_addr_type=%d our_id_addr=",
|
||||
desc->our_id_addr.type);
|
||||
print_addr(desc->our_id_addr.val);
|
||||
console_printf(" peer_ota_addr_type=%d peer_ota_addr=",
|
||||
desc->peer_ota_addr.type);
|
||||
print_addr(desc->peer_ota_addr.val);
|
||||
console_printf(" peer_id_addr_type=%d peer_id_addr=",
|
||||
desc->peer_id_addr.type);
|
||||
print_addr(desc->peer_id_addr.val);
|
||||
console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d"
|
||||
" key_size=%d encrypted=%d authenticated=%d bonded=%d\n",
|
||||
desc->conn_itvl, desc->conn_latency,
|
||||
desc->supervision_timeout,
|
||||
desc->sec_state.key_size,
|
||||
desc->sec_state.encrypted,
|
||||
desc->sec_state.authenticated,
|
||||
desc->sec_state.bonded);
|
||||
}
|
||||
|
||||
static void
|
||||
print_dsc(struct btshell_dsc *dsc)
|
||||
{
|
||||
console_printf(" dsc_handle=%d uuid=", dsc->dsc.handle);
|
||||
print_uuid(&dsc->dsc.uuid.u);
|
||||
console_printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_chr(struct btshell_chr *chr)
|
||||
{
|
||||
struct btshell_dsc *dsc;
|
||||
|
||||
console_printf(" def_handle=%d val_handle=%d properties=0x%02x "
|
||||
"uuid=", chr->chr.def_handle, chr->chr.val_handle,
|
||||
chr->chr.properties);
|
||||
print_uuid(&chr->chr.uuid.u);
|
||||
console_printf("\n");
|
||||
|
||||
SLIST_FOREACH(dsc, &chr->dscs, next) {
|
||||
print_dsc(dsc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_svc(struct btshell_svc *svc)
|
||||
{
|
||||
struct btshell_chr *chr;
|
||||
|
||||
console_printf(" start=%d end=%d uuid=", svc->svc.start_handle,
|
||||
svc->svc.end_handle);
|
||||
print_uuid(&svc->svc.uuid.u);
|
||||
console_printf("\n");
|
||||
|
||||
SLIST_FOREACH(chr, &svc->chrs, next) {
|
||||
print_chr(chr);
|
||||
}
|
||||
}
|
||||
112
packages/third-party/nimble/apps/btshell/src/parse.c
vendored
Normal file
112
packages/third-party/nimble/apps/btshell/src/parse.c
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_eddystone.h"
|
||||
#include "cmd.h"
|
||||
|
||||
int
|
||||
parse_eddystone_url(char *full_url, uint8_t *out_scheme, char *out_body,
|
||||
uint8_t *out_body_len, uint8_t *out_suffix)
|
||||
{
|
||||
static const struct {
|
||||
char *s;
|
||||
uint8_t scheme;
|
||||
} schemes[] = {
|
||||
{ "http://www.", BLE_EDDYSTONE_URL_SCHEME_HTTP_WWW },
|
||||
{ "https://www.", BLE_EDDYSTONE_URL_SCHEME_HTTPS_WWW },
|
||||
{ "http://", BLE_EDDYSTONE_URL_SCHEME_HTTP },
|
||||
{ "https://", BLE_EDDYSTONE_URL_SCHEME_HTTPS },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
char *s;
|
||||
uint8_t code;
|
||||
} suffixes[] = {
|
||||
{ ".com/", BLE_EDDYSTONE_URL_SUFFIX_COM_SLASH },
|
||||
{ ".org/", BLE_EDDYSTONE_URL_SUFFIX_ORG_SLASH },
|
||||
{ ".edu/", BLE_EDDYSTONE_URL_SUFFIX_EDU_SLASH },
|
||||
{ ".net/", BLE_EDDYSTONE_URL_SUFFIX_NET_SLASH },
|
||||
{ ".info/", BLE_EDDYSTONE_URL_SUFFIX_INFO_SLASH },
|
||||
{ ".biz/", BLE_EDDYSTONE_URL_SUFFIX_BIZ_SLASH },
|
||||
{ ".gov/", BLE_EDDYSTONE_URL_SUFFIX_GOV_SLASH },
|
||||
{ ".com", BLE_EDDYSTONE_URL_SUFFIX_COM },
|
||||
{ ".org", BLE_EDDYSTONE_URL_SUFFIX_ORG },
|
||||
{ ".edu", BLE_EDDYSTONE_URL_SUFFIX_EDU },
|
||||
{ ".net", BLE_EDDYSTONE_URL_SUFFIX_NET },
|
||||
{ ".info", BLE_EDDYSTONE_URL_SUFFIX_INFO },
|
||||
{ ".biz", BLE_EDDYSTONE_URL_SUFFIX_BIZ },
|
||||
{ ".gov", BLE_EDDYSTONE_URL_SUFFIX_GOV },
|
||||
};
|
||||
|
||||
char *prefix;
|
||||
char *suffix;
|
||||
int full_url_len;
|
||||
int prefix_len;
|
||||
int suffix_len;
|
||||
int suffix_idx;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
full_url_len = strlen(full_url);
|
||||
|
||||
rc = BLE_HS_EINVAL;
|
||||
for (i = 0; i < sizeof schemes / sizeof schemes[0]; i++) {
|
||||
prefix = schemes[i].s;
|
||||
prefix_len = strlen(schemes[i].s);
|
||||
|
||||
if (full_url_len >= prefix_len &&
|
||||
memcmp(full_url, prefix, prefix_len) == 0) {
|
||||
|
||||
*out_scheme = i;
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = BLE_HS_EINVAL;
|
||||
for (i = 0; i < sizeof suffixes / sizeof suffixes[0]; i++) {
|
||||
suffix = suffixes[i].s;
|
||||
suffix_len = strlen(suffixes[i].s);
|
||||
|
||||
suffix_idx = full_url_len - suffix_len;
|
||||
if (suffix_idx >= prefix_len &&
|
||||
memcmp(full_url + suffix_idx, suffix, suffix_len) == 0) {
|
||||
|
||||
*out_suffix = i;
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rc != 0) {
|
||||
*out_suffix = BLE_EDDYSTONE_URL_SUFFIX_NONE;
|
||||
*out_body_len = full_url_len - prefix_len;
|
||||
} else {
|
||||
*out_body_len = full_url_len - prefix_len - suffix_len;
|
||||
}
|
||||
|
||||
memcpy(out_body, full_url + prefix_len, *out_body_len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
packages/third-party/nimble/apps/btshell/syscfg.yml
vendored
Normal file
55
packages/third-party/nimble/apps/btshell/syscfg.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
syscfg.defs:
|
||||
BTSHELL_ANS:
|
||||
description: Include support for the alert notification service.
|
||||
value: 1
|
||||
|
||||
syscfg.vals:
|
||||
CONSOLE_IMPLEMENTATION: full
|
||||
LOG_IMPLEMENTATION: full
|
||||
STATS_IMPLEMENTATION: full
|
||||
|
||||
# Enable the shell task.
|
||||
SHELL_TASK: 1
|
||||
|
||||
# Set log level to info (disable debug logging).
|
||||
LOG_LEVEL: 1
|
||||
|
||||
# Disable security manager (pairing and bonding).
|
||||
BLE_SM_LEGACY: 0
|
||||
BLE_SM_SC: 0
|
||||
|
||||
# Default task settings
|
||||
OS_MAIN_STACK_SIZE: 512
|
||||
|
||||
# SMP is not supported in this app, so disable smp-over-shell.
|
||||
SHELL_MGMT: 0
|
||||
|
||||
# Whether to save data to sys/config, or just keep it in RAM.
|
||||
BLE_STORE_CONFIG_PERSIST: 0
|
||||
|
||||
# L2CAP COC SDU buffers in RX endpoint
|
||||
BLE_L2CAP_COC_SDU_BUFF_COUNT: 1
|
||||
|
||||
syscfg.vals.BLE_MESH:
|
||||
MSYS_1_BLOCK_COUNT: 16
|
||||
|
||||
syscfg.vals.BLE_AUDIO_BROADCAST_SINK:
|
||||
BLE_AUDIO_BROADCAST_SINK_MAX: 1
|
||||
Reference in New Issue
Block a user