Example #1
0
static DBusMessage *proxy_set_serial_params(DBusConnection *conn,
        DBusMessage *msg, void *data)
{
    struct serial_proxy *prx = data;
    const char *ratestr, *paritystr;
    uint8_t databits, stopbits;
    tcflag_t ctrl;		/* Control mode flags */
    speed_t speed = B0;	/* In/Out speed */

    /* Don't allow change TTY settings if it is open */
    if (prx->local)
        return failed(msg, "Not allowed");

    if (!dbus_message_get_args(msg, NULL,
                               DBUS_TYPE_STRING, &ratestr,
                               DBUS_TYPE_BYTE, &databits,
                               DBUS_TYPE_BYTE, &stopbits,
                               DBUS_TYPE_STRING, &paritystr,
                               DBUS_TYPE_INVALID))
        return NULL;

    if (str2speed(ratestr, &speed)  == B0)
        return invalid_arguments(msg, "Invalid baud rate");

    ctrl = prx->proxy_ti.c_cflag;
    if (set_databits(databits, &ctrl) < 0)
        return invalid_arguments(msg, "Invalid data bits");

    if (set_stopbits(stopbits, &ctrl) < 0)
        return invalid_arguments(msg, "Invalid stop bits");

    if (set_parity(paritystr, &ctrl) < 0)
        return invalid_arguments(msg, "Invalid parity");

    prx->proxy_ti.c_cflag = ctrl;
    prx->proxy_ti.c_cflag |= (CLOCAL | CREAD);
    cfsetispeed(&prx->proxy_ti, speed);
    cfsetospeed(&prx->proxy_ti, speed);

    proxy_store(&prx->src, prx->uuid128, prx->address, NULL,
                prx->channel, 0, &prx->proxy_ti);

    return dbus_message_new_method_return(msg);
}
Example #2
0
static DBusMessage *create_proxy(DBusConnection *conn,
				DBusMessage *msg, void *data)
{
	struct serial_adapter *adapter = data;
	struct serial_proxy *proxy;
	const char *pattern, *address;
	char *uuid_str;
	int err;

	if (!dbus_message_get_args(msg, NULL,
				DBUS_TYPE_STRING, &pattern,
				DBUS_TYPE_STRING, &address,
				DBUS_TYPE_INVALID))
		return NULL;

	uuid_str = bt_name2string(pattern);
	if (!uuid_str)
		return invalid_arguments(msg, "Invalid UUID");

	err = register_proxy(adapter, uuid_str, address, &proxy);
	g_free(uuid_str);

	if (err == -EINVAL)
		return invalid_arguments(msg, "Invalid address");
	else if (err == -EALREADY)
		return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyExist",
						"Proxy already exists");
	else if (err < 0)
		return g_dbus_create_error(msg, ERROR_INTERFACE "Failed",
				"Proxy creation failed (%s)", strerror(-err));

	proxy->owner = g_strdup(dbus_message_get_sender(msg));
	proxy->watch = g_dbus_add_disconnect_watch(conn, proxy->owner,
						watch_proxy,
						proxy, NULL);

	return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &proxy->path,
					DBUS_TYPE_INVALID);
}
Example #3
0
static DBusMessage *update_xml_record(DBusConnection *conn,
				DBusMessage *msg,
				struct service_adapter *serv_adapter)
{
	struct record_data *user_record;
	sdp_record_t *sdp_record;
	const char *record;
	dbus_uint32_t handle;
	int len;

	if (dbus_message_get_args(msg, NULL,
				DBUS_TYPE_UINT32, &handle,
				DBUS_TYPE_STRING, &record,
				DBUS_TYPE_INVALID) == FALSE)
		return NULL;

	len = (record ? strlen(record) : 0);
	if (len == 0)
		return invalid_arguments(msg);

	user_record = find_record(serv_adapter, handle,
				dbus_message_get_sender(msg));
	if (!user_record)
		return g_dbus_create_error(msg,
				ERROR_INTERFACE ".NotAvailable",
				"Not Available");

	sdp_record = sdp_xml_parse_record(record, len);
	if (!sdp_record) {
		error("Parsing of XML service record failed");
		sdp_record_free(sdp_record);
		return g_dbus_create_error(msg,
				ERROR_INTERFACE ".Failed",
				strerror(EIO));
	}

	return update_record(conn, msg, serv_adapter, handle, sdp_record);
}
Example #4
0
static DBusMessage *create_proxy(DBusConnection *conn,
                                 DBusMessage *msg, void *data)
{
    struct serial_adapter *adapter = data;
    char path[MAX_PATH_LENGTH + 1];
    const char *pattern, *address, *ppath = path;
    char *uuid_str;
    proxy_type_t type;
    uuid_t uuid;
    int ret;

    if (!dbus_message_get_args(msg, NULL,
                               DBUS_TYPE_STRING, &pattern,
                               DBUS_TYPE_STRING, &address,
                               DBUS_TYPE_INVALID))
        return NULL;

    uuid_str = bt_name2string(pattern);
    if (!uuid_str)
        return invalid_arguments(msg, "Invalid UUID");

    bt_string2uuid(&uuid, uuid_str);

    type = addr2type(address);
    if (type == UNKNOWN_PROXY_TYPE) {
        g_free(uuid_str);
        return invalid_arguments(msg, "Invalid address");
    }

    /* Only one proxy per address(TTY or unix socket) is allowed */
    if (g_slist_find_custom(adapter->proxies, address, proxy_addrcmp)) {
        g_free(uuid_str);
        return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyExist",
                                   "Proxy already exists");
    }

    switch (type) {
    case UNIX_SOCKET_PROXY:
        ret = proxy_socket_register(adapter, uuid_str, address,
                                    path, sizeof(path), TRUE);
        break;
    case TTY_PROXY:
        ret = proxy_tty_register(adapter, uuid_str, address,
                                 NULL, path, sizeof(path), TRUE);
        break;
    case TCP_SOCKET_PROXY:
        ret = proxy_tcp_register(adapter, uuid_str, address,
                                 path, sizeof(path), TRUE);
        break;
    default:
        ret = -1;
    }

    g_free(uuid_str);

    if (ret < 0)
        return failed(msg, "Create object path failed");

    g_dbus_emit_signal(adapter->conn,
                       adapter_get_path(adapter->btd_adapter),
                       SERIAL_MANAGER_INTERFACE, "ProxyCreated",
                       DBUS_TYPE_STRING, &ppath,
                       DBUS_TYPE_INVALID);

    return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &ppath,
                               DBUS_TYPE_INVALID);
}