Update to nimble 1.3.0 + WIP : debug BLE connection issue with android phones.

This commit is contained in:
JF 2020-06-16 20:36:24 +02:00
parent fab220d0b9
commit 9898fed806
31 changed files with 768 additions and 1043 deletions

View file

@ -132,6 +132,7 @@ set(NIMBLE_SRC
libs/mynewt-nimble/nimble/host/src/ble_hs_stop.c libs/mynewt-nimble/nimble/host/src/ble_hs_stop.c
libs/mynewt-nimble/nimble/host/src/ble_hs_startup.c libs/mynewt-nimble/nimble/host/src/ble_hs_startup.c
libs/mynewt-nimble/nimble/host/store/ram/src/ble_store_ram.c libs/mynewt-nimble/nimble/host/store/ram/src/ble_store_ram.c
libs/mynewt-nimble/nimble/host/src/ble_monitor.c
libs/mynewt-nimble/nimble/transport/ram/src/ble_hci_ram.c libs/mynewt-nimble/nimble/transport/ram/src/ble_hci_ram.c
libs/mynewt-nimble/nimble/controller/src/ble_ll.c libs/mynewt-nimble/nimble/controller/src/ble_ll.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_rand.c libs/mynewt-nimble/nimble/controller/src/ble_ll_rand.c

View file

@ -17,8 +17,12 @@ int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct
} }
void AlertNotificationService::Init() { void AlertNotificationService::Init() {
ble_gatts_count_cfg(serviceDefinition); int res;
ble_gatts_add_svcs(serviceDefinition); res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
res = ble_gatts_add_svcs(serviceDefinition);
ASSERT(res == 0);
} }
AlertNotificationService::AlertNotificationService ( Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NotificationManager& notificationManager ) : m_systemTask{systemTask}, m_notificationManager{notificationManager}, AlertNotificationService::AlertNotificationService ( Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NotificationManager& notificationManager ) : m_systemTask{systemTask}, m_notificationManager{notificationManager},

View file

@ -13,8 +13,12 @@ int CTSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_acce
} }
void CurrentTimeService::Init() { void CurrentTimeService::Init() {
ble_gatts_count_cfg(serviceDefinition); int res;
ble_gatts_add_svcs(serviceDefinition); res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
res = ble_gatts_add_svcs(serviceDefinition);
ASSERT(res == 0);
} }

View file

@ -15,8 +15,12 @@ int DeviceInformationCallback(uint16_t conn_handle, uint16_t attr_handle, struct
} }
void DeviceInformationService::Init() { void DeviceInformationService::Init() {
ble_gatts_count_cfg(serviceDefinition); int res = 0;
ble_gatts_add_svcs(serviceDefinition); res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
res = ble_gatts_add_svcs(serviceDefinition);
ASSERT(res == 0);
} }

View file

@ -74,8 +74,12 @@ DfuService::DfuService(Pinetime::System::SystemTask &systemTask, Pinetime::Contr
} }
void DfuService::Init() { void DfuService::Init() {
ble_gatts_count_cfg(serviceDefinition); int res;
ble_gatts_add_svcs(serviceDefinition); res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
res = ble_gatts_add_svcs(serviceDefinition);
ASSERT(res == 0);
} }
int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context) { int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context) {

View file

@ -180,8 +180,8 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) {
StartAdvertising(); StartAdvertising();
bleController.Disconnect(); bleController.Disconnect();
} else { } else {
bleController.Connect(); //bleController.Connect();
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleConnected); //systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleConnected);
connectionHandle = event->connect.conn_handle; connectionHandle = event->connect.conn_handle;
// Service discovery is deffered via systemtask // Service discovery is deffered via systemtask
} }

View file

@ -48,8 +48,8 @@ void SystemTask::Process(void *instance) {
} }
void SystemTask::Work() { void SystemTask::Work() {
watchdog.Setup(7); //watchdog.Setup(7);
watchdog.Start(); //watchdog.Start();
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
APP_GPIOTE_INIT(2); APP_GPIOTE_INIT(2);

View file

@ -1,4 +1,4 @@
#include <sdk/modules/nrfx/mdk/nrf.h> #include <mdk/nrf.h>
#include "InternalFlash.h" #include "InternalFlash.h"
using namespace Pinetime::Drivers; using namespace Pinetime::Drivers;

View file

@ -2691,25 +2691,12 @@ cmd_security_unpair(int argc, char **argv)
{ {
ble_addr_t peer; ble_addr_t peer;
int rc; int rc;
int oldest;
rc = parse_arg_all(argc - 1, argv + 1); rc = parse_arg_all(argc - 1, argv + 1);
if (rc != 0) { if (rc != 0) {
return rc; return rc;
} }
rc = parse_arg_bool_dflt("oldest", 0, &oldest);
if (rc != 0) {
console_printf("invalid 'oldest' parameter\n");
return rc;
}
if (oldest) {
rc = ble_gap_unpair_oldest_peer();
console_printf("Unpair oldest status: 0x%02x\n", rc);
return 0;
}
rc = parse_dev_addr("peer_", cmd_peer_addr_types, &peer); rc = parse_dev_addr("peer_", cmd_peer_addr_types, &peer);
if (rc != 0) { if (rc != 0) {
console_printf("invalid 'peer_addr' parameter\n"); console_printf("invalid 'peer_addr' parameter\n");
@ -2727,7 +2714,6 @@ cmd_security_unpair(int argc, char **argv)
#if MYNEWT_VAL(SHELL_CMD_HELP) #if MYNEWT_VAL(SHELL_CMD_HELP)
static const struct shell_param security_unpair_params[] = { static const struct shell_param security_unpair_params[] = {
{"oldest", "usage: =[true|false], default: false"},
{"peer_addr_type", "usage: =[public|random|public_id|random_id], default: public"}, {"peer_addr_type", "usage: =[public|random|public_id|random_id], default: public"},
{"peer_addr", "usage: =[XX:XX:XX:XX:XX:XX]"}, {"peer_addr", "usage: =[XX:XX:XX:XX:XX:XX]"},
{NULL, NULL} {NULL, NULL}

View file

@ -546,9 +546,6 @@ int ble_ll_rand_data_get(uint8_t *buf, uint8_t len);
void ble_ll_rand_prand_get(uint8_t *prand); void ble_ll_rand_prand_get(uint8_t *prand);
int ble_ll_rand_start(void); int ble_ll_rand_start(void);
// TODO added by JF, don't know why I need this?
void ble_ll_task(void *arg);
static inline int static inline int
ble_ll_get_addr_type(uint8_t txrxflag) ble_ll_get_addr_type(uint8_t txrxflag)
{ {

View file

@ -21,6 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <sdk/components/libraries/log/nrf_log.h>
#include "sysinit/sysinit.h" #include "sysinit/sysinit.h"
#include "syscfg/syscfg.h" #include "syscfg/syscfg.h"
#include "os/os.h" #include "os/os.h"

View file

@ -131,7 +131,6 @@ struct ble_ll_adv_sm
uint8_t aux_index : 1; uint8_t aux_index : 1;
uint8_t aux_first_pdu : 1; uint8_t aux_first_pdu : 1;
uint8_t aux_not_scanned : 1; uint8_t aux_not_scanned : 1;
uint8_t aux_dropped : 1;
struct ble_mbuf_hdr *rx_ble_hdr; struct ble_mbuf_hdr *rx_ble_hdr;
struct os_mbuf **aux_data; struct os_mbuf **aux_data;
struct ble_ll_adv_aux aux[2]; struct ble_ll_adv_aux aux[2];
@ -1270,7 +1269,7 @@ ble_ll_adv_secondary_tx_start_cb(struct ble_ll_sched_item *sch)
rc = ble_phy_tx_set_start_time(txstart, sch->remainder); rc = ble_phy_tx_set_start_time(txstart, sch->remainder);
if (rc) { if (rc) {
STATS_INC(ble_ll_stats, adv_late_starts); STATS_INC(ble_ll_stats, adv_late_starts);
goto adv_aux_dropped; goto adv_tx_done;
} }
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
@ -1305,7 +1304,7 @@ ble_ll_adv_secondary_tx_start_cb(struct ble_ll_sched_item *sch)
/* Transmit advertisement */ /* Transmit advertisement */
rc = ble_phy_tx(pducb, advsm, end_trans); rc = ble_phy_tx(pducb, advsm, end_trans);
if (rc) { if (rc) {
goto adv_aux_dropped; goto adv_tx_done;
} }
/* Enable/disable whitelisting based on filter policy */ /* Enable/disable whitelisting based on filter policy */
@ -1323,8 +1322,7 @@ ble_ll_adv_secondary_tx_start_cb(struct ble_ll_sched_item *sch)
return BLE_LL_SCHED_STATE_RUNNING; return BLE_LL_SCHED_STATE_RUNNING;
adv_aux_dropped: adv_tx_done:
advsm->aux_dropped = 1;
ble_ll_adv_tx_done(advsm); ble_ll_adv_tx_done(advsm);
return BLE_LL_SCHED_STATE_DONE; return BLE_LL_SCHED_STATE_DONE;
} }
@ -1556,7 +1554,6 @@ ble_ll_adv_aux_schedule_first(struct ble_ll_adv_sm *advsm)
advsm->aux_index = 0; advsm->aux_index = 0;
advsm->aux_first_pdu = 1; advsm->aux_first_pdu = 1;
advsm->aux_not_scanned = 0; advsm->aux_not_scanned = 0;
advsm->aux_dropped = 0;
aux = AUX_CURRENT(advsm); aux = AUX_CURRENT(advsm);
ble_ll_adv_aux_calculate(advsm, aux, 0); ble_ll_adv_aux_calculate(advsm, aux, 0);
@ -4839,11 +4836,6 @@ ble_ll_adv_sec_done(struct ble_ll_adv_sm *advsm)
/* We don't need RF anymore */ /* We don't need RF anymore */
ble_ll_rfmgmt_release(); ble_ll_rfmgmt_release();
if (advsm->aux_dropped) {
ble_ll_adv_drop_event(advsm);
return;
}
if (advsm->aux_not_scanned) { if (advsm->aux_not_scanned) {
ble_ll_sched_rmv_elem(&aux_next->sch); ble_ll_sched_rmv_elem(&aux_next->sch);
} }

View file

@ -617,7 +617,7 @@ ble_ll_scan_add_scan_rsp_adv(uint8_t *addr, uint8_t txadd,
static int static int
ble_ll_hci_send_legacy_ext_adv_report(uint8_t evtype, ble_ll_hci_send_legacy_ext_adv_report(uint8_t evtype,
const uint8_t *addr, uint8_t addr_type, const uint8_t *addr, uint8_t addr_type,
int8_t rssi, uint8_t rssi,
uint8_t adv_data_len, uint8_t adv_data_len,
struct os_mbuf *adv_data, struct os_mbuf *adv_data,
const uint8_t *inita, uint8_t inita_type) const uint8_t *inita, uint8_t inita_type)
@ -1991,10 +1991,10 @@ ble_ll_scan_rx_filter(struct ble_mbuf_hdr *hdr, struct ble_ll_scan_addr_data *ad
{ {
struct ble_ll_scan_sm *scansm = &g_ble_ll_scan_sm; struct ble_ll_scan_sm *scansm = &g_ble_ll_scan_sm;
struct ble_ll_scan_params *scanp = scansm->scanp; struct ble_ll_scan_params *scanp = scansm->scanp;
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
struct ble_ll_aux_data *aux_data = hdr->rxinfo.user_data; struct ble_ll_aux_data *aux_data = hdr->rxinfo.user_data;
#endif #endif
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
struct ble_mbuf_hdr_rxinfo *rxinfo = &hdr->rxinfo; struct ble_mbuf_hdr_rxinfo *rxinfo = &hdr->rxinfo;
struct ble_ll_resolv_entry *rl = NULL; struct ble_ll_resolv_entry *rl = NULL;
#endif #endif
@ -2227,7 +2227,6 @@ ble_ll_scan_rx_isr_on_aux(uint8_t pdu_type, uint8_t *rxbuf,
*/ */
if (aux_data->flags & BLE_LL_AUX_IS_MATCHED) { if (aux_data->flags & BLE_LL_AUX_IS_MATCHED) {
rxinfo->flags |= BLE_MBUF_HDR_F_DEVMATCH; rxinfo->flags |= BLE_MBUF_HDR_F_DEVMATCH;
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
rxinfo->rpa_index = aux_data->rpa_index; rxinfo->rpa_index = aux_data->rpa_index;
if (rxinfo->rpa_index >= 0) { if (rxinfo->rpa_index >= 0) {
rxinfo->flags |= BLE_MBUF_HDR_F_RESOLVED; rxinfo->flags |= BLE_MBUF_HDR_F_RESOLVED;
@ -2235,7 +2234,6 @@ ble_ll_scan_rx_isr_on_aux(uint8_t pdu_type, uint8_t *rxbuf,
if (aux_data->flags & BLE_LL_AUX_IS_TARGETA_RESOLVED) { if (aux_data->flags & BLE_LL_AUX_IS_TARGETA_RESOLVED) {
rxinfo->flags |= BLE_MBUF_HDR_F_TARGETA_RESOLVED; rxinfo->flags |= BLE_MBUF_HDR_F_TARGETA_RESOLVED;
} }
#endif
goto done; goto done;
} }

View file

@ -20,6 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <sdk/components/libraries/log/nrf_log.h>
#include "syscfg/syscfg.h" #include "syscfg/syscfg.h"
#include "os/os.h" #include "os/os.h"
#include "ble/xcvr.h" #include "ble/xcvr.h"

View file

@ -1896,20 +1896,6 @@ int ble_gap_unpair(const ble_addr_t *peer_addr);
*/ */
int ble_gap_unpair_oldest_peer(void); int ble_gap_unpair_oldest_peer(void);
/**
* Similar to `ble_gap_unpair_oldest_peer()`, except it makes sure that the
* peer received in input parameters is not deleted.
*
* @param peer_addr Address of the peer (not to be deleted)
*
* @return 0 on success;
* A BLE host HCI return code if the controller
* rejected the request;
* A BLE host core return code on unexpected
* error.
*/
int ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr);
#define BLE_GAP_PRIVATE_MODE_NETWORK 0 #define BLE_GAP_PRIVATE_MODE_NETWORK 0
#define BLE_GAP_PRIVATE_MODE_DEVICE 1 #define BLE_GAP_PRIVATE_MODE_DEVICE 1

View file

@ -1020,7 +1020,7 @@ ble_gap_slave_set_timer(uint32_t ticks_from_now)
} }
#endif #endif
#if (NIMBLE_BLE_CONNECT || NIMBLE_BLE_SCAN) #if NIMBLE_BLE_CONNECT
/** /**
* Called when an error is encountered while the master-connection-fsm is * Called when an error is encountered while the master-connection-fsm is
* active. * active.
@ -1034,22 +1034,12 @@ ble_gap_master_failed(int status)
ble_gap_master_connect_failure(status); ble_gap_master_connect_failure(status);
break; break;
#if NIMBLE_BLE_SCAN
case BLE_GAP_OP_M_DISC:
STATS_INC(ble_gap_stats, initiate_fail);
ble_gap_disc_complete();
ble_gap_master_reset_state();
break;
#endif
default: default:
BLE_HS_DBG_ASSERT(0); BLE_HS_DBG_ASSERT(0);
break; break;
} }
} }
#endif
#if NIMBLE_BLE_CONNECT
static void static void
ble_gap_update_failed(uint16_t conn_handle, int status) ble_gap_update_failed(uint16_t conn_handle, int status)
{ {
@ -1247,46 +1237,6 @@ ble_gap_adv_active_instance(uint8_t instance)
return ble_gap_slave[instance].op == BLE_GAP_OP_S_ADV; return ble_gap_slave[instance].op == BLE_GAP_OP_S_ADV;
} }
/**
* Clears advertisement and discovery state. This function is necessary
* when the controller loses its active state (e.g. on stack reset).
*/
void
ble_gap_reset_state(int reason)
{
uint16_t conn_handle;
while (1) {
conn_handle = ble_hs_atomic_first_conn_handle();
if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
break;
}
ble_gap_conn_broken(conn_handle, reason);
}
#if NIMBLE_BLE_ADVERTISE
#if MYNEWT_VAL(BLE_EXT_ADV)
uint8_t i;
for (i = 0; i < BLE_ADV_INSTANCES; i++) {
if (ble_gap_adv_active_instance(i)) {
/* Indicate to application that advertising has stopped. */
ble_gap_adv_finished(i, reason, 0, 0);
}
}
#else
if (ble_gap_adv_active_instance(0)) {
/* Indicate to application that advertising has stopped. */
ble_gap_adv_finished(0, reason, 0, 0);
}
#endif
#endif
#if (NIMBLE_BLE_SCAN || NIMBLE_BLE_CONNECT)
ble_gap_master_failed(reason);
#endif
}
#if NIMBLE_BLE_CONNECT #if NIMBLE_BLE_CONNECT
static int static int
ble_gap_accept_master_conn(void) ble_gap_accept_master_conn(void)
@ -1993,6 +1943,7 @@ ble_gap_update_timer(void)
ble_hs_unlock(); ble_hs_unlock();
if (entry != NULL) { if (entry != NULL) {
ble_gap_update_notify(conn_handle, BLE_HS_ETIMEOUT);
ble_gap_update_entry_free(entry); ble_gap_update_entry_free(entry);
} }
} while (entry != NULL); } while (entry != NULL);
@ -5594,7 +5545,7 @@ ble_gap_unpair_oldest_peer(void)
} }
if (num_peers == 0) { if (num_peers == 0) {
return BLE_HS_ENOENT; return 0;
} }
rc = ble_gap_unpair(&oldest_peer_id_addr); rc = ble_gap_unpair(&oldest_peer_id_addr);
@ -5605,36 +5556,6 @@ ble_gap_unpair_oldest_peer(void)
return 0; return 0;
} }
int
ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr)
{
ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
int num_peers;
int rc, i;
rc = ble_store_util_bonded_peers(
&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
if (rc != 0) {
return rc;
}
if (num_peers == 0) {
return BLE_HS_ENOENT;
}
for (i = 0; i < num_peers; i++) {
if (ble_addr_cmp(peer_addr, &peer_id_addrs[i]) != 0) {
break;
}
}
if (i >= num_peers) {
return BLE_HS_ENOMEM;
}
return ble_gap_unpair(&peer_id_addrs[i]);
}
void void
ble_gap_passkey_event(uint16_t conn_handle, ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params) struct ble_gap_passkey_params *passkey_params)

View file

@ -136,7 +136,6 @@ void ble_gap_preempt(void);
void ble_gap_preempt_done(void); void ble_gap_preempt_done(void);
int ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason); int ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason);
void ble_gap_reset_state(int reason);
void ble_gap_conn_broken(uint16_t conn_handle, int reason); void ble_gap_conn_broken(uint16_t conn_handle, int reason);
int32_t ble_gap_timer(void); int32_t ble_gap_timer(void);

View file

@ -361,6 +361,7 @@ ble_hs_sync(void)
static int static int
ble_hs_reset(void) ble_hs_reset(void)
{ {
uint16_t conn_handle;
int rc; int rc;
STATS_INC(ble_hs_stats, reset); STATS_INC(ble_hs_stats, reset);
@ -375,8 +376,14 @@ ble_hs_reset(void)
ble_hs_clear_rx_queue(); ble_hs_clear_rx_queue();
/* Clear adverising and scanning states. */ while (1) {
ble_gap_reset_state(ble_hs_reset_reason); conn_handle = ble_hs_atomic_first_conn_handle();
if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
break;
}
ble_gap_conn_broken(conn_handle, ble_hs_reset_reason);
}
/* Clear configured addresses. */ /* Clear configured addresses. */
ble_hs_id_reset(); ble_hs_id_reset();

View file

@ -327,7 +327,6 @@ ble_hs_conn_find_by_addr(const ble_addr_t *addr)
#endif #endif
struct ble_hs_conn *conn; struct ble_hs_conn *conn;
struct ble_hs_conn_addrs addrs;
BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task()); BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
@ -344,14 +343,6 @@ ble_hs_conn_find_by_addr(const ble_addr_t *addr)
if (ble_addr_cmp(&conn->bhc_peer_addr, addr) == 0) { if (ble_addr_cmp(&conn->bhc_peer_addr, addr) == 0) {
return conn; return conn;
} }
if (conn->bhc_peer_addr.type < BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT) {
continue;
}
/*If type 0x02 or 0x03 is used, let's double check if address is good */
ble_hs_conn_addrs(conn, &addrs);
if (ble_addr_cmp(&addrs.peer_id_addr, addr) == 0) {
return conn;
}
} }
} }

View file

@ -440,7 +440,6 @@ ble_l2cap_coc_continue_tx(struct ble_l2cap_chan *chan)
BLE_HS_LOG(DEBUG, "Sending SDU len=%d\n", OS_MBUF_PKTLEN(tx->sdu)); BLE_HS_LOG(DEBUG, "Sending SDU len=%d\n", OS_MBUF_PKTLEN(tx->sdu));
rc = os_mbuf_append(txom, &l, sizeof(uint16_t)); rc = os_mbuf_append(txom, &l, sizeof(uint16_t));
if (rc) { if (rc) {
rc = BLE_HS_ENOMEM;
BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc); BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc);
goto failed; goto failed;
} }
@ -453,7 +452,6 @@ ble_l2cap_coc_continue_tx(struct ble_l2cap_chan *chan)
rc = os_mbuf_appendfrom(txom, tx->sdu, tx->data_offset, rc = os_mbuf_appendfrom(txom, tx->sdu, tx->data_offset,
len - sdu_size_offset); len - sdu_size_offset);
if (rc) { if (rc) {
rc = BLE_HS_ENOMEM;
BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc); BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc);
goto failed; goto failed;
} }

View file

@ -17,6 +17,7 @@
* under the License. * under the License.
*/ */
#include <stdio.h>
#include "host/ble_monitor.h" #include "host/ble_monitor.h"
#if BLE_MONITOR #if BLE_MONITOR
@ -28,13 +29,14 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include <libs/mynewt-nimble/porting/nimble/include/os/os_cputime.h>
#include "os/os.h" #include "os/os.h"
#include "log/log.h" #include "log/log.h"
#if MYNEWT_VAL(BLE_MONITOR_UART) #if MYNEWT_VAL(BLE_MONITOR_UART)
#include "uart/uart.h" #include "uart/uart.h"
#endif #endif
#if MYNEWT_VAL(BLE_MONITOR_RTT) #if MYNEWT_VAL(BLE_MONITOR_RTT)
#include "rtt/SEGGER_RTT.h" #include "SEGGER_RTT.h"
#endif #endif
#include "ble_hs_priv.h" #include "ble_hs_priv.h"
#include "ble_monitor_priv.h" #include "ble_monitor_priv.h"
@ -236,7 +238,7 @@ monitor_write_header(uint16_t opcode, uint16_t len)
hdr.flags = 0; hdr.flags = 0;
/* Use uptime for timestamp */ /* Use uptime for timestamp */
ts = os_get_uptime_usec(); ts = os_cputime_ticks_to_usecs(os_cputime_get32());
/* /*
* btsnoop specification states that fields of extended header must be * btsnoop specification states that fields of extended header must be
@ -266,6 +268,17 @@ btmon_write(FILE *instance, const char *bp, size_t n)
return n; return n;
} }
struct File_methods
{
size_t (*write)(FILE* instance, const char *bp, size_t n);
size_t (*read)(FILE* instance, char *bp, size_t n);
};
struct File
{
const struct File_methods *vmt;
};
static FILE *btmon = (FILE *) &(struct File) { static FILE *btmon = (FILE *) &(struct File) {
.vmt = &(struct File_methods) { .vmt = &(struct File_methods) {
.write = btmon_write, .write = btmon_write,
@ -276,7 +289,7 @@ static FILE *btmon = (FILE *) &(struct File) {
static void static void
drops_tmp_cb(struct ble_npl_event *ev) drops_tmp_cb(struct ble_npl_event *ev)
{ {
ble_npl_mutex_pend(&lock, OS_TIMEOUT_NEVER); ble_npl_mutex_pend(&lock, portMAX_DELAY);
/* /*
* There's no "nop" in btsnoop protocol so we just send empty system note * There's no "nop" in btsnoop protocol so we just send empty system note
@ -345,7 +358,7 @@ ble_monitor_init(void)
int int
ble_monitor_send(uint16_t opcode, const void *data, size_t len) ble_monitor_send(uint16_t opcode, const void *data, size_t len)
{ {
ble_npl_mutex_pend(&lock, OS_TIMEOUT_NEVER); ble_npl_mutex_pend(&lock, portMAX_DELAY);
monitor_write_header(opcode, len); monitor_write_header(opcode, len);
monitor_write(data, len); monitor_write(data, len);
@ -367,7 +380,7 @@ ble_monitor_send_om(uint16_t opcode, const struct os_mbuf *om)
om_tmp = SLIST_NEXT(om_tmp, om_next); om_tmp = SLIST_NEXT(om_tmp, om_next);
} }
ble_npl_mutex_pend(&lock, OS_TIMEOUT_NEVER); ble_npl_mutex_pend(&lock, portMAX_DELAY);
monitor_write_header(opcode, length); monitor_write_header(opcode, length);
@ -429,7 +442,7 @@ ble_monitor_log(int level, const char *fmt, ...)
ulog.ident_len = sizeof(id); ulog.ident_len = sizeof(id);
ble_npl_mutex_pend(&lock, OS_TIMEOUT_NEVER); ble_npl_mutex_pend(&lock, portMAX_DELAY);
monitor_write_header(BLE_MONITOR_OPCODE_USER_LOGGING, monitor_write_header(BLE_MONITOR_OPCODE_USER_LOGGING,
sizeof(ulog) + sizeof(id) + len + 1); sizeof(ulog) + sizeof(id) + len + 1);

View file

@ -68,6 +68,8 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
swap_buf(tmp, plaintext, 16); swap_buf(tmp, plaintext, 16);
if (tc_aes_encrypt(enc_data, tmp, &s) == TC_CRYPTO_FAIL) { if (tc_aes_encrypt(enc_data, tmp, &s) == TC_CRYPTO_FAIL) {
return BLE_HS_EUNKNOWN; return BLE_HS_EUNKNOWN;
} }

View file

@ -235,10 +235,8 @@ ble_store_util_status_rr(struct ble_store_status_event *event, void *arg)
switch (event->overflow.obj_type) { switch (event->overflow.obj_type) {
case BLE_STORE_OBJ_TYPE_OUR_SEC: case BLE_STORE_OBJ_TYPE_OUR_SEC:
case BLE_STORE_OBJ_TYPE_PEER_SEC: case BLE_STORE_OBJ_TYPE_PEER_SEC:
return ble_gap_unpair_oldest_peer();
case BLE_STORE_OBJ_TYPE_CCCD: case BLE_STORE_OBJ_TYPE_CCCD:
/* Try unpairing oldest peer except current peer */ return ble_gap_unpair_oldest_peer();
return ble_gap_unpair_oldest_except(&event->overflow.value->cccd.peer_addr);
default: default:
return BLE_HS_EUNKNOWN; return BLE_HS_EUNKNOWN;

View file

@ -2049,6 +2049,70 @@ ble_gap_test_util_update_l2cap(struct ble_gap_upd_params *params,
peer_addr, 6) == 0); peer_addr, 6) == 0);
} }
static void
ble_gap_test_util_update_no_l2cap_tmo(struct ble_gap_upd_params *params,
int master)
{
struct ble_hs_conn *conn;
int rc;
uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
ble_gap_test_util_init();
ble_hs_test_util_create_conn(2, peer_addr, ble_gap_test_util_connect_cb,
NULL);
if (!master) {
ble_hs_lock();
conn = ble_hs_conn_find(2);
TEST_ASSERT_FATAL(conn != NULL);
conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
ble_hs_unlock();
}
/* Erase callback info reported during connection establishment; we only
* care about updates.
*/
ble_gap_test_util_reset_cb_info();
TEST_ASSERT(!ble_gap_master_in_progress());
rc = ble_hs_test_util_conn_update(2, params, 0);
TEST_ASSERT(rc == 0);
TEST_ASSERT(!ble_gap_master_in_progress());
/* Verify tx of connection update command. */
ble_gap_test_util_verify_tx_update_conn(params);
/* Ensure no update event reported. */
TEST_ASSERT(ble_gap_test_event.type == 0xff);
/* Advance 39 seconds; ensure no timeout reported. */
os_time_advance(39 * OS_TICKS_PER_SEC);
ble_gap_timer();
TEST_ASSERT(ble_gap_test_event.type == 0xff);
/* Advance 40th second; ensure timeout reported. */
os_time_advance(1 * OS_TICKS_PER_SEC);
/* Timeout will result in a terminate HCI command being sent; schedule ack
* from controller.
*/
ble_hs_test_util_hci_ack_set_disconnect(0);
ble_gap_timer();
/* Verify terminate was sent. */
ble_gap_test_util_verify_tx_disconnect();
TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_ETIMEOUT);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr.val,
peer_addr, 6) == 0);
}
static void static void
ble_gap_test_util_update_l2cap_tmo(struct ble_gap_upd_params *params, ble_gap_test_util_update_l2cap_tmo(struct ble_gap_upd_params *params,
uint8_t hci_status, uint8_t event_status, uint8_t hci_status, uint8_t event_status,
@ -2918,6 +2982,9 @@ TEST_CASE_SELF(ble_gap_test_case_update_timeout)
.max_ce_len = 456, .max_ce_len = 456,
}; };
/* No L2CAP. */
ble_gap_test_util_update_no_l2cap_tmo(&params, 1);
/* L2CAP - Local unsupported; L2CAP timeout. */ /* L2CAP - Local unsupported; L2CAP timeout. */
ble_gap_test_util_update_l2cap_tmo(&params, BLE_ERR_UNKNOWN_HCI_CMD, 0, 0); ble_gap_test_util_update_l2cap_tmo(&params, BLE_ERR_UNKNOWN_HCI_CMD, 0, 0);

View file

@ -540,7 +540,7 @@ ble_hci_sock_config(void)
rc = bind(s, (struct sockaddr *)&shci, sizeof(shci)); rc = bind(s, (struct sockaddr *)&shci, sizeof(shci));
if (rc) { if (rc) {
dprintf(1, "bind() failed %d hci%d\n", errno, shci.hci_dev); dprintf(1, "bind() failed %d\n", errno);
goto err; goto err;
} }

File diff suppressed because it is too large Load diff

View file

@ -20,6 +20,7 @@
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <sdk/components/libraries/log/nrf_log.h>
#include "nimble/nimble_npl.h" #include "nimble/nimble_npl.h"
static inline bool static inline bool

View file

@ -201,6 +201,7 @@ void nimble_port_init(void) {
} }
void nimble_port_ll_task_func(void *args) { void nimble_port_ll_task_func(void *args) {
extern void ble_ll_task(void *);
ble_ll_task(args); ble_ll_task(args);
} }
} }

View file

@ -8460,15 +8460,15 @@
// <e> NRF_LOG_ENABLED - nrf_log - Logger // <e> NRF_LOG_ENABLED - nrf_log - Logger
//========================================================== //==========================================================
#ifndef NRF_LOG_ENABLED #ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 0 #define NRF_LOG_ENABLED 1
#endif #endif
#ifndef NRF_LOG_BACKEND_RTT_ENABLED #ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 0 #define NRF_LOG_BACKEND_RTT_ENABLED 1
#endif #endif
#ifndef NRF_LOG_BACKEND_SERIAL_USES_RTT #ifndef NRF_LOG_BACKEND_SERIAL_USES_RTT
#define NRF_LOG_BACKEND_SERIAL_USES_RTT 0 #define NRF_LOG_BACKEND_SERIAL_USES_RTT 1
#endif #endif
// <h> Log message pool - Configuration of log message pool // <h> Log message pool - Configuration of log message pool
@ -12817,7 +12817,7 @@
// <o> SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS - Maximum number of upstream buffers. // <o> SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS - Maximum number of upstream buffers.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS #ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 2 #define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 4
#endif #endif
// <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN - Size of downstream buffer. // <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN - Size of downstream buffer.