summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-09-02 02:28:33 +0200
committerMarcel Holtmann <marcel@holtmann.org>2008-09-02 02:28:33 +0200
commit0c05dd3dc5a18d64734a9f091d5285612e41107b (patch)
tree57de979b0fdef6c07329d0aae06235730a2fb4cb
parent4f946e36897fc67a28a56fb3102994da6857a038 (diff)
parent3f498e694e39756890db475f1f1edb528b378ee2 (diff)
Merge branch 'for-upstream' of git://gitorious.org/bluez/cktakahasis-clone
-rw-r--r--doc/network-api.txt34
-rw-r--r--network/Makefile.am2
-rw-r--r--network/common.c20
-rw-r--r--network/common.h4
-rw-r--r--network/connection.c8
-rw-r--r--network/manager.c14
-rw-r--r--network/manager.h6
-rw-r--r--network/network-api.txt199
-rw-r--r--network/server.c14
-rwxr-xr-xnetwork/test-network37
-rw-r--r--src/adapter.c61
-rw-r--r--src/hcid.h59
-rw-r--r--src/main.c304
-rw-r--r--src/storage.c8
-rw-r--r--src/storage.h4
15 files changed, 170 insertions, 604 deletions
diff --git a/doc/network-api.txt b/doc/network-api.txt
index a59c8972..85171711 100644
--- a/doc/network-api.txt
+++ b/doc/network-api.txt
@@ -36,3 +36,37 @@ Methods string Connect(string uuid)
Signals void Connected(string device, string uuid)
void Disconnected(string device)
+
+
+Network Hub/Peer/Router hierarchy
+=================
+
+Service org.bluez
+Interface org.bluez.network.{Hub, Peer, Router}
+Object path /org/bluez/{hci0,hci1,...}
+
+Methods dict GetProperties()
+
+ Returns all properties for the GN/PANU/NAP server. See the
+ properties section for available properties.
+
+ void SetProperty(string name, variant value)
+
+ Changes the value of the specified property. Only
+ properties that are listed a read-write are changeable.
+ On success this will emit a PropertyChanged signal.
+
+ Possible Errors: org.bluez.Error.DoesNotExist
+ org.bluez.Error.InvalidArguments
+
+Properties string Name[readwrite]
+
+ The Bluetooth network server name.
+
+ boolean Enable[readwrite]
+
+ Indicates if the server is Enabled/Disabled.
+
+ string Uuid[readonly]
+
+ The Bluetooth network server UUID 128 identification.
diff --git a/network/Makefile.am b/network/Makefile.am
index 71291d93..5966a619 100644
--- a/network/Makefile.am
+++ b/network/Makefile.am
@@ -19,6 +19,6 @@ AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@
INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/src
-EXTRA_DIST = network.conf network-api.txt test-network
+EXTRA_DIST = network.conf
MAINTAINERCLEANFILES = Makefile.in
diff --git a/network/common.c b/network/common.c
index 151e4810..980486fc 100644
--- a/network/common.c
+++ b/network/common.c
@@ -32,7 +32,6 @@
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <sys/stat.h>
#include <sys/wait.h>
#include <net/if.h>
@@ -44,7 +43,6 @@
#include "logging.h"
#include "common.h"
-#include "textfile.h"
static int ctl;
static GSList *pids;
@@ -372,21 +370,3 @@ done:
return 0;
}
-
-int read_remote_name(bdaddr_t *src, bdaddr_t *dst, char *buf, size_t size)
-{
- char filename[PATH_MAX + 1], addr[18], *str;
-
- ba2str(src, addr);
- create_name(filename, PATH_MAX, STORAGEDIR, addr, "names");
-
- ba2str(dst, addr);
- str = textfile_get(filename, addr);
- if (!str)
- return -ENOENT;
-
- snprintf(buf, size, "%s", str);
- free(str);
-
- return 0;
-}
diff --git a/network/common.h b/network/common.h
index cc154471..78d0d769 100644
--- a/network/common.h
+++ b/network/common.h
@@ -21,8 +21,6 @@
*
*/
-#define MAX_PATH_LENGTH 64 /* D-Bus path */
-
#define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb"
#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb"
#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb"
@@ -41,5 +39,3 @@ int bnep_kill_all_connections(void);
int bnep_connadd(int sk, uint16_t role, char *dev);
int bnep_if_up(const char *devname, uint16_t id);
int bnep_if_down(const char *devname);
-
-int read_remote_name(bdaddr_t *src, bdaddr_t *dst, char *buf, size_t size);
diff --git a/network/connection.c b/network/connection.c
index c61eb49c..16d3e383 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -28,29 +28,21 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/param.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
-#include <bluetooth/l2cap.h>
#include <bluetooth/bnep.h>
#include <bluetooth/sdp.h>
#include <glib.h>
#include <gdbus.h>
-#include "../src/dbus-common.h"
-
#include "logging.h"
-#include "textfile.h"
#include "glib-helper.h"
#include "error.h"
#include "common.h"
-#include "connection.h"
#define NETWORK_PEER_INTERFACE "org.bluez.network.Peer"
diff --git a/network/manager.c b/network/manager.c
index 7cbf8220..8067b821 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -25,34 +25,24 @@
#include <config.h>
#endif
-#include <errno.h>
-#include <ctype.h>
-#include <dirent.h>
-
-#include <sys/stat.h>
-
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/bnep.h>
#include <bluetooth/sdp.h>
-#include <bluetooth/sdp_lib.h>
#include <glib.h>
#include <gdbus.h>
#include "logging.h"
-#include "textfile.h"
-#include "glib-helper.h"
#include "adapter.h"
#include "device.h"
-#include "error.h"
#include "bridge.h"
#include "manager.h"
#include "common.h"
-
-#define MAX_NAME_SIZE 256
+#include "connection.h"
+#include "server.h"
static struct network_conf *conf = NULL;/* Network service configuration */
diff --git a/network/manager.h b/network/manager.h
index 9b16c2a3..455b0963 100644
--- a/network/manager.h
+++ b/network/manager.h
@@ -21,12 +21,6 @@
*
*/
-#include "connection.h"
-#include "server.h"
-
-#define MAX_PATH_LENGTH 64 /* D-Bus path */
-#define NETWORK_PATH "/org/bluez/network"
-
struct network_conf {
gboolean connection_enabled;
gboolean server_enabled;
diff --git a/network/network-api.txt b/network/network-api.txt
deleted file mode 100644
index 2d46abfd..00000000
--- a/network/network-api.txt
+++ /dev/null
@@ -1,199 +0,0 @@
-Bluetooth network service API description
-*****************************************
-
-Copyright (C) 2006-2007 Marcel Holtmann <marcel@holtmann.org>
-
-
-Network Manager hierarchy
-=========================
-
-Interface org.bluez.network.Manager
-Object path /org/bluez/network
-
-Methods array{string} ListServers()
-
- Returns an array of available network devices paths.
- Currently only NAP and GN are supported.
-
- string FindServer(string pattern)
-
- Returns server path.
-
- Possible errors: org.bluez.Error.DoesNotExist
- org.bluez.Error.Failed
-
- string CreateConnection(string address, string uuid)
-
- Creates a network connection object(NAP or GN).
-
- Possible errors: org.bluez.Error.AlreadyExists
- org.bluez.Error.NotSupported
- org.bluez.Error.ConnectionAttemptFailed
- org.bluez.Error.Failed
-
- void RemoveConnection(string path)
-
- Removes a network connection object for a given path.
-
- Possible errors: org.bluez.Error.DoesNotExist
- org.bluez.Error.Failed
-
- array{string} ListConnections()
-
- Returns an array of available network connections paths.
-
- string FindConnection(string pattern)
-
- Returns connection path.
-
- Possible errors: org.bluez.Error.DoesNotExist
- org.bluez.Error.Failed
-
- string LastConnection()
-
- Returns last connected connection path, if none is connected
- fallback to last created connection.
-
- Possible errors: org.bluez.Error.DoesNotExist
-
- string DefaultConnection()
-
- Returns default connection path.
-
- Possible errors: org.bluez.Error.DoesNotExist
-
- string ChangeDefaultConnection(string pattern)
-
- Changes default connection path.
-
- Possible errors: org.bluez.Error.DoesNotExist
-
-Signals void ConnectionCreated(string path)
-
- void ConnectionRemoved(string path)
-
- void DefaultConnectionChanged(string path)
-
-
-Network Server hierarchy (experimental)
-=======================================
-
-Interface org.bluez.network.Server
-Object path /org/bluez/network/{gn, nap, panu}
-
-Methods string GetUUID()
-
- Returns the UUID-128 string representation of
- the server.
-
- void Enable()
-
- Enable server and updates service record.
-
- Possible errors: org.bluez.Error.AlreadyExists
- org.bluez.Error.Failed
-
- void Disable()
-
- Disable server and remove service record.
-
- Possible errors: org.bluez.Error.Failed
-
- bool IsEnabled()
-
- Returns the server status.
-
- void SetName(string name)
-
- Sets the name attribute.
-
- string GetName()
-
- Returns the service name.
-
- void SetAddressRange(string start, string end)
-
- TBD
-
- void SetRouting(string interface)
-
- TBD
-
- dict GetInfo()
-
- Returns the server properties.
-
-Signals void Enabled()
-
- void Disabled()
-
-
-Network Connection hierarchy (experimental)
-===========================================
-
-Interface org.bluez.network.Connection
-Object path /org/bluez/network/connection*
-
-Methods string GetAdapter()
-
- Returns the Bluetooth address of the adapter.
-
- string GetAddress()
-
- Returns the Bluetooth address of the ending point.
-
- string GetUUID()
-
- Returns the uuid 128 string representation of
- the connected service.
-
- string GetName()
-
- Returns the string representation of connected host.
-
- Possible errors: org.bluez.Error.Failed
-
- string GetDescription()
-
- Returns the string description of connected host.
-
- Possible errors: org.bluez.Error.Failed
-
- string GetInterface()
-
- Returns the string network interface.
-
- Possible errors: org.bluez.Error.Failed
-
- string Connect()
-
- Connects to host and return the network interface
- created.
-
- Possible errors: org.bluez.Error.ConnectionAttemptFailed
- org.bluez.Error.Failed
-
- void CancelConnect()
-
- Abort connection attempt in case of errors or
- timeouts in the client.
-
- Possible errors: org.bluez.Error.Failed
-
- void Disconnect()
-
- Disconnects to host.
-
- Possible errors: org.bluez.Error.Failed
-
- bool IsConnected()
-
- Returns the connection status.
-
- dict GetInfo()
-
- Returns the connection properties.
-
-Signals void Connected()
-
- void Disconnected()
diff --git a/network/server.c b/network/server.c
index 3fa99d25..00e8f0aa 100644
--- a/network/server.c
+++ b/network/server.c
@@ -29,18 +29,13 @@
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <net/if.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
#include <bluetooth/bnep.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
-
#include <netinet/in.h>
#include <glib.h>
@@ -51,19 +46,16 @@
#include "logging.h"
#include "error.h"
-#include "textfile.h"
#include "sdpd.h"
#include "glib-helper.h"
+#include "bridge.h"
+#include "common.h"
+
#define NETWORK_PEER_INTERFACE "org.bluez.network.Peer"
#define NETWORK_HUB_INTERFACE "org.bluez.network.Hub"
#define NETWORK_ROUTER_INTERFACE "org.bluez.network.Router"
#define SETUP_TIMEOUT 1000
-#define MAX_SETUP_ATTEMPTS 3
-
-#include "bridge.h"
-#include "common.h"
-#include "manager.h"
/* Pending Authorization */
struct setup_session {
diff --git a/network/test-network b/network/test-network
deleted file mode 100755
index f428c25f..00000000
--- a/network/test-network
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/python
-
-import dbus
-
-bus = dbus.SystemBus()
-
-manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
- 'org.bluez.Manager')
-
-conn = manager.ActivateService('network')
-
-network = dbus.Interface(bus.get_object(conn, '/org/bluez/network'),
- 'org.bluez.network.Manager')
-
-try:
- nap = dbus.Interface(bus.get_object(conn, network.FindServer('nap')),
- 'org.bluez.network.Server')
-except:
- pass
-
-try:
- gn = dbus.Interface(bus.get_object(conn, network.FindServer('gn')),
- 'org.bluez.network.Server')
-except:
- pass
-
-try:
- panu = dbus.Interface(bus.get_object(conn, network.FindServer('panu')),
- 'org.bluez.network.Server')
-except:
- pass
-
-try:
- client = dbus.Interface(bus.get_object(conn, network.LastConnection()),
- 'org.bluez.network.Connection')
-except:
- pass
diff --git a/src/adapter.c b/src/adapter.c
index 18b03313..a22112c8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -457,8 +457,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)
@@ -475,7 +475,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);
@@ -1375,7 +1375,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);
@@ -2389,22 +2389,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);
@@ -2426,11 +2465,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);
@@ -2896,7 +2935,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;
}
diff --git a/src/hcid.h b/src/hcid.h
index 16f5dc93..687481c3 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -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);
diff --git a/src/main.c b/src/main.c
index 02d89967..576c983a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);