/* Handles message for test command */ static void ui_svc_tcmd_handle_message(struct cfw_message *msg, void *param) { int ui_status; ui_srv_data_t *priv = CFW_MESSAGE_PRIV(msg); struct tcmd_handler_ctx *ctx = priv->context; char *message = balloc(BUFFER_LENGTH, NULL); switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_UI_LED_RSP: case MSG_ID_UI_VIBR_RSP: ui_status = ((struct cfw_rsp_message *)msg)->status; if (ui_status == DRV_RC_OK) { TCMD_RSP_FINAL(ctx, NULL); } else { snprintf(message, BUFFER_LENGTH, "KO (status: %d)", ui_status); TCMD_RSP_ERROR(ctx, message); } break; default: /* default cfw handler */ snprintf(message, BUFFER_LENGTH, "Wrong ui_svc rsp (id: 0x%X)", CFW_MESSAGE_ID(msg)); TCMD_RSP_ERROR(ctx, message); break; } cproxy_disconnect(priv->ui_service_conn); cfw_msg_free(msg); bfree(priv); bfree(message); }
static void handle_message(struct cfw_message *msg, void *param) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CIRCULAR_STORAGE_PUSH_REQ: handle_push(msg); break; case MSG_ID_CIRCULAR_STORAGE_POP_REQ: handle_pop(msg); break; case MSG_ID_CIRCULAR_STORAGE_PEEK_REQ: handle_peek(msg); break; case MSG_ID_CIRCULAR_STORAGE_CLEAR_REQ: handle_clear(msg); break; case MSG_ID_LL_CIRCULAR_STORAGE_SHUTDOWN_REQ: cfw_send_message(CFW_MESSAGE_PRIV(msg)); break; case MSG_ID_CIRCULAR_STORAGE_GET_REQ: handle_get(msg); default: cfw_print_default_handle_error_msg(LOG_MODULE_MAIN, CFW_MESSAGE_ID( msg)); break; } cfw_msg_free(msg); }
void cfw_send_event(struct cfw_message * msg) { #ifdef SVC_MANAGER_DEBUG pr_debug(LOG_MODULE_CFW, "%s : msg:%d", __func__, CFW_MESSAGE_ID(msg)); #endif list_head_t * list = get_event_list(CFW_MESSAGE_ID(msg)); if (list != NULL ) { list_foreach(list, send_event_callback, msg); } }
void my_handle_message(struct cfw_message * msg, void * param) { pr_info(LOG_MODULE_MAIN, "%s:%s for param: %s conn:%p", __FILE__, __func__, (char*)param, msg->conn); cfw_dump_message(msg); switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_OPEN_SERVICE_RSP: { pr_info(LOG_MODULE_MAIN, "%s:%s for conn: %s", __FILE__, __func__, (char*)msg->priv); cfw_open_conn_rsp_msg_t * cnf = (cfw_open_conn_rsp_msg_t*)msg; int events[1] = {MSG_ID_TEST_1_EVT}; test_service_conn = cnf->service_conn; cfw_register_events(test_service_conn, events, 1, msg->priv); } break; case MSG_ID_CFW_REGISTER_EVT_RSP: if (!strcmp(msg->priv, "Conn2")) { test_service_test_1(test_service_conn, "Coucou"); } break; case MSG_ID_TEST_1_RSP: { pr_info(LOG_MODULE_MAIN, "got MSG_ID_TEST_1_RSP Priv: %s", (char*)msg->priv); test_service_test_2(test_service_conn, "Testing 2"); break; } case MSG_ID_TEST_2_RSP: { pr_info(LOG_MODULE_MAIN, "got MSG_ID_TEST_2_RSP Priv: %s", (char*)msg->priv); test_service_test_1(test_service_conn, "Testing 1"); break; } } cfw_msg_free(msg); }
/** * Callback function for gpio service response */ void pwrbtn_tst_handle_msg(struct cfw_message *msg, void *data) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_OPEN_SERVICE_RSP: *((cfw_service_conn_t **)(msg->priv)) = (cfw_service_conn_t *)((cfw_open_conn_rsp_msg_t *)msg) -> service_conn; cu_print("TST_PWRBTN service opened \n"); break; case MSG_ID_GPIO_SERVICE_CONFIGURE_RSP: cu_print("TST_PWRBTN %s state=%d\n", msg->priv, ((gpio_service_configure_rsp_msg_t *)msg)->status); tst_pwrbtn_configure = 1; break; case MSG_ID_GPIO_SERVICE_SET_STATE_RSP: tst_pwrbtn_set_state = 1; cu_print("TST_PWRBTN %s: state=%d\n", msg->priv, ((gpio_service_set_state_rsp_msg_t *)msg)->status); break; case MSG_ID_GPIO_SERVICE_GET_STATE_RSP: tst_pwrbtn_get_state = 1; tst_pwrbtn_get_value = ((gpio_service_get_state_rsp_msg_t *)msg)->state; cu_print("TST_PWRBTN %s: state=%d, pin=0x%x\n", msg->priv, ((gpio_service_set_state_rsp_msg_t *)msg)->status, ((gpio_service_get_state_rsp_msg_t *)msg)->state); case MSG_ID_GPIO_SERVICE_GET_BANK_STATE_RSP: tst_pwrbtn_get_bank_state = 1; tst_pwrbtn_get_bank_value = ((gpio_service_get_bank_state_rsp_msg_t *)msg)->state; cu_print("TST_PWRBTN %s: state=%d, pin=0x%x\n", msg->priv, ((gpio_service_set_state_rsp_msg_t *)msg)->status, ((gpio_service_get_bank_state_rsp_msg_t *)msg)->state); break; case MSG_ID_GPIO_SERVICE_LISTEN_RSP: tst_pwrbtn_listen = 1; cu_print("TST_PWRBTN %s: state=%d, pin=%d\n", msg->priv, ((gpio_service_listen_rsp_msg_t *)msg)->status, ((gpio_service_listen_rsp_msg_t *)msg)->index); break; case MSG_ID_GPIO_SERVICE_UNLISTEN_RSP: tst_pwrbtn_unlisten = 1; cu_print("TST_PWRBTN %s: state=%d, pin=%d\n", msg->priv, ((gpio_service_unlisten_rsp_msg_t *)msg)->status, ((gpio_service_listen_rsp_msg_t *)msg)->index); break; case MSG_ID_GPIO_SERVICE_EVT: tst_pwrbtn_event = 1; cu_print("TST_PWRBTN EVT %s: state=%d, pin=%d\n", msg->priv, ((gpio_service_listen_evt_msg_t *)msg)->pin_state, ((gpio_service_listen_evt_msg_t *)msg)->index); break; default: cu_print("default cfw handler\n"); break; } cfw_msg_free(msg); }
static void cfw_message_handler(struct cfw_message *msg, void *param) { DRIVER_API_RC ret = DRV_RC_FAIL; static uint16_t adc_value; switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_GPIO_SERVICE_CONFIGURE_RSP: case MSG_ID_GPIO_SERVICE_SET_STATE_RSP: break; case MSG_ID_ADC_SERVICE_SUBSCRIBE_RSP: pr_debug(LOG_MODULE_MAIN, "ADC subscribe Response"); adc_svc_client = ((adc_service_subscribe_rsp_msg_t *)msg)-> adc_sub_conn_handle; ret = ((adc_service_subscribe_rsp_msg_t *)msg)->status; if (DRV_RC_OK != ret) { pr_error(LOG_MODULE_MAIN, "ADC subscribe fails %d", ret); panic(-1); } break; case MSG_ID_ADC_SERVICE_GET_VAL_EVT: ret = ((adc_service_get_evt_msg_t *)msg)->status; if (DRV_RC_OK == ret) { adc_value = ((adc_service_get_evt_msg_t *)msg)->adc_value; pr_debug(LOG_MODULE_MAIN, "adc_value %d", adc_value); if (adc_value < LOWER_LIMIT) blink_freq = LED_BLINK_ONE_SEC; else if (adc_value > HIGHER_LIMIT) blink_freq = LED_BLINK_500_MS; else blink_freq = LED_BLINK_TWO_SEC; } else { pr_error(LOG_MODULE_MAIN, "ADC get value fails %d", ret); } break; default: pr_info(LOG_MODULE_MAIN, "Discarded message: %x", CFW_MESSAGE_ID(msg)); } cfw_msg_free(msg); }
static void ble_is_not_enabled_rsp(struct cfw_message *msg, int status) { struct ble_enable_rsp *resp = (struct ble_enable_rsp *)cfw_alloc_rsp_msg(msg, /* translate msg from req to rsp */ (CFW_MESSAGE_ID(msg) ^ MSG_ID_BLE_SERVICE_BASE) | MSG_ID_BLE_SERVICE_RSP, sizeof(*resp)); resp->status = status; cfw_send_message(resp); }
static void srv_client_handle_msg(struct cfw_message * msg, void * data) { cfw_dump_message(msg); switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_OPEN_SERVICE_RSP: { cfw_open_conn_rsp_msg_t *resp = (cfw_open_conn_rsp_msg_t *)msg; printf("server_main:%s(): MSG_ID_CFW_OPEN_SERVICE_RSP::port_id: %d, cpu_id: %d, " "service_conn: 0x%p, priv 0x%p\n", __func__, resp->port, resp->cpu_id, resp->service_conn, msg->priv); break; } case MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP: printf("server_main::%s(): MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP, priv:" " 0x%p\n", __func__, msg->priv); break; case MSG_ID_CFW_SVC_AVAIL_EVT: { cfw_svc_available_evt_msg_t * evt = (cfw_svc_available_evt_msg_t *)msg; if ((evt->service_id == BLE_CORE_SERVICE_ID) || (0 != cfw_service_registered( BLE_CORE_SERVICE_ID))) { _server_cb.ble_svc_started = 1; printf("\n%s(): BLE_CORE_SERVICE_ID registered!\n", __func__); #ifdef CONFIG_BLE_CORE_TEST extern void test_ble_service_init(void); test_ble_service_init(); #endif } break; } default: pr_info(LOG_MODULE_MAIN, "server_main::%s(): Unhandled Msg: 0x%x", __func__, CFW_MESSAGE_ID(msg)); break; } cfw_msg_free(msg); }
struct cfw_message * cfw_alloc_internal_msg(int msg_id, int size, void * priv) { struct cfw_message * evt = (struct cfw_message *) cfw_alloc_message(size, NULL); CFW_MESSAGE_TYPE(evt) = TYPE_INT; CFW_MESSAGE_ID(evt) = msg_id; CFW_MESSAGE_LEN(evt) = size; CFW_MESSAGE_SRC(evt) = 0; /* 3 fields below whould be filed by send_event method*/ CFW_MESSAGE_DST(evt) = 0; evt->priv = priv; evt->conn = NULL; return evt; }
struct cfw_message * cfw_alloc_evt_msg(service_t *svc, int msg_id, int size) { struct cfw_message * evt = (struct cfw_message *) cfw_alloc_message(size, NULL); CFW_MESSAGE_TYPE(evt) = TYPE_EVT; CFW_MESSAGE_ID(evt) = msg_id; CFW_MESSAGE_LEN(evt) = size; CFW_MESSAGE_SRC(evt) = svc->port_id; /* 3 fields below whould be filed by send_event method*/ CFW_MESSAGE_DST(evt) = 0; evt->priv = NULL; evt->conn = NULL; return evt; }
/**@brief Function to handle requests, responses and events * @param[in] msg Event message. */ static void bs_handle_message(struct cfw_message *msg, void *param) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_BATTERY_SERVICE_GET_BATTERY_INFO_REQ: handle_battery_service_get_info(msg); break; case MSG_ID_BATTERY_SERVICE_SET_LOW_LEVEL_ALARM_REQ: case MSG_ID_BATTERY_SERVICE_SET_CRITICAL_LEVEL_ALARM_REQ: handle_bs_set_level_alarm(msg, CFW_MESSAGE_ID(msg)); break; case MSG_ID_BATTERY_SERVICE_SET_MEASURE_INTERVAL_REQ: handle_battery_set_measure_interval(msg); break; default: pr_error(LOG_MODULE_BS, "Unexpected message id: %x", CFW_MESSAGE_ID( msg)); break; } cfw_msg_free(msg); }
static void sensor_handle_msg(struct cfw_message *msg, void *data) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_SS_START_SENSOR_SCANNING_EVT: handle_start_scanning_evt(msg); break; case MSG_ID_SS_SENSOR_SUBSCRIBE_DATA_EVT: handle_sensor_subscribe_data(msg); break; } cfw_msg_free(msg); }
void cfw_dump_message(struct cfw_message * msg) { #if 1 pr_debug(LOG_MODULE_CFW, "%p id: %x src: %d[cpu:%d] dst: %d[cpu:%d] type: %s", msg, CFW_MESSAGE_ID(msg), CFW_MESSAGE_SRC(msg), port_get_cpu_id(CFW_MESSAGE_SRC(msg)), CFW_MESSAGE_DST(msg), port_get_cpu_id(CFW_MESSAGE_DST(msg)), cfw_get_msg_type_str(msg)); #else pr_debug(LOG_MODULE_CFW, "id: %x src: %d dst: %d type: %s", msg->id, msg->src, msg->dst, cfw_get_msg_type_str(msg)); #endif }
fsm_state_t act_start_done(struct fsm_event_message * evt) { pr_info(LOG_MODULE_NFC, "NFC RF active!"); { struct cfw_message evt; CFW_MESSAGE_ID(&evt) = MSG_ID_NFC_RF_EVT; CFW_MESSAGE_TYPE(&evt) = TYPE_EVT; CFW_MESSAGE_LEN(&evt) = sizeof(evt); CFW_MESSAGE_SRC(&evt) = _cfw_get_service_port(NFC_SERVICE_ID); cfw_send_event(&evt); } process_pending_msg_cb(NFC_STATUS_SUCCESS); return ST_ACTIVE; }
static void handle_message(struct cfw_message * msg, void * param) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_LL_ERASE_BLOCK_REQ: handle_erase_block(msg); break; case MSG_ID_LL_READ_PARTITION_REQ: handle_read_partition(msg); break; case MSG_ID_LL_WRITE_PARTITION_REQ: handle_write_partition(msg); break; #ifdef CONFIG_SERVICES_QUARK_SE_STORAGE_CIRCULAR case MSG_ID_LL_CIR_STOR_INIT_REQ: handle_cir_stor_init(msg); break; case MSG_ID_LL_PUSH_REQ: handle_push(msg); break; case MSG_ID_LL_POP_REQ: handle_pop(msg); break; case MSG_ID_LL_PEEK_REQ: handle_peek(msg); break; case MSG_ID_LL_CLEAR_REQ: handle_clear(msg); break; #endif default: cfw_print_default_handle_error_msg(LOG_MODULE_MAIN, CFW_MESSAGE_ID(msg)); break; } cfw_msg_free(msg); }
static void send_service_avail_evt(int service_id, uint16_t port_id, void *param) { cfw_svc_available_evt_msg_t * evt = (cfw_svc_available_evt_msg_t*) balloc(sizeof(*evt), NULL); evt->service_id = service_id; CFW_MESSAGE_LEN(&evt->header) = sizeof(*evt); CFW_MESSAGE_ID(&evt->header) = MSG_ID_CFW_SVC_AVAIL_EVT; CFW_MESSAGE_SRC(&evt->header) = service_mgr_port_id; CFW_MESSAGE_DST(&evt->header) = port_id; CFW_MESSAGE_TYPE(&evt->header) = TYPE_EVT; evt->header.priv = param; pr_debug(LOG_MODULE_MAIN, "Notify : %d to %d", service_id, port_id); cfw_send_message(evt); }
struct cfw_rsp_message * cfw_alloc_rsp_msg(const struct cfw_message *req, int msg_id, int size) { struct cfw_rsp_message * rsp = (struct cfw_rsp_message *) cfw_alloc_message(size, NULL); CFW_MESSAGE_TYPE(&rsp->header) = TYPE_RSP; CFW_MESSAGE_ID(&rsp->header) = msg_id; CFW_MESSAGE_LEN(&rsp->header) = size; CFW_MESSAGE_DST(&rsp->header) = CFW_MESSAGE_SRC(req); CFW_MESSAGE_SRC(&rsp->header) = CFW_MESSAGE_DST(req); rsp->header.priv = req->priv; /* Substitute server-side with client-side conn */ if (req->conn != NULL) rsp->header.conn = ((conn_handle_t*)req->conn)->client_handle; else rsp->header.conn = NULL; return rsp; }
static void circular_storage_shutdown(service_t *svc, struct cfw_message *msg) { struct cfw_message *sm = (struct cfw_message *)message_alloc( sizeof(*sm), NULL); /* In order to ensure that any pending requests are processed prior to the * service shutdown, send a message to self so it will be processed after * all other pending requests. */ CFW_MESSAGE_ID(sm) = MSG_ID_LL_CIRCULAR_STORAGE_SHUTDOWN_REQ; CFW_MESSAGE_DST(sm) = circular_storage_service.port_id; CFW_MESSAGE_SRC(sm) = circular_storage_service.port_id; CFW_MESSAGE_PRIV(sm) = msg; cfw_send_message(sm); }
static void _handle_client_message(struct cfw_message *msg, void *data) { (void)data; switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_OPEN_SERVICE: { /* We have passed the allocated cnx as an opaque data */ struct _svc_cnx *cnx = CFW_MESSAGE_PRIV(msg); /* Get the service parameters from the message and store them locally */ cfw_open_conn_rsp_msg_t *con_msg = (cfw_open_conn_rsp_msg_t *)msg; cnx->sh = (svc_client_handle_t *)(con_msg->client_handle); cnx->src_port = con_msg->port; cfw_msg_free(msg); list_add(&_services, (list_t *)cnx); break; } case MSG_ID_CFW_CLOSE_SERVICE: { struct _svc_cnx *cnx = CFW_MESSAGE_PRIV(msg); list_remove(&_services, (list_t *)cnx); bfree(cnx); cfw_msg_free(msg); break; } case MSG_ID_CFW_SVC_AVAIL_EVT: { struct _svc_cnx *cnx = CFW_MESSAGE_PRIV(msg); if (((cfw_svc_available_evt_msg_t*)msg)->service_id == cnx->service_id) { cfw_open_service(_proxy_handle, cnx->service_id, cnx); } cfw_msg_free(msg); break; } default: { /* Find the service connection based on the message source port */ struct _svc_cnx *cnx = (struct _svc_cnx*) list_find_first(&_services, _cmp_port, &(CFW_MESSAGE_SRC(msg))); if (cnx) { cnx->cb(msg, cnx->data); } else { cfw_msg_free(msg); } break; } } }
static void ble_service_message_handler(struct cfw_message *msg, void *param) { bool free_msg = true; struct _ble_service_cb *p_cb = param; uint16_t msg_id = CFW_MESSAGE_ID(msg); if (p_cb->ble_state < BLE_ST_ENABLED && msg_id != MSG_ID_BLE_ENABLE_REQ) { ble_is_not_enabled_rsp(msg, -ENODEV); goto out; } switch (msg_id) { case MSG_ID_BLE_ENABLE_REQ: { struct ble_enable_req *req = container_of(msg, struct ble_enable_req, header); if (p_cb->ble_state) { if (req->enable) { handle_ble_enable(req, p_cb); free_msg = false; } else handle_ble_disable(req, p_cb); } else { pr_debug(LOG_MODULE_BLE, "ble_hdl_msg: core service not opened!"); /* core service is not yet up */ struct ble_enable_rsp *resp = (void *)cfw_alloc_rsp_msg(msg, MSG_ID_BLE_ENABLE_RSP, sizeof(*resp)); resp->status = -EINPROGRESS; resp->enable = 0; cfw_send_message(resp); } } break; #ifdef CONFIG_TCMD_BLE_DEBUG case MSG_ID_BLE_DBG_REQ: handle_msg_id_ble_dbg(msg); break; #endif default: pr_warning(LOG_MODULE_BLE, "unsupported %d", msg_id); break; } out: if (free_msg) cfw_msg_free(msg); }
/** * \fn void gpio_tst_handle_msg(struct cfw_message * msg, void * data) * * \brief Callback function for gpio service test */ void gpio_tst_handle_msg(struct cfw_message * msg, void * data) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_OPEN_SERVICE_RSP: *((cfw_service_conn_t **)(msg->priv)) = (cfw_service_conn_t *)((cfw_open_conn_rsp_msg_t*)msg)->service_conn; cu_print("TST_GPIO open\n"); break; case MSG_ID_GPIO_CONFIGURE_RSP: cu_print("TST_GPIO %s state=%d\n", msg->priv, ((gpio_configure_rsp_msg_t*)msg)->rsp_header.status); tst_gpio_configure = 1; break; case MSG_ID_GPIO_SET_RSP: tst_gpio_set_state = 1; cu_print("TST_GPIO %s: state=%d\n", msg->priv, ((gpio_set_rsp_msg_t*)msg)->rsp_header.status); break; case MSG_ID_GPIO_GET_RSP: tst_gpio_get_state = 1; tst_gpio_get_value = ((gpio_get_rsp_msg_t*)msg)->state; cu_print("TST_GPIO %s: state=%d, pin=0x%x\n", msg->priv, ((gpio_set_rsp_msg_t*)msg)->rsp_header.status, ((gpio_get_rsp_msg_t*)msg)->state); break; case MSG_ID_GPIO_LISTEN_RSP: tst_gpio_listen = 1; cu_print("TST_GPIO %s: state=%d, pin=%d\n", msg->priv,((gpio_listen_rsp_msg_t*)msg)->rsp_header.status, ((gpio_listen_rsp_msg_t*)msg)->index); break; case MSG_ID_GPIO_UNLISTEN_RSP: tst_gpio_unlisten = 1; cu_print("TST_GPIO %s: state=%d, pin=%d\n", msg->priv,((gpio_unlisten_rsp_msg_t*)msg)->rsp_header.status, ((gpio_listen_rsp_msg_t*)msg)->index); break; case MSG_ID_GPIO_EVT: tst_gpio_event = 1; cu_print("TST_GPIO EVT %s: state=%d, pin=%d\n", msg->priv,((gpio_listen_evt_msg_t*)msg)->pin_state, ((gpio_listen_evt_msg_t*)msg)->index); break; default: cu_print("default cfw handler\n"); break; } cfw_msg_free(msg); }
static void ble_app_msg_handler(struct cfw_message *msg, void *param) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_BLE_ENABLE_RSP: handle_msg_id_ble_enable_rsp(msg); break; case MSG_ID_PROP_SERVICE_ADD_RSP: break; case MSG_ID_PROP_SERVICE_READ_RSP: handle_ble_property_read_rsp(msg); break; case MSG_ID_PROP_SERVICE_WRITE_RSP: break; #ifdef CONFIG_BLE_APP_USE_BAT case MSG_ID_BATTERY_SERVICE_LEVEL_UPDATED_EVT: { battery_service_listen_evt_rsp_msg_t *evt = container_of( msg, battery_service_listen_evt_rsp_msg_t, header); if (_ble_app_cb.flags & BLE_APP_ENABLED) ble_bas_update( evt->battery_service_evt_content_rsp_msg. bat_soc); break; } case MSG_ID_BATTERY_SERVICE_GET_BATTERY_INFO_RSP: { struct battery_service_info_request_rsp_msg *batt_msg = container_of( msg, struct battery_service_info_request_rsp_msg, header); if (_ble_app_cb.flags & BLE_APP_ENABLED) ble_bas_update(batt_msg->battery_soc.bat_soc); break; } #endif default: pr_debug(LOG_MODULE_BLE, "Unhandled BLE app message"); } cfw_msg_free(msg); }
static void ble_core_client_handle_message(struct cfw_message *msg, void *param) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_SVC_AVAIL_EVT: handle_msg_id_cfw_svc_avail_evt((cfw_svc_available_evt_msg_t *)msg, param); break; case MSG_ID_CFW_OPEN_SERVICE: handle_msg_id_cfw_open_svc((cfw_open_conn_rsp_msg_t *)msg, param); break; case MSG_ID_BLE_GAP_WR_CONF_RSP: handle_msg_id_ble_gap_wr_conf_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GAP_RD_BDA_RSP: handle_msg_id_ble_gap_rd_bda_rsp((ble_bda_rd_rsp_t *)msg, param); break; case MSG_ID_BLE_GAP_SM_CONFIG_RSP: handle_msg_id_ble_gap_sm_config_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GAP_WR_ADV_DATA_RSP: handle_msg_id_ble_gap_wr_adv_data_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GAP_ENABLE_ADV_RSP: handle_msg_id_ble_gap_enable_adv_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GAP_DISABLE_ADV_RSP: handle_msg_id_ble_gap_disable_adv_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GATTS_ADD_SERVICE_RSP: handle_msg_id_gatts_add_service_rsp((struct ble_gatts_add_svc_rsp *)msg, param); break; case MSG_ID_BLE_GATTS_ADD_CHARACTERISTIC_RSP: handle_msg_id_gatts_add_characteristic_rsp((struct ble_gatts_add_char_rsp *)msg, param); break; case MSG_ID_BLE_GATTS_ADD_DESCRIPTOR_RSP: handle_msg_id_gatts_add_desc_rsp((struct ble_gatts_add_desc_rsp *)msg, param); break; case MSG_ID_BLE_GATTS_SET_ATTRIBUTE_VALUE_RSP: handle_msg_id_ble_gatts_set_attribute_value_rsp((struct ble_gatts_set_attr_rsp_msg *)msg, param); break; case MSG_ID_BLE_GATTS_SEND_NOTIF_RSP: case MSG_ID_BLE_GATTS_SEND_IND_RSP: handle_msg_id_ble_gatts_send_notif_ind_rsp((ble_gatts_rsp_t *)msg, param); break; case MSG_ID_BLE_GAP_CONNECT_EVT: handle_msg_id_ble_gap_connect_evt_msg((struct ble_gap_event *)msg, param); break; case MSG_ID_BLE_GAP_DISCONNECT_EVT: handle_msg_id_ble_gap_disconnect_evt_msg((struct ble_gap_event *)msg, param); break; case MSG_ID_BLE_GAP_TO_EVT: handle_msg_id_ble_gap_timeout_evt_msg((struct ble_gap_event *)msg, param); break; case MSG_ID_BLE_GAP_RSSI_EVT: handle_msg_id_ble_gap_rssi_evt_msg((struct ble_gap_event *)msg, param); break; case MSG_ID_BLE_GATTS_WRITE_EVT: handle_msg_id_ble_gatts_write_evt_msg((struct ble_gatts_evt_msg *)msg, param); break; case MSG_ID_BLE_GAP_DISCONNECT_RSP: handle_msg_id_ble_gap_disconnect_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GAP_SET_RSSI_REPORT_RSP: handle_msg_id_ble_gap_set_rssi_report_rsp((struct ble_rsp *)msg, param); break; case MSG_ID_BLE_GAP_DTM_INIT_RSP: handle_msg_id_ble_gap_dtm_init_rsp((struct ble_generic_msg *)msg, param); break; } cfw_msg_free(msg); }
void internal_handle_message(struct cfw_message * msg, void * param) { int free_msg = 1; /* by default free message */ switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_ALLOC_PORT: { //TODO: Enable this, currently relies on sync IPC API. //_port_t * port = cfw_port_alloc(NULL); //cfw_port_set_handler(port, send_message_ipc, NULL); break; } case MSG_ID_CFW_OPEN_SERVICE: { cfw_open_conn_req_msg_t * req = (cfw_open_conn_req_msg_t *) msg; service_t * svc = cfw_get_service(req->service_id); if (svc == NULL) { pr_error(LOG_MODULE_MAIN, "try to open non registered service %d", req->service_id); cfw_open_conn_rsp_msg_t * resp = (cfw_open_conn_rsp_msg_t *) cfw_alloc_rsp_msg(msg, MSG_ID_CFW_OPEN_SERVICE, sizeof(*resp)); resp->rsp_header.status = E_OS_ERR_UNKNOWN; cfw_send_message(resp); break; } uint8_t svc_cpu_id = port_get_cpu_id(svc->port_id); if (svc_cpu_id != get_cpu_id()) { #ifdef INFRA_MULTI_CPU_SUPPORT pr_debug(LOG_MODULE_MAIN, "forward open service to proxy"); CFW_MESSAGE_DST(msg) = proxies[svc_cpu_id].port_id; cfw_send_message(msg); free_msg = 0; /* the lower layers will free it! */ #else pr_error(LOG_MODULE_MAIN, "incorrect cpu_id settings, single cpu!"); #endif } else { conn_handle_t * conn_handle; conn_handle = (conn_handle_t *) balloc(sizeof(*conn_handle), NULL ); conn_handle->client_port = CFW_MESSAGE_SRC(msg); conn_handle->priv_data = NULL; conn_handle->svc = svc; conn_handle->client_handle = req->client_handle; /* For OPEN_SERVICE, conn is not know yet, it is just alloc'ed. * set it here.*/ req->header.conn = conn_handle; if (svc->client_connected != NULL && svc_cpu_id == get_cpu_id()) svc->client_connected(conn_handle); cfw_open_conn_rsp_msg_t * resp = (cfw_open_conn_rsp_msg_t *) cfw_alloc_rsp_msg(msg, MSG_ID_CFW_OPEN_SERVICE, sizeof(*resp)); resp->port = svc->port_id; resp->cpu_id = svc_cpu_id; #ifdef SVC_MANAGER_DEBUG pr_debug(LOG_MODULE_CFW, "OPEN_SERVICE: %d, svc:%p port:%d", req->service_id, svc, svc->port_id); #endif resp->svc_server_handle = conn_handle; resp->client_handle = req->client_handle; cfw_send_message(resp); } break; } case MSG_ID_CFW_CLOSE_SERVICE: { cfw_close_conn_req_msg_t * req = (cfw_close_conn_req_msg_t*) msg; service_t * svc = cfw_get_service(req->service_id); if (svc == NULL) { pr_debug(LOG_MODULE_MAIN, "try close unregistered service %d", req->service_id); cfw_close_conn_rsp_msg_t * resp = (cfw_close_conn_rsp_msg_t *) cfw_alloc_rsp_msg(msg, MSG_ID_CFW_CLOSE_SERVICE, sizeof(*resp)); resp->rsp_header.status = E_OS_ERR_UNKNOWN; cfw_send_message(resp); break; } uint8_t svc_cpu_id = port_get_cpu_id(svc->port_id); if (svc_cpu_id != get_cpu_id()) { #ifdef INFRA_MULTI_CPU_SUPPORT CFW_MESSAGE_DST(msg) = proxies[svc_cpu_id].port_id; cfw_send_message(msg); free_msg=0; #else pr_error(LOG_MODULE_MAIN, "incorrect cpu_id!"); #endif } else { cfw_close_conn_rsp_msg_t * resp = (cfw_close_conn_rsp_msg_t *) cfw_alloc_rsp_msg(msg, MSG_ID_CFW_CLOSE_SERVICE, sizeof(*resp)); conn_handle_t * conn = (conn_handle_t*) msg->conn; if (conn != NULL && conn->svc != NULL && conn->svc->client_disconnected != NULL ) conn->svc->client_disconnected(conn); cfw_send_message(resp); /* Free server-side conn */ bfree(conn); } break; } case MSG_ID_CFW_REGISTER_EVT: { int * params = (int *) &msg[1]; int i; for (i = 0; i < params[0]; i++) { _cfw_register_event((conn_handle_t*) msg->conn, params[i + 1]); } cfw_register_evt_rsp_msg_t * resp = (cfw_register_evt_rsp_msg_t *) cfw_alloc_rsp_msg(msg, MSG_ID_CFW_REGISTER_EVT, (sizeof(*resp))); conn_handle_t * conn = (conn_handle_t*) msg->conn; if (conn != NULL && conn->svc != NULL && conn->svc->registered_events_changed != NULL ) conn->svc->registered_events_changed(conn); cfw_send_message(resp); break; } case MSG_ID_CFW_REGISTER_SVC_AVAIL: { bool already_avail = true; cfw_register_svc_avail_req_msg_t * req = (cfw_register_svc_avail_req_msg_t *) msg; int flags = interrupt_lock(); if (_find_service(req->service_id) == -1) { add_service_avail_listener(CFW_MESSAGE_SRC(msg), req->service_id, msg->priv); already_avail = false; } interrupt_unlock(flags); cfw_register_svc_avail_rsp_msg_t * resp = (cfw_register_svc_avail_rsp_msg_t *) cfw_alloc_rsp_msg(msg, MSG_ID_CFW_REGISTER_SVC_AVAIL, (sizeof(*resp))); cfw_send_message(resp); if (already_avail) { send_service_avail_evt(req->service_id, CFW_MESSAGE_SRC(msg), msg->priv); } break; } default: pr_warning(LOG_MODULE_CFW, "%s: unhandled message id: %x", __func__, CFW_MESSAGE_ID(msg)); break; } if (free_msg) cfw_msg_free(msg); }
void sensor_core_svc_rsp_handle(struct cfw_message *p_msg, void *p_param) { switch (CFW_MESSAGE_ID(p_msg)) { case MSG_ID_CFW_OPEN_SERVICE_RSP: { cfw_open_conn_rsp_msg_t *cnf = (cfw_open_conn_rsp_msg_t *)p_msg; p_sc_service_conn = (cfw_service_conn_t *)cnf->service_conn; if (NULL == p_sc_service_conn) { SS_PRINT_ERR("Opening Score_svc failed"); return; } SS_PRINT_LOG("Opening Score_svc successful"); if (core_connected_cb) { core_connected_cb(core_connected_cb_data); } } break; case MSG_ID_CFW_REGISTER_EVT_RSP: { SS_PRINT_LOG("Register evt!!"); } break; case MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP: break; case MSG_ID_CFW_SVC_AVAIL_EVT: { uint16_t service_id = ((cfw_svc_available_evt_msg_t *)p_msg)->service_id; SS_PRINT_LOG("AVAIL_EVT: %d", service_id); if (ARC_SC_SVC_ID == service_id) { cfw_open_service_conn(p_client, ARC_SC_SVC_ID, NULL); } else { SS_PRINT_LOG("AVAIL_EVT:service_id is error"); } } break; case MSG_ID_SENSOR_SERVICE_START_SCANNING_RSP: { SS_PRINT_LOG("[%s]Scanning rsp", __func__); } break; case MSG_ID_SENSOR_SERVICE_START_SCANNING_EVT: { sensor_service_scan_event_t *p_evt = (sensor_service_scan_event_t *)p_msg; uint8_t sensor_type = (uint8_t)(((uint32_t)p_evt->handle) >> 8); uint8_t sensor_id = (uint8_t)(((uint32_t)p_evt->handle) & 0xff); send_scan_evt_message_to_clients(sensor_type, sensor_id); SS_PRINT_LOG("[%s]Scanning evt", __func__); } break; case MSG_ID_SENSOR_SERVICE_STOP_SCANNING_RSP: { SS_PRINT_LOG("[%s]Stop SCANNING RSP", __func__); } break; case MSG_ID_SENSOR_SERVICE_PAIR_RSP: { SS_PRINT_LOG("[%s]PAIR RSP", __func__); } break; case MSG_ID_SENSOR_SERVICE_SUBSCRIBE_DATA_RSP: { sensor_service_message_general_rsp_t *p_rsp = (sensor_service_message_general_rsp_t *)p_msg; uint8_t sensor_type = (uint8_t)(((uint32_t)p_rsp->handle) >> 8); uint8_t sensor_id = (uint8_t)(((uint32_t)p_rsp->handle) & 0xff); SS_PRINT_LOG("SUBSCRIBE_DATA_RSP:type=%d,id=%d,status=%d]", \ sensor_type, sensor_id, \ p_rsp->status); send_sensor_subscribing_rsp_message_to_clients(sensor_type, sensor_id, p_rsp->status); } break; case MSG_ID_SENSOR_SERVICE_SUBSCRIBE_DATA_EVT: { sensor_service_subscribe_data_event_t *p_evt = (sensor_service_subscribe_data_event_t *)p_msg; sensor_service_sensor_data_header_t *p_data_header = &p_evt->sensor_data_header; uint8_t sensor_type = (uint8_t)(((uint32_t)p_evt->handle) >> 8); uint8_t sensor_id = (uint8_t)(((uint32_t)p_evt->handle) & 0xff); send_sensor_subscribing_evt_message_to_clients( sensor_type, sensor_id, 0, \ p_data_header-> timestamp, \ (void *) p_data_header->data, \ p_data_header-> data_length); } break; case MSG_ID_SENSOR_SERVICE_UNSUBSCRIBE_DATA_RSP: { SS_PRINT_LOG("[%s]UNSUBSCRIBED RSP", __func__); ss_sensor_unsubscribe_data_rsp_t *p_rsp = (ss_sensor_unsubscribe_data_rsp_t *)p_msg; uint8_t sensor_type = GET_SENSOR_TYPE(p_rsp->handle); uint8_t sensor_id = GET_SENSOR_ID(p_rsp->handle); send_sensor_unsubscribing_rsp_message_to_clients(sensor_type, sensor_id, p_rsp->status); } break; case MSG_ID_SENSOR_SERVICE_UNPAIR_RSP: break; case MSG_ID_SS_SENSOR_UNLINK_EVT: break; default: SS_PRINT_ERR("[%s]unhandled msg %d", __func__, CFW_MESSAGE_ID(p_msg)); break; } cfw_msg_free(p_msg); }
void test_handle_message(struct cfw_message * msg, void * param) { cfw_log("%s:%s for param: %s conn:%p id:%d\n", __FILE__, __func__, (char*) param, msg->conn, CFW_MESSAGE_ID(msg)); //cfw_dump_message(msg); switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP: break; case MSG_ID_CFW_SVC_AVAIL_EVT: { int svc_id = ((cfw_svc_available_evt_msg_t *)msg)->service_id; if (svc_id == SOC_GPIO_SERVICE_ID) { cfw_open_service_conn(client, SOC_GPIO_SERVICE_ID, "Conn1"); } break; } case MSG_ID_CFW_OPEN_SERVICE_RSP: { cfw_log("%s:%s for conn: %s\n", __FILE__, __func__, (char*) CFW_MESSAGE_PRIV(msg)); cfw_open_conn_rsp_msg_t * cnf = (cfw_open_conn_rsp_msg_t*) msg; gpio_service_conn = cnf->service_conn; gpio_configure(gpio_service_conn, 26, 1, NULL); break; } case MSG_ID_GPIO_CONFIGURE_RSP: gpio_set_state(gpio_service_conn, 26, 1, NULL); break; case MSG_ID_GPIO_SET_RSP: { int val; void * next; if (!((int) CFW_MESSAGE_PRIV(msg))) { val = 0; next = (void*) 1; } else { val = 1; next = (void*) 0; } printf("Got response: %d %d \n", val, (int) next); if (count ++ > 100) { cfw_close_service_conn(gpio_service_conn, NULL); } else { gpio_set_state(gpio_service_conn, 26, val, next); } } break; case MSG_ID_CFW_CLOSE_SERVICE_RSP: { cfw_close_conn_rsp_msg_t * resp = (cfw_close_conn_rsp_msg_t*) msg; cfw_log("%s: res: %d\n", __func__, resp->rsp_header.status); exit(0); } break; default: { cfw_log("%s: Unhandled message: %d\n", __func__, CFW_MESSAGE_ID(msg)); break; } } cfw_msg_free(msg); }
void client_handle_message(struct cfw_message *msg, void *param) { _cfw_client_t *c = (_cfw_client_t *)param; bool handled = false; switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP: if (get_conn_helper(c, msg->priv)) handled = true; break; case MSG_ID_CFW_SVC_AVAIL_EVT: { cfw_svc_available_evt_msg_t *evt = (cfw_svc_available_evt_msg_t *)msg; if (get_conn_helper(c, evt->header.priv)) { cfw_open_service_conn(c, evt->service_id, evt->header.priv); handled = true; } } break; case MSG_ID_CFW_OPEN_SERVICE_RSP: { cfw_open_conn_rsp_msg_t *cnf = (cfw_open_conn_rsp_msg_t *)msg; /** Make client handle point to server handle */ ((cfw_service_conn_t *)cnf->service_conn)->server_handle = cnf->svc_server_handle; /** Initialize service port. */ ((cfw_service_conn_t *)cnf->service_conn)->port = cnf->port; #ifndef CONFIG_PORT_IS_MASTER /* Set local port and cpu id */ if (get_cpu_id() != cnf->cpu_id) { port_set_port_id(cnf->port); port_set_cpu_id(cnf->port, cnf->cpu_id); } #endif struct conn_helper_data *helper = get_conn_helper( c, cnf->header.priv); if (helper != NULL) { helper->service_conn = (cfw_service_conn_t *)cnf->service_conn; if (helper->event_count > 0) { cfw_register_events(helper->service_conn, helper->events, helper->event_count, helper); } else { /* call the helper callback and free it */ cfw_open_service_helper_done(c, helper); } handled = true; } break; } case MSG_ID_CFW_REGISTER_EVT_RSP: { struct conn_helper_data *helper = get_conn_helper( c, CFW_MESSAGE_PRIV(msg)); if (helper != NULL) { helper->cb(helper->service_conn, helper->cb_data); list_remove(&c->helper_list, &helper->list); bfree(helper); handled = true; } } break; case MSG_ID_CFW_CLOSE_SERVICE_RSP: { /* Free client-side conn */ bfree(msg->conn); break; } default: //Nothing to do break; } if (handled) /* message handled here: free it */ bfree(msg); else { /* defer processing to message handler */ if (CFW_MESSAGE_CB(msg)) { /* A specific callback was specified for this message */ CFW_MESSAGE_CB(msg) (msg); } else { /* Call client global message handler */ c->handle_msg(msg, c->data); } } }