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.h" 20 #include "types/bluetooth/uuid.h" 21 #include "types/raw_address.h" 22 23 #define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15 24 25 __BEGIN_DECLS 26 27 /** 28 * These events are handled by the state machine 29 */ 30 typedef enum { 31 SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUIDs 32 SDP_TYPE_MAP_MAS, // Message Access Profile - Server 33 SDP_TYPE_MAP_MNS, // Message Access Profile - Client (Notification Server) 34 SDP_TYPE_PBAP_PSE, // Phone Book Profile - Server 35 SDP_TYPE_PBAP_PCE, // Phone Book Profile - Client 36 SDP_TYPE_OPP_SERVER, // Object Push Profile 37 SDP_TYPE_SAP_SERVER, // SIM Access Profile 38 SDP_TYPE_DIP, // Device Identification Profile 39 SDP_TYPE_MPS // Multi-Profile Specification 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 struct _bluetooth_sdp_mps_record { 115 bluetooth_sdp_hdr_overlay hdr; 116 uint8_t supported_scenarios_mpsd[8]; 117 uint8_t supported_scenarios_mpmd[8]; 118 uint8_t supported_dependencies[2]; 119 } bluetooth_sdp_mps_record; 120 121 typedef union { 122 bluetooth_sdp_hdr_overlay hdr; 123 bluetooth_sdp_mas_record mas; 124 bluetooth_sdp_mns_record mns; 125 bluetooth_sdp_pse_record pse; 126 bluetooth_sdp_pce_record pce; 127 bluetooth_sdp_ops_record ops; 128 bluetooth_sdp_sap_record sap; 129 bluetooth_sdp_dip_record dip; 130 bluetooth_sdp_mps_record mps; 131 } bluetooth_sdp_record; 132 133 /** Callback for SDP search */ 134 typedef void (*btsdp_search_callback)(bt_status_t status, const RawAddress& bd_addr, 135 const bluetooth::Uuid& uuid, int num_records, 136 bluetooth_sdp_record* records); 137 138 typedef struct { 139 /** Set to sizeof(btsdp_callbacks_t) */ 140 size_t size; 141 btsdp_search_callback sdp_search_cb; 142 } btsdp_callbacks_t; 143 144 typedef struct { 145 /** Set to size of this struct */ 146 size_t size; 147 148 /** Register BT SDP search callbacks */ 149 bt_status_t (*init)(btsdp_callbacks_t* callbacks); 150 151 /** Unregister BT SDP */ 152 bt_status_t (*deinit)(); 153 154 /** Search for SDP records with specific uuid on remote device */ 155 bt_status_t (*sdp_search)(RawAddress* bd_addr, const bluetooth::Uuid& uuid); 156 157 /** 158 * Use listen in the socket interface to create rfcomm and/or l2cap PSM 159 * channels, (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP 160 * flag in flags). Then use createSdpRecord to create the SDP record 161 * associated with the rfcomm/l2cap channels. 162 * 163 * Returns a handle to the SDP record, which can be parsed to 164 * remove_sdp_record. 165 * 166 * record (in) The SDP record to create 167 * record_handle (out)The corresponding record handle will be written to 168 * this pointer. 169 */ 170 bt_status_t (*create_sdp_record)(bluetooth_sdp_record* record, int* record_handle); 171 172 /** Remove a SDP record created by createSdpRecord */ 173 bt_status_t (*remove_sdp_record)(int sdp_handle); 174 } btsdp_interface_t; 175 176 __END_DECLS 177 178 #if __has_include(<bluetooth/log.h>) 179 #include <bluetooth/log.h> 180 181 namespace std { 182 template <> 183 struct formatter<bluetooth_sdp_types> : enum_formatter<bluetooth_sdp_types> {}; 184 } // namespace std 185 186 #endif // __has_include(<bluetooth/log.h>) 187