diff options
-rw-r--r-- | hcid/hcid.h | 2 | ||||
-rw-r--r-- | hcid/security.c | 20 | ||||
-rw-r--r-- | hcid/storage.c | 17 |
3 files changed, 39 insertions, 0 deletions
diff --git a/hcid/hcid.h b/hcid/hcid.h index 482cf589..a09c5198 100644 --- a/hcid/hcid.h +++ b/hcid/hcid.h @@ -23,6 +23,7 @@ * */ +#include <time.h> #include <syslog.h> #include <sys/types.h> #include <sys/ioctl.h> @@ -150,6 +151,7 @@ int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name); int read_device_name(bdaddr_t *local, bdaddr_t *peer, char *name); int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver); int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *features); +int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm); int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, int type); int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key); int read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin); diff --git a/hcid/security.c b/hcid/security.c index f4b46bfe..c3c8caeb 100644 --- a/hcid/security.c +++ b/hcid/security.c @@ -38,6 +38,7 @@ #include <signal.h> #include <syslog.h> #include <time.h> +#include <sys/time.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -422,6 +423,17 @@ static inline void inquiry_complete(int dev, bdaddr_t *sba, void *ptr) hcid_dbus_inquiry_complete(sba); } +static inline void update_lastseen(bdaddr_t *sba, bdaddr_t *dba) +{ + time_t t; + struct tm *tm; + + t = time(NULL); + tm = gmtime(&t); + + write_lastseen_info(sba, dba, tm); +} + static inline void inquiry_result(int dev, bdaddr_t *sba, int plen, void *ptr) { uint8_t num = *(uint8_t *) ptr++; @@ -435,6 +447,8 @@ static inline void inquiry_result(int dev, bdaddr_t *sba, int plen, void *ptr) hcid_dbus_inquiry_result(sba, &info->bdaddr, class, 0); + update_lastseen(sba, &info->bdaddr); + ptr += INQUIRY_INFO_SIZE; } } @@ -457,6 +471,8 @@ static inline void inquiry_result_with_rssi(int dev, bdaddr_t *sba, int plen, vo hcid_dbus_inquiry_result(sba, &info->bdaddr, class, info->rssi); + update_lastseen(sba, &info->bdaddr); + ptr += INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE; } } else { @@ -469,6 +485,8 @@ static inline void inquiry_result_with_rssi(int dev, bdaddr_t *sba, int plen, vo hcid_dbus_inquiry_result(sba, &info->bdaddr, class, info->rssi); + update_lastseen(sba, &info->bdaddr); + ptr += INQUIRY_INFO_WITH_RSSI_SIZE; } } @@ -487,6 +505,8 @@ static inline void extended_inquiry_result(int dev, bdaddr_t *sba, int plen, voi hcid_dbus_inquiry_result(sba, &info->bdaddr, class, info->rssi); + update_lastseen(sba, &info->bdaddr); + ptr += EXTENDED_INQUIRY_INFO_SIZE; } } diff --git a/hcid/storage.c b/hcid/storage.c index 02c5dc0c..063b6952 100644 --- a/hcid/storage.c +++ b/hcid/storage.c @@ -32,6 +32,7 @@ #include <unistd.h> #include <stdlib.h> #include <malloc.h> +#include <time.h> #include <sys/file.h> #include <sys/stat.h> #include <sys/param.h> @@ -120,6 +121,22 @@ int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *features return textfile_put(filename, addr, str); } +int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm) +{ + char filename[PATH_MAX + 1], addr[18], str[24]; + + memset(str, 0, sizeof(str)); + strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm); + + ba2str(local, addr); + snprintf(filename, PATH_MAX, "%s/%s/lastseen", STORAGEDIR, addr); + + create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + ba2str(peer, addr); + return textfile_put(filename, addr, str); +} + int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, int type) { char filename[PATH_MAX + 1], addr[18], str[35]; |