Ejemplo n.º 1
0
/**
 * Reset the advertising state machine.
 *
 * Context: Link Layer task
 *
 */
void
ble_ll_adv_reset(void)
{
    struct ble_ll_adv_sm *advsm;
    advsm = &g_ble_ll_adv_sm;

    /* Stop advertising state machine */
    ble_ll_adv_sm_stop(advsm);

    /* re-initialize the advertiser state machine */
    ble_ll_adv_init();
}
/**
 * Reset the advertising state machine.
 *
 * Context: Link Layer task
 *
 */
void
ble_ll_adv_reset(void)
{
    struct ble_ll_adv_sm *advsm;
    advsm = &g_ble_ll_adv_sm;

    /* Stop advertising state machine */
    ble_ll_adv_sm_stop(advsm);

    /* Free scan pdu's */
    os_mbuf_free_chain(advsm->scan_rsp_pdu);

    /* re-initialize the advertiser state machine */
    ble_ll_adv_init();
}
Ejemplo n.º 3
0
/**
 * Initialize the Link Layer. Should be called only once
 *
 * @return int
 */
void
ble_ll_init(void)
{
    int rc;
    uint8_t features;
    struct ble_ll_obj *lldata;

    /* Get pointer to global data object */
    lldata = &g_ble_ll_data;

    /* Set acl pkt size and number */
    lldata->ll_num_acl_pkts = MYNEWT_VAL(BLE_ACL_BUF_COUNT);
    lldata->ll_acl_pkt_size = MYNEWT_VAL(BLE_ACL_BUF_SIZE);

    /* Initialize eventq */
    os_eventq_init(&lldata->ll_evq);

    /* Initialize the transmit (from host) and receive (from phy) queues */
    STAILQ_INIT(&lldata->ll_tx_pkt_q);
    STAILQ_INIT(&lldata->ll_rx_pkt_q);

    /* Initialize transmit (from host) and receive packet (from phy) event */
    lldata->ll_rx_pkt_ev.ev_cb = ble_ll_event_rx_pkt;
    lldata->ll_tx_pkt_ev.ev_cb = ble_ll_event_tx_pkt;
    lldata->ll_dbuf_overflow_ev.ev_cb = ble_ll_event_dbuf_overflow;

    /* Initialize the HW error timer */
    os_callout_init(&g_ble_ll_data.ll_hw_err_timer,
                    &g_ble_ll_data.ll_evq,
                    ble_ll_hw_err_timer_cb,
                    NULL);

    /* Initialize wait for response timer */
    os_cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,
                          NULL);

    ble_ll_hci_os_event_buf = malloc(
                                  OS_MEMPOOL_BYTES(16, sizeof (struct os_event)));
    SYSINIT_PANIC_ASSERT(ble_ll_hci_os_event_buf != NULL);

    /* Create memory pool of OS events */
    rc = os_mempool_init(&g_ble_ll_hci_ev_pool, 16,
                         sizeof (struct os_event), ble_ll_hci_os_event_buf,
                         "g_ble_ll_hci_ev_pool");
    SYSINIT_PANIC_ASSERT(rc == 0);

    /* Initialize LL HCI */
    ble_ll_hci_init();

    /* Init the scheduler */
    ble_ll_sched_init();

    /* Initialize advertiser */
    ble_ll_adv_init();

    /* Initialize a scanner */
    ble_ll_scan_init();

    /* Initialize the connection module */
    ble_ll_conn_module_init();

    /* Set the supported features. NOTE: we always support extended reject. */
    features = BLE_LL_FEAT_EXTENDED_REJ;

#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_DATA_LEN_EXT) == 1)
    features |= BLE_LL_FEAT_DATA_LEN_EXT;
#endif
#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_CONN_PARAM_REQ) == 1)
    features |= BLE_LL_FEAT_CONN_PARM_REQ;
#endif
#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG) == 1)
    features |= BLE_LL_FEAT_SLAVE_INIT;
#endif
#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
    features |= BLE_LL_FEAT_LE_ENCRYPTION;
#endif

#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
    features |= (BLE_LL_FEAT_LL_PRIVACY | BLE_LL_FEAT_EXT_SCAN_FILT);
    ble_ll_resolv_init();
#endif

#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING) == 1)
    features |= BLE_LL_FEAT_LE_PING;
#endif

    /* Initialize random number generation */
    ble_ll_rand_init();

    /* XXX: This really doesn't belong here, as the address probably has not
     * been set yet.
     */
    ble_ll_seed_prng();

    lldata->ll_supp_features = features;

    /* Initialize the LL task */
    os_task_init(&g_ble_ll_task, "ble_ll", ble_ll_task, NULL,
                 MYNEWT_VAL(BLE_LL_PRIO), OS_WAIT_FOREVER, g_ble_ll_stack,
                 BLE_LL_STACK_SIZE);

    rc = stats_init_and_reg(STATS_HDR(ble_ll_stats),
                            STATS_SIZE_INIT_PARMS(ble_ll_stats, STATS_SIZE_32),
                            STATS_NAME_INIT_PARMS(ble_ll_stats),
                            "ble_ll");
    SYSINIT_PANIC_ASSERT(rc == 0);

    ble_hci_trans_cfg_ll(ble_ll_hci_cmd_rx, NULL, ble_ll_hci_acl_rx, NULL);
}