1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <bluetooth/uuid.h> 20 #include <raw_address.h> 21 22 #include "bluetooth.h" 23 24 #define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15 25 26 __BEGIN_DECLS 27 28 /** 29 * These events are handled by the state machine 30 */ 31 typedef enum { 32 SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUIDs 33 SDP_TYPE_MAP_MAS, // Message Access Profile - Server 34 SDP_TYPE_MAP_MNS, // Message Access Profile - Client (Notification Server) 35 SDP_TYPE_PBAP_PSE, // Phone Book Profile - Server 36 SDP_TYPE_PBAP_PCE, // Phone Book Profile - Client 37 SDP_TYPE_OPP_SERVER, // Object Push Profile 38 SDP_TYPE_SAP_SERVER, // SIM Access Profile 39 SDP_TYPE_DIP // Device Identification Profile 40 } bluetooth_sdp_types; 41 42 typedef struct _bluetooth_sdp_hdr { 43 bluetooth_sdp_types type; 44 bluetooth::Uuid uuid; 45 uint32_t service_name_length; 46 char* service_name; 47 int32_t rfcomm_channel_number; 48 int32_t l2cap_psm; 49 int32_t profile_version; 50 } bluetooth_sdp_hdr; 51 52 /** 53 * Some signals need additional pointers, hence we introduce a 54 * generic way to handle these pointers. 55 */ 56 typedef struct _bluetooth_sdp_hdr_overlay { 57 bluetooth_sdp_types type; 58 bluetooth::Uuid uuid; 59 uint32_t service_name_length; 60 const char* service_name; 61 int32_t rfcomm_channel_number; 62 int32_t l2cap_psm; 63 int32_t profile_version; 64 65 // User pointers, only used for some signals - see bluetooth_sdp_ops_record 66 int user1_ptr_len; 67 const uint8_t* user1_ptr; 68 int user2_ptr_len; 69 const uint8_t* user2_ptr; 70 } bluetooth_sdp_hdr_overlay; 71 72 typedef struct _bluetooth_sdp_mas_record { 73 bluetooth_sdp_hdr_overlay hdr; 74 uint32_t mas_instance_id; 75 uint32_t supported_features; 76 uint32_t supported_message_types; 77 } bluetooth_sdp_mas_record; 78 79 typedef struct _bluetooth_sdp_mns_record { 80 bluetooth_sdp_hdr_overlay hdr; 81 uint32_t supported_features; 82 } bluetooth_sdp_mns_record; 83 84 typedef struct _bluetooth_sdp_pse_record { 85 bluetooth_sdp_hdr_overlay hdr; 86 uint32_t supported_features; 87 uint32_t supported_repositories; 88 } bluetooth_sdp_pse_record; 89 90 typedef struct _bluetooth_sdp_pce_record { 91 bluetooth_sdp_hdr_overlay hdr; 92 } bluetooth_sdp_pce_record; 93 94 typedef struct _bluetooth_sdp_ops_record { 95 bluetooth_sdp_hdr_overlay hdr; 96 int supported_formats_list_len; 97 uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH]; 98 } bluetooth_sdp_ops_record; 99 100 typedef struct _bluetooth_sdp_sap_record { 101 bluetooth_sdp_hdr_overlay hdr; 102 } bluetooth_sdp_sap_record; 103 104 typedef struct _bluetooth_sdp_dip_record { 105 bluetooth_sdp_hdr_overlay hdr; 106 uint16_t spec_id; 107 uint16_t vendor; 108 uint16_t vendor_id_source; 109 uint16_t product; 110 uint16_t version; 111 bool primary_record; 112 } bluetooth_sdp_dip_record; 113 114 typedef union { 115 bluetooth_sdp_hdr_overlay hdr; 116 bluetooth_sdp_mas_record mas; 117 bluetooth_sdp_mns_record mns; 118 bluetooth_sdp_pse_record pse; 119 bluetooth_sdp_pce_record pce; 120 bluetooth_sdp_ops_record ops; 121 bluetooth_sdp_sap_record sap; 122 bluetooth_sdp_dip_record dip; 123 } bluetooth_sdp_record; 124 125 /** Callback for SDP search */ 126 typedef void (*btsdp_search_callback)(bt_status_t status, 127 const RawAddress& bd_addr, 128 const bluetooth::Uuid& uuid, 129 int num_records, 130 bluetooth_sdp_record* records); 131 132 typedef struct { 133 /** Set to sizeof(btsdp_callbacks_t) */ 134 size_t size; 135 btsdp_search_callback sdp_search_cb; 136 } btsdp_callbacks_t; 137 138 typedef struct { 139 /** Set to size of this struct */ 140 size_t size; 141 142 /** Register BT SDP search callbacks */ 143 bt_status_t (*init)(btsdp_callbacks_t* callbacks); 144 145 /** Unregister BT SDP */ 146 bt_status_t (*deinit)(); 147 148 /** Search for SDP records with specific uuid on remote device */ 149 bt_status_t (*sdp_search)(RawAddress* bd_addr, const bluetooth::Uuid& uuid); 150 151 /** 152 * Use listen in the socket interface to create rfcomm and/or l2cap PSM 153 * channels, (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP 154 * flag in flags). Then use createSdpRecord to create the SDP record 155 * associated with the rfcomm/l2cap channels. 156 * 157 * Returns a handle to the SDP record, which can be parsed to 158 * remove_sdp_record. 159 * 160 * record (in) The SDP record to create 161 * record_handle (out)The corresponding record handle will be written to 162 * this pointer. 163 */ 164 bt_status_t (*create_sdp_record)(bluetooth_sdp_record* record, 165 int* record_handle); 166 167 /** Remove a SDP record created by createSdpRecord */ 168 bt_status_t (*remove_sdp_record)(int sdp_handle); 169 } btsdp_interface_t; 170 171 __END_DECLS 172