From c1b43b8cbf456009709c2bfac2ea092aca9b5191 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 13 Jun 2010 08:26:47 +0000 Subject: [PATCH] pass on connection to sdp register functions, call sdp_unregister_services_for_connection when client disconnects --- src/daemon.c | 14 ++++++++------ src/sdp.c | 12 ++++++++---- {include/btstack => src}/sdp.h | 8 ++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) rename {include/btstack => src}/sdp.h (87%) diff --git a/src/daemon.c b/src/daemon.c index a13ff68bb..d7a6175b9 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -48,13 +48,14 @@ #include -#include "hci.h" -#include "hci_dump.h" -#include "l2cap.h" #include #include #include -#include + +#include "hci.h" +#include "hci_dump.h" +#include "l2cap.h" +#include "sdp.h" #include "socket_connection.h" #ifdef USE_BLUETOOL @@ -168,11 +169,11 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui break; case SDP_REGISTER_SERVICE_RECORD: printf("SDP_REGISTER_SERVICE_RECORD size %u\n", size); - sdp_register_service_internal(&packet[3]); + sdp_register_service_internal(connection, &packet[3]); break; case SDP_UNREGISTER_SERVICE_RECORD: service_record_handle = READ_BT_32(packet, 3); - sdp_unregister_service_internal(service_record_handle); + sdp_unregister_service_internal(connection, service_record_handle); break; default: //@TODO: log into hci dump as vendor specific "event" @@ -203,6 +204,7 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type, case DAEMON_EVENT_PACKET: switch (data[0]) { case DAEMON_EVENT_CONNECTION_CLOSED: + sdp_unregister_services_for_connection(connection); l2cap_close_connection(connection); break; case DAEMON_NR_CONNECTIONS_CHANGED: diff --git a/src/sdp.c b/src/sdp.c index c40fe95e6..40bbcafa2 100644 --- a/src/sdp.c +++ b/src/sdp.c @@ -33,7 +33,7 @@ * Implementation of the Service Discovery Protocol Server */ -#include +#include "sdp.h" #include @@ -61,7 +61,7 @@ static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p linked_list_t sdp_service_records; // our handles start after the reserved range -static uint32_t sdp_next_service_record_handle = maxReservedServiceRecordHandle + 1; +static uint32_t sdp_next_service_record_handle = maxReservedServiceRecordHandle + 2; // AttributeIDList used to remove ServiceRecordHandle const uint8_t removeServiceRecordHandleAttributeIDList[] = { 0x36, 0x00, 0x05, 0x0A, 0x00, 0x01, 0xFF, 0xFF }; @@ -103,7 +103,7 @@ uint32_t sdp_create_service_record_handle(){ // register service record internally // pre: AttributeIDs are in ascending order => ServiceRecordHandle is first attribute if present // @returns ServiceRecordHandle or 0 if registration failed -uint32_t sdp_register_service_internal(uint8_t * record){ +uint32_t sdp_register_service_internal(connection_t *connection, uint8_t * record){ // dump for now printf("Register service record\n"); @@ -160,13 +160,17 @@ uint32_t sdp_register_service_internal(uint8_t * record){ } // unregister service record internally -void sdp_unregister_service_internal(uint32_t service_record_handle){ +void sdp_unregister_service_internal(connection_t *connection, uint32_t service_record_handle){ service_record_item_t * record_item = sdp_get_record_for_handle(service_record_handle); if (record_item) { linked_list_remove(&sdp_service_records, (linked_item_t *) record_item); } } +// remove all service record for a client +void sdp_unregister_services_for_connection(connection_t *connectino){ +} + // PDU // PDU ID (1), Transaction ID (2), Param Length (2), Param 1, Param 2, .. diff --git a/include/btstack/sdp.h b/src/sdp.h similarity index 87% rename from include/btstack/sdp.h rename to src/sdp.h index e63ff00d6..51cc37659 100644 --- a/include/btstack/sdp.h +++ b/src/sdp.h @@ -31,6 +31,7 @@ #pragma mark once #include +#include "socket_connection.h" typedef enum { SDP_ErrorResponse = 1, @@ -46,7 +47,10 @@ void sdp_init(); // register service record internally // @returns ServiceRecordHandle or 0 if registration failed -uint32_t sdp_register_service_internal(uint8_t * service_record); +uint32_t sdp_register_service_internal(connection_t *connection, uint8_t * service_record); // unregister service record internally -void sdp_unregister_service_internal(uint32_t service_record_handle); +void sdp_unregister_service_internal(connection_t *connection, uint32_t service_record_handle); + +// +void sdp_unregister_services_for_connection(connection_t *connection);