From 5b0ad4acac274ee0c37ffd6accd6c6c492bb30de Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Wed, 9 Jun 2010 17:33:28 +0000 Subject: [PATCH] added sdp preliminaries --- include/btstack/sdp.h | 42 ++++++++++++++ src/Makefile.in | 2 + src/sdp.c | 127 ++++++++++++++++++++++++++++++++++++++++++ src/sdp_util.c | 33 ++--------- 4 files changed, 176 insertions(+), 28 deletions(-) create mode 100644 include/btstack/sdp.h create mode 100644 src/sdp.c diff --git a/include/btstack/sdp.h b/include/btstack/sdp.h new file mode 100644 index 000000000..76d949ec8 --- /dev/null +++ b/include/btstack/sdp.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#pragma mark once + +#include + +void sdp_init(); + +// register service record internally +// @returns ServiceRecordHandle or 0 if registration failed +uint32_t sdp_register_service_internal(uint8_t * service_record); + +// unregister service record internally +void sdp_unregister_service(uint32_t service_record_handle); diff --git a/src/Makefile.in b/src/Makefile.in index f138233a7..5aa947505 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -22,6 +22,8 @@ BTdaemon_SOURCES = $(libBTstack_SOURCES) \ l2cap.c \ l2cap_signaling.c \ platform_iphone.c \ + sdp.c \ + sdp_util.c \ $(springboard_access_sources) all: libBTstack.$(BTSTACK_LIB_EXTENSION) libBTstack.a BTdaemon diff --git a/src/sdp.c b/src/sdp.c new file mode 100644 index 000000000..ab38bd591 --- /dev/null +++ b/src/sdp.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2010 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/* + * Implementation of the Service Discovery Protocol Server + */ + +#include + +#include + +#include +#include "l2cap.h" + +static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); + +void sdp_init(){ + // register with l2cap psm sevices + l2cap_register_service_internal(NULL, sdp_packet_handler, PSM_SDP, 250); +} + +// register service record internally +// @returns ServiceRecordHandle or 0 if registration failed +uint32_t sdp_register_service_internal(uint8_t * service_record){ + return 0; +} + +// unregister service record internally +void sdp_unregister_service(uint32_t service_record_handle){ +} + +// PDU +// PDU ID (1), Transaction ID (2), Param Length (2), Param 1, Param 2, .. + +static uint8_t sdp_response_buffer[250]; + +static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ + bd_addr_t event_addr; + uint16_t handle; + uint16_t psm; + uint16_t local_cid; + uint16_t remote_cid; + uint16_t transaction_id; + uint8_t pdu_id; + uint16_t param_len; + + + switch (packet_type) { + + case L2CAP_DATA_PACKET: + pdu_id = packet[0]; + transaction_id = READ_NET_16(packet, 1); + param_len = READ_NET_16(packet, 3); + printf("SDP Request: type %u, transaction id %u, len %u\n", pdu_id, transaction_id, param_len); + switch (pdu_id){ + case 6: // handle SDP_ServiceSearchAttributeRequest + // header + sdp_response_buffer[0] = 7; + net_store_16(sdp_response_buffer, 1, transaction_id); + net_store_16(sdp_response_buffer, 3, 5); // empty list + + // AttributeListsByteCount + net_store_16(sdp_response_buffer, 5, 2); // should be 3, but I see 2 used for empty list + // AttributeLists + sdp_response_buffer[7] = 0x35; + net_store_16(sdp_response_buffer, 8, 0); // DES len = 0 + l2cap_send_internal(channel, sdp_response_buffer, 5 + 5); + break; + default: + // just dump data for now + printf("source cid %x -- ", channel); + hexdump( packet, size ); + break; + } + break; + + case HCI_EVENT_PACKET: + + switch (packet[0]) { + + case L2CAP_EVENT_INCOMING_CONNECTION: + // accept + l2cap_accept_connection_internal(channel); + break; + + default: + // other event + break; + } + break; + + default: + // other packet type + break; + } +} + + + diff --git a/src/sdp_util.c b/src/sdp_util.c index 71fa195c8..3c3c01195 100644 --- a/src/sdp_util.c +++ b/src/sdp_util.c @@ -33,7 +33,8 @@ * sdp_util.c */ -#include "sdp_util.h" +#include +#include #include #include @@ -89,33 +90,6 @@ static uint32_t sdp_next_service_record_handle = maxReservedServiceRecordHandle #define READ_NET_16( buffer, pos) ( ((uint16_t) buffer[pos+1]) | (((uint16_t)buffer[pos ]) << 8)) #define READ_NET_32( buffer, pos) ( ((uint32_t) buffer[pos+3]) | (((uint32_t)buffer[pos+2]) << 8) | (((uint32_t)buffer[pos+1]) << 16) | (((uint32_t) buffer[pos])) << 24) -void net_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){ - buffer[pos++] = value >> 8; - buffer[pos++] = value; -} - -void net_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){ - buffer[pos++] = value >> 24; - buffer[pos++] = value >> 16; - buffer[pos++] = value >> 8; - buffer[pos++] = value; -} - -// temp cop from utils.c -void hexdump(void *data, int size){ - int i; - for (i=0; i