Example #1
0
static void parse_proxy(char *key, char *value, void *data)
{
    struct serial_adapter *adapter = data;
    char uuid128[MAX_LEN_UUID_STR], tmp[3];
    char *pvalue;
    proxy_type_t type;
    unsigned int pos;
    int ch, opts;
    struct termios ti;
    uint8_t *pti;

    memset(uuid128, 0, sizeof(uuid128));
    ch = opts = pos = 0;
    if (sscanf(value,"%s %d 0x%04X %n", uuid128, &ch, &opts, &pos) != 3)
        return;

    /* Extracting name */
    value += pos;
    pvalue = strchr(value, ':');
    if (!pvalue)
        return;

    /* FIXME: currently name is not used */
    *pvalue = '\0';

    type = addr2type(key);
    switch (type) {
    case TTY_PROXY:
        /* Extracting termios */
        pvalue++;
        if (!pvalue || strlen(pvalue) != (2 * sizeof(ti)))
            return;

        memset(&ti, 0, sizeof(ti));
        memset(tmp, 0, sizeof(tmp));

        /* Converting to termios struct */
        pti = (uint8_t *) &ti;
        for (pos = 0; pos < sizeof(ti); pos++, pvalue += 2, pti++) {
            memcpy(tmp, pvalue, 2);
            *pti = (uint8_t) strtol(tmp, NULL, 16);
        }

        proxy_tty_register(adapter, uuid128, key, &ti, NULL, 0, FALSE);
        break;
    case UNIX_SOCKET_PROXY:
        proxy_socket_register(adapter, uuid128, key, NULL, 0, FALSE);
        break;
    case TCP_SOCKET_PROXY:
        proxy_tcp_register(adapter, uuid128, key, NULL, 0, FALSE);
        break;
    default:
        return;
    }
}
Example #2
0
static int register_proxy(struct serial_adapter *adapter,
				const char *uuid_str, const char *address,
				struct serial_proxy **proxy)
{
	proxy_type_t type;
	int err;

	type = addr2type(address);
	if (type == UNKNOWN_PROXY_TYPE)
		return -EINVAL;

	/* Only one proxy per address(TTY or unix socket) is allowed */
	if (g_slist_find_custom(adapter->proxies, address, proxy_addrcmp))
		return -EALREADY;

	switch (type) {
	case UNIX_SOCKET_PROXY:
		err = proxy_socket_register(adapter, uuid_str, address, proxy);
		break;
	case TTY_PROXY:
		err = proxy_tty_register(adapter, uuid_str, address, NULL,
					proxy);
		break;
	case TCP_SOCKET_PROXY:
		err = proxy_tcp_register(adapter, uuid_str, address, proxy);
		break;
	default:
		err = -EINVAL;
	}

	if (err < 0)
		return err;

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

	return 0;
}
Example #3
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);
}