From 8b06b2eaa33356a80ff97746b69c6011301e0232 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 17 Nov 2012 06:53:30 +0200 Subject: [PATCH] core: Add support for generic L2CAP & RFCOMM profiles --- src/profile.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/profile.c b/src/profile.c index 79cb6af43..175d8c791 100644 --- a/src/profile.c +++ b/src/profile.c @@ -395,6 +395,34 @@ \ " +#define GENERIC_RECORD \ + " \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + %s \ + \ + %s \ + \ + \ + \ + \ + \ + \ + \ + %s \ + \ + \ + \ + " + struct ext_io; struct ext_profile { @@ -1485,6 +1513,64 @@ static char *get_ftp_record(struct ext_profile *ext, struct ext_io *l2cap, return g_strdup_printf(FTP_RECORD, chan, ext->version, psm, ext->name); } +#define RFCOMM_SEQ " \ + \ + \ + " + +#define VERSION_ATTR \ + " \ + \ + \ + \ + \ + \ + \ + " + +static char *get_generic_record(struct ext_profile *ext, struct ext_io *l2cap, + struct ext_io *rfcomm) +{ + char uuid_str[MAX_LEN_UUID_STR], svc_str[MAX_LEN_UUID_STR], psm[30]; + char *rf_seq, *ver_attr, *rec; + uuid_t uuid; + + bt_string2uuid(&uuid, ext->uuid); + sdp_uuid2strn(&uuid, uuid_str, sizeof(uuid_str)); + + if (ext->service) { + bt_string2uuid(&uuid, ext->service); + sdp_uuid2strn(&uuid, svc_str, sizeof(svc_str)); + } else { + strncpy(svc_str, uuid_str, sizeof(svc_str)); + } + + if (l2cap) + snprintf(psm, sizeof(psm), "", + l2cap->psm); + else + psm[0] = '\0'; + + if (rfcomm) + rf_seq = g_strdup_printf(RFCOMM_SEQ, rfcomm->chan); + else + rf_seq = g_strdup(""); + + if (ext->version) + ver_attr = g_strdup_printf(VERSION_ATTR, uuid_str, + ext->version); + else + ver_attr = g_strdup(""); + + rec = g_strdup_printf(GENERIC_RECORD, svc_str, psm, rf_seq, ver_attr, + ext->name); + + g_free(rf_seq); + g_free(ver_attr); + + return rec; +} + static struct default_settings { const char *uuid; const char *name; @@ -1782,6 +1868,9 @@ static struct ext_profile *create_ext(const char *owner, const char *path, if (!ext->service) set_service(ext); + if (ext->enable_server && !(ext->record || ext->get_record)) + ext->get_record = get_generic_record; + if (!ext->name) ext->name = g_strdup_printf("%s%s/%s", owner, path, uuid); -- 2.47.3