Skip to content

Commit

Permalink
Add a way to store the remote device type
Browse files Browse the repository at this point in the history
Because we need to know the device type (LE, Basic Rate or Dual Mode)
to be able to fully restore the device from storage, we have to store
and load this information to permanent storage.

Note: due to "device_type_t" usage in storage.h, some header includes
needed to be reordered in files which include storage.h.
  • Loading branch information
vcgomes authored and Johan Hedberg committed Dec 22, 2010
1 parent 5f44369 commit 50fb53c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions input/device.c
Expand Up @@ -46,11 +46,11 @@
#include "textfile.h"
#include "uinput.h"

#include "../src/storage.h"
#include "../src/adapter.h"
#include "../src/device.h"
#include "../src/storage.h"
#include "../src/manager.h"
#include "../src/dbus-common.h"
#include "../src/device.h"

#include "device.h"
#include "error.h"
Expand Down
2 changes: 1 addition & 1 deletion plugins/hciops.c
Expand Up @@ -41,11 +41,11 @@
#include "hcid.h"
#include "sdpd.h"
#include "adapter.h"
#include "device.h"
#include "plugin.h"
#include "log.h"
#include "storage.h"
#include "event.h"
#include "device.h"
#include "manager.h"

static int child_pipe[2] = { -1, -1 };
Expand Down
2 changes: 2 additions & 0 deletions serial/port.c
Expand Up @@ -53,6 +53,8 @@

#include "error.h"
#include "manager.h"
#include "adapter.h"
#include "device.h"
#include "storage.h"
#include "port.h"

Expand Down
40 changes: 40 additions & 0 deletions src/storage.c
Expand Up @@ -45,6 +45,8 @@
#include <bluetooth/sdp_lib.h>

#include "textfile.h"
#include "adapter.h"
#include "device.h"
#include "glib-helper.h"
#include "storage.h"

Expand Down Expand Up @@ -1391,3 +1393,41 @@ int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data)

return textfile_foreach(filename, func, data);
}

int write_device_type(const bdaddr_t *sba, const bdaddr_t *dba,
device_type_t type)
{
char filename[PATH_MAX + 1], addr[18], chars[3];

create_filename(filename, PATH_MAX, sba, "types");

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

ba2str(dba, addr);

snprintf(chars, sizeof(chars), "%2.2X", type);

return textfile_put(filename, addr, chars);
}

device_type_t read_device_type(const bdaddr_t *sba, const bdaddr_t *dba)
{
char filename[PATH_MAX + 1], addr[18], *chars;
device_type_t type;

create_filename(filename, PATH_MAX, sba, "types");

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

ba2str(dba, addr);

chars = textfile_caseget(filename, addr);
if (chars == NULL)
return DEVICE_TYPE_UNKNOWN;

type = strtol(chars, NULL, 16);

free(chars);

return type;
}
3 changes: 3 additions & 0 deletions src/storage.h
Expand Up @@ -91,6 +91,9 @@ char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
int write_device_attribute(const bdaddr_t *sba, const bdaddr_t *dba,
uint16_t handle, const char *chars);
int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data);
int write_device_type(const bdaddr_t *sba, const bdaddr_t *dba,
device_type_t type);
device_type_t read_device_type(const bdaddr_t *sba, const bdaddr_t *dba);

#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb"

0 comments on commit 50fb53c

Please sign in to comment.