aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-01-18 01:27:20 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2012-01-18 01:27:20 +0200
commit26a2456f1f3a075b1a4b94454dcc6f13274b7c03 (patch)
treefe5552d4dc0e2c6465d1722817232dc10bc3a84e
parentcacfa7e3a408583614d029a532858367fff1ddac (diff)
downloadbluez-26a2456f1f3a075b1a4b94454dcc6f13274b7c03.tar.gz
bluez-26a2456f1f3a075b1a4b94454dcc6f13274b7c03.tar.xz
bluez-26a2456f1f3a075b1a4b94454dcc6f13274b7c03.zip
hciops: Encode class of device data into EIR
-rw-r--r--plugins/hciops.c62
-rw-r--r--plugins/mgmtops.c15
-rw-r--r--src/adapter.c11
-rw-r--r--src/adapter.h3
-rw-r--r--src/event.c8
-rw-r--r--src/event.h4
6 files changed, 52 insertions, 51 deletions
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 86589ad2..f1eb1a23 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -1949,8 +1949,8 @@ static inline void remote_version_information(int index, void *ptr)
}
static void dev_found(struct dev_info *info, bdaddr_t *dba, addr_type_t type,
- uint32_t cod, int8_t rssi, uint8_t cfm_name,
- uint8_t *eir, uint8_t eir_len)
+ uint8_t *cod, int8_t rssi, uint8_t cfm_name,
+ uint8_t *eir, size_t eir_len)
{
struct found_dev *dev;
GSList *match;
@@ -1969,10 +1969,14 @@ static void dev_found(struct dev_info *info, bdaddr_t *dba, addr_type_t type,
else
dev->name_state = NAME_NOT_NEEDED;
+ if (cod && !eir_has_data_type(eir, eir_len, EIR_CLASS_OF_DEV))
+ eir_len = eir_append_data(eir, eir_len, EIR_CLASS_OF_DEV,
+ cod, 3);
+
info->found_devs = g_slist_prepend(info->found_devs, dev);
event:
- btd_event_device_found(&info->bdaddr, dba, type, cod, rssi, cfm_name,
+ btd_event_device_found(&info->bdaddr, dba, type, rssi, cfm_name,
eir, eir_len);
}
@@ -1984,12 +1988,11 @@ static inline void inquiry_result(int index, int plen, void *ptr)
for (i = 0; i < num; i++) {
inquiry_info *info = ptr;
- uint32_t class = info->dev_class[0] |
- (info->dev_class[1] << 8) |
- (info->dev_class[2] << 16);
+ uint8_t eir[5];
- dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR, class, 0, 1,
- NULL, 0);
+ memset(eir, 0, sizeof(eir));
+ dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR, info->dev_class,
+ 0, 1, eir, 0);
ptr += INQUIRY_INFO_SIZE;
}
}
@@ -1998,6 +2001,7 @@ static inline void inquiry_result_with_rssi(int index, int plen, void *ptr)
{
struct dev_info *dev = &devs[index];
uint8_t num = *(uint8_t *) ptr++;
+ uint8_t eir[5];
int i;
if (!num)
@@ -2006,23 +2010,21 @@ static inline void inquiry_result_with_rssi(int index, int plen, void *ptr)
if ((plen - 1) / num == INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE) {
for (i = 0; i < num; i++) {
inquiry_info_with_rssi_and_pscan_mode *info = ptr;
- uint32_t class = info->dev_class[0]
- | (info->dev_class[1] << 8)
- | (info->dev_class[2] << 16);
- dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR, class,
- info->rssi, 1, NULL, 0);
+ memset(eir, 0, sizeof(eir));
+ dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR,
+ info->dev_class, info->rssi,
+ 1, eir, 0);
ptr += INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE;
}
} else {
for (i = 0; i < num; i++) {
inquiry_info_with_rssi *info = ptr;
- uint32_t class = info->dev_class[0]
- | (info->dev_class[1] << 8)
- | (info->dev_class[2] << 16);
- dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR, class,
- info->rssi, 1, NULL, 0);
+ memset(eir, 0, sizeof(eir));
+ dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR,
+ info->dev_class, info->rssi,
+ 1, eir, 0);
ptr += INQUIRY_INFO_WITH_RSSI_SIZE;
}
}
@@ -2036,20 +2038,22 @@ static inline void extended_inquiry_result(int index, int plen, void *ptr)
for (i = 0; i < num; i++) {
extended_inquiry_info *info = ptr;
- uint32_t class = info->dev_class[0]
- | (info->dev_class[1] << 8)
- | (info->dev_class[2] << 16);
+ uint8_t eir[sizeof(info->data) + 5];
gboolean cfm_name;
+ size_t eir_len;
+
+ eir_len = eir_length(info->data, sizeof(info->data));
+
+ memset(eir, 0, sizeof(eir));
+ memcpy(eir, info->data, eir_len);
- if (eir_has_data_type(info->data, sizeof(info->data),
- EIR_NAME_COMPLETE))
+ if (eir_has_data_type(eir, eir_len, EIR_NAME_COMPLETE))
cfm_name = FALSE;
else
cfm_name = TRUE;
- dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR, class,
- info->rssi, cfm_name,
- info->data, sizeof(info->data));
+ dev_found(dev, &info->bdaddr, ADDR_TYPE_BREDR, info->dev_class,
+ info->rssi, cfm_name, eir, eir_len);
ptr += EXTENDED_INQUIRY_INFO_SIZE;
}
}
@@ -2287,8 +2291,8 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
info = (le_advertising_info *) &meta->data[1];
rssi = *(info->data + info->length);
- dev_found(dev, &info->bdaddr, le_addr_type(info->bdaddr_type), 0, rssi,
- 0, info->data, info->length);
+ dev_found(dev, &info->bdaddr, le_addr_type(info->bdaddr_type), NULL,
+ rssi, 0, info->data, info->length);
num_reports--;
@@ -2298,7 +2302,7 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
rssi = *(info->data + info->length);
dev_found(dev, &info->bdaddr, le_addr_type(info->bdaddr_type),
- 0, rssi, 0, info->data, info->length);
+ NULL, rssi, 0, info->data, info->length);
}
}
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 6d98ad95..c931985d 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1277,7 +1277,6 @@ static void mgmt_device_found(int sk, uint16_t index, void *buf, size_t len)
struct controller_info *info;
char addr[18];
uint8_t *eir;
- uint32_t cls;
if (len != sizeof(*ev)) {
error("mgmt_device_found length %zu instead of expected %zu",
@@ -1292,23 +1291,19 @@ static void mgmt_device_found(int sk, uint16_t index, void *buf, size_t len)
info = &controllers[index];
- cls = ev->dev_class[0] | (ev->dev_class[1] << 8) |
- (ev->dev_class[2] << 16);
-
if (ev->eir[0] == 0)
eir = NULL;
else
eir = ev->eir;
ba2str(&ev->addr.bdaddr, addr);
- DBG("hci%u addr %s, class %u rssi %d cfm_name %u %s", index, addr, cls,
- ev->rssi, ev->confirm_name,
- eir ? "eir" : "");
+ DBG("hci%u addr %s, rssi %d cfm_name %u %s", index, addr, ev->rssi,
+ ev->confirm_name, eir ? "eir" : "");
btd_event_device_found(&info->bdaddr, &ev->addr.bdaddr,
- mgmt_addr_type(ev->addr.type), cls,
- ev->rssi, ev->confirm_name,
- eir, HCI_MAX_EIR_LENGTH);
+ mgmt_addr_type(ev->addr.type),
+ ev->rssi, ev->confirm_name,
+ eir, HCI_MAX_EIR_LENGTH);
}
static void mgmt_discovering(int sk, uint16_t index, void *buf, size_t len)
diff --git a/src/adapter.c b/src/adapter.c
index 2984d80a..7a41df9a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2782,14 +2782,14 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
void adapter_update_found_devices(struct btd_adapter *adapter,
bdaddr_t *bdaddr, addr_type_t type,
- uint32_t class, int8_t rssi,
- uint8_t confirm_name,
+ int8_t rssi, uint8_t confirm_name,
uint8_t *data, uint8_t data_len)
{
struct remote_dev_info *dev;
struct eir_data eir_data;
char *alias, *name;
gboolean legacy, name_known;
+ uint32_t dev_class;
int err;
memset(&eir_data, 0, sizeof(eir_data));
@@ -2799,6 +2799,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
return;
}
+ dev_class = eir_data.dev_class[0] | (eir_data.dev_class[1] << 8) |
+ (eir_data.dev_class[2] << 16);
+ if (dev_class != 0)
+ write_remote_class(&adapter->bdaddr, bdaddr, dev_class);
+
if (eir_data.name != NULL && eir_data.name_complete)
write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
@@ -2846,7 +2851,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
- dev = found_device_new(bdaddr, type, name, alias, class, legacy,
+ dev = found_device_new(bdaddr, type, name, alias, dev_class, legacy,
eir_data.flags);
free(name);
free(alias);
diff --git a/src/adapter.h b/src/adapter.h
index fb1dcdfe..c17cf0c3 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -103,8 +103,7 @@ struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter
bdaddr_t *bdaddr);
void adapter_update_found_devices(struct btd_adapter *adapter,
bdaddr_t *bdaddr, addr_type_t type,
- uint32_t class, int8_t rssi,
- uint8_t confirm_name,
+ int8_t rssi, uint8_t confirm_name,
uint8_t *data, uint8_t data_len);
void adapter_emit_device_found(struct btd_adapter *adapter,
struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index d0e192ba..30666354 100644
--- a/src/event.c
+++ b/src/event.c
@@ -247,9 +247,8 @@ static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
}
void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, addr_type_t type,
- uint32_t class, int8_t rssi,
- uint8_t confirm_name, uint8_t *data,
- uint8_t data_len)
+ int8_t rssi, uint8_t confirm_name,
+ uint8_t *data, uint8_t data_len)
{
struct btd_adapter *adapter;
@@ -260,12 +259,11 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, addr_type_t type,
}
update_lastseen(local, peer);
- write_remote_class(local, peer, class);
if (data)
write_remote_eir(local, peer, data);
- adapter_update_found_devices(adapter, peer, type, class, rssi,
+ adapter_update_found_devices(adapter, peer, type, rssi,
confirm_name, data, data_len);
}
diff --git a/src/event.h b/src/event.h
index 57b7fd9b..7e6c4086 100644
--- a/src/event.h
+++ b/src/event.h
@@ -24,8 +24,8 @@
int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure);
void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, addr_type_t type,
- uint32_t cls, int8_t rssi, uint8_t confirm_name,
- uint8_t *data, uint8_t data_len);
+ int8_t rssi, uint8_t confirm_name,
+ uint8_t *data, uint8_t data_len);
void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
void btd_event_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name);