From 2c383fb4b14c9225cf41e77d5c5da62ddf8e4bda Mon Sep 17 00:00:00 2001 From: Alexander Orlenko Date: Fri, 9 Jul 2010 17:39:44 +1100 Subject: Added part of sdp source from bluez-hcidump-1.42 package Added SDP XML parser to bt-device (service discovery method) Rewrited UUID to name helper --- src/Makefile.am | 3 +- src/bt-adapter.c | 2 +- src/bt-device.c | 130 +++++++++++++++++++++++++++++++++- src/lib/agent.c | 2 +- src/lib/bluez-dbus.h | 1 + src/lib/helpers.c | 150 +++++++++++++++++++++------------------ src/lib/helpers.h | 11 ++- src/lib/sdp.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/sdp.h | 166 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 584 insertions(+), 76 deletions(-) create mode 100644 src/lib/sdp.c create mode 100644 src/lib/sdp.h diff --git a/src/Makefile.am b/src/Makefile.am index 92b3795..9888ef7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,8 @@ lib_sources = lib/marshallers.c lib/marshallers.h \ lib/input.c lib/input.h \ lib/manager.c lib/manager.h \ lib/network.c lib/network.h \ - lib/serial.c lib/serial.h + lib/serial.c lib/serial.h \ + lib/sdp.c lib/sdp.h bin_PROGRAMS = bt-monitor bt-adapter bt-agent bt-device bt-input bt-audio bt-network bt-serial bt_monitor_SOURCES = $(lib_sources) bt-monitor.c diff --git a/src/bt-adapter.c b/src/bt-adapter.c index 188ab13..12a5ef5 100644 --- a/src/bt-adapter.c +++ b/src/bt-adapter.c @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) const gchar **uuids = adapter_get_uuids(adapter); for (int j = 0; uuids[j] != NULL; j++) { if (j > 0) g_print(", "); - g_print("%s", uuid2service(uuids[j])); + g_print("%s", get_uuid_name(uuids[j])); } g_print("]\n"); diff --git a/src/bt-device.c b/src/bt-device.c index 58ec3cc..0d9e277 100644 --- a/src/bt-device.c +++ b/src/bt-device.c @@ -26,6 +26,7 @@ #endif #include +#include #include #include "lib/bluez-dbus.h" @@ -36,6 +37,127 @@ static void create_paired_device_done(gpointer data) g_main_loop_quit(mainloop); } +static int rec_elem_num = 0; +static int attr_elem_num = 0; +static int seq_elem_num = 0; +static int int_elem_num = 0; + +static int current_attr_id = -1; +static int current_uuid_id = -1; + +void xml_start_element(GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + GPatternSpec *int_pattern = g_pattern_spec_new("*int*"); + + if (g_strcmp0(element_name, "record") == 0) { + rec_elem_num++; + + attr_elem_num = 0; + seq_elem_num = 0; + int_elem_num = 0; + + current_attr_id = -1; + current_uuid_id = -1; + + if (rec_elem_num == 1) g_print("\n"); + } else if (g_strcmp0(element_name, "attribute") == 0 && g_strcmp0(attribute_names[0], "id") == 0) { + int attr_id = xtoi(attribute_values[0]); + const gchar *attr_name = sdp_get_attr_id_name(attr_id); + current_attr_id = attr_id; + attr_elem_num++; + + if (attr_elem_num > 1) g_print("\n"); + if (attr_name == NULL) { + g_print("AttrID-%s: ", attribute_values[0]); + } else { + g_print("%s: ", attr_name); + } + } else if (g_strcmp0(element_name, "sequence") == 0) { + seq_elem_num++; + int_elem_num = 0; + if (seq_elem_num > 1) { + g_print("\n"); + for (int i = 0; i < seq_elem_num; i++) g_print(" "); + } + } else if ((g_pattern_match(int_pattern, strlen(element_name), element_name, NULL)) && g_strcmp0(attribute_names[0], "value") == 0) { + int_elem_num++; + + if (int_elem_num > 1) g_print(", "); + if (current_uuid_id == SDP_UUID_RFCOMM) { + g_print("Channel: %d", xtoi(attribute_values[0])); + } else { + g_print("0x%x", xtoi(attribute_values[0])); + } + } else if (g_strcmp0(element_name, "uuid") == 0 && g_strcmp0(attribute_names[0], "value") == 0) { + int uuid_id = -1; + const gchar *uuid_name; + int_elem_num++; + + if (attribute_values[0][0] == '0' && attribute_values[0][1] == 'x') { + uuid_id = xtoi(attribute_values[0]); + uuid_name = sdp_get_uuid_name(uuid_id); + current_uuid_id = uuid_id; + } else { + uuid_name = get_uuid_name(attribute_values[0]); + } + + if (int_elem_num > 1) g_print(", "); + if (uuid_name == NULL) { + g_print("\"UUID-%s\"", attribute_values[0]); + } else { + g_print("\"%s\"", uuid_name); + } + } else if (g_strcmp0(element_name, "text") == 0 && g_strcmp0(attribute_names[0], "value") == 0) { + int_elem_num++; + + if (int_elem_num > 1) g_print(", "); + g_print("\"%s\"", attribute_values[0]); + } else if (g_strcmp0(element_name, "boolean") == 0 && g_strcmp0(attribute_names[0], "value") == 0) { + int_elem_num++; + + if (int_elem_num > 1) g_print(", "); + g_print("%s", attribute_values[0]); + } else { + if (error) + *error = g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Invalid XML element: %s", element_name); + } + + g_pattern_spec_free(int_pattern); +} + +void xml_end_element(GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + if (g_strcmp0(element_name, "record") == 0) { + attr_elem_num = 0; + seq_elem_num = 0; + int_elem_num = 0; + + current_attr_id = -1; + current_uuid_id = -1; + + g_print("\n\n"); + } else if (g_strcmp0(element_name, "attribute") == 0) { + seq_elem_num = 0; + int_elem_num = 0; + + current_attr_id = -1; + current_uuid_id = -1; + } else if (g_strcmp0(element_name, "sequence") == 0) { + seq_elem_num--; + int_elem_num = 0; + + current_uuid_id = -1; + } +} + static gchar *adapter_arg = NULL; static gboolean list_arg = FALSE; static gchar *connect_arg = NULL; @@ -159,7 +281,7 @@ int main(int argc, char *argv[]) const gchar **uuids = device_get_uuids(device); for (int j = 0; uuids[j] != NULL; j++) { if (j > 0) g_print(", "); - g_print("%s", uuid2service(uuids[j])); + g_print("%s", get_uuid_name(uuids[j])); } g_print("]\n"); @@ -177,7 +299,11 @@ int main(int argc, char *argv[]) g_hash_table_iter_init(&iter, device_services); while (g_hash_table_iter_next(&iter, &key, &value)) { - g_print("%d:\n%s\n", key, value); + GMarkupParser xml_parser = {xml_start_element, xml_end_element, NULL, NULL, NULL}; + GMarkupParseContext *xml_parse_context = g_markup_parse_context_new(&xml_parser, 0, NULL, NULL); + g_markup_parse_context_parse(xml_parse_context, value, strlen(value), &error); + exit_if_error(error); + g_markup_parse_context_free(xml_parse_context); } g_print("Done\n"); diff --git a/src/lib/agent.c b/src/lib/agent.c index 76ec719..90d64d3 100644 --- a/src/lib/agent.c +++ b/src/lib/agent.c @@ -138,7 +138,7 @@ gboolean agent_authorize(Agent *self, const gchar *device, const gchar *uuid, GE g_object_unref(device_obj); gchar yn[4] = {0,}; - g_print("Authorize a connection to: %s (yes/no)? ", uuid2service(uuid)); + g_print("Authorize a connection to: %s (yes/no)? ", get_uuid_name(uuid)); scanf("%3s", yn); if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) { return TRUE; diff --git a/src/lib/bluez-dbus.h b/src/lib/bluez-dbus.h index 9322850..d20baff 100644 --- a/src/lib/bluez-dbus.h +++ b/src/lib/bluez-dbus.h @@ -31,6 +31,7 @@ /* Local includes */ #include "dbus-common.h" #include "helpers.h" +#include "sdp.h" #include "marshallers.h" /* Bluez DBus Interfaces */ diff --git a/src/lib/helpers.c b/src/lib/helpers.c index bc8902f..c9f0dd6 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -25,11 +25,91 @@ #include #endif +#include #include #include "manager.h" #include "helpers.h" +/* UUID Name lookup table */ +typedef struct { + gchar *uuid; + gchar *name; +} uuid_name_lookup_table_t; + +static uuid_name_lookup_table_t uuid_name_lookup_table[] = { + {"00001000-0000-1000-8000-00805f9b34fb", "ServiceDiscoveryServer"}, + {"00001001-0000-1000-8000-00805f9b34fb", "BrowseGroupDescriptor"}, + {"00001002-0000-1000-8000-00805f9b34fb", "PublicBrowseGroup"}, + {"00001101-0000-1000-8000-00805f9b34fb", "SerialPort"}, + {"00001102-0000-1000-8000-00805f9b34fb", "LANAccessUsingPPP"}, + {"00001103-0000-1000-8000-00805f9b34fb", "DialupNetworking"}, + {"00001104-0000-1000-8000-00805f9b34fb", "IrMCSync"}, + {"00001105-0000-1000-8000-00805f9b34fb", "OBEXObjectPush"}, + {"00001106-0000-1000-8000-00805f9b34fb", "OBEXFileTransfer"}, + {"00001107-0000-1000-8000-00805f9b34fb", "IrMCSyncCommand"}, + {"00001108-0000-1000-8000-00805f9b34fb", "Headset"}, + {"00001109-0000-1000-8000-00805f9b34fb", "CordlessTelephony"}, + {"0000110a-0000-1000-8000-00805f9b34fb", "AudioSource"}, + {"0000110b-0000-1000-8000-00805f9b34fb", "AudioSink"}, + {"0000110c-0000-1000-8000-00805f9b34fb", "AVRemoteControlTarget"}, + {"0000110d-0000-1000-8000-00805f9b34fb", "AdvancedAudioDistribution"}, + {"0000110e-0000-1000-8000-00805f9b34fb", "AVRemoteControl"}, + {"0000110f-0000-1000-8000-00805f9b34fb", "VideoConferencing"}, + {"00001110-0000-1000-8000-00805f9b34fb", "Intercom"}, + {"00001111-0000-1000-8000-00805f9b34fb", "Fax"}, + {"00001112-0000-1000-8000-00805f9b34fb", "HeadsetAudioGateway"}, + {"00001113-0000-1000-8000-00805f9b34fb", "WAP"}, + {"00001114-0000-1000-8000-00805f9b34fb", "WAPClient"}, + {"00001115-0000-1000-8000-00805f9b34fb", "PANU"}, + {"00001116-0000-1000-8000-00805f9b34fb", "NAP"}, + {"00001117-0000-1000-8000-00805f9b34fb", "GN"}, + {"00001118-0000-1000-8000-00805f9b34fb", "DirectPrinting"}, + {"00001119-0000-1000-8000-00805f9b34fb", "ReferencePrinting"}, + {"0000111a-0000-1000-8000-00805f9b34fb", "Imaging"}, + {"0000111b-0000-1000-8000-00805f9b34fb", "ImagingResponder"}, + {"0000111c-0000-1000-8000-00805f9b34fb", "ImagingAutomaticArchive"}, + {"0000111d-0000-1000-8000-00805f9b34fb", "ImagingReferenceObjects"}, + {"0000111e-0000-1000-8000-00805f9b34fb", "Handsfree"}, + {"0000111f-0000-1000-8000-00805f9b34fb", "HandsfreeAudioGateway"}, + {"00001120-0000-1000-8000-00805f9b34fb", "DirectPrintingReferenceObjects"}, + {"00001121-0000-1000-8000-00805f9b34fb", "ReflectedUI"}, + {"00001122-0000-1000-8000-00805f9b34fb", "BasicPringing"}, + {"00001123-0000-1000-8000-00805f9b34fb", "PrintingStatus"}, + {"00001124-0000-1000-8000-00805f9b34fb", "HumanInterfaceDevice"}, + {"00001125-0000-1000-8000-00805f9b34fb", "HardcopyCableReplacement"}, + {"00001126-0000-1000-8000-00805f9b34fb", "HCRPrint"}, + {"00001127-0000-1000-8000-00805f9b34fb", "HCRScan"}, + {"00001128-0000-1000-8000-00805f9b34fb", "CommonISDNAccess"}, + {"00001129-0000-1000-8000-00805f9b34fb", "VideoConferencingGW"}, + {"0000112a-0000-1000-8000-00805f9b34fb", "UDIMT"}, + {"0000112b-0000-1000-8000-00805f9b34fb", "UDITA"}, + {"0000112c-0000-1000-8000-00805f9b34fb", "AudioVideo"}, + {"0000112d-0000-1000-8000-00805f9b34fb", "SIMAccess"}, + {"00001200-0000-1000-8000-00805f9b34fb", "PnPInformation"}, + {"00001201-0000-1000-8000-00805f9b34fb", "GenericNetworking"}, + {"00001202-0000-1000-8000-00805f9b34fb", "GenericFileTransfer"}, + {"00001203-0000-1000-8000-00805f9b34fb", "GenericAudio"}, + {"00001204-0000-1000-8000-00805f9b34fb", "GenericTelephony"}, + + // Custom: + {"0000112f-0000-1000-8000-00805f9b34fb", "PhoneBookAccess"}, + {"831c4071-7bc8-4a9c-a01c-15df25a4adbc", "ActiveSync"}, +}; + +#define UUID_NAME_LOOKUP_TABLE_SIZE \ + (sizeof(uuid_name_lookup_table)/sizeof(uuid_name_lookup_table_t)) + +const gchar *get_uuid_name(const gchar *uuid) +{ + for (int i = 0; i < UUID_NAME_LOOKUP_TABLE_SIZE; i++) { + if (g_strcmp0(uuid_name_lookup_table[i].uuid, uuid) == 0) + return uuid_name_lookup_table[i].name; + } + + return uuid; +} + Adapter *find_adapter(const gchar *name, GError **error) { gchar *adapter_path = NULL; @@ -79,76 +159,6 @@ Adapter *find_adapter(const gchar *name, GError **error) return adapter; } -const gchar *uuid2service(const gchar *uuid) -{ - static GHashTable *t = NULL; - if (t == NULL) { - t = g_hash_table_new(g_str_hash, g_str_equal); - g_hash_table_insert(t, "00001000-0000-1000-8000-00805f9b34fb", "ServiceDiscoveryServer"); - g_hash_table_insert(t, "00001001-0000-1000-8000-00805f9b34fb", "BrowseGroupDescriptor"); - g_hash_table_insert(t, "00001002-0000-1000-8000-00805f9b34fb", "PublicBrowseGroup"); - g_hash_table_insert(t, "00001101-0000-1000-8000-00805f9b34fb", "SerialPort"); - g_hash_table_insert(t, "00001102-0000-1000-8000-00805f9b34fb", "LANAccessUsingPPP"); - g_hash_table_insert(t, "00001103-0000-1000-8000-00805f9b34fb", "DialupNetworking"); - g_hash_table_insert(t, "00001104-0000-1000-8000-00805f9b34fb", "IrMCSync"); - g_hash_table_insert(t, "00001105-0000-1000-8000-00805f9b34fb", "OBEXObjectPush"); - g_hash_table_insert(t, "00001106-0000-1000-8000-00805f9b34fb", "OBEXFileTransfer"); - g_hash_table_insert(t, "00001107-0000-1000-8000-00805f9b34fb", "IrMCSyncCommand"); - g_hash_table_insert(t, "00001108-0000-1000-8000-00805f9b34fb", "Headset"); - g_hash_table_insert(t, "00001109-0000-1000-8000-00805f9b34fb", "CordlessTelephony"); - g_hash_table_insert(t, "0000110a-0000-1000-8000-00805f9b34fb", "AudioSource"); - g_hash_table_insert(t, "0000110b-0000-1000-8000-00805f9b34fb", "AudioSink"); - g_hash_table_insert(t, "0000110c-0000-1000-8000-00805f9b34fb", "AVRemoteControlTarget"); - g_hash_table_insert(t, "0000110d-0000-1000-8000-00805f9b34fb", "AdvancedAudioDistribution"); - g_hash_table_insert(t, "0000110e-0000-1000-8000-00805f9b34fb", "AVRemoteControl"); - g_hash_table_insert(t, "0000110f-0000-1000-8000-00805f9b34fb", "VideoConferencing"); - g_hash_table_insert(t, "00001110-0000-1000-8000-00805f9b34fb", "Intercom"); - g_hash_table_insert(t, "00001111-0000-1000-8000-00805f9b34fb", "Fax"); - g_hash_table_insert(t, "00001112-0000-1000-8000-00805f9b34fb", "HeadsetAudioGateway"); - g_hash_table_insert(t, "00001113-0000-1000-8000-00805f9b34fb", "WAP"); - g_hash_table_insert(t, "00001114-0000-1000-8000-00805f9b34fb", "WAPClient"); - g_hash_table_insert(t, "00001115-0000-1000-8000-00805f9b34fb", "PANU"); - g_hash_table_insert(t, "00001116-0000-1000-8000-00805f9b34fb", "NAP"); - g_hash_table_insert(t, "00001117-0000-1000-8000-00805f9b34fb", "GN"); - g_hash_table_insert(t, "00001118-0000-1000-8000-00805f9b34fb", "DirectPrinting"); - g_hash_table_insert(t, "00001119-0000-1000-8000-00805f9b34fb", "ReferencePrinting"); - g_hash_table_insert(t, "0000111a-0000-1000-8000-00805f9b34fb", "Imaging"); - g_hash_table_insert(t, "0000111b-0000-1000-8000-00805f9b34fb", "ImagingResponder"); - g_hash_table_insert(t, "0000111c-0000-1000-8000-00805f9b34fb", "ImagingAutomaticArchive"); - g_hash_table_insert(t, "0000111d-0000-1000-8000-00805f9b34fb", "ImagingReferenceObjects"); - g_hash_table_insert(t, "0000111e-0000-1000-8000-00805f9b34fb", "Handsfree"); - g_hash_table_insert(t, "0000111f-0000-1000-8000-00805f9b34fb", "HandsfreeAudioGateway"); - g_hash_table_insert(t, "00001120-0000-1000-8000-00805f9b34fb", "DirectPrintingReferenceObjects"); - g_hash_table_insert(t, "00001121-0000-1000-8000-00805f9b34fb", "ReflectedUI"); - g_hash_table_insert(t, "00001122-0000-1000-8000-00805f9b34fb", "BasicPringing"); - g_hash_table_insert(t, "00001123-0000-1000-8000-00805f9b34fb", "PrintingStatus"); - g_hash_table_insert(t, "00001124-0000-1000-8000-00805f9b34fb", "HumanInterfaceDevice"); - g_hash_table_insert(t, "00001125-0000-1000-8000-00805f9b34fb", "HardcopyCableReplacement"); - g_hash_table_insert(t, "00001126-0000-1000-8000-00805f9b34fb", "HCRPrint"); - g_hash_table_insert(t, "00001127-0000-1000-8000-00805f9b34fb", "HCRScan"); - g_hash_table_insert(t, "00001128-0000-1000-8000-00805f9b34fb", "CommonISDNAccess"); - g_hash_table_insert(t, "00001129-0000-1000-8000-00805f9b34fb", "VideoConferencingGW"); - g_hash_table_insert(t, "0000112a-0000-1000-8000-00805f9b34fb", "UDIMT"); - g_hash_table_insert(t, "0000112b-0000-1000-8000-00805f9b34fb", "UDITA"); - g_hash_table_insert(t, "0000112c-0000-1000-8000-00805f9b34fb", "AudioVideo"); - g_hash_table_insert(t, "0000112d-0000-1000-8000-00805f9b34fb", "SIMAccess"); - g_hash_table_insert(t, "00001200-0000-1000-8000-00805f9b34fb", "PnPInformation"); - g_hash_table_insert(t, "00001201-0000-1000-8000-00805f9b34fb", "GenericNetworking"); - g_hash_table_insert(t, "00001202-0000-1000-8000-00805f9b34fb", "GenericFileTransfer"); - g_hash_table_insert(t, "00001203-0000-1000-8000-00805f9b34fb", "GenericAudio"); - g_hash_table_insert(t, "00001204-0000-1000-8000-00805f9b34fb", "GenericTelephony"); - // Manualy added - g_hash_table_insert(t, "0000112f-0000-1000-8000-00805f9b34fb", "PhoneBookAccess"); - g_hash_table_insert(t, "831c4071-7bc8-4a9c-a01c-15df25a4adbc", "ActiveSync"); - } - - if (g_hash_table_lookup(t, uuid) != NULL) { - return g_hash_table_lookup(t, uuid); - } else { - return uuid; - } -} - Device *find_device(Adapter *adapter, const gchar *name, GError **error) { g_assert(adapter != NULL); diff --git a/src/lib/helpers.h b/src/lib/helpers.h index 1de7894..b343867 100644 --- a/src/lib/helpers.h +++ b/src/lib/helpers.h @@ -24,6 +24,7 @@ #ifndef __HELPERS_H #define __HELPERS_H +#include #include #include "adapter.h" @@ -31,16 +32,24 @@ /* Adapter helpers */ Adapter *find_adapter(const gchar *name, GError **error); -const gchar *uuid2service(const gchar *uuid); /* Device helpers */ Device *find_device(Adapter *adapter, const gchar *name, GError **error); +/* Others helpers */ #define exit_if_error(error) G_STMT_START{ \ if (error) { \ g_printerr("%s\n", error->message); \ exit(EXIT_FAILURE); \ }; }G_STMT_END +inline int xtoi(const gchar *str) { + int i = 0; + sscanf(str, "0x%x", &i); + return i; +} + +const gchar *get_uuid_name(const gchar *uuid); + #endif /* __HELPERS_H */ diff --git a/src/lib/sdp.c b/src/lib/sdp.c new file mode 100644 index 0000000..4b3c94d --- /dev/null +++ b/src/lib/sdp.c @@ -0,0 +1,195 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2001-2002 Ricky Yuen + * Copyright (C) 2003-2007 Marcel Holtmann + * Copyright (C) 2010 Alexander Orlenko + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include "sdp.h" + +/* UUID name lookup table */ +typedef struct { + int uuid; + char* name; +} sdp_uuid_nam_lookup_table_t; + +static sdp_uuid_nam_lookup_table_t sdp_uuid_nam_lookup_table[] = { + { SDP_UUID_SDP, "SDP" }, + { SDP_UUID_UDP, "UDP" }, + { SDP_UUID_RFCOMM, "RFCOMM" }, + { SDP_UUID_TCP, "TCP" }, + { SDP_UUID_TCS_BIN, "TCS-BIN" }, + { SDP_UUID_TCS_AT, "TCS-AT" }, + { SDP_UUID_OBEX, "OBEX" }, + { SDP_UUID_IP, "IP" }, + { SDP_UUID_FTP, "FTP" }, + { SDP_UUID_HTTP, "HTTP" }, + { SDP_UUID_WSP, "WSP" }, + { SDP_UUID_L2CAP, "L2CAP" }, + { SDP_UUID_BNEP, "BNEP" }, /* PAN */ + { SDP_UUID_HIDP, "HIDP" }, /* HID */ + { SDP_UUID_AVCTP, "AVCTP" }, /* AVCTP */ + { SDP_UUID_AVDTP, "AVDTP" }, /* AVDTP */ + { SDP_UUID_CMTP, "CMTP" }, /* CIP */ + { SDP_UUID_UDI_C_PLANE, "UDI_C-Plane" }, /* UDI */ + { SDP_UUID_SERVICE_DISCOVERY_SERVER, "SDServer" }, + { SDP_UUID_BROWSE_GROUP_DESCRIPTOR, "BrwsGrpDesc" }, + { SDP_UUID_PUBLIC_BROWSE_GROUP, "PubBrwsGrp" }, + { SDP_UUID_SERIAL_PORT, "SP" }, + { SDP_UUID_LAN_ACCESS_PPP, "LAN" }, + { SDP_UUID_DIALUP_NETWORKING, "DUN" }, + { SDP_UUID_IR_MC_SYNC, "IRMCSync" }, + { SDP_UUID_OBEX_OBJECT_PUSH, "OBEXObjPush" }, + { SDP_UUID_OBEX_FILE_TRANSFER, "OBEXObjTrnsf" }, + { SDP_UUID_IR_MC_SYNC_COMMAND, "IRMCSyncCmd" }, + { SDP_UUID_HEADSET, "Headset" }, + { SDP_UUID_CORDLESS_TELEPHONY, "CordlessTel" }, + { SDP_UUID_AUDIO_SOURCE, "AudioSource" }, /* A2DP */ + { SDP_UUID_AUDIO_SINK, "AudioSink" }, /* A2DP */ + { SDP_UUID_AV_REMOTE_TARGET, "AVRemTarget" }, /* AVRCP */ + { SDP_UUID_ADVANCED_AUDIO, "AdvAudio" }, /* A2DP */ + { SDP_UUID_AV_REMOTE, "AVRemote" }, /* AVRCP */ + { SDP_UUID_VIDEO_CONFERENCING, "VideoConf" }, /* VCP */ + { SDP_UUID_INTERCOM, "Intercom" }, + { SDP_UUID_FAX, "Fax" }, + { SDP_UUID_HEADSET_AUDIO_GATEWAY, "Headset AG" }, + { SDP_UUID_WAP, "WAP" }, + { SDP_UUID_WAP_CLIENT, "WAP Client" }, + { SDP_UUID_PANU, "PANU" }, /* PAN */ + { SDP_UUID_NAP, "NAP" }, /* PAN */ + { SDP_UUID_GN, "GN" }, /* PAN */ + { SDP_UUID_DIRECT_PRINTING, "DirectPrint" }, /* BPP */ + { SDP_UUID_REFERENCE_PRINTING, "RefPrint" }, /* BPP */ + { SDP_UUID_IMAGING, "Imaging" }, /* BIP */ + { SDP_UUID_IMAGING_RESPONDER, "ImagingResp" }, /* BIP */ + { SDP_UUID_HANDSFREE, "Handsfree" }, + { SDP_UUID_HANDSFREE_AUDIO_GATEWAY, "Handsfree AG" }, + { SDP_UUID_DIRECT_PRINTING_REF_OBJS, "RefObjsPrint" }, /* BPP */ + { SDP_UUID_REFLECTED_UI, "ReflectedUI" }, /* BPP */ + { SDP_UUID_BASIC_PRINTING, "BasicPrint" }, /* BPP */ + { SDP_UUID_PRINTING_STATUS, "PrintStatus" }, /* BPP */ + { SDP_UUID_HUMAN_INTERFACE_DEVICE, "HID" }, /* HID */ + { SDP_UUID_HARDCOPY_CABLE_REPLACE, "HCRP" }, /* HCRP */ + { SDP_UUID_HCR_PRINT, "HCRPrint" }, /* HCRP */ + { SDP_UUID_HCR_SCAN, "HCRScan" }, /* HCRP */ + { SDP_UUID_COMMON_ISDN_ACCESS, "CIP" }, /* CIP */ + { SDP_UUID_VIDEO_CONFERENCING_GW, "VideoConf GW" }, /* VCP */ + { SDP_UUID_UDI_MT, "UDI MT" }, /* UDI */ + { SDP_UUID_UDI_TA, "UDI TA" }, /* UDI */ + { SDP_UUID_AUDIO_VIDEO, "AudioVideo" }, /* VCP */ + { SDP_UUID_SIM_ACCESS, "SAP" }, /* SAP */ + { SDP_UUID_PHONEBOOK_ACCESS_PCE, "PBAP PCE" }, /* PBAP */ + { SDP_UUID_PHONEBOOK_ACCESS_PSE, "PBAP PSE" }, /* PBAP */ + { SDP_UUID_PHONEBOOK_ACCESS, "PBAP" }, /* PBAP */ + { SDP_UUID_PNP_INFORMATION, "PNPInfo" }, + { SDP_UUID_GENERIC_NETWORKING, "Networking" }, + { SDP_UUID_GENERIC_FILE_TRANSFER, "FileTrnsf" }, + { SDP_UUID_GENERIC_AUDIO, "Audio" }, + { SDP_UUID_GENERIC_TELEPHONY, "Telephony" }, + { SDP_UUID_UPNP_SERVICE, "UPNP" }, /* ESDP */ + { SDP_UUID_UPNP_IP_SERVICE, "UPNP IP" }, /* ESDP */ + { SDP_UUID_ESDP_UPNP_IP_PAN, "UPNP PAN" }, /* ESDP */ + { SDP_UUID_ESDP_UPNP_IP_LAP, "UPNP LAP" }, /* ESDP */ + { SDP_UUID_ESDP_UPNP_L2CAP, "UPNP L2CAP" }, /* ESDP */ + { SDP_UUID_VIDEO_SOURCE, "VideoSource" }, /* VDP */ + { SDP_UUID_VIDEO_SINK, "VideoSink" }, /* VDP */ + { SDP_UUID_VIDEO_DISTRIBUTION, "VideoDist" }, /* VDP */ + { SDP_UUID_APPLE_AGENT, "AppleAgent" }, +}; + +#define SDP_UUID_NAM_LOOKUP_TABLE_SIZE \ + (sizeof(sdp_uuid_nam_lookup_table)/sizeof(sdp_uuid_nam_lookup_table_t)) + +/* AttrID name lookup table */ +typedef struct { + int attr_id; + char* name; +} sdp_attr_id_nam_lookup_table_t; + +static sdp_attr_id_nam_lookup_table_t sdp_attr_id_nam_lookup_table[] = { + { SDP_ATTR_ID_SERVICE_RECORD_HANDLE, "SrvRecHndl" }, + { SDP_ATTR_ID_SERVICE_CLASS_ID_LIST, "SrvClassIDList" }, + { SDP_ATTR_ID_SERVICE_RECORD_STATE, "SrvRecState" }, + { SDP_ATTR_ID_SERVICE_SERVICE_ID, "SrvID" }, + { SDP_ATTR_ID_PROTOCOL_DESCRIPTOR_LIST, "ProtocolDescList" }, + { SDP_ATTR_ID_BROWSE_GROUP_LIST, "BrwGrpList" }, + { SDP_ATTR_ID_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, "LangBaseAttrIDList" }, + { SDP_ATTR_ID_SERVICE_INFO_TIME_TO_LIVE, "SrvInfoTimeToLive" }, + { SDP_ATTR_ID_SERVICE_AVAILABILITY, "SrvAvail" }, + { SDP_ATTR_ID_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, "BTProfileDescList" }, + { SDP_ATTR_ID_DOCUMENTATION_URL, "DocURL" }, + { SDP_ATTR_ID_CLIENT_EXECUTABLE_URL, "ClientExeURL" }, + { SDP_ATTR_ID_ICON_10, "Icon10" }, + { SDP_ATTR_ID_ICON_URL, "IconURL" }, + { SDP_ATTR_ID_SERVICE_NAME, "SrvName" }, + { SDP_ATTR_ID_SERVICE_DESCRIPTION, "SrvDesc" }, + { SDP_ATTR_ID_PROVIDER_NAME, "ProviderName" }, + { SDP_ATTR_ID_VERSION_NUMBER_LIST, "VersionNumList" }, + { SDP_ATTR_ID_GROUP_ID, "GrpID" }, + { SDP_ATTR_ID_SERVICE_DATABASE_STATE, "SrvDBState" }, + { SDP_ATTR_ID_SERVICE_VERSION, "SrvVersion" }, + { SDP_ATTR_ID_SECURITY_DESCRIPTION, "SecurityDescription"}, /* PAN */ + { SDP_ATTR_ID_SUPPORTED_DATA_STORES_LIST, "SuppDataStoresList" }, /* Synchronization */ + { SDP_ATTR_ID_SUPPORTED_FORMATS_LIST, "SuppFormatsList" }, /* OBEX Object Push */ + { SDP_ATTR_ID_NET_ACCESS_TYPE, "NetAccessType" }, /* PAN */ + { SDP_ATTR_ID_MAX_NET_ACCESS_RATE, "MaxNetAccessRate" }, /* PAN */ + { SDP_ATTR_ID_IPV4_SUBNET, "IPv4Subnet" }, /* PAN */ + { SDP_ATTR_ID_IPV6_SUBNET, "IPv6Subnet" }, /* PAN */ + { SDP_ATTR_ID_SUPPORTED_CAPABILITIES, "SuppCapabilities" }, /* Imaging */ + { SDP_ATTR_ID_SUPPORTED_FEATURES, "SuppFeatures" }, /* Imaging and Hansfree */ + { SDP_ATTR_ID_SUPPORTED_FUNCTIONS, "SuppFunctions" }, /* Imaging */ + { SDP_ATTR_ID_TOTAL_IMAGING_DATA_CAPACITY, "SuppTotalCapacity" }, /* Imaging */ + { SDP_ATTR_ID_SUPPORTED_REPOSITORIES, "SuppRepositories" }, /* PBAP */ +}; + +#define SDP_ATTR_ID_NAM_LOOKUP_TABLE_SIZE \ + (sizeof(sdp_attr_id_nam_lookup_table)/sizeof(sdp_attr_id_nam_lookup_table_t)) + +const char* sdp_get_uuid_name(int uuid) +{ + for (int i = 0; i < SDP_UUID_NAM_LOOKUP_TABLE_SIZE; i++) { + if (sdp_uuid_nam_lookup_table[i].uuid == uuid) + return sdp_uuid_nam_lookup_table[i].name; + } + + return NULL; +} + +const char* sdp_get_attr_id_name(int attr_id) +{ + for (int i = 0; i < SDP_ATTR_ID_NAM_LOOKUP_TABLE_SIZE; i++) + if (sdp_attr_id_nam_lookup_table[i].attr_id == attr_id) + return sdp_attr_id_nam_lookup_table[i].name; + + return NULL; +} + diff --git a/src/lib/sdp.h b/src/lib/sdp.h new file mode 100644 index 0000000..04267d0 --- /dev/null +++ b/src/lib/sdp.h @@ -0,0 +1,166 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2001-2002 Ricky Yuen + * Copyright (C) 2003-2007 Marcel Holtmann + * Copyright (C) 2010 Alexander Orlenko + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __SDP_H +#define __SDP_H + +/* Bluetooth assigned UUIDs for protocols */ +#define SDP_UUID_SDP 0x0001 +#define SDP_UUID_UDP 0x0002 +#define SDP_UUID_RFCOMM 0x0003 +#define SDP_UUID_TCP 0x0004 +#define SDP_UUID_TCS_BIN 0x0005 +#define SDP_UUID_TCS_AT 0x0006 +#define SDP_UUID_OBEX 0x0008 +#define SDP_UUID_IP 0x0009 +#define SDP_UUID_FTP 0x000A +#define SDP_UUID_HTTP 0x000C +#define SDP_UUID_WSP 0x000E +#define SDP_UUID_BNEP 0x000F /* PAN */ +#define SDP_UUID_HIDP 0x0011 /* HID */ +#define SDP_UUID_HARDCOPY_CONTROL_CHANNEL 0x0012 /* HCRP */ +#define SDP_UUID_HARDCOPY_DATA_CHANNEL 0x0014 /* HCRP */ +#define SDP_UUID_HARDCOPY_NOTIFICATION 0x0016 /* HCRP */ +#define SDP_UUID_AVCTP 0x0017 /* AVCTP */ +#define SDP_UUID_AVDTP 0x0019 /* AVDTP */ +#define SDP_UUID_CMTP 0x001B /* CIP */ +#define SDP_UUID_UDI_C_PLANE 0x001D /* UDI */ +#define SDP_UUID_L2CAP 0x0100 + +/* Bluetooth assigned UUIDs for Service Classes */ +#define SDP_UUID_SERVICE_DISCOVERY_SERVER 0x1000 +#define SDP_UUID_BROWSE_GROUP_DESCRIPTOR 0x1001 +#define SDP_UUID_PUBLIC_BROWSE_GROUP 0x1002 +#define SDP_UUID_SERIAL_PORT 0x1101 +#define SDP_UUID_LAN_ACCESS_PPP 0x1102 +#define SDP_UUID_DIALUP_NETWORKING 0x1103 +#define SDP_UUID_IR_MC_SYNC 0x1104 +#define SDP_UUID_OBEX_OBJECT_PUSH 0x1105 +#define SDP_UUID_OBEX_FILE_TRANSFER 0x1106 +#define SDP_UUID_IR_MC_SYNC_COMMAND 0x1107 +#define SDP_UUID_HEADSET 0x1108 +#define SDP_UUID_CORDLESS_TELEPHONY 0x1109 +#define SDP_UUID_AUDIO_SOURCE 0x110a /* A2DP */ +#define SDP_UUID_AUDIO_SINK 0x110b /* A2DP */ +#define SDP_UUID_AV_REMOTE_TARGET 0x110c /* AVRCP */ +#define SDP_UUID_ADVANCED_AUDIO 0x110d /* A2DP */ +#define SDP_UUID_AV_REMOTE 0x110e /* AVRCP */ +#define SDP_UUID_VIDEO_CONFERENCING 0x110f /* VCP */ +#define SDP_UUID_INTERCOM 0x1110 +#define SDP_UUID_FAX 0x1111 +#define SDP_UUID_HEADSET_AUDIO_GATEWAY 0x1112 +#define SDP_UUID_WAP 0x1113 +#define SDP_UUID_WAP_CLIENT 0x1114 +#define SDP_UUID_PANU 0x1115 /* PAN */ +#define SDP_UUID_NAP 0x1116 /* PAN */ +#define SDP_UUID_GN 0x1117 /* PAN */ +#define SDP_UUID_DIRECT_PRINTING 0x1118 /* BPP */ +#define SDP_UUID_REFERENCE_PRINTING 0x1119 /* BPP */ +#define SDP_UUID_IMAGING 0x111a /* BIP */ +#define SDP_UUID_IMAGING_RESPONDER 0x111b /* BIP */ +#define SDP_UUID_IMAGING_AUTOMATIC_ARCHIVE 0x111c /* BIP */ +#define SDP_UUID_IMAGING_REFERENCED_OBJECTS 0x111d /* BIP */ +#define SDP_UUID_HANDSFREE 0x111e +#define SDP_UUID_HANDSFREE_AUDIO_GATEWAY 0x111f +#define SDP_UUID_DIRECT_PRINTING_REF_OBJS 0x1120 /* BPP */ +#define SDP_UUID_DIRECT_PRINTING_REFERENCE_OBJECTS 0x1120 /* BPP */ +#define SDP_UUID_REFLECTED_UI 0x1121 /* BPP */ +#define SDP_UUID_BASIC_PRINTING 0x1122 /* BPP */ +#define SDP_UUID_PRINTING_STATUS 0x1123 /* BPP */ +#define SDP_UUID_HUMAN_INTERFACE_DEVICE 0x1124 /* HID */ +#define SDP_UUID_HARDCOPY_CABLE_REPLACE 0x1125 /* HCRP */ +#define SDP_UUID_HCR_PRINT 0x1126 /* HCRP */ +#define SDP_UUID_HCR_SCAN 0x1127 /* HCRP */ +#define SDP_UUID_COMMON_ISDN_ACCESS 0x1128 /* CIP */ +#define SDP_UUID_VIDEO_CONFERENCING_GW 0x1129 /* VCP */ +#define SDP_UUID_UDI_MT 0x112a /* UDI */ +#define SDP_UUID_UDI_TA 0x112b /* UDI */ +#define SDP_UUID_AUDIO_VIDEO 0x112c /* VCP */ +#define SDP_UUID_SIM_ACCESS 0x112d /* SAP */ +#define SDP_UUID_PHONEBOOK_ACCESS_PCE 0x112e /* PBAP */ +#define SDP_UUID_PHONEBOOK_ACCESS_PSE 0x112f /* PBAP */ +#define SDP_UUID_PHONEBOOK_ACCESS 0x1130 /* PBAP */ +#define SDP_UUID_PNP_INFORMATION 0x1200 +#define SDP_UUID_GENERIC_NETWORKING 0x1201 +#define SDP_UUID_GENERIC_FILE_TRANSFER 0x1202 +#define SDP_UUID_GENERIC_AUDIO 0x1203 +#define SDP_UUID_GENERIC_TELEPHONY 0x1204 +#define SDP_UUID_UPNP_SERVICE 0x1205 /* ESDP */ +#define SDP_UUID_UPNP_IP_SERVICE 0x1206 /* ESDP */ +#define SDP_UUID_ESDP_UPNP_IP_PAN 0x1300 /* ESDP */ +#define SDP_UUID_ESDP_UPNP_IP_LAP 0x1301 /* ESDP */ +#define SDP_UUID_ESDP_UPNP_L2CAP 0x1302 /* ESDP */ +#define SDP_UUID_VIDEO_SOURCE 0x1303 /* VDP */ +#define SDP_UUID_VIDEO_SINK 0x1304 /* VDP */ +#define SDP_UUID_VIDEO_DISTRIBUTION 0x1305 /* VDP */ +#define SDP_UUID_APPLE_AGENT 0x2112 + +/* Bluetooth assigned numbers for Attribute IDs */ +#define SDP_ATTR_ID_SERVICE_RECORD_HANDLE 0x0000 +#define SDP_ATTR_ID_SERVICE_CLASS_ID_LIST 0x0001 +#define SDP_ATTR_ID_SERVICE_RECORD_STATE 0x0002 +#define SDP_ATTR_ID_SERVICE_SERVICE_ID 0x0003 +#define SDP_ATTR_ID_PROTOCOL_DESCRIPTOR_LIST 0x0004 +#define SDP_ATTR_ID_BROWSE_GROUP_LIST 0x0005 +#define SDP_ATTR_ID_LANGUAGE_BASE_ATTRIBUTE_ID_LIST 0x0006 +#define SDP_ATTR_ID_SERVICE_INFO_TIME_TO_LIVE 0x0007 +#define SDP_ATTR_ID_SERVICE_AVAILABILITY 0x0008 +#define SDP_ATTR_ID_BLUETOOTH_PROFILE_DESCRIPTOR_LIST 0x0009 +#define SDP_ATTR_ID_DOCUMENTATION_URL 0x000A +#define SDP_ATTR_ID_CLIENT_EXECUTABLE_URL 0x000B +#define SDP_ATTR_ID_ICON_10 0x000C +#define SDP_ATTR_ID_ICON_URL 0x000D +#define SDP_ATTR_ID_SERVICE_NAME 0x0100 +#define SDP_ATTR_ID_SERVICE_DESCRIPTION 0x0101 +#define SDP_ATTR_ID_PROVIDER_NAME 0x0102 +#define SDP_ATTR_ID_VERSION_NUMBER_LIST 0x0200 +#define SDP_ATTR_ID_GROUP_ID 0x0200 +#define SDP_ATTR_ID_SERVICE_DATABASE_STATE 0x0201 +#define SDP_ATTR_ID_SERVICE_VERSION 0x0300 + +#define SDP_ATTR_ID_EXTERNAL_NETWORK 0x0301 /* Cordless Telephony */ +#define SDP_ATTR_ID_SUPPORTED_DATA_STORES_LIST 0x0301 /* Synchronization */ +#define SDP_ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 /* GAP */ +#define SDP_ATTR_ID_SUPPORTED_FORMATS_LIST 0x0303 /* OBEX Object Push */ +#define SDP_ATTR_ID_FAX_CLASS_1_SUPPORT 0x0302 /* Fax */ +#define SDP_ATTR_ID_FAX_CLASS_2_0_SUPPORT 0x0303 +#define SDP_ATTR_ID_FAX_CLASS_2_SUPPORT 0x0304 +#define SDP_ATTR_ID_AUDIO_FEEDBACK_SUPPORT 0x0305 +#define SDP_ATTR_ID_SECURITY_DESCRIPTION 0x030a /* PAN */ +#define SDP_ATTR_ID_NET_ACCESS_TYPE 0x030b /* PAN */ +#define SDP_ATTR_ID_MAX_NET_ACCESS_RATE 0x030c /* PAN */ +#define SDP_ATTR_ID_IPV4_SUBNET 0x030d /* PAN */ +#define SDP_ATTR_ID_IPV6_SUBNET 0x030e /* PAN */ + +#define SDP_ATTR_ID_SUPPORTED_CAPABILITIES 0x0310 /* Imaging */ +#define SDP_ATTR_ID_SUPPORTED_FEATURES 0x0311 /* Imaging and Hansfree */ +#define SDP_ATTR_ID_SUPPORTED_FUNCTIONS 0x0312 /* Imaging */ +#define SDP_ATTR_ID_TOTAL_IMAGING_DATA_CAPACITY 0x0313 /* Imaging */ +#define SDP_ATTR_ID_SUPPORTED_REPOSITORIES 0x0314 /* PBAP */ + +const char* sdp_get_uuid_name(int uuid); +const char* sdp_get_attr_id_name(int attr_id); + +#endif /* __SDP_H */ -- cgit v1.2.1