diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-08-30 09:54:27 -0300 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-09-01 17:23:27 -0300 |
commit | 676f5e7dea3c6c160ffdf08d42bf83e72a5a6c3f (patch) | |
tree | 1eafa357750c5c25070d76b66b09cad19a50fd2c /src | |
parent | 75c562d773e5fe37f4257631318d7f918edc5b53 (diff) |
Adapter initialization cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/adapter.c | 61 | ||||
-rw-r--r-- | src/hcid.h | 59 | ||||
-rw-r--r-- | src/main.c | 304 | ||||
-rw-r--r-- | src/storage.c | 8 | ||||
-rw-r--r-- | src/storage.h | 4 |
5 files changed, 130 insertions, 306 deletions
diff --git a/src/adapter.c b/src/adapter.c index a16d1a4b..786c4953 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -436,8 +436,8 @@ static DBusMessage *set_mode(DBusConnection *conn, DBusMessage *msg, return no_such_adapter(msg); if (!adapter->up && - (hcid.offmode == HCID_OFFMODE_NOSCAN || - (hcid.offmode == HCID_OFFMODE_DEVDOWN && + (main_opts.offmode == HCID_OFFMODE_NOSCAN || + (main_opts.offmode == HCID_OFFMODE_DEVDOWN && scan_enable != SCAN_DISABLED))) { /* Start HCI device */ if (ioctl(dd, HCIDEVUP, adapter->dev_id) == 0) @@ -454,7 +454,7 @@ static DBusMessage *set_mode(DBusConnection *conn, DBusMessage *msg, } if (adapter->up && scan_enable == SCAN_DISABLED && - hcid.offmode == HCID_OFFMODE_DEVDOWN) { + main_opts.offmode == HCID_OFFMODE_DEVDOWN) { if (ioctl(dd, HCIDEVDOWN, adapter->dev_id) < 0) { hci_close_dev(dd); return failed_strerror(msg, errno); @@ -1354,7 +1354,7 @@ static DBusMessage *adapter_discover_devices(DBusConnection *conn, if ((adapter->state & STD_INQUIRY) || (adapter->state & PERIODIC_INQUIRY)) goto done; - if (default_device.inqmode) + if (main_opts.inqmode) err = start_inquiry(adapter); else err = start_periodic_inquiry(adapter); @@ -2236,22 +2236,61 @@ static void load_drivers(struct adapter *adapter) } } +static int get_discoverable_timeout(const char *src) +{ + int timeout; + + if (read_discoverable_timeout(src, &timeout) == 0) + return timeout; + + return main_opts.discovto; +} + static void adapter_up(struct adapter *adapter, int dd) { struct hci_conn_list_req *cl = NULL; struct hci_conn_info *ci; - const char *mode; + const char *pmode; + char mode[14]; int i; adapter->up = 1; - adapter->discov_timeout = get_discoverable_timeout(adapter->dev_id); + adapter->discov_timeout = get_discoverable_timeout(adapter->address); adapter->state = DISCOVER_TYPE_NONE; - adapter->scan_mode = get_startup_scan(adapter->dev_id); + /* Set scan mode */ + if (read_device_mode(adapter->address, mode, sizeof(mode)) == 0) { + if (!strcmp(mode, "off") && main_opts.offmode == HCID_OFFMODE_NOSCAN) { + adapter->mode = MODE_OFF; + adapter->scan_mode= SCAN_DISABLED; + } else if (!strcmp(mode, "connectable")) { + adapter->mode = MODE_CONNECTABLE; + adapter->scan_mode = SCAN_PAGE; + } else if (!strcmp(mode, "discoverable")) { + /* Set discoverable only if timeout is 0 */ + if (adapter->discov_timeout == 0) { + adapter->mode = MODE_DISCOVERABLE; + adapter->scan_mode = SCAN_PAGE | SCAN_INQUIRY; + } else { + adapter->mode = MODE_CONNECTABLE; + adapter->scan_mode = SCAN_PAGE; + } + } else if (!strcmp(mode, "limited")) { + /* Set discoverable only if timeout is 0 */ + if (adapter->discov_timeout == 0) { + adapter->mode = MODE_LIMITED; + adapter->scan_mode = SCAN_PAGE | SCAN_INQUIRY; + } else { + adapter->mode = MODE_CONNECTABLE; + adapter->scan_mode = SCAN_PAGE; + + } + } + } + hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE, 1, &adapter->scan_mode); - adapter->mode = get_startup_mode(adapter->dev_id); if (adapter->mode == MODE_LIMITED) set_limited_discoverable(dd, adapter->dev.class, TRUE); @@ -2273,11 +2312,11 @@ static void adapter_up(struct adapter *adapter, int dd) } g_free(cl); - mode = mode2str(adapter->mode); + pmode = mode2str(adapter->mode); dbus_connection_emit_property_changed(connection, adapter->path, ADAPTER_INTERFACE, "Mode", - DBUS_TYPE_STRING, &mode); + DBUS_TYPE_STRING, &pmode); load_drivers(adapter); load_devices(adapter); @@ -2743,7 +2782,7 @@ void adapter_set_state(struct adapter *adapter, int state) if (adapter->scheduler_id) goto done; } else if (adapter->disc_sessions && adapter->state & STD_INQUIRY) { - adapter->scheduler_id = g_timeout_add(default_device.inqmode * 1000, + adapter->scheduler_id = g_timeout_add(main_opts.inqmode * 1000, (GSourceFunc) start_inquiry, adapter); goto done; } @@ -23,8 +23,6 @@ * */ -#define HCID_DEFAULT_DISCOVERABLE_TIMEOUT 180 /* 3 minutes */ - /* When all services should trust a remote device */ #define GLOBAL_TRUST "[all]" @@ -44,49 +42,32 @@ #define MODE_LIMITED 0x03 #define MODE_UNKNOWN 0xff -struct device_opts { - unsigned long flags; - char *name; - uint32_t class; - uint16_t voice; - uint8_t inqmode; - uint16_t pageto; - uint16_t pkt_type; - uint16_t link_mode; - uint16_t link_policy; - uint8_t scan; - uint8_t mode; - uint32_t discovto; -}; - -extern struct device_opts default_device; - -struct device_list { - char *ref; /* HCI device or Bluetooth address */ - struct device_list *next; - struct device_opts opts; -}; - -struct hcid_opts { - char host_name[40]; - int auto_init; - int offmode; - char deviceid[15]; +#define HCID_OFFMODE_DEVDOWN 0 +#define HCID_OFFMODE_NOSCAN 1 - int sock; +struct main_opts { + char host_name[40]; + unsigned long flags; + char *name; + uint32_t class; + uint16_t pageto; + uint32_t discovto; + uint16_t link_mode; + uint16_t link_policy; + + int offmode; + uint8_t scan; + uint8_t mode; + uint8_t inqmode; + char deviceid[15]; /* FIXME: */ + + int sock; }; -extern struct hcid_opts hcid; +extern struct main_opts main_opts; void hci_req_queue_remove(int dev_id, bdaddr_t *dba); -#define HCID_OFFMODE_DEVDOWN 0 -#define HCID_OFFMODE_NOSCAN 1 - -uint8_t get_startup_scan(int hdev); -uint8_t get_startup_mode(int hdev); -int get_discoverable_timeout(int dev_id); - void start_security_manager(int hdev); void stop_security_manager(int hdev); @@ -59,6 +59,8 @@ #include "manager.h" #include "storage.h" +#define HCID_DEFAULT_DISCOVERABLE_TIMEOUT 180 /* 3 minutes */ + enum { HCID_SET_NAME, HCID_SET_CLASS, @@ -68,9 +70,8 @@ enum { HCID_SET_LP, }; -struct hcid_opts hcid; -struct device_opts default_device; -static struct device_list *device_list = NULL; +struct main_opts main_opts; + static int child_pipe[2]; static GKeyFile *load_config(const char *file) @@ -112,7 +113,7 @@ static void parse_config(GKeyFile *config) } else { debug("offmode=%s", str); if (g_str_equal(str, "DevDown")) - hcid.offmode = HCID_OFFMODE_DEVDOWN; + main_opts.offmode = HCID_OFFMODE_DEVDOWN; g_free(str); } @@ -125,8 +126,8 @@ static void parse_config(GKeyFile *config) err = NULL; } else { debug("discovto=%d", val); - default_device.discovto = val; - default_device.flags |= 1 << HCID_SET_DISCOVTO; + main_opts.discovto = val; + main_opts.flags |= 1 << HCID_SET_DISCOVTO; } val = g_key_file_get_integer(config, "General", @@ -138,8 +139,8 @@ static void parse_config(GKeyFile *config) err = NULL; } else { debug("pageto=%d", val); - default_device.pageto = val; - default_device.flags |= 1 << HCID_SET_PAGETO; + main_opts.pageto = val; + main_opts.flags |= 1 << HCID_SET_PAGETO; } str = g_key_file_get_string(config, "General", @@ -150,9 +151,9 @@ static void parse_config(GKeyFile *config) err = NULL; } else { debug("name=%s", str); - g_free(default_device.name); - default_device.name = g_strdup(str); - default_device.flags |= 1 << HCID_SET_NAME; + g_free(main_opts.name); + main_opts.name = g_strdup(str); + main_opts.flags |= 1 << HCID_SET_NAME; g_free(str); } @@ -164,8 +165,8 @@ static void parse_config(GKeyFile *config) err = NULL; } else { debug("class=%s", str); - default_device.class = strtol(str, NULL, 16); - default_device.flags |= 1 << HCID_SET_CLASS; + main_opts.class = strtol(str, NULL, 16); + main_opts.flags |= 1 << HCID_SET_CLASS; g_free(str); } @@ -178,172 +179,15 @@ static void parse_config(GKeyFile *config) err = NULL; } else { debug("inqmode=%d", val); - default_device.inqmode = val; + main_opts.inqmode = val; } - default_device.link_mode = HCI_LM_ACCEPT; - default_device.flags |= (1 << HCID_SET_LM); + main_opts.link_mode = HCI_LM_ACCEPT; + main_opts.flags |= (1 << HCID_SET_LM); - default_device.link_policy = HCI_LP_RSWITCH | HCI_LP_SNIFF | + main_opts.link_policy = HCI_LP_RSWITCH | HCI_LP_SNIFF | HCI_LP_HOLD | HCI_LP_PARK; - default_device.flags |= (1 << HCID_SET_LP); -} - -static inline void init_device_defaults(struct device_opts *device_opts) -{ - memset(device_opts, 0, sizeof(*device_opts)); - device_opts->scan = SCAN_PAGE; - device_opts->mode = MODE_CONNECTABLE; - device_opts->name = g_strdup("BlueZ"); - device_opts->discovto = HCID_DEFAULT_DISCOVERABLE_TIMEOUT; -} - -static void free_device_opts(void) -{ - struct device_list *device, *next; - - g_free(default_device.name); - - for (device = device_list; device; device = next) { - g_free(device->ref); - g_free(device->opts.name); - next = device->next; - g_free(device); - } - - device_list = NULL; -} - -static inline struct device_opts *find_device_opts(char *ref) -{ - struct device_list *device; - - for (device = device_list; device; device = device->next) - if (!strcmp(ref, device->ref)) - return &device->opts; - - return NULL; -} - -static struct device_opts *get_device_opts(int hdev) -{ - struct device_opts *device_opts = NULL; - struct hci_dev_info di; - - /* First try to get BD_ADDR based settings ... */ - if (hci_devinfo(hdev, &di) == 0) { - char addr[18]; - ba2str(&di.bdaddr, addr); - device_opts = find_device_opts(addr); - } - - /* ... then try HCI based settings ... */ - if (!device_opts) { - char ref[8]; - snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); - device_opts = find_device_opts(ref); - } - - /* ... and last use the default settings. */ - if (!device_opts) - device_opts = &default_device; - - return device_opts; -} - -static struct device_opts *get_opts(int hdev) -{ - struct device_opts *device_opts = NULL; - struct hci_dev_info di; - char addr[18]; - int sock; - - if (hdev < 0) - return NULL; - - sock = hci_open_dev(hdev); - if (sock < 0) - goto no_address; - - if (hci_devinfo(hdev, &di) < 0) { - close(sock); - goto no_address; - } - - close(sock); - - ba2str(&di.bdaddr, addr); - device_opts = find_device_opts(addr); - -no_address: - if (!device_opts) { - char ref[8]; - snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); - device_opts = find_device_opts(ref); - } - - if (!device_opts) - device_opts = &default_device; - - return device_opts; -} - -uint8_t get_startup_scan(int hdev) -{ - struct device_opts *device_opts = get_opts(hdev); - if (!device_opts) - return SCAN_DISABLED; - - return device_opts->scan; -} - -uint8_t get_startup_mode(int hdev) -{ - struct device_opts *device_opts = get_opts(hdev); - if (!device_opts) - return MODE_OFF; - - return device_opts->mode; -} - -int get_discoverable_timeout(int hdev) -{ - struct device_opts *device_opts = NULL; - struct hci_dev_info di; - char addr[18]; - int sock, timeout; - - if (hdev < 0) - return HCID_DEFAULT_DISCOVERABLE_TIMEOUT; - - sock = hci_open_dev(hdev); - if (sock < 0) - goto no_address; - - if (hci_devinfo(hdev, &di) < 0) { - close(sock); - goto no_address; - } - - close(sock); - - if (read_discoverable_timeout(&di.bdaddr, &timeout) == 0) - return timeout; - - ba2str(&di.bdaddr, addr); - device_opts = find_device_opts(addr); - -no_address: - if (!device_opts) { - char ref[8]; - snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); - device_opts = find_device_opts(ref); - } - - if (!device_opts) - device_opts = &default_device; - - return device_opts->discovto; + main_opts.flags |= (1 << HCID_SET_LP); } static void update_service_classes(const bdaddr_t *bdaddr, uint8_t value) @@ -427,7 +271,7 @@ static char *expand_name(char *dst, int size, char *str, int dev_id) break; case 'h': - opt = hcid.host_name; + opt = main_opts.host_name; break; case '%': @@ -488,53 +332,16 @@ static void at_child_exit(void) static void configure_device(int dev_id) { - struct device_opts *device_opts; struct hci_dev_req dr; struct hci_dev_info di; - char mode[14]; int dd; - device_opts = get_device_opts(dev_id); - if (hci_devinfo(dev_id, &di) < 0) return; if (hci_test_bit(HCI_RAW, &di.flags)) return; - /* Set default discoverable timeout if not set */ - if (!(device_opts->flags & (1 << HCID_SET_DISCOVTO))) - device_opts->discovto = HCID_DEFAULT_DISCOVERABLE_TIMEOUT; - - /* Set scan mode */ - if (read_device_mode(&di.bdaddr, mode, sizeof(mode)) == 0) { - if (!strcmp(mode, "off") && hcid.offmode == HCID_OFFMODE_NOSCAN) { - device_opts->mode = MODE_OFF; - device_opts->scan = SCAN_DISABLED; - } else if (!strcmp(mode, "connectable")) { - device_opts->mode = MODE_CONNECTABLE; - device_opts->scan = SCAN_PAGE; - } else if (!strcmp(mode, "discoverable")) { - /* Set discoverable only if timeout is 0 */ - if (!get_discoverable_timeout(dev_id)) { - device_opts->scan = SCAN_PAGE | SCAN_INQUIRY; - device_opts->mode = MODE_DISCOVERABLE; - } else { - device_opts->scan = SCAN_PAGE; - device_opts->mode = MODE_CONNECTABLE; - } - } else if (!strcmp(mode, "limited")) { - /* Set discoverable only if timeout is 0 */ - if (!get_discoverable_timeout(dev_id)) { - device_opts->scan = SCAN_PAGE | SCAN_INQUIRY; - device_opts->mode = MODE_LIMITED; - } else { - device_opts->scan = SCAN_PAGE; - device_opts->mode = MODE_CONNECTABLE; - } - } - } - /* Do configuration in the separate process */ switch (fork()) { case 0: @@ -558,8 +365,8 @@ static void configure_device(int dev_id) dr.dev_id = dev_id; /* Set link mode */ - if ((device_opts->flags & (1 << HCID_SET_LM))) { - dr.dev_opt = device_opts->link_mode; + if ((main_opts.flags & (1 << HCID_SET_LM))) { + dr.dev_opt = main_opts.link_mode; if (ioctl(dd, HCISETLINKMODE, (unsigned long) &dr) < 0) { error("Can't set link mode on hci%d: %s (%d)", dev_id, strerror(errno), errno); @@ -567,8 +374,8 @@ static void configure_device(int dev_id) } /* Set link policy */ - if ((device_opts->flags & (1 << HCID_SET_LP))) { - dr.dev_opt = device_opts->link_policy; + if ((main_opts.flags & (1 << HCID_SET_LP))) { + dr.dev_opt = main_opts.link_policy; if (ioctl(dd, HCISETLINKPOL, (unsigned long) &dr) < 0) { error("Can't set link policy on hci%d: %s (%d)", dev_id, strerror(errno), errno); @@ -576,29 +383,29 @@ static void configure_device(int dev_id) } /* Set device name */ - if ((device_opts->flags & (1 << HCID_SET_NAME)) && device_opts->name) { + if ((main_opts.flags & (1 << HCID_SET_NAME)) && main_opts.name) { change_local_name_cp cp; memset(cp.name, 0, sizeof(cp.name)); expand_name((char *) cp.name, sizeof(cp.name), - device_opts->name, dev_id); + main_opts.name, dev_id); hci_send_cmd(dd, OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME, CHANGE_LOCAL_NAME_CP_SIZE, &cp); } /* Set device class */ - if ((device_opts->flags & (1 << HCID_SET_CLASS))) { + if ((main_opts.flags & (1 << HCID_SET_CLASS))) { write_class_of_dev_cp cp; uint32_t class; uint8_t cls[3]; if (read_local_class(&di.bdaddr, cls) < 0) { - class = htobl(device_opts->class); + class = htobl(main_opts.class); cls[2] = get_service_classes(&di.bdaddr); memcpy(cp.dev_class, &class, 3); } else { - if (!(device_opts->scan & SCAN_INQUIRY)) + if (!(main_opts.scan & SCAN_INQUIRY)) cls[1] &= 0xdf; /* Clear discoverable bit */ cls[2] = get_service_classes(&di.bdaddr); memcpy(cp.dev_class, cls, 3); @@ -609,10 +416,10 @@ static void configure_device(int dev_id) } /* Set page timeout */ - if ((device_opts->flags & (1 << HCID_SET_PAGETO))) { + if ((main_opts.flags & (1 << HCID_SET_PAGETO))) { write_page_timeout_cp cp; - cp.timeout = htobs(device_opts->pageto); + cp.timeout = htobs(main_opts.pageto); hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_PAGE_TIMEOUT, WRITE_PAGE_TIMEOUT_CP_SIZE, &cp); } @@ -657,10 +464,11 @@ static void init_device(int dev_id) if (hci_test_bit(HCI_RAW, &di.flags)) goto done; - if (hcid.offmode == HCID_OFFMODE_DEVDOWN) { - char mode[16]; + if (main_opts.offmode == HCID_OFFMODE_DEVDOWN) { + char mode[16], src[18]; - if (read_device_mode(&di.bdaddr, mode, sizeof(mode)) == 0 && + ba2str(&di.bdaddr, src); + if (read_device_mode(src, mode, sizeof(mode)) == 0 && strcmp(mode, "off") == 0) { ioctl(dd, HCIDEVDOWN, dev_id); goto done; @@ -680,8 +488,7 @@ static void device_devreg_setup(int dev_id) { struct hci_dev_info di; - if (hcid.auto_init) - init_device(dev_id); + init_device(dev_id); if (hci_devinfo(dev_id, &di) < 0) return; @@ -692,8 +499,8 @@ static void device_devreg_setup(int dev_id) static void device_devup_setup(int dev_id) { - if (hcid.auto_init) - configure_device(dev_id); + configure_device(dev_id); + manager_start_adapter(dev_id); start_security_manager(dev_id); } @@ -734,9 +541,16 @@ static void init_all_devices(int ctl) static void init_defaults(void) { - hcid.auto_init = 1; - - init_device_defaults(&default_device); + /* Default HCId settings */ + memset(&main_opts, 0, sizeof(main_opts)); + main_opts.offmode = HCID_OFFMODE_NOSCAN; + main_opts.scan = SCAN_PAGE; + main_opts.mode = MODE_CONNECTABLE; + main_opts.name = g_strdup("BlueZ"); + main_opts.discovto = HCID_DEFAULT_DISCOVERABLE_TIMEOUT; + + if (gethostname(main_opts.host_name, sizeof(main_opts.host_name) - 1) < 0) + strcpy(main_opts.host_name, "noname"); } static inline void device_event(GIOChannel *chan, evt_stack_internal *si) @@ -843,14 +657,6 @@ int main(int argc, char *argv[]) uint16_t mtu = 0; GKeyFile *config; - /* Default HCId settings */ - memset(&hcid, 0, sizeof(hcid)); - hcid.auto_init = 1; - hcid.offmode = HCID_OFFMODE_NOSCAN; - - if (gethostname(hcid.host_name, sizeof(hcid.host_name) - 1) < 0) - strcpy(hcid.host_name, "noname"); - init_defaults(); context = g_option_context_new(NULL); @@ -896,7 +702,7 @@ int main(int argc, char *argv[]) } /* Create and bind HCI socket */ - if ((hcid.sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) { + if ((main_opts.sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) { error("Can't open HCI socket: %s (%d)", strerror(errno), errno); exit(1); @@ -906,7 +712,7 @@ int main(int argc, char *argv[]) hci_filter_clear(&flt); hci_filter_set_ptype(HCI_EVENT_PKT, &flt); hci_filter_set_event(EVT_STACK_INTERNAL, &flt); - if (setsockopt(hcid.sock, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { + if (setsockopt(main_opts.sock, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { error("Can't set filter: %s (%d)", strerror(errno), errno); exit(1); @@ -914,7 +720,7 @@ int main(int argc, char *argv[]) addr.hci_family = AF_BLUETOOTH; addr.hci_dev = HCI_DEV_NONE; - if (bind(hcid.sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (bind(main_opts.sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { error("Can't bind HCI socket: %s (%d)", strerror(errno), errno); exit(1); @@ -943,7 +749,7 @@ int main(int argc, char *argv[]) exit(1); } - start_sdp_server(mtu, hcid.deviceid, SDP_SERVER_COMPAT); + start_sdp_server(mtu, main_opts.deviceid, SDP_SERVER_COMPAT); set_service_classes_callback(update_service_classes); /* Loading plugins has to be done after D-Bus has been setup since @@ -954,7 +760,7 @@ int main(int argc, char *argv[]) event_loop = g_main_loop_new(NULL, FALSE); - ctl_io = g_io_channel_unix_new(hcid.sock); + ctl_io = g_io_channel_unix_new(main_opts.sock); g_io_channel_set_close_on_unref(ctl_io, TRUE); g_io_add_watch(ctl_io, G_IO_IN, io_stack_event, NULL); @@ -962,7 +768,7 @@ int main(int argc, char *argv[]) g_io_channel_unref(ctl_io); /* Initialize already connected devices */ - init_all_devices(hcid.sock); + init_all_devices(main_opts.sock); g_main_loop_run(event_loop); @@ -972,8 +778,6 @@ int main(int argc, char *argv[]) stop_sdp_server(); - free_device_opts(); - agent_exit(); hcid_dbus_exit(); diff --git a/src/storage.c b/src/storage.c index f85dbb53..c2450ba2 100644 --- a/src/storage.c +++ b/src/storage.c @@ -97,11 +97,11 @@ int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout) return textfile_put(filename, "discovto", str); } -int read_discoverable_timeout(bdaddr_t *bdaddr, int *timeout) +int read_discoverable_timeout(const char *src, int *timeout) { char filename[PATH_MAX + 1], *str; - create_filename(filename, PATH_MAX, bdaddr, "config"); + create_name(filename, PATH_MAX, STORAGEDIR, src, "config"); str = textfile_get(filename, "discovto"); if (!str) @@ -131,11 +131,11 @@ int write_device_mode(bdaddr_t *bdaddr, const char *mode) return textfile_put(filename, "mode", mode); } -int read_device_mode(bdaddr_t *bdaddr, char *mode, int length) +int read_device_mode(const char *src, char *mode, int length) { char filename[PATH_MAX + 1], *str; - create_filename(filename, PATH_MAX, bdaddr, "config"); + create_name(filename, PATH_MAX, STORAGEDIR, src, "config"); str = textfile_get(filename, "mode"); if (!str) diff --git a/src/storage.h b/src/storage.h index 8a06d4e3..7f89ef19 100644 --- a/src/storage.h +++ b/src/storage.h @@ -24,9 +24,9 @@ int read_device_alias(const char *src, const char *dst, char *alias, size_t size); int write_device_alias(const char *src, const char *dst, const char *alias); int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout); -int read_discoverable_timeout(bdaddr_t *bdaddr, int *timeout); +int read_discoverable_timeout(const char *src, int *timeout); int write_device_mode(bdaddr_t *bdaddr, const char *mode); -int read_device_mode(bdaddr_t *bdaddr, char *mode, int length); +int read_device_mode(const char *src, char *mode, int length); int read_on_mode(const char *src, char *mode, int length); int write_local_name(bdaddr_t *bdaddr, char *name); int read_local_name(bdaddr_t *bdaddr, char *name); |