static DBusMessage *handsfree_set_property(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_handsfree *hf = data; DBusMessageIter iter, var; ofono_bool_t enabled; const char *name; if (hf->pending) return __ofono_error_busy(msg); if (dbus_message_iter_init(msg, &iter) == FALSE) return __ofono_error_invalid_args(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&iter, &name); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return __ofono_error_invalid_args(msg); dbus_message_iter_recurse(&iter, &var); if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&var, &enabled); if (g_str_equal(name, "VoiceRecognition") == TRUE) { if (!hf->driver->voice_recognition) return __ofono_error_not_implemented(msg); if (hf->voice_recognition == enabled) return dbus_message_new_method_return(msg); hf->voice_recognition_pending = enabled; hf->pending = dbus_message_ref(msg); hf->driver->voice_recognition(hf, enabled, voicerec_set_cb, hf); } else if (g_str_equal(name, "EchoCancelingNoiseReduction") == TRUE) { if (!(hf->ag_features & HFP_AG_FEATURE_ECNR)) return __ofono_error_not_supported(msg); if (!hf->driver->disable_nrec || enabled == TRUE) return __ofono_error_not_implemented(msg); if (hf->nrec == FALSE) return dbus_message_new_method_return(msg); hf->pending = dbus_message_ref(msg); hf->driver->disable_nrec(hf, nrec_set_cb, hf); } else return __ofono_error_invalid_args(msg); return NULL; }
static DBusMessage *ussd_respond(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_ussd *ussd = data; const char *str; int dcs = 0x0f; unsigned char buf[160]; long num_packed; if (ussd->pending) return __ofono_error_busy(msg); if (ussd->state != USSD_STATE_USER_ACTION) return __ofono_error_not_active(msg); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); if (strlen(str) == 0) return __ofono_error_invalid_format(msg); if (!ussd_encode(str, &num_packed, buf)) return __ofono_error_invalid_format(msg); if (ussd->driver->request == NULL) return __ofono_error_not_implemented(msg); ussd->pending = dbus_message_ref(msg); ussd->driver->request(ussd, dcs, buf, num_packed, ussd_response_callback, ussd); return NULL; }
static DBusMessage *sink_connect(DBusConnection *conn, DBusMessage *msg, void *data) { struct audio_device *dev = data; struct sink *sink = dev->sink; struct pending_request *pending; if (!sink->session) sink->session = avdtp_get(&dev->src, &dev->dst); if (!sink->session) return btd_error_failed(msg, "Unable to get a session"); if (sink->connect || sink->disconnect) return btd_error_busy(msg); if (sink->stream_state >= AVDTP_STATE_OPEN) return btd_error_already_connected(msg); if (!sink_setup_stream(sink, NULL)) return btd_error_failed(msg, "Failed to create a stream"); dev->auto_connect = FALSE; pending = sink->connect; pending->conn = dbus_connection_ref(conn); pending->msg = dbus_message_ref(msg); DBG("stream creation in progress"); return NULL; }
static DBusMessage *dev_disconnect(DBusConnection *conn, DBusMessage *msg, void *data) { struct audio_device *dev = data; struct dev_priv *priv = dev->priv; if (priv->state == AUDIO_STATE_DISCONNECTED) return g_dbus_create_error(msg, ERROR_INTERFACE ".NotConnected", "Not connected"); if (priv->dc_req) return dbus_message_new_method_return(msg); priv->dc_req = dbus_message_ref(msg); if (dev->control) { device_remove_control_timer(dev); avrcp_disconnect(dev); } if (dev->sink && priv->sink_state != SINK_STATE_DISCONNECTED) sink_shutdown(dev->sink); else if (priv->hs_state != HEADSET_STATE_DISCONNECTED) headset_shutdown(dev); else { dbus_message_unref(priv->dc_req); priv->dc_req = NULL; return dbus_message_new_method_return(msg); } return NULL; }
static unsigned int start_write_request(DBusMessage *msg, uint16_t handle, struct bt_gatt_client *gatt, const uint8_t *value, size_t value_len, void *data, async_dbus_op_complete_t complete) { struct async_dbus_op *op; unsigned int id; op = new0(struct async_dbus_op, 1); if (!op) return false; op->msg = dbus_message_ref(msg); op->data = data; op->complete = complete; id = bt_gatt_client_write_value(gatt, handle, value, value_len, write_cb, op, async_dbus_op_free); if (!id) async_dbus_op_free(op); return id; }
static DBusMessage *get_capabilities(DBusConnection *connection, DBusMessage *message, void *user_data) { struct obc_session *session = user_data; struct obc_transfer *pull; DBusMessage *reply; GError *gerr = NULL; pull = obc_transfer_get("x-obex/capability", NULL, NULL, &gerr); if (pull == NULL) goto fail; if (!obc_session_queue(session, pull, capabilities_complete_callback, message, &gerr)) goto fail; dbus_message_ref(message); return NULL; fail: reply = g_dbus_create_error(message, "org.openobex.Error.Failed", "%s", gerr->message); g_error_free(gerr); return reply; }
static DBusMessage *discover_char(DBusConnection *conn, DBusMessage *msg, void *data) { struct gatt_service *gatt = data; struct query *query; struct query_data *qchr; INFO("discovering characteristics on %s",gatt->path); query = g_new0(struct query, 1); qchr = g_new0(struct query_data, 1); qchr->gatt = gatt; query->msg = dbus_message_ref(msg); gatt->query = query; query_list_append(gatt, qchr); if (gatt->attrib == 0) { INFO("trying to connect..."); query->attioid = btd_device_add_attio_callback(gatt->dev, send_discover, cancel_discover, qchr); } else { INFO("using existing connection"); gatt_discover_char(gatt->attrib, gatt->prim->range.start, gatt->prim->range.end, NULL, char_discovered_cb, qchr); } return NULL; }
static DBusMessage *map_setpath(DBusConnection *connection, DBusMessage *message, void *user_data) { struct map_data *map = user_data; const char *folder; GError *err = NULL; if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &folder, DBUS_TYPE_INVALID) == FALSE) return g_dbus_create_error(message, ERROR_INTERFACE ".InvalidArguments", NULL); obc_session_setpath(map->session, folder, simple_cb, map, &err); if (err != NULL) { DBusMessage *reply; reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s", err->message); g_error_free(err); return reply; } map->msg = dbus_message_ref(message); return NULL; }
static DBusMessage *agent_request_browser_method(DBusConnection *dbus_cnx, DBusMessage *msg, void *data) { DBusMessageIter arg; const char *path; const char *url; if (agent_if == NULL || agent_if->browser_cb == NULL) goto error; if (dbus_message_iter_init(msg, &arg) == FALSE) goto error; if (cui_dbus_get_basic(&arg, DBUS_TYPE_OBJECT_PATH, &path) != 0) goto error; dbus_message_iter_next(&arg); if (cui_dbus_get_basic(&arg, DBUS_TYPE_STRING, &url) != 0) goto error; agent_if->pending_reply = dbus_message_ref(msg); agent_if->browser_cb(path, url); return NULL; error: return g_dbus_create_error(msg, CONNMAN_ERROR ".Canceled", NULL); }
static DBusMessage *agent_report_error_method(DBusConnection *dbus_cnx, DBusMessage *msg, void *data) { DBusMessageIter arg; const char *error; const char *path; if (agent_if == NULL || agent_if->error_cb == NULL) goto error; if (dbus_message_iter_init(msg, &arg) == FALSE) goto error; if (cui_dbus_get_basic(&arg, DBUS_TYPE_OBJECT_PATH, &path) != 0) goto error; dbus_message_iter_next(&arg); if (cui_dbus_get_basic(&arg, DBUS_TYPE_STRING, &error) != 0) goto error; agent_if->pending_reply = dbus_message_ref(msg); agent_if->error_cb(path, error); return NULL; error: return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *set_property_request(struct ofono_call_forwarding *cf, DBusMessage *msg, int type, int cls, struct ofono_phone_number *ph, int timeout) { if (ph->number[0] != '\0' && cf->driver->registration == NULL) return __ofono_error_not_implemented(msg); if (ph->number[0] == '\0' && cf->driver->erasure == NULL) return __ofono_error_not_implemented(msg); cf->pending = dbus_message_ref(msg); cf->query_next = type; cf->query_end = type; DBG("Farming off request, will be erasure: %d", ph->number[0] == '\0'); if (ph->number[0] != '\0') cf->driver->registration(cf, type, cls, ph, timeout, set_property_callback, cf); else cf->driver->erasure(cf, type, cls, set_property_callback, cf); return NULL; }
static DBusMessage *pbap_select(DBusConnection *connection, DBusMessage *message, void *user_data) { struct pbap_data *pbap = user_data; const char *item, *location; char *path = NULL; int err = 0; if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &location, DBUS_TYPE_STRING, &item, DBUS_TYPE_INVALID) == FALSE) return g_dbus_create_error(message, ERROR_INF ".InvalidArguments", NULL); path = build_phonebook_path(location, item); if (!path) return g_dbus_create_error(message, ERROR_INF ".InvalidArguments", "InvalidPhonebook"); err = pbap_set_path(pbap, path); g_free(path); if (err != G_OBEX_RSP_SUCCESS) return g_dbus_create_error(message, ERROR_INF ".Failed", "0x%02x", err); pbap->msg = dbus_message_ref(message); return NULL; }
static DBusMessage *media_folder_list_items(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_player *mp = data; struct media_folder *folder = mp->scope; struct player_callback *cb = mp->cb; DBusMessageIter iter; uint32_t start, end; int err; dbus_message_iter_init(msg, &iter); if (parse_filters(mp, &iter, &start, &end) < 0) return btd_error_invalid_args(msg); if (cb->cbs->list_items == NULL) return btd_error_not_supported(msg); if (folder->msg != NULL) return btd_error_failed(msg, strerror(EBUSY)); err = cb->cbs->list_items(mp, folder->item->name, start, end, cb->user_data); if (err < 0) return btd_error_failed(msg, strerror(-err)); folder->msg = dbus_message_ref(msg); return NULL; }
static DBusMessage *media_folder_search(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_player *mp = data; struct media_folder *folder = mp->scope; struct player_callback *cb = mp->cb; DBusMessageIter iter; const char *string; int err; dbus_message_iter_init(msg, &iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return btd_error_invalid_args(msg); dbus_message_iter_get_basic(&iter, &string); if (!mp->searchable || folder != mp->folder || !cb->cbs->search) return btd_error_not_supported(msg); if (folder->msg != NULL) return btd_error_failed(msg, strerror(EINVAL)); err = cb->cbs->search(mp, string, cb->user_data); if (err < 0) return btd_error_failed(msg, strerror(-err)); folder->msg = dbus_message_ref(msg); return NULL; }
DBusMessageRefPtr::DBusMessageRefPtr(DBusMessage* aMsg) : mMsg(aMsg) { if (mMsg) { dbus_message_ref(mMsg); } }
static DBusMessage *gnss_send_element(DBusConnection *conn, DBusMessage *msg, void *data) { const char *caller = dbus_message_get_sender(msg); struct ofono_gnss *gnss = data; const char *xml; DBG(""); if (gnss->pending) return __ofono_error_busy(msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)) return __ofono_error_invalid_args(msg); if (gnss->posr_agent == NULL) return __ofono_error_not_available(msg); if (!gnss_agent_sender_matches(gnss->posr_agent, caller)) return __ofono_error_access_denied(msg); gnss->pending = dbus_message_ref(msg); gnss->driver->send_element(gnss, xml, gnss_send_element_cb, gnss); return NULL; }
static DBusMessage *map_update_inbox(DBusConnection *connection, DBusMessage *message, void *user_data) { struct map_data *map = user_data; DBusMessage *reply; char contents[2]; struct obc_transfer *transfer; GError *err = NULL; contents[0] = FILLER_BYTE; contents[1] = '\0'; transfer = obc_transfer_put("x-bt/MAP-messageUpdate", NULL, NULL, contents, sizeof(contents), &err); if (transfer == NULL) goto fail; if (!obc_session_queue(map->session, transfer, update_inbox_cb, map, &err)) goto fail; map->msg = dbus_message_ref(message); return NULL; fail: reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s", err->message); g_error_free(err); return reply; }
static DBusMessage *map_get_message_listing(DBusConnection *connection, DBusMessage *message, void *user_data) { struct map_data *map = user_data; struct obc_transfer *transfer; const char *folder; DBusMessageIter msg_iter; GError *err = NULL; DBusMessage *reply; dbus_message_iter_init(message, &msg_iter); if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_STRING) return g_dbus_create_error(message, "org.openobex.Error.InvalidArguments", NULL); dbus_message_iter_get_basic(&msg_iter, &folder); transfer = obc_transfer_get("x-bt/MAP-msg-listing", folder, NULL, &err); if (transfer == NULL) goto fail; if (obc_session_queue(map->session, transfer, buffer_cb, map, &err)) { map->msg = dbus_message_ref(message); return NULL; } fail: reply = g_dbus_create_error(message, "org.openobex.Error.Failed", "%s", err->message); g_error_free(err); return reply; }
static DBusMessage *get_folder_listing(struct map_data *map, DBusMessage *message, GObexApparam *apparam) { struct obc_transfer *transfer; GError *err = NULL; DBusMessage *reply; transfer = obc_transfer_get("x-obex/folder-listing", NULL, NULL, &err); if (transfer == NULL) { g_obex_apparam_free(apparam); goto fail; } obc_transfer_set_apparam(transfer, apparam); if (obc_session_queue(map->session, transfer, folder_listing_cb, map, &err)) { map->msg = dbus_message_ref(message); return NULL; } fail: reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s", err->message); g_error_free(err); return reply; }
static DBusMessage *cm_acm_reset(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_call_meter *cm = data; const char *pin2; if (cm->driver->acm_reset == NULL) return __ofono_error_not_implemented(msg); if (cm->pending) return __ofono_error_busy(msg); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pin2, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); if (!__ofono_is_valid_sim_pin(pin2, OFONO_SIM_PASSWORD_SIM_PIN2)) return __ofono_error_invalid_format(msg); cm->pending = dbus_message_ref(msg); cm->driver->acm_reset(cm, pin2, acm_reset_callback, cm); return NULL; }
int __connman_technology_disable(enum connman_service_type type, DBusMessage *msg) { struct connman_technology *technology; GSList *list; int err = 0; int ret = -ENODEV; DBusMessage *reply; DBG("type %d disable", type); technology = technology_find(type); if (technology == NULL) { err = -ENXIO; goto done; } if (technology->pending_reply != NULL) { err = -EBUSY; goto done; } if (technology->tethering == TRUE) set_tethering(technology, FALSE); if (msg != NULL) { technology->enable_persistent = FALSE; save_state(technology); } __connman_rfkill_block(technology->type, TRUE); for (list = technology->device_list; list; list = list->next) { struct connman_device *device = list->data; err = __connman_device_disable(device); if (err == 0) ret = 0; } done: if (ret == 0) { if (msg != NULL) g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID); return ret; } if (msg != NULL) { if (err == -EINPROGRESS) { technology->pending_reply = dbus_message_ref(msg); technology->pending_timeout = g_timeout_add_seconds(10, technology_pending_reply, technology); } else { reply = __connman_error_failed(msg, -err); if (reply != NULL) g_dbus_send_message(connection, reply); } } return err; }
static DBusMessage *add_sdp_record(DBusConnection *conn, DBusMessage *msg, void *data) { const char *sender, *record; int err; debug("%s", __FUNCTION__); debug( "SDP: add_sdp_record conn=%p ", conn ); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) { error("SDP: error getting args"); return NULL; } debug( "SDP: add_sdp_record record=%s ", record ); sender = dbus_message_get_sender(msg); err = add_xml_record(conn, sender, record); if (err < 0) return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",strerror(err)); g_conn = dbus_connection_ref(conn); g_msg = dbus_message_ref(msg); return NULL; }
static DBusMessage *set_property_online(struct ofono_modem *modem, DBusMessage *msg, DBusMessageIter *var) { ofono_bool_t online; const struct ofono_modem_driver *driver = modem->driver; if (modem->powered == FALSE) return __ofono_error_not_available(msg); if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(var, &online); if (modem->pending != NULL) return __ofono_error_busy(msg); if (modem->online == online) return dbus_message_new_method_return(msg); if (ofono_modem_get_emergency_mode(modem) == TRUE) return __ofono_error_emergency_active(msg); if (modem_is_always_online(modem) == TRUE) return __ofono_error_not_implemented(msg); modem->pending = dbus_message_ref(msg); driver->set_online(modem, online, online ? online_cb : offline_cb, modem); return NULL; }
static DBusMessage *remove_sdp_record(DBusConnection *conn, DBusMessage *msg, void *data) { struct service_adapter *serv_adapter = data; tDTUN_METHOD_DM_REMOVE_SDP_REC_EX method; dbus_uint32_t handle; const char *sender; debug( "SDP: remove_sdp_record conn=%p", conn ); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) return NULL; sender = dbus_message_get_sender(msg); g_conn = dbus_connection_ref(conn); g_msg = dbus_message_ref(msg); memset(&method,0, sizeof(method)); method.handle = handle; method.hdr.len= sizeof(handle); method.hdr.id = DTUN_METHOD_SDP_REMOVE_RECORD; dtun_client_call_method((tDTUN_DEVICE_METHOD *)&method); return NULL; }
static DBusMessage *characteristic_read_value(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct characteristic *chrc = user_data; struct bt_gatt_client *gatt = chrc->service->client->gatt; struct async_dbus_op *op; if (chrc->read_id) return btd_error_in_progress(msg); op = new0(struct async_dbus_op, 1); if (!op) return btd_error_failed(msg, "Failed to initialize request"); op->msg = dbus_message_ref(msg); op->data = chrc; chrc->read_id = bt_gatt_client_read_value(gatt, chrc->value_handle, chrc_read_cb, async_dbus_op_ref(op), async_dbus_op_unref); if (chrc->read_id) return NULL; async_dbus_op_free(op); return btd_error_failed(msg, "Failed to send read request"); }
static DBusMessage *descriptor_read_value(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct descriptor *desc = user_data; struct bt_gatt_client *gatt = desc->chrc->service->client->gatt; struct async_dbus_op *op; if (!gatt) return btd_error_failed(msg, "Not connected"); if (desc->read_id) return btd_error_in_progress(msg); op = new0(struct async_dbus_op, 1); op->msg = dbus_message_ref(msg); op->data = desc; desc->read_id = bt_gatt_client_read_value(gatt, desc->handle, desc_read_cb, async_dbus_op_ref(op), async_dbus_op_unref); if (desc->read_id) return NULL; async_dbus_op_free(op); return btd_error_failed(msg, "Failed to send read request"); }
static DBusMessage *set_property_active(struct dundee_device *device, DBusMessage *msg, DBusMessageIter *var) { ofono_bool_t active; DBG("%p path %s", device, device->path); if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) return __dundee_error_invalid_args(msg); if (device->pending) return __dundee_error_in_progress(msg); dbus_message_iter_get_basic(var, &active); device->pending = dbus_message_ref(msg); if (active) device->driver->connect(device, connect_callback, device); else if (device->ppp) g_at_ppp_shutdown(device->ppp); return NULL; }
static DBusMessage *gnss_register_agent(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_gnss *gnss = data; const char *agent_path; if (gnss->pending) return __ofono_error_busy(msg); if (gnss->posr_agent) return __ofono_error_busy(msg); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &agent_path, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); if (!__ofono_dbus_valid_object_path(agent_path)) return __ofono_error_invalid_format(msg); gnss->posr_agent = gnss_agent_new(agent_path, dbus_message_get_sender(msg)); if (gnss->posr_agent == NULL) return __ofono_error_failed(msg); gnss_agent_set_removed_notify(gnss->posr_agent, gnss_agent_notify, gnss); gnss->driver->set_position_reporting(gnss, TRUE, gnss_register_agent_cb, gnss); gnss->pending = dbus_message_ref(msg); return NULL; }
static DBusMessage *sink_disconnect(DBusConnection *conn, DBusMessage *msg, void *data) { struct audio_device *device = data; struct sink *sink = device->sink; struct pending_request *pending; int err; if (!sink->session) return btd_error_not_connected(msg); if (sink->connect || sink->disconnect) return btd_error_busy(msg); if (sink->stream_state < AVDTP_STATE_OPEN) { DBusMessage *reply = dbus_message_new_method_return(msg); if (!reply) return NULL; avdtp_unref(sink->session); sink->session = NULL; return reply; } err = avdtp_close(sink->session, sink->stream, FALSE); if (err < 0) return btd_error_failed(msg, strerror(-err)); pending = g_new0(struct pending_request, 1); pending->conn = dbus_connection_ref(conn); pending->msg = dbus_message_ref(msg); sink->disconnect = pending; return NULL; }
static DBusMessage *gnss_unregister_agent(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_gnss *gnss = data; const char *agent_path; const char *agent_bus = dbus_message_get_sender(msg); if (gnss->pending) return __ofono_error_busy(msg); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &agent_path, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); if (gnss->posr_agent == NULL) return __ofono_error_failed(msg); if (!gnss_agent_matches(gnss->posr_agent, agent_path, agent_bus)) return __ofono_error_access_denied(msg); gnss->pending = dbus_message_ref(msg); gnss->enabled = FALSE; gnss->driver->set_position_reporting(gnss, FALSE, gnss_unregister_agent_cb, gnss); return NULL; }