Esempio n. 1
0
static void _ble_register_services(void)
{
	/* GAP_SVC */
	ble_gap_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "GAP");

	/* DIS_SVC */
	ble_dis_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "DIS");

	/* BAS_SVC */
	ble_bas_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "BAS");

#ifdef CONFIG_BLE_HRS_LIB
	/* HRM_SVC */
	ble_hrs_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "HRM");
#endif

#ifdef CONFIG_BLE_LNS_LIB
	/* LNS_SVC */
	ble_lns_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "LNS");
#endif

#ifdef CONFIG_BLE_RSCS_LIB
	/* RSC_SVC */
	ble_rscs_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "RSC");
#endif

#if defined(CONFIG_PACKAGE_ISPP)
	/* ISPP_SVC */
	ble_ispp_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "ISPP");
#endif
#if defined(CONFIG_UAS)
	ble_uas_init();
	pr_info(LOG_MODULE_BLE, "Registering %s", "UAS");
#endif

	on_ble_app_started();
}
Esempio n. 2
0
/**
 * Initializes the host portion of the BLE stack.
 */
int
ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
{
    int rc;

    ble_hs_free_mem();

    if (app_evq == NULL) {
        rc = BLE_HS_EINVAL;
        goto err;
    }
    ble_hs_parent_evq = app_evq;

    ble_hs_cfg_init(cfg);

    log_init();
    log_console_handler_init(&ble_hs_log_console_handler);
    log_register("ble_hs", &ble_hs_log, &ble_hs_log_console_handler);

    ble_hs_hci_cmd_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs,
                                                 HCI_CMD_BUF_SIZE));
    if (ble_hs_hci_cmd_buf == NULL) {
        rc = BLE_HS_ENOMEM;
        goto err;
    }

    /* Create memory pool of command buffers */
    rc = os_mempool_init(&g_hci_cmd_pool, ble_hs_cfg.max_hci_bufs,
                         HCI_CMD_BUF_SIZE, ble_hs_hci_cmd_buf,
                         "HCICmdPool");
    assert(rc == 0);

    ble_hs_hci_os_event_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs,
                                                      HCI_OS_EVENT_BUF_SIZE));
    if (ble_hs_hci_os_event_buf == NULL) {
        rc = BLE_HS_ENOMEM;
        goto err;
    }

    /* Create memory pool of OS events */
    rc = os_mempool_init(&g_hci_os_event_pool, ble_hs_cfg.max_hci_bufs,
                         HCI_OS_EVENT_BUF_SIZE, ble_hs_hci_os_event_buf,
                         "HCIOsEventPool");
    assert(rc == 0);

    /* Initialize eventq */
    os_eventq_init(&ble_hs_evq);

    /* Initialize stats. */
    rc = stats_module_init();
    if (rc != 0) {
        rc = BLE_HS_EOS;
        goto err;
    }

    ble_hci_cmd_init();

    rc = ble_hs_conn_init();
    if (rc != 0) {
        goto err;
    }

    rc = ble_l2cap_init();
    if (rc != 0) {
        goto err;
    }

    rc = ble_att_init();
    if (rc != 0) {
        goto err;
    }

    rc = ble_att_svr_init();
    if (rc != 0) {
        goto err;
    }

    rc = ble_gap_init();
    if (rc != 0) {
        goto err;
    }

    rc = ble_gattc_init();
    if (rc != 0) {
        goto err;
    }

    rc = ble_gatts_init();
    if (rc != 0) {
        goto err;
    }

    os_mqueue_init(&ble_hs_rx_q, NULL);
    os_mqueue_init(&ble_hs_tx_q, NULL);

    rc = stats_init_and_reg(
        STATS_HDR(ble_hs_stats), STATS_SIZE_INIT_PARMS(ble_hs_stats,
        STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_hs_stats), "ble_hs");
    if (rc != 0) {
        rc = BLE_HS_EOS;
        goto err;
    }

    os_callout_func_init(&ble_hs_heartbeat_timer, ble_hs_parent_evq,
                         ble_hs_heartbeat, NULL);
    os_callout_func_init(&ble_hs_event_co, &ble_hs_evq,
                         ble_hs_event_handle, NULL);

    rc = os_mutex_init(&ble_hs_mutex);
    if (rc != 0) {
        rc = BLE_HS_EOS;
        goto err;
    }

    return 0;

err:
    ble_hs_free_mem();
    return rc;
}