Home | History | Annotate | Download | only in serial

Lines Matching refs:port

59 #include "port.h"
111 struct serial_port *port = l->data;
115 if (port->uuid && !strcasecmp(port->uuid, pattern))
116 return port;
118 if (endptr && *endptr == '\0' && port->channel == channel)
119 return port;
121 if (port->dev && !strcmp(port->dev, pattern))
122 return port;
124 if (!port->uuid)
131 ret = strcasecmp(port->uuid, uuid_str);
134 return port;
140 static int port_release(struct serial_port *port)
146 if (port->id < 0) {
147 if (port->io) {
148 g_io_channel_shutdown(port->io, TRUE, NULL);
149 g_io_channel_unref(port->io);
150 port->io = NULL;
152 bt_cancel_discovery(&port->device->src,
153 &port->device->dst);
158 DBG("Serial port %s released", port->dev);
164 if (port->fd >= 0) {
165 close(port->fd);
166 port->fd = -1;
170 req.dev_id = port->id;
182 port->dev, strerror(err), err);
185 g_free(port->dev);
186 port->dev = NULL;
187 port->id = -1;
192 static void serial_port_free(struct serial_port *port)
194 struct serial_device *device = port->device;
196 if (device && port->listener_id > 0)
197 g_dbus_remove_watch(device->conn, port->listener_id);
199 port_release(port);
201 g_free(port->uuid);
202 g_free(port);
215 struct serial_port *port = user_data;
217 port_release(port);
219 port->listener_id = 0;
239 static void open_notify(int fd, int err, struct serial_port *port)
241 struct serial_device *device = port->device;
246 port_release(port);
247 reply = btd_error_failed(port->msg, strerror(-err));
249 port->fd = fd;
250 reply = g_dbus_create_reply(port->msg,
251 DBUS_TYPE_STRING, &port->dev,
261 struct serial_port *port = user_data;
265 if (!port->listener_id)
268 fd = open(port->dev, O_RDONLY | O_NOCTTY);
272 port->dev, strerror(-err), -err);
275 open_notify(fd, err, port);
283 open_notify(fd, 0, port);
287 static int port_open(struct serial_port *port)
291 fd = open(port->dev, O_RDONLY | O_NOCTTY);
293 g_timeout_add(OPEN_WAIT, open_continue, port);
303 struct serial_port *port = user_data;
304 struct serial_device *device = port->device;
310 if (!port->listener_id)
315 reply = btd_error_failed(port->msg, conn_err->message);
324 req.channel = port->channel;
326 g_io_channel_unref(port->io);
327 port->io = NULL;
330 port->id = ioctl(sk, RFCOMMCREATEDEV, &req);
331 if (port->id < 0) {
334 reply = btd_error_failed(port->msg, strerror(-err));
339 port->dev = g_strdup_printf("/dev/rfcomm%d", port->id);
341 DBG("Serial port %s created", port->dev);
345 /* Addressing connect port */
346 fd = port_open(port);
351 open_notify(fd, 0, port);
356 g_dbus_remove_watch(device->conn, port->listener_id);
357 port->listener_id = 0;
362 struct serial_port *port = user_data;
363 struct serial_device *device = port->device;
369 if (!port->listener_id) {
377 reply = btd_error_failed(port->msg, strerror(-err));
383 reply = btd_error_failed(port->msg, "No record found");
390 error("Unable to get access protos from port record");
391 reply = btd_error_failed(port->msg, "Invalid channel");
395 port->channel = sdp_get_proto_port(protos, RFCOMM_UUID);
400 port->io = bt_io_connect(BT_IO_RFCOMM, rfcomm_connect_cb, port,
404 BT_IO_OPT_CHANNEL, port->channel,
406 if (!port->io) {
408 reply = btd_error_failed(port->msg, gerr->message);
416 g_dbus_remove_watch(device->conn, port->listener_id);
417 port->listener_id = 0;
421 static int connect_port(struct serial_port *port)
423 struct serial_device *device = port->device;
427 if (!port->uuid)
430 err = bt_string2uuid(&uuid, port->uuid);
437 get_record_cb, port, NULL);
440 port->io = bt_io_connect(BT_IO_RFCOMM, rfcomm_connect_cb, port,
444 BT_IO_OPT_CHANNEL, port->channel,
446 if (port->io)
455 struct serial_port *port;
457 port = g_new0(struct serial_port, 1);
458 port->uuid = g_strdup(uuid);
459 port->channel = channel;
460 port->device = device;
461 port->id = -1;
462 port->fd = -1;
464 device->ports = g_slist_append(device->ports, port);
466 return port;
473 struct serial_port *port;
481 port = find_port(device->ports, pattern);
482 if (!port) {
490 port = create_port(device, NULL, channel);
493 if (port->listener_id)
494 return btd_error_failed(msg, "Port already in use");
496 port->listener_id = g_dbus_add_disconnect_watch(conn,
498 port_owner_exited, port,
500 port->msg = dbus_message_ref(msg);
502 err = connect_port(port);
505 g_dbus_remove_watch(conn, port->listener_id);
506 port->listener_id = 0;
518 struct serial_port *port;
525 port = find_port(device->ports, dev);
526 if (!port)
529 if (!port->listener_id)
532 owner = dbus_message_get_sender(port->msg);
537 port_release(port);
539 g_dbus_remove_watch(conn, port->listener_id);
540 port->listener_id = 0;
583 struct serial_port *port;
596 port = g_new0(struct serial_port, 1);
597 port->uuid = g_strdup(uuid);
598 port->channel = channel;
599 port->device = device;
600 port->id = -1;
601 port->fd = -1;
603 device->ports = g_slist_append(device->ports, port);