Пример #1
0
static int
hid_known(bdaddr_t *bdaddr, int argc, char **argv)
{
	struct hid_device	*hd = NULL;
	struct hostent		*he = NULL;
	int			 e = FAILED;

	if (read_config_file() == 0) {
		if (read_hids_file() == 0) {
			e = OK;

			for (hd = get_next_hid_device(hd);
			     hd != NULL;
			     hd = get_next_hid_device(hd)) {
				if (hd->new_device)
					continue;

				he = bt_gethostbyaddr((char *) &hd->bdaddr,
						sizeof(hd->bdaddr),
						AF_BLUETOOTH);

				fprintf(stdout,
"%s %s\n",				bt_ntoa(&hd->bdaddr, NULL),
					(he != NULL && he->h_name != NULL)?
						he->h_name : "");
			}
		}

		clean_config();
	}

	return (e);
}
Пример #2
0
int32_t
client_rescan(bthid_server_p srv)
{
	static hid_device_p	d;
	bthid_session_p		s;

	assert(srv != NULL);

	if (connect_in_progress)
		return (0); /* another connect is still pending */ 

	d = get_next_hid_device(d);
	if (d == NULL)
		return (0); /* XXX should not happen? empty config? */

	if ((s = session_by_bdaddr(srv, &d->bdaddr)) != NULL)
		return (0); /* session already active */

	if (!d->new_device) {
		if (d->reconnect_initiate)
			return (0); /* device will initiate reconnect */
	}

	syslog(LOG_NOTICE, "Opening outbound session for %s " \
		"(new_device=%d, reconnect_initiate=%d)",
		bt_ntoa(&d->bdaddr, NULL), d->new_device, d->reconnect_initiate);

	if ((s = session_open(srv, d)) == NULL) {
		syslog(LOG_CRIT, "Could not create outbound session for %s",
			bt_ntoa(&d->bdaddr, NULL));
		return (-1);
	}

	/* Open control channel */
	s->ctrl = client_socket(&s->bdaddr, d->control_psm);
	if (s->ctrl < 0) {
		syslog(LOG_ERR, "Could not open control channel to %s. %s (%d)",
			bt_ntoa(&s->bdaddr, NULL), strerror(errno), errno);
		session_close(s);
		return (-1);
	}

	s->state = W4CTRL;

	FD_SET(s->ctrl, &srv->wfdset);
	if (s->ctrl > srv->maxfd)
		srv->maxfd = s->ctrl;

	connect_in_progress = 1;

	return (0);
}