diff options
author | Alexander Orlenko <zxteam@gmail.com> | 2010-07-09 23:46:55 +1100 |
---|---|---|
committer | Alexander Orlenko <zxteam@gmail.com> | 2010-07-09 23:46:55 +1100 |
commit | 024e778b2cae61d9b72223d2363666a037eec92d (patch) | |
tree | 1291d8c8ce9291565cdd2972f59d93e2c0c5c152 | |
parent | 2c383fb4b14c9225cf41e77d5c5da62ddf8e4bda (diff) | |
download | bluez-tools-024e778b2cae61d9b72223d2363666a037eec92d.tar.gz |
Implemented bt-network
-rw-r--r-- | src/bt-audio.c | 8 | ||||
-rw-r--r-- | src/bt-network.c | 108 | ||||
-rw-r--r-- | src/lib/helpers.c | 117 |
3 files changed, 173 insertions, 60 deletions
diff --git a/src/bt-audio.c b/src/bt-audio.c index f76a647..67fc49f 100644 --- a/src/bt-audio.c +++ b/src/bt-audio.c @@ -33,10 +33,10 @@ static void audio_property_changed(Audio *audio, const gchar *name, const GValue *value, gpointer data) { GMainLoop *mainloop = data; - if (g_strcmp0(name, "state") == 0) { - if (g_strcmp0(g_value_get_string(value), "connecting") == 0) { + if (g_strcmp0(name, "State") == 0) { + if (g_ascii_strcasecmp(g_value_get_string(value), "connecting") == 0) { g_print("Connecting to an audio service\n"); - } else if (g_strcmp0(g_value_get_string(value), "connected") == 0) { + } else if (g_ascii_strcasecmp(g_value_get_string(value), "connected") == 0) { g_print("Audio service is connected\n"); g_main_loop_quit(mainloop); } else { @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) if (g_strcmp0(audio_get_state(audio), "connected") == 0) { g_print("Audio service is already connected\n"); } else if (g_strcmp0(audio_get_state(audio), "connecting") == 0) { - //g_print("Audio service is already connecting\n"); + g_print("Audio service is already in connection state\n"); } else { audio_connect(audio, &error); exit_if_error(error); diff --git a/src/bt-network.c b/src/bt-network.c index 67cf115..1c1e289 100644 --- a/src/bt-network.c +++ b/src/bt-network.c @@ -30,8 +30,116 @@ #include "lib/bluez-dbus.h" +static void network_property_changed(Network *network, const gchar *name, const GValue *value, gpointer data) +{ + GMainLoop *mainloop = data; + if (g_strcmp0(name, "Connected") == 0) { + if (g_value_get_boolean(value) == TRUE) { + g_print("Network service is connected\n"); + } else { + g_print("Network service is disconnected\n"); + } + g_main_loop_quit(mainloop); + } +} + +static gchar *adapter_arg = NULL; +static gboolean connect_arg = FALSE; +static gchar *connect_device_arg = NULL; +static gchar *connect_service_arg = NULL; +static gchar *disconnect_arg = NULL; + +static GOptionEntry entries[] = { + {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter name or MAC", "adapter#id"}, + {"connect", 'c', 0, G_OPTION_ARG_NONE, &connect_arg, "Connect to a network device", NULL}, + {"disconnect", 'd', 0, G_OPTION_ARG_STRING, &disconnect_arg, "Disconnect from a network device", "device#id"}, + {NULL} +}; + int main(int argc, char *argv[]) { + GError *error = NULL; + GOptionContext *context; + + g_type_init(); + + context = g_option_context_new("- a bluetooth network manager"); + g_option_context_add_main_entries(context, entries, NULL); + g_option_context_set_summary(context, "network summary"); + g_option_context_set_description(context, + "Connect Options:\n" + " -c, --connect <device#id> <pattern>\n" + " Where `pattern` is:\n" + " UUID 128 bit string\n" + " Profile short name: gn, panu or nap\n" + " UUID hexadecimal number\n\n" + "network desc" + ); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("%s: %s\n", g_get_prgname(), error->message); + g_print("Try `%s --help` for more information.\n", g_get_prgname()); + exit(EXIT_FAILURE); + } else if (!connect_arg && !disconnect_arg) { + g_print("%s", g_option_context_get_help(context, FALSE, NULL)); + exit(EXIT_FAILURE); + } else if (connect_arg && argc != 3) { + g_print("%s: Invalid arguments for --connect\n", g_get_prgname()); + g_print("Try `%s --help` for more information.\n", g_get_prgname()); + exit(EXIT_FAILURE); + } + + g_option_context_free(context); + + if (connect_arg) { + connect_device_arg = argv[1]; + connect_service_arg = argv[2]; + } + + if (!dbus_connect(&error)) { + g_printerr("Couldn't connect to dbus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + Adapter *adapter = find_adapter(adapter_arg, &error); + exit_if_error(error); + + Device *device = find_device(adapter, connect_device_arg != NULL ? connect_device_arg : disconnect_arg, &error); + exit_if_error(error); + + // TODO: Test to NETWORK service + + GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); + + Network *network = g_object_new(NETWORK_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL); + g_signal_connect(network, "PropertyChanged", G_CALLBACK(network_property_changed), mainloop); + + if (connect_arg) { + if (network_get_connected(network) == TRUE) { + g_print("Network service is already connected\n"); + } else { + gchar *intf = network_connect(network, connect_service_arg, &error); + exit_if_error(error); + g_main_loop_run(mainloop); + g_free(intf); + } + g_print("Interface: %s\n", network_get_interface(network)); + g_print("UUID: %s\n", network_get_uuid(network)); + } else if (disconnect_arg) { + if (network_get_connected(network) == FALSE) { + g_print("Network service is already disconnected\n"); + } else { + network_disconnect(network, &error); + exit_if_error(error); + g_main_loop_run(mainloop); + } + } + + g_main_loop_unref(mainloop); + g_object_unref(network); + g_object_unref(device); + g_object_unref(adapter); + exit(EXIT_SUCCESS); } diff --git a/src/lib/helpers.c b/src/lib/helpers.c index c9f0dd6..d7b7557 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -38,63 +38,68 @@ typedef struct { } 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"}, + {"00001000-0000-1000-8000-00805F9B34FB", "ServiceDiscoveryServerService"}, + {"00001001-0000-1000-8000-00805F9B34FB", "BrowseGroupDescriptorService"}, + {"00001002-0000-1000-8000-00805F9B34FB", "PublicBrowseGroupService"}, + {"00001101-0000-1000-8000-00805F9B34FB", "SerialPortService"}, + {"00001102-0000-1000-8000-00805F9B34FB", "LANAccessUsingPPPService"}, + {"00001103-0000-1000-8000-00805F9B34FB", "DialupNetworkingService"}, + {"00001104-0000-1000-8000-00805F9B34FB", "IrMCSyncService"}, + {"00001105-0000-1000-8000-00805F9B34FB", "OBEXObjectPushService"}, + {"00001106-0000-1000-8000-00805F9B34FB", "OBEXFileTransferService"}, + {"00001107-0000-1000-8000-00805F9B34FB", "IrMCSyncCommandService"}, + {"00001108-0000-1000-8000-00805F9B34FB", "HeadsetService"}, + {"00001109-0000-1000-8000-00805F9B34FB", "CordlessTelephonyService"}, + {"0000110A-0000-1000-8000-00805F9B34FB", "AudioSourceService"}, + {"0000110B-0000-1000-8000-00805F9B34FB", "AudioSinkService"}, + {"0000110C-0000-1000-8000-00805F9B34FB", "AVRemoteControlTargetService"}, + {"0000110D-0000-1000-8000-00805F9B34FB", "AdvancedAudioDistributionService"}, + {"0000110E-0000-1000-8000-00805F9B34FB", "AVRemoteControlService"}, + {"0000110F-0000-1000-8000-00805F9B34FB", "VideoConferencingService"}, + {"00001110-0000-1000-8000-00805F9B34FB", "IntercomService"}, + {"00001111-0000-1000-8000-00805F9B34FB", "FaxService"}, + {"00001112-0000-1000-8000-00805F9B34FB", "HeadsetAudioGatewayService"}, + {"00001113-0000-1000-8000-00805F9B34FB", "WAPService"}, + {"00001114-0000-1000-8000-00805F9B34FB", "WAPClientService"}, + {"00001115-0000-1000-8000-00805F9B34FB", "PANUService"}, + {"00001116-0000-1000-8000-00805F9B34FB", "NAPService"}, + {"00001117-0000-1000-8000-00805F9B34FB", "GNService"}, + {"00001118-0000-1000-8000-00805F9B34FB", "DirectPrintingService"}, + {"00001119-0000-1000-8000-00805F9B34FB", "ReferencePrintingService"}, + {"0000111A-0000-1000-8000-00805F9B34FB", "ImagingService"}, + {"0000111B-0000-1000-8000-00805F9B34FB", "ImagingResponderService"}, + {"0000111C-0000-1000-8000-00805F9B34FB", "ImagingAutomaticArchiveService"}, + {"0000111D-0000-1000-8000-00805F9B34FB", "ImagingReferenceObjectsService"}, + {"0000111E-0000-1000-8000-00805F9B34FB", "HandsfreeService"}, + {"0000111F-0000-1000-8000-00805F9B34FB", "HandsfreeAudioGatewayService"}, + {"00001120-0000-1000-8000-00805F9B34FB", "DirectPrintingReferenceObjectsService"}, + {"00001121-0000-1000-8000-00805F9B34FB", "ReflectedUIService"}, + {"00001122-0000-1000-8000-00805F9B34FB", "BasicPringingService"}, + {"00001123-0000-1000-8000-00805F9B34FB", "PrintingStatusService"}, + {"00001124-0000-1000-8000-00805F9B34FB", "HumanInterfaceDeviceService"}, + {"00001125-0000-1000-8000-00805F9B34FB", "HardcopyCableReplacementService"}, + {"00001126-0000-1000-8000-00805F9B34FB", "HCRPrintService"}, + {"00001127-0000-1000-8000-00805F9B34FB", "HCRScanService"}, + {"00001128-0000-1000-8000-00805F9B34FB", "CommonISDNAccessService"}, + {"00001129-0000-1000-8000-00805F9B34FB", "VideoConferencingGWService"}, + {"0000112A-0000-1000-8000-00805F9B34FB", "UDIMTService"}, + {"0000112B-0000-1000-8000-00805F9B34FB", "UDITAService"}, + {"0000112C-0000-1000-8000-00805F9B34FB", "AudioVideoService"}, + {"00001200-0000-1000-8000-00805F9B34FB", "PnPInformationService"}, + {"00001201-0000-1000-8000-00805F9B34FB", "GenericNetworkingService"}, + {"00001202-0000-1000-8000-00805F9B34FB", "GenericFileTransferService"}, + {"00001203-0000-1000-8000-00805F9B34FB", "GenericAudioService"}, + {"00001203-0000-1000-8000-00805F9B34FB", "GenericAudioService"}, + {"00001204-0000-1000-8000-00805F9B34FB", "GenericTelephonyService"}, + {"00001205-0000-1000-8000-00805F9B34FB", "UPnPService"}, + {"00001206-0000-1000-8000-00805F9B34FB", "UPnPIpService"}, + {"00001300-0000-1000-8000-00805F9B34FB", "ESdpUPnPIpPanService"}, + {"00001301-0000-1000-8000-00805F9B34FB", "ESdpUPnPIpLapService"}, + {"00001302-0000-1000-8000-00805F9B34FB", "EdpUPnpIpL2CAPService"}, // Custom: - {"0000112f-0000-1000-8000-00805f9b34fb", "PhoneBookAccess"}, - {"831c4071-7bc8-4a9c-a01c-15df25a4adbc", "ActiveSync"}, + {"0000112F-0000-1000-8000-00805F9B34FB", "PhoneBookAccessService"}, + {"831C4071-7BC8-4A9C-A01C-15DF25A4ADBC", "ActiveSyncService"}, }; #define UUID_NAME_LOOKUP_TABLE_SIZE \ @@ -103,7 +108,7 @@ static uuid_name_lookup_table_t uuid_name_lookup_table[] = { 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) + if (g_ascii_strcasecmp(uuid_name_lookup_table[i].uuid, uuid) == 0) return uuid_name_lookup_table[i].name; } |