static int cras_hsp_ag_new_connection(DBusConnection *conn, struct cras_bt_profile *profile, struct cras_bt_device *device, int rfcomm_fd) { struct audio_gateway *ag; if (has_audio_gateway(device)) { syslog(LOG_ERR, "Audio gateway exists when %s connects for profile %s", cras_bt_device_name(device), profile->name); close(rfcomm_fd); return 0; } if (check_for_conflict_ag(device)) return -1; cras_bt_device_set_append_iodev_cb(device, possibly_remove_conflict_dev); ag = (struct audio_gateway *)calloc(1, sizeof(*ag)); ag->device = device; ag->conn = conn; ag->profile = cras_bt_device_profile_from_uuid(profile->uuid); ag->slc_handle = hfp_slc_create(rfcomm_fd, 1, device, NULL, cras_hfp_ag_slc_disconnected); DL_APPEND(connected_ags, ag); cras_hfp_ag_slc_initialized(ag->slc_handle); return 0; }
void cras_bt_transport_fill_properties(struct cras_bt_transport *transport, int fd, const char *uuid) { transport->device = cras_bt_device_get(transport->object_path); transport->profile = cras_bt_device_profile_from_uuid(uuid); free(transport->configuration); /* For HFP, the configuration is just the file descriptor of * the rfcomm socket */ transport->configuration = (int *)malloc(sizeof(fd)); memcpy(transport->configuration, &fd, sizeof(fd)); transport->configuration_len = sizeof(fd); }
void cras_bt_transport_update_properties( struct cras_bt_transport *transport, DBusMessageIter *properties_array_iter, DBusMessageIter *invalidated_array_iter) { while (dbus_message_iter_get_arg_type(properties_array_iter) != DBUS_TYPE_INVALID) { DBusMessageIter properties_dict_iter, variant_iter; const char *key; int type; dbus_message_iter_recurse(properties_array_iter, &properties_dict_iter); dbus_message_iter_get_basic(&properties_dict_iter, &key); dbus_message_iter_next(&properties_dict_iter); dbus_message_iter_recurse(&properties_dict_iter, &variant_iter); type = dbus_message_iter_get_arg_type(&variant_iter); if (type == DBUS_TYPE_STRING) { const char *value; dbus_message_iter_get_basic(&variant_iter, &value); if (strcmp(key, "UUID") == 0) { transport->profile = cras_bt_device_profile_from_uuid(value); } else if (strcmp(key, "State") == 0) { enum cras_bt_transport_state old_state = transport->state; transport->state = cras_bt_transport_state_from_string( value); if (transport->state != old_state) cras_bt_transport_state_changed( transport); } } else if (type == DBUS_TYPE_BYTE) { int value; dbus_message_iter_get_basic(&variant_iter, &value); if (strcmp(key, "Codec") == 0) transport->codec = value; } else if (type == DBUS_TYPE_OBJECT_PATH) { const char *obj_path; /* Property: object Device [readonly] */ dbus_message_iter_get_basic(&variant_iter, &obj_path); transport->device = cras_bt_device_get(obj_path); if (!transport->device) { syslog(LOG_ERR, "Device %s not found at update" "transport properties", obj_path); transport->device = cras_bt_device_create(transport->conn, obj_path); cras_bt_transport_update_device(transport); } } else if (strcmp( dbus_message_iter_get_signature(&variant_iter), "ay") == 0 && strcmp(key, "Configuration") == 0) { DBusMessageIter value_iter; char *value; int len; dbus_message_iter_recurse(&variant_iter, &value_iter); dbus_message_iter_get_fixed_array(&value_iter, &value, &len); free(transport->configuration); transport->configuration_len = 0; transport->configuration = malloc(len); if (transport->configuration) { memcpy(transport->configuration, value, len); transport->configuration_len = len; } } else if (strcmp(key, "Volume") == 0) { uint16_t volume; dbus_message_iter_get_basic(&variant_iter, &volume); transport->volume = volume; cras_bt_transport_update_device(transport); } dbus_message_iter_next(properties_array_iter); } while (invalidated_array_iter && dbus_message_iter_get_arg_type(invalidated_array_iter) != DBUS_TYPE_INVALID) { const char *key; dbus_message_iter_get_basic(invalidated_array_iter, &key); if (strcmp(key, "Device") == 0) { transport->device = NULL; } else if (strcmp(key, "UUID") == 0) { transport->profile = 0; } else if (strcmp(key, "State") == 0) { transport->state = CRAS_BT_TRANSPORT_STATE_IDLE; } else if (strcmp(key, "Codec") == 0) { transport->codec = 0; } else if (strcmp(key, "Configuration") == 0) { free(transport->configuration); transport->configuration = NULL; transport->configuration_len = 0; } dbus_message_iter_next(invalidated_array_iter); } }