/** * Stop advertising state machine * * Context: Link Layer task. * * @param advsm */ static void ble_ll_adv_sm_stop(struct ble_ll_adv_sm *advsm) { os_sr_t sr; if (advsm->enabled) { /* Remove any scheduled advertising items */ ble_ll_sched_rmv_elem(&advsm->adv_sch); /* Set to standby if we are no longer advertising */ OS_ENTER_CRITICAL(sr); if (ble_ll_state_get() == BLE_LL_STATE_ADV) { ble_phy_disable(); ble_ll_wfr_disable(); ble_ll_state_set(BLE_LL_STATE_STANDBY); } OS_EXIT_CRITICAL(sr); os_eventq_remove(&g_ble_ll_data.ll_evq, &advsm->adv_txdone_ev); /* If there is an event buf we need to free it */ if (advsm->conn_comp_ev) { ble_hci_trans_buf_free(advsm->conn_comp_ev); advsm->conn_comp_ev = NULL; } /* Disable advertising */ advsm->enabled = 0; } }
/** * Called to reset the controller. This performs a "software reset" of the link * layer; it does not perform a HW reset of the controller nor does it reset * the HCI interface. * * Context: Link Layer task (HCI command) * * @return int The ble error code to place in the command complete event that * is returned when this command is issued. */ int ble_ll_reset(void) { int rc; os_sr_t sr; /* Stop the phy */ ble_phy_disable(); /* Stop any wait for response timer */ OS_ENTER_CRITICAL(sr); ble_ll_wfr_disable(); ble_ll_sched_stop(); OS_EXIT_CRITICAL(sr); /* Stop any scanning */ ble_ll_scan_reset(); /* Stop any advertising */ ble_ll_adv_reset(); /* FLush all packets from Link layer queues */ ble_ll_flush_pkt_queue(&g_ble_ll_data.ll_tx_pkt_q); ble_ll_flush_pkt_queue(&g_ble_ll_data.ll_rx_pkt_q); /* Reset LL stats */ memset((uint8_t *)&ble_ll_stats + sizeof(struct stats_hdr), 0, sizeof(struct stats_ble_ll_stats) - sizeof(struct stats_hdr)); #ifdef BLE_LL_LOG g_ble_ll_log_index = 0; memset(&g_ble_ll_log, 0, sizeof(g_ble_ll_log)); #endif /* Reset connection module */ ble_ll_conn_module_reset(); /* All this does is re-initialize the event masks so call the hci init */ ble_ll_hci_init(); /* Set state to standby */ ble_ll_state_set(BLE_LL_STATE_STANDBY); /* Reset our random address */ memset(g_random_addr, 0, BLE_DEV_ADDR_LEN); /* Clear the whitelist */ ble_ll_whitelist_clear(); /* Reset resolving list */ #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1) ble_ll_resolv_list_reset(); #endif /* Re-initialize the PHY */ rc = ble_phy_init(); return rc; }
/** * Stop advertising state machine * * Context: Link Layer task. * * @param advsm */ static void ble_ll_adv_sm_stop(struct ble_ll_adv_sm *advsm) { os_sr_t sr; if (advsm->enabled) { /* Remove any scheduled advertising items */ ble_ll_sched_rmv_elem(&advsm->adv_sch); os_eventq_remove(&g_ble_ll_data.ll_evq, &advsm->adv_txdone_ev); /* Set to standby if we are no longer advertising */ OS_ENTER_CRITICAL(sr); if (ble_ll_state_get() == BLE_LL_STATE_ADV) { ble_ll_wfr_disable(); ble_ll_state_set(BLE_LL_STATE_STANDBY); } OS_EXIT_CRITICAL(sr); /* Disable advertising */ advsm->enabled = 0; } }