summaryrefslogtreecommitdiffstats
path: root/serial
diff options
context:
space:
mode:
Diffstat (limited to 'serial')
-rw-r--r--serial/manager.c31
-rw-r--r--serial/storage.c40
-rw-r--r--serial/storage.h3
3 files changed, 65 insertions, 9 deletions
diff --git a/serial/manager.c b/serial/manager.c
index 73485382..86f5255f 100644
--- a/serial/manager.c
+++ b/serial/manager.c
@@ -49,6 +49,7 @@
#include "error.h"
#include "port.h"
+#include "storage.h"
#include "manager.h"
#define BASE_UUID "00000000-0000-1000-8000-00805F9B34FB"
@@ -366,7 +367,7 @@ static void record_reply(DBusPendingCall *call, void *data)
{
struct pending_connect *pc = data;
DBusMessage *reply = dbus_pending_call_steal_reply(call);
- sdp_record_t *rec;
+ sdp_record_t *rec = NULL;
const uint8_t *rec_bin;
sdp_list_t *protos;
DBusError derr;
@@ -414,7 +415,6 @@ static void record_reply(DBusPendingCall *call, void *data)
}
if (len != scanned || (sdp_get_access_protos(rec, &protos) < 0)) {
- sdp_record_free(rec);
err_not_supported(pc->conn, pc->msg);
goto fail;
}
@@ -423,18 +423,17 @@ static void record_reply(DBusPendingCall *call, void *data)
sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
sdp_list_free(protos, NULL);
- sdp_record_free(rec);
-
if (ch < 1 || ch > 30) {
error("Channel out of range: %d", ch);
err_not_supported(pc->conn, pc->msg);
goto fail;
}
-
if (dbus_message_has_member(pc->msg, "CreatePort")) {
char path[MAX_PATH_LENGTH];
char port_name[16];
const char *ppath = path;
+ sdp_data_t *d;
+ char *svcname = NULL;
DBusMessage *reply;
bdaddr_t dst;
@@ -444,8 +443,19 @@ static void record_reply(DBusPendingCall *call, void *data)
err_failed(pc->conn, pc->msg, strerror(-err));
goto fail;
}
-
snprintf(port_name, sizeof(port_name), "/dev/rfcomm%d", err);
+
+ d = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY);
+ if (d) {
+ svcname = g_new0(char, d->unitSize);
+ snprintf(svcname, d->unitSize, "%.*s",
+ d->unitSize, d->val.str);
+ }
+
+ port_store(&pc->src, &dst, err, ch, svcname);
+ if (svcname)
+ g_free(svcname);
+
port_register(pc->conn, err, &dst, port_name, path);
reply = dbus_message_new_method_return(pc->msg);
@@ -469,14 +479,16 @@ static void record_reply(DBusPendingCall *call, void *data)
}
/* Wait the connect callback */
- dbus_message_unref(reply);
- return;
+ goto done;
}
fail:
- dbus_message_unref(reply);
pending_connects = g_slist_remove(pending_connects, pc);
pending_connect_free(pc);
+done:
+ if (rec)
+ sdp_record_free(rec);
+ dbus_message_unref(reply);
}
static int get_record(struct pending_connect *pc, uint32_t handle,
@@ -721,6 +733,7 @@ static DBusHandlerResult create_port(DBusConnection *conn,
return err_failed(conn, msg, strerror(-err));
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);
reply = dbus_message_new_method_return(msg);
diff --git a/serial/storage.c b/serial/storage.c
index bf885407..0b599247 100644
--- a/serial/storage.c
+++ b/serial/storage.c
@@ -25,4 +25,44 @@
#include <config.h>
#endif
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include <bluetooth/bluetooth.h>
+
+#include <glib.h>
+
+#include "logging.h"
+#include "textfile.h"
+
#include "storage.h"
+
+int port_store(bdaddr_t *src, bdaddr_t *dst, int id,
+ uint8_t ch, const char *svcname)
+{
+ char filename[PATH_MAX + 1];
+ char src_addr[18], dst_addr[18];
+ char key[32];
+ char *value;
+ int size, err;
+
+ if (!svcname)
+ svcname = "Bluetooth RFCOMM port";
+
+ ba2str(src, src_addr);
+ ba2str(dst, dst_addr);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "serial");
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ size = strlen(svcname) + 3;
+ value = g_malloc0(size);
+
+ snprintf(key, 32, "%s#%d", dst_addr, id);
+ snprintf(value, size, "%d:%s", ch, svcname);
+
+ err = textfile_put(filename, key, value);
+ g_free(value);
+
+ return err;
+}
diff --git a/serial/storage.h b/serial/storage.h
index e87dd676..82512c90 100644
--- a/serial/storage.h
+++ b/serial/storage.h
@@ -20,3 +20,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
+int port_store(bdaddr_t *src, bdaddr_t *dst, int id,
+ uint8_t ch, const char *svcname);