[352] | 1 | /*
|
---|
| 2 | * Copyright (C) 2009-2012 by Matthias Ringwald
|
---|
| 3 | *
|
---|
| 4 | * Redistribution and use in source and binary forms, with or without
|
---|
| 5 | * modification, are permitted provided that the following conditions
|
---|
| 6 | * are met:
|
---|
| 7 | *
|
---|
| 8 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 9 | * notice, this list of conditions and the following disclaimer.
|
---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 12 | * documentation and/or other materials provided with the distribution.
|
---|
| 13 | * 3. Neither the name of the copyright holders nor the names of
|
---|
| 14 | * contributors may be used to endorse or promote products derived
|
---|
| 15 | * from this software without specific prior written permission.
|
---|
| 16 | * 4. Any redistribution, use, or modification is done solely for
|
---|
| 17 | * personal benefit and not for any commercial purpose or for
|
---|
| 18 | * monetary gain.
|
---|
| 19 | *
|
---|
| 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
|
---|
| 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
| 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
---|
| 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
---|
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
---|
| 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
---|
| 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 31 | * SUCH DAMAGE.
|
---|
| 32 | *
|
---|
| 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
| 36 | #ifndef __SDP_H
|
---|
| 37 | #define __SDP_H
|
---|
| 38 |
|
---|
| 39 | #include <stdint.h>
|
---|
| 40 | #include <btstack/linked_list.h>
|
---|
| 41 |
|
---|
| 42 | #include "btstack-config.h"
|
---|
| 43 |
|
---|
| 44 | #if defined __cplusplus
|
---|
| 45 | extern "C" {
|
---|
| 46 | #endif
|
---|
| 47 |
|
---|
| 48 | typedef enum {
|
---|
| 49 | SDP_Invalid = 0,
|
---|
| 50 | SDP_ErrorResponse = 1,
|
---|
| 51 | SDP_ServiceSearchRequest,
|
---|
| 52 | SDP_ServiceSearchResponse,
|
---|
| 53 | SDP_ServiceAttributeRequest,
|
---|
| 54 | SDP_ServiceAttributeResponse,
|
---|
| 55 | SDP_ServiceSearchAttributeRequest,
|
---|
| 56 | SDP_ServiceSearchAttributeResponse
|
---|
| 57 | } SDP_PDU_ID_t;
|
---|
| 58 |
|
---|
| 59 | // service record
|
---|
| 60 | // -- uses user_data field for actual
|
---|
| 61 | typedef struct {
|
---|
| 62 | // linked list - assert: first field
|
---|
| 63 | linked_item_t item;
|
---|
| 64 |
|
---|
| 65 | // client connection
|
---|
| 66 | void * connection;
|
---|
| 67 |
|
---|
| 68 | // data is contained in same memory
|
---|
| 69 | uint32_t service_record_handle;
|
---|
| 70 | uint8_t service_record[1]; // waste 1 byte to allow compilation with older compilers
|
---|
| 71 | } service_record_item_t;
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | void sdp_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type,
|
---|
| 75 | uint16_t channel, uint8_t *packet, uint16_t size));
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | //
|
---|
| 79 | int sdp_handle_service_search_request(uint8_t * packet, uint16_t remote_mtu);
|
---|
| 80 | int sdp_handle_service_attribute_request(uint8_t * packet, uint16_t remote_mtu);
|
---|
| 81 | int sdp_handle_service_search_attribute_request(uint8_t * packet, uint16_t remote_mtu);
|
---|
| 82 |
|
---|
| 83 | #ifndef EMBEDDED
|
---|
| 84 | // Register service record internally - this version creates a copy of the record
|
---|
| 85 | // precondition: AttributeIDs are in ascending order => ServiceRecordHandle is first attribute if present
|
---|
| 86 | // @returns ServiceRecordHandle or 0 if registration failed
|
---|
| 87 | uint32_t sdp_register_service_internal(void *connection, uint8_t * service_record);
|
---|
| 88 | #endif
|
---|
| 89 |
|
---|
| 90 | //
|
---|
| 91 |
|
---|
| 92 | /** Embedded API **/
|
---|
| 93 |
|
---|
| 94 | // Set up SDP.
|
---|
| 95 | void sdp_init(void);
|
---|
| 96 |
|
---|
| 97 | #ifdef EMBEDDED
|
---|
| 98 | // Register service record internally - this version doesn't copy the record therefore it must be forever accessible.
|
---|
| 99 | // Preconditions:
|
---|
| 100 | // - AttributeIDs are in ascending order;
|
---|
| 101 | // - ServiceRecordHandle is first attribute and valid.
|
---|
| 102 | // @returns ServiceRecordHandle or 0 if registration failed.
|
---|
| 103 | uint32_t sdp_register_service_internal(void *connection, service_record_item_t * record_item);
|
---|
| 104 | #endif
|
---|
| 105 |
|
---|
| 106 | // Unregister service record internally.
|
---|
| 107 | void sdp_unregister_service_internal(void *connection, uint32_t service_record_handle);
|
---|
| 108 |
|
---|
| 109 | #if defined __cplusplus
|
---|
| 110 | }
|
---|
| 111 | #endif
|
---|
| 112 | #endif // __SDP_H
|
---|