diff options
| -rw-r--r-- | hcid/hcid.h | 1 | ||||
| -rw-r--r-- | hcid/security.c | 35 | ||||
| -rw-r--r-- | hcid/storage.c | 16 | 
3 files changed, 41 insertions, 11 deletions
| diff --git a/hcid/hcid.h b/hcid/hcid.h index a09c5198..a51f2699 100644 --- a/hcid/hcid.h +++ b/hcid/hcid.h @@ -152,6 +152,7 @@ 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_lastused_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 633583c8..89cc4cd1 100644 --- a/hcid/security.c +++ b/hcid/security.c @@ -97,6 +97,28 @@ static inline int get_bdaddr(int dev, bdaddr_t *sba, uint16_t handle, bdaddr_t *  	return -ENOENT;  } +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 update_lastused(bdaddr_t *sba, bdaddr_t *dba) +{ +	time_t t; +	struct tm *tm; + +	t = time(NULL); +	tm = gmtime(&t); + +	write_lastused_info(sba, dba, tm); +} +  /* Link Key handling */  static void link_key_request(int dev, bdaddr_t *sba, bdaddr_t *dba) @@ -423,17 +445,6 @@ 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++; @@ -544,6 +555,8 @@ static inline void conn_complete(int dev, bdaddr_t *sba, void *ptr)  	if (evt->status)  		return; +	update_lastused(sba, &evt->bdaddr); +  	name_resolve(dev, &evt->bdaddr);  	hcid_dbus_conn_complete(sba, &evt->bdaddr); diff --git a/hcid/storage.c b/hcid/storage.c index 063b6952..a553ae96 100644 --- a/hcid/storage.c +++ b/hcid/storage.c @@ -137,6 +137,22 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)  	return textfile_put(filename, addr, str);  } +int write_lastused_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/lastused", 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]; | 
