int nmgr_transport_init(struct nmgr_transport *nt, nmgr_transport_out_func_t output_func, nmgr_transport_get_mtu_func_t get_mtu_func) { int rc; nt->nt_output = output_func; nt->nt_get_mtu = get_mtu_func; rc = os_mqueue_init(&nt->nt_imq, nmgr_event_data_in, nt); if (rc != 0) { goto err; } return (0); err: return (rc); }
/** * Nmgr ble GATT server initialization * * @param eventq * @return 0 on success; non-zero on failure */ int nmgr_ble_gatt_svr_init(void) { int rc; rc = ble_gatts_count_cfg(gatt_svr_svcs); if (rc != 0) { goto err; } rc = ble_gatts_add_svcs(gatt_svr_svcs); if (rc != 0) { return rc; } os_mqueue_init(&nmgr_ble_mq, &nmgr_ble_event_data_in, NULL); rc = nmgr_transport_init(&ble_nt, nmgr_ble_out, nmgr_ble_get_mtu); err: return rc; }
/** * 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; }