diff options
Diffstat (limited to 'serial')
-rw-r--r-- | serial/manager.c | 15 | ||||
-rw-r--r-- | serial/port.c | 32 | ||||
-rw-r--r-- | serial/port.h | 2 | ||||
-rw-r--r-- | serial/serial-api.txt | 5 |
4 files changed, 43 insertions, 11 deletions
diff --git a/serial/manager.c b/serial/manager.c index 371c8a95..378434e4 100644 --- a/serial/manager.c +++ b/serial/manager.c @@ -559,10 +559,12 @@ static void record_reply(DBusPendingCall *call, void *data) } port_store(&pc->src, &dst, err, ch, svcname); + + port_register(pc->conn, err, &pc->src, &dst, port_name, + path, svcname); if (svcname) g_free(svcname); - 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 +842,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, &src, &dst, port_name, path); + port_register(conn, err, &src, &dst, port_name, path, NULL); ports_paths = g_slist_append(ports_paths, g_strdup(path)); reply = dbus_message_new_method_return(msg); @@ -2144,7 +2146,7 @@ static DBusSignalVTable manager_signals[] = { static void parse_port(char *key, char *value, void *data) { - char path[MAX_PATH_LENGTH], port_name[16], dst_addr[18]; + char path[MAX_PATH_LENGTH], port_name[16], dst_addr[18], *svc; char *src_addr = data; bdaddr_t dst, src; int ch, id; @@ -2156,6 +2158,10 @@ static void parse_port(char *key, char *value, void *data) if (sscanf(value,"%d:", &ch) != 1) return; + svc = strchr(value, ':'); + if (svc && *svc) + svc++; + str2ba(dst_addr, &dst); str2ba(src_addr, &src); @@ -2164,7 +2170,8 @@ 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, &src, &dst, port_name, path) < 0) { + if (port_register(connection, id, &src, &dst, + port_name, path, svc) < 0) { rfcomm_release(id); return; } diff --git a/serial/port.c b/serial/port.c index 70e0afb4..30b1412e 100644 --- a/serial/port.c +++ b/serial/port.c @@ -55,6 +55,7 @@ struct rfcomm_node { int16_t id; /* RFCOMM device id */ bdaddr_t src; /* Source (local) address */ bdaddr_t dst; /* Destination address */ + char *svcname; /* RFCOMM service name */ char *device; /* RFCOMM device name */ DBusConnection *conn; /* for name listener handling */ char *owner; /* Bus name */ @@ -162,6 +163,21 @@ static DBusHandlerResult port_get_name(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult port_get_service_name(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct rfcomm_node *node = data; + DBusMessage *reply; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_append_args(reply, + DBUS_TYPE_STRING, &node->svcname, + DBUS_TYPE_INVALID); + return send_message_and_unref(conn, reply); +} static DBusHandlerResult port_get_info(DBusConnection *conn, DBusMessage *msg, void *data) @@ -196,11 +212,12 @@ 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}" }, + { "GetAddress", port_get_address, "", "s" }, + { "GetDevice", port_get_device, "", "s" }, + { "GetAdapter", port_get_adapter, "", "s" }, + { "GetName", port_get_name, "", "s" }, + { "GetServiceName", port_get_service_name, "", "s" }, + { "GetInfo", port_get_info, "", "{sv}" }, { NULL, NULL, NULL, NULL }, }; @@ -216,6 +233,8 @@ static void rfcomm_node_free(struct rfcomm_node *node) dbus_connection_unref(node->conn); if (node->owner) g_free(node->owner); + if (node->svcname) + g_free(node->svcname); if (node->io) { g_source_remove(node->io_id); g_io_channel_close(node->io); @@ -310,7 +329,7 @@ int port_remove_listener(const char *owner, const char *dev) } int port_register(DBusConnection *conn, int16_t id, bdaddr_t *src, - bdaddr_t *dst, const char *dev, char *ppath) + bdaddr_t *dst, const char *dev, char *ppath, const char *svc) { char path[MAX_PATH_LENGTH]; struct rfcomm_node *node; @@ -321,6 +340,7 @@ int port_register(DBusConnection *conn, int16_t id, bdaddr_t *src, node->id = id; node->device = g_strdup(dev); node->conn = dbus_connection_ref(conn); + node->svcname = g_strdup(svc?:"Bluetooth RFCOMM port"); snprintf(path, MAX_PATH_LENGTH, "%s/rfcomm%hd", SERIAL_MANAGER_PATH, id); diff --git a/serial/port.h b/serial/port.h index 5935bef3..ad6f4fa8 100644 --- a/serial/port.h +++ b/serial/port.h @@ -27,6 +27,6 @@ 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 *src, - bdaddr_t *dst, const char *dev, char *ppath); + bdaddr_t *dst, const char *dev, char *ppath, const char *svc); int port_unregister(const char *path); diff --git a/serial/serial-api.txt b/serial/serial-api.txt index 20a94e51..e8431ded 100644 --- a/serial/serial-api.txt +++ b/serial/serial-api.txt @@ -122,6 +122,11 @@ Methods string GetAdapter() [experimental] Returns the name of the remote device. + string GetServiceName() + + Returns the name of the remote service. + e.g.: "Dial-up networking Gateway" + Proxy hierarchy (experimental) ============================= Interface org.bluez.serial.Proxy |