mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
don't process SDP record for EMBEDDED configuration - no malloc uese
This commit is contained in:
parent
9cfcc54d6f
commit
7934ed2f08
42
src/sdp.c
42
src/sdp.c
@ -38,27 +38,12 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <btstack/linked_list.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
#include "l2cap.h"
|
||||
|
||||
// max reserved ServiceRecordHandle
|
||||
#define maxReservedServiceRecordHandle 0xffff
|
||||
|
||||
// service record
|
||||
// -- uses user_data field for actual
|
||||
typedef struct {
|
||||
// linked list - assert: first field
|
||||
linked_item_t item;
|
||||
|
||||
// client connection
|
||||
void * connection;
|
||||
|
||||
// data is contained in same memory
|
||||
uint32_t service_record_handle;
|
||||
uint8_t service_record[0];
|
||||
} service_record_item_t;
|
||||
|
||||
static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
// registered service records
|
||||
@ -108,7 +93,30 @@ uint32_t sdp_create_service_record_handle(){
|
||||
return handle;
|
||||
}
|
||||
|
||||
// register service record internally
|
||||
#ifdef EMBEDDED
|
||||
|
||||
// register service record internally - this special version doesn't copy the record, it cannot be freeed
|
||||
// pre: AttributeIDs are in ascending order
|
||||
// pre: ServiceRecordHandle is first attribute and valid
|
||||
// pre: record
|
||||
// @returns ServiceRecordHandle or 0 if registration failed
|
||||
uint32_t sdp_register_service_internal(void *connection, service_record_item_t * record_item){
|
||||
// get user record handle
|
||||
uint32_t record_handle = record_itme->service_record_handle;
|
||||
// validate service record handle is not in reserved range
|
||||
if (record_handle <= maxReservedServiceRecordHandle) record_handle = 0;
|
||||
// check if already registered
|
||||
if (sdp_get_record_for_handle(record_handle)) {
|
||||
return 0;
|
||||
}
|
||||
// add to linked list
|
||||
linked_list_add(&sdp_service_records, (linked_item_t *) record_item);
|
||||
return record_handle;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// register service record internally - the normal version creates a copy of the record
|
||||
// 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(void *connection, uint8_t * record){
|
||||
@ -171,6 +179,8 @@ uint32_t sdp_register_service_internal(void *connection, uint8_t * record){
|
||||
return record_handle;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// unregister service record internally
|
||||
//
|
||||
// makes sure one client cannot remove service records of other clients
|
||||
|
28
src/sdp.h
28
src/sdp.h
@ -31,6 +31,7 @@
|
||||
#pragma mark once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <btstack/linked_list.h>
|
||||
|
||||
typedef enum {
|
||||
SDP_ErrorResponse = 1,
|
||||
@ -42,11 +43,36 @@ typedef enum {
|
||||
SDP_ServiceSearchAttributeResponse
|
||||
} SDP_PDU_ID_t;
|
||||
|
||||
// service record
|
||||
// -- uses user_data field for actual
|
||||
typedef struct {
|
||||
// linked list - assert: first field
|
||||
linked_item_t item;
|
||||
|
||||
// client connection
|
||||
void * connection;
|
||||
|
||||
// data is contained in same memory
|
||||
uint32_t service_record_handle;
|
||||
uint8_t service_record[0];
|
||||
} service_record_item_t;
|
||||
|
||||
|
||||
void sdp_init();
|
||||
|
||||
// register service record internally
|
||||
#ifdef EMBEDDED
|
||||
// register service record internally - the normal version creates a copy of the record
|
||||
// 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(void *connection, service_record_item_t * record_item);
|
||||
#else
|
||||
// register service record internally - this special version doesn't copy the record, it cannot be freeed
|
||||
// pre: AttributeIDs are in ascending order
|
||||
// pre: ServiceRecordHandle is first attribute and valid
|
||||
// pre: record
|
||||
// @returns ServiceRecordHandle or 0 if registration failed
|
||||
uint32_t sdp_register_service_internal(void *connection, uint8_t * service_record);
|
||||
#endif
|
||||
|
||||
// unregister service record internally
|
||||
void sdp_unregister_service_internal(void *connection, uint32_t service_record_handle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user