1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 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 BLUEKITCHEN GMBH 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 34 * [email protected] 35 * 36 */ 37 38 /* 39 * sdp_util.h 40 */ 41 42 #ifndef __SDP_UTIL_H 43 #define __SDP_UTIL_H 44 45 #include <stdint.h> 46 47 #if defined __cplusplus 48 extern "C" { 49 #endif 50 51 /* API_START */ 52 53 typedef enum { 54 DE_NIL = 0, 55 DE_UINT, 56 DE_INT, 57 DE_UUID, 58 DE_STRING, 59 DE_BOOL, 60 DE_DES, 61 DE_DEA, 62 DE_URL 63 } de_type_t; 64 65 typedef enum { 66 DE_SIZE_8 = 0, 67 DE_SIZE_16, 68 DE_SIZE_32, 69 DE_SIZE_64, 70 DE_SIZE_128, 71 DE_SIZE_VAR_8, 72 DE_SIZE_VAR_16, 73 DE_SIZE_VAR_32 74 } de_size_t; 75 76 // MARK: DateElement 77 void de_dump_data_element(uint8_t * record); 78 int de_get_len(uint8_t *header); 79 de_size_t de_get_size_type(uint8_t *header); 80 de_type_t de_get_element_type(uint8_t *header); 81 int de_get_header_size(uint8_t * header); 82 void de_create_sequence(uint8_t *header); 83 void de_store_descriptor_with_len(uint8_t * header, de_type_t type, de_size_t size, uint32_t len); 84 uint8_t * de_push_sequence(uint8_t *header); 85 void de_pop_sequence(uint8_t * parent, uint8_t * child); 86 void de_add_number(uint8_t *seq, de_type_t type, de_size_t size, uint32_t value); 87 void de_add_data( uint8_t *seq, de_type_t type, uint16_t size, uint8_t *data); 88 int de_element_get_uint16(uint8_t * element, uint16_t * value); 89 90 int de_get_data_size(uint8_t * header); 91 void de_add_uuid128(uint8_t * seq, uint8_t * uuid); 92 uint32_t de_get_uuid32(uint8_t * element); 93 int de_get_normalized_uuid(uint8_t *uuid128, uint8_t *element); 94 95 // MARK: DES iterator 96 typedef struct { 97 uint8_t * element; 98 uint16_t pos; 99 uint16_t length; 100 } des_iterator_t; 101 102 int des_iterator_init(des_iterator_t * it, uint8_t * element); 103 int des_iterator_has_more(des_iterator_t * it); 104 de_type_t des_iterator_get_type (des_iterator_t * it); 105 uint16_t des_iterator_get_size (des_iterator_t * it); 106 uint8_t * des_iterator_get_element(des_iterator_t * it); 107 void des_iterator_next(des_iterator_t * it); 108 109 // MARK: SDP 110 uint16_t sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startOffset, uint16_t maxBytes, uint8_t *buffer); 111 uint8_t * sdp_get_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID); 112 uint8_t sdp_set_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID, uint32_t value); 113 int sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern); 114 int spd_get_filtered_size(uint8_t *record, uint8_t *attributeIDList); 115 int sdp_filter_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startOffset, uint16_t maxBytes, uint16_t *usedBytes, uint8_t *buffer); 116 int sdp_attribute_list_constains_id(uint8_t *attributeIDList, uint16_t attributeID); 117 int sdp_traversal_match_pattern(uint8_t * element, de_type_t attributeType, de_size_t size, void *my_context); 118 119 void sdp_create_spp_service(uint8_t *service, uint32_t service_record_handle, int service_id, const char *name); 120 121 /* API_END */ 122 123 #if defined __cplusplus 124 } 125 #endif 126 127 #endif // __SDP_UTIL_H 128