static struct health_channel *create_channel(struct health_app *app, uint8_t mdep_index, struct health_device *dev) { struct mdep_cfg *mdep; struct health_channel *channel; static unsigned int channel_id = 1; DBG("mdep %u", mdep_index); if (!dev || !app) return NULL; mdep = queue_find(app->mdeps, match_mdep_by_id, INT_TO_PTR(mdep_index)); if (!mdep) { if (mdep_index == MDEP_ECHO) { mdep = new0(struct mdep_cfg, 1); if (!mdep) return NULL; /* Leave other configuration zeroes */ mdep->id = MDEP_ECHO; if (!queue_push_tail(app->mdeps, mdep)) { free_mdep_cfg(mdep); return NULL; } } else return NULL;
static void bt_health_mdep_cfg_data(const void *buf, uint16_t len) { const struct hal_cmd_health_mdep *cmd = buf; struct health_app *app; struct mdep_cfg *mdep = NULL; uint8_t status; DBG(""); app = queue_find(apps, match_app_by_id, INT_TO_PTR(cmd->app_id)); if (!app) { status = HAL_STATUS_INVALID; goto fail; } mdep = new0(struct mdep_cfg, 1); mdep->role = cmd->role; mdep->data_type = cmd->data_type; mdep->channel_type = android2channel_type(cmd->channel_type); mdep->id = queue_length(app->mdeps) + 1; if (cmd->descr_len > 0) { mdep->descr = malloc0(cmd->descr_len); memcpy(mdep->descr, cmd->descr, cmd->descr_len); } queue_push_tail(app->mdeps, mdep); if (app->num_of_mdep != queue_length(app->mdeps)) goto send_rsp; /* add sdp record from app configuration data */ /* * TODO: Check what to be done if mupltple applications are trying to * register with different role and different configurations. * 1) Does device supports SOURCE and SINK at the same time ? * 2) Does it require different SDP records or one record with * multile MDEP configurations ? */ if (update_sdp_record(app) < 0) { error("health: HDP SDP record preparation failed"); status = HAL_STATUS_FAILED; goto fail; } send_app_reg_notify(app, HAL_HEALTH_APP_REG_SUCCESS); send_rsp: ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH, HAL_OP_HEALTH_MDEP, HAL_STATUS_SUCCESS); return; fail: if (status != HAL_STATUS_SUCCESS) { free_mdep_cfg(mdep); queue_remove(apps, app); free_health_app(app); } ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH, HAL_OP_HEALTH_MDEP, status); }