summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-09-26 13:58:19 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-09-26 13:58:19 +0000
commit4c18c3e4ffbd0bb6eeb7d0933acadc2f8200587b (patch)
tree54a51289c708ce0298445aa48abf82233cf74ad3
parent90e08a3db079ce84c9f49f46c48ef7c4b757a2e4 (diff)
serial: Added GetName and GetAdapter
-rw-r--r--serial/manager.c6
-rw-r--r--serial/port.c59
-rw-r--r--serial/port.h4
-rw-r--r--serial/serial-api.txt10
-rw-r--r--serial/storage.c35
-rw-r--r--serial/storage.h1
6 files changed, 106 insertions, 9 deletions
diff --git a/serial/manager.c b/serial/manager.c
index 36af5523..371c8a95 100644
--- a/serial/manager.c
+++ b/serial/manager.c
@@ -562,7 +562,7 @@ static void record_reply(DBusPendingCall *call, void *data)
if (svcname)
g_free(svcname);
- port_register(pc->conn, err, &dst, port_name, path);
+ port_register(pc->conn, err, &pc->src, &dst, port_name, path);
ports_paths = g_slist_append(ports_paths, g_strdup(path));
reply = dbus_message_new_method_return(pc->msg);
@@ -840,7 +840,7 @@ static DBusHandlerResult create_port(DBusConnection *conn,
snprintf(port_name, sizeof(port_name), "/dev/rfcomm%d", err);
port_store(&src, &dst, err, val, NULL);
- port_register(conn, err, &dst, port_name, path);
+ port_register(conn, err, &src, &dst, port_name, path);
ports_paths = g_slist_append(ports_paths, g_strdup(path));
reply = dbus_message_new_method_return(msg);
@@ -2164,7 +2164,7 @@ static void parse_port(char *key, char *value, void *data)
snprintf(port_name, sizeof(port_name), "/dev/rfcomm%d", id);
- if (port_register(connection, id, &dst, port_name, path) < 0) {
+ if (port_register(connection, id, &src, &dst, port_name, path) < 0) {
rfcomm_release(id);
return;
}
diff --git a/serial/port.c b/serial/port.c
index e4048256..70e0afb4 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -30,6 +30,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -46,12 +47,13 @@
#include "error.h"
#include "manager.h"
-#include "port.h"
+#include "storage.h"
#define SERIAL_PORT_INTERFACE "org.bluez.serial.Port"
struct rfcomm_node {
int16_t id; /* RFCOMM device id */
+ bdaddr_t src; /* Source (local) address */
bdaddr_t dst; /* Destination address */
char *device; /* RFCOMM device name */
DBusConnection *conn; /* for name listener handling */
@@ -113,6 +115,54 @@ static DBusHandlerResult port_get_device(DBusConnection *conn,
}
+static DBusHandlerResult port_get_adapter(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct rfcomm_node *node = data;
+ DBusMessage *reply;
+ char addr[18];
+ const char *paddr = addr;
+
+ ba2str(&node->src, addr);
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply,
+ DBUS_TYPE_STRING, &paddr,
+ DBUS_TYPE_INVALID);
+
+ return send_message_and_unref(conn, reply);
+}
+
+
+static DBusHandlerResult port_get_name(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct rfcomm_node *node = data;
+ DBusMessage *reply;
+ const char *pname;
+ char *name = NULL;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ read_device_name(&node->src, &node->dst, &name);
+
+ pname = (name ? name : "");
+ dbus_message_append_args(reply,
+ DBUS_TYPE_STRING, &pname,
+ DBUS_TYPE_INVALID);
+
+ if (name)
+ g_free(name);
+
+ return send_message_and_unref(conn, reply);
+}
+
+
static DBusHandlerResult port_get_info(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -148,6 +198,8 @@ static DBusHandlerResult port_get_info(DBusConnection *conn,
static DBusMethodVTable port_methods[] = {
{ "GetAddress", port_get_address, "", "s" },
{ "GetDevice", port_get_device, "", "s" },
+ { "GetAdapter", port_get_adapter, "", "s" },
+ { "GetName", port_get_name, "", "s" },
{ "GetInfo", port_get_info, "", "{sv}" },
{ NULL, NULL, NULL, NULL },
};
@@ -257,14 +309,15 @@ int port_remove_listener(const char *owner, const char *dev)
return 0;
}
-int port_register(DBusConnection *conn, int16_t id, bdaddr_t *dst,
- const char *dev, char *ppath)
+int port_register(DBusConnection *conn, int16_t id, bdaddr_t *src,
+ bdaddr_t *dst, const char *dev, char *ppath)
{
char path[MAX_PATH_LENGTH];
struct rfcomm_node *node;
node = g_new0(struct rfcomm_node, 1);
bacpy(&node->dst, dst);
+ bacpy(&node->src, src);
node->id = id;
node->device = g_strdup(dev);
node->conn = dbus_connection_ref(conn);
diff --git a/serial/port.h b/serial/port.h
index c0b9073d..5935bef3 100644
--- a/serial/port.h
+++ b/serial/port.h
@@ -26,7 +26,7 @@ int port_add_listener(DBusConnection *conn, int16_t id, bdaddr_t *dst,
int port_remove_listener(const char *owner, const char *dev);
-int port_register(DBusConnection *conn, int16_t id, bdaddr_t *dst,
- const char *dev, char *ppath);
+int port_register(DBusConnection *conn, int16_t id, bdaddr_t *src,
+ bdaddr_t *dst, const char *dev, char *ppath);
int port_unregister(const char *path);
diff --git a/serial/serial-api.txt b/serial/serial-api.txt
index 5ac7091a..20a94e51 100644
--- a/serial/serial-api.txt
+++ b/serial/serial-api.txt
@@ -102,7 +102,11 @@ Port hierarchy (experimental)
Interface org.bluez.serial.Port
Object path /org/bluez/serial/rfcomm*
-Methods string GetAddress() [experimental]
+Methods string GetAdapter() [experimental]
+
+ Returns the adapter address.
+
+ string GetAddress() [experimental]
Returns the Bluetooth address of the ending point.
@@ -114,6 +118,10 @@ Methods string GetAddress() [experimental]
Returns the port properties.
+ string GetName()
+
+ Returns the name of the remote device.
+
Proxy hierarchy (experimental)
=============================
Interface org.bluez.serial.Proxy
diff --git a/serial/storage.c b/serial/storage.c
index 110d8de7..6ea3eb41 100644
--- a/serial/storage.c
+++ b/serial/storage.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <errno.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
@@ -133,3 +134,37 @@ done:
return err;
}
+
+int read_device_name(bdaddr_t *src, bdaddr_t *dst, char **name)
+{
+ char filename[PATH_MAX + 1], *str;
+ char src_addr[18], dst_addr[18];
+ int len;
+
+ ba2str(src, src_addr);
+ ba2str(dst, dst_addr);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "names");
+
+ str = textfile_get(filename, dst_addr);
+ if (!str)
+ return -ENOENT;
+
+ len = strlen(str);
+
+ /* Max remote device name */
+ if (len < 248) {
+ *name = str;
+ return 0;
+ }
+
+ *name = g_try_malloc0(248);
+ if (!*name)
+ return -ENOMEM;
+
+ snprintf(*name, 248, "%s", str);
+
+ free(str);
+
+ return 0;
+}
diff --git a/serial/storage.h b/serial/storage.h
index 4a24bdf7..271ae722 100644
--- a/serial/storage.h
+++ b/serial/storage.h
@@ -27,3 +27,4 @@ int port_store(bdaddr_t *src, bdaddr_t *dst, int16_t id,
int proxy_delete(bdaddr_t *src, const char *tty);
int proxy_store(bdaddr_t *src, const char *uuid, const char *tty,
const char *name, uint8_t ch, int opts, struct termios *ti);
+int read_device_name(bdaddr_t *src, bdaddr_t *dst, char **name);