mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-12 15:47:14 +00:00
added sdp preliminaries
This commit is contained in:
parent
c840b07bfe
commit
5b0ad4acac
42
include/btstack/sdp.h
Normal file
42
include/btstack/sdp.h
Normal file
@ -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 <stdint.h>
|
||||
|
||||
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);
|
@ -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
|
||||
|
127
src/sdp.c
Normal file
127
src/sdp.c
Normal file
@ -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 <btstack/sdp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <btstack/sdp_util.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,8 @@
|
||||
* sdp_util.c
|
||||
*/
|
||||
|
||||
#include "sdp_util.h"
|
||||
#include <btstack/sdp_util.h>
|
||||
#include <btstack/utils.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
@ -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<size;i++){
|
||||
printf("%02X ", ((uint8_t *)data)[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void printUUID(uint8_t *uuid) {
|
||||
printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
|
||||
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
|
||||
}
|
||||
|
||||
void sdp_normalize_uuid(uint8_t *uuid, uint32_t shortUUID){
|
||||
memcpy(uuid, sdp_bluetooth_base_uuid, 16);
|
||||
net_store_32(uuid, 0, shortUUID);
|
||||
@ -564,6 +538,8 @@ int sdp_get_record_handles_for_service_search_pattern(uint8_t * searchServicePat
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
uint8_t buffer[100];
|
||||
uint8_t record[100];
|
||||
uint8_t attributes[100];
|
||||
@ -667,3 +643,4 @@ int main(){
|
||||
printf("new handle %08x \n", handle);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user