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