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; }
struct cras_iodev *hfp_iodev_create( enum CRAS_STREAM_DIRECTION dir, struct cras_bt_device *device, struct hfp_slc_handle *slc, enum cras_bt_device_profile profile, struct hfp_info *info) { struct hfp_io *hfpio; struct cras_iodev *iodev; struct cras_ionode *node; const char *name; hfpio = (struct hfp_io *)calloc(1, sizeof(*hfpio)); if (!hfpio) goto error; iodev = &hfpio->base; iodev->direction = dir; hfpio->device = device; hfpio->slc = slc; /* Set iodev's name to device readable name or the address. */ name = cras_bt_device_name(device); if (!name) name = cras_bt_device_object_path(device); snprintf(iodev->info.name, sizeof(iodev->info.name), "%s", name); iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = 0; iodev->info.stable_id = SuperFastHash( cras_bt_device_object_path(device), strlen(cras_bt_device_object_path(device)), strlen(cras_bt_device_object_path(device))); iodev->open_dev= open_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; iodev->get_buffer = get_buffer; iodev->put_buffer = put_buffer; iodev->flush_buffer = flush_buffer; iodev->close_dev = close_dev; iodev->update_supported_formats = update_supported_formats; iodev->update_active_node = update_active_node; iodev->set_volume = set_hfp_volume; node = (struct cras_ionode *)calloc(1, sizeof(*node)); node->dev = iodev; strcpy(node->name, iodev->info.name); node->plugged = 1; node->type = CRAS_NODE_TYPE_BLUETOOTH; node->volume = 100; gettimeofday(&node->plugged_time, NULL); cras_bt_device_append_iodev(device, iodev, profile); cras_iodev_add_node(iodev, node); cras_iodev_set_active_node(iodev, node); hfpio->info = info; hfp_register_packet_size_changed_callback(info, hfp_packet_size_changed, hfpio); return iodev; error: if (hfpio) { hfp_free_resources(hfpio); free(hfpio); } return NULL; }