summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-23 10:52:57 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-23 10:52:57 +0000
commit3960b7affa107530a67baf695febf12e15600865 (patch)
tree99c9f9a46b4b84764697a4d2710347449a004da2
parent2c9cbad68a808567201f01d3f29f49611d59b690 (diff)
Move scan mode setting into adapter startup
-rw-r--r--hcid/dbus-hci.c43
-rw-r--r--hcid/hcid.h1
-rw-r--r--hcid/main.c92
3 files changed, 77 insertions, 59 deletions
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 25d6e01e..c521d569 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -350,7 +350,7 @@ static void adapter_mode_changed(struct adapter *adapter, uint8_t mode)
DBUS_TYPE_INVALID);
send_message_and_unref(connection, message);
-}
+}
/*
* HCI D-Bus services
@@ -601,17 +601,15 @@ failed:
int hcid_dbus_start_device(uint16_t id)
{
char path[MAX_PATH_LENGTH];
- int i, err, dd = -1, ret = -1;
- read_scan_enable_rp rp;
struct hci_dev_info di;
- struct hci_request rq;
struct adapter* adapter;
struct hci_conn_list_req *cl = NULL;
struct hci_conn_info *ci;
+ uint8_t mode;
+ int i, err, dd = -1, ret = -1;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
- /* FIXME: check dupplicated code - configure_device() */
if (hci_devinfo(id, &di) < 0) {
error("Getting device info failed: hci%d", id);
return -1;
@@ -620,33 +618,10 @@ int hcid_dbus_start_device(uint16_t id)
if (hci_test_bit(HCI_RAW, &di.flags))
return -1;
- dd = hci_open_dev(id);
- if (dd < 0) {
- error("HCI device open failed: hci%d", id);
- rp.enable = SCAN_PAGE | SCAN_INQUIRY;
- } else {
- memset(&rq, 0, sizeof(rq));
- rq.ogf = OGF_HOST_CTL;
- rq.ocf = OCF_READ_SCAN_ENABLE;
- rq.rparam = &rp;
- rq.rlen = READ_SCAN_ENABLE_RP_SIZE;
- rq.event = EVT_CMD_COMPLETE;
-
- if (hci_send_req(dd, &rq, 1000) < 0) {
- error("Sending read scan enable command failed: %s (%d)",
- strerror(errno), errno);
- rp.enable = SCAN_PAGE | SCAN_INQUIRY;
- } else if (rp.status) {
- error("Getting scan enable failed with status 0x%02x",
- rp.status);
- rp.enable = SCAN_PAGE | SCAN_INQUIRY;
- }
- }
-
if (!dbus_connection_get_object_path_data(connection, path,
(void *) &adapter)) {
error("Getting %s path data failed!", path);
- goto failed;
+ return -1;
}
if (hci_test_bit(HCI_INQUIRY, &di.flags))
@@ -658,6 +633,14 @@ int hcid_dbus_start_device(uint16_t id)
adapter->discov_timeout = get_discoverable_timeout(id);
adapter->discov_type = DISCOVER_TYPE_NONE;
+ mode = get_startup_mode(id);
+
+ dd = hci_open_dev(id);
+ if (dd < 0)
+ goto failed;
+
+ hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE, 1, &mode);
+
/*
* Get the adapter Bluetooth address
*/
@@ -666,7 +649,7 @@ int hcid_dbus_start_device(uint16_t id)
if (err < 0)
goto failed;
- adapter_mode_changed(adapter, rp.enable);
+ adapter_mode_changed(adapter, mode);
/*
* retrieve the active connections: address the scenario where
diff --git a/hcid/hcid.h b/hcid/hcid.h
index 0c77c225..aeba6bb6 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -134,6 +134,7 @@ int read_config(char *file);
struct device_opts *alloc_device_opts(char *ref);
+uint8_t get_startup_mode(int hdev);
int get_discoverable_timeout(int dev_id);
void init_security_data(void);
diff --git a/hcid/main.c b/hcid/main.c
index 0a6b832f..3f43c067 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -153,12 +153,49 @@ static struct device_opts *get_device_opts(int sock, int hdev)
return device_opts;
}
+uint8_t get_startup_mode(int hdev)
+{
+ struct device_opts *device_opts = NULL;
+ struct hci_dev_info di;
+ char addr[18];
+ int sock;
+
+ if (hdev < 0)
+ return SCAN_DISABLED;
+
+ 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->scan;
+}
+
int get_discoverable_timeout(int hdev)
{
- int sock, timeout;
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;
@@ -288,6 +325,25 @@ static void configure_device(int dev_id)
device_opts = get_device_opts(dd, dev_id);
+ /* 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))) {
+ if (!strcmp(mode, MODE_OFF) && hcid.offmode == HCID_OFFMODE_NOSCAN)
+ device_opts->scan = SCAN_DISABLED;
+ else if (!strcmp(mode, MODE_CONNECTABLE))
+ device_opts->scan = SCAN_PAGE;
+ else if (!strcmp(mode, MODE_DISCOVERABLE)) {
+ /* Set discoverable only if timeout is 0 */
+ if (!get_discoverable_timeout(dev_id))
+ device_opts->scan = SCAN_PAGE | SCAN_INQUIRY;
+ else
+ device_opts->scan = SCAN_PAGE;
+ }
+ }
+
/* Set packet type */
if ((device_opts->flags & (1 << HCID_SET_PTYPE))) {
dr.dev_opt = device_opts->pkt_type;
@@ -365,15 +421,6 @@ static void configure_device(int dev_id)
WRITE_CLASS_OF_DEV_CP_SIZE, &cp);
}
- /* Set voice setting */
- if ((device_opts->flags & (1 << HCID_SET_VOICE))) {
- write_voice_setting_cp cp;
-
- cp.voice_setting = htobl(device_opts->voice);
- hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_VOICE_SETTING,
- WRITE_VOICE_SETTING_CP_SIZE, &cp);
- }
-
/* Set page timeout */
if ((device_opts->flags & (1 << HCID_SET_PAGETO))) {
write_page_timeout_cp cp;
@@ -383,28 +430,15 @@ static void configure_device(int dev_id)
WRITE_PAGE_TIMEOUT_CP_SIZE, &cp);
}
- /* Set default discoverable timeout if not set */
- if (!(device_opts->flags & (1 << HCID_SET_DISCOVTO)))
- device_opts->discovto = HCID_DEFAULT_DISCOVERABLE_TIMEOUT;
+ /* Set voice setting */
+ if ((device_opts->flags & (1 << HCID_SET_VOICE))) {
+ write_voice_setting_cp cp;
- /* Set scan mode */
- if (!read_device_mode(&di.bdaddr, mode, sizeof(mode))) {
- if (!strcmp(mode, MODE_OFF) && hcid.offmode == HCID_OFFMODE_NOSCAN)
- device_opts->scan = SCAN_DISABLED;
- else if (!strcmp(mode, MODE_CONNECTABLE))
- device_opts->scan = SCAN_PAGE;
- else if (!strcmp(mode, MODE_DISCOVERABLE)) {
- /* Set discoverable only if timeout is 0 */
- if (!get_discoverable_timeout(dev_id))
- device_opts->scan = SCAN_PAGE | SCAN_INQUIRY;
- else
- device_opts->scan = SCAN_PAGE;
- }
+ cp.voice_setting = htobl(device_opts->voice);
+ hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_VOICE_SETTING,
+ WRITE_VOICE_SETTING_CP_SIZE, &cp);
}
- hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE, 1,
- &device_opts->scan);
-
exit(0);
}