summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMax Krasnyansky <maxk@qualcomm.com>2002-06-24 02:38:01 +0000
committerMax Krasnyansky <maxk@qualcomm.com>2002-06-24 02:38:01 +0000
commitf79b2c879c633667916d1fb17870c54597294d8e (patch)
tree02480d88917cd8dd1a92ad28ab7d4f8db229d5b2 /hcid
parent917527a5cc61d76032060aeca74deecac58da2a1 (diff)
Link key handling rewrite. Remove max link key limit.
Keep key database updated. Minor cleanup.
Diffstat (limited to 'hcid')
-rw-r--r--hcid/hcid.conf2
-rw-r--r--hcid/hcid.h65
-rw-r--r--hcid/kword.c40
-rw-r--r--hcid/lexer.l40
-rw-r--r--hcid/lib.c42
-rw-r--r--hcid/lib.h86
-rw-r--r--hcid/main.c53
-rw-r--r--hcid/parser.y40
-rw-r--r--hcid/security.c266
9 files changed, 285 insertions, 349 deletions
diff --git a/hcid/hcid.conf b/hcid/hcid.conf
index cfd06e5f..784e1d97 100644
--- a/hcid/hcid.conf
+++ b/hcid/hcid.conf
@@ -31,7 +31,7 @@ device {
class 0x100;
# Default packet type
- pkt_type DH1,DM1,HV1;
+ #pkt_type DH1,DM1,HV1;
# Inquiry and Page scan
iscan enable; pscan enable;
diff --git a/hcid/hcid.h b/hcid/hcid.h
index 677a02dd..40dc6ad0 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -1,24 +1,24 @@
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
* $Id$
@@ -34,8 +34,6 @@
#define HCID_PIN_FILE "/etc/bluetooth/pin"
#define HCID_KEY_FILE "/etc/bluetooth/link_key"
#define HCID_PIN_HELPER "/bin/bluepin"
-#define HCID_KEY_NUM 20
-#define HCID_KEY_TTL 172800 /* 2 days */
struct device_opts {
char *name;
@@ -58,22 +56,20 @@ struct link_key {
};
struct hcid_opts {
- char *host_name;
- int auto_init;
- int security;
+ char *host_name;
+ int auto_init;
+ int security;
- char *config_file;
+ char *config_file;
- uint8_t pin_code[16];
- int pin_len;
- char *pin_helper;
- char *pin_file;
+ uint8_t pin_code[16];
+ int pin_len;
+ char *pin_helper;
+ char *pin_file;
- struct link_key **link_key;
- int key_num;
- char *key_file;
+ char *key_file;
- int sock;
+ int sock;
};
extern struct hcid_opts hcid;
@@ -88,5 +84,4 @@ gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data);
void start_security_manager(int hdev);
void stop_security_manager(int hdev);
-void save_link_keys(void);
void flush_link_keys(void);
diff --git a/hcid/kword.c b/hcid/kword.c
index a496591f..cc69db39 100644
--- a/hcid/kword.c
+++ b/hcid/kword.c
@@ -1,24 +1,24 @@
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
* $Id$
diff --git a/hcid/lexer.l b/hcid/lexer.l
index a7af9c63..85cd5780 100644
--- a/hcid/lexer.l
+++ b/hcid/lexer.l
@@ -1,25 +1,25 @@
%{
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
diff --git a/hcid/lib.c b/hcid/lib.c
index ac47603d..2e310012 100644
--- a/hcid/lib.c
+++ b/hcid/lib.c
@@ -1,24 +1,24 @@
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
* $Id$
@@ -95,7 +95,7 @@ char * expand_name(char *dst, char *str, int dev_id)
}
/* Returns current host name */
-char * get_host_name(void)
+char *get_host_name(void)
{
char name[40];
diff --git a/hcid/lib.h b/hcid/lib.h
index 4683c0ff..17f21a71 100644
--- a/hcid/lib.h
+++ b/hcid/lib.h
@@ -1,24 +1,24 @@
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
* $Id$
@@ -26,9 +26,9 @@
#include <errno.h>
-char * expand_name(char *dst, char *str, int dev_id);
+char *expand_name(char *dst, char *str, int dev_id);
-char * get_host_name(void);
+char *get_host_name(void);
void init_title(int argc, char *argv[], char *env[], const char *name);
void set_title(const char *ftm, ...);
@@ -49,36 +49,40 @@ static inline void io_cancel(void)
/* Read exactly len bytes (Signal safe)*/
static inline int read_n(int fd, void *buf, int len)
{
- register int t=0, w;
+ register int t = 0, w;
while (!__io_canceled && len > 0) {
- if( (w = read(fd, buf, len)) < 0 ){
- if( errno == EINTR || errno == EAGAIN )
- continue;
- return -1;
- }
- if( !w )
- return 0;
- len -= w; buf += w; t += w;
+ if ((w = read(fd, buf, len)) < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ return -1;
+ }
+ if (!w)
+ return 0;
+ len -= w;
+ buf += w;
+ t += w;
}
return t;
-}
+}
/* Write exactly len bytes (Signal safe)*/
static inline int write_n(int fd, void *buf, int len)
{
- register int t=0, w;
+ register int t = 0, w;
while (!__io_canceled && len > 0) {
- if( (w = write(fd, buf, len)) < 0 ){
- if( errno == EINTR || errno == EAGAIN )
- continue;
- return -1;
- }
- if( !w )
- return 0;
- len -= w; buf += w; t += w;
+ if ((w = write(fd, buf, len)) < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ return -1;
+ }
+ if (!w)
+ return 0;
+ len -= w;
+ buf += w;
+ t += w;
}
return t;
diff --git a/hcid/main.c b/hcid/main.c
index 6b0a4067..1f2537fb 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -1,24 +1,24 @@
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
* $Id$
@@ -38,11 +38,11 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
-#include <asm/types.h>
+#include <sys/stat.h>
-#include <bluetooth.h>
-#include <hci.h>
-#include <hci_lib.h>
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
#include <glib.h>
@@ -359,7 +359,6 @@ int main(int argc, char *argv[], char *env[])
hcid.pin_file = strdup(HCID_PIN_FILE);
hcid.pin_helper = strdup(HCID_PIN_HELPER);
hcid.key_file = strdup(HCID_KEY_FILE);
- hcid.key_num = HCID_KEY_NUM;
init_defaults();
@@ -393,6 +392,8 @@ int main(int argc, char *argv[], char *env[])
chdir("/");
}
+ umask(0077);
+
init_title(argc, argv, env, "hcid: ");
set_title("initializing");
@@ -453,8 +454,6 @@ int main(int argc, char *argv[], char *env[])
/* Start event processor */
g_main_run(event_loop);
- save_link_keys();
-
syslog(LOG_INFO, "Exit.");
return 0;
}
diff --git a/hcid/parser.y b/hcid/parser.y
index e8be6c99..ff2cd1c6 100644
--- a/hcid/parser.y
+++ b/hcid/parser.y
@@ -1,25 +1,25 @@
%{
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
diff --git a/hcid/security.c b/hcid/security.c
index f87fca5f..a980b500 100644
--- a/hcid/security.c
+++ b/hcid/security.c
@@ -1,24 +1,24 @@
/*
- BlueZ - Bluetooth protocol stack for Linux
- Copyright (C) 2000-2001 Qualcomm Incorporated
-
- Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
- OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
- USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
- TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
+ BlueZ - Bluetooth protocol stack for Linux
+ Copyright (C) 2000-2001 Qualcomm Incorporated
+
+ Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation;
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+ OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
+ USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS,
+ TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.
*/
/*
* $Id$
@@ -42,9 +42,9 @@
#include <sys/stat.h>
#include <asm/types.h>
-#include <bluetooth.h>
-#include <hci.h>
-#include <hci_lib.h>
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
#include <glib.h>
@@ -53,75 +53,104 @@
static GIOChannel *io_chan[HCI_MAX_DEV];
-void save_link_keys(void)
+/* Link Key handling */
+
+void flush_link_keys(void)
{
- int n, f;
+ syslog(LOG_INFO, "Flushing link key database");
+ truncate(hcid.key_file, 0);
+}
- syslog(LOG_INFO, "Saving link key database");
+/* This function is not reentrable */
+static struct link_key *get_link_key(bdaddr_t *sba, bdaddr_t *dba)
+{
+ static struct link_key k;
+ struct link_key *key = NULL;
+ int f, r;
- umask(0077);
- if (!(f = open(hcid.key_file, O_WRONLY | O_CREAT | O_TRUNC, 0))) {
- syslog(LOG_ERR, "Can't save key database %s. %s(%d)",
- hcid.key_file, strerror(errno), errno);
- return;
+ f = open(hcid.key_file, O_RDONLY);
+ if (f < 0) {
+ if (errno != ENOENT)
+ syslog(LOG_ERR, "Link key database open failed. %s(%d)",
+ strerror(errno), errno);
+ return NULL;
}
- for (n = 0; n < hcid.key_num; n++) {
- if (!hcid.link_key[n])
- continue;
+ while ((r = read_n(f, &k, sizeof(k)))) {
+ if (r < 0) {
+ syslog(LOG_ERR, "Link key database read failed. %s(%d)",
+ strerror(errno), errno);
+ break;
+ }
- if (write_n(f, hcid.link_key[n], sizeof(struct link_key)) < 0)
+ if (!bacmp(&k.sba, sba) && !bacmp(&k.dba, dba)) {
+ key = &k;
break;
+ }
}
close(f);
+ return key;
}
-void flush_link_keys(void)
+static void link_key_request(int dev, bdaddr_t *sba, bdaddr_t *dba)
{
- int n;
-
- syslog(LOG_INFO, "Flushing link key database");
+ struct link_key *key = get_link_key(sba, dba);
- for (n=0; n < hcid.key_num; n++) {
- if (hcid.link_key[n]) {
- free(hcid.link_key[n]);
- hcid.link_key[n] = NULL;
- }
+ if (key) {
+ /* Link key found */
+ link_key_reply_cp lr;
+ memcpy(lr.link_key, key->key, 16);
+ bacpy(&lr.bdaddr, dba);
+ hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_REPLY,
+ LINK_KEY_REPLY_CP_SIZE, &lr);
+ key->time = time(0);
+ } else {
+ /* Link key not found */
+ hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_NEG_REPLY, 6, dba);
}
}
-int read_link_keys(void)
+static void save_link_key(struct link_key *key)
{
- int f, n = 0;
+ char sa[40], da[40];
+ int f;
- if (!(f = open(hcid.key_file, O_RDONLY))) {
- syslog(LOG_ERR, "Can't open key database %s. %s(%d)",
- hcid.key_file, strerror(errno), errno);
- return -1;
+ f = open(hcid.key_file, O_WRONLY | O_CREAT | O_APPEND, 0);
+ if (f < 0) {
+ syslog(LOG_ERR, "Link key database open failed. %s(%d)",
+ strerror(errno), errno);
+ return;
}
- while (n < hcid.key_num) {
- struct link_key *key;
- int r;
+ if (write_n(f, key, sizeof(*key)) < 0) {
+ syslog(LOG_ERR, "Link key database write failed. %s(%d)",
+ strerror(errno), errno);
+ }
- key = malloc(sizeof(*key));
- if (!key)
- continue;
+ close(f);
- r = read_n(f, key, sizeof(*key));
- if (r <= 0) {
- free(key);
- break;
- }
+ ba2str(&key->sba, sa); ba2str(&key->dba, da);
+ syslog(LOG_INFO, "Saving link key %s %s", sa, da);
+}
- hcid.link_key[n++] = key;
- }
+static void link_key_notify(int dev, bdaddr_t *sba, void *ptr)
+{
+ evt_link_key_notify *evt = ptr;
+ bdaddr_t *dba = &evt->bdaddr;
+ struct link_key key;
- close(f);
- return n;
+ memcpy(key.key, evt->link_key, 16);
+ bacpy(&key.sba, sba);
+ bacpy(&key.dba, dba);
+ key.type = evt->key_type;
+ key.time = time(0);
+
+ save_link_key(&key);
}
+/* PIN code handling */
+
int read_pin_code(void)
{
char buf[17];
@@ -225,36 +254,6 @@ reject:
exit(0);
}
-static void link_key_request(int dev, bdaddr_t *sba, bdaddr_t *dba)
-{
- struct link_key *key = NULL;
- int n;
-
- /* Find the key */
- for (n=0; n < hcid.key_num; n++) {
- if (!hcid.link_key[n])
- continue;
- if (!bacmp(&hcid.link_key[n]->sba, sba) &&
- !bacmp(&hcid.link_key[n]->dba, dba)) {
- key = hcid.link_key[n];
- break;
- }
- }
-
- if (key) {
- /* Link key found */
- link_key_reply_cp lr;
- memcpy(lr.link_key, key->key, 16);
- bacpy(&lr.bdaddr, dba);
- hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_REPLY,
- LINK_KEY_REPLY_CP_SIZE, &lr);
- key->time = time(0);
- } else {
- /* Link key not found */
- hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_NEG_REPLY, 6, dba);
- }
-}
-
static void pin_code_request(int dev, bdaddr_t *ba)
{
struct hci_conn_info_req *cr;
@@ -300,60 +299,6 @@ static void pin_code_request(int dev, bdaddr_t *ba)
free(cr);
}
-static void link_key_notify(int dev, bdaddr_t *sba, void *ptr)
-{
- evt_link_key_notify *evt = ptr;
- bdaddr_t *dba = &evt->bdaddr;
- struct link_key *key;
- time_t tm, td, ot;
- int n, k = -1, ek = -1;
-
- tm = time(0); ot = HCID_KEY_TTL;
-
- /* Find an empty slot or the oldest key */
- for (n=0; n < hcid.key_num; n++) {
- key = hcid.link_key[n];
- if (!key || (!bacmp(&key->sba, sba) && !bacmp(&key->dba, dba))) {
- k = n;
- break;
- }
-
- td = tm - key->time;
- if (td > ot) {
- ot = td;
- ek = n;
- }
- }
-
- if (k == -1 && ek != -1)
- k = ek;
-
- if (k != -1) {
- char sa[40], da[40];
-
- /* Update link key */
- key = hcid.link_key[k];
- if (!key && !(key = malloc(sizeof(*key)))) {
- syslog(LOG_ERR, "Can't allocate link key memory. %s(%d)",
- strerror(errno), errno);
- return;
- }
-
- ba2str(sba, sa); ba2str(dba, da);
- syslog(LOG_INFO, "Storing link key %s %s", sa, da);
-
- bacpy(&key->sba, sba);
- bacpy(&key->dba, dba);
- memcpy(key->key, evt->link_key, 16);
- key->type = evt->key_type;
- key->time = tm;
-
- hcid.link_key[k] = key;
- } else
- syslog(LOG_ERR, "No slot available for a link key.");
-
-}
-
gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
@@ -407,19 +352,14 @@ gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
return TRUE;
}
-int init_security_data(void)
+static void init_security_data(void)
{
- void *buf;
-
- buf = calloc(hcid.key_num, sizeof(void*));
- if (!buf) {
- syslog(LOG_ERR, "Can't allocate link key database. %s(%d)",
- strerror(errno), errno);
- return -1;
- }
- hcid.link_key = buf;
- read_link_keys();
+ static int initialized = 0;
+ if (initialized)
+ return;
+ initialized = 1;
+
/* Set local PIN code */
if (hcid.security == HCID_SEC_AUTO) {
if (read_pin_code() < 0) {
@@ -427,8 +367,7 @@ int init_security_data(void)
hcid.pin_len = 5;
}
}
-
- return 0;
+ return;
}
void start_security_manager(int hdev)
@@ -443,8 +382,7 @@ void start_security_manager(int hdev)
syslog(LOG_INFO, "Starting security manager %d", hdev);
- if (!hcid.link_key && init_security_data())
- return;
+ init_security_data();
if ((dev = hci_open_dev(hdev)) < 0) {
syslog(LOG_ERR, "Can't open device hci%d. %s(%d)",