static void dump_properties(int num_properties, bt_property_t *properties) { int i; for (i = 0; i < num_properties; i++) { /* * properities sometimes come unaligned hence memcp to * aligned buffer */ bt_property_t prop; memcpy(&prop, properties + i, sizeof(prop)); haltest_info("prop: %s\n", btproperty2str(&prop)); } }
static int set_adapter_property(const bt_property_t *property) { char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len]; struct hal_cmd_set_adapter_prop *cmd = (void *) buf; DBG("prop: %s", btproperty2str(property)); if (!interface_ready()) return BT_STATUS_NOT_READY; adapter_prop_from_hal(property, &cmd->type, &cmd->len, cmd->val); return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP, sizeof(*cmd) + cmd->len, cmd, 0, NULL, NULL); }
static void adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop, uint8_t num_props, uint16_t len) { void *buf = prop; uint8_t i; for (i = 0; i < num_props; i++) { if (sizeof(*prop) + prop->len > len) { error("invalid adapter properties(%zu > %u), aborting", sizeof(*prop) + prop->len, len); exit(EXIT_FAILURE); } send_props[i].type = prop->type; switch (prop->type) { case HAL_PROP_ADAPTER_TYPE: enum_prop_to_hal(send_props[i], prop, bt_device_type_t); break; case HAL_PROP_ADAPTER_SCAN_MODE: enum_prop_to_hal(send_props[i], prop, bt_scan_mode_t); break; case HAL_PROP_ADAPTER_SERVICE_REC: default: send_props[i].len = prop->len; send_props[i].val = prop->val; break; } DBG("prop[%d]: %s", i, btproperty2str(&send_props[i])); len -= sizeof(*prop) + prop->len; buf += sizeof(*prop) + prop->len; prop = buf; } if (!len) return; error("invalid adapter properties (%u bytes left), aborting", len); exit(EXIT_FAILURE); }
static void device_props_to_hal(bt_property_t *send_props, struct hal_property *prop, uint8_t num_props, uint16_t len) { void *buf = prop; uint8_t i; for (i = 0; i < num_props; i++) { if (sizeof(*prop) + prop->len > len) { error("invalid device properties (%zu > %u), aborting", sizeof(*prop) + prop->len, len); exit(EXIT_FAILURE); } send_props[i].type = prop->type; switch (prop->type) { case HAL_PROP_DEVICE_TYPE: enum_prop_to_hal(send_props[i], prop, bt_device_type_t); break; case HAL_PROP_DEVICE_VERSION_INFO: { static bt_remote_version_t e; const struct hal_prop_device_info *p; send_props[i].val = &e; send_props[i].len = sizeof(e); p = (struct hal_prop_device_info *) prop->val; e.manufacturer = p->manufacturer; e.sub_ver = p->sub_version; e.version = p->version; } break; case HAL_PROP_DEVICE_SERVICE_REC: { static bt_service_record_t e; const struct hal_prop_device_service_rec *p; send_props[i].val = &e; send_props[i].len = sizeof(e); p = (struct hal_prop_device_service_rec *) prop->val; memset(&e, 0, sizeof(e)); memcpy(&e.channel, &p->channel, sizeof(e.channel)); memcpy(e.uuid.uu, p->uuid, sizeof(e.uuid.uu)); memcpy(e.name, p->name, p->name_len); } break; default: send_props[i].len = prop->len; send_props[i].val = prop->val; break; } len -= sizeof(*prop) + prop->len; buf += sizeof(*prop) + prop->len; prop = buf; DBG("prop[%d]: %s", i, btproperty2str(&send_props[i])); } if (!len) return; error("invalid device properties (%u bytes left), aborting", len); exit(EXIT_FAILURE); }