static int connect_port(struct serial_port *port) { struct serial_device *device = port->device; uuid_t uuid; int err; if (!port->uuid) goto connect; err = bt_string2uuid(&uuid, port->uuid); if (err < 0) return err; sdp_uuid128_to_uuid(&uuid); return bt_search_service(&device->src, &device->dst, &uuid, get_record_cb, port, NULL); connect: port->io = bt_io_connect(BT_IO_RFCOMM, rfcomm_connect_cb, port, NULL, NULL, BT_IO_OPT_SOURCE_BDADDR, &device->src, BT_IO_OPT_DEST_BDADDR, &device->dst, BT_IO_OPT_CHANNEL, port->channel, BT_IO_OPT_INVALID); if (port->io) return 0; return -errno; }
static gboolean service_callback(GIOChannel *io, GIOCondition cond, gpointer user_data) { struct bluetooth_session *session = user_data; sdp_list_t *search, *attrid; uint32_t range = 0x0000ffff; GError *gerr = NULL; uuid_t uuid; if (cond & G_IO_NVAL) return FALSE; if (cond & G_IO_ERR) goto failed; if (sdp_set_notify(session->sdp, search_callback, session) < 0) goto failed; if (bt_string2uuid(&uuid, session->service) < 0) goto failed; sdp_uuid128_to_uuid(&uuid); search = sdp_list_append(NULL, &uuid); attrid = sdp_list_append(NULL, &range); if (sdp_service_search_attr_async(session->sdp, search, SDP_ATTR_REQ_RANGE, attrid) < 0) { sdp_list_free(attrid, NULL); sdp_list_free(search, NULL); goto failed; } sdp_list_free(attrid, NULL); sdp_list_free(search, NULL); g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, process_callback, session); return FALSE; failed: g_io_channel_shutdown(session->io, TRUE, NULL); g_io_channel_unref(session->io); session->io = NULL; g_set_error(&gerr, OBC_BT_ERROR, -EIO, "Unable to find service record"); if (session->func) session->func(session->io, gerr, session->user_data); g_clear_error(&gerr); session_destroy(session); return FALSE; }
static sdp_record_t *proxy_record_new(const char *uuid128, uint8_t channel) { sdp_list_t *apseq, *aproto, *profiles, *proto[2], *root, *svclass_id; uuid_t uuid, root_uuid, l2cap, rfcomm; sdp_profile_desc_t profile; sdp_record_t *record; sdp_data_t *ch; record = sdp_record_alloc(); if (!record) return NULL; sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(NULL, &root_uuid); sdp_set_browse_groups(record, root); sdp_list_free(root, NULL); bt_string2uuid(&uuid, uuid128); sdp_uuid128_to_uuid(&uuid); svclass_id = sdp_list_append(NULL, &uuid); sdp_set_service_classes(record, svclass_id); sdp_list_free(svclass_id, NULL); sdp_uuid16_create(&profile.uuid, SERIAL_PORT_PROFILE_ID); profile.version = 0x0100; profiles = sdp_list_append(NULL, &profile); sdp_set_profile_descs(record, profiles); sdp_list_free(profiles, NULL); sdp_uuid16_create(&l2cap, L2CAP_UUID); proto[0] = sdp_list_append(NULL, &l2cap); apseq = sdp_list_append(NULL, proto[0]); sdp_uuid16_create(&rfcomm, RFCOMM_UUID); proto[1] = sdp_list_append(NULL, &rfcomm); ch = sdp_data_alloc(SDP_UINT8, &channel); proto[1] = sdp_list_append(proto[1], ch); apseq = sdp_list_append(apseq, proto[1]); aproto = sdp_list_append(NULL, apseq); sdp_set_access_protos(record, aproto); add_lang_attr(record); sdp_set_info_attr(record, "Serial Proxy", NULL, "Serial Proxy"); sdp_data_free(ch); sdp_list_free(proto[0], NULL); sdp_list_free(proto[1], NULL); sdp_list_free(apseq, NULL); sdp_list_free(aproto, NULL); return record; }
static void handle_uuid(const char *uuidstr, struct audio_device *device) { uuid_t uuid; uint16_t uuid16; if (bt_string2uuid(&uuid, uuidstr) < 0) { error("%s not detected as an UUID-128", uuidstr); return; } if (!sdp_uuid128_to_uuid(&uuid) && uuid.type != SDP_UUID16) { error("Could not convert %s to a UUID-16", uuidstr); return; } uuid16 = uuid.value.uuid16; if (!server_is_enabled(&device->src, uuid16)) { DBG("server not enabled for %s (0x%04x)", uuidstr, uuid16); return; } switch (uuid16) { case HEADSET_SVCLASS_ID: DBG("Found Headset record"); if (device->headset) headset_update(device, uuid16, uuidstr); else device->headset = headset_init(device, uuid16, uuidstr); break; case HEADSET_AGW_SVCLASS_ID: DBG("Found Headset AG record"); break; case HANDSFREE_SVCLASS_ID: DBG("Found Handsfree record"); if (device->headset) headset_update(device, uuid16, uuidstr); else device->headset = headset_init(device, uuid16, uuidstr); break; case HANDSFREE_AGW_SVCLASS_ID: DBG("Found Handsfree AG record"); if (enabled.gateway && (device->gateway == NULL)) device->gateway = gateway_init(device); break; case AUDIO_SINK_SVCLASS_ID: DBG("Found Audio Sink"); if (device->sink == NULL) device->sink = sink_init(device); break; case AUDIO_SOURCE_SVCLASS_ID: DBG("Found Audio Source"); if (device->source == NULL) device->source = source_init(device); break; case AV_REMOTE_SVCLASS_ID: case AV_REMOTE_TARGET_SVCLASS_ID: DBG("Found AV %s", uuid16 == AV_REMOTE_SVCLASS_ID ? "Remote" : "Target"); if (device->control) control_update(device, uuid16); else device->control = control_init(device, uuid16); /* SS_Bluetooth(sunjo4.kim) 2012.2.16 - add for a2dp connect fail */ //if (device->sink && sink_is_active(device)) // avrcp_connect(device); /* SS_Bluetooth(sunjo4.kim) End */ break; default: DBG("Unrecognized UUID: 0x%04X", uuid16); break; } }
static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data) { struct audio_device *dev = user_data; struct gateway *gw = dev->gateway; int ch; sdp_list_t *protos, *classes; uuid_t uuid; GIOChannel *io; GError *gerr = NULL; if (err < 0) { error("Unable to get service record: %s (%d)", strerror(-err), -err); goto fail; } if (!recs || !recs->data) { error("No records found"); err = -EIO; goto fail; } if (sdp_get_service_classes(recs->data, &classes) < 0) { error("Unable to get service classes from record"); err = -EINVAL; goto fail; } if (sdp_get_access_protos(recs->data, &protos) < 0) { error("Unable to get access protocols from record"); err = -ENODATA; goto fail; } gw->version = get_remote_profile_version(recs->data); if (gw->version == 0) { error("Unable to get profile version from record"); err = -EINVAL; goto fail; } memcpy(&uuid, classes->data, sizeof(uuid)); sdp_list_free(classes, free); if (!sdp_uuid128_to_uuid(&uuid) || uuid.type != SDP_UUID16 || uuid.value.uuid16 != HANDSFREE_AGW_SVCLASS_ID) { sdp_list_free(protos, NULL); error("Invalid service record or not HFP"); err = -EIO; goto fail; } ch = sdp_get_proto_port(protos, RFCOMM_UUID); sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL); sdp_list_free(protos, NULL); if (ch <= 0) { error("Unable to extract RFCOMM channel from service record"); err = -EIO; goto fail; } io = bt_io_connect(rfcomm_connect_cb, dev, NULL, &gerr, BT_IO_OPT_SOURCE_BDADDR, &dev->src, BT_IO_OPT_DEST_BDADDR, &dev->dst, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, BT_IO_OPT_CHANNEL, ch, BT_IO_OPT_INVALID); if (!io) { error("Unable to connect: %s", gerr->message); goto fail; } g_io_channel_unref(io); return; fail: if (gw->msg) { DBusMessage *reply = btd_error_failed(gw->msg, gerr ? gerr->message : strerror(-err)); g_dbus_send_message(btd_get_dbus_connection(), reply); } gateway_close(dev); if (gerr) g_error_free(gerr); }