summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-11-14 18:22:37 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-11-14 18:22:37 +0000
commit38a404ba5bfbf21d4607a5d048846288a2359c56 (patch)
treec2d2f7a9d8e5c5077e21ca2cd99d17129cd28201 /hcid
parentfc03565db71241cbc0a47ae7528273d3982fb606 (diff)
Add offmode config option for defining SetMode("off") behaviour
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-adapter.c17
-rw-r--r--hcid/hcid.conf.57
-rw-r--r--hcid/hcid.h4
-rw-r--r--hcid/kword.c7
-rw-r--r--hcid/kword.h1
-rw-r--r--hcid/main.c1
-rw-r--r--hcid/parser.y19
7 files changed, 52 insertions, 4 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 3edbabf2..c7bc7671 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -426,7 +426,10 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn,
if (dd < 0)
return error_no_such_adapter(conn, msg);
- if (!adapter->up) {
+ if (!adapter->up &&
+ (hcid.offmode == HCID_OFFMODE_NOSCAN ||
+ (hcid.offmode == HCID_OFFMODE_DEVDOWN &&
+ hci_mode != SCAN_DISABLED))) {
bdaddr_t local;
str2ba(adapter->address, &local);
@@ -434,7 +437,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn,
write_device_mode(&local, scan_mode);
/* Start HCI device */
- if (ioctl(dd, HCIDEVUP, adapter->dev_id) == 0)
+ if (ioctl(dd, HCIDEVUP, adapter->dev_id) == 0)
goto done; /* on success */
if (errno != EALREADY) {
@@ -447,6 +450,16 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn,
}
}
+ if (adapter->up && hci_mode == SCAN_DISABLED &&
+ hcid.offmode == HCID_OFFMODE_DEVDOWN) {
+ if (ioctl(dd, HCIDEVDOWN, adapter->dev_id) < 0) {
+ hci_close_dev(dd);
+ return error_failed(conn, msg, errno);
+ }
+
+ goto done;
+ }
+
/* Check if the new requested mode is different from the current */
if (current_mode != hci_mode) {
struct hci_request rq;
diff --git a/hcid/hcid.conf.5 b/hcid/hcid.conf.5
index 67fb5f19..1dad854d 100644
--- a/hcid/hcid.conf.5
+++ b/hcid/hcid.conf.5
@@ -45,6 +45,13 @@ with already paired devices. \fIonce\fP allows pairing once and denies
successive attempts. The default hcid configuration is shipped with \fBmulti\fP
enabled
+.TP
+\fBoffmode\fP noscan|devdown
+
+\fInoscan\fP means that page and inquiry scans are disabled when you call
+SetMode("off"). \fIdevdown\fP sets the adapter into down state (same what
+\fIhciconfig hci0 down\fP does).
+
.TP
\fBpasskey\fP "\fIpin\fP"
diff --git a/hcid/hcid.h b/hcid/hcid.h
index e1465cce..3085a7ed 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -89,6 +89,7 @@ struct hcid_opts {
int auto_init;
int security;
int pairing;
+ int offmode;
char *config_file;
@@ -127,6 +128,9 @@ void hci_req_queue_remove(int dev_id, bdaddr_t *dba);
#define HCID_PAIRING_MULTI 1
#define HCID_PAIRING_ONCE 2
+#define HCID_OFFMODE_DEVDOWN 0
+#define HCID_OFFMODE_NOSCAN 1
+
int read_config(char *file);
struct device_opts *alloc_device_opts(char *ref);
diff --git a/hcid/kword.c b/hcid/kword.c
index e96cad20..018caa72 100644
--- a/hcid/kword.c
+++ b/hcid/kword.c
@@ -48,6 +48,7 @@ struct kword cfg_keyword[] = {
{ "autoinit", K_AUTOINIT },
{ "security", K_SECURITY },
{ "pairing", K_PAIRING },
+ { "offmode", K_OFFMODE },
{ "pkt_type", K_PTYPE },
{ "lm", K_LM },
{ "lp", K_LP },
@@ -81,6 +82,12 @@ struct kword pair_param[] = {
{ NULL , 0 }
};
+struct kword off_param[] = {
+ { "devdown", HCID_OFFMODE_DEVDOWN },
+ { "noscan", HCID_OFFMODE_NOSCAN },
+ { NULL , 0 }
+};
+
int lineno;
int find_keyword(struct kword *kw, char *str)
diff --git a/hcid/kword.h b/hcid/kword.h
index 63ff5133..9457c9ca 100644
--- a/hcid/kword.h
+++ b/hcid/kword.h
@@ -32,5 +32,6 @@ extern int lineno;
extern struct kword cfg_keyword[];
extern struct kword sec_param[];
extern struct kword pair_param[];
+extern struct kword off_param[];
int find_keyword(struct kword *kw, char *str);
diff --git a/hcid/main.c b/hcid/main.c
index 2ca34681..ce3c527e 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -620,6 +620,7 @@ int main(int argc, char *argv[])
hcid.config_file = HCID_CONFIG_FILE;
hcid.security = HCID_SEC_AUTO;
hcid.pairing = HCID_PAIRING_MULTI;
+ hcid.offmode = HCID_OFFMODE_NOSCAN;
if (gethostname(hcid.host_name, sizeof(hcid.host_name) - 1) < 0)
strcpy(hcid.host_name, "noname");
diff --git a/hcid/parser.y b/hcid/parser.y
index 0a162b36..890dbd3a 100644
--- a/hcid/parser.y
+++ b/hcid/parser.y
@@ -60,7 +60,7 @@ void yylex_destroy(void);
}
%token K_OPTIONS K_DEVICE
-%token K_AUTOINIT K_SECURITY K_PAIRING
+%token K_AUTOINIT K_SECURITY K_PAIRING K_OFFMODE
%token K_PTYPE K_NAME K_CLASS K_VOICE K_PAGETO K_LM K_LP K_ISCAN K_PSCAN K_DISCOVTO
%token K_PASSKEY
%token K_YES K_NO
@@ -68,7 +68,7 @@ void yylex_destroy(void);
%token <str> WORD PATH STRING LIST HCI BDADDR
%token <num> NUM
-%type <num> bool pkt_type link_mode link_policy sec_mode pair_mode
+%type <num> bool pkt_type link_mode link_policy sec_mode pair_mode off_mode
%type <str> dev_name hci bdaddr
%%
@@ -116,6 +116,10 @@ hcid_opt:
hcid.pairing = $2;
}
+ | K_OFFMODE off_mode {
+ hcid.offmode = $2;
+ }
+
| K_PASSKEY STRING {
strncpy((char *) hcid.pin_code, $2, 16);
hcid.pin_len = strlen($2);
@@ -155,6 +159,17 @@ pair_mode:
}
;
+off_mode:
+ WORD {
+ int opt = find_keyword(off_param, $1);
+ if (opt < 0) {
+ cfg_error("Unknown off mode '%s'", $1);
+ $$ = 0;
+ } else
+ $$ = opt;
+ }
+ ;
+
device_options: '{' device_opts '}';
device_opts: | device_opt ';' | error ';' | device_opts device_opt ';';